1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
//===- ir_test.go - Tests for ir ------------------------------------------===//
//
// The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file tests bindings for the ir component.
//
//===----------------------------------------------------------------------===//
package llvm
import (
"strings"
"testing"
)
func testAttribute(t *testing.T, name string) {
mod := NewModule("")
defer mod.Dispose()
ftyp := FunctionType(VoidType(), nil, false)
fn := AddFunction(mod, "foo", ftyp)
kind := AttributeKindID(name)
attr := mod.Context().CreateEnumAttribute(kind, 0)
fn.AddFunctionAttr(attr)
newattr := fn.GetEnumFunctionAttribute(kind)
if attr != newattr {
t.Errorf("got attribute mask %d, want %d", newattr, attr)
}
text := mod.String()
if !strings.Contains(text, " "+name+" ") {
t.Errorf("expected attribute '%s', got:\n%s", name, text)
}
fn.RemoveEnumFunctionAttribute(kind)
newattr = fn.GetEnumFunctionAttribute(kind)
if !newattr.IsNil() {
t.Errorf("got attribute mask %d, want 0", newattr)
}
}
func TestAttributes(t *testing.T) {
// Tests that our attribute constants haven't drifted from LLVM's.
attrTests := []string{
"sanitize_address",
"alwaysinline",
"builtin",
"byval",
"convergent",
"inalloca",
"inlinehint",
"inreg",
"jumptable",
"minsize",
"naked",
"nest",
"noalias",
"nobuiltin",
"nocapture",
"noduplicate",
"noimplicitfloat",
"noinline",
"nonlazybind",
"nonnull",
"noredzone",
"noreturn",
"nounwind",
"optnone",
"optsize",
"readnone",
"readonly",
"returned",
"returns_twice",
"signext",
"safestack",
"ssp",
"sspreq",
"sspstrong",
"sret",
"sanitize_thread",
"sanitize_memory",
"uwtable",
"zeroext",
"cold",
}
for _, name := range attrTests {
testAttribute(t, name)
}
}
|