aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimm Bäder <tbaeder@redhat.com>2024-06-21 09:30:53 +0200
committerTimm Bäder <tbaeder@redhat.com>2024-06-22 18:54:42 +0200
commit170c194ec19c76deee33d8aa8b288368c574f7a0 (patch)
tree0f061027928cdfa820173d7bd8dd7e0458b5ee1d
parenta4ca22506c96cd8508bcfb93a26941f19c7179ef (diff)
downloadllvm-170c194ec19c76deee33d8aa8b288368c574f7a0.zip
llvm-170c194ec19c76deee33d8aa8b288368c574f7a0.tar.gz
llvm-170c194ec19c76deee33d8aa8b288368c574f7a0.tar.bz2
[clang][Interp] Fix CFStringMakeConstantString etc. evaluation
We're ultimately expected to return an APValue simply pointing to the CallExpr, not any useful value. Do that by creating a global variable for the call.
-rw-r--r--clang/lib/AST/Interp/ByteCodeExprGen.cpp11
-rw-r--r--clang/lib/AST/Interp/InterpBuiltin.cpp2
-rw-r--r--clang/test/CodeGen/cfstring.c1
3 files changed, 12 insertions, 2 deletions
diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index edc2ec8..72c569f 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -3562,6 +3562,17 @@ bool ByteCodeExprGen<Emitter>::VisitBuiltinCallExpr(const CallExpr *E) {
if (!Func)
return false;
+ // For these, we're expected to ultimately return an APValue pointing
+ // to the CallExpr. This is needed to get the correct codegen.
+ unsigned Builtin = E->getBuiltinCallee();
+ if (Builtin == Builtin::BI__builtin___CFStringMakeConstantString ||
+ Builtin == Builtin::BI__builtin___NSStringMakeConstantString ||
+ Builtin == Builtin::BI__builtin_function_start) {
+ if (std::optional<unsigned> GlobalOffset = P.createGlobal(E))
+ return this->emitGetPtrGlobal(*GlobalOffset, E);
+ return false;
+ }
+
QualType ReturnType = E->getType();
std::optional<PrimType> ReturnT = classify(E);
diff --git a/clang/lib/AST/Interp/InterpBuiltin.cpp b/clang/lib/AST/Interp/InterpBuiltin.cpp
index 44629fe..af8841c 100644
--- a/clang/lib/AST/Interp/InterpBuiltin.cpp
+++ b/clang/lib/AST/Interp/InterpBuiltin.cpp
@@ -1329,8 +1329,6 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F,
break;
case Builtin::BI__builtin_launder:
- case Builtin::BI__builtin___CFStringMakeConstantString:
- case Builtin::BI__builtin___NSStringMakeConstantString:
if (!noopPointer(S, OpPC, Frame, F, Call))
return false;
break;
diff --git a/clang/test/CodeGen/cfstring.c b/clang/test/CodeGen/cfstring.c
index 4a84d00..8614186 100644
--- a/clang/test/CodeGen/cfstring.c
+++ b/clang/test/CodeGen/cfstring.c
@@ -1,6 +1,7 @@
// REQUIRES: x86-registered-target
// RUN: %clang_cc1 -triple x86_64-macho -emit-llvm %s -o %t
+// RUN: %clang_cc1 -triple x86_64-macho -emit-llvm %s -o %t -fexperimental-new-constant-interpreter
// Check that the backing store of CFStrings are constant with the
// -fwritable-strings flag.