1
0
mirror of https://github.com/facebook/zstd.git synced 2025-07-30 22:23:13 +03:00

[fuzz] Fix compiler detection & update ubsan flags

* Fix compiler version regex, which was broken for multi-digit
  versions.
* Fix compiler detection for gcc.
* Disable `pointer-overflow` instead of `integer-overflow` for gcc
  versions newer than 8.0.0.
This commit is contained in:
Nick Terrell
2021-02-19 13:11:29 -08:00
parent a2adc6df9f
commit 91e6480458

View File

@ -180,14 +180,15 @@ def compiler_version(cc, cxx):
cxx_version_bytes = subprocess.check_output([cxx, "--version"]) cxx_version_bytes = subprocess.check_output([cxx, "--version"])
compiler = None compiler = None
version = None version = None
print("{} --version:\n{}".format(cc, cc_version_bytes.decode('ascii')))
if b'clang' in cc_version_bytes: if b'clang' in cc_version_bytes:
assert(b'clang' in cxx_version_bytes) assert(b'clang' in cxx_version_bytes)
compiler = 'clang' compiler = 'clang'
elif b'gcc' in cc_version_bytes: elif b'gcc' in cc_version_bytes or b'GCC' in cc_version_bytes:
assert(b'gcc' in cxx_version_bytes or b'g++' in cxx_version_bytes) assert(b'gcc' in cxx_version_bytes or b'g++' in cxx_version_bytes)
compiler = 'gcc' compiler = 'gcc'
if compiler is not None: if compiler is not None:
version_regex = b'([0-9])+\.([0-9])+\.([0-9])+' version_regex = b'([0-9]+)\.([0-9]+)\.([0-9]+)'
version_match = re.search(version_regex, cc_version_bytes) version_match = re.search(version_regex, cc_version_bytes)
version = tuple(int(version_match.group(i)) for i in range(1, 4)) version = tuple(int(version_match.group(i)) for i in range(1, 4))
return compiler, version return compiler, version
@ -195,9 +196,9 @@ def compiler_version(cc, cxx):
def overflow_ubsan_flags(cc, cxx): def overflow_ubsan_flags(cc, cxx):
compiler, version = compiler_version(cc, cxx) compiler, version = compiler_version(cc, cxx)
if compiler == 'gcc': if compiler == 'gcc' and version < (8, 0, 0):
return ['-fno-sanitize=signed-integer-overflow'] return ['-fno-sanitize=signed-integer-overflow']
if compiler == 'clang' and version >= (5, 0, 0): if compiler == 'gcc' or (compiler == 'clang' and version >= (5, 0, 0)):
return ['-fno-sanitize=pointer-overflow'] return ['-fno-sanitize=pointer-overflow']
return [] return []