llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

Author: Ingo Müller (ingomueller-net)

<details>
<summary>Changes</summary>

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.

---
Full diff: https://github.com/llvm/llvm-project/pull/199328.diff


1 Files Affected:

- (modified) clang/tools/libclang/CIndex.cpp (+2) 


``````````diff
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));

``````````

</details>


https://github.com/llvm/llvm-project/pull/199328
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to