mirror of
https://github.com/github/codeql.git
synced 2026-04-25 00:35:20 +02:00
Merge pull request #18510 from jketema/noreturn
C++: Support more "noreturn" attributes in DefaultOptions
This commit is contained in:
@@ -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
|
||||
|
||||
4
cpp/ql/lib/change-notes/2025-01-16-noreturn.md
Normal file
4
cpp/ql/lib/change-notes/2025-01-16-noreturn.md
Normal file
@@ -0,0 +1,4 @@
|
||||
---
|
||||
category: minorAnalysis
|
||||
---
|
||||
* `DefaultOptions::exits` now holds for C23 functions with the `_Noreturn` or `___Noreturn__` attribute.
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -188,3 +188,10 @@ int g22() {
|
||||
int g23() {
|
||||
Aborting().a(); // GOOD [FALSE POSITIVE]
|
||||
}
|
||||
|
||||
[[__noreturn__]]
|
||||
int g24();
|
||||
|
||||
int g25() {
|
||||
g24(); // GOOD
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user