arocc
arocc copied to clipboard
More fuzzer-discovered crash fixes
Parser: add TODO for complex fp16/_Float16 types
Can you give an example of the crash this prevents?
_Complex float x = 1.0f16 + 2i;
Should I add this as a test with a TESTS_SKIPPED?
The TODO could be avoided by reversing #454 for _Float16 since Clang does seem to support it and casting __fp16 to float:
diff --git a/src/aro/Parser.zig b/src/aro/Parser.zig
index 5bb1784..77eea6c 100644
--- a/src/aro/Parser.zig
+++ b/src/aro/Parser.zig
@@ -5758,8 +5758,8 @@ pub const Result = struct {
// No `_Complex _Float16`
.{ .invalid, .float16 },
};
- const a_spec = a.ty.canonicalize(.standard).specifier;
- const b_spec = b.ty.canonicalize(.standard).specifier;
+ var a_spec = a.ty.canonicalize(.standard).specifier;
+ var b_spec = b.ty.canonicalize(.standard).specifier;
if (p.comp.target.c_type_bit_size(.longdouble) == 128) {
if (try a.floatConversion(b, a_spec, b_spec, p, float_types[0])) return;
}
@@ -5771,9 +5771,18 @@ pub const Result = struct {
if (p.comp.target.c_type_bit_size(.longdouble) == 64) {
if (try a.floatConversion(b, a_spec, b_spec, p, float_types[0])) return;
}
+ if (a_spec == .fp16 and b.ty.isComplex()) {
+ try a.floatCast(p, .{ .specifier = .float });
+ a_spec = .float;
+ }
+ if (b_spec == .fp16 and a.ty.isComplex()) {
+ try b.floatCast(p, .{ .specifier = .float });
+ b_spec = .float;
+ }
if (try a.floatConversion(b, a_spec, b_spec, p, float_types[3])) return;
if (try a.floatConversion(b, a_spec, b_spec, p, float_types[4])) return;
if (try a.floatConversion(b, a_spec, b_spec, p, float_types[5])) return;
+ unreachable;
}
if (a.ty.eql(b.ty, p.comp, true)) {
I must have tested on an ancient version of clang - looks like _Complex _Float16 support was added in clang 15, so I just went ahead and added that.