From patchwork Fri Feb 11 10:13:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 51041 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 056013858429 for ; Fri, 11 Feb 2022 10:14:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 056013858429 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1644574466; bh=xTpj79+LZLyJ1v6GM9kilrCZdveAw+BtdR8UVdUES2Y=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=aH8BtRsJoBIUd1g6Yi++u5xGgusb3rxwtakP7CLH8NysfyLvJExUmr05zcxMl6Pf3 u/f1VntPMaidtdarAfXE7TVJHUAbA/zHixJgEecOIVTC5LTvv5tnMfZI3G6wkbJki3 0WlN0WH9nMbv4fY91bww1H5iiyuJ80XIXqixNVrk= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 4FE0F3858431 for ; Fri, 11 Feb 2022 10:13:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 4FE0F3858431 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-647-DYunlQZ2PCeRErnBjYF2SA-1; Fri, 11 Feb 2022 05:13:52 -0500 X-MC-Unique: DYunlQZ2PCeRErnBjYF2SA-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id E04D210B7462 for ; Fri, 11 Feb 2022 10:13:51 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.125]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 701577BE46; Fri, 11 Feb 2022 10:13:51 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.16.1/8.16.1) with ESMTPS id 21BADmZ72432001 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 11 Feb 2022 11:13:49 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.16.1/8.16.1/Submit) id 21BADmZD2432000; Fri, 11 Feb 2022 11:13:48 +0100 Date: Fri, 11 Feb 2022 11:13:48 +0100 To: Jason Merrill Subject: [PATCH] c++: Fix up constant expression __builtin_convertvector folding [PR104472] Message-ID: <20220211101348.GO2646553@tucnak> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-5.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Cc: gcc-patches@gcc.gnu.org Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" Hi! The following testcase ICEs, because due to the -frounding-math fold_const_call fails, which is it returns NULL, and returning NULL from cxx_eval* is wrong, all the callers rely on them to either return folded value or original with *non_constant_p = true. The following patch does that, and additionally falls through into the default case where there is diagnostics for the !ctx->quiet case too. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2022-02-11 Jakub Jelinek PR c++/104472 * constexpr.cc (cxx_eval_internal_function) : Only return fold_const_call result if it is non-NULL. Otherwise fall through into the default: case to return t, set *non_constant_p and emit diagnostics if needed. * g++.dg/cpp0x/constexpr-104472.C: New test. Jakub --- gcc/cp/constexpr.cc.jj 2022-02-08 20:15:33.997295271 +0100 +++ gcc/cp/constexpr.cc 2022-02-10 12:33:48.243321592 +0100 @@ -1840,13 +1840,10 @@ cxx_eval_internal_function (const conste false, non_constant_p, overflow_p); if (TREE_CODE (arg) == VECTOR_CST) - return fold_const_call (CFN_VEC_CONVERT, TREE_TYPE (t), arg); - else - { - *non_constant_p = true; - return t; - } + if (tree r = fold_const_call (CFN_VEC_CONVERT, TREE_TYPE (t), arg)) + return r; } + /* FALLTHRU */ default: if (!ctx->quiet) --- gcc/testsuite/g++.dg/cpp0x/constexpr-104472.C.jj 2022-02-10 12:44:09.869720657 +0100 +++ gcc/testsuite/g++.dg/cpp0x/constexpr-104472.C 2022-02-10 12:46:25.881838766 +0100 @@ -0,0 +1,9 @@ +// PR c++/104472 +// { dg-options "-O2 -frounding-math" } +// { dg-add-options float16 } +// { dg-require-effective-target float16 } + +typedef short __attribute__((__vector_size__ (16))) V; +typedef _Float16 __attribute__((__vector_size__ (16))) F; + +V v = __builtin_convertvector (__builtin_convertvector ((V){5534}, F), V) < 8;