From 01fa6f3b298b98d5f3ecccad52223326c30a280b Mon Sep 17 00:00:00 2001 From: Sean Callanan Date: Mon, 19 Dec 2016 19:15:43 +0000 Subject: [PATCH] Reverting r290004, r290006, r290010 pending review. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@290130 91177308-0d34-0410-b5e6-96231b3b80d8 --- test/CMakeLists.txt | 1 - test/Import/clang-flags/Inputs/S.c | 2 - test/Import/clang-flags/test.c | 5 - test/Import/empty-struct/Inputs/S.c | 2 - test/Import/empty-struct/test.c | 5 - test/Import/error-in-expression/Inputs/S.c | 2 - test/Import/error-in-expression/test.c | 6 - test/Import/error-in-import/Inputs/S.c | 2 - test/Import/error-in-import/test.c | 6 - test/Import/missing-import/test.c | 6 - tools/CMakeLists.txt | 1 - tools/clang-import-test/CMakeLists.txt | 27 -- tools/clang-import-test/clang-import-test.cpp | 319 ------------------ 13 files changed, 384 deletions(-) delete mode 100644 test/Import/clang-flags/Inputs/S.c delete mode 100644 test/Import/clang-flags/test.c delete mode 100644 test/Import/empty-struct/Inputs/S.c delete mode 100644 test/Import/empty-struct/test.c delete mode 100644 test/Import/error-in-expression/Inputs/S.c delete mode 100644 test/Import/error-in-expression/test.c delete mode 100644 test/Import/error-in-import/Inputs/S.c delete mode 100644 test/Import/error-in-import/test.c delete mode 100644 test/Import/missing-import/test.c delete mode 100644 tools/clang-import-test/CMakeLists.txt delete mode 100644 tools/clang-import-test/clang-import-test.cpp diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 46bf2ae213..8ba9040a92 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -39,7 +39,6 @@ list(APPEND CLANG_TEST_DEPS c-index-test diagtool clang-tblgen clang-offload-bundler - clang-import-test ) if(CLANG_ENABLE_STATIC_ANALYZER) diff --git a/test/Import/clang-flags/Inputs/S.c b/test/Import/clang-flags/Inputs/S.c deleted file mode 100644 index 742dac8a35..0000000000 --- a/test/Import/clang-flags/Inputs/S.c +++ /dev/null @@ -1,2 +0,0 @@ -STRUCT S { -}; diff --git a/test/Import/clang-flags/test.c b/test/Import/clang-flags/test.c deleted file mode 100644 index 7a19ea7ff6..0000000000 --- a/test/Import/clang-flags/test.c +++ /dev/null @@ -1,5 +0,0 @@ -// RUN: clang-import-test -import %S/Inputs/S.c -expression %s -Xcc -DSTRUCT=struct -void expr() { - STRUCT S MyS; - void *MyPtr = &MyS; -} diff --git a/test/Import/empty-struct/Inputs/S.c b/test/Import/empty-struct/Inputs/S.c deleted file mode 100644 index 8c90352bc4..0000000000 --- a/test/Import/empty-struct/Inputs/S.c +++ /dev/null @@ -1,2 +0,0 @@ -struct S { -}; diff --git a/test/Import/empty-struct/test.c b/test/Import/empty-struct/test.c deleted file mode 100644 index d51a69706d..0000000000 --- a/test/Import/empty-struct/test.c +++ /dev/null @@ -1,5 +0,0 @@ -// RUN: clang-import-test -import %S/Inputs/S.c -expression %s -void expr() { - struct S MyS; - void *MyPtr = &MyS; -} diff --git a/test/Import/error-in-expression/Inputs/S.c b/test/Import/error-in-expression/Inputs/S.c deleted file mode 100644 index 8c90352bc4..0000000000 --- a/test/Import/error-in-expression/Inputs/S.c +++ /dev/null @@ -1,2 +0,0 @@ -struct S { -}; diff --git a/test/Import/error-in-expression/test.c b/test/Import/error-in-expression/test.c deleted file mode 100644 index 65d3b4a5dc..0000000000 --- a/test/Import/error-in-expression/test.c +++ /dev/null @@ -1,6 +0,0 @@ -// RUN: not clang-import-test -import %S/Inputs/S.c -expression %s 2>&1 | FileCheck %s -// CHECK: {{.*}}no viable conversion{{.*}} -void expr() { - struct S MyS; - void *MyPtr = MyS; -} diff --git a/test/Import/error-in-import/Inputs/S.c b/test/Import/error-in-import/Inputs/S.c deleted file mode 100644 index 23ca763f67..0000000000 --- a/test/Import/error-in-import/Inputs/S.c +++ /dev/null @@ -1,2 +0,0 @@ -struct S [ -]; diff --git a/test/Import/error-in-import/test.c b/test/Import/error-in-import/test.c deleted file mode 100644 index 197d4e3042..0000000000 --- a/test/Import/error-in-import/test.c +++ /dev/null @@ -1,6 +0,0 @@ -// RUN: not clang-import-test -import %S/Inputs/S.c -expression %s 2>&1 | FileCheck %s -// CHECK: {{.*}}expected unqualified-id{{.*}} -void expr() { - struct S MyS; - void *MyPtr = &MyS; -} diff --git a/test/Import/missing-import/test.c b/test/Import/missing-import/test.c deleted file mode 100644 index acf6389cc5..0000000000 --- a/test/Import/missing-import/test.c +++ /dev/null @@ -1,6 +0,0 @@ -// RUN: not clang-import-test -import %S/Inputs/S.c -expression %s 2>&1 | FileCheck %s -// CHECK: {{.*}}Couldn't open{{.*}}Inputs/S.c{{.*}} -void expr() { - struct S MyS; - void *MyPtr = &MyS; -} diff --git a/tools/CMakeLists.txt b/tools/CMakeLists.txt index b0c97f0f1e..b8850e4546 100644 --- a/tools/CMakeLists.txt +++ b/tools/CMakeLists.txt @@ -5,7 +5,6 @@ add_clang_subdirectory(driver) add_clang_subdirectory(clang-format) add_clang_subdirectory(clang-format-vs) add_clang_subdirectory(clang-fuzzer) -add_clang_subdirectory(clang-import-test) add_clang_subdirectory(clang-offload-bundler) add_clang_subdirectory(c-index-test) diff --git a/tools/clang-import-test/CMakeLists.txt b/tools/clang-import-test/CMakeLists.txt deleted file mode 100644 index bd4919694a..0000000000 --- a/tools/clang-import-test/CMakeLists.txt +++ /dev/null @@ -1,27 +0,0 @@ -set(LLVM_LINK_COMPONENTS - core - support -) - -if(NOT CLANG_BUILT_STANDALONE) - set(tablegen_deps intrinsics_gen) -endif() - -add_clang_tool(clang-import-test - clang-import-test.cpp - DEPENDS - ${tablegen_deps} - ) - -set(CLANG_IMPORT_TEST_LIB_DEPS - clangAST - clangBasic - clangCodeGen - clangFrontend - clangLex - clangParse - ) - -target_link_libraries(clang-import-test - ${CLANG_IMPORT_TEST_LIB_DEPS} - ) diff --git a/tools/clang-import-test/clang-import-test.cpp b/tools/clang-import-test/clang-import-test.cpp deleted file mode 100644 index 931b46245b..0000000000 --- a/tools/clang-import-test/clang-import-test.cpp +++ /dev/null @@ -1,319 +0,0 @@ -//===-- import-test.cpp - ASTImporter/ExternalASTSource testbed -----------===// -// -// The LLVM Compiler Infrastructure -// -// This file is distributed under the University of Illinois Open Source -// License. See LICENSE.TXT for details. -// -//===----------------------------------------------------------------------===// - -#include "clang/AST/ASTContext.h" -#include "clang/AST/ASTImporter.h" -#include "clang/Basic/Builtins.h" -#include "clang/Basic/IdentifierTable.h" -#include "clang/Basic/SourceLocation.h" -#include "clang/Basic/TargetInfo.h" -#include "clang/Basic/TargetOptions.h" -#include "clang/CodeGen/ModuleBuilder.h" -#include "clang/Frontend/CompilerInstance.h" -#include "clang/Frontend/TextDiagnosticBuffer.h" -#include "clang/Lex/Lexer.h" -#include "clang/Lex/Preprocessor.h" -#include "clang/Parse/ParseAST.h" - -#include "llvm/IR/LLVMContext.h" -#include "llvm/Support/CommandLine.h" -#include "llvm/Support/Error.h" -#include "llvm/Support/Host.h" -#include "llvm/Support/Signals.h" - -#include -#include - -using namespace clang; - -static llvm::cl::opt Expression( - "expression", llvm::cl::Required, - llvm::cl::desc("Path to a file containing the expression to parse")); - -static llvm::cl::list - Imports("import", llvm::cl::ZeroOrMore, - llvm::cl::desc("Path to a file containing declarations to import")); - -static llvm::cl::list - ClangArgs("Xcc", llvm::cl::ZeroOrMore, - llvm::cl::desc("Argument to pass to the CompilerInvocation"), - llvm::cl::CommaSeparated); - -namespace init_convenience { -class TestDiagnosticConsumer : public DiagnosticConsumer { -private: - std::unique_ptr Passthrough; - const LangOptions *LangOpts = nullptr; - -public: - TestDiagnosticConsumer() - : Passthrough(llvm::make_unique()) {} - - virtual void BeginSourceFile(const LangOptions &LangOpts, - const Preprocessor *PP = nullptr) override { - this->LangOpts = &LangOpts; - return Passthrough->BeginSourceFile(LangOpts, PP); - } - - virtual void EndSourceFile() override { - this->LangOpts = nullptr; - Passthrough->EndSourceFile(); - } - - virtual bool IncludeInDiagnosticCounts() const override { - return Passthrough->IncludeInDiagnosticCounts(); - } - -private: - static void PrintSourceForLocation(const SourceLocation &Loc, - SourceManager &SM) { - const char *LocData = SM.getCharacterData(Loc, /*Invalid=*/nullptr); - unsigned LocColumn = - SM.getSpellingColumnNumber(Loc, /*Invalid=*/nullptr) - 1; - FileID FID = SM.getFileID(Loc); - llvm::MemoryBuffer *Buffer = SM.getBuffer(FID, Loc, /*Invalid=*/nullptr); - - assert(LocData >= Buffer->getBufferStart() && - LocData < Buffer->getBufferEnd()); - - const char *LineBegin = LocData - LocColumn; - - assert(LineBegin >= Buffer->getBufferStart()); - - const char *LineEnd = nullptr; - - for (LineEnd = LineBegin; *LineEnd != '\n' && *LineEnd != '\r' && - LineEnd < Buffer->getBufferEnd(); - ++LineEnd) - ; - - llvm::StringRef LineString(LineBegin, LineEnd - LineBegin); - - llvm::errs() << LineString << '\n'; - std::string Space(LocColumn, ' '); - llvm::errs() << Space.c_str() << '\n'; - } - - virtual void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, - const Diagnostic &Info) override { - if (Info.hasSourceManager() && LangOpts) { - SourceManager &SM = Info.getSourceManager(); - - if (Info.getLocation().isValid()) { - Info.getLocation().print(llvm::errs(), SM); - llvm::errs() << ": "; - } - - SmallString<16> DiagText; - Info.FormatDiagnostic(DiagText); - llvm::errs() << DiagText << '\n'; - - if (Info.getLocation().isValid()) { - PrintSourceForLocation(Info.getLocation(), SM); - } - - for (const CharSourceRange &Range : Info.getRanges()) { - bool Invalid = true; - StringRef Ref = Lexer::getSourceText(Range, SM, *LangOpts, &Invalid); - if (!Invalid) { - llvm::errs() << Ref.str() << '\n'; - } - } - } - DiagnosticConsumer::HandleDiagnostic(DiagLevel, Info); - } -}; - -std::unique_ptr -BuildCompilerInstance(ArrayRef ClangArgv) { - auto Ins = llvm::make_unique(); - auto DC = llvm::make_unique(); - const bool ShouldOwnClient = true; - Ins->createDiagnostics(DC.release(), ShouldOwnClient); - - auto Inv = llvm::make_unique(); - - CompilerInvocation::CreateFromArgs(*Inv, ClangArgv.data(), - &ClangArgv.data()[ClangArgv.size()], - Ins->getDiagnostics()); - - Inv->getLangOpts()->CPlusPlus = true; - Inv->getLangOpts()->CPlusPlus11 = true; - Inv->getHeaderSearchOpts().UseLibcxx = true; - Inv->getLangOpts()->Bool = true; - Inv->getLangOpts()->WChar = true; - Inv->getLangOpts()->Blocks = true; - Inv->getLangOpts()->DebuggerSupport = true; - Inv->getLangOpts()->SpellChecking = false; - Inv->getLangOpts()->ThreadsafeStatics = false; - Inv->getLangOpts()->AccessControl = false; - Inv->getLangOpts()->DollarIdents = true; - Inv->getCodeGenOpts().setDebugInfo(codegenoptions::FullDebugInfo); - Inv->getTargetOpts().Triple = llvm::sys::getDefaultTargetTriple(); - - Ins->setInvocation(Inv.release()); - - TargetInfo *TI = TargetInfo::CreateTargetInfo( - Ins->getDiagnostics(), Ins->getInvocation().TargetOpts); - Ins->setTarget(TI); - Ins->getTarget().adjust(Ins->getLangOpts()); - Ins->createFileManager(); - Ins->createSourceManager(Ins->getFileManager()); - Ins->createPreprocessor(TU_Complete); - - return Ins; -} - -std::unique_ptr -BuildASTContext(CompilerInstance &CI, SelectorTable &ST, Builtin::Context &BC) { - auto AST = llvm::make_unique( - CI.getLangOpts(), CI.getSourceManager(), - CI.getPreprocessor().getIdentifierTable(), ST, BC); - AST->InitBuiltinTypes(CI.getTarget()); - return AST; -} - -std::unique_ptr BuildCodeGen(CompilerInstance &CI, - llvm::LLVMContext &LLVMCtx) { - StringRef ModuleName("$__module"); - return std::unique_ptr(CreateLLVMCodeGen( - CI.getDiagnostics(), ModuleName, CI.getHeaderSearchOpts(), - CI.getPreprocessorOpts(), CI.getCodeGenOpts(), LLVMCtx)); -} -} // end namespace - -namespace { -class TestExternalASTSource : public ExternalASTSource { -private: - llvm::ArrayRef> ImportCIs; - std::map> ForwardImporters; - std::map> ReverseImporters; - -public: - TestExternalASTSource( - CompilerInstance &ExpressionCI, - llvm::ArrayRef> ImportCIs) - : ImportCIs(ImportCIs) { - for (const std::unique_ptr &ImportCI : ImportCIs) { - ForwardImporters[ImportCI.get()] = llvm::make_unique( - ExpressionCI.getASTContext(), ExpressionCI.getFileManager(), - ImportCI->getASTContext(), ImportCI->getFileManager(), - /*MinimalImport=*/true); - ReverseImporters[ImportCI.get()] = llvm::make_unique( - ImportCI->getASTContext(), ImportCI->getFileManager(), - ExpressionCI.getASTContext(), ExpressionCI.getFileManager(), - /*MinimalImport=*/true); - } - } - - bool FindExternalVisibleDeclsByName(const DeclContext *DC, - DeclarationName Name) override { - llvm::SmallVector Decls; - - if (isa(DC)) { - for (const std::unique_ptr &I : ImportCIs) { - DeclarationName FromName = ReverseImporters[I.get()]->Import(Name); - DeclContextLookupResult Result = - I->getASTContext().getTranslationUnitDecl()->lookup(FromName); - for (NamedDecl *FromD : Result) { - NamedDecl *D = - llvm::cast(ForwardImporters[I.get()]->Import(FromD)); - Decls.push_back(D); - } - } - } - if (Decls.empty()) { - return false; - } else { - SetExternalVisibleDeclsForName(DC, Name, Decls); - return true; - } - } -}; - -void AddExternalSource( - CompilerInstance &CI, - llvm::ArrayRef> Imports) { - ASTContext &AST = CI.getASTContext(); - auto ES = llvm::make_unique(CI, Imports); - AST.setExternalSource(ES.release()); - AST.getTranslationUnitDecl()->setHasExternalVisibleStorage(); -} - -llvm::Error ParseSource(const std::string &Path, CompilerInstance &CI, - CodeGenerator &CG) { - SourceManager &SM = CI.getSourceManager(); - const FileEntry *FE = CI.getFileManager().getFile(Path); - if (!FE) { - return llvm::make_error( - llvm::Twine("Couldn't open ", Path), std::error_code()); - } - SM.setMainFileID(SM.createFileID(FE, SourceLocation(), SrcMgr::C_User)); - ParseAST(CI.getPreprocessor(), &CG, CI.getASTContext()); - return llvm::Error::success(); -} - -llvm::Expected> -Parse(const std::string &Path, - llvm::ArrayRef> Imports) { - std::vector ClangArgv(ClangArgs.size()); - std::transform(ClangArgs.begin(), ClangArgs.end(), ClangArgv.begin(), - [](const std::string &s) -> const char * { return s.data(); }); - std::unique_ptr CI = - init_convenience::BuildCompilerInstance(ClangArgv); - auto ST = llvm::make_unique(); - auto BC = llvm::make_unique(); - std::unique_ptr AST = - init_convenience::BuildASTContext(*CI, *ST, *BC); - CI->setASTContext(AST.release()); - AddExternalSource(*CI, Imports); - - auto LLVMCtx = llvm::make_unique(); - std::unique_ptr CG = - init_convenience::BuildCodeGen(*CI, *LLVMCtx); - CG->Initialize(CI->getASTContext()); - - CI->getDiagnosticClient().BeginSourceFile(CI->getLangOpts(), - &CI->getPreprocessor()); - if (llvm::Error PE = ParseSource(Path, *CI, *CG)) { - return std::move(PE); - } - CI->getDiagnosticClient().EndSourceFile(); - if (CI->getDiagnosticClient().getNumErrors()) { - return llvm::make_error( - "Errors occured while parsing the expression.", std::error_code()); - } else { - return std::move(CI); - } -} -} // end namespace - -int main(int argc, const char **argv) { - const bool DisableCrashReporting = true; - llvm::sys::PrintStackTraceOnErrorSignal(argv[0], DisableCrashReporting); - llvm::cl::ParseCommandLineOptions(argc, argv); - std::vector> ImportCIs; - for (auto I : Imports) { - llvm::Expected> ImportCI = Parse(I, {}); - if (auto E = ImportCI.takeError()) { - llvm::errs() << llvm::toString(std::move(E)); - exit(-1); - } else { - ImportCIs.push_back(std::move(*ImportCI)); - } - } - llvm::Expected> ExpressionCI = - Parse(Expression, ImportCIs); - if (auto E = ExpressionCI.takeError()) { - llvm::errs() << llvm::toString(std::move(E)); - exit(-1); - } else { - return 0; - } -} -- 2.40.0