Skip to content

Commit

Permalink
[flang] Do not write implicit SAVE attribute into the mod file. (#67215)
Browse files Browse the repository at this point in the history
If it happens that a symbol has an implicit SAVE attribute,
we have to omit it in the mod file writer. Otherwise it may
violate F202X C862:
The SAVE attribute shall not be specified for... an object that is
in a common block.
  • Loading branch information
vzakhari committed Sep 25, 2023
1 parent e7b8e18 commit 1db42fa
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
12 changes: 10 additions & 2 deletions flang/lib/Semantics/mod-file.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,14 @@ bool ModFileWriter::PutComponents(const Symbol &typeSymbol) {
}
}

// Return the symbol's attributes that should be written
// into the mod file.
static Attrs getSymbolAttrsToWrite(const Symbol &symbol) {
// Is SAVE attribute is implicit, it should be omitted
// to not violate F202x C862 for a common block member.
return symbol.attrs() & ~(symbol.implicitAttrs() & Attrs{Attr::SAVE});
}

static llvm::raw_ostream &PutGenericName(
llvm::raw_ostream &os, const Symbol &symbol) {
if (IsGenericDefinedOp(symbol)) {
Expand Down Expand Up @@ -314,7 +322,7 @@ void ModFileWriter::PutSymbol(
}
decls_ << '\n';
if (symbol.attrs().test(Attr::BIND_C)) {
PutAttrs(decls_, symbol.attrs(), x.bindName(),
PutAttrs(decls_, getSymbolAttrsToWrite(symbol), x.bindName(),
x.isExplicitBindName(), ""s);
decls_ << "::/" << symbol.name() << "/\n";
}
Expand Down Expand Up @@ -723,7 +731,7 @@ void ModFileWriter::PutObjectEntity(
}
PutEntity(
os, symbol, [&]() { PutType(os, DEREF(symbol.GetType())); },
symbol.attrs());
getSymbolAttrsToWrite(symbol));
PutShape(os, details.shape(), '(', ')');
PutShape(os, details.coshape(), '[', ']');
PutInit(os, symbol, details.init(), details.unanalyzedPDTComponentInit());
Expand Down
18 changes: 18 additions & 0 deletions flang/test/Semantics/modfile58.f90
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
! RUN: %python %S/test_modfile.py %s %flang_fc1

! Test that the implicit SAVE attribute (set
! for the equivalenced symbols) is not written
! into the mod file.
module implicit_save
real dx,dy
common /blk/ dx
equivalence(dx,dy)
end module implicit_save

!Expect: implicit_save.mod
!moduleimplicit_save
!real(4)::dx
!real(4)::dy
!common/blk/dx
!equivalence(dx,dy)
!end

0 comments on commit 1db42fa

Please sign in to comment.