Skip to content

Commit 170c194

Browse files
committed
[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.
1 parent a4ca225 commit 170c194

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

clang/lib/AST/Interp/ByteCodeExprGen.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3562,6 +3562,17 @@ bool ByteCodeExprGen<Emitter>::VisitBuiltinCallExpr(const CallExpr *E) {
35623562
if (!Func)
35633563
return false;
35643564

3565+
// For these, we're expected to ultimately return an APValue pointing
3566+
// to the CallExpr. This is needed to get the correct codegen.
3567+
unsigned Builtin = E->getBuiltinCallee();
3568+
if (Builtin == Builtin::BI__builtin___CFStringMakeConstantString ||
3569+
Builtin == Builtin::BI__builtin___NSStringMakeConstantString ||
3570+
Builtin == Builtin::BI__builtin_function_start) {
3571+
if (std::optional<unsigned> GlobalOffset = P.createGlobal(E))
3572+
return this->emitGetPtrGlobal(*GlobalOffset, E);
3573+
return false;
3574+
}
3575+
35653576
QualType ReturnType = E->getType();
35663577
std::optional<PrimType> ReturnT = classify(E);
35673578

clang/lib/AST/Interp/InterpBuiltin.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1329,8 +1329,6 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F,
13291329
break;
13301330

13311331
case Builtin::BI__builtin_launder:
1332-
case Builtin::BI__builtin___CFStringMakeConstantString:
1333-
case Builtin::BI__builtin___NSStringMakeConstantString:
13341332
if (!noopPointer(S, OpPC, Frame, F, Call))
13351333
return false;
13361334
break;

clang/test/CodeGen/cfstring.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// REQUIRES: x86-registered-target
22

33
// RUN: %clang_cc1 -triple x86_64-macho -emit-llvm %s -o %t
4+
// RUN: %clang_cc1 -triple x86_64-macho -emit-llvm %s -o %t -fexperimental-new-constant-interpreter
45

56
// Check that the backing store of CFStrings are constant with the
67
// -fwritable-strings flag.

0 commit comments

Comments
 (0)