[clang-tools-extra] ebb0a21 - [GlobPattern] Update invalid glob pattern diagnostic for unmatched '['
Fangrui Song via cfe-commits
cfe-commits at lists.llvm.org
Tue Aug 8 20:25:14 PDT 2023
Author: Fangrui Song
Date: 2023-08-08T20:25:10-07:00
New Revision: ebb0a210995dcf69d9696f8e14629e1378e63a21
URL: https://github.com/llvm/llvm-project/commit/ebb0a210995dcf69d9696f8e14629e1378e63a21
DIFF: https://github.com/llvm/llvm-project/commit/ebb0a210995dcf69d9696f8e14629e1378e63a21.diff
LOG: [GlobPattern] Update invalid glob pattern diagnostic for unmatched '['
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.
Added:
Modified:
clang-tools-extra/test/pp-trace/pp-trace-filter.cpp
lld/Common/Strings.cpp
lld/ELF/Driver.cpp
lld/test/ELF/dead-reloc-in-nonalloc.s
lld/test/ELF/remap-inputs.test
lld/test/ELF/shuffle-sections.s
lld/test/ELF/undefined-glob.s
lld/test/ELF/version-script-complex-wildcards.s
lld/test/ELF/warn-backrefs.s
llvm/lib/Support/GlobPattern.cpp
llvm/test/tools/llvm-ifs/exclude.test
llvm/test/tools/llvm-objcopy/ELF/wildcard-syntax.test
Removed:
################################################################################
diff --git a/clang-tools-extra/test/pp-trace/pp-trace-filter.cpp b/clang-tools-extra/test/pp-trace/pp-trace-filter.cpp
index 1cd2ce7ef14d73..8f090ab0bb79aa 100644
--- a/clang-tools-extra/test/pp-trace/pp-trace-filter.cpp
+++ b/clang-tools-extra/test/pp-trace/pp-trace-filter.cpp
@@ -14,4 +14,4 @@ int i = M;
// CHECK-NOT: - Callback: EndOfMainFile
// CHECK: ...
-// INVALID: error: invalid glob pattern: [
+// INVALID: error: invalid glob pattern, unmatched '['
diff --git a/lld/Common/Strings.cpp b/lld/Common/Strings.cpp
index db22c06eb17e28..41cbbf36f38cb0 100644
--- a/lld/Common/Strings.cpp
+++ b/lld/Common/Strings.cpp
@@ -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;
diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index 8ce2f481f2df6d..1759598b6d9705 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -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;
@@ -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),
@@ -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();
@@ -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
@@ -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;
}
diff --git a/lld/test/ELF/dead-reloc-in-nonalloc.s b/lld/test/ELF/dead-reloc-in-nonalloc.s
index 9e93a0cf32afdd..3857ead6e55d01 100644
--- a/lld/test/ELF/dead-reloc-in-nonalloc.s
+++ b/lld/test/ELF/dead-reloc-in-nonalloc.s
@@ -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:
diff --git a/lld/test/ELF/remap-inputs.test b/lld/test/ELF/remap-inputs.test
index 8a2d2e98910649..0f9cafa987ac9e 100644
--- a/lld/test/ELF/remap-inputs.test
+++ b/lld/test/ELF/remap-inputs.test
@@ -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 | \
diff --git a/lld/test/ELF/shuffle-sections.s b/lld/test/ELF/shuffle-sections.s
index 6328035e0584b9..21c79eab950d67 100644
--- a/lld/test/ELF/shuffle-sections.s
+++ b/lld/test/ELF/shuffle-sections.s
@@ -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
diff --git a/lld/test/ELF/undefined-glob.s b/lld/test/ELF/undefined-glob.s
index f6d692acf2ebf9..22df4aeee2b955 100644
--- a/lld/test/ELF/undefined-glob.s
+++ b/lld/test/ELF/undefined-glob.s
@@ -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:
diff --git a/lld/test/ELF/version-script-complex-wildcards.s b/lld/test/ELF/version-script-complex-wildcards.s
index 233c4b1fdd904e..c58fb54bcb072a 100644
--- a/lld/test/ELF/version-script-complex-wildcards.s
+++ b/lld/test/ELF/version-script-complex-wildcards.s
@@ -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
diff --git a/lld/test/ELF/warn-backrefs.s b/lld/test/ELF/warn-backrefs.s
index 483ef8a2decefb..1e5c14ed052e66 100644
--- a/lld/test/ELF/warn-backrefs.s
+++ b/lld/test/ELF/warn-backrefs.s
@@ -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:
diff --git a/llvm/lib/Support/GlobPattern.cpp b/llvm/lib/Support/GlobPattern.cpp
index 0de69153cc6896..74e9bc88de4720 100644
--- a/llvm/lib/Support/GlobPattern.cpp
+++ b/llvm/lib/Support/GlobPattern.cpp
@@ -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.
@@ -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] == '!';
diff --git a/llvm/test/tools/llvm-ifs/exclude.test b/llvm/test/tools/llvm-ifs/exclude.test
index 78789486bc8d51..c55c9540a5ab11 100644
--- a/llvm/test/tools/llvm-ifs/exclude.test
+++ b/llvm/test/tools/llvm-ifs/exclude.test
@@ -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
diff --git a/llvm/test/tools/llvm-objcopy/ELF/wildcard-syntax.test b/llvm/test/tools/llvm-objcopy/ELF/wildcard-syntax.test
index 67f7f0b273c989..0eca56a95e9999 100644
--- a/llvm/test/tools/llvm-objcopy/ELF/wildcard-syntax.test
+++ b/llvm/test/tools/llvm-objcopy/ELF/wildcard-syntax.test
@@ -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)
More information about the cfe-commits
mailing list