Fix a tautological comparison bug caught during post-commit

This amends fd874e5fb1 to correctly set
the bit width of a '!' operator to be the same width as an 'int'. This
fixes a failed assertion about unexpected bit widths that was reported
during post-commit testing.
This commit is contained in:
Aaron Ballman 2022-09-28 14:21:30 -04:00
parent 8dd3ff62f5
commit 96a79cb308
2 changed files with 4 additions and 2 deletions

View File

@ -1002,7 +1002,7 @@ private:
if (BuildOpts.Observer)
BuildOpts.Observer->compareBitwiseEquality(B,
B->getOpcode() != BO_EQ);
TryResult(B->getOpcode() != BO_EQ);
return TryResult(B->getOpcode() != BO_EQ);
}
} else if (BoolExpr->isKnownToHaveBooleanValue()) {
if ((*IntLiteral1 == 1) || (*IntLiteral1 == 0)) {
@ -1041,7 +1041,7 @@ private:
case UO_Not:
return ~Value;
case UO_LNot:
return llvm::APInt(Value.getBitWidth(), !Value);
return llvm::APInt(Context->getTypeSize(Context->IntTy), !Value);
default:
assert(false && "Unexpected unary operator!");
return llvm::None;

View File

@ -91,6 +91,8 @@ void f(int x) {
if ((x | mydefine2) == 4) {}
if ((x & 1) == 1L) {}
if (0 != (x | !0LL)) {} // expected-warning {{bitwise comparison always evaluates to true}}
}
void g(int x) {