@@ -1056,7 +1056,7 @@ llvm::Expected<SILFunction *> SILDeserializer::readSILFunctionChecked(
1056
1056
1057
1057
GenericEnvironment *genericEnv = nullptr ;
1058
1058
// Generic signatures are stored for declarations as well in a debug context.
1059
- if (!declarationOnly || onlyReferencedByDebugInfo)
1059
+ if (!declarationOnly || onlyReferencedByDebugInfo || genericSigID )
1060
1060
genericEnv = MF->getGenericSignature (genericSigID).getGenericEnvironment ();
1061
1061
1062
1062
// If the next entry is the end of the block, then this function has
@@ -1066,8 +1066,8 @@ llvm::Expected<SILFunction *> SILDeserializer::readSILFunctionChecked(
1066
1066
return maybeEntry.takeError ();
1067
1067
entry = maybeEntry.get ();
1068
1068
bool isEmptyFunction = (entry.Kind == llvm::BitstreamEntry::EndBlock);
1069
- assert ((!isEmptyFunction || !genericEnv || onlyReferencedByDebugInfo) &&
1070
- " generic environment without body?!" );
1069
+ assert ((!isEmptyFunction || !genericEnv || onlyReferencedByDebugInfo ||
1070
+ genericSigID) && " generic environment without body?!" );
1071
1071
1072
1072
// Remember this in our cache in case it's a recursive function.
1073
1073
// Increase the reference count to keep it alive.
@@ -1133,7 +1133,8 @@ llvm::Expected<SILFunction *> SILDeserializer::readSILFunctionChecked(
1133
1133
1134
1134
auto Scope = maybeScope.get ();
1135
1135
if (isFirstScope) {
1136
- fn->setDebugScope (Scope);
1136
+ if (!fn->getDebugScope () || fn->getDebugScope ()->getLoc ().isAutoGenerated ())
1137
+ fn->setDebugScope (Scope);
1137
1138
isFirstScope = false ;
1138
1139
}
1139
1140
Builder.setCurrentDebugScope (Scope);
@@ -1421,6 +1422,8 @@ bool SILDeserializer::readSILInstruction(SILFunction *Fn,
1421
1422
switch (RecordKind) {
1422
1423
default :
1423
1424
llvm_unreachable (" Record kind for a SIL instruction is not supported." );
1425
+ case SIL_DEBUG_VALUE_DELIMITER:
1426
+ return false ;
1424
1427
case SIL_ONE_VALUE_ONE_OPERAND:
1425
1428
SILOneValueOneOperandLayout::readRecord (scratch, RawOpCode, Attr,
1426
1429
ValID, TyID, TyCategory,
@@ -1593,20 +1596,121 @@ bool SILDeserializer::readSILInstruction(SILFunction *Fn,
1593
1596
SILThunkLayout::readRecord (scratch, Attr, TyID, TyCategory, ValID, SubID);
1594
1597
RawOpCode = unsigned (SILInstructionKind::ThunkInst);
1595
1598
break ;
1599
+
1600
+ case SIL_DEBUG_VALUE:
1601
+ SILDebugValueLayout::readRecord (scratch, TyCategory, TyCategory2, Attr,
1602
+ ListOfValues);
1603
+ RawOpCode = (unsigned )SILInstructionKind::DebugValueInst;
1604
+
1605
+ break ;
1596
1606
}
1597
1607
1598
1608
// FIXME: validate
1599
1609
SILInstructionKind OpCode = (SILInstructionKind) RawOpCode;
1600
1610
1601
1611
SILInstruction *ResultInst;
1602
1612
switch (OpCode) {
1603
- case SILInstructionKind::DebugValueInst:
1604
1613
case SILInstructionKind::DebugStepInst:
1605
1614
case SILInstructionKind::SpecifyTestInst:
1606
1615
case SILInstructionKind::AllocPackMetadataInst:
1607
1616
case SILInstructionKind::DeallocPackMetadataInst:
1608
1617
llvm_unreachable (" not supported" );
1609
1618
1619
+ case SILInstructionKind::DebugValueInst: {
1620
+ assert (ListOfValues.size () >= 2 && " Unexpected number of values" );
1621
+ SILValue Value =
1622
+ getLocalValue (Fn, ListOfValues[0 ],
1623
+ getSILType (MF->getType (ListOfValues[1 ]),
1624
+ (SILValueCategory)TyCategory, Fn));
1625
+
1626
+ auto PoisonRefs = PoisonRefs_t (Attr & 0x1 );
1627
+ auto UsesMoveableValDebugInfo =
1628
+ UsesMoveableValueDebugInfo_t ((Attr >> 1 ) & 0x1 );
1629
+ auto HasTrace = (Attr >> 2 ) & 0x1 ;
1630
+
1631
+ bool HaveDebugVar = (Attr >> 3 ) & 0x1 ;
1632
+ bool HasLoc = false ;
1633
+
1634
+ SILDebugVariable DebugVar;
1635
+ if (HaveDebugVar) {
1636
+ assert (ListOfValues.size () >= 4 && " Unexpected number of values" );
1637
+ bool IsLet = (Attr >> 4 ) & 0x1 ;
1638
+ unsigned IsDenseMapSingleton = (Attr >> 5 ) & 0x3 ;
1639
+ bool HasType = (Attr >> 7 ) & 0x1 ;
1640
+ bool HasScope = (Attr >> 8 ) & 0x1 ;
1641
+ HasLoc = (Attr >> 9 ) & 0x1 ;
1642
+
1643
+ auto VarName = MF->getIdentifierText (ListOfValues[2 ]);
1644
+ auto ArgNo = ListOfValues[3 ];
1645
+ std::optional<SILType> Type;
1646
+
1647
+ unsigned I = 4 ;
1648
+ unsigned Row, Col;
1649
+ StringRef FileName;
1650
+ std::optional<SILLocation> Loc;
1651
+ if (HasType) {
1652
+ Type = getSILType (MF->getType (ListOfValues[I++]),
1653
+ (SILValueCategory)TyCategory2, Fn);
1654
+ }
1655
+
1656
+ if (HasLoc) {
1657
+ Row = ListOfValues[I++];
1658
+ Col = ListOfValues[I++];
1659
+ FileName = MF->getIdentifierText (ListOfValues[I++]);
1660
+ Loc = RegularLocation (SILLocation::FilenameAndLocation::alloc (
1661
+ Row, Col, FileName, Fn->getModule ()));
1662
+ }
1663
+
1664
+ SILDebugInfoExpression Expressions;
1665
+ while (I < ListOfValues.size ()) {
1666
+ using DIExpr = SILDIExprElement;
1667
+ SILDIExprElement::Kind Kind = (SILDIExprElement::Kind)ListOfValues[I++];
1668
+ switch (Kind) {
1669
+ case DIExpr::OperatorKind:
1670
+ Expressions.push_back (
1671
+ DIExpr::createOperator ((SILDIExprOperator)ListOfValues[I++]));
1672
+ break ;
1673
+ case DIExpr::DeclKind:
1674
+ Expressions.push_back (
1675
+ DIExpr::createDecl (MF->getDecl (ListOfValues[I++])));
1676
+ break ;
1677
+ case DIExpr::ConstIntKind: {
1678
+ auto Str = MF->getIdentifierText (ListOfValues[I++]);
1679
+ APInt Int;
1680
+ Str.getAsInteger (10 , Int);
1681
+ Expressions.push_back (DIExpr::createConstInt (Int.getLimitedValue ()));
1682
+ break ;
1683
+ }
1684
+ case SILDIExprElement::Kind::TypeKind:
1685
+ Expressions.push_back (
1686
+ DIExpr::createType (MF->getType (ListOfValues[I++])));
1687
+ break ;
1688
+ }
1689
+ }
1690
+
1691
+ const SILDebugScope *Scope = nullptr ;
1692
+ if (HasScope) {
1693
+ SmallVector<uint64_t , 64 > scratch;
1694
+ auto maybeKind = readNextRecord (scratch);
1695
+ if (!maybeKind) MF->fatal (maybeKind.takeError ());
1696
+ auto maybeScope = readDebugScopes (Fn, scratch, Builder, maybeKind.get ());
1697
+ if (!maybeScope) MF->fatal (maybeScope.takeError ());
1698
+ Scope = maybeScope.get ();
1699
+ }
1700
+
1701
+ DebugVar = SILDebugVariable (
1702
+ VarName, IsLet, ArgNo, Type, Loc, Scope,
1703
+ llvm::ArrayRef<SILDIExprElement>(Expressions.element_begin (),
1704
+ Expressions.element_end ()));
1705
+ DebugVar.isDenseMapSingleton = IsDenseMapSingleton;
1706
+ }
1707
+
1708
+ ResultInst =
1709
+ Builder.createDebugValue (Loc, Value, DebugVar, PoisonRefs,
1710
+ UsesMoveableValDebugInfo, HasTrace, !HasLoc);
1711
+
1712
+ break ;
1713
+ }
1610
1714
case SILInstructionKind::AllocBoxInst: {
1611
1715
assert (RecordKind == SIL_ONE_TYPE && " Layout should be OneType." );
1612
1716
auto hasDynamicLifetime = HasDynamicLifetime_t (Attr & 0x1 );
0 commit comments