[Lldb-commits] [clang] [lldb] [clang] Add -ast-dump-filter-path to filter AST dump by file path (PR #194266)

Aaron Ballman via lldb-commits lldb-commits at lists.llvm.org
Wed May 6 06:07:32 PDT 2026


================
@@ -83,7 +88,28 @@ namespace {
       return "";
     }
     bool filterMatches(Decl *D) {
-      return getName(D).find(FilterString) != std::string::npos;
+      if (!FilterString.empty() &&
+          getName(D).find(FilterString) == std::string::npos)
+        return false;
+
+      if (!FilterPath.empty()) {
+        const SourceManager &SM = D->getASTContext().getSourceManager();
+
+        SourceLocation Loc = SM.getSpellingLoc(D->getLocation());
----------------
AaronBallman wrote:

I think we want `getPresumedLoc()` because there can be things like line directive markers that set the file name explicitly. But this raises a question of how to handle declarations formed via macro expansions. e.g.,
```
// In foo.h
#define BLAH(name) int name

// In bar.c
#include "foo.h"

BLAH(x);
```
If the user has `-ast-dump-filter-path=bar.c` I think they'd expect `int x;` to be dumped. Going with the spelling location means we'd not dump that declaration, going with the expansion location means we would. (Using the presumed location would give you the expansion location + any changes due to line markers.)

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


More information about the lldb-commits mailing list