LibJSGCVerifier: Support marking GCPtr members as raw references

This lets us avoid false positives when a GCPtr-wrapped member is only
a weak reference which is automatically updated by the GC when the
member's gc state is updated.
This commit is contained in:
Idan Horowitz 2024-04-05 20:04:37 +03:00 committed by Andreas Kling
parent c3217754f1
commit c84cd1d668
Notes: sideshowbarker 2024-07-17 03:30:41 +09:00
4 changed files with 9 additions and 5 deletions

View file

@ -87,7 +87,7 @@ std::vector<clang::QualType> get_all_qualified_types(clang::QualType const& type
if (auto const* template_specialization = type->getAs<clang::TemplateSpecializationType>()) {
auto specialization_name = template_specialization->getTemplateName().getAsTemplateDecl()->getQualifiedNameAsString();
// Do not unwrap GCPtr/NonnullGCPtr
if (specialization_name == "JS::GCPtr" || specialization_name == "JS::NonnullGCPtr") {
if (specialization_name == "JS::GCPtr" || specialization_name == "JS::NonnullGCPtr" || specialization_name == "JS::RawGCPtr") {
qualified_types.push_back(type);
} else {
auto const template_arguments = template_specialization->template_arguments();
@ -141,7 +141,7 @@ FieldValidationResult validate_field(clang::FieldDecl const* field_decl)
}
} else if (auto const* specialization = qualified_type->getAs<clang::TemplateSpecializationType>()) {
auto template_type_name = specialization->getTemplateName().getAsTemplateDecl()->getName();
if (template_type_name != "GCPtr" && template_type_name != "NonnullGCPtr")
if (template_type_name != "GCPtr" && template_type_name != "NonnullGCPtr" && template_type_name != "RawGCPtr")
return result;
auto const template_args = specialization->template_arguments();
@ -159,7 +159,7 @@ FieldValidationResult validate_field(clang::FieldDecl const* field_decl)
result.is_wrapped_in_gcptr = true;
result.is_valid = record_inherits_from_cell(*record_decl);
result.needs_visiting = true;
result.needs_visiting = template_type_name != "RawGCPtr";
}
}

View file

@ -186,6 +186,10 @@ private:
T* m_ptr { nullptr };
};
// Non-Owning GCPtr
template<typename T>
using RawGCPtr = GCPtr<T>;
template<typename T, typename U>
inline bool operator==(GCPtr<T> const& a, GCPtr<U> const& b)
{

View file

@ -100,7 +100,7 @@ private:
struct FreelistEntry final : public Cell {
JS_CELL(FreelistEntry, Cell);
GCPtr<FreelistEntry> next;
RawGCPtr<FreelistEntry> next;
};
Cell* cell(size_t index)

View file

@ -32,7 +32,7 @@ public:
private:
explicit WeakSet(Object& prototype);
HashTable<GCPtr<Cell>> m_values; // This stores Cell pointers instead of Object pointers to aide with sweeping
HashTable<RawGCPtr<Cell>> m_values; // This stores Cell pointers instead of Object pointers to aide with sweeping
};
}