public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/95693] New: Incorrect error from undefined behavior sanitizer
@ 2020-06-16  5:12 gcc-90 at tbilles dot hu
  2020-06-16  6:43 ` [Bug sanitizer/95693] [8/9/10/11 Regression] " rguenth at gcc dot gnu.org
                   ` (14 more replies)
  0 siblings, 15 replies; 16+ messages in thread
From: gcc-90 at tbilles dot hu @ 2020-06-16  5:12 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 95693
           Summary: Incorrect error from undefined behavior sanitizer
           Product: gcc
           Version: 10.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gcc-90 at tbilles dot hu
  Target Milestone: ---

After upgrading GCC from 7.2 to 10.1 I get a runtime error when using
-fsanitize=undefined. I cannot see anything wrong with the code. It was also
suggested on the gcc-help mailing list that this is a bug in the compiler.
(https://gcc.gnu.org/pipermail/gcc-help/2020-June/139055.html)

The code in question can be found on Compiler Explorer (also pasted at the end
of this description): https://godbolt.org/z/7rAxJj

It shows that different compiler versions behave differently.

Version 10.1 prints "runtime error: reference binding to null pointer of type
'int'" although there is no null pointer in the code, the reference is bound to
a global integer.

There is a comment on line 16 that explicitly defaults the Derived constructor.
If you switch the comment with line 17, both compiler versions run fine without
producing the runtime error although the defaulted constructor should be
exactly the same the user defined one: https://godbolt.org/z/UShm-u

According to Compiler Explorer the incorrect behavior began in GCC 8.x series
and is still present in trunk.

---
int global = 9;

class Payload {
public:
    Payload() : data(global) {}
private:
    int& data;
};

struct Base {
    Payload payload;
};

class Derived : public Base {
public:
    //Derived() = default;
    Derived() : Base() {}

    Payload p;
};

int main()
{
    Derived t;
}

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

end of thread, other threads:[~2021-04-23 14:14 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-16  5:12 [Bug c++/95693] New: Incorrect error from undefined behavior sanitizer gcc-90 at tbilles dot hu
2020-06-16  6:43 ` [Bug sanitizer/95693] [8/9/10/11 Regression] " rguenth at gcc dot gnu.org
2020-06-16  6:57 ` marxin at gcc dot gnu.org
2020-06-16  7:24 ` jakub at gcc dot gnu.org
2020-06-16  8:41 ` redi at gcc dot gnu.org
2021-01-14  9:02 ` rguenth at gcc dot gnu.org
2021-01-14 12:58 ` nathan at gcc dot gnu.org
2021-01-21 13:50 ` jakub at gcc dot gnu.org
2021-01-22 18:05 ` cvs-commit at gcc dot gnu.org
2021-01-22 18:06 ` [Bug sanitizer/95693] [8/9/10 " jakub at gcc dot gnu.org
2021-01-29 19:19 ` cvs-commit at gcc dot gnu.org
2021-01-29 19:24 ` [Bug sanitizer/95693] [8/9 " jakub at gcc dot gnu.org
2021-04-20 23:31 ` cvs-commit at gcc dot gnu.org
2021-04-22 16:49 ` cvs-commit at gcc dot gnu.org
2021-04-22 17:06 ` jakub at gcc dot gnu.org
2021-04-23 14:14 ` gcc-90 at tbilles dot hu

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).