Skip to contentSkip to conversation

Some more improvements related to compiler warnings

PATCH Applied Thomas Huth 3 participants 11 messages Jun 29, 2017 – Jun 30, 2017

Subsystems (3)

v1 of 3 Applied Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover Some more improvements related to compiler warnings

Two patches to get rid of -Wextra and use other warning flags globally instead, and an additional third patch to make some functions "static" (to be able to compile the files with the "-Wmissing-prototypes" parameter)

Thomas Huth (3):
Move flags that are shared between C and C++ into COMMON_CFLAGS Replace -Wextra with a saner list of warning flags Mark some local functions as "static"

 Makefile                | 27 ++++++++++++++++-----------
 arm/Makefile.common     |  1 -
 arm/pmu.c               |  2 +-
 lib/pci-testdev.c       |  4 ++--
 lib/printf.c            |  8 ++++----
 lib/x86/fwcfg.c         |  2 +-
 powerpc/Makefile.common |  1 -
 s390x/Makefile          |  1 -
 s390x/intercept.c       |  2 +-
 x86/Makefile.common     |  4 ++--
 x86/Makefile.x86_64     |  2 +-
 11 files changed, 28 insertions(+), 26 deletions(-)
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH 1/3 Move flags that are shared between C and C++ into COMMON_CFLAGS

This way we can add some C-only parameters to CFLAGS later.

---
 Makefile            | 21 +++++++++++----------
 x86/Makefile.common |  4 ++--
 x86/Makefile.x86_64 |  2 +-
 3 files changed, 14 insertions(+), 13 deletions(-)
Makefile +11 -10
index e79cf93..3ef6ea7 100644
@@ -50,8 +50,8 @@ include $(SRCDIR)/$(TEST_DIR)/Makefile
 cc-option = $(shell if $(CC) $(1) -S -o /dev/null -xc /dev/null \
               > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi ;)
 
-CFLAGS += -g
-CFLAGS += $(autodepend-flags) -Wall -Wwrite-strings -Werror
+COMMON_CFLAGS += -g
+COMMON_CFLAGS += $(autodepend-flags) -Wall -Wwrite-strings -Werror
 frame-pointer-flag=-f$(if $(KEEP_FRAME_POINTER),no-,)omit-frame-pointer
 fomit_frame_pointer := $(call cc-option, $(frame-pointer-flag), "")
 fnostack_protector := $(call cc-option, -fno-stack-protector, "")
@@ -59,14 +59,15 @@ fnostack_protector_all := $(call cc-option, -fno-stack-protector-all, "")
 wno_frame_address := $(call cc-option, -Wno-frame-address, "")
 fno_pic := $(call cc-option, -fno-pic, "")
 no_pie := $(call cc-option, -no-pie, "")
-CFLAGS += $(fomit_frame_pointer)
-CFLAGS += $(fno_stack_protector)
-CFLAGS += $(fno_stack_protector_all)
-CFLAGS += $(wno_frame_address)
-CFLAGS += $(if $(U32_LONG_FMT),-D__U32_LONG_FMT__,)
-CFLAGS += $(fno_pic) $(no_pie)
-
-CXXFLAGS += $(CFLAGS)
+COMMON_CFLAGS += $(fomit_frame_pointer)
+COMMON_CFLAGS += $(fno_stack_protector)
+COMMON_CFLAGS += $(fno_stack_protector_all)
+COMMON_CFLAGS += $(wno_frame_address)
+COMMON_CFLAGS += $(if $(U32_LONG_FMT),-D__U32_LONG_FMT__,)
+COMMON_CFLAGS += $(fno_pic) $(no_pie)
+
+CFLAGS += $(COMMON_CFLAGS)
+CXXFLAGS += $(COMMON_CFLAGS)
 
 autodepend-flags = -MMD -MF $(dir $*).$(notdir $*).d
 
x86/Makefile.common +2 -2
index ca97a8e..e96812b 100644
@@ -21,8 +21,8 @@ OBJDIRS += lib/x86
 $(libcflat): LDFLAGS += -nostdlib
 $(libcflat): CFLAGS += -ffreestanding -I $(SRCDIR)/lib -I lib
 
