Skip to content

Commit

Permalink
jvm: Fix compilation of routines that produce a void result
Browse files Browse the repository at this point in the history
This fixes the code for stubs for calls to features that do never return (Fuzion
result type `void`), these need a `return` bytecode anyway to keep the JVM
classfile verifier happy.

Additionally, a feature's result field may not exist if the code produces a void
value as in

  f i32 => panic "bah"

so we must not attempt to read the result field in the epilog.

This fixes the failure of tests/local_mutate when using the JVM backend.
  • Loading branch information
fridis committed Sep 27, 2023
1 parent 9786e05 commit d57ae1a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
7 changes: 3 additions & 4 deletions src/dev/flang/be/jvm/CodeGen.java
Original file line number Diff line number Diff line change
Expand Up @@ -538,10 +538,9 @@ private void addStub(int tt, int cc, String dn, String ds, boolean isCall)
na.add(t.load(1));
}
var p = staticAccess(-1, false, tt, cc, tv, na, isCall);
var code = p._v0 == null
? p._v1
: (p._v1.andThen(p._v0)
.andThen(retoern));
var code = p._v1
.andThen(p._v0 == null ? Expr.UNIT : p._v0)
.andThen(retoern);
var ca = cf.codeAttribute(dn + "in class for " + _fuir.clazzAsString(tt),
code, new List<>(), new List<>());
cf.method(ACC_PUBLIC, dn, ds, new List<>(ca));
Expand Down
8 changes: 3 additions & 5 deletions src/dev/flang/be/jvm/JVM.java
Original file line number Diff line number Diff line change
Expand Up @@ -954,11 +954,9 @@ else if (r == -1) // a constructor
var jt = _types.javaType(t);
var ft = _types.resultType(t);
var getf =
ft != PrimitiveType.type_void ? (Expr.aload(current_index(cl), jt)
.andThen(Expr.getfield(_names.javaClass(cl),
_names.field(r),
ft)))
: Expr.UNIT;
fieldExists(r) ? (Expr.aload(current_index(cl), jt)
.andThen(getfield(r)))
: Expr.UNIT;
return
traceReturn(cl, pre)
.andThen(getf)
Expand Down

0 comments on commit d57ae1a

Please sign in to comment.