Commit c1e17e5
authored
[ThreadSafety] Ignore parameter destructors (#170843)
Fixes a false positive in thread safety analysis when function
parameters have lock/unlock annotations in their constructor/destructor.
PR #169320 added destructors to the CFG, which introduced false
positives in thread safety analysis for function parameters. According
to [expr.call#6](https://eel.is/c++draft/expr.call#6), parameter
initialization occurs in the caller's context while destruction occurs
in the callee's context.
```cpp
class A {
public:
A() EXCLUSIVE_LOCK_FUNCTION(mu_) { mu_.Lock(); }
~A() UNLOCK_FUNCTION(mu_) { mu_.Unlock(); }
private:
Mutex mu_;
};
int do_something(A a) { // Previously: false positive warning
return 0;
}
```
Previously, thread safety analysis would see the destructor (unlock) in
`do_something` but not the corresponding constructor (lock) that
happened in the caller's context, causing a false positive.1 parent 72402e8 commit c1e17e5
File tree
2 files changed
+44
-0
lines changed- clang
- lib/Analysis
- test/SemaCXX
2 files changed
+44
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
43 | 43 | | |
44 | 44 | | |
45 | 45 | | |
| 46 | + | |
46 | 47 | | |
47 | 48 | | |
48 | 49 | | |
| |||
2820 | 2821 | | |
2821 | 2822 | | |
2822 | 2823 | | |
| 2824 | + | |
| 2825 | + | |
| 2826 | + | |
| 2827 | + | |
| 2828 | + | |
| 2829 | + | |
2823 | 2830 | | |
2824 | 2831 | | |
2825 | 2832 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1849 | 1849 | | |
1850 | 1850 | | |
1851 | 1851 | | |
| 1852 | + | |
| 1853 | + | |
| 1854 | + | |
| 1855 | + | |
| 1856 | + | |
| 1857 | + | |
| 1858 | + | |
| 1859 | + | |
| 1860 | + | |
| 1861 | + | |
| 1862 | + | |
| 1863 | + | |
| 1864 | + | |
| 1865 | + | |
| 1866 | + | |
| 1867 | + | |
| 1868 | + | |
| 1869 | + | |
| 1870 | + | |
| 1871 | + | |
| 1872 | + | |
| 1873 | + | |
| 1874 | + | |
| 1875 | + | |
| 1876 | + | |
| 1877 | + | |
| 1878 | + | |
| 1879 | + | |
| 1880 | + | |
| 1881 | + | |
| 1882 | + | |
| 1883 | + | |
| 1884 | + | |
| 1885 | + | |
| 1886 | + | |
| 1887 | + | |
| 1888 | + | |
1852 | 1889 | | |
1853 | 1890 | | |
1854 | 1891 | | |
| |||
0 commit comments