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`. Reviewed By: steakhal Differential Revision: https://reviews.llvm.org/D102669
- Loading branch information
Showing
12 changed files
with
154 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,21 @@ | ||
// RUN: rm -rf %t | ||
// RUN: mkdir %t | ||
|
||
// RUN: echo '"%/S/Inputs/ctu-lookup-name-with-space.cpp" : ["g++", "-c", "%/S/Inputs/ctu-lookup-name-with-space.cpp"]' > %t/invocations.yaml | ||
// RUN: %clang_extdef_map %S/Inputs/ctu-lookup-name-with-space.cpp -- > %t/externalDefMap.txt | ||
|
||
// RUN: cd %t && %clang_cc1 -fsyntax-only -analyze \ | ||
// RUN: -analyzer-checker=core,debug.ExprInspection \ | ||
// RUN: -analyzer-config experimental-enable-naive-ctu-analysis=true \ | ||
// RUN: -analyzer-config ctu-dir=. \ | ||
// RUN: -analyzer-config ctu-invocation-list=invocations.yaml \ | ||
// RUN: -verify %s | ||
|
||
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