public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/101210] New: [7/8/9/10/11/12 regression] spurious "reference binding to misaligned address" ubsan error for integer comparison
@ 2021-06-25 14:11 jlegg at feralinteractive dot com
  2021-06-25 16:50 ` [Bug c++/101210] [9/10/11/12 " jakub at gcc dot gnu.org
                   ` (12 more replies)
  0 siblings, 13 replies; 14+ messages in thread
From: jlegg at feralinteractive dot com @ 2021-06-25 14:11 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 101210
           Summary: [7/8/9/10/11/12 regression] spurious "reference
                    binding to misaligned address" ubsan error for integer
                    comparison
           Product: gcc
           Version: 11.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jlegg at feralinteractive dot com
  Target Milestone: ---

With -fsanitize=undefined, this C++ code:
int main()
{
        int x;
        int & y {x};
        return reinterpret_cast<long int>(&y) == 1;
}

Produces this error at runtime:
test.cc:5:40: runtime error: reference binding to misaligned address
0x000000000001 for type 'int', which requires 4 byte alignment
0x000000000001: note: pointer points here
<memory cannot be printed>

However, address 1 is never bound to a reference to an int. It is an integer
which is compared to another integer (which happens to be pointer sized and
derived from an address taken from a reference).

Checking various versions with compiler explorer, GCC 6 did not have this
issue, but later releases did.

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

end of thread, other threads:[~2022-05-11  6:36 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-25 14:11 [Bug c++/101210] New: [7/8/9/10/11/12 regression] spurious "reference binding to misaligned address" ubsan error for integer comparison jlegg at feralinteractive dot com
2021-06-25 16:50 ` [Bug c++/101210] [9/10/11/12 " jakub at gcc dot gnu.org
2021-06-28  7:37 ` jakub at gcc dot gnu.org
2021-06-28  8:18 ` jakub at gcc dot gnu.org
2021-06-28  8:20 ` marxin at gcc dot gnu.org
2021-06-28  8:22 ` jakub at gcc dot gnu.org
2021-06-28  8:27 ` marxin at gcc dot gnu.org
2021-06-29  9:25 ` cvs-commit at gcc dot gnu.org
2021-06-29  9:50 ` [Bug c++/101210] [9/10/11 " jakub at gcc dot gnu.org
2021-07-18 23:28 ` cvs-commit at gcc dot gnu.org
2021-07-19  7:55 ` [Bug c++/101210] [9/10 " jakub at gcc dot gnu.org
2022-05-10  8:19 ` cvs-commit at gcc dot gnu.org
2022-05-11  6:21 ` cvs-commit at gcc dot gnu.org
2022-05-11  6:36 ` jakub 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).