This is an archive of the discontinued LLVM Phabricator instance.

[flang] Let double allocation error be catched by AllocatableAllocate
AbandonedPublic

Authored by clementval on Mar 16 2023, 6:35 AM.

Details

Summary

When doing an allocation, the three following functions can be called
before AllocatableAllocate.

  • AllocatableInitIntrinsic
  • AllocatableInitCharacter
  • AllocatableInitDerived

When the descriptor is allocated, make sure these three function do not
reset it so the double allocation can be caught by AllocatableAllocate
later.

Diff Detail

Event Timeline

clementval created this revision.Mar 16 2023, 6:35 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptMar 16 2023, 6:35 AM
Herald added a subscriber: sunshaoce. · View Herald Transcript
clementval requested review of this revision.Mar 16 2023, 6:35 AM
PeteSteinfeld edited the summary of this revision. (Show Details)Mar 16 2023, 7:43 AM
PeteSteinfeld accepted this revision.Mar 16 2023, 8:06 AM

All builds and tests correctly and looks good.

This revision is now accepted and ready to land.Mar 16 2023, 8:06 AM
klausler added inline comments.Mar 16 2023, 8:15 AM
flang/runtime/allocatable.cpp
24

Like Establish functions, these Init functions should make no assumptions about the contents of the descriptor before they are called. I think that your change depends on lowered code initializing the base addresses of new allocatables to null pointers.

clementval added inline comments.Mar 16 2023, 8:19 AM
flang/runtime/allocatable.cpp
24

If we allocate an already allocated allocatable, these functions will reset the descriptor and therefore the error is not catch in the AllocatableAllocate function. I can also do an inlined check in the lowering before calling these functions if this is preferable.

klausler added inline comments.Mar 16 2023, 8:22 AM
flang/runtime/allocatable.cpp
24

I understand the problem, yes. My concern is that a descriptor containing random garbage will pass your if (descriptor.IsAllocated()) test and then not become established.

clementval added inline comments.Mar 16 2023, 8:24 AM
flang/runtime/allocatable.cpp
24

Ok I see your point. I'll do this differently then.

clementval abandoned this revision.Mar 16 2023, 8:25 AM