Commit 296c53ac by Marek Polacek Committed by Marek Polacek

re PR c/81233 (--Wdiscarded-qualifiers and Wincompatible-pointer-types missing important detail)

	PR c/81233
	* c-typeck.c (pedwarn_init): Make the function take a variable list.
	Call emit_diagnostic_valist instead of pedwarn.
	(convert_for_assignment): Unroll the PEDWARN_FOR_ASSIGNMENT macro.
	Print the relevant types in diagnostics.

	* diagnostic-core.h (emit_diagnostic_valist): Add declaration.
	* diagnostic.c (emit_diagnostic): Add a comment.
	(emit_diagnostic_valist): New function.

	* gcc.dg/diagnostic-types-1.c: New test.
	* gcc.dg/assign-warn-1.c: Update warning messages.
	* gcc.dg/assign-warn-2.c: Likewise.
	* gcc.dg/c90-const-expr-5.c: Likewise.
	* gcc.dg/c99-const-expr-5.c: Likewise.
	* gcc.dg/conv-2.c: Likewise.
	* gcc.dg/init-bad-7.c: Likewise.
	* gcc.dg/overflow-warn-1.c: Likewise.
	* gcc.dg/overflow-warn-2.c: Likewise.
	* gcc.dg/overflow-warn-3.c: Likewise.
	* gcc.dg/overflow-warn-4.c: Likewise.
	* gcc.dg/pointer-array-atomic.c: Likewise.
	* gcc.dg/pr26865.c: Likewise.
	* gcc.dg/pr61162-2.c: Likewise.
	* gcc.dg/pr61162.c: Likewise.
	* gcc.dg/pr67730-2.c: Likewise.
	* gcc.dg/pr69156.c: Likewise.
	* gcc.dg/pr70174.c: Likewise.
	* objc.dg/proto-lossage-4.m: Likewise.

