Skip to content

Commit

Permalink
./:
Browse files Browse the repository at this point in the history
	* c-common.c (skip_evaluation): Don't define.
	(c_inhibit_evaluation_warnings): Define global variable.
	(overflow_warning): Check c_inhibit_evaluation_warnings rather
	than skip_evaluation.
	(convert_and_check, warn_for_div_by_zero): Likewise.
	* c-common.h (skip_evaluation): Don't declare.
	(c_inhibit_evaluation_warnings): Declare.
	* c-parser.c (c_parser_typeof_specifier): Set
	c_inhibit_evaluation_warnings rather than skip_evaluation.
	(c_parser_conditional_expression): Likewise.
	(c_parser_binary_expression): Likewise.
	(c_parser_sizeof_expression): Likewise.
	(c_parser_alignof_expression): Likewise.
	* c-typeck.c (build_indirect_ref): Check
	c_inhibit_evaluation_warnings rather than skip_evaluation.
	(build_conditional_expr, build_binary_op): Likewise.
cp/:
	* parser.c (cp_unevaluated_operand): Define global variable.
	(cp_parser_question_colon_clause): Increment
	c_inhibit_evaluation_warnings when evaluating an expression which
	will never be executed.
	(cp_parser_decltype): Increment cp_unevaluated_operand and
	c_inhibit_evaluation_warnings, not skip_evaluation.
	(cp_parser_sizeof_operand): Likewise.
	(cp_parser_enclosed_template_argument_list): Save
	cp_unevaluated_operand and c_inhibit_evaluation_warnings, not
	skip_evaluation.
	* cp-tree.h (struct saved_scope): Remove skip_evaluation field.
	Add unevaluated_operand and inhibit_evaluation_warnings fields.
	(cp_unevaluated_operand): Declare.
	* name-lookup.c (push_to_top_level): Save cp_unevaluated_operand
	and c_inhibit_evaluation_warnings rather than skip_evaluation.
	(pop_from_top_level): Restore cp_unevaluated_operand and
	c_inhibit_evaluation_warnings rather than skip_evaluation.
	* class.c (build_base_path): Check cp_unevaluated_operand rather
	than skip_evaluation.
	* typeck.c (build_class_member_access_expr): Likewise.
	(cp_build_binary_op): Don't warn about bad shift counts if
	c_inhibit_evaluation_warnings is non-zero.
	* pt.c (coerce_template_parms): Save state of
	cp_unevaluated_operand and c_inhibit_evaluation_warnings, not
	skip_evaluation.
	(tsubst_aggr_type): Likewise.
	(tsubst_pack_expansion): Check cp_unevaluated_operand rather than
	skip_evaluation.
	(tsubst_copy): Likewise.
	(tsubst): Set cp_unevaluated_operand and
	c_inhibit_evaluation_warnings, not skip_evaluation.
	(tsubst_copy_and_build): Likewise.
	* call.c (convert_arg_to_ellipsis): Check cp_unevaluated_operand
	rather than skip_evaluation.
	* decl2.c (mark_used): Likewise.
	* semantics.c (finish_non_static_data_member): Likewise.
	* cvt.c (cp_convert_and_check): Check
	c_inhibit_evaluation_warnings rather than skip_evaluation.
	* mangle.c (write_type): Set cp_unevaluated_operand rather than
	skip_evaluation.
testsuite/:
	* g++.dg/warn/skip-1.C: New testcase.


git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@148535 138bc75d-0d04-0410-961f-82ee72b054a4
  • Loading branch information
ian committed Jun 16, 2009
1 parent e8146f0 commit 48d94ed
Show file tree
Hide file tree
Showing 19 changed files with 231 additions and 82 deletions.
19 changes: 19 additions & 0 deletions gcc/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,22 @@
2009-06-16 Ian Lance Taylor <[email protected]>

* c-common.c (skip_evaluation): Don't define.
(c_inhibit_evaluation_warnings): Define global variable.
(overflow_warning): Check c_inhibit_evaluation_warnings rather
than skip_evaluation.
(convert_and_check, warn_for_div_by_zero): Likewise.
* c-common.h (skip_evaluation): Don't declare.
(c_inhibit_evaluation_warnings): Declare.
* c-parser.c (c_parser_typeof_specifier): Set
c_inhibit_evaluation_warnings rather than skip_evaluation.
(c_parser_conditional_expression): Likewise.
(c_parser_binary_expression): Likewise.
(c_parser_sizeof_expression): Likewise.
(c_parser_alignof_expression): Likewise.
* c-typeck.c (build_indirect_ref): Check
c_inhibit_evaluation_warnings rather than skip_evaluation.
(build_conditional_expr, build_binary_op): Likewise.

