https://github.com/tbaederr created 
https://github.com/llvm/llvm-project/pull/109520

We need to have the final APValue point to the ObjCStringLiteral expression, 
not the StringLiteral itself.

>From ca2960bcb2307c415547ef12fa3628aec4d4d702 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbae...@redhat.com>
Date: Sat, 21 Sep 2024 09:56:44 +0200
Subject: [PATCH] [clang][bytecode] Create dummy pointers for
 ObjCStringLiterals

We need to have the final APValue point to the ObjCStringLiteral
expression, not the StringLiteral itself.
---
 clang/lib/AST/ByteCode/Compiler.cpp |  4 +++-
 clang/test/AST/ByteCode/codegen.m   | 12 ++++++++++++
 2 files changed, 15 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/AST/ByteCode/codegen.m

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!";

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to