Skip to content

[flang][lowering] Fix clash between string literals of different kinds #67576

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion flang/lib/Lower/ConvertConstant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
17 changes: 17 additions & 0 deletions flang/test/Lower/HLFIR/constant-character.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
! Test that character literals of different 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>