aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimm Bäder <tbaeder@redhat.com>2024-04-29 16:29:38 +0200
committerTimm Bäder <tbaeder@redhat.com>2024-04-29 16:33:21 +0200
commit45bd85e4815254a4528cc337447fd6a8eb6fd583 (patch)
treee7f619e1c1463b4856be06e281448822a4d92882
parente34b41c707a8cc589725d5f996e1a40e9631a495 (diff)
downloadllvm-45bd85e4815254a4528cc337447fd6a8eb6fd583.zip
llvm-45bd85e4815254a4528cc337447fd6a8eb6fd583.tar.gz
llvm-45bd85e4815254a4528cc337447fd6a8eb6fd583.tar.bz2
[clang][Interp] Fix casting function pointers to integers
-rw-r--r--clang/lib/AST/Interp/ByteCodeExprGen.cpp7
-rw-r--r--clang/test/AST/Interp/c.c7
2 files changed, 14 insertions, 0 deletions
diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index accaea0..3ceccfd 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -212,6 +212,13 @@ bool ByteCodeExprGen<Emitter>::VisitCastExpr(const CastExpr *CE) {
if (!this->visit(SubExpr))
return false;
+ // If SubExpr doesn't result in a pointer, make it one.
+ if (PrimType FromT = classifyPrim(SubExpr->getType()); FromT != PT_Ptr) {
+ assert(isPtrType(FromT));
+ if (!this->emitDecayPtr(FromT, PT_Ptr, CE))
+ return false;
+ }
+
PrimType T = classifyPrim(CE->getType());
if (T == PT_IntAP)
return this->emitCastPointerIntegralAP(Ctx.getBitWidth(CE->getType()),
diff --git a/clang/test/AST/Interp/c.c b/clang/test/AST/Interp/c.c
index a595115..207da5f 100644
--- a/clang/test/AST/Interp/c.c
+++ b/clang/test/AST/Interp/c.c
@@ -263,3 +263,10 @@ const int *p = &b;
const __int128 K = (__int128)(int*)0;
const unsigned __int128 KU = (unsigned __int128)(int*)0;
#endif
+
+
+int test3(void) {
+ int a[2];
+ a[0] = test3; // all-error {{incompatible pointer to integer conversion assigning to 'int' from 'int (void)'}}
+ return 0;
+}