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: [patch] Add a new warning flag -Wself-assign


On Thu, Jun 10, 2010 at 12:32 PM, Le-Chun Wu <lcwu@google.com> wrote:
> On Wed, Jun 9, 2010 at 6:55 PM, Gabriel Dos Reis
> <gdr@integrable-solutions.net> wrote:
>> On Wed, Jun 9, 2010 at 1:25 PM, Le-Chun Wu <lcwu@google.com> wrote:
>>>
>>> The reason why I had to add a flag in expr and set it after folding an
>>> expression is because the C frontend is too eager to constant-fold an
>>> expression at parse time. For example, when parsing an assignment x =
>>> x + 0 (which we don't want to warn under -Wself-assign), what we get
>>> after paring the statement is already x = x (while, on the other hand,
>>> C++ parser would return x = x + 0 first, and then call the folding
>>> routines). While I would welcome any other better ideas, I did some
>>> compile time tests with my patch and the results show that the code
>>> does not slow down the compiler. Diego pointed me to the GCC
>>> PerformanceTesting wiki page that contains some compile-time test
>>> instructions, but there are too many packages to download and set up,
>>> so I picked some of the largest GCC source files to measure the
>>> compile time with and without this patch. Here are the results:
>>
>> How do you plan handle
>>
>> ? ?void* p = &p;
>>
>> ?
>>
>
> The new flag doesn't warn about this case.

Good.

> While this code looks
> dubious (and the compiler probably should emit a warning), it is
> strictly-speaking not a self-assignment or self-initialization as it
> assigns p's address to p. If we are going to warn about it, the
> warning should probably not be under -Wself-assign.

I would not recommend warning about it.

>
> Thanks,
>
> Le-chun
>


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