diff mbox

[c++-delayed-folding] fold_simple

Message ID CAEwic4Zz0OnrFxuxCFeV2Qych_zwJBzCoOEXFQExfMJfjVQ2yA@mail.gmail.com
State New
Headers show

Commit Message

Kai Tietz Aug. 31, 2015, 7:08 p.m. UTC
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

Comments

Jason Merrill Aug. 31, 2015, 7:29 p.m. UTC | #1
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.

Jason
Kai Tietz Aug. 31, 2015, 7:43 p.m. UTC | #2
2015-08-31 21:29 GMT+02:00 Jason Merrill <jason@redhat.com>:
> 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
Jason Merrill Sept. 1, 2015, 2:47 p.m. UTC | #3
On 08/31/2015 03:43 PM, Kai Tietz wrote:
> 2015-08-31 21:29 GMT+02:00 Jason Merrill <jason@redhat.com>:
>> 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.

I would rather handle this by checking whether the folded operands are 
constant before even building the folded result.

Jason
Kai Tietz Sept. 1, 2015, 3:27 p.m. UTC | #4
2015-09-01 16:47 GMT+02:00 Jason Merrill <jason@redhat.com>:
> On 08/31/2015 03:43 PM, Kai Tietz wrote:
>>
>> 2015-08-31 21:29 GMT+02:00 Jason Merrill <jason@redhat.com>:
>>>
>>> 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.
>
>
> I would rather handle this by checking whether the folded operands are
> constant before even building the folded result.

I rewrote binary/unary overflow-check logic so, that we avoid double
checking-s.  I think this address things as you intend, beside the
checking for constant value.  We would need to check for *_CST
tree-codes.  Is there a macro we could use, which is just checking for
those?

> Jason
>

Kai
Jason Merrill Sept. 1, 2015, 3:31 p.m. UTC | #5
On 09/01/2015 11:27 AM, Kai Tietz wrote:
> I rewrote binary/unary overflow-check logic so, that we avoid double
> checking-s.  I think this address things as you intend, beside the
> checking for constant value.  We would need to check for *_CST
> tree-codes.  Is there a macro we could use, which is just checking for
> those?

Yes, CONSTANT_CLASS_P.

Jason
Kai Tietz Sept. 1, 2015, 3:34 p.m. UTC | #6
2015-09-01 17:31 GMT+02:00 Jason Merrill <jason@redhat.com>:
> On 09/01/2015 11:27 AM, Kai Tietz wrote:
>>
>> I rewrote binary/unary overflow-check logic so, that we avoid double
>> checking-s.  I think this address things as you intend, beside the
>> checking for constant value.  We would need to check for *_CST
>> tree-codes.  Is there a macro we could use, which is just checking for
>> those?
>
>
> Yes, CONSTANT_CLASS_P.
>
> Jason


Thanks, I found it too :]  I applied a patch short-cutting check for
cases that operands aren't of constant-class.

Kai
diff mbox

Patch

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)