[PATCH] D36429: [clang-import-test] Option to dump the IR for an expression

2017-08-07 Thread Sean Callanan via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL310318: This adds the argument --dump-ir to 
clang-import-test, which allows  (authored by spyffe).

Changed prior to commit:
  https://reviews.llvm.org/D36429?vs=110095=110104#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D36429

Files:
  cfe/trunk/test/Import/local-struct/Inputs/Callee.cpp
  cfe/trunk/test/Import/local-struct/test.cpp
  cfe/trunk/test/Import/struct-layout/Inputs/Callee.cpp
  cfe/trunk/test/Import/struct-layout/test.cpp
  cfe/trunk/tools/clang-import-test/clang-import-test.cpp

Index: cfe/trunk/tools/clang-import-test/clang-import-test.cpp
===
--- cfe/trunk/tools/clang-import-test/clang-import-test.cpp
+++ cfe/trunk/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 @@
 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::Expected
 Parse(const std::string ,
   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 @@
 
   auto LLVMCtx = llvm::make_unique();
   ASTConsumers.push_back(init_convenience::BuildCodeGen(*CI, *LLVMCtx));
+  auto  = *static_cast(ASTConsumers.back().get());
 
   if (ShouldDumpAST)
 ASTConsumers.push_back(CreateASTDumper("", true, false, false));
@@ -292,6 +298,8 @@
 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 @@
   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 @@
 }
   }
   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);
Index: cfe/trunk/test/Import/local-struct/Inputs/Callee.cpp
===
--- cfe/trunk/test/Import/local-struct/Inputs/Callee.cpp
+++ cfe/trunk/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 };
+}
+  };
+};
Index: cfe/trunk/test/Import/local-struct/test.cpp
===
--- cfe/trunk/test/Import/local-struct/test.cpp
+++ cfe/trunk/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);
+}
Index: cfe/trunk/test/Import/struct-layout/Inputs/Callee.cpp
===
--- cfe/trunk/test/Import/struct-layout/Inputs/Callee.cpp
+++ cfe/trunk/test/Import/struct-layout/Inputs/Callee.cpp
@@ -0,0 +1,9 @@
+struct S {
+  int a;
+};
+
+struct Bar {
+  void bar(int _a) {
+S s = { _a };
+  };
+};
Index: cfe/trunk/test/Import/struct-layout/test.cpp
===
--- cfe/trunk/test/Import/struct-layout/test.cpp
+++ cfe/trunk/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);
+}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D36429: [clang-import-test] Option to dump the IR for an expression

2017-08-07 Thread Lang Hames via Phabricator via cfe-commits
lhames accepted this revision.
lhames added a comment.
This revision is now accepted and ready to land.

LGTM!




Comment at: tools/clang-import-test/clang-import-test.cpp:301-303
+  if (ShouldDumpIR) {
+CG.GetModule()->print(llvm::outs(), nullptr);
+  }

LLVM style says no braces for single line conditionals. :)


https://reviews.llvm.org/D36429



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D36429: [clang-import-test] Option to dump the IR for an expression

2017-08-07 Thread Sean Callanan via Phabricator via cfe-commits
spyffe updated this revision to Diff 110095.
spyffe added a comment.

Eliminate sensitive dependence on `sizeof(int)`.  `bool` should still be 
rendered as `i1` though.


https://reviews.llvm.org/D36429

Files:
  test/Import/local-struct/Inputs/Callee.cpp
  test/Import/local-struct/test.cpp
  test/Import/struct-layout/Inputs/Callee.cpp
  test/Import/struct-layout/test.cpp
  tools/clang-import-test/clang-import-test.cpp

Index: tools/clang-import-test/clang-import-test.cpp
===
--- tools/clang-import-test/clang-import-test.cpp
+++ 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 @@
 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::Expected
 Parse(const std::string ,
   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 @@
 
   auto LLVMCtx = llvm::make_unique();
   ASTConsumers.push_back(init_convenience::BuildCodeGen(*CI, *LLVMCtx));
+  auto  = *static_cast(ASTConsumers.back().get());
 
   if (ShouldDumpAST)
 ASTConsumers.push_back(CreateASTDumper("", true, false, false));
@@ -292,6 +298,9 @@
 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 +318,7 @@
   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 +334,7 @@
 }
   }
   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);
