diff mbox

PR28901 Add two levels for -Wunused-const-variable.

Message ID 1456214140.7770.101.camel@redhat.com
State New
Headers show

Commit Message

Mark Wielaard Feb. 23, 2016, 7:55 a.m. UTC
On Mon, 2016-02-22 at 19:20 -0800, H.J. Lu wrote:
> It caused:
> 
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69911

Apologies. Apparently main_input_filename can be NULL. I am not entirely
sure when that happens. Or how I failed to see that test failure. I
think I didn't have java enabled, causing libffi to be skipped.

I am testing this patch that skips the test in that case:

Comments

Jakub Jelinek Feb. 23, 2016, 8:26 a.m. UTC | #1
On Tue, Feb 23, 2016 at 08:55:40AM +0100, Mark Wielaard wrote:
> On Mon, 2016-02-22 at 19:20 -0800, H.J. Lu wrote:
> > It caused:
> > 
> > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=69911
> 
> Apologies. Apparently main_input_filename can be NULL. I am not entirely
> sure when that happens. Or how I failed to see that test failure. I
> think I didn't have java enabled, causing libffi to be skipped.
> 
> I am testing this patch that skips the test in that case:

Are you sure that is the problem?
I think it doesn't hurt to check for non-NULL main_input_filename, perhaps
some non-c-family languages might not set it, and this is in generic code,
but at least on the gcc.target/i386/iamcu/test_passing_structs.c testcase and on one
randomly selected libffi testcase I see the ICE from completely different
reason - what is NULL is DECL_SOURCE_FILE (decl).

decl is e.g.
 <var_decl 0x7ffff18b3cf0 *.LC3
    type <record_type 0x7ffff18865e8 char7_struct sizes-gimplified type_0 BLK
        size <integer_cst 0x7ffff184cf30 constant 56>
        unit size <integer_cst 0x7ffff184cf00 constant 7>
        align 8 symtab 0 alias set 6 canonical type 0x7ffff18865e8
        fields <field_decl 0x7ffff1889390 c1 type <integer_type 0x7ffff17175e8 char>
            QI file /usr/src/gcc/gcc/testsuite/gcc.target/i386/iamcu/test_passing_structs.c line 133 col 8
            size <integer_cst 0x7ffff1713de0 constant 8>
            unit size <integer_cst 0x7ffff1713df8 constant 1>
            align 8 offset_align 32
            offset <integer_cst 0x7ffff1713cd8 constant 0>
            bit offset <integer_cst 0x7ffff1713d38 constant 0> context <record_type 0x7ffff18865e8 char7_struct> chain <field_decl 0x7ffff1889428 c2>> context <translation_unit_decl 0x7ffff171f708 D.2134>
        chain <type_decl 0x7ffff18892f8 D.2095>>
    readonly addressable static ignored in-constant-pool BLK file (null) line 0 col 0 size <integer_cst 0x7ffff184cf30 56> unit size <integer_cst 0x7ffff184cf00 7>
    align 32 initial <constructor 0x7ffff188e5e8>>

We are not really going to warn about this anyway, e.g. because
it is DECL_ARTIFICIAL, but that is checked only in a much later
condition.  So, I think you should check also for NULL DECL_SOURCE_FILE
(and treat it as possibly in a header).  Unfortunately
DECL_SOURCE_FILE involves a function call, so you might want to cache
it in some automatic variable.
		&& (warn_unused_const_variable == 2
		    || (main_input_filename != NULL
		        && (decl_file = DECL_SOURCE_FILE (decl)) != NULL
			&& filename_cmp (main_input_filename,
					 decl_file) == 0))))

	Jakub
diff mbox

Patch

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 49f6c25..788f07e 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,9 @@ 
+2016-02-23  Mark Wielaard  <mjw@redhat.com>
+
+	PR c/69911
+	* cgraphunit.c (check_global_declaration): Check main_input_filename
+	is not NULL.
+
 2016-02-20  Mark Wielaard  <mjw@redhat.com>
 
 	PR c/28901
diff --git a/gcc/cgraphunit.c b/gcc/cgraphunit.c
index 27a073a..6c14be2 100644
--- a/gcc/cgraphunit.c
+++ b/gcc/cgraphunit.c
@@ -944,8 +944,9 @@  check_global_declaration (symtab_node *snode)
        || (((warn_unused_variable && ! TREE_READONLY (decl))
 	    || (warn_unused_const_variable > 0 && TREE_READONLY (decl)
 		&& (warn_unused_const_variable == 2
-		    || filename_cmp (main_input_filename,
-				     DECL_SOURCE_FILE (decl)) == 0)))
+		    || (main_input_filename != NULL
+			&& filename_cmp (main_input_filename,
+					 DECL_SOURCE_FILE (decl)) == 0))))
 	   && TREE_CODE (decl) == VAR_DECL))
       && ! DECL_IN_SYSTEM_HEADER (decl)
       && ! snode->referred_to_p (/*include_self=*/false)