Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cmd] Do not allow ctu-ast-mode in non-CTU mode #3146

Merged
merged 2 commits into from
Jan 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions analyzer/codechecker_analyzer/cmd/analyze.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,9 +513,10 @@ def add_arguments_to_parser(parser):
action='store',
dest='ctu_ast_mode',
choices=['load-from-pch', 'parse-on-demand'],
default='parse-on-demand',
default=argparse.SUPPRESS,
gamesh411 marked this conversation as resolved.
Show resolved Hide resolved
help="Choose the way ASTs are loaded during "
"CTU analysis. Mode 'load-from-pch' "
"CTU analysis. Only available if CTU "
"mode is enabled. Mode 'load-from-pch' "
"generates PCH format serialized ASTs "
"during the 'collect' phase. Mode "
"'parse-on-demand' only generates the "
Expand All @@ -525,7 +526,8 @@ def add_arguments_to_parser(parser):
"serialized ASTs, while mode "
"'parse-on-demand' can incur some "
"runtime CPU overhead in the second "
"phase of the analysis.")
"phase of the analysis. (default: "
"parse-on-demand)")

if analyzer_types.is_statistics_capable(context):
stat_opts = parser.add_argument_group(
Expand Down Expand Up @@ -815,6 +817,11 @@ def main(args):
"""
logger.setup_logger(args.verbose if 'verbose' in args else None)

# CTU loading mode is only meaningful if CTU itself is enabled.
if 'ctu_ast_mode' in args and 'ctu_phases' not in args:
LOG.error("Analyzer option 'ctu-ast-mode' requires CTU mode enabled")
sys.exit(1)

try:
cmd_config.check_config_file(args)
except FileNotFoundError as fnerr:
Expand Down
13 changes: 10 additions & 3 deletions analyzer/codechecker_analyzer/cmd/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import argparse
import os
import shutil
import sys
import tempfile

from codechecker_analyzer import analyzer_context
Expand Down Expand Up @@ -515,9 +516,10 @@ def add_arguments_to_parser(parser):
action='store',
dest='ctu_ast_mode',
choices=['load-from-pch', 'parse-on-demand'],
default='parse-on-demand',
default=argparse.SUPPRESS,
gamesh411 marked this conversation as resolved.
Show resolved Hide resolved
help="Choose the way ASTs are loaded during "
"CTU analysis. Mode 'load-from-pch' "
"CTU analysis. Only available if CTU "
"mode is enabled. Mode 'load-from-pch' "
"generates PCH format serialized ASTs "
"during the 'collect' phase. Mode "
"'parse-on-demand' only generates the "
Expand All @@ -527,7 +529,8 @@ def add_arguments_to_parser(parser):
"serialized ASTs, while mode "
"'parse-on-demand' can incur some "
"runtime CPU overhead in the second "
"phase of the analysis.")
"phase of the analysis. (default: "
"parse-on-demand)")

if analyzer_types.is_statistics_capable(context):
stat_opts = parser.add_argument_group(
Expand Down Expand Up @@ -729,6 +732,10 @@ def main(args):

logger.setup_logger(args.verbose if 'verbose' in args else None)

if 'ctu_ast_mode' in args and 'ctu_phases' not in args:
LOG.error("Analyzer option 'ctu-ast-mode' requires CTU mode enabled")
sys.exit(1)

def __update_if_key_exists(source, target, key):
"""Append the source Namespace's element with 'key' to target with
the same key, but only if it exists."""
Expand Down
11 changes: 11 additions & 0 deletions analyzer/tests/functional/ctu/test_ctu.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import shutil
import unittest

from subprocess import run
from typing import IO

from libtest import env
Expand Down Expand Up @@ -78,6 +79,16 @@ def tearDown(self):
shutil.rmtree(self.report_dir, ignore_errors=True)
os.chdir(self.__old_pwd)

@skipUnlessCTUCapable
def test_ctu_loading_mode_requires_ctu_mode(self):
""" Test ctu-ast-mode option requires ctu mode enabled. """
cmd = [self._codechecker_cmd, 'analyze', '-o', self.report_dir,
'--analyzers', 'clangsa', '--ctu-ast-mode=load-from-pch',
self.buildlog]

self.assertEqual(1,
run(cmd, cwd=self.test_dir, env=self.env).returncode)

@skipUnlessCTUCapable
def test_ctu_all_ast_dump_based(self):
""" Test full CTU AST-dump based analysis. """
Expand Down
36 changes: 18 additions & 18 deletions docs/analyzer/user_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -302,16 +302,16 @@ cross translation unit analysis arguments:
If Cross-TU analysis is enabled and fails for some
reason, try to re analyze the same translation unit
without Cross-TU enabled.
[--ctu-ast-mode {load-from-pch,parse-on-demand}]
--ctu-ast-mode {load-from-pch,parse-on-demand}
Choose the way ASTs are loaded during CTU analysis.
Mode 'load-from-pch' generates PCH format serialized
ASTs during the 'collect' phase. Mode 'parse-on-
demand' only generates the invocations needed to parse
the ASTs. Mode 'load-from-pch' can use significant
disk-space for the serialized ASTs, while mode 'parse-
on-demand' can incur some runtime CPU overhead in the
second phase of the analysis. (default: parse-on-demand)
Choose the way ASTs are loaded during CTU analysis. Only
available if CTU mode is enabled. Mode 'load-from-pch'
generates PCH format serialized ASTs during the
'collect' phase. Mode 'parse-on-demand' only generates
the invocations needed to parse the ASTs. Mode
'load-from-pch' can use significant disk-space for the
serialized ASTs, while mode 'parse-on-demand' can incur
some runtime CPU overhead in the second phase of the
analysis. (default: parse-on-demand)

checker configuration:

Expand Down Expand Up @@ -1441,16 +1441,16 @@ cross translation unit analysis arguments:
analysis, using already available extra files in
'<OUTPUT_DIR>/ctu-dir'. (These files will not be
cleaned up in this mode.)

--ctu-ast-mode {load-from-pch,parse-on-demand}
Choose the way ASTs are loaded during CTU analysis.
Mode 'load-from-pch' generates PCH format serialized
ASTs during the 'collect' phase. Mode 'parse-on-
demand' only generates the invocations needed to parse
the ASTs. Mode 'load-from-pch' can use significant
disk-space for the serialized ASTs, while mode 'parse-
on-demand' can incur some runtime CPU overhead in the
second phase of the analysis. (default: parse-on-demand)
Choose the way ASTs are loaded during CTU analysis. Only
available if CTU mode is enabled. Mode 'load-from-pch'
generates PCH format serialized ASTs during the
'collect' phase. Mode 'parse-on-demand' only generates
the invocations needed to parse the ASTs. Mode
'load-from-pch' can use significant disk-space for the
serialized ASTs, while mode 'parse-on-demand' can incur
some runtime CPU overhead in the second phase of the
analysis. (default: parse-on-demand)
```

### Statistical analysis mode <a name="statistical"></a>
Expand Down