public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug lto/114241] New: False-positive -Wodr warning when using -flto and -fno-semantic-interposition
@ 2024-03-05 15:38 abbeyj+gcc at gmail dot com
  2024-03-06  7:46 ` [Bug lto/114241] " rguenth at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: abbeyj+gcc at gmail dot com @ 2024-03-05 15:38 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 114241
           Summary: False-positive -Wodr warning when using -flto and
                    -fno-semantic-interposition
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: lto
          Assignee: unassigned at gcc dot gnu.org
          Reporter: abbeyj+gcc at gmail dot com
  Target Milestone: ---

When building the following example, a `-Wodr` warning is shown.  I don't think
the code violates the ODR so this warning is unexpected.  This reproducer
consists of 3 files.

d.h:
```
class A {
public:
  virtual ~A();
  virtual void a1();
};

class B : public A {
public:
  void a1();
  virtual void b1() = 0;
  virtual void b2() = 0;
};

class C : public B {
};

class D : public C {
public:
  void b1();
  void b2();
};
```


foo.cpp:
```
#include "d.h"

void foo() {
  D x;
}
```


bar.cpp:
```
#include "d.h"

void B::a1() {
}

void bar() {
  D y;
}
```


Build using:
g++ -fPIC -fno-semantic-interposition -flto -c foo.cpp
g++ -fPIC -fno-semantic-interposition -flto -c bar.cpp
g++ -shared foo.o bar.o -o lib.so


Output:
> d.h:14:7: warning: virtual table of type ‘struct C’ violates one definition rule [-Wodr]
>    14 | class C : public B {
>       |       ^
> d.h:14:7: note: the conflicting type defined in another translation unit has virtual table with more entries
>    14 | class C : public B {
>       |       ^


The warning message here is not great as it refers to "another translation
unit" but never names either of the two translation units involved.  In this
reduced example there are only two translation units but when there are many
translation units involved it is more difficult to figure out where the problem
is coming from.

The bigger issue is that I don't think this warning should have been issued at
all.  I can't see any way that the code is violating the ODR.

The earliest version that I've been able to reproduce with is 8.4

Godbolt link: https://godbolt.org/z/ncnqPMdzq

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug lto/114241] False-positive -Wodr warning when using -flto and -fno-semantic-interposition
  2024-03-05 15:38 [Bug lto/114241] New: False-positive -Wodr warning when using -flto and -fno-semantic-interposition abbeyj+gcc at gmail dot com
@ 2024-03-06  7:46 ` rguenth at gcc dot gnu.org
  2024-03-06  9:16 ` hubicka at ucw dot cz
  2024-03-06  9:18 ` hubicka at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: rguenth at gcc dot gnu.org @ 2024-03-06  7:46 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |hubicka at gcc dot gnu.org
     Ever confirmed|0                           |1
      Known to fail|                            |13.2.1
   Last reconfirmed|                            |2024-03-06
             Status|UNCONFIRMED                 |NEW

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
Confirmed also with GCC 13.  I guess we're optimizing things in a strange
(invalid) way before WPA and get confused because of that.

Honza?

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug lto/114241] False-positive -Wodr warning when using -flto and -fno-semantic-interposition
  2024-03-05 15:38 [Bug lto/114241] New: False-positive -Wodr warning when using -flto and -fno-semantic-interposition abbeyj+gcc at gmail dot com
  2024-03-06  7:46 ` [Bug lto/114241] " rguenth at gcc dot gnu.org
@ 2024-03-06  9:16 ` hubicka at ucw dot cz
  2024-03-06  9:18 ` hubicka at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: hubicka at ucw dot cz @ 2024-03-06  9:16 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Jan Hubicka <hubicka at ucw dot cz> ---
This indeed looks like bug caused by fact that the class is keyed into
one of the two units.

Outputting translation unit names is unfortunately hard, since they are
object files and often comming from .a archive where we know only
offset, but no original file name or something.

I had patch which passed through original filename attached to
TRALSATION_UNIT_DECL, but it also had problems, i.e. printing relative
filenames from wrong directory.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug lto/114241] False-positive -Wodr warning when using -flto and -fno-semantic-interposition
  2024-03-05 15:38 [Bug lto/114241] New: False-positive -Wodr warning when using -flto and -fno-semantic-interposition abbeyj+gcc at gmail dot com
  2024-03-06  7:46 ` [Bug lto/114241] " rguenth at gcc dot gnu.org
  2024-03-06  9:16 ` hubicka at ucw dot cz
@ 2024-03-06  9:18 ` hubicka at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: hubicka at gcc dot gnu.org @ 2024-03-06  9:18 UTC (permalink / raw)
  To: gcc-bugs

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

Jan Hubicka <hubicka at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |hubicka at gcc dot gnu.org
             Status|NEW                         |ASSIGNED

--- Comment #3 from Jan Hubicka <hubicka at gcc dot gnu.org> ---
mine. Will debug why the tables diverges.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-03-06  9:18 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-05 15:38 [Bug lto/114241] New: False-positive -Wodr warning when using -flto and -fno-semantic-interposition abbeyj+gcc at gmail dot com
2024-03-06  7:46 ` [Bug lto/114241] " rguenth at gcc dot gnu.org
2024-03-06  9:16 ` hubicka at ucw dot cz
2024-03-06  9:18 ` hubicka at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).