From a4f0e85c729c335c4a586f2e4e3a90fd8188e56f Mon Sep 17 00:00:00 2001 From: Neil Brown Date: Wed, 28 Jan 2009 23:16:31 +0000 Subject: [PATCH] Fixed a bug involving abbreviation of arrays of channels into arrays of channel-ends in the C++ backend The array for the channel-ends was not being allocated storage, so the array (a pointer to some random location) was being written to and causing a seg-fault --- backends/GenerateCPPCSP.hs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/backends/GenerateCPPCSP.hs b/backends/GenerateCPPCSP.hs index 7fd1110..ca86c29 100644 --- a/backends/GenerateCPPCSP.hs +++ b/backends/GenerateCPPCSP.hs @@ -621,9 +621,15 @@ cppintroduceSpec (A.Specification _ n (A.Proc _ sm fs p)) --A helper function for calling the wrapped functions: genParamList :: [A.Formal] -> CGen() genParamList fs = infixComma $ map genParam fs -cppintroduceSpec (A.Specification _ n (A.Is _ am t@(A.Array _ (A.ChanEnd {})) (A.DirectedVariable +cppintroduceSpec (A.Specification _ n (A.Is _ am t@(A.Array ds c@(A.ChanEnd {})) dirV@(A.DirectedVariable m dir v))) - = do call genDecl am t n + = do t' <- if A.UnknownDimension `elem` ds + then do dirVT <- astTypeOf dirV + case dirVT of + A.Array ds' _ -> return $ A.Array ds' c + _ -> diePC m $ formatCode "Expected variable to be an array type, instead: %" dirVT + else return t + call genDeclaration t' n False tell [";"] tell ["tockInitChan",if dir == A.DirInput then "in" else "out","Array("] call genVariableAM v am