This is an archive of the discontinued LLVM Phabricator instance.

[C89/C2x] Diagnose calls to a function without a prototype but passes arguments
ClosedPublic

Authored by aaron.ballman on Apr 9 2022, 8:02 AM.

Details

Reviewers
jyknight
hubert.reinterpretcast
delcypher
erichkeane
cor3ntin
Group Reviewers
Restricted Project
Summary

This catches places where a function without a prototype is accidentally used, potentially passing an incorrect number of arguments, and is a follow-up to the work done in https://reviews.llvm.org/D122895 and described in the RFC (https://discourse.llvm.org/t/rfc-enabling-wstrict-prototypes-by-default-in-c). The diagnostic is grouped under the new -Wdeprecated-non-prototypes warning group and is enabled by default.

The diagnostic is disabled if the function being called was implicitly declared (the user already gets an on-by-default warning about the creation of the implicit function declaration, so no need to warn them twice on the same line). Additionally, the diagnostic is disabled if the declaration of the function without a prototype was in a location where the user explicitly disabled deprecation warnings for functions without prototypes (this allows the provider of the API a way to disable the diagnostic at call sites because the lack of prototype is intentional).

Diff Detail

Event Timeline

aaron.ballman created this revision.Apr 9 2022, 8:02 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 9 2022, 8:02 AM
aaron.ballman requested review of this revision.Apr 9 2022, 8:02 AM
Herald added a project: Restricted Project. · View Herald TranscriptApr 9 2022, 8:02 AM
cor3ntin accepted this revision as: cor3ntin.Apr 9 2022, 8:18 AM
cor3ntin added a subscriber: cor3ntin.

LGTM except a couple of nitpicks

clang/lib/Sema/SemaExpr.cpp
7052

I have a hard time parsing this sentence. I suspect words or punctuation are missing

7065

!= nullptr may be cleaner

This revision is now accepted and ready to land.Apr 9 2022, 8:18 AM
aaron.ballman marked 2 inline comments as done.

Updated based on review comments.

clang/lib/Sema/SemaExpr.cpp
7052

I reworded to mention the warning group specifically; that hopefully clears up the confusion.

7065

Sure!

cor3ntin added inline comments.Apr 9 2022, 8:35 AM
clang/lib/Sema/SemaExpr.cpp
7052

Excellent !

erichkeane added inline comments.Apr 12 2022, 6:18 AM
clang/docs/ReleaseNotes.rst
146

This reads awkwardly to me... Maybe something like?

Additionally, it will diagnose calls with provided arguments to a function without a prototype. This warning is enabled only when the `-Wdeprecated-non-prototype` option is enabled at the function declaration, which allows a developer to disable the diagnostic for all callers at the point of declaration.

clang/include/clang/Basic/DiagnosticSemaKinds.td
5558

perhaps:

"function %select{|%1}0 without prototype called with arguments specified"

or something like that?

aaron.ballman marked 3 inline comments as done.

Updated based on review feedback (reworded diagnostic and release note).

clang/docs/ReleaseNotes.rst
146

Oh, this is much better, thank you!

clang/include/clang/Basic/DiagnosticSemaKinds.td
5558

After some off-list discussion, we landed on some new wording here that better describes the issue with the user's code instead of just describing what the user's code does and hoping they infer the issue from there. :-D

erichkeane accepted this revision.Apr 12 2022, 7:44 AM

FYI -- I plan to land this tomorrow unless I hear more feedback from reviewers (but as always, I'll happily take post-commit feedback as well).