diff options
author | Bill Wendling <isanbard@gmail.com> | 2018-11-22 15:14:08 -0800 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2018-11-22 15:14:08 -0800 |
commit | c932653ceabf1d9db39b88120c43c659731b0308 (patch) | |
tree | 5f2c01f0807d7ec9e0f7f03688ffe92509a47dc0 | |
parent | 480b04683bfce6083098ed2758c4b6c6389a4075 (diff) | |
parent | 1034e9ab38bba688ffdf4e315634549a8df91701 (diff) | |
download | clang-c932653ceabf1d9db39b88120c43c659731b0308.tar.gz |
A __builtin_constant_p() returns 0 with a function type.
am: 1034e9ab38
Change-Id: I38be83e1b99c0f0269bc9a6f526c953ca4aec1bc
-rw-r--r-- | lib/CodeGen/CGBuiltin.cpp | 2 | ||||
-rw-r--r-- | test/CodeGen/builtin-constant-p.c | 26 |
2 files changed, 27 insertions, 1 deletions
diff --git a/lib/CodeGen/CGBuiltin.cpp b/lib/CodeGen/CGBuiltin.cpp index 9301bfb0e9..b1323031d9 100644 --- a/lib/CodeGen/CGBuiltin.cpp +++ b/lib/CodeGen/CGBuiltin.cpp @@ -1935,7 +1935,7 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID, const Expr *Arg = E->getArg(0); QualType ArgType = Arg->getType(); - if (!hasScalarEvaluationKind(ArgType)) + if (!hasScalarEvaluationKind(ArgType) || ArgType->isFunctionType()) // We can only reason about scalar types. return RValue::get(ConstantInt::get(ResultType, 0)); diff --git a/test/CodeGen/builtin-constant-p.c b/test/CodeGen/builtin-constant-p.c index 978ec4c8f5..3f1225fb8b 100644 --- a/test/CodeGen/builtin-constant-p.c +++ b/test/CodeGen/builtin-constant-p.c @@ -128,3 +128,29 @@ int 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); +} |