This patch ports the implementation of -Wself-assign warning from a GCC-4.4.3 based tree to google/main branch. The warning checks for self-assignment and self-initialization. It is intended for detecting accidental self-assignment due to typos, and therefore does not warn on a statement that is semantically a self-assignment after constant folding (e.g. x = x + 0). The patch also includes another new (sub-)flag -Wself-assign-non-pod that controls whether or not to warn about self-assignment of non-POD variables.
Bootstrapped and passed gcc regression testsuite on x86_64. Le-chun On Fri, Apr 22, 2011 at 1:08 PM, Le-Chun Wu <l...@google.com> wrote: > > 2011-04-22 Le-Chun Wu <l...@google.com> > > gcc/c-family/ChangeLog: > * c-common.c (check_for_self_assign): New function. > * c-common.h: New function declaration. > * c.opt: New option. > > gcc/ChangeLog: > * c-parser.c (c_parser_declaration_or_fndef): Check for self-assign. > (c_parser_expr_no_commas): Check for self-assign. > * common.opt: New option. > * doc/invoke.texi: Documentation for new options. > * fold-const.c (operand_equal_p): Allow operands without typres to > compare. > (fold_unary_loc_1): Renamed from fold_unary_loc. > (fold_unary_loc): New wrapper function. > (fold_binary_loc_1): Renamed from fold_binary_loc. > (fold_binary_loc): New wrapper function. > (fold_ternary_loc_1): Renamed from fold_ternary_loc. > (fold_ternary_loc): New wrapper function. > * tree.h (struct tree_base): New flag for folded expr. > (enum operand_equal_flag): New flags. > > gcc/cp/ChangeLog: > * init.c (perform_member_init): Check for self-assign. > * parser.c (expr_is_pod): New function. > (cp_parser_assignment_expression): Check for self-assign. > (cp_parser_init_declarator): Check for self-assign. > > gcc/testsuite/ChangeLog: > * testsuite/g++.dg/plugin/selfassign.c (check_self_assign): Renamed > from warn_self_assign. > (execute_warn_self_assign): Call a function by its new name. > * testsuite/g++.dg/warn/Wself-assign-1.C: New test case. > * testsuite/g++.dg/warn/Wself-assign-2.C: Likewise. > * testsuite/g++.dg/warn/Wself-assign-3.C: Likewise. > * testsuite/g++.dg/warn/Wself-assign-4.C: Likewise. > * testsuite/g++.dg/warn/Wself-assign-5.C: Likewise. > * testsuite/g++.dg/warn/Wself-assign-non-pod-1.C: Likewise. > * testsuite/g++.dg/warn/Wself-assign-non-pod-2.C: Likewise. > * testsuite/g++.dg/warn/Wself-assign-non-pod-3.C: Likewise. > * testsuite/g++.dg/warn/Wself-assign-non-pod-4.C: Likewise. > * testsuite/g++.dg/warn/Wself-assign-non-pod-5.C: Likewise. > * testsuite/gcc.dg/plugin/selfassign.c (check_self_assign): Renamed > from warn_self_assign. > (execute_warn_self_assign): Call a function by its new name.: > * testsuite/gcc.dg/wself-assign-1.c: New test case. > * testsuite/gcc.dg/wself-assign-2.c: Likewise. > > > -- > This patch is available for review at http://codereview.appspot.com/4442075