This is an archive of the discontinued LLVM Phabricator instance.

[scan-build] fix warnings emitted on LLVM MachineCode code base
Needs ReviewPublic

Authored by apelete on May 5 2016, 6:44 AM.

Details

Summary

Fix logic error warnings of the type "called C++ object pointer is
null" emitted by Clang Static Analyzer on the following file:

  • lib/MC/MCParser/AsmParser.cpp.

Signed-off-by: Apelete Seketeli <apelete@seketeli.net>

Diff Detail

Event Timeline

apelete updated this revision to Diff 56278.May 5 2016, 6:44 AM
apelete retitled this revision from to [scan-build] fix warnings emitted on LLVM MachineCode code base Fix logic error warnings of the type "called C++ object pointer is null" emitted by Clang Static Analyzer on the following file: - lib/MC/MCParser/AsmParser.cpp..
apelete updated this object.
apelete added reviewers: grosbach, rafael.
apelete added a subscriber: llvm-commits.
rafael edited edge metadata.May 5 2016, 7:04 AM
rafael added a subscriber: rafael.

When is Sec null?

apelete retitled this revision from [scan-build] fix warnings emitted on LLVM MachineCode code base Fix logic error warnings of the type "called C++ object pointer is null" emitted by Clang Static Analyzer on the following file: - lib/MC/MCParser/AsmParser.cpp. to [scan-build] fix warnings emitted on LLVM MachineCode code base.May 5 2016, 7:46 AM
apelete updated this object.
apelete edited edge metadata.

But is the static analyzer correct?

Cheers,
Rafael

apelete added a comment.EditedMay 5 2016, 8:16 AM

But is the static analyzer correct?

Cheers,
Rafael

Let's see:

  1. MCSection *Sec = getStreamer().getCurrentSection().first;

Here the analyzer seems to be complaining about the fact that the pointer to MCSection type (which is the first element of MCSectionSubPair type that is returned by getStreamer().getCurrentSection().first) might be nullptr.
Digging into the declaration of MCTargetStreamer class which AsmParser class indirectly derives from, it appears that MCSectionSubPair is not initialized by its constructor.

I understand that there is a code path that takes care of such an initialization, but from static analysis point of view that particular code path might not have been taken at this point.

Should I assert Sec value before if (!Sec->getBeginSymbol()) ?

espindola edited reviewers, added: espindola; removed: rafael.Mar 15 2018, 10:50 AM