-
Notifications
You must be signed in to change notification settings - Fork 369
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
[analyze] [CTU] Add support for pch paramteres of clang-extdef-mapping #3707
base: master
Are you sure you want to change the base?
Conversation
da76d5f
to
9808e51
Compare
""" | ||
try: | ||
return bool(util.strtobool( | ||
os.environ['CC_TEST_FORCE_EXTDEF_MAPPING_CAN_READ_PCH'])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bruntib TODO set a JIRA ticket to turn this variable on before our next internal release, when we rebase Clang.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be done before the PR is merged.
Ping |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically it looks good to me, though, it's not clear why relative/absolute paths matter. Maybe it would be worth for a comment about its reasons.
analyzer/codechecker_analyzer/analyzers/clangsa/ctu_autodetection.py
Outdated
Show resolved
Hide resolved
Thanks for the review! Relative/absolute paths matter because the "on-demand" and the "pch" based CTU uses the paths differently. This is documented in
|
9808e51
to
a5ce565
Compare
Ping |
Ping @Szelethus |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This absolutely cannot go in without a proper PR description and commit message. Please make the review, and the subsequent archeology easier.
Does this have a corresponding LLVM commit and/or phabricator revision? Is there an issue or something for this? Why do we need this? Whats to gain?
This patch is about supporting https://reviews.llvm.org/D128704 from Clang. When doing CTU analysis setup we parse the .cpp to get an .ast and then With this patch we can now run clang-extdef-mapping directly on |
BTW, the commit message refers to an issue that describes the meaning of this PR: |
# Make relative path out of absolute. | ||
path = path[1:] if path[0] == os.sep else path | ||
|
||
# If clang-extdef-mapping can read a pch then the file entry already has | ||
# the .ast suffix. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this something worth assert
in then?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, because there is another case we want to support: when the clang-extdef-mapping cannot read a pch (i.e. older Clang).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is not what the comment says. It says "Can read pch => entry already has the .ast suffix". That is assertable, not that the entry has an .ast suffix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand. In this line, we add a the ".ast" suffix for the path, but only when necessary.
@@ -138,8 +138,12 @@ def __get_ctu_pre_analysis_cmds(self, action): | |||
cmds.append(' '.join(cmd)) | |||
|
|||
# Get command to create CTU index file. | |||
# FIXME Even if clang-extdef-mapping supports pch files as parameters, | |||
# feed the source files rather. This way, the below 'sed' command is | |||
# still meaningful. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You lost me here a little. What is the context?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately, there is a legacy technical debt here: The makefile generation implementation in makefile.py
diverges and uses its own implementation for generating the ext-def-mapping file. E.g., Instead of using a generic version of ast-dump_path
, it uses sed
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The FIXME states the current hack, or what the fix should be? I'm not in the clear. Shouldn't the FIXME state that we should use the ast_dump_path
method? What is preventing us from doing it? Why does this divergence exist?
Also, what you wrote here could be in the code as well, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, maybe this fixme should simply be in the documentation for get_extdef_mapping_cmd
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The FIXME states the current hack, or what the fix should be? I'm not in the clear.
makefile.py
had been architectured with a technical debt.
Shouldn't the FIXME state that we should use the ast_dump_path method?
Ok, I am updating the comment with that.
What is preventing us from doing it? Why does this divergence exist?
That would require further changes in makefile.py
which is out of the scope of this patch, in my opinion. Addressing the mentioned technical debt should be done in a follow up patch.
Also, what you wrote here could be in the code as well, right?
Could be, yes.
Oh, maybe this fixme should simply be in the documentation for get_extdef_mapping_cmd.
I think, this problem relates to makefile.py
and not of the ctu_manager.
""" AST-dump based analysis uses preprocessed paths, here the path prefix | ||
'ast' and the filename suffix '.ast' is added to the name of the original | ||
source file. """ | ||
|
||
# If clang-extdef-mapping can read a pch then the parameter 'path' is an | ||
# absolute path to the ast file. Let's transform that to a relative path | ||
# from the ctu-dir; that is the same format we have in the other cases. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was kind of missing the "otherwise" part. "If [....] path is [...]. Otherwise, path is [...], which is what we want".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I tried to reword this.
@@ -138,8 +138,12 @@ def __get_ctu_pre_analysis_cmds(self, action): | |||
cmds.append(' '.join(cmd)) | |||
|
|||
# Get command to create CTU index file. | |||
# FIXME Even if clang-extdef-mapping supports pch files as parameters, | |||
# feed the source files rather. This way, the below 'sed' command is | |||
# still meaningful. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The FIXME states the current hack, or what the fix should be? I'm not in the clear. Shouldn't the FIXME state that we should use the ast_dump_path
method? What is preventing us from doing it? Why does this divergence exist?
Also, what you wrote here could be in the code as well, right?
# Make relative path out of absolute. | ||
path = path[1:] if path[0] == os.sep else path | ||
|
||
# If clang-extdef-mapping can read a pch then the file entry already has | ||
# the .ast suffix. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is not what the comment says. It says "Can read pch => entry already has the .ast suffix". That is assertable, not that the entry has an .ast suffix.
def get_extdef_mapping_cmd(action, config, source, func_map_cmd): | ||
def get_extdef_mapping_cmd( | ||
action, config, source, func_map_cmd, triple_arch, | ||
for_makefile_generation): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please explain this parameter in the comments. I think I get it now -- we need to act a little different if this function is called from makefile.py -- explain why.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, added. Plus I've added some more explanatory comments to the command assembly.
@@ -138,8 +138,12 @@ def __get_ctu_pre_analysis_cmds(self, action): | |||
cmds.append(' '.join(cmd)) | |||
|
|||
# Get command to create CTU index file. | |||
# FIXME Even if clang-extdef-mapping supports pch files as parameters, | |||
# feed the source files rather. This way, the below 'sed' command is | |||
# still meaningful. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, maybe this fixme should simply be in the documentation for get_extdef_mapping_cmd
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Very nice! 🥲
# still meaningful. Unfortunately, there is a legacy technical debt | ||
# here: The makefile generation implementation in makefile.py diverges | ||
# and uses its own implementation for generating the ext-def-mapping | ||
# file. E.g., Instead of using a generic version of ast-dump_path, it |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# file. E.g., Instead of using a generic version of ast-dump_path, it | |
# file. E.g., Instead of using a generic version of ast_dump_path, it |
""" | ||
try: | ||
return bool(util.strtobool( | ||
os.environ['CC_TEST_FORCE_EXTDEF_MAPPING_CAN_READ_PCH'])) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be done before the PR is merged.
This patch is about supporting https://reviews.llvm.org/D128704 from Clang.
When doing CTU analysis setup we parse the .cpp to get an .ast and then
we run clang-extdef-mapping on the .cpp file later. This is
sub-optimal since we have to re-parse the file again.
With this patch we can now run clang-extdef-mapping directly on
the .ast file. That saves some time.
Fixes #3703