[clang] 5b4c80f - [clang][bytecode] Create dummy pointers for ObjCStringLiterals (#109520)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Sep 21 01:33:06 PDT 2024
Author: Timm Baeder
Date: 2024-09-21T10:33:02+02:00
New Revision: 5b4c80f1234f176c19bdbe687861e7f076ec189a
URL: https://github.com/llvm/llvm-project/commit/5b4c80f1234f176c19bdbe687861e7f076ec189a
DIFF: https://github.com/llvm/llvm-project/commit/5b4c80f1234f176c19bdbe687861e7f076ec189a.diff
LOG: [clang][bytecode] Create dummy pointers for ObjCStringLiterals (#109520)
We need to have the final APValue point to the ObjCStringLiteral
expression, not the StringLiteral itself.
Added:
clang/test/AST/ByteCode/codegen.m
Modified:
clang/lib/AST/ByteCode/Compiler.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp
index 7e0775a51aee61..161b6a9bb36ec7 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -2134,7 +2134,9 @@ bool Compiler<Emitter>::VisitStringLiteral(const StringLiteral *E) {
template <class Emitter>
bool Compiler<Emitter>::VisitObjCStringLiteral(const ObjCStringLiteral *E) {
- return this->delegate(E->getString());
+ if (std::optional<unsigned> I = P.getOrCreateDummy(E))
+ return this->emitGetPtrGlobal(*I, E);
+ return false;
}
template <class Emitter>
diff --git a/clang/test/AST/ByteCode/codegen.m b/clang/test/AST/ByteCode/codegen.m
new file mode 100644
index 00000000000000..08c3d9a70b36d7
--- /dev/null
+++ b/clang/test/AST/ByteCode/codegen.m
@@ -0,0 +1,12 @@
+// REQUIRES: x86-registered-target
+
+/// See test/CodeGenObjC/constant-strings.m
+/// Test that we let the APValue we create for ObjCStringLiterals point to the right expression.
+
+// RUN: %clang_cc1 -triple x86_64-macho -emit-llvm -o %t %s -fexperimental-new-constant-interpreter
+// RUN: FileCheck --check-prefix=CHECK-NEXT < %t %s
+
+// Check that we set alignment 1 on the string.
+//
+// CHECK-NEXT: @.str = {{.*}}constant [13 x i8] c"Hello World!\00", section "__TEXT,__cstring,cstring_literals", align 1
+id a = @"Hello World!";
More information about the cfe-commits
mailing list