[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: clang and _Noreturn
From: |
Paul Eggert |
Subject: |
Re: clang and _Noreturn |
Date: |
Sun, 23 Apr 2017 12:06:33 -0700 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 |
Bruno Haible wrote:
1) If _Noreturn does not apply to function pointers, only to functions, we
should better avoid it. It's an ill-defined standard's feature.
Hmm, well, we cannot avoid _Noreturn in general, since the standard requires it
for functions defined by the standard. Admittedly this incompatibility between
_Noreturn and __attribute__ ((__noreturn__)) is a pain.
So, at least for obstack.c, I propose to be consistent: use only
__attribute__ ((__noreturn__)).
Although this will work for GCC and Clang, I suppose it might cause other
compilers to generate slightly-less-efficient code, because they won't know that
print_and_abort does not return. To avoid that problem, how about this further
patch? If we run into this problem elsewhere we can move the Noreturn macro to a
more-public location.
2017-04-23 Paul Eggert <address@hidden>
obstack: tweak noreturn for non-GCC
* lib/obstack.c (Noreturn): New macro.
(print_and_abort): Use it.
diff --git a/lib/obstack.c b/lib/obstack.c
index 49a846c..9399d4e 100644
--- a/lib/obstack.c
+++ b/lib/obstack.c
@@ -326,7 +326,18 @@ int obstack_exit_failure = EXIT_FAILURE;
# include <libio/iolibio.h>
# endif
-static __attribute_noreturn__ void
+/* Attribute for defining a function that does not return and whose
+ address can be assigned to an __attribute_noreturn__ function
+ pointer. __attribute_noreturn__ is required for compilers that
+ grok __attribute__ ((__noreturn__)) and _Noreturn might help
+ compilers that do not. */
+#if 2 < __GNUC__ + (8 <= __GNUC_MINOR__) || 0x5110 <= __SUNPRO_C
+# define Noreturn __attribute_noreturn__
+#else
+# define Noreturn _Noreturn
+#endif
+
+static Noreturn void
print_and_abort (void)
{
/* Don't change any of these strings. Yes, it would be possible to add
- clang and _Noreturn, Bruno Haible, 2017/04/22
- Re: clang and _Noreturn, Paul Eggert, 2017/04/22
- Re: clang and _Noreturn, Bruno Haible, 2017/04/23
- Re: clang and _Noreturn,
Paul Eggert <=
- Re: clang and _Noreturn, Bruno Haible, 2017/04/23
- Re: clang and _Noreturn, Paul Eggert, 2017/04/23
- Re: clang and _Noreturn, Bruno Haible, 2017/04/24
- Re: clang and _Noreturn, Paul Eggert, 2017/04/24
- Re: clang and _Noreturn, Bruno Haible, 2017/04/25
- Re: clang and _Noreturn, Paul Eggert, 2017/04/25
- Re: clang and _Noreturn, Bruno Haible, 2017/04/26
- Re: clang and _Noreturn, Bruno Haible, 2017/04/26