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/Support | |
| 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/Support')
| -rw-r--r-- | llvm/lib/Support/ScaledNumber.cpp | 3 | ||||
| -rw-r--r-- | llvm/lib/Support/raw_ostream.cpp | 1 |
2 files changed, 2 insertions, 2 deletions
diff --git a/llvm/lib/Support/ScaledNumber.cpp b/llvm/lib/Support/ScaledNumber.cpp index 725f4649613..3cd75091caf 100644 --- a/llvm/lib/Support/ScaledNumber.cpp +++ b/llvm/lib/Support/ScaledNumber.cpp @@ -169,8 +169,7 @@ static std::string toStringAPFloat(uint64_t D, int E, unsigned Precision) { int Shift = 63 - (NewE - E); assert(Shift <= LeadingZeros); assert(Shift == LeadingZeros || NewE == ScaledNumbers::MaxScale); - assert((Shift & (1u << std::numeric_limits<int>::digits)) == 0 && - "undefined behavior"); + assert(Shift >= 0 && Shift < 64 && "undefined behavior"); D <<= Shift; E = NewE; diff --git a/llvm/lib/Support/raw_ostream.cpp b/llvm/lib/Support/raw_ostream.cpp index bbbbe4ae8c6..1bcc31b40a4 100644 --- a/llvm/lib/Support/raw_ostream.cpp +++ b/llvm/lib/Support/raw_ostream.cpp @@ -312,6 +312,7 @@ raw_ostream &raw_ostream::write(const char *Ptr, size_t Size) { // than the buffer. Directly write the chunk that is a multiple of the // preferred buffer size and put the remainder in the buffer. if (LLVM_UNLIKELY(OutBufCur == OutBufStart)) { + assert(NumBytes != 0 && "undefined behavior"); size_t BytesToWrite = Size - (Size % NumBytes); write_impl(Ptr, BytesToWrite); size_t BytesRemaining = Size - BytesToWrite; |

