The recently behavior in the code that these tests were meant to be checking will be ammended as soon as a suitable change can be properly reviewed.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@313684
91177308-0d34-0410-b5e6-
96231b3b80d8
// CHECK: inttoptr
// CHECK-NOT: getelementptr
-// This doesn't meet the idiom because the offset type isn't pointer-sized.
-int8_t *test2(int8_t n) {
- return NULLPTRI8 + n;
-}
-// CHECK-LABEL: test2
-// CHECK: getelementptr
-// CHECK-NOT: inttoptr
-
// This doesn't meet the idiom because the element type is larger than a byte.
-int16_t *test3(intptr_t n) {
+int16_t *test2(intptr_t n) {
return (int16_t*)0 + n;
}
-// CHECK-LABEL: test3
+// CHECK-LABEL: test2
// CHECK: getelementptr
// CHECK-NOT: inttoptr
// This doesn't meet the idiom because the offset is subtracted.
-int8_t* test4(intptr_t n) {
+int8_t* test3(intptr_t n) {
return NULLPTRI8 - n;
}
-// CHECK-LABEL: test4
+// CHECK-LABEL: test3
// CHECK: getelementptr
// CHECK-NOT: inttoptr
// Cases that don't match the GNU inttoptr idiom get a different warning.
f = (char*)0 - i; // expected-warning {{performing pointer arithmetic on a null pointer has undefined behavior}}
int *g = (int*)0 + i; // expected-warning {{performing pointer arithmetic on a null pointer has undefined behavior}}
- unsigned char j = (unsigned char)b;
- f = (char*)0 + j; // expected-warning {{performing pointer arithmetic on a null pointer has undefined behavior}}
}
#include <stdint.h>
-void f(intptr_t offset, int8_t b) {
+void f(intptr_t offset) {
// A zero offset from a nullptr is OK.
char *f = (char*)nullptr + 0;
int *g = (int*)0 + 0;
// Cases that don't match the GNU inttoptr idiom get a different warning.
f = (char*)0 - offset; // expected-warning {{performing pointer arithmetic on a null pointer has undefined behavior if the offset is nonzero}}
g = (int*)0 + offset; // expected-warning {{performing pointer arithmetic on a null pointer has undefined behavior if the offset is nonzero}}
- f = (char*)0 + b; // expected-warning {{performing pointer arithmetic on a null pointer has undefined behavior if the offset is nonzero}}
}
// Value-dependent pointer arithmetic should not produce a nullptr warning.