Skip to content

[6.0][IRGen] Properly compute bit mask for extra tag bits in CVW #75525

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

Merged
merged 1 commit into from
Jul 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/IRGen/GenEnum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1696,7 +1696,7 @@ namespace {
projectedBits = IGF.Builder.CreateElementBitCast(projectedBits, IGM.Int8Ty);
}
extraTag = IGF.Builder.CreateLoad(projectedBits);
auto maskBits = llvm::PowerOf2Ceil(NumExtraTagValues) - 1;
auto maskBits = (1 << ExtraTagBitCount) - 1;
auto mask = llvm::ConstantInt::get(extraTag->getType(), maskBits);
extraTag = IGF.Builder.CreateAnd(extraTag, mask);
} else {
Expand Down
32 changes: 32 additions & 0 deletions test/Interpreter/Inputs/layout_string_witnesses_types.swift
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,38 @@ public enum TwoPayloadOuter {
case y(TwoPayloadInner)
}

public enum OneExtraTagValue {
public enum E0 {
case a(Bool)
case b(Bool)
}

public enum E1 {
case a(E0)
case b(Bool)
}
public enum E2 {
case a(E1)
case b(Bool)
}
public enum E3 {
case a(E2)
case b(Bool)
}

public enum E4 {
case a(E3)
case b(Bool)
}

case x0(E4, Int8, Int16, Int32)
case x1(E4, Int8, Int16, Int32)
case x2(E4, Int8, Int16, Int32)
case x3(E4, Int8, Int16, Int32)
case y(SimpleClass)
case z
}

@inline(never)
public func consume<T>(_ x: T.Type) {
withExtendedLifetime(x) {}
Expand Down
29 changes: 29 additions & 0 deletions test/Interpreter/layout_string_witnesses_static.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1319,6 +1319,35 @@ func testNestedTwoPayload() {

testNestedTwoPayload()

func testMultiPayloadOneExtraTagValue() {
let ptr = UnsafeMutablePointer<OneExtraTagValue>.allocate(capacity: 1)

do {
let x = OneExtraTagValue.y(SimpleClass(x: 23))
testInit(ptr, to: x)
}

do {
let y = OneExtraTagValue.y(SimpleClass(x: 1))

// CHECK: Before deinit
print("Before deinit")

// CHECK-NEXT: SimpleClass deinitialized!
testAssign(ptr, from: y)
}

// CHECK-NEXT: Before deinit
print("Before deinit")

// CHECK-NEXT: SimpleClass deinitialized!
testDestroy(ptr)

ptr.deallocate()
}

testMultiPayloadOneExtraTagValue()

#if os(macOS)
func testObjc() {
let ptr = UnsafeMutablePointer<ObjcWrapper>.allocate(capacity: 1)
Expand Down