From 2e698d61cc3181dd454ca3d2782ea642b228fe83 Mon Sep 17 00:00:00 2001 From: Yuxiao Mao Date: Wed, 5 Mar 2025 12:37:04 +0100 Subject: [PATCH 1/3] [tests] add some Single test and [hl] fix null(f32) cannot cast to f64 --- src/generators/genhl.ml | 2 +- tests/unit/src/unit/issues/Issue10965.hx | 2 +- tests/unit/src/unit/issues/Issue12039.hx | 35 ++++++++++++++++++++++++ 3 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 tests/unit/src/unit/issues/Issue12039.hx diff --git a/src/generators/genhl.ml b/src/generators/genhl.ml index bf972e71a71..a2b5bc9d9c4 100644 --- a/src/generators/genhl.ml +++ b/src/generators/genhl.ml @@ -1242,7 +1242,7 @@ and cast_to ?(force=false) ctx (r:reg) (t:ttype) p = let r = alloc_tmp ctx (HNull t) in op ctx (OToDyn (r,tmp)); r - | HNull ((HUI8 | HUI16 | HI32 | HI64) as it), (HF32 | HF64) -> + | HNull ((HUI8 | HUI16 | HI32 | HI64 | HF32 | HF64) as it), (HF32 | HF64) -> let i = alloc_tmp ctx it in op ctx (OSafeCast (i,r)); let tmp = alloc_tmp ctx t in diff --git a/tests/unit/src/unit/issues/Issue10965.hx b/tests/unit/src/unit/issues/Issue10965.hx index 0ab14b2acea..a9af8f03cda 100644 --- a/tests/unit/src/unit/issues/Issue10965.hx +++ b/tests/unit/src/unit/issues/Issue10965.hx @@ -1,7 +1,7 @@ package unit.issues; class Issue10965 extends Test { - #if jvm + #if (jvm || hl || cpp) function testNeg() { var a:Single = 1; var c = -a; diff --git a/tests/unit/src/unit/issues/Issue12039.hx b/tests/unit/src/unit/issues/Issue12039.hx new file mode 100644 index 00000000000..8a087f006fd --- /dev/null +++ b/tests/unit/src/unit/issues/Issue12039.hx @@ -0,0 +1,35 @@ +package unit.issues; + +class Issue12039 extends Test { + #if (java || hl || cpp) + @:analyzer(ignore) + function testCastNullFloat() { + var fnull : Null = null; + var snull : Null = null; + var f0 : Float = snull; + feq(f0, 0); + var s0 : Single = fnull; + feq(s0, 0); + } + + @:analyzer(ignore) + function testSingle() { + var s1 : Single = 10.0; + var s2 : Single = 0.3; + var f1 : Float = 10.0; + var f2 : Float = 0.3; + var a : Single = s1 + s2; + feq(10.3, a); + var a : Single = s1 - s2; + feq(9.7, a); + var a : Single = s1 / s2; + feq(33.3333333333, a); + var a : Single = s1 / (f2 : Single); + feq(33.3333333333, a); + var a : Single = (f1 : Single) / s2; + feq(33.3333333333, a); + var a : Single = (f1 : Single) / (f2 : Single); + feq(33.3333333333, a); + } + #end +} From b86e3929a9c8fb71eee8d39ab442632010fd6bee Mon Sep 17 00:00:00 2001 From: Yuxiao Mao Date: Wed, 5 Mar 2025 15:36:36 +0100 Subject: [PATCH 2/3] [tests] add test for 11647 --- tests/unit/src/unit/issues/Issue11647.hx | 15 +++++++++++++++ tests/unit/src/unit/issues/Issue12039.hx | 2 ++ 2 files changed, 17 insertions(+) create mode 100644 tests/unit/src/unit/issues/Issue11647.hx diff --git a/tests/unit/src/unit/issues/Issue11647.hx b/tests/unit/src/unit/issues/Issue11647.hx new file mode 100644 index 00000000000..44636483a57 --- /dev/null +++ b/tests/unit/src/unit/issues/Issue11647.hx @@ -0,0 +1,15 @@ +package unit.issues; + +class Issue11647 extends Test { + #if (java || hl || cpp) + function test() { + foo(); + } + + function foo(a : Single = 10.0, b:Single = 11.0, c:Single = 12.0) : Void { + feq(10, a); + feq(11, b); + feq(12, c); + } + #end +} diff --git a/tests/unit/src/unit/issues/Issue12039.hx b/tests/unit/src/unit/issues/Issue12039.hx index 8a087f006fd..1da13e2b1c9 100644 --- a/tests/unit/src/unit/issues/Issue12039.hx +++ b/tests/unit/src/unit/issues/Issue12039.hx @@ -15,7 +15,9 @@ class Issue12039 extends Test { @:analyzer(ignore) function testSingle() { var s1 : Single = 10.0; + feq(10.0, s1); var s2 : Single = 0.3; + feq(0.3, s2); var f1 : Float = 10.0; var f2 : Float = 0.3; var a : Single = s1 + s2; From 0181806e98e12b2927789f932a2cb00d49aef588 Mon Sep 17 00:00:00 2001 From: Yuxiao Mao Date: Wed, 5 Mar 2025 15:58:54 +0100 Subject: [PATCH 3/3] [hl] enable F32 literal and add some tests --- src/generators/genhl.ml | 8 ++------ .../unit/issues/{Issue12039.hx => Issue12041.hx} | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 8 deletions(-) rename tests/unit/src/unit/issues/{Issue12039.hx => Issue12041.hx} (76%) diff --git a/src/generators/genhl.ml b/src/generators/genhl.ml index a2b5bc9d9c4..728e17c1517 100644 --- a/src/generators/genhl.ml +++ b/src/generators/genhl.ml @@ -1086,18 +1086,14 @@ let rec eval_to ctx e (t:ttype) = let r = alloc_tmp ctx t in op ctx (OFloat (r,alloc_float ctx (Int32.to_float i))); r - (* this causes a bug with NG, to be reviewed later | TConst (TInt i), HF32 -> let r = alloc_tmp ctx t in - let bits = Int32.bits_of_float (Int32.to_float i) in - op ctx (OFloat (r,alloc_float ctx (Int64.float_of_bits (Int64.of_int32 bits)))); + op ctx (OFloat (r, alloc_float ctx (Int32.to_float i))); r | TConst (TFloat f), HF32 -> let r = alloc_tmp ctx t in - let bits = Int32.bits_of_float (float_of_string f) in - op ctx (OFloat (r,alloc_float ctx (Int64.float_of_bits (Int64.of_int32 bits)))); + op ctx (OFloat (r, alloc_float ctx (float_of_string f))); r - *) | _ -> let r = eval_expr ctx e in cast_to ctx r t e.epos diff --git a/tests/unit/src/unit/issues/Issue12039.hx b/tests/unit/src/unit/issues/Issue12041.hx similarity index 76% rename from tests/unit/src/unit/issues/Issue12039.hx rename to tests/unit/src/unit/issues/Issue12041.hx index 1da13e2b1c9..2c2ed2fe9dc 100644 --- a/tests/unit/src/unit/issues/Issue12039.hx +++ b/tests/unit/src/unit/issues/Issue12041.hx @@ -1,6 +1,6 @@ package unit.issues; -class Issue12039 extends Test { +class Issue12041 extends Test { #if (java || hl || cpp) @:analyzer(ignore) function testCastNullFloat() { @@ -13,7 +13,7 @@ class Issue12039 extends Test { } @:analyzer(ignore) - function testSingle() { + function testSingleOp() { var s1 : Single = 10.0; feq(10.0, s1); var s2 : Single = 0.3; @@ -24,6 +24,8 @@ class Issue12039 extends Test { feq(10.3, a); var a : Single = s1 - s2; feq(9.7, a); + var a : Single = s1 * s2; + feq(3.0, a); var a : Single = s1 / s2; feq(33.3333333333, a); var a : Single = s1 / (f2 : Single); @@ -33,5 +35,13 @@ class Issue12039 extends Test { var a : Single = (f1 : Single) / (f2 : Single); feq(33.3333333333, a); } + + @:analyzer(ignore) + function testSingleFromInt() { + var s1 : Single = 10; + feq(10.0, s1); + var s2 : Single = 3; + feq(3.0, s2); + } #end }