Properly generate const-qualified structs and unions.

Global structs and unions with the const qualifier were not being generated in object files. This occurred because they were represented as having "defined types" and the code was not handling those types properly.

The following example demonstrated this problem:

const struct x { int i; } X = {9};
int main(void) {
    return X.i;
}
This commit is contained in:
Stephen Heumann 2017-06-21 21:15:56 -05:00
parent f79887c565
commit 10ca3bcc73

View File

@ -447,14 +447,18 @@ procedure DoGlobals;
lval: longint; {for converting types}
size: longint; {size of the array}
sp: identPtr; {pointer to a symbol table entry}
tPtr: typePtr; {type of global array/struct/union}
begin {GenArrays}
didOne := false;
for i := 0 to hashSize do begin
sp := table^.buckets[i];
while sp <> nil do begin
if sp^.storage in [global,private] then
if sp^.itype^.kind in [arrayType,structType,unionType] then begin
if sp^.storage in [global,private] then begin
tPtr := sp^.itype;
while tPtr^.kind = definedType do
tPtr := tPtr^.dType;
if tPtr^.kind in [arrayType,structType,unionType] then begin
if not didOne then begin
if smallMemoryModel then
currentSegment := ' '
@ -507,6 +511,7 @@ procedure DoGlobals;
end; {while}
end; {else}
end; {if}
end; {if}
sp := sp^.next;
end; {while}
end; {for}