diff options
author | Reid Kleckner <rnk@google.com> | 2018-12-26 21:52:17 +0000 |
---|---|---|
committer | Reid Kleckner <rnk@google.com> | 2018-12-26 21:52:17 +0000 |
commit | c168c6f86f811327488b58f7e2cc9826801a0155 (patch) | |
tree | 3ec6122b4d1a79b4bb234ea92dc4143d28eb791f /llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp | |
parent | a643e6449ba284e345ddd35479b8c4f897eed386 (diff) | |
download | llvm-c168c6f86f811327488b58f7e2cc9826801a0155.zip llvm-c168c6f86f811327488b58f7e2cc9826801a0155.tar.gz llvm-c168c6f86f811327488b58f7e2cc9826801a0155.tar.bz2 |
[codeview] Check if this 'this' type of a method is a pointer
Fixes crash reported after r347354 for frontends that don't always emit
'this' pointers for methods. Now we will silently produce debug info
that makes functions like this look like static methods, which seems
reasonable.
llvm-svn: 350073
Diffstat (limited to 'llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp')
-rw-r--r-- | llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp b/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp index 990f0f4..8cabad4 100644 --- a/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp +++ b/llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp @@ -1838,9 +1838,19 @@ TypeIndex CodeViewDebug::lowerTypeMemberFunction(const DISubroutineType *Ty, SmallVector<TypeIndex, 8> ArgTypeIndices; TypeIndex ReturnTypeIndex = getTypeIndex(ReturnAndArgs[Index++]); + // If the first argument is a pointer type and this isn't a static method, + // treat it as the special 'this' parameter, which is encoded separately from + // the arguments. TypeIndex ThisTypeIndex; - if (!IsStaticMethod && ReturnAndArgs.size() > 1) - ThisTypeIndex = getTypeIndexForThisPtr(ReturnAndArgs[Index++], Ty); + if (!IsStaticMethod && ReturnAndArgs.size() > Index) { + if (const DIDerivedType *PtrTy = + dyn_cast_or_null<DIDerivedType>(ReturnAndArgs[Index].resolve())) { + if (PtrTy->getTag() == dwarf::DW_TAG_pointer_type) { + ThisTypeIndex = getTypeIndexForThisPtr(PtrTy, Ty); + Index++; + } + } + } while (Index < ReturnAndArgs.size()) ArgTypeIndices.push_back(getTypeIndex(ReturnAndArgs[Index++])); @@ -2396,9 +2406,10 @@ TypeIndex CodeViewDebug::getTypeIndex(DITypeRef TypeRef, DITypeRef ClassTyRef) { } codeview::TypeIndex -CodeViewDebug::getTypeIndexForThisPtr(DITypeRef TypeRef, +CodeViewDebug::getTypeIndexForThisPtr(const DIDerivedType *PtrTy, const DISubroutineType *SubroutineTy) { - const DIType *Ty = TypeRef.resolve(); + assert(PtrTy->getTag() == dwarf::DW_TAG_pointer_type && + "this type must be a pointer type"); PointerOptions Options = PointerOptions::None; if (SubroutineTy->getFlags() & DINode::DIFlags::FlagLValueReference) @@ -2411,13 +2422,13 @@ CodeViewDebug::getTypeIndexForThisPtr(DITypeRef TypeRef, // so that the TypeIndex for the this pointer can be shared with the type // index for other pointers to this class type. If there is a ref qualifier // then we lookup the pointer using the subroutine as the parent type. - auto I = TypeIndices.find({Ty, SubroutineTy}); + auto I = TypeIndices.find({PtrTy, SubroutineTy}); if (I != TypeIndices.end()) return I->second; TypeLoweringScope S(*this); - TypeIndex TI = lowerTypePointer(cast<DIDerivedType>(Ty), Options); - return recordTypeIndexForDINode(Ty, TI, SubroutineTy); + TypeIndex TI = lowerTypePointer(PtrTy, Options); + return recordTypeIndexForDINode(PtrTy, TI, SubroutineTy); } TypeIndex CodeViewDebug::getTypeIndexForReferenceTo(DITypeRef TypeRef) { |