-
Notifications
You must be signed in to change notification settings - Fork 14.5k
Open
Labels
clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerfloating-pointFloating-point mathFloating-point math
Description
Clang seems to believe these two additions produce the same result and will optimize away the later one. However this is incorrect due to the __builtin_set_flt_rounds
call, potentially changing the rounding mode.
Input:
void f(float a, float b, float *d, float *e) {
*d = a + b;
__builtin_set_flt_rounds(2);
*e = a + b;
}
ir:
define dso_local void @f(float, float, float*, float*)(float noundef %a, float noundef %b, ptr noundef writeonly captures(none) initializes((0, 4)) %d, ptr noundef writeonly captures(none) initializes((0, 4)) %e) local_unnamed_addr {
entry:
%add = fadd float %a, %b
store float %add, ptr %d, align 4
tail call void @llvm.set.rounding(i32 2)
store float %add, ptr %e, align 4
ret void
}
godbolt: https://godbolt.org/z/aaKnhvqMj
Metadata
Metadata
Assignees
Labels
clang:diagnosticsNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerNew/improved warning or error message in Clang, but not in clang-tidy or static analyzerfloating-pointFloating-point mathFloating-point math