llvm.org GIT mirror llvm / 37d0e7e
Test the handling of constant expressions. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@2889 91177308-0d34-0410-b5e6-96231b3b80d8 Vikram S. Adve 18 years ago
2 changed file(s) with 113 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
0 ; This testcase is for testing expressions constructed from
1 ; constant values, including constant pointers to globals.
2 ;
3
4 ;;-------------------------------
5 ;; Test constant cast expressions
6 ;;-------------------------------
7
8 %t2 = global int* %t1 ;; Forward reference without cast
9 %t3 = global uint* cast int* %t1 ;; Forward reference with cast
10 %t1 = global int 4 ;; int* %0
11 %t4 = global int** cast uint** %t3 ;; Cast of a previous cast
12 %t5 = global uint** %t3 ;; Reference to a previous cast
13 %t6 = global int*** %t4 ;; Different ref. to a previous cast
14 %t7 = global float* cast int 12345678 ;; Cast ordinary value to ptr
15 %t9 = global int cast float cast int 8 ;; Nested cast expression
16
17 global int* cast float* %0 ;; Forward numeric reference
18 global float* %0 ;; Duplicate forward numeric reference
19 global float 0.0
20
21
22 ;;---------------------------------------------------
23 ;; Test constant getelementpr expressions for arrays
24 ;;---------------------------------------------------
25
26 %array = constant [2 x int] [ int 12, int 52 ]
27 %arrayPtr = global int* getelementptr ([2 x int]* %array, uint 0, uint 0) ;; int* &%array[0][0]
28 %arrayPtr5 = global int* getelementptr (int** %arrayPtr, uint 0, uint 5) ;; int* &%arrayPtr[5]
29
30 %somestr = constant [11x sbyte] c"hello world"
31 %char5 = global sbyte* getelementptr([11x sbyte]* %somestr, uint 0, uint 5)
32
33 %char8a = global int* cast sbyte* getelementptr([11x sbyte]* %somestr, uint 0, uint 8) ;; cast of getelementptr
34
35 %char8b = global sbyte* getelementptr([11x sbyte]* %somestr, uint cast ubyte 0, uint cast sbyte 8) ;; getelementptr containing casts
36
37 ;;-------------------------------------------------------
38 ;; TODO: Test constant getelementpr expressions for structures
39 ;;-------------------------------------------------------
40
41 %SType = type { int , {float, {ubyte} }, ulong } ;; struct containing struct
42 %SAType = type { int , {[2x float], ulong} } ;; struct containing array
43
44 %S1 = global %SType* null ;; Global initialized to NULL
45 %S2c = constant %SType { int 1, {float,{ubyte}} {float 2.0, {ubyte} {ubyte 3}}, ulong 4}
46
47 %S3c = constant %SAType { int 1, {[2x float], ulong} {[2x float] [float 2.0, float 3.0], ulong 4} }
48
49 %S1ptr = global %SType** %S1 ;; Ref. to global S1
50 %S2 = global %SType* %S2c ;; Ref. to constant S2
51 %S3 = global %SAType* %S3c ;; Ref. to constant S3
52
53 ;; Pointer to float (**%S1).1.0
54 %S1fld1a = global float* getelementptr (%SType** %S1, uint 0, uint 0, ubyte 1, ubyte 0)
55 ;; Another ptr to the same!
56 %S1fld1b = global float* getelementptr (%SType*** %S1ptr, uint 0, uint 0, uint 0, ubyte 1, ubyte 0)
57
58 %S1fld1bptr = global float** %S1fld1b ;; Ref. to previous pointer
59
60 ;; Pointer to ubyte (**%S2).1.1.0
61 %S2fld3 = global ubyte* getelementptr (%SType** %S2, uint 0, uint 0, ubyte 1, ubyte 1, ubyte 0)
62
63 ;; Pointer to float (**%S2).1.0[0]
64 %S3fld3 = global float* getelementptr (%SAType** %S3, uint 0, uint 0, ubyte 1, ubyte 0, uint 0)
65
66 ;;---------------------------------------------------------
67 ;; TODO: Test constant expressions for unary and binary operators
68 ;;---------------------------------------------------------
69
70 implementation
71
0 ; This testcase is for testing illegal constant expressions.
1 ; Uncomment any code line below to test that the error is caught
2 ; See constexpr.ll in this directory for legal ones.
3 ;
4
5 %somestr = constant [11x sbyte] c"hello world"
6
7 ;;---------------------------------------------------
8 ;; Illegal cast expressions
9 ;;---------------------------------------------------
10
11 ;missing attribute (global/constant) or type before operator
12 ;%casterr1 = cast int 0
13 ;%casterr2 = global cast int 0
14
15 ;missing or illegal initializer value for constant
16 ;%casterr3 = constant
17 ;%casterr4 = constant int 4.0
18
19 ;;
20 ;;---------------------------------------------------
21 ;; Illegal getelementptr expressions
22 ;;---------------------------------------------------
23
24 ;; return value must be a pointer to the element
25 ;%geperr1 = global sbyte getelementptr([11x sbyte]* %somestr, uint 0, uint 8)
26
27 ;; index types must be valid for pointer type
28 ;%geperr2 = global sbyte* getelementptr([11x sbyte]* %somestr, ubyte 0)
29 ;%geperr3 = global sbyte* getelementptr([11x sbyte]* %somestr, uint 0, uint 0, uint 3)
30
31 ;; element accessed by index list must match return type
32 ;%geperr4 = global sbyte* getelementptr([11x sbyte]* %somestr)
33 ;%geperr5 = global sbyte* getelementptr([11x sbyte]* %somestr, uint 0)
34 ;%geperr6 = global int* getelementptr([11x sbyte]* %somestr, uint 0, uint 0)
35
36 ;; Cannot use cast expression in pointer field of getelementptr
37 ;; (unlike the index fields, where it is legal)
38 ;%geperr7 = constant int* getelementptr (int* cast long 0, uint 27)
39
40