This is an archive of the discontinued LLVM Phabricator instance.

[scan-build] fix warnings emitted on LLVM Hexagon code base
ClosedPublic

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

Details

Summary

This path fixes the following warnings that were reported while
running Clang Static Analyzer on Clang code base:

Logic error: called C++ object pointer is null, on files

  • lib/Target/Hexagon/RDFGraph.cpp
  • lib/Target/Hexagon/HexagonCFGOptimizer.cpp.

Logic error: branch condition evaluates to a garbage value, on file:

  • lib/Target/Hexagon/HexagonInstrInfo.cpp.

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

Diff Detail

Repository
rL LLVM

Event Timeline

apelete updated this revision to Diff 56276.May 5 2016, 6:21 AM
apelete retitled this revision from to [scan-build] fix warnings emitted on LLVM Hexagon code base.
apelete added a reviewer: kparzysz.
apelete updated this object.
apelete added a subscriber: llvm-commits.
kparzysz accepted this revision.May 5 2016, 7:06 AM
kparzysz edited edge metadata.

LGTM. I added a minor comment, but it's not a blocker.

lib/Target/Hexagon/HexagonInstrInfo.cpp
1304 ↗(On Diff #56276)

The array OpCExtended is initialized in the loop below (line 1308).

This revision is now accepted and ready to land.May 5 2016, 7:06 AM
apelete added inline comments.May 5 2016, 2:22 PM
lib/Target/Hexagon/HexagonInstrInfo.cpp
1304 ↗(On Diff #56276)

This one was added to suppress a warning in the following case:

  1. ​ if (NumOperands > 4)
  2. ​ NumOperands = 4;
  3. ​ for (int i = 0; i < NumOperands; i++)
  4. ​ OpCExtended[i] = (isOperandExtended(&MI, i) && isConstExtended(&MI));
  5. ​​ switch(Opc) {

...

  1. ​ case Hexagon::S4_storeiri_io:
  2. return (OpCExtended[1] || isUInt<6>(MI.getOperand(1).getImm())) &&
  3. (OpCExtended[2] || isInt<6>(MI.getOperand(2).getImm()));

...

  1. }

If branches at lines 1305 and 1308 evaluate to 'false', then the branch condition at line 1362 would evaluate to a garbage value because OpCExtended wasn't initialized.

If this is OK for you, then I would need your help to commit this for me as I do not have commit access.

Thanks.

This revision was automatically updated to reflect the committed changes.
kparzysz added inline comments.May 5 2016, 3:06 PM
lib/Target/Hexagon/HexagonInstrInfo.cpp
1304 ↗(On Diff #56276)

NumOperands is the number of operands in the instruction. S4_storeiri_io has 3, so NumOperands will be 3. The loop at 1308-1309 will initialize OpCExtended for i=0..2, so both references will be valid.