xref: /aosp_15_r20/external/llvm/test/Feature/constexpr.ll (revision 9880d6810fe72a1726cb53787c6711e909410d58)
1*9880d681SAndroid Build Coastguard Worker; RUN: llvm-as < %s | llvm-dis > %t1.ll
2*9880d681SAndroid Build Coastguard Worker; RUN: llvm-as %t1.ll -o - | llvm-dis > %t2.ll
3*9880d681SAndroid Build Coastguard Worker; RUN: diff %t1.ll %t2.ll
4*9880d681SAndroid Build Coastguard Worker
5*9880d681SAndroid Build Coastguard Worker; This testcase is for testing expressions constructed from
6*9880d681SAndroid Build Coastguard Worker; constant values, including constant pointers to globals.
7*9880d681SAndroid Build Coastguard Worker;
8*9880d681SAndroid Build Coastguard Worker
9*9880d681SAndroid Build Coastguard Worker;;-------------------------------
10*9880d681SAndroid Build Coastguard Worker;; Test constant cast expressions
11*9880d681SAndroid Build Coastguard Worker;;-------------------------------
12*9880d681SAndroid Build Coastguard Worker
13*9880d681SAndroid Build Coastguard Worker@0 = global i64 u0x00001     ; hexadecimal unsigned integer constants
14*9880d681SAndroid Build Coastguard Worker@1 = global i64  s0x0012312   ; hexadecimal signed integer constants
15*9880d681SAndroid Build Coastguard Worker
16*9880d681SAndroid Build Coastguard Worker@t2 = global i32* @t1                             ;; Forward reference without cast
17*9880d681SAndroid Build Coastguard Worker@t3 = global i32* bitcast (i32* @t1 to i32*)       ;; Forward reference with cast
18*9880d681SAndroid Build Coastguard Worker@t1 = global i32 4                                ;; i32* @0
19*9880d681SAndroid Build Coastguard Worker@t4 = global i32** bitcast (i32** @t3 to i32**)     ;; Cast of a previous cast
20*9880d681SAndroid Build Coastguard Worker@t5 = global i32** @t3                           ;; Reference to a previous cast
21*9880d681SAndroid Build Coastguard Worker@t6 = global i32*** @t4                           ;; Different ref. to a previous cast
22*9880d681SAndroid Build Coastguard Worker@t7 = global float* inttoptr (i32 12345678 to float*) ;; Cast ordinary value to ptr
23*9880d681SAndroid Build Coastguard Worker@t9 = global i32 bitcast (float bitcast (i32 8 to float) to i32) ;; Nested cast expression
24*9880d681SAndroid Build Coastguard Worker
25*9880d681SAndroid Build Coastguard Worker@2 = global i32* bitcast (float* @4 to i32*)   ;; Forward numeric reference
26*9880d681SAndroid Build Coastguard Worker@3 = global float* @4                     ;; Duplicate forward numeric reference
27*9880d681SAndroid Build Coastguard Worker@4 = global float 0.0
28*9880d681SAndroid Build Coastguard Worker
29*9880d681SAndroid Build Coastguard Worker
30*9880d681SAndroid Build Coastguard Worker;;---------------------------------------------------
31*9880d681SAndroid Build Coastguard Worker;; Test constant getelementpr expressions for arrays
32*9880d681SAndroid Build Coastguard Worker;;---------------------------------------------------
33*9880d681SAndroid Build Coastguard Worker
34*9880d681SAndroid Build Coastguard Worker@array  = constant [2 x i32] [ i32 12, i32 52 ]
35*9880d681SAndroid Build Coastguard Worker@arrayPtr = global i32* getelementptr ([2 x i32], [2 x i32]* @array, i64 0, i64 0)    ;; i32* &@array[0][0]
36*9880d681SAndroid Build Coastguard Worker@arrayPtr5 = global i32** getelementptr (i32*, i32** @arrayPtr, i64 5)    ;; i32* &@arrayPtr[5]
37*9880d681SAndroid Build Coastguard Worker
38*9880d681SAndroid Build Coastguard Worker@somestr = constant [11x i8] c"hello world"
39*9880d681SAndroid Build Coastguard Worker@char5  = global i8* getelementptr([11x i8], [11x i8]* @somestr, i64 0, i64 5)
40*9880d681SAndroid Build Coastguard Worker
41*9880d681SAndroid Build Coastguard Worker;; cast of getelementptr
42*9880d681SAndroid Build Coastguard Worker@char8a = global i32* bitcast (i8* getelementptr([11x i8], [11x i8]* @somestr, i64 0, i64 8) to i32*)
43*9880d681SAndroid Build Coastguard Worker
44*9880d681SAndroid Build Coastguard Worker;; getelementptr containing casts
45*9880d681SAndroid Build Coastguard Worker@char8b = global i8* getelementptr([11x i8], [11x i8]* @somestr, i64 sext (i8 0 to i64), i64 sext (i8 8 to i64))
46*9880d681SAndroid Build Coastguard Worker
47*9880d681SAndroid Build Coastguard Worker;;-------------------------------------------------------
48*9880d681SAndroid Build Coastguard Worker;; TODO: Test constant getelementpr expressions for structures
49*9880d681SAndroid Build Coastguard Worker;;-------------------------------------------------------
50*9880d681SAndroid Build Coastguard Worker
51*9880d681SAndroid Build Coastguard Worker%SType  = type { i32 , {float, {i8} }, i64 } ;; struct containing struct
52*9880d681SAndroid Build Coastguard Worker%SAType = type { i32 , {[2x float], i64} } ;; struct containing array
53*9880d681SAndroid Build Coastguard Worker
54*9880d681SAndroid Build Coastguard Worker@S1 = global %SType* null			;; Global initialized to NULL
55*9880d681SAndroid Build Coastguard Worker@S2c = constant %SType { i32 1, {float,{i8}} {float 2.0, {i8} {i8 3}}, i64 4}
56*9880d681SAndroid Build Coastguard Worker
57*9880d681SAndroid Build Coastguard Worker@S3c = constant %SAType { i32 1, {[2x float], i64} {[2x float] [float 2.0, float 3.0], i64 4} }
58*9880d681SAndroid Build Coastguard Worker
59*9880d681SAndroid Build Coastguard Worker@S1ptr = global %SType** @S1		    ;; Ref. to global S1
60*9880d681SAndroid Build Coastguard Worker@S2  = global %SType* @S2c		    ;; Ref. to constant S2
61*9880d681SAndroid Build Coastguard Worker@S3  = global %SAType* @S3c		    ;; Ref. to constant S3
62*9880d681SAndroid Build Coastguard Worker
63*9880d681SAndroid Build Coastguard Worker					    ;; Pointer to float (**@S1).1.0
64*9880d681SAndroid Build Coastguard Worker@S1fld1a = global float* getelementptr (%SType, %SType* @S2c, i64 0, i32 1, i32 0)
65*9880d681SAndroid Build Coastguard Worker					    ;; Another ptr to the same!
66*9880d681SAndroid Build Coastguard Worker@S1fld1b = global float* getelementptr (%SType, %SType* @S2c, i64 0, i32 1, i32 0)
67*9880d681SAndroid Build Coastguard Worker
68*9880d681SAndroid Build Coastguard Worker@S1fld1bptr = global float** @S1fld1b	    ;; Ref. to previous pointer
69*9880d681SAndroid Build Coastguard Worker
70*9880d681SAndroid Build Coastguard Worker					    ;; Pointer to i8 (**@S2).1.1.0
71*9880d681SAndroid Build Coastguard Worker@S2fld3 = global i8* getelementptr (%SType, %SType* @S2c, i64 0, i32 1, i32 1, i32 0)
72*9880d681SAndroid Build Coastguard Worker
73*9880d681SAndroid Build Coastguard Worker					    ;; Pointer to float (**@S2).1.0[0]
74*9880d681SAndroid Build Coastguard Worker;@S3fld3 = global float* getelementptr (%SAType*, %SAType** @S3, i64 0, i64 0, i32 1, i32 0, i64 0)
75*9880d681SAndroid Build Coastguard Worker
76*9880d681SAndroid Build Coastguard Worker;;---------------------------------------------------------
77*9880d681SAndroid Build Coastguard Worker;; TODO: Test constant expressions for unary and binary operators
78*9880d681SAndroid Build Coastguard Worker;;---------------------------------------------------------
79*9880d681SAndroid Build Coastguard Worker
80*9880d681SAndroid Build Coastguard Worker;;---------------------------------------------------
81