[clang] [Sema] Provide `-fno-/-fvisibility-global-new-delete` option (PR #75364)

via cfe-commits cfe-commits at lists.llvm.org
Mon Dec 18 12:30:30 PST 2023


bd1976bris wrote:

> From a UI perspective, "add a visibility attribute" doesn't seem all that descriptive. What visibility does it add? Therefore, I suggest `-fvisibility-global-new-delete[=<visibility>]` so the user can ask for what they want, and `-fvisibility-global-new-delete-hidden` equals `-fvisibility-global-new-delete=hidden`. The help text can indicate that the default is `default`.

Thanks Paul. It's a nice suggestion for the UI. I didn't go down this route because the name `-fvisibility-global-new-delete[=<visibility>]` seems to imply (at least to me) that the option should behave like `-fvisibility[=<visibility>]` . However, the latter only applies to definitions and not to declarations whereas the former would apply to both.

> I'm unclear what the `-fno` variant actually turns into. There's always a visibility, ultimately, right? So wouldn't that be equivalent to the `keep` option in #74629 ? Which suggests not having the `-fno` variant here, and allowing `=keep` instead.

There's a difference! The `keep` option in #74629 is applying to the visibility of the IR globals. However, the replaceable new and delete declarations are given a visibility during SEMA (a `VisibilityAttr`) - as if those declarations were parsed with an explicit visibility attribute. By default that `VisibilityAttr` has `default` visibility but `-fvisibility-global-new-delete-hidden` changes it to `hidden` visibility. The proposed `-fno-visibility-global-new-delete` instructs the compiler not to add a `VisibilityAttr` to these special globals. Therefore, these declarations behaviour like any other declarations w.r.t. visibility options/attributes and pragmas.

https://github.com/llvm/llvm-project/pull/75364


More information about the cfe-commits mailing list