This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [c++-delayed-folding] fold_simple
- From: Kai Tietz <ktietz70 at googlemail dot com>
- To: Jason Merrill <jason at redhat dot com>
- Cc: gcc-patches List <gcc-patches at gcc dot gnu dot org>
- Date: Mon, 31 Aug 2015 21:08:28 +0200
- Subject: Re: [c++-delayed-folding] fold_simple
- Authentication-results: sourceware.org; auth=none
- References: <55DE7C84 dot 8080206 at redhat dot com> <CAEwic4ZCg=XYskoUNLKcWfSkN-vb66V6-VptDjSkEbQuap+k9w at mail dot gmail dot com> <55E13905 dot 9040607 at redhat dot com> <CAEwic4bbxFWjucsH1Rt5tQ-jzUz7kM_omsyHE12mRBAFngGWaw at mail dot gmail dot com> <55E49448 dot 1040803 at redhat dot com>
2015-08-31 19:52 GMT+02:00 Jason Merrill <jason@redhat.com>:
> On 08/29/2015 10:10 AM, Kai Tietz wrote:
>>
>> Hmm, I don't think we want to call maybe_constant_value in functions
>> like cp_build_binary_op. We are interested in overflow only on
>> constant-values anyway, I don't see that we want to have here any
>> constexpr-logic, nor specific address-manipulation logic. So I see
>> here not much advantage in using maybe_constant_value. Maybe I simply
>> not seeing the obvious here. Do you have a specific testcase, which
>> shows what diagnostics could be missed?
>
>
> #include <limits.h>
> constexpr int f() { return INT_MAX; }
> int main()
> {
> return f()+2; // { dg-warning "overflow" }
> }
>
> Jason
>
Ok. Following patch should allow this missed diagnostics
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.
Kai
Index: typeck.c
===================================================================
--- typeck.c (Revision 227339)
+++ typeck.c (Arbeitskopie)
@@ -5070,8 +5070,12 @@ cp_build_binary_op (location_t location,
result = build2 (resultcode, build_type, op0, op1);
if (final_type != 0)
result = cp_convert (final_type, result, complain);
- op0 = fold_simple (op0);
- op1 = fold_simple (op1);
+ op0 = maybe_constant_value (op0);
+ op1 = maybe_constant_value (op1);
+ /* Strip added nop-expression for overflow-operand introduced by
+ maybe_constant_value. */
+ STRIP_NOPS (op0);
+ STRIP_NOPS (op1);
result_ovl = fold_build2 (resultcode, build_type, op0, op1);
if (TREE_OVERFLOW_P (result_ovl)
&& !TREE_OVERFLOW_P (op0)