-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
struct field load through underaligned pointer has incorrect alignment #14904
Labels
backend-c
The C backend (CBE) outputs C source code.
bug
Observed behavior contradicts documented or intended behavior
frontend
Tokenization, parsing, AstGen, Sema, and Liveness.
miscompilation
The compiler reports success but produces semantically incorrect code.
regression
It worked in a previous version of Zig, but stopped working.
Milestone
Comments
andrewrk
added
bug
Observed behavior contradicts documented or intended behavior
frontend
Tokenization, parsing, AstGen, Sema, and Liveness.
backend-llvm
The LLVM backend outputs an LLVM IR Module.
regression
It worked in a previous version of Zig, but stopped working.
labels
Mar 13, 2023
andrewrk
added
the
miscompilation
The compiler reports success but produces semantically incorrect code.
label
Mar 13, 2023
truemedian
pushed a commit
to truemedian/zig
that referenced
this issue
Mar 30, 2023
See tracking issue ziglang#14904
andrewrk
added a commit
that referenced
this issue
Aug 1, 2023
std.zig.Server: remove workaround for fixed issue closes #14904 Note the C backend is not passing the new test.
andrewrk
added a commit
that referenced
this issue
Aug 1, 2023
The workaround in std.zig.Server remains because the C backend is not passing the new test. see #14904
andrewrk
added
backend-c
The C backend (CBE) outputs C source code.
and removed
backend-llvm
The LLVM backend outputs an LLVM IR Module.
labels
Aug 1, 2023
Fixed for the LLVM backend; issue remains for the C backend. |
andrewrk
added a commit
that referenced
this issue
Aug 1, 2023
The workaround in std.zig.Server remains because the C backend is not passing the new test. see #14904
LinuxUserGD
pushed a commit
to LinuxUserGD/zig
that referenced
this issue
Aug 2, 2023
The workaround in std.zig.Server remains because the C backend is not passing the new test. see ziglang#14904
QusaiHroub
pushed a commit
to QusaiHroub/zig
that referenced
this issue
Aug 3, 2023
The workaround in std.zig.Server remains because the C backend is not passing the new test. see ziglang#14904
C code generated is now: static uint16_t test_doTheTest__251(void) {
static uint8_t const t1[9] = "\001\002\003\004\005\006\a\b\t";
uint8_t *t2;
uint8_t (*t3)[8];
struct Header__885 *t4;
uint32_t *t5;
uint32_t t6;
zig_align(4) uint8_t t0[9];
memcpy((char *)&t0, t1, sizeof(uint8_t[9]));
t2 = (uint8_t *)&t0;
t2 = (uint8_t *)(((uintptr_t)t2) + ((uintptr_t)1ul*sizeof(uint8_t)));
t3 = (uint8_t (*)[8])t2;
t4 = (struct Header__885 *)t3;
t5 = (uint32_t *)&t4->bytes_len;
memcpy(&t6, (const char *)t5, sizeof(uint32_t));
foo(t6);
return UINT16_C(0);
} The |
Hmm the actual behavior test is not fixed however: --- a/test/behavior/align.zig
+++ b/test/behavior/align.zig
@@ -624,7 +624,6 @@ test "sub-aligned pointer field access" {
if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest;
- if (builtin.zig_backend == .stage2_c) return error.SkipZigTest;
// Originally reported at https://github.com/ziglang/zig/issues/14904
Looks like the pointer cast causes UB even though the pointer is not accessed. |
jacobly0
added a commit
to jacobly0/zig
that referenced
this issue
Mar 29, 2024
jacobly0
added a commit
to jacobly0/zig
that referenced
this issue
Mar 30, 2024
jacobly0
added a commit
to jacobly0/zig
that referenced
this issue
Mar 31, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
backend-c
The C backend (CBE) outputs C source code.
bug
Observed behavior contradicts documented or intended behavior
frontend
Tokenization, parsing, AstGen, Sema, and Liveness.
miscompilation
The compiler reports success but produces semantically incorrect code.
regression
It worked in a previous version of Zig, but stopped working.
Zig Version
0.11.0-dev.1969+d525ecb52
Steps to Reproduce and Observed Behavior
The problem is incorrect alignment in the LLVM IR:
The problem is
%6 = load i32, ptr %5, align 4
which has align 4 instead of align 1.Side note: it is very annoying that the
panic
override above does not eliminatepanicOutOfBounds
from calling intostd.debug.panicExtra
and dragging in a whole lot of formatting code.I have no evidence this is a regression, but I suspect it is.
Expected Behavior
I expect to see
%6 = load i32, ptr %5, align 1
which would cause LLVM to generate machine code that did not cause a Bus Error.The text was updated successfully, but these errors were encountered: