This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: add warning for unused user-defined operator


On Thu, Oct 30, 2014 at 6:49 PM, Prathamesh Kulkarni
<bilbotheelffriend@gmail.com> wrote:
> On Thu, Oct 30, 2014 at 11:12 PM, Prathamesh Kulkarni
> <bilbotheelffriend@gmail.com> wrote:
>> On Tue, Oct 28, 2014 at 3:38 PM, Richard Biener
>> <richard.guenther@gmail.com> wrote:
>>> On Sat, Oct 25, 2014 at 12:38 PM, Prathamesh Kulkarni
>>> <bilbotheelffriend@gmail.com> wrote:
>>>> Add warning for unused user-defined operator in for.
>>>>
>>>> Issues:
>>>> a) I added a new field "used" in user_id, which is initially false,
>>>> and is set to true, when it is looked up using get_operator(). Not sure
>>>> if that's a good idea.
>>>
>>> Sure - that's the simplest way.
>>>
>>>> b) error_cb determines whether to exit depending on second
>>>> argument, and does not if it equals CPP_DL_WARNING.
>>>> I am not sure what to return from error_cb, I just put return 0.
>>>
>>> Yeah, I suppose that works.  The return parameter doesn't seem to be
>>> documented anywhere.
>>>
>>>> During the build it gives the following warning:
>>>> ../../src/gcc/match.pd:64:6 warning: operator op defined but not used
>>>> (for op (ceil_mod floor_mod round_mod trunc_mod)
>>>>       ^
>>>>
>>>> * genmatch.c
>>>>   (error_cb): Adjust to print warnings.
>>>>   (warning_at): New function.
>>>>   (user_id): Add new member used.
>>>>   (get_operator): Adjust to changes in user_id.
>>>>   (parse_for): Warn for unused operators.
>>>
>>> Looks good.  I'll apply this later after merging from trunk again.
>>>
>>> Please watch out for added trailing spaces like here on the 2nd line
>>>
>>> -error_cb (cpp_reader *, int, int, source_location location,
>>> -         unsigned int, const char *msg, va_list *ap)
>>> +error_cb (cpp_reader *, int errtype, int, source_location location,
>>> +         unsigned int, const char *msg, va_list *ap)
>>>
>>> and long lines like
>>>
>>> +  fprintf (stderr, "%s:%d:%d %s: ", loc.file, loc.line, loc.column,
>>> (errtype == CPP_DL_WARNING) ? "warning" : "error");
>>>
>>> As well as spurious whitespace changes like
>>>
>>>  }
>>>
>>> +
>>>  static void
>>>
>>> The following is what I have applied.
>> It warns "defined but not used" if the operator is used in c_expr.
>> eg (artificial pattern):
>> (for op (plus minus)
>>       op2 (mult trunc_div)
>>   (op @x @y)
>>   { op2; })
>>
>> The following patch fixes that.
>>
>> * genmatch.c
>>   (parser::parse_c_expr): Mark operator as used.
> Oops, I had forgotten get_operator marks operator as used.
> We then only need to call get_operator.
>
> * genmatch.c
>   (parser::parse_c_expr): Call get_operator.

Thanks, applied.  (please post patches to gcc-patches)

Richard.

> Thanks,
> Prathamesh
>>
>> Thanks,
>> Prathamesh
>>>
>>> Thanks,
>>> Richard.
>>>
>>> 2014-10-28  Prathamesh Kulkarni  <bilbotheelffriend@gmail.com>
>>>
>>>         * genmatch.c (error_cb): Adjust for printing warnings.
>>>         (warning_at): New function.
>>>         (user_id): Add new member used.
>>>         (get_operator): Mark user_id as used.
>>>         (parse_for): Warn for unused operators.
>>>
>>>
>>>> Thanks,
>>>> Prathamesh


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]