This is an archive of the discontinued LLVM Phabricator instance.

[Preprocessor] Fix crash emitting note with framework location for "file not found" error.
ClosedPublic

Authored by vsapsai on May 8 2019, 5:41 PM.

Details

Summary

A filename can be remapped with a header map to point to a framework
header and we can find the corresponding framework without the header.
But if the original filename doesn't have a remapped framework name,
we'll fail to find its location and will dereference a null pointer
during diagnostics emission.

Fix by tracking remappings better and emit the note only if a framework
is found before any of the remappings.

rdar://problem/48883447

Event Timeline

vsapsai created this revision.May 8 2019, 5:41 PM
arphaman added inline comments.May 22 2019, 2:26 PM
clang/lib/Lex/HeaderSearch.cpp
821

NIT: It looks like HasBeenMapped should be always set when CacheLookup.MappedName is set as well. Would it make sense to check CacheLookup.MappedName instead to avoid divergence in the future? You could have a helper lambda HasBeenMapped = [] (&) { return CacheLookup.MappedName; } as well.

clang/test/Preprocessor/include-header-missing-in-framework-with-headermap.c
10

would it make sense to exercise both #ifdef in the test in the two clang invocations, but guard the expected-errors with the #ifdef? This way the test can ensure that the error is not emitted in the other invocation.

vsapsai marked 2 inline comments as done.May 22 2019, 7:32 PM
vsapsai added inline comments.
clang/lib/Lex/HeaderSearch.cpp
821

Good point, will change. Now that you've mentioned it, keeping IsMapped and CacheLookup.MappedName in sync doesn't look great.

clang/test/Preprocessor/include-header-missing-in-framework-with-headermap.c
10

The tricky part is that "file not found" is a fatal error and %clang_cc1 will ignore subsequent errors. So we cannot test both includes in the same invocation. It is possible to test all combinations by adding 2 more clang invocations but those extra cases aren't very useful.

vsapsai updated this revision to Diff 200864.May 22 2019, 7:33 PM
  • Address review comments: don't introduce HasBeenMapped and rely on CacheLookup.MappedName.

Changes are rebased, so diff between diffs can be noisy.

This revision is now accepted and ready to land.May 24 2019, 5:13 PM

Thanks for the review, Alex.

This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptMay 27 2019, 12:14 PM