r363908 - [clang][AST] Refactoring ASTNameGenerator to use pimpl pattern (NFC).

2019-06-19 Thread Puyan Lotfi via cfe-commits
Author: zer0
Date: Wed Jun 19 23:01:06 2019
New Revision: 363908

URL: http://llvm.org/viewvc/llvm-project?rev=363908=rev
Log:
[clang][AST] Refactoring ASTNameGenerator to use pimpl pattern (NFC).

The original pimpl pattern used between CodegenNameGenerator and
CodegenNameGeneratorImpl did a good job of hiding DataLayout making it so that
users of CodegenNameGenerator did not need to link with llvm core.  This is an
NFC change to neatly wrap ASTNameGenerator in a pimpl.

Differential Revision: https://reviews.llvm.org/D63584



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

Modified: cfe/trunk/include/clang/AST/Mangle.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Mangle.h?rev=363908=363907=363908=diff
==
--- cfe/trunk/include/clang/AST/Mangle.h (original)
+++ cfe/trunk/include/clang/AST/Mangle.h Wed Jun 19 23:01:06 2019
@@ -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 @@ public:
 };
 
 class ASTNameGenerator {
-  std::unique_ptr MC;
-  llvm::DataLayout DL;
-
 public:
   explicit ASTNameGenerator(ASTContext );
+  ~ASTNameGenerator();
   bool writeName(const Decl *D, raw_ostream );
   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 );
-  void writeObjCClassName(const ObjCInterfaceDecl *D, raw_ostream );
-  std::string getMangledStructor(const NamedDecl *ND, unsigned StructorType);
-  std::string getMangledThunk(const CXXMethodDecl *MD, const ThunkInfo );
+  class Implementation;
+  std::unique_ptr Impl;
 };
 }
 

Modified: cfe/trunk/lib/AST/Mangle.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Mangle.cpp?rev=363908=363907=363908=diff
==
--- cfe/trunk/lib/AST/Mangle.cpp (original)
+++ cfe/trunk/lib/AST/Mangle.cpp Wed Jun 19 23:01:06 2019
@@ -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 @@ void MangleContext::mangleObjCMethodName
   Out << OS.str().size() << OS.str();
 }
 
-ASTNameGenerator::ASTNameGenerator(ASTContext )
-: MC(Ctx.createMangleContext()), DL(Ctx.getTargetInfo().getDataLayout()) {}
-
-bool ASTNameGenerator::writeName(const Decl *D, raw_ostream ) {
-  // 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 )
+  : MC(Ctx.createMangleContext()), DL(Ctx.getTargetInfo().getDataLayout()) 
{
+  }
+
+  bool writeName(const Decl *D, raw_ostream ) {
+// 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 

[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=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 );
+  ~ASTNameGenerator();
   bool writeName(const Decl *D, raw_ostream );
   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 );
-  void writeObjCClassName(const ObjCInterfaceDecl *D, raw_ostream );
-  std::string getMangledStructor(const NamedDecl *ND, unsigned StructorType);
-  std::string getMangledThunk(const CXXMethodDecl *MD, const ThunkInfo );
+  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 )
-: MC(Ctx.createMangleContext()), DL(Ctx.getTargetInfo().getDataLayout()) {}
-
-bool ASTNameGenerator::writeName(const Decl *D, raw_ostream ) {
-  // 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 )
+  : MC(Ctx.createMangleContext()), DL(Ctx.getTargetInfo().getDataLayout()) {
+  }
+
+  bool writeName(const Decl *D, raw_ostream ) {
+// 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 ) {
-  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 = 

[PATCH] D63227: [analyzer] Better timers.

2019-06-19 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun added inline comments.



Comment at: clang/lib/StaticAnalyzer/Core/ExprEngine.cpp:228
 
-ExprEngine::~ExprEngine() {
-  BR.FlushReports();

NoQ wrote:
> xazax.hun wrote:
> > Hmm. Maybe add an assert that all the bug reports are flushed at this 
> > point? Just to make sure we never need this :) I am not insisting on this 
> > change just wondering.
> Actually we already have the same code in `~BugReporter` itself, so this 
> assertion would be kinda trivial. Like, it wouldn't necessarily hold, as the 
> destructor for the field hasn't been executed at this point, but it's still 
> useless, because the destructor will be executed very soon.
Makes sense, thanks. 


Repository:
  rC Clang

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

https://reviews.llvm.org/D63227



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


[PATCH] D60455: [SYCL] Implement SYCL device code outlining

2019-06-19 Thread Ronan Keryell via Phabricator via cfe-commits
keryell added inline comments.



Comment at: clang/test/SemaSYCL/device-attributes.cpp:3
+
+[[clang::sycl_kernel]] int gv2 = 0; // expected-warning {{'sycl_kernel' 
attribute only applies to functions}}
+__attribute((sycl_kernel)) int gv3 = 0; // expected-warning {{'sycl_kernel' 
attribute only applies to functions}}

bader wrote:
> aaron.ballman wrote:
> > Fznamznon wrote:
> > > aaron.ballman wrote:
> > > > I'd like to see some more tests covering less obvious scenarios. Can I 
> > > > add this attribute to a lambda? What about a member function? How does 
> > > > it work with virtual functions? That sort of thing.
> > > Actually there is no restrictions for adding this attribute to any 
> > > function to outline device code so I just checked the simplest variant.
> > > 
> > > But I'm working on new patch which will put some requirements on function 
> > > which is marked with `sycl_kernel` attribute. 
> > > This new patch will add generation of OpenCL kernel from function marked 
> > > with `sycl_kernel` attribute. The main idea of this approach is described 
> > > in this [[ 
> > > https://github.com/intel/llvm/blob/sycl/sycl/doc/SYCL_compiler_and_runtime_design.md#lowering-of-lambda-function-objects-and-named-function-objects
> > >  | document ]] (in this document generated kernel is called "kernel 
> > > wrapper").
> > > And to be able to generate OpenCL kernel using function marked with 
> > > `sycl_kernel` attribute we put some requirements on this function, for 
> > > example it must be a template function. You can find these requirements 
> > > and example of proper function which can be marked with `sycl_kernel` in 
> > > this [[ https://github.com/intel/llvm/pull/177#discussion_r290451286 | 
> > > comment ]] .
> > > 
> > > 
> > > Actually there is no restrictions for adding this attribute to any 
> > > function to outline device code so I just checked the simplest variant.
> > 
> > So there are no concerns about code like:
> > ```
> > struct Base {
> >   __attribute__((sycl_kernel)) virtual void foo();
> >   virtual void bar();
> > };
> > 
> > struct Derived : Base {
> >   void foo() override;
> >   __attribute__((sycl_kernel)) void bar() override;
> > };
> > 
> > void f(Base *B, Derived *D) {
> >   // Will all of these "do the right thing"?
> >   B->foo();
> >   B->bar();
> > 
> >   D->foo();
> >   D->bar();
> > }
> > ```
> > Actually there is no restrictions for adding this attribute to any function 
> > to outline device code so I just checked the simplest variant.
> > But I'm working on new patch which will put some requirements on function 
> > which is marked with sycl_kernel attribute.
> 
> @aaron.ballman, sorry for confusing. The  usage scenarios should have been 
> articulated more accurately.
> We have only four uses of this attribute in our implementation:
> https://github.com/intel/llvm/blob/sycl/sycl/include/CL/sycl/handler.hpp#L538 
> (lines 538-605).
> All four uses are applied to member functions of `cl::sycl::handler` class 
> and all of them have similar prototype (which is mentioned by Mariya in the 
> previous 
> [comment](https://github.com/intel/llvm/pull/177#discussion_r290451286):
> 
> ```
> namespace cl { namespace sycl {
> class handler {
>   template 
>   __attribute__((sycl_kernel)) void sycl_kernel_function(KernelType 
> KernelFuncObj) {
> KernelFuncObj();
>   }
> };
> }}
> ```
> 
> Here is the list of SYCL device compiler expectations with regard to the 
> function marked with `sycl_kernel` attribute.
>   - Function template with at least one parameter is expected. The 
> compiler generates OpenCL kernel and uses first template parameter as unique 
> name to the generated OpenCL kernel. Host application uses this unique name 
> to invoke the OpenCL kernel generated for the `sycl_kernel_function` 
> specialized by this name and KernelType (which might be a lambda type).
>   - Function must have at least one parameter. First parameter expected 
> to be a function object type (named or unnamed i.e. lambda). Compiler uses 
> function object type field to generate OpenCL kernel parameters.
> 
> Aaron, I hope it makes more sense now.
> 
> We don't plan in any use cases other than in SYCL standard library 
> implementation mentioned above.
> If I understand you concerns correctly, you want to be sure that clang 
> prohibits other uses of this attribute, which are not intended. Right?
> What is the best way to do this? Add more negative tests cases and make sure 
> that clang generate error diagnostic messages?
> 
> If I understand you concerns correctly, you want to be sure that clang 
> prohibits other uses of this attribute, which are not intended. Right?

But since it is an attribute to be used by SYCL run-time writers, I am not sure 
there is a lot of value in over-engineering the restrictions of its use. It 
diverts brain power from the real implementation & review and might even 
prevent innovation due to some creative 

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

2019-06-19 Thread Saleem Abdulrasool via Phabricator via cfe-commits
compnerd accepted this revision.
compnerd added inline comments.
This revision is now accepted and ready to land.



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

plotfi wrote:
> @aaron.ballman I can move this down to the private section in a subsequent 
> NFC if you'd like. 
The implementation is never leaked to the user.  This means that this is 
effectively private.



Comment at: clang/lib/AST/Mangle.cpp:416
 
-bool ASTNameGenerator::writeFuncOrVarName(const NamedDecl *D, raw_ostream ) 
{
+private:
+  bool writeFuncOrVarName(const NamedDecl *D, raw_ostream ) {

Don't think that it really matters to make this private or public really.  The 
implementation is fully private.



Comment at: clang/lib/AST/Mangle.cpp:473
+ASTNameGenerator::ASTNameGenerator(ASTContext )
+: Impl(new Implementation(Ctx)) {}
+

`llvm::make_unique` would be nicer.


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] D63156: [clang][NewPM] Add -fno-experimental-new-pass-manager to tests

2019-06-19 Thread Chandler Carruth via Phabricator via cfe-commits
chandlerc added a comment.

just a minor comment on one of these...




Comment at: clang/test/CodeGen/pgo-sample.c:10
+
+// The new pass manager analog to PrunEH is a combination of 'function-attrs'
+// and 'function(simplify-cgf)'.

s/PrunEH/PruneEH/



Comment at: clang/test/CodeGen/pgo-sample.c:12-14
+// NEWPM-DAG: PostOrderFunctionAttrsPass
+// NEWPM-DAG: SimplifyCFGPass
+// NEWPM-DAG: SampleProfileLoaderPass

The DAG worries me a bit ... The point here is to check that we remove EH 
before attaching sample profile data, and with the DAG it isn't clear that this 
happens *before*.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63156



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


[PATCH] D63277: [CUDA][HIP] Don't set "comdat" attribute for CUDA device stub functions.

2019-06-19 Thread John McCall via Phabricator via cfe-commits
rjmccall accepted this revision.
rjmccall added a comment.

Alright, thanks.  I agree that per the documentation this should be sufficient.


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

https://reviews.llvm.org/D63277



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


[PATCH] D61989: [clang-tidy] enable modernize-concat-nested-namespaces on header files

2019-06-19 Thread Xiao Shi via Phabricator via cfe-commits
shixiao updated this revision to Diff 205731.
shixiao added a comment.

rebase


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D61989

Files:
  clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.cpp
  clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.h
  clang-tools-extra/docs/ReleaseNotes.rst
  
clang-tools-extra/docs/clang-tidy/checks/modernize-concat-nested-namespaces.rst
  clang-tools-extra/test/clang-tidy/modernize-concat-nested-namespaces.cpp
  clang-tools-extra/test/clang-tidy/modernize-concat-nested-namespaces.h
  clang-tools-extra/test/clang-tidy/modernize-concat-nested-namespaces2.h

Index: clang-tools-extra/test/clang-tidy/modernize-concat-nested-namespaces2.h
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/modernize-concat-nested-namespaces2.h
@@ -0,0 +1,9 @@
+#pragma once
+
+namespace foo {
+namespace bar {
+namespace baz {
+struct S2 {};
+} // namespace baz
+} // namespace bar
+} // namespace foo
Index: clang-tools-extra/test/clang-tidy/modernize-concat-nested-namespaces.h
===
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/modernize-concat-nested-namespaces.h
@@ -0,0 +1,11 @@
+#pragma once
+
+#include "modernize-concat-nested-namespaces2.h"
+
+namespace foo {
+namespace bar {
+namespace baz {
+struct S {};
+} // namespace baz
+} // namespace bar
+} // namespace foo
Index: clang-tools-extra/test/clang-tidy/modernize-concat-nested-namespaces.cpp
===
--- clang-tools-extra/test/clang-tidy/modernize-concat-nested-namespaces.cpp
+++ clang-tools-extra/test/clang-tidy/modernize-concat-nested-namespaces.cpp
@@ -1,4 +1,12 @@
-// RUN: %check_clang_tidy -std=c++17-or-later %s modernize-concat-nested-namespaces %t
+// Note: since this check fixes instances in the headers, we need to copy the
+// headers before each run (for a mode that supports this check).
+//
+// RUN: cp %S/modernize-concat-nested-namespaces*.h %T
+// RUN: %check_clang_tidy -std=c++17 %s modernize-concat-nested-namespaces %t -- -header-filter="concat" -- -I %T
+// RUN: cp %S/modernize-concat-nested-namespaces*.h %T
+// RUN: %check_clang_tidy -std=c++2a %s modernize-concat-nested-namespaces %t -- -header-filter="concat" -- -I %T
+
+#include "modernize-concat-nested-namespaces.h"
 
 namespace n1 {}
 
@@ -159,3 +167,8 @@
 
   return 0;
 }
+
+// Checks for header file:
+
+// CHECK-MESSAGES: modernize-concat-nested-namespaces.h:{{.*}} warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
+// CHECK-MESSAGES: modernize-concat-nested-namespaces2.h:{{.*}} warning: nested namespaces can be concatenated [modernize-concat-nested-namespaces]
Index: clang-tools-extra/docs/clang-tidy/checks/modernize-concat-nested-namespaces.rst
===
--- clang-tools-extra/docs/clang-tidy/checks/modernize-concat-nested-namespaces.rst
+++ clang-tools-extra/docs/clang-tidy/checks/modernize-concat-nested-namespaces.rst
@@ -47,3 +47,13 @@
   }
   }
 
+Options
+---
+
+.. option:: HeaderFileExtensions
+
+   A comma-separated list of filename extensions of header files (the filename
+   extensions should not contain "." prefix). Default is `h,hh,hpp,hxx`.
+   For header files without an extension, use an empty string (if there are no
+   other desired extensions) or leave an empty element in the list. e.g.,
+   `h,hh,hpp,hxx,` (note the trailing comma).
Index: clang-tools-extra/docs/ReleaseNotes.rst
===
--- clang-tools-extra/docs/ReleaseNotes.rst
+++ clang-tools-extra/docs/ReleaseNotes.rst
@@ -195,6 +195,11 @@
   :doc:`objc-property-declaration `
   check have been removed.
 
+- The :doc:`modernize-concat-nested-namespaces
+  ` now supports the
+  `HeaderFileExtensions` option and issues warnings for transitively included
+  header files that pass the header filter.
+
 - The :doc:`modernize-use-override
   ` now supports `OverrideSpelling`
   and `FinalSpelling` options.
Index: clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.h
===
--- clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.h
+++ clang-tools-extra/clang-tidy/modernize/ConcatNestedNamespacesCheck.h
@@ -10,6 +10,7 @@
 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_CONCATNESTEDNAMESPACESCHECK_H
 
 #include "../ClangTidyCheck.h"
+#include "../utils/HeaderFileExtensionsUtils.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/SmallVector.h"
 
@@ -17,10 +18,16 @@
 namespace tidy {
 namespace modernize {
 
+/// The check supports these options:
+///   - `HeaderFileExtensions`: a comma-separated list of filename extensions of
+/// 

[PATCH] D63580: [clang][NewPM] Do not eliminate available_externally durng `-O2 -flto` runs

2019-06-19 Thread Chandler Carruth via Phabricator via cfe-commits
chandlerc accepted this revision.
chandlerc added a comment.
This revision is now accepted and ready to land.

LGTM, again, really nice. Tiny tweak below.




Comment at: llvm/test/Other/available-externally-lto.ll:1
+; Ensure that we don't emit available_externally functions at -O2, unless 
-flto is present in which case we should preserve them for link-time inlining 
decisions.
+; RUN: opt < %s -S -passes='default' | FileCheck %s

Wrap to 80-columns?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63580



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


[PATCH] D63577: [clang][NewPM] Move EntryExitInstrumenterPass to the start of the pipeline

2019-06-19 Thread Chandler Carruth via Phabricator via cfe-commits
chandlerc accepted this revision.
chandlerc added a comment.
This revision is now accepted and ready to land.

LGTM, nice!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63577



___
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
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
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 )
-: 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 ) {
+public:
+  explicit Implementation(ASTContext )
+  : MC(Ctx.createMangleContext()), DL(Ctx.getTargetInfo().getDataLayout()) {
+  }
+
+  bool writeName(const Decl *D, raw_ostream ) {
 // 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 ) {
+private:
+  bool writeFuncOrVarName(const NamedDecl *D, raw_ostream ) {
 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 ) {
+  void writeObjCClassName(const ObjCInterfaceDecl *D, raw_ostream ) {
 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 ) {
+  std::string getMangledThunk(const CXXMethodDecl *MD, const ThunkInfo ) {
 std::string FrontendBuf;
 llvm::raw_string_ostream FOS(FrontendBuf);
 
@@ -463,3 +467,21 @@
 
 return BOS.str();
   }
+};
+
+ASTNameGenerator::ASTNameGenerator(ASTContext )
+: Impl(new Implementation(Ctx)) {}
+
+ASTNameGenerator::~ASTNameGenerator() {}
+
+bool ASTNameGenerator::writeName(const Decl *D, raw_ostream ) {
+  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 );
+  ~ASTNameGenerator();
   bool writeName(const Decl *D, raw_ostream );
   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 );
-  void writeObjCClassName(const ObjCInterfaceDecl *D, raw_ostream );
-  std::string getMangledStructor(const NamedDecl *ND, unsigned 

[PATCH] D57086: Ignore trailing NullStmts in StmtExprs for GCC compatibility

2019-06-19 Thread Dominic Ferreira via Phabricator via cfe-commits
domdom added a comment.

In D57086#1550514 , @aaron.ballman 
wrote:

> In D57086#1549632 , @domdom wrote:
>
> > clang-format the patch
>
>
> Thanks! Do you need someone to commit on your behalf?


You are very welcome; thank you both for your comments!

I do need someone to commit on my behalf :)


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

https://reviews.llvm.org/D57086



___
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
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 )
-: 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 ) {
-  // 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 )
+  : MC(Ctx.createMangleContext()), DL(Ctx.getTargetInfo().getDataLayout()) {
+  }
+
+  bool writeName(const Decl *D, raw_ostream ) {
+// 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 ) {
-  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 ) {
+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());
+  

[PATCH] D63174: [clang][NewPM] Add RUNS for tests that produce slightly different IR under new PM

2019-06-19 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan updated this revision to Diff 205727.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63174

Files:
  clang/test/CodeGen/avx512-reduceMinMaxIntrin.c
  clang/test/CodeGen/avx512f-builtins.c
  clang/test/CodeGen/avx512vl-builtins.c
  clang/test/CodeGen/avx512vlbw-builtins.c
  clang/test/CodeGenOpenCL/convergent.cl

Index: clang/test/CodeGenOpenCL/convergent.cl
===
--- clang/test/CodeGenOpenCL/convergent.cl
+++ clang/test/CodeGenOpenCL/convergent.cl
@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 -triple spir-unknown-unknown -emit-llvm %s -o - | opt -instnamer -S | FileCheck -enable-var-scope %s
+// RUN: %clang_cc1 -triple spir-unknown-unknown -emit-llvm %s -o - -fno-experimental-new-pass-manager | opt -instnamer -S | FileCheck -enable-var-scope %s --check-prefixes=CHECK,CHECK-LEGACY
+// RUN: %clang_cc1 -triple spir-unknown-unknown -emit-llvm %s -o - -fexperimental-new-pass-manager | opt -instnamer -S | FileCheck -enable-var-scope %s --check-prefixes=CHECK,CHECK-NEWPM
 
 // This is initially assumed convergent, but can be deduced to not require it.
 
@@ -117,7 +118,12 @@
 // CHECK: [[for_body]]:
 // CHECK:  tail call spir_func void @nodupfun() #[[attr5:[0-9]+]]
 // CHECK-NOT: call spir_func void @nodupfun()
-// CHECK:  br i1 %{{.+}}, label %[[for_body]], label %[[for_cond_cleanup]]
+
+// The new PM produces a slightly different IR for the loop from the legacy PM,
+// but the test still checks that the loop is not unrolled.
+// CHECK-LEGACY:  br i1 %{{.+}}, label %[[for_body]], label %[[for_cond_cleanup]]
+// CHECK-NEW: br i1 %{{.+}}, label %[[for_body_crit_edge:.+]], label %[[for_cond_cleanup]]
+// CHECK-NEW: [[for_body_crit_edge]]:
 
 void test_not_unroll() {
   for (int i = 0; i < 10; i++)
Index: clang/test/CodeGen/avx512vlbw-builtins.c
===
--- clang/test/CodeGen/avx512vlbw-builtins.c
+++ clang/test/CodeGen/avx512vlbw-builtins.c
@@ -1,6 +1,10 @@
-// RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +avx512bw -target-feature +avx512vl -emit-llvm -o - -Wall -Werror | FileCheck %s
-// RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +avx512bw -target-feature +avx512vl -fno-signed-char -emit-llvm -o - -Wall -Werror | FileCheck %s
+// RUN: %clang_cc1 -ffreestanding %s -fno-experimental-new-pass-manager -triple=x86_64-apple-darwin -target-feature +avx512bw -target-feature +avx512vl -emit-llvm -o - -Wall -Werror | FileCheck %s
+// RUN: %clang_cc1 -ffreestanding %s -fno-experimental-new-pass-manager -triple=x86_64-apple-darwin -target-feature +avx512bw -target-feature +avx512vl -fno-signed-char -emit-llvm -o - -Wall -Werror | FileCheck %s
 
+// There are a few cases where instead accpeting the result of an instruction
+// directly as an argument to a select, it instead goes through some bitcasts.
+// RUN: %clang_cc1 -ffreestanding %s -fexperimental-new-pass-manager -triple=x86_64-apple-darwin -target-feature +avx512bw -target-feature +avx512vl -emit-llvm -o - -Wall -Werror | FileCheck %s --check-prefixes=CHECK,CHECK-NEWPM
+// RUN: %clang_cc1 -ffreestanding %s -fexperimental-new-pass-manager -triple=x86_64-apple-darwin -target-feature +avx512bw -target-feature +avx512vl -fno-signed-char -emit-llvm -o - -Wall -Werror | FileCheck %s --check-prefixes=CHECK,CHECK-NEWPM
 
 #include 
 
@@ -901,6 +905,8 @@
   // CHECK: [[SUB:%.*]] = sub <16 x i8> zeroinitializer, [[A:%.*]]
   // CHECK: [[CMP:%.*]] = icmp sgt <16 x i8> [[A]], zeroinitializer
   // CHECK: [[SEL:%.*]] = select <16 x i1> [[CMP]], <16 x i8> [[A]], <16 x i8> [[SUB]]
+  // CHECK-NEWPM: [[TMP:%.*]] = bitcast [[SRCTY:<.*>]] [[SEL]] to [[DSTTY:<.*>]]
+  // CHECK-NEWPM: [[SEL:%.*]] = bitcast [[DSTTY]] [[TMP]] to [[SRCTY]]
   // CHECK: select <16 x i1> %{{.*}}, <16 x i8> [[SEL]], <16 x i8> %{{.*}}
   return _mm_mask_abs_epi8(__W,__U,__A); 
 }
@@ -910,6 +916,8 @@
   // CHECK: [[SUB:%.*]] = sub <16 x i8> zeroinitializer, [[A:%.*]]
   // CHECK: [[CMP:%.*]] = icmp sgt <16 x i8> [[A]], zeroinitializer
   // CHECK: [[SEL:%.*]] = select <16 x i1> [[CMP]], <16 x i8> [[A]], <16 x i8> [[SUB]]
+  // CHECK-NEWPM: [[TMP:%.*]] = bitcast [[SRCTY:<.*>]] [[SEL]] to [[DSTTY:<.*>]]
+  // CHECK-NEWPM: [[SEL:%.*]] = bitcast [[DSTTY]] [[TMP]] to [[SRCTY]]
   // CHECK: select <16 x i1> %{{.*}}, <16 x i8> [[SEL]], <16 x i8> %{{.*}}
   return _mm_maskz_abs_epi8(__U,__A); 
 }
@@ -919,6 +927,8 @@
   // CHECK: [[SUB:%.*]] = sub <32 x i8> zeroinitializer, [[A:%.*]]
   // CHECK: [[CMP:%.*]] = icmp sgt <32 x i8> [[A]], zeroinitializer
   // CHECK: [[SEL:%.*]] = select <32 x i1> [[CMP]], <32 x i8> [[A]], <32 x i8> [[SUB]]
+  // CHECK-NEWPM: [[TMP:%.*]] = bitcast [[SRCTY:<.*>]] [[SEL]] to [[DSTTY:<.*>]]
+  // CHECK-NEWPM: [[SEL:%.*]] = bitcast [[DSTTY]] [[TMP]] to [[SRCTY]]
   // CHECK: select <32 x i1> %{{.*}}, <32 x i8> 

[PATCH] D63538: [analyzer][CFG] Return the correct terminator condition

2019-06-19 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

I think this kinda makes sense, but also it looks like a risky change, because 
who knows how many times we have took the old behavior for granted. In 
particular, i'm slightly worried about this breaking the wonky logic of 
`ExprEngine::VisitLogicalExpr` (cf. D59857 ). 
But i've no specific concerns, so i think it's worth a try, given that it's a 
massive simplification.




Comment at: clang/lib/Analysis/CFG.cpp:5628-5630
+  const Expr *Cond;
 
+  if (!(Cond = dyn_cast(S))) {

Can we do the assignment to the previous line pls? ^.^



Comment at: clang/lib/Analysis/CFG.cpp:5631-5634
+// Only ObjCForCollectionStmt is known not to be a non-Expr terminator.
+const auto *O = cast(S);
 
+Cond = O->getCollection();

The new arrow doesn't really make much sense. Like, there's nothing interesting 
going on specifically with the collection, so there's no reason to highlight it 
separately from, say, the element we're extracting from it. Let's just keep the 
old behavior.


Repository:
  rC Clang

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

https://reviews.llvm.org/D63538



___
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
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 )
-: 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 ) {
-  // 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 )
+  : MC(Ctx.createMangleContext()), DL(Ctx.getTargetInfo().getDataLayout()) {
+  }
+
+  bool writeName(const Decl *D, raw_ostream ) {
+// 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 ) {
-  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 ) {
+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(ObjCClass, ClassName),
-  

[PATCH] D63174: [clang][NewPM] Add RUNS for tests that produce slightly different IR under new PM

2019-06-19 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan added a comment.

In D63174#1549601 , @chandlerc wrote:

> OMG, I'm so sorry, I had no idea that the tests would explode like that... 
> Yeah, I don't think that's useful
>
> Maybe a better approach is to just explicitly run the code through `opt 
> -passes=instsimplify` before handing it to FileCheck? That should produce 
> almost identical results to the old PM's inliner?
>
> Feel free to just try this out and report back -- if it isn't looking good, 
> don't invest a bunch of time in it, we should talk to Craig and figure out 
> what the right long-term strategy here is.


Hmm so `-instsimplify` and combinations of other passes like `intsnamer` and 
`instcombine` don't seem to clean this up any further. The IR still differs 
between PMs (at -O0), and I can provide the diffs if necessary.

In the short term, I imagine an "ok" solution for now would be to just run the 
original tests with `-fno-experimental-new-pas-manager`, and either have a 
separate file with these new PM `-O1` checks at or separate runs in the same 
file to prevent regressions. I emailed Craig for his insight and info on these 
tests.

For now I reverted back to an early diff for this with the -O0 tests only.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63174



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


[PATCH] D62899: [analyzer][UninitializedObjectChecker] Mark uninitialized regions as interesting.

2019-06-19 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

In D62899#1549715 , @Szelethus wrote:

> Added a proper testfile. The only downside of it is that it doesn't test 
> anything.


Use creduce!


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

https://reviews.llvm.org/D62899



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


[PATCH] D63174: [clang][NewPM] Add RUNS for tests that produce slightly different IR under new PM

2019-06-19 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan updated this revision to Diff 205722.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63174

Files:
  clang/test/CodeGen/avx512-reduceMinMaxIntrin.c
  clang/test/CodeGen/avx512f-builtins.c
  clang/test/CodeGen/avx512vl-builtins.c
  clang/test/CodeGen/avx512vlbw-builtins.c
  clang/test/CodeGenOpenCL/convergent.cl

Index: clang/test/CodeGenOpenCL/convergent.cl
===
--- clang/test/CodeGenOpenCL/convergent.cl
+++ clang/test/CodeGenOpenCL/convergent.cl
@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 -triple spir-unknown-unknown -emit-llvm %s -o - | opt -instnamer -S | FileCheck -enable-var-scope %s
+// RUN: %clang_cc1 -triple spir-unknown-unknown -emit-llvm %s -o - -fno-experimental-new-pass-manager | opt -instnamer -S | FileCheck -enable-var-scope %s --check-prefixes=CHECK,CHECK-LEGACY
+// RUN: %clang_cc1 -triple spir-unknown-unknown -emit-llvm %s -o - -fexperimental-new-pass-manager | opt -instnamer -S | FileCheck -enable-var-scope %s --check-prefixes=CHECK,CHECK-NEWPM
 
 // This is initially assumed convergent, but can be deduced to not require it.
 
@@ -117,7 +118,12 @@
 // CHECK: [[for_body]]:
 // CHECK:  tail call spir_func void @nodupfun() #[[attr5:[0-9]+]]
 // CHECK-NOT: call spir_func void @nodupfun()
-// CHECK:  br i1 %{{.+}}, label %[[for_body]], label %[[for_cond_cleanup]]
+
+// The new PM produces a slightly different IR for the loop from the legacy PM,
+// but the test still checks that the loop is not unrolled.
+// CHECK-LEGACY:  br i1 %{{.+}}, label %[[for_body]], label %[[for_cond_cleanup]]
+// CHECK-NEW: br i1 %{{.+}}, label %[[for_body_crit_edge:.+]], label %[[for_cond_cleanup]]
+// CHECK-NEW: [[for_body_crit_edge]]:
 
 void test_not_unroll() {
   for (int i = 0; i < 10; i++)
Index: clang/test/CodeGen/avx512vlbw-builtins.c
===
--- clang/test/CodeGen/avx512vlbw-builtins.c
+++ clang/test/CodeGen/avx512vlbw-builtins.c
@@ -1,6 +1,10 @@
-// RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +avx512bw -target-feature +avx512vl -emit-llvm -o - -Wall -Werror | FileCheck %s
-// RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +avx512bw -target-feature +avx512vl -fno-signed-char -emit-llvm -o - -Wall -Werror | FileCheck %s
+// RUN: %clang_cc1 -ffreestanding %s -fno-experimental-new-pass-manager -triple=x86_64-apple-darwin -target-feature +avx512bw -target-feature +avx512vl -emit-llvm -o - -Wall -Werror | FileCheck %s
+// RUN: %clang_cc1 -ffreestanding %s -fno-experimental-new-pass-manager -triple=x86_64-apple-darwin -target-feature +avx512bw -target-feature +avx512vl -fno-signed-char -emit-llvm -o - -Wall -Werror | FileCheck %s
 
+// There are a few cases where instead accpeting the result of an instruction
+// directly as an argument to a select, it instead goes through some bitcasts.
+// RUN: %clang_cc1 -ffreestanding %s -fexperimental-new-pass-manager -triple=x86_64-apple-darwin -target-feature +avx512bw -target-feature +avx512vl -emit-llvm -o - -Wall -Werror | FileCheck %s --check-prefixes=CHECK,CHECK-NEWPM
+// RUN: %clang_cc1 -ffreestanding %s -fexperimental-new-pass-manager -triple=x86_64-apple-darwin -target-feature +avx512bw -target-feature +avx512vl -fno-signed-char -emit-llvm -o - -Wall -Werror | FileCheck %s --check-prefixes=CHECK,CHECK-NEWPM
 
 #include 
 
@@ -901,6 +905,8 @@
   // CHECK: [[SUB:%.*]] = sub <16 x i8> zeroinitializer, [[A:%.*]]
   // CHECK: [[CMP:%.*]] = icmp sgt <16 x i8> [[A]], zeroinitializer
   // CHECK: [[SEL:%.*]] = select <16 x i1> [[CMP]], <16 x i8> [[A]], <16 x i8> [[SUB]]
+  // CHECK-NEWPM: [[TMP:%.*]] = bitcast [[SRCTY:<.*>]] [[SEL]] to [[DSTTY:<.*>]]
+  // CHECK-NEWPM: [[SEL:%.*]] = bitcast [[DSTTY]] [[TMP]] to [[SRCTY]]
   // CHECK: select <16 x i1> %{{.*}}, <16 x i8> [[SEL]], <16 x i8> %{{.*}}
   return _mm_mask_abs_epi8(__W,__U,__A); 
 }
@@ -910,6 +916,8 @@
   // CHECK: [[SUB:%.*]] = sub <16 x i8> zeroinitializer, [[A:%.*]]
   // CHECK: [[CMP:%.*]] = icmp sgt <16 x i8> [[A]], zeroinitializer
   // CHECK: [[SEL:%.*]] = select <16 x i1> [[CMP]], <16 x i8> [[A]], <16 x i8> [[SUB]]
+  // CHECK-NEWPM: [[TMP:%.*]] = bitcast [[SRCTY:<.*>]] [[SEL]] to [[DSTTY:<.*>]]
+  // CHECK-NEWPM: [[SEL:%.*]] = bitcast [[DSTTY]] [[TMP]] to [[SRCTY]]
   // CHECK: select <16 x i1> %{{.*}}, <16 x i8> [[SEL]], <16 x i8> %{{.*}}
   return _mm_maskz_abs_epi8(__U,__A); 
 }
@@ -919,6 +927,8 @@
   // CHECK: [[SUB:%.*]] = sub <32 x i8> zeroinitializer, [[A:%.*]]
   // CHECK: [[CMP:%.*]] = icmp sgt <32 x i8> [[A]], zeroinitializer
   // CHECK: [[SEL:%.*]] = select <32 x i1> [[CMP]], <32 x i8> [[A]], <32 x i8> [[SUB]]
+  // CHECK-NEWPM: [[TMP:%.*]] = bitcast [[SRCTY:<.*>]] [[SEL]] to [[DSTTY:<.*>]]
+  // CHECK-NEWPM: [[SEL:%.*]] = bitcast [[DSTTY]] [[TMP]] to [[SRCTY]]
   // CHECK: select <32 x i1> %{{.*}}, <32 x i8> 

[PATCH] D62825: [C++2a] Add __builtin_bit_cast, used to implement std::bit_cast

2019-06-19 Thread Erik Pilkington via Phabricator via cfe-commits
erik.pilkington updated this revision to Diff 205713.
erik.pilkington marked 16 inline comments as done.
erik.pilkington added a comment.

Address review comments, thanks!


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

https://reviews.llvm.org/D62825

Files:
  clang/include/clang-c/Index.h
  clang/include/clang/AST/ExprCXX.h
  clang/include/clang/AST/OperationKinds.def
  clang/include/clang/AST/RecursiveASTVisitor.h
  clang/include/clang/Basic/DiagnosticASTKinds.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/StmtNodes.td
  clang/include/clang/Basic/TokenKinds.def
  clang/include/clang/Parse/Parser.h
  clang/include/clang/Sema/Sema.h
  clang/lib/AST/Expr.cpp
  clang/lib/AST/ExprClassification.cpp
  clang/lib/AST/ExprConstant.cpp
  clang/lib/AST/ItaniumMangle.cpp
  clang/lib/AST/StmtPrinter.cpp
  clang/lib/AST/StmtProfile.cpp
  clang/lib/CodeGen/CGExpr.cpp
  clang/lib/CodeGen/CGExprAgg.cpp
  clang/lib/CodeGen/CGExprComplex.cpp
  clang/lib/CodeGen/CGExprConstant.cpp
  clang/lib/CodeGen/CGExprScalar.cpp
  clang/lib/Edit/RewriteObjCFoundationAPI.cpp
  clang/lib/Lex/PPMacroExpansion.cpp
  clang/lib/Parse/ParseExpr.cpp
  clang/lib/Parse/ParseExprCXX.cpp
  clang/lib/Sema/SemaCast.cpp
  clang/lib/Sema/SemaExceptionSpec.cpp
  clang/lib/Sema/TreeTransform.h
  clang/lib/Serialization/ASTReaderStmt.cpp
  clang/lib/Serialization/ASTWriterStmt.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
  clang/lib/StaticAnalyzer/Core/ExprEngineC.cpp
  clang/test/CodeGenCXX/builtin-bit-cast-no-tbaa.cpp
  clang/test/CodeGenCXX/builtin-bit-cast.cpp
  clang/test/SemaCXX/builtin-bit-cast.cpp
  clang/test/SemaCXX/constexpr-builtin-bit-cast.cpp
  clang/tools/libclang/CIndex.cpp
  clang/tools/libclang/CXCursor.cpp
  llvm/include/llvm/ADT/APInt.h
  llvm/lib/ExecutionEngine/ExecutionEngine.cpp
  llvm/lib/Support/APInt.cpp

Index: llvm/lib/Support/APInt.cpp
===
--- llvm/lib/Support/APInt.cpp
+++ llvm/lib/Support/APInt.cpp
@@ -2929,3 +2929,56 @@
   LLVM_DEBUG(dbgs() << __func__ << ": solution (wrap): " << X << '\n');
   return X;
 }
