hliao created this revision.
hliao added a reviewer: yaxunl.
Herald added subscribers: cfe-commits, jvesely.
Herald added a project: clang.

- If a string literal is reused directly, need to add necessary address space 
casting if the target requires that.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D58509

Files:
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/test/CodeGenCXX/amdgcn-string-literal.cpp


Index: clang/test/CodeGenCXX/amdgcn-string-literal.cpp
===================================================================
--- clang/test/CodeGenCXX/amdgcn-string-literal.cpp
+++ clang/test/CodeGenCXX/amdgcn-string-literal.cpp
@@ -14,7 +14,7 @@
 // CHECK-LABEL: define void @_Z1fv()
 void f() {
   const char* l_str = "l_str";
-  
+
   // CHECK: call void @llvm.memcpy.p0i8.p4i8.i64
   char l_array[] = "l_array";
 
@@ -26,3 +26,9 @@
   const char* p = g_str;
   g(p);
 }
+
+// CHECK-LABEL: define void @_Z1ev
+void e() {
+  g("string literal");
+  g("string literal");
+}
Index: clang/lib/CodeGen/CodeGenModule.cpp
===================================================================
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -4522,7 +4522,8 @@
     if (auto GV = *Entry) {
       if (Alignment.getQuantity() > GV->getAlignment())
         GV->setAlignment(Alignment.getQuantity());
-      return ConstantAddress(GV, Alignment);
+      return ConstantAddress(castStringLiteralToDefaultAddressSpace(*this, GV),
+                             Alignment);
     }
   }
 
@@ -4584,7 +4585,8 @@
     if (auto GV = *Entry) {
       if (Alignment.getQuantity() > GV->getAlignment())
         GV->setAlignment(Alignment.getQuantity());
-      return ConstantAddress(GV, Alignment);
+      return ConstantAddress(castStringLiteralToDefaultAddressSpace(*this, GV),
+                             Alignment);
     }
   }
 


Index: clang/test/CodeGenCXX/amdgcn-string-literal.cpp
===================================================================
--- clang/test/CodeGenCXX/amdgcn-string-literal.cpp
+++ clang/test/CodeGenCXX/amdgcn-string-literal.cpp
@@ -14,7 +14,7 @@
 // CHECK-LABEL: define void @_Z1fv()
 void f() {
   const char* l_str = "l_str";
-  
+
   // CHECK: call void @llvm.memcpy.p0i8.p4i8.i64
   char l_array[] = "l_array";
 
@@ -26,3 +26,9 @@
   const char* p = g_str;
   g(p);
 }
+
+// CHECK-LABEL: define void @_Z1ev
+void e() {
+  g("string literal");
+  g("string literal");
+}
Index: clang/lib/CodeGen/CodeGenModule.cpp
===================================================================
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -4522,7 +4522,8 @@
     if (auto GV = *Entry) {
       if (Alignment.getQuantity() > GV->getAlignment())
         GV->setAlignment(Alignment.getQuantity());
-      return ConstantAddress(GV, Alignment);
+      return ConstantAddress(castStringLiteralToDefaultAddressSpace(*this, GV),
+                             Alignment);
     }
   }
 
@@ -4584,7 +4585,8 @@
     if (auto GV = *Entry) {
       if (Alignment.getQuantity() > GV->getAlignment())
         GV->setAlignment(Alignment.getQuantity());
-      return ConstantAddress(GV, Alignment);
+      return ConstantAddress(castStringLiteralToDefaultAddressSpace(*this, GV),
+                             Alignment);
     }
   }
 
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to