[flang-commits] [flang] 06d103f - [flang] Correct bug in literal CHARACTER constant names
Valentin Clement via flang-commits
flang-commits at lists.llvm.org
Thu Jun 30 01:10:48 PDT 2022
Author: Valentin Clement
Date: 2022-06-30T10:10:37+02:00
New Revision: 06d103ff9553197f6d4d545366f4fa2996a82a10
URL: https://github.com/llvm/llvm-project/commit/06d103ff9553197f6d4d545366f4fa2996a82a10
DIFF: https://github.com/llvm/llvm-project/commit/06d103ff9553197f6d4d545366f4fa2996a82a10.diff
LOG: [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 at nvidia.com>
Added:
Modified:
flang/lib/Lower/ConvertExpr.cpp
flang/test/Lower/array-wide-char.f90
Removed:
################################################################################
diff --git a/flang/lib/Lower/ConvertExpr.cpp b/flang/lib/Lower/ConvertExpr.cpp
index e0f77736208d..3840de68fe23 100644
--- a/flang/lib/Lower/ConvertExpr.cpp
+++ b/flang/lib/Lower/ConvertExpr.cpp
@@ -1513,8 +1513,10 @@ class ScalarExprLowering {
// 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(
diff --git a/flang/test/Lower/array-wide-char.f90 b/flang/test/Lower/array-wide-char.f90
index 43d9e9d546bd..db48ada8e5c0 100644
--- a/flang/test/Lower/array-wide-char.f90
+++ b/flang/test/Lower/array-wide-char.f90
@@ -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)
More information about the flang-commits
mailing list