From a6359f67e000c4df1237a9eeac6988ef9e1699d4 Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Sun, 7 Nov 2021 18:25:45 -0600 Subject: [PATCH] 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 5b953e2db091, 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. --- Parser.pas | 11 +++++++++++ cc.notes | 2 ++ 2 files changed, 13 insertions(+) diff --git a/Parser.pas b/Parser.pas index 2f366ba..0021691 100644 --- a/Parser.pas +++ b/Parser.pas @@ -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 diff --git a/cc.notes b/cc.notes index 97680b8..505527d 100644 --- a/cc.notes +++ b/cc.notes @@ -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.