]> granicus.if.org Git - clang/commitdiff
[CodeGen] Fix string literal address space casting.
authorMichael Liao <michael.hliao@gmail.com>
Thu, 21 Feb 2019 19:40:20 +0000 (19:40 +0000)
committerMichael Liao <michael.hliao@gmail.com>
Thu, 21 Feb 2019 19:40:20 +0000 (19:40 +0000)
Summary:
- If a string literal is reused directly, need to add necessary address
  space casting if the target requires that.

Reviewers: yaxunl

Subscribers: jvesely, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D58509

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@354610 91177308-0d34-0410-b5e6-96231b3b80d8

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

index 972d2afa8e6c5314ff55e1a5cf4467328d1d1781..65116dba095b0f57356c5fe6d9ce98bdee46568b 100644 (file)
@@ -4522,7 +4522,8 @@ CodeGenModule::GetAddrOfConstantStringFromLiteral(const StringLiteral *S,
     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 @@ ConstantAddress CodeGenModule::GetAddrOfConstantCString(
     if (auto GV = *Entry) {
       if (Alignment.getQuantity() > GV->getAlignment())
         GV->setAlignment(Alignment.getQuantity());
-      return ConstantAddress(GV, Alignment);
+      return ConstantAddress(castStringLiteralToDefaultAddressSpace(*this, GV),
+                             Alignment);
     }
   }
 
index 70be249433fb16c8a50e7616d37acc46497b63bf..31480771653ea5e970b05a202f0cdd97de1d8dbd 100644 (file)
@@ -14,7 +14,7 @@ void g(const char* p);
 // 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 @@ void f() {
   const char* p = g_str;
   g(p);
 }
+
+// CHECK-LABEL: define void @_Z1ev
+void e() {
+  g("string literal");
+  g("string literal");
+}