Adjust parameters with typedef'd array types to have pointer types.

Parameters declared directly with array types were already adjusted to pointer types in commit 5b953e2db0, but this code is needed for the remaining case where a typedef'd array type is used.

With these changes, 'array' parameters are treated for all purposes as really having pointer types, which is what the standards call for. This affects at least their size as reported by sizeof and the debugging information generated for them.
This commit is contained in:
Stephen Heumann 2021-11-07 18:25:45 -06:00
parent 906f9f6312
commit a6359f67e0
2 changed files with 13 additions and 0 deletions

View File

@ -1676,6 +1676,17 @@ while typeStack <> nil do begin {reverse the type stack}
firstIteration := false;
end; {while}
if doingParameters then {adjust array parameters to pointers}
if tPtr^.kind = arrayType then begin
tPtr2 := pointer(Calloc(sizeof(typeRecord)));
tPtr2^.size := cgPointerSize;
{tPtr2^.qualifiers := [];}
{tPtr2^.saveDisp := 0;}
tPtr2^.kind := pointerType;
tPtr2^.pType := tPtr^.aType;
tPtr := tPtr2;
end; {if}
if checkParms then begin {check for parameter type conflicts}
with variable^ do begin
if doingParameters then begin

View File

@ -1403,6 +1403,8 @@ int foo(int[42]);
170. Variable argument processing could not be restarted by calling va_start() after va_end(). Also, the addresses of local variables would change when va_end() was called, invalidating any pointers to them. The implementation of variable arguments has been changed to fix these problems. The only remaining non-standard restriction is that if #pragma optimize bit 6 or #pragma debug bit 4 is set, calls to functions taking variable arguments are not allowed to pass extra arguments beyond the number that the function will use.
171. Function parameters declared with array types are adjusted to actually have pointer types, but this adjustment was not applied in some situations. Now such parameters are consistently treated as actually having pointer types. This affects their size as given by sizeof and their type as shown in debuggers.
-- Bugs from C 2.1.0 that have been fixed -----------------------------------
1. In some situations, fread() reread the first 1K or so of the file.