-CFLAGS += -m$(bits)
-CFLAGS += -O1
+COMMON_CFLAGS += -m$(bits)
+COMMON_CFLAGS += -O1
 
 # stack.o relies on frame pointers.
 KEEP_FRAME_POINTER := y
x86/Makefile.x86_64 +1 -1
index fd34cce..623fc5b 100644
@@ -1,7 +1,7 @@
 cstart.o = $(TEST_DIR)/cstart64.o
 bits = 64
 ldarch = elf64-x86-64
-CFLAGS += -mno-red-zone
+COMMON_CFLAGS += -mno-red-zone
 
 cflatobjs += lib/x86/setjmp64.o
 cflatobjs += lib/x86/intel-iommu.o
Signature · 1 line
1.8.3.1
#2 lore raw

PATCH v2 2/3 Replace -Wextra with a saner list of warning flags

In reply to Thomas Huth

Using -Wextra together with -Werror is troublesome - various versions of GCC produce suspicious or even wrong warnings with -Wextra which then become fatal errors with -Werror. For example, the current state of the kvm-unit-tests does not compile anymore with GCC 4.8.1 for s390x due to an inadequate -Wmissing-field-initializers warning. That's annoying for users who just would like to compile the kvm-unit-tests and cumbersome for the developers who have to work around these problems in the source code. So let's replace -Wextra by a saner lists of warning flags that are normally enabled by -Wextra. Since they apparently can be used for building x86, too, the flags are now also applied to the global CFLAGS instead of specifying them for the single targets only.

---
v2:
- Now that we've got COMMON_CFLAGS, the remaining flags can be added to the global CFLAGS, too
- Removed -Wsign-compare

 Makefile                | 10 +++++++---
 arm/Makefile.common     |  1 -
 powerpc/Makefile.common |  1 -
 s390x/Makefile          |  1 -
 4 files changed, 7 insertions(+), 6 deletions(-)
Makefile +7 -3
index 3ef6ea7..f12b2df 100644
@@ -50,9 +50,11 @@ include $(SRCDIR)/$(TEST_DIR)/Makefile
 cc-option = $(shell if $(CC) $(1) -S -o /dev/null -xc /dev/null \
               > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi ;)
 
-COMMON_CFLAGS += -g
-COMMON_CFLAGS += $(autodepend-flags) -Wall -Wwrite-strings -Werror
-frame-pointer-flag=-f$(if $(KEEP_FRAME_POINTER),no-,)omit-frame-pointer
+COMMON_CFLAGS += -g $(autodepend-flags)
+COMMON_CFLAGS += -Wall -Wwrite-strings -Wclobbered -Wempty-body -Wuninitialized
+COMMON_CFLAGS += -Wtype-limits -Wignored-qualifiers -Wunused-but-set-parameter
+COMMON_CFLAGS += -Werror
+ rame-pointer-flag=-f$(if $(KEEP_FRAME_POINTER),no-,)omit-frame-pointer
 fomit_frame_pointer := $(call cc-option, $(frame-pointer-flag), "")
 fnostack_protector := $(call cc-option, -fno-stack-protector, "")
 fnostack_protector_all := $(call cc-option, -fno-stack-protector-all, "")
@@ -67,6 +69,8 @@ COMMON_CFLAGS += $(if $(U32_LONG_FMT),-D__U32_LONG_FMT__,)
 COMMON_CFLAGS += $(fno_pic) $(no_pie)
 
 CFLAGS += $(COMMON_CFLAGS)
+CFLAGS += -Wmissing-parameter-type -Wold-style-declaration -Woverride-init
+
 CXXFLAGS += $(COMMON_CFLAGS)
 
 autodepend-flags = -MMD -MF $(dir $*).$(notdir $*).d
arm/Makefile.common +0 -1
index 03b497b..7e5f527 100644
@@ -24,7 +24,6 @@ phys_base = $(LOADADDR)
 
 CFLAGS += -std=gnu99
 CFLAGS += -ffreestanding
