Skip to content

Commit 1a1c34e

Browse files
committed
C++: Handle C11 _Noreturn in DefaultOptions
1 parent b45f56a commit 1a1c34e

File tree

5 files changed

+19
-5
lines changed

5 files changed

+19
-5
lines changed

cpp/ql/lib/DefaultOptions.qll

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,13 @@ class Options extends string {
5454
*
5555
* By default, this holds for `exit`, `_exit`, `abort`, `__assert_fail`,
5656
* `longjmp`, `__builtin_unreachable` and any function with a
57-
* `noreturn` attribute.
57+
* `noreturn` attribute or specifier.
5858
*/
5959
predicate exits(Function f) {
6060
f.getAnAttribute().hasName("noreturn")
6161
or
62+
f.getASpecifier().hasName("noreturn")
63+
or
6264
f.hasGlobalOrStdName([
6365
"exit", "_exit", "abort", "__assert_fail", "longjmp", "__builtin_unreachable"
6466
])

cpp/ql/lib/Options.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ class CustomOptions extends Options {
3939
*
4040
* By default, this holds for `exit`, `_exit`, `abort`, `__assert_fail`,
4141
* `longjmp`, `error`, `__builtin_unreachable` and any function with a
42-
* `noreturn` attribute.
42+
* `noreturn` attribute or specifier.
4343
*/
4444
override predicate exits(Function f) { Options.super.exits(f) }
4545

cpp/ql/lib/semmle/code/cpp/Specifier.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class FunctionSpecifier extends Specifier {
3838

3939
/**
4040
* A C/C++ storage class specifier: `auto`, `register`, `static`, `extern`,
41-
* or `mutable".
41+
* or `mutable`.
4242
*/
4343
class StorageClassSpecifier extends Specifier {
4444
StorageClassSpecifier() { this.hasName(["auto", "register", "static", "extern", "mutable"]) }

cpp/ql/test/query-tests/jsf/4.13 Functions/AV Rule 114/test.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
1+
// semmle-extractor-options: -std=c11
22
int f1(void) {
33
int x = 1;
44
return 2;
@@ -99,3 +99,9 @@ int f14()
9999
{
100100
__asm__("rdtsc"); // GOOD
101101
}
102+
103+
_Noreturn void f15();
104+
105+
int f16() {
106+
f15(); // GOOD
107+
}

cpp/ql/test/query-tests/jsf/4.13 Functions/AV Rule 114/test.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
1+
// semmle-extractor-options: -std=c++11
22
class MyValue {
33
public:
44
MyValue(int _val) : val(_val) {};
@@ -164,3 +164,9 @@ int g19(int x)
164164

165165
return x; // GOOD
166166
}
167+
168+
[[noreturn]] void g20();
169+
170+
int g21() {
171+
g20(); // GOOD
172+
}

0 commit comments

Comments
 (0)