Skip to content

Commit

Permalink
[GlobPattern] Update invalid glob pattern diagnostic for unmatched '['
Browse files Browse the repository at this point in the history
Update this diagnostic to mention the reason (unmatched '['), matching
the other diagnostic about stray '\'. The original pattern is omitted,
as some users may mention the original pattern in another position, not
repeating it.
  • Loading branch information
MaskRay committed Aug 9, 2023
1 parent 132bb5c commit ebb0a21
Show file tree
Hide file tree
Showing 12 changed files with 17 additions and 17 deletions.
2 changes: 1 addition & 1 deletion clang-tools-extra/test/pp-trace/pp-trace-filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ int i = M;
// CHECK-NOT: - Callback: EndOfMainFile
// CHECK: ...

// INVALID: error: invalid glob pattern: [
// INVALID: error: invalid glob pattern, unmatched '['
2 changes: 1 addition & 1 deletion lld/Common/Strings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ SingleStringMatcher::SingleStringMatcher(StringRef Pattern) {
} else {
Expected<GlobPattern> Glob = GlobPattern::create(Pattern);
if (!Glob) {
error(toString(Glob.takeError()));
error(toString(Glob.takeError()) + ": " + Pattern);
return;
}
ExactMatch = false;
Expand Down
11 changes: 6 additions & 5 deletions lld/ELF/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1114,7 +1114,7 @@ static bool remapInputs(StringRef line, const Twine &location) {
else if (Expected<GlobPattern> pat = GlobPattern::create(fields[0]))
config->remapInputsWildcards.emplace_back(std::move(*pat), fields[1]);
else {
error(location + ": " + toString(pat.takeError()));
error(location + ": " + toString(pat.takeError()) + ": " + fields[0]);
return true;
}
return false;
Expand Down Expand Up @@ -1415,7 +1415,7 @@ static void readConfigs(opt::InputArgList &args) {
else if (Expected<GlobPattern> pat = GlobPattern::create(kv.first))
config->shuffleSections.emplace_back(std::move(*pat), uint32_t(v));
else
error(errPrefix + toString(pat.takeError()));
error(errPrefix + toString(pat.takeError()) + ": " + kv.first);
}

auto reports = {std::make_pair("bti-report", &config->zBtiReport),
Expand Down Expand Up @@ -1453,7 +1453,7 @@ static void readConfigs(opt::InputArgList &args) {
else if (Expected<GlobPattern> pat = GlobPattern::create(kv.first))
config->deadRelocInNonAlloc.emplace_back(std::move(*pat), v);
else
error(errPrefix + toString(pat.takeError()));
error(errPrefix + toString(pat.takeError()) + ": " + kv.first);
}

cl::ResetAllOptionOccurrences();
Expand Down Expand Up @@ -1610,7 +1610,8 @@ static void readConfigs(opt::InputArgList &args) {
if (Expected<GlobPattern> pat = GlobPattern::create(pattern))
config->warnBackrefsExclude.push_back(std::move(*pat));
else
error(arg->getSpelling() + ": " + toString(pat.takeError()));
error(arg->getSpelling() + ": " + toString(pat.takeError()) + ": " +
pattern);
}

// For -no-pie and -pie, --export-dynamic-symbol specifies defined symbols
Expand Down Expand Up @@ -1968,7 +1969,7 @@ static void handleUndefined(Symbol *sym, const char *option) {
static void handleUndefinedGlob(StringRef arg) {
Expected<GlobPattern> pat = GlobPattern::create(arg);
if (!pat) {
error("--undefined-glob: " + toString(pat.takeError()));
error("--undefined-glob: " + toString(pat.takeError()) + ": " + arg);
return;
}

Expand Down
2 changes: 1 addition & 1 deletion lld/test/ELF/dead-reloc-in-nonalloc.s
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@

# RUN: not ld.lld -z dead-reloc-in-nonalloc='['=0 2>&1 | FileCheck %s --check-prefix=INVALID

# INVALID: error: -z dead-reloc-in-nonalloc=: invalid glob pattern: [
# INVALID: error: -z dead-reloc-in-nonalloc=: invalid glob pattern, unmatched '[': [

.globl _start
_start:
Expand Down
2 changes: 1 addition & 1 deletion lld/test/ELF/remap-inputs.test
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

# RUN: not ld.lld --remap-inputs-file=err2.map aa.o -o /dev/null 2>&1 | \
# RUN: FileCheck %s --check-prefix=ERR2 --implicit-check-not=error:
# ERR2: error: err2.map:1: invalid glob pattern: aa.[o
# ERR2: error: err2.map:1: invalid glob pattern, unmatched '[': aa.[o
# ERR2-NEXT: error: cannot open aa.o: {{.*}}

# RUN: not ld.lld --remap-inputs=aa.o aa.o -o /dev/null 2>&1 | \
Expand Down
2 changes: 1 addition & 1 deletion lld/test/ELF/shuffle-sections.s
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@

# RUN: not ld.lld --shuffle-sections='['=0 2>&1 | FileCheck %s --check-prefix=INVALID

# INVALID: error: --shuffle-sections=: invalid glob pattern: [
# INVALID: error: --shuffle-sections=: invalid glob pattern, unmatched '[': [

## .text has an alignment of 4.
.global _start
Expand Down
2 changes: 1 addition & 1 deletion lld/test/ELF/undefined-glob.s
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
# RUN: not ld.lld -o /dev/null %t.o %t.a --undefined-glob '[' 2>&1 | \
# RUN: FileCheck -check-prefix=BAD-PATTERN %s

# BAD-PATTERN: --undefined-glob: invalid glob pattern: [
# BAD-PATTERN: --undefined-glob: invalid glob pattern, unmatched '[': [

.globl _start
_start:
2 changes: 1 addition & 1 deletion lld/test/ELF/version-script-complex-wildcards.s
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
# RUN: echo "FOO { global: extern \"C++\" { a[; }; };" > %t9.script
# RUN: not ld.lld --version-script %t9.script -shared %t.o -o /dev/null 2>&1 \
# RUN: | FileCheck %s --check-prefix=ERROR
# ERROR: invalid glob pattern: a[
# ERROR: invalid glob pattern, unmatched '[': a[

.text
.globl _Z3abbi
Expand Down
2 changes: 1 addition & 1 deletion lld/test/ELF/warn-backrefs.s
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
# RUN: ld.lld --fatal-warnings --warn-backrefs -u foo %t2.a %t1.o -o /dev/null

# RUN: not ld.lld --warn-backrefs-exclude='[' 2>&1 | FileCheck --check-prefix=INVALID %s
# INVALID: error: --warn-backrefs-exclude: invalid glob pattern: [
# INVALID: error: --warn-backrefs-exclude: invalid glob pattern, unmatched '[': [

.globl _start, foo
_start:
Expand Down
3 changes: 1 addition & 2 deletions llvm/lib/Support/GlobPattern.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ Expected<GlobPattern> GlobPattern::create(StringRef S) {
Pat.Prefix = S.substr(0, PrefixSize);
if (PrefixSize == std::string::npos)
return Pat;
StringRef Original = S;
S = S.substr(PrefixSize);

// Parse brackets.
Expand All @@ -74,7 +73,7 @@ Expected<GlobPattern> GlobPattern::create(StringRef S) {
++I;
size_t J = S.find(']', I + 1);
if (J == StringRef::npos)
return make_error<StringError>("invalid glob pattern: " + Original,
return make_error<StringError>("invalid glob pattern, unmatched '['",
errc::invalid_argument);
StringRef Chars = S.substr(I, J - I);
bool Invert = S[I] == '^' || S[I] == '!';
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/tools/llvm-ifs/exclude.test
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# RUN: not llvm-ifs --input-format=IFS --output-ifs=- --exclude='[' %s 2>&1 | \
# RUN: FileCheck %s --check-prefix=BAD-GLOB

# BAD-GLOB: error: invalid glob pattern: [
# BAD-GLOB: error: invalid glob pattern, unmatched '['

--- !ifs-v1
SoName: somelib.so
Expand Down
2 changes: 1 addition & 1 deletion llvm/test/tools/llvm-objcopy/ELF/wildcard-syntax.test
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ Sections:
Type: SHT_PROGBITS
Symbols: []

# WARN: warning: invalid glob pattern: ][]
# WARN: warning: invalid glob pattern, unmatched '['

# CHECK: LoadName:
# CHECK: Name: (0)
Expand Down

0 comments on commit ebb0a21

Please sign in to comment.