diff options
Diffstat (limited to 'test/Feature')
50 files changed, 2083 insertions, 0 deletions
diff --git a/test/Feature/README.txt b/test/Feature/README.txt new file mode 100644 index 0000000..5947bb2 --- /dev/null +++ b/test/Feature/README.txt @@ -0,0 +1,6 @@ +This directory contains test cases for individual source features of LLVM. +It is designed to make sure that the major components of LLVM support all of the +features of LLVM, for very small examples. Entire programs should not go here. + +Regression tests for individual bug fixes should go into the test/Regression dir. + diff --git a/test/Feature/aliases.ll b/test/Feature/aliases.ll new file mode 100644 index 0000000..fc5e768 --- /dev/null +++ b/test/Feature/aliases.ll @@ -0,0 +1,30 @@ +; RUN: llvm-as < %s | llvm-dis > %t1.ll +; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll +; RUN: diff %t1.ll %t2.ll + +@bar = external global i32 +@foo1 = alias i32* @bar +@foo2 = alias i32* @bar + +%FunTy = type i32() + +declare i32 @foo_f() +@bar_f = alias weak %FunTy* @foo_f + +@bar_i = alias internal i32* @bar + +@A = alias bitcast (i32* @bar to i64*) + +define i32 @test() { +entry: + %tmp = load i32* @foo1 + %tmp1 = load i32* @foo2 + %tmp0 = load i32* @bar_i + %tmp2 = call i32 @foo_f() + %tmp3 = add i32 %tmp, %tmp2 + %tmp4 = call %FunTy* @bar_f() + %tmp5 = add i32 %tmp3, %tmp4 + %tmp6 = add i32 %tmp1, %tmp5 + %tmp7 = add i32 %tmp6, %tmp0 + ret i32 %tmp7 +} diff --git a/test/Feature/alignment.ll b/test/Feature/alignment.ll new file mode 100644 index 0000000..9277dbc --- /dev/null +++ b/test/Feature/alignment.ll @@ -0,0 +1,20 @@ +; RUN: llvm-upgrade < %s | llvm-as | llvm-dis > %t1.ll +; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll +; RUN: diff %t1.ll %t2.ll + +%X = global int 4, align 16 + +int *%test() align 32 { + %X = alloca int, align 4 + %Y = alloca int, uint 42, align 16 + %Z = alloca int, align 0 + ret int *%X +} + +int *%test2() { + %X = malloc int, align 4 + %Y = malloc int, uint 42, align 16 + %Z = malloc int, align 0 + %T = malloc int, align 256 + ret int *%X +} diff --git a/test/Feature/basictest.ll b/test/Feature/basictest.ll new file mode 100644 index 0000000..cf040ec --- /dev/null +++ b/test/Feature/basictest.ll @@ -0,0 +1,32 @@ +; RUN: llvm-upgrade < %s | llvm-as | llvm-dis > %t1.ll +; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll +; RUN: diff %t1.ll %t2.ll + +implementation + +; Test "stripped" format where nothing is symbolic... this is how the bytecode +; format looks anyways (except for negative vs positive offsets)... +; +void "void"(int, int) ; Def %0, %1 +begin + add int 0, 0 ; Def 2 + sub int 0, 4 ; Def 3 + br label %1 + + add int %0, %1 ; Def 4 + sub int %4, %3 ; Def 5 + setle int %5, %2 ; Def 0 - bool plane + br bool %0, label %2, label %1 + + add int %0, %1 ; Def 6 + sub int %4, %3 ; Def 7 + setle int %7, %2 ; Def 1 - bool plane + ret void +end + +; This function always returns zero +int "zarro"() +begin +Startup: + ret int 0 +end diff --git a/test/Feature/callingconventions.ll b/test/Feature/callingconventions.ll new file mode 100644 index 0000000..5617f9f --- /dev/null +++ b/test/Feature/callingconventions.ll @@ -0,0 +1,47 @@ +; RUN: llvm-upgrade < %s | llvm-as | llvm-dis > %t1.ll +; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll +; RUN: diff %t1.ll %t2.ll + +fastcc void %foo() { + ret void +} + +coldcc void %bar() { + call fastcc void %foo() + ret void +} + +csretcc void %structret({sbyte}* %P) { + call csretcc void %structret({sbyte}* %P) + ret void +} + + +cc0 void %foo2() { + ret void +} + +coldcc void %bar2() { + call fastcc void %foo() + ret void +} + +cc42 void %bar3() { + invoke fastcc void %foo() to label %Ok unwind label %U +Ok: + ret void +U: + unwind +} + + +void %bar4() { + call cc42 void %bar() + invoke cc42 void %bar3() to label %Ok unwind label %U +Ok: + ret void +U: + unwind +} + + diff --git a/test/Feature/calltest.ll b/test/Feature/calltest.ll new file mode 100644 index 0000000..f015223 --- /dev/null +++ b/test/Feature/calltest.ll @@ -0,0 +1,34 @@ +; RUN: llvm-upgrade < %s | llvm-as | llvm-dis > %t1.ll +; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll +; RUN: diff %t1.ll %t2.ll + +%FunTy = type int(int) + +declare int "test"(int) ; Test forward declaration merging + +implementation + +void "invoke"(%FunTy *%x) { + %foo = call %FunTy* %x(int 123) + %foo2 = tail call %FunTy* %x(int 123) + ret void +} + +int "main"(int %argc) ; TODO: , sbyte **argv, sbyte **envp) +begin + %retval = call int (int) *%test(int %argc) + %two = add int %retval, %retval + %retval2 = invoke int %test(int %argc) + to label %Next except label %Error +Next: + %two2 = add int %two, %retval2 + call void %invoke (%FunTy* %test) + ret int %two2 +Error: + ret int -1 +end + +int "test"(int %i0) +begin + ret int %i0 +end diff --git a/test/Feature/casttest.ll b/test/Feature/casttest.ll new file mode 100644 index 0000000..96f971a --- /dev/null +++ b/test/Feature/casttest.ll @@ -0,0 +1,13 @@ +; RUN: llvm-upgrade < %s | llvm-as | llvm-dis > %t1.ll +; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll +; RUN: diff %t1.ll %t2.ll + +short "FunFunc"(long %x, sbyte %z) +begin +bb0: ;;<label> + %cast110 = cast sbyte %z to short ;;<short>:(signed operands) + %cast10 = cast long %x to short ;;<short> + %reg109 = add short %cast110, %cast10 ;;<short> + ret short %reg109 ;;<void> +end + diff --git a/test/Feature/cfgstructures.ll b/test/Feature/cfgstructures.ll new file mode 100644 index 0000000..b16af47 --- /dev/null +++ b/test/Feature/cfgstructures.ll @@ -0,0 +1,57 @@ +; RUN: llvm-upgrade < %s | llvm-as | llvm-dis > %t1.ll +; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll +; RUN: diff %t1.ll %t2.ll + +implementation + +;; This is an irreducible flow graph + + +void "irreducible"(bool %cond) +begin + br bool %cond, label %X, label %Y + +X: + br label %Y +Y: + br label %X +end + +;; This is a pair of loops that share the same header + +void "sharedheader"(bool %cond) +begin + br label %A +A: + br bool %cond, label %X, label %Y + +X: + br label %A +Y: + br label %A +end + +;; This is a simple nested loop +void "nested"(bool %cond1, bool %cond2, bool %cond3) +begin + br label %Loop1 + +Loop1: + br label %Loop2 + +Loop2: + br label %Loop3 + +Loop3: + br bool %cond3, label %Loop3, label %L3Exit + +L3Exit: + br bool %cond2, label %Loop2, label %L2Exit + +L2Exit: + br bool %cond1, label %Loop1, label %L1Exit + +L1Exit: + ret void +end + diff --git a/test/Feature/constexpr.ll b/test/Feature/constexpr.ll new file mode 100644 index 0000000..aea8944 --- /dev/null +++ b/test/Feature/constexpr.ll @@ -0,0 +1,83 @@ +; RUN: llvm-upgrade < %s | llvm-as | llvm-dis > %t1.ll +; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll +; RUN: diff %t1.ll %t2.ll + +; This testcase is for testing expressions constructed from +; constant values, including constant pointers to globals. +; + +;;------------------------------- +;; Test constant cast expressions +;;------------------------------- + +global ulong u0x00001 ; hexadecimal unsigned integer constants +global long s0x0012312 ; hexadecimal signed integer constants + +%t2 = global int* %t1 ;; Forward reference without cast +%t3 = global uint* cast (int* %t1 to uint*) ;; Forward reference with cast +%t1 = global int 4 ;; int* %0 +%t4 = global int** cast (uint** %t3 to int**) ;; Cast of a previous cast +%t5 = global uint** %t3 ;; Reference to a previous cast +%t6 = global int*** %t4 ;; Different ref. to a previous cast +%t7 = global float* cast (int 12345678 to float*) ;; Cast ordinary value to ptr +%t9 = global int cast (float cast (int 8 to float) to int) ;; Nested cast expression + +global int* cast (float* %0 to int*) ;; Forward numeric reference +global float* %0 ;; Duplicate forward numeric reference +global float 0.0 + + +;;--------------------------------------------------- +;; Test constant getelementpr expressions for arrays +;;--------------------------------------------------- + +%array = constant [2 x int] [ int 12, int 52 ] +%arrayPtr = global int* getelementptr ([2 x int]* %array, long 0, long 0) ;; int* &%array[0][0] +%arrayPtr5 = global int** getelementptr (int** %arrayPtr, long 5) ;; int* &%arrayPtr[5] + +%somestr = constant [11x sbyte] c"hello world" +%char5 = global sbyte* getelementptr([11x sbyte]* %somestr, long 0, long 5) + +;; cast of getelementptr +%char8a = global int* cast (sbyte* getelementptr([11x sbyte]* %somestr, long 0, long 8) to int*) + +;; getelementptr containing casts +%char8b = global sbyte* getelementptr([11x sbyte]* %somestr, long cast (ubyte 0 to long), long cast (sbyte 8 to long)) + +;;------------------------------------------------------- +;; TODO: Test constant getelementpr expressions for structures +;;------------------------------------------------------- + +%SType = type { int , {float, {ubyte} }, ulong } ;; struct containing struct +%SAType = type { int , {[2x float], ulong} } ;; struct containing array + +%S1 = global %SType* null ;; Global initialized to NULL +%S2c = constant %SType { int 1, {float,{ubyte}} {float 2.0, {ubyte} {ubyte 3}}, ulong 4} + +%S3c = constant %SAType { int 1, {[2x float], ulong} {[2x float] [float 2.0, float 3.0], ulong 4} } + +%S1ptr = global %SType** %S1 ;; Ref. to global S1 +%S2 = global %SType* %S2c ;; Ref. to constant S2 +%S3 = global %SAType* %S3c ;; Ref. to constant S3 + + ;; Pointer to float (**%S1).1.0 +%S1fld1a = global float* getelementptr (%SType* %S2c, long 0, uint 1, uint 0) + ;; Another ptr to the same! +%S1fld1b = global float* getelementptr (%SType* %S2c, long 0, uint 1, uint 0) + +%S1fld1bptr = global float** %S1fld1b ;; Ref. to previous pointer + + ;; Pointer to ubyte (**%S2).1.1.0 +%S2fld3 = global ubyte* getelementptr (%SType* %S2c, long 0, uint 1, uint 1, uint 0) + + ;; Pointer to float (**%S2).1.0[0] +;%S3fld3 = global float* getelementptr (%SAType** %S3, long 0, long 0, uint 1, uint 0, long 0) + +;;--------------------------------------------------------- +;; TODO: Test constant expressions for unary and binary operators +;;--------------------------------------------------------- + +;;--------------------------------------------------- + +implementation + diff --git a/test/Feature/constpointer.ll b/test/Feature/constpointer.ll new file mode 100644 index 0000000..d1dddaa --- /dev/null +++ b/test/Feature/constpointer.ll @@ -0,0 +1,33 @@ +; RUN: llvm-upgrade < %s | llvm-as | llvm-dis > %t1.ll +; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll +; RUN: diff %t1.ll %t2.ll + +; This testcase is primarily used for testing that global values can be used as +; constant pointer initializers. This is tricky because they can be forward +; declared and involves an icky bytecode encoding. There is no meaningful +; optimization that can be performed on this file, it is just here to test +; assembly and disassembly. +; + + +%t3 = global int * %t1 ;; Forward reference +%t1 = global int 4 +%t4 = global int ** %t3 ;; reference to reference + +%t2 = global int * %t1 + +global float * %0 ;; Forward numeric reference +global float * %0 ;; Duplicate forward numeric reference +global float 0.0 +global float * %0 ;; Numeric reference + + +%fptr = global void() * %f ;; Forward ref method defn +declare void "f"() ;; External method + +%sptr1 = global [11x sbyte]* %somestr ;; Forward ref to a constant +%somestr = constant [11x sbyte] c"hello world" +%sptr2 = global [11x sbyte]* %somestr + +implementation + diff --git a/test/Feature/dg.exp b/test/Feature/dg.exp new file mode 100644 index 0000000..879685c --- /dev/null +++ b/test/Feature/dg.exp @@ -0,0 +1,3 @@ +load_lib llvm.exp + +RunLLVMTests [lsort [glob -nocomplain $srcdir/$subdir/*.{ll,llx,c,cpp,tr}]] diff --git a/test/Feature/escaped_label.ll b/test/Feature/escaped_label.ll new file mode 100644 index 0000000..4532fe9 --- /dev/null +++ b/test/Feature/escaped_label.ll @@ -0,0 +1,10 @@ +; RUN: llvm-upgrade < %s | llvm-as | llvm-dis > %t1.ll +; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll +; RUN: diff %t1.ll %t2.ll + + +int %foo() { + br label "foo`~!@#$%^&*()-_=+{}[]\\|;:',<.>/?" +"foo`~!@#$%^&*()-_=+{}[]\\|;:',<.>/?": + ret int 17 +} diff --git a/test/Feature/float.ll b/test/Feature/float.ll new file mode 100644 index 0000000..5a53c2c0 --- /dev/null +++ b/test/Feature/float.ll @@ -0,0 +1,6 @@ +; RUN: llvm-upgrade < %s | llvm-as | llvm-dis > Output/t1.ll +; RUN: llvm-as Output/t1.ll -o - | llvm-dis > Output/t2.ll +; RUN: diff Output/t1.ll Output/t2.ll + +%F1 = global float 0x4010000000000000 +%D1 = global double 0x4010000000000000 diff --git a/test/Feature/fold-fpcast.ll b/test/Feature/fold-fpcast.ll new file mode 100644 index 0000000..65759b5 --- /dev/null +++ b/test/Feature/fold-fpcast.ll @@ -0,0 +1,18 @@ +; RUN: llvm-upgrade < %s | llvm-as | llvm-dis | not grep bitcast + +int %test1() { + ret int bitcast(float 3.7 to int) +} + +float %test2() { + ret float bitcast(int 17 to float) +} + +long %test3() { + ret long bitcast (double 3.1415926 to long) +} + +double %test4() { + ret double bitcast (long 42 to double) +} + diff --git a/test/Feature/forwardreftest.ll b/test/Feature/forwardreftest.ll new file mode 100644 index 0000000..edb1f28 --- /dev/null +++ b/test/Feature/forwardreftest.ll @@ -0,0 +1,34 @@ +; RUN: llvm-upgrade < %s | llvm-as | llvm-dis > %t1.ll +; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll +; RUN: diff %t1.ll %t2.ll + + %myty = type int + %myfn = type float (int,double,uint,short) + type int(%myfn*) + type int(int) + type int(int(int)*) + + %thisfuncty = type int (int) * +implementation + +declare void %F(%thisfuncty, %thisfuncty, %thisfuncty) + +; This function always returns zero +int %zarro(int %Func) +begin +Startup: + add int 0, 10 + ret int 0 +end + +int %test(int) +begin + call void %F(%thisfuncty %zarro, %thisfuncty %test, %thisfuncty %foozball) + ret int 0 +end + +int %foozball(int) +begin + ret int 0 +end + diff --git a/test/Feature/global_section.ll b/test/Feature/global_section.ll new file mode 100644 index 0000000..08a2c32 --- /dev/null +++ b/test/Feature/global_section.ll @@ -0,0 +1,10 @@ +; RUN: llvm-upgrade < %s | llvm-as | llvm-dis > %t1.ll +; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll +; RUN: diff %t1.ll %t2.ll + +%X = global int 4, section "foo", align 16 + +void %test() section "bar" { + ret void +} + diff --git a/test/Feature/globalredefinition.ll b/test/Feature/globalredefinition.ll new file mode 100644 index 0000000..642c093 --- /dev/null +++ b/test/Feature/globalredefinition.ll @@ -0,0 +1,18 @@ +; RUN: llvm-upgrade < %s | llvm-as | llvm-dis > %t1.ll +; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll +; RUN: diff %t1.ll %t2.ll + +; Test forward references and redefinitions of globals + +%A = global int* %B +%B = global int 7 + +declare void %X() + +declare void %X() + +void %X() { + ret void +} + +declare void %X() diff --git a/test/Feature/globalredefinition2.ll b/test/Feature/globalredefinition2.ll new file mode 100644 index 0000000..9949e05 --- /dev/null +++ b/test/Feature/globalredefinition2.ll @@ -0,0 +1,6 @@ +; Test that redefinitions of globals produces an error in llvm-upgrade +; RUN: llvm-upgrade < %s -o /dev/null -f |& grep \ +; RUN: "Renaming global variable 'B' to.*linkage errors" + +%B = global int 7 +%B = global int 7 diff --git a/test/Feature/globalredefinition3.ll b/test/Feature/globalredefinition3.ll new file mode 100644 index 0000000..9906c06 --- /dev/null +++ b/test/Feature/globalredefinition3.ll @@ -0,0 +1,6 @@ +; RUN: ignore llvm-as < %s -o /dev/null -f |& grep \ +; RUN: "Redefinition of global variable named 'B'" +; END. + +@B = global i32 7 +@B = global i32 7 diff --git a/test/Feature/globalvars.ll b/test/Feature/globalvars.ll new file mode 100644 index 0000000..26259da --- /dev/null +++ b/test/Feature/globalvars.ll @@ -0,0 +1,26 @@ +; RUN: llvm-upgrade < %s | llvm-as | llvm-dis > %t1.ll +; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll +; RUN: diff %t1.ll %t2.ll + + +%MyVar = uninitialized global int +%MyIntList = uninitialized global { \2 *, int } + external global int ; int*:0 + +%AConst = constant int 123 + +%AString = constant [4 x ubyte] c"test" + +%ZeroInit = global { [100 x int ], [40 x float ] } { [100 x int] zeroinitializer, + [40 x float] zeroinitializer } + +implementation + +int "foo"(int %blah) +begin + store int 5, int *%MyVar + %idx = getelementptr { \2 *, int } * %MyIntList, long 0, uint 1 + store int 12, int* %idx + ret int %blah +end + diff --git a/test/Feature/indirectcall.ll b/test/Feature/indirectcall.ll new file mode 100644 index 0000000..2d1855b --- /dev/null +++ b/test/Feature/indirectcall.ll @@ -0,0 +1,54 @@ +; RUN: llvm-upgrade < %s | llvm-as | llvm-dis > %t1.ll +; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll +; RUN: diff %t1.ll %t2.ll + +implementation + +declare int "atoi"(sbyte *) + +ulong "fib"(ulong %n) +begin + setlt ulong %n, 2 ; {bool}:0 + br bool %0, label %BaseCase, label %RecurseCase + +BaseCase: + ret ulong 1 + +RecurseCase: + %n2 = sub ulong %n, 2 + %n1 = sub ulong %n, 1 + %f2 = call ulong(ulong) * %fib(ulong %n2) + %f1 = call ulong(ulong) * %fib(ulong %n1) + %result = add ulong %f2, %f1 + ret ulong %result +end + +ulong "realmain"(int %argc, sbyte ** %argv) +begin + seteq int %argc, 2 ; {bool}:0 + br bool %0, label %HasArg, label %Continue +HasArg: + ; %n1 = atoi(argv[1]) + %n1 = add int 1, 1 + br label %Continue + +Continue: + %n = phi int [%n1, %HasArg], [1, %0] + %N = cast int %n to ulong + %F = call ulong(ulong) *%fib(ulong %N) + ret ulong %F +end + +ulong "trampoline"(ulong %n, ulong(ulong)* %fibfunc) +begin + %F = call ulong(ulong) *%fibfunc(ulong %n) + ret ulong %F +end + +int "main"() +begin + %Result = call ulong %trampoline(ulong 10, ulong(ulong) *%fib) + %Result = cast ulong %Result to int + ret int %Result +end + diff --git a/test/Feature/indirectcall2.ll b/test/Feature/indirectcall2.ll new file mode 100644 index 0000000..d16c737 --- /dev/null +++ b/test/Feature/indirectcall2.ll @@ -0,0 +1,25 @@ +; RUN: llvm-upgrade < %s | llvm-as | llvm-dis > %t1.ll +; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll +; RUN: diff %t1.ll %t2.ll + +implementation + +ulong "test"(ulong %X) +begin + ret ulong %X +end + +ulong "fib"(ulong %n) +begin + %T = setlt ulong %n, 2 ; {bool}:0 + br bool %T, label %BaseCase, label %RecurseCase + +RecurseCase: + %result = call ulong %test(ulong %n) + br label %BaseCase + +BaseCase: + %X = phi ulong [1, %0], [2, %RecurseCase] + ret ulong %X +end + diff --git a/test/Feature/inlineasm.ll b/test/Feature/inlineasm.ll new file mode 100644 index 0000000..c8f59f2 --- /dev/null +++ b/test/Feature/inlineasm.ll @@ -0,0 +1,14 @@ +; RUN: llvm-upgrade %s -o - | llvm-as -o /dev/null -f +; RUN: llvm-upgrade < %s | llvm-as | llvm-dis > Output/t1.ll +; RUN: llvm-as Output/t1.ll -o - | llvm-dis > Output/t2.ll +; RUN: diff Output/t1.ll Output/t2.ll + + +module asm "this is an inline asm block" +module asm "this is another inline asm block" + +int %test() { + %X = call int asm "tricky here $0, $1", "=r,r"(int 4) + call void asm sideeffect "eieio", ""() + ret int %X +} diff --git a/test/Feature/instructions.ll b/test/Feature/instructions.ll new file mode 100644 index 0000000..6867491 --- /dev/null +++ b/test/Feature/instructions.ll @@ -0,0 +1,25 @@ +; RUN: llvm-upgrade < %s | llvm-as | llvm-dis > %t1.ll +; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll +; RUN: diff %t1.ll %t2.ll + +uint %test_extractelement(<4 x uint> %V) { + %R = extractelement <4 x uint> %V, uint 1 + ret uint %R +} + +<4 x uint> %test_insertelement(<4 x uint> %V) { + %R = insertelement <4 x uint> %V, uint 0, uint 0 + ret <4 x uint> %R +} + +<4 x uint> %test_shufflevector_u(<4 x uint> %V) { + %R = shufflevector <4 x uint> %V, <4 x uint> %V, + <4 x uint> < uint 1, uint undef, uint 7, uint 2> + ret <4 x uint> %R +} + +<4 x float> %test_shufflevector_f(<4 x float> %V) { + %R = shufflevector <4 x float> %V, <4 x float> undef, + <4 x uint> < uint 1, uint undef, uint 7, uint 2> + ret <4 x float> %R +} diff --git a/test/Feature/intrinsics.ll b/test/Feature/intrinsics.ll new file mode 100644 index 0000000..d464726 --- /dev/null +++ b/test/Feature/intrinsics.ll @@ -0,0 +1,59 @@ +; RUN: llvm-upgrade < %s | llvm-as | llvm-dis > %t1.ll +; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll +; RUN: diff %t1.ll %t2.ll + + +declare bool %llvm.isunordered.f32(float,float) +declare bool %llvm.isunordered.f64(double,double) + +declare void %llvm.prefetch(sbyte*, uint, uint) + +declare uint %llvm.ctpop.i8(ubyte) +declare uint %llvm.ctpop.i16(ushort) +declare uint %llvm.ctpop.i32(uint) +declare uint %llvm.ctpop.i64(ulong) + +declare uint %llvm.cttz.i8(ubyte) +declare uint %llvm.cttz.i16(ushort) +declare uint %llvm.cttz.i32(uint) +declare uint %llvm.cttz.i64(ulong) + +declare uint %llvm.ctlz.i8(ubyte) +declare uint %llvm.ctlz.i16(ushort) +declare uint %llvm.ctlz.i32(uint) +declare uint %llvm.ctlz.i64(ulong) + +declare float %llvm.sqrt.f32(float) +declare double %llvm.sqrt.f64(double) + +implementation + +; Test llvm intrinsics +; +void %libm() { + call bool %llvm.isunordered.f32(float 1.0, float 2.0) + call bool %llvm.isunordered.f64(double 3.0, double 4.0) + + call void %llvm.prefetch(sbyte* null, uint 1, uint 3) + + call float %llvm.sqrt.f32(float 5.0) + call double %llvm.sqrt.f64(double 6.0) + + call uint %llvm.ctpop.i8(ubyte 10) + call uint %llvm.ctpop.i16(ushort 11) + call uint %llvm.ctpop.i32(uint 12) + call uint %llvm.ctpop.i64(ulong 13) + + call uint %llvm.ctlz.i8(ubyte 14) + call uint %llvm.ctlz.i16(ushort 15) + call uint %llvm.ctlz.i32(uint 16) + call uint %llvm.ctlz.i64(ulong 17) + + call uint %llvm.cttz.i8(ubyte 18) + call uint %llvm.cttz.i16(ushort 19) + call uint %llvm.cttz.i32(uint 20) + call uint %llvm.cttz.i64(ulong 21) + ret void +} + +; FIXME: test ALL the intrinsics in this file. diff --git a/test/Feature/llvm2cpp.exp b/test/Feature/llvm2cpp.exp new file mode 100644 index 0000000..b05d64a --- /dev/null +++ b/test/Feature/llvm2cpp.exp @@ -0,0 +1,3 @@ +load_lib llvm2cpp.exp + +llvm2cpp-test [lsort [glob -nocomplain $srcdir/$subdir/*.{ll,llx}]] diff --git a/test/Feature/llvm2cpp.ll b/test/Feature/llvm2cpp.ll new file mode 100644 index 0000000..4cfb66d --- /dev/null +++ b/test/Feature/llvm2cpp.ll @@ -0,0 +1,795 @@ +; RUN: llvm-as < %s | llvm-dis > %t1.ll +; RUN: llvm-as < %s | llvm2cpp -gen-program -o %t2.cpp - -f +; RUN: %link -o %t2.exe %t2.cpp -lLLVMCore -lLLVMSupport -lLLVMSystem -lstdc++ +; RUN: %t2.exe > %t2.ll +; RUN: diff %t1.ll %t2.ll + +@X = global i32 4, align 16 ; <i32*> [#uses=0] + +define i32* @test1012() align 32 { + %X = alloca i32, align 4 ; <i32*> [#uses=1] + %Y = alloca i32, i32 42, align 16 ; <i32*> [#uses=0] + %Z = alloca i32 ; <i32*> [#uses=0] + ret i32* %X +} + +define i32* @test1013() { + %X = malloc i32, align 4 ; <i32*> [#uses=1] + %Y = malloc i32, i32 42, align 16 ; <i32*> [#uses=0] + %Z = malloc i32 ; <i32*> [#uses=0] + ret i32* %X +} + +define void @void(i32, i32) { + add i32 0, 0 ; <i32>:3 [#uses=2] + sub i32 0, 4 ; <i32>:4 [#uses=2] + br label %5 + +; <label>:5 ; preds = %5, %2 + add i32 %0, %1 ; <i32>:6 [#uses=2] + sub i32 %6, %4 ; <i32>:7 [#uses=1] + icmp sle i32 %7, %3 ; <i1>:8 [#uses=1] + br i1 %8, label %9, label %5 + +; <label>:9 ; preds = %5 + add i32 %0, %1 ; <i32>:10 [#uses=0] + sub i32 %6, %4 ; <i32>:11 [#uses=1] + icmp sle i32 %11, %3 ; <i1>:12 [#uses=0] + ret void +} + +define i32 @zarro() { +Startup: + ret i32 0 +} + +define fastcc void @foo() { + ret void +} + +define coldcc void @bar() { + call fastcc void @foo( ) + ret void +} + +define void @structret({ i8 }* sret %P) { + call void @structret( { i8 }* %P sret ) + ret void +} + +define void @foo4() { + ret void +} + +define coldcc void @bar2() { + call fastcc void @foo( ) + ret void +} + +define cc42 void @bar3() { + invoke fastcc void @foo( ) + to label %Ok unwind label %U + +Ok: ; preds = %0 + ret void + +U: ; preds = %0 + unwind +} + +define void @bar4() { + call cc42 void @bar( ) + invoke cc42 void @bar3( ) + to label %Ok unwind label %U + +Ok: ; preds = %0 + ret void + +U: ; preds = %0 + unwind +} +; ModuleID = 'calltest.ll' + %FunTy = type i32 (i32) + +define i32 @test1000(i32 %i0) { + ret i32 %i0 +} + +define void @invoke(%FunTy* %x) { + %foo = call i32 %x( i32 123 ) ; <i32> [#uses=0] + %foo2 = tail call i32 %x( i32 123 ) ; <i32> [#uses=0] + ret void +} + +define i32 @main(i32 %argc) { + %retval = call i32 @test1000( i32 %argc ) ; <i32> [#uses=2] + %two = add i32 %retval, %retval ; <i32> [#uses=1] + %retval2 = invoke i32 @test1000( i32 %argc ) + to label %Next unwind label %Error ; <i32> [#uses=1] + +Next: ; preds = %0 + %two2 = add i32 %two, %retval2 ; <i32> [#uses=1] + call void @invoke( %FunTy* @test1000 ) + ret i32 %two2 + +Error: ; preds = %0 + ret i32 -1 +} +; ModuleID = 'casttest.ll' + +define i16 @FunFunc(i64 %x, i8 %z) { +bb0: + %cast110 = sext i8 %z to i16 ; <i16> [#uses=1] + %cast10 = trunc i64 %x to i16 ; <i16> [#uses=1] + %reg109 = add i16 %cast110, %cast10 ; <i16> [#uses=1] + ret i16 %reg109 +} +; ModuleID = 'cfgstructures.ll' + +define void @irreducible(i1 %cond) { + br i1 %cond, label %X, label %Y + +X: ; preds = %Y, %0 + br label %Y + +Y: ; preds = %X, %0 + br label %X +} + +define void @sharedheader(i1 %cond) { + br label %A + +A: ; preds = %Y, %X, %0 + br i1 %cond, label %X, label %Y + +X: ; preds = %A + br label %A + +Y: ; preds = %A + br label %A +} + +define void @nested(i1 %cond1, i1 %cond2, i1 %cond3) { + br label %Loop1 + +Loop1: ; preds = %L2Exit, %0 + br label %Loop2 + +Loop2: ; preds = %L3Exit, %Loop1 + br label %Loop3 + +Loop3: ; preds = %Loop3, %Loop2 + br i1 %cond3, label %Loop3, label %L3Exit + +L3Exit: ; preds = %Loop3 + br i1 %cond2, label %Loop2, label %L2Exit + +L2Exit: ; preds = %L3Exit + br i1 %cond1, label %Loop1, label %L1Exit + +L1Exit: ; preds = %L2Exit + ret void +} +; ModuleID = 'constexpr.ll' + %SAType = type { i32, { [2 x float], i64 } } + %SType = type { i32, { float, { i8 } }, i64 } +global i64 1 ; <i64*>:0 [#uses=0] +global i64 74514 ; <i64*>:1 [#uses=0] +@t2 = global i32* @t1 ; <i32**> [#uses=0] +@t3 = global i32* @t1 ; <i32**> [#uses=2] +@t1 = global i32 4 ; <i32*> [#uses=2] +@t4 = global i32** @t3 ; <i32***> [#uses=1] +@t5 = global i32** @t3 ; <i32***> [#uses=0] +@t6 = global i32*** @t4 ; <i32****> [#uses=0] +@t7 = global float* inttoptr (i32 12345678 to float*) ; <float**> [#uses=0] +@t9 = global i32 8 ; <i32*> [#uses=0] +global i32* bitcast (float* @4 to i32*) ; <i32**>:2 [#uses=0] +global float* @4 ; <float**>:3 [#uses=0] +global float 0.000000e+00 ; <float*>:4 [#uses=2] +@array = constant [2 x i32] [ i32 12, i32 52 ] ; <[2 x i32]*> [#uses=1] +@arrayPtr = global i32* getelementptr ([2 x i32]* @array, i64 0, i64 0) ; <i32**> [#uses=1] +@arrayPtr5 = global i32** getelementptr (i32** @arrayPtr, i64 5) ; <i32***> [#uses=0] +@somestr = constant [11 x i8] c"hello world" ; <[11 x i8]*> [#uses=2] +@char5 = global i8* getelementptr ([11 x i8]* @somestr, i64 0, i64 5) ; <i8**> [#uses=0] +@char8a = global i32* bitcast (i8* getelementptr ([11 x i8]* @somestr, i64 0, i64 8) to i32*) ; <i32**> [#uses=0] +@char8b = global i8* getelementptr ([11 x i8]* @somestr, i64 0, i64 8) ; <i8**> [#uses=0] +@S1 = global %SType* null ; <%SType**> [#uses=1] +@S2c = constant %SType { + i32 1, + { float, { i8 } } { float 2.000000e+00, { i8 } { i8 3 } }, + i64 4 } ; <%SType*> [#uses=3] +@S3c = constant %SAType { i32 1, { [2 x float], i64 } { [2 x float] [ float 2.000000e+00, float 3.000000e+00 ], i64 4 } } ; <%SAType*> [#uses=1] +@S1ptr = global %SType** @S1 ; <%SType***> [#uses=0] +@S2 = global %SType* @S2c ; <%SType**> [#uses=0] +@S3 = global %SAType* @S3c ; <%SAType**> [#uses=0] +@S1fld1a = global float* getelementptr (%SType* @S2c, i64 0, i32 1, i32 0) ; <float**> [#uses=0] +@S1fld1b = global float* getelementptr (%SType* @S2c, i64 0, i32 1, i32 0) ; <float**> [#uses=1] +@S1fld1bptr = global float** @S1fld1b ; <float***> [#uses=0] +@S2fld3 = global i8* getelementptr (%SType* @S2c, i64 0, i32 1, i32 1, i32 0) ; <i8**> [#uses=0] + +; ModuleID = 'constpointer.ll' +@cpt3 = global i32* @cpt1 ; <i32**> [#uses=1] +@cpt1 = global i32 4 ; <i32*> [#uses=2] +@cpt4 = global i32** @cpt3 ; <i32***> [#uses=0] +@cpt2 = global i32* @cpt1 ; <i32**> [#uses=0] +global float* @7 ; <float**>:0 [#uses=0] +global float* @7 ; <float**>:1 [#uses=0] +global float 0.000000e+00 ; <float*>:2 [#uses=3] +global float* @7 ; <float**>:3 [#uses=0] +@fptr = global void ()* @f ; <void ()**> [#uses=0] +@sptr1 = global [11 x i8]* @somestr ; <[11 x i8]**> [#uses=0] +@somestr2 = constant [11 x i8] c"hello world" ; <[11 x i8]*> [#uses=2] +@sptr2 = global [11 x i8]* @somestr2 ; <[11 x i8]**> [#uses=0] + +declare void @f() +; ModuleID = 'escaped_label.ll' + +define i32 @foo3() { + br label "foo`~!@#$%^&*()-_=+{}[]\\|;:',<.>/?" + +"foo`~!@#$%^&*()-_=+{}[]\\|;:',<.>/?": ; preds = %0 + ret i32 17 +} +; ModuleID = 'float.ll' +@F1 = global float 4.000000e+00 ; <float*> [#uses=0] +@D1 = global double 4.000000e+00 ; <double*> [#uses=0] +; ModuleID = 'fold-fpcast.ll' + +define i32 @test1() { + ret i32 1080872141 +} + +define float @test1002() { + ret float 0x36E1000000000000 +} + +define i64 @test3() { + ret i64 4614256656431372362 +} + +define double @test4() { + ret double 2.075076e-322 +} +; ModuleID = 'forwardreftest.ll' + %myfn = type float (i32, double, i32, i16) + %myty = type i32 + %thisfuncty = type i32 (i32)* + +declare void @F(%thisfuncty, %thisfuncty, %thisfuncty) + +define i32 @zarro2(i32 %Func) { +Startup: + add i32 0, 10 ; <i32>:0 [#uses=0] + ret i32 0 +} + +define i32 @test1004(i32) { + call void @F( %thisfuncty @zarro2, %thisfuncty @test1004, %thisfuncty @foozball ) + ret i32 0 +} + +define i32 @foozball(i32) { + ret i32 0 +} + +; ModuleID = 'globalredefinition.ll' +@A = global i32* @B ; <i32**> [#uses=0] +@B = global i32 7 ; <i32*> [#uses=1] + +define void @X() { + ret void +} +; ModuleID = 'global_section.ll' +@GlobSec = global i32 4, section "foo", align 16 + +define void @test1005() section "bar" { + ret void +} + +; ModuleID = 'globalvars.ll' +@MyVar = external global i32 ; <i32*> [#uses=1] +@MyIntList = external global { \2*, i32 } ; <{ \2*, i32 }*> [#uses=1] +external global i32 ; <i32*>:0 [#uses=0] +@AConst = constant i32 123 ; <i32*> [#uses=0] +@AString = constant [4 x i8] c"test" ; <[4 x i8]*> [#uses=0] +@ZeroInit = global { [100 x i32], [40 x float] } zeroinitializer ; <{ [100 x i32], [40 x float] }*> [#uses=0] + +define i32 @foo10015(i32 %blah) { + store i32 5, i32* @MyVar + %idx = getelementptr { \2*, i32 }* @MyIntList, i64 0, i32 1 ; <i32*> [#uses=1] + store i32 12, i32* %idx + ret i32 %blah +} +; ModuleID = 'indirectcall2.ll' + +define i64 @test1006(i64 %X) { + ret i64 %X +} + +define i64 @fib(i64 %n) { +; <label>:0 + %T = icmp ult i64 %n, 2 ; <i1> [#uses=1] + br i1 %T, label %BaseCase, label %RecurseCase + +RecurseCase: ; preds = %0 + %result = call i64 @test1006( i64 %n ) ; <i64> [#uses=0] + br label %BaseCase + +BaseCase: ; preds = %RecurseCase, %0 + %X = phi i64 [ 1, %0 ], [ 2, %RecurseCase ] ; <i64> [#uses=1] + ret i64 %X +} +; ModuleID = 'indirectcall.ll' + +declare i32 @atoi(i8*) + +define i64 @fibonacc(i64 %n) { + icmp ult i64 %n, 2 ; <i1>:1 [#uses=1] + br i1 %1, label %BaseCase, label %RecurseCase + +BaseCase: ; preds = %0 + ret i64 1 + +RecurseCase: ; preds = %0 + %n2 = sub i64 %n, 2 ; <i64> [#uses=1] + %n1 = sub i64 %n, 1 ; <i64> [#uses=1] + %f2 = call i64 @fibonacc( i64 %n2 ) ; <i64> [#uses=1] + %f1 = call i64 @fibonacc( i64 %n1 ) ; <i64> [#uses=1] + %result = add i64 %f2, %f1 ; <i64> [#uses=1] + ret i64 %result +} + +define i64 @realmain(i32 %argc, i8** %argv) { +; <label>:0 + icmp eq i32 %argc, 2 ; <i1>:1 [#uses=1] + br i1 %1, label %HasArg, label %Continue + +HasArg: ; preds = %0 + %n1 = add i32 1, 1 ; <i32> [#uses=1] + br label %Continue + +Continue: ; preds = %HasArg, %0 + %n = phi i32 [ %n1, %HasArg ], [ 1, %0 ] ; <i32> [#uses=1] + %N = sext i32 %n to i64 ; <i64> [#uses=1] + %F = call i64 @fib( i64 %N ) ; <i64> [#uses=1] + ret i64 %F +} + +define i64 @trampoline(i64 %n, i64 (i64)* %fibfunc) { + %F = call i64 %fibfunc( i64 %n ) ; <i64> [#uses=1] + ret i64 %F +} + +define i32 @main2() { + %Result = call i64 @trampoline( i64 10, i64 (i64)* @fib ) ; <i64> [#uses=1] + %Result.upgrd.1 = trunc i64 %Result to i32 ; <i32> [#uses=1] + ret i32 %Result.upgrd.1 +} +; ModuleID = 'inlineasm.ll' +module asm "this is an inline asm block" +module asm "this is another inline asm block" + +define i32 @test1007() { + %X = call i32 asm "tricky here $0, $1", "=r,r"( i32 4 ) ; <i32> [#uses=1] + call void asm sideeffect "eieio", ""( ) + ret i32 %X +} +; ModuleID = 'instructions.ll' + +define i32 @test_extractelement(<4 x i32> %V) { + %R = extractelement <4 x i32> %V, i32 1 ; <i32> [#uses=1] + ret i32 %R +} + +define <4 x i32> @test_insertelement(<4 x i32> %V) { + %R = insertelement <4 x i32> %V, i32 0, i32 0 ; <<4 x i32>> [#uses=1] + ret <4 x i32> %R +} + +define <4 x i32> @test_shufflevector_u(<4 x i32> %V) { + %R = shufflevector <4 x i32> %V, <4 x i32> %V, <4 x i32> < i32 1, i32 undef, i32 7, i32 2 > ; <<4 x i32>> [#uses=1] + ret <4 x i32> %R +} + +define <4 x float> @test_shufflevector_f(<4 x float> %V) { + %R = shufflevector <4 x float> %V, <4 x float> undef, <4 x i32> < i32 1, i32 undef, i32 7, i32 2 > ; <<4 x float>> [#uses=1] + ret <4 x float> %R +} +; ModuleID = 'intrinsics.ll' + +declare i1 @llvm.isunordered.f32(float, float) + +declare i1 @llvm.isunordered.f64(double, double) + +declare void @llvm.prefetch(i8*, i32, i32) + +declare i32 @upgrd.rm.llvm.ctpop.i8(i8) + +declare i32 @upgrd.rm.llvm.ctpop.i16(i16) + +declare i32 @upgrd.rm.llvm.ctpop.i32(i32) + +declare i32 @upgrd.rm.llvm.ctpop.i64(i64) + +declare i32 @upgrd.rm.llvm.cttz.i8(i8) + +declare i32 @upgrd.rm.llvm.cttz.i16(i16) + +declare i32 @upgrd.rm.llvm.cttz.i32(i32) + +declare i32 @upgrd.rm.llvm.cttz.i64(i64) + +declare i32 @upgrd.rm.llvm.ctlz.i8(i8) + +declare i32 @upgrd.rm.llvm.ctlz.i16(i16) + +declare i32 @upgrd.rm.llvm.ctlz.i32(i32) + +declare i32 @upgrd.rm.llvm.ctlz.i64(i64) + +declare float @llvm.sqrt.f32(float) + +declare double @llvm.sqrt.f64(double) + +define void @libm() { + fcmp uno float 1.000000e+00, 2.000000e+00 ; <i1>:1 [#uses=0] + fcmp uno double 3.000000e+00, 4.000000e+00 ; <i1>:2 [#uses=0] + call void @llvm.prefetch( i8* null, i32 1, i32 3 ) + call float @llvm.sqrt.f32( float 5.000000e+00 ) ; <float>:3 [#uses=0] + call double @llvm.sqrt.f64( double 6.000000e+00 ) ; <double>:4 [#uses=0] + call i32 @llvm.ctpop.i8( i8 10 ) ; <i32>:5 [#uses=1] + bitcast i32 %5 to i32 ; <i32>:6 [#uses=0] + call i32 @llvm.ctpop.i16( i16 11 ) ; <i32>:7 [#uses=1] + bitcast i32 %7 to i32 ; <i32>:8 [#uses=0] + call i32 @llvm.ctpop.i32( i32 12 ) ; <i32>:9 [#uses=1] + bitcast i32 %9 to i32 ; <i32>:10 [#uses=0] + call i32 @llvm.ctpop.i64( i64 13 ) ; <i32>:11 [#uses=1] + bitcast i32 %11 to i32 ; <i32>:12 [#uses=0] + call i32 @llvm.ctlz.i8( i8 14 ) ; <i32>:13 [#uses=1] + bitcast i32 %13 to i32 ; <i32>:14 [#uses=0] + call i32 @llvm.ctlz.i16( i16 15 ) ; <i32>:15 [#uses=1] + bitcast i32 %15 to i32 ; <i32>:16 [#uses=0] + call i32 @llvm.ctlz.i32( i32 16 ) ; <i32>:17 [#uses=1] + bitcast i32 %17 to i32 ; <i32>:18 [#uses=0] + call i32 @llvm.ctlz.i64( i64 17 ) ; <i32>:19 [#uses=1] + bitcast i32 %19 to i32 ; <i32>:20 [#uses=0] + call i32 @llvm.cttz.i8( i8 18 ) ; <i32>:21 [#uses=1] + bitcast i32 %21 to i32 ; <i32>:22 [#uses=0] + call i32 @llvm.cttz.i16( i16 19 ) ; <i32>:23 [#uses=1] + bitcast i32 %23 to i32 ; <i32>:24 [#uses=0] + call i32 @llvm.cttz.i32( i32 20 ) ; <i32>:25 [#uses=1] + bitcast i32 %25 to i32 ; <i32>:26 [#uses=0] + call i32 @llvm.cttz.i64( i64 21 ) ; <i32>:27 [#uses=1] + bitcast i32 %27 to i32 ; <i32>:28 [#uses=0] + ret void +} + +declare i32 @llvm.ctpop.i8(i8) + +declare i32 @llvm.ctpop.i16(i16) + +declare i32 @llvm.ctpop.i32(i32) + +declare i32 @llvm.ctpop.i64(i64) + +declare i32 @llvm.ctlz.i8(i8) + +declare i32 @llvm.ctlz.i16(i16) + +declare i32 @llvm.ctlz.i32(i32) + +declare i32 @llvm.ctlz.i64(i64) + +declare i32 @llvm.cttz.i8(i8) + +declare i32 @llvm.cttz.i16(i16) + +declare i32 @llvm.cttz.i32(i32) + +declare i32 @llvm.cttz.i64(i64) + +; ModuleID = 'packed.ll' +@foo1 = external global <4 x float> ; <<4 x float>*> [#uses=2] +@foo102 = external global <2 x i32> ; <<2 x i32>*> [#uses=2] + +define void @main3() { + store <4 x float> < float 1.000000e+00, float 2.000000e+00, float 3.000000e+00, float 4.000000e+00 >, <4 x float>* @foo1 + store <2 x i32> < i32 4, i32 4 >, <2 x i32>* @foo102 + %l1 = load <4 x float>* @foo1 ; <<4 x float>> [#uses=0] + %l2 = load <2 x i32>* @foo102 ; <<2 x i32>> [#uses=0] + ret void +} + +; ModuleID = 'properties.ll' +target datalayout = "e-p:32:32" +target triple = "proc-vend-sys" +deplibs = [ "m", "c" ] +; ModuleID = 'prototype.ll' + +declare i32 @bar1017(i32 %in) + +define i32 @foo1016(i32 %blah) { + %xx = call i32 @bar1017( i32 %blah ) ; <i32> [#uses=1] + ret i32 %xx +} + +; ModuleID = 'recursivetype.ll' + %list = type { %list*, i32 } + +declare i8* @malloc(i32) + +define void @InsertIntoListTail(%list** %L, i32 %Data) { +bb1: + %reg116 = load %list** %L ; <%list*> [#uses=1] + %cast1004 = inttoptr i64 0 to %list* ; <%list*> [#uses=1] + %cond1000 = icmp eq %list* %reg116, %cast1004 ; <i1> [#uses=1] + br i1 %cond1000, label %bb3, label %bb2 + +bb2: ; preds = %bb2, %bb1 + %reg117 = phi %list** [ %reg118, %bb2 ], [ %L, %bb1 ] ; <%list**> [#uses=1] + %cast1010 = bitcast %list** %reg117 to %list*** ; <%list***> [#uses=1] + %reg118 = load %list*** %cast1010 ; <%list**> [#uses=3] + %reg109 = load %list** %reg118 ; <%list*> [#uses=1] + %cast1005 = inttoptr i64 0 to %list* ; <%list*> [#uses=1] + %cond1001 = icmp ne %list* %reg109, %cast1005 ; <i1> [#uses=1] + br i1 %cond1001, label %bb2, label %bb3 + +bb3: ; preds = %bb2, %bb1 + %reg119 = phi %list** [ %reg118, %bb2 ], [ %L, %bb1 ] ; <%list**> [#uses=1] + %cast1006 = bitcast %list** %reg119 to i8** ; <i8**> [#uses=1] + %reg111 = call i8* @malloc( i32 16 ) ; <i8*> [#uses=3] + store i8* %reg111, i8** %cast1006 + %reg111.upgrd.1 = ptrtoint i8* %reg111 to i64 ; <i64> [#uses=1] + %reg1002 = add i64 %reg111.upgrd.1, 8 ; <i64> [#uses=1] + %reg1002.upgrd.2 = inttoptr i64 %reg1002 to i8* ; <i8*> [#uses=1] + %cast1008 = bitcast i8* %reg1002.upgrd.2 to i32* ; <i32*> [#uses=1] + store i32 %Data, i32* %cast1008 + %cast1003 = inttoptr i64 0 to i64* ; <i64*> [#uses=1] + %cast1009 = bitcast i8* %reg111 to i64** ; <i64**> [#uses=1] + store i64* %cast1003, i64** %cast1009 + ret void +} + +define %list* @FindData(%list* %L, i32 %Data) { +bb1: + br label %bb2 + +bb2: ; preds = %bb6, %bb1 + %reg115 = phi %list* [ %reg116, %bb6 ], [ %L, %bb1 ] ; <%list*> [#uses=4] + %cast1014 = inttoptr i64 0 to %list* ; <%list*> [#uses=1] + %cond1011 = icmp ne %list* %reg115, %cast1014 ; <i1> [#uses=1] + br i1 %cond1011, label %bb4, label %bb3 + +bb3: ; preds = %bb2 + ret %list* null + +bb4: ; preds = %bb2 + %idx = getelementptr %list* %reg115, i64 0, i32 1 ; <i32*> [#uses=1] + %reg111 = load i32* %idx ; <i32> [#uses=1] + %cond1013 = icmp ne i32 %reg111, %Data ; <i1> [#uses=1] + br i1 %cond1013, label %bb6, label %bb5 + +bb5: ; preds = %bb4 + ret %list* %reg115 + +bb6: ; preds = %bb4 + %idx2 = getelementptr %list* %reg115, i64 0, i32 0 ; <%list**> [#uses=1] + %reg116 = load %list** %idx2 ; <%list*> [#uses=1] + br label %bb2 +} +; ModuleID = 'simplecalltest.ll' + %FunTy = type i32 (i32) + +define void @invoke1019(%FunTy* %x) { + %foo = call i32 %x( i32 123 ) ; <i32> [#uses=0] + ret void +} + +define i32 @main4(i32 %argc, i8** %argv, i8** %envp) { + %retval = call i32 @test1008( i32 %argc ) ; <i32> [#uses=2] + %two = add i32 %retval, %retval ; <i32> [#uses=1] + %retval2 = call i32 @test1008( i32 %argc ) ; <i32> [#uses=1] + %two2 = add i32 %two, %retval2 ; <i32> [#uses=1] + call void @invoke1019( %FunTy* @test1008 ) + ret i32 %two2 +} + +define i32 @test1008(i32 %i0) { + ret i32 %i0 +} +; ModuleID = 'smallest.ll' +; ModuleID = 'small.ll' + %x = type i32 + +define i32 @foo1020(i32 %in) { +label: + ret i32 2 +} +; ModuleID = 'testalloca.ll' + %inners = type { float, { i8 } } + %struct = type { i32, %inners, i64 } + +define i32 @testfunction(i32 %i0, i32 %j0) { + alloca i8, i32 5 ; <i8*>:1 [#uses=0] + %ptr = alloca i32 ; <i32*> [#uses=2] + store i32 3, i32* %ptr + %val = load i32* %ptr ; <i32> [#uses=0] + %sptr = alloca %struct ; <%struct*> [#uses=2] + %nsptr = getelementptr %struct* %sptr, i64 0, i32 1 ; <%inners*> [#uses=1] + %ubsptr = getelementptr %inners* %nsptr, i64 0, i32 1 ; <{ i8 }*> [#uses=1] + %idx = getelementptr { i8 }* %ubsptr, i64 0, i32 0 ; <i8*> [#uses=1] + store i8 4, i8* %idx + %fptr = getelementptr %struct* %sptr, i64 0, i32 1, i32 0 ; <float*> [#uses=1] + store float 4.000000e+00, float* %fptr + ret i32 3 +} +; ModuleID = 'testconstants.ll' +@somestr3 = constant [11 x i8] c"hello world" +@array99 = constant [2 x i32] [ i32 12, i32 52 ] +constant { i32, i32 } { i32 4, i32 3 } ; <{ i32, i32 }*>:0 [#uses=0] + +define [2 x i32]* @testfunction99(i32 %i0, i32 %j0) { + ret [2 x i32]* @array +} + +define i8* @otherfunc(i32, double) { + %somestr = getelementptr [11 x i8]* @somestr3, i64 0, i64 0 ; <i8*> [#uses=1] + ret i8* %somestr +} + +define i8* @yetanotherfunc(i32, double) { + ret i8* null +} + +define i32 @negativeUnsigned() { + ret i32 -1 +} + +define i32 @largeSigned() { + ret i32 -394967296 +} +; ModuleID = 'testlogical.ll' + +define i32 @simpleAdd(i32 %i0, i32 %j0) { + %t1 = xor i32 %i0, %j0 ; <i32> [#uses=1] + %t2 = or i32 %i0, %j0 ; <i32> [#uses=1] + %t3 = and i32 %t1, %t2 ; <i32> [#uses=1] + ret i32 %t3 +} +; ModuleID = 'testmemory.ll' + %complexty = type { i32, { [4 x i8*], float }, double } + %struct = type { i32, { float, { i8 } }, i64 } + +define i32 @main6() { + call i32 @testfunction98( i64 0, i64 1 ) + ret i32 0 +} + +define i32 @testfunction98(i64 %i0, i64 %j0) { + %array0 = malloc [4 x i8] ; <[4 x i8]*> [#uses=2] + %size = add i32 2, 2 ; <i32> [#uses=1] + %array1 = malloc i8, i32 4 ; <i8*> [#uses=1] + %array2 = malloc i8, i32 %size ; <i8*> [#uses=1] + %idx = getelementptr [4 x i8]* %array0, i64 0, i64 2 ; <i8*> [#uses=1] + store i8 123, i8* %idx + free [4 x i8]* %array0 + free i8* %array1 + free i8* %array2 + %aa = alloca %complexty, i32 5 ; <%complexty*> [#uses=1] + %idx2 = getelementptr %complexty* %aa, i64 %i0, i32 1, i32 0, i64 %j0 ; <i8**> [#uses=1] + store i8* null, i8** %idx2 + %ptr = alloca i32 ; <i32*> [#uses=2] + store i32 3, i32* %ptr + %val = load i32* %ptr ; <i32> [#uses=0] + %sptr = alloca %struct ; <%struct*> [#uses=1] + %ubsptr = getelementptr %struct* %sptr, i64 0, i32 1, i32 1 ; <{ i8 }*> [#uses=1] + %idx3 = getelementptr { i8 }* %ubsptr, i64 0, i32 0 ; <i8*> [#uses=1] + store i8 4, i8* %idx3 + ret i32 3 +} +; ModuleID = 'testswitch.ll' + %int = type i32 + +define i32 @squared(i32 %i0) { + switch i32 %i0, label %Default [ + i32 1, label %Case1 + i32 2, label %Case2 + i32 4, label %Case4 + ] + +Default: ; preds = %0 + ret i32 -1 + +Case1: ; preds = %0 + ret i32 1 + +Case2: ; preds = %0 + ret i32 4 + +Case4: ; preds = %0 + ret i32 16 +} +; ModuleID = 'testvarargs.ll' + +declare i32 @printf(i8*, ...) + +define i32 @testvarar() { + call i32 (i8*, ...)* @printf( i8* null, i32 12, i8 42 ) ; <i32>:1 [#uses=1] + ret i32 %1 +} +; ModuleID = 'undefined.ll' +@X2 = global i32 undef ; <i32*> [#uses=0] + +declare i32 @atoi(i8*) + +define i32 @test1009() { + ret i32 undef +} + +define i32 @test1003() { + %X = add i32 undef, 1 ; <i32> [#uses=1] + ret i32 %X +} +; ModuleID = 'unreachable.ll' + +declare void @bar() + +define i32 @foo1021() { + unreachable +} + +define double @xyz() { + call void @bar( ) + unreachable +} +; ModuleID = 'varargs.ll' + +declare void @llvm.va_start(i8* %ap) + +declare void @llvm.va_copy(i8* %aq, i8* %ap) + +declare void @llvm.va_end(i8* %ap) + +define i32 @test1010(i32 %X, ...) { + %ap = alloca i8* ; <i8**> [#uses=4] + %va.upgrd.1 = bitcast i8** %ap to i8* ; <i8*> [#uses=1] + call void @llvm.va_start( i8* %va.upgrd.1 ) + %tmp = va_arg i8** %ap, i32 ; <i32> [#uses=1] + %aq = alloca i8* ; <i8**> [#uses=2] + %va0.upgrd.2 = bitcast i8** %aq to i8* ; <i8*> [#uses=1] + %va1.upgrd.3 = bitcast i8** %ap to i8* ; <i8*> [#uses=1] + call void @llvm.va_copy( i8* %va0.upgrd.2, i8* %va1.upgrd.3 ) + %va.upgrd.4 = bitcast i8** %aq to i8* ; <i8*> [#uses=1] + call void @llvm.va_end( i8* %va.upgrd.4 ) + %va.upgrd.5 = bitcast i8** %ap to i8* ; <i8*> [#uses=1] + call void @llvm.va_end( i8* %va.upgrd.5 ) + ret i32 %tmp +} +; ModuleID = 'varargs_new.ll' + +declare void @llvm.va_start(i8*) + +declare void @llvm.va_copy(i8*, i8*) + +declare void @llvm.va_end(i8*) + +define i32 @test1011(i32 %X, ...) { + %ap = alloca i8* ; <i8**> [#uses=4] + %aq = alloca i8* ; <i8**> [#uses=2] + %va.upgrd.1 = bitcast i8** %ap to i8* ; <i8*> [#uses=1] + call void @llvm.va_start( i8* %va.upgrd.1 ) + %tmp = va_arg i8** %ap, i32 ; <i32> [#uses=1] + %apv = load i8** %ap ; <i8*> [#uses=1] + %va0.upgrd.2 = bitcast i8** %aq to i8* ; <i8*> [#uses=1] + %va1.upgrd.3 = bitcast i8* %apv to i8* ; <i8*> [#uses=1] + call void @llvm.va_copy( i8* %va0.upgrd.2, i8* %va1.upgrd.3 ) + %va.upgrd.4 = bitcast i8** %aq to i8* ; <i8*> [#uses=1] + call void @llvm.va_end( i8* %va.upgrd.4 ) + %va.upgrd.5 = bitcast i8** %ap to i8* ; <i8*> [#uses=1] + call void @llvm.va_end( i8* %va.upgrd.5 ) + ret i32 %tmp +} +; ModuleID = 'weirdnames.ll' + "&^ " = type { i32 } +@"%.*+ foo" = global "&^ " { i32 5 } ; <"&^ "*> [#uses=0] +@"0" = global float 0.000000e+00 ; <float*> [#uses=0] diff --git a/test/Feature/load_module.ll b/test/Feature/load_module.ll new file mode 100644 index 0000000..356eceb --- /dev/null +++ b/test/Feature/load_module.ll @@ -0,0 +1,10 @@ +; PR1318 +; RUN: llvm-as < %s | opt -load=%llvmlibsdir/LLVMHello%shlibext -hello \ +; RUN: -disable-output - |& grep Hello + +@junk = global i32 0 + +define i32* @somefunk() { + ret i32* @junk +} + diff --git a/test/Feature/newcasts.ll b/test/Feature/newcasts.ll new file mode 100644 index 0000000..d237157 --- /dev/null +++ b/test/Feature/newcasts.ll @@ -0,0 +1,28 @@ +; RUN: llvm-as < %s | llvm-dis > %t1.ll +; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll +; RUN: diff %t1.ll %t2.ll + +define void @"NewCasts" (i16 %x) { + %a = zext i16 %x to i32 + %b = sext i16 %x to i32 + %c = trunc i16 %x to i8 + %d = uitofp i16 %x to float + %e = sitofp i16 %x to double + %f = fptoui float %d to i16 + %g = fptosi double %e to i16 + %i = fpext float %d to double + %j = fptrunc double %i to float + %k = bitcast i32 %a to float + %l = inttoptr i16 %x to i32* + %m = ptrtoint i32* %l to i64 + ret void +} + + +define i16 @"ZExtConst" () { + ret i16 trunc ( i32 zext ( i16 42 to i32) to i16 ) +} + +define i16 @"SExtConst" () { + ret i16 trunc (i32 sext (i16 42 to i32) to i16 ) +} diff --git a/test/Feature/opaquetypes.ll b/test/Feature/opaquetypes.ll new file mode 100644 index 0000000..92efaeb --- /dev/null +++ b/test/Feature/opaquetypes.ll @@ -0,0 +1,61 @@ +; RUN: llvm-upgrade < %s | llvm-as | llvm-dis > %t1.ll +; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll +; RUN: diff %t1.ll %t2.ll + +; This test case is used to test opaque type processing, forward references, +; and recursive types. Oh my. +; + +%SQ1 = type { int } +%ITy = type opaque +%SQ2 = type { %ITy } +%ITy = type int + + +%CCC = type { \2* } +%BBB = type { \2*, \2 * } +%AAA = type { \2*, {\2*}, [12x{\2*}], {[1x{\2*}]} } + +; Test numbered types +type %CCC +type %BBB +%Composite = type { %0, %1 } + +; Test simple opaque type resolution... +%intty = type opaque +%intty = type int + +; Perform a simple forward reference... +%ty1 = type { %ty2, int } +%ty2 = type float + +; Do a recursive type... +%list = type { %list * } +%listp = type { %listp } * + +; Do two mutually recursive types... +%TyA = type { %ty2, %TyB * } +%TyB = type { double, %TyA * } + +; A complex recursive type... +%Y = type { {%Y*}, %Y* } +%Z = type { { %Z * }, [12x%Z] *, {{{ %Z * }}} } + +; More ridiculous test cases... +%A = type [ 123x %A*] +%M = type %M (%M, %M) * +%P = type %P* + +; Recursive ptrs +%u = type %v* +%v = type %u* + +; Test the parser for unnamed recursive types... +%P1 = type \1 * +%Y1 = type { { \3 * }, \2 * } +%Z1 = type { { \3 * }, [12x\3] *, { { { \5 * } } } } + +implementation + + + diff --git a/test/Feature/packed.ll b/test/Feature/packed.ll new file mode 100755 index 0000000..a8d9370 --- /dev/null +++ b/test/Feature/packed.ll @@ -0,0 +1,17 @@ +; RUN: llvm-upgrade < %s | llvm-as | llvm-dis > %t1.ll +; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll +; RUN: diff %t1.ll %t2.ll + +%foo1 = uninitialized global <4 x float>; +%foo2 = uninitialized global <2 x int>; + +implementation ; Functions: + +void %main() +{ + store <4 x float> <float 1.0, float 2.0, float 3.0, float 4.0>, <4 x float>* %foo1 + store <2 x int> <int 4, int 4>, <2 x int>* %foo2 + %l1 = load <4 x float>* %foo1 + %l2 = load <2 x int>* %foo2 + ret void +} diff --git a/test/Feature/packed_struct.ll b/test/Feature/packed_struct.ll new file mode 100755 index 0000000..5bf609b --- /dev/null +++ b/test/Feature/packed_struct.ll @@ -0,0 +1,33 @@ +; RUN: llvm-as < %s | llvm-dis > %t1.ll +; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll +; RUN: diff %t1.ll %t2.ll +; RUN: not grep cast %t2.ll +; RUN: grep {\<\{} %t2.ll +; END. + +%struct.anon = type <{ i8, i32, i32, i32 }> +@foos = external global %struct.anon +@bara = external global [2 x <{ i32, i8 }>] + +;initializers should work for packed and non-packed the same way +@E1 = global <{i8, i32, i32}> <{i8 1, i32 2, i32 3}> +@E2 = global {i8, i32, i32} {i8 4, i32 5, i32 6} + + +define i32 @main() +{ + %tmp = load i32* getelementptr (%struct.anon* @foos, i32 0, i32 1) ; <i32> [#uses=1] + %tmp3 = load i32* getelementptr (%struct.anon* @foos, i32 0, i32 2) ; <i32> [#uses=1] + %tmp6 = load i32* getelementptr (%struct.anon* @foos, i32 0, i32 3) ; <i32> [#uses=1] + %tmp4 = add i32 %tmp3, %tmp ; <i32> [#uses=1] + %tmp7 = add i32 %tmp4, %tmp6 ; <i32> [#uses=1] + ret i32 %tmp7 +} + +define i32 @bar() { +entry: + %tmp = load i32* getelementptr([2 x <{ i32, i8 }>]* @bara, i32 0, i32 0, i32 0 ) ; <i32> [#uses=1] + %tmp4 = load i32* getelementptr ([2 x <{ i32, i8 }>]* @bara, i32 0, i32 1, i32 0) ; <i32> [#uses=1] + %tmp5 = add i32 %tmp4, %tmp ; <i32> [#uses=1] + ret i32 %tmp5 +} diff --git a/test/Feature/paramattrs.ll b/test/Feature/paramattrs.ll new file mode 100644 index 0000000..01dc2fa --- /dev/null +++ b/test/Feature/paramattrs.ll @@ -0,0 +1,22 @@ +; RUN: llvm-as < %s | llvm-dis > %t1.ll +; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll +; RUN: diff %t1.ll %t2.ll + +%ZFunTy = type i32(i8 zext) +%SFunTy = type i32(i8 sext) + +declare i16 @"test"(i16 sext %arg) sext +declare i8 @"test2" (i16 zext %a2) zext + +declare i32 @"test3"(i32* noalias %p) + +declare void @exit(i32) noreturn nounwind + +define i32 @main(i32 %argc, i8 **%argv) nounwind inreg { + %val = trunc i32 %argc to i16 + %res1 = call i16 (i16 sext) sext *@test(i16 %val) + %two = add i16 %res1, %res1 + %res2 = call i8 @test2(i16 %two zext) zext + %retVal = sext i16 %two to i32 + ret i32 %retVal +} diff --git a/test/Feature/properties.ll b/test/Feature/properties.ll new file mode 100644 index 0000000..e906f22 --- /dev/null +++ b/test/Feature/properties.ll @@ -0,0 +1,10 @@ +; RUN: llvm-upgrade < %s | llvm-as | llvm-dis > %t1.ll +; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll +; RUN: diff %t1.ll %t2.ll + + +target endian = little +target pointersize = 32 +target triple = "proc-vend-sys" +deplibs = [ "m", "c" ] + diff --git a/test/Feature/prototype.ll b/test/Feature/prototype.ll new file mode 100644 index 0000000..9bab73f --- /dev/null +++ b/test/Feature/prototype.ll @@ -0,0 +1,14 @@ +; RUN: llvm-upgrade < %s | llvm-as | llvm-dis > %t1.ll +; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll +; RUN: diff %t1.ll %t2.ll + +implementation + +declare int "bar"(int %in) + +int "foo"(int %blah) +begin + %xx = call int %bar(int %blah) + ret int %xx +end + diff --git a/test/Feature/recursivetype.ll b/test/Feature/recursivetype.ll new file mode 100644 index 0000000..9ea3484 --- /dev/null +++ b/test/Feature/recursivetype.ll @@ -0,0 +1,108 @@ +; RUN: llvm-upgrade < %s | llvm-as | llvm-dis > %t1.ll +; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll +; RUN: diff %t1.ll %t2.ll + +; This file contains the output from the following compiled C code: +; typedef struct list { +; struct list *Next; +; int Data; +; } list; +; +; // Iterative insert fn +; void InsertIntoListTail(list **L, int Data) { +; while (*L) +; L = &(*L)->Next; +; *L = (list*)malloc(sizeof(list)); +; (*L)->Data = Data; +; (*L)->Next = 0; +; } +; +; // Recursive list search fn +; list *FindData(list *L, int Data) { +; if (L == 0) return 0; +; if (L->Data == Data) return L; +; return FindData(L->Next, Data); +; } +; +; void DoListStuff() { +; list *MyList = 0; +; InsertIntoListTail(&MyList, 100); +; InsertIntoListTail(&MyList, 12); +; InsertIntoListTail(&MyList, 42); +; InsertIntoListTail(&MyList, 1123); +; InsertIntoListTail(&MyList, 1213); +; +; if (FindData(MyList, 75)) foundIt(); +; if (FindData(MyList, 42)) foundIt(); +; if (FindData(MyList, 700)) foundIt(); +; } + +%list = type { %list*, int } + +declare sbyte *"malloc"(uint) + +;;********************** +implementation +;;********************** + +void "InsertIntoListTail"(%list** %L, int %Data) +begin +bb1: + %reg116 = load %list** %L ;;<%list*> + %cast1004 = cast ulong 0 to %list* ;;<%list*> + %cond1000 = seteq %list* %reg116, %cast1004 ;;<bool> + br bool %cond1000, label %bb3, label %bb2 + +bb2: + %reg117 = phi %list** [ %reg118, %bb2 ], [ %L, %bb1 ] ;;<%list**> + %cast1010 = cast %list** %reg117 to %list*** ;;<%list***> + %reg118 = load %list*** %cast1010 ;;<%list**> + %reg109 = load %list** %reg118 ;;<%list*> + %cast1005 = cast ulong 0 to %list* ;;<%list*> + %cond1001 = setne %list* %reg109, %cast1005 ;;<bool> + br bool %cond1001, label %bb2, label %bb3 + +bb3: + %reg119 = phi %list** [ %reg118, %bb2 ], [ %L, %bb1 ] ;;<%list**> + %cast1006 = cast %list** %reg119 to sbyte** ;;<sbyte**> + %reg111 = call sbyte* %malloc(uint 16) ;;<sbyte*> + store sbyte* %reg111, sbyte** %cast1006 ;;<void> + %reg111 = cast sbyte* %reg111 to ulong + %reg1002 = add ulong %reg111, 8 + %reg1002 = cast ulong %reg1002 to sbyte* ;;<sbyte*> + %cast1008 = cast sbyte* %reg1002 to int* ;;<int*> + store int %Data, int* %cast1008 ;;<void> + %cast1003 = cast ulong 0 to ulong* ;;<ulong*> + %cast1009 = cast sbyte* %reg111 to ulong** ;;<ulong**> + store ulong* %cast1003, ulong** %cast1009 ;;<void> + ret void +end + +%list* "FindData"(%list* %L, int %Data) +begin +bb1: + br label %bb2 + +bb2: + %reg115 = phi %list* [ %reg116, %bb6 ], [ %L, %bb1 ] ;;<%list*> + %cast1014 = cast ulong 0 to %list* ;;<%list*> + %cond1011 = setne %list* %reg115, %cast1014 ;;<bool> + br bool %cond1011, label %bb4, label %bb3 + +bb3: + ret %list* null + +bb4: + %idx = getelementptr %list* %reg115, long 0, uint 1 ;;<int> + %reg111 = load int* %idx + %cond1013 = setne int %reg111, %Data ;;<bool> + br bool %cond1013, label %bb6, label %bb5 + +bb5: + ret %list* %reg115 + +bb6: + %idx2 = getelementptr %list* %reg115, long 0, uint 0 ;;<%list*> + %reg116 = load %list** %idx2 + br label %bb2 +end diff --git a/test/Feature/simplecalltest.ll b/test/Feature/simplecalltest.ll new file mode 100644 index 0000000..6f0b72e --- /dev/null +++ b/test/Feature/simplecalltest.ll @@ -0,0 +1,29 @@ +; RUN: llvm-upgrade < %s | llvm-as | llvm-dis > %t1.ll +; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll +; RUN: diff %t1.ll %t2.ll + +%FunTy = type int(int) + +implementation + +void "invoke"(%FunTy *%x) +begin + %foo = call %FunTy* %x(int 123) + ret void +end + +int "main"(int %argc, sbyte **%argv, sbyte **%envp) +begin + %retval = call int (int) *%test(int %argc) + %two = add int %retval, %retval + %retval2 = call int %test(int %argc) + + %two2 = add int %two, %retval2 + call void %invoke (%FunTy* %test) + ret int %two2 +end + +int "test"(int %i0) +begin + ret int %i0 +end diff --git a/test/Feature/small.ll b/test/Feature/small.ll new file mode 100644 index 0000000..6ef37c7 --- /dev/null +++ b/test/Feature/small.ll @@ -0,0 +1,14 @@ +; RUN: llvm-upgrade < %s | llvm-as | llvm-dis > %t1.ll +; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll +; RUN: diff %t1.ll %t2.ll + +%x = type int + +implementation + +int "foo"(int %in) +begin +label: + ret int 2 +end + diff --git a/test/Feature/smallest.ll b/test/Feature/smallest.ll new file mode 100644 index 0000000..910af3c --- /dev/null +++ b/test/Feature/smallest.ll @@ -0,0 +1,7 @@ +; RUN: llvm-upgrade < %s | llvm-as | llvm-dis > %t1.ll +; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll +; RUN: diff %t1.ll %t2.ll + + +implementation + diff --git a/test/Feature/testalloca.ll b/test/Feature/testalloca.ll new file mode 100644 index 0000000..d05b70d --- /dev/null +++ b/test/Feature/testalloca.ll @@ -0,0 +1,28 @@ +; RUN: llvm-upgrade < %s | llvm-as | llvm-dis > %t1.ll +; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll +; RUN: diff %t1.ll %t2.ll + +%inners = type {float, {ubyte } } +%struct = type { int , {float, {ubyte } } , ulong } + +implementation + +int %testfunction(int %i0, int %j0) +begin + alloca ubyte, uint 5 + %ptr = alloca int ; yields {int*}:ptr + store int 3, int* %ptr ; yields {void} + %val = load int* %ptr ; yields {int}:val = int %3 + + %sptr = alloca %struct ; yields {%struct*}:sptr + %nsptr = getelementptr %struct * %sptr, long 0, uint 1 ; yields {inners*}:nsptr + %ubsptr = getelementptr %inners * %nsptr, long 0, uint 1 ; yields {{ubyte}*}:ubsptr + %idx = getelementptr {ubyte} * %ubsptr, long 0, uint 0 + store ubyte 4, ubyte* %idx + + %fptr = getelementptr %struct * %sptr, long 0, uint 1, uint 0 ; yields {float*}:fptr + store float 4.0, float * %fptr + + ret int 3 +end + diff --git a/test/Feature/testconstants.ll b/test/Feature/testconstants.ll new file mode 100644 index 0000000..7d9e119 --- /dev/null +++ b/test/Feature/testconstants.ll @@ -0,0 +1,33 @@ +; RUN: llvm-upgrade < %s | llvm-as | llvm-dis > %t1.ll +; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll +; RUN: diff %t1.ll %t2.ll + +%somestr = constant [11x sbyte] c"hello world" +%array = constant [2 x int] [ int 12, int 52 ] + constant { int, int } { int 4, int 3 } + +implementation + +[2 x int]* %testfunction(int %i0, int %j0) +begin + ret [2x int]* %array +end + +sbyte* %otherfunc(int, double) +begin + %somestr = getelementptr [11x sbyte]* %somestr, long 0, long 0 + ret sbyte* %somestr +end + +sbyte* %yetanotherfunc(int, double) +begin + ret sbyte* null ; Test null +end + +uint %negativeUnsigned() { + ret uint -1 +} + +int %largeSigned() { + ret int 3900000000 +} diff --git a/test/Feature/testlogical.ll b/test/Feature/testlogical.ll new file mode 100644 index 0000000..887699a --- /dev/null +++ b/test/Feature/testlogical.ll @@ -0,0 +1,14 @@ +; RUN: llvm-upgrade < %s | llvm-as | llvm-dis > %t1.ll +; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll +; RUN: diff %t1.ll %t2.ll + +implementation + +int "simpleAdd"(int %i0, int %j0) +begin + %t1 = xor int %i0, %j0 + %t2 = or int %i0, %j0 + %t3 = and int %t1, %t2 + ret int %t3 +end + diff --git a/test/Feature/testmemory.ll b/test/Feature/testmemory.ll new file mode 100644 index 0000000..ce48e57 --- /dev/null +++ b/test/Feature/testmemory.ll @@ -0,0 +1,45 @@ +; RUN: llvm-upgrade < %s | llvm-as | llvm-dis > %t1.ll +; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll +; RUN: diff %t1.ll %t2.ll + +%struct = type { int , {float, {ubyte } } , ulong } +%complexty = type {int, {[4 x sbyte *], float}, double} + +implementation + +int "main"() +begin + call int %testfunction(long 0, long 1) + ret int 0 +end + +int "testfunction"(long %i0, long %j0) +begin + %array0 = malloc [4 x ubyte] ; yields {[4 x ubyte]*}:array0 + %size = add uint 2, 2 ; yields {uint}:size = uint %4 + %array1 = malloc ubyte, uint 4 ; yields {ubyte*}:array1 + %array2 = malloc ubyte, uint %size ; yields {ubyte*}:array2 + + %idx = getelementptr [4 x ubyte]* %array0, long 0, long 2 + store ubyte 123, ubyte* %idx + free [4x ubyte]* %array0 + free ubyte* %array1 + free ubyte* %array2 + + + %aa = alloca %complexty, uint 5 + %idx2 = getelementptr %complexty* %aa, long %i0, uint 1, uint 0, long %j0 + store sbyte *null, sbyte** %idx2 + + %ptr = alloca int ; yields {int*}:ptr + store int 3, int* %ptr ; yields {void} + %val = load int* %ptr ; yields {int}:val = int %3 + + %sptr = alloca %struct ; yields {%struct*}:sptr + %ubsptr = getelementptr %struct * %sptr, long 0, uint 1, uint 1 ; yields {{ubyte}*}:ubsptr + %idx3 = getelementptr {ubyte} * %ubsptr, long 0, uint 0 + store ubyte 4, ubyte* %idx3 + + ret int 3 +end + diff --git a/test/Feature/testswitch.ll b/test/Feature/testswitch.ll new file mode 100644 index 0000000..8664ace --- /dev/null +++ b/test/Feature/testswitch.ll @@ -0,0 +1,25 @@ +; RUN: llvm-upgrade < %s | llvm-as | llvm-dis > %t1.ll +; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll +; RUN: diff %t1.ll %t2.ll + + %int = type int + +implementation + +int "squared"(%int %i0) +begin + switch int %i0, label %Default [ + int 1, label %Case1 + int 2, label %Case2 + int 4, label %Case4 ] + +Default: + ret int -1 ; Unrecognized input value + +Case1: + ret int 1 +Case2: + ret int 4 +Case4: + ret int 16 +end diff --git a/test/Feature/testvarargs.ll b/test/Feature/testvarargs.ll new file mode 100644 index 0000000..196ab01 --- /dev/null +++ b/test/Feature/testvarargs.ll @@ -0,0 +1,15 @@ +; RUN: llvm-upgrade < %s | llvm-as | llvm-dis > %t1.ll +; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll +; RUN: diff %t1.ll %t2.ll + +implementation + +declare int "printf"(sbyte*, ...) ;; Prototype for: int __builtin_printf(const char*, ...) + +int "testvarar"() +begin + call int(sbyte*, ...) *%printf(sbyte * null, int 12, sbyte 42); + ret int %0 +end + + diff --git a/test/Feature/undefined.ll b/test/Feature/undefined.ll new file mode 100644 index 0000000..dc1b7c5 --- /dev/null +++ b/test/Feature/undefined.ll @@ -0,0 +1,19 @@ +; RUN: llvm-upgrade < %s | llvm-as | llvm-dis > %t1.ll +; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll +; RUN: diff %t1.ll %t2.ll + + +%X = global int undef + +implementation + +declare int "atoi"(sbyte *) + +int %test() { + ret int undef +} + +int %test2() { + %X = add int undef, 1 + ret int %X +} diff --git a/test/Feature/unreachable.ll b/test/Feature/unreachable.ll new file mode 100644 index 0000000..48558dd --- /dev/null +++ b/test/Feature/unreachable.ll @@ -0,0 +1,17 @@ +; RUN: llvm-upgrade < %s | llvm-as | llvm-dis > %t1.ll +; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll +; RUN: diff %t1.ll %t2.ll + + +implementation + +declare void %bar() + +int %foo() { ;; Calling this function has undefined behavior + unreachable +} + +double %xyz() { + call void %bar() + unreachable ;; Bar must not return. +} diff --git a/test/Feature/varargs.ll b/test/Feature/varargs.ll new file mode 100644 index 0000000..672d96a --- /dev/null +++ b/test/Feature/varargs.ll @@ -0,0 +1,24 @@ +; RUN: llvm-upgrade < %s | llvm-as | llvm-dis > %t1.ll +; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll +; RUN: diff %t1.ll %t2.ll + +; Demonstrate all of the variable argument handling intrinsic functions plus +; the va_arg instruction. + +implementation +declare void %llvm.va_start(sbyte** %ap) +declare void %llvm.va_copy(sbyte** %aq, sbyte** %ap) +declare void %llvm.va_end(sbyte** %ap) + +int %test(int %X, ...) { + %ap = alloca sbyte* + call void %llvm.va_start(sbyte** %ap) + %tmp = va_arg sbyte** %ap, int + + %aq = alloca sbyte* + call void %llvm.va_copy(sbyte** %aq, sbyte** %ap) + call void %llvm.va_end(sbyte** %aq) + + call void %llvm.va_end(sbyte** %ap) + ret int %tmp +} diff --git a/test/Feature/varargs_new.ll b/test/Feature/varargs_new.ll new file mode 100644 index 0000000..a0e8c46 --- /dev/null +++ b/test/Feature/varargs_new.ll @@ -0,0 +1,33 @@ +; RUN: llvm-upgrade < %s | llvm-as | llvm-dis > %t1.ll +; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll +; RUN: diff %t1.ll %t2.ll + +; Demonstrate all of the variable argument handling intrinsic functions plus +; the va_arg instruction. + +implementation ; Functions: +declare void %llvm.va_start(sbyte**) +declare void %llvm.va_copy(sbyte**, sbyte*) +declare void %llvm.va_end(sbyte**) + +int %test(int %X, ...) { + ; Allocate two va_list items. On this target, va_list is of type sbyte* + %ap = alloca sbyte* ; <sbyte**> [#uses=4] + %aq = alloca sbyte* ; <sbyte**> [#uses=2] + + ; Initialize variable argument processing + call void %llvm.va_start(sbyte** %ap) + + ; Read a single integer argument + %tmp = va_arg sbyte** %ap, int ; <int> [#uses=1] + + ; Demonstrate usage of llvm.va_copy and llvm_va_end + %apv = load sbyte** %ap ; <sbyte*> [#uses=1] + call void %llvm.va_copy(sbyte** %aq, sbyte* %apv) + call void %llvm.va_end(sbyte** %aq) + + ; Stop processing of arguments. + call void %llvm.va_end(sbyte** %ap) + ret int %tmp + +} diff --git a/test/Feature/weirdnames.ll b/test/Feature/weirdnames.ll new file mode 100644 index 0000000..bf143c3 --- /dev/null +++ b/test/Feature/weirdnames.ll @@ -0,0 +1,10 @@ +; RUN: llvm-upgrade < %s | llvm-as | llvm-dis > %t1.ll +; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll +; RUN: diff %t1.ll %t2.ll + +; Test using double quotes to form names that are not legal in the % form + +"&^ " = type { int } +"%.*+ foo" = global "&^ " { int 5 } +"0" = global float 0.0 ; This CANNOT be %0 +"\03foo" = global float 0.1 ; Make sure funny char gets round trip |