Raw
1 ifndef COMPILER_FEATURES
2 COMPILER_FEATURES := $(shell ./tools/detect-compiler $(CC))
3 endif
4
5 ifeq ($(filter no-error,$(DEVOPTS)),)
6 DEVELOPER_CFLAGS += -Werror
7 SPARSE_FLAGS += -Wsparse-error
8 endif
9
10 DEVELOPER_CFLAGS += -Wall
11 ifeq ($(filter no-pedantic,$(DEVOPTS)),)
12 DEVELOPER_CFLAGS += -pedantic
13 ifneq ($(or $(filter gcc5,$(COMPILER_FEATURES)),$(filter clang4,$(COMPILER_FEATURES))),)
14 DEVELOPER_CFLAGS += -Wpedantic
15 ifneq ($(filter gcc10,$(COMPILER_FEATURES)),)
16 ifeq ($(uname_S),MINGW)
17 DEVELOPER_CFLAGS += -Wno-pedantic-ms-format
18 endif
19 endif
20 endif
21 endif
22
23 ifneq ($(uname_S),FreeBSD)
24 ifneq ($(or $(filter gcc6,$(COMPILER_FEATURES)),$(filter clang7,$(COMPILER_FEATURES))),)
25 DEVELOPER_CFLAGS += -std=gnu99
26 endif
27 else
28 # FreeBSD cannot limit to C99 because its system headers unconditionally
29 # rely on C11 features.
30 endif
31
32 DEVELOPER_CFLAGS += -Wdeclaration-after-statement
33 DEVELOPER_CFLAGS += -Wformat-security
34 DEVELOPER_CFLAGS += -Wold-style-definition
35 DEVELOPER_CFLAGS += -Woverflow
36 DEVELOPER_CFLAGS += -Wpointer-arith
37 DEVELOPER_CFLAGS += -Wstrict-prototypes
38 DEVELOPER_CFLAGS += -Wunused
39 DEVELOPER_CFLAGS += -Wvla
40 DEVELOPER_CFLAGS += -Wwrite-strings
41 DEVELOPER_CFLAGS += -fno-common
42 DEVELOPER_CFLAGS += -Wunreachable-code
43
44 ifneq ($(filter clang9,$(COMPILER_FEATURES)),)
45 DEVELOPER_CFLAGS += -Wcomma
46 endif
47
48 ifneq ($(filter clang4,$(COMPILER_FEATURES)),)
49 DEVELOPER_CFLAGS += -Wtautological-constant-out-of-range-compare
50 endif
51
52 ifneq ($(or $(filter gcc6,$(COMPILER_FEATURES)),$(filter clang4,$(COMPILER_FEATURES))),)
53 DEVELOPER_CFLAGS += -Wextra
54 # if a function is public, there should be a prototype and the right
55 # header file should be included. If not, it should be static.
56 DEVELOPER_CFLAGS += -Wmissing-prototypes
57 ifeq ($(filter extra-all,$(DEVOPTS)),)
58 # These are disabled because we have these all over the place.
59 DEVELOPER_CFLAGS += -Wno-empty-body
60 DEVELOPER_CFLAGS += -Wno-missing-field-initializers
61 endif
62 endif
63
64 # uninitialized warnings on gcc 4.9.2 in xdiff/xdiffi.c and config.c
65 # not worth fixing since newer compilers correctly stop complaining
66 #
67 # Likewise, gcc older than 4.9 complains about initializing a
68 # struct-within-a-struct using just "{ 0 }"
69 ifneq ($(filter gcc4,$(COMPILER_FEATURES)),)
70 ifeq ($(filter gcc5,$(COMPILER_FEATURES)),)
71 DEVELOPER_CFLAGS += -Wno-uninitialized
72 DEVELOPER_CFLAGS += -Wno-missing-braces
73 endif
74 endif
75
76 # Old versions of clang complain about initializing a
77 # struct-within-a-struct using just "{0}" rather than "{{0}}". This
78 # error is considered a false-positive and not worth fixing, because
79 # new clang versions do not, so just disable it.
80 #
81 # The "bug" was fixed in upstream clang 9.
82 #
83 # Complicating this is that versions of clang released by Apple have
84 # their own version numbers (associated with the corresponding version
85 # of XCode) unrelated to the official clang version numbers.
86 #
87 # The bug was fixed in Apple clang 12.
88 #
89 ifneq ($(filter clang1,$(COMPILER_FEATURES)),) # if we are using clang
90 ifeq ($(uname_S),Darwin) # if we are on darwin
91 ifeq ($(filter clang12,$(COMPILER_FEATURES)),) # if version < 12
92 DEVELOPER_CFLAGS += -Wno-missing-braces
93 endif
94 else # not darwin
95 ifeq ($(filter clang9,$(COMPILER_FEATURES)),) # if version < 9
96 DEVELOPER_CFLAGS += -Wno-missing-braces
97 endif
98 endif
99 endif
100
101 # glibc 2.43 headers unconditionally use _Generic even when we ask the
102 # compiler to stick to -std=gnu99 and unlike GCC, clang lacks a
103 # workaround to squelch warnings from system headers.
104 ifneq ($(filter clang1,$(COMPILER_FEATURES)),) # if we are using clang
105 DEVELOPER_CFLAGS += -Wno-c11-extensions
106 endif
107
108 # https://bugzilla.redhat.com/show_bug.cgi?id=2075786
109 ifneq ($(filter gcc12,$(COMPILER_FEATURES)),)
110 DEVELOPER_CFLAGS += -Wno-error=stringop-overread
111 endif
112
113 GIT_TEST_PERL_FATAL_WARNINGS = YesPlease