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

            Bug ID: 85432
           Summary: Wodr can be more verbose for C code
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: lto
          Assignee: unassigned at gcc dot gnu.org
          Reporter: marxin at gcc dot gnu.org
                CC: hubicka at gcc dot gnu.org, marxin at gcc dot gnu.org
  Target Milestone: ---

Let's consider:

$ cat 1.c
struct A
{
  int a;
  double b;
};

extern void foo (struct A *);

int main()
{
  struct A a;
  foo (&a);

  return a.a;
}

$ cat 2.c
struct A
{
  int a;
};


void foo (struct A *a)
{
  a->a = 123;
}

$ gcc *.c -flto
1.c:7:13: warning: type of ‘foo’ does not match original declaration
[-Wlto-type-mismatch]
 extern void foo (struct A *);
             ^
2.c:7:6: note: ‘foo’ was previously declared here
 void foo (struct A *a)
      ^
2.c:7:6: note: code may be misoptimized unless -fno-strict-aliasing is used

C++ FE is more verbose:

g++ *.c -flto
1.c:1:8: warning: type ‘struct A’ violates the C++ One Definition Rule [-Wodr]
 struct A
        ^
2.c:1:8: note: a different type is defined in another translation unit
 struct A
        ^
1.c:4:10: note: the first difference of corresponding definitions is field ‘b’
   double b;
          ^
2.c:1:8: note: a type with different number of fields is defined in another
translation unit
 struct A
        ^
1.c:7:13: warning: ‘foo’ violates the C++ One Definition Rule  [-Wodr]
 extern void foo (struct A *);
             ^
2.c:7:6: note: type mismatch in parameter 1
 void foo (struct A *a)
      ^
2.c:1:8: note: type ‘struct A’ itself violates the C++ One Definition Rule
 struct A
        ^
1.c:1:8: note: the incompatible type is defined here
 struct A
        ^
2.c:7:6: note: ‘foo’ was previously declared here
 void foo (struct A *a)
      ^
2.c:7:6: note: code may be misoptimized unless -fno-strict-aliasing is used

Reply via email to