-CFLAGS += -Wextra
 CFLAGS += -O2
 CFLAGS += -I $(SRCDIR)/lib -I $(SRCDIR)/lib/libfdt -I lib
 
powerpc/Makefile.common +0 -1
index db5ba62..c4df2e9 100644
@@ -19,7 +19,6 @@ all: directories $(TEST_DIR)/boot_rom.bin $(tests-all)
 
 CFLAGS += -std=gnu99
 CFLAGS += -ffreestanding
-CFLAGS += -Wextra
 CFLAGS += -O2
 CFLAGS += -I $(SRCDIR)/lib -I $(SRCDIR)/lib/libfdt -I lib
 CFLAGS += -Wa,-mregnames
s390x/Makefile +0 -1
index 470cbba..bc099da 100644
@@ -7,7 +7,6 @@ test_cases: $(tests)
 
 CFLAGS += -std=gnu99
 CFLAGS += -ffreestanding
-CFLAGS += -Wextra
 CFLAGS += -I $(SRCDIR)/lib
 CFLAGS += -O2
 CFLAGS += -march=z900
Signature · 1 line
1.8.3.1
#3 lore raw

Re: [kvm-unit-tests v2 PATCH 2/3] Replace -Wextra with a saner list of warning flags

Quoted 32 lines · Thomas Huth

Using -Wextra together with -Werror is troublesome - various versions of GCC produce suspicious or even wrong warnings with -Wextra which then become fatal errors with -Werror. For example, the current state of the kvm-unit-tests does not compile anymore with GCC 4.8.1 for s390x due to an inadequate -Wmissing-field-initializers warning. That's annoying for users who just would like to compile the kvm-unit-tests and cumbersome for the developers who have to work around these problems in the source code. So let's replace -Wextra by a saner lists of warning flags that are normally enabled by -Wextra. Since they apparently can be used for building x86, too, the flags are now also applied to the global CFLAGS instead of specifying them for the single targets only.

---
v2:
- Now that we've got COMMON_CFLAGS, the remaining flags can be added to the global CFLAGS, too
- Removed -Wsign-compare

 Makefile                | 10 +++++++---
 arm/Makefile.common     |  1 -
 powerpc/Makefile.common |  1 -
 s390x/Makefile          |  1 -
 4 files changed, 7 insertions(+), 6 deletions(-)
Makefile +0 -0
index 3ef6ea7..f12b2df 100644
@@ -50,9 +50,11 @@ include $(SRCDIR)/$(TEST_DIR)/Makefile
 cc-option = $(shell if $(CC) $(1) -S -o /dev/null -xc /dev/null \

Makefile include $(SRCDIR)/$(TEST_DIR)/Makefile · line 57

Quoted 10 lines
Makefile +5 -3
               > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi ;)
 
-COMMON_CFLAGS += -g
-COMMON_CFLAGS += $(autodepend-flags) -Wall -Wwrite-strings -Werror
-frame-pointer-flag=-f$(if $(KEEP_FRAME_POINTER),no-,)omit-frame-pointer
+COMMON_CFLAGS += -g $(autodepend-flags)
+COMMON_CFLAGS += -Wall -Wwrite-strings -Wclobbered -Wempty-body -Wuninitialized
+COMMON_CFLAGS += -Wtype-limits -Wignored-qualifiers -Wunused-but-set-parameter
+COMMON_CFLAGS += -Werror
+ rame-pointer-flag=-f$(if $(KEEP_FRAME_POINTER),no-,)omit-frame-pointer

Some finger fumbling here.

Quoted 51 lines
Makefile +2 -0
 fomit_frame_pointer := $(call cc-option, $(frame-pointer-flag), "")
 fnostack_protector := $(call cc-option, -fno-stack-protector, "")
 fnostack_protector_all := $(call cc-option, -fno-stack-protector-all, "")
@@ -67,6 +69,8 @@ COMMON_CFLAGS += $(if $(U32_LONG_FMT),-D__U32_LONG_FMT__,)
 COMMON_CFLAGS += $(fno_pic) $(no_pie)
 
 CFLAGS += $(COMMON_CFLAGS)
