This is an archive of the discontinued LLVM Phabricator instance.

Don't trim non-alphanumeric characters in 'file not found' errors for include directives.
ClosedPublic

Authored by jgorbe on Sep 19 2018, 2:32 PM.

Details

Summary

r342177 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.

Diff Detail

Repository
rC Clang

Event Timeline

jgorbe created this revision.Sep 19 2018, 2:32 PM
christylee accepted this revision.Sep 20 2018, 5:21 AM

Thanks for the fix!

This revision is now accepted and ready to land.Sep 20 2018, 5:21 AM
This revision was automatically updated to reflect the committed changes.
This revision was automatically updated to reflect the committed changes.