Skip to content

Commit b6d070f

Browse files
andrurogerztomtor
authored andcommitted
[llvm] annotate interfaces in llvm/Option and llvm/Remarks for DLL export (llvm#142856)
## Purpose This patch is one in a series of code-mods that annotate LLVM’s public interface for export. This patch annotates the `llvm/Options` and `llvm/Remarks` libraries. These 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 llvm#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). These changes were generated automatically using the [Interface Definition Scanner (IDS)](https://github.com/compnerd/ids) tool, followed formatting with `git clang-format`. No manual fixups were required. ## 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 8d3958a commit b6d070f

File tree

12 files changed

+103
-85
lines changed

12 files changed

+103
-85
lines changed

llvm/include/llvm/Option/Arg.h

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "llvm/ADT/SmallVector.h"
1818
#include "llvm/ADT/StringRef.h"
1919
#include "llvm/Option/Option.h"
20+
#include "llvm/Support/Compiler.h"
2021
#include <string>
2122

2223
namespace llvm {
@@ -70,15 +71,16 @@ class Arg {
7071
std::unique_ptr<Arg> Alias;
7172

7273
public:
73-
Arg(const Option Opt, StringRef Spelling, unsigned Index,
74-
const Arg *BaseArg = nullptr);
75-
Arg(const Option Opt, StringRef Spelling, unsigned Index,
76-
const char *Value0, const Arg *BaseArg = nullptr);
77-
Arg(const Option Opt, StringRef Spelling, unsigned Index,
78-
const char *Value0, const char *Value1, const Arg *BaseArg = nullptr);
74+
LLVM_ABI Arg(const Option Opt, StringRef Spelling, unsigned Index,
75+
const Arg *BaseArg = nullptr);
76+
LLVM_ABI Arg(const Option Opt, StringRef Spelling, unsigned Index,
77+
const char *Value0, const Arg *BaseArg = nullptr);
78+
LLVM_ABI Arg(const Option Opt, StringRef Spelling, unsigned Index,
79+
const char *Value0, const char *Value1,
80+
const Arg *BaseArg = nullptr);
7981
Arg(const Arg &) = delete;
8082
Arg &operator=(const Arg &) = delete;
81-
~Arg();
83+
LLVM_ABI ~Arg();
8284

8385
const Option &getOption() const { return Opt; }
8486

@@ -134,23 +136,23 @@ class Arg {
134136
}
135137

136138
/// Append the argument onto the given array as strings.
137-
void render(const ArgList &Args, ArgStringList &Output) const;
139+
LLVM_ABI void render(const ArgList &Args, ArgStringList &Output) const;
138140

139141
/// Append the argument, render as an input, onto the given
140142
/// array as strings.
141143
///
142144
/// The distinction is that some options only render their values
143145
/// when rendered as a input (e.g., Xlinker).
144-
void renderAsInput(const ArgList &Args, ArgStringList &Output) const;
146+
LLVM_ABI void renderAsInput(const ArgList &Args, ArgStringList &Output) const;
145147

146-
void print(raw_ostream &O) const;
147-
void dump() const;
148+
LLVM_ABI void print(raw_ostream &O) const;
149+
LLVM_ABI void dump() const;
148150

149151
/// Return a formatted version of the argument and its values, for
150152
/// diagnostics. Since this is for diagnostics, if this Arg was produced
151153
/// through an alias, this returns the string representation of the alias
152154
/// that the user wrote.
153-
std::string getAsString(const ArgList &Args) const;
155+
LLVM_ABI std::string getAsString(const ArgList &Args) const;
154156
};
155157

156158
} // end namespace opt

llvm/include/llvm/Option/ArgList.h

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@
1111

1212
#include "llvm/ADT/ArrayRef.h"
1313
#include "llvm/ADT/DenseMap.h"
14-
#include "llvm/ADT/iterator_range.h"
1514
#include "llvm/ADT/SmallString.h"
1615
#include "llvm/ADT/SmallVector.h"
1716
#include "llvm/ADT/StringRef.h"
1817
#include "llvm/ADT/Twine.h"
18+
#include "llvm/ADT/iterator_range.h"
1919
#include "llvm/Option/Arg.h"
2020
#include "llvm/Option/OptSpecifier.h"
2121
#include "llvm/Option/Option.h"
22+
#include "llvm/Support/Compiler.h"
2223
#include <algorithm>
2324
#include <cstddef>
2425
#include <initializer_list>
@@ -139,7 +140,7 @@ class ArgList {
139140

140141
/// Get the range of indexes in which options with the specified IDs might
141142
/// reside, or (0, 0) if there are no such options.
142-
OptRange getRange(std::initializer_list<OptSpecifier> Ids) const;
143+
LLVM_ABI OptRange getRange(std::initializer_list<OptSpecifier> Ids) const;
143144

144145
protected:
145146
// Make the default special members protected so they won't be used to slice
@@ -178,7 +179,7 @@ class ArgList {
178179
/// @{
179180

180181
/// append - Append \p A to the arg list.
181-
void append(Arg *A);
182+
LLVM_ABI void append(Arg *A);
182183

183184
const arglist_type &getArgs() const { return Args; }
184185

@@ -227,7 +228,7 @@ class ArgList {
227228
/// @{
228229

229230
/// eraseArg - Remove any option matching \p Id.
230-
void eraseArg(OptSpecifier Id);
231+
LLVM_ABI void eraseArg(OptSpecifier Id);
231232

232233
/// @}
233234
/// @name Arg Access
@@ -284,11 +285,12 @@ class ArgList {
284285
/// @{
285286

286287
/// getLastArgValue - Return the value of the last argument, or a default.
287-
StringRef getLastArgValue(OptSpecifier Id, StringRef Default = "") const;
288+
LLVM_ABI StringRef getLastArgValue(OptSpecifier Id,
289+
StringRef Default = "") const;
288290

289291
/// getAllArgValues - Get the values of all instances of the given argument
290292
/// as strings.
291-
std::vector<std::string> getAllArgValues(OptSpecifier Id) const;
293+
LLVM_ABI std::vector<std::string> getAllArgValues(OptSpecifier Id) const;
292294

293295
/// @}
294296
/// @name Translation Utilities
@@ -298,20 +300,21 @@ class ArgList {
298300
/// true if the option is present, false if the negation is present, and
299301
/// \p Default if neither option is given. If both the option and its
300302
/// negation are present, the last one wins.
301-
bool hasFlag(OptSpecifier Pos, OptSpecifier Neg, bool Default) const;
302-
bool hasFlagNoClaim(OptSpecifier Pos, OptSpecifier Neg, bool Default) const;
303+
LLVM_ABI bool hasFlag(OptSpecifier Pos, OptSpecifier Neg, bool Default) const;
304+
LLVM_ABI bool hasFlagNoClaim(OptSpecifier Pos, OptSpecifier Neg,
305+
bool Default) const;
303306

304307
/// hasFlag - Given an option \p Pos, an alias \p PosAlias and its negative
305308
/// form \p Neg, return true if the option or its alias is present, false if
306309
/// the negation is present, and \p Default if none of the options are
307310
/// given. If multiple options are present, the last one wins.
308-
bool hasFlag(OptSpecifier Pos, OptSpecifier PosAlias, OptSpecifier Neg,
309-
bool Default) const;
311+
LLVM_ABI bool hasFlag(OptSpecifier Pos, OptSpecifier PosAlias,
312+
OptSpecifier Neg, bool Default) const;
310313

311314
/// Given an option Pos and its negative form Neg, render the option if Pos is
312315
/// present.
313-
void addOptInFlag(ArgStringList &Output, OptSpecifier Pos,
314-
OptSpecifier Neg) const;
316+
LLVM_ABI void addOptInFlag(ArgStringList &Output, OptSpecifier Pos,
317+
OptSpecifier Neg) const;
315318
/// Render the option if Neg is present.
316319
void addOptOutFlag(ArgStringList &Output, OptSpecifier Pos,
317320
OptSpecifier Neg) const {
@@ -331,32 +334,35 @@ class ArgList {
331334

332335
/// AddAllArgsExcept - Render all arguments matching any of the given ids
333336
/// and not matching any of the excluded ids.
334-
void AddAllArgsExcept(ArgStringList &Output, ArrayRef<OptSpecifier> Ids,
335-
ArrayRef<OptSpecifier> ExcludeIds) const;
337+
LLVM_ABI void AddAllArgsExcept(ArgStringList &Output,
338+
ArrayRef<OptSpecifier> Ids,
339+
ArrayRef<OptSpecifier> ExcludeIds) const;
336340
/// Render all arguments matching any of the given ids.
337-
void addAllArgs(ArgStringList &Output, ArrayRef<OptSpecifier> Ids) const;
341+
LLVM_ABI void addAllArgs(ArgStringList &Output,
342+
ArrayRef<OptSpecifier> Ids) const;
338343

339344
/// AddAllArgs - Render all arguments matching the given ids.
340-
void AddAllArgs(ArgStringList &Output, OptSpecifier Id0) const;
345+
LLVM_ABI void AddAllArgs(ArgStringList &Output, OptSpecifier Id0) const;
341346

342347
/// AddAllArgValues - Render the argument values of all arguments
343348
/// matching the given ids.
344-
void AddAllArgValues(ArgStringList &Output, OptSpecifier Id0,
345-
OptSpecifier Id1 = 0U, OptSpecifier Id2 = 0U) const;
349+
LLVM_ABI void AddAllArgValues(ArgStringList &Output, OptSpecifier Id0,
350+
OptSpecifier Id1 = 0U,
351+
OptSpecifier Id2 = 0U) const;
346352

347353
/// AddAllArgsTranslated - Render all the arguments matching the
348354
/// given ids, but forced to separate args and using the provided
349355
/// name instead of the first option value.
350356
///
351357
/// \param Joined - If true, render the argument as joined with
352358
/// the option specifier.
353-
void AddAllArgsTranslated(ArgStringList &Output, OptSpecifier Id0,
354-
const char *Translation,
355-
bool Joined = false) const;
359+
LLVM_ABI void AddAllArgsTranslated(ArgStringList &Output, OptSpecifier Id0,
360+
const char *Translation,
361+
bool Joined = false) const;
356362

357363
/// ClaimAllArgs - Claim all arguments which match the given
358364
/// option id.
359-
void ClaimAllArgs(OptSpecifier Id0) const;
365+
LLVM_ABI void ClaimAllArgs(OptSpecifier Id0) const;
360366

361367
template <typename... OptSpecifiers>
362368
void claimAllArgs(OptSpecifiers... Ids) const {
@@ -366,7 +372,7 @@ class ArgList {
366372

367373
/// ClaimAllArgs - Claim all arguments.
368374
///
369-
void ClaimAllArgs() const;
375+
LLVM_ABI void ClaimAllArgs() const;
370376
/// @}
371377
/// @name Arg Synthesis
372378
/// @{
@@ -381,16 +387,16 @@ class ArgList {
381387

382388
/// Create an arg string for (\p LHS + \p RHS), reusing the
383389
/// string at \p Index if possible.
384-
const char *GetOrMakeJoinedArgString(unsigned Index, StringRef LHS,
385-
StringRef RHS) const;
390+
LLVM_ABI const char *GetOrMakeJoinedArgString(unsigned Index, StringRef LHS,
391+
StringRef RHS) const;
386392

387-
void print(raw_ostream &O) const;
388-
void dump() const;
393+
LLVM_ABI void print(raw_ostream &O) const;
394+
LLVM_ABI void dump() const;
389395

390396
/// @}
391397
};
392398

393-
class InputArgList final : public ArgList {
399+
class LLVM_ABI InputArgList final : public ArgList {
394400
private:
395401
/// List of argument strings used by the contained Args.
396402
///
@@ -463,7 +469,7 @@ class InputArgList final : public ArgList {
463469

464470
/// DerivedArgList - An ordered collection of driver arguments,
465471
/// whose storage may be in another argument list.
466-
class DerivedArgList final : public ArgList {
472+
class LLVM_ABI DerivedArgList final : public ArgList {
467473
const InputArgList &BaseArgs;
468474

469475
/// The list of arguments we synthesized.

llvm/include/llvm/Option/OptSpecifier.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class OptSpecifier {
2222
OptSpecifier() = default;
2323
explicit OptSpecifier(bool) = delete;
2424
/*implicit*/ OptSpecifier(unsigned ID) : ID(ID) {}
25-
/*implicit*/ OptSpecifier(const Option *Opt);
25+
/*implicit*/ LLVM_ABI OptSpecifier(const Option *Opt);
2626

2727
bool isValid() const { return ID != 0; }
2828

llvm/include/llvm/Option/OptTable.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "llvm/ADT/StringRef.h"
1515
#include "llvm/ADT/StringTable.h"
1616
#include "llvm/Option/OptSpecifier.h"
17+
#include "llvm/Support/Compiler.h"
1718
#include "llvm/Support/StringSaver.h"
1819
#include <cassert>
1920
#include <string>
@@ -50,7 +51,7 @@ class Visibility {
5051
/// be needed at runtime; the OptTable class maintains enough information to
5152
/// parse command lines without instantiating Options, while letting other
5253
/// parts of the driver still use Option instances where convenient.
53-
class OptTable {
54+
class LLVM_ABI OptTable {
5455
public:
5556
/// Entry for a single option instance in the option data table.
5657
struct Info {
@@ -425,9 +426,9 @@ class OptTable {
425426
/// Specialization of OptTable
426427
class GenericOptTable : public OptTable {
427428
protected:
428-
GenericOptTable(const StringTable &StrTable,
429-
ArrayRef<StringTable::Offset> PrefixesTable,
430-
ArrayRef<Info> OptionInfos, bool IgnoreCase = false);
429+
LLVM_ABI GenericOptTable(const StringTable &StrTable,
430+
ArrayRef<StringTable::Offset> PrefixesTable,
431+
ArrayRef<Info> OptionInfos, bool IgnoreCase = false);
431432
};
432433

433434
class PrecomputedOptTable : public OptTable {

llvm/include/llvm/Option/Option.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "llvm/ADT/StringRef.h"
1414
#include "llvm/Option/OptSpecifier.h"
1515
#include "llvm/Option/OptTable.h"
16+
#include "llvm/Support/Compiler.h"
1617
#include "llvm/Support/ErrorHandling.h"
1718
#include <cassert>
1819

@@ -81,7 +82,7 @@ class Option {
8182
const OptTable *Owner;
8283

8384
public:
84-
Option(const OptTable::Info *Info, const OptTable *Owner);
85+
LLVM_ABI Option(const OptTable::Info *Info, const OptTable *Owner);
8586

8687
bool isValid() const {
8788
return Info != nullptr;
@@ -213,7 +214,7 @@ class Option {
213214
/// Note that matches against options which are an alias should never be
214215
/// done -- aliases do not participate in matching and so such a query will
215216
/// always be false.
216-
bool matches(OptSpecifier ID) const;
217+
LLVM_ABI bool matches(OptSpecifier ID) const;
217218

218219
/// Potentially accept the current argument, returning a new Arg instance,
219220
/// or 0 if the option does not accept this argument (or the argument is
@@ -227,16 +228,17 @@ class Option {
227228
/// underlying storage to represent a Joined argument.
228229
/// \p GroupedShortOption If true, we are handling the fallback case of
229230
/// parsing a prefix of the current argument as a short option.
230-
std::unique_ptr<Arg> accept(const ArgList &Args, StringRef CurArg,
231-
bool GroupedShortOption, unsigned &Index) const;
231+
LLVM_ABI std::unique_ptr<Arg> accept(const ArgList &Args, StringRef CurArg,
232+
bool GroupedShortOption,
233+
unsigned &Index) const;
232234

233235
private:
234236
std::unique_ptr<Arg> acceptInternal(const ArgList &Args, StringRef CurArg,
235237
unsigned &Index) const;
236238

237239
public:
238-
void print(raw_ostream &O, bool AddNewLine = true) const;
239-
void dump() const;
240+
LLVM_ABI void print(raw_ostream &O, bool AddNewLine = true) const;
241+
LLVM_ABI void dump() const;
240242
};
241243

242244
} // end namespace opt

llvm/include/llvm/Remarks/Remark.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include "llvm/ADT/SmallVector.h"
1818
#include "llvm/ADT/StringRef.h"
1919
#include "llvm/Support/CBindingWrapping.h"
20+
#include "llvm/Support/Compiler.h"
2021
#include "llvm/Support/raw_ostream.h"
2122
#include <optional>
2223
#include <string>
@@ -35,7 +36,7 @@ struct RemarkLocation {
3536
unsigned SourceColumn = 0;
3637

3738
/// Implement operator<< on RemarkLocation.
38-
void print(raw_ostream &OS) const;
39+
LLVM_ABI void print(raw_ostream &OS) const;
3940
};
4041

4142
// Create wrappers for C Binding types (see CBindingWrapping.h).
@@ -51,11 +52,11 @@ struct Argument {
5152
std::optional<RemarkLocation> Loc;
5253

5354
/// Implement operator<< on Argument.
54-
void print(raw_ostream &OS) const;
55+
LLVM_ABI void print(raw_ostream &OS) const;
5556
/// Return the value of argument as int.
56-
std::optional<int> getValAsInt() const;
57+
LLVM_ABI std::optional<int> getValAsInt() const;
5758
/// Check if the argument value can be parsed as int.
58-
bool isValInt() const;
59+
LLVM_ABI bool isValInt() const;
5960
};
6061

6162
// Create wrappers for C Binding types (see CBindingWrapping.h).
@@ -124,13 +125,13 @@ struct Remark {
124125
Remark &operator=(Remark &&) = default;
125126

126127
/// Return a message composed from the arguments as a string.
127-
std::string getArgsAsMsg() const;
128+
LLVM_ABI std::string getArgsAsMsg() const;
128129

129130
/// Clone this remark to explicitly ask for a copy.
130131
Remark clone() const { return *this; }
131132

132133
/// Implement operator<< on Remark.
133-
void print(raw_ostream &OS) const;
134+
LLVM_ABI void print(raw_ostream &OS) const;
134135

135136
private:
136137
/// In order to avoid unwanted copies, "delete" the copy constructor.

llvm/include/llvm/Remarks/RemarkFormat.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#define LLVM_REMARKS_REMARKFORMAT_H
1515

1616
#include "llvm/ADT/StringRef.h"
17+
#include "llvm/Support/Compiler.h"
1718
#include "llvm/Support/Error.h"
1819

1920
namespace llvm {
@@ -25,10 +26,10 @@ constexpr StringLiteral Magic("REMARKS");
2526
enum class Format { Unknown, YAML, YAMLStrTab, Bitstream };
2627

2728
/// Parse and validate a string for the remark format.
28-
Expected<Format> parseFormat(StringRef FormatStr);
29+
LLVM_ABI Expected<Format> parseFormat(StringRef FormatStr);
2930

3031
/// Parse and validate a magic number to a remark format.
31-
Expected<Format> magicToFormat(StringRef Magic);
32+
LLVM_ABI Expected<Format> magicToFormat(StringRef Magic);
3233

3334
} // end namespace remarks
3435
} // end namespace llvm

0 commit comments

Comments
 (0)