r310318 - This adds the argument --dump-ir to clang-import-test, which allows
Sean Callanan via cfe-commits
cfe-commits at lists.llvm.org
Mon Aug 7 15:27:30 PDT 2017
Author: spyffe
Date: Mon Aug 7 15:27:30 2017
New Revision: 310318
URL: http://llvm.org/viewvc/llvm-project?rev=310318&view=rev
Log:
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
Added:
cfe/trunk/test/Import/local-struct/
- copied from r310276, cfe/trunk/test/Import/import-overrides/
cfe/trunk/test/Import/local-struct/Inputs/Callee.cpp
- copied, changed from r310276, cfe/trunk/test/Import/import-overrides/Inputs/Hierarchy.cpp
cfe/trunk/test/Import/struct-layout/
- copied from r310276, cfe/trunk/test/Import/import-overrides/
cfe/trunk/test/Import/struct-layout/Inputs/Callee.cpp
- copied, changed from r310276, cfe/trunk/test/Import/import-overrides/Inputs/Hierarchy.cpp
Removed:
cfe/trunk/test/Import/local-struct/Inputs/Hierarchy.cpp
cfe/trunk/test/Import/struct-layout/Inputs/Hierarchy.cpp
Modified:
cfe/trunk/test/Import/local-struct/test.cpp
cfe/trunk/test/Import/struct-layout/test.cpp
cfe/trunk/tools/clang-import-test/clang-import-test.cpp
Copied: cfe/trunk/test/Import/local-struct/Inputs/Callee.cpp (from r310276, cfe/trunk/test/Import/import-overrides/Inputs/Hierarchy.cpp)
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Import/local-struct/Inputs/Callee.cpp?p2=cfe/trunk/test/Import/local-struct/Inputs/Callee.cpp&p1=cfe/trunk/test/Import/import-overrides/Inputs/Hierarchy.cpp&r1=310276&r2=310318&rev=310318&view=diff
==============================================================================
--- cfe/trunk/test/Import/import-overrides/Inputs/Hierarchy.cpp (original)
+++ cfe/trunk/test/Import/local-struct/Inputs/Callee.cpp Mon Aug 7 15:27:30 2017
@@ -1,9 +1,12 @@
-class Base {
-public:
- virtual void foo() {}
-};
-
-class Derived : public Base {
-public:
- void foo() override {}
+struct Bar {
+ void bar(int _a, bool _b) {
+ {
+ struct S { int a; };
+ S s = { _a };
+ }
+ {
+ struct S { bool b; };
+ S t = { _b };
+ }
+ };
};
Removed: cfe/trunk/test/Import/local-struct/Inputs/Hierarchy.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Import/import-overrides/Inputs/Hierarchy.cpp?rev=310276&view=auto
==============================================================================
--- cfe/trunk/test/Import/local-struct/Inputs/Hierarchy.cpp (original)
+++ cfe/trunk/test/Import/local-struct/Inputs/Hierarchy.cpp (removed)
@@ -1,9 +0,0 @@
-class Base {
-public:
- virtual void foo() {}
-};
-
-class Derived : public Base {
-public:
- void foo() override {}
-};
Modified: cfe/trunk/test/Import/local-struct/test.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Import/local-struct/test.cpp?rev=310318&r1=310276&r2=310318&view=diff
==============================================================================
--- cfe/trunk/test/Import/local-struct/test.cpp (original)
+++ cfe/trunk/test/Import/local-struct/test.cpp Mon Aug 7 15:27:30 2017
@@ -1,7 +1,8 @@
-// RUN: clang-import-test -dump-ast -import %S/Inputs/Hierarchy.cpp -expression %s | FileCheck %s
-
-// CHECK: Overrides:{{.*}}Base::foo
+// 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() {
- Derived d;
+ return Bar().bar(3, true);
}
Copied: cfe/trunk/test/Import/struct-layout/Inputs/Callee.cpp (from r310276, cfe/trunk/test/Import/import-overrides/Inputs/Hierarchy.cpp)
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Import/struct-layout/Inputs/Callee.cpp?p2=cfe/trunk/test/Import/struct-layout/Inputs/Callee.cpp&p1=cfe/trunk/test/Import/import-overrides/Inputs/Hierarchy.cpp&r1=310276&r2=310318&rev=310318&view=diff
==============================================================================
--- cfe/trunk/test/Import/import-overrides/Inputs/Hierarchy.cpp (original)
+++ cfe/trunk/test/Import/struct-layout/Inputs/Callee.cpp Mon Aug 7 15:27:30 2017
@@ -1,9 +1,9 @@
-class Base {
-public:
- virtual void foo() {}
+struct S {
+ int a;
};
-class Derived : public Base {
-public:
- void foo() override {}
+struct Bar {
+ void bar(int _a) {
+ S s = { _a };
+ };
};
Removed: cfe/trunk/test/Import/struct-layout/Inputs/Hierarchy.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Import/import-overrides/Inputs/Hierarchy.cpp?rev=310276&view=auto
==============================================================================
--- cfe/trunk/test/Import/struct-layout/Inputs/Hierarchy.cpp (original)
+++ cfe/trunk/test/Import/struct-layout/Inputs/Hierarchy.cpp (removed)
@@ -1,9 +0,0 @@
-class Base {
-public:
- virtual void foo() {}
-};
-
-class Derived : public Base {
-public:
- void foo() override {}
-};
Modified: cfe/trunk/test/Import/struct-layout/test.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Import/struct-layout/test.cpp?rev=310318&r1=310276&r2=310318&view=diff
==============================================================================
--- cfe/trunk/test/Import/struct-layout/test.cpp (original)
+++ cfe/trunk/test/Import/struct-layout/test.cpp Mon Aug 7 15:27:30 2017
@@ -1,7 +1,6 @@
-// RUN: clang-import-test -dump-ast -import %S/Inputs/Hierarchy.cpp -expression %s | FileCheck %s
-
-// CHECK: Overrides:{{.*}}Base::foo
+// RUN: clang-import-test -dump-ir -import %S/Inputs/Callee.cpp -expression %s | FileCheck %s
+// CHECK: %struct.S = type { i
void foo() {
- Derived d;
+ return Bar().bar(3);
}
Modified: cfe/trunk/tools/clang-import-test/clang-import-test.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-import-test/clang-import-test.cpp?rev=310318&r1=310317&r2=310318&view=diff
==============================================================================
--- cfe/trunk/tools/clang-import-test/clang-import-test.cpp (original)
+++ cfe/trunk/tools/clang-import-test/clang-import-test.cpp Mon Aug 7 15:27:30 2017
@@ -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<bool>
DumpAST("dump-ast", llvm::cl::init(false),
llvm::cl::desc("Dump combined AST"));
+static llvm::cl::opt<bool>
+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::strin
llvm::Expected<std::unique_ptr<CompilerInstance>>
Parse(const std::string &Path,
llvm::ArrayRef<std::unique_ptr<CompilerInstance>> Imports,
- bool ShouldDumpAST) {
+ bool ShouldDumpAST, bool ShouldDumpIR) {
std::unique_ptr<CompilerInstance> CI =
init_convenience::BuildCompilerInstance();
auto ST = llvm::make_unique<SelectorTable>();
@@ -279,6 +284,7 @@ Parse(const std::string &Path,
auto LLVMCtx = llvm::make_unique<llvm::LLVMContext>();
ASTConsumers.push_back(init_convenience::BuildCodeGen(*CI, *LLVMCtx));
+ auto &CG = *static_cast<CodeGenerator*>(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<llvm::StringError>(
"Errors occured while parsing the expression.", std::error_code());
@@ -309,7 +317,7 @@ int main(int argc, const char **argv) {
std::vector<std::unique_ptr<CompilerInstance>> ImportCIs;
for (auto I : Imports) {
llvm::Expected<std::unique_ptr<CompilerInstance>> 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<std::unique_ptr<CompilerInstance>> 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);
More information about the cfe-commits
mailing list