public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Lewis Hyatt <lhyatt@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-2994] diagnostics: Fix virtual location for -Wuninitialized [PR69543] Date: Fri, 30 Sep 2022 18:10:26 +0000 (GMT) [thread overview] Message-ID: <20220930181026.E12313858D1E@sourceware.org> (raw) https://gcc.gnu.org/g:b52b99b62df8fc9b3a3010cb0a8cf49bc35037f0 commit r13-2994-gb52b99b62df8fc9b3a3010cb0a8cf49bc35037f0 Author: Lewis Hyatt <lhyatt@gmail.com> Date: Fri Sep 30 14:10:00 2022 -0400 diagnostics: Fix virtual location for -Wuninitialized [PR69543] Warnings issued for -Wuninitialized have been using the spelling location of the problematic usage, discarding any information on the location of the macro expansion point if such usage was in a macro. This makes the warnings impossible to control reliably with #pragma GCC diagnostic, and also discards useful context in the diagnostic output. There seems to be no need to discard the virtual location information, so this patch fixes that. PR69543 was mostly about _Pragma issues which have been fixed for many years now. The PR remains open because two of the testcases added in response to it still have xfails, but those xfails have nothing to do with _Pragma and rather just with the issue fixed by this patch, so the PR can be closed now as well. The other testcase modified here, pragma-diagnostic-2.c, was explicitly testing for the undesirable behavior that was xfailed in pr69543-3.c. I have adjusted that and also added a new testcase verifying all 3 types of warning that come from tree-ssa-uninit.cc get the proper location information now. gcc/ChangeLog: PR preprocessor/69543 * tree-ssa-uninit.cc (warn_uninit): Stop stripping macro tracking information away from the diagnostic location. (maybe_warn_read_write_only): Likewise. (maybe_warn_operand): Likewise. gcc/testsuite/ChangeLog: PR preprocessor/69543 * c-c++-common/pr69543-3.c: Remove xfail. * c-c++-common/pr69543-4.c: Likewise. * gcc.dg/cpp/pragma-diagnostic-2.c: Adjust test for new behavior. * c-c++-common/pragma-diag-16.c: New test. Diff: --- gcc/testsuite/c-c++-common/pr69543-3.c | 8 +--- gcc/testsuite/c-c++-common/pr69543-4.c | 8 +--- gcc/testsuite/c-c++-common/pragma-diag-16.c | 63 ++++++++++++++++++++++++++ gcc/testsuite/gcc.dg/cpp/pragma-diagnostic-2.c | 7 +-- gcc/tree-ssa-uninit.cc | 12 +---- 5 files changed, 73 insertions(+), 25 deletions(-) diff --git a/gcc/testsuite/c-c++-common/pr69543-3.c b/gcc/testsuite/c-c++-common/pr69543-3.c index fcf750cc05d..6d4224f4af7 100644 --- a/gcc/testsuite/c-c++-common/pr69543-3.c +++ b/gcc/testsuite/c-c++-common/pr69543-3.c @@ -3,15 +3,11 @@ /* 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\"") diff --git a/gcc/testsuite/c-c++-common/pr69543-4.c b/gcc/testsuite/c-c++-common/pr69543-4.c index cd71e7e1188..3db2eeb16eb 100644 --- a/gcc/testsuite/c-c++-common/pr69543-4.c +++ b/gcc/testsuite/c-c++-common/pr69543-4.c @@ -3,10 +3,6 @@ /* 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\"")\ @@ -14,11 +10,11 @@ # 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 diff --git a/gcc/testsuite/c-c++-common/pragma-diag-16.c b/gcc/testsuite/c-c++-common/pragma-diag-16.c new file mode 100644 index 00000000000..8cacd872bef --- /dev/null +++ b/gcc/testsuite/c-c++-common/pragma-diag-16.c @@ -0,0 +1,63 @@ +/* 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 diff --git a/gcc/testsuite/gcc.dg/cpp/pragma-diagnostic-2.c b/gcc/testsuite/gcc.dg/cpp/pragma-diagnostic-2.c index 38fc77c47ba..89d2975ee7b 100644 --- a/gcc/testsuite/gcc.dg/cpp/pragma-diagnostic-2.c +++ b/gcc/testsuite/gcc.dg/cpp/pragma-diagnostic-2.c @@ -7,18 +7,17 @@ void f (unsigned); #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 @@ -26,3 +25,5 @@ h (void) { CODE_WITH_WARNING; /* { dg-message "in expansion of macro 'CODE_WITH_WARNING'" } */ } + +/* { dg-regexp {.*some warnings being treated as errors} } */ diff --git a/gcc/tree-ssa-uninit.cc b/gcc/tree-ssa-uninit.cc index bde23997a0a..bf2e50511af 100644 --- a/gcc/tree-ssa-uninit.cc +++ b/gcc/tree-ssa-uninit.cc @@ -274,9 +274,6 @@ warn_uninit (opt_code opt, tree t, tree var, gimple *context, 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) @@ -424,10 +421,7 @@ maybe_warn_read_write_only (tree fndecl, gimple *stmt, tree arg, tree ptr) && 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; @@ -722,9 +716,7 @@ maybe_warn_operand (ao_ref &ref, gimple *stmt, tree lhs, tree rhs, 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,
reply other threads:[~2022-09-30 18:10 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20220930181026.E12313858D1E@sourceware.org \ --to=lhyatt@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).