if (!addr_space_superset (as_to, as_from, &as_common))
{
if (ADDR_SPACE_GENERIC_P (as_from))
- warning_at (loc, 0, "cast to %s address space pointer "
+ warning_at (loc, 0, "cast to %qs address space pointer "
"from disjoint generic address space pointer",
c_addr_space_name (as_to));
else if (ADDR_SPACE_GENERIC_P (as_to))
warning_at (loc, 0, "cast to generic address space pointer "
- "from disjoint %s address space pointer",
+ "from disjoint %qs address space pointer",
c_addr_space_name (as_from));
else
- warning_at (loc, 0, "cast to %s address space pointer "
- "from disjoint %s address space pointer",
+ warning_at (loc, 0, "cast to %qs address space pointer "
+ "from disjoint %qs address space pointer",
c_addr_space_name (as_to),
c_addr_space_name (as_from));
}
if (!null_pointer_constant_p (rhs)
&& asr != asl && !targetm.addr_space.subset_p (asr, asl))
{
+ auto_diagnostic_group d;
+ bool diagnosed = true;
switch (errtype)
{
case ic_argpass:
const char msg[] = G_("passing argument %d of %qE from "
"pointer to non-enclosed address space");
if (warnopt)
- warning_at (expr_loc, warnopt, msg, parmnum, rname);
+ diagnosed
+ = warning_at (expr_loc, warnopt, msg, parmnum, rname);
else
error_at (expr_loc, msg, parmnum, rname);
break;
const char msg[] = G_("assignment from pointer to "
"non-enclosed address space");
if (warnopt)
- warning_at (location, warnopt, msg);
+ diagnosed = warning_at (location, warnopt, msg);
else
error_at (location, msg);
break;
const char msg[] = G_("initialization from pointer to "
"non-enclosed address space");
if (warnopt)
- warning_at (location, warnopt, msg);
+ diagnosed = warning_at (location, warnopt, msg);
else
error_at (location, msg);
break;
const char msg[] = G_("return from pointer to "
"non-enclosed address space");
if (warnopt)
- warning_at (location, warnopt, msg);
+ diagnosed = warning_at (location, warnopt, msg);
else
error_at (location, msg);
break;
default:
gcc_unreachable ();
}
+ if (diagnosed)
+ {
+ if (errtype == ic_argpass)
+ inform_for_arg (fundecl, expr_loc, parmnum, type, rhstype);
+ else
+ inform (location, "expected %qT but pointer is of type %qT",
+ type, rhstype);
+ }
return error_mark_node;
}
--- /dev/null
+/* Tests of C frontend's address space type-checking. */
+/* { dg-options "-std=gnu90 -fdiagnostics-show-caret" } */
+
+/* Verify that we emit helpful diagnostics at a mismatching address space
+ at a function call, and that the underlined locations are correct. */
+
+extern void expects_seg_gs (int i, void __seg_gs *param, int j); /* { dg-line "decl_line" } */
+
+void
+test_bad_call (void *ptr)
+{
+ expects_seg_gs (0, ptr, 1); /* { dg-line "err_line" } */
+}
+
+/* { dg-error "passing argument 2 of 'expects_seg_gs' from pointer to non-enclosed address space" "" { target *-*-* } err_line } */
+/* { dg-begin-multiline-output "" }
+ expects_seg_gs (0, ptr, 1);
+ ^~~
+ { dg-end-multiline-output "" } */
+
+/* { dg-message "expected '__seg_gs void \\*' but argument is of type 'void \\*'" "" { target *-*-* } decl_line } */
+/* { dg-begin-multiline-output "" }
+ extern void expects_seg_gs (int i, void __seg_gs *param, int j);
+ ~~~~~~~~~~~~~~~^~~~~
+ { dg-end-multiline-output "" } */