Issue 75920
Summary `SIGSEGV` in `clang_getCursorPrettyPrinted()` (or, precisely, `StmtPrinter::Visit(clang::Stmt*)`)
Labels clang
Assignees
Reporter 0x6675636b796f75676974687562
    I'm parsing C and C++ source code using _Libclang_ by calling `clang_visitChildren(CXCursor, CXCursorVisitor, CXClientData)` from a JVM, using [JVM bindings](https://github.com/bytedeco/javacpp-presets/tree/master/llvm) to _Libclang_.

In some complex cases (like the source code of _Linux_ kernel), the JVM process crashes with a `SIGSEGV` (Linux) or `EXCEPTION_ACCESS_VIOLATION` (Windows) inside `libclang.so`. This happens when my client code calls [`clang_getCursorPrettyPrinted()`](https://clang.llvm.org/doxygen/group__CINDEX__CURSOR__XREF.html#gab9d561cc237ce0d8bfbab80cdd5be216), and the exact location is [`StmtPrinter::Visit(clang::Stmt*)`](https://github.com/llvm-mirror/clang/blob/aa231e4be75ac4759c236b755c57876f76e3cf05/lib/AST/StmtPrinter.cpp#L67):

```console
C [libclang.so.16+0x86ac4a]  (anonymous namespace)::StmtPrinter::Visit(clang::Stmt*)+0x2a
```

I managed to pinpoint the problem: it occurs when I'm calling `clang_getCursorPrettyPrinted()` for a `CXCursor` instance of type `CXCursor_StructDecl` or `CXCursor_FunctionDecl`. Furtherore, _Libclang_ crashes trying to pretty-print the following function declaration:

```c
void *__kmalloc(size_t size, gfp_t flags) __attribute__((__assume_aligned__(__alignof__(unsigned long long)))) __attribute__((__malloc__));
```

One of the minimal reproducers is:

```c
void *f() __attribute__((__assume_aligned__(__alignof__(unsigned long long))));
```

_Libclang_ versions **15.0.3**, **16.0.4**, and **17.0.6** are all equally affected.

Original issue:
 - bytedeco/javacpp-presets#1442
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to