Disable warning flags when running .fail.cpp tests.

Increasingly the .fail.cpp tests are written using -verify, making them
sensitive to the exact diagnostics generated by the compiler. To prevent
additional diagnostics from being generated, and causing the tests to fail,
this patch removes the warning flags when compiling those tests.




git-svn-id: https://llvm.org/svn/llvm-project/libcxx/trunk@276208 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Eric Fiselier
2016-07-20 23:37:28 +00:00
parent b5bdc070f2
commit 2edb326926
3 changed files with 57 additions and 26 deletions

View File

@@ -13,11 +13,17 @@ import libcxx.util
class CXXCompiler(object): class CXXCompiler(object):
CM_Default = 0
CM_PreProcess = 1
CM_Compile = 2
CM_Link = 3
def __init__(self, path, flags=None, compile_flags=None, link_flags=None, def __init__(self, path, flags=None, compile_flags=None, link_flags=None,
use_ccache=False): use_ccache=False):
self.path = path self.path = path
self.flags = list(flags or []) self.flags = list(flags or [])
self.compile_flags = list(compile_flags or []) self.compile_flags = list(compile_flags or [])
self.warning_flags = []
self.link_flags = list(link_flags or []) self.link_flags = list(link_flags or [])
self.use_ccache = use_ccache self.use_ccache = use_ccache
self.type = None self.type = None
@@ -47,10 +53,13 @@ class CXXCompiler(object):
self.type = compiler_type self.type = compiler_type
self.version = (major_ver, minor_ver, patchlevel) self.version = (major_ver, minor_ver, patchlevel)
def _basicCmd(self, source_files, out, is_link=False, input_is_cxx=False, def _basicCmd(self, source_files, out, mode=CM_Default, flags=[],
disable_ccache=False): input_is_cxx=False,
enable_warnings=True, disable_ccache=False):
cmd = [] cmd = []
if self.use_ccache and not disable_ccache and not is_link: if self.use_ccache and not disable_ccache \
and not mode == self.CM_Link \
and not mode == self.CM_PreProcess:
cmd += ['ccache'] cmd += ['ccache']
cmd += [self.path] cmd += [self.path]
if out is not None: if out is not None:
@@ -63,30 +72,45 @@ class CXXCompiler(object):
cmd += [source_files] cmd += [source_files]
else: else:
raise TypeError('source_files must be a string or list') raise TypeError('source_files must be a string or list')
if mode == self.CM_PreProcess:
cmd += ['-E']
elif mode == self.CM_Compile:
cmd += ['-c']
cmd += self.flags
if mode != self.CM_Link:
cmd += self.compile_flags
if enable_warnings:
cmd += self.warning_flags
if mode != self.CM_PreProcess and mode != self.CM_Compile:
cmd += self.link_flags
cmd += flags
return cmd return cmd
def preprocessCmd(self, source_files, out=None, flags=[]): def _getWarningFlags(self, enable_warnings=True):
cmd = self._basicCmd(source_files, out, input_is_cxx=True, return self.warning_flags if enable_warnings else []
disable_ccache=True) + ['-E']
cmd += self.flags + self.compile_flags + flags def preprocessCmd(self, source_files, out=None, flags=[],
return cmd enable_warnings=True):
return self._basicCmd(source_files, out, flags=flags,
mode=self.CM_PreProcess,
enable_warnings=enable_warnings,
input_is_cxx=True)
def compileCmd(self, source_files, out=None, flags=[], def compileCmd(self, source_files, out=None, flags=[],
disable_ccache=False): disable_ccache=False, enable_warnings=True):
cmd = self._basicCmd(source_files, out, input_is_cxx=True, return self._basicCmd(source_files, out, flags=flags,
mode=self.CM_Compile,
input_is_cxx=True,
enable_warnings=enable_warnings,
disable_ccache=disable_ccache) + ['-c'] disable_ccache=disable_ccache) + ['-c']
cmd += self.flags + self.compile_flags + flags
return cmd
def linkCmd(self, source_files, out=None, flags=[]): def linkCmd(self, source_files, out=None, flags=[]):
cmd = self._basicCmd(source_files, out, is_link=True) return self._basicCmd(source_files, out, mode=self.CM_Link)
cmd += self.flags + self.link_flags + flags
return cmd
def compileLinkCmd(self, source_files, out=None, flags=[]): def compileLinkCmd(self, source_files, out=None, flags=[],
cmd = self._basicCmd(source_files, out, is_link=True) enable_warnings=True):
cmd += self.flags + self.compile_flags + self.link_flags + flags return self._basicCmd(source_files, out, flags=flags,
return cmd enable_warnings=enable_warnings)
def preprocess(self, source_files, out=None, flags=[], env=None, cwd=None): def preprocess(self, source_files, out=None, flags=[], env=None, cwd=None):
cmd = self.preprocessCmd(source_files, out, flags) cmd = self.preprocessCmd(source_files, out, flags)
@@ -94,9 +118,10 @@ class CXXCompiler(object):
return cmd, out, err, rc return cmd, out, err, rc
def compile(self, source_files, out=None, flags=[], env=None, cwd=None, def compile(self, source_files, out=None, flags=[], env=None, cwd=None,
disable_ccache=False): disable_ccache=False, enable_warnings=True):
cmd = self.compileCmd(source_files, out, flags, cmd = self.compileCmd(source_files, out, flags,
disable_ccache=disable_ccache) disable_ccache=disable_ccache,
enable_warnings=enable_warnings)
out, err, rc = lit.util.executeCommand(cmd, env=env, cwd=cwd) out, err, rc = lit.util.executeCommand(cmd, env=env, cwd=cwd)
return cmd, out, err, rc return cmd, out, err, rc
@@ -189,9 +214,12 @@ class CXXCompiler(object):
""" """
assert isinstance(flag, str) assert isinstance(flag, str)
if not flag.startswith('-Wno-'): if not flag.startswith('-Wno-'):
return self.addCompileFlagIfSupported(flag) if self.hasCompileFlag(flag):
self.warning_flags += [flag]
return True
return False
flags = ['-Werror', flag] flags = ['-Werror', flag]
cmd = self.compileCmd('-', os.devnull, flags) cmd = self.compileCmd('-', os.devnull, flags, enable_warnings=False)
# Remove '-v' because it will cause the command line invocation # Remove '-v' because it will cause the command line invocation
# to be printed as part of the error output. # to be printed as part of the error output.
# TODO(EricWF): Are there other flags we need to worry about? # TODO(EricWF): Are there other flags we need to worry about?
@@ -201,5 +229,5 @@ class CXXCompiler(object):
assert rc != 0 assert rc != 0
if flag in err: if flag in err:
return False return False
self.compile_flags += [flag] self.warning_flags += [flag]
return True return True

