clang 24.0.0git
CppBoundedBuffers.h
Go to the documentation of this file.
1//===- CppBoundedBuffers.h --------------------------------------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// The cpp-bounded-buffers transformation rewrites buffers -- raw pointers and
10// arrays -- reachable from unsafe buffer usage into bounded types
11// (bounded_ptr<T>, bounded_array<T, N>). Reachable declarators that are not
12// rewritten are reported instead, so no reachable buffer is silently left raw.
13//
14//===----------------------------------------------------------------------===//
15
16#ifndef LLVM_CLANG_SCALABLESTATICANALYSIS_SOURCETRANSFORMATION_TRANSFORMATIONS_CPPBOUNDEDBUFFERS_H
17#define LLVM_CLANG_SCALABLESTATICANALYSIS_SOURCETRANSFORMATION_TRANSFORMATIONS_CPPBOUNDEDBUFFERS_H
18
19#include "clang/AST/Type.h"
21#include "llvm/ADT/SmallSet.h"
22#include "llvm/ADT/StringRef.h"
23#include <optional>
24#include <string>
25
26namespace clang {
27class ASTContext;
28} // namespace clang
29
30namespace clang::ssaf {
31
32/// The bounded type a raw declarator is rewritten to.
33enum class BoundedType { Ptr, Array };
34
35/// Why a reachable declarator was reported instead of rewritten.
54
55/// Returns the report message for \p Reason.
56llvm::StringRef messageFor(ReportReason Reason);
57
58/// The outcome of classifying a declared type against the reachable pointer
59/// levels of its entity: a bounded-type rewrite, or a report reason.
61 // Meaningful only when Skip is nullopt.
63 // Pointee/element spelling; meaningful only when Skip is nullopt.
64 std::string InnerSpelling;
65 std::optional<ReportReason> Skip = ReportReason::NotTransformed;
66};
67
68/// Classifies the declared type \p T of a reachable entity. \p ReachableLevels
69/// holds the entity's reachable pointer levels (1-based, outermost is level 1).
71classifyDeclType(QualType T, const llvm::SmallSet<unsigned, 4> &ReachableLevels,
72 const ASTContext &Ctx);
73
74class CppBoundedBuffers final : public Transformation {
75public:
77
78 void HandleTranslationUnit(clang::ASTContext &Ctx) override;
79};
80
81} // namespace clang::ssaf
82
83#endif // LLVM_CLANG_SCALABLESTATICANALYSIS_SOURCETRANSFORMATION_TRANSFORMATIONS_CPPBOUNDEDBUFFERS_H
C Language Family Type Representation.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition ASTContext.h:223
A (possibly-)qualified type.
Definition TypeBase.h:938
Transformation(const WPASuite &Suite, SourceEditEmitter &Edits, TransformationReportEmitter &Report)
void HandleTranslationUnit(clang::ASTContext &Ctx) override
HandleTranslationUnit - This method is called when the ASTs for entire translation unit have been par...
Transformation(const WPASuite &Suite, SourceEditEmitter &Edits, TransformationReportEmitter &Report)
BoundedType
The bounded type a raw declarator is rewritten to.
llvm::json::Array Array
ClassifyResult classifyDeclType(QualType T, const llvm::SmallSet< unsigned, 4 > &ReachableLevels, const ASTContext &Ctx)
Classifies the declared type T of a reachable entity.
llvm::StringRef messageFor(ReportReason Reason)
Returns the report message for Reason.
ReportReason
Why a reachable declarator was reported instead of rewritten.
Top level wrappers for InstallAPI frontend operations.
const FunctionProtoType * T
The outcome of classifying a declared type against the reachable pointer levels of its entity: a boun...
std::optional< ReportReason > Skip