From 55937c177f90ecf0dea40c318d2f8d52fa69b55d Mon Sep 17 00:00:00 2001 From: Bernhard Schommer Date: Fri, 20 Jan 2017 10:55:26 +0100 Subject: Implement offsetof via builtin. The implementation of offsetof as macro in the form ((size_t) &((ty*) NULL)->member) has the problem that it cannot be used everywhere were an integer constant expression is allowed, for example in initiliazers of global variables and there is also no check for the case that member is of bitifield type. The new implementation adds a builtin function for this which is replaced by an integer constant during elaboration. Bug 20765 --- cparser/pre_parser.mly | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'cparser/pre_parser.mly') diff --git a/cparser/pre_parser.mly b/cparser/pre_parser.mly index 613ec17f..1c917b23 100644 --- a/cparser/pre_parser.mly +++ b/cparser/pre_parser.mly @@ -57,7 +57,7 @@ AUTO REGISTER INLINE NORETURN CHAR SHORT INT LONG SIGNED UNSIGNED FLOAT DOUBLE UNDERSCORE_BOOL CONST VOLATILE VOID STRUCT UNION ENUM CASE DEFAULT IF ELSE SWITCH WHILE DO FOR GOTO CONTINUE BREAK RETURN BUILTIN_VA_ARG ALIGNOF - ATTRIBUTE ALIGNAS PACKED ASM + ATTRIBUTE ALIGNAS PACKED ASM BUILTIN_OFFSETOF %token EOF @@ -254,6 +254,7 @@ postfix_expression: | postfix_expression LBRACK expression RBRACK | postfix_expression LPAREN argument_expression_list? RPAREN | BUILTIN_VA_ARG LPAREN assignment_expression COMMA type_name RPAREN +| BUILTIN_OFFSETOF LPAREN type_name COMMA other_identifier RPAREN | postfix_expression DOT other_identifier | postfix_expression PTR other_identifier | postfix_expression INC -- cgit