Skip to content

Commit 32ca35c

Browse files
committed
Fix SILBridging for GlobalAddr_getDecl
and RefElementAddr_getDecl. Fixes: Assertion failed: (isa<To>(Val) && "cast<Ty>() argument of incompatible type!"), function cast, file Casting.h While running pass swiftlang#224 SILFunctionTransform "LifetimeDependenceDiagnostics" swiftlang#7 0x0000000102d3efcc decltype(auto) llvm::cast<swift::DebugValueInst, swift::SILInstruction>(swift::SILInstruction*) swiftlang#8 0x0000000102d01e24 swift::DebugValueInst* BridgedInstruction::getAs<swift::DebugValueInst>() const swiftlang#9 0x0000000102d01ee4 BridgedInstruction::GlobalAddr_getDecl() const
1 parent 3961729 commit 32ca35c

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

include/swift/SIL/SILBridgingImpl.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -1362,11 +1362,11 @@ BridgedNullableVarDecl BridgedInstruction::AllocBox_getDecl() const {
13621362
}
13631363

13641364
BridgedNullableVarDecl BridgedInstruction::GlobalAddr_getDecl() const {
1365-
return {getAs<swift::DebugValueInst>()->getDecl()};
1365+
return {getAs<swift::GlobalAddrInst>()->getReferencedGlobal()->getDecl()};
13661366
}
13671367

13681368
BridgedNullableVarDecl BridgedInstruction::RefElementAddr_getDecl() const {
1369-
return {getAs<swift::DebugValueInst>()->getDecl()};
1369+
return {getAs<swift::RefElementAddrInst>()->getField()};
13701370
}
13711371

13721372
OptionalBridgedSILDebugVariable

test/SILOptimizer/lifetime_dependence/lifetime_dependence_borrow_fail.swift

+6
Original file line numberDiff line numberDiff line change
@@ -64,3 +64,9 @@ func bv_incorrect_annotation2(_ w1: borrowing Wrapper, _ w2: borrowing Wrapper)
6464
return w1.bv // expected-note @-1{{it depends on the lifetime of argument 'w1'}}
6565
} // expected-note @-1{{this use causes the lifetime-dependent value to escape}}
6666

67+
let ptr = UnsafeRawPointer(bitPattern: 1)!
68+
let nc = NC(ptr, 0) // expected-error {{lifetime-dependent variable 'nc' escapes its scope}}
69+
70+
func bv_global(dummy: BV) -> BV {
71+
nc.getBV()
72+
} // expected-note {{this use causes the lifetime-dependent value to escape}}

0 commit comments

Comments
 (0)