예제 #1
0
def get_compile_command(action, config, source='', output=''):
    """ Generate a standardized and cleaned compile command serving as a base
    for other operations. """

    cmd = [config.analyzer_binary]

    compile_lang = action.lang

    if not has_flag('--target', cmd) and \
            action.target[compile_lang] != "":
        cmd.append("--target=" + action.target[compile_lang])

    extend_analyzer_cmd_with_resource_dir(cmd, config.compiler_resource_dir)

    cmd.extend(action.compiler_includes[compile_lang])
    cmd.append('-c')
    if not has_flag('-x', cmd):
        cmd.extend(['-x', action.lang])
    cmd.extend(config.analyzer_extra_arguments)
    cmd.extend(action.analyzer_options)
    if output:
        cmd.extend(['-o', output])
    if source:
        cmd.append(source)

    if not has_flag('-std', cmd) and not has_flag('--std', cmd):
        cmd.append(action.compiler_standard[compile_lang])

    return cmd
예제 #2
0
def build_stat_coll_cmd(action, config, source):
    """
    Build the statistics collector analysis command.
    """

    cmd = [
        config.analyzer_binary,
        '-c',
        '-x',
        action.lang,
        '--analyze',
        # Do not warn about the unused gcc/g++ arguments.
        '-Qunused-arguments',
        '--analyzer-output',
        'text'
    ]

    for plugin in config.analyzer_plugins:
        cmd.extend([
            "-Xclang", "-plugin", "-Xclang", "checkercfg", "-Xclang", "-load",
            "-Xclang", plugin
        ])

    cmd.extend(['-Xclang', '-analyzer-opt-analyze-headers'])

    cmd.extend(config.analyzer_extra_arguments)
    cmd.extend(action.analyzer_options)

    # Enable the statistics collector checkers only.
    collector_checkers = []
    for checker_name, _ in config.checks().items():
        if SpecialReturnValueCollector.checker_collect in checker_name:
            collector_checkers.append(checker_name)

        if ReturnValueCollector.checker_collect in checker_name:
            collector_checkers.append(checker_name)

    if not collector_checkers:
        LOG.debug('No available statistics collector checkers were found')
        return [], False

    for coll_check in collector_checkers:
        cmd.extend(['-Xclang', '-analyzer-checker=' + coll_check])

    if action.target != "":
        cmd.append("--target=" + action.target)
    extend_analyzer_cmd_with_resource_dir(cmd, config.compiler_resource_dir)
    cmd.extend(action.compiler_includes)

    if source:
        cmd.append(source)
    return cmd, True
예제 #3
0
def get_compile_command(action, config, source='', output=''):
    """ Generate a standardized and cleaned compile command serving as a base
    for other operations. """

    cmd = [config.analyzer_binary]
    if action.target != "":
        cmd.append("--target=" + action.target)
    extend_analyzer_cmd_with_resource_dir(cmd, config.compiler_resource_dir)
    cmd.extend(action.compiler_includes)
    cmd.append('-c')
    cmd.extend(['-x', action.lang])
    cmd.extend(config.analyzer_extra_arguments)
    cmd.extend(action.analyzer_options)
    if output:
        cmd.extend(['-o', output])
    if source:
        cmd.append(source)

    if all(not opt.startswith('-std=') for opt in action.analyzer_options):
        cmd.append(action.compiler_standard)

    return cmd
예제 #4
0
    def construct_analyzer_cmd(self, result_handler):
        """
        """
        try:
            config = self.config_handler

            analyzer_cmd = [config.analyzer_binary]

            # Disable all checkers except compiler warnings by default.
            # The latest clang-tidy (3.9) release enables clang static analyzer
            # checkers by default. They must be disabled explicitly.
            # For clang compiler warnings a correspoding
            # clang-diagnostic error is generated by Clang tidy.
            # They can be disabled by this glob -clang-diagnostic-*
            checkers_cmdline = '-*,-clang-analyzer-*,clang-diagnostic-*'

            compiler_warnings = []

            # Config handler stores which checkers are enabled or disabled.
            for checker_name, value in config.checks().items():
                enabled, _ = value

                # Checker name is a compiler warning.
                if checker_name.startswith('W'):
                    warning_name = checker_name[4:] if \
                        checker_name.startswith('Wno-') else checker_name[1:]

                    if enabled:
                        compiler_warnings.append('-W' + warning_name)
                    else:
                        compiler_warnings.append('-Wno-' + warning_name)

                    continue

                if enabled:
                    checkers_cmdline += ',' + checker_name
                else:
                    checkers_cmdline += ',-' + checker_name

            analyzer_cmd.append("-checks='%s'" % checkers_cmdline.lstrip(','))

            analyzer_cmd.extend(config.analyzer_extra_arguments)

            if config.checker_config:
                analyzer_cmd.append('-config="' + config.checker_config + '"')

            analyzer_cmd.append(self.source_file)

            analyzer_cmd.append("--")

            analyzer_cmd.append('-Qunused-arguments')

            # Enable these compiler warnings by default.
            analyzer_cmd.extend(['-Wall', '-Wextra'])

            compile_lang = self.buildaction.lang

            if not has_flag('-x', analyzer_cmd):
                analyzer_cmd.extend(['-x', compile_lang])

            if not has_flag('--target', analyzer_cmd) and \
                    self.buildaction.target.get(compile_lang, "") != "":
                analyzer_cmd.append(
                    "--target=" +
                    self.buildaction.target.get(compile_lang, ""))

            analyzer_cmd.extend(self.buildaction.analyzer_options)

            env.extend_analyzer_cmd_with_resource_dir(
                analyzer_cmd, config.compiler_resource_dir)

            analyzer_cmd.extend(
                self.buildaction.compiler_includes[compile_lang])

            if not has_flag('-std', analyzer_cmd) and not \
                    has_flag('--std', analyzer_cmd):
                analyzer_cmd.append(
                    self.buildaction.compiler_standard.get(compile_lang, ""))

            analyzer_cmd.extend(compiler_warnings)

            return analyzer_cmd

        except Exception as ex:
            LOG.error(ex)
            return []