Index: test/Import/struct-layout/test.cpp
===
--- test/Import/struct-layout/test.cpp
+++ test/Import/struct-layout/test.cpp
@@ -1,7 +1,6 @@
-// RUN: clang-import-test -dump-ast -import %S/Inputs/Hierarchy.cpp -expression %s | FileCheck %s
+// RUN: clang-import-test -dump-ir -import %S/Inputs/Callee.cpp -expression %s | FileCheck %s
+// CHECK: %struct.S = type { i
 
-// CHECK: Overrides:{{.*}}Base::foo
-
 void foo() {
-  Derived d;
+  return Bar().bar(3);
 }
Index: test/Import/struct-layout/Inputs/Callee.cpp
===
--- test/Import/struct-layout/Inputs/Callee.cpp
+++ test/Import/struct-layout/Inputs/Callee.cpp
@@ -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 };
+  };
 };
Index: test/Import/local-struct/test.cpp
===
--- test/Import/local-struct/test.cpp
+++ test/Import/local-struct/test.cpp
@@ -1,7 +1,8 @@
-// RUN: clang-import-test -dump-ast -import %S/Inputs/Hierarchy.cpp -expression %s | FileCheck %s
+// 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 }
 
-// CHECK: Overrides:{{.*}}Base::foo
-
 void foo() {
-  Derived d;
+  return Bar().bar(3, true);
 }
Index: test/Import/local-struct/Inputs/Callee.cpp
===
--- test/Import/local-struct/Inputs/Callee.cpp
+++ test/Import/local-struct/Inputs/Callee.cpp
@@ -1,9 +1,12 @@
-class Base {
-public:
-  virtual void foo() {}
+struct Bar {
+  void bar(int _a, bool _b) {
+{
+  struct S { int a; };
+  S s = { _a };
+}
+{
+  struct S { bool b; };
+  S t = { _b };
+}
+  };
 };
-
-class Derived : public Base {
-public:
-  void foo() override {}
-};
___
cfe-commits mailing list
cfe-commits@lists.llvm.org

[PATCH] D36429: [clang-import-test] Option to dump the IR for an expression

2017-08-07 Thread Sean Callanan via Phabricator via cfe-commits
spyffe updated this revision to Diff 110093.
spyffe added a comment.

Added a passing test for a global struct, so we have something that'll fail if 
the IR dumping breaks.


https://reviews.llvm.org/D36429

Files:
  test/Import/local-struct/Inputs/Callee.cpp
  test/Import/local-struct/test.cpp
  test/Import/struct-layout/Inputs/Callee.cpp
  test/Import/struct-layout/test.cpp
  tools/clang-import-test/clang-import-test.cpp

Index: tools/clang-import-test/clang-import-test.cpp
===
--- tools/clang-import-test/clang-import-test.cpp
+++ 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 @@
 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::Expected
 Parse(const std::string ,
   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 @@
 
   auto LLVMCtx = llvm::make_unique();
   ASTConsumers.push_back(init_convenience::BuildCodeGen(*CI, *LLVMCtx));
+  auto  = *static_cast(ASTConsumers.back().get());
 
   if (ShouldDumpAST)
 ASTConsumers.push_back(CreateASTDumper("", true, false, false));
@@ -292,6 +298,9 @@
 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 +318,7 @@
   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 +334,7 @@
 }
   }
   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);
Index: test/Import/struct-layout/test.cpp
===
--- test/Import/struct-layout/test.cpp
+++ test/Import/struct-layout/test.cpp
@@ -1,7 +1,6 @@
-// RUN: clang-import-test -dump-ast -import %S/Inputs/Hierarchy.cpp -expression %s | FileCheck %s
+// RUN: clang-import-test -dump-ir -import %S/Inputs/Callee.cpp -expression %s | FileCheck %s
+// CHECK: %struct.S = type { i32 }
 
-// CHECK: Overrides:{{.*}}Base::foo
-
 void foo() {
-  Derived d;
+  return Bar().bar(3);
 }
