[clang] [llvm] [NFC][analyzer] Introduce the BoundsChecking library (PR #213957)

DonĂ¡t Nagy via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 5 06:05:45 PDT 2026


================
@@ -0,0 +1,105 @@
+//===- BoundsChecking.h - Bounds checking related APIs ----------*- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===----------------------------------------------------------------------===//
+//
+//  This header declares 'checkBounds', a function that compares memory offsets
+//  (that may be symbolic) and uses heuristical workarounds to provide more
+//  accurate results than directly calling evalBinOp or assumeInBound.
+//
+//  As of now, this logic only supports the needs of `security.ArrayBound`, but
+//  in the future it will be generalized and applied in all checkers that
+//  perform bounds checking (to bring them out of `alpha` stage).
+//
+//  TODO: This header should be extended by other utilities (e.g. message
+//  formatting tools) that are relevant for multiple bounds checking checkers.
+//
----------------
NagyDonat wrote:

No, currently the message formatting tools are left in `ArrayBoundChecker.cpp`.

The "first attempt" PR https://github.com/llvm/llvm-project/pull/202372 also moved those to `BoundsChecking.{h,cpp}` but here I follow a more gradual approach and left those in `ArrayBoundChecker.cpp` because I don't know which of the formatting tools will be actually useful in other checkers like PointerArithm or cstring out of bounds.

I added this TODO to state that although this header now only contains `checkBounds()`, all other tools for bounds checking belong here.

https://github.com/llvm/llvm-project/pull/213957


More information about the llvm-commits mailing list