On Tue, Apr 02, 2013 at 02:05:13PM +1030, Alan Modra wrote: > suspicious. For instance, you might wonder why it is correct to have > if (decl && !DECL_P (decl)) > decl = NULL_TREE; > before calling get_section(). The answer is that get_section() is not > prepared to handle !DECL_P trees when reporting errors. Arguably it > should be modified to do that.
This patch tidies error reporting in get_section(), removing non-sensical messages like "foo causes a section type conflict with foo" which was one of the things we hit prior to my pr55033 fix. I'm moving the DECL_P check into error handling code. That seems like a win since decl and sect->named.decl are only used on the error path. Bootstrapped and regression tested powerpc64-linux. OK for mainline? * varasm.c (get_section): Don't die on !DECL_P decl. Tidy error reporting. (get_named_section): Don't NULL !DECL_P decl. Index: gcc/varasm.c =================================================================== --- gcc/varasm.c (revision 199718) +++ gcc/varasm.c (working copy) @@ -307,19 +307,22 @@ get_section (const char *name, unsigned int flags, return sect; } /* Sanity check user variables for flag changes. */ - if (decl == 0) - decl = sect->named.decl; - gcc_assert (decl); - if (sect->named.decl == NULL) + if (sect->named.decl != NULL + && DECL_P (sect->named.decl) + && decl != sect->named.decl) + { + if (decl != NULL && DECL_P (decl)) + error ("%+D causes a section type conflict with %D", + decl, sect->named.decl); + else + error ("section type conflict with %D", sect->named.decl); + inform (DECL_SOURCE_LOCATION (sect->named.decl), + "%qD was declared here", sect->named.decl); + } + else if (decl != NULL && DECL_P (decl)) error ("%+D causes a section type conflict", decl); else - { - error ("%+D causes a section type conflict with %D", - decl, sect->named.decl); - if (decl != sect->named.decl) - inform (DECL_SOURCE_LOCATION (sect->named.decl), - "%qD was declared here", sect->named.decl); - } + error ("section type conflict"); /* Make sure we don't error about one section multiple times. */ sect->common.flags |= SECTION_OVERRIDE; } @@ -409,9 +412,6 @@ get_named_section (tree decl, const char *name, in } flags = targetm.section_type_flags (decl, name, reloc); - - if (decl && !DECL_P (decl)) - decl = NULL_TREE; return get_section (name, flags, decl); } -- Alan Modra Australia Development Lab, IBM