From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2153) id 9B0463857345; Mon, 20 Jun 2022 06:38:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9B0463857345 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jakub Jelinek To: gcc-cvs@gcc.gnu.org Subject: [gcc r10-10857] varasm: Fix up ICE in narrowing_initializer_constant_valid_p [PR105998] X-Act-Checkin: gcc X-Git-Author: Jakub Jelinek X-Git-Refname: refs/heads/releases/gcc-10 X-Git-Oldrev: 62148f13c6427edd256072b3196a01b3d5ed2805 X-Git-Newrev: 20bb976fb6a853d4f79577278ac2f01622946b61 Message-Id: <20220620063816.9B0463857345@sourceware.org> Date: Mon, 20 Jun 2022 06:38:16 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 20 Jun 2022 06:38:16 -0000 https://gcc.gnu.org/g:20bb976fb6a853d4f79577278ac2f01622946b61 commit r10-10857-g20bb976fb6a853d4f79577278ac2f01622946b61 Author: Jakub Jelinek Date: Sat Jun 18 11:07:13 2022 +0200 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 PR middle-end/105998 * varasm.c (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) Diff: --- gcc/testsuite/c-c++-common/pr105998.c | 12 ++++++++++++ gcc/varasm.c | 10 ++++++++-- 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 @@ +/* PR middle-end/105998 */ + +typedef int __attribute__((__vector_size__ (sizeof (long long)))) V; + +V v; + +long long +foo (void) +{ + long long l = (long long) ((0 | v) - ((V) { } == 0)); + return l; +} diff --git a/gcc/varasm.c b/gcc/varasm.c index 04d59727a79..d65985d9748 100644 --- a/gcc/varasm.c +++ b/gcc/varasm.c @@ -4455,7 +4455,10 @@ narrowing_initializer_constant_valid_p (tree value, tree endtype, tree *cache) { tree inner = TREE_OPERAND (op0, 0); if (inner == error_mark_node - || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner))) + || ! INTEGRAL_TYPE_P (TREE_TYPE (op0)) + || ! SCALAR_INT_MODE_P (TYPE_MODE (TREE_TYPE (op0))) + || ! INTEGRAL_TYPE_P (TREE_TYPE (inner)) + || ! SCALAR_INT_MODE_P (TYPE_MODE (TREE_TYPE (inner))) || (GET_MODE_SIZE (SCALAR_INT_TYPE_MODE (TREE_TYPE (op0))) > GET_MODE_SIZE (SCALAR_INT_TYPE_MODE (TREE_TYPE (inner))))) break; @@ -4467,7 +4470,10 @@ narrowing_initializer_constant_valid_p (tree value, tree endtype, tree *cache) { tree inner = TREE_OPERAND (op1, 0); if (inner == error_mark_node - || ! INTEGRAL_MODE_P (TYPE_MODE (TREE_TYPE (inner))) + || ! INTEGRAL_TYPE_P (TREE_TYPE (op1)) + || ! SCALAR_INT_MODE_P (TYPE_MODE (TREE_TYPE (op1))) + || ! INTEGRAL_TYPE_P (TREE_TYPE (inner)) + || ! SCALAR_INT_MODE_P (TYPE_MODE (TREE_TYPE (inner))) || (GET_MODE_SIZE (SCALAR_INT_TYPE_MODE (TREE_TYPE (op1))) > GET_MODE_SIZE (SCALAR_INT_TYPE_MODE (TREE_TYPE (inner))))) break;