r354610 - [CodeGen] Fix string literal address space casting.

Michael Liao via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 21 11:40:20 PST 2019


Author: hliao
Date: Thu Feb 21 11:40:20 2019
New Revision: 354610

URL: http://llvm.org/viewvc/llvm-project?rev=354610&view=rev
Log:
[CodeGen] Fix string literal address space casting.

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

Modified:
    cfe/trunk/lib/CodeGen/CodeGenModule.cpp
    cfe/trunk/test/CodeGenCXX/amdgcn-string-literal.cpp

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=354610&r1=354609&r2=354610&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Thu Feb 21 11:40:20 2019
@@ -4522,7 +4522,8 @@ CodeGenModule::GetAddrOfConstantStringFr
     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::GetAddrOf
     if (auto GV = *Entry) {
       if (Alignment.getQuantity() > GV->getAlignment())
         GV->setAlignment(Alignment.getQuantity());
-      return ConstantAddress(GV, Alignment);
+      return ConstantAddress(castStringLiteralToDefaultAddressSpace(*this, GV),
+                             Alignment);
     }
   }
 

Modified: cfe/trunk/test/CodeGenCXX/amdgcn-string-literal.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/amdgcn-string-literal.cpp?rev=354610&r1=354609&r2=354610&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/amdgcn-string-literal.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/amdgcn-string-literal.cpp Thu Feb 21 11:40:20 2019
@@ -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");
+}




More information about the cfe-commits mailing list