[clang] [analyzer][NFC] Introduce APSIntPtr, a safe wrapper of APSInt (1/4) (PR #120435)

Arseniy Zaostrovnykh via cfe-commits cfe-commits at lists.llvm.org
Thu Dec 19 00:08:50 PST 2024


================
@@ -165,79 +166,70 @@ class BasicValueFactory {
 
   /// Convert - Create a new persistent APSInt with the same value as 'From'
   ///  but with the bitwidth and signedness of 'To'.
-  const llvm::APSInt &Convert(const llvm::APSInt& To,
-                              const llvm::APSInt& From) {
+  APSIntPtr Convert(const llvm::APSInt &To, const llvm::APSInt &From) {
     APSIntType TargetType(To);
     if (TargetType == APSIntType(From))
-      return From;
+      return APSIntPtr(&From);
----------------
necto wrote:

This might create a tricky bug, given that despite the doc comment and the type signature, this function does not create a persistent APSInt *only in this case*, if `From` was not persistent on the call.
I suggest requiring the `From` argument to be `APSIntPtr` to make this function safer.

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


More information about the cfe-commits mailing list