From 170c194ec19c76deee33d8aa8b288368c574f7a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= Date: Fri, 21 Jun 2024 09:30:53 +0200 Subject: [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. --- clang/lib/AST/Interp/ByteCodeExprGen.cpp | 11 +++++++++++ clang/lib/AST/Interp/InterpBuiltin.cpp | 2 -- clang/test/CodeGen/cfstring.c | 1 + 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::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 GlobalOffset = P.createGlobal(E)) + return this->emitGetPtrGlobal(*GlobalOffset, E); + return false; + } + QualType ReturnType = E->getType(); std::optional 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. -- cgit v1.1