From: Matt H. <ma...@cs...> - 2005-12-08 01:45:31
|
> -----Original Message----- > From: cil...@li... > [mailto:cil...@li...] On Behalf Of > Roberto Bagnara > Sent: Wednesday, December 07, 2005 8:04 AM > To: cil...@li... > Subject: [CIL users] Problem with variable-length arrays > > Maybe variable-length arrays are not supported by CIL; I > assumed they were because the documentation says: "CIL > supports all GCC and MSVC extensions except for nested > functions and complex numbers." > All the best, > > Roberto Hi Roberto, Variable-length arrays were supported as local variables, but not as formals. Here's a patch. Cabs2cil replaces the array type with a pointer type. These are the right semantics, although as Dillon noted last week we lose a little information about the programmer's intention. -- Matt --- cil/src/frontc/cabs2cil.ml 4 Dec 2005 19:20:44 -0000 1.452 +++ cil/src/frontc/cabs2cil.ml 7 Dec 2005 23:56:32 -0000 1.453 @@ -2560,7 +2560,24 @@ (* Make the argument as for a formal *) let doOneArg (s, (n, ndt, a, cloc)) : varinfo = let s' = doSpecList n s in - makeVarInfoCabs ~isformal:true ~isglobal:false (convLoc cloc) s' (n,ndt,a) + let ndt' = match isVariableSizedArray ndt with + None -> ndt + | Some (ndt', se, len) -> + (* If this is a variable-sized array, we replace the array + type with a pointer type. This is the defined behavior + for array parameters, so we do not need to add this to + varSizeArrays, fix sizeofs, etc. *) + if isNotEmpty se then + E.s (error "array parameter: length not pure"); + ndt' + in + let vi = makeVarInfoCabs ~isformal:true ~isglobal:false + (convLoc cloc) s' (n,ndt',a) in + (* Add the formal to the environment, so it can be referenced by + other formals (e.g. in an array type, although that will be + changed to a pointer later, or though typeof). *) + addLocalToEnv vi.vname (EnvVar vi); + vi in let targs : varinfo list option = match List.map doOneArg args' with |