Opened 9 years ago

#3349 new defect

ParModelica: Unassigned parglobal output array from parkernel may SegFault

Reported by: Gustaf Thorslund Owned by: Mahder Alemseged Gebremedhin
Priority: high Milestone: Future
Component: ParModelica Version: trunk
Keywords: Cc:

Description

If a temporary array (maybe even bigger than available for parlocal) is needed inside a kernel function, it can only be provided using an output variable that's only used internally. If this array is not assigned to an array outside, it may give segmentation fault. Here's a test case:

setCommandLineOptions("-v=1 +g=ParModelica +d=noevalfunc");
loadString("
package ParTmp
  constant Integer arrayCnt = 2;
  parkernel function f
    parglobal input Real A[arrayCnt];
    parglobal output Real B[arrayCnt];
    parglobal output Real Tmp[arrayCnt];
  algorithm
    for
      i in oclGetGlobalId(1):oclGetGlobalSize(1):arrayCnt
    loop
      Tmp[i] := A[i]*7;
      B[i] := Tmp[i]+A[i];
    end for;
  end f;
  
  function test
    input Real d;
    output Real result[arrayCnt];
  protected
    parglobal Real pResult[arrayCnt];
    Real tmp[arrayCnt];
    parglobal Real pTmp[arrayCnt];
  algorithm
    for i loop
      tmp[i] := i;
    end for;
    pTmp := tmp;
    pResult := f(pTmp);
    result := pResult;
  end test;
end ParTmp;
");

x:=ParTmp.test(4);
Limited backtrace at point of segmentation fault
/usr/lib/libpthread.so.0(+0xf870)[0x7f56beb44870]
./ParTmp_test.so(omc_ParTmp_f+0xc2)[0x7f56b22d5862]
./ParTmp_test.so(omc_ParTmp_test+0x22d)[0x7f56b22d54fd]
./ParTmp_test.so(in_ParTmp_test+0x105)[0x7f56b22d5685]
/home/gusth/src/OpenModelica/build/bin/../lib/x86_64-linux-gnu/omc/libOpenModelicaCompiler.so(+0xdfd604)[0x7f56bcdce604]
/home/gusth/src/OpenModelica/build/bin/../lib/x86_64-linux-gnu/omc/libOpenModelicaCompiler.so(DynLoad_executeFunction+0x3d)[0x7f56bcdce7dd]
/home/gusth/src/OpenModelica/build/bin/../lib/x86_64-linux-gnu/omc/libOpenModelicaCompiler.so(omc_CevalScript_cevalCallFunctionEvaluateOrGenerate+0x4f2)[0x7f56bc84f3e2]
/home/gusth/src/OpenModelica/build/bin/../lib/x86_64-linux-gnu/omc/libOpenModelicaCompiler.so(omc_CevalScript_cevalCallFunction+0x47d)[0x7f56bc850c9d]
/home/gusth/src/OpenModelica/build/bin/../lib/x86_64-linux-gnu/omc/libOpenModelicaCompiler.so(omc_BackendInterface_cevalCallFunction+0x5f)[0x7f56bcd8962f]
/home/gusth/src/OpenModelica/build/bin/../lib/x86_64-linux-gnu/omc/libOpenModelicaCompiler.so(omc_Ceval_cevalWork2+0x4ed4)[0x7f56bcd78a04]
/home/gusth/src/OpenModelica/build/bin/../lib/x86_64-linux-gnu/omc/libOpenModelicaCompiler.so(omc_Ceval_cevalWork1+0xc6)[0x7f56bcd7a436]
/home/gusth/src/OpenModelica/build/bin/../lib/x86_64-linux-gnu/omc/libOpenModelicaCompiler.so(omc_Ceval_ceval+0x64)[0x7f56bcd60bd4]
/home/gusth/src/OpenModelica/build/bin/../lib/x86_64-linux-gnu/omc/libOpenModelicaCompiler.so(omc_Ceval_cevalIfConstant+0x271)[0x7f56bcd736f1]
/home/gusth/src/OpenModelica/build/bin/../lib/x86_64-linux-gnu/omc/libOpenModelicaCompiler.so(omc_Static_elabCallArgs3+0x6b3)[0x7f56bcb95b63]
/home/gusth/src/OpenModelica/build/bin/../lib/x86_64-linux-gnu/omc/libOpenModelicaCompiler.so(omc_Static_elabCallArgs2+0xc4d)[0x7f56bcb97fbd]
Segmentation fault (core dumped)

Tested using my ParModelicaFixes branch on github containing fixes from Mahder, so it may or may not be related to those fixes.

Change History (0)

Note: See TracTickets for help on using tickets.