This is an archive of the discontinued LLVM Phabricator instance.

[flang] Unnecessary call to CHECK() for call to NULL() as an actual argument
AbandonedPublic

Authored by PeteSteinfeld on Sep 17 2020, 2:46 PM.

Details

Summary

A program that passes NULL() to the intrinsic ASSOCIATED() should return an
error since section 16.9.16 requires that the pointer association status "shall
not be undefined".

In processing NULL() as an actual argument, the compiler ends up with an
'std::nullopt', which caused a call to 'CHECK()' to fail. But the value of
'std::nullopt' seems correct to me.

I fixed this by just removing the call to 'CHECK()' and adding a test.

Diff Detail

Unit TestsFailed

Event Timeline

PeteSteinfeld created this revision.Sep 17 2020, 2:46 PM
Herald added a project: Restricted Project. · View Herald Transcript
PeteSteinfeld requested review of this revision.Sep 17 2020, 2:46 PM
PeteSteinfeld added a project: Restricted Project.Sep 17 2020, 2:46 PM
klausler requested changes to this revision.Sep 17 2020, 2:57 PM

NULL() isn't "undefined". It's a pointer (or in some other contexts, an unallocated allocatable), and the description of ASSOCIATED() in 16.9.16 just requires that its first (POINTER=) argument be a pointer.

(Even if NULL() were undefined, it would be okay -- see paragraph (2) of 16.1, which describes general rules for inquiry functions, of which ASSOCIATED is an example.) "Unless the description of an intrinsic inquiry function states otherwise, these arguments are permitted to be unallocated allocatable variables or pointers that are undefined or disassociated."

This revision now requires changes to proceed.Sep 17 2020, 2:57 PM

NULL() isn't "undefined". It's a pointer (or in some other contexts, an unallocated allocatable), and the description of ASSOCIATED() in 16.9.16 just requires that its first (POINTER=) argument be a pointer.

(Even if NULL() were undefined, it would be okay -- see paragraph (2) of 16.1, which describes general rules for inquiry functions, of which ASSOCIATED is an example.) "Unless the description of an intrinsic inquiry function states otherwise, these arguments are permitted to be unallocated allocatable variables or pointers that are undefined or disassociated."

This all sounds reasonable to me. If what you say is all correct, I would expect the call to ALLOCATED() to return .FALSE.. But every compiler I've tried (IBM, Intel, PGI, and GNU) all produce compile-time errors.

@klausler, is it your guidance that we should compiler the expression ALLOCATED(NULL)) without error?

NULL() isn't "undefined". It's a pointer (or in some other contexts, an unallocated allocatable), and the description of ASSOCIATED() in 16.9.16 just requires that its first (POINTER=) argument be a pointer.

(Even if NULL() were undefined, it would be okay -- see paragraph (2) of 16.1, which describes general rules for inquiry functions, of which ASSOCIATED is an example.) "Unless the description of an intrinsic inquiry function states otherwise, these arguments are permitted to be unallocated allocatable variables or pointers that are undefined or disassociated."

This all sounds reasonable to me. If what you say is all correct, I would expect the call to ALLOCATED() to return .FALSE.. But every compiler I've tried (IBM, Intel, PGI, and GNU) all produce compile-time errors.

@klausler, is it your guidance that we should compiler the expression ALLOCATED(NULL)) without error?

nagfor gets it right; we should do so too.

PeteSteinfeld abandoned this revision.Sep 24 2020, 2:55 PM

I've lost the repository where I was working on this, so I'm abandoning it.