1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-25 20:23:11 +01:00
llvm-mirror/bindings/go/llvm/ir_test.go
Peter Collingbourne cb037f41a1 Add safestack attribute to LLVMAttribute enum and Go bindings. Correct
constants in commented-out part of LLVMAttribute enum. Add tests that verify
that the safestack attribute is only allowed as a function attribute.

llvm-svn: 239772
2015-06-15 22:16:51 +00:00

98 lines
2.8 KiB
Go

//===- 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, attr Attribute, name string) {
mod := NewModule("")
defer mod.Dispose()
ftyp := FunctionType(VoidType(), nil, false)
fn := AddFunction(mod, "foo", ftyp)
fn.AddFunctionAttr(attr)
newattr := fn.FunctionAttr()
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.RemoveFunctionAttr(attr)
newattr = fn.FunctionAttr()
if newattr != 0 {
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 := []struct {
attr Attribute
name string
}{
{SanitizeAddressAttribute, "sanitize_address"},
{AlwaysInlineAttribute, "alwaysinline"},
{BuiltinAttribute, "builtin"},
{ByValAttribute, "byval"},
{ConvergentAttribute, "convergent"},
{InAllocaAttribute, "inalloca"},
{InlineHintAttribute, "inlinehint"},
{InRegAttribute, "inreg"},
{JumpTableAttribute, "jumptable"},
{MinSizeAttribute, "minsize"},
{NakedAttribute, "naked"},
{NestAttribute, "nest"},
{NoAliasAttribute, "noalias"},
{NoBuiltinAttribute, "nobuiltin"},
{NoCaptureAttribute, "nocapture"},
{NoDuplicateAttribute, "noduplicate"},
{NoImplicitFloatAttribute, "noimplicitfloat"},
{NoInlineAttribute, "noinline"},
{NonLazyBindAttribute, "nonlazybind"},
{NonNullAttribute, "nonnull"},
{NoRedZoneAttribute, "noredzone"},
{NoReturnAttribute, "noreturn"},
{NoUnwindAttribute, "nounwind"},
{OptimizeNoneAttribute, "optnone"},
{OptimizeForSizeAttribute, "optsize"},
{ReadNoneAttribute, "readnone"},
{ReadOnlyAttribute, "readonly"},
{ReturnedAttribute, "returned"},
{ReturnsTwiceAttribute, "returns_twice"},
{SExtAttribute, "signext"},
{SafeStackAttribute, "safestack"},
{StackProtectAttribute, "ssp"},
{StackProtectReqAttribute, "sspreq"},
{StackProtectStrongAttribute, "sspstrong"},
{StructRetAttribute, "sret"},
{SanitizeThreadAttribute, "sanitize_thread"},
{SanitizeMemoryAttribute, "sanitize_memory"},
{UWTableAttribute, "uwtable"},
{ZExtAttribute, "zeroext"},
{ColdAttribute, "cold"},
}
for _, a := range attrTests {
testAttribute(t, a.attr, a.name)
}
}