Skip to content

Commit 39402cd

Browse files
[compiler-rt][ubsan] Refactor cast-overflow test (#129460)
This PR cleans up cast-overflow.cpp, more specifically: 1. avoid using undefined value as an exit code (old case `9`) 2. narrowing conversions are allowed to produce `inf` and they are well-defined. Remove dead code (old case `8`) 3. the same applies to the conversion int -> float16. Remove dead code (old case `7`) See also https://clang.llvm.org/docs/UndefinedBehaviorSanitizer.html#:~:text=%2Dfsanitize%3Dfloat%2Dcast,to%20integer%20types. Currently ubsan doesn't properly detect UB on float16 -> int casts, I have a fix for that (will send as a separate PR).
1 parent 4ca8ea8 commit 39402cd

File tree

1 file changed

+7
-16
lines changed

1 file changed

+7
-16
lines changed

compiler-rt/test/ubsan/TestCases/Float/cast-overflow.cpp

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77
// RUN: %run %t 4 2>&1 | FileCheck %s --check-prefix=CHECK-4
88
// RUN: %run %t 5 2>&1 | FileCheck %s --check-prefix=CHECK-5
99
// RUN: %run %t 6 2>&1 | FileCheck %s --check-prefix=CHECK-6
10-
// FIXME: %run %t 7 2>&1 | FileCheck %s --check-prefix=CHECK-7
11-
// FIXME: not %run %t 8 2>&1 | FileCheck %s --check-prefix=CHECK-8
12-
// RUN: not %run %t 9 2>&1 | FileCheck %s --check-prefix=CHECK-9
10+
// RUN: %run %t 7 2>&1 | FileCheck %s --check-prefix=CHECK-7
1311

1412
// Issue #41838
1513
// XFAIL: sparc-target-arch && target={{.*solaris.*}}
@@ -151,20 +149,13 @@ int main(int argc, char **argv) {
151149
return 0;
152150
#endif
153151
}
154-
// FIXME: The backend cannot lower __fp16 operations on x86 yet.
155-
//case '7':
156-
// (__fp16)65504; // ok
157-
// // CHECK-7: runtime error: 65505 is outside the range of representable values of type '__fp16'
158-
// return (__fp16)65505;
159-
160-
// Floating point -> floating point overflow.
161-
case '8':
162-
// CHECK-8: {{.*}}cast-overflow.cpp:[[@LINE+1]]:19: runtime error: 1e+39 is outside the range of representable values of type 'float'
163-
return (float)1e39;
164-
case '9':
152+
case '7': {
165153
volatile long double ld = 300.0;
166-
// CHECK-9: {{.*}}cast-overflow.cpp:[[@LINE+1]]:14: runtime error: 300 is outside the range of representable values of type 'char'
154+
// CHECK-7: {{.*}}cast-overflow.cpp:[[@LINE+1]]:14: runtime error: 300 is outside the range of representable values of type 'char'
167155
char c = ld;
168-
return c;
156+
// `c` is allowed to contain UNDEF, thus we should not use
157+
// its value as an exit code.
158+
return 0;
159+
}
169160
}
170161
}

0 commit comments

Comments
 (0)