https://github.com/ingomueller-net created https://github.com/llvm/llvm-project/pull/199328
Fix a regression introduced in PR #198452 where querying raw comments on invalid cursors caused a segmentation fault due to unconditional ASTContext lookup. Adding an early exit for unsupported cursor kinds at the top of getCursorRawComment safely avoids resolving the context on invalid cursors with null translation units. From 9c155822eb7f4b2a78fab8be1d72449787ad804c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ingo=20M=C3=BCller?= <[email protected]> Date: Sat, 23 May 2026 09:54:47 +0200 Subject: [PATCH] [clang] Fix crash in getCursorRawComments. Fix a regression introduced in PR #198452 where querying raw comments on invalid cursors caused a segmentation fault due to unconditional ASTContext lookup. Adding an early exit for unsupported cursor kinds at the top of getCursorRawComment safely avoids resolving the context on invalid cursors with null translation units. --- clang/tools/libclang/CIndex.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/clang/tools/libclang/CIndex.cpp b/clang/tools/libclang/CIndex.cpp index c07c4cd84bbce..85760968cdbde 100644 --- a/clang/tools/libclang/CIndex.cpp +++ b/clang/tools/libclang/CIndex.cpp @@ -9327,6 +9327,8 @@ CXString clang_Cursor_getBinaryOpcodeStr(enum CX_BinaryOperatorKind Op) { } static const RawComment *getCursorRawComment(CXCursor C) { + if (!clang_isDeclaration(C.kind) && C.kind != CXCursor_MacroDefinition) + return nullptr; ASTContext &Context = getCursorContext(C); if (clang_isDeclaration(C.kind)) return Context.getRawCommentForAnyRedecl(getCursorDecl(C)); _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
