Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CodeGen] use saturating FP casts when compiling with "no-strict-floa…
…t-cast-overflow" We got an unintended consequence of the optimizer getting smarter when compiling in a non-standard mode, and there's no good way to inhibit those optimizations at a later stage. The test is based on an example linked from D92270. We allow the "no-strict-float-cast-overflow" exception to normal C cast rules to preserve legacy code that does not expect overflowing casts from FP to int to produce UB. See D46236 for details. Differential Revision: https://reviews.llvm.org/D115804
- Loading branch information
1 parent
9a35844
commit 8c7f2a4
Showing
2 changed files
with
22 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,22 @@ | ||
// RUN: %clang_cc1 -S -fno-strict-float-cast-overflow %s -emit-llvm -o - | FileCheck %s --check-prefix=NOSTRICT | ||
|
||
// When compiling with non-standard semantics, use intrinsics to inhibit the optimizer. | ||
|
||
// NOSTRICT-LABEL: main | ||
// NOSTRICT: call i32 @llvm.fptosi.sat.i32.f64 | ||
// NOSTRICT: call i32 @llvm.fptoui.sat.i32.f64 | ||
// NOSTRICT: attributes #0 = {{.*}}"strict-float-cast-overflow"="false"{{.*}} | ||
|
||
// The workaround attribute is not applied by default. | ||
|
||
// RUN: %clang_cc1 -S %s -emit-llvm -o - | FileCheck %s --check-prefix=STRICT | ||
// STRICT-LABEL: main | ||
// STRICT: = fptosi | ||
// STRICT: = fptoui | ||
// STRICT-NOT: strict-float-cast-overflow | ||
|
||
|
||
int main() { | ||
return 0; | ||
double d = 1e20; | ||
return (int)d != 1e20 && (unsigned)d != 1e20; | ||
} | ||
|