-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Stage2: simple if expression randomly has wrong result when safety checks are enabled #11898
Comments
Valgrind reveals:
Points at .Optional => {
if (value) |payload| { Suggesting that Looking at the LLVM IR: Entry:
%1 = alloca { i8, i1 }, align 1
; here is the block where `self[left_index]` is stored to `left`:
Block: ; preds = %Then1
%19 = extractvalue { i8*, i64 } %15, 0, !dbg !454
%20 = getelementptr inbounds i8, i8* %19, i64 %16, !dbg !454
%21 = load i8, i8* %20, align 1, !dbg !454
%22 = bitcast { i8, i1 }* %1 to i8*, !dbg !454
store i8 %21, i8* %22, align 1, !dbg !454 ; <==== here is the store
br label %Block3, !dbg !454 So we can see that it is storing the payload of the optional, but not setting the non-null bit. The corresponding AIR:
This seems like suspicious AIR code for Sema to emit because Sema is not really supposed to assume the layout of this type. So next I will investigate why this |
With 8bf3e1f reverted, we get the correct behavior:
Then: ; preds = %Entry
%6 = load { i8*, i64 }, { i8*, i64 }* %2, align 8, !dbg !70
%7 = extractvalue { i8*, i64 } %6, 0, !dbg !70
%8 = getelementptr inbounds i8, i8* %7, i64 0, !dbg !70
%9 = load i8, i8* %8, align 1, !dbg !70
%10 = insertvalue { i8, i1 } undef, i8 %9, 0, !dbg !70
%11 = insertvalue { i8, i1 } %10, i1 true, 1, !dbg !70
br label %Block, !dbg !70
Else: ; preds = %Entry
br label %Block, !dbg !70
Block: ; preds = %Else, %Then
%12 = phi { i8, i1 } [ %11, %Then ], [ { i8 undef, i1 false }, %Else ], !dbg !70
store { i8, i1 } %12, { i8, i1 }* %1, align 1, !dbg !70
call void @llvm.dbg.declare(metadata { i8, i1 }* %1, metadata !63, metadata !DIExpression()), !dbg !70 In this case, each prong gets coerced to the optional type, then stored to the result. So I think I will investigate reverting this commit while doing something else to keep all the tests passing. |
This reverts commit 8bf3e1f, which introduced miscompilations for peer expressions any time they needed coercions to runtime types. I opened ziglang#11957 as a proposal to accomplish the goal of the reverted commit. Closes ziglang#11898
The same binary produced by
zig2 test a.zig -femit-bin=a
ran multiple times will sometimes print the correct resultleft 98 right 99
and on other timesleft null right null
. When compiled in a release mode it always produces the correct result,@setRuntimeSafety
does not work as the resulting AIR always has calls topanicOutOfBounds
.This is blocking
std.PriorityQueue
tests.The text was updated successfully, but these errors were encountered: