[flang-commits] [flang] 7ad3825 - [flang][lowering] Fix clash between string literals of different kinds (#67576)
via flang-commits
flang-commits at lists.llvm.org
Thu Sep 28 01:47:09 PDT 2023
Author: jeanPerier
Date: 2023-09-28T10:47:04+02:00
New Revision: 7ad3825975770e26972873b9e72f57e98647eb66
URL: https://github.com/llvm/llvm-project/commit/7ad3825975770e26972873b9e72f57e98647eb66
DIFF: https://github.com/llvm/llvm-project/commit/7ad3825975770e26972873b9e72f57e98647eb66.diff
LOG: [flang][lowering] Fix clash between string literals of different kinds (#67576)
At least fir.global for empty string literals of different kinds. Add
the kind to the prefix if it is not 1.
Added:
flang/test/Lower/HLFIR/constant-character.f90
Modified:
flang/lib/Lower/ConvertConstant.cpp
Removed:
################################################################################
diff --git a/flang/lib/Lower/ConvertConstant.cpp b/flang/lib/Lower/ConvertConstant.cpp
index ded0a1959a6c1eb..940e70da511c22e 100644
--- a/flang/lib/Lower/ConvertConstant.cpp
+++ b/flang/lib/Lower/ConvertConstant.cpp
@@ -323,7 +323,8 @@ genScalarLit(fir::FirOpBuilder &builder, mlir::Location loc,
auto size = builder.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);
+ std::string globalName = fir::factory::uniqueCGIdent(
+ KIND == 1 ? "cl"s : "cl"s + std::to_string(KIND), strVal);
fir::GlobalOp global = builder.getNamedGlobal(globalName);
fir::CharacterType type =
fir::CharacterType::get(builder.getContext(), KIND, len);
diff --git a/flang/test/Lower/HLFIR/constant-character.f90 b/flang/test/Lower/HLFIR/constant-character.f90
new file mode 100644
index 000000000000000..0c788488930bd92
--- /dev/null
+++ b/flang/test/Lower/HLFIR/constant-character.f90
@@ -0,0 +1,17 @@
+! Test that character literals of
diff erent types do not clash.
+! RUN: bbc -emit-hlfir %s -o - | FileCheck %s
+
+subroutine repro(c1, c4)
+ character(kind=1,len=*) :: c1
+ character(kind=4,len=*) :: c4
+ print *, ""
+ print *, 4_""
+end subroutine
+!CHECK-LABEL: func.func @_QPrepro
+!CHECK: fir.address_of(@_QQcl.) : !fir.ref<!fir.char<1,0>>
+!CHECK: fir.call @_FortranAioOutputAscii
+!CHECK: fir.address_of(@_QQcl4.) : !fir.ref<!fir.char<4,0>>
+!CHECK: fir.call @_FortranAioOutputDescriptor(
+
+!CHECK-DAG: fir.global linkonce @_QQcl. constant : !fir.char<1,0>
+!CHECK-DAG: fir.global linkonce @_QQcl4. constant : !fir.char<4,0>
More information about the flang-commits
mailing list