Skip to content

Commit

Permalink
Merge pull request #18510 from jketema/noreturn
Browse files Browse the repository at this point in the history
C++: Support more "noreturn" attributes in DefaultOptions
  • Loading branch information
jketema authored Jan 16, 2025
2 parents 133e269 + ff0d495 commit e6eaf5e
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 4 deletions.
6 changes: 3 additions & 3 deletions cpp/ql/lib/DefaultOptions.qll
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions cpp/ql/lib/change-notes/2025-01-16-noreturn.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
category: minorAnalysis
---
* `DefaultOptions::exits` now holds for C23 functions with the `_Noreturn` or `___Noreturn__` attribute.
26 changes: 25 additions & 1 deletion cpp/ql/test/query-tests/jsf/4.13 Functions/AV Rule 114/test.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// semmle-extractor-options: -std=c11
// semmle-extractor-options: -std=c23
int f1(void) {
int x = 1;
return 2;
Expand Down Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -188,3 +188,10 @@ int g22() {
int g23() {
Aborting().a(); // GOOD [FALSE POSITIVE]
}

[[__noreturn__]]
int g24();

int g25() {
g24(); // GOOD
}

0 comments on commit e6eaf5e

Please sign in to comment.