[clang] f05b70c - Revert "[analyzer][ctu] Avoid parsing invocation list again and again during on-demand parsing of CTU"
Balazs Benics via cfe-commits
cfe-commits at lists.llvm.org
Tue May 25 00:31:07 PDT 2021
Author: Balazs Benics
Date: 2021-05-25T09:29:56+02:00
New Revision: f05b70c23687fdf3de349ab1dd99ad79c4c40e85
URL: https://github.com/llvm/llvm-project/commit/f05b70c23687fdf3de349ab1dd99ad79c4c40e85
DIFF: https://github.com/llvm/llvm-project/commit/f05b70c23687fdf3de349ab1dd99ad79c4c40e85.diff
LOG: Revert "[analyzer][ctu] Avoid parsing invocation list again and again during on-demand parsing of CTU"
This reverts commit db8af0f21dc9aad4d336754c857c24470afe53e3.
clang-x86_64-debian-fast fails on this.
+ : 'RUN: at line 4'
+ /usr/bin/ccache
/b/1/clang-x86_64-debian-fast/llvm.src/clang/test/Analysis/ctu-on-demand-parsing-multiple-invocation-list-parsing.cpp
-fPIC -shared -o
/b/1/clang-x86_64-debian-fast/llvm.obj/tools/clang/test/Analysis/Output/ctu-on-demand-parsing-multiple-invocation-list-parsing.cpp.tmp/mock_open.so
ccache: error: execv of
/b/1/clang-x86_64-debian-fast/llvm.src/clang/test/Analysis/ctu-on-demand-parsing-multiple-invocation-list-parsing.cpp
failed: Permission denied
Added:
Modified:
clang/include/clang/CrossTU/CrossTranslationUnit.h
clang/lib/CrossTU/CrossTranslationUnit.cpp
Removed:
clang/test/Analysis/ctu-on-demand-parsing-multiple-invocation-list-parsing.cpp
################################################################################
diff --git a/clang/include/clang/CrossTU/CrossTranslationUnit.h b/clang/include/clang/CrossTU/CrossTranslationUnit.h
index d9f9c51fccd9c..b419b9be67cb9 100644
--- a/clang/include/clang/CrossTU/CrossTranslationUnit.h
+++ b/clang/include/clang/CrossTU/CrossTranslationUnit.h
@@ -38,7 +38,6 @@ class TranslationUnitDecl;
namespace cross_tu {
enum class index_error_code {
- success = 0,
unspecified = 1,
missing_index_file,
invalid_index_format,
@@ -254,7 +253,6 @@ class CrossTranslationUnitContext {
/// In case of on-demand parsing, the invocations for parsing the source
/// files is stored.
llvm::Optional<InvocationListTy> InvocationList;
- index_error_code PreviousParsingResult = index_error_code::success;
};
/// Maintain number of AST loads and check for reaching the load limit.
diff --git a/clang/lib/CrossTU/CrossTranslationUnit.cpp b/clang/lib/CrossTU/CrossTranslationUnit.cpp
index adee55304c871..640538cae3bbc 100644
--- a/clang/lib/CrossTU/CrossTranslationUnit.cpp
+++ b/clang/lib/CrossTU/CrossTranslationUnit.cpp
@@ -92,10 +92,6 @@ class IndexErrorCategory : public std::error_category {
std::string message(int Condition) const override {
switch (static_cast<index_error_code>(Condition)) {
- case index_error_code::success:
- // There should not be a success error. Jump to unreachable directly.
- // Add this case to make the compiler stop complaining.
- break;
case index_error_code::unspecified:
return "An unknown error has occurred.";
case index_error_code::missing_index_file:
@@ -671,15 +667,12 @@ llvm::Error CrossTranslationUnitContext::ASTLoader::lazyInitInvocationList() {
/// Lazily initialize the invocation list member used for on-demand parsing.
if (InvocationList)
return llvm::Error::success();
- if (index_error_code::success != PreviousParsingResult)
- return llvm::make_error<IndexError>(PreviousParsingResult);
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> FileContent =
llvm::MemoryBuffer::getFile(InvocationListFilePath);
- if (!FileContent) {
- PreviousParsingResult = index_error_code::invocation_list_file_not_found;
- return llvm::make_error<IndexError>(PreviousParsingResult);
- }
+ if (!FileContent)
+ return llvm::make_error<IndexError>(
+ index_error_code::invocation_list_file_not_found);
std::unique_ptr<llvm::MemoryBuffer> ContentBuffer = std::move(*FileContent);
assert(ContentBuffer && "If no error was produced after loading, the pointer "
"should not be nullptr.");
@@ -687,13 +680,8 @@ llvm::Error CrossTranslationUnitContext::ASTLoader::lazyInitInvocationList() {
llvm::Expected<InvocationListTy> ExpectedInvocationList =
parseInvocationList(ContentBuffer->getBuffer(), PathStyle);
- // Handle the error to store the code for next call to this function.
- if (!ExpectedInvocationList) {
- llvm::handleAllErrors(
- ExpectedInvocationList.takeError(),
- [&](const IndexError &E) { PreviousParsingResult = E.getCode(); });
- return llvm::make_error<IndexError>(PreviousParsingResult);
- }
+ if (!ExpectedInvocationList)
+ return ExpectedInvocationList.takeError();
InvocationList = *ExpectedInvocationList;
diff --git a/clang/test/Analysis/ctu-on-demand-parsing-multiple-invocation-list-parsing.cpp b/clang/test/Analysis/ctu-on-demand-parsing-multiple-invocation-list-parsing.cpp
deleted file mode 100644
index 7121a798e3c27..0000000000000
--- a/clang/test/Analysis/ctu-on-demand-parsing-multiple-invocation-list-parsing.cpp
+++ /dev/null
@@ -1,56 +0,0 @@
-// RUN: rm -rf %t
-// RUN: mkdir -p %t
-
-// RUN: %host_cxx %s -fPIC -shared -o %t/mock_open.so
-
-// RUN: echo "void bar(); void foo() { bar(); bar(); }" > %t/trigger.c
-// RUN: echo "void bar() {}" > %t/importee.c
-// RUN: echo '[{"directory":"%t", "command":"cc -c %t/importee.c", "file": "%t/importee.c"}]' > %t/compile_commands.json
-// RUN: %clang_extdef_map -p %t "%t/importee.c" > %t/externalDefMap.txt
-
-// Add an empty invocation list to make the on-demand parsing fail and load it again.
-// RUN: echo '' > %t/invocations.yaml
-
-// RUN: cd %t && \
-// RUN: LD_PRELOAD=%t/mock_open.so \
-// 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 ctu-invocation-list=invocations.yaml \
-// RUN: %t/trigger.c | FileCheck %s
-
-// REQUIRES: shell, system-linux
-
-// CHECK: {{Opening file invocations.yaml: 1}}
-// CHECK-NOT: {{Opening file invocations.yaml: 2}}
-
-#define _GNU_SOURCE 1
-#include <dlfcn.h>
-#include <fcntl.h>
-
-#include <cassert>
-#include <cstdarg>
-#include <iostream>
-using namespace std;
-
-extern "C" int open(const char *name, int flag, ...) {
- // Log how many times the invocation list is opened.
- if ("invocations.yaml" == string(name)) {
- static unsigned N = 0;
- cout << "Opening file invocations.yaml: " << ++N << endl;
- }
-
- // The original open function will be called to open the files.
- using open_t = int (*)(const char *, int, mode_t);
- static open_t o_open = nullptr;
- if (!o_open)
- o_open = reinterpret_cast<open_t>(dlsym(RTLD_NEXT, "open"));
- assert(o_open && "Cannot find function `open'.");
-
- va_list vl;
- va_start(vl, flag);
- auto mode = va_arg(vl, mode_t);
- va_end(vl);
- return o_open(name, flag, mode);
-}
More information about the cfe-commits
mailing list