-
Notifications
You must be signed in to change notification settings - Fork 14.7k
Labels
Description
The below test case fails at optimization levels greater than -O1
#include <math.h>
#include <stdio.h>
__attribute__((noinline))
int test(double a, double b)
{
int maxIdx = 0;
double maxDot = 0.0;
for (int i = 0; i < 2; ++i) {
double dot = a * b;
if (fabs(dot) > fabs(maxDot)) {
maxIdx = i;
maxDot = dot;
}
}
return maxIdx;
}
int main(int argc, char *argv[])
{
int i = test(1.0, -1.0);
int failed = (i != 0);
printf("Returned %d, should be 0: %s\n", i, (failed ? "failed" : "success"));
return failed;
}
This is a regression introduced in #76360
The bug is due to https://github.com/llvm/llvm-project/pull/76360/files#diff-532fd830a7b080a7121645e6c8dccb2f94a7e25450c74aa496b8600f8f4481ccR6220
comparing a std::optional to false rather than dereferencing it (maybe we need a way to warn about this? it's a super easy error)
[Implicit conversion means the comparison I thought was wrong, was correct, and my PoC fix worked by functionally disabling signedness propagation entirely]