From: Martin Sebor Date: Thu, 2 Sep 2021 15:20:09 +0000 (-0600) Subject: Improve -Wuninitialized note location. X-Git-Tag: basepoints/gcc-13~4998 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9695e1c23be5b5c55d572ced152897313ddb96ae;p=thirdparty%2Fgcc.git Improve -Wuninitialized note location. Related: PR tree-optimization/17506 - warning about uninitialized variable points to wrong location PR testsuite/37182 - Revision 139286 caused gcc.dg/pr17506.c and gcc.dg/uninit-15.c gcc/ChangeLog: PR tree-optimization/17506 PR testsuite/37182 * tree-ssa-uninit.c (warn_uninit): Remove conditional guarding note. gcc/testsuite/ChangeLog: PR tree-optimization/17506 PR testsuite/37182 * gcc.dg/diagnostic-tree-expr-ranges-2.c: Add expected output. * gcc.dg/uninit-15-O0.c: Remove xfail. * gcc.dg/uninit-15.c: Same. --- diff --git a/gcc/testsuite/gcc.dg/diagnostic-tree-expr-ranges-2.c b/gcc/testsuite/gcc.dg/diagnostic-tree-expr-ranges-2.c index 302e233a04ac..1cbcad5ac7dd 100644 --- a/gcc/testsuite/gcc.dg/diagnostic-tree-expr-ranges-2.c +++ b/gcc/testsuite/gcc.dg/diagnostic-tree-expr-ranges-2.c @@ -3,21 +3,25 @@ int test_uninit_1 (void) { - int result; - return result; /* { dg-warning "uninitialized" } */ -/* { dg-begin-multiline-output "" } - return result; - ^~~~~~ + int result_1; /* { dg-message "declared here" } */ + return result_1; /* { dg-warning "uninitialized" } */ + /* { dg-begin-multiline-output "" } + return result_1; + ^~~~~~~~ + int result_1; + ^~~~~~~~ { dg-end-multiline-output "" } */ } int test_uninit_2 (void) { - int result; - result += 3; /* { dg-warning "uninitialized" } */ -/* { dg-begin-multiline-output "" } - result += 3; - ~~~~~~~^~~~ + int result_2; /* { dg-message "declared here" } */ + result_2 += 3; /* { dg-warning "uninitialized" } */ + /* { dg-begin-multiline-output "" } + result_2 += 3; + ~~~~~~~~~^~~~ + int result_2; + ^~~~~~~~ { dg-end-multiline-output "" } */ - return result; + return result_2; } diff --git a/gcc/testsuite/gcc.dg/uninit-15-O0.c b/gcc/testsuite/gcc.dg/uninit-15-O0.c index 36d963486175..1ddddee1388b 100644 --- a/gcc/testsuite/gcc.dg/uninit-15-O0.c +++ b/gcc/testsuite/gcc.dg/uninit-15-O0.c @@ -14,7 +14,7 @@ void baz(); void bar() { - int j; /* { dg-message "was declared here" {} { xfail *-*-* } } */ + int j; /* { dg-message "declared here" } */ for (; foo(j); ++j) /* { dg-warning "is used uninitialized" } */ baz(); } diff --git a/gcc/testsuite/gcc.dg/uninit-15.c b/gcc/testsuite/gcc.dg/uninit-15.c index 85cb116f3494..7352662f6276 100644 --- a/gcc/testsuite/gcc.dg/uninit-15.c +++ b/gcc/testsuite/gcc.dg/uninit-15.c @@ -20,7 +20,7 @@ void baz (void); void bar (void) { - int j; /* { dg-message "note: 'j' was declared here" "" { xfail *-*-* } } */ + int j; /* { dg-message "note: 'j' was declared here" } */ for (; foo (j); ++j) /* { dg-warning "'j' is used uninitialized" } */ baz (); } diff --git a/gcc/tree-ssa-uninit.c b/gcc/tree-ssa-uninit.c index 394dbf40c9ca..cb6d11452026 100644 --- a/gcc/tree-ssa-uninit.c +++ b/gcc/tree-ssa-uninit.c @@ -206,14 +206,7 @@ warn_uninit (opt_code opt, tree t, tree var, const char *gmsgid, if (location == var_loc) return; - location_t cfun_loc = DECL_SOURCE_LOCATION (cfun->decl); - expanded_location xloc = expand_location (location); - expanded_location floc = expand_location (cfun_loc); - if (xloc.file != floc.file - || linemap_location_before_p (line_table, location, cfun_loc) - || linemap_location_before_p (line_table, cfun->function_end_locus, - location)) - inform (var_loc, "%qD was declared here", var); + inform (var_loc, "%qD was declared here", var); } struct check_defs_data