Skip to content

Commit

Permalink
Revert d91ed80 "[codeview] Reference types in type parent scopes"
Browse files Browse the repository at this point in the history
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
  • Loading branch information
zmodem committed Nov 8, 2019
1 parent f649f24 commit ff3b513
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 170 deletions.
36 changes: 14 additions & 22 deletions llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
Expand Up @@ -303,19 +303,12 @@ static StringRef getPrettyScopeName(const DIScope *Scope) {
return StringRef();
}

const DISubprogram *CodeViewDebug::collectParentScopeNames(
static const DISubprogram *getQualifiedNameComponents(
const DIScope *Scope, SmallVectorImpl<StringRef> &QualifiedNameComponents) {
const DISubprogram *ClosestSubprogram = nullptr;
while (Scope != nullptr) {
if (ClosestSubprogram == nullptr)
ClosestSubprogram = dyn_cast<DISubprogram>(Scope);

// If a type appears in a scope chain, make sure it gets emitted. The
// frontend will be responsible for deciding if this should be a forward
// declaration or a complete type.
if (const auto *Ty = dyn_cast<DIType>(Scope))
(void)getTypeIndex(Ty);

StringRef ScopeName = getPrettyScopeName(Scope);
if (!ScopeName.empty())
QualifiedNameComponents.push_back(ScopeName);
Expand All @@ -324,9 +317,8 @@ const DISubprogram *CodeViewDebug::collectParentScopeNames(
return ClosestSubprogram;
}

std::string
CodeViewDebug::formatNestedName(ArrayRef<StringRef> QualifiedNameComponents,
StringRef TypeName) {
static std::string getQualifiedName(ArrayRef<StringRef> QualifiedNameComponents,
StringRef TypeName) {
std::string FullyQualifiedName;
for (StringRef QualifiedNameComponent :
llvm::reverse(QualifiedNameComponents)) {
Expand All @@ -337,15 +329,10 @@ CodeViewDebug::formatNestedName(ArrayRef<StringRef> QualifiedNameComponents,
return FullyQualifiedName;
}

std::string CodeViewDebug::getFullyQualifiedName(const DIScope *Scope, StringRef Name) {
static std::string getFullyQualifiedName(const DIScope *Scope, StringRef Name) {
SmallVector<StringRef, 5> QualifiedNameComponents;
collectParentScopeNames(Scope, QualifiedNameComponents);
return formatNestedName(QualifiedNameComponents, Name);
}

std::string CodeViewDebug::getFullyQualifiedName(const DIScope *Ty) {
const DIScope *Scope = Ty->getScope();
return getFullyQualifiedName(Scope, getPrettyScopeName(Ty));
getQualifiedNameComponents(Scope, QualifiedNameComponents);
return getQualifiedName(QualifiedNameComponents, Name);
}

struct CodeViewDebug::TypeLoweringScope {
Expand All @@ -360,6 +347,11 @@ struct CodeViewDebug::TypeLoweringScope {
CodeViewDebug &CVD;
};

static std::string getFullyQualifiedName(const DIScope *Ty) {
const DIScope *Scope = Ty->getScope();
return getFullyQualifiedName(Scope, getPrettyScopeName(Ty));
}

TypeIndex CodeViewDebug::getScopeIndex(const DIScope *Scope) {
// No scope means global scope and that uses the zero index.
if (!Scope || isa<DIFile>(Scope))
Expand Down Expand Up @@ -1476,12 +1468,12 @@ void CodeViewDebug::addToUDTs(const DIType *Ty) {
if (!shouldEmitUdt(Ty))
return;

SmallVector<StringRef, 5> ParentScopeNames;
SmallVector<StringRef, 5> QualifiedNameComponents;
const DISubprogram *ClosestSubprogram =
collectParentScopeNames(Ty->getScope(), ParentScopeNames);
getQualifiedNameComponents(Ty->getScope(), QualifiedNameComponents);

std::string FullyQualifiedName =
formatNestedName(ParentScopeNames, getPrettyScopeName(Ty));
getQualifiedName(QualifiedNameComponents, getPrettyScopeName(Ty));

if (ClosestSubprogram == nullptr) {
GlobalUDTs.emplace_back(std::move(FullyQualifiedName), Ty);
Expand Down
13 changes: 0 additions & 13 deletions llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.h
Expand Up @@ -443,19 +443,6 @@ class LLVM_LIBRARY_VISIBILITY CodeViewDebug : public DebugHandlerBase {
codeview::TypeIndex TI,
const DIType *ClassTy = nullptr);

/// Collect the names of parent scopes, innermost to outermost. Return the
/// innermost subprogram scope if present. Ensure that parent type scopes are
/// inserted into the type table.
const DISubprogram *
collectParentScopeNames(const DIScope *Scope,
SmallVectorImpl<StringRef> &ParentScopeNames);

std::string formatNestedName(ArrayRef<StringRef> ParentScopeNames,
StringRef TypeName);

std::string getFullyQualifiedName(const DIScope *Scope, StringRef Name);
std::string getFullyQualifiedName(const DIScope *Scope);

unsigned getPointerSizeInBytes();

protected:
Expand Down
4 changes: 2 additions & 2 deletions llvm/test/DebugInfo/COFF/global-constants.ll
Expand Up @@ -36,7 +36,7 @@
; ASM-NEXT: .asciz "S::TestConst2" # Name
; ASM: .short {{.*-.*}} # Record length
; ASM: .short 4359 # Record kind: S_CONSTANT
; ASM-NEXT: .long 4113 # Type
; ASM-NEXT: .long 4105 # Type
; ASM-NEXT: .byte 0x0a, 0x80, 0x40, 0x61 # Value
; ASM-NEXT: .byte 0x07, 0x80, 0xff, 0xff
; ASM-NEXT: .byte 0xff, 0xff
Expand All @@ -62,7 +62,7 @@
; OBJ-NEXT: }
; OBJ-NEXT: ConstantSym {
; OBJ-NEXT: Kind: S_CONSTANT (0x1107)
; OBJ-NEXT: Type: TestEnum (0x1011)
; OBJ-NEXT: Type: TestEnum (0x1009)
; OBJ-NEXT: Value: 18446744071562551616
; OBJ-NEXT: Name: ENUM_B
; OBJ-NEXT: }
Expand Down
133 changes: 0 additions & 133 deletions llvm/test/DebugInfo/COFF/parent-type-scopes.ll

This file was deleted.

0 comments on commit ff3b513

Please sign in to comment.