summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2022-06-18 11:07:13 +0200
committerJakub Jelinek <jakub@redhat.com>2022-06-19 12:08:35 +0200
commite8df0d960b36146c8e193b269f9f7ae7dc76e08b (patch)
tree4afae601e2be8ad7019951ec2665f51812c3157a
parentc++: Use fold_non_dependent_expr rather than maybe_constant_value in __builti... (diff)
downloadgcc-e8df0d960b36146c8e193b269f9f7ae7dc76e08b.tar.gz
gcc-e8df0d960b36146c8e193b269f9f7ae7dc76e08b.tar.bz2
gcc-e8df0d960b36146c8e193b269f9f7ae7dc76e08b.tar.xz
varasm: Fix up ICE in narrowing_initializer_constant_valid_p [PR105998]
The following testcase ICEs because there is NON_LVALUE_EXPR (location wrapper) around a VAR_DECL and has TYPE_MODE V2SImode and SCALAR_INT_TYPE_MODE on that ICEs. Or for -m32 -march=i386 TYPE_MODE is DImode, but SCALAR_INT_TYPE_MODE still uses the raw V2SImode and ICEs too. 2022-06-18 Jakub Jelinek <jakub@redhat.com> PR middle-end/105998 * varasm.cc (narrowing_initializer_constant_valid_p): Check SCALAR_INT_MODE_P instead of INTEGRAL_MODE_P, also break on ! INTEGRAL_TYPE_P and do the same check also on op{0,1}'s type. * c-c++-common/pr105998.c: New test. (cherry picked from commit ef662120177d39af5f88ffc622d90bb6ae0ca1d3)
-rw-r--r--gcc/testsuite/c-c++-common/pr105998.c12
-rw-r--r--gcc/varasm.cc10
2 files changed, 20 insertions, 2 deletions
diff --git a/gcc/testsuite/c-c++-common/pr105998.c b/gcc/testsuite/c-c++-common/pr105998.c
new file mode 100644
index 00000000000..85277b97007
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/pr105998.c
@@ -0,0 +1,12 @@
1/* PR middle-end/105998 */
2
3typedef int __attribute__((__vector_size__ (sizeof (long long)))) V;
4
5V v;
6
7long long
8foo (void)
9{
10 long long l = (long long) ((0 | v) - ((V) { } == 0));
11 return l;
12}
diff --git a/gcc/varasm.cc b/gcc/varasm.cc
index c41f17d64f7..021e912a37c 100644
--- a/gcc/varasm.cc
+++ b/gcc/varasm.cc
@@ -4716,7 +4716,10 @@ narrowing_initializer_constant_valid_p (tree value, tree endtype, tree *cache)
4716 { 4716 {
4717 tree inner = TREE_OPERAND (op0, 0); 4717 tree inner = TREE_OPERAND (op0, 0);
4718 if (inner == error_mark_node 4718 if (inner == error_mark_node
4719 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner))) 4719 || ! INTEGRAL_TYPE_P (TREE_TYPE (op0))
4720 || ! SCALAR_INT_MODE_P (TYPE_MODE (TREE_TYPE (op0)))
4721 || ! INTEGRAL_TYPE_P (TREE_TYPE (inner))
4722 || ! SCALAR_INT_MODE_P (TYPE_MODE (TREE_TYPE (inner)))
4720 || (GET_MODE_SIZE (SCALAR_INT_TYPE_MODE (TREE_TYPE (op0))) 4723 || (GET_MODE_SIZE (SCALAR_INT_TYPE_MODE (TREE_TYPE (op0)))
4721 > GET_MODE_SIZE (SCALAR_INT_TYPE_MODE (TREE_TYPE (inner))))) 4724 > GET_MODE_SIZE (SCALAR_INT_TYPE_MODE (TREE_TYPE (inner)))))
4722 break; 4725 break;
@@ -4728,7 +4731,10 @@ narrowing_initializer_constant_valid_p (tree value, tree endtype, tree *cache)
4728 { 4731 {
4729 tree inner = TREE_OPERAND (op1, 0); 4732 tree inner = TREE_OPERAND (op1, 0);
4730 if (inner == error_mark_node 4733 if (inner == error_mark_node
4731 || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner))) 4734 || ! INTEGRAL_TYPE_P (TREE_TYPE (op1))
4735 || ! SCALAR_INT_MODE_P (TYPE_MODE (TREE_TYPE (op1)))
4736 || ! INTEGRAL_TYPE_P (TREE_TYPE (inner))
4737 || ! SCALAR_INT_MODE_P (TYPE_MODE (TREE_TYPE (inner)))
4732 || (GET_MODE_SIZE (SCALAR_INT_TYPE_MODE (TREE_TYPE (op1))) 4738 || (GET_MODE_SIZE (SCALAR_INT_TYPE_MODE (TREE_TYPE (op1)))
4733 > GET_MODE_SIZE (SCALAR_INT_TYPE_MODE (TREE_TYPE (inner))))) 4739 > GET_MODE_SIZE (SCALAR_INT_TYPE_MODE (TREE_TYPE (inner)))))
4734 break; 4740 break;