|
32 | 32 | #include "clang/Basic/FileManager.h" |
33 | 33 | #include "clang/Basic/SourceManager.h" |
34 | 34 | #include "clang/Basic/Version.h" |
| 35 | +#include "clang/CodeGen/ModuleBuilder.h" |
35 | 36 | #include "clang/Frontend/FrontendOptions.h" |
36 | 37 | #include "clang/Lex/HeaderSearchOptions.h" |
37 | 38 | #include "clang/Lex/ModuleMap.h" |
@@ -1731,6 +1732,28 @@ llvm::DIType *CGDebugInfo::createFieldType( |
1731 | 1732 | offsetInBits, flags, debugType, Annotations); |
1732 | 1733 | } |
1733 | 1734 |
|
| 1735 | +llvm::DISubprogram * |
| 1736 | +CGDebugInfo::createInlinedTrapSubprogram(StringRef FuncName, |
| 1737 | + llvm::DIFile *FileScope) { |
| 1738 | + // We are caching the subprogram because we don't want to duplicate |
| 1739 | + // subprograms with the same message. Note that `SPFlagDefinition` prevents |
| 1740 | + // subprograms from being uniqued. |
| 1741 | + llvm::DISubprogram *&SP = InlinedTrapFuncMap[FuncName]; |
| 1742 | + |
| 1743 | + if (!SP) { |
| 1744 | + llvm::DISubroutineType *DIFnTy = DBuilder.createSubroutineType(nullptr); |
| 1745 | + SP = DBuilder.createFunction( |
| 1746 | + /*Scope=*/FileScope, /*Name=*/FuncName, /*LinkageName=*/StringRef(), |
| 1747 | + /*File=*/FileScope, /*LineNo=*/0, /*Ty=*/DIFnTy, |
| 1748 | + /*ScopeLine=*/0, |
| 1749 | + /*Flags=*/llvm::DINode::FlagArtificial, |
| 1750 | + /*SPFlags=*/llvm::DISubprogram::SPFlagDefinition, |
| 1751 | + /*TParams=*/nullptr, /*ThrownTypes=*/nullptr, /*Annotations=*/nullptr); |
| 1752 | + } |
| 1753 | + |
| 1754 | + return SP; |
| 1755 | +} |
| 1756 | + |
1734 | 1757 | void CGDebugInfo::CollectRecordLambdaFields( |
1735 | 1758 | const CXXRecordDecl *CXXDecl, SmallVectorImpl<llvm::Metadata *> &elements, |
1736 | 1759 | llvm::DIType *RecordTy) { |
@@ -3527,6 +3550,23 @@ llvm::DIMacroFile *CGDebugInfo::CreateTempMacroFile(llvm::DIMacroFile *Parent, |
3527 | 3550 | return DBuilder.createTempMacroFile(Parent, Line, FName); |
3528 | 3551 | } |
3529 | 3552 |
|
| 3553 | +llvm::DILocation *CGDebugInfo::CreateTrapFailureMessageFor( |
| 3554 | + llvm::DebugLoc TrapLocation, StringRef Category, StringRef FailureMsg) { |
| 3555 | + // Create a debug location from `TrapLocation` that adds an artificial inline |
| 3556 | + // frame. |
| 3557 | + SmallString<64> FuncName(ClangTrapPrefix); |
| 3558 | + |
| 3559 | + FuncName += "$"; |
| 3560 | + FuncName += Category; |
| 3561 | + FuncName += "$"; |
| 3562 | + FuncName += FailureMsg; |
| 3563 | + |
| 3564 | + llvm::DISubprogram *TrapSP = |
| 3565 | + createInlinedTrapSubprogram(FuncName, TrapLocation->getFile()); |
| 3566 | + return llvm::DILocation::get(CGM.getLLVMContext(), /*Line=*/0, /*Column=*/0, |
| 3567 | + /*Scope=*/TrapSP, /*InlinedAt=*/TrapLocation); |
| 3568 | +} |
| 3569 | + |
3530 | 3570 | static QualType UnwrapTypeForDebugInfo(QualType T, const ASTContext &C) { |
3531 | 3571 | Qualifiers Quals; |
3532 | 3572 | do { |
|
0 commit comments