2009-06-16 Richard Guenther <[email protected]>

* tree-ssa-alias.c (is_escape_site): Remove.
Expand Down
15 changes: 9 additions & 6 deletions gcc/c-common.c
Original file line number Diff line number Diff line change
Expand Up @@ -442,9 +442,9 @@ tree *ridpointers;

tree (*make_fname_decl) (location_t, tree, int);

/* Nonzero means the expression being parsed will never be evaluated.
This is a count, since unevaluated expressions can nest. */
int skip_evaluation;
/* Nonzero means don't warn about problems that occur when the code is
executed. */
int c_inhibit_evaluation_warnings;

/* Whether lexing has been completed, so subsequent preprocessor
errors should use the compiler's input_location. */
Expand Down Expand Up @@ -1507,7 +1507,8 @@ constant_expression_error (tree value)
void
overflow_warning (location_t loc, tree value)
{
if (skip_evaluation) return;
if (c_inhibit_evaluation_warnings != 0)
return;

switch (TREE_CODE (value))
{
Expand Down Expand Up @@ -2225,7 +2226,9 @@ convert_and_check (tree type, tree expr)

result = convert (type, expr);

if (!skip_evaluation && !TREE_OVERFLOW_P (expr) && result != error_mark_node)
if (c_inhibit_evaluation_warnings == 0
&& !TREE_OVERFLOW_P (expr)
&& result != error_mark_node)
warnings_for_convert_and_check (type, expr_for_warning, result);

return result;
Expand Down Expand Up @@ -8952,7 +8955,7 @@ warn_for_div_by_zero (location_t loc, tree divisor)
about division by zero. Do not issue a warning if DIVISOR has a
floating-point type, since we consider 0.0/0.0 a valid way of
generating a NaN. */
if (skip_evaluation == 0
if (c_inhibit_evaluation_warnings == 0
&& (integer_zerop (divisor) || fixed_zerop (divisor)))
warning_at (loc, OPT_Wdiv_by_zero, "division by zero");
}
Expand Down
9 changes: 6 additions & 3 deletions gcc/c-common.h
Original file line number Diff line number Diff line change
Expand Up @@ -719,10 +719,13 @@ extern int warn_strict_null_sentinel;

extern int max_tinst_depth;

/* Nonzero means the expression being parsed will never be evaluated.
This is a count, since unevaluated expressions can nest. */
/* Nonzero means that we should not issue warnings about problems that
occur when the code is executed, because the code being processed
is not expected to be executed. This is set during parsing. This
is used for cases like sizeof() and "0 ? a : b". This is a count,
not a bool, because unexecuted expressions can nest. */

extern int skip_evaluation;
extern int c_inhibit_evaluation_warnings;

/* Whether lexing has been completed, so subsequent preprocessor
errors should use the compiler's input_location. */
Expand Down
53 changes: 29 additions & 24 deletions gcc/c-parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -2102,18 +2102,18 @@ c_parser_typeof_specifier (c_parser *parser)
ret.expr_const_operands = true;
gcc_assert (c_parser_next_token_is_keyword (parser, RID_TYPEOF));
c_parser_consume_token (parser);
skip_evaluation++;
c_inhibit_evaluation_warnings++;
in_typeof++;
if (!c_parser_require (parser, CPP_OPEN_PAREN, "expected %<(%>"))
{
skip_evaluation--;
c_inhibit_evaluation_warnings--;
in_typeof--;
return ret;
}
if (c_parser_next_token_starts_typename (parser))
{
struct c_type_name *type = c_parser_type_name (parser);
skip_evaluation--;
c_inhibit_evaluation_warnings--;
in_typeof--;
if (type != NULL)
{
Expand All @@ -2126,7 +2126,7 @@ c_parser_typeof_specifier (c_parser *parser)
bool was_vm;
location_t here = c_parser_peek_token (parser)->location;
struct c_expr expr = c_parser_expression (parser);
skip_evaluation--;
c_inhibit_evaluation_warnings--;
in_typeof--;
if (TREE_CODE (expr.value) == COMPONENT_REF
&& DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
Expand Down Expand Up @@ -4568,23 +4568,24 @@ c_parser_conditional_expression (c_parser *parser, struct c_expr *after)
exp1.value = build1 (EXCESS_PRECISION_EXPR, eptype, exp1.value);
exp1.original_type = NULL;
cond.value = c_objc_common_truthvalue_conversion (cond_loc, exp1.value);
skip_evaluation += cond.value == truthvalue_true_node;
c_inhibit_evaluation_warnings += cond.value == truthvalue_true_node;
}
else
{
cond.value
= c_objc_common_truthvalue_conversion
(cond_loc, default_conversion (cond.value));
skip_evaluation += cond.value == truthvalue_false_node;
c_inhibit_evaluation_warnings += cond.value == truthvalue_false_node;
exp1 = c_parser_expression_conv (parser);
skip_evaluation += ((cond.value == truthvalue_true_node)
- (cond.value == truthvalue_false_node));
c_inhibit_evaluation_warnings +=
((cond.value == truthvalue_true_node)
- (cond.value == truthvalue_false_node));
}

colon_loc = c_parser_peek_token (parser)->location;
if (!c_parser_require (parser, CPP_COLON, "expected %<:%>"))
{
skip_evaluation -= cond.value == truthvalue_true_node;
c_inhibit_evaluation_warnings -= cond.value == truthvalue_true_node;
ret.value = error_mark_node;
ret.original_code = ERROR_MARK;
ret.original_type = NULL;
Expand All @@ -4595,7 +4596,7 @@ c_parser_conditional_expression (c_parser *parser, struct c_expr *after)
exp2 = c_parser_conditional_expression (parser, NULL);
exp2 = default_function_array_conversion (exp2_loc, exp2);
}
skip_evaluation -= cond.value == truthvalue_true_node;
c_inhibit_evaluation_warnings -= cond.value == truthvalue_true_node;
ret.value = build_conditional_expr (colon_loc, cond.value,
cond.original_code == C_MAYBE_CONST_EXPR,
exp1.value, exp2.value);
Expand Down Expand Up @@ -4696,8 +4697,8 @@ c_parser_binary_expression (c_parser *parser, struct c_expr *after)
the stack has lower precedence than the new operator or there is
only one element on the stack; then the top expression is the LHS
of the new operator. In the case of logical AND and OR
expressions, we also need to adjust skip_evaluation as
appropriate when the operators are pushed and popped. */
expressions, we also need to adjust c_inhibit_evaluation_warnings
as appropriate when the operators are pushed and popped. */

/* The precedence levels, where 0 is a dummy lowest level used for
the bottom of the stack. */
Expand Down Expand Up @@ -4734,10 +4735,12 @@ c_parser_binary_expression (c_parser *parser, struct c_expr *after)
switch (stack[sp].op) \
{ \
case TRUTH_ANDIF_EXPR: \
skip_evaluation -= stack[sp - 1].expr.value == truthvalue_false_node; \
c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
== truthvalue_false_node); \
break; \
case TRUTH_ORIF_EXPR: \
skip_evaluation -= stack[sp - 1].expr.value == truthvalue_true_node; \
c_inhibit_evaluation_warnings -= (stack[sp - 1].expr.value \
== truthvalue_true_node); \
break; \
default: \
break; \
Expand Down Expand Up @@ -4855,15 +4858,17 @@ c_parser_binary_expression (c_parser *parser, struct c_expr *after)
stack[sp].expr);
stack[sp].expr.value = c_objc_common_truthvalue_conversion
(stack[sp].loc, default_conversion (stack[sp].expr.value));
skip_evaluation += stack[sp].expr.value == truthvalue_false_node;
c_inhibit_evaluation_warnings += (stack[sp].expr.value
== truthvalue_false_node);
break;
case TRUTH_ORIF_EXPR:
stack[sp].expr
= default_function_array_conversion (stack[sp].loc,
stack[sp].expr);
stack[sp].expr.value = c_objc_common_truthvalue_conversion
(stack[sp].loc, default_conversion (stack[sp].expr.value));
skip_evaluation += stack[sp].expr.value == truthvalue_true_node;
c_inhibit_evaluation_warnings += (stack[sp].expr.value
== truthvalue_true_node);
break;
default:
break;
Expand Down Expand Up @@ -5086,7 +5091,7 @@ c_parser_sizeof_expression (c_parser *parser)
location_t expr_loc;
gcc_assert (c_parser_next_token_is_keyword (parser, RID_SIZEOF));
c_parser_consume_token (parser);
skip_evaluation++;
c_inhibit_evaluation_warnings++;
in_sizeof++;
if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
&& c_token_starts_typename (c_parser_peek_2nd_token (parser)))
Expand All @@ -5101,7 +5106,7 @@ c_parser_sizeof_expression (c_parser *parser)
if (type_name == NULL)
{
struct c_expr ret;
skip_evaluation--;
c_inhibit_evaluation_warnings--;
in_sizeof--;
ret.value = error_mark_node;
ret.original_code = ERROR_MARK;
Expand All @@ -5116,7 +5121,7 @@ c_parser_sizeof_expression (c_parser *parser)
goto sizeof_expr;
}
/* sizeof ( type-name ). */
skip_evaluation--;
c_inhibit_evaluation_warnings--;
in_sizeof--;
return c_expr_sizeof_type (expr_loc, type_name);
}
Expand All @@ -5125,7 +5130,7 @@ c_parser_sizeof_expression (c_parser *parser)
expr_loc = c_parser_peek_token (parser)->location;
expr = c_parser_unary_expression (parser);
sizeof_expr:
skip_evaluation--;
c_inhibit_evaluation_warnings--;
in_sizeof--;
if (TREE_CODE (expr.value) == COMPONENT_REF
&& DECL_C_BIT_FIELD (TREE_OPERAND (expr.value, 1)))
Expand All @@ -5143,7 +5148,7 @@ c_parser_alignof_expression (c_parser *parser)
location_t loc = c_parser_peek_token (parser)->location;
gcc_assert (c_parser_next_token_is_keyword (parser, RID_ALIGNOF));
c_parser_consume_token (parser);
skip_evaluation++;
c_inhibit_evaluation_warnings++;
in_alignof++;
if (c_parser_next_token_is (parser, CPP_OPEN_PAREN)
&& c_token_starts_typename (c_parser_peek_2nd_token (parser)))
Expand All @@ -5160,7 +5165,7 @@ c_parser_alignof_expression (c_parser *parser)
if (type_name == NULL)
{
struct c_expr ret;
skip_evaluation--;
c_inhibit_evaluation_warnings--;
in_alignof--;
ret.value = error_mark_node;
ret.original_code = ERROR_MARK;
Expand All @@ -5175,7 +5180,7 @@ c_parser_alignof_expression (c_parser *parser)
goto alignof_expr;
}
/* alignof ( type-name ). */
skip_evaluation--;
c_inhibit_evaluation_warnings--;
in_alignof--;
ret.value = c_alignof (loc, groktypename (type_name, NULL, NULL));
ret.original_code = ERROR_MARK;
Expand All @@ -5187,7 +5192,7 @@ c_parser_alignof_expression (c_parser *parser)
struct c_expr ret;
expr = c_parser_unary_expression (parser);
alignof_expr:
skip_evaluation--;
c_inhibit_evaluation_warnings--;
in_alignof--;
ret.value = c_alignof_expr (loc, expr.value);
ret.original_code = ERROR_MARK;
Expand Down
14 changes: 7 additions & 7 deletions gcc/c-typeck.c
Original file line number Diff line number Diff line change
Expand Up @@ -2079,7 +2079,7 @@ build_indirect_ref (location_t loc, tree ptr, const char *errorstring)
error_at (loc, "dereferencing pointer to incomplete type");
return error_mark_node;
}
if (VOID_TYPE_P (t) && skip_evaluation == 0)
if (VOID_TYPE_P (t) && c_inhibit_evaluation_warnings == 0)
warning_at (loc, 0, "dereferencing %<void *%> pointer");