+
+/// StoreIntToMemory - Fills the StoreBytes bytes of memory starting from Dst
+/// with the integer held in IntVal.
+void llvm::StoreIntToMemory(const APInt , uint8_t *Dst,
+unsigned StoreBytes) {
+  assert((IntVal.getBitWidth()+7)/8 >= StoreBytes && "Integer too small!");
+  const uint8_t *Src = (const uint8_t *)IntVal.getRawData();
+
+  if (sys::IsLittleEndianHost) {
+// Little-endian host - the source is ordered from LSB to MSB.  Order the
+// destination from LSB to MSB: Do a straight copy.
+memcpy(Dst, Src, StoreBytes);
+  } else {
+// Big-endian host - the source is an array of 64 bit words ordered from
+// LSW to MSW.  Each word is ordered from MSB to LSB.  Order the destination
+// from MSB to LSB: Reverse the word order, but not the bytes in a word.
+while (StoreBytes > sizeof(uint64_t)) {
+  StoreBytes -= sizeof(uint64_t);
+  // May not be aligned so use memcpy.
+  memcpy(Dst + StoreBytes, Src, sizeof(uint64_t));
+  Src += sizeof(uint64_t);
+}
+
+memcpy(Dst, Src + sizeof(uint64_t) - StoreBytes, StoreBytes);
+  }
+}
+
+/// LoadIntFromMemory - Loads the integer stored in the LoadBytes bytes starting
+/// from Src into IntVal, which is assumed to be wide enough and to hold zero.
+void llvm::LoadIntFromMemory(APInt , uint8_t *Src, unsigned LoadBytes) {
+  assert((IntVal.getBitWidth()+7)/8 >= LoadBytes && "Integer too small!");
+  uint8_t *Dst = reinterpret_cast(
+   const_cast(IntVal.getRawData()));
+
+  if (sys::IsLittleEndianHost)
+// Little-endian host - the destination must be ordered from LSB to MSB.
+// The source is ordered from LSB to MSB: Do a straight copy.
+memcpy(Dst, Src, LoadBytes);
+  else {
+// Big-endian - the destination is an array of 64 bit words ordered from
+// LSW to MSW.  Each word must be ordered from MSB to LSB.  The source is
+// ordered from MSB to LSB: Reverse the word order, but not the bytes in
+// a word.
+while (LoadBytes > sizeof(uint64_t)) {
+  LoadBytes -= sizeof(uint64_t);
+  // May not be aligned so use memcpy.
+  memcpy(Dst, Src + LoadBytes, sizeof(uint64_t));
+  Dst += sizeof(uint64_t);
+}
+
+memcpy(Dst + sizeof(uint64_t) - LoadBytes, Src, LoadBytes);
+  }
+}
Index: llvm/lib/ExecutionEngine/ExecutionEngine.cpp
===
--- llvm/lib/ExecutionEngine/ExecutionEngine.cpp
+++ llvm/lib/ExecutionEngine/ExecutionEngine.cpp
@@ -1019,32 +1019,6 @@
   return Result;
 }
 
-/// StoreIntToMemory - Fills the StoreBytes bytes of memory starting from Dst
-/// with the integer held in IntVal.
-static void StoreIntToMemory(const APInt , uint8_t *Dst,
- unsigned StoreBytes) {
-  assert((IntVal.getBitWidth()+7)/8 >= StoreBytes && 

[PATCH] D62825: [C++2a] Add __builtin_bit_cast, used to implement std::bit_cast

2019-06-19 Thread Erik Pilkington via Phabricator via cfe-commits
erik.pilkington added inline comments.



Comment at: clang/lib/AST/ExprConstant.cpp:5461-5469
+case APValue::LValue: {
+  LValue LVal;
+  LVal.setFrom(Info.Ctx, Val);
+  APValue RVal;
+  if (!handleLValueToRValueConversion(Info, BCE, Ty.withConst(),
+  LVal, RVal))
+return false;

rsmith wrote:
> This looks wrong: bitcasting a pointer should not dereference the pointer and 
> store its pointee! (Likewise for a reference member.) But I think this should 
> actually simply be unreachable: we already checked for pointers and reference 
> members in `checkBitCastConstexprEligibilityType`.
> 
> (However, I think it currently *is* reached, because there's also some cases 
> where the operand of the bitcast is an lvalue, and the resulting lvalue gets 
> misinterpreted as a value of the underlying type, landing us here. See below.)
Okay, the new patch moves the read to handleBitCast. I added an unreachable 
here. 



Comment at: clang/lib/AST/ExprConstant.cpp:5761-5764
+for (FieldDecl *FD : Record->fields()) {
+  if (!checkBitCastConstexprEligibilityType(Loc, FD->getType(), Info, Ctx))
+return note(0, FD->getType(), FD->getBeginLoc());
+}

rsmith wrote:
> The spec for `bit_cast` also asks us to check for members of reference type. 
> That can't happen because a type with reference members can never be 
> trivially-copyable, but please include an assert here to demonstrate to a 
> reader that we've thought about and handled that case.
Oh, it looks like the old patch crashed in this case! Turns out structs with 
reference members are trivially copyable.



Comment at: clang/lib/AST/ExprConstant.cpp:7098-7099
   case CK_BitCast:
+// CK_BitCast originating from a __builtin_bit_cast have different 
constexpr
+// semantics. This is only reachable when bit casting to nullptr_t.
+if (isa(E))

rsmith wrote:
> I think this is reversed from the way I'd think about it: casts to `void*` 
> are modeled as bit-casts, and so need special handling here. (Theoretically 
> it'd be preferable to call the base class function for all other kinds of 
> bitcast we encounter, but it turns out to not matter because only bitcasts to 
> `nullptr_t` are ever evaluatable currently. In future we might want to 
> support bit-casts between integers and pointers (for constant folding only), 
> and then it might matter.)
The new patch creates a special cast kind for this, so no changes here are 
necessary here.



Comment at: clang/test/CodeGenCXX/builtin-bit-cast.cpp:100-112
+void test_array(int ()[2]) {
+  // CHECK-LABEL: define void @_Z10test_arrayRA2_i
+  __builtin_bit_cast(unsigned long, ary);
+
+  // CHECK: [[ARY_PTR:%.*]] = alloca [2 x i32]*, align 8
+  // CHECK-NEXT: [[TEMP]] = alloca [2 x i32], align 8
+  // store ary into ARY_PTR

rsmith wrote:
> If we remove the `DefaultLvalueConversion` from building the bitcast 
> expression, we should be able to avoid the unnecessary extra alloca here, and 
> instead `memcpy` directly from `ary` to the `unsigned long`. (This is the 
> most important testcase in this file, since it's the only one that gives 
> `__builtin_bit_cast` an lvalue operand, which is what `std::bit_cast` will 
> do.)
`ScalarExprEmitter::VisitCastExpr` has to return a Value of type `i32` here 
though, so we don't know where to memcpy the array to when emitting the cast. I 
guess we could bitcast the pointer and load from it if the alignments are 
compatible, and fall back to a temporary otherwise (such as this case, where 
alignof(ary) is 4, but alignof(unsigned long) is 8). I think its more in the 
spirit of clang CodeGen to just emit simple code that always works though, then 
leave any optimizations to, well, the optimizer (assuming the `-O0` output 
isn't too horrible). We can use this CodeGen strategy for aggregate 
destinations, which the new patch does.

> This is the most important testcase in this file, since it's the only one 
> that gives __builtin_bit_cast an lvalue operand

Yeah, good point. New patch gives lvalue operands to the other calls.


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

https://reviews.llvm.org/D62825



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


[PATCH] D63361: Pretend NRVO variables are references so they can be found by debug info

2019-06-19 Thread Amy Huang via Phabricator via cfe-commits
akhuang added inline comments.



Comment at: clang/lib/CodeGen/CodeGenFunction.cpp:908
 --EI;
 llvm::Value *Addr = Builder.CreateStructGEP(nullptr, &*EI, Idx);
 Addr = Builder.CreateAlignedLoad(Addr, getPointerAlign(), "agg.result");

rnk wrote:
> akhuang wrote:
> > rnk wrote:
> > > What I had in mind was to use this GEP as the ReturnValuePointer here. 
> > > The inalloca parameter is also a pointer to stack memory, and a GEP is an 
> > > offset, so it should end up being handled like a static alloca.
> > Oh, ok. I changed it, but not sure how to test debug info for the inalloca 
> > case
> I don't think this is the correct alignment. The sret slot in the inalloca 
> has a pointer type, so I think you want pointer alignment here. I think you 
> can substitute Int8PtrTy for RetTy here.
I suppose getPointerAlign() should work?


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63361



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


[PATCH] D63361: Pretend NRVO variables are references so they can be found by debug info

2019-06-19 Thread Amy Huang via Phabricator via cfe-commits
akhuang updated this revision to Diff 205712.
akhuang marked 2 inline comments as done.
akhuang added a comment.
Herald added a subscriber: javed.absar.

- fix alignment of pointer in inalloca case
- make existing tests stop failing by changing some and adding a check for 
existing return value alloca (I think?) before adding the ReturnValuePointer 
alloca


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63361

Files:
  clang/lib/CodeGen/CGDebugInfo.cpp
  clang/lib/CodeGen/CGDebugInfo.h
  clang/lib/CodeGen/CGDecl.cpp
  clang/lib/CodeGen/CodeGenFunction.cpp
  clang/lib/CodeGen/CodeGenFunction.h
  clang/test/CodeGen/arm64-microsoft-arguments.cpp
  clang/test/CodeGenCXX/conditional-gnu-ext.cpp
  clang/test/CodeGenCXX/debug-info-nrvo.cpp
  clang/test/CodeGenCXX/lambda-expressions.cpp
  clang/test/CodeGenObjC/objc-non-trivial-struct-nrvo.m
  debuginfo-tests/nrvo-string.cpp
  debuginfo-tests/win_cdb/nrvo.cpp
  llvm/lib/CodeGen/AsmPrinter/CodeViewDebug.cpp
  llvm/test/DebugInfo/COFF/nrvo.ll

Index: llvm/test/DebugInfo/COFF/nrvo.ll
===
--- /dev/null
+++ llvm/test/DebugInfo/COFF/nrvo.ll
@@ -0,0 +1,144 @@
+; RUN: llc < %s | FileCheck %s --check-prefix=ASM
+; RUN: llc < %s -filetype=obj | llvm-readobj - --codeview | FileCheck %s --check-prefix=OBJ
+
+; C++ source to regenerate:
+; struct Foo {
+;   Foo() = default;
+;   Foo(Foo &) { x = other.x; }
+;   int x;
+; };
+; void some_function(int);
+; Foo getFoo() {
+;   Foo foo;
+;   foo.x = 41;
+;   some_function(foo.x);
+;   return foo;
+; }
+;
+; int main() {
+;   Foo bar = getFoo();
+;   return bar.x;
+; }
+; $ clang t.cpp -S -emit-llvm -g -o t.ll
+
+; ASM-LABEL:  .long  241  # Symbol subsection for GetFoo 
+; ASM:.short 4414 # Record kind: S_LOCAL
+; ASM-NEXT:   .long 4113  # TypeIndex
+; ASM-NEXT:   .short 0# Flags
+; ASM-NEXT:   .asciz "foo"
+; ASM-NEXT:   .p2align 2
+; ASM-NEXT: .Ltmp
+; ASM:.cv_def_range  .Ltmp{{.*}} .Ltmp{{.*}}, "B\021(\000\000\000"
+
+; OBJ: Subsection [
+; OBJ:   SubSectionType: Symbols (0xF1)
+; OBJ:   LocalSym {
+; OBJ: Kind: S_LOCAL (0x113E)
+; OBJ: Type: Foo& (0x1011)
+; OBJ: Flags [ (0x0)
+; OBJ: ]
+; OBJ: VarName: foo
+; OBJ:   }
+; OBJ:   DefRangeFramePointerRelSym {
+; OBJ: Kind: S_DEFRANGE_FRAMEPOINTER_REL (0x1142)
+; OBJ: Offset: 40
+; OBJ: LocalVariableAddrRange {
+; OBJ:   OffsetStart: .text+0x1D
+; OBJ:   ISectStart: 0x0
+; OBJ:   Range: 0x16
+; OBJ:   }
+
+; ModuleID = 't.cpp'
+source_filename = "t.cpp"
+target datalayout = "e-m:w-i64:64-f80:128-n8:16:32:64-S128"
+target triple = "x86_64-pc-windows-msvc19.16.27030"
+
+%struct.Foo = type { i32 }
+
+; Function Attrs: noinline nounwind optnone uwtable
+define dso_local void @"?some_function@@YAXH@Z"(i32) #0 !dbg !8 {
+entry:
+  %.addr = alloca i32, align 4
+  store i32 %0, i32* %.addr, align 4
+  call void @llvm.dbg.declare(metadata i32* %.addr, metadata !12, metadata !DIExpression()), !dbg !13
+  ret void, !dbg !13
+}
+
+; Function Attrs: nounwind readnone speculatable
+declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
+
+; Function Attrs: noinline nounwind optnone uwtable
+define dso_local void @"?GetFoo@@YA?AUFoo@@XZ"(%struct.Foo* noalias sret %agg.result) #0 !dbg !14 {
+entry:
+  %result.ptr = alloca i8*, align 8
+  %0 = bitcast %struct.Foo* %agg.result to i8*
+  store i8* %0, i8** %result.ptr, align 8
+  call void @llvm.dbg.declare(metadata i8** %result.ptr, metadata !28, metadata !DIExpression(DW_OP_deref)), !dbg !29
+  %x = getelementptr inbounds %struct.Foo, %struct.Foo* %agg.result, i32 0, i32 0, !dbg !30
+  store i32 41, i32* %x, align 4, !dbg !30
+  %x1 = getelementptr inbounds %struct.Foo, %struct.Foo* %agg.result, i32 0, i32 0, !dbg !31
+  %1 = load i32, i32* %x1, align 4, !dbg !31
+  call void @"?some_function@@YAXH@Z"(i32 %1), !dbg !31
+  ret void, !dbg !32
+}
+
+; Function Attrs: noinline norecurse nounwind optnone uwtable
+define dso_local i32 @main() #2 !dbg !33 {
+entry:
+  %retval = alloca i32, align 4
+  %bar = alloca %struct.Foo, align 4
+  store i32 0, i32* %retval, align 4
+  call void @llvm.dbg.declare(metadata %struct.Foo* %bar, metadata !36, metadata !DIExpression()), !dbg !37
+  call void @"?GetFoo@@YA?AUFoo@@XZ"(%struct.Foo* sret %bar), !dbg !37
+  %x = getelementptr inbounds %struct.Foo, %struct.Foo* %bar, i32 0, i32 0, !dbg !38
+  %0 = load i32, i32* %x, align 4, !dbg !38
+  ret i32 %0, !dbg !38
+}
+
+attributes #0 = { noinline nounwind optnone uwtable "correctly-rounded-divide-sqrt-fp-math"="false" "disable-tail-calls"="false" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="false" 

[PATCH] D63277: [CUDA][HIP] Don't set "comdat" attribute for CUDA device stub functions.

2019-06-19 Thread Konstantin Pyzhov via Phabricator via cfe-commits
kpyzhov added a comment.

In D63277#1550870 , @rjmccall wrote:

> This optimization is disabled for functions not in COMDAT sections?  Is that 
> documented somewhere?


It is documented here: 
https://docs.microsoft.com/en-us/cpp/build/reference/opt-optimizations?view=vs-2019


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

https://reviews.llvm.org/D63277



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


[PATCH] D63156: [clang][NewPM] Add -fno-experimental-new-pass-manager to tests

2019-06-19 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan added a comment.

>> **CodeGen/pgo-sample.c [No new fix]**: The test checks that `PruneEH` runs, 
>> but there doesn’t seem to be a corresponding new PM pass for it. Should 
>> there be? If there is one then we can just check for that in the debug PM 
>> dump.
> 
> The analog would be `function-attrs` and `function(simplify-cfg)` in some 
> combination. Maybe this should just check that some specific thing is 
> optimized away at `-O2` rather than checking the specific details of pass 
> pipeline construction?

For now I added a check that those 2 extra passes are run in the debug pass 
dump. It seems that the original test just wanted to see that a particular pass 
was run, so I left it at that, but I can still add a separate test/run for 
checking that `function-attrs` and `function(simplify-cfg)` replace `invoke` 
instructions at `-O2` (which is what I think PruneEH does).

> Yeah, I think the entry/exit pass really wants to come *before* any other 
> pass. That should be possible even in the new PM by using an extension point?

Moved this into D63577 .

>> **CodeGenCXX/conditional-temporaries.cpp**: The new pm seems to be unable to 
>> statically determine the return value of some functions. For now I just add 
>> separate checks for the new PM IR.
> 
> Interesting. Definitely the right thing for this patch. Maybe file a PR to 
> track understanding why the new PM struggles here.
> 
>> **CodeGenCXX/member-function-pointer-calls.cpp**: Same as 
>> `CodeGenCXX/conditional-temporaries.cpp`. In this case, the new PM codegen 
>> also contains calls to lifetime start/end intrinsics. Perhaps this time it 
>> could be due to the intrinsics not being optimized out?
> 
> Weird, but that's also my best guess. Again, maybe we need a bug to track why 
> this is different.

Created https://bugs.llvm.org/show_bug.cgi?id=42333 to track these 2.

>> **CodeGenObjC/os_log.m**: Legacy test expects argument of `ptrtoint` and 
>> some functions to be a specific type and argument, though the new PM codegen 
>> uses a different type and argument which are also valid since 
>> `@llvm.objc.retainAutoreleasedReturnValue(val)` always returns `val`.
>> 
>> **CodeGenObjCXX/os_log.mm**: A function seems to have been inlined under the 
>> new PM. Here we just prevent inlining for the new PM run since the test 
>> expects this specific function call.
> 
> You could also use a `noinline` attribute in the code to express the 
> *specific* call that needs to be retained?

Hmm `noinline` doesn't seem to be working in this case. The call is made to a 
code generated builtin function (`__os_log_helper`).




Comment at: clang/lib/CodeGen/BackendUtil.cpp:1135-1139
+  PB.registerOptimizerLastEPCallback(
+  [](FunctionPassManager , PassBuilder::OptimizationLevel Level) {
+FPM.addPass(EntryExitInstrumenterPass(/*PostInlining=*/false));
+  });
+

chandlerc wrote:
> FYI, feel free to split out the entry/exit change (and its test) to a 
> separate patch if you want. Either way really.
Separated this into D63577



Comment at: llvm/lib/Passes/PassBuilder.cpp:815-818
+  // running remaining passes on the eliminated functions. These should be
+  // preserved during prelinking for link-time inlining decisions.
+  if (!LTOPreLink)
+MPM.addPass(EliminateAvailableExternallyPass());

chandlerc wrote:
> I'd suggest splitting this into a separate patch to LLVM and adding an 
> LLVM-side test to cover it as well.
Separated this into D63580 and added an LLVM test in that one


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63156



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


[PATCH] D63174: [clang][NewPM] Add RUNS for tests that produce slightly different IR under new PM

2019-06-19 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan updated this revision to Diff 205707.
Herald added subscribers: dexonsmith, steven_wu, javed.absar, mehdi_amini.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63174

Files:
  clang/test/CodeGen/aggregate-assign-call.c
  clang/test/CodeGen/arm_acle.c
  clang/test/CodeGen/cspgo-instrumentation.c
  clang/test/CodeGen/cspgo-instrumentation_lto.c
  clang/test/CodeGen/cspgo-instrumentation_thinlto.c
  clang/test/CodeGen/pgo-instrumentation.c
  clang/test/CodeGen/pgo-sample.c
  clang/test/CodeGen/thinlto-debug-pm.c
  clang/test/CodeGenCXX/auto-var-init.cpp
  clang/test/CodeGenCXX/conditional-temporaries.cpp
  clang/test/CodeGenCXX/member-function-pointer-calls.cpp
  clang/test/CodeGenObjC/os_log.m
  clang/test/CodeGenObjCXX/os_log.mm
  clang/test/Misc/pr32207.c

Index: clang/test/Misc/pr32207.c
===
--- clang/test/Misc/pr32207.c
+++ clang/test/Misc/pr32207.c
@@ -1,4 +1,4 @@
 // test for r305179
-// RUN: %clang_cc1 -emit-llvm -O -mllvm -print-after-all %s -o %t 2>&1 | FileCheck %s
+// RUN: %clang_cc1 -emit-llvm -O2 -fno-experimental-new-pass-manager -mllvm -print-after-all %s -o %t 2>&1 | FileCheck %s
 // CHECK: *** IR Dump After Function Integration/Inlining ***
 void foo() {}
Index: clang/test/CodeGenObjCXX/os_log.mm
===
--- clang/test/CodeGenObjCXX/os_log.mm
+++ clang/test/CodeGenObjCXX/os_log.mm
@@ -1,5 +1,7 @@
 // RUN: %clang_cc1 %s -emit-llvm -o - -triple x86_64-darwin-apple -fobjc-arc \
-// RUN:   -fexceptions -fcxx-exceptions -O1 | FileCheck %s
+// RUN:   -fexceptions -fcxx-exceptions -O1 -fno-experimental-new-pass-manager | FileCheck %s
+// RUN: %clang_cc1 %s -emit-llvm -o - -triple x86_64-darwin-apple -fobjc-arc \
+// RUN:   -fexceptions -fcxx-exceptions -O1 -fexperimental-new-pass-manager -fno-inline | FileCheck %s
 
 // Check that no EH cleanup is emitted around the call to __os_log_helper.
 namespace no_eh_cleanup {
Index: clang/test/CodeGenObjC/os_log.m
===
--- clang/test/CodeGenObjC/os_log.m
+++ clang/test/CodeGenObjC/os_log.m
@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 %s -emit-llvm -o - -triple x86_64-darwin-apple -fobjc-arc -O2 | FileCheck %s
+// RUN: %clang_cc1 %s -emit-llvm -o - -triple x86_64-darwin-apple -fobjc-arc -O2 -fno-experimental-new-pass-manager | FileCheck %s --check-prefixes=CHECK,CHECK-LEGACY
+// RUN: %clang_cc1 %s -emit-llvm -o - -triple x86_64-darwin-apple -fobjc-arc -O2 -fexperimental-new-pass-manager | FileCheck %s --check-prefixes=CHECK,CHECK-NEWPM
 // RUN: %clang_cc1 %s -emit-llvm -o - -triple x86_64-darwin-apple -fobjc-arc -O0 | FileCheck %s -check-prefix=CHECK-O0
 
 // Make sure we emit clang.arc.use before calling objc_release as part of the
@@ -22,7 +23,8 @@
   // CHECK: %[[CALL:.*]] = tail call %[[TY0:.*]]* (...) @GenString()
   // CHECK: %[[V0:.*]] = bitcast %[[TY0]]* %[[CALL]] to i8*
   // CHECK: %[[V1:.*]] = notail call i8* @llvm.objc.retainAutoreleasedReturnValue(i8* %[[V0]])
-  // CHECK: %[[V2:.*]] = ptrtoint %[[TY0]]* %[[CALL]] to i64
+  // CHECK-LEGACY: %[[V2:.*]] = ptrtoint %[[TY0]]* %[[CALL]] to i64
+  // CHECK-NEWPM: %[[V2:.*]] = ptrtoint i8* %[[V1]] to i64
   // CHECK: store i8 2, i8* %[[BUF]], align 1
   // CHECK: %[[NUMARGS_I:.*]] = getelementptr i8, i8* %[[BUF]], i64 1
   // CHECK: store i8 1, i8* %[[NUMARGS_I]], align 1
@@ -33,8 +35,10 @@
   // CHECK: %[[ARGDATA_I:.*]] = getelementptr i8, i8* %[[BUF]], i64 4
   // CHECK: %[[ARGDATACAST_I:.*]] = bitcast i8* %[[ARGDATA_I]] to i64*
   // CHECK: store i64 %[[V2]], i64* %[[ARGDATACAST_I]], align 1
-  // CHECK: tail call void (...) @llvm.objc.clang.arc.use(%[[TY0]]* %[[CALL]])
-  // CHECK: tail call void @llvm.objc.release(i8* %[[V0]])
+  // CHECK-LEGACY: tail call void (...) @llvm.objc.clang.arc.use(%[[TY0]]* %[[CALL]])
+  // CHECK-LEGACY: tail call void @llvm.objc.release(i8* %[[V0]])
+  // CHECK-NEWPM: tail call void (...) @llvm.objc.clang.arc.use(i8* %[[V1]])
+  // CHECK-NEWPM: tail call void @llvm.objc.release(i8* %[[V1]])
   // CHECK: ret i8* %[[BUF]]
 
   // clang.arc.use is used and removed in IR optimizations. At O0, we should not
Index: clang/test/CodeGenCXX/member-function-pointer-calls.cpp
===
--- clang/test/CodeGenCXX/member-function-pointer-calls.cpp
+++ clang/test/CodeGenCXX/member-function-pointer-calls.cpp
@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -O3 -o - | FileCheck %s
+// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -O3 -fno-experimental-new-pass-manager  -o - | FileCheck %s --check-prefixes=CHECK,CHECK-LEGACY
+// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -O3 -fexperimental-new-pass-manager  -o - | FileCheck %s --check-prefixes=CHECK,CHECK-NEWPM
 // RUN: %clang_cc1 %s 

[PATCH] D63156: [clang][NewPM] Add -fno-experimental-new-pass-manager to tests

2019-06-19 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan updated this revision to Diff 205708.
leonardchan marked 3 inline comments as done.

Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63156

Files:
  clang/test/CodeGen/aggregate-assign-call.c
  clang/test/CodeGen/arm_acle.c
  clang/test/CodeGen/cspgo-instrumentation.c
  clang/test/CodeGen/cspgo-instrumentation_lto.c
  clang/test/CodeGen/cspgo-instrumentation_thinlto.c
  clang/test/CodeGen/pgo-instrumentation.c
  clang/test/CodeGen/pgo-sample.c
  clang/test/CodeGen/thinlto-debug-pm.c
  clang/test/CodeGenCXX/auto-var-init.cpp
  clang/test/CodeGenCXX/conditional-temporaries.cpp
  clang/test/CodeGenCXX/member-function-pointer-calls.cpp
  clang/test/CodeGenObjC/os_log.m
  clang/test/CodeGenObjCXX/os_log.mm
  clang/test/Misc/pr32207.c

Index: clang/test/Misc/pr32207.c
===
--- clang/test/Misc/pr32207.c
+++ clang/test/Misc/pr32207.c
@@ -1,4 +1,4 @@
 // test for r305179
-// RUN: %clang_cc1 -emit-llvm -O -mllvm -print-after-all %s -o %t 2>&1 | FileCheck %s
+// RUN: %clang_cc1 -emit-llvm -O2 -fno-experimental-new-pass-manager -mllvm -print-after-all %s -o %t 2>&1 | FileCheck %s
 // CHECK: *** IR Dump After Function Integration/Inlining ***
 void foo() {}
Index: clang/test/CodeGenObjCXX/os_log.mm
===
--- clang/test/CodeGenObjCXX/os_log.mm
+++ clang/test/CodeGenObjCXX/os_log.mm
@@ -1,5 +1,7 @@
 // RUN: %clang_cc1 %s -emit-llvm -o - -triple x86_64-darwin-apple -fobjc-arc \
-// RUN:   -fexceptions -fcxx-exceptions -O1 | FileCheck %s
+// RUN:   -fexceptions -fcxx-exceptions -O1 -fno-experimental-new-pass-manager | FileCheck %s
+// RUN: %clang_cc1 %s -emit-llvm -o - -triple x86_64-darwin-apple -fobjc-arc \
+// RUN:   -fexceptions -fcxx-exceptions -O1 -fexperimental-new-pass-manager -fno-inline | FileCheck %s
 
 // Check that no EH cleanup is emitted around the call to __os_log_helper.
 namespace no_eh_cleanup {
Index: clang/test/CodeGenObjC/os_log.m
===
--- clang/test/CodeGenObjC/os_log.m
+++ clang/test/CodeGenObjC/os_log.m
@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 %s -emit-llvm -o - -triple x86_64-darwin-apple -fobjc-arc -O2 | FileCheck %s
+// RUN: %clang_cc1 %s -emit-llvm -o - -triple x86_64-darwin-apple -fobjc-arc -O2 -fno-experimental-new-pass-manager | FileCheck %s --check-prefixes=CHECK,CHECK-LEGACY
+// RUN: %clang_cc1 %s -emit-llvm -o - -triple x86_64-darwin-apple -fobjc-arc -O2 -fexperimental-new-pass-manager | FileCheck %s --check-prefixes=CHECK,CHECK-NEWPM
 // RUN: %clang_cc1 %s -emit-llvm -o - -triple x86_64-darwin-apple -fobjc-arc -O0 | FileCheck %s -check-prefix=CHECK-O0
 
 // Make sure we emit clang.arc.use before calling objc_release as part of the
@@ -22,7 +23,8 @@
   // CHECK: %[[CALL:.*]] = tail call %[[TY0:.*]]* (...) @GenString()
   // CHECK: %[[V0:.*]] = bitcast %[[TY0]]* %[[CALL]] to i8*
   // CHECK: %[[V1:.*]] = notail call i8* @llvm.objc.retainAutoreleasedReturnValue(i8* %[[V0]])
-  // CHECK: %[[V2:.*]] = ptrtoint %[[TY0]]* %[[CALL]] to i64
+  // CHECK-LEGACY: %[[V2:.*]] = ptrtoint %[[TY0]]* %[[CALL]] to i64
+  // CHECK-NEWPM: %[[V2:.*]] = ptrtoint i8* %[[V1]] to i64
   // CHECK: store i8 2, i8* %[[BUF]], align 1
   // CHECK: %[[NUMARGS_I:.*]] = getelementptr i8, i8* %[[BUF]], i64 1
   // CHECK: store i8 1, i8* %[[NUMARGS_I]], align 1
@@ -33,8 +35,10 @@
   // CHECK: %[[ARGDATA_I:.*]] = getelementptr i8, i8* %[[BUF]], i64 4
   // CHECK: %[[ARGDATACAST_I:.*]] = bitcast i8* %[[ARGDATA_I]] to i64*
   // CHECK: store i64 %[[V2]], i64* %[[ARGDATACAST_I]], align 1
-  // CHECK: tail call void (...) @llvm.objc.clang.arc.use(%[[TY0]]* %[[CALL]])
-  // CHECK: tail call void @llvm.objc.release(i8* %[[V0]])
+  // CHECK-LEGACY: tail call void (...) @llvm.objc.clang.arc.use(%[[TY0]]* %[[CALL]])
+  // CHECK-LEGACY: tail call void @llvm.objc.release(i8* %[[V0]])
+  // CHECK-NEWPM: tail call void (...) @llvm.objc.clang.arc.use(i8* %[[V1]])
+  // CHECK-NEWPM: tail call void @llvm.objc.release(i8* %[[V1]])
   // CHECK: ret i8* %[[BUF]]
 
   // clang.arc.use is used and removed in IR optimizations. At O0, we should not
Index: clang/test/CodeGenCXX/member-function-pointer-calls.cpp
===
--- clang/test/CodeGenCXX/member-function-pointer-calls.cpp
+++ clang/test/CodeGenCXX/member-function-pointer-calls.cpp
@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -O3 -o - | FileCheck %s
+// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -O3 -fno-experimental-new-pass-manager  -o - | FileCheck %s --check-prefixes=CHECK,CHECK-LEGACY
+// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -O3 -fexperimental-new-pass-manager  -o - | FileCheck %s --check-prefixes=CHECK,CHECK-NEWPM
 // RUN: %clang_cc1 %s -triple=x86_64-windows-gnu -emit-llvm -o - | 

RE: r363855 - [clang] Adapt ASTMatcher to explicit(bool) specifier

2019-06-19 Thread via cfe-commits
Hi Gauthier,

Your commit seemed to have broken the build on Windows. Can you take a look?

http://lab.llvm.org:8011/builders/llvm-clang-lld-x86_64-scei-ps4-windows10pro-fast/builds/110

494.204 [1215/36/2881] Linking CXX executable bin\clang-query.exe
FAILED: bin/clang-query.exe 
cmd.exe /C "cd . && "C:\Program Files (x86)\CMake\bin\cmake.exe" -E vs_link_exe 
--intdir=tools\clang\tools\extra\clang-query\tool\CMakeFiles\clang-query.dir 
--manifests  -- 
C:\PROGRA~2\MIB055~1\2017\COMMUN~1\VC\Tools\MSVC\1416~1.270\bin\Hostx64\x64\link.exe
 /nologo 
tools\clang\tools\extra\clang-query\tool\CMakeFiles\clang-query.dir\ClangQuery.cpp.obj
 
tools\clang\tools\extra\clang-query\tool\CMakeFiles\clang-query.dir\__\__\__\__\__\__\resources\windows_version_resource.rc.res
  /out:bin\clang-query.exe /implib:lib\clang-query.lib /pdb:bin\clang-query.pdb 
/version:0.0  /machine:x64 /STACK:1000 /INCREMENTAL:NO /subsystem:console  
lib\LLVMLineEditor.lib lib\LLVMSupport.lib lib\clangAST.lib 
lib\clangASTMatchers.lib lib\clangBasic.lib lib\clangDynamicASTMatchers.lib 
lib\clangFrontend.lib lib\clangQuery.lib lib\clangSerialization.lib 
lib\clangTooling.lib lib\LLVMLineEditor.lib lib\clangDynamicASTMatchers.lib 
lib\clangFrontend.lib lib\clangParse.lib lib\LLVMMCParser.lib 
lib\LLVMProfileData.lib lib\clangSerialization.lib lib\clangSema.lib 
lib\clangEdit.lib lib\clangAnalysis.lib lib\clangASTMatchers.lib 
lib\LLVMBitReader.lib lib\clangDriver.lib version.lib lib\LLVMOption.lib 
lib\clangFormat.lib lib\clangToolingInclusions.lib lib\clangToolingCore.lib 
lib\clangAST.lib lib\clangRewrite.lib lib\clangLex.lib lib\clangBasic.lib 
lib\LLVMCore.lib lib\LLVMRemarks.lib lib\LLVMMC.lib lib\LLVMBinaryFormat.lib 
lib\LLVMDebugInfoCodeView.lib lib\LLVMDebugInfoMSF.lib lib\LLVMSupport.lib 
psapi.lib shell32.lib ole32.lib uuid.lib advapi32.lib delayimp.lib 
-delayload:shell32.dll -delayload:ole32.dll lib\LLVMDemangle.lib kernel32.lib 
user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib 
comdlg32.lib advapi32.lib && cd ."
LINK: command 
"C:\PROGRA~2\MIB055~1\2017\COMMUN~1\VC\Tools\MSVC\1416~1.270\bin\Hostx64\x64\link.exe
 /nologo 
tools\clang\tools\extra\clang-query\tool\CMakeFiles\clang-query.dir\ClangQuery.cpp.obj
 
tools\clang\tools\extra\clang-query\tool\CMakeFiles\clang-query.dir\__\__\__\__\__\__\resources\windows_version_resource.rc.res
 /out:bin\clang-query.exe /implib:lib\clang-query.lib /pdb:bin\clang-query.pdb 
/version:0.0 /machine:x64 /STACK:1000 /INCREMENTAL:NO /subsystem:console 
lib\LLVMLineEditor.lib lib\LLVMSupport.lib lib\clangAST.lib 
lib\clangASTMatchers.lib lib\clangBasic.lib lib\clangDynamicASTMatchers.lib 
lib\clangFrontend.lib lib\clangQuery.lib lib\clangSerialization.lib 
lib\clangTooling.lib lib\LLVMLineEditor.lib lib\clangDynamicASTMatchers.lib 
lib\clangFrontend.lib lib\clangParse.lib lib\LLVMMCParser.lib 
lib\LLVMProfileData.lib lib\clangSerialization.lib lib\clangSema.lib 
lib\clangEdit.lib lib\clangAnalysis.lib lib\clangASTMatchers.lib 
lib\LLVMBitReader.lib lib\clangDriver.lib version.lib lib\LLVMOption.lib 
lib\clangFormat.lib lib\clangToolingInclusions.lib lib\clangToolingCore.lib 
lib\clangAST.lib lib\clangRewrite.lib lib\clangLex.lib lib\clangBasic.lib 
lib\LLVMCore.lib lib\LLVMRemarks.lib lib\LLVMMC.lib lib\LLVMBinaryFormat.lib 
lib\LLVMDebugInfoCodeView.lib lib\LLVMDebugInfoMSF.lib lib\LLVMSupport.lib 
psapi.lib shell32.lib ole32.lib uuid.lib advapi32.lib delayimp.lib 
-delayload:shell32.dll -delayload:ole32.dll lib\LLVMDemangle.lib kernel32.lib 
user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib 
comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:bin\clang-query.exe.manifest" 
failed (exit code 1120) with the following output:
clangDynamicASTMatchers.lib(Registry.cpp.obj) : error LNK2019: unresolved 
external symbol "class 
clang::ast_matchers::internal::VariadicDynCastAllOfMatcher const 
clang::ast_matchers::cxxDeductionGuideDecl" 
(?cxxDeductionGuideDecl@ast_matchers@clang@@3V?$VariadicDynCastAllOfMatcher@VDecl@clang@@VCXXDeductionGuideDecl@2@@internal@12@B)
 referenced in function "public: __cdecl 
clang::ast_matchers::dynamic::`anonymous 
namespace'::RegistryMaps::RegistryMaps(void)" 
(??0RegistryMaps@?A0x914e59e4@dynamic@ast_matchers@clang@@QEAA@XZ)
bin\clang-query.exe : fatal error LNK1120: 1 unresolved externals

Douglas Yung

-Original Message-
From: cfe-commits  On Behalf Of Gauthier 
Harnisch via cfe-commits
Sent: Wednesday, June 19, 2019 11:28
To: cfe-commits@lists.llvm.org
Subject: r363855 - [clang] Adapt ASTMatcher to explicit(bool) specifier

Author: tyker
Date: Wed Jun 19 11:27:56 2019
New Revision: 363855

URL: http://llvm.org/viewvc/llvm-project?rev=363855=rev
Log:
[clang] Adapt ASTMatcher to explicit(bool) specifier

Summary:
Changes:
 - add an ast matcher for deductiong guide.
 - allow isExplicit matcher for deductiong guide.
 - add hasExplicitSpecifier matcher which give access to the expression of the 
explicit 

[PATCH] D63227: [analyzer] Better timers.

2019-06-19 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ marked an inline comment as done.
NoQ added inline comments.



Comment at: clang/lib/StaticAnalyzer/Core/ExprEngine.cpp:228
 
-ExprEngine::~ExprEngine() {
-  BR.FlushReports();

xazax.hun wrote:
> Hmm. Maybe add an assert that all the bug reports are flushed at this point? 
> Just to make sure we never need this :) I am not insisting on this change 
> just wondering.
Actually we already have the same code in `~BugReporter` itself, so this 
assertion would be kinda trivial. Like, it wouldn't necessarily hold, as the 
destructor for the field hasn't been executed at this point, but it's still 
useless, because the destructor will be executed very soon.


Repository:
  rC Clang

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

https://reviews.llvm.org/D63227



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


[PATCH] D62761: [analyzer] exploded-graph-rewriter: Implement a --diff mode.

2019-06-19 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL363898: [analyzer] exploded-graph-rewriter: Implement a 
--diff mode. (authored by dergachev, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D62761?vs=205443=205706#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D62761

Files:
  cfe/trunk/test/Analysis/exploded-graph-rewriter/environment_diff.dot
  cfe/trunk/test/Analysis/exploded-graph-rewriter/program_points.dot
  cfe/trunk/test/Analysis/exploded-graph-rewriter/store.dot
  cfe/trunk/test/Analysis/exploded-graph-rewriter/store_diff.dot
  cfe/trunk/utils/analyzer/exploded-graph-rewriter.py

Index: cfe/trunk/utils/analyzer/exploded-graph-rewriter.py
===
--- cfe/trunk/utils/analyzer/exploded-graph-rewriter.py
+++ cfe/trunk/utils/analyzer/exploded-graph-rewriter.py
@@ -18,6 +18,13 @@
 import re
 
 
+# A helper function for finding the difference between two dictionaries.
+def diff_dicts(curr, prev):
+removed = [k for k in prev if k not in curr or curr[k] != prev[k]]
+added = [k for k in curr if k not in prev or curr[k] != prev[k]]
+return (removed, added)
+
+
 # A deserialized source location.
 class SourceLocation(object):
 def __init__(self, json_loc):
@@ -47,13 +54,21 @@
 self.block_id = json_pp['block_id']
 
 
-# A value of a single expression in a deserialized Environment.
-class EnvironmentBinding(object):
-def __init__(self, json_eb):
-super(EnvironmentBinding, self).__init__()
-self.stmt_id = json_eb['stmt_id']
-self.pretty = json_eb['pretty']
-self.value = json_eb['value']
+# A single expression acting as a key in a deserialized Environment.
+class EnvironmentBindingKey(object):
+def __init__(self, json_ek):
+super(EnvironmentBindingKey, self).__init__()
+self.stmt_id = json_ek['stmt_id']
+self.pretty = json_ek['pretty']
+
+def _key(self):
+return self.stmt_id
+
+def __eq__(self, other):
+return self._key() == other._key()
+
+def __hash__(self):
+return hash(self._key())
 
 
 # Deserialized description of a location context.
@@ -65,6 +80,15 @@
 self.decl = json_frame['calling']
 self.line = json_frame['call_line']
 
+def _key(self):
+return self.lctx_id
+
+def __eq__(self, other):
+return self._key() == other._key()
+
+def __hash__(self):
+return hash(self._key())
+
 
 # A group of deserialized Environment bindings that correspond to a specific
 # location context.
@@ -72,8 +96,17 @@
 def __init__(self, json_frame):
 super(EnvironmentFrame, self).__init__()
 self.location_context = LocationContext(json_frame)
-self.bindings = [EnvironmentBinding(b) for b in json_frame['items']] \
-if json_frame['items'] is not None else []
+self.bindings = collections.OrderedDict(
+[(EnvironmentBindingKey(b),
+  b['value']) for b in json_frame['items']]
+if json_frame['items'] is not None else [])
+
+def diff_bindings(self, prev):
+return diff_dicts(self.bindings, prev.bindings)
+
+def is_different(self, prev):
+removed, added = self.diff_bindings(prev)
+return len(removed) != 0 or len(added) != 0
 
 
 # A deserialized Environment.
@@ -82,14 +115,46 @@
 super(Environment, self).__init__()
 self.frames = [EnvironmentFrame(f) for f in json_e]
 
+def diff_frames(self, prev):
+# TODO: It's difficult to display a good diff when frame numbers shift.
+if len(self.frames) != len(prev.frames):
+return None
+
+updated = []
+for i in range(len(self.frames)):
+f = self.frames[i]
+prev_f = prev.frames[i]
+if f.location_context == prev_f.location_context:
+if f.is_different(prev_f):
+updated.append(i)
+else:
+# We have the whole frame replaced with another frame.
+# TODO: Produce a nice diff.
+return None
+
+# TODO: Add support for added/removed.
+return updated
+
+def is_different(self, prev):
+updated = self.diff_frames(prev)
+return updated is None or len(updated) > 0
+
+
+# A single binding key in a deserialized RegionStore cluster.
+class StoreBindingKey(object):
+def __init__(self, json_sk):
+super(StoreBindingKey, self).__init__()
+self.kind = json_sk['kind']
+self.offset = json_sk['offset']
+
+def _key(self):
+return (self.kind, self.offset)
 
-# A single binding in a deserialized RegionStore cluster.
-class StoreBinding(object):
-def __init__(self, json_sb):
-super(StoreBinding, 

[PATCH] D63580: [clang][NewPM] Do not eliminate available_externally durng `-O2 -flto` runs

2019-06-19 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan created this revision.
leonardchan added reviewers: chandlerc, phosek, echristo, serge-sans-paille.
leonardchan added a project: clang.
Herald added subscribers: llvm-commits, dexonsmith, steven_wu, hiraditya, 
inglorion, mehdi_amini.
Herald added a project: LLVM.

This fixes `CodeGen/available-externally-suppress.c` when the new pass manager 
is turned on by default. `available_externally` was not emitted during `-O2 
-flto` runs when it should still be retained for link time inlining purposes. 
This can be fixed by checking that we aren't LTOPrelinking when adding the 
`EliminateAvailableExternallyPass`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D63580

Files:
  clang/test/CodeGen/available-externally-suppress.c
  llvm/lib/Passes/PassBuilder.cpp
  llvm/test/Other/available-externally-lto.ll


Index: llvm/test/Other/available-externally-lto.ll
===
--- /dev/null
+++ llvm/test/Other/available-externally-lto.ll
@@ -0,0 +1,21 @@
+; Ensure that we don't emit available_externally functions at -O2, unless 
-flto is present in which case we should preserve them for link-time inlining 
decisions.
+; RUN: opt < %s -S -passes='default' | FileCheck %s
+; RUN: opt < %s -S -passes='lto-pre-link' | FileCheck %s --check-prefix=LTO
+
+@x = common local_unnamed_addr global i32 0, align 4
+
+define void @test() local_unnamed_addr #0 {
+entry:
+  tail call void @f0(i32 17)
+  ret void
+}
+
+; CHECK: declare void @f0(i32)
+; LTO: define available_externally void @f0(i32 %y)
+define available_externally void @f0(i32 %y) local_unnamed_addr #0 {
+entry:
+  store i32 %y, i32* @x, align 4
+  ret void
+}
+
+attributes #0 = { noinline }
Index: llvm/lib/Passes/PassBuilder.cpp
===
--- llvm/lib/Passes/PassBuilder.cpp
+++ llvm/lib/Passes/PassBuilder.cpp
@@ -812,8 +812,10 @@
   // available externally globals. Eventually they will be suppressed during
   // codegen, but eliminating here enables more opportunity for GlobalDCE as it
   // may make globals referenced by available external functions dead and saves
-  // running remaining passes on the eliminated functions.
-  MPM.addPass(EliminateAvailableExternallyPass());
+  // running remaining passes on the eliminated functions. These should be
+  // preserved during prelinking for link-time inlining decisions.
+  if (!LTOPreLink)
+MPM.addPass(EliminateAvailableExternallyPass());
 
   if (EnableOrderFileInstrumentation)
 MPM.addPass(InstrOrderFilePass());
Index: clang/test/CodeGen/available-externally-suppress.c
===
--- clang/test/CodeGen/available-externally-suppress.c
+++ clang/test/CodeGen/available-externally-suppress.c
@@ -1,6 +1,9 @@
-// RUN: %clang_cc1 -emit-llvm -o - -triple x86_64-apple-darwin10 %s | 
FileCheck %s
-// RUN: %clang_cc1 -O2 -fno-inline -emit-llvm -o - -triple 
x86_64-apple-darwin10 %s | FileCheck %s
-// RUN: %clang_cc1 -flto -O2 -fno-inline -emit-llvm -o - -triple 
x86_64-apple-darwin10 %s | FileCheck %s -check-prefix=LTO
+// RUN: %clang_cc1 -fno-experimental-new-pass-manager -emit-llvm -o - -triple 
x86_64-apple-darwin10 %s | FileCheck %s
+// RUN: %clang_cc1 -fno-experimental-new-pass-manager -O2 -fno-inline 
-emit-llvm -o - -triple x86_64-apple-darwin10 %s | FileCheck %s
+// RUN: %clang_cc1 -fno-experimental-new-pass-manager -flto -O2 -fno-inline 
-emit-llvm -o - -triple x86_64-apple-darwin10 %s | FileCheck %s 
-check-prefix=LTO
+// RUN: %clang_cc1 -fexperimental-new-pass-manager -emit-llvm -o - -triple 
x86_64-apple-darwin10 %s | FileCheck %s
+// RUN: %clang_cc1 -fexperimental-new-pass-manager -O2 -fno-inline -emit-llvm 
-o - -triple x86_64-apple-darwin10 %s | FileCheck %s
+// RUN: %clang_cc1 -fexperimental-new-pass-manager -flto -O2 -fno-inline 
-emit-llvm -o - -triple x86_64-apple-darwin10 %s | FileCheck %s 
-check-prefix=LTO
 
 // Ensure that we don't emit available_externally functions at -O0.
 // Also should not emit them at -O2, unless -flto is present in which case


Index: llvm/test/Other/available-externally-lto.ll
===
--- /dev/null
+++ llvm/test/Other/available-externally-lto.ll
@@ -0,0 +1,21 @@
+; Ensure that we don't emit available_externally functions at -O2, unless -flto is present in which case we should preserve them for link-time inlining decisions.
+; RUN: opt < %s -S -passes='default' | FileCheck %s
+; RUN: opt < %s -S -passes='lto-pre-link' | FileCheck %s --check-prefix=LTO
+
+@x = common local_unnamed_addr global i32 0, align 4
+
+define void @test() local_unnamed_addr #0 {
+entry:
+  tail call void @f0(i32 17)
+  ret void
+}
+
+; CHECK: declare void @f0(i32)
+; LTO: define available_externally void @f0(i32 %y)
+define available_externally void @f0(i32 %y) local_unnamed_addr #0 {
+entry:
+  store i32 %y, i32* @x, align 4
+  ret void
+}
+

[PATCH] D63519: [analyzer] exploded-graph-rewriter: Fix escaping and unescaping of StringRegions.

2019-06-19 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL363897: [analyzer] exploded-graph-rewriter: Fix escaping 
StringRegions. (authored by dergachev, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D63519?vs=205449=205705#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D63519

Files:
  cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp
  cfe/trunk/test/Analysis/exploded-graph-rewriter/escapes.c
  cfe/trunk/test/Analysis/exploded-graph-rewriter/lit.local.cfg
  cfe/trunk/utils/analyzer/exploded-graph-rewriter.py


Index: cfe/trunk/test/Analysis/exploded-graph-rewriter/escapes.c
===
--- cfe/trunk/test/Analysis/exploded-graph-rewriter/escapes.c
+++ cfe/trunk/test/Analysis/exploded-graph-rewriter/escapes.c
@@ -0,0 +1,18 @@
+// FIXME: Figure out how to use %clang_analyze_cc1 with our lit.local.cfg.
+// RUN: %clang_cc1 -analyze -triple x86_64-unknown-linux-gnu \
+// RUN: -analyzer-checker=core \
+// RUN: -analyzer-dump-egraph=%t.dot %s
+// RUN: %exploded_graph_rewriter %t.dot | FileCheck %s
+
+// FIXME: Substitution doesn't seem to work on Windows.
+// UNSUPPORTED: system-windows
+
+void string_region_escapes() {
+  // CHECK: Store: 
+  // CHECK-SAME: foo0
+  // CHECK-SAME: Element\{"foo",0 S64b,char\}
+  // CHECK: Environment: 
+  // CHECK-SAME: "foo"
+  // CHECK-SAME: Element\{"foo",0 S64b,char\}
+  const char *const foo = "foo";
+}
Index: cfe/trunk/test/Analysis/exploded-graph-rewriter/lit.local.cfg
===
--- cfe/trunk/test/Analysis/exploded-graph-rewriter/lit.local.cfg
+++ cfe/trunk/test/Analysis/exploded-graph-rewriter/lit.local.cfg
@@ -15,4 +15,4 @@
 config.clang_src_dir,
 'utils', 'analyzer')
 
-config.suffixes = ['.dot']
+config.suffixes.add('.dot')
Index: cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp
@@ -210,6 +210,7 @@
   void printJson(raw_ostream , const char *NL = "\n",
  unsigned int Space = 0, bool IsDot = false) const {
 for (iterator I = begin(); I != end(); ++I) {
+  // TODO: We might need a .printJson for I.getKey() as well.
   Indent(Out, Space, IsDot)
   << "{ \"cluster\": \"" << I.getKey() << "\", \"pointer\": \""
   << (const void *)I.getKey() << "\", \"items\": [" << NL;
@@ -217,8 +218,9 @@
   ++Space;
   const ClusterBindings  = I.getData();
   for (ClusterBindings::iterator CI = CB.begin(); CI != CB.end(); ++CI) {
-Indent(Out, Space, IsDot) << "{ " << CI.getKey() << ", \"value\": \""
-  << CI.getData() << "\" }";
+Indent(Out, Space, IsDot) << "{ " << CI.getKey() << ", \"value\": ";
+CI.getData().printJson(Out, /*AddQuotes=*/true);
+Out << " }";
 if (std::next(CI) != CB.end())
   Out << ',';
 Out << NL;
Index: cfe/trunk/utils/analyzer/exploded-graph-rewriter.py
===
--- cfe/trunk/utils/analyzer/exploded-graph-rewriter.py
+++ cfe/trunk/utils/analyzer/exploded-graph-rewriter.py
@@ -199,6 +199,7 @@
 .replace('\\"', '"') \
 .replace('\\{', '{') \
 .replace('\\}', '}') \
+.replace('', '\\') \
 .replace('\\<', '<') \
 .replace('\\>', '>') \
 .rstrip(',')


Index: cfe/trunk/test/Analysis/exploded-graph-rewriter/escapes.c
===
--- cfe/trunk/test/Analysis/exploded-graph-rewriter/escapes.c
+++ cfe/trunk/test/Analysis/exploded-graph-rewriter/escapes.c
@@ -0,0 +1,18 @@
+// FIXME: Figure out how to use %clang_analyze_cc1 with our lit.local.cfg.
+// RUN: %clang_cc1 -analyze -triple x86_64-unknown-linux-gnu \
+// RUN: -analyzer-checker=core \
+// RUN: -analyzer-dump-egraph=%t.dot %s
+// RUN: %exploded_graph_rewriter %t.dot | FileCheck %s
+
+// FIXME: Substitution doesn't seem to work on Windows.
+// UNSUPPORTED: system-windows
+
+void string_region_escapes() {
+  // CHECK: Store: 
+  // CHECK-SAME: foo0
+  // CHECK-SAME: Element\{"foo",0 S64b,char\}
+  // CHECK: Environment: 
+  // CHECK-SAME: "foo"
+  // CHECK-SAME: Element\{"foo",0 S64b,char\}
+  const char *const 

[PATCH] D62716: [analyzer] Fix JSON dumps for dynamic types, add test.

2019-06-19 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL363894: [analyzer] Fix JSON dumps for dynamic type 
information. (authored by dergachev, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D62716?vs=202360=205702#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D62716

Files:
  cfe/trunk/lib/StaticAnalyzer/Core/DynamicTypeMap.cpp
  cfe/trunk/test/Analysis/dump_egraph.cpp


Index: cfe/trunk/lib/StaticAnalyzer/Core/DynamicTypeMap.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Core/DynamicTypeMap.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/DynamicTypeMap.cpp
@@ -72,12 +72,12 @@
 Out << "{ \"region\": \"" << MR << "\", \"dyn_type\": ";
 if (DTI.isValid()) {
   Out << '\"' << DTI.getType()->getPointeeType().getAsString()
-  << "\" \"sub_classable\": "
+  << "\", \"sub_classable\": "
   << (DTI.canBeASubClass() ? "true" : "false");
 } else {
   Out << "null"; // Invalid type info
 }
-Out << "\" }";
+Out << "}";
 
 if (std::next(I) != DTM.end())
   Out << ',';
Index: cfe/trunk/test/Analysis/dump_egraph.cpp
===
--- cfe/trunk/test/Analysis/dump_egraph.cpp
+++ cfe/trunk/test/Analysis/dump_egraph.cpp
@@ -14,11 +14,14 @@
 void foo() {
   // Test that dumping symbols conjured on null statements doesn't crash.
   T t;
+
+  new S;
 }
 
 // CHECK: \"location_context\": \"#0 Call\", \"calling\": \"foo\", 
\"call_line\": null, \"items\": 
[\l\{ \"lctx_id\": 1, 
\"stmt_id\": {{[0-9]+}}, \"kind\": \"construct into local variable\", 
\"argument_index\": null, \"pretty\": \"T t;\", \"value\": \"\"
 
 // CHECK: \"location_context\": \"#0 Call\", \"calling\": \"T::T\", 
\"call_line\": \"16\", \"items\": 
[\l\{ \"lctx_id\": 2, 
\"init_id\": {{[0-9]+}}, \"kind\": \"construct into member variable\", 
\"argument_index\": null, \"pretty\": \"s\", \"value\": \"\>s\"
 
-// CHECK: \"cluster\": \"t\", \"items\": 
[\l\{ \"kind\": \"Default\", 
\"offset\": 0, \"value\": \"conj_$3\{int, LC3, no stmt, #1\}\"
+// CHECK: \"cluster\": \"t\", \"items\": 
[\l\{ \"kind\": \"Default\", 
\"offset\": 0, \"value\": \"conj_$2\{int, LC5, no stmt, #1\}\"
 
+// CHECK: \"dynamic_types\": [\l\{ \"region\": 
\"HeapSymRegion\{conj_$1\{struct S *, LC1, S{{[0-9]+}}, #1\}\}\", \"dyn_type\": 
\"struct S\", \"sub_classable\": false\}\l


Index: cfe/trunk/lib/StaticAnalyzer/Core/DynamicTypeMap.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Core/DynamicTypeMap.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/DynamicTypeMap.cpp
@@ -72,12 +72,12 @@
 Out << "{ \"region\": \"" << MR << "\", \"dyn_type\": ";
 if (DTI.isValid()) {
   Out << '\"' << DTI.getType()->getPointeeType().getAsString()
-  << "\" \"sub_classable\": "
+  << "\", \"sub_classable\": "
   << (DTI.canBeASubClass() ? "true" : "false");
 } else {
   Out << "null"; // Invalid type info
 }
-Out << "\" }";
+Out << "}";
 
 if (std::next(I) != DTM.end())
   Out << ',';
Index: cfe/trunk/test/Analysis/dump_egraph.cpp
===
--- cfe/trunk/test/Analysis/dump_egraph.cpp
+++ cfe/trunk/test/Analysis/dump_egraph.cpp
@@ -14,11 +14,14 @@
 void foo() {
   // Test that dumping symbols conjured on null statements doesn't crash.
   T t;
+
+  new S;
 }
 
 // CHECK: \"location_context\": \"#0 Call\", \"calling\": \"foo\", \"call_line\": null, \"items\": [\l\{ \"lctx_id\": 1, \"stmt_id\": {{[0-9]+}}, \"kind\": \"construct into local variable\", \"argument_index\": null, \"pretty\": \"T t;\", \"value\": \"\"
 
 // CHECK: \"location_context\": \"#0 Call\", \"calling\": \"T::T\", \"call_line\": \"16\", \"items\": [\l\{ \"lctx_id\": 2, \"init_id\": {{[0-9]+}}, \"kind\": \"construct into member variable\", \"argument_index\": null, \"pretty\": \"s\", \"value\": \"\>s\"
 
-// CHECK: \"cluster\": \"t\", \"items\": [\l\{ \"kind\": \"Default\", \"offset\": 0, \"value\": \"conj_$3\{int, LC3, no stmt, #1\}\"
+// CHECK: \"cluster\": \"t\", \"items\": [\l\{ \"kind\": \"Default\", \"offset\": 0, \"value\": \"conj_$2\{int, LC5, no stmt, #1\}\"
 
+// CHECK: \"dynamic_types\": [\l\{ \"region\": \"HeapSymRegion\{conj_$1\{struct S *, LC1, S{{[0-9]+}}, #1\}\}\", \"dyn_type\": \"struct S\", \"sub_classable\": false\}\l
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D63362: [analyzer] Fix JSON dumps for store clusters.

2019-06-19 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL363896: [analyzer] Fix JSON dumps for store clusters. 
(authored by dergachev, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D63362?vs=204874=205704#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D63362

Files:
  cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp
  cfe/trunk/test/Analysis/dump_egraph.cpp
  cfe/trunk/test/Analysis/expr-inspection.c


Index: cfe/trunk/test/Analysis/dump_egraph.cpp
===
--- cfe/trunk/test/Analysis/dump_egraph.cpp
+++ cfe/trunk/test/Analysis/dump_egraph.cpp
@@ -22,6 +22,6 @@
 
 // CHECK: \"location_context\": \"#0 Call\", \"calling\": \"T::T\", 
\"call_line\": \"16\", \"items\": 
[\l\{ \"init_id\": {{[0-9]+}}, 
\"kind\": \"construct into member variable\", \"argument_index\": null, 
\"pretty\": \"s\", \"value\": \"\>s\"
 
-// CHECK: \"cluster\": \"t\", \"items\": 
[\l\{ \"kind\": \"Default\", 
\"offset\": 0, \"value\": \"conj_$2\{int, LC5, no stmt, #1\}\"
+// CHECK: \"cluster\": \"t\", \"pointer\": \"{{0x[0-9a-f]+}}\", \"items\": 
[\l\{ \"kind\": \"Default\", 
\"offset\": 0, \"value\": \"conj_$2\{int, LC5, no stmt, #1\}\"
 
 // CHECK: \"dynamic_types\": [\l\{ \"region\": 
\"HeapSymRegion\{conj_$1\{struct S *, LC1, S{{[0-9]+}}, #1\}\}\", \"dyn_type\": 
\"struct S\", \"sub_classable\": false\}\l
Index: cfe/trunk/test/Analysis/expr-inspection.c
===
--- cfe/trunk/test/Analysis/expr-inspection.c
+++ cfe/trunk/test/Analysis/expr-inspection.c
@@ -25,7 +25,7 @@
 
 // CHECK:  "program_state": {
 // CHECK-NEXT:   "store": [
-// CHECK-NEXT: { "cluster": "y", "items": [
+// CHECK-NEXT: { "cluster": "y", "pointer": "{{0x[0-9a-f]+}}", "items": [
 // CHECK-NEXT:   { "kind": "Direct", "offset": 0, "value": "2 S32b" }
 // CHECK-NEXT: ]}
 // CHECK-NEXT:   ],
Index: cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp
@@ -211,7 +211,8 @@
  unsigned int Space = 0, bool IsDot = false) const {
 for (iterator I = begin(); I != end(); ++I) {
   Indent(Out, Space, IsDot)
-  << "{ \"cluster\": \"" << I.getKey() << "\", \"items\": [" << NL;
+  << "{ \"cluster\": \"" << I.getKey() << "\", \"pointer\": \""
+  << (const void *)I.getKey() << "\", \"items\": [" << NL;
 
   ++Space;
   const ClusterBindings  = I.getData();


Index: cfe/trunk/test/Analysis/dump_egraph.cpp
===
--- cfe/trunk/test/Analysis/dump_egraph.cpp
+++ cfe/trunk/test/Analysis/dump_egraph.cpp
@@ -22,6 +22,6 @@
 
 // CHECK: \"location_context\": \"#0 Call\", \"calling\": \"T::T\", \"call_line\": \"16\", \"items\": [\l\{ \"init_id\": {{[0-9]+}}, \"kind\": \"construct into member variable\", \"argument_index\": null, \"pretty\": \"s\", \"value\": \"\>s\"
 
-// CHECK: \"cluster\": \"t\", \"items\": [\l\{ \"kind\": \"Default\", \"offset\": 0, \"value\": \"conj_$2\{int, LC5, no stmt, #1\}\"
+// CHECK: \"cluster\": \"t\", \"pointer\": \"{{0x[0-9a-f]+}}\", \"items\": [\l\{ \"kind\": \"Default\", \"offset\": 0, \"value\": \"conj_$2\{int, LC5, no stmt, #1\}\"
 
 // CHECK: \"dynamic_types\": [\l\{ \"region\": \"HeapSymRegion\{conj_$1\{struct S *, LC1, S{{[0-9]+}}, #1\}\}\", \"dyn_type\": \"struct S\", \"sub_classable\": false\}\l
Index: cfe/trunk/test/Analysis/expr-inspection.c
===
--- cfe/trunk/test/Analysis/expr-inspection.c
+++ cfe/trunk/test/Analysis/expr-inspection.c
@@ -25,7 +25,7 @@
 
 // CHECK:  "program_state": {
 // CHECK-NEXT:   "store": [
-// CHECK-NEXT: { "cluster": "y", "items": [
+// CHECK-NEXT: { "cluster": "y", "pointer": "{{0x[0-9a-f]+}}", "items": [
 // CHECK-NEXT:   { "kind": "Direct", "offset": 0, "value": "2 S32b" }
 // CHECK-NEXT: ]}
 // CHECK-NEXT:   ],
Index: cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp
@@ -211,7 +211,8 @@
  unsigned int Space = 0, bool IsDot = false) const {
 for (iterator I = begin(); I != end(); ++I) {
   Indent(Out, Space, IsDot)
-  << "{ \"cluster\": \"" << I.getKey() << "\", \"items\": [" << NL;
+  << "{ \"cluster\": \"" << I.getKey() << "\", \"pointer\": \""
+  << (const void *)I.getKey() << "\", \"items\": [" << NL;
 
   ++Space;
   const ClusterBindings  = I.getData();

[PATCH] D62754: [analyzer] Fix JSON dumps for location contexts.

2019-06-19 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL363895: [analyzer] Fix JSON dumps for location contexts. 
(authored by dergachev, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D62754?vs=202493=205703#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D62754

Files:
  cfe/trunk/lib/Analysis/AnalysisDeclContext.cpp
  cfe/trunk/lib/StaticAnalyzer/Core/Environment.cpp
  cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
  cfe/trunk/test/Analysis/dump_egraph.cpp
  cfe/trunk/test/Analysis/expr-inspection.c


Index: cfe/trunk/lib/Analysis/AnalysisDeclContext.cpp
===
--- cfe/trunk/lib/Analysis/AnalysisDeclContext.cpp
+++ cfe/trunk/lib/Analysis/AnalysisDeclContext.cpp
@@ -527,7 +527,8 @@
 
   unsigned Frame = 0;
   for (const LocationContext *LCtx = this; LCtx; LCtx = LCtx->getParent()) {
-Indent(Out, Space, IsDot) << "{ \"location_context\": \"";
+Indent(Out, Space, IsDot)
+<< "{ \"lctx_id\": " << LCtx->getID() << ", \"location_context\": \"";
 switch (LCtx->getKind()) {
 case StackFrame:
   Out << '#' << Frame << " Call\", \"calling\": \"";
@@ -541,7 +542,7 @@
   if (const Stmt *S = cast(LCtx)->getCallSite()) {
 Out << '\"';
 printLocation(Out, SM, S->getBeginLoc());
-   Out << '\"';
+Out << '\"';
   } else {
 Out << "null";
   }
Index: cfe/trunk/lib/StaticAnalyzer/Core/Environment.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Core/Environment.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/Environment.cpp
@@ -261,8 +261,7 @@
 
   const Stmt *S = I->first.getStmt();
   Indent(Out, InnerSpace, IsDot)
-  << "{ \"lctx_id\": " << LC->getID()
-  << ", \"stmt_id\": " << S->getID(Ctx) << ", \"pretty\": ";
+  << "{ \"stmt_id\": " << S->getID(Ctx) << ", \"pretty\": ";
   S->printJson(Out, nullptr, PP, /*AddQuotes=*/true);
 
   Out << ", \"value\": ";
Index: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
@@ -149,9 +149,6 @@
 if (!S)
   I = getItem().getCXXCtorInitializer();
 
-// IDs
-Out << "\"lctx_id\": " << getLocationContext()->getID() << ", ";
-
 if (S)
   Out << "\"stmt_id\": " << S->getID(getASTContext());
 else
Index: cfe/trunk/test/Analysis/dump_egraph.cpp
===
--- cfe/trunk/test/Analysis/dump_egraph.cpp
+++ cfe/trunk/test/Analysis/dump_egraph.cpp
@@ -18,9 +18,9 @@
   new S;
 }
 
-// CHECK: \"location_context\": \"#0 Call\", \"calling\": \"foo\", 
\"call_line\": null, \"items\": 
[\l\{ \"lctx_id\": 1, 
\"stmt_id\": {{[0-9]+}}, \"kind\": \"construct into local variable\", 
\"argument_index\": null, \"pretty\": \"T t;\", \"value\": \"\"
+// CHECK: \"location_context\": \"#0 Call\", \"calling\": \"foo\", 
\"call_line\": null, \"items\": 
[\l\{ \"stmt_id\": {{[0-9]+}}, 
\"kind\": \"construct into local variable\", \"argument_index\": null, 
\"pretty\": \"T t;\", \"value\": \"\"
 
-// CHECK: \"location_context\": \"#0 Call\", \"calling\": \"T::T\", 
\"call_line\": \"16\", \"items\": 
[\l\{ \"lctx_id\": 2, 
\"init_id\": {{[0-9]+}}, \"kind\": \"construct into member variable\", 
\"argument_index\": null, \"pretty\": \"s\", \"value\": \"\>s\"
+// CHECK: \"location_context\": \"#0 Call\", \"calling\": \"T::T\", 
\"call_line\": \"16\", \"items\": 
[\l\{ \"init_id\": {{[0-9]+}}, 
\"kind\": \"construct into member variable\", \"argument_index\": null, 
\"pretty\": \"s\", \"value\": \"\>s\"
 
 // CHECK: \"cluster\": \"t\", \"items\": 
[\l\{ \"kind\": \"Default\", 
\"offset\": 0, \"value\": \"conj_$2\{int, LC5, no stmt, #1\}\"
 
Index: cfe/trunk/test/Analysis/expr-inspection.c
===
--- cfe/trunk/test/Analysis/expr-inspection.c
+++ cfe/trunk/test/Analysis/expr-inspection.c
@@ -30,8 +30,8 @@
 // CHECK-NEXT: ]}
 // CHECK-NEXT:   ],
 // CHECK-NEXT:   "environment": [
-// CHECK-NEXT: { "location_context": "#0 Call", "calling": "foo", 
"call_line": null, "items": [
-// CHECK-NEXT:   { "lctx_id": 1, "stmt_id": {{[0-9]+}}, "pretty": 
"clang_analyzer_printState", "value": "{clang_analyzer_printState}" }
+// CHECK-NEXT: { "lctx_id": 1, "location_context": "#0 Call", "calling": 
"foo", "call_line": null, "items": [
+// CHECK-NEXT:   { "stmt_id": {{[0-9]+}}, "pretty": 
"clang_analyzer_printState", "value": "{clang_analyzer_printState}" }
 // CHECK-NEXT: ]}
 // CHECK-NEXT:   ],
 // CHECK-NEXT:   "constraints": [


Index: 

[PATCH] D62440: [analyzer] NFC: Change evalCall() to provide a CallEvent.

2019-06-19 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL363893: [analyzer] NFC: Change evalCall() to provide a 
CallEvent. (authored by dergachev, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D62440?vs=201380=205701#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D62440

Files:
  cfe/trunk/include/clang/StaticAnalyzer/Core/Checker.h
  cfe/trunk/include/clang/StaticAnalyzer/Core/CheckerManager.h
  cfe/trunk/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
  cfe/trunk/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
  cfe/trunk/lib/StaticAnalyzer/Checkers/ChrootChecker.cpp
  cfe/trunk/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp
  
cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp
  cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.h
  cfe/trunk/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
  cfe/trunk/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
  cfe/trunk/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
  cfe/trunk/lib/StaticAnalyzer/Core/CheckerManager.cpp

Index: cfe/trunk/include/clang/StaticAnalyzer/Core/CheckerManager.h
===
--- cfe/trunk/include/clang/StaticAnalyzer/Core/CheckerManager.h
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/CheckerManager.h
@@ -490,7 +490,7 @@
   CheckerFn;
 
-  using EvalCallFunc = CheckerFn;
+  using EvalCallFunc = CheckerFn;
 
   using CheckEndOfTranslationUnit =
   CheckerFn
-  static bool _evalCall(void *checker, const CallExpr *CE, CheckerContext ) {
-return ((const CHECKER *)checker)->evalCall(CE, C);
+  static bool _evalCall(void *checker, const CallEvent ,
+CheckerContext ) {
+return ((const CHECKER *)checker)->evalCall(Call, C);
   }
 
 public:
Index: cfe/trunk/lib/StaticAnalyzer/Core/CheckerManager.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Core/CheckerManager.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Core/CheckerManager.cpp
@@ -651,7 +651,6 @@
 const ExplodedNodeSet ,
 const CallEvent ,
 ExprEngine ) {
-  const CallExpr *CE = cast(Call.getOriginExpr());
   for (const auto Pred : Src) {
 bool anyEvaluated = false;
 
@@ -660,16 +659,19 @@
 
 // Check if any of the EvalCall callbacks can evaluate the call.
 for (const auto EvalCallChecker : EvalCallCheckers) {
-  ProgramPoint::Kind K = ProgramPoint::PostStmtKind;
-  const ProgramPoint  =
-  ProgramPoint::getProgramPoint(CE, K, Pred->getLocationContext(),
-EvalCallChecker.Checker);
+  // TODO: Support the situation when the call doesn't correspond
+  // to any Expr.
+  ProgramPoint L = ProgramPoint::getProgramPoint(
+  cast(Call.getOriginExpr()),
+  ProgramPoint::PostStmtKind,
+  Pred->getLocationContext(),
+  EvalCallChecker.Checker);
   bool evaluated = false;
   { // CheckerContext generates transitions(populates checkDest) on
 // destruction, so introduce the scope to make sure it gets properly
 // populated.
 CheckerContext C(B, Eng, Pred, L);
-evaluated = EvalCallChecker(CE, C);
+evaluated = EvalCallChecker(Call, C);
   }
   assert(!(evaluated && anyEvaluated)
  && "There are more than one checkers evaluating the call");
Index: cfe/trunk/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp
@@ -11,6 +11,7 @@
 #include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
 #include "clang/StaticAnalyzer/Core/Checker.h"
 #include "clang/StaticAnalyzer/Core/IssueHash.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/Support/ScopedPrinter.h"
@@ -53,7 +54,7 @@
   ExplodedNode *N) const;
 
 public:
-  bool evalCall(const CallExpr *CE, CheckerContext ) const;
+  bool evalCall(const CallEvent , CheckerContext ) const;
   void checkDeadSymbols(SymbolReaper , CheckerContext ) const;
   void checkEndAnalysis(ExplodedGraph , BugReporter ,
 ExprEngine ) const;
@@ -63,8 +64,12 @@
 REGISTER_SET_WITH_PROGRAMSTATE(MarkedSymbols, SymbolRef)
 REGISTER_MAP_WITH_PROGRAMSTATE(DenotedSymbols, SymbolRef, const StringLiteral *)
 
-bool ExprInspectionChecker::evalCall(const CallExpr *CE,
+bool 

r363898 - [analyzer] exploded-graph-rewriter: Implement a --diff mode.

2019-06-19 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Wed Jun 19 16:33:59 2019
New Revision: 363898

URL: http://llvm.org/viewvc/llvm-project?rev=363898=rev
Log:
[analyzer] exploded-graph-rewriter: Implement a --diff mode.

In this mode the tool would avoid duplicating the contents of the
program state on every node, replacing them with a diff-like dump
of changes that happened on that node.

This is useful because most of the time we only interested in whether
the effect of the statement was modeled correctly. A diffed graph would
also be much faster to load and navigate, being much smaller than
the original graph.

The diffs are computed "semantically" as opposed to plain text diffs.
I.e., the diff algorithm is hand-crafted separately for every state trait,
taking the underlying data structures into account. This is especially nice
for Environment because textual diffs would have been terrible.
On the other hand, it requires some boilerplate to implement.

Differential Revision: https://reviews.llvm.org/D62761

Added:
cfe/trunk/test/Analysis/exploded-graph-rewriter/environment_diff.dot
cfe/trunk/test/Analysis/exploded-graph-rewriter/store_diff.dot
Modified:
cfe/trunk/test/Analysis/exploded-graph-rewriter/program_points.dot
cfe/trunk/test/Analysis/exploded-graph-rewriter/store.dot
cfe/trunk/utils/analyzer/exploded-graph-rewriter.py

Added: cfe/trunk/test/Analysis/exploded-graph-rewriter/environment_diff.dot
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/exploded-graph-rewriter/environment_diff.dot?rev=363898=auto
==
--- cfe/trunk/test/Analysis/exploded-graph-rewriter/environment_diff.dot (added)
+++ cfe/trunk/test/Analysis/exploded-graph-rewriter/environment_diff.dot Wed 
Jun 19 16:33:59 2019
@@ -0,0 +1,110 @@
+// RUN: %exploded_graph_rewriter -d %s | FileCheck %s
+
+// FIXME: Substitution doesn't seem to work on Windows.
+// UNSUPPORTED: system-windows
+
+// No diffs on the first node, nothing to check.
+Node0x1 [shape=record,label=
+ "{
+{ "node_id": 1,
+  "pointer": "0x1",
+  "state_id": 2,
+  "program_points": [],
+  "program_state": {
+"store": null,
+"environment": [
+  {
+"location_context": "#0 Call",
+"lctx_id": 3,
+"calling": "foo",
+"call_line": 4,
+"items": [
+  {
+"stmt_id": 5,
+"pretty": "bar()",
+"value": "Unknown"
+  }
+]
+  }
+]
+  }
+}
+\l}"];
+
+Node0x1 -> Node0x6;
+
+// CHECK: Node0x6 [
+// CHECK-SAME: 
+// CHECK-SAME:   -
+// CHECK-SAME:   S5
+// CHECK-SAME:   bar()
+// CHECK-SAME:   Unknown
+// CHECK-SAME: 
+// CHECK-SAME: 
+// CHECK-SAME:   +
+// CHECK-SAME:   S9
+// CHECK-SAME:   baz()
+// CHECK-SAME:   Undefined
+// CHECK-SAME: 
+Node0x6 [shape=record,label=
+ "{
+{ "node_id": 6,
+  "pointer": "0x6",
+  "state_id": 7,
+  "program_points": [],
+  "program_state": {
+"store": null,
+"environment": [
+  {
+"location_context": "#0 Call",
+"lctx_id": 3,
+"calling": "foo",
+"call_line": 4,
+"items": [
+  {
+"stmt_id": 9,
+"pretty": "baz()",
+"value": "Undefined"
+  }
+]
+  }
+]
+  }
+}
+\l}"];
+
+Node0x6 -> Node0x9;
+// Make sure that the last node in the path is not diffed.
+// CHECK: Node0x9 [
+// CHECK-SAME: 
+// CHECK-SAME:   
+// CHECK-SAME:   S9
+// CHECK-SAME:   baz()
+// CHECK-SAME:   Undefined
+// CHECK-SAME: 
+Node0x9 [shape=record,label=
+ "{
+{ "node_id": 9,
+  "pointer": "0x9",
+  "state_id": 7,
+  "program_points": [],
+  "program_state": {
+"store": null,
+"environment": [
+  {
+"location_context": "#0 Call",
+"lctx_id": 3,
+"calling": "foo",
+"call_line": 4,
+"items": [
+  {
+"stmt_id": 9,
+"pretty": "baz()",
+"value": "Undefined"
+  }
+]
+  }
+]
+  }
+}
+\l}"];

Modified: cfe/trunk/test/Analysis/exploded-graph-rewriter/program_points.dot
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/exploded-graph-rewriter/program_points.dot?rev=363898=363897=363898=diff
==
--- cfe/trunk/test/Analysis/exploded-graph-rewriter/program_points.dot 
(original)
+++ cfe/trunk/test/Analysis/exploded-graph-rewriter/program_points.dot Wed Jun 
19 16:33:59 2019
@@ -7,7 +7,6 @@
 // CHECK-SAME: 
 // CHECK-SAME:   
 // CHECK-SAME: 
-// CHECK-SAME:   -
 // CHECK-SAME: 
 // CHECK-SAME: 
 // CHECK-SAME:   Edge

Modified: cfe/trunk/test/Analysis/exploded-graph-rewriter/store.dot

[PATCH] D63118: [analyzer] DeadStores: Add a crude suppression files generated by DriverKit IIG.

2019-06-19 Thread Phabricator 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 rL363892: [analyzer] DeadStores: Add a crude suppression files 
generated by DriverKit IIG. (authored by dergachev, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D63118?vs=203962=205700#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D63118

Files:
  cfe/trunk/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp
  cfe/trunk/test/Analysis/deadstores-driverkit.cpp
  cfe/trunk/test/Analysis/os_object_base.h


Index: cfe/trunk/test/Analysis/os_object_base.h
===
--- cfe/trunk/test/Analysis/os_object_base.h
+++ cfe/trunk/test/Analysis/os_object_base.h
@@ -19,6 +19,9 @@
 
 using size_t = decltype(sizeof(int));
 
+typedef int kern_return_t;
+struct IORPC {};
+
 struct OSMetaClass;
 
 struct OSMetaClassBase {
@@ -37,8 +40,13 @@
 
   virtual void free();
   virtual ~OSMetaClassBase(){};
+
+  kern_return_t Invoke(IORPC invoke);
 };
 
+typedef kern_return_t (*OSDispatchMethod)(OSMetaClassBase *self,
+  const IORPC rpc);
+
 struct OSObject : public OSMetaClassBase {
   virtual ~OSObject(){}
 
Index: cfe/trunk/test/Analysis/deadstores-driverkit.cpp
===
--- cfe/trunk/test/Analysis/deadstores-driverkit.cpp
+++ cfe/trunk/test/Analysis/deadstores-driverkit.cpp
@@ -0,0 +1,24 @@
+/* iig generated from SomethingSomething.iig */
+
+// The comment above is the whole point of the test.
+// That's how the suppression works.
+// It needs to be on the top.
+// Run-lines can wait.
+
+// RUN: %clang_analyze_cc1 -w -triple x86_64-apple-driverkit19.0 \
+// RUN:   -analyzer-checker=deadcode -verify %s
+
+// expected-no-diagnostics
+
+#include "os_object_base.h"
+
+class OSSomething {
+  kern_return_t Invoke(const IORPC);
+  void foo(OSDispatchMethod supermethod) {
+kern_return_t ret;
+IORPC rpc;
+// Test the DriverKit specific suppression in the dead stores checker.
+if (supermethod) ret = supermethod((OSObject *)this, rpc); // no-warning
+else ret = ((OSObject *)this)->Invoke(rpc); // no-warning
+  }
+};
Index: cfe/trunk/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp
@@ -160,6 +160,26 @@
 return InEH->count(D);
   }
 
+  bool isSuppressed(SourceRange R) {
+SourceManager  = Ctx.getSourceManager();
+SourceLocation Loc = R.getBegin();
+if (!Loc.isValid())
+  return false;
+
+FileID FID = SMgr.getFileID(Loc);
+bool Invalid = false;
+StringRef Data = SMgr.getBufferData(FID, );
+if (Invalid)
+  return false;
+
+// Files autogenerated by DriverKit IIG contain some dead stores that
+// we don't want to report.
+if (Data.startswith("/* iig generated from"))
+  return true;
+
+return false;
+  }
+
   void Report(const VarDecl *V, DeadStoreKind dsk,
   PathDiagnosticLocation L, SourceRange R) {
 if (Escaped.count(V))
@@ -175,6 +195,9 @@
 if (!reachableCode->isReachable(currentBlock))
   return;
 
+if (isSuppressed(R))
+  return;
+
 SmallString<64> buf;
 llvm::raw_svector_ostream os(buf);
 const char *BugType = nullptr;


Index: cfe/trunk/test/Analysis/os_object_base.h
===
--- cfe/trunk/test/Analysis/os_object_base.h
+++ cfe/trunk/test/Analysis/os_object_base.h
@@ -19,6 +19,9 @@
 
 using size_t = decltype(sizeof(int));
 
+typedef int kern_return_t;
+struct IORPC {};
+
 struct OSMetaClass;
 
 struct OSMetaClassBase {
@@ -37,8 +40,13 @@
 
   virtual void free();
   virtual ~OSMetaClassBase(){};
+
+  kern_return_t Invoke(IORPC invoke);
 };
 
+typedef kern_return_t (*OSDispatchMethod)(OSMetaClassBase *self,
+  const IORPC rpc);
+
 struct OSObject : public OSMetaClassBase {
   virtual ~OSObject(){}
 
Index: cfe/trunk/test/Analysis/deadstores-driverkit.cpp
===
--- cfe/trunk/test/Analysis/deadstores-driverkit.cpp
+++ cfe/trunk/test/Analysis/deadstores-driverkit.cpp
@@ -0,0 +1,24 @@
+/* iig generated from SomethingSomething.iig */
+
+// The comment above is the whole point of the test.
+// That's how the suppression works.
+// It needs to be on the top.
+// Run-lines can wait.
+
+// RUN: %clang_analyze_cc1 -w -triple x86_64-apple-driverkit19.0 \
+// RUN:   -analyzer-checker=deadcode -verify %s
+
+// expected-no-diagnostics
+
+#include "os_object_base.h"
+
+class 

[PATCH] D63117: [analyzer] RetainCount: Add support for OSRequiredCast().

2019-06-19 Thread Phabricator 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 rL363891: [analyzer] RetainCount: Add support for 
OSRequiredCast(). (authored by dergachev, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D63117?vs=203959=205698#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D63117

Files:
  cfe/trunk/lib/Analysis/RetainSummaryManager.cpp
  cfe/trunk/test/Analysis/os_object_base.h
  cfe/trunk/test/Analysis/osobject-retain-release.cpp


Index: cfe/trunk/lib/Analysis/RetainSummaryManager.cpp
===
--- cfe/trunk/lib/Analysis/RetainSummaryManager.cpp
+++ cfe/trunk/lib/Analysis/RetainSummaryManager.cpp
@@ -152,6 +152,10 @@
   return S == "safeMetaCast";
 }
 
+static bool isOSObjectRequiredCast(StringRef S) {
+  return S == "requiredMetaCast";
+}
+
 static bool isOSObjectThisCast(StringRef S) {
   return S == "metaCast";
 }
@@ -234,7 +238,8 @@
   if (RetTy->isPointerType()) {
 const CXXRecordDecl *PD = RetTy->getPointeeType()->getAsCXXRecordDecl();
 if (PD && isOSObjectSubclass(PD)) {
-  if (isOSObjectDynamicCast(FName) || isOSObjectThisCast(FName))
+  if (isOSObjectDynamicCast(FName) || isOSObjectRequiredCast(FName) ||
+  isOSObjectThisCast(FName))
 return getDefaultSummary();
 
   // TODO: Add support for the slightly common *Matching(table) idiom.
@@ -745,6 +750,8 @@
 if (TrackOSObjects) {
   if (isOSObjectDynamicCast(FName) && FD->param_size() >= 1) {
 return BehaviorSummary::IdentityOrZero;
+  } else if (isOSObjectRequiredCast(FName) && FD->param_size() >= 1) {
+return BehaviorSummary::Identity;
   } else if (isOSObjectThisCast(FName) && isa(FD) &&
  !cast(FD)->isStatic()) {
 return BehaviorSummary::IdentityThis;
Index: cfe/trunk/test/Analysis/os_object_base.h
===
--- cfe/trunk/test/Analysis/os_object_base.h
+++ cfe/trunk/test/Analysis/os_object_base.h
@@ -12,6 +12,8 @@
 
 #define OSDynamicCast(type, inst)   \
 ((type *) OSMetaClassBase::safeMetaCast((inst), OSTypeID(type)))
+#define OSRequiredCast(type, inst)   \
+((type *) OSMetaClassBase::requiredMetaCast((inst), OSTypeID(type)))
 
 #define OSTypeAlloc(type)   ((type *) ((type::metaClass)->alloc()))
 
@@ -22,6 +24,8 @@
 struct OSMetaClassBase {
   static OSMetaClassBase *safeMetaCast(const OSMetaClassBase *inst,
const OSMetaClass *meta);
+  static OSMetaClassBase *requiredMetaCast(const OSMetaClassBase *inst,
+   const OSMetaClass *meta);
 
   OSMetaClassBase *metaCast(const char *toMeta);
 
Index: cfe/trunk/test/Analysis/osobject-retain-release.cpp
===
--- cfe/trunk/test/Analysis/osobject-retain-release.cpp
+++ cfe/trunk/test/Analysis/osobject-retain-release.cpp
@@ -1,9 +1,11 @@
 // RUN: %clang_analyze_cc1 -fblocks -analyze -analyzer-output=text\
-// RUN:-analyzer-checker=core,osx -verify %s
+// RUN:   -analyzer-checker=core,osx,debug.ExprInspection -verify %s
 
 #include "os_object_base.h"
 #include "os_smart_ptr.h"
 
+void clang_analyzer_eval(bool);
+
 struct OSIterator : public OSObject {
   static const OSMetaClass * const metaClass;
 };
@@ -483,6 +485,23 @@
   arr->release();
 }
 
+void check_required_cast() {
+  OSArray *arr = OSRequiredCast(OSArray, OSObject::generateObject(1));
+  arr->release(); // no-warning
+}
+
+void check_cast_behavior(OSObject *obj) {
+  OSArray *arr1 = OSDynamicCast(OSArray, obj);
+  clang_analyzer_eval(arr1 == obj); // expected-warning{{TRUE}}
+// expected-note@-1{{TRUE}}
+// expected-note@-2{{Assuming 'arr1' is 
not equal to 'obj'}}
+// expected-warning@-3{{FALSE}}
+// expected-note@-4   {{FALSE}}
+  OSArray *arr2 = OSRequiredCast(OSArray, obj);
+  clang_analyzer_eval(arr2 == obj); // expected-warning{{TRUE}}
+// expected-note@-1{{TRUE}}
+}
+
 unsigned int check_dynamic_cast_no_null_on_orig(OSObject *obj) {
   OSArray *arr = OSDynamicCast(OSArray, obj);
   if (arr) {


Index: cfe/trunk/lib/Analysis/RetainSummaryManager.cpp
===
--- cfe/trunk/lib/Analysis/RetainSummaryManager.cpp
+++ cfe/trunk/lib/Analysis/RetainSummaryManager.cpp
@@ -152,6 +152,10 @@
   return S == "safeMetaCast";
 }
 
+static bool isOSObjectRequiredCast(StringRef S) {
+  return S == "requiredMetaCast";
+}
+
 static bool isOSObjectThisCast(StringRef S) {
   

r363897 - [analyzer] exploded-graph-rewriter: Fix escaping StringRegions.

2019-06-19 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Wed Jun 19 16:33:55 2019
New Revision: 363897

URL: http://llvm.org/viewvc/llvm-project?rev=363897=rev
Log:
[analyzer] exploded-graph-rewriter: Fix escaping StringRegions.

Quotes around StringRegions are now escaped and unescaped correctly,
producing valid JSON.

Additionally, add a forgotten escape for Store values.

Differential Revision: https://reviews.llvm.org/D63519

Added:
cfe/trunk/test/Analysis/exploded-graph-rewriter/escapes.c
Modified:
cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp
cfe/trunk/test/Analysis/exploded-graph-rewriter/lit.local.cfg
cfe/trunk/utils/analyzer/exploded-graph-rewriter.py

Modified: cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp?rev=363897=363896=363897=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp Wed Jun 19 16:33:55 2019
@@ -210,6 +210,7 @@ public:
   void printJson(raw_ostream , const char *NL = "\n",
  unsigned int Space = 0, bool IsDot = false) const {
 for (iterator I = begin(); I != end(); ++I) {
+  // TODO: We might need a .printJson for I.getKey() as well.
   Indent(Out, Space, IsDot)
   << "{ \"cluster\": \"" << I.getKey() << "\", \"pointer\": \""
   << (const void *)I.getKey() << "\", \"items\": [" << NL;
@@ -217,8 +218,9 @@ public:
   ++Space;
   const ClusterBindings  = I.getData();
   for (ClusterBindings::iterator CI = CB.begin(); CI != CB.end(); ++CI) {
-Indent(Out, Space, IsDot) << "{ " << CI.getKey() << ", \"value\": \""
-  << CI.getData() << "\" }";
+Indent(Out, Space, IsDot) << "{ " << CI.getKey() << ", \"value\": ";
+CI.getData().printJson(Out, /*AddQuotes=*/true);
+Out << " }";
 if (std::next(CI) != CB.end())
   Out << ',';
 Out << NL;

Added: cfe/trunk/test/Analysis/exploded-graph-rewriter/escapes.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/exploded-graph-rewriter/escapes.c?rev=363897=auto
==
--- cfe/trunk/test/Analysis/exploded-graph-rewriter/escapes.c (added)
+++ cfe/trunk/test/Analysis/exploded-graph-rewriter/escapes.c Wed Jun 19 
16:33:55 2019
@@ -0,0 +1,18 @@
+// FIXME: Figure out how to use %clang_analyze_cc1 with our lit.local.cfg.
+// RUN: %clang_cc1 -analyze -triple x86_64-unknown-linux-gnu \
+// RUN: -analyzer-checker=core \
+// RUN: -analyzer-dump-egraph=%t.dot %s
+// RUN: %exploded_graph_rewriter %t.dot | FileCheck %s
+
+// FIXME: Substitution doesn't seem to work on Windows.
+// UNSUPPORTED: system-windows
+
+void string_region_escapes() {
+  // CHECK: Store: 
+  // CHECK-SAME: foo0
+  // CHECK-SAME: Element\{"foo",0 S64b,char\}
+  // CHECK: Environment: 
+  // CHECK-SAME: "foo"
+  // CHECK-SAME: Element\{"foo",0 S64b,char\}
+  const char *const foo = "foo";
+}

Modified: cfe/trunk/test/Analysis/exploded-graph-rewriter/lit.local.cfg
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/exploded-graph-rewriter/lit.local.cfg?rev=363897=363896=363897=diff
==
--- cfe/trunk/test/Analysis/exploded-graph-rewriter/lit.local.cfg (original)
+++ cfe/trunk/test/Analysis/exploded-graph-rewriter/lit.local.cfg Wed Jun 19 
16:33:55 2019
@@ -15,4 +15,4 @@ config.substitutions.append(('%exploded_
 config.clang_src_dir,
 'utils', 'analyzer')
 
-config.suffixes = ['.dot']
+config.suffixes.add('.dot')

Modified: cfe/trunk/utils/analyzer/exploded-graph-rewriter.py
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/utils/analyzer/exploded-graph-rewriter.py?rev=363897=363896=363897=diff
==
--- cfe/trunk/utils/analyzer/exploded-graph-rewriter.py (original)
+++ cfe/trunk/utils/analyzer/exploded-graph-rewriter.py Wed Jun 19 16:33:55 2019
@@ -199,6 +199,7 @@ class ExplodedGraph(object):
 .replace('\\"', '"') \
 .replace('\\{', '{') \
 .replace('\\}', '}') \
+.replace('', '\\') \
 .replace('\\<', '<') \
 .replace('\\>', '>') \
 .rstrip(',')


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


[PATCH] D63579: [clang-scan-deps] print the dependencies to stdout and remove the need to use -MD options in the CDB

2019-06-19 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman created this revision.
arphaman added reviewers: Bigcheese, aganea.
Herald added subscribers: tschuett, dexonsmith, jkorous.
Herald added a project: clang.

The gathered dependencies are now printed to the STDOUT instead of being 
written to disk. The tool also doesn't need the dependency output options as 
well to produce the dependencies.


Repository:
  rC Clang

https://reviews.llvm.org/D63579

Files:
  clang/include/clang/Frontend/Utils.h
  clang/lib/Frontend/DependencyFile.cpp
  clang/test/ClangScanDeps/Inputs/regular_cdb.json
  clang/test/ClangScanDeps/regular_cdb.cpp
  clang/tools/clang-scan-deps/ClangScanDeps.cpp

Index: clang/tools/clang-scan-deps/ClangScanDeps.cpp
===
--- clang/tools/clang-scan-deps/ClangScanDeps.cpp
+++ clang/tools/clang-scan-deps/ClangScanDeps.cpp
@@ -29,12 +29,59 @@
 
 namespace {
 
+class DependencyCollectorFactory {
+public:
+  virtual ~DependencyCollectorFactory() {}
+
+  virtual std::shared_ptr createDependencyCollector(
+  const std::unique_ptr Opts) = 0;
+};
+
+/// Prints out all of the gathered dependencies into one output stream instead
+/// of using the output dependency file.
+class DependencyPrinter : public DependencyFileGenerator {
+public:
+  class Factory : public DependencyCollectorFactory {
+  public:
+Factory(raw_ostream ) : OS(OS) {}
+
+std::shared_ptr createDependencyCollector(
+std::unique_ptr Opts) override {
+  std::unique_lock LockGuard(SharedLock);
+  return std::make_shared(std::move(Opts), SharedLock,
+ OS);
+}
+
+  private:
+std::mutex SharedLock;
+raw_ostream 
+  };
+
+  DependencyPrinter(std::unique_ptr Opts,
+std::mutex , raw_ostream )
+  : DependencyFileGenerator(*Opts), Opts(std::move(Opts)), Lock(Lock),
+OS(OS) {}
+
+  void finishedMainFile(DiagnosticsEngine ) override {
+std::unique_lock LockGuard(Lock);
+outputDependencyFile(OS);
+OS.flush();
+  }
+
+private:
+  std::unique_ptr Opts;
+  std::mutex 
+  raw_ostream 
+};
+
 /// A clang tool that runs the preprocessor only for the given compiler
 /// invocation.
 class PreprocessorOnlyTool : public tooling::ToolAction {
 public:
-  PreprocessorOnlyTool(StringRef WorkingDirectory)
-  : WorkingDirectory(WorkingDirectory) {}
+  PreprocessorOnlyTool(StringRef WorkingDirectory,
+   DependencyCollectorFactory )
+  : WorkingDirectory(WorkingDirectory),
+DepCollectorFactory(DepCollectorFactory) {}
 
   bool runInvocation(std::shared_ptr Invocation,
  FileManager *FileMgr,
@@ -53,6 +100,21 @@
 
 Compiler.createSourceManager(*FileMgr);
 
+// Create the dependency collector that will collect the produced
+// dependencies.
+//
+// This also moves the existing dependency output options from the
+// invocation to the collector. The options in the invocation are reset,
+// which ensures that the compiler won't create new dependency collectors,
+// and thus won't write out the extra '.d' files to disk.
+auto Opts = llvm::make_unique(
+std::move(Compiler.getInvocation().getDependencyOutputOpts()));
+// We need at least one -MT equivalent for the generator to work.
+if (Opts->Targets.empty())
+  Opts->Targets = {"clang-scan-deps dependency"};
+Compiler.addDependencyCollector(
+DepCollectorFactory.createDependencyCollector(std::move(Opts)));
+
 auto Action = llvm::make_unique();
 const bool Result = Compiler.ExecuteAction(*Action);
 FileMgr->clearStatCache();
@@ -61,6 +123,7 @@
 
 private:
   StringRef WorkingDirectory;
+  DependencyCollectorFactory 
 };
 
 /// A proxy file system that doesn't call `chdir` when changing the working
@@ -93,8 +156,9 @@
   ///
   /// \param Compilations The reference to the compilation database that's
   /// used by the clang tool.
-  DependencyScanningTool(const tooling::CompilationDatabase )
-  : Compilations(Compilations) {
+  DependencyScanningTool(const tooling::CompilationDatabase ,
+ DependencyCollectorFactory )
+  : Compilations(Compilations), DepCollectorFactory(DepCollectorFactory) {
 PCHContainerOps = std::make_shared();
 BaseFS = new ProxyFileSystemWithoutChdir(llvm::vfs::getRealFileSystem());
   }
@@ -107,12 +171,13 @@
 tooling::ClangTool Tool(Compilations, Input, PCHContainerOps, BaseFS);
 Tool.clearArgumentsAdjusters();
 Tool.setRestoreWorkingDir(false);
-PreprocessorOnlyTool Action(CWD);
+PreprocessorOnlyTool Action(CWD, DepCollectorFactory);
 return Tool.run();
   }
 
 private:
   const tooling::CompilationDatabase 
+  DependencyCollectorFactory 
   std::shared_ptr PCHContainerOps;
   /// The real filesystem used as a base for all the operations performed by the
   /// tool.
@@ -176,12 +241,14 @@
 return AdjustedArgs;
   });
 
+  // Print out the 

r363894 - [analyzer] Fix JSON dumps for dynamic type information.

2019-06-19 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Wed Jun 19 16:33:45 2019
New Revision: 363894

URL: http://llvm.org/viewvc/llvm-project?rev=363894=rev
Log:
[analyzer] Fix JSON dumps for dynamic type information.

They're now valid JSON.

Differential Revision: https://reviews.llvm.org/D62716

Modified:
cfe/trunk/lib/StaticAnalyzer/Core/DynamicTypeMap.cpp
cfe/trunk/test/Analysis/dump_egraph.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Core/DynamicTypeMap.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/DynamicTypeMap.cpp?rev=363894=363893=363894=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/DynamicTypeMap.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/DynamicTypeMap.cpp Wed Jun 19 16:33:45 
2019
@@ -72,12 +72,12 @@ void printDynamicTypeInfoJson(raw_ostrea
 Out << "{ \"region\": \"" << MR << "\", \"dyn_type\": ";
 if (DTI.isValid()) {
   Out << '\"' << DTI.getType()->getPointeeType().getAsString()
-  << "\" \"sub_classable\": "
+  << "\", \"sub_classable\": "
   << (DTI.canBeASubClass() ? "true" : "false");
 } else {
   Out << "null"; // Invalid type info
 }
-Out << "\" }";
+Out << "}";
 
 if (std::next(I) != DTM.end())
   Out << ',';

Modified: cfe/trunk/test/Analysis/dump_egraph.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/dump_egraph.cpp?rev=363894=363893=363894=diff
==
--- cfe/trunk/test/Analysis/dump_egraph.cpp (original)
+++ cfe/trunk/test/Analysis/dump_egraph.cpp Wed Jun 19 16:33:45 2019
@@ -14,11 +14,14 @@ struct T {
 void foo() {
   // Test that dumping symbols conjured on null statements doesn't crash.
   T t;
+
+  new S;
 }
 
 // CHECK: \"location_context\": \"#0 Call\", \"calling\": \"foo\", 
\"call_line\": null, \"items\": 
[\l\{ \"lctx_id\": 1, 
\"stmt_id\": {{[0-9]+}}, \"kind\": \"construct into local variable\", 
\"argument_index\": null, \"pretty\": \"T t;\", \"value\": \"\"
 
 // CHECK: \"location_context\": \"#0 Call\", \"calling\": \"T::T\", 
\"call_line\": \"16\", \"items\": 
[\l\{ \"lctx_id\": 2, 
\"init_id\": {{[0-9]+}}, \"kind\": \"construct into member variable\", 
\"argument_index\": null, \"pretty\": \"s\", \"value\": \"\>s\"
 
-// CHECK: \"cluster\": \"t\", \"items\": 
[\l\{ \"kind\": \"Default\", 
\"offset\": 0, \"value\": \"conj_$3\{int, LC3, no stmt, #1\}\"
+// CHECK: \"cluster\": \"t\", \"items\": 
[\l\{ \"kind\": \"Default\", 
\"offset\": 0, \"value\": \"conj_$2\{int, LC5, no stmt, #1\}\"
 
+// CHECK: \"dynamic_types\": [\l\{ \"region\": 
\"HeapSymRegion\{conj_$1\{struct S *, LC1, S{{[0-9]+}}, #1\}\}\", \"dyn_type\": 
\"struct S\", \"sub_classable\": false\}\l


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


r363892 - [analyzer] DeadStores: Add a crude suppression files generated by DriverKit IIG.

2019-06-19 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Wed Jun 19 16:33:39 2019
New Revision: 363892

URL: http://llvm.org/viewvc/llvm-project?rev=363892=rev
Log:
[analyzer] DeadStores: Add a crude suppression files generated by DriverKit IIG.

IIG is a replacement for MIG in DriverKit: IIG is autogenerating C++ code.
Suppress dead store warnings on such code, as the tool seems to be producing
them regularly, and the users of IIG are not in position to address these
warnings, as they don't control the autogenerated code. IIG-generated code
is identified by looking at the comments at the top of the file.

Differential Revision: https://reviews.llvm.org/D63118

Added:
cfe/trunk/test/Analysis/deadstores-driverkit.cpp
Modified:
cfe/trunk/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp
cfe/trunk/test/Analysis/os_object_base.h

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp?rev=363892=363891=363892=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/DeadStoresChecker.cpp Wed Jun 19 
16:33:39 2019
@@ -160,6 +160,26 @@ public:
 return InEH->count(D);
   }
 
+  bool isSuppressed(SourceRange R) {
+SourceManager  = Ctx.getSourceManager();
+SourceLocation Loc = R.getBegin();
+if (!Loc.isValid())
+  return false;
+
+FileID FID = SMgr.getFileID(Loc);
+bool Invalid = false;
+StringRef Data = SMgr.getBufferData(FID, );
+if (Invalid)
+  return false;
+
+// Files autogenerated by DriverKit IIG contain some dead stores that
+// we don't want to report.
+if (Data.startswith("/* iig generated from"))
+  return true;
+
+return false;
+  }
+
   void Report(const VarDecl *V, DeadStoreKind dsk,
   PathDiagnosticLocation L, SourceRange R) {
 if (Escaped.count(V))
@@ -175,6 +195,9 @@ public:
 if (!reachableCode->isReachable(currentBlock))
   return;
 
+if (isSuppressed(R))
+  return;
+
 SmallString<64> buf;
 llvm::raw_svector_ostream os(buf);
 const char *BugType = nullptr;

Added: cfe/trunk/test/Analysis/deadstores-driverkit.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/deadstores-driverkit.cpp?rev=363892=auto
==
--- cfe/trunk/test/Analysis/deadstores-driverkit.cpp (added)
+++ cfe/trunk/test/Analysis/deadstores-driverkit.cpp Wed Jun 19 16:33:39 2019
@@ -0,0 +1,24 @@
+/* iig generated from SomethingSomething.iig */
+
+// The comment above is the whole point of the test.
+// That's how the suppression works.
+// It needs to be on the top.
+// Run-lines can wait.
+
+// RUN: %clang_analyze_cc1 -w -triple x86_64-apple-driverkit19.0 \
+// RUN:   -analyzer-checker=deadcode -verify %s
+
+// expected-no-diagnostics
+
+#include "os_object_base.h"
+
+class OSSomething {
+  kern_return_t Invoke(const IORPC);
+  void foo(OSDispatchMethod supermethod) {
+kern_return_t ret;
+IORPC rpc;
+// Test the DriverKit specific suppression in the dead stores checker.
+if (supermethod) ret = supermethod((OSObject *)this, rpc); // no-warning
+else ret = ((OSObject *)this)->Invoke(rpc); // no-warning
+  }
+};

Modified: cfe/trunk/test/Analysis/os_object_base.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/os_object_base.h?rev=363892=363891=363892=diff
==
--- cfe/trunk/test/Analysis/os_object_base.h (original)
+++ cfe/trunk/test/Analysis/os_object_base.h Wed Jun 19 16:33:39 2019
@@ -19,6 +19,9 @@
 
 using size_t = decltype(sizeof(int));
 
+typedef int kern_return_t;
+struct IORPC {};
+
 struct OSMetaClass;
 
 struct OSMetaClassBase {
@@ -37,8 +40,13 @@ struct OSMetaClassBase {
 
   virtual void free();
   virtual ~OSMetaClassBase(){};
+
+  kern_return_t Invoke(IORPC invoke);
 };
 
+typedef kern_return_t (*OSDispatchMethod)(OSMetaClassBase *self,
+  const IORPC rpc);
+
 struct OSObject : public OSMetaClassBase {
   virtual ~OSObject(){}
 


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


r363896 - [analyzer] Fix JSON dumps for store clusters.

2019-06-19 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Wed Jun 19 16:33:51 2019
New Revision: 363896

URL: http://llvm.org/viewvc/llvm-project?rev=363896=rev
Log:
[analyzer] Fix JSON dumps for store clusters.

Include a unique pointer so that it was possible to figure out if it's
the same cluster in different program states. This allows comparing
dumps of different states against each other.

Differential Revision: https://reviews.llvm.org/D63362

Modified:
cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp
cfe/trunk/test/Analysis/dump_egraph.cpp
cfe/trunk/test/Analysis/expr-inspection.c

Modified: cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp?rev=363896=363895=363896=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/RegionStore.cpp Wed Jun 19 16:33:51 2019
@@ -211,7 +211,8 @@ public:
  unsigned int Space = 0, bool IsDot = false) const {
 for (iterator I = begin(); I != end(); ++I) {
   Indent(Out, Space, IsDot)
-  << "{ \"cluster\": \"" << I.getKey() << "\", \"items\": [" << NL;
+  << "{ \"cluster\": \"" << I.getKey() << "\", \"pointer\": \""
+  << (const void *)I.getKey() << "\", \"items\": [" << NL;
 
   ++Space;
   const ClusterBindings  = I.getData();

Modified: cfe/trunk/test/Analysis/dump_egraph.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/dump_egraph.cpp?rev=363896=363895=363896=diff
==
--- cfe/trunk/test/Analysis/dump_egraph.cpp (original)
+++ cfe/trunk/test/Analysis/dump_egraph.cpp Wed Jun 19 16:33:51 2019
@@ -22,6 +22,6 @@ void foo() {
 
 // CHECK: \"location_context\": \"#0 Call\", \"calling\": \"T::T\", 
\"call_line\": \"16\", \"items\": 
[\l\{ \"init_id\": {{[0-9]+}}, 
\"kind\": \"construct into member variable\", \"argument_index\": null, 
\"pretty\": \"s\", \"value\": \"\>s\"
 
-// CHECK: \"cluster\": \"t\", \"items\": 
[\l\{ \"kind\": \"Default\", 
\"offset\": 0, \"value\": \"conj_$2\{int, LC5, no stmt, #1\}\"
+// CHECK: \"cluster\": \"t\", \"pointer\": \"{{0x[0-9a-f]+}}\", \"items\": 
[\l\{ \"kind\": \"Default\", 
\"offset\": 0, \"value\": \"conj_$2\{int, LC5, no stmt, #1\}\"
 
 // CHECK: \"dynamic_types\": [\l\{ \"region\": 
\"HeapSymRegion\{conj_$1\{struct S *, LC1, S{{[0-9]+}}, #1\}\}\", \"dyn_type\": 
\"struct S\", \"sub_classable\": false\}\l

Modified: cfe/trunk/test/Analysis/expr-inspection.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/expr-inspection.c?rev=363896=363895=363896=diff
==
--- cfe/trunk/test/Analysis/expr-inspection.c (original)
+++ cfe/trunk/test/Analysis/expr-inspection.c Wed Jun 19 16:33:51 2019
@@ -25,7 +25,7 @@ void foo(int x) {
 
 // CHECK:  "program_state": {
 // CHECK-NEXT:   "store": [
-// CHECK-NEXT: { "cluster": "y", "items": [
+// CHECK-NEXT: { "cluster": "y", "pointer": "{{0x[0-9a-f]+}}", "items": [
 // CHECK-NEXT:   { "kind": "Direct", "offset": 0, "value": "2 S32b" }
 // CHECK-NEXT: ]}
 // CHECK-NEXT:   ],


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


r363895 - [analyzer] Fix JSON dumps for location contexts.

2019-06-19 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Wed Jun 19 16:33:48 2019
New Revision: 363895

URL: http://llvm.org/viewvc/llvm-project?rev=363895=rev
Log:
[analyzer] Fix JSON dumps for location contexts.

Location context ID is a property of the location context, not of an item
within it. It's useful to know the id even when there are no items
in the context, eg. for the purposes of figuring out how did contents
of the Environment for the same location context changed across states.

Differential Revision: https://reviews.llvm.org/D62754

Modified:
cfe/trunk/lib/Analysis/AnalysisDeclContext.cpp
cfe/trunk/lib/StaticAnalyzer/Core/Environment.cpp
cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
cfe/trunk/test/Analysis/dump_egraph.cpp
cfe/trunk/test/Analysis/expr-inspection.c

Modified: cfe/trunk/lib/Analysis/AnalysisDeclContext.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/AnalysisDeclContext.cpp?rev=363895=363894=363895=diff
==
--- cfe/trunk/lib/Analysis/AnalysisDeclContext.cpp (original)
+++ cfe/trunk/lib/Analysis/AnalysisDeclContext.cpp Wed Jun 19 16:33:48 2019
@@ -527,7 +527,8 @@ void LocationContext::printJson(raw_ostr
 
   unsigned Frame = 0;
   for (const LocationContext *LCtx = this; LCtx; LCtx = LCtx->getParent()) {
-Indent(Out, Space, IsDot) << "{ \"location_context\": \"";
+Indent(Out, Space, IsDot)
+<< "{ \"lctx_id\": " << LCtx->getID() << ", \"location_context\": \"";
 switch (LCtx->getKind()) {
 case StackFrame:
   Out << '#' << Frame << " Call\", \"calling\": \"";
@@ -541,7 +542,7 @@ void LocationContext::printJson(raw_ostr
   if (const Stmt *S = cast(LCtx)->getCallSite()) {
 Out << '\"';
 printLocation(Out, SM, S->getBeginLoc());
-   Out << '\"';
+Out << '\"';
   } else {
 Out << "null";
   }

Modified: cfe/trunk/lib/StaticAnalyzer/Core/Environment.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/Environment.cpp?rev=363895=363894=363895=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/Environment.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/Environment.cpp Wed Jun 19 16:33:48 2019
@@ -261,8 +261,7 @@ void Environment::printJson(raw_ostream
 
   const Stmt *S = I->first.getStmt();
   Indent(Out, InnerSpace, IsDot)
-  << "{ \"lctx_id\": " << LC->getID()
-  << ", \"stmt_id\": " << S->getID(Ctx) << ", \"pretty\": ";
+  << "{ \"stmt_id\": " << S->getID(Ctx) << ", \"pretty\": ";
   S->printJson(Out, nullptr, PP, /*AddQuotes=*/true);
 
   Out << ", \"value\": ";

Modified: cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp?rev=363895=363894=363895=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp Wed Jun 19 16:33:48 2019
@@ -149,9 +149,6 @@ public:
 if (!S)
   I = getItem().getCXXCtorInitializer();
 
-// IDs
-Out << "\"lctx_id\": " << getLocationContext()->getID() << ", ";
-
 if (S)
   Out << "\"stmt_id\": " << S->getID(getASTContext());
 else

Modified: cfe/trunk/test/Analysis/dump_egraph.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/dump_egraph.cpp?rev=363895=363894=363895=diff
==
--- cfe/trunk/test/Analysis/dump_egraph.cpp (original)
+++ cfe/trunk/test/Analysis/dump_egraph.cpp Wed Jun 19 16:33:48 2019
@@ -18,9 +18,9 @@ void foo() {
   new S;
 }
 
-// CHECK: \"location_context\": \"#0 Call\", \"calling\": \"foo\", 
\"call_line\": null, \"items\": 
[\l\{ \"lctx_id\": 1, 
\"stmt_id\": {{[0-9]+}}, \"kind\": \"construct into local variable\", 
\"argument_index\": null, \"pretty\": \"T t;\", \"value\": \"\"
+// CHECK: \"location_context\": \"#0 Call\", \"calling\": \"foo\", 
\"call_line\": null, \"items\": 
[\l\{ \"stmt_id\": {{[0-9]+}}, 
\"kind\": \"construct into local variable\", \"argument_index\": null, 
\"pretty\": \"T t;\", \"value\": \"\"
 
-// CHECK: \"location_context\": \"#0 Call\", \"calling\": \"T::T\", 
\"call_line\": \"16\", \"items\": 
[\l\{ \"lctx_id\": 2, 
\"init_id\": {{[0-9]+}}, \"kind\": \"construct into member variable\", 
\"argument_index\": null, \"pretty\": \"s\", \"value\": \"\>s\"
+// CHECK: \"location_context\": \"#0 Call\", \"calling\": \"T::T\", 
\"call_line\": \"16\", \"items\": 
[\l\{ \"init_id\": {{[0-9]+}}, 
\"kind\": \"construct into member variable\", \"argument_index\": null, 
\"pretty\": \"s\", \"value\": \"\>s\"
 
 // CHECK: \"cluster\": \"t\", \"items\": 
[\l\{ \"kind\": \"Default\", 
\"offset\": 0, \"value\": \"conj_$2\{int, LC5, no stmt, #1\}\"
 

Modified: 

r363891 - [analyzer] RetainCount: Add support for OSRequiredCast().

2019-06-19 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Wed Jun 19 16:33:34 2019
New Revision: 363891

URL: http://llvm.org/viewvc/llvm-project?rev=363891=rev
Log:
[analyzer] RetainCount: Add support for OSRequiredCast().

It's a new API for custom RTTI in Apple IOKit/DriverKit framework that is
similar to OSDynamicCast() that's already supported, but crashes instead of
returning null (and therefore causing UB when the cast fails unexpectedly).
Kind of like cast_or_null<> as opposed to dyn_cast_or_null<> in LLVM's RTTI.

Historically, RetainCountChecker was responsible for modeling OSDynamicCast.
This is simply an extension of the same functionality.

Differential Revision: https://reviews.llvm.org/D63117

Modified:
cfe/trunk/lib/Analysis/RetainSummaryManager.cpp
cfe/trunk/test/Analysis/os_object_base.h
cfe/trunk/test/Analysis/osobject-retain-release.cpp

Modified: cfe/trunk/lib/Analysis/RetainSummaryManager.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/RetainSummaryManager.cpp?rev=363891=363890=363891=diff
==
--- cfe/trunk/lib/Analysis/RetainSummaryManager.cpp (original)
+++ cfe/trunk/lib/Analysis/RetainSummaryManager.cpp Wed Jun 19 16:33:34 2019
@@ -152,6 +152,10 @@ static bool isOSObjectDynamicCast(String
   return S == "safeMetaCast";
 }
 
+static bool isOSObjectRequiredCast(StringRef S) {
+  return S == "requiredMetaCast";
+}
+
 static bool isOSObjectThisCast(StringRef S) {
   return S == "metaCast";
 }
@@ -234,7 +238,8 @@ RetainSummaryManager::getSummaryForOSObj
   if (RetTy->isPointerType()) {
 const CXXRecordDecl *PD = RetTy->getPointeeType()->getAsCXXRecordDecl();
 if (PD && isOSObjectSubclass(PD)) {
-  if (isOSObjectDynamicCast(FName) || isOSObjectThisCast(FName))
+  if (isOSObjectDynamicCast(FName) || isOSObjectRequiredCast(FName) ||
+  isOSObjectThisCast(FName))
 return getDefaultSummary();
 
   // TODO: Add support for the slightly common *Matching(table) idiom.
@@ -745,6 +750,8 @@ RetainSummaryManager::canEval(const Call
 if (TrackOSObjects) {
   if (isOSObjectDynamicCast(FName) && FD->param_size() >= 1) {
 return BehaviorSummary::IdentityOrZero;
+  } else if (isOSObjectRequiredCast(FName) && FD->param_size() >= 1) {
+return BehaviorSummary::Identity;
   } else if (isOSObjectThisCast(FName) && isa(FD) &&
  !cast(FD)->isStatic()) {
 return BehaviorSummary::IdentityThis;

Modified: cfe/trunk/test/Analysis/os_object_base.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/os_object_base.h?rev=363891=363890=363891=diff
==
--- cfe/trunk/test/Analysis/os_object_base.h (original)
+++ cfe/trunk/test/Analysis/os_object_base.h Wed Jun 19 16:33:34 2019
@@ -12,6 +12,8 @@
 
 #define OSDynamicCast(type, inst)   \
 ((type *) OSMetaClassBase::safeMetaCast((inst), OSTypeID(type)))
+#define OSRequiredCast(type, inst)   \
+((type *) OSMetaClassBase::requiredMetaCast((inst), OSTypeID(type)))
 
 #define OSTypeAlloc(type)   ((type *) ((type::metaClass)->alloc()))
 
@@ -22,6 +24,8 @@ struct OSMetaClass;
 struct OSMetaClassBase {
   static OSMetaClassBase *safeMetaCast(const OSMetaClassBase *inst,
const OSMetaClass *meta);
+  static OSMetaClassBase *requiredMetaCast(const OSMetaClassBase *inst,
+   const OSMetaClass *meta);
 
   OSMetaClassBase *metaCast(const char *toMeta);
 

Modified: cfe/trunk/test/Analysis/osobject-retain-release.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/osobject-retain-release.cpp?rev=363891=363890=363891=diff
==
--- cfe/trunk/test/Analysis/osobject-retain-release.cpp (original)
+++ cfe/trunk/test/Analysis/osobject-retain-release.cpp Wed Jun 19 16:33:34 2019
@@ -1,9 +1,11 @@
 // RUN: %clang_analyze_cc1 -fblocks -analyze -analyzer-output=text\
-// RUN:-analyzer-checker=core,osx -verify %s
+// RUN:   -analyzer-checker=core,osx,debug.ExprInspection -verify %s
 
 #include "os_object_base.h"
 #include "os_smart_ptr.h"
 
+void clang_analyzer_eval(bool);
+
 struct OSIterator : public OSObject {
   static const OSMetaClass * const metaClass;
 };
@@ -483,6 +485,23 @@ void check_dynamic_cast() {
   arr->release();
 }
 
+void check_required_cast() {
+  OSArray *arr = OSRequiredCast(OSArray, OSObject::generateObject(1));
+  arr->release(); // no-warning
+}
+
+void check_cast_behavior(OSObject *obj) {
+  OSArray *arr1 = OSDynamicCast(OSArray, obj);
+  clang_analyzer_eval(arr1 == obj); // expected-warning{{TRUE}}
+// expected-note@-1{{TRUE}}
+// expected-note@-2{{Assuming 'arr1' is 
not equal to 'obj'}}
+// 

r363893 - [analyzer] NFC: Change evalCall() to provide a CallEvent.

2019-06-19 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Wed Jun 19 16:33:42 2019
New Revision: 363893

URL: http://llvm.org/viewvc/llvm-project?rev=363893=rev
Log:
[analyzer] NFC: Change evalCall() to provide a CallEvent.

This changes the checker callback signature to use the modern, easy to
use interface. Additionally, this unblocks future work on allowing
checkers to implement evalCall() for calls that don't correspond to any
call-expression or require additional information that's only available
as part of the CallEvent, such as C++ constructors and destructors.

Differential Revision: https://reviews.llvm.org/D62440

Modified:
cfe/trunk/include/clang/StaticAnalyzer/Core/Checker.h
cfe/trunk/include/clang/StaticAnalyzer/Core/CheckerManager.h
cfe/trunk/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp
cfe/trunk/lib/StaticAnalyzer/Checkers/CStringChecker.cpp
cfe/trunk/lib/StaticAnalyzer/Checkers/ChrootChecker.cpp
cfe/trunk/lib/StaticAnalyzer/Checkers/ExprInspectionChecker.cpp

cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.cpp

cfe/trunk/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountChecker.h
cfe/trunk/lib/StaticAnalyzer/Checkers/SmartPtrModeling.cpp
cfe/trunk/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
cfe/trunk/lib/StaticAnalyzer/Checkers/StreamChecker.cpp
cfe/trunk/lib/StaticAnalyzer/Core/CheckerManager.cpp

Modified: cfe/trunk/include/clang/StaticAnalyzer/Core/Checker.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/Checker.h?rev=363893=363892=363893=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Core/Checker.h (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/Checker.h Wed Jun 19 16:33:42 
2019
@@ -474,8 +474,9 @@ public:
 
 class Call {
   template 
-  static bool _evalCall(void *checker, const CallExpr *CE, CheckerContext ) {
-return ((const CHECKER *)checker)->evalCall(CE, C);
+  static bool _evalCall(void *checker, const CallEvent ,
+CheckerContext ) {
+return ((const CHECKER *)checker)->evalCall(Call, C);
   }
 
 public:

Modified: cfe/trunk/include/clang/StaticAnalyzer/Core/CheckerManager.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Core/CheckerManager.h?rev=363893=363892=363893=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Core/CheckerManager.h (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Core/CheckerManager.h Wed Jun 19 
16:33:42 2019
@@ -490,7 +490,7 @@ public:
   CheckerFn;
 
-  using EvalCallFunc = CheckerFn;
+  using EvalCallFunc = CheckerFn;
 
   using CheckEndOfTranslationUnit =
   CheckerFnhttp://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp?rev=363893=363892=363893=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/BuiltinFunctionChecker.cpp Wed Jun 19 
16:33:42 2019
@@ -14,6 +14,7 @@
 #include "clang/Basic/Builtins.h"
 #include "clang/StaticAnalyzer/Core/Checker.h"
 #include "clang/StaticAnalyzer/Core/CheckerManager.h"
+#include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
 #include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
 
 using namespace clang;
@@ -23,30 +24,32 @@ namespace {
 
 class BuiltinFunctionChecker : public Checker {
 public:
-  bool evalCall(const CallExpr *CE, CheckerContext ) const;
+  bool evalCall(const CallEvent , CheckerContext ) const;
 };
 
 }
 
-bool BuiltinFunctionChecker::evalCall(const CallExpr *CE,
+bool BuiltinFunctionChecker::evalCall(const CallEvent ,
   CheckerContext ) const {
   ProgramStateRef state = C.getState();
-  const FunctionDecl *FD = C.getCalleeDecl(CE);
-  const LocationContext *LCtx = C.getLocationContext();
+  const auto *FD = dyn_cast_or_null(Call.getDecl());
   if (!FD)
 return false;
 
+  const LocationContext *LCtx = C.getLocationContext();
+  const Expr *CE = Call.getOriginExpr();
+
   switch (FD->getBuiltinID()) {
   default:
 return false;
 
   case Builtin::BI__builtin_assume: {
-assert (CE->arg_begin() != CE->arg_end());
-SVal ArgSVal = C.getSVal(CE->getArg(0));
-if (ArgSVal.isUndef())
+assert (Call.getNumArgs() > 0);
+SVal Arg = Call.getArgSVal(0);
+if (Arg.isUndef())
   return true; // Return true to model purity.
 
-state = state->assume(ArgSVal.castAs(), true);
+state = state->assume(Arg.castAs(), true);
 // FIXME: do we want to warn here? Not right now. The most reports might
 // come from infeasible paths, thus being false positives.
 if (!state) {
@@ -66,9 +69,9 @@ bool BuiltinFunctionChecker::evalCall(co
 // __builtin_assume_aligned, 

[PATCH] D63082: [Diagnostics] Added support for -Wint-in-bool-context

2019-06-19 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 updated this revision to Diff 205696.
xbolva00 added a comment.

Addressed review notes. Thanks!


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

https://reviews.llvm.org/D63082

Files:
  include/clang/Basic/DiagnosticGroups.td
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/Sema/SemaChecking.cpp
  test/Analysis/misc-ps.c
  test/Sema/integer-overflow.c
  test/Sema/parentheses.c
  test/Sema/parentheses.cpp
  test/Sema/warn-unreachable.c
  test/SemaCXX/constexpr-printing.cpp
  test/SemaCXX/integer-overflow.cpp
  test/SemaCXX/nested-name-spec.cpp
  test/SemaCXX/warn-unreachable.cpp

Index: test/SemaCXX/warn-unreachable.cpp
===
--- test/SemaCXX/warn-unreachable.cpp
+++ test/SemaCXX/warn-unreachable.cpp
@@ -186,13 +186,13 @@
 
 
 int test_enum_sizeof_arithmetic() {
-  if (BrownCow)
+  if (BrownCow) // expected-warning {{enum constant in boolean context}}
 return 1;
   return 2;
 }
 
 int test_enum_arithmetic() {
-  if (CowBrown)
+  if (CowBrown) // expected-warning {{enum constant in boolean context}}
 return 1;
   return 2; // expected-warning {{never be executed}}
 }
Index: test/SemaCXX/nested-name-spec.cpp
===
--- test/SemaCXX/nested-name-spec.cpp
+++ test/SemaCXX/nested-name-spec.cpp
@@ -402,9 +402,9 @@
 T1 var_1a;
 T1 var_1b;  // expected-error{{unexpected ':' in nested name specifier; did you mean '::'?}}
 template int F() {}
-int (*X1)() = (B1::B2 ? F<1> : F<2>);
+int (*X1)() = (B1::B2 ? F<1> : F<2>); // expected-warning {{enum constant in boolean context}}
 int (*X2)() = (B1:B2 ? F<1> : F<2>);  // expected-error{{unexpected ':' in nested name specifier; did you mean '::'?}}
-
+// expected-warning@-1 {{enum constant in boolean context}}
 // Bit fields + templates
 struct S7a {
   T1::C1 m1 : T1::N1;
Index: test/SemaCXX/integer-overflow.cpp
===
--- test/SemaCXX/integer-overflow.cpp
+++ test/SemaCXX/integer-overflow.cpp
@@ -41,13 +41,13 @@
   uint64_t not_overflow2 = (1ULL * ((uint64_t)(4608) * (1024 * 1024)) + 2ULL);
 
 // expected-warning@+1 2{{overflow in expression; result is 536870912 with type 'int'}}
-  overflow = 4608 * 1024 * 1024 ?  4608 * 1024 * 1024 : 0;
+  overflow = 4608 * 1024 * 1024 ?  4608 * 1024 * 1024 : 0; // expected-warning {{'*' in boolean context}}
 
 // expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
   overflow =  0 ? 0 : 4608 * 1024 * 1024;
 
 // expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
-  if (4608 * 1024 * 1024)
+  if (4608 * 1024 * 1024) // expected-warning {{'*' in boolean context}}
 return 0;
 
 // expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
@@ -100,7 +100,7 @@
 #endif
 
 // expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
-  while (4608 * 1024 * 1024);
+  while (4608 * 1024 * 1024); // expected-warning {{'*' in boolean context}}
 
 // expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
   while ((uint64_t)(4608 * 1024 * 1024));
@@ -121,7 +121,7 @@
   while ((uint64_t)((uint64_t)(4608 * 1024 * 1024) * (uint64_t)(4608 * 1024 * 1024)));
 
 // expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
-  do { } while (4608 * 1024 * 1024);
+  do { } while (4608 * 1024 * 1024); // expected-warning {{'*' in boolean context}}
 
 // expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}}
   do { } while ((uint64_t)(4608 * 1024 * 1024));
Index: test/SemaCXX/constexpr-printing.cpp
===
--- test/SemaCXX/constexpr-printing.cpp
+++ test/SemaCXX/constexpr-printing.cpp
@@ -99,6 +99,7 @@
   a:b:return;
 }
 
+// expected-warning@+1 {{'*' in boolean context}}
 constexpr bool test_bool_printing(bool b) { return 1 / !(2*b | !(2*b)); } // expected-note 2{{division by zero}}
 constexpr bool test_bool_0 = test_bool_printing(false); // expected-error {{constant expr}} expected-note {{in call to 'test_bool_printing(false)'}}
 constexpr bool test_bool_1 = test_bool_printing(true); // expected-error {{constant expr}} expected-note {{in call to 'test_bool_printing(true)'}}
Index: test/Sema/warn-unreachable.c
===
--- test/Sema/warn-unreachable.c
+++ test/Sema/warn-unreachable.c
@@ -141,7 +141,9 @@
 void test_mul_and_zero(int x) {
   if (x & 0) calledFun(); // expected-warning {{will never be executed}}
   if (0 & x) calledFun(); // expected-warning {{will never be executed}}
+  // expected-warning@+1 {{'*' in boolean context}}
   if (x * 0) calledFun(); // expected-warning {{will never be executed}}
+  // expected-warning@+1 {{'*' in boolean context}}
   if (0 * x) calledFun(); // expected-warning {{will never be 

r363890 - [X86] Correct the __min_vector_width__ attribute on a few intrinsics.

2019-06-19 Thread Craig Topper via cfe-commits
Author: ctopper
Date: Wed Jun 19 16:27:04 2019
New Revision: 363890

URL: http://llvm.org/viewvc/llvm-project?rev=363890=rev
Log:
[X86] Correct the __min_vector_width__ attribute on a few intrinsics.

Modified:
cfe/trunk/lib/Headers/avx512bwintrin.h
cfe/trunk/lib/Headers/avx512vlintrin.h

Modified: cfe/trunk/lib/Headers/avx512bwintrin.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/avx512bwintrin.h?rev=363890=363889=363890=diff
==
--- cfe/trunk/lib/Headers/avx512bwintrin.h (original)
+++ cfe/trunk/lib/Headers/avx512bwintrin.h Wed Jun 19 16:27:04 2019
@@ -1711,14 +1711,14 @@ _mm512_maskz_set1_epi8 (__mmask64 __M, c
   (__v64qi) 
_mm512_setzero_si512());
 }
 
-static __inline__ __mmask64 __DEFAULT_FN_ATTRS512
+static __inline__ __mmask64 __DEFAULT_FN_ATTRS
 _mm512_kunpackd (__mmask64 __A, __mmask64 __B)
 {
   return (__mmask64) __builtin_ia32_kunpckdi ((__mmask64) __A,
 (__mmask64) __B);
 }
 
-static __inline__ __mmask32 __DEFAULT_FN_ATTRS512
+static __inline__ __mmask32 __DEFAULT_FN_ATTRS
 _mm512_kunpackw (__mmask32 __A, __mmask32 __B)
 {
   return (__mmask32) __builtin_ia32_kunpcksi ((__mmask32) __A,

Modified: cfe/trunk/lib/Headers/avx512vlintrin.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/avx512vlintrin.h?rev=363890=363889=363890=diff
==
--- cfe/trunk/lib/Headers/avx512vlintrin.h (original)
+++ cfe/trunk/lib/Headers/avx512vlintrin.h Wed Jun 19 16:27:04 2019
@@ -6986,7 +6986,7 @@ _mm_mask_cvtsepi32_storeu_epi8 (void * _
   __builtin_ia32_pmovsdb128mem_mask ((__v16qi *) __P, (__v4si) __A, __M);
 }
 
-static __inline__ __m128i __DEFAULT_FN_ATTRS128
+static __inline__ __m128i __DEFAULT_FN_ATTRS256
 _mm256_cvtsepi32_epi8 (__m256i __A)
 {
   return (__m128i) __builtin_ia32_pmovsdb256_mask ((__v8si) __A,
@@ -7009,7 +7009,7 @@ _mm256_maskz_cvtsepi32_epi8 (__mmask8 __
__M);
 }
 
-static __inline__ void __DEFAULT_FN_ATTRS128
+static __inline__ void __DEFAULT_FN_ATTRS256
 _mm256_mask_cvtsepi32_storeu_epi8 (void * __P, __mmask8 __M, __m256i __A)
 {
   __builtin_ia32_pmovsdb256mem_mask ((__v16qi *) __P, (__v8si) __A, __M);
@@ -7567,7 +7567,7 @@ _mm_maskz_cvtepi32_epi8 (__mmask8 __M, _
   __M);
 }
 
-static __inline__ void __DEFAULT_FN_ATTRS256
+static __inline__ void __DEFAULT_FN_ATTRS128
 _mm_mask_cvtepi32_storeu_epi8 (void * __P, __mmask8 __M, __m128i __A)
 {
   __builtin_ia32_pmovdb128mem_mask ((__v16qi *) __P, (__v4si) __A, __M);


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


[PATCH] D63575: [WebAssembly] Add builtin functions for creating vector constants

2019-06-19 Thread Thomas Lively via Phabricator via cfe-commits
tlively added a comment.

This CL does not provide a mechanism for enforcing that the lanes of a floating 
point vector are constant, and it doesn't look like clang supports that kind of 
check. That makes this CL a half-baked solution, so I'm not sure we should 
actually go in this direction.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63575



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


[clang-tools-extra] r363889 - [clangd] Include the diagnostics's code when comparing diagnostics

2019-06-19 Thread Nathan Ridge via cfe-commits
Author: nridge
Date: Wed Jun 19 16:11:02 2019
New Revision: 363889

URL: http://llvm.org/viewvc/llvm-project?rev=363889=rev
Log:
[clangd] Include the diagnostics's code when comparing diagnostics

Summary: This fixes https://github.com/clangd/clangd/issues/60

Reviewers: kadircet

Reviewed By: kadircet

Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D63316

Added:
clang-tools-extra/trunk/clangd/test/fixits-duplication.test
Modified:
clang-tools-extra/trunk/clangd/Protocol.h

Modified: clang-tools-extra/trunk/clangd/Protocol.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Protocol.h?rev=363889=363888=363889=diff
==
--- clang-tools-extra/trunk/clangd/Protocol.h (original)
+++ clang-tools-extra/trunk/clangd/Protocol.h Wed Jun 19 16:11:02 2019
@@ -616,7 +616,6 @@ struct DocumentSymbolParams {
 };
 bool fromJSON(const llvm::json::Value &, DocumentSymbolParams &);
 
-
 /// Represents a related message and source code location for a diagnostic.
 /// This should be used to point to code locations that cause or related to a
 /// diagnostics, e.g when duplicating a symbol in a scope.
@@ -666,11 +665,17 @@ llvm::json::Value toJSON(const Diagnosti
 
 /// A LSP-specific comparator used to find diagnostic in a container like
 /// std:map.
-/// We only use the required fields of Diagnostic to do the comparsion to avoid
-/// any regression issues from LSP clients (e.g. VScode), see
-/// https://git.io/vbr29
+/// We only use as many fields of Diagnostic as is needed to make distinct
+/// diagnostics unique in practice, to avoid  regression issues from LSP 
clients
+/// (e.g. VScode), see https://git.io/vbr29
 struct LSPDiagnosticCompare {
   bool operator()(const Diagnostic , const Diagnostic ) const {
+if (!LHS.code.empty() && !RHS.code.empty()) {
+  // If the code is known for both, use the code to diambiguate, as e.g.
+  // two checkers could produce diagnostics with the same range and 
message.
+  return std::tie(LHS.range, LHS.message, LHS.code) <
+ std::tie(RHS.range, RHS.message, RHS.code);
+}
 return std::tie(LHS.range, LHS.message) < std::tie(RHS.range, RHS.message);
   }
 };

Added: clang-tools-extra/trunk/clangd/test/fixits-duplication.test
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/test/fixits-duplication.test?rev=363889=auto
==
--- clang-tools-extra/trunk/clangd/test/fixits-duplication.test (added)
+++ clang-tools-extra/trunk/clangd/test/fixits-duplication.test Wed Jun 19 
16:11:02 2019
@@ -0,0 +1,221 @@
+# RUN: clangd -lit-test 
-clang-tidy-checks=modernize-use-nullptr,hicpp-use-nullptr < %s | FileCheck 
-strict-whitespace %s
+{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"clangd","capabilities":{"textDocument":{"codeAction":{"codeActionLiteralSupport":{,"trace":"off"}}
+---
+{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"test:///foo.cpp","languageId":"cpp","version":1,"text":"void
 foo() { char* p = 0; }"}}}
+#  CHECK:"method": "textDocument/publishDiagnostics",
+# CHECK-NEXT:  "params": {
+# CHECK-NEXT:"diagnostics": [
+# CHECK-NEXT:  {
+# CHECK-NEXT:"code": "hicpp-use-nullptr",
+# CHECK-NEXT:"message": "Use nullptr (fix available)",
+# CHECK-NEXT:"range": {
+# CHECK-NEXT:  "end": {
+# CHECK-NEXT:"character": 24,
+# CHECK-NEXT:"line": 0
+# CHECK-NEXT:  },
+# CHECK-NEXT:  "start": {
+# CHECK-NEXT:"character": 23,
+# CHECK-NEXT:"line": 0
+# CHECK-NEXT:  }
+# CHECK-NEXT:},
+# CHECK-NEXT:"severity": 2,
+# CHECK-NEXT:"source": "clang-tidy"
+# CHECK-NEXT:  },
+# CHECK-NEXT:  {
+# CHECK-NEXT:"code": "modernize-use-nullptr",
+# CHECK-NEXT:"message": "Use nullptr (fix available)",
+# CHECK-NEXT:"range": {
+# CHECK-NEXT:  "end": {
+# CHECK-NEXT:"character": 24,
+# CHECK-NEXT:"line": 0
+# CHECK-NEXT:  },
+# CHECK-NEXT:  "start": {
+# CHECK-NEXT:"character": 23,
+# CHECK-NEXT:"line": 0
+# CHECK-NEXT:  }
+# CHECK-NEXT:},
+# CHECK-NEXT:"severity": 2,
+# CHECK-NEXT:"source": "clang-tidy"
+# CHECK-NEXT:  }
+# CHECK-NEXT:],
+# CHECK-NEXT:"uri": "file:///{{.*}}/foo.cpp"
+# CHECK-NEXT:  }
+---
+{"jsonrpc":"2.0","id":2,"method":"textDocument/codeAction","params":{"textDocument":{"uri":"test:///foo.cpp"},"range":{"start":{"line":0,"character":23},"end":{"line":0,"character":24}},"context":{"diagnostics":[{"range":{"start":
 {"line": 0, "character": 23}, "end": {"line": 0, "character": 
24}},"severity":2,"message":"Use nullptr (fix 

[PATCH] D63316: [clangd] Include the diagnostics's code when comparing diagnostics

2019-06-19 Thread Nathan Ridge via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL363889: [clangd] Include the diagnosticss code when 
comparing diagnostics (authored by nridge, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D63316?vs=205694=205695#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D63316

Files:
  clang-tools-extra/trunk/clangd/Protocol.h
  clang-tools-extra/trunk/clangd/test/fixits-duplication.test

Index: clang-tools-extra/trunk/clangd/test/fixits-duplication.test
===
--- clang-tools-extra/trunk/clangd/test/fixits-duplication.test
+++ clang-tools-extra/trunk/clangd/test/fixits-duplication.test
@@ -0,0 +1,221 @@
+# RUN: clangd -lit-test -clang-tidy-checks=modernize-use-nullptr,hicpp-use-nullptr < %s | FileCheck -strict-whitespace %s
+{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"clangd","capabilities":{"textDocument":{"codeAction":{"codeActionLiteralSupport":{,"trace":"off"}}
+---
+{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"test:///foo.cpp","languageId":"cpp","version":1,"text":"void foo() { char* p = 0; }"}}}
+#  CHECK:"method": "textDocument/publishDiagnostics",
+# CHECK-NEXT:  "params": {
+# CHECK-NEXT:"diagnostics": [
+# CHECK-NEXT:  {
+# CHECK-NEXT:"code": "hicpp-use-nullptr",
+# CHECK-NEXT:"message": "Use nullptr (fix available)",
+# CHECK-NEXT:"range": {
+# CHECK-NEXT:  "end": {
+# CHECK-NEXT:"character": 24,
+# CHECK-NEXT:"line": 0
+# CHECK-NEXT:  },
+# CHECK-NEXT:  "start": {
+# CHECK-NEXT:"character": 23,
+# CHECK-NEXT:"line": 0
+# CHECK-NEXT:  }
+# CHECK-NEXT:},
+# CHECK-NEXT:"severity": 2,
+# CHECK-NEXT:"source": "clang-tidy"
+# CHECK-NEXT:  },
+# CHECK-NEXT:  {
+# CHECK-NEXT:"code": "modernize-use-nullptr",
+# CHECK-NEXT:"message": "Use nullptr (fix available)",
+# CHECK-NEXT:"range": {
+# CHECK-NEXT:  "end": {
+# CHECK-NEXT:"character": 24,
+# CHECK-NEXT:"line": 0
+# CHECK-NEXT:  },
+# CHECK-NEXT:  "start": {
+# CHECK-NEXT:"character": 23,
+# CHECK-NEXT:"line": 0
+# CHECK-NEXT:  }
+# CHECK-NEXT:},
+# CHECK-NEXT:"severity": 2,
+# CHECK-NEXT:"source": "clang-tidy"
+# CHECK-NEXT:  }
+# CHECK-NEXT:],
+# CHECK-NEXT:"uri": "file:///{{.*}}/foo.cpp"
+# CHECK-NEXT:  }
+---
+{"jsonrpc":"2.0","id":2,"method":"textDocument/codeAction","params":{"textDocument":{"uri":"test:///foo.cpp"},"range":{"start":{"line":0,"character":23},"end":{"line":0,"character":24}},"context":{"diagnostics":[{"range":{"start": {"line": 0, "character": 23}, "end": {"line": 0, "character": 24}},"severity":2,"message":"Use nullptr (fix available)", "code": "hicpp-use-nullptr", "source": "clang-tidy"},{"range":{"start": {"line": 0, "character": 23}, "end": {"line": 0, "character": 24}},"severity":2,"message":"Use nullptr (fix available)", "code": "modernize-use-nullptr", "source": "clang-tidy"}]}}}
+#  CHECK:  "id": 2,
+# CHECK-NEXT:  "jsonrpc": "2.0",
+# CHECK-NEXT:  "result": [
+# CHECK-NEXT:{
+# CHECK-NEXT:  "diagnostics": [
+# CHECK-NEXT:{
+# CHECK-NEXT:  "code": "hicpp-use-nullptr",
+# CHECK-NEXT:  "message": "Use nullptr (fix available)",
+# CHECK-NEXT:  "range": {
+# CHECK-NEXT:"end": {
+# CHECK-NEXT:  "character": 24,
+# CHECK-NEXT:  "line": 0
+# CHECK-NEXT:},
+# CHECK-NEXT:"start": {
+# CHECK-NEXT:  "character": 23,
+# CHECK-NEXT:  "line": 0
+# CHECK-NEXT:}
+# CHECK-NEXT:  },
+# CHECK-NEXT:  "severity": 2,
+# CHECK-NEXT:  "source": "clang-tidy"
+# CHECK-NEXT:}
+# CHECK-NEXT:  ],
+# CHECK-NEXT:  "edit": {
+# CHECK-NEXT:"changes": {
+# CHECK-NEXT:  "file://{{.*}}/foo.cpp": [
+# CHECK-NEXT:{
+# CHECK-NEXT:  "newText": "nullptr",
+# CHECK-NEXT:  "range": {
+# CHECK-NEXT:"end": {
+# CHECK-NEXT:  "character": 24,
+# CHECK-NEXT:  "line": 0
+# CHECK-NEXT:},
+# CHECK-NEXT:"start": {
+# CHECK-NEXT:  "character": 23,
+# CHECK-NEXT:  "line": 0
+# CHECK-NEXT:}
+# CHECK-NEXT:  }
+# CHECK-NEXT:}
+# CHECK-NEXT:  ]
+# CHECK-NEXT:}
+# CHECK-NEXT:  },
+# CHECK-NEXT:  "kind": "quickfix",
+# CHECK-NEXT:  "title": "change '0' to 'nullptr'"
+# CHECK-NEXT:},
+# CHECK-NEXT:{
+# CHECK-NEXT:  "diagnostics": [
+# 

[PATCH] D63316: [clangd] Include the diagnostics's code when comparing diagnostics

2019-06-19 Thread Nathan Ridge via Phabricator via cfe-commits
nridge updated this revision to Diff 205694.
nridge added a comment.

Add requested test case


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63316

Files:
  clang-tools-extra/clangd/Protocol.h
  clang-tools-extra/clangd/test/fixits-duplication.test

Index: clang-tools-extra/clangd/test/fixits-duplication.test
===
--- /dev/null
+++ clang-tools-extra/clangd/test/fixits-duplication.test
@@ -0,0 +1,221 @@
+# RUN: clangd -lit-test -clang-tidy-checks=modernize-use-nullptr,hicpp-use-nullptr < %s | FileCheck -strict-whitespace %s
+{"jsonrpc":"2.0","id":0,"method":"initialize","params":{"processId":123,"rootPath":"clangd","capabilities":{"textDocument":{"codeAction":{"codeActionLiteralSupport":{,"trace":"off"}}
+---
+{"jsonrpc":"2.0","method":"textDocument/didOpen","params":{"textDocument":{"uri":"test:///foo.cpp","languageId":"cpp","version":1,"text":"void foo() { char* p = 0; }"}}}
+#  CHECK:"method": "textDocument/publishDiagnostics",
+# CHECK-NEXT:  "params": {
+# CHECK-NEXT:"diagnostics": [
+# CHECK-NEXT:  {
+# CHECK-NEXT:"code": "hicpp-use-nullptr",
+# CHECK-NEXT:"message": "Use nullptr (fix available)",
+# CHECK-NEXT:"range": {
+# CHECK-NEXT:  "end": {
+# CHECK-NEXT:"character": 24,
+# CHECK-NEXT:"line": 0
+# CHECK-NEXT:  },
+# CHECK-NEXT:  "start": {
+# CHECK-NEXT:"character": 23,
+# CHECK-NEXT:"line": 0
+# CHECK-NEXT:  }
+# CHECK-NEXT:},
+# CHECK-NEXT:"severity": 2,
+# CHECK-NEXT:"source": "clang-tidy"
+# CHECK-NEXT:  },
+# CHECK-NEXT:  {
+# CHECK-NEXT:"code": "modernize-use-nullptr",
+# CHECK-NEXT:"message": "Use nullptr (fix available)",
+# CHECK-NEXT:"range": {
+# CHECK-NEXT:  "end": {
+# CHECK-NEXT:"character": 24,
+# CHECK-NEXT:"line": 0
+# CHECK-NEXT:  },
+# CHECK-NEXT:  "start": {
+# CHECK-NEXT:"character": 23,
+# CHECK-NEXT:"line": 0
+# CHECK-NEXT:  }
+# CHECK-NEXT:},
+# CHECK-NEXT:"severity": 2,
+# CHECK-NEXT:"source": "clang-tidy"
+# CHECK-NEXT:  }
+# CHECK-NEXT:],
+# CHECK-NEXT:"uri": "file:///{{.*}}/foo.cpp"
+# CHECK-NEXT:  }
+---
+{"jsonrpc":"2.0","id":2,"method":"textDocument/codeAction","params":{"textDocument":{"uri":"test:///foo.cpp"},"range":{"start":{"line":0,"character":23},"end":{"line":0,"character":24}},"context":{"diagnostics":[{"range":{"start": {"line": 0, "character": 23}, "end": {"line": 0, "character": 24}},"severity":2,"message":"Use nullptr (fix available)", "code": "hicpp-use-nullptr", "source": "clang-tidy"},{"range":{"start": {"line": 0, "character": 23}, "end": {"line": 0, "character": 24}},"severity":2,"message":"Use nullptr (fix available)", "code": "modernize-use-nullptr", "source": "clang-tidy"}]}}}
+#  CHECK:  "id": 2,
+# CHECK-NEXT:  "jsonrpc": "2.0",
+# CHECK-NEXT:  "result": [
+# CHECK-NEXT:{
+# CHECK-NEXT:  "diagnostics": [
+# CHECK-NEXT:{
+# CHECK-NEXT:  "code": "hicpp-use-nullptr",
+# CHECK-NEXT:  "message": "Use nullptr (fix available)",
+# CHECK-NEXT:  "range": {
+# CHECK-NEXT:"end": {
+# CHECK-NEXT:  "character": 24,
+# CHECK-NEXT:  "line": 0
+# CHECK-NEXT:},
+# CHECK-NEXT:"start": {
+# CHECK-NEXT:  "character": 23,
+# CHECK-NEXT:  "line": 0
+# CHECK-NEXT:}
+# CHECK-NEXT:  },
+# CHECK-NEXT:  "severity": 2,
+# CHECK-NEXT:  "source": "clang-tidy"
+# CHECK-NEXT:}
+# CHECK-NEXT:  ],
+# CHECK-NEXT:  "edit": {
+# CHECK-NEXT:"changes": {
+# CHECK-NEXT:  "file://{{.*}}/foo.cpp": [
+# CHECK-NEXT:{
+# CHECK-NEXT:  "newText": "nullptr",
+# CHECK-NEXT:  "range": {
+# CHECK-NEXT:"end": {
+# CHECK-NEXT:  "character": 24,
+# CHECK-NEXT:  "line": 0
+# CHECK-NEXT:},
+# CHECK-NEXT:"start": {
+# CHECK-NEXT:  "character": 23,
+# CHECK-NEXT:  "line": 0
+# CHECK-NEXT:}
+# CHECK-NEXT:  }
+# CHECK-NEXT:}
+# CHECK-NEXT:  ]
+# CHECK-NEXT:}
+# CHECK-NEXT:  },
+# CHECK-NEXT:  "kind": "quickfix",
+# CHECK-NEXT:  "title": "change '0' to 'nullptr'"
+# CHECK-NEXT:},
+# CHECK-NEXT:{
+# CHECK-NEXT:  "diagnostics": [
+# CHECK-NEXT:{
+# CHECK-NEXT:  "code": "modernize-use-nullptr",
+# CHECK-NEXT:  "message": "Use nullptr (fix available)",
+# CHECK-NEXT:  "range": {
+# CHECK-NEXT:"end": {
+# CHECK-NEXT:  "character": 24,
+# CHECK-NEXT:  "line": 0
+# CHECK-NEXT:

[PATCH] D63533: [analyzer] Fix clang-tidy crash on GCCAsmStmt

2019-06-19 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 added inline comments.



Comment at: clang/lib/StaticAnalyzer/Core/CoreEngine.cpp:401
+  case Stmt::GCCAsmStmtClass:
+return;
 }

nickdesaulniers wrote:
> nickdesaulniers wrote:
> > NoQ wrote:
> > > Please add a TODO to actually implement this functionality.
> > And an `assert` that this `Stmt::isAsmGoto() == true`. (We should not hit 
> > this for any inline assembly, just asm goto statements)
> Take a look at other `assert`s in the codebase.  They usually are in the 
> form: `assert(some_expr_should_be_true && "helpful error message when 
> false");`
or llvm_unreachable :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63533



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


[PATCH] D61809: [BPF] Preserve debuginfo array/union/struct type/access index

2019-06-19 Thread Yonghong Song via Phabricator via cfe-commits
yonghong-song marked an inline comment as done.
yonghong-song added a comment.

@eli.friedman Sorry for replying late. I am outside US and currently in PTO. 
Will back to US soon to address your comments.

> can we really expect the user to know which expressions to apply this to?

Yes, this is specifically targeting some bpf helper calls like bpf_probe_read. 
So users know which expressions to apply.

> I'd like to see an actual specification for this in 
> docs/LanguageExtensions.rst at some point.

I will find a place to put this into docs/LanguageExtensions.rst.




Comment at: lib/CodeGen/CGExpr.cpp:663
+  while (true) {
+const auto  = getContext().getParents(*E);
+if (Parents.size() != 1)

efriedma wrote:
> I'm not sure you can use getParents like this safely... it's not really meant 
> for use inside of clang semantic analysis/code generation, and I don't think 
> we recompute it as the AST changes.
Good point. Let me check whether I can traverse AST instead.


Repository:
  rC Clang

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

https://reviews.llvm.org/D61809



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


[PATCH] D63533: [analyzer] Fix clang-tidy crash on GCCAsmStmt

2019-06-19 Thread Tom Roeder via Phabricator via cfe-commits
tmroeder added a comment.

I can confirm that this fixes the clang-tidy crash I observed in trying to 
analyze the kernel.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63533



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


[PATCH] D63578: AMDGPU: Add DS GWS sema builtins

2019-06-19 Thread Matt Arsenault via Phabricator via cfe-commits
arsenm created this revision.
arsenm added reviewers: rampitec, b-sumner, yaxunl.
Herald added subscribers: t-tye, tpr, dstuttard, nhaehnle, wdng, jvesely, 
kzhuravl.
arsenm added a parent revision: D63576: AMDGPU: Add intrinsics for DS GWS 
semaphore instructions.

https://reviews.llvm.org/D63578

Files:
  include/clang/Basic/BuiltinsAMDGPU.def
  test/CodeGenOpenCL/builtins-amdgcn-ci.cl
  test/CodeGenOpenCL/builtins-amdgcn.cl
  test/SemaOpenCL/builtins-amdgcn-error-ci.cl


Index: test/SemaOpenCL/builtins-amdgcn-error-ci.cl
===
--- test/SemaOpenCL/builtins-amdgcn-error-ci.cl
+++ test/SemaOpenCL/builtins-amdgcn-error-ci.cl
@@ -1,8 +1,9 @@
 // REQUIRES: amdgpu-registered-target
 // RUN: %clang_cc1 -triple amdgcn-- -target-cpu tahiti -verify -S -o - %s
 
-void test_ci_biltins()
+void test_ci_builtins()
 {
   __builtin_amdgcn_s_dcache_inv_vol(); // expected-error 
{{'__builtin_amdgcn_s_dcache_inv_vol' needs target feature ci-insts}}
   __builtin_amdgcn_buffer_wbinvl1_vol(); // expected-error 
{{'__builtin_amdgcn_buffer_wbinvl1_vol' needs target feature ci-insts}}
+  __builtin_amdgcn_ds_gws_sema_release_all(0); // expected-error 
{{'__builtin_amdgcn_ds_gws_sema_release_all' needs target feature ci-insts}}
 }
Index: test/CodeGenOpenCL/builtins-amdgcn.cl
===
--- test/CodeGenOpenCL/builtins-amdgcn.cl
+++ test/CodeGenOpenCL/builtins-amdgcn.cl
@@ -560,6 +560,24 @@
   __builtin_amdgcn_ds_gws_barrier(value, id);
 }
 
+// CHECK-LABEL: @test_gws_sema_v(
+// CHECK: call void @llvm.amdgcn.ds.gws.sema.v(i32 %id)
+kernel void test_gws_sema_v(uint id) {
+  __builtin_amdgcn_ds_gws_sema_v(id);
+}
+
+// CHECK-LABEL: @test_gws_sema_br(
+// CHECK: call void @llvm.amdgcn.ds.gws.sema.br(i32 %value, i32 %id)
+kernel void test_gws_sema_br(uint value, uint id) {
+  __builtin_amdgcn_ds_gws_sema_br(value, id);
+}
+
+// CHECK-LABEL: @test_gws_sema_p(
+// CHECK: call void @llvm.amdgcn.ds.gws.sema.p(i32 %id)
+kernel void test_gws_sema_p(uint id) {
+  __builtin_amdgcn_ds_gws_sema_p(id);
+}
+
 // CHECK-DAG: [[$WI_RANGE]] = !{i32 0, i32 1024}
 // CHECK-DAG: attributes #[[$NOUNWIND_READONLY:[0-9]+]] = { nounwind readonly }
 // CHECK-DAG: attributes #[[$READ_EXEC_ATTRS]] = { convergent }
Index: test/CodeGenOpenCL/builtins-amdgcn-ci.cl
===
--- test/CodeGenOpenCL/builtins-amdgcn-ci.cl
+++ test/CodeGenOpenCL/builtins-amdgcn-ci.cl
@@ -17,3 +17,9 @@
   __builtin_amdgcn_buffer_wbinvl1_vol();
 }
 
+// CHECK-LABEL: @test_gws_sema_release_all(
+// CHECK: call void @llvm.amdgcn.ds.gws.sema.release.all(i32 %id)
+kernel void test_gws_sema_p(uint id)
+{
+  __builtin_amdgcn_ds_gws_sema_release_all(id);
+}
Index: include/clang/Basic/BuiltinsAMDGPU.def
===
--- include/clang/Basic/BuiltinsAMDGPU.def
+++ include/clang/Basic/BuiltinsAMDGPU.def
@@ -47,6 +47,9 @@
 BUILTIN(__builtin_amdgcn_buffer_wbinvl1, "v", "n")
 BUILTIN(__builtin_amdgcn_ds_gws_init, "vUiUi", "n")
 BUILTIN(__builtin_amdgcn_ds_gws_barrier, "vUiUi", "n")
+BUILTIN(__builtin_amdgcn_ds_gws_sema_v, "vUi", "n")
+BUILTIN(__builtin_amdgcn_ds_gws_sema_br, "vUiUi", "n")
+BUILTIN(__builtin_amdgcn_ds_gws_sema_p, "vUi", "n")
 
 // FIXME: Need to disallow constant address space.
 BUILTIN(__builtin_amdgcn_div_scale, "dddbb*", "n")
@@ -108,6 +111,7 @@
 
//===--===//
 TARGET_BUILTIN(__builtin_amdgcn_s_dcache_inv_vol, "v", "n", "ci-insts")
 TARGET_BUILTIN(__builtin_amdgcn_buffer_wbinvl1_vol, "v", "n", "ci-insts")
+TARGET_BUILTIN(__builtin_amdgcn_ds_gws_sema_release_all, "vUi", "n", 
"ci-insts")
 
 
//===--===//
 // Interpolation builtins.


Index: test/SemaOpenCL/builtins-amdgcn-error-ci.cl
===
--- test/SemaOpenCL/builtins-amdgcn-error-ci.cl
+++ test/SemaOpenCL/builtins-amdgcn-error-ci.cl
@@ -1,8 +1,9 @@
 // REQUIRES: amdgpu-registered-target
 // RUN: %clang_cc1 -triple amdgcn-- -target-cpu tahiti -verify -S -o - %s
 
-void test_ci_biltins()
+void test_ci_builtins()
 {
   __builtin_amdgcn_s_dcache_inv_vol(); // expected-error {{'__builtin_amdgcn_s_dcache_inv_vol' needs target feature ci-insts}}
   __builtin_amdgcn_buffer_wbinvl1_vol(); // expected-error {{'__builtin_amdgcn_buffer_wbinvl1_vol' needs target feature ci-insts}}
+  __builtin_amdgcn_ds_gws_sema_release_all(0); // expected-error {{'__builtin_amdgcn_ds_gws_sema_release_all' needs target feature ci-insts}}
 }
Index: test/CodeGenOpenCL/builtins-amdgcn.cl
===
--- test/CodeGenOpenCL/builtins-amdgcn.cl
+++ test/CodeGenOpenCL/builtins-amdgcn.cl
@@ -560,6 +560,24 @@
   __builtin_amdgcn_ds_gws_barrier(value, id);
 }
 
+// CHECK-LABEL: @test_gws_sema_v(

[PATCH] D63423: [Diagnostics] Diagnose misused xor as pow

2019-06-19 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 updated this revision to Diff 205692.
xbolva00 added a comment.

Improved code, added const.


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

https://reviews.llvm.org/D63423

Files:
  include/clang/Basic/DiagnosticGroups.td
  include/clang/Basic/DiagnosticSemaKinds.td
  lib/Sema/SemaExpr.cpp
  test/SemaCXX/warn-xor-as-pow.cpp

Index: test/SemaCXX/warn-xor-as-pow.cpp
===
--- test/SemaCXX/warn-xor-as-pow.cpp
+++ test/SemaCXX/warn-xor-as-pow.cpp
@@ -0,0 +1,98 @@
+// RUN: %clang_cc1 -x c -fsyntax-only -verify -Wxor-used-as-pow %s
+// RUN: %clang_cc1 -x c -fsyntax-only -verify %s
+// RUN: %clang_cc1 -x c -fsyntax-only -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
+
+// RUN: %clang_cc1 -x c++ -DKW_XOR -fsyntax-only -verify -Wxor-used-as-pow %s
+// RUN: %clang_cc1 -x c++ -DKW_XOR -fsyntax-only -verify %s
+// RUN: %clang_cc1 -x c++ -DKW_XOR -fsyntax-only -fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
+
+#define FOOBAR(x, y) (x * y)
+#define XOR(x, y) (x ^ y)
+#define TWO 2
+#define TEN 10
+#define TWO_ULL 2ULL
+#define EPSILON 10 ^ -300
+
+void test(unsigned a, unsigned b) {
+  unsigned res;
+  res = a ^ 5;
+  res = 2 ^ b;
+  res = a ^ b;
+  res = 2 ^ -1;
+  res = 2 ^ 0; // expected-warning {{result of '2 ^ 0' is 2; did you mean '1<<0' (1)?}}
+   // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:9-[[@LINE-1]]:14}:"1"
+   // expected-note@-2 {{replace expression with '0x2 ^ 0' to silence this warning}}
+  res = 2 ^ 1; // expected-warning {{result of '2 ^ 1' is 3; did you mean '1<<1' (2)?}}
+   // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:9-[[@LINE-1]]:14}:"1<<1"
+   // expected-note@-2 {{replace expression with '0x2 ^ 1' to silence this warning}}
+  res = 2 ^ 2; // expected-warning {{result of '2 ^ 2' is 0; did you mean '1<<2' (4)?}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:9-[[@LINE-1]]:14}:"1<<2"
+  // expected-note@-2 {{replace expression with '0x2 ^ 2' to silence this warning}}
+  res = 2 ^ 8; // expected-warning {{result of '2 ^ 8' is 10; did you mean '1<<8' (256)?}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:9-[[@LINE-1]]:14}:"1<<8"
+  // expected-note@-2 {{replace expression with '0x2 ^ 8' to silence this warning}}
+  res = TWO ^ 8; // expected-warning {{result of 'TWO ^ 8' is 10; did you mean '1<<8' (256)?}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:9-[[@LINE-1]]:16}:"1<<8"
+  // expected-note@-2 {{replace expression with '0x2 ^ 8' to silence this warning}}
+  res = 2 ^ 16; // expected-warning {{result of '2 ^ 16' is 18; did you mean '1<<16' (65536)?}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:9-[[@LINE-1]]:15}:"1<<16"
+  // expected-note@-2 {{replace expression with '0x2 ^ 16' to silence this warning}}
+  res = 2 ^ TEN; // expected-warning {{result of '2 ^ TEN' is 8; did you mean '1<= width of type}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:9-[[@LINE-1]]:15}:"1LL<<32"
+  // expected-note@-2 {{replace expression with '0x2 ^ 32' to silence this warning}}
+  res = 2 ^ 64; // expected-warning {{result of '2 ^ 64' is 66; did you mean '1<<64', but shift count >= width of type}}
+// expected-note@-1 {{replace expression with '0x2 ^ 64' to silence this warning}}
+
+  res = EPSILON;
+  res = 10 ^ 0; // expected-warning {{result of '10 ^ 0' is 10; did you mean '1e0'?}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:9-[[@LINE-1]]:15}:"1e0"
+  // expected-note@-2 {{replace expression with '0xA ^ 0' to silence this warning}}
+  res = 10 ^ 1; // expected-warning {{result of '10 ^ 1' is 11; did you mean '1e1'?}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:9-[[@LINE-1]]:15}:"1e1"
+  // expected-note@-2 {{replace expression with '0xA ^ 1' to silence this warning}}
+  res = 10 ^ 2; // expected-warning {{result of '10 ^ 2' is 8; did you mean '1e2'?}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:9-[[@LINE-1]]:15}:"1e2"
+  // expected-note@-2 {{replace expression with '0xA ^ 2' to silence this warning}}
+  res = 10 ^ 4; // expected-warning {{result of '10 ^ 4' is 14; did you mean '1e4'?}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:9-[[@LINE-1]]:15}:"1e4"
+  // expected-note@-2 {{replace expression with '0xA ^ 4' to silence this warning}}
+  res = 10 ^ 10; // expected-warning {{result of '10 ^ 10' is 0; did you mean '1e10'?}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:9-[[@LINE-1]]:16}:"1e10"
+  // expected-note@-2 {{replace expression with '0xA ^ 10' to silence this warning}}
+  res = TEN ^ 10; // expected-warning {{result of 'TEN ^ 10' is 0; did you mean '1e10'?}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:9-[[@LINE-1]]:17}:"1e10"
+  // expected-note@-2 {{replace expression with '0xA ^ 10' to silence this warning}}
+  res = 10 ^ 100; // expected-warning {{result of '10 ^ 100' is 110; did you mean '1e100'?}}
+  // CHECK: fix-it:"{{.*}}":{[[@LINE-1]]:9-[[@LINE-1]]:17}:"1e100"
+  // expected-note@-2 {{replace expression with '0xA ^ 100' to silence this warning}}
+  res = 0xA ^ 10;
+#if 

[PATCH] D63577: [clang][NewPM] Move EntryExitInstrumenterPass to the start of the pipeline

2019-06-19 Thread Leonard Chan via Phabricator via cfe-commits
leonardchan created this revision.
leonardchan added reviewers: chandlerc, phosek, echristo, serge-sans-paille.
leonardchan added a project: clang.

This fixes `CodeGen/x86_64-instrument-functions.c` when running under the new 
pass manager. The pass should go before any other pass to prevent 
`__cyg_profile_func_enter/exit()` from not being emitted by inlined functions.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D63577

Files:
  clang/lib/CodeGen/BackendUtil.cpp
  clang/test/CodeGen/x86_64-instrument-functions.c


Index: clang/test/CodeGen/x86_64-instrument-functions.c
===
--- clang/test/CodeGen/x86_64-instrument-functions.c
+++ clang/test/CodeGen/x86_64-instrument-functions.c
@@ -1,6 +1,9 @@
 // REQUIRES: x86-registered-target
-// RUN: %clang_cc1 -triple x86_64-unknown-unknown -S -finstrument-functions 
-O2 -o - %s | FileCheck %s
-// RUN: %clang_cc1 -triple x86_64-unknown-unknown -S 
-finstrument-functions-after-inlining -O2 -o - %s | FileCheck 
-check-prefix=NOINLINE %s
+// RUN: %clang_cc1 -fno-experimental-new-pass-manager -triple 
x86_64-unknown-unknown -S -finstrument-functions -O2 -o - %s | FileCheck %s
+// RUN: %clang_cc1 -fno-experimental-new-pass-manager -triple 
x86_64-unknown-unknown -S -finstrument-functions-after-inlining -O2 -o - %s | 
FileCheck -check-prefix=NOINLINE %s
+
+// RUN: %clang_cc1 -fexperimental-new-pass-manager -triple 
x86_64-unknown-unknown -S -finstrument-functions -O2 -o - %s | FileCheck %s
+// RUN: %clang_cc1 -fexperimental-new-pass-manager -triple 
x86_64-unknown-unknown -S -finstrument-functions-after-inlining -O2 -o - %s | 
FileCheck -check-prefix=NOINLINE %s
 
 // It's not so nice having asm tests in Clang, but we need to check that we set
 // up the pipeline correctly in order to have the instrumentation inserted.
Index: clang/lib/CodeGen/BackendUtil.cpp
===
--- clang/lib/CodeGen/BackendUtil.cpp
+++ clang/lib/CodeGen/BackendUtil.cpp
@@ -67,6 +67,7 @@
 #include "llvm/Transforms/Scalar/GVN.h"
 #include "llvm/Transforms/Utils.h"
 #include "llvm/Transforms/Utils/CanonicalizeAliases.h"
+#include "llvm/Transforms/Utils/EntryExitInstrumenter.h"
 #include "llvm/Transforms/Utils/NameAnonGlobals.h"
 #include "llvm/Transforms/Utils/SymbolRewriter.h"
 #include 
@@ -1131,6 +1132,11 @@
   // configure the pipeline.
   PassBuilder::OptimizationLevel Level = mapToLevel(CodeGenOpts);
 
+  PB.registerPipelineStartEPCallback([](ModulePassManager ) {
+MPM.addPass(createModuleToFunctionPassAdaptor(
+EntryExitInstrumenterPass(/*PostInlining=*/false)));
+  });
+
   // Register callbacks to schedule sanitizer passes at the appropriate 
part of
   // the pipeline.
   // FIXME: either handle asan/the remaining sanitizers or error out


Index: clang/test/CodeGen/x86_64-instrument-functions.c
===
--- clang/test/CodeGen/x86_64-instrument-functions.c
+++ clang/test/CodeGen/x86_64-instrument-functions.c
@@ -1,6 +1,9 @@
 // REQUIRES: x86-registered-target
-// RUN: %clang_cc1 -triple x86_64-unknown-unknown -S -finstrument-functions -O2 -o - %s | FileCheck %s
-// RUN: %clang_cc1 -triple x86_64-unknown-unknown -S -finstrument-functions-after-inlining -O2 -o - %s | FileCheck -check-prefix=NOINLINE %s
+// RUN: %clang_cc1 -fno-experimental-new-pass-manager -triple x86_64-unknown-unknown -S -finstrument-functions -O2 -o - %s | FileCheck %s
+// RUN: %clang_cc1 -fno-experimental-new-pass-manager -triple x86_64-unknown-unknown -S -finstrument-functions-after-inlining -O2 -o - %s | FileCheck -check-prefix=NOINLINE %s
+
+// RUN: %clang_cc1 -fexperimental-new-pass-manager -triple x86_64-unknown-unknown -S -finstrument-functions -O2 -o - %s | FileCheck %s
+// RUN: %clang_cc1 -fexperimental-new-pass-manager -triple x86_64-unknown-unknown -S -finstrument-functions-after-inlining -O2 -o - %s | FileCheck -check-prefix=NOINLINE %s
 
 // It's not so nice having asm tests in Clang, but we need to check that we set
 // up the pipeline correctly in order to have the instrumentation inserted.
Index: clang/lib/CodeGen/BackendUtil.cpp
===
--- clang/lib/CodeGen/BackendUtil.cpp
+++ clang/lib/CodeGen/BackendUtil.cpp
@@ -67,6 +67,7 @@
 #include "llvm/Transforms/Scalar/GVN.h"
 #include "llvm/Transforms/Utils.h"
 #include "llvm/Transforms/Utils/CanonicalizeAliases.h"
+#include "llvm/Transforms/Utils/EntryExitInstrumenter.h"
 #include "llvm/Transforms/Utils/NameAnonGlobals.h"
 #include "llvm/Transforms/Utils/SymbolRewriter.h"
 #include 
@@ -1131,6 +1132,11 @@
   // configure the pipeline.
   PassBuilder::OptimizationLevel Level = mapToLevel(CodeGenOpts);
 
+  PB.registerPipelineStartEPCallback([](ModulePassManager ) {
+MPM.addPass(createModuleToFunctionPassAdaptor(
+

[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] D63082: [Diagnostics] Added support for -Wint-in-bool-context

2019-06-19 Thread Arnaud Bienner via Phabricator via cfe-commits
ArnaudBienner added inline comments.



Comment at: lib/Sema/SemaChecking.cpp:11103
+
+  if (auto *BO = dyn_cast(E)) {
+BinaryOperator::Opcode Opc = BO->getOpcode();

Shouldn't that be "const auto*" instead?
I'm surprised dyn_cast casts away const qualifier, but FWIW having the returned 
pointer being const makes clearer the variable pointed by this pointer won't be 
modified.
But maybe this was intended to not make the code too verbose?


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

https://reviews.llvm.org/D63082



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


[PATCH] D63575: [WebAssembly] Add builtin functions for creating vector constants

2019-06-19 Thread Thomas Lively via Phabricator via cfe-commits
tlively created this revision.
tlively added reviewers: dschuff, aheejin.
Herald added subscribers: cfe-commits, sunfish, jgravelle-google, sbc100.
Herald added a project: clang.

These builtins do not offer any functionality over the normal
aggregate initialization for vector types, except that they enforce
that their arguments constant fold to integer expressions so they
always generate a vector constant. They are meant for use in the new
WebAssembly SIMD intrinsic header.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D63575

Files:
  clang/include/clang/Basic/BuiltinsWebAssembly.def
  clang/lib/CodeGen/CGBuiltin.cpp
  clang/test/CodeGen/builtins-wasm.c


Index: clang/test/CodeGen/builtins-wasm.c
===
--- clang/test/CodeGen/builtins-wasm.c
+++ clang/test/CodeGen/builtins-wasm.c
@@ -140,10 +140,29 @@
   // WEBASSEMBLY-NEXT: ret
 }
 
+i8x16 const_i8x16() {
+  // MISSING-SIMD: error: '__builtin_wasm_const_i8x16' needs target feature 
simd128
+  // WEBASSEMBLY: ret <16 x i8> 
+  return __builtin_wasm_const_i8x16(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 
13, 14, 15);
+}
+
+i16x8 const_i16x8() {
+  // WEBASSEMBLY: ret <8 x i16> 
+  return __builtin_wasm_const_i16x8(0, 1, 2, 3, 4, 5, 6, 7);
+}
+
+i32x4 const_i32x4() {
+  // WEBASSEMBLY: ret <4 x i32> 
+  return __builtin_wasm_const_i32x4(0, 1, 2, 3);
+}
+
+i64x2 const_i64x2() {
+  // WEBASSEMBLY: ret <2 x i64> 
+  return __builtin_wasm_const_i64x2(0, 1);
+}
 
 int extract_lane_s_i8x16(i8x16 v) {
   return __builtin_wasm_extract_lane_s_i8x16(v, 13);
-  // MISSING-SIMD: error: '__builtin_wasm_extract_lane_s_i8x16' needs target 
feature simd128
   // WEBASSEMBLY: extractelement <16 x i8> %v, i32 13
   // WEBASSEMBLY-NEXT: sext
   // WEBASSEMBLY-NEXT: ret
Index: clang/lib/CodeGen/CGBuiltin.cpp
===
--- clang/lib/CodeGen/CGBuiltin.cpp
+++ clang/lib/CodeGen/CGBuiltin.cpp
@@ -13971,6 +13971,19 @@
  ConvertType(E->getType()));
 return Builder.CreateCall(Callee, {LHS, RHS});
   }
+  case WebAssembly::BI__builtin_wasm_const_i8x16:
+  case WebAssembly::BI__builtin_wasm_const_i16x8:
+  case WebAssembly::BI__builtin_wasm_const_i32x4:
+  case WebAssembly::BI__builtin_wasm_const_i64x2: {
+SmallVector Args;
+for (size_t i = 0; i < E->getNumArgs(); ++i) {
+  llvm::APSInt Const;
+  if (!E->getArg(i)->isIntegerConstantExpr(Const, getContext()))
+llvm_unreachable("Constant arg isn't actually constant?");
+  Args.push_back(llvm::ConstantInt::get(getLLVMContext(), Const));
+}
+return Builder.Insert(llvm::ConstantVector::get(Args));
+  }
   case WebAssembly::BI__builtin_wasm_extract_lane_s_i8x16:
   case WebAssembly::BI__builtin_wasm_extract_lane_u_i8x16:
   case WebAssembly::BI__builtin_wasm_extract_lane_s_i16x8:
Index: clang/include/clang/Basic/BuiltinsWebAssembly.def
===
--- clang/include/clang/Basic/BuiltinsWebAssembly.def
+++ clang/include/clang/Basic/BuiltinsWebAssembly.def
@@ -55,6 +55,11 @@
 TARGET_BUILTIN(__builtin_wasm_trunc_saturate_u_i64_f64, "LLid", "nc", 
"nontrapping-fptoint")
 
 // SIMD builtins
+TARGET_BUILTIN(__builtin_wasm_const_i8x16, 
"V16cIcIcIcIcIcIcIcIcIcIcIcIcIcIcIcIc", "nc", "simd128")
+TARGET_BUILTIN(__builtin_wasm_const_i16x8, "V8sIsIsIsIsIsIsIsIs", "nc", 
"simd128")
+TARGET_BUILTIN(__builtin_wasm_const_i32x4, "V4iIiIiIiIi", "nc", "simd128")
+TARGET_BUILTIN(__builtin_wasm_const_i64x2, "V2LLiILLiILLi", "nc", 
"unimplemented-simd128")
+
 TARGET_BUILTIN(__builtin_wasm_extract_lane_s_i8x16, "iV16cIi", "nc", "simd128")
 TARGET_BUILTIN(__builtin_wasm_extract_lane_u_i8x16, "iV16cIi", "nc", 
"unimplemented-simd128")
 TARGET_BUILTIN(__builtin_wasm_extract_lane_s_i16x8, "iV8sIi", "nc", "simd128")


Index: clang/test/CodeGen/builtins-wasm.c
===
--- clang/test/CodeGen/builtins-wasm.c
+++ clang/test/CodeGen/builtins-wasm.c
@@ -140,10 +140,29 @@
   // WEBASSEMBLY-NEXT: ret
 }
 
+i8x16 const_i8x16() {
+  // MISSING-SIMD: error: '__builtin_wasm_const_i8x16' needs target feature simd128
+  // WEBASSEMBLY: ret <16 x i8> 
+  return __builtin_wasm_const_i8x16(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
+}
+
+i16x8 const_i16x8() {
+  // WEBASSEMBLY: ret <8 x i16> 
+  return __builtin_wasm_const_i16x8(0, 1, 2, 3, 4, 5, 6, 7);
+}
+
+i32x4 const_i32x4() {
+  // WEBASSEMBLY: ret <4 x i32> 
+  return __builtin_wasm_const_i32x4(0, 1, 2, 3);
+}
+
+i64x2 const_i64x2() {
+  // WEBASSEMBLY: ret <2 x i64> 
+  return __builtin_wasm_const_i64x2(0, 1);
+}
 
 int extract_lane_s_i8x16(i8x16 v) {
   return __builtin_wasm_extract_lane_s_i8x16(v, 13);
-  // MISSING-SIMD: error: '__builtin_wasm_extract_lane_s_i8x16' needs target feature simd128
   // WEBASSEMBLY: extractelement <16 x i8> %v, i32 13
   // WEBASSEMBLY-NEXT: sext
   // 

[PATCH] D63533: [analyzer] Fix clang-tidy crash on GCCAsmStmt

2019-06-19 Thread Nathan Huckleberry via Phabricator via cfe-commits
Nathan-Huckleberry marked an inline comment as done.
Nathan-Huckleberry added inline comments.



Comment at: clang/test/Analysis/egraph-asm-goto-no-crash.cpp:1
+// RUN: %clang_analyze_cc1 -analyzer-checker=core -analyzer-dump-egraph=%t.dot 
%s
+// RUN: cat %t.dot | FileCheck %s

nickdesaulniers wrote:
> NoQ wrote:
> > NoQ wrote:
> > > NoQ wrote:
> > > > Ugh, you picked an exotic test as an example.
> > > > 
> > > > Let's try the following:
> > > > ```lang=c++
> > > > // RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection 
> > > > -verify %s
> > > > 
> > > > // expected-no-diagnostics
> > > > 
> > > > void clang_analyzer_warnIfReached();
> > > > 
> > > > void testAsmGoto() {
> > > >   asm goto("xor %0, %0\n je %l[label1]\n jl %l[label2]"
> > > >: /* no outputs */
> > > >: /* inputs */
> > > >: /* clobbers */
> > > >: label1, label2 /* any labels used */);
> > > > 
> > > >   label1:
> > > >   // FIXME: Should be reachable.
> > > >   clang_analyzer_warnIfReached();
> > > >   return;
> > > > 
> > > >   label2:
> > > >   // FIXME: Should be reachable.
> > > >   clang_analyzer_warnIfReached();
> > > >   return;
> > > > }
> > > > ```
> > > > 
> > > >  (and the egraph part in the main file is also out of place)
> > > (wait, one of these shouldn't be reachable, right?)
> > (i mean, let's do something similar, just with the correct amount of FIXMEs)
> You'd have to "peak" into the assembly to tell.  Essentially `asm goto` is 
> treated as a "black box" throughout Clang and LLVM, similar to vanilla inline 
> assembly.  Basically, the explicit list of labels are valid branch targets 
> from the inline assembly, as is fallthrough.  It's undefined behavior if the 
> assembly jumps to a label not explicitly listed in the asm statement (but 
> would likely fail to link, in the best case).
To answer the original question both labels and the 'fallthrough' case should 
all be technically reachable in this test case, but will not actually be 
reached during analysis since handling for `asm goto` branching doesn't exist.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63533



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


[PATCH] D63518: WIP BitStream reader: propagate errors

2019-06-19 Thread JF Bastien via Phabricator via cfe-commits
jfb added a comment.

In D63518#1550827 , @bruno wrote:

> Hi JF. Thanks for working on this, nice improvement to error handling!
>
> The overall approach is pretty solid and should prevent a lot of red herring 
> while investigating hard to reproduce crashes in clang, specially when 
> implicit clang modules is involved. Dropping the errors on the floor for 
> previous code that didn't handle errors at all is a fair tradeoff for 
> introducing the functionality.


Thanks!

> I have omitted any format comments but I noticed several of 80 cols 
> violations. More specific reviews inline.

Yeah I've been avoiding `clang-format` because it's sometimes easier to manage 
merge conflicts without reformatting. I'll absolutely run format when the patch 
is further along.




Comment at: clang/lib/Frontend/SerializedDiagnosticReader.cpp:59
+} else
+return SDError::InvalidDiagnostics; // FIXME propagate the error 
details.
 

bruno wrote:
> Can this be simplified as below?
> 
> ```
> Expected Res = Stream.ReadCode();
> if (!Res || Res.get() != llvm::bitc::ENTER_SUBBLOCK)
>   return SDError::InvalidDiagnostics; // FIXME propagate the error details.
> ```
Yeah, but I think we'll want to propagate errors in a follow-up so we'll end up 
re-separating them. I'd rather have the right structure here.



Comment at: clang/lib/Serialization/ASTReader.cpp:1158
   StringRef Blob;
-  unsigned Code = Cursor.ReadCode();
-  unsigned RecCode = Cursor.readRecord(Code, Record, );
+  Expected MaybeCode = Cursor.ReadCode();
+  if (!MaybeCode) {

bruno wrote:
> Not necessarily needed as part of this patch, but I wonder how many of 
> repetitive access patterns (readCode + readRecord, and maybe other patterns) 
> we have that would take advantage of refactoring all these checks out into 
> their own methods.
Yeah I noticed that too, probably worth adding a helper for. I'll note it in a 
bug: https://bugs.llvm.org/show_bug.cgi?id=42335



Comment at: clang/lib/Serialization/ASTReader.cpp:4283
+return llvm::createStringError(std::errc::illegal_byte_sequence, "file too 
small to contain AST file magic");
+  for (unsigned C : {'C','P','C','H'})
+if (Expected Res = Stream.Read(8)) {

bruno wrote:
> Very similar to SerializedDiagnosticReader.cpp:44, does it deserve a common 
> helper?
It would be nice, but they don't have the same error handling :(
I'll add a FIXME.



Comment at: clang/lib/Serialization/ASTReader.cpp:4559
+  // FIXME this drops the error.
+  return Failure;
+}

bruno wrote:
> This is a good example of a real issue this patch solves. Sometimes we get 
> signature mismatch problems in implicit modules builds because we read 
> garbage. Having this check and failure here prevents the misleading error 
> message.




Comment at: clang/lib/Serialization/ASTReaderDecl.cpp:3695
+  if (!MaybeDeclCode)
+llvm::report_fatal_error("ASTReader::ReadDeclRecord failed readung decl 
code: " + toString(MaybeDeclCode.takeError()));
+  switch ((DeclCode)MaybeDeclCode.get()) {

bruno wrote:
> typo on `readung`
lol dung



Comment at: clang/lib/Serialization/ASTReaderDecl.cpp:4036
+  if (llvm::Error JumpFailed = Cursor.JumpToBit(Offset))
+// FIXME don't do a fatal error.
+llvm::report_fatal_error("ASTReader::loadDeclUpdateRecords failed 
jumping: " + toString(std::move(JumpFailed)));

bruno wrote:
> Why? What's a better alternative?
Anything that can be used as a clang API needs to return errors instead of 
using `report_fatal_error`, so that the API can't just `abort` your process. We 
should propagate this error, but it's getting tedious here and I think better 
in a follow-up.



Comment at: clang/lib/Serialization/ASTReaderDecl.cpp:4119
+  if (Expected MaybeRecCode = Cursor.readRecord(Code, Record))
+assert(MaybeRecCode.get() == LOCAL_REDECLARATIONS && "expected 
LOCAL_REDECLARATIONS record!");
+  else

bruno wrote:
> Does this builds fine without assertions?
It should, why? The variable is used on both sides of the `if`.



Comment at: clang/lib/Serialization/GlobalModuleIndex.cpp:266
   // Sniff for the signature.
-  if (Cursor.Read(8) != 'B' ||
-  Cursor.Read(8) != 'C' ||
-  Cursor.Read(8) != 'G' ||
-  Cursor.Read(8) != 'I') {
-return std::make_pair(nullptr, EC_IOError);
+  for (unsigned char C : {'B', 'C', 'G', 'I'}) {
+if (Expected Res = Cursor.Read(8)) {

bruno wrote:
> Very similar to SerializedDiagnosticReader.cpp:44, does it deserve a common 
> helper?
Left a FIXME in ASTReader.cpp for this.



Comment at: llvm/include/llvm/Bitcode/BitstreamReader.h:230
+uint32_t Piece;
+if (Expected Res = Read(NumBits))
+  Piece = Res.get();

[PATCH] D63325: [Support][Time profiler] Make FE codegen blocks to be inside frontend blocks

2019-06-19 Thread Anton Afanasyev via Phabricator via cfe-commits
anton-afanasyev updated this revision to Diff 205673.
anton-afanasyev added a comment.

Updated, changed test


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63325

Files:
  clang/lib/CodeGen/CodeGenAction.cpp
  clang/lib/Parse/ParseAST.cpp
  clang/test/Driver/check-time-trace-sections.cpp
  clang/test/Driver/check-time-trace-sections.py
  llvm/lib/Support/TimeProfiler.cpp

Index: llvm/lib/Support/TimeProfiler.cpp
===
--- llvm/lib/Support/TimeProfiler.cpp
+++ llvm/lib/Support/TimeProfiler.cpp
@@ -65,7 +65,7 @@
 E.Duration = steady_clock::now() - E.Start;
 
 // Only include sections longer than TimeTraceGranularity msec.
-if (duration_cast(E.Duration).count() > TimeTraceGranularity)
+if (duration_cast(E.Duration).count() >= TimeTraceGranularity)
   Entries.emplace_back(E);
 
 // Track total time taken by each "name", but only the topmost levels of
Index: clang/test/Driver/check-time-trace-sections.py
===
--- /dev/null
+++ clang/test/Driver/check-time-trace-sections.py
@@ -0,0 +1,32 @@
+#!/usr/bin/env python
+
+import json, sys
+
+def is_inside(range1, range2):
+a = range1["ts"]; b = a + range1["dur"]
+c = range2["ts"]; d = c + range2["dur"]
+return (a >= c and a <= d) and (b >= c and b <= d)
+
+def is_before(range1, range2):
+b = range1["ts"] + range1["dur"]; c = range2["ts"]
+return b <= c
+
+events = json.loads(sys.stdin.read())["traceEvents"]
+codegens = filter(lambda x: x["name"] == "CodeGen Function", events)
+frontends = filter(lambda x: x["name"] == "Frontend", events)
+backends = filter(lambda x: x["name"] == "Backend", events)
+
+if not len(frontends) == 1:
+sys.exit("There should be exactly one Frontend section!")
+
+if not len(backends) == 1:
+sys.exit("There should be exactly one Backend section!")
+
+frontend = frontends[0]
+backend = backends[0]
+
+if not all([is_inside(codegen, frontend) for codegen in codegens]):
+sys.exit("Not all CodeGen sections are inside Frontend section!")
+
+if not is_before(frontend, backend):
+sys.exit("Frontend section are not before Backend section!")
Index: clang/test/Driver/check-time-trace-sections.cpp
===
--- /dev/null
+++ clang/test/Driver/check-time-trace-sections.cpp
@@ -0,0 +1,7 @@
+// REQUIRES: shell
+// RUN: %clangxx -S -ftime-trace -mllvm --time-trace-granularity=0 -o %T/check-time-trace-sections %s
+// RUN: cat %T/check-time-trace-sections.json | %python %S/check-time-trace-sections.py
+
+template 
+void foo(T) {}
+void bar() { foo(0); }
Index: clang/lib/Parse/ParseAST.cpp
===
--- clang/lib/Parse/ParseAST.cpp
+++ clang/lib/Parse/ParseAST.cpp
@@ -150,8 +150,12 @@
   // after the pragma, there won't be any tokens or a Lexer.
   bool HaveLexer = S.getPreprocessor().getCurrentLexer();
 
+  // Start "Frontend" section finishing inside clang::HandleTranslationUnit()
+  if (llvm::timeTraceProfilerEnabled())
+llvm::timeTraceProfilerBegin("Frontend", StringRef(""));
+
   if (HaveLexer) {
-llvm::TimeTraceScope TimeScope("Frontend", StringRef(""));
+llvm::TimeTraceScope TimeScope("Lexing", StringRef(""));
 P.Initialize();
 Parser::DeclGroupPtrTy ADecl;
 for (bool AtEOF = P.ParseFirstTopLevelDecl(ADecl); !AtEOF;
@@ -159,8 +163,11 @@
   // If we got a null return and something *was* parsed, ignore it.  This
   // is due to a top-level semicolon, an action override, or a parse error
   // skipping something.
-  if (ADecl && !Consumer->HandleTopLevelDecl(ADecl.get()))
+  if (ADecl && !Consumer->HandleTopLevelDecl(ADecl.get())) {
+if (llvm::timeTraceProfilerEnabled())
+  llvm::timeTraceProfilerEnd();
 return;
+  }
 }
   }
 
Index: clang/lib/CodeGen/CodeGenAction.cpp
===
--- clang/lib/CodeGen/CodeGenAction.cpp
+++ clang/lib/CodeGen/CodeGenAction.cpp
@@ -37,6 +37,7 @@
 #include "llvm/Pass.h"
 #include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/SourceMgr.h"
+#include "llvm/Support/TimeProfiler.h"
 #include "llvm/Support/Timer.h"
 #include "llvm/Support/ToolOutputFile.h"
 #include "llvm/Support/YAMLTraits.h"
@@ -246,6 +247,12 @@
 IRGenFinished = true;
   }
 
+  // Finish "Frontend" section starting inside clang::ParseAST()
+  // We don't want "Backend" section to turn out within "Frontend" section,
+  // so finishing it here before EmitBackendOutput() and possible return's.
+  if (llvm::timeTraceProfilerEnabled())
+llvm::timeTraceProfilerEnd();
+
   // Silently ignore if we weren't initialized for some reason.
   if (!getModule())
 return;

[PATCH] D63108: [OpenMP] Add support for handling declare target to clause when unified memory is required

2019-06-19 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
gtbercea added a comment.

Still need to update the test but the rest of the code is updated.


Repository:
  rC Clang

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

https://reviews.llvm.org/D63108



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


[PATCH] D63108: [OpenMP] Add support for handling declare target to clause when unified memory is required

2019-06-19 Thread Gheorghe-Teodor Bercea via Phabricator via cfe-commits
gtbercea updated this revision to Diff 205667.
gtbercea marked an inline comment as done.
gtbercea added a comment.

- Merge MT_Link and MT_To with unified memory cases.
- Transform switch into if statements.
- Fix declare target attribute checks.


Repository:
  rC Clang

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

https://reviews.llvm.org/D63108

Files:
  lib/CodeGen/CGDeclCXX.cpp
  lib/CodeGen/CGExpr.cpp
  lib/CodeGen/CGOpenMPRuntime.cpp
  lib/CodeGen/CGOpenMPRuntime.h
  lib/CodeGen/CodeGenModule.cpp
  test/OpenMP/nvptx_target_requires_unified_shared_memory.cpp

Index: test/OpenMP/nvptx_target_requires_unified_shared_memory.cpp
===
--- test/OpenMP/nvptx_target_requires_unified_shared_memory.cpp
+++ test/OpenMP/nvptx_target_requires_unified_shared_memory.cpp
@@ -8,16 +8,18 @@
 #define N 1000
 
 double var = 10.0;
+double to_var = 20.0;
 
 #pragma omp requires unified_shared_memory
 #pragma omp declare target link(var)
+#pragma omp declare target to(to_var)
 
 int bar(int n){
   double sum = 0;
 
 #pragma omp target
   for(int i = 0; i < n; i++) {
-sum += var;
+sum += var + to_var;
   }
 
   return sum;
@@ -26,9 +28,20 @@
 // CHECK: [[VAR:@.+]] = global double 1.00e+01
 // CHECK: [[VAR_DECL_TGT_LINK_PTR:@.+]] = global double* [[VAR]]
 
+// CHECK: [[TO_VAR:@.+]] = global double 2.00e+01
+// CHECK: [[VAR_DECL_TGT_TO_PTR:@.+]] = global double* [[TO_VAR]]
+
 // CHECK: [[OFFLOAD_SIZES:@.+]] = private unnamed_addr constant [2 x i64] [i64 4, i64 8]
 // CHECK: [[OFFLOAD_MAPTYPES:@.+]] = private unnamed_addr constant [2 x i64] [i64 800, i64 800]
 
+// CHECK: [[OMP_OFFLOAD_ENTRY_LINK_VAR_PTR_NAME:@.+]] = internal unnamed_addr constant [22 x i8]
+// CHECK: [[OMP_OFFLOAD_ENTRY_LINK_VAR_PTR:@.+]] = weak constant %struct.__tgt_offload_entry { i8* bitcast (double** [[VAR_DECL_TGT_LINK_PTR]] to i8*), i8* getelementptr inbounds ([22 x i8], [22 x i8]* [[OMP_OFFLOAD_ENTRY_LINK_VAR_PTR_NAME]], i32 0, i32 0), i64 8, i32 1, i32 0 }, section ".omp_offloading.entries"
+
+// CHECK: [[OMP_OFFLOAD_ENTRY_TO_VAR_PTR_NAME:@.+]] = internal unnamed_addr constant [23 x i8]
+// CHECK: [[OMP_OFFLOAD_ENTRY_TO_VAR_PTR:@.+]] = weak constant %struct.__tgt_offload_entry { i8* bitcast (double** [[VAR_DECL_TGT_TO_PTR]] to i8*), i8* getelementptr inbounds ([23 x i8], [23 x i8]* [[OMP_OFFLOAD_ENTRY_TO_VAR_PTR_NAME]], i32 0, i32 0), i64 8, i32 0, i32 0 }, section ".omp_offloading.entries"
+
+// CHECK: @llvm.used = appending global [2 x i8*] [i8* bitcast (double** [[VAR_DECL_TGT_LINK_PTR]] to i8*), i8* bitcast (double** [[VAR_DECL_TGT_TO_PTR]] to i8*)], section "llvm.metadata"
+
 // CHECK: [[N_CASTED:%.+]] = alloca i64
 // CHECK: [[SUM_CASTED:%.+]] = alloca i64
 
Index: lib/CodeGen/CodeGenModule.cpp
===
--- lib/CodeGen/CodeGenModule.cpp
+++ lib/CodeGen/CodeGenModule.cpp
@@ -2475,13 +2475,18 @@
 // Emit declaration of the must-be-emitted declare target variable.
 if (llvm::Optional Res =
 OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(VD)) {
-  if (*Res == OMPDeclareTargetDeclAttr::MT_To) {
+  bool UnifiedMemoryEnabled =
+  getOpenMPRuntime().hasRequiresUnifiedSharedMemory();
+  if (*Res == OMPDeclareTargetDeclAttr::MT_To &&
+  !UnifiedMemoryEnabled)
 (void)GetAddrOfGlobalVar(VD);
-  } else {
-assert(*Res == OMPDeclareTargetDeclAttr::MT_Link &&
-   "link claue expected.");
-(void)getOpenMPRuntime().getAddrOfDeclareTargetLink(VD);
-  }
+  else if (*Res == OMPDeclareTargetDeclAttr::MT_Link ||
+   (*Res == OMPDeclareTargetDeclAttr::MT_To &&
+UnifiedMemoryEnabled))
+(void)getOpenMPRuntime().getAddrOfDeclareTargetClause(VD);
+  else
+llvm_unreachable("Link or to clause expected!");
+
   return;
 }
   }
Index: lib/CodeGen/CGOpenMPRuntime.h
===
--- lib/CodeGen/CGOpenMPRuntime.h
+++ lib/CodeGen/CGOpenMPRuntime.h
@@ -1121,8 +1121,8 @@
  SourceLocation Loc);
 
   /// Returns the address of the variable marked as declare target with link
-  /// clause.
-  virtual Address getAddrOfDeclareTargetLink(const VarDecl *VD);
+  /// clause OR as declare target with to clause and unified memory.
+  virtual Address getAddrOfDeclareTargetClause(const VarDecl *VD);
 
   /// Emit a code for initialization of threadprivate variable. It emits
   /// a call to runtime library which adds initial value to the newly created
Index: lib/CodeGen/CGOpenMPRuntime.cpp
===
--- lib/CodeGen/CGOpenMPRuntime.cpp
+++ lib/CodeGen/CGOpenMPRuntime.cpp
@@ -2552,16 +2552,21 @@
   return CGM.CreateRuntimeFunction(FnTy, Name);

[PATCH] D63533: [analyzer] Fix clang-tidy crash on GCCAsmStmt

2019-06-19 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added inline comments.



Comment at: clang/lib/StaticAnalyzer/Core/CoreEngine.cpp:401
+  case Stmt::GCCAsmStmtClass:
+return;
 }

nickdesaulniers wrote:
> NoQ wrote:
> > Please add a TODO to actually implement this functionality.
> And an `assert` that this `Stmt::isAsmGoto() == true`. (We should not hit 
> this for any inline assembly, just asm goto statements)
Take a look at other `assert`s in the codebase.  They usually are in the form: 
`assert(some_expr_should_be_true && "helpful error message when false");`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63533



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


[PATCH] D60455: [SYCL] Implement SYCL device code outlining

2019-06-19 Thread Alexey Bader via Phabricator via cfe-commits
bader added inline comments.



Comment at: clang/test/SemaSYCL/device-attributes.cpp:3
+
+[[clang::sycl_kernel]] int gv2 = 0; // expected-warning {{'sycl_kernel' 
attribute only applies to functions}}
+__attribute((sycl_kernel)) int gv3 = 0; // expected-warning {{'sycl_kernel' 
attribute only applies to functions}}

aaron.ballman wrote:
> Fznamznon wrote:
> > aaron.ballman wrote:
> > > I'd like to see some more tests covering less obvious scenarios. Can I 
> > > add this attribute to a lambda? What about a member function? How does it 
> > > work with virtual functions? That sort of thing.
> > Actually there is no restrictions for adding this attribute to any function 
> > to outline device code so I just checked the simplest variant.
> > 
> > But I'm working on new patch which will put some requirements on function 
> > which is marked with `sycl_kernel` attribute. 
> > This new patch will add generation of OpenCL kernel from function marked 
> > with `sycl_kernel` attribute. The main idea of this approach is described 
> > in this [[ 
> > https://github.com/intel/llvm/blob/sycl/sycl/doc/SYCL_compiler_and_runtime_design.md#lowering-of-lambda-function-objects-and-named-function-objects
> >  | document ]] (in this document generated kernel is called "kernel 
> > wrapper").
> > And to be able to generate OpenCL kernel using function marked with 
> > `sycl_kernel` attribute we put some requirements on this function, for 
> > example it must be a template function. You can find these requirements and 
> > example of proper function which can be marked with `sycl_kernel` in this 
> > [[ https://github.com/intel/llvm/pull/177#discussion_r290451286 | comment 
> > ]] .
> > 
> > 
> > Actually there is no restrictions for adding this attribute to any function 
> > to outline device code so I just checked the simplest variant.
> 
> So there are no concerns about code like:
> ```
> struct Base {
>   __attribute__((sycl_kernel)) virtual void foo();
>   virtual void bar();
> };
> 
> struct Derived : Base {
>   void foo() override;
>   __attribute__((sycl_kernel)) void bar() override;
> };
> 
> void f(Base *B, Derived *D) {
>   // Will all of these "do the right thing"?
>   B->foo();
>   B->bar();
> 
>   D->foo();
>   D->bar();
> }
> ```
> Actually there is no restrictions for adding this attribute to any function 
> to outline device code so I just checked the simplest variant.
> But I'm working on new patch which will put some requirements on function 
> which is marked with sycl_kernel attribute.

@aaron.ballman, sorry for confusing. The  usage scenarios should have been 
articulated more accurately.
We have only four uses of this attribute in our implementation:
https://github.com/intel/llvm/blob/sycl/sycl/include/CL/sycl/handler.hpp#L538 
(lines 538-605).
All four uses are applied to member functions of `cl::sycl::handler` class and 
all of them have similar prototype (which is mentioned by Mariya in the 
previous 
[comment](https://github.com/intel/llvm/pull/177#discussion_r290451286):

```
namespace cl { namespace sycl {
class handler {
  template 
  __attribute__((sycl_kernel)) void sycl_kernel_function(KernelType 
KernelFuncObj) {
KernelFuncObj();
  }
};
}}
```

Here is the list of SYCL device compiler expectations with regard to the 
function marked with `sycl_kernel` attribute.
- Function template with at least one parameter is expected. The 
compiler generates OpenCL kernel and uses first template parameter as unique 
name to the generated OpenCL kernel. Host application uses this unique name to 
invoke the OpenCL kernel generated for the `sycl_kernel_function` specialized 
by this name and KernelType (which might be a lambda type).
- Function must have at least one parameter. First parameter expected 
to be a function object type (named or unnamed i.e. lambda). Compiler uses 
function object type field to generate OpenCL kernel parameters.

Aaron, I hope it makes more sense now.

We don't plan in any use cases other than in SYCL standard library 
implementation mentioned above.
If I understand you concerns correctly, you want to be sure that clang 
prohibits other uses of this attribute, which are not intended. Right?
What is the best way to do this? Add more negative tests cases and make sure 
that clang generate error diagnostic messages?



Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D60455



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


[PATCH] D63533: [analyzer] Fix clang-tidy crash on GCCAsmStmt

2019-06-19 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added inline comments.



Comment at: clang/test/Analysis/egraph-asm-goto-no-crash.cpp:1
+// RUN: %clang_analyze_cc1 -analyzer-checker=core -analyzer-dump-egraph=%t.dot 
%s
+// RUN: cat %t.dot | FileCheck %s

NoQ wrote:
> NoQ wrote:
> > NoQ wrote:
> > > Ugh, you picked an exotic test as an example.
> > > 
> > > Let's try the following:
> > > ```lang=c++
> > > // RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection 
> > > -verify %s
> > > 
> > > // expected-no-diagnostics
> > > 
> > > void clang_analyzer_warnIfReached();
> > > 
> > > void testAsmGoto() {
> > >   asm goto("xor %0, %0\n je %l[label1]\n jl %l[label2]"
> > >: /* no outputs */
> > >: /* inputs */
> > >: /* clobbers */
> > >: label1, label2 /* any labels used */);
> > > 
> > >   label1:
> > >   // FIXME: Should be reachable.
> > >   clang_analyzer_warnIfReached();
> > >   return;
> > > 
> > >   label2:
> > >   // FIXME: Should be reachable.
> > >   clang_analyzer_warnIfReached();
> > >   return;
> > > }
> > > ```
> > > 
> > >  (and the egraph part in the main file is also out of place)
> > (wait, one of these shouldn't be reachable, right?)
> (i mean, let's do something similar, just with the correct amount of FIXMEs)
You'd have to "peak" into the assembly to tell.  Essentially `asm goto` is 
treated as a "black box" throughout Clang and LLVM, similar to vanilla inline 
assembly.  Basically, the explicit list of labels are valid branch targets from 
the inline assembly, as is fallthrough.  It's undefined behavior if the 
assembly jumps to a label not explicitly listed in the asm statement (but would 
likely fail to link, in the best case).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63533



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


[PATCH] D63533: [analyzer] Fix clang-tidy crash on GCCAsmStmt

2019-06-19 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added inline comments.



Comment at: clang/test/Analysis/egraph-asm-goto-no-crash.cpp:1
+// RUN: %clang_analyze_cc1 -analyzer-checker=core -analyzer-dump-egraph=%t.dot 
%s
+// RUN: cat %t.dot | FileCheck %s

NoQ wrote:
> NoQ wrote:
> > Ugh, you picked an exotic test as an example.
> > 
> > Let's try the following:
> > ```lang=c++
> > // RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection 
> > -verify %s
> > 
> > // expected-no-diagnostics
> > 
> > void clang_analyzer_warnIfReached();
> > 
> > void testAsmGoto() {
> >   asm goto("xor %0, %0\n je %l[label1]\n jl %l[label2]"
> >: /* no outputs */
> >: /* inputs */
> >: /* clobbers */
> >: label1, label2 /* any labels used */);
> > 
> >   label1:
> >   // FIXME: Should be reachable.
> >   clang_analyzer_warnIfReached();
> >   return;
> > 
> >   label2:
> >   // FIXME: Should be reachable.
> >   clang_analyzer_warnIfReached();
> >   return;
> > }
> > ```
> > 
> >  (and the egraph part in the main file is also out of place)
> (wait, one of these shouldn't be reachable, right?)
(i mean, let's do something similar, just with the correct amount of FIXMEs)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63533



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


[PATCH] D63533: [analyzer] Fix clang-tidy crash on GCCAsmStmt

2019-06-19 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added inline comments.



Comment at: clang/test/Analysis/egraph-asm-goto-no-crash.cpp:1
+// RUN: %clang_analyze_cc1 -analyzer-checker=core -analyzer-dump-egraph=%t.dot 
%s
+// RUN: cat %t.dot | FileCheck %s

NoQ wrote:
> Ugh, you picked an exotic test as an example.
> 
> Let's try the following:
> ```lang=c++
> // RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection 
> -verify %s
> 
> // expected-no-diagnostics
> 
> void clang_analyzer_warnIfReached();
> 
> void testAsmGoto() {
>   asm goto("xor %0, %0\n je %l[label1]\n jl %l[label2]"
>: /* no outputs */
>: /* inputs */
>: /* clobbers */
>: label1, label2 /* any labels used */);
> 
>   label1:
>   // FIXME: Should be reachable.
>   clang_analyzer_warnIfReached();
>   return;
> 
>   label2:
>   // FIXME: Should be reachable.
>   clang_analyzer_warnIfReached();
>   return;
> }
> ```
> 
>  (and the egraph part in the main file is also out of place)
(wait, one of these shouldn't be reachable, right?)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63533



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


[PATCH] D63533: [analyzer] Fix clang-tidy crash on GCCAsmStmt

2019-06-19 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added inline comments.



Comment at: clang/test/Analysis/egraph-asm-goto-no-crash.cpp:1
+// RUN: %clang_analyze_cc1 -analyzer-checker=core -analyzer-dump-egraph=%t.dot 
%s
+// RUN: cat %t.dot | FileCheck %s

Ugh, you picked an exotic test as an example.

Let's try the following:
```lang=c++
// RUN: %clang_analyze_cc1 -analyzer-checker=core,debug.ExprInspection -verify 
%s

// expected-no-diagnostics

void clang_analyzer_warnIfReached();

void testAsmGoto() {
  asm goto("xor %0, %0\n je %l[label1]\n jl %l[label2]"
   : /* no outputs */
   : /* inputs */
   : /* clobbers */
   : label1, label2 /* any labels used */);

  label1:
  // FIXME: Should be reachable.
  clang_analyzer_warnIfReached();
  return;

  label2:
  // FIXME: Should be reachable.
  clang_analyzer_warnIfReached();
  return;
}
```

 (and the egraph part in the main file is also out of place)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63533



___
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=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 ,
 DiagnosticsEngine );
 };
+
+class ASTNameGenerator {
+  std::unique_ptr MC;
+  llvm::DataLayout DL;
+
+public:
+  explicit ASTNameGenerator(ASTContext );
+  bool writeName(const Decl *D, raw_ostream );
+  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 );
+  void writeObjCClassName(const ObjCInterfaceDecl *D, raw_ostream );
+  std::string getMangledStructor(const NamedDecl *ND, unsigned StructorType);
+  std::string getMangledThunk(const CXXMethodDecl *MD, const ThunkInfo );
+};
 }
 
 #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 )
+: MC(Ctx.createMangleContext()), DL(Ctx.getTargetInfo().getDataLayout()) {}
+
+bool ASTNameGenerator::writeName(const Decl *D, raw_ostream ) {
+  // 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 ) {
+  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 

r363878 - [clang][AST] ASTNameGenerator: A refactoring of CodegenNameGeneratorImpl (NFC).

2019-06-19 Thread Puyan Lotfi via cfe-commits
Author: zer0
Date: Wed Jun 19 13:51:35 2019
New Revision: 363878

URL: http://llvm.org/viewvc/llvm-project?rev=363878=rev
Log:
[clang][AST] ASTNameGenerator: A refactoring of CodegenNameGeneratorImpl (NFC).

This is a NFC refactor move of CodegenNameGeneratorImpl from clang::Index to
clang:AST (and rename to ASTNameGenerator). The purpose is to make the
highlevel mangling code more reusable inside of clang (say in places like clang
FrontendAction). This does not affect anything in CodegenNameGenerator, except
that CodegenNameGenerator will now use ASTNameGenerator (in AST).

Differential Revision: https://reviews.llvm.org/D63535

Modified:
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

Modified: cfe/trunk/include/clang/AST/Mangle.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Mangle.h?rev=363878=363877=363878=diff
==
--- cfe/trunk/include/clang/AST/Mangle.h (original)
+++ cfe/trunk/include/clang/AST/Mangle.h Wed Jun 19 13:51:35 2019
@@ -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 @@ public:
   static MicrosoftMangleContext *create(ASTContext ,
 DiagnosticsEngine );
 };
+
+class ASTNameGenerator {
+  std::unique_ptr MC;
+  llvm::DataLayout DL;
+
+public:
+  explicit ASTNameGenerator(ASTContext );
+  bool writeName(const Decl *D, raw_ostream );
+  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 );
+  void writeObjCClassName(const ObjCInterfaceDecl *D, raw_ostream );
+  std::string getMangledStructor(const NamedDecl *ND, unsigned StructorType);
+  std::string getMangledThunk(const CXXMethodDecl *MD, const ThunkInfo );
+};
 }
 
 #endif

Modified: cfe/trunk/include/clang/Index/CodegenNameGenerator.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Index/CodegenNameGenerator.h?rev=363878=363877=363878=diff
==
--- cfe/trunk/include/clang/Index/CodegenNameGenerator.h (original)
+++ cfe/trunk/include/clang/Index/CodegenNameGenerator.h Wed Jun 19 13:51:35 
2019
@@ -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 @@ public:
 
 private:
   struct Implementation;
-  std::unique_ptr Impl;
+  std::unique_ptr Impl;
 };
 
 } // namespace index

Modified: cfe/trunk/lib/AST/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/CMakeLists.txt?rev=363878=363877=363878=diff
==
--- cfe/trunk/lib/AST/CMakeLists.txt (original)
+++ cfe/trunk/lib/AST/CMakeLists.txt Wed Jun 19 13:51:35 2019
@@ -1,5 +1,6 @@
 set(LLVM_LINK_COMPONENTS
   BinaryFormat
+  Core
   Support
   )
 

Modified: cfe/trunk/lib/AST/Mangle.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Mangle.cpp?rev=363878=363877=363878=diff
==
--- cfe/trunk/lib/AST/Mangle.cpp (original)
+++ cfe/trunk/lib/AST/Mangle.cpp Wed Jun 19 13:51:35 2019
@@ -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 @@ void MangleContext::mangleObjCMethodName
   mangleObjCMethodNameWithoutSize(MD, OS);
   Out << OS.str().size() << OS.str();
 }
+
+ASTNameGenerator::ASTNameGenerator(ASTContext )
+: MC(Ctx.createMangleContext()), DL(Ctx.getTargetInfo().getDataLayout()) {}
+
+bool ASTNameGenerator::writeName(const Decl *D, raw_ostream ) {
+  // 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 = 

[PATCH] D60455: [SYCL] Implement SYCL device code outlining

2019-06-19 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon added inline comments.



Comment at: clang/include/clang/Basic/AttrDocs.td:263-264
+entry point to device code i.e. will be called by host in run time.
+Here is a code example of the SYCL program, which demonstrates the need for
+this attribute:
+.. code-block:: c++

aaron.ballman wrote:
> This doesn't really demonstrate the need for the attribute -- the attribute 
> is never shown in the code example. I'd prefer an example that shows when and 
> how a user would write this attribute.
I see. I will update documentation in the next version. 


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D60455



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


[PATCH] D60455: [SYCL] Implement SYCL device code outlining

2019-06-19 Thread Mariya Podchishchaeva via Phabricator via cfe-commits
Fznamznon updated this revision to Diff 205663.
Fznamznon added a comment.

Appled part of comments from @aaron.ballman:

- Fixed grammar and code style in all places except sycl_kernel docs
- Added a lit test which checks that sycl_device attribute implicitly added to 
proper declarations


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D60455

Files:
  clang/include/clang/Basic/Attr.td
  clang/include/clang/Basic/AttrDocs.td
  clang/include/clang/Sema/Sema.h
  clang/lib/CodeGen/CodeGenModule.cpp
  clang/lib/Parse/ParseAST.cpp
  clang/lib/Sema/CMakeLists.txt
  clang/lib/Sema/Sema.cpp
  clang/lib/Sema/SemaDeclAttr.cpp
  clang/lib/Sema/SemaSYCL.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/test/CodeGenSYCL/device-functions.cpp
  clang/test/Misc/pragma-attribute-supported-attributes-list.test
  clang/test/SemaSYCL/device-attributes-on-non-sycl.cpp
  clang/test/SemaSYCL/device-attributes.cpp
  clang/test/SemaSYCL/device-code-outlining.cpp

Index: clang/test/SemaSYCL/device-code-outlining.cpp
===
--- /dev/null
+++ clang/test/SemaSYCL/device-code-outlining.cpp
@@ -0,0 +1,37 @@
+// RUN: %clang_cc1 -std=c++11 -fsycl-is-device -ast-dump %s | FileCheck %s
+
+template 
+T bar(T arg);
+// CHECK: FunctionTemplateDecl {{.*}} bar
+// CHECK: SYCLDeviceAttr {{.*}} Implicit
+
+void foo() {
+  int a = 1 + 1 + bar(1);
+}
+// CHECK: FunctionDecl {{.*}} foo
+// CHECK: SYCLDeviceAttr {{.*}} Implicit
+
+template 
+T bar(T arg) {
+  return arg;
+}
+
+template 
+__attribute__((sycl_kernel)) void kernel_single_task(Func kernelFunc) {
+  kernelFunc();
+}
+// CHECK: FunctionTemplateDecl {{.*}} kernel_single_task
+// CHECK: SYCLDeviceAttr {{.*}} Implicit
+
+void host_foo() {
+  int b = 0;
+}
+// CHECK: FunctionDecl {{.*}} host_foo
+// CHECK-NOT: SYCLDeviceAttr
+// CHECK: FunctionDecl {{.*}} main
+
+int main() {
+  kernel_single_task([]() { foo(); });
+  host_foo();
+  return 0;
+}
Index: clang/test/SemaSYCL/device-attributes.cpp
===
--- /dev/null
+++ clang/test/SemaSYCL/device-attributes.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -fsycl-is-device -verify %s
+
+[[clang::sycl_kernel]] int gv2 = 0; // expected-warning {{'sycl_kernel' attribute only applies to functions}}
+__attribute__((sycl_kernel)) int gv3 = 0; // expected-warning {{'sycl_kernel' attribute only applies to functions}}
+
+__attribute__((sycl_kernel)) void foo();
+[[clang::sycl_kernel]] void foo1();
+
+__attribute__((sycl_kernel(1))) void foo(); // expected-error {{'sycl_kernel' attribute takes no arguments}}
+[[clang::sycl_kernel(1)]] void foo2(); // expected-error {{'sycl_kernel' attribute takes no arguments}}
Index: clang/test/SemaSYCL/device-attributes-on-non-sycl.cpp
===
--- /dev/null
+++ clang/test/SemaSYCL/device-attributes-on-non-sycl.cpp
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -fsycl-is-device -verify %s
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify -x c++ %s
+
+#ifndef __SYCL_DEVICE_ONLY__
+// expected-warning@+6 {{'sycl_kernel' attribute ignored}}
+// expected-warning@+6 {{'sycl_kernel' attribute ignored}}
+#else
+// expected-no-diagnostics
+#endif
+
+__attribute__((sycl_kernel)) void foo();
+[[clang::sycl_kernel]] void foo2();
+
Index: clang/test/Misc/pragma-attribute-supported-attributes-list.test
===
--- clang/test/Misc/pragma-attribute-supported-attributes-list.test
+++ clang/test/Misc/pragma-attribute-supported-attributes-list.test
@@ -125,6 +125,7 @@
 // CHECK-NEXT: ReturnTypestate (SubjectMatchRule_function, SubjectMatchRule_variable_is_parameter)
 // CHECK-NEXT: ReturnsNonNull (SubjectMatchRule_objc_method, SubjectMatchRule_function)
 // CHECK-NEXT: ReturnsTwice (SubjectMatchRule_function)
+// CHECK-NEXT: SYCLKernel (SubjectMatchRule_function)
 // CHECK-NEXT: ScopedLockable (SubjectMatchRule_record)
 // CHECK-NEXT: Section (SubjectMatchRule_function, SubjectMatchRule_variable_is_global, SubjectMatchRule_objc_method, SubjectMatchRule_objc_property)
 // CHECK-NEXT: SetTypestate (SubjectMatchRule_function_is_member)
Index: clang/test/CodeGenSYCL/device-functions.cpp
===
--- /dev/null
+++ clang/test/CodeGenSYCL/device-functions.cpp
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -triple spir64-unknown-unknown -std=c++11 -fsycl-is-device -S -emit-llvm %s -o - | FileCheck %s
+
+template 
+T bar(T arg);
+
+void foo() {
+  int a = 1 + 1 + bar(1);
+}
+
+template 
+T bar(T arg) {
+  return arg;
+}
+
+template 
+__attribute__((sycl_kernel)) void kernel_single_task(Func kernelFunc) {
+  kernelFunc();
+}
+
+int main() {
+  kernel_single_task([]() { foo(); });
+  return 0;
+}
+// CHECK: define spir_func void 

r363873 - Print whether a generic selection expression is result dependent when dumping the AST to JSON.

2019-06-19 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Wed Jun 19 13:16:55 2019
New Revision: 363873

URL: http://llvm.org/viewvc/llvm-project?rev=363873=rev
Log:
Print whether a generic selection expression is result dependent when dumping 
the AST to JSON.

Modified:
cfe/trunk/include/clang/AST/JSONNodeDumper.h
cfe/trunk/lib/AST/JSONNodeDumper.cpp
cfe/trunk/test/AST/ast-dump-stmt-json.cpp

Modified: cfe/trunk/include/clang/AST/JSONNodeDumper.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/JSONNodeDumper.h?rev=363873=363872=363873=diff
==
--- cfe/trunk/include/clang/AST/JSONNodeDumper.h (original)
+++ cfe/trunk/include/clang/AST/JSONNodeDumper.h Wed Jun 19 13:16:55 2019
@@ -252,6 +252,7 @@ public:
   void VisitCXXTypeidExpr(const CXXTypeidExpr *CTE);
   void VisitConstantExpr(const ConstantExpr *CE);
   void VisitInitListExpr(const InitListExpr *ILE);
+  void VisitGenericSelectionExpr(const GenericSelectionExpr *GSE);
 
   void VisitIntegerLiteral(const IntegerLiteral *IL);
   void VisitCharacterLiteral(const CharacterLiteral *CL);

Modified: cfe/trunk/lib/AST/JSONNodeDumper.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/JSONNodeDumper.cpp?rev=363873=363872=363873=diff
==
--- cfe/trunk/lib/AST/JSONNodeDumper.cpp (original)
+++ cfe/trunk/lib/AST/JSONNodeDumper.cpp Wed Jun 19 13:16:55 2019
@@ -989,6 +989,11 @@ void JSONNodeDumper::VisitInitListExpr(c
 JOS.attribute("field", createBareDeclRef(FD));
 }
 
+void JSONNodeDumper::VisitGenericSelectionExpr(
+const GenericSelectionExpr *GSE) {
+  attributeOnlyIfTrue("resultDependent", GSE->isResultDependent());
+}
+
 void JSONNodeDumper::VisitIntegerLiteral(const IntegerLiteral *IL) {
   JOS.attribute("value",
 IL->getValue().toString(

Modified: cfe/trunk/test/AST/ast-dump-stmt-json.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/AST/ast-dump-stmt-json.cpp?rev=363873=363872=363873=diff
==
--- cfe/trunk/test/AST/ast-dump-stmt-json.cpp (original)
+++ cfe/trunk/test/AST/ast-dump-stmt-json.cpp Wed Jun 19 13:16:55 2019
@@ -103,6 +103,12 @@ void TestIteration() {
 ;
 }
 
+template 
+void TestDependentGenericSelectionExpr(Ty T) {
+  _Generic(T, int : 1, default : 0);
+  _Generic(T, default : 0);
+}
+
 
 // CHECK:  "kind": "FunctionDecl",
 // CHECK-NEXT:  "loc": {
@@ -5987,6 +5993,334 @@ void TestIteration() {
 // CHECK-NEXT:   }
 // CHECK-NEXT:  ]
 // CHECK-NEXT: }
+// CHECK-NEXT:]
+// CHECK-NEXT:   }
+// CHECK-NEXT:  ]
+// CHECK-NEXT: }
+
+
+// CHECK:  "kind": "FunctionTemplateDecl",
+// CHECK-NEXT:  "loc": {
+// CHECK-NEXT:   "col": 6,
+// CHECK-NEXT:   "file": "{{.*}}",
+// CHECK-NEXT:   "line": 107
+// CHECK-NEXT:  },
+// CHECK-NEXT:  "range": {
+// CHECK-NEXT:   "begin": {
+// CHECK-NEXT:"col": 1,
+// CHECK-NEXT:"file": "{{.*}}",
+// CHECK-NEXT:"line": 106
+// CHECK-NEXT:   },
+// CHECK-NEXT:   "end": {
+// CHECK-NEXT:"col": 1,
+// CHECK-NEXT:"file": "{{.*}}",
+// CHECK-NEXT:"line": 110
+// CHECK-NEXT:   }
+// CHECK-NEXT:  },
+// CHECK-NEXT:  "name": "TestDependentGenericSelectionExpr",
+// CHECK-NEXT:  "inner": [
+// CHECK-NEXT:   {
+// CHECK-NEXT:"id": "0x{{.*}}",
+// CHECK-NEXT:"kind": "TemplateTypeParmDecl",
+// CHECK-NEXT:"loc": {
+// CHECK-NEXT: "col": 20,
+// CHECK-NEXT: "file": "{{.*}}",
+// CHECK-NEXT: "line": 106
+// CHECK-NEXT:},
+// CHECK-NEXT:"range": {
+// CHECK-NEXT: "begin": {
+// CHECK-NEXT:  "col": 11,
+// CHECK-NEXT:  "file": "{{.*}}",
+// CHECK-NEXT:  "line": 106
+// CHECK-NEXT: },
+// CHECK-NEXT: "end": {
+// CHECK-NEXT:  "col": 20,
+// CHECK-NEXT:  "file": "{{.*}}",
+// CHECK-NEXT:  "line": 106
+// CHECK-NEXT: }
+// CHECK-NEXT:},
+// CHECK-NEXT:"isReferenced": true,
+// CHECK-NEXT:"name": "Ty",
+// CHECK-NEXT:"tagUsed": "typename",
+// CHECK-NEXT:"depth": 0,
+// CHECK-NEXT:"index": 0
+// CHECK-NEXT:   },
+// CHECK-NEXT:   {
+// CHECK-NEXT:"id": "0x{{.*}}",
+// CHECK-NEXT:"kind": "FunctionDecl",
+// CHECK-NEXT:"loc": {
+// CHECK-NEXT: "col": 6,
+// CHECK-NEXT: "file": "{{.*}}",
+// CHECK-NEXT: "line": 107
+// CHECK-NEXT:},
+// CHECK-NEXT:"range": {
+// CHECK-NEXT: "begin": {
+// CHECK-NEXT:  "col": 1,
+// CHECK-NEXT:  "file": "{{.*}}",
+// CHECK-NEXT:  "line": 107
+// CHECK-NEXT: },
+// CHECK-NEXT: "end": {
+// CHECK-NEXT:  "col": 1,
+// CHECK-NEXT:  "file": "{{.*}}",
+// CHECK-NEXT:  "line": 110
+// CHECK-NEXT: }
+// CHECK-NEXT:},
+// CHECK-NEXT:"name": "TestDependentGenericSelectionExpr",
+// CHECK-NEXT:"type": {
+// CHECK-NEXT: "qualType": "void (Ty)"
+// CHECK-NEXT:},
+// CHECK-NEXT:"inner": [
+// CHECK-NEXT: {
+// 

r363871 - Reapply "r363684: AMDGPU: Add GWS instruction builtins"

2019-06-19 Thread Matt Arsenault via cfe-commits
Author: arsenm
Date: Wed Jun 19 12:55:49 2019
New Revision: 363871

URL: http://llvm.org/viewvc/llvm-project?rev=363871=rev
Log:
Reapply "r363684: AMDGPU: Add GWS instruction builtins"

Modified:
cfe/trunk/include/clang/Basic/BuiltinsAMDGPU.def
cfe/trunk/test/CodeGenOpenCL/builtins-amdgcn.cl

Modified: cfe/trunk/include/clang/Basic/BuiltinsAMDGPU.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/BuiltinsAMDGPU.def?rev=363871=363870=363871=diff
==
--- cfe/trunk/include/clang/Basic/BuiltinsAMDGPU.def (original)
+++ cfe/trunk/include/clang/Basic/BuiltinsAMDGPU.def Wed Jun 19 12:55:49 2019
@@ -45,6 +45,8 @@ BUILTIN(__builtin_amdgcn_s_barrier, "v",
 BUILTIN(__builtin_amdgcn_wave_barrier, "v", "n")
 BUILTIN(__builtin_amdgcn_s_dcache_inv, "v", "n")
 BUILTIN(__builtin_amdgcn_buffer_wbinvl1, "v", "n")
+BUILTIN(__builtin_amdgcn_ds_gws_init, "vUiUi", "n")
+BUILTIN(__builtin_amdgcn_ds_gws_barrier, "vUiUi", "n")
 
 // FIXME: Need to disallow constant address space.
 BUILTIN(__builtin_amdgcn_div_scale, "dddbb*", "n")

Modified: cfe/trunk/test/CodeGenOpenCL/builtins-amdgcn.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/builtins-amdgcn.cl?rev=363871=363870=363871=diff
==
--- cfe/trunk/test/CodeGenOpenCL/builtins-amdgcn.cl (original)
+++ cfe/trunk/test/CodeGenOpenCL/builtins-amdgcn.cl Wed Jun 19 12:55:49 2019
@@ -548,6 +548,18 @@ kernel void test_ds_consume_lds(global i
   *out = __builtin_amdgcn_ds_consume(ptr);
 }
 
+// CHECK-LABEL: @test_gws_init(
+// CHECK: call void @llvm.amdgcn.ds.gws.init(i32 %value, i32 %id)
+kernel void test_gws_init(uint value, uint id) {
+  __builtin_amdgcn_ds_gws_init(value, id);
+}
+
+// CHECK-LABEL: @test_gws_barrier(
+// CHECK: call void @llvm.amdgcn.ds.gws.barrier(i32 %value, i32 %id)
+kernel void test_gws_barrier(uint value, uint id) {
+  __builtin_amdgcn_ds_gws_barrier(value, id);
+}
+
 // CHECK-DAG: [[$WI_RANGE]] = !{i32 0, i32 1024}
 // CHECK-DAG: attributes #[[$NOUNWIND_READONLY:[0-9]+]] = { nounwind readonly }
 // CHECK-DAG: attributes #[[$READ_EXEC_ATTRS]] = { convergent }


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


r363869 - Print out the union field being initialized by an InitListExpr when dumping the AST to JSON.

2019-06-19 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Wed Jun 19 12:40:07 2019
New Revision: 363869

URL: http://llvm.org/viewvc/llvm-project?rev=363869=rev
Log:
Print out the union field being initialized by an InitListExpr when dumping the 
AST to JSON.

Modified:
cfe/trunk/include/clang/AST/JSONNodeDumper.h
cfe/trunk/lib/AST/JSONNodeDumper.cpp
cfe/trunk/test/AST/ast-dump-stmt-json.cpp

Modified: cfe/trunk/include/clang/AST/JSONNodeDumper.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/JSONNodeDumper.h?rev=363869=363868=363869=diff
==
--- cfe/trunk/include/clang/AST/JSONNodeDumper.h (original)
+++ cfe/trunk/include/clang/AST/JSONNodeDumper.h Wed Jun 19 12:40:07 2019
@@ -251,6 +251,7 @@ public:
   void VisitAddrLabelExpr(const AddrLabelExpr *ALE);
   void VisitCXXTypeidExpr(const CXXTypeidExpr *CTE);
   void VisitConstantExpr(const ConstantExpr *CE);
+  void VisitInitListExpr(const InitListExpr *ILE);
 
   void VisitIntegerLiteral(const IntegerLiteral *IL);
   void VisitCharacterLiteral(const CharacterLiteral *CL);

Modified: cfe/trunk/lib/AST/JSONNodeDumper.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/JSONNodeDumper.cpp?rev=363869=363868=363869=diff
==
--- cfe/trunk/lib/AST/JSONNodeDumper.cpp (original)
+++ cfe/trunk/lib/AST/JSONNodeDumper.cpp Wed Jun 19 12:40:07 2019
@@ -984,6 +984,11 @@ void JSONNodeDumper::VisitConstantExpr(c
   }
 }
 
+void JSONNodeDumper::VisitInitListExpr(const InitListExpr *ILE) {
+  if (const FieldDecl *FD = ILE->getInitializedFieldInUnion())
+JOS.attribute("field", createBareDeclRef(FD));
+}
+
 void JSONNodeDumper::VisitIntegerLiteral(const IntegerLiteral *IL) {
   JOS.attribute("value",
 IL->getValue().toString(

Modified: cfe/trunk/test/AST/ast-dump-stmt-json.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/AST/ast-dump-stmt-json.cpp?rev=363869=363868=363869=diff
==
--- cfe/trunk/test/AST/ast-dump-stmt-json.cpp (original)
+++ cfe/trunk/test/AST/ast-dump-stmt-json.cpp Wed Jun 19 12:40:07 2019
@@ -2415,7 +2415,15 @@ void TestIteration() {
 // CHECK-NEXT:"type": {
 // CHECK-NEXT: "qualType": "U"
 // CHECK-NEXT:},
-// CHECK-NEXT:"valueCategory": "rvalue"
+// CHECK-NEXT:"valueCategory": "rvalue",
+// CHECK-NEXT:"field": {
+// CHECK-NEXT: "id": "0x{{.*}}",
+// CHECK-NEXT: "kind": "FieldDecl",
+// CHECK-NEXT: "name": "i",
+// CHECK-NEXT: "type": {
+// CHECK-NEXT:  "qualType": "int"
+// CHECK-NEXT: }
+// CHECK-NEXT:}
 // CHECK-NEXT:   },
 // CHECK-NEXT:   {
 // CHECK-NEXT:"id": "0x{{.*}}",
@@ -2436,6 +2444,14 @@ void TestIteration() {
 // CHECK-NEXT: "qualType": "U"
 // CHECK-NEXT:},
 // CHECK-NEXT:"valueCategory": "rvalue",
+// CHECK-NEXT:"field": {
+// CHECK-NEXT: "id": "0x{{.*}}",
+// CHECK-NEXT: "kind": "FieldDecl",
+// CHECK-NEXT: "name": "i",
+// CHECK-NEXT: "type": {
+// CHECK-NEXT:  "qualType": "int"
+// CHECK-NEXT: }
+// CHECK-NEXT:},
 // CHECK-NEXT:"inner": [
 // CHECK-NEXT: {
 // CHECK-NEXT:  "id": "0x{{.*}}",
@@ -5975,4 +5991,3 @@ void TestIteration() {
 // CHECK-NEXT:   }
 // CHECK-NEXT:  ]
 // CHECK-NEXT: }
-


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


[PATCH] D57450: [RISCV] Set MaxAtomicInlineWidth and MaxAtomicPromoteWidth for RV32/RV64 targets with atomics

2019-06-19 Thread John LLVM via Phabricator via cfe-commits
JohnLLVM added a comment.
Herald added subscribers: Jim, benna, psnobl, dexonsmith.

@asb: Gentle ping on this.

I would really like to avoid atomics libcalls in order to make proper llvm 
benchmarks.


Repository:
  rC Clang

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

https://reviews.llvm.org/D57450



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


[PATCH] D63277: [CUDA][HIP] Don't set "comdat" attribute for CUDA device stub functions.

2019-06-19 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

This optimization is disabled for functions not in COMDAT sections?  Is that 
documented somewhere?


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

https://reviews.llvm.org/D63277



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


[PATCH] D63277: [CUDA][HIP] Don't set "comdat" attribute for CUDA device stub functions.

2019-06-19 Thread Konstantin Pyzhov via Phabricator via cfe-commits
kpyzhov updated this revision to Diff 205655.

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

https://reviews.llvm.org/D63277

Files:
  clang/lib/CodeGen/CodeGenModule.cpp


Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -3706,6 +3706,11 @@
   if (!CGM.supportsCOMDAT())
 return false;
 
+  // Do not set COMDAT attribute for CUDA/HIP stub functions to prevent
+  // them being "merged" by the COMDAT Folding linker optimization.
+  if (D.hasAttr())
+return false;
+
   if (D.hasAttr())
 return true;
 


Index: clang/lib/CodeGen/CodeGenModule.cpp
===
--- clang/lib/CodeGen/CodeGenModule.cpp
+++ clang/lib/CodeGen/CodeGenModule.cpp
@@ -3706,6 +3706,11 @@
   if (!CGM.supportsCOMDAT())
 return false;
 
+  // Do not set COMDAT attribute for CUDA/HIP stub functions to prevent
+  // them being "merged" by the COMDAT Folding linker optimization.
+  if (D.hasAttr())
+return false;
+
   if (D.hasAttr())
 return true;
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D63508: make -frewrite-includes handle __has_include wrapped in a macro

2019-06-19 Thread Luboš Luňák via Phabricator via cfe-commits
llunak added a comment.

In D63508#1550668 , @rsmith wrote:

> Perhaps we should rewrite all `#if`-like directives to `#if 0` or `#if 1`?


I think that would work too and it'd be in fact a reliable simple solution.


Repository:
  rC Clang

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

https://reviews.llvm.org/D63508



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


[PATCH] D59744: Fix i386 ABI "__m64" type bug

2019-06-19 Thread Craig Topper via Phabricator via cfe-commits
craig.topper added a comment.

-O0 always inline isn't working because the frontend is emitting a store of 
vector type to memory then a load of x86_mmx to do the type coercion. The 
caller does the opposite to coerce back from mmx. This -O0 pipeline isn't 
capable of getting rid of these redundant store/load pairs. We might have a 
better chance if we just emitted bitcasts.


Repository:
  rL LLVM

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

https://reviews.llvm.org/D59744



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


r363866 - Dump the value calculated by a constant expression when dumping the AST to JSON.

2019-06-19 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Wed Jun 19 12:12:22 2019
New Revision: 363866

URL: http://llvm.org/viewvc/llvm-project?rev=363866=rev
Log:
Dump the value calculated by a constant expression when dumping the AST to JSON.

Modified:
cfe/trunk/include/clang/AST/JSONNodeDumper.h
cfe/trunk/lib/AST/JSONNodeDumper.cpp
cfe/trunk/test/AST/ast-dump-if-json.cpp
cfe/trunk/test/AST/ast-dump-stmt-json.cpp

Modified: cfe/trunk/include/clang/AST/JSONNodeDumper.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/JSONNodeDumper.h?rev=363866=363865=363866=diff
==
--- cfe/trunk/include/clang/AST/JSONNodeDumper.h (original)
+++ cfe/trunk/include/clang/AST/JSONNodeDumper.h Wed Jun 19 12:12:22 2019
@@ -250,6 +250,7 @@ public:
   void VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *ULE);
   void VisitAddrLabelExpr(const AddrLabelExpr *ALE);
   void VisitCXXTypeidExpr(const CXXTypeidExpr *CTE);
+  void VisitConstantExpr(const ConstantExpr *CE);
 
   void VisitIntegerLiteral(const IntegerLiteral *IL);
   void VisitCharacterLiteral(const CharacterLiteral *CL);

Modified: cfe/trunk/lib/AST/JSONNodeDumper.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/JSONNodeDumper.cpp?rev=363866=363865=363866=diff
==
--- cfe/trunk/lib/AST/JSONNodeDumper.cpp (original)
+++ cfe/trunk/lib/AST/JSONNodeDumper.cpp Wed Jun 19 12:12:22 2019
@@ -975,6 +975,15 @@ void JSONNodeDumper::VisitCXXTypeidExpr(
   }
 }
 
+void JSONNodeDumper::VisitConstantExpr(const ConstantExpr *CE) {
+  if (CE->getResultAPValueKind() != APValue::None) {
+std::string Str;
+llvm::raw_string_ostream OS(Str);
+CE->getAPValueResult().printPretty(OS, Ctx, CE->getType());
+JOS.attribute("value", OS.str());
+  }
+}
+
 void JSONNodeDumper::VisitIntegerLiteral(const IntegerLiteral *IL) {
   JOS.attribute("value",
 IL->getValue().toString(

Modified: cfe/trunk/test/AST/ast-dump-if-json.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/AST/ast-dump-if-json.cpp?rev=363866=363865=363866=diff
==
--- cfe/trunk/test/AST/ast-dump-if-json.cpp (original)
+++ cfe/trunk/test/AST/ast-dump-if-json.cpp Wed Jun 19 12:12:22 2019
@@ -528,6 +528,7 @@ void func(int val) {
 // CHECK-NEXT: "qualType": "bool"
 // CHECK-NEXT:},
 // CHECK-NEXT:"valueCategory": "rvalue",
+// CHECK-NEXT:"value": "true",
 // CHECK-NEXT:"inner": [
 // CHECK-NEXT: {
 // CHECK-NEXT:  "id": "0x{{.*}}",

Modified: cfe/trunk/test/AST/ast-dump-stmt-json.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/AST/ast-dump-stmt-json.cpp?rev=363866=363865=363866=diff
==
--- cfe/trunk/test/AST/ast-dump-stmt-json.cpp (original)
+++ cfe/trunk/test/AST/ast-dump-stmt-json.cpp Wed Jun 19 12:12:22 2019
@@ -2951,6 +2951,7 @@ void TestIteration() {
 // CHECK-NEXT: "qualType": "bool"
 // CHECK-NEXT:},
 // CHECK-NEXT:"valueCategory": "rvalue",
+// CHECK-NEXT:"value": "true",
 // CHECK-NEXT:"inner": [
 // CHECK-NEXT: {
 // CHECK-NEXT:  "id": "0x{{.*}}",
@@ -3150,6 +3151,7 @@ void TestIteration() {
 // CHECK-NEXT: "qualType": "bool"
 // CHECK-NEXT:},
 // CHECK-NEXT:"valueCategory": "rvalue",
+// CHECK-NEXT:"value": "true",
 // CHECK-NEXT:"inner": [
 // CHECK-NEXT: {
 // CHECK-NEXT:  "id": "0x{{.*}}",


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


r363859 - Switching this test to use output generated by script; NFC.

2019-06-19 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Wed Jun 19 12:07:52 2019
New Revision: 363859

URL: http://llvm.org/viewvc/llvm-project?rev=363859=rev
Log:
Switching this test to use output generated by script; NFC.

Modified:
cfe/trunk/test/AST/ast-dump-if-json.cpp

Modified: cfe/trunk/test/AST/ast-dump-if-json.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/AST/ast-dump-if-json.cpp?rev=363859=363858=363859=diff
==
--- cfe/trunk/test/AST/ast-dump-if-json.cpp (original)
+++ cfe/trunk/test/AST/ast-dump-if-json.cpp Wed Jun 19 12:07:52 2019
@@ -4,242 +4,11 @@ void func(int val) {
   if (val)
 ;
 
-// CHECK: "kind": "IfStmt",
-// CHECK-NEXT: "range": {
-// CHECK-NEXT: "begin": {
-// CHECK-NEXT: "col": 3,
-// CHECK-NEXT: "file": "{{.*}}",
-// CHECK-NEXT: "line": 4
-// CHECK-NEXT: },
-// CHECK-NEXT: "end": {
-// CHECK-NEXT: "col": 5,
-// CHECK-NEXT: "file": "{{.*}}",
-// CHECK-NEXT: "line": 5
-// CHECK-NEXT: }
-// CHECK-NEXT: },
-// CHECK-NEXT: "inner": [
-// CHECK-NEXT: {
-// CHECK-NEXT: "id": "0x{{.*}}",
-// CHECK-NEXT: "kind": "ImplicitCastExpr",
-// CHECK-NEXT: "range": {
-// CHECK-NEXT: "begin": {
-// CHECK-NEXT: "col": 7,
-// CHECK-NEXT: "file": "{{.*}}",
-// CHECK-NEXT: "line": 4
-// CHECK-NEXT: },
-// CHECK-NEXT: "end": {
-// CHECK-NEXT: "col": 7,
-// CHECK-NEXT: "file": "{{.*}}",
-// CHECK-NEXT: "line": 4
-// CHECK-NEXT: }
-// CHECK-NEXT: },
-// CHECK-NEXT: "type": {
-// CHECK-NEXT: "qualType": "bool"
-// CHECK-NEXT: },
-// CHECK-NEXT: "valueCategory": "rvalue",
-// CHECK-NEXT: "castKind": "IntegralToBoolean",
-// CHECK-NEXT: "inner": [
-// CHECK-NEXT: {
-// CHECK-NEXT: "id": "0x{{.*}}",
-// CHECK-NEXT: "kind": "ImplicitCastExpr",
-// CHECK-NEXT: "range": {
-// CHECK-NEXT: "begin": {
-// CHECK-NEXT: "col": 7,
-// CHECK-NEXT: "file": "{{.*}}",
-// CHECK-NEXT: "line": 4
-// CHECK-NEXT: },
-// CHECK-NEXT: "end": {
-// CHECK-NEXT: "col": 7,
-// CHECK-NEXT: "file": "{{.*}}",
-// CHECK-NEXT: "line": 4
-// CHECK-NEXT: }
-// CHECK-NEXT: },
-// CHECK-NEXT: "type": {
-// CHECK-NEXT: "qualType": "int"
-// CHECK-NEXT: },
-// CHECK-NEXT: "valueCategory": "rvalue",
-// CHECK-NEXT: "castKind": "LValueToRValue",
-// CHECK-NEXT: "inner": [
-// CHECK-NEXT: {
-// CHECK-NEXT: "id": "0x{{.*}}",
-// CHECK-NEXT: "kind": "DeclRefExpr",
-// CHECK-NEXT: "range": {
-// CHECK-NEXT: "begin": {
-// CHECK-NEXT: "col": 7,
-// CHECK-NEXT: "file": "{{.*}}",
-// CHECK-NEXT: "line": 4
-// CHECK-NEXT: },
-// CHECK-NEXT: "end": {
-// CHECK-NEXT: "col": 7,
-// CHECK-NEXT: "file": "{{.*}}",
-// CHECK-NEXT: "line": 4
-// CHECK-NEXT: }
-// CHECK-NEXT: },
-// CHECK-NEXT: "type": {
-// CHECK-NEXT: "qualType": "int"
-// CHECK-NEXT: },
-// CHECK-NEXT: "valueCategory": "lvalue",
-// CHECK-NEXT: "referencedDecl": {
-// CHECK-NEXT: "id": "0x{{.*}}",
-// CHECK-NEXT: "kind": "ParmVarDecl",
-// CHECK-NEXT: "name": "val",
-// CHECK-NEXT: "type": {
-// CHECK-NEXT: "qualType": "int"
-// CHECK-NEXT: }
-// CHECK-NEXT: }
-// CHECK-NEXT: }
-// CHECK-NEXT: ]
-// CHECK-NEXT: }
-// CHECK-NEXT: ]
-// CHECK-NEXT: },
-// CHECK-NEXT: {
-// CHECK-NEXT: "id": "0x{{.*}}",
-// CHECK-NEXT: "kind": "NullStmt",
-// CHECK-NEXT: "range": {
-// CHECK-NEXT: "begin": {
-// CHECK-NEXT: "col": 5,
-// CHECK-NEXT: "file": "{{.*}}",
-// CHECK-NEXT: "line": 5
-// CHECK-NEXT: },
-// CHECK-NEXT: "end": {
-// CHECK-NEXT: "col": 5,
-// CHECK-NEXT: "file": "{{.*}}",
-// CHECK-NEXT: "line": 5
-// CHECK-NEXT: }
-// CHECK-NEXT: }
-// CHECK-NEXT: }
-// CHECK-NEXT: ]
-// CHECK-NEXT: },
-
   if (val)
 ;
   else
 ;
 
-// CHECK: "kind": "IfStmt",
-// CHECK-NEXT: "range": {
-// CHECK-NEXT: "begin": {
-// CHECK-NEXT: "col": 3,
-// CHECK-NEXT: "file": "{{.*}}",
-// CHECK-NEXT: "line": 114
-// CHECK-NEXT: },
-// CHECK-NEXT: "end": {
-// CHECK-NEXT: "col": 5,
-// CHECK-NEXT: "file": "{{.*}}",
-// CHECK-NEXT: "line": 117
-// CHECK-NEXT: }
-// CHECK-NEXT: },
-// CHECK-NEXT: "hasElse": true,
-// CHECK-NEXT: "inner": [
-// CHECK-NEXT: {
-// CHECK-NEXT: "id": "0x{{.*}}",
-// CHECK-NEXT: "kind": "ImplicitCastExpr",
-// CHECK-NEXT: "range": {
-// CHECK-NEXT: "begin": {
-// CHECK-NEXT: "col": 7,
-// CHECK-NEXT: "file": "{{.*}}",
-// CHECK-NEXT: "line": 114
-// CHECK-NEXT: },
-// CHECK-NEXT: "end": {
-// CHECK-NEXT: "col": 7,
-// CHECK-NEXT: "file": "{{.*}}",
-// CHECK-NEXT: "line": 114
-// CHECK-NEXT: }
-// CHECK-NEXT: },
-// CHECK-NEXT: "type": {
-// CHECK-NEXT: "qualType": "bool"
-// CHECK-NEXT: },
-// CHECK-NEXT: "valueCategory": "rvalue",
-// CHECK-NEXT: "castKind": "IntegralToBoolean",
-// CHECK-NEXT: "inner": [
-// CHECK-NEXT: {
-// CHECK-NEXT: "id": "0x{{.*}}",
-// CHECK-NEXT: "kind": "ImplicitCastExpr",
-// CHECK-NEXT: "range": {
-// CHECK-NEXT: "begin": {
-// CHECK-NEXT: "col": 7,
-// CHECK-NEXT: "file": "{{.*}}",
-// CHECK-NEXT: "line": 114
-// CHECK-NEXT: },
-// CHECK-NEXT: "end": {
-// CHECK-NEXT: "col": 7,
-// CHECK-NEXT: "file": "{{.*}}",
-// CHECK-NEXT: "line": 114
-// CHECK-NEXT: }
-// CHECK-NEXT: },
-// 

[PATCH] D63518: WIP BitStream reader: propagate errors

2019-06-19 Thread Bruno Cardoso Lopes via Phabricator via cfe-commits
bruno added a comment.

Hi JF. Thanks for working on this, nice improvement to error handling!

The overall approach is pretty solid and should prevent a lot of red herring 
while investigating hard to reproduce crashes in clang, specially when implicit 
clang modules is involved. Dropping the errors on the floor for previous code 
that didn't handle errors at all is a fair tradeoff for introducing the 
functionality. I have omitted any format comments but I noticed several of 80 
cols violations. More specific reviews inline.




Comment at: clang/lib/Frontend/PrecompiledPreamble.cpp:356
+  if (llvm::Error Err = Act->Execute())
+return errorToErrorCode(std::move(Err));
 

Changes like this are so much better!



Comment at: clang/lib/Frontend/SerializedDiagnosticReader.cpp:59
+} else
+return SDError::InvalidDiagnostics; // FIXME propagate the error 
details.
 

Can this be simplified as below?

```
Expected Res = Stream.ReadCode();
if (!Res || Res.get() != llvm::bitc::ENTER_SUBBLOCK)
  return SDError::InvalidDiagnostics; // FIXME propagate the error details.
```



Comment at: clang/lib/Serialization/ASTReader.cpp:1158
   StringRef Blob;
-  unsigned Code = Cursor.ReadCode();
-  unsigned RecCode = Cursor.readRecord(Code, Record, );
+  Expected MaybeCode = Cursor.ReadCode();
+  if (!MaybeCode) {

Not necessarily needed as part of this patch, but I wonder how many of 
repetitive access patterns (readCode + readRecord, and maybe other patterns) we 
have that would take advantage of refactoring all these checks out into their 
own methods.



Comment at: clang/lib/Serialization/ASTReader.cpp:4283
+return llvm::createStringError(std::errc::illegal_byte_sequence, "file too 
small to contain AST file magic");
+  for (unsigned C : {'C','P','C','H'})
+if (Expected Res = Stream.Read(8)) {

Very similar to SerializedDiagnosticReader.cpp:44, does it deserve a common 
helper?



Comment at: clang/lib/Serialization/ASTReader.cpp:4559
+  // FIXME this drops the error.
+  return Failure;
+}

This is a good example of a real issue this patch solves. Sometimes we get 
signature mismatch problems in implicit modules builds because we read garbage. 
Having this check and failure here prevents the misleading error message.



Comment at: clang/lib/Serialization/ASTReaderDecl.cpp:3695
+  if (!MaybeDeclCode)
+llvm::report_fatal_error("ASTReader::ReadDeclRecord failed readung decl 
code: " + toString(MaybeDeclCode.takeError()));
+  switch ((DeclCode)MaybeDeclCode.get()) {

typo on `readung`



Comment at: clang/lib/Serialization/ASTReaderDecl.cpp:4036
+  if (llvm::Error JumpFailed = Cursor.JumpToBit(Offset))
+// FIXME don't do a fatal error.
+llvm::report_fatal_error("ASTReader::loadDeclUpdateRecords failed 
jumping: " + toString(std::move(JumpFailed)));

Why? What's a better alternative?



Comment at: clang/lib/Serialization/ASTReaderDecl.cpp:4119
+  if (Expected MaybeRecCode = Cursor.readRecord(Code, Record))
+assert(MaybeRecCode.get() == LOCAL_REDECLARATIONS && "expected 
LOCAL_REDECLARATIONS record!");
+  else

Does this builds fine without assertions?



Comment at: clang/lib/Serialization/GlobalModuleIndex.cpp:133
+report_fatal_error("Module index '" + Buffer->getBufferIdentifier() + "' 
failed: " + toString(std::move(Err)));
+  };
+

Maybe use a similar helper for error checking added in ASTReaderDecl.cpp?



Comment at: clang/lib/Serialization/GlobalModuleIndex.cpp:266
   // Sniff for the signature.
-  if (Cursor.Read(8) != 'B' ||
-  Cursor.Read(8) != 'C' ||
-  Cursor.Read(8) != 'G' ||
-  Cursor.Read(8) != 'I') {
-return std::make_pair(nullptr, EC_IOError);
+  for (unsigned char C : {'B', 'C', 'G', 'I'}) {
+if (Expected Res = Cursor.Read(8)) {

Very similar to SerializedDiagnosticReader.cpp:44, does it deserve a common 
helper?



Comment at: clang/lib/Serialization/GlobalModuleIndex.cpp:535
   // Sniff for the signature.
-  if (InStream.Read(8) != 'C' ||
-  InStream.Read(8) != 'P' ||
-  InStream.Read(8) != 'C' ||
-  InStream.Read(8) != 'H') {
-return true;
-  }
+  for (unsigned char C : {'C','P','C','H'})
+if (Expected Res = InStream.Read(8)) {

Very similar to SerializedDiagnosticReader.cpp:44, does it deserve a common 
helper?



Comment at: llvm/include/llvm/Bitcode/BitstreamReader.h:230
+uint32_t Piece;
+if (Expected Res = Read(NumBits))
+  Piece = Res.get();

Alternatively, you can go early return mode for this and other error checking 
in BitstreamReader.h

```
Expected Res = Read(NumBits);
if (!Res)
  return Res;

[PATCH] D63423: [Diagnostics] Diagnose misused xor as pow

2019-06-19 Thread Dávid Bolvanský via Phabricator via cfe-commits
xbolva00 added a comment.

David Malcon - GCC: “I think we'd want to *not* warn if either of the operands 
are from a macro expansion.“

But I see no reason to follow this and why we should restrict this even more..


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

https://reviews.llvm.org/D63423



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


[PATCH] D59474: [OpenMP 5.0] Codegen support for user-defined mappers

2019-06-19 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: lib/CodeGen/CGOpenMPRuntime.cpp:8739
+/// // For each component specified by this mapper:
+/// if (currentComponent.hasMapper())
+///   (*currentComponent.Mapper())(rt_mapper_handle, arg_base, arg_begin,

lildmh wrote:
> ABataev wrote:
> > Currently `currentComponent` is generated by the compiler. But can we 
> > instead pass this data as an extra parameter to this `omp_mapper` function.
> Emm, I think this scheme will be very difficult and inefficient. If we pass 
> components as an argument of `omp_mapper` function, it means that the runtime 
> needs to generate all components related to a map clause. I don't think the 
> runtime is able to do that efficiently. On the other hand, in the current 
> scheme, these components are naturally generated by the compiler, and the 
> runtime only needs to know the base pointer, pointer, type, size. etc.
With the current scheme, we may end with the code blowout. We need to generate 
very similar code for different types and variables. The worst thing here is 
that we will be unable to optimize this huge amount of code because the codegen 
relies on the runtime functions and the code cannot be inlined. That's why I 
would like to move as much as possible code to the runtime rather than to emit 
it in the compiler. 



Comment at: lib/CodeGen/CGOpenMPRuntime.cpp:8740
+/// if (currentComponent.hasMapper())
+///   (*currentComponent.Mapper())(rt_mapper_handle, arg_base, arg_begin,
+///arg_size, arg_type);

lildmh wrote:
> ABataev wrote:
> > I don't see this part of logic in the code. Could you show me where is it 
> > exactly?
> This part doesn't exist in this patch. Currently we don't really look up the 
> mapper for any mapped variable/array/etc. The next patch will add the code to 
> look up the specified mapper for every map clause, and get the mapper 
> function for them correspondingly.
Then we need at least some kind of `TODO` note that this part is not 
implemented in this patch.



Comment at: lib/CodeGen/CGOpenMPRuntime.cpp:8773
+ C.VoidPtrTy, ImplicitParamDecl::Other);
+  ImplicitParamDecl SizeArg(C, SizeTy, ImplicitParamDecl::Other);
+  ImplicitParamDecl TypeArg(C, Int64Ty, ImplicitParamDecl::Other);

Always better to use constructor with the location to generate correct debug 
info for all the parameters.



Comment at: lib/CodeGen/CGOpenMPRuntime.cpp:8866-8867
+  createRuntimeFunction(OMPRTL__tgt_mapper_num_components), 
OffloadingArgs);
+  llvm::Value *ShiftedPreviousSize =
+  MapperCGF.Builder.CreateShl(PreviousSize, 
MapperCGF.Builder.getInt64(48));
+

I don't like this code very much! It hides the logiс ща the MEMBER_OF flag deep 
inside and it is going to be very hard to update it in future if there are some 
changes in the flags.



Comment at: lib/CodeGen/CGOpenMPRuntime.cpp:8934
+MapperCGF.Builder.getInt64(MappableExprsHandler::OMP_MAP_TO));
+MapperCGF.Builder.CreateCondBr(IsTo, ToBB, ToElseBB);
+// In case of to, clear OMP_MAP_FROM.

I don't see this logic in the comment for the function. Could you add more 
details for all this logic implemented here?



Comment at: lib/CodeGen/CGOpenMPRuntime.cpp:8995
+
+// Emit the array initialization or deletion portion for user-defined mapper
+// code generation.

1. Use `///` style of comment here
2. Add the description of the logic implemented here



Comment at: lib/CodeGen/CGOpenMPRuntime.cpp:9003
+  QualType SizeTy = C.getSizeType();
+  std::string Prefix = IsInit ? ".init" : ".del";
+

Use `StringRef` or `SmallString`



Comment at: lib/CodeGen/CGOpenMPRuntime.cpp:9020-9026
+  if (IsInit)
+DeleteCond = MapperCGF.Builder.CreateIsNull(
+DeleteBit, "omp.array" + Prefix + ".delete");
+  else {
+DeleteCond = MapperCGF.Builder.CreateIsNotNull(
+DeleteBit, "omp.array" + Prefix + ".delete");
+  }

Enclose all substatements into braces or none of them.


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

https://reviews.llvm.org/D59474



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


[PATCH] D63361: Pretend NRVO variables are references so they can be found by debug info

2019-06-19 Thread Reid Kleckner via Phabricator via cfe-commits
rnk added a comment.

I see we don't have any tests for inalloca to model this on, so I think we 
should skip that for this change. I'll add one later that handles arguments as 
well, since those are interesting.




Comment at: clang/lib/CodeGen/CGDecl.cpp:1564
+Address DebugAddr = address;
+bool UsePointerValue = false;
 DI->setLocation(D.getLocation());

Nit: Since the boolean is really the condition of the if, I'd suggest writing 
it like this:
  bool UsePointerValue = NRVO && ReturnValuePointer.isValid();
  if (UsePointerValue)
DebugAddr = ReturnValuePointer;
  ...
It's more functional, less stateful, and is one less line in the end.



Comment at: clang/lib/CodeGen/CodeGenFunction.cpp:908
 --EI;
 llvm::Value *Addr = Builder.CreateStructGEP(nullptr, &*EI, Idx);
 Addr = Builder.CreateAlignedLoad(Addr, getPointerAlign(), "agg.result");

akhuang wrote:
> rnk wrote:
> > What I had in mind was to use this GEP as the ReturnValuePointer here. The 
> > inalloca parameter is also a pointer to stack memory, and a GEP is an 
> > offset, so it should end up being handled like a static alloca.
> Oh, ok. I changed it, but not sure how to test debug info for the inalloca 
> case
I don't think this is the correct alignment. The sret slot in the inalloca has 
a pointer type, so I think you want pointer alignment here. I think you can 
substitute Int8PtrTy for RetTy here.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63361



___
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 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


r363857 - [AST] Fixed extraneous warnings for binary conditional operator

2019-06-19 Thread Nathan Huckleberry via cfe-commits
Author: nathan-huckleberry
Date: Wed Jun 19 11:37:01 2019
New Revision: 363857

URL: http://llvm.org/viewvc/llvm-project?rev=363857=rev
Log:
[AST] Fixed extraneous warnings for binary conditional operator

Summary:
Binary conditional operator gave warnings where ternary operators
did not. They have been fixed to warn similarly to ternary operators.

Link: https://bugs.llvm.org/show_bug.cgi?id=42239

Reviewers: rsmith, aaron.ballman, nickdesaulniers

Reviewed By: rsmith, nickdesaulniers

Subscribers: srhines, cfe-commits

Tags: #clang

Differential Revision: https://reviews.llvm.org/D63369

Added:
cfe/trunk/test/Sema/warn-binary-conditional-expression-unused.c
Modified:
cfe/trunk/lib/AST/Expr.cpp

Modified: cfe/trunk/lib/AST/Expr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=363857=363856=363857=diff
==
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Wed Jun 19 11:37:01 2019
@@ -2453,12 +2453,13 @@ bool Expr::isUnusedResultAWarning(const
 // If only one of the LHS or RHS is a warning, the operator might
 // be being used for control flow. Only warn if both the LHS and
 // RHS are warnings.
-const ConditionalOperator *Exp = cast(this);
-if (!Exp->getRHS()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx))
-  return false;
-if (!Exp->getLHS())
-  return true;
-return Exp->getLHS()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx);
+const auto *Exp = cast(this);
+return Exp->getLHS()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx) &&
+   Exp->getRHS()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx);
+  }
+  case BinaryConditionalOperatorClass: {
+const auto *Exp = cast(this);
+return Exp->getFalseExpr()->isUnusedResultAWarning(WarnE, Loc, R1, R2, 
Ctx);
   }
 
   case MemberExprClass:

Added: cfe/trunk/test/Sema/warn-binary-conditional-expression-unused.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/warn-binary-conditional-expression-unused.c?rev=363857=auto
==
--- cfe/trunk/test/Sema/warn-binary-conditional-expression-unused.c (added)
+++ cfe/trunk/test/Sema/warn-binary-conditional-expression-unused.c Wed Jun 19 
11:37:01 2019
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -fsyntax-only -Wunused-value -verify %s
+int main() {
+int a;
+int b;
+a ? : b; //expected-warning{{expression result unused}}
+a ? a : b; //expected-warning{{expression result unused}}
+a ? : ++b;
+a ? a : ++b;
+++a ? : b; //expected-warning{{expression result unused}}
+++a ? a : b; //expected-warning{{expression result unused}}
+++a ? : ++b;
+++a ? a : ++b;
+return 0;
+};
+


___
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 Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.

LGTM with a few nits.




Comment at: clang/include/clang/AST/Mangle.h:253
+public:
+  ASTNameGenerator(ASTContext );
+  bool writeName(const Decl *D, raw_ostream );

Slight preference to make this constructor `explicit` since it only accepts a 
single argument and I can't imagine wanting a converting constructor there.



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

Do we have to link in any new libraries in CMake for this new dependency?


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] D63369: [AST] Fixed extraneous warnings for binary conditional operator

2019-06-19 Thread Nathan Huckleberry via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL363857: [AST] Fixed extraneous warnings for binary 
conditional operator (authored by Nathan-Huckleberry, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D63369?vs=205473=205652#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D63369

Files:
  cfe/trunk/lib/AST/Expr.cpp
  cfe/trunk/test/Sema/warn-binary-conditional-expression-unused.c


Index: cfe/trunk/lib/AST/Expr.cpp
===
--- cfe/trunk/lib/AST/Expr.cpp
+++ cfe/trunk/lib/AST/Expr.cpp
@@ -2453,12 +2453,13 @@
 // If only one of the LHS or RHS is a warning, the operator might
 // be being used for control flow. Only warn if both the LHS and
 // RHS are warnings.
-const ConditionalOperator *Exp = cast(this);
-if (!Exp->getRHS()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx))
-  return false;
-if (!Exp->getLHS())
-  return true;
-return Exp->getLHS()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx);
+const auto *Exp = cast(this);
+return Exp->getLHS()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx) &&
+   Exp->getRHS()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx);
+  }
+  case BinaryConditionalOperatorClass: {
+const auto *Exp = cast(this);
+return Exp->getFalseExpr()->isUnusedResultAWarning(WarnE, Loc, R1, R2, 
Ctx);
   }
 
   case MemberExprClass:
Index: cfe/trunk/test/Sema/warn-binary-conditional-expression-unused.c
===
--- cfe/trunk/test/Sema/warn-binary-conditional-expression-unused.c
+++ cfe/trunk/test/Sema/warn-binary-conditional-expression-unused.c
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -fsyntax-only -Wunused-value -verify %s
+int main() {
+int a;
+int b;
+a ? : b; //expected-warning{{expression result unused}}
+a ? a : b; //expected-warning{{expression result unused}}
+a ? : ++b;
+a ? a : ++b;
+++a ? : b; //expected-warning{{expression result unused}}
+++a ? a : b; //expected-warning{{expression result unused}}
+++a ? : ++b;
+++a ? a : ++b;
+return 0;
+};
+


Index: cfe/trunk/lib/AST/Expr.cpp
===
--- cfe/trunk/lib/AST/Expr.cpp
+++ cfe/trunk/lib/AST/Expr.cpp
@@ -2453,12 +2453,13 @@
 // If only one of the LHS or RHS is a warning, the operator might
 // be being used for control flow. Only warn if both the LHS and
 // RHS are warnings.
-const ConditionalOperator *Exp = cast(this);
-if (!Exp->getRHS()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx))
-  return false;
-if (!Exp->getLHS())
-  return true;
-return Exp->getLHS()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx);
+const auto *Exp = cast(this);
+return Exp->getLHS()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx) &&
+   Exp->getRHS()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx);
+  }
+  case BinaryConditionalOperatorClass: {
+const auto *Exp = cast(this);
+return Exp->getFalseExpr()->isUnusedResultAWarning(WarnE, Loc, R1, R2, Ctx);
   }
 
   case MemberExprClass:
Index: cfe/trunk/test/Sema/warn-binary-conditional-expression-unused.c
===
--- cfe/trunk/test/Sema/warn-binary-conditional-expression-unused.c
+++ cfe/trunk/test/Sema/warn-binary-conditional-expression-unused.c
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -fsyntax-only -Wunused-value -verify %s
+int main() {
+int a;
+int b;
+a ? : b; //expected-warning{{expression result unused}}
+a ? a : b; //expected-warning{{expression result unused}}
+a ? : ++b;
+a ? a : ++b;
+++a ? : b; //expected-warning{{expression result unused}}
+++a ? a : b; //expected-warning{{expression result unused}}
+++a ? : ++b;
+++a ? a : ++b;
+return 0;
+};
+
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D63423: [Diagnostics] Diagnose misused xor as pow

2019-06-19 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In D63423#1550768 , @xbolva00 wrote:

> >> Perhaps the author can run the check over a large corpus of code to see 
> >> whether fps come up in practice? (The presence of fps will suggest to not 
> >> warn in macros, but the absence of fps won't tell us too much.)
>
> Sorry, I have no time nor spare computers to check big codebases. As @jfb 
> said, let's start with a conservative approach and possibly improve it in the 
> future.


I can live with that, but my concern is that we often don't do that "improve it 
in the future" bit and we already know about buggy cases in the wild where the 
diagnostic will not trigger. Given how often people use macros for simple, but 
wrong, constructs like my `POW` example, I think this reduces the utility of 
the check.

What are the GCC folks planning to do with macros?


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

https://reviews.llvm.org/D63423



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


[PATCH] D63108: [OpenMP] Add support for handling declare target to clause when unified memory is required

2019-06-19 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added inline comments.



Comment at: lib/CodeGen/CGExpr.cpp:2297-2319
+static Address emitDeclTargetToVarDeclLValue(CodeGenFunction ,
+ const VarDecl *VD, QualType T) {
+  llvm::Optional Res =
+  OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(VD);
+  if (!Res || *Res == OMPDeclareTargetDeclAttr::MT_Link)
+return Address::invalid();
+  assert(*Res == OMPDeclareTargetDeclAttr::MT_To && "Expected to clause");

I think it would be better to merge these 2 functions into 1 
`emitDeclTargetVarDeclLValue`. It should return the correct address for link 
vars and to vars with unified memory.



Comment at: lib/CodeGen/CGOpenMPRuntime.cpp:7458-7467
   if (*Res == OMPDeclareTargetDeclAttr::MT_Link) {
 IsLink = true;
 BP = CGF.CGM.getOpenMPRuntime().getAddrOfDeclareTargetLink(VD);
   }
+  if (*Res == OMPDeclareTargetDeclAttr::MT_To &&
+  CGF.CGM.getOpenMPRuntime().hasRequiresUnifiedSharedMemory()) {
+// TODO: Make this into a flag for TO with unified memory.

You can merge those pieces of code into one, no need to duplicate. Plus, I 
don't think we need a new flag for to with unified memory if we can express 
everything using the existing flags.



Comment at: lib/CodeGen/CGOpenMPRuntime.h:1123-1127
+  virtual Address getAddrOfDeclareTargetToUnderUnifiedMem(const VarDecl *VD);
+
   /// Returns the address of the variable marked as declare target with link
   /// clause.
   virtual Address getAddrOfDeclareTargetLink(const VarDecl *VD);

Same here, better to merge these 2 functions into one 
`getAddrOfDeclareTargetVar`



Comment at: test/OpenMP/nvptx_target_requires_unified_shared_memory.cpp:2
 // Test declare target link under unified memory requirement.
 // RUN: %clang_cc1 -verify -fopenmp -fopenmp-cuda-mode -x c++ -triple 
powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm %s 
-o - | FileCheck %s --check-prefix CHECK
 // expected-no-diagnostics

`CHECK` is the default prefix, no need to specify it.



Comment at: test/OpenMP/nvptx_target_requires_unified_shared_memory.cpp:2
 // Test declare target link under unified memory requirement.
 // RUN: %clang_cc1 -verify -fopenmp -fopenmp-cuda-mode -x c++ -triple 
powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm %s 
-o - | FileCheck %s --check-prefix CHECK
 // expected-no-diagnostics

ABataev wrote:
> `CHECK` is the default prefix, no need to specify it.
We also need the checks for the device codegen since you're changing something 
not only in the host codegen, but in the device codegen too. Just extend this 
test to check for the codegen for the device.


Repository:
  rC Clang

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

https://reviews.llvm.org/D63108



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


[PATCH] D61552: [clang] Adapt ASTMatcher to explicit(bool) specifier

2019-06-19 Thread Tyker via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL363855: [clang] Adapt ASTMatcher to explicit(bool) specifier 
(authored by Tyker, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D61552?vs=205645=205650#toc

Repository:
  rL LLVM

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

https://reviews.llvm.org/D61552

Files:
  cfe/trunk/docs/LibASTMatchersReference.html
  cfe/trunk/include/clang/AST/DeclCXX.h
  cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
  cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp
  cfe/trunk/unittests/ASTMatchers/ASTMatchersNarrowingTest.cpp
  cfe/trunk/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp

Index: cfe/trunk/docs/LibASTMatchersReference.html
===
--- cfe/trunk/docs/LibASTMatchersReference.html
+++ cfe/trunk/docs/LibASTMatchersReference.html
@@ -194,6 +194,16 @@
 
 
 
+Matcherhttps://clang.llvm.org/doxygen/classclang_1_1Decl.html;>DeclcxxDeductionGuideDeclMatcherhttps://clang.llvm.org/doxygen/classclang_1_1CXXDeductionGuideDecl.html;>CXXDeductionGuideDecl...
+Matches user-defined and implicitly generated deduction guide.
+
+Example matches the deduction guide.
+  templatetypename T
+  class X { X(int) };
+  X(int) - Xint;
+
+
+
 Matcherhttps://clang.llvm.org/doxygen/classclang_1_1Decl.html;>DeclcxxDestructorDeclMatcherhttps://clang.llvm.org/doxygen/classclang_1_1CXXDestructorDecl.html;>CXXDestructorDecl...
 Matches explicit C++ destructor declarations.
 
@@ -,18 +2232,26 @@
 
 
 Matcherhttps://clang.llvm.org/doxygen/classclang_1_1CXXConstructorDecl.html;>CXXConstructorDeclisExplicit
-Matches constructor and conversion declarations that are marked with
-the explicit keyword.
+Matches constructor, conversion function, and deduction guide declarations
+that have an explicit specifier if this explicit specifier is resolved to
+true.
 
 Given
+  templatebool b
   struct S {
 S(int); // #1
 explicit S(double); // #2
 operator int(); // #3
 explicit operator bool(); // #4
-  };
-cxxConstructorDecl(isExplicit()) will match #2, but not #1.
+explicit(false) S(bool) // # 7
+explicit(true) S(char) // # 8
+explicit(b) S(S) // # 9
+  };
+  S(int) - Strue // #5
+  explicit S(double) - Sfalse // #6
+cxxConstructorDecl(isExplicit()) will match #2 and #8, but not #1, #7 or #9.
 cxxConversionDecl(isExplicit()) will match #4, but not #3.
+cxxDeductionGuideDecl(isExplicit()) will match #6, but not #5.
 
 
 
@@ -2251,18 +2269,26 @@
 
 
 Matcherhttps://clang.llvm.org/doxygen/classclang_1_1CXXConversionDecl.html;>CXXConversionDeclisExplicit
-Matches constructor and conversion declarations that are marked with
-the explicit keyword.
+Matches constructor, conversion function, and deduction guide declarations
+that have an explicit specifier if this explicit specifier is resolved to
+true.
 
 Given
+  templatebool b
   struct S {
 S(int); // #1
 explicit S(double); // #2
 operator int(); // #3
 explicit operator bool(); // #4
-  };
-cxxConstructorDecl(isExplicit()) will match #2, but not #1.
+explicit(false) S(bool) // # 7
+explicit(true) S(char) // # 8
+explicit(b) S(S) // # 9
+  };
+  S(int) - Strue // #5
+  explicit S(double) - Sfalse // #6
+cxxConstructorDecl(isExplicit()) will match #2 and #8, but not #1, #7 or #9.
 cxxConversionDecl(isExplicit()) will match #4, but not #3.
+cxxDeductionGuideDecl(isExplicit()) will match #6, but not #5.
 
 
 
@@ -2317,6 +2343,30 @@
 
 
 
+Matcherhttps://clang.llvm.org/doxygen/classclang_1_1CXXDeductionGuideDecl.html;>CXXDeductionGuideDeclisExplicit
+Matches constructor, conversion function, and deduction guide declarations
+that have an explicit specifier if this explicit specifier is resolved to
+true.
+
+Given
+  templatebool b
+  struct S {
+S(int); // #1
+explicit S(double); // #2
+operator int(); // #3
+explicit operator bool(); // #4
+explicit(false) S(bool) // # 7
+explicit(true) S(char) // # 8
+explicit(b) S(S) // # 9
+  };
+  S(int) - Strue // #5
+  explicit S(double) - Sfalse // #6
+cxxConstructorDecl(isExplicit()) will match #2 and #8, but not #1, #7 or #9.
+cxxConversionDecl(isExplicit()) will match #4, but not #3.
+cxxDeductionGuideDecl(isExplicit()) will match #6, but not #5.
+
+
+
 Matcherhttps://clang.llvm.org/doxygen/classclang_1_1CXXDependentScopeMemberExpr.html;>CXXDependentScopeMemberExprisArrow
 Matches member expressions that are called with '-' as opposed
 to '.'.
@@ -6007,6 +6057,29 @@
 
 
 
+Matcherhttps://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html;>FunctionDeclhasExplicitSpecifierMatcherhttps://clang.llvm.org/doxygen/classclang_1_1Expr.html;>Expr InnerMatcher
+Matches the expression in an explicit specifier if present in the given
+declaration.
+
+Given
+  templatebool b
+  struct S {
+S(int); // #1
+explicit 

[PATCH] D63361: Pretend NRVO variables are references so they can be found by debug info

2019-06-19 Thread Amy Huang via Phabricator via cfe-commits
akhuang marked an inline comment as done.
akhuang added inline comments.



Comment at: clang/lib/CodeGen/CodeGenFunction.cpp:908
 --EI;
 llvm::Value *Addr = Builder.CreateStructGEP(nullptr, &*EI, Idx);
 Addr = Builder.CreateAlignedLoad(Addr, getPointerAlign(), "agg.result");

rnk wrote:
> What I had in mind was to use this GEP as the ReturnValuePointer here. The 
> inalloca parameter is also a pointer to stack memory, and a GEP is an offset, 
> so it should end up being handled like a static alloca.
Oh, ok. I changed it, but not sure how to test debug info for the inalloca case


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D63361



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


  1   2   3   >