diff --git a/flang/lib/Lower/ConvertExpr.cpp b/flang/lib/Lower/ConvertExpr.cpp --- a/flang/lib/Lower/ConvertExpr.cpp +++ b/flang/lib/Lower/ConvertExpr.cpp @@ -1513,8 +1513,10 @@ // 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(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 --- a/flang/test/Lower/array-wide-char.f90 +++ b/flang/test/Lower/array-wide-char.f90 @@ -27,4 +27,4 @@ ! 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)