Repository navigation
fix(const-param): keep the parameter types of a function used as a callback - #292
Draft
SizzleUnrlsd wants to merge 12 commits into
Draft
SizzleUnrlsd wants to merge 12 commits into
SizzleUnrlsd wants to merge 12 commits into
Conversation
…llback A function whose address goes to a call, into memory, out of a function or into the initializer of a variable is called through a pointer to function, and the type of that pointer sets the types of its parameters: const is not suggested for them. A virtual function, held in the table of its class, is not such a use. Refs #217
Its address goes to a call, into a table, into a variable or out of a function. A function that is only called keeps the suggestion. Refs #217
…lback A lambda converted to a pointer to function gives away a function that the compiler writes in its class, and that function calls the lambda's body: the body's parameters have the types the pointer sets. Refs #217
One has the shape of a thread's start routine, another takes a typed pointer. A lambda that is only called keeps the suggestion. Refs #217
…llbacks The index of the modules analyzed together lists the external functions whose address a module gives away, defined there or not. A function listed there keeps its parameter types. Refs #217
…her file A multi-file run gathers the callbacks of every module: one module that uses a function as a callback is enough to set its types. Refs #217
…nother Alone, the file that defines it says nothing of that use, and const is suggested. With the file that uses it, whatever the sort order, it is not. A function that the other file only calls keeps the suggestion. Refs #217
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ConstParameterNotModifiedsuggestedconstfor a parameter of a function used as a callback. That function is called through a pointer to function, and the type of the pointer sets the types of its parameters: the suggested type does not compile. This is the callback example of #217; the other examples of that issue are not changed.Refs #217
Change
llvm.used. No function is named in the rule.Tests
New, in
test/pointer_reference-const_correctness/:callback-signature.c: a C function given to a call, kept in a table, kept in a variable, returned. A function that is only called keeps the suggestion.callback-lambda.cpp: a lambda with the shape of a thread's start routine and one with a typed pointer, each converted to a pointer to function. A lambda that is only called keeps the suggestion.check_const_param_callback_cross_tu(run_test.py):on_value()is suggested when its file is analyzed alone, and not with the file that gives it to a call, whatever the sort order;only_called()is suggested in both.callback-virtual-function.cpp: a virtual function that overrides nothing keeps the suggestion.No existing test is changed.
takes_void(void* p)ofadvanced-cases.ckeeps its suggestion.The same checks with main's analyzer (0372f35) and with this one (9fcbff7), built on one runner (run 46917587199, on the branch
experiment/217-callback-compare):callback-signature.ccallback-lambda.cppcheck_const_param_callback_cross_tuon_valueis reported with the file that uses itadvanced-cases.ccallback-virtual-function.cppReports of main and of this pull request on the same inputs
Same run. Each fixture of this tree is analyzed alone by both analyzers (499 inputs), then main's sources as the Self-analysis step of
ci.ymldoes (55 files, 4 analyzers).No run ends differently with the two analyzers. The eleven diagnostics are all
ConstParameterNotModified.Pointer, on a function used as a callback:callback-signature.cand 2 incallback-lambda.cpp: the new fixtures.test/escape-stack/indirect-callback-unknown-target-with-safe-candidate.c:safe_cb(char* p), whichchoose_safe()returns as acb_t, a pointer tovoid (char*). That fixture expects nothing about this parameter and is not changed.src/app/AnalyzerApp.cpp:rawContext, the parameter of the lambda thatrunParallelWorkgives topthread_create, once per instantiation of the template.Each of the seven suggestions on the fixtures, applied to its source, fails to compile with clang 20:
incompatible function pointer typesfor the C functions,no matching function for callfor the lambdas. The lambda ofrunParallelWorkhas the shape of the first one ofcallback-lambda.cpp. The suggestions that stay compile once applied:only_called, the lambda that is only called, and the virtual function.CI at 9fcbff7
All ... passed.line.rawContextsuggestions, and nothing new.Limits
std::threaddoes. A suggestion that would compile is then lost.&ppassed to a pointer to pointer, a lambda whose body is never emitted, a reference bound to a reference member.