diff options
author | Michael Ilseman <milseman@apple.com> | 2014-12-12 21:48:03 +0000 |
---|---|---|
committer | Michael Ilseman <milseman@apple.com> | 2014-12-12 21:48:03 +0000 |
commit | 5be22a12c2fdb4e13ead4b2e8a8a68f07fb1f270 (patch) | |
tree | d32cd1ee5853b7b127f7bc8acbb58e753c5feccd /llvm/lib/MC | |
parent | 90482a77b114ba612951233d90f0173d7b7d04a6 (diff) | |
download | bcm5719-llvm-5be22a12c2fdb4e13ead4b2e8a8a68f07fb1f270.tar.gz bcm5719-llvm-5be22a12c2fdb4e13ead4b2e8a8a68f07fb1f270.zip |
Clean up static analyzer warnings.
Clang's static analyzer found several potential cases of undefined
behavior, use of un-initialized values, and potentially null pointer
dereferences in tablegen, Support, MC, and ADT. This cleans them up
with specific assertions on the assumptions of the code.
llvm-svn: 224154
Diffstat (limited to 'llvm/lib/MC')
-rw-r--r-- | llvm/lib/MC/MCAsmStreamer.cpp | 5 | ||||
-rw-r--r-- | llvm/lib/MC/MCObjectStreamer.cpp | 4 | ||||
-rw-r--r-- | llvm/lib/MC/MCParser/COFFAsmParser.cpp | 8 |
3 files changed, 11 insertions, 6 deletions
diff --git a/llvm/lib/MC/MCAsmStreamer.cpp b/llvm/lib/MC/MCAsmStreamer.cpp index 84eb0937765..a4f82a742dd 100644 --- a/llvm/lib/MC/MCAsmStreamer.cpp +++ b/llvm/lib/MC/MCAsmStreamer.cpp @@ -682,7 +682,10 @@ void MCAsmStreamer::EmitValueImpl(const MCExpr *Value, unsigned Size, // We truncate our partial emission to fit within the bounds of the // emission domain. This produces nicer output and silences potential // truncation warnings when round tripping through another assembler. - ValueToEmit &= ~0ULL >> (64 - EmissionSize * 8); + uint64_t Shift = 64 - EmissionSize * 8; + assert(Shift < std::numeric_limits<unsigned long long>::digits && + "undefined behavior"); + ValueToEmit &= ~0ULL >> Shift; EmitIntValue(ValueToEmit, EmissionSize); Emitted += EmissionSize; } diff --git a/llvm/lib/MC/MCObjectStreamer.cpp b/llvm/lib/MC/MCObjectStreamer.cpp index 21e68678e75..08fe5017bd5 100644 --- a/llvm/lib/MC/MCObjectStreamer.cpp +++ b/llvm/lib/MC/MCObjectStreamer.cpp @@ -405,7 +405,9 @@ void MCObjectStreamer::EmitFill(uint64_t NumBytes, uint8_t FillValue) { } void MCObjectStreamer::EmitZeros(uint64_t NumBytes) { - unsigned ItemSize = getCurrentSection().first->isVirtualSection() ? 0 : 1; + const MCSection *Sec = getCurrentSection().first; + assert(Sec && "need a section"); + unsigned ItemSize = Sec->isVirtualSection() ? 0 : 1; insert(new MCFillFragment(0, ItemSize, NumBytes)); } diff --git a/llvm/lib/MC/MCParser/COFFAsmParser.cpp b/llvm/lib/MC/MCParser/COFFAsmParser.cpp index 6f82e6ef3e4..18bdb03336a 100644 --- a/llvm/lib/MC/MCParser/COFFAsmParser.cpp +++ b/llvm/lib/MC/MCParser/COFFAsmParser.cpp @@ -582,7 +582,7 @@ bool COFFAsmParser::ParseSEHDirectiveHandlerData(StringRef, SMLoc) { } bool COFFAsmParser::ParseSEHDirectivePushReg(StringRef, SMLoc L) { - unsigned Reg; + unsigned Reg = 0; if (ParseSEHRegisterNumber(Reg)) return true; @@ -595,7 +595,7 @@ bool COFFAsmParser::ParseSEHDirectivePushReg(StringRef, SMLoc L) { } bool COFFAsmParser::ParseSEHDirectiveSetFrame(StringRef, SMLoc L) { - unsigned Reg; + unsigned Reg = 0; int64_t Off; if (ParseSEHRegisterNumber(Reg)) return true; @@ -636,7 +636,7 @@ bool COFFAsmParser::ParseSEHDirectiveAllocStack(StringRef, SMLoc) { } bool COFFAsmParser::ParseSEHDirectiveSaveReg(StringRef, SMLoc L) { - unsigned Reg; + unsigned Reg = 0; int64_t Off; if (ParseSEHRegisterNumber(Reg)) return true; @@ -663,7 +663,7 @@ bool COFFAsmParser::ParseSEHDirectiveSaveReg(StringRef, SMLoc L) { // FIXME: This method is inherently x86-specific. It should really be in the // x86 backend. bool COFFAsmParser::ParseSEHDirectiveSaveXMM(StringRef, SMLoc L) { - unsigned Reg; + unsigned Reg = 0; int64_t Off; if (ParseSEHRegisterNumber(Reg)) return true; |