Index: lib/CodeGen/AsmPrinter/CodeViewDebug.h =================================================================== --- lib/CodeGen/AsmPrinter/CodeViewDebug.h +++ lib/CodeGen/AsmPrinter/CodeViewDebug.h @@ -117,11 +117,6 @@ /// to be confused with type indices for LF_FUNC_ID records. unsigned NextFuncId = 0; - codeview::TypeIndex VoidFnTyIdx; - - /// Get a type index for a generic void function type. - codeview::TypeIndex getGenericFunctionTypeIndex(); - InlineSite &getInlineSite(const DILocation *InlinedAt, const DISubprogram *Inlinee); @@ -195,6 +190,7 @@ codeview::TypeIndex lowerTypePointer(const DIDerivedType *Ty); codeview::TypeIndex lowerTypeMemberPointer(const DIDerivedType *Ty); codeview::TypeIndex lowerTypeModifier(const DIDerivedType *Ty); + codeview::TypeIndex lowerTypeFunction(const DISubroutineType *Ty); public: CodeViewDebug(AsmPrinter *Asm); Index: lib/CodeGen/AsmPrinter/CodeViewDebug.cpp =================================================================== --- lib/CodeGen/AsmPrinter/CodeViewDebug.cpp +++ lib/CodeGen/AsmPrinter/CodeViewDebug.cpp @@ -122,24 +122,10 @@ return *Site; } -TypeIndex CodeViewDebug::getGenericFunctionTypeIndex() { - if (VoidFnTyIdx.getIndex() != 0) - return VoidFnTyIdx; - - ArrayRef NoArgs; - ArgListRecord ArgListRec(TypeRecordKind::ArgList, NoArgs); - TypeIndex ArgListIndex = TypeTable.writeArgList(ArgListRec); - - ProcedureRecord Procedure(TypeIndex::Void(), CallingConvention::NearC, - FunctionOptions::None, 0, ArgListIndex); - VoidFnTyIdx = TypeTable.writeProcedure(Procedure); - return VoidFnTyIdx; -} - void CodeViewDebug::recordFuncIdForSubprogram(const DISubprogram *SP) { TypeIndex ParentScope = TypeIndex(0); StringRef DisplayName = SP->getDisplayName(); - FuncIdRecord FuncId(ParentScope, getGenericFunctionTypeIndex(), DisplayName); + FuncIdRecord FuncId(ParentScope, getTypeIndex(SP->getType()), DisplayName); TypeIndex TI = TypeTable.writeFuncId(FuncId); TypeIndices[SP] = TI; } @@ -495,7 +481,10 @@ OS.AddComment("Offset before epilogue"); OS.EmitIntValue(0, 4); OS.AddComment("Function type index"); - OS.EmitIntValue(0, 4); + if (const DISubprogram *Subprogram = GV->getSubprogram()) + OS.EmitIntValue(getTypeIndex(Subprogram->getType()).getIndex(), 4); + else + OS.EmitIntValue(0, 4); OS.AddComment("Function section relative address"); OS.EmitCOFFSecRel32(Fn); OS.AddComment("Function section index"); @@ -744,6 +733,8 @@ case dwarf::DW_TAG_const_type: case dwarf::DW_TAG_volatile_type: return lowerTypeModifier(cast(Ty)); + case dwarf::DW_TAG_subroutine_type: + return lowerTypeFunction(cast(Ty)); default: // Use the null type index. return TypeIndex(); @@ -934,6 +925,27 @@ return TypeTable.writeModifier(MR); } +TypeIndex CodeViewDebug::lowerTypeFunction(const DISubroutineType *Ty) { + SmallVector ReturnAndArgTypeIndices; + for (DITypeRef ArgTypeRef : Ty->getTypeArray()) + ReturnAndArgTypeIndices.push_back(getTypeIndex(ArgTypeRef)); + + TypeIndex ReturnTypeIndex = TypeIndex::Void(); + ArrayRef ArgTypeIndices = None; + if (!ReturnAndArgTypeIndices.empty()) { + auto ReturnAndArgTypesRef = makeArrayRef(ReturnAndArgTypeIndices); + ReturnTypeIndex = ReturnAndArgTypesRef.front(); + ArgTypeIndices = ReturnAndArgTypesRef.drop_front(); + } + + ArgListRecord ArgListRec(TypeRecordKind::ArgList, ArgTypeIndices); + TypeIndex ArgListIndex = TypeTable.writeArgList(ArgListRec); + + ProcedureRecord Procedure(ReturnTypeIndex, CallingConvention::NearC, + FunctionOptions::None, 0, ArgListIndex); + return TypeTable.writeProcedure(Procedure); +} + TypeIndex CodeViewDebug::getTypeIndex(DITypeRef TypeRef) { const DIType *Ty = TypeRef.resolve();