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 6877C38582B2 for ; Mon, 24 Oct 2022 14:07:28 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6877C38582B2 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1666620447; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=iliUW8swOwEiBaHu5OMCa1N3pO83O9IjJrMYzB1kbjo=; b=CkRGOFwwKw2RL+1W0HPxlC2E6f+MdYxBPRXdH+Dq0EAE7pIR9B4cLnlvpTRfIgMe/FXOPf 4gK/eWNQ7vjmTby9em1kBaPwxIG+W+H6xVBteExdH3ywy3+QsSYo7jXCyiJDe79SaHrI2y g6Uk+JqqsA18244XwwV+sKHOKkT0t2E= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-613-a89wR_16MAC1tUjyGnhEVA-1; Mon, 24 Oct 2022 10:07:17 -0400 X-MC-Unique: a89wR_16MAC1tUjyGnhEVA-1 Received: by mail-qk1-f197.google.com with SMTP id h8-20020a05620a284800b006b5c98f09fbso9176684qkp.21 for ; Mon, 24 Oct 2022 07:07:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=iliUW8swOwEiBaHu5OMCa1N3pO83O9IjJrMYzB1kbjo=; b=V2ES33RhzFqGPVkyyeRlQs61H5BrQQZl8LW1ImsOx76NJ6sx3PbRNhJSdRPi/Sx4wk L/0a5piF/brIG3/jqGmQa+iFmIFj1jSju8i1Iy4jf2147qW2fzeLkXjvDTJ7uy8ujppI bLJQ6OATQSTXRfvyWCyZefIH592heNByvlGIho02/z4oCzVjIebpNiMn1EqCIWbYmPnM 12HOpSNIZkW16YvTkmIZSJoecs28io44bBkK0ajC1v8Ynud8RknrtkZMHmIheqn+O8+u WKkyPf4+HnxudW57Aavowu8Mld9T7pD6W1Mr9TQb8+U0CZXIfSd71S1zsUvvHPnSKjec CGzw== X-Gm-Message-State: ACrzQf0SR3w8nRBc/KQ/2UtywZBwr08bIUIXJVdg4zffhb3DRRp6ROaD Sc0674D0BO5I54j0y1ls5Z+peZwjBXJNuZ5gPI5GAAgWE5UpQjTRj7oUAFFZPMxTCO9QbOdk5v2 DHi7axycBZpp0Qkq+zw== X-Received: by 2002:a05:620a:43a5:b0:6ee:d075:207b with SMTP id a37-20020a05620a43a500b006eed075207bmr23177776qkp.464.1666620436740; Mon, 24 Oct 2022 07:07:16 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4zBoCVSTezopXQbR8xQVmIvep/GQibUMFA8+CNxJb5Xmk7igzPeqGfoAIlFkDl1zGVBCLl4A== X-Received: by 2002:a05:620a:43a5:b0:6ee:d075:207b with SMTP id a37-20020a05620a43a500b006eed075207bmr23177746qkp.464.1666620436404; Mon, 24 Oct 2022 07:07:16 -0700 (PDT) Received: from [192.168.1.101] (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 m16-20020a05620a291000b006cf9084f7d0sm43834qkp.4.2022.10.24.07.07.15 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 24 Oct 2022 07:07:15 -0700 (PDT) Message-ID: <193270d5-60e7-7c03-d88b-5006300768a8@redhat.com> Date: Mon, 24 Oct 2022 10:07:09 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.4.0 Subject: Re: [PATCH] c++: Fix up constexpr handling of char/signed char/short pre/post inc/decrement [PR105774] 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=-6.7 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,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 10/24/22 03:27, Jakub Jelinek wrote: > Hi! > > signed char, char or short int pre/post inc/decrement are represented by > normal {PRE,POST}_{INC,DEC}REMENT_EXPRs in the FE and only gimplification > ensures that the {PLUS,MINUS}_EXPR is done in unsigned version of those > types: > case PREINCREMENT_EXPR: > case PREDECREMENT_EXPR: > case POSTINCREMENT_EXPR: > case POSTDECREMENT_EXPR: > { > tree type = TREE_TYPE (TREE_OPERAND (*expr_p, 0)); > if (INTEGRAL_TYPE_P (type) && c_promoting_integer_type_p (type)) > { > if (!TYPE_OVERFLOW_WRAPS (type)) > type = unsigned_type_for (type); > return gimplify_self_mod_expr (expr_p, pre_p, post_p, 1, type); > } > break; > } > This means during constant evaluation we need to do it similarly (either > using unsigned_type_for or using widening to integer_type_node). > The following patch does the latter. > > Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? OK. > 2022-10-24 Jakub Jelinek > > PR c++/105774 > * constexpr.cc (cxx_eval_increment_expression): For signed types > that promote to int, evaluate PLUS_EXPR or MINUS_EXPR in int type. > > * g++.dg/cpp1y/constexpr-105774.C: New test. > > --- gcc/cp/constexpr.cc.jj 2022-10-21 18:04:47.869797312 +0200 > +++ gcc/cp/constexpr.cc 2022-10-23 18:43:27.003390282 +0200 > @@ -6234,6 +6234,18 @@ cxx_eval_increment_expression (const con > offset = fold_build1 (NEGATE_EXPR, TREE_TYPE (offset), offset); > mod = fold_build2 (POINTER_PLUS_EXPR, type, val, offset); > } > + else if (c_promoting_integer_type_p (type) > + && !TYPE_UNSIGNED (type) > + && TYPE_PRECISION (type) < TYPE_PRECISION (integer_type_node)) > + { > + offset = fold_convert (integer_type_node, offset); > + mod = fold_convert (integer_type_node, val); > + tree t = fold_build2 (inc ? PLUS_EXPR : MINUS_EXPR, integer_type_node, > + mod, offset); > + mod = fold_convert (type, t); > + if (TREE_OVERFLOW_P (mod) && !TREE_OVERFLOW_P (t)) > + TREE_OVERFLOW (mod) = false; > + } > else > mod = fold_build2 (inc ? PLUS_EXPR : MINUS_EXPR, type, val, offset); > if (!ptr) > --- gcc/testsuite/g++.dg/cpp1y/constexpr-105774.C.jj 2022-10-23 18:44:15.587729613 +0200 > +++ gcc/testsuite/g++.dg/cpp1y/constexpr-105774.C 2022-10-23 18:33:54.754170726 +0200 > @@ -0,0 +1,15 @@ > +// PR c++/105774 > +// { dg-do compile { target c++14 } } > + > +constexpr signed char > +foo () > +{ > +#if __SCHAR_MAX__ < __INT_MAX__ > + signed char x = __SCHAR_MAX__; > +#else > + signed char x = 0; > +#endif > + return ++x; > +} > + > +constexpr auto a = foo (); > > Jakub >