diff options
author | Richard Biener <rguenther@suse.de> | 2020-12-11 09:50:59 +0100 |
---|---|---|
committer | Richard Biener <rguenther@suse.de> | 2021-01-06 09:33:41 +0100 |
commit | c9ee9c1e3553247c776f33eb0fe0aadee094a192 (patch) | |
tree | 767a296e7aa92d2b27b3e0184c87fb5074a0d0e5 /gcc | |
parent | a05cc70a6c1ae0e5b22e16f4d8d13995a38ea1f9 (diff) | |
download | gcc-c9ee9c1e3553247c776f33eb0fe0aadee094a192.zip gcc-c9ee9c1e3553247c776f33eb0fe0aadee094a192.tar.gz gcc-c9ee9c1e3553247c776f33eb0fe0aadee094a192.tar.bz2 |
add signed_bool_precision attribute for GIMPLE FE use
This adds __attribute__((signed_bool_precision(precision))) to be able
to construct nonstandard boolean types which for the included testcase
is needed to simulate Ada and LTO interaction (Ada uses a 8 bit
precision boolean_type_node). This will also be useful for vector
unit testcases where we need to produce vector types with
non-standard precision signed boolean type components.
2021-01-06 Richard Biener <rguenther@suse.de>
PR tree-optimization/95582
gcc/c-family/
* c-attribs.c (c_common_attribute_table): Add entry for
signed_bool_precision.
(handle_signed_bool_precision_attribute): New.
gcc/testsuite/
* gcc.dg/pr95582.c: New testcase.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/c-family/c-attribs.c | 41 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/pr95582.c | 19 |
2 files changed, 60 insertions, 0 deletions
diff --git a/gcc/c-family/c-attribs.c b/gcc/c-family/c-attribs.c index ef7cec9..84ec86b 100644 --- a/gcc/c-family/c-attribs.c +++ b/gcc/c-family/c-attribs.c @@ -161,6 +161,8 @@ static tree handle_copy_attribute (tree *, tree, tree, int, bool *); static tree handle_nsobject_attribute (tree *, tree, tree, int, bool *); static tree handle_objc_root_class_attribute (tree *, tree, tree, int, bool *); static tree handle_objc_nullability_attribute (tree *, tree, tree, int, bool *); +static tree handle_signed_bool_precision_attribute (tree *, tree, tree, int, + bool *); /* Helper to define attribute exclusions. */ #define ATTR_EXCL(name, function, type, variable) \ @@ -274,6 +276,8 @@ const struct attribute_spec c_common_attribute_table[] = { /* { name, min_len, max_len, decl_req, type_req, fn_type_req, affects_type_identity, handler, exclude } */ + { "signed_bool_precision", 1, 1, false, true, false, true, + handle_signed_bool_precision_attribute, NULL }, { "packed", 0, 0, false, false, false, false, handle_packed_attribute, attr_aligned_exclusions }, @@ -894,6 +898,43 @@ validate_attr_arg (tree node[2], tree name, tree newarg) /* Attribute handlers common to C front ends. */ +/* Handle a "signed_bool_precision" attribute; arguments as in + struct attribute_spec.handler. */ + +static tree +handle_signed_bool_precision_attribute (tree *node, tree name, tree args, + int, bool *no_add_attrs) +{ + *no_add_attrs = true; + if (!flag_gimple) + { + warning (OPT_Wattributes, "%qE attribute ignored", name); + return NULL_TREE; + } + + if (!TYPE_P (*node) || TREE_CODE (*node) != BOOLEAN_TYPE) + { + warning (OPT_Wattributes, "%qE attribute only supported on " + "boolean types", name); + return NULL_TREE; + } + + unsigned HOST_WIDE_INT prec = HOST_WIDE_INT_M1U; + if (tree_fits_uhwi_p (TREE_VALUE (args))) + prec = tree_to_uhwi (TREE_VALUE (args)); + if (prec > MAX_FIXED_MODE_SIZE) + { + warning (OPT_Wattributes, "%qE attribute with unsupported boolean " + "precision", name); + return NULL_TREE; + } + + tree new_type = build_nonstandard_boolean_type (prec); + *node = lang_hooks.types.reconstruct_complex_type (*node, new_type); + + return NULL_TREE; +} + /* Handle a "packed" attribute; arguments as in struct attribute_spec.handler. */ diff --git a/gcc/testsuite/gcc.dg/pr95582.c b/gcc/testsuite/gcc.dg/pr95582.c new file mode 100644 index 0000000..cc2ab46 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr95582.c @@ -0,0 +1,19 @@ +/* { dg-do compile } */ +/* { dg-options "-fgimple -O3" } */ + +typedef _Bool bool8 __attribute__((signed_bool_precision(8))); + +bool8 data[16]; + +void __GIMPLE(ssa) foo(int f) +{ + _Bool t; + bool8 tp; + +__BB(2): + t_2 = f_1(D) != 0; + tp_3 = (bool8) t_2; + data[0] = tp_3; + data[1] = tp_3; + return; +} |