Skip to content

Commit 7ad3825

Browse files
authored
[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.
1 parent aa9eb47 commit 7ad3825

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

flang/lib/Lower/ConvertConstant.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,8 @@ genScalarLit(fir::FirOpBuilder &builder, mlir::Location loc,
323323

324324
auto size = builder.getKindMap().getCharacterBitsize(KIND) / 8 * value.size();
325325
llvm::StringRef strVal(reinterpret_cast<const char *>(value.c_str()), size);
326-
std::string globalName = fir::factory::uniqueCGIdent("cl", strVal);
326+
std::string globalName = fir::factory::uniqueCGIdent(
327+
KIND == 1 ? "cl"s : "cl"s + std::to_string(KIND), strVal);
327328
fir::GlobalOp global = builder.getNamedGlobal(globalName);
328329
fir::CharacterType type =
329330
fir::CharacterType::get(builder.getContext(), KIND, len);
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
! Test that character literals of different types do not clash.
2+
! RUN: bbc -emit-hlfir %s -o - | FileCheck %s
3+
4+
subroutine repro(c1, c4)
5+
character(kind=1,len=*) :: c1
6+
character(kind=4,len=*) :: c4
7+
print *, ""
8+
print *, 4_""
9+
end subroutine
10+
!CHECK-LABEL: func.func @_QPrepro
11+
!CHECK: fir.address_of(@_QQcl.) : !fir.ref<!fir.char<1,0>>
12+
!CHECK: fir.call @_FortranAioOutputAscii
13+
!CHECK: fir.address_of(@_QQcl4.) : !fir.ref<!fir.char<4,0>>
14+
!CHECK: fir.call @_FortranAioOutputDescriptor(
15+
16+
!CHECK-DAG: fir.global linkonce @_QQcl. constant : !fir.char<1,0>
17+
!CHECK-DAG: fir.global linkonce @_QQcl4. constant : !fir.char<4,0>

0 commit comments

Comments
 (0)