This is an archive of the discontinued LLVM Phabricator instance.

[-Wunsafe-buffer-usage] Do not assert that function parameters have names.
ClosedPublic

Authored by ziqingluo-90 on Jul 18 2023, 2:14 PM.

Details

Summary

It is possible that a function parameter does not have a name even in a function definition.
So we should not assert that function parameters always have names.

This patch lets the analysis give up on generating fix-its in cases where a function parameter of a definition has no name.
Later we can come up with a better solution, e.g., generating a name for the parameter.

Diff Detail

Event Timeline

ziqingluo-90 created this revision.Jul 18 2023, 2:14 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 18 2023, 2:14 PM
ziqingluo-90 requested review of this revision.Jul 18 2023, 2:14 PM
Herald added a project: Restricted Project. · View Herald TranscriptJul 18 2023, 2:14 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
NoQ added a comment.Jul 18 2023, 3:12 PM

I nitpicked to comments, but other than that LGTM, thanks!

clang/lib/Analysis/UnsafeBufferUsage.cpp
1889–1890

There doesn't have to be a name anywhere, and if it's not there in the definition this usually means the parameter is unused. If it's unused, we won't ever fix it, and this also means that there's no need to give it a name. So I suspect that in the typical case the correct behavior is to just preserve the anonymous parameter as-is.

This is just my usual argument: I think the fixit should simply take the part that doesn't need fixing from the original code, and include it textually. In this case this would mean duplicating the text rather than simply not touching it, but that's probably still more precise than writing code from scratch.

clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-parm-span.cpp
160

There's no fundamental reason we can't fix this, we just didn't have time yet.

NoQ accepted this revision.Jul 18 2023, 3:12 PM
This revision is now accepted and ready to land.Jul 18 2023, 3:12 PM
ziqingluo-90 marked an inline comment as done.Jul 19 2023, 10:56 AM
ziqingluo-90 added inline comments.
clang/lib/Analysis/UnsafeBufferUsage.cpp
1889–1890

I think you are right. I'll update the FIXME comment before land this patch.

This revision was landed with ongoing or failed builds.Jul 19 2023, 2:14 PM
This revision was automatically updated to reflect the committed changes.
ziqingluo-90 marked an inline comment as done.