r279207 - clang/test/Modules/prebuilt-module.m: Prune "-triple" to fix a configuration mismatch.

2016-08-18 Thread NAKAMURA Takumi via cfe-commits
Author: chapuni
Date: Fri Aug 19 00:25:26 2016
New Revision: 279207

URL: http://llvm.org/viewvc/llvm-project?rev=279207&view=rev
Log:
clang/test/Modules/prebuilt-module.m: Prune "-triple" to fix a configuration 
mismatch.

Modified:
cfe/trunk/test/Modules/prebuilt-module.m

Modified: cfe/trunk/test/Modules/prebuilt-module.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/prebuilt-module.m?rev=279207&r1=279206&r2=279207&view=diff
==
--- cfe/trunk/test/Modules/prebuilt-module.m (original)
+++ cfe/trunk/test/Modules/prebuilt-module.m Fri Aug 19 00:25:26 2016
@@ -1,6 +1,6 @@
 // RUN: rm -rf %t
 //
-// RUN: %clang_cc1 -fmodules -x objective-c -I %S/Inputs/prebuilt-module 
-triple %itanium_abi_triple -emit-module 
%S/Inputs/prebuilt-module/module.modulemap -fmodule-name=prebuilt -o 
%t/prebuilt.pcm
+// RUN: %clang_cc1 -fmodules -x objective-c -I %S/Inputs/prebuilt-module 
-emit-module %S/Inputs/prebuilt-module/module.modulemap -fmodule-name=prebuilt 
-o %t/prebuilt.pcm
 // RUN: %clang_cc1 -fmodules -fprebuilt-module-path=%t/ -fdisable-module-hash 
%s -verify
 
 // expected-no-diagnostics


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


[PATCH] D23705: [GraphTraits] Make nodes_iterator dereference to NodeRef

2016-08-18 Thread Tim Shen via cfe-commits
timshen created this revision.
timshen added a reviewer: dblaikie.
timshen added a subscriber: cfe-commits.

Currently nodes_iterator may dereference to a NodeType* or a NodeType&. Make 
them all dereference to NodeType*, which is NodeRef later. Corresponding LLVM 
change: D23704

https://reviews.llvm.org/D23705

Files:
  include/clang/Analysis/Analyses/Dominators.h
  include/clang/Analysis/CFG.h
  include/clang/Analysis/CallGraph.h

Index: include/clang/Analysis/CallGraph.h
===
--- include/clang/Analysis/CallGraph.h
+++ include/clang/Analysis/CallGraph.h
@@ -205,7 +205,8 @@
 return CGN->getRoot();  // Start at the external node!
   }
   typedef std::pair PairTy;
-  typedef std::pointer_to_unary_function DerefFun;
+  typedef std::pointer_to_unary_function
+  DerefFun;
   // nodes_iterator/begin/end - Allow iteration over all nodes in the graph
   typedef mapped_iterator nodes_iterator;
 
@@ -215,9 +216,7 @@
   static nodes_iterator nodes_end  (clang::CallGraph *CG) {
 return map_iterator(CG->end(), DerefFun(CGdereference));
   }
-  static clang::CallGraphNode &CGdereference(PairTy P) {
-return *(P.second);
-  }
+  static clang::CallGraphNode *CGdereference(PairTy P) { return P.second; }
 
   static unsigned size(clang::CallGraph *CG) {
 return CG->size();
@@ -230,7 +229,8 @@
 return CGN->getRoot();
   }
   typedef std::pair PairTy;
-  typedef std::pointer_to_unary_function DerefFun;
+  typedef std::pointer_to_unary_function
+  DerefFun;
   // nodes_iterator/begin/end - Allow iteration over all nodes in the graph
   typedef mapped_iterator nodes_iterator;
@@ -241,9 +241,7 @@
   static nodes_iterator nodes_end(const clang::CallGraph *CG) {
 return map_iterator(CG->end(), DerefFun(CGdereference));
   }
-  static clang::CallGraphNode &CGdereference(PairTy P) {
-return *(P.second);
-  }
+  static clang::CallGraphNode *CGdereference(PairTy P) { return P.second; }
 
   static unsigned size(const clang::CallGraph *CG) {
 return CG->size();
Index: include/clang/Analysis/CFG.h
===
--- include/clang/Analysis/CFG.h
+++ include/clang/Analysis/CFG.h
@@ -761,55 +761,6 @@
 AddCXXNewAllocator(false), AddCXXDefaultInitExprInCtors(false) {}
   };
 
-  /// \brief Provides a custom implementation of the iterator class to have the
-  /// same interface as Function::iterator - iterator returns CFGBlock
-  /// (not a pointer to CFGBlock).
-  class graph_iterator {
-  public:
-typedef CFGBlockvalue_type;
-typedef value_type& reference;
-typedef value_type* pointer;
-typedef BumpVector::iterator ImplTy;
-
-graph_iterator(const ImplTy &i) : I(i) {}
-
-bool operator==(const graph_iterator &X) const { return I == X.I; }
-bool operator!=(const graph_iterator &X) const { return I != X.I; }
-
-reference operator*()const { return **I; }
-pointer operator->() const { return  *I; }
-operator CFGBlock* ()  { return  *I; }
-
-graph_iterator &operator++() { ++I; return *this; }
-graph_iterator &operator--() { --I; return *this; }
-
-  private:
-ImplTy I;
-  };
-
-  class const_graph_iterator {
-  public:
-typedef const CFGBlock  value_type;
-typedef value_type& reference;
-typedef value_type* pointer;
-typedef BumpVector::const_iterator ImplTy;
-
-const_graph_iterator(const ImplTy &i) : I(i) {}
-
-bool operator==(const const_graph_iterator &X) const { return I == X.I; }
-bool operator!=(const const_graph_iterator &X) const { return I != X.I; }
-
-reference operator*() const { return **I; }
-pointer operator->()  const { return  *I; }
-operator CFGBlock* () const { return  *I; }
-
-const_graph_iterator &operator++() { ++I; return *this; }
-const_graph_iterator &operator--() { --I; return *this; }
-
-  private:
-ImplTy I;
-  };
-
   /// buildCFG - Builds a CFG from an AST.
   static std::unique_ptr buildCFG(const Decl *D, Stmt *AST, ASTContext *C,
const BuildOptions &BO);
@@ -845,14 +796,10 @@
   const_iteratorbegin()   const{ return Blocks.begin(); }
   const_iteratorend() const{ return Blocks.end(); }
 
-  graph_iterator nodes_begin() { return graph_iterator(Blocks.begin()); }
-  graph_iterator nodes_end() { return graph_iterator(Blocks.end()); }
-  const_graph_iterator nodes_begin() const {
-return const_graph_iterator(Blocks.begin());
-  }
-  const_graph_iterator nodes_end() const {
-return const_graph_iterator(Blocks.end());
-  }
+  iterator nodes_begin() { return iterator(Blocks.begin()); }
+  iterator nodes_end() { return iterator(Blocks.end()); }
+  const_iterator nodes_begin() const { return const_iterator(Blocks.begin()); }
+  const_iter

r279206 - Re-commit [OpenCL] AMDGCN: Fix size_t type

2016-08-18 Thread Yaxun Liu via cfe-commits
Author: yaxunl
Date: Fri Aug 19 00:17:25 2016
New Revision: 279206

URL: http://llvm.org/viewvc/llvm-project?rev=279206&view=rev
Log:
Re-commit [OpenCL] AMDGCN: Fix size_t type

There was a premature cast to pointer type in emitPointerArithmetic which 
caused assertion in tests with assertion enabled.

Added:
cfe/trunk/test/CodeGenOpenCL/size_t.cl
Modified:
cfe/trunk/include/clang/Basic/TargetInfo.h
cfe/trunk/lib/Basic/TargetInfo.cpp
cfe/trunk/lib/Basic/Targets.cpp
cfe/trunk/lib/CodeGen/CGExprScalar.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/lib/CodeGen/CodeGenTypeCache.h

Modified: cfe/trunk/include/clang/Basic/TargetInfo.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TargetInfo.h?rev=279206&r1=279205&r2=279206&view=diff
==
--- cfe/trunk/include/clang/Basic/TargetInfo.h (original)
+++ cfe/trunk/include/clang/Basic/TargetInfo.h Fri Aug 19 00:17:25 2016
@@ -294,6 +294,11 @@ public:
 return AddrSpace == 0 ? PointerAlign : getPointerAlignV(AddrSpace);
   }
 
+  /// \brief Return the maximum width of pointers on this target.
+  virtual uint64_t getMaxPointerWidth() const {
+return PointerWidth;
+  }
+
   /// \brief Return the size of '_Bool' and C++ 'bool' for this target, in 
bits.
   unsigned getBoolWidth() const { return BoolWidth; }
 

Modified: cfe/trunk/lib/Basic/TargetInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/TargetInfo.cpp?rev=279206&r1=279205&r2=279206&view=diff
==
--- cfe/trunk/lib/Basic/TargetInfo.cpp (original)
+++ cfe/trunk/lib/Basic/TargetInfo.cpp Fri Aug 19 00:17:25 2016
@@ -306,8 +306,9 @@ void TargetInfo::adjust(const LangOption
 }
 LongDoubleWidth = LongDoubleAlign = 128;
 
-assert(PointerWidth == 32 || PointerWidth == 64);
-bool Is32BitArch = PointerWidth == 32;
+unsigned MaxPointerWidth = getMaxPointerWidth();
+assert(MaxPointerWidth == 32 || MaxPointerWidth == 64);
+bool Is32BitArch = MaxPointerWidth == 32;
 SizeType = Is32BitArch ? UnsignedInt : UnsignedLong;
 PtrDiffType = Is32BitArch ? SignedInt : SignedLong;
 IntPtrType = Is32BitArch ? SignedInt : SignedLong;

Modified: cfe/trunk/lib/Basic/Targets.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=279206&r1=279205&r2=279206&view=diff
==
--- cfe/trunk/lib/Basic/Targets.cpp (original)
+++ cfe/trunk/lib/Basic/Targets.cpp Fri Aug 19 00:17:25 2016
@@ -2004,6 +2004,10 @@ public:
 }
   }
 
+  uint64_t getMaxPointerWidth() const override {
+return getTriple().getArch() == llvm::Triple::amdgcn ? 64 : 32;
+  }
+
   const char * getClobbers() const override {
 return "";
   }

Modified: cfe/trunk/lib/CodeGen/CGExprScalar.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprScalar.cpp?rev=279206&r1=279205&r2=279206&view=diff
==
--- cfe/trunk/lib/CodeGen/CGExprScalar.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprScalar.cpp Fri Aug 19 00:17:25 2016
@@ -787,7 +787,7 @@ Value *ScalarExprEmitter::EmitScalarConv
   // Handle pointer conversions next: pointers can only be converted to/from
   // other pointers and integers. Check for pointer types in terms of LLVM, as
   // some native types (like Obj-C id) may map to a pointer type.
