[PATCH] D29599: Clang Changes for alloc_align

2017-02-12 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak added a comment.

Can this attribute be used on c++ template methods? Is the following code valid?

  template
  struct S {
T foo(int a)  __attribute__((alloc_align(1)));
  };


https://reviews.llvm.org/D29599



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


[PATCH] D29755: Cache FileID when translating diagnostics in PCH files

2017-02-12 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak added inline comments.



Comment at: lib/Frontend/ASTUnit.cpp:2551
   continue;
-FileID FID = SrcMgr.translateFile(FE);
+FileID FID;
+if (FE == CachedFE) {

Since FID is always equal to CachedFID, I think you can simplify this a bit by 
removing FID and using just CachedFID.


https://reviews.llvm.org/D29755



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


Re: r293199 - Turn on -Wblock-capture-autoreleasing by default.

2017-02-12 Thread Akira Hatanaka via cfe-commits
Hi Nico,

The documentation might confuse people now that the warning is on by default, 
but it’s correct as clang still qualifies indirect parameters with 
__autoreleasing. We had to add this warning and turn it on by default because a 
lot of people capture indirect parameters in their code not realizing the 
object assigned might get released by an autorelease pool.

Perhaps we can change the warning message or the documentation to make it clear 
that the parameter has been implicitly marked __autoreleasing regardless.

> On Feb 11, 2017, at 11:54 AM, Nico Weber  wrote:
> 
> Hi Akira,
> 
> this fires in internal chrome/ios code like so:
> 
> somefile.m: error: block captures an autoreleasing out-parameter, which may 
> result in use-after-free bugs [-Werror,-Wblock-capture-autoreleasing]
>   if (error) {
>   ^
> somefile.m: note: declare the parameter __autoreleasing explicitly to 
> suppress this warning
> - (NSDictionary *)fooWithError:(NSError **)error {
>   ^
>   __autoreleasing
> somefile.m: note: declare the parameter __strong or capture a __block 
> __strong variable to keep values alive across autorelease pools
> 
> 
> A colleague points out that 
> http://clang.llvm.org/docs/AutomaticReferenceCounting.html#indirect-parameters
>  
> 
>  suggests NSError ** should "be implicitly qualified with __autoreleasing." 
> Is that a bug in the implementation of the warning, is 
> AutomaticReferenceCounting.html incorrect, or are we just misunderstanding 
> that document?
> 
> Thanks,
> Nico
> 
> On Thu, Jan 26, 2017 at 1:51 PM, Akira Hatanaka via cfe-commits 
> > wrote:
> Author: ahatanak
> Date: Thu Jan 26 12:51:10 2017
> New Revision: 293199
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=293199=rev 
> 
> Log:
> Turn on -Wblock-capture-autoreleasing by default.
> 
> Turning on the warning by default helps the users as it's a common
> mistake to capture out-parameters in a block without ensuring the object
> assigned doesn't get released.
> 
> rdar://problem/30200058
> 
> Modified:
> cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> cfe/trunk/test/SemaObjC/arc.m
> 
> Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=293199=293198=293199=diff
>  
> 
> ==
> --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
> +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Thu Jan 26 12:51:10 
> 2017
> @@ -5185,7 +5185,7 @@ def err_arc_inconsistent_property_owners
>  def warn_block_capture_autoreleasing : Warning<
>"block captures an autoreleasing out-parameter, which may result in "
>"use-after-free bugs">,
> -  InGroup, DefaultIgnore;
> +  InGroup;
>  def note_declare_parameter_autoreleasing : Note<
>"declare the parameter __autoreleasing explicitly to suppress this 
> warning">;
>  def note_declare_parameter_strong : Note<
> 
> Modified: cfe/trunk/test/SemaObjC/arc.m
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaObjC/arc.m?rev=293199=293198=293199=diff
>  
> 
> ==
> --- cfe/trunk/test/SemaObjC/arc.m (original)
> +++ cfe/trunk/test/SemaObjC/arc.m Thu Jan 26 12:51:10 2017
> @@ -1,4 +1,4 @@
> -// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fobjc-runtime-has-weak 
> -fsyntax-only -fobjc-arc -fblocks -verify -Wno-objc-root-class 
> -Wblock-capture-autoreleasing %s
> +// RUN: %clang_cc1 -triple x86_64-apple-darwin11 -fobjc-runtime-has-weak 
> -fsyntax-only -fobjc-arc -fblocks -verify -Wno-objc-root-class %s
> 
>  typedef unsigned long NSUInteger;
>  typedef const void * CFTypeRef;
> 
> 
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org 
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits 
> 
> 

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


[PATCH] D28835: [coroutines] NFC: Refactor Sema::CoroutineBodyStmt construction.

2017-02-12 Thread Gor Nishanov via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
GorNishanov marked an inline comment as done.
Closed by commit rL294933: [coroutines] NFC: Refactor Sema::CoroutineBodyStmt 
construction. (authored by GorNishanov).

Changed prior to commit:
  https://reviews.llvm.org/D28835?vs=88152=88156#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D28835

Files:
  cfe/trunk/include/clang/AST/StmtCXX.h
  cfe/trunk/include/clang/Sema/ScopeInfo.h
  cfe/trunk/lib/AST/StmtCXX.cpp
  cfe/trunk/lib/Sema/SemaCoroutine.cpp
  cfe/trunk/test/SemaCXX/coroutines.cpp

Index: cfe/trunk/include/clang/Sema/ScopeInfo.h
===
--- cfe/trunk/include/clang/Sema/ScopeInfo.h
+++ cfe/trunk/include/clang/Sema/ScopeInfo.h
@@ -157,7 +157,7 @@
   SmallVector Returns;
 
   /// \brief The promise object for this coroutine, if any.
-  VarDecl *CoroutinePromise;
+  VarDecl *CoroutinePromise = nullptr;
 
   /// \brief The list of coroutine control flow constructs (co_await, co_yield,
   /// co_return) that occur within the function or block. Empty if and only if
Index: cfe/trunk/include/clang/AST/StmtCXX.h
===
--- cfe/trunk/include/clang/AST/StmtCXX.h
+++ cfe/trunk/include/clang/AST/StmtCXX.h
@@ -296,7 +296,9 @@
 /// \brief Represents the body of a coroutine. This wraps the normal function
 /// body and holds the additional semantic context required to set up and tear
 /// down the coroutine frame.
-class CoroutineBodyStmt : public Stmt {
+class CoroutineBodyStmt final
+: public Stmt,
+  private llvm::TrailingObjects {
   enum SubStmt {
 Body,  ///< The body of the coroutine.
 Promise,   ///< The promise statement.
@@ -309,52 +311,76 @@
 ReturnValue,   ///< Return value for thunk function.
 FirstParamMove ///< First offset for move construction of parameter copies.
   };
-  Stmt *SubStmts[SubStmt::FirstParamMove];
+  unsigned NumParams;
 
   friend class ASTStmtReader;
+  friend TrailingObjects;
+
+  Stmt **getStoredStmts() { return getTrailingObjects(); }
+
+  Stmt *const *getStoredStmts() const { return getTrailingObjects(); }
+
 public:
-  CoroutineBodyStmt(Stmt *Body, Stmt *Promise, Stmt *InitSuspend,
-Stmt *FinalSuspend, Stmt *OnException, Stmt *OnFallthrough,
-Expr *Allocate, Stmt *Deallocate,
-Expr *ReturnValue, ArrayRef ParamMoves)
-  : Stmt(CoroutineBodyStmtClass) {
-SubStmts[CoroutineBodyStmt::Body] = Body;
-SubStmts[CoroutineBodyStmt::Promise] = Promise;
-SubStmts[CoroutineBodyStmt::InitSuspend] = InitSuspend;
-SubStmts[CoroutineBodyStmt::FinalSuspend] = FinalSuspend;
-SubStmts[CoroutineBodyStmt::OnException] = OnException;
-SubStmts[CoroutineBodyStmt::OnFallthrough] = OnFallthrough;
-SubStmts[CoroutineBodyStmt::Allocate] = Allocate;
-SubStmts[CoroutineBodyStmt::Deallocate] = Deallocate;
-SubStmts[CoroutineBodyStmt::ReturnValue] = ReturnValue;
-// FIXME: Tail-allocate space for parameter move expressions and store them.
-assert(ParamMoves.empty() && "not implemented yet");
-  }
+
+  struct CtorArgs {
+Stmt *Body = nullptr;
+Stmt *Promise = nullptr;
+Expr *InitialSuspend = nullptr;
+Expr *FinalSuspend = nullptr;
+Stmt *OnException = nullptr;
+Stmt *OnFallthrough = nullptr;
+Expr *Allocate = nullptr;
+Expr *Deallocate = nullptr;
+Stmt *ReturnValue = nullptr;
+ArrayRef ParamMoves;
+  };
+
+private:
+
+  CoroutineBodyStmt(CtorArgs const& Args);
+
+public:
+  static CoroutineBodyStmt *Create(const ASTContext , CtorArgs const );
 
   /// \brief Retrieve the body of the coroutine as written. This will be either
   /// a CompoundStmt or a TryStmt.
   Stmt *getBody() const {
-return SubStmts[SubStmt::Body];
+return getStoredStmts()[SubStmt::Body];
   }
 
-  Stmt *getPromiseDeclStmt() const { return SubStmts[SubStmt::Promise]; }
+  Stmt *getPromiseDeclStmt() const {
+return getStoredStmts()[SubStmt::Promise];
+  }
   VarDecl *getPromiseDecl() const {
 return cast(cast(getPromiseDeclStmt())->getSingleDecl());
   }
 
-  Stmt *getInitSuspendStmt() const { return SubStmts[SubStmt::InitSuspend]; }
-  Stmt *getFinalSuspendStmt() const { return SubStmts[SubStmt::FinalSuspend]; }
+  Stmt *getInitSuspendStmt() const {
+return getStoredStmts()[SubStmt::InitSuspend];
+  }
+  Stmt *getFinalSuspendStmt() const {
+return getStoredStmts()[SubStmt::FinalSuspend];
+  }
 
-  Stmt *getExceptionHandler() const { return SubStmts[SubStmt::OnException]; }
+  Stmt *getExceptionHandler() const {
+return getStoredStmts()[SubStmt::OnException];
+  }
   Stmt *getFallthroughHandler() const {
-return SubStmts[SubStmt::OnFallthrough];
+return getStoredStmts()[SubStmt::OnFallthrough];
   }
 
-  Expr *getAllocate() const { return cast(SubStmts[SubStmt::Allocate]); }
-  

r294933 - [coroutines] NFC: Refactor Sema::CoroutineBodyStmt construction.

2017-02-12 Thread Gor Nishanov via cfe-commits
Author: gornishanov
Date: Sun Feb 12 23:05:02 2017
New Revision: 294933

URL: http://llvm.org/viewvc/llvm-project?rev=294933=rev
Log:
[coroutines] NFC: Refactor Sema::CoroutineBodyStmt construction.

Summary:
Sema::CheckCompletedCoroutineBody was growing unwieldy with building all of the 
substatements. Also, constructors for CoroutineBodyStmt had way too many 
parameters.

Instead,  CoroutineBodyStmt now defines CtorArgs structure with all of the 
required construction parameters.
CheckCompleteCoroutineBody delegates construction of individual substatements 
to short functions one per each substatement.

Also, added a drive-by fix of initializing CoroutinePromise to nullptr in 
ScopeInfo.h.
And addressed the FIXME that wanted to tail allocate extra room at the end of 
the CoroutineBodyStmt to hold parameter move expressions. (The comment was 
longer that the code that implemented tail allocation).

Reviewers: rsmith, EricWF

Subscribers: mehdi_amini, cfe-commits

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

Modified:
cfe/trunk/include/clang/AST/StmtCXX.h
cfe/trunk/include/clang/Sema/ScopeInfo.h
cfe/trunk/lib/AST/StmtCXX.cpp
cfe/trunk/lib/Sema/SemaCoroutine.cpp
cfe/trunk/test/SemaCXX/coroutines.cpp

Modified: cfe/trunk/include/clang/AST/StmtCXX.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/StmtCXX.h?rev=294933=294932=294933=diff
==
--- cfe/trunk/include/clang/AST/StmtCXX.h (original)
+++ cfe/trunk/include/clang/AST/StmtCXX.h Sun Feb 12 23:05:02 2017
@@ -296,7 +296,9 @@ public:
 /// \brief Represents the body of a coroutine. This wraps the normal function
 /// body and holds the additional semantic context required to set up and tear
 /// down the coroutine frame.
-class CoroutineBodyStmt : public Stmt {
+class CoroutineBodyStmt final
+: public Stmt,
+  private llvm::TrailingObjects {
   enum SubStmt {
 Body,  ///< The body of the coroutine.
 Promise,   ///< The promise statement.
@@ -309,52 +311,76 @@ class CoroutineBodyStmt : public Stmt {
 ReturnValue,   ///< Return value for thunk function.
 FirstParamMove ///< First offset for move construction of parameter copies.
   };
-  Stmt *SubStmts[SubStmt::FirstParamMove];
+  unsigned NumParams;
 
   friend class ASTStmtReader;
+  friend TrailingObjects;
+
+  Stmt **getStoredStmts() { return getTrailingObjects(); }
+
+  Stmt *const *getStoredStmts() const { return getTrailingObjects(); }
+
 public:
-  CoroutineBodyStmt(Stmt *Body, Stmt *Promise, Stmt *InitSuspend,
-Stmt *FinalSuspend, Stmt *OnException, Stmt *OnFallthrough,
-Expr *Allocate, Stmt *Deallocate,
-Expr *ReturnValue, ArrayRef ParamMoves)
-  : Stmt(CoroutineBodyStmtClass) {
-SubStmts[CoroutineBodyStmt::Body] = Body;
-SubStmts[CoroutineBodyStmt::Promise] = Promise;
-SubStmts[CoroutineBodyStmt::InitSuspend] = InitSuspend;
-SubStmts[CoroutineBodyStmt::FinalSuspend] = FinalSuspend;
-SubStmts[CoroutineBodyStmt::OnException] = OnException;
-SubStmts[CoroutineBodyStmt::OnFallthrough] = OnFallthrough;
-SubStmts[CoroutineBodyStmt::Allocate] = Allocate;
-SubStmts[CoroutineBodyStmt::Deallocate] = Deallocate;
-SubStmts[CoroutineBodyStmt::ReturnValue] = ReturnValue;
-// FIXME: Tail-allocate space for parameter move expressions and store 
them.
-assert(ParamMoves.empty() && "not implemented yet");
-  }
+
+  struct CtorArgs {
+Stmt *Body = nullptr;
+Stmt *Promise = nullptr;
+Expr *InitialSuspend = nullptr;
+Expr *FinalSuspend = nullptr;
+Stmt *OnException = nullptr;
+Stmt *OnFallthrough = nullptr;
+Expr *Allocate = nullptr;
+Expr *Deallocate = nullptr;
+Stmt *ReturnValue = nullptr;
+ArrayRef ParamMoves;
+  };
+
+private:
+
+  CoroutineBodyStmt(CtorArgs const& Args);
+
+public:
+  static CoroutineBodyStmt *Create(const ASTContext , CtorArgs const );
 
   /// \brief Retrieve the body of the coroutine as written. This will be either
   /// a CompoundStmt or a TryStmt.
   Stmt *getBody() const {
-return SubStmts[SubStmt::Body];
+return getStoredStmts()[SubStmt::Body];
   }
 
-  Stmt *getPromiseDeclStmt() const { return SubStmts[SubStmt::Promise]; }
+  Stmt *getPromiseDeclStmt() const {
+return getStoredStmts()[SubStmt::Promise];
+  }
   VarDecl *getPromiseDecl() const {
 return 
cast(cast(getPromiseDeclStmt())->getSingleDecl());
   }
 
-  Stmt *getInitSuspendStmt() const { return SubStmts[SubStmt::InitSuspend]; }
-  Stmt *getFinalSuspendStmt() const { return SubStmts[SubStmt::FinalSuspend]; }
+  Stmt *getInitSuspendStmt() const {
+return getStoredStmts()[SubStmt::InitSuspend];
+  }
+  Stmt *getFinalSuspendStmt() const {
+return getStoredStmts()[SubStmt::FinalSuspend];
+  }
 
-  Stmt *getExceptionHandler() const { return SubStmts[SubStmt::OnException]; }
+  

[PATCH] D28835: [coroutines] NFC: Refactor Sema::CoroutineBodyStmt construction.

2017-02-12 Thread Gor Nishanov via Phabricator via cfe-commits
GorNishanov marked an inline comment as done.
GorNishanov added a comment.

Preparing to land. Thank you very much for review!




Comment at: lib/Sema/SemaCoroutine.cpp:719
+
+  if (!PromiseRecordDecl)
+return true;

EricWF wrote:
> I figured out what's going on. `PromiseRecordDecl` doesn't get initialized to 
> null when `IsPromiseDependentType` is false. Initializing `PromiseRecordDecl` 
> fixes the problem.
Good catch!


https://reviews.llvm.org/D28835



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


[PATCH] D28835: [coroutines] NFC: Refactor Sema::CoroutineBodyStmt construction.

2017-02-12 Thread Gor Nishanov via Phabricator via cfe-commits
GorNishanov updated this revision to Diff 88152.
GorNishanov added a comment.

Initialized PromiseRecordDecl to nullptr


https://reviews.llvm.org/D28835

Files:
  include/clang/AST/StmtCXX.h
  include/clang/Sema/ScopeInfo.h
  lib/AST/StmtCXX.cpp
  lib/Sema/SemaCoroutine.cpp
  test/SemaCXX/coroutines.cpp

Index: test/SemaCXX/coroutines.cpp
===
--- test/SemaCXX/coroutines.cpp
+++ test/SemaCXX/coroutines.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -std=c++14 -fcoroutines-ts -verify %s
+// RUN: %clang_cc1 -std=c++14 -fcoroutines-ts -verify %s -fcxx-exceptions
 
 void no_coroutine_traits_bad_arg_await() {
   co_await a; // expected-error {{include }}
Index: lib/Sema/SemaCoroutine.cpp
===
--- lib/Sema/SemaCoroutine.cpp
+++ lib/Sema/SemaCoroutine.cpp
@@ -487,7 +487,7 @@
 static bool buildAllocationAndDeallocation(Sema , SourceLocation Loc,
FunctionScopeInfo *Fn,
Expr *,
-   Stmt *) {
+   Expr *) {
   TypeSourceInfo *TInfo = Fn->CoroutinePromise->getTypeSourceInfo();
   QualType PromiseType = TInfo->getType();
   if (PromiseType->isDependentType())
@@ -564,6 +564,48 @@
   return true;
 }
 
+namespace {
+class SubStmtBuilder : public CoroutineBodyStmt::CtorArgs {
+  Sema 
+  FunctionDecl 
+  FunctionScopeInfo 
+  bool IsValid;
+  SourceLocation Loc;
+  QualType RetType;
+  SmallVector ParamMovesVector;
+  const bool IsPromiseDependentType;
+  CXXRecordDecl *PromiseRecordDecl = nullptr;
+
+public:
+  SubStmtBuilder(Sema , FunctionDecl , FunctionScopeInfo , Stmt *Body)
+  : S(S), FD(FD), Fn(Fn), Loc(FD.getLocation()),
+IsPromiseDependentType(
+!Fn.CoroutinePromise ||
+Fn.CoroutinePromise->getType()->isDependentType()) {
+this->Body = Body;
+if (!IsPromiseDependentType) {
+  PromiseRecordDecl = Fn.CoroutinePromise->getType()->getAsCXXRecordDecl();
+  assert(PromiseRecordDecl && "Type should have already been checked");
+}
+this->IsValid = makePromiseStmt() && makeInitialSuspend() &&
+makeFinalSuspend() && makeOnException() &&
+makeOnFallthrough() && makeNewAndDeleteExpr() &&
+makeReturnObject() && makeParamMoves();
+  }
+
+  bool isInvalid() const { return !this->IsValid; }
+
+  bool makePromiseStmt();
+  bool makeInitialSuspend();
+  bool makeFinalSuspend();
+  bool makeNewAndDeleteExpr();
+  bool makeOnFallthrough();
+  bool makeOnException();
+  bool makeReturnObject();
+  bool makeParamMoves();
+};
+}
+
 void Sema::CheckCompletedCoroutineBody(FunctionDecl *FD, Stmt *) {
   FunctionScopeInfo *Fn = getCurFunction();
   assert(Fn && !Fn->CoroutineStmts.empty() && "not a coroutine");
@@ -577,120 +619,159 @@
 << (isa(First) ? 0 :
 isa(First) ? 1 : 2);
   }
+  SubStmtBuilder Builder(*this, *FD, *Fn, Body);
+  if (Builder.isInvalid())
+return FD->setInvalidDecl();
 
-  SourceLocation Loc = FD->getLocation();
+  // Build body for the coroutine wrapper statement.
+  Body = CoroutineBodyStmt::Create(Context, Builder);
+}
 
+bool SubStmtBuilder::makePromiseStmt() {
   // Form a declaration statement for the promise declaration, so that AST
   // visitors can more easily find it.
   StmtResult PromiseStmt =
-  ActOnDeclStmt(ConvertDeclToDeclGroup(Fn->CoroutinePromise), Loc, Loc);
+  S.ActOnDeclStmt(S.ConvertDeclToDeclGroup(Fn.CoroutinePromise), Loc, Loc);
   if (PromiseStmt.isInvalid())
-return FD->setInvalidDecl();
+return false;
+
+  this->Promise = PromiseStmt.get();
+  return true;
+}
 
+bool SubStmtBuilder::makeInitialSuspend() {
   // Form and check implicit 'co_await p.initial_suspend();' statement.
   ExprResult InitialSuspend =
-  buildPromiseCall(*this, Fn, Loc, "initial_suspend", None);
+  buildPromiseCall(S, , Loc, "initial_suspend", None);
   // FIXME: Support operator co_await here.
   if (!InitialSuspend.isInvalid())
-InitialSuspend = BuildCoawaitExpr(Loc, InitialSuspend.get());
-  InitialSuspend = ActOnFinishFullExpr(InitialSuspend.get());
+InitialSuspend = S.BuildCoawaitExpr(Loc, InitialSuspend.get());
+  InitialSuspend = S.ActOnFinishFullExpr(InitialSuspend.get());
   if (InitialSuspend.isInvalid())
-return FD->setInvalidDecl();
+return false;
+
+  this->InitialSuspend = InitialSuspend.get();
+  return true;
+}
 
+bool SubStmtBuilder::makeFinalSuspend() {
   // Form and check implicit 'co_await p.final_suspend();' statement.
   ExprResult FinalSuspend =
-  buildPromiseCall(*this, Fn, Loc, "final_suspend", None);
+  buildPromiseCall(S, , Loc, "final_suspend", None);
   // FIXME: Support operator co_await here.
   if (!FinalSuspend.isInvalid())
-FinalSuspend = BuildCoawaitExpr(Loc, FinalSuspend.get());
-  FinalSuspend = 

[PATCH] D28835: [coroutines] NFC: Refactor Sema::CoroutineBodyStmt construction.

2017-02-12 Thread Gor Nishanov via Phabricator via cfe-commits
GorNishanov updated this revision to Diff 88151.
GorNishanov added a comment.

Initialized member variable to zero.


https://reviews.llvm.org/D28835

Files:
  include/clang/AST/StmtCXX.h
  include/clang/Sema/ScopeInfo.h
  lib/AST/StmtCXX.cpp
  lib/Sema/SemaCoroutine.cpp
  test/SemaCXX/coroutines.cpp

Index: test/SemaCXX/coroutines.cpp
===
--- test/SemaCXX/coroutines.cpp
+++ test/SemaCXX/coroutines.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -std=c++14 -fcoroutines-ts -verify %s
+// RUN: %clang_cc1 -std=c++14 -fcoroutines-ts -verify %s -fcxx-exceptions
 
 void no_coroutine_traits_bad_arg_await() {
   co_await a; // expected-error {{include }}
Index: lib/Sema/SemaCoroutine.cpp
===
--- lib/Sema/SemaCoroutine.cpp
+++ lib/Sema/SemaCoroutine.cpp
@@ -487,7 +487,7 @@
 static bool buildAllocationAndDeallocation(Sema , SourceLocation Loc,
FunctionScopeInfo *Fn,
Expr *,
-   Stmt *) {
+   Expr *) {
   TypeSourceInfo *TInfo = Fn->CoroutinePromise->getTypeSourceInfo();
   QualType PromiseType = TInfo->getType();
   if (PromiseType->isDependentType())
@@ -564,6 +564,48 @@
   return true;
 }
 
+namespace {
+class SubStmtBuilder : public CoroutineBodyStmt::CtorArgs {
+  Sema 
+  FunctionDecl 
+  FunctionScopeInfo 
+  bool IsValid;
+  SourceLocation Loc;
+  QualType RetType;
+  SmallVector ParamMovesVector;
+  const bool IsPromiseDependentType;
+  CXXRecordDecl *PromiseRecordDecl;
+
+public:
+  SubStmtBuilder(Sema , FunctionDecl , FunctionScopeInfo , Stmt *Body)
+  : S(S), FD(FD), Fn(Fn), Loc(FD.getLocation()),
+IsPromiseDependentType(
+!Fn.CoroutinePromise ||
+Fn.CoroutinePromise->getType()->isDependentType()) {
+this->Body = Body;
+if (!IsPromiseDependentType) {
+  PromiseRecordDecl = Fn.CoroutinePromise->getType()->getAsCXXRecordDecl();
+  assert(PromiseRecordDecl && "Type should have already been checked");
+}
+this->IsValid = makePromiseStmt() && makeInitialSuspend() &&
+makeFinalSuspend() && makeOnException() &&
+makeOnFallthrough() && makeNewAndDeleteExpr() &&
+makeReturnObject() && makeParamMoves();
+  }
+
+  bool isInvalid() const { return !this->IsValid; }  
+
+  bool makePromiseStmt();
+  bool makeInitialSuspend();
+  bool makeFinalSuspend();
+  bool makeNewAndDeleteExpr();
+  bool makeOnFallthrough();
+  bool makeOnException();
+  bool makeReturnObject();
+  bool makeParamMoves();
+};
+}
+
 void Sema::CheckCompletedCoroutineBody(FunctionDecl *FD, Stmt *) {
   FunctionScopeInfo *Fn = getCurFunction();
   assert(Fn && !Fn->CoroutineStmts.empty() && "not a coroutine");
@@ -577,120 +619,159 @@
 << (isa(First) ? 0 :
 isa(First) ? 1 : 2);
   }
+  SubStmtBuilder Builder(*this, *FD, *Fn, Body);
+  if (Builder.isInvalid())
+return FD->setInvalidDecl();
 
-  SourceLocation Loc = FD->getLocation();
+  // Build body for the coroutine wrapper statement.
+  Body = CoroutineBodyStmt::Create(Context, Builder);
+}
 
+bool SubStmtBuilder::makePromiseStmt() {
   // Form a declaration statement for the promise declaration, so that AST
   // visitors can more easily find it.
   StmtResult PromiseStmt =
-  ActOnDeclStmt(ConvertDeclToDeclGroup(Fn->CoroutinePromise), Loc, Loc);
+  S.ActOnDeclStmt(S.ConvertDeclToDeclGroup(Fn.CoroutinePromise), Loc, Loc);
   if (PromiseStmt.isInvalid())
-return FD->setInvalidDecl();
+return false;
+
+  this->Promise = PromiseStmt.get();
+  return true;
+}
 
+bool SubStmtBuilder::makeInitialSuspend() {
   // Form and check implicit 'co_await p.initial_suspend();' statement.
   ExprResult InitialSuspend =
-  buildPromiseCall(*this, Fn, Loc, "initial_suspend", None);
+  buildPromiseCall(S, , Loc, "initial_suspend", None);
   // FIXME: Support operator co_await here.
   if (!InitialSuspend.isInvalid())
-InitialSuspend = BuildCoawaitExpr(Loc, InitialSuspend.get());
-  InitialSuspend = ActOnFinishFullExpr(InitialSuspend.get());
+InitialSuspend = S.BuildCoawaitExpr(Loc, InitialSuspend.get());
+  InitialSuspend = S.ActOnFinishFullExpr(InitialSuspend.get());
   if (InitialSuspend.isInvalid())
-return FD->setInvalidDecl();
+return false;
+
+  this->InitialSuspend = InitialSuspend.get();
+  return true;
+}
 
+bool SubStmtBuilder::makeFinalSuspend() {
   // Form and check implicit 'co_await p.final_suspend();' statement.
   ExprResult FinalSuspend =
-  buildPromiseCall(*this, Fn, Loc, "final_suspend", None);
+  buildPromiseCall(S, , Loc, "final_suspend", None);
   // FIXME: Support operator co_await here.
   if (!FinalSuspend.isInvalid())
-FinalSuspend = BuildCoawaitExpr(Loc, FinalSuspend.get());
-  FinalSuspend = 

[PATCH] D29839: [clang-tidy] New misc-istream-overflow check

2017-02-12 Thread Kostya Kortchinsky via Phabricator via cfe-commits
cryptoad added a comment.

So if I understand correctly, the consensus is to abandon this and rewrite it 
to be part of the clang static analyzer?


https://reviews.llvm.org/D29839



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


[PATCH] D29879: [OpenMP] Teams reduction on the NVPTX device.

2017-02-12 Thread Arpith Jacob via Phabricator via cfe-commits
arpith-jacob created this revision.
Herald added a subscriber: jholewinski.

This patch implements codegen for the reduction clause on
any teams construct for elementary data types.  It builds
on parallel reductions on the GPU.  Subsequently,
the team master writes to a unique location in a global
memory scratchpad.  The last team to do so loads and
reduces this array to calculate the final result.

This patch emits two helper functions that are used by
the OpenMP runtime on the GPU to perform reductions across
teams.

Patch by Tian Jin in collaboration with Arpith Jacob


https://reviews.llvm.org/D29879

Files:
  lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
  lib/CodeGen/CGStmtOpenMP.cpp
  test/OpenMP/nvptx_teams_reduction_codegen.cpp

Index: test/OpenMP/nvptx_teams_reduction_codegen.cpp
===
--- /dev/null
+++ test/OpenMP/nvptx_teams_reduction_codegen.cpp
@@ -0,0 +1,1131 @@
+// Test target codegen - host bc file has to be created first.
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm-bc %s -o %t-ppc-host.bc
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple nvptx64-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - | FileCheck %s --check-prefix CHECK --check-prefix CHECK-64
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple i386-unknown-unknown -fopenmp-targets=nvptx-nvidia-cuda -emit-llvm-bc %s -o %t-x86-host.bc
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple nvptx-unknown-unknown -fopenmp-targets=nvptx-nvidia-cuda -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-x86-host.bc -o - | FileCheck %s --check-prefix CHECK --check-prefix CHECK-32
+// RUN: %clang_cc1 -verify -fopenmp -fexceptions -fcxx-exceptions -x c++ -triple nvptx-unknown-unknown -fopenmp-targets=nvptx-nvidia-cuda -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-x86-host.bc -o - | FileCheck %s --check-prefix CHECK --check-prefix CHECK-32
+// expected-no-diagnostics
+#ifndef HEADER
+#define HEADER
+
+// Check for the data transfer medium in shared memory to transfer the reduction list to the first warp.
+// CHECK-DAG: [[TRANSFER_STORAGE:@.+]] = common addrspace([[SHARED_ADDRSPACE:[0-9]+]]) global [32 x i64]
+
+// Check that the execution mode of all 3 target regions is set to Generic Mode.
+// CHECK-DAG: {{@__omp_offloading_.+l27}}_exec_mode = weak constant i8 1
+// CHECK-DAG: {{@__omp_offloading_.+l33}}_exec_mode = weak constant i8 1
+// CHECK-DAG: {{@__omp_offloading_.+l40}}_exec_mode = weak constant i8 1
+
+template
+tx ftemplate(int n) {
+  int a;
+  short b;
+  tx c;
+  float d;
+  double e;
+
+  #pragma omp target
+  #pragma omp teams reduction(+: e)
+  {
+e += 5;
+  }
+
+  #pragma omp target
+  #pragma omp teams reduction(^: c) reduction(*: d)
+  {
+c ^= 2;
+d *= 33;
+  }
+
+  #pragma omp target
+  #pragma omp teams reduction(|: a) reduction(max: b)
+  {
+a |= 1;
+b = 99 > b ? 99 : b;
+  }
+
+  return a+b+c+d+e;
+}
+
+int bar(int n){
+  int a = 0;
+
+  a += ftemplate(n);
+
+  return a;
+}
+
+  // CHECK-LABEL: define {{.*}}void {{@__omp_offloading_.+template.+l27}}_worker()
+
+  // CHECK: define {{.*}}void [[T1:@__omp_offloading_.+template.+l27]](
+  //
+  // CHECK: {{call|invoke}} void [[T1]]_worker()
+  //
+  // CHECK: call void @__kmpc_kernel_init(
+  //
+  // CHECK: store double {{[0\.e\+]+}}, double* [[E:%.+]], align
+  // CHECK: [[EV:%.+]] = load double, double* [[E]], align
+  // CHECK: [[ADD:%.+]] = fadd double [[EV]], 5
+  // CHECK: store double [[ADD]], double* [[E]], align
+  // CHECK: [[PTR1:%.+]] = getelementptr inbounds [[RLT:.+]], [1 x i8*]* [[RL:%.+]], i{{32|64}} 0, i{{32|64}} 0
+  // CHECK: [[E_CAST:%.+]] = bitcast double* [[E]] to i8*
+  // CHECK: store i8* [[E_CAST]], i8** [[PTR1]], align
+  // CHECK: [[ARG_RL:%.+]] = bitcast [[RLT]]* [[RL]] to i8*
+  // CHECK: [[RET:%.+]] = call i32 @__kmpc_nvptx_teams_reduce_nowait(i32 {{.+}}, i32 1, i{{32|64}} {{4|8}}, i8* [[ARG_RL]], void (i8*, i16, i16, i16)* [[SHUFFLE_REDUCE_FN:@.+]], void (i8*, i32)* [[WARP_COPY_FN:@.+]], void (i8*, i8*, i32, i32)* [[SCRATCH_COPY_FN:@.+]], void (i8*, i8*, i32, i32, i32)* [[LOAD_REDUCE_FN:@.+]])
+  // CHECK: [[COND:%.+]] = icmp eq i32 [[RET]], 1
+  // CHECK: br i1 [[COND]], label {{%?}}[[IFLABEL:.+]], label {{%?}}[[EXIT:.+]]
+  //
+  // CHECK: [[IFLABEL]]
+  // CHECK: [[E_INV:%.+]] = load double, double* [[E_IN:%.+]], align
+  // CHECK: [[EV:%.+]] = load double, double* [[E]], align
+  // CHECK: [[ADD:%.+]] = fadd double [[E_INV]], [[EV]]
+  // CHECK: store double [[ADD]], double* [[E_IN]], align
+  // CHECK: call void @__kmpc_nvptx_end_reduce_nowait(
+  // CHECK: br label %[[EXIT]]
+  //
+  // CHECK: [[EXIT]]
+  // CHECK: call void @__kmpc_kernel_deinit()
+
+  //
+  // Reduction function
+  // CHECK: define internal void [[REDUCTION_FUNC:@.+]](i8*, i8*)
+  // CHECK: 

[PATCH] D29758: [OpenMP] Parallel reduction on the NVPTX device.

2017-02-12 Thread Arpith Jacob via Phabricator via cfe-commits
arpith-jacob updated this revision to Diff 88149.
arpith-jacob added a comment.

Minor fixup of comment style on emitInterWarpCopyFunction().


https://reviews.llvm.org/D29758

Files:
  lib/CodeGen/CGOpenMPRuntime.cpp
  lib/CodeGen/CGOpenMPRuntime.h
  lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
  lib/CodeGen/CGOpenMPRuntimeNVPTX.h
  lib/CodeGen/CGStmtOpenMP.cpp
  lib/CodeGen/CodeGenFunction.h
  test/OpenMP/nvptx_target_parallel_reduction_codegen.cpp

Index: test/OpenMP/nvptx_target_parallel_reduction_codegen.cpp
===
--- /dev/null
+++ test/OpenMP/nvptx_target_parallel_reduction_codegen.cpp
@@ -0,0 +1,830 @@
+// Test target codegen - host bc file has to be created first.
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm-bc %s -o %t-ppc-host.bc
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple nvptx64-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - | FileCheck %s --check-prefix CHECK --check-prefix CHECK-64
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple i386-unknown-unknown -fopenmp-targets=nvptx-nvidia-cuda -emit-llvm-bc %s -o %t-x86-host.bc
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple nvptx-unknown-unknown -fopenmp-targets=nvptx-nvidia-cuda -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-x86-host.bc -o - | FileCheck %s --check-prefix CHECK --check-prefix CHECK-32
+// RUN: %clang_cc1 -verify -fopenmp -fexceptions -fcxx-exceptions -x c++ -triple nvptx-unknown-unknown -fopenmp-targets=nvptx-nvidia-cuda -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-x86-host.bc -o - | FileCheck %s --check-prefix CHECK --check-prefix CHECK-32
+// expected-no-diagnostics
+#ifndef HEADER
+#define HEADER
+
+// Check for the data transfer medium in shared memory to transfer the reduction list to the first warp.
+// CHECK-DAG: [[TRANSFER_STORAGE:@.+]] = common addrspace([[SHARED_ADDRSPACE:[0-9]+]]) global [32 x i64]
+
+// Check that the execution mode of all 3 target regions is set to Spmd Mode.
+// CHECK-DAG: {{@__omp_offloading_.+l27}}_exec_mode = weak constant i8 0
+// CHECK-DAG: {{@__omp_offloading_.+l32}}_exec_mode = weak constant i8 0
+// CHECK-DAG: {{@__omp_offloading_.+l38}}_exec_mode = weak constant i8 0
+
+template
+tx ftemplate(int n) {
+  int a;
+  short b;
+  tx c;
+  float d;
+  double e;
+
+  #pragma omp target parallel reduction(+: e) map(tofrom: e)
+  {
+e += 5;
+  }
+
+  #pragma omp target parallel reduction(^: c) reduction(*: d) map(tofrom: c,d)
+  {
+c ^= 2;
+d *= 33;
+  }
+
+  #pragma omp target parallel reduction(|: a) reduction(max: b) map(tofrom: a,b)
+  {
+a |= 1;
+b = 99 > b ? 99 : b;
+  }
+
+  return a+b+c+d+e;
+}
+
+int bar(int n){
+  int a = 0;
+
+  a += ftemplate(n);
+
+  return a;
+}
+
+  // CHECK: define {{.*}}void {{@__omp_offloading_.+template.+l27}}(
+  //
+  // CHECK: call void @__kmpc_spmd_kernel_init(
+  // CHECK: br label {{%?}}[[EXECUTE:.+]]
+  //
+  // CHECK: [[EXECUTE]]
+  // CHECK: {{call|invoke}} void [[PFN:@.+]](i32*
+  // CHECK: call void @__kmpc_spmd_kernel_deinit()
+  //
+  //
+  // define internal void [[PFN]](
+  // CHECK: store double {{[0\.e\+]+}}, double* [[E:%.+]], align
+  // CHECK: [[EV:%.+]] = load double, double* [[E]], align
+  // CHECK: [[ADD:%.+]] = fadd double [[EV]], 5
+  // CHECK: store double [[ADD]], double* [[E]], align
+  // CHECK: [[PTR1:%.+]] = getelementptr inbounds [[RLT:.+]], [1 x i8*]* [[RL:%.+]], i{{32|64}} 0, i{{32|64}} 0
+  // CHECK: [[E_CAST:%.+]] = bitcast double* [[E]] to i8*
+  // CHECK: store i8* [[E_CAST]], i8** [[PTR1]], align
+  // CHECK: [[ARG_RL:%.+]] = bitcast [[RLT]]* [[RL]] to i8*
+  // CHECK: [[RET:%.+]] = call i32 @__kmpc_nvptx_parallel_reduce_nowait(i32 {{.+}}, i32 1, i{{32|64}} {{4|8}}, i8* [[ARG_RL]], void (i8*, i16, i16, i16)* [[SHUFFLE_REDUCE_FN:@.+]], void (i8*, i32)* [[WARP_COPY_FN:@.+]])
+  // CHECK: switch i32 [[RET]], label {{%?}}[[DEFAULTLABEL:.+]] [
+  // CHECK: i32 1, label {{%?}}[[REDLABEL:.+]]
+
+  // CHECK: [[REDLABEL]]
+  // CHECK: [[E_INV:%.+]] = load double, double* [[E_IN:%.+]], align
+  // CHECK: [[EV:%.+]] = load double, double* [[E]], align
+  // CHECK: [[ADD:%.+]] = fadd double [[E_INV]], [[EV]]
+  // CHECK: store double [[ADD]], double* [[E_IN]], align
+  // CHECK: call void @__kmpc_nvptx_end_reduce_nowait(
+  // CHECK: br label %[[DEFAULTLABEL]]
+  //
+  // CHECK: [[DEFAULTLABEL]]
+  // CHECK: ret
+
+  //
+  // Reduction function
+  // CHECK: define internal void [[REDUCTION_FUNC:@.+]](i8*, i8*)
+  // CHECK: [[VAR_RHS_REF:%.+]] = getelementptr inbounds [[RLT]], [[RLT]]* [[RED_LIST_RHS:%.+]], i{{32|64}} 0, i{{32|64}} 0
+  // CHECK: [[VAR_RHS_VOID:%.+]] = load i8*, i8** [[VAR_RHS_REF]],
+  // CHECK: [[VAR_RHS:%.+]] = bitcast i8* [[VAR_RHS_VOID]] to double*
+  //
+  // CHECK: [[VAR_LHS_REF:%.+]] = getelementptr inbounds [[RLT]], [[RLT]]* 

[PATCH] D28952: [analyzer] Add new Z3 constraint manager backend

2017-02-12 Thread Devin Coughlin via Phabricator via cfe-commits
dcoughlin added a comment.

Thanks for updating the tests to be able to run both the z3 and 
range-constraint managers! I think this will make it much easier to ensure the 
z3-backed manager continues to work as as expected moving forward. I suggested 
an alternative approach inline to running the tests under both managers, which 
you may wish to consider.

In https://reviews.llvm.org/D28952#669963, @ddcc wrote:

> I added support for a callback field in lit's configuration (see 
> https://reviews.llvm.org/D29684), which is used to execute each testcase for 
> each supported constraint solver backends at runtime. I believe this resolves 
> all remaining issues, except for the remaining two testcase failures:
>
> 1. The testcase Analysis/reference.cpp currently fails, because the 
> RangeConstraintManager has an internal optimization that assumes references 
> are known to be non-zero (see RangeConstraintManager.cpp:422). This 
> optimization is probably in the wrong place, and should be moved into the 
> analyzer and out of the constraint solver. Unless anyone objects, I plan to 
> modify this testcase so that this result is fine for the z3 solver backend.


This sounds reasonable to me.

> 1. The testcase Analysis/ptr-arith.c currently fails, because handling of 
> ptrdiff_t is somewhat tricky. This constraint manager interface maps 
> ptrdiff_t to a signed bitvector in Z3, and pointers to unsigned bitvectors in 
> Z3. However, since this testcase compares the pointer values both directly 
> and indirectly via ptrdiff_t, if a < b is true using a signed comparison, the 
> same is not necessarily true using an unsigned comparison. Likewise, unless 
> anyone objects, I plan to whitelist this result for the z3 solver backend.

I think in both cases whitelisting is the right thing to do -- just provide a 
comment in the test explaining why. If you have a sense of the right way to fix 
the problem, please add a // FIXME: in the test with a short description.

There are some minor comments inline. Also: It is important to make sure the 
build still works and the tests still pass even both when Z3 is not present and 
when it is not enabled.




Comment at: CMakeLists.txt:371
 
+option(CLANG_BUILD_Z3
+  "Build the static analyzer with the Z3 constraint manager." OFF)

I think it would be good to change the name of this setting to have the prefix 
"CLANG_ANALYZER_...". This will help make it clear in, for example, the ccmake 
interface, that the option is only relevant to the analyzer.



Comment at: lib/StaticAnalyzer/Core/CMakeLists.txt:62
+  ${Z3_LINK_FILES}
   )

This needs something like:
```
if(CLANG_BUILD_Z3 AND CLANG_HAVE_Z3)
  target_include_directories(clangStaticAnalyzerCore SYSTEM
  PRIVATE
  ${Z3_INCLUDE_DIR}
  )
endif()
```
so that the analyzer core can find the Z3 headers when they are installed 
outside of the usual system include paths.



Comment at: lib/StaticAnalyzer/Core/Z3ConstraintManager.cpp:17
+
+#if defined(CLANG_BUILD_Z3) && defined(CLANG_HAVE_Z3)
+

Is it possible to expose only one Z3-related definition here? Does the C++ need 
to understand the distinction between CLANG_HAVE_Z3 and CLANG_BUILD_Z3?

Could the CMake expose one master build setting that is true when other two are 
both true?



Comment at: lib/StaticAnalyzer/Core/Z3ConstraintManager.cpp:21
+
+using namespace clang;
+using namespace ento;

These 'using' declarations need to be moved outside the #if -- otherwise there 
is a compile error at the definition of CreateZ3ConstraintManager() when 
building without Z3.



Comment at: test/Analysis/lit.local.cfg:2
+import lit.TestRunner
+
+def callback(test, cmd):

Here is a suggestion that would avoid needing to block changes to 'lit' itself.

lit allows you to create different a different Test subclass in each test 
directory. You could create a custom subclass just for analyzer tests (we 
already do this for unit tests):

```
class AnalyzerTest(lit.formats.ShTest, object):

def execute(self, test, litConfig):
result = self.executeWithAnalyzeSubstitution(test, litConfig, 
'-analyzer-constraints=range')

if result.code == lit.Test.FAIL:
return result
  
if test.config.build_z3 == 'ON' and test.config.have_z3 == '1':
result = self.executeWithAnalyzeSubstitution(test, litConfig, 
'-analyzer-constraints=z3 -DANALYZER_CM_Z3')

return result

def executeWithAnalyzeSubstitution(self, test, litConfig, substitution):
saved_substitutions = list(test.config.substitutions)
test.config.substitutions.append(('%analyze', substitution))
result = lit.TestRunner.executeShTest(test, litConfig, 
self.execute_external)
test.config.substitutions = saved_substitutions

return result


config.test_format = 

[PATCH] D29839: [clang-tidy] New misc-istream-overflow check

2017-02-12 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh requested changes to this revision.
alexfh added a comment.
This revision now requires changes to proceed.

In https://reviews.llvm.org/D29839#674517, @aaron.ballman wrote:

> In https://reviews.llvm.org/D29839#674301, @xazax.hun wrote:
>
> > Shouldn't this be a path sensitive check within the clang static analyzer 
> > instead? So branches are properly handled and interprocedural analysis is 
> > done.
>
>
> I agree; I think this check should be part of the static analyzer because it 
> is path sensitive if we want it to be particularly useful. As it stands now, 
> it will catch trivial bugs, but by designing it as a clang-tidy check, it 
> isn't easily extensible to catch the bigger bugs across procedures.


I totally agree with Aaron and Gabor. This analysis can't be properly 
implemented without path sensitivity and I can imagine many valid situations 
where it will be too noisy (custom functions or stream manipulators that hide 
width setting, for example). Clang-tidy has a bunch of lint-style analyses, but 
when there is a more appropriate technology to implement a certain analysis, it 
should be preferred. It's all trade-offs, but here path sensitive analysis 
seems to be a much better tool for the job.


https://reviews.llvm.org/D29839



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


[PATCH] D29868: Recover more gracefully when __declspec is not supported as a keyword

2017-02-12 Thread Saleem Abdulrasool via Phabricator via cfe-commits
compnerd added inline comments.



Comment at: lib/Parse/ParseDecl.cpp:2989
+
+  Diag(Loc, diag::err_ms_attributes_not_enabled);
+  continue;

aaron.ballman wrote:
> compnerd wrote:
> > I think that we want to emit the diagnostic even if there is no parenthesis 
> > as `__declspec` is a reserved identifier, and we would normally diagnose 
> > the bad `__declspec` (expected '(' after '__declspec').
> Yes, but it could also lead to a rejecting code that we used to accept and 
> properly handle when __declspec is an identifier rather than a keyword. e.g.,
> ```
> struct __declspec {};
> 
> __declspec some_func(void);
> ```
> By looking for the paren, we run less risk of breaking working code, even if 
> that code abuses the implementation namespace (after all, __declspec it not a 
> keyword in this scenario).
But we would reject that code under `-fdeclspec` anyways.  I think having the 
code be more portable is a bit nicer.


https://reviews.llvm.org/D29868



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


[libcxx] r294917 - test: use char32_t rather than wchar_t

2017-02-12 Thread Saleem Abdulrasool via cfe-commits
Author: compnerd
Date: Sun Feb 12 15:42:35 2017
New Revision: 294917

URL: http://llvm.org/viewvc/llvm-project?rev=294917=rev
Log:
test: use char32_t rather than wchar_t

wchar_t is not as portable as char32_t.  On Windows, wchar_t is
16-bytes and on Linux 32-bits.  The conversion to utf8 causes the
characters to exceed the limits on char16_t, resulting in tautological
comparisons.

Modified:
libcxx/trunk/test/std/localization/locale.stdcvt/codecvt_utf16_in.pass.cpp
libcxx/trunk/test/std/localization/locale.stdcvt/codecvt_utf8_in.pass.cpp

Modified: 
libcxx/trunk/test/std/localization/locale.stdcvt/codecvt_utf16_in.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/localization/locale.stdcvt/codecvt_utf16_in.pass.cpp?rev=294917=294916=294917=diff
==
--- libcxx/trunk/test/std/localization/locale.stdcvt/codecvt_utf16_in.pass.cpp 
(original)
+++ libcxx/trunk/test/std/localization/locale.stdcvt/codecvt_utf16_in.pass.cpp 
Sun Feb 12 15:42:35 2017
@@ -28,11 +28,11 @@
 int main()
 {
 {
-typedef std::codecvt_utf16 C;
+typedef std::codecvt_utf16 C;
 C c;
-wchar_t w = 0;
+char32_t w = 0;
 char n[4] = {char(0xD8), char(0xC0), char(0xDC), char(0x03)};
-wchar_t* wp = nullptr;
+char32_t* wp = nullptr;
 std::mbstate_t m;
 const char* np = nullptr;
 std::codecvt_base::result r = c.in(m, n, n+4, np, , +1, wp);
@@ -67,11 +67,11 @@ int main()
 assert(w == 0x56);
 }
 {
-typedef std::codecvt_utf16 C;
+typedef std::codecvt_utf16 C;
 C c;
-wchar_t w = 0;
+char32_t w = 0;
 char n[4] = {char(0xD8), char(0xC0), char(0xDC), char(0x03)};
-wchar_t* wp = nullptr;
+char32_t* wp = nullptr;
 std::mbstate_t m;
 const char* np = nullptr;
 std::codecvt_base::result r = c.in(m, n, n+4, np, , +1, wp);
@@ -106,11 +106,11 @@ int main()
 assert(w == 0x56);
 }
 {
-typedef std::codecvt_utf16 C;
+typedef std::codecvt_utf16 C;
 C c;
-wchar_t w = 0;
+char32_t w = 0;
 char n[6] = {char(0xFE), char(0xFF), char(0xD8), char(0xC0), 
char(0xDC), char(0x03)};
-wchar_t* wp = nullptr;
+char32_t* wp = nullptr;
 std::mbstate_t m;
 const char* np = nullptr;
 std::codecvt_base::result r = c.in(m, n, n+6, np, , +1, wp);
@@ -145,11 +145,11 @@ int main()
 assert(w == 0x56);
 }
 {
-typedef std::codecvt_utf16 C;
+typedef std::codecvt_utf16 C;
 C c;
-wchar_t w = 0;
+char32_t w = 0;
 char n[4] = {char(0xC0), char(0xD8), char(0x03), char(0xDC)};
-wchar_t* wp = nullptr;
+char32_t* wp = nullptr;
 std::mbstate_t m;
 const char* np = nullptr;
 std::codecvt_base::result r = c.in(m, n, n+4, np, , +1, wp);
@@ -184,11 +184,11 @@ int main()
 assert(w == 0x56);
 }
 {
-typedef std::codecvt_utf16 C;
+typedef std::codecvt_utf16 C;
 C c;
-wchar_t w = 0;
+char32_t w = 0;
 char n[4] = {char(0xC0), char(0xD8), char(0x03), char(0xDC)};
-wchar_t* wp = nullptr;
+char32_t* wp = nullptr;
 std::mbstate_t m;
 const char* np = nullptr;
 std::codecvt_base::result r = c.in(m, n, n+4, np, , +1, wp);
@@ -223,13 +223,13 @@ int main()
 assert(w == 0x56);
 }
 {
-typedef std::codecvt_utf16 
C;
+typedef std::codecvt_utf16 C;
+
 C c;
-wchar_t w = 0;
+char32_t w = 0;
 char n[6] = {char(0xFF), char(0xFE), char(0xC0), char(0xD8), 
char(0x03), char(0xDC)};
-wchar_t* wp = nullptr;
+char32_t* wp = nullptr;
 std::mbstate_t m;
 const char* np = nullptr;
 std::codecvt_base::result r = c.in(m, n, n+6, np, , +1, wp);

Modified: 
libcxx/trunk/test/std/localization/locale.stdcvt/codecvt_utf8_in.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/localization/locale.stdcvt/codecvt_utf8_in.pass.cpp?rev=294917=294916=294917=diff
==
--- libcxx/trunk/test/std/localization/locale.stdcvt/codecvt_utf8_in.pass.cpp 
(original)
+++ 

[libcxx] r294918 - math: follow up to SVN r294902

2017-02-12 Thread Saleem Abdulrasool via cfe-commits
Author: compnerd
Date: Sun Feb 12 15:42:37 2017
New Revision: 294918

URL: http://llvm.org/viewvc/llvm-project?rev=294918=rev
Log:
math: follow up to SVN r294902

Pull in the math functions from ucrt 14+ after auditing the library.  It
seems that they are now complete for C99 math.  Fixes more windows
tests!

Modified:
libcxx/trunk/include/math.h

Modified: libcxx/trunk/include/math.h
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/math.h?rev=294918=294917=294918=diff
==
--- libcxx/trunk/include/math.h (original)
+++ libcxx/trunk/include/math.h Sun Feb 12 15:42:37 2017
@@ -650,7 +650,7 @@ abs(long double __lcpp_x) _NOEXCEPT {ret
 
 // acos
 
-#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX) || defined(__sun__))
+#if !((defined(_LIBCPP_MSVCRT) && (_VC_CRT_MAJOR_VERSION-0) < 14) || 
defined(_AIX) || defined(__sun__))
 inline _LIBCPP_INLINE_VISIBILITY float   acos(float __lcpp_x) _NOEXCEPT
   {return ::acosf(__lcpp_x);}
 inline _LIBCPP_INLINE_VISIBILITY long double acos(long double __lcpp_x) 
_NOEXCEPT {return ::acosl(__lcpp_x);}
 #endif
@@ -662,7 +662,7 @@ acos(_A1 __lcpp_x) _NOEXCEPT {return ::a
 
 // asin
 
-#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX) || defined(__sun__))
+#if !((defined(_LIBCPP_MSVCRT) && (_VC_CRT_MAJOR_VERSION-0) < 14) || 
defined(_AIX) || defined(__sun__))
 inline _LIBCPP_INLINE_VISIBILITY float   asin(float __lcpp_x) _NOEXCEPT
   {return ::asinf(__lcpp_x);}
 inline _LIBCPP_INLINE_VISIBILITY long double asin(long double __lcpp_x) 
_NOEXCEPT {return ::asinl(__lcpp_x);}
 #endif
@@ -674,7 +674,7 @@ asin(_A1 __lcpp_x) _NOEXCEPT {return ::a
 
 // atan
 
-#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX) || defined(__sun__))
+#if !((defined(_LIBCPP_MSVCRT) && (_VC_CRT_MAJOR_VERSION-0) < 14) || 
defined(_AIX) || defined(__sun__))
 inline _LIBCPP_INLINE_VISIBILITY float   atan(float __lcpp_x) _NOEXCEPT
   {return ::atanf(__lcpp_x);}
 inline _LIBCPP_INLINE_VISIBILITY long double atan(long double __lcpp_x) 
_NOEXCEPT {return ::atanl(__lcpp_x);}
 #endif
@@ -686,7 +686,7 @@ atan(_A1 __lcpp_x) _NOEXCEPT {return ::a
 
 // atan2
 
-#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX) || defined(__sun__))
+#if !((defined(_LIBCPP_MSVCRT) && (_VC_CRT_MAJOR_VERSION-0) < 14) || 
defined(_AIX) || defined(__sun__))
 inline _LIBCPP_INLINE_VISIBILITY float   atan2(float __lcpp_y, float 
__lcpp_x) _NOEXCEPT {return ::atan2f(__lcpp_y, __lcpp_x);}
 inline _LIBCPP_INLINE_VISIBILITY long double atan2(long double __lcpp_y, long 
double __lcpp_x) _NOEXCEPT {return ::atan2l(__lcpp_y, __lcpp_x);}
 #endif
@@ -709,7 +709,7 @@ atan2(_A1 __lcpp_y, _A2 __lcpp_x) _NOEXC
 
 // ceil
 
-#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX) || defined(__sun__))
+#if !((defined(_LIBCPP_MSVCRT) && (_VC_CRT_MAJOR_VERSION-0) < 14) || 
defined(_AIX) || defined(__sun__))
 inline _LIBCPP_INLINE_VISIBILITY float   ceil(float __lcpp_x) _NOEXCEPT
   {return ::ceilf(__lcpp_x);}
 inline _LIBCPP_INLINE_VISIBILITY long double ceil(long double __lcpp_x) 
_NOEXCEPT {return ::ceill(__lcpp_x);}
 #endif
@@ -721,7 +721,7 @@ ceil(_A1 __lcpp_x) _NOEXCEPT {return ::c
 
 // cos
 
-#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX) || defined(__sun__))
+#if !((defined(_LIBCPP_MSVCRT) && (_VC_CRT_MAJOR_VERSION-0) < 14) || 
defined(_AIX) || defined(__sun__))
 inline _LIBCPP_INLINE_VISIBILITY float   cos(float __lcpp_x) _NOEXCEPT 
  {return ::cosf(__lcpp_x);}
 inline _LIBCPP_INLINE_VISIBILITY long double cos(long double __lcpp_x) 
_NOEXCEPT {return ::cosl(__lcpp_x);}
 #endif
@@ -733,7 +733,7 @@ cos(_A1 __lcpp_x) _NOEXCEPT {return ::co
 
 // cosh
 
-#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX) || defined(__sun__))
+#if !((defined(_LIBCPP_MSVCRT) && (_VC_CRT_MAJOR_VERSION-0) < 14) || 
defined(_AIX) || defined(__sun__))
 inline _LIBCPP_INLINE_VISIBILITY float   cosh(float __lcpp_x) _NOEXCEPT
   {return ::coshf(__lcpp_x);}
 inline _LIBCPP_INLINE_VISIBILITY long double cosh(long double __lcpp_x) 
_NOEXCEPT {return ::coshl(__lcpp_x);}
 #endif
@@ -745,7 +745,7 @@ cosh(_A1 __lcpp_x) _NOEXCEPT {return ::c
 
 // exp
 
-#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX) || defined(__sun__))
+#if !((defined(_LIBCPP_MSVCRT) && (_VC_CRT_MAJOR_VERSION-0) < 14) || 
defined(_AIX) || defined(__sun__))
 inline _LIBCPP_INLINE_VISIBILITY float   exp(float __lcpp_x) _NOEXCEPT 
  {return ::expf(__lcpp_x);}
 inline _LIBCPP_INLINE_VISIBILITY long double exp(long double __lcpp_x) 
_NOEXCEPT {return ::expl(__lcpp_x);}
 #endif
@@ -757,7 +757,7 @@ exp(_A1 __lcpp_x) _NOEXCEPT {return ::ex
 
 // fabs
 
-#if !(defined(_LIBCPP_MSVCRT) || defined(_AIX) || defined(__sun__))
+#if !((defined(_LIBCPP_MSVCRT) && (_VC_CRT_MAJOR_VERSION-0) < 14) || 
defined(_AIX) || defined(__sun__))
 inline _LIBCPP_INLINE_VISIBILITY float   fabs(float __lcpp_x) _NOEXCEPT
   {return ::fabsf(__lcpp_x);}
 inline _LIBCPP_INLINE_VISIBILITY long double fabs(long 

[libclc] r294916 - Move BufferPtr into the block where it it being used

2017-02-12 Thread Jeroen Ketema via cfe-commits
Author: jketema
Date: Sun Feb 12 15:33:49 2017
New Revision: 294916

URL: http://llvm.org/viewvc/llvm-project?rev=294916=rev
Log:
Move BufferPtr into the block where it it being used

The previous location outside the block would crash prepare-builtins
when no the builtins file accidentially not passed on the command line.

Modified:
libclc/trunk/utils/prepare-builtins.cpp

Modified: libclc/trunk/utils/prepare-builtins.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/utils/prepare-builtins.cpp?rev=294916=294915=294916=diff
==
--- libclc/trunk/utils/prepare-builtins.cpp (original)
+++ libclc/trunk/utils/prepare-builtins.cpp Sun Feb 12 15:33:49 2017
@@ -36,10 +36,10 @@ int main(int argc, char **argv) {
   {
 ErrorOr BufferOrErr =
   MemoryBuffer::getFile(InputFilename);
-std::unique_ptr  = BufferOrErr.get();
-if (std::error_code  ec = BufferOrErr.getError())
+if (std::error_code  ec = BufferOrErr.getError()) {
   ErrorMessage = ec.message();
-else {
+} else {
+  std::unique_ptr  = BufferOrErr.get();
   ErrorOr ModuleOrErr =
   expectedToErrorOrAndEmitErrors(Context,
   parseBitcodeFile(BufferPtr.get()->getMemBufferRef(), Context));


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


[libclc] r294915 - Add the correct prefixes to the cl_khr_fp64 pragma

2017-02-12 Thread Jeroen Ketema via cfe-commits
Author: jketema
Date: Sun Feb 12 15:31:41 2017
New Revision: 294915

URL: http://llvm.org/viewvc/llvm-project?rev=294915=rev
Log:
Add the correct prefixes to the cl_khr_fp64 pragma

Modified:
libclc/trunk/generic/include/clc/shared/vstore.h

Modified: libclc/trunk/generic/include/clc/shared/vstore.h
URL: 
http://llvm.org/viewvc/llvm-project/libclc/trunk/generic/include/clc/shared/vstore.h?rev=294915=294914=294915=diff
==
--- libclc/trunk/generic/include/clc/shared/vstore.h (original)
+++ libclc/trunk/generic/include/clc/shared/vstore.h Sun Feb 12 15:31:41 2017
@@ -29,7 +29,7 @@
 _CLC_VECTOR_VSTORE_PRIM3(_half, half, float)
 
 #ifdef cl_khr_fp64
-#pragma cl_khr_fp64: enable
+#pragma OPENCL EXTENSION cl_khr_fp64: enable
   _CLC_VECTOR_VSTORE_PRIM1(double)
   _CLC_VECTOR_VSTORE_PRIM3(_half, half, double)
   _CLC_VSTORE_DECL(_half, half, double, , __private)


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


[PATCH] D29877: Warn about unused static file scope function template declarations.

2017-02-12 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev created this revision.

Repository:
  rL LLVM

https://reviews.llvm.org/D29877

Files:
  lib/Sema/Sema.cpp
  lib/Sema/SemaDecl.cpp
  lib/Serialization/ASTReader.cpp
  test/SemaCXX/warn-unused-filescoped.cpp


Index: test/SemaCXX/warn-unused-filescoped.cpp
===
--- test/SemaCXX/warn-unused-filescoped.cpp
+++ test/SemaCXX/warn-unused-filescoped.cpp
@@ -32,6 +32,14 @@
   inline void bar(int, int) { }
 };
 
+namespace test8 {
+// Should ignore overloaded operators.
+template 
+struct S {};
+template 
+static bool operator==(S lhs, S rhs) { }
+}
+
 namespace pr19713 {
 #if __cplusplus >= 201103L
   static constexpr int constexpr1() { return 1; }
@@ -200,6 +208,11 @@
 static void func() {}
 }
 
+namespace test9 {
+template
+static void completeRedeclChainForTemplateSpecialization() { } // 
expected-warning {{unused}}
+}
+
 namespace pr19713 {
 #if __cplusplus >= 201103L
   // FIXME: We should warn on both of these.
Index: lib/Serialization/ASTReader.cpp
===
--- lib/Serialization/ASTReader.cpp
+++ lib/Serialization/ASTReader.cpp
@@ -6511,12 +6511,6 @@
   return GetDecl(ID);
 }
 
-template
-static void completeRedeclChainForTemplateSpecialization(Decl *D) {
-  if (auto *TSD = dyn_cast(D))
-TSD->getSpecializedTemplate()->LoadLazySpecializations();
-}
-
 void ASTReader::CompleteRedeclChain(const Decl *D) {
   if (NumCurrentElementsDeserializing) {
 // We arrange to not care about the complete redeclaration chain while 
we're
@@ -7136,7 +7130,7 @@
 }
 
 template
-static void
+LLVM_DUMP_METHOD static void
 dumpModuleIDMap(StringRef Name,
 const ContinuousRangeMap ) {
Index: lib/Sema/SemaDecl.cpp
===
--- lib/Sema/SemaDecl.cpp
+++ lib/Sema/SemaDecl.cpp
@@ -1493,6 +1493,10 @@
   // 'static inline' functions are defined in headers; don't warn.
   if (FD->isInlined() && !isMainFileLoc(*this, FD->getLocation()))
 return false;
+  // 'static operator' functions are defined in headers; don't warn.
+  if (FD->isOverloadedOperator() &&
+  !isMainFileLoc(*this, FD->getLocation()))
+return false;
 }
 
 if (FD->doesThisDeclarationHaveABody() &&
@@ -8846,6 +8850,7 @@
 if (FunctionTemplate) {
   if (NewFD->isInvalidDecl())
 FunctionTemplate->setInvalidDecl();
+  MarkUnusedFileScopedDecl(NewFD);
   return FunctionTemplate;
 }
   }
Index: lib/Sema/Sema.cpp
===
--- lib/Sema/Sema.cpp
+++ lib/Sema/Sema.cpp
@@ -470,6 +470,13 @@
 return true;
 
   if (const FunctionDecl *FD = dyn_cast(D)) {
+// If this is a function template, we should remove if it has no
+// specializations.
+if (FunctionTemplateDecl *Template = FD->getDescribedFunctionTemplate()) {
+  if (std::distance(Template->spec_begin(), Template->spec_end()))
+return true;
+}
+
 // UnusedFileScopedDecls stores the first declaration.
 // The declaration may have become definition so check again.
 const FunctionDecl *DeclToCheck;


Index: test/SemaCXX/warn-unused-filescoped.cpp
===
--- test/SemaCXX/warn-unused-filescoped.cpp
+++ test/SemaCXX/warn-unused-filescoped.cpp
@@ -32,6 +32,14 @@
   inline void bar(int, int) { }
 };
 
+namespace test8 {
+// Should ignore overloaded operators.
+template 
+struct S {};
+template 
+static bool operator==(S lhs, S rhs) { }
+}
+
 namespace pr19713 {
 #if __cplusplus >= 201103L
   static constexpr int constexpr1() { return 1; }
@@ -200,6 +208,11 @@
 static void func() {}
 }
 
+namespace test9 {
+template
+static void completeRedeclChainForTemplateSpecialization() { } // expected-warning {{unused}}
+}
+
 namespace pr19713 {
 #if __cplusplus >= 201103L
   // FIXME: We should warn on both of these.
Index: lib/Serialization/ASTReader.cpp
===
--- lib/Serialization/ASTReader.cpp
+++ lib/Serialization/ASTReader.cpp
@@ -6511,12 +6511,6 @@
   return GetDecl(ID);
 }
 
-template
-static void completeRedeclChainForTemplateSpecialization(Decl *D) {
-  if (auto *TSD = dyn_cast(D))
-TSD->getSpecializedTemplate()->LoadLazySpecializations();
-}
-
 void ASTReader::CompleteRedeclChain(const Decl *D) {
   if (NumCurrentElementsDeserializing) {
 // We arrange to not care about the complete redeclaration chain while we're
@@ -7136,7 +7130,7 @@
 }
 
 template
-static void
+LLVM_DUMP_METHOD static void
 dumpModuleIDMap(StringRef Name,
 const ContinuousRangeMap ) {
Index: lib/Sema/SemaDecl.cpp

[PATCH] D29863: [libc++] Fix PR 31938 - std::basic_string constructors use non-deductible parameter types.

2017-02-12 Thread Richard Smith via Phabricator via cfe-commits
rsmith added inline comments.



Comment at: include/string:782
 _LIBCPP_INLINE_VISIBILITY
 basic_string(const value_type* __s, size_type __n);
 _LIBCPP_INLINE_VISIBILITY

EricWF wrote:
> rsmith wrote:
> > Did you skip this one intentionally?
> Yes. `size_type`  is a typedef for `allocator_traits::size_type`, 
> This causes the `basic_string(CharT*, Allocator const&)` to always be chosen 
> instead, resulting in a incorrect allocator type.
I don't think it will always be chosen instead; if the argument is of type 
`size_t`, the `(const CharT*, size_type)` overload should be chosen.


https://reviews.llvm.org/D29863



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


[PATCH] D29758: [OpenMP] Parallel reduction on the NVPTX device.

2017-02-12 Thread Arpith Jacob via Phabricator via cfe-commits
arpith-jacob updated this revision to Diff 88144.
arpith-jacob added a comment.

Updated patch to address Alexey's comments.  Condensed parameters in 
emitReduction() to a struct Options.


https://reviews.llvm.org/D29758

Files:
  lib/CodeGen/CGOpenMPRuntime.cpp
  lib/CodeGen/CGOpenMPRuntime.h
  lib/CodeGen/CGOpenMPRuntimeNVPTX.cpp
  lib/CodeGen/CGOpenMPRuntimeNVPTX.h
  lib/CodeGen/CGStmtOpenMP.cpp
  lib/CodeGen/CodeGenFunction.h
  test/OpenMP/nvptx_target_parallel_reduction_codegen.cpp

Index: test/OpenMP/nvptx_target_parallel_reduction_codegen.cpp
===
--- /dev/null
+++ test/OpenMP/nvptx_target_parallel_reduction_codegen.cpp
@@ -0,0 +1,830 @@
+// Test target codegen - host bc file has to be created first.
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm-bc %s -o %t-ppc-host.bc
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple nvptx64-unknown-unknown -fopenmp-targets=nvptx64-nvidia-cuda -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-ppc-host.bc -o - | FileCheck %s --check-prefix CHECK --check-prefix CHECK-64
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple i386-unknown-unknown -fopenmp-targets=nvptx-nvidia-cuda -emit-llvm-bc %s -o %t-x86-host.bc
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple nvptx-unknown-unknown -fopenmp-targets=nvptx-nvidia-cuda -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-x86-host.bc -o - | FileCheck %s --check-prefix CHECK --check-prefix CHECK-32
+// RUN: %clang_cc1 -verify -fopenmp -fexceptions -fcxx-exceptions -x c++ -triple nvptx-unknown-unknown -fopenmp-targets=nvptx-nvidia-cuda -emit-llvm %s -fopenmp-is-device -fopenmp-host-ir-file-path %t-x86-host.bc -o - | FileCheck %s --check-prefix CHECK --check-prefix CHECK-32
+// expected-no-diagnostics
+#ifndef HEADER
+#define HEADER
+
+// Check for the data transfer medium in shared memory to transfer the reduction list to the first warp.
+// CHECK-DAG: [[TRANSFER_STORAGE:@.+]] = common addrspace([[SHARED_ADDRSPACE:[0-9]+]]) global [32 x i64]
+
+// Check that the execution mode of all 3 target regions is set to Spmd Mode.
+// CHECK-DAG: {{@__omp_offloading_.+l27}}_exec_mode = weak constant i8 0
+// CHECK-DAG: {{@__omp_offloading_.+l32}}_exec_mode = weak constant i8 0
+// CHECK-DAG: {{@__omp_offloading_.+l38}}_exec_mode = weak constant i8 0
+
+template
+tx ftemplate(int n) {
+  int a;
+  short b;
+  tx c;
+  float d;
+  double e;
+
+  #pragma omp target parallel reduction(+: e) map(tofrom: e)
+  {
+e += 5;
+  }
+
+  #pragma omp target parallel reduction(^: c) reduction(*: d) map(tofrom: c,d)
+  {
+c ^= 2;
+d *= 33;
+  }
+
+  #pragma omp target parallel reduction(|: a) reduction(max: b) map(tofrom: a,b)
+  {
+a |= 1;
+b = 99 > b ? 99 : b;
+  }
+
+  return a+b+c+d+e;
+}
+
+int bar(int n){
+  int a = 0;
+
+  a += ftemplate(n);
+
+  return a;
+}
+
+  // CHECK: define {{.*}}void {{@__omp_offloading_.+template.+l27}}(
+  //
+  // CHECK: call void @__kmpc_spmd_kernel_init(
+  // CHECK: br label {{%?}}[[EXECUTE:.+]]
+  //
+  // CHECK: [[EXECUTE]]
+  // CHECK: {{call|invoke}} void [[PFN:@.+]](i32*
+  // CHECK: call void @__kmpc_spmd_kernel_deinit()
+  //
+  //
+  // define internal void [[PFN]](
+  // CHECK: store double {{[0\.e\+]+}}, double* [[E:%.+]], align
+  // CHECK: [[EV:%.+]] = load double, double* [[E]], align
+  // CHECK: [[ADD:%.+]] = fadd double [[EV]], 5
+  // CHECK: store double [[ADD]], double* [[E]], align
+  // CHECK: [[PTR1:%.+]] = getelementptr inbounds [[RLT:.+]], [1 x i8*]* [[RL:%.+]], i{{32|64}} 0, i{{32|64}} 0
+  // CHECK: [[E_CAST:%.+]] = bitcast double* [[E]] to i8*
+  // CHECK: store i8* [[E_CAST]], i8** [[PTR1]], align
+  // CHECK: [[ARG_RL:%.+]] = bitcast [[RLT]]* [[RL]] to i8*
+  // CHECK: [[RET:%.+]] = call i32 @__kmpc_nvptx_parallel_reduce_nowait(i32 {{.+}}, i32 1, i{{32|64}} {{4|8}}, i8* [[ARG_RL]], void (i8*, i16, i16, i16)* [[SHUFFLE_REDUCE_FN:@.+]], void (i8*, i32)* [[WARP_COPY_FN:@.+]])
+  // CHECK: switch i32 [[RET]], label {{%?}}[[DEFAULTLABEL:.+]] [
+  // CHECK: i32 1, label {{%?}}[[REDLABEL:.+]]
+
+  // CHECK: [[REDLABEL]]
+  // CHECK: [[E_INV:%.+]] = load double, double* [[E_IN:%.+]], align
+  // CHECK: [[EV:%.+]] = load double, double* [[E]], align
+  // CHECK: [[ADD:%.+]] = fadd double [[E_INV]], [[EV]]
+  // CHECK: store double [[ADD]], double* [[E_IN]], align
+  // CHECK: call void @__kmpc_nvptx_end_reduce_nowait(
+  // CHECK: br label %[[DEFAULTLABEL]]
+  //
+  // CHECK: [[DEFAULTLABEL]]
+  // CHECK: ret
+
+  //
+  // Reduction function
+  // CHECK: define internal void [[REDUCTION_FUNC:@.+]](i8*, i8*)
+  // CHECK: [[VAR_RHS_REF:%.+]] = getelementptr inbounds [[RLT]], [[RLT]]* [[RED_LIST_RHS:%.+]], i{{32|64}} 0, i{{32|64}} 0
+  // CHECK: [[VAR_RHS_VOID:%.+]] = load i8*, i8** [[VAR_RHS_REF]],
+  // CHECK: [[VAR_RHS:%.+]] = bitcast i8* [[VAR_RHS_VOID]] to double*
+  //
+  // CHECK: [[VAR_LHS_REF:%.+]] 

[clang-tools-extra] r294913 - [clang-tidy] Fix for bug 31838: readability-delete-null-pointer does not work for class members

2017-02-12 Thread Mads Ravn via cfe-commits
Author: madsravn
Date: Sun Feb 12 14:35:42 2017
New Revision: 294913

URL: http://llvm.org/viewvc/llvm-project?rev=294913=rev
Log:
[clang-tidy] Fix for bug 31838: readability-delete-null-pointer does not work 
for class members

Fix for commit r294912 which had a small error in the AST matcher.

Modified:
clang-tools-extra/trunk/clang-tidy/readability/DeleteNullPointerCheck.cpp

Modified: 
clang-tools-extra/trunk/clang-tidy/readability/DeleteNullPointerCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/DeleteNullPointerCheck.cpp?rev=294913=294912=294913=diff
==
--- clang-tools-extra/trunk/clang-tidy/readability/DeleteNullPointerCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/readability/DeleteNullPointerCheck.cpp 
Sun Feb 12 14:35:42 2017
@@ -43,7 +43,7 @@ void DeleteNullPointerCheck::registerMat
   ifStmt(hasCondition(anyOf(PointerCondition, 
BinaryPointerCheckCondition)),
  hasThen(anyOf(
  DeleteExpr, DeleteMemberExpr,
- compoundStmt(has(anyOf(DeleteExpr, DeleteMemberExpr)),
+ compoundStmt(anyOf(has(DeleteExpr), has(DeleteMemberExpr)),
   statementCountIs(1))
  .bind("compound"
   .bind("ifWithDelete"),


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


[PATCH] D29726: [Clang-tidy] Fix for bug 31838: readability-delete-null-pointer does not work for class members

2017-02-12 Thread Mads Ravn via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL294912: [clang-tidy] Fix for bug 31838: 
readability-delete-null-pointer does not work… (authored by madsravn).

Changed prior to commit:
  https://reviews.llvm.org/D29726?vs=88123=88143#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D29726

Files:
  clang-tools-extra/trunk/clang-tidy/readability/DeleteNullPointerCheck.cpp
  clang-tools-extra/trunk/clang-tidy/readability/DeleteNullPointerCheck.h
  clang-tools-extra/trunk/test/clang-tidy/readability-delete-null-pointer.cpp


Index: clang-tools-extra/trunk/clang-tidy/readability/DeleteNullPointerCheck.h
===
--- clang-tools-extra/trunk/clang-tidy/readability/DeleteNullPointerCheck.h
+++ clang-tools-extra/trunk/clang-tidy/readability/DeleteNullPointerCheck.h
@@ -16,7 +16,8 @@
 namespace tidy {
 namespace readability {
 
-/// Check whether the 'if' statement is unnecessary before calling 'delete' on 
a pointer.
+/// Check whether the 'if' statement is unnecessary before calling 'delete' on 
a
+/// pointer.
 ///
 /// For the user-facing documentation see:
 /// 
http://clang.llvm.org/extra/clang-tidy/checks/readability-delete-null-pointer.html
Index: clang-tools-extra/trunk/clang-tidy/readability/DeleteNullPointerCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/readability/DeleteNullPointerCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/readability/DeleteNullPointerCheck.cpp
@@ -24,19 +24,28 @@
 to(decl(equalsBoundNode("deletedPointer"
   .bind("deleteExpr");
 
-  const auto PointerExpr =
-  ignoringImpCasts(declRefExpr(to(decl().bind("deletedPointer";
+  const auto DeleteMemberExpr =
+  cxxDeleteExpr(has(castExpr(has(memberExpr(hasDeclaration(
+
fieldDecl(equalsBoundNode("deletedMemberPointer"
+  .bind("deleteMemberExpr");
+
+  const auto PointerExpr = ignoringImpCasts(anyOf(
+  declRefExpr(to(decl().bind("deletedPointer"))),
+  memberExpr(hasDeclaration(fieldDecl().bind("deletedMemberPointer");
+
   const auto PointerCondition = castExpr(hasCastKind(CK_PointerToBoolean),
  hasSourceExpression(PointerExpr));
   const auto BinaryPointerCheckCondition =
   binaryOperator(hasEitherOperand(castExpr(hasCastKind(CK_NullToPointer))),
  hasEitherOperand(PointerExpr));
 
   Finder->addMatcher(
   ifStmt(hasCondition(anyOf(PointerCondition, 
BinaryPointerCheckCondition)),
- hasThen(anyOf(DeleteExpr,
-   compoundStmt(has(DeleteExpr), statementCountIs(1))
-   .bind("compound"
+ hasThen(anyOf(
+ DeleteExpr, DeleteMemberExpr,
+ compoundStmt(has(anyOf(DeleteExpr, DeleteMemberExpr)),
+  statementCountIs(1))
+ .bind("compound"
   .bind("ifWithDelete"),
   this);
 }
Index: 
clang-tools-extra/trunk/test/clang-tidy/readability-delete-null-pointer.cpp
===
--- clang-tools-extra/trunk/test/clang-tidy/readability-delete-null-pointer.cpp
+++ clang-tools-extra/trunk/test/clang-tidy/readability-delete-null-pointer.cpp
@@ -59,6 +59,16 @@
   } else {
 c2 = c;
   }
+  struct A {
+void foo() {
+  if (mp) // #6
+delete mp;
+  // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: 'if' statement is 
unnecessary; deleting null pointer has no effect 
[readability-delete-null-pointer]
+  // CHECK-FIXES: {{^  }}// #6
+  // CHECK-FIXES-NEXT: delete mp;
+}
+int *mp;
+  };
 }
 
 void g() {


Index: clang-tools-extra/trunk/clang-tidy/readability/DeleteNullPointerCheck.h
===
--- clang-tools-extra/trunk/clang-tidy/readability/DeleteNullPointerCheck.h
+++ clang-tools-extra/trunk/clang-tidy/readability/DeleteNullPointerCheck.h
@@ -16,7 +16,8 @@
 namespace tidy {
 namespace readability {
 
-/// Check whether the 'if' statement is unnecessary before calling 'delete' on a pointer.
+/// Check whether the 'if' statement is unnecessary before calling 'delete' on a
+/// pointer.
 ///
 /// For the user-facing documentation see:
 /// http://clang.llvm.org/extra/clang-tidy/checks/readability-delete-null-pointer.html
Index: clang-tools-extra/trunk/clang-tidy/readability/DeleteNullPointerCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/readability/DeleteNullPointerCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/readability/DeleteNullPointerCheck.cpp
@@ -24,19 +24,28 @@
 to(decl(equalsBoundNode("deletedPointer"
   .bind("deleteExpr");
 
-  const auto PointerExpr =
-  

[clang-tools-extra] r294912 - [clang-tidy] Fix for bug 31838: readability-delete-null-pointer does not work for class members

2017-02-12 Thread Mads Ravn via cfe-commits
Author: madsravn
Date: Sun Feb 12 14:09:59 2017
New Revision: 294912

URL: http://llvm.org/viewvc/llvm-project?rev=294912=rev
Log:
[clang-tidy] Fix for bug 31838: readability-delete-null-pointer does not work 
for class members

I have made a small fix for readability-delete-null-pointer check so it also 
checks for class members.

Example of case that it fixes
```
  struct A {
void foo() {
  if(mp)
delete mp;
}
int *mp;
  };
```

Reviewers: JDevlieghere, aaron.ballman, alexfh, malcolm.parsons

Subscribers: cfe-commits

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

Modified:
clang-tools-extra/trunk/clang-tidy/readability/DeleteNullPointerCheck.cpp
clang-tools-extra/trunk/clang-tidy/readability/DeleteNullPointerCheck.h
clang-tools-extra/trunk/test/clang-tidy/readability-delete-null-pointer.cpp

Modified: 
clang-tools-extra/trunk/clang-tidy/readability/DeleteNullPointerCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/DeleteNullPointerCheck.cpp?rev=294912=294911=294912=diff
==
--- clang-tools-extra/trunk/clang-tidy/readability/DeleteNullPointerCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/readability/DeleteNullPointerCheck.cpp 
Sun Feb 12 14:09:59 2017
@@ -24,8 +24,15 @@ void DeleteNullPointerCheck::registerMat
 to(decl(equalsBoundNode("deletedPointer"
   .bind("deleteExpr");
 
-  const auto PointerExpr =
-  ignoringImpCasts(declRefExpr(to(decl().bind("deletedPointer";
+  const auto DeleteMemberExpr =
+  cxxDeleteExpr(has(castExpr(has(memberExpr(hasDeclaration(
+
fieldDecl(equalsBoundNode("deletedMemberPointer"
+  .bind("deleteMemberExpr");
+
+  const auto PointerExpr = ignoringImpCasts(anyOf(
+  declRefExpr(to(decl().bind("deletedPointer"))),
+  memberExpr(hasDeclaration(fieldDecl().bind("deletedMemberPointer");
+
   const auto PointerCondition = castExpr(hasCastKind(CK_PointerToBoolean),
  hasSourceExpression(PointerExpr));
   const auto BinaryPointerCheckCondition =
@@ -34,9 +41,11 @@ void DeleteNullPointerCheck::registerMat
 
   Finder->addMatcher(
   ifStmt(hasCondition(anyOf(PointerCondition, 
BinaryPointerCheckCondition)),
- hasThen(anyOf(DeleteExpr,
-   compoundStmt(has(DeleteExpr), statementCountIs(1))
-   .bind("compound"
+ hasThen(anyOf(
+ DeleteExpr, DeleteMemberExpr,
+ compoundStmt(has(anyOf(DeleteExpr, DeleteMemberExpr)),
+  statementCountIs(1))
+ .bind("compound"
   .bind("ifWithDelete"),
   this);
 }

Modified: 
clang-tools-extra/trunk/clang-tidy/readability/DeleteNullPointerCheck.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/readability/DeleteNullPointerCheck.h?rev=294912=294911=294912=diff
==
--- clang-tools-extra/trunk/clang-tidy/readability/DeleteNullPointerCheck.h 
(original)
+++ clang-tools-extra/trunk/clang-tidy/readability/DeleteNullPointerCheck.h Sun 
Feb 12 14:09:59 2017
@@ -16,7 +16,8 @@ namespace clang {
 namespace tidy {
 namespace readability {
 
-/// Check whether the 'if' statement is unnecessary before calling 'delete' on 
a pointer.
+/// Check whether the 'if' statement is unnecessary before calling 'delete' on 
a
+/// pointer.
 ///
 /// For the user-facing documentation see:
 /// 
http://clang.llvm.org/extra/clang-tidy/checks/readability-delete-null-pointer.html

Modified: 
clang-tools-extra/trunk/test/clang-tidy/readability-delete-null-pointer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/readability-delete-null-pointer.cpp?rev=294912=294911=294912=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/readability-delete-null-pointer.cpp 
(original)
+++ clang-tools-extra/trunk/test/clang-tidy/readability-delete-null-pointer.cpp 
Sun Feb 12 14:09:59 2017
@@ -59,6 +59,16 @@ void f() {
   } else {
 c2 = c;
   }
+  struct A {
+void foo() {
+  if (mp) // #6
+delete mp;
+  // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: 'if' statement is 
unnecessary; deleting null pointer has no effect 
[readability-delete-null-pointer]
+  // CHECK-FIXES: {{^  }}// #6
+  // CHECK-FIXES-NEXT: delete mp;
+}
+int *mp;
+  };
 }
 
 void g() {


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


Re: r294862 - Hopefully fixes a compile error introduced by r294861.

2017-02-12 Thread Renato Golin via cfe-commits
On 12 February 2017 at 19:24, Aaron Ballman  wrote:
> Did, just that the test also needs a triple. I guess I'll do the dance
> to add it and re-commit.

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


Re: r294910 - Revert "Attributes on K C functions should not cause incompatible..."

2017-02-12 Thread Aaron Ballman via cfe-commits
On Sun, Feb 12, 2017 at 2:08 PM, Renato Golin via cfe-commits
 wrote:
> Author: rengolin
> Date: Sun Feb 12 13:08:02 2017
> New Revision: 294910
>
> URL: http://llvm.org/viewvc/llvm-project?rev=294910=rev
> Log:
> Revert "Attributes on K C functions should not cause incompatible..."
>
> ...function type with a redeclaration having the same attribute. Fixing this
> introduced a secondary problem where we were assuming that K functions
> could not be attributed types when reporting old-style function definitions
> that are not preceded by a prototype."
>
> Also Revert "Hopefully fixes a compile error introduced by r294861."
>
> This reverts commit r294862, r294861, as they bork the ARM builds and
> haven't fix it back.

It seems this was a case where we needed a target triple. I've
recommit in r294911, and hopefully the ARM bots will be happy with
that.

> Also, please, short commit titles, long commit decsriptions...

Sorry about that.

~Aaron

>
> Modified:
> cfe/trunk/include/clang/AST/Type.h
> cfe/trunk/include/clang/AST/TypeLoc.h
> cfe/trunk/lib/Sema/SemaDecl.cpp
> cfe/trunk/test/Sema/knr-def-call.c
> cfe/trunk/test/Sema/warn-strict-prototypes.c
>
> Modified: cfe/trunk/include/clang/AST/Type.h
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=294910=294909=294910=diff
> ==
> --- cfe/trunk/include/clang/AST/Type.h (original)
> +++ cfe/trunk/include/clang/AST/Type.h Sun Feb 12 13:08:02 2017
> @@ -1888,13 +1888,6 @@ public:
>/// immediately following this class.
>template  const T *getAs() const;
>
> -  /// Member-template getAsAdjusted. Look through specific 
> kinds
> -  /// of sugar (parens, attributes, etc) for an instance of \.
> -  /// This is used when you need to walk over sugar nodes that represent some
> -  /// kind of type adjustment from a type that was written as a \ type>
> -  /// to another type that is still canonically a \.
> -  template  const T *getAsAdjusted() const;
> -
>/// A variant of getAs<> for array types which silently discards
>/// qualifiers from the outermost type.
>const ArrayType *getAsArrayTypeUnsafe() const;
> @@ -6015,38 +6008,6 @@ template  const T *Type::get
>return cast(getUnqualifiedDesugaredType());
>  }
>
> -template  const T *Type::getAsAdjusted() const {
> -  static_assert(!TypeIsArrayType::value, "ArrayType cannot be used with 
> getAsAdjusted!");
> -
> -  // If this is directly a T type, return it.
> -  if (const T *Ty = dyn_cast(this))
> -return Ty;
> -
> -  // If the canonical form of this type isn't the right kind, reject it.
> -  if (!isa(CanonicalType))
> -return nullptr;
> -
> -  // Strip off type adjustments that do not modify the underlying nature of 
> the
> -  // type.
> -  const Type *Ty = this;
> -  while (Ty) {
> -if (const auto *A = dyn_cast(Ty))
> -  Ty = A->getModifiedType().getTypePtr();
> -else if (const auto *E = dyn_cast(Ty))
> -  Ty = E->desugar().getTypePtr();
> -else if (const auto *P = dyn_cast(Ty))
> -  Ty = P->desugar().getTypePtr();
> -else if (const auto *A = dyn_cast(Ty))
> -  Ty = A->desugar().getTypePtr();
> -else
> -  break;
> -  }
> -
> -  // Just because the canonical type is correct does not mean we can use 
> cast<>,
> -  // since we may not have stripped off all the sugar down to the base type.
> -  return dyn_cast(Ty);
> -}
> -
>  inline const ArrayType *Type::getAsArrayTypeUnsafe() const {
>// If this is directly an array type, return it.
>if (const ArrayType *arr = dyn_cast(this))
>
> Modified: cfe/trunk/include/clang/AST/TypeLoc.h
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/TypeLoc.h?rev=294910=294909=294910=diff
> ==
> --- cfe/trunk/include/clang/AST/TypeLoc.h (original)
> +++ cfe/trunk/include/clang/AST/TypeLoc.h Sun Feb 12 13:08:02 2017
> @@ -70,13 +70,6 @@ public:
>  return t;
>}
>
> -  /// \brief Convert to the specified TypeLoc type, returning a null TypeLoc 
> if
> -  /// this TypeLock is not of the desired type. It will consider type
> -  /// adjustments from a type that wad written as a T to another type that is
> -  /// still canonically a T (ignores parens, attributes, elaborated types, 
> etc).
> -  template 
> -  T getAsAdjusted() const;
> -
>/// The kinds of TypeLocs.  Equivalent to the Type::TypeClass enum,
>/// except it also defines a Qualified enum that corresponds to the
>/// QualifiedLoc class.
> @@ -2195,24 +2188,6 @@ public:
>
>QualType getInnerType() const { return 
> this->getTypePtr()->getElementType(); }
>  };
> -
> -template 
> -inline T TypeLoc::getAsAdjusted() const {
> -  TypeLoc Cur = *this;
> -  while (!T::isKind(Cur)) {
> -if (auto PTL = Cur.getAs())
> -  Cur = PTL.getInnerLoc();
> -else if (auto ATL = 

r294911 - Revert r294910 and recommit r294861 and r294862 with a target triple to hopefully appease the bots.

2017-02-12 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Sun Feb 12 13:24:47 2017
New Revision: 294911

URL: http://llvm.org/viewvc/llvm-project?rev=294911=rev
Log:
Revert r294910 and recommit r294861 and r294862 with a target triple to 
hopefully appease the bots.

Modified:
cfe/trunk/include/clang/AST/Type.h
cfe/trunk/include/clang/AST/TypeLoc.h
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/Sema/knr-def-call.c
cfe/trunk/test/Sema/warn-strict-prototypes.c

Modified: cfe/trunk/include/clang/AST/Type.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=294911=294910=294911=diff
==
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Sun Feb 12 13:24:47 2017
@@ -1888,6 +1888,13 @@ public:
   /// immediately following this class.
   template  const T *getAs() const;
 
+  /// Member-template getAsAdjusted. Look through specific kinds
+  /// of sugar (parens, attributes, etc) for an instance of \.
+  /// This is used when you need to walk over sugar nodes that represent some
+  /// kind of type adjustment from a type that was written as a \
+  /// to another type that is still canonically a \.
+  template  const T *getAsAdjusted() const;
+
   /// A variant of getAs<> for array types which silently discards
   /// qualifiers from the outermost type.
   const ArrayType *getAsArrayTypeUnsafe() const;
@@ -6008,6 +6015,38 @@ template  const T *Type::get
   return cast(getUnqualifiedDesugaredType());
 }
 
+template  const T *Type::getAsAdjusted() const {
+  static_assert(!TypeIsArrayType::value, "ArrayType cannot be used with 
getAsAdjusted!");
+
+  // If this is directly a T type, return it.
+  if (const T *Ty = dyn_cast(this))
+return Ty;
+
+  // If the canonical form of this type isn't the right kind, reject it.
+  if (!isa(CanonicalType))
+return nullptr;
+
+  // Strip off type adjustments that do not modify the underlying nature of the
+  // type.
+  const Type *Ty = this;
+  while (Ty) {
+if (const auto *A = dyn_cast(Ty))
+  Ty = A->getModifiedType().getTypePtr();
+else if (const auto *E = dyn_cast(Ty))
+  Ty = E->desugar().getTypePtr();
+else if (const auto *P = dyn_cast(Ty))
+  Ty = P->desugar().getTypePtr();
+else if (const auto *A = dyn_cast(Ty))
+  Ty = A->desugar().getTypePtr();
+else
+  break;
+  }
+
+  // Just because the canonical type is correct does not mean we can use 
cast<>,
+  // since we may not have stripped off all the sugar down to the base type.
+  return dyn_cast(Ty);
+}
+
 inline const ArrayType *Type::getAsArrayTypeUnsafe() const {
   // If this is directly an array type, return it.
   if (const ArrayType *arr = dyn_cast(this))

Modified: cfe/trunk/include/clang/AST/TypeLoc.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/TypeLoc.h?rev=294911=294910=294911=diff
==
--- cfe/trunk/include/clang/AST/TypeLoc.h (original)
+++ cfe/trunk/include/clang/AST/TypeLoc.h Sun Feb 12 13:24:47 2017
@@ -70,6 +70,13 @@ public:
 return t;
   }
 
+  /// \brief Convert to the specified TypeLoc type, returning a null TypeLoc if
+  /// this TypeLock is not of the desired type. It will consider type
+  /// adjustments from a type that wad written as a T to another type that is
+  /// still canonically a T (ignores parens, attributes, elaborated types, 
etc).
+  template 
+  T getAsAdjusted() const;
+
   /// The kinds of TypeLocs.  Equivalent to the Type::TypeClass enum,
   /// except it also defines a Qualified enum that corresponds to the
   /// QualifiedLoc class.
@@ -2188,6 +2195,24 @@ public:
 
   QualType getInnerType() const { return this->getTypePtr()->getElementType(); 
}
 };
+
+template 
+inline T TypeLoc::getAsAdjusted() const {
+  TypeLoc Cur = *this;
+  while (!T::isKind(Cur)) {
+if (auto PTL = Cur.getAs())
+  Cur = PTL.getInnerLoc();
+else if (auto ATL = Cur.getAs())
+  Cur = ATL.getModifiedLoc();
+else if (auto ETL = Cur.getAs())
+  Cur = ETL.getNamedTypeLoc();
+else if (auto ATL = Cur.getAs())
+  Cur = ATL.getOriginalLoc();
+else
+  break;
+  }
+  return Cur.getAs();
+}
 }
 
 #endif

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=294911=294910=294911=diff
==
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Sun Feb 12 13:24:47 2017
@@ -7564,11 +7564,12 @@ static FunctionDecl* CreateNewFunctionDe
 // Determine whether the function was written with a
 // prototype. This true when:
 //   - there is a prototype in the declarator, or
-//   - the type R of the function is some kind of typedef or other 
reference
-// to a type name (which eventually refers to a function type).
+// 

Re: r294862 - Hopefully fixes a compile error introduced by r294861.

2017-02-12 Thread Aaron Ballman via cfe-commits
On Sun, Feb 12, 2017 at 2:20 PM, Renato Golin  wrote:
> On 11 February 2017 at 18:00, Aaron Ballman via cfe-commits
>  wrote:
>> Author: aaronballman
>> Date: Sat Feb 11 12:00:32 2017
>> New Revision: 294862
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=294862=rev
>> Log:
>> Hopefully fixes a compile error introduced by r294861.
>
> Didn't... :)
>
> http://lab.llvm.org:8011/builders/clang-cmake-armv7-a15/builds/3873 (and 
> others)
>
> Reverted both in r294910.

Did, just that the test also needs a triple. I guess I'll do the dance
to add it and re-commit.

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


Re: r294862 - Hopefully fixes a compile error introduced by r294861.

2017-02-12 Thread Renato Golin via cfe-commits
On 11 February 2017 at 18:00, Aaron Ballman via cfe-commits
 wrote:
> Author: aaronballman
> Date: Sat Feb 11 12:00:32 2017
> New Revision: 294862
>
> URL: http://llvm.org/viewvc/llvm-project?rev=294862=rev
> Log:
> Hopefully fixes a compile error introduced by r294861.

Didn't... :)

http://lab.llvm.org:8011/builders/clang-cmake-armv7-a15/builds/3873 (and others)

Reverted both in r294910.

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


r294910 - Revert "Attributes on K C functions should not cause incompatible..."

2017-02-12 Thread Renato Golin via cfe-commits
Author: rengolin
Date: Sun Feb 12 13:08:02 2017
New Revision: 294910

URL: http://llvm.org/viewvc/llvm-project?rev=294910=rev
Log:
Revert "Attributes on K C functions should not cause incompatible..."

...function type with a redeclaration having the same attribute. Fixing this
introduced a secondary problem where we were assuming that K functions
could not be attributed types when reporting old-style function definitions
that are not preceded by a prototype."

Also Revert "Hopefully fixes a compile error introduced by r294861."

This reverts commit r294862, r294861, as they bork the ARM builds and
haven't fix it back.

Also, please, short commit titles, long commit decsriptions...

Modified:
cfe/trunk/include/clang/AST/Type.h
cfe/trunk/include/clang/AST/TypeLoc.h
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/Sema/knr-def-call.c
cfe/trunk/test/Sema/warn-strict-prototypes.c

Modified: cfe/trunk/include/clang/AST/Type.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=294910=294909=294910=diff
==
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Sun Feb 12 13:08:02 2017
@@ -1888,13 +1888,6 @@ public:
   /// immediately following this class.
   template  const T *getAs() const;
 
-  /// Member-template getAsAdjusted. Look through specific kinds
-  /// of sugar (parens, attributes, etc) for an instance of \.
-  /// This is used when you need to walk over sugar nodes that represent some
-  /// kind of type adjustment from a type that was written as a \
-  /// to another type that is still canonically a \.
-  template  const T *getAsAdjusted() const;
-
   /// A variant of getAs<> for array types which silently discards
   /// qualifiers from the outermost type.
   const ArrayType *getAsArrayTypeUnsafe() const;
@@ -6015,38 +6008,6 @@ template  const T *Type::get
   return cast(getUnqualifiedDesugaredType());
 }
 
-template  const T *Type::getAsAdjusted() const {
-  static_assert(!TypeIsArrayType::value, "ArrayType cannot be used with 
getAsAdjusted!");
-
-  // If this is directly a T type, return it.
-  if (const T *Ty = dyn_cast(this))
-return Ty;
-
-  // If the canonical form of this type isn't the right kind, reject it.
-  if (!isa(CanonicalType))
-return nullptr;
-
-  // Strip off type adjustments that do not modify the underlying nature of the
-  // type.
-  const Type *Ty = this;
-  while (Ty) {
-if (const auto *A = dyn_cast(Ty))
-  Ty = A->getModifiedType().getTypePtr();
-else if (const auto *E = dyn_cast(Ty))
-  Ty = E->desugar().getTypePtr();
-else if (const auto *P = dyn_cast(Ty))
-  Ty = P->desugar().getTypePtr();
-else if (const auto *A = dyn_cast(Ty))
-  Ty = A->desugar().getTypePtr();
-else
-  break;
-  }
-
-  // Just because the canonical type is correct does not mean we can use 
cast<>,
-  // since we may not have stripped off all the sugar down to the base type.
-  return dyn_cast(Ty);
-}
-
 inline const ArrayType *Type::getAsArrayTypeUnsafe() const {
   // If this is directly an array type, return it.
   if (const ArrayType *arr = dyn_cast(this))

Modified: cfe/trunk/include/clang/AST/TypeLoc.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/TypeLoc.h?rev=294910=294909=294910=diff
==
--- cfe/trunk/include/clang/AST/TypeLoc.h (original)
+++ cfe/trunk/include/clang/AST/TypeLoc.h Sun Feb 12 13:08:02 2017
@@ -70,13 +70,6 @@ public:
 return t;
   }
 
-  /// \brief Convert to the specified TypeLoc type, returning a null TypeLoc if
-  /// this TypeLock is not of the desired type. It will consider type
-  /// adjustments from a type that wad written as a T to another type that is
-  /// still canonically a T (ignores parens, attributes, elaborated types, 
etc).
-  template 
-  T getAsAdjusted() const;
-
   /// The kinds of TypeLocs.  Equivalent to the Type::TypeClass enum,
   /// except it also defines a Qualified enum that corresponds to the
   /// QualifiedLoc class.
@@ -2195,24 +2188,6 @@ public:
 
   QualType getInnerType() const { return this->getTypePtr()->getElementType(); 
}
 };
-
-template 
-inline T TypeLoc::getAsAdjusted() const {
-  TypeLoc Cur = *this;
-  while (!T::isKind(Cur)) {
-if (auto PTL = Cur.getAs())
-  Cur = PTL.getInnerLoc();
-else if (auto ATL = Cur.getAs())
-  Cur = ATL.getModifiedLoc();
-else if (auto ETL = Cur.getAs())
-  Cur = ETL.getNamedTypeLoc();
-else if (auto ATL = Cur.getAs())
-  Cur = ATL.getOriginalLoc();
-else
-  break;
-  }
-  return Cur.getAs();
-}
 }
 
 #endif

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=294910=294909=294910=diff
==
--- 

r294904 - ASTReader: Refactor common code for writing function definitions, to match the writing code

2017-02-12 Thread David Blaikie via cfe-commits
Author: dblaikie
Date: Sun Feb 12 12:45:31 2017
New Revision: 294904

URL: http://llvm.org/viewvc/llvm-project?rev=294904=rev
Log:
ASTReader: Refactor common code for writing function definitions, to match the 
writing code

Modified:
cfe/trunk/lib/Serialization/ASTReaderDecl.cpp

Modified: cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReaderDecl.cpp?rev=294904=294903=294904=diff
==
--- cfe/trunk/lib/Serialization/ASTReaderDecl.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReaderDecl.cpp Sun Feb 12 12:45:31 2017
@@ -240,6 +240,7 @@ namespace clang {
 /// \brief Determine whether this declaration has a pending body.
 bool hasPendingBody() const { return HasPendingBody; }
 
+void ReadFunctionDefinition(FunctionDecl *FD);
 void Visit(Decl *D);
 
 void UpdateDecl(Decl *D);
@@ -421,6 +422,17 @@ uint64_t ASTDeclReader::GetCurrentCursor
   return Loc.F->DeclsCursor.GetCurrentBitNo() + Loc.F->GlobalBitOffset;
 }
 
+void ASTDeclReader::ReadFunctionDefinition(FunctionDecl *FD) {
+  if (auto *CD = dyn_cast(FD)) {
+CD->NumCtorInitializers = Record.readInt();
+if (CD->NumCtorInitializers)
+  CD->CtorInitializers = ReadGlobalOffset();
+  }
+  // Store the offset of the body so we can lazily load it later.
+  Reader.PendingBodies[FD] = GetCurrentCursorOffset();
+  HasPendingBody = true;
+}
+
 void ASTDeclReader::Visit(Decl *D) {
   DeclVisitor::Visit(D);
 
@@ -457,15 +469,8 @@ void ASTDeclReader::Visit(Decl *D) {
 // We only read it if FD doesn't already have a body (e.g., from another
 // module).
 // FIXME: Can we diagnose ODR violations somehow?
-if (Record.readInt()) {
-  if (auto *CD = dyn_cast(FD)) {
-CD->NumCtorInitializers = Record.readInt();
-if (CD->NumCtorInitializers)
-  CD->CtorInitializers = ReadGlobalOffset();
-  }
-  Reader.PendingBodies[FD] = GetCurrentCursorOffset();
-  HasPendingBody = true;
-}
+if (Record.readInt())
+  ReadFunctionDefinition(FD);
   }
 }
 
@@ -3861,14 +3866,7 @@ void ASTDeclReader::UpdateDecl(Decl *D)
 });
   }
   FD->setInnerLocStart(ReadSourceLocation());
-  if (auto *CD = dyn_cast(FD)) {
-CD->NumCtorInitializers = Record.readInt();
-if (CD->NumCtorInitializers)
-  CD->CtorInitializers = ReadGlobalOffset();
-  }
-  // Store the offset of the body so we can lazily load it later.
-  Reader.PendingBodies[FD] = GetCurrentCursorOffset();
-  HasPendingBody = true;
+  ReadFunctionDefinition(FD);
   assert(Record.getIdx() == Record.size() && "lazy body must be last");
   break;
 }


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


[PATCH] D28768: [clang-tidy] Add check 'modernize-return-braced-init-list'

2017-02-12 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh requested changes to this revision.
alexfh added a comment.
This revision now requires changes to proceed.

A couple of comments.




Comment at: clang-tidy/modernize/ReturnBracedInitListCheck.cpp:35
+
+  auto HasConstructExpr = has(ConstructExpr);
+

Nit: I see no point in this variable. I'd merge `has` into either the matcher 
above or the one below. 



Comment at: clang-tidy/modernize/ReturnBracedInitListCheck.cpp:74
+dyn_cast(MatchedFunctionDecl->getParamDecl(I))) {
+  if (MatchedConstructExpr->getArg(I)->getType().getCanonicalType() !=
+  VD->getType().getCanonicalType())

I wonder whether `MatchedConstructExpr` can have fewer arguments than the 
declaration (e.g. when there are default arguments). Could you add a test with 
default arguments and check whether this code works correctly?


Repository:
  rL LLVM

https://reviews.llvm.org/D28768



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


[PATCH] D29726: [Clang-tidy] Fix for bug 31838: readability-delete-null-pointer does not work for class members

2017-02-12 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh accepted this revision.
alexfh added a comment.
This revision is now accepted and ready to land.

LG


https://reviews.llvm.org/D29726



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


[libcxx] r294903 - test: mark requirement for pthread test

2017-02-12 Thread Saleem Abdulrasool via cfe-commits
Author: compnerd
Date: Sun Feb 12 11:37:48 2017
New Revision: 294903

URL: http://llvm.org/viewvc/llvm-project?rev=294903=rev
Log:
test: mark requirement for pthread test

This test explicitly is checking the behaviour of std::thread and
pthread interactions.  This requires pthreads.  Add an appropriate
requirement.

Modified:

libcxx/trunk/test/std/thread/thread.condition/PR30202_notify_from_pthread_created_thread.pass.cpp

Modified: 
libcxx/trunk/test/std/thread/thread.condition/PR30202_notify_from_pthread_created_thread.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/thread/thread.condition/PR30202_notify_from_pthread_created_thread.pass.cpp?rev=294903=294902=294903=diff
==
--- 
libcxx/trunk/test/std/thread/thread.condition/PR30202_notify_from_pthread_created_thread.pass.cpp
 (original)
+++ 
libcxx/trunk/test/std/thread/thread.condition/PR30202_notify_from_pthread_created_thread.pass.cpp
 Sun Feb 12 11:37:48 2017
@@ -8,6 +8,7 @@
 
//===--===//
 //
 // UNSUPPORTED: libcpp-has-no-threads
+// REQUIRES: libcpp-has-thread-api-pthread
 
 // notify_all_at_thread_exit(...) requires move semantics to transfer the
 // unique_lock.


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


[libcxx] r294902 - math: pull more C functions from std

2017-02-12 Thread Saleem Abdulrasool via cfe-commits
Author: compnerd
Date: Sun Feb 12 11:37:45 2017
New Revision: 294902

URL: http://llvm.org/viewvc/llvm-project?rev=294902=rev
Log:
math: pull more C functions from std

The newer ucrt version provides the gamma meth routines.  Includede them
when building the library.

Modified:
libcxx/trunk/include/math.h

Modified: libcxx/trunk/include/math.h
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/math.h?rev=294902=294901=294902=diff
==
--- libcxx/trunk/include/math.h (original)
+++ libcxx/trunk/include/math.h Sun Feb 12 11:37:45 2017
@@ -1017,7 +1017,7 @@ copysign(_A1 __lcpp_x, _A2 __lcpp_y) _NO
 return ::copysign((__result_type)__lcpp_x, (__result_type)__lcpp_y);
 }
 
-#ifndef _LIBCPP_MSVCRT
+#if !defined(_LIBCPP_MSVCRT) || ((_VC_CRT_MAJOR_VERSION-0) >= 14)
 
 // erf
 
@@ -1401,7 +1401,7 @@ inline _LIBCPP_INLINE_VISIBILITY
 typename std::enable_if::value, double>::type
 trunc(_A1 __lcpp_x) _NOEXCEPT {return ::trunc((double)__lcpp_x);}
 
-#endif // !_LIBCPP_MSVCRT
+#endif // !defined(_LIBCPP_MSVCRT) || ((_VC_CRT_MAJOR_VERSION-0) >= 14)
 
 } // extern "C++"
 


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


[libcxx] r294901 - test: squelch -Wreturn-type error

2017-02-12 Thread Saleem Abdulrasool via cfe-commits
Author: compnerd
Date: Sun Feb 12 11:37:44 2017
New Revision: 294901

URL: http://llvm.org/viewvc/llvm-project?rev=294901=rev
Log:
test: squelch -Wreturn-type error

Add an unreachable marker to avoid a -Wreturn-type error when building
on Windows.

Modified:
libcxx/trunk/test/std/utilities/function.objects/func.not_fn/not_fn.pass.cpp

Modified: 
libcxx/trunk/test/std/utilities/function.objects/func.not_fn/not_fn.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/function.objects/func.not_fn/not_fn.pass.cpp?rev=294901=294900=294901=diff
==
--- 
libcxx/trunk/test/std/utilities/function.objects/func.not_fn/not_fn.pass.cpp 
(original)
+++ 
libcxx/trunk/test/std/utilities/function.objects/func.not_fn/not_fn.pass.cpp 
Sun Feb 12 11:37:44 2017
@@ -414,7 +414,14 @@ void throws_in_constructor_test()
 throw 42;
   }
   ThrowsOnCopy() = default;
-  bool operator()() const { assert(false); }
+  bool operator()() const {
+assert(false);
+#if defined(_LIBCPP_MSVC)
+__assume(0);
+#else
+__builtin_unreachable();
+#endif
+  }
 };
 {
 ThrowsOnCopy cp;


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


[libcxx] r294899 - cmath: adjust math forwards for Windows

2017-02-12 Thread Saleem Abdulrasool via cfe-commits
Author: compnerd
Date: Sun Feb 12 10:44:17 2017
New Revision: 294899

URL: http://llvm.org/viewvc/llvm-project?rev=294899=rev
Log:
cmath: adjust math forwards for Windows

The newer versions of ucrt have the math routines.  Use the CRT version
to determine if we should include the math routines.  Fixes two tests
for Windows.

Modified:
libcxx/trunk/include/cmath

Modified: libcxx/trunk/include/cmath
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/cmath?rev=294899=294898=294899=diff
==
--- libcxx/trunk/include/cmath (original)
+++ libcxx/trunk/include/cmath Sun Feb 12 10:44:17 2017
@@ -495,7 +495,7 @@ using ::cbrtl;
 
 using ::copysignl;
 
-#ifndef _LIBCPP_MSVCRT
+#if !defined(_LIBCPP_MSVCRT) || (_VC_CRT_MAJOR_VERSION-0) >= 14
 using ::erfl;
 using ::erfcl;
 using ::exp2l;
@@ -526,7 +526,7 @@ using ::scalblnl;
 using ::scalbnl;
 using ::tgammal;
 using ::truncl;
-#endif // !_LIBCPP_MSVCRT
+#endif // !defined(_LIBCPP_MSVCRT) || (_VC_CRT_MAJOR_VERSION-0) >= 14
 
 #if _LIBCPP_STD_VER > 14
 inline _LIBCPP_INLINE_VISIBILITY float   hypot(   float x,   float 
y,   float z ) { return sqrt(x*x + y*y + z*z); }


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


[PATCH] D29726: [Clang-tidy] Fix for bug 31838: readability-delete-null-pointer does not work for class members

2017-02-12 Thread Mads Ravn via Phabricator via cfe-commits
madsravn updated this revision to Diff 88123.
madsravn marked an inline comment as done.
madsravn added a comment.

Added comment in CHECK-FIX to ensure the line we are referring to is uniquely 
identified.


https://reviews.llvm.org/D29726

Files:
  clang-tidy/readability/DeleteNullPointerCheck.cpp
  clang-tidy/readability/DeleteNullPointerCheck.h
  test/clang-tidy/readability-delete-null-pointer.cpp


Index: test/clang-tidy/readability-delete-null-pointer.cpp
===
--- test/clang-tidy/readability-delete-null-pointer.cpp
+++ test/clang-tidy/readability-delete-null-pointer.cpp
@@ -59,6 +59,16 @@
   } else {
 c2 = c;
   }
+  struct A {
+void foo() {
+  if (mp) // #6
+delete mp;
+  // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: 'if' statement is 
unnecessary; deleting null pointer has no effect 
[readability-delete-null-pointer]
+  // CHECK-FIXES: {{^  }}// #6
+  // CHECK-FIXES-NEXT: delete mp;
+}
+int *mp;
+  };
 }
 
 void g() {
Index: clang-tidy/readability/DeleteNullPointerCheck.h
===
--- clang-tidy/readability/DeleteNullPointerCheck.h
+++ clang-tidy/readability/DeleteNullPointerCheck.h
@@ -16,7 +16,8 @@
 namespace tidy {
 namespace readability {
 
-/// Check whether the 'if' statement is unnecessary before calling 'delete' on 
a pointer.
+/// Check whether the 'if' statement is unnecessary before calling 'delete' on 
a
+/// pointer.
 ///
 /// For the user-facing documentation see:
 /// 
http://clang.llvm.org/extra/clang-tidy/checks/readability-delete-null-pointer.html
Index: clang-tidy/readability/DeleteNullPointerCheck.cpp
===
--- clang-tidy/readability/DeleteNullPointerCheck.cpp
+++ clang-tidy/readability/DeleteNullPointerCheck.cpp
@@ -24,19 +24,28 @@
 to(decl(equalsBoundNode("deletedPointer"
   .bind("deleteExpr");
 
-  const auto PointerExpr =
-  ignoringImpCasts(declRefExpr(to(decl().bind("deletedPointer";
+  const auto DeleteMemberExpr =
+  cxxDeleteExpr(has(castExpr(has(memberExpr(hasDeclaration(
+
fieldDecl(equalsBoundNode("deletedMemberPointer"
+  .bind("deleteMemberExpr");
+
+  const auto PointerExpr = ignoringImpCasts(anyOf(
+  declRefExpr(to(decl().bind("deletedPointer"))),
+  memberExpr(hasDeclaration(fieldDecl().bind("deletedMemberPointer");
+
   const auto PointerCondition = castExpr(hasCastKind(CK_PointerToBoolean),
  hasSourceExpression(PointerExpr));
   const auto BinaryPointerCheckCondition =
   binaryOperator(hasEitherOperand(castExpr(hasCastKind(CK_NullToPointer))),
  hasEitherOperand(PointerExpr));
 
   Finder->addMatcher(
   ifStmt(hasCondition(anyOf(PointerCondition, 
BinaryPointerCheckCondition)),
- hasThen(anyOf(DeleteExpr,
-   compoundStmt(has(DeleteExpr), statementCountIs(1))
-   .bind("compound"
+ hasThen(anyOf(
+ DeleteExpr, DeleteMemberExpr,
+ compoundStmt(has(anyOf(DeleteExpr, DeleteMemberExpr)),
+  statementCountIs(1))
+ .bind("compound"
   .bind("ifWithDelete"),
   this);
 }


Index: test/clang-tidy/readability-delete-null-pointer.cpp
===
--- test/clang-tidy/readability-delete-null-pointer.cpp
+++ test/clang-tidy/readability-delete-null-pointer.cpp
@@ -59,6 +59,16 @@
   } else {
 c2 = c;
   }
+  struct A {
+void foo() {
+  if (mp) // #6
+delete mp;
+  // CHECK-MESSAGES: :[[@LINE-2]]:7: warning: 'if' statement is unnecessary; deleting null pointer has no effect [readability-delete-null-pointer]
+  // CHECK-FIXES: {{^  }}// #6
+  // CHECK-FIXES-NEXT: delete mp;
+}
+int *mp;
+  };
 }
 
 void g() {
Index: clang-tidy/readability/DeleteNullPointerCheck.h
===
--- clang-tidy/readability/DeleteNullPointerCheck.h
+++ clang-tidy/readability/DeleteNullPointerCheck.h
@@ -16,7 +16,8 @@
 namespace tidy {
 namespace readability {
 
-/// Check whether the 'if' statement is unnecessary before calling 'delete' on a pointer.
+/// Check whether the 'if' statement is unnecessary before calling 'delete' on a
+/// pointer.
 ///
 /// For the user-facing documentation see:
 /// http://clang.llvm.org/extra/clang-tidy/checks/readability-delete-null-pointer.html
Index: clang-tidy/readability/DeleteNullPointerCheck.cpp
===
--- clang-tidy/readability/DeleteNullPointerCheck.cpp
+++ clang-tidy/readability/DeleteNullPointerCheck.cpp
@@ -24,19 +24,28 @@
 

[PATCH] D29685: Lit C++11 Compatibility - Function Attributes

2017-02-12 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a reviewer: delesley.
aaron.ballman added a subscriber: delesley.
aaron.ballman added a comment.

The changes to the format string look good to me, but the changes to the 
thread-safety attributes do not make sense. I *think* those are indicative of a 
bug with thready safety analysis, but @delesley would have the definitive 
answer there. I'm not certain how a static function or variable can be safely 
guarded by an instance member.


https://reviews.llvm.org/D29685



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


[PATCH] D28768: [clang-tidy] Add check 'modernize-return-braced-init-list'

2017-02-12 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

I found a few more small nits, but basically LGTM.




Comment at: clang-tidy/modernize/ReturnBracedInitListCheck.cpp:70
+
+  for (int I = 0, NumParams = MatchedFunctionDecl->getNumParams();
+   I < NumParams; ++I) {

`I` should be `unsigned` rather than `int`.



Comment at: clang-tidy/modernize/ReturnBracedInitListCheck.cpp:80-85
+  const SourceRange CallParensRange =
+  MatchedConstructExpr->getParenOrBraceRange();
+
+  // Return if there is no explicit constructor call.
+  if (CallParensRange.isInvalid())
+return;

This could be hoisted above the `for` loop to early return while doing less 
work.



Comment at: clang-tidy/modernize/ReturnBracedInitListCheck.cpp:88
+  // Range for constructor name and opening brace.
+  auto CtorCallSourceRange = CharSourceRange::getTokenRange(
+  Loc, CallParensRange.getBegin().getLocWithOffset(-1));

Not keen on this use of `auto`, as the type is not spelled out in the 
initialization.


Repository:
  rL LLVM

https://reviews.llvm.org/D28768



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


[PATCH] D29692: [clang-tidy] add check modernize-use-const-instead-of-define

2017-02-12 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

One big concern I have with this is the potential to introduce ODR violations 
into the user's code. We may want to limit this check to only trigger on macros 
that are defined in the primary source file of the TU rather than something in 
the include stack.

One other problem with this advice is that a constant variable isn't always the 
same thing as a macro replacement value. For instance, a const variable 
requires the ability to take the address of the variable, which means that 
space must be reserved for it at runtime. A frequent way around this is to use 
enumerator rather than constant variables for integral types. The enumerations 
are not prone to ODR violations and enumerators are not things with storage.




Comment at: clang-tidy/modernize/UseConstInsteadOfDefineCheck.cpp:41
+
+/// numeric values may have + or - signs in front of them
+/// others like ~ are not so obvious and depend on usage

Make sure the comments have proper capitalization and punctuation, here and 
elsewhere.



Comment at: clang-tidy/modernize/UseConstInsteadOfDefineCheck.cpp:43
+/// others like ~ are not so obvious and depend on usage
+static bool isReasonableNumberPrefix(const Token ) {
+  return T.isOneOf(tok::plus, tok::minus);

I don't think most of these helper functions really clarify the code all that 
much (except for perhaps `isAnyCharLiteral()`, but even that's debatable). I 
would just fold these into the code.



Comment at: clang-tidy/modernize/UseConstInsteadOfDefineCheck.cpp:83-84
+}
+// numbers may have a prefix, however chars with a prefix are rather
+// strange... let's not touch them
+else if (isAnyParenthesis(Tok) || isAnyNumericLiteral(Tok) ||

I don't really agree with this comment. `L'1'` is a reasonable character 
constant and not at all strange. You should add tests for that case and perhaps 
clarify the comment.



Comment at: clang-tidy/modernize/UseConstInsteadOfDefineCheck.cpp:86
+else if (isAnyParenthesis(Tok) || isAnyNumericLiteral(Tok) ||
+ (!hasPrefix && isAnyCharLiteral(Tok))) {
+  // prefix shall not be accepted anymore after any number

What about string literals? e.g., `#define NAME "foobar"`



Comment at: clang-tidy/modernize/UseConstInsteadOfDefineCheck.h:19-21
+/// C++ const variables should be preferred over #define statements
+///
+/// const variables obey type checking and scopes

Missing punctuation at the end of the sentences in these comments.



Comment at: docs/clang-tidy/checks/modernize-use-const-instead-of-define.rst:14
+
+  `// calc.h
+  namespace RealCalculation {

Extraneous ` before the comment.


https://reviews.llvm.org/D29692



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


[PATCH] D29839: [clang-tidy] New misc-istream-overflow check

2017-02-12 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

In https://reviews.llvm.org/D29839#674301, @xazax.hun wrote:

> Shouldn't this be a path sensitive check within the clang static analyzer 
> instead? So branches are properly handled and interprocedural analysis is 
> done.


I agree; I think this check should be part of the static analyzer because it is 
path sensitive if we want it to be particularly useful. As it stands now, it 
will catch trivial bugs, but by designing it as a clang-tidy check, it isn't 
easily extensible to catch the bigger bugs across procedures.


https://reviews.llvm.org/D29839



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


[PATCH] D29868: Recover more gracefully when __declspec is not supported as a keyword

2017-02-12 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: lib/Parse/ParseDecl.cpp:2973
+  // recognize that scenario and recover gracefully.
+  if (!getLangOpts().MicrosoftExt && Tok.is(tok::identifier) &&
+  Tok.getIdentifierInfo()->getName().equals("__declspec")) {

compnerd wrote:
> Shouldn't this be `getLangOpts().DeclSpecKeyword` since you don't need the 
> Microsoft extensions as much as you need the declspec keyword to be 
> processed.  Having `MicrosoftExt` implicitly enable `DeclSpecKeyword` (just 
> as borland mode enables it as well).  I suppose that it would fail anyways as 
> `Tok.is(tok::identifier)` would fail.
That's a good point, I've corrected.



Comment at: lib/Parse/ParseDecl.cpp:2989
+
+  Diag(Loc, diag::err_ms_attributes_not_enabled);
+  continue;

compnerd wrote:
> I think that we want to emit the diagnostic even if there is no parenthesis 
> as `__declspec` is a reserved identifier, and we would normally diagnose the 
> bad `__declspec` (expected '(' after '__declspec').
Yes, but it could also lead to a rejecting code that we used to accept and 
properly handle when __declspec is an identifier rather than a keyword. e.g.,
```
struct __declspec {};

__declspec some_func(void);
```
By looking for the paren, we run less risk of breaking working code, even if 
that code abuses the implementation namespace (after all, __declspec it not a 
keyword in this scenario).


https://reviews.llvm.org/D29868



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


[PATCH] D29868: Recover more gracefully when __declspec is not supported as a keyword

2017-02-12 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman updated this revision to Diff 88122.
aaron.ballman marked an inline comment as done.
aaron.ballman added a comment.

Correcting review feedback.


https://reviews.llvm.org/D29868

Files:
  include/clang/Basic/DiagnosticParseKinds.td
  lib/Parse/ParseDecl.cpp
  test/Parser/declspec-recovery.c
  test/Parser/declspec-supported.c


Index: test/Parser/declspec-supported.c
===
--- test/Parser/declspec-supported.c
+++ test/Parser/declspec-supported.c
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -triple i386-pc-unknown -fsyntax-only -fms-extensions 
-verify %s
+// RUN: %clang_cc1 -triple i386-pc-unknown -fsyntax-only -fdeclspec -verify %s
+// expected-no-diagnostics
+
+__declspec(naked) void f(void) {}
+
+struct S {
+  __declspec(property(get=Getter, put=Setter)) int X;
+  int Y;
+};
Index: test/Parser/declspec-recovery.c
===
--- test/Parser/declspec-recovery.c
+++ test/Parser/declspec-recovery.c
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -triple i386-pc-unknown -fsyntax-only -verify %s
+
+__declspec(naked) void f(void) {} // expected-error{{'__declspec' attributes 
are not enabled; use '-fdeclspec' or '-fms-extensions' to enable support for 
__declspec attributes}}
+
+struct S {
+  __declspec(property(get=Getter, put=Setter)) int X; // 
expected-error{{'__declspec' attributes are not enabled; use '-fdeclspec' or 
'-fms-extensions' to enable support for __declspec attributes}}
+  int Y;
+};
Index: lib/Parse/ParseDecl.cpp
===
--- lib/Parse/ParseDecl.cpp
+++ lib/Parse/ParseDecl.cpp
@@ -2966,6 +2966,31 @@
   if (DS.hasTypeSpecifier())
 goto DoneWithDeclSpec;
 
+  // If the token is an identifier named "__declspec" and Microsoft
+  // extensions are not enabled, it is likely that there will be cascading
+  // parse errors if this really is a __declspec attribute. Attempt to
+  // recognize that scenario and recover gracefully.
+  if (!getLangOpts().DeclSpecKeyword && Tok.is(tok::identifier) &&
+  Tok.getIdentifierInfo()->getName().equals("__declspec")) {
+// The next token should be an open paren. If it is, eat the entire
+// attribute declaration and continue.
+if (NextToken().is(tok::l_paren)) {
+  // Consume the __declspec identifier.
+  SourceLocation Loc = ConsumeToken();
+
+  // Eat the parens and everything between them.
+  BalancedDelimiterTracker T(*this, tok::l_paren);
+  if (T.consumeOpen()) {
+assert(false && "Not a left paren?");
+return;
+  }
+  T.skipToEnd();
+
+  Diag(Loc, diag::err_ms_attributes_not_enabled);
+  continue;
+}
+  }
+
   // In C++, check to see if this is a scope specifier like foo::bar::, if
   // so handle it as such.  This is important for ctor parsing.
   if (getLangOpts().CPlusPlus) {
Index: include/clang/Basic/DiagnosticParseKinds.td
===
--- include/clang/Basic/DiagnosticParseKinds.td
+++ include/clang/Basic/DiagnosticParseKinds.td
@@ -176,6 +176,9 @@
 def warn_attribute_no_decl : Warning<
   "attribute %0 ignored, because it is not attached to a declaration">, 
   InGroup;
+def err_ms_attributes_not_enabled : Error<
+  "'__declspec' attributes are not enabled; use '-fdeclspec' or "
+  "'-fms-extensions' to enable support for __declspec attributes">;
 def err_expected_method_body : Error<"expected method body">;
 def err_declspec_after_virtspec : Error<
   "'%0' qualifier may not appear after the virtual specifier '%1'">;


Index: test/Parser/declspec-supported.c
===
--- test/Parser/declspec-supported.c
+++ test/Parser/declspec-supported.c
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -triple i386-pc-unknown -fsyntax-only -fms-extensions -verify %s
+// RUN: %clang_cc1 -triple i386-pc-unknown -fsyntax-only -fdeclspec -verify %s
+// expected-no-diagnostics
+
+__declspec(naked) void f(void) {}
+
+struct S {
+  __declspec(property(get=Getter, put=Setter)) int X;
+  int Y;
+};
Index: test/Parser/declspec-recovery.c
===
--- test/Parser/declspec-recovery.c
+++ test/Parser/declspec-recovery.c
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -triple i386-pc-unknown -fsyntax-only -verify %s
+
+__declspec(naked) void f(void) {} // expected-error{{'__declspec' attributes are not enabled; use '-fdeclspec' or '-fms-extensions' to enable support for __declspec attributes}}
+
+struct S {
+  __declspec(property(get=Getter, put=Setter)) int X; // expected-error{{'__declspec' attributes are not enabled; use '-fdeclspec' or '-fms-extensions' to enable support for __declspec attributes}}
+  int Y;
+};
Index: lib/Parse/ParseDecl.cpp