mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-08-15 06:29:05 +00:00
PVS-Studio noticed that EmitVBR64 would perform undefined behaviour if the
number of bits was bigger than 32. I checked every use of this function that I could find and it looks like the maximum number of bits is 32, so I've added an assertion checking this property, and a type cast to (hopefully) stop PVS-Studio from warning about this in the future. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@162277 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -155,6 +155,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void EmitVBR(uint32_t Val, unsigned NumBits) {
|
void EmitVBR(uint32_t Val, unsigned NumBits) {
|
||||||
|
assert(NumBits <= 32 && "Too many bits to emit!");
|
||||||
uint32_t Threshold = 1U << (NumBits-1);
|
uint32_t Threshold = 1U << (NumBits-1);
|
||||||
|
|
||||||
// Emit the bits with VBR encoding, NumBits-1 bits at a time.
|
// Emit the bits with VBR encoding, NumBits-1 bits at a time.
|
||||||
@@ -167,10 +168,11 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
void EmitVBR64(uint64_t Val, unsigned NumBits) {
|
void EmitVBR64(uint64_t Val, unsigned NumBits) {
|
||||||
|
assert(NumBits <= 32 && "Too many bits to emit!");
|
||||||
if ((uint32_t)Val == Val)
|
if ((uint32_t)Val == Val)
|
||||||
return EmitVBR((uint32_t)Val, NumBits);
|
return EmitVBR((uint32_t)Val, NumBits);
|
||||||
|
|
||||||
uint64_t Threshold = 1U << (NumBits-1);
|
uint64_t Threshold = uint64_t(1U << (NumBits-1));
|
||||||
|
|
||||||
// Emit the bits with VBR encoding, NumBits-1 bits at a time.
|
// Emit the bits with VBR encoding, NumBits-1 bits at a time.
|
||||||
while (Val >= Threshold) {
|
while (Val >= Threshold) {
|
||||||
|
Reference in New Issue
Block a user