Explicitly use void in the C function list of arguments for functions that take no arguments#38307
Merged
Merged
Conversation
that take no arguments Using void in the list of function arguments in C++ is allowed for functions that take no arguments, but it's rather uncommon. However, when it comes to plain C, there is an actual difference between a function declaration `int foo()` and `int foo(void)`. The first one says that there is a function foo that returns an integer and nothing is known about the arguments the function takes. While the second one explicitly declares that the function takes no argument. In practice this difference does not often matter, however, from the language point of view, they are not the same and it triggers UBSAN when running Envoy tests on clang-18. Specifically, UBSAN complains that tests attempt to call a function thought a pointer of incompatible function type. I don't believe it causes any issues in practice for Envoy, but addressing these warnings will help us to move to a newer version of LLVM toolchains for Envoy. NOTE: There are some alternative ways we could address this issue as well, for example, we can change all the examples to use C++ instead of C, and, I belive, it would also address the issue, but it's a bit more invasive and I opted not to convert all the tests because of is practically a false positive UBSAN complain. Signed-off-by: Mikhail Krinkin <mkrinkin@microsoft.com>
Signed-off-by: Mikhail Krinkin <mkrinkin@microsoft.com>
Contributor
|
Assigning @mathetake as extension code-owner. |
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.
Commit Message:
Using void in the list of function arguments in C++ is allowed for functions that take no arguments, but it's rather uncommon.
However, when it comes to plain C, there is an actual difference between a function declaration
int foo()andint foo(void). The first one says that there is a function foo that returns an integer and nothing is known about the arguments the function takes. While the second one explicitly declares that the function takes no argument.In practice this difference does not often matter, however, from the language point of view, they are not the same and it triggers UBSAN when running Envoy tests on clang-18.
Specifically, UBSAN complains that tests attempt to call a function thought a pointer of incompatible function type.
I don't believe it causes any issues in practice for Envoy, but addressing these warnings will help us to move to a newer version of LLVM toolchains for Envoy.
NOTE: There are some alternative ways we could address this issue as well, for example, we can change all the examples to use C++ instead of C, and, I belive, it would also address the issue, but it's a bit more invasive and I opted not to convert all the tests because of is practically a false positive UBSAN complain.
Additional Description:
Related to #37911 and fixes one of the issues in #38093
This is the best write-up on the topic of using void in the paramters list I could find to elaborate: https://wiki.sei.cmu.edu/confluence/display/c/DCL20-C.+Explicitly+specify+void+when+a+function+accepts+no+arguments#:~:text=Defining%20a%20function%20with%20a,%5BTIGCC%2C%20void%20usage%5D..
Risk Level: low
Testing:
bazel test -c dbg //test/extensions/dynamic_modules:dynamic_modules_test --config=docker-asanDocs Changes: n/a
Release Notes: n/a
Platform Specific Features: n/a
+cc @phlax