Merge pull request #18510 from jketema/noreturn

C++: Support more "noreturn" attributes in DefaultOptions
This commit is contained in:
Jeroen Ketema
2025-01-16 19:09:44 +01:00
committed by GitHub
4 changed files with 39 additions and 4 deletions

View File

@@ -54,11 +54,11 @@ class Options extends string {
*
* By default, this holds for `exit`, `_exit`, `_Exit`, `abort`,
* `__assert_fail`, `longjmp`, `__builtin_unreachable` and any
* function with a `noreturn` or `__noreturn__` attribute or
* `noreturn` specifier.
* function with a `noreturn`, `__noreturn__`, or `_Noreturn`
* attribute or `noreturn` specifier.
*/
predicate exits(Function f) {
f.getAnAttribute().hasName(["noreturn", "__noreturn__"])
f.getAnAttribute().hasName(["noreturn", "__noreturn__", "_Noreturn"])
or
f.getASpecifier().hasName("noreturn")
or

View File

@@ -0,0 +1,4 @@
---
category: minorAnalysis
---
* `DefaultOptions::exits` now holds for C23 functions with the `_Noreturn` or `___Noreturn__` attribute.

View File

@@ -1,4 +1,4 @@
// semmle-extractor-options: -std=c11
// semmle-extractor-options: -std=c23
int f1(void) {
int x = 1;
return 2;
@@ -110,3 +110,27 @@ int f17() {
if (__builtin_expect(1, 0))
__builtin_unreachable(); // GOOD
}
[[_Noreturn]] void f18();
int f19() {
f18(); // GOOD
}
[[___Noreturn__]] void f20();
int f21() {
f20(); // GOOD
}
[[noreturn]] void f22();
int f23() {
f22(); // GOOD
}
[[__noreturn__]] void f24();
int f25() {
f24(); // GOOD
}

View File

@@ -188,3 +188,10 @@ int g22() {
int g23() {
Aborting().a(); // GOOD [FALSE POSITIVE]
}
[[__noreturn__]]
int g24();
int g25() {
g24(); // GOOD
}