[clang] [analyzer] Model concrete floating-point values (PR #214098)

Balázs Benics via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 21 10:01:27 PDT 2026


================
@@ -0,0 +1,52 @@
+//== APFloatPtr.h - Wrapper for APFloat objects owned separately -*- 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
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_APFLOATPTR_H
+#define LLVM_CLANG_STATICANALYZER_CORE_PATHSENSITIVE_APFLOATPTR_H
+
+#include "llvm/ADT/APFloat.h"
+#include "llvm/Support/Compiler.h"
+
+namespace clang::ento {
+
+/// A safe wrapper around APFloat objects allocated and owned by
+/// \c BasicValueFactory. This just wraps a common llvm::APFloat.
+class APFloatPtr {
+  using APFloat = llvm::APFloat;
+
+public:
+  APFloatPtr() = delete;
+  APFloatPtr(const APFloatPtr &) = default;
+  APFloatPtr &operator=(const APFloatPtr &) & = default;
+  ~APFloatPtr() = default;
+
+  /// You should not use this API.
+  /// If do, ensure that the \p Ptr is not going to dangle.
+  /// Prefer using \c BasicValueFactory::getFloatValue() to get an APFloatPtr
+  /// object.
+  static APFloatPtr unsafeConstructor(const APFloat *Ptr) {
----------------
steakhal wrote:

I'd be more restrictive and make this private and mark `BasicValueFactory` as a friend class.
Have a comment with something like: `BasicValueFactory` owns the storage of \p Ptr.

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


More information about the cfe-commits mailing list