From 47f54b89920e3962ba1f74d07dadbd6b6bf82083 Mon Sep 17 00:00:00 2001 From: Jake Hemstad <15221289+jrhemstad@users.noreply.github.com> Date: Sun, 8 Mar 2026 20:26:20 -0500 Subject: [PATCH] Fix crash on include cursors without source file Skip inclusion directives when clang_getFileLocation returns a null source_file handle (seen for built-in CUDA headers), preventing std::string construction from null while preserving normal include graph generation. --- src/include_graph_parser.cc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/include_graph_parser.cc b/src/include_graph_parser.cc index 180508f..e106193 100644 --- a/src/include_graph_parser.cc +++ b/src/include_graph_parser.cc @@ -424,6 +424,12 @@ enum CXChildVisitResult inclusion_cursor_visitor( clang_getFileLocation(clang_getCursorLocation(cursor), &source_file, &line, &column, &offset); + if(source_file == nullptr) { + LOG(debug) << "WARNING: Cannot find source file for include text: " + << get_raw_include_text(cursor); + return CXChildVisit_Continue; + } + const std::string source_file_str{ clang_getCString(clang_getFileName(source_file))};