-
Notifications
You must be signed in to change notification settings - Fork 11.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ELF] Add a spell corrector for "undefined symbol" diagnostics
Non-undefined symbols with Levenshtein distance 1 or a transposition are suggestion candidates. This is probably good enough and it can suggest some missing/superfluous qualifiers: const, restrict, volatile, & and && ref-qualifier, e.g. error: undefined symbol: foo(int*) >>> referenced by b.o:(.text+0x1) +>>> did you mean: foo(int const*) +>>> defined in: a.o error: undefined symbol: foo(int*&) >>> referenced by b.o:(.text+0x1) +>>> did you mean: foo(int*) +>>> defined in: b.o Reviewed By: ruiu Differential Revision: https://reviews.llvm.org/D67039 llvm-svn: 370853
- Loading branch information
Showing
2 changed files
with
149 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# REQUIRES: x86 | ||
# RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t.o | ||
|
||
## Insert a character. | ||
## The spell corrector is enabled for the first two "undefined symbol" diagnostics. | ||
# RUN: echo 'call bcde; call abcd; call abde' | llvm-mc -filetype=obj -triple=x86_64 - -o %t1.o | ||
# RUN: not ld.lld %t.o %t1.o -o /dev/null 2>&1 | FileCheck --check-prefix=INSERT %s -DFILE=%t.o | ||
|
||
## Symbols defined in DSO can be suggested. | ||
# RUN: ld.lld %t.o -shared -o %t.so | ||
# RUN: not ld.lld %t.so %t1.o -o /dev/null 2>&1 | FileCheck --check-prefix=INSERT %s -DFILE=%t.so | ||
|
||
# INSERT: error: undefined symbol: bcde | ||
# INSERT-NEXT: >>> referenced by {{.*}} | ||
# INSERT-NEXT: >>> did you mean: abcde | ||
# INSERT-NEXT: >>> defined in: [[FILE]] | ||
# INSERT: error: undefined symbol: abcd | ||
# INSERT-NEXT: >>> referenced by {{.*}} | ||
# INSERT-NEXT: >>> did you mean: abcde | ||
# INSERT-NEXT: >>> defined in: [[FILE]] | ||
# INSERT: error: undefined symbol: abde | ||
# INSERT-NEXT: >>> referenced by {{.*}} | ||
# INSERT-NOT: >>> | ||
|
||
## Substitute a character. | ||
# RUN: echo 'call bbcde; call abcdd' | llvm-mc -filetype=obj -triple=x86_64 - -o %t1.o | ||
# RUN: not ld.lld %t.o %t1.o -o /dev/null 2>&1 | FileCheck --check-prefix=SUBST %s | ||
|
||
# SUBST: error: undefined symbol: bbcde | ||
# SUBST-NEXT: >>> referenced by {{.*}} | ||
# SUBST-NEXT: >>> did you mean: abcde | ||
# SUBST: error: undefined symbol: abcdd | ||
# SUBST-NEXT: >>> referenced by {{.*}} | ||
# SUBST-NEXT: >>> did you mean: abcde | ||
|
||
## Delete a character. | ||
# RUN: echo 'call aabcde; call abcdee' | llvm-mc -filetype=obj -triple=x86_64 - -o %t1.o | ||
# RUN: not ld.lld %t.o %t1.o -o /dev/null 2>&1 | FileCheck --check-prefix=DELETE %s | ||
|
||
# DELETE: error: undefined symbol: aabcde | ||
# DELETE-NEXT: >>> referenced by {{.*}} | ||
# DELETE-NEXT: >>> did you mean: abcde | ||
# DELETE: error: undefined symbol: abcdee | ||
# DELETE-NEXT: >>> referenced by {{.*}} | ||
# DELETE-NEXT: >>> did you mean: abcde | ||
|
||
## Transpose. | ||
# RUN: echo 'call bacde' | llvm-mc -filetype=obj -triple=x86_64 - -o %t1.o | ||
# RUN: not ld.lld %t.o %t1.o -o /dev/null 2>&1 | FileCheck --check-prefix=TRANSPOSE %s | ||
|
||
# TRANSPOSE: error: undefined symbol: bacde | ||
# TRANSPOSE-NEXT: >>> referenced by {{.*}} | ||
# TRANSPOSE-NEXT: >>> did you mean: abcde | ||
|
||
## Missing const qualifier. | ||
# RUN: echo 'call _Z3fooPi' | llvm-mc -filetype=obj -triple=x86_64 - -o %t1.o | ||
# RUN: not ld.lld %t.o %t1.o -o /dev/null 2>&1 | FileCheck --check-prefix=CONST %s | ||
## Local defined symbols. | ||
# RUN: echo '_Z3fooPKi: call _Z3fooPi' | llvm-mc -filetype=obj -triple=x86_64 - -o %t1.o | ||
# RUN: not ld.lld %t1.o -o /dev/null 2>&1 | FileCheck --check-prefix=CONST %s | ||
|
||
# CONST: error: undefined symbol: foo(int*) | ||
# CONST-NEXT: >>> referenced by {{.*}} | ||
# CONST-NEXT: >>> did you mean: foo(int const*) | ||
|
||
.globl _start, abcde, _Z3fooPKi | ||
_start: | ||
abcde: | ||
_Z3fooPKi: |