Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix -Wstrict-prototype warnings in HalideRuntime.h #8027

Merged
merged 1 commit into from
Jan 9, 2024

Conversation

twesterhout
Copy link
Contributor

@twesterhout twesterhout commented Jan 8, 2024

When HalideRuntime.h is included in a C file, functions that are declared with () instead of (void) for their arguments change meaning. These may cause issues downstream because different code is generated.

E.g., godbolt example

This PR introduces a HALIDE_NO_ARGS macro that expands to nothing or void depending on whether the code is compiled in C++ or C mode. That way declarations such as function(HALIDE_NO_ARGS) mean "function function receives no arguments" in both C++ and C.
This PR replaces uses of function() with function(void) since function(void) means "function function receives no arguments in both C++ and C"

P.S. this issue was discovered when trying to use Halide with Chapel, but Chapel used -Wstrict-prototypes...

When HalideRuntime.h is included in a C file, funtions that are declared
with `()` instead of `(void)` for their arguments change meaning. These
may cause issues downstream because different code is generated.
E.g., [godbolt link](https://godbolt.org/#z:OYLghAFBqd5TKALEBjA9gEwKYFFMCWALugE4A0BIEAZgQDbYB2AhgLbYgDkAjF%2BTXRMiAZVQtGIHgBYBQogFUAztgAKAD24AGfgCsp5eiyagA%2BudTkVjVEQJDqzTAGF09AK5smIAMw9yTgAyBEzYAHKeAEbYpCAArOQADuhKxPZMrh5evv7JqXZCwaERbNGxCdbYtukiRCykRJme3n5W2DYFTLX1REXhUTHxVnUNTdmtSiO9If2lg3EAlFbo7qSonFzY6kQxTADUIUR7gugQCwCkPgBC51oAgrd3Wzuk%2B4d7kfUQAG7oBJgXa6PR7vNgsEIQd71YCWPaoJD1ABUiL20O%2BCz25wA7Dd7nt8R8voDcXcCcd0KdiY8yaRsERVvstJcSdiACJcJb0bhxfjeLg6cjobjOPZKFZrbCYgBMfn4RG0HKWAGtfD4AHQ%2BTVa7XagBshm40n4bHiWnIfIFQq4/CUIDN8v5HPIcFgKAwOHwxDIlGodEYrA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anks for the fix

@abadams abadams merged commit cdebeb8 into halide:main Jan 9, 2024
14 of 19 checks passed
@twesterhout twesterhout deleted the fix-strict-prototypes branch January 9, 2024 10:32
@steven-johnson
Copy link
Contributor

I am deeply confused: how is it possible that () vs (void) can cause different codegen? Don't they have identical meanings in the language (ie: no arguments)?

@steven-johnson
Copy link
Contributor

Additionally, if we must standardize on one or the other, I would vastly prefer that we choose () rather than (void) since the former is what is enforced by our clang-format/clang-tidy ruleset (and I'm surprised that this PR landed without them complaining)

@twesterhout
Copy link
Contributor Author

twesterhout commented Jan 9, 2024

@steven-johnson they have identical meaning in C++ and C23 (and newer), but not in C11 and older versions of C. I guess the idea of HalideRuntime.h is to be usable from both C++ and C, hence the choice of (void) in the PR. The godbolt example shows that if compiled as C++, () and (void) generate the same code, but if compiled as C, the generated code is different (this was very surprising to me as well, but was pointed out originally by folks from Chapel's compiler team).

@steven-johnson
Copy link
Contributor

OK, I see now, they are equivalent in C++ but officially-obsolescent-but-still-legal C means "any kind of args", sigh, sorry for the noise

ardier pushed a commit to ardier/Halide-mutation that referenced this pull request Mar 3, 2024
When HalideRuntime.h is included in a C file, funtions that are declared
with `()` instead of `(void)` for their arguments change meaning. These
may cause issues downstream because different code is generated.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants