diff options
author | Hans Wennborg <hans@hanshq.net> | 2018-11-27 14:01:40 +0000 |
---|---|---|
committer | Hans Wennborg <hans@hanshq.net> | 2018-11-27 14:01:40 +0000 |
commit | 8c79706e89dd2792bcc7b1e44d8f5db6abaf1617 (patch) | |
tree | b1ebe35d9001f44880de2719abd98aeaa260270a /clang/test/CodeGen/builtin-constant-p.c | |
parent | 032f3e7fd8a12ceab800b0d9c3aca0f769f7b7cc (diff) | |
download | bcm5719-llvm-8c79706e89dd2792bcc7b1e44d8f5db6abaf1617.tar.gz bcm5719-llvm-8c79706e89dd2792bcc7b1e44d8f5db6abaf1617.zip |
Revert r347417 "Re-Reinstate 347294 with a fix for the failures."
This caused a miscompile in Chrome (see crbug.com/908372) that's
illustrated by this small reduction:
static bool f(int *a, int *b) {
return !__builtin_constant_p(b - a) || (!(b - a));
}
int arr[] = {1,2,3};
bool g() {
return f(arr, arr + 3);
}
$ clang -O2 -S -emit-llvm a.cc -o -
g() should return true, but after r347417 it became false for some reason.
This also reverts the follow-up commits.
r347417:
> Re-Reinstate 347294 with a fix for the failures.
>
> Don't try to emit a scalar expression for a non-scalar argument to
> __builtin_constant_p().
>
> Third time's a charm!
r347446:
> The result of is.constant() is unsigned.
r347480:
> A __builtin_constant_p() returns 0 with a function type.
r347512:
> isEvaluatable() implies a constant context.
>
> Assume that we're in a constant context if we're asking if the expression can
> be compiled into a constant initializer. This fixes the issue where a
> __builtin_constant_p() in a compound literal was diagnosed as not being
> constant, even though it's always possible to convert the builtin into a
> constant.
r347531:
> A "constexpr" is evaluated in a constant context. Make sure this is reflected
> if a __builtin_constant_p() is a part of a constexpr.
llvm-svn: 347656
Diffstat (limited to 'clang/test/CodeGen/builtin-constant-p.c')
-rw-r--r-- | clang/test/CodeGen/builtin-constant-p.c | 159 |
1 files changed, 0 insertions, 159 deletions
diff --git a/clang/test/CodeGen/builtin-constant-p.c b/clang/test/CodeGen/builtin-constant-p.c deleted file mode 100644 index 5cdcc721235..00000000000 --- a/clang/test/CodeGen/builtin-constant-p.c +++ /dev/null @@ -1,159 +0,0 @@ -// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -o - %s -O2 | FileCheck %s - -int a = 42; - -inline int bcp(int x) { - return __builtin_constant_p(x); -} - -/* --- Compound literals */ - -struct foo { int x, y; }; - -int y; -struct foo f = (struct foo){ __builtin_constant_p(y), 42 }; - -struct foo test0(int expr) { - // CHECK: define i64 @test0(i32 %expr) - // CHECK: call i1 @llvm.is.constant.i32(i32 %expr) - struct foo f = (struct foo){ __builtin_constant_p(expr), 42 }; - return f; -} - -/* --- Pointer types */ - -inline int test1_i(int *x) { - return *x; -} - -int test1() { - // CHECK: define i32 @test1 - // CHECK: add nsw i32 %0, -13 - // CHECK-NEXT: call i1 @llvm.is.constant.i32(i32 %sub) - return bcp(test1_i(&a) - 13); -} - -int test2() { - // CHECK: define i32 @test2 - // CHECK: ret i32 0 - return __builtin_constant_p(&a - 13); -} - -inline int test3_i(int *x) { - return 42; -} - -int test3() { - // CHECK: define i32 @test3 - // CHECK: ret i32 1 - return bcp(test3_i(&a) - 13); -} - -/* --- Aggregate types */ - -int b[] = {1, 2, 3}; - -int test4() { - // CHECK: define i32 @test4 - // CHECK: ret i32 0 - return __builtin_constant_p(b); -} - -const char test5_c[] = {1, 2, 3, 0}; - -int test5() { - // CHECK: define i32 @test5 - // CHECK: ret i32 0 - return __builtin_constant_p(test5_c); -} - -inline char test6_i(const char *x) { - return x[1]; -} - -int test6() { - // CHECK: define i32 @test6 - // CHECK: ret i32 0 - return __builtin_constant_p(test6_i(test5_c)); -} - -/* --- Non-constant global variables */ - -int test7() { - // CHECK: define i32 @test7 - // CHECK: call i1 @llvm.is.constant.i32(i32 %0) - return bcp(a); -} - -/* --- Constant global variables */ - -const int c = 42; - -int test8() { - // CHECK: define i32 @test8 - // CHECK: ret i32 1 - return bcp(c); -} - -/* --- Array types */ - -int arr[] = { 1, 2, 3 }; -const int c_arr[] = { 1, 2, 3 }; - -int test9() { - // CHECK: define i32 @test9 - // CHECK: call i1 @llvm.is.constant.i32(i32 %0) - return __builtin_constant_p(arr[2]); -} - -int test10() { - // CHECK: define i32 @test10 - // CHECK: ret i32 1 - return __builtin_constant_p(c_arr[2]); -} - -int test11() { - // CHECK: define i32 @test11 - // CHECK: ret i32 0 - return __builtin_constant_p(c_arr); -} - -/* --- Function pointers */ - -int test12() { - // CHECK: define i32 @test12 - // CHECK: ret i32 0 - return __builtin_constant_p(&test10); -} - -int test13() { - // CHECK: define i32 @test13 - // CHECK: ret i32 1 - return __builtin_constant_p(&test10 != 0); -} - -typedef unsigned long uintptr_t; -#define assign(p, v) ({ \ - uintptr_t _r_a_p__v = (uintptr_t)(v); \ - if (__builtin_constant_p(v) && _r_a_p__v == (uintptr_t)0) { \ - union { \ - uintptr_t __val; \ - char __c[1]; \ - } __u = { \ - .__val = (uintptr_t)_r_a_p__v \ - }; \ - *(volatile unsigned int*)&p = *(unsigned int*)(__u.__c); \ - __u.__val; \ - } \ - _r_a_p__v; \ -}) - -typedef void fn_p(void); -extern fn_p *dest_p; - -static void src_fn(void) { -} - -void test14() { - assign(dest_p, src_fn); -} |