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.

Reply via email to