/* Verify disabling a warning, where the _Pragma is in regular code,
but the affected code is within a macro. */
-/* TODO: XFAIL: both C and C++ erroneously fail to suppress the warning
- The warning is reported at the macro definition location, rather than
- the macro expansion location. */
-
-#define WARNABLE_CODE *++yyvsp = yylval; /* { dg-bogus "used uninitialized" "" { xfail *-*-* } } */
+#define WARNABLE_CODE *++yyvsp = yylval; /* { dg-bogus "used uninitialized" } */
void test (char yylval)
{
- char *yyvsp; /* { dg-bogus "declared here" "" { xfail *-*-* } } */
+ char *yyvsp; /* { dg-bogus "declared here" } */
_Pragma ("GCC diagnostic push")
_Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")
_Pragma ("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")
/* Verify disabling a warning, where both the _Pragma and the
affected code are within (different) macros. */
-/* TODO: XFAIL: both C and C++ erroneously fail to suppress the warning
- The warning is reported at the macro definition location, rather than
- the macro expansion location. */
-
# define YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN \
_Pragma ("GCC diagnostic push") \
_Pragma ("GCC diagnostic ignored \"-Wuninitialized\"")\
# define YY_IGNORE_MAYBE_UNINITIALIZED_END \
_Pragma ("GCC diagnostic pop")
-#define WARNABLE_CODE *++yyvsp = yylval; /* { dg-bogus "used uninitialized" "" { xfail *-*-* } } */
+#define WARNABLE_CODE *++yyvsp = yylval; /* { dg-bogus "used uninitialized" } */
void test (char yylval)
{
- char *yyvsp; /* { dg-bogus "declared here" "" { xfail *-*-* } } */
+ char *yyvsp; /* { dg-bogus "declared here" } */
YY_IGNORE_MAYBE_UNINITIALIZED_BEGIN
WARNABLE_CODE
YY_IGNORE_MAYBE_UNINITIALIZED_END
--- /dev/null
+/* Make sure that the 3 types of warnings generated from tree-ssa-uninit.cc have
+ proper virtual locations and so can be controlled by pragmas when they appear
+ in macros. */
+
+/* { dg-do compile } */
+/* { dg-options "-Wuninitialized -Wmaybe-uninitialized" } */
+
+/* 1. Check maybe_warn_read_write_only(). */
+#define DEREF1(p) (*p) /* { dg-warning {may be used uninitialized} } */
+__attribute__ ((access (write_only, 1)))
+int f1 (int* x) /* { dg-note {accessing argument 1} } */
+{
+ return DEREF1 (x); /* { dg-note {in expansion of macro 'DEREF1'} } */
+}
+
+#define DEREF2(p) (*p) /* { dg-bogus {may be used uninitialized} } */
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
+__attribute__ ((access (write_only, 1)))
+int f2 (int* x) /* { dg-bogus {accessing argument 1} } */
+{
+ return DEREF2 (x); /* { dg-bogus {in expansion of macro 'DEREF1'} } */
+}
+#pragma GCC diagnostic pop
+
+/* 2. Check warn_uninit(). */
+int g;
+#define SET3(a, b) ((a) = (b)) /* { dg-warning {'x' is used uninitialized} } */
+void f3 ()
+{
+ int x; /* { dg-note {'x' was declared here} } */
+ SET3 (g, x); /* { dg-note {in expansion of macro 'SET3'} } */
+}
+
+#define SET4(a, b) ((a) = (b)) /* { dg-bogus {'x' is used uninitialized} } */
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wuninitialized"
+void f4 ()
+{
+ int x; /* { dg-bogus {'x' was declared here} } */
+ SET4 (g, x); /* { dg-bogus {in expansion of macro 'SET3'} } */
+}
+#pragma GCC diagnostic pop
+
+/* 3. Check maybe_warn_operand(). */
+#define CALL5(func, arg) ((func) (arg)) /* { dg-warning {'c' may be used uninitialized} } */
+void f5a (const char *); /* { dg-note {by argument 1} } */
+void f5b ()
+{
+ char c; /* { dg-note {'c' declared here} } */
+ CALL5 (f5a, &c); /* { dg-note {in expansion of macro 'CALL5'} } */
+}
+
+#define CALL6(func, arg) ((func) (arg)) /* { dg-bogus {'c' may be used uninitialized} } */
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
+void f6a (const char *); /* { dg-bogus {by argument 1} } */
+void f6b ()
+{
+ char c; /* { dg-bogus {'c' declared here} } */
+ CALL6 (f6a, &c); /* { dg-bogus {in expansion of macro 'CALL6'} } */
+}
+#pragma GCC diagnostic pop
#define CODE_WITH_WARNING \
int a; /* { dg-message "was declared here" } */ \
- f (a) /* { dg-warning "used uninitialized" } */
+ f (a) /* { dg-error "used uninitialized" } */
#pragma GCC diagnostic ignored "-Wuninitialized"
void
g (void)
{
+ /* No warning expected here since the #pragma is in effect. */
CODE_WITH_WARNING;
}
-#pragma GCC diagnostic push
-
#pragma GCC diagnostic error "-Wuninitialized"
void
{
CODE_WITH_WARNING; /* { dg-message "in expansion of macro 'CODE_WITH_WARNING'" } */
}
+
+/* { dg-regexp {.*some warnings being treated as errors} } */
else if (var_name_str)
location = gimple_location (var_def_stmt);
- location = linemap_resolve_location (line_table, location,
- LRK_SPELLING_LOCATION, NULL);
-
auto_diagnostic_group d;
gcc_assert (opt == OPT_Wuninitialized || opt == OPT_Wmaybe_uninitialized);
if (var)
&& access->mode != access_write_only)
continue;
- location_t stmtloc
- = linemap_resolve_location (line_table, gimple_location (stmt),
- LRK_SPELLING_LOCATION, NULL);
-
+ location_t stmtloc = gimple_location (stmt);
if (!warning_at (stmtloc, OPT_Wmaybe_uninitialized,
"%qE may be used uninitialized", ptr))
break;
bool warned = false;
/* We didn't find any may-defs so on all paths either
reached function entry or a killing clobber. */
- location_t location
- = linemap_resolve_location (line_table, gimple_location (stmt),
- LRK_SPELLING_LOCATION, NULL);
+ location_t location = gimple_location (stmt);
if (wlims.always_executed)
{
if (warning_at (location, OPT_Wuninitialized,