From-SVN: r250985
parent a32c8316
2017-08-09 Marek Polacek <polacek@redhat.com>
PR c/81233
* diagnostic-core.h (emit_diagnostic_valist): Add declaration.
* diagnostic.c (emit_diagnostic): Add a comment.
(emit_diagnostic_valist): New function.
2017-08-09 Marek Polacek <polacek@redhat.com>
PR c/81417
* input.c (make_location): New overload.
* input.h (make_location): Declare.
......
2017-08-09 Marek Polacek <polacek@redhat.com>
PR c/81233
* c-typeck.c (pedwarn_init): Make the function take a variable list.
Call emit_diagnostic_valist instead of pedwarn.
(convert_for_assignment): Unroll the PEDWARN_FOR_ASSIGNMENT macro.
Print the relevant types in diagnostics.
2017-08-09 Marek Polacek <polacek@redhat.com>
PR c/81417
* c-array-notation.c (fix_builtin_array_notation_fn): Update calls to
build_conditional_expr.
......
......@@ -6065,20 +6065,19 @@ error_init (location_t loc, const char *gmsgid)
it is unconditionally given. GMSGID identifies the message. The
component name is taken from the spelling stack. */
static void
pedwarn_init (location_t loc, int opt, const char *gmsgid)
static void ATTRIBUTE_GCC_DIAG (3,0)
pedwarn_init (location_t loc, int opt, const char *gmsgid, ...)
{
char *ofwhat;
bool warned;
/* Use the location where a macro was expanded rather than where
it was defined to make sure macros defined in system headers
but used incorrectly elsewhere are diagnosed. */
source_location exploc = expansion_point_location_if_in_system_header (loc);
/* The gmsgid may be a format string with %< and %>. */
warned = pedwarn (exploc, opt, gmsgid);
ofwhat = print_spelling ((char *) alloca (spelling_length () + 1));
va_list ap;
va_start (ap, gmsgid);
bool warned = emit_diagnostic_valist (DK_PEDWARN, exploc, opt, gmsgid, &ap);
va_end (ap);
char *ofwhat = print_spelling ((char *) alloca (spelling_length () + 1));
if (*ofwhat && warned)
inform (exploc, "(near initialization for %qs)", ofwhat);
}
......@@ -6311,17 +6310,33 @@ convert_for_assignment (location_t location, location_t expr_loc, tree type,
if (checktype != error_mark_node
&& TREE_CODE (type) == ENUMERAL_TYPE
&& TYPE_MAIN_VARIANT (checktype) != TYPE_MAIN_VARIANT (type))
{
PEDWARN_FOR_ASSIGNMENT (location, expr_loc, OPT_Wc___compat,
G_("enum conversion when passing argument "
"%d of %qE is invalid in C++"),
G_("enum conversion in assignment is "
"invalid in C++"),
G_("enum conversion in initialization is "
"invalid in C++"),
G_("enum conversion in return is "
"invalid in C++"));
}
switch (errtype)
{
case ic_argpass:
if (pedwarn (expr_loc, OPT_Wc___compat, "enum conversion when "
"passing argument %d of %qE is invalid in C++",
parmnum, rname))
inform ((fundecl && !DECL_IS_BUILTIN (fundecl))
? DECL_SOURCE_LOCATION (fundecl) : expr_loc,
"expected %qT but argument is of type %qT",
type, rhstype);
break;
case ic_assign:
pedwarn (location, OPT_Wc___compat, "enum conversion from %qT to "
"%qT in assignment is invalid in C++", rhstype, type);
break;
case ic_init:
pedwarn_init (location, OPT_Wc___compat, "enum conversion from "
"%qT to %qT in initialization is invalid in C++",
rhstype, type);
break;
case ic_return:
pedwarn (location, OPT_Wc___compat, "enum conversion from %qT to "
"%qT in return is invalid in C++", rhstype, type);
break;
default:
gcc_unreachable ();
}
}
if (TYPE_MAIN_VARIANT (type) == TYPE_MAIN_VARIANT (rhstype))
......@@ -6727,15 +6742,36 @@ convert_for_assignment (location_t location, location_t expr_loc, tree type,
;
/* If there is a mismatch, do warn. */
else if (warn_pointer_sign)
PEDWARN_FOR_ASSIGNMENT (location, expr_loc, OPT_Wpointer_sign,
G_("pointer targets in passing argument "
"%d of %qE differ in signedness"),
G_("pointer targets in assignment "
"differ in signedness"),
G_("pointer targets in initialization "
"differ in signedness"),
G_("pointer targets in return differ "
"in signedness"));
switch (errtype)
{
case ic_argpass:
if (pedwarn (expr_loc, OPT_Wpointer_sign,
"pointer targets in passing argument %d of "
"%qE differ in signedness", parmnum, rname))
inform ((fundecl && !DECL_IS_BUILTIN (fundecl))
? DECL_SOURCE_LOCATION (fundecl) : expr_loc,
"expected %qT but argument is of type %qT",
type, rhstype);
break;
case ic_assign:
pedwarn (location, OPT_Wpointer_sign,
"pointer targets in assignment from %qT to %qT "
"differ in signedness", rhstype, type);
break;
case ic_init:
pedwarn_init (location, OPT_Wpointer_sign,
"pointer targets in initialization of %qT "
"from %qT differ in signedness", type,
rhstype);
break;
case ic_return:
pedwarn (location, OPT_Wpointer_sign, "pointer targets in "
"returning %qT from a function with return type "
"%qT differ in signedness", rhstype, type);
break;
default:
gcc_unreachable ();
}
}
else if (TREE_CODE (ttl) == FUNCTION_TYPE
&& TREE_CODE (ttr) == FUNCTION_TYPE)
......@@ -6760,17 +6796,39 @@ convert_for_assignment (location_t location, location_t expr_loc, tree type,
TYPE_QUALS (ttl) & ~TYPE_QUALS (ttr));
}
}
else
/* Avoid warning about the volatile ObjC EH puts on decls. */
if (!objc_ok)
PEDWARN_FOR_ASSIGNMENT (location, expr_loc,
OPT_Wincompatible_pointer_types,
G_("passing argument %d of %qE from "
"incompatible pointer type"),
G_("assignment from incompatible pointer type"),
G_("initialization from incompatible "
"pointer type"),
G_("return from incompatible pointer type"));
/* Avoid warning about the volatile ObjC EH puts on decls. */
else if (!objc_ok)
{
switch (errtype)
{
case ic_argpass:
if (pedwarn (expr_loc, OPT_Wincompatible_pointer_types,
"passing argument %d of %qE from incompatible "
"pointer type", parmnum, rname))
inform ((fundecl && !DECL_IS_BUILTIN (fundecl))
? DECL_SOURCE_LOCATION (fundecl) : expr_loc,
"expected %qT but argument is of type %qT",
type, rhstype);
break;
case ic_assign:
pedwarn (location, OPT_Wincompatible_pointer_types,
"assignment to %qT from incompatible pointer type %qT",
type, rhstype);
break;
case ic_init:
pedwarn_init (location, OPT_Wincompatible_pointer_types,
"initialization of %qT from incompatible pointer "
"type %qT", type, rhstype);
break;
case ic_return:
pedwarn (location, OPT_Wincompatible_pointer_types,
"returning %qT from a function with incompatible "
"return type %qT", rhstype, type);
break;
default:
gcc_unreachable ();
}
}
return convert (type, rhs);
}
......@@ -6787,31 +6845,70 @@ convert_for_assignment (location_t location, location_t expr_loc, tree type,
or one that results from arithmetic, even including
a cast to integer type. */
if (!null_pointer_constant)
PEDWARN_FOR_ASSIGNMENT (location, expr_loc,
OPT_Wint_conversion,
G_("passing argument %d of %qE makes "
"pointer from integer without a cast"),
G_("assignment makes pointer from integer "
"without a cast"),
G_("initialization makes pointer from "
"integer without a cast"),
G_("return makes pointer from integer "
"without a cast"));
switch (errtype)
{
case ic_argpass:
if (pedwarn (expr_loc, OPT_Wint_conversion,
"passing argument %d of %qE makes pointer from "
"integer without a cast", parmnum, rname))
inform ((fundecl && !DECL_IS_BUILTIN (fundecl))
? DECL_SOURCE_LOCATION (fundecl) : expr_loc,
"expected %qT but argument is of type %qT",
type, rhstype);
break;
case ic_assign:
pedwarn (location, OPT_Wint_conversion,
"assignment to %qT from %qT makes pointer from integer "
"without a cast", type, rhstype);
break;
case ic_init:
pedwarn_init (location, OPT_Wint_conversion,
"initialization of %qT from %qT makes pointer from "
"integer without a cast", type, rhstype);
break;
case ic_return:
pedwarn (location, OPT_Wint_conversion, "returning %qT from a "
"function with return type %qT makes pointer from "
"integer without a cast", rhstype, type);
break;
default:
gcc_unreachable ();
}
return convert (type, rhs);
}
else if (codel == INTEGER_TYPE && coder == POINTER_TYPE)
{
PEDWARN_FOR_ASSIGNMENT (location, expr_loc,
OPT_Wint_conversion,
G_("passing argument %d of %qE makes integer "
"from pointer without a cast"),
G_("assignment makes integer from pointer "
"without a cast"),
G_("initialization makes integer from pointer "
"without a cast"),
G_("return makes integer from pointer "
"without a cast"));
switch (errtype)
{
case ic_argpass:
if (pedwarn (expr_loc, OPT_Wint_conversion,
"passing argument %d of %qE makes integer from "
"pointer without a cast", parmnum, rname))
inform ((fundecl && !DECL_IS_BUILTIN (fundecl))
? DECL_SOURCE_LOCATION (fundecl) : expr_loc,
"expected %qT but argument is of type %qT",
type, rhstype);
break;
case ic_assign:
pedwarn (location, OPT_Wint_conversion,
"assignment to %qT from %qT makes integer from pointer "
"without a cast", type, rhstype);
break;
case ic_init:
pedwarn_init (location, OPT_Wint_conversion,
"initialization of %qT from %qT makes integer from "
"pointer without a cast", type, rhstype);
break;
case ic_return:
pedwarn (location, OPT_Wint_conversion, "returning %qT from a "
"function with return type %qT makes integer from "
"pointer without a cast", rhstype, type);
break;
default:
gcc_unreachable ();
}
return convert (type, rhs);
}
else if (codel == BOOLEAN_TYPE && coder == POINTER_TYPE)
......
......@@ -93,6 +93,8 @@ extern void inform_n (location_t, int, const char *, const char *, ...)
extern void verbatim (const char *, ...) ATTRIBUTE_GCC_DIAG(1,2);
extern bool emit_diagnostic (diagnostic_t, location_t, int,
const char *, ...) ATTRIBUTE_GCC_DIAG(4,5);
extern bool emit_diagnostic_valist (diagnostic_t, location_t, int, const char *,
va_list *) ATTRIBUTE_GCC_DIAG (4,0);
extern bool seen_error (void);
#ifdef BUFSIZ
......
......@@ -1128,6 +1128,8 @@ diagnostic_n_impl (location_t location, int opt, int n,
singular_gmsgid, plural_gmsgid, ap, kind);
}
/* Wrapper around diagnostic_impl taking a variable argument list. */
bool
emit_diagnostic (diagnostic_t kind, location_t location, int opt,
const char *gmsgid, ...)
......@@ -1140,6 +1142,16 @@ emit_diagnostic (diagnostic_t kind, location_t location, int opt,
return ret;
}
/* Wrapper around diagnostic_impl taking a va_list parameter. */
bool
emit_diagnostic_valist (diagnostic_t kind, location_t location, int opt,
const char *gmsgid, va_list *ap)
{
rich_location richloc (line_table, location);
return diagnostic_impl (&richloc, opt, gmsgid, ap, kind);
}
/* An informative note at LOCATION. Use this for additional details on an error
message. */
void
......
2017-08-09 Marek Polacek <polacek@redhat.com>
PR c/81233
* gcc.dg/diagnostic-types-1.c: New test.
* gcc.dg/assign-warn-1.c: Update warning messages.
* gcc.dg/assign-warn-2.c: Likewise.
* gcc.dg/c90-const-expr-5.c: Likewise.
* gcc.dg/c99-const-expr-5.c: Likewise.
* gcc.dg/conv-2.c: Likewise.
* gcc.dg/init-bad-7.c: Likewise.
* gcc.dg/overflow-warn-1.c: Likewise.
* gcc.dg/overflow-warn-2.c: Likewise.
* gcc.dg/overflow-warn-3.c: Likewise.
* gcc.dg/overflow-warn-4.c: Likewise.
* gcc.dg/pointer-array-atomic.c: Likewise.
* gcc.dg/pr26865.c: Likewise.
* gcc.dg/pr61162-2.c: Likewise.
* gcc.dg/pr61162.c: Likewise.
* gcc.dg/pr67730-2.c: Likewise.
* gcc.dg/pr69156.c: Likewise.
* gcc.dg/pr70174.c: Likewise.
* objc.dg/proto-lossage-4.m: Likewise.
2017-08-09 Marek Polacek <polacek@redhat.com>
PR c/81417
* Wsign-compare-1.c: New test.
* gcc.dg/compare1.c: Adjust dg-bogus.
......
......@@ -15,8 +15,8 @@ f (void)
{
/* (V *)0 is a null pointer constant, so the assignment should be
diagnosed. */
q = (j ? p : (V *)0); /* { dg-error "5:assignment from incompatible pointer type" } */
q = (j ? p : (void *)0); /* { dg-error "5:assignment from incompatible pointer type" } */
q = (j ? p : (V *)0); /* { dg-error "5:assignment to 'long int \\*' from incompatible pointer type 'int \\*'" } */
q = (j ? p : (void *)0); /* { dg-error "5:assignment to 'long int \\*' from incompatible pointer type 'int \\*'" } */
/* And this conversion should be valid. */
(void (*)(void))(V *)0;
(void (*)(void))(void *)0;
......
......@@ -15,8 +15,8 @@ f (void)
{
/* (V *)0 is a null pointer constant, so the assignment should be
diagnosed. */
q = (j ? p : (V *)0); /* { dg-error "assignment from incompatible pointer type" } */
q = (j ? p : (void *)0); /* { dg-error "assignment from incompatible pointer type" } */
q = (j ? p : (V *)0); /* { dg-error "assignment to 'long int \\*' from incompatible pointer type 'int \\*'" } */
q = (j ? p : (void *)0); /* { dg-error "assignment to 'long int \\*' from incompatible pointer type 'int \\*'" } */
/* And this conversion should be valid. */
(void (*)(void))(V *)0;
(void (*)(void))(void *)0;
......
......@@ -12,15 +12,15 @@ int main()
unsigned char *ucp;
signed char *scp;
ulp = lp; /* { dg-warning " pointer targets in assignment differ in signedness" } */
lp = ulp; /* { dg-warning " pointer targets in assignment differ in signedness" } */
ulp = lp; /* { dg-warning " pointer targets in assignment from 'long int \\*' to 'long unsigned int \\*' differ in signedness" } */
lp = ulp; /* { dg-warning " pointer targets in assignment from 'long unsigned int \\*' to 'long int \\*' differ in signedness" } */
f1(ulp); /* { dg-warning " differ in signedness" } */
f2(lp); /* { dg-warning " differ in signedness" } */
cp = ucp; /* { dg-warning " pointer targets in assignment differ in signedness" } */
cp = scp; /* { dg-warning " pointer targets in assignment differ in signedness" } */
ucp = scp; /* { dg-warning " pointer targets in assignment differ in signedness" } */
ucp = cp; /* { dg-warning " pointer targets in assignment differ in signedness" } */
scp = ucp; /* { dg-warning " pointer targets in assignment differ in signedness" } */
scp = cp; /* { dg-warning " pointer targets in assignment differ in signedness" } */
cp = ucp; /* { dg-warning " pointer targets in assignment from 'unsigned char \\*' to 'char \\*' differ in signedness" } */
cp = scp; /* { dg-warning " pointer targets in assignment from 'signed char \\*' to 'char \\*' differ in signedness" } */
ucp = scp; /* { dg-warning " pointer targets in assignment from 'signed char \\*' to 'unsigned char \\*' differ in signedness" } */
ucp = cp; /* { dg-warning " pointer targets in assignment from 'char \\*' to 'unsigned char \\*' differ in signedness" } */
scp = ucp; /* { dg-warning " pointer targets in assignment from 'unsigned char \\*' to 'signed char \\*' differ in signedness" } */
scp = cp; /* { dg-warning " pointer targets in assignment from 'char \\*' to 'signed char \\*' differ in signedness" } */
}
/* PR c/81233 */
/* { dg-do compile } */
/* { dg-options "-Wc++-compat -Wpedantic" } */
/* Test we're printing the types, like the good compiler we are. */
enum E1 { A } e;
enum E2 { B };
extern void foo_E (enum E1); /* { dg-message "expected 'enum E1' but argument is of type 'int'" } */
extern void foo (char *); /* { dg-message "expected 'char \\*' but argument is of type 'int \\*'" } */
extern void foo2 (int *); /* { dg-message "expected 'int \\*' but argument is of type 'int'" } */
extern void foo3 (int); /* { dg-message "expected 'int' but argument is of type 'int \\*'" } */
extern void foo4 (int *); /* { dg-message "expected 'int \\*' but argument is of type 'unsigned int \\*'" } */
char *
fn0 (int *p, char *q)
{
p = q; /* { dg-warning "assignment to 'int \\*' from incompatible pointer type 'char \\*'" } */
int *r = q; /* { dg-warning "initialization of 'int \\*' from incompatible pointer type 'char \\*'" } */
foo (r); /* { dg-warning "passing argument 1 of 'foo' from incompatible pointer type" } */
return p; /* { dg-warning "returning 'int \\*' from a function with incompatible return type 'char \\*'" } */
}
int *
fn1 (int *p)
{
p = 1; /* { dg-warning "assignment to 'int \\*' from 'int' makes pointer from integer without a cast" } */
int *q = 1; /* { dg-warning "initialization of 'int \\*' from 'int' makes pointer from integer without a cast" } */
foo2 (1); /* { dg-warning "passing argument 1 of 'foo2' makes pointer from integer without a cast" } */
return 1; /* { dg-warning "returning 'int' from a function with return type 'int \\*' makes pointer from integer without a cast" } */
}
int
fn2 (int i, int *p)
{
i = p; /* { dg-warning "assignment to 'int' from 'int \\*' makes integer from pointer without a cast" } */
int j = p; /* { dg-warning "initialization of 'int' from 'int \\*' makes integer from pointer without a cast" } */
foo3 (p); /* { dg-warning "passing argument 1 of 'foo3' makes integer from pointer without a cast" } */
return p; /* { dg-warning "returning 'int \\*' from a function with return type 'int' makes integer from pointer without a cast" } */
}
int *
fn3 (int *p, unsigned int *u)
{
p = u; /* { dg-warning "pointer targets in assignment from 'unsigned int \\*' to 'int \\*' differ in signedness" } */
int *q = u; /* { dg-warning "pointer targets in initialization of 'int \\*' from 'unsigned int \\*' differ in signedness" } */
foo4 (u); /* { dg-warning "pointer targets in passing argument 1 of 'foo4' differ in signedness" } */
return u; /* { dg-warning "pointer targets in returning 'unsigned int \\*' from a function with return type 'int \\*' differ in signedness" } */
}
enum E1
fn4 (void)
{
foo_E (B); /* { dg-warning "enum conversion when passing argument" } */
e = 0; /* { dg-warning "enum conversion from 'int' to 'enum E1' in assignment is invalid" } */
enum E1 f = 0; /* { dg-warning "enum conversion from 'int' to 'enum E1' in initialization is invalid" } */
return 0; /* { dg-warning "enum conversion from 'int' to 'enum E1' in return is invalid" } */
}
......@@ -8,4 +8,4 @@ struct f
};
char b[10];
struct f g = {b}; /* { dg-warning "initialization from incompatible pointer type|near initialization for" } */
struct f g = {b}; /* { dg-warning "initialization of 'int \\*' from incompatible pointer type|near initialization for" } */
......@@ -47,10 +47,10 @@ static int sc = INT_MAX + 1; /* { dg-warning "25:integer overflow in expression"
constants. The third has the overflow in an unevaluated
subexpression, so is a null pointer constant. */
void *p = 0 * (INT_MAX + 1); /* { dg-warning "integer overflow in expression" } */
/* { dg-warning "initialization makes pointer from integer without a cast" "null" { target *-*-* } .-1 } */
/* { dg-warning "initialization of 'void \\*' from 'int' makes pointer from integer without a cast" "null" { target *-*-* } .-1 } */
void *q = 0 * (1 / 0); /* { dg-warning "division by zero" } */
/* { dg-error "initializer element is not constant" "constant" { target *-*-* } .-1 } */
/* { dg-warning "initialization makes pointer from integer without a cast" "null" { target *-*-* } .-2 } */
/* { dg-warning "initialization of 'void \\*' from 'int' makes pointer from integer without a cast" "null" { target *-*-* } .-2 } */
void *r = (1 ? 0 : INT_MAX+1);
void
......
......@@ -47,10 +47,10 @@ static int sc = INT_MAX + 1; /* { dg-warning "integer overflow in expression" }
constants. The third has the overflow in an unevaluated
subexpression, so is a null pointer constant. */
void *p = 0 * (INT_MAX + 1); /* { dg-warning "integer overflow in expression" } */
/* { dg-warning "initialization makes pointer from integer without a cast" "null" { target *-*-* } .-1 } */
/* { dg-warning "initialization of 'void \\*' from 'int' makes pointer from integer without a cast" "null" { target *-*-* } .-1 } */
void *q = 0 * (1 / 0); /* { dg-warning "division by zero" } */
/* { dg-error "initializer element is not constant" "constant" { target *-*-* } .-1 } */
/* { dg-warning "initialization makes pointer from integer without a cast" "null" { target *-*-* } .-2 } */
/* { dg-warning "initialization of 'void \\*' from 'int' makes pointer from integer without a cast" "null" { target *-*-* } .-2 } */
void *r = (1 ? 0 : INT_MAX+1);
void
......
......@@ -53,10 +53,10 @@ static int sc = INT_MAX + 1; /* { dg-warning "integer overflow in expression" }
subexpression, so is a null pointer constant. */
void *p = 0 * (INT_MAX + 1); /* { dg-warning "integer overflow in expression" } */
/* { dg-warning "overflow in constant expression" "constant" { target *-*-* } .-1 } */
/* { dg-warning "initialization makes pointer from integer without a cast" "null" { target *-*-* } .-2 } */
/* { dg-warning "initialization of 'void \\*' from 'int' makes pointer from integer without a cast" "null" { target *-*-* } .-2 } */
void *q = 0 * (1 / 0); /* { dg-warning "division by zero" } */
/* { dg-error "initializer element is not constant" "constant" { target *-*-* } .-1 } */
/* { dg-warning "initialization makes pointer from integer without a cast" "null" { target *-*-* } .-2 } */
/* { dg-warning "initialization of 'void \\*' from 'int' makes pointer from integer without a cast" "null" { target *-*-* } .-2 } */
void *r = (1 ? 0 : INT_MAX+1);
void
......
......@@ -53,10 +53,10 @@ static int sc = INT_MAX + 1; /* { dg-warning "integer overflow in expression" }
subexpression, so is a null pointer constant. */
void *p = 0 * (INT_MAX + 1); /* { dg-warning "integer overflow in expression" } */
/* { dg-error "overflow in constant expression" "constant" { target *-*-* } .-1 } */
/* { dg-error "initialization makes pointer from integer without a cast" "null" { target *-*-* } .-2 } */
/* { dg-error "initialization of 'void \\*' from 'int' makes pointer from integer without a cast" "null" { target *-*-* } .-2 } */
void *q = 0 * (1 / 0); /* { dg-warning "division by zero" } */
/* { dg-error "initializer element is not constant" "constant" { target *-*-* } .-1 } */
/* { dg-error "initialization makes pointer from integer without a cast" "null" { target *-*-* } .-2 } */
/* { dg-error "initialization of 'void \\*' from 'int' makes pointer from integer without a cast" "null" { target *-*-* } .-2 } */
void *r = (1 ? 0 : INT_MAX+1);
void
......
......@@ -6,8 +6,8 @@ void transpose0(double* out, _Atomic double* in) { }
void transpose1(double out[2][2], _Atomic double in[2][2]) { }
void transpose2(double out[2][2][2], _Atomic double in[2][2][2]) { }
// return
int (*x2(_Atomic int x[3][3]))[3] { return x; } /* { dg-warning "return from incompatible pointer type" } */
_Atomic int (*x3(int x[3][3]))[3] { return x; } /* { dg-warning "return from incompatible pointer type" } */
int (*x2(_Atomic int x[3][3]))[3] { return x; } /* { dg-warning "returning '_Atomic int \\(\\*\\)\\\[3\\\]' from a function with incompatible return type" } */
_Atomic int (*x3(int x[3][3]))[3] { return x; } /* { dg-warning "returning 'int \\(\\*\\)\\\[3\\\]' from a function with incompatible return type" } */
void test(void)
{
double x0[2];
......@@ -31,13 +31,13 @@ void test(void)
transpose2(y2, o2); /* { dg-warning "passing argument 2 of 'transpose2' from incompatible pointer type" } */
transpose2(y2, x2); /* { dg-warning "passing argument 2 of 'transpose2' from incompatible pointer type" } */
// initialization
_Atomic double (*x0p) = x0; /* { dg-warning "initialization from incompatible pointer type" } */
_Atomic double (*x1p)[2] = x1; /* { dg-warning "initialization from incompatible pointer type" } */
_Atomic double (*x2p)[2][2] = x2; /* { dg-warning "initialization from incompatible pointer type" } */
_Atomic double (*x0p) = x0; /* { dg-warning "initialization of '_Atomic double \\*' from incompatible pointer type" } */
_Atomic double (*x1p)[2] = x1; /* { dg-warning "initialization of '_Atomic double \\(\\*\\)\\\[2\\\]' from incompatible pointer type" } */
_Atomic double (*x2p)[2][2] = x2; /* { dg-warning "initialization of '_Atomic double \\(\\*\\)\\\[2\\\]\\\[2\\\]' from incompatible pointer type" } */
// assignment
x0p = x0; /* { dg-warning "assignment from incompatible pointer type" } */
x1p = x1; /* { dg-warning "assignment from incompatible pointer type" } */
x2p = x2; /* { dg-warning "assignment from incompatible pointer type" } */
x0p = x0; /* { dg-warning "assignment to '_Atomic double \\*' from incompatible pointer type" } */
x1p = x1; /* { dg-warning "assignment to '_Atomic double \\(\\*\\)\\\[2\\\]' from incompatible pointer type" } */
x2p = x2; /* { dg-warning "assignment to '_Atomic double \\(\\*\\)\\\[2\\\]\\\[2\\\]' from incompatible pointer type" } */
// subtraction
&(x0[1]) - &(z0[0]); /* { dg-error "invalid operands to binary" } */
&(x1[1]) - &(z1[0]); /* { dg-error "invalid operands to binary" } */
......
......@@ -4,5 +4,5 @@
void
foo (void)
{
char *e = alloca (100); /* { dg-warning "implicit declaration|initialization makes" } */
char *e = alloca (100); /* { dg-warning "implicit declaration|initialization of 'char \\*' from 'int' makes" } */
}
......@@ -8,7 +8,7 @@ struct s { int a; };
enum e
fn1 (void)
{
return 0; /* { dg-warning "10:enum conversion in return" } */
return 0; /* { dg-warning "10:enum conversion from 'int' to 'enum e' in return" } */
}
int
......@@ -26,19 +26,19 @@ fn3 (void)
int
fn4 (int *a)
{
return a; /* { dg-warning "10:return makes integer from pointer without a cast" } */
return a; /* { dg-warning "10:returning 'int \\*' from a function with return type 'int' makes integer from pointer without a cast" } */
}
int *
fn5 (int a)
{
return a; /* { dg-warning "10:return makes pointer from integer without a cast" } */
return a; /* { dg-warning "10:returning 'int' from a function with return type 'int \\*' makes pointer from integer without a cast" } */
}
unsigned int *
fn6 (int *i)
{
return i; /* { dg-warning "10:pointer targets in return differ" } */
return i; /* { dg-warning "10:pointer targets in returning 'int \\*' from a function with return type 'unsigned int \\*' differ" } */
}
void *
......
......@@ -6,7 +6,7 @@ enum e { A };
enum e
fn1 (void)
{
enum e e, q = 0; /* { dg-warning "17:enum conversion in initialization is invalid" } */
e = 0; /* { dg-warning "5:enum conversion in assignment is invalid" } */
1; return 0; /* { dg-warning "13:enum conversion in return is invalid" } */
enum e e, q = 0; /* { dg-warning "17:enum conversion from 'int' to 'enum e' in initialization is invalid" } */
e = 0; /* { dg-warning "5:enum conversion from 'int' to 'enum e' in assignment is invalid" } */
1; return 0; /* { dg-warning "13:enum conversion from 'int' to 'enum e' in return is invalid" } */
}
......@@ -9,14 +9,14 @@ extern void bar (int);
int
fn1 (void)
{
int a = NULL; /* { dg-warning "initialization makes integer from pointer" } */
a = NULL; /* { dg-warning "assignment makes integer from pointer" } */
int a = NULL; /* { dg-warning "initialization of 'int' from 'void \\*' makes integer from pointer" } */
a = NULL; /* { dg-warning "assignment to 'int' from 'void \\*' makes integer from pointer" } */
bar (NULL); /* { dg-warning "passing argument 1" } */
return NULL; /* { dg-warning "return makes integer from pointer" } */
return NULL; /* { dg-warning "returning 'void \\*' from a function with return type 'int' makes integer from pointer" } */
}
int
fn2 (void)
{
RETURN; /* { dg-warning "return makes integer from pointer" } */
RETURN; /* { dg-warning "returning 'void \\*' from a function with return type 'int' makes integer from pointer" } */
}
......@@ -5,6 +5,6 @@
_Bool
foo ()
{
_Bool (*f) () = __builtin_abs; /* { dg-warning "initialization from incompatible pointer type" } */
_Bool (*f) () = __builtin_abs; /* { dg-warning "initialization of '_Bool \\(\\*\\)\\(\\)' from incompatible pointer type" } */
return f (0);
}
......@@ -7,5 +7,5 @@ struct S { int f : 4; } a;
void
foo (void)
{
a.f = foo; /* { dg-warning "assignment makes integer from pointer without a cast" } */
a.f = foo; /* { dg-warning "assignment to 'signed char:4' from 'void \\(\\*\\)\\(void\\)' makes integer from pointer without a cast" } */
}
......@@ -28,13 +28,13 @@ long foo(void) {
receiver += [receiver anotherValue]; /* { dg-warning "invalid receiver type .intptr_t." } */
receiver += [(Obj *)receiver someValue]; /* { dg-warning ".Obj. may not respond to .\\-someValue." } */
/* { dg-warning "assignment makes integer from pointer without a cast" "" { target *-*-* } .-1 } */
/* { dg-warning "assignment to 'intptr_t {aka long int}' from 'id' makes integer from pointer without a cast" "" { target *-*-* } .-1 } */
receiver += [(Obj *)receiver anotherValue];
receiver += [(Obj <Proto> *)receiver someValue];
receiver += [(Obj <Proto> *)receiver anotherValue];
receiver += [objrcvr someValue]; /* { dg-warning ".Obj. may not respond to .\\-someValue." } */
/* { dg-warning "assignment makes integer from pointer without a cast" "" { target *-*-* } .-1 } */
/* { dg-warning "assignment to 'intptr_t {aka long int}' from 'id' makes integer from pointer without a cast" "" { target *-*-* } .-1 } */
receiver += [objrcvr anotherValue];
receiver += [(Obj <Proto> *)objrcvr someValue];
......@@ -42,7 +42,7 @@ long foo(void) {
receiver += [objrcvr2 someValue];
receiver += [objrcvr2 anotherValue];
receiver += [(Obj *)objrcvr2 someValue]; /* { dg-warning ".Obj. may not respond to .\\-someValue." } */
/* { dg-warning "assignment makes integer from pointer without a cast" "" { target *-*-* } .-1 } */
/* { dg-warning "assignment to 'intptr_t {aka long int}' from 'id' makes integer from pointer without a cast" "" { target *-*-* } .-1 } */
receiver += [(Obj *)objrcvr2 anotherValue];
......
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