Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

ClangPlugins: Warn on Handle/SafeFunction members in GC allocated objects; Verify JS_CELL-like macros #24422

Merged
merged 7 commits into from
May 30, 2024

Conversation

mattco98
Copy link
Collaborator

@mattco98 mattco98 commented May 23, 2024

The plugins now detect if a GC-allocated class contains a field with a Handle/SafeFunction type. Unfortunately there are many occurrences of this in the code base, so for now I've left it as a warning with a FIXME to change it to an error later. It is also very noisy at the moment, but that is because many warnings are emitted for each field occurrence. Not quite sure how to fix this, but in the mean time it can serve as motivation to change the field types 馃槂

The plugins now also verify that the JS_CELL-like macros are used properly. This includes JS_CELL, JS_OBJECT, JS_ENVIRONMENT, JS_PROTOTYPE_OBJECT, and WEB_PLATFORM_OBJECT. For these macros, the first argument must exactly match the class name in the declaration, and the second argument must exactly match the parent name (namespaces included).

Closes #23900, closes #23881, closes #23880

@github-actions github-actions bot added the 馃憖 pr-needs-review PR needs review from a maintainer or community member label May 23, 2024
@mattco98 mattco98 force-pushed the clang-plugins-bad-field-types branch from 627f977 to f310ee7 Compare May 23, 2024 14:18
Copy link
Member

@ADKaster ADKaster left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This all looks very cool. I do wonder though, could we have 'nosiy' warnings behind a flag (or plugin opt..?) so that folks can enable the plugins for general libweb work without worrying about noise in their build logs?

@mattco98
Copy link
Collaborator Author

mattco98 commented May 23, 2024

This all looks very cool. I do wonder though, could we have 'nosiy' warnings behind a flag (or plugin opt..?) so that folks can enable the plugins for general libweb work without worrying about noise in their build logs?

Like a CMake flag that ends up adding -fplugin-arg-...? Yeah I could probably do that.

Note to self: need to change the plugin names use underscores instead of dashes to be able to use -fplugin-arg.

@mattco98 mattco98 force-pushed the clang-plugins-bad-field-types branch from f310ee7 to d00ea71 Compare May 24, 2024 11:49
This makes it more clear what it is used for
This allows arguments to be passed to them from the command line
GC-allocated objects should never have JS::SafeFunction/JS::Handle
fields.

For now the plugin only emits warnings here, as there are many cases
of this occurring in the codebase that aren't trivial to fix. It is also
behind a CMake flag since it is a _very_ loud warning.
@mattco98 mattco98 force-pushed the clang-plugins-bad-field-types branch from d00ea71 to 54f4a0d Compare May 24, 2024 13:24
@ADKaster ADKaster merged commit 5740f93 into SerenityOS:master May 30, 2024
12 checks passed
@github-actions github-actions bot removed the 馃憖 pr-needs-review PR needs review from a maintainer or community member label May 30, 2024
@mattco98 mattco98 deleted the clang-plugins-bad-field-types branch May 30, 2024 15:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants