This is an archive of the discontinued LLVM Phabricator instance.

[clang][lex] Use `SearchDirIterator` types in for loops
ClosedPublic

Authored by jansvoboda11 on Feb 14 2022, 7:34 AM.

Details

Summary

This patch replaces a lot of index-based loops with iterators and ranges.

Depends on D117566.

Diff Detail

Event Timeline

jansvoboda11 requested review of this revision.Feb 14 2022, 7:34 AM
jansvoboda11 created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptFeb 14 2022, 7:35 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript

Nice. I think this reads a lot better than the index-based implementation.

clang/lib/Lex/HeaderSearch.cpp
1449–1450

Could we change this function to return an unsigned instead of Optional<unsigned> now?

Also, is &DL - &*SearchDirs.begin() safe and doesn’t trigger the issues we saw previously if start and end are allocated in different memory regions, because I don’t know.

jansvoboda11 added inline comments.Feb 14 2022, 11:28 PM
clang/lib/Lex/HeaderSearch.cpp
1449–1450

Yes, updating the return type makes sense now, thanks!

Yes, this should be safe as of this patch, since we're still storing DirectoryLookup objects in std::vector<DirectoryLookup>. I'll be updating this code when we change the storage (separate std::vector<DirectoryLookup> for quoted, angled and system search paths).

Remove Optional<...>

ahoppen accepted this revision.Feb 15 2022, 12:47 AM
ahoppen added inline comments.
clang/lib/Lex/HeaderSearch.cpp
1449–1450

OK, great. Makes sense. 👍

This revision is now accepted and ready to land.Feb 15 2022, 12:47 AM
This revision was landed with ongoing or failed builds.Feb 15 2022, 2:04 AM
This revision was automatically updated to reflect the committed changes.