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

Address type mismatch warnings on aarch64 #313

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ellert
Copy link
Contributor

@ellert ellert commented Jan 28, 2025

The PROVIDER_INFO macro used in the aarch64 code declares all functions with the signature:

extern void function(void);

The actual return type and parameter list of the functions are however different. The declarations provided by the PROVIDER_INFO macro therfore conflicts with the actual declarations of the functions elsewhere in the code, causing compiler warnings.

This commit drops the PROVIDER_INFO macro and provides proper function declarations, eiter by including a header file or by providing a forward declaration. This corresponds to how the code for the other architectures are handlinging this issue.

This PR fixes: #312

The PROVIDER_INFO macro used in the aarch64 code declares all
functions with the signature:

extern void function(void);

The actual return type and parameter list of the functions are however
different. The declarations provided by the PROVIDER_INFO macro
therfore conflicts with the actual declarations of the functions
elsewhere in the code, causing compiler warnings.

This commit drops the PROVIDER_INFO macro and provides proper function
declarations, eiter by including a header file or by providing a
forward declaration. This corresponds to how the code for the other
architectures are handlinging this issue.

Signed-off-by: Mattias Ellert <[email protected]>
@pablodelara
Copy link
Contributor

@liuqinfei could you take a look at this PR? Thanks!

@pablodelara
Copy link
Contributor

@ellert, China is on holidays until next week I think, so @liuqinfei won't be available until then to review.

@liuqinfei
Copy link
Contributor

Hi, ellert. Thanks for your commit.
Macros such as Provider_INFO enable efficient declaration of functions without redundant lines of code.
You can refer to the implementation of x86. When declaring a extern function, you do not need to use the return value type. And here for aarch64, you can see that DIGNOSTIC_IGNORE(-Wnested-externs) has been explicitly used in the macro definition to ignore specific warning messages releated to extern.
And i compiled isal v2.31.1 on the openEuler 22.03 (LTS-SP3) OS with kunpeng920 platform(aarch64). There is no such warning information.
I don't think such a modification is necessary.

@ellert
Copy link
Contributor Author

ellert commented Feb 11, 2025

There is no such warning information.

Did you try to compile with gcc 15? The problem reported by @pablodelara in #312 and also seen in e.g. this compilation log from the RPM package build on Fedora 42:

https://kojipkgs.fedoraproject.org//packages/isa-l/2.31.1/4.fc42/data/logs/aarch64/build.log

are related to this new compiler version. This is related to that the default C version in this compiler is C23, especially this section of the porting notes is relevant:

https://gcc.gnu.org/gcc-15/porting_to.html#c23-fn-decls-without-parameters

So the error prone behaviour of earlier C versions where a function with an empty parameter list () can take any number of arguments is no longer valid, and an empty parameter list ins now the same as (void), i.e. a function with no arguments.

@liuqinfei
Copy link
Contributor

Oh, I haven't had a chance to try out GCC 15 yet. I did verify GCC 10 and GCC 12, which is currently the latest version available on openEuler. However, I'm puzzled as to why GCC 15 would still issue a warning even when the "GCC diagnostic ignored -Wnested-externs" directive is in place.

@liuqinfei
Copy link
Contributor

https://gcc.gnu.org/gcc-15/porting_to.html#c23-fn-decls-without-parameters
These can be fixed by including the correct header and removing the non-prototype declaration.
Alternatively you can use -std= to select an earlier version of the C standard.

And if the second way can fix the warning. Could you verify that?

@ellert
Copy link
Contributor Author

ellert commented Mar 6, 2025

Hej. Sorry for the late reply.

The warning here is not strictly related to c23 and gcc 15, since you see the same warnings with gcc 11 and gcc 14 which defaults to c17. The warning is because the same function is defined with different parameter lists in different source files. i.e. once in the file where it is implemented (and possibly also in a header file) with the actual parameter list, and once by using the PROVIDER_INFO macro with the parameter list (void), i.e. taking exactly 0 parameters. When linking the object files together the compiler sees the conflicting definitions and issues a warning. I.e. this is a link time warning about inconsistent definitions in different source files, not a warning about C language syntax violations in a single source file.

Possibly the intention of the original author of the PROVIDER_INFO macro was not to use the parameter list (void) in the macro, but rather to use () as the parameter signature. In c17 and earlier standards the parameter list () has a different meaning than the parameter list (void). Here () mean an unknown parameter list with arbitrary length, while (void) means an empty parameter list with zero length.

If () is used in the macro, there is no conflict between the real parameter list in other source files and the unknown parameter list in the macro. However, using an unknown parameter list is a common source of errors in C code, and the isa-l project activates the -Wstrict-prototypes option in the makefiles to ensure that a warning is issued if it is used in the code.

So replacing (void) with () in the macro replaces the warning about conflicting definition to warnings about not using strict prototypes, with c17 and earlier. With c23, the meaning of () has changed and now means the same as (void), i.e. an empty parameter list with exactly zero elements (as was always the case in C++). So with c23 changing (void) to () has no effect and the same warnings about conflicting definitions as before the change are shown.

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.

Compilation warnings in ISA-L 2.31.1 on Fedora-aarch64
3 participants