Skip to content

Commit b5f3984

Browse files
committedApr 24, 2019
[CommandLine] Provide parser<unsigned long> instantiation to allow cl::opt<uint64_t> on LP64 platforms
Summary: And migrate opt<unsigned long long> to opt<uint64_t> Fixes PR19665 Differential Revision: https://reviews.llvm.org/D60933 llvm-svn: 359068
1 parent add16a8 commit b5f3984

File tree

13 files changed

+100
-73
lines changed

13 files changed

+100
-73
lines changed
 

‎llvm/include/llvm/Support/CommandLine.h

+24-1
Original file line numberDiff line numberDiff line change
@@ -972,6 +972,29 @@ template <> class parser<unsigned> final : public basic_parser<unsigned> {
972972

973973
extern template class basic_parser<unsigned>;
974974

975+
//--------------------------------------------------
976+
// parser<unsigned long>
977+
//
978+
template <>
979+
class parser<unsigned long> final : public basic_parser<unsigned long> {
980+
public:
981+
parser(Option &O) : basic_parser(O) {}
982+
983+
// parse - Return true on error.
984+
bool parse(Option &O, StringRef ArgName, StringRef Arg, unsigned long &Val);
985+
986+
// getValueName - Overload in subclass to provide a better default value.
987+
StringRef getValueName() const override { return "ulong"; }
988+
989+
void printOptionDiff(const Option &O, unsigned long V, OptVal Default,
990+
size_t GlobalWidth) const;
991+
992+
// An out-of-line virtual method to provide a 'home' for this class.
993+
void anchor() override;
994+
};
995+
996+
extern template class basic_parser<unsigned long>;
997+
975998
//--------------------------------------------------
976999
// parser<unsigned long long>
9771000
//
@@ -986,7 +1009,7 @@ class parser<unsigned long long> final
9861009
unsigned long long &Val);
9871010

9881011
// getValueName - Overload in subclass to provide a better default value.
989-
StringRef getValueName() const override { return "uint"; }
1012+
StringRef getValueName() const override { return "ulong"; }
9901013

9911014
void printOptionDiff(const Option &O, unsigned long long V, OptVal Default,
9921015
size_t GlobalWidth) const;

‎llvm/lib/Support/CommandLine.cpp

+14-1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ template class basic_parser<bool>;
5454
template class basic_parser<boolOrDefault>;
5555
template class basic_parser<int>;
5656
template class basic_parser<unsigned>;
57+
template class basic_parser<unsigned long>;
5758
template class basic_parser<unsigned long long>;
5859
template class basic_parser<double>;
5960
template class basic_parser<float>;
@@ -78,6 +79,7 @@ void parser<bool>::anchor() {}
7879
void parser<boolOrDefault>::anchor() {}
7980
void parser<int>::anchor() {}
8081
void parser<unsigned>::anchor() {}
82+
void parser<unsigned long>::anchor() {}
8183
void parser<unsigned long long>::anchor() {}
8284
void parser<double>::anchor() {}
8385
void parser<float>::anchor() {}
@@ -1663,14 +1665,24 @@ bool parser<unsigned>::parse(Option &O, StringRef ArgName, StringRef Arg,
16631665
return false;
16641666
}
16651667

1668+
// parser<unsigned long> implementation
1669+
//
1670+
bool parser<unsigned long>::parse(Option &O, StringRef ArgName, StringRef Arg,
1671+
unsigned long &Value) {
1672+
1673+
if (Arg.getAsInteger(0, Value))
1674+
return O.error("'" + Arg + "' value invalid for ulong argument!");
1675+
return false;
1676+
}
1677+
16661678
// parser<unsigned long long> implementation
16671679
//
16681680
bool parser<unsigned long long>::parse(Option &O, StringRef ArgName,
16691681
StringRef Arg,
16701682
unsigned long long &Value) {
16711683

16721684
if (Arg.getAsInteger(0, Value))
1673-
return O.error("'" + Arg + "' value invalid for uint argument!");
1685+
return O.error("'" + Arg + "' value invalid for ullong argument!");
16741686
return false;
16751687
}
16761688

