diff --git a/src/dev/flang/be/interpreter/Interpreter.java b/src/dev/flang/be/interpreter/Interpreter.java index 3a4ded5b1c..76a2424df5 100644 --- a/src/dev/flang/be/interpreter/Interpreter.java +++ b/src/dev/flang/be/interpreter/Interpreter.java @@ -158,7 +158,7 @@ static void setField(int thiz, int staticClazz, Value curValue, Value v) ); int fclazz = clazzForField(thiz); - LValue slot = fieldSlot(thiz, staticClazz, fclazz, curValue); + LValue slot = fieldSlot(thiz, staticClazz, fclazz, curValue); setFieldSlot(thiz, fclazz, slot, v); } @@ -435,7 +435,6 @@ private static void setChoiceField(int thiz, */ private static LValue fieldSlot(int thiz, int staticClazz, int fclazz, Value curValue) { - int off; var clazz = staticClazz; if (fuir().clazzIsRef(staticClazz)) { @@ -448,7 +447,7 @@ private static LValue fieldSlot(int thiz, int staticClazz, int fclazz, Value cur clazz = ((Boxed)curValue)._valueClazz; curValue = ((Boxed)curValue)._contents; } - off = Layout.get(clazz).offset(thiz); + int off = Layout.get(clazz).offset(thiz); // NYI: check if this is a can be enabled or removed: // diff --git a/src/dev/flang/fuir/analysis/AbstractInterpreter.java b/src/dev/flang/fuir/analysis/AbstractInterpreter.java index a3d3195ec7..2c7e6732d4 100644 --- a/src/dev/flang/fuir/analysis/AbstractInterpreter.java +++ b/src/dev/flang/fuir/analysis/AbstractInterpreter.java @@ -29,6 +29,7 @@ import java.util.Stack; import dev.flang.fuir.FUIR; +import dev.flang.ir.IR.ExprKind; import static dev.flang.ir.IR.NO_SITE; @@ -521,27 +522,20 @@ public Pair processCode(int s0) l.add(_processor.reportErrorInCode("Severe compiler bug! This code should be unreachable.")); } - if (!containsVoid(stack) && stack.size() > 0) - { // NYI: #1875: Manual stack cleanup. This should not be needed since the - // FUIR has the (so far undocumented) invariant that the stack must be - // empty at the end of a basic block. There were some cases - // (tests/reg_issue1294) where this is not the case that need to be - // fixed, the FUIR code should contain a POP instructions to avoid this - // special handling here! - // - var e = _fuir.codeAt(last_s); - switch (e) + // FUIR has the (so far undocumented) invariant that the stack must be + // empty at the end of a basic block. + if (CHECKS) check + (containsVoid(stack) || stack.isEmpty() || _fuir.alwaysResultsInVoid(last_s)); + + if (!containsVoid(stack) && !stack.isEmpty() && _fuir.alwaysResultsInVoid(last_s)) + { + if (CHECKS) check + (_fuir.codeAt(last_s) == ExprKind.Call); + var cc0 = _fuir.accessedClazz(last_s); + var rt = _fuir.clazzResultClazz(cc0); + if (!clazzHasUnitValue(rt)) { - case Call: - var cc0 = _fuir.accessedClazz(last_s); - var rt = _fuir.clazzResultClazz(cc0); - if (!clazzHasUnitValue(rt)) - { - l.add(_processor.drop(stack.pop(), rt)); - } - break; - default: - break; // NYI: ignore this case for now, this occurs infrequently, one example is tests/reg_issue1294. + l.add(_processor.drop(stack.pop(), rt)); } } diff --git a/tests/reg_issue1294/issue1294.fz b/tests/reg_issue1294/issue1294.fz index 7fb4449884..0ded49ce1f 100644 --- a/tests/reg_issue1294/issue1294.fz +++ b/tests/reg_issue1294/issue1294.fz @@ -44,7 +44,7 @@ scenario1 => fs(F type : a F) => _ := F.zero -scenario1 +# NYI: BUG: #3649 scenario1 diff --git a/tests/reg_issue2345/Makefile b/tests/reg_issue2345/Makefile new file mode 100644 index 0000000000..8c2e132e22 --- /dev/null +++ b/tests/reg_issue2345/Makefile @@ -0,0 +1,25 @@ +# This file is part of the Fuzion language implementation. +# +# The Fuzion language implementation is free software: you can redistribute it +# and/or modify it under the terms of the GNU General Public License as published +# by the Free Software Foundation, version 3 of the License. +# +# The Fuzion language implementation is distributed in the hope that it will be +# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +# License for more details. +# +# You should have received a copy of the GNU General Public License along with The +# Fuzion language implementation. If not, see . + + +# ----------------------------------------------------------------------- +# +# Tokiwa Software GmbH, Germany +# +# Source code of Fuzion test Makefile +# +# ----------------------------------------------------------------------- + +override NAME = reg_issue2345.fz +include ../compile.mk diff --git a/tests/reg_issue2345/reg_issue2345.fz b/tests/reg_issue2345/reg_issue2345.fz new file mode 100644 index 0000000000..d4ffcfe061 --- /dev/null +++ b/tests/reg_issue2345/reg_issue2345.fz @@ -0,0 +1,25 @@ +# This file is part of the Fuzion language implementation. +# +# The Fuzion language implementation is free software: you can redistribute it +# and/or modify it under the terms of the GNU General Public License as published +# by the Free Software Foundation, version 3 of the License. +# +# The Fuzion language implementation is distributed in the hope that it will be +# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +# License for more details. +# +# You should have received a copy of the GNU General Public License along with The +# Fuzion language implementation. If not, see . + + +# ----------------------------------------------------------------------- +# +# Tokiwa Software GmbH, Germany +# +# Source code of Fuzion test reg_issue2345 +# +# ----------------------------------------------------------------------- + +_ := n +n => if true then n else panic "n" diff --git a/tests/reg_issue2345_1/Makefile b/tests/reg_issue2345_1/Makefile new file mode 100644 index 0000000000..b46b53bbcd --- /dev/null +++ b/tests/reg_issue2345_1/Makefile @@ -0,0 +1,25 @@ +# This file is part of the Fuzion language implementation. +# +# The Fuzion language implementation is free software: you can redistribute it +# and/or modify it under the terms of the GNU General Public License as published +# by the Free Software Foundation, version 3 of the License. +# +# The Fuzion language implementation is distributed in the hope that it will be +# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +# License for more details. +# +# You should have received a copy of the GNU General Public License along with The +# Fuzion language implementation. If not, see . + + +# ----------------------------------------------------------------------- +# +# Tokiwa Software GmbH, Germany +# +# Source code of Fuzion test Makefile +# +# ----------------------------------------------------------------------- + +override NAME = reg_issue2345_1 +include ../compile.mk diff --git a/tests/reg_issue2345_1/reg_issue2345_1.fz b/tests/reg_issue2345_1/reg_issue2345_1.fz new file mode 100644 index 0000000000..6234bc5aad --- /dev/null +++ b/tests/reg_issue2345_1/reg_issue2345_1.fz @@ -0,0 +1,26 @@ +# This file is part of the Fuzion language implementation. +# +# The Fuzion language implementation is free software: you can redistribute it +# and/or modify it under the terms of the GNU General Public License as published +# by the Free Software Foundation, version 3 of the License. +# +# The Fuzion language implementation is distributed in the hope that it will be +# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +# License for more details. +# +# You should have received a copy of the GNU General Public License along with The +# Fuzion language implementation. If not, see . + + +# ----------------------------------------------------------------------- +# +# Tokiwa Software GmbH, Germany +# +# Source code of Fuzion test reg_issue2345_1 +# +# ----------------------------------------------------------------------- + +reg_issue2345_1 is + n2 => if true then n2 else panic "n" + n2 diff --git a/tests/reg_issue3521/Makefile b/tests/reg_issue3521/Makefile new file mode 100644 index 0000000000..eac7c2662d --- /dev/null +++ b/tests/reg_issue3521/Makefile @@ -0,0 +1,25 @@ +# This file is part of the Fuzion language implementation. +# +# The Fuzion language implementation is free software: you can redistribute it +# and/or modify it under the terms of the GNU General Public License as published +# by the Free Software Foundation, version 3 of the License. +# +# The Fuzion language implementation is distributed in the hope that it will be +# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +# License for more details. +# +# You should have received a copy of the GNU General Public License along with The +# Fuzion language implementation. If not, see . + + +# ----------------------------------------------------------------------- +# +# Tokiwa Software GmbH, Germany +# +# Source code of Fuzion test Makefile +# +# ----------------------------------------------------------------------- + +override NAME = reg_issue3521 +include ../simple.mk diff --git a/tests/reg_issue3521/reg_issue3521.fz b/tests/reg_issue3521/reg_issue3521.fz new file mode 100644 index 0000000000..9d32a5cd12 --- /dev/null +++ b/tests/reg_issue3521/reg_issue3521.fz @@ -0,0 +1,25 @@ +# This file is part of the Fuzion language implementation. +# +# The Fuzion language implementation is free software: you can redistribute it +# and/or modify it under the terms of the GNU General Public License as published +# by the Free Software Foundation, version 3 of the License. +# +# The Fuzion language implementation is distributed in the hope that it will be +# useful, but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +# License for more details. +# +# You should have received a copy of the GNU General Public License along with The +# Fuzion language implementation. If not, see . + + +# ----------------------------------------------------------------------- +# +# Tokiwa Software GmbH, Germany +# +# Source code of Fuzion test reg_issue3521 +# +# ----------------------------------------------------------------------- + +a => if false then _ := "$unit" + diff --git a/tests/reg_issue3521/reg_issue3521.fz.expected_err b/tests/reg_issue3521/reg_issue3521.fz.expected_err new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tests/reg_issue3521/reg_issue3521.fz.expected_out b/tests/reg_issue3521/reg_issue3521.fz.expected_out new file mode 100644 index 0000000000..e69de29bb2