[PATCH] D99903: [Clang][Sema] better -Wcast-function-type diagnose for pointer parameters and parameters with cv-qualifiers
Yuanfang Chen via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Apr 5 15:22:42 PDT 2021
ychen created this revision.
ychen added a reviewer: rsmith.
ychen requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
1. Skip diagnosing all pointer-like parameters.
2. Replace `Context.hasSameUnqualifiedType` with `Context.hasSimilarType`.
3. Add corresponding tests.
After some thoughts, I think we could add the following extension in the
future (probably under an additional flag such as `-Wcast-function-type=2)
according to user feedbacks for the reasons: 1) users could use
`void(*)(void)` to explicitly override checks (for example:
https://trac.webkit.org/changeset/231565/webkit); 2) these checks could
hide real bugs that users may want to catch; 3) using `void(*)(void)`
makes following extension worthwhile only when a codebase uses these
patterns on a large scale which seems unlikely.
(GCC does not do the following)
- allow integer promotion (`void(int)` -> `void(char)`)
- allow arbitrary pointer-to-member conversion
- allow parameter counts mismatch
the use pattern is "passing an extra (unwanted) parameter to callbacks"
https://bugs.freedesktop.org/show_bug.cgi?id=107349#c0
Thoughts?
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D99903
Files:
clang/lib/Sema/SemaCast.cpp
clang/test/Sema/warn-cast-function-type.c
clang/test/Sema/warn-cast-function-type.m
clang/test/SemaCXX/warn-cast-function-type.cpp
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D99903.335343.patch
Type: text/x-patch
Size: 5406 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210405/c93b65ac/attachment-0001.bin>
More information about the cfe-commits
mailing list