Forráskód Böngészése

LibJS+ClangPlugins: Add escape hatch for GCPtr checks

Andrew Kaster 1 éve
szülő
commit
f314f58fca

+ 14 - 0
Meta/Lagom/ClangPlugins/LibJSGCPluginAction.cpp

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

+ 8 - 0
Userland/Libraries/LibJS/Heap/Cell.h

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