@@ -1875,9 +1875,9 @@ class TailAllocatedDebugVariable {
18751875 bool isLet () const { return Bits.Data .Constant ; }
18761876
18771877 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,
18811881 llvm::ArrayRef<SILDIExprElement> DIExprElements = {}) const {
18821882 if (!Bits.Data .HasValue )
18831883 return std::nullopt ;
@@ -2087,11 +2087,18 @@ class AllocStackInst final
20872087 SILLocation getVarLoc () const {
20882088 if (hasAuxDebugLocation ())
20892089 return *getTrailingObjects<SILLocation>();
2090- return getLoc ();
2090+ return getLoc (). strippedForDebugVariable () ;
20912091 }
20922092
20932093 // / 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 {
20952102 // If we used to have debug info attached but our debug info is now
20962103 // invalidated, just bail.
20972104 if (sharedUInt8 ().AllocStackInst .hasInvalidatedVarInfo ) {
@@ -2103,11 +2110,18 @@ class AllocStackInst final
21032110 const SILDebugScope *VarDeclScope = nullptr ;
21042111 if (HasAuxDebugVariableType)
21052112 AuxVarType = *getTrailingObjects<SILType>();
2113+ else if (complete)
2114+ AuxVarType = getElementType ();
21062115
21072116 if (hasAuxDebugLocation ())
21082117 VarDeclLoc = *getTrailingObjects<SILLocation>();
2118+ else if (complete)
2119+ VarDeclLoc = getLoc ().strippedForDebugVariable ();
2120+
21092121 if (hasAuxDebugScope ())
21102122 VarDeclScope = *getTrailingObjects<const SILDebugScope *>();
2123+ else if (complete)
2124+ VarDeclScope = getDebugScope ();
21112125
21122126 llvm::ArrayRef<SILDIExprElement> DIExprElements (
21132127 getTrailingObjects<SILDIExprElement>(), NumDIExprOperands);
@@ -2509,8 +2523,13 @@ class AllocBoxInst final
25092523 SILType getAddressType () const ;
25102524
25112525 // / 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 );
25142533 };
25152534
25162535 void setUsesMoveableValueDebugInfo () {
@@ -5385,21 +5404,41 @@ class DebugValueInst final
53855404 SILLocation getVarLoc () const {
53865405 if (hasAuxDebugLocation ())
53875406 return *getTrailingObjects<SILLocation>();
5388- return getLoc ();
5407+ return getLoc (). strippedForDebugVariable () ;
53895408 }
53905409
53915410 // / 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 {
53935422 std::optional<SILType> AuxVarType;
53945423 std::optional<SILLocation> VarDeclLoc;
53955424 const SILDebugScope *VarDeclScope = nullptr ;
5425+
53965426 if (HasAuxDebugVariableType)
53975427 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();
53985432
53995433 if (hasAuxDebugLocation ())
54005434 VarDeclLoc = *getTrailingObjects<SILLocation>();
5435+ else if (complete)
5436+ VarDeclLoc = getLoc ().strippedForDebugVariable ();
5437+
54015438 if (hasAuxDebugScope ())
54025439 VarDeclScope = *getTrailingObjects<const SILDebugScope *>();
5440+ else if (complete)
5441+ VarDeclScope = getDebugScope ();
54035442
54045443 llvm::ArrayRef<SILDIExprElement> DIExprElements (
54055444 getTrailingObjects<SILDIExprElement>(), NumDIExprOperands);
0 commit comments