summaryrefslogtreecommitdiffstats
path: root/clang/test/Sema/builtins.c
diff options
context:
space:
mode:
authorBill Wendling <isanbard@gmail.com>2018-11-20 08:53:30 +0000
committerBill Wendling <isanbard@gmail.com>2018-11-20 08:53:30 +0000
commit107b0e9881c87dba9f51109bae70b63d9e444546 (patch)
treec2bcc110804ddf7dca9704e3a47a2f26a6e2bcd5 /clang/test/Sema/builtins.c
parentcabb36d38d9e71610c7767a22477576aa8a4d9fa (diff)
downloadbcm5719-llvm-107b0e9881c87dba9f51109bae70b63d9e444546.tar.gz
bcm5719-llvm-107b0e9881c87dba9f51109bae70b63d9e444546.zip
Use is.constant intrinsic for __builtin_constant_p
Summary: A __builtin_constant_p may end up with a constant after inlining. Use the is.constant intrinsic if it's a variable that's in a context where it may resolve to a constant, e.g., an argument to a function after inlining. Reviewers: rsmith, shafik Subscribers: jfb, kristina, cfe-commits, nickdesaulniers, jyknight Differential Revision: https://reviews.llvm.org/D54355 llvm-svn: 347294
Diffstat (limited to 'clang/test/Sema/builtins.c')
-rw-r--r--clang/test/Sema/builtins.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/clang/test/Sema/builtins.c b/clang/test/Sema/builtins.c
index e874f598857..7d01e89756c 100644
--- a/clang/test/Sema/builtins.c
+++ b/clang/test/Sema/builtins.c
@@ -122,6 +122,14 @@ int test16() {
__builtin_constant_p(1, 2); // expected-error {{too many arguments}}
}
+// __builtin_constant_p cannot resolve non-constants as a file scoped array.
+int expr;
+char y[__builtin_constant_p(expr) ? -1 : 1]; // no warning, the builtin is false.
+
+// no warning, the builtin is false.
+struct foo { int a; };
+struct foo x = (struct foo) { __builtin_constant_p(42) ? 37 : 927 };
+
const int test17_n = 0;
const char test17_c[] = {1, 2, 3, 0};
const char test17_d[] = {1, 2, 3, 4};
@@ -161,6 +169,7 @@ void test17() {
F(&test17_d);
F((struct Aggregate){0, 1});
F((IntVector){0, 1, 2, 3});
+ F(test17);
// Ensure that a technique used in glibc is handled correctly.
#define OPT(...) (__builtin_constant_p(__VA_ARGS__) && strlen(__VA_ARGS__) < 4)
OpenPOWER on IntegriCloud