clang 23.0.0git
UnsafeBufferUsageAnalysis.cpp
Go to the documentation of this file.
1//===- UnsafeBufferUsageAnalysis.cpp - WPA for UnsafeBufferUsage ----------===//
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// UnsafeBufferUsageAnalysis is a noop analysis.
9//
10// UnsafeBufferUsageAnalysisResult is a map from EntityIds to
11// EntityPointerLevelSets
12//===----------------------------------------------------------------------===//
13
15#include "SSAFAnalysesCommon.h"
22#include "llvm/Support/Error.h"
23#include "llvm/Support/JSON.h"
24#include <memory>
25
26using namespace clang::ssaf;
27using namespace llvm;
28
29namespace {
30
31json::Object serializeUnsafeBufferUsageAnalysisResult(
34 json::Object Result;
35
37 entityPointerLevelMapToJSON(R.UnsafeBuffers, IdToJSON);
38 return Result;
39}
40
42deserializeUnsafeBufferUsageAnalysisResult(
43 const json::Object &Obj, JSONFormat::EntityIdFromJSONFn IdFromJSON) {
44 const json::Array *Content =
46
47 if (!Content)
48 return makeSawButExpectedError(Obj, "an object with a key %s",
50
51 auto UnsafeBuffers = entityPointerLevelMapFromJSON(*Content, IdFromJSON);
52
53 if (!UnsafeBuffers)
54 return UnsafeBuffers.takeError();
55
56 auto Ret = std::make_unique<UnsafeBufferUsageAnalysisResult>();
57
58 Ret->UnsafeBuffers = std::move(*UnsafeBuffers);
59 return Ret;
60}
61
62JSONFormat::AnalysisResultRegistry::Add<UnsafeBufferUsageAnalysisResult>
63 RegisterUnsafeBufferUsageResultForJSON(
64 serializeUnsafeBufferUsageAnalysisResult,
65 deserializeUnsafeBufferUsageAnalysisResult);
66
67class UnsafeBufferUsageAnalysis final
68 : public SummaryAnalysis<UnsafeBufferUsageAnalysisResult,
69 UnsafeBufferUsageEntitySummary> {
70public:
71 llvm::Error add(EntityId Id,
72 const UnsafeBufferUsageEntitySummary &Summary) override {
73 auto UnsafeBuffersOfEntity = getUnsafeBuffers(Summary);
74
75 getResult().UnsafeBuffers[Id] = EntityPointerLevelSet(
76 UnsafeBuffersOfEntity.begin(), UnsafeBuffersOfEntity.end());
77 return llvm::Error::success();
78 }
79};
80
82 RegisterUnsafeBufferUsageAnalysis(
83 "Whole-program unsafe buffer usage analysis");
84
85} // namespace
86
87// NOLINTNEXTLINE(misc-use-internal-linkage)
Result
Implement __builtin_bit_cast and related operations.
volatile int UnsafeBufferUsageAnalysisAnchorSource
llvm::function_ref< llvm::Expected< EntityId >(const Object &)> EntityIdFromJSONFn
Definition JSONFormat.h:71
llvm::function_ref< Object(EntityId)> EntityIdToJSONFn
Definition JSONFormat.h:70
Typed intermediate that concrete summary analyses inherit from.
PRESERVE_NONE bool Ret(InterpState &S, CodePtr &PC)
Definition Interp.h:258
Expected< std::map< EntityId, EntityPointerLevelSet > > entityPointerLevelMapFromJSON(const llvm::json::Array &Content, JSONFormat::EntityIdFromJSONFn IdFromJSON)
Deserialize a flat array of alternating [EntityId, EntityPointerLevelSet, ...] pairs into a map.
llvm::Error makeSawButExpectedError(const JSONTy &Saw, llvm::StringRef Expected, const Ts &...ExpectedArgs)
constexpr llvm::StringLiteral UnsafeBufferUsageAnalysisResultName
llvm::json::Array entityPointerLevelMapToJSON(const std::map< EntityId, EntityPointerLevelSet > &Map, JSONFormat::EntityIdToJSONFn IdToJSON)
Serialize a map<EntityId, EntityPointerLevelSet> as a flat array of alternating [EntityId,...
Diagnostic wrappers for TextAPI types for error reporting.
Definition Dominators.h:30
Registers AnalysisT with the unified registry.