Skip to content

Commit

Permalink
[Flang] -funderscoring bug fix
Browse files Browse the repository at this point in the history
There was a bug with the -funderscoring / -fno-underscoring options from (https://reviews.llvm.org/D140795) that prevented the driver option from controlling the underscoring behaviour and instead the behaviour could only be controlled by the pass option instead of the driver option. The driver test case did not catch the bug and also needed to be updated.

Reviewed By: awarzynski

Differential Revision: https://reviews.llvm.org/D155042
  • Loading branch information
madanial0 committed Jul 13, 2023
1 parent 0249ea6 commit d85b94b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
2 changes: 1 addition & 1 deletion flang/include/flang/Optimizer/Transforms/Passes.td
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def ExternalNameConversion : Pass<"external-name-interop", "mlir::ModuleOp"> {
}];
let constructor = "::fir::createExternalNameConversionPass()";
let options = [
Option<"appendUnderscore", "append-underscore",
Option<"appendUnderscoreOpt", "append-underscore",
"bool", /*default=*/"true",
"Append trailing underscore to external names.">
];
Expand Down
7 changes: 5 additions & 2 deletions flang/lib/Optimizer/Transforms/ExternalNameConversion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,23 +158,26 @@ class ExternalNameConversionPass
ExternalNameConversionPass(bool appendUnderscoring)
: appendUnderscores(appendUnderscoring) {}

ExternalNameConversionPass() { appendUnderscores = appendUnderscore; }
ExternalNameConversionPass() { usePassOpt = true; }

mlir::ModuleOp getModule() { return getOperation(); }
void runOnOperation() override;

private:
bool appendUnderscores;
bool usePassOpt;
};
} // namespace

void ExternalNameConversionPass::runOnOperation() {
auto op = getOperation();
auto *context = &getContext();

appendUnderscores = (usePassOpt) ? appendUnderscoreOpt : appendUnderscores;

mlir::RewritePatternSet patterns(context);
patterns.insert<MangleNameOnFuncOp, MangleNameForCommonBlock,
MangleNameOnAddrOfOp>(context, appendUnderscore);
MangleNameOnAddrOfOp>(context, appendUnderscores);

ConversionTarget target(*context);
target.addLegalDialect<fir::FIROpsDialect, LLVM::LLVMDialect,
Expand Down
12 changes: 6 additions & 6 deletions flang/test/Driver/underscoring.f90
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ subroutine test()
end

! UNDERSCORING: test_
! UNDERSCORING-NOT: {{test:$}}
! UNDERSCORING: ext_sub_
! UNDERSCORING-NOT: {{ext_sub[^_]*$}}
! UNDERSCORING: comblk_
! UNDERSCORING-NOT: comblk,

! NO-UNDERSCORING-NOT: test_
! NO-UNDERSCORING-NOT: _QPtest
! NO-UNDERSCORING: test
! NO-UNDERSCORING: test:
! NO-UNDERSCORING-NOT: ext_sub_
! NO-UNDERSCORING-NOT: _QPext_sub
! NO-UNDERSCORING: ext_sub
! NO-UNDERSCORING: {{ext_sub[^_]*$}}
! NO-UNDERSCORING-NOT: comblk_
! NO-UNDERSCORING-NOT: _QBcomblk
! NO-UNDERSCORING: comblk
! NO-UNDERSCORING: comblk,

0 comments on commit d85b94b

Please sign in to comment.