[llvm] r271773 - [MC] Check the upper bound in truncate assertion

Petr Hosek via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 3 21:02:18 PDT 2016


Author: phosek
Date: Fri Jun  3 23:02:18 2016
New Revision: 271773

URL: http://llvm.org/viewvc/llvm-project?rev=271773&view=rev
Log:
[MC] Check the upper bound in truncate assertion

The truncateToSize function already has assertion to check the
lower boundary for the number bytes, but it does not check the
upper boundary which could still lead to usage errors.

Differential Revision: http://reviews.llvm.org/D20755

Modified:
    llvm/trunk/lib/MC/MCAsmStreamer.cpp

Modified: llvm/trunk/lib/MC/MCAsmStreamer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/MC/MCAsmStreamer.cpp?rev=271773&r1=271772&r2=271773&view=diff
==============================================================================
--- llvm/trunk/lib/MC/MCAsmStreamer.cpp (original)
+++ llvm/trunk/lib/MC/MCAsmStreamer.cpp Fri Jun  3 23:02:18 2016
@@ -314,7 +314,7 @@ void MCAsmStreamer::EmitCommentsAndEOL()
 }
 
 static inline int64_t truncateToSize(int64_t Value, unsigned Bytes) {
-  assert(Bytes && "Invalid size!");
+  assert(Bytes > 0 && Bytes <= 8 && "Invalid size!");
   return Value & ((uint64_t) (int64_t) -1 >> (64 - Bytes * 8));
 }
 




More information about the llvm-commits mailing list