aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJan Hubicka <jh@suse.cz>2020-05-26 10:14:38 +0200
committerJan Hubicka <jh@suse.cz>2020-05-26 10:14:38 +0200
commit5c8344e7289969e1ee3103beaf9631b284f5ebc3 (patch)
treec5a1697ecc49aaa82862cb9cd1dca734de44804d /gcc
parentf1f862aec2c3b93dbd6adfc35b0e1b6034e59c21 (diff)
downloadgcc-5c8344e7289969e1ee3103beaf9631b284f5ebc3.zip
gcc-5c8344e7289969e1ee3103beaf9631b284f5ebc3.tar.gz
gcc-5c8344e7289969e1ee3103beaf9631b284f5ebc3.tar.bz2
Simplify types of TYPE_VALUES in enumeral types
streaming code assumes that INTEGER_CST never appears in non-trivial component. This is not true and we sometimes stream such components which sort of silently works but breaks our IL invariant about tree sharing. This patch fixes one instance of this problem where ENUMERAL_TYPE lists all its valids in TYPE_VALUES that with some FEs (like Ada and C++) are having the enumeral type as a type while in other FEs (like C) are simple integer types. I convert them all to integers which also increases chance that they will be shared with other integer constants at stream time. gcc/ * tree.c (free_lang_data_in_type): Simpify types of TYPE_VALUES in enumeral types.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/tree.c24
1 files changed, 22 insertions, 2 deletions
diff --git a/gcc/tree.c b/gcc/tree.c
index 54e471a..ea66924 100644
--- a/gcc/tree.c
+++ b/gcc/tree.c
@@ -5556,6 +5556,7 @@ free_lang_data_in_type (tree type, class free_lang_data_d *fld)
{
if (TREE_CODE (type) == ENUMERAL_TYPE)
{
+ tree it = NULL_TREE;
ENUM_IS_OPAQUE (type) = 0;
ENUM_IS_SCOPED (type) = 0;
/* Type values are used only for C++ ODR checking. Drop them
@@ -5568,8 +5569,27 @@ free_lang_data_in_type (tree type, class free_lang_data_d *fld)
/* Simplify representation by recording only values rather
than const decls. */
for (tree e = TYPE_VALUES (type); e; e = TREE_CHAIN (e))
- if (TREE_CODE (TREE_VALUE (e)) == CONST_DECL)
- TREE_VALUE (e) = DECL_INITIAL (TREE_VALUE (e));
+ {
+ if (TREE_CODE (TREE_VALUE (e)) == CONST_DECL)
+ {
+ TREE_VALUE (e) = DECL_INITIAL (TREE_VALUE (e));
+ /* We can not stream values whose TREE_TYPE is type itself
+ because that would create non-trivial CSS. Canonicalize
+ them to integer types. */
+ }
+ /* Some frontends use ENUMERAL_TYPE to represent the constants.
+ This leads to nontrivial SCC components containing
+ INTEGER_CST which is not good for streaming. Convert them
+ all to corresponding integer type. */
+ if (TREE_CODE (TREE_TYPE (TREE_VALUE (e))) != INTEGER_TYPE)
+ {
+ if (!it)
+ it = lang_hooks.types.type_for_size
+ (TYPE_PRECISION (TREE_TYPE (TREE_VALUE (e))),
+ TYPE_UNSIGNED (TREE_TYPE (TREE_VALUE (e))));
+ TREE_VALUE (e) = fold_convert (it, TREE_VALUE (e));
+ }
+ }
}
free_lang_data_in_one_sizepos (&TYPE_MIN_VALUE (type));
free_lang_data_in_one_sizepos (&TYPE_MAX_VALUE (type));