diff --git a/flang/lib/Semantics/compute-offsets.cpp b/flang/lib/Semantics/compute-offsets.cpp --- a/flang/lib/Semantics/compute-offsets.cpp +++ b/flang/lib/Semantics/compute-offsets.cpp @@ -173,9 +173,13 @@ Symbol &base{*dep.symbol}; if (const auto *baseBlock{FindCommonBlockContaining(base)}) { if (baseBlock == &commonBlock) { - context_.Say(errorSite, - "'%s' is storage associated with '%s' by EQUIVALENCE elsewhere in COMMON block /%s/"_err_en_US, - symbol.name(), base.name(), commonBlock.name()); + if (base.offset() != symbol.offset() - dep.offset || + std::find(details.objects().begin(), details.objects().end(), + base) != details.objects().end()) { + context_.Say(errorSite, + "'%s' is storage associated with '%s' by EQUIVALENCE elsewhere in COMMON block /%s/"_err_en_US, + symbol.name(), base.name(), commonBlock.name()); + } } else { // 8.10.3(1) context_.Say(errorSite, "'%s' in COMMON block /%s/ must not be storage associated with '%s' in COMMON block /%s/ by EQUIVALENCE"_err_en_US, diff --git a/flang/test/Semantics/offsets03.f90 b/flang/test/Semantics/offsets03.f90 --- a/flang/test/Semantics/offsets03.f90 +++ b/flang/test/Semantics/offsets03.f90 @@ -60,4 +60,8 @@ integer :: i5, j5, l5(10) equivalence(l5(1), i5) common /common7/ j5, i5 ! CHECK: common7 size=44 offset=0: CommonBlockDetails alignment=4: + + real :: a1, a2, a3(2) + equivalence(a1,a3(1)),(a2,a3(2)) + common /common8/ a1, a2 ! CHECK: common8 size=8 offset=0: CommonBlockDetails alignment=4: end