[clang] [clang][ExtractAPI] fix a couple crashes when used via libclang (PR #132297)

via cfe-commits cfe-commits at lists.llvm.org
Tue Mar 25 14:29:11 PDT 2025


================
@@ -175,28 +175,30 @@ class ExtractAPIVisitorBase : public RecursiveASTVisitor<Derived> {
   SmallVector<SymbolReference> getBases(const CXXRecordDecl *Decl) {
     // FIXME: store AccessSpecifier given by inheritance
     SmallVector<SymbolReference> Bases;
-    for (const auto &BaseSpecifier : Decl->bases()) {
-      // skip classes not inherited as public
-      if (BaseSpecifier.getAccessSpecifier() != AccessSpecifier::AS_public)
-        continue;
-      if (auto *BaseDecl = BaseSpecifier.getType()->getAsTagDecl()) {
-        Bases.emplace_back(createSymbolReferenceForDecl(*BaseDecl));
-      } else {
-        SymbolReference BaseClass;
-        BaseClass.Name = API.copyString(BaseSpecifier.getType().getAsString(
-            Decl->getASTContext().getPrintingPolicy()));
-
-        if (BaseSpecifier.getType().getTypePtr()->isTemplateTypeParmType()) {
-          if (auto *TTPTD = BaseSpecifier.getType()
-                                ->getAs<TemplateTypeParmType>()
-                                ->getDecl()) {
-            SmallString<128> USR;
-            index::generateUSRForDecl(TTPTD, USR);
-            BaseClass.USR = API.copyString(USR);
-            BaseClass.Source = API.copyString(getOwningModuleName(*TTPTD));
+    if (Decl->isCompleteDefinition()) {
----------------
QuietMisdreavus wrote:

It looks like incomplete decls are already skipped in batch mode:

https://github.com/llvm/llvm-project/blob/960615954e4cb3150ae4a479fa7f9d0d17035eea/clang/lib/ExtractAPI/ExtractAPIConsumer.cpp#L232-L244

Between this and the fact that decls are otherwise processed in isolation in libclang mode, i'm not concerned about incomplete decls messing up the list of bases in the APISet. Would you still like me to move the check outside of `getBases`, or can we move forward with the change as-is?

https://github.com/llvm/llvm-project/pull/132297


More information about the cfe-commits mailing list