@@ -1851,6 +1863,7 @@ PRINT_OPT_DIFF(bool)
18511863
PRINT_OPT_DIFF(boolOrDefault)
18521864
PRINT_OPT_DIFF(int)
18531865
PRINT_OPT_DIFF(unsigned)
1866+
PRINT_OPT_DIFF(unsigned long)
18541867
PRINT_OPT_DIFF(unsigned long long)
18551868
PRINT_OPT_DIFF(double)
18561869
PRINT_OPT_DIFF(float)

‎llvm/lib/Support/RandomNumberGenerator.cpp

+3-7
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,9 @@ using namespace llvm;
2626

2727
#define DEBUG_TYPE "rng"
2828

29-
// Tracking BUG: 19665
30-
// http://llvm.org/bugs/show_bug.cgi?id=19665
31-
//
32-
// Do not change to cl::opt<uint64_t> since this silently breaks argument parsing.
33-
static cl::opt<unsigned long long>
34-
Seed("rng-seed", cl::value_desc("seed"), cl::Hidden,
35-
cl::desc("Seed for the random number generator"), cl::init(0));
29+
static cl::opt<uint64_t> Seed("rng-seed", cl::value_desc("seed"), cl::Hidden,
30+
cl::desc("Seed for the random number generator"),
31+
cl::init(0));
3632

