mirror of
https://github.com/github/codeql.git
synced 2026-05-01 11:45:14 +02:00
Merge pull request #1702 from mgrettondann/cpp-add-thread_local-support-external
C++: add thread_local support
This commit is contained in:
@@ -45,6 +45,7 @@ predicate hasNontrivialConversion(Expr e) {
|
||||
from LocalScopeVariable var, VariableAccess va, ReturnStmt r
|
||||
where
|
||||
not var.isStatic() and
|
||||
not var.isThreadLocal() and
|
||||
not var.getUnspecifiedType() instanceof ReferenceType and
|
||||
not r.isFromUninstantiatedTemplate(_) and
|
||||
va = var.getAnAccess() and
|
||||
|
||||
@@ -139,6 +139,13 @@ class Variable extends Declaration, @variable {
|
||||
this.hasSpecifier("is_constexpr")
|
||||
}
|
||||
|
||||
/**
|
||||
* Holds if this variable is `thread_local`.
|
||||
*/
|
||||
predicate isThreadLocal() {
|
||||
this.hasSpecifier("is_thread_local")
|
||||
}
|
||||
|
||||
/**
|
||||
* Holds if this variable is constructed from `v` as a result
|
||||
* of template instantiation. If so, it originates either from a template
|
||||
|
||||
@@ -88,6 +88,7 @@
|
||||
| file://:0:0:0:0 | inline |
|
||||
| file://:0:0:0:0 | int |
|
||||
| file://:0:0:0:0 | is_constexpr |
|
||||
| file://:0:0:0:0 | is_thread_local |
|
||||
| file://:0:0:0:0 | long |
|
||||
| file://:0:0:0:0 | long double |
|
||||
| file://:0:0:0:0 | long long |
|
||||
|
||||
@@ -65,6 +65,7 @@
|
||||
| file://:0:0:0:0 | inline |
|
||||
| file://:0:0:0:0 | int |
|
||||
| file://:0:0:0:0 | is_constexpr |
|
||||
| file://:0:0:0:0 | is_thread_local |
|
||||
| file://:0:0:0:0 | long |
|
||||
| file://:0:0:0:0 | long double |
|
||||
| file://:0:0:0:0 | long long |
|
||||
|
||||
@@ -113,6 +113,7 @@
|
||||
| file://:0:0:0:0 | int & |
|
||||
| file://:0:0:0:0 | int * |
|
||||
| file://:0:0:0:0 | is_constexpr |
|
||||
| file://:0:0:0:0 | is_thread_local |
|
||||
| file://:0:0:0:0 | long |
|
||||
| file://:0:0:0:0 | long double |
|
||||
| file://:0:0:0:0 | long long |
|
||||
|
||||
@@ -58,6 +58,7 @@
|
||||
| file://:0:0:0:0 | int * | Other |
|
||||
| file://:0:0:0:0 | int[0] | Other |
|
||||
| file://:0:0:0:0 | is_constexpr | Other |
|
||||
| file://:0:0:0:0 | is_thread_local | Other |
|
||||
| file://:0:0:0:0 | long | Other |
|
||||
| file://:0:0:0:0 | long double | Other |
|
||||
| file://:0:0:0:0 | long long | Other |
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
|
||||
void returnThreadLocal() {
|
||||
thread_local int threadLocal;
|
||||
int not_threadLocal;
|
||||
static thread_local int threadLocalStatic;
|
||||
extern thread_local int threadLocalExtern;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
| file://:0:0:0:0 | fp_offset | false |
|
||||
| file://:0:0:0:0 | gp_offset | false |
|
||||
| file://:0:0:0:0 | overflow_arg_area | false |
|
||||
| file://:0:0:0:0 | p#0 | false |
|
||||
| file://:0:0:0:0 | p#0 | false |
|
||||
| file://:0:0:0:0 | reg_save_area | false |
|
||||
| thread_local.cpp:3:20:3:30 | threadLocal | true |
|
||||
| thread_local.cpp:4:7:4:21 | not_threadLocal | false |
|
||||
| thread_local.cpp:5:27:5:43 | threadLocalStatic | true |
|
||||
| thread_local.cpp:6:27:6:43 | threadLocalExtern | true |
|
||||
@@ -0,0 +1,6 @@
|
||||
import cpp
|
||||
|
||||
from Variable v
|
||||
select v,
|
||||
any(boolean b | if v.isThreadLocal() then b = true else b = false)
|
||||
|
||||
@@ -5,5 +5,4 @@
|
||||
| test.cpp:92:2:92:12 | return ... | May return stack-allocated memory from $@. | test.cpp:89:10:89:11 | mc | mc |
|
||||
| test.cpp:112:2:112:12 | return ... | May return stack-allocated memory from $@. | test.cpp:112:9:112:11 | arr | arr |
|
||||
| test.cpp:119:2:119:19 | return ... | May return stack-allocated memory from $@. | test.cpp:119:11:119:13 | arr | arr |
|
||||
| test.cpp:149:3:149:22 | return ... | May return stack-allocated memory from $@. | test.cpp:149:11:149:21 | threadLocal | threadLocal |
|
||||
| test.cpp:171:3:171:24 | return ... | May return stack-allocated memory from $@. | test.cpp:170:35:170:41 | myLocal | myLocal |
|
||||
|
||||
@@ -146,7 +146,7 @@ char *testArray5()
|
||||
|
||||
int *returnThreadLocal() {
|
||||
thread_local int threadLocal;
|
||||
return &threadLocal; // GOOD [FALSE POSITIVE]
|
||||
return &threadLocal; // GOOD
|
||||
}
|
||||
|
||||
int returnDereferenced() {
|
||||
|
||||
Reference in New Issue
Block a user