From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 84968 invoked by alias); 1 Sep 2015 13:40:47 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 84950 invoked by uid 89); 1 Sep 2015 13:40:46 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.1 required=5.0 tests=AWL,BAYES_00,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-wi0-f171.google.com Received: from mail-wi0-f171.google.com (HELO mail-wi0-f171.google.com) (209.85.212.171) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Tue, 01 Sep 2015 13:40:38 +0000 Received: by wicge5 with SMTP id ge5so7728588wic.0 for ; Tue, 01 Sep 2015 06:40:35 -0700 (PDT) MIME-Version: 1.0 X-Received: by 10.180.105.202 with SMTP id go10mr3578719wib.91.1441114834929; Tue, 01 Sep 2015 06:40:34 -0700 (PDT) Received: by 10.28.12.19 with HTTP; Tue, 1 Sep 2015 06:40:34 -0700 (PDT) In-Reply-To: References: <55DE7C84.8080206@redhat.com> <55E13905.9040607@redhat.com> <55E49448.1040803@redhat.com> <55E4AB07.4060405@redhat.com> Date: Tue, 01 Sep 2015 13:40:00 -0000 Message-ID: Subject: Re: [c++-delayed-folding] fold_simple From: Kai Tietz To: Jason Merrill Cc: gcc-patches List Content-Type: text/plain; charset=UTF-8 X-IsSubscribed: yes X-SW-Source: 2015-09/txt/msg00049.txt.bz2 2015-09-01 13:17 GMT+02:00 Kai Tietz : > 2015-09-01 10:43 GMT+02:00 Kai Tietz : >> 2015-09-01 10:15 GMT+02:00 Kai Tietz : >>> 2015-08-31 22:19 GMT+02:00 Kai Tietz : >>>> 2015-08-31 21:43 GMT+02:00 Kai Tietz : >>>>> 2015-08-31 21:29 GMT+02:00 Jason Merrill : >>>>>> On 08/31/2015 03:08 PM, Kai Tietz wrote: >>>>>>> >>>>>>> I will need to verify that this patch doesn't introduce regressions. >>>>>>> The wacky thing here is the encapsulation of overflowed-arguments in >>>>>>> maybe_constant_value function by nop-expr. >>>>>> >>>>>> >>>>>> Do we need to worry about that? If one of the operands is overflowed, we >>>>>> don't care whether the result is overflowed. >>>>> >>>>> Well, we would introduce, if we don't see in condition that operand >>>>> already overflowed, double overflow-warning, which seems to be >>>>> something we avoided until now. So I would say, it matters. >>>>> >>>>> Kai >>>> >>>> Similar to the binary-operation we want to do then the same for >>>> unary-operations, too. >>>> >>>> Eg. testcase: >>>> >>>> #include >>>> >>>> constexpr int f() { return INT_MIN; } >>>> >>>> int main() >>>> { >>>> return -f(); // { dg-warning "overflow" } >>>> } >>>> With following patch we do diagnostics for it. >>>> >>>> Kai >>>> >>>> Index: semantics.c >>>> =================================================================== >>>> --- semantics.c (Revision 227339) >>>> +++ semantics.c (Arbeitskopie) >>>> @@ -2553,9 +2553,11 @@ finish_unary_op_expr (location_t loc, enum tree_co >>>> tree result = build_x_unary_op (loc, code, expr, complain); >>>> tree result_ovl = result; >>>> >>>> - expr_ovl = fold_simple (expr_ovl); >>>> - result_ovl = fold_simple (result); >>>> - >>>> + expr_ovl = maybe_constant_value (expr_ovl); >>>> + result_ovl = maybe_constant_value (result); >>>> + /* Strip nop-expressions added by maybe_constant_value on overflow. */ >>>> + STRIP_NOPS (expr_ovl); >>>> + STRIP_NOPS (result_ovl); >>>> if ((complain & tf_warning) >>>> && TREE_OVERFLOW_P (result_ovl) && !TREE_OVERFLOW_P (expr_ovl)) >>>> overflow_warning (input_location, result_ovl); >>> >>> I committed patches for binary & unary operations together with >>> testcases. Regression-run still running. There seems to be >>> additional expressions needed in constexpr for this. For now we have >>> a bootstrap-issue due cast_expr in cxx_eval_constant_expression. >>> There might be more of them ... >> >> I had to add for now that cxx_eval_constant_expr ignores on CAST_EXPR, >> STATIC_CAST_EXPR, OVERLOAD, and TREE_LIST. Additionally we need to >> handle for increments that offset is NULL_TREE (TREE_OPERAND (,1)) . > > Issue was easier to resolve by checking in binary/unary > overflow-checking-functions that we aren't processing template > declarations. If we aren't within template-declaration processing we > can call maybe_constant_value. This avoids that we feed > maybe_constant_value with mentioned C++-template specific expressions. > > Bootstrap ran successful, regression-testing still running for it. I > committed additional check already to branch. All tests passed as expected. Kai