From de57170ef8434a68a7bf1101557526e77c0be5c8 Mon Sep 17 00:00:00 2001 From: Stephen Heumann Date: Mon, 7 Nov 2022 19:00:35 -0600 Subject: [PATCH] Try to form composite types for extern declarations within blocks. If the extern declaration refers to a global variable/function for which a declaration is already visible, the inner declaration should have the composite type (and it is an error if the types are incompatible). This affects programs like the following: static char a[60] = {5}; int main(void) { extern char a[]; return sizeof(a)+a[0]; /* should return 65 */ } --- Symbol.pas | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Symbol.pas b/Symbol.pas index 996096c..5f9d70a 100644 --- a/Symbol.pas +++ b/Symbol.pas @@ -2019,7 +2019,6 @@ var begin {NewSymbol} needSymbol := true; {assume we need a symbol} -cs := nil; {no current symbol found} isGlobal := false; {set up defaults} isFunction := false; lUseGlobalPool := useGlobalPool; @@ -2056,7 +2055,18 @@ if space <> fieldListSpace then begin {are we defining a function?} p := cs; needSymbol := false; end; {else} - end; {if} + end {if} + else if class = externsy then {check for outer decl of same object/fn} + if table <> globalTable then begin + cs := FindSymbol(tk, space, false, true); + if cs <> nil then + if cs^.name^[1] <> '~' then {exclude block-scope statics} + if cs^.storage in [global,external,private] then begin + if not CompTypes(cs^.itype, itype) then + Error(47); + itype := MakeCompositeType(cs^.itype, itype); + end; {if} + end; {if} end; {if} if class = staticsy then {statics go in the global symbol table} if not isFunction then