Skip to content

Commit 1db42fa

Browse files
authored
[flang] Do not write implicit SAVE attribute into the mod file. (llvm#67215)
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.
1 parent e7b8e18 commit 1db42fa

File tree

2 files changed

+28
-2
lines changed

2 files changed

+28
-2
lines changed

flang/lib/Semantics/mod-file.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,14 @@ bool ModFileWriter::PutComponents(const Symbol &typeSymbol) {
244244
}
245245
}
246246

247+
// Return the symbol's attributes that should be written
248+
// into the mod file.
249+
static Attrs getSymbolAttrsToWrite(const Symbol &symbol) {
250+
// Is SAVE attribute is implicit, it should be omitted
251+
// to not violate F202x C862 for a common block member.
252+
return symbol.attrs() & ~(symbol.implicitAttrs() & Attrs{Attr::SAVE});
253+
}
254+
247255
static llvm::raw_ostream &PutGenericName(
248256
llvm::raw_ostream &os, const Symbol &symbol) {
249257
if (IsGenericDefinedOp(symbol)) {
@@ -314,7 +322,7 @@ void ModFileWriter::PutSymbol(
314322
}
315323
decls_ << '\n';
316324
if (symbol.attrs().test(Attr::BIND_C)) {
317-
PutAttrs(decls_, symbol.attrs(), x.bindName(),
325+
PutAttrs(decls_, getSymbolAttrsToWrite(symbol), x.bindName(),
318326
x.isExplicitBindName(), ""s);
319327
decls_ << "::/" << symbol.name() << "/\n";
320328
}
@@ -723,7 +731,7 @@ void ModFileWriter::PutObjectEntity(
723731
}
724732
PutEntity(
725733
os, symbol, [&]() { PutType(os, DEREF(symbol.GetType())); },
726-
symbol.attrs());
734+
getSymbolAttrsToWrite(symbol));
727735
PutShape(os, details.shape(), '(', ')');
728736
PutShape(os, details.coshape(), '[', ']');
729737
PutInit(os, symbol, details.init(), details.unanalyzedPDTComponentInit());

flang/test/Semantics/modfile58.f90

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
! RUN: %python %S/test_modfile.py %s %flang_fc1
2+
3+
! Test that the implicit SAVE attribute (set
4+
! for the equivalenced symbols) is not written
5+
! into the mod file.
6+
module implicit_save
7+
real dx,dy
8+
common /blk/ dx
9+
equivalence(dx,dy)
10+
end module implicit_save
11+
12+
!Expect: implicit_save.mod
13+
!moduleimplicit_save
14+
!real(4)::dx
15+
!real(4)::dy
16+
!common/blk/dx
17+
!equivalence(dx,dy)
18+
!end

0 commit comments

Comments
 (0)