[PATCH] D58509: [CodeGen] Fix string literal address space casting.

Michael Liao via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 21 07:42:57 PST 2019


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);
     }
   }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D58509.187797.patch
Type: text/x-patch
Size: 1450 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190221/ad5bd005/attachment.bin>


More information about the cfe-commits mailing list