예제 #5
0
    def construct_analyzer_cmd(self, result_handler):
        """
        Called by the analyzer method.
        Construct the analyzer command.
        """
        try:
            # Get an output file from the result handler.
            analyzer_output_file = result_handler.analyzer_result_file

            # Get the checkers list from the config_handler.
            # Checker order matters.
            config = self.config_handler

            analyzer_cmd = [
                config.analyzer_binary,
                '--analyze',
                # Do not warn about the unused gcc/g++ arguments.
                '-Qunused-arguments',
                # Turn off clang hardcoded checkers list.
                '--analyzer-no-default-checks'
            ]

            for plugin in config.analyzer_plugins:
                analyzer_cmd.extend([
                    "-Xclang", "-plugin", "-Xclang", "checkercfg", "-Xclang",
                    "-load", "-Xclang", plugin
                ])

            analyzer_mode = 'plist-multi-file'
            analyzer_cmd.extend([
                '-Xclang', '-analyzer-opt-analyze-headers', '-Xclang',
                '-analyzer-output=' + analyzer_mode, '-o', analyzer_output_file
            ])

            # Expand macros in plist output on the bug path.
            analyzer_cmd.extend([
                '-Xclang', '-analyzer-config', '-Xclang', 'expand-macros=true'
            ])

            # Checker configuration arguments needs to be set before
            # the checkers.
            if self.__checker_configs:
                for cfg in self.__checker_configs:
                    analyzer_cmd.extend(cfg)

            # Config handler stores which checkers are enabled or disabled.
            for checker_name, value in config.checks().items():
                enabled, _ = value
                if enabled:
                    analyzer_cmd.extend(
                        ['-Xclang', '-analyzer-checker=' + checker_name])
                else:
                    analyzer_cmd.extend([
                        '-Xclang', '-analyzer-disable-checker=' + checker_name
                    ])

            # Needed for the iterator checkers.
            analyzer_cmd.extend([
                '-Xclang', '-analyzer-config', '-Xclang',
                'aggressive-binary-operation-simplification'
                '=true'
            ])

            # Enable the z3 solver backend.
            if config.enable_z3:
                analyzer_cmd.extend(['-Xclang', '-analyzer-constraints=z3'])

            if config.enable_z3_refutation and not config.enable_z3:
                analyzer_cmd.extend([
                    '-Xclang', '-analyzer-config', '-Xclang',
                    'crosscheck-with-z3=true'
                ])

            if config.ctu_dir and not self.__disable_ctu:
                analyzer_cmd.extend([
                    '-Xclang', '-analyzer-config', '-Xclang',
                    'experimental-enable-naive-ctu-analysis=true', '-Xclang',
                    '-analyzer-config', '-Xclang',
                    'ctu-dir=' + self.get_ctu_dir()
                ])
                ctu_display_progress = config.ctu_capability.display_progress
                if ctu_display_progress:
                    analyzer_cmd.extend(ctu_display_progress)

            compile_lang = self.buildaction.lang
            if not has_flag('-x', analyzer_cmd):
                analyzer_cmd.extend(['-x', compile_lang])

            if not has_flag('--target', analyzer_cmd) and \
                    self.buildaction.target.get(compile_lang, "") != "":
                analyzer_cmd.append("--target=" +
                                    self.buildaction.target.get(compile_lang))

            if not has_flag('-std', analyzer_cmd) and \
                    self.buildaction.compiler_standard.get(compile_lang, "") \
                    != "":
                analyzer_cmd.append(
                    self.buildaction.compiler_standard[compile_lang])

            analyzer_cmd.extend(config.analyzer_extra_arguments)

            analyzer_cmd.extend(self.buildaction.analyzer_options)

            env.extend_analyzer_cmd_with_resource_dir(
                analyzer_cmd, config.compiler_resource_dir)

            analyzer_cmd.extend(
                self.buildaction.compiler_includes[compile_lang])

            analyzer_cmd.append(self.source_file)

            return analyzer_cmd

        except Exception as ex:
            LOG.error(ex)
            return []