diff mbox

[c-family] : Fix Bug 35330 - [4.8/4.9/5 regression] ICE with invalid pragma weak

Message ID CAEwic4YQ7wDM9SWoPohwigxP=D+Jb7rop0BNGiiyu0TDmUzaag@mail.gmail.com
State New
Headers show

Commit Message

Kai Tietz Feb. 26, 2015, 8:25 p.m. UTC
2015-02-26 19:53 GMT+01:00 Marek Polacek <polacek@redhat.com>:
> On Thu, Feb 26, 2015 at 07:28:02PM +0100, Kai Tietz wrote:
>> Hi,
>>
>> This patch addresses the reported ICE about #pragma weak used on
>> declarations not var or function.
>>
>> ChangeLog
>>
>> 2015-02-26  Kai Tietz  <ktietz@redhat.com>
>>
>>         * c-pragma.c (handle_pragma_weak): Do not try to creat
>
> "create"
>
>> weak/alias of declarations
>>         not being function, or variable declarations.
>
> "functions"
>
>> --- c-pragma.c  (Revision 221019)
>> +++ c-pragma.c  (Arbeitskopie)
>> @@ -392,6 +392,11 @@ handle_pragma_weak (cpp_reader * ARG_UNUSED (dummy
>>    decl = identifier_global_value (name);
>>    if (decl && DECL_P (decl))
>>      {
>> +      if (TREE_CODE (decl) != FUNCTION_DECL && TREE_CODE (decl) != VAR_DECL)
>
> Use !VAR_OR_FUNCTION_DECL_P.

ah, wasn't aware about this macro.  thanks for point me to it.

>> +       {
>> +         error ("weak declaration of %q+D not allowed", decl);
>> +         return;
>> +       }
>
> I think that shouldn't be an error, merely a warning.  Thus, use
>
>   GCC_BAD2 ("..., ignored", decl);
>
> instead?

Ok, I am fine to make it a warning.

> Also please add a testcase.
>
>         Marek

Well, testcase for the pragma ...

ChangeLog testsuite/

2015-02-26  Kai Tietz  <ktietz@redhat.com>

        * gcc.dg/weak/weak-17.c: New file

weak-17.c:
/* { dg-do compile } */
/* { dg-require-weak "" } */
#pragma weak int = foo

/* { dg-warning "weak declaration" "weak" { target *-*-* } 0 } */
--- end of weak-17.c

Updated patch (regression-tested):

Comments

Marek Polacek Feb. 27, 2015, 10:32 a.m. UTC | #1
On Thu, Feb 26, 2015 at 09:25:57PM +0100, Kai Tietz wrote:
> Well, testcase for the pragma ...
> 
> ChangeLog testsuite/
> 
> 2015-02-26  Kai Tietz  <ktietz@redhat.com>
> 
>         * gcc.dg/weak/weak-17.c: New file
 
Missing full stop.

> Updated patch (regression-tested):
> Index: c-pragma.c
> ===================================================================
> --- c-pragma.c  (Revision 221019)
> +++ c-pragma.c  (Arbeitskopie)
> @@ -392,6 +392,8 @@ handle_pragma_weak (cpp_reader * ARG_UNUSED (dummy
>    decl = identifier_global_value (name);
>    if (decl && DECL_P (decl))
>      {
> +      if (!VAR_OR_FUNCTION_DECL_P (decl))
> +       GCC_BAD2 ("weak declaration of %q+D not allowed, ignored", decl);

I think this message should explicitly mention "#pragma weak".

Ok with those changes.

	Marek
diff mbox

Patch

Index: c-pragma.c
===================================================================
--- c-pragma.c  (Revision 221019)
+++ c-pragma.c  (Arbeitskopie)
@@ -392,6 +392,8 @@  handle_pragma_weak (cpp_reader * ARG_UNUSED (dummy
   decl = identifier_global_value (name);
   if (decl && DECL_P (decl))
     {
+      if (!VAR_OR_FUNCTION_DECL_P (decl))
+       GCC_BAD2 ("weak declaration of %q+D not allowed, ignored", decl);
       apply_pragma_weak (decl, value);
       if (value)
        {