This is an archive of the discontinued LLVM Phabricator instance.

[analyzer][ctu] Append ctu-dir to ctu-invocation-list for non-absolute paths
AbandonedPublic

Authored by OikawaKirie on May 7 2021, 4:04 AM.

Details

Summary

This patch fixes the problem mentioned in D101763#2743984.
When the ctu-invocation-list is not an absolute path and the current working directory is not the ctu-dir, the invocation list will fail to be loaded.
In this patch, the ctu-dir is appended to the ctu-invocation-list if the ctu-invocation-list is not an absolute path.
And the original test cases for on-demand parsing are reused to test this feature.

Diff Detail

Event Timeline

OikawaKirie created this revision.May 7 2021, 4:04 AM
OikawaKirie requested review of this revision.May 7 2021, 4:04 AM

On second thought the current behavior is reasonable.
We call clang from a command line, so I think it's fair to expect that relative paths are resolved using the CWD.
AFAIK if one does not supply the ctu-invocation-list, then it would be substituted by ctu-dir/invocations.yaml anyway.

On second thought the current behavior is reasonable.

The behavior of all CTU affairs are related to the ctu-dir rather than CWD, such as loading the external function map file and looking for the AST dumps and source files to be imported.
If a relative path is provided for these files, the ctu-dir will be added to the path when trying to open the file (see the comments in the code).
Therefore, IMO the behavior of ctu-invocation-list and its contents should also be relative to the ctu-dir unless an absolute path is provided.

We call clang from a command line, so I think it's fair to expect that relative paths are resolved using the CWD.

I do not know how other people use CSA, but I prefer using CSA via clang-check.
It works with the relative path to the "directory" option in the compilation database of each source file, which could make the CWD not unique.

AFAIK if one does not supply the ctu-invocation-list, then it would be substituted by ctu-dir/invocations.yaml anyway.

But we cannot currently distinguish the difference between setting ctu-invocation-list to invocations.yaml and not setting it. As the default value of ctu-invocation-list is invocations.yaml rather than an empty string.
Therefore, adding the ctu-dir to a relative ctu-invocation-list path by default seems to be a better choice.

clang/lib/CrossTU/CrossTranslationUnit.cpp
470

Loading the external function map.

516

Loading the ASTUnit from external AST dumps or source files.

First of all, thank you for the patch!
We had a meeting with my colleges (@steakhal, @gamesh411) and we agreed in the following.

We'd like to keep the current behavior because this way the behavior is similar that we got used to with any other command line tools.

OikawaKirie abandoned this revision.May 19 2021, 7:09 AM

First of all, thank you for the patch!
We had a meeting with my colleges (@steakhal, @gamesh411) and we agreed in the following.

We'd like to keep the current behavior because this way the behavior is similar that we got used to with any other command line tools.

Ok, if you all agree with using ctu-invocation-list with a path related to CWD rather than ctu-dir, I will drop this revision here.
Although, I still believe that it would be better to make the behavior similar to the ctu index file, which is related to the ctu-dir (see the comments in the code).

Thanks for your suggestions on this revision.