aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
diff options
context:
space:
mode:
authorDaniel Grumberg <dgrumberg@apple.com>2023-01-19 11:25:17 +0000
committerDaniel Grumberg <dgrumberg@apple.com>2023-02-10 16:30:19 +0000
commit7da2d644e0398be39e188ea6eacab2a942e0fa7e (patch)
tree52398861f701069f5c73c76d98a7cead273debf9 /clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
parent57606bb356199dbb51c20f28bd57f6c34c521abf (diff)
downloadllvm-7da2d644e0398be39e188ea6eacab2a942e0fa7e.zip
llvm-7da2d644e0398be39e188ea6eacab2a942e0fa7e.tar.gz
llvm-7da2d644e0398be39e188ea6eacab2a942e0fa7e.tar.bz2
[clang] [extract-api] Don't crash for category in libclang APIs
Remove failure conditions for categories in libclang and return empty content instead. Differential Revision: https://reviews.llvm.org/D142101
Diffstat (limited to 'clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp')
-rw-r--r--clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp28
1 files changed, 19 insertions, 9 deletions
diff --git a/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp b/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
index 01e9b37..8beb016 100644
--- a/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
+++ b/clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
@@ -487,6 +487,7 @@ bool generatePathComponents(
SmallVector<PathComponent, 4> ReverseComponenents;
ReverseComponenents.emplace_back(Record.USR, Record.Name, Record.getKind());
const auto *CurrentParent = &Record.ParentInformation;
+ bool FailedToFindParent = false;
while (CurrentParent && !CurrentParent->empty()) {
PathComponent CurrentParentComponent(CurrentParent->ParentUSR,
CurrentParent->ParentName,
@@ -509,8 +510,10 @@ bool generatePathComponents(
// The parent record doesn't exist which means the symbol shouldn't be
// treated as part of the current product.
- if (!ParentRecord)
- return true;
+ if (!ParentRecord) {
+ FailedToFindParent = true;
+ break;
+ }
ReverseComponenents.push_back(std::move(CurrentParentComponent));
CurrentParent = &ParentRecord->ParentInformation;
@@ -519,8 +522,9 @@ bool generatePathComponents(
for (const auto &PC : reverse(ReverseComponenents))
ComponentTransformer(PC);
- return false;
+ return FailedToFindParent;
}
+
Object serializeParentContext(const PathComponent &PC, Language Lang) {
Object ParentContextElem;
ParentContextElem["usr"] = PC.USR;
@@ -533,12 +537,15 @@ template <typename RecordTy>
Array generateParentContexts(const RecordTy &Record, const APISet &API,
Language Lang) {
Array ParentContexts;
- if (generatePathComponents(
- Record, API, [Lang, &ParentContexts](const PathComponent &PC) {
- ParentContexts.push_back(serializeParentContext(PC, Lang));
- }))
- ParentContexts.clear();
- ParentContexts.pop_back();
+ generatePathComponents(Record, API,
+ [Lang, &ParentContexts](const PathComponent &PC) {
+ ParentContexts.push_back(
+ serializeParentContext(PC, Lang));
+ });
+
+ // The last component would be the record itself so let's remove it.
+ if (!ParentContexts.empty())
+ ParentContexts.pop_back();
return ParentContexts;
}
@@ -865,6 +872,9 @@ SymbolGraphSerializer::serializeSingleSymbolSGF(StringRef USR,
if (!Record)
return {};
+ if (isa<ObjCCategoryRecord>(Record))
+ return {};
+
Object Root;
APIIgnoresList EmptyIgnores;
SymbolGraphSerializer Serializer(API, EmptyIgnores,