From 6ffea74f7c2cda7de91879a771daa6d45da198d9 Mon Sep 17 00:00:00 2001 From: jeanPerier Date: Fri, 8 Sep 2023 10:43:55 +0200 Subject: [flang] Use BIND name, if any, when consolidating common blocks (#65613) This patch changes how common blocks are aggregated and named in lowering in order to: * fix one obvious issue where BIND(C) and non BIND(C) with the same Fortran name were "merged" * go further and deal with a derivative where the BIND(C) C name matches the assembly name of a Fortran common block. This is a bit unspecified IMHO, but gfortran, ifort, and nvfortran "merge" the common block without complaints as a linker would have done. This required getting rid of all the common block mangling early in FIR (\_QC) instead of leaving that to the phase that emits LLVM from FIR because BIND(C) common blocks did not have mangled names. Care has to be taken to deal with the underscoring option of flang-new. See added flang/test/Lower/HLFIR/common-block-bindc-conflicts.f90 for an illustration. --- flang/lib/Frontend/CompilerInvocation.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'flang/lib/Frontend/CompilerInvocation.cpp') diff --git a/flang/lib/Frontend/CompilerInvocation.cpp b/flang/lib/Frontend/CompilerInvocation.cpp index 81bf89b..dba2ac1 100644 --- a/flang/lib/Frontend/CompilerInvocation.cpp +++ b/flang/lib/Frontend/CompilerInvocation.cpp @@ -1237,7 +1237,8 @@ void CompilerInvocation::setSemanticsOpts( .set_searchDirectories(fortranOptions.searchDirectories) .set_intrinsicModuleDirectories(fortranOptions.intrinsicModuleDirectories) .set_warningsAreErrors(getWarnAsErr()) - .set_moduleFileSuffix(getModuleFileSuffix()); + .set_moduleFileSuffix(getModuleFileSuffix()) + .set_underscoring(getCodeGenOpts().Underscoring); llvm::Triple targetTriple{llvm::Triple(this->targetOpts.triple)}; // FIXME: Handle real(3) ? @@ -1262,6 +1263,7 @@ void CompilerInvocation::setLoweringOptions() { // Lower TRANSPOSE as a runtime call under -O0. loweringOpts.setOptimizeTranspose(codegenOpts.OptimizationLevel > 0); + loweringOpts.setUnderscoring(codegenOpts.Underscoring); const LangOptions &langOptions = getLangOpts(); Fortran::common::MathOptionsBase &mathOpts = loweringOpts.getMathOptions(); -- cgit v1.1