diff options
author | Leonard Chan <leonardchan@google.com> | 2023-09-13 23:11:50 +0000 |
---|---|---|
committer | Leonard Chan <leonardchan@google.com> | 2023-09-13 23:15:50 +0000 |
commit | 6385c1df919f237d4149fabf542a158f61010bf8 (patch) | |
tree | e5e038bdf30c132d16a1054961248f0fd8e9fe63 /clang/lib/Frontend/CompilerInvocation.cpp | |
parent | 4fed5959974e4a85504667ce47ef03234dd9aec6 (diff) | |
download | llvm-6385c1df919f237d4149fabf542a158f61010bf8.zip llvm-6385c1df919f237d4149fabf542a158f61010bf8.tar.gz llvm-6385c1df919f237d4149fabf542a158f61010bf8.tar.bz2 |
[clang] Add experimental option to omit the RTTI component from the vtable when -fno-rtti is used
For programs that don't use RTTI, the rtti component is just replaced with a
zero. This way, vtables that don't use RTTI can still cooperate with vtables
that use RTTI since offset calculations on the ABI level would still work.
However, if throughout your whole program you don't use RTTI at all (such as
the embedded case), then this is just an unused pointer-sized component that's
wasting space. This adds an experimental option for removing the RTTI component
from the vtable.
Some notes:
- This is only allowed when RTTI is disabled, so we don't have to worry about
things like `typeid` or `dynamic_cast`.
- This is a "use at your own risk" since, similar to relative vtables, everything
must be compiled with this since it's an ABI breakage. That is, a program compiled
with this is not guaranteed to work with a program compiled without this, even
if RTTI is disabled for both programs.
Note that this is a completely different ABI flavor orthogonal to the
relative-vtables ABI. That is, they can be enabled/disabled independently.
Differential Revision: https://reviews.llvm.org/D152405
Diffstat (limited to 'clang/lib/Frontend/CompilerInvocation.cpp')
-rw-r--r-- | clang/lib/Frontend/CompilerInvocation.cpp | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index 730db8e..2dd299b 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -4109,6 +4109,14 @@ bool CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args, options::OPT_fno_experimental_relative_cxx_abi_vtables, TargetCXXABI::usesRelativeVTables(T)); + // RTTI is on by default. + bool HasRTTI = Args.hasFlag(options::OPT_frtti, options::OPT_fno_rtti, true); + Opts.OmitVTableRTTI = + Args.hasFlag(options::OPT_fexperimental_omit_vtable_rtti, + options::OPT_fno_experimental_omit_vtable_rtti, false); + if (Opts.OmitVTableRTTI && HasRTTI) + Diags.Report(diag::err_drv_using_omit_rtti_component_without_no_rtti); + for (const auto &A : Args.getAllArgValues(OPT_fmacro_prefix_map_EQ)) { auto Split = StringRef(A).split('='); Opts.MacroPrefixMap.insert( |