Commit 68fca595 by Marek Polacek Committed by Marek Polacek

re PR c/59940 (Imprecise column number for -Wconversion)

	PR c/59940
c-family/
	* c-common.h (unsafe_conversion_p): Adjust declaration.
	(warnings_for_convert_and_check): Likewise.
	(convert_and_check): Likewise.
	* c-common.c (unsafe_conversion_p): Add location parameter.  Call
	expansion_point_location_if_in_system_header on it.
	(warnings_for_convert_and_check): Add location parameter.  Call
	expansion_point_location_if_in_system_header on it.  Use it.
	(convert_and_check): Add location parameter.  Use it.
	(conversion_warning): Likewise.
	(c_add_case_label): Adjust convert_and_check calls.
	(scalar_to_vector): Adjust unsafe_conversion_p calls.
cp/
	* typeck.c (build_ptrmemfunc1): Call convert_and_check with
	input_location.
	* cvt.c (cp_convert_and_check): Call warnings_for_convert_and_check
	with input_location.
	* call.c (build_conditional_expr_1): Call unsafe_conversion_p with
	loc parameter.
c/
	* c-typeck.c (build_function_call_vec): Use loc parameter.
	(convert_arguments): Add location parameter.  Use it.
	(ep_convert_and_check): Likewise.
	(build_atomic_assign): Adjust convert_for_assignment call.
	(build_modify_expr): Likewise.
	(digest_init): Likewise.
	(c_finish_return): Likewise.
	(build_conditional_expr): Adjust ep_convert_and_check calls.
	(convert_for_assignment): Add rhs_loc parameter.  Use it.
	(build_binary_op): Adjust convert_and_check and ep_convert_and_check
	calls.
testsuite/
	* gcc.dg/pr59940.c: New test.
	* gcc.dg/pr35635.c (func3): Move dg-warning.

From-SVN: r207309
parent 2d70f6d4
2014-01-30 Marek Polacek <polacek@redhat.com>
PR c/59940
* c-common.h (unsafe_conversion_p): Adjust declaration.
(warnings_for_convert_and_check): Likewise.
(convert_and_check): Likewise.
* c-common.c (unsafe_conversion_p): Add location parameter. Call
expansion_point_location_if_in_system_header on it.
(warnings_for_convert_and_check): Add location parameter. Call
expansion_point_location_if_in_system_header on it. Use it.
(convert_and_check): Add location parameter. Use it.
(conversion_warning): Likewise.
(c_add_case_label): Adjust convert_and_check calls.
(scalar_to_vector): Adjust unsafe_conversion_p calls.
2014-01-24 Balaji V. Iyer <balaji.v.iyer@intel.com>
* c-common.c (c_define_builtins): Replaced flag_enable_cilkplus with
......
......@@ -2526,23 +2526,24 @@ shorten_binary_op (tree result_type, tree op0, tree op1, bool bitwise)
return result_type;
}
/* Checks if expression EXPR of real/integer type cannot be converted
/* Checks if expression EXPR of real/integer type cannot be converted
to the real/integer type TYPE. Function returns non-zero when:
* EXPR is a constant which cannot be exactly converted to TYPE
* EXPR is not a constant and size of EXPR's type > than size of TYPE,
* EXPR is a constant which cannot be exactly converted to TYPE.
* EXPR is not a constant and size of EXPR's type > than size of TYPE,
for EXPR type and TYPE being both integers or both real.
* EXPR is not a constant of real type and TYPE is an integer.
* EXPR is not a constant of integer type which cannot be
exactly converted to real type.
* EXPR is not a constant of real type and TYPE is an integer.
* EXPR is not a constant of integer type which cannot be
exactly converted to real type.
Function allows conversions between types of different signedness and
can return SAFE_CONVERSION (zero) in that case. Function can produce
signedness warnings if PRODUCE_WARNS is true. */
enum conversion_safety
unsafe_conversion_p (tree type, tree expr, bool produce_warns)
unsafe_conversion_p (location_t loc, tree type, tree expr, bool produce_warns)
{
enum conversion_safety give_warning = SAFE_CONVERSION; /* is 0 or false */
tree expr_type = TREE_TYPE (expr);
location_t loc = EXPR_LOC_OR_LOC (expr, input_location);
loc = expansion_point_location_if_in_system_header (loc);
if (TREE_CODE (expr) == REAL_CST || TREE_CODE (expr) == INTEGER_CST)
{
......@@ -2705,10 +2706,9 @@ unsafe_conversion_p (tree type, tree expr, bool produce_warns)
This is a helper function for warnings_for_convert_and_check. */
static void
conversion_warning (tree type, tree expr)
conversion_warning (location_t loc, tree type, tree expr)
{
tree expr_type = TREE_TYPE (expr);
location_t loc = EXPR_LOC_OR_LOC (expr, input_location);
enum conversion_safety conversion_kind;
if (!warn_conversion && !warn_sign_conversion && !warn_float_conversion)
......@@ -2738,7 +2738,7 @@ conversion_warning (tree type, tree expr)
case REAL_CST:
case INTEGER_CST:
conversion_kind = unsafe_conversion_p (type, expr, true);
conversion_kind = unsafe_conversion_p (loc, type, expr, true);
if (conversion_kind == UNSAFE_REAL)
warning_at (loc, OPT_Wfloat_conversion,
"conversion to %qT alters %qT constant value",
......@@ -2756,13 +2756,13 @@ conversion_warning (tree type, tree expr)
tree op1 = TREE_OPERAND (expr, 1);
tree op2 = TREE_OPERAND (expr, 2);
conversion_warning (type, op1);
conversion_warning (type, op2);
conversion_warning (loc, type, op1);
conversion_warning (loc, type, op2);
return;
}
default: /* 'expr' is not a constant. */
conversion_kind = unsafe_conversion_p (type, expr, true);
conversion_kind = unsafe_conversion_p (loc, type, expr, true);
if (conversion_kind == UNSAFE_REAL)
warning_at (loc, OPT_Wfloat_conversion,
"conversion to %qT from %qT may alter its value",
......@@ -2779,9 +2779,10 @@ conversion_warning (tree type, tree expr)
convert_and_check and cp_convert_and_check. */
void
warnings_for_convert_and_check (tree type, tree expr, tree result)
warnings_for_convert_and_check (location_t loc, tree type, tree expr,
tree result)
{
location_t loc = EXPR_LOC_OR_LOC (expr, input_location);
loc = expansion_point_location_if_in_system_header (loc);
if (TREE_CODE (expr) == INTEGER_CST
&& (TREE_CODE (type) == INTEGER_TYPE
......@@ -2801,10 +2802,10 @@ warnings_for_convert_and_check (tree type, tree expr, tree result)
warning_at (loc, OPT_Woverflow,
"large integer implicitly truncated to unsigned type");
else
conversion_warning (type, expr);
conversion_warning (loc, type, expr);
}
else if (!int_fits_type_p (expr, c_common_unsigned_type (type)))
warning (OPT_Woverflow,
warning_at (loc, OPT_Woverflow,
"overflow in implicit constant conversion");
/* No warning for converting 0x80000000 to int. */
else if (pedantic
......@@ -2815,14 +2816,14 @@ warnings_for_convert_and_check (tree type, tree expr, tree result)
"overflow in implicit constant conversion");
else
conversion_warning (type, expr);
conversion_warning (loc, type, expr);
}
else if ((TREE_CODE (result) == INTEGER_CST
|| TREE_CODE (result) == FIXED_CST) && TREE_OVERFLOW (result))
warning_at (loc, OPT_Woverflow,
"overflow in implicit constant conversion");
else
conversion_warning (type, expr);
conversion_warning (loc, type, expr);
}
......@@ -2831,7 +2832,7 @@ warnings_for_convert_and_check (tree type, tree expr, tree result)
i.e. because of language rules and not because of an explicit cast. */
tree
convert_and_check (tree type, tree expr)
convert_and_check (location_t loc, tree type, tree expr)
{
tree result;
tree expr_for_warning;
......@@ -2858,7 +2859,7 @@ convert_and_check (tree type, tree expr)
if (c_inhibit_evaluation_warnings == 0
&& !TREE_OVERFLOW_P (expr)
&& result != error_mark_node)
warnings_for_convert_and_check (type, expr_for_warning, result);
warnings_for_convert_and_check (loc, type, expr_for_warning, result);
return result;
}
......@@ -5960,14 +5961,14 @@ c_add_case_label (location_t loc, splay_tree cases, tree cond, tree orig_type,
if (low_value)
{
low_value = check_case_value (low_value);
low_value = convert_and_check (type, low_value);
low_value = convert_and_check (loc, type, low_value);
if (low_value == error_mark_node)
goto error_out;
}
if (high_value)
{
high_value = check_case_value (high_value);
high_value = convert_and_check (type, high_value);
high_value = convert_and_check (loc, type, high_value);
if (high_value == error_mark_node)
goto error_out;
}
......@@ -11725,7 +11726,7 @@ scalar_to_vector (location_t loc, enum tree_code code, tree op0, tree op1,
if (TREE_CODE (type0) == INTEGER_TYPE
&& TREE_CODE (TREE_TYPE (type1)) == INTEGER_TYPE)
{
if (unsafe_conversion_p (TREE_TYPE (type1), op0, false))
if (unsafe_conversion_p (loc, TREE_TYPE (type1), op0, false))
{
if (complain)
error_at (loc, "conversion of scalar %qT to vector %qT "
......@@ -11775,7 +11776,7 @@ scalar_to_vector (location_t loc, enum tree_code code, tree op0, tree op1,
if (TREE_CODE (type0) == INTEGER_TYPE
&& TREE_CODE (TREE_TYPE (type1)) == INTEGER_TYPE)
{
if (unsafe_conversion_p (TREE_TYPE (type1), op0, false))
if (unsafe_conversion_p (loc, TREE_TYPE (type1), op0, false))
{
if (complain)
error_at (loc, "conversion of scalar %qT to vector %qT "
......@@ -11790,7 +11791,7 @@ scalar_to_vector (location_t loc, enum tree_code code, tree op0, tree op1,
|| TREE_CODE (type0) == INTEGER_TYPE)
&& SCALAR_FLOAT_TYPE_P (TREE_TYPE (type1)))
{
if (unsafe_conversion_p (TREE_TYPE (type1), op0, false))
if (unsafe_conversion_p (loc, TREE_TYPE (type1), op0, false))
{
if (complain)
error_at (loc, "conversion of scalar %qT to vector %qT "
......
......@@ -749,7 +749,8 @@ extern tree c_common_signed_type (tree);
extern tree c_common_signed_or_unsigned_type (int, tree);
extern void c_common_init_ts (void);
extern tree c_build_bitfield_integer_type (unsigned HOST_WIDE_INT, int);
extern enum conversion_safety unsafe_conversion_p (tree, tree, bool);
extern enum conversion_safety unsafe_conversion_p (location_t, tree, tree,
bool);
extern bool decl_with_nonnull_addr_p (const_tree);
extern tree c_fully_fold (tree, bool, bool *);
extern tree decl_constant_value_for_optimization (tree);
......@@ -769,8 +770,8 @@ extern bool strict_aliasing_warning (tree, tree, tree);
extern void sizeof_pointer_memaccess_warning (location_t *, tree,
vec<tree, va_gc> *, tree *,
bool (*) (tree, tree));
extern void warnings_for_convert_and_check (tree, tree, tree);
extern tree convert_and_check (tree, tree);
extern void warnings_for_convert_and_check (location_t, tree, tree, tree);
extern tree convert_and_check (location_t, tree, tree);
extern void overflow_warning (location_t, tree);
extern bool warn_if_unused_value (const_tree, location_t);
extern void warn_logical_operator (location_t, enum tree_code, tree,
......
2014-01-30 Marek Polacek <polacek@redhat.com>
PR c/59940
* c-typeck.c (build_function_call_vec): Use loc parameter.
(convert_arguments): Add location parameter. Use it.
(ep_convert_and_check): Likewise.
(build_atomic_assign): Adjust convert_for_assignment call.
(build_modify_expr): Likewise.
(digest_init): Likewise.
(c_finish_return): Likewise.
(build_conditional_expr): Adjust ep_convert_and_check calls.
(convert_for_assignment): Add rhs_loc parameter. Use it.
(build_binary_op): Adjust convert_and_check and ep_convert_and_check
calls.
2014-01-30 Richard Biener <rguenther@suse.de>
PR c/59905
......
2014-01-30 Marek Polacek <polacek@redhat.com>
PR c/59940
* typeck.c (build_ptrmemfunc1): Call convert_and_check with
input_location.
* cvt.c (cp_convert_and_check): Call warnings_for_convert_and_check
with input_location.
* call.c (build_conditional_expr_1): Call unsafe_conversion_p with
loc parameter.
2014-01-30 Paolo Carlini <paolo.carlini@oracle.com>
PR c++/58843
......
......@@ -4484,14 +4484,14 @@ build_conditional_expr_1 (location_t loc, tree arg1, tree arg2, tree arg3,
but the warnings (like Wsign-conversion) have already been
given by the scalar build_conditional_expr_1. We still check
unsafe_conversion_p to forbid truncating long long -> float. */
if (unsafe_conversion_p (stype, arg2, false))
if (unsafe_conversion_p (loc, stype, arg2, false))
{
if (complain & tf_error)
error_at (loc, "conversion of scalar %qT to vector %qT "
"involves truncation", arg2_type, vtype);
return error_mark_node;
}
if (unsafe_conversion_p (stype, arg3, false))
if (unsafe_conversion_p (loc, stype, arg3, false))
{
if (complain & tf_error)
error_at (loc, "conversion of scalar %qT to vector %qT "
......
......@@ -639,7 +639,8 @@ cp_convert_and_check (tree type, tree expr, tsubst_flags_t complain)
if (!TREE_OVERFLOW_P (stripped)
&& folded_result != error_mark_node)
warnings_for_convert_and_check (type, folded, folded_result);
warnings_for_convert_and_check (input_location, type, folded,
folded_result);
}
return result;
......
......@@ -7715,7 +7715,7 @@ build_ptrmemfunc1 (tree type, tree delta, tree pfn)
delta_field = DECL_CHAIN (pfn_field);
/* Make sure DELTA has the type we want. */
delta = convert_and_check (delta_type_node, delta);
delta = convert_and_check (input_location, delta_type_node, delta);
/* Convert to the correct target type if necessary. */
pfn = fold_convert (TREE_TYPE (pfn_field), pfn);
......
2014-01-30 Marek Polacek <polacek@redhat.com>
PR c/59940
* gcc.dg/pr59940.c: New test.
* gcc.dg/pr35635.c (func3): Move dg-warning.
2014-01-30 Richard Biener <rguenther@suse.de>
PR tree-optimization/59903
......
......@@ -62,9 +62,9 @@ void func3()
/* At least one branch of ? does not fit in the destination, thus
warn. */
uchar_x = bar != 0 ? 2.1 : 10; /* { dg-warning "conversion" } */
uchar_x = bar != 0
uchar_x = bar != 0 /* { dg-warning "negative integer implicitly converted to unsigned type" } */
? (unsigned char) 1024
: -1; /* { dg-warning "negative integer implicitly converted to unsigned type" } */
: -1;
}
void func4()
......
/* PR c/59940 */
/* { dg-do compile } */
/* { dg-options "-Wconversion -Woverflow" } */
int f (unsigned int);
int
g (void)
{
int si = 12;
unsigned int ui = -1; /* { dg-warning "21:negative integer implicitly converted to unsigned type" } */
unsigned char uc;
ui = si; /* { dg-warning "8:conversion" } */
si = 0x80000000; /* { dg-warning "8:conversion of unsigned constant value to negative integer" } */
si = 3.2f; /* { dg-warning "8:conversion" } */
uc = 256; /* { dg-warning "8:large integer implicitly truncated to unsigned type" } */
si = 0x800000000; /* { dg-warning "8:overflow in implicit constant conversion" } */
return f (si) /* { dg-warning "12:conversion" } */
+ f (si); /* { dg-warning "14:conversion" } */
}
int
y (void)
{
f (); /* { dg-error "5:too few arguments to function" } */
g (0xa); /* { dg-error "5:too many arguments to function" } */
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment