From: Sean Callanan Date: Mon, 7 Aug 2017 22:27:30 +0000 (+0000) Subject: This adds the argument --dump-ir to clang-import-test, which allows X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6dad790d8f716b965ba714aa3710af5648069f76;p=clang This adds the argument --dump-ir to clang-import-test, which allows viewing of the final IR. This is useful for confirming that structure layout was correct. I've added two tests: - A test that checks that structs in top-level code are completed correctly during struct layout (they are) - A test that checks that structs defined in function bodies are cpmpleted correctly during struct layout (currently they are not, so this is XFAIL). The second test fails because LookupSameContext() (ExternalASTMerger.cpp) can't find the struct. This is an issue I intend to resolve separately. Differential Revision: https://reviews.llvm.org/D36429 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@310318 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/test/Import/local-struct/Inputs/Callee.cpp b/test/Import/local-struct/Inputs/Callee.cpp new file mode 100644 index 0000000000..96cd2f22e4 --- /dev/null +++ b/test/Import/local-struct/Inputs/Callee.cpp @@ -0,0 +1,12 @@ +struct Bar { + void bar(int _a, bool _b) { + { + struct S { int a; }; + S s = { _a }; + } + { + struct S { bool b; }; + S t = { _b }; + } + }; +}; diff --git a/test/Import/local-struct/test.cpp b/test/Import/local-struct/test.cpp new file mode 100644 index 0000000000..8f6e38138f --- /dev/null +++ b/test/Import/local-struct/test.cpp @@ -0,0 +1,8 @@ +// RUN: clang-import-test -dump-ir -import %S/Inputs/Callee.cpp -expression %s | FileCheck %s +// XFAIL: * +// CHECK: %struct.S = type { i +// CHECK: %struct.S.0 = type { i1 } + +void foo() { + return Bar().bar(3, true); +} diff --git a/test/Import/struct-layout/Inputs/Callee.cpp b/test/Import/struct-layout/Inputs/Callee.cpp new file mode 100644 index 0000000000..62422af6c2 --- /dev/null +++ b/test/Import/struct-layout/Inputs/Callee.cpp @@ -0,0 +1,9 @@ +struct S { + int a; +}; + +struct Bar { + void bar(int _a) { + S s = { _a }; + }; +}; diff --git a/test/Import/struct-layout/test.cpp b/test/Import/struct-layout/test.cpp new file mode 100644 index 0000000000..698d0609fa --- /dev/null +++ b/test/Import/struct-layout/test.cpp @@ -0,0 +1,6 @@ +// RUN: clang-import-test -dump-ir -import %S/Inputs/Callee.cpp -expression %s | FileCheck %s +// CHECK: %struct.S = type { i + +void foo() { + return Bar().bar(3); +} diff --git a/tools/clang-import-test/clang-import-test.cpp b/tools/clang-import-test/clang-import-test.cpp index 286cb05219..186a7c82dc 100644 --- a/tools/clang-import-test/clang-import-test.cpp +++ b/tools/clang-import-test/clang-import-test.cpp @@ -27,6 +27,7 @@ #include "clang/Parse/ParseAST.h" #include "llvm/IR/LLVMContext.h" +#include "llvm/IR/Module.h" #include "llvm/Support/CommandLine.h" #include "llvm/Support/Error.h" #include "llvm/Support/Host.h" @@ -63,6 +64,10 @@ static llvm::cl::opt DumpAST("dump-ast", llvm::cl::init(false), llvm::cl::desc("Dump combined AST")); +static llvm::cl::opt +DumpIR("dump-ir", llvm::cl::init(false), + llvm::cl::desc("Dump IR from final parse")); + namespace init_convenience { class TestDiagnosticConsumer : public DiagnosticConsumer { private: @@ -264,7 +269,7 @@ llvm::Error ParseSource(const std::string &Path, CompilerInstance &CI, llvm::Expected> Parse(const std::string &Path, llvm::ArrayRef> Imports, - bool ShouldDumpAST) { + bool ShouldDumpAST, bool ShouldDumpIR) { std::unique_ptr CI = init_convenience::BuildCompilerInstance(); auto ST = llvm::make_unique(); @@ -279,6 +284,7 @@ Parse(const std::string &Path, auto LLVMCtx = llvm::make_unique(); ASTConsumers.push_back(init_convenience::BuildCodeGen(*CI, *LLVMCtx)); + auto &CG = *static_cast(ASTConsumers.back().get()); if (ShouldDumpAST) ASTConsumers.push_back(CreateASTDumper("", true, false, false)); @@ -292,6 +298,8 @@ Parse(const std::string &Path, return std::move(PE); } CI->getDiagnosticClient().EndSourceFile(); + if (ShouldDumpIR) + CG.GetModule()->print(llvm::outs(), nullptr); if (CI->getDiagnosticClient().getNumErrors()) { return llvm::make_error( "Errors occured while parsing the expression.", std::error_code()); @@ -309,7 +317,7 @@ int main(int argc, const char **argv) { std::vector> ImportCIs; for (auto I : Imports) { llvm::Expected> ImportCI = - Parse(I, {}, false); + Parse(I, {}, false, false); if (auto E = ImportCI.takeError()) { llvm::errs() << llvm::toString(std::move(E)); exit(-1); @@ -325,7 +333,7 @@ int main(int argc, const char **argv) { } } llvm::Expected> ExpressionCI = - Parse(Expression, Direct ? ImportCIs : IndirectCIs, DumpAST); + Parse(Expression, Direct ? ImportCIs : IndirectCIs, DumpAST, DumpIR); if (auto E = ExpressionCI.takeError()) { llvm::errs() << llvm::toString(std::move(E)); exit(-1);