]> granicus.if.org Git - clang/commitdiff
A __builtin_constant_p() returns 0 with a function type.
authorBill Wendling <isanbard@gmail.com>
Thu, 22 Nov 2018 22:58:06 +0000 (22:58 +0000)
committerBill Wendling <isanbard@gmail.com>
Thu, 22 Nov 2018 22:58:06 +0000 (22:58 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@347480 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGBuiltin.cpp
test/CodeGen/builtin-constant-p.c

index 9301bfb0e90b929214b49579dfab5f9871eca486..b1323031d9a1e3eaf6e842e7ff174f4c04b2cd0c 100644 (file)
@@ -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));
 
index 978ec4c8f5490395dc6db3d134e30d8e164a1d67..3f1225fb8b29a896b083d3d7f16de80f8261dca4 100644 (file)
@@ -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);
+}