[PATCH] D19900: [scan-build] fix dead store warnings emitted on LLVM Hexagon code base

Apelete Seketeli via llvm-commits llvm-commits at lists.llvm.org
Wed May 4 08:10:04 PDT 2016


apelete added inline comments.

================
Comment at: lib/Target/Hexagon/HexagonOptAddrMode.cpp:399
@@ -398,3 +398,3 @@
   bool Changed = false;
-  unsigned OpStart;
+  unsigned OpStart = 0;
   unsigned OpEnd = OldMI->getNumOperands();
----------------
kparzysz wrote:
> This is not strictly necessary since OpStart is only used when Changed it "true".  That happens iff OpStart is assigned a value.
Not strictly necessary, it just helps suppressing a logic error warning, I agree.
To be more precise, in the following code path:

406.   if (ImmOpNum == 0) {
407.     if (HII->getAddrMode(OldMI) == HexagonII::BaseRegOffset) {
...
415.       OpStart = 4;
416.     } else if (HII->getAddrMode(OldMI) == HexagonII::BaseImmOffset) {
...
424.        OpStart = 3;
425.     }
426.     Changed = true;
...
429.   } else if (ImmOpNum == 1 && OldMI->getOperand(2).getImm() == 0) {
...
440.   }

>From a static analysis point of view, if the branches at line 407 and 416 evaluate to 'false', then OpStart would be left un-initialized.
Then, when "Changed" is 'true':

441.   if (Changed)
442.     for (unsigned i = OpStart; i < OpEnd; ++i)
443.       MIB.addOperand(OldMI->getOperand(i));

'i' would be assigned the value of 'OpStart' which hasn't been initialized, thus the warning "assigned value is
garbage or undefined" from a static analysis point of view.

I understand that exact code path is unlikely to be taken at runtime.
Would you prefer we ignore the warning then (instead of trying to suppress it) ?


http://reviews.llvm.org/D19900





More information about the llvm-commits mailing list