[patch] Add a new warning flag -Wself-assign

Andrew Pinski pinskia@gmail.com
Wed Jun 9 18:56:00 GMT 2010


On Wed, Jun 9, 2010 at 11:25 AM, 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.

I think we should first decide what interactions we want for this
option vs -Winit-self.  Because adding a new option seems over kill
and wrong.  It would cause more confusion to our users.  In fact maybe
we should just get rid of the special case of -Winit-self and improve
the C++ front-end where -Wself-asign would warn more (the bug report I
mentioned before for an example).

And then we remove the issue I have with fold.  The special case is
implemented one place in c_gimplify_expr.  In fact "int x = x+0;" will
cause right now the unitialized warning for x to be disabled (without
-Winit-self) because of the folding.

Thanks,
Andrew Pinski



More information about the Gcc-patches mailing list