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/Cabs.v | 1 + 1 file changed, 1 insertion(+) (limited to 'cparser/Cabs.v') diff --git a/cparser/Cabs.v b/cparser/Cabs.v index d087e8c7..355c748e 100644 --- a/cparser/Cabs.v +++ b/cparser/Cabs.v @@ -142,6 +142,7 @@ with expression := (* Non-standard *) | EXPR_ALIGNOF : expression -> expression | TYPE_ALIGNOF : (list spec_elem * decl_type) -> expression + | BUILTIN_OFFSETOF : (list spec_elem * decl_type) -> string -> expression with constant := (* The string is the textual representation of the constant in -- cgit From d60b593c8b1d19a4adfdadaeeaa93aa10b9dba53 Mon Sep 17 00:00:00 2001 From: Bernhard Schommer Date: Tue, 24 Jan 2017 10:29:30 +0100 Subject: New version to support designators. The c standard allows member designators for offsetof. The current implementation works by recursively combining the offset of each of the member designators. For array access the size of the subtypes is multiplied by the index and for members the offset of the member is calculated. Bug 20765 --- cparser/Cabs.v | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cparser/Cabs.v') diff --git a/cparser/Cabs.v b/cparser/Cabs.v index 355c748e..b3e4ffda 100644 --- a/cparser/Cabs.v +++ b/cparser/Cabs.v @@ -142,7 +142,7 @@ with expression := (* Non-standard *) | EXPR_ALIGNOF : expression -> expression | TYPE_ALIGNOF : (list spec_elem * decl_type) -> expression - | BUILTIN_OFFSETOF : (list spec_elem * decl_type) -> string -> expression + | BUILTIN_OFFSETOF : (list spec_elem * decl_type) -> list initwhat -> expression with constant := (* The string is the textual representation of the constant in -- cgit