serenity/Toolchain/Patches/llvm/0006-clang-Add-fvisibility-inlines-hidden-function-templa.patch
Dan Klishch fa1eef8bbe Toolchain: Update LLVM to 18.1.3
Apart from bumping the toolchain Clang's and port's version, this commit
completely overhauls the way LLVM toolchain is built.

First, it gets rid of a complicated two-stage process of first compiling
clang and compiler-rt builtins and then building libunwind, libc++abi,
and libc++ -- it is possible to create a complete cross-compilation
toolchain in a single CMake invocation with a modern LLVM. Moreover, the
old method was inherently unsupported and subtly broken.

Next, it utilizes full potential of the Stubs "framework". Now we are
even able to compile Clang with -Wl,-z,defs which makes one of the
patches obsolete and the whole installation less error-prone. Note that
it comes at a cost of complicating the bootstrap process on a completely
novel architecture but this hopefully won't happen often.

Lastly, it fixes handling of the -no*lib* family of flags in the
Serenity LLVM driver and correctly uses -nostartfiles in conjunction
with stubs to make necessary CMake configure-time checks succeed.
2024-04-18 13:14:33 -06:00

90 lines
4.7 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Daniel Bertalan <dani@danielbertalan.dev>
Date: Fri, 8 Sep 2023 00:42:17 +0200
Subject: [PATCH] [clang] Add -fvisibility-inlines-hidden-function-templates
---
clang/include/clang/Basic/LangOptions.def | 3 +++
clang/include/clang/Driver/Options.td | 6 ++++++
clang/lib/AST/Decl.cpp | 18 ++++++++++++------
clang/lib/Driver/ToolChains/Clang.cpp | 2 ++
4 files changed, 23 insertions(+), 6 deletions(-)
diff --git a/clang/include/clang/Basic/LangOptions.def b/clang/include/clang/Basic/LangOptions.def
index 4942dcaa086e..677ad6273e3a 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -310,6 +310,9 @@ BENIGN_LANGOPT(IgnoreXCOFFVisibility, 1, 0, "All the visibility attributes that
BENIGN_LANGOPT(VisibilityInlinesHiddenStaticLocalVar, 1, 0,
"hidden visibility for static local variables in inline C++ "
"methods when -fvisibility-inlines hidden is enabled")
+BENIGN_LANGOPT(VisibilityInlinesHiddenFunctionTemplate, 1, 0,
+ "hidden visibility for implicitly instantiated C++ function "
+ "templates when -fvisibility-inlines-hidden is enabled")
ENUM_LANGOPT(GlobalAllocationFunctionVisibility, VisibilityForcedKinds, 3, VisibilityForcedKinds::ForceDefault,
"How to apply visibility to global operator new and delete declarations")
LANGOPT(NewInfallible , 1, 0, "Treats throwing global C++ operator new as always returning valid memory (annotates with __attribute__((returns_nonnull)) and throw()). This is detectable in source.")
diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td
index 175bedbfb4d0..7cc661956e3a 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3918,6 +3918,12 @@ defm visibility_inlines_hidden_static_local_var : BoolFOption<"visibility-inline
NegFlag<SetFalse, [], [ClangOption], "Disables -fvisibility-inlines-hidden-static-local-var"
" (this is the default on non-darwin targets)">, BothFlags<
[], [ClangOption, CC1Option]>>;
+defm visibility_inlines_hidden_function_template : BoolFOption<"visibility-inlines-hidden-function-template",
+ LangOpts<"VisibilityInlinesHiddenFunctionTemplate">, DefaultFalse,
+ PosFlag<SetTrue, [], [ClangOption, CC1Option],
+ "When -fvisibility-inlines-hidden is enabled, all template functions will be given"
+ " hidden visibility by default, even if they are not declared ``inline``">,
+ NegFlag<SetFalse>>;
def fvisibility_ms_compat : Flag<["-"], "fvisibility-ms-compat">, Group<f_Group>,
HelpText<"Give global types 'default' visibility and global functions and "
"variables 'hidden' visibility by default">;
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index 1ee33fd7576d..b8cb7e5a494b 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -562,13 +562,19 @@ static bool useInlineVisibilityHidden(const NamedDecl *D) {
TSK = MSI->getTemplateSpecializationKind();
}
+ if (TSK == TSK_ExplicitInstantiationDeclaration ||
+ TSK == TSK_ExplicitInstantiationDefinition)
+ return false;
+
const FunctionDecl *Def = nullptr;
- // InlineVisibilityHidden only applies to definitions, and
- // isInlined() only gives meaningful answers on definitions
- // anyway.
- return TSK != TSK_ExplicitInstantiationDeclaration &&
- TSK != TSK_ExplicitInstantiationDefinition &&
- FD->hasBody(Def) && Def->isInlined() && !Def->hasAttr<GNUInlineAttr>();
+ if (!FD->hasBody(Def))
+ return false;
+
+ if (Def->hasAttr<GNUInlineAttr>())
+ return false;
+
+ return Def->isInlined() || (TSK == TSK_ImplicitInstantiation &&
+ Opts.VisibilityInlinesHiddenFunctionTemplate);
}
template <typename T> static bool isFirstInExternCContext(T *D) {
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index aa344b3465ab..a9e2a4012fd1 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -6350,6 +6350,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
Args.AddLastArg(CmdArgs, options::OPT_fvisibility_inlines_hidden_static_local_var,
options::OPT_fno_visibility_inlines_hidden_static_local_var);
+ Args.AddLastArg(CmdArgs, options::OPT_fvisibility_inlines_hidden_function_template,
+ options::OPT_fno_visibility_inlines_hidden_function_template);
// -fvisibility-global-new-delete-hidden is a deprecated spelling of
// -fvisibility-global-new-delete=force-hidden.
--
2.44.0