Skip to content

Commit 97eb971

Browse files
[compiler-rt][ubsan] Add support for f16
1 parent c1aebd4 commit 97eb971

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

compiler-rt/lib/ubsan/ubsan_value.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -120,15 +120,11 @@ FloatMax Value::getFloatValue() const {
120120
CHECK(getType().isFloatTy());
121121
if (isInlineFloat()) {
122122
switch (getType().getFloatBitWidth()) {
123-
#if 0
124-
// FIXME: OpenCL / NEON 'half' type. LLVM can't lower the conversion
125-
// from '__fp16' to 'long double'.
126123
case 16: {
127124
__fp16 Value;
128-
internal_memcpy(&Value, &Val, 4);
125+
internal_memcpy(&Value, &Val, sizeof(Value));
129126
return Value;
130127
}
131-
#endif
132128
case 32: {
133129
float Value;
134130
#if defined(__BYTE_ORDER__) && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,19 @@ int main(int argc, char **argv) {
131131
return 0;
132132
}
133133
case '5': {
134-
// CHECK-5: {{.*}}cast-overflow.cpp:[[@LINE+1]]:27: runtime error: {{.*}} is outside the range of representable values of type 'int'
134+
// CHECK-5: {{.*}}cast-overflow.cpp:[[@LINE+1]]:28: runtime error: {{.*}} is outside the range of representable values of type 'int'
135+
static int test_int = (__fp16)Inf;
136+
return 0;
137+
}
138+
case '6': {
139+
// CHECK-6: {{.*}}cast-overflow.cpp:[[@LINE+1]]:27: runtime error: {{.*}} is outside the range of representable values of type 'int'
135140
static int test_int = NaN;
136141
return 0;
137142
}
138143

139144
// Integer -> floating point overflow.
140-
case '6': {
141-
// 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}}
145+
case '7': {
146+
// 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}}
142147
#if defined(__SIZEOF_INT128__) && !defined(_WIN32)
143148
static int test_int = (float)(FloatMaxAsUInt128 + 1);
144149
return 0;
@@ -149,9 +154,9 @@ int main(int argc, char **argv) {
149154
return 0;
150155
#endif
151156
}
152-
case '7': {
157+
case '8': {
153158
volatile long double ld = 300.0;
154-
// CHECK-7: {{.*}}cast-overflow.cpp:[[@LINE+1]]:14: runtime error: 300 is outside the range of representable values of type 'char'
159+
// CHECK-8: {{.*}}cast-overflow.cpp:[[@LINE+1]]:14: runtime error: 300 is outside the range of representable values of type 'char'
155160
char c = ld;
156161
// `c` is allowed to contain UNDEF, thus we should not use
157162
// its value as an exit code.

0 commit comments

Comments
 (0)