Skip to content

Commit 5b4c80f

Browse files
authored
[clang][bytecode] Create dummy pointers for ObjCStringLiterals (llvm#109520)
We need to have the final APValue point to the ObjCStringLiteral expression, not the StringLiteral itself.
1 parent 8527861 commit 5b4c80f

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

clang/lib/AST/ByteCode/Compiler.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2134,7 +2134,9 @@ bool Compiler<Emitter>::VisitStringLiteral(const StringLiteral *E) {
21342134

21352135
template <class Emitter>
21362136
bool Compiler<Emitter>::VisitObjCStringLiteral(const ObjCStringLiteral *E) {
2137-
return this->delegate(E->getString());
2137+
if (std::optional<unsigned> I = P.getOrCreateDummy(E))
2138+
return this->emitGetPtrGlobal(*I, E);
2139+
return false;
21382140
}
21392141

21402142
template <class Emitter>

clang/test/AST/ByteCode/codegen.m

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// REQUIRES: x86-registered-target
2+
3+
/// See test/CodeGenObjC/constant-strings.m
4+
/// Test that we let the APValue we create for ObjCStringLiterals point to the right expression.
5+
6+
// RUN: %clang_cc1 -triple x86_64-macho -emit-llvm -o %t %s -fexperimental-new-constant-interpreter
7+
// RUN: FileCheck --check-prefix=CHECK-NEXT < %t %s
8+
9+
// Check that we set alignment 1 on the string.
10+
//
11+
// CHECK-NEXT: @.str = {{.*}}constant [13 x i8] c"Hello World!\00", section "__TEXT,__cstring,cstring_literals", align 1
12+
id a = @"Hello World!";

0 commit comments

Comments
 (0)