[clang] Thread Safety Analysis: Support warning on taking address of guarded variables (PR #123063)
Aaron Puchert via cfe-commits
cfe-commits at lists.llvm.org
Thu Feb 13 08:17:05 PST 2025
aaronpuchert wrote:
Something like `READ_ONCE` might be supported differently: suppose there is actually a read, i.e. an lvalue-to-rvalue cast. We check those here:
```c++
void BuildLockset::VisitCastExpr(const CastExpr *CE) {
if (CE->getCastKind() != CK_LValueToRValue)
return;
checkAccess(CE->getSubExpr(), AK_Read);
}
```
Then `checkAccess` looks through `*`:
```c++
if (const auto *UO = dyn_cast<UnaryOperator>(Exp)) {
// For dereferences
if (UO->getOpcode() == UO_Deref)
checkPtAccess(FSet, UO->getSubExpr(), AK, POK);
return;
}
```
Then we only need to make sure that `checkPtAccess` can look through `&`, as mentioned above. (Casts should already be unwrapped.) This might not even need a new flag, it's just closing a gap in the existing analysis.
https://github.com/llvm/llvm-project/pull/123063
More information about the cfe-commits
mailing list