This is an archive of the discontinued LLVM Phabricator instance.

[flang] Add check for conflict of BIND(C) and Parameter attributes
ClosedPublic

Authored by peixin on May 30 2022, 7:36 AM.

Details

Summary

The entity with BIND(C) attribute cannot be a named constant, so the
BIND(C) and parameter attributes are conflicted. Add check for it.

Diff Detail

Event Timeline

peixin created this revision.May 30 2022, 7:36 AM
Herald added a project: Restricted Project. · View Herald Transcript
Herald added a subscriber: jdoerfert. · View Herald Transcript
peixin requested review of this revision.May 30 2022, 7:36 AM

Are you checking constraint C818? That constraint lists four things that a BIND(C) item can be. It might be more effective to verify that a BIND(C) entity is one of those four things rather than trying to check that it is not any of the many other possibilities.

Are you checking constraint C818? That constraint lists four things that a BIND(C) item can be. It might be more effective to verify that a BIND(C) entity is one of those four things rather than trying to check that it is not any of the many other possibilities.

OK. Let me dig more to try to add checking for C818.

peixin updated this revision to Diff 433096.May 31 2022, 8:33 AM
peixin retitled this revision from [flang] Add check for conflict of BIND(C) and Parameter attributes to [flang] Check BIND(C) variables attributes.
peixin edited the summary of this revision. (Show Details)

Are you checking constraint C818? That constraint lists four things that a BIND(C) item can be. It might be more effective to verify that a BIND(C) entity is one of those four things rather than trying to check that it is not any of the many other possibilities.

The BIND(C) can only be in type-declaration-stmt, bind-stmt, or proc-language-binding-spec. I think there is no need to check C818 since those does not satisfy C818 will fail in parser with the exception of named constant. Also the pointer and allocatable variables cannot have BIND(C) attribute.

The other semantic checks for bind-stmt and proc-language-binding-spec will be later work. The semantic checks for Section 8.5.5 should be done after this patch.

BTW, I checked the conflict of all the attributes in type-declaration-stmt for BIND(C). The parameter and allocatable attributes can be deduced to be conflicted with BIND(C). For pointer attribute, I don't find the restriction in the standard. gfortran and ifort report the errors.

BTW, I checked the conflict of all the attributes in type-declaration-stmt for BIND(C). The parameter and allocatable attributes can be deduced to be conflicted with BIND(C). For pointer attribute, I don't find the restriction in the standard. gfortran and ifort report the errors.

Pointers and allocatables are not allowed as components in derived types with BIND(C), but there's no such restriction on variables in the standard, and the interoperable descriptor has features to support both pointers and allocatables.

peixin updated this revision to Diff 433107.May 31 2022, 9:09 AM
peixin retitled this revision from [flang] Check BIND(C) variables attributes to [flang] Add check for conflict of BIND(C) and Parameter attributes.
peixin edited the summary of this revision. (Show Details)

Pointers and allocatables are not allowed as components in derived types with BIND(C), but there's no such restriction on variables in the standard

BIND(C) is not allowed as components in derived types. This will fail in parser.

the interoperable descriptor has features to support both pointers and allocatables.

Thanks for letting me know this. I will go forward with that after going through the semantic analysis of interoperability.

Pointers and allocatables are not allowed as components in derived types with BIND(C), but there's no such restriction on variables in the standard

BIND(C) is not allowed as components in derived types. This will fail in parser.

I know, but that's not what I was addressing. BIND(C) is allowed on the derived type itself, and this has consequences of the semantics of the components.

peixin updated this revision to Diff 433331.Jun 1 2022, 2:41 AM

Add more regression tests.

peixin added a comment.Jun 1 2022, 2:53 AM

I know, but that's not what I was addressing. BIND(C) is allowed on the derived type itself, and this has consequences of the semantics of the components.

Oh. Sorry, I misunderstood. Got what you mean.

I checked all the cases for C818. The entity does not satify C818 fails in parser or the semantic checks have been supported before. It seems the named constant is the only exception. Maybe I miss something? The named constant is kind of like special case, such as its usage in common block, function result, or with the bind(c) attribute. The standard usually does not decribe it on purpose. Instead, the standard usually states "a variable" to exclude the named constant. I think these checks are missed since the named constant and variable both have ObjectEntity detail, but they are different. Maybe there are still somewhere missing this check.

klausler accepted this revision.Jun 1 2022, 9:05 AM
This revision is now accepted and ready to land.Jun 1 2022, 9:05 AM