diff options
author | Xavier Leroy <xavier.leroy@inria.fr> | 2019-02-13 16:04:27 +0100 |
---|---|---|
committer | Xavier Leroy <xavierleroy@users.noreply.github.com> | 2019-02-25 17:15:36 +0100 |
commit | eec6d60b5fa43fa8cf011747d6b98322dcdaaae8 (patch) | |
tree | 145f86d69c19b54d017db7f060ae07ab2ee6fa1e /cparser/Cutil.ml | |
parent | aca94d735e74a0cfbdbebfbc1c81aa03c0a3bdb3 (diff) | |
download | compcert-eec6d60b5fa43fa8cf011747d6b98322dcdaaae8.tar.gz compcert-eec6d60b5fa43fa8cf011747d6b98322dcdaaae8.zip |
Reject object-related and struct-related attributes on typedefs
This commit adds a check to reject type definitions such as
```
typedef __attribute((section "foo")) int fooint;
```
GCC and Clang also reject this as an error.
Without the check, the behavior is somewhat surprising:
```
fooint x; // placed in section "foo"
fooint * x; // placed in default section, attribute "foo" is ignored
```
Note that the following must be accepted:
```
typedef struct { ... } __attribute((packed)) t;
```
The "packed" attribute is correctly attached to the struct type and should not be checked. This is achieved by using `attribute_of_type_no_expand` to get the attributes of the typedef-ed type, excluding the attributes carried by a struct/union or another typedef.
Diffstat (limited to 'cparser/Cutil.ml')
-rw-r--r-- | cparser/Cutil.ml | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/cparser/Cutil.ml b/cparser/Cutil.ml index 25329694..cf67015a 100644 --- a/cparser/Cutil.ml +++ b/cparser/Cutil.ml @@ -119,6 +119,15 @@ let class_of_attribute = function try Hashtbl.find attr_class (normalize_attrname name) with Not_found -> Attr_unknown +(* Name for printing an attribute *) + +let name_of_attribute = function + | AConst -> "const" + | AVolatile -> "volatile" + | ARestrict -> "restrict" + | AAlignas n -> "_Alignas" + | Attr(name, _) -> name + (* Is an attribute a ISO C standard attribute? *) let attr_is_standard = function |