[clang] [clang][ssaf] Add cpp-bounded-buffers source transformation (PR #210457)
Balázs Benics via cfe-commits
cfe-commits at lists.llvm.org
Wed Aug 12 06:46:28 PDT 2026
================
@@ -0,0 +1,77 @@
+//===- CppBoundedBuffers.h --------------------------------------*- 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
+//
+//===----------------------------------------------------------------------===//
+//
+// The cpp-bounded-buffers transformation rewrites buffers -- raw pointers and
+// arrays -- reachable from unsafe buffer usage into bounded types
+// (bounded_ptr<T>, bounded_array<T, N>). Reachable declarators that are not
+// rewritten are reported instead, so no reachable buffer is silently left raw.
+//
+//===----------------------------------------------------------------------===//
+
+#ifndef LLVM_CLANG_SCALABLESTATICANALYSIS_SOURCETRANSFORMATION_TRANSFORMATIONS_CPPBOUNDEDBUFFERS_H
+#define LLVM_CLANG_SCALABLESTATICANALYSIS_SOURCETRANSFORMATION_TRANSFORMATIONS_CPPBOUNDEDBUFFERS_H
+
+#include "clang/AST/Type.h"
+#include "clang/ScalableStaticAnalysis/SourceTransformation/Transformation.h"
+#include "llvm/ADT/SmallSet.h"
+#include "llvm/ADT/StringRef.h"
+#include <optional>
+#include <string>
+
+namespace clang {
+class ASTContext;
+} // namespace clang
+
+namespace clang::ssaf {
+
+/// The bounded type a raw declarator is rewritten to.
+enum class BoundedType { Ptr, Array };
+
+/// Why a reachable declarator was reported instead of rewritten.
+enum class ReportReason {
+ MultiLevelPointer,
+ PointerToArray,
+ ReferenceToPointer,
+ MultiDimensionalArray,
+ IncompleteArray,
+ UnreproducibleType,
+ DeclarationGroup,
+ MacroExpansion,
+ TrailingReturnType,
+ EmissionFailed,
+ NotTransformed,
+};
----------------
steakhal wrote:
Are there any reason for not having these sorted?
https://github.com/llvm/llvm-project/pull/210457
More information about the cfe-commits
mailing list