1 //===- ir_test.go - Tests for ir ------------------------------------------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 // This file tests bindings for the ir component.
12 //===----------------------------------------------------------------------===//
21 func testAttribute(t *testing.T, attr Attribute, name string) {
25 ftyp := FunctionType(VoidType(), nil, false)
26 fn := AddFunction(mod, "foo", ftyp)
28 fn.AddFunctionAttr(attr)
29 newattr := fn.FunctionAttr()
31 t.Errorf("got attribute mask %d, want %d", newattr, attr)
35 if !strings.Contains(text, " "+name+" ") {
36 t.Errorf("expected attribute '%s', got:\n%s", name, text)
39 fn.RemoveFunctionAttr(attr)
40 newattr = fn.FunctionAttr()
42 t.Errorf("got attribute mask %d, want 0", newattr)
46 func TestAttributes(t *testing.T) {
47 // Tests that our attribute constants haven't drifted from LLVM's.
48 attrTests := []struct {
52 {SanitizeAddressAttribute, "sanitize_address"},
53 {AlwaysInlineAttribute, "alwaysinline"},
54 {BuiltinAttribute, "builtin"},
55 {ByValAttribute, "byval"},
56 {ConvergentAttribute, "convergent"},
57 {InAllocaAttribute, "inalloca"},
58 {InlineHintAttribute, "inlinehint"},
59 {InRegAttribute, "inreg"},
60 {JumpTableAttribute, "jumptable"},
61 {MinSizeAttribute, "minsize"},
62 {NakedAttribute, "naked"},
63 {NestAttribute, "nest"},
64 {NoAliasAttribute, "noalias"},
65 {NoBuiltinAttribute, "nobuiltin"},
66 {NoCaptureAttribute, "nocapture"},
67 {NoDuplicateAttribute, "noduplicate"},
68 {NoImplicitFloatAttribute, "noimplicitfloat"},
69 {NoInlineAttribute, "noinline"},
70 {NonLazyBindAttribute, "nonlazybind"},
71 {NonNullAttribute, "nonnull"},
72 {NoRedZoneAttribute, "noredzone"},
73 {NoReturnAttribute, "noreturn"},
74 {NoUnwindAttribute, "nounwind"},
75 {OptimizeNoneAttribute, "optnone"},
76 {OptimizeForSizeAttribute, "optsize"},
77 {ReadNoneAttribute, "readnone"},
78 {ReadOnlyAttribute, "readonly"},
79 {ReturnedAttribute, "returned"},
80 {ReturnsTwiceAttribute, "returns_twice"},
81 {SExtAttribute, "signext"},
82 {SafeStackAttribute, "safestack"},
83 {StackProtectAttribute, "ssp"},
84 {StackProtectReqAttribute, "sspreq"},
85 {StackProtectStrongAttribute, "sspstrong"},
86 {StructRetAttribute, "sret"},
87 {SanitizeThreadAttribute, "sanitize_thread"},
88 {SanitizeMemoryAttribute, "sanitize_memory"},
89 {UWTableAttribute, "uwtable"},
90 {ZExtAttribute, "zeroext"},
91 {ColdAttribute, "cold"},
94 for _, a := range attrTests {
95 testAttribute(t, a.attr, a.name)