1 // RUN: %clang_cc1 %s -emit-llvm -o - | FileCheck %s
2 // RUN: %clang_cc1 %s -emit-llvm -triple i686-unknown-unknown -o - | FileCheck %s
3 // RUN: %clang_cc1 %s -emit-llvm -triple x86_64-unknown-unknown -o - | FileCheck %s
7 // This test is meant to verify code that handles the 'p = nullptr + n' idiom
8 // used by some versions of glibc and gcc. This is undefined behavior but
9 // it is intended there to act like a conversion from a pointer-sized integer
10 // to a pointer, and we would like to tolerate that.
12 #define NULLPTRI8 ((int8_t*)0)
14 // This should get the inttoptr instruction.
15 int8_t *test1(intptr_t n
) {
20 // CHECK-NOT: getelementptr
22 // This doesn't meet the idiom because the element type is larger than a byte.
23 int16_t *test2(intptr_t n
) {
24 return (int16_t*)0 + n
;
27 // CHECK: getelementptr
28 // CHECK-NOT: inttoptr
30 // This doesn't meet the idiom because the offset is subtracted.
31 int8_t* test3(intptr_t n
) {
35 // CHECK: getelementptr
36 // CHECK-NOT: inttoptr
38 // This checks the case where the offset isn't pointer-sized.
39 // The front end will implicitly cast the offset to an integer, so we need to
40 // make sure that doesn't cause problems on targets where integers and pointers
41 // are not the same size.
42 int8_t *test4(int8_t b
) {
47 // CHECK-NOT: getelementptr