Skip to content

CIF PLC code generator crashes on certain models with multiple initial locations if the simplify values option is disabled

See #683 (comment 1323809):

PLC code generator also crashes if the simplify values option is disabled.

[Exception]
org.eclipse.emf.common.util.BasicEList$BasicIndexOutOfBoundsException: index=0, size=0
	at org.eclipse.emf.common.util.BasicEList.get(BasicEList.java:346)
	at org.eclipse.escet.common.java.Lists.first(Lists.java:244)
	at org.eclipse.escet.cif.cif2plc.CifToPlcTrans.generateProgram(CifToPlcTrans.java:634)
	at org.eclipse.escet.cif.cif2plc.CifToPlcTrans.transformSpec(CifToPlcTrans.java:478)
	at org.eclipse.escet.cif.cif2plc.CifToPlcTrans.transform(CifToPlcTrans.java:419)
	at org.eclipse.escet.cif.cif2plc.CifToPlcApp.runInternal(CifToPlcApp.java:112)
	at org.eclipse.escet.common.app.framework.Application.runApplication(Application.java:315)
	at org.eclipse.escet.common.app.framework.Application.run(Application.java:180)
	at org.eclipse.escet.common.eclipse.ui.BaseFileCommandHandler.run(BaseFileCommandHandler.java:261)
	at org.eclipse.escet.common.eclipse.ui.BaseFileCommandHandler$1.run(BaseFileCommandHandler.java:102)
	at java.base/java.lang.Thread.run(Thread.java:833)

By default PLC code generator uses the SimplifyValues transformation (except if the option is disabled). That transformation simplifies the initialization expression, as follows:

plant automaton Automaton1:
  alg bool Condition1 = true;
  location Open:
    initial;
  location Closed;
end

The transformation is then trivial with linearize-merge.

The CodeGen application uses SimplifyValuesNoRefsOptimized, that does not simplify the initialization expression. Transformation is than less trivial. The resulting location pointer variable for Automaton1 has then no initial value after linearize merge, and crashes.