From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 0BBB1383A606 for ; Thu, 9 Jun 2022 12:49:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0BBB1383A606 Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-247-qUYfUVUHMPe13RtYOTylGg-1; Thu, 09 Jun 2022 08:49:07 -0400 X-MC-Unique: qUYfUVUHMPe13RtYOTylGg-1 Received: by mail-qk1-f199.google.com with SMTP id l12-20020a05620a28cc00b006a73a2285dbso476052qkp.20 for ; Thu, 09 Jun 2022 05:49:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=POK126z4ea9OG7Hc+BPP6uS/cIyzXRD7gyEFKfgeFKA=; b=SGCOc8XIRBbPMtKlIv2jImBZ/03dn+Dr/fgVNV2jD9NWPs2gNwb2mFmlwGTSLrbORc jqrdMSNlNFJVTr+ZJBmSsibZ+n0CHXtzuFGYHYbKkQQwI8+tISECiKxekO2imOAXWxvI cM/19EVQisd4u+3xWSjafmblXBzZxvhrdjnVfvrFJlMcpsC1EO4cKsICjkb9DltdpTSb RcsAT6edPie3xhpWn23X9iaPOlkOianq+odfu1EtPLEOmBLXOdjHmoqthK5OFi2bv9KY AInOA+9Egy6bKHAtcA2loVX8zGpU+p33jal+FUJ+S3P3jKA9WHlXAPXHkUWA5WLNGxIH fFzQ== X-Gm-Message-State: AOAM532hUmrvyxvz/Y8wfOYZJJ9oeMnDCfKulAkbCgSHhpAGFTQmDj2e vR4YaJe+fvfiPHM09GNB5eXQySDRfdFC8aIkdWJqMaMUIt6u4Ez4KGb85iubKrRlDfAvfGLTkZN rSeo2qKTK4QrqaFQ5GA== X-Received: by 2002:a05:620a:44c6:b0:6a6:d033:7804 with SMTP id y6-20020a05620a44c600b006a6d0337804mr11530418qkp.153.1654778947205; Thu, 09 Jun 2022 05:49:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxpoKFakhRbCq4i+1BbLwcOpewv2/wC1Qf4ZiJecAamKE+YFsldorpK0Acjix3/411OTeY25w== X-Received: by 2002:a05:620a:44c6:b0:6a6:d033:7804 with SMTP id y6-20020a05620a44c600b006a6d0337804mr11530405qkp.153.1654778946823; Thu, 09 Jun 2022 05:49:06 -0700 (PDT) Received: from [192.168.1.100] (130-44-159-43.s15913.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.159.43]) by smtp.gmail.com with ESMTPSA id h2-20020a05620a244200b006a6d3fa430csm7660308qkn.58.2022.06.09.05.49.06 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 09 Jun 2022 05:49:06 -0700 (PDT) Message-ID: <3bc6bd66-5d3e-f3ed-8099-bf5bf2dcc576@redhat.com> Date: Thu, 9 Jun 2022 08:49:05 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.10.0 Subject: Re: [PATCH] c++: Fix up ICE on __builtin_shufflevector constexpr evaluation [PR105871] To: Jakub Jelinek Cc: gcc-patches@gcc.gnu.org References: From: Jason Merrill In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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-List-Received-Date: Thu, 09 Jun 2022 12:49:10 -0000 On 6/8/22 02:08, Jakub Jelinek wrote: > Hi! > > As the following testcase shows, BIT_FIELD_REF result doesn't have to have > just integral type, it can also have vector type. And in that case > cxx_eval_bit_field_ref just ICEs on it because it is unprepared for that > case, creates the initial value with build_int_cst (sure, that one could be > easily replaced with build_zero_cst) and then expects it can through shifts, > ands and ors come up with the final value, but that doesn't work for > vectors. > > We already call fold_ternary if whole is a VECTOR_CST, this patch does the > same if the result doesn't have integral type. And, there is no guarantee > fold_ternary will succeed and the callers certainly don't expect NULL > being returned, so it also diagnoses those as non-constant and returns > original t in that case. > > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? OK. > 2022-06-08 Jakub Jelinek > > PR c++/105871 > * constexpr.cc (cxx_eval_bit_field_ref): For BIT_FIELD_REF with > non-integral result type use fold_ternary too like for BIT_FIELD_REFs > from VECTOR_CST. If fold_ternary returns NULL, diagnose non-constant > expression, set *non_constant_p and return t, instead of returning > NULL. > > * g++.dg/pr105871.C: New test. > > --- gcc/cp/constexpr.cc.jj 2022-06-03 11:20:13.000000000 +0200 > +++ gcc/cp/constexpr.cc 2022-06-07 13:43:13.157127740 +0200 > @@ -4198,9 +4198,16 @@ cxx_eval_bit_field_ref (const constexpr_ > if (*non_constant_p) > return t; > > - if (TREE_CODE (whole) == VECTOR_CST) > - return fold_ternary (BIT_FIELD_REF, TREE_TYPE (t), whole, > - TREE_OPERAND (t, 1), TREE_OPERAND (t, 2)); > + if (TREE_CODE (whole) == VECTOR_CST || !INTEGRAL_TYPE_P (TREE_TYPE (t))) > + { > + if (tree r = fold_ternary (BIT_FIELD_REF, TREE_TYPE (t), whole, > + TREE_OPERAND (t, 1), TREE_OPERAND (t, 2))) > + return r; > + if (!ctx->quiet) > + error ("%qE is not a constant expression", orig_whole); > + *non_constant_p = true; > + return t; > + } > > start = TREE_OPERAND (t, 2); > istart = tree_to_shwi (start); > --- gcc/testsuite/g++.dg/pr105871.C.jj 2022-06-07 13:56:02.743241969 +0200 > +++ gcc/testsuite/g++.dg/pr105871.C 2022-06-07 13:56:29.042975525 +0200 > @@ -0,0 +1,12 @@ > +// PR c++/105871 > +// { dg-do compile } > +// { dg-options "-Wno-psabi" } > + > +typedef __attribute__((__vector_size__ ( 1))) unsigned char U; > +typedef __attribute__((__vector_size__ (16))) unsigned char V; > + > +U > +foo (void) > +{ > + return __builtin_shufflevector ((U){}, (V){}, 0); > +} > > Jakub >