aboutsummaryrefslogtreecommitdiffstats
path: root/cparser/Parser.vy
diff options
context:
space:
mode:
authorBernhard Schommer <bernhardschommer@gmail.com>2017-01-20 10:55:26 +0100
committerBernhard Schommer <bernhardschommer@gmail.com>2017-01-20 10:55:26 +0100
commit55937c177f90ecf0dea40c318d2f8d52fa69b55d (patch)
tree493a207959cd64f6b3419dc109d246df35b01e54 /cparser/Parser.vy
parentefaf1cf1c47370ab23db190fc4c2c1f3ad05323e (diff)
downloadcompcert-kvx-55937c177f90ecf0dea40c318d2f8d52fa69b55d.tar.gz
compcert-kvx-55937c177f90ecf0dea40c318d2f8d52fa69b55d.zip
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
Diffstat (limited to 'cparser/Parser.vy')
-rw-r--r--cparser/Parser.vy4
1 files changed, 3 insertions, 1 deletions
diff --git a/cparser/Parser.vy b/cparser/Parser.vy
index 3e175a37..fb0b7444 100644
--- a/cparser/Parser.vy
+++ b/cparser/Parser.vy
@@ -37,7 +37,7 @@ Require Import List.
STRUCT UNION ENUM UNDERSCORE_BOOL PACKED ALIGNAS ATTRIBUTE ASM
%token<cabsloc> CASE DEFAULT IF ELSE SWITCH WHILE DO FOR GOTO CONTINUE BREAK
- RETURN BUILTIN_VA_ARG
+ RETURN BUILTIN_VA_ARG BUILTIN_OFFSETOF
%token EOF
@@ -145,6 +145,8 @@ postfix_expression:
{ (CAST typ (COMPOUND_INIT (rev' init)), loc) }
| loc = LPAREN typ = type_name RPAREN LBRACE init = initializer_list COMMA RBRACE
{ (CAST typ (COMPOUND_INIT (rev' init)), loc) }
+| loc = BUILTIN_OFFSETOF LPAREN typ = type_name COMMA mem = OTHER_NAME RPAREN
+ { (BUILTIN_OFFSETOF typ (fst mem), loc) }
(* Semantic value is in reverse order. *)
argument_expression_list: