浏览代码

[hlc] prefetch should not access field but only addr (#12000)

* [hlc] prefetch should not access field but only addr

* [tests] add  compilation test
Yuxiao Mao 7 月之前
父节点
当前提交
bb4b6893a4
共有 2 个文件被更改,包括 29 次插入1 次删除
  1. 1 1
      src/generators/hl2c.ml
  2. 28 0
      tests/unit/src/unit/issues/Issue12000.hx

+ 1 - 1
src/generators/hl2c.ml

@@ -1109,7 +1109,7 @@ let generate_function ctx f =
 			let expr = (if fid = 0 then reg r else (match rtype r with
 			| HObj o | HStruct o ->
 				let name, t = resolve_field o (fid - 1) in
-				Printf.sprintf "%s->%s" (reg r) name
+				Printf.sprintf "&%s->%s" (reg r) name
 			| _ ->
 				Globals.die "" __LOC__
 			)) in

+ 28 - 0
tests/unit/src/unit/issues/Issue12000.hx

@@ -0,0 +1,28 @@
+package unit.issues;
+
+private class Foo {
+	public var m : Map<Int, String>;
+	public var length : Int;
+	public function new() {
+	}
+}
+
+class Issue12000 extends unit.Test {
+	var obj = new Foo();
+
+	#if hl
+	public function test() {
+		untyped $prefetch(obj, 0);
+		untyped $prefetch(obj, 1);
+		untyped $prefetch(obj, 2);
+		untyped $prefetch(obj, 3);
+		untyped $prefetch(obj, 4);
+		untyped $prefetch(obj.length, 0);
+		untyped $prefetch(obj.length, 1);
+		untyped $prefetch(obj.length, 2);
+		untyped $prefetch(obj.length, 3);
+		untyped $prefetch(obj.length, 4);
+		noAssert();
+	}
+	#end
+}