Page MenuHomePhabricator

[scan-build] fix warning emitted on LLVM Bitcode code base
Needs ReviewPublic

Authored by apelete on May 5 2016, 7:42 AM.

Details

Summary

Fix a logic error warning of the type "assigned value is garbage or
undefined" emitted by Clang Static Analyzer on the following file:

  • lib/Bitcode/Writer/BitcodeWriter.cpp.

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

Diff Detail

Event Timeline

apelete updated this revision to Diff 56287.May 5 2016, 7:42 AM
apelete retitled this revision from to [scan-build] fix warning emitted on LLVM Bitcode code base Fix a logic error warning of the type "called C++ object pointer is null" emitted by Clang Static Analyzer on the following file: - lib/Bitcode/Writer/BitcodeWriter.cpp..
apelete updated this object.
apelete added reviewers: joe.abbey, tejohnson.
apelete added a subscriber: llvm-commits.
apelete retitled this revision from [scan-build] fix warning emitted on LLVM Bitcode code base Fix a logic error warning of the type "called C++ object pointer is null" emitted by Clang Static Analyzer on the following file: - lib/Bitcode/Writer/BitcodeWriter.cpp. to [scan-build] fix warning emitted on LLVM Bitcode code base.May 5 2016, 7:45 AM
apelete updated this object.
tejohnson edited edge metadata.May 5 2016, 8:13 AM

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

What does this error mean? It seems like a case where we would get a maybe uninitialized warning, if -Wmaybe-uninitialized was enabled (but its my understanding that there is a conscious decision not to enable this warning for llvm). In this case, we have assertion checks (noted below) that ensure we never use these without initializing them.

If we need to fix this case to silence an analyzer, I'd rather initialize those abbrevs to 0 and add an assert down near the uses that they are non-zero (as noted below the default added in this patch doesn't make sense for this bitcode record type).

lib/Bitcode/Writer/BitcodeWriter.cpp
2512

These are not correct abbrev ids for this code.

2576

The above 2 asserts will ensure that we never reach here without initializing FnEntry*BitAbbrev.

apelete added inline comments.May 5 2016, 3:16 PM
lib/Bitcode/Writer/BitcodeWriter.cpp
2512

These were needed to suppress a warning in case branch at line 2513 evaluates to 'false'.
From the analyzer point of view, assigned value at line 2585 would then be garbage or undefined (commit message was mistaken in the wording of the warning, will fix).

I was not sure about which abbrev ids to assign variables FnEntry8BitAbbrev, FnEntry7BitAbbrev and FnEntry6BitAbbrev.
Will fix by assigning 0 and assert their value before use if that's OK for you.

apelete updated this object.May 5 2016, 3:17 PM
apelete edited edge metadata.
apelete updated this revision to Diff 56361.May 5 2016, 3:48 PM

[scan-build] fix warning emitted on LLVM Bitcode code base

Changes since last revision:

  • initialize FnEntry8BitAbbrev, FnEntry7BitAbbrev and FnEntry6BitAbbrev variables to 0 and assert they are non-zero prior being read.