diff options
author | Richard Biener <rguenther@suse.de> | 2022-01-20 14:25:51 +0100 |
---|---|---|
committer | Richard Biener <rguenther@suse.de> | 2022-01-20 16:50:34 +0100 |
commit | 5c12507f5d0bc080e4f346af99824e039236e61c (patch) | |
tree | 61747d6d9370e7df95b11c42e3bfd3e423594302 /gcc | |
parent | 62eb400b51f8a552320a250b3ac0b5d2ebd8927f (diff) | |
download | gcc-5c12507f5d0bc080e4f346af99824e039236e61c.zip gcc-5c12507f5d0bc080e4f346af99824e039236e61c.tar.gz gcc-5c12507f5d0bc080e4f346af99824e039236e61c.tar.bz2 |
middle-end/100786 - constant folding from incompatible alias
The following avoids us ICEing doing constant folding from variables
with aliases of different types. The issue appears both in
folding and CCP and FRE can do more fancy stuff to still constant
fold cases where the load is smaller than the initializer so
defer it to there.
2022-01-20 Richard Biener <rguenther@suse.de>
PR middle-end/100786
* gimple-fold.cc (get_symbol_constant_value): Only return
values of compatible type to the symbol.
* gcc.dg/torture/pr100786.c: New testcase.
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/gimple-fold.cc | 4 | ||||
-rw-r--r-- | gcc/testsuite/gcc.dg/torture/pr100786.c | 9 |
2 files changed, 12 insertions, 1 deletions
diff --git a/gcc/gimple-fold.cc b/gcc/gimple-fold.cc index 08d3cc2..3639aa2 100644 --- a/gcc/gimple-fold.cc +++ b/gcc/gimple-fold.cc @@ -291,7 +291,9 @@ get_symbol_constant_value (tree sym) if (val) { val = canonicalize_constructor_val (unshare_expr (val), sym); - if (val && is_gimple_min_invariant (val)) + if (val + && is_gimple_min_invariant (val) + && useless_type_conversion_p (TREE_TYPE (sym), TREE_TYPE (val))) return val; else return NULL_TREE; diff --git a/gcc/testsuite/gcc.dg/torture/pr100786.c b/gcc/testsuite/gcc.dg/torture/pr100786.c new file mode 100644 index 0000000..42f4e48 --- /dev/null +++ b/gcc/testsuite/gcc.dg/torture/pr100786.c @@ -0,0 +1,9 @@ +/* { dg-do compile } */ + +const double a = 0; +extern int b __attribute__((alias("a"))); +void inc() { b++; } + +const int a2 = 0; +extern double b2 __attribute__((alias("a2"))); +void inc2() { b2+=1; } |