Skip to content

Commit 1fdef3b

Browse files
committed
[-Wunsafe-buffer-usage][NFC] Note future work for isSafeArraySubscript
-Warray-bounds implemented in Sema::CheckArrayAccess() already solves a similar (opposite) problem and is battle-tested. Adding -Wunsafe-buffer-usage diagnostics to Sema is a non starter as we need to emit both the warnings and fixits and the performance impact of the fixit machine is unacceptable for Sema. CheckArrayAccess() as is doesn't distinguish between "safe" and "unknown" array accesses. It also mixes the analysis that decides if an index is out of bounds with crafting the diagnostics. A refactor of CheckArrayAccess() might serve both the original purpose and help us avoid false-positive with -Wunsafe-buffer-usage on constant size arrrays.
1 parent a82cc25 commit 1fdef3b

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

clang/lib/Analysis/UnsafeBufferUsage.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,12 @@ AST_MATCHER(CXXConstructExpr, isSafeSpanTwoParamConstruct) {
408408
}
409409

410410
AST_MATCHER(ArraySubscriptExpr, isSafeArraySubscript) {
411+
// FIXME: Proper solution:
412+
// - refactor Sema::CheckArrayAccess
413+
// - split safe/OOB/unknown decision logic from diagnostics emitting code
414+
// - e. g. "Try harder to find a NamedDecl to point at in the note." already duplicated
415+
// - call both from Sema and from here
416+
411417
const DeclRefExpr * BaseDRE = dyn_cast_or_null<DeclRefExpr>(Node.getBase()->IgnoreParenImpCasts());
412418
if (!BaseDRE)
413419
return false;

0 commit comments

Comments
 (0)