Fix code generation for qualified struct or union function parameters.

They were not being properly recognized as structs/unions, so they were being passed by address rather than by value as they should be.

Here is an example affected by this:

struct S {int a,b,c,d;};

int f(struct S s) {
    return s.a + s.b + s.c + s.d;
}

int main(void) {
    const struct S s = {1,2,3,4};
    return f(s);
}
This commit is contained in:
Stephen Heumann 2024-04-01 20:06:26 -05:00
parent 83537fd3c7
commit 50636bd28b
2 changed files with 13 additions and 5 deletions

View File

@ -3453,11 +3453,17 @@ var
while tp <> nil do begin while tp <> nil do begin
if tp^.middle <> nil then begin if tp^.middle <> nil then begin
GenerateCode(tp^.middle); GenerateCode(tp^.middle);
if expressionType^.kind in [structType,unionType] then begin if expressionType^.kind in [structType,unionType,definedType]
if expressionType^.size & $FFFF8000 <> 0 then then begin
Error(61); tType := expressionType;
Gen1t(pc_ldc, long(expressionType^.size).lsw, cgWord); while tType^.kind = definedType do
Gen0(pc_psh); tType := tType^.dType;
if tType^.kind in [structType,unionType] then begin
if tType^.size & $FFFF8000 <> 0 then
Error(61);
Gen1t(pc_ldc, long(tType^.size).lsw, cgWord);
Gen0(pc_psh);
end; {if}
end; {if} end; {if}
if fmt <> fmt_none then begin if fmt <> fmt_none then begin
new(tfp); new(tfp);

View File

@ -1620,6 +1620,8 @@ If you use #pragma debug 0x0010 to enable stack check debug code, the compiler w
15. Native code peephole optimization might produce invalid code in some obscure circumstances where one element of a global or static array was decremented and then another element of the same array was accessed immediately thereafter. 15. Native code peephole optimization might produce invalid code in some obscure circumstances where one element of a global or static array was decremented and then another element of the same array was accessed immediately thereafter.
16. When an expression of const- or volatile-qualified struct or union type was passed as a function parameter, incorrect code would be generated. This could lead to incorrect program behavior or crashes.
-- Bugs from C 2.1.1 B3 that have been fixed in C 2.2.0 --------------------- -- Bugs from C 2.1.1 B3 that have been fixed in C 2.2.0 ---------------------
1. There were various bugs that could cause incorrect code to be generated in certain cases. Some of these were specific to certain optimization passes, alone or in combination. 1. There were various bugs that could cause incorrect code to be generated in certain cases. Some of these were specific to certain optimization passes, alone or in combination.