Skip to content

Commit 4b30e56

Browse files
committedAug 26, 2015
[libcxx] Add special warning flag detection logic to compiler.py
Summary: Detecting `-Wno-<warning>` flags can be tricky with GCC (See https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html). This patch adds a special `addWarningFlagIfSupported(<flag>)` method to the test compiler object that can be used to add warning flags. The goal of this patch is to help get the test suite running with more warnings. Reviewers: danalbert, jroelofs Subscribers: cfe-commits Differential Revision: http://reviews.llvm.org/D11333 llvm-svn: 246069
1 parent 70192a9 commit 4b30e56

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed
 

‎libcxx/test/libcxx/compiler.py

+25
Original file line numberDiff line numberDiff line change
@@ -161,3 +161,28 @@ def addCompileFlagIfSupported(self, flag):
161161
return True
162162
else:
163163
return False
164+
165+
def addWarningFlagIfSupported(self, flag):
166+
"""
167+
addWarningFlagIfSupported - Add a warning flag if the compiler
168+
supports it. Unlike addCompileFlagIfSupported, this function detects
169+
when "-Wno-<warning>" flags are unsupported. If flag is a
170+
"-Wno-<warning>" GCC will not emit an unknown option diagnostic unless
171+
another error is triggered during compilation.
172+
"""
173+
assert isinstance(flag, str)
174+
if not flag.startswith('-Wno-'):
175+
return self.addCompileFlagIfSupported(flag)
176+
flags = ['-Werror', flag]
177+
cmd = self.compileCmd('-', os.devnull, flags)
178+
# Remove '-v' because it will cause the command line invocation
179+
# to be printed as part of the error output.
180+
# TODO(EricWF): Are there other flags we need to worry about?
181+
if '-v' in cmd:
182+
cmd.remove('-v')
183+
out, err, rc = lit.util.executeCommand(cmd, input='#error\n')
184+
assert rc != 0
185+
if flag in err:
186+
return False
187+
self.compile_flags += [flag]
188+
return True

‎libcxx/test/libcxx/test/config.py

+5-6
Original file line numberDiff line numberDiff line change
@@ -574,16 +574,15 @@ def configure_warnings(self):
574574
'-D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER',
575575
'-Wall', '-Werror'
576576
]
577-
self.cxx.addCompileFlagIfSupported('-Wno-attributes')
578-
if self.cxx.type == 'clang' or self.cxx.type == 'apple-clang':
579-
self.cxx.addCompileFlagIfSupported('-Wno-pessimizing-move')
580-
self.cxx.addCompileFlagIfSupported('-Wno-c++11-extensions')
581-
self.cxx.addCompileFlagIfSupported('-Wno-user-defined-literals')
577+
self.cxx.addWarningFlagIfSupported('-Wno-attributes')
578+
self.cxx.addWarningFlagIfSupported('-Wno-pessimizing-move')
579+
self.cxx.addWarningFlagIfSupported('-Wno-c++11-extensions')
580+
self.cxx.addWarningFlagIfSupported('-Wno-user-defined-literals')
582581
std = self.get_lit_conf('std', None)
583582
if std in ['c++98', 'c++03']:
584583
# The '#define static_assert' provided by libc++ in C++03 mode
585584
# causes an unused local typedef whenever it is used.
586-
self.cxx.addCompileFlagIfSupported('-Wno-unused-local-typedef')
585+
self.cxx.addWarningFlagIfSupported('-Wno-unused-local-typedef')
587586

588587
def configure_sanitizer(self):
589588
san = self.get_lit_conf('use_sanitizer', '').strip()

0 commit comments

Comments
 (0)
Please sign in to comment.