https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96126

            Bug ID: 96126
           Summary: conflicting attribute section accepted on
                    redeclaration
           Product: gcc
           Version: 10.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

GCC rejects conflicting attribute section on same declaration but fails to
detect the far more likely and difficult to debug problem where the conflict is
on two declaration of the same function or variable:

$ cat z.c && gcc -O2 -S -Wall z.c
__attribute__ ((section ("s1"), section ("s2")))  // error (good)
void f1 (void);

__attribute__ ((section ("s2"))) __attribute ((section ("s3")))
void f2 (void);                                   // error (good)

__attribute__ ((section ("s4"))) void f3 (void);
__attribute__ ((section ("s5"))) void f3 (void);  // missing diagnosic

z.c:2:6: error: section of ‘f1’ conflicts with previous declaration
    2 | void f1 (void);
      |      ^~
z.c:5:6: error: section of ‘f2’ conflicts with previous declaration
    5 | void f2 (void);                                   // error (good)
      |      ^~

In addition, referring to a previous declaration in the first declaration of a
symbol is misleading.

Clang diagnoses all instances of the problem as expected (although it too
suffers from the "previous declaration" problem):

z.c:1:33: warning: section does not match previous declaration [-Wsection]
__attribute__ ((section ("s1"), section ("s2")))  // error (good)
                                ^
z.c:1:17: note: previous attribute is here
__attribute__ ((section ("s1"), section ("s2")))  // error (good)
                ^
z.c:4:48: warning: section does not match previous declaration [-Wsection]
__attribute__ ((section ("s2"))) __attribute ((section ("s3")))
                                               ^
z.c:4:17: note: previous attribute is here
__attribute__ ((section ("s2"))) __attribute ((section ("s3")))
                ^
z.c:8:17: warning: section does not match previous declaration [-Wsection]
__attribute__ ((section ("s5"))) void f3 (void);  // missing diagnosic
                ^
z.c:7:17: note: previous attribute is here
__attribute__ ((section ("s4"))) void f3 (void);
                ^
3 warnings generated.

Reply via email to