From 7266b1d613a18822d9a8228b0490c45f82229c64 Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Sun, 25 Mar 2018 20:56:15 -0500 Subject: [PATCH] Properly support use of const structs and unions in assignments and as function arguments. Here's an example that shows the issues (derived from a csmith-generated test case): struct S { unsigned f; }; void f1(struct S p) { printf("%u\n", p.f); } int main(void) { const struct S l = {123}; struct S s; f1(l); s = l; printf("%u\n", s.f); } --- Expression.pas | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Expression.pas b/Expression.pas index 9030d95..75da9f0 100644 --- a/Expression.pas +++ b/Expression.pas @@ -2266,6 +2266,8 @@ var lexpressionType := expressionType; {save the expression type} GenerateCode(tree); {get the type} + while expressionType^.kind = definedType do + expressionType := expressionType^.dType; ExpressionKind := expressionType^.kind; doDispose := ldoDispose; {resore the volitile variables} @@ -2853,7 +2855,10 @@ case tree^.token.kind of FunctionCall(tree); ident: begin - case tree^.id^.itype^.kind of + tType := tree^.id^.itype; + while tType^.kind = definedType do + tType := tType^.dType; + case tType^.kind of scalarType: begin LoadScalar(tree^.id); @@ -2885,8 +2890,6 @@ case tree^.token.kind of expressionType := wordPtr; end; - otherwise: ; - end; {case} end;