There's currently no way to get this information from libclang. This patch adds a small function to see if a given CXCursor representing a FunctionDecl is marked with __attribute__((noreturn)), [[gnu::noreturn]], or [[noreturn]] to libclang as CXCursor_NoReturnAttr.
Details
- Reviewers
dblaikie akyrtzi milianw skalinichev - Group Reviewers
Restricted Project
Diff Detail
- Repository
- rL LLVM
Event Timeline
This fails to link when I compile it locally, and I have absolutely no idea why. So this is still untested.
Patch lacking changes in tools/libclang/libclang.exports
include/clang-c/Index.h | ||
---|---|---|
3319 | I assume that you already tried something like: But it doesn't work (no attributes in AST?), right? | |
unittests/libclang/LibclangTest.cpp | ||
463 ↗ | (On Diff #95980) | Please add tests to test/Index/* it's easier to read/modify. (see e.g. before-mentioned commit for the reference) |
include/clang-c/Index.h | ||
---|---|---|
3319 | The main issue is that there are several different attributes (NoReturn, C11NoReturn, CXX11NoReturn, AnalyzerNoReturn) and I'm not sure whether to expose them all (meaning clients need to check for all of them) or roll them into one exposed attribute. |
include/clang-c/Index.h | ||
---|---|---|
3319 | One attribute should suffice I think, and you still can distinguish them if needed, e.g. via clang_getCursorSpelling. Again see how it's done in r246931 |
test/Index/noreturn.c | ||
---|---|---|
3 ↗ | (On Diff #96223) | Please make sure to test all noreturn attributes (c11/cxx11, noretun). And verify that the test case actually passes! |
tools/libclang/CXCursor.cpp | ||
62–64 ↗ | (On Diff #96223) | Ok, I've just tried a couple of test cases with different noreturn attributes:
Therefore this code will only work with CXX11NoReturn/C11NoReturn attributes. And the test case you provided shouldn't work at all (as you're using NoReturn there) So let's use clang_Cursor_isFunctionNoReturn after all, as it should cover all cases (or so I think) |
tools/libclang/CXCursor.cpp | ||
---|---|---|
62–64 ↗ | (On Diff #96223) | How should I unit test clang_Cursor_isFunctionNoReturn? I can't seem to find any tests for, say, clang_Cursor_isFunctionInlined... |
tools/libclang/CXCursor.cpp | ||
---|---|---|
62–64 ↗ | (On Diff #96223) | I guess something like this: https://reviews.llvm.org/D13388 |
I assume that you already tried something like:
r246931: Index: expose visibility attribute
But it doesn't work (no attributes in AST?), right?