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

Donát Nagy via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 24 07:28:53 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) {
----------------
NagyDonat wrote:

I agree with this suggestion – using a `friend` is a better approach. In that case you don't need this `unsafeConstructor`, the friend can just call the private constructor directly.

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


More information about the cfe-commits mailing list