Repository navigation
Objects of empty classes have size zero in generated C (memset overwrites neighbours) #560
lexx42xxel
started this conversation in
Issue Triage - Compilation
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Issue Summary
With USE_EMPTY_STRUCT_IN_GENERATED_C (g++ ABI compatibility) complete objects of an empty class have size zero in the generated C although the class has size 1 in C++. Writing
sizeofbytes to such an object overwrites neighbouring objects; distinct objects may share an address; address constants such as&ga[3]evaluate to&ga[0].Reproducing Source Code
Command-line Options
eccp --c++17 --g++ --exceptions t.cpp -o t && ./t
Type of Issue
[Back End] There is a problem with the generated C code.
Additional Details
Version: EDG C/C++ front end 7.0, main at commit
6a6c7f2d6bd8027f1b0c90877b4ba222fbff6642(2026-11-15).Actual output:
Expected: guard "abc"
Proposed fix: declare such variables (and arrays of them) as
char NAME[size]and refer to themthrough a cast; by-value parameters keep size zero (as in g++) and are referenced through a local
char array; address-constant offsets into such arrays are added on a
char *.The program exits nonzero when the bug is present. A fix with a regression
test is ready (branch
fix/empty-class-object-storage); a PR will reference this issue.AddressSanitizer
The reproducer above is also detected by AddressSanitizer.
Report on main (6a6c7f2), addresses elided:
No report with the fix, nor with g++ (
-fsanitize=address).Reproducing (Standard) Configuration(s)
linux-gcc-debug
Reproducing (Non-standard) Configuration
No response
I acknowledge that:
LICENSE.txtfile in my.zipor.tar.gzupload. If I included aLICENSE.txtfile, any tests created using the reproducing source code will be governed by the terms of the license I provided instead.All reactions