3733
RandomNumberGenerator::RandomNumberGenerator(StringRef Salt) {
3834
LLVM_DEBUG(if (Seed == 0) dbgs()

‎llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -321,10 +321,10 @@ static cl::opt<int> ClMappingScale("asan-mapping-scale",
321321
cl::desc("scale of asan shadow mapping"),
322322
cl::Hidden, cl::init(0));
323323

324-
static cl::opt<unsigned long long> ClMappingOffset(
325-
"asan-mapping-offset",
326-
cl::desc("offset of asan shadow mapping [EXPERIMENTAL]"), cl::Hidden,
327-
cl::init(0));
324+
static cl::opt<uint64_t>
325+
ClMappingOffset("asan-mapping-offset",
326+
cl::desc("offset of asan shadow mapping [EXPERIMENTAL]"),
327+
cl::Hidden, cl::init(0));
328328

329329
// Optimization flags. Not user visible, used mostly for testing
330330
// and benchmarking the tool.

‎llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,10 @@ static cl::opt<bool> ClEnableKhwasan(
124124
// is accessed. The shadow mapping looks like:
125125
// Shadow = (Mem >> scale) + offset
126126

127-
static cl::opt<unsigned long long> ClMappingOffset(
128-
"hwasan-mapping-offset",
129-
cl::desc("HWASan shadow mapping offset [EXPERIMENTAL]"), cl::Hidden,
130-
cl::init(0));
127+
static cl::opt<uint64_t>
128+
ClMappingOffset("hwasan-mapping-offset",
129+
cl::desc("HWASan shadow mapping offset [EXPERIMENTAL]"),
130+
cl::Hidden, cl::init(0));
131131

132132
static cl::opt<bool>
133133
ClWithIfunc("hwasan-with-ifunc",

‎llvm/lib/Transforms/Instrumentation/MemorySanitizer.cpp

+12-12
Original file line numberDiff line numberDiff line change
@@ -304,21 +304,21 @@ static cl::opt<bool> ClWithComdat("msan-with-comdat",
304304

305305
// These options allow to specify custom memory map parameters
306306
// See MemoryMapParams for details.
307-
static cl::opt<unsigned long long> ClAndMask("msan-and-mask",
308-
cl::desc("Define custom MSan AndMask"),
309-
cl::Hidden, cl::init(0));
307+
static cl::opt<uint64_t> ClAndMask("msan-and-mask",
308+
cl::desc("Define custom MSan AndMask"),
309+
cl::Hidden, cl::init(0));
310310

311-
static cl::opt<unsigned long long> ClXorMask("msan-xor-mask",
312-
cl::desc("Define custom MSan XorMask"),
313-
cl::Hidden, cl::init(0));
311+
static cl::opt<uint64_t> ClXorMask("msan-xor-mask",
312+
cl::desc("Define custom MSan XorMask"),
313+
cl::Hidden, cl::init(0));
314314

315-
static cl::opt<unsigned long long> ClShadowBase("msan-shadow-base",
316-
cl::desc("Define custom MSan ShadowBase"),
317-
cl::Hidden, cl::init(0));
315+
static cl::opt<uint64_t> ClShadowBase("msan-shadow-base",
316+
cl::desc("Define custom MSan ShadowBase"),
317+
cl::Hidden, cl::init(0));
318318

319-
static cl::opt<unsigned long long> ClOriginBase("msan-origin-base",
320-
cl::desc("Define custom MSan OriginBase"),
321-
cl::Hidden, cl::init(0));
319+
static cl::opt<uint64_t> ClOriginBase("msan-origin-base",
320+
cl::desc("Define custom MSan OriginBase"),
321+
cl::Hidden, cl::init(0));
322322

323323
static const char *const kMsanModuleCtorName = "msan.module_ctor";
324324
static const char *const kMsanInitName = "__msan_init";

‎llvm/tools/llvm-cfi-verify/lib/GraphBuilder.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,17 @@ using Instr = llvm::cfi_verify::FileAnalysis::Instr;
3838
namespace llvm {
3939
namespace cfi_verify {
4040

41-
unsigned long long SearchLengthForUndef;
42-
unsigned long long SearchLengthForConditionalBranch;
41+
uint64_t SearchLengthForUndef;
42+
uint64_t SearchLengthForConditionalBranch;
4343

44-
static cl::opt<unsigned long long, true> SearchLengthForUndefArg(
44+
static cl::opt<uint64_t, true> SearchLengthForUndefArg(
4545
"search-length-undef",
4646
cl::desc("Specify the maximum amount of instructions "
4747
"to inspect when searching for an undefined "
4848
"instruction from a conditional branch."),
4949
cl::location(SearchLengthForUndef), cl::init(2));
5050

51-
static cl::opt<unsigned long long, true> SearchLengthForConditionalBranchArg(
51+
static cl::opt<uint64_t, true> SearchLengthForConditionalBranchArg(
5252
"search-length-cb",
5353
cl::desc("Specify the maximum amount of instructions "
5454
"to inspect when searching for a conditional "

‎llvm/tools/llvm-cfi-verify/lib/GraphBuilder.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ using Instr = llvm::cfi_verify::FileAnalysis::Instr;
4646
namespace llvm {
4747
namespace cfi_verify {
4848

49-
extern unsigned long long SearchLengthForUndef;
50-
extern unsigned long long SearchLengthForConditionalBranch;
49+
extern uint64_t SearchLengthForUndef;
50+
extern uint64_t SearchLengthForConditionalBranch;
5151

5252
struct ConditionalBranchNode {
5353
uint64_t Address;

‎llvm/tools/llvm-dwarfdump/llvm-dwarfdump.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,8 @@ static list<std::string> Name(
154154
"the -regex option <pattern> is interpreted as a regular expression."),
155155
value_desc("pattern"), cat(DwarfDumpCategory));
156156
static alias NameAlias("n", desc("Alias for -name"), aliasopt(Name));
157-
static opt<unsigned long long> Lookup("lookup",
157+
static opt<uint64_t>
158+
Lookup("lookup",
158159
desc("Lookup <address> in the debug information and print out any "
159160
"available file, function, block and line table details."),
160161
value_desc("address"), cat(DwarfDumpCategory));

‎llvm/tools/llvm-lto/llvm-lto.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,8 @@ static cl::opt<int>
157157
ThinLTOCachePruningInterval("thinlto-cache-pruning-interval",
158158
cl::init(1200), cl::desc("Set ThinLTO cache pruning interval."));
159159

160-
static cl::opt<unsigned long long>
161-
ThinLTOCacheMaxSizeBytes("thinlto-cache-max-size-bytes",
160+
static cl::opt<uint64_t> ThinLTOCacheMaxSizeBytes(
161+
"thinlto-cache-max-size-bytes",
162162
cl::desc("Set ThinLTO cache pruning directory maximum size in bytes."));
163163

164164
static cl::opt<int>

‎llvm/tools/llvm-objdump/llvm-objdump.cpp

+6-5
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ extern cl::opt<bool> Rebase;
8787
extern cl::opt<bool> UniversalHeaders;
8888
extern cl::opt<bool> WeakBind;
8989

90-
static cl::opt<unsigned long long> AdjustVMA(
90+
static cl::opt<uint64_t> AdjustVMA(
9191
"adjust-vma",
9292
cl::desc("Increase the displayed address by the specified offset"),
9393
cl::value_desc("offset"), cl::init(0));
@@ -271,12 +271,13 @@ static cl::alias PrintSourceShort("S", cl::desc("Alias for -source"),
271271
cl::NotHidden, cl::Grouping,
272272
cl::aliasopt(PrintSource));
273273

274-
static cl::opt<unsigned long long>
274+
static cl::opt<uint64_t>
275275
StartAddress("start-address", cl::desc("Disassemble beginning at address"),
276276
cl::value_desc("address"), cl::init(0));
277-
static cl::opt<unsigned long long>
278-
StopAddress("stop-address", cl::desc("Stop disassembly at address"),
279-
cl::value_desc("address"), cl::init(UINT64_MAX));
277+
static cl::opt<uint64_t> StopAddress("stop-address",
278+
cl::desc("Stop disassembly at address"),
279+
cl::value_desc("address"),
280+
cl::init(UINT64_MAX));
280281

281282
cl::opt<bool> SymbolTable("syms", cl::desc("Display the symbol table"));
282283
static cl::alias SymbolTableShort("t", cl::desc("Alias for --syms"),

‎llvm/tools/llvm-rtdyld/llvm-rtdyld.cpp

+22-29
Original file line numberDiff line numberDiff line change
@@ -91,35 +91,28 @@ CheckFiles("check",
9191
cl::desc("File containing RuntimeDyld verifier checks."),
9292
cl::ZeroOrMore);
9393

94-
// Tracking BUG: 19665
95-
// http://llvm.org/bugs/show_bug.cgi?id=19665
96-
//
97-
// Do not change these options to cl::opt<uint64_t> since this silently breaks
98-
// argument parsing.
99-
static cl::opt<unsigned long long>
100-
PreallocMemory("preallocate",
101-
cl::desc("Allocate memory upfront rather than on-demand"),
102-
cl::init(0));
103-
104-
static cl::opt<unsigned long long>
105-
TargetAddrStart("target-addr-start",
106-
cl::desc("For -verify only: start of phony target address "
107-
"range."),
108-
cl::init(4096), // Start at "page 1" - no allocating at "null".
109-
cl::Hidden);
110-
111-
static cl::opt<unsigned long long>
112-
TargetAddrEnd("target-addr-end",
113-
cl::desc("For -verify only: end of phony target address range."),
114-
cl::init(~0ULL),
115-
cl::Hidden);
116-
117-
static cl::opt<unsigned long long>
118-
TargetSectionSep("target-section-sep",
119-
cl::desc("For -verify only: Separation between sections in "
120-
"phony target address space."),
121-
cl::init(0),
122-
cl::Hidden);
94+
static cl::opt<uint64_t>
95+
PreallocMemory("preallocate",
96+
cl::desc("Allocate memory upfront rather than on-demand"),
97+
cl::init(0));
98+
99+
static cl::opt<uint64_t> TargetAddrStart(
100+
"target-addr-start",
101+
cl::desc("For -verify only: start of phony target address "
102+
"range."),
103+
cl::init(4096), // Start at "page 1" - no allocating at "null".
104+
cl::Hidden);
105+
106+
static cl::opt<uint64_t> TargetAddrEnd(
107+
"target-addr-end",
108+
cl::desc("For -verify only: end of phony target address range."),
109+
cl::init(~0ULL), cl::Hidden);
110+
111+
static cl::opt<uint64_t> TargetSectionSep(
112+
"target-section-sep",
113+
cl::desc("For -verify only: Separation between sections in "
114+
"phony target address space."),
115+
cl::init(0), cl::Hidden);
123116

124117
static cl::list<std::string>
125118
SpecificSectionMappings("map-section",

‎llvm/tools/llvm-symbolizer/llvm-symbolizer.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ static cl::opt<bool> ClVerbose("verbose", cl::init(false),
134134
cl::desc("Print verbose line info"));
135135

136136
// -adjust-vma
137-
static cl::opt<unsigned long long>
137+
static cl::opt<uint64_t>
138138
ClAdjustVMA("adjust-vma", cl::init(0), cl::value_desc("offset"),
139139
cl::desc("Add specified offset to object file addresses"));
140140

0 commit comments

Comments
 (0)
Please sign in to comment.