Skip to content

Commit dc263e1

Browse files
committed
Add regex error handling.
1 parent 27be6e1 commit dc263e1

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

llvm/test/tools/llvm-remarkutil/instruction-mix.test

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ RUN: llvm-remarkutil instruction-mix --parser=yaml %p/Inputs/instruction-mix.yam
22
RUN: llvm-remarkutil yaml2bitstream %p/Inputs/instruction-mix.yaml | llvm-remarkutil instruction-mix --parser=bitstream | FileCheck %s
33
RUN: llvm-remarkutil instruction-mix --parser=yaml %p/Inputs/instruction-mix.yaml --report_style=human | FileCheck %s
44
RUN: llvm-remarkutil instruction-mix --parser=yaml %p/Inputs/instruction-mix.yaml --report_style=csv | FileCheck %s --check-prefix=CSV
5-
RUN: llvm-remarkutil instruction-mix --parser=yaml %p/Inputs/instruction-mix.yaml --filter=meow | FileCheck %s --check-prefix=MEOW
5+
RUN: llvm-remarkutil instruction-mix --parser=yaml %p/Inputs/instruction-mix.yaml --rfilter=meow | FileCheck %s --check-prefix=MEOW
6+
RUN: not llvm-remarkutil instruction-mix --parser=yaml %p/Inputs/instruction-mix.yaml --rfilter=* 2>&1 | FileCheck %s --check-prefix=ERROR
67

78
; CHECK-LABEL: Instruction Count
89
; CHECK-NEXT: ----------- -----
@@ -19,4 +20,6 @@ RUN: llvm-remarkutil instruction-mix --parser=yaml %p/Inputs/instruction-mix.yam
1920
; MEOW-NEXT: ----------- -----
2021
; MEOW-NEXT: mul 15
2122
; MEOW-NEXT: add 12
22-
; MEOW-NEXT: nop 9
23+
; MEOW-NEXT: nop 9
24+
25+
; ERROR: error: invalid argument '--rfilter=*': repetition-operator operand invalid

llvm/tools/llvm-remarkutil/RemarkInstructionMix.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ static cl::SubCommand
1919
"Instruction Mix (requires asm-printer remarks)");
2020

2121
static cl::opt<std::string>
22-
FunctionFilter("filter", cl::sub(InstructionMix), cl::init(".*"),
23-
cl::value_desc("filter_regex"),
24-
cl::desc("regex to filter functions with"));
22+
FunctionFilterRE("rfilter", cl::sub(InstructionMix), cl::init(".*"),
23+
cl::ValueOptional,
24+
cl::desc("Optional function name to filter collection by "
25+
"(accepts regular expressions)"));
2526

2627
enum ReportStyleOptions { human_output, csv_output };
2728
static cl::opt<ReportStyleOptions> ReportStyle(
@@ -48,7 +49,11 @@ static Error tryInstructionMix() {
4849
if (!MaybeParser)
4950
return MaybeParser.takeError();
5051

51-
Regex Filter(FunctionFilter);
52+
Regex Filter(FunctionFilterRE);
53+
std::string Error;
54+
if (!Filter.isValid(Error))
55+
return createStringError(make_error_code(std::errc::invalid_argument),
56+
Twine("invalid argument '--rfilter=") + FunctionFilterRE + "': " + Error);
5257

5358
// Collect the histogram of instruction counts.
5459
std::unordered_map<std::string, unsigned> Histogram;

0 commit comments

Comments
 (0)