From b7ab7fc92653631ce5c879cec8c158c9c0f562c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Per=20=C3=96stlund?= Date: Thu, 25 Feb 2021 20:36:40 +0100 Subject: [PATCH] Check array length in collapseArrayExpressions - Check that the length of the array actually matches the number of elements in the array that the cref represents. --- OMCompiler/Compiler/BackEnd/BackendDAETransform.mo | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/OMCompiler/Compiler/BackEnd/BackendDAETransform.mo b/OMCompiler/Compiler/BackEnd/BackendDAETransform.mo index 441f776763d..418daa300bc 100644 --- a/OMCompiler/Compiler/BackEnd/BackendDAETransform.mo +++ b/OMCompiler/Compiler/BackEnd/BackendDAETransform.mo @@ -871,7 +871,7 @@ protected DAE.Type ty; list dims; list ds; - Integer len; + Integer len, exp_count; list exps; DAE.Exp exp1; Absyn.Ident call1, call2; @@ -911,8 +911,15 @@ algorithm for sub in subs loop DAE.INDEX(DAE.ICONST(1)) := sub; end for; + // Same number of expressions as expected... - true := (1+listLength(exps))==len; + exp_count := listLength(exps) + 1; + true := exp_count == len; + + // Check that the number of expressions matches the size of the array the cref represents. + dims := Types.getDimensions(ComponentReference.crefLastType(cr1)); + true := exp_count == product(i for i in Expression.dimensionsSizes(dims)); + for exp in exps loop //DAE.CREF(componentRef=cr2) := exp; (cr2, call2) := match exp