This is an archive of the discontinued LLVM Phabricator instance.

[scan-build] fix logic error warnings emitted on llvm code base
AbandonedPublic

Authored by apelete on Apr 25 2016, 2:36 PM.

Details

Summary

This patch fixes logic error warnings of the type "called C++ object
pointer is null" that were emitted by Clang Static Analyzer on the
following files:

  • lib/Transforms/Scalar/TailRecursionElimination.cpp,
  • lib/Transforms/Scalar/StructurizeCFG.cpp,
  • lib/Transforms/Scalar/ScalarReplAggregates.cpp,
  • lib/Target/X86/AsmParser/X86AsmParser.cpp,
  • lib/Target/Hexagon/RDFGraph.cpp,
  • lib/Target/Hexagon/HexagonCFGOptimizer.cpp,
  • lib/Target/ARM/Thumb2SizeReduction.cpp,
  • lib/Target/ARM/MCTargetDesc/ARMMachObjectWriter.cpp,
  • lib/Target/ARM/ARMFrameLowering.cpp,
  • lib/CodeGen/ScheduleDAGInstrs.cpp,
  • lib/Bitcode/Writer/BitcodeWriter.cpp.

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

Diff Detail

Event Timeline

apelete updated this revision to Diff 54911.Apr 25 2016, 2:36 PM
apelete retitled this revision from to [scan-build] fix logic error warnings emitted on llvm code base.
apelete updated this object.
apelete added a subscriber: llvm-commits.
kparzysz edited edge metadata.Apr 25 2016, 2:46 PM

The Hexagon part looks good to me.

I looked at the ScheduleDAG and ARM changes here.

lib/CodeGen/ScheduleDAGInstrs.cpp
917–918

I think this is so obvious that we don't even need the assert. We will get a crash in MI->isDebugValue() anyway when MI is nullptr.

lib/Target/ARM/ARMFrameLowering.cpp
1710

ARMBaseRegisterInfo::requiresRegisterScavenging() always returns true. So this should never be nullptr, instead of adding the assert you can probably remove the nullptr-check in line 1610.

lib/Target/ARM/Thumb2SizeReduction.cpp
976–977

This looks like it needs to go inside the "if (MI->isInsideBundle())" case below. I must admit I also don't understand why the analyzer would warn here, there is nothing obvious that indicates that BundleMI may be a nullptr below...

apelete updated this revision to Diff 55012.Apr 26 2016, 8:44 AM
apelete marked 2 inline comments as done.
apelete edited edge metadata.

[scan-build] fix logic error warnings emitted on llvm code base

Changes since last revision:

  • lib/CodeGen/ScheduleDAGInstrs.cpp: remove assert and nullptr check on MachineInstr pointer to suppress analyzer warning: dereferencing MI pointer will induce a crash if it is null anyway,
  • lib/Target/ARM/ARMFrameLowering.cpp: remove assert and nullptr check on RegScavenger pointer since ARMBaseRegisterInfo::requiresRegisterScavenging() always returns true,
  • lib/Target/ARM/Thumb2SizeReduction.cpp: move assert closer to corresponding code block.
lib/CodeGen/ScheduleDAGInstrs.cpp
917–918

In that case, not checking MI as I did below should be enough to suppress the analyzer warning.
Would that be a good solution (since MI->isDebugValue() will induce a crash if MI is nullptr anyway) ?

lib/Target/ARM/Thumb2SizeReduction.cpp
976–977

Will move the assert inside the "if (MI->isInsideBundle())" case.

It seems the analyzer is warning because of:

  1. MachineInstr *BundleMI = nullptr;
  1. if (MI->isBundle()) {
  2. BundleMI = MI;
  3. continue;
  4. }

If the condition is false, then BundleMI is nullptr at this point.

apelete updated this revision to Diff 55751.May 1 2016, 9:35 AM

[scan-build] fix logic error warnings emitted on llvm code base

Changes since last revision:

  • fast forward rebase on git master branch.

Waiting for review, could someone please have a look at this one ?

apelete abandoned this revision.May 5 2016, 4:07 PM

This patch was split into D19083, D19410, D19966, D19968, D19973 and D19975 to ease review process.