As Fortran 2018 8.6.4(1), the BIND statement specifies the BIND attribute
for a list of variables and common blocks.
Details
Diff Detail
Event Timeline
flang/lib/Semantics/resolve-names.cpp | ||
---|---|---|
3915 | What happens if this symbol turns out later to be a procedure? I think this sort of check should be done later in check-declarations, after name resolution has been done as the symbol table is complete. |
flang/lib/Semantics/resolve-names.cpp | ||
---|---|---|
3915 |
This works for this case. Check the following case (modfile16.f90 in this patch): real :: d external :: d bind(c, name='dd') :: d real :: e bind(c, name='ee') :: e external :: e bind(c, name='ff') :: f real :: f external :: f You will get errors for d, e, and f. The reason is that it walks the parse-tree for DeclTypeSpecVisitor before parser::BindEntity. (https://github.com/llvm/llvm-project/blob/576b8245c838e822f709d8450f537c7909d45411/flang/lib/Semantics/resolve-names.cpp#L132-L144) For procedures, the symbol has EntityDetails, but GetType is empty.
I tried to look at check-declarations, but I didn't figure out how to do it there since it is unknown if the BIND(C) attribute for procedure is from bind statement or procedure declaration statement. Let me dig some more again to see if it can be done in check-declarations. |
flang/lib/Semantics/resolve-names.cpp | ||
---|---|---|
3915 | @klausler It seems that this must be done here.
|
Will this error be incorrectly triggered if a BIND(C) :: x declaration appears before any other declaration for a variable or COMMON block 'x'? What if a BIND(C) :: j declaration appears as the only declaration for an implicitly-typed variable "j"?
Thanks for this. The previous fix is not correct for this. It should not check if there is the type for the entity. The bind statement is one declaration statement, so it is actually declaring one new entity. The real error is multiple declaration of one name. This is consistent with the errors in ifort.
flang/lib/Semantics/check-declarations.cpp | ||
---|---|---|
1886 | First, you can compare symbol names without converting them to strings. But I don't see why this test is needed here in BIND(C) checking in the first place; it does not seem to be specific to BIND(C). If a check like this is needed, wouldn't it be necessary for non-BIND(C) symbols as well? |
flang/lib/Semantics/check-declarations.cpp | ||
---|---|---|
1886 | I take a look at non-bind(C) symbols, and find out that LLVM Flang can support this. Check the following case: module m integer :: m end LLVM Flang codegen supports this since the name mangling makes the module name and variable name unique. gfortran and ifort do not support this. For BIND(C) symbols, it's the same issue. So, there is no necessary for the previous check. |
flang/lib/Semantics/resolve-names.cpp | ||
---|---|---|
3914 | "named" constant |
First, you can compare symbol names without converting them to strings. But I don't see why this test is needed here in BIND(C) checking in the first place; it does not seem to be specific to BIND(C). If a check like this is needed, wouldn't it be necessary for non-BIND(C) symbols as well?