Allow the operand of sizeof to be an un-parenthesized compound literal.

This is allowed based on the C standard syntax, but it previously gave a spurious error in ORCA/C, because the parenthesized type name at the beginning of the compound literal was parsed as the complete operand to sizeof.

Here is an example program affected by this:

int main(void) {
        return sizeof (char[]){1,2,3}; // should return 3
}
This commit is contained in:
Stephen Heumann 2024-08-11 20:33:36 -05:00
parent 5f59f152ed
commit 347ad00ff7
2 changed files with 5 additions and 2 deletions

View File

@ -2287,7 +2287,9 @@ if token.kind in startExpression then begin
else if opStack^.token.kind = _Alignofsy then
doingAlignof := true;
tType := TypeName;
if doingSizeof or doingAlignof then begin
Match(rparench,12);
if (doingSizeof and (token.kind <> lbracech)) or doingAlignof then
begin
{handle a sizeof operator}
op := opStack;
@ -2324,7 +2326,6 @@ if token.kind in startExpression then begin
op^.next := opStack;
opStack := op;
end; {else}
Match(rparench,12);
end {if}
else begin
new(op); {record the '('}

View File

@ -1630,6 +1630,8 @@ If you use #pragma debug 0x0010 to enable stack check debug code, the compiler w
20. When using strict type checks, == or != comparisons between a function pointer and NULL or (void*)0 would cause a spurious error.
21. If the operand to sizeof was a compound literal that was not enclosed in parentheses, a spurious error would be reported.
-- 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.