[clang] 170c194 - [clang][Interp] Fix CFStringMakeConstantString etc. evaluation
Timm Bäder via cfe-commits
cfe-commits at lists.llvm.org
Sat Jun 22 09:55:06 PDT 2024
Author: Timm Bäder
Date: 2024-06-22T18:54:42+02:00
New Revision: 170c194ec19c76deee33d8aa8b288368c574f7a0
URL: https://github.com/llvm/llvm-project/commit/170c194ec19c76deee33d8aa8b288368c574f7a0
DIFF: https://github.com/llvm/llvm-project/commit/170c194ec19c76deee33d8aa8b288368c574f7a0.diff
LOG: [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.
Added:
Modified:
clang/lib/AST/Interp/ByteCodeExprGen.cpp
clang/lib/AST/Interp/InterpBuiltin.cpp
clang/test/CodeGen/cfstring.c
Removed:
################################################################################
diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index edc2ec8e50952..72c569f56a788 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 44629fe218b1e..af8841c8b4ef8 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 4a84d00d23bd6..86141868bced1 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.
More information about the cfe-commits
mailing list