[cfe-commits] r172016 - in /cfe/trunk: include/clang/AST/Expr.h lib/AST/ExprConstant.cpp lib/Sema/SemaStmt.cpp test/Sema/switch-1.c
Richard Smith
richard at metafoo.co.uk
Thu Jan 17 15:24:24 PST 2013
This looks like a good start. But I think it won't check for integer
overflow in subexpressions of a full-expression? eg, "case (123456 *
789012) + 1:" In order to catch that without repeatedly evaluating
subexpressions, I was thinking you could move the checking logic into
ExprConstant.cpp.
On Thu, Jan 17, 2013 at 2:50 PM, jahanian <fjahanian at apple.com> wrote:
>
> On Jan 17, 2013, at 1:09 PM, Richard Smith <richard at metafoo.co.uk> wrote:
>
>> On Thu, Jan 17, 2013 at 12:35 PM, jahanian <fjahanian at apple.com> wrote:
>>>
>>> On Jan 17, 2013, at 11:31 AM, jahanian <fjahanian at apple.com> wrote:
>>>
>>>>
>>>> On Jan 16, 2013, at 5:19 PM, Richard Smith <richard at metafoo.co.uk> wrote:
>>>>
>>>>> On Wed, Jan 16, 2013 at 5:05 PM, jahanian <fjahanian at apple.com> wrote:
>>>>>>
>>>>>> Any more thought on this?
>>>>>
>>>>> Here's one possible plan:
>>>>>
>>>>> Add a mode to the expression evaluator which visits all subexpressions
>>>>> and produces warnings for overflow etc. Call it in that mode from
>>>>> CheckCompletedExpr (just added in r172690), except in cases where the
>>>>> expression is required to be constant (the callers of
>>>>> ActOnFinishFullExpr should know this).
>>>>
>>>>
>>>> Here is the patch which moves checking to CheckCompletedExpr and avoids re-evaluation.
>>>> I still had to add the overflow check in the case statement because case label expressions do not
>>>> go through ActOnFinishFullExpr.
>>
>> They are full-expressions, so they should go through
>> ActOnFinishFullExpr. Here's an accepts-invalid resulting from this
>> omission:
>>
>> template<int...N> void f(int k) { switch(k) case N: ; }
>
>>
>>> Oops I forgot about the 'except' part. A new patch will be coming.
>
> This is the completed patch.
>
>
>
>
>
> - Thanks, Fariborz
>
>
>>
>> Thanks!
>
>
More information about the cfe-commits
mailing list