[flang-commits] [flang] [flang] Avoid crash on conflicting BIND(C) declaration (PR #231816)
Eugene Epshteyn via flang-commits
flang-commits at lists.llvm.org
Wed Oct 14 19:58:13 PDT 2026
================
@@ -6831,7 +6831,7 @@ Symbol &DeclarationVisitor::DeclareUnknownEntity(
Attr::SAVE, Attr::TARGET, Attr::VALUE, Attr::VOLATILE})) {
ConvertToObjectEntity(symbol);
}
- if (attrs.test(Attr::BIND_C)) {
+ if (attrs.test(Attr::BIND_C) && !context().HasError(symbol)) {
----------------
eugeneepshteyn wrote:
(This comment was generated with the help of AI)
`context().HasError(symbol)` is also true for a genuine variable that an earlier statement, or `SetType` on this very statement, has already marked erroneous. For such a symbol `SetBindNameOn` is now skipped altogether, and with it the "multiple BIND names" check it performs:
```fortran
module m
integer, bind(c, name="a") :: x
real, bind(c, name="b") :: x
end module
```
Today `flang -fsyntax-only` reports `The entity 'x' has multiple BIND names ('a' and 'b')` next to the two other errors; with this change that message disappears, while the same two declarations written as arrays (`x(2)` on both lines, which go through `DeclareObjectEntity`) keep it. The question that matters here is whether the symbol can carry a binding label at all, which is how `DeclareObjectEntity` and `DeclareProcEntity` guard the same call: they test the symbol's details class. The same test works here and still fixes the crash, because every branch of `DeclareEntity<EntityDetails>` that reports a conflict hands back the pre-existing symbol, which is never an entity.
https://github.com/llvm/llvm-project/pull/231816
More information about the flang-commits
mailing list