@@ -1875,9 +1875,9 @@ class TailAllocatedDebugVariable {
1875
1875
bool isLet () const { return Bits.Data .Constant ; }
1876
1876
1877
1877
std::optional<SILDebugVariable>
1878
- get (VarDecl *VD, const char *buf, std::optional<SILType> AuxVarType = {} ,
1879
- std::optional<SILLocation> DeclLoc = {} ,
1880
- const SILDebugScope *DeclScope = nullptr ,
1878
+ get (VarDecl *VD, const char *buf, std::optional<SILType> AuxVarType,
1879
+ std::optional<SILLocation> DeclLoc,
1880
+ const SILDebugScope *DeclScope,
1881
1881
llvm::ArrayRef<SILDIExprElement> DIExprElements = {}) const {
1882
1882
if (!Bits.Data .HasValue )
1883
1883
return std::nullopt ;
@@ -2087,11 +2087,18 @@ class AllocStackInst final
2087
2087
SILLocation getVarLoc () const {
2088
2088
if (hasAuxDebugLocation ())
2089
2089
return *getTrailingObjects<SILLocation>();
2090
- return getLoc ();
2090
+ return getLoc (). strippedForDebugVariable () ;
2091
2091
}
2092
2092
2093
2093
// / Return the debug variable information attached to this instruction.
2094
- std::optional<SILDebugVariable> getVarInfo () const {
2094
+ // /
2095
+ // / \param complete If true, always retrieve the complete variable with
2096
+ // / location, scope, and element type. If false, only return the
2097
+ // / values if they are stored (if they are different from the instruction's
2098
+ // / location, scope, and type). This should only be set to false in
2099
+ // / SILPrinter. Incomplete var info is unpredictable, as it will sometimes
2100
+ // / have location and scope and sometimes not.
2101
+ std::optional<SILDebugVariable> getVarInfo (bool complete = true ) const {
2095
2102
// If we used to have debug info attached but our debug info is now
2096
2103
// invalidated, just bail.
2097
2104
if (sharedUInt8 ().AllocStackInst .hasInvalidatedVarInfo ) {
@@ -2103,11 +2110,18 @@ class AllocStackInst final
2103
2110
const SILDebugScope *VarDeclScope = nullptr ;
2104
2111
if (HasAuxDebugVariableType)
2105
2112
AuxVarType = *getTrailingObjects<SILType>();
2113
+ else if (complete)
2114
+ AuxVarType = getElementType ();
2106
2115
2107
2116
if (hasAuxDebugLocation ())
2108
2117
VarDeclLoc = *getTrailingObjects<SILLocation>();
2118
+ else if (complete)
2119
+ VarDeclLoc = getLoc ().strippedForDebugVariable ();
2120
+
2109
2121
if (hasAuxDebugScope ())
2110
2122
VarDeclScope = *getTrailingObjects<const SILDebugScope *>();
2123
+ else if (complete)
2124
+ VarDeclScope = getDebugScope ();
2111
2125
2112
2126
llvm::ArrayRef<SILDIExprElement> DIExprElements (
2113
2127
getTrailingObjects<SILDIExprElement>(), NumDIExprOperands);
@@ -2509,8 +2523,13 @@ class AllocBoxInst final
2509
2523
SILType getAddressType () const ;
2510
2524
2511
2525
// / Return the debug variable information attached to this instruction.
2512
- std::optional<SILDebugVariable> getVarInfo () const {
2513
- return VarInfo.get (getDecl (), getTrailingObjects<char >());
2526
+ std::optional<SILDebugVariable> getVarInfo (bool complete = true ) const {
2527
+ if (complete)
2528
+ return VarInfo.get (getDecl (), getTrailingObjects<char >(),
2529
+ getAddressType ().getObjectType (),
2530
+ getLoc ().strippedForDebugVariable (),
2531
+ getDebugScope ());
2532
+ return VarInfo.get (getDecl (), getTrailingObjects<char >(), {}, {}, nullptr );
2514
2533
};
2515
2534
2516
2535
void setUsesMoveableValueDebugInfo () {
@@ -5385,21 +5404,41 @@ class DebugValueInst final
5385
5404
SILLocation getVarLoc () const {
5386
5405
if (hasAuxDebugLocation ())
5387
5406
return *getTrailingObjects<SILLocation>();
5388
- return getLoc ();
5407
+ return getLoc (). strippedForDebugVariable () ;
5389
5408
}
5390
5409
5391
5410
// / Return the debug variable information attached to this instruction.
5392
- std::optional<SILDebugVariable> getVarInfo () const {
5411
+ // /
5412
+ // / \param complete If true, always retrieve the complete variable with
5413
+ // / location and scope, and the type if possible. If false, only return the
5414
+ // / values if they are stored (if they are different from the instruction's
5415
+ // / location, scope, and type). This should only be set to false in
5416
+ // / SILPrinter. Incomplete var info is unpredictable, as it will sometimes
5417
+ // / have location and scope and sometimes not.
5418
+ // /
5419
+ // / \note The type is not included because it can change during a pass.
5420
+ // / Passes must make sure to not lose the type information.
5421
+ std::optional<SILDebugVariable> getVarInfo (bool complete = true ) const {
5393
5422
std::optional<SILType> AuxVarType;
5394
5423
std::optional<SILLocation> VarDeclLoc;
5395
5424
const SILDebugScope *VarDeclScope = nullptr ;
5425
+
5396
5426
if (HasAuxDebugVariableType)
5397
5427
AuxVarType = *getTrailingObjects<SILType>();
5428
+ // TODO: passes break if we set the type here, as the type of the operand
5429
+ // can be changed during a pass.
5430
+ // else if (complete)
5431
+ // AuxVarType = getOperand()->getType().getObjectType();
5398
5432
5399
5433
if (hasAuxDebugLocation ())
5400
5434
VarDeclLoc = *getTrailingObjects<SILLocation>();
5435
+ else if (complete)
5436
+ VarDeclLoc = getLoc ().strippedForDebugVariable ();
5437
+
5401
5438
if (hasAuxDebugScope ())
5402
5439
VarDeclScope = *getTrailingObjects<const SILDebugScope *>();
5440
+ else if (complete)
5441
+ VarDeclScope = getDebugScope ();
5403
5442
5404
5443
llvm::ArrayRef<SILDIExprElement> DIExprElements (
5405
5444
getTrailingObjects<SILDIExprElement>(), NumDIExprOperands);
0 commit comments