New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
c++11: constant emitter needs to zero-initialize padding for trivially-copyable types #12114
Comments
A testcase or three would be nice. |
Simple example: struct S { char c = 1; attribute((aligned(8))) char d = 2; } s = S(); ... gives ... @s = global %struct.S { i8 1, [7 x i8] undef, i8 2, [7 x i8] undef }, align 8 ... which is wrong. The padding should be zeroed. Running this through opt -instcombine -globalopt gives: @k = global i8 undef, align 1 ... which is wrong. k should be 1. (Running this through just opt -globalopt strangely gives @k = global i8 1, align 1 which Nick tells me is a bug in globalopt.) |
If the C++11 standard really says that padding must be initialized to zero |
It really does. C++11 [dcl.init]p6: "To zero-initialize an object or reference of type T means: |
I partially fixed this in dragonegg in commit 169678. There remains the case |
I'm not sure what your notation means, but if you mean something like 'struct S { char A; int B; };', then yes, if an object of type S is zero-initialized, the padding between fields must be initialized to zero bits. In Clang at least, such a struct is emitted as 'global %struct.S { i8 1, i32 2 }'. It's not clear to me whether the padding is zero or undef in this case. |
I'm pretty sure the padding is "undef" in this case. |
@llvm/issue-subscribers-clang-codegen Author: None (ec04fc15-fa35-46f2-80e1-5d271f2ef708)
| | |
| --- | --- |
| Bugzilla Link | [11742](https://llvm.org/bz11742) |
| Version | unspecified |
| OS | Linux |
| CC | @DougGregor |
Extended DescriptionPadding for objects with static storage duration is currently emitted as undef. This is non-conforming in C++11, because:
Hence a conforming program can tell whether the padding has been zero-initialized. |
Extended Description
Padding for objects with static storage duration is currently emitted as undef. This is non-conforming in C++11, because:
Hence a conforming program can tell whether the padding has been zero-initialized.
The text was updated successfully, but these errors were encountered: