This is an archive of the discontinued LLVM Phabricator instance.

[NFC][CLANG] Fix static analyzer bugs about unnecessary object copies with auto
ClosedPublic

Authored by Manna on Sep 6 2023, 2:31 PM.

Diff Detail

Event Timeline

Manna created this revision.Sep 6 2023, 2:31 PM
Herald added a reviewer: ributzka. · View Herald Transcript
Herald added a project: Restricted Project. · View Herald Transcript
Manna requested review of this revision.Sep 6 2023, 2:31 PM
Herald added a project: Restricted Project. · View Herald Transcript
Manna updated this revision to Diff 556273.Sep 8 2023, 9:17 AM
tahonermann accepted this revision.Sep 12 2023, 1:08 PM

Thanks, @Manna, these changes look good to me!

clang/include/clang/ExtractAPI/ExtractAPIVisitor.h
175

I agree that this looks like a good change. CXXBaseSpecifier contains a SourceRange, a SourceLocation, a unsigned (used as a bit-field, and a TypeSourceInfo*. Those are all individually cheap to copy, but together are large enough to justify use of a reference.

clang/lib/Analysis/UnsafeBufferUsage.cpp
2256

This looks good too. The returned map value has const VarDecl* as a key and the element type is FixItList (aka SmallVector<FixItHint, 4>) . FixItHint contains two CharSourceRange objects, a std::string, and a bool, so we definitely don't want to be copying that; especially since the value isn't even wanted here!

clang/lib/ExtractAPI/Serialization/SymbolGraphSerializer.cpp
903

Another case of CXXBaseSpecifier which, per earlier comments, is large enough to justify use of a reference.

This revision is now accepted and ready to land.Sep 12 2023, 1:08 PM
Manna added a comment.Sep 12 2023, 1:43 PM

Thank you @tahonermann for reviews and feedbacks.