[flang-dev] [f18]How to check if a variable was initialised in f18.
Timothy Keith via flang-dev
flang-dev at lists.llvm.org
Fri Dec 6 08:59:40 PST 2019
You are right, a variable initialized with a DATA statement should have an initial value returned by init() and that comes from DataStmtValue. That’s not implemented yet, whether the DATA statement is in a BLOCK DATA program unit or not.
Somewhere in resolve-names.cc we need to recognize DataStmtSet and walk through the lists of DataStmtObject and DataStmtValue and set the initialization of the objects from the values.
Tim
From: Caroline Concatto <Caroline.Concatto at arm.com>
Date: Friday, December 6, 2019 at 8:11 AM
To: Timothy Keith <tkeith at nvidia.com>, "flang-dev at lists.llvm.org" <flang-dev at lists.llvm.org>
Subject: Re: [flang-dev] [f18]How to check if a variable was initialised in f18.
Hey,
I have another question:
So I would imagine that a variable initialized with DATA block could be checked as: object->init().has_value()
But this code :
BLOCK DATA DBAXES
Integer ifail
COMMON /CBAXES/I,J,K
DATA I,J,K,ifail /1,2,3,4/
END BLOCK DATA
When I run does not accuse ifail as being initialized.
Looking at the code I can see that if a variable is initialized as DATA it is only saved as std::list<common::Indirection<parser::DataStmtValue>>, is this correct? I mean is my thought correct?
Carol
From: Timothy Keith <tkeith at nvidia.com>
Date: Wednesday, 27 November 2019 at 15:32
To: Caroline Concatto <Caroline.Concatto at arm.com>, "flang-dev at lists.llvm.org" <flang-dev at lists.llvm.org>
Subject: Re: [flang-dev] [f18]How to check if a variable was initialised in f18.
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/20191206/4232569f/attachment-0001.html>
More information about the flang-dev
mailing list