LibJS+ClangPlugins: Add escape hatch for GCPtr checks

This commit is contained in:
Andrew Kaster 2024-07-25 14:16:09 -06:00
parent 7f953a8519
commit f314f58fca
Notes: github-actions[bot] 2024-07-26 00:37:12 +00:00
2 changed files with 22 additions and 0 deletions

View file

@ -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) {

View file

@ -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; \