public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug sanitizer/114637] New: Problems when compiling with both undefined and address sanitizer
@ 2024-04-08 10:21 teodor_spaeren at riseup dot net
  2024-04-08 11:53 ` [Bug sanitizer/114637] " teodor_spaeren at riseup dot net
  2024-04-08 15:43 ` xry111 at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: teodor_spaeren at riseup dot net @ 2024-04-08 10:21 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 114637
           Summary: Problems when compiling with both undefined and
                    address sanitizer
           Product: gcc
           Version: 13.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: sanitizer
          Assignee: unassigned at gcc dot gnu.org
          Reporter: teodor_spaeren at riseup dot net
                CC: dodji at gcc dot gnu.org, dvyukov at gcc dot gnu.org,
                    jakub at gcc dot gnu.org, kcc at gcc dot gnu.org
  Target Milestone: ---

Here is the code:

#include <cstdint>
#include <memory>

struct RingBuffer
{
  alignas(64) std::uint64_t m_head{ 0xFAFAFAFAFAFAFAFA };

  int good()
  {
    return m_head == 2;
  }
};

int main() {
  RingBuffer buffer;
  return buffer.good();
}


Gcc version:
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/13.2.1/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /build/gcc/src/gcc/configure
--enable-languages=ada,c,c++,d,fortran,go,lto,m2,objc,obj-c++
--enable-bootstrap --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib
--mandir=/usr/share/man --infodir=/usr/share/info
--with-bugurl=https://bugs.archlinux.org/ --with-build-config=bootstrap-lto
--with-linker-hash-style=gnu --with-system-zlib --enable-__cxa_atexit
--enable-cet=auto --enable-checking=release --enable-clocale=gnu
--enable-default-pie --enable-default-ssp --enable-gnu-indirect-function
--enable-gnu-unique-object --enable-libstdcxx-backtrace
--enable-link-serialization=1 --enable-linker-build-id --enable-lto
--enable-multilib --enable-plugin --enable-shared --enable-threads=posix
--disable-libssp --disable-libstdcxx-pch --disable-werror
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 13.2.1 20230801 (GCC) 


The problem is that when compiling with:

g++ -std=c++2a -Wall -Wextra -fsanitize=undefined,address -o w
compiler_bug_2.cpp -g -D_GLIBCXX_DEBUG

Running gives:

dragon % ./w 
compiler_bug_2.cpp:10:12: runtime error: member access within misaligned
address 0x7f4264f09020 for type 'struct RingBuffer', which requires 64 byte
alignment
0x7f4264f09020: note: pointer points here
 fd 7f 00 00  fa fa fa fa fa fa fa fa  00 00 00 00 00 00 00 00  00 00 00 00 00
00 00 00  00 00 00 00

Without `address` or without `undefined`, this runtime error does not occur.
I've checked the value of the pointer at runtime and it's aligned when running
under the debugger.

I have another repo, where I am able to force it in my debugger:

https://github.com/rHermes/hage/commit/b76cf0cddfadde1f647c575cb1a615d655e7dfbe

After building I am able to get it with:

/home/rhermes/commons/projects/hage/cmake-build-debug/tests/hage_test
"--test-case=ByteBuffer tests<hage::RingBuffer<4096>>" -ni

In the debugger.

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

* [Bug sanitizer/114637] Problems when compiling with both undefined and address sanitizer
  2024-04-08 10:21 [Bug sanitizer/114637] New: Problems when compiling with both undefined and address sanitizer teodor_spaeren at riseup dot net
@ 2024-04-08 11:53 ` teodor_spaeren at riseup dot net
  2024-04-08 15:43 ` xry111 at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: teodor_spaeren at riseup dot net @ 2024-04-08 11:53 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from teodor_spaeren at riseup dot net ---
Just to clearify here, the error only occurs when
`-fsanitize=undefined,address` are used together. Either alone works just fine.

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

* [Bug sanitizer/114637] Problems when compiling with both undefined and address sanitizer
  2024-04-08 10:21 [Bug sanitizer/114637] New: Problems when compiling with both undefined and address sanitizer teodor_spaeren at riseup dot net
  2024-04-08 11:53 ` [Bug sanitizer/114637] " teodor_spaeren at riseup dot net
@ 2024-04-08 15:43 ` xry111 at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: xry111 at gcc dot gnu.org @ 2024-04-08 15:43 UTC (permalink / raw)
  To: gcc-bugs

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

Xi Ruoyao <xry111 at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |xry111 at gcc dot gnu.org
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |DUPLICATE

--- Comment #2 from Xi Ruoyao <xry111 at gcc dot gnu.org> ---
This is almost an exact dup of #113053, and #113053 is marked as a dup of
#110027 despite not related to vector types.

*** This bug has been marked as a duplicate of bug 110027 ***

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

end of thread, other threads:[~2024-04-08 15:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-08 10:21 [Bug sanitizer/114637] New: Problems when compiling with both undefined and address sanitizer teodor_spaeren at riseup dot net
2024-04-08 11:53 ` [Bug sanitizer/114637] " teodor_spaeren at riseup dot net
2024-04-08 15:43 ` xry111 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).