mirror of
https://github.com/byteworksinc/ORCA-C.git
synced 2024-12-22 23:29:27 +00:00
Fix issues where static initialization may generate the wrong number of bytes.
This relates to unions or structs that are "filled" with zeros because the initializer does not include explicit terms for them, and that contain bit-fields or (for unions) do not start with the longest member. The following program is an example that was miscompiled: #include <stdio.h> struct BF { int i:3; int j:4; }; union U { int i; long l; }; struct Outer1 { int n; struct BF bf[7]; union U u[5]; }; struct Outer2 { long p; struct Outer1 o1; long q; }; int main(void) { static struct Outer2 s = {1,{0},212}; printf("%li %li\n", s.p, s.q); }
This commit is contained in:
parent
4d10fbae01
commit
fedd275395
28
Parser.pas
28
Parser.pas
@ -2211,20 +2211,28 @@ var
|
|||||||
else if tp^.kind = structType then begin
|
else if tp^.kind = structType then begin
|
||||||
|
|
||||||
{fill a structure}
|
{fill a structure}
|
||||||
i := count;
|
if variable^.storage in [external,global,private] then
|
||||||
while i <> 0 do begin
|
Fill(count * tp^.size, bytePtr)
|
||||||
ip := tp^.fieldList;
|
else begin
|
||||||
while ip <> nil do begin
|
i := count;
|
||||||
Fill(1, ip^.iType);
|
while i <> 0 do begin
|
||||||
ip := ip^.next;
|
ip := tp^.fieldList;
|
||||||
|
while ip <> nil do begin
|
||||||
|
Fill(1, ip^.iType);
|
||||||
|
ip := ip^.next;
|
||||||
|
end; {while}
|
||||||
|
i := i-1;
|
||||||
end; {while}
|
end; {while}
|
||||||
i := i-1;
|
end; {else}
|
||||||
end; {while}
|
|
||||||
end {else if}
|
end {else if}
|
||||||
else if tp^.kind = unionType then
|
else if tp^.kind = unionType then begin
|
||||||
|
|
||||||
{fill a union}
|
{fill a union}
|
||||||
Fill(count, tp^.fieldList^.iType)
|
if variable^.storage in [external,global,private] then
|
||||||
|
Fill(count * tp^.size, bytePtr)
|
||||||
|
else
|
||||||
|
Fill(count, tp^.fieldList^.iType);
|
||||||
|
end {else if}
|
||||||
else
|
else
|
||||||
|
|
||||||
{fill a single value}
|
{fill a single value}
|
||||||
|
Loading…
Reference in New Issue
Block a user