Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SIGSEGV in clang_getCursorPrettyPrinted() (or StmtPrinter::Visit(clang::Stmt*)) #1442

Open
0x6675636b796f75676974687562 opened this issue Nov 30, 2023 · 4 comments

Comments

@0x6675636b796f75676974687562
Copy link
Contributor

So, as I mentioned in the previous issue (#1437), I was calling clang_visitChildren(CXCursor, CXCursorVisitor, CXClientData), now in a single-threaded mode.

We managed to successfully parse the code base of CMake, GNU Make, and OpenSSL.

When parsing the source code of Linux (5.18, if it matters), while in the middle of clang_getCursorPrettyPrinted(), we received a steadily reproducible SIGSEGV at

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

StmtPrinter::Visit(clang::Stmt*) is a C++ call invoked internally by clang_getCursorPrettyPrinted().

The issue does not depend on the JVM vendor or version (versions 11 and 17 were tested).

@saudet
Copy link
Member

saudet commented Nov 30, 2023

Please try again with the snapshots: http://bytedeco.org/builds/

@0x6675636b796f75676974687562
Copy link
Contributor Author

@saudet, the same is true with snapshot versions, too.

What I managed to find out is that clang_getCursorPrettyPrinted() doesn't always work well for some CXCursor types, notably CXCursor_StructDecl and CXCursor_FunctionDecl. This means that sometimes correct struct or function bodies are returned, and sometimes the JVM process crashes.

Particularly, the following function declaration (from include/linux/slab.h, included in mm/slob.c) results in a crash:

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

To be more specific, a function should return a void * and have the __assume_aligned__(__alignof__(unsigned long long)) attribute. So here's one of the minimal reproducers:

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

@0x6675636b796f75676974687562
Copy link
Contributor Author

Forwarded upstream as:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants