[lldb] Let ClangASTImporter assert that the target AST has an external source
authorRaphael Isemann <teemperor@gmail.com>
Thu, 25 Feb 2021 10:28:43 +0000 (11:28 +0100)
committerRaphael Isemann <teemperor@gmail.com>
Thu, 25 Feb 2021 10:42:14 +0000 (11:42 +0100)
This prevents people from accidentially using this code outside the
intended setup.

lldb/source/Plugins/ExpressionParser/Clang/ClangASTImporter.h

index f4ea3af..7946531 100644 (file)
@@ -198,6 +198,12 @@ public:
       // nodes within the same AST doesn't make any sense as the whole idea
       // is to import them to a different AST.
       lldbassert(target_ctx != source_ctx && "Can't import into itself");
+      // This is always doing a minimal import of any declarations. This means
+      // that there has to be an ExternalASTSource in the target ASTContext
+      // (that should implement the callbacks that complete any declarations
+      // on demand). Without an ExternalASTSource, this ASTImporter will just
+      // do a minimal import and the imported declarations won't be completed.
+      assert(target_ctx->getExternalSource() && "Missing ExternalSource");
       setODRHandling(clang::ASTImporter::ODRHandlingType::Liberal);
     }