[clang] [lldb] [Clang] Improve Sema diagnostic performance for __builtin_counted_by_ref (PR #116719)
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Wed Nov 27 06:39:33 PST 2024
================
@@ -14690,6 +14690,13 @@ void Sema::FinalizeDeclaration(Decl *ThisDecl) {
}
}
+ // The result of __builtin_counted_by_ref cannot be assigned to a variable.
+ // It allows leaking and modification of bounds safety information.
+ if (IsBuiltinCountedByRef(VD->getInit()))
+ Diag(VD->getInit()->getExprLoc(),
+ diag::err_builtin_counted_by_ref_cannot_leak_reference)
+ << VD->getInit()->getSourceRange();
----------------
AaronBallman wrote:
It is the same in every case. Each time, the logic is:
```
if (IsBuiltinCountedByRef(SomeExpr))
Diag(SomeExpr->getExprLoc(), diag::err_builtin_counted_by_ref_cannot_leak_reference) << SomeExpr->getSourceRange();
```
This would require changing some later to this equivalent:
```
auto CheckBuiltinCountedByRef = [&](const Expr *E) {
if (BinaryOperator::isAssignmentOp(Opc))
CheckInvalidBuiltinCountedByRef(E);
else if (IsBuiltinCountedByRef(E))
Diag(E->getExprLoc(), diag::err_builtin_counted_by_ref_invalid_use)
<< 1 << E->getSourceRange();
};
```
https://github.com/llvm/llvm-project/pull/116719
More information about the cfe-commits
mailing list