Skip to content

Commit 1a9377b

Browse files
authored
[clang][analysis] Thread Safety Analysis: Handle parenthesis (#140656)
1 parent a0058d1 commit 1a9377b

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

clang/lib/Analysis/ThreadSafety.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1671,7 +1671,7 @@ void ThreadSafetyAnalyzer::checkAccess(const FactSet &FSet, const Expr *Exp,
16711671
// Guard against self-initialization. e.g., int &i = i;
16721672
if (E == Exp)
16731673
break;
1674-
Exp = E;
1674+
Exp = E->IgnoreImplicit()->IgnoreParenCasts();
16751675
continue;
16761676
}
16771677
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// RUN: %clang_cc1 -verify -fsyntax-only -Wthread-safety %s
2+
3+
struct __attribute__((lockable)) Lock {};
4+
5+
void sink_protected(int);
6+
7+
struct Baz {
8+
public:
9+
Lock lock_;
10+
int protected_num_ __attribute__((guarded_by(lock_))) = 1;
11+
};
12+
13+
void paren_test() {
14+
Baz baz;
15+
int& n = baz.protected_num_;
16+
sink_protected(n); // expected-warning{{reading variable 'protected_num_' requires holding mutex 'baz.lock_'}}
17+
int& n2 = (baz.protected_num_);
18+
sink_protected(n2); // expected-warning{{reading variable 'protected_num_' requires holding mutex 'baz.lock_'}}
19+
}

0 commit comments

Comments
 (0)