Skip to content

Commit ff3b513

Browse files
committed
Revert d91ed80 "[codeview] Reference types in type parent scopes"
This triggered asserts in the Chromium build, see https://crbug.com/1022729 for details and reproducer. > Without this change, when a nested tag type of any kind (enum, class, > struct, union) is used as a variable type, it is emitted without > emitting the parent type. In CodeView, parent types point to their inner > types, and inner types do not point back to their parents. We already > walk over all of the parent scopes to build the fully qualified name. > This change simply requests their type indices as we go along to enusre > they are all emitted. > > Fixes PR43905 > > Reviewers: akhuang, amccarth > > Differential Revision: https://reviews.llvm.org/D69924
1 parent f649f24 commit ff3b513

File tree

4 files changed

+16
-170
lines changed

4 files changed

+16
-170
lines changed

llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -303,19 +303,12 @@ static StringRef getPrettyScopeName(const DIScope *Scope) {
303303
return StringRef();
304304
}
305305

306-
const DISubprogram *CodeViewDebug::collectParentScopeNames(
306+
static const DISubprogram *getQualifiedNameComponents(
307307
const DIScope *Scope, SmallVectorImpl<StringRef> &QualifiedNameComponents) {
308308
const DISubprogram *ClosestSubprogram = nullptr;
309309
while (Scope != nullptr) {
310310
if (ClosestSubprogram == nullptr)
311311
ClosestSubprogram = dyn_cast<DISubprogram>(Scope);
312-
313-
// If a type appears in a scope chain, make sure it gets emitted. The
314-
// frontend will be responsible for deciding if this should be a forward
315-
// declaration or a complete type.
316-
if (const auto *Ty = dyn_cast<DIType>(Scope))
317-
(void)getTypeIndex(Ty);
318-
319312
StringRef ScopeName = getPrettyScopeName(Scope);
320313
if (!ScopeName.empty())
321314
QualifiedNameComponents.push_back(ScopeName);
@@ -324,9 +317,8 @@ const DISubprogram *CodeViewDebug::collectParentScopeNames(
324317
return ClosestSubprogram;
325318
}
326319

327-
std::string
328-
CodeViewDebug::formatNestedName(ArrayRef<StringRef> QualifiedNameComponents,
329-
StringRef TypeName) {
320+
static std::string getQualifiedName(ArrayRef<StringRef> QualifiedNameComponents,
321+
StringRef TypeName) {
330322
std::string FullyQualifiedName;
331323
for (StringRef QualifiedNameComponent :
332324
llvm::reverse(QualifiedNameComponents)) {
@@ -337,15 +329,10 @@ CodeViewDebug::formatNestedName(ArrayRef<StringRef> QualifiedNameComponents,
337329
return FullyQualifiedName;
338330
}
339331

340-
std::string CodeViewDebug::getFullyQualifiedName(const DIScope *Scope, StringRef Name) {
332+
static std::string getFullyQualifiedName(const DIScope *Scope, StringRef Name) {
341333
SmallVector<StringRef, 5> QualifiedNameComponents;
342-
collectParentScopeNames(Scope, QualifiedNameComponents);
343-
return formatNestedName(QualifiedNameComponents, Name);
344-
}
345-
346-
std::string CodeViewDebug::getFullyQualifiedName(const DIScope *Ty) {
347-
const DIScope *Scope = Ty->getScope();
348-
return getFullyQualifiedName(Scope, getPrettyScopeName(Ty));
334+
getQualifiedNameComponents(Scope, QualifiedNameComponents);
335+
return getQualifiedName(QualifiedNameComponents, Name);
349336
}
350337

351338
struct CodeViewDebug::TypeLoweringScope {
@@ -360,6 +347,11 @@ struct CodeViewDebug::TypeLoweringScope {
360347
CodeViewDebug &CVD;
361348
};
362349

350+
static std::string getFullyQualifiedName(const DIScope *Ty) {
351+
const DIScope *Scope = Ty->getScope();
352+
return getFullyQualifiedName(Scope, getPrettyScopeName(Ty));
353+
}
354+
363355
TypeIndex CodeViewDebug::getScopeIndex(const DIScope *Scope) {
364356
// No scope means global scope and that uses the zero index.
365357
if (!Scope || isa<DIFile>(Scope))
@@ -1476,12 +1468,12 @@ void CodeViewDebug::addToUDTs(const DIType *Ty) {
14761468
if (!shouldEmitUdt(Ty))
14771469
return;
14781470

1479-
SmallVector<StringRef, 5> ParentScopeNames;
1471+
SmallVector<StringRef, 5> QualifiedNameComponents;
14801472
const DISubprogram *ClosestSubprogram =
1481-
collectParentScopeNames(Ty->getScope(), ParentScopeNames);
1473+
getQualifiedNameComponents(Ty->getScope(), QualifiedNameComponents);
14821474

14831475
std::string FullyQualifiedName =
1484-
formatNestedName(ParentScopeNames, getPrettyScopeName(Ty));
1476+
getQualifiedName(QualifiedNameComponents, getPrettyScopeName(Ty));
14851477

14861478
if (ClosestSubprogram == nullptr) {
14871479
GlobalUDTs.emplace_back(std::move(FullyQualifiedName), Ty);

llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -443,19 +443,6 @@ class LLVM_LIBRARY_VISIBILITY CodeViewDebug : public DebugHandlerBase {
443443
codeview::TypeIndex TI,
444444
const DIType *ClassTy = nullptr);
445445

446-
/// Collect the names of parent scopes, innermost to outermost. Return the
447-
/// innermost subprogram scope if present. Ensure that parent type scopes are
448-
/// inserted into the type table.
449-
const DISubprogram *
450-
collectParentScopeNames(const DIScope *Scope,
451-
SmallVectorImpl<StringRef> &ParentScopeNames);
452-
453-
std::string formatNestedName(ArrayRef<StringRef> ParentScopeNames,
454-
StringRef TypeName);
455-
456-
std::string getFullyQualifiedName(const DIScope *Scope, StringRef Name);
457-
std::string getFullyQualifiedName(const DIScope *Scope);
458-
459446
unsigned getPointerSizeInBytes();
460447

461448
protected:

llvm/test/DebugInfo/COFF/global-constants.ll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
; ASM-NEXT: .asciz "S::TestConst2" # Name
3737
; ASM: .short {{.*-.*}} # Record length
3838
; ASM: .short 4359 # Record kind: S_CONSTANT
39-
; ASM-NEXT: .long 4113 # Type
39+
; ASM-NEXT: .long 4105 # Type
4040
; ASM-NEXT: .byte 0x0a, 0x80, 0x40, 0x61 # Value
4141
; ASM-NEXT: .byte 0x07, 0x80, 0xff, 0xff
4242
; ASM-NEXT: .byte 0xff, 0xff
@@ -62,7 +62,7 @@
6262
; OBJ-NEXT: }
6363
; OBJ-NEXT: ConstantSym {
6464
; OBJ-NEXT: Kind: S_CONSTANT (0x1107)
65-
; OBJ-NEXT: Type: TestEnum (0x1011)
65+
; OBJ-NEXT: Type: TestEnum (0x1009)
6666
; OBJ-NEXT: Value: 18446744071562551616
6767
; OBJ-NEXT: Name: ENUM_B
6868
; OBJ-NEXT: }

llvm/test/DebugInfo/COFF/parent-type-scopes.ll

Lines changed: 0 additions & 133 deletions
This file was deleted.

0 commit comments

Comments
 (0)