0
Files
Takashi Sakamoto ae7fa269d8 [clang-plugin] make tools/clang/raw_ptr_plugin from tools/clang/plugins.
PS1 = Copy tools/clang/plugin to tools/clang/raw_ptr_plugin
      and rename FindBadConstructs* into RawPtrPlugin*.

Since it is not possible for clang plugins to depend //base, plugins
cannot depend on scoped_refptr. Instead, they use banned
std::shared_ptr. Since //tools/clang/plugins uses std::shared_ptr,
raw_ptr_plugin also uses it. To avoid chromium_presubmit, we need
to use No-Presubmit: true for this CL.

Change-Id: I19cb30740fabb006d991889e64a0abd9742b9b5f
No-Presubmit: true
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5529293
Reviewed-by: Keishi Hattori <keishi@chromium.org>
Reviewed-by: Daniel Cheng <dcheng@chromium.org>
Commit-Queue: Takashi Sakamoto <tasak@google.com>
Cr-Commit-Position: refs/heads/main@{#1301679}
2024-05-16 00:44:38 +00:00

49 lines
1.5 KiB
C++

// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef TOOLS_CLANG_RAW_PTR_PLUGIN_STACKALLOCATEDCHECKER_H_
#define TOOLS_CLANG_RAW_PTR_PLUGIN_STACKALLOCATEDCHECKER_H_
#include <map>
namespace clang {
class CompilerInstance;
class CXXRecordDecl;
class FieldDecl;
} // namespace clang
namespace raw_ptr_plugin {
// This determines a record (class/struct) is annotated with
// |STACK_ALLOCATED()|. Even if it is explicitly annotated with
// |STACK_ALLOCATED()|, this will consider it as "stack allocated" when its
// ancestor has the annotation. Similarly, classes with a "stack allocated"
// template type parameter is considered "stack allocated".
class StackAllocatedPredicate {
public:
bool IsStackAllocated(const clang::CXXRecordDecl* record) const;
private:
mutable std::map<const clang::CXXRecordDecl*, bool> cache_;
};
// This verifies usage of classes annotated with STACK_ALLOCATED().
// Specifically, it ensures that an instance of such a class cannot be used as a
// member variable in a non-STACK_ALLOCATED() class.
class StackAllocatedChecker {
public:
explicit StackAllocatedChecker(clang::CompilerInstance& compiler);
void Check(clang::CXXRecordDecl* record);
private:
clang::CompilerInstance& compiler_;
unsigned stack_allocated_field_error_signature_;
StackAllocatedPredicate predicate_;
};
} // namespace raw_ptr_plugin
#endif // TOOLS_CLANG_RAW_PTR_PLUGIN_STACKALLOCATEDCHECKER_H_