+CFLAGS += -Wmissing-parameter-type -Wold-style-declaration -Woverride-init
+
 CXXFLAGS += $(COMMON_CFLAGS)
 
 autodepend-flags = -MMD -MF $(dir $*).$(notdir $*).d
arm/Makefile.common +0 -1
index 03b497b..7e5f527 100644
@@ -24,7 +24,6 @@ phys_base = $(LOADADDR)
 
 CFLAGS += -std=gnu99
 CFLAGS += -ffreestanding
-CFLAGS += -Wextra
 CFLAGS += -O2
 CFLAGS += -I $(SRCDIR)/lib -I $(SRCDIR)/lib/libfdt -I lib
 
powerpc/Makefile.common +0 -1
index db5ba62..c4df2e9 100644
@@ -19,7 +19,6 @@ all: directories $(TEST_DIR)/boot_rom.bin $(tests-all)
 
 CFLAGS += -std=gnu99
 CFLAGS += -ffreestanding
-CFLAGS += -Wextra
 CFLAGS += -O2
 CFLAGS += -I $(SRCDIR)/lib -I $(SRCDIR)/lib/libfdt -I lib
 CFLAGS += -Wa,-mregnames
s390x/Makefile +0 -1
index 470cbba..bc099da 100644
@@ -7,7 +7,6 @@ test_cases: $(tests)
 
 CFLAGS += -std=gnu99
 CFLAGS += -ffreestanding
-CFLAGS += -Wextra
 CFLAGS += -I $(SRCDIR)/lib
 CFLAGS += -O2
 CFLAGS += -march=z900
Signature · 1 line
1.8.3.1
#4 lore raw

Re: [kvm-unit-tests v2 PATCH 2/3] Replace -Wextra with a saner list of warning flags

Quoted 35 lines · Andrew Jones
Quoted 34 lines · Thomas Huth

Using -Wextra together with -Werror is troublesome - various versions of GCC produce suspicious or even wrong warnings with -Wextra which then become fatal errors with -Werror. For example, the current state of the kvm-unit-tests does not compile anymore with GCC 4.8.1 for s390x due to an inadequate -Wmissing-field-initializers warning. That's annoying for users who just would like to compile the kvm-unit-tests and cumbersome for the developers who have to work around these problems in the source code. So let's replace -Wextra by a saner lists of warning flags that are normally enabled by -Wextra. Since they apparently can be used for building x86, too, the flags are now also applied to the global CFLAGS instead of specifying them for the single targets only.

---
v2:
- Now that we've got COMMON_CFLAGS, the remaining flags can be added to the global CFLAGS, too
- Removed -Wsign-compare

 Makefile                | 10 +++++++---
 arm/Makefile.common     |  1 -
 powerpc/Makefile.common |  1 -
 s390x/Makefile          |  1 -
 4 files changed, 7 insertions(+), 6 deletions(-)
Makefile +0 -0
index 3ef6ea7..f12b2df 100644
@@ -50,9 +50,11 @@ include $(SRCDIR)/$(TEST_DIR)/Makefile
 cc-option = $(shell if $(CC) $(1) -S -o /dev/null -xc /dev/null \
               > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi ;)
 
Quoted 10 lines

Makefile include $(SRCDIR)/$(TEST_DIR)/Makefile · line 57

Quoted 8 lines
Makefile +5 -3
-COMMON_CFLAGS += -g
-COMMON_CFLAGS += $(autodepend-flags) -Wall -Wwrite-strings -Werror
-frame-pointer-flag=-f$(if $(KEEP_FRAME_POINTER),no-,)omit-frame-pointer
+COMMON_CFLAGS += -g $(autodepend-flags)
+COMMON_CFLAGS += -Wall -Wwrite-strings -Wclobbered -Wempty-body -Wuninitialized
+COMMON_CFLAGS += -Wtype-limits -Wignored-qualifiers -Wunused-but-set-parameter
+COMMON_CFLAGS += -Werror
+ rame-pointer-flag=-f$(if $(KEEP_FRAME_POINTER),no-,)omit-frame-pointer

Some finger fumbling here.

Ooops, ... very well spotted ... I'll send a v3

Thomas

#5 lore raw

