[flang] Correct bug in literal CHARACTER constant names

The names of CHARACTER strings were being truncated leading to invalid
collisions and other failures. This change makes sure to use the entire
string as the seed for the unique name.

This patch is part of the upstreaming effort from fir-dev branch.

Reviewed By: jeanPerier

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
This commit is contained in:
Valentin Clement 2022-06-30 10:09:47 +02:00
parent 76f7e4b7a3
commit 06d103ff95
No known key found for this signature in database
GPG Key ID: 086D54783C928776
2 changed files with 5 additions and 3 deletions

View File

@ -1513,8 +1513,10 @@ public:
// Otherwise, the string is in a plain old expression so "outline" the value
// by hashconsing it to a constant literal object.
std::string globalName =
fir::factory::uniqueCGIdent("cl", (const char *)value.c_str());
auto size =
converter.getKindMap().getCharacterBitsize(KIND) / 8 * value.size();
llvm::StringRef strVal(reinterpret_cast<const char *>(value.c_str()), size);
std::string globalName = fir::factory::uniqueCGIdent("cl", strVal);
fir::GlobalOp global = builder.getNamedGlobal(globalName);
if (!global)
global = builder.createGlobalConstant(

View File

@ -27,4 +27,4 @@ end subroutine sub1
! CHECK: call void @_QPaction_on_char4(ptr @_QFEarr, i64 10)
! CHECK-LABEL: define void @_QPsub1(
! CHECK: call void @_QPsub2(ptr @_QQcl.77, i64 63)
! CHECK: call void @_QPsub2(ptr @_QQcl[[inline]], i64 63)