Index: test/Import/struct-layout/Inputs/Callee.cpp
===
--- test/Import/struct-layout/Inputs/Callee.cpp
+++ test/Import/struct-layout/Inputs/Callee.cpp
@@ -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 };
+  };
 };
Index: test/Import/local-struct/test.cpp
===
--- test/Import/local-struct/test.cpp
+++ test/Import/local-struct/test.cpp
@@ -1,7 +1,8 @@
-// RUN: clang-import-test -dump-ast -import %S/Inputs/Hierarchy.cpp -expression %s | FileCheck %s
+// RUN: clang-import-test -dump-ir -import %S/Inputs/Callee.cpp -expression %s | FileCheck %s
+// XFAIL: *
+// CHECK: %struct.S = type { i32 }
+// CHECK: %struct.S.0 = type { i8 }
 
-// CHECK: Overrides:{{.*}}Base::foo
-
 void foo() {
-  Derived d;
+  return Bar().bar(3, true);
 }
Index: test/Import/local-struct/Inputs/Callee.cpp
===
--- test/Import/local-struct/Inputs/Callee.cpp
+++ test/Import/local-struct/Inputs/Callee.cpp
@@ -1,9 +1,12 @@
-class Base {
-public:
-  virtual void foo() {}
+struct Bar {
+  void bar(int _a, bool _b) {
+{
+  struct S { int a; };
+  S s = { _a };
+}
+{
+  struct S { bool b; };
+  S t = { _b };
+}
+  };
 };
-
-class Derived : public Base {
-public:
-  void foo() override {}
-};
___
cfe-commits mailing list
cfe-commits@lists.llvm.org

[PATCH] D36429: [clang-import-test] Option to dump the IR for an expression

2017-08-07 Thread Sean Callanan via Phabricator via cfe-commits
spyffe created this revision.

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 an XFAILed test that exercises this, checking that a struct defined 
inside a function body has the right fields.  Currently it does not because 
`LookupSameContext()` (ExternalASTMerger.cpp) can't find the struct.  This is 
an issue I intend to resolve separately.


Repository:
  rL LLVM

https://reviews.llvm.org/D36429

Files:
  test/Import/local-struct/Inputs/Callee.cpp
  test/Import/local-struct/test.cpp
  tools/clang-import-test/clang-import-test.cpp

Index: tools/clang-import-test/clang-import-test.cpp
===
--- tools/clang-import-test/clang-import-test.cpp
+++ 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 @@
 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::Expected
 Parse(const std::string ,
   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 @@
 
   auto LLVMCtx = llvm::make_unique();
   ASTConsumers.push_back(init_convenience::BuildCodeGen(*CI, *LLVMCtx));
+  auto  = *static_cast(ASTConsumers.back().get());
 
   if (ShouldDumpAST)
 ASTConsumers.push_back(CreateASTDumper("", true, false, false));
@@ -292,6 +298,9 @@
 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 +318,7 @@
   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 +334,7 @@
 }
   }
   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);
Index: test/Import/local-struct/test.cpp
===
--- test/Import/local-struct/test.cpp
+++ test/Import/local-struct/test.cpp
@@ -1,7 +1,8 @@
-// RUN: clang-import-test -dump-ast -import %S/Inputs/Hierarchy.cpp -expression %s | FileCheck %s
+// RUN: clang-import-test -dump-ir -import %S/Inputs/Callee.cpp -expression %s | FileCheck %s
+// XFAIL: *
+// CHECK: %struct.S = type { i32 }
+// CHECK: %struct.S.0 = type { i8 }
 
-// CHECK: Overrides:{{.*}}Base::foo
-
 void foo() {
-  Derived d;
+  return Bar().bar(3, true);
 }
Index: test/Import/local-struct/Inputs/Callee.cpp
===
--- test/Import/local-struct/Inputs/Callee.cpp
+++ test/Import/local-struct/Inputs/Callee.cpp
@@ -1,9 +1,12 @@
-class Base {
-public:
-  virtual void foo() {}
+struct Bar {
+  void bar(int _a, bool _b) {
+{
+  struct S { int a; };
+  S s = { _a };
+}
+{
+  struct S { bool b; };
+  S t = { _b };
+}
+  };
 };
-
-class Derived : public Base {
-public:
-  void foo() override {}
-};
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits