Merge pull request #1702 from mgrettondann/cpp-add-thread_local-support-external

C++: add thread_local support
This commit is contained in:
Nick Rolfe
2019-08-06 14:51:27 +01:00
committed by GitHub
12 changed files with 37 additions and 2 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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 |

View File

@@ -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 |

View File

@@ -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 |

View File

@@ -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 |

View File

@@ -0,0 +1,7 @@
void returnThreadLocal() {
thread_local int threadLocal;
int not_threadLocal;
static thread_local int threadLocalStatic;
extern thread_local int threadLocalExtern;
}

View File

@@ -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 |

View File

@@ -0,0 +1,6 @@
import cpp
from Variable v
select v,
any(boolean b | if v.isThreadLocal() then b = true else b = false)

View File

@@ -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 |

View File

@@ -146,7 +146,7 @@ char *testArray5()
int *returnThreadLocal() {
thread_local int threadLocal;
return &threadLocal; // GOOD [FALSE POSITIVE]
return &threadLocal; // GOOD
}
int returnDereferenced() {