<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/101274>101274</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
CTU mapping is not interpreted correctly
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
temyurchenko
</td>
</tr>
</table>
<pre>
In 5cc18516c4839fccc64b54eaa5aa447a8e1ed8fa, there is a diff:
```
- const size_t Pos = Line.find(" ");
- if (Pos > 0 && Pos != std::string::npos) {
- StringRef LineRef{Line};
- StringRef LookupName = LineRef.substr(0, Pos);
- if (Result.count(LookupName))
+ StringRef LineRef{Line};
+ const size_t Delimiter = LineRef.find(" ");
+ if (Delimiter > 0 && Delimiter != std::string::npos) {
+ StringRef LookupName = LineRef.substr(0, Delimiter);
+
+ // Store paths with posix-style directory separator.
+ SmallVector<char, 32> FilePath;
+ llvm::Twine{LineRef.substr(Delimiter + 1)}.toVector(FilePath);
+ llvm::sys::path::native(FilePath, llvm::sys::path::Style::posix);
+
+ bool InsertionOccured;
+ std::tie(std::ignore, InsertionOccured) =
+ Result.try_emplace(LookupName, FilePath.begin(), FilePath.end());
+ if (!InsertionOccured)
return llvm::make_error<IndexError>(
index_error_code::multiple_definitions, IndexPath.str(), LineNo);
- StringRef FileName = LineRef.substr(Pos + 1);
- SmallString<256> FilePath = CrossTUDir;
- llvm::sys::path::append(FilePath, FileName);
- Result[LookupName] = std::string(FilePath);
```
The code creates a mapping of `FilePath`s containing the definition of `LookupName`s. The `FilePath`s are fetched from a CTU index file at `IndexPath`. Note, how in the version before `CrossTUDir` was prepended to the `FilePath`. In the new version, it doesn't.
That constitutes a problem. The [documentation](https://clang.llvm.org/docs/analyzer/user-docs/CrossTranslationUnit.html#automated-ctu-analysis-with-codechecker) on using CodeChecker to generate a CTU database, gives us an index file with _relative_ paths. If one doesn't append the CTU directory to such a path, the AST file is not going to be found. Which is exactly what happens.
Perhaps, the patch was necessary to support the on-demand CTU analysis, but it seems to have broken the PCH-based one. Or, perhaps, the documentation is outdated.
cc @gamesh411.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUVtGO4joS_RrzUiJKnBDCAw8DDNqWVnNb0z27jy1jV4i3EzuyK93D_fqVnUADM31172hEE6fq1PGp4zLCe300iGu22LDFbiYGaqxbE3anwckGzaudHaw6rR8MLKTMqkVWyqLKV7WUsiwOiwKFWAhRFEtRYYaqqgXjW6AGHYL2IEDpumb5F5buWHr-LNPpf3ycAwBIazyB13_iC8Gj9cDyHfxbG0xqbRTjFeMcGOeMr1i-OSfqGhivxvCvkALjJePlmM-zAOFJher5F09Om-P43fTWM74CttxcUQB4ijHfsY6Vv2PNlpvwjS13V0XvQ619HfpvosML5-9YJ344eHKMV2kQ5DEW_IX5d_RDS4m0gyHGqw-oEMxXk1x883fJhdAbJXfY6k4Tuhtun0s61RrZXSdfqXu1_E80nqD_sXSXcnc871AZ3zO-hyeyDqEX1Hh419RAb73-Ofd0ahGUdijJuhN47IUTZF1yT64TbfufGMXyrWyECxxyHhTY6xYfBTU3arXtWzfu-Pk9dmPzyzauBdtAFvax3CVkpzK8ugDfdeID25_8-KWP9aPAgvQb3mRv_zrjKYgwLQZVPhX0YG0LD8ajI23NH1IODtW9R-Cj76QDj8ujPhrrMND5BSMYIt_d4YR_00kgd3rBrm-FxLvzsL3InxzwqE307-pmHSdXr37j6LOnGc9-Q2oMvZBxSIMzV2J24hVf0Lloigej8OfX8eFrgByTdVgeg16kVZPQ3dCS7lt8UVhro0NZPyqj8GdkPXpk2kvwzjd7Oyo-zkvY6eenZZx6k8Hux1Ww9dN0PLd8UV77OcJtnfX--cdOu_vcv_SU6PtR9msXnnn-hsjYZ7bYXPV2sYPfjZFPzsXt5TF-PjcIQXOQDgVhuHc60ffaHMHWwMr0glSmPkxIEtqEt9QgfHRmCr6iVqY-gYB-jyEcQo0kG1RQO9uBgO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