-
Notifications
You must be signed in to change notification settings - Fork 14k
[compiler-rt][ubsan] Add support for f16 #129624
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[compiler-rt][ubsan] Add support for f16 #129624
Conversation
@llvm/pr-subscribers-compiler-rt-sanitizer Author: Alexander Shaposhnikov (alexander-shaposhnikov) ChangesLLVM supports long double <-> f16 conversions so we can remove the old FIXME. Full diff: https://github.com/llvm/llvm-project/pull/129624.diff 2 Files Affected:
diff --git a/compiler-rt/lib/ubsan/ubsan_value.cpp b/compiler-rt/lib/ubsan/ubsan_value.cpp
index 6e88ebaf34d4b..609253ae16622 100644
--- a/compiler-rt/lib/ubsan/ubsan_value.cpp
+++ b/compiler-rt/lib/ubsan/ubsan_value.cpp
@@ -120,15 +120,11 @@ FloatMax Value::getFloatValue() const {
CHECK(getType().isFloatTy());
if (isInlineFloat()) {
switch (getType().getFloatBitWidth()) {
-#if 0
- // FIXME: OpenCL / NEON 'half' type. LLVM can't lower the conversion
- // from '__fp16' to 'long double'.
case 16: {
__fp16 Value;
- internal_memcpy(&Value, &Val, 4);
+ internal_memcpy(&Value, &Val, sizeof(Value));
return Value;
}
-#endif
case 32: {
float Value;
#if defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
diff --git a/compiler-rt/test/ubsan/TestCases/Float/cast-overflow.cpp b/compiler-rt/test/ubsan/TestCases/Float/cast-overflow.cpp
index 859bc6a2fc9e7..05827f0f28e19 100644
--- a/compiler-rt/test/ubsan/TestCases/Float/cast-overflow.cpp
+++ b/compiler-rt/test/ubsan/TestCases/Float/cast-overflow.cpp
@@ -131,14 +131,19 @@ int main(int argc, char **argv) {
return 0;
}
case '5': {
- // CHECK-5: {{.*}}cast-overflow.cpp:[[@LINE+1]]:27: runtime error: {{.*}} is outside the range of representable values of type 'int'
+ // CHECK-5: {{.*}}cast-overflow.cpp:[[@LINE+1]]:28: runtime error: {{.*}} is outside the range of representable values of type 'int'
+ static int test_int = (__fp16)Inf;
+ return 0;
+ }
+ case '6': {
+ // CHECK-6: {{.*}}cast-overflow.cpp:[[@LINE+1]]:27: runtime error: {{.*}} is outside the range of representable values of type 'int'
static int test_int = NaN;
return 0;
}
// Integer -> floating point overflow.
- case '6': {
- // CHECK-6: cast-overflow.cpp:[[@LINE+2]]:{{27: runtime error: 3.40282e\+38 is outside the range of representable values of type 'int'| __int128 not supported}}
+ case '7': {
+ // CHECK-7: cast-overflow.cpp:[[@LINE+2]]:{{27: runtime error: 3.40282e\+38 is outside the range of representable values of type 'int'| __int128 not supported}}
#if defined(__SIZEOF_INT128__) && !defined(_WIN32)
static int test_int = (float)(FloatMaxAsUInt128 + 1);
return 0;
@@ -149,9 +154,9 @@ int main(int argc, char **argv) {
return 0;
#endif
}
- case '7': {
+ case '8': {
volatile long double ld = 300.0;
- // CHECK-7: {{.*}}cast-overflow.cpp:[[@LINE+1]]:14: runtime error: 300 is outside the range of representable values of type 'char'
+ // CHECK-8: {{.*}}cast-overflow.cpp:[[@LINE+1]]:14: runtime error: 300 is outside the range of representable values of type 'char'
char c = ld;
// `c` is allowed to contain UNDEF, thus we should not use
// its value as an exit code.
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
97eb971
to
13f6fec
Compare
also CI needs fixes |
regarding the CI - I'd have to reformat the whole file, otherwise things look a bit awkward |
Please reformat as NFC preparation patch |
9707cb7
to
90f35d4
Compare
90f35d4
to
2a45423
Compare
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/204/builds/2290 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/205/builds/2271 Here is the relevant piece of the build log for the reference
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/30/builds/16860 Here is the relevant piece of the build log for the reference
|
Hi, can this be fixed-forward or should we revert to investigate? |
I'll revert |
Thank you. If you need assistance reproducing the issue let me know. |
This reverts commit 23a30e6. The commit has broken some build bots.
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/153/builds/24583 Here is the relevant piece of the build log for the reference
|
@jplehr - yeah, if you could say a few words about how to reproduce this issue, this would be helpful. |
upd. I have a local repro now. |
LLVM supports long double <-> f16 conversions so we can remove the old FIXME.
This reverts commit 23a30e6. The commit has broken some build bots.
LLVM supports long double <-> f16 conversions so we can remove the old FIXME.