/* We *must* set TREE_READONLY when dereferencing a pointer to const,
Expand Down Expand Up @@ -3864,7 +3864,7 @@ build_conditional_expr (location_t colon_loc, tree ifexp, bool ifexp_bcp,
and later code won't know it used to be different.
Do this check on the original types, so that explicit casts
will be considered, but default promotions won't. */
if (!skip_evaluation)
if (c_inhibit_evaluation_warnings == 0)
{
int unsigned_op1 = TYPE_UNSIGNED (TREE_TYPE (orig_op1));
int unsigned_op2 = TYPE_UNSIGNED (TREE_TYPE (orig_op2));
Expand Down Expand Up @@ -9074,7 +9074,7 @@ build_binary_op (location_t location, enum tree_code code,
if (tree_int_cst_sgn (op1) < 0)
{
int_const = false;
if (skip_evaluation == 0)
if (c_inhibit_evaluation_warnings == 0)
warning (0, "right shift count is negative");
}
else
Expand All @@ -9085,7 +9085,7 @@ build_binary_op (location_t location, enum tree_code code,
if (compare_tree_int (op1, TYPE_PRECISION (type0)) >= 0)
{
int_const = false;
if (skip_evaluation == 0)
if (c_inhibit_evaluation_warnings == 0)
warning (0, "right shift count >= width of type");
}
}
Expand All @@ -9111,14 +9111,14 @@ build_binary_op (location_t location, enum tree_code code,
if (tree_int_cst_sgn (op1) < 0)
{
int_const = false;
if (skip_evaluation == 0)
if (c_inhibit_evaluation_warnings == 0)
warning (0, "left shift count is negative");
}

else if (compare_tree_int (op1, TYPE_PRECISION (type0)) >= 0)
{
int_const = false;
if (skip_evaluation == 0)
if (c_inhibit_evaluation_warnings == 0)
warning (0, "left shift count >= width of type");
}
}
Expand Down Expand Up @@ -9458,7 +9458,7 @@ build_binary_op (location_t location, enum tree_code code,
converted = 1;
resultcode = xresultcode;

if (!skip_evaluation)
if (c_inhibit_evaluation_warnings == 0)
{
bool op0_maybe_const = true;
bool op1_maybe_const = true;
Expand Down
43 changes: 43 additions & 0 deletions gcc/cp/ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,46 @@
2009-06-16 Ian Lance Taylor <[email protected]>

* parser.c (cp_unevaluated_operand): Define global variable.
(cp_parser_question_colon_clause): Increment
c_inhibit_evaluation_warnings when evaluating an expression which
will never be executed.
(cp_parser_decltype): Increment cp_unevaluated_operand and
c_inhibit_evaluation_warnings, not skip_evaluation.
(cp_parser_sizeof_operand): Likewise.
(cp_parser_enclosed_template_argument_list): Save
cp_unevaluated_operand and c_inhibit_evaluation_warnings, not
skip_evaluation.
* cp-tree.h (struct saved_scope): Remove skip_evaluation field.
Add unevaluated_operand and inhibit_evaluation_warnings fields.
(cp_unevaluated_operand): Declare.
* name-lookup.c (push_to_top_level): Save cp_unevaluated_operand
and c_inhibit_evaluation_warnings rather than skip_evaluation.
(pop_from_top_level): Restore cp_unevaluated_operand and
c_inhibit_evaluation_warnings rather than skip_evaluation.
* class.c (build_base_path): Check cp_unevaluated_operand rather
than skip_evaluation.
* typeck.c (build_class_member_access_expr): Likewise.
(cp_build_binary_op): Don't warn about bad shift counts if
c_inhibit_evaluation_warnings is non-zero.
* pt.c (coerce_template_parms): Save state of
cp_unevaluated_operand and c_inhibit_evaluation_warnings, not
skip_evaluation.
(tsubst_aggr_type): Likewise.
(tsubst_pack_expansion): Check cp_unevaluated_operand rather than
skip_evaluation.
(tsubst_copy): Likewise.
(tsubst): Set cp_unevaluated_operand and
c_inhibit_evaluation_warnings, not skip_evaluation.
(tsubst_copy_and_build): Likewise.
* call.c (convert_arg_to_ellipsis): Check cp_unevaluated_operand
rather than skip_evaluation.
* decl2.c (mark_used): Likewise.
* semantics.c (finish_non_static_data_member): Likewise.
* cvt.c (cp_convert_and_check): Check
c_inhibit_evaluation_warnings rather than skip_evaluation.
* mangle.c (write_type): Set cp_unevaluated_operand rather than
skip_evaluation.

2009-06-15 Ian Lance Taylor <[email protected]>

* parser.c (cp_parser_direct_declarator): Add braces around
Expand Down
2 changes: 1 addition & 1 deletion gcc/cp/call.c
Original file line number Diff line number Diff line change
Expand Up @@ -5064,7 +5064,7 @@ convert_arg_to_ellipsis (tree arg)
If the call appears in the context of a sizeof expression,
there is no need to emit a warning, since the expression won't be
evaluated. We keep the builtin_trap just as a safety check. */
if (!skip_evaluation)
if (cp_unevaluated_operand == 0)
warning (0, "cannot pass objects of non-POD type %q#T through %<...%>; "
"call will abort at runtime", TREE_TYPE (arg));
arg = call_builtin_trap ();
Expand Down
2 changes: 1 addition & 1 deletion gcc/cp/class.c
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ build_base_path (enum tree_code code,

/* Don't bother with the calculations inside sizeof; they'll ICE if the
source type is incomplete and the pointer value doesn't matter. */
if (skip_evaluation)
if (cp_unevaluated_operand != 0)
{
expr = build_nop (build_pointer_type (target_type), expr);
if (!want_pointer)
Expand Down
Loading

0 comments on commit 48d94ed

Please sign in to comment.