|
6 | 6 |
|
7 | 7 | #include <model/fileloc.h> |
8 | 8 | #include <model/fileloc-odb.hxx> |
| 9 | +#include <util/logutil.h> |
9 | 10 |
|
10 | 11 | #include "symbolhelper.h" |
11 | 12 |
|
@@ -75,9 +76,28 @@ std::string getMangledName( |
75 | 76 |
|
76 | 77 | if (const clang::DeclContext* dc = nd_->getParentFunctionOrMethod()) |
77 | 78 | { |
78 | | - result += ':' + getMangledName( |
79 | | - mangleContext_, |
80 | | - llvm::dyn_cast<clang::FunctionDecl>(dc)); |
| 79 | + // Fixes issue #415 of parser segfaults. |
| 80 | + // https://github.com/Ericsson/CodeCompass/issues/415 |
| 81 | + // |
| 82 | + // There are contexts in which getParentFunctionOrMethod() is not |
| 83 | + // null, but the result is not FunctionDecl (such as CapturedDecl), |
| 84 | + // e.g. when the to-be-mangled node is inside an OMP block. |
| 85 | + // In that case, try to find some parent DeclContext we can |
| 86 | + // reasonably mangle. |
| 87 | + while (!llvm::isa<clang::FunctionDecl>(dc) && |
| 88 | + !llvm::isa<clang::TranslationUnitDecl>(dc)) |
| 89 | + { |
| 90 | + LOG(debug) << "Yet another getparentFunctionMethod() && " |
| 91 | + "! llvm::dyn_cast<clang::FunctionDecl>(dc) "; |
| 92 | + LOG(debug) << dc->getDeclKindName(); |
| 93 | + |
| 94 | + dc = dc->getLookupParent(); |
| 95 | + } |
| 96 | + |
| 97 | + if (const auto* dcfd = llvm::dyn_cast<clang::FunctionDecl>(dc)) |
| 98 | + result += ':' + getMangledName(mangleContext_, dcfd); |
| 99 | + else if (llvm::isa<clang::TranslationUnitDecl>(dc)) |
| 100 | + result += ':' + std::to_string(fileLoc_.file.object_id()); |
81 | 101 |
|
82 | 102 | if (const clang::ParmVarDecl* pvd = |
83 | 103 | llvm::dyn_cast<clang::ParmVarDecl>(nd_)) |
|
0 commit comments