r347480 - A __builtin_constant_p() returns 0 with a function type.

Bill Wendling via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 22 14:58:06 PST 2018


Author: void
Date: Thu Nov 22 14:58:06 2018
New Revision: 347480

URL: http://llvm.org/viewvc/llvm-project?rev=347480&view=rev
Log:
A __builtin_constant_p() returns 0 with a function type.

Modified:
    cfe/trunk/lib/CodeGen/CGBuiltin.cpp
    cfe/trunk/test/CodeGen/builtin-constant-p.c

Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=347480&r1=347479&r2=347480&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Thu Nov 22 14:58:06 2018
@@ -1935,7 +1935,7 @@ RValue CodeGenFunction::EmitBuiltinExpr(
 
     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));
 

Modified: cfe/trunk/test/CodeGen/builtin-constant-p.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/builtin-constant-p.c?rev=347480&r1=347479&r2=347480&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/builtin-constant-p.c (original)
+++ cfe/trunk/test/CodeGen/builtin-constant-p.c Thu Nov 22 14:58:06 2018
@@ -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);
+}




More information about the cfe-commits mailing list