summaryrefslogtreecommitdiff
path: root/gnu/llvm/clang/tools/c-index-test
diff options
context:
space:
mode:
authorPatrick Wildt <patrick@cvs.openbsd.org>2021-12-17 12:26:56 +0000
committerPatrick Wildt <patrick@cvs.openbsd.org>2021-12-17 12:26:56 +0000
commit62c6e032fae72fcce51d30b40fad9b3be39763de (patch)
tree5d4bb2f9d723fb838757ad5d92688ffcd2cf86cf /gnu/llvm/clang/tools/c-index-test
parentac454a928e5fd4511477b6e325e6b0690519290a (diff)
Import LLVM 13.0.0 release.
Diffstat (limited to 'gnu/llvm/clang/tools/c-index-test')
-rw-r--r--gnu/llvm/clang/tools/c-index-test/c-index-test.c35
-rw-r--r--gnu/llvm/clang/tools/c-index-test/core_main.cpp39
2 files changed, 64 insertions, 10 deletions
diff --git a/gnu/llvm/clang/tools/c-index-test/c-index-test.c b/gnu/llvm/clang/tools/c-index-test/c-index-test.c
index 6e82bf9999f..a32062caf88 100644
--- a/gnu/llvm/clang/tools/c-index-test/c-index-test.c
+++ b/gnu/llvm/clang/tools/c-index-test/c-index-test.c
@@ -24,6 +24,7 @@
#endif
extern int indextest_core_main(int argc, const char **argv);
+extern int indextest_perform_shell_execution(const char *command_line);
/******************************************************************************/
/* Utility functions. */
@@ -1539,10 +1540,20 @@ static void PrintNullabilityKind(CXType T, const char *Format) {
const char *nullability = 0;
switch (N) {
- case CXTypeNullability_NonNull: nullability = "nonnull"; break;
- case CXTypeNullability_Nullable: nullability = "nullable"; break;
- case CXTypeNullability_Unspecified: nullability = "unspecified"; break;
- case CXTypeNullability_Invalid: break;
+ case CXTypeNullability_NonNull:
+ nullability = "nonnull";
+ break;
+ case CXTypeNullability_Nullable:
+ nullability = "nullable";
+ break;
+ case CXTypeNullability_NullableResult:
+ nullability = "nullable_result";
+ break;
+ case CXTypeNullability_Unspecified:
+ nullability = "unspecified";
+ break;
+ case CXTypeNullability_Invalid:
+ break;
}
if (nullability) {
@@ -2085,6 +2096,8 @@ int perform_test_reparse_source(int argc, const char **argv, int trials,
enum CXErrorCode Err;
int result, i;
int trial;
+ int execute_after_trial = 0;
+ const char *execute_command = NULL;
int remap_after_trial = 0;
char *endptr = 0;
@@ -2123,12 +2136,26 @@ int perform_test_reparse_source(int argc, const char **argv, int trials,
if (checkForErrors(TU) != 0)
return -1;
+ if (getenv("CINDEXTEST_EXECUTE_COMMAND")) {
+ execute_command = getenv("CINDEXTEST_EXECUTE_COMMAND");
+ }
+ if (getenv("CINDEXTEST_EXECUTE_AFTER_TRIAL")) {
+ execute_after_trial =
+ strtol(getenv("CINDEXTEST_EXECUTE_AFTER_TRIAL"), &endptr, 10);
+ }
+
if (getenv("CINDEXTEST_REMAP_AFTER_TRIAL")) {
remap_after_trial =
strtol(getenv("CINDEXTEST_REMAP_AFTER_TRIAL"), &endptr, 10);
}
for (trial = 0; trial < trials; ++trial) {
+ if (execute_command && trial == execute_after_trial) {
+ result = indextest_perform_shell_execution(execute_command);
+ if (result != 0)
+ return result;
+ }
+
free_remapped_files(unsaved_files, num_unsaved_files);
if (parse_remapped_files_with_try(trial, argc, argv, 0,
&unsaved_files, &num_unsaved_files)) {
diff --git a/gnu/llvm/clang/tools/c-index-test/core_main.cpp b/gnu/llvm/clang/tools/c-index-test/core_main.cpp
index b03783b7e04..7037252ffa0 100644
--- a/gnu/llvm/clang/tools/c-index-test/core_main.cpp
+++ b/gnu/llvm/clang/tools/c-index-test/core_main.cpp
@@ -13,22 +13,25 @@
#include "clang/Frontend/CompilerInstance.h"
#include "clang/Frontend/CompilerInvocation.h"
#include "clang/Frontend/FrontendAction.h"
-#include "clang/Index/IndexingAction.h"
#include "clang/Index/IndexDataConsumer.h"
+#include "clang/Index/IndexingAction.h"
#include "clang/Index/USRGeneration.h"
#include "clang/Lex/Preprocessor.h"
#include "clang/Serialization/ASTReader.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/PrettyStackTrace.h"
+#include "llvm/Support/Program.h"
#include "llvm/Support/Signals.h"
+#include "llvm/Support/StringSaver.h"
#include "llvm/Support/raw_ostream.h"
-#include "llvm/Support/PrettyStackTrace.h"
using namespace clang;
using namespace clang::index;
using namespace llvm;
extern "C" int indextest_core_main(int argc, const char **argv);
+extern "C" int indextest_perform_shell_execution(const char *command_line);
namespace {
@@ -60,6 +63,9 @@ DumpModuleImports("dump-imported-module-files",
static cl::opt<bool>
IncludeLocals("include-locals", cl::desc("Print local symbols"));
+static cl::opt<bool> IgnoreMacros("ignore-macros",
+ cl::desc("Skip indexing macros"));
+
static cl::opt<std::string>
ModuleFilePath("module-file",
cl::desc("Path to module file to print symbols from"));
@@ -207,7 +213,8 @@ static void dumpModuleFileInputs(serialization::ModuleFile &Mod,
static bool printSourceSymbols(const char *Executable,
ArrayRef<const char *> Args,
- bool dumpModuleImports, bool indexLocals) {
+ bool dumpModuleImports, bool indexLocals,
+ bool ignoreMacros) {
SmallVector<const char *, 4> ArgsWithProgName;
ArgsWithProgName.push_back(Executable);
ArgsWithProgName.append(Args.begin(), Args.end());
@@ -221,6 +228,8 @@ static bool printSourceSymbols(const char *Executable,
auto DataConsumer = std::make_shared<PrintIndexDataConsumer>(OS);
IndexingOptions IndexOpts;
IndexOpts.IndexFunctionLocals = indexLocals;
+ IndexOpts.IndexMacros = !ignoreMacros;
+ IndexOpts.IndexMacrosInPreprocessor = !ignoreMacros;
std::unique_ptr<FrontendAction> IndexAction =
createIndexingAction(DataConsumer, IndexOpts);
@@ -262,8 +271,8 @@ static bool printSourceSymbolsFromModule(StringRef modulePath,
std::unique_ptr<ASTUnit> AU = ASTUnit::LoadFromASTFile(
std::string(modulePath), *pchRdr, ASTUnit::LoadASTOnly, Diags,
FileSystemOpts, /*UseDebugInfo=*/false,
- /*OnlyLocalDecls=*/true, None, CaptureDiagsKind::None,
- /*AllowPCHWithCompilerErrors=*/true,
+ /*OnlyLocalDecls=*/true, CaptureDiagsKind::None,
+ /*AllowASTWithCompilerErrors=*/true,
/*UserFilesAreVolatile=*/false);
if (!AU) {
errs() << "failed to create TU for: " << modulePath << '\n';
@@ -354,8 +363,26 @@ int indextest_core_main(int argc, const char **argv) {
}
return printSourceSymbols(Executable.c_str(), CompArgs,
options::DumpModuleImports,
- options::IncludeLocals);
+ options::IncludeLocals, options::IgnoreMacros);
}
return 0;
}
+
+//===----------------------------------------------------------------------===//
+// Utility functions
+//===----------------------------------------------------------------------===//
+
+int indextest_perform_shell_execution(const char *command_line) {
+ BumpPtrAllocator Alloc;
+ llvm::StringSaver Saver(Alloc);
+ SmallVector<const char *, 4> Args;
+ llvm::cl::TokenizeGNUCommandLine(command_line, Saver, Args);
+ auto Program = llvm::sys::findProgramByName(Args[0]);
+ if (std::error_code ec = Program.getError()) {
+ llvm::errs() << "command not found: " << Args[0] << "\n";
+ return ec.value();
+ }
+ SmallVector<StringRef, 8> execArgs(Args.begin(), Args.end());
+ return llvm::sys::ExecuteAndWait(*Program, execArgs);
+}