Skip to content
This repository has been archived by the owner on Mar 30, 2021. It is now read-only.

Add On-the-fly analysis support #694

Open
wants to merge 1 commit into
base: ctu-clang801
Choose a base branch
from

Conversation

gamesh411
Copy link
Collaborator

Add an option to enable on-the-fly parsing of needed ASTs during CTU
analysis. The option CTUCompilationDatabase should be a path to a
compilation database, which has all the necessary information to
generate the ASTs. In case an empty string is given, on-the-fly parsing
is disabled.

@gamesh411 gamesh411 requested a review from martong August 1, 2019 10:26
Copy link

@martong martong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice and hard work 👍

It would be really benefitial to have a lit test similar to ctu-main.cpp (with a few functions).

Other than that, could you please write a novel about the absolute and relative path difficulties? The goal is to understand the problem and the solution even after a few months...

include/clang/CrossTU/CrossTranslationUnit.h Outdated Show resolved Hide resolved
include/clang/StaticAnalyzer/Core/AnalyzerOptions.def Outdated Show resolved Hide resolved
lib/CrossTU/CrossTranslationUnit.cpp Outdated Show resolved Hide resolved
@gamesh411
Copy link
Collaborator Author

Could you plase check the new test files 'ctu-on-the-fly.c' and 'ctu-on-the-fly.cpp'. I have managed to get almost working, however there are 2 issues still reamining.

First issue:
During the analysis of sometimes the file part is entirely left off from the diagnostic. The interesting part is that Line number is OK, just the file part gets lost. This could be fixed by making the check more lenient in case of on-demand analysis (eg. not requiring that the diagnostic contains the file information).

Second issue:
Inline assembly importing fails if -std=c89 is given inside compile_commands.json for the c test (see the test RUN: lines for the contents of the compile_commands.json). If however no -std=c89 is given, then unsupported AST node error is given during the analysis (I assume that it must be the clang tool which parses the file).

What are your thoughts?

Thanks

Copy link

@martong martong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First issue:
During the analysis of sometimes the file part is entirely left off from the diagnostic. The interesting part is that Line number is OK, just the file part gets lost. This could be fixed by making the check more lenient in case of on-demand analysis (eg. not requiring that the diagnostic contains the file information).

Could you please elaborate this with examples?

Second issue:
Inline assembly importing fails if -std=c89 is given inside compile_commands.json for the c test (see the test RUN: lines for the contents of the compile_commands.json). If however no -std=c89 is given, then unsupported AST node error is given during the analysis (I assume that it must be the clang tool which parses the file).

That is strange, I cannot say what could be wrong here, we should be able to import inline assembly without the unsupported node error. We must further debug it.

lib/CrossTU/CrossTranslationUnit.cpp Outdated Show resolved Hide resolved
lib/CrossTU/CrossTranslationUnit.cpp Outdated Show resolved Hide resolved
lib/CrossTU/CrossTranslationUnit.cpp Outdated Show resolved Hide resolved
lib/CrossTU/CrossTranslationUnit.cpp Outdated Show resolved Hide resolved
test/Analysis/ctu-different-triples.cpp Show resolved Hide resolved
test/Analysis/ctu-on-the-fly.c Outdated Show resolved Hide resolved
@gamesh411
Copy link
Collaborator Author

I have a working solution updated. The parsing logic of external TUs should be refactored to increase maintainability. However, this change is complex enough as is, and I would recommend refactoring in a separate change.

There is another ongoing issue with passing configuration options to CTUContext during the CallEvent handling of the analyzer engine. This promotes parameter-style passing of information, however, the Context object would be better off with constructor parameter injection or getters and setters (which is still a bit inferior to constructor injection because the values are set every time an external TU definition is requested from the context).

@gamesh411
Copy link
Collaborator Author

Fixed a remaining typo.

Copy link

@martong martong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks okay, other than a few minor things.
But could you please check why the PR CI failed?

include/clang/CrossTU/CrossTranslationUnit.h Show resolved Hide resolved
lib/CrossTU/CrossTranslationUnit.cpp Outdated Show resolved Hide resolved
lib/CrossTU/CrossTranslationUnit.cpp Outdated Show resolved Hide resolved
lib/CrossTU/CrossTranslationUnit.cpp Outdated Show resolved Hide resolved
lib/CrossTU/CrossTranslationUnit.cpp Outdated Show resolved Hide resolved
lib/CrossTU/CrossTranslationUnit.cpp Outdated Show resolved Hide resolved
lib/CrossTU/CrossTranslationUnit.cpp Outdated Show resolved Hide resolved
lib/Frontend/CompilerInvocation.cpp Show resolved Hide resolved
test/Analysis/ctu-on-demand-parsing.c Show resolved Hide resolved
@gamesh411
Copy link
Collaborator Author

I have refactored and rebased the solution. There is an extra diagnostic as requested, and I have asserted some invariants in the code.

Copy link

@martong martong left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@martong
Copy link

martong commented Oct 28, 2019

CI still fails...

@martong
Copy link

martong commented Oct 29, 2019

run tests (this message is intended for the build bot, if you answer to this message then you owe me a bottle of whiskey)

@martong
Copy link

martong commented Oct 29, 2019

run tests

Add an option to enable on-demand parsing of needed ASTs during CTU
analysis, and another option to specify the compilation database used.
The option CTUOnDemandParsing is a boolean flag, which enables the new
AST-loading mode. Option CTUOnDemandParsingDatabase is a string, which
should be the path of the compilation database used for on-demand parsing.
The compilation database is needed for on-demand mode, because it has all the
necessary information to generate the ASTs.

Please enter the commit message for your changes. Lines starting
@gamesh411
Copy link
Collaborator Author

run tests

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants