@@ -450,17 +450,17 @@ public enum VariableScopeInstruction {
450
450
scopeBegin. uses. lazy. filter { $0. endsLifetime || $0. instruction is ExtendLifetimeInst }
451
451
}
452
452
453
- // TODO: with SIL verification, we might be able to make varDecl non-Optional.
454
- public var varDecl : VarDecl ? {
455
- if let debugVarDecl = instruction. debugResultDecl {
456
- return debugVarDecl
457
- }
453
+ // TODO: assert that VarDecl is valid whenever isFromVarDecl returns tyue.
454
+ public func findVarDecl( ) -> VarDecl ? {
458
455
// SILGen may produce double var_decl instructions for the same variable:
459
456
// %box = alloc_box [var_decl] "x"
460
457
// begin_borrow %box [var_decl]
461
458
//
462
- // Assume that, if the begin_borrow or move_value does not have its own debug_value, then it must actually be
463
- // associated with its operand's var_decl.
459
+ // Therefore, first check if begin_borrow or move_value has any debug_value users.
460
+ if let debugVarDecl = instruction. findVarDeclFromDebugUsers ( ) {
461
+ return debugVarDecl
462
+ }
463
+ // Otherwise, assume that the var_decl is associated with its operand's var_decl.
464
464
return instruction. operands [ 0 ] . value. definingInstruction? . findVarDecl ( )
465
465
}
466
466
}
@@ -472,14 +472,14 @@ extension Instruction {
472
472
return varDeclInst. varDecl
473
473
}
474
474
if let varScopeInst = VariableScopeInstruction ( self ) {
475
- return varScopeInst. varDecl
475
+ return varScopeInst. findVarDecl ( )
476
476
}
477
- return debugResultDecl
477
+ return findVarDeclFromDebugUsers ( )
478
478
}
479
479
480
- var debugResultDecl : VarDecl ? {
480
+ func findVarDeclFromDebugUsers ( ) -> VarDecl ? {
481
481
for result in results {
482
- if let varDecl = result. debugUserDecl {
482
+ if let varDecl = result. findVarDeclFromDebugUsers ( ) {
483
483
return varDecl
484
484
}
485
485
}
@@ -488,14 +488,14 @@ extension Instruction {
488
488
}
489
489
490
490
extension Value {
491
- var debugValDecl : VarDecl ? {
491
+ public func findVarDecl ( ) -> VarDecl ? {
492
492
if let arg = self as? Argument {
493
- return arg. varDecl
493
+ return arg. findVarDecl ( )
494
494
}
495
- return debugUserDecl
495
+ return findVarDeclFromDebugUsers ( )
496
496
}
497
497
498
- var debugUserDecl : VarDecl ? {
498
+ func findVarDeclFromDebugUsers ( ) -> VarDecl ? {
499
499
for use in uses {
500
500
if let debugVal = use. instruction as? DebugValueInst {
501
501
return debugVal. varDecl
0 commit comments