[PATCH] D52280: Don't trim non-alphanumeric characters in 'file not found' errors for include directives.
Jorge Gorbe via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Sep 19 14:34:30 PDT 2018
jgorbe created this revision.
jgorbe added reviewers: christylee, rsmith, aaron.ballman.
r342177 <https://reviews.llvm.org/rL342177> introduced a hint in cases where an #included file is not found. It tries to find a suggestion by removing leading or trailing non-alphanumeric characters and checking if a matching file exists, then it reports an error like:
include-likely-typo.c:3:10: error: '<empty_file_to_include.h>' file not found, did you mean 'empty_file_to_include.h'?
#include "<empty_file_to_include.h>" // expected-error {{'<empty_file_to_include.h>' file not found, did you mean 'empty_file_to_include.h'?}}
^~~~~~~~~~~~~~~~~~~~~~~~~~~
"empty_file_to_include.h"
1 error generated.
However, if a hint is **not** found, the error message will show only the trimmed name we use to look for a hint, so:
#include "/non_existing_file."
will result in:
include-leading-nonalpha-no-suggest.c:3:10: fatal error: 'non_existing_file_to_include.h' file not found
#include "/non_existing_file_to_include.h" // expected-error {{'/non_existing_file_to_include.h' file not found}}
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 error generated.
where the name reported after `"fatal error:"` doesn't match what the user wrote.
This change reports the original file name instead of the trimmed one when a suggestion is not found.
Repository:
rC Clang
https://reviews.llvm.org/D52280
Files:
lib/Lex/PPDirectives.cpp
test/Preprocessor/include-leading-nonalpha-no-suggest.c
test/Preprocessor/include-leading-nonalpha-suggest.c
Index: test/Preprocessor/include-leading-nonalpha-suggest.c
===================================================================
--- /dev/null
+++ test/Preprocessor/include-leading-nonalpha-suggest.c
@@ -0,0 +1,3 @@
+// RUN: %clang_cc1 %s -verify
+
+#include "/empty_file_to_include.h" // expected-error {{'/empty_file_to_include.h' file not found, did you mean 'empty_file_to_include.h'?}}
Index: test/Preprocessor/include-leading-nonalpha-no-suggest.c
===================================================================
--- /dev/null
+++ test/Preprocessor/include-leading-nonalpha-no-suggest.c
@@ -0,0 +1,3 @@
+// RUN: %clang_cc1 %s -verify
+
+#include "/non_existing_file_to_include.h" // expected-error {{'/non_existing_file_to_include.h' file not found}}
Index: lib/Lex/PPDirectives.cpp
===================================================================
--- lib/Lex/PPDirectives.cpp
+++ lib/Lex/PPDirectives.cpp
@@ -1887,8 +1887,8 @@
// Check for likely typos due to leading or trailing non-isAlphanumeric
// characters
+ StringRef OriginalFilename = Filename;
if (!File) {
- StringRef OriginalFilename = Filename;
while (!isAlphanumeric(Filename.front())) {
Filename = Filename.drop_front();
}
@@ -1915,7 +1915,7 @@
// If the file is still not found, just go with the vanilla diagnostic
if (!File)
- Diag(FilenameTok, diag::err_pp_file_not_found) << Filename
+ Diag(FilenameTok, diag::err_pp_file_not_found) << OriginalFilename
<< FilenameRange;
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D52280.166184.patch
Type: text/x-patch
Size: 1614 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180919/58b97204/attachment.bin>
More information about the cfe-commits
mailing list