Skip to content

Commit

Permalink
[CodeGen] Fix string literal address space casting.
Browse files Browse the repository at this point in the history
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

llvm-svn: 354610
  • Loading branch information
darkbuck committed Feb 21, 2019
1 parent 948c9f9 commit 0ee7bd4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
6 changes: 4 additions & 2 deletions clang/lib/CodeGen/CodeGenModule.cpp
Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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);
}
}

Expand Down
8 changes: 7 additions & 1 deletion clang/test/CodeGenCXX/amdgcn-string-literal.cpp
Expand Up @@ -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";

Expand All @@ -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");
}

0 comments on commit 0ee7bd4

Please sign in to comment.