This is an archive of the discontinued LLVM Phabricator instance.

[flang][OpenMP] Fix warning due to uninitialized pointer dereference during atomic update lowering
ClosedPublic

Authored by NimishMishra on Jul 15 2022, 6:56 PM.

Details

Summary

This patch places a guard around to prevent nullptr deference during atomic update lowering

Diff Detail

Event Timeline

NimishMishra created this revision.Jul 15 2022, 6:56 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptJul 15 2022, 6:56 PM
NimishMishra requested review of this revision.Jul 15 2022, 6:56 PM
peixin added inline comments.Jul 15 2022, 8:39 PM
flang/lib/Lower/OpenMP.cpp
1129–1130

Can you move the code in line 1130-1138 to line 1164?

1130

Is it better to move this assert outside in line 1164?

You can submit it after addressing @peixin's comment. If there are issues then revert D125668.

flang/lib/Lower/OpenMP.cpp
1129–1130

+1

This revision is now accepted and ready to land.Jul 15 2022, 9:21 PM
kazu added a subscriber: kazu.Jul 15 2022, 10:09 PM

Thank you for the patch. I am wondering if it's better to completely remove the if statements. Please see the inline comments. Thanks again!

flang/lib/Lower/OpenMP.cpp
1129–1130

If you expect updateSymbol to be always set, could we do something like this? We can catch errors earlier this way. Also, if statements that are always taken should be assert instead.

auto varDesignator =
    std::get_if<Fortran::common::Indirection<Fortran::parser::Designator>>(
        &assignmentStmtVariable.u);
assert(varDesignator && "varDesignator must have a value.");
const auto *name = getDesignatorNameIfDataRef(varDesignator->value());
assert(name && name->symbol &&
       "No symbol attached to atomic update variable.");
const Fortran::semantics::Symbol *updateSymbol = name->symbol;
flang/lib/Lower/OpenMP.cpp
1129–1130

That is a nice suggestion.

Addressed comments.

kazu added a comment.Jul 15 2022, 11:13 PM

Thank you for updating the patch. Please see the inline comment.

flang/lib/Lower/OpenMP.cpp
1156–1164

If you are moving this block of code, you might as well do:

const Fortran::semantics::Symbol *updateSymbol = name->symbol;
converter.bindSymbol(*updateSymbol, val);

or drop the intermediate variable altogether:

converter.bindSymbol(*(name->symbol), val);

I would avoid an unused value like = nullptr in the straight-line code. Some compilers might even issue a warning like "set but unused" or something.

Addressed comment.

kazu accepted this revision.Jul 15 2022, 11:45 PM

LGTM. Thank you for updating the patch!