Index: clang/lib/CrossTU/CrossTranslationUnit.cpp =================================================================== --- clang/lib/CrossTU/CrossTranslationUnit.cpp +++ clang/lib/CrossTU/CrossTranslationUnit.cpp @@ -157,7 +157,7 @@ unsigned LineNo = 1; while (std::getline(ExternalMapFile, Line)) { StringRef LineRef{Line}; - const size_t Delimiter = LineRef.find(' '); + const size_t Delimiter = LineRef.rfind(' '); if (Delimiter > 0 && Delimiter != std::string::npos) { StringRef LookupName = LineRef.substr(0, Delimiter); Index: clang/test/Analysis/Inputs/ctu-lookup-name-with-space.cpp =================================================================== --- /dev/null +++ clang/test/Analysis/Inputs/ctu-lookup-name-with-space.cpp @@ -0,0 +1,14 @@ +void f(int (*)(char)); +void f(bool (*)(char)); + +struct G { + G() { + // CHECK-NOT: error: multiple definitions are found for the same key in index + f([](char) -> int { return 42; }); + f([](char) -> bool { return true; }); + } +}; + +int importee(int X) { + return 1 / X; +} Index: clang/test/Analysis/ctu-lookup-name-with-space.cpp =================================================================== --- /dev/null +++ clang/test/Analysis/ctu-lookup-name-with-space.cpp @@ -0,0 +1,29 @@ +// RUN: rm -rf %t +// RUN: mkdir %t + +// RUN: cp %s %t/trigger.cpp +// RUN: cp %S/Inputs/ctu-lookup-name-with-space.cpp %t/importee.cpp +// RUN: echo '"%t/importee.cpp" : ["g++", "-c", "%t/importee.cpp"]' > %t/invocations.yaml +// RUN: echo '[{"directory": "%t", "command": "g++ -c %t/importee.cpp", "file": "%t/importee.cpp"}, {"directory": "%t", "command": "g++ -c %t/trigger.cpp", "file": "%t/trigger.cpp"}]' > %t/compile_commands.json + +// RUN: %clang_extdef_map -p %t %t/importee.cpp > %t/externalDefMap.txt + +// RUN: cd %t && %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 ctu-invocation-list=invocations.yaml \ +// RUN: trigger.cpp 2>&1 | FileCheck importee.cpp + +// RUN: cd %t && %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 ctu-invocation-list=invocations.yaml \ +// RUN: -verify trigger.cpp + +int importee(int); + +void trigger() { + importee(0); // expected-warning@importee.cpp:13 {{Division by zero}} +}