
`checkIncorrectLogicOperator` checks if an expression, for example `x != 0 || x != 1.0`, is always true or false by comparing the two literals `0` and `1.0`. But in case `x` is a 16-bit float, the two literals have distinct types---16-bit float and double, respectively. Directly comparing `APValue`s extracted from the two literals results in an assertion failure because of their distinct types. This commit fixes the issue by doing a conversion from the "smaller" one to the "bigger" one. The two literals must be compatible because both of them are comparing with `x`. rdar://152456316
17 lines
451 B
C++
17 lines
451 B
C++
// RUN: %clang_cc1 -verify -Wunreachable-code %s
|
|
|
|
// Previously this test will crash
|
|
static void test(__fp16& x) {
|
|
if (x != 0 || x != 1.0) { // expected-note{{}} no-crash
|
|
x = 0.9;
|
|
} else
|
|
x = 0.8; // expected-warning{{code will never be executed}}
|
|
}
|
|
|
|
static void test2(__fp16& x) {
|
|
if (x != 1 && x == 1.0) { // expected-note{{}} no-crash
|
|
x = 0.9; // expected-warning{{code will never be executed}}
|
|
} else
|
|
x = 0.8;
|
|
}
|