PATCH RFC: Fix enum comparisons

Ian Lance Taylor iant@google.com
Wed Sep 3 22:32:00 GMT 2008


I wrote a patch to support -Wenum-compare in C.  This is useful for
gcc-in-cxx because -Wenum-compare is the default in C++.  Supporting
-Wenum-compare in C will make it easier to make gcc code C++
compliant.

Unfortunately, since we are in stage 3, that patch is not appropriate
to apply now.  However, bootstrapping with the patch found several
minor bugs in the gcc source code.  Those changes, being bugs, are
appropriate for stage 3.

The first attachment below is the -Wenum-compare support.  I don't
propose to apply that patch now, but I would be interested in any
comments from the C frontend maintainers.  I have not yet updated the
documentation; basically, -Wenum-compare is the default in C++, and in
C it is enabled by -Wall or -Wc++-compat.

The second attachment below is the changes to gcc to permit it to
bootstrap when the first patch is applied.  I plan to apply that
patch, with the following ChangeLog entry.

Fortran maintainers: as I noted yesterday, the code in
check_assumed_size_reference is wrong.  The patch below makes the code
equivalent to what it was before, in that it compares against an enum
of the right type with the same value.  I don't know how to fix this
correctly.  If you like, I will simply omit that part of that patch
when I commit.

Ian


gcc/ChangeLog:
2008-09-03  Ian Lance Taylor  <iant@google.com>

	* rtl.h (LABEL_REF_NONLOCAL_P): Don't check for REG_LABEL_OPERAND
	or REG_LABEL_TARGET.
	* calls.c (emit_library_call_value_1): Use MEM_P rather than
	comparing MODE with MEM.
	* gimple.c (gimple_build_predict): Cast END_PREDICTORS before
	comparing with GF_PREDICT_TAKEN.
	(gimple_get_lhs): Change code to enum gimple_code.
	(gimple_set_lhs): Likewise.
	* ifcvt.c (noce_process_if_block): Correct GET_MODE to GET_CODE.
	* omp-low.c (find_omp_clause): Change kind parameter to enum
	omp_clause_code.
	* tree-flow.h (find_omp_clause): Update declaration.
	* regrename.c (clear_dead_regs): Change kind parameter to enum
	reg_note.
	* reload1.c (eliminate_regs_1): Use REG_NOTE_KIND rather than
	GET_MODE.
	* see.c (see_get_extension_data): Change return type to enum
	entry_type.  Change UNKNOWN to NOT_RELEVANT, SIGN_EXTEND to
	SIGNED_EXTENDED_DEF, ZERO_EXTEND to ZERO_EXTENDED_DEF.
	(see_gen_normalized_extension): Change extension_code parameter to
	enum entry_type.
	(see_seek_pre_extension_expr): Change extension_code to enum
	entry_type.
	(see_merge_one_def_extension): Likewise.
	(see_handle_relevant_defs): Likewise.
	(see_handle_relevant_uses): Likewise.
	(see_analyze_one_def): Likewise.
	* tree-cfg.c (need_fake_edge_p): Compare gimple code with
	GIMPLE_ASM rather than ASM_EXPR.
	* tree-ssa-alias.c (is_escape_site): Compare gimple code with
	GIMPLE_RETURN rather than RETURN_EXPR.
	* tree-ssa-ccp.c (likely_value): Change code to enum gimple_code.
	(evaluate_stmt): Likewise.
	* tree-vect-analyze.c (vect_analyze_operations): Change relevance
	to enum vect_relevant.
	(vect_mark_stmts_to_be_vectorized): Change assertion to not
	compare gimple codes with tree codes.

gcc/cp/ChangeLog:
2008-09-03  Ian Lance Taylor  <iant@google.com>

	* parser.c (check_no_duplicate_clause): Change code parameter to
	enum omp_clause_code.

gcc/fortran/ChangeLog:
2008-09-03  Ian Lance Taylor  <iant@google.com>

	* symbol.c (generate_isocbinding_symbol): Compare
	gfc_notification_std with ERROR rather than FAILURE.
	* resolve.c (check_assumed_size_reference): Compare array type
	with AR_FULL rather than DIMEN_ELEMENT.
	(resolve_actual_arglist): Compare with EXPR_VARIABLE rather than
	FL_VARIABLE.


-Wenum-compare support:

-------------- next part --------------
A non-text attachment was scrubbed...
Name: foo1.patch
Type: text/x-patch
Size: 23064 bytes
Desc: Support for -Wenum-compare
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20080903/47943395/attachment.bin>
-------------- next part --------------


-Wenum-compare fixes:

-------------- next part --------------
A non-text attachment was scrubbed...
Name: foo.patch
Type: text/x-patch
Size: 16034 bytes
Desc: -Wenum-compare fixes
URL: <http://gcc.gnu.org/pipermail/fortran/attachments/20080903/47943395/attachment-0001.bin>


More information about the Fortran mailing list