Open genotrance opened 4 years ago
Can you try to reduce this down to make it easier to identify the problem?
The first line of the function itself fails. Reducing it even further:
align = ({ typeof((int)align) var__a = ((int)align);});
(translation_unit 2 1 57
(expression_statement 2 1 56
(assignment_expression 2 1 55
(identifier 2 1 5 "align")
(parenthesized_expression 2 9 47
(ERROR 2 10 20
(call_expression 2 12 18 "typeof((int)align)"
(identifier 2 12 6 "typeof")
(argument_list 2 18 12 "((int)align)"
(cast_expression 2 19 10 "(int)align"
(type_descriptor 2 20 3 "int"
(primitive_type 2 20 3 "int")
)
(identifier 2 24 5 "align")
)
)
)
)
(assignment_expression 2 31 21
(identifier 2 31 6 "var__a")
(parenthesized_expression 2 40 12 "((int)align)"
(cast_expression 2 41 10 "(int)align"
(type_descriptor 2 42 3 "int"
(primitive_type 2 42 3 "int")
)
(identifier 2 46 5 "align")
)
)
)
(ERROR 2 52 3)
)
)
)
)
That doesn’t look like standard C. What is that syntax called?
I found this in the sx library:
align = sx_max((int)align, SX_CONFIG_ALLOCATOR_NATURAL_ALIGNMENT);
// https://github.com/septag/sx/blob/master/include/sx/allocator.h#L136
gets expanded to the following after preprocessing (gcc -E):
align = ({ typeof((int)align) var__a = ((int)align); typeof(8) var__b = (8); (void)(&var__a == &var__b); var__a > 8 ? var__a : var__b; });
This is because they define sx_max() as follows:
#ifndef __cplusplus
# if SX_COMPILER_GCC || SX_COMPILER_CLANG
# define sx_max(a, b) \
({ \
typeof(a) var__a = (a); \
typeof(b) var__b = (b); \
(void)(&var__a == &var__b); \
var__a > b ? var__a : var__b; \
})
// https://github.com/septag/sx/blob/master/include/sx/sx.h#L78
Looks like a block syntax using {}, gcc doesn't mind.
This example uses a couple of GCC extensions: typeof
and statement expressions. Not sure what our policy is for supporting syntax extensions in the grammar — if we do, we should add these. typeof
should be handled similarly to sizeof
(i.e. it's an operator with an alphabetic name, not a standard function or macro being called).
Source:
Results in error:
First line of function itself fails by itself.