-  if (isa(DstTy)) {
+  if (auto DstPT = dyn_cast(DstTy)) {
 // The source value may be an integer, or a pointer.
 if (isa(SrcTy))
   return Builder.CreateBitCast(Src, DstTy, "conv");
@@ -795,7 +795,7 @@ Value *ScalarExprEmitter::EmitScalarConv
 assert(SrcType->isIntegerType() && "Not ptr->ptr or int->ptr conversion?");
 // First, convert to the correct width so that we control the kind of
 // extension.
-llvm::Type *MiddleTy = CGF.IntPtrTy;
+llvm::Type *MiddleTy = CGF.CGM.getDataLayout().getIntPtrType(DstPT);
 bool InputSigned = SrcType->isSignedIntegerOrEnumerationType();
 llvm::Value* IntResult =
 Builder.CreateIntCast(Src, MiddleTy, InputSigned, "conv");
@@ -1510,12 +1510,13 @@ Value *ScalarExprEmitter::VisitCastExpr(
 
 // First, convert to the correct width so that we control the kind of
 // extension.
-llvm::Type *MiddleTy = CGF.IntPtrTy;
+auto DestLLVMTy = ConvertType(DestTy);
+llvm::Type *MiddleTy = CGF.CGM.getDataLayout().getIntPtrType(DestLLVMTy);
 bool InputSigned = E->getType()->isSignedIntegerOrEnumerationType();
 llvm::Value* IntResult =
   Builder.CreateIntCast(Src, MiddleTy, InputSigned, "conv");
 
-return Builder.CreateIntToPtr(IntResult, ConvertType(DestTy));
+return Builder.CreateIntToPtr(IntResult, DestLLVMTy);
   }
   case CK_PointerToIntegral:
 assert(!DestTy->isBooleanType() && "bool should use PointerToBool"

Re: [PATCH] D23493: Fix PR28366: Teach the const-expression evaluator to be more fault tolerant with non-const enclosing local variables, or otherwise fold them if const.

2016-08-18 Thread Faisal Vali via cfe-commits
faisalv added a comment.

Address Richard's comments.



Comment at: lib/Sema/SemaTemplateInstantiateDecl.cpp:190
@@ -189,3 +189,3 @@
   if (A->getCond()->isValueDependent() && !Cond->isValueDependent() &&
-  !Expr::isPotentialConstantExprUnevaluated(Cond, cast(Tmpl),
+  !Expr::isPotentialConstantExprUnevaluated(Cond, cast(New),
 Diags)) {

rsmith wrote:
> Do we have existing test coverage for this (tests that fail with the 
> ExprConstant change if we don't fix this at the same time)?
Yes we do.  That's how I realized it needed to be fixed - it's enable_if.cpp in 
SemaCXX that has the following test:
template  T templatedBar(T m) attribute((enable_if(m > 0, ""))) { 
return T(); }



https://reviews.llvm.org/D23493



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


Re: [PATCH] D23493: Fix PR28366: Teach the const-expression evaluator to be more fault tolerant with non-const enclosing local variables, or otherwise fold them if const.

2016-08-18 Thread Faisal Vali via cfe-commits
faisalv updated this revision to Diff 68644.
faisalv marked 4 inline comments as done.
faisalv added a comment.

Address Richard's comments.


https://reviews.llvm.org/D23493

Files:
  lib/AST/ExprConstant.cpp
  lib/Sema/SemaTemplateInstantiateDecl.cpp
  test/SemaCXX/constant-expression-cxx11.cpp

Index: test/SemaCXX/constant-expression-cxx11.cpp
===
--- test/SemaCXX/constant-expression-cxx11.cpp
+++ test/SemaCXX/constant-expression-cxx11.cpp
@@ -2066,3 +2066,33 @@
   constexpr Z z(1);
   static_assert(z.w == 1 && z.x == 2 && z.y == 3 && z.z == 4, "");
 }
+
+
+namespace PR28366 {
+namespace ns1 {
+
+void f(char c) { //expected-note2{{declared here}}
+  struct X {
+static constexpr char f() { //expected-error{{never produces a constant 
expression}}
+  return c; //expected-error{{reference to local}} 
expected-note{{non-const variable}}
+}
+  };
+  int I = X::f();
+}
+
+void g() {
+  const int c = 'c';
+  static const int d = 'd';
+  struct X {
+static constexpr int f() {
+  return c + d;
+}
+  };
+  static_assert(X::f() == c + d,"");
+}
+
+
+} // end ns1
+
+} //end ns PR28366
+
Index: lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -187,7 +187,7 @@
 
   SmallVector Diags;
   if (A->getCond()->isValueDependent() && !Cond->isValueDependent() &&
-  !Expr::isPotentialConstantExprUnevaluated(Cond, cast(Tmpl),
+  !Expr::isPotentialConstantExprUnevaluated(Cond, cast(New),
 Diags)) {
 S.Diag(A->getLocation(), diag::err_enable_if_never_constant_expr);
 for (int I = 0, N = Diags.size(); I != N; ++I)
Index: lib/AST/ExprConstant.cpp
===
--- lib/AST/ExprConstant.cpp
+++ lib/AST/ExprConstant.cpp
@@ -4788,10 +4788,21 @@
   return Error(E);
 }
 
+
 bool LValueExprEvaluator::VisitVarDecl(const Expr *E, const VarDecl *VD) {
   CallStackFrame *Frame = nullptr;
-  if (VD->hasLocalStorage() && Info.CurrentCall->Index > 1)
-Frame = Info.CurrentCall;
+  if (VD->hasLocalStorage() && Info.CurrentCall->Index > 1) {
+// Only if a local variable was declared in the function currently being
+// evaluated, do we expect to be able to find its value in the current
+// frame. (Otherwise it was likely declared in an enclosing context and
+// could either have a valid evaluatable value (for e.g. a constexpr
+// variable) or be ill-formed (and trigger an appropriate evaluation
+// diagnostic)).
+if (Info.CurrentCall->Callee &&
+Info.CurrentCall->Callee->Equals(VD->getDeclContext())) {
+  Frame = Info.CurrentCall;
+}
+  }
 
   if (!VD->getType()->isReferenceType()) {
 if (Frame) {


Index: test/SemaCXX/constant-expression-cxx11.cpp
===
--- test/SemaCXX/constant-expression-cxx11.cpp
+++ test/SemaCXX/constant-expression-cxx11.cpp
@@ -2066,3 +2066,33 @@
   constexpr Z z(1);
   static_assert(z.w == 1 && z.x == 2 && z.y == 3 && z.z == 4, "");
 }
+
+
+namespace PR28366 {
+namespace ns1 {
+
+void f(char c) { //expected-note2{{declared here}}
+  struct X {
+static constexpr char f() { //expected-error{{never produces a constant expression}}
+  return c; //expected-error{{reference to local}} expected-note{{non-const variable}}
+}
+  };
+  int I = X::f();
+}
+
+void g() {
+  const int c = 'c';
+  static const int d = 'd';
+  struct X {
+static constexpr int f() {
+  return c + d;
+}
+  };
+  static_assert(X::f() == c + d,"");
+}
+
+
+} // end ns1
+
+} //end ns PR28366
+
Index: lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -187,7 +187,7 @@
 
   SmallVector Diags;
   if (A->getCond()->isValueDependent() && !Cond->isValueDependent() &&
-  !Expr::isPotentialConstantExprUnevaluated(Cond, cast(Tmpl),
+  !Expr::isPotentialConstantExprUnevaluated(Cond, cast(New),
 Diags)) {
 S.Diag(A->getLocation(), diag::err_enable_if_never_constant_expr);
 for (int I = 0, N = Diags.size(); I != N; ++I)
Index: lib/AST/ExprConstant.cpp
===
--- lib/AST/ExprConstant.cpp
+++ lib/AST/ExprConstant.cpp
@@ -4788,10 +4788,21 @@
   return Error(E);
 }
 
+
 bool LValueExprEvaluator::VisitVarDecl(const Expr *E, const VarDecl *VD) {
   CallStackFrame *Frame = nullptr;
-  if (VD->hasLocalStorage() && Info.CurrentCall->Index > 1)
-Frame = Info.CurrentCall;
+  if (VD->hasLocalStorage() && Info.CurrentCall->Index > 1) {
+// Only if a local variable was declared in the function currently being
+// eval

Re: Upgrade and fix clang-format-vs

2016-08-18 Thread Zachary Turner via cfe-commits
The key.snk is generated when you build, the problem is the csproj file
hardcodes the directory to the sdk instead of using the appropriate project
system variable like $(SDKToolsDir)
On Thu, Aug 18, 2016 at 7:09 PM Zachary Turner  wrote:

> Llvm doesn't support vs2012 anymore, as long as it supports vs2013 it's
> fine
> On Thu, Aug 18, 2016 at 7:07 PM Antonio Maiorano 
> wrote:
>
>> Hi,
>>
>> What I meant by upgrade was simply making it build in VS 2015. However,
>> you bring up a valid point about making sure the extension will continue to
>> work in VS 2012. I will look into that. Like those references that go from
>> 10 to 14 that point out; I wonder if instead I should be able to bring in
>> those version 10 assemblies via NuGet. I'll take a closer look.
>>
>> Part of my change, however, seems to imply that the extension (vsix)
>> project would not build correctly even in VS 2012. For instance, the
>> missing Key.snk file. I don't have VS 2012 installed at the moment, so I
>> cannot validate.
>>
>> Thanks,
>>
>> Antonio
>>
>>
>>
>> On Thu, 18 Aug 2016 at 19:38 Hans Wennborg  wrote:
>>
>>> Hi Antonio,
>>>
>>> On Wed, Aug 17, 2016 at 8:15 AM, Antonio Maiorano via cfe-commits
>>>  wrote:
>>> > This patch for clang-format-vs includes the following:
>>> >
>>> > - Upgrade to VS 2015, including .NET framework upgrade from 4.0 to
>>> 4.5, and
>>> > upgrading Microsoft.VisualStudio references to v14 versions
>>> > - Fix build by removing dependency on "Key.snk" file which was never
>>> checked
>>> > in (and not really required anyway)
>>> > - Add ".vs" directory to svn ignore (new folder that VS 2015 creates
>>> for
>>> > user settings)
>>>
>>> "What does "Upgrade to VS 2015 mean? Adding support for running the
>>> plugin in VS2015, or does it mean requiring VS2015 for building?
>>>
>>> +zturner: I thought the plugin already worked in VS 2015?
>>>
>>> I mostly just build the plugin without knowing exactly how this stuff
>>> works, but looking at the patch I'm worried that you're increasing the
>>> required version for building it? I see a bunch of values going from
>>> 10 (VS 2012) to 14 (VS 2015).
>>>
>>> Thanks,
>>> Hans
>>>
>>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: Upgrade and fix clang-format-vs

2016-08-18 Thread Zachary Turner via cfe-commits
Llvm doesn't support vs2012 anymore, as long as it supports vs2013 it's
fine
On Thu, Aug 18, 2016 at 7:07 PM Antonio Maiorano 
wrote:

> Hi,
>
> What I meant by upgrade was simply making it build in VS 2015. However,
> you bring up a valid point about making sure the extension will continue to
> work in VS 2012. I will look into that. Like those references that go from
> 10 to 14 that point out; I wonder if instead I should be able to bring in
> those version 10 assemblies via NuGet. I'll take a closer look.
>
> Part of my change, however, seems to imply that the extension (vsix)
> project would not build correctly even in VS 2012. For instance, the
> missing Key.snk file. I don't have VS 2012 installed at the moment, so I
> cannot validate.
>
> Thanks,
>
> Antonio
>
>
>
> On Thu, 18 Aug 2016 at 19:38 Hans Wennborg  wrote:
>
>> Hi Antonio,
>>
>> On Wed, Aug 17, 2016 at 8:15 AM, Antonio Maiorano via cfe-commits
>>  wrote:
>> > This patch for clang-format-vs includes the following:
>> >
>> > - Upgrade to VS 2015, including .NET framework upgrade from 4.0 to 4.5,
>> and
>> > upgrading Microsoft.VisualStudio references to v14 versions
>> > - Fix build by removing dependency on "Key.snk" file which was never
>> checked
>> > in (and not really required anyway)
>> > - Add ".vs" directory to svn ignore (new folder that VS 2015 creates for
>> > user settings)
>>
>> "What does "Upgrade to VS 2015 mean? Adding support for running the
>> plugin in VS2015, or does it mean requiring VS2015 for building?
>>
>> +zturner: I thought the plugin already worked in VS 2015?
>>
>> I mostly just build the plugin without knowing exactly how this stuff
>> works, but looking at the patch I'm worried that you're increasing the
>> required version for building it? I see a bunch of values going from
>> 10 (VS 2012) to 14 (VS 2015).
>>
>> Thanks,
>> Hans
>>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libunwind] r279195 - Creating release candidate rc2 from release_390 branch

2016-08-18 Thread Hans Wennborg via cfe-commits
Author: hans
Date: Thu Aug 18 20:42:56 2016
New Revision: 279195

URL: http://llvm.org/viewvc/llvm-project?rev=279195&view=rev
Log:
Creating release candidate rc2 from release_390 branch

Added:
libunwind/tags/RELEASE_390/rc2/   (props changed)
  - copied from r279194, libunwind/branches/release_39/

Propchange: libunwind/tags/RELEASE_390/rc2/
--
svn:mergeinfo = /libunwind/trunk:276128,277868,278029


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


r279196 - C++ Modules TS: support parsing the 'module' declaration (including extensions

2016-08-18 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Thu Aug 18 20:43:06 2016
New Revision: 279196

URL: http://llvm.org/viewvc/llvm-project?rev=279196&view=rev
Log:
C++ Modules TS: support parsing the 'module' declaration (including extensions
from p0273r0 approved by EWG). We'll eventually need to handle this from the
lexer as well, in order to disallow preprocessor directives preceding the
module declaration and to support macro import.

Modified:
cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/include/clang/Parse/Parser.h
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Parse/ParseAST.cpp
cfe/trunk/lib/Parse/Parser.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/Parser/cxx-modules-import.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td?rev=279196&r1=279195&r2=279196&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td Thu Aug 18 20:43:06 
2016
@@ -1022,7 +1022,11 @@ def warn_pragma_unroll_cuda_value_in_par
 
 let CategoryName = "Modules Issue" in {
 def err_module_expected_ident : Error<
-  "expected a module name after module import">;
+  "expected a module name after module%select{| import}0">;
+def err_unexpected_module_kind : Error<
+  "unexpected module kind %0; expected 'implementation' or 'partition'">;
+def err_attribute_not_module_attr : Error<
+  "%0 attribute cannot be applied to a module">;
 def err_attribute_not_import_attr : Error<
   "%0 attribute cannot be applied to a module import">;
 def err_module_expected_semi : Error<

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=279196&r1=279195&r2=279196&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Thu Aug 18 20:43:06 
2016
@@ -8462,6 +8462,11 @@ def note_related_result_type_explicit :
 }
 
 let CategoryName = "Modules Issue" in {
+def err_module_interface_implementation_mismatch : Error<
+  "%select{'module'|'module partition'|'module implementation'}0 declaration "
+  "found while %select{not |not |}0building module interface">;
+def err_current_module_name_mismatch : Error<
+  "module name '%0' specified on command line does not match name of module">;
 def err_module_private_specialization : Error<
   "%select{template|partial|member}0 specialization cannot be "
   "declared __module_private__">;

Modified: cfe/trunk/include/clang/Parse/Parser.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=279196&r1=279195&r2=279196&view=diff
==
--- cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/trunk/include/clang/Parse/Parser.h Thu Aug 18 20:43:06 2016
@@ -278,6 +278,9 @@ public:
   ///
   void Initialize();
 
+  /// Parse the first top-level declaration in a translation unit.
+  bool ParseFirstTopLevelDecl(DeclGroupPtrTy &Result);
+
   /// ParseTopLevelDecl - Parse one top-level declaration. Returns true if
   /// the EOF was encountered.
   bool ParseTopLevelDecl(DeclGroupPtrTy &Result);
@@ -2656,6 +2659,7 @@ private:
 
   
//======//
   // Modules
+  DeclGroupPtrTy ParseModuleDecl();
   DeclGroupPtrTy ParseModuleImport(SourceLocation AtLoc);
   bool parseMisplacedModuleImport();
   bool tryParseMisplacedModuleImport() {
@@ -2666,6 +2670,11 @@ private:
 return false;
   }
 
+  bool ParseModuleName(
+  SourceLocation UseLoc,
+  SmallVectorImpl> &Path,
+  bool IsImport);
+
   
//======//
   // C++11/G++: Type Traits [Type-Traits.html in the GCC manual]
   ExprResult ParseTypeTrait();

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=279196&r1=279195&r2=279196&view=diff
==
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Thu Aug 18 20:43:06 2016
@@ -1859,6 +1859,17 @@ public:
   AttributeList *AttrList,
   SourceLocation SemiLoc);
 
+  enum class ModuleDeclKind {
+Module, ///< 'module X;'
+Partition,  ///< 'module partition X;'
+Implementation, ///< 'module implementation X;'
+  };
+
+  /// The parser has processed a module-declaration that begins the definition
+  /// of a module inter

[libcxx] r279188 - Creating release candidate rc2 from release_390 branch

2016-08-18 Thread Hans Wennborg via cfe-commits
Author: hans
Date: Thu Aug 18 20:42:35 2016
New Revision: 279188

URL: http://llvm.org/viewvc/llvm-project?rev=279188&view=rev
Log:
Creating release candidate rc2 from release_390 branch

Added:
libcxx/tags/RELEASE_390/rc2/   (props changed)
  - copied from r279187, libcxx/branches/release_39/

Propchange: libcxx/tags/RELEASE_390/rc2/
--
--- svn:mergeinfo (added)
+++ svn:mergeinfo Thu Aug 18 20:42:35 2016
@@ -0,0 +1,2 @@
+/libcxx/branches/apple:136569-137939
+/libcxx/trunk:278282,278357,278387,278904,279008


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


[libcxxabi] r279189 - Creating release candidate rc2 from release_390 branch

2016-08-18 Thread Hans Wennborg via cfe-commits
Author: hans
Date: Thu Aug 18 20:42:38 2016
New Revision: 279189

URL: http://llvm.org/viewvc/llvm-project?rev=279189&view=rev
Log:
Creating release candidate rc2 from release_390 branch

Added:
libcxxabi/tags/RELEASE_390/rc2/   (props changed)
  - copied from r279188, libcxxabi/branches/release_39/

Propchange: libcxxabi/tags/RELEASE_390/rc2/
--
svn:mergeinfo = /libcxxabi/trunk:278030,278579


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


r279183 - [www] Add analyzer FAQ about not releasing ivars in -dealloc.

2016-08-18 Thread Devin Coughlin via cfe-commits
Author: dcoughlin
Date: Thu Aug 18 20:22:50 2016
New Revision: 279183

URL: http://llvm.org/viewvc/llvm-project?rev=279183&view=rev
Log:
[www] Add analyzer FAQ about not releasing ivars in -dealloc.

Modified:
cfe/trunk/www/analyzer/faq.html

Modified: cfe/trunk/www/analyzer/faq.html
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/www/analyzer/faq.html?rev=279183&r1=279182&r2=279183&view=diff
==
--- cfe/trunk/www/analyzer/faq.html (original)
+++ cfe/trunk/www/analyzer/faq.html Thu Aug 18 20:22:50 2016
@@ -29,6 +29,7 @@ null?
   How do I tell the static analyzer that I don't 
care about a specific dead store?
   How do I tell the static analyzer that I don't 
care about a specific unused instance variable in Objective C?
   How do I tell the static analyzer that I 
don't care about a specific unlocalized string?
+  How do I tell the analyzer that my instance 
variable does not need to be released in -dealloc under Manual 
Retain/Release?
   The analyzer assumes that a loop body is never 
entered.  How can I tell it that the loop body will be entered at least 
once?
   How can I suppress a specific analyzer 
warning?
   How can I selectively exclude code the analyzer 
examines?
@@ -105,6 +106,15 @@ NSString *s = NSLocalizedString(@"Hello
 
 
 
+Q: How do I tell the analyzer that my 
instance variable does not need to be released in -dealloc under Manual 
Retain/Release?
+
+If your class only uses an instance variable for part of its lifetime, it 
may
+maintain an invariant guaranteeing that the instance variable is always 
released
+before -dealloc. In this case, you can silence a warning about a missing 
release
+by either adding assert(_ivar == nil) or an explicit release
+[_ivar release] (which will be a no-op when the variable is nil) in
+-dealloc. 
+
 Q: The analyzer assumes that a loop body is 
never entered.  How can I tell it that the loop body will be entered at least 
once?
 
 


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


r279181 - [analyzer] Weaken assertion in trackNullOrUndefValue()

2016-08-18 Thread Devin Coughlin via cfe-commits
Author: dcoughlin
Date: Thu Aug 18 20:05:31 2016
New Revision: 279181

URL: http://llvm.org/viewvc/llvm-project?rev=279181&view=rev
Log:
[analyzer] Weaken assertion in trackNullOrUndefValue()

We should ignore paren casts when making sure that the semantic expression
in a PseudoObjectExpr for an ObjC getter is a message send.

This has no other intended functionality change.

Adding a test for this exposed an interesting issue in another test case
that only manifests under ARC. trackNullOrUndefValue() is not properly
suppressing for nil values that are the result of nil propagation from a nil
receiver when the nil is returned from a function. I've added a FIXME for that
missing suppression.

rdar://problem/27290568

Modified:
cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
cfe/trunk/test/Analysis/inlining/false-positive-suppression.m

Modified: cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp?rev=279181&r1=279180&r2=279181&view=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Core/BugReporterVisitors.cpp Thu Aug 18 
20:05:31 2016
@@ -916,7 +916,7 @@ static const Expr *peelOffOuterExpr(cons
 if (PropRef && PropRef->isMessagingGetter()) {
   const Expr *GetterMessageSend =
   POE->getSemanticExpr(POE->getNumSemanticExprs() - 1);
-  assert(isa(GetterMessageSend));
+  assert(isa(GetterMessageSend->IgnoreParenCasts()));
   return peelOffOuterExpr(GetterMessageSend, N);
 }
   }

Modified: cfe/trunk/test/Analysis/inlining/false-positive-suppression.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/inlining/false-positive-suppression.m?rev=279181&r1=279180&r2=279181&view=diff
==
--- cfe/trunk/test/Analysis/inlining/false-positive-suppression.m (original)
+++ cfe/trunk/test/Analysis/inlining/false-positive-suppression.m Thu Aug 18 
20:05:31 2016
@@ -1,8 +1,11 @@
 // RUN: %clang_cc1 -analyze -analyzer-checker=core -analyzer-config 
suppress-null-return-paths=false -verify %s
 // RUN: %clang_cc1 -analyze -analyzer-checker=core -verify -DSUPPRESSED=1 %s
+// RUN: %clang_cc1 -analyze -analyzer-checker=core -fobjc-arc -verify 
-DSUPPRESSED=1 %s
 // RUN: %clang_cc1 -analyze -analyzer-checker=core -analyzer-config 
avoid-suppressing-null-argument-paths=true -DSUPPRESSED=1 -DNULL_ARGS=1 -verify 
%s
 
-#ifdef SUPPRESSED
+#define ARC __has_feature(objc_arc)
+
+#if defined(SUPPRESSED) && !ARC
 // expected-no-diagnostics
 #endif
 
@@ -24,8 +27,9 @@ void testNilReceiverHelperA(int *x) {
 
 void testNilReceiverHelperB(int *x) {
   *x = 1;
-#ifndef SUPPRESSED
-  // expected-warning@-2 {{Dereference of null pointer}}
+// FIXME: Suppression for this case isn't working under ARC. It should.
+#if !defined(SUPPRESSED) || (defined(SUPPRESSED) && ARC)
+  // expected-warning@-3 {{Dereference of null pointer}}
 #endif
 }
 
@@ -40,13 +44,17 @@ void testNilReceiver(int coin) {
 // FALSE NEGATIVES (over-suppression)
 
 __attribute__((objc_root_class))
-@interface SomeClass
+@interface SomeClass {
+  int ivar;
+}
 -(int *)methodReturningNull;
 
 @property(readonly) int *propertyReturningNull;
 
 @property(readonly) int *synthesizedProperty;
 
+@property(readonly) SomeClass *propertyReturningNil;
+
 @end
 
 @interface SubOfSomeClass : SomeClass
@@ -64,6 +72,10 @@ __attribute__((objc_root_class))
   return 0;
 }
 
+-(SomeClass *)propertyReturningNil {
+  return 0;
+}
+
 +(int *)classPropertyReturningNull {
   return 0;
 }
@@ -103,6 +115,16 @@ void testClassPropertyReturningNull() {
 #endif
 }
 
+@implementation SomeClass (ForTestOfPropertyReturningNil)
+void testPropertyReturningNil(SomeClass *sc) {
+  SomeClass *result = sc.propertyReturningNil;
+  result->ivar = 1;
+#ifndef SUPPRESSED
+  // expected-warning@-2 {{Access to instance variable 'ivar' results in a 
dereference of a null pointer (loaded from variable 'result')}}
+#endif
+}
+@end
+
 void testSynthesizedPropertyReturningNull(SomeClass *sc) {
   if (sc.synthesizedProperty)
 return;


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


[PATCH] D23699: [CMake] Be more consistent about naming targets and components

2016-08-18 Thread Chris Bieneman via cfe-commits
beanz created this revision.
beanz added a reviewer: EricWF.
beanz added a subscriber: cfe-commits.

The point of this patch is to have a consistent convention for naming build, 
check and install targets so that the targets can be constructed from the 
project name.

This change renames a bunch of CMake components and targets from libcxx to cxx. 
For each renamed target I've added a convenience target that matches the old 
target name and depends on the new target. This will preserve function of the 
old targets so that the change doesn't break the world. We can evaluate if it 
is worth removing the extra targets later.

https://reviews.llvm.org/D23699

Files:
  include/CMakeLists.txt
  lib/CMakeLists.txt
  test/CMakeLists.txt

Index: test/CMakeLists.txt
===
--- test/CMakeLists.txt
+++ test/CMakeLists.txt
@@ -52,11 +52,13 @@
   set(experimental_dep cxx_experimental)
 endif()
 
-add_lit_testsuite(check-libcxx
+add_lit_testsuite(check-cxx
   "Running libcxx tests"
   ${CMAKE_CURRENT_BINARY_DIR}
   DEPENDS cxx ${experimental_dep})
 
+add_custom_target(check-libcxx DEPENDS check-cxx)
+
 if (LIBCXX_GENERATE_COVERAGE)
   include(CodeCoverage)
   set(output_dir "${CMAKE_CURRENT_BINARY_DIR}/coverage")
Index: lib/CMakeLists.txt
===
--- lib/CMakeLists.txt
+++ lib/CMakeLists.txt
@@ -225,8 +225,8 @@
 set(experimental_lib cxx_experimental)
   endif()
   install(TARGETS ${LIBCXX_TARGETS} ${experimental_lib}
-LIBRARY DESTINATION lib${LIBCXX_LIBDIR_SUFFIX} COMPONENT libcxx
-ARCHIVE DESTINATION lib${LIBCXX_LIBDIR_SUFFIX} COMPONENT libcxx
+LIBRARY DESTINATION lib${LIBCXX_LIBDIR_SUFFIX} COMPONENT cxx
+ARCHIVE DESTINATION lib${LIBCXX_LIBDIR_SUFFIX} COMPONENT cxx
 )
   # NOTE: This install command must go after the cxx install command otherwise
   # it will not be executed after the library symlinks are installed.
@@ -248,13 +248,14 @@
   set(experimental_lib_install_target cxx_experimental)
 endif()
 if(LIBCXX_INSTALL_HEADERS)
-  set(header_install_target install-libcxx-headers)
+  set(header_install_target install-cxx-headers)
 endif()
-add_custom_target(install-libcxx
+add_custom_target(install-cxx
   DEPENDS ${lib_install_target}
   ${experimental_lib_install_target}
   ${header_install_target}
   COMMAND "${CMAKE_COMMAND}"
-  -DCMAKE_INSTALL_COMPONENT=libcxx
+  -DCMAKE_INSTALL_COMPONENT=cxx
   -P "${LIBCXX_BINARY_DIR}/cmake_install.cmake")
+add_custom_target(install-libcxx DEPENDS install-cxx)
 endif()
Index: include/CMakeLists.txt
===
--- include/CMakeLists.txt
+++ include/CMakeLists.txt
@@ -19,7 +19,7 @@
 if (LIBCXX_INSTALL_HEADERS)
   install(DIRECTORY .
 DESTINATION include/c++/v1
-COMPONENT libcxx-headers
+COMPONENT cxx-headers
 FILES_MATCHING
 ${LIBCXX_HEADER_PATTERN}
 PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
@@ -47,17 +47,20 @@
   DESTINATION include/c++/v1
   PERMISSIONS OWNER_READ OWNER_WRITE GROUP_READ WORLD_READ
   RENAME __config
-  COMPONENT libcxx-headers)
+  COMPONENT cxx-headers)
   endif()
 
   if (NOT CMAKE_CONFIGURATION_TYPES)
 # this target is just needed as a placeholder for the distribution target
-add_custom_target(libcxx-headers)
-add_custom_target(install-libcxx-headers
-  DEPENDS libcxx-headers ${generated_config_deps}
+add_custom_target(cxx-headers)
+add_custom_target(install-cxx-headers
+  DEPENDS cxx-headers ${generated_config_deps}
   COMMAND "${CMAKE_COMMAND}"
-  -DCMAKE_INSTALL_COMPONENT=libcxx-headers
+  -DCMAKE_INSTALL_COMPONENT=cxx-headers
   -P "${CMAKE_BINARY_DIR}/cmake_install.cmake")
+
+add_custom_target(libcxx-headers)
+add_custom_target(install-libcxx-headers DEPENDS install-cxx-headers)
   endif()
 
 endif()


Index: test/CMakeLists.txt
===
--- test/CMakeLists.txt
+++ test/CMakeLists.txt
@@ -52,11 +52,13 @@
   set(experimental_dep cxx_experimental)
 endif()
 
-add_lit_testsuite(check-libcxx
+add_lit_testsuite(check-cxx
   "Running libcxx tests"
   ${CMAKE_CURRENT_BINARY_DIR}
   DEPENDS cxx ${experimental_dep})
 
+add_custom_target(check-libcxx DEPENDS check-cxx)
+
 if (LIBCXX_GENERATE_COVERAGE)
   include(CodeCoverage)
   set(output_dir "${CMAKE_CURRENT_BINARY_DIR}/coverage")
Index: lib/CMakeLists.txt
===
--- lib/CMakeLists.txt
+++ lib/CMakeLists.txt
@@ -225,8 +225,8 @@
 set(experimental_lib cxx_experimental)
   endif()
  

[libunwind] r279180 - EHABI: cover switch once more

2016-08-18 Thread Saleem Abdulrasool via cfe-commits
Author: compnerd
Date: Thu Aug 18 18:59:12 2016
New Revision: 279180

URL: http://llvm.org/viewvc/llvm-project?rev=279180&view=rev
Log:
EHABI: cover switch once more

When making WMMX support optional, we uncovered the switch.  Add the missing
entries.  Since the entry is a break leading to a dead path, it should get
optimized out yet retain the switch overage.

Modified:
libunwind/trunk/src/Unwind-EHABI.cpp

Modified: libunwind/trunk/src/Unwind-EHABI.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libunwind/trunk/src/Unwind-EHABI.cpp?rev=279180&r1=279179&r2=279180&view=diff
==
--- libunwind/trunk/src/Unwind-EHABI.cpp (original)
+++ libunwind/trunk/src/Unwind-EHABI.cpp Thu Aug 18 18:59:12 2016
@@ -804,6 +804,10 @@ _Unwind_VRS_Set(_Unwind_Context *context
*(unw_fpreg_t *)valuep) == UNW_ESUCCESS
  ? _UVRSR_OK
  : _UVRSR_FAILED;
+#else
+case _UVRSC_WMMXC:
+case _UVRSC_WMMXD:
+  break;
 #endif
   }
   _LIBUNWIND_ABORT("unsupported register class");
@@ -854,6 +858,10 @@ _Unwind_VRS_Get_Internal(_Unwind_Context
(unw_fpreg_t *)valuep) == UNW_ESUCCESS
  ? _UVRSR_OK
  : _UVRSR_FAILED;
+#else
+case _UVRSC_WMMXC:
+case _UVRSC_WMMXD:
+  break;
 #endif
   }
   _LIBUNWIND_ABORT("unsupported register class");


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


Re: Upgrade and fix clang-format-vs

2016-08-18 Thread Hans Wennborg via cfe-commits
Hi Antonio,

On Wed, Aug 17, 2016 at 8:15 AM, Antonio Maiorano via cfe-commits
 wrote:
> This patch for clang-format-vs includes the following:
>
> - Upgrade to VS 2015, including .NET framework upgrade from 4.0 to 4.5, and
> upgrading Microsoft.VisualStudio references to v14 versions
> - Fix build by removing dependency on "Key.snk" file which was never checked
> in (and not really required anyway)
> - Add ".vs" directory to svn ignore (new folder that VS 2015 creates for
> user settings)

"What does "Upgrade to VS 2015 mean? Adding support for running the
plugin in VS2015, or does it mean requiring VS2015 for building?

+zturner: I thought the plugin already worked in VS 2015?

I mostly just build the plugin without knowing exactly how this stuff
works, but looking at the patch I'm worried that you're increasing the
required version for building it? I see a bunch of values going from
10 (VS 2012) to 14 (VS 2015).

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


Re: [PATCH] D22515: [analyzer] Added custom hashing to the CloneDetector.

2016-08-18 Thread Raphael Isemann via cfe-commits
teemperor updated this revision to Diff 68632.
teemperor added a comment.
This revision is now accepted and ready to land.

- Moved from hash_stream to LLVM's MD5 implementation.


https://reviews.llvm.org/D22515

Files:
  include/clang/Analysis/CloneDetection.h
  lib/Analysis/CloneDetection.cpp
  lib/StaticAnalyzer/Checkers/CloneChecker.cpp

Index: lib/StaticAnalyzer/Checkers/CloneChecker.cpp
===
--- lib/StaticAnalyzer/Checkers/CloneChecker.cpp
+++ lib/StaticAnalyzer/Checkers/CloneChecker.cpp
@@ -91,15 +91,6 @@
"Related code clone is here.");
 
   for (CloneDetector::CloneGroup &Group : CloneGroups) {
-// For readability reasons we sort the clones by line numbers.
-std::sort(Group.Sequences.begin(), Group.Sequences.end(),
-  [&SM](const StmtSequence &LHS, const StmtSequence &RHS) {
-return SM.isBeforeInTranslationUnit(LHS.getStartLoc(),
-RHS.getStartLoc()) &&
-   SM.isBeforeInTranslationUnit(LHS.getEndLoc(),
-RHS.getEndLoc());
-  });
-
 // We group the clones by printing the first as a warning and all others
 // as a note.
 DiagEngine.Report(Group.Sequences.front().getStartLoc(), WarnID);
Index: lib/Analysis/CloneDetection.cpp
===
--- lib/Analysis/CloneDetection.cpp
+++ lib/Analysis/CloneDetection.cpp
@@ -19,6 +19,7 @@
 #include "clang/AST/StmtVisitor.h"
 #include "clang/Lex/Lexer.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/MD5.h"
 #include "llvm/Support/raw_ostream.h"
 
 using namespace clang;
@@ -279,47 +280,35 @@
 /// This class defines what a code clone is: If it collects for two statements
 /// the same data, then those two statements are considered to be clones of each
 /// other.
-class StmtDataCollector : public ConstStmtVisitor {
+///
+/// All collected data is forwarded to the given data consumer of the type T.
+/// The data consumer class needs to provide a member method with the signature:
+///   update(StringRef Str)
+template 
+class StmtDataCollector : public ConstStmtVisitor> {
 
   ASTContext &Context;
-  std::vector &CollectedData;
+  /// \brief The data sink to which all data is forwarded.
+  T &DataConsumer;
 
 public:
   /// \brief Collects data of the given Stmt.
   /// \param S The given statement.
   /// \param Context The ASTContext of S.
-  /// \param D The given data vector to which all collected data is appended.
-  StmtDataCollector(const Stmt *S, ASTContext &Context,
-std::vector &D)
-  : Context(Context), CollectedData(D) {
-Visit(S);
+  /// \param D The data sink to which all data is forwarded.
+  StmtDataCollector(const Stmt *S, ASTContext &Context, T &DataConsumer)
+  : Context(Context), DataConsumer(DataConsumer) {
+this->Visit(S);
   }
 
   // Below are utility methods for appending different data to the vector.
 
   void addData(CloneDetector::DataPiece Integer) {
-CollectedData.push_back(Integer);
+DataConsumer.update(
+StringRef(reinterpret_cast(&Integer), sizeof(Integer)));
   }
 
-  // FIXME: The functions below add long strings to the data vector which are
-  // probably not good for performance. Replace the strings with pointer values
-  // or a some other unique integer.
-
-  void addData(llvm::StringRef Str) {
-if (Str.empty())
-  return;
-
-const size_t OldSize = CollectedData.size();
-
-const size_t PieceSize = sizeof(CloneDetector::DataPiece);
-// Calculate how many vector units we need to accomodate all string bytes.
-size_t RoundedUpPieceNumber = (Str.size() + PieceSize - 1) / PieceSize;
-// Allocate space for the string in the data vector.
-CollectedData.resize(CollectedData.size() + RoundedUpPieceNumber);
-
-// Copy the string to the allocated space at the end of the vector.
-std::memcpy(CollectedData.data() + OldSize, Str.data(), Str.size());
-  }
+  void addData(llvm::StringRef Str) { DataConsumer.update(Str); }
 
   void addData(const QualType &QT) { addData(QT.getAsString()); }
 
@@ -466,8 +455,10 @@
 // Create an empty signature that will be filled in this method.
 CloneDetector::CloneSignature Signature;
 
-// Collect all relevant data from S and put it into the empty signature.
-StmtDataCollector(S, Context, Signature.Data);
+llvm::MD5 Hash;
+
+// Collect all relevant data from S and hash it.
+StmtDataCollector(S, Context, Hash);
 
 // Look up what macros expanded into the current statement.
 std::string StartMacroStack = getMacroStack(S->getLocStart(), Context);
@@ -505,7 +496,9 @@
   auto ChildSignature = generateSignatures(Child, StartMacroStack);
 
   // Add the collected data to the signature of the current statement.
-  Signature.add(C

Re: [PATCH] D23643: [Driver] Report invalid -mtune/-mcpu parameters when -arch=arm64

2016-08-18 Thread Vedant Kumar via cfe-commits
vsk updated this revision to Diff 68630.
vsk added a comment.

Per Akira's suggestion, don't pretend that the Arg* for -arch is a 
user-specified CPU name (and update the doxygen to reflect this).


https://reviews.llvm.org/D23643

Files:
  lib/Driver/Tools.cpp
  test/Driver/arm-cortex-cpus.c

Index: test/Driver/arm-cortex-cpus.c
===
--- test/Driver/arm-cortex-cpus.c
+++ test/Driver/arm-cortex-cpus.c
@@ -303,7 +303,10 @@
 
 // == Check that a bogus CPU gives an error
 // RUN: %clang -target arm -mcpu=bogus -### -c %s 2>&1 | FileCheck 
-check-prefix=CHECK-BOGUS-CPU %s
+// RUN: %clang -arch arm64 -mcpu=bogus -### -c %s 2>&1 | FileCheck 
-check-prefix=CHECK-BOGUS-CPU %s
 // CHECK-BOGUS-CPU: error: {{.*}} does not support '-mcpu=bogus'
+// RUN: %clang -arch arm64 -mtune=bogus -### -c %s 2>&1 | FileCheck 
-check-prefix=CHECK-BOGUS-TUNE %s
+// CHECK-BOGUS-TUNE: error: {{.*}} does not support '-mtune=bogus'
 
 // == Check default Architecture on each ARM11 CPU
 // RUN: %clang -target arm-linux-gnueabi -mcpu=arm1136j-s -### -c %s 2>&1 | 
FileCheck -check-prefix=CHECK-CPUV6 %s
Index: lib/Driver/Tools.cpp
===
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -1140,9 +1140,9 @@
 // ARM tools end.
 
 /// getAArch64TargetCPU - Get the (LLVM) name of the AArch64 cpu we are
-/// targeting.
-static std::string getAArch64TargetCPU(const ArgList &Args) {
-  Arg *A;
+/// targeting. Set \p A to the Arg corresponding to the -mcpu or -mtune
+/// arguments if they are provided, or to nullptr otherwise.
+static std::string getAArch64TargetCPU(const ArgList &Args, Arg *&A) {
   std::string CPU;
   // If we have -mtune or -mcpu, use that.
   if ((A = Args.getLastArg(options::OPT_mtune_EQ))) {
@@ -1919,13 +1919,15 @@
 
 static std::string getCPUName(const ArgList &Args, const llvm::Triple &T,
   bool FromAs = false) {
+  Arg *A;
+
   switch (T.getArch()) {
   default:
 return "";
 
   case llvm::Triple::aarch64:
   case llvm::Triple::aarch64_be:
-return getAArch64TargetCPU(Args);
+return getAArch64TargetCPU(Args, A);
 
   case llvm::Triple::arm:
   case llvm::Triple::armeb:
@@ -2443,18 +2445,18 @@
   else if ((A = Args.getLastArg(options::OPT_mcpu_EQ)))
 success = getAArch64ArchFeaturesFromMcpu(D, A->getValue(), Args, Features);
   else if (Args.hasArg(options::OPT_arch))
-success = getAArch64ArchFeaturesFromMcpu(D, getAArch64TargetCPU(Args), 
Args,
- Features);
+success = getAArch64ArchFeaturesFromMcpu(D, getAArch64TargetCPU(Args, A),
+ Args, Features);
 
   if (success && (A = Args.getLastArg(options::OPT_mtune_EQ)))
 success =
 getAArch64MicroArchFeaturesFromMtune(D, A->getValue(), Args, Features);
   else if (success && (A = Args.getLastArg(options::OPT_mcpu_EQ)))
 success =
 getAArch64MicroArchFeaturesFromMcpu(D, A->getValue(), Args, Features);
-  else if (Args.hasArg(options::OPT_arch))
-success = getAArch64MicroArchFeaturesFromMcpu(D, getAArch64TargetCPU(Args),
-  Args, Features);
+  else if (success && Args.hasArg(options::OPT_arch))
+success = getAArch64MicroArchFeaturesFromMcpu(
+D, getAArch64TargetCPU(Args, A), Args, Features);
 
   if (!success)
 D.Diag(diag::err_drv_clang_unsupported) << A->getAsString(Args);


Index: test/Driver/arm-cortex-cpus.c
===
--- test/Driver/arm-cortex-cpus.c
+++ test/Driver/arm-cortex-cpus.c
@@ -303,7 +303,10 @@
 
 // == Check that a bogus CPU gives an error
 // RUN: %clang -target arm -mcpu=bogus -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-BOGUS-CPU %s
+// RUN: %clang -arch arm64 -mcpu=bogus -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-BOGUS-CPU %s
 // CHECK-BOGUS-CPU: error: {{.*}} does not support '-mcpu=bogus'
+// RUN: %clang -arch arm64 -mtune=bogus -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-BOGUS-TUNE %s
+// CHECK-BOGUS-TUNE: error: {{.*}} does not support '-mtune=bogus'
 
 // == Check default Architecture on each ARM11 CPU
 // RUN: %clang -target arm-linux-gnueabi -mcpu=arm1136j-s -### -c %s 2>&1 | FileCheck -check-prefix=CHECK-CPUV6 %s
Index: lib/Driver/Tools.cpp
===
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -1140,9 +1140,9 @@
 // ARM tools end.
 
 /// getAArch64TargetCPU - Get the (LLVM) name of the AArch64 cpu we are
-/// targeting.
-static std::string getAArch64TargetCPU(const ArgList &Args) {
-  Arg *A;
+/// targeting. Set \p A to the Arg corresponding to the -mcpu or -mtune
+/// arguments if they are provided, or to nullptr otherwise.
+static std::string getAArch64TargetCPU(const ArgList &Args, Arg *&A) {
   std::

Re: [PATCH] D23643: [Driver] Report invalid -mtune/-mcpu parameters when -arch=arm64

2016-08-18 Thread Vedant Kumar via cfe-commits
vsk added inline comments.


Comment at: lib/Driver/Tools.cpp:1163
@@ -1162,3 +1162,3 @@
   // FIXME: Should this be picked by checking the target triple instead?
-  if (Args.getLastArg(options::OPT_arch))
+  if ((A = Args.getLastArg(options::OPT_arch)))
 return "cyclone";

ahatanak wrote:
> vsk wrote:
> > vsk wrote:
> > > ahatanak wrote:
> > > > Is there a test case for this change? I don't think this was needed to 
> > > > pass the tests you added?
> > > Good point, I'll work up a test case.
> > Actually, none of the callers of `getAArch64TargetCPU' fail when 
> > CPU="cyclone" (afaict).
> > 
> > Do you have a suggestion for how I can test this? I made the change here to 
> > make the function's contract more consistent, but can leave it out if you 
> > object.
> I couldn't find a test case for this either.
> 
> I think we should leave it out if the contract of the function is to get the 
> string passed by either -mtune or -mcpu in "A", but we can leave it in if 
> it's supposed to get one of the strings passed by -mtune, -mcpu, or -arch.
All right, IMO it makes more sense to leave out -arch. I'll omit this change 
and update the doxygen for the function.


https://reviews.llvm.org/D23643



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


Re: [PATCH] D23643: [Driver] Report invalid -mtune/-mcpu parameters when -arch=arm64

2016-08-18 Thread Akira Hatanaka via cfe-commits
ahatanak added inline comments.


Comment at: lib/Driver/Tools.cpp:1163
@@ -1162,3 +1162,3 @@
   // FIXME: Should this be picked by checking the target triple instead?
-  if (Args.getLastArg(options::OPT_arch))
+  if ((A = Args.getLastArg(options::OPT_arch)))
 return "cyclone";

vsk wrote:
> vsk wrote:
> > ahatanak wrote:
> > > Is there a test case for this change? I don't think this was needed to 
> > > pass the tests you added?
> > Good point, I'll work up a test case.
> Actually, none of the callers of `getAArch64TargetCPU' fail when 
> CPU="cyclone" (afaict).
> 
> Do you have a suggestion for how I can test this? I made the change here to 
> make the function's contract more consistent, but can leave it out if you 
> object.
I couldn't find a test case for this either.

I think we should leave it out if the contract of the function is to get the 
string passed by either -mtune or -mcpu in "A", but we can leave it in if it's 
supposed to get one of the strings passed by -mtune, -mcpu, or -arch.


https://reviews.llvm.org/D23643



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


Re: [PATCH] D23530: Remove excessive padding from BarrierOp, PrefetchOp, PSBHintOp.

2016-08-18 Thread Saleem Abdulrasool via cfe-commits
compnerd closed this revision.
compnerd added a comment.

SVN r279173


https://reviews.llvm.org/D23530



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


[clang-tools-extra] r279170 - [Documentation] Fixed style in modernize-use-emplace.rst.

2016-08-18 Thread Eugene Zelenko via cfe-commits
Author: eugenezelenko
Date: Thu Aug 18 17:11:27 2016
New Revision: 279170

URL: http://llvm.org/viewvc/llvm-project?rev=279170&view=rev
Log:
[Documentation] Fixed style in modernize-use-emplace.rst.

Modified:
clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-use-emplace.rst

Modified: 
clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-use-emplace.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-use-emplace.rst?rev=279170&r1=279169&r2=279170&view=diff
==
--- clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-use-emplace.rst 
(original)
+++ clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-use-emplace.rst 
Thu Aug 18 17:11:27 2016
@@ -57,9 +57,8 @@ After:
 v.emplace_back("abc");
 
 
-In some cases the transformation would be valid, but the code
-wouldn't be exception safe.
-In this case the calls of ``push_back`` won't be replaced.
+In some cases the transformation would be valid, but the code wouldn't be
+exception safe. In this case the calls of ``push_back`` won't be replaced.
 
 .. code-block:: c++
 
@@ -73,7 +72,7 @@ pointer if ``emplace_back`` would throw
 enough memory to add new element).
 
 For more info read item 42 - "Consider emplacement instead of insertion." of
-Scott Meyers Effective Modern C++.
+Scott Meyers "Effective Modern C++".
 
 The default smart pointers that are considered are ``std::unique_ptr``,
 ``std::shared_ptr``, ``std::auto_ptr``.  To specify other smart pointers or


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


r279165 - AMDGPU: Add clang builtin for ds_swizzle.

2016-08-18 Thread Changpeng Fang via cfe-commits
Author: chfang
Date: Thu Aug 18 17:04:54 2016
New Revision: 279165

URL: http://llvm.org/viewvc/llvm-project?rev=279165&view=rev
Log:
AMDGPU: Add clang builtin for ds_swizzle.

Summary:
  int __builtin_amdgcn_ds_swizzle (int a, int imm);
while imm is a constant.

Differential Revision:
  http://reviews.llvm.org/D23682

Modified:
cfe/trunk/include/clang/Basic/BuiltinsAMDGPU.def
cfe/trunk/lib/CodeGen/CGBuiltin.cpp
cfe/trunk/test/CodeGenOpenCL/builtins-amdgcn-error.cl
cfe/trunk/test/CodeGenOpenCL/builtins-amdgcn.cl

Modified: cfe/trunk/include/clang/Basic/BuiltinsAMDGPU.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/BuiltinsAMDGPU.def?rev=279165&r1=279164&r2=279165&view=diff
==
--- cfe/trunk/include/clang/Basic/BuiltinsAMDGPU.def (original)
+++ cfe/trunk/include/clang/Basic/BuiltinsAMDGPU.def Thu Aug 18 17:04:54 2016
@@ -76,6 +76,7 @@ BUILTIN(__builtin_amdgcn_sicmp, "LUiiiIi
 BUILTIN(__builtin_amdgcn_sicmpl, "LUiLiLiIi", "nc")
 BUILTIN(__builtin_amdgcn_fcmp, "LUiddIi", "nc")
 BUILTIN(__builtin_amdgcn_fcmpf, "LUiffIi", "nc")
+BUILTIN(__builtin_amdgcn_ds_swizzle, "iiIi", "nc")
 
 
//===--===//
 // VI+ only builtins.

Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=279165&r1=279164&r2=279165&view=diff
==
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Thu Aug 18 17:04:54 2016
@@ -7652,6 +7652,9 @@ Value *CodeGenFunction::EmitAMDGPUBuilti
 llvm::Value *Src3ToBool = Builder.CreateIsNotNull(Src3);
 return Builder.CreateCall(F, {Src0, Src1, Src2, Src3ToBool});
   }
+
+  case AMDGPU::BI__builtin_amdgcn_ds_swizzle:
+return emitBinaryBuiltin(*this, E, Intrinsic::amdgcn_ds_swizzle);
   case AMDGPU::BI__builtin_amdgcn_div_fixup:
   case AMDGPU::BI__builtin_amdgcn_div_fixupf:
 return emitTernaryBuiltin(*this, E, Intrinsic::amdgcn_div_fixup);

Modified: cfe/trunk/test/CodeGenOpenCL/builtins-amdgcn-error.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/builtins-amdgcn-error.cl?rev=279165&r1=279164&r2=279165&view=diff
==
--- cfe/trunk/test/CodeGenOpenCL/builtins-amdgcn-error.cl (original)
+++ cfe/trunk/test/CodeGenOpenCL/builtins-amdgcn-error.cl Thu Aug 18 17:04:54 
2016
@@ -48,3 +48,7 @@ void test_fcmp_f64(global ulong* out, do
   *out = __builtin_amdgcn_fcmp(a, b, c); // expected-error {{argument to 
'__builtin_amdgcn_fcmp' must be a constant integer}}
 }
 
+void test_ds_swizzle(global int* out, int a, int b)
+{
+  *out = __builtin_amdgcn_ds_swizzle(a, b); // expected-error {{argument to 
'__builtin_amdgcn_ds_swizzle' must be a constant integer}}
+}

Modified: cfe/trunk/test/CodeGenOpenCL/builtins-amdgcn.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenOpenCL/builtins-amdgcn.cl?rev=279165&r1=279164&r2=279165&view=diff
==
--- cfe/trunk/test/CodeGenOpenCL/builtins-amdgcn.cl (original)
+++ cfe/trunk/test/CodeGenOpenCL/builtins-amdgcn.cl Thu Aug 18 17:04:54 2016
@@ -228,6 +228,13 @@ void test_uicmp_i64(global ulong* out, u
   *out = __builtin_amdgcn_uicmpl(a, b, 30+5);
 }
 
+// CHECK-LABEL: @test_ds_swizzle
+// CHECK: call i32 @llvm.amdgcn.ds.swizzle(i32 %a, i32 32)
+void test_ds_swizzle(global int* out, int a)
+{
+  *out = __builtin_amdgcn_ds_swizzle(a, 32);
+}
+
 // CHECK-LABEL: @test_fcmp_f32
 // CHECK: call i64 @llvm.amdgcn.fcmp.f32(float %a, float %b, i32 5)
 void test_fcmp_f32(global ulong* out, float a, float b)


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


r279164 - PR28794: Don't try to instantiate function templates which are not visible.

2016-08-18 Thread Vassil Vassilev via cfe-commits
Author: vvassilev
Date: Thu Aug 18 17:01:25 2016
New Revision: 279164

URL: http://llvm.org/viewvc/llvm-project?rev=279164&view=rev
Log:
PR28794: Don't try to instantiate function templates which are not visible.

Reviewed by Richard Smith.

Added:
cfe/trunk/test/Modules/Inputs/PR28794/
cfe/trunk/test/Modules/Inputs/PR28794/LibAHeader.h
cfe/trunk/test/Modules/Inputs/PR28794/Subdir/
cfe/trunk/test/Modules/Inputs/PR28794/Subdir/Empty.h
cfe/trunk/test/Modules/Inputs/PR28794/Subdir/LibBHeader.h
cfe/trunk/test/Modules/Inputs/PR28794/module.modulemap
Modified:
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Sema/SemaTemplate.cpp
cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp
cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=279164&r1=279163&r2=279164&view=diff
==
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Thu Aug 18 17:01:25 2016
@@ -5711,6 +5711,14 @@ public:
TemplateTy &SuggestedTemplate,
TemplateNameKind &SuggestedKind);
 
+  bool DiagnoseUninstantiableTemplate(SourceLocation PointOfInstantiation,
+  NamedDecl *Instantiation,
+  bool InstantiatedFromMember,
+  const NamedDecl *Pattern,
+  const NamedDecl *PatternDef,
+  TemplateSpecializationKind TSK,
+  bool Complain = true);
+
   void DiagnoseTemplateParameterShadow(SourceLocation Loc, Decl *PrevDecl);
   TemplateDecl *AdjustDeclIfTemplate(Decl *&Decl);
 

Modified: cfe/trunk/lib/Sema/SemaTemplate.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplate.cpp?rev=279164&r1=279163&r2=279164&view=diff
==
--- cfe/trunk/lib/Sema/SemaTemplate.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplate.cpp Thu Aug 18 17:01:25 2016
@@ -456,6 +456,70 @@ Sema::BuildDependentDeclRefExpr(const CX
   TemplateArgs);
 }
 
+
+/// Determine whether we would be unable to instantiate this template (because
+/// it either has no definition, or is in the process of being instantiated).
+bool Sema::DiagnoseUninstantiableTemplate(SourceLocation PointOfInstantiation,
+  NamedDecl *Instantiation,
+  bool InstantiatedFromMember,
+  const NamedDecl *Pattern,
+  const NamedDecl *PatternDef,
+  TemplateSpecializationKind TSK,
+  bool Complain /*= true*/) {
+  assert(isa(Instantiation) || isa(Instantiation));
+
+  if (PatternDef && (isa(PatternDef)
+ || !cast(PatternDef)->isBeingDefined())) {
+NamedDecl *SuggestedDef = nullptr;
+if (!hasVisibleDefinition(const_cast(PatternDef), 
&SuggestedDef,
+  /*OnlyNeedComplete*/false)) {
+  // If we're allowed to diagnose this and recover, do so.
+  bool Recover = Complain && !isSFINAEContext();
+  if (Complain)
+diagnoseMissingImport(PointOfInstantiation, SuggestedDef,
+  Sema::MissingImportKind::Definition, Recover);
+  return !Recover;
+}
+return false;
+  }
+
+
+  QualType InstantiationTy;
+  if (TagDecl *TD = dyn_cast(Instantiation))
+InstantiationTy = Context.getTypeDeclType(TD);
+  else
+InstantiationTy = cast(Instantiation)->getType();
+  if (!Complain || (PatternDef && PatternDef->isInvalidDecl())) {
+// Say nothing
+  } else if (PatternDef) {
+Diag(PointOfInstantiation,
+ diag::err_template_instantiate_within_definition)
+  << (TSK != TSK_ImplicitInstantiation)
+  << InstantiationTy;
+// Not much point in noting the template declaration here, since
+// we're lexically inside it.
+Instantiation->setInvalidDecl();
+  } else if (InstantiatedFromMember) {
+Diag(PointOfInstantiation,
+ diag::err_implicit_instantiate_member_undefined)
+  << InstantiationTy;
+Diag(Pattern->getLocation(), diag::note_member_declared_at);
+  } else {
+Diag(PointOfInstantiation, diag::err_template_instantiate_undefined)
+  << (TSK != TSK_ImplicitInstantiation)
+  << InstantiationTy;
+Diag(Pattern->getLocation(), diag::note_template_decl_here);
+  }
+
+  // In general, Instantiation isn't marked invalid to get more than one
+  // error for multiple undefined instantiations. But the code that does
+  // explicit declaration -> explicit definition conversion can't handle
+  // in

r279163 - C++ Modules TS: Add parsing support for module import declaration.

2016-08-18 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Thu Aug 18 16:59:42 2016
New Revision: 279163

URL: http://llvm.org/viewvc/llvm-project?rev=279163&view=rev
Log:
C++ Modules TS: Add parsing support for module import declaration.

Added:
cfe/trunk/test/Parser/cxx-modules-import.cpp
Modified:
cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
cfe/trunk/include/clang/Parse/Parser.h
cfe/trunk/lib/Lex/Preprocessor.cpp
cfe/trunk/lib/Parse/ParseDecl.cpp
cfe/trunk/lib/Parse/Parser.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td?rev=279163&r1=279162&r2=279163&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td Thu Aug 18 16:59:42 
2016
@@ -1023,6 +1023,8 @@ def warn_pragma_unroll_cuda_value_in_par
 let CategoryName = "Modules Issue" in {
 def err_module_expected_ident : Error<
   "expected a module name after module import">;
+def err_attribute_not_import_attr : Error<
+  "%0 attribute cannot be applied to a module import">;
 def err_module_expected_semi : Error<
   "expected ';' after module name">;
 def err_missing_before_module_end : Error<"expected %0 at end of module">;

Modified: cfe/trunk/include/clang/Parse/Parser.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=279163&r1=279162&r2=279163&view=diff
==
--- cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/trunk/include/clang/Parse/Parser.h Thu Aug 18 16:59:42 2016
@@ -2116,7 +2116,8 @@ private:
   // Forbid C++11 attributes that appear on certain syntactic 
   // locations which standard permits but we don't supported yet, 
   // for example, attributes appertain to decl specifiers.
-  void ProhibitCXX11Attributes(ParsedAttributesWithRange &attrs);
+  void ProhibitCXX11Attributes(ParsedAttributesWithRange &Attrs,
+   unsigned DiagID);
 
   /// \brief Skip C++11 attributes and return the end location of the last one.
   /// \returns SourceLocation() if there are no attributes.

Modified: cfe/trunk/lib/Lex/Preprocessor.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Preprocessor.cpp?rev=279163&r1=279162&r2=279163&view=diff
==
--- cfe/trunk/lib/Lex/Preprocessor.cpp (original)
+++ cfe/trunk/lib/Lex/Preprocessor.cpp Thu Aug 18 16:59:42 2016
@@ -712,9 +712,12 @@ bool Preprocessor::HandleIdentifier(Toke
   // Note that we do not treat 'import' as a contextual
   // keyword when we're in a caching lexer, because caching lexers only get
   // used in contexts where import declarations are disallowed.
-  if (LastTokenWasAt && II.isModulesImport() && !InMacroArgs && 
-  !DisableMacroExpansion &&
-  (getLangOpts().Modules || getLangOpts().DebuggerSupport) && 
+  //
+  // Likewise if this is the C++ Modules TS import keyword.
+  if (((LastTokenWasAt && II.isModulesImport()) ||
+   Identifier.is(tok::kw_import)) &&
+  !InMacroArgs && !DisableMacroExpansion &&
+  (getLangOpts().Modules || getLangOpts().DebuggerSupport) &&
   CurLexerKind != CLK_CachingLexer) {
 ModuleImportLoc = Identifier.getLocation();
 ModuleImportPath.clear();
@@ -782,7 +785,8 @@ void Preprocessor::LexAfterModuleImport(
   }
   
   // If we're expecting a '.' or a ';', and we got a '.', then wait until we
-  // see the next identifier.
+  // see the next identifier. (We can also see a '[[' that begins an
+  // attribute-specifier-seq here under the C++ Modules TS.)
   if (!ModuleImportExpectsIdentifier && Result.getKind() == tok::period) {
 ModuleImportExpectsIdentifier = true;
 CurLexerKind = CLK_LexAfterModuleImport;

Modified: cfe/trunk/lib/Parse/ParseDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDecl.cpp?rev=279163&r1=279162&r2=279163&view=diff
==
--- cfe/trunk/lib/Parse/ParseDecl.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDecl.cpp Thu Aug 18 16:59:42 2016
@@ -1407,15 +1407,19 @@ void Parser::DiagnoseProhibitedAttribute
 << attrs.Range;
 }
 
-void Parser::ProhibitCXX11Attributes(ParsedAttributesWithRange &attrs) {
-  AttributeList *AttrList = attrs.getList();
-  while (AttrList) {
-if (AttrList->isCXX11Attribute()) {
-  Diag(AttrList->getLoc(), diag::err_attribute_not_type_attr) 
-<< AttrList->getName();
-  AttrList->setInvalid();
+void Parser::ProhibitCXX11Attributes(ParsedAttributesWithRange &Attrs,
+ unsigned DiagID) {
+  for (AttributeList *Attr = Attrs.getList(); Attr; Attr = Attr->getNext()) {
+if (!Attr->isCXX11Attribute())
+  contin

r279159 - CodeGen: Rename a variable to better fit LLVM style. NFC

2016-08-18 Thread Justin Bogner via cfe-commits
Author: bogner
Date: Thu Aug 18 16:46:54 2016
New Revision: 279159

URL: http://llvm.org/viewvc/llvm-project?rev=279159&view=rev
Log:
CodeGen: Rename a variable to better fit LLVM style. NFC

Modified:
cfe/trunk/lib/CodeGen/CGCall.cpp

Modified: cfe/trunk/lib/CodeGen/CGCall.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=279159&r1=279158&r2=279159&view=diff
==
--- cfe/trunk/lib/CodeGen/CGCall.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCall.cpp Thu Aug 18 16:46:54 2016
@@ -2468,7 +2468,7 @@ static llvm::Value *tryEmitFusedAutorele
   // result is in a BasicBlock and is therefore an Instruction.
   llvm::Instruction *generator = cast(result);
 
-  SmallVector insnsToKill;
+  SmallVector InstsToKill;
 
   // Look for:
   //  %generator = bitcast %type1* %generator2 to %type2*
@@ -2481,7 +2481,7 @@ static llvm::Value *tryEmitFusedAutorele
 if (generator->getNextNode() != bitcast)
   return nullptr;
 
-insnsToKill.push_back(bitcast);
+InstsToKill.push_back(bitcast);
   }
 
   // Look for:
@@ -2514,25 +2514,25 @@ static llvm::Value *tryEmitFusedAutorele
   assert(isa(prev));
   assert(cast(prev)->getCalledValue() ==

CGF.CGM.getObjCEntrypoints().retainAutoreleasedReturnValueMarker);
-  insnsToKill.push_back(prev);
+  InstsToKill.push_back(prev);
 }
   } else {
 return nullptr;
   }
 
   result = call->getArgOperand(0);
-  insnsToKill.push_back(call);
+  InstsToKill.push_back(call);
 
   // Keep killing bitcasts, for sanity.  Note that we no longer care
   // about precise ordering as long as there's exactly one use.
   while (llvm::BitCastInst *bitcast = dyn_cast(result)) {
 if (!bitcast->hasOneUse()) break;
-insnsToKill.push_back(bitcast);
+InstsToKill.push_back(bitcast);
 result = bitcast->getOperand(0);
   }
 
   // Delete all the unnecessary instructions, from latest to earliest.
-  for (auto *I : insnsToKill)
+  for (auto *I : InstsToKill)
 I->eraseFromParent();
 
   // Do the fused retain/autorelease if we were asked to.


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


Re: [PATCH] D23492: Make function local tags visible.

2016-08-18 Thread Vassil Vassilev via cfe-commits
v.g.vassilev updated this revision to Diff 68620.
v.g.vassilev marked an inline comment as done.
v.g.vassilev added a comment.

Move DiagnoseUninstantiableTemplate before the late template parsing.


https://reviews.llvm.org/D23492

Files:
  include/clang/Sema/Sema.h
  lib/Sema/SemaTemplate.cpp
  lib/Sema/SemaTemplateInstantiate.cpp
  lib/Sema/SemaTemplateInstantiateDecl.cpp
  test/Modules/Inputs/PR28794/LibAHeader.h
  test/Modules/Inputs/PR28794/Subdir/Empty.h
  test/Modules/Inputs/PR28794/Subdir/LibBHeader.h
  test/Modules/Inputs/PR28794/module.modulemap

Index: test/Modules/Inputs/PR28794/module.modulemap
===
--- test/Modules/Inputs/PR28794/module.modulemap
+++ test/Modules/Inputs/PR28794/module.modulemap
@@ -0,0 +1,3 @@
+module M {
+  umbrella "Subdir" module * {export *}
+}
Index: test/Modules/Inputs/PR28794/Subdir/LibBHeader.h
===
--- test/Modules/Inputs/PR28794/Subdir/LibBHeader.h
+++ test/Modules/Inputs/PR28794/Subdir/LibBHeader.h
@@ -0,0 +1,12 @@
+#ifndef LIB_B_HEADER
+#define LIB_B_HEADER
+
+#include "LibAHeader.h"
+
+template 
+void *operator new(size_t, BumpPtrAllocatorImpl &) {
+  struct S {};
+  return (void*)0xdead;
+}
+
+#endif // LIB_B_HEADER
Index: test/Modules/Inputs/PR28794/Subdir/Empty.h
===
--- test/Modules/Inputs/PR28794/Subdir/Empty.h
+++ test/Modules/Inputs/PR28794/Subdir/Empty.h
@@ -0,0 +1 @@
+
Index: test/Modules/Inputs/PR28794/LibAHeader.h
===
--- test/Modules/Inputs/PR28794/LibAHeader.h
+++ test/Modules/Inputs/PR28794/LibAHeader.h
@@ -0,0 +1,12 @@
+#ifndef LIB_A_HEADER
+#define LIB_A_HEADER
+
+typedef __SIZE_TYPE__ size_t;
+
+template 
+class BumpPtrAllocatorImpl;
+
+template 
+void * operator new(size_t, BumpPtrAllocatorImpl &);
+
+#endif // LIB_A_HEADER
Index: lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -3545,7 +3545,8 @@
 
   // Never instantiate an explicit specialization except if it is a class scope
   // explicit specialization.
-  if (Function->getTemplateSpecializationKind() == TSK_ExplicitSpecialization &&
+  TemplateSpecializationKind TSK = Function->getTemplateSpecializationKind();
+  if (TSK == TSK_ExplicitSpecialization &&
   !Function->getClassScopeSpecializationPattern())
 return;
 
@@ -3561,6 +3562,16 @@
   }
   assert(PatternDecl && "template definition is not a template");
 
+  // FIXME: We need to track the instantiation stack in order to know which
+  // definitions should be visible within this instantiation.
+  if (DiagnoseUninstantiableTemplate(PointOfInstantiation, Function,
+Function->getInstantiatedFromMemberFunction(),
+ PatternDecl, PatternDecl, TSK,
+ /*Complain*/DefinitionRequired))
+ return;
+
+
+
   // Postpone late parsed template instantiations.
   if (PatternDecl->isLateTemplateParsed() &&
   !LateTemplateParser) {
@@ -3593,10 +3604,8 @@
 Pattern = PatternDecl->getBody(PatternDecl);
   }
 
-  // FIXME: Check that the definition is visible before trying to instantiate
-  // it. This requires us to track the instantiation stack in order to know
-  // which definitions should be visible.
-
+  // FIXME: Check if we could sink these diagnostics in
+  // DiagnoseUninstantiableTemplate.
   if (!Pattern && !PatternDecl->isDefaulted()) {
 if (DefinitionRequired) {
   if (Function->getPrimaryTemplate())
@@ -3612,13 +3621,11 @@
 Diag(PatternDecl->getLocation(),
  diag::note_explicit_instantiation_here);
   Function->setInvalidDecl();
-} else if (Function->getTemplateSpecializationKind()
- == TSK_ExplicitInstantiationDefinition) {
+} else if (TSK == TSK_ExplicitInstantiationDefinition) {
   assert(!Recursive);
   PendingInstantiations.push_back(
 std::make_pair(Function, PointOfInstantiation));
-} else if (Function->getTemplateSpecializationKind()
- == TSK_ImplicitInstantiation) {
+} else if (TSK == TSK_ImplicitInstantiation) {
   if (AtEndOfTU && !getDiagnostics().hasErrorOccurred()) {
 Diag(PointOfInstantiation, diag::warn_func_template_missing)
   << Function;
@@ -3637,8 +3644,7 @@
   //   initializer or return value, and class template specializations, other
   //   explicit instantiation declarations have the effect of suppressing the
   //   implicit instantiation of the entity to which they refer.
-  if (Function->getTemplateSpecializationKind() ==
-  TSK_ExplicitInstantiationDeclaration &&
+  if (TSK == TSK_ExplicitInstantiationDeclaration &&
   !PatternDecl->isInlined() &&
   !PatternDecl

r279154 - CodeGen: use range based for loop, NFC

2016-08-18 Thread Saleem Abdulrasool via cfe-commits
Author: compnerd
Date: Thu Aug 18 16:40:06 2016
New Revision: 279154

URL: http://llvm.org/viewvc/llvm-project?rev=279154&view=rev
Log:
CodeGen: use range based for loop, NFC

Modified:
cfe/trunk/lib/CodeGen/CGCall.cpp

Modified: cfe/trunk/lib/CodeGen/CGCall.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGCall.cpp?rev=279154&r1=279153&r2=279154&view=diff
==
--- cfe/trunk/lib/CodeGen/CGCall.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGCall.cpp Thu Aug 18 16:40:06 2016
@@ -2532,9 +2532,8 @@ static llvm::Value *tryEmitFusedAutorele
   }
 
   // Delete all the unnecessary instructions, from latest to earliest.
-  for (SmallVectorImpl::iterator
- i = insnsToKill.begin(), e = insnsToKill.end(); i != e; ++i)
-(*i)->eraseFromParent();
+  for (auto *I : insnsToKill)
+I->eraseFromParent();
 
   // Do the fused retain/autorelease if we were asked to.
   if (doRetainAutorelease)


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


Re: [PATCH] D23696: [CMake] Get libcxx building under LLVM/runtimes

2016-08-18 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL279151: [CMake] Get libcxx building under LLVM/runtimes 
(authored by cbieneman).

Changed prior to commit:
  https://reviews.llvm.org/D23696?vs=68610&id=68613#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D23696

Files:
  libcxx/trunk/CMakeLists.txt
  libcxx/trunk/cmake/Modules/HandleOutOfTreeLLVM.cmake
  libcxx/trunk/test/CMakeLists.txt

Index: libcxx/trunk/cmake/Modules/HandleOutOfTreeLLVM.cmake
===
--- libcxx/trunk/cmake/Modules/HandleOutOfTreeLLVM.cmake
+++ libcxx/trunk/cmake/Modules/HandleOutOfTreeLLVM.cmake
@@ -1,15 +1,17 @@
 macro(find_llvm_parts)
 # Rely on llvm-config.
   set(CONFIG_OUTPUT)
-  find_program(LLVM_CONFIG "llvm-config")
+  if(NOT LLVM_CONFIG_PATH)
+find_program(LLVM_CONFIG_PATH "llvm-config")
+  endif()
   if(DEFINED LLVM_PATH)
 set(LLVM_INCLUDE_DIR ${LLVM_INCLUDE_DIR} CACHE PATH "Path to llvm/include")
 set(LLVM_PATH ${LLVM_PATH} CACHE PATH "Path to LLVM source tree")
 set(LLVM_MAIN_SRC_DIR ${LLVM_PATH})
 set(LLVM_CMAKE_PATH "${LLVM_PATH}/cmake/modules")
-  elseif(LLVM_CONFIG)
-message(STATUS "Found LLVM_CONFIG as ${LLVM_CONFIG}")
-set(CONFIG_COMMAND ${LLVM_CONFIG}
+  elseif(LLVM_CONFIG_PATH)
+message(STATUS "Found LLVM_CONFIG_PATH as ${LLVM_CONFIG_PATH}")
+set(CONFIG_COMMAND ${LLVM_CONFIG_PATH}
   "--includedir"
   "--prefix"
   "--src-root")
@@ -60,8 +62,8 @@
 endmacro(find_llvm_parts)
 
 
-if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
-  set(LIBCXX_BUILT_STANDALONE 1)
+if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR OR 
LIBCXX_STANDALONE_BUILD)
+  set(LIBCXX_STANDALONE_BUILD 1)
   message(STATUS "Configuring for standalone build.")
 
   find_llvm_parts()
Index: libcxx/trunk/test/CMakeLists.txt
===
--- libcxx/trunk/test/CMakeLists.txt
+++ libcxx/trunk/test/CMakeLists.txt
@@ -1,3 +1,5 @@
+include(AddLLVM) # for add_lit_testsuite
+
 macro(pythonize_bool var)
   if (${var})
 set(${var} True)
Index: libcxx/trunk/CMakeLists.txt
===
--- libcxx/trunk/CMakeLists.txt
+++ libcxx/trunk/CMakeLists.txt
@@ -22,16 +22,16 @@
 # Find the LLVM sources and simulate LLVM CMake options.
 include(HandleOutOfTreeLLVM)
 
-if (LIBCXX_BUILT_STANDALONE)
+if (LIBCXX_STANDALONE_BUILD)
   project(libcxx CXX C)
 
   set(PACKAGE_NAME libcxx)
   set(PACKAGE_VERSION 4.0.0svn)
   set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
   set(PACKAGE_BUGREPORT "llvm-b...@lists.llvm.org")
 endif()
 
-if (LIBCXX_BUILT_STANDALONE AND NOT LLVM_FOUND)
+if (LIBCXX_STANDALONE_BUILD AND NOT LLVM_FOUND)
   message(WARNING "UNSUPPORTED LIBCXX CONFIGURATION DETECTED: "
   "llvm-config not found and LLVM_PATH not defined.\n"
   "Reconfigure with -DLLVM_CONFIG=path/to/llvm-config "
@@ -81,7 +81,7 @@
 
 # Setup the default options if LIBCXX_CXX_ABI is not specified.
 if (NOT LIBCXX_CXX_ABI)
-  if (NOT DEFINED LIBCXX_BUILT_STANDALONE AND
+  if (NOT DEFINED LIBCXX_STANDALONE_BUILD AND
   IS_DIRECTORY "${CMAKE_SOURCE_DIR}/projects/libcxxabi")
 set(LIBCXX_CXX_ABI_LIBNAME "libcxxabi")
 set(LIBCXX_CXX_ABI_INCLUDE_PATHS 
"${CMAKE_SOURCE_DIR}/projects/libcxxabi/include")
@@ -367,9 +367,9 @@
 
 # Sanitizer flags =
 
-# Configure for sanitizers. If LIBCXX_BUILT_STANDALONE then we have to do
+# Configure for sanitizers. If LIBCXX_STANDALONE_BUILD then we have to do
 # the flag translation ourselves. Othewise LLVM's CMakeList.txt will handle it.
-if (LIBCXX_BUILT_STANDALONE)
+if (LIBCXX_STANDALONE_BUILD)
   set(LLVM_USE_SANITIZER "" CACHE STRING
   "Define the sanitizer used to build the library and tests")
   # NOTE: LLVM_USE_SANITIZER checks for a UNIX like system instead of MSVC.


Index: libcxx/trunk/cmake/Modules/HandleOutOfTreeLLVM.cmake
===
--- libcxx/trunk/cmake/Modules/HandleOutOfTreeLLVM.cmake
+++ libcxx/trunk/cmake/Modules/HandleOutOfTreeLLVM.cmake
@@ -1,15 +1,17 @@
 macro(find_llvm_parts)
 # Rely on llvm-config.
   set(CONFIG_OUTPUT)
-  find_program(LLVM_CONFIG "llvm-config")
+  if(NOT LLVM_CONFIG_PATH)
+find_program(LLVM_CONFIG_PATH "llvm-config")
+  endif()
   if(DEFINED LLVM_PATH)
 set(LLVM_INCLUDE_DIR ${LLVM_INCLUDE_DIR} CACHE PATH "Path to llvm/include")
 set(LLVM_PATH ${LLVM_PATH} CACHE PATH "Path to LLVM source tree")
 set(LLVM_MAIN_SRC_DIR ${LLVM_PATH})
 set(LLVM_CMAKE_PATH "${LLVM_PATH}/cmake/modules")
-  elseif(LLVM_CONFIG)
-message(STATUS "Found LLVM_CONFIG as ${LLVM_CONFIG}")
-set(CONFIG_COMMAND ${LLVM_CONFIG}
+  elseif(LLVM_CONFIG_PATH)
+message(STATUS "Found LLVM_CONFIG_PATH as ${LLVM_CONFIG_PATH}")
+set(CONFIG_COMMAND ${LLVM_CONFIG_PATH}
   "--included

[libcxx] r279151 - [CMake] Get libcxx building under LLVM/runtimes

2016-08-18 Thread Chris Bieneman via cfe-commits
Author: cbieneman
Date: Thu Aug 18 16:31:51 2016
New Revision: 279151

URL: http://llvm.org/viewvc/llvm-project?rev=279151&view=rev
Log:
[CMake] Get libcxx building under LLVM/runtimes

Summary:
The new LLVM runtimes build directory requires some basic conventions across 
the runtime projects. These changes make libcxx build under the runtimes 
subdirectory. The general idea of the changes is that the runtimes subdirectory 
requires some conventions to be consistent across runtime projects.

I expect to have a few more small patches that build on this to tie up check 
targets and other things useful in development workflows.

Summary of changes in this patch:

* Renamed variable LLVM_CONFIG -> LLVM_CONFIG_PATH
* Renamed variable LIBCXX_BUILT_STANDALONE -> LIBCXX_STANDALONE_BUILD
* Add an include of AddLLVM in the tests subdirectory for add_lit_testsuite.

Reviewers: EricWF

Subscribers: cfe-commits

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

Modified:
libcxx/trunk/CMakeLists.txt
libcxx/trunk/cmake/Modules/HandleOutOfTreeLLVM.cmake
libcxx/trunk/test/CMakeLists.txt

Modified: libcxx/trunk/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/CMakeLists.txt?rev=279151&r1=279150&r2=279151&view=diff
==
--- libcxx/trunk/CMakeLists.txt (original)
+++ libcxx/trunk/CMakeLists.txt Thu Aug 18 16:31:51 2016
@@ -22,7 +22,7 @@ set(CMAKE_MODULE_PATH
 # Find the LLVM sources and simulate LLVM CMake options.
 include(HandleOutOfTreeLLVM)
 
-if (LIBCXX_BUILT_STANDALONE)
+if (LIBCXX_STANDALONE_BUILD)
   project(libcxx CXX C)
 
   set(PACKAGE_NAME libcxx)
@@ -31,7 +31,7 @@ if (LIBCXX_BUILT_STANDALONE)
   set(PACKAGE_BUGREPORT "llvm-b...@lists.llvm.org")
 endif()
 
-if (LIBCXX_BUILT_STANDALONE AND NOT LLVM_FOUND)
+if (LIBCXX_STANDALONE_BUILD AND NOT LLVM_FOUND)
   message(WARNING "UNSUPPORTED LIBCXX CONFIGURATION DETECTED: "
   "llvm-config not found and LLVM_PATH not defined.\n"
   "Reconfigure with -DLLVM_CONFIG=path/to/llvm-config "
@@ -81,7 +81,7 @@ set_property(CACHE LIBCXX_CXX_ABI PROPER
 
 # Setup the default options if LIBCXX_CXX_ABI is not specified.
 if (NOT LIBCXX_CXX_ABI)
-  if (NOT DEFINED LIBCXX_BUILT_STANDALONE AND
+  if (NOT DEFINED LIBCXX_STANDALONE_BUILD AND
   IS_DIRECTORY "${CMAKE_SOURCE_DIR}/projects/libcxxabi")
 set(LIBCXX_CXX_ABI_LIBNAME "libcxxabi")
 set(LIBCXX_CXX_ABI_INCLUDE_PATHS 
"${CMAKE_SOURCE_DIR}/projects/libcxxabi/include")
@@ -367,9 +367,9 @@ define_if(MSVC -D_CRT_SECURE_NO_WARNINGS
 
 # Sanitizer flags =
 
-# Configure for sanitizers. If LIBCXX_BUILT_STANDALONE then we have to do
+# Configure for sanitizers. If LIBCXX_STANDALONE_BUILD then we have to do
 # the flag translation ourselves. Othewise LLVM's CMakeList.txt will handle it.
-if (LIBCXX_BUILT_STANDALONE)
+if (LIBCXX_STANDALONE_BUILD)
   set(LLVM_USE_SANITIZER "" CACHE STRING
   "Define the sanitizer used to build the library and tests")
   # NOTE: LLVM_USE_SANITIZER checks for a UNIX like system instead of MSVC.

Modified: libcxx/trunk/cmake/Modules/HandleOutOfTreeLLVM.cmake
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/cmake/Modules/HandleOutOfTreeLLVM.cmake?rev=279151&r1=279150&r2=279151&view=diff
==
--- libcxx/trunk/cmake/Modules/HandleOutOfTreeLLVM.cmake (original)
+++ libcxx/trunk/cmake/Modules/HandleOutOfTreeLLVM.cmake Thu Aug 18 16:31:51 
2016
@@ -1,15 +1,17 @@
 macro(find_llvm_parts)
 # Rely on llvm-config.
   set(CONFIG_OUTPUT)
-  find_program(LLVM_CONFIG "llvm-config")
+  if(NOT LLVM_CONFIG_PATH)
+find_program(LLVM_CONFIG_PATH "llvm-config")
+  endif()
   if(DEFINED LLVM_PATH)
 set(LLVM_INCLUDE_DIR ${LLVM_INCLUDE_DIR} CACHE PATH "Path to llvm/include")
 set(LLVM_PATH ${LLVM_PATH} CACHE PATH "Path to LLVM source tree")
 set(LLVM_MAIN_SRC_DIR ${LLVM_PATH})
 set(LLVM_CMAKE_PATH "${LLVM_PATH}/cmake/modules")
-  elseif(LLVM_CONFIG)
-message(STATUS "Found LLVM_CONFIG as ${LLVM_CONFIG}")
-set(CONFIG_COMMAND ${LLVM_CONFIG}
+  elseif(LLVM_CONFIG_PATH)
+message(STATUS "Found LLVM_CONFIG_PATH as ${LLVM_CONFIG_PATH}")
+set(CONFIG_COMMAND ${LLVM_CONFIG_PATH}
   "--includedir"
   "--prefix"
   "--src-root")
@@ -60,8 +62,8 @@ macro(find_llvm_parts)
 endmacro(find_llvm_parts)
 
 
-if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
-  set(LIBCXX_BUILT_STANDALONE 1)
+if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR OR 
LIBCXX_STANDALONE_BUILD)
+  set(LIBCXX_STANDALONE_BUILD 1)
   message(STATUS "Configuring for standalone build.")
 
   find_llvm_parts()

Modified: libcxx/trunk/test/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/CMakeLists.txt?rev=279151&r1=279150&r2=279151&view=diff
===

Re: [PATCH] D23696: [CMake] Get libcxx building under LLVM/runtimes

2016-08-18 Thread Eric Fiselier via cfe-commits
EricWF accepted this revision.
EricWF added a comment.
This revision is now accepted and ready to land.

LGTM


https://reviews.llvm.org/D23696



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


[PATCH] D23696: [CMake] Get libcxx building under LLVM/runtimes

2016-08-18 Thread Chris Bieneman via cfe-commits
beanz created this revision.
beanz added a reviewer: EricWF.
beanz added a subscriber: cfe-commits.

The new LLVM runtimes build directory requires some basic conventions across 
the runtime projects. These changes make libcxx build under the runtimes 
subdirectory. The general idea of the changes is that the runtimes subdirectory 
requires some conventions to be consistent across runtime projects.

I expect to have a few more small patches that build on this to tie up check 
targets and other things useful in development workflows.

Summary of changes in this patch:

* Renamed variable LLVM_CONFIG -> LLVM_CONFIG_PATH
* Renamed variable LIBCXX_BUILT_STANDALONE -> LIBCXX_STANDALONE_BUILD
* Add an include of AddLLVM in the tests subdirectory for add_lit_testsuite.

https://reviews.llvm.org/D23696

Files:
  CMakeLists.txt
  cmake/Modules/HandleOutOfTreeLLVM.cmake
  test/CMakeLists.txt

Index: test/CMakeLists.txt
===
--- test/CMakeLists.txt
+++ test/CMakeLists.txt
@@ -1,3 +1,5 @@
+include(AddLLVM) # for add_lit_testsuite
+
 macro(pythonize_bool var)
   if (${var})
 set(${var} True)
Index: cmake/Modules/HandleOutOfTreeLLVM.cmake
===
--- cmake/Modules/HandleOutOfTreeLLVM.cmake
+++ cmake/Modules/HandleOutOfTreeLLVM.cmake
@@ -1,15 +1,17 @@
 macro(find_llvm_parts)
 # Rely on llvm-config.
   set(CONFIG_OUTPUT)
-  find_program(LLVM_CONFIG "llvm-config")
+  if(NOT LLVM_CONFIG_PATH)
+find_program(LLVM_CONFIG_PATH "llvm-config")
+  endif()
   if(DEFINED LLVM_PATH)
 set(LLVM_INCLUDE_DIR ${LLVM_INCLUDE_DIR} CACHE PATH "Path to llvm/include")
 set(LLVM_PATH ${LLVM_PATH} CACHE PATH "Path to LLVM source tree")
 set(LLVM_MAIN_SRC_DIR ${LLVM_PATH})
 set(LLVM_CMAKE_PATH "${LLVM_PATH}/cmake/modules")
-  elseif(LLVM_CONFIG)
-message(STATUS "Found LLVM_CONFIG as ${LLVM_CONFIG}")
-set(CONFIG_COMMAND ${LLVM_CONFIG}
+  elseif(LLVM_CONFIG_PATH)
+message(STATUS "Found LLVM_CONFIG_PATH as ${LLVM_CONFIG_PATH}")
+set(CONFIG_COMMAND ${LLVM_CONFIG_PATH}
   "--includedir"
   "--prefix"
   "--src-root")
@@ -60,8 +62,8 @@
 endmacro(find_llvm_parts)
 
 
-if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
-  set(LIBCXX_BUILT_STANDALONE 1)
+if (CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR OR 
LIBCXX_STANDALONE_BUILD)
+  set(LIBCXX_STANDALONE_BUILD 1)
   message(STATUS "Configuring for standalone build.")
 
   find_llvm_parts()
Index: CMakeLists.txt
===
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -22,16 +22,16 @@
 # Find the LLVM sources and simulate LLVM CMake options.
 include(HandleOutOfTreeLLVM)
 
-if (LIBCXX_BUILT_STANDALONE)
+if (LIBCXX_STANDALONE_BUILD)
   project(libcxx CXX C)
 
   set(PACKAGE_NAME libcxx)
   set(PACKAGE_VERSION 4.0.0svn)
   set(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
   set(PACKAGE_BUGREPORT "llvm-b...@lists.llvm.org")
 endif()
 
-if (LIBCXX_BUILT_STANDALONE AND NOT LLVM_FOUND)
+if (LIBCXX_STANDALONE_BUILD AND NOT LLVM_FOUND)
   message(WARNING "UNSUPPORTED LIBCXX CONFIGURATION DETECTED: "
   "llvm-config not found and LLVM_PATH not defined.\n"
   "Reconfigure with -DLLVM_CONFIG=path/to/llvm-config "
@@ -81,7 +81,7 @@
 
 # Setup the default options if LIBCXX_CXX_ABI is not specified.
 if (NOT LIBCXX_CXX_ABI)
-  if (NOT DEFINED LIBCXX_BUILT_STANDALONE AND
+  if (NOT DEFINED LIBCXX_STANDALONE_BUILD AND
   IS_DIRECTORY "${CMAKE_SOURCE_DIR}/projects/libcxxabi")
 set(LIBCXX_CXX_ABI_LIBNAME "libcxxabi")
 set(LIBCXX_CXX_ABI_INCLUDE_PATHS 
"${CMAKE_SOURCE_DIR}/projects/libcxxabi/include")
@@ -367,9 +367,9 @@
 
 # Sanitizer flags =
 
-# Configure for sanitizers. If LIBCXX_BUILT_STANDALONE then we have to do
+# Configure for sanitizers. If LIBCXX_STANDALONE_BUILD then we have to do
 # the flag translation ourselves. Othewise LLVM's CMakeList.txt will handle it.
-if (LIBCXX_BUILT_STANDALONE)
+if (LIBCXX_STANDALONE_BUILD)
   set(LLVM_USE_SANITIZER "" CACHE STRING
   "Define the sanitizer used to build the library and tests")
   # NOTE: LLVM_USE_SANITIZER checks for a UNIX like system instead of MSVC.


Index: test/CMakeLists.txt
===
--- test/CMakeLists.txt
+++ test/CMakeLists.txt
@@ -1,3 +1,5 @@
+include(AddLLVM) # for add_lit_testsuite
+
 macro(pythonize_bool var)
   if (${var})
 set(${var} True)
Index: cmake/Modules/HandleOutOfTreeLLVM.cmake
===
--- cmake/Modules/HandleOutOfTreeLLVM.cmake
+++ cmake/Modules/HandleOutOfTreeLLVM.cmake
@@ -1,15 +1,17 @@
 macro(find_llvm_parts)
 # Rely on llvm-config.
   set(CONFIG_OUTPUT)
-  find_program(LLVM_CONFIG "llvm-config")
+  if(NOT LLVM_CONFIG_PATH)
+find_program(LLVM_CONFIG_PATH "llvm-config")

Re: [PATCH] D23684: Resolve ambiguity in a declaration if global nested name specifier is used

2016-08-18 Thread Richard Smith via cfe-commits
PR28422 is invalid. Giving better diagnostics in this case seems
reasonable, but we should not accept the ill-formed code.

On 18 Aug 2016 11:41 a.m., "Serge Pavlov"  wrote:

> sepavloff created this revision.
> sepavloff added reviewers: rsmith, doug.gregor.
> sepavloff added a subscriber: cfe-commits.
>
> If a declaration references a function from global namespace by its
> qualified name and if that function return type is a class or enum, there
> is possible ambiguity. The declaration:
> ```
> friend A::B::C();
> ```
> may be considered as a declaration of a function `::C()` that returns
> `A::B`, or a function `::B::C()` that returns `A`.
>
> With this change when the compiler sees 'A::B' while parsing decl-spec, it
> tries to find `B` within 'A'. If it finds, 'A::B' is treated as a part of
> qualified name. If it doesn't and the current declaration declares a
> function, '::B' is assumed to be a part of declarator. For non-function
> declarations 'B' can be searched for in the global namespace to improve
> diagnostics.
>
> This changes fixes https://llvm.org/bugs/show_bug.cgi?id=28422.
>
> https://reviews.llvm.org/D23684
>
> Files:
>   include/clang/Parse/Parser.h
>   include/clang/Sema/Sema.h
>   lib/Parse/ParseDecl.cpp
>   lib/Parse/ParseDeclCXX.cpp
>   lib/Parse/ParseExprCXX.cpp
>   lib/Parse/Parser.cpp
>   lib/Parse/RAIIObjectsForParser.h
>   lib/Sema/SemaCXXScopeSpec.cpp
>   lib/Sema/TreeTransform.h
>   test/CXX/drs/dr1xx.cpp
>   test/CXX/drs/dr2xx.cpp
>   test/Parser/cxx-decl.cpp
>   test/SemaCXX/nested-name-spec2.cpp
>   test/SemaCXX/pr18284-crash-on-invalid.cpp
>   test/SemaCXX/typo-correction.cpp
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [PATCH] D23492: Make function local tags visible.

2016-08-18 Thread Richard Smith via cfe-commits
rsmith added inline comments.


Comment at: lib/Sema/SemaTemplateInstantiateDecl.cpp:3598-3603
@@ -3599,1 +3597,8 @@
+  // FIXME: We need to track the instantiation stack in order to know which
+  // definitions should be visible within this instantiation.
+  if (DiagnoseUninstantiableTemplate(PointOfInstantiation, Function,
+Function->getInstantiatedFromMemberFunction(),
+ PatternDecl, PatternDecl, TSK,
+ /*Complain*/DefinitionRequired))
+ return;
 

As long as we treat a late-parsed template as being defined, it should be fine 
(and looking at `FunctionDecl::isThisDeclarationADefinition`, we do). It's not 
correct to parse a late-parsed template that's not visible, so we need to move 
this check to before we handle late-parsed templates for correctness.


https://reviews.llvm.org/D23492



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


Re: [PATCH] D23692: Interpret strlen as constexpr for GCC Compatibility

2016-08-18 Thread Erich Keane via cfe-commits
erichkeane abandoned this revision.
erichkeane added a comment.

In https://reviews.llvm.org/D23692#520081, @rsmith wrote:

> This is not a conforming extension. We are explicitly not allowed to make 
> standard library functions `constexpr` if the standard doesn't say they are; 
> see [constexpr.functions] (17.6.5.6) in the C++ standard. Clang previously 
> used to allow constant-folding `strlen` calls, but we removed that support 
> intentionally for this reason.
>
> It would seem reasonable for this constant-folding to be enabled for `strlen` 
> if the callee was explicitly marked as `constexpr` in the source code. That 
> way, if the standard library chooses to mark it as `constexpr` as a 
> (currently) non-conforming extension, we would provide an optimized 
> implementation.


Ok, thank you for your prompt response.  I'll see if that is a viable solution 
for this case.

Thanks!


Repository:
  rL LLVM

https://reviews.llvm.org/D23692



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


r279145 - Fixed more signed/unsigned mismatch warnings introduced in my change at r279076

2016-08-18 Thread Cameron Desrochers via cfe-commits
Author: cameron314
Date: Thu Aug 18 15:56:48 2016
New Revision: 279145

URL: http://llvm.org/viewvc/llvm-project?rev=279145&view=rev
Log:
Fixed more signed/unsigned mismatch warnings introduced in my change at r279076

Modified:
cfe/trunk/unittests/libclang/LibclangTest.cpp

Modified: cfe/trunk/unittests/libclang/LibclangTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/libclang/LibclangTest.cpp?rev=279145&r1=279144&r2=279145&view=diff
==
--- cfe/trunk/unittests/libclang/LibclangTest.cpp (original)
+++ cfe/trunk/unittests/libclang/LibclangTest.cpp Thu Aug 18 15:56:48 2016
@@ -439,23 +439,23 @@ TEST_F(LibclangParseTest, AllSkippedRang
nullptr, 0, TUFlags);
 
   CXSourceRangeList *Ranges = clang_getAllSkippedRanges(ClangTU);
-  EXPECT_EQ(2u, Ranges->count);
+  EXPECT_EQ(2U, Ranges->count);
   
   CXSourceLocation cxl;
   unsigned line;
   cxl = clang_getRangeStart(Ranges->ranges[0]);
   clang_getSpellingLocation(cxl, nullptr, &line, nullptr, nullptr);
-  EXPECT_EQ(1, line);
+  EXPECT_EQ(1U, line);
   cxl = clang_getRangeEnd(Ranges->ranges[0]);
   clang_getSpellingLocation(cxl, nullptr, &line, nullptr, nullptr);
-  EXPECT_EQ(3, line);
+  EXPECT_EQ(3U, line);
 
   cxl = clang_getRangeStart(Ranges->ranges[1]);
   clang_getSpellingLocation(cxl, nullptr, &line, nullptr, nullptr);
-  EXPECT_EQ(2, line);
+  EXPECT_EQ(2U, line);
   cxl = clang_getRangeEnd(Ranges->ranges[1]);
   clang_getSpellingLocation(cxl, nullptr, &line, nullptr, nullptr);
-  EXPECT_EQ(4, line);
+  EXPECT_EQ(4U, line);
 
   clang_disposeSourceRangeList(Ranges);
 }


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


Re: [PATCH] D23692: Interpret strlen as constexpr for GCC Compatibility

2016-08-18 Thread Richard Smith via cfe-commits
rsmith requested changes to this revision.
rsmith added a comment.
This revision now requires changes to proceed.

This is not a conforming extension. We are explicitly not allowed to make 
standard library functions `constexpr` if the standard doesn't say they are; 
see [constexpr.functions] (17.6.5.6) in the C++ standard. Clang previously used 
to allow constant-folding `strlen` calls, but we removed that support 
intentionally for this reason.

It would seem reasonable for this constant-folding to be enabled for `strlen` 
if the callee was explicitly marked as `constexpr` in the source code. That 
way, if the standard library chooses to mark it as `constexpr` as a (currently) 
non-conforming extension, we would provide an optimized implementation.


Repository:
  rL LLVM

https://reviews.llvm.org/D23692



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


Re: [PATCH] D23627: [CUDA] Improve handling of math functions.

2016-08-18 Thread Justin Lebar via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL279140: [CUDA] Improve handling of math functions. (authored 
by jlebar).

Changed prior to commit:
  https://reviews.llvm.org/D23627?vs=68427&id=68600#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D23627

Files:
  cfe/trunk/lib/Headers/__clang_cuda_cmath.h
  cfe/trunk/lib/Headers/__clang_cuda_math_forward_declares.h

Index: cfe/trunk/lib/Headers/__clang_cuda_math_forward_declares.h
===
--- cfe/trunk/lib/Headers/__clang_cuda_math_forward_declares.h
+++ cfe/trunk/lib/Headers/__clang_cuda_math_forward_declares.h
@@ -140,6 +140,7 @@
 __DEVICE__ long lrint(float);
 __DEVICE__ long lround(double);
 __DEVICE__ long lround(float);
+__DEVICE__ long long llround(float); // No llround(double).
 __DEVICE__ double modf(double, double *);
 __DEVICE__ float modf(float, float *);
 __DEVICE__ double nan(const char *);
@@ -149,7 +150,8 @@
 __DEVICE__ double nextafter(double, double);
 __DEVICE__ float nextafter(float, float);
 __DEVICE__ double nexttoward(double, double);
-__DEVICE__ float nexttoward(float, float);
+__DEVICE__ float nexttoward(float, double);
+__DEVICE__ float nexttowardf(float, double);
 __DEVICE__ double pow(double, double);
 __DEVICE__ double pow(double, int);
 __DEVICE__ float pow(float, float);
@@ -235,6 +237,7 @@
 using ::logb;
 using ::lrint;
 using ::lround;
+using ::llround;
 using ::modf;
 using ::nan;
 using ::nanf;
Index: cfe/trunk/lib/Headers/__clang_cuda_cmath.h
===
--- cfe/trunk/lib/Headers/__clang_cuda_cmath.h
+++ cfe/trunk/lib/Headers/__clang_cuda_cmath.h
@@ -26,13 +26,15 @@
 #error "This file is for CUDA compilation only."
 #endif
 
+#include 
+
 // CUDA lets us use various std math functions on the device side.  This file
 // works in concert with __clang_cuda_math_forward_declares.h to make this work.
 //
 // Specifically, the forward-declares header declares __device__ overloads for
 // these functions in the global namespace, then pulls them into namespace std
 // with 'using' statements.  Then this file implements those functions, after
-// the implementations have been pulled in.
+// their implementations have been pulled in.
 //
 // It's important that we declare the functions in the global namespace and pull
 // them into namespace std with using statements, as opposed to simply declaring
@@ -120,12 +122,15 @@
 __DEVICE__ float log(float __x) { return ::logf(__x); }
 __DEVICE__ float log10(float __x) { return ::log10f(__x); }
 __DEVICE__ float modf(float __x, float *__iptr) { return ::modff(__x, __iptr); }
-__DEVICE__ float nexttoward(float __from, float __to) {
+__DEVICE__ float nexttoward(float __from, double __to) {
   return __builtin_nexttowardf(__from, __to);
 }
 __DEVICE__ double nexttoward(double __from, double __to) {
   return __builtin_nexttoward(__from, __to);
 }
+__DEVICE__ float nexttowardf(float __from, double __to) {
+  return __builtin_nexttowardf(__from, __to);
+}
 __DEVICE__ float pow(float __base, float __exp) {
   return ::powf(__base, __exp);
 }
@@ -143,6 +148,280 @@
 __DEVICE__ float tan(float __x) { return ::tanf(__x); }
 __DEVICE__ float tanh(float __x) { return ::tanhf(__x); }
 
+// Now we've defined everything we promised we'd define in
+// __clang_cuda_math_forward_declares.h.  We need to do two additional things to
+// fix up our math functions.
+//
+// 1) Define __device__ overloads for e.g. sin(int).  The CUDA headers define
+//only sin(float) and sin(double), which means that e.g. sin(0) is
+//ambiguous.
+//
+// 2) Pull the __device__ overloads of "foobarf" math functions into namespace
+//std.  These are defined in the CUDA headers in the global namespace,
+//independent of everything else we've done here.
+
+// We can't use std::enable_if, because we want to be pre-C++11 compatible.  But
+// we go ahead and unconditionally define functions that are only available when
+// compiling for C++11 to match the behavior of the CUDA headers.
+template
+struct __clang_cuda_enable_if {};
+
+template  struct __clang_cuda_enable_if {
+  typedef __T type;
+};
+
+// Defines an overload of __fn that accepts one integral argument, calls
+// __fn((double)x), and returns __retty.
+#define __CUDA_CLANG_FN_INTEGER_OVERLOAD_1(__retty, __fn)  \
+  template   \
+  __DEVICE__   \
+  typename __clang_cuda_enable_if::is_integer,\
+  __retty>::type   \
+  __fn(__T __x) {  \
+return ::__fn((double)__x);\
+  }
+
+// Defines an overload of __fn that accepts one two arithmetic arguments, calls
+// __fn((double)x, (double)y), and

r279140 - [CUDA] Improve handling of math functions.

2016-08-18 Thread Justin Lebar via cfe-commits
Author: jlebar
Date: Thu Aug 18 15:43:13 2016
New Revision: 279140

URL: http://llvm.org/viewvc/llvm-project?rev=279140&view=rev
Log:
[CUDA] Improve handling of math functions.

Summary:
A bunch of related changes here to our CUDA math headers.

- The second arg to nexttoward is a double (well, technically, long
  double, but we don't have that), not a float.

- Add a forward-declare of llround(float), which is defined in the CUDA
  headers.  We need this for the same reason we need most of the other
  forward-declares: To prevent a constexpr function in our standard
  library from becoming host+device.

- Add nexttowardf implementation.

- Pull "foobarf" functions defined by the CUDA headers in the global
  namespace into namespace std.  This lets you do e.g. std::sinf.

- Add overloads for math functions accepting integer types.  This lets
  you do e.g. std::sin(0) without having an ambiguity between the
  overload that takes a float and the one that takes a double.

With these changes, we pass testcases derived from libc++ for cmath and
math.h.  We can check these testcases in to the test-suite once support
for CUDA lands there.

Reviewers: tra

Subscribers: cfe-commits

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

Modified:
cfe/trunk/lib/Headers/__clang_cuda_cmath.h
cfe/trunk/lib/Headers/__clang_cuda_math_forward_declares.h

Modified: cfe/trunk/lib/Headers/__clang_cuda_cmath.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Headers/__clang_cuda_cmath.h?rev=279140&r1=279139&r2=279140&view=diff
==
--- cfe/trunk/lib/Headers/__clang_cuda_cmath.h (original)
+++ cfe/trunk/lib/Headers/__clang_cuda_cmath.h Thu Aug 18 15:43:13 2016
@@ -26,13 +26,15 @@
 #error "This file is for CUDA compilation only."
 #endif
 
+#include 
+
 // CUDA lets us use various std math functions on the device side.  This file
 // works in concert with __clang_cuda_math_forward_declares.h to make this 
work.
 //
 // Specifically, the forward-declares header declares __device__ overloads for
 // these functions in the global namespace, then pulls them into namespace std
 // with 'using' statements.  Then this file implements those functions, after
-// the implementations have been pulled in.
+// their implementations have been pulled in.
 //
 // It's important that we declare the functions in the global namespace and 
pull
 // them into namespace std with using statements, as opposed to simply 
declaring
@@ -120,12 +122,15 @@ __DEVICE__ float ldexp(float __arg, int
 __DEVICE__ float log(float __x) { return ::logf(__x); }
 __DEVICE__ float log10(float __x) { return ::log10f(__x); }
 __DEVICE__ float modf(float __x, float *__iptr) { return ::modff(__x, __iptr); 
}
-__DEVICE__ float nexttoward(float __from, float __to) {
+__DEVICE__ float nexttoward(float __from, double __to) {
   return __builtin_nexttowardf(__from, __to);
 }
 __DEVICE__ double nexttoward(double __from, double __to) {
   return __builtin_nexttoward(__from, __to);
 }
+__DEVICE__ float nexttowardf(float __from, double __to) {
+  return __builtin_nexttowardf(__from, __to);
+}
 __DEVICE__ float pow(float __base, float __exp) {
   return ::powf(__base, __exp);
 }
@@ -143,6 +148,280 @@ __DEVICE__ float sqrt(float __x) { retur
 __DEVICE__ float tan(float __x) { return ::tanf(__x); }
 __DEVICE__ float tanh(float __x) { return ::tanhf(__x); }
 
+// Now we've defined everything we promised we'd define in
+// __clang_cuda_math_forward_declares.h.  We need to do two additional things 
to
+// fix up our math functions.
+//
+// 1) Define __device__ overloads for e.g. sin(int).  The CUDA headers define
+//only sin(float) and sin(double), which means that e.g. sin(0) is
+//ambiguous.
+//
+// 2) Pull the __device__ overloads of "foobarf" math functions into namespace
+//std.  These are defined in the CUDA headers in the global namespace,
+//independent of everything else we've done here.
+
+// We can't use std::enable_if, because we want to be pre-C++11 compatible.  
But
+// we go ahead and unconditionally define functions that are only available 
when
+// compiling for C++11 to match the behavior of the CUDA headers.
+template
+struct __clang_cuda_enable_if {};
+
+template  struct __clang_cuda_enable_if {
+  typedef __T type;
+};
+
+// Defines an overload of __fn that accepts one integral argument, calls
+// __fn((double)x), and returns __retty.
+#define __CUDA_CLANG_FN_INTEGER_OVERLOAD_1(__retty, __fn)  
\
+  template   
\
+  __DEVICE__   
\
+  typename __clang_cuda_enable_if::is_integer,
\
+  __retty>::type   
\
+  __fn(__T __x) {  
\
+return ::__fn((double)__x);  

Re: [PATCH] D23627: [CUDA] Improve handling of math functions.

2016-08-18 Thread Justin Lebar via cfe-commits
jlebar added a comment.

These changes have always been kind of scary.  tra tested this against Thrust 
all combinations of CUDA 7.0/7.5, c++98/11, 
libc++/libstdc++{4.8.5/4.9.3,5.3.0}.  So we should be good here.  I hope.


https://reviews.llvm.org/D23627



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


[PATCH] D23692: Interpret strlen as constexpr for GCC Compatibility

2016-08-18 Thread Erich Keane via cfe-commits
erichkeane created this revision.
erichkeane added reviewers: cfe-commits, majnemer, vbyakovl, DavidKreitzer, 
andreybokhanko, rsmith.
erichkeane set the repository for this revision to rL LLVM.

GCC (and other compilers) treat strlen as a 'constexpr' function as an 
extension to the language.  Clang previously treated __builtin_strlen as a 
constexpr extension, so for this patch it was only necessary to remove the 
error-causing diagnostic for the strlen case, which falls through to the 
__builtin_strlen handling.

Additionally, the strlen test previously expected this error, so this patch 
removes the error-expectation from the test.

Repository:
  rL LLVM

https://reviews.llvm.org/D23692

Files:
  lib/AST/ExprConstant.cpp
  test/SemaCXX/constexpr-strlen.cpp

Index: lib/AST/ExprConstant.cpp
===
--- lib/AST/ExprConstant.cpp
+++ lib/AST/ExprConstant.cpp
@@ -7022,11 +7022,9 @@
   }
 
   case Builtin::BIstrlen:
-// A call to strlen is not a constant expression.
-if (Info.getLangOpts().CPlusPlus11)
-  Info.CCEDiag(E, diag::note_constexpr_invalid_function)
-<< /*isConstexpr*/0 << /*isConstructor*/0 << "'strlen'";
-else
+// As a GCC compatibility extension, we support strlen() 
+// as a constant expression.
+if (!Info.getLangOpts().CPlusPlus11)
   Info.CCEDiag(E, diag::note_invalid_subexpr_in_const_expr);
 // Fall through.
   case Builtin::BI__builtin_strlen: {
Index: test/SemaCXX/constexpr-strlen.cpp
===
--- test/SemaCXX/constexpr-strlen.cpp
+++ test/SemaCXX/constexpr-strlen.cpp
@@ -8,7 +8,7 @@
 
 # 10 "SemaCXX/constexpr-strlen.cpp" 2
 constexpr int n = __builtin_strlen("hello"); // ok
-constexpr int m = strlen("hello"); // expected-error {{constant expression}} 
expected-note {{non-constexpr function 'strlen' cannot be used in a constant 
expression}}
+constexpr int m = strlen("hello"); // ok
 
 // Make sure we can evaluate a call to strlen.
 int arr[3]; // expected-note {{here}}


Index: lib/AST/ExprConstant.cpp
===
--- lib/AST/ExprConstant.cpp
+++ lib/AST/ExprConstant.cpp
@@ -7022,11 +7022,9 @@
   }
 
   case Builtin::BIstrlen:
-// A call to strlen is not a constant expression.
-if (Info.getLangOpts().CPlusPlus11)
-  Info.CCEDiag(E, diag::note_constexpr_invalid_function)
-<< /*isConstexpr*/0 << /*isConstructor*/0 << "'strlen'";
-else
+// As a GCC compatibility extension, we support strlen() 
+// as a constant expression.
+if (!Info.getLangOpts().CPlusPlus11)
   Info.CCEDiag(E, diag::note_invalid_subexpr_in_const_expr);
 // Fall through.
   case Builtin::BI__builtin_strlen: {
Index: test/SemaCXX/constexpr-strlen.cpp
===
--- test/SemaCXX/constexpr-strlen.cpp
+++ test/SemaCXX/constexpr-strlen.cpp
@@ -8,7 +8,7 @@
 
 # 10 "SemaCXX/constexpr-strlen.cpp" 2
 constexpr int n = __builtin_strlen("hello"); // ok
-constexpr int m = strlen("hello"); // expected-error {{constant expression}} expected-note {{non-constexpr function 'strlen' cannot be used in a constant expression}}
+constexpr int m = strlen("hello"); // ok
 
 // Make sure we can evaluate a call to strlen.
 int arr[3]; // expected-note {{here}}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r279127 - Revert [OpenCL] AMDGCN: Fix size_t type

2016-08-18 Thread Yaxun Liu via cfe-commits
Author: yaxunl
Date: Thu Aug 18 15:01:06 2016
New Revision: 279127

URL: http://llvm.org/viewvc/llvm-project?rev=279127&view=rev
Log:
Revert [OpenCL] AMDGCN: Fix size_t type

due to regressions in test/CodeGen/exprs.c on certain platforms.

Removed:
cfe/trunk/test/CodeGenOpenCL/size_t.cl
Modified:
cfe/trunk/include/clang/Basic/TargetInfo.h
cfe/trunk/lib/Basic/TargetInfo.cpp
cfe/trunk/lib/Basic/Targets.cpp
cfe/trunk/lib/CodeGen/CGExprScalar.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/lib/CodeGen/CodeGenTypeCache.h

Modified: cfe/trunk/include/clang/Basic/TargetInfo.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TargetInfo.h?rev=279127&r1=279126&r2=279127&view=diff
==
--- cfe/trunk/include/clang/Basic/TargetInfo.h (original)
+++ cfe/trunk/include/clang/Basic/TargetInfo.h Thu Aug 18 15:01:06 2016
@@ -294,11 +294,6 @@ public:
 return AddrSpace == 0 ? PointerAlign : getPointerAlignV(AddrSpace);
   }
 
-  /// \brief Return the maximum width of pointers on this target.
-  virtual uint64_t getMaxPointerWidth() const {
-return PointerWidth;
-  }
-
   /// \brief Return the size of '_Bool' and C++ 'bool' for this target, in 
bits.
   unsigned getBoolWidth() const { return BoolWidth; }
 

Modified: cfe/trunk/lib/Basic/TargetInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/TargetInfo.cpp?rev=279127&r1=279126&r2=279127&view=diff
==
--- cfe/trunk/lib/Basic/TargetInfo.cpp (original)
+++ cfe/trunk/lib/Basic/TargetInfo.cpp Thu Aug 18 15:01:06 2016
@@ -306,9 +306,8 @@ void TargetInfo::adjust(const LangOption
 }
 LongDoubleWidth = LongDoubleAlign = 128;
 
-unsigned MaxPointerWidth = getMaxPointerWidth();
-assert(MaxPointerWidth == 32 || MaxPointerWidth == 64);
-bool Is32BitArch = MaxPointerWidth == 32;
+assert(PointerWidth == 32 || PointerWidth == 64);
+bool Is32BitArch = PointerWidth == 32;
 SizeType = Is32BitArch ? UnsignedInt : UnsignedLong;
 PtrDiffType = Is32BitArch ? SignedInt : SignedLong;
 IntPtrType = Is32BitArch ? SignedInt : SignedLong;

Modified: cfe/trunk/lib/Basic/Targets.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=279127&r1=279126&r2=279127&view=diff
==
--- cfe/trunk/lib/Basic/Targets.cpp (original)
+++ cfe/trunk/lib/Basic/Targets.cpp Thu Aug 18 15:01:06 2016
@@ -2004,10 +2004,6 @@ public:
 }
   }
 
-  uint64_t getMaxPointerWidth() const override {
-return getTriple().getArch() == llvm::Triple::amdgcn ? 64 : 32;
-  }
-
   const char * getClobbers() const override {
 return "";
   }

Modified: cfe/trunk/lib/CodeGen/CGExprScalar.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprScalar.cpp?rev=279127&r1=279126&r2=279127&view=diff
==
--- cfe/trunk/lib/CodeGen/CGExprScalar.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprScalar.cpp Thu Aug 18 15:01:06 2016
@@ -787,7 +787,7 @@ Value *ScalarExprEmitter::EmitScalarConv
   // Handle pointer conversions next: pointers can only be converted to/from
   // other pointers and integers. Check for pointer types in terms of LLVM, as
   // some native types (like Obj-C id) may map to a pointer type.
-  if (auto DstPT = dyn_cast(DstTy)) {
+  if (isa(DstTy)) {
 // The source value may be an integer, or a pointer.
 if (isa(SrcTy))
   return Builder.CreateBitCast(Src, DstTy, "conv");
@@ -795,7 +795,7 @@ Value *ScalarExprEmitter::EmitScalarConv
 assert(SrcType->isIntegerType() && "Not ptr->ptr or int->ptr conversion?");
 // First, convert to the correct width so that we control the kind of
 // extension.
-llvm::Type *MiddleTy = CGF.CGM.getDataLayout().getIntPtrType(DstPT);
+llvm::Type *MiddleTy = CGF.IntPtrTy;
 bool InputSigned = SrcType->isSignedIntegerOrEnumerationType();
 llvm::Value* IntResult =
 Builder.CreateIntCast(Src, MiddleTy, InputSigned, "conv");
@@ -1510,13 +1510,12 @@ Value *ScalarExprEmitter::VisitCastExpr(
 
 // First, convert to the correct width so that we control the kind of
 // extension.
-auto DestLLVMTy = ConvertType(DestTy);
-llvm::Type *MiddleTy = CGF.CGM.getDataLayout().getIntPtrType(DestLLVMTy);
+llvm::Type *MiddleTy = CGF.IntPtrTy;
 bool InputSigned = E->getType()->isSignedIntegerOrEnumerationType();
 llvm::Value* IntResult =
   Builder.CreateIntCast(Src, MiddleTy, InputSigned, "conv");
 
-return Builder.CreateIntToPtr(IntResult, DestLLVMTy);
+return Builder.CreateIntToPtr(IntResult, ConvertType(DestTy));
   }
   case CK_PointerToIntegral:
 assert(!DestTy->isBooleanType() && "bool should use PointerToBool");
@@ -2427,7 +2426,6 @@ static Value *emitPointerArithmetic(

Re: [PATCH] D23618: [LibTooling] Allow compilation database to explicitly specify compilation database file and source root

2016-08-18 Thread Alexander Kornienko via cfe-commits
alexfh requested changes to this revision.
alexfh added a comment.
This revision now requires changes to proceed.

As discussed offline, since the functionality being added in this patch is only 
useful for tests, the related simplification of tests seems not worth the added 
complexity.


https://reviews.llvm.org/D23618



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


r279122 - Fix json compilation database syntax on non-Windows.

2016-08-18 Thread Zachary Turner via cfe-commits
Author: zturner
Date: Thu Aug 18 14:42:00 2016
New Revision: 279122

URL: http://llvm.org/viewvc/llvm-project?rev=279122&view=rev
Log:
Fix json compilation database syntax on non-Windows.

Modified:
cfe/trunk/lib/Tooling/JSONCompilationDatabase.cpp

Modified: cfe/trunk/lib/Tooling/JSONCompilationDatabase.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/JSONCompilationDatabase.cpp?rev=279122&r1=279121&r2=279122&view=diff
==
--- cfe/trunk/lib/Tooling/JSONCompilationDatabase.cpp (original)
+++ cfe/trunk/lib/Tooling/JSONCompilationDatabase.cpp Thu Aug 18 14:42:00 2016
@@ -117,16 +117,14 @@ class CommandLineArgumentParser {
 std::vector unescapeCommandLine(JSONCommandLineSyntax Syntax,
  StringRef EscapedCommandLine) {
   if (Syntax == JSONCommandLineSyntax::AutoDetect) {
+Syntax = JSONCommandLineSyntax::Gnu;
 llvm::Triple Triple(llvm::sys::getProcessTriple());
 if (Triple.getOS() == llvm::Triple::OSType::Win32) {
   // Assume Windows command line parsing on Win32 unless the triple
-  // explicitly
-  // tells us otherwise.
+  // explicitly tells us otherwise.
   if (!Triple.hasEnvironment() ||
   Triple.getEnvironment() == llvm::Triple::EnvironmentType::MSVC)
 Syntax = JSONCommandLineSyntax::Windows;
-  else
-Syntax = JSONCommandLineSyntax::Gnu;
 }
   }
 


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


Re: [PATCH] D23361: [OpenCL] AMDGCN: Fix size_t type

2016-08-18 Thread Yaxun Liu via cfe-commits
This revision was automatically updated to reflect the committed changes.
yaxunl marked an inline comment as done.
Closed by commit rL279121: [OpenCL] AMDGCN: Fix size_t type (authored by 
yaxunl).

Changed prior to commit:
  https://reviews.llvm.org/D23361?vs=68360&id=68594#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D23361

Files:
  cfe/trunk/include/clang/Basic/TargetInfo.h
  cfe/trunk/lib/Basic/TargetInfo.cpp
  cfe/trunk/lib/Basic/Targets.cpp
  cfe/trunk/lib/CodeGen/CGExprScalar.cpp
  cfe/trunk/lib/CodeGen/CodeGenModule.cpp
  cfe/trunk/lib/CodeGen/CodeGenTypeCache.h
  cfe/trunk/test/CodeGenOpenCL/size_t.cl

Index: cfe/trunk/include/clang/Basic/TargetInfo.h
===
--- cfe/trunk/include/clang/Basic/TargetInfo.h
+++ cfe/trunk/include/clang/Basic/TargetInfo.h
@@ -294,6 +294,11 @@
 return AddrSpace == 0 ? PointerAlign : getPointerAlignV(AddrSpace);
   }
 
+  /// \brief Return the maximum width of pointers on this target.
+  virtual uint64_t getMaxPointerWidth() const {
+return PointerWidth;
+  }
+
   /// \brief Return the size of '_Bool' and C++ 'bool' for this target, in bits.
   unsigned getBoolWidth() const { return BoolWidth; }
 
Index: cfe/trunk/test/CodeGenOpenCL/size_t.cl
===
--- cfe/trunk/test/CodeGenOpenCL/size_t.cl
+++ cfe/trunk/test/CodeGenOpenCL/size_t.cl
@@ -0,0 +1,110 @@
+// RUN: %clang_cc1 %s -cl-std=CL2.0 -finclude-default-header -emit-llvm -O0 -triple spir-unknown-unknown -o - | FileCheck --check-prefix=SZ32 %s
+// RUN: %clang_cc1 %s -cl-std=CL2.0 -finclude-default-header -emit-llvm -O0 -triple spir64-unknown-unknown -o - | FileCheck --check-prefix=SZ64 --check-prefix=SZ64ONLY %s
+// RUN: %clang_cc1 %s -cl-std=CL2.0 -finclude-default-header -emit-llvm -O0 -triple amdgcn-- -o - | FileCheck --check-prefix=SZ64 --check-prefix=AMDONLY %s
+
+//SZ32: define{{.*}} i32 @test_ptrtoint_private(i8* %x)
+//SZ32: ptrtoint i8* %{{.*}} to i32
+//SZ64: define{{.*}} i64 @test_ptrtoint_private(i8* %x)
+//SZ64: ptrtoint i8* %{{.*}} to i64
+size_t test_ptrtoint_private(private char* x) {
+  return (size_t)x;
+}
+
+//SZ32: define{{.*}} i32 @test_ptrtoint_global(i8 addrspace(1)* %x)
+//SZ32: ptrtoint i8 addrspace(1)* %{{.*}} to i32
+//SZ64: define{{.*}} i64 @test_ptrtoint_global(i8 addrspace(1)* %x)
+//SZ64: ptrtoint i8 addrspace(1)* %{{.*}} to i64
+intptr_t test_ptrtoint_global(global char* x) {
+  return (intptr_t)x;
+}
+
+//SZ32: define{{.*}} i32 @test_ptrtoint_constant(i8 addrspace(2)* %x)
+//SZ32: ptrtoint i8 addrspace(2)* %{{.*}} to i32
+//SZ64: define{{.*}} i64 @test_ptrtoint_constant(i8 addrspace(2)* %x)
+//SZ64: ptrtoint i8 addrspace(2)* %{{.*}} to i64
+uintptr_t test_ptrtoint_constant(constant char* x) {
+  return (uintptr_t)x;
+}
+
+//SZ32: define{{.*}} i32 @test_ptrtoint_local(i8 addrspace(3)* %x)
+//SZ32: ptrtoint i8 addrspace(3)* %{{.*}} to i32
+//SZ64: define{{.*}} i64 @test_ptrtoint_local(i8 addrspace(3)* %x)
+//SZ64: ptrtoint i8 addrspace(3)* %{{.*}} to i64
+size_t test_ptrtoint_local(local char* x) {
+  return (size_t)x;
+}
+
+//SZ32: define{{.*}} i32 @test_ptrtoint_generic(i8 addrspace(4)* %x)
+//SZ32: ptrtoint i8 addrspace(4)* %{{.*}} to i32
+//SZ64: define{{.*}} i64 @test_ptrtoint_generic(i8 addrspace(4)* %x)
+//SZ64: ptrtoint i8 addrspace(4)* %{{.*}} to i64
+size_t test_ptrtoint_generic(generic char* x) {
+  return (size_t)x;
+}
+
+//SZ32: define{{.*}} i8* @test_inttoptr_private(i32 %x)
+//SZ32: inttoptr i32 %{{.*}} to i8*
+//SZ64: define{{.*}} i8* @test_inttoptr_private(i64 %x)
+//AMDONLY: trunc i64 %{{.*}} to i32
+//AMDONLY: inttoptr i32 %{{.*}} to i8*
+//SZ64ONLY: inttoptr i64 %{{.*}} to i8*
+private char* test_inttoptr_private(size_t x) {
+  return (private char*)x;
+}
+
+//SZ32: define{{.*}} i8 addrspace(1)* @test_inttoptr_global(i32 %x)
+//SZ32: inttoptr i32 %{{.*}} to i8 addrspace(1)*
+//SZ64: define{{.*}} i8 addrspace(1)* @test_inttoptr_global(i64 %x)
+//SZ64: inttoptr i64 %{{.*}} to i8 addrspace(1)*
+global char* test_inttoptr_global(size_t x) {
+  return (global char*)x;
+}
+
+//SZ32: define{{.*}} i8 addrspace(3)* @test_add_local(i8 addrspace(3)* %x, i32 %y)
+//SZ32: getelementptr inbounds i8, i8 addrspace(3)* %{{.*}}, i32
+//SZ64: define{{.*}} i8 addrspace(3)* @test_add_local(i8 addrspace(3)* %x, i64 %y)
+//AMDONLY: trunc i64 %{{.*}} to i32
+//AMDONLY: getelementptr inbounds i8, i8 addrspace(3)* %{{.*}}, i32
+//SZ64ONLY: getelementptr inbounds i8, i8 addrspace(3)* %{{.*}}, i64
+local char* test_add_local(local char* x, ptrdiff_t y) {
+  return x + y;
+}
+
+//SZ32: define{{.*}} i8 addrspace(1)* @test_add_global(i8 addrspace(1)* %x, i32 %y)
+//SZ32: getelementptr inbounds i8, i8 addrspace(1)* %{{.*}}, i32
+//SZ64: define{{.*}} i8 addrspace(1)* @test_add_global(i8 addrspace(1)* %x, i64 %y)
+//SZ64: getelementptr inbounds i8, i8 addrspace(1)* %{{.*}}, i64
+global char* test_add_global(global char* x, ptrdiff_t y) {
+  return x + y;
+}
+
+//SZ32

r279121 - [OpenCL] AMDGCN: Fix size_t type

2016-08-18 Thread Yaxun Liu via cfe-commits
Author: yaxunl
Date: Thu Aug 18 14:34:04 2016
New Revision: 279121

URL: http://llvm.org/viewvc/llvm-project?rev=279121&view=rev
Log:
[OpenCL] AMDGCN: Fix size_t type

Pointers of certain GPUs in AMDGCN target in private address space is 32 bit 
but pointers in other address spaces are 64 bit. size_t type should be defined 
as 64 bit for these GPUs so that it could hold pointers in all address spaces. 
Also fixed issues in pointer arithmetic codegen by using pointer specific 
intptr type.

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

Added:
cfe/trunk/test/CodeGenOpenCL/size_t.cl
Modified:
cfe/trunk/include/clang/Basic/TargetInfo.h
cfe/trunk/lib/Basic/TargetInfo.cpp
cfe/trunk/lib/Basic/Targets.cpp
cfe/trunk/lib/CodeGen/CGExprScalar.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/lib/CodeGen/CodeGenTypeCache.h

Modified: cfe/trunk/include/clang/Basic/TargetInfo.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TargetInfo.h?rev=279121&r1=279120&r2=279121&view=diff
==
--- cfe/trunk/include/clang/Basic/TargetInfo.h (original)
+++ cfe/trunk/include/clang/Basic/TargetInfo.h Thu Aug 18 14:34:04 2016
@@ -294,6 +294,11 @@ public:
 return AddrSpace == 0 ? PointerAlign : getPointerAlignV(AddrSpace);
   }
 
+  /// \brief Return the maximum width of pointers on this target.
+  virtual uint64_t getMaxPointerWidth() const {
+return PointerWidth;
+  }
+
   /// \brief Return the size of '_Bool' and C++ 'bool' for this target, in 
bits.
   unsigned getBoolWidth() const { return BoolWidth; }
 

Modified: cfe/trunk/lib/Basic/TargetInfo.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/TargetInfo.cpp?rev=279121&r1=279120&r2=279121&view=diff
==
--- cfe/trunk/lib/Basic/TargetInfo.cpp (original)
+++ cfe/trunk/lib/Basic/TargetInfo.cpp Thu Aug 18 14:34:04 2016
@@ -306,8 +306,9 @@ void TargetInfo::adjust(const LangOption
 }
 LongDoubleWidth = LongDoubleAlign = 128;
 
-assert(PointerWidth == 32 || PointerWidth == 64);
-bool Is32BitArch = PointerWidth == 32;
+unsigned MaxPointerWidth = getMaxPointerWidth();
+assert(MaxPointerWidth == 32 || MaxPointerWidth == 64);
+bool Is32BitArch = MaxPointerWidth == 32;
 SizeType = Is32BitArch ? UnsignedInt : UnsignedLong;
 PtrDiffType = Is32BitArch ? SignedInt : SignedLong;
 IntPtrType = Is32BitArch ? SignedInt : SignedLong;

Modified: cfe/trunk/lib/Basic/Targets.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=279121&r1=279120&r2=279121&view=diff
==
--- cfe/trunk/lib/Basic/Targets.cpp (original)
+++ cfe/trunk/lib/Basic/Targets.cpp Thu Aug 18 14:34:04 2016
@@ -2004,6 +2004,10 @@ public:
 }
   }
 
+  uint64_t getMaxPointerWidth() const override {
+return getTriple().getArch() == llvm::Triple::amdgcn ? 64 : 32;
+  }
+
   const char * getClobbers() const override {
 return "";
   }

Modified: cfe/trunk/lib/CodeGen/CGExprScalar.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExprScalar.cpp?rev=279121&r1=279120&r2=279121&view=diff
==
--- cfe/trunk/lib/CodeGen/CGExprScalar.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExprScalar.cpp Thu Aug 18 14:34:04 2016
@@ -787,7 +787,7 @@ Value *ScalarExprEmitter::EmitScalarConv
   // Handle pointer conversions next: pointers can only be converted to/from
   // other pointers and integers. Check for pointer types in terms of LLVM, as
   // some native types (like Obj-C id) may map to a pointer type.
-  if (isa(DstTy)) {
+  if (auto DstPT = dyn_cast(DstTy)) {
 // The source value may be an integer, or a pointer.
 if (isa(SrcTy))
   return Builder.CreateBitCast(Src, DstTy, "conv");
@@ -795,7 +795,7 @@ Value *ScalarExprEmitter::EmitScalarConv
 assert(SrcType->isIntegerType() && "Not ptr->ptr or int->ptr conversion?");
 // First, convert to the correct width so that we control the kind of
 // extension.
-llvm::Type *MiddleTy = CGF.IntPtrTy;
+llvm::Type *MiddleTy = CGF.CGM.getDataLayout().getIntPtrType(DstPT);
 bool InputSigned = SrcType->isSignedIntegerOrEnumerationType();
 llvm::Value* IntResult =
 Builder.CreateIntCast(Src, MiddleTy, InputSigned, "conv");
@@ -1510,12 +1510,13 @@ Value *ScalarExprEmitter::VisitCastExpr(
 
 // First, convert to the correct width so that we control the kind of
 // extension.
-llvm::Type *MiddleTy = CGF.IntPtrTy;
+auto DestLLVMTy = ConvertType(DestTy);
+llvm::Type *MiddleTy = CGF.CGM.getDataLayout().getIntPtrType(DestLLVMTy);
 bool InputSigned = E->getType()->isSignedIntegerOrEnumerationType();
 llvm::Value* IntResult =
   Builder.CreateIntCast(Src, MiddleTy, InputSigne

Re: [PATCH] D23628: Fix unittests after windows command line parsing

2016-08-18 Thread Zachary Turner via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL279120: Resubmit "[Tooling] Parse compilation database 
command lines on Windows." (authored by zturner).

Changed prior to commit:
  https://reviews.llvm.org/D23628?vs=68426&id=68593#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D23628

Files:
  cfe/trunk/include/clang/Tooling/JSONCompilationDatabase.h
  cfe/trunk/lib/Tooling/JSONCompilationDatabase.cpp
  cfe/trunk/unittests/Tooling/CompilationDatabaseTest.cpp

Index: cfe/trunk/include/clang/Tooling/JSONCompilationDatabase.h
===
--- cfe/trunk/include/clang/Tooling/JSONCompilationDatabase.h
+++ cfe/trunk/include/clang/Tooling/JSONCompilationDatabase.h
@@ -55,20 +55,23 @@
 ///
 /// JSON compilation databases can for example be generated in CMake projects
 /// by setting the flag -DCMAKE_EXPORT_COMPILE_COMMANDS.
+enum class JSONCommandLineSyntax { Windows, Gnu, AutoDetect };
 class JSONCompilationDatabase : public CompilationDatabase {
 public:
   /// \brief Loads a JSON compilation database from the specified file.
   ///
   /// Returns NULL and sets ErrorMessage if the database could not be
   /// loaded from the given file.
   static std::unique_ptr
-  loadFromFile(StringRef FilePath, std::string &ErrorMessage);
+  loadFromFile(StringRef FilePath, std::string &ErrorMessage,
+   JSONCommandLineSyntax Syntax);
 
   /// \brief Loads a JSON compilation database from a data buffer.
   ///
   /// Returns NULL and sets ErrorMessage if the database could not be loaded.
   static std::unique_ptr
-  loadFromBuffer(StringRef DatabaseString, std::string &ErrorMessage);
+  loadFromBuffer(StringRef DatabaseString, std::string &ErrorMessage,
+ JSONCommandLineSyntax Syntax);
 
   /// \brief Returns all compile comamnds in which the specified file was
   /// compiled.
@@ -89,8 +92,9 @@
 
 private:
   /// \brief Constructs a JSON compilation database on a memory buffer.
-  JSONCompilationDatabase(std::unique_ptr Database)
-  : Database(std::move(Database)),
+  JSONCompilationDatabase(std::unique_ptr Database,
+  JSONCommandLineSyntax Syntax)
+  : Database(std::move(Database)), Syntax(Syntax),
 YAMLStream(this->Database->getBuffer(), SM) {}
 
   /// \brief Parses the database file and creates the index.
@@ -123,6 +127,7 @@
   FileMatchTrie MatchTrie;
 
   std::unique_ptr Database;
+  JSONCommandLineSyntax Syntax;
   llvm::SourceMgr SM;
   llvm::yaml::Stream YAMLStream;
 };
Index: cfe/trunk/lib/Tooling/JSONCompilationDatabase.cpp
===
--- cfe/trunk/lib/Tooling/JSONCompilationDatabase.cpp
+++ cfe/trunk/lib/Tooling/JSONCompilationDatabase.cpp
@@ -16,7 +16,10 @@
 #include "clang/Tooling/CompilationDatabasePluginRegistry.h"
 #include "clang/Tooling/Tooling.h"
 #include "llvm/ADT/SmallString.h"
+#include "llvm/Support/Allocator.h"
+#include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Path.h"
+#include "llvm/Support/StringSaver.h"
 #include 
 
 namespace clang {
@@ -111,8 +114,31 @@
   std::vector CommandLine;
 };
 
-std::vector unescapeCommandLine(
-StringRef EscapedCommandLine) {
+std::vector unescapeCommandLine(JSONCommandLineSyntax Syntax,
+ StringRef EscapedCommandLine) {
+  if (Syntax == JSONCommandLineSyntax::AutoDetect) {
+llvm::Triple Triple(llvm::sys::getProcessTriple());
+if (Triple.getOS() == llvm::Triple::OSType::Win32) {
+  // Assume Windows command line parsing on Win32 unless the triple
+  // explicitly
+  // tells us otherwise.
+  if (!Triple.hasEnvironment() ||
+  Triple.getEnvironment() == llvm::Triple::EnvironmentType::MSVC)
+Syntax = JSONCommandLineSyntax::Windows;
+  else
+Syntax = JSONCommandLineSyntax::Gnu;
+}
+  }
+
+  if (Syntax == JSONCommandLineSyntax::Windows) {
+llvm::BumpPtrAllocator Alloc;
+llvm::StringSaver Saver(Alloc);
+llvm::SmallVector T;
+llvm::cl::TokenizeWindowsCommandLine(EscapedCommandLine, Saver, T);
+std::vector Result(T.begin(), T.end());
+return Result;
+  }
+  assert(Syntax == JSONCommandLineSyntax::Gnu);
   CommandLineArgumentParser parser(EscapedCommandLine);
   return parser.parse();
 }
@@ -123,7 +149,8 @@
 SmallString<1024> JSONDatabasePath(Directory);
 llvm::sys::path::append(JSONDatabasePath, "compile_commands.json");
 std::unique_ptr Database(
-JSONCompilationDatabase::loadFromFile(JSONDatabasePath, ErrorMessage));
+JSONCompilationDatabase::loadFromFile(
+JSONDatabasePath, ErrorMessage, JSONCommandLineSyntax::AutoDetect));
 if (!Database)
   return nullptr;
 return Database;
@@ -143,27 +170,29 @@
 
 std::unique_ptr
 JSONCompilationDatabase::loadFromFile(StringRef FilePath,
-  std::string &ErrorMessage) {
+

r279120 - Resubmit "[Tooling] Parse compilation database command lines on Windows."

2016-08-18 Thread Zachary Turner via cfe-commits
Author: zturner
Date: Thu Aug 18 14:31:48 2016
New Revision: 279120

URL: http://llvm.org/viewvc/llvm-project?rev=279120&view=rev
Log:
Resubmit "[Tooling] Parse compilation database command lines on Windows."

This patch introduced the ability to decide at runtime whether to parse
JSON compilation database command lines using Gnu syntax or Windows
syntax.  However, there were many existing unit tests written that
hardcoded Gnu-specific paths.  These tests were now failing because
the auto-detection logic was choosing to parse them using Windows
rules.

This resubmission of the patch fixes this by introducing an enum
which defines the syntax mode, which defaults to auto-detect, but
for which the unit tests force Gnu style parsing.

Reviewed By: alexfh
Differential Revision: https://reviews.llvm.org/D23628

Modified:
cfe/trunk/include/clang/Tooling/JSONCompilationDatabase.h
cfe/trunk/lib/Tooling/JSONCompilationDatabase.cpp
cfe/trunk/unittests/Tooling/CompilationDatabaseTest.cpp

Modified: cfe/trunk/include/clang/Tooling/JSONCompilationDatabase.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Tooling/JSONCompilationDatabase.h?rev=279120&r1=279119&r2=279120&view=diff
==
--- cfe/trunk/include/clang/Tooling/JSONCompilationDatabase.h (original)
+++ cfe/trunk/include/clang/Tooling/JSONCompilationDatabase.h Thu Aug 18 
14:31:48 2016
@@ -55,6 +55,7 @@ namespace tooling {
 ///
 /// JSON compilation databases can for example be generated in CMake projects
 /// by setting the flag -DCMAKE_EXPORT_COMPILE_COMMANDS.
+enum class JSONCommandLineSyntax { Windows, Gnu, AutoDetect };
 class JSONCompilationDatabase : public CompilationDatabase {
 public:
   /// \brief Loads a JSON compilation database from the specified file.
@@ -62,13 +63,15 @@ public:
   /// Returns NULL and sets ErrorMessage if the database could not be
   /// loaded from the given file.
   static std::unique_ptr
-  loadFromFile(StringRef FilePath, std::string &ErrorMessage);
+  loadFromFile(StringRef FilePath, std::string &ErrorMessage,
+   JSONCommandLineSyntax Syntax);
 
   /// \brief Loads a JSON compilation database from a data buffer.
   ///
   /// Returns NULL and sets ErrorMessage if the database could not be loaded.
   static std::unique_ptr
-  loadFromBuffer(StringRef DatabaseString, std::string &ErrorMessage);
+  loadFromBuffer(StringRef DatabaseString, std::string &ErrorMessage,
+ JSONCommandLineSyntax Syntax);
 
   /// \brief Returns all compile comamnds in which the specified file was
   /// compiled.
@@ -89,8 +92,9 @@ public:
 
 private:
   /// \brief Constructs a JSON compilation database on a memory buffer.
-  JSONCompilationDatabase(std::unique_ptr Database)
-  : Database(std::move(Database)),
+  JSONCompilationDatabase(std::unique_ptr Database,
+  JSONCommandLineSyntax Syntax)
+  : Database(std::move(Database)), Syntax(Syntax),
 YAMLStream(this->Database->getBuffer(), SM) {}
 
   /// \brief Parses the database file and creates the index.
@@ -123,6 +127,7 @@ private:
   FileMatchTrie MatchTrie;
 
   std::unique_ptr Database;
+  JSONCommandLineSyntax Syntax;
   llvm::SourceMgr SM;
   llvm::yaml::Stream YAMLStream;
 };

Modified: cfe/trunk/lib/Tooling/JSONCompilationDatabase.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Tooling/JSONCompilationDatabase.cpp?rev=279120&r1=279119&r2=279120&view=diff
==
--- cfe/trunk/lib/Tooling/JSONCompilationDatabase.cpp (original)
+++ cfe/trunk/lib/Tooling/JSONCompilationDatabase.cpp Thu Aug 18 14:31:48 2016
@@ -16,7 +16,10 @@
 #include "clang/Tooling/CompilationDatabasePluginRegistry.h"
 #include "clang/Tooling/Tooling.h"
 #include "llvm/ADT/SmallString.h"
+#include "llvm/Support/Allocator.h"
+#include "llvm/Support/CommandLine.h"
 #include "llvm/Support/Path.h"
+#include "llvm/Support/StringSaver.h"
 #include 
 
 namespace clang {
@@ -111,8 +114,31 @@ class CommandLineArgumentParser {
   std::vector CommandLine;
 };
 
-std::vector unescapeCommandLine(
-StringRef EscapedCommandLine) {
+std::vector unescapeCommandLine(JSONCommandLineSyntax Syntax,
+ StringRef EscapedCommandLine) {
+  if (Syntax == JSONCommandLineSyntax::AutoDetect) {
+llvm::Triple Triple(llvm::sys::getProcessTriple());
+if (Triple.getOS() == llvm::Triple::OSType::Win32) {
+  // Assume Windows command line parsing on Win32 unless the triple
+  // explicitly
+  // tells us otherwise.
+  if (!Triple.hasEnvironment() ||
+  Triple.getEnvironment() == llvm::Triple::EnvironmentType::MSVC)
+Syntax = JSONCommandLineSyntax::Windows;
+  else
+Syntax = JSONCommandLineSyntax::Gnu;
+}
+  }
+
+  if (Syntax == JSONCommandLineSyntax::Windows) {
+llvm::BumpPtrAllocator Alloc;
+llvm::StringSav

Re: [PATCH] D22910: Add support for CXXOperatorCallExpr in Expr::HasSideEffects

2016-08-18 Thread Richard Smith via cfe-commits
rsmith added inline comments.


Comment at: lib/AST/Expr.cpp:2865-2867
@@ +2864,5 @@
+  case CXXOperatorCallExprClass: {
+// If it is an operator call expr it can have side effects when the
+// underlaying operator is of assignment kind.
+// Othrwise fall through the rest of cases.
+OverloadedOperatorKind Op = cast(this)->getOperator();

Well, this is true for any overloaded operator. Perhaps something like

"When looking for potential side-effects, we assume that an overloaded 
assignment operator is intended to have a side-effect and other overloaded 
operators are not."


Comment at: lib/AST/Expr.cpp:2869-2871
@@ +2868,5 @@
+OverloadedOperatorKind Op = cast(this)->getOperator();
+if (CXXOperatorCallExpr::isAssignmentOp(Op)) {
+  return true;
+}
+  }

I think this should go after the check for a pure callee -- if for whatever 
reason someone has defined an `operator=` with `__attribute__((pure))`, we 
shouldn't claim it has a side-effect.



https://reviews.llvm.org/D22910



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


r279116 - [MS] Silence -Wextern-init on const selectany variables

2016-08-18 Thread Reid Kleckner via cfe-commits
Author: rnk
Date: Thu Aug 18 13:45:07 2016
New Revision: 279116

URL: http://llvm.org/viewvc/llvm-project?rev=279116&view=rev
Log:
[MS] Silence -Wextern-init on const selectany variables

In C, 'extern' is typically used to avoid tentative definitions when
declaring variables in headers, but adding an intializer makes it a
defintion. This is somewhat confusing, so GCC and Clang both warn on it.
In C++, 'extern' is often used to give implictly static 'const'
variables external linkage, so don't warn in that case. If selectany is
present, this might be header code intended for C and C++ inclusion, so
apply the C++ rules.

Added:
cfe/trunk/test/Sema/attr-selectany.c
Modified:
cfe/trunk/lib/Sema/SemaDecl.cpp

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=279116&r1=279115&r2=279116&view=diff
==
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Thu Aug 18 13:45:07 2016
@@ -9938,10 +9938,17 @@ void Sema::AddInitializerToDecl(Decl *Re
   VDecl->setInvalidDecl();
 }
   } else if (VDecl->isFileVarDecl()) {
+// In C, extern is typically used to avoid tentative definitions when
+// declaring variables in headers, but adding an intializer makes it a
+// defintion. This is somewhat confusing, so GCC and Clang both warn on it.
+// In C++, extern is often used to give implictly static const variables
+// external linkage, so don't warn in that case. If selectany is present,
+// this might be header code intended for C and C++ inclusion, so apply the
+// C++ rules.
 if (VDecl->getStorageClass() == SC_Extern &&
-(!getLangOpts().CPlusPlus ||
- !(Context.getBaseElementType(VDecl->getType()).isConstQualified() ||
-   VDecl->isExternC())) &&
+((!getLangOpts().CPlusPlus && !VDecl->hasAttr()) ||
+ !Context.getBaseElementType(VDecl->getType()).isConstQualified()) &&
+!(getLangOpts().CPlusPlus && VDecl->isExternC()) &&
 !isTemplateInstantiation(VDecl->getTemplateSpecializationKind()))
   Diag(VDecl->getLocation(), diag::warn_extern_init);
 

Added: cfe/trunk/test/Sema/attr-selectany.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/attr-selectany.c?rev=279116&view=auto
==
--- cfe/trunk/test/Sema/attr-selectany.c (added)
+++ cfe/trunk/test/Sema/attr-selectany.c Thu Aug 18 13:45:07 2016
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -fms-compatibility -fms-extensions -verify %s
+
+extern __declspec(selectany) const int x1 = 1; // no warning, const means we 
need extern in C++
+
+// Should we really warn on this?
+extern __declspec(selectany) int x2 = 1; // expected-warning {{'extern' 
variable has an initializer}}
+
+__declspec(selectany) void foo() { } // expected-error{{'selectany' can only 
be applied to data items with external linkage}}


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


[clang-tools-extra] r279115 - [clang-tidy docs] Move option descriptions to the Options section

2016-08-18 Thread Alexander Kornienko via cfe-commits
Author: alexfh
Date: Thu Aug 18 13:43:47 2016
New Revision: 279115

URL: http://llvm.org/viewvc/llvm-project?rev=279115&view=rev
Log:
[clang-tidy docs] Move option descriptions to the Options section

+ random fixes

Modified:
clang-tools-extra/trunk/docs/clang-tidy/checks/misc-assert-side-effect.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/misc-dangling-handle.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-use-emplace.rst

Modified: 
clang-tools-extra/trunk/docs/clang-tidy/checks/misc-assert-side-effect.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/misc-assert-side-effect.rst?rev=279115&r1=279114&r2=279115&view=diff
==
--- clang-tools-extra/trunk/docs/clang-tidy/checks/misc-assert-side-effect.rst 
(original)
+++ clang-tools-extra/trunk/docs/clang-tidy/checks/misc-assert-side-effect.rst 
Thu Aug 18 13:43:47 2016
@@ -9,7 +9,8 @@ The condition of ``assert()`` is evaluat
 condition with side effect can cause different behavior in debug / release
 builds.
 
-There are two options:
+Options
+---
 
 .. option:: AssertMacros
 

Modified: 
clang-tools-extra/trunk/docs/clang-tidy/checks/misc-dangling-handle.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/misc-dangling-handle.rst?rev=279115&r1=279114&r2=279115&view=diff
==
--- clang-tools-extra/trunk/docs/clang-tidy/checks/misc-dangling-handle.rst 
(original)
+++ clang-tools-extra/trunk/docs/clang-tidy/checks/misc-dangling-handle.rst Thu 
Aug 18 13:43:47 2016
@@ -3,15 +3,11 @@
 misc-dangling-handle
 
 
-Detect dangling references in value handlers like
+Detect dangling references in value handles like
 ``std::experimental::string_view``.
-These dangling references can come from constructing handles from temporary
+These dangling references can be a result of constructing handles from 
temporary
 values, where the temporary is destroyed soon after the handle is created.
 
-By default only ``std::experimental::basic_string_view`` is considered.
-This list can be modified by passing a `;` separated list of class names using
-the HandleClasses option.
-
 Examples:
 
 .. code-block:: c++
@@ -32,3 +28,11 @@ Examples:
 char Array[10]{};
 return Array;
   }
+
+Options
+---
+
+.. option:: HandleClasses
+
+   A semicolon-separated list of class names that should be treated as handles.
+   By default only ``std::experimental::basic_string_view`` is considered.

Modified: 
clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-use-emplace.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-use-emplace.rst?rev=279115&r1=279114&r2=279115&view=diff
==
--- clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-use-emplace.rst 
(original)
+++ clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-use-emplace.rst 
Thu Aug 18 13:43:47 2016
@@ -13,12 +13,11 @@ because replacing ``insert`` with ``empl
 `speed regression 
`_,
 but it might get support with some addition flag in the future.
 
 By default only ``std::vector``, ``std::deque``, ``std::list`` are considered.
-This list can be modified by passing a semicolon-separated list of class names
-using the `ContainersWithPushBack` option.
+This list can be modified using the :option:`ContainersWithPushBack` option.
 
 Before:
 
-.. code:: c++
+.. code-block:: c++
 
 std::vector v;
 v.push_back(MyClass(21, 37));
@@ -30,7 +29,7 @@ Before:
 
 After:
 
-.. code:: c++
+.. code-block:: c++
 
 std::vector v;
 v.emplace_back(21, 37);
@@ -45,14 +44,14 @@ inside a container.
 
 Before:
 
-.. code:: c++
+.. code-block:: c++
 
 std::vector > v;
 v.push_back("abc");
 
 After:
 
-.. code:: c++
+.. code-block:: c++
 
 std::vector > v;
 v.emplace_back("abc");
@@ -62,7 +61,7 @@ In some cases the transformation would b
 wouldn't be exception safe.
 In this case the calls of ``push_back`` won't be replaced.
 
-.. code:: c++
+.. code-block:: c++
 
 std::vector> v;
 v.push_back(std::unique_ptr(new int(0)));
@@ -70,16 +69,15 @@ In this case the calls of ``push_back``
 v.push_back(std::unique_ptr(ptr));
 
 This is because replacing it with ``emplace_back`` could cause a leak of this
-pointer if ``emplace_back`` would throw exception before emplacement
-(e.g. not enough memory to add new element).
+pointer if ``emplace_back`` would throw exception before emplacement (e.g. not
+enough memory to add new element).
 
-For more info read item 42 - "Consider emplacement instead of insertion."
-of Scott Meyers Effective Modern C++.
+For more info read item 42 - "Consider emplacemen

r279114 - Removed use of 'emplace' on std::map, since not all buildbot slaves support it

2016-08-18 Thread Cameron Desrochers via cfe-commits
Author: cameron314
Date: Thu Aug 18 13:41:41 2016
New Revision: 279114

URL: http://llvm.org/viewvc/llvm-project?rev=279114&view=rev
Log:
Removed use of 'emplace' on std::map, since not all buildbot slaves support it

Modified:
cfe/trunk/unittests/libclang/LibclangTest.cpp

Modified: cfe/trunk/unittests/libclang/LibclangTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/libclang/LibclangTest.cpp?rev=279114&r1=279113&r2=279114&view=diff
==
--- cfe/trunk/unittests/libclang/LibclangTest.cpp (original)
+++ cfe/trunk/unittests/libclang/LibclangTest.cpp Thu Aug 18 13:41:41 2016
@@ -397,9 +397,9 @@ public:
   llvm::sys::path::append(Path, Filename);
   Filename = Path.str();
 }
-auto it = UnsavedFileContents.emplace(
+auto it = UnsavedFileContents.insert(std::make_pair(
 fixed_addr_string(new std::string(Filename)),
-fixed_addr_string(new std::string(Contents)));
+fixed_addr_string(new std::string(Contents;
 UnsavedFiles.push_back({
 it.first->first->c_str(),   // filename
 it.first->second->c_str(),  // contents


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


[PATCH] D23685: [libcxx] [test] Include the iterator header for back_inserter.

2016-08-18 Thread Stephan T. Lavavej via cfe-commits
STL_MSFT created this revision.
STL_MSFT added reviewers: EricWF, mclow.lists.
STL_MSFT added a subscriber: cfe-commits.

Code was recently added to this test that uses std::back_inserter. Therefore, 
the header  must be included. (MSVC's STL demands this, as we don't 
otherwise drag in back_inserter.)

https://reviews.llvm.org/D23685

Files:
  test/std/containers/associative/map/map.cons/copy_assign.pass.cpp

Index: test/std/containers/associative/map/map.cons/copy_assign.pass.cpp
===
--- test/std/containers/associative/map/map.cons/copy_assign.pass.cpp
+++ test/std/containers/associative/map/map.cons/copy_assign.pass.cpp
@@ -17,6 +17,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 


Index: test/std/containers/associative/map/map.cons/copy_assign.pass.cpp
===
--- test/std/containers/associative/map/map.cons/copy_assign.pass.cpp
+++ test/std/containers/associative/map/map.cons/copy_assign.pass.cpp
@@ -17,6 +17,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D23684: Resolve ambiguity in a declaration if global nested name specifier is used

2016-08-18 Thread Serge Pavlov via cfe-commits
sepavloff created this revision.
sepavloff added reviewers: rsmith, doug.gregor.
sepavloff added a subscriber: cfe-commits.

If a declaration references a function from global namespace by its
qualified name and if that function return type is a class or enum, there
is possible ambiguity. The declaration:
```
friend A::B::C();
```
may be considered as a declaration of a function `::C()` that returns
`A::B`, or a function `::B::C()` that returns `A`.

With this change when the compiler sees 'A::B' while parsing decl-spec, it
tries to find `B` within 'A'. If it finds, 'A::B' is treated as a part of
qualified name. If it doesn't and the current declaration declares a
function, '::B' is assumed to be a part of declarator. For non-function
declarations 'B' can be searched for in the global namespace to improve
diagnostics.

This changes fixes https://llvm.org/bugs/show_bug.cgi?id=28422.

https://reviews.llvm.org/D23684

Files:
  include/clang/Parse/Parser.h
  include/clang/Sema/Sema.h
  lib/Parse/ParseDecl.cpp
  lib/Parse/ParseDeclCXX.cpp
  lib/Parse/ParseExprCXX.cpp
  lib/Parse/Parser.cpp
  lib/Parse/RAIIObjectsForParser.h
  lib/Sema/SemaCXXScopeSpec.cpp
  lib/Sema/TreeTransform.h
  test/CXX/drs/dr1xx.cpp
  test/CXX/drs/dr2xx.cpp
  test/Parser/cxx-decl.cpp
  test/SemaCXX/nested-name-spec2.cpp
  test/SemaCXX/pr18284-crash-on-invalid.cpp
  test/SemaCXX/typo-correction.cpp

Index: test/SemaCXX/typo-correction.cpp
===
--- test/SemaCXX/typo-correction.cpp
+++ test/SemaCXX/typo-correction.cpp
@@ -478,22 +478,17 @@
 }
 }
 
-namespace PR18213 {  // expected-note {{'PR18213' declared here}}
+namespace PR18213 {
 struct WrapperInfo {
   int i;
 };
 
 template  struct Wrappable {
   static WrapperInfo kWrapperInfo;
 };
 
-// Note the space before "::PR18213" is intended and needed, as it highlights
-// the actual typo, which is the leading "::".
-// TODO: Suggest removing the "::" from "::PR18213" (the right correction)
-// instead of incorrectly suggesting dropping "PR18213::WrapperInfo::".
 template <>
-PR18213::WrapperInfo ::PR18213::Wrappable::kWrapperInfo = { 0 };  // expected-error {{no member named 'PR18213' in 'PR18213::WrapperInfo'; did you mean simply 'PR18213'?}} \
-   // expected-error {{C++ requires a type specifier for all declarations}}
+PR18213::WrapperInfo ::PR18213::Wrappable::kWrapperInfo = { 0 };
 }
 
 namespace PR18651 {
Index: test/SemaCXX/pr18284-crash-on-invalid.cpp
===
--- test/SemaCXX/pr18284-crash-on-invalid.cpp
+++ test/SemaCXX/pr18284-crash-on-invalid.cpp
@@ -5,7 +5,7 @@
 class A { };
 class C { A a; };
 
-A::RunTest() {} // expected-error {{C++ requires a type specifier for all declarations}}
+A::RunTest() {} // expected-error {{definition or redeclaration of 'RunTest' cannot name the global scope}}
 
 void f() {
   new C;
@@ -16,7 +16,7 @@
 class A { };
 class C : public A { };
 
-A::RunTest() {} // expected-error {{C++ requires a type specifier for all declarations}}
+A::RunTest() {} // expected-error {{definition or redeclaration of 'RunTest' cannot name the global scope}}
 
 void f() {
   new C;
Index: test/SemaCXX/nested-name-spec2.cpp
===
--- /dev/null
+++ test/SemaCXX/nested-name-spec2.cpp
@@ -0,0 +1,60 @@
+// RUN: %clang_cc1 -fsyntax-only -std=c++11 -verify %s
+enum E1 { ABCD };
+
+struct C1 {
+  struct C2 {};
+  enum E2 { XYZ };
+};
+
+E1   func_01();
+E1 ::func_01();  // expected-warning{{extra qualification on member}}
+
+C1   func_02();
+C1 ::func_02();  // expected-warning{{extra qualification on member}}
+
+C1::C2   func_03();
+C1::C2 ::func_03();  // expected-warning{{extra qualification on member}}
+
+C1::E2   func_04();
+C1::E2 ::func_04();  // expected-warning{{extra qualification on member}}
+
+class C3 {
+  friend E1 ::func_01();
+  friend C1 ::func_02();
+  friend C1::C2 ::func_03();
+  friend C1::E2 ::func_04();
+};
+
+
+namespace N1 {
+  class C3 {
+friend ::E1 ::func_01();
+friend ::C1 ::func_02();
+friend ::C1::C2 ::func_03();
+friend ::C1::E2 ::func_04();
+  };
+}
+
+
+namespace N2 {
+  enum E1 { ABCD };
+
+  struct C1 {
+struct C2 {};
+enum E2 { XYZ };
+  };
+
+  E1 func_01();
+  C1 func_02();
+  C1::C2 func_03();
+  C1::E2 func_04();
+}
+
+namespace N3 {
+  class C4 {
+friend ::N2::E1 ::N2::func_01();
+friend ::N2::C1 ::N2::func_02();
+friend ::N2::C1::C2 ::N2::func_03();
+friend ::N2::C1::E2 ::N2::func_04();
+  };
+}
Index: test/Parser/cxx-decl.cpp
===
--- test/Parser/cxx-decl.cpp
+++ test/Parser/cxx-decl.cpp
@@ -249,8 +249,11 @@
 FooBar(); // expected-error {{missing return type for function 'FooBar'; did you mean the constructor name 'Foobar'?}}
 ~FooBar(); // 

Re: [PATCH] D23643: [Driver] Report invalid -mtune/-mcpu parameters when -arch=arm64

2016-08-18 Thread Vedant Kumar via cfe-commits
vsk added inline comments.


Comment at: lib/Driver/Tools.cpp:1163
@@ -1162,3 +1162,3 @@
   // FIXME: Should this be picked by checking the target triple instead?
-  if (Args.getLastArg(options::OPT_arch))
+  if ((A = Args.getLastArg(options::OPT_arch)))
 return "cyclone";

vsk wrote:
> ahatanak wrote:
> > Is there a test case for this change? I don't think this was needed to pass 
> > the tests you added?
> Good point, I'll work up a test case.
Actually, none of the callers of `getAArch64TargetCPU' fail when CPU="cyclone" 
(afaict).

Do you have a suggestion for how I can test this? I made the change here to 
make the function's contract more consistent, but can leave it out if you 
object.


https://reviews.llvm.org/D23643



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


Re: r278882 - If possible, set the stack rlimit to at least 8MiB on cc1 startup, and work

2016-08-18 Thread Richard Smith via cfe-commits
On Wed, Aug 17, 2016 at 6:35 AM, Joerg Sonnenberger via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> On Wed, Aug 17, 2016 at 01:05:08AM -, Richard Smith via cfe-commits
> wrote:
> > Author: rsmith
> > Date: Tue Aug 16 20:05:07 2016
> > New Revision: 278882
> >
> > URL: http://llvm.org/viewvc/llvm-project?rev=278882&view=rev
> > Log:
> > If possible, set the stack rlimit to at least 8MiB on cc1 startup, and
> work
> > around a Linux kernel bug where the actual amount of available stack may
> be a
> > *lot* lower than the rlimit.
>
> Can you please restrict this to Linux? I'm quite opposed to overriding
> system default limits, they exist for a reason.


No, that wouldn't make any sense. It's not up to the operating system how
an application decides to allocate memory (on the heap versus on the
stack), and Clang's stack usage isn't going to be significantly lower on
other kernels. If some BSD kernel's VM is unable to cope with this, we
could spawn a thread with a suitable amount of stack space instead.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r278882 - If possible, set the stack rlimit to at least 8MiB on cc1 startup, and work

2016-08-18 Thread Richard Smith via cfe-commits
llvm-config.h doesn't provide the necessary macros. I've applied a
different fix for out-of-tree builds in r279112.

On Wed, Aug 17, 2016 at 11:51 PM, Vedant Kumar via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Done in clang/r279035.
>
> thanks,
> vedant
>
> > On Aug 17, 2016, at 7:43 AM, Will Dietz via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
> >
> > (Seems to fix the build here, FWIW.  If sounds reasonable can someone
> commit this? Thanks!)
> >
> > ~Will
> >
> > On Wed, Aug 17, 2016 at 9:39 AM Will Dietz  wrote:
> > This is the first use of "llvm/Config/config.h" in the clang tree, which
> breaks out-of-tree builds for me (since llvm's config.h isn't installed).
> >
> > Would using "llvm/Config/llvm-config.h" suffice instead? I'm trying that
> now...
> >
> > ~Will
> >
> > On Wed, Aug 17, 2016 at 8:36 AM Joerg Sonnenberger via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
> > On Wed, Aug 17, 2016 at 01:05:08AM -, Richard Smith via cfe-commits
> wrote:
> > > Author: rsmith
> > > Date: Tue Aug 16 20:05:07 2016
> > > New Revision: 278882
> > >
> > > URL: http://llvm.org/viewvc/llvm-project?rev=278882&view=rev
> > > Log:
> > > If possible, set the stack rlimit to at least 8MiB on cc1 startup, and
> work
> > > around a Linux kernel bug where the actual amount of available stack
> may be a
> > > *lot* lower than the rlimit.
> >
> > Can you please restrict this to Linux? I'm quite opposed to overriding
> > system default limits, they exist for a reason.
> >
> > Joerg
> > ___
> > 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
>
> ___
> 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


r279112 - Use __has_include rather than a configure-time macro to determine if

2016-08-18 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Thu Aug 18 13:22:22 2016
New Revision: 279112

URL: http://llvm.org/viewvc/llvm-project?rev=279112&view=rev
Log:
Use __has_include rather than a configure-time macro to determine if
 is available. This should fix out-of-tree builds, at the cost
of not providing the higher rlimits to stage 1 clang when built with an old
host compiler not implementing this feature yet (bootstrap builds should be
fine, though).

Modified:
cfe/trunk/tools/driver/cc1_main.cpp

Modified: cfe/trunk/tools/driver/cc1_main.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/driver/cc1_main.cpp?rev=279112&r1=279111&r2=279112&view=diff
==
--- cfe/trunk/tools/driver/cc1_main.cpp (original)
+++ cfe/trunk/tools/driver/cc1_main.cpp Thu Aug 18 13:22:22 2016
@@ -37,9 +37,14 @@
 #include "llvm/Support/Timer.h"
 #include "llvm/Support/raw_ostream.h"
 #include 
-#if HAVE_SYS_RESOURCE_H
+
+#ifdef __has_include
+#if __has_include()
+#define HAVE_RLIMITS
 #include 
 #endif
+#endif
+
 using namespace clang;
 using namespace llvm::opt;
 
@@ -69,7 +74,7 @@ void initializePollyPasses(llvm::PassReg
 }
 #endif
 
-#if HAVE_SYS_RESOURCE_H && HAVE_GETRLIMIT && HAVE_SETRLIMIT
+#ifdef HAVE_RLIMITS
 // The amount of stack we think is "sufficient". If less than this much is
 // available, we may be unable to reach our template instantiation depth
 // limit and other similar limits.


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


Re: [PATCH] D23628: Fix unittests after windows command line parsing

2016-08-18 Thread Alexander Kornienko 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/D23628



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


Re: [PATCH] D23643: [Driver] Report invalid -mtune/-mcpu parameters when -arch=arm64

2016-08-18 Thread Vedant Kumar via cfe-commits
vsk added inline comments.


Comment at: lib/Driver/Tools.cpp:1163
@@ -1162,3 +1162,3 @@
   // FIXME: Should this be picked by checking the target triple instead?
-  if (Args.getLastArg(options::OPT_arch))
+  if ((A = Args.getLastArg(options::OPT_arch)))
 return "cyclone";

ahatanak wrote:
> Is there a test case for this change? I don't think this was needed to pass 
> the tests you added?
Good point, I'll work up a test case.


https://reviews.llvm.org/D23643



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


Re: [PATCH] D23602: Port tools/clang-format/git-clang-format to work Python beyond 2.7

2016-08-18 Thread Daniel Jasper via cfe-commits
djasper accepted this revision.
djasper added a comment.

Looks good.


Repository:
  rL LLVM

https://reviews.llvm.org/D23602



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


Re: [PATCH] D23643: [Driver] Report invalid -mtune/-mcpu parameters when -arch=arm64

2016-08-18 Thread Akira Hatanaka via cfe-commits
ahatanak added a subscriber: ahatanak.
ahatanak added a comment.

Thanks Vedant, this also fixes the crash that occurs when -mtune=native is 
provided.

https://reviews.llvm.org/D14471.



Comment at: lib/Driver/Tools.cpp:1163
@@ -1162,3 +1162,3 @@
   // FIXME: Should this be picked by checking the target triple instead?
-  if (Args.getLastArg(options::OPT_arch))
+  if ((A = Args.getLastArg(options::OPT_arch)))
 return "cyclone";

Is there a test case for this change? I don't think this was needed to pass the 
tests you added?


https://reviews.llvm.org/D23643



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


Re: [PATCH] D23602: Port tools/clang-format/git-clang-format to work Python beyond 2.7

2016-08-18 Thread Vedant Kumar via cfe-commits
vsk accepted this revision.
vsk added a reviewer: vsk.
vsk added a comment.
This revision is now accepted and ready to land.

This lgtm. I haven't touched clang-format before, so it would be good to 
double-check with the code owner before committing.


Repository:
  rL LLVM

https://reviews.llvm.org/D23602



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


Re: r279035 - [Driver] Use llvm-config.h, not config.h to unbreak out-of-tree builds

2016-08-18 Thread Vedant Kumar via cfe-commits
I shouldn't have assumed that this was correct because it built.

Reverted in r279097.

vedant

> On Aug 18, 2016, at 9:25 AM, Richard Smith  wrote:
> 
> This doesn't work at all, llvm-config.h does not provide the relevant 
> configuration macros.
> 
> 
> On 17 Aug 2016 11:56 p.m., "Vedant Kumar via cfe-commits" 
>  wrote:
> Author: vedantk
> Date: Thu Aug 18 01:43:07 2016
> New Revision: 279035
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=279035&view=rev
> Log:
> [Driver] Use llvm-config.h, not config.h to unbreak out-of-tree builds
> 
> llvm/Config/config.h has intentionally been excluded from llvm
> installations (see: llvm/CMakeLists.txt). Un-break out-of-tree builds
> post-r278882 by switching to llvm-config.h, which is exported.
> 
> Suggested by Will Dietz!
> 
> Modified:
> cfe/trunk/tools/driver/cc1_main.cpp
> 
> Modified: cfe/trunk/tools/driver/cc1_main.cpp
> URL: 
> http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/driver/cc1_main.cpp?rev=279035&r1=279034&r2=279035&view=diff
> ==
> --- cfe/trunk/tools/driver/cc1_main.cpp (original)
> +++ cfe/trunk/tools/driver/cc1_main.cpp Thu Aug 18 01:43:07 2016
> @@ -25,7 +25,7 @@
>  #include "clang/Frontend/Utils.h"
>  #include "clang/FrontendTool/Utils.h"
>  #include "llvm/ADT/Statistic.h"
> -#include "llvm/Config/config.h"
> +#include "llvm/Config/llvm-config.h"
>  #include "llvm/LinkAllPasses.h"
>  #include "llvm/Option/ArgList.h"
>  #include "llvm/Option/OptTable.h"
> 
> 
> ___
> 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


r279096 - Module: add -fprebuilt-module-path to support loading prebuilt modules.

2016-08-18 Thread Manman Ren via cfe-commits
Author: mren
Date: Thu Aug 18 12:42:15 2016
New Revision: 279096

URL: http://llvm.org/viewvc/llvm-project?rev=279096&view=rev
Log:
Module: add -fprebuilt-module-path to support loading prebuilt modules.

In this mode, there is no need to load any module map and the programmer can
simply use "@import" syntax to load the module directly from a prebuilt
module path. When loading from prebuilt module path, we don't support
rebuilding of the module files and we ignore compatible configuration
mismatches.

rdar://27290316
Differential Revision: http://reviews.llvm.org/D23125

Added:
cfe/trunk/test/Modules/Inputs/prebuilt-module/
cfe/trunk/test/Modules/Inputs/prebuilt-module/a.h
cfe/trunk/test/Modules/Inputs/prebuilt-module/module.modulemap
cfe/trunk/test/Modules/prebuilt-module.m
Modified:
cfe/trunk/docs/Modules.rst
cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/include/clang/Lex/HeaderSearch.h
cfe/trunk/include/clang/Lex/HeaderSearchOptions.h
cfe/trunk/include/clang/Serialization/Module.h
cfe/trunk/lib/Driver/Tools.cpp
cfe/trunk/lib/Frontend/ASTUnit.cpp
cfe/trunk/lib/Frontend/CompilerInstance.cpp
cfe/trunk/lib/Frontend/CompilerInvocation.cpp
cfe/trunk/lib/Frontend/FrontendActions.cpp
cfe/trunk/lib/Lex/HeaderSearch.cpp
cfe/trunk/lib/Serialization/ASTReader.cpp
cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
cfe/trunk/lib/Serialization/ModuleManager.cpp
cfe/trunk/test/Driver/modules.m

Modified: cfe/trunk/docs/Modules.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/Modules.rst?rev=279096&r1=279095&r2=279096&view=diff
==
--- cfe/trunk/docs/Modules.rst (original)
+++ cfe/trunk/docs/Modules.rst Thu Aug 18 12:42:15 2016
@@ -213,6 +213,9 @@ Command-line parameters
 ``-fmodule-file=``
   Load the given precompiled module file.
 
+``-fprebuilt-module-path=``
+  Specify the path to the prebuilt modules. If specified, we will look for 
modules in this directory for a given top-level module name. We don't need a 
module map for loading prebuilt modules in this directory and the compiler will 
not try to rebuild these modules. This can be specified multiple times.
+
 Module Semantics
 
 

Modified: cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td?rev=279096&r1=279095&r2=279096&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td Thu Aug 18 12:42:15 
2016
@@ -94,6 +94,8 @@ def err_module_lock_timeout : Error<
   "timed out waiting to acquire lock file for module '%0'">, DefaultFatal;
 def err_module_cycle : Error<"cyclic dependency in module '%0': %1">, 
   DefaultFatal;
+def err_module_prebuilt : Error<
+  "error in loading module '%0' from prebuilt module path">, DefaultFatal;
 def note_pragma_entered_here : Note<"#pragma entered here">;  
 def note_decl_hiding_tag_type : Note<
   "%1 %0 is hidden by a non-type declaration of %0 here">;

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=279096&r1=279095&r2=279096&view=diff
==
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Thu Aug 18 12:42:15 2016
@@ -840,6 +840,9 @@ def fmodules_cache_path : Joined<["-"],
 def fmodules_user_build_path : Separate<["-"], "fmodules-user-build-path">, 
Group,
   Flags<[DriverOption, CC1Option]>, MetaVarName<"">,
   HelpText<"Specify the module user build path">;
+def fprebuilt_module_path : Joined<["-"], "fprebuilt-module-path=">, 
Group,
+  Flags<[DriverOption, CC1Option]>, MetaVarName<"">,
+  HelpText<"Specify the prebuilt module path">;
 def fmodules_prune_interval : Joined<["-"], "fmodules-prune-interval=">, 
Group,
   Flags<[CC1Option]>, MetaVarName<"">,
   HelpText<"Specify the interval (in seconds) between attempts to prune the 
module cache">;

Modified: cfe/trunk/include/clang/Lex/HeaderSearch.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/HeaderSearch.h?rev=279096&r1=279095&r2=279096&view=diff
==
--- cfe/trunk/include/clang/Lex/HeaderSearch.h (original)
+++ cfe/trunk/include/clang/Lex/HeaderSearch.h Thu Aug 18 12:42:15 2016
@@ -481,9 +481,12 @@ public:
   /// \param ModuleMapPath A path that when combined with \c ModuleName
   /// uniquely identifies this module. See Module::ModuleMap.
   ///
+  /// \param UsePrebuiltPath Whether we should use the prebuilt module path.
+  ///
   /// \returns The name of the module 

r279097 - Revert "[Driver] Use llvm-config.h, not config.h to unbreak out-of-tree builds"

2016-08-18 Thread Vedant Kumar via cfe-commits
Author: vedantk
Date: Thu Aug 18 12:43:02 2016
New Revision: 279097

URL: http://llvm.org/viewvc/llvm-project?rev=279097&view=rev
Log:
Revert "[Driver] Use llvm-config.h, not config.h to unbreak out-of-tree builds"

This reverts commit r279035. According to Richard Smith, llvm-config.h
does not contain the right definitions.

Modified:
cfe/trunk/tools/driver/cc1_main.cpp

Modified: cfe/trunk/tools/driver/cc1_main.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/driver/cc1_main.cpp?rev=279097&r1=279096&r2=279097&view=diff
==
--- cfe/trunk/tools/driver/cc1_main.cpp (original)
+++ cfe/trunk/tools/driver/cc1_main.cpp Thu Aug 18 12:43:02 2016
@@ -25,7 +25,7 @@
 #include "clang/Frontend/Utils.h"
 #include "clang/FrontendTool/Utils.h"
 #include "llvm/ADT/Statistic.h"
-#include "llvm/Config/llvm-config.h"
+#include "llvm/Config/config.h"
 #include "llvm/LinkAllPasses.h"
 #include "llvm/Option/ArgList.h"
 #include "llvm/Option/OptTable.h"


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


Re: [PATCH] D23125: Modules: add command line option to support loading prebuilt modules on demand, without parsing any module map

2016-08-18 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL279096: Module: add -fprebuilt-module-path to support 
loading prebuilt modules. (authored by mren).

Changed prior to commit:
  https://reviews.llvm.org/D23125?vs=68456&id=68570#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D23125

Files:
  cfe/trunk/docs/Modules.rst
  cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td
  cfe/trunk/include/clang/Driver/Options.td
  cfe/trunk/include/clang/Lex/HeaderSearch.h
  cfe/trunk/include/clang/Lex/HeaderSearchOptions.h
  cfe/trunk/include/clang/Serialization/Module.h
  cfe/trunk/lib/Driver/Tools.cpp
  cfe/trunk/lib/Frontend/ASTUnit.cpp
  cfe/trunk/lib/Frontend/CompilerInstance.cpp
  cfe/trunk/lib/Frontend/CompilerInvocation.cpp
  cfe/trunk/lib/Frontend/FrontendActions.cpp
  cfe/trunk/lib/Lex/HeaderSearch.cpp
  cfe/trunk/lib/Serialization/ASTReader.cpp
  cfe/trunk/lib/Serialization/ASTReaderDecl.cpp
  cfe/trunk/lib/Serialization/ModuleManager.cpp
  cfe/trunk/test/Driver/modules.m
  cfe/trunk/test/Modules/Inputs/prebuilt-module/a.h
  cfe/trunk/test/Modules/Inputs/prebuilt-module/module.modulemap
  cfe/trunk/test/Modules/prebuilt-module.m

Index: cfe/trunk/docs/Modules.rst
===
--- cfe/trunk/docs/Modules.rst
+++ cfe/trunk/docs/Modules.rst
@@ -213,6 +213,9 @@
 ``-fmodule-file=``
   Load the given precompiled module file.
 
+``-fprebuilt-module-path=``
+  Specify the path to the prebuilt modules. If specified, we will look for modules in this directory for a given top-level module name. We don't need a module map for loading prebuilt modules in this directory and the compiler will not try to rebuild these modules. This can be specified multiple times.
+
 Module Semantics
 
 
Index: cfe/trunk/include/clang/Driver/Options.td
===
--- cfe/trunk/include/clang/Driver/Options.td
+++ cfe/trunk/include/clang/Driver/Options.td
@@ -840,6 +840,9 @@
 def fmodules_user_build_path : Separate<["-"], "fmodules-user-build-path">, Group,
   Flags<[DriverOption, CC1Option]>, MetaVarName<"">,
   HelpText<"Specify the module user build path">;
+def fprebuilt_module_path : Joined<["-"], "fprebuilt-module-path=">, Group,
+  Flags<[DriverOption, CC1Option]>, MetaVarName<"">,
+  HelpText<"Specify the prebuilt module path">;
 def fmodules_prune_interval : Joined<["-"], "fmodules-prune-interval=">, Group,
   Flags<[CC1Option]>, MetaVarName<"">,
   HelpText<"Specify the interval (in seconds) between attempts to prune the module cache">;
Index: cfe/trunk/include/clang/Lex/HeaderSearchOptions.h
===
--- cfe/trunk/include/clang/Lex/HeaderSearchOptions.h
+++ cfe/trunk/include/clang/Lex/HeaderSearchOptions.h
@@ -93,6 +93,9 @@
   /// \brief The directory used for a user build.
   std::string ModuleUserBuildPath;
 
+  /// \brief The directories used to load prebuilt module files.
+  std::vector PrebuiltModulePaths;
+
   /// The module/pch container format.
   std::string ModuleFormat;
 
@@ -201,6 +204,10 @@
   void AddVFSOverlayFile(StringRef Name) {
 VFSOverlayFiles.push_back(Name);
   }
+
+  void AddPrebuiltModulePath(StringRef Name) {
+PrebuiltModulePaths.push_back(Name);
+  }
 };
 
 } // end namespace clang
Index: cfe/trunk/include/clang/Lex/HeaderSearch.h
===
--- cfe/trunk/include/clang/Lex/HeaderSearch.h
+++ cfe/trunk/include/clang/Lex/HeaderSearch.h
@@ -481,9 +481,12 @@
   /// \param ModuleMapPath A path that when combined with \c ModuleName
   /// uniquely identifies this module. See Module::ModuleMap.
   ///
+  /// \param UsePrebuiltPath Whether we should use the prebuilt module path.
+  ///
   /// \returns The name of the module file that corresponds to this module,
   /// or an empty string if this module does not correspond to any module file.
-  std::string getModuleFileName(StringRef ModuleName, StringRef ModuleMapPath);
+  std::string getModuleFileName(StringRef ModuleName, StringRef ModuleMapPath,
+bool UsePrebuiltPath);
 
   /// \brief Lookup a module Search for a module with the given name.
   ///
Index: cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td
===
--- cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td
+++ cfe/trunk/include/clang/Basic/DiagnosticCommonKinds.td
@@ -94,6 +94,8 @@
   "timed out waiting to acquire lock file for module '%0'">, DefaultFatal;
 def err_module_cycle : Error<"cyclic dependency in module '%0': %1">, 
   DefaultFatal;
+def err_module_prebuilt : Error<
+  "error in loading module '%0' from prebuilt module path">, DefaultFatal;
 def note_pragma_entered_here : Note<"#pragma entered here">;  
 def note_decl_hiding_tag_type : Note<
   "%1 %0 is hidden by a non-type declaration of %0 her

Re: [PATCH] D23316: [analyzer] Fixed the false-positives caused by macro generated code.

2016-08-18 Thread Raphael Isemann via cfe-commits
teemperor updated this revision to Diff 68568.
teemperor marked 2 inline comments as done.
teemperor added a comment.

- Added false-positives note for empty macros to the test suite.


https://reviews.llvm.org/D23316

Files:
  include/clang/Analysis/CloneDetection.h
  lib/Analysis/CloneDetection.cpp
  test/Analysis/copypaste/macro-complexity.cpp
  test/Analysis/copypaste/macros.cpp

Index: test/Analysis/copypaste/macros.cpp
===
--- /dev/null
+++ test/Analysis/copypaste/macros.cpp
@@ -0,0 +1,67 @@
+// RUN: %clang_cc1 -analyze -std=c++11 -analyzer-checker=alpha.clone.CloneChecker -verify %s
+
+// Tests that macros and non-macro clones aren't mixed into the same hash
+// group. This is currently necessary as all clones in a hash group need
+// to have the same complexity value. Macros have smaller complexity values
+// and need to be in their own hash group.
+
+int foo(int a) { // expected-warning{{Detected code clone.}}
+  a = a + 1;
+  a = a + 1 / 1;
+  a = a + 1 + 1 + 1;
+  a = a + 1 - 1 + 1 + 1;
+  a = a + 1 * 1 + 1 + 1 + 1;
+  a = a + 1 / 1 + 1 + 1 + 1;
+  return a;
+}
+
+int fooClone(int a) { // expected-note{{Related code clone is here.}}
+  a = a + 1;
+  a = a + 1 / 1;
+  a = a + 1 + 1 + 1;
+  a = a + 1 - 1 + 1 + 1;
+  a = a + 1 * 1 + 1 + 1 + 1;
+  a = a + 1 / 1 + 1 + 1 + 1;
+  return a;
+}
+
+// Below is the same AST as above but this time generated with macros. The
+// clones below should land in their own hash group for the reasons given above.
+
+#define ASSIGN(T, V) T = T + V
+
+int macro(int a) { // expected-warning{{Detected code clone.}}
+  ASSIGN(a, 1);
+  ASSIGN(a, 1 / 1);
+  ASSIGN(a, 1 + 1 + 1);
+  ASSIGN(a, 1 - 1 + 1 + 1);
+  ASSIGN(a, 1 * 1 + 1 + 1 + 1);
+  ASSIGN(a, 1 / 1 + 1 + 1 + 1);
+  return a;
+}
+
+int macroClone(int a) { // expected-note{{Related code clone is here.}}
+  ASSIGN(a, 1);
+  ASSIGN(a, 1 / 1);
+  ASSIGN(a, 1 + 1 + 1);
+  ASSIGN(a, 1 - 1 + 1 + 1);
+  ASSIGN(a, 1 * 1 + 1 + 1 + 1);
+  ASSIGN(a, 1 / 1 + 1 + 1 + 1);
+  return a;
+}
+
+// FIXME: Macros with empty definitions in the AST are currently ignored.
+
+#define EMPTY
+
+int fooFalsePositiveClone(int a) { // expected-note{{Related code clone is here.}}
+  a = EMPTY a + 1;
+  a = a + 1 / 1;
+  a = a + 1 + 1 + 1;
+  a = a + 1 - 1 + 1 + 1;
+  a = a + 1 * 1 + 1 + 1 + 1;
+  a = a + 1 / 1 + 1 + 1 + 1;
+  return a;
+}
+
+
Index: test/Analysis/copypaste/macro-complexity.cpp
===
--- /dev/null
+++ test/Analysis/copypaste/macro-complexity.cpp
@@ -0,0 +1,50 @@
+// RUN: %clang_cc1 -analyze -std=c++11 -analyzer-checker=alpha.clone.CloneChecker -analyzer-config alpha.clone.CloneChecker:MinimumCloneComplexity=10 -verify %s
+
+// Tests that the complexity value of a macro expansion is about the same as
+// the complexity value of a normal function call and the the macro body doesn't
+// influence the complexity. See the CloneSignature class in CloneDetection.h
+// for more information about complexity values of clones.
+
+#define MACRO_FOO(a, b) a > b ? -a * a : -b * b;
+
+// First, manually apply MACRO_FOO and see if the code gets detected as a clone.
+// This confirms that with the current configuration the macro body would be
+// considered large enough to pass the MinimumCloneComplexity constraint.
+
+int manualMacro(int a, int b) { // expected-warning{{Detected code clone.}}
+  return a > b ? -a * a : -b * b;
+}
+
+int manualMacroClone(int a, int b) { // expected-note{{Related code clone is here.}}
+  return a > b ? -a * a : -b * b;
+}
+
+// Now we actually use the macro to generate the same AST as above. They
+// shouldn't be reported because the macros only slighly increase the complexity
+// value and the resulting code will never pass the MinimumCloneComplexity
+// constraint.
+
+int macro(int a, int b) {
+  return MACRO_FOO(a, b);
+}
+
+int macroClone(int a, int b) {
+  return MACRO_FOO(a, b);
+}
+
+// So far we only tested that macros increase the complexity by a lesser amount
+// than normal code. We also need to be sure this amount is not zero because
+// we otherwise macro code would be 'invisible' for the CloneDetector.
+// This tests that it is possible to increase the reach the minimum complexity
+// by only using macros. This is only possible if the complexity value is bigger
+// than zero.
+
+#define NEG(A) -(A)
+
+int nestedMacros() { // expected-warning{{Detected code clone.}}
+  return NEG(NEG(NEG(NEG(NEG(NEG(NEG(NEG(NEG(NEG(1));
+}
+
+int nestedMacrosClone() { // expected-note{{Related code clone is here.}}
+  return NEG(NEG(NEG(NEG(NEG(NEG(NEG(NEG(NEG(NEG(1));
+}
Index: lib/Analysis/CloneDetection.cpp
===
--- lib/Analysis/CloneDetection.cpp
+++ lib/Analysis/CloneDetection.cpp
@@ -17,7 +17,9 @@
 #include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/AST/Stmt.h"
 #include "clang/AST/StmtVisitor.h"
+#in

Re: [PATCH] D23316: [analyzer] Fixed the false-positives caused by macro generated code.

2016-08-18 Thread Raphael Isemann via cfe-commits
teemperor marked 10 inline comments as done.


Comment at: lib/Analysis/CloneDetection.cpp:436
@@ +435,3 @@
+if (IsInMacro) {
+  Signature.Complexity = 0;
+}

NoQ wrote:
> omtcyfz wrote:
> > omtcyfz wrote:
> > > omtcyfz wrote:
> > > > NoQ wrote:
> > > > > omtcyfz wrote:
> > > > > > Do I understand correctly that a code generated by a macro doesn't 
> > > > > > affect "complexity" at all then?
> > > > > > 
> > > > > > ```
> > > > > > TEST_F(QueryParserTest, Complete) {
> > > > > >   std::vector Comps =
> > > > > >   QueryParser::complete("", 0, QS);
> > > > > >   ASSERT_EQ(6u, Comps.size());
> > > > > >   EXPECT_EQ("help ", Comps[0].TypedText);
> > > > > >   EXPECT_EQ("help", Comps[0].DisplayText);
> > > > > >   EXPECT_EQ("let ", Comps[1].TypedText);
> > > > > >   EXPECT_EQ("let", Comps[1].DisplayText);
> > > > > >   EXPECT_EQ("match ", Comps[2].TypedText);
> > > > > >   EXPECT_EQ("match", Comps[2].DisplayText);
> > > > > >   EXPECT_EQ("set ", Comps[3].TypedText);
> > > > > >   EXPECT_EQ("set", Comps[3].DisplayText);
> > > > > >   EXPECT_EQ("unlet ", Comps[4].TypedText);
> > > > > >   EXPECT_EQ("unlet", Comps[4].DisplayText);
> > > > > >   EXPECT_EQ("quit", Comps[5].DisplayText);
> > > > > >   EXPECT_EQ("quit ", Comps[5].TypedText);
> > > > > > 
> > > > > >   Comps = QueryParser::complete("set o", 5, QS);
> > > > > >   ASSERT_EQ(1u, Comps.size());
> > > > > >   EXPECT_EQ("utput ", Comps[0].TypedText);
> > > > > >   EXPECT_EQ("output", Comps[0].DisplayText);
> > > > > > 
> > > > > >   Comps = QueryParser::complete("match while", 11, QS);
> > > > > >   ASSERT_EQ(1u, Comps.size());
> > > > > >   EXPECT_EQ("Stmt(", Comps[0].TypedText);
> > > > > >   EXPECT_EQ("Matcher whileStmt(Matcher...)",
> > > > > > Comps[0].DisplayText);
> > > > > > }
> > > > > > ```
> > > > > > 
> > > > > > This is an actual piece of code from 
> > > > > > `extra/unittests/clang-query/QueryParserTest.cpp`. Yes, it is a 
> > > > > > test, but it still is a nice example of how many macros can be 
> > > > > > found in code (especially if we are talking about pure C or some 
> > > > > > weird C++).
> > > > > > 
> > > > > > Thus, I think it is reasonable to treat macro invocation as a 
> > > > > > `1`-"complexity" node.
> > > > > This "0" is not for the macro itself, but for the statements into 
> > > > > which it expands. Macro itself is not a statement. If we put "1" 
> > > > > here, it would produce a lot more complexity than you want.
> > > > > 
> > > > > That said, it's a good idea to treat every macro as a "complexity-1" 
> > > > > statement, just need to figure out how to implement that correctly :)
> > > > > 
> > > > > Perhaps scan the source range of the sequence for how many different 
> > > > > macro expansions are included, and add that number to complexity(?)
> > > > > This "0" is not for the macro itself, but for the statements into 
> > > > > which it expands. Macro itself is not a statement. If we put "1" 
> > > > > here, it would produce a lot more complexity than you want.
> > > > 
> > > > Sure, I understand that, this is why I didn't suggest putting `1` there.
> > > > 
> > > > > Perhaps scan the source range of the sequence for how many different 
> > > > > macro expansions are included, and add that number to complexity(?)
> > > > 
> > > > Yes, this is exactly the solution that would work. Since macros aren't 
> > > > in the AST we'd need to get through SourceRange anyway.
> > > Though, it has to be optimized in order to prevent parsing a 
> > > SourceLocation multiple times.
> > *visiting each SourceLocation
> Yeah, as a rough approximation we could count macro expansions within the 
> current statement's children...
I'm now checking all expanded macros of the start/end locations. This should 
handle everything if I see that correctly (beside empty non-function macros 
which I marked as false-positives - not sure how we best handle them).


Comment at: test/Analysis/copypaste/macros.cpp:11
@@ +10,3 @@
+int max(int a, int b) { // expected-warning{{Detected code clone.}}
+  return a > b ? a : b;
+}

v.g.vassilev wrote:
> Wouldn't it be a good idea to have a fixit hint, saying "Did you mean to use 
> ABS(a,b)". If the suggestion is applied, it would make the code more 
> consistent, however it would encourage using preprocessor tricks (which is 
> not always considered as good practice).
I don't think detecting clones between macro definitions and normal code is 
easily possible. Doing the same for functions however is certainly possible 
(i.e. "did you meant to call `max(a, b)`). I added that to the open points list.


https://reviews.llvm.org/D23316



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


r279092 - [libclang] Added missing entry for newly introduced 'clang_getAllSkippedRanges' to libclang.exports

2016-08-18 Thread Cameron Desrochers via cfe-commits
Author: cameron314
Date: Thu Aug 18 12:18:03 2016
New Revision: 279092

URL: http://llvm.org/viewvc/llvm-project?rev=279092&view=rev
Log:
[libclang] Added missing entry for newly introduced 'clang_getAllSkippedRanges' 
to libclang.exports

Modified:
cfe/trunk/tools/libclang/libclang.exports

Modified: cfe/trunk/tools/libclang/libclang.exports
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/libclang.exports?rev=279092&r1=279091&r2=279092&view=diff
==
--- cfe/trunk/tools/libclang/libclang.exports (original)
+++ cfe/trunk/tools/libclang/libclang.exports Thu Aug 18 12:18:03 2016
@@ -142,6 +142,7 @@ clang_findReferencesInFile
 clang_findReferencesInFileWithBlock
 clang_formatDiagnostic
 clang_free
+clang_getAllSkippedRanges
 clang_getArgType
 clang_getArrayElementType
 clang_getArraySize


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


Re: [PATCH] D23316: [analyzer] Fixed the false-positives caused by macro generated code.

2016-08-18 Thread Raphael Isemann via cfe-commits
teemperor updated this revision to Diff 68556.
teemperor added a comment.

- Added more documentation to the CloneSignature::Complexity field.
- Macros now have a complexity value of 1 + sum(ChildComplexityValues).
- Tests should be less cryptic now.


https://reviews.llvm.org/D23316

Files:
  include/clang/Analysis/CloneDetection.h
  lib/Analysis/CloneDetection.cpp
  test/Analysis/copypaste/macro-complexity.cpp
  test/Analysis/copypaste/macros.cpp

Index: test/Analysis/copypaste/macros.cpp
===
--- /dev/null
+++ test/Analysis/copypaste/macros.cpp
@@ -0,0 +1,51 @@
+// RUN: %clang_cc1 -analyze -std=c++11 -analyzer-checker=alpha.clone.CloneChecker -verify %s
+
+// Tests that macros and non-macro clones aren't mixed into the same hash
+// group. This is currently necessary as all clones in a hash group need
+// to have the same complexity value. Macros have smaller complexity values
+// and need to be in their own hash group.
+
+int foo(int a) { // expected-warning{{Detected code clone.}}
+  a = a + 1;
+  a = a + 1 / 1;
+  a = a + 1 + 1 + 1;
+  a = a + 1 - 1 + 1 + 1;
+  a = a + 1 * 1 + 1 + 1 + 1;
+  a = a + 1 / 1 + 1 + 1 + 1;
+  return a;
+}
+
+int fooClone(int a) { // expected-note{{Related code clone is here.}}
+  a = a + 1;
+  a = a + 1 / 1;
+  a = a + 1 + 1 + 1;
+  a = a + 1 - 1 + 1 + 1;
+  a = a + 1 * 1 + 1 + 1 + 1;
+  a = a + 1 / 1 + 1 + 1 + 1;
+  return a;
+}
+
+// Below is the same AST as above but this time generated with macros. The
+// clones below should land in their own hash group for the reasons given above.
+
+#define ASSIGN(T, V) T = T + V
+
+int macro(int a) { // expected-warning{{Detected code clone.}}
+  ASSIGN(a, 1);
+  ASSIGN(a, 1 / 1);
+  ASSIGN(a, 1 + 1 + 1);
+  ASSIGN(a, 1 - 1 + 1 + 1);
+  ASSIGN(a, 1 * 1 + 1 + 1 + 1);
+  ASSIGN(a, 1 / 1 + 1 + 1 + 1);
+  return a;
+}
+
+int macroClone(int a) { // expected-note{{Related code clone is here.}}
+  ASSIGN(a, 1);
+  ASSIGN(a, 1 / 1);
+  ASSIGN(a, 1 + 1 + 1);
+  ASSIGN(a, 1 - 1 + 1 + 1);
+  ASSIGN(a, 1 * 1 + 1 + 1 + 1);
+  ASSIGN(a, 1 / 1 + 1 + 1 + 1);
+  return a;
+}
Index: test/Analysis/copypaste/macro-complexity.cpp
===
--- /dev/null
+++ test/Analysis/copypaste/macro-complexity.cpp
@@ -0,0 +1,50 @@
+// RUN: %clang_cc1 -analyze -std=c++11 -analyzer-checker=alpha.clone.CloneChecker -analyzer-config alpha.clone.CloneChecker:MinimumCloneComplexity=10 -verify %s
+
+// Tests that the complexity value of a macro expansion is about the same as
+// the complexity value of a normal function call and the the macro body doesn't
+// influence the complexity. See the CloneSignature class in CloneDetection.h
+// for more information about complexity values of clones.
+
+#define MACRO_FOO(a, b) a > b ? -a * a : -b * b;
+
+// First, manually apply MACRO_FOO and see if the code gets detected as a clone.
+// This confirms that with the current configuration the macro body would be
+// considered large enough to pass the MinimumCloneComplexity constraint.
+
+int manualMacro(int a, int b) { // expected-warning{{Detected code clone.}}
+  return a > b ? -a * a : -b * b;
+}
+
+int manualMacroClone(int a, int b) { // expected-note{{Related code clone is here.}}
+  return a > b ? -a * a : -b * b;
+}
+
+// Now we actually use the macro to generate the same AST as above. They
+// shouldn't be reported because the macros only slighly increase the complexity
+// value and the resulting code will never pass the MinimumCloneComplexity
+// constraint.
+
+int macro(int a, int b) {
+  return MACRO_FOO(a, b);
+}
+
+int macroClone(int a, int b) {
+  return MACRO_FOO(a, b);
+}
+
+// So far we only tested that macros increase the complexity by a lesser amount
+// than normal code. We also need to be sure this amount is not zero because
+// we otherwise macro code would be 'invisible' for the CloneDetector.
+// This tests that it is possible to increase the reach the minimum complexity
+// by only using macros. This is only possible if the complexity value is bigger
+// than zero.
+
+#define NEG(A) -(A)
+
+int nestedMacros() { // expected-warning{{Detected code clone.}}
+  return NEG(NEG(NEG(NEG(NEG(NEG(NEG(NEG(NEG(NEG(1));
+}
+
+int nestedMacrosClone() { // expected-note{{Related code clone is here.}}
+  return NEG(NEG(NEG(NEG(NEG(NEG(NEG(NEG(NEG(NEG(1));
+}
Index: lib/Analysis/CloneDetection.cpp
===
--- lib/Analysis/CloneDetection.cpp
+++ lib/Analysis/CloneDetection.cpp
@@ -17,7 +17,9 @@
 #include "clang/AST/RecursiveASTVisitor.h"
 #include "clang/AST/Stmt.h"
 #include "clang/AST/StmtVisitor.h"
+#include "clang/Lex/Lexer.h"
 #include "llvm/ADT/StringRef.h"
+#include "llvm/Support/raw_ostream.h"
 
 using namespace clang;
 
@@ -175,6 +177,38 @@
 };
 }
 
+/// \brief Prints the macro name that contains the given SourceLocation into
+///the given raw_string_ostream.
+st

Re: Record ranges skipped by the preprocessor and expose them with libclang.

2016-08-18 Thread Cameron via cfe-commits
Ah, is that why! My fault, sorry. I couldn't figure out why it wouldn't
link on the build machines when it worked fine for me locally (on
Windows)...
Thank you, I will fix this shortly.

On Thu, Aug 18, 2016 at 12:52 PM, Will Dietz via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> (Sending again, somehow the uiuc.edu mailing list address was in my
> reply-all! Sorry for the duplicates :))
>
> This breaks things for me, I think an entry in 'libclang.exports' is
> needed for clang_getAllSkippedRanges ?
>
> If that sounds right, can someone commit the fix?
>
> Thanks! :)
>
> ~Will, he-who-builds-from-trunk-more-often-than-he-should
>
> On Thu, Aug 18, 2016 at 11:48 AM Will Dietz  wrote:
>
>>
>>
>> On Thu, Dec 5, 2013 at 2:25 AM Argyrios Kyrtzidis 
>> wrote:
>>
>>>
>>> On Nov 15, 2013, at 7:57 AM, Erik Verbruggen 
>>> wrote:
>>>
>>> > Hi Argyrios,
>>> >
>>> > New patch attached. Your PCH comments do make sense, and I'll have to
>>> ponder about it a bit for my integration :)
>>>
>>> Committed in r196487, thanks!
>>>
>>> >
>>> > Cheers,
>>> > Erik.
>>> >
>>> > Ps: sorry about not including the comments from your mail, but my
>>> Mavericks upgrade managed to hose Mail.app or the index or something.
>>> >
>>> > <0001-Record-ranges-skipped-by-the-preprocessor-and-
>>> expose.patch>___
>>> > cfe-commits mailing list
>>> > cfe-comm...@cs.uiuc.edu
>>> > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>>>
>>> ___
>>> cfe-commits mailing list
>>> cfe-comm...@cs.uiuc.edu
>>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>>>
>>
> ___
> 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


Re: r279035 - [Driver] Use llvm-config.h, not config.h to unbreak out-of-tree builds

2016-08-18 Thread Richard Smith via cfe-commits
On 18 Aug 2016 9:36 a.m., "Reid Kleckner"  wrote:
>
> Clang isn't allowed to use LLVM's config.h, though, specifically to
support the standalone build.
>
> You can either create equivalent LLVM_ prefixed macros in
llvm-config.h.cmake, or repeat the checks and define the same macros in
clang/include/clang/Config/config.h.cmake.

Perhaps the best thing would be to move this functionality into LLVM and
just call it from clang.

> On Thu, Aug 18, 2016 at 9:25 AM, Richard Smith via cfe-commits <
cfe-commits@lists.llvm.org> wrote:
>>
>> This doesn't work at all, llvm-config.h does not provide the relevant
configuration macros.
>>
>>
>> On 17 Aug 2016 11:56 p.m., "Vedant Kumar via cfe-commits" <
cfe-commits@lists.llvm.org> wrote:
>>>
>>> Author: vedantk
>>> Date: Thu Aug 18 01:43:07 2016
>>> New Revision: 279035
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=279035&view=rev
>>> Log:
>>> [Driver] Use llvm-config.h, not config.h to unbreak out-of-tree builds
>>>
>>> llvm/Config/config.h has intentionally been excluded from llvm
>>> installations (see: llvm/CMakeLists.txt). Un-break out-of-tree builds
>>> post-r278882 by switching to llvm-config.h, which is exported.
>>>
>>> Suggested by Will Dietz!
>>>
>>> Modified:
>>> cfe/trunk/tools/driver/cc1_main.cpp
>>>
>>> Modified: cfe/trunk/tools/driver/cc1_main.cpp
>>> URL:
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/driver/cc1_main.cpp?rev=279035&r1=279034&r2=279035&view=diff
>>>
==
>>> --- cfe/trunk/tools/driver/cc1_main.cpp (original)
>>> +++ cfe/trunk/tools/driver/cc1_main.cpp Thu Aug 18 01:43:07 2016
>>> @@ -25,7 +25,7 @@
>>>  #include "clang/Frontend/Utils.h"
>>>  #include "clang/FrontendTool/Utils.h"
>>>  #include "llvm/ADT/Statistic.h"
>>> -#include "llvm/Config/config.h"
>>> +#include "llvm/Config/llvm-config.h"
>>>  #include "llvm/LinkAllPasses.h"
>>>  #include "llvm/Option/ArgList.h"
>>>  #include "llvm/Option/OptTable.h"
>>>
>>>
>>> ___
>>> 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
>>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: Record ranges skipped by the preprocessor and expose them with libclang.

2016-08-18 Thread Will Dietz via cfe-commits
(Sending again, somehow the uiuc.edu mailing list address was in my
reply-all! Sorry for the duplicates :))

This breaks things for me, I think an entry in 'libclang.exports' is needed
for clang_getAllSkippedRanges ?

If that sounds right, can someone commit the fix?

Thanks! :)

~Will, he-who-builds-from-trunk-more-often-than-he-should

On Thu, Aug 18, 2016 at 11:48 AM Will Dietz  wrote:

>
>
> On Thu, Dec 5, 2013 at 2:25 AM Argyrios Kyrtzidis 
> wrote:
>
>>
>> On Nov 15, 2013, at 7:57 AM, Erik Verbruggen 
>> wrote:
>>
>> > Hi Argyrios,
>> >
>> > New patch attached. Your PCH comments do make sense, and I'll have to
>> ponder about it a bit for my integration :)
>>
>> Committed in r196487, thanks!
>>
>> >
>> > Cheers,
>> > Erik.
>> >
>> > Ps: sorry about not including the comments from your mail, but my
>> Mavericks upgrade managed to hose Mail.app or the index or something.
>> >
>> >
>> <0001-Record-ranges-skipped-by-the-preprocessor-and-expose.patch>___
>> > cfe-commits mailing list
>> > cfe-comm...@cs.uiuc.edu
>> > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>>
>> ___
>> cfe-commits mailing list
>> cfe-comm...@cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: r279076 - [libclang] Add clang_getAllSkippedRanges function

2016-08-18 Thread H.J. Lu via cfe-commits
On Thu, Aug 18, 2016 at 8:43 AM, Cameron Desrochers via cfe-commits
 wrote:
> Author: cameron314
> Date: Thu Aug 18 10:43:55 2016
> New Revision: 279076
>
> URL: http://llvm.org/viewvc/llvm-project?rev=279076&view=rev
> Log:
> [libclang] Add clang_getAllSkippedRanges function
>
> This complements the clang_getSkippedRanges function which returns skipped 
> ranges filtered by a specific file.
>
> This function is useful when all the ranges are desired (and a lot more 
> efficient than the equivalent of asking for the ranges file by file, since 
> the implementation of clang_getSkippedRanges iterates over all ranges anyway).
>
> Differential Revision: https://reviews.llvm.org/D20132
>
> Modified:
> cfe/trunk/include/clang-c/Index.h
> cfe/trunk/tools/libclang/CIndex.cpp
> cfe/trunk/unittests/libclang/LibclangTest.cpp
>

libclangTests fails for me on Linux:

cd 
/export/build/gnu/llvm-clang/build-x86_64-linux/tools/clang/unittests/libclang
&& /usr/bin/cmake -E cmake_link_script
CMakeFiles/libclangTests.dir/link.txt --verbose=1
/usr/bin/g++  -m64   -fPIC -fvisibility-inlines-hidden -Wall -W
-Wno-unused-parameter -Wwrite-strings -Wcast-qual
-Wno-missing-field-initializers -pedantic -Wno-long-long
-Wno-maybe-uninitialized -Wdelete-non-virtual-dtor -Wno-comment
-Werror=date-time -std=c++11 -ffunction-sections -fdata-sections
-fno-common -Woverloaded-virtual -fno-strict-aliasing -O2 -g -DNDEBUG
 -Wl,-allow-shlib-undefined  -Wl,-O3 -Wl,--gc-sections
CMakeFiles/libclangTests.dir/LibclangTest.cpp.o  -o libclangTests
../../../../lib/libLLVMSupport.a -lpthread
../../../../lib/libgtest_main.a ../../../../lib/libgtest.a -lpthread
../../../../lib/libclang.so.4.0 ../../../../lib/libLLVMSupport.a -lrt
-ldl -ltinfo -lpthread -lz -lm -lpthread -Wl,-rpath,"\$ORIGIN/../lib"
CMakeFiles/libclangTests.dir/LibclangTest.cpp.o: In function
`LibclangParseTest_AllSkippedRanges_Test::TestBody()':
/export/gnu/import/git/llvm/tools/clang/unittests/libclang/LibclangTest.cpp:441:
undefined reference to `clang_getAllSkippedRanges'
collect2: error: ld returned 1 exit status
tools/clang/unittests/libclang/CMakeFiles/libclangTests.dir/build.make:99:
recipe for target 'tools/clang/unittests/libclang/libclangTests'
failed
gmake[4]: *** [tools/clang/unittests/libclang/libclangTests] Error 1
gmake[4]: Leaving directory '/export/build/gnu/llvm-clang/build-x86_64-linux'
CMakeFiles/Makefile2:32037: recipe for target
'tools/clang/unittests/libclang/CMakeFiles/libclangTests.dir/all'
failed

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


LLVM buildmaster will be restarted tonight

2016-08-18 Thread Galina Kistanova via cfe-commits
Hello everyone,

LLVM buildmaster will be updated and restarted after 6 PM Pacific time
today.

Thanks

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


Re: r279035 - [Driver] Use llvm-config.h, not config.h to unbreak out-of-tree builds

2016-08-18 Thread Reid Kleckner via cfe-commits
Clang isn't allowed to use LLVM's config.h, though, specifically to support
the standalone build.

You can either create equivalent LLVM_ prefixed macros in
llvm-config.h.cmake, or repeat the checks and define the same macros in
clang/include/clang/Config/config.h.cmake.

On Thu, Aug 18, 2016 at 9:25 AM, Richard Smith via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> This doesn't work at all, llvm-config.h does not provide the relevant
> configuration macros.
>
> On 17 Aug 2016 11:56 p.m., "Vedant Kumar via cfe-commits" <
> cfe-commits@lists.llvm.org> wrote:
>
>> Author: vedantk
>> Date: Thu Aug 18 01:43:07 2016
>> New Revision: 279035
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=279035&view=rev
>> Log:
>> [Driver] Use llvm-config.h, not config.h to unbreak out-of-tree builds
>>
>> llvm/Config/config.h has intentionally been excluded from llvm
>> installations (see: llvm/CMakeLists.txt). Un-break out-of-tree builds
>> post-r278882 by switching to llvm-config.h, which is exported.
>>
>> Suggested by Will Dietz!
>>
>> Modified:
>> cfe/trunk/tools/driver/cc1_main.cpp
>>
>> Modified: cfe/trunk/tools/driver/cc1_main.cpp
>> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/driver/
>> cc1_main.cpp?rev=279035&r1=279034&r2=279035&view=diff
>> 
>> ==
>> --- cfe/trunk/tools/driver/cc1_main.cpp (original)
>> +++ cfe/trunk/tools/driver/cc1_main.cpp Thu Aug 18 01:43:07 2016
>> @@ -25,7 +25,7 @@
>>  #include "clang/Frontend/Utils.h"
>>  #include "clang/FrontendTool/Utils.h"
>>  #include "llvm/ADT/Statistic.h"
>> -#include "llvm/Config/config.h"
>> +#include "llvm/Config/llvm-config.h"
>>  #include "llvm/LinkAllPasses.h"
>>  #include "llvm/Option/ArgList.h"
>>  #include "llvm/Option/OptTable.h"
>>
>>
>> ___
>> 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
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r279085 - [libclang] Fixed signed/unsigned comparison warning introduced in my revision r279076

2016-08-18 Thread Cameron Desrochers via cfe-commits
Author: cameron314
Date: Thu Aug 18 11:25:42 2016
New Revision: 279085

URL: http://llvm.org/viewvc/llvm-project?rev=279085&view=rev
Log:
[libclang] Fixed signed/unsigned comparison warning introduced in my revision 
r279076

Modified:
cfe/trunk/unittests/libclang/LibclangTest.cpp

Modified: cfe/trunk/unittests/libclang/LibclangTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/libclang/LibclangTest.cpp?rev=279085&r1=279084&r2=279085&view=diff
==
--- cfe/trunk/unittests/libclang/LibclangTest.cpp (original)
+++ cfe/trunk/unittests/libclang/LibclangTest.cpp Thu Aug 18 11:25:42 2016
@@ -439,7 +439,7 @@ TEST_F(LibclangParseTest, AllSkippedRang
nullptr, 0, TUFlags);
 
   CXSourceRangeList *Ranges = clang_getAllSkippedRanges(ClangTU);
-  EXPECT_EQ(2, Ranges->count);
+  EXPECT_EQ(2u, Ranges->count);
   
   CXSourceLocation cxl;
   unsigned line;


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


Re: r279035 - [Driver] Use llvm-config.h, not config.h to unbreak out-of-tree builds

2016-08-18 Thread Richard Smith via cfe-commits
This doesn't work at all, llvm-config.h does not provide the relevant
configuration macros.

On 17 Aug 2016 11:56 p.m., "Vedant Kumar via cfe-commits" <
cfe-commits@lists.llvm.org> wrote:

> Author: vedantk
> Date: Thu Aug 18 01:43:07 2016
> New Revision: 279035
>
> URL: http://llvm.org/viewvc/llvm-project?rev=279035&view=rev
> Log:
> [Driver] Use llvm-config.h, not config.h to unbreak out-of-tree builds
>
> llvm/Config/config.h has intentionally been excluded from llvm
> installations (see: llvm/CMakeLists.txt). Un-break out-of-tree builds
> post-r278882 by switching to llvm-config.h, which is exported.
>
> Suggested by Will Dietz!
>
> Modified:
> cfe/trunk/tools/driver/cc1_main.cpp
>
> Modified: cfe/trunk/tools/driver/cc1_main.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/
> driver/cc1_main.cpp?rev=279035&r1=279034&r2=279035&view=diff
> 
> ==
> --- cfe/trunk/tools/driver/cc1_main.cpp (original)
> +++ cfe/trunk/tools/driver/cc1_main.cpp Thu Aug 18 01:43:07 2016
> @@ -25,7 +25,7 @@
>  #include "clang/Frontend/Utils.h"
>  #include "clang/FrontendTool/Utils.h"
>  #include "llvm/ADT/Statistic.h"
> -#include "llvm/Config/config.h"
> +#include "llvm/Config/llvm-config.h"
>  #include "llvm/LinkAllPasses.h"
>  #include "llvm/Option/ArgList.h"
>  #include "llvm/Option/OptTable.h"
>
>
> ___
> 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


Re: [PATCH] D21959: [X86] Add xgetbv xsetbv intrinsics

2016-08-18 Thread Reid Kleckner via cfe-commits
rnk added a comment.

Hm, resending my comments because it doesn't appear to work from email. I swear 
it used to...

In https://reviews.llvm.org/D21959#519179, @guyblank wrote:

> Still, __XSAVE__ should have been defined when compiling for a target that 
> supports the feature.


That's not how MSVC intrinsics (or icc intrinsics, right?) are supposed to 
work, though. In MSVC, all intrinsics are always available, regardless of 
subtarget options. Unfortunately, Clang is not very compatible in this area, 
because of the way that we map the vector intrinsics to our generic vector IR 
and then codegen that. In this case, we don't have any generic instruction to 
map to, so I think we should try to be compatible here.

> But anyway, the xsaveintrin.h is quite small so always including it shouldn't 
> be an issue.

>  Are you ok with me removing the #if just for this header file, or would you 
> like to wait for Nico?


I think removing the _MSC_VER check is probably OK, but will the new LLVM 
intrinsic you added generate correct code when the xsave feature is disabled, 
as I expect it is in Chromium?


Repository:
  rL LLVM

https://reviews.llvm.org/D21959



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


Re: [PATCH] D20132: [libclang] Add clang_getAllSkippedRanges function

2016-08-18 Thread Cameron via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL279076: [libclang] Add clang_getAllSkippedRanges function 
(authored by cameron314).

Changed prior to commit:
  https://reviews.llvm.org/D20132?vs=56964&id=68548#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D20132

Files:
  cfe/trunk/include/clang-c/Index.h
  cfe/trunk/tools/libclang/CIndex.cpp
  cfe/trunk/unittests/libclang/LibclangTest.cpp

Index: cfe/trunk/tools/libclang/CIndex.cpp
===
--- cfe/trunk/tools/libclang/CIndex.cpp
+++ cfe/trunk/tools/libclang/CIndex.cpp
@@ -7773,6 +7773,33 @@
   return skipped;
 }
 
+CXSourceRangeList *clang_getAllSkippedRanges(CXTranslationUnit TU) {
+  CXSourceRangeList *skipped = new CXSourceRangeList;
+  skipped->count = 0;
+  skipped->ranges = nullptr;
+
+  if (isNotUsableTU(TU)) {
+LOG_BAD_TU(TU);
+return skipped;
+  }
+
+  ASTUnit *astUnit = cxtu::getASTUnit(TU);
+  PreprocessingRecord *ppRec = astUnit->getPreprocessor().getPreprocessingRecord();
+  if (!ppRec)
+return skipped;
+
+  ASTContext &Ctx = astUnit->getASTContext();
+
+  const std::vector &SkippedRanges = ppRec->getSkippedRanges();
+
+  skipped->count = SkippedRanges.size();
+  skipped->ranges = new CXSourceRange[skipped->count];
+  for (unsigned i = 0, ei = skipped->count; i != ei; ++i)
+skipped->ranges[i] = cxloc::translateSourceRange(Ctx, SkippedRanges[i]);
+
+  return skipped;
+}
+
 void clang_disposeSourceRangeList(CXSourceRangeList *ranges) {
   if (ranges) {
 delete[] ranges->ranges;
Index: cfe/trunk/include/clang-c/Index.h
===
--- cfe/trunk/include/clang-c/Index.h
+++ cfe/trunk/include/clang-c/Index.h
@@ -627,6 +627,15 @@
  CXFile file);
 
 /**
+ * \brief Retrieve all ranges from all files that were skipped by the
+ * preprocessor.
+ *
+ * The preprocessor will skip lines when they are surrounded by an
+ * if/ifdef/ifndef directive whose condition does not evaluate to true.
+ */
+CINDEX_LINKAGE CXSourceRangeList *clang_getAllSkippedRanges(CXTranslationUnit tu);
+
+/**
  * \brief Destroy the given \c CXSourceRangeList.
  */
 CINDEX_LINKAGE void clang_disposeSourceRangeList(CXSourceRangeList *ranges);
Index: cfe/trunk/unittests/libclang/LibclangTest.cpp
===
--- cfe/trunk/unittests/libclang/LibclangTest.cpp
+++ cfe/trunk/unittests/libclang/LibclangTest.cpp
@@ -14,6 +14,9 @@
 #include "llvm/Support/raw_ostream.h"
 #include "gtest/gtest.h"
 #include 
+#include 
+#include 
+#include 
 #include 
 #define DEBUG_TYPE "libclang-test"
 
@@ -349,21 +352,25 @@
   clang_ModuleMapDescriptor_dispose(MMD);
 }
 
-class LibclangReparseTest : public ::testing::Test {
+class LibclangParseTest : public ::testing::Test {
   std::set Files;
+  typedef std::unique_ptr fixed_addr_string;
+  std::map UnsavedFileContents;
 public:
   std::string TestDir;
   CXIndex Index;
   CXTranslationUnit ClangTU;
   unsigned TUFlags;
+  std::vector UnsavedFiles;
 
   void SetUp() override {
 llvm::SmallString<256> Dir;
 ASSERT_FALSE(llvm::sys::fs::createUniqueDirectory("libclang-test", Dir));
 TestDir = Dir.str();
 TUFlags = CXTranslationUnit_DetailedPreprocessingRecord |
-  clang_defaultEditingTranslationUnitOptions();
+  clang_defaultEditingTranslationUnitOptions();
 Index = clang_createIndex(0, 0);
+ClangTU = nullptr;
   }
   void TearDown() override {
 clang_disposeTranslationUnit(ClangTU);
@@ -384,6 +391,77 @@
 OS << Contents;
 assert(OS.good());
   }
+  void MapUnsavedFile(std::string Filename, const std::string &Contents) {
+if (!llvm::sys::path::is_absolute(Filename)) {
+  llvm::SmallString<256> Path(TestDir);
+  llvm::sys::path::append(Path, Filename);
+  Filename = Path.str();
+}
+auto it = UnsavedFileContents.emplace(
+fixed_addr_string(new std::string(Filename)),
+fixed_addr_string(new std::string(Contents)));
+UnsavedFiles.push_back({
+it.first->first->c_str(),   // filename
+it.first->second->c_str(),  // contents
+it.first->second->size()// length
+});
+  }
+  template
+  void Traverse(const F &TraversalFunctor) {
+CXCursor TuCursor = clang_getTranslationUnitCursor(ClangTU);
+std::reference_wrapper FunctorRef = std::cref(TraversalFunctor);
+clang_visitChildren(TuCursor,
+&TraverseStateless>,
+&FunctorRef);
+  }
+private:
+  template
+  static CXChildVisitResult TraverseStateless(CXCursor cx, CXCursor parent,
+  CXClientData data) {
+TState *State = static_cast(data);
+return State->get()(cx, parent);
+  }
+};
+
+TEST_F(LibclangParseTest, AllSkippedRanges) {
+  std::string Header = "header.h", Main = "main.cpp";
+  WriteFile(Header,
+"#ifdef MANGOS\n"
+"printf(\"mmm\");\n"
+"#endif")

r279076 - [libclang] Add clang_getAllSkippedRanges function

2016-08-18 Thread Cameron Desrochers via cfe-commits
Author: cameron314
Date: Thu Aug 18 10:43:55 2016
New Revision: 279076

URL: http://llvm.org/viewvc/llvm-project?rev=279076&view=rev
Log:
[libclang] Add clang_getAllSkippedRanges function

This complements the clang_getSkippedRanges function which returns skipped 
ranges filtered by a specific file.

This function is useful when all the ranges are desired (and a lot more 
efficient than the equivalent of asking for the ranges file by file, since the 
implementation of clang_getSkippedRanges iterates over all ranges anyway).

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

Modified:
cfe/trunk/include/clang-c/Index.h
cfe/trunk/tools/libclang/CIndex.cpp
cfe/trunk/unittests/libclang/LibclangTest.cpp

Modified: cfe/trunk/include/clang-c/Index.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang-c/Index.h?rev=279076&r1=279075&r2=279076&view=diff
==
--- cfe/trunk/include/clang-c/Index.h (original)
+++ cfe/trunk/include/clang-c/Index.h Thu Aug 18 10:43:55 2016
@@ -627,6 +627,15 @@ CINDEX_LINKAGE CXSourceRangeList *clang_
  CXFile file);
 
 /**
+ * \brief Retrieve all ranges from all files that were skipped by the
+ * preprocessor.
+ *
+ * The preprocessor will skip lines when they are surrounded by an
+ * if/ifdef/ifndef directive whose condition does not evaluate to true.
+ */
+CINDEX_LINKAGE CXSourceRangeList *clang_getAllSkippedRanges(CXTranslationUnit 
tu);
+
+/**
  * \brief Destroy the given \c CXSourceRangeList.
  */
 CINDEX_LINKAGE void clang_disposeSourceRangeList(CXSourceRangeList *ranges);

Modified: cfe/trunk/tools/libclang/CIndex.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=279076&r1=279075&r2=279076&view=diff
==
--- cfe/trunk/tools/libclang/CIndex.cpp (original)
+++ cfe/trunk/tools/libclang/CIndex.cpp Thu Aug 18 10:43:55 2016
@@ -7773,6 +7773,33 @@ CXSourceRangeList *clang_getSkippedRange
   return skipped;
 }
 
+CXSourceRangeList *clang_getAllSkippedRanges(CXTranslationUnit TU) {
+  CXSourceRangeList *skipped = new CXSourceRangeList;
+  skipped->count = 0;
+  skipped->ranges = nullptr;
+
+  if (isNotUsableTU(TU)) {
+LOG_BAD_TU(TU);
+return skipped;
+  }
+
+  ASTUnit *astUnit = cxtu::getASTUnit(TU);
+  PreprocessingRecord *ppRec = 
astUnit->getPreprocessor().getPreprocessingRecord();
+  if (!ppRec)
+return skipped;
+
+  ASTContext &Ctx = astUnit->getASTContext();
+
+  const std::vector &SkippedRanges = ppRec->getSkippedRanges();
+
+  skipped->count = SkippedRanges.size();
+  skipped->ranges = new CXSourceRange[skipped->count];
+  for (unsigned i = 0, ei = skipped->count; i != ei; ++i)
+skipped->ranges[i] = cxloc::translateSourceRange(Ctx, SkippedRanges[i]);
+
+  return skipped;
+}
+
 void clang_disposeSourceRangeList(CXSourceRangeList *ranges) {
   if (ranges) {
 delete[] ranges->ranges;

Modified: cfe/trunk/unittests/libclang/LibclangTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/libclang/LibclangTest.cpp?rev=279076&r1=279075&r2=279076&view=diff
==
--- cfe/trunk/unittests/libclang/LibclangTest.cpp (original)
+++ cfe/trunk/unittests/libclang/LibclangTest.cpp Thu Aug 18 10:43:55 2016
@@ -14,6 +14,9 @@
 #include "llvm/Support/raw_ostream.h"
 #include "gtest/gtest.h"
 #include 
+#include 
+#include 
+#include 
 #include 
 #define DEBUG_TYPE "libclang-test"
 
@@ -349,21 +352,25 @@ TEST(libclang, ModuleMapDescriptor) {
   clang_ModuleMapDescriptor_dispose(MMD);
 }
 
-class LibclangReparseTest : public ::testing::Test {
+class LibclangParseTest : public ::testing::Test {
   std::set Files;
+  typedef std::unique_ptr fixed_addr_string;
+  std::map UnsavedFileContents;
 public:
   std::string TestDir;
   CXIndex Index;
   CXTranslationUnit ClangTU;
   unsigned TUFlags;
+  std::vector UnsavedFiles;
 
   void SetUp() override {
 llvm::SmallString<256> Dir;
 ASSERT_FALSE(llvm::sys::fs::createUniqueDirectory("libclang-test", Dir));
 TestDir = Dir.str();
 TUFlags = CXTranslationUnit_DetailedPreprocessingRecord |
-  clang_defaultEditingTranslationUnitOptions();
+  clang_defaultEditingTranslationUnitOptions();
 Index = clang_createIndex(0, 0);
+ClangTU = nullptr;
   }
   void TearDown() override {
 clang_disposeTranslationUnit(ClangTU);
@@ -384,6 +391,77 @@ public:
 OS << Contents;
 assert(OS.good());
   }
+  void MapUnsavedFile(std::string Filename, const std::string &Contents) {
+if (!llvm::sys::path::is_absolute(Filename)) {
+  llvm::SmallString<256> Path(TestDir);
+  llvm::sys::path::append(Path, Filename);
+  Filename = Path.str();
+}
+auto it = UnsavedFileContents.emplace(
+fixed_addr_string(new std::string(Filename)),
+   

Re: [PATCH] D23651: [clang-rename] improve performance for rename-all

2016-08-18 Thread Alexander Kornienko via cfe-commits
alexfh requested changes to this revision.
This revision now requires changes to proceed.


Comment at: clang-rename/USRFindingAction.cpp:69
@@ -69,2 +68,3 @@
 }
-USRs->insert(USRs->end(), USRSet.begin(), USRSet.end());
+USRs.insert(USRs.end(), USRSet.begin(), USRSet.end());
+return USRs;

Should USRs be a local variable now?


Comment at: clang-rename/USRFindingAction.cpp:147
@@ +146,3 @@
+  explicit NamedDeclFindingConsumer(
+  const std::vector &SymbolOffsets,
+  const std::vector &OldNames,

Use `ArrayRef` here as well. BTW, if the code relies on `SymbolOffsets` and 
`OldNames` being of the same length, maybe a single collection of pairs would 
work better? Or define a structure for keeping offset and old name together?


Comment at: clang-rename/USRFindingAction.h:29
@@ -27,3 +28,3 @@
 struct USRFindingAction {
-  USRFindingAction(unsigned Offset, const std::string &Name)
-  : SymbolOffset(Offset), OldName(Name) {}
+  USRFindingAction(const std::vector &SymbolOffsets,
+   const std::vector &OldNames)

Use `ArrayRef` instead of `const vector<>&`. `ArrayRef<>` is less restrictive.


Comment at: clang-rename/USRFindingAction.h:30
@@ +29,3 @@
+  USRFindingAction(const std::vector &SymbolOffsets,
+   const std::vector &OldNames)
+  : SymbolOffsets(SymbolOffsets), OldNames(OldNames) {}

Use `ArrayRef`.


Comment at: clang-rename/USRFindingAction.h:38
@@ -37,5 +37,3 @@
 private:
-  unsigned SymbolOffset;
-  std::string OldName;
-  std::string SpellingName;
-  std::vector USRs;
+  const std::vector &SymbolOffsets;
+  const std::vector &OldNames;

omtcyfz wrote:
> Aw, you're right. Good catch, thanks!
Reference members always seem suspicious to me. One has to be really really 
careful not to mess up lifetimes. Are we actually saving much but not copying 
these vectors?


https://reviews.llvm.org/D23651



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


Re: [PATCH] D23361: [OpenCL] AMDGCN: Fix size_t type

2016-08-18 Thread Anastasia Stulova via cfe-commits
Anastasia accepted this revision.
Anastasia added a comment.
This revision is now accepted and ready to land.

LGTM!


https://reviews.llvm.org/D23361



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


Re: [PATCH] D23361: [OpenCL] AMDGCN: Fix size_t type

2016-08-18 Thread Yaxun Liu via cfe-commits
yaxunl marked an inline comment as done.


Comment at: lib/CodeGen/CGExprScalar.cpp:1513
@@ -1512,2 +1512,3 @@
 // extension.
-llvm::Type *MiddleTy = CGF.IntPtrTy;
+auto DestLLVMTy = ConvertType(DestTy);
+llvm::Type *MiddleTy = CGF.CGM.getDataLayout().getIntPtrType(DestLLVMTy);

Anastasia wrote:
> Did you miss this changes in the original patch then?
Yes.


Comment at: lib/CodeGen/CGExprScalar.cpp:2447
@@ -2443,3 +2446,3 @@
 bool isSigned = 
indexOperand->getType()->isSignedIntegerOrEnumerationType();
-index = CGF.Builder.CreateIntCast(index, CGF.PtrDiffTy, isSigned,
+index = CGF.Builder.CreateIntCast(index, DL.getIntPtrType(PtrTy), isSigned,
   "idx.ext");

Anastasia wrote:
> No longer ptrdiff_t?
PtrDiffTy and IntPtrTy are members of an anonymous union

  /// intptr_t, size_t, and ptrdiff_t, which we assume are the same size.
  union {
llvm::IntegerType *IntPtrTy;
llvm::IntegerType *SizeTy;
llvm::IntegerType *PtrDiffTy;
  };

so they are actually the same thing. 


https://reviews.llvm.org/D23361



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


Re: [PATCH] D15332: new clang-tidy checker readability-non-const-parameter

2016-08-18 Thread Alexander Kornienko via cfe-commits
alexfh accepted this revision.
alexfh added a comment.
This revision is now accepted and ready to land.

LG



Comment at: clang-tidy/readability/NonConstParameterCheck.cpp:104
@@ +103,3 @@
+  const QualType T = Parm->getType();
+  if (!T->isPointerType() || T->getPointeeType().isConstQualified() ||
+  !(T->getPointeeType()->isIntegerType() ||

You're right. I was thinking about enums, but `isIntegerType` takes care of 
them too. As the next step, we should try to add all POD types, but that's a 
question for another patch.


Comment at: test/clang-tidy/readability-non-const-parameter.cpp:118-136
@@ +117,21 @@
+int return1(int *p) {
+  // CHECK-FIXES: {{^}}int return1(const int *p) {{{$}}
+  return *p;
+}
+
+// CHECK-MESSAGES: :[[@LINE+1]]:25: warning: pointer parameter 'p' can be
+const int *return2(int *p) {
+  // CHECK-FIXES: {{^}}const int *return2(const int *p) {{{$}}
+  return p;
+}
+
+// CHECK-MESSAGES: :[[@LINE+1]]:25: warning: pointer parameter 'p' can be
+const int *return3(int *p) {
+  // CHECK-FIXES: {{^}}const int *return3(const int *p) {{{$}}
+  return p + 1;
+}
+
+// CHECK-MESSAGES: :[[@LINE+1]]:27: warning: pointer parameter 'p' can be
+const char *return4(char *p) {
+  // CHECK-FIXES: {{^}}const char *return4(const char *p) {{{$}}
+  return p ? p : "";

`PointerParameterConstnessCheck` is not much better, IMO. Maybe 
`readability-use-pointer-to-const-parameter`? Or just leave it like this for 
now.


https://reviews.llvm.org/D15332



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


Re: [PATCH] D23361: [OpenCL] AMDGCN: Fix size_t type

2016-08-18 Thread Anastasia Stulova via cfe-commits
Anastasia added inline comments.


Comment at: lib/CodeGen/CGExprScalar.cpp:1513
@@ -1512,2 +1512,3 @@
 // extension.
-llvm::Type *MiddleTy = CGF.IntPtrTy;
+auto DestLLVMTy = ConvertType(DestTy);
+llvm::Type *MiddleTy = CGF.CGM.getDataLayout().getIntPtrType(DestLLVMTy);

Did you miss this changes in the original patch then?


Comment at: lib/CodeGen/CGExprScalar.cpp:2447
@@ -2443,3 +2446,3 @@
 bool isSigned = 
indexOperand->getType()->isSignedIntegerOrEnumerationType();
-index = CGF.Builder.CreateIntCast(index, CGF.PtrDiffTy, isSigned,
+index = CGF.Builder.CreateIntCast(index, DL.getIntPtrType(PtrTy), isSigned,
   "idx.ext");

No longer ptrdiff_t?


https://reviews.llvm.org/D23361



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


Re: [PATCH] D23662: [libclang] Control whether crash recovery is enabled/disabled using function argument.

2016-08-18 Thread John Brawn via cfe-commits
john.brawn added a subscriber: john.brawn.
john.brawn added a comment.

> When my Java application calls clang_createIndex() with crash recovery 
> enabled it replaces the JVM's segfault handler with 
> CrashRecoverySignalHandler and now this handler gets all the segfault signals 
> that would have normally been sent to the JVM and when it does and tries to 
> restore the previous segfault hanlder (which is the JVMs) it doesn't install 
> the right one because the JVM ends up crashing and producing a core dump.


Surely the fix then is to make sure CrashRecoveryContext::Disable //does// 
reinstall the right signal handler?

> The only way to correctly solve my problem is to set the environment variable 
> 'LIBCLANG_DISABLE_CRASH_RECOVERY' but I find this to not be a very nice way 
> to control the program behaviour


Why not? Also I notice that using environment variables to control behaviour is 
used in a bunch of places in libclang so you're introducing some inconsistency 
here.


Repository:
  rL LLVM

https://reviews.llvm.org/D23662



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


Re: [PATCH] D23492: Make function local tags visible.

2016-08-18 Thread Vassil Vassilev via cfe-commits
v.g.vassilev updated this revision to Diff 68536.
v.g.vassilev marked 2 inline comments as done.
v.g.vassilev added a comment.

Add setHidden(false) and update fixme.


https://reviews.llvm.org/D23492

Files:
  include/clang/Sema/Sema.h
  lib/Sema/SemaTemplate.cpp
  lib/Sema/SemaTemplateInstantiate.cpp
  lib/Sema/SemaTemplateInstantiateDecl.cpp
  test/Modules/Inputs/PR28794/LibAHeader.h
  test/Modules/Inputs/PR28794/Subdir/Empty.h
  test/Modules/Inputs/PR28794/Subdir/LibBHeader.h
  test/Modules/Inputs/PR28794/module.modulemap
  test/Modules/pr28794.cpp

Index: test/Modules/pr28794.cpp
===
--- /dev/null
+++ test/Modules/pr28794.cpp
@@ -0,0 +1,17 @@
+// RUN: rm -rf %t
+// RUN: %clang_cc1 -std=c++11 -I%S/Inputs/PR28794 -verify %s
+// RUN: %clang_cc1 -std=c++11 -fmodules -fmodule-map-file=%S/Inputs/PR28794/module.modulemap -fmodules-cache-path=%t -I%S/Inputs/PR28794/ -verify %s
+
+#include "Subdir/Empty.h"
+#include "LibAHeader.h"
+
+BumpPtrAllocatorImpl<> &getPreprocessorAllocator();
+class B {
+  struct ModuleMacroInfo {
+ModuleMacroInfo *getModuleInfo() {
+  return new (getPreprocessorAllocator()) ModuleMacroInfo();
+}
+  };
+};
+
+// expected-no-diagnostics
Index: test/Modules/Inputs/PR28794/module.modulemap
===
--- /dev/null
+++ test/Modules/Inputs/PR28794/module.modulemap
@@ -0,0 +1,3 @@
+module M {
+  umbrella "Subdir" module * {export *}
+}
Index: test/Modules/Inputs/PR28794/Subdir/LibBHeader.h
===
--- /dev/null
+++ test/Modules/Inputs/PR28794/Subdir/LibBHeader.h
@@ -0,0 +1,12 @@
+#ifndef LIB_B_HEADER
+#define LIB_B_HEADER
+
+#include "LibAHeader.h"
+
+template 
+void *operator new(size_t, BumpPtrAllocatorImpl &) {
+  struct S {};
+  return (void*)0xdead;
+}
+
+#endif // LIB_B_HEADER
Index: test/Modules/Inputs/PR28794/Subdir/Empty.h
===
--- /dev/null
+++ test/Modules/Inputs/PR28794/Subdir/Empty.h
@@ -0,0 +1 @@
+
Index: test/Modules/Inputs/PR28794/LibAHeader.h
===
--- /dev/null
+++ test/Modules/Inputs/PR28794/LibAHeader.h
@@ -0,0 +1,12 @@
+#ifndef LIB_A_HEADER
+#define LIB_A_HEADER
+
+typedef __SIZE_TYPE__ size_t;
+
+template 
+class BumpPtrAllocatorImpl;
+
+template 
+void * operator new(size_t, BumpPtrAllocatorImpl &);
+
+#endif // LIB_A_HEADER
Index: lib/Sema/SemaTemplateInstantiateDecl.cpp
===
--- lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -3545,7 +3545,8 @@
 
   // Never instantiate an explicit specialization except if it is a class scope
   // explicit specialization.
-  if (Function->getTemplateSpecializationKind() == TSK_ExplicitSpecialization &&
+  TemplateSpecializationKind TSK = Function->getTemplateSpecializationKind();
+  if (TSK == TSK_ExplicitSpecialization &&
   !Function->getClassScopeSpecializationPattern())
 return;
 
@@ -3593,10 +3594,16 @@
 Pattern = PatternDecl->getBody(PatternDecl);
   }
 
-  // FIXME: Check that the definition is visible before trying to instantiate
-  // it. This requires us to track the instantiation stack in order to know
-  // which definitions should be visible.
+  // FIXME: We need to track the instantiation stack in order to know which
+  // definitions should be visible within this instantiation.
+  if (DiagnoseUninstantiableTemplate(PointOfInstantiation, Function,
+Function->getInstantiatedFromMemberFunction(),
+ PatternDecl, PatternDecl, TSK,
+ /*Complain*/DefinitionRequired))
+ return;
 
+  // FIXME: Check if we could sink these diagnostics in
+  // DiagnoseUninstantiableTemplate.
   if (!Pattern && !PatternDecl->isDefaulted()) {
 if (DefinitionRequired) {
   if (Function->getPrimaryTemplate())
@@ -3612,13 +3619,11 @@
 Diag(PatternDecl->getLocation(),
  diag::note_explicit_instantiation_here);
   Function->setInvalidDecl();
-} else if (Function->getTemplateSpecializationKind()
- == TSK_ExplicitInstantiationDefinition) {
+} else if (TSK == TSK_ExplicitInstantiationDefinition) {
   assert(!Recursive);
   PendingInstantiations.push_back(
 std::make_pair(Function, PointOfInstantiation));
-} else if (Function->getTemplateSpecializationKind()
- == TSK_ImplicitInstantiation) {
+} else if (TSK == TSK_ImplicitInstantiation) {
   if (AtEndOfTU && !getDiagnostics().hasErrorOccurred()) {
 Diag(PointOfInstantiation, diag::warn_func_template_missing)
   << Function;
@@ -3637,8 +3642,7 @@
   //   initializer or return value, and class template specializations, other
   //   explicit instantiation decla

Re: [PATCH] D20132: [libclang] Add clang_getAllSkippedRanges function

2016-08-18 Thread Cameron via cfe-commits
cameron314 added inline comments.


Comment at: unittests/libclang/LibclangTest.cpp:16-20
@@ -15,4 +15,7 @@
 #include "gtest/gtest.h"
 #include 
 #include 
+#include 
+#include 
+#include 
 #define DEBUG_TYPE "libclang-test"

rsmith wrote:
> Please put these in alphabetical order.
Will do!


https://reviews.llvm.org/D20132



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


Re: [PATCH] D15332: new clang-tidy checker readability-non-const-parameter

2016-08-18 Thread Daniel Marjamäki via cfe-commits
danielmarjamaki updated this revision to Diff 68531.
danielmarjamaki added a comment.

Fixed review comments about formatting in doc


https://reviews.llvm.org/D15332

Files:
  clang-tidy/readability/CMakeLists.txt
  clang-tidy/readability/NonConstParameterCheck.cpp
  clang-tidy/readability/NonConstParameterCheck.h
  clang-tidy/readability/ReadabilityTidyModule.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/readability-non-const-parameter.rst
  test/clang-tidy/readability-non-const-parameter.cpp

Index: test/clang-tidy/readability-non-const-parameter.cpp
===
--- test/clang-tidy/readability-non-const-parameter.cpp
+++ test/clang-tidy/readability-non-const-parameter.cpp
@@ -0,0 +1,279 @@
+// RUN: %check_clang_tidy %s readability-non-const-parameter %t
+
+// Currently the checker only warns about pointer arguments.
+//
+// It can be defined both that the data is const and that the pointer is const,
+// the checker only checks if the data can be const-specified.
+//
+// It does not warn about pointers to records or function pointers.
+
+// Some external function where first argument is nonconst and second is const.
+char *strcpy1(char *dest, const char *src);
+unsigned my_strcpy(char *buf, const char *s);
+unsigned my_strlen(const char *buf);
+
+// CHECK-MESSAGES: :[[@LINE+1]]:29: warning: pointer parameter 'last' can be pointer to const [readability-non-const-parameter]
+void warn1(int *first, int *last) {
+  // CHECK-FIXES: {{^}}void warn1(int *first, const int *last) {{{$}}
+  *first = 0;
+  if (first < last) {
+  } // <- last can be const
+}
+
+// TODO: warning should be written here
+void warn2(char *p) {
+  char buf[10];
+  strcpy1(buf, p);
+}
+
+// CHECK-MESSAGES: :[[@LINE+1]]:19: warning: pointer parameter 'p' can be
+void assign1(int *p) {
+  // CHECK-FIXES: {{^}}void assign1(const int *p) {{{$}}
+  const int *q;
+  q = p;
+}
+
+// CHECK-MESSAGES: :[[@LINE+1]]:19: warning: pointer parameter 'p' can be
+void assign2(int *p) {
+  // CHECK-FIXES: {{^}}void assign2(const int *p) {{{$}}
+  const int *q;
+  q = p + 1;
+}
+
+void assign3(int *p) {
+  *p = 0;
+}
+
+void assign4(int *p) {
+  *p += 2;
+}
+
+void assign5(char *p) {
+  p[0] = 0;
+}
+
+void assign6(int *p) {
+  int *q;
+  q = p++;
+}
+
+void assign7(char *p) {
+  char *a, *b;
+  a = b = p;
+}
+
+void assign8(char *a, char *b) {
+  char *x;
+  x = (a ? a : b);
+}
+
+void assign9(unsigned char *str, const unsigned int i) {
+  unsigned char *p;
+  for (p = str + i; *p;) {
+  }
+}
+
+void assign10(int *buf) {
+  int i, *p;
+  for (i = 0, p = buf; i < 10; i++, p++) {
+*p = 1;
+  }
+}
+
+// CHECK-MESSAGES: :[[@LINE+1]]:17: warning: pointer parameter 'p' can be
+void init1(int *p) {
+  // CHECK-FIXES: {{^}}void init1(const int *p) {{{$}}
+  const int *q = p;
+}
+
+// CHECK-MESSAGES: :[[@LINE+1]]:17: warning: pointer parameter 'p' can be
+void init2(int *p) {
+  // CHECK-FIXES: {{^}}void init2(const int *p) {{{$}}
+  const int *q = p + 1;
+}
+
+void init3(int *p) {
+  int *q = p;
+}
+
+void init4(float *p) {
+  int *q = (int *)p;
+}
+
+void init5(int *p) {
+  int *i = p ? p : 0;
+}
+
+void init6(int *p) {
+  int *a[] = {p, p, 0};
+}
+
+void init7(int *p, int x) {
+  for (int *q = p + x - 1; 0; q++)
+;
+}
+
+// CHECK-MESSAGES: :[[@LINE+1]]:18: warning: pointer parameter 'p' can be
+int return1(int *p) {
+  // CHECK-FIXES: {{^}}int return1(const int *p) {{{$}}
+  return *p;
+}
+
+// CHECK-MESSAGES: :[[@LINE+1]]:25: warning: pointer parameter 'p' can be
+const int *return2(int *p) {
+  // CHECK-FIXES: {{^}}const int *return2(const int *p) {{{$}}
+  return p;
+}
+
+// CHECK-MESSAGES: :[[@LINE+1]]:25: warning: pointer parameter 'p' can be
+const int *return3(int *p) {
+  // CHECK-FIXES: {{^}}const int *return3(const int *p) {{{$}}
+  return p + 1;
+}
+
+// CHECK-MESSAGES: :[[@LINE+1]]:27: warning: pointer parameter 'p' can be
+const char *return4(char *p) {
+  // CHECK-FIXES: {{^}}const char *return4(const char *p) {{{$}}
+  return p ? p : "";
+}
+
+char *return5(char *s) {
+  return s;
+}
+
+char *return6(char *s) {
+  return s + 1;
+}
+
+char *return7(char *a, char *b) {
+  return a ? a : b;
+}
+
+char return8(int *p) {
+  return ++(*p);
+}
+
+void dontwarn1(int *p) {
+  ++(*p);
+}
+
+void dontwarn2(int *p) {
+  (*p)++;
+}
+
+int dontwarn3(_Atomic(int) * p) {
+  return *p;
+}
+
+void callFunction1(char *p) {
+  strcpy1(p, "abc");
+}
+
+void callFunction2(char *p) {
+  strcpy1(&p[0], "abc");
+}
+
+void callFunction3(char *p) {
+  strcpy1(p + 2, "abc");
+}
+
+char *callFunction4(char *p) {
+  return strcpy1(p, "abc");
+}
+
+unsigned callFunction5(char *buf) {
+  unsigned len = my_strlen(buf);
+  return len + my_strcpy(buf, "abc");
+}
+
+void f6(int **p);
+void callFunction6(int *p) { f6(&p); }
+
+typedef union { void *v; } t;
+void f7(t obj);
+void callFunction7(int *p) {
+  f7((t){p});
+}
+
+void f8(int &x);
+void callFunction8(int *p) {
+  f8(*p);

Re: [PATCH] D15332: new clang-tidy checker readability-non-const-parameter

2016-08-18 Thread Daniel Marjamäki via cfe-commits
danielmarjamaki updated this revision to Diff 68528.
danielmarjamaki marked 2 inline comments as done.
danielmarjamaki added a comment.

Fixed review comments


https://reviews.llvm.org/D15332

Files:
  clang-tidy/readability/CMakeLists.txt
  clang-tidy/readability/NonConstParameterCheck.cpp
  clang-tidy/readability/NonConstParameterCheck.h
  clang-tidy/readability/ReadabilityTidyModule.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/readability-non-const-parameter.rst
  test/clang-tidy/readability-non-const-parameter.cpp

Index: test/clang-tidy/readability-non-const-parameter.cpp
===
--- test/clang-tidy/readability-non-const-parameter.cpp
+++ test/clang-tidy/readability-non-const-parameter.cpp
@@ -0,0 +1,279 @@
+// RUN: %check_clang_tidy %s readability-non-const-parameter %t
+
+// Currently the checker only warns about pointer arguments.
+//
+// It can be defined both that the data is const and that the pointer is const,
+// the checker only checks if the data can be const-specified.
+//
+// It does not warn about pointers to records or function pointers.
+
+// Some external function where first argument is nonconst and second is const.
+char *strcpy1(char *dest, const char *src);
+unsigned my_strcpy(char *buf, const char *s);
+unsigned my_strlen(const char *buf);
+
+// CHECK-MESSAGES: :[[@LINE+1]]:29: warning: pointer parameter 'last' can be pointer to const [readability-non-const-parameter]
+void warn1(int *first, int *last) {
+  // CHECK-FIXES: {{^}}void warn1(int *first, const int *last) {{{$}}
+  *first = 0;
+  if (first < last) {
+  } // <- last can be const
+}
+
+// TODO: warning should be written here
+void warn2(char *p) {
+  char buf[10];
+  strcpy1(buf, p);
+}
+
+// CHECK-MESSAGES: :[[@LINE+1]]:19: warning: pointer parameter 'p' can be
+void assign1(int *p) {
+  // CHECK-FIXES: {{^}}void assign1(const int *p) {{{$}}
+  const int *q;
+  q = p;
+}
+
+// CHECK-MESSAGES: :[[@LINE+1]]:19: warning: pointer parameter 'p' can be
+void assign2(int *p) {
+  // CHECK-FIXES: {{^}}void assign2(const int *p) {{{$}}
+  const int *q;
+  q = p + 1;
+}
+
+void assign3(int *p) {
+  *p = 0;
+}
+
+void assign4(int *p) {
+  *p += 2;
+}
+
+void assign5(char *p) {
+  p[0] = 0;
+}
+
+void assign6(int *p) {
+  int *q;
+  q = p++;
+}
+
+void assign7(char *p) {
+  char *a, *b;
+  a = b = p;
+}
+
+void assign8(char *a, char *b) {
+  char *x;
+  x = (a ? a : b);
+}
+
+void assign9(unsigned char *str, const unsigned int i) {
+  unsigned char *p;
+  for (p = str + i; *p;) {
+  }
+}
+
+void assign10(int *buf) {
+  int i, *p;
+  for (i = 0, p = buf; i < 10; i++, p++) {
+*p = 1;
+  }
+}
+
+// CHECK-MESSAGES: :[[@LINE+1]]:17: warning: pointer parameter 'p' can be
+void init1(int *p) {
+  // CHECK-FIXES: {{^}}void init1(const int *p) {{{$}}
+  const int *q = p;
+}
+
+// CHECK-MESSAGES: :[[@LINE+1]]:17: warning: pointer parameter 'p' can be
+void init2(int *p) {
+  // CHECK-FIXES: {{^}}void init2(const int *p) {{{$}}
+  const int *q = p + 1;
+}
+
+void init3(int *p) {
+  int *q = p;
+}
+
+void init4(float *p) {
+  int *q = (int *)p;
+}
+
+void init5(int *p) {
+  int *i = p ? p : 0;
+}
+
+void init6(int *p) {
+  int *a[] = {p, p, 0};
+}
+
+void init7(int *p, int x) {
+  for (int *q = p + x - 1; 0; q++)
+;
+}
+
+// CHECK-MESSAGES: :[[@LINE+1]]:18: warning: pointer parameter 'p' can be
+int return1(int *p) {
+  // CHECK-FIXES: {{^}}int return1(const int *p) {{{$}}
+  return *p;
+}
+
+// CHECK-MESSAGES: :[[@LINE+1]]:25: warning: pointer parameter 'p' can be
+const int *return2(int *p) {
+  // CHECK-FIXES: {{^}}const int *return2(const int *p) {{{$}}
+  return p;
+}
+
+// CHECK-MESSAGES: :[[@LINE+1]]:25: warning: pointer parameter 'p' can be
+const int *return3(int *p) {
+  // CHECK-FIXES: {{^}}const int *return3(const int *p) {{{$}}
+  return p + 1;
+}
+
+// CHECK-MESSAGES: :[[@LINE+1]]:27: warning: pointer parameter 'p' can be
+const char *return4(char *p) {
+  // CHECK-FIXES: {{^}}const char *return4(const char *p) {{{$}}
+  return p ? p : "";
+}
+
+char *return5(char *s) {
+  return s;
+}
+
+char *return6(char *s) {
+  return s + 1;
+}
+
+char *return7(char *a, char *b) {
+  return a ? a : b;
+}
+
+char return8(int *p) {
+  return ++(*p);
+}
+
+void dontwarn1(int *p) {
+  ++(*p);
+}
+
+void dontwarn2(int *p) {
+  (*p)++;
+}
+
+int dontwarn3(_Atomic(int) * p) {
+  return *p;
+}
+
+void callFunction1(char *p) {
+  strcpy1(p, "abc");
+}
+
+void callFunction2(char *p) {
+  strcpy1(&p[0], "abc");
+}
+
+void callFunction3(char *p) {
+  strcpy1(p + 2, "abc");
+}
+
+char *callFunction4(char *p) {
+  return strcpy1(p, "abc");
+}
+
+unsigned callFunction5(char *buf) {
+  unsigned len = my_strlen(buf);
+  return len + my_strcpy(buf, "abc");
+}
+
+void f6(int **p);
+void callFunction6(int *p) { f6(&p); }
+
+typedef union { void *v; } t;
+void f7(t obj);
+void callFunction7(int *p) {
+  f7((t){p});
+}
+
+void f8(int &x);
+void callFunct

[PATCH] D23657: Remove some false positives when taking the address of packed members

2016-08-18 Thread Roger Ferrer Ibanez via cfe-commits
rogfer01 created this revision.
rogfer01 added reviewers: aaron.ballman, rsmith.
rogfer01 added a subscriber: cfe-commits.

This change remove some false positives when taking the address of packed 
members.

- It silences the warning when a cast to uintptr_t/intptr_t happens.
- If the field is in a packed record that is overaligned, the field may still 
be in a suitable offset for the required alignment of the field. We now check 
this as well.

https://reviews.llvm.org/D23657

Files:
  lib/Sema/SemaChecking.cpp
  test/Sema/address-packed.c

Index: test/Sema/address-packed.c
===
--- test/Sema/address-packed.c
+++ test/Sema/address-packed.c
@@ -26,6 +26,7 @@
 struct Arguable *get_arguable();
 
 void to_void(void *);
+void to_intptr(intptr_t);
 
 void g0(void) {
   {
@@ -41,43 +42,48 @@
 
 f1((int *)(void *)&arguable.x); // no-warning
 to_void(&arguable.x);   // no-warning
-void *p = &arguable.x;  // no-warning;
+void *p = &arguable.x;  // no-warning
 to_void(p);
+to_intptr((intptr_t)p); // no-warning
   }
   {
 union UnionArguable arguable;
 f2(&arguable.c); // no-warning
 f1(&arguable.x); // expected-warning {{packed member 'x' of class or structure 'UnionArguable'}}
 
-f1((int *)(void *)&arguable.x); // no-warning
-to_void(&arguable.x);   // no-warning
+f1((int *)(void *)&arguable.x);   // no-warning
+to_void(&arguable.x); // no-warning
+to_intptr((intptr_t)&arguable.x); // no-warning
   }
   {
 ArguableT arguable;
 f2(&arguable.c0); // no-warning
 f1(&arguable.x);  // expected-warning {{packed member 'x' of class or structure 'Arguable'}}
 f2(&arguable.c1); // no-warning
 
-f1((int *)(void *)&arguable.x); // no-warning
-to_void(&arguable.x);   // no-warning
+f1((int *)(void *)&arguable.x);   // no-warning
+to_void(&arguable.x); // no-warning
+to_intptr((intptr_t)&arguable.x); // no-warning
   }
   {
 struct Arguable *arguable = get_arguable();
 f2(&arguable->c0); // no-warning
 f1(&arguable->x);  // expected-warning {{packed member 'x' of class or structure 'Arguable'}}
 f2(&arguable->c1); // no-warning
 
-f1((int *)(void *)&arguable->x); // no-warning
-to_void(&arguable->c1);  // no-warning
+f1((int *)(void *)&arguable->x);// no-warning
+to_void(&arguable->c1); // no-warning
+to_intptr((intptr_t)&arguable->c1); // no-warning
   }
   {
 ArguableT *arguable = get_arguable();
 f2(&(arguable->c0)); // no-warning
 f1(&(arguable->x));  // expected-warning {{packed member 'x' of class or structure 'Arguable'}}
 f2(&(arguable->c1)); // no-warning
 
-f1((int *)(void *)&(arguable->x)); // no-warning
-to_void(&(arguable->c1));  // no-warning
+f1((int *)(void *)&(arguable->x));  // no-warning
+to_void(&(arguable->c1));   // no-warning
+to_intptr((intptr_t)&(arguable->c1));   // no-warning
   }
 }
 
@@ -161,3 +167,18 @@
 {
 return (struct AlignedTo2Bis*)&s->x; // no-warning
 }
+
+struct S6 {
+int a;
+int _;
+int c;
+char __;
+int d;
+} __attribute__((packed, aligned(16))) s6;
+
+void foo()
+{ 
+f1(&s6.a); // no-warning
+f1(&s6.c); // no-warning
+f1(&s6.d); // expected-warning {{packed member 'd' of class or structure 'S6'}}
+}
Index: lib/Sema/SemaChecking.cpp
===
--- lib/Sema/SemaChecking.cpp
+++ lib/Sema/SemaChecking.cpp
@@ -11016,43 +11016,55 @@
 }
 
 void Sema::DiscardMisalignedMemberAddress(const Type *T, Expr *E) {
-  if (!T->isPointerType())
+  if (!T->isPointerType() && !T->isIntegerType())
 return;
   if (isa(E) &&
   cast(E)->getOpcode() == UO_AddrOf) {
 auto *Op = cast(E)->getSubExpr()->IgnoreParens();
 if (isa(Op)) {
   auto MA = std::find(MisalignedMembers.begin(), MisalignedMembers.end(),
   MisalignedMember(Op));
   if (MA != MisalignedMembers.end() &&
-  Context.getTypeAlignInChars(T->getPointeeType()) <= MA->Alignment)
+  (T->isIntegerType() ||
+   (T->isPointerType() &&
+Context.getTypeAlignInChars(T->getPointeeType()) <= MA->Alignment)))
 MisalignedMembers.erase(MA);
 }
   }
 }
 
 void Sema::RefersToMemberWithReducedAlignment(
 Expr *E,
 std::function Action) {
+  // return;
   const auto *ME = dyn_cast(E);
+  CharUnits RequiredAlignment;
   while (ME && isa(ME->getMemberDecl())) {
 QualType BaseType = ME->getBase()->getType();
 if (ME->isArrow())
   BaseType = BaseType->getPointeeType();
 RecordDecl *RD = BaseType->getAs()->getDecl();
 
 ValueDecl *MD = ME->getMemberDecl();
-bool ByteAligned = Context.getTypeAlignInChars(MD->getType()).isOne();
-if (ByteAligned) // Attribute packed does not have any effect.
-  break;
+a

r279056 - [analyzer] Teach CloneDetector to find clones that look like copy-paste errors.

2016-08-18 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Thu Aug 18 07:29:41 2016
New Revision: 279056

URL: http://llvm.org/viewvc/llvm-project?rev=279056&view=rev
Log:
[analyzer] Teach CloneDetector to find clones that look like copy-paste errors.

The original clone checker tries to find copy-pasted code that is exactly
identical to the original code, up to minor details.

As an example, if the copy-pasted code has all references to variable 'a'
replaced with references to variable 'b', it is still considered to be
an exact clone.

The new check finds copy-pasted code in which exactly one variable seems
out of place compared to the original code, which likely indicates
a copy-paste error (a variable was forgotten to be renamed in one place).

Patch by Raphael Isemann!

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

Added:
cfe/trunk/test/Analysis/copypaste/suspicious-clones.cpp
Modified:
cfe/trunk/include/clang/Analysis/CloneDetection.h
cfe/trunk/lib/Analysis/CloneDetection.cpp
cfe/trunk/lib/StaticAnalyzer/Checkers/CloneChecker.cpp

Modified: cfe/trunk/include/clang/Analysis/CloneDetection.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/CloneDetection.h?rev=279056&r1=279055&r2=279056&view=diff
==
--- cfe/trunk/include/clang/Analysis/CloneDetection.h (original)
+++ cfe/trunk/include/clang/Analysis/CloneDetection.h Thu Aug 18 07:29:41 2016
@@ -24,6 +24,7 @@ namespace clang {
 
 class Stmt;
 class Decl;
+class VarDecl;
 class ASTContext;
 class CompoundStmt;
 
@@ -222,7 +223,43 @@ public:
   ///   that were identified to be clones of each other.
   /// \param MinGroupComplexity Only return clones which have at least this
   ///   complexity value.
-  void findClones(std::vector &Result, unsigned 
MinGroupComplexity);
+  /// \param CheckPatterns Returns only clone groups in which the referenced
+  ///  variables follow the same pattern.
+  void findClones(std::vector &Result, unsigned MinGroupComplexity,
+  bool CheckPatterns = true);
+
+  /// \brief Describes two clones that reference their variables in a different
+  ///pattern which could indicate a programming error.
+  struct SuspiciousClonePair {
+/// \brief Utility class holding the relevant information about a single
+///clone in this pair.
+struct SuspiciousCloneInfo {
+  /// The variable which referencing in this clone was against the pattern.
+  const VarDecl *Variable;
+  /// Where the variable was referenced.
+  SourceRange VarRange;
+  /// The variable that should have been referenced to follow the pattern.
+  /// If Suggestion is a nullptr then it's not possible to fix the pattern
+  /// by referencing a different variable in this clone.
+  const VarDecl *Suggestion;
+  SuspiciousCloneInfo(const VarDecl *Variable, SourceRange Range,
+  const VarDecl *Suggestion)
+  : Variable(Variable), VarRange(Range), Suggestion(Suggestion) {}
+  SuspiciousCloneInfo() {}
+};
+/// The first clone in the pair which always has a suggested variable.
+SuspiciousCloneInfo FirstCloneInfo;
+/// This other clone in the pair which can have a suggested variable.
+SuspiciousCloneInfo SecondCloneInfo;
+  };
+
+  /// \brief Searches the provided statements for pairs of clones that don't
+  ///follow the same pattern when referencing variables.
+  /// \param Result Output parameter that will contain the clone pairs.
+  /// \param MinGroupComplexity Only clone pairs in which the clones have at
+  ///   least this complexity value.
+  void findSuspiciousClones(std::vector &Result,
+unsigned MinGroupComplexity);
 
 private:
   /// Stores all found clone groups including invalid groups with only a single

Modified: cfe/trunk/lib/Analysis/CloneDetection.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CloneDetection.cpp?rev=279056&r1=279055&r2=279056&view=diff
==
--- cfe/trunk/lib/Analysis/CloneDetection.cpp (original)
+++ cfe/trunk/lib/Analysis/CloneDetection.cpp Thu Aug 18 07:29:41 2016
@@ -88,8 +88,11 @@ class VariablePattern {
   struct VariableOccurence {
 /// The index of the associated VarDecl in the Variables vector.
 size_t KindID;
+/// The source range in the code where the variable was referenced.
+SourceRange Range;
 
-VariableOccurence(size_t KindID) : KindID(KindID) {}
+VariableOccurence(size_t KindID, SourceRange Range)
+: KindID(KindID), Range(Range) {}
   };
 
   /// All occurences of referenced variables in the order of appearance.
@@ -100,19 +103,20 @@ class VariablePattern {
 
   /// \brief Adds a new variable referenced to this pattern.
   /// \param VarDecl The declaration of the variable

Re: [PATCH] D23314: [analyzer] CloneDetector allows comparing clones for suspicious variable pattern errors.

2016-08-18 Thread Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL279056: [analyzer] Teach CloneDetector to find clones that 
look like copy-paste errors. (authored by dergachev).

Changed prior to commit:
  https://reviews.llvm.org/D23314?vs=68422&id=68518#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D23314

Files:
  cfe/trunk/include/clang/Analysis/CloneDetection.h
  cfe/trunk/lib/Analysis/CloneDetection.cpp
  cfe/trunk/lib/StaticAnalyzer/Checkers/CloneChecker.cpp
  cfe/trunk/test/Analysis/copypaste/suspicious-clones.cpp

Index: cfe/trunk/include/clang/Analysis/CloneDetection.h
===
--- cfe/trunk/include/clang/Analysis/CloneDetection.h
+++ cfe/trunk/include/clang/Analysis/CloneDetection.h
@@ -24,6 +24,7 @@
 
 class Stmt;
 class Decl;
+class VarDecl;
 class ASTContext;
 class CompoundStmt;
 
@@ -222,7 +223,43 @@
   ///   that were identified to be clones of each other.
   /// \param MinGroupComplexity Only return clones which have at least this
   ///   complexity value.
-  void findClones(std::vector &Result, unsigned MinGroupComplexity);
+  /// \param CheckPatterns Returns only clone groups in which the referenced
+  ///  variables follow the same pattern.
+  void findClones(std::vector &Result, unsigned MinGroupComplexity,
+  bool CheckPatterns = true);
+
+  /// \brief Describes two clones that reference their variables in a different
+  ///pattern which could indicate a programming error.
+  struct SuspiciousClonePair {
+/// \brief Utility class holding the relevant information about a single
+///clone in this pair.
+struct SuspiciousCloneInfo {
+  /// The variable which referencing in this clone was against the pattern.
+  const VarDecl *Variable;
+  /// Where the variable was referenced.
+  SourceRange VarRange;
+  /// The variable that should have been referenced to follow the pattern.
+  /// If Suggestion is a nullptr then it's not possible to fix the pattern
+  /// by referencing a different variable in this clone.
+  const VarDecl *Suggestion;
+  SuspiciousCloneInfo(const VarDecl *Variable, SourceRange Range,
+  const VarDecl *Suggestion)
+  : Variable(Variable), VarRange(Range), Suggestion(Suggestion) {}
+  SuspiciousCloneInfo() {}
+};
+/// The first clone in the pair which always has a suggested variable.
+SuspiciousCloneInfo FirstCloneInfo;
+/// This other clone in the pair which can have a suggested variable.
+SuspiciousCloneInfo SecondCloneInfo;
+  };
+
+  /// \brief Searches the provided statements for pairs of clones that don't
+  ///follow the same pattern when referencing variables.
+  /// \param Result Output parameter that will contain the clone pairs.
+  /// \param MinGroupComplexity Only clone pairs in which the clones have at
+  ///   least this complexity value.
+  void findSuspiciousClones(std::vector &Result,
+unsigned MinGroupComplexity);
 
 private:
   /// Stores all found clone groups including invalid groups with only a single
Index: cfe/trunk/test/Analysis/copypaste/suspicious-clones.cpp
===
--- cfe/trunk/test/Analysis/copypaste/suspicious-clones.cpp
+++ cfe/trunk/test/Analysis/copypaste/suspicious-clones.cpp
@@ -0,0 +1,97 @@
+// RUN: %clang_cc1 -analyze -analyzer-checker=alpha.clone.CloneChecker -analyzer-config alpha.clone.CloneChecker:ReportSuspiciousClones=true  -analyzer-config alpha.clone.CloneChecker:ReportNormalClones=false -verify %s
+
+// Tests finding a suspicious clone that references local variables.
+
+void log();
+
+int max(int a, int b) {
+  log();
+  if (a > b)
+return a;
+  return b; // expected-note{{suggestion is based on the usage of this variable in a similar piece of code}}
+}
+
+int maxClone(int x, int y, int z) {
+  log();
+  if (x > y)
+return x;
+  return z; // expected-warning{{suspicious code clone detected; did you mean to use 'y'?}}
+}
+
+// Tests finding a suspicious clone that references global variables.
+
+struct mutex {
+  bool try_lock();
+  void unlock();
+};
+
+mutex m1;
+mutex m2;
+int i;
+
+void busyIncrement() {
+  while (true) {
+if (m1.try_lock()) {
+  ++i;
+  m1.unlock(); // expected-note{{suggestion is based on the usage of this variable in a similar piece of code}}
+  if (i > 1000) {
+return;
+  }
+}
+  }
+}
+
+void faultyBusyIncrement() {
+  while (true) {
+if (m1.try_lock()) {
+  ++i;
+  m2.unlock();  // expected-warning{{suspicious code clone detected; did you mean to use 'm1'?}}
+  if (i > 1000) {
+return;
+  }
+}
+  }
+}
+
+// Tests that we provide two suggestions in cases where two fixes are possible.
+
+int foo(int a, int b, int c) {
+  a += b 

r279055 - Correct the documentation for isSignedInteger() and isUnsignedInteger().

2016-08-18 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Thu Aug 18 07:26:17 2016
New Revision: 279055

URL: http://llvm.org/viewvc/llvm-project?rev=279055&view=rev
Log:
Correct the documentation for isSignedInteger() and isUnsignedInteger().

Patch by Visoiu Mistrih Francis

Modified:
cfe/trunk/docs/LibASTMatchersReference.html
cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h

Modified: cfe/trunk/docs/LibASTMatchersReference.html
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/LibASTMatchersReference.html?rev=279055&r1=279054&r2=279055&view=diff
==
--- cfe/trunk/docs/LibASTMatchersReference.html (original)
+++ cfe/trunk/docs/LibASTMatchersReference.html Thu Aug 18 07:26:17 2016
@@ -3006,7 +3006,7 @@ Given
   void a(int);
   void b(unsigned long);
   void c(double);
-functionDecl(hasAnyParameter(hasType(isInteger(
+functionDecl(hasAnyParameter(hasType(isSignedInteger(
 matches "a(int)", but not "b(unsigned long)" and "c(double)".
 
 
@@ -3018,7 +3018,7 @@ Given
   void a(int);
   void b(unsigned long);
   void c(double);
-functionDecl(hasAnyParameter(hasType(isInteger(
+functionDecl(hasAnyParameter(hasType(isUnsignedInteger(
 matches "b(unsigned long)", but not "a(int)" and "c(double)".
 
 

Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h?rev=279055&r1=279054&r2=279055&view=diff
==
--- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h (original)
+++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h Thu Aug 18 07:26:17 2016
@@ -4161,7 +4161,7 @@ AST_MATCHER(QualType, isInteger) {
 ///   void b(unsigned long);
 ///   void c(double);
 /// \endcode
-/// functionDecl(hasAnyParameter(hasType(isInteger(
+/// functionDecl(hasAnyParameter(hasType(isUnsignedInteger(
 /// matches "b(unsigned long)", but not "a(int)" and "c(double)".
 AST_MATCHER(QualType, isUnsignedInteger) {
 return Node->isUnsignedIntegerType();
@@ -4175,7 +4175,7 @@ AST_MATCHER(QualType, isUnsignedInteger)
 ///   void b(unsigned long);
 ///   void c(double);
 /// \endcode
-/// functionDecl(hasAnyParameter(hasType(isInteger(
+/// functionDecl(hasAnyParameter(hasType(isSignedInteger(
 /// matches "a(int)", but not "b(unsigned long)" and "c(double)".
 AST_MATCHER(QualType, isSignedInteger) {
 return Node->isSignedIntegerType();


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


Re: [PATCH] D23641: [ASTMatchers] Fix documentation of is(Un)SignedInteger()

2016-08-18 Thread Aaron Ballman via cfe-commits
aaron.ballman closed this revision.
aaron.ballman added a comment.

Commit in r279055


https://reviews.llvm.org/D23641



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


Re: [PATCH] D23112: [analyzer] Correctly add assumptions based on array bounds.

2016-08-18 Thread Artem Dergachev via cfe-commits
NoQ added a comment.

On second thought, in `RangeConstraintManager` we need a different 
functionality. In particular, from `4 * x < 1000` it does not follow that `x < 
250` in the general case (due to possible overflows). But in the case of this 
checker, it doesn't matter - we are always sure that any valid array address is 
never overflowing even when converted to bytes.

That said, it is still boilerplate. Some day i wish to consider adding the 
non-overflowing versions of common operations into the `SValBuilder`'s 
`evalBinOp()`, so that it could help checkers simplify various symbolic 
expressions. In my opinion, `evalBinOp()` should be as user-friendly as 
possible.

But that's another story, your approach looks good to me!


https://reviews.llvm.org/D23112



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


Re: [PATCH] D23641: [ASTMatchers] Fix documentation of is(Un)SignedInteger()

2016-08-18 Thread Visoiu Mistrih Francis via cfe-commits
thegameg added a comment.

Can you commit this for me, please? Thanks!


https://reviews.llvm.org/D23641



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


Re: [PATCH] D23641: [ASTMatchers] Fix documentation of is(Un)SignedInteger()

2016-08-18 Thread Aaron Ballman via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

LGTM, thank you!


https://reviews.llvm.org/D23641



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


  1   2   >