arocc icon indicating copy to clipboard operation
arocc copied to clipboard

More fuzzer-discovered crash fixes

Open ehaas opened this issue 1 year ago • 2 comments

ehaas avatar May 10 '24 19:05 ehaas

Parser: add TODO for complex fp16/_Float16 types

Can you give an example of the crash this prevents?

Vexu avatar May 19 '24 18:05 Vexu

_Complex float x = 1.0f16 + 2i;

ehaas avatar May 19 '24 20:05 ehaas

Should I add this as a test with a TESTS_SKIPPED?

ehaas avatar May 20 '24 01:05 ehaas

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)) {

Vexu avatar May 20 '24 05:05 Vexu

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.

ehaas avatar May 22 '24 23:05 ehaas