mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-21 03:55:24 +00:00
LibJS+ClangPlugins: Add escape hatch for GCPtr checks
This commit is contained in:
parent
7f953a8519
commit
f314f58fca
Notes:
github-actions[bot]
2024-07-26 00:37:12 +00:00
Author: https://github.com/ADKaster Commit: https://github.com/LadybirdBrowser/ladybird/commit/f314f58fca0 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/837
2 changed files with 22 additions and 0 deletions
|
@ -155,6 +155,17 @@ static std::optional<QualTypeGCInfo> validate_field_qualified_type(clang::FieldD
|
|||
return {};
|
||||
}
|
||||
|
||||
static bool decl_has_annotation(clang::Decl const* decl, std::string name)
|
||||
{
|
||||
for (auto const* attr : decl->attrs()) {
|
||||
if (auto const* annotate_attr = llvm::dyn_cast<clang::AnnotateAttr>(attr)) {
|
||||
if (annotate_attr->getAnnotation() == name)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool LibJSGCVisitor::VisitCXXRecordDecl(clang::CXXRecordDecl* record)
|
||||
{
|
||||
using namespace clang::ast_matchers;
|
||||
|
@ -177,6 +188,9 @@ bool LibJSGCVisitor::VisitCXXRecordDecl(clang::CXXRecordDecl* record)
|
|||
if (!validation_results)
|
||||
continue;
|
||||
|
||||
if (decl_has_annotation(field, "serenity::ignore_gc"))
|
||||
continue;
|
||||
|
||||
auto [outer_type, base_type_inherits_from_cell] = *validation_results;
|
||||
|
||||
if (outer_type == OuterType::Ptr || outer_type == OuterType::Ref) {
|
||||
|
|
|
@ -19,6 +19,14 @@
|
|||
|
||||
namespace JS {
|
||||
|
||||
// This instrumentation tells analysis tooling to ignore a potentially mis-wrapped GC-allocated member variable
|
||||
// It should only be used when the lifetime of the GC-allocated member is always longer than the object
|
||||
#if defined(AK_COMPILER_CLANG)
|
||||
# define IGNORE_GC [[clang::annotate("serenity::ignore_gc")]]
|
||||
#else
|
||||
# define IGNORE_GC
|
||||
#endif
|
||||
|
||||
#define JS_CELL(class_, base_class) \
|
||||
public: \
|
||||
using Base = base_class; \
|
||||
|
|
Loading…
Add table
Reference in a new issue