[clang] [NFC][Clang][unsafe-buffer-usage] Simplify isPtrBufferSafe with helper. (PR #178768)

Rohan Jacob-Rao via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 4 13:55:39 PST 2026


================
@@ -458,6 +458,46 @@ static bool areEqualIntegers(const Expr *E1, const Expr *E2, ASTContext &Ctx) {
   }
 }
 
+// Given an expression like `&X` or `std::addressof(X)`, returns the `Expr`
+// corresponding to `X` (after removing parens and implicit casts).
+// Returns null if the input expression `E` is not an address-of expression.
+static const Expr *getSubExprInAddressOfExpr(const Expr &E) {
----------------
rohanjr wrote:

I made it a reference to codify the assumption that `E` is not null. (The previous versions of these functions dereference the pointer without a check.) This is a positive in my mind, and there are other uses of reference parameters such as for `ASTContext`.

I do see that most of the AST nodes are passed around by pointers, so if you feel this is more important I don't mind changing it back to pointers.

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


More information about the cfe-commits mailing list