Re: [kvm-unit-tests v2 PATCH 2/3] Replace -Wextra with a saner list of warning flags

In reply to Thomas Huth
Quoted 13 lines · Thomas Huth

Using -Wextra together with -Werror is troublesome - various versions of GCC produce suspicious or even wrong warnings with -Wextra which then become fatal errors with -Werror. For example, the current state of the kvm-unit-tests does not compile anymore with GCC 4.8.1 for s390x due to an inadequate -Wmissing-field-initializers warning. That's annoying for users who just would like to compile the kvm-unit-tests and cumbersome for the developers who have to work around these problems in the source code. So let's replace -Wextra by a saner lists of warning flags that are normally enabled by -Wextra. Since they apparently can be used for building x86, too, the flags are now also applied to the global CFLAGS instead of specifying them for the single targets only.

Quoted 6 lines

---
v2:
- Now that we've got COMMON_CFLAGS, the remaining flags can be added to the global CFLAGS, too
- Removed -Wsign-compare

I was just doing some reading about warning types. It looks like -Wsign-compare comes with -Wall anyway.

drew

#6 lore raw

Re: [kvm-unit-tests v2 PATCH 2/3] Replace -Wextra with a saner list of warning flags

Quoted 21 lines · Andrew Jones
Quoted 13 lines · Thomas Huth

Using -Wextra together with -Werror is troublesome - various versions of GCC produce suspicious or even wrong warnings with -Wextra which then become fatal errors with -Werror. For example, the current state of the kvm-unit-tests does not compile anymore with GCC 4.8.1 for s390x due to an inadequate -Wmissing-field-initializers warning. That's annoying for users who just would like to compile the kvm-unit-tests and cumbersome for the developers who have to work around these problems in the source code. So let's replace -Wextra by a saner lists of warning flags that are normally enabled by -Wextra. Since they apparently can be used for building x86, too, the flags are now also applied to the global CFLAGS instead of specifying them for the single targets only.

Quoted 6 lines

---
v2:
- Now that we've got COMMON_CFLAGS, the remaining flags can be added to the global CFLAGS, too
- Removed -Wsign-compare

Quoted 2 lines

I was just doing some reading about warning types. It looks like -Wsign-compare comes with -Wall anyway.

According to https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html
it's only enabled by -Wall when you're compiling a C++ file, for plain C it is only enabled by -Wextra.

Thomas

maintainer
#7 lore raw

Re: [kvm-unit-tests v2 PATCH 2/3] Replace -Wextra with a saner list of warning flags

In reply to Thomas Huth
Quoted 1 line · Thomas Huth

+ rame-pointer-flag=-f$(if $(KEEP_FRAME_POINTER),no-,)omit-frame-pointer

Fixed the first character of this line.

Paolo

Quoted 2 lines

fomit_frame_pointer := $(call cc-option, $(frame-pointer-flag), "") fnostack_protector := $(call cc-option, -fno-stack-protector, "")

#8 lore raw

PATCH 3/3 Mark some local functions as "static"

In reply to Thomas Huth

Discovered while compiling kvm-unit-tests with the "-Wmissing-prototypes" parameter of GCC.

---
NB: There's more to do to make the whole code compilable with "-Wmissing-prototypes" ... not sure whether we really want all that, but at least these spots in this patch here seemed to make sense to me.

 arm/pmu.c         | 2 +-
 lib/pci-testdev.c | 4 ++--
 lib/printf.c      | 8 ++++----
 lib/x86/fwcfg.c   | 2 +-
 s390x/intercept.c | 2 +-
 5 files changed, 9 insertions(+), 9 deletions(-)
arm/pmu.c +1 -1
index 1ac6920..1de7d77 100644
@@ -276,7 +276,7 @@ static void pmccntr64_test(void)
 }
 
 /* Return FALSE if no PMU found, otherwise return TRUE */
