Skip to content

Commit

Permalink
Visual Studio Address Sanitizer updates
Browse files Browse the repository at this point in the history
* Allow address sanitizer for Visual Studio 2019 version 16.9

Address Sanitizer was first supported with the current syntax in Visual
Studio 16.9.0 (cl version 19.28.29910).

* VS: Convert /fsanitize=address to project file setting
  • Loading branch information
peterh authored May 15, 2021
1 parent ab0b727 commit be015a3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 10 additions & 0 deletions mesonbuild/backend/vs2010backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ def generate(self):
self.buildtype = self.environment.coredata.get_option(OptionKey('buildtype'))
self.optimization = self.environment.coredata.get_option(OptionKey('optimization'))
self.debug = self.environment.coredata.get_option(OptionKey('debug'))
try:
self.sanitize = self.environment.coredata.get_option(OptionKey('b_sanitize'))
except MesonException:
self.sanitize = 'none'
sln_filename = os.path.join(self.environment.get_build_dir(), self.build.project_name + '.sln')
projlist = self.generate_projects()
self.gen_testproj('RUN_TESTS', os.path.join(self.environment.get_build_dir(), 'RUN_TESTS.vcxproj'))
Expand Down Expand Up @@ -613,6 +617,8 @@ def is_argument_with_msbuild_xml_entry(self, entry):
# Remove arguments that have a top level XML entry so
# they are not used twice.
# FIXME add args as needed.
if entry[1:].startswith('fsanitize'):
return True
return entry[1:].startswith('M')

def add_additional_options(self, lang, parent_node, file_args):
Expand Down Expand Up @@ -767,6 +773,7 @@ def gen_vcxproj(self, target, ofname, guid):
build_args = compiler.get_buildtype_args(self.buildtype)
build_args += compiler.get_optimization_args(self.optimization)
build_args += compiler.get_debug_args(self.debug)
build_args += compiler.sanitizer_compile_args(self.sanitize)
buildtype_link_args = compiler.get_buildtype_linker_args(self.buildtype)
vscrt_type = self.environment.coredata.options[OptionKey('b_vscrt')]
project_name = target.name
Expand Down Expand Up @@ -842,6 +849,9 @@ def gen_vcxproj(self, target, ofname, guid):
else:
ET.SubElement(type_config, 'UseDebugLibraries').text = 'false'
ET.SubElement(clconf, 'RuntimeLibrary').text = 'MultiThreadedDLL'
# Sanitizers
if '/fsanitize=address' in build_args:
ET.SubElement(type_config, 'EnableASAN').text = 'true'
# Debug format
if '/ZI' in build_args:
ET.SubElement(clconf, 'DebugInformationFormat').text = 'EditAndContinue'
Expand Down
2 changes: 1 addition & 1 deletion mesonbuild/compilers/mixins/visualstudio.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def __init__(self, target: str):
self.machine = 'arm'
else:
self.machine = target
if mesonlib.version_compare(self.version, '>=19.29.29917'):
if mesonlib.version_compare(self.version, '>=19.28.29910'): # VS 16.9.0 includes cl 19.28.29910
self.base_options.add(mesonlib.OptionKey('b_sanitize'))
assert self.linker is not None
self.linker.machine = self.machine
Expand Down

0 comments on commit be015a3

Please sign in to comment.