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

make check fails with gcc7 #202

Closed
ghost opened this issue Jul 1, 2017 · 15 comments · Fixed by #204
Closed

make check fails with gcc7 #202

ghost opened this issue Jul 1, 2017 · 15 comments · Fixed by #204

Comments

@ghost
Copy link

ghost commented Jul 1, 2017

Due to the new implicit-fallthrough warning and -Werror make check fails with gcc7.

make  tests/pick-test
make[1]: Entering directory '/build/pick/src/pick-1.7.0'
gcc -DHAVE_CONFIG_H -I.  -D_GNU_SOURCE -D_FORTIFY_SOURCE=2 -pedantic -Wall -Werror -Wextra -march=x86-64 -mtune=generic -O2 -pipe -fstack-protector-strong -MT tests/tests_pick_test-pick-test.o -MD -MP -MF tests/.deps/tests_pick_test-pick-test.Tpo -c -o tests/tests_pick_test-pick-test.o `test -f 'tests/pick-test.c' || echo './'`tests/pick-test.c
tests/pick-test.c: In function ‘main’:
tests/pick-test.c:76:3: error: this statement may fall through [-Werror=implicit-fallthrough=]
   child(master, slave);
   ^~~~~~~~~~~~~~~~~~~~
tests/pick-test.c:78:2: note: here
  default:
  ^~~~~~~
cc1: all warnings being treated as errors
@ghost
Copy link
Author

ghost commented Jul 1, 2017

Seems like gcc7 does not recognize the /* NOTREACHED */-comment from the old lint to suppress the warning, so there should be an unnecessary break; after child(master, slave);

@ghost
Copy link
Author

ghost commented Jul 1, 2017

so there should be an unnecessary break; after child(master, slave);

That, or adding -Wimplicit-fallthrough=1 to the CFLAGS.

From: https://developers.redhat.com/blog/2017/03/10/wimplicit-fallthrough-in-gcc-7/

The Warning is enabled by -Wextra

-Wimplicit-fallthrough=0 disables the warning altogether.
-Wimplicit-fallthrough=1 treats any kind of comment as a “falls through” comment.

@ghost
Copy link
Author

ghost commented Jul 1, 2017

That, or adding -Wimplicit-fallthrough=1 to the CFLAGS.

I'm for -Wimplicit-fallthrough=0 because it is not really a "falls through" ... although adding new switches to CFLAGS without checking the version of gcc leads to errors on older ones ...

mptre added a commit that referenced this issue Jul 2, 2017
In an attempt to fix #202.
@mptre
Copy link
Owner

mptre commented Jul 2, 2017

Does #204 solve this issue?

@ghost
Copy link
Author

ghost commented Jul 2, 2017

Sorry to report, Anton, it does not ... (gcc (Debian 7.1.0-7) 7.1.0)

@mptre
Copy link
Owner

mptre commented Jul 3, 2017

Is __dead defined on Debian?

diff --git a/compat.h b/compat.h
index 6d2cfee..99ef9f9 100644
--- a/compat.h
+++ b/compat.h
@@ -6,6 +6,7 @@
 #endif
 
 #ifndef __dead
+#error "__dead is not defined"
 #define __dead
 #endif

@ghost
Copy link
Author

ghost commented Jul 3, 2017

No ... seems that __dead is only defined on some *BSD-Systems (not on Linux and FreeBSD).

@mptre
Copy link
Owner

mptre commented Jul 3, 2017

This commit 7f5694a might have been a bad idea after all then...

mptre added a commit that referenced this issue Jul 3, 2017
This reverts commit 7f5694a.

In an attempt to #202.
@mptre
Copy link
Owner

mptre commented Jul 3, 2017

Please give #204 another try.

@ghost
Copy link
Author

ghost commented Jul 4, 2017

Still no luck ... the following works here:

--- pick-test.c.orig	2017-07-04 06:53:01.730489953 +0200
+++ pick-test.c	2017-07-04 06:54:00.510488670 +0200
@@ -12,7 +12,7 @@
 #include <string.h>
 #include <unistd.h>
 
-static void	 child(int, int);
+static void	 child(int, int) __attribute__((noreturn));
 static void	 parent(int, int, const char *);
 static char	*parsekeys(const char *);
 static void	 sighandler(int);

@mptre
Copy link
Owner

mptre commented Jul 4, 2017

My bad, forgot to actually declare the functions as dead. Please give #204 another try.

@ghost
Copy link
Author

ghost commented Jul 4, 2017

For me the fallthrough branch is working now.

@ghost
Copy link
Author

ghost commented Jul 4, 2017

Confirmed for working with gcc (Debian 7.1.0-7) 7.1.0. Thanks @mptre!
Just curious: I understand that this saves a few bytes in the binary - so just inserting a break (or exit, abort, assert) was no valid option?

@mptre
Copy link
Owner

mptre commented Jul 4, 2017

Just curious: I understand that this saves a few bytes in the binary - so just inserting a break (or exit, abort, assert) was no valid option?

Your proposed solutions are sure valid options in order to silence the
compiler. However, I don't want to add a code path that cannot be
reached (i.e. dead code). In this particular scenario the compiler can't
deduce that child() will never return so I think we're better of
instructing the compiler about the behavior and intent of the code
rather than lying about it. Hope that makes sense.

mptre added a commit that referenced this issue Jul 4, 2017
This reverts commit 7f5694a.

Partial fix to #202.
mptre added a commit that referenced this issue Jul 4, 2017
Fixes #202, an issue discovered while compiling pick-test with GCC 7.
@mptre mptre closed this as completed in #204 Jul 4, 2017
@mptre
Copy link
Owner

mptre commented Jul 4, 2017

Thanks to both of you for compiling pick using modern compilers! The fix
has been merged.

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 a pull request may close this issue.

1 participant