Skip to content

Commit a451fff

Browse files
authored
[llvm] fix extern cl::opt definitions for DLL export (#145374)
## Purpose This patch is one in a series of code-mods that annotate LLVM’s public interface for export. This patch ensures a few `cl::opt` declarations are properly annotated with `LLVM_ABI`. The annotations currently have no meaningful impact on the LLVM build; however, they are a prerequisite to support an LLVM Windows DLL (shared library) build. ## Background This effort is tracked in #109483. Additional context is provided in [this discourse](https://discourse.llvm.org/t/psa-annotating-llvm-public-interface/85307), and documentation for `LLVM_ABI` and related annotations is found in the LLVM repo [here](https://github.com/llvm/llvm-project/blob/main/llvm/docs/InterfaceExportAnnotations.rst). ## Overview - Remove local `extern` declarations of `llvm::PrintPipelinePasses` because it is already correctly declared with an `LLVM_ABI` annotation in `llvm\Passes\PassBuilder.h`. Leaving these declarations results in a gcc compile warning unless they are also annotated with `LLVM_ABI`. - Similarly, remove local `extern` declarations of `ProfileSummaryCutoffHot` and `UseContextLessSummary` from `llvm/tools/llvm-profgen/ProfileGenerator.cpp` since they are declared with `LLVM_ABI` in `llvm\ProfileData\ProfileCommon.h`. - Explicitly annotate the extern declaration of `ProfileCorrelate` in `clang/lib/CodeGen/BackendUtil.cpp` since it is not declared in a header. The definition of `ProfileCorrelate` in `llvm\lib\Transforms\Instrumentation\InstrProfiling.cpp` is already annotated with `LLVM_ABI`. ## Validation Local builds and tests to validate cross-platform compatibility. This included llvm, clang, and lldb on the following configurations: - Windows with MSVC - Windows with Clang - Linux with GCC - Linux with Clang - Darwin with Clang
1 parent e93a0d0 commit a451fff

File tree

3 files changed

+3
-9
lines changed

3 files changed

+3
-9
lines changed

clang/lib/CodeGen/BackendUtil.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include "llvm/ProfileData/InstrProfCorrelator.h"
4444
#include "llvm/Support/BuryPointer.h"
4545
#include "llvm/Support/CommandLine.h"
46+
#include "llvm/Support/Compiler.h"
4647
#include "llvm/Support/MemoryBuffer.h"
4748
#include "llvm/Support/PrettyStackTrace.h"
4849
#include "llvm/Support/Program.h"
@@ -96,8 +97,6 @@ using namespace llvm;
9697
#include "llvm/Support/Extension.def"
9798

9899
namespace llvm {
99-
extern cl::opt<bool> PrintPipelinePasses;
100-
101100
// Experiment to move sanitizers earlier.
102101
static cl::opt<bool> ClSanitizeOnOptimizerEarlyEP(
103102
"sanitizer-early-opt-ep", cl::Optional,
@@ -118,7 +117,8 @@ static cl::opt<PGOOptions::ColdFuncOpt> ClPGOColdFuncAttr(
118117
clEnumValN(PGOOptions::ColdFuncOpt::OptNone, "optnone",
119118
"Mark cold functions with optnone.")));
120119

121-
extern cl::opt<InstrProfCorrelator::ProfCorrelatorKind> ProfileCorrelate;
120+
LLVM_ABI extern cl::opt<InstrProfCorrelator::ProfCorrelatorKind>
121+
ProfileCorrelate;
122122
} // namespace llvm
123123
namespace clang {
124124
extern llvm::cl::opt<bool> ClSanitizeGuardChecks;

flang/lib/Frontend/FrontendActions.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,6 @@
7474
#include <memory>
7575
#include <system_error>
7676

77-
namespace llvm {
78-
extern cl::opt<bool> PrintPipelinePasses;
79-
} // namespace llvm
80-
8177
using namespace Fortran::frontend;
8278

8379
constexpr llvm::StringLiteral timingIdParse = "Parse";

llvm/tools/llvm-profgen/ProfileGenerator.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,6 @@ using namespace llvm;
108108
using namespace sampleprof;
109109

110110
namespace llvm {
111-
extern cl::opt<int> ProfileSummaryCutoffHot;
112-
extern cl::opt<bool> UseContextLessSummary;
113111

114112
namespace sampleprof {
115113

0 commit comments

Comments
 (0)