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

Using C11 stdnoreturn.h causes compiler warnings in headers #332

Open
blue42u opened this issue Sep 5, 2024 · 4 comments · May be fixed by #333
Open

Using C11 stdnoreturn.h causes compiler warnings in headers #332

blue42u opened this issue Sep 5, 2024 · 4 comments · May be fixed by #333
Labels
accepted bug upcoming release A fix/support will be available with the upcoming external release

Comments

@blue42u
Copy link

blue42u commented Sep 5, 2024

The public headers introduce a compiler warning related to the noreturn attribute if stdnoreturn.h is included before they are. This prevents -Werror builds from passing for XED users using C11 features:

# gcc --version
gcc (Ubuntu 13.2.0-23ubuntu4) 13.2.0
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

# cat example.c
#include <stdnoreturn.h>
#include <xed/xed-interface.h>
# gcc example.c -I kits/xed-*/include -Werror
In file included from kits/xed-install-base-2024-09-05-lin-x86-64/include/xed/xed-decoded-inst.h:26,
                 from kits/xed-install-base-2024-09-05-lin-x86-64/include/xed/xed-decode.h:24,
                 from kits/xed-install-base-2024-09-05-lin-x86-64/include/xed/xed-interface.h:40,
                 from example.c:2:
kits/xed-install-base-2024-09-05-lin-x86-64/include/xed/xed-util.h:120:1: error: '_Noreturn' attribute directive ignored [-Werror=attributes]
  120 | XED_NORETURN XED_NOINLINE XED_DLL_EXPORT void xed_internal_assert(const char* s, const char* file, int line);
      | ^~~~~~~~~~~~
cc1: all warnings being treated as errors
@blue42u

This comment was marked as resolved.

@marjevan
Copy link
Member

marjevan commented Sep 9, 2024

Thank you for reporting the issue.

The XED library uses the __attribute__((noreturn)) directive to mark functions that do not return, instead of the _Noreturn keyword. This decision was made to maintain backward compatibility with C99 standards (before C11) where _Noreturn is not supported.

When you include <stdnoreturn.h> (a C11 header) before the XED library, GCC encounters a potential conflict between the _Noreturn keyword (introduced in C11) and the __attribute__((noreturn)) attribute used in XED. Both serve the same purpose, but GCC may issue warnings when it detects both attributes in the same code, sometimes ignoring one.

To resolve this issue, I recommend swapping the order in which you include headers. By including the XED library headers before including <stdnoreturn.h>, you ensure that GCC correctly handles the __attribute__((noreturn)) directive used by the XED library, while still allowing you to use the _Noreturn keyword in your own code if needed.

You can adjust it to:

#include <xed/xed-interface.h>
#include <stdnoreturn.h>

Please let us know if this solution works for you.

@blue42u
Copy link
Author

blue42u commented Sep 9, 2024

Thank you for the comprehensive response. Swapping the order of #includes does work in this simple example, however in our full codebase we include external C11 headers that do or may in the future include stdnoreturn.h themselves. Combined with #include sorting it is generally difficult for us to ensure Xed headers are always #included before stdnoreturn.h.

Please fix the headers to work in a C11 codebase. For C99 compatibility you can use the __attribute__((__noreturn__)) alias, but I recommend using the standardized noreturn or [[noreturn]] attributes when compiling in C11 or C23 mode respectively.

@blue42u blue42u linked a pull request Sep 14, 2024 that will close this issue
@marjevan
Copy link
Member

A fix will be available with the upcoming external release.

@marjevan marjevan added the upcoming release A fix/support will be available with the upcoming external release label Sep 17, 2024
jmellorcrummey pushed a commit to HPCToolkit/hpctoolkit that referenced this issue Oct 2, 2024
The Xed headers have a bug where they generate compiler warnings when
compiled in C11 code, specifically when `stdnoreturn.h` is included
before they are. See intelxed/xed#332.

Apply a PR patch to dodge this bug and permit a -Werror build.

Signed-off-by: Jonathon Anderson <[email protected]>
@marjevan marjevan added the bug label Oct 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted bug upcoming release A fix/support will be available with the upcoming external release
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants
@blue42u @marjevan and others