Skip to content

Commit ecb7315

Browse files
MiloszSkobejkoigcbot
authored andcommitted
Fix DIStringType length emitting in DWARF
For some cases, there wasn't DW_AT_string_length added to variable, which resulted in treating vla array as character.
1 parent 9d5bec3 commit ecb7315

File tree

3 files changed

+32
-16
lines changed

3 files changed

+32
-16
lines changed

IGC/DebugInfo/DwarfCompileUnit.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2034,11 +2034,18 @@ void CompileUnit::constructContainingTypeDIEs() {
20342034
}
20352035
}
20362036

2037-
IGC::DIE *CompileUnit::constructVariableDIE(DbgVariable &DV, bool isScopeAbstract) {
2037+
IGC::DIE *CompileUnit::constructVariableDIE(DbgVariable &DV) {
20382038
StringRef Name = DV.getName();
20392039
LLVM_DEBUG(dbgs() << "[DwarfDebug] constructing DIE for variable <" << Name << ">\n");
20402040
// Define variable debug information entry.
20412041
DIE *VariableDie = new DIE(DV.getTag());
2042+
insertDIE(const_cast<DILocalVariable *>(DV.getVariable()), VariableDie);
2043+
return VariableDie;
2044+
}
2045+
2046+
void CompileUnit::applyVariableAttributes(DbgVariable &DV, DIE *VariableDie, bool isScopeAbstract) {
2047+
StringRef Name = DV.getName();
2048+
LLVM_DEBUG(dbgs() << "[DwarfDebug] applying attributes for DIE variable <" << Name << ">\n");
20422049
DbgVariable *AbsVar = DV.getAbstractVariable();
20432050
DIE *AbsDIE = AbsVar ? AbsVar->getDIE() : NULL;
20442051
if (AbsDIE) {
@@ -2058,7 +2065,7 @@ IGC::DIE *CompileUnit::constructVariableDIE(DbgVariable &DV, bool isScopeAbstrac
20582065
if (isScopeAbstract) {
20592066
DV.setDIE(VariableDie);
20602067
LLVM_DEBUG(dbgs() << " done. Variable is scope-abstract\n");
2061-
return VariableDie;
2068+
return;
20622069
}
20632070

20642071
// Add variable address.
@@ -2079,21 +2086,20 @@ IGC::DIE *CompileUnit::constructVariableDIE(DbgVariable &DV, bool isScopeAbstrac
20792086

20802087
DV.setDIE(VariableDie);
20812088
LLVM_DEBUG(dbgs() << " done. Location is taken from .debug_loc\n");
2082-
return VariableDie;
2089+
return;
20832090
}
20842091

20852092
// Check if variable is described by a DBG_VALUE instruction.
20862093
const Instruction *pDbgInst = DV.getDbgInst();
20872094
if (!pDbgInst || !DV.currentLocationIsInlined()) {
20882095
DV.setDIE(VariableDie);
20892096
LLVM_DEBUG(dbgs() << " done. No dbg.inst assotiated\n");
2090-
return VariableDie;
2097+
return;
20912098
}
20922099

20932100
buildLocation(pDbgInst, DV, VariableDie);
20942101

20952102
LLVM_DEBUG(dbgs() << " done. Location is emitted directly in DIE\n");
2096-
return VariableDie;
20972103
}
20982104

20992105
void CompileUnit::buildLocation(const llvm::Instruction *pDbgInst, DbgVariable &DV, IGC::DIE *VariableDie) {

IGC/DebugInfo/DwarfCompileUnit.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,10 @@ class CompileUnit {
355355
void constructContainingTypeDIEs();
356356

357357
/// constructVariableDIE - Construct a DIE for the given DbgVariable.
358-
DIE *constructVariableDIE(DbgVariable &DV, bool isScopeAbstract);
358+
DIE *constructVariableDIE(DbgVariable &DV);
359+
360+
/// Apply attributes for DIE created in constructVariableDIE
361+
void applyVariableAttributes(DbgVariable &DV, DIE *VariableDie, bool isScopeAbstract);
359362

360363
/// Create a DIE with the given Tag, add the DIE to its parent, and
361364
/// call insertDIE if MD is not null.

IGC/DebugInfo/DwarfDebug.cpp

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,6 @@ DIE *DwarfDebug::createScopeChildrenDIE(CompileUnit *TheCU, LexicalScope *Scope,
682682
DIE *ObjectPointer = NULL;
683683

684684
SmallVector<DbgVariable *, 8> dbgVariables;
685-
686685
// Collect arguments for current function.
687686
if (LScopes.isCurrentFunctionScope(Scope)) {
688687
std::copy(CurrentFnArguments.begin(), CurrentFnArguments.end(), std::back_inserter(dbgVariables));
@@ -694,15 +693,23 @@ DIE *DwarfDebug::createScopeChildrenDIE(CompileUnit *TheCU, LexicalScope *Scope,
694693
std::copy(Variables.begin(), Variables.end(), std::back_inserter(dbgVariables));
695694
}
696695

697-
// Collect all argument/variable children
696+
// Create and collect all argument/variable children
698697
for (DbgVariable *ArgDV : dbgVariables) {
699698
if (!ArgDV)
700699
continue;
701-
if (DIE *Arg = TheCU->constructVariableDIE(*ArgDV, Scope->isAbstractScope())) {
702-
Children.push_back(Arg);
703-
if (ArgDV->isObjectPointer())
704-
ObjectPointer = Arg;
705-
}
700+
DIE *Arg = TheCU->constructVariableDIE(*ArgDV);
701+
Children.push_back(Arg);
702+
if (ArgDV->isObjectPointer())
703+
ObjectPointer = Arg;
704+
}
705+
706+
// Apply attributes to each created DIE. It needs to be done after creating all
707+
// subprogram DIEs, beacuse we might need reference to them in addType() function.
708+
for (DbgVariable *ArgDV : dbgVariables) {
709+
if (!ArgDV)
710+
continue;
711+
DIE *VarDIE = TheCU->getDIE(const_cast<DILocalVariable*>(ArgDV->getVariable()));
712+
TheCU->applyVariableAttributes(*ArgDV, VarDIE, Scope->isAbstractScope());
706713
}
707714

708715
// There is no need to emit empty lexical block DIE.
@@ -1135,9 +1142,9 @@ void DwarfDebug::collectDeadVariables() {
11351142
if (!isa<DILocalVariable>(DV))
11361143
continue;
11371144
DbgVariable NewVar(cast<DILocalVariable>(DV));
1138-
if (DIE *VariableDIE = SPCU->constructVariableDIE(NewVar, false)) {
1139-
SPDIE->addChild(VariableDIE);
1140-
}
1145+
DIE *VariableDIE = SPCU->constructVariableDIE(NewVar);
1146+
SPCU->applyVariableAttributes(NewVar, VariableDIE, false);
1147+
SPDIE->addChild(VariableDIE);
11411148
}
11421149
}
11431150

0 commit comments

Comments
 (0)