[flang-dev] [f18]How to check if a variable was initialised in f18.

Timothy Keith via flang-dev flang-dev at lists.llvm.org
Wed Nov 27 07:32:06 PST 2019


You’re getting a segmentation fault because not every symbols has ObjectEntityDetails (only those that represent objects do). So sometimes object is null. If you check for object being nullptr before dereferencing it your code wouldn’t crash.

There are two other kinds of details that also have init(): ProcEntityDetails and TypeParamDetails. If you’re interested in initialization of those kinds of symbols as well, you’ll need to check for those using detailsIf or std::visit over the details of the symbol.

One more thing: If you are only checking constraints and not doing things that affect what ends up in symbols, check-declarations.cc might be a better place for your change. resolve-names.cc is for building up the symbols and it checks constraints along the way. The checks in check-declarations.cc happen after that and are ones that can be done by just looking at the symbol table without any context from the parse tree.

Tim

From: flang-dev <flang-dev-bounces at lists.llvm.org> on behalf of Caroline Concatto via flang-dev <flang-dev at lists.llvm.org>
Reply-To: Caroline Concatto <Caroline.Concatto at arm.com>
Date: Wednesday, November 27, 2019 at 3:07 AM
To: "flang-dev at lists.llvm.org" <flang-dev at lists.llvm.org>
Subject: [flang-dev] [f18]How to check if a variable was initialised in f18.

Hi all,

I don’t know if anyone can help. Probably with more info.
But worth a shot, as a start.

How do I check if a variable was initialized in F18 when my method only receives symbol? Is it possible?

I’ve tried the code bellow, but it gives me segmentation fault.

//F18 function in resolve-names.cc
void ResolveNamesVisitor::FinishSpecificationPart() {
….
  for (auto &pair : currScope()) {
     auto &symbol{*pair.second};
     ….
     CheckInitialization(symbol);
  }
}

void DeclarationVisitor::CheckInitialization(const Symbol &symbol) {
          const auto *object{symbol.detailsIf<ObjectEntityDetails>()};
          if (object->init().has_value()) {
                       Say(symbol.name(),
                                     " Element '%s' was initialized"_err_en_US);

   }
}

By looking at the source code it looks like I need to reference to name, something like symbol.name(), but that does not work.

Thank you,

Carol

-----------------------------------------------------------------------------------
This email message is for the sole use of the intended recipient(s) and may contain
confidential information.  Any unauthorized review, use, disclosure or distribution
is prohibited.  If you are not the intended recipient, please contact the sender by
reply email and destroy all copies of the original message.
-----------------------------------------------------------------------------------
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/flang-dev/attachments/20191127/bd25275e/attachment.html>


More information about the flang-dev mailing list