View File

@@ -120,6 +120,8 @@ class Configuration(object):
self.lit_config.note('Using flags: %s' % self.cxx.flags) self.lit_config.note('Using flags: %s' % self.cxx.flags)
self.lit_config.note('Using compile flags: %s' self.lit_config.note('Using compile flags: %s'
% self.cxx.compile_flags) % self.cxx.compile_flags)
if len(self.cxx.warning_flags):
self.lit_config.note('Using warnings: %s' % self.cxx.warning_flags)
self.lit_config.note('Using link flags: %s' % self.cxx.link_flags) self.lit_config.note('Using link flags: %s' % self.cxx.link_flags)
# Print as list to prevent "set([...])" from being printed. # Print as list to prevent "set([...])" from being printed.
self.lit_config.note('Using available_features: %s' % self.lit_config.note('Using available_features: %s' %
@@ -569,7 +571,7 @@ class Configuration(object):
def configure_warnings(self): def configure_warnings(self):
enable_warnings = self.get_lit_bool('enable_warnings', False) enable_warnings = self.get_lit_bool('enable_warnings', False)
if enable_warnings: if enable_warnings:
self.cxx.compile_flags += [ self.cxx.warning_flags += [
'-D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER', '-D_LIBCPP_HAS_NO_PRAGMA_SYSTEM_HEADER',
'-Wall', '-Wextra', '-Werror' '-Wall', '-Wextra', '-Werror'
] ]

View File

@@ -174,7 +174,8 @@ class LibcxxTestFormat(object):
'-ferror-limit=1024'] '-ferror-limit=1024']
cmd, out, err, rc = self.cxx.compile(source_path, out=os.devnull, cmd, out, err, rc = self.cxx.compile(source_path, out=os.devnull,
flags=extra_flags, flags=extra_flags,
disable_ccache=True) disable_ccache=True,
enable_warnings=False)
expected_rc = 0 if use_verify else 1 expected_rc = 0 if use_verify else 1
if rc == expected_rc: if rc == expected_rc:
return lit.Test.PASS, '' return lit.Test.PASS, ''