forked from OSchip/llvm-project
Fix APFloat assertion failure in IdempotentOperationChecker resulting in having
an APFloat with different "float semantics" than the compared float literal. llvm-svn: 108590
This commit is contained in:
parent
83f250f005
commit
8b9fd890e3
|
|
@ -515,10 +515,12 @@ bool IdempotentOperationChecker::containsOneConstant(const Stmt *S) {
|
|||
if (IL && IL->getValue() == 1)
|
||||
return true;
|
||||
|
||||
const FloatingLiteral *FL = dyn_cast<FloatingLiteral>(S);
|
||||
const llvm::APFloat one(1.0);
|
||||
if (FL && FL->getValue().compare(one) == llvm::APFloat::cmpEqual)
|
||||
return true;
|
||||
if (const FloatingLiteral *FL = dyn_cast<FloatingLiteral>(S)) {
|
||||
const llvm::APFloat &val = FL->getValue();
|
||||
const llvm::APFloat one(val.getSemantics(), 1);
|
||||
if (val.compare(one) == llvm::APFloat::cmpEqual)
|
||||
return true;
|
||||
}
|
||||
|
||||
for (Stmt::const_child_iterator I = S->child_begin(); I != S->child_end();
|
||||
++I)
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
// Basic tests
|
||||
|
||||
extern void test(int i);
|
||||
extern void test_f(float f);
|
||||
|
||||
void basic() {
|
||||
int x = 10, zero = 0, one = 1;
|
||||
|
|
@ -50,3 +51,8 @@ void basic() {
|
|||
test(zero << x); // expected-warning {{idempotent operation; the left operand is always 0}}
|
||||
test(zero >> x); // expected-warning {{idempotent operation; the left operand is always 0}}
|
||||
}
|
||||
|
||||
void floats(float x) {
|
||||
test_f(x * 1.0); // no-warning
|
||||
test_f(x * 1.0F); // no-warning
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue