[PATCH] D59745: [NFC] Move writeFuncOrVarName out of class CodegenNameGenerator so that it can be reused more easily.

2019-03-23 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi created this revision.
plotfi added reviewers: compnerd, akyrtzi.
Herald added subscribers: cfe-commits, jdoerfert, arphaman.
Herald added a project: clang.

I simply want a helper function to use for printing out mangled Decl names. I 
think this could be a pretty simple straightforward patch to do so, in an NFC 
manner.


Repository:
  rC Clang

https://reviews.llvm.org/D59745

Files:
  clang/include/clang/Index/CodegenNameGenerator.h
  clang/lib/Index/CodegenNameGenerator.cpp


Index: clang/lib/Index/CodegenNameGenerator.cpp
===
--- clang/lib/Index/CodegenNameGenerator.cpp
+++ clang/lib/Index/CodegenNameGenerator.cpp
@@ -24,6 +24,29 @@
 using namespace clang;
 using namespace clang::index;
 
+namespace clang {
+namespace index {
+bool writeFuncOrVarName(MangleContext *MC, const NamedDecl *D,
+raw_ostream &OS) {
+  if (MC->shouldMangleDeclName(D)) {
+if (const auto *CtorD = dyn_cast(D))
+  MC->mangleCXXCtor(CtorD, Ctor_Complete, OS);
+else if (const auto *DtorD = dyn_cast(D))
+  MC->mangleCXXDtor(DtorD, Dtor_Complete, OS);
+else
+  MC->mangleName(D, OS);
+return false;
+  } else {
+IdentifierInfo *II = D->getIdentifier();
+if (!II)
+  return true;
+OS << II->getName();
+return false;
+  }
+}
+} // namespace index
+} // namespace clang
+
 struct CodegenNameGenerator::Implementation {
   std::unique_ptr MC;
   llvm::DataLayout DL;
@@ -147,21 +170,7 @@
 
 private:
   bool writeFuncOrVarName(const NamedDecl *D, raw_ostream &OS) {
-if (MC->shouldMangleDeclName(D)) {
-  if (const auto *CtorD = dyn_cast(D))
-MC->mangleCXXCtor(CtorD, Ctor_Complete, OS);
-  else if (const auto *DtorD = dyn_cast(D))
-MC->mangleCXXDtor(DtorD, Dtor_Complete, OS);
-  else
-MC->mangleName(D, OS);
-  return false;
-} else {
-  IdentifierInfo *II = D->getIdentifier();
-  if (!II)
-return true;
-  OS << II->getName();
-  return false;
-}
+return clang::index::writeFuncOrVarName(MC.get(), D, OS);
   }
 
   void writeObjCClassName(const ObjCInterfaceDecl *D, raw_ostream &OS) {
Index: clang/include/clang/Index/CodegenNameGenerator.h
===
--- clang/include/clang/Index/CodegenNameGenerator.h
+++ clang/include/clang/Index/CodegenNameGenerator.h
@@ -13,7 +13,10 @@
 #ifndef LLVM_CLANG_INDEX_CODEGENNAMEGENERATOR_H
 #define LLVM_CLANG_INDEX_CODEGENNAMEGENERATOR_H
 
+#include "clang/AST/DeclCXX.h"
+#include "clang/AST/Mangle.h"
 #include "clang/Basic/LLVM.h"
+#include "llvm/Support/raw_ostream.h"
 #include 
 #include 
 #include 
@@ -24,6 +27,8 @@
 
 namespace index {
 
+bool writeFuncOrVarName(MangleContext *MC, const NamedDecl *D, raw_ostream 
&OS);
+
 class CodegenNameGenerator {
 public:
   explicit CodegenNameGenerator(ASTContext &Ctx);


Index: clang/lib/Index/CodegenNameGenerator.cpp
===
--- clang/lib/Index/CodegenNameGenerator.cpp
+++ clang/lib/Index/CodegenNameGenerator.cpp
@@ -24,6 +24,29 @@
 using namespace clang;
 using namespace clang::index;
 
+namespace clang {
+namespace index {
+bool writeFuncOrVarName(MangleContext *MC, const NamedDecl *D,
+raw_ostream &OS) {
+  if (MC->shouldMangleDeclName(D)) {
+if (const auto *CtorD = dyn_cast(D))
+  MC->mangleCXXCtor(CtorD, Ctor_Complete, OS);
+else if (const auto *DtorD = dyn_cast(D))
+  MC->mangleCXXDtor(DtorD, Dtor_Complete, OS);
+else
+  MC->mangleName(D, OS);
+return false;
+  } else {
+IdentifierInfo *II = D->getIdentifier();
+if (!II)
+  return true;
+OS << II->getName();
+return false;
+  }
+}
+} // namespace index
+} // namespace clang
+
 struct CodegenNameGenerator::Implementation {
   std::unique_ptr MC;
   llvm::DataLayout DL;
@@ -147,21 +170,7 @@
 
 private:
   bool writeFuncOrVarName(const NamedDecl *D, raw_ostream &OS) {
-if (MC->shouldMangleDeclName(D)) {
-  if (const auto *CtorD = dyn_cast(D))
-MC->mangleCXXCtor(CtorD, Ctor_Complete, OS);
-  else if (const auto *DtorD = dyn_cast(D))
-MC->mangleCXXDtor(DtorD, Dtor_Complete, OS);
-  else
-MC->mangleName(D, OS);
-  return false;
-} else {
-  IdentifierInfo *II = D->getIdentifier();
-  if (!II)
-return true;
-  OS << II->getName();
-  return false;
-}
+return clang::index::writeFuncOrVarName(MC.get(), D, OS);
   }
 
   void writeObjCClassName(const ObjCInterfaceDecl *D, raw_ostream &OS) {
Index: clang/include/clang/Index/CodegenNameGenerator.h
===
--- clang/include/clang/Index/CodegenNameGenerator.h
+++ clang/include/clang/Index/CodegenNameGenerator.h
@@ -13,7 +13,10 @@
 #ifndef LLVM_CLANG_INDEX_CODEGENNAMEGENERATOR_H
 #define LLVM_CLANG_INDEX_CODEGENNAMEGENERATOR_H
 
+#includ

[PATCH] D59745: [NFC] Move writeFuncOrVarName out of class CodegenNameGenerator so that it can be reused more easily.

2019-03-24 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi abandoned this revision.
plotfi added a comment.

Found a better way to do what I needed without this unnecessary change.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D59745/new/

https://reviews.llvm.org/D59745



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


[PATCH] D60974: Clang IFSO driver action.

2019-04-22 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi created this revision.
Herald added subscribers: cfe-commits, eraman, mgorny.
Herald added a project: clang.

This enables -emit-ifso to generate an interface library for each .o file. 
Currently it just writes a text file with the mangled names in it.


Repository:
  rC Clang

https://reviews.llvm.org/D60974

Files:
  clang/include/clang/Driver/Options.td
  clang/include/clang/Driver/Types.def
  clang/include/clang/Frontend/FrontendActions.h
  clang/include/clang/Frontend/FrontendOptions.h
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CMakeLists.txt
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Frontend/FrontendActions.cpp
  clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
  clang/test/IFSO/foo-inline.h
  clang/test/IFSO/foo.cpp

Index: clang/test/IFSO/foo.cpp
===
--- /dev/null
+++ clang/test/IFSO/foo.cpp
@@ -0,0 +1,53 @@
+// RUN: %clang -emit-ifso -fvisibility=hidden %s -o - | FileCheck --check-prefix=CHECK-HIDDEN %s
+// RUN: %clang -emit-ifso %s -o - | FileCheck %s
+
+// CHECK-HIDDEN-NOT: __Z4fbarff
+// CHECK: __Z4fbarff
+
+
+
+
+// CHECK-HIDDEN-NOT: __Z3fooii
+// CHECK-NOT:__Z3fooii
+
+
+
+#include "foo-inline.h"
+
+__attribute__ ((visibility ("hidden"))) int foo(int a, int b) { return a + b; }
+__attribute__ ((visibility ("default"))) int foo_default_visi(int a, int b) { return a + b; }
+
+
+__attribute__ ((visibility ("default"))) int fvih_1(int a, int b) { return a + fvih(); }
+
+int dataA = 34;
+
+namespace baz {
+  template 
+  T add(T a, T b) {
+return a + b;
+  }
+}
+
+namespace n {
+  template 
+  struct __attribute__((__visibility__("default"))) S {
+S() = default;
+~S() = default;
+int __attribute__((__visibility__(("default" func() const { return 32; }
+int __attribute__((__visibility__(("hidden" operator()() const { return 53; }
+  };
+}
+
+template  T neverUsed(T t) { return t + 2; }
+
+template<> int neverUsed(int t);
+
+void g() { n::S()(); }
+
+namespace qux {
+int bar(int a, int b) { return baz::add(a, b); }
+}
+
+float fbar(float a, float b) { return baz::add(a, b); }
+
Index: clang/test/IFSO/foo-inline.h
===
--- /dev/null
+++ clang/test/IFSO/foo-inline.h
@@ -0,0 +1,6 @@
+
+inline int fvih() {
+static int fortytwo = 42;
+  return fortytwo;
+}
+
Index: clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
===
--- clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
+++ clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
@@ -64,6 +64,7 @@
   case GenerateHeaderModule:
 return llvm::make_unique();
   case GeneratePCH:return llvm::make_unique();
+  case GenerateIFSO:   return llvm::make_unique();
   case InitOnly:   return llvm::make_unique();
   case ParseSyntaxOnly:return llvm::make_unique();
   case ModuleFileInfo: return llvm::make_unique();
Index: clang/lib/Frontend/FrontendActions.cpp
===
--- clang/lib/Frontend/FrontendActions.cpp
+++ clang/lib/Frontend/FrontendActions.cpp
@@ -25,6 +25,8 @@
 #include "llvm/Support/Path.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Support/YAMLTraits.h"
+#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/Index/CodegenNameGenerator.h"
 #include 
 #include 
 
@@ -158,6 +160,136 @@
   return true;
 }
 
+class IFSOFunctionsConsumer : public ASTConsumer {
+  CompilerInstance &Instance;
+  StringRef InFile = "";
+  std::set ParsedTemplates;
+
+  enum RootDeclOrigin { TopLevel = 0, FromTU = 1, IsLate = 2 };
+
+  template 
+  bool WriteNamedDecl(const NamedDecl *ND, raw_pwrite_stream &OS, int RDO) {
+if (!isa(ND))
+  return false;
+if (ND->getVisibility() != DefaultVisibility)
+  return true;
+// If this is a FunctionDecl that is dependent on a template parameter, then
+// don't get the symbol because we can only export specializations.
+bool IsRDOLate = (RDO & IsLate);
+if (const auto *FD = dyn_cast(ND))
+  if (FD->isDependentContext() && !IsRDOLate)
+return true;
+index::CodegenNameGenerator CGNameGen(ND->getASTContext());
+std::string MangledName = CGNameGen.getName(ND);
+OS << (IsRDOLate ? "late-parsed-decl: " : "")
+   << (IsRDOLate ? ND->getNameAsString() : MangledName) << "\n";
+// For now, lets just dump the -fdelayed-template-parsing decls until we
+// decide how to handle them.
+if (IsRDOLate)
+  ND->dump();
+return true;
+  }
+
+  template 
+  bool HandleSomeDecl(const NamedDecl *ND, raw_pwrite_stream &OS,
+  int RDO) {
+if (!isa(ND))
+  return false;
+for (auto *I : cast(ND)->decls())
+  HandleNamedDecl(dyn_cast(I), OS, RDO);
+return true;
+  }
+
+  template 
+  bool HandleSomeDeclSpec(const NamedDecl *ND,

[PATCH] D60974: Clang IFSO driver action.

2019-04-22 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi marked an inline comment as done.
plotfi added inline comments.



Comment at: clang/lib/Frontend/FrontendActions.cpp:185
+OS << (IsRDOLate ? "late-parsed-decl: " : "")
+   << (IsRDOLate ? ND->getNameAsString() : MangledName) << "\n";
+// For now, lets just dump the -fdelayed-template-parsing decls until we

Still feeling out what the proper format should be. Might just go with yaml for 
now. 


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60974/new/

https://reviews.llvm.org/D60974



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


[PATCH] D60974: Clang IFSO driver action.

2019-04-22 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi added a comment.

In D60974#1474591 , @jakehehrlich 
wrote:

> Can you elaborate on the use case for this? Like can you explain end to end 
> how this would be used?


There are a few that I have in mind.

1. -emit-ifso could be added to a build to produce .so files as part of a 
device SDK (where we don't want to ship the runnable bits in the SDK, we ship 
those on the device updates).
2. -emit-ifso could be added to whatever the existing set of build flags are to 
be run as a pre-build step to produce tapi-like .so files that break up build 
dependencies.
3. -emit-ifso -fvisibility=hidden could added to the invocation to disallow 
usage of non-public apis.

The way we are thinking it would work is similar to the dwos and .o files where 
you get one .ifso for each TU, then have a link-action that merges the mangled 
names and produces the .so file.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60974/new/

https://reviews.llvm.org/D60974



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


[PATCH] D60974: Clang IFSO driver action.

2019-04-23 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi updated this revision to Diff 196291.
plotfi added a comment.
Herald added a subscriber: mgrang.

I've added an output format. The YAML coming out of -emit-ifso can now run 
through yaml2obj to produce a striped .o file. Those .o files can be handled by 
an existing linker.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60974/new/

https://reviews.llvm.org/D60974

Files:
  clang/include/clang/Driver/Options.td
  clang/include/clang/Driver/Types.def
  clang/include/clang/Frontend/FrontendActions.h
  clang/include/clang/Frontend/FrontendOptions.h
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CMakeLists.txt
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Frontend/FrontendActions.cpp
  clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
  clang/test/IFSO/foo-inline.h
  clang/test/IFSO/foo.cpp

Index: clang/test/IFSO/foo.cpp
===
--- /dev/null
+++ clang/test/IFSO/foo.cpp
@@ -0,0 +1,53 @@
+// RUN: %clang -emit-ifso -fvisibility=hidden %s -o - | FileCheck --check-prefix=CHECK-HIDDEN %s
+// RUN: %clang -emit-ifso %s -o - | FileCheck %s
+
+// CHECK-HIDDEN-NOT: __Z4fbarff
+// CHECK: __Z4fbarff
+
+
+
+
+// CHECK-HIDDEN-NOT: __Z3fooii
+// CHECK-NOT:__Z3fooii
+
+
+
+#include "foo-inline.h"
+
+__attribute__ ((visibility ("hidden"))) int foo(int a, int b) { return a + b; }
+__attribute__ ((visibility ("default"))) int foo_default_visi(int a, int b) { return a + b; }
+
+
+__attribute__ ((visibility ("default"))) int fvih_1(int a, int b) { return a + fvih(); }
+
+int dataA = 34;
+
+namespace baz {
+  template 
+  T add(T a, T b) {
+return a + b;
+  }
+}
+
+namespace n {
+  template 
+  struct __attribute__((__visibility__("default"))) S {
+S() = default;
+~S() = default;
+int __attribute__((__visibility__(("default" func() const { return 32; }
+int __attribute__((__visibility__(("hidden" operator()() const { return 53; }
+  };
+}
+
+template  T neverUsed(T t) { return t + 2; }
+
+template<> int neverUsed(int t);
+
+void g() { n::S()(); }
+
+namespace qux {
+int bar(int a, int b) { return baz::add(a, b); }
+}
+
+float fbar(float a, float b) { return baz::add(a, b); }
+
Index: clang/test/IFSO/foo-inline.h
===
--- /dev/null
+++ clang/test/IFSO/foo-inline.h
@@ -0,0 +1,6 @@
+
+inline int fvih() {
+static int fortytwo = 42;
+  return fortytwo;
+}
+
Index: clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
===
--- clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
+++ clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
@@ -64,6 +64,7 @@
   case GenerateHeaderModule:
 return llvm::make_unique();
   case GeneratePCH:return llvm::make_unique();
+  case GenerateIFSO:   return llvm::make_unique();
   case InitOnly:   return llvm::make_unique();
   case ParseSyntaxOnly:return llvm::make_unique();
   case ModuleFileInfo: return llvm::make_unique();
Index: clang/lib/Frontend/FrontendActions.cpp
===
--- clang/lib/Frontend/FrontendActions.cpp
+++ clang/lib/Frontend/FrontendActions.cpp
@@ -25,6 +25,8 @@
 #include "llvm/Support/Path.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Support/YAMLTraits.h"
+#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/Index/CodegenNameGenerator.h"
 #include 
 #include 
 
@@ -158,6 +160,186 @@
   return true;
 }
 
+class IFSOFunctionsConsumer : public ASTConsumer {
+  CompilerInstance &Instance;
+  StringRef InFile = "";
+  std::set ParsedTemplates;
+
+  enum RootDeclOrigin { TopLevel = 0, FromTU = 1, IsLate = 2 };
+
+  template 
+  bool WriteNamedDecl(const NamedDecl *ND,
+  std::vector &MangledNames, int RDO) {
+if (!isa(ND))
+  return false;
+if (ND->getVisibility() != DefaultVisibility)
+  return true;
+// If this is a FunctionDecl that is dependent on a template parameter, then
+// don't get the symbol because we can only export specializations.
+bool IsRDOLate = (RDO & IsLate);
+if (const auto *FD = dyn_cast(ND))
+  if (FD->isDependentContext() && !IsRDOLate)
+return true;
+index::CodegenNameGenerator CGNameGen(ND->getASTContext());
+std::string MangledName = CGNameGen.getName(ND);
+MangledNames.push_back(MangledName);
+// For now, lets just dump the -fdelayed-template-parsing decls until we
+// decide how to handle them.
+if (IsRDOLate) {
+  llvm::errs() << "LATE DECL:\n";
+  ND->dump();
+}
+return true;
+  }
+
+  template 
+  bool HandleSomeDecl(const NamedDecl *ND,
+  std::vector &MangledNames, int RDO) {
+if (!isa(ND))
+  return false;
+for (auto *I : cast(ND)->decls())
+  HandleNamedDecl(dyn_cast(I), Mangled

[PATCH] D60974: Clang IFSO driver action.

2019-04-23 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi added a comment.

In D60974#1474994 , @compnerd wrote:

> Note that I am not advocating that this change go in as is - I think that 
> this is far from something which would be useful, and until it can produce 
> something meaningful, this shouldn't really be merged (i.e. generate 
> something which obj2yaml or some other tool can consume to generate the 
> barest ELF stub).


Neither was I, as I did not have an output format (but I've added something 
now). I just want feedback to iterate on.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60974/new/

https://reviews.llvm.org/D60974



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


[PATCH] D60974: Clang IFSO driver action.

2019-04-23 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi added a comment.

In D60974#1474777 , @jakehehrlich 
wrote:

> In D60974#1474751 , @plotfi wrote:
>
> > There are a few that I have in mind.
> >
> > 1. -emit-ifso could be added to a build to produce .so files as part of a 
> > device SDK (where we don't want to ship the runnable bits in the SDK, we 
> > ship those on the device updates).
>
>
> This would require creating a linker for these files. Is this what you intend 
> to do?


No, I do not intend to write any sort of linker in the classical sense. At most 
I'd be handling and merging symbol names from yaml files or possibly going from 
yaml -> elf .o -> .so. Weighing options.

>> 2. -emit-ifso could be added to whatever the existing set of build flags are 
>> to be run as a pre-build step to produce tapi-like .so files that break up 
>> build dependencies.
> 
> How would this work? To be clear, this would happen at the same time that .o 
> files are produced correct? The build graph would basically look the same but 
> your new linking step would replace the original link step and there would be 
> a pendent node for the original link step. This would not break up the build 
> graph much at all save for the fact that we might imagine that this new link 
> step would be much faster.

I was thinking that since -emit-ifso doesn't invoke the backend, it could be 
run as a pre-build step. Then during the build, linking is done against the 
ifso stubs that are already generated instead of the actual .so files.

> 
> 
>> 3. -emit-ifso -fvisibility=hidden could added to the invocation to disallow 
>> usage of non-public apis.
> 
> Can you be more specific? This is already how the actual modules do this 
> today so what is the advantage here.

I believe modules produce much more data than what I am doing here. What I am 
doing is trying to use visibility semantics to produce the bare minimum ELF and 
bare minimum symbols while still being able to link with the resulting .so file.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60974/new/

https://reviews.llvm.org/D60974



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


[PATCH] D60974: Clang IFSO driver action.

2019-04-23 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi added a comment.

In D60974#1476084 , @jakehehrlich 
wrote:

> Why is this better than producing output from the output of the static linker 
> at the end? Also how do we plan on integrating this with llvm-elfabi so that 
> we don't have unnecessarily duplicated efforts? Why does that tool not 
> suffice?
>
> > I'm well versed in the complexities of a linker - I've worked extensively 
> > on the GNU linkers as well as with lld. The visibility of the symbols is 
> > actually computed by the compiler - the STV_* flags associated with the 
> > symtab entry give you that information which is actually tracked through 
> > the frontend to the backend. Yes, each linker behaves differently - 
> > including lld which completely changes the semantics of Unix/ELF linking 
> > guarantees. In fact every single attribute that you mentioned is something 
> > which is emitted from the compiler - which we have access to here given 
> > that we are in clang itself. I think that this can be made to work 
> > properly, though will probably require some iteration to get all the corner 
> > cases, and that you may be slightly dismissive of this approach.
> > 
> > Ah, okay, I didn't pick up that you were using module as the actual module 
> > from the context since normally the module doesn't control what it exposes 
> > itself.
> > 
> > Note that I am not advocating that this change go in as is - I think that 
> > this is far from something which would be useful, and until it can produce 
> > something meaningful, this shouldn't really be merged (i.e. generate 
> > something which obj2yaml or some other tool can consume to generate the 
> > barest ELF stub).
>
> It's not a matter of where they're produced, its how you treat them and 
> ensure that they're correctly handled so that the final produced stub has the 
> correct output. I don't think this is entirely trivial when you consider all 
> of those different aspects that I listed.


I'll let @compnerd respond to the above...

>> No, I do not intend to write any sort of linker in the classical sense. At 
>> most I'd be handling and merging symbol names from yaml files or possibly 
>> going from yaml -> elf .o -> .so. Weighing options.
> 
> I'm calling that a kind of linker here. I'm not saying it would be as 
> complicated as a full linker but it would be a linker. I am claiming it would 
> be more complicated than the dwp linker however. Whatever you're calling it 
> you have to write it and that's an important part of this proposal process 
> but that wasn't mentioned until I asked about it.

You are right about this, because the original proposal was proposing a header 
-> .so file processor. But because of the issue of faithfully reproducing the 
ifso based on the build flags, I decided to re-implement things using the clang 
driver which results the need to do a symbol merge. I could do another proposal 
RFC if you think that is necessary.

>> I was thinking that since -emit-ifso doesn't invoke the backend, it could be 
>> run as a pre-build step. Then during the build, linking is done against the 
>> ifso stubs that are already generated instead of the actual .so files.
> 
> That seems a lot better than what I understood. This behavior might be useful 
> to some people. In particular you don't need .tbe files in your source tree 
> so if that isn't something you want to have this would be a less ideal 
> alternative because it was to invoke enough of the compiler to get rich 
> symbol information but not so much that its as slow as compiling. You pay for 
> this by having to reparse and go though some of the compilation process and 
> you have to link/merge many files to produce the stub but it doesn't require 
> funny files in your tree. I think that's a niche that some people might want. 
> The tradeoff between not having to deal with .tbe files and the huge increase 
> of build steps, computation needed (overall build times could very well 
> decrease if your build wasn't sufficiently parallel due to linking orders), 
> and total amount of IO seems like a tradeoff that I personally wouldn't want 
> to make. Is this a trade off you want to make? Almost every metric I can 
> think of would be worse than just adding .tbe files into your source code.

I actually don't see why something like this couldn't be used in both scenarios 
(ie some users generating the files at build time, and others using -emit-ifso 
to periodically generate and land changes to checked in files).


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60974/new/

https://reviews.llvm.org/D60974



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


[PATCH] D60974: Clang IFSO driver action.

2019-04-24 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi updated this revision to Diff 196516.
plotfi added a comment.

Updated to support properly setting OBJECT/FUNC types as well as section flags.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60974/new/

https://reviews.llvm.org/D60974

Files:
  clang/include/clang/Driver/Options.td
  clang/include/clang/Driver/Types.def
  clang/include/clang/Frontend/FrontendActions.h
  clang/include/clang/Frontend/FrontendOptions.h
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CMakeLists.txt
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Frontend/FrontendActions.cpp
  clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
  clang/test/IFSO/foo-inline.h
  clang/test/IFSO/foo.cpp

Index: clang/test/IFSO/foo.cpp
===
--- /dev/null
+++ clang/test/IFSO/foo.cpp
@@ -0,0 +1,53 @@
+// RUN: %clang -emit-ifso -fvisibility=hidden %s -o - | FileCheck --check-prefix=CHECK-HIDDEN %s
+// RUN: %clang -emit-ifso %s -o - | FileCheck %s
+
+// CHECK-HIDDEN-NOT: __Z4fbarff
+// CHECK: __Z4fbarff
+
+
+
+
+// CHECK-HIDDEN-NOT: __Z3fooii
+// CHECK-NOT:__Z3fooii
+
+
+
+#include "foo-inline.h"
+
+__attribute__ ((visibility ("hidden"))) int foo(int a, int b) { return a + b; }
+__attribute__ ((visibility ("default"))) int foo_default_visi(int a, int b) { return a + b; }
+
+
+__attribute__ ((visibility ("default"))) int fvih_1(int a, int b) { return a + fvih(); }
+
+int dataA = 34;
+
+namespace baz {
+  template 
+  T add(T a, T b) {
+return a + b;
+  }
+}
+
+namespace n {
+  template 
+  struct __attribute__((__visibility__("default"))) S {
+S() = default;
+~S() = default;
+int __attribute__((__visibility__(("default" func() const { return 32; }
+int __attribute__((__visibility__(("hidden" operator()() const { return 53; }
+  };
+}
+
+template  T neverUsed(T t) { return t + 2; }
+
+template<> int neverUsed(int t);
+
+void g() { n::S()(); }
+
+namespace qux {
+int bar(int a, int b) { return baz::add(a, b); }
+}
+
+float fbar(float a, float b) { return baz::add(a, b); }
+
Index: clang/test/IFSO/foo-inline.h
===
--- /dev/null
+++ clang/test/IFSO/foo-inline.h
@@ -0,0 +1,6 @@
+
+inline int fvih() {
+static int fortytwo = 42;
+  return fortytwo;
+}
+
Index: clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
===
--- clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
+++ clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
@@ -64,6 +64,7 @@
   case GenerateHeaderModule:
 return llvm::make_unique();
   case GeneratePCH:return llvm::make_unique();
+  case GenerateIFSO:   return llvm::make_unique();
   case InitOnly:   return llvm::make_unique();
   case ParseSyntaxOnly:return llvm::make_unique();
   case ModuleFileInfo: return llvm::make_unique();
Index: clang/lib/Frontend/FrontendActions.cpp
===
--- clang/lib/Frontend/FrontendActions.cpp
+++ clang/lib/Frontend/FrontendActions.cpp
@@ -20,11 +20,14 @@
 #include "clang/Sema/TemplateInstCallback.h"
 #include "clang/Serialization/ASTReader.h"
 #include "clang/Serialization/ASTWriter.h"
+#include "llvm/BinaryFormat/ELF.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Support/YAMLTraits.h"
+#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/Index/CodegenNameGenerator.h"
 #include 
 #include 
 
@@ -158,6 +161,260 @@
   return true;
 }
 
+class IFSOFunctionsConsumer : public ASTConsumer {
+  CompilerInstance &Instance;
+  StringRef InFile = "";
+  std::set ParsedTemplates;
+
+  enum RootDeclOrigin { TopLevel = 0, FromTU = 1, IsLate = 2 };
+  struct MangledSymbol {
+std::string Name = "";
+uint8_t Type = llvm::ELF::STT_NOTYPE;
+uint8_t Binding = llvm::ELF::STB_LOCAL;
+MangledSymbol(const std::string &Name, uint8_t Type, uint8_t Binding)
+: Name(Name), Type(Type), Binding(Binding) {}
+  };
+  using MangledSymbols = std::map;
+
+  template 
+  bool WriteNamedDecl(const NamedDecl *ND, MangledSymbols &Symbols, int RDO) {
+if (!isa(ND))
+  return false;
+if (Symbols.find(ND) != Symbols.end())
+  return true;
+if (isa(ND))
+  return true;
+if (ND->getVisibility() != DefaultVisibility)
+  return true;
+// If this is a FunctionDecl that is dependent on a template parameter, then
+// don't get the symbol because we can only export specializations.
+bool IsRDOLate = (RDO & IsLate);
+if (const auto *FD = dyn_cast(ND))
+  if (FD->isDependentContext() && !IsRDOLate)
+return true;
+index::CodegenNameGenerator CGNameGen(ND->getASTContext());
+std::string MangledName = CGName

[PATCH] D60974: Clang IFSO driver action.

2019-04-24 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi added a comment.

In D60974#1477302 , @phosek wrote:

> Aside from comments that @jakehehrlich already made which I agree with, I'm 
> also concerned about the use of `yaml2obj`. AFAIK that tool has always been 
> intended as a testing, not a production tool, but with this change this would 
> no longer be the case. Specifically, it formalizes the `yaml2obj` input 
> format by making it one of the output formats supported by Clang. I believe 
> that this is such a fundamental change that it should be discussed separately 
> before moving on with this implementation.


My main goal here is to emit some kind of a mergable format. If not yaml or 
tbe, then directly emitting the ELF. yaml is a stepping stone for now.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60974/new/

https://reviews.llvm.org/D60974



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


[PATCH] D60974: Clang IFSO driver action.

2019-04-24 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi updated this revision to Diff 196535.
plotfi added a comment.

First stab at trying to properly handle Weak Symbols


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60974/new/

https://reviews.llvm.org/D60974

Files:
  clang/include/clang/Driver/Options.td
  clang/include/clang/Driver/Types.def
  clang/include/clang/Frontend/FrontendActions.h
  clang/include/clang/Frontend/FrontendOptions.h
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CMakeLists.txt
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Frontend/FrontendActions.cpp
  clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
  clang/test/IFSO/foo-inline.h
  clang/test/IFSO/foo.cpp

Index: clang/test/IFSO/foo.cpp
===
--- /dev/null
+++ clang/test/IFSO/foo.cpp
@@ -0,0 +1,56 @@
+// RUN: %clang -emit-ifso -fvisibility=hidden %s -o - | FileCheck --check-prefix=CHECK-HIDDEN %s
+// RUN: %clang -emit-ifso %s -o - | FileCheck %s
+
+// CHECK-HIDDEN-NOT: __Z4fbarff
+// CHECK: __Z4fbarff
+
+
+
+
+// CHECK-HIDDEN-NOT: __Z3fooii
+// CHECK-NOT:__Z3fooii
+
+
+
+#include "foo-inline.h"
+
+__attribute__ ((visibility ("hidden"))) int foo(int a, int b) { return a + b; }
+__attribute__ ((visibility ("default"))) int foo_default_visi(int a, int b) { return a + b; }
+
+
+__attribute__ ((visibility ("default"))) int fvih_1(int a, int b) { return a + fvih(); }
+
+
+__attribute__((weak)) int someWeakFunc() { return 42; }
+
+int dataA = 34;
+
+namespace baz {
+  template 
+  T add(T a, T b) {
+return a + b;
+  }
+}
+
+namespace n {
+  template 
+  struct __attribute__((__visibility__("default"))) S {
+S() = default;
+~S() = default;
+int __attribute__((__visibility__(("default" func() const { return 32; }
+int __attribute__((__visibility__(("hidden" operator()() const { return 53; }
+  };
+}
+
+template  T neverUsed(T t) { return t + 2; }
+
+template<> int neverUsed(int t);
+
+void g() { n::S()(); }
+
+namespace qux {
+int bar(int a, int b) { return baz::add(a, b); }
+}
+
+float fbar(float a, float b) { return baz::add(a, b); }
+
Index: clang/test/IFSO/foo-inline.h
===
--- /dev/null
+++ clang/test/IFSO/foo-inline.h
@@ -0,0 +1,6 @@
+
+inline int fvih() {
+static int fortytwo = 42;
+  return fortytwo;
+}
+
Index: clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
===
--- clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
+++ clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
@@ -64,6 +64,7 @@
   case GenerateHeaderModule:
 return llvm::make_unique();
   case GeneratePCH:return llvm::make_unique();
+  case GenerateIFSO:   return llvm::make_unique();
   case InitOnly:   return llvm::make_unique();
   case ParseSyntaxOnly:return llvm::make_unique();
   case ModuleFileInfo: return llvm::make_unique();
Index: clang/lib/Frontend/FrontendActions.cpp
===
--- clang/lib/Frontend/FrontendActions.cpp
+++ clang/lib/Frontend/FrontendActions.cpp
@@ -20,11 +20,14 @@
 #include "clang/Sema/TemplateInstCallback.h"
 #include "clang/Serialization/ASTReader.h"
 #include "clang/Serialization/ASTWriter.h"
+#include "llvm/BinaryFormat/ELF.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Support/YAMLTraits.h"
+#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/Index/CodegenNameGenerator.h"
 #include 
 #include 
 
@@ -158,6 +161,256 @@
   return true;
 }
 
+class IFSOFunctionsConsumer : public ASTConsumer {
+  CompilerInstance &Instance;
+  StringRef InFile = "";
+  std::set ParsedTemplates;
+
+  enum RootDeclOrigin { TopLevel = 0, FromTU = 1, IsLate = 2 };
+  struct MangledSymbol {
+std::string Name = "";
+uint8_t Type = llvm::ELF::STT_NOTYPE;
+uint8_t Binding = llvm::ELF::STB_LOCAL;
+MangledSymbol(const std::string &Name, uint8_t Type, uint8_t Binding)
+: Name(Name), Type(Type), Binding(Binding) {}
+  };
+  using MangledSymbols = std::map;
+
+  template 
+  bool WriteNamedDecl(const NamedDecl *ND, MangledSymbols &Symbols, int RDO) {
+if (!isa(ND))
+  return false;
+if (Symbols.find(ND) != Symbols.end())
+  return true;
+if (isa(ND))
+  return true;
+if (ND->getVisibility() != DefaultVisibility)
+  return true;
+// If this is a FunctionDecl that is dependent on a template parameter, then
+// don't get the symbol because we can only export specializations.
+bool IsRDOLate = (RDO & IsLate);
+if (const auto *FD = dyn_cast(ND))
+  if (FD->isDependentContext() && !IsRDOLate)
+return true;
+index::CodegenNameGenerator CGNameGen(ND->getASTContext());
+  

[PATCH] D60974: Clang IFSO driver action.

2019-04-24 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi added a comment.

In D60974#1477761 , @jakehehrlich 
wrote:

> In D60974#1477690 , @compnerd wrote:
>
> > @jakehehrlich - when do you expect to have your idea put up?  I don't think 
> > that it is fair to have this wait until you have time to put something up 
> > that can be discussed.  I think that getting this working and then 
> > iterating on it and migrating it over to some shared representation is 
> > something which we could do - that tends to be a common thing that I have 
> > seen happen multiple times with the necessary work never materialising.  
> > Re-use of the YAML structure means that we can iterate and identify the 
> > pieces that are necessary, though, I expect that largely, what will be 
> > needed is the name, the binding, the visibility, possibly the size (for 
> > TBEs), the section, and the type, at least for anything which adheres to 
> > the GABI.  If you have extensions outside of GABI, this will need to be 
> > adjusted.
>
>
> I don't know when but in the next 2 days likely. Regardless of my timeline I 
> don't think I'm blocking anyone. I'm just saying that I will put up a 
> proposal. You should also put up a proposal as well. The yaml2obj format is 
> just not well designed for any purpose but is far from designed for this 
> purpose. yaml2obj works ok-ish for testing. I'd rather start with a minimal 
> format and then add things to it rather than starting with a bloated and ill 
> designed format and then create a new format from that experience. Creating a 
> minimal format shouldn't be hard and I suspect our proposal will look 
> extremely similar; I'd wager if you put up a proposal I'd probably just 
> review your proposal rather than bother writing out my own.
>
> As for what I think it would entail. I think name, weather or not the symbol 
> is defined or undefined, visibility, size, alignment (this is a feature of 
> the section and the symbol offset) and type will all mater but not all 
> combinations make sense. Sections don't matter as it turns out but alignment 
> does for copy relocations. When we started llvm-elfabi I thought at least the 
> section permissions mattered but they don't really. While .tbe has things 
> like soname and dt_needed that isn't needed here.  The top of the file should 
> probably contain the architecture. Other details in the ELF header shouldn't 
> be needed.


Would you be ok with having yaml emission as a debug/testing format (not as the 
official format, which I will post in a proposal this week or early next)? I 
suppose whatever tool handles the format can convert it to yaml, but it could 
still be convenient for debugging.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60974/new/

https://reviews.llvm.org/D60974



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


[PATCH] D60974: Clang IFSO driver action.

2019-04-25 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi added a comment.

In D60974#1479467 , @jakehehrlich 
wrote:

> As an example, .tbe and .tbd files use YAML but in a very specific well 
> defined structure. yaml2obj also uses a specific format which is actually 
> well defined, it just doesn't map on very well here.


I specifically meant the yaml2obj format. Mainly because yaml2obj is a handy 
tool for developing things. I suppose one way to do it could be to put together 
a more stable format and output the yaml2obj format for that.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60974/new/

https://reviews.llvm.org/D60974



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


[PATCH] D60974: Clang IFSO driver action.

2019-04-29 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi added a comment.

So, @compnerd and I have discussed and we'd like to propose a yaml schema that 
can express what we need for ifsos for the Sections and the Symbols. Something 
like:

  


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60974/new/

https://reviews.llvm.org/D60974



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


[PATCH] D60974: Clang IFSO driver action.

2019-04-29 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi added a comment.

So, @compnerd and I have discussed and we'd like to propose a yaml schema that 
can express what we need for ifsos for the Sections and the Symbols.

For the Symbols we want:

  Symbols:
- Name:_dataA
  Type:STT_OBJECT
  Section: .data
  Binding: STB_GLOBAL
- Name:__ZN3qux3barEii
  Type:STT_FUNC
  Section: .text
  Binding: STB_GLOBAL

Because this expresses the bare minimum of the symbol name, whether its a 
function or an exported object, which section it belongs to, and if it is bound 
globally or locally or weakly.

For the sections, this yaml schema gives us what we need to set the name, type 
and flags properly:

  Sections:
- Name:.text
  Type:SHT_PROGBITS
  Flags:   [ SHF_ALLOC, SHF_EXECINSTR ]
- Name:.data
  Type:SHT_PROGBITS
  Flags:   [ SHF_WRITE, SHF_ALLOC ]

We also think that the existing FileHeader works for emitting ELF ifsos:

  
FileHeader:
Class:   ELFCLASS64
Data:ELFDATA2LSB
Type:ET_REL
Machine: EM_X86_64
  


I could see us compacting this (something like "Kind: ELF_64_LSB_X86-64") but I 
don't see why we'd want to deviate from what ELF already lays out.
The file type is important because ET_REL vs ET_DYN can be used to denote if 
this is an ifso artifact that is meant to be merged or if it is already merged. 
I think we could have one stage that does the merging of the ET_RELs and one 
that assembles the final binary from a merged ET_DYN ifso.

We looked at other formats like TBD, and the major thing we also want to add is:

  --- !ifso-elf-v1

at the beginning of the yaml to denote that this is an ifso specifically for 
ELF and to denote the versioning.
I think the versioning could be used to direct how we read the FileHeader.

So the yaml ifso file syntax:

  --- !ifso-elf-
  FileHeader:
Class:   
Data:
Type:
Machine: 
  Sections: 
# One or more of these:
- Name:
  Type:
  Flags:   [  ]
  Symbols:
# One or more of these:
- Name:
  Type:
  Section: 
  Binding: 

How does this sound?

PL


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60974/new/

https://reviews.llvm.org/D60974



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


[PATCH] D60974: Clang IFSO driver action.

2019-04-29 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi added a comment.

In D60974#1483210 , @jakehehrlich 
wrote:

> In D60974#1483164 , @plotfi wrote:
>
> > So, @compnerd and I have discussed and we'd like to propose a yaml schema 
> > that can express what we need for ifsos for the Sections and the Symbols.
> >
> > ...
>
>
> Can you clarify is this is for the fully merged format or for the unmerged 
> format? I *really* strongly believe that the fully merged format should go 
> though llvm-elfabi.


Unmerged. The merged format could be elfabi or raw elf, but I want to agree on 
something that just lets us generate the intermediate unmerged artifacts for 
now.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60974/new/

https://reviews.llvm.org/D60974



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


[PATCH] D60974: Clang IFSO driver action.

2019-04-29 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi added a comment.

In D60974#1483209 , @jakehehrlich 
wrote:

>   I think I know the format that I'd like *roughly*. I haven't worked out how 
> to handle COMDAT and section groups yet. Roland seems to think that COMDAT 
> and section groups will be an issue but I'm working out the details with him 
> to make sure I understand it. I'll get back to you soon.
>   
>
>   Version: 1.0
>   Arch: AArch64
>   Symbols:
> - Name: foo
>   Type: Function
>   Weak: true
> - Name: bar
>   Type: Function
>   Defined: false
> - Name: baz
>   Type: Object
>   Size: 256
>   Alignment: 32
>
>
>


Me and @compnerd had discussed a more abstracted format like this but decided 
it was best to just use the same names that are in the ELF already.
Is there any compelling reason not to?
As far as I understand, by having something like "Weak: true" is already 
harking back to ELF so why not stick to the same names?

I think the !tbd-elf-v1 versioning can help with any changes or alterations we 
want to make along the way too.
We did discuss the alignment field too.

> Only Arch is used other details from your header can be inferred as defaults 
> but are not needed here. I think binding is not needed beyond Weak vs. Not 
> Weak. I spoke with Roland about this and he pointed out STB_GNU_UNIQUE. This 
> would motivate allowing Global, Weak, and GNU_UNIQUE as valid bindings. The 
> only cases for viability that we care are protected and default. Internal and 
> hidden will never appear in the public interface. We can treat protected and 
> default as the same as they just mean that the symbol will appear in the 
> public interface and their difference is related to how the linker resolves 
> symbols relative to module itself not other external modules.
> 
> We don't have to worry about symbol version (and the TextAPI types don't 
> support that yet either) but Warnings are another case to think about. Each 
> symbol can have a warning string associated with it. This will be one of the 
> last features (before symbol versions but after almost everyhing else) that 
> support is added for in llvm-elfabi so I think we can ignore it here for now.
> 
> One thing we forgot to add in llvm-elfabi that we now know we need to add is 
> Alignment. Alignment can be computed from the section and the offset within 
> the section. This is the one bit of information that comes from the section 
> itself and not the symbol table.
> 
> Absolute symbols probably aren't needed but if we ever need them they're easy 
> enough to add via a new symbol type.




Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60974/new/

https://reviews.llvm.org/D60974



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


[PATCH] D60974: Clang IFSO driver action.

2019-04-29 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi added a comment.

In D60974#1483209 , @jakehehrlich 
wrote:

>   I think I know the format that I'd like *roughly*. I haven't worked out how 
> to handle COMDAT and section groups yet. Roland seems to think that COMDAT 
> and section groups will be an issue but I'm working out the details with him 
> to make sure I understand it. I'll get back to you soon.
>   
>
>   Version: 1.0
>   Arch: AArch64
>   Symbols:
> - Name: foo
>   Type: Function
>   Weak: true
> - Name: bar
>   Type: Function
>   Defined: false
> - Name: baz
>   Type: Object
>   Size: 256
>   Alignment: 32
>
>
>


Also, curious on the lack of denoting the sections and which symbols go in 
which sections? Do you just assume that "Type: Object" goes into .data?

> Only Arch is used other details from your header can be inferred as defaults 
> but are not needed here. I think binding is not needed beyond Weak vs. Not 
> Weak. I spoke with Roland about this and he pointed out STB_GNU_UNIQUE. This 
> would motivate allowing Global, Weak, and GNU_UNIQUE as valid bindings. The 
> only cases for viability that we care are protected and default. Internal and 
> hidden will never appear in the public interface. We can treat protected and 
> default as the same as they just mean that the symbol will appear in the 
> public interface and their difference is related to how the linker resolves 
> symbols relative to module itself not other external modules.
> 
> We don't have to worry about symbol version (and the TextAPI types don't 
> support that yet either) but Warnings are another case to think about. Each 
> symbol can have a warning string associated with it. This will be one of the 
> last features (before symbol versions but after almost everyhing else) that 
> support is added for in llvm-elfabi so I think we can ignore it here for now.
> 
> One thing we forgot to add in llvm-elfabi that we now know we need to add is 
> Alignment. Alignment can be computed from the section and the offset within 
> the section. This is the one bit of information that comes from the section 
> itself and not the symbol table.
> 
> Absolute symbols probably aren't needed but if we ever need them they're easy 
> enough to add via a new symbol type.




Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60974/new/

https://reviews.llvm.org/D60974



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


[PATCH] D60974: Clang IFSO driver action.

2019-04-29 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi added a comment.

In D60974#1483265 , @jakehehrlich 
wrote:

> In D60974#1483240 , @plotfi wrote:
>
> > Me and @compnerd had discussed a more abstracted format like this but 
> > decided it was best to just use the same names that are in the ELF already.
> >  Is there any compelling reason not to?
> >  As far as I understand, by having something like "Weak: true" is already 
> > harking back to ELF so why not stick to the same names?
> >
> > I think the !tbd-elf-v1 versioning can help with any changes or alterations 
> > we want to make along the way too.
> >  We did discuss the alignment field too.
>
>
> The format will have to be ELF specific but that doesn't mean we have to use 
> the exact names. The benefit of this format is that you can only do the 
> intended thing with it while anything more. This is also the format that 
> matches most closely with .tbe which is a plus for consistency of this and 
> integration of both tools into the llvm ecosystem. It's obvious how to merge 
> my format into the ELFStub format. Your format has extraneous details that 
> would never matter to the creation of the ELFStub format like the name of the 
> section a symbol was defined in. Also I think much more of the compiler has 
> to be considered to get section names right unless you're just recomputing 
> them and then that's redundant for no gain.


We wanted to use the same names because its just a lot easier understand what 
is if you've already looked at the ELF header code (ie STT_FUNC vs Function).

> When we first reviewed the .tbe format I was on the "just use ELF name" side 
> of things for the Type and Arch fields. I don't remember why that wasn't 
> chosen but for consistency with that choice I think we should do the same 
> thing here. As for fields like Weak vs not Weak distilling the format down to 
> only allow for those options is a design benefit. not Weak means (GLOBAL or 
> GNU_UNIQUE) and Weak means WEAK. Likewise by not messing with visability (you 
> don't mess with it either, I'm just pointing this out) we split things into 
> (default | protected) and (internal | hidden). These grouped concepts, though 
> exactly what we need, are not what available concepts. We also constrain 
> useless bindings from existing like LOCAL which isn't meaningful in this 
> context.
> 
> Every bit of my format is needed to produce the final stub in working form. 
> All section information in your format, some bindings, and ELF file type are 
> all not needed. There's an argument for embedding the ELF encoding format in 
> this file but that will only be used later once linking occurs. It can also 
> be inferred by the architecture in most cases and otherwise specified using a 
> bfd output format name when that's what people need/want.




Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60974/new/

https://reviews.llvm.org/D60974



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


[PATCH] D60974: Clang IFSO driver action.

2019-04-29 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi added a comment.

In D60974#1483480 , @jakehehrlich 
wrote:

> In D60974#1483399 , @plotfi wrote:
>
> > In D60974#1483265 , @jakehehrlich 
> > wrote:
> >
> > > In D60974#1483240 , @plotfi 
> > > wrote:
> > >
> > > > Me and @compnerd had discussed a more abstracted format like this but 
> > > > decided it was best to just use the same names that are in the ELF 
> > > > already.
> > > >  Is there any compelling reason not to?
> > > >  As far as I understand, by having something like "Weak: true" is 
> > > > already harking back to ELF so why not stick to the same names?
> > > >
> > > > I think the !tbd-elf-v1 versioning can help with any changes or 
> > > > alterations we want to make along the way too.
> > > >  We did discuss the alignment field too.
> > >
> > >
> > > The format will have to be ELF specific but that doesn't mean we have to 
> > > use the exact names. The benefit of this format is that you can only do 
> > > the intended thing with it while anything more. This is also the format 
> > > that matches most closely with .tbe which is a plus for consistency of 
> > > this and integration of both tools into the llvm ecosystem. It's obvious 
> > > how to merge my format into the ELFStub format. Your format has 
> > > extraneous details that would never matter to the creation of the ELFStub 
> > > format like the name of the section a symbol was defined in. Also I think 
> > > much more of the compiler has to be considered to get section names right 
> > > unless you're just recomputing them and then that's redundant for no gain.
> >
> >
> > We wanted to use the same names because its just a lot easier understand 
> > what is if you've already looked at the ELF header code (ie STT_FUNC vs 
> > Function).
>
>
> This is a reasonable opinion and was my opinion as well. But that isn't the 
> way review went for .tbe and so now we have a responsibility to be 
> consistent. This is bike shed level stuff. I could care less either way 
> except for consistency.


Does llvm-elfabi consume your proposed Schema format? Has it landed yet?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60974/new/

https://reviews.llvm.org/D60974



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


[PATCH] D60974: Clang IFSO driver action.

2019-04-30 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi added a comment.

In D60974#1484744 , @jakehehrlich 
wrote:

> > Does llvm-elfabi consume your proposed Schema format? Has it landed yet?
>
> No, I just proposed it and explained my reasoning. If you wanted to add this 
> format to TextAPI that would be acceptable.


I'm a little bit confused. At what point will llvm-elfabi be capable of 
generating a binary object/shared object file?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60974/new/

https://reviews.llvm.org/D60974



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


[PATCH] D60974: Clang IFSO driver action.

2019-04-30 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi added a comment.

In D60974#1485417 , @jakehehrlich 
wrote:

> Background:
>  There are two parts to this. TextAPI is a public interface of textual 
> representations for these sorts of files that already exists in llvm. There 
> exist ELF and MachO textual representations currently. llvm-elfabi is a tool 
> for 1) Creating Stubs 2) Creating .tbe (the TextAPI fully linked ELF format) 
> files 3) Converting between them and 4) Analyzing the details of the formats.
>
> You asked about the format I proposed here, not the already accepted .tbe 
> format. The format proposed here could be added to TextAPI where it could 
> subsequently be used in both Clang and a tool that would use the llvm-elfabi 
> code to create stubs. I imagine the flags needed for this new tool would be 
> very differnet from what llvm-elfabi uses or would use in the future so we'd 
> probably want a second symlink the behaved very differently.
>
> It can currently read ELF and .tbe files and can currently write .tbe files. 
> I'll have the basics of ELF writing up for review by the end of the day and 
> that will, for the next month or two be my primary work which should likely 
> see it close to stabilized. I'd expect landing the basics of ELF writing to 
> take another week or two since its somewhat involved and I'll likely need to 
> split the patches up from what I have. Given that no such writer currently 
> exists this should put a version of your tool well ahead of schedule. Such 
> are the wonderful benefits of open source.


Good, thanks for confirming this. For the format you proposed here, do you 
think that should be consumed by llvm-elfabi or by a secondary tool that 
generates a final merged tbe to be consumed by llvm-elfabi?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60974/new/

https://reviews.llvm.org/D60974



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


[PATCH] D60974: Clang IFSO driver action.

2019-04-30 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi added a comment.

In D60974#1483479 , @jakehehrlich 
wrote:

> In D60974#1483380 , @plotfi wrote:
>
> > Also, curious on the lack of denoting the sections and which symbols go in 
> > which sections? Do you just assume that "Type: Object" goes into .data?
>
>
> You don't need that information and the linker doesn't use it. It only uses 
> that information to get alignment. In the code that I'm writing right now it 
> happens to put everything in a single rodata section (except for tls which it 
> puts in a TLS rodata section, which isn't a thing that even exists in the 
> wild)


Wanted to mention, from my testing with yaml2obj, I needed the section flags 
(SHF_EXECINSTR, SHF_WRITE, SHF_ALLOC, etc) otherwise nm was spitting the wrong 
thing. How are you going to handle those?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60974/new/

https://reviews.llvm.org/D60974



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


[PATCH] D60974: Clang IFSO driver action.

2019-04-30 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi added a comment.

In D60974#1485552 , @jakehehrlich 
wrote:

> Well I think it should be a seperate tool but because the code inside 
> llvm-elfabi isn't a library yet (though it is written to be used like one) we 
> can do that by adding a symlink and changing the behavior of the underlying 
> binary to present as a different tool. Many different tools around llvm do 
> this for similar reasons.


So, I think we could do something like:

  --- !ifo-elf-v1
  Arch: X86_64
  Endian: little
  Sections:
- Name:.text
  Type:SHT_PROGBITS
  Flags:   [ SHF_ALLOC, SHF_EXECINSTR ]
- Name:.data
  Type:SHT_PROGBITS
  Flags:   [ SHF_WRITE, SHF_ALLOC ]
  Symbols:
- Name:_dataA
  Type:Object
  Section: .data
  Alignment: 32
- Name:__ZN3qux3barEii
  Type:Function
  Section: .text
  Weak: true
  ...

Notice the "ifo" and not the "ifso"; I think that could be a good way to denote 
that this is the unmerged format.

I could also drop the section parts:

  --- !ifo-elf-v1
  Arch: X86_64
  Endian: little
  Symbols:
- Name:_dataA
  Type:Object
  Alignment: 32
- Name:__ZN3qux3barEii
  Type:Function
  Weak: true
  ...

as soon as we discuss the section flags.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60974/new/

https://reviews.llvm.org/D60974



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


[PATCH] D60974: Clang IFSO driver action.

2019-04-30 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi added a comment.

In D60974#1485611 , @jakehehrlich 
wrote:

> Oh and "ifo" is a good name.


I still would like to keep the clang flag as -emit-ifso; the intermediate 
unmerged files are analogous to object files but the final result should be 
something that resembles a .so file.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60974/new/

https://reviews.llvm.org/D60974



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


[PATCH] D60974: Clang IFSO driver action.

2019-04-30 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi added a comment.

In D60974#1485610 , @jakehehrlich 
wrote:

> > Wanted to mention, from my testing with yaml2obj, I needed the section 
> > flags (SHF_EXECINSTR, SHF_WRITE, SHF_ALLOC, etc) otherwise nm was spitting 
> > the wrong thing. How are you going to handle those?
>
> I'm not sure what you mean. yaml2obj is a different tool that we shouldn't be 
> using IMO. yaml2obj would require the sections to denote that a symbol was 
> defined. When producing an elf file from the .tbe format you have to 
> synthesize sections for this same reason.


I meant, not including the section permissions (when I was emitting yaml2obj 
yaml) resulted in a .so file where nm thought all the symbols were ' "N" The 
symbol is a debugging symbol '


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60974/new/

https://reviews.llvm.org/D60974



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


[PATCH] D60974: Clang IFSO driver action.

2019-04-30 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi added a comment.

In D60974#1485607 , @jakehehrlich 
wrote:

> The linker doesn't look at section permissions. In fact the only thing it 
> even looks at the section index for is to check for alignment for copy 
> relocations which is something most people don't even use.


Alright, that seems reasonable. Then I will work on emitting something that 
resembles:

  --- !ifo-elf-v1
  Arch: 
  Endian:  
  Symbols:
  # One or more symbols here:
- Name:
  Type:
  
  
  ...

Along with a tool that merges these "ifo" files.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60974/new/

https://reviews.llvm.org/D60974



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


[PATCH] D60974: Clang IFSO driver action.

2019-05-01 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi updated this revision to Diff 197645.
plotfi added a comment.

- change "ifso" for intermediate files to "ifo"
- Updated schemas. I have both our own proposal and the proposal that resembles 
elfeabi here.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60974/new/

https://reviews.llvm.org/D60974

Files:
  clang/include/clang/Driver/Options.td
  clang/include/clang/Driver/Types.def
  clang/include/clang/Frontend/FrontendActions.h
  clang/include/clang/Frontend/FrontendOptions.h
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CMakeLists.txt
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Frontend/FrontendActions.cpp
  clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
  clang/test/IFSO/foo-inline.h
  clang/test/IFSO/foo.cpp

Index: clang/test/IFSO/foo.cpp
===
--- /dev/null
+++ clang/test/IFSO/foo.cpp
@@ -0,0 +1,56 @@
+// RUN: %clang -emit-ifso -fvisibility=hidden %s -o - | FileCheck --check-prefix=CHECK-HIDDEN %s
+// RUN: %clang -emit-ifso %s -o - | FileCheck %s
+
+// CHECK-HIDDEN-NOT: __Z4fbarff
+// CHECK: __Z4fbarff
+
+
+
+
+// CHECK-HIDDEN-NOT: __Z3fooii
+// CHECK-NOT:__Z3fooii
+
+
+
+#include "foo-inline.h"
+
+__attribute__ ((visibility ("hidden"))) int foo(int a, int b) { return a + b; }
+__attribute__ ((visibility ("default"))) int foo_default_visi(int a, int b) { return a + b; }
+
+
+__attribute__ ((visibility ("default"))) int fvih_1(int a, int b) { return a + fvih(); }
+
+
+__attribute__((weak)) int someWeakFunc() { return 42; }
+
+int dataA = 34;
+
+namespace baz {
+  template 
+  T add(T a, T b) {
+return a + b;
+  }
+}
+
+namespace n {
+  template 
+  struct __attribute__((__visibility__("default"))) S {
+S() = default;
+~S() = default;
+int __attribute__((__visibility__(("default" func() const { return 32; }
+int __attribute__((__visibility__(("hidden" operator()() const { return 53; }
+  };
+}
+
+template  T neverUsed(T t) { return t + 2; }
+
+template<> int neverUsed(int t);
+
+void g() { n::S()(); }
+
+namespace qux {
+int bar(int a, int b) { return baz::add(a, b); }
+}
+
+float fbar(float a, float b) { return baz::add(a, b); }
+
Index: clang/test/IFSO/foo-inline.h
===
--- /dev/null
+++ clang/test/IFSO/foo-inline.h
@@ -0,0 +1,6 @@
+
+inline int fvih() {
+static int fortytwo = 42;
+  return fortytwo;
+}
+
Index: clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
===
--- clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
+++ clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
@@ -64,6 +64,7 @@
   case GenerateHeaderModule:
 return llvm::make_unique();
   case GeneratePCH:return llvm::make_unique();
+  case GenerateIFSO:   return llvm::make_unique();
   case InitOnly:   return llvm::make_unique();
   case ParseSyntaxOnly:return llvm::make_unique();
   case ModuleFileInfo: return llvm::make_unique();
Index: clang/lib/Frontend/FrontendActions.cpp
===
--- clang/lib/Frontend/FrontendActions.cpp
+++ clang/lib/Frontend/FrontendActions.cpp
@@ -20,11 +20,14 @@
 #include "clang/Sema/TemplateInstCallback.h"
 #include "clang/Serialization/ASTReader.h"
 #include "clang/Serialization/ASTWriter.h"
+#include "llvm/BinaryFormat/ELF.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Support/YAMLTraits.h"
+#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/Index/CodegenNameGenerator.h"
 #include 
 #include 
 
@@ -158,6 +161,291 @@
   return true;
 }
 
+class IFSOFunctionsConsumer : public ASTConsumer {
+  CompilerInstance &Instance;
+  StringRef InFile = "";
+  std::set ParsedTemplates;
+
+  enum RootDeclOrigin { TopLevel = 0, FromTU = 1, IsLate = 2 };
+  struct MangledSymbol {
+std::string Name = "";
+uint8_t Type = llvm::ELF::STT_NOTYPE;
+uint8_t Binding = llvm::ELF::STB_LOCAL;
+MangledSymbol(const std::string &Name, uint8_t Type, uint8_t Binding)
+: Name(Name), Type(Type), Binding(Binding) {}
+  };
+  using MangledSymbols = std::map;
+
+  template 
+  bool WriteNamedDecl(const NamedDecl *ND, MangledSymbols &Symbols, int RDO) {
+if (!isa(ND))
+  return false;
+if (Symbols.find(ND) != Symbols.end())
+  return true;
+if (isa(ND))
+  return true;
+if (ND->getVisibility() != DefaultVisibility)
+  return true;
+// If this is a FunctionDecl that is dependent on a template parameter, then
+// don't get the symbol because we can only export specializations.
+bool IsRDOLate = (RDO & IsLate);
+if (const auto *FD = dyn_cast(ND))
+  if (FD->isDependentContext() && !IsRDOLate)

[PATCH] D60974: Clang IFSO driver action.

2019-05-02 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi marked an inline comment as done.
plotfi added a comment.

In D60974#1486631 , @jakehehrlich 
wrote:

> In D60974#1486384 , @compnerd wrote:
>
> > @jakehehrlich - unfortunately, removing the attributes on the sections will 
> > make the content look different with `nm` which is something we do need to 
> > appear proper for consumers of the interface libraries.  Versioning has a 
> > number of problems inherent to it (unfortunately, its the closest to 
> > multi-level namespaces in ELF).  I think that getting something in tree and 
> > iterating on it is far better than continuing to argue over this in the 
> > dream of something that unifies the TAPI approach and this approach.  The 
> > section names are relevant (you can add attributes to put symbols into 
> > alternate sections and you can have section relative relocations).  I think 
> > that you are loosing fidelity in the final output which is sufficient for 
> > your needs, but I think that there are places where the full fidelity can 
> > be needed.
> >
> > This currently works and allows us to generate the interface library which 
> > means that this is actually further than what you are proposing still.  Is 
> > there something technical that this is doing incorrectly or breaking 
> > something?  Otherwise, this really does seem like it is devolving into a 
> > bike shedding argument that isn't really going anywhere.  This is not a 
> > large amount of code and there is backing to maintain it, so it is not an 
> > issue of "this is adding un-maintained complexity" either.
> >
> > Just like the LLVM APIs, this can/will evolve.  I don't see why this needs 
> > to be set in stone from the initial implementation.  There are use cases 
> > which can come up which require reworking the solution.
>
>
>
>
> 1. The output of nm when you give it what exactly is different? What output 
> are you expecting? You aren't making that specific. Passing the unmerged 
> output though nm doesn't make any sense. If you have a precise use case for 
> section names you should mention it. We can always add symbol information 
> back as needed if we first start with something more minimal. What output of 
> nm are you expecting a
> 2. We're basically in agreement on what should happen here. I don't think 
> it's a dream of unifying these things. It looks like a very close reality to 
> me.
> 3. You mention sections and relocation as being relevant information. Can you 
> give a specific use case? Section names in general are not meaningful 
> information. They're just there for humans to debug things. Putting symbols 
> in different sections lets the linker treat them specially but in the end 
> binary sections are not relevant to much of anything.


Jake, I am still not sure what you would prefer for moving forward. The current 
patch can output the yaml format I originally proposed or the one that looks 
similar to the one you proposed. What I need to know is:

- Do you want the merging if the "ifo" files to happen inside of llvm-elfabi?
- Do you care if we upstream the yaml we proposed as a first step (which is 
really a distilled version of that yaml2obj can consume anyways. this right now 
functions actually) ???
- Or, would you rather the ifo files be merged by a different separate tool 
(something maybe called llvm-ifsogen)???


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60974/new/

https://reviews.llvm.org/D60974



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


[PATCH] D60974: Clang IFSO driver action.

2019-05-04 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi updated this revision to Diff 198152.
plotfi added a comment.
Herald added subscribers: llvm-commits, MaskRay, hiraditya, arichardson, emaste.
Herald added a reviewer: espindola.
Herald added a project: LLVM.

Adding support for multiple formats using -interface-stubs-version=.

I'll add another diff soon. My idea is what 
-interface-stubs-version=experimental-ifo-elf-v1 could be used to generate 
literally anything that works currently (which is likely to be a distillation 
of whatever is the latest obj2yaml schema), or 
-interface-stubs-version=tapi-tbe to generate valid elfabi tapi.

I've also added an optional Endian field to elf tapi because that seems pretty 
important to have.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60974/new/

https://reviews.llvm.org/D60974

Files:
  clang/include/clang/Driver/Options.td
  clang/include/clang/Driver/Types.def
  clang/include/clang/Frontend/FrontendActions.h
  clang/include/clang/Frontend/FrontendOptions.h
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CMakeLists.txt
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Frontend/FrontendActions.cpp
  clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
  clang/test/IFSO/foo-inline.h
  clang/test/IFSO/foo.cpp
  llvm/include/llvm/TextAPI/ELF/ELFStub.h
  llvm/lib/TextAPI/ELF/TBEHandler.cpp

Index: llvm/lib/TextAPI/ELF/TBEHandler.cpp
===
--- llvm/lib/TextAPI/ELF/TBEHandler.cpp
+++ llvm/lib/TextAPI/ELF/TBEHandler.cpp
@@ -134,6 +134,7 @@
 IO.mapRequired("TbeVersion", Stub.TbeVersion);
 IO.mapOptional("SoName", Stub.SoName);
 IO.mapRequired("Arch", (ELFArchMapper &)Stub.Arch);
+IO.mapOptional("Endian", Stub.Endian);
 IO.mapOptional("NeededLibs", Stub.NeededLibs);
 IO.mapRequired("Symbols", Stub.Symbols);
   }
Index: llvm/include/llvm/TextAPI/ELF/ELFStub.h
===
--- llvm/include/llvm/TextAPI/ELF/ELFStub.h
+++ llvm/include/llvm/TextAPI/ELF/ELFStub.h
@@ -55,6 +55,7 @@
   VersionTuple TbeVersion;
   Optional SoName;
   ELFArch Arch;
+  Optional Endian;
   std::vector NeededLibs;
   std::set Symbols;
 
Index: clang/test/IFSO/foo.cpp
===
--- /dev/null
+++ clang/test/IFSO/foo.cpp
@@ -0,0 +1,57 @@
+// Using %clang instead of %clang_cc1 because of -fvisibility
+// RUN: %clang -target x86_64-linux-gnu -emit-interface-stubs -fvisibility=hidden %s -o - | FileCheck --check-prefix=CHECK-HIDDEN %s
+// RUN: %clang -target x86_64-linux-gnu -emit-interface-stubs %s -o - | FileCheck %s
+
+// CHECK-HIDDEN-NOT: _Z4fbarff
+// CHECK: _Z4fbarff
+
+
+
+
+// CHECK-HIDDEN-NOT: _Z3fooii
+// CHECK-NOT:_Z3fooii
+
+
+
+#include "foo-inline.h"
+
+__attribute__ ((visibility ("hidden"))) int foo(int a, int b) { return a + b; }
+__attribute__ ((visibility ("default"))) int foo_default_visi(int a, int b) { return a + b; }
+
+
+__attribute__ ((visibility ("default"))) int fvih_1(int a, int b) { return a + fvih(); }
+
+
+__attribute__((weak)) int someWeakFunc() { return 42; }
+
+int dataA = 34;
+
+namespace baz {
+  template 
+  T add(T a, T b) {
+return a + b;
+  }
+}
+
+namespace n {
+  template 
+  struct __attribute__((__visibility__("default"))) S {
+S() = default;
+~S() = default;
+int __attribute__((__visibility__(("default" func() const { return 32; }
+int __attribute__((__visibility__(("hidden" operator()() const { return 53; }
+  };
+}
+
+template  T neverUsed(T t) { return t + 2; }
+
+template<> int neverUsed(int t);
+
+void g() { n::S()(); }
+
+namespace qux {
+int bar(int a, int b) { return baz::add(a, b); }
+}
+
+float fbar(float a, float b) { return baz::add(a, b); }
+
Index: clang/test/IFSO/foo-inline.h
===
--- /dev/null
+++ clang/test/IFSO/foo-inline.h
@@ -0,0 +1,6 @@
+
+inline int fvih() {
+static int fortytwo = 42;
+  return fortytwo;
+}
+
Index: clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
===
--- clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
+++ clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
@@ -64,6 +64,8 @@
   case GenerateHeaderModule:
 return llvm::make_unique();
   case GeneratePCH:return llvm::make_unique();
+  case GenerateIfsoObjYamlExpV1: return llvm::make_unique();
+  case GenerateIfsoTbeExpV1:   return llvm::make_unique();
   case InitOnly:   return llvm::make_unique();
   case ParseSyntaxOnly:return llvm::make_unique();
   case ModuleFileInfo: return llvm::make_unique();
Index: clang/lib/Frontend/FrontendActions.cpp
===
--- clang/lib/Frontend/FrontendActions.cpp
+++ clang/lib/Frontend/FrontendActions.cpp
@@ -20,11 +20,14 @@

[PATCH] D60974: Clang IFSO driver action.

2019-05-04 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi updated this revision to Diff 198157.
plotfi added a comment.

Changing experimental flag to -interface-stubs-version=experimental-ifo-elf-v1


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60974/new/

https://reviews.llvm.org/D60974

Files:
  clang/include/clang/Driver/Options.td
  clang/include/clang/Driver/Types.def
  clang/include/clang/Frontend/FrontendActions.h
  clang/include/clang/Frontend/FrontendOptions.h
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CMakeLists.txt
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Frontend/FrontendActions.cpp
  clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
  clang/test/IFSO/foo-inline.h
  clang/test/IFSO/foo.cpp
  llvm/include/llvm/TextAPI/ELF/ELFStub.h
  llvm/lib/TextAPI/ELF/TBEHandler.cpp

Index: llvm/lib/TextAPI/ELF/TBEHandler.cpp
===
--- llvm/lib/TextAPI/ELF/TBEHandler.cpp
+++ llvm/lib/TextAPI/ELF/TBEHandler.cpp
@@ -134,6 +134,7 @@
 IO.mapRequired("TbeVersion", Stub.TbeVersion);
 IO.mapOptional("SoName", Stub.SoName);
 IO.mapRequired("Arch", (ELFArchMapper &)Stub.Arch);
+IO.mapOptional("Endian", Stub.Endian);
 IO.mapOptional("NeededLibs", Stub.NeededLibs);
 IO.mapRequired("Symbols", Stub.Symbols);
   }
Index: llvm/include/llvm/TextAPI/ELF/ELFStub.h
===
--- llvm/include/llvm/TextAPI/ELF/ELFStub.h
+++ llvm/include/llvm/TextAPI/ELF/ELFStub.h
@@ -55,6 +55,7 @@
   VersionTuple TbeVersion;
   Optional SoName;
   ELFArch Arch;
+  Optional Endian;
   std::vector NeededLibs;
   std::set Symbols;
 
Index: clang/test/IFSO/foo.cpp
===
--- /dev/null
+++ clang/test/IFSO/foo.cpp
@@ -0,0 +1,57 @@
+// Using %clang instead of %clang_cc1 because of -fvisibility
+// RUN: %clang -target x86_64-linux-gnu -emit-interface-stubs -fvisibility=hidden %s -o - | FileCheck --check-prefix=CHECK-HIDDEN %s
+// RUN: %clang -target x86_64-linux-gnu -emit-interface-stubs %s -o - | FileCheck %s
+
+// CHECK-HIDDEN-NOT: _Z4fbarff
+// CHECK: _Z4fbarff
+
+
+
+
+// CHECK-HIDDEN-NOT: _Z3fooii
+// CHECK-NOT:_Z3fooii
+
+
+
+#include "foo-inline.h"
+
+__attribute__ ((visibility ("hidden"))) int foo(int a, int b) { return a + b; }
+__attribute__ ((visibility ("default"))) int foo_default_visi(int a, int b) { return a + b; }
+
+
+__attribute__ ((visibility ("default"))) int fvih_1(int a, int b) { return a + fvih(); }
+
+
+__attribute__((weak)) int someWeakFunc() { return 42; }
+
+int dataA = 34;
+
+namespace baz {
+  template 
+  T add(T a, T b) {
+return a + b;
+  }
+}
+
+namespace n {
+  template 
+  struct __attribute__((__visibility__("default"))) S {
+S() = default;
+~S() = default;
+int __attribute__((__visibility__(("default" func() const { return 32; }
+int __attribute__((__visibility__(("hidden" operator()() const { return 53; }
+  };
+}
+
+template  T neverUsed(T t) { return t + 2; }
+
+template<> int neverUsed(int t);
+
+void g() { n::S()(); }
+
+namespace qux {
+int bar(int a, int b) { return baz::add(a, b); }
+}
+
+float fbar(float a, float b) { return baz::add(a, b); }
+
Index: clang/test/IFSO/foo-inline.h
===
--- /dev/null
+++ clang/test/IFSO/foo-inline.h
@@ -0,0 +1,6 @@
+
+inline int fvih() {
+static int fortytwo = 42;
+  return fortytwo;
+}
+
Index: clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
===
--- clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
+++ clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
@@ -64,6 +64,8 @@
   case GenerateHeaderModule:
 return llvm::make_unique();
   case GeneratePCH:return llvm::make_unique();
+  case GenerateIfsoObjYamlExpV1: return llvm::make_unique();
+  case GenerateIfsoTbeExpV1:   return llvm::make_unique();
   case InitOnly:   return llvm::make_unique();
   case ParseSyntaxOnly:return llvm::make_unique();
   case ModuleFileInfo: return llvm::make_unique();
Index: clang/lib/Frontend/FrontendActions.cpp
===
--- clang/lib/Frontend/FrontendActions.cpp
+++ clang/lib/Frontend/FrontendActions.cpp
@@ -20,11 +20,14 @@
 #include "clang/Sema/TemplateInstCallback.h"
 #include "clang/Serialization/ASTReader.h"
 #include "clang/Serialization/ASTWriter.h"
+#include "llvm/BinaryFormat/ELF.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/raw_ostream.h"
 #include "llvm/Support/YAMLTraits.h"
+#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/Index/CodegenNameGenerator.h"
 #include 
 #include 
 
@@ -158,6 +161,264 @@
   return true;
 }
 
+class IFSOFunctionsConsumer : publ

[PATCH] D60974: Clang IFSO driver action.

2019-05-06 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi added a comment.

In D60974#1490358 , @rupprecht wrote:

> I didn't follow the technical details, but I don't see anything wrong with 
> moving forward on this patch. I think this seems like an interesting idea 
> worth experimenting with.
>
> In D60974#1488563 , @jakehehrlich 
> wrote:
>
> > > Jake, I am still not sure what you would prefer for moving forward. The 
> > > current patch can output the yaml format I originally proposed or the one 
> > > that looks similar to the one you proposed. What I need to know is:
> > > 
> > > Do you want the merging if the "ifo" files to happen inside of 
> > > llvm-elfabi?
> > >  Do you care if we upstream the yaml we proposed as a first step (which 
> > > is really a distilled version of that yaml2obj can consume anyways. this 
> > > right now functions actually) ???
> > >  Or, would you rather the ifo files be merged by a different separate 
> > > tool (something maybe called llvm-ifsogen)???
> >
> > This is my proposal:
> >
> > 1. We should plan on adding the code ofr merging these files inside of 
> > `llvm/tools/llvm-elfabi` but will it be a separate tool from `llvm-elfabi`. 
> > You can create "separate" tools in the same directory using the symlink 
> > trick. See llvm-ar and friends or llvm-objcopy and llvm-strip. The tool 
> > name can be discussed in review.
>
>
> The symlink trick is usually used when the new frontend tool is just a thin 
> layer over the underlying tool. Is that going to be the case here?
>
> For example,
>
> - `llvm-ranlib` is equivalent to `llvm-ar s`
> - `llvm-readelf` is equivalent to `llvm-readobj --elf-output-style=GNU`
> - `llvm-addr2line` is equivalent to `llvm-symbolizer --output-style=GNU`
> - `llvm-strip` is equivalent to `llvm-objcopy --strip-all` (maybe not exactly)
>
>   In other words, is `llvm-mergeifo` (placeholder name) going to be roughly 
> equivalent to `llvm-elfabi --merge-ifo` (again, placeholder flag name)? And 
> if so, it doesn't seem like a symlink is strictly necessary -- users can just 
> call `llvm-elfabi --merge-ifo`. Am I missing something?


@rupprecht
I was looking into this. I think it could work to just have a secondary path 
for loading tbe files and merging them. I modified the tbe schema to include an 
"Endian" field (which I would like to emit from clang).

>> 2. The yaml proposed thus far is not acceptable IMO for reasons already 
>> outlined but this can be discussed in code review. Before adding sections a 
>> clear reason for needing them is required which hasn't been given yet. 
>> Things can evolve and change later as needed but we should start with the 
>> minimum and add as needed later; not start with extra and remove later. 
>> Support for the new format should be added into TextAPI and in the review 
>> for that process we should discuss the format. After we add support for this 
>> new format into TextAPI we can add support for emitting this format into 
>> clang (well actually you can write the code whenever but I'm using "after" 
>> in a different sense here).
> 
> What if we named it experimental for now? i.e. `--experimental-emit-ifo` for 
> the clang flag name and `!experimental-ifo-elf-v1` for the yaml id? That 
> would allow those working on this patch to play around with more features, 
> but still give sufficient warning to anyone that fields they depend on may be 
> removed.
> 
> In fact, if we label it experimental (or maybe even if we don't), I don't see 
> any reason this couldn't land now, even without a consumer of it. So what if 
> a tool produces a yaml file that we don't haven't finished the yaml parser 
> for? Does anything break?

@rupprecht I like this idea a lot, and I think it's a good compromise. I think 
in the long run there are multiple formats that could be output from 
clang-emit-interface-stubs so I went ahead and added an additional 
-interface-stubs-version= flag (because why limit the output format to a 
specific version of tbe or elf?). My current diff can generate either tbe (that 
can be consumed by llvm-elfabi) by default or yaml that can be consumed by 
yaml2obj (when passing -interface-stubs-version=experimental-ifo-elf-v1). The 
default output pretty much produces the exact tbe that llvm-elfabi consumes so 
its not really a new yaml schema here (-interface-stubs-version=tapi-tbe or the 
default will do this), on the other hand 
-interface-stubs-version=experimental-ifo-elf-v1 can be used to give us freedom 
to target the internal yaml2obj tool if we needed to. I still need to go back 
and change all the references to either "ifso" or "ifo" to "interface stub" or 
"ifs" for consistency. I hope this is a reasonable compromise and can land with 
close to what I have here. @jakehehrlich  @compnerd thoughts?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60974/new/

https://reviews.llvm.org/D60974



__

[PATCH] D60974: Clang IFSO driver action.

2019-05-07 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi added a comment.

@jakehehrlich @compnerd ping


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60974/new/

https://reviews.llvm.org/D60974



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


[PATCH] D60974: Clang IFSO driver action.

2019-05-07 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi marked 6 inline comments as done.
plotfi added inline comments.



Comment at: clang/include/clang/Driver/Options.td:626
   HelpText<"Use the LLVM representation for assembler and object files">;
+def emit_ifso : Flag<["-"], "emit-interface-stubs">, Flags<[CC1Option]>, 
Group,
+  HelpText<"Generate Inteface Stub Files.">;

compnerd wrote:
> I thought that we were going to add `experimental` to this for the time being?
Oh, I was specifying experimental in the 
-interface-stubs-version=experimental-ifo-elf-v1. Do you want the main flag to 
also be -emit-interface-stubs-experimental??



Comment at: clang/include/clang/Driver/Types.def:91
 TYPE("ast",  AST,  INVALID, "ast",   "u")
+TYPE("ifs",  IFS,  INVALID, "ifs",   "u")
 TYPE("pcm",  ModuleFile,   INVALID, "pcm",   "u")

compnerd wrote:
> What about `ifo` instead of `ifs`?
I went with ifs because ifo implies the analog of a .o file and ifso implies 
the analog of a .so file. I want the tbe/ifs text files to just be thought of 
as something a little different. Like symbol listings that another tool can 
assemble into whatever format.  



Comment at: clang/lib/Frontend/CompilerInvocation.cpp:1649
+case OPT_emit_ifso:
+  Opts.ProgramAction = frontend::GenerateIfsoTbeExpV1;
+  if (Args.hasArg(OPT_ifso_version_EQ))

compnerd wrote:
> Can we make this required to be specified instead of defaulting please?  I 
> think that it is more clear.
I think that makes sense. 



Comment at: clang/lib/Frontend/FrontendActions.cpp:179
+  };
+  using MangledSymbols = std::map;
+

compnerd wrote:
> Hmm, I wonder if `DenseSet` is more appropriate here.  Is there some reason 
> that I am overlooking for supporting duplicate entries?  In fact, since the 
> key is a pointer, you could even do a `DenseMap`.
Can we do data-structure improvements post landing the first version? 



Comment at: clang/lib/Frontend/FrontendActions.cpp:214
+  ND->dump();
+}
+return true;

compnerd wrote:
> debugging left over?
Ah yeah I need to replace this with an llvm_unreachable or something. 



Comment at: clang/lib/Frontend/FrontendActions.cpp:297
+sema.LateTemplateParser(sema.OpaqueParser, LPT);
+HandleNamedDecl(FD, Symbols, (FromTU | IsLate));
+  }

compnerd wrote:
> Typo of `||`?  The field is boolean not a mask.
It is a bitmask. 


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60974/new/

https://reviews.llvm.org/D60974



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


[PATCH] D60974: Clang IFSO driver action.

2019-05-09 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi marked 2 inline comments as done.
plotfi added inline comments.



Comment at: clang/lib/Driver/ToolChains/Clang.cpp:3590
+Twine("-interface-stubs-version=") +
+Args.getLastArgValue(options::OPT_ifso_version_EQ)));
+  }

compnerd wrote:
> Please ensure that the value being passed is valid or emit a diagnostic.
Couldn't I do this in the cc1 path? 


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60974/new/

https://reviews.llvm.org/D60974



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


[PATCH] D60974: Clang IFSO driver action.

2019-05-09 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi marked 2 inline comments as done.
plotfi added inline comments.



Comment at: clang/lib/Frontend/FrontendActions.cpp:223
+for (auto *I : cast(ND)->decls())
+  HandleNamedDecl(dyn_cast(I), Symbols, RDO);
+return true;

compnerd wrote:
> Hmm, do we have a guarantee that the decl is named?  Could you not hit a 
> `_Static_assert` or `static_assert` in this traversal?  Or if it is a C++ 
> context, an `extern "C"` block?  What about `#pragma comment(...)`?  Please 
> add test cases for these.
HandleNamedDecl bails when the NamedDecl is not a NamedDecl. 


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60974/new/

https://reviews.llvm.org/D60974



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


[PATCH] D60974: Clang IFSO driver action.

2019-05-09 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi updated this revision to Diff 198902.
plotfi added a comment.

addressing a lot of @compnerd 's feedback. Still lots of templating.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60974/new/

https://reviews.llvm.org/D60974

Files:
  clang/include/clang/Driver/Options.td
  clang/include/clang/Driver/Types.def
  clang/include/clang/Frontend/FrontendActions.h
  clang/include/clang/Frontend/FrontendOptions.h
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CMakeLists.txt
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Frontend/InterfaceStubFunctionsConsumer.cpp
  clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
  clang/test/IFSO/foo-inline.h
  clang/test/IFSO/foo.cpp
  llvm/include/llvm/TextAPI/ELF/ELFStub.h
  llvm/lib/TextAPI/ELF/TBEHandler.cpp

Index: llvm/lib/TextAPI/ELF/TBEHandler.cpp
===
--- llvm/lib/TextAPI/ELF/TBEHandler.cpp
+++ llvm/lib/TextAPI/ELF/TBEHandler.cpp
@@ -134,6 +134,7 @@
 IO.mapRequired("TbeVersion", Stub.TbeVersion);
 IO.mapOptional("SoName", Stub.SoName);
 IO.mapRequired("Arch", (ELFArchMapper &)Stub.Arch);
+IO.mapOptional("Endian", Stub.Endian);
 IO.mapOptional("NeededLibs", Stub.NeededLibs);
 IO.mapRequired("Symbols", Stub.Symbols);
   }
Index: llvm/include/llvm/TextAPI/ELF/ELFStub.h
===
--- llvm/include/llvm/TextAPI/ELF/ELFStub.h
+++ llvm/include/llvm/TextAPI/ELF/ELFStub.h
@@ -55,6 +55,7 @@
   VersionTuple TbeVersion;
   Optional SoName;
   ELFArch Arch;
+  Optional Endian;
   std::vector NeededLibs;
   std::set Symbols;
 
Index: clang/test/IFSO/foo.cpp
===
--- /dev/null
+++ clang/test/IFSO/foo.cpp
@@ -0,0 +1,57 @@
+// Using %clang instead of %clang_cc1 because of -fvisibility
+// RUN: %clang -target x86_64-linux-gnu -emit-interface-stubs -interface-stubs-version=tapi-tbe -fvisibility=hidden %s -o - | FileCheck --check-prefix=CHECK-HIDDEN %s
+// RUN: %clang -target x86_64-linux-gnu -emit-interface-stubs -interface-stubs-version=tapi-tbe %s -o - | FileCheck %s
+
+// CHECK-HIDDEN-NOT: _Z4fbarff
+// CHECK: _Z4fbarff
+
+
+
+
+// CHECK-HIDDEN-NOT: _Z3fooii
+// CHECK-NOT:_Z3fooii
+
+
+
+#include "foo-inline.h"
+
+__attribute__ ((visibility ("hidden"))) int foo(int a, int b) { return a + b; }
+__attribute__ ((visibility ("default"))) int foo_default_visi(int a, int b) { return a + b; }
+
+
+__attribute__ ((visibility ("default"))) int fvih_1(int a, int b) { return a + fvih(); }
+
+
+__attribute__((weak)) int someWeakFunc() { return 42; }
+
+int dataA = 34;
+
+namespace baz {
+  template 
+  T add(T a, T b) {
+return a + b;
+  }
+}
+
+namespace n {
+  template 
+  struct __attribute__((__visibility__("default"))) S {
+S() = default;
+~S() = default;
+int __attribute__((__visibility__(("default" func() const { return 32; }
+int __attribute__((__visibility__(("hidden" operator()() const { return 53; }
+  };
+}
+
+template  T neverUsed(T t) { return t + 2; }
+
+template<> int neverUsed(int t);
+
+void g() { n::S()(); }
+
+namespace qux {
+int bar(int a, int b) { return baz::add(a, b); }
+}
+
+float fbar(float a, float b) { return baz::add(a, b); }
+
Index: clang/test/IFSO/foo-inline.h
===
--- /dev/null
+++ clang/test/IFSO/foo-inline.h
@@ -0,0 +1,6 @@
+
+inline int fvih() {
+static int fortytwo = 42;
+  return fortytwo;
+}
+
Index: clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
===
--- clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
+++ clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
@@ -64,6 +64,10 @@
   case GenerateHeaderModule:
 return llvm::make_unique();
   case GeneratePCH:return llvm::make_unique();
+  case GenerateInterfaceYAMLExpV1:
+return llvm::make_unique();
+  case GenerateInterfaceTBEExpV1:
+return llvm::make_unique();
   case InitOnly:   return llvm::make_unique();
   case ParseSyntaxOnly:return llvm::make_unique();
   case ModuleFileInfo: return llvm::make_unique();
Index: clang/lib/Frontend/InterfaceStubFunctionsConsumer.cpp
===
--- /dev/null
+++ clang/lib/Frontend/InterfaceStubFunctionsConsumer.cpp
@@ -0,0 +1,280 @@
+//===--- InterfaceStubFunctionsConsumer.cpp ---===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "clang/AST/RecursiveASTVisitor.h"
+#include "clang/Frontend/CompilerInstan

[PATCH] D60974: Clang IFSO driver action.

2019-06-04 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi updated this revision to Diff 202976.
plotfi added a comment.

Adding a test for inheritance and constructors/destroctors. Also addressing 
feedback from @alexshap


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60974/new/

https://reviews.llvm.org/D60974

Files:
  clang/include/clang/Driver/Options.td
  clang/include/clang/Driver/Types.def
  clang/include/clang/Frontend/FrontendActions.h
  clang/include/clang/Frontend/FrontendOptions.h
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CMakeLists.txt
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Frontend/InterfaceStubFunctionsConsumer.cpp
  clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
  clang/test/InterfaceStubs/bad-format.cpp
  clang/test/InterfaceStubs/class-template-specialization.cpp
  clang/test/InterfaceStubs/externstatic.c
  clang/test/InterfaceStubs/function-template-specialization.cpp
  clang/test/InterfaceStubs/inline.c
  clang/test/InterfaceStubs/inline.h
  clang/test/InterfaceStubs/object.cpp
  clang/test/InterfaceStubs/public-hidden.cpp
  clang/test/InterfaceStubs/template-namespace-function.cpp
  clang/test/InterfaceStubs/virtual.cpp
  clang/test/InterfaceStubs/visibility.cpp
  clang/test/InterfaceStubs/weak.cpp

Index: clang/test/InterfaceStubs/weak.cpp
===
--- /dev/null
+++ clang/test/InterfaceStubs/weak.cpp
@@ -0,0 +1,27 @@
+// RUN: %clang -target x86_64-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-tapi-elf-v1 %s | \
+// RUN: FileCheck %s
+
+// RUN: %clang -target x86_64-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-yaml-elf-v1 %s | \
+// RUN: FileCheck --check-prefix=CHECK-YAML %s
+
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -c %s | llvm-nm - 2>&1 | \
+// RUN: FileCheck -check-prefix=CHECK-SYMBOLS %s
+
+// CHECK: Symbols:
+// CHECK-NEXT:  _Z8weakFuncv: { Type: Func, Weak: true }
+// CHECK-NEXT:  _Z10strongFuncv: { Type: Func }
+
+// CHECK-YAML: Symbols:
+// CHECK-YAML-NEXT:   - Name:_Z8weakFuncv
+// CHECK-YAML-NEXT: Type:STT_FUNC
+// CHECK-YAML-NEXT: Binding: STB_WEAK
+// CHECK-YAML-NEXT:   - Name:_Z10strongFuncv
+// CHECK-YAML-NEXT: Type:STT_FUNC
+// CHECK-YAML-NEXT: Binding: STB_GLOBAL
+
+// CHECK-SYMBOLS: _Z10strongFuncv
+// CHECK-SYMBOLS: _Z8weakFuncv
+__attribute__((weak)) void weakFunc() {}
+int strongFunc() { return 42; }
Index: clang/test/InterfaceStubs/visibility.cpp
===
--- /dev/null
+++ clang/test/InterfaceStubs/visibility.cpp
@@ -0,0 +1,35 @@
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-tapi-elf-v1 -fvisibility=hidden \
+// RUN: %s | FileCheck --check-prefix=CHECK-CMD-HIDDEN %s
+
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-yaml-elf-v1 -fvisibility=hidden \
+// RUN: %s | FileCheck --check-prefix=CHECK-CMD-HIDDEN %s
+
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-tapi-elf-v1 %s | FileCheck %s
+
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-yaml-elf-v1 %s | FileCheck %s
+
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -c %s | llvm-readelf -s - 2>&1 | \
+// RUN: FileCheck -check-prefix=CHECK-SYMBOLS %s
+
+// Always Be Hidden:
+// CHECK-CMD-HIDDEN-NOT: _Z6hiddenv
+// CHECK-NOT: _Z6hiddenv
+__attribute__((visibility("hidden"))) void hidden() {}
+
+// Always Be Visible:
+// CHECK-CMD-HIDDEN: _Z9nothiddenv
+// CHECK: _Z9nothiddenv
+__attribute__((visibility("default"))) void nothidden() {}
+
+// Do Whatever -fvisibility says:
+// CHECK-CMD-HIDDEN-NOT: _Z10cmdVisiblev
+// CHECK: _Z10cmdVisiblev
+void cmdVisible() {}
+
+// CHECK-SYMBOLS: DEFAULT{{.*}} _Z10cmdVisiblev
+// CHECK-SYMBOLS: HIDDEN {{.*}} _Z6hiddenv
+// CHECK-SYMBOLS: DEFAULT{{.*}} _Z9nothiddenv
Index: clang/test/InterfaceStubs/virtual.cpp
===
--- /dev/null
+++ clang/test/InterfaceStubs/virtual.cpp
@@ -0,0 +1,38 @@
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-tapi-elf-v1 %s | \
+// RUN: FileCheck -check-prefix=CHECK-TAPI %s
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -c %s | \
+// RUN: llvm-readelf -s - 2>&1 | FileCheck -check-prefix=CHECK-SYMBOLS %s
+
+#define HIDDEN  __attribute__((__visibility__(("hidden"
+#define DEFAULT __attribute__((__visibility__(("default"
+
+// CHECK-TAPI-NOT: _ZNK1Q5func1Ev
+// CHECK-TAPI-NOT: _ZNK1Q5func2Ev
+// CHECK-SYMBOLS: NOTYPE  GLOBAL HIDDEN   {{.*}} _Z

[PATCH] D60974: Clang IFSO driver action.

2019-06-06 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi updated this revision to Diff 203464.
plotfi added a comment.

Updated hidden parent/child class inheritance cases.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60974/new/

https://reviews.llvm.org/D60974

Files:
  clang/include/clang/Driver/Options.td
  clang/include/clang/Driver/Types.def
  clang/include/clang/Frontend/FrontendActions.h
  clang/include/clang/Frontend/FrontendOptions.h
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CMakeLists.txt
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Frontend/InterfaceStubFunctionsConsumer.cpp
  clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
  clang/test/InterfaceStubs/bad-format.cpp
  clang/test/InterfaceStubs/class-template-specialization.cpp
  clang/test/InterfaceStubs/externstatic.c
  clang/test/InterfaceStubs/function-template-specialization.cpp
  clang/test/InterfaceStubs/inline.c
  clang/test/InterfaceStubs/inline.h
  clang/test/InterfaceStubs/object.cpp
  clang/test/InterfaceStubs/public-hidden.cpp
  clang/test/InterfaceStubs/template-namespace-function.cpp
  clang/test/InterfaceStubs/virtual.cpp
  clang/test/InterfaceStubs/visibility.cpp
  clang/test/InterfaceStubs/weak.cpp

Index: clang/test/InterfaceStubs/weak.cpp
===
--- /dev/null
+++ clang/test/InterfaceStubs/weak.cpp
@@ -0,0 +1,27 @@
+// RUN: %clang -target x86_64-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-tapi-elf-v1 %s | \
+// RUN: FileCheck %s
+
+// RUN: %clang -target x86_64-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-yaml-elf-v1 %s | \
+// RUN: FileCheck --check-prefix=CHECK-YAML %s
+
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -c %s | llvm-nm - 2>&1 | \
+// RUN: FileCheck -check-prefix=CHECK-SYMBOLS %s
+
+// CHECK: Symbols:
+// CHECK-DAG:  _Z8weakFuncv: { Type: Func, Weak: true }
+// CHECK-DAG:  _Z10strongFuncv: { Type: Func }
+
+// CHECK-YAML: Symbols:
+// CHECK-YAML-DAG:   - Name:_Z8weakFuncv
+// CHECK-YAML-DAG: Type:STT_FUNC
+// CHECK-YAML-DAG: Binding: STB_WEAK
+// CHECK-YAML-DAG:   - Name:_Z10strongFuncv
+// CHECK-YAML-DAG: Type:STT_FUNC
+// CHECK-YAML-DAG: Binding: STB_GLOBAL
+
+// CHECK-SYMBOLS-DAG: _Z10strongFuncv
+// CHECK-SYMBOLS-DAG: _Z8weakFuncv
+__attribute__((weak)) void weakFunc() {}
+int strongFunc() { return 42; }
Index: clang/test/InterfaceStubs/visibility.cpp
===
--- /dev/null
+++ clang/test/InterfaceStubs/visibility.cpp
@@ -0,0 +1,35 @@
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-tapi-elf-v1 -fvisibility=hidden \
+// RUN: %s | FileCheck --check-prefix=CHECK-CMD-HIDDEN %s
+
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-yaml-elf-v1 -fvisibility=hidden \
+// RUN: %s | FileCheck --check-prefix=CHECK-CMD-HIDDEN %s
+
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-tapi-elf-v1 %s | FileCheck %s
+
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-yaml-elf-v1 %s | FileCheck %s
+
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -c %s | llvm-readelf -s - 2>&1 | \
+// RUN: FileCheck -check-prefix=CHECK-SYMBOLS %s
+
+// Always Be Hidden:
+// CHECK-CMD-HIDDEN-NOT: _Z6hiddenv
+// CHECK-NOT: _Z6hiddenv
+__attribute__((visibility("hidden"))) void hidden() {}
+
+// Always Be Visible:
+// CHECK-CMD-HIDDEN: _Z9nothiddenv
+// CHECK-DAG: _Z9nothiddenv
+__attribute__((visibility("default"))) void nothidden() {}
+
+// Do Whatever -fvisibility says:
+// CHECK-CMD-HIDDEN-NOT: _Z10cmdVisiblev
+// CHECK-DAG: _Z10cmdVisiblev
+void cmdVisible() {}
+
+// CHECK-SYMBOLS-DAG: DEFAULT{{.*}} _Z10cmdVisiblev
+// CHECK-SYMBOLS-DAG: HIDDEN {{.*}} _Z6hiddenv
+// CHECK-SYMBOLS-DAG: DEFAULT{{.*}} _Z9nothiddenv
Index: clang/test/InterfaceStubs/virtual.cpp
===
--- /dev/null
+++ clang/test/InterfaceStubs/virtual.cpp
@@ -0,0 +1,38 @@
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-tapi-elf-v1 %s | \
+// RUN: FileCheck -check-prefix=CHECK-TAPI %s
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -c %s | \
+// RUN: llvm-readelf -s - 2>&1 | FileCheck -check-prefix=CHECK-SYMBOLS %s
+
+#define HIDDEN  __attribute__((__visibility__(("hidden"
+#define DEFAULT __attribute__((__visibility__(("default"
+
+// CHECK-TAPI-NOT: _ZNK1Q5func1Ev
+// CHECK-TAPI-NOT: _ZNK1Q5func2Ev
+// CHECK-SYMBOLS-DAG: NOTYPE  GLOBAL HIDDEN   {{.*}} _ZNK1Q5func1Ev
+// CHECK-S

[PATCH] D60974: Clang IFSO driver action.

2019-06-06 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi updated this revision to Diff 203465.
plotfi added a comment.

git mv'ed hidden-class-inheritance.cpp


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60974/new/

https://reviews.llvm.org/D60974

Files:
  clang/include/clang/Driver/Options.td
  clang/include/clang/Driver/Types.def
  clang/include/clang/Frontend/FrontendActions.h
  clang/include/clang/Frontend/FrontendOptions.h
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CMakeLists.txt
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Frontend/InterfaceStubFunctionsConsumer.cpp
  clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
  clang/test/InterfaceStubs/bad-format.cpp
  clang/test/InterfaceStubs/class-template-specialization.cpp
  clang/test/InterfaceStubs/externstatic.c
  clang/test/InterfaceStubs/function-template-specialization.cpp
  clang/test/InterfaceStubs/hidden-class-inheritance.cpp
  clang/test/InterfaceStubs/inline.c
  clang/test/InterfaceStubs/inline.h
  clang/test/InterfaceStubs/object.cpp
  clang/test/InterfaceStubs/template-namespace-function.cpp
  clang/test/InterfaceStubs/virtual.cpp
  clang/test/InterfaceStubs/visibility.cpp
  clang/test/InterfaceStubs/weak.cpp

Index: clang/test/InterfaceStubs/weak.cpp
===
--- /dev/null
+++ clang/test/InterfaceStubs/weak.cpp
@@ -0,0 +1,27 @@
+// RUN: %clang -target x86_64-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-tapi-elf-v1 %s | \
+// RUN: FileCheck %s
+
+// RUN: %clang -target x86_64-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-yaml-elf-v1 %s | \
+// RUN: FileCheck --check-prefix=CHECK-YAML %s
+
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -c %s | llvm-nm - 2>&1 | \
+// RUN: FileCheck -check-prefix=CHECK-SYMBOLS %s
+
+// CHECK: Symbols:
+// CHECK-DAG:  _Z8weakFuncv: { Type: Func, Weak: true }
+// CHECK-DAG:  _Z10strongFuncv: { Type: Func }
+
+// CHECK-YAML: Symbols:
+// CHECK-YAML-DAG:   - Name:_Z8weakFuncv
+// CHECK-YAML-DAG: Type:STT_FUNC
+// CHECK-YAML-DAG: Binding: STB_WEAK
+// CHECK-YAML-DAG:   - Name:_Z10strongFuncv
+// CHECK-YAML-DAG: Type:STT_FUNC
+// CHECK-YAML-DAG: Binding: STB_GLOBAL
+
+// CHECK-SYMBOLS-DAG: _Z10strongFuncv
+// CHECK-SYMBOLS-DAG: _Z8weakFuncv
+__attribute__((weak)) void weakFunc() {}
+int strongFunc() { return 42; }
Index: clang/test/InterfaceStubs/visibility.cpp
===
--- /dev/null
+++ clang/test/InterfaceStubs/visibility.cpp
@@ -0,0 +1,35 @@
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-tapi-elf-v1 -fvisibility=hidden \
+// RUN: %s | FileCheck --check-prefix=CHECK-CMD-HIDDEN %s
+
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-yaml-elf-v1 -fvisibility=hidden \
+// RUN: %s | FileCheck --check-prefix=CHECK-CMD-HIDDEN %s
+
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-tapi-elf-v1 %s | FileCheck %s
+
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-yaml-elf-v1 %s | FileCheck %s
+
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -c %s | llvm-readelf -s - 2>&1 | \
+// RUN: FileCheck -check-prefix=CHECK-SYMBOLS %s
+
+// Always Be Hidden:
+// CHECK-CMD-HIDDEN-NOT: _Z6hiddenv
+// CHECK-NOT: _Z6hiddenv
+__attribute__((visibility("hidden"))) void hidden() {}
+
+// Always Be Visible:
+// CHECK-CMD-HIDDEN: _Z9nothiddenv
+// CHECK-DAG: _Z9nothiddenv
+__attribute__((visibility("default"))) void nothidden() {}
+
+// Do Whatever -fvisibility says:
+// CHECK-CMD-HIDDEN-NOT: _Z10cmdVisiblev
+// CHECK-DAG: _Z10cmdVisiblev
+void cmdVisible() {}
+
+// CHECK-SYMBOLS-DAG: DEFAULT{{.*}} _Z10cmdVisiblev
+// CHECK-SYMBOLS-DAG: HIDDEN {{.*}} _Z6hiddenv
+// CHECK-SYMBOLS-DAG: DEFAULT{{.*}} _Z9nothiddenv
Index: clang/test/InterfaceStubs/virtual.cpp
===
--- /dev/null
+++ clang/test/InterfaceStubs/virtual.cpp
@@ -0,0 +1,38 @@
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-tapi-elf-v1 %s | \
+// RUN: FileCheck -check-prefix=CHECK-TAPI %s
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -c %s | \
+// RUN: llvm-readelf -s - 2>&1 | FileCheck -check-prefix=CHECK-SYMBOLS %s
+
+#define HIDDEN  __attribute__((__visibility__(("hidden"
+#define DEFAULT __attribute__((__visibility__(("default"
+
+// CHECK-TAPI-NOT: _ZNK1Q5func1Ev
+// CHECK-TAPI-NOT: _ZNK1Q5func2Ev
+// CHECK-SYMBOLS-DAG: NOTYPE  GLOBAL HIDDEN   {{.*}} _ZNK1Q5func1Ev
+// CHECK-SYMB

[PATCH] D61914: [Support][Test] Time profiler: add regression test

2019-06-07 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi added a comment.

cfe/trunk/test/Driver/check-time-trace.cpp appears to fail on Darwin. Did you 
mean to pass the target explicitly ?


Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D61914/new/

https://reviews.llvm.org/D61914



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


[PATCH] D61914: [Support][Test] Time profiler: add regression test

2019-06-07 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi added inline comments.



Comment at: cfe/trunk/test/Driver/check-time-trace.cpp:1
+// RUN: %clangxx -ftime-trace %s 2>&1 | grep "Time trace json-file dumped to" \
+// RUN:   | awk '{print $NF}' | xargs cat \

This test should probably have // REQUIRES: shell


Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D61914/new/

https://reviews.llvm.org/D61914



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


[PATCH] D60974: Clang IFSO driver action.

2019-06-07 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi updated this revision to Diff 203638.
plotfi added a comment.

-U99


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60974/new/

https://reviews.llvm.org/D60974

Files:
  clang/include/clang/Driver/Options.td
  clang/include/clang/Driver/Types.def
  clang/include/clang/Frontend/FrontendActions.h
  clang/include/clang/Frontend/FrontendOptions.h
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CMakeLists.txt
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Frontend/InterfaceStubFunctionsConsumer.cpp
  clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
  clang/test/InterfaceStubs/bad-format.cpp
  clang/test/InterfaceStubs/class-template-specialization.cpp
  clang/test/InterfaceStubs/externstatic.c
  clang/test/InterfaceStubs/function-template-specialization.cpp
  clang/test/InterfaceStubs/hidden-class-inheritance.cpp
  clang/test/InterfaceStubs/inline.c
  clang/test/InterfaceStubs/inline.h
  clang/test/InterfaceStubs/object.cpp
  clang/test/InterfaceStubs/template-namespace-function.cpp
  clang/test/InterfaceStubs/virtual.cpp
  clang/test/InterfaceStubs/visibility.cpp
  clang/test/InterfaceStubs/weak.cpp

Index: clang/test/InterfaceStubs/weak.cpp
===
--- /dev/null
+++ clang/test/InterfaceStubs/weak.cpp
@@ -0,0 +1,27 @@
+// RUN: %clang -target x86_64-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-tapi-elf-v1 %s | \
+// RUN: FileCheck %s
+
+// RUN: %clang -target x86_64-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-yaml-elf-v1 %s | \
+// RUN: FileCheck --check-prefix=CHECK-YAML %s
+
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -c %s | llvm-nm - 2>&1 | \
+// RUN: FileCheck -check-prefix=CHECK-SYMBOLS %s
+
+// CHECK: Symbols:
+// CHECK-DAG:  _Z8weakFuncv: { Type: Func, Weak: true }
+// CHECK-DAG:  _Z10strongFuncv: { Type: Func }
+
+// CHECK-YAML: Symbols:
+// CHECK-YAML-DAG:   - Name:_Z8weakFuncv
+// CHECK-YAML-DAG: Type:STT_FUNC
+// CHECK-YAML-DAG: Binding: STB_WEAK
+// CHECK-YAML-DAG:   - Name:_Z10strongFuncv
+// CHECK-YAML-DAG: Type:STT_FUNC
+// CHECK-YAML-DAG: Binding: STB_GLOBAL
+
+// CHECK-SYMBOLS-DAG: _Z10strongFuncv
+// CHECK-SYMBOLS-DAG: _Z8weakFuncv
+__attribute__((weak)) void weakFunc() {}
+int strongFunc() { return 42; }
Index: clang/test/InterfaceStubs/visibility.cpp
===
--- /dev/null
+++ clang/test/InterfaceStubs/visibility.cpp
@@ -0,0 +1,35 @@
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-tapi-elf-v1 -fvisibility=hidden \
+// RUN: %s | FileCheck --check-prefix=CHECK-CMD-HIDDEN %s
+
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-yaml-elf-v1 -fvisibility=hidden \
+// RUN: %s | FileCheck --check-prefix=CHECK-CMD-HIDDEN %s
+
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-tapi-elf-v1 %s | FileCheck %s
+
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-yaml-elf-v1 %s | FileCheck %s
+
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -c %s | llvm-readelf -s - 2>&1 | \
+// RUN: FileCheck -check-prefix=CHECK-SYMBOLS %s
+
+// Always Be Hidden:
+// CHECK-CMD-HIDDEN-NOT: _Z6hiddenv
+// CHECK-NOT: _Z6hiddenv
+__attribute__((visibility("hidden"))) void hidden() {}
+
+// Always Be Visible:
+// CHECK-CMD-HIDDEN: _Z9nothiddenv
+// CHECK-DAG: _Z9nothiddenv
+__attribute__((visibility("default"))) void nothidden() {}
+
+// Do Whatever -fvisibility says:
+// CHECK-CMD-HIDDEN-NOT: _Z10cmdVisiblev
+// CHECK-DAG: _Z10cmdVisiblev
+void cmdVisible() {}
+
+// CHECK-SYMBOLS-DAG: DEFAULT{{.*}} _Z10cmdVisiblev
+// CHECK-SYMBOLS-DAG: HIDDEN {{.*}} _Z6hiddenv
+// CHECK-SYMBOLS-DAG: DEFAULT{{.*}} _Z9nothiddenv
Index: clang/test/InterfaceStubs/virtual.cpp
===
--- /dev/null
+++ clang/test/InterfaceStubs/virtual.cpp
@@ -0,0 +1,38 @@
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-tapi-elf-v1 %s | \
+// RUN: FileCheck -check-prefix=CHECK-TAPI %s
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -c %s | \
+// RUN: llvm-readelf -s - 2>&1 | FileCheck -check-prefix=CHECK-SYMBOLS %s
+
+#define HIDDEN  __attribute__((__visibility__(("hidden"
+#define DEFAULT __attribute__((__visibility__(("default"
+
+// CHECK-TAPI-NOT: _ZNK1Q5func1Ev
+// CHECK-TAPI-NOT: _ZNK1Q5func2Ev
+// CHECK-SYMBOLS-DAG: NOTYPE  GLOBAL HIDDEN   {{.*}} _ZNK1Q5func1Ev
+// CHECK-SYMBOLS-DAG: NOTYPE  GLOBAL DEFAUL

[PATCH] D60974: Clang IFSO driver action.

2019-06-11 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi updated this revision to Diff 204187.
plotfi marked 11 inline comments as done.
plotfi added a comment.

addressing @rupprecht's feedback


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60974/new/

https://reviews.llvm.org/D60974

Files:
  clang/include/clang/Basic/DiagnosticFrontendKinds.td
  clang/include/clang/Driver/Options.td
  clang/include/clang/Driver/Types.def
  clang/include/clang/Frontend/FrontendActions.h
  clang/include/clang/Frontend/FrontendOptions.h
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CMakeLists.txt
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Frontend/InterfaceStubFunctionsConsumer.cpp
  clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
  clang/test/InterfaceStubs/bad-format.cpp
  clang/test/InterfaceStubs/class-template-specialization.cpp
  clang/test/InterfaceStubs/externstatic.c
  clang/test/InterfaceStubs/function-template-specialization.cpp
  clang/test/InterfaceStubs/hidden-class-inheritance.cpp
  clang/test/InterfaceStubs/inline.c
  clang/test/InterfaceStubs/inline.h
  clang/test/InterfaceStubs/object.cpp
  clang/test/InterfaceStubs/template-namespace-function.cpp
  clang/test/InterfaceStubs/virtual.cpp
  clang/test/InterfaceStubs/visibility.cpp
  clang/test/InterfaceStubs/weak.cpp

Index: clang/test/InterfaceStubs/weak.cpp
===
--- /dev/null
+++ clang/test/InterfaceStubs/weak.cpp
@@ -0,0 +1,27 @@
+// RUN: %clang -target x86_64-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-tapi-elf-v1 %s | \
+// RUN: FileCheck %s
+
+// RUN: %clang -target x86_64-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-yaml-elf-v1 %s | \
+// RUN: FileCheck --check-prefix=CHECK-YAML %s
+
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -c %s | llvm-nm - 2>&1 | \
+// RUN: FileCheck -check-prefix=CHECK-SYMBOLS %s
+
+// CHECK: Symbols:
+// CHECK-DAG:  _Z8weakFuncv: { Type: Func, Weak: true }
+// CHECK-DAG:  _Z10strongFuncv: { Type: Func }
+
+// CHECK-YAML: Symbols:
+// CHECK-YAML-DAG:   - Name:_Z8weakFuncv
+// CHECK-YAML-DAG: Type:STT_FUNC
+// CHECK-YAML-DAG: Binding: STB_WEAK
+// CHECK-YAML-DAG:   - Name:_Z10strongFuncv
+// CHECK-YAML-DAG: Type:STT_FUNC
+// CHECK-YAML-DAG: Binding: STB_GLOBAL
+
+// CHECK-SYMBOLS-DAG: _Z10strongFuncv
+// CHECK-SYMBOLS-DAG: _Z8weakFuncv
+__attribute__((weak)) void weakFunc() {}
+int strongFunc() { return 42; }
Index: clang/test/InterfaceStubs/visibility.cpp
===
--- /dev/null
+++ clang/test/InterfaceStubs/visibility.cpp
@@ -0,0 +1,35 @@
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-tapi-elf-v1 -fvisibility=hidden \
+// RUN: %s | FileCheck --check-prefix=CHECK-CMD-HIDDEN %s
+
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-yaml-elf-v1 -fvisibility=hidden \
+// RUN: %s | FileCheck --check-prefix=CHECK-CMD-HIDDEN %s
+
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-tapi-elf-v1 %s | FileCheck %s
+
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-yaml-elf-v1 %s | FileCheck %s
+
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -c %s | llvm-readelf -s - 2>&1 | \
+// RUN: FileCheck -check-prefix=CHECK-SYMBOLS %s
+
+// Always Be Hidden:
+// CHECK-CMD-HIDDEN-NOT: _Z6hiddenv
+// CHECK-NOT: _Z6hiddenv
+__attribute__((visibility("hidden"))) void hidden() {}
+
+// Always Be Visible:
+// CHECK-CMD-HIDDEN: _Z9nothiddenv
+// CHECK-DAG: _Z9nothiddenv
+__attribute__((visibility("default"))) void nothidden() {}
+
+// Do Whatever -fvisibility says:
+// CHECK-CMD-HIDDEN-NOT: _Z10cmdVisiblev
+// CHECK-DAG: _Z10cmdVisiblev
+void cmdVisible() {}
+
+// CHECK-SYMBOLS-DAG: DEFAULT{{.*}} _Z10cmdVisiblev
+// CHECK-SYMBOLS-DAG: HIDDEN {{.*}} _Z6hiddenv
+// CHECK-SYMBOLS-DAG: DEFAULT{{.*}} _Z9nothiddenv
Index: clang/test/InterfaceStubs/virtual.cpp
===
--- /dev/null
+++ clang/test/InterfaceStubs/virtual.cpp
@@ -0,0 +1,38 @@
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-tapi-elf-v1 %s | \
+// RUN: FileCheck -check-prefix=CHECK-TAPI %s
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -c %s | \
+// RUN: llvm-readelf -s - 2>&1 | FileCheck -check-prefix=CHECK-SYMBOLS %s
+
+#define HIDDEN  __attribute__((__visibility__(("hidden"
+#define DEFAULT __attribute__((__visibility__(("default"
+
+// CHECK-TAPI-NOT: _ZNK1Q5func1Ev
+// CHECK-TAPI-NOT: _ZNK1Q5

[PATCH] D60974: Clang IFSO driver action.

2019-06-11 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi marked 3 inline comments as done.
plotfi added a comment.

In D60974#1534662 , @rupprecht wrote:

> Can you upload this patch with context? Either use arc or upload w/ -U9


Thanks for the review.

> I seem to have a lot of comments, but they're all nits -- my major concern 
> being the `llvm_unreachable`s should be errors instead (i.e. should be 
> triggered in release builds).
> 
> Since this is clearly labeled as experimental, I think you should feel free 
> to commit if you can get another lgtm (@compnerd?)






Comment at: clang/lib/Driver/ToolChains/Clang.cpp:3614-3616
+  Args.hasArg(options::OPT_iterface_stub_version_EQ)
+  ? Args.getLastArgValue(options::OPT_iterface_stub_version_EQ)
+  : "")

rupprecht wrote:
> `Args.getLastArgValue(options::OPT_iterface_stub_version_EQ)` should already 
> default to returning the empty string if unset (note the default param)
But what if it is set to something that's not either experimental-yaml-elf-v1 
or experimental-tapi-elf-v1? This was to truncate any values that aren't those 
two to "" so that the error check could just be if (StubFormat.empty()). Maybe 
something other than a string switch would have been more explicit. 



Comment at: clang/lib/Frontend/CompilerInvocation.cpp:1688
+  if (!ProgramActionPair.second)
+llvm_unreachable("Must specify a valid interface stub format.");
+  Opts.ProgramAction = ProgramActionPair.first;

rupprecht wrote:
> I think this is very much reachable if someone provides 
> `--interface-stub-version=x`
AH yes, you are right. This should probably be a diag. 
(clang/test/InterfaceStubs/bad-format.cpp tests for this "unreachable").



Comment at: clang/lib/Frontend/InterfaceStubFunctionsConsumer.cpp:41
+  return true;
+if (Symbols.find(ND) != Symbols.end())
+  return true;

rupprecht wrote:
> llvm::is_contained(Symbols, ND)
llvm::is_contained does not appear to work with std::map. I will try to figure 
out why. 


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60974/new/

https://reviews.llvm.org/D60974



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


[PATCH] D60974: Clang IFSO driver action.

2019-06-12 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi updated this revision to Diff 204308.
plotfi marked 2 inline comments as done.
plotfi added a comment.

Improving support for visibility correctness with classes, methods and 
inheritance.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60974/new/

https://reviews.llvm.org/D60974

Files:
  clang/include/clang/Basic/DiagnosticFrontendKinds.td
  clang/include/clang/Driver/Options.td
  clang/include/clang/Driver/Types.def
  clang/include/clang/Frontend/FrontendActions.h
  clang/include/clang/Frontend/FrontendOptions.h
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CMakeLists.txt
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Frontend/InterfaceStubFunctionsConsumer.cpp
  clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
  clang/test/InterfaceStubs/bad-format.cpp
  clang/test/InterfaceStubs/class-template-specialization.cpp
  clang/test/InterfaceStubs/externstatic.c
  clang/test/InterfaceStubs/function-template-specialization.cpp
  clang/test/InterfaceStubs/hidden-class-inheritance.cpp
  clang/test/InterfaceStubs/inline.c
  clang/test/InterfaceStubs/inline.h
  clang/test/InterfaceStubs/object.cpp
  clang/test/InterfaceStubs/template-namespace-function.cpp
  clang/test/InterfaceStubs/virtual.cpp
  clang/test/InterfaceStubs/visibility.cpp
  clang/test/InterfaceStubs/weak.cpp

Index: clang/test/InterfaceStubs/weak.cpp
===
--- /dev/null
+++ clang/test/InterfaceStubs/weak.cpp
@@ -0,0 +1,27 @@
+// RUN: %clang -target x86_64-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-tapi-elf-v1 %s | \
+// RUN: FileCheck %s
+
+// RUN: %clang -target x86_64-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-yaml-elf-v1 %s | \
+// RUN: FileCheck --check-prefix=CHECK-YAML %s
+
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -c %s | llvm-nm - 2>&1 | \
+// RUN: FileCheck -check-prefix=CHECK-SYMBOLS %s
+
+// CHECK: Symbols:
+// CHECK-DAG:  _Z8weakFuncv: { Type: Func, Weak: true }
+// CHECK-DAG:  _Z10strongFuncv: { Type: Func }
+
+// CHECK-YAML: Symbols:
+// CHECK-YAML-DAG:   - Name:_Z8weakFuncv
+// CHECK-YAML-DAG: Type:STT_FUNC
+// CHECK-YAML-DAG: Binding: STB_WEAK
+// CHECK-YAML-DAG:   - Name:_Z10strongFuncv
+// CHECK-YAML-DAG: Type:STT_FUNC
+// CHECK-YAML-DAG: Binding: STB_GLOBAL
+
+// CHECK-SYMBOLS-DAG: _Z10strongFuncv
+// CHECK-SYMBOLS-DAG: _Z8weakFuncv
+__attribute__((weak)) void weakFunc() {}
+int strongFunc() { return 42; }
Index: clang/test/InterfaceStubs/visibility.cpp
===
--- /dev/null
+++ clang/test/InterfaceStubs/visibility.cpp
@@ -0,0 +1,35 @@
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-tapi-elf-v1 -fvisibility=hidden \
+// RUN: %s | FileCheck --check-prefix=CHECK-CMD-HIDDEN %s
+
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-yaml-elf-v1 -fvisibility=hidden \
+// RUN: %s | FileCheck --check-prefix=CHECK-CMD-HIDDEN %s
+
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-tapi-elf-v1 %s | FileCheck %s
+
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-yaml-elf-v1 %s | FileCheck %s
+
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -c %s | llvm-readelf -s - 2>&1 | \
+// RUN: FileCheck -check-prefix=CHECK-SYMBOLS %s
+
+// Always Be Hidden:
+// CHECK-CMD-HIDDEN-NOT: _Z6hiddenv
+// CHECK-NOT: _Z6hiddenv
+__attribute__((visibility("hidden"))) void hidden() {}
+
+// Always Be Visible:
+// CHECK-CMD-HIDDEN: _Z9nothiddenv
+// CHECK-DAG: _Z9nothiddenv
+__attribute__((visibility("default"))) void nothidden() {}
+
+// Do Whatever -fvisibility says:
+// CHECK-CMD-HIDDEN-NOT: _Z10cmdVisiblev
+// CHECK-DAG: _Z10cmdVisiblev
+void cmdVisible() {}
+
+// CHECK-SYMBOLS-DAG: DEFAULT{{.*}} _Z10cmdVisiblev
+// CHECK-SYMBOLS-DAG: HIDDEN {{.*}} _Z6hiddenv
+// CHECK-SYMBOLS-DAG: DEFAULT{{.*}} _Z9nothiddenv
Index: clang/test/InterfaceStubs/virtual.cpp
===
--- /dev/null
+++ clang/test/InterfaceStubs/virtual.cpp
@@ -0,0 +1,38 @@
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-tapi-elf-v1 %s | \
+// RUN: FileCheck -check-prefix=CHECK-TAPI %s
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -c %s | \
+// RUN: llvm-readelf -s - 2>&1 | FileCheck -check-prefix=CHECK-SYMBOLS %s
+
+#define HIDDEN  __attribute__((__visibility__(("hidden"
+#define DEFAULT __attribute__((__visibility__(("default"
+
+// CHECK-T

[PATCH] D60974: Clang IFSO driver action.

2019-06-16 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi updated this revision to Diff 204978.
plotfi marked 17 inline comments as done.
plotfi added a comment.

Addressing @compnerd's feedback


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60974/new/

https://reviews.llvm.org/D60974

Files:
  clang/include/clang/Basic/DiagnosticFrontendKinds.td
  clang/include/clang/Driver/Options.td
  clang/include/clang/Driver/Types.def
  clang/include/clang/Frontend/FrontendActions.h
  clang/include/clang/Frontend/FrontendOptions.h
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CMakeLists.txt
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Frontend/InterfaceStubFunctionsConsumer.cpp
  clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
  clang/test/InterfaceStubs/bad-format.cpp
  clang/test/InterfaceStubs/class-template-specialization.cpp
  clang/test/InterfaceStubs/externstatic.c
  clang/test/InterfaceStubs/function-template-specialization.cpp
  clang/test/InterfaceStubs/hidden-class-inheritance.cpp
  clang/test/InterfaceStubs/inline.c
  clang/test/InterfaceStubs/inline.h
  clang/test/InterfaceStubs/object.cpp
  clang/test/InterfaceStubs/template-namespace-function.cpp
  clang/test/InterfaceStubs/virtual.cpp
  clang/test/InterfaceStubs/visibility.cpp
  clang/test/InterfaceStubs/weak.cpp

Index: clang/test/InterfaceStubs/weak.cpp
===
--- /dev/null
+++ clang/test/InterfaceStubs/weak.cpp
@@ -0,0 +1,27 @@
+// RUN: %clang -target x86_64-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-tapi-elf-v1 %s | \
+// RUN: FileCheck %s
+
+// RUN: %clang -target x86_64-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-yaml-elf-v1 %s | \
+// RUN: FileCheck --check-prefix=CHECK-YAML %s
+
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -c %s | llvm-nm - 2>&1 | \
+// RUN: FileCheck -check-prefix=CHECK-SYMBOLS %s
+
+// CHECK: Symbols:
+// CHECK-DAG:  _Z8weakFuncv: { Type: Func, Weak: true }
+// CHECK-DAG:  _Z10strongFuncv: { Type: Func }
+
+// CHECK-YAML: Symbols:
+// CHECK-YAML-DAG:   - Name:_Z8weakFuncv
+// CHECK-YAML-DAG: Type:STT_FUNC
+// CHECK-YAML-DAG: Binding: STB_WEAK
+// CHECK-YAML-DAG:   - Name:_Z10strongFuncv
+// CHECK-YAML-DAG: Type:STT_FUNC
+// CHECK-YAML-DAG: Binding: STB_GLOBAL
+
+// CHECK-SYMBOLS-DAG: _Z10strongFuncv
+// CHECK-SYMBOLS-DAG: _Z8weakFuncv
+__attribute__((weak)) void weakFunc() {}
+int strongFunc() { return 42; }
Index: clang/test/InterfaceStubs/visibility.cpp
===
--- /dev/null
+++ clang/test/InterfaceStubs/visibility.cpp
@@ -0,0 +1,35 @@
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-tapi-elf-v1 -fvisibility=hidden \
+// RUN: %s | FileCheck --check-prefix=CHECK-CMD-HIDDEN %s
+
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-yaml-elf-v1 -fvisibility=hidden \
+// RUN: %s | FileCheck --check-prefix=CHECK-CMD-HIDDEN %s
+
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-tapi-elf-v1 %s | FileCheck %s
+
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-yaml-elf-v1 %s | FileCheck %s
+
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -c %s | llvm-readelf -s - 2>&1 | \
+// RUN: FileCheck -check-prefix=CHECK-SYMBOLS %s
+
+// Always Be Hidden:
+// CHECK-CMD-HIDDEN-NOT: _Z6hiddenv
+// CHECK-NOT: _Z6hiddenv
+__attribute__((visibility("hidden"))) void hidden() {}
+
+// Always Be Visible:
+// CHECK-CMD-HIDDEN: _Z9nothiddenv
+// CHECK-DAG: _Z9nothiddenv
+__attribute__((visibility("default"))) void nothidden() {}
+
+// Do Whatever -fvisibility says:
+// CHECK-CMD-HIDDEN-NOT: _Z10cmdVisiblev
+// CHECK-DAG: _Z10cmdVisiblev
+void cmdVisible() {}
+
+// CHECK-SYMBOLS-DAG: DEFAULT{{.*}} _Z10cmdVisiblev
+// CHECK-SYMBOLS-DAG: HIDDEN {{.*}} _Z6hiddenv
+// CHECK-SYMBOLS-DAG: DEFAULT{{.*}} _Z9nothiddenv
Index: clang/test/InterfaceStubs/virtual.cpp
===
--- /dev/null
+++ clang/test/InterfaceStubs/virtual.cpp
@@ -0,0 +1,38 @@
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-tapi-elf-v1 %s | \
+// RUN: FileCheck -check-prefix=CHECK-TAPI %s
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -c %s | \
+// RUN: llvm-readelf -s - 2>&1 | FileCheck -check-prefix=CHECK-SYMBOLS %s
+
+#define HIDDEN  __attribute__((__visibility__(("hidden"
+#define DEFAULT __attribute__((__visibility__(("default"
+
+// CHECK-TAPI-NOT: _ZNK1Q5func1Ev
+// CHECK-TAPI-NOT: _ZNK1Q5f

[PATCH] D60974: Clang IFSO driver action.

2019-06-16 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi added inline comments.



Comment at: clang/lib/Frontend/InterfaceStubFunctionsConsumer.cpp:21
+  StringRef InFile;
+  StringRef Format;
+  std::set ParsedTemplates;

compnerd wrote:
> An enumeration may be nicer.
For now the format goes into the first line of the yaml (in both formats) and 
ends up as "--- ! \n".
I'd like to keep it this way for now. 



Comment at: clang/lib/Frontend/InterfaceStubFunctionsConsumer.cpp:39
+  bool WriteNamedDecl(const NamedDecl *ND, MangledSymbols &Symbols, int RDO) {
+if (!(RDO & FromTU))
+  return true;

compnerd wrote:
> I tend to prefer `if (RDO & ~FromTU)`
0 != (RDO & 0x1) vs (RDO & 0xE)

I'm not sure if these are logically equivalent



Comment at: clang/lib/Frontend/InterfaceStubFunctionsConsumer.cpp:72
+ VD->getParentFunctionOrMethod() == nullptr))
+  return true;
+  if (const FunctionDecl *FD = dyn_cast(ND)) {

compnerd wrote:
> If it is a `VarDecl`, it cannot be a `FunctionDecl`.  I think that this can 
> be simplified a bit as:
> 
> ```
> if (const auto *VD = dyn_cast(VD))
>   return VD->getStorageClass() == StorageClass::SC_Extern ||
>   VD->getStorageClass() == StorageClass::SC_Static ||
>   VD->getParentFunctionOrMethod() == nullptr;
> ```
I don't understand. Here I remember wanting to bail if 
VD->getParentFunctionOrMethod() == nullptr and the vardecl was marked static. 



Comment at: clang/lib/Frontend/InterfaceStubFunctionsConsumer.cpp:77
+  return true;
+if (const CXXMethodDecl *MD = dyn_cast(FD)) {
+  if (const auto *RC = dyn_cast(MD->getParent())) {

compnerd wrote:
> I think that flipping this around would be nicer.
> 
> ```
> if (const auto *MD = dyn_cast(FD)) {
>   ...
> }
> 
> return FD->isInlined() && !Instance.getLangOpts().GNUInline;
> ```
I think this still causes the isInlined + !GNUInlined code to trigger on 
CXXMethodDecls. 


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60974/new/

https://reviews.llvm.org/D60974



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


[PATCH] D60974: Clang IFSO driver action.

2019-06-17 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi updated this revision to Diff 205191.
plotfi marked 2 inline comments as done.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60974/new/

https://reviews.llvm.org/D60974

Files:
  clang/include/clang/Basic/DiagnosticFrontendKinds.td
  clang/include/clang/Driver/Options.td
  clang/include/clang/Driver/Types.def
  clang/include/clang/Frontend/FrontendActions.h
  clang/include/clang/Frontend/FrontendOptions.h
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CMakeLists.txt
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Frontend/InterfaceStubFunctionsConsumer.cpp
  clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
  clang/test/InterfaceStubs/bad-format.cpp
  clang/test/InterfaceStubs/class-template-specialization.cpp
  clang/test/InterfaceStubs/externstatic.c
  clang/test/InterfaceStubs/function-template-specialization.cpp
  clang/test/InterfaceStubs/hidden-class-inheritance.cpp
  clang/test/InterfaceStubs/inline.c
  clang/test/InterfaceStubs/inline.h
  clang/test/InterfaceStubs/object.cpp
  clang/test/InterfaceStubs/template-namespace-function.cpp
  clang/test/InterfaceStubs/virtual.cpp
  clang/test/InterfaceStubs/visibility.cpp
  clang/test/InterfaceStubs/weak.cpp

Index: clang/test/InterfaceStubs/weak.cpp
===
--- /dev/null
+++ clang/test/InterfaceStubs/weak.cpp
@@ -0,0 +1,27 @@
+// RUN: %clang -target x86_64-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-tapi-elf-v1 %s | \
+// RUN: FileCheck %s
+
+// RUN: %clang -target x86_64-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-yaml-elf-v1 %s | \
+// RUN: FileCheck --check-prefix=CHECK-YAML %s
+
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -c %s | llvm-nm - 2>&1 | \
+// RUN: FileCheck -check-prefix=CHECK-SYMBOLS %s
+
+// CHECK: Symbols:
+// CHECK-DAG:  _Z8weakFuncv: { Type: Func, Weak: true }
+// CHECK-DAG:  _Z10strongFuncv: { Type: Func }
+
+// CHECK-YAML: Symbols:
+// CHECK-YAML-DAG:   - Name:_Z8weakFuncv
+// CHECK-YAML-DAG: Type:STT_FUNC
+// CHECK-YAML-DAG: Binding: STB_WEAK
+// CHECK-YAML-DAG:   - Name:_Z10strongFuncv
+// CHECK-YAML-DAG: Type:STT_FUNC
+// CHECK-YAML-DAG: Binding: STB_GLOBAL
+
+// CHECK-SYMBOLS-DAG: _Z10strongFuncv
+// CHECK-SYMBOLS-DAG: _Z8weakFuncv
+__attribute__((weak)) void weakFunc() {}
+int strongFunc() { return 42; }
Index: clang/test/InterfaceStubs/visibility.cpp
===
--- /dev/null
+++ clang/test/InterfaceStubs/visibility.cpp
@@ -0,0 +1,45 @@
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-tapi-elf-v1 -fvisibility=hidden \
+// RUN: %s | FileCheck --check-prefix=CHECK-CMD-HIDDEN %s
+
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-yaml-elf-v1 -fvisibility=hidden \
+// RUN: %s | FileCheck --check-prefix=CHECK-CMD-HIDDEN %s
+
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-tapi-elf-v1 %s | \
+// RUN: FileCheck --check-prefix=CHECK-CMD %s
+
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-yaml-elf-v1 %s | \
+// RUN: FileCheck --check-prefix=CHECK-CMD %s
+
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-tapi-elf-v1 %s | \
+// RUN: FileCheck --check-prefix=CHECK-CMD2 %s
+
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-yaml-elf-v1 %s | \
+// RUN: FileCheck --check-prefix=CHECK-CMD2 %s
+
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -c %s | llvm-readelf -s - 2>&1 | \
+// RUN: FileCheck -check-prefix=CHECK-SYMBOLS %s
+
+// Always Be Hidden:
+// CHECK-CMD-HIDDEN-NOT: _Z6hiddenv
+// CHECK-CMD2-NOT: _Z6hiddenv
+__attribute__((visibility("hidden"))) void hidden() {}
+
+// Always Be Visible:
+// CHECK-CMD-HIDDEN: _Z9nothiddenv
+// CHECK-CMD-DAG: _Z9nothiddenv
+__attribute__((visibility("default"))) void nothidden() {}
+
+// Do Whatever -fvisibility says:
+// CHECK-CMD-HIDDEN-NOT: _Z10cmdVisiblev
+// CHECK-CMD-DAG: _Z10cmdVisiblev
+void cmdVisible() {}
+
+// CHECK-SYMBOLS-DAG: DEFAULT{{.*}} _Z10cmdVisiblev
+// CHECK-SYMBOLS-DAG: HIDDEN {{.*}} _Z6hiddenv
+// CHECK-SYMBOLS-DAG: DEFAULT{{.*}} _Z9nothiddenv
Index: clang/test/InterfaceStubs/virtual.cpp
===
--- /dev/null
+++ clang/test/InterfaceStubs/virtual.cpp
@@ -0,0 +1,41 @@
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-vers

[PATCH] D60974: Clang IFSO driver action.

2019-06-17 Thread Puyan Lotfi via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL363626: [clang-ifs] Clang Interface Stubs, first version. 
(authored by zer0, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D60974?vs=205191&id=205203#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60974/new/

https://reviews.llvm.org/D60974

Files:
  cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td
  cfe/trunk/include/clang/Driver/Options.td
  cfe/trunk/include/clang/Driver/Types.def
  cfe/trunk/include/clang/Frontend/FrontendActions.h
  cfe/trunk/include/clang/Frontend/FrontendOptions.h
  cfe/trunk/lib/Driver/Driver.cpp
  cfe/trunk/lib/Driver/ToolChains/Clang.cpp
  cfe/trunk/lib/Frontend/CMakeLists.txt
  cfe/trunk/lib/Frontend/CompilerInvocation.cpp
  cfe/trunk/lib/Frontend/InterfaceStubFunctionsConsumer.cpp
  cfe/trunk/lib/FrontendTool/ExecuteCompilerInvocation.cpp
  cfe/trunk/test/InterfaceStubs/bad-format.cpp
  cfe/trunk/test/InterfaceStubs/class-template-specialization.cpp
  cfe/trunk/test/InterfaceStubs/externstatic.c
  cfe/trunk/test/InterfaceStubs/function-template-specialization.cpp
  cfe/trunk/test/InterfaceStubs/hidden-class-inheritance.cpp
  cfe/trunk/test/InterfaceStubs/inline.c
  cfe/trunk/test/InterfaceStubs/inline.h
  cfe/trunk/test/InterfaceStubs/object.cpp
  cfe/trunk/test/InterfaceStubs/template-namespace-function.cpp
  cfe/trunk/test/InterfaceStubs/virtual.cpp
  cfe/trunk/test/InterfaceStubs/visibility.cpp
  cfe/trunk/test/InterfaceStubs/weak.cpp

Index: cfe/trunk/include/clang/Driver/Options.td
===
--- cfe/trunk/include/clang/Driver/Options.td
+++ cfe/trunk/include/clang/Driver/Options.td
@@ -623,6 +623,9 @@
   HelpText<"Emit Clang AST files for source inputs">;
 def emit_llvm : Flag<["-"], "emit-llvm">, Flags<[CC1Option]>, Group,
   HelpText<"Use the LLVM representation for assembler and object files">;
+def emit_iterface_stubs : Flag<["-"], "emit-interface-stubs">, Flags<[CC1Option]>, Group,
+  HelpText<"Generate Inteface Stub Files.">;
+def iterface_stub_version_EQ : JoinedOrSeparate<["-"], "interface-stub-version=">, Flags<[CC1Option]>;
 def exported__symbols__list : Separate<["-"], "exported_symbols_list">;
 def e : JoinedOrSeparate<["-"], "e">, Group;
 def fPIC : Flag<["-"], "fPIC">, Group;
Index: cfe/trunk/include/clang/Driver/Types.def
===
--- cfe/trunk/include/clang/Driver/Types.def
+++ cfe/trunk/include/clang/Driver/Types.def
@@ -88,6 +88,7 @@
 
 // Misc.
 TYPE("ast",  AST,  INVALID, "ast",   "u")
+TYPE("ifs",  IFS,  INVALID, "ifs",   "u")
 TYPE("pcm",  ModuleFile,   INVALID, "pcm",   "u")
 TYPE("plist",Plist,INVALID, "plist", "")
 TYPE("rewritten-objc",   RewrittenObjC,INVALID, "cpp",   "")
Index: cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td
===
--- cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td
+++ cfe/trunk/include/clang/Basic/DiagnosticFrontendKinds.td
@@ -220,6 +220,8 @@
 def err_module_header_file_invalid :
   Error<"unexpected module header file input '%0'">, DefaultFatal;
 
+def err_interface_stubs : Error<"clang-ifs (-emit-iterface-stubs): %0">;
+
 def err_test_module_file_extension_version : Error<
   "test module file extension '%0' has different version (%1.%2) than expected "
   "(%3.%4)">;
Index: cfe/trunk/include/clang/Frontend/FrontendOptions.h
===
--- cfe/trunk/include/clang/Frontend/FrontendOptions.h
+++ cfe/trunk/include/clang/Frontend/FrontendOptions.h
@@ -88,6 +88,10 @@
   /// Generate pre-compiled header.
   GeneratePCH,
 
+  /// Generate Interface Stub Files.
+  GenerateInterfaceYAMLExpV1,
+  GenerateInterfaceTBEExpV1,
+
   /// Only execute frontend initialization.
   InitOnly,
 
Index: cfe/trunk/include/clang/Frontend/FrontendActions.h
===
--- cfe/trunk/include/clang/Frontend/FrontendActions.h
+++ cfe/trunk/include/clang/Frontend/FrontendActions.h
@@ -119,6 +119,26 @@
   bool hasASTFileSupport() const override { return false; }
 };
 
+class GenerateInterfaceStubAction : public ASTFrontendAction {
+protected:
+  TranslationUnitKind getTranslationUnitKind() override { return TU_Module; }
+
+  bool hasASTFileSupport() const override { return false; }
+};
+
+// Support different interface stub formats this way:
+class GenerateInterfaceYAMLExpV1Action : public GenerateInterfaceStubAction {
+protected:
+  std::unique_ptr CreateASTConsumer(CompilerInstance &CI,
+ StringRef InFile) override;
+};
+
+class GenerateInterfaceTBEExpV1Action : public GenerateInterfaceStubAction

[PATCH] D60974: Clang IFSO driver action.

2019-06-17 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi marked an inline comment as done.
plotfi added inline comments.



Comment at: cfe/trunk/lib/Frontend/CMakeLists.txt:58
   clangDriver
+  clangIndex
   clangEdit

MaskRay wrote:
> This is a layering issue. clangIndex depends on clangFrontend so 
> clangFrontend should not depend on clangIndex.
> 
> The circular dependency is allowed for static libraries but it breaks 
> `-DBUILD_SHARED_LIBS=on`:
> 
> ```
> CMake Error: The inter-target dependency graph contains the following 
> strongly connected component (cycle):
>   "clangFrontend" of type SHARED_LIBRARY
> depends on "clangIndex" (weak)
>   "clangIndex" of type SHARED_LIBRARY
> depends on "clangFrontend" (weak)
> At least one of these targets is not a STATIC_LIBRARY.  Cyclic dependencies 
> are allowed only among static libraries.
> ```
Is there a bot affected by this? I will take a look.


Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60974/new/

https://reviews.llvm.org/D60974



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


[PATCH] D60974: Clang IFSO driver action.

2019-06-17 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi marked 3 inline comments as done.
plotfi added inline comments.



Comment at: cfe/trunk/lib/Frontend/InterfaceStubFunctionsConsumer.cpp:22
+  StringRef Format;
+  std::set ParsedTemplates;
+

MaskRay wrote:
> Does `StringSet<>` work?
It probably could work. I will likely follow up with an NFC patch for this. 



Comment at: cfe/trunk/lib/Frontend/InterfaceStubFunctionsConsumer.cpp:36
+  };
+  using MangledSymbols = std::map;
+

MaskRay wrote:
> Are you relying on the ordered property of `std::map`?
No I am not. 



Comment at: cfe/trunk/lib/Frontend/InterfaceStubFunctionsConsumer.cpp:101
+  return true;
+if (Symbols.find(ND) != Symbols.end())
+  return true;

MaskRay wrote:
> `.count`
Nice. 


Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60974/new/

https://reviews.llvm.org/D60974



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


[PATCH] D60974: Clang IFSO driver action.

2019-06-17 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi marked 3 inline comments as done.
plotfi added inline comments.



Comment at: cfe/trunk/lib/Frontend/CMakeLists.txt:58
   clangDriver
+  clangIndex
   clangEdit

asb wrote:
> plotfi wrote:
> > MaskRay wrote:
> > > This is a layering issue. clangIndex depends on clangFrontend so 
> > > clangFrontend should not depend on clangIndex.
> > > 
> > > The circular dependency is allowed for static libraries but it breaks 
> > > `-DBUILD_SHARED_LIBS=on`:
> > > 
> > > ```
> > > CMake Error: The inter-target dependency graph contains the following 
> > > strongly connected component (cycle):
> > >   "clangFrontend" of type SHARED_LIBRARY
> > > depends on "clangIndex" (weak)
> > >   "clangIndex" of type SHARED_LIBRARY
> > > depends on "clangFrontend" (weak)
> > > At least one of these targets is not a STATIC_LIBRARY.  Cyclic 
> > > dependencies are allowed only among static libraries.
> > > ```
> > Is there a bot affected by this? I will take a look.
> Sadly there is no -DBUILD_SHARED_LIBS=True bot. This layering issue will 
> break builds for all downstream users using that option though.
Just checking (to see if there is a bot to verify with). I have a fix (removing 
clangIndex) that I think will build with or without -DBUILD_SHARED_LIBS=ON. 



Comment at: cfe/trunk/lib/Frontend/CMakeLists.txt:58
   clangDriver
+  clangIndex
   clangEdit

plotfi wrote:
> asb wrote:
> > plotfi wrote:
> > > MaskRay wrote:
> > > > This is a layering issue. clangIndex depends on clangFrontend so 
> > > > clangFrontend should not depend on clangIndex.
> > > > 
> > > > The circular dependency is allowed for static libraries but it breaks 
> > > > `-DBUILD_SHARED_LIBS=on`:
> > > > 
> > > > ```
> > > > CMake Error: The inter-target dependency graph contains the following 
> > > > strongly connected component (cycle):
> > > >   "clangFrontend" of type SHARED_LIBRARY
> > > > depends on "clangIndex" (weak)
> > > >   "clangIndex" of type SHARED_LIBRARY
> > > > depends on "clangFrontend" (weak)
> > > > At least one of these targets is not a STATIC_LIBRARY.  Cyclic 
> > > > dependencies are allowed only among static libraries.
> > > > ```
> > > Is there a bot affected by this? I will take a look.
> > Sadly there is no -DBUILD_SHARED_LIBS=True bot. This layering issue will 
> > break builds for all downstream users using that option though.
> Just checking (to see if there is a bot to verify with). I have a fix 
> (removing clangIndex) that I think will build with or without 
> -DBUILD_SHARED_LIBS=ON. 
I've updated cfe/trunk/lib/Frontend/CMakeLists.txt in r363646


Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60974/new/

https://reviews.llvm.org/D60974



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


[PATCH] D60974: Clang IFSO driver action.

2019-06-17 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi added a comment.

I had to back out r363646. While it worked for me building locally with and 
without shared lib, it appears to have caused bots to break. I will take 
another look at fixing it in about 10 hours.


Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60974/new/

https://reviews.llvm.org/D60974



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


[PATCH] D60974: Clang IFSO driver action.

2019-06-17 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi added a comment.

In D60974#1547682 , @MaskRay wrote:

> @plotfi Sorry I have to revert this patch. This can also cause problems in 
> `-DBUILD_SHARED_LIBS=off` builds.  clangFrontend files cannot `#include 
> "clang/Index/CodegenNameGenerator.h"`, I think you may have to move files 
> around.


That’s fine. I will coordinate with you when I attempt to re-land.


Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60974/new/

https://reviews.llvm.org/D60974



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


[PATCH] D63535: [clang][AST] MangleUtil: A refactoring of CodegenNameGeneratorImpl (NFC).

2019-06-18 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi created this revision.
plotfi added reviewers: compnerd, ahatanak, akyrtzi, aaron.ballman.
Herald added subscribers: cfe-commits, arphaman, dexonsmith.
Herald added a project: clang.

CodegenNameGeneratorImpl is the most complete implementation of name mangling 
but it is in clang::Index. This makes it very difficult to use it elsewhere in 
clang. This is just a NFC refactoring  of CodegenNameGeneratorImpl into a class 
called MangleUtil. Other than the name and placement change there is no 
functional change.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D63535

Files:
  clang/include/clang/AST/Mangle.h
  clang/include/clang/Index/CodegenNameGenerator.h
  clang/lib/AST/Mangle.cpp
  clang/lib/Index/CodegenNameGenerator.cpp

Index: clang/lib/Index/CodegenNameGenerator.cpp
===
--- clang/lib/Index/CodegenNameGenerator.cpp
+++ clang/lib/Index/CodegenNameGenerator.cpp
@@ -14,7 +14,6 @@
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/DeclCXX.h"
 #include "clang/AST/DeclObjC.h"
-#include "clang/AST/Mangle.h"
 #include "clang/AST/VTableBuilder.h"
 #include "clang/Basic/TargetInfo.h"
 #include "llvm/IR/DataLayout.h"
@@ -24,191 +23,9 @@
 using namespace clang;
 using namespace clang::index;
 
-struct CodegenNameGenerator::Implementation {
-  std::unique_ptr MC;
-  llvm::DataLayout DL;
-
-  Implementation(ASTContext &Ctx)
-: MC(Ctx.createMangleContext()),
-  DL(Ctx.getTargetInfo().getDataLayout()) {}
-
-  bool writeName(const Decl *D, raw_ostream &OS) {
-// First apply frontend mangling.
-SmallString<128> FrontendBuf;
-llvm::raw_svector_ostream FrontendBufOS(FrontendBuf);
-if (auto *FD = dyn_cast(D)) {
-  if (FD->isDependentContext())
-return true;
-  if (writeFuncOrVarName(FD, FrontendBufOS))
-return true;
-} else if (auto *VD = dyn_cast(D)) {
-  if (writeFuncOrVarName(VD, FrontendBufOS))
-return true;
-} else if (auto *MD = dyn_cast(D)) {
-  MC->mangleObjCMethodNameWithoutSize(MD, OS);
-  return false;
-} else if (auto *ID = dyn_cast(D)) {
-  writeObjCClassName(ID, FrontendBufOS);
-} else {
-  return true;
-}
-
-// Now apply backend mangling.
-llvm::Mangler::getNameWithPrefix(OS, FrontendBufOS.str(), DL);
-return false;
-  }
-
-  std::string getName(const Decl *D) {
-std::string Name;
-{
-  llvm::raw_string_ostream OS(Name);
-  writeName(D, OS);
-}
-return Name;
-  }
-
-  enum ObjCKind {
-ObjCClass,
-ObjCMetaclass,
-  };
-
-  std::vector getAllManglings(const ObjCContainerDecl *OCD) {
-StringRef ClassName;
-if (const auto *OID = dyn_cast(OCD))
-  ClassName = OID->getObjCRuntimeNameAsString();
-else if (const auto *OID = dyn_cast(OCD))
-  ClassName = OID->getObjCRuntimeNameAsString();
-
-if (ClassName.empty())
-  return {};
-
-auto Mangle = [&](ObjCKind Kind, StringRef ClassName) -> std::string {
-  SmallString<40> Mangled;
-  auto Prefix = getClassSymbolPrefix(Kind, OCD->getASTContext());
-  llvm::Mangler::getNameWithPrefix(Mangled, Prefix + ClassName, DL);
-  return Mangled.str();
-};
-
-return {
-  Mangle(ObjCClass, ClassName),
-  Mangle(ObjCMetaclass, ClassName),
-};
-  }
-
-  std::vector getAllManglings(const Decl *D) {
-if (const auto *OCD = dyn_cast(D))
-  return getAllManglings(OCD);
-
-if (!(isa(D) || isa(D)))
-  return {};
-
-const NamedDecl *ND = cast(D);
-
-ASTContext &Ctx = ND->getASTContext();
-std::unique_ptr M(Ctx.createMangleContext());
-
-std::vector Manglings;
-
-auto hasDefaultCXXMethodCC = [](ASTContext &C, const CXXMethodDecl *MD) {
-  auto DefaultCC = C.getDefaultCallingConvention(/*IsVariadic=*/false,
- /*IsCSSMethod=*/true);
-  auto CC = MD->getType()->getAs()->getCallConv();
-  return CC == DefaultCC;
-};
-
-if (const auto *CD = dyn_cast_or_null(ND)) {
-  Manglings.emplace_back(getMangledStructor(CD, Ctor_Base));
-
-  if (Ctx.getTargetInfo().getCXXABI().isItaniumFamily())
-if (!CD->getParent()->isAbstract())
-  Manglings.emplace_back(getMangledStructor(CD, Ctor_Complete));
-
-  if (Ctx.getTargetInfo().getCXXABI().isMicrosoft())
-if (CD->hasAttr() && CD->isDefaultConstructor())
-  if (!(hasDefaultCXXMethodCC(Ctx, CD) && CD->getNumParams() == 0))
-Manglings.emplace_back(getMangledStructor(CD, Ctor_DefaultClosure));
-} else if (const auto *DD = dyn_cast_or_null(ND)) {
-  Manglings.emplace_back(getMangledStructor(DD, Dtor_Base));
-  if (Ctx.getTargetInfo().getCXXABI().isItaniumFamily()) {
-Manglings.emplace_back(getMangledStructor(DD, Dtor_Complete));
-if (DD->isVirtual())
-  Manglings.emplace_back(getMangledStructor(DD, Dtor_Deleting));
-  }
-} else if (const auto *MD = dyn_cast_or_null(N

[PATCH] D63535: [clang][AST] ASTNameGenerator: A refactoring of CodegenNameGeneratorImpl (NFC).

2019-06-19 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi updated this revision to Diff 205625.
plotfi added a comment.

Addressing @compnerd's feedback.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D63535/new/

https://reviews.llvm.org/D63535

Files:
  clang/include/clang/AST/Mangle.h
  clang/include/clang/Index/CodegenNameGenerator.h
  clang/lib/AST/Mangle.cpp
  clang/lib/Index/CodegenNameGenerator.cpp

Index: clang/lib/Index/CodegenNameGenerator.cpp
===
--- clang/lib/Index/CodegenNameGenerator.cpp
+++ clang/lib/Index/CodegenNameGenerator.cpp
@@ -12,203 +12,12 @@
 
 #include "clang/Index/CodegenNameGenerator.h"
 #include "clang/AST/ASTContext.h"
-#include "clang/AST/DeclCXX.h"
-#include "clang/AST/DeclObjC.h"
-#include "clang/AST/Mangle.h"
-#include "clang/AST/VTableBuilder.h"
-#include "clang/Basic/TargetInfo.h"
-#include "llvm/IR/DataLayout.h"
-#include "llvm/IR/Mangler.h"
-#include "llvm/Support/raw_ostream.h"
 
 using namespace clang;
 using namespace clang::index;
 
-struct CodegenNameGenerator::Implementation {
-  std::unique_ptr MC;
-  llvm::DataLayout DL;
-
-  Implementation(ASTContext &Ctx)
-: MC(Ctx.createMangleContext()),
-  DL(Ctx.getTargetInfo().getDataLayout()) {}
-
-  bool writeName(const Decl *D, raw_ostream &OS) {
-// First apply frontend mangling.
-SmallString<128> FrontendBuf;
-llvm::raw_svector_ostream FrontendBufOS(FrontendBuf);
-if (auto *FD = dyn_cast(D)) {
-  if (FD->isDependentContext())
-return true;
-  if (writeFuncOrVarName(FD, FrontendBufOS))
-return true;
-} else if (auto *VD = dyn_cast(D)) {
-  if (writeFuncOrVarName(VD, FrontendBufOS))
-return true;
-} else if (auto *MD = dyn_cast(D)) {
-  MC->mangleObjCMethodNameWithoutSize(MD, OS);
-  return false;
-} else if (auto *ID = dyn_cast(D)) {
-  writeObjCClassName(ID, FrontendBufOS);
-} else {
-  return true;
-}
-
-// Now apply backend mangling.
-llvm::Mangler::getNameWithPrefix(OS, FrontendBufOS.str(), DL);
-return false;
-  }
-
-  std::string getName(const Decl *D) {
-std::string Name;
-{
-  llvm::raw_string_ostream OS(Name);
-  writeName(D, OS);
-}
-return Name;
-  }
-
-  enum ObjCKind {
-ObjCClass,
-ObjCMetaclass,
-  };
-
-  std::vector getAllManglings(const ObjCContainerDecl *OCD) {
-StringRef ClassName;
-if (const auto *OID = dyn_cast(OCD))
-  ClassName = OID->getObjCRuntimeNameAsString();
-else if (const auto *OID = dyn_cast(OCD))
-  ClassName = OID->getObjCRuntimeNameAsString();
-
-if (ClassName.empty())
-  return {};
-
-auto Mangle = [&](ObjCKind Kind, StringRef ClassName) -> std::string {
-  SmallString<40> Mangled;
-  auto Prefix = getClassSymbolPrefix(Kind, OCD->getASTContext());
-  llvm::Mangler::getNameWithPrefix(Mangled, Prefix + ClassName, DL);
-  return Mangled.str();
-};
-
-return {
-  Mangle(ObjCClass, ClassName),
-  Mangle(ObjCMetaclass, ClassName),
-};
-  }
-
-  std::vector getAllManglings(const Decl *D) {
-if (const auto *OCD = dyn_cast(D))
-  return getAllManglings(OCD);
-
-if (!(isa(D) || isa(D)))
-  return {};
-
-const NamedDecl *ND = cast(D);
-
-ASTContext &Ctx = ND->getASTContext();
-std::unique_ptr M(Ctx.createMangleContext());
-
-std::vector Manglings;
-
-auto hasDefaultCXXMethodCC = [](ASTContext &C, const CXXMethodDecl *MD) {
-  auto DefaultCC = C.getDefaultCallingConvention(/*IsVariadic=*/false,
- /*IsCSSMethod=*/true);
-  auto CC = MD->getType()->getAs()->getCallConv();
-  return CC == DefaultCC;
-};
-
-if (const auto *CD = dyn_cast_or_null(ND)) {
-  Manglings.emplace_back(getMangledStructor(CD, Ctor_Base));
-
-  if (Ctx.getTargetInfo().getCXXABI().isItaniumFamily())
-if (!CD->getParent()->isAbstract())
-  Manglings.emplace_back(getMangledStructor(CD, Ctor_Complete));
-
-  if (Ctx.getTargetInfo().getCXXABI().isMicrosoft())
-if (CD->hasAttr() && CD->isDefaultConstructor())
-  if (!(hasDefaultCXXMethodCC(Ctx, CD) && CD->getNumParams() == 0))
-Manglings.emplace_back(getMangledStructor(CD, Ctor_DefaultClosure));
-} else if (const auto *DD = dyn_cast_or_null(ND)) {
-  Manglings.emplace_back(getMangledStructor(DD, Dtor_Base));
-  if (Ctx.getTargetInfo().getCXXABI().isItaniumFamily()) {
-Manglings.emplace_back(getMangledStructor(DD, Dtor_Complete));
-if (DD->isVirtual())
-  Manglings.emplace_back(getMangledStructor(DD, Dtor_Deleting));
-  }
-} else if (const auto *MD = dyn_cast_or_null(ND)) {
-  Manglings.emplace_back(getName(ND));
-  if (MD->isVirtual())
-if (const auto *TIV = Ctx.getVTableContext()->getThunkInfo(MD))
-  for (const auto &T : *TIV)
-Manglings.emplace_back(getMangledThunk(MD, T));
-

[PATCH] D63535: [clang][AST] ASTNameGenerator: A refactoring of CodegenNameGeneratorImpl (NFC).

2019-06-19 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi marked an inline comment as done.
plotfi added inline comments.



Comment at: clang/include/clang/AST/Mangle.h:249-250
+struct ASTNameGenerator {
+  std::unique_ptr MC;
+  llvm::DataLayout DL;
+

aaron.ballman wrote:
> Do these still need to be public members? Back when this class was an 
> implementation detail, that didn't matter as much, but I'd prefer a cleaner 
> public interface before we expose this to other consumers.
Good catch! This was a struct when it was CodegenNameGeneratorImpl but these 
were hidden by the mere fact that they were inside the .cpp file and not in a 
header. Thanks!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D63535/new/

https://reviews.llvm.org/D63535



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


[PATCH] D63535: [clang][AST] ASTNameGenerator: A refactoring of CodegenNameGeneratorImpl (NFC).

2019-06-19 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi updated this revision to Diff 205643.
plotfi added a comment.

Update to address @aaron.ballman's catch that ASTNameGenerator was not private 
enough.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D63535/new/

https://reviews.llvm.org/D63535

Files:
  clang/include/clang/AST/Mangle.h
  clang/include/clang/Index/CodegenNameGenerator.h
  clang/lib/AST/Mangle.cpp
  clang/lib/Index/CodegenNameGenerator.cpp

Index: clang/lib/Index/CodegenNameGenerator.cpp
===
--- clang/lib/Index/CodegenNameGenerator.cpp
+++ clang/lib/Index/CodegenNameGenerator.cpp
@@ -12,203 +12,12 @@
 
 #include "clang/Index/CodegenNameGenerator.h"
 #include "clang/AST/ASTContext.h"
-#include "clang/AST/DeclCXX.h"
-#include "clang/AST/DeclObjC.h"
-#include "clang/AST/Mangle.h"
-#include "clang/AST/VTableBuilder.h"
-#include "clang/Basic/TargetInfo.h"
-#include "llvm/IR/DataLayout.h"
-#include "llvm/IR/Mangler.h"
-#include "llvm/Support/raw_ostream.h"
 
 using namespace clang;
 using namespace clang::index;
 
-struct CodegenNameGenerator::Implementation {
-  std::unique_ptr MC;
-  llvm::DataLayout DL;
-
-  Implementation(ASTContext &Ctx)
-: MC(Ctx.createMangleContext()),
-  DL(Ctx.getTargetInfo().getDataLayout()) {}
-
-  bool writeName(const Decl *D, raw_ostream &OS) {
-// First apply frontend mangling.
-SmallString<128> FrontendBuf;
-llvm::raw_svector_ostream FrontendBufOS(FrontendBuf);
-if (auto *FD = dyn_cast(D)) {
-  if (FD->isDependentContext())
-return true;
-  if (writeFuncOrVarName(FD, FrontendBufOS))
-return true;
-} else if (auto *VD = dyn_cast(D)) {
-  if (writeFuncOrVarName(VD, FrontendBufOS))
-return true;
-} else if (auto *MD = dyn_cast(D)) {
-  MC->mangleObjCMethodNameWithoutSize(MD, OS);
-  return false;
-} else if (auto *ID = dyn_cast(D)) {
-  writeObjCClassName(ID, FrontendBufOS);
-} else {
-  return true;
-}
-
-// Now apply backend mangling.
-llvm::Mangler::getNameWithPrefix(OS, FrontendBufOS.str(), DL);
-return false;
-  }
-
-  std::string getName(const Decl *D) {
-std::string Name;
-{
-  llvm::raw_string_ostream OS(Name);
-  writeName(D, OS);
-}
-return Name;
-  }
-
-  enum ObjCKind {
-ObjCClass,
-ObjCMetaclass,
-  };
-
-  std::vector getAllManglings(const ObjCContainerDecl *OCD) {
-StringRef ClassName;
-if (const auto *OID = dyn_cast(OCD))
-  ClassName = OID->getObjCRuntimeNameAsString();
-else if (const auto *OID = dyn_cast(OCD))
-  ClassName = OID->getObjCRuntimeNameAsString();
-
-if (ClassName.empty())
-  return {};
-
-auto Mangle = [&](ObjCKind Kind, StringRef ClassName) -> std::string {
-  SmallString<40> Mangled;
-  auto Prefix = getClassSymbolPrefix(Kind, OCD->getASTContext());
-  llvm::Mangler::getNameWithPrefix(Mangled, Prefix + ClassName, DL);
-  return Mangled.str();
-};
-
-return {
-  Mangle(ObjCClass, ClassName),
-  Mangle(ObjCMetaclass, ClassName),
-};
-  }
-
-  std::vector getAllManglings(const Decl *D) {
-if (const auto *OCD = dyn_cast(D))
-  return getAllManglings(OCD);
-
-if (!(isa(D) || isa(D)))
-  return {};
-
-const NamedDecl *ND = cast(D);
-
-ASTContext &Ctx = ND->getASTContext();
-std::unique_ptr M(Ctx.createMangleContext());
-
-std::vector Manglings;
-
-auto hasDefaultCXXMethodCC = [](ASTContext &C, const CXXMethodDecl *MD) {
-  auto DefaultCC = C.getDefaultCallingConvention(/*IsVariadic=*/false,
- /*IsCSSMethod=*/true);
-  auto CC = MD->getType()->getAs()->getCallConv();
-  return CC == DefaultCC;
-};
-
-if (const auto *CD = dyn_cast_or_null(ND)) {
-  Manglings.emplace_back(getMangledStructor(CD, Ctor_Base));
-
-  if (Ctx.getTargetInfo().getCXXABI().isItaniumFamily())
-if (!CD->getParent()->isAbstract())
-  Manglings.emplace_back(getMangledStructor(CD, Ctor_Complete));
-
-  if (Ctx.getTargetInfo().getCXXABI().isMicrosoft())
-if (CD->hasAttr() && CD->isDefaultConstructor())
-  if (!(hasDefaultCXXMethodCC(Ctx, CD) && CD->getNumParams() == 0))
-Manglings.emplace_back(getMangledStructor(CD, Ctor_DefaultClosure));
-} else if (const auto *DD = dyn_cast_or_null(ND)) {
-  Manglings.emplace_back(getMangledStructor(DD, Dtor_Base));
-  if (Ctx.getTargetInfo().getCXXABI().isItaniumFamily()) {
-Manglings.emplace_back(getMangledStructor(DD, Dtor_Complete));
-if (DD->isVirtual())
-  Manglings.emplace_back(getMangledStructor(DD, Dtor_Deleting));
-  }
-} else if (const auto *MD = dyn_cast_or_null(ND)) {
-  Manglings.emplace_back(getName(ND));
-  if (MD->isVirtual())
-if (const auto *TIV = Ctx.getVTableContext()->getThunkInfo(MD))
-  for (const auto &T : *TIV)
-  

[PATCH] D63535: [clang][AST] ASTNameGenerator: A refactoring of CodegenNameGeneratorImpl (NFC).

2019-06-19 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi marked 3 inline comments as done.
plotfi added inline comments.



Comment at: clang/lib/AST/Mangle.cpp:25
 #include "llvm/ADT/StringExtras.h"
+#include "llvm/IR/Mangler.h"
 #include "llvm/Support/ErrorHandling.h"

aaron.ballman wrote:
> Do we have to link in any new libraries in CMake for this new dependency?
I don't believe so. It builds and make check-clangs. I will try a shared lib 
build too. It looks like AST things are already included, and LLVM things are 
already included so I doubt any new library dep change is needed at all. 


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D63535/new/

https://reviews.llvm.org/D63535



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


[PATCH] D63535: [clang][AST] ASTNameGenerator: A refactoring of CodegenNameGeneratorImpl (NFC).

2019-06-19 Thread Puyan Lotfi via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL363878: [clang][AST] ASTNameGenerator: A refactoring of 
CodegenNameGeneratorImpl (NFC). (authored by zer0, committed by ).
Herald added subscribers: llvm-commits, mgorny.
Herald added a project: LLVM.

Changed prior to commit:
  https://reviews.llvm.org/D63535?vs=205643&id=205665#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D63535/new/

https://reviews.llvm.org/D63535

Files:
  cfe/trunk/include/clang/AST/Mangle.h
  cfe/trunk/include/clang/Index/CodegenNameGenerator.h
  cfe/trunk/lib/AST/CMakeLists.txt
  cfe/trunk/lib/AST/Mangle.cpp
  cfe/trunk/lib/Index/CodegenNameGenerator.cpp

Index: cfe/trunk/include/clang/AST/Mangle.h
===
--- cfe/trunk/include/clang/AST/Mangle.h
+++ cfe/trunk/include/clang/AST/Mangle.h
@@ -17,6 +17,7 @@
 #include "clang/AST/Type.h"
 #include "clang/Basic/ABI.h"
 #include "llvm/ADT/DenseMap.h"
+#include "llvm/IR/DataLayout.h"
 #include "llvm/Support/Casting.h"
 
 namespace llvm {
@@ -243,6 +244,24 @@
   static MicrosoftMangleContext *create(ASTContext &Context,
 DiagnosticsEngine &Diags);
 };
+
+class ASTNameGenerator {
+  std::unique_ptr MC;
+  llvm::DataLayout DL;
+
+public:
+  explicit ASTNameGenerator(ASTContext &Ctx);
+  bool writeName(const Decl *D, raw_ostream &OS);
+  std::string getName(const Decl *D);
+  std::vector getAllManglings(const Decl *D);
+
+private:
+  std::vector getAllManglings(const ObjCContainerDecl *OCD);
+  bool writeFuncOrVarName(const NamedDecl *D, raw_ostream &OS);
+  void writeObjCClassName(const ObjCInterfaceDecl *D, raw_ostream &OS);
+  std::string getMangledStructor(const NamedDecl *ND, unsigned StructorType);
+  std::string getMangledThunk(const CXXMethodDecl *MD, const ThunkInfo &T);
+};
 }
 
 #endif
Index: cfe/trunk/include/clang/Index/CodegenNameGenerator.h
===
--- cfe/trunk/include/clang/Index/CodegenNameGenerator.h
+++ cfe/trunk/include/clang/Index/CodegenNameGenerator.h
@@ -13,6 +13,7 @@
 #ifndef LLVM_CLANG_INDEX_CODEGENNAMEGENERATOR_H
 #define LLVM_CLANG_INDEX_CODEGENNAMEGENERATOR_H
 
+#include "clang/AST/Mangle.h"
 #include "clang/Basic/LLVM.h"
 #include 
 #include 
@@ -42,7 +43,7 @@
 
 private:
   struct Implementation;
-  std::unique_ptr Impl;
+  std::unique_ptr Impl;
 };
 
 } // namespace index
Index: cfe/trunk/lib/AST/Mangle.cpp
===
--- cfe/trunk/lib/AST/Mangle.cpp
+++ cfe/trunk/lib/AST/Mangle.cpp
@@ -17,10 +17,12 @@
 #include "clang/AST/DeclTemplate.h"
 #include "clang/AST/ExprCXX.h"
 #include "clang/AST/Mangle.h"
+#include "clang/AST/VTableBuilder.h"
 #include "clang/Basic/ABI.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/TargetInfo.h"
 #include "llvm/ADT/StringExtras.h"
+#include "llvm/IR/Mangler.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/raw_ostream.h"
 
@@ -280,3 +282,184 @@
   mangleObjCMethodNameWithoutSize(MD, OS);
   Out << OS.str().size() << OS.str();
 }
+
+ASTNameGenerator::ASTNameGenerator(ASTContext &Ctx)
+: MC(Ctx.createMangleContext()), DL(Ctx.getTargetInfo().getDataLayout()) {}
+
+bool ASTNameGenerator::writeName(const Decl *D, raw_ostream &OS) {
+  // First apply frontend mangling.
+  SmallString<128> FrontendBuf;
+  llvm::raw_svector_ostream FrontendBufOS(FrontendBuf);
+  if (auto *FD = dyn_cast(D)) {
+if (FD->isDependentContext())
+  return true;
+if (writeFuncOrVarName(FD, FrontendBufOS))
+  return true;
+  } else if (auto *VD = dyn_cast(D)) {
+if (writeFuncOrVarName(VD, FrontendBufOS))
+  return true;
+  } else if (auto *MD = dyn_cast(D)) {
+MC->mangleObjCMethodNameWithoutSize(MD, OS);
+return false;
+  } else if (auto *ID = dyn_cast(D)) {
+writeObjCClassName(ID, FrontendBufOS);
+  } else {
+return true;
+  }
+
+  // Now apply backend mangling.
+  llvm::Mangler::getNameWithPrefix(OS, FrontendBufOS.str(), DL);
+  return false;
+}
+
+std::string ASTNameGenerator::getName(const Decl *D) {
+  std::string Name;
+  {
+llvm::raw_string_ostream OS(Name);
+writeName(D, OS);
+  }
+  return Name;
+}
+
+enum ObjCKind {
+  ObjCClass,
+  ObjCMetaclass,
+};
+
+static StringRef getClassSymbolPrefix(ObjCKind Kind,
+  const ASTContext &Context) {
+  if (Context.getLangOpts().ObjCRuntime.isGNUFamily())
+return Kind == ObjCMetaclass ? "_OBJC_METACLASS_" : "_OBJC_CLASS_";
+  return Kind == ObjCMetaclass ? "OBJC_METACLASS_$_" : "OBJC_CLASS_$_";
+}
+
+std::vector
+ASTNameGenerator::getAllManglings(const ObjCContainerDecl *OCD) {
+  StringRef ClassName;
+  if (const auto *OID = dyn_cast(OCD))
+ClassName = OID->getObjCRuntimeNameAsString();
+  else if (const auto *OID = dyn_cast(OCD))
+ClassName = OID->getObjCRuntimeNameAsString();
+
+  if (ClassN

[PATCH] D60974: Clang IFSO driver action.

2019-06-19 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi updated this revision to Diff 205686.
plotfi added a comment.

This should address the shared lib issue.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60974/new/

https://reviews.llvm.org/D60974

Files:
  clang/include/clang/Basic/DiagnosticFrontendKinds.td
  clang/include/clang/Driver/Options.td
  clang/include/clang/Driver/Types.def
  clang/include/clang/Frontend/FrontendActions.h
  clang/include/clang/Frontend/FrontendOptions.h
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/ToolChains/Clang.cpp
  clang/lib/Frontend/CMakeLists.txt
  clang/lib/Frontend/CompilerInvocation.cpp
  clang/lib/Frontend/InterfaceStubFunctionsConsumer.cpp
  clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp
  clang/test/InterfaceStubs/bad-format.cpp
  clang/test/InterfaceStubs/class-template-specialization.cpp
  clang/test/InterfaceStubs/externstatic.c
  clang/test/InterfaceStubs/function-template-specialization.cpp
  clang/test/InterfaceStubs/hidden-class-inheritance.cpp
  clang/test/InterfaceStubs/inline.c
  clang/test/InterfaceStubs/inline.h
  clang/test/InterfaceStubs/object.cpp
  clang/test/InterfaceStubs/template-namespace-function.cpp
  clang/test/InterfaceStubs/virtual.cpp
  clang/test/InterfaceStubs/visibility.cpp
  clang/test/InterfaceStubs/weak.cpp

Index: clang/test/InterfaceStubs/weak.cpp
===
--- /dev/null
+++ clang/test/InterfaceStubs/weak.cpp
@@ -0,0 +1,27 @@
+// RUN: %clang -target x86_64-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-tapi-elf-v1 %s | \
+// RUN: FileCheck %s
+
+// RUN: %clang -target x86_64-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-yaml-elf-v1 %s | \
+// RUN: FileCheck --check-prefix=CHECK-YAML %s
+
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -c %s | llvm-nm - 2>&1 | \
+// RUN: FileCheck -check-prefix=CHECK-SYMBOLS %s
+
+// CHECK: Symbols:
+// CHECK-DAG:  _Z8weakFuncv: { Type: Func, Weak: true }
+// CHECK-DAG:  _Z10strongFuncv: { Type: Func }
+
+// CHECK-YAML: Symbols:
+// CHECK-YAML-DAG:   - Name:_Z8weakFuncv
+// CHECK-YAML-DAG: Type:STT_FUNC
+// CHECK-YAML-DAG: Binding: STB_WEAK
+// CHECK-YAML-DAG:   - Name:_Z10strongFuncv
+// CHECK-YAML-DAG: Type:STT_FUNC
+// CHECK-YAML-DAG: Binding: STB_GLOBAL
+
+// CHECK-SYMBOLS-DAG: _Z10strongFuncv
+// CHECK-SYMBOLS-DAG: _Z8weakFuncv
+__attribute__((weak)) void weakFunc() {}
+int strongFunc() { return 42; }
Index: clang/test/InterfaceStubs/visibility.cpp
===
--- /dev/null
+++ clang/test/InterfaceStubs/visibility.cpp
@@ -0,0 +1,45 @@
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-tapi-elf-v1 -fvisibility=hidden \
+// RUN: %s | FileCheck --check-prefix=CHECK-CMD-HIDDEN %s
+
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-yaml-elf-v1 -fvisibility=hidden \
+// RUN: %s | FileCheck --check-prefix=CHECK-CMD-HIDDEN %s
+
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-tapi-elf-v1 %s | \
+// RUN: FileCheck --check-prefix=CHECK-CMD %s
+
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-yaml-elf-v1 %s | \
+// RUN: FileCheck --check-prefix=CHECK-CMD %s
+
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-tapi-elf-v1 %s | \
+// RUN: FileCheck --check-prefix=CHECK-CMD2 %s
+
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
+// RUN: -interface-stub-version=experimental-yaml-elf-v1 %s | \
+// RUN: FileCheck --check-prefix=CHECK-CMD2 %s
+
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -c %s | llvm-readelf -s - 2>&1 | \
+// RUN: FileCheck -check-prefix=CHECK-SYMBOLS %s
+
+// Always Be Hidden:
+// CHECK-CMD-HIDDEN-NOT: _Z6hiddenv
+// CHECK-CMD2-NOT: _Z6hiddenv
+__attribute__((visibility("hidden"))) void hidden() {}
+
+// Always Be Visible:
+// CHECK-CMD-HIDDEN: _Z9nothiddenv
+// CHECK-CMD-DAG: _Z9nothiddenv
+__attribute__((visibility("default"))) void nothidden() {}
+
+// Do Whatever -fvisibility says:
+// CHECK-CMD-HIDDEN-NOT: _Z10cmdVisiblev
+// CHECK-CMD-DAG: _Z10cmdVisiblev
+void cmdVisible() {}
+
+// CHECK-SYMBOLS-DAG: DEFAULT{{.*}} _Z10cmdVisiblev
+// CHECK-SYMBOLS-DAG: HIDDEN {{.*}} _Z6hiddenv
+// CHECK-SYMBOLS-DAG: DEFAULT{{.*}} _Z9nothiddenv
Index: clang/test/InterfaceStubs/virtual.cpp
===
--- /dev/null
+++ clang/test/InterfaceStubs/virtual.cpp
@@ -0,0 +1,41 @@
+// RUN: %clang -target x86_64-unknown-linux-gnu -o - -emit-interface-stubs \
+/

[PATCH] D63584: [clang][AST] Refactoring ASTNameGenerator to use pimpl pattern (NFC).

2019-06-19 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi created this revision.
plotfi added reviewers: compnerd, aaron.ballman.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D63584

Files:
  clang/include/clang/AST/Mangle.h
  clang/lib/AST/Mangle.cpp

Index: clang/lib/AST/Mangle.cpp
===
--- clang/lib/AST/Mangle.cpp
+++ clang/lib/AST/Mangle.cpp
@@ -283,183 +283,204 @@
   Out << OS.str().size() << OS.str();
 }
 
-ASTNameGenerator::ASTNameGenerator(ASTContext &Ctx)
-: MC(Ctx.createMangleContext()), DL(Ctx.getTargetInfo().getDataLayout()) {}
+class ASTNameGenerator::Implementation {
+  std::unique_ptr MC;
+  llvm::DataLayout DL;
 
-bool ASTNameGenerator::writeName(const Decl *D, raw_ostream &OS) {
-  // First apply frontend mangling.
-  SmallString<128> FrontendBuf;
-  llvm::raw_svector_ostream FrontendBufOS(FrontendBuf);
-  if (auto *FD = dyn_cast(D)) {
-if (FD->isDependentContext())
-  return true;
-if (writeFuncOrVarName(FD, FrontendBufOS))
-  return true;
-  } else if (auto *VD = dyn_cast(D)) {
-if (writeFuncOrVarName(VD, FrontendBufOS))
+public:
+  explicit Implementation(ASTContext &Ctx)
+  : MC(Ctx.createMangleContext()), DL(Ctx.getTargetInfo().getDataLayout()) {
+  }
+
+  bool writeName(const Decl *D, raw_ostream &OS) {
+// First apply frontend mangling.
+SmallString<128> FrontendBuf;
+llvm::raw_svector_ostream FrontendBufOS(FrontendBuf);
+if (auto *FD = dyn_cast(D)) {
+  if (FD->isDependentContext())
+return true;
+  if (writeFuncOrVarName(FD, FrontendBufOS))
+return true;
+} else if (auto *VD = dyn_cast(D)) {
+  if (writeFuncOrVarName(VD, FrontendBufOS))
+return true;
+} else if (auto *MD = dyn_cast(D)) {
+  MC->mangleObjCMethodNameWithoutSize(MD, OS);
+  return false;
+} else if (auto *ID = dyn_cast(D)) {
+  writeObjCClassName(ID, FrontendBufOS);
+} else {
   return true;
-  } else if (auto *MD = dyn_cast(D)) {
-MC->mangleObjCMethodNameWithoutSize(MD, OS);
+}
+
+// Now apply backend mangling.
+llvm::Mangler::getNameWithPrefix(OS, FrontendBufOS.str(), DL);
 return false;
-  } else if (auto *ID = dyn_cast(D)) {
-writeObjCClassName(ID, FrontendBufOS);
-  } else {
-return true;
   }
 
-  // Now apply backend mangling.
-  llvm::Mangler::getNameWithPrefix(OS, FrontendBufOS.str(), DL);
-  return false;
-}
-
-std::string ASTNameGenerator::getName(const Decl *D) {
-  std::string Name;
-  {
-llvm::raw_string_ostream OS(Name);
-writeName(D, OS);
+  std::string getName(const Decl *D) {
+std::string Name;
+{
+  llvm::raw_string_ostream OS(Name);
+  writeName(D, OS);
+}
+return Name;
   }
-  return Name;
-}
 
-enum ObjCKind {
-  ObjCClass,
-  ObjCMetaclass,
-};
+  enum ObjCKind {
+ObjCClass,
+ObjCMetaclass,
+  };
 
-static StringRef getClassSymbolPrefix(ObjCKind Kind,
-  const ASTContext &Context) {
-  if (Context.getLangOpts().ObjCRuntime.isGNUFamily())
-return Kind == ObjCMetaclass ? "_OBJC_METACLASS_" : "_OBJC_CLASS_";
-  return Kind == ObjCMetaclass ? "OBJC_METACLASS_$_" : "OBJC_CLASS_$_";
-}
+  static StringRef getClassSymbolPrefix(ObjCKind Kind,
+const ASTContext &Context) {
+if (Context.getLangOpts().ObjCRuntime.isGNUFamily())
+  return Kind == ObjCMetaclass ? "_OBJC_METACLASS_" : "_OBJC_CLASS_";
+return Kind == ObjCMetaclass ? "OBJC_METACLASS_$_" : "OBJC_CLASS_$_";
+  }
 
-std::vector
-ASTNameGenerator::getAllManglings(const ObjCContainerDecl *OCD) {
-  StringRef ClassName;
-  if (const auto *OID = dyn_cast(OCD))
-ClassName = OID->getObjCRuntimeNameAsString();
-  else if (const auto *OID = dyn_cast(OCD))
-ClassName = OID->getObjCRuntimeNameAsString();
-
-  if (ClassName.empty())
-return {};
-
-  auto Mangle = [&](ObjCKind Kind, StringRef ClassName) -> std::string {
-SmallString<40> Mangled;
-auto Prefix = getClassSymbolPrefix(Kind, OCD->getASTContext());
-llvm::Mangler::getNameWithPrefix(Mangled, Prefix + ClassName, DL);
-return Mangled.str();
-  };
+  std::vector getAllManglings(const ObjCContainerDecl *OCD) {
+StringRef ClassName;
+if (const auto *OID = dyn_cast(OCD))
+  ClassName = OID->getObjCRuntimeNameAsString();
+else if (const auto *OID = dyn_cast(OCD))
+  ClassName = OID->getObjCRuntimeNameAsString();
+
+if (ClassName.empty())
+  return {};
+
+auto Mangle = [&](ObjCKind Kind, StringRef ClassName) -> std::string {
+  SmallString<40> Mangled;
+  auto Prefix = getClassSymbolPrefix(Kind, OCD->getASTContext());
+  llvm::Mangler::getNameWithPrefix(Mangled, Prefix + ClassName, DL);
+  return Mangled.str();
+};
+
+return {
+Mangle(ObjCClass, ClassName),
+Mangle(ObjCMetaclass, ClassName),
+};
+  }
 
-  return {
-  Mangle(ObjCClas

[PATCH] D63584: [clang][AST] Refactoring ASTNameGenerator to use pimpl pattern (NFC).

2019-06-19 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi updated this revision to Diff 205728.
plotfi added a comment.

moving datalayout.h


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D63584/new/

https://reviews.llvm.org/D63584

Files:
  clang/include/clang/AST/Mangle.h
  clang/lib/AST/Mangle.cpp

Index: clang/lib/AST/Mangle.cpp
===
--- clang/lib/AST/Mangle.cpp
+++ clang/lib/AST/Mangle.cpp
@@ -22,6 +22,7 @@
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/TargetInfo.h"
 #include "llvm/ADT/StringExtras.h"
+#include "llvm/IR/DataLayout.h"
 #include "llvm/IR/Mangler.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/raw_ostream.h"
@@ -283,183 +284,204 @@
   Out << OS.str().size() << OS.str();
 }
 
-ASTNameGenerator::ASTNameGenerator(ASTContext &Ctx)
-: MC(Ctx.createMangleContext()), DL(Ctx.getTargetInfo().getDataLayout()) {}
+class ASTNameGenerator::Implementation {
+  std::unique_ptr MC;
+  llvm::DataLayout DL;
 
-bool ASTNameGenerator::writeName(const Decl *D, raw_ostream &OS) {
-  // First apply frontend mangling.
-  SmallString<128> FrontendBuf;
-  llvm::raw_svector_ostream FrontendBufOS(FrontendBuf);
-  if (auto *FD = dyn_cast(D)) {
-if (FD->isDependentContext())
-  return true;
-if (writeFuncOrVarName(FD, FrontendBufOS))
-  return true;
-  } else if (auto *VD = dyn_cast(D)) {
-if (writeFuncOrVarName(VD, FrontendBufOS))
+public:
+  explicit Implementation(ASTContext &Ctx)
+  : MC(Ctx.createMangleContext()), DL(Ctx.getTargetInfo().getDataLayout()) {
+  }
+
+  bool writeName(const Decl *D, raw_ostream &OS) {
+// First apply frontend mangling.
+SmallString<128> FrontendBuf;
+llvm::raw_svector_ostream FrontendBufOS(FrontendBuf);
+if (auto *FD = dyn_cast(D)) {
+  if (FD->isDependentContext())
+return true;
+  if (writeFuncOrVarName(FD, FrontendBufOS))
+return true;
+} else if (auto *VD = dyn_cast(D)) {
+  if (writeFuncOrVarName(VD, FrontendBufOS))
+return true;
+} else if (auto *MD = dyn_cast(D)) {
+  MC->mangleObjCMethodNameWithoutSize(MD, OS);
+  return false;
+} else if (auto *ID = dyn_cast(D)) {
+  writeObjCClassName(ID, FrontendBufOS);
+} else {
   return true;
-  } else if (auto *MD = dyn_cast(D)) {
-MC->mangleObjCMethodNameWithoutSize(MD, OS);
+}
+
+// Now apply backend mangling.
+llvm::Mangler::getNameWithPrefix(OS, FrontendBufOS.str(), DL);
 return false;
-  } else if (auto *ID = dyn_cast(D)) {
-writeObjCClassName(ID, FrontendBufOS);
-  } else {
-return true;
   }
 
-  // Now apply backend mangling.
-  llvm::Mangler::getNameWithPrefix(OS, FrontendBufOS.str(), DL);
-  return false;
-}
-
-std::string ASTNameGenerator::getName(const Decl *D) {
-  std::string Name;
-  {
-llvm::raw_string_ostream OS(Name);
-writeName(D, OS);
+  std::string getName(const Decl *D) {
+std::string Name;
+{
+  llvm::raw_string_ostream OS(Name);
+  writeName(D, OS);
+}
+return Name;
   }
-  return Name;
-}
 
-enum ObjCKind {
-  ObjCClass,
-  ObjCMetaclass,
-};
+  enum ObjCKind {
+ObjCClass,
+ObjCMetaclass,
+  };
 
-static StringRef getClassSymbolPrefix(ObjCKind Kind,
-  const ASTContext &Context) {
-  if (Context.getLangOpts().ObjCRuntime.isGNUFamily())
-return Kind == ObjCMetaclass ? "_OBJC_METACLASS_" : "_OBJC_CLASS_";
-  return Kind == ObjCMetaclass ? "OBJC_METACLASS_$_" : "OBJC_CLASS_$_";
-}
+  static StringRef getClassSymbolPrefix(ObjCKind Kind,
+const ASTContext &Context) {
+if (Context.getLangOpts().ObjCRuntime.isGNUFamily())
+  return Kind == ObjCMetaclass ? "_OBJC_METACLASS_" : "_OBJC_CLASS_";
+return Kind == ObjCMetaclass ? "OBJC_METACLASS_$_" : "OBJC_CLASS_$_";
+  }
 
-std::vector
-ASTNameGenerator::getAllManglings(const ObjCContainerDecl *OCD) {
-  StringRef ClassName;
-  if (const auto *OID = dyn_cast(OCD))
-ClassName = OID->getObjCRuntimeNameAsString();
-  else if (const auto *OID = dyn_cast(OCD))
-ClassName = OID->getObjCRuntimeNameAsString();
-
-  if (ClassName.empty())
-return {};
-
-  auto Mangle = [&](ObjCKind Kind, StringRef ClassName) -> std::string {
-SmallString<40> Mangled;
-auto Prefix = getClassSymbolPrefix(Kind, OCD->getASTContext());
-llvm::Mangler::getNameWithPrefix(Mangled, Prefix + ClassName, DL);
-return Mangled.str();
-  };
+  std::vector getAllManglings(const ObjCContainerDecl *OCD) {
+StringRef ClassName;
+if (const auto *OID = dyn_cast(OCD))
+  ClassName = OID->getObjCRuntimeNameAsString();
+else if (const auto *OID = dyn_cast(OCD))
+  ClassName = OID->getObjCRuntimeNameAsString();
+
+if (ClassName.empty())
+  return {};
+
+auto Mangle = [&](ObjCKind Kind, StringRef ClassName) -> std::string {
+  SmallString<40> Mangled;
+  auto Prefix = getClassSymbolPrefix(Kind, 

[PATCH] D63584: [clang][AST] Refactoring ASTNameGenerator to use pimpl pattern (NFC).

2019-06-19 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi updated this revision to Diff 205729.
plotfi added a comment.

full context


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D63584/new/

https://reviews.llvm.org/D63584

Files:
  clang/include/clang/AST/Mangle.h
  clang/lib/AST/Mangle.cpp

Index: clang/lib/AST/Mangle.cpp
===
--- clang/lib/AST/Mangle.cpp
+++ clang/lib/AST/Mangle.cpp
@@ -22,6 +22,7 @@
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/TargetInfo.h"
 #include "llvm/ADT/StringExtras.h"
+#include "llvm/IR/DataLayout.h"
 #include "llvm/IR/Mangler.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/raw_ostream.h"
@@ -283,10 +284,16 @@
   Out << OS.str().size() << OS.str();
 }
 
-ASTNameGenerator::ASTNameGenerator(ASTContext &Ctx)
-: MC(Ctx.createMangleContext()), DL(Ctx.getTargetInfo().getDataLayout()) {}
+class ASTNameGenerator::Implementation {
+  std::unique_ptr MC;
+  llvm::DataLayout DL;
 
-bool ASTNameGenerator::writeName(const Decl *D, raw_ostream &OS) {
+public:
+  explicit Implementation(ASTContext &Ctx)
+  : MC(Ctx.createMangleContext()), DL(Ctx.getTargetInfo().getDataLayout()) {
+  }
+
+  bool writeName(const Decl *D, raw_ostream &OS) {
 // First apply frontend mangling.
 SmallString<128> FrontendBuf;
 llvm::raw_svector_ostream FrontendBufOS(FrontendBuf);
@@ -312,7 +319,7 @@
 return false;
   }
 
-std::string ASTNameGenerator::getName(const Decl *D) {
+  std::string getName(const Decl *D) {
 std::string Name;
 {
   llvm::raw_string_ostream OS(Name);
@@ -333,8 +340,7 @@
 return Kind == ObjCMetaclass ? "OBJC_METACLASS_$_" : "OBJC_CLASS_$_";
   }
 
-std::vector
-ASTNameGenerator::getAllManglings(const ObjCContainerDecl *OCD) {
+  std::vector getAllManglings(const ObjCContainerDecl *OCD) {
 StringRef ClassName;
 if (const auto *OID = dyn_cast(OCD))
   ClassName = OID->getObjCRuntimeNameAsString();
@@ -357,7 +363,7 @@
 };
   }
 
-std::vector ASTNameGenerator::getAllManglings(const Decl *D) {
+  std::vector getAllManglings(const Decl *D) {
 if (const auto *OCD = dyn_cast(D))
   return getAllManglings(OCD);
 
@@ -407,7 +413,8 @@
 return Manglings;
   }
 
-bool ASTNameGenerator::writeFuncOrVarName(const NamedDecl *D, raw_ostream &OS) {
+private:
+  bool writeFuncOrVarName(const NamedDecl *D, raw_ostream &OS) {
 if (MC->shouldMangleDeclName(D)) {
   if (const auto *CtorD = dyn_cast(D))
 MC->mangleCXXCtor(CtorD, Ctor_Complete, OS);
@@ -425,14 +432,12 @@
 }
   }
 
-void ASTNameGenerator::writeObjCClassName(const ObjCInterfaceDecl *D,
-  raw_ostream &OS) {
+  void writeObjCClassName(const ObjCInterfaceDecl *D, raw_ostream &OS) {
 OS << getClassSymbolPrefix(ObjCClass, D->getASTContext());
 OS << D->getObjCRuntimeNameAsString();
   }
 
-std::string ASTNameGenerator::getMangledStructor(const NamedDecl *ND,
- unsigned StructorType) {
+  std::string getMangledStructor(const NamedDecl *ND, unsigned StructorType) {
 std::string FrontendBuf;
 llvm::raw_string_ostream FOS(FrontendBuf);
 
@@ -449,8 +454,7 @@
 return BOS.str();
   }
 
-std::string ASTNameGenerator::getMangledThunk(const CXXMethodDecl *MD,
-  const ThunkInfo &T) {
+  std::string getMangledThunk(const CXXMethodDecl *MD, const ThunkInfo &T) {
 std::string FrontendBuf;
 llvm::raw_string_ostream FOS(FrontendBuf);
 
@@ -463,3 +467,21 @@
 
 return BOS.str();
   }
+};
+
+ASTNameGenerator::ASTNameGenerator(ASTContext &Ctx)
+: Impl(new Implementation(Ctx)) {}
+
+ASTNameGenerator::~ASTNameGenerator() {}
+
+bool ASTNameGenerator::writeName(const Decl *D, raw_ostream &OS) {
+  return Impl->writeName(D, OS);
+}
+
+std::string ASTNameGenerator::getName(const Decl *D) {
+  return Impl->getName(D);
+}
+
+std::vector ASTNameGenerator::getAllManglings(const Decl *D) {
+  return Impl->getAllManglings(D);
+}
Index: clang/include/clang/AST/Mangle.h
===
--- clang/include/clang/AST/Mangle.h
+++ clang/include/clang/AST/Mangle.h
@@ -17,7 +17,6 @@
 #include "clang/AST/Type.h"
 #include "clang/Basic/ABI.h"
 #include "llvm/ADT/DenseMap.h"
-#include "llvm/IR/DataLayout.h"
 #include "llvm/Support/Casting.h"
 
 namespace llvm {
@@ -246,21 +245,16 @@
 };
 
 class ASTNameGenerator {
-  std::unique_ptr MC;
-  llvm::DataLayout DL;
-
 public:
   explicit ASTNameGenerator(ASTContext &Ctx);
+  ~ASTNameGenerator();
   bool writeName(const Decl *D, raw_ostream &OS);
   std::string getName(const Decl *D);
   std::vector getAllManglings(const Decl *D);
 
 private:
-  std::vector getAllManglings(const ObjCContainerDecl *OCD);
-  bool writeFuncOrVarName(const NamedDecl *D, raw_ostream &OS);
-  void writeObjCClassName(const ObjCInterfaceDecl *D, raw_ostream &OS);
-  std::string ge

[PATCH] D63584: [clang][AST] Refactoring ASTNameGenerator to use pimpl pattern (NFC).

2019-06-19 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi marked an inline comment as done.
plotfi added inline comments.



Comment at: clang/lib/AST/Mangle.cpp:343
 
-std::vector
-ASTNameGenerator::getAllManglings(const ObjCContainerDecl *OCD) {
+  std::vector getAllManglings(const ObjCContainerDecl *OCD) {
 StringRef ClassName;

@aaron.ballman I can move this down to the private section in a subsequent NFC 
if you'd like. 


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D63584/new/

https://reviews.llvm.org/D63584



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


[PATCH] D63584: [clang][AST] Refactoring ASTNameGenerator to use pimpl pattern (NFC).

2019-06-19 Thread Puyan Lotfi via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL363908: [clang][AST] Refactoring ASTNameGenerator to use 
pimpl pattern (NFC). (authored by zer0, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D63584?vs=205729&id=205739#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D63584/new/

https://reviews.llvm.org/D63584

Files:
  cfe/trunk/include/clang/AST/Mangle.h
  cfe/trunk/lib/AST/Mangle.cpp

Index: cfe/trunk/include/clang/AST/Mangle.h
===
--- cfe/trunk/include/clang/AST/Mangle.h
+++ cfe/trunk/include/clang/AST/Mangle.h
@@ -17,7 +17,6 @@
 #include "clang/AST/Type.h"
 #include "clang/Basic/ABI.h"
 #include "llvm/ADT/DenseMap.h"
-#include "llvm/IR/DataLayout.h"
 #include "llvm/Support/Casting.h"
 
 namespace llvm {
@@ -246,21 +245,16 @@
 };
 
 class ASTNameGenerator {
-  std::unique_ptr MC;
-  llvm::DataLayout DL;
-
 public:
   explicit ASTNameGenerator(ASTContext &Ctx);
+  ~ASTNameGenerator();
   bool writeName(const Decl *D, raw_ostream &OS);
   std::string getName(const Decl *D);
   std::vector getAllManglings(const Decl *D);
 
 private:
-  std::vector getAllManglings(const ObjCContainerDecl *OCD);
-  bool writeFuncOrVarName(const NamedDecl *D, raw_ostream &OS);
-  void writeObjCClassName(const ObjCInterfaceDecl *D, raw_ostream &OS);
-  std::string getMangledStructor(const NamedDecl *ND, unsigned StructorType);
-  std::string getMangledThunk(const CXXMethodDecl *MD, const ThunkInfo &T);
+  class Implementation;
+  std::unique_ptr Impl;
 };
 }
 
Index: cfe/trunk/lib/AST/Mangle.cpp
===
--- cfe/trunk/lib/AST/Mangle.cpp
+++ cfe/trunk/lib/AST/Mangle.cpp
@@ -22,6 +22,7 @@
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/TargetInfo.h"
 #include "llvm/ADT/StringExtras.h"
+#include "llvm/IR/DataLayout.h"
 #include "llvm/IR/Mangler.h"
 #include "llvm/Support/ErrorHandling.h"
 #include "llvm/Support/raw_ostream.h"
@@ -283,183 +284,204 @@
   Out << OS.str().size() << OS.str();
 }
 
-ASTNameGenerator::ASTNameGenerator(ASTContext &Ctx)
-: MC(Ctx.createMangleContext()), DL(Ctx.getTargetInfo().getDataLayout()) {}
-
-bool ASTNameGenerator::writeName(const Decl *D, raw_ostream &OS) {
-  // First apply frontend mangling.
-  SmallString<128> FrontendBuf;
-  llvm::raw_svector_ostream FrontendBufOS(FrontendBuf);
-  if (auto *FD = dyn_cast(D)) {
-if (FD->isDependentContext())
+class ASTNameGenerator::Implementation {
+  std::unique_ptr MC;
+  llvm::DataLayout DL;
+
+public:
+  explicit Implementation(ASTContext &Ctx)
+  : MC(Ctx.createMangleContext()), DL(Ctx.getTargetInfo().getDataLayout()) {
+  }
+
+  bool writeName(const Decl *D, raw_ostream &OS) {
+// First apply frontend mangling.
+SmallString<128> FrontendBuf;
+llvm::raw_svector_ostream FrontendBufOS(FrontendBuf);
+if (auto *FD = dyn_cast(D)) {
+  if (FD->isDependentContext())
+return true;
+  if (writeFuncOrVarName(FD, FrontendBufOS))
+return true;
+} else if (auto *VD = dyn_cast(D)) {
+  if (writeFuncOrVarName(VD, FrontendBufOS))
+return true;
+} else if (auto *MD = dyn_cast(D)) {
+  MC->mangleObjCMethodNameWithoutSize(MD, OS);
+  return false;
+} else if (auto *ID = dyn_cast(D)) {
+  writeObjCClassName(ID, FrontendBufOS);
+} else {
   return true;
-if (writeFuncOrVarName(FD, FrontendBufOS))
-  return true;
-  } else if (auto *VD = dyn_cast(D)) {
-if (writeFuncOrVarName(VD, FrontendBufOS))
-  return true;
-  } else if (auto *MD = dyn_cast(D)) {
-MC->mangleObjCMethodNameWithoutSize(MD, OS);
+}
+
+// Now apply backend mangling.
+llvm::Mangler::getNameWithPrefix(OS, FrontendBufOS.str(), DL);
 return false;
-  } else if (auto *ID = dyn_cast(D)) {
-writeObjCClassName(ID, FrontendBufOS);
-  } else {
-return true;
   }
 
-  // Now apply backend mangling.
-  llvm::Mangler::getNameWithPrefix(OS, FrontendBufOS.str(), DL);
-  return false;
-}
-
-std::string ASTNameGenerator::getName(const Decl *D) {
-  std::string Name;
-  {
-llvm::raw_string_ostream OS(Name);
-writeName(D, OS);
+  std::string getName(const Decl *D) {
+std::string Name;
+{
+  llvm::raw_string_ostream OS(Name);
+  writeName(D, OS);
+}
+return Name;
   }
-  return Name;
-}
 
-enum ObjCKind {
-  ObjCClass,
-  ObjCMetaclass,
-};
-
-static StringRef getClassSymbolPrefix(ObjCKind Kind,
-  const ASTContext &Context) {
-  if (Context.getLangOpts().ObjCRuntime.isGNUFamily())
-return Kind == ObjCMetaclass ? "_OBJC_METACLASS_" : "_OBJC_CLASS_";
-  return Kind == ObjCMetaclass ? "OBJC_METACLASS_$_" : "OBJC_CLASS_$_";
-}
-
-std::vector
-ASTNameGenerator::getAllManglings(const ObjCContainerDecl *OCD) {
-  StringRef C

[PATCH] D60974: Clang IFSO driver action.

2019-06-20 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi added a comment.

This was re-landed in r363948


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60974/new/

https://reviews.llvm.org/D60974



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


[PATCH] D64098: [NFC][clang] Refactor getCompilationPhases step 1: Move list of phases into Types.def table.

2019-07-17 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi added a comment.

@aaron.ballman Any thoughts on this?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64098/new/

https://reviews.llvm.org/D64098



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


[PATCH] D64098: [NFC][clang] Refactor getCompilationPhases step 1: Move list of phases into Types.def table.

2019-07-17 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi added inline comments.



Comment at: clang/lib/Driver/Driver.cpp:2217
   public:
-typedef llvm::SmallVector PhasesTy;
+typedef const std::vector PhasesTy;
 

aaron.ballman wrote:
> Why are you changing this to an STL type?
I changed it because it didn't look like you can return a SmallVector, but I 
just changed it back to the old SmallVector function calling style.



Comment at: clang/lib/Driver/Driver.cpp:3236
 
-PL.clear();
-types::getCompilationPhases(InputType, PL);
+const std::vector PL = types::getCompilationPhases(InputType);
+LastPLSize = PL.size();

aaron.ballman wrote:
> You could use a `const &` here and avoid the copy. Either that, or drop the 
> `const` (it's not a common pattern in the code base).
Going to keep the copy. I want to eventually merge getCompilationPhases and 
getFinalPhase into the same function. 



Comment at: clang/lib/Driver/Types.cpp:301-303
+  assert(Phases.size() == P.size() && "Invalid size.");
+  for (unsigned i = 0; i < Phases.size(); i++)
+assert(Phases[i] == P[i] && "Invalid Phase");

aaron.ballman wrote:
> You can replace all three lines by:
> `assert(std::equal(Phases.begin(), Phases.end(), P.begin(), P.end()) && 
> "Invalid phase or size");`
Nice!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64098/new/

https://reviews.llvm.org/D64098



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


[PATCH] D64098: [NFC][clang] Refactor getCompilationPhases step 1: Move list of phases into Types.def table.

2019-07-17 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi updated this revision to Diff 210431.
plotfi marked 10 inline comments as done.
plotfi added a comment.

Updated to address @aaron.ballman 's feedback


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64098/new/

https://reviews.llvm.org/D64098

Files:
  clang/include/clang/Driver/Types.def
  clang/include/clang/Driver/Types.h
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/Types.cpp

Index: clang/lib/Driver/Types.cpp
===
--- clang/lib/Driver/Types.cpp
+++ clang/lib/Driver/Types.cpp
@@ -9,8 +9,9 @@
 #include "clang/Driver/Types.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringSwitch.h"
+#include "llvm/ADT/SmallVector.h"
 #include 
-#include 
+#include 
 
 using namespace clang::driver;
 using namespace clang::driver::types;
@@ -20,11 +21,12 @@
   const char *Flags;
   const char *TempSuffix;
   ID PreprocessedType;
+  const llvm::SmallVector Phases;
 };
 
 static const TypeInfo TypeInfos[] = {
-#define TYPE(NAME, ID, PP_TYPE, TEMP_SUFFIX, FLAGS) \
-  { NAME, FLAGS, TEMP_SUFFIX, TY_##PP_TYPE, },
+#define TYPE(NAME, ID, PP_TYPE, TEMP_SUFFIX, FLAGS, ...) \
+  { NAME, FLAGS, TEMP_SUFFIX, TY_##PP_TYPE, { __VA_ARGS__ }, },
 #include "clang/Driver/Types.def"
 #undef TYPE
 };
@@ -264,6 +266,8 @@
 }
 
 // FIXME: Why don't we just put this list in the defs file, eh.
+// FIXME: The list is now in Types.def but for now this function will verify
+//the old behavior and a subsequent change will delete most of the body.
 void types::getCompilationPhases(ID Id, llvm::SmallVectorImpl &P) {
   if (Id != TY_Object) {
 if (getPreprocessedType(Id) != TY_INVALID) {
@@ -286,6 +290,21 @@
   if (!onlyPrecompileType(Id)) {
 P.push_back(phases::Link);
   }
+
+  // Check that the static Phase list matches.
+  // TODO: These will be deleted.
+  const llvm::SmallVectorImpl &Phases = getInfo(Id).Phases;
+  assert(Phases.size() == P.size() &&
+ std::equal(Phases.begin(), Phases.end(), P.begin()) &&
+ "Invalid phase or size");
+
+  // TODO: This function is still being used to assert that the phase list in
+  //   Types.def is correct. Everything above this comment will be removed
+  //   in a subsequent NFC commit.
+  P.clear();
+  for (auto Phase : getInfo(Id).Phases)
+P.push_back(Phase);
+
   assert(0 < P.size() && "Not enough phases in list");
   assert(P.size() <= phases::MaxNumberOfPhases && "Too many phases in list");
 }
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -2223,7 +2223,7 @@
   /// Builder interface. It doesn't build anything or keep any state.
   class DeviceActionBuilder {
   public:
-typedef llvm::SmallVector PhasesTy;
+typedef const llvm::SmallVectorImpl PhasesTy;
 
 enum ActionBuilderReturnCode {
   // The builder acted successfully on the current action.
@@ -3237,13 +3237,14 @@
   HeaderModulePrecompileJobAction *HeaderModuleAction = nullptr;
   ActionList LinkerInputs;
 
-  llvm::SmallVector PL;
+  unsigned LastPLSize = 0;
   for (auto &I : Inputs) {
 types::ID InputType = I.first;
 const Arg *InputArg = I.second;
 
-PL.clear();
+llvm::SmallVector PL;
 types::getCompilationPhases(InputType, PL);
+LastPLSize = PL.size();
 
 // If the first step comes after the final phase we are doing as part of
 // this compilation, warn the user about it.
@@ -3309,9 +3310,7 @@
 if (OffloadBuilder.addHostDependenceToDeviceActions(Current, InputArg))
   break;
 
-for (SmallVectorImpl::iterator i = PL.begin(), e = PL.end();
- i != e; ++i) {
-  phases::ID Phase = *i;
+for (phases::ID Phase : PL) {
 
   // We are done if this step is past what the user requested.
   if (Phase > FinalPhase)
@@ -3325,7 +3324,7 @@
 
   // Queue linker inputs.
   if (Phase == phases::Link) {
-assert((i + 1) == e && "linking must be final compilation step.");
+assert(Phase == PL.back() && "linking must be final compilation step.");
 LinkerInputs.push_back(Current);
 Current = nullptr;
 break;
@@ -3382,7 +3381,8 @@
 
   // If we are linking, claim any options which are obviously only used for
   // compilation.
-  if (FinalPhase == phases::Link && PL.size() == 1) {
+  // FIXME: Understand why the last Phase List length is used here.
+  if (FinalPhase == phases::Link && LastPLSize == 1) {
 Args.ClaimAllArgs(options::OPT_CompileOnly_Group);
 Args.ClaimAllArgs(options::OPT_cl_compile_Group);
   }
Index: clang/include/clang/Driver/Types.h
===
--- clang/include/clang/Driver/Types.h
+++ clang/include/clang/Driver/Types.h
@@ -20,7 +20,7 @@
 namespace types {
   enum ID {
 TY_INVALID,
-#define TYPE(NAME, ID, PP_TYPE, TEMP_SUFFIX, FLAGS) TY_##ID,
+#define TYPE(NAME, ID, 

[PATCH] D64098: [NFC][clang] Refactor getCompilationPhases step 1: Move list of phases into Types.def table.

2019-07-18 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi marked an inline comment as done.
plotfi added inline comments.



Comment at: clang/lib/Driver/Types.cpp:305
+  P.clear();
+  for (auto Phase : getInfo(Id).Phases)
+P.push_back(Phase);

aaron.ballman wrote:
> Can't you use the local `Phases` object instead of calling `getInfo()` again? 
> This seems like it wants to be `P = Phases;`
Oh yeah sure. I can change that. Anything else pop out at you? 


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64098/new/

https://reviews.llvm.org/D64098



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


[PATCH] D64098: [NFC][clang] Refactor getCompilationPhases step 1: Move list of phases into Types.def table.

2019-07-18 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi updated this revision to Diff 210609.
plotfi added a comment.

Update.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64098/new/

https://reviews.llvm.org/D64098

Files:
  clang/include/clang/Driver/Types.def
  clang/include/clang/Driver/Types.h
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/Types.cpp

Index: clang/lib/Driver/Types.cpp
===
--- clang/lib/Driver/Types.cpp
+++ clang/lib/Driver/Types.cpp
@@ -9,8 +9,9 @@
 #include "clang/Driver/Types.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringSwitch.h"
+#include "llvm/ADT/SmallVector.h"
 #include 
-#include 
+#include 
 
 using namespace clang::driver;
 using namespace clang::driver::types;
@@ -20,11 +21,12 @@
   const char *Flags;
   const char *TempSuffix;
   ID PreprocessedType;
+  const llvm::SmallVector Phases;
 };
 
 static const TypeInfo TypeInfos[] = {
-#define TYPE(NAME, ID, PP_TYPE, TEMP_SUFFIX, FLAGS) \
-  { NAME, FLAGS, TEMP_SUFFIX, TY_##PP_TYPE, },
+#define TYPE(NAME, ID, PP_TYPE, TEMP_SUFFIX, FLAGS, ...) \
+  { NAME, FLAGS, TEMP_SUFFIX, TY_##PP_TYPE, { __VA_ARGS__ }, },
 #include "clang/Driver/Types.def"
 #undef TYPE
 };
@@ -264,6 +266,8 @@
 }
 
 // FIXME: Why don't we just put this list in the defs file, eh.
+// FIXME: The list is now in Types.def but for now this function will verify
+//the old behavior and a subsequent change will delete most of the body.
 void types::getCompilationPhases(ID Id, llvm::SmallVectorImpl &P) {
   if (Id != TY_Object) {
 if (getPreprocessedType(Id) != TY_INVALID) {
@@ -286,6 +290,21 @@
   if (!onlyPrecompileType(Id)) {
 P.push_back(phases::Link);
   }
+
+  // Check that the static Phase list matches.
+  // TODO: These will be deleted.
+  const llvm::SmallVectorImpl &Phases = getInfo(Id).Phases;
+  assert(Phases.size() == P.size() &&
+ std::equal(Phases.begin(), Phases.end(), P.begin()) &&
+ "Invalid phase or size");
+
+  // TODO: This function is still being used to assert that the phase list in
+  //   Types.def is correct. Everything above this comment will be removed
+  //   in a subsequent NFC commit.
+  P.clear();
+  for (auto Phase : Phases)
+P.push_back(Phase);
+
   assert(0 < P.size() && "Not enough phases in list");
   assert(P.size() <= phases::MaxNumberOfPhases && "Too many phases in list");
 }
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -2223,7 +2223,7 @@
   /// Builder interface. It doesn't build anything or keep any state.
   class DeviceActionBuilder {
   public:
-typedef llvm::SmallVector PhasesTy;
+typedef const llvm::SmallVectorImpl PhasesTy;
 
 enum ActionBuilderReturnCode {
   // The builder acted successfully on the current action.
@@ -3237,13 +3237,14 @@
   HeaderModulePrecompileJobAction *HeaderModuleAction = nullptr;
   ActionList LinkerInputs;
 
-  llvm::SmallVector PL;
+  unsigned LastPLSize = 0;
   for (auto &I : Inputs) {
 types::ID InputType = I.first;
 const Arg *InputArg = I.second;
 
-PL.clear();
+llvm::SmallVector PL;
 types::getCompilationPhases(InputType, PL);
+LastPLSize = PL.size();
 
 // If the first step comes after the final phase we are doing as part of
 // this compilation, warn the user about it.
@@ -3309,9 +3310,7 @@
 if (OffloadBuilder.addHostDependenceToDeviceActions(Current, InputArg))
   break;
 
-for (SmallVectorImpl::iterator i = PL.begin(), e = PL.end();
- i != e; ++i) {
-  phases::ID Phase = *i;
+for (phases::ID Phase : PL) {
 
   // We are done if this step is past what the user requested.
   if (Phase > FinalPhase)
@@ -3325,7 +3324,7 @@
 
   // Queue linker inputs.
   if (Phase == phases::Link) {
-assert((i + 1) == e && "linking must be final compilation step.");
+assert(Phase == PL.back() && "linking must be final compilation step.");
 LinkerInputs.push_back(Current);
 Current = nullptr;
 break;
@@ -3382,7 +3381,8 @@
 
   // If we are linking, claim any options which are obviously only used for
   // compilation.
-  if (FinalPhase == phases::Link && PL.size() == 1) {
+  // FIXME: Understand why the last Phase List length is used here.
+  if (FinalPhase == phases::Link && LastPLSize == 1) {
 Args.ClaimAllArgs(options::OPT_CompileOnly_Group);
 Args.ClaimAllArgs(options::OPT_cl_compile_Group);
   }
Index: clang/include/clang/Driver/Types.h
===
--- clang/include/clang/Driver/Types.h
+++ clang/include/clang/Driver/Types.h
@@ -20,7 +20,7 @@
 namespace types {
   enum ID {
 TY_INVALID,
-#define TYPE(NAME, ID, PP_TYPE, TEMP_SUFFIX, FLAGS) TY_##ID,
+#define TYPE(NAME, ID, PP_TYPE, TEMP_SUFFIX, FLAGS, ...) TY_##ID,
 #include "clang/Driver/Types.def"
 #undef TYPE
 

[PATCH] D64098: [NFC][clang] Refactor getCompilationPhases step 1: Move list of phases into Types.def table.

2019-07-18 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi updated this revision to Diff 210696.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64098/new/

https://reviews.llvm.org/D64098

Files:
  clang/include/clang/Driver/Types.def
  clang/include/clang/Driver/Types.h
  clang/lib/Driver/Driver.cpp
  clang/lib/Driver/Types.cpp

Index: clang/lib/Driver/Types.cpp
===
--- clang/lib/Driver/Types.cpp
+++ clang/lib/Driver/Types.cpp
@@ -9,8 +9,9 @@
 #include "clang/Driver/Types.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringSwitch.h"
+#include "llvm/ADT/SmallVector.h"
 #include 
-#include 
+#include 
 
 using namespace clang::driver;
 using namespace clang::driver::types;
@@ -20,11 +21,12 @@
   const char *Flags;
   const char *TempSuffix;
   ID PreprocessedType;
+  const llvm::SmallVector Phases;
 };
 
 static const TypeInfo TypeInfos[] = {
-#define TYPE(NAME, ID, PP_TYPE, TEMP_SUFFIX, FLAGS) \
-  { NAME, FLAGS, TEMP_SUFFIX, TY_##PP_TYPE, },
+#define TYPE(NAME, ID, PP_TYPE, TEMP_SUFFIX, FLAGS, ...) \
+  { NAME, FLAGS, TEMP_SUFFIX, TY_##PP_TYPE, { __VA_ARGS__ }, },
 #include "clang/Driver/Types.def"
 #undef TYPE
 };
@@ -264,6 +266,8 @@
 }
 
 // FIXME: Why don't we just put this list in the defs file, eh.
+// FIXME: The list is now in Types.def but for now this function will verify
+//the old behavior and a subsequent change will delete most of the body.
 void types::getCompilationPhases(ID Id, llvm::SmallVectorImpl &P) {
   if (Id != TY_Object) {
 if (getPreprocessedType(Id) != TY_INVALID) {
@@ -286,6 +290,18 @@
   if (!onlyPrecompileType(Id)) {
 P.push_back(phases::Link);
   }
+
+  // Check that the static Phase list matches.
+  // TODO: These will be deleted.
+  const llvm::SmallVectorImpl &Phases = getInfo(Id).Phases;
+  assert(Phases.size() == P.size() &&
+ std::equal(Phases.begin(), Phases.end(), P.begin()) &&
+ "Invalid phase or size");
+
+  // TODO: This function is still being used to assert that the phase list in
+  //   Types.def is correct. Everything above this comment will be removed
+  //   in a subsequent NFC commit.a
+  P = Phases;
   assert(0 < P.size() && "Not enough phases in list");
   assert(P.size() <= phases::MaxNumberOfPhases && "Too many phases in list");
 }
Index: clang/lib/Driver/Driver.cpp
===
--- clang/lib/Driver/Driver.cpp
+++ clang/lib/Driver/Driver.cpp
@@ -2223,7 +2223,7 @@
   /// Builder interface. It doesn't build anything or keep any state.
   class DeviceActionBuilder {
   public:
-typedef llvm::SmallVector PhasesTy;
+typedef const llvm::SmallVectorImpl PhasesTy;
 
 enum ActionBuilderReturnCode {
   // The builder acted successfully on the current action.
@@ -3237,13 +3237,14 @@
   HeaderModulePrecompileJobAction *HeaderModuleAction = nullptr;
   ActionList LinkerInputs;
 
-  llvm::SmallVector PL;
+  unsigned LastPLSize = 0;
   for (auto &I : Inputs) {
 types::ID InputType = I.first;
 const Arg *InputArg = I.second;
 
-PL.clear();
+llvm::SmallVector PL;
 types::getCompilationPhases(InputType, PL);
+LastPLSize = PL.size();
 
 // If the first step comes after the final phase we are doing as part of
 // this compilation, warn the user about it.
@@ -3309,9 +3310,7 @@
 if (OffloadBuilder.addHostDependenceToDeviceActions(Current, InputArg))
   break;
 
-for (SmallVectorImpl::iterator i = PL.begin(), e = PL.end();
- i != e; ++i) {
-  phases::ID Phase = *i;
+for (phases::ID Phase : PL) {
 
   // We are done if this step is past what the user requested.
   if (Phase > FinalPhase)
@@ -3325,7 +3324,7 @@
 
   // Queue linker inputs.
   if (Phase == phases::Link) {
-assert((i + 1) == e && "linking must be final compilation step.");
+assert(Phase == PL.back() && "linking must be final compilation step.");
 LinkerInputs.push_back(Current);
 Current = nullptr;
 break;
@@ -3382,7 +3381,8 @@
 
   // If we are linking, claim any options which are obviously only used for
   // compilation.
-  if (FinalPhase == phases::Link && PL.size() == 1) {
+  // FIXME: Understand why the last Phase List length is used here.
+  if (FinalPhase == phases::Link && LastPLSize == 1) {
 Args.ClaimAllArgs(options::OPT_CompileOnly_Group);
 Args.ClaimAllArgs(options::OPT_cl_compile_Group);
   }
Index: clang/include/clang/Driver/Types.h
===
--- clang/include/clang/Driver/Types.h
+++ clang/include/clang/Driver/Types.h
@@ -20,7 +20,7 @@
 namespace types {
   enum ID {
 TY_INVALID,
-#define TYPE(NAME, ID, PP_TYPE, TEMP_SUFFIX, FLAGS) TY_##ID,
+#define TYPE(NAME, ID, PP_TYPE, TEMP_SUFFIX, FLAGS, ...) TY_##ID,
 #include "clang/Driver/Types.def"
 #undef TYPE
 TY_LAST
Index: clang/include/clang/Driver/Types.def

[PATCH] D64098: [NFC][clang] Refactor getCompilationPhases step 1: Move list of phases into Types.def table.

2019-07-18 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi marked 2 inline comments as done.
plotfi added inline comments.



Comment at: clang/lib/Driver/Types.cpp:305
+  P.clear();
+  for (auto Phase : getInfo(Id).Phases)
+P.push_back(Phase);

aaron.ballman wrote:
> plotfi wrote:
> > aaron.ballman wrote:
> > > Can't you use the local `Phases` object instead of calling `getInfo()` 
> > > again? This seems like it wants to be `P = Phases;`
> > Oh yeah sure. I can change that. Anything else pop out at you? 
> You can drop the `P.clear()` as part of that assignment, but otherwise, no.
Ahh. I understand what you mean now. Thanks!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64098/new/

https://reviews.llvm.org/D64098



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


[PATCH] D64098: [NFC][clang] Refactor getCompilationPhases step 1: Move list of phases into Types.def table.

2019-07-22 Thread Puyan Lotfi via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL366761: [NFC][clang] Refactor 
getCompilationPhases()+Types.def step 1. (authored by zer0, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D64098?vs=210696&id=211225#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64098/new/

https://reviews.llvm.org/D64098

Files:
  cfe/trunk/include/clang/Driver/Types.def
  cfe/trunk/include/clang/Driver/Types.h
  cfe/trunk/lib/Driver/Driver.cpp
  cfe/trunk/lib/Driver/Types.cpp

Index: cfe/trunk/include/clang/Driver/Types.def
===
--- cfe/trunk/include/clang/Driver/Types.def
+++ cfe/trunk/include/clang/Driver/Types.def
@@ -37,69 +37,71 @@
 //  A - The type's temporary suffix should be appended when generating
 //  outputs of this type.
 
+// The sixth value is a variadic list of phases for each type. Eventually the
+// options flag string will be replaced with this variadic list.
 
 // C family source language (with and without preprocessing).
-TYPE("cpp-output",   PP_C, INVALID, "i", "u")
-TYPE("c",C,PP_C,"c", "u")
-TYPE("cl",   CL,   PP_C,"cl","u")
-TYPE("cuda-cpp-output",  PP_CUDA,  INVALID, "cui",   "u")
-TYPE("cuda", CUDA, PP_CUDA, "cu","u")
-TYPE("cuda", CUDA_DEVICE,  PP_CUDA, "cu","")
-TYPE("hip-cpp-output",   PP_HIP,   INVALID, "cui",   "u")
-TYPE("hip",  HIP,  PP_HIP,  "cu","u")
-TYPE("hip",  HIP_DEVICE,   PP_HIP,  "cu","")
-TYPE("objective-c-cpp-output",   PP_ObjC,  INVALID, "mi","u")
-TYPE("objc-cpp-output",  PP_ObjC_Alias, INVALID,"mi","u")
-TYPE("objective-c",  ObjC, PP_ObjC, "m", "u")
-TYPE("c++-cpp-output",   PP_CXX,   INVALID, "ii","u")
-TYPE("c++",  CXX,  PP_CXX,  "cpp",   "u")
-TYPE("objective-c++-cpp-output", PP_ObjCXX,INVALID, "mii",   "u")
-TYPE("objc++-cpp-output",PP_ObjCXX_Alias, INVALID,  "mii",   "u")
-TYPE("objective-c++",ObjCXX,   PP_ObjCXX,   "mm","u")
-TYPE("renderscript", RenderScript, PP_C,"rs","u")
+TYPE("cpp-output",   PP_C, INVALID, "i", "u", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
+TYPE("c",C,PP_C,"c", "u", phases::Preprocess, phases::Compile, phases::Backend, phases::Assemble, phases::Link)
+TYPE("cl",   CL,   PP_C,"cl","u", phases::Preprocess, phases::Compile, phases::Backend, phases::Assemble, phases::Link)
+TYPE("cuda-cpp-output",  PP_CUDA,  INVALID, "cui",   "u", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
+TYPE("cuda", CUDA, PP_CUDA, "cu","u", phases::Preprocess, phases::Compile, phases::Backend, phases::Assemble, phases::Link)
+TYPE("cuda", CUDA_DEVICE,  PP_CUDA, "cu","" , phases::Preprocess, phases::Compile, phases::Backend, phases::Assemble, phases::Link)
+TYPE("hip-cpp-output",   PP_HIP,   INVALID, "cui",   "u", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
+TYPE("hip",  HIP,  PP_HIP,  "cu","u", phases::Preprocess, phases::Compile, phases::Backend, phases::Assemble, phases::Link)
+TYPE("hip",  HIP_DEVICE,   PP_HIP,  "cu","" , phases::Preprocess, phases::Compile, phases::Backend, phases::Assemble, phases::Link)
+TYPE("objective-c-cpp-output",   PP_ObjC,  INVALID, "mi","u", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
+TYPE("objc-cpp-output",  PP_ObjC_Alias, INVALID,"mi","u", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
+TYPE("objective-c",  ObjC, PP_ObjC, "m", "u", phases::Preprocess, phases::Compile, phases::Backend, phases::Assemble, phases::Link)
+TYPE("c++-cpp-output",   PP_CXX,   INVALID, "ii","u", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
+TYPE("c++",  CXX,  PP_CXX,  "cpp",   "u", phases::Preprocess, phases::Compile, phases::Backend, phases::Assemble, phases::Link)
+TYPE("objective-c++-cpp-output", PP_ObjCXX,INVALID, "mii",   "u", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
+TYPE("objc++-cpp-output",PP_ObjCXX_Alias, INVALID,  "

[PATCH] D65176: [NFC][clang] Refactor getCompilationPhases()+Types.def step 2.

2019-07-23 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi created this revision.
plotfi added reviewers: aaron.ballman, compnerd.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

- Removing a few of the entries in the Flags for the Types.def table.
- Removing redundant parts of getCompilationPhases().


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D65176

Files:
  clang/include/clang/Driver/Types.def
  clang/lib/Driver/Types.cpp

Index: clang/lib/Driver/Types.cpp
===
--- clang/lib/Driver/Types.cpp
+++ clang/lib/Driver/Types.cpp
@@ -42,11 +42,19 @@
 }
 
 types::ID types::getPreprocessedType(ID Id) {
-  return getInfo(Id).PreprocessedType;
+  ID PPT = getInfo(Id).PreprocessedType;
+  assert((llvm::is_contained(getInfo(Id).Phases, phases::Preprocess) !=
+  (PPT == TY_INVALID)) &&
+ "Unexpected Preprocess Type.");
+  return PPT;
+}
+
+static bool isPrepeocessedModuleType(ID Id) {
+  return Id == TY_CXXModule || Id == TY_PP_CXXModule;
 }
 
 types::ID types::getPrecompiledType(ID Id) {
-  if (strchr(getInfo(Id).Flags, 'm'))
+  if (isPrepeocessedModuleType(Id))
 return TY_ModuleFile;
   if (onlyPrecompileType(Id))
 return TY_PCH;
@@ -71,11 +79,14 @@
 }
 
 bool types::onlyAssembleType(ID Id) {
-  return strchr(getInfo(Id).Flags, 'a');
+  return llvm::is_contained(getInfo(Id).Phases, phases::Assemble) &&
+ !llvm::is_contained(getInfo(Id).Phases, phases::Compile) &&
+ !llvm::is_contained(getInfo(Id).Phases, phases::Backend);
 }
 
 bool types::onlyPrecompileType(ID Id) {
-  return strchr(getInfo(Id).Flags, 'p');
+  return llvm::is_contained(getInfo(Id).Phases, phases::Precompile) &&
+ !isPrepeocessedModuleType(Id);
 }
 
 bool types::canTypeBeUserSpecified(ID Id) {
@@ -269,39 +280,7 @@
 // FIXME: The list is now in Types.def but for now this function will verify
 //the old behavior and a subsequent change will delete most of the body.
 void types::getCompilationPhases(ID Id, llvm::SmallVectorImpl &P) {
-  if (Id != TY_Object) {
-if (getPreprocessedType(Id) != TY_INVALID) {
-  P.push_back(phases::Preprocess);
-}
-
-if (getPrecompiledType(Id) != TY_INVALID) {
-  P.push_back(phases::Precompile);
-}
-
-if (!onlyPrecompileType(Id)) {
-  if (!onlyAssembleType(Id)) {
-P.push_back(phases::Compile);
-P.push_back(phases::Backend);
-  }
-  P.push_back(phases::Assemble);
-}
-  }
-
-  if (!onlyPrecompileType(Id)) {
-P.push_back(phases::Link);
-  }
-
-  // Check that the static Phase list matches.
-  // TODO: These will be deleted.
-  const llvm::SmallVectorImpl &Phases = getInfo(Id).Phases;
-  assert(Phases.size() == P.size() &&
- std::equal(Phases.begin(), Phases.end(), P.begin()) &&
- "Invalid phase or size");
-
-  // TODO: This function is still being used to assert that the phase list in
-  //   Types.def is correct. Everything above this comment will be removed
-  //   in a subsequent NFC commit.
-  P = Phases;
+  P = getInfo(Id).Phases;
   assert(0 < P.size() && "Not enough phases in list");
   assert(P.size() <= phases::MaxNumberOfPhases && "Too many phases in list");
 }
Index: clang/include/clang/Driver/Types.def
===
--- clang/include/clang/Driver/Types.def
+++ clang/include/clang/Driver/Types.def
@@ -30,15 +30,19 @@
 // of this type, or null if unspecified.
 
 // The fifth value is a string containing option flags. Valid values:
-//  a - The type should only be assembled.
-//  p - The type should only be precompiled.
 //  u - The type can be user specified (with -x).
-//  m - Precompiling this type produces a module file.
 //  A - The type's temporary suffix should be appended when generating
 //  outputs of this type.
 
 // The sixth value is a variadic list of phases for each type. Eventually the
 // options flag string will be replaced with this variadic list.
+// Some of the options in Flags have been removed, so far those are:
+//  a - The type should only be assembled: Now, check that Phases contains
+//  phases::Assemble but not phases::Compile or phases::Backend.
+//  p - The type should only be precompiled: Now, check that Phases contains
+//  phases::Precompile but that Flags does not contain 'm'.
+//  m - Precompiling this type produces a module file: Now, check that
+//  isPrepeocessedModuleType.
 
 // C family source language (with and without preprocessing).
 TYPE("cpp-output",   PP_C, INVALID, "i", "u", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
@@ -61,22 +65,22 @@
 TYPE("renderscript", RenderScript, PP_C,"rs","u", phases::Preprocess, phases::Compile, phases::Backend, phases::Assemble, phases::Link)
 
 // C family input files to precompile.
-TYPE("c-header-cpp-output",  PP_CHeader,   INVALID, "i", "p",  phases::Precompile)
-TYPE("c-head

[PATCH] D65176: [NFC][clang] Refactor getCompilationPhases()+Types.def step 2.

2019-07-23 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi added a comment.

In D65176#1598431 , @compnerd wrote:

> This looks good to me generally.  I don't fully understand the reason for `u` 
> being kept, is that something you intend to clean up in a subsequent patch?


I’d like to remove it but I don’t yet understand its purpose. Might deal with 
it in another patch  along with ‘A’


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65176/new/

https://reviews.llvm.org/D65176



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


[PATCH] D64098: [NFC][clang] Refactor getCompilationPhases step 1: Move list of phases into Types.def table.

2019-07-24 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi added a comment.

This was a mistake. Updated the Wrong diff.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64098/new/

https://reviews.llvm.org/D64098



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


[PATCH] D64098: [NFC][clang] Refactor getCompilationPhases step 1: Move list of phases into Types.def table.

2019-07-24 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi updated this revision to Diff 211651.
plotfi marked an inline comment as done.
plotfi added a comment.

Removing 'A'


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D64098/new/

https://reviews.llvm.org/D64098

Files:
  clang/include/clang/Driver/Types.def
  clang/lib/Driver/Types.cpp

Index: clang/lib/Driver/Types.cpp
===
--- clang/lib/Driver/Types.cpp
+++ clang/lib/Driver/Types.cpp
@@ -42,11 +42,19 @@
 }
 
 types::ID types::getPreprocessedType(ID Id) {
-  return getInfo(Id).PreprocessedType;
+  ID PPT = getInfo(Id).PreprocessedType;
+  assert((llvm::is_contained(getInfo(Id).Phases, phases::Preprocess) !=
+  (PPT == TY_INVALID)) &&
+ "Unexpected Preprocess Type.");
+  return PPT;
+}
+
+static bool isPrepeocessedModuleType(ID Id) {
+  return Id == TY_CXXModule || Id == TY_PP_CXXModule;
 }
 
 types::ID types::getPrecompiledType(ID Id) {
-  if (strchr(getInfo(Id).Flags, 'm'))
+  if (isPrepeocessedModuleType(Id))
 return TY_ModuleFile;
   if (onlyPrecompileType(Id))
 return TY_PCH;
@@ -71,11 +79,14 @@
 }
 
 bool types::onlyAssembleType(ID Id) {
-  return strchr(getInfo(Id).Flags, 'a');
+  return llvm::is_contained(getInfo(Id).Phases, phases::Assemble) &&
+ !llvm::is_contained(getInfo(Id).Phases, phases::Compile) &&
+ !llvm::is_contained(getInfo(Id).Phases, phases::Backend);
 }
 
 bool types::onlyPrecompileType(ID Id) {
-  return strchr(getInfo(Id).Flags, 'p');
+  return llvm::is_contained(getInfo(Id).Phases, phases::Precompile) &&
+ !isPrepeocessedModuleType(Id);
 }
 
 bool types::canTypeBeUserSpecified(ID Id) {
@@ -83,7 +94,8 @@
 }
 
 bool types::appendSuffixForType(ID Id) {
-  return strchr(getInfo(Id).Flags, 'A');
+  return Id == TY_PCH || Id == TY_dSYM || Id == TY_CUDA_FATBIN ||
+ Id == TY_HIP_FATBIN;
 }
 
 bool types::canLipoType(ID Id) {
@@ -269,39 +281,7 @@
 // FIXME: The list is now in Types.def but for now this function will verify
 //the old behavior and a subsequent change will delete most of the body.
 void types::getCompilationPhases(ID Id, llvm::SmallVectorImpl &P) {
-  if (Id != TY_Object) {
-if (getPreprocessedType(Id) != TY_INVALID) {
-  P.push_back(phases::Preprocess);
-}
-
-if (getPrecompiledType(Id) != TY_INVALID) {
-  P.push_back(phases::Precompile);
-}
-
-if (!onlyPrecompileType(Id)) {
-  if (!onlyAssembleType(Id)) {
-P.push_back(phases::Compile);
-P.push_back(phases::Backend);
-  }
-  P.push_back(phases::Assemble);
-}
-  }
-
-  if (!onlyPrecompileType(Id)) {
-P.push_back(phases::Link);
-  }
-
-  // Check that the static Phase list matches.
-  // TODO: These will be deleted.
-  const llvm::SmallVectorImpl &Phases = getInfo(Id).Phases;
-  assert(Phases.size() == P.size() &&
- std::equal(Phases.begin(), Phases.end(), P.begin()) &&
- "Invalid phase or size");
-
-  // TODO: This function is still being used to assert that the phase list in
-  //   Types.def is correct. Everything above this comment will be removed
-  //   in a subsequent NFC commit.
-  P = Phases;
+  P = getInfo(Id).Phases;
   assert(0 < P.size() && "Not enough phases in list");
   assert(P.size() <= phases::MaxNumberOfPhases && "Too many phases in list");
 }
Index: clang/include/clang/Driver/Types.def
===
--- clang/include/clang/Driver/Types.def
+++ clang/include/clang/Driver/Types.def
@@ -30,15 +30,20 @@
 // of this type, or null if unspecified.
 
 // The fifth value is a string containing option flags. Valid values:
-//  a - The type should only be assembled.
-//  p - The type should only be precompiled.
 //  u - The type can be user specified (with -x).
-//  m - Precompiling this type produces a module file.
-//  A - The type's temporary suffix should be appended when generating
-//  outputs of this type.
 
 // The sixth value is a variadic list of phases for each type. Eventually the
 // options flag string will be replaced with this variadic list.
+// Some of the options in Flags have been removed, so far those are:
+//  a - The type should only be assembled: Now, check that Phases contains
+//  phases::Assemble but not phases::Compile or phases::Backend.
+//  p - The type should only be precompiled: Now, check that Phases contains
+//  phases::Precompile but that Flags does not contain 'm'.
+//  m - Precompiling this type produces a module file: Now, check
+//  isPrepeocessedModuleType.
+//  A - The type's temporary suffix should be appended when generating
+//  outputs of this type: Now, check appendSuffixForType.
+
 
 // C family source language (with and without preprocessing).
 TYPE("cpp-output",   PP_C, INVALID, "i", "u", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
@@ -61,22 +66,22 @@
 TYPE("renderscript",

[PATCH] D65176: [NFC][clang] Refactor getCompilationPhases()+Types.def step 2.

2019-07-24 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi updated this revision to Diff 211652.
plotfi added a comment.

Removing 'A'


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65176/new/

https://reviews.llvm.org/D65176

Files:
  clang/include/clang/Driver/Types.def
  clang/lib/Driver/Types.cpp

Index: clang/lib/Driver/Types.cpp
===
--- clang/lib/Driver/Types.cpp
+++ clang/lib/Driver/Types.cpp
@@ -42,11 +42,19 @@
 }
 
 types::ID types::getPreprocessedType(ID Id) {
-  return getInfo(Id).PreprocessedType;
+  ID PPT = getInfo(Id).PreprocessedType;
+  assert((llvm::is_contained(getInfo(Id).Phases, phases::Preprocess) !=
+  (PPT == TY_INVALID)) &&
+ "Unexpected Preprocess Type.");
+  return PPT;
+}
+
+static bool isPrepeocessedModuleType(ID Id) {
+  return Id == TY_CXXModule || Id == TY_PP_CXXModule;
 }
 
 types::ID types::getPrecompiledType(ID Id) {
-  if (strchr(getInfo(Id).Flags, 'm'))
+  if (isPrepeocessedModuleType(Id))
 return TY_ModuleFile;
   if (onlyPrecompileType(Id))
 return TY_PCH;
@@ -71,11 +79,14 @@
 }
 
 bool types::onlyAssembleType(ID Id) {
-  return strchr(getInfo(Id).Flags, 'a');
+  return llvm::is_contained(getInfo(Id).Phases, phases::Assemble) &&
+ !llvm::is_contained(getInfo(Id).Phases, phases::Compile) &&
+ !llvm::is_contained(getInfo(Id).Phases, phases::Backend);
 }
 
 bool types::onlyPrecompileType(ID Id) {
-  return strchr(getInfo(Id).Flags, 'p');
+  return llvm::is_contained(getInfo(Id).Phases, phases::Precompile) &&
+ !isPrepeocessedModuleType(Id);
 }
 
 bool types::canTypeBeUserSpecified(ID Id) {
@@ -83,7 +94,8 @@
 }
 
 bool types::appendSuffixForType(ID Id) {
-  return strchr(getInfo(Id).Flags, 'A');
+  return Id == TY_PCH || Id == TY_dSYM || Id == TY_CUDA_FATBIN ||
+ Id == TY_HIP_FATBIN;
 }
 
 bool types::canLipoType(ID Id) {
@@ -269,39 +281,7 @@
 // FIXME: The list is now in Types.def but for now this function will verify
 //the old behavior and a subsequent change will delete most of the body.
 void types::getCompilationPhases(ID Id, llvm::SmallVectorImpl &P) {
-  if (Id != TY_Object) {
-if (getPreprocessedType(Id) != TY_INVALID) {
-  P.push_back(phases::Preprocess);
-}
-
-if (getPrecompiledType(Id) != TY_INVALID) {
-  P.push_back(phases::Precompile);
-}
-
-if (!onlyPrecompileType(Id)) {
-  if (!onlyAssembleType(Id)) {
-P.push_back(phases::Compile);
-P.push_back(phases::Backend);
-  }
-  P.push_back(phases::Assemble);
-}
-  }
-
-  if (!onlyPrecompileType(Id)) {
-P.push_back(phases::Link);
-  }
-
-  // Check that the static Phase list matches.
-  // TODO: These will be deleted.
-  const llvm::SmallVectorImpl &Phases = getInfo(Id).Phases;
-  assert(Phases.size() == P.size() &&
- std::equal(Phases.begin(), Phases.end(), P.begin()) &&
- "Invalid phase or size");
-
-  // TODO: This function is still being used to assert that the phase list in
-  //   Types.def is correct. Everything above this comment will be removed
-  //   in a subsequent NFC commit.
-  P = Phases;
+  P = getInfo(Id).Phases;
   assert(0 < P.size() && "Not enough phases in list");
   assert(P.size() <= phases::MaxNumberOfPhases && "Too many phases in list");
 }
Index: clang/include/clang/Driver/Types.def
===
--- clang/include/clang/Driver/Types.def
+++ clang/include/clang/Driver/Types.def
@@ -30,15 +30,20 @@
 // of this type, or null if unspecified.
 
 // The fifth value is a string containing option flags. Valid values:
-//  a - The type should only be assembled.
-//  p - The type should only be precompiled.
 //  u - The type can be user specified (with -x).
-//  m - Precompiling this type produces a module file.
-//  A - The type's temporary suffix should be appended when generating
-//  outputs of this type.
 
 // The sixth value is a variadic list of phases for each type. Eventually the
 // options flag string will be replaced with this variadic list.
+// Some of the options in Flags have been removed, so far those are:
+//  a - The type should only be assembled: Now, check that Phases contains
+//  phases::Assemble but not phases::Compile or phases::Backend.
+//  p - The type should only be precompiled: Now, check that Phases contains
+//  phases::Precompile but that Flags does not contain 'm'.
+//  m - Precompiling this type produces a module file: Now, check
+//  isPrepeocessedModuleType.
+//  A - The type's temporary suffix should be appended when generating
+//  outputs of this type: Now, check appendSuffixForType.
+
 
 // C family source language (with and without preprocessing).
 TYPE("cpp-output",   PP_C, INVALID, "i", "u", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
@@ -61,22 +66,22 @@
 TYPE("renderscript", RenderScript, PP_C,"rs",

[PATCH] D65176: [NFC][clang] Refactor getCompilationPhases()+Types.def step 2.

2019-07-24 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi marked 4 inline comments as done.
plotfi added inline comments.



Comment at: clang/include/clang/Driver/Types.def:39-45
+// Some of the options in Flags have been removed, so far those are:
+//  a - The type should only be assembled: Now, check that Phases contains
+//  phases::Assemble but not phases::Compile or phases::Backend.
+//  p - The type should only be precompiled: Now, check that Phases contains
+//  phases::Precompile but that Flags does not contain 'm'.
+//  m - Precompiling this type produces a module file: Now, check that
+//  isPrepeocessedModuleType.

aaron.ballman wrote:
> compnerd wrote:
> > aaron.ballman wrote:
> > > Why should we document the removed flags, since users cannot write them 
> > > anyway?
> > Actually, that makes sense to me.  The reasoning for it (and the key thing 
> > to note about the documentation) is that it helps downstream forks as it 
> > indicates how to migrate.  Now, if you believe that this bit of 
> > functionality is unlikely to be used, thats a different story.  But, I 
> > don't think that it hurts to have the documentation in the commit message 
> > instead.
> Okay, that makes sense to me. Thank you for the explanation!
Yeah I just wanted a heads up for anyone downstream or anyone trying to update 
this table. Unfortunately I dont really understand the concept behind "user 
specified" types here. I assume it means  things like clang -xc++ or something 
like that. I will move this comment into the  commit message. Thanks!


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65176/new/

https://reviews.llvm.org/D65176



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


[PATCH] D65176: [NFC][clang] Refactor getCompilationPhases()+Types.def step 2.

2019-07-25 Thread Puyan Lotfi via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL367063: [NFC][clang] Refactor 
getCompilationPhases()+Types.def step 2. (authored by zer0, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D65176?vs=211652&id=211832#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65176/new/

https://reviews.llvm.org/D65176

Files:
  cfe/trunk/include/clang/Driver/Types.def
  cfe/trunk/lib/Driver/Types.cpp

Index: cfe/trunk/include/clang/Driver/Types.def
===
--- cfe/trunk/include/clang/Driver/Types.def
+++ cfe/trunk/include/clang/Driver/Types.def
@@ -30,15 +30,12 @@
 // of this type, or null if unspecified.
 
 // The fifth value is a string containing option flags. Valid values:
-//  a - The type should only be assembled.
-//  p - The type should only be precompiled.
 //  u - The type can be user specified (with -x).
-//  m - Precompiling this type produces a module file.
-//  A - The type's temporary suffix should be appended when generating
-//  outputs of this type.
 
 // The sixth value is a variadic list of phases for each type. Eventually the
 // options flag string will be replaced with this variadic list.
+// Most of the options in Flags have been removed in favor of subsuming their
+// meaning from the phases list.
 
 // C family source language (with and without preprocessing).
 TYPE("cpp-output",   PP_C, INVALID, "i", "u", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
@@ -61,22 +58,22 @@
 TYPE("renderscript", RenderScript, PP_C,"rs","u", phases::Preprocess, phases::Compile, phases::Backend, phases::Assemble, phases::Link)
 
 // C family input files to precompile.
-TYPE("c-header-cpp-output",  PP_CHeader,   INVALID, "i", "p",  phases::Precompile)
-TYPE("c-header", CHeader,  PP_CHeader,  "h", "pu", phases::Preprocess, phases::Precompile)
-TYPE("cl-header",CLHeader, PP_CHeader,  "h", "pu", phases::Preprocess, phases::Precompile)
-TYPE("objective-c-header-cpp-output", PP_ObjCHeader, INVALID,   "mi","p",  phases::Precompile)
-TYPE("objective-c-header",   ObjCHeader,   PP_ObjCHeader,   "h", "pu", phases::Preprocess, phases::Precompile)
-TYPE("c++-header-cpp-output",PP_CXXHeader, INVALID, "ii","p",  phases::Precompile)
-TYPE("c++-header",   CXXHeader,PP_CXXHeader,"hh","pu", phases::Preprocess, phases::Precompile)
-TYPE("objective-c++-header-cpp-output", PP_ObjCXXHeader, INVALID, "mii", "p",  phases::Precompile)
-TYPE("objective-c++-header", ObjCXXHeader, PP_ObjCXXHeader, "h", "pu", phases::Preprocess, phases::Precompile)
-TYPE("c++-module",   CXXModule,PP_CXXModule,"cppm",  "mu", phases::Preprocess, phases::Precompile, phases::Compile, phases::Backend, phases::Assemble, phases::Link)
-TYPE("c++-module-cpp-output",PP_CXXModule, INVALID, "iim",   "m",  phases::Precompile, phases::Compile, phases::Backend, phases::Assemble, phases::Link)
+TYPE("c-header-cpp-output",  PP_CHeader,   INVALID, "i", "",   phases::Precompile)
+TYPE("c-header", CHeader,  PP_CHeader,  "h", "u",  phases::Preprocess, phases::Precompile)
+TYPE("cl-header",CLHeader, PP_CHeader,  "h", "u",  phases::Preprocess, phases::Precompile)
+TYPE("objective-c-header-cpp-output", PP_ObjCHeader, INVALID,   "mi","",   phases::Precompile)
+TYPE("objective-c-header",   ObjCHeader,   PP_ObjCHeader,   "h", "u",  phases::Preprocess, phases::Precompile)
+TYPE("c++-header-cpp-output",PP_CXXHeader, INVALID, "ii","",   phases::Precompile)
+TYPE("c++-header",   CXXHeader,PP_CXXHeader,"hh","u",  phases::Preprocess, phases::Precompile)
+TYPE("objective-c++-header-cpp-output", PP_ObjCXXHeader, INVALID, "mii", "",   phases::Precompile)
+TYPE("objective-c++-header", ObjCXXHeader, PP_ObjCXXHeader, "h", "u",  phases::Preprocess, phases::Precompile)
+TYPE("c++-module",   CXXModule,PP_CXXModule,"cppm",  "u",  phases::Preprocess, phases::Precompile, phases::Compile, phases::Backend, phases::Assemble, phases::Link)
+TYPE("c++-module-cpp-output",PP_CXXModule, INVALID, "iim",   "",   phases::Precompile, phases::Compile, phases::Backend, phases::Assemble, phases::Link)
 
 // Other languages.
 TYPE("ada",  Ada,  INVALID, nullptr, "u",  phases::Compile, phases::Backend, phases::Assemble, phases::Link)
-TYPE("assembler",PP_Asm,   INVALID, "s", "au", phases::Assemble, phases::Link)
-TYPE("assembler-with-cpp",   Asm,  PP_Asm,  "S", "au", phases::Preprocess, phases::Assemb

[PATCH] D65308: [NFC][clang] Refactor getCompilationPhases()+Types.def step 3.

2019-07-25 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi created this revision.
plotfi added reviewers: compnerd, aaron.ballman.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

New improved 'u'-less clang.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D65308

Files:
  clang/include/clang/Driver/Types.def
  clang/include/clang/Driver/Types.h
  clang/lib/Driver/Types.cpp

Index: clang/lib/Driver/Types.cpp
===
--- clang/lib/Driver/Types.cpp
+++ clang/lib/Driver/Types.cpp
@@ -18,15 +18,14 @@
 
 struct TypeInfo {
   const char *Name;
-  const char *Flags;
   const char *TempSuffix;
   ID PreprocessedType;
   const llvm::SmallVector Phases;
 };
 
 static const TypeInfo TypeInfos[] = {
-#define TYPE(NAME, ID, PP_TYPE, TEMP_SUFFIX, FLAGS, ...) \
-  { NAME, FLAGS, TEMP_SUFFIX, TY_##PP_TYPE, { __VA_ARGS__ }, },
+#define TYPE(NAME, ID, PP_TYPE, TEMP_SUFFIX, ...) \
+  { NAME, TEMP_SUFFIX, TY_##PP_TYPE, { __VA_ARGS__ }, },
 #include "clang/Driver/Types.def"
 #undef TYPE
 };
@@ -90,7 +89,28 @@
 }
 
 bool types::canTypeBeUserSpecified(ID Id) {
-  return strchr(getInfo(Id).Flags, 'u');
+// clang-format off
+  return !(Id == TY_CUDA_DEVICE ||
+   Id == TY_HIP_DEVICE ||
+   Id == TY_PP_CHeader ||
+   Id == TY_PP_ObjCHeader ||
+   Id == TY_PP_CXXHeader ||
+   Id == TY_ObjCXXHeader ||
+   Id == TY_PP_CXXModule ||
+   Id == TY_LTO_IR ||
+   Id == TY_LTO_BC ||
+   Id == TY_Plist ||
+   Id == TY_RewrittenObjC ||
+   Id == TY_RewrittenLegacyObjC ||
+   Id == TY_Remap ||
+   Id == TY_PCH ||
+   Id == TY_Object ||
+   Id == TY_Image ||
+   Id == TY_dSYM ||
+   Id == TY_Dependencies ||
+   Id == TY_CUDA_FATBIN ||
+   Id == TY_HIP_FATBIN);
+// clang-format on
 }
 
 bool types::appendSuffixForType(ID Id) {
Index: clang/include/clang/Driver/Types.h
===
--- clang/include/clang/Driver/Types.h
+++ clang/include/clang/Driver/Types.h
@@ -20,7 +20,7 @@
 namespace types {
   enum ID {
 TY_INVALID,
-#define TYPE(NAME, ID, PP_TYPE, TEMP_SUFFIX, FLAGS, ...) TY_##ID,
+#define TYPE(NAME, ID, PP_TYPE, TEMP_SUFFIX, ...) TY_##ID,
 #include "clang/Driver/Types.def"
 #undef TYPE
 TY_LAST
Index: clang/include/clang/Driver/Types.def
===
--- clang/include/clang/Driver/Types.def
+++ clang/include/clang/Driver/Types.def
@@ -29,76 +29,73 @@
 // The fourth value is the suffix to use when creating temporary files
 // of this type, or null if unspecified.
 
-// The fifth value is a string containing option flags. Valid values:
-//  u - The type can be user specified (with -x).
-
-// The sixth value is a variadic list of phases for each type. Eventually the
+// The final value is a variadic list of phases for each type. Eventually the
 // options flag string will be replaced with this variadic list.
 // Most of the options in Flags have been removed in favor of subsuming their
 // meaning from the phases list.
 
 // C family source language (with and without preprocessing).
-TYPE("cpp-output",   PP_C, INVALID, "i", "u", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
-TYPE("c",C,PP_C,"c", "u", phases::Preprocess, phases::Compile, phases::Backend, phases::Assemble, phases::Link)
-TYPE("cl",   CL,   PP_C,"cl","u", phases::Preprocess, phases::Compile, phases::Backend, phases::Assemble, phases::Link)
-TYPE("cuda-cpp-output",  PP_CUDA,  INVALID, "cui",   "u", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
-TYPE("cuda", CUDA, PP_CUDA, "cu","u", phases::Preprocess, phases::Compile, phases::Backend, phases::Assemble, phases::Link)
-TYPE("cuda", CUDA_DEVICE,  PP_CUDA, "cu","" , phases::Preprocess, phases::Compile, phases::Backend, phases::Assemble, phases::Link)
-TYPE("hip-cpp-output",   PP_HIP,   INVALID, "cui",   "u", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
-TYPE("hip",  HIP,  PP_HIP,  "cu","u", phases::Preprocess, phases::Compile, phases::Backend, phases::Assemble, phases::Link)
-TYPE("hip",  HIP_DEVICE,   PP_HIP,  "cu","" , phases::Preprocess, phases::Compile, phases::Backend, phases::Assemble, phases::Link)
-TYPE("objective-c-cpp-output",   PP_ObjC,  INVALID, "mi","u", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
-TYPE("objc-cpp-output",  PP_ObjC_Alias, INVALID,"mi","u", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
-TYPE("objective-c",  ObjC, PP_ObjC, "m"

[PATCH] D65308: [NFC][clang] Refactor getCompilationPhases()+Types.def step 3.

2019-07-26 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi updated this revision to Diff 211981.
plotfi marked an inline comment as done.
plotfi added a comment.

addressing @compnerd 's feedback


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65308/new/

https://reviews.llvm.org/D65308

Files:
  clang/include/clang/Driver/Types.def
  clang/include/clang/Driver/Types.h
  clang/lib/Driver/Types.cpp

Index: clang/lib/Driver/Types.cpp
===
--- clang/lib/Driver/Types.cpp
+++ clang/lib/Driver/Types.cpp
@@ -18,15 +18,14 @@
 
 struct TypeInfo {
   const char *Name;
-  const char *Flags;
   const char *TempSuffix;
   ID PreprocessedType;
   const llvm::SmallVector Phases;
 };
 
 static const TypeInfo TypeInfos[] = {
-#define TYPE(NAME, ID, PP_TYPE, TEMP_SUFFIX, FLAGS, ...) \
-  { NAME, FLAGS, TEMP_SUFFIX, TY_##PP_TYPE, { __VA_ARGS__ }, },
+#define TYPE(NAME, ID, PP_TYPE, TEMP_SUFFIX, ...) \
+  { NAME, TEMP_SUFFIX, TY_##PP_TYPE, { __VA_ARGS__ }, },
 #include "clang/Driver/Types.def"
 #undef TYPE
 };
@@ -90,7 +89,15 @@
 }
 
 bool types::canTypeBeUserSpecified(ID Id) {
-  return strchr(getInfo(Id).Flags, 'u');
+  static const clang::driver::types::ID kStaticLangageTypes[] = {
+  TY_CUDA_DEVICE,   TY_HIP_DEVICE,TY_PP_CHeader,
+  TY_PP_ObjCHeader, TY_PP_CXXHeader,  TY_ObjCXXHeader,
+  TY_PP_CXXModule,  TY_LTO_IR,TY_LTO_BC,
+  TY_Plist, TY_RewrittenObjC, TY_RewrittenLegacyObjC,
+  TY_Remap, TY_PCH,   TY_Object,
+  TY_Image, TY_dSYM,  TY_Dependencies,
+  TY_CUDA_FATBIN,   TY_HIP_FATBIN};
+  return !llvm::is_contained(kStaticLangageTypes, Id);
 }
 
 bool types::appendSuffixForType(ID Id) {
Index: clang/include/clang/Driver/Types.h
===
--- clang/include/clang/Driver/Types.h
+++ clang/include/clang/Driver/Types.h
@@ -20,7 +20,7 @@
 namespace types {
   enum ID {
 TY_INVALID,
-#define TYPE(NAME, ID, PP_TYPE, TEMP_SUFFIX, FLAGS, ...) TY_##ID,
+#define TYPE(NAME, ID, PP_TYPE, TEMP_SUFFIX, ...) TY_##ID,
 #include "clang/Driver/Types.def"
 #undef TYPE
 TY_LAST
Index: clang/include/clang/Driver/Types.def
===
--- clang/include/clang/Driver/Types.def
+++ clang/include/clang/Driver/Types.def
@@ -29,76 +29,73 @@
 // The fourth value is the suffix to use when creating temporary files
 // of this type, or null if unspecified.
 
-// The fifth value is a string containing option flags. Valid values:
-//  u - The type can be user specified (with -x).
-
-// The sixth value is a variadic list of phases for each type. Eventually the
+// The final value is a variadic list of phases for each type. Eventually the
 // options flag string will be replaced with this variadic list.
 // Most of the options in Flags have been removed in favor of subsuming their
 // meaning from the phases list.
 
 // C family source language (with and without preprocessing).
-TYPE("cpp-output",   PP_C, INVALID, "i", "u", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
-TYPE("c",C,PP_C,"c", "u", phases::Preprocess, phases::Compile, phases::Backend, phases::Assemble, phases::Link)
-TYPE("cl",   CL,   PP_C,"cl","u", phases::Preprocess, phases::Compile, phases::Backend, phases::Assemble, phases::Link)
-TYPE("cuda-cpp-output",  PP_CUDA,  INVALID, "cui",   "u", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
-TYPE("cuda", CUDA, PP_CUDA, "cu","u", phases::Preprocess, phases::Compile, phases::Backend, phases::Assemble, phases::Link)
-TYPE("cuda", CUDA_DEVICE,  PP_CUDA, "cu","" , phases::Preprocess, phases::Compile, phases::Backend, phases::Assemble, phases::Link)
-TYPE("hip-cpp-output",   PP_HIP,   INVALID, "cui",   "u", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
-TYPE("hip",  HIP,  PP_HIP,  "cu","u", phases::Preprocess, phases::Compile, phases::Backend, phases::Assemble, phases::Link)
-TYPE("hip",  HIP_DEVICE,   PP_HIP,  "cu","" , phases::Preprocess, phases::Compile, phases::Backend, phases::Assemble, phases::Link)
-TYPE("objective-c-cpp-output",   PP_ObjC,  INVALID, "mi","u", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
-TYPE("objc-cpp-output",  PP_ObjC_Alias, INVALID,"mi","u", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
-TYPE("objective-c",  ObjC, PP_ObjC, "m", "u", phases::Preprocess, phases::Compile, phases::Backend, phases::Assemble, phases::Link)
-TYPE("c++-cpp-output",   PP_CXX,   INVALID, "ii","u", ph

[PATCH] D65308: [NFC][clang] Refactor getCompilationPhases()+Types.def step 3.

2019-07-30 Thread Puyan Lotfi via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL367345: [NFC][clang] Refactor 
getCompilationPhases()+Types.def step 3. (authored by zer0, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D65308?vs=211981&id=212405#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65308/new/

https://reviews.llvm.org/D65308

Files:
  cfe/trunk/include/clang/Driver/Types.def
  cfe/trunk/include/clang/Driver/Types.h
  cfe/trunk/lib/Driver/Types.cpp

Index: cfe/trunk/include/clang/Driver/Types.def
===
--- cfe/trunk/include/clang/Driver/Types.def
+++ cfe/trunk/include/clang/Driver/Types.def
@@ -29,76 +29,73 @@
 // The fourth value is the suffix to use when creating temporary files
 // of this type, or null if unspecified.
 
-// The fifth value is a string containing option flags. Valid values:
-//  u - The type can be user specified (with -x).
-
-// The sixth value is a variadic list of phases for each type. Eventually the
+// The final value is a variadic list of phases for each type. Eventually the
 // options flag string will be replaced with this variadic list.
 // Most of the options in Flags have been removed in favor of subsuming their
 // meaning from the phases list.
 
 // C family source language (with and without preprocessing).
-TYPE("cpp-output",   PP_C, INVALID, "i", "u", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
-TYPE("c",C,PP_C,"c", "u", phases::Preprocess, phases::Compile, phases::Backend, phases::Assemble, phases::Link)
-TYPE("cl",   CL,   PP_C,"cl","u", phases::Preprocess, phases::Compile, phases::Backend, phases::Assemble, phases::Link)
-TYPE("cuda-cpp-output",  PP_CUDA,  INVALID, "cui",   "u", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
-TYPE("cuda", CUDA, PP_CUDA, "cu","u", phases::Preprocess, phases::Compile, phases::Backend, phases::Assemble, phases::Link)
-TYPE("cuda", CUDA_DEVICE,  PP_CUDA, "cu","" , phases::Preprocess, phases::Compile, phases::Backend, phases::Assemble, phases::Link)
-TYPE("hip-cpp-output",   PP_HIP,   INVALID, "cui",   "u", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
-TYPE("hip",  HIP,  PP_HIP,  "cu","u", phases::Preprocess, phases::Compile, phases::Backend, phases::Assemble, phases::Link)
-TYPE("hip",  HIP_DEVICE,   PP_HIP,  "cu","" , phases::Preprocess, phases::Compile, phases::Backend, phases::Assemble, phases::Link)
-TYPE("objective-c-cpp-output",   PP_ObjC,  INVALID, "mi","u", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
-TYPE("objc-cpp-output",  PP_ObjC_Alias, INVALID,"mi","u", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
-TYPE("objective-c",  ObjC, PP_ObjC, "m", "u", phases::Preprocess, phases::Compile, phases::Backend, phases::Assemble, phases::Link)
-TYPE("c++-cpp-output",   PP_CXX,   INVALID, "ii","u", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
-TYPE("c++",  CXX,  PP_CXX,  "cpp",   "u", phases::Preprocess, phases::Compile, phases::Backend, phases::Assemble, phases::Link)
-TYPE("objective-c++-cpp-output", PP_ObjCXX,INVALID, "mii",   "u", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
-TYPE("objc++-cpp-output",PP_ObjCXX_Alias, INVALID,  "mii",   "u", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
-TYPE("objective-c++",ObjCXX,   PP_ObjCXX,   "mm","u", phases::Preprocess, phases::Compile, phases::Backend, phases::Assemble, phases::Link)
-TYPE("renderscript", RenderScript, PP_C,"rs","u", phases::Preprocess, phases::Compile, phases::Backend, phases::Assemble, phases::Link)
+TYPE("cpp-output",   PP_C, INVALID, "i",  phases::Compile, phases::Backend, phases::Assemble, phases::Link)
+TYPE("c",C,PP_C,"c",  phases::Preprocess, phases::Compile, phases::Backend, phases::Assemble, phases::Link)
+TYPE("cl",   CL,   PP_C,"cl", phases::Preprocess, phases::Compile, phases::Backend, phases::Assemble, phases::Link)
+TYPE("cuda-cpp-output",  PP_CUDA,  INVALID, "cui",phases::Compile, phases::Backend, phases::Assemble, phases::Link)
+TYPE("cuda", CUDA, PP_CUDA, "cu", phases::Preprocess, phases::Compile, ph

[PATCH] D65308: [NFC][clang] Refactor getCompilationPhases()+Types.def step 3.

2019-07-31 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi updated this revision to Diff 212634.
plotfi added a comment.

trying to re-land, changing TY_ObjCXXHeader to  TY_PP_ObjCXXHeader,


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65308/new/

https://reviews.llvm.org/D65308

Files:
  clang/include/clang/Driver/Types.def
  clang/include/clang/Driver/Types.h
  clang/lib/Driver/Types.cpp

Index: clang/lib/Driver/Types.cpp
===
--- clang/lib/Driver/Types.cpp
+++ clang/lib/Driver/Types.cpp
@@ -18,15 +18,14 @@
 
 struct TypeInfo {
   const char *Name;
-  const char *Flags;
   const char *TempSuffix;
   ID PreprocessedType;
   const llvm::SmallVector Phases;
 };
 
 static const TypeInfo TypeInfos[] = {
-#define TYPE(NAME, ID, PP_TYPE, TEMP_SUFFIX, FLAGS, ...) \
-  { NAME, FLAGS, TEMP_SUFFIX, TY_##PP_TYPE, { __VA_ARGS__ }, },
+#define TYPE(NAME, ID, PP_TYPE, TEMP_SUFFIX, ...) \
+  { NAME, TEMP_SUFFIX, TY_##PP_TYPE, { __VA_ARGS__ }, },
 #include "clang/Driver/Types.def"
 #undef TYPE
 };
@@ -90,7 +89,15 @@
 }
 
 bool types::canTypeBeUserSpecified(ID Id) {
-  return strchr(getInfo(Id).Flags, 'u');
+  static const clang::driver::types::ID kStaticLangageTypes[] = {
+  TY_CUDA_DEVICE,   TY_HIP_DEVICE,TY_PP_CHeader,
+  TY_PP_ObjCHeader, TY_PP_CXXHeader,  TY_PP_ObjCXXHeader,
+  TY_PP_CXXModule,  TY_LTO_IR,TY_LTO_BC,
+  TY_Plist, TY_RewrittenObjC, TY_RewrittenLegacyObjC,
+  TY_Remap, TY_PCH,   TY_Object,
+  TY_Image, TY_dSYM,  TY_Dependencies,
+  TY_CUDA_FATBIN,   TY_HIP_FATBIN};
+  return !llvm::is_contained(kStaticLangageTypes, Id);
 }
 
 bool types::appendSuffixForType(ID Id) {
Index: clang/include/clang/Driver/Types.h
===
--- clang/include/clang/Driver/Types.h
+++ clang/include/clang/Driver/Types.h
@@ -20,7 +20,7 @@
 namespace types {
   enum ID {
 TY_INVALID,
-#define TYPE(NAME, ID, PP_TYPE, TEMP_SUFFIX, FLAGS, ...) TY_##ID,
+#define TYPE(NAME, ID, PP_TYPE, TEMP_SUFFIX, ...) TY_##ID,
 #include "clang/Driver/Types.def"
 #undef TYPE
 TY_LAST
Index: clang/include/clang/Driver/Types.def
===
--- clang/include/clang/Driver/Types.def
+++ clang/include/clang/Driver/Types.def
@@ -29,76 +29,73 @@
 // The fourth value is the suffix to use when creating temporary files
 // of this type, or null if unspecified.
 
-// The fifth value is a string containing option flags. Valid values:
-//  u - The type can be user specified (with -x).
-
-// The sixth value is a variadic list of phases for each type. Eventually the
+// The final value is a variadic list of phases for each type. Eventually the
 // options flag string will be replaced with this variadic list.
 // Most of the options in Flags have been removed in favor of subsuming their
 // meaning from the phases list.
 
 // C family source language (with and without preprocessing).
-TYPE("cpp-output",   PP_C, INVALID, "i", "u", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
-TYPE("c",C,PP_C,"c", "u", phases::Preprocess, phases::Compile, phases::Backend, phases::Assemble, phases::Link)
-TYPE("cl",   CL,   PP_C,"cl","u", phases::Preprocess, phases::Compile, phases::Backend, phases::Assemble, phases::Link)
-TYPE("cuda-cpp-output",  PP_CUDA,  INVALID, "cui",   "u", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
-TYPE("cuda", CUDA, PP_CUDA, "cu","u", phases::Preprocess, phases::Compile, phases::Backend, phases::Assemble, phases::Link)
-TYPE("cuda", CUDA_DEVICE,  PP_CUDA, "cu","" , phases::Preprocess, phases::Compile, phases::Backend, phases::Assemble, phases::Link)
-TYPE("hip-cpp-output",   PP_HIP,   INVALID, "cui",   "u", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
-TYPE("hip",  HIP,  PP_HIP,  "cu","u", phases::Preprocess, phases::Compile, phases::Backend, phases::Assemble, phases::Link)
-TYPE("hip",  HIP_DEVICE,   PP_HIP,  "cu","" , phases::Preprocess, phases::Compile, phases::Backend, phases::Assemble, phases::Link)
-TYPE("objective-c-cpp-output",   PP_ObjC,  INVALID, "mi","u", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
-TYPE("objc-cpp-output",  PP_ObjC_Alias, INVALID,"mi","u", phases::Compile, phases::Backend, phases::Assemble, phases::Link)
-TYPE("objective-c",  ObjC, PP_ObjC, "m", "u", phases::Preprocess, phases::Compile, phases::Backend, phases::Assemble, phases::Link)
-TYPE("c++-cpp-output",   PP_CXX,   INVALID, "ii","u", phase

[PATCH] D58418: [clang][DirectoryWatcher] Upstream DirectoryWatcher

2019-07-31 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi added a comment.

@jkorous DirectoryWatcherTests causes ninja check-clang to hang on my Ubuntu 
18.04 computer. check-clang will not finish and I am forced to killall -9 
DirectoryWatcherTests. My system has 40 threads and this repros on ext4 and 
btrfs.


Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D58418/new/

https://reviews.llvm.org/D58418



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


[PATCH] D65704: DirectoryWatcher::create: Adding better error handling.

2019-08-03 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi created this revision.
plotfi added reviewers: jkorous, compnerd.
Herald added subscribers: cfe-commits, dexonsmith.
Herald added a project: clang.

There are cases where the DirectoryWatcherTests just hang in a deadlock when 
there are inotify limits hit, with no error reporting. This patch is a first 
attempt to resolve these issues by bubbling up errors to the user.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D65704

Files:
  clang/include/clang/DirectoryWatcher/DirectoryWatcher.h
  clang/lib/DirectoryWatcher/default/DirectoryWatcher-not-implemented.cpp
  clang/lib/DirectoryWatcher/linux/DirectoryWatcher-linux.cpp
  clang/lib/DirectoryWatcher/mac/DirectoryWatcher-mac.cpp
  clang/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp

Index: clang/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp
===
--- clang/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp
+++ clang/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp
@@ -280,6 +280,10 @@
 TestConsumer.consume(Events, IsInitial);
   },
   /*waitForInitialSync=*/true);
+  if (!DW) {
+llvm::errs() << llvm::toString(DW.takeError()) << "\n";
+llvm_unreachable("DirectoryWatcher::create() FAILED!");
+  }
 
   checkEventualResultWithTimeout(TestConsumer);
 }
@@ -311,6 +315,10 @@
 TestConsumer.consume(Events, IsInitial);
   },
   /*waitForInitialSync=*/false);
+  if (!DW) {
+llvm::errs() << llvm::toString(DW.takeError()) << "\n";
+llvm_unreachable("DirectoryWatcher::create() FAILED!");
+  }
 
   checkEventualResultWithTimeout(TestConsumer);
 }
@@ -331,6 +339,10 @@
 TestConsumer.consume(Events, IsInitial);
   },
   /*waitForInitialSync=*/true);
+  if (!DW) {
+llvm::errs() << llvm::toString(DW.takeError()) << "\n";
+llvm_unreachable("DirectoryWatcher::create() FAILED!");
+  }
 
   fixture.addFile("a");
   fixture.addFile("b");
@@ -356,6 +368,10 @@
 TestConsumer.consume(Events, IsInitial);
   },
   /*waitForInitialSync=*/true);
+  if (!DW) {
+llvm::errs() << llvm::toString(DW.takeError()) << "\n";
+llvm_unreachable("DirectoryWatcher::create() FAILED!");
+  }
 
   // modify the file
   {
@@ -386,6 +402,10 @@
 TestConsumer.consume(Events, IsInitial);
   },
   /*waitForInitialSync=*/true);
+  if (!DW) {
+llvm::errs() << llvm::toString(DW.takeError()) << "\n";
+llvm_unreachable("DirectoryWatcher::create() FAILED!");
+  }
 
   fixture.deleteFile("a");
 
@@ -407,6 +427,10 @@
 TestConsumer.consume(Events, IsInitial);
   },
   /*waitForInitialSync=*/true);
+  if (!DW) {
+llvm::errs() << llvm::toString(DW.takeError()) << "\n";
+llvm_unreachable("DirectoryWatcher::create() FAILED!");
+  }
 
   remove_directories(fixture.TestWatchedDir);
 
@@ -427,7 +451,11 @@
   TestConsumer.consume(Events, IsInitial);
 },
 /*waitForInitialSync=*/true);
+if (!DW) {
+  llvm::errs() << llvm::toString(DW.takeError()) << "\n";
+  llvm_unreachable("DirectoryWatcher::create() FAILED!");
+}
   } // DW is destructed here.
 
   checkEventualResultWithTimeout(TestConsumer);
 }
\ No newline at end of file
Index: clang/lib/DirectoryWatcher/mac/DirectoryWatcher-mac.cpp
===
--- clang/lib/DirectoryWatcher/mac/DirectoryWatcher-mac.cpp
+++ clang/lib/DirectoryWatcher/mac/DirectoryWatcher-mac.cpp
@@ -11,6 +11,7 @@
 
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Error.h"
 #include "llvm/Support/Path.h"
 #include 
 
@@ -205,7 +206,7 @@
   FSEventStreamRelease(EventStream);
 }
 
-std::unique_ptr clang::DirectoryWatcher::create(
+llvm::Expected> clang::DirectoryWatcher::create(
 StringRef Path,
 std::function, bool)> Receiver,
 bool WaitForInitialSync) {
@@ -213,12 +214,15 @@
   dispatch_queue_create("DirectoryWatcher", DISPATCH_QUEUE_SERIAL);
 
   if (Path.empty())
-return nullptr;
+return llvm::make_error(
+std::string("Path.empty() error: ") + strerror(errno),
+llvm::inconvertibleErrorCode());
 
   auto EventStream = createFSEventStream(Path, Receiver, Queue);
-  if (!EventStream) {
-return nullptr;
-  }
+  if (!EventStream)
+return llvm::make_error(
+std::string("createFSEventStream() error: ") + strerror(errno),
+llvm::inconvertibleErrorCode());
 
   std::unique_ptr Result =
   llvm::make_unique(EventStream, Receiver, Path);
Index: clang/lib/DirectoryWatcher/linux/DirectoryWatcher-linux.cpp
===
--- clang/lib/DirectoryWatcher/linux/DirectoryWatcher-linux.cpp
+++ clang/lib/DirectoryWatcher/linux/DirectoryWatcher-linux.cpp
@@ -13,6 +13,7 @@
 #include "llvm/ADT/ScopeExit.h"
 #include "llvm/Support/AlignOf.h"
 #include "llvm/Support/Errno.h"
+#include "llvm/Support/Error.h"
 #include "llvm/Support/Mutex.

[PATCH] D65704: DirectoryWatcher::create: Adding better error handling.

2019-08-03 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi marked an inline comment as done.
plotfi added inline comments.



Comment at: clang/lib/DirectoryWatcher/linux/DirectoryWatcher-linux.cpp:32
 #include 
+#include 
 

This include should be removed. 


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65704/new/

https://reviews.llvm.org/D65704



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


[PATCH] D65704: DirectoryWatcher::create: Adding better error handling.

2019-08-03 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi updated this revision to Diff 213209.
plotfi added a comment.

Cleanup some stuff


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65704/new/

https://reviews.llvm.org/D65704

Files:
  clang/include/clang/DirectoryWatcher/DirectoryWatcher.h
  clang/lib/DirectoryWatcher/default/DirectoryWatcher-not-implemented.cpp
  clang/lib/DirectoryWatcher/linux/DirectoryWatcher-linux.cpp
  clang/lib/DirectoryWatcher/mac/DirectoryWatcher-mac.cpp
  clang/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp

Index: clang/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp
===
--- clang/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp
+++ clang/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp
@@ -280,8 +280,8 @@
 TestConsumer.consume(Events, IsInitial);
   },
   /*waitForInitialSync=*/true);
-
-  checkEventualResultWithTimeout(TestConsumer);
+  if (DW)
+checkEventualResultWithTimeout(TestConsumer);
 }
 
 TEST(DirectoryWatcherTest, InitialScanAsync) {
@@ -311,8 +311,8 @@
 TestConsumer.consume(Events, IsInitial);
   },
   /*waitForInitialSync=*/false);
-
-  checkEventualResultWithTimeout(TestConsumer);
+  if (DW)
+checkEventualResultWithTimeout(TestConsumer);
 }
 
 TEST(DirectoryWatcherTest, AddFiles) {
@@ -331,12 +331,12 @@
 TestConsumer.consume(Events, IsInitial);
   },
   /*waitForInitialSync=*/true);
-
-  fixture.addFile("a");
-  fixture.addFile("b");
-  fixture.addFile("c");
-
-  checkEventualResultWithTimeout(TestConsumer);
+  if (DW) {
+fixture.addFile("a");
+fixture.addFile("b");
+fixture.addFile("c");
+checkEventualResultWithTimeout(TestConsumer);
+  }
 }
 
 TEST(DirectoryWatcherTest, ModifyFile) {
@@ -356,17 +356,18 @@
 TestConsumer.consume(Events, IsInitial);
   },
   /*waitForInitialSync=*/true);
+  if (DW) {
+// modify the file
+{
+  std::error_code error;
+  llvm::raw_fd_ostream bStream(fixture.getPathInWatched("a"), error,
+   CD_OpenExisting);
+  assert(!error);
+  bStream << "foo";
+}
 
-  // modify the file
-  {
-std::error_code error;
-llvm::raw_fd_ostream bStream(fixture.getPathInWatched("a"), error,
- CD_OpenExisting);
-assert(!error);
-bStream << "foo";
+checkEventualResultWithTimeout(TestConsumer);
   }
-
-  checkEventualResultWithTimeout(TestConsumer);
 }
 
 TEST(DirectoryWatcherTest, DeleteFile) {
@@ -386,10 +387,10 @@
 TestConsumer.consume(Events, IsInitial);
   },
   /*waitForInitialSync=*/true);
-
-  fixture.deleteFile("a");
-
-  checkEventualResultWithTimeout(TestConsumer);
+  if (DW) {
+fixture.deleteFile("a");
+checkEventualResultWithTimeout(TestConsumer);
+  }
 }
 
 TEST(DirectoryWatcherTest, DeleteWatchedDir) {
@@ -407,10 +408,10 @@
 TestConsumer.consume(Events, IsInitial);
   },
   /*waitForInitialSync=*/true);
-
-  remove_directories(fixture.TestWatchedDir);
-
-  checkEventualResultWithTimeout(TestConsumer);
+  if (DW) {
+remove_directories(fixture.TestWatchedDir);
+checkEventualResultWithTimeout(TestConsumer);
+  }
 }
 
 TEST(DirectoryWatcherTest, InvalidatedWatcher) {
@@ -427,7 +428,9 @@
   TestConsumer.consume(Events, IsInitial);
 },
 /*waitForInitialSync=*/true);
+if (DW)
+  return;
   } // DW is destructed here.
 
   checkEventualResultWithTimeout(TestConsumer);
 }
\ No newline at end of file
Index: clang/lib/DirectoryWatcher/mac/DirectoryWatcher-mac.cpp
===
--- clang/lib/DirectoryWatcher/mac/DirectoryWatcher-mac.cpp
+++ clang/lib/DirectoryWatcher/mac/DirectoryWatcher-mac.cpp
@@ -11,6 +11,7 @@
 
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Error.h"
 #include "llvm/Support/Path.h"
 #include 
 
@@ -205,7 +206,7 @@
   FSEventStreamRelease(EventStream);
 }
 
-std::unique_ptr clang::DirectoryWatcher::create(
+llvm::Expected> clang::DirectoryWatcher::create(
 StringRef Path,
 std::function, bool)> Receiver,
 bool WaitForInitialSync) {
@@ -213,12 +214,15 @@
   dispatch_queue_create("DirectoryWatcher", DISPATCH_QUEUE_SERIAL);
 
   if (Path.empty())
-return nullptr;
+return llvm::make_error(
+std::string("Path.empty() error: ") + strerror(errno),
+llvm::inconvertibleErrorCode());
 
   auto EventStream = createFSEventStream(Path, Receiver, Queue);
-  if (!EventStream) {
-return nullptr;
-  }
+  if (!EventStream)
+return llvm::make_error(
+std::string("createFSEventStream() error: ") + strerror(errno),
+llvm::inconvertibleErrorCode());
 
   std::unique_ptr Result =
   llvm::make_unique(EventStream, Receiver, Path);
Index: clang/lib/DirectoryWatcher/linux/DirectoryWatcher-linux.cpp
=

[PATCH] D65704: DirectoryWatcher::create: Adding better error handling.

2019-08-03 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi updated this revision to Diff 213218.
plotfi added a comment.

More cleanup


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65704/new/

https://reviews.llvm.org/D65704

Files:
  clang/include/clang/DirectoryWatcher/DirectoryWatcher.h
  clang/lib/DirectoryWatcher/default/DirectoryWatcher-not-implemented.cpp
  clang/lib/DirectoryWatcher/linux/DirectoryWatcher-linux.cpp
  clang/lib/DirectoryWatcher/mac/DirectoryWatcher-mac.cpp
  clang/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp

Index: clang/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp
===
--- clang/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp
+++ clang/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp
@@ -280,6 +280,7 @@
 TestConsumer.consume(Events, IsInitial);
   },
   /*waitForInitialSync=*/true);
+  if (!DW) return;
 
   checkEventualResultWithTimeout(TestConsumer);
 }
@@ -311,6 +312,7 @@
 TestConsumer.consume(Events, IsInitial);
   },
   /*waitForInitialSync=*/false);
+  if (!DW) return;
 
   checkEventualResultWithTimeout(TestConsumer);
 }
@@ -331,6 +333,7 @@
 TestConsumer.consume(Events, IsInitial);
   },
   /*waitForInitialSync=*/true);
+  if (!DW) return;
 
   fixture.addFile("a");
   fixture.addFile("b");
@@ -356,6 +359,7 @@
 TestConsumer.consume(Events, IsInitial);
   },
   /*waitForInitialSync=*/true);
+  if (!DW) return;
 
   // modify the file
   {
@@ -386,6 +390,7 @@
 TestConsumer.consume(Events, IsInitial);
   },
   /*waitForInitialSync=*/true);
+  if (!DW) return;
 
   fixture.deleteFile("a");
 
@@ -407,6 +412,7 @@
 TestConsumer.consume(Events, IsInitial);
   },
   /*waitForInitialSync=*/true);
+  if (!DW) return;
 
   remove_directories(fixture.TestWatchedDir);
 
@@ -427,7 +433,8 @@
   TestConsumer.consume(Events, IsInitial);
 },
 /*waitForInitialSync=*/true);
+if (!DW) return;
   } // DW is destructed here.
 
   checkEventualResultWithTimeout(TestConsumer);
 }
\ No newline at end of file
Index: clang/lib/DirectoryWatcher/mac/DirectoryWatcher-mac.cpp
===
--- clang/lib/DirectoryWatcher/mac/DirectoryWatcher-mac.cpp
+++ clang/lib/DirectoryWatcher/mac/DirectoryWatcher-mac.cpp
@@ -11,16 +11,13 @@
 
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Error.h"
 #include "llvm/Support/Path.h"
 #include 
 
 using namespace llvm;
 using namespace clang;
 
-static FSEventStreamRef createFSEventStream(
-StringRef Path,
-std::function, bool)>,
-dispatch_queue_t);
 static void stopFSEventStream(FSEventStreamRef);
 
 namespace {
@@ -149,12 +146,13 @@
   }
 }
 
-FSEventStreamRef createFSEventStream(
+llvm::Expected createFSEventStream(
 StringRef Path,
 std::function, bool)> Receiver,
 dispatch_queue_t Queue) {
   if (Path.empty())
-return nullptr;
+return llvm::make_error(
+std::string("Path.empty() error: "), llvm::inconvertibleErrorCode());
 
   CFMutableArrayRef PathsToWatch = [&]() {
 CFMutableArrayRef PathsToWatch =
@@ -205,7 +203,7 @@
   FSEventStreamRelease(EventStream);
 }
 
-std::unique_ptr clang::DirectoryWatcher::create(
+llvm::Expected> clang::DirectoryWatcher::create(
 StringRef Path,
 std::function, bool)> Receiver,
 bool WaitForInitialSync) {
@@ -213,12 +211,14 @@
   dispatch_queue_create("DirectoryWatcher", DISPATCH_QUEUE_SERIAL);
 
   if (Path.empty())
-return nullptr;
+return llvm::make_error(
+std::string("Path.empty() error: "), llvm::inconvertibleErrorCode());
+
+  auto EventStreamOrErr = createFSEventStream(Path, Receiver, Queue);
+  if (!EventStreamOrErr)
+return EventStreamOrErr.takeError();
+  auto EventStream = EventStreamOrErr.get();
 
-  auto EventStream = createFSEventStream(Path, Receiver, Queue);
-  if (!EventStream) {
-return nullptr;
-  }
 
   std::unique_ptr Result =
   llvm::make_unique(EventStream, Receiver, Path);
Index: clang/lib/DirectoryWatcher/linux/DirectoryWatcher-linux.cpp
===
--- clang/lib/DirectoryWatcher/linux/DirectoryWatcher-linux.cpp
+++ clang/lib/DirectoryWatcher/linux/DirectoryWatcher-linux.cpp
@@ -13,6 +13,7 @@
 #include "llvm/ADT/ScopeExit.h"
 #include "llvm/Support/AlignOf.h"
 #include "llvm/Support/Errno.h"
+#include "llvm/Support/Error.h"
 #include "llvm/Support/Mutex.h"
 #include "llvm/Support/Path.h"
 #include 
@@ -321,16 +322,19 @@
 
 } // namespace
 
-std::unique_ptr clang::DirectoryWatcher::create(
+llvm::Expected> clang::DirectoryWatcher::create(
 StringRef Path,
 std::function, bool)> Receiver,
 bool WaitForInitialSync) {
   if (Path.empty())
-return nullptr;
+return llvm::make_error(
+std::string("Path.empty() error: "), llvm::inconvertibleErrorCode());

[PATCH] D65704: DirectoryWatcher::create: Adding better error handling.

2019-08-03 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi added a comment.

In D65704#1613688 , @compnerd wrote:

> Rather than silently ignoring tests when the DirectoryWatcher isn't created, 
> can you please print an error message and exit with an error code to indicate 
> the test failed?


llvm::Expected requires consumption.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65704/new/

https://reviews.llvm.org/D65704



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


[PATCH] D65708: [NFC][DirectoryWatchedTests] Unlocking mutexes before signaling condition variable.

2019-08-03 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
plotfi added reviewers: compnerd, jkorous.
Herald added a subscriber: dexonsmith.

This should not affect actual behavior, but should pessimize the threading less 
by avoiding the situation where:

- mutex is still locked
- T1 notifies on condition variable
- T2 wakes to check mutex
- T2 sees mutex is still locked
- T2 waits
- T1 unlocks mutex
- T2 tries again, acquires mutex.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D65708

Files:
  clang/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp


Index: clang/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp
===
--- clang/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp
+++ clang/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp
@@ -132,8 +132,10 @@
 } else {
   ExpectedInitial.erase(It);
 }
-if (result())
+if (result()) {
+  L.unlock();
   ResultIsReady.notify_one();
+}
   }
 
   void consumeNonInitial(DirectoryWatcher::Event E) {
@@ -151,8 +153,10 @@
 } else {
   ExpectedNonInitial.erase(It);
 }
-if (result())
+if (result()) {
+  L.unlock();
   ResultIsReady.notify_one();
+}
   }
 
   // This method is used by DirectoryWatcher.


Index: clang/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp
===
--- clang/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp
+++ clang/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp
@@ -132,8 +132,10 @@
 } else {
   ExpectedInitial.erase(It);
 }
-if (result())
+if (result()) {
+  L.unlock();
   ResultIsReady.notify_one();
+}
   }
 
   void consumeNonInitial(DirectoryWatcher::Event E) {
@@ -151,8 +153,10 @@
 } else {
   ExpectedNonInitial.erase(It);
 }
-if (result())
+if (result()) {
+  L.unlock();
   ResultIsReady.notify_one();
+}
   }
 
   // This method is used by DirectoryWatcher.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D65704: DirectoryWatcher::create: Adding better error handling.

2019-08-03 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi updated this revision to Diff 213221.
plotfi added a comment.

Fix a linux typo


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65704/new/

https://reviews.llvm.org/D65704

Files:
  clang/include/clang/DirectoryWatcher/DirectoryWatcher.h
  clang/lib/DirectoryWatcher/default/DirectoryWatcher-not-implemented.cpp
  clang/lib/DirectoryWatcher/linux/DirectoryWatcher-linux.cpp
  clang/lib/DirectoryWatcher/mac/DirectoryWatcher-mac.cpp
  clang/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp

Index: clang/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp
===
--- clang/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp
+++ clang/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp
@@ -280,6 +280,7 @@
 TestConsumer.consume(Events, IsInitial);
   },
   /*waitForInitialSync=*/true);
+  if (!DW) return;
 
   checkEventualResultWithTimeout(TestConsumer);
 }
@@ -311,6 +312,7 @@
 TestConsumer.consume(Events, IsInitial);
   },
   /*waitForInitialSync=*/false);
+  if (!DW) return;
 
   checkEventualResultWithTimeout(TestConsumer);
 }
@@ -331,6 +333,7 @@
 TestConsumer.consume(Events, IsInitial);
   },
   /*waitForInitialSync=*/true);
+  if (!DW) return;
 
   fixture.addFile("a");
   fixture.addFile("b");
@@ -356,6 +359,7 @@
 TestConsumer.consume(Events, IsInitial);
   },
   /*waitForInitialSync=*/true);
+  if (!DW) return;
 
   // modify the file
   {
@@ -386,6 +390,7 @@
 TestConsumer.consume(Events, IsInitial);
   },
   /*waitForInitialSync=*/true);
+  if (!DW) return;
 
   fixture.deleteFile("a");
 
@@ -407,6 +412,7 @@
 TestConsumer.consume(Events, IsInitial);
   },
   /*waitForInitialSync=*/true);
+  if (!DW) return;
 
   remove_directories(fixture.TestWatchedDir);
 
@@ -427,7 +433,8 @@
   TestConsumer.consume(Events, IsInitial);
 },
 /*waitForInitialSync=*/true);
+if (!DW) return;
   } // DW is destructed here.
 
   checkEventualResultWithTimeout(TestConsumer);
 }
\ No newline at end of file
Index: clang/lib/DirectoryWatcher/mac/DirectoryWatcher-mac.cpp
===
--- clang/lib/DirectoryWatcher/mac/DirectoryWatcher-mac.cpp
+++ clang/lib/DirectoryWatcher/mac/DirectoryWatcher-mac.cpp
@@ -11,16 +11,13 @@
 
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Error.h"
 #include "llvm/Support/Path.h"
 #include 
 
 using namespace llvm;
 using namespace clang;
 
-static FSEventStreamRef createFSEventStream(
-StringRef Path,
-std::function, bool)>,
-dispatch_queue_t);
 static void stopFSEventStream(FSEventStreamRef);
 
 namespace {
@@ -131,12 +128,13 @@
   }
 }
 
-FSEventStreamRef createFSEventStream(
+llvm::Expected createFSEventStream(
 StringRef Path,
 std::function, bool)> Receiver,
 dispatch_queue_t Queue) {
   if (Path.empty())
-return nullptr;
+return llvm::make_error(
+std::string("Path.empty() error: "), llvm::inconvertibleErrorCode());
 
   CFMutableArrayRef PathsToWatch = [&]() {
 CFMutableArrayRef PathsToWatch =
@@ -187,7 +185,7 @@
   FSEventStreamRelease(EventStream);
 }
 
-std::unique_ptr clang::DirectoryWatcher::create(
+llvm::Expected> clang::DirectoryWatcher::create(
 StringRef Path,
 std::function, bool)> Receiver,
 bool WaitForInitialSync) {
@@ -195,12 +193,14 @@
   dispatch_queue_create("DirectoryWatcher", DISPATCH_QUEUE_SERIAL);
 
   if (Path.empty())
-return nullptr;
+return llvm::make_error(
+std::string("Path.empty() error: "), llvm::inconvertibleErrorCode());
+
+  auto EventStreamOrErr = createFSEventStream(Path, Receiver, Queue);
+  if (!EventStreamOrErr)
+return EventStreamOrErr.takeError();
+  auto EventStream = EventStreamOrErr.get();
 
-  auto EventStream = createFSEventStream(Path, Receiver, Queue);
-  if (!EventStream) {
-return nullptr;
-  }
 
   std::unique_ptr Result =
   llvm::make_unique(EventStream, Receiver, Path);
Index: clang/lib/DirectoryWatcher/linux/DirectoryWatcher-linux.cpp
===
--- clang/lib/DirectoryWatcher/linux/DirectoryWatcher-linux.cpp
+++ clang/lib/DirectoryWatcher/linux/DirectoryWatcher-linux.cpp
@@ -13,6 +13,7 @@
 #include "llvm/ADT/ScopeExit.h"
 #include "llvm/Support/AlignOf.h"
 #include "llvm/Support/Errno.h"
+#include "llvm/Support/Error.h"
 #include "llvm/Support/Mutex.h"
 #include "llvm/Support/Path.h"
 #include 
@@ -321,16 +322,19 @@
 
 } // namespace
 
-std::unique_ptr clang::DirectoryWatcher::create(
+llvm::Expected> clang::DirectoryWatcher::create(
 StringRef Path,
 std::function, bool)> Receiver,
 bool WaitForInitialSync) {
   if (Path.empty())
-return nullptr;
+return llvm::make_error(
+std::string("Path.empty() error: "), llvm::inconvertibleErrorCode(

[PATCH] D65704: DirectoryWatcher::create: Adding better error handling.

2019-08-05 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi marked 3 inline comments as done.
plotfi added inline comments.



Comment at: clang/include/clang/DirectoryWatcher/DirectoryWatcher.h:102
 
   /// Returns nullptr if \param Path doesn't exist or isn't a directory.
   /// Returns nullptr if OS kernel API told us we can't start watching. In such

jkorous wrote:
> Could you please update the comments?
Ahh, Yes. 



Comment at: clang/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp:283
   /*waitForInitialSync=*/true);
+  if (!DW) return;
 

jkorous wrote:
> jkorous wrote:
> > IIUC this is silently dropping errors. We should print the error here.
> Ah, my bad - I just took a better look at `Expected<>` and you're right.
Nah, the way llvm::Expected works is that if the error isn't consumed then it 
will blow up in the destructor. So if it is an error, returning will cause the 
destructor to crash the program and print the error implicitly. Very nice error 
handling mechanism you ask me :-) 


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65704/new/

https://reviews.llvm.org/D65704



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


[PATCH] D65708: [NFC][DirectoryWatchedTests] Unlocking mutexes before signaling condition variable.

2019-08-05 Thread Puyan Lotfi via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rL367968: [NFC][DirectoryWatchedTests] Unlocks mutexes before 
signaling condition variable (authored by zer0, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D65708?vs=213220&id=213510#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65708/new/

https://reviews.llvm.org/D65708

Files:
  cfe/trunk/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp


Index: cfe/trunk/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp
===
--- cfe/trunk/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp
+++ cfe/trunk/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp
@@ -132,8 +132,10 @@
 } else {
   ExpectedInitial.erase(It);
 }
-if (result())
+if (result()) {
+  L.unlock();
   ResultIsReady.notify_one();
+}
   }
 
   void consumeNonInitial(DirectoryWatcher::Event E) {
@@ -151,8 +153,10 @@
 } else {
   ExpectedNonInitial.erase(It);
 }
-if (result())
+if (result()) {
+  L.unlock();
   ResultIsReady.notify_one();
+}
   }
 
   // This method is used by DirectoryWatcher.


Index: cfe/trunk/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp
===
--- cfe/trunk/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp
+++ cfe/trunk/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp
@@ -132,8 +132,10 @@
 } else {
   ExpectedInitial.erase(It);
 }
-if (result())
+if (result()) {
+  L.unlock();
   ResultIsReady.notify_one();
+}
   }
 
   void consumeNonInitial(DirectoryWatcher::Event E) {
@@ -151,8 +153,10 @@
 } else {
   ExpectedNonInitial.erase(It);
 }
-if (result())
+if (result()) {
+  L.unlock();
   ResultIsReady.notify_one();
+}
   }
 
   // This method is used by DirectoryWatcher.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D65704: DirectoryWatcher::create: Adding better error handling.

2019-08-05 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi updated this revision to Diff 213515.
plotfi added a comment.

Improve comments, change Path.empty() errors for asserts.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65704/new/

https://reviews.llvm.org/D65704

Files:
  clang/include/clang/DirectoryWatcher/DirectoryWatcher.h
  clang/lib/DirectoryWatcher/default/DirectoryWatcher-not-implemented.cpp
  clang/lib/DirectoryWatcher/linux/DirectoryWatcher-linux.cpp
  clang/lib/DirectoryWatcher/mac/DirectoryWatcher-mac.cpp
  clang/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp

Index: clang/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp
===
--- clang/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp
+++ clang/unittests/DirectoryWatcher/DirectoryWatcherTest.cpp
@@ -280,6 +280,7 @@
 TestConsumer.consume(Events, IsInitial);
   },
   /*waitForInitialSync=*/true);
+  if (!DW) return;
 
   checkEventualResultWithTimeout(TestConsumer);
 }
@@ -311,6 +312,7 @@
 TestConsumer.consume(Events, IsInitial);
   },
   /*waitForInitialSync=*/false);
+  if (!DW) return;
 
   checkEventualResultWithTimeout(TestConsumer);
 }
@@ -331,6 +333,7 @@
 TestConsumer.consume(Events, IsInitial);
   },
   /*waitForInitialSync=*/true);
+  if (!DW) return;
 
   fixture.addFile("a");
   fixture.addFile("b");
@@ -356,6 +359,7 @@
 TestConsumer.consume(Events, IsInitial);
   },
   /*waitForInitialSync=*/true);
+  if (!DW) return;
 
   // modify the file
   {
@@ -386,6 +390,7 @@
 TestConsumer.consume(Events, IsInitial);
   },
   /*waitForInitialSync=*/true);
+  if (!DW) return;
 
   fixture.deleteFile("a");
 
@@ -407,6 +412,7 @@
 TestConsumer.consume(Events, IsInitial);
   },
   /*waitForInitialSync=*/true);
+  if (!DW) return;
 
   remove_directories(fixture.TestWatchedDir);
 
@@ -427,7 +433,8 @@
   TestConsumer.consume(Events, IsInitial);
 },
 /*waitForInitialSync=*/true);
+if (!DW) return;
   } // DW is destructed here.
 
   checkEventualResultWithTimeout(TestConsumer);
 }
\ No newline at end of file
Index: clang/lib/DirectoryWatcher/mac/DirectoryWatcher-mac.cpp
===
--- clang/lib/DirectoryWatcher/mac/DirectoryWatcher-mac.cpp
+++ clang/lib/DirectoryWatcher/mac/DirectoryWatcher-mac.cpp
@@ -11,16 +11,13 @@
 
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Error.h"
 #include "llvm/Support/Path.h"
 #include 
 
 using namespace llvm;
 using namespace clang;
 
-static FSEventStreamRef createFSEventStream(
-StringRef Path,
-std::function, bool)>,
-dispatch_queue_t);
 static void stopFSEventStream(FSEventStreamRef);
 
 namespace {
@@ -153,8 +150,7 @@
 StringRef Path,
 std::function, bool)> Receiver,
 dispatch_queue_t Queue) {
-  if (Path.empty())
-return nullptr;
+  assert(!Path.empty() && "Path.empty()");
 
   CFMutableArrayRef PathsToWatch = [&]() {
 CFMutableArrayRef PathsToWatch =
@@ -205,7 +201,7 @@
   FSEventStreamRelease(EventStream);
 }
 
-std::unique_ptr clang::DirectoryWatcher::create(
+llvm::Expected> clang::DirectoryWatcher::create(
 StringRef Path,
 std::function, bool)> Receiver,
 bool WaitForInitialSync) {
@@ -213,12 +209,11 @@
   dispatch_queue_create("DirectoryWatcher", DISPATCH_QUEUE_SERIAL);
 
   if (Path.empty())
-return nullptr;
+return llvm::make_error(
+std::string("Path.empty() error: "), llvm::inconvertibleErrorCode());
 
   auto EventStream = createFSEventStream(Path, Receiver, Queue);
-  if (!EventStream) {
-return nullptr;
-  }
+  assert(EventStream && "EventStream expected to be non-null.")
 
   std::unique_ptr Result =
   llvm::make_unique(EventStream, Receiver, Path);
Index: clang/lib/DirectoryWatcher/linux/DirectoryWatcher-linux.cpp
===
--- clang/lib/DirectoryWatcher/linux/DirectoryWatcher-linux.cpp
+++ clang/lib/DirectoryWatcher/linux/DirectoryWatcher-linux.cpp
@@ -13,6 +13,7 @@
 #include "llvm/ADT/ScopeExit.h"
 #include "llvm/Support/AlignOf.h"
 #include "llvm/Support/Errno.h"
+#include "llvm/Support/Error.h"
 #include "llvm/Support/Mutex.h"
 #include "llvm/Support/Path.h"
 #include 
@@ -320,16 +321,17 @@
 
 } // namespace
 
-std::unique_ptr clang::DirectoryWatcher::create(
+llvm::Expected> clang::DirectoryWatcher::create(
 StringRef Path,
 std::function, bool)> Receiver,
 bool WaitForInitialSync) {
-  if (Path.empty())
-return nullptr;
+  assert(!Path.empty() && "Path.empty()");
 
   const int InotifyFD = inotify_init1(IN_CLOEXEC);
   if (InotifyFD == -1)
-return nullptr;
+return llvm::make_error(
+std::string("inotify_init1() error: ") + strerror(errno),
+llvm::inconvertibleErrorCode());
 
   const int InotifyWD = inotify_add_watch(
   Inot

[PATCH] D65704: DirectoryWatcher::create: Adding better error handling.

2019-08-05 Thread Puyan Lotfi via Phabricator via cfe-commits
plotfi updated this revision to Diff 213520.
plotfi added a comment.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

add another assert


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D65704/new/

https://reviews.llvm.org/D65704

Files:
  include/clang/DirectoryWatcher/DirectoryWatcher.h
  lib/DirectoryWatcher/default/DirectoryWatcher-not-implemented.cpp
  lib/DirectoryWatcher/linux/DirectoryWatcher-linux.cpp
  lib/DirectoryWatcher/mac/DirectoryWatcher-mac.cpp
  unittests/DirectoryWatcher/DirectoryWatcherTest.cpp

Index: unittests/DirectoryWatcher/DirectoryWatcherTest.cpp
===
--- unittests/DirectoryWatcher/DirectoryWatcherTest.cpp
+++ unittests/DirectoryWatcher/DirectoryWatcherTest.cpp
@@ -284,6 +284,7 @@
 TestConsumer.consume(Events, IsInitial);
   },
   /*waitForInitialSync=*/true);
+  if (!DW) return;
 
   checkEventualResultWithTimeout(TestConsumer);
 }
@@ -315,6 +316,7 @@
 TestConsumer.consume(Events, IsInitial);
   },
   /*waitForInitialSync=*/false);
+  if (!DW) return;
 
   checkEventualResultWithTimeout(TestConsumer);
 }
@@ -335,6 +337,7 @@
 TestConsumer.consume(Events, IsInitial);
   },
   /*waitForInitialSync=*/true);
+  if (!DW) return;
 
   fixture.addFile("a");
   fixture.addFile("b");
@@ -360,6 +363,7 @@
 TestConsumer.consume(Events, IsInitial);
   },
   /*waitForInitialSync=*/true);
+  if (!DW) return;
 
   // modify the file
   {
@@ -390,6 +394,7 @@
 TestConsumer.consume(Events, IsInitial);
   },
   /*waitForInitialSync=*/true);
+  if (!DW) return;
 
   fixture.deleteFile("a");
 
@@ -411,6 +416,7 @@
 TestConsumer.consume(Events, IsInitial);
   },
   /*waitForInitialSync=*/true);
+  if (!DW) return;
 
   remove_directories(fixture.TestWatchedDir);
 
@@ -431,6 +437,7 @@
   TestConsumer.consume(Events, IsInitial);
 },
 /*waitForInitialSync=*/true);
+if (!DW) return;
   } // DW is destructed here.
 
   checkEventualResultWithTimeout(TestConsumer);
Index: lib/DirectoryWatcher/mac/DirectoryWatcher-mac.cpp
===
--- lib/DirectoryWatcher/mac/DirectoryWatcher-mac.cpp
+++ lib/DirectoryWatcher/mac/DirectoryWatcher-mac.cpp
@@ -11,6 +11,7 @@
 
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/Error.h"
 #include "llvm/Support/Path.h"
 #include 
 
@@ -17,10 +18,6 @@
 using namespace llvm;
 using namespace clang;
 
-static FSEventStreamRef createFSEventStream(
-StringRef Path,
-std::function, bool)>,
-dispatch_queue_t);
 static void stopFSEventStream(FSEventStreamRef);
 
 namespace {
@@ -153,8 +150,7 @@
 StringRef Path,
 std::function, bool)> Receiver,
 dispatch_queue_t Queue) {
-  if (Path.empty())
-return nullptr;
+  assert(!Path.empty() && "Path.empty()");
 
   CFMutableArrayRef PathsToWatch = [&]() {
 CFMutableArrayRef PathsToWatch =
@@ -205,7 +201,7 @@
   FSEventStreamRelease(EventStream);
 }
 
-std::unique_ptr clang::DirectoryWatcher::create(
+llvm::Expected> clang::DirectoryWatcher::create(
 StringRef Path,
 std::function, bool)> Receiver,
 bool WaitForInitialSync) {
@@ -212,13 +208,9 @@
   dispatch_queue_t Queue =
   dispatch_queue_create("DirectoryWatcher", DISPATCH_QUEUE_SERIAL);
 
-  if (Path.empty())
-return nullptr;
-
+  assert(!Path.empty() && "Path.empty()");
   auto EventStream = createFSEventStream(Path, Receiver, Queue);
-  if (!EventStream) {
-return nullptr;
-  }
+  assert(EventStream && "EventStream expected to be non-null.")
 
   std::unique_ptr Result =
   llvm::make_unique(EventStream, Receiver, Path);
Index: lib/DirectoryWatcher/linux/DirectoryWatcher-linux.cpp
===
--- lib/DirectoryWatcher/linux/DirectoryWatcher-linux.cpp
+++ lib/DirectoryWatcher/linux/DirectoryWatcher-linux.cpp
@@ -13,6 +13,7 @@
 #include "llvm/ADT/ScopeExit.h"
 #include "llvm/Support/AlignOf.h"
 #include "llvm/Support/Errno.h"
+#include "llvm/Support/Error.h"
 #include "llvm/Support/Mutex.h"
 #include "llvm/Support/Path.h"
 #include 
@@ -320,16 +321,17 @@
 
 } // namespace
 
-std::unique_ptr clang::DirectoryWatcher::create(
+llvm::Expected> clang::DirectoryWatcher::create(
 StringRef Path,
 std::function, bool)> Receiver,
 bool WaitForInitialSync) {
-  if (Path.empty())
-return nullptr;
+  assert(!Path.empty() && "Path.empty()");
 
   const int InotifyFD = inotify_init1(IN_CLOEXEC);
   if (InotifyFD == -1)
-return nullptr;
+return llvm::make_error(
+std::string("inotify_init1() error: ") + strerror(errno),
+llvm::inconvertibleErrorCode());
 
   const int InotifyWD = inotify_add_watch(
   InotifyFD, Path.str().c_str(),
@@ -340,12 +342,16 @@
 #endif
   );
   if (InotifyWD == -1)
-return n

  1   2   3   4   >