summaryrefslogtreecommitdiffstats
path: root/clang/test/CodeGen/alloc-size.c
diff options
context:
space:
mode:
authorJoel E. Denny <jdenny.ornl@gmail.com>2019-04-23 17:04:15 +0000
committerJoel E. Denny <jdenny.ornl@gmail.com>2019-04-23 17:04:15 +0000
commit3234887fe2ea94d5997b4ba9999401459a29905b (patch)
tree843fa6636935b50c1cf5a6871a8b19fefc91332e /clang/test/CodeGen/alloc-size.c
parentbdb864a5762e10a485c0b76c5677f5c14b4045d7 (diff)
downloadbcm5719-llvm-3234887fe2ea94d5997b4ba9999401459a29905b.tar.gz
bcm5719-llvm-3234887fe2ea94d5997b4ba9999401459a29905b.zip
[APSInt][OpenMP] Fix isNegative, etc. for unsigned types
Without this patch, APSInt inherits APInt::isNegative, which merely checks the sign bit without regard to whether the type is actually signed. isNonNegative and isStrictlyPositive call isNegative and so are also affected. This patch adjusts APSInt to override isNegative, isNonNegative, and isStrictlyPositive with implementations that consider whether the type is signed. A large set of Clang OpenMP tests are affected. Without this patch, these tests assume that `true` is not a valid argument for clauses like `collapse`. Indeed, `true` fails APInt::isStrictlyPositive but not APSInt::isStrictlyPositive. This patch adjusts those tests to assume `true` should be accepted. This patch also adds tests revealing various other similar fixes due to APSInt::isNegative calls in Clang's ExprConstant.cpp and SemaExpr.cpp: `++` and `--` overflow in `constexpr`, evaluated object size based on `alloc_size`, `<<` and `>>` shift count validation, and OpenMP array section validation. Reviewed By: lebedev.ri, ABataev, hfinkel Differential Revision: https://reviews.llvm.org/D59712 llvm-svn: 359012
Diffstat (limited to 'clang/test/CodeGen/alloc-size.c')
-rw-r--r--clang/test/CodeGen/alloc-size.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/clang/test/CodeGen/alloc-size.c b/clang/test/CodeGen/alloc-size.c
index aa5b295b0c3..16cc0fe1181 100644
--- a/clang/test/CodeGen/alloc-size.c
+++ b/clang/test/CodeGen/alloc-size.c
@@ -357,3 +357,12 @@ void test12() {
// CHECK: store i32 -1
gi = OBJECT_SIZE_BUILTIN(my_signed_calloc(-2, 1), 0);
}
+
+void *alloc_uchar(unsigned char) __attribute__((alloc_size(1)));
+
+// CHECK-LABEL: @test13
+void test13() {
+ // If 128 were incorrectly seen as negative, the result would become -1.
+ // CHECK: store i32 128,
+ gi = OBJECT_SIZE_BUILTIN(alloc_uchar(128), 0);
+}
OpenPOWER on IntegriCloud