diff options
| -rw-r--r-- | clang/test/CodeGen/nullptr-arithmetic.c | 16 | ||||
| -rw-r--r-- | clang/test/Sema/pointer-addition.c | 2 | ||||
| -rw-r--r-- | clang/test/SemaCXX/nullptr-arithmetic.cpp | 3 |
3 files changed, 5 insertions, 16 deletions
diff --git a/clang/test/CodeGen/nullptr-arithmetic.c b/clang/test/CodeGen/nullptr-arithmetic.c index 4c62df132de..0c8ad5e34dc 100644 --- a/clang/test/CodeGen/nullptr-arithmetic.c +++ b/clang/test/CodeGen/nullptr-arithmetic.c @@ -17,26 +17,18 @@ int8_t *test1(intptr_t n) { // 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 diff --git a/clang/test/Sema/pointer-addition.c b/clang/test/Sema/pointer-addition.c index 00778996f4a..3e77cbde477 100644 --- a/clang/test/Sema/pointer-addition.c +++ b/clang/test/Sema/pointer-addition.c @@ -27,6 +27,4 @@ void a(S* b, void* c) { // 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}} } diff --git a/clang/test/SemaCXX/nullptr-arithmetic.cpp b/clang/test/SemaCXX/nullptr-arithmetic.cpp index bcb99b6eed8..7d11e268f25 100644 --- a/clang/test/SemaCXX/nullptr-arithmetic.cpp +++ b/clang/test/SemaCXX/nullptr-arithmetic.cpp @@ -2,7 +2,7 @@ #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; @@ -13,7 +13,6 @@ void f(intptr_t offset, int8_t b) { // 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. |

