forked from MaxMood96/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[analyzer][ctu] Fix wrong 'multiple definitions' errors caused by spa…
…ce characters in lookup names when parsing the ctu index file This error was found when analyzing MySQL with CTU enabled. When there are space characters in the lookup name, the current delimiter searching strategy will make the file path wrongly parsed. And when two lookup names have the same prefix before their first space characters, a 'multiple definitions' error will be wrongly reported. e.g. The lookup names for the two lambda exprs in the test case are `c:@s@G@F@G#@sa@F@operator int (*)(char)#1` and `c:@s@G@F@G#@sa@F@operator bool (*)(char)#1` respectively. And their prefixes are both `c:@s@G@F@G#@sa@F@operator` when using the first space character as the delimiter. Solving the problem by adding a length for the lookup name, making the index items in the format of `<USR-Length>:<USR File> <Path>`. --- In the test case of this patch, we found that it will trigger a "triple mismatch" warning when using `clang -cc1` to analyze the source file with CTU using the on-demand-parsing strategy in Darwin systems. And this problem is also encountered in D75665, which is the patch introducing the on-demand parsing strategy. We temporarily bypass this problem by using the loading-ast-file strategy. Refer to the [discourse topic](https://discourse.llvm.org/t/60762) for more details. Differential Revision: https://reviews.llvm.org/D102669
- Loading branch information
Showing
12 changed files
with
174 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
clang/test/Analysis/Inputs/ctu-import.c.externalDefMap.ast-dump.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
c:@F@testStaticImplicit ctu-import.c.ast | ||
23:c:@F@testStaticImplicit ctu-import.c.ast |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
void f(void (*)()); | ||
void f(void (*)(int)); | ||
|
||
struct G { | ||
G() { | ||
// multiple definitions are found for the same key in index | ||
f([]() -> void {}); // USR: c:@S@G@F@G#@Sa@F@operator void (*)()#1 | ||
f([](int) -> void {}); // USR: c:@S@G@F@G#@Sa@F@operator void (*)(int)#1 | ||
|
||
// As both lambda exprs have the same prefix, if the CTU index parser uses | ||
// the first space character as the delimiter between USR and file path, a | ||
// "multiple definitions are found for the same key in index" error will | ||
// be reported. | ||
} | ||
}; | ||
|
||
void importee() {} |
14 changes: 7 additions & 7 deletions
14
clang/test/Analysis/Inputs/ctu-other.c.externalDefMap.ast-dump.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
c:@F@inlineAsm ctu-other.c.ast | ||
c:@F@g ctu-other.c.ast | ||
c:@F@f ctu-other.c.ast | ||
c:@F@enumCheck ctu-other.c.ast | ||
c:@F@identImplicit ctu-other.c.ast | ||
c:@F@structInProto ctu-other.c.ast | ||
c:@F@switchWithoutCases ctu-other.c.ast | ||
14:c:@F@inlineAsm ctu-other.c.ast | ||
6:c:@F@g ctu-other.c.ast | ||
6:c:@F@f ctu-other.c.ast | ||
14:c:@F@enumCheck ctu-other.c.ast | ||
18:c:@F@identImplicit ctu-other.c.ast | ||
18:c:@F@structInProto ctu-other.c.ast | ||
23:c:@F@switchWithoutCases ctu-other.c.ast |
60 changes: 30 additions & 30 deletions
60
clang/test/Analysis/Inputs/ctu-other.cpp.externalDefMap.ast-dump.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,30 @@ | ||
c:@N@chns@F@chf1#I# ctu-other.cpp.ast | ||
c:@N@myns@N@embed_ns@F@fens#I# ctu-other.cpp.ast | ||
c:@F@g#I# ctu-other.cpp.ast | ||
c:@S@mycls@F@fscl#I#S ctu-other.cpp.ast | ||
c:@S@mycls@F@fcl#I# ctu-other.cpp.ast | ||
c:@S@mycls@F@fvcl#I# ctu-other.cpp.ast | ||
c:@N@myns@S@embed_cls@F@fecl#I# ctu-other.cpp.ast | ||
c:@S@mycls@S@embed_cls2@F@fecl2#I# ctu-other.cpp.ast | ||
c:@S@derived@F@fvcl#I# ctu-other.cpp.ast | ||
c:@F@f#I# ctu-other.cpp.ast | ||
c:@N@myns@F@fns#I# ctu-other.cpp.ast | ||
c:@F@h#I# ctu-other.cpp.ast | ||
c:@F@h_chain#I# ctu-chain.cpp.ast | ||
c:@N@chns@S@chcls@F@chf4#I# ctu-chain.cpp.ast | ||
c:@N@chns@F@chf2#I# ctu-chain.cpp.ast | ||
c:@F@fun_using_anon_struct#I# ctu-other.cpp.ast | ||
c:@F@other_macro_diag#I# ctu-other.cpp.ast | ||
c:@extInt ctu-other.cpp.ast | ||
c:@N@intns@extInt ctu-other.cpp.ast | ||
c:@extS ctu-other.cpp.ast | ||
c:@S@A@a ctu-other.cpp.ast | ||
c:@extSC ctu-other.cpp.ast | ||
c:@S@ST@sc ctu-other.cpp.ast | ||
c:@extSCN ctu-other.cpp.ast | ||
c:@extSubSCN ctu-other.cpp.ast | ||
c:@extSCC ctu-other.cpp.ast | ||
c:@extU ctu-other.cpp.ast | ||
c:@S@TestAnonUnionUSR@Test ctu-other.cpp.ast | ||
c:@F@testImportOfIncompleteDefaultParmDuringImport#I# ctu-other.cpp.ast | ||
c:@F@testImportOfDelegateConstructor#I# ctu-other.cpp.ast | ||
19:c:@N@chns@F@chf1#I# ctu-other.cpp.ast | ||
30:c:@N@myns@N@embed_ns@F@fens#I# ctu-other.cpp.ast | ||
9:c:@F@g#I# ctu-other.cpp.ast | ||
21:c:@S@mycls@F@fscl#I#S ctu-other.cpp.ast | ||
19:c:@S@mycls@F@fcl#I# ctu-other.cpp.ast | ||
20:c:@S@mycls@F@fvcl#I# ctu-other.cpp.ast | ||
31:c:@N@myns@S@embed_cls@F@fecl#I# ctu-other.cpp.ast | ||
34:c:@S@mycls@S@embed_cls2@F@fecl2#I# ctu-other.cpp.ast | ||
22:c:@S@derived@F@fvcl#I# ctu-other.cpp.ast | ||
9:c:@F@f#I# ctu-other.cpp.ast | ||
18:c:@N@myns@F@fns#I# ctu-other.cpp.ast | ||
9:c:@F@h#I# ctu-other.cpp.ast | ||
15:c:@F@h_chain#I# ctu-chain.cpp.ast | ||
27:c:@N@chns@S@chcls@F@chf4#I# ctu-chain.cpp.ast | ||
19:c:@N@chns@F@chf2#I# ctu-chain.cpp.ast | ||
29:c:@F@fun_using_anon_struct#I# ctu-other.cpp.ast | ||
24:c:@F@other_macro_diag#I# ctu-other.cpp.ast | ||
9:c:@extInt ctu-other.cpp.ast | ||
17:c:@N@intns@extInt ctu-other.cpp.ast | ||
7:c:@extS ctu-other.cpp.ast | ||
8:c:@S@A@a ctu-other.cpp.ast | ||
8:c:@extSC ctu-other.cpp.ast | ||
10:c:@S@ST@sc ctu-other.cpp.ast | ||
9:c:@extSCN ctu-other.cpp.ast | ||
12:c:@extSubSCN ctu-other.cpp.ast | ||
9:c:@extSCC ctu-other.cpp.ast | ||
7:c:@extU ctu-other.cpp.ast | ||
26:c:@S@TestAnonUnionUSR@Test ctu-other.cpp.ast | ||
53:c:@F@testImportOfIncompleteDefaultParmDuringImport#I# ctu-other.cpp.ast | ||
39:c:@F@testImportOfDelegateConstructor#I# ctu-other.cpp.ast |
8 changes: 4 additions & 4 deletions
8
clang/test/Analysis/Inputs/plist-macros-with-expansion-ctu.c.externalDefMap.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
c:@F@F1 plist-macros-ctu.c.ast | ||
c:@F@F2 plist-macros-ctu.c.ast | ||
c:@F@F3 plist-macros-ctu.c.ast | ||
c:@F@F_H plist-macros-ctu.c.ast | ||
7:c:@F@F1 plist-macros-ctu.c.ast | ||
7:c:@F@F2 plist-macros-ctu.c.ast | ||
7:c:@F@F3 plist-macros-ctu.c.ast | ||
8:c:@F@F_H plist-macros-ctu.c.ast |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// RUN: rm -rf %t | ||
// RUN: mkdir %t | ||
|
||
// RUN: echo '41:c:@S@G@F@G#@Sa@F@operator void (*)(int)#1 %/t/importee.ast' >> %t/externalDefMap.txt | ||
// RUN: echo '38:c:@S@G@F@G#@Sa@F@operator void (*)()#1 %/t/importee.ast' >> %t/externalDefMap.txt | ||
// RUN: echo '14:c:@F@importee# %/t/importee.ast' >> %t/externalDefMap.txt | ||
// RUN: %clang_cc1 -emit-pch %/S/Inputs/ctu-lookup-name-with-space.cpp -o %t/importee.ast | ||
|
||
// RUN: cd %t | ||
// RUN: %clang_cc1 -fsyntax-only -analyze \ | ||
// RUN: -analyzer-checker=core \ | ||
// RUN: -analyzer-config experimental-enable-naive-ctu-analysis=true \ | ||
// RUN: -analyzer-config ctu-dir=. \ | ||
// RUN: -analyzer-config display-ctu-progress=true \ | ||
// RUN: -verify %s 2>&1 | FileCheck %s | ||
|
||
// CHECK: CTU loaded AST file | ||
|
||
// FIXME: In this test case, we cannot use the on-demand-parsing approach to | ||
// load the external TU. | ||
// | ||
// In the Darwin system, the target triple is determined by the driver, | ||
// rather than using the default one like other systems. However, when | ||
// using bare `clang -cc1`, the adjustment is not done, which cannot | ||
// match the one loaded with on-demand-parsing (adjusted triple). | ||
// We bypass this problem by loading AST files, whose target triple is | ||
// also unadjusted when generated via `clang -cc1 -emit-pch`. | ||
// | ||
// Refer to: https://discourse.llvm.org/t/60762 | ||
// | ||
// This is also the reason why the test case of D75665 (introducing | ||
// the on-demand-parsing feature) is enabled only on Linux. | ||
|
||
void importee(); | ||
|
||
void trigger() { | ||
// Call an external function to trigger the parsing process of CTU index. | ||
// Refer to file Inputs/ctu-lookup-name-with-space.cpp for more details. | ||
|
||
importee(); // expected-no-diagnostics | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters