This is an archive of the discontinued LLVM Phabricator instance.

[Clang] Use range loops and autos in lib/Serialization/ASTReader.cpp
AbandonedPublic

Authored by Eugene.Zelenko on Dec 4 2015, 4:24 PM.

Details

Summary

I fixed Clang-tidy modernize-loop-convert. Autos are used for pointer variables assigned via casts. Patch includes other minor cleanups.

Build and regressions were finr on RHEL 6.

Diff Detail

Event Timeline

Eugene.Zelenko retitled this revision from to [Clang] Use range loops and autos in lib/Serialization/ASTReader.cpp.
Eugene.Zelenko updated this object.
Eugene.Zelenko added reviewers: hans, aaron.ballman.
Eugene.Zelenko set the repository for this revision to rL LLVM.
Eugene.Zelenko added a subscriber: cfe-commits.
hans added inline comments.Dec 4 2015, 7:15 PM
lib/Serialization/ASTReader.cpp
3390
for (Module *Exported : Exports)

would be much easier to read. (And having Exported by a reference to a pointer seems odd.)

3512

Using a range-based for loop here is very nice, but again I'm not sure the "auto" is helping.

for (const auto &ImportedModule : ...

would be easier to read, I think.

3570

Same thing.

4306

I'd say "bool" is a better choice here.

5104

I'd spell out ModuleIterator instead of auto here.

6860

Maybe:

for (const ModuleFile &MF : ModuleMgr)
6867

Same here.

7220

Does this fit on one line now?

7854

bool seems better than auto for these (well, not AS I suppose).

aaron.ballman added inline comments.Dec 7 2015, 5:41 AM
lib/Serialization/ASTReader.cpp
3390

for (Module *Exported : Exports)
would be much easier to read. (And having Exported by a reference to a pointer seems odd.)

I would also find: for (const auto *Exported : Exports) to be fine, but definitely agree with Hans that const auto & isn't what we want here.

3512

Using a range-based for loop here is very nice, but again I'm not sure the "auto" is helping.

for (const auto &ImportedModule : ...
would be easier to read, I think.

I think const auto &M is reasonable (it fits with our usual naming conventions), but wouldn't complain if there were a more descriptive name used.

4306

I'd say "bool" is a better choice here.

Agreed.

5074

If auto doesn't shorten this sufficiently to fit on a single line, I think I slightly prefer HeaderFileInfoLookupTable. It's easier to figure out what Table is without having to go to another line in the source file to find out.

5104

I'd spell out ModuleIterator instead of auto here.

I don't see a reason to do that, but I also don't like that this appears to be doing a copy. Is ModuleIterator a pointer? If so, this should be const auto *I instead. If not, const auto &.

6860

Maybe:

for (const ModuleFile &MF : ModuleMgr)

I don't think that naming the type adds benefit for range-based for loop iteration variables unless the type is really obscure. We don't name the types in the vast majority of places in the code base from what I can tell.

7220

Does this fit on one line now?

If it does not, I don't think auto is the correct type specifier to use here.

Eugene.Zelenko removed rL LLVM as the repository for this revision.

I fixed two loops and don't use auto instead of bool.

Auto is also used for results of new.

Eugene.Zelenko added inline comments.Dec 7 2015, 11:56 AM
lib/Serialization/ASTReader.cpp
5074

I don't think it's good idea to make coding practices depending on formatting.

aaron.ballman added inline comments.Dec 7 2015, 12:29 PM
lib/Serialization/ASTReader.cpp
5074

I don't think it's good idea to make coding practices depending on formatting.

I disagree. The use of auto is only when it adds to readability of the code. We've distilled this down to cases where the type is obvious due to already being stated in the initialization of the variable. If that initialization means I have to look somewhere else to see the actual type, then the benefit of auto is reduced.

Eugene.Zelenko abandoned this revision.Jan 14 2016, 6:48 PM