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

Compile Under -pedantic -Werror and -std=c90 #2099

Merged
merged 11 commits into from
May 4, 2020

Conversation

felixhandte
Copy link
Contributor

@felixhandte felixhandte commented Apr 30, 2020

This changeset allows Zstd to be built without warnings under -pedantic. Specifically, this was tested with:

make clean zstd CFLAGS="-std=c99 -Wall -Wextra -pedantic -Werror -DDEBUGLEVEL=3" CC=gcc
make clean zstd CFLAGS="-std=c99 -Wall -Wextra -pedantic -Werror -DDEBUGLEVEL=3" CC=clang

This addresses #2035. See also previous threads on this topic: #1989, #1540, and #1538.

It also lets Zstd build successfully (though not without warnings) under C90/C89/ANSI mode.

This PR accomplishes this in a different way than previous solutions. Rather than diverge into two kinds of macros with and without additional arguments, it simply complies with C99 by making sure every invocation of these macros does have at least one argument.

Known deficiencies:

  • Every invocation of RETURN_ERROR_IF, RETURN_ERROR, and FORWARD_IF_ERROR must have an info string.

Why I selected this approach: adding , "" to the args is no more characters than adding _MSG to the name of the macro, and I'd rather bias contributors towards including explanatory text than away.

That being said, we could also introduce versions of these macros that don't take additional arguments. I'm open to suggestions.

@felixhandte felixhandte changed the title Compile Under -pedantic -Werror Compile Under -pedantic -Werror and -std=c90 Apr 30, 2020
@terrelln
Copy link
Contributor

Looks like the failing test is just noise, but this looks good to me once all the CI is passing!

@terrelln
Copy link
Contributor

We will need to compile with -pedantic in some CI. I suggest adding it to the CircleCI builds, since those are mostly compilation tests, and they complete the fastest by far.

@Cyan4973
Copy link
Contributor

Cyan4973 commented May 1, 2020

The proposed solution looks good to me.
I agree with @terrelln that the only missing detail is a -pedantic test to ensure that the property remains respected in future changes.

felixhandte added 11 commits May 4, 2020 10:58
Even without `-pedantic`, these macros will now fail to compile unless you
provide an info string argument. This will prevent us from regressing.
`-Wall` implies `-Wformat-zero-length`, which will cause compilation to fail
under `-Werror` when an empty string is passed as the format string to a
`printf`-family function. This commit moves us back to prefixing the provided
format string, which successfully avoids that warning.

However, this removes the failure mode where that `RAWLOG` invocation would
fail to compile when no format string was provided at all (which was desirable
to avoid having code that would successfully compile normally but fail under
`-pedantic`, which *does* require that a non-zero number of args are provided).

So this commit also introduces a function which does nothing at all, but will
fail to compile if not provided with at least one argument, which is a string.
This successfully links the compilability of pedantic and non-pedantic builds.
Previously we would use it for all gcc-like compilations, even when a
restrictive mode that disallowed it had been selected.
It was causing build issues in ANSI mode.
It's complaining about the `memcpy`s, saying:

"warning C4090: 'function': different 'const' qualifiers"

Let's try explicitly casting to the argument types...
@felixhandte felixhandte force-pushed the compile-under-pedantic branch from 56bcf6e to 2cf72d5 Compare May 4, 2020 14:59
@felixhandte felixhandte merged commit 7e9aabd into facebook:dev May 4, 2020
@Cyan4973 Cyan4973 mentioned this pull request May 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants