Skip to content

Commit 2ffc8d8

Browse files
pvdrzemilio
authored andcommitted
handle c++ [[noreturn]] attribute
1 parent e503476 commit 2ffc8d8

File tree

4 files changed

+23
-4
lines changed

4 files changed

+23
-4
lines changed

src/clang.rs

+7
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,13 @@ impl Attribute {
3737
kind: None,
3838
token_kind: CXToken_Keyword,
3939
};
40+
41+
/// A `[[noreturn]]` attribute.
42+
pub const NO_RETURN_CPP: Self = Self {
43+
name: b"noreturn",
44+
kind: None,
45+
token_kind: CXToken_Identifier,
46+
};
4047
}
4148

4249
/// A cursor into the Clang AST, pointing to an AST node.

src/ir/function.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -450,9 +450,14 @@ impl FunctionSig {
450450
}
451451
};
452452

453-
let [must_use, is_divergent] =
453+
let (must_use, is_divergent) =
454454
if ctx.options().enable_function_attribute_detection {
455-
cursor.has_attrs(&[Attribute::MUST_USE, Attribute::NO_RETURN])
455+
let [must_use, no_return, no_return_cpp] = cursor.has_attrs(&[
456+
Attribute::MUST_USE,
457+
Attribute::NO_RETURN,
458+
Attribute::NO_RETURN_CPP,
459+
]);
460+
(must_use, no_return || no_return_cpp)
456461
} else {
457462
Default::default()
458463
};

tests/expectations/tests/noreturn.rs

+8-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/headers/noreturn.h renamed to tests/headers/noreturn.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
_Noreturn void f(void);
33
// TODO (pvdrz): figure out how to handle this case.
44
__attribute__((noreturn)) void g(void);
5+
[[noreturn]] void h(void);

0 commit comments

Comments
 (0)