-bool pmu_probe(void)
+static bool pmu_probe(void)
 {
 	pmu_version = get_pmu_version();
 	report_info("PMU version: %d", pmu_version);
lib/pci-testdev.c +2 -2
index 7d298e6..039bb44 100644
@@ -131,8 +131,8 @@ static bool pci_testdev_one(struct pci_test_dev_hdr *test,
 	return (int)count == nr_writes;
 }
 
-void pci_testdev_print(struct pci_test_dev_hdr *test,
-		       struct pci_testdev_ops *ops)
+static void pci_testdev_print(struct pci_test_dev_hdr *test,
+			      struct pci_testdev_ops *ops)
 {
 	bool io = (ops == &pci_testdev_io_ops);
 	int i;
lib/printf.c +4 -4
index bfe05f5..1269723 100644
@@ -30,7 +30,7 @@ static void addchar(pstream_t *p, char c)
     ++p->added;
 }
 
-void print_str(pstream_t *p, const char *s, strprops_t props)
+static void print_str(pstream_t *p, const char *s, strprops_t props)
 {
     const char *s_orig = s;
     int npad = props.npad;
@@ -58,7 +58,7 @@ void print_str(pstream_t *p, const char *s, strprops_t props)
 
 static char digits[16] = "0123456789abcdef";
 
-void print_int(pstream_t *ps, long long n, int base, strprops_t props)
+static void print_int(pstream_t *ps, long long n, int base, strprops_t props)
 {
     char buf[sizeof(long) * 3 + 2], *p = buf;
     int s = 0, i;
@@ -92,8 +92,8 @@ void print_int(pstream_t *ps, long long n, int base, strprops_t props)
     print_str(ps, buf, props);
 }
 
-void print_unsigned(pstream_t *ps, unsigned long long n, int base,
-		    strprops_t props)
+static void print_unsigned(pstream_t *ps, unsigned long long n, int base,
+			   strprops_t props)
 {
     char buf[sizeof(long) * 3 + 3], *p = buf;
     int i;
lib/x86/fwcfg.c +1 -1
index e2cdd15..c52b445 100644
@@ -3,7 +3,7 @@
 
 static struct spinlock lock;
 
-uint64_t fwcfg_get_u(uint16_t index, int bytes)
+static uint64_t fwcfg_get_u(uint16_t index, int bytes)
 {
     uint64_t r = 0;
     uint8_t b;
s390x/intercept.c +1 -1
index 9766289..59e5fca 100644
@@ -182,7 +182,7 @@ struct {
 	{ NULL, NULL, false }
 };
 
-void parse_intercept_test_args(int argc, char **argv)
+static void parse_intercept_test_args(int argc, char **argv)
 {
 	int i, ti;
 	bool run_all = true;
Signature · 1 line
1.8.3.1
maintainer
#9 lore raw

Re: [kvm-unit-tests PATCH 3/3] Mark some local functions as "static"

Quoted 9 lines · Thomas Huth

Discovered while compiling kvm-unit-tests with the "-Wmissing-prototypes" parameter of GCC.

---
NB: There's more to do to make the whole code compilable with "-Wmissing-prototypes" ... not sure whether we really want all that, but at least these spots in this patch here seemed to make sense to me.

Yes, I think we want that.

Paolo

maintainer Applied
#10 lore raw
In reply to Thomas Huth
Quoted 10 lines · Thomas Huth

Two patches to get rid of -Wextra and use other warning flags globally instead, and an additional third patch to make some functions "static" (to be able to compile the files with the "-Wmissing-prototypes" parameter)

Thomas Huth (3):
Move flags that are shared between C and C++ into COMMON_CFLAGS Replace -Wextra with a saner list of warning flags Mark some local functions as "static"

Quoted 13 lines
 Makefile                | 27 ++++++++++++++++-----------
 arm/Makefile.common     |  1 -
 arm/pmu.c               |  2 +-
 lib/pci-testdev.c       |  4 ++--
 lib/printf.c            |  8 ++++----
 lib/x86/fwcfg.c         |  2 +-
 powerpc/Makefile.common |  1 -
 s390x/Makefile          |  1 -
 s390x/intercept.c       |  2 +-
 x86/Makefile.common     |  4 ++--
 x86/Makefile.x86_64     |  2 +-
 11 files changed, 28 insertions(+), 26 deletions(-)

Applied, thanks.

Paolo