Skip to content

Commit

Permalink
[hlc] prefetch should not access field but only addr (#12000)
Browse files Browse the repository at this point in the history
* [hlc] prefetch should not access field but only addr

* [tests] add  compilation test
  • Loading branch information
yuxiaomao authored Feb 12, 2025
1 parent d4bdcee commit bb4b689
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/generators/hl2c.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
28 changes: 28 additions & 0 deletions tests/unit/src/unit/issues/Issue12000.hx
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit bb4b689

Please sign in to comment.