From: Justin Bogner Date: Tue, 23 Jun 2015 07:32:55 +0000 (+0000) Subject: MCExpr: Avoid UB by evaluating this shift as unsigned X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=1e4a7e02f84e3ff320ebb5fdaf04dff29a4e70f3;p=oota-llvm.git MCExpr: Avoid UB by evaluating this shift as unsigned We hit undefined behaviour in some MCExpr tests when the LHS of a left shift is -1. Twos-complement semantics are completely reasonable here, so we should just do the shift in unsigned. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@240385 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/MC/MCExpr.cpp b/lib/MC/MCExpr.cpp index b16245ac3f4..a30ceecc952 100644 --- a/lib/MC/MCExpr.cpp +++ b/lib/MC/MCExpr.cpp @@ -752,7 +752,7 @@ bool MCExpr::evaluateAsRelocatableImpl(MCValue &Res, const MCAssembler *Asm, case MCBinaryExpr::Mul: Result = LHS * RHS; break; case MCBinaryExpr::NE: Result = LHS != RHS; break; case MCBinaryExpr::Or: Result = LHS | RHS; break; - case MCBinaryExpr::Shl: Result = LHS << RHS; break; + case MCBinaryExpr::Shl: Result = uint64_t(LHS) << uint64_t(RHS); break; case MCBinaryExpr::Sub: Result = LHS - RHS; break; case MCBinaryExpr::Xor: Result = LHS ^ RHS; break; }