[Sema] Add `-fvisibility-global-new-delete=` option (#75364)
commit27ce26b06655cfece3d54b30e442ef93d3e78ac7
authorbd1976bris <bd1976llvm@gmail.com>
Mon, 22 Jan 2024 12:37:11 +0000 (22 12:37 +0000)
committerGitHub <noreply@github.com>
Mon, 22 Jan 2024 12:37:11 +0000 (22 12:37 +0000)
tree73d5fb4e6a8fc121bc45369c6f4eccc8f18c06f6
parentdf4ba00c7b50429fa88c3a9991e9194e2422dc76
[Sema] Add `-fvisibility-global-new-delete=` option (#75364)

[Sema] Add `-fvisibility-global-new-delete=` option (#75364)

By default the implicitly declared replaceable global new and delete
operators are given a default visibility attribute. Previous work, see:
https://reviews.llvm.org/D53787, added
`-fvisibility-global-new-delete-hidden` to change this to a hidden
visibility attribute.

This change adds `-fvisibility-global-new-delete=` which controls
whether (or not) to add an implicit visibility attribute to the implicit
declarations for these functions, and what visibility that attribute
will specify. The option takes 4 values: `force-hidden`,
`force-protected`, `force-default` and `source`. Option values
`force-hidden`, `force-protected` and `force-default` assign hidden,
protected, and default visibilities respectively; the use of the term
force in the value names is designed to imply to a user that the semantics
of this option differ significantly from `-fvisibility=`. An option
value of `source` implies that no implicit attribute is added; without
the attribute the replaceable global new and delete operators behave
normally (like other functions) with respect to visibility attributes,
pragmas and options.

The motivation for the `source` value is to facilitate users who intend
to replace these functions either for a single linkage unit or a limited
set of linkage units. `-fvisibility-global-new-delete=source` can be
applied globally to the compilations in a build where the existing
`-fvisibility-global-new-delete-hidden` cannot, as it conflicts with a
common pattern where these functions are dynamically imported.

The existing `-fvisibility-global-new-delete-hidden` is now a deprecated
spelling of `-fvisibility-global-new-delete=force-hidden`

A release note has been added for these changes.

`-fvisibility-global-new-delete=source` will be set by default for PS5.
PS5 users that want the normal toolchain behaviour will be able to
supply `-fvisibility-global-new-delete=force-default`.
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/LangOptions.def
clang/include/clang/Basic/LangOptions.h
clang/include/clang/Driver/Options.td
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Driver/ToolChains/PS4CPU.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/test/CodeGenCXX/visibility-global-new-delete.cpp [new file with mode: 0644]
clang/test/Driver/visibility-global-new-delete.cl [new file with mode: 0644]