From: Michael Liao Date: Thu, 21 Feb 2019 19:40:20 +0000 (+0000) Subject: [CodeGen] Fix string literal address space casting. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=eb76eb1a7ebfef45b135b452f6c4ce164e061e40;p=clang [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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@354610 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index 972d2afa8e..65116dba09 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -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); } } diff --git a/test/CodeGenCXX/amdgcn-string-literal.cpp b/test/CodeGenCXX/amdgcn-string-literal.cpp index 70be249433..3148077165 100644 --- a/test/CodeGenCXX/amdgcn-string-literal.cpp +++ b/test/CodeGenCXX/amdgcn-string-literal.cpp @@ -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"); +}