C++: Handle C11 _Noreturn in DefaultOptions

This commit is contained in:
Jeroen Ketema
2022-03-14 12:48:58 +01:00
parent b45f56ac08
commit 1a1c34e1be
5 changed files with 19 additions and 5 deletions

View File

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

View File

@@ -39,7 +39,7 @@ class CustomOptions extends Options {
*
* By default, this holds for `exit`, `_exit`, `abort`, `__assert_fail`,
* `longjmp`, `error`, `__builtin_unreachable` and any function with a
* `noreturn` attribute.
* `noreturn` attribute or specifier.
*/
override predicate exits(Function f) { Options.super.exits(f) }

View File

@@ -38,7 +38,7 @@ class FunctionSpecifier extends Specifier {
/**
* A C/C++ storage class specifier: `auto`, `register`, `static`, `extern`,
* or `mutable".
* or `mutable`.
*/
class StorageClassSpecifier extends Specifier {
StorageClassSpecifier() { this.hasName(["auto", "register", "static", "extern", "mutable"]) }

View File

@@ -1,4 +1,4 @@
// semmle-extractor-options: -std=c11
int f1(void) {
int x = 1;
return 2;
@@ -99,3 +99,9 @@ int f14()
{
__asm__("rdtsc"); // GOOD
}
_Noreturn void f15();
int f16() {
f15(); // GOOD
}

View File

@@ -1,4 +1,4 @@
// semmle-extractor-options: -std=c++11
class MyValue {
public:
MyValue(int _val) : val(_val) {};
@@ -164,3 +164,9 @@ int g19(int x)
return x; // GOOD
}
[[noreturn]] void g20();
int g21() {
g20(); // GOOD
}