0001-Fix-implicit-fallthrough-warning.patch 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. From 962e532099d10ee6ce5b4ce68537bc46595230c0 Mon Sep 17 00:00:00 2001
  2. From: Joshua Watt <Joshua.Watt@garmin.com>
  3. Date: Tue, 24 Nov 2020 08:30:13 -0600
  4. Subject: [PATCH] Fix implicit fallthrough warning
  5. Fixes a warning about an implicit fall through in a case statement
  6. (-Werror=implicit-fallthrough) with newer versions of GCC
  7. Upstream-status: Submitted [https://github.com/gnosek/fcgiwrap/pull/54]
  8. Signed-off-by: Joshua Watt <Joshua.Watt@garmin.com>
  9. ---
  10. configure.ac | 3 +
  11. fcgiwrap.c | 7 ++
  12. m4/ax_gcc_func_attribute.m4 | 242 ++++++++++++++++++++++++++++++++++++
  13. 3 files changed, 252 insertions(+)
  14. create mode 100644 m4/ax_gcc_func_attribute.m4
  15. diff --git a/configure.ac b/configure.ac
  16. index bb3674e..9ef517a 100644
  17. --- a/configure.ac
  18. +++ b/configure.ac
  19. @@ -3,6 +3,7 @@
  20. AC_PREREQ(2.61)
  21. AC_INIT([fcgiwrap], [1.1.0], [root@localdomain.pl])
  22. +AC_CONFIG_MACRO_DIRS([m4])
  23. AM_CFLAGS="-std=gnu99 -Wall -Wextra -Werror -pedantic"
  24. if test x"$CFLAGS" = x""; then
  25. AM_CFLAGS="$AM_CFLAGS -O2 -g3"
  26. @@ -62,5 +63,7 @@ AC_FUNC_MALLOC
  27. AC_CHECK_FUNCS([strchr strdup strrchr])
  28. AC_CHECK_FUNCS([dup2 putenv select setenv strerror],, [AC_MSG_ERROR([seems as if your libraries don't provide an expected function])])
  29. +AX_GCC_FUNC_ATTRIBUTE([fallthrough])
  30. +
  31. AC_CONFIG_FILES([Makefile])
  32. AC_OUTPUT
  33. diff --git a/fcgiwrap.c b/fcgiwrap.c
  34. index b44d8aa..a83726b 100644
  35. --- a/fcgiwrap.c
  36. +++ b/fcgiwrap.c
  37. @@ -56,6 +56,12 @@
  38. #define UNIX_PATH_MAX 108
  39. #endif
  40. +#ifdef HAVE_FUNC_ATTRIBUTE_FALLTHROUGH
  41. +#define FALLTHROUGH __attribute__ ((fallthrough))
  42. +#else
  43. +#define FALLTHROUGH (void)
  44. +#endif
  45. +
  46. extern char **environ;
  47. static char * const * inherited_environ;
  48. static const char **allowed_programs;
  49. @@ -580,6 +586,7 @@ static void handle_fcgi_request(void)
  50. execl(filename, filename, (void *)NULL);
  51. cgi_error("502 Bad Gateway", "Cannot execute script", filename);
  52. + FALLTHROUGH;
  53. default: /* parent */
  54. close(pipe_in[0]);
  55. close(pipe_out[1]);
  56. diff --git a/m4/ax_gcc_func_attribute.m4 b/m4/ax_gcc_func_attribute.m4
  57. new file mode 100644
  58. index 0000000..da2b1ac
  59. --- /dev/null
  60. +++ b/m4/ax_gcc_func_attribute.m4
  61. @@ -0,0 +1,242 @@
  62. +# ===========================================================================
  63. +# https://www.gnu.org/software/autoconf-archive/ax_gcc_func_attribute.html
  64. +# ===========================================================================
  65. +#
  66. +# SYNOPSIS
  67. +#
  68. +# AX_GCC_FUNC_ATTRIBUTE(ATTRIBUTE)
  69. +#
  70. +# DESCRIPTION
  71. +#
  72. +# This macro checks if the compiler supports one of GCC's function
  73. +# attributes; many other compilers also provide function attributes with
  74. +# the same syntax. Compiler warnings are used to detect supported
  75. +# attributes as unsupported ones are ignored by default so quieting
  76. +# warnings when using this macro will yield false positives.
  77. +#
  78. +# The ATTRIBUTE parameter holds the name of the attribute to be checked.
  79. +#
  80. +# If ATTRIBUTE is supported define HAVE_FUNC_ATTRIBUTE_<ATTRIBUTE>.
  81. +#
  82. +# The macro caches its result in the ax_cv_have_func_attribute_<attribute>
  83. +# variable.
  84. +#
  85. +# The macro currently supports the following function attributes:
  86. +#
  87. +# alias
  88. +# aligned
  89. +# alloc_size
  90. +# always_inline
  91. +# artificial
  92. +# cold
  93. +# const
  94. +# constructor
  95. +# constructor_priority for constructor attribute with priority
  96. +# deprecated
  97. +# destructor
  98. +# dllexport
  99. +# dllimport
  100. +# error
  101. +# externally_visible
  102. +# fallthrough
  103. +# flatten
  104. +# format
  105. +# format_arg
  106. +# gnu_format
  107. +# gnu_inline
  108. +# hot
  109. +# ifunc
  110. +# leaf
  111. +# malloc
  112. +# noclone
  113. +# noinline
  114. +# nonnull
  115. +# noreturn
  116. +# nothrow
  117. +# optimize
  118. +# pure
  119. +# sentinel
  120. +# sentinel_position
  121. +# unused
  122. +# used
  123. +# visibility
  124. +# warning
  125. +# warn_unused_result
  126. +# weak
  127. +# weakref
  128. +#
  129. +# Unsupported function attributes will be tested with a prototype
  130. +# returning an int and not accepting any arguments and the result of the
  131. +# check might be wrong or meaningless so use with care.
  132. +#
  133. +# LICENSE
  134. +#
  135. +# Copyright (c) 2013 Gabriele Svelto <gabriele.svelto@gmail.com>
  136. +#
  137. +# Copying and distribution of this file, with or without modification, are
  138. +# permitted in any medium without royalty provided the copyright notice
  139. +# and this notice are preserved. This file is offered as-is, without any
  140. +# warranty.
  141. +
  142. +#serial 12
  143. +
  144. +AC_DEFUN([AX_GCC_FUNC_ATTRIBUTE], [
  145. + AS_VAR_PUSHDEF([ac_var], [ax_cv_have_func_attribute_$1])
  146. +
  147. + AC_CACHE_CHECK([for __attribute__(($1))], [ac_var], [
  148. + AC_LINK_IFELSE([AC_LANG_PROGRAM([
  149. + m4_case([$1],
  150. + [alias], [
  151. + int foo( void ) { return 0; }
  152. + int bar( void ) __attribute__(($1("foo")));
  153. + ],
  154. + [aligned], [
  155. + int foo( void ) __attribute__(($1(32)));
  156. + ],
  157. + [alloc_size], [
  158. + void *foo(int a) __attribute__(($1(1)));
  159. + ],
  160. + [always_inline], [
  161. + inline __attribute__(($1)) int foo( void ) { return 0; }
  162. + ],
  163. + [artificial], [
  164. + inline __attribute__(($1)) int foo( void ) { return 0; }
  165. + ],
  166. + [cold], [
  167. + int foo( void ) __attribute__(($1));
  168. + ],
  169. + [const], [
  170. + int foo( void ) __attribute__(($1));
  171. + ],
  172. + [constructor_priority], [
  173. + int foo( void ) __attribute__((__constructor__(65535/2)));
  174. + ],
  175. + [constructor], [
  176. + int foo( void ) __attribute__(($1));
  177. + ],
  178. + [deprecated], [
  179. + int foo( void ) __attribute__(($1("")));
  180. + ],
  181. + [destructor], [
  182. + int foo( void ) __attribute__(($1));
  183. + ],
  184. + [dllexport], [
  185. + __attribute__(($1)) int foo( void ) { return 0; }
  186. + ],
  187. + [dllimport], [
  188. + int foo( void ) __attribute__(($1));
  189. + ],
  190. + [error], [
  191. + int foo( void ) __attribute__(($1("")));
  192. + ],
  193. + [externally_visible], [
  194. + int foo( void ) __attribute__(($1));
  195. + ],
  196. + [fallthrough], [
  197. + int foo( void ) {switch (0) { case 1: __attribute__(($1)); case 2: break ; }};
  198. + ],
  199. + [flatten], [
  200. + int foo( void ) __attribute__(($1));
  201. + ],
  202. + [format], [
  203. + int foo(const char *p, ...) __attribute__(($1(printf, 1, 2)));
  204. + ],
  205. + [gnu_format], [
  206. + int foo(const char *p, ...) __attribute__((format(gnu_printf, 1, 2)));
  207. + ],
  208. + [format_arg], [
  209. + char *foo(const char *p) __attribute__(($1(1)));
  210. + ],
  211. + [gnu_inline], [
  212. + inline __attribute__(($1)) int foo( void ) { return 0; }
  213. + ],
  214. + [hot], [
  215. + int foo( void ) __attribute__(($1));
  216. + ],
  217. + [ifunc], [
  218. + int my_foo( void ) { return 0; }
  219. + static int (*resolve_foo(void))(void) { return my_foo; }
  220. + int foo( void ) __attribute__(($1("resolve_foo")));
  221. + ],
  222. + [leaf], [
  223. + __attribute__(($1)) int foo( void ) { return 0; }
  224. + ],
  225. + [malloc], [
  226. + void *foo( void ) __attribute__(($1));
  227. + ],
  228. + [noclone], [
  229. + int foo( void ) __attribute__(($1));
  230. + ],
  231. + [noinline], [
  232. + __attribute__(($1)) int foo( void ) { return 0; }
  233. + ],
  234. + [nonnull], [
  235. + int foo(char *p) __attribute__(($1(1)));
  236. + ],
  237. + [noreturn], [
  238. + void foo( void ) __attribute__(($1));
  239. + ],
  240. + [nothrow], [
  241. + int foo( void ) __attribute__(($1));
  242. + ],
  243. + [optimize], [
  244. + __attribute__(($1(3))) int foo( void ) { return 0; }
  245. + ],
  246. + [pure], [
  247. + int foo( void ) __attribute__(($1));
  248. + ],
  249. + [sentinel], [
  250. + int foo(void *p, ...) __attribute__(($1));
  251. + ],
  252. + [sentinel_position], [
  253. + int foo(void *p, ...) __attribute__(($1(1)));
  254. + ],
  255. + [returns_nonnull], [
  256. + void *foo( void ) __attribute__(($1));
  257. + ],
  258. + [unused], [
  259. + int foo( void ) __attribute__(($1));
  260. + ],
  261. + [used], [
  262. + int foo( void ) __attribute__(($1));
  263. + ],
  264. + [visibility], [
  265. + int foo_def( void ) __attribute__(($1("default")));
  266. + int foo_hid( void ) __attribute__(($1("hidden")));
  267. + int foo_int( void ) __attribute__(($1("internal")));
  268. + int foo_pro( void ) __attribute__(($1("protected")));
  269. + ],
  270. + [warning], [
  271. + int foo( void ) __attribute__(($1("")));
  272. + ],
  273. + [warn_unused_result], [
  274. + int foo( void ) __attribute__(($1));
  275. + ],
  276. + [weak], [
  277. + int foo( void ) __attribute__(($1));
  278. + ],
  279. + [weakref], [
  280. + static int foo( void ) { return 0; }
  281. + static int bar( void ) __attribute__(($1("foo")));
  282. + ],
  283. + [
  284. + m4_warn([syntax], [Unsupported attribute $1, the test may fail])
  285. + int foo( void ) __attribute__(($1));
  286. + ]
  287. + )], [])
  288. + ],
  289. + dnl GCC doesn't exit with an error if an unknown attribute is
  290. + dnl provided but only outputs a warning, so accept the attribute
  291. + dnl only if no warning were issued.
  292. + [AS_IF([grep -- -Wattributes conftest.err],
  293. + [AS_VAR_SET([ac_var], [no])],
  294. + [AS_VAR_SET([ac_var], [yes])])],
  295. + [AS_VAR_SET([ac_var], [no])])
  296. + ])
  297. +
  298. + AS_IF([test yes = AS_VAR_GET([ac_var])],
  299. + [AC_DEFINE_UNQUOTED(AS_TR_CPP(HAVE_FUNC_ATTRIBUTE_$1), 1,
  300. + [Define to 1 if the system has the `$1' function attribute])], [])
  301. +
  302. + AS_VAR_POPDEF([ac_var])
  303. +])
  304. --
  305. 2.29.2