This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/83780] New: False positive alignment error with -fsanitize=undefined with virtual base
- From: "securesneakers at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 11 Jan 2018 01:26:27 +0000
- Subject: [Bug c++/83780] New: False positive alignment error with -fsanitize=undefined with virtual base
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83780
Bug ID: 83780
Summary: False positive alignment error with
-fsanitize=undefined with virtual base
Product: gcc
Version: 7.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: securesneakers at gmail dot com
Target Milestone: ---
Created attachment 43091
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=43091&action=edit
Minimal example that reproduces the issue
Attached program generates false misalignment errors when compiled with
-fsanitize=undefined
$ g++ --version
g++ (GCC) 7.2.1 20171224
$ uname -s -m
Linux x86_64
$ g++ -std=c++11 -O2 -fsanitize=undefined minimal.cpp && ./a.out
minimal.cpp:9:8: runtime error: constructor call on misaligned address
0x7ffdd1e1e658 for type 'struct Base2', which requires 16 byte alignment
Attached example contains following hierarchy:
struct alignas(16) Base1 { };
struct Base2 : virtual Base1 { };
struct Base3 : virtual Base2 { };
alignof(Base2) is set to 16 due to alignment of its base class. But when Base3
is instantiated, Base2 is placed with alignment of 8 as it should be according
to Itanium C++ ABI (due to its non-virtual alignment being equal 8):
https://refspecs.linuxfoundation.org/cxxabi-1.75.html#class-types. Yet
sanitizer complains about alignment not being 16.
Seems that sanitizer checks address using "normal" alignment when "non-virtual
alignment" should be used.