r306372 - clang/test/CodeGenObjC/ivar-type-encoding.m: Tweak to satisfy -m32.

2017-06-27 Thread NAKAMURA Takumi via cfe-commits
Author: chapuni
Date: Tue Jun 27 00:40:47 2017
New Revision: 306372

URL: http://llvm.org/viewvc/llvm-project?rev=306372&view=rev
Log:
clang/test/CodeGenObjC/ivar-type-encoding.m: Tweak to satisfy -m32.

Modified:
cfe/trunk/test/CodeGenObjC/ivar-type-encoding.m

Modified: cfe/trunk/test/CodeGenObjC/ivar-type-encoding.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/ivar-type-encoding.m?rev=306372&r1=306371&r2=306372&view=diff
==
--- cfe/trunk/test/CodeGenObjC/ivar-type-encoding.m (original)
+++ cfe/trunk/test/CodeGenObjC/ivar-type-encoding.m Tue Jun 27 00:40:47 2017
@@ -48,4 +48,4 @@ int main() {
 // CHECK: @{{.*}} = private unnamed_addr constant [5 x i8] c"b0i3\00"
 // CHECK: @{{.*}} = private unnamed_addr constant [5 x i8] c"b3s2\00"
 // CHECK: @{{.*}} = private unnamed_addr constant [2 x i8] c"q\00"
-// CHECK: @{{.*}} = private unnamed_addr constant [7 x i8] c"b128c1\00"
+// CHECK: @{{.*}} = private unnamed_addr constant [{{7|6}} x i8] 
c"b{{128|96}}c1\00"


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


[Diffusion] rL306364: [CodeGen][ObjC] Fix GNU's encoding of bit-field ivars.

2017-06-27 Thread NAKAMURA Takumi via Phabricator via cfe-commits
chapuni added subscribers: cfe-commits, chapuni.
chapuni added a comment.

Could you confirm if my change were reasonable? Or rewrite it.


/cfe/trunk/test/CodeGenObjC/ivar-type-encoding.m:51 It was incompatible to -m32.

  @9 = private unnamed_addr constant [6 x i8] c"b96c1\00", align 1

Tweaked in rL306372.

Users:
  ahatanak (Author)

https://reviews.llvm.org/rL306364



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


r306373 - Switch TestVisitor to Lang_C via -x c

2017-06-27 Thread Stephan Bergmann via cfe-commits
Author: sberg
Date: Tue Jun 27 00:59:56 2017
New Revision: 306373

URL: http://llvm.org/viewvc/llvm-project?rev=306373&view=rev
Log:
Switch TestVisitor to Lang_C via -x c

...instead of -std=c99, as the latter lead to

  error: invalid argument '-std=c99' not allowed with 'C++'

complaints in test logs

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

Modified:
cfe/trunk/unittests/Tooling/TestVisitor.h

Modified: cfe/trunk/unittests/Tooling/TestVisitor.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Tooling/TestVisitor.h?rev=306373&r1=306372&r2=306373&view=diff
==
--- cfe/trunk/unittests/Tooling/TestVisitor.h (original)
+++ cfe/trunk/unittests/Tooling/TestVisitor.h Tue Jun 27 00:59:56 2017
@@ -53,7 +53,10 @@ public:
   bool runOver(StringRef Code, Language L = Lang_CXX) {
 std::vector Args;
 switch (L) {
-  case Lang_C: Args.push_back("-std=c99"); break;
+  case Lang_C:
+Args.push_back("-x");
+Args.push_back("c");
+break;
   case Lang_CXX98: Args.push_back("-std=c++98"); break;
   case Lang_CXX11: Args.push_back("-std=c++11"); break;
   case Lang_CXX14: Args.push_back("-std=c++14"); break;


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


[PATCH] D34417: Switch TestVisitor to Lang_C via -x c

2017-06-27 Thread Stephan Bergmann via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL306373: Switch TestVisitor to Lang_C via -x c (authored by 
sberg).

Changed prior to commit:
  https://reviews.llvm.org/D34417?vs=103263&id=104101#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D34417

Files:
  cfe/trunk/unittests/Tooling/TestVisitor.h


Index: cfe/trunk/unittests/Tooling/TestVisitor.h
===
--- cfe/trunk/unittests/Tooling/TestVisitor.h
+++ cfe/trunk/unittests/Tooling/TestVisitor.h
@@ -53,7 +53,10 @@
   bool runOver(StringRef Code, Language L = Lang_CXX) {
 std::vector Args;
 switch (L) {
-  case Lang_C: Args.push_back("-std=c99"); break;
+  case Lang_C:
+Args.push_back("-x");
+Args.push_back("c");
+break;
   case Lang_CXX98: Args.push_back("-std=c++98"); break;
   case Lang_CXX11: Args.push_back("-std=c++11"); break;
   case Lang_CXX14: Args.push_back("-std=c++14"); break;


Index: cfe/trunk/unittests/Tooling/TestVisitor.h
===
--- cfe/trunk/unittests/Tooling/TestVisitor.h
+++ cfe/trunk/unittests/Tooling/TestVisitor.h
@@ -53,7 +53,10 @@
   bool runOver(StringRef Code, Language L = Lang_CXX) {
 std::vector Args;
 switch (L) {
-  case Lang_C: Args.push_back("-std=c99"); break;
+  case Lang_C:
+Args.push_back("-x");
+Args.push_back("c");
+break;
   case Lang_CXX98: Args.push_back("-std=c++98"); break;
   case Lang_CXX11: Args.push_back("-std=c++11"); break;
   case Lang_CXX14: Args.push_back("-std=c++14"); break;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D32439: Fix for incorrect source position of dependent c'tor initializer (bug:26195)

2017-06-27 Thread Serge Preis via Phabricator via cfe-commits
Serge_Preis added a comment.

Thank you all for your help! The problem was that in Windows-targeted builds 
-fdelayed-template-parsing is set by default affecting template symbols 
appearance in index. Throwing -fno-delayed-template-parsing to c-index-test 
fixed the situation for failed configuration. The regular Linux build wors as 
before. So attaching fixed patch for 2nd attempt.


Repository:
  rL LLVM

https://reviews.llvm.org/D32439



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


[PATCH] D32439: Fix for incorrect source position of dependent c'tor initializer (bug:26195)

2017-06-27 Thread Serge Preis via Phabricator via cfe-commits
Serge_Preis updated this revision to Diff 104102.
Serge_Preis added a comment.

-fno-delayed-template-parsing atted to c-index-test arguments for consistent 
testing results among all targets


https://reviews.llvm.org/D32439

Files:
  lib/Sema/SemaDeclCXX.cpp
  test/Index/ctor-init-source-loc.cpp

Index: test/Index/ctor-init-source-loc.cpp
===
--- test/Index/ctor-init-source-loc.cpp
+++ test/Index/ctor-init-source-loc.cpp
@@ -0,0 +1,117 @@
+// RUN: c-index-test -test-load-source all %s -fno-delayed-template-parsing | FileCheck %s
+template
+struct Derived:  MyBase::InnerIterator
+{
+Derived() : MyBase::InnerIterator() {}
+// CHECK:  TypeRef=MyBase:2:19 Extent=[5:17 - 5:23]
+};
+
+template
+struct Derived2:  MyBase::Deeper::InnerIterator
+{
+Derived2() : MyBase::Deeper::InnerIterator() {}
+// CHECK:  TypeRef=MyBase:9:19 Extent=[12:18 - 12:24]
+};
+
+template
+struct Templ;
+
+template
+struct Derived3:  Templ::InnerIterator
+{
+Derived3() : Templ::InnerIterator() {}
+// CHECK: TemplateRef=Templ:17:8 Extent=[22:18 - 22:23]
+// CHECK: TypeRef=MyBase:19:19 Extent=[22:24 - 22:30]
+};
+
+
+struct Outer {
+template 
+struct Inner {
+typedef Q Parm;
+};
+};
+
+template
+struct Derived4:  Outer::Inner::Parm
+{
+Derived4() : Outer::Inner::Parm() {}
+// CHECK: TypeRef=struct Outer:28:8 Extent=[38:18 - 38:23]
+// CHECK: TemplateRef=Inner:30:12 Extent=[38:25 - 38:30]
+// CHECK: TypeRef=Q:35:19 Extent=[38:31 - 38:32]
+};
+
+template
+struct Derived5:  Outer::Inner::Parm::InnerIterator
+{
+Derived5() : Outer::Inner::Parm::InnerIterator() {}
+// CHECK: TypeRef=struct Outer:28:8 Extent=[47:18 - 47:23]
+// CHECK: TemplateRef=Inner:30:12 Extent=[47:25 - 47:30]
+// CHECK: TypeRef=Q:44:19 Extent=[47:31 - 47:32]
+};
+
+template
+struct Derived6:  Outer::Inner
+{
+Derived6() : Outer::Inner() {}
+// CHECK: TypeRef=struct Outer:28:8 Extent=[56:18 - 56:23]
+// CHECK: TemplateRef=Inner:30:12 Extent=[56:25 - 56:30]
+// CHECK: TypeRef=Q:53:19 Extent=[56:31 - 56:32]
+};
+
+struct Base {};
+
+struct Derived7:  Outer::Inner::Parm
+{
+Derived7() : Outer::Inner::Parm() {}
+// CHECK: TypeRef=struct Outer:28:8 Extent=[66:18 - 66:23]
+// CHECK: TemplateRef=Inner:30:12 Extent=[66:25 - 66:30]
+// CHECK: TypeRef=struct Base:62:8 Extent=[66:31 - 66:35]
+};
+
+struct Derived8:  Outer::Inner
+{
+Derived8() : Outer::Inner() {}
+// CHECK: TypeRef=struct Outer:28:8 Extent=[74:18 - 74:23]
+// CHECK: TemplateRef=Inner:30:12 Extent=[74:25 - 74:30]
+// CHECK: TypeRef=struct Base:62:8 Extent=[74:31 - 74:35]
+};
+
+namespace Namespace {
+template struct Templ;
+
+struct Outer {
+template 
+struct Inner {
+typedef Q Parm;
+};
+};
+}
+
+template
+struct Derived9:  Namespace::Templ::InnerIterator
+{
+Derived9() : Namespace::Templ::InnerIterator() {}
+// CHECK: NamespaceRef=Namespace:80:11 Extent=[94:18 - 94:27]
+// CHECK: TemplateRef=Templ:81:33 Extent=[94:29 - 94:34]
+// CHECK: TypeRef=MyBase:91:19 Extent=[94:35 - 94:41]
+};
+
+template
+struct Derived10:  Namespace::Templ
+{
+Derived10() : Namespace::Templ() {}
+// CHECK: NamespaceRef=Namespace:80:11 Extent=[103:19 - 103:28]
+// CHECK: TemplateRef=Templ:81:33 Extent=[103:30 - 103:35]
+// CHECK: TypeRef=MyBase:100:19 Extent=[103:36 - 103:42]
+};
+
+template
+struct Derived11:  Namespace::Outer::Inner::Parm
+{
+Derived11() : Namespace::Outer::Inner::Parm() {}
+// CHECK: NamespaceRef=Namespace:80:11 Extent=[112:19 - 112:28]
+// CHECK: TypeRef=struct Namespace::Outer:83:12 Extent=[112:30 - 112:35]
+// CHECK: TemplateRef=Inner:85:16 Extent=[112:37 - 112:42]
+// CHECK: TypeRef=MyBase:109:19 Extent=[112:43 - 112:49]
+};
Index: lib/Sema/SemaDeclCXX.cpp
===
--- lib/Sema/SemaDeclCXX.cpp
+++ lib/Sema/SemaDeclCXX.cpp
@@ -3778,6 +3778,15 @@
   if (BaseType.isNull())
 return true;
 
+  TInfo = Context.CreateTypeSourceInfo(BaseType);
+  DependentNameTypeLoc TL =
+  TInfo->getTypeLoc().castAs();
+  if (!TL.isNull()) {
+TL.setNameLoc(IdLoc);
+TL.setElaboratedKeywordLoc(SourceLocation());
+TL.setQualifierLoc(SS.getWithLocInContext(Context));
+  }
+
   R.clear();
   R.setLookupName(MemberOrBase);
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r306374 - Make sure TraverseInitListExpr visits InitListExpr exactly twice

2017-06-27 Thread Stephan Bergmann via cfe-commits
Author: sberg
Date: Tue Jun 27 01:04:08 2017
New Revision: 306374

URL: http://llvm.org/viewvc/llvm-project?rev=306374&view=rev
Log:
Make sure TraverseInitListExpr visits InitListExpr exactly twice

... once each for the syntactic and semantic form. Without this fix, behavior
of the newly added tests would have been

InitListExprIsPreOrderVisitedTwice:
 syntactic: 1
 semantic: 2

InitListExprIsPostOrderVisitedTwice:
 syntactic: 0
 semantic: 1

InitListExprIsPreOrderNoQueueVisitedTwice:
 syntactic: 1
 semantic: 2

InitListExprIsPostOrderNoQueueVisitedTwice:
 syntactic: 0
 semantic: 2

Modified:
cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
cfe/trunk/unittests/Tooling/RecursiveASTVisitorTest.cpp

Modified: cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/RecursiveASTVisitor.h?rev=306374&r1=306373&r2=306374&view=diff
==
--- cfe/trunk/include/clang/AST/RecursiveASTVisitor.h (original)
+++ cfe/trunk/include/clang/AST/RecursiveASTVisitor.h Tue Jun 27 01:04:08 2017
@@ -593,6 +593,16 @@ bool RecursiveASTVisitor::PostV
 #define STMT(CLASS, PARENT)
\
   case Stmt::CLASS##Class: 
\
 TRY_TO(WalkUpFrom##CLASS(static_cast(S))); break;
+#define INITLISTEXPR(CLASS, PARENT)
\
+  case Stmt::CLASS##Class: 
\
+{  
\
+  auto ILE = static_cast(S);  
\
+  if (auto Syn = ILE->isSemanticForm() ? ILE->getSyntacticForm() : ILE)
\
+TRY_TO(WalkUpFrom##CLASS(Syn));
\
+  if (auto Sem = ILE->isSemanticForm() ? ILE : ILE->getSemanticForm()) 
\
+TRY_TO(WalkUpFrom##CLASS(Sem));
\
+  break;   
\
+}
 #include "clang/AST/StmtNodes.inc"
   }
 
@@ -2220,13 +2230,15 @@ bool RecursiveASTVisitor::Trave
 // the syntactic and the semantic form.
 //
 // There is no guarantee about which form \p S takes when this method is 
called.
-DEF_TRAVERSE_STMT(InitListExpr, {
+template 
+bool RecursiveASTVisitor::TraverseInitListExpr(
+InitListExpr *S, DataRecursionQueue *Queue) {
   TRY_TO(TraverseSynOrSemInitListExpr(
   S->isSemanticForm() ? S->getSyntacticForm() : S, Queue));
   TRY_TO(TraverseSynOrSemInitListExpr(
   S->isSemanticForm() ? S : S->getSemanticForm(), Queue));
-  ShouldVisitChildren = false;
-})
+  return true;
+}
 
 // GenericSelectionExpr is a special case because the types and expressions
 // are interleaved.  We also need to watch out for null types (default

Modified: cfe/trunk/unittests/Tooling/RecursiveASTVisitorTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Tooling/RecursiveASTVisitorTest.cpp?rev=306374&r1=306373&r2=306374&view=diff
==
--- cfe/trunk/unittests/Tooling/RecursiveASTVisitorTest.cpp (original)
+++ cfe/trunk/unittests/Tooling/RecursiveASTVisitorTest.cpp Tue Jun 27 01:04:08 
2017
@@ -158,4 +158,90 @@ TEST(RecursiveASTVisitor, DefaultArgumen
   "static int k = f();\n"));
 }
 
+// Check to ensure that InitListExpr is visited twice, once each for the
+// syntactic and semantic form.
+class InitListExprPreOrderVisitor
+: public ExpectedLocationVisitor {
+public:
+  bool VisitInitListExpr(InitListExpr *ILE) {
+Match(ILE->isSemanticForm() ? "semantic" : "syntactic", 
ILE->getLocStart());
+return true;
+  }
+};
+
+class InitListExprPostOrderVisitor
+: public ExpectedLocationVisitor {
+public:
+  bool shouldTraversePostOrder() const { return true; }
+
+  bool VisitInitListExpr(InitListExpr *ILE) {
+Match(ILE->isSemanticForm() ? "semantic" : "syntactic", 
ILE->getLocStart());
+return true;
+  }
+};
+
+class InitListExprPreOrderNoQueueVisitor
+: public ExpectedLocationVisitor {
+public:
+  bool TraverseInitListExpr(InitListExpr *ILE) {
+return ExpectedLocationVisitor::TraverseInitListExpr(ILE);
+  }
+
+  bool VisitInitListExpr(InitListExpr *ILE) {
+Match(ILE->isSemanticForm() ? "semantic" : "syntactic", 
ILE->getLocStart());
+return true;
+  }
+};
+
+class InitListExprPostOrderNoQueueVisitor
+: public ExpectedLocationVisitor {
+public:
+  bool shouldTraversePostOrder() const { return true; }
+
+  bool TraverseInitListExpr(InitListExpr *ILE) {
+return ExpectedLocationVisitor::TraverseInitListExpr(ILE);
+  }
+
+  bool VisitInitListExpr(InitListExpr *ILE) {
+Match(ILE->isSemanticForm() ? "semantic" : "syntactic", 
ILE->getLocStart());
+return true;
+  }
+};
+
+TEST(RecursiveASTVisitor, InitListExp

[PATCH] D34419: Make sure TraverseInitListExpr visits InitListExpr exactly twice

2017-06-27 Thread Stephan Bergmann via Phabricator via cfe-commits
sberg added a comment.

committed as https://reviews.llvm.org/rL306374


https://reviews.llvm.org/D34419



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


[PATCH] D22128: Make CastExpr::getSubExprAsWritten look through implicit temporary under CK_ConstructorConversion

2017-06-27 Thread Stephan Bergmann via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL306377: Make CastExpr::getSubExprAsWritten look through 
implicit temporary under… (authored by sberg).

Changed prior to commit:
  https://reviews.llvm.org/D22128?vs=103449&id=104104#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D22128

Files:
  cfe/trunk/lib/AST/Expr.cpp
  cfe/trunk/unittests/Tooling/CMakeLists.txt
  cfe/trunk/unittests/Tooling/CastExprTest.cpp

Index: cfe/trunk/lib/AST/Expr.cpp
===
--- cfe/trunk/lib/AST/Expr.cpp
+++ cfe/trunk/lib/AST/Expr.cpp
@@ -1641,25 +1641,32 @@
   llvm_unreachable("Unhandled cast kind!");
 }
 
+namespace {
+  Expr *skipImplicitTemporary(Expr *expr) {
+// Skip through reference binding to temporary.
+if (MaterializeTemporaryExpr *Materialize
+  = dyn_cast(expr))
+  expr = Materialize->GetTemporaryExpr();
+
+// Skip any temporary bindings; they're implicit.
+if (CXXBindTemporaryExpr *Binder = dyn_cast(expr))
+  expr = Binder->getSubExpr();
+
+return expr;
+  }
+}
+
 Expr *CastExpr::getSubExprAsWritten() {
   Expr *SubExpr = nullptr;
   CastExpr *E = this;
   do {
-SubExpr = E->getSubExpr();
+SubExpr = skipImplicitTemporary(E->getSubExpr());
 
-// Skip through reference binding to temporary.
-if (MaterializeTemporaryExpr *Materialize 
-  = dyn_cast(SubExpr))
-  SubExpr = Materialize->GetTemporaryExpr();
-
-// Skip any temporary bindings; they're implicit.
-if (CXXBindTemporaryExpr *Binder = dyn_cast(SubExpr))
-  SubExpr = Binder->getSubExpr();
-
 // Conversions by constructor and conversion functions have a
 // subexpression describing the call; strip it off.
 if (E->getCastKind() == CK_ConstructorConversion)
-  SubExpr = cast(SubExpr)->getArg(0);
+  SubExpr =
+skipImplicitTemporary(cast(SubExpr)->getArg(0));
 else if (E->getCastKind() == CK_UserDefinedConversion) {
   assert((isa(SubExpr) ||
   isa(SubExpr)) &&
Index: cfe/trunk/unittests/Tooling/CMakeLists.txt
===
--- cfe/trunk/unittests/Tooling/CMakeLists.txt
+++ cfe/trunk/unittests/Tooling/CMakeLists.txt
@@ -11,6 +11,7 @@
 endif()
 
 add_clang_unittest(ToolingTests
+  CastExprTest.cpp
   CommentHandlerTest.cpp
   CompilationDatabaseTest.cpp
   FixItTest.cpp
Index: cfe/trunk/unittests/Tooling/CastExprTest.cpp
===
--- cfe/trunk/unittests/Tooling/CastExprTest.cpp
+++ cfe/trunk/unittests/Tooling/CastExprTest.cpp
@@ -0,0 +1,38 @@
+//===- unittest/Tooling/CastExprTest.cpp --===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "TestVisitor.h"
+
+using namespace clang;
+
+namespace {
+
+struct CastExprVisitor : TestVisitor {
+  std::function OnExplicitCast;
+
+  bool VisitExplicitCastExpr(ExplicitCastExpr *Expr) {
+if (OnExplicitCast)
+  OnExplicitCast(Expr);
+return true;
+  }
+};
+
+TEST(CastExprTest, GetSubExprAsWrittenThroughMaterializedTemporary) {
+CastExprVisitor Visitor;
+Visitor.OnExplicitCast = [](ExplicitCastExpr *Expr) {
+  auto Sub = Expr->getSubExprAsWritten();
+  EXPECT_TRUE(isa(Sub))
+<< "Expected DeclRefExpr, but saw " << Sub->getStmtClassName();
+};
+Visitor.runOver("struct S1 {};\n"
+"struct S2 { operator S1(); };\n"
+"S1 f(S2 s) { return static_cast(s); }\n");
+}
+
+}
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r306377 - Make CastExpr::getSubExprAsWritten look through implicit temporary under CK_ConstructorConversion

2017-06-27 Thread Stephan Bergmann via cfe-commits
Author: sberg
Date: Tue Jun 27 01:19:09 2017
New Revision: 306377

URL: http://llvm.org/viewvc/llvm-project?rev=306377&view=rev
Log:
Make CastExpr::getSubExprAsWritten look through implicit temporary under 
CK_ConstructorConversion

With

struct S1 {};
struct S2 { operator S1(); };
S1 f(S2 s) { return static_cast(s); }

the static_cast expr is

CXXStaticCastExpr 0x... 'struct S1' static_cast 

`-CXXConstructExpr 0x... 'struct S1' 'void (struct S1 &&) noexcept' elidable

`-MaterializeTemporaryExpr 0x... 'struct S1' xvalue
  `-ImplicitCastExpr 0x... 'struct S1' 
`-CXXMemberCallExpr 0x... 'struct S1'
  `-MemberExpr 0x... '' .operator S1 0x...
`-DeclRefExpr 0x... 'struct S2' lvalue ParmVar 0x... 's' 'struct S2'

getSubExprAsWritten used to return the MaterializeTemporaryExpr (of type S1)
under the CXXConstructExpr, instead of unwinding further to the DeclRefExpr (of
type S2) at the bottom.

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

Added:
cfe/trunk/unittests/Tooling/CastExprTest.cpp
Modified:
cfe/trunk/lib/AST/Expr.cpp
cfe/trunk/unittests/Tooling/CMakeLists.txt

Modified: cfe/trunk/lib/AST/Expr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=306377&r1=306376&r2=306377&view=diff
==
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Tue Jun 27 01:19:09 2017
@@ -1641,25 +1641,32 @@ const char *CastExpr::getCastKindName()
   llvm_unreachable("Unhandled cast kind!");
 }
 
+namespace {
+  Expr *skipImplicitTemporary(Expr *expr) {
+// Skip through reference binding to temporary.
+if (MaterializeTemporaryExpr *Materialize
+  = dyn_cast(expr))
+  expr = Materialize->GetTemporaryExpr();
+
+// Skip any temporary bindings; they're implicit.
+if (CXXBindTemporaryExpr *Binder = dyn_cast(expr))
+  expr = Binder->getSubExpr();
+
+return expr;
+  }
+}
+
 Expr *CastExpr::getSubExprAsWritten() {
   Expr *SubExpr = nullptr;
   CastExpr *E = this;
   do {
-SubExpr = E->getSubExpr();
+SubExpr = skipImplicitTemporary(E->getSubExpr());
 
-// Skip through reference binding to temporary.
-if (MaterializeTemporaryExpr *Materialize 
-  = 
dyn_cast(SubExpr))
-  SubExpr = Materialize->GetTemporaryExpr();
-
-// Skip any temporary bindings; they're implicit.
-if (CXXBindTemporaryExpr *Binder = dyn_cast(SubExpr))
-  SubExpr = Binder->getSubExpr();
-
 // Conversions by constructor and conversion functions have a
 // subexpression describing the call; strip it off.
 if (E->getCastKind() == CK_ConstructorConversion)
-  SubExpr = cast(SubExpr)->getArg(0);
+  SubExpr =
+skipImplicitTemporary(cast(SubExpr)->getArg(0));
 else if (E->getCastKind() == CK_UserDefinedConversion) {
   assert((isa(SubExpr) ||
   isa(SubExpr)) &&

Modified: cfe/trunk/unittests/Tooling/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Tooling/CMakeLists.txt?rev=306377&r1=306376&r2=306377&view=diff
==
--- cfe/trunk/unittests/Tooling/CMakeLists.txt (original)
+++ cfe/trunk/unittests/Tooling/CMakeLists.txt Tue Jun 27 01:19:09 2017
@@ -11,6 +11,7 @@ if (MSVC)
 endif()
 
 add_clang_unittest(ToolingTests
+  CastExprTest.cpp
   CommentHandlerTest.cpp
   CompilationDatabaseTest.cpp
   FixItTest.cpp

Added: cfe/trunk/unittests/Tooling/CastExprTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Tooling/CastExprTest.cpp?rev=306377&view=auto
==
--- cfe/trunk/unittests/Tooling/CastExprTest.cpp (added)
+++ cfe/trunk/unittests/Tooling/CastExprTest.cpp Tue Jun 27 01:19:09 2017
@@ -0,0 +1,38 @@
+//===- unittest/Tooling/CastExprTest.cpp 
--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "TestVisitor.h"
+
+using namespace clang;
+
+namespace {
+
+struct CastExprVisitor : TestVisitor {
+  std::function OnExplicitCast;
+
+  bool VisitExplicitCastExpr(ExplicitCastExpr *Expr) {
+if (OnExplicitCast)
+  OnExplicitCast(Expr);
+return true;
+  }
+};
+
+TEST(CastExprTest, GetSubExprAsWrittenThroughMaterializedTemporary) {
+CastExprVisitor Visitor;
+Visitor.OnExplicitCast = [](ExplicitCastExpr *Expr) {
+  auto Sub = Expr->getSubExprAsWritten();
+  EXPECT_TRUE(isa(Sub))
+<< "Expected DeclRefExpr, but saw " << Sub->getStmtClassName();
+};
+Visitor.runOver("struct S1 {};\n"
+"struct S2 { operator S1

[clang-tools-extra] r306378 - [clang-tidy] Fix type names in modernize-use-unique/shared_ptr checks.

2017-06-27 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Tue Jun 27 01:31:27 2017
New Revision: 306378

URL: http://llvm.org/viewvc/llvm-project?rev=306378&view=rev
Log:
[clang-tidy] Fix type names in modernize-use-unique/shared_ptr checks.

Summary:
If the class being created in unique_ptr is in anonymous nampespace, the
anonymous namespace will be included in the apply-fixes. This patch fix
this.

```
namespace {
class Foo {};
}
std::unique_ptr f;
f.reset(new Foo());
// Before the change: f = std::make_unique<(annonymous namespace)::Foo>();
// After the change: f = std::make_unique();
```

Reviewers: alexfh

Reviewed By: alexfh

Subscribers: JDevlieghere, xazax.hun, cfe-commits

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

Modified:
clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/modernize-make-unique.cpp

Modified: clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.cpp?rev=306378&r1=306377&r2=306378&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.cpp Tue Jun 
27 01:31:27 2017
@@ -16,6 +16,17 @@ namespace clang {
 namespace tidy {
 namespace modernize {
 
+namespace {
+StringRef GetNewExprName(const CXXNewExpr *NewExpr,
+ const SourceManager &SM,
+ const LangOptions &Lang) {
+  return Lexer::getSourceText(
+  CharSourceRange::getTokenRange(
+  
NewExpr->getAllocatedTypeSourceInfo()->getTypeLoc().getSourceRange()),
+  SM, Lang);
+}
+} // namespace
+
 const char MakeSmartPtrCheck::PointerType[] = "pointerType";
 const char MakeSmartPtrCheck::ConstructorCall[] = "constructorCall";
 const char MakeSmartPtrCheck::ResetCall[] = "resetCall";
@@ -87,7 +98,7 @@ void MakeSmartPtrCheck::checkConstruct(S
   StringRef ExprStr = Lexer::getSourceText(
   CharSourceRange::getCharRange(
   ConstructCallStart, Construct->getParenOrBraceRange().getBegin()),
-  SM, LangOptions(), &Invalid);
+  SM, getLangOpts(), &Invalid);
   if (Invalid)
 return;
 
@@ -102,7 +113,8 @@ void MakeSmartPtrCheck::checkConstruct(S
 // we have to add it back.
 ConstructCallEnd = ConstructCallStart.getLocWithOffset(ExprStr.size());
 Diag << FixItHint::CreateInsertion(
-ConstructCallEnd, "<" + Type->getAsString(getLangOpts()) + ">");
+ConstructCallEnd,
+"<" + GetNewExprName(New, SM, getLangOpts()).str() + ">");
   } else {
 ConstructCallEnd = ConstructCallStart.getLocWithOffset(LAngle);
   }
@@ -144,7 +156,7 @@ void MakeSmartPtrCheck::checkReset(Sourc
   Diag << FixItHint::CreateReplacement(
   CharSourceRange::getCharRange(OperatorLoc, ExprEnd),
   (llvm::Twine(" = ") + makeSmartPtrFunctionName + "<" +
-   New->getAllocatedType().getAsString(getLangOpts()) + ">")
+   GetNewExprName(New, SM, getLangOpts()) + ">")
   .str());
 
   if (Expr->isArrow())

Modified: clang-tools-extra/trunk/test/clang-tidy/modernize-make-unique.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/modernize-make-unique.cpp?rev=306378&r1=306377&r2=306378&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/modernize-make-unique.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/modernize-make-unique.cpp Tue Jun 
27 01:31:27 2017
@@ -49,6 +49,14 @@ struct DPair {
 
 struct Empty {};
 
+namespace {
+class Foo {};
+} // namespace
+
+namespace bar {
+class Bar {};
+} // namespace bar
+
 template 
 using unique_ptr_ = std::unique_ptr;
 
@@ -239,6 +247,20 @@ void initialization(int T, Base b) {
   std::unique_ptr PEmpty = std::unique_ptr(new Empty{});
   // CHECK-MESSAGES: :[[@LINE-1]]:35: warning: use std::make_unique instead
   // CHECK-FIXES: std::unique_ptr PEmpty = 
std::make_unique(Empty{});
+
+  std::unique_ptr FF = std::unique_ptr(new Foo());
+  // CHECK-MESSAGES: :[[@LINE-1]]:29: warning:
+  // CHECK-FIXES: std::unique_ptr FF = std::make_unique();
+  FF.reset(new Foo());
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning:
+  // CHECK-FIXES: FF = std::make_unique();
+
+  std::unique_ptr BB = std::unique_ptr(new bar::Bar());
+  // CHECK-MESSAGES: :[[@LINE-1]]:34: warning:
+  // CHECK-FIXES: std::unique_ptr BB = std::make_unique();
+  BB.reset(new bar::Bar());
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning:
+  // CHECK-FIXES: BB = std::make_unique();
 }
 
 void aliases() {


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


[PATCH] D34286: [clang-tidy] Fix type names in modernize-use-unique/shared_ptr checks.

2017-06-27 Thread Haojian Wu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL306378: [clang-tidy] Fix type names in 
modernize-use-unique/shared_ptr checks. (authored by hokein).

Repository:
  rL LLVM

https://reviews.llvm.org/D34286

Files:
  clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.cpp
  clang-tools-extra/trunk/test/clang-tidy/modernize-make-unique.cpp


Index: clang-tools-extra/trunk/test/clang-tidy/modernize-make-unique.cpp
===
--- clang-tools-extra/trunk/test/clang-tidy/modernize-make-unique.cpp
+++ clang-tools-extra/trunk/test/clang-tidy/modernize-make-unique.cpp
@@ -49,6 +49,14 @@
 
 struct Empty {};
 
+namespace {
+class Foo {};
+} // namespace
+
+namespace bar {
+class Bar {};
+} // namespace bar
+
 template 
 using unique_ptr_ = std::unique_ptr;
 
@@ -239,6 +247,20 @@
   std::unique_ptr PEmpty = std::unique_ptr(new Empty{});
   // CHECK-MESSAGES: :[[@LINE-1]]:35: warning: use std::make_unique instead
   // CHECK-FIXES: std::unique_ptr PEmpty = 
std::make_unique(Empty{});
+
+  std::unique_ptr FF = std::unique_ptr(new Foo());
+  // CHECK-MESSAGES: :[[@LINE-1]]:29: warning:
+  // CHECK-FIXES: std::unique_ptr FF = std::make_unique();
+  FF.reset(new Foo());
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning:
+  // CHECK-FIXES: FF = std::make_unique();
+
+  std::unique_ptr BB = std::unique_ptr(new bar::Bar());
+  // CHECK-MESSAGES: :[[@LINE-1]]:34: warning:
+  // CHECK-FIXES: std::unique_ptr BB = std::make_unique();
+  BB.reset(new bar::Bar());
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning:
+  // CHECK-FIXES: BB = std::make_unique();
 }
 
 void aliases() {
Index: clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.cpp
@@ -16,6 +16,17 @@
 namespace tidy {
 namespace modernize {
 
+namespace {
+StringRef GetNewExprName(const CXXNewExpr *NewExpr,
+ const SourceManager &SM,
+ const LangOptions &Lang) {
+  return Lexer::getSourceText(
+  CharSourceRange::getTokenRange(
+  
NewExpr->getAllocatedTypeSourceInfo()->getTypeLoc().getSourceRange()),
+  SM, Lang);
+}
+} // namespace
+
 const char MakeSmartPtrCheck::PointerType[] = "pointerType";
 const char MakeSmartPtrCheck::ConstructorCall[] = "constructorCall";
 const char MakeSmartPtrCheck::ResetCall[] = "resetCall";
@@ -87,7 +98,7 @@
   StringRef ExprStr = Lexer::getSourceText(
   CharSourceRange::getCharRange(
   ConstructCallStart, Construct->getParenOrBraceRange().getBegin()),
-  SM, LangOptions(), &Invalid);
+  SM, getLangOpts(), &Invalid);
   if (Invalid)
 return;
 
@@ -102,7 +113,8 @@
 // we have to add it back.
 ConstructCallEnd = ConstructCallStart.getLocWithOffset(ExprStr.size());
 Diag << FixItHint::CreateInsertion(
-ConstructCallEnd, "<" + Type->getAsString(getLangOpts()) + ">");
+ConstructCallEnd,
+"<" + GetNewExprName(New, SM, getLangOpts()).str() + ">");
   } else {
 ConstructCallEnd = ConstructCallStart.getLocWithOffset(LAngle);
   }
@@ -144,7 +156,7 @@
   Diag << FixItHint::CreateReplacement(
   CharSourceRange::getCharRange(OperatorLoc, ExprEnd),
   (llvm::Twine(" = ") + makeSmartPtrFunctionName + "<" +
-   New->getAllocatedType().getAsString(getLangOpts()) + ">")
+   GetNewExprName(New, SM, getLangOpts()) + ">")
   .str());
 
   if (Expr->isArrow())


Index: clang-tools-extra/trunk/test/clang-tidy/modernize-make-unique.cpp
===
--- clang-tools-extra/trunk/test/clang-tidy/modernize-make-unique.cpp
+++ clang-tools-extra/trunk/test/clang-tidy/modernize-make-unique.cpp
@@ -49,6 +49,14 @@
 
 struct Empty {};
 
+namespace {
+class Foo {};
+} // namespace
+
+namespace bar {
+class Bar {};
+} // namespace bar
+
 template 
 using unique_ptr_ = std::unique_ptr;
 
@@ -239,6 +247,20 @@
   std::unique_ptr PEmpty = std::unique_ptr(new Empty{});
   // CHECK-MESSAGES: :[[@LINE-1]]:35: warning: use std::make_unique instead
   // CHECK-FIXES: std::unique_ptr PEmpty = std::make_unique(Empty{});
+
+  std::unique_ptr FF = std::unique_ptr(new Foo());
+  // CHECK-MESSAGES: :[[@LINE-1]]:29: warning:
+  // CHECK-FIXES: std::unique_ptr FF = std::make_unique();
+  FF.reset(new Foo());
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning:
+  // CHECK-FIXES: FF = std::make_unique();
+
+  std::unique_ptr BB = std::unique_ptr(new bar::Bar());
+  // CHECK-MESSAGES: :[[@LINE-1]]:34: warning:
+  // CHECK-FIXES: std::unique_ptr BB = std::make_unique();
+  BB.reset(new bar::Bar());
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning:
+  // CHECK-FIXES: BB = std::make_unique();
 }
 
 void aliases() {
Index: clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrChe

[PATCH] D34674: [clang-tidy] Handle new array expressions in modernize-make-unique check.

2017-06-27 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
Herald added subscribers: xazax.hun, JDevlieghere.

https://reviews.llvm.org/D34674

Files:
  clang-tidy/modernize/MakeSmartPtrCheck.cpp
  clang-tidy/modernize/MakeSmartPtrCheck.h
  test/clang-tidy/modernize-make-unique.cpp

Index: test/clang-tidy/modernize-make-unique.cpp
===
--- test/clang-tidy/modernize-make-unique.cpp
+++ test/clang-tidy/modernize-make-unique.cpp
@@ -18,6 +18,7 @@
   type *release();
   void reset();
   void reset(type *pt);
+  void reset(type pt);
   unique_ptr &operator=(unique_ptr &&);
   template 
   unique_ptr &operator=(unique_ptr &&);
@@ -261,6 +262,36 @@
   BB.reset(new bar::Bar());
   // CHECK-MESSAGES: :[[@LINE-1]]:6: warning:
   // CHECK-FIXES: BB = std::make_unique();
+
+  std::unique_ptr FFs;
+  FFs.reset(new Foo[5]);
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning:
+  // CHECK-FIXES: FFs = std::make_unique(5);
+  FFs.reset(new Foo[5]());
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning:
+  // CHECK-FIXES: FFs = std::make_unique(5);
+  const int Num = 1;
+  FFs.reset(new Foo[Num]);
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning:
+  // CHECK-FIXES: FFs = std::make_unique(Num);
+  int Num2 = 1;
+  FFs.reset(new Foo[Num2]);
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning:
+  // CHECK-FIXES: FFs = std::make_unique(Num2);
+
+  std::unique_ptr FI;
+  FI.reset(new int[5]);
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning:
+  // CHECK-FIXES: FI = std::make_unique(5);
+  FI.reset(new int[5]());
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning:
+  // CHECK-FIXES: FI = std::make_unique(5);
+  FI.reset(new int[Num]);
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning:
+  // CHECK-FIXES: FI = std::make_unique(Num);
+  FI.reset(new int[Num2]);
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning:
+  // CHECK-FIXES: FI = std::make_unique(Num2);
 }
 
 void aliases() {
Index: clang-tidy/modernize/MakeSmartPtrCheck.h
===
--- clang-tidy/modernize/MakeSmartPtrCheck.h
+++ clang-tidy/modernize/MakeSmartPtrCheck.h
@@ -49,7 +49,9 @@
   const QualType *Type, const CXXNewExpr *New);
   void checkReset(SourceManager &SM, const CXXMemberCallExpr *Member,
   const CXXNewExpr *New);
-  void replaceNew(DiagnosticBuilder &Diag, const CXXNewExpr *New);
+  void replaceNew(DiagnosticBuilder& Diag,
+  const CXXNewExpr* New,
+  SourceManager& SM);
 };
 
 } // namespace modernize
Index: clang-tidy/modernize/MakeSmartPtrCheck.cpp
===
--- clang-tidy/modernize/MakeSmartPtrCheck.cpp
+++ clang-tidy/modernize/MakeSmartPtrCheck.cpp
@@ -17,13 +17,17 @@
 namespace modernize {
 
 namespace {
-StringRef GetNewExprName(const CXXNewExpr *NewExpr,
- const SourceManager &SM,
- const LangOptions &Lang) {
-  return Lexer::getSourceText(
+std::string GetNewExprName(const CXXNewExpr *NewExpr,
+   const SourceManager &SM,
+   const LangOptions &Lang) {
+  StringRef WrittenName = Lexer::getSourceText(
   CharSourceRange::getTokenRange(
   NewExpr->getAllocatedTypeSourceInfo()->getTypeLoc().getSourceRange()),
   SM, Lang);
+  if (NewExpr->isArray()) {
+return WrittenName.str() + "[]";
+  }
+  return WrittenName.str();
 }
 } // namespace
 
@@ -114,7 +118,7 @@
 ConstructCallEnd = ConstructCallStart.getLocWithOffset(ExprStr.size());
 Diag << FixItHint::CreateInsertion(
 ConstructCallEnd,
-"<" + GetNewExprName(New, SM, getLangOpts()).str() + ">");
+"<" + GetNewExprName(New, SM, getLangOpts()) + ">");
   } else {
 ConstructCallEnd = ConstructCallStart.getLocWithOffset(LAngle);
   }
@@ -137,7 +141,7 @@
 ")");
   }
 
-  replaceNew(Diag, New);
+  replaceNew(Diag, New, SM);
 }
 
 void MakeSmartPtrCheck::checkReset(SourceManager &SM,
@@ -162,23 +166,50 @@
   if (Expr->isArrow())
 Diag << FixItHint::CreateInsertion(ExprStart, "*");
 
-  replaceNew(Diag, New);
+  replaceNew(Diag, New, SM);
 }
 
 void MakeSmartPtrCheck::replaceNew(DiagnosticBuilder &Diag,
-   const CXXNewExpr *New) {
+   const CXXNewExpr *New,
+   SourceManager& SM) {
   SourceLocation NewStart = New->getSourceRange().getBegin();
   SourceLocation NewEnd = New->getSourceRange().getEnd();
+
+  std::string ArraySizeExpr;
+  if (const auto* ArraySize = New->getArraySize()) {
+ArraySizeExpr = Lexer::getSourceText(CharSourceRange::getTokenRange(
+ ArraySize->getSourceRange()),
+ SM, getLangOpts())
+.str();
+  }
+
+
   switch (New->getInitializationStyle()) {
   case CXXNewExpr::NoInit: {
-Diag << FixItHint::CreateRemoval(SourceRange(NewStart, NewEnd));
+ 

[PATCH] D34449: [clang-tidy] Enable constexpr definitions in headers.

2017-06-27 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun updated this revision to Diff 104111.
xazax.hun marked 5 inline comments as done.
xazax.hun added a comment.
Herald added a subscriber: JDevlieghere.

- Updates according to the reviews.


https://reviews.llvm.org/D34449

Files:
  clang-tidy/misc/DefinitionsInHeadersCheck.cpp
  test/clang-tidy/misc-definitions-in-headers-1z.hpp


Index: test/clang-tidy/misc-definitions-in-headers-1z.hpp
===
--- /dev/null
+++ test/clang-tidy/misc-definitions-in-headers-1z.hpp
@@ -0,0 +1,13 @@
+// RUN: %check_clang_tidy %s misc-definitions-in-headers %t -- -- -std=c++1z
+
+// Inline variables should be ok.
+class CE {
+  constexpr static int i = 5;
+};
+
+inline int i = 5;
+
+constexpr int a = 1;
+
+int b = 1;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: variable 'b' defined in a header 
file; variable definitions in header files can lead to ODR violations 
[misc-definitions-in-headers]
Index: clang-tidy/misc/DefinitionsInHeadersCheck.cpp
===
--- clang-tidy/misc/DefinitionsInHeadersCheck.cpp
+++ clang-tidy/misc/DefinitionsInHeadersCheck.cpp
@@ -139,6 +139,9 @@
 // Ignore variable definition within function scope.
 if (VD->hasLocalStorage() || VD->isStaticLocal())
   return;
+// Ignore inline variables.
+if (VD->isInline())
+  return;
 
 diag(VD->getLocation(),
  "variable %0 defined in a header file; "


Index: test/clang-tidy/misc-definitions-in-headers-1z.hpp
===
--- /dev/null
+++ test/clang-tidy/misc-definitions-in-headers-1z.hpp
@@ -0,0 +1,13 @@
+// RUN: %check_clang_tidy %s misc-definitions-in-headers %t -- -- -std=c++1z
+
+// Inline variables should be ok.
+class CE {
+  constexpr static int i = 5;
+};
+
+inline int i = 5;
+
+constexpr int a = 1;
+
+int b = 1;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: variable 'b' defined in a header file; variable definitions in header files can lead to ODR violations [misc-definitions-in-headers]
Index: clang-tidy/misc/DefinitionsInHeadersCheck.cpp
===
--- clang-tidy/misc/DefinitionsInHeadersCheck.cpp
+++ clang-tidy/misc/DefinitionsInHeadersCheck.cpp
@@ -139,6 +139,9 @@
 // Ignore variable definition within function scope.
 if (VD->hasLocalStorage() || VD->isStaticLocal())
   return;
+// Ignore inline variables.
+if (VD->isInline())
+  return;
 
 diag(VD->getLocation(),
  "variable %0 defined in a header file; "
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D34674: [clang-tidy] Handle new array expressions in modernize-make-unique check.

2017-06-27 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 104113.
hokein added a comment.

Fix code style.


https://reviews.llvm.org/D34674

Files:
  clang-tidy/modernize/MakeSmartPtrCheck.cpp
  clang-tidy/modernize/MakeSmartPtrCheck.h
  test/clang-tidy/modernize-make-unique.cpp

Index: test/clang-tidy/modernize-make-unique.cpp
===
--- test/clang-tidy/modernize-make-unique.cpp
+++ test/clang-tidy/modernize-make-unique.cpp
@@ -18,6 +18,7 @@
   type *release();
   void reset();
   void reset(type *pt);
+  void reset(type pt);
   unique_ptr &operator=(unique_ptr &&);
   template 
   unique_ptr &operator=(unique_ptr &&);
@@ -261,6 +262,36 @@
   BB.reset(new bar::Bar());
   // CHECK-MESSAGES: :[[@LINE-1]]:6: warning:
   // CHECK-FIXES: BB = std::make_unique();
+
+  std::unique_ptr FFs;
+  FFs.reset(new Foo[5]);
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning:
+  // CHECK-FIXES: FFs = std::make_unique(5);
+  FFs.reset(new Foo[5]());
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning:
+  // CHECK-FIXES: FFs = std::make_unique(5);
+  const int Num = 1;
+  FFs.reset(new Foo[Num]);
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning:
+  // CHECK-FIXES: FFs = std::make_unique(Num);
+  int Num2 = 1;
+  FFs.reset(new Foo[Num2]);
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning:
+  // CHECK-FIXES: FFs = std::make_unique(Num2);
+
+  std::unique_ptr FI;
+  FI.reset(new int[5]);
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning:
+  // CHECK-FIXES: FI = std::make_unique(5);
+  FI.reset(new int[5]());
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning:
+  // CHECK-FIXES: FI = std::make_unique(5);
+  FI.reset(new int[Num]);
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning:
+  // CHECK-FIXES: FI = std::make_unique(Num);
+  FI.reset(new int[Num2]);
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning:
+  // CHECK-FIXES: FI = std::make_unique(Num2);
 }
 
 void aliases() {
Index: clang-tidy/modernize/MakeSmartPtrCheck.h
===
--- clang-tidy/modernize/MakeSmartPtrCheck.h
+++ clang-tidy/modernize/MakeSmartPtrCheck.h
@@ -49,7 +49,8 @@
   const QualType *Type, const CXXNewExpr *New);
   void checkReset(SourceManager &SM, const CXXMemberCallExpr *Member,
   const CXXNewExpr *New);
-  void replaceNew(DiagnosticBuilder &Diag, const CXXNewExpr *New);
+  void replaceNew(DiagnosticBuilder &Diag, const CXXNewExpr *New,
+  SourceManager &SM);
 };
 
 } // namespace modernize
Index: clang-tidy/modernize/MakeSmartPtrCheck.cpp
===
--- clang-tidy/modernize/MakeSmartPtrCheck.cpp
+++ clang-tidy/modernize/MakeSmartPtrCheck.cpp
@@ -17,13 +17,17 @@
 namespace modernize {
 
 namespace {
-StringRef GetNewExprName(const CXXNewExpr *NewExpr,
- const SourceManager &SM,
- const LangOptions &Lang) {
-  return Lexer::getSourceText(
+std::string GetNewExprName(const CXXNewExpr *NewExpr,
+   const SourceManager &SM,
+   const LangOptions &Lang) {
+  StringRef WrittenName = Lexer::getSourceText(
   CharSourceRange::getTokenRange(
   NewExpr->getAllocatedTypeSourceInfo()->getTypeLoc().getSourceRange()),
   SM, Lang);
+  if (NewExpr->isArray()) {
+return WrittenName.str() + "[]";
+  }
+  return WrittenName.str();
 }
 } // namespace
 
@@ -114,7 +118,7 @@
 ConstructCallEnd = ConstructCallStart.getLocWithOffset(ExprStr.size());
 Diag << FixItHint::CreateInsertion(
 ConstructCallEnd,
-"<" + GetNewExprName(New, SM, getLangOpts()).str() + ">");
+"<" + GetNewExprName(New, SM, getLangOpts()) + ">");
   } else {
 ConstructCallEnd = ConstructCallStart.getLocWithOffset(LAngle);
   }
@@ -137,7 +141,7 @@
 ")");
   }
 
-  replaceNew(Diag, New);
+  replaceNew(Diag, New, SM);
 }
 
 void MakeSmartPtrCheck::checkReset(SourceManager &SM,
@@ -162,23 +166,50 @@
   if (Expr->isArrow())
 Diag << FixItHint::CreateInsertion(ExprStart, "*");
 
-  replaceNew(Diag, New);
+  replaceNew(Diag, New, SM);
 }
 
 void MakeSmartPtrCheck::replaceNew(DiagnosticBuilder &Diag,
-   const CXXNewExpr *New) {
+   const CXXNewExpr *New,
+   SourceManager& SM) {
   SourceLocation NewStart = New->getSourceRange().getBegin();
   SourceLocation NewEnd = New->getSourceRange().getEnd();
+
+  std::string ArraySizeExpr;
+  if (const auto* ArraySize = New->getArraySize()) {
+ArraySizeExpr = Lexer::getSourceText(CharSourceRange::getTokenRange(
+ ArraySize->getSourceRange()),
+ SM, getLangOpts())
+.str();
+  }
+
+
   switch (New->getInitializationStyle()) {
   case CXXNewExpr::NoInit: {
-Diag << FixItHint::CreateRemoval(SourceRange(NewStart, NewEnd));
+if (ArrayS

Re: r306127 - [GSoC] Add support for CC1 options.

2017-06-27 Thread Vassil Vassilev via cfe-commits

On 27/06/17 07:17, Saleem Abdulrasool via cfe-commits wrote:
I think that we shouldn't be providing completion for `-cc1` options. 
 `-cc1as` options are fine as the IAS serves as a replacement for the 
traditional unix `as`.  But, the `NoDriverOption` values shouldn't be 
exposed to users.  They are internal details, with no compatibility.  
If users start using those options, it makes it harder to prevent 
command line incompatibilities.

Thanks for the feedback!

We probably should only expose the cc1 options if the user typed clang 
-cc1 -f[tab], i.e. the user already is looking for something internal or 
make sure they are noted as a cc1 arguments. On the other hand, this 
should be of great help to more advanced users.


On Fri, Jun 23, 2017 at 10:05 AM, Yuka Takahashi via cfe-commits 
mailto:cfe-commits@lists.llvm.org>> wrote:


Author: yamaguchi
Date: Fri Jun 23 12:05:50 2017
New Revision: 306127

URL: http://llvm.org/viewvc/llvm-project?rev=306127&view=rev

Log:
[GSoC] Add support for CC1 options.

Summary:
Add value completion support for options which are defined in
CC1Options.td, because we only handled options in Options.td.

Reviewers: ruiu, v.g.vassilev, teemperor

Subscribers: llvm-commits

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


Modified:
cfe/trunk/include/clang/Driver/CC1Options.td
cfe/trunk/test/Driver/autocomplete.c

Modified: cfe/trunk/include/clang/Driver/CC1Options.td
URL:

http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/CC1Options.td?rev=306127&r1=306126&r2=306127&view=diff



==
--- cfe/trunk/include/clang/Driver/CC1Options.td (original)
+++ cfe/trunk/include/clang/Driver/CC1Options.td Fri Jun 23
12:05:50 2017
@@ -158,7 +158,7 @@ def msave_temp_labels : Flag<["-"], "msa
"Note this may change .s semantics and shouldn't
generally be used "
"on compiler-generated code.">;
 def mrelocation_model : Separate<["-"], "mrelocation-model">,
-  HelpText<"The relocation model to use">;
+  HelpText<"The relocation model to use">,
Values<"static,pic,ropi,rwpi,ropi-rwpi,dynamic-no-pic">;
 def fno_math_builtin : Flag<["-"], "fno-math-builtin">,
   HelpText<"Disable implicit builtin knowledge of math functions">;
 }
@@ -229,7 +229,7 @@ def no_struct_path_tbaa : Flag<["-"], "n
 def masm_verbose : Flag<["-"], "masm-verbose">,
   HelpText<"Generate verbose assembly output">;
 def mcode_model : Separate<["-"], "mcode-model">,
-  HelpText<"The code model to use">;
+  HelpText<"The code model to use">,
Values<"small,kernel,medium,large">;
 def mdebug_pass : Separate<["-"], "mdebug-pass">,
   HelpText<"Enable additional debug output">;
 def mdisable_fp_elim : Flag<["-"], "mdisable-fp-elim">,
@@ -308,7 +308,7 @@ def fsanitize_coverage_no_prune
   HelpText<"Disable coverage pruning (i.e. instrument all
blocks/edges)">;
 def fprofile_instrument_EQ : Joined<["-"], "fprofile-instrument=">,
 HelpText<"Enable PGO instrumentation. The accepted value is
clang, llvm, "
- "or none">;
+ "or none">, Values<"none,clang,llvm">;
 def fprofile_instrument_path_EQ : Joined<["-"],
"fprofile-instrument-path=">,
 HelpText<"Generate instrumented code to collect execution
counts into "
  " (overridden by LLVM_PROFILE_FILE env var)">;
@@ -348,9 +348,9 @@ def diagnostic_serialized_file : Separat
   HelpText<"File for serializing diagnostics in a binary format">;

 def fdiagnostics_format : Separate<["-"], "fdiagnostics-format">,
-  HelpText<"Change diagnostic formatting to match IDE and command
line tools">;
+  HelpText<"Change diagnostic formatting to match IDE and command
line tools">, Values<"clang,msvc,msvc-fallback,vi">;
 def fdiagnostics_show_category : Separate<["-"],
"fdiagnostics-show-category">,
-  HelpText<"Print diagnostic category">;
+  HelpText<"Print diagnostic category">, Values<"none,id,name">;
 def fno_diagnostics_use_presumed_location : Flag<["-"],
"fno-diagnostics-use-presumed-location">,
   HelpText<"Ignore #line directives when displaying diagnostic
locations">;
 def ftabstop : Separate<["-"], "ftabstop">, MetaVarName<"">,
@@ -595,11 +595,11 @@ def fconstant_string_class : Separate<["
   MetaVarName<"">,
   HelpText<"Specify the class to use for constant Objective-C
string objects.">;
 def fobjc_arc_cxxlib_EQ : Joined<["-"], "fobjc-arc-cxxlib=">,
-  HelpText<"Objective-C++ Automatic Reference 

[PATCH] D32439: Fix for incorrect source position of dependent c'tor initializer (bug:26195)

2017-06-27 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added a comment.

Thanks! I'll recommit today.


https://reviews.llvm.org/D32439



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


r306383 - Reapply "Frontend support for Nios2 target"

2017-06-27 Thread Nikolai Bozhenov via cfe-commits
Author: n.bozhenov
Date: Tue Jun 27 02:48:24 2017
New Revision: 306383

URL: http://llvm.org/viewvc/llvm-project?rev=306383&view=rev
Log:
Reapply "Frontend support for Nios2 target"

Summary:
- Implements TargetInfo class for Nios2 target.
- Enables handling of -march and -mcpu options for Nios2 target.
- Definition of Nios2 builtin functions.

Reviewed By: craig.topper

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

Author: belickim 

Added:
cfe/trunk/include/clang/Basic/BuiltinsNios2.def
cfe/trunk/test/Driver/nios2-cpu.c   (with props)
Modified:
cfe/trunk/include/clang/Basic/TargetBuiltins.h
cfe/trunk/include/clang/module.modulemap
cfe/trunk/lib/Basic/Targets.cpp
cfe/trunk/lib/Driver/ToolChains/CommonArgs.cpp

Added: cfe/trunk/include/clang/Basic/BuiltinsNios2.def
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/BuiltinsNios2.def?rev=306383&view=auto
==
--- cfe/trunk/include/clang/Basic/BuiltinsNios2.def (added)
+++ cfe/trunk/include/clang/Basic/BuiltinsNios2.def Tue Jun 27 02:48:24 2017
@@ -0,0 +1,70 @@
+//===-- BuiltinsNios2.def - Nios2 Builtin function database *- C++ 
-*-==//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// This file defines the Nios2-specific builtin function database. Users of
+// this file must define the BUILTIN macro to make use of this information.
+//
+//===--===//
+
+// The format of this database matches clang/Basic/Builtins.def.
+
+#if defined(BUILTIN) && !defined(TARGET_BUILTIN)
+#   define TARGET_BUILTIN(ID, TYPE, ATTRS, FEATURE) BUILTIN(ID, TYPE, ATTRS)
+#endif
+
+// Nios2 R1 builtins:
+
+//int __builtin_ldbio(volatile const void *);
+BUILTIN(__builtin_ldbio, "ivDC*", "")
+//int __builtin_ldbuio(volatile const void *);
+BUILTIN(__builtin_ldbuio, "ivDC*", "")
+//int __builtin_ldhio(volatile const void *);
+BUILTIN(__builtin_ldhio, "ivDC*", "")
+//int __builtin_ldhuio(volatile const void *);
+BUILTIN(__builtin_ldhuio, "ivDC*", "")
+//int __builtin_ldwio(volatile const void *);
+BUILTIN(__builtin_ldwio, "ivDC*", "")
+//int __builtin_ldwuio(int);
+BUILTIN(__builtin_ldwuio, "ii", "")
+// int __builtin_rdctl(int);
+BUILTIN(__builtin_rdctl, "iIi", "")
+// void __builtin_wrctl(int, int);
+BUILTIN(__builtin_wrctl, "vIii", "")
+// int __builtin_rdprs(int, int);
+BUILTIN(__builtin_rdprs, "iii", "")
+//void __builtin_stbio(volatile void *, int);
+BUILTIN(__builtin_stbio, "vvD*i", "")
+//void __builtin_sthio(volatile void *, int);
+BUILTIN(__builtin_sthio, "vvD*i", "")
+//void __builtin_stwio(volatile void *, int);
+BUILTIN(__builtin_stwio, "vvD*i", "")
+//void __builtin_sync(void);
+BUILTIN(__builtin_sync, "v", "")
+// void __builtin_flushd(volatile void *);
+BUILTIN(__builtin_flushd, "vvD*", "")
+// void __builtin_flushda(volatile void *);
+BUILTIN(__builtin_flushda, "vvD*", "")
+
+// Nios2 R2 builtins:
+
+// int __builtin_wrpie(int);
+TARGET_BUILTIN(__builtin_wrpie, "ii", "", "nios2r2mandatory")
+// void __builtin_eni(int);
+TARGET_BUILTIN(__builtin_eni, "vi", "", "nios2r2mandatory")
+// int __builtin_ldex(volatile const void *);
+TARGET_BUILTIN(__builtin_ldex, "ivDC*", "", "nios2r2mandatory")
+// int __builtin_stex(volatile void *, int);
+TARGET_BUILTIN(__builtin_stex, "ivD*i", "", "nios2r2mandatory")
+// int __builtin_ldsex(volatile const void *);
+TARGET_BUILTIN(__builtin_ldsex, "ivDC*", "", "nios2r2mpx")
+// int __builtin_stsex(volatile void *, int);
+TARGET_BUILTIN(__builtin_stsex, "ivDC*i", "", "nios2r2mpx")
+
+#undef BUILTIN
+#undef TARGET_BUILTIN

Modified: cfe/trunk/include/clang/Basic/TargetBuiltins.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TargetBuiltins.h?rev=306383&r1=306382&r2=306383&view=diff
==
--- cfe/trunk/include/clang/Basic/TargetBuiltins.h (original)
+++ cfe/trunk/include/clang/Basic/TargetBuiltins.h Tue Jun 27 02:48:24 2017
@@ -150,6 +150,16 @@ namespace clang {
 };
   }
 
+  /// \brief Nios2 builtins
+  namespace Nios2 {
+  enum {
+LastTIBuiltin = clang::Builtin::FirstTSBuiltin - 1,
+#define BUILTIN(ID, TYPE, ATTRS) BI##ID,
+#include "clang/Basic/BuiltinsNios2.def"
+LastTSBuiltin
+  };
+  }
+
   /// \brief MIPS builtins
   namespace Mips {
 enum {

Modified: cfe/trunk/include/clang/module.modulemap
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/module.modulemap?rev=306383&r1=306382&r2=306383&view=diff
==
--- cfe/trunk/include/clang/module.modulemap (original)
+++ cfe/trunk/include/clang/module.modulemap Tue Jun 27 02:

[PATCH] D34506: Relax an assert in the comparison of source locations

2017-06-27 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun added a comment.

In https://reviews.llvm.org/D34506#791089, @akyrtzi wrote:

> Comparing SourceLocations from different translation units is not meaningful 
> and my concern is that treating source locations like this can very easily 
> lead to errors where by mistake the code is resolving a SourceLocation with 
> the wrong translation unit and not the translation unit that it came from.
>
> If you intend to sort source locations across translation units I think you 
> should use an abstraction that includes the source location _and_ the 
> ASTContext or ASTUnit (or something to identify the translation unit) that 
> the source location came from, and use that for sorting (by checking whether 
> the TU are the same, and if not sort appropriately with the TUs, before 
> sorting the SourceLocations).
>  That way you don't need to 'allow' comparing source locations from different 
> TUs, which IMO is a good sanity check to make sure the code did not mix-up 
> the source locations by accident.


Thank you for the suggestions! 
The use-case is to make the analyzer deterministic when reporting the 
diagnostics. Unfortunately, we are already using FullSourceLocs, and it does 
not help, because the imported AST (using the ASTImporter) has imported source 
locations that are using the same source manager as the original AST. But I 
will look into some workaround.


Repository:
  rL LLVM

https://reviews.llvm.org/D34506



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


[PATCH] D34623: [clang-format] Add a test for associative map proto buffer fields

2017-06-27 Thread Daniel Jasper via Phabricator via cfe-commits
djasper accepted this revision.
djasper added a comment.
This revision is now accepted and ready to land.

Looks good. Thank you!


https://reviews.llvm.org/D34623



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


r306384 - Revert "Revert "[NFC] Refactor DiagnosticRenderer to use FullSourceLoc""

2017-06-27 Thread Christof Douma via cfe-commits
Author: christof
Date: Tue Jun 27 02:50:38 2017
New Revision: 306384

URL: http://llvm.org/viewvc/llvm-project?rev=306384&view=rev
Log:
Revert "Revert "[NFC] Refactor DiagnosticRenderer to use FullSourceLoc""

This reverts commit r305688 meaning it reintroduces r305684. To repeat:

[NFC] Refactor DiagnosticRenderer to use FullSourceLoc

Move the DiagnosticRenderer and its dependents to using FullSourceLocs
instead of a SourceLocation and SourceManager pointer. The changeset is
rather large but entirely mechanical.

This is step one to allow DiagnosticRenderer to take either
llvm::SMLocs or clang::SourceLocations.

This breaks clang-tidy and clng-query which will be fixed in a commit
soon after.

Patch by Sanne Wouda

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

Modified:
cfe/trunk/include/clang/Basic/SourceLocation.h
cfe/trunk/include/clang/Frontend/DiagnosticRenderer.h
cfe/trunk/include/clang/Frontend/TextDiagnostic.h
cfe/trunk/lib/Basic/SourceLocation.cpp
cfe/trunk/lib/Frontend/DiagnosticRenderer.cpp
cfe/trunk/lib/Frontend/SerializedDiagnosticPrinter.cpp
cfe/trunk/lib/Frontend/TextDiagnostic.cpp
cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp
cfe/trunk/tools/libclang/CIndexDiagnostic.cpp

Modified: cfe/trunk/include/clang/Basic/SourceLocation.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/SourceLocation.h?rev=306384&r1=306383&r2=306384&view=diff
==
--- cfe/trunk/include/clang/Basic/SourceLocation.h (original)
+++ cfe/trunk/include/clang/Basic/SourceLocation.h Tue Jun 27 02:50:38 2017
@@ -262,6 +262,65 @@ public:
   bool isInvalid() const { return !isValid(); }
 };
 
+/// \brief Represents an unpacked "presumed" location which can be presented
+/// to the user.
+///
+/// A 'presumed' location can be modified by \#line and GNU line marker
+/// directives and is always the expansion point of a normal location.
+///
+/// You can get a PresumedLoc from a SourceLocation with SourceManager.
+class PresumedLoc {
+  const char *Filename;
+  unsigned Line, Col;
+  SourceLocation IncludeLoc;
+
+public:
+  PresumedLoc() : Filename(nullptr) {}
+  PresumedLoc(const char *FN, unsigned Ln, unsigned Co, SourceLocation IL)
+  : Filename(FN), Line(Ln), Col(Co), IncludeLoc(IL) {}
+
+  /// \brief Return true if this object is invalid or uninitialized.
+  ///
+  /// This occurs when created with invalid source locations or when walking
+  /// off the top of a \#include stack.
+  bool isInvalid() const { return Filename == nullptr; }
+  bool isValid() const { return Filename != nullptr; }
+
+  /// \brief Return the presumed filename of this location.
+  ///
+  /// This can be affected by \#line etc.
+  const char *getFilename() const {
+assert(isValid());
+return Filename;
+  }
+
+  /// \brief Return the presumed line number of this location.
+  ///
+  /// This can be affected by \#line etc.
+  unsigned getLine() const {
+assert(isValid());
+return Line;
+  }
+
+  /// \brief Return the presumed column number of this location.
+  ///
+  /// This cannot be affected by \#line, but is packaged here for convenience.
+  unsigned getColumn() const {
+assert(isValid());
+return Col;
+  }
+
+  /// \brief Return the presumed include location of this location.
+  ///
+  /// This can be affected by GNU linemarker directives.
+  SourceLocation getIncludeLoc() const {
+assert(isValid());
+return IncludeLoc;
+  }
+};
+
+class FileEntry;
+
 /// \brief A SourceLocation and its associated SourceManager.
 ///
 /// This is useful for argument passing to functions that expect both objects.
@@ -274,6 +333,12 @@ public:
   explicit FullSourceLoc(SourceLocation Loc, const SourceManager &SM)
 : SourceLocation(Loc), SrcMgr(&SM) {}
 
+  bool hasManager() const {
+  bool hasSrcMgr =  SrcMgr != nullptr;
+  assert(hasSrcMgr == isValid() && "FullSourceLoc has location but no 
manager");
+  return hasSrcMgr;
+  }
+
   /// \pre This FullSourceLoc has an associated SourceManager.
   const SourceManager &getManager() const {
 assert(SrcMgr && "SourceManager is NULL.");
@@ -284,6 +349,13 @@ public:
 
   FullSourceLoc getExpansionLoc() const;
   FullSourceLoc getSpellingLoc() const;
+  FullSourceLoc getFileLoc() const;
+  std::pair getImmediateExpansionRange() const;
+  PresumedLoc getPresumedLoc(bool UseLineDirectives = true) const;
+  bool isMacroArgExpansion(FullSourceLoc *StartLoc = nullptr) const;
+  FullSourceLoc getImmediateMacroCallerLoc() const;
+  std::pair getModuleImportLoc() const;
+  unsigned getFileOffset() const;
 
   unsigned getExpansionLineNumber(bool *Invalid = nullptr) const;
   unsigned getExpansionColumnNumber(bool *Invalid = nullptr) const;
@@ -293,6 +365,12 @@ public:
 
   const char *getCharacterData(bool *Invalid = nullptr) const;
 
+  unsigned getLineNumber(bool *Invalid = nullptr) const;
+  unsigned getColumnNumber(bool *Invalid = 

[PATCH] D31709: [NFC] Refactor DiagnosticRenderer to use FullSourceLoc

2017-06-27 Thread Christof Douma via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL306384: Revert "Revert "[NFC] Refactor DiagnosticRenderer to 
use FullSourceLoc"" (authored by christof).

Changed prior to commit:
  https://reviews.llvm.org/D31709?vs=101933&id=104115#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D31709

Files:
  cfe/trunk/include/clang/Basic/SourceLocation.h
  cfe/trunk/include/clang/Frontend/DiagnosticRenderer.h
  cfe/trunk/include/clang/Frontend/TextDiagnostic.h
  cfe/trunk/lib/Basic/SourceLocation.cpp
  cfe/trunk/lib/Frontend/DiagnosticRenderer.cpp
  cfe/trunk/lib/Frontend/SerializedDiagnosticPrinter.cpp
  cfe/trunk/lib/Frontend/TextDiagnostic.cpp
  cfe/trunk/lib/Frontend/TextDiagnosticPrinter.cpp
  cfe/trunk/tools/libclang/CIndexDiagnostic.cpp

Index: cfe/trunk/lib/Frontend/TextDiagnostic.cpp
===
--- cfe/trunk/lib/Frontend/TextDiagnostic.cpp
+++ cfe/trunk/lib/Frontend/TextDiagnostic.cpp
@@ -672,20 +672,16 @@
 
 TextDiagnostic::~TextDiagnostic() {}
 
-void
-TextDiagnostic::emitDiagnosticMessage(SourceLocation Loc,
-  PresumedLoc PLoc,
-  DiagnosticsEngine::Level Level,
-  StringRef Message,
-  ArrayRef Ranges,
-  const SourceManager *SM,
-  DiagOrStoredDiag D) {
+void TextDiagnostic::emitDiagnosticMessage(
+FullSourceLoc Loc, PresumedLoc PLoc, DiagnosticsEngine::Level Level,
+StringRef Message, ArrayRef Ranges,
+DiagOrStoredDiag D) {
   uint64_t StartOfLocationInfo = OS.tell();
 
   // Emit the location of this particular diagnostic.
   if (Loc.isValid())
-emitDiagnosticLoc(Loc, PLoc, Level, Ranges, *SM);
-  
+emitDiagnosticLoc(Loc, PLoc, Level, Ranges);
+
   if (DiagOpts->ShowColors)
 OS.resetColor();
   
@@ -787,17 +783,16 @@
 /// This includes extracting as much location information as is present for
 /// the diagnostic and printing it, as well as any include stack or source
 /// ranges necessary.
-void TextDiagnostic::emitDiagnosticLoc(SourceLocation Loc, PresumedLoc PLoc,
+void TextDiagnostic::emitDiagnosticLoc(FullSourceLoc Loc, PresumedLoc PLoc,
DiagnosticsEngine::Level Level,
-   ArrayRef Ranges,
-   const SourceManager &SM) {
+   ArrayRef Ranges) {
   if (PLoc.isInvalid()) {
 // At least print the file name if available:
-FileID FID = SM.getFileID(Loc);
+FileID FID = Loc.getFileID();
 if (FID.isValid()) {
-  const FileEntry* FE = SM.getFileEntryForID(FID);
+  const FileEntry *FE = Loc.getFileEntry();
   if (FE && FE->isValid()) {
-emitFilename(FE->getName(), SM);
+emitFilename(FE->getName(), Loc.getManager());
 if (FE->isInPCH())
   OS << " (in PCH)";
 OS << ": ";
@@ -813,7 +808,7 @@
   if (DiagOpts->ShowColors)
 OS.changeColor(savedColor, true);
 
-  emitFilename(PLoc.getFilename(), SM);
+  emitFilename(PLoc.getFilename(), Loc.getManager());
   switch (DiagOpts->getFormat()) {
   case DiagnosticOptions::Clang: OS << ':'  << LineNo; break;
   case DiagnosticOptions::MSVC:  OS << '('  << LineNo; break;
@@ -848,29 +843,32 @@
   }
 
   if (DiagOpts->ShowSourceRanges && !Ranges.empty()) {
-FileID CaretFileID =
-  SM.getFileID(SM.getExpansionLoc(Loc));
+FileID CaretFileID = Loc.getExpansionLoc().getFileID();
 bool PrintedRange = false;
 
 for (ArrayRef::const_iterator RI = Ranges.begin(),
  RE = Ranges.end();
  RI != RE; ++RI) {
   // Ignore invalid ranges.
   if (!RI->isValid()) continue;
 
-  SourceLocation B = SM.getExpansionLoc(RI->getBegin());
-  SourceLocation E = SM.getExpansionLoc(RI->getEnd());
+  FullSourceLoc B =
+  FullSourceLoc(RI->getBegin(), Loc.getManager()).getExpansionLoc();
+  FullSourceLoc E =
+  FullSourceLoc(RI->getEnd(), Loc.getManager()).getExpansionLoc();
 
   // If the End location and the start location are the same and are a
   // macro location, then the range was something that came from a
   // macro expansion or _Pragma.  If this is an object-like macro, the
   // best we can do is to highlight the range.  If this is a
   // function-like macro, we'd also like to highlight the arguments.
   if (B == E && RI->getEnd().isMacroID())
-E = SM.getExpansionRange(RI->getEnd()).second;
+E = FullSourceLoc(RI->getEnd(), Loc.getManager())
+.getExpansionRange()
+.second;
 
-  std::pair BInfo = SM.getDecomposedLoc(B);
-  std::pair EInfo = SM.getDecomposedLoc(E);
+  std::pair BInfo = B.getDecomposedLoc();
+  std::pair EInfo = E.getDecomposedLoc();
 
   // If the start o

[clang-tools-extra] r306385 - [NFC] Update to account for DiagnosticRenderer use of FullSourceLoc

2017-06-27 Thread Peter Smith via cfe-commits
Author: psmith
Date: Tue Jun 27 03:04:04 2017
New Revision: 306385

URL: http://llvm.org/viewvc/llvm-project?rev=306385&view=rev
Log:
[NFC] Update to account for DiagnosticRenderer use of FullSourceLoc

D31709 [NFC] Refactor DiagnosticRenderer to use FullSourceLoc was committed
in r305684 and reverted in 305688 as clang-tidy and clang-query failed to
build. This change updates the extra tools to use the new interface.

Reviewers: christof, rnk, rsmith, rovka, alexfh

Reviewed By: alexfh

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


Modified:
clang-tools-extra/trunk/clang-query/Query.cpp
clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp

Modified: clang-tools-extra/trunk/clang-query/Query.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-query/Query.cpp?rev=306385&r1=306384&r2=306385&view=diff
==
--- clang-tools-extra/trunk/clang-query/Query.cpp (original)
+++ clang-tools-extra/trunk/clang-query/Query.cpp Tue Jun 27 03:04:04 2017
@@ -97,10 +97,10 @@ bool MatchQuery::run(llvm::raw_ostream &
   if (R.isValid()) {
 TextDiagnostic TD(OS, AST->getASTContext().getLangOpts(),
   &AST->getDiagnostics().getDiagnosticOptions());
-TD.emitDiagnostic(R.getBegin(), DiagnosticsEngine::Note,
-  "\"" + BI->first + "\" binds here",
-  CharSourceRange::getTokenRange(R), None,
-  &AST->getSourceManager());
+TD.emitDiagnostic(
+FullSourceLoc(R.getBegin(), AST->getSourceManager()),
+DiagnosticsEngine::Note, "\"" + BI->first + "\" binds here",
+CharSourceRange::getTokenRange(R), None);
   }
   break;
 }

Modified: clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp?rev=306385&r1=306384&r2=306385&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp Tue Jun 
27 03:04:04 2017
@@ -36,10 +36,9 @@ public:
   : DiagnosticRenderer(LangOpts, DiagOpts), Error(Error) {}
 
 protected:
-  void emitDiagnosticMessage(SourceLocation Loc, PresumedLoc PLoc,
+  void emitDiagnosticMessage(FullSourceLoc Loc, PresumedLoc PLoc,
  DiagnosticsEngine::Level Level, StringRef Message,
  ArrayRef Ranges,
- const SourceManager *SM,
  DiagOrStoredDiag Info) override {
 // Remove check name from the message.
 // FIXME: Remove this once there's a better way to pass check names than
@@ -49,9 +48,10 @@ protected:
 if (Message.endswith(CheckNameInMessage))
   Message = Message.substr(0, Message.size() - CheckNameInMessage.size());
 
-auto TidyMessage = Loc.isValid()
-   ? tooling::DiagnosticMessage(Message, *SM, Loc)
-   : tooling::DiagnosticMessage(Message);
+auto TidyMessage =
+Loc.isValid()
+? tooling::DiagnosticMessage(Message, Loc.getManager(), Loc)
+: tooling::DiagnosticMessage(Message);
 if (Level == DiagnosticsEngine::Note) {
   Error.Notes.push_back(TidyMessage);
   return;
@@ -60,15 +60,13 @@ protected:
 Error.Message = TidyMessage;
   }
 
-  void emitDiagnosticLoc(SourceLocation Loc, PresumedLoc PLoc,
+  void emitDiagnosticLoc(FullSourceLoc Loc, PresumedLoc PLoc,
  DiagnosticsEngine::Level Level,
- ArrayRef Ranges,
- const SourceManager &SM) override {}
+ ArrayRef Ranges) override {}
 
-  void emitCodeContext(SourceLocation Loc, DiagnosticsEngine::Level Level,
+  void emitCodeContext(FullSourceLoc Loc, DiagnosticsEngine::Level Level,
SmallVectorImpl &Ranges,
-   ArrayRef Hints,
-   const SourceManager &SM) override {
+   ArrayRef Hints) override {
 assert(Loc.isValid());
 for (const auto &FixIt : Hints) {
   CharSourceRange Range = FixIt.RemoveRange;
@@ -77,7 +75,8 @@ protected:
   assert(Range.getBegin().isFileID() && Range.getEnd().isFileID() &&
  "Only file locations supported in fix-it hints.");
 
-  tooling::Replacement Replacement(SM, Range, FixIt.CodeToInsert);
+  tooling::Replacement Replacement(Loc.getManager(), Range,
+   FixIt.CodeToInsert);
   llvm::Error Err = Error.Fix[Replacement.getFilePath()].add(Replacement);
   // FIXME: better error handling (at least, don't let other replacements

[PATCH] D34513: [NFC] Update to account for DiagnosticRenderer use of FullSourceLoc

2017-06-27 Thread Peter Smith via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL306385: [NFC] Update to account for DiagnosticRenderer use 
of FullSourceLoc (authored by psmith).

Changed prior to commit:
  https://reviews.llvm.org/D34513?vs=103570&id=104116#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D34513

Files:
  clang-tools-extra/trunk/clang-query/Query.cpp
  clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp

Index: clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp
===
--- clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp
+++ clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp
@@ -36,10 +36,9 @@
   : DiagnosticRenderer(LangOpts, DiagOpts), Error(Error) {}
 
 protected:
-  void emitDiagnosticMessage(SourceLocation Loc, PresumedLoc PLoc,
+  void emitDiagnosticMessage(FullSourceLoc Loc, PresumedLoc PLoc,
  DiagnosticsEngine::Level Level, StringRef Message,
  ArrayRef Ranges,
- const SourceManager *SM,
  DiagOrStoredDiag Info) override {
 // Remove check name from the message.
 // FIXME: Remove this once there's a better way to pass check names than
@@ -49,35 +48,35 @@
 if (Message.endswith(CheckNameInMessage))
   Message = Message.substr(0, Message.size() - CheckNameInMessage.size());
 
-auto TidyMessage = Loc.isValid()
-   ? tooling::DiagnosticMessage(Message, *SM, Loc)
-   : tooling::DiagnosticMessage(Message);
+auto TidyMessage =
+Loc.isValid()
+? tooling::DiagnosticMessage(Message, Loc.getManager(), Loc)
+: tooling::DiagnosticMessage(Message);
 if (Level == DiagnosticsEngine::Note) {
   Error.Notes.push_back(TidyMessage);
   return;
 }
 assert(Error.Message.Message.empty() && "Overwriting a diagnostic message");
 Error.Message = TidyMessage;
   }
 
-  void emitDiagnosticLoc(SourceLocation Loc, PresumedLoc PLoc,
+  void emitDiagnosticLoc(FullSourceLoc Loc, PresumedLoc PLoc,
  DiagnosticsEngine::Level Level,
- ArrayRef Ranges,
- const SourceManager &SM) override {}
+ ArrayRef Ranges) override {}
 
-  void emitCodeContext(SourceLocation Loc, DiagnosticsEngine::Level Level,
+  void emitCodeContext(FullSourceLoc Loc, DiagnosticsEngine::Level Level,
SmallVectorImpl &Ranges,
-   ArrayRef Hints,
-   const SourceManager &SM) override {
+   ArrayRef Hints) override {
 assert(Loc.isValid());
 for (const auto &FixIt : Hints) {
   CharSourceRange Range = FixIt.RemoveRange;
   assert(Range.getBegin().isValid() && Range.getEnd().isValid() &&
  "Invalid range in the fix-it hint.");
   assert(Range.getBegin().isFileID() && Range.getEnd().isFileID() &&
  "Only file locations supported in fix-it hints.");
 
-  tooling::Replacement Replacement(SM, Range, FixIt.CodeToInsert);
+  tooling::Replacement Replacement(Loc.getManager(), Range,
+   FixIt.CodeToInsert);
   llvm::Error Err = Error.Fix[Replacement.getFilePath()].add(Replacement);
   // FIXME: better error handling (at least, don't let other replacements be
   // applied).
@@ -89,16 +88,13 @@
 }
   }
 
-  void emitIncludeLocation(SourceLocation Loc, PresumedLoc PLoc,
-   const SourceManager &SM) override {}
+  void emitIncludeLocation(FullSourceLoc Loc, PresumedLoc PLoc) override {}
 
-  void emitImportLocation(SourceLocation Loc, PresumedLoc PLoc,
-  StringRef ModuleName,
-  const SourceManager &SM) override {}
-
-  void emitBuildingModuleLocation(SourceLocation Loc, PresumedLoc PLoc,
-  StringRef ModuleName,
-  const SourceManager &SM) override {}
+  void emitImportLocation(FullSourceLoc Loc, PresumedLoc PLoc,
+  StringRef ModuleName) override {}
+
+  void emitBuildingModuleLocation(FullSourceLoc Loc, PresumedLoc PLoc,
+  StringRef ModuleName) override {}
 
   void endDiagnostic(DiagOrStoredDiag D,
  DiagnosticsEngine::Level Level) override {
@@ -419,11 +415,12 @@
   Errors.back());
   SmallString<100> Message;
   Info.FormatDiagnostic(Message);
-  SourceManager *Sources = nullptr;
-  if (Info.hasSourceManager())
-Sources = &Info.getSourceManager();
-  Converter.emitDiagnostic(Info.getLocation(), DiagLevel, Message,
-   Info.getRanges(), Info.getFixItHints(), Sources);
+  FullSourceLoc Loc =
+  (Info.getLocation().isInvalid())
+  ? FullSourceLoc(

r306386 - [clang-format] Add a test for associative map proto buffer fields

2017-06-27 Thread Krasimir Georgiev via cfe-commits
Author: krasimir
Date: Tue Jun 27 03:06:40 2017
New Revision: 306386

URL: http://llvm.org/viewvc/llvm-project?rev=306386&view=rev
Log:
[clang-format] Add a test for associative map proto buffer fields

Summary:
The test suite was missing a test about associative maps:
https://developers.google.com/protocol-buffers/docs/proto3#maps

Reviewers: djasper

Reviewed By: djasper

Subscribers: cfe-commits, klimek

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

Modified:
cfe/trunk/unittests/Format/FormatTestProto.cpp

Modified: cfe/trunk/unittests/Format/FormatTestProto.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestProto.cpp?rev=306386&r1=306385&r2=306386&view=diff
==
--- cfe/trunk/unittests/Format/FormatTestProto.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestProto.cpp Tue Jun 27 03:06:40 2017
@@ -61,6 +61,29 @@ TEST_F(FormatTestProto, FormatsMessages)
"  really.really.long.qualified.type.aaa.aaa.\n"
"  another_field = 2;\n"
"}");
+  verifyFormat("message SomeMessage {\n"
+   "  map projects = 1;\n"
+   "  optional map size_projects = 2;\n"
+   "  map\n"
+   "  projects = 3;\n"
+   "  map projects = 4;\n"
+   "  map\n"
+   "  projects = 5;\n"
+   "  map\n"
+   "  longlonglonglonglonglonglonglonglonglongonglon = 6;\n"
+   "  
map projects = 7;\n"
+   "  
map\n"
+   "  releleallyreallyreallyreallyreallyreallyreallylongnam 
=\n"
+   "  8;\n"
+   "  map projects = 9;\n"
+   "}");
 }
 
 TEST_F(FormatTestProto, KeywordsInOtherLanguages) {


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


[PATCH] D34623: [clang-format] Add a test for associative map proto buffer fields

2017-06-27 Thread Krasimir Georgiev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL306386: [clang-format] Add a test for associative map proto 
buffer fields (authored by krasimir).

Repository:
  rL LLVM

https://reviews.llvm.org/D34623

Files:
  cfe/trunk/unittests/Format/FormatTestProto.cpp


Index: cfe/trunk/unittests/Format/FormatTestProto.cpp
===
--- cfe/trunk/unittests/Format/FormatTestProto.cpp
+++ cfe/trunk/unittests/Format/FormatTestProto.cpp
@@ -61,6 +61,29 @@
"  really.really.long.qualified.type.aaa.aaa.\n"
"  another_field = 2;\n"
"}");
+  verifyFormat("message SomeMessage {\n"
+   "  map projects = 1;\n"
+   "  optional map size_projects = 2;\n"
+   "  map\n"
+   "  projects = 3;\n"
+   "  map projects = 4;\n"
+   "  map\n"
+   "  projects = 5;\n"
+   "  map\n"
+   "  longlonglonglonglonglonglonglonglonglongonglon = 6;\n"
+   "  
map projects = 7;\n"
+   "  
map\n"
+   "  releleallyreallyreallyreallyreallyreallyreallylongnam 
=\n"
+   "  8;\n"
+   "  map projects = 9;\n"
+   "}");
 }
 
 TEST_F(FormatTestProto, KeywordsInOtherLanguages) {


Index: cfe/trunk/unittests/Format/FormatTestProto.cpp
===
--- cfe/trunk/unittests/Format/FormatTestProto.cpp
+++ cfe/trunk/unittests/Format/FormatTestProto.cpp
@@ -61,6 +61,29 @@
"  really.really.long.qualified.type.aaa.aaa.\n"
"  another_field = 2;\n"
"}");
+  verifyFormat("message SomeMessage {\n"
+   "  map projects = 1;\n"
+   "  optional map size_projects = 2;\n"
+   "  map\n"
+   "  projects = 3;\n"
+   "  map projects = 4;\n"
+   "  map\n"
+   "  projects = 5;\n"
+   "  map\n"
+   "  longlonglonglonglonglonglonglonglonglongonglon = 6;\n"
+   "  map projects = 7;\n"
+   "  map\n"
+   "  releleallyreallyreallyreallyreallyreallyreallylongnam =\n"
+   "  8;\n"
+   "  map projects = 9;\n"
+   "}");
 }
 
 TEST_F(FormatTestProto, KeywordsInOtherLanguages) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D34102: [analyzer] Add portability package for the checkers.

2017-06-27 Thread Artem Dergachev via Phabricator via cfe-commits
NoQ added a comment.

In https://reviews.llvm.org/D34102#788138, @zaks.anna wrote:

> I think it's better to have inconsistency than having checks applicable to 
> windows in a package named portability.unix.




In https://reviews.llvm.org/D34102#788138, @zaks.anna wrote:

> If there will be checks that need to be in portability and only used for 
> unix, we could create that sub-package later on.


Sounds good to me, will commit then. Still, more reasons to have aliases or 
tags.


https://reviews.llvm.org/D34102



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


[PATCH] D34329: [GSoC] Clang AST diffing

2017-06-27 Thread Johannes Altmanninger via Phabricator via cfe-commits
johannes updated this revision to Diff 104124.

https://reviews.llvm.org/D34329

Files:
  include/clang/Tooling/ASTDiff/ASTDiff.h
  include/clang/Tooling/ASTDiff/ASTDiffInternal.h
  lib/Tooling/ASTDiff/ASTDiff.cpp
  lib/Tooling/ASTDiff/CMakeLists.txt
  lib/Tooling/CMakeLists.txt
  test/Tooling/clang-diff-basic.cpp
  tools/CMakeLists.txt
  tools/clang-diff/CMakeLists.txt
  tools/clang-diff/ClangDiff.cpp

Index: tools/clang-diff/ClangDiff.cpp
===
--- /dev/null
+++ tools/clang-diff/ClangDiff.cpp
@@ -0,0 +1,110 @@
+//===- ClangDiff.cpp - compare source files by AST nodes --*- C++ -*- -===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// This file implements a tool for syntax tree based comparison using
+// Tooling/ASTDiff.
+//
+//===--===//
+
+#include "clang/Tooling/ASTDiff/ASTDiff.h"
+#include "clang/Tooling/CommonOptionsParser.h"
+#include "clang/Tooling/Tooling.h"
+#include "llvm/Support/CommandLine.h"
+
+using namespace llvm;
+using namespace clang;
+using namespace clang::tooling;
+
+static cl::OptionCategory ClangDiffCategory("clang-diff options");
+
+static cl::opt
+DumpAST("ast-dump",
+cl::desc("Print the internal representation of the AST as JSON."),
+cl::init(false), cl::cat(ClangDiffCategory));
+
+static cl::opt NoCompilationDatabase(
+"no-compilation-database",
+cl::desc(
+"Do not attempt to load build settings from a compilation database"),
+cl::init(false), cl::cat(ClangDiffCategory));
+
+static cl::opt SourcePath(cl::Positional, cl::desc(""),
+   cl::Required,
+   cl::cat(ClangDiffCategory));
+
+static cl::opt DestinationPath(cl::Positional,
+cl::desc(""),
+cl::Optional,
+cl::cat(ClangDiffCategory));
+
+static std::unique_ptr getAST(const StringRef Filename) {
+  std::string ErrorMessage;
+  std::unique_ptr Compilations;
+  if (!NoCompilationDatabase)
+Compilations =
+CompilationDatabase::autoDetectFromSource(Filename, ErrorMessage);
+  if (!Compilations) {
+if (!NoCompilationDatabase)
+  llvm::errs()
+  << "Error while trying to load a compilation database, running "
+ "without flags.\n"
+  << ErrorMessage;
+Compilations = llvm::make_unique(
+".", std::vector());
+  }
+  std::array Files = {{Filename}};
+  ClangTool Tool(*Compilations, Files);
+  std::vector> ASTs;
+  Tool.buildASTs(ASTs);
+  if (ASTs.size() != Files.size())
+return nullptr;
+  return std::move(ASTs[0]);
+}
+
+int main(int argc, const char **argv) {
+  cl::HideUnrelatedOptions(ClangDiffCategory);
+  if (!cl::ParseCommandLineOptions(argc, argv)) {
+cl::PrintOptionValues();
+return 1;
+  }
+
+  if (DumpAST) {
+if (!DestinationPath.empty()) {
+  llvm::errs() << "Error: Please specify exactly one filename.\n";
+  return 1;
+}
+std::unique_ptr AST = getAST(SourcePath);
+if (!AST)
+  return 1;
+diff::SyntaxTree Tree(AST->getASTContext());
+Tree.printAsJson(llvm::outs());
+return 0;
+  }
+
+  if (DestinationPath.empty()) {
+llvm::errs() << "Error: Exactly two paths are required.\n";
+return 1;
+  }
+
+  std::unique_ptr Src = getAST(SourcePath);
+  std::unique_ptr Dst = getAST(DestinationPath);
+  if (!Src || !Dst)
+return 1;
+
+  diff::ComparisonOptions Options;
+  diff::SyntaxTree SrcTree(Src->getASTContext());
+  diff::SyntaxTree DstTree(Dst->getASTContext());
+  diff::ASTDiff DiffTool(SrcTree, DstTree, &Options);
+  for (const auto &Match : DiffTool.getMatches())
+DiffTool.printMatch(llvm::outs(), Match);
+  for (const auto &Change : DiffTool.getChanges())
+DiffTool.printChange(llvm::outs(), Change);
+
+  return 0;
+}
Index: tools/clang-diff/CMakeLists.txt
===
--- /dev/null
+++ tools/clang-diff/CMakeLists.txt
@@ -0,0 +1,13 @@
+set(LLVM_LINK_COMPONENTS
+  Support
+  )
+
+add_clang_executable(clang-diff
+  ClangDiff.cpp
+  )
+
+target_link_libraries(clang-diff
+  clangFrontend
+  clangTooling
+  clangToolingASTDiff
+  )
Index: tools/CMakeLists.txt
===
--- tools/CMakeLists.txt
+++ tools/CMakeLists.txt
@@ -2,6 +2,7 @@
 
 add_clang_subdirectory(diagtool)
 add_clang_subdirectory(driver)
+add_clang_subdirectory(clang-diff)
 add_clang_subdirectory(clang-format)
 add_clang_subdirectory(clang-format-vs)
 add_clang_subdirectory(clang-fuzzer)
Index: test/Tooling/clang-diff-basic.cpp

r306392 - Recommit r306103: PR26195: Set correct NestedNameSpecifierLoc for the

2017-06-27 Thread Alex Lorenz via cfe-commits
Author: arphaman
Date: Tue Jun 27 03:35:30 2017
New Revision: 306392

URL: http://llvm.org/viewvc/llvm-project?rev=306392&view=rev
Log:
Recommit r306103: PR26195: Set correct NestedNameSpecifierLoc for the
dependent initializer

This commit fixes incorrect source positions of dependent c'tor initializers
like in the following code:

template
struct Derived: MyBase::InnerIterator
{

Derived() : MyBase::InnerIterator() {} /// This line is problematic: all 
positions point to InnerIterator and nothing points to MyBase
};

Patch by Serge Preis!

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

Added:
cfe/trunk/test/Index/ctor-init-source-loc.cpp
Modified:
cfe/trunk/lib/Sema/SemaDeclCXX.cpp

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=306392&r1=306391&r2=306392&view=diff
==
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Tue Jun 27 03:35:30 2017
@@ -3778,6 +3778,15 @@ Sema::BuildMemInitializer(Decl *Construc
   if (BaseType.isNull())
 return true;
 
+  TInfo = Context.CreateTypeSourceInfo(BaseType);
+  DependentNameTypeLoc TL =
+  TInfo->getTypeLoc().castAs();
+  if (!TL.isNull()) {
+TL.setNameLoc(IdLoc);
+TL.setElaboratedKeywordLoc(SourceLocation());
+TL.setQualifierLoc(SS.getWithLocInContext(Context));
+  }
+
   R.clear();
   R.setLookupName(MemberOrBase);
 }

Added: cfe/trunk/test/Index/ctor-init-source-loc.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Index/ctor-init-source-loc.cpp?rev=306392&view=auto
==
--- cfe/trunk/test/Index/ctor-init-source-loc.cpp (added)
+++ cfe/trunk/test/Index/ctor-init-source-loc.cpp Tue Jun 27 03:35:30 2017
@@ -0,0 +1,117 @@
+// RUN: c-index-test -test-load-source all %s -fno-delayed-template-parsing | 
FileCheck %s
+template
+struct Derived:  MyBase::InnerIterator
+{
+Derived() : MyBase::InnerIterator() {}
+// CHECK:  TypeRef=MyBase:2:19 Extent=[5:17 - 5:23]
+};
+
+template
+struct Derived2:  MyBase::Deeper::InnerIterator
+{
+Derived2() : MyBase::Deeper::InnerIterator() {}
+// CHECK:  TypeRef=MyBase:9:19 Extent=[12:18 - 12:24]
+};
+
+template
+struct Templ;
+
+template
+struct Derived3:  Templ::InnerIterator
+{
+Derived3() : Templ::InnerIterator() {}
+// CHECK: TemplateRef=Templ:17:8 Extent=[22:18 - 22:23]
+// CHECK: TypeRef=MyBase:19:19 Extent=[22:24 - 22:30]
+};
+
+
+struct Outer {
+template 
+struct Inner {
+typedef Q Parm;
+};
+};
+
+template
+struct Derived4:  Outer::Inner::Parm
+{
+Derived4() : Outer::Inner::Parm() {}
+// CHECK: TypeRef=struct Outer:28:8 Extent=[38:18 - 38:23]
+// CHECK: TemplateRef=Inner:30:12 Extent=[38:25 - 38:30]
+// CHECK: TypeRef=Q:35:19 Extent=[38:31 - 38:32]
+};
+
+template
+struct Derived5:  Outer::Inner::Parm::InnerIterator
+{
+Derived5() : Outer::Inner::Parm::InnerIterator() {}
+// CHECK: TypeRef=struct Outer:28:8 Extent=[47:18 - 47:23]
+// CHECK: TemplateRef=Inner:30:12 Extent=[47:25 - 47:30]
+// CHECK: TypeRef=Q:44:19 Extent=[47:31 - 47:32]
+};
+
+template
+struct Derived6:  Outer::Inner
+{
+Derived6() : Outer::Inner() {}
+// CHECK: TypeRef=struct Outer:28:8 Extent=[56:18 - 56:23]
+// CHECK: TemplateRef=Inner:30:12 Extent=[56:25 - 56:30]
+// CHECK: TypeRef=Q:53:19 Extent=[56:31 - 56:32]
+};
+
+struct Base {};
+
+struct Derived7:  Outer::Inner::Parm
+{
+Derived7() : Outer::Inner::Parm() {}
+// CHECK: TypeRef=struct Outer:28:8 Extent=[66:18 - 66:23]
+// CHECK: TemplateRef=Inner:30:12 Extent=[66:25 - 66:30]
+// CHECK: TypeRef=struct Base:62:8 Extent=[66:31 - 66:35]
+};
+
+struct Derived8:  Outer::Inner
+{
+Derived8() : Outer::Inner() {}
+// CHECK: TypeRef=struct Outer:28:8 Extent=[74:18 - 74:23]
+// CHECK: TemplateRef=Inner:30:12 Extent=[74:25 - 74:30]
+// CHECK: TypeRef=struct Base:62:8 Extent=[74:31 - 74:35]
+};
+
+namespace Namespace {
+template struct Templ;
+
+struct Outer {
+template 
+struct Inner {
+typedef Q Parm;
+};
+};
+}
+
+template
+struct Derived9:  Namespace::Templ::InnerIterator
+{
+Derived9() : Namespace::Templ::InnerIterator() {}
+// CHECK: NamespaceRef=Namespace:80:11 Extent=[94:18 - 94:27]
+// CHECK: TemplateRef=Templ:81:33 Extent=[94:29 - 94:34]
+// CHECK: TypeRef=MyBase:91:19 Extent=[94:35 - 94:41]
+};
+
+template
+struct Derived10:  Namespace::Templ
+{
+Derived10() : Namespace::Templ() {}
+// CHECK: NamespaceRef=Namespace:80:11 Extent=[103:19 - 103:28]
+// CHECK: TemplateRef=Templ:81:33 Extent=[103:30 - 103:35]
+// CHECK: TypeRef=MyBase:100:19 Extent=[103:36 - 103:42]
+};
+
+template
+struct Derived11:  Namespace::Outer::Inner::Parm
+{
+Derived11() : Namespace::Outer::Inner::Parm() {}
+// CH

[PATCH] D32439: Fix for incorrect source position of dependent c'tor initializer (bug:26195)

2017-06-27 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added a comment.

Recommitted in r306392.


https://reviews.llvm.org/D32439



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


[PATCH] D32439: Fix for incorrect source position of dependent c'tor initializer (bug:26195)

2017-06-27 Thread NAKAMURA Takumi via Phabricator via cfe-commits
chapuni added a comment.

@Serge_Preis @arphaman Thanks!


https://reviews.llvm.org/D32439



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


[PATCH] D34030: Fix the postorder visting of the ClassTemplateSpecializationDecl nodes in the RecursiveASTVisitor.

2017-06-27 Thread Peter Siket via Phabricator via cfe-commits
MontyKutyi added a comment.

Could anybody take a look at on this please?

Thanks,
Peter


https://reviews.llvm.org/D34030



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


[PATCH] D33644: Add default values for function parameter chunks

2017-06-27 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan added a comment.

Recheck please the latest diff


https://reviews.llvm.org/D33644



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


[PATCH] D34279: Fix release_40 build with MSVC (VS 2015)

2017-06-27 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan abandoned this revision.
yvvan added a comment.

Can't reproduce an error anymore


https://reviews.llvm.org/D34279



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


r306396 - [analyzer] Move zero-size allocation checks to optin.portability.

2017-06-27 Thread Artem Dergachev via cfe-commits
Author: dergachev
Date: Tue Jun 27 04:14:39 2017
New Revision: 306396

URL: http://llvm.org/viewvc/llvm-project?rev=306396&view=rev
Log:
[analyzer] Move zero-size allocation checks to optin.portability.

This is a new checker package. It contains checkers that highlight
well-documented implementation-defined behavior. Such checkers are only useful
to developers that intend to write portable code. Code that is only compiled for
a single platform should be allowed to rely on this platform's specific
documented behavior.

rdar://problem/30545046

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

Modified:
cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td
cfe/trunk/lib/StaticAnalyzer/Checkers/UnixAPIChecker.cpp
cfe/trunk/test/Analysis/malloc-overflow2.c
cfe/trunk/test/Analysis/unix-fns.c

Modified: cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td?rev=306396&r1=306395&r2=306396&view=diff
==
--- cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td (original)
+++ cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td Tue Jun 27 
04:14:39 2017
@@ -38,6 +38,11 @@ def CoreAlpha : Package<"core">, InPacka
 // default. Such checkers belong in the alpha package.
 def OptIn : Package<"optin">;
 
+// In the Portability package reside checkers for finding code that relies on
+// implementation-defined behavior. Such checks are wanted for cross-platform
+// development, but unwanted for developers who target only a single platform.
+def PortabilityOptIn : Package<"portability">, InPackage;
+
 def Nullability : Package<"nullability">;
 
 def Cplusplus : Package<"cplusplus">;
@@ -416,7 +421,7 @@ def GenericTaintChecker : Checker<"Taint
 
 let ParentPackage = Unix in {
 
-def UnixAPIChecker : Checker<"API">,
+def UnixAPIMisuseChecker : Checker<"API">,
   HelpText<"Check calls to various UNIX/Posix functions">,
   DescFile<"UnixAPIChecker.cpp">;
 
@@ -754,3 +759,14 @@ def CloneChecker : Checker<"CloneChecker
 
 } // end "clone"
 
+//===--===//
+// Portability checkers.
+//===--===//
+
+let ParentPackage = PortabilityOptIn in {
+
+def UnixAPIPortabilityChecker : Checker<"UnixAPI">,
+  HelpText<"Finds implementation-defined behavior in UNIX/Posix functions">,
+  DescFile<"UnixAPIChecker.cpp">;
+
+} // end optin.portability

Modified: cfe/trunk/lib/StaticAnalyzer/Checkers/UnixAPIChecker.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Checkers/UnixAPIChecker.cpp?rev=306396&r1=306395&r2=306396&view=diff
==
--- cfe/trunk/lib/StaticAnalyzer/Checkers/UnixAPIChecker.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/UnixAPIChecker.cpp Tue Jun 27 
04:14:39 2017
@@ -45,6 +45,8 @@ class UnixAPIChecker : public Checker< c
   mutable Optional Val_O_CREAT;
 
 public:
+  DefaultBool CheckMisuse, CheckPortability;
+
   void checkPreStmt(const CallExpr *CE, CheckerContext &C) const;
 
   void CheckOpen(CheckerContext &C, const CallExpr *CE) const;
@@ -437,29 +439,42 @@ void UnixAPIChecker::checkPreStmt(const
   if (FName.empty())
 return;
 
-  SubChecker SC =
-llvm::StringSwitch(FName)
-  .Case("open", &UnixAPIChecker::CheckOpen)
-  .Case("openat", &UnixAPIChecker::CheckOpenAt)
-  .Case("pthread_once", &UnixAPIChecker::CheckPthreadOnce)
-  .Case("calloc", &UnixAPIChecker::CheckCallocZero)
-  .Case("malloc", &UnixAPIChecker::CheckMallocZero)
-  .Case("realloc", &UnixAPIChecker::CheckReallocZero)
-  .Case("reallocf", &UnixAPIChecker::CheckReallocfZero)
-  .Cases("alloca", "__builtin_alloca", &UnixAPIChecker::CheckAllocaZero)
-  .Case("__builtin_alloca_with_align",
-&UnixAPIChecker::CheckAllocaWithAlignZero)
-  .Case("valloc", &UnixAPIChecker::CheckVallocZero)
-  .Default(nullptr);
-
-  if (SC)
-(this->*SC)(C, CE);
+  if (CheckMisuse) {
+if (SubChecker SC =
+llvm::StringSwitch(FName)
+.Case("open", &UnixAPIChecker::CheckOpen)
+.Case("openat", &UnixAPIChecker::CheckOpenAt)
+.Case("pthread_once", &UnixAPIChecker::CheckPthreadOnce)
+.Default(nullptr)) {
+  (this->*SC)(C, CE);
+}
+  }
+  if (CheckPortability) {
+if (SubChecker SC =
+llvm::StringSwitch(FName)
+.Case("calloc", &UnixAPIChecker::CheckCallocZero)
+.Case("malloc", &UnixAPIChecker::CheckMallocZero)
+.Case("realloc", &UnixAPIChecker::CheckReallocZero)
+.Case("reallocf", &UnixAPIChecker::CheckReallocfZero)
+.Cases("alloca", "__builtin_alloca",
+   &UnixAPICh

[PATCH] D34102: [analyzer] Add portability package for the checkers.

2017-06-27 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL306396: [analyzer] Move zero-size allocation checks to 
optin.portability. (authored by dergachev).

Changed prior to commit:
  https://reviews.llvm.org/D34102?vs=102829&id=104133#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D34102

Files:
  cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td
  cfe/trunk/lib/StaticAnalyzer/Checkers/UnixAPIChecker.cpp
  cfe/trunk/test/Analysis/malloc-overflow2.c
  cfe/trunk/test/Analysis/unix-fns.c

Index: cfe/trunk/lib/StaticAnalyzer/Checkers/UnixAPIChecker.cpp
===
--- cfe/trunk/lib/StaticAnalyzer/Checkers/UnixAPIChecker.cpp
+++ cfe/trunk/lib/StaticAnalyzer/Checkers/UnixAPIChecker.cpp
@@ -45,6 +45,8 @@
   mutable Optional Val_O_CREAT;
 
 public:
+  DefaultBool CheckMisuse, CheckPortability;
+
   void checkPreStmt(const CallExpr *CE, CheckerContext &C) const;
 
   void CheckOpen(CheckerContext &C, const CallExpr *CE) const;
@@ -437,29 +439,42 @@
   if (FName.empty())
 return;
 
-  SubChecker SC =
-llvm::StringSwitch(FName)
-  .Case("open", &UnixAPIChecker::CheckOpen)
-  .Case("openat", &UnixAPIChecker::CheckOpenAt)
-  .Case("pthread_once", &UnixAPIChecker::CheckPthreadOnce)
-  .Case("calloc", &UnixAPIChecker::CheckCallocZero)
-  .Case("malloc", &UnixAPIChecker::CheckMallocZero)
-  .Case("realloc", &UnixAPIChecker::CheckReallocZero)
-  .Case("reallocf", &UnixAPIChecker::CheckReallocfZero)
-  .Cases("alloca", "__builtin_alloca", &UnixAPIChecker::CheckAllocaZero)
-  .Case("__builtin_alloca_with_align",
-&UnixAPIChecker::CheckAllocaWithAlignZero)
-  .Case("valloc", &UnixAPIChecker::CheckVallocZero)
-  .Default(nullptr);
-
-  if (SC)
-(this->*SC)(C, CE);
+  if (CheckMisuse) {
+if (SubChecker SC =
+llvm::StringSwitch(FName)
+.Case("open", &UnixAPIChecker::CheckOpen)
+.Case("openat", &UnixAPIChecker::CheckOpenAt)
+.Case("pthread_once", &UnixAPIChecker::CheckPthreadOnce)
+.Default(nullptr)) {
+  (this->*SC)(C, CE);
+}
+  }
+  if (CheckPortability) {
+if (SubChecker SC =
+llvm::StringSwitch(FName)
+.Case("calloc", &UnixAPIChecker::CheckCallocZero)
+.Case("malloc", &UnixAPIChecker::CheckMallocZero)
+.Case("realloc", &UnixAPIChecker::CheckReallocZero)
+.Case("reallocf", &UnixAPIChecker::CheckReallocfZero)
+.Cases("alloca", "__builtin_alloca",
+   &UnixAPIChecker::CheckAllocaZero)
+.Case("__builtin_alloca_with_align",
+  &UnixAPIChecker::CheckAllocaWithAlignZero)
+.Case("valloc", &UnixAPIChecker::CheckVallocZero)
+.Default(nullptr)) {
+  (this->*SC)(C, CE);
+}
+  }
 }
 
 //===--===//
 // Registration.
 //===--===//
 
-void ento::registerUnixAPIChecker(CheckerManager &mgr) {
-  mgr.registerChecker();
-}
+#define REGISTER_CHECKER(Name) \
+  void ento::registerUnixAPI##Name##Checker(CheckerManager &mgr) { \
+mgr.registerChecker()->Check##Name = true; \
+  }
+
+REGISTER_CHECKER(Misuse)
+REGISTER_CHECKER(Portability)
Index: cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td
===
--- cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td
+++ cfe/trunk/include/clang/StaticAnalyzer/Checkers/Checkers.td
@@ -38,6 +38,11 @@
 // default. Such checkers belong in the alpha package.
 def OptIn : Package<"optin">;
 
+// In the Portability package reside checkers for finding code that relies on
+// implementation-defined behavior. Such checks are wanted for cross-platform
+// development, but unwanted for developers who target only a single platform.
+def PortabilityOptIn : Package<"portability">, InPackage;
+
 def Nullability : Package<"nullability">;
 
 def Cplusplus : Package<"cplusplus">;
@@ -416,7 +421,7 @@
 
 let ParentPackage = Unix in {
 
-def UnixAPIChecker : Checker<"API">,
+def UnixAPIMisuseChecker : Checker<"API">,
   HelpText<"Check calls to various UNIX/Posix functions">,
   DescFile<"UnixAPIChecker.cpp">;
 
@@ -754,3 +759,14 @@
 
 } // end "clone"
 
+//===--===//
+// Portability checkers.
+//===--===//
+
+let ParentPackage = PortabilityOptIn in {
+
+def UnixAPIPortabilityChecker : Checker<"UnixAPI">,
+  HelpText<"Finds implementation-defined behavior in UNIX/Posix functions">,
+  DescFile<"UnixAPIChecker.cpp">;
+
+} // end optin.portability
Index: cfe/trun

[PATCH] D34680: Fix clang-cl build -fprofile-instr-use flag

2017-06-27 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan created this revision.

Reproduced while building llvm with clang-cl.
I have trained profdata file. When I tried to use it I got crash complaining of 
nullptr casted inside visitor.


https://reviews.llvm.org/D34680

Files:
  lib/CodeGen/CodeGenPGO.cpp


Index: lib/CodeGen/CodeGenPGO.cpp
===
--- lib/CodeGen/CodeGenPGO.cpp
+++ lib/CodeGen/CodeGenPGO.cpp
@@ -249,9 +249,12 @@
 
   void VisitFunctionDecl(const FunctionDecl *D) {
 // Counter tracks entry to the function body.
-uint64_t BodyCount = setCount(PGO.getRegionCount(D->getBody()));
-CountMap[D->getBody()] = BodyCount;
-Visit(D->getBody());
+auto* body = D->getBody();
+if (!body)
+  return;
+uint64_t BodyCount = setCount(PGO.getRegionCount(body));
+CountMap[body] = BodyCount;
+Visit(body);
   }
 
   // Skip lambda expressions. We visit these as FunctionDecls when we're


Index: lib/CodeGen/CodeGenPGO.cpp
===
--- lib/CodeGen/CodeGenPGO.cpp
+++ lib/CodeGen/CodeGenPGO.cpp
@@ -249,9 +249,12 @@
 
   void VisitFunctionDecl(const FunctionDecl *D) {
 // Counter tracks entry to the function body.
-uint64_t BodyCount = setCount(PGO.getRegionCount(D->getBody()));
-CountMap[D->getBody()] = BodyCount;
-Visit(D->getBody());
+auto* body = D->getBody();
+if (!body)
+  return;
+uint64_t BodyCount = setCount(PGO.getRegionCount(body));
+CountMap[body] = BodyCount;
+Visit(body);
   }
 
   // Skip lambda expressions. We visit these as FunctionDecls when we're
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D34680: clang-cl crashes with -fprofile-instr-use flag

2017-06-27 Thread Ivan Donchevskii via Phabricator via cfe-commits
yvvan added a comment.

F3487082: llvm.profdata 
Profdata which causes crash


https://reviews.llvm.org/D34680



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


[PATCH] D34329: [clang-diff] Initial implementation.

2017-06-27 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added a comment.

Just to clarify: I'm fine with adding the




Comment at: include/clang/Tooling/ASTDiff/ASTDiff.h:32
+public:
+  ASTDiff(SyntaxTree &T1, SyntaxTree &T2, ComparisonOptions *Options);
+

Can you pass-in the options by value instead of a pointer?


https://reviews.llvm.org/D34329



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


[PATCH] D34329: [clang-diff] Initial implementation.

2017-06-27 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added a comment.

Ignore the "Just to clarify: I'm fine with adding the" comment, it was from 
last week that was saved in my session and that I didn't delete.


https://reviews.llvm.org/D34329



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


[PATCH] D34588: Check for _MSC_VER before define _LIBCPP_MSVCRT

2017-06-27 Thread Ben Craig via Phabricator via cfe-commits
bcraig added a comment.

_LIBCPP_MS_CRT seems fine too.


https://reviews.llvm.org/D34588



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


[PATCH] D34329: [clang-diff] Initial implementation.

2017-06-27 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added inline comments.



Comment at: include/clang/Tooling/ASTDiff/ASTDiff.h:57
+  SyntaxTree(T *Node, const ASTContext &AST)
+  : TreeImpl(llvm::make_unique(this, Node, AST)) {}
+

If you want to use two different names then something like `SyntaxTreeImpl` is 
better imho


https://reviews.llvm.org/D34329



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


[PATCH] D34621: [clang-format] Support <>-style proto message fields

2017-06-27 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir updated this revision to Diff 104146.
krasimir added a comment.

- Rebase with master
- Updated implementation with the new tests


https://reviews.llvm.org/D34621

Files:
  lib/Format/ContinuationIndenter.cpp
  lib/Format/FormatToken.h
  lib/Format/TokenAnnotator.cpp
  lib/Format/UnwrappedLineParser.cpp
  lib/Format/UnwrappedLineParser.h
  unittests/Format/FormatTestProto.cpp

Index: unittests/Format/FormatTestProto.cpp
===
--- unittests/Format/FormatTestProto.cpp
+++ unittests/Format/FormatTestProto.cpp
@@ -207,6 +207,142 @@
"  field_c: \"OK\",\n"
"  msg_field: \n"
"};");
+
+  verifyFormat("option (MyProto.options) = {\n"
+   "  msg_field: <>\n"
+   "  field_c: \"OK\",\n"
+   "  msg_field: \n"
+   "  field_e: OK\n"
+   "  msg_field: \n"
+   "};");
+
+  verifyFormat("option (MyProto.options) = <\n"
+   "  field_a: OK\n"
+   "  field_b: \"OK\"\n"
+   "  field_c: 1\n"
+   "  field_d: 12.5\n"
+   "  field_e: OK\n"
+   ">;");
+
+  verifyFormat("option (MyProto.options) = <\n"
+   "  field_a: OK,\n"
+   "  field_b: \"OK\",\n"
+   "  field_c: 1,\n"
+   "  field_d: 12.5,\n"
+   "  field_e: OK,\n"
+   ">;");
+
+  verifyFormat("option (MyProto.options) = <\n"
+   "  field_a: \"OK\"\n"
+   "  msg_field: {field_b: OK}\n"
+   "  field_g: OK\n"
+   "  field_g: OK\n"
+   "  field_g: OK\n"
+   ">;");
+
+  verifyFormat("option (MyProto.options) = <\n"
+   "  field_a: \"OK\"\n"
+   "  msg_field<\n"
+   "field_b: OK\n"
+   "field_c: OK\n"
+   "field_d: OK\n"
+   "field_e: OK\n"
+   "field_f: OK\n"
+   "  >\n"
+   "  field_g: OK\n"
+   ">;");
+
+  verifyFormat("option (MyProto.options) = <\n"
+   "  field_a: \"OK\"\n"
+   "  msg_field<\n"
+   "field_b: OK,\n"
+   "field_c: OK,\n"
+   "field_d: OK,\n"
+   "field_e: OK,\n"
+   "field_f: OK\n"
+   "  >\n"
+   "  field_g: OK\n"
+   ">;");
+
+  verifyFormat("option (MyProto.options) = <\n"
+   "  field_a: \"OK\"\n"
+   "  msg_field: <\n"
+   "field_b: OK\n"
+   "field_c: OK\n"
+   "field_d: OK\n"
+   "field_e: OK\n"
+   "field_f: OK\n"
+   "  >\n"
+   "  field_g: OK\n"
+   ">;");
+
+  verifyFormat("option (MyProto.options) = <\n"
+   "  field_a: \"OK\"\n"
+   "  msg_field: {\n"
+   "field_b: OK\n"
+   "field_c: OK\n"
+   "field_d: OK\n"
+   "field_e: OK\n"
+   "field_f: OK\n"
+   "  }\n"
+   "  field_g: OK\n"
+   ">;");
+
+  verifyFormat("option (MyProto.options) = <\n"
+   "  field_a: \"OK\"\n"
+   "  msg_field{\n"
+   "field_b: OK\n"
+   "field_c: OK\n"
+   "field_d: OK\n"
+   "field_e: OK\n"
+   "field_f: OK\n"
+   "  }\n"
+   "  field_g: OK\n"
+   ">;");
+
+  verifyFormat("option (MyProto.options) = {\n"
+   "  field_a: \"OK\"\n"
+   "  msg_field<\n"
+   "field_b: OK\n"
+   "field_c: OK\n"
+   "field_d: OK\n"
+   "field_e: OK\n"
+   "field_f: OK\n"
+   "  >\n"
+   "  field_g: OK\n"
+   "};");
+
+  verifyFormat("option (MyProto.options) = {\n"
+   "  field_a: \"OK\"\n"
+   "  msg_field: <\n"
+   "field_b: OK\n"
+   "field_c: OK\n"
+   "field_d: OK\n"
+   "field_e: OK\n"
+   "field_f: OK\n"
+   "  >\n"
+   "  field_g: OK\n"
+   "};");
+
+  verifyFormat("option (MyProto.options) = <\n"
+   "  field_a: \"OK\"\n"
+   "  msg_field{\n"
+   "field_b: OK\n"
+   "field_c: OK\n"
+   "field_d: OK\n"
+   "msg_field<\n"
+   "  field_A: 1\n"
+   "  field_B: 2\n"
+   "  field_C: 3\n"
+   "  field_D: 4\n"
+   "  field_E: 5\n"
+   ">\n"
+   "msg_field\n"
+   "field_e: OK\n"
+   "field_f: OK\n"
+

[PATCH] D34621: [clang-format] Support <>-style proto message fields

2017-06-27 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir updated this revision to Diff 104148.
krasimir added a comment.

- Remove todo test case


https://reviews.llvm.org/D34621

Files:
  lib/Format/ContinuationIndenter.cpp
  lib/Format/FormatToken.h
  lib/Format/TokenAnnotator.cpp
  lib/Format/UnwrappedLineParser.cpp
  lib/Format/UnwrappedLineParser.h
  unittests/Format/FormatTestProto.cpp

Index: unittests/Format/FormatTestProto.cpp
===
--- unittests/Format/FormatTestProto.cpp
+++ unittests/Format/FormatTestProto.cpp
@@ -207,6 +207,142 @@
"  field_c: \"OK\",\n"
"  msg_field: \n"
"};");
+
+  verifyFormat("option (MyProto.options) = {\n"
+   "  msg_field: <>\n"
+   "  field_c: \"OK\",\n"
+   "  msg_field: \n"
+   "  field_e: OK\n"
+   "  msg_field: \n"
+   "};");
+
+  verifyFormat("option (MyProto.options) = <\n"
+   "  field_a: OK\n"
+   "  field_b: \"OK\"\n"
+   "  field_c: 1\n"
+   "  field_d: 12.5\n"
+   "  field_e: OK\n"
+   ">;");
+
+  verifyFormat("option (MyProto.options) = <\n"
+   "  field_a: OK,\n"
+   "  field_b: \"OK\",\n"
+   "  field_c: 1,\n"
+   "  field_d: 12.5,\n"
+   "  field_e: OK,\n"
+   ">;");
+
+  verifyFormat("option (MyProto.options) = <\n"
+   "  field_a: \"OK\"\n"
+   "  msg_field: {field_b: OK}\n"
+   "  field_g: OK\n"
+   "  field_g: OK\n"
+   "  field_g: OK\n"
+   ">;");
+
+  verifyFormat("option (MyProto.options) = <\n"
+   "  field_a: \"OK\"\n"
+   "  msg_field<\n"
+   "field_b: OK\n"
+   "field_c: OK\n"
+   "field_d: OK\n"
+   "field_e: OK\n"
+   "field_f: OK\n"
+   "  >\n"
+   "  field_g: OK\n"
+   ">;");
+
+  verifyFormat("option (MyProto.options) = <\n"
+   "  field_a: \"OK\"\n"
+   "  msg_field<\n"
+   "field_b: OK,\n"
+   "field_c: OK,\n"
+   "field_d: OK,\n"
+   "field_e: OK,\n"
+   "field_f: OK\n"
+   "  >\n"
+   "  field_g: OK\n"
+   ">;");
+
+  verifyFormat("option (MyProto.options) = <\n"
+   "  field_a: \"OK\"\n"
+   "  msg_field: <\n"
+   "field_b: OK\n"
+   "field_c: OK\n"
+   "field_d: OK\n"
+   "field_e: OK\n"
+   "field_f: OK\n"
+   "  >\n"
+   "  field_g: OK\n"
+   ">;");
+
+  verifyFormat("option (MyProto.options) = <\n"
+   "  field_a: \"OK\"\n"
+   "  msg_field: {\n"
+   "field_b: OK\n"
+   "field_c: OK\n"
+   "field_d: OK\n"
+   "field_e: OK\n"
+   "field_f: OK\n"
+   "  }\n"
+   "  field_g: OK\n"
+   ">;");
+
+  verifyFormat("option (MyProto.options) = <\n"
+   "  field_a: \"OK\"\n"
+   "  msg_field{\n"
+   "field_b: OK\n"
+   "field_c: OK\n"
+   "field_d: OK\n"
+   "field_e: OK\n"
+   "field_f: OK\n"
+   "  }\n"
+   "  field_g: OK\n"
+   ">;");
+
+  verifyFormat("option (MyProto.options) = {\n"
+   "  field_a: \"OK\"\n"
+   "  msg_field<\n"
+   "field_b: OK\n"
+   "field_c: OK\n"
+   "field_d: OK\n"
+   "field_e: OK\n"
+   "field_f: OK\n"
+   "  >\n"
+   "  field_g: OK\n"
+   "};");
+
+  verifyFormat("option (MyProto.options) = {\n"
+   "  field_a: \"OK\"\n"
+   "  msg_field: <\n"
+   "field_b: OK\n"
+   "field_c: OK\n"
+   "field_d: OK\n"
+   "field_e: OK\n"
+   "field_f: OK\n"
+   "  >\n"
+   "  field_g: OK\n"
+   "};");
+
+  verifyFormat("option (MyProto.options) = <\n"
+   "  field_a: \"OK\"\n"
+   "  msg_field{\n"
+   "field_b: OK\n"
+   "field_c: OK\n"
+   "field_d: OK\n"
+   "msg_field<\n"
+   "  field_A: 1\n"
+   "  field_B: 2\n"
+   "  field_C: 3\n"
+   "  field_D: 4\n"
+   "  field_E: 5\n"
+   ">\n"
+   "msg_field\n"
+   "field_e: OK\n"
+   "field_f: OK\n"
+   "  }\n"
+   "  field_g

[PATCH] D34621: [clang-format] Support <>-style proto message fields

2017-06-27 Thread Daniel Jasper via Phabricator via cfe-commits
djasper accepted this revision.
djasper added a comment.
This revision is now accepted and ready to land.

Looks good.


https://reviews.llvm.org/D34621



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


r306406 - [clang-format] Support <>-style proto message fields

2017-06-27 Thread Krasimir Georgiev via cfe-commits
Author: krasimir
Date: Tue Jun 27 06:43:07 2017
New Revision: 306406

URL: http://llvm.org/viewvc/llvm-project?rev=306406&view=rev
Log:
[clang-format] Support <>-style proto message fields

Summary:
This patch adds support for <>-style proto message fields inside proto options.
Previously these were wrongly treated as binary operators and as such were
working only by chance for a limited number of cases.

Reviewers: djasper

Reviewed By: djasper

Subscribers: cfe-commits, klimek

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

Modified:
cfe/trunk/lib/Format/ContinuationIndenter.cpp
cfe/trunk/lib/Format/FormatToken.h
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/lib/Format/UnwrappedLineParser.cpp
cfe/trunk/lib/Format/UnwrappedLineParser.h
cfe/trunk/unittests/Format/FormatTestProto.cpp

Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=306406&r1=306405&r2=306406&view=diff
==
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Tue Jun 27 06:43:07 2017
@@ -56,6 +56,8 @@ static bool startsNextParameter(const Fo
   if (Current.is(TT_CtorInitializerComma) &&
   Style.BreakConstructorInitializers == FormatStyle::BCIS_BeforeComma)
 return true;
+  if (Style.Language == FormatStyle::LK_Proto && Current.is(TT_SelectorName))
+return true;
   return Previous.is(tok::comma) && !Current.isTrailingComment() &&
  ((Previous.isNot(TT_CtorInitializerComma) ||
Style.BreakConstructorInitializers !=
@@ -499,6 +501,13 @@ void ContinuationIndenter::addTokenOnCur
   }
 }
 
+static bool lessOpensProtoMessageField(const FormatToken &LessTok,
+   const LineState &State) {
+  assert(LessTok.is(tok::less));
+  return LessTok.NestingLevel > 0 ||
+ (LessTok.Previous && LessTok.Previous->is(tok::equal));
+}
+
 unsigned ContinuationIndenter::addTokenOnNewLine(LineState &State,
  bool DryRun) {
   FormatToken &Current = *State.NextToken;
@@ -641,6 +650,9 @@ unsigned ContinuationIndenter::addTokenO
   // before the corresponding } or ].
   if (PreviousNonComment &&
   (PreviousNonComment->isOneOf(tok::l_brace, TT_ArrayInitializerLSquare) ||
+  (Style.Language == FormatStyle::LK_Proto &&
+   PreviousNonComment->is(tok::less) &&
+   lessOpensProtoMessageField(*PreviousNonComment, State)) ||
(PreviousNonComment->is(TT_TemplateString) &&
 PreviousNonComment->opensScope(
 State.Stack.back().BreakBeforeClosingBrace = true;
@@ -682,7 +694,9 @@ unsigned ContinuationIndenter::getNewLin
   if (NextNonComment->is(tok::l_brace) && NextNonComment->BlockKind == 
BK_Block)
 return Current.NestingLevel == 0 ? State.FirstIndent
  : State.Stack.back().Indent;
-  if (Current.isOneOf(tok::r_brace, tok::r_square) && State.Stack.size() > 1) {
+  if ((Current.isOneOf(tok::r_brace, tok::r_square) ||
+   (Current.is(tok::greater) && Style.Language == FormatStyle::LK_Proto)) 
&&
+  State.Stack.size() > 1) {
 if (Current.closesBlockOrBlockTypeList(Style))
   return State.Stack[State.Stack.size() - 2].NestedBlockIndent;
 if (Current.MatchingParen &&
@@ -1035,7 +1049,9 @@ void ContinuationIndenter::moveStatePast
   bool BreakBeforeParameter = false;
   unsigned NestedBlockIndent = std::max(State.Stack.back().StartOfFunctionCall,
 State.Stack.back().NestedBlockIndent);
-  if (Current.isOneOf(tok::l_brace, TT_ArrayInitializerLSquare)) {
+  if (Current.isOneOf(tok::l_brace, TT_ArrayInitializerLSquare) ||
+  (Style.Language == FormatStyle::LK_Proto && Current.is(tok::less) &&
+   lessOpensProtoMessageField(Current, State))) {
 if (Current.opensBlockOrBlockTypeList(Style)) {
   NewIndent = Style.IndentWidth +
   std::min(State.Column, State.Stack.back().NestedBlockIndent);

Modified: cfe/trunk/lib/Format/FormatToken.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/FormatToken.h?rev=306406&r1=306405&r2=306406&view=diff
==
--- cfe/trunk/lib/Format/FormatToken.h (original)
+++ cfe/trunk/lib/Format/FormatToken.h Tue Jun 27 06:43:07 2017
@@ -465,7 +465,8 @@ struct FormatToken {
 return is(TT_ArrayInitializerLSquare) ||
(is(tok::l_brace) &&
 (BlockKind == BK_Block || is(TT_DictLiteral) ||
- (!Style.Cpp11BracedListStyle && NestingLevel == 0)));
+ (!Style.Cpp11BracedListStyle && NestingLevel == 0))) ||
+   (is(tok::less) && Style.Language == FormatStyle::LK_Proto);
   }
 
   /// \brief Same as opensBlockOrBlockTypeList, but for the closing token.

Modified: cfe/trunk/lib/Format/T

[PATCH] D34621: [clang-format] Support <>-style proto message fields

2017-06-27 Thread Krasimir Georgiev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL306406: [clang-format] Support <>-style proto message fields 
(authored by krasimir).

Repository:
  rL LLVM

https://reviews.llvm.org/D34621

Files:
  cfe/trunk/lib/Format/ContinuationIndenter.cpp
  cfe/trunk/lib/Format/FormatToken.h
  cfe/trunk/lib/Format/TokenAnnotator.cpp
  cfe/trunk/lib/Format/UnwrappedLineParser.cpp
  cfe/trunk/lib/Format/UnwrappedLineParser.h
  cfe/trunk/unittests/Format/FormatTestProto.cpp

Index: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
===
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp
@@ -1176,9 +1176,11 @@
   }
 
   nextToken();
-  if (FormatTok->Tok.is(tok::l_brace)) {
+  if (FormatTok->Tok.is(tok::l_brace))
 parseBracedList();
-  }
+  else if (Style.Language == FormatStyle::LK_Proto &&
+   FormatTok->Tok.is(tok::less))
+parseBracedList(/*ClosingBraceKind=*/tok::greater);
   break;
 case tok::l_square:
   parseSquare();
@@ -1346,7 +1348,8 @@
   return true;
 }
 
-bool UnwrappedLineParser::parseBracedList(bool ContinueOnSemicolons) {
+bool UnwrappedLineParser::parseBracedList(bool ContinueOnSemicolons,
+  tok::TokenKind ClosingBraceKind) {
   bool HasError = false;
   nextToken();
 
@@ -1375,6 +1378,10 @@
 parseChildBlock();
   }
 }
+if (FormatTok->Tok.getKind() == ClosingBraceKind) {
+  nextToken();
+  return !HasError;
+}
 switch (FormatTok->Tok.getKind()) {
 case tok::caret:
   nextToken();
@@ -1401,9 +1408,6 @@
   FormatTok->BlockKind = BK_BracedInit;
   parseBracedList();
   break;
-case tok::r_brace:
-  nextToken();
-  return !HasError;
 case tok::semi:
   // JavaScript (or more precisely TypeScript) can have semicolons in braced
   // lists (in so-called TypeMemberLists). Thus, the semicolon cannot be
Index: cfe/trunk/lib/Format/TokenAnnotator.cpp
===
--- cfe/trunk/lib/Format/TokenAnnotator.cpp
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp
@@ -89,7 +89,8 @@
 continue;
   }
   if (CurrentToken->isOneOf(tok::r_paren, tok::r_square, tok::r_brace) ||
-  (CurrentToken->isOneOf(tok::colon, tok::question) && InExprContext))
+  (CurrentToken->isOneOf(tok::colon, tok::question) && InExprContext &&
+   Style.Language != FormatStyle::LK_Proto))
 return false;
   // If a && or || is found and interpreted as a binary operator, this set
   // of angles is likely part of something like "a < b && c > d". If the
@@ -103,6 +104,14 @@
   !Line.startsWith(tok::kw_template))
 return false;
   updateParameterCount(Left, CurrentToken);
+  if (Style.Language == FormatStyle::LK_Proto) {
+if (FormatToken *Previous = CurrentToken->getPreviousNonComment()) {
+  if (CurrentToken->is(tok::colon) ||
+  (CurrentToken->isOneOf(tok::l_brace, tok::less) &&
+   Previous->isNot(tok::colon)))
+Previous->Type = TT_SelectorName;
+}
+  }
   if (!consumeToken())
 return false;
 }
@@ -440,7 +449,7 @@
 if (CurrentToken->isOneOf(tok::r_paren, tok::r_square))
   return false;
 updateParameterCount(Left, CurrentToken);
-if (CurrentToken->isOneOf(tok::colon, tok::l_brace)) {
+if (CurrentToken->isOneOf(tok::colon, tok::l_brace, tok::less)) {
   FormatToken *Previous = CurrentToken->getPreviousNonComment();
   if (((CurrentToken->is(tok::colon) &&
 (!Contexts.back().ColonIsDictLiteral || !Style.isCpp())) ||
@@ -2549,10 +2558,16 @@
 // deliberate choice and might have aligned the contents of the string
 // literal accordingly. Thus, we try keep existing line breaks.
 return Right.NewlinesBefore > 0;
-  if (Right.Previous->is(tok::l_brace) && Right.NestingLevel == 1 &&
-  Style.Language == FormatStyle::LK_Proto)
-// Don't put enums onto single lines in protocol buffers.
+  if ((Right.Previous->is(tok::l_brace) ||
+   (Right.Previous->is(tok::less) &&
+Right.Previous->Previous &&
+Right.Previous->Previous->is(tok::equal))
+) &&
+  Right.NestingLevel == 1 && Style.Language == FormatStyle::LK_Proto) {
+// Don't put enums or option definitions onto single lines in protocol
+// buffers.
 return true;
+  }
   if (Right.is(TT_InlineASMBrace))
 return Right.HasUnescapedNewline;
   if (isAllmanBrace(Left) || isAllmanBrace(Right))
Index: cfe/trunk/lib/Format/ContinuationIndenter.cpp
===
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp
@@ -56,6 +56,8 @@
   if (Current.is(TT_Ct

r306408 - [clang-format] Fix a buildbot failure after r306406

2017-06-27 Thread Krasimir Georgiev via cfe-commits
Author: krasimir
Date: Tue Jun 27 06:58:41 2017
New Revision: 306408

URL: http://llvm.org/viewvc/llvm-project?rev=306408&view=rev
Log:
[clang-format] Fix a buildbot failure after r306406

Modified:
cfe/trunk/lib/Format/UnwrappedLineParser.cpp

Modified: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.cpp?rev=306408&r1=306407&r2=306408&view=diff
==
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Tue Jun 27 06:58:41 2017
@@ -1180,7 +1180,8 @@ void UnwrappedLineParser::parseStructura
 parseBracedList();
   else if (Style.Language == FormatStyle::LK_Proto &&
FormatTok->Tok.is(tok::less))
-parseBracedList(/*ClosingBraceKind=*/tok::greater);
+parseBracedList(/*ContinueOnSemicolons=*/false,
+/*ClosingBraceKind=*/tok::greater);
   break;
 case tok::l_square:
   parseSquare();


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


[PATCH] D34674: [clang-tidy] Handle new array expressions in modernize-make-unique check.

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

LG


https://reviews.llvm.org/D34674



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


r306409 - [clang-format] Fix a clang-tidy warning, NFC

2017-06-27 Thread Krasimir Georgiev via cfe-commits
Author: krasimir
Date: Tue Jun 27 07:07:45 2017
New Revision: 306409

URL: http://llvm.org/viewvc/llvm-project?rev=306409&view=rev
Log:
[clang-format] Fix a clang-tidy warning, NFC

Modified:
cfe/trunk/lib/Format/NamespaceEndCommentsFixer.cpp

Modified: cfe/trunk/lib/Format/NamespaceEndCommentsFixer.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/NamespaceEndCommentsFixer.cpp?rev=306409&r1=306408&r2=306409&view=diff
==
--- cfe/trunk/lib/Format/NamespaceEndCommentsFixer.cpp (original)
+++ cfe/trunk/lib/Format/NamespaceEndCommentsFixer.cpp Tue Jun 27 07:07:45 2017
@@ -174,7 +174,7 @@ tooling::Replacements NamespaceEndCommen
 AllNamespaceNames = "::" + NamespaceName + AllNamespaceNames;
 continue;
   }
-  NamespaceName += std::move(AllNamespaceNames);
+  NamespaceName += AllNamespaceNames;
   CompactedNamespacesCount = 0;
   AllNamespaceNames = std::string();
 }


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


[PATCH] D34686: [AArch64] Add hasFP16VectorArithmetic helper function. NFCI

2017-06-27 Thread Sjoerd Meijer via Phabricator via cfe-commits
SjoerdMeijer created this revision.
Herald added subscribers: kristof.beyls, aemerson.

This is a clean-up for different ARMV8-A architecture kinds. Helper function 
hasFP16VectorArithmetic makes things a bit more “scalable” if we want to add 
ARMv8.3 at some point.


https://reviews.llvm.org/D34686

Files:
  lib/Basic/Targets.cpp


Index: lib/Basic/Targets.cpp
===
--- lib/Basic/Targets.cpp
+++ lib/Basic/Targets.cpp
@@ -6186,9 +6186,8 @@
   unsigned CRC;
   unsigned Crypto;
   unsigned Unaligned;
-  unsigned V8_1A;
-  unsigned V8_2A;
   unsigned HasFullFP16;
+  unsigned ArchKind;
 
   static const Builtin::Info BuiltinInfo[];
 
@@ -6254,6 +6253,18 @@
static_cast(llvm::AArch64::ArchKind::AK_INVALID);
   }
 
+  bool hasFP16VectorArithmetic() const {
+if (FPU != NeonMode || !HasFullFP16)
+  return false;
+
+switch(ArchKind) {
+default:
+  return false;
+case llvm::ARM::AK_ARMV8_2A:
+  return true;
+}
+  }
+
   void getTargetDefines(const LangOptions &Opts,
 MacroBuilder &Builder) const override {
 // Target identification.
@@ -6318,9 +6329,10 @@
 if (Unaligned)
   Builder.defineMacro("__ARM_FEATURE_UNALIGNED", "1");
 
-if (V8_1A)
+if (ArchKind == llvm::ARM::AK_ARMV8_1A)
   Builder.defineMacro("__ARM_FEATURE_QRDMX", "1");
-if (V8_2A && FPU == NeonMode && HasFullFP16)
+
+if (hasFP16VectorArithmetic())
   Builder.defineMacro("__ARM_FEATURE_FP16_VECTOR_ARITHMETIC", "1");
 
 // All of the __sync_(bool|val)_compare_and_swap_(1|2|4|8) builtins work.
@@ -6348,9 +6360,8 @@
 CRC = 0;
 Crypto = 0;
 Unaligned = 1;
-V8_1A = 0;
-V8_2A = 0;
 HasFullFP16 = 0;
+ArchKind = llvm::ARM::AK_INVALID;
 
 for (const auto &Feature : Features) {
   if (Feature == "+neon")
@@ -6362,9 +6373,9 @@
   if (Feature == "+strict-align")
 Unaligned = 0;
   if (Feature == "+v8.1a")
-V8_1A = 1;
+ArchKind = llvm::ARM::AK_ARMV8_1A;
   if (Feature == "+v8.2a")
-V8_2A = 1;
+ArchKind = llvm::ARM::AK_ARMV8_2A;
   if (Feature == "+fullfp16")
 HasFullFP16 = 1;
 }


Index: lib/Basic/Targets.cpp
===
--- lib/Basic/Targets.cpp
+++ lib/Basic/Targets.cpp
@@ -6186,9 +6186,8 @@
   unsigned CRC;
   unsigned Crypto;
   unsigned Unaligned;
-  unsigned V8_1A;
-  unsigned V8_2A;
   unsigned HasFullFP16;
+  unsigned ArchKind;
 
   static const Builtin::Info BuiltinInfo[];
 
@@ -6254,6 +6253,18 @@
static_cast(llvm::AArch64::ArchKind::AK_INVALID);
   }
 
+  bool hasFP16VectorArithmetic() const {
+if (FPU != NeonMode || !HasFullFP16)
+  return false;
+
+switch(ArchKind) {
+default:
+  return false;
+case llvm::ARM::AK_ARMV8_2A:
+  return true;
+}
+  }
+
   void getTargetDefines(const LangOptions &Opts,
 MacroBuilder &Builder) const override {
 // Target identification.
@@ -6318,9 +6329,10 @@
 if (Unaligned)
   Builder.defineMacro("__ARM_FEATURE_UNALIGNED", "1");
 
-if (V8_1A)
+if (ArchKind == llvm::ARM::AK_ARMV8_1A)
   Builder.defineMacro("__ARM_FEATURE_QRDMX", "1");
-if (V8_2A && FPU == NeonMode && HasFullFP16)
+
+if (hasFP16VectorArithmetic())
   Builder.defineMacro("__ARM_FEATURE_FP16_VECTOR_ARITHMETIC", "1");
 
 // All of the __sync_(bool|val)_compare_and_swap_(1|2|4|8) builtins work.
@@ -6348,9 +6360,8 @@
 CRC = 0;
 Crypto = 0;
 Unaligned = 1;
-V8_1A = 0;
-V8_2A = 0;
 HasFullFP16 = 0;
+ArchKind = llvm::ARM::AK_INVALID;
 
 for (const auto &Feature : Features) {
   if (Feature == "+neon")
@@ -6362,9 +6373,9 @@
   if (Feature == "+strict-align")
 Unaligned = 0;
   if (Feature == "+v8.1a")
-V8_1A = 1;
+ArchKind = llvm::ARM::AK_ARMV8_1A;
   if (Feature == "+v8.2a")
-V8_2A = 1;
+ArchKind = llvm::ARM::AK_ARMV8_2A;
   if (Feature == "+fullfp16")
 HasFullFP16 = 1;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D34687: [Tooling] CompilationDatabase should be able to strip position arguments when `-fsyntax-only` is used

2017-06-27 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman created this revision.

Right now, Clang fails to create a fixed compilation database when the 
compilation arguments use `-fsyntax-only` instead of `-c`. The reported error 
is: "warning: no compile jobs found". This happens because we don't look at the 
compilation job when stripping the positional arguments.


Repository:
  rL LLVM

https://reviews.llvm.org/D34687

Files:
  lib/Tooling/CompilationDatabase.cpp
  unittests/Tooling/CompilationDatabaseTest.cpp


Index: unittests/Tooling/CompilationDatabaseTest.cpp
===
--- unittests/Tooling/CompilationDatabaseTest.cpp
+++ unittests/Tooling/CompilationDatabaseTest.cpp
@@ -586,6 +586,27 @@
   EXPECT_EQ(2, Argc);
 }
 
+TEST(ParseFixedCompilationDatabase, HandlesPositionalArgsSyntaxOnly) {
+  // Adjust the given command line arguments to ensure that any positional
+  // arguments in them are stripped.
+  const char *Argv[] = {"--", "somefile.cpp", "-fsyntax-only", "-DDEF3"};
+  int Argc = llvm::array_lengthof(Argv);
+  std::string ErrorMessage;
+  std::unique_ptr Database =
+  FixedCompilationDatabase::loadFromCommandLine(Argc, Argv, ErrorMessage);
+  ASSERT_TRUE((bool)Database);
+  ASSERT_TRUE(ErrorMessage.empty());
+  std::vector Result = Database->getCompileCommands("source");
+  ASSERT_EQ(1ul, Result.size());
+  ASSERT_EQ(".", Result[0].Directory);
+  std::vector Expected;
+  Expected.push_back("clang-tool");
+  Expected.push_back("-fsyntax-only");
+  Expected.push_back("-DDEF3");
+  Expected.push_back("source");
+  ASSERT_EQ(Expected, Result[0].CommandLine);
+}
+
 TEST(ParseFixedCompilationDatabase, HandlesArgv0) {
   const char *Argv[] = {"1", "2", "--", "mytool", "somefile.cpp"};
   int Argc = sizeof(Argv) / sizeof(char*);
Index: lib/Tooling/CompilationDatabase.cpp
===
--- lib/Tooling/CompilationDatabase.cpp
+++ lib/Tooling/CompilationDatabase.cpp
@@ -255,10 +255,12 @@
   CompileJobAnalyzer CompileAnalyzer;
 
   for (const auto &Cmd : Jobs) {
-// Collect only for Assemble jobs. If we do all jobs we get duplicates
-// since Link jobs point to Assemble jobs as inputs.
-if (Cmd.getSource().getKind() == driver::Action::AssembleJobClass)
+// Collect only for Assemble and Compile jobs. If we do all jobs we get
+// duplicates since Link jobs point to Assemble jobs as inputs.
+if (Cmd.getSource().getKind() == driver::Action::AssembleJobClass ||
+Cmd.getSource().getKind() == driver::Action::CompileJobClass) {
   CompileAnalyzer.run(&Cmd.getSource());
+}
   }
 
   if (CompileAnalyzer.Inputs.empty()) {


Index: unittests/Tooling/CompilationDatabaseTest.cpp
===
--- unittests/Tooling/CompilationDatabaseTest.cpp
+++ unittests/Tooling/CompilationDatabaseTest.cpp
@@ -586,6 +586,27 @@
   EXPECT_EQ(2, Argc);
 }
 
+TEST(ParseFixedCompilationDatabase, HandlesPositionalArgsSyntaxOnly) {
+  // Adjust the given command line arguments to ensure that any positional
+  // arguments in them are stripped.
+  const char *Argv[] = {"--", "somefile.cpp", "-fsyntax-only", "-DDEF3"};
+  int Argc = llvm::array_lengthof(Argv);
+  std::string ErrorMessage;
+  std::unique_ptr Database =
+  FixedCompilationDatabase::loadFromCommandLine(Argc, Argv, ErrorMessage);
+  ASSERT_TRUE((bool)Database);
+  ASSERT_TRUE(ErrorMessage.empty());
+  std::vector Result = Database->getCompileCommands("source");
+  ASSERT_EQ(1ul, Result.size());
+  ASSERT_EQ(".", Result[0].Directory);
+  std::vector Expected;
+  Expected.push_back("clang-tool");
+  Expected.push_back("-fsyntax-only");
+  Expected.push_back("-DDEF3");
+  Expected.push_back("source");
+  ASSERT_EQ(Expected, Result[0].CommandLine);
+}
+
 TEST(ParseFixedCompilationDatabase, HandlesArgv0) {
   const char *Argv[] = {"1", "2", "--", "mytool", "somefile.cpp"};
   int Argc = sizeof(Argv) / sizeof(char*);
Index: lib/Tooling/CompilationDatabase.cpp
===
--- lib/Tooling/CompilationDatabase.cpp
+++ lib/Tooling/CompilationDatabase.cpp
@@ -255,10 +255,12 @@
   CompileJobAnalyzer CompileAnalyzer;
 
   for (const auto &Cmd : Jobs) {
-// Collect only for Assemble jobs. If we do all jobs we get duplicates
-// since Link jobs point to Assemble jobs as inputs.
-if (Cmd.getSource().getKind() == driver::Action::AssembleJobClass)
+// Collect only for Assemble and Compile jobs. If we do all jobs we get
+// duplicates since Link jobs point to Assemble jobs as inputs.
+if (Cmd.getSource().getKind() == driver::Action::AssembleJobClass ||
+Cmd.getSource().getKind() == driver::Action::CompileJobClass) {
   CompileAnalyzer.run(&Cmd.getSource());
+}
   }
 
   if (CompileAnalyzer.Inputs.empty()) {
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailma

[PATCH] D34506: Factor out a functionality from `isBeforeInTranslationUnit`

2017-06-27 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun updated this revision to Diff 104167.
xazax.hun retitled this revision from "Relax an assert in the comparison of 
source locations" to "Factor out a functionality from 
`isBeforeInTranslationUnit`".
xazax.hun edited the summary of this revision.
xazax.hun added a comment.

- New approach to solve the original problem


https://reviews.llvm.org/D34506

Files:
  include/clang/Basic/SourceManager.h
  lib/Basic/SourceManager.cpp

Index: lib/Basic/SourceManager.cpp
===
--- lib/Basic/SourceManager.cpp
+++ lib/Basic/SourceManager.cpp
@@ -2055,19 +2055,64 @@
   if (LOffs.first == ROffs.first)
 return LOffs.second < ROffs.second;
 
+  std::pair InSameTU = isInTheSameTranslationUnit(LOffs, ROffs);
+  if (InSameTU.first)
+return InSameTU.second;
+
+  // If we arrived here, the location is either in a built-ins buffer or
+  // associated with global inline asm. PR5662 and PR22576 are examples.
+
+  StringRef LB = getBuffer(LOffs.first)->getBufferIdentifier();
+  StringRef RB = getBuffer(ROffs.first)->getBufferIdentifier();
+  bool LIsBuiltins = LB == "";
+  bool RIsBuiltins = RB == "";
+  // Sort built-in before non-built-in.
+  if (LIsBuiltins || RIsBuiltins) {
+if (LIsBuiltins != RIsBuiltins)
+  return LIsBuiltins;
+// Both are in built-in buffers, but from different files. We just claim that
+// lower IDs come first.
+return LOffs.first < ROffs.first;
+  }
+  bool LIsAsm = LB == "";
+  bool RIsAsm = RB == "";
+  // Sort assembler after built-ins, but before the rest.
+  if (LIsAsm || RIsAsm) {
+if (LIsAsm != RIsAsm)
+  return RIsAsm;
+assert(LOffs.first == ROffs.first);
+return false;
+  }
+  bool LIsScratch = LB == "";
+  bool RIsScratch = RB == "";
+  // Sort scratch after inline asm, but before the rest.
+  if (LIsScratch || RIsScratch) {
+if (LIsScratch != RIsScratch)
+  return LIsScratch;
+return LOffs.second < ROffs.second;
+  }
+  // Source locations from different translation units.
+  llvm_unreachable("Unsortable locations found");
+}
+
+std::pair SourceManager::isInTheSameTranslationUnit(
+std::pair &LOffs,
+std::pair &ROffs) const {
   // If we are comparing a source location with multiple locations in the same
   // file, we get a big win by caching the result.
   InBeforeInTUCacheEntry &IsBeforeInTUCache =
-getInBeforeInTUCache(LOffs.first, ROffs.first);
+  getInBeforeInTUCache(LOffs.first, ROffs.first);
 
   // If we are comparing a source location with multiple locations in the same
   // file, we get a big win by caching the result.
   if (IsBeforeInTUCache.isCacheValid(LOffs.first, ROffs.first))
-return IsBeforeInTUCache.getCachedResult(LOffs.second, ROffs.second);
+return std::make_pair(
+true, IsBeforeInTUCache.getCachedResult(LOffs.second, ROffs.second));
 
   // Okay, we missed in the cache, start updating the cache for this query.
   IsBeforeInTUCache.setQueryFIDs(LOffs.first, ROffs.first,
-  /*isLFIDBeforeRFID=*/LOffs.first.ID < ROffs.first.ID);
+ /*isLFIDBeforeRFID=*/LOffs.first.ID <
+ ROffs.first.ID);
 
   // We need to find the common ancestor. The only way of doing this is to
   // build the complete include chain for one and then walking up the chain
@@ -2082,7 +2127,7 @@
 // quit early. The other way round unfortunately remains suboptimal.
   } while (LOffs.first != ROffs.first && !MoveUpIncludeHierarchy(LOffs, *this));
   LocSet::iterator I;
-  while((I = LChain.find(ROffs.first)) == LChain.end()) {
+  while ((I = LChain.find(ROffs.first)) == LChain.end()) {
 if (MoveUpIncludeHierarchy(ROffs, *this))
   break; // Met at topmost file.
   }
@@ -2093,44 +2138,12 @@
   // locations within the common file and cache them.
   if (LOffs.first == ROffs.first) {
 IsBeforeInTUCache.setCommonLoc(LOffs.first, LOffs.second, ROffs.second);
-return IsBeforeInTUCache.getCachedResult(LOffs.second, ROffs.second);
+return std::make_pair(
+true, IsBeforeInTUCache.getCachedResult(LOffs.second, ROffs.second));
   }
-
-  // If we arrived here, the location is either in a built-ins buffer or
-  // associated with global inline asm. PR5662 and PR22576 are examples.
-
   // Clear the lookup cache, it depends on a common location.
   IsBeforeInTUCache.clear();
-  StringRef LB = getBuffer(LOffs.first)->getBufferIdentifier();
-  StringRef RB = getBuffer(ROffs.first)->getBufferIdentifier();
-  bool LIsBuiltins = LB == "";
-  bool RIsBuiltins = RB == "";
-  // Sort built-in before non-built-in.
-  if (LIsBuiltins || RIsBuiltins) {
-if (LIsBuiltins != RIsBuiltins)
-  return LIsBuiltins;
-// Both are in built-in buffers, but from different files. We just claim that
-// lower IDs come first.
-return LOffs.first < ROffs.first;
-  }
-  bool LIsAsm = LB == "";
-  bool RIsAsm = RB == "";
-  // Sort assembler after built-in

[PATCH] D34506: Factor out a functionality from `isBeforeInTranslationUnit`

2017-06-27 Thread Gábor Horváth via Phabricator via cfe-commits
xazax.hun added a comment.

I created a new public API that is using a piece of code that was factored out 
from `isBeforeInTranslationUnit`. Using this new function it is possible to 
implement proper comparison of source locations within the Static Analyzer. 
What do you think?


https://reviews.llvm.org/D34506



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


[PATCH] D24644: Pass -ffunction-sections/-fdata-sections along to gold-plugin

2017-06-27 Thread Florian Hahn via Phabricator via cfe-commits
fhahn added a comment.

I'd like to fix PR22999 and was wondering if you think adding a 
function-section attribute to the IR would be a viable solution?

When doing LTO, we could add the same function-section to each function in a 
module in the IRLinker. @mehdi_amini did you think something like that when 
suggesting using attributes?

ps: Maybe it would be better to discuss this at the bug report, but this review 
seemed the easiest way to address the right people.


Repository:
  rL LLVM

https://reviews.llvm.org/D24644



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


[PATCH] D34695: _Float16 preprocessor macro definitions

2017-06-27 Thread Sjoerd Meijer via Phabricator via cfe-commits
SjoerdMeijer created this revision.
Herald added subscribers: aheejin, dschuff, jfb.

This adds the _Float16 preprocessor macro definitions.


https://reviews.llvm.org/D34695

Files:
  lib/Frontend/InitPreprocessor.cpp
  lib/Headers/float.h
  test/Preprocessor/init.c

Index: test/Preprocessor/init.c
===
--- test/Preprocessor/init.c
+++ test/Preprocessor/init.c
@@ -285,6 +285,20 @@
 // AARCH64:#define __DBL_MIN_EXP__ (-1021)
 // AARCH64:#define __DBL_MIN__ 2.2250738585072014e-308
 // AARCH64:#define __DECIMAL_DIG__ __LDBL_DECIMAL_DIG__
+// AARCH64:#define __FLT16_DECIMAL_DIG__ 5
+// AARCH64:#define __FLT16_DENORM_MIN__ 5.9604644775390625e-8F16
+// AARCH64:#define __FLT16_DIG__ 3
+// AARCH64:#define __FLT16_EPSILON__ 9.765625e-4F16
+// AARCH64:#define __FLT16_HAS_DENORM__ 1
+// AARCH64:#define __FLT16_HAS_INFINITY__ 1
+// AARCH64:#define __FLT16_HAS_QUIET_NAN__ 1
+// AARCH64:#define __FLT16_MANT_DIG__ 11
+// AARCH64:#define __FLT16_MAX_10_EXP__ 4
+// AARCH64:#define __FLT16_MAX_EXP__ 15
+// AARCH64:#define __FLT16_MAX__ 6.5504e+4F16
+// AARCH64:#define __FLT16_MIN_10_EXP__ (-13)
+// AARCH64:#define __FLT16_MIN_EXP__ (-14)
+// AARCH64:#define __FLT16_MIN__ 6.103515625e-5F16
 // AARCH64:#define __FLT_DENORM_MIN__ 1.40129846e-45F
 // AARCH64:#define __FLT_DIG__ 6
 // AARCH64:#define __FLT_EPSILON__ 1.19209290e-7F
@@ -8884,7 +8898,7 @@
 // WEBASSEMBLY32-NEXT:#define __DECIMAL_DIG__ __LDBL_DECIMAL_DIG__
 // WEBASSEMBLY32-NOT:#define __ELF__
 // WEBASSEMBLY32-NEXT:#define __FINITE_MATH_ONLY__ 0
-// WEBASSEMBLY32-NEXT:#define __FLT_DECIMAL_DIG__ 9
+// WEBASSEMBLY32:#define __FLT_DECIMAL_DIG__ 9
 // WEBASSEMBLY32-NEXT:#define __FLT_DENORM_MIN__ 1.40129846e-45F
 // WEBASSEMBLY32-NEXT:#define __FLT_DIG__ 6
 // WEBASSEMBLY32-NEXT:#define __FLT_EPSILON__ 1.19209290e-7F
@@ -9210,7 +9224,7 @@
 // WEBASSEMBLY64-NEXT:#define __DECIMAL_DIG__ __LDBL_DECIMAL_DIG__
 // WEBASSEMBLY64-NOT:#define __ELF__
 // WEBASSEMBLY64-NEXT:#define __FINITE_MATH_ONLY__ 0
-// WEBASSEMBLY64-NEXT:#define __FLT_DECIMAL_DIG__ 9
+// WEBASSEMBLY64:#define __FLT_DECIMAL_DIG__ 9
 // WEBASSEMBLY64-NEXT:#define __FLT_DENORM_MIN__ 1.40129846e-45F
 // WEBASSEMBLY64-NEXT:#define __FLT_DIG__ 6
 // WEBASSEMBLY64-NEXT:#define __FLT_EPSILON__ 1.19209290e-7F
Index: lib/Headers/float.h
===
--- lib/Headers/float.h
+++ lib/Headers/float.h
@@ -134,4 +134,18 @@
 #  define LDBL_DECIMAL_DIG __LDBL_DECIMAL_DIG__
 #endif
 
+#ifdef __STDC_WANT_IEC_60559_TYPES_EXT__
+#  define FLT16_MANT_DIG  __FLT16_MANT_DIG__
+#  define FLT16_DECIMAL_DIG __LT16_DECIMAL_DIG__
+#  define FLT16_DIG  __LT16_DIG__
+#  define FLT16_MIN_EXP  __LT16_MIN_EXP__
+#  define FLT16_MIN_10_EXP __FLT16_MIN_10_EXP__
+#  define FLT16_MAX_EXP __FLT16_MAX_EXP__
+#  define FLT16_MAX_10_EXP __FLT16_MAX_10_EXP__
+#  define FLT16_MAX __FLT16_MAX__
+#  define FLT16_EPSILON __FLT16_EPSILON__
+#  define FLT16_MIN __FLT16_MIN__
+#  define FLT_TRUE_MIN __FLT_TRUE_MIN__
+#endif /* __STDC_WANT_IEC_60559_TYPES_EXT__ */
+
 #endif /* __FLOAT_H */
Index: lib/Frontend/InitPreprocessor.cpp
===
--- lib/Frontend/InitPreprocessor.cpp
+++ lib/Frontend/InitPreprocessor.cpp
@@ -109,9 +109,11 @@
 /// PickFP - This is used to pick a value based on the FP semantics of the
 /// specified FP model.
 template 
-static T PickFP(const llvm::fltSemantics *Sem, T IEEESingleVal,
+static T PickFP(const llvm::fltSemantics *Sem, T IEEEHalfVal, T IEEESingleVal,
 T IEEEDoubleVal, T X87DoubleExtendedVal, T PPCDoubleDoubleVal,
 T IEEEQuadVal) {
+  if (Sem == (const llvm::fltSemantics*)&llvm::APFloat::IEEEhalf())
+return IEEEHalfVal;
   if (Sem == (const llvm::fltSemantics*)&llvm::APFloat::IEEEsingle())
 return IEEESingleVal;
   if (Sem == (const llvm::fltSemantics*)&llvm::APFloat::IEEEdouble())
@@ -127,26 +129,26 @@
 static void DefineFloatMacros(MacroBuilder &Builder, StringRef Prefix,
   const llvm::fltSemantics *Sem, StringRef Ext) {
   const char *DenormMin, *Epsilon, *Max, *Min;
-  DenormMin = PickFP(Sem, "1.40129846e-45", "4.9406564584124654e-324",
- "3.64519953188247460253e-4951",
+  DenormMin = PickFP(Sem, "5.9604644775390625e-8", "1.40129846e-45",
+ "4.9406564584124654e-324", "3.64519953188247460253e-4951",
  "4.94065645841246544176568792868221e-324",
  "6.47517511943802511092443895822764655e-4966");
-  int Digits = PickFP(Sem, 6, 15, 18, 31, 33);
-  int DecimalDigits = PickFP(Sem, 9, 17, 21, 33, 36);
-  Epsilon = PickFP(Sem, "1.19209290e-7", "2.2204460492503131e-16",
-   "1.08420217248550443401e-19",
+  int Digits = PickFP(Sem, 3, 6, 15, 18, 31, 33);
+  int DecimalDigits = PickFP(Sem, 5, 9, 17, 21, 33, 36);
+  Epsilon = PickFP(Sem, "9.765625e-4", "1.19209290e-7", 
+   "2.2

Re: [Diffusion] rL306364: [CodeGen][ObjC] Fix GNU's encoding of bit-field ivars.

2017-06-27 Thread Akira Hatanaka via cfe-commits
Thanks for the fix!

The change looks reasonable to me.

On Tue, Jun 27, 2017 at 12:46 AM, NAKAMURA Takumi via Phabricator <
revi...@reviews.llvm.org> wrote:

> chapuni added subscribers: cfe-commits, chapuni.
> chapuni added a comment.
>
> Could you confirm if my change were reasonable? Or rewrite it.
>
>
> /cfe/trunk/test/CodeGenObjC/ivar-type-encoding.m:51 It was incompatible
> to -m32.
>
>   @9 = private unnamed_addr constant [6 x i8] c"b96c1\00", align 1
>
> Tweaked in rL306372.
>
> Users:
>   ahatanak (Author)
>
> https://reviews.llvm.org/rL306364
>
>
>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r306419 - [OPENMP] Use MapVector instead of DenseMap for stable codegen, NFC.

2017-06-27 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Tue Jun 27 08:46:42 2017
New Revision: 306419

URL: http://llvm.org/viewvc/llvm-project?rev=306419&view=rev
Log:
[OPENMP] Use MapVector instead of DenseMap for stable codegen, NFC.

Modified:
cfe/trunk/include/clang/AST/OpenMPClause.h
cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp

Modified: cfe/trunk/include/clang/AST/OpenMPClause.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/OpenMPClause.h?rev=306419&r1=306418&r2=306419&view=diff
==
--- cfe/trunk/include/clang/AST/OpenMPClause.h (original)
+++ cfe/trunk/include/clang/AST/OpenMPClause.h Tue Jun 27 08:46:42 2017
@@ -20,6 +20,7 @@
 #include "clang/AST/Stmt.h"
 #include "clang/Basic/OpenMPKinds.h"
 #include "clang/Basic/SourceLocation.h"
+#include "llvm/ADT/MapVector.h"
 
 namespace clang {
 
@@ -3001,7 +3002,7 @@ protected:
 // Organize the components by declaration and retrieve the original
 // expression. Original expressions are always the first component of the
 // mappable component list.
-llvm::DenseMap>
+llvm::MapVector>
 ComponentListMap;
 {
   auto CI = ComponentLists.begin();

Modified: cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp?rev=306419&r1=306418&r2=306419&view=diff
==
--- cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGOpenMPRuntime.cpp Tue Jun 27 08:46:42 2017
@@ -5603,7 +5603,7 @@ public:
 // We have to process the component lists that relate with the same
 // declaration in a single chunk so that we can generate the map flags
 // correctly. Therefore, we organize all lists in a map.
-llvm::DenseMap> Info;
+llvm::MapVector> Info;
 
 // Helper function to fill the information map for the different supported
 // clauses.


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


[PATCH] D33719: Add _Float16 as a C/C++ source language type

2017-06-27 Thread Sjoerd Meijer via Phabricator via cfe-commits
SjoerdMeijer added a comment.

I have create a separate patch for the _Float16 preprocessor macro definitions 
in https://reviews.llvm.org/D34695.


https://reviews.llvm.org/D33719



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


[PATCH] D24644: Pass -ffunction-sections/-fdata-sections along to gold-plugin

2017-06-27 Thread Mehdi AMINI via Phabricator via cfe-commits
mehdi_amini added a comment.

In https://reviews.llvm.org/D24644#792168, @fhahn wrote:

> I'd like to fix PR22999 and was wondering if you think adding a 
> function-section attribute to the IR would be a viable solution?
>
> When doing LTO, we could add the same function-section to each function in a 
> module in the IRLinker. @mehdi_amini did you think something like that when 
> suggesting using attributes?


Not sure how this would work? How do you codegen half of the functions with 
function-section but not all? How is the backend supposed to behave if it 
starts with a function that isn't decorated with this attribute, then move to 
one that is, and finally proceed with one that isn't?


Repository:
  rL LLVM

https://reviews.llvm.org/D24644



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


[PATCH] D34674: [clang-tidy] Handle new array expressions in modernize-make-unique check.

2017-06-27 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 104190.
hokein added a comment.

Remove a redundant empty line.


https://reviews.llvm.org/D34674

Files:
  clang-tidy/modernize/MakeSmartPtrCheck.cpp
  clang-tidy/modernize/MakeSmartPtrCheck.h
  test/clang-tidy/modernize-make-unique.cpp

Index: test/clang-tidy/modernize-make-unique.cpp
===
--- test/clang-tidy/modernize-make-unique.cpp
+++ test/clang-tidy/modernize-make-unique.cpp
@@ -18,6 +18,7 @@
   type *release();
   void reset();
   void reset(type *pt);
+  void reset(type pt);
   unique_ptr &operator=(unique_ptr &&);
   template 
   unique_ptr &operator=(unique_ptr &&);
@@ -261,6 +262,36 @@
   BB.reset(new bar::Bar());
   // CHECK-MESSAGES: :[[@LINE-1]]:6: warning:
   // CHECK-FIXES: BB = std::make_unique();
+
+  std::unique_ptr FFs;
+  FFs.reset(new Foo[5]);
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning:
+  // CHECK-FIXES: FFs = std::make_unique(5);
+  FFs.reset(new Foo[5]());
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning:
+  // CHECK-FIXES: FFs = std::make_unique(5);
+  const int Num = 1;
+  FFs.reset(new Foo[Num]);
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning:
+  // CHECK-FIXES: FFs = std::make_unique(Num);
+  int Num2 = 1;
+  FFs.reset(new Foo[Num2]);
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning:
+  // CHECK-FIXES: FFs = std::make_unique(Num2);
+
+  std::unique_ptr FI;
+  FI.reset(new int[5]);
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning:
+  // CHECK-FIXES: FI = std::make_unique(5);
+  FI.reset(new int[5]());
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning:
+  // CHECK-FIXES: FI = std::make_unique(5);
+  FI.reset(new int[Num]);
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning:
+  // CHECK-FIXES: FI = std::make_unique(Num);
+  FI.reset(new int[Num2]);
+  // CHECK-MESSAGES: :[[@LINE-1]]:6: warning:
+  // CHECK-FIXES: FI = std::make_unique(Num2);
 }
 
 void aliases() {
Index: clang-tidy/modernize/MakeSmartPtrCheck.h
===
--- clang-tidy/modernize/MakeSmartPtrCheck.h
+++ clang-tidy/modernize/MakeSmartPtrCheck.h
@@ -49,7 +49,8 @@
   const QualType *Type, const CXXNewExpr *New);
   void checkReset(SourceManager &SM, const CXXMemberCallExpr *Member,
   const CXXNewExpr *New);
-  void replaceNew(DiagnosticBuilder &Diag, const CXXNewExpr *New);
+  void replaceNew(DiagnosticBuilder &Diag, const CXXNewExpr *New,
+  SourceManager &SM);
 };
 
 } // namespace modernize
Index: clang-tidy/modernize/MakeSmartPtrCheck.cpp
===
--- clang-tidy/modernize/MakeSmartPtrCheck.cpp
+++ clang-tidy/modernize/MakeSmartPtrCheck.cpp
@@ -17,13 +17,17 @@
 namespace modernize {
 
 namespace {
-StringRef GetNewExprName(const CXXNewExpr *NewExpr,
- const SourceManager &SM,
- const LangOptions &Lang) {
-  return Lexer::getSourceText(
+std::string GetNewExprName(const CXXNewExpr *NewExpr,
+   const SourceManager &SM,
+   const LangOptions &Lang) {
+  StringRef WrittenName = Lexer::getSourceText(
   CharSourceRange::getTokenRange(
   NewExpr->getAllocatedTypeSourceInfo()->getTypeLoc().getSourceRange()),
   SM, Lang);
+  if (NewExpr->isArray()) {
+return WrittenName.str() + "[]";
+  }
+  return WrittenName.str();
 }
 } // namespace
 
@@ -114,7 +118,7 @@
 ConstructCallEnd = ConstructCallStart.getLocWithOffset(ExprStr.size());
 Diag << FixItHint::CreateInsertion(
 ConstructCallEnd,
-"<" + GetNewExprName(New, SM, getLangOpts()).str() + ">");
+"<" + GetNewExprName(New, SM, getLangOpts()) + ">");
   } else {
 ConstructCallEnd = ConstructCallStart.getLocWithOffset(LAngle);
   }
@@ -137,7 +141,7 @@
 ")");
   }
 
-  replaceNew(Diag, New);
+  replaceNew(Diag, New, SM);
 }
 
 void MakeSmartPtrCheck::checkReset(SourceManager &SM,
@@ -162,23 +166,49 @@
   if (Expr->isArrow())
 Diag << FixItHint::CreateInsertion(ExprStart, "*");
 
-  replaceNew(Diag, New);
+  replaceNew(Diag, New, SM);
 }
 
 void MakeSmartPtrCheck::replaceNew(DiagnosticBuilder &Diag,
-   const CXXNewExpr *New) {
+   const CXXNewExpr *New,
+   SourceManager& SM) {
   SourceLocation NewStart = New->getSourceRange().getBegin();
   SourceLocation NewEnd = New->getSourceRange().getEnd();
+
+  std::string ArraySizeExpr;
+  if (const auto* ArraySize = New->getArraySize()) {
+ArraySizeExpr = Lexer::getSourceText(CharSourceRange::getTokenRange(
+ ArraySize->getSourceRange()),
+ SM, getLangOpts())
+.str();
+  }
+
   switch (New->getInitializationStyle()) {
   case CXXNewExpr::NoInit: {
-Diag << FixItHint::CreateRemoval(SourceRange(NewStart, NewEnd));
+ 

[PATCH] D34696: [refactor] Move the core of clang-rename to lib/Tooling/Refactoring

2017-06-27 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman created this revision.
Herald added a subscriber: mgorny.

The core engine of clang-rename will be used for local and global renames in 
the new refactoring engine 
(http://lists.llvm.org/pipermail/cfe-dev/2017-June/054286.html).

I haven't renamed the files/cleaned up the code in this patch, do you think I 
should? E.g. SymbolOccurrenceFinder instead of USRLocFinder.


Repository:
  rL LLVM

https://reviews.llvm.org/D34696

Files:
  include/clang/Tooling/Refactoring/USRFinder.h
  include/clang/Tooling/Refactoring/USRFindingAction.h
  include/clang/Tooling/Refactoring/USRLocFinder.h
  include/clang/module.modulemap
  lib/Tooling/Refactoring/CMakeLists.txt
  lib/Tooling/Refactoring/USRFinder.cpp
  lib/Tooling/Refactoring/USRFindingAction.cpp
  lib/Tooling/Refactoring/USRLocFinder.cpp
  tools/extra/clang-rename/CMakeLists.txt
  tools/extra/clang-rename/RenamingAction.cpp
  tools/extra/clang-rename/USRFinder.cpp
  tools/extra/clang-rename/USRFinder.h
  tools/extra/clang-rename/USRFindingAction.cpp
  tools/extra/clang-rename/USRFindingAction.h
  tools/extra/clang-rename/USRLocFinder.cpp
  tools/extra/clang-rename/USRLocFinder.h
  tools/extra/clang-rename/tool/ClangRename.cpp

Index: tools/extra/clang-rename/tool/ClangRename.cpp
===
--- tools/extra/clang-rename/tool/ClangRename.cpp
+++ tools/extra/clang-rename/tool/ClangRename.cpp
@@ -14,7 +14,6 @@
 //===--===//
 
 #include "../RenamingAction.h"
-#include "../USRFindingAction.h"
 #include "clang/Basic/Diagnostic.h"
 #include "clang/Basic/DiagnosticOptions.h"
 #include "clang/Basic/FileManager.h"
@@ -26,6 +25,7 @@
 #include "clang/Rewrite/Core/Rewriter.h"
 #include "clang/Tooling/CommonOptionsParser.h"
 #include "clang/Tooling/Refactoring.h"
+#include "clang/Tooling/Refactoring/USRFindingAction.h"
 #include "clang/Tooling/ReplacementsYaml.h"
 #include "clang/Tooling/Tooling.h"
 #include "llvm/ADT/IntrusiveRefCntPtr.h"
@@ -160,7 +160,7 @@
 
   auto Files = OP.getSourcePathList();
   tooling::RefactoringTool Tool(OP.getCompilations(), Files);
-  rename::USRFindingAction FindingAction(SymbolOffsets, QualifiedNames, Force);
+  tooling::USRFindingAction FindingAction(SymbolOffsets, QualifiedNames, Force);
   Tool.run(tooling::newFrontendActionFactory(&FindingAction).get());
   const std::vector> &USRList =
   FindingAction.getUSRList();
Index: tools/extra/clang-rename/USRLocFinder.h
===
--- tools/extra/clang-rename/USRLocFinder.h
+++ /dev/null
@@ -1,49 +0,0 @@
-//===--- tools/extra/clang-rename/USRLocFinder.h - Clang rename tool --===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===--===//
-///
-/// \file
-/// \brief Provides functionality for finding all instances of a USR in a given
-/// AST.
-///
-//===--===//
-
-#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_RENAME_USR_LOC_FINDER_H
-#define LLVM_CLANG_TOOLS_EXTRA_CLANG_RENAME_USR_LOC_FINDER_H
-
-#include "clang/AST/AST.h"
-#include "clang/Tooling/Core/Replacement.h"
-#include "clang/Tooling/Refactoring/AtomicChange.h"
-#include "llvm/ADT/StringRef.h"
-#include 
-#include 
-
-namespace clang {
-namespace rename {
-
-/// Create atomic changes for renaming all symbol references which are
-/// identified by the USRs set to a given new name.
-///
-/// \param USRs The set containing USRs of a particular old symbol.
-/// \param NewName The new name to replace old symbol name.
-/// \param TranslationUnitDecl The translation unit declaration.
-///
-/// \return Atomic changes for renaming.
-std::vector
-createRenameAtomicChanges(llvm::ArrayRef USRs,
-  llvm::StringRef NewName, Decl *TranslationUnitDecl);
-
-// FIXME: make this an AST matcher. Wouldn't that be awesome??? I agree!
-std::vector
-getLocationsOfUSRs(const std::vector &USRs,
-   llvm::StringRef PrevName, Decl *Decl);
-
-} // namespace rename
-} // namespace clang
-
-#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_RENAME_USR_LOC_FINDER_H
Index: tools/extra/clang-rename/USRLocFinder.cpp
===
--- tools/extra/clang-rename/USRLocFinder.cpp
+++ /dev/null
@@ -1,509 +0,0 @@
-//===--- tools/extra/clang-rename/USRLocFinder.cpp - Clang rename tool ===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===--===//
-///
-/// \file
-/// \brief Mehtods for finding all instances of a USR. Our strategy is 

[PATCH] D34158: to support gcc 4.8 (and newer) compatibility on Linux, preinclude

2017-06-27 Thread Melanie Blower via Phabricator via cfe-commits
mibintc added a comment.

@fedor.sergeev do you have time to review my (hopefully) final revision?  Also 
can you recommend someone to review the extra test changes?


Repository:
  rL LLVM

https://reviews.llvm.org/D34158



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


[PATCH] D34674: [clang-tidy] Handle new array expressions in modernize-make-unique check.

2017-06-27 Thread Haojian Wu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL306421: [clang-tidy] Handle new array expressions in 
modernize-make-unique check. (authored by hokein).

Repository:
  rL LLVM

https://reviews.llvm.org/D34674

Files:
  clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.cpp
  clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.h
  clang-tools-extra/trunk/test/clang-tidy/modernize-make-unique.cpp

Index: clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.h
===
--- clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.h
+++ clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.h
@@ -49,7 +49,8 @@
   const QualType *Type, const CXXNewExpr *New);
   void checkReset(SourceManager &SM, const CXXMemberCallExpr *Member,
   const CXXNewExpr *New);
-  void replaceNew(DiagnosticBuilder &Diag, const CXXNewExpr *New);
+  void replaceNew(DiagnosticBuilder &Diag, const CXXNewExpr *New,
+  SourceManager &SM);
 };
 
 } // namespace modernize
Index: clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.cpp
@@ -17,13 +17,17 @@
 namespace modernize {
 
 namespace {
-StringRef GetNewExprName(const CXXNewExpr *NewExpr,
- const SourceManager &SM,
- const LangOptions &Lang) {
-  return Lexer::getSourceText(
+std::string GetNewExprName(const CXXNewExpr *NewExpr,
+   const SourceManager &SM,
+   const LangOptions &Lang) {
+  StringRef WrittenName = Lexer::getSourceText(
   CharSourceRange::getTokenRange(
   NewExpr->getAllocatedTypeSourceInfo()->getTypeLoc().getSourceRange()),
   SM, Lang);
+  if (NewExpr->isArray()) {
+return WrittenName.str() + "[]";
+  }
+  return WrittenName.str();
 }
 } // namespace
 
@@ -114,7 +118,7 @@
 ConstructCallEnd = ConstructCallStart.getLocWithOffset(ExprStr.size());
 Diag << FixItHint::CreateInsertion(
 ConstructCallEnd,
-"<" + GetNewExprName(New, SM, getLangOpts()).str() + ">");
+"<" + GetNewExprName(New, SM, getLangOpts()) + ">");
   } else {
 ConstructCallEnd = ConstructCallStart.getLocWithOffset(LAngle);
   }
@@ -137,7 +141,7 @@
 ")");
   }
 
-  replaceNew(Diag, New);
+  replaceNew(Diag, New, SM);
 }
 
 void MakeSmartPtrCheck::checkReset(SourceManager &SM,
@@ -162,23 +166,49 @@
   if (Expr->isArrow())
 Diag << FixItHint::CreateInsertion(ExprStart, "*");
 
-  replaceNew(Diag, New);
+  replaceNew(Diag, New, SM);
 }
 
 void MakeSmartPtrCheck::replaceNew(DiagnosticBuilder &Diag,
-   const CXXNewExpr *New) {
+   const CXXNewExpr *New,
+   SourceManager& SM) {
   SourceLocation NewStart = New->getSourceRange().getBegin();
   SourceLocation NewEnd = New->getSourceRange().getEnd();
+
+  std::string ArraySizeExpr;
+  if (const auto* ArraySize = New->getArraySize()) {
+ArraySizeExpr = Lexer::getSourceText(CharSourceRange::getTokenRange(
+ ArraySize->getSourceRange()),
+ SM, getLangOpts())
+.str();
+  }
+
   switch (New->getInitializationStyle()) {
   case CXXNewExpr::NoInit: {
-Diag << FixItHint::CreateRemoval(SourceRange(NewStart, NewEnd));
+if (ArraySizeExpr.empty()) {
+  Diag << FixItHint::CreateRemoval(SourceRange(NewStart, NewEnd));
+} else {
+  // New array expression without written initializer:
+  //   smart_ptr(new Foo[5]);
+  Diag << FixItHint::CreateReplacement(SourceRange(NewStart, NewEnd),
+   ArraySizeExpr);
+}
 break;
   }
   case CXXNewExpr::CallInit: {
-SourceRange InitRange = New->getDirectInitRange();
-Diag << FixItHint::CreateRemoval(
-SourceRange(NewStart, InitRange.getBegin()));
-Diag << FixItHint::CreateRemoval(SourceRange(InitRange.getEnd(), NewEnd));
+if (ArraySizeExpr.empty()) {
+  SourceRange InitRange = New->getDirectInitRange();
+  Diag << FixItHint::CreateRemoval(
+  SourceRange(NewStart, InitRange.getBegin()));
+  Diag << FixItHint::CreateRemoval(SourceRange(InitRange.getEnd(), NewEnd));
+}
+else {
+  // New array expression with default/value initialization:
+  //   smart_ptr(new int[5]());
+  //   smart_ptr(new Foo[5]());
+  Diag << FixItHint::CreateReplacement(SourceRange(NewStart, NewEnd),
+   ArraySizeExpr);
+}
 break;
   }
   case CXXNewExpr::ListInit: {
Index: clang-tools-extra/trunk/test/cla

[clang-tools-extra] r306421 - [clang-tidy] Handle new array expressions in modernize-make-unique check.

2017-06-27 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Tue Jun 27 09:25:05 2017
New Revision: 306421

URL: http://llvm.org/viewvc/llvm-project?rev=306421&view=rev
Log:
[clang-tidy] Handle new array expressions in modernize-make-unique check.

Reviewers: alexfh

Reviewed By: alexfh

Subscribers: JDevlieghere, xazax.hun, cfe-commits

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

Modified:
clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.cpp
clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.h
clang-tools-extra/trunk/test/clang-tidy/modernize-make-unique.cpp

Modified: clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.cpp?rev=306421&r1=306420&r2=306421&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.cpp Tue Jun 
27 09:25:05 2017
@@ -17,13 +17,17 @@ namespace tidy {
 namespace modernize {
 
 namespace {
-StringRef GetNewExprName(const CXXNewExpr *NewExpr,
- const SourceManager &SM,
- const LangOptions &Lang) {
-  return Lexer::getSourceText(
+std::string GetNewExprName(const CXXNewExpr *NewExpr,
+   const SourceManager &SM,
+   const LangOptions &Lang) {
+  StringRef WrittenName = Lexer::getSourceText(
   CharSourceRange::getTokenRange(
   
NewExpr->getAllocatedTypeSourceInfo()->getTypeLoc().getSourceRange()),
   SM, Lang);
+  if (NewExpr->isArray()) {
+return WrittenName.str() + "[]";
+  }
+  return WrittenName.str();
 }
 } // namespace
 
@@ -114,7 +118,7 @@ void MakeSmartPtrCheck::checkConstruct(S
 ConstructCallEnd = ConstructCallStart.getLocWithOffset(ExprStr.size());
 Diag << FixItHint::CreateInsertion(
 ConstructCallEnd,
-"<" + GetNewExprName(New, SM, getLangOpts()).str() + ">");
+"<" + GetNewExprName(New, SM, getLangOpts()) + ">");
   } else {
 ConstructCallEnd = ConstructCallStart.getLocWithOffset(LAngle);
   }
@@ -137,7 +141,7 @@ void MakeSmartPtrCheck::checkConstruct(S
 ")");
   }
 
-  replaceNew(Diag, New);
+  replaceNew(Diag, New, SM);
 }
 
 void MakeSmartPtrCheck::checkReset(SourceManager &SM,
@@ -162,23 +166,49 @@ void MakeSmartPtrCheck::checkReset(Sourc
   if (Expr->isArrow())
 Diag << FixItHint::CreateInsertion(ExprStart, "*");
 
-  replaceNew(Diag, New);
+  replaceNew(Diag, New, SM);
 }
 
 void MakeSmartPtrCheck::replaceNew(DiagnosticBuilder &Diag,
-   const CXXNewExpr *New) {
+   const CXXNewExpr *New,
+   SourceManager& SM) {
   SourceLocation NewStart = New->getSourceRange().getBegin();
   SourceLocation NewEnd = New->getSourceRange().getEnd();
+
+  std::string ArraySizeExpr;
+  if (const auto* ArraySize = New->getArraySize()) {
+ArraySizeExpr = Lexer::getSourceText(CharSourceRange::getTokenRange(
+ ArraySize->getSourceRange()),
+ SM, getLangOpts())
+.str();
+  }
+
   switch (New->getInitializationStyle()) {
   case CXXNewExpr::NoInit: {
-Diag << FixItHint::CreateRemoval(SourceRange(NewStart, NewEnd));
+if (ArraySizeExpr.empty()) {
+  Diag << FixItHint::CreateRemoval(SourceRange(NewStart, NewEnd));
+} else {
+  // New array expression without written initializer:
+  //   smart_ptr(new Foo[5]);
+  Diag << FixItHint::CreateReplacement(SourceRange(NewStart, NewEnd),
+   ArraySizeExpr);
+}
 break;
   }
   case CXXNewExpr::CallInit: {
-SourceRange InitRange = New->getDirectInitRange();
-Diag << FixItHint::CreateRemoval(
-SourceRange(NewStart, InitRange.getBegin()));
-Diag << FixItHint::CreateRemoval(SourceRange(InitRange.getEnd(), NewEnd));
+if (ArraySizeExpr.empty()) {
+  SourceRange InitRange = New->getDirectInitRange();
+  Diag << FixItHint::CreateRemoval(
+  SourceRange(NewStart, InitRange.getBegin()));
+  Diag << FixItHint::CreateRemoval(SourceRange(InitRange.getEnd(), 
NewEnd));
+}
+else {
+  // New array expression with default/value initialization:
+  //   smart_ptr(new int[5]());
+  //   smart_ptr(new Foo[5]());
+  Diag << FixItHint::CreateReplacement(SourceRange(NewStart, NewEnd),
+   ArraySizeExpr);
+}
 break;
   }
   case CXXNewExpr::ListInit: {

Modified: clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.h?rev=306421&r1=306420&r2=306421&view=diff
==

[PATCH] D34206: [clang-tidy] Add "MakeSmartPtrFunction" option to modernize-make-shared/unique checks.

2017-06-27 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a comment.

In https://reviews.llvm.org/D34206#790406, @alexfh wrote:

> Ping me once you're done fixing the bugs.


The bugs are fixed. The patch is ready for review ;)


https://reviews.llvm.org/D34206



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


[PATCH] D24644: Pass -ffunction-sections/-fdata-sections along to gold-plugin

2017-06-27 Thread Florian Hahn via Phabricator via cfe-commits
fhahn added a comment.

In https://reviews.llvm.org/D24644#792262, @mehdi_amini wrote:

> In https://reviews.llvm.org/D24644#792168, @fhahn wrote:
>
> > I'd like to fix PR22999 and was wondering if you think adding a 
> > function-section attribute to the IR would be a viable solution?
> >
> > When doing LTO, we could add the same function-section to each function in 
> > a module in the IRLinker. @mehdi_amini did you think something like that 
> > when suggesting using attributes?
>
>
> Not sure how this would work? How do you codegen half of the functions with 
> function-section but not all? How is the backend supposed to behave if it 
> starts with a function that isn't decorated with this attribute, then move to 
> one that is, and finally proceed with one that isn't?


hm yes I guess we would have to group the functions by their function-section 
attribute, which isn't such a good idea probably.

@echristo you mentioned that the compiler maybe could determine if we should 
use function-sections during codegen, but it does not seem possible to 
determine the size of the code section before emitting all functions, at which 
point it is already too late. Maybe I am missing something?


Repository:
  rL LLVM

https://reviews.llvm.org/D24644



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


[PATCH] D34342: [OpenCL] Fix code generation of function-scope constant samplers.

2017-06-27 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl added a comment.

In https://reviews.llvm.org/D34342#786941, @bader wrote:

> Added test case reproducing the issue described in the description.
>  Removed test cases from test/SemaOpenCL/sampler_t.cl covered by 
> test/CodeGenOpenCL/sampler.cl.
>
> While I was moving one test case from test/SemaOpenCL/sampler_t.cl, I found 
> another bug in CodeGen library that crashes the compilation if sampler is 
> initialized with non-constant expression.
>
> Here is a short reproducer:
>
>   int get_sampler_initializer(void);
>   kernel void foo() {
> const sampler_t const_smp_func_init = get_sampler_initializer();
>   }
>
>
> The problem is that clang does not discard this code as invalid, but CodeGen 
> library expects sampler initializer to be a constant expression:
>
>   llvm::Value *
>   CodeGenModule::createOpenCLIntToSamplerConversion(const Expr *E,
> CodeGenFunction &CGF) {
> llvm::Constant *C = EmitConstantExpr(E, E->getType(), &CGF); // for the 
> reproducer expression here is CallExpr.
> auto SamplerT = getOpenCLRuntime().getSamplerType();
> auto FTy = llvm::FunctionType::get(SamplerT, {C->getType()}, false);
> return CGF.Builder.CreateCall(CreateRuntimeFunction(FTy,
>   "__translate_sampler_initializer"),
>   {C});
>   }
>
>
> There are two ways to handle this issue:
>
> 1. Implement diagnostics allowing only compile time constant initializers.
> 2. Add non-constant sampler initializer support to CodeGen library.
>
>   OpenCL specification examples give me impression that samplers declared 
> inside OpenCL programs must be known at compile time. On the other hand 
> OpenCL allows samplers passed via kernel parameters to be unknown at compile 
> time.
>
>   Thoughts?


The OpenCL spec v1.2 s6.9.b:

The sampler type (sampler_t) can only be used as the type of a function 
argument or a
variable declared in the program scope or the outermost scope of a kernel 
function. The
behavior of a sampler variable declared in a non-outermost scope of a kernel 
function is
implementation-defined. A sampler argument or variable cannot be modified.
The sampler type cannot be used to declare a structure or union field, an array 
of
samplers, a pointer to a sampler, or the return type of a function. The sampler 
type cannot
be used with the __local and __global address space qualifiers.

So a function returning sampler is invalid. However, the spec does not forbid a 
sampler
defined in the outermost scope of a kernel function to be initialized 
dynamically, e.g.

  kernel void f(sampler_t s1, sampler_t s2, int x) {
sampler_t s = x ? s1 : s2;
  }

The question is: if we allow this, will it cause any issue?


https://reviews.llvm.org/D34342



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


[PATCH] D34506: Factor out a functionality from `isBeforeInTranslationUnit`

2017-06-27 Thread Argyrios Kyrtzidis via Phabricator via cfe-commits
akyrtzi added a comment.

I'd prefer to avoid including whitespace-only changes (there are a couple of 
lines in the diff with only whitespace change), otherwise LGTM!


https://reviews.llvm.org/D34506



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


[PATCH] D34663: Update test for enabling ICP for AutoFDO.

2017-06-27 Thread Dehao Chen via Phabricator via cfe-commits
danielcdh updated this revision to Diff 104199.
danielcdh added a comment.

update comments


https://reviews.llvm.org/D34663

Files:
  test/CodeGen/pgo-sample-thinlto-summary.c


Index: test/CodeGen/pgo-sample-thinlto-summary.c
===
--- test/CodeGen/pgo-sample-thinlto-summary.c
+++ test/CodeGen/pgo-sample-thinlto-summary.c
@@ -32,10 +32,10 @@
 baz(i);
 }
 
-// Check that icp is not invoked (both -O2 and ThinLTO).
+// Check that icp is not invoked for ThinLTO, but invoked for -O2.
 // O2-LABEL: define void @icp
 // THINLTO-LABEL: define void @icp
-// O2-NOT: if.true.direct_targ
+// O2: if.true.direct_targ
 // ThinLTO-NOT: if.true.direct_targ
 void icp(void (*p)()) {
   p();


Index: test/CodeGen/pgo-sample-thinlto-summary.c
===
--- test/CodeGen/pgo-sample-thinlto-summary.c
+++ test/CodeGen/pgo-sample-thinlto-summary.c
@@ -32,10 +32,10 @@
 baz(i);
 }
 
-// Check that icp is not invoked (both -O2 and ThinLTO).
+// Check that icp is not invoked for ThinLTO, but invoked for -O2.
 // O2-LABEL: define void @icp
 // THINLTO-LABEL: define void @icp
-// O2-NOT: if.true.direct_targ
+// O2: if.true.direct_targ
 // ThinLTO-NOT: if.true.direct_targ
 void icp(void (*p)()) {
   p();
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D32411: [libcxx] Provide #include_next alternative for MSVC

2017-06-27 Thread Shoaib Meenai via Phabricator via cfe-commits
smeenai resigned from this revision.
smeenai added a comment.

Sorry, I've been meaning to respond for a while.

This is kinda ugly, but I can't think of a better way to do it. I'm fine with 
this, but given that it's a pretty invasive change, I'm not comfortable 
accepting. You may wanna ping @EricWF and @mclow.lists directly.


https://reviews.llvm.org/D32411



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


[PATCH] D34342: [OpenCL] Fix code generation of function-scope constant samplers.

2017-06-27 Thread Alexey Bader via Phabricator via cfe-commits
bader added a comment.

Note: `get_sampler_initializer` from my test case returns integer, not a 
sampler, but having function is not relevant to the problem. 
Here is a bit simplified test case without function calls that still reproduces 
the problem:

  kernel void foo(int sampler_init_value) {
const sampler_t const_smp_func_init = sampler_init_value;
  }

The problem is in the function that handles sampler initialization with integer.
There should no problems with the case you provided as it doesn't require 
additional function call injection.


https://reviews.llvm.org/D34342



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


[PATCH] D34663: Update test for enabling ICP for AutoFDO.

2017-06-27 Thread David Li via Phabricator via cfe-commits
davidxl added inline comments.



Comment at: test/CodeGen/pgo-sample-thinlto-summary.c:39
+// O2: if.true.direct_targ
 // ThinLTO-NOT: if.true.direct_targ
 void icp(void (*p)()) {

Is the thinLTO behavior here expected?


https://reviews.llvm.org/D34663



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


[PATCH] D34663: Update test for enabling ICP for AutoFDO.

2017-06-27 Thread Dehao Chen via Phabricator via cfe-commits
danielcdh added inline comments.



Comment at: test/CodeGen/pgo-sample-thinlto-summary.c:39
+// O2: if.true.direct_targ
 // ThinLTO-NOT: if.true.direct_targ
 void icp(void (*p)()) {

davidxl wrote:
> Is the thinLTO behavior here expected?
Yes, it's expected, icp is turned off for the samplepgo thinlto summary phase 
(details in https://reviews.llvm.org/D31217)


https://reviews.llvm.org/D34663



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


[PATCH] D34663: Update test for enabling ICP for AutoFDO.

2017-06-27 Thread David Li via Phabricator via cfe-commits
davidxl accepted this revision.
davidxl added a comment.
This revision is now accepted and ready to land.

lgtm


https://reviews.llvm.org/D34663



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


r306430 - Update test for enabling ICP for AutoFDO.

2017-06-27 Thread Dehao Chen via cfe-commits
Author: dehao
Date: Tue Jun 27 10:23:42 2017
New Revision: 306430

URL: http://llvm.org/viewvc/llvm-project?rev=306430&view=rev
Log:
Update test for enabling ICP for AutoFDO.

Summary: This is the test update patch for https://reviews.llvm.org/D34662

Reviewers: davidxl

Reviewed By: davidxl

Subscribers: cfe-commits, sanjoy, mehdi_amini, eraman, llvm-commits

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

Modified:
cfe/trunk/test/CodeGen/pgo-sample-thinlto-summary.c

Modified: cfe/trunk/test/CodeGen/pgo-sample-thinlto-summary.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/pgo-sample-thinlto-summary.c?rev=306430&r1=306429&r2=306430&view=diff
==
--- cfe/trunk/test/CodeGen/pgo-sample-thinlto-summary.c (original)
+++ cfe/trunk/test/CodeGen/pgo-sample-thinlto-summary.c Tue Jun 27 10:23:42 2017
@@ -32,10 +32,10 @@ void unroll() {
 baz(i);
 }
 
-// Check that icp is not invoked (both -O2 and ThinLTO).
+// Check that icp is not invoked for ThinLTO, but invoked for -O2.
 // O2-LABEL: define void @icp
 // THINLTO-LABEL: define void @icp
-// O2-NOT: if.true.direct_targ
+// O2: if.true.direct_targ
 // ThinLTO-NOT: if.true.direct_targ
 void icp(void (*p)()) {
   p();


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


[PATCH] D34275: [analyzer] Re-implemente current virtual calls checker in a path-sensitive way

2017-06-27 Thread wangxin via Phabricator via cfe-commits
wangxindsb updated this revision to Diff 104201.
wangxindsb marked an inline comment as done.
wangxindsb added a comment.

-Fix the bug of the virtual call during a function call of the object.
-Add flag for the PUREONLY.


https://reviews.llvm.org/D34275

Files:
  lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp
  test/Analysis/virtualcall.cpp

Index: test/Analysis/virtualcall.cpp
===
--- test/Analysis/virtualcall.cpp
+++ test/Analysis/virtualcall.cpp
@@ -1,79 +1,43 @@
 // RUN: %clang_analyze_cc1 -analyzer-checker=optin.cplusplus.VirtualCall -analyzer-store region -verify -std=c++11 %s
-// RUN: %clang_analyze_cc1 -analyzer-checker=optin.cplusplus.VirtualCall -analyzer-store region -analyzer-config optin.cplusplus.VirtualCall:Interprocedural=true -DINTERPROCEDURAL=1 -verify -std=c++11 %s
-// RUN: %clang_analyze_cc1 -analyzer-checker=optin.cplusplus.VirtualCall -analyzer-store region -analyzer-config optin.cplusplus.VirtualCall:PureOnly=true -DPUREONLY=1 -verify -std=c++11 %s
 
-/* When INTERPROCEDURAL is set, we expect diagnostics in all functions reachable
-   from a constructor or destructor. If it is not set, we expect diagnostics
-   only in the constructor or destructor.
-
-   When PUREONLY is set, we expect diagnostics only for calls to pure virtual
-   functions not to non-pure virtual functions.
-*/
+// RUN: %clang_analyze_cc1 -analyzer-checker=optin.cplusplus.VirtualCall -analyzer-store region -analyzer-config optin.cplusplus.VirtualCall:PureOnly=true -DPUREONLY=1 -verify -std=c++11 %s
 
 class A {
 public:
   A();
-  A(int i);
 
   ~A() {};
   
-  virtual int foo() = 0; // from Sema: expected-note {{'foo' declared here}}
-  virtual void bar() = 0;
+  virtual int foo()=0;
+  virtual void bar()=0;
   void f() {
 foo();
-#if INTERPROCEDURAL
-// expected-warning-re@-2 ^}}Call Path : foo <-- fCall to pure virtual function during construction has undefined behavior}}
-#endif
+// expected-warning:Call to virtual function during construction
   }
 };
 
 class B : public A {
 public:
   B() {
 foo();
-#if !PUREONLY
-#if INTERPROCEDURAL
-// expected-warning-re@-3 ^}}Call Path : fooCall to virtual function during construction will not dispatch to derived class}}
-#else
-// expected-warning-re@-5 ^}}Call to virtual function during construction will not dispatch to derived class}}
-#endif
-#endif
-
+// expected-warning:Call to virtual function during construction
   }
   ~B();
   
   virtual int foo();
   virtual void bar() { foo(); }
-#if INTERPROCEDURAL
-  // expected-warning-re@-2 ^}}Call Path : foo <-- barCall to virtual function during destruction will not dispatch to derived class}}
-#endif
+  // expected-warning:Call to virtual function during destruction
 };
 
 A::A() {
   f();
 }
 
-A::A(int i) {
-  foo(); // From Sema: expected-warning {{call to pure virtual member function 'foo' has undefined behavior}}
-#if INTERPROCEDURAL
-  // expected-warning-re@-2 ^}}Call Path : fooCall to pure virtual function during construction has undefined behavior}}
-#else
-  // expected-warning-re@-4 ^}}Call to pure virtual function during construction has undefined behavior}}
-#endif
-}
-
 B::~B() {
   this->B::foo(); // no-warning
   this->B::bar();
   this->foo();
-#if !PUREONLY
-#if INTERPROCEDURAL
-  // expected-warning-re@-3 ^}}Call Path : fooCall to virtual function during destruction will not dispatch to derived class}}
-#else
-  // expected-warning-re@-5 ^}}Call to virtual function during destruction will not dispatch to derived class}}
-#endif
-#endif
-
+  // expected-warning:Call to virtual function during destruction
 }
 
 class C : public B {
@@ -87,13 +51,7 @@
 
 C::C() {
   f(foo());
-#if !PUREONLY
-#if INTERPROCEDURAL
-  // expected-warning-re@-3 ^}}Call Path : fooCall to virtual function during construction will not dispatch to derived class}}
-#else
-  // expected-warning-re@-5 ^}}Call to virtual function during construction will not dispatch to derived class}}
-#endif
-#endif
+  // expected-warning:Call to virtual function during construction
 }
 
 class D : public B {
@@ -103,7 +61,8 @@
   }
   ~D() { bar(); }
   int foo() final;
-  void bar() final { foo(); } // no-warning
+  void bar() final { foo(); } 
+  // no-warning
 };
 
 class E final : public B {
@@ -115,7 +74,6 @@
   int foo() override;
 };
 
-// Regression test: don't crash when there's no direct callee.
 class F {
 public:
   F() {
@@ -125,17 +83,88 @@
   void foo();
 };
 
-int main() {
-  A *a;
-  B *b;
-  C *c;
-  D *d;
-  E *e;
-  F *f;
-}
+class G {
+public:
+  virtual void bar();
+  void foo() {
+bar();
+  // no warning
+  }
+};
+
+class H{
+public:
+  H() : initState(0) { init(); }
+  int initState;
+  virtual void f() const;
+  void init() {
+if (initState)
+  f();
+  // no warning
+  }
+
+  H(int i) {
+G g;
+g.fo

r306433 - [x86] weaken test checks that shouldn't be here in the first place

2017-06-27 Thread Sanjay Patel via cfe-commits
Author: spatel
Date: Tue Jun 27 10:39:46 2017
New Revision: 306433

URL: http://llvm.org/viewvc/llvm-project?rev=306433&view=rev
Log:
[x86] weaken test checks that shouldn't be here in the first place

This test would fail after the proposed change in:
https://reviews.llvm.org/D34242

Modified:
cfe/trunk/test/CodeGen/avx512f-builtins.c

Modified: cfe/trunk/test/CodeGen/avx512f-builtins.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/avx512f-builtins.c?rev=306433&r1=306432&r2=306433&view=diff
==
--- cfe/trunk/test/CodeGen/avx512f-builtins.c (original)
+++ cfe/trunk/test/CodeGen/avx512f-builtins.c Tue Jun 27 10:39:46 2017
@@ -1,4 +1,7 @@
 // RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin 
-target-feature +avx512f -emit-llvm -o - -Wall -Werror | FileCheck %s
+
+// FIXME: It's wrong to check LLVM IR transformations from clang. This run 
should be removed and tests added to the appropriate LLVM pass.
+
 // RUN: %clang_cc1 -ffreestanding %s -triple=x86_64-apple-darwin 
-target-feature +avx512f -O2 -emit-llvm -o - -Wall -Werror | FileCheck %s 
-check-prefix=O2
 
 #include 
@@ -8240,10 +8243,10 @@ __m128 test_mm_mask_move_ss (__m128 __W,
 {
   // O2-LABEL: @test_mm_mask_move_ss
   // O2: %[[M:.*]] = and i8 %__U, 1
-  // O2: %[[M2:.*]] = icmp ne i8 %[[M]], 0
-  // O2: %[[ELM1:.*]] = extractelement <4 x float> %__B, i32 0
-  // O2: %[[ELM2:.*]] = extractelement <4 x float> %__W, i32 0
-  // O2: %[[SEL:.*]] = select i1 %[[M2]], float %[[ELM1]], float %[[ELM2]]
+  // O2: %[[M2:.*]] = icmp 
+  // O2: %[[ELM1:.*]] = extractelement <4 x float> 
+  // O2: %[[ELM2:.*]] = extractelement <4 x float> 
+  // O2: %[[SEL:.*]] = select i1 %[[M2]]
   // O2: %[[RES:.*]] = insertelement <4 x float> %__A, float %[[SEL]], i32 0
   // O2: ret <4 x float> %[[RES]]
   return _mm_mask_move_ss ( __W,  __U,  __A,  __B);
@@ -8253,9 +8256,9 @@ __m128 test_mm_maskz_move_ss (__mmask8 _
 {
   // O2-LABEL: @test_mm_maskz_move_ss
   // O2: %[[M:.*]] = and i8 %__U, 1
-  // O2: %[[M2:.*]] = icmp ne i8 %[[M]], 0
+  // O2: %[[M2:.*]] = icmp
   // O2: %[[ELM1:.*]] = extractelement <4 x float> %__B, i32 0
-  // O2: %[[SEL:.*]] = select i1 %[[M2]], float %[[ELM1]], float 0.0 
+  // O2: %[[SEL:.*]] = select i1 %[[M2]] 
   // O2: %[[RES:.*]] = insertelement <4 x float> %__A, float %[[SEL]], i32 0
   // O2: ret <4 x float> %[[RES]]
   return _mm_maskz_move_ss (__U, __A, __B);
@@ -8265,10 +8268,10 @@ __m128d test_mm_mask_move_sd (__m128d __
 {
   // O2-LABEL: @test_mm_mask_move_sd
   // O2: %[[M:.*]] = and i8 %__U, 1
-  // O2: %[[M2:.*]] = icmp ne i8 %[[M]], 0
-  // O2: %[[ELM1:.*]] = extractelement <2 x double> %__B, i32 0
-  // O2: %[[ELM2:.*]] = extractelement <2 x double> %__W, i32 0
-  // O2: %[[SEL:.*]] = select i1 %[[M2]], double %[[ELM1]], double %[[ELM2]]
+  // O2: %[[M2:.*]] = icmp
+  // O2: %[[ELM1:.*]] = extractelement <2 x double>
+  // O2: %[[ELM2:.*]] = extractelement <2 x double>
+  // O2: %[[SEL:.*]] = select i1 %[[M2]]
   // O2: %[[RES:.*]] = insertelement <2 x double> %__A, double %[[SEL]], i32 0
   // O2: ret <2 x double> %[[RES]]
   return _mm_mask_move_sd ( __W,  __U,  __A,  __B);
@@ -8278,9 +8281,9 @@ __m128d test_mm_maskz_move_sd (__mmask8
 {
   // O2-LABEL: @test_mm_maskz_move_sd
   // O2: %[[M:.*]] = and i8 %__U, 1
-  // O2: %[[M2:.*]] = icmp ne i8 %[[M]], 0
+  // O2: %[[M2:.*]] = icmp
   // O2: %[[ELM1:.*]] = extractelement <2 x double> %__B, i32 0
-  // O2: %[[SEL:.*]] = select i1 %[[M2]], double %[[ELM1]], double 0.0
+  // O2: %[[SEL:.*]] = select i1 %[[M2]]
   // O2: %[[RES:.*]] = insertelement <2 x double> %__A, double %[[SEL]], i32 0
   // O2: ret <2 x double> %[[RES]]
   return _mm_maskz_move_sd (__U, __A, __B);


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


r306434 - Update the test comment to clarify the intention of the test.

2017-06-27 Thread Dehao Chen via cfe-commits
Author: dehao
Date: Tue Jun 27 10:45:40 2017
New Revision: 306434

URL: http://llvm.org/viewvc/llvm-project?rev=306434&view=rev
Log:
Update the test comment to clarify the intention of the test.

Modified:
cfe/trunk/test/CodeGen/pgo-sample-thinlto-summary.c

Modified: cfe/trunk/test/CodeGen/pgo-sample-thinlto-summary.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/pgo-sample-thinlto-summary.c?rev=306434&r1=306433&r2=306434&view=diff
==
--- cfe/trunk/test/CodeGen/pgo-sample-thinlto-summary.c (original)
+++ cfe/trunk/test/CodeGen/pgo-sample-thinlto-summary.c Tue Jun 27 10:45:40 2017
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -O2 
-fprofile-sample-use=%S/Inputs/pgo-sample-thinlto-summary.prof %s -emit-llvm -o 
- 2>&1 | FileCheck %s -check-prefix=O2
+// RUN: %clang_cc1 -O2 
-fprofile-sample-use=%S/Inputs/pgo-sample-thinlto-summary.prof %s -emit-llvm -o 
- 2>&1 | FileCheck %s -check-prefix=SAMPLEPGO
 // RUN: %clang_cc1 -O2 
-fprofile-sample-use=%S/Inputs/pgo-sample-thinlto-summary.prof %s -emit-llvm 
-flto=thin -o - 2>&1 | FileCheck %s -check-prefix=THINLTO
 // Checks if hot call is inlined by normal compile, but not inlined by
 // thinlto compile.
@@ -11,9 +11,9 @@ void foo(int n) {
 g += baz(i);
 }
 
-// O2-LABEL: define void @bar
+// SAMPLEPGO-LABEL: define void @bar
 // THINLTO-LABEL: define void @bar
-// O2-NOT: call{{.*}}foo
+// SAMPLEPGO-NOT: call{{.*}}foo
 // THINLTO: call{{.*}}foo
 void bar(int n) {
   for (int i = 0; i < n; i++)
@@ -21,10 +21,10 @@ void bar(int n) {
 }
 
 // Checks if loop unroll is invoked by normal compile, but not thinlto compile.
-// O2-LABEL: define void @unroll
+// SAMPLEPGO-LABEL: define void @unroll
 // THINLTO-LABEL: define void @unroll
-// O2: call{{.*}}baz
-// O2: call{{.*}}baz
+// SAMPLEPGO: call{{.*}}baz
+// SAMPLEPGO: call{{.*}}baz
 // THINLTO: call{{.*}}baz
 // THINLTO-NOT: call{{.*}}baz
 void unroll() {
@@ -32,10 +32,10 @@ void unroll() {
 baz(i);
 }
 
-// Check that icp is not invoked for ThinLTO, but invoked for -O2.
-// O2-LABEL: define void @icp
+// Checks that icp is not invoked for ThinLTO, but invoked for normal 
samplepgo.
+// SAMPLEPGO-LABEL: define void @icp
 // THINLTO-LABEL: define void @icp
-// O2: if.true.direct_targ
+// SAMPLEPGO: if.true.direct_targ
 // ThinLTO-NOT: if.true.direct_targ
 void icp(void (*p)()) {
   p();


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


[libunwind] r306442 - [libunwind] Add _LIBUNWIND_DISABLE_VISIBILITY_ANNOTATIONS

2017-06-27 Thread Nico Weber via cfe-commits
Author: nico
Date: Tue Jun 27 11:37:06 2017
New Revision: 306442

URL: http://llvm.org/viewvc/llvm-project?rev=306442&view=rev
Log:
[libunwind] Add _LIBUNWIND_DISABLE_VISIBILITY_ANNOTATIONS

It's useful to be able to disable visibility annotations entirely; for
example, if we're building libunwind static to include in another library,
and we don't want any libunwind functions getting exported out of that
library.

https://reviews.llvm.org/D34637
Patch from Thomas Anderson !

Modified:
libunwind/trunk/src/config.h

Modified: libunwind/trunk/src/config.h
URL: 
http://llvm.org/viewvc/llvm-project/libunwind/trunk/src/config.h?rev=306442&r1=306441&r2=306442&view=diff
==
--- libunwind/trunk/src/config.h (original)
+++ libunwind/trunk/src/config.h Tue Jun 27 11:37:06 2017
@@ -44,9 +44,14 @@
   #endif
 #endif
 
-// FIXME: these macros are not correct for COFF targets
-#define _LIBUNWIND_EXPORT __attribute__((visibility("default")))
-#define _LIBUNWIND_HIDDEN __attribute__((visibility("hidden")))
+#if defined(_LIBUNWIND_DISABLE_VISIBILITY_ANNOTATIONS)
+  #define _LIBUNWIND_EXPORT
+  #define _LIBUNWIND_HIDDEN
+#else
+  // FIXME: these macros are not correct for COFF targets
+  #define _LIBUNWIND_EXPORT __attribute__((visibility("default")))
+  #define _LIBUNWIND_HIDDEN __attribute__((visibility("hidden")))
+#endif
 
 #if (defined(__APPLE__) && defined(__arm__)) || 
defined(__USING_SJLJ_EXCEPTIONS__)
 #define _LIBUNWIND_BUILD_SJLJ_APIS


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


r306444 - CodeGen: load indirect ObjC ARC arguments in prologue

2017-06-27 Thread Saleem Abdulrasool via cfe-commits
Author: compnerd
Date: Tue Jun 27 11:37:51 2017
New Revision: 306444

URL: http://llvm.org/viewvc/llvm-project?rev=306444&view=rev
Log:
CodeGen: load indirect ObjC ARC arguments in prologue

When generating a prologue, add loads for ARC arguments passed
indirectly.

Patch by Dave Lee!

Added:
cfe/trunk/test/CodeGenObjCXX/arc-indirect.mm
Modified:
cfe/trunk/lib/CodeGen/CGDecl.cpp

Modified: cfe/trunk/lib/CodeGen/CGDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDecl.cpp?rev=306444&r1=306443&r2=306444&view=diff
==
--- cfe/trunk/lib/CodeGen/CGDecl.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGDecl.cpp Tue Jun 27 11:37:51 2017
@@ -1860,6 +1860,10 @@ void CodeGenFunction::EmitParmDecl(const
 lt = Qualifiers::OCL_ExplicitNone;
   }
 
+  // Load objects passed indirectly.
+  if (Arg.isIndirect() && !ArgVal)
+ArgVal = Builder.CreateLoad(DeclPtr);
+
   if (lt == Qualifiers::OCL_Strong) {
 if (!isConsumed) {
   if (CGM.getCodeGenOpts().OptimizationLevel == 0) {

Added: cfe/trunk/test/CodeGenObjCXX/arc-indirect.mm
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjCXX/arc-indirect.mm?rev=306444&view=auto
==
--- cfe/trunk/test/CodeGenObjCXX/arc-indirect.mm (added)
+++ cfe/trunk/test/CodeGenObjCXX/arc-indirect.mm Tue Jun 27 11:37:51 2017
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -std=c++11 -triple i686-unknown-windows-msvc 
-fobjc-runtime=gnustep -fobjc-arc -Wno-objc-root-class -emit-llvm -o - %s | 
FileCheck -check-prefixes CHECK,CHECK-GNUSTEP %s
+// RUN: %clang_cc1 -std=c++11 -triple i686-unknown-windows-msvc 
-fobjc-runtime=macosx -fobjc-arc -Wno-objc-root-class -emit-llvm -o - %s | 
FileCheck -check-prefixes CHECK,CHECK-DARWIN %s
+// RUN: %clang_cc1 -std=c++11 -triple i686-unknown-windows-msvc 
-fobjc-runtime=ios -fobjc-arc -Wno-objc-root-class -emit-llvm -o - %s | 
FileCheck -check-prefixes CHECK,CHECK-DARWIN %s
+
+// non trivially copyable, forces inalloca
+struct S {
+  S(const S &s) {}
+};
+
+@interface C
+@end
+@implementation C
+- (void)object:(id)obj struct:(S)s {
+}
+@end
+
+// CHECK-GNUSTEP: define internal void @_i_C__object_struct_(<{ %0*, i8*, i8*, 
%struct.S, [3 x i8] }>* inalloca)
+// CHECK-DARWIN: define internal void @"\01-[C object:struct:]"(<{ %0*, i8*, 
i8*, %struct.S, [3 x i8] }>* inalloca)
+// CHECK: %obj = getelementptr inbounds <{ %0*, i8*, i8*, %struct.S, [3 x i8] 
}>, <{ %0*, i8*, i8*, %struct.S, [3 x i8] }>* %0, i32 0, i32 2
+// CHECK: %1 = load i8*, i8** %obj, align 4
+// CHECK: call void @objc_storeStrong(i8** %obj, i8* %1)


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


[PATCH] D34580: [CodeGen][ObjC] Load indirect ARC arguments in prolog

2017-06-27 Thread Saleem Abdulrasool via Phabricator via cfe-commits
compnerd closed this revision.
compnerd added a comment.

SVN r306444


https://reviews.llvm.org/D34580



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


[PATCH] D34665: [CodeGen] Fix assertion failure in EmitCallArg

2017-06-27 Thread John McCall via Phabricator via cfe-commits
rjmccall accepted this revision.
rjmccall added a comment.
This revision is now accepted and ready to land.

This seems fine, thanks.


https://reviews.llvm.org/D34665



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


r306447 - test: fix test for release builds

2017-06-27 Thread Saleem Abdulrasool via cfe-commits
Author: compnerd
Date: Tue Jun 27 11:57:50 2017
New Revision: 306447

URL: http://llvm.org/viewvc/llvm-project?rev=306447&view=rev
Log:
test: fix test for release builds

Use a regex capture to avoid hardcoding the name.  This should repair
the failing buildbot.

Modified:
cfe/trunk/test/CodeGenObjCXX/arc-indirect.mm

Modified: cfe/trunk/test/CodeGenObjCXX/arc-indirect.mm
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjCXX/arc-indirect.mm?rev=306447&r1=306446&r2=306447&view=diff
==
--- cfe/trunk/test/CodeGenObjCXX/arc-indirect.mm (original)
+++ cfe/trunk/test/CodeGenObjCXX/arc-indirect.mm Tue Jun 27 11:57:50 2017
@@ -9,6 +9,7 @@ struct S {
 
 @interface C
 @end
+
 @implementation C
 - (void)object:(id)obj struct:(S)s {
 }
@@ -17,5 +18,5 @@ struct S {
 // CHECK-GNUSTEP: define internal void @_i_C__object_struct_(<{ %0*, i8*, i8*, 
%struct.S, [3 x i8] }>* inalloca)
 // CHECK-DARWIN: define internal void @"\01-[C object:struct:]"(<{ %0*, i8*, 
i8*, %struct.S, [3 x i8] }>* inalloca)
 // CHECK: %obj = getelementptr inbounds <{ %0*, i8*, i8*, %struct.S, [3 x i8] 
}>, <{ %0*, i8*, i8*, %struct.S, [3 x i8] }>* %0, i32 0, i32 2
-// CHECK: %1 = load i8*, i8** %obj, align 4
-// CHECK: call void @objc_storeStrong(i8** %obj, i8* %1)
+// CHECK: %[[INSTANCE:[0-9]+]] = load i8*, i8** %obj, align 4
+// CHECK: call void @objc_storeStrong(i8** %obj, i8* %[[INSTANCE]])


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


[PATCH] D34449: [clang-tidy] Enable constexpr definitions in headers.

2017-06-27 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a comment.

BTW, could you please also update the 
`docs/clang-tidy/checks/misc-definitions-in-headers.rst`?




Comment at: test/clang-tidy/misc-definitions-in-headers-1z.hpp:5
+class CE {
+  constexpr static int i = 5;
+};

Could you follow the way of comment in the 
`misc-definitions-in-headers-1z.hpp`? For each allowed case, add the comment 
like `constexpr static int i = 5; // OK: inline variable definition.`

The same below.



Comment at: test/clang-tidy/misc-definitions-in-headers-1z.hpp:10
+
+constexpr int a = 1;
+

I think this case is allowed because of internal linkage. I'd suggesting 
putting it to `misc-definitions-in-headers.hpp`.


https://reviews.llvm.org/D34449



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


[PATCH] D34198: Fix __has_trivial_destructor crash when the type is incomplete with unknown array bounds.

2017-06-27 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith accepted this revision.
rsmith added a comment.

LGTM, thanks. Do you need someone to commit for you?


https://reviews.llvm.org/D34198



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


[PATCH] D34444: Teach codegen to work in incremental processing mode.

2017-06-27 Thread John McCall via Phabricator via cfe-commits
rjmccall added a comment.

What's the relationship between these llvm::Modules that you want to generate?  
Are you imagining them as separate translation units, or are the subsequent 
modules more like addenda to the original?


Repository:
  rL LLVM

https://reviews.llvm.org/D3



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


[PATCH] D34444: Teach codegen to work in incremental processing mode.

2017-06-27 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev added a comment.

We use them as separate translation units due to the fact that we need to 
survive multiple calls to `HandleEndOfTranslationUnit`. This 'finalizes' the 
module, and we cannot write to it anymore. Even though we could write to it 
(this was the case when we were using the old JIT), with the orc infrastructure 
we generate machine code for the whole module.


Repository:
  rL LLVM

https://reviews.llvm.org/D3



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


[PATCH] D34329: [clang-diff] Initial implementation.

2017-06-27 Thread Johannes Altmanninger via Phabricator via cfe-commits
johannes updated this revision to Diff 104249.
johannes added a comment.

- pass Options as a const reference instead of a pointer
- rename TreeComparator -> ASTDiff::Impl, rename Comparator -> DiffImpl
- move declaration of ASTDiff::Impl from the header to the source file so that 
Options does not need to be an opaque pointer
- rename SyntaxTreeI -> SyntaxTreeImpl


https://reviews.llvm.org/D34329

Files:
  include/clang/Tooling/ASTDiff/ASTDiff.h
  include/clang/Tooling/ASTDiff/ASTDiffInternal.h
  lib/Tooling/ASTDiff/ASTDiff.cpp
  lib/Tooling/ASTDiff/CMakeLists.txt
  lib/Tooling/CMakeLists.txt
  test/Tooling/clang-diff-basic.cpp
  tools/CMakeLists.txt
  tools/clang-diff/CMakeLists.txt
  tools/clang-diff/ClangDiff.cpp

Index: tools/clang-diff/ClangDiff.cpp
===
--- /dev/null
+++ tools/clang-diff/ClangDiff.cpp
@@ -0,0 +1,110 @@
+//===- ClangDiff.cpp - compare source files by AST nodes --*- C++ -*- -===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+//
+// This file implements a tool for syntax tree based comparison using
+// Tooling/ASTDiff.
+//
+//===--===//
+
+#include "clang/Tooling/ASTDiff/ASTDiff.h"
+#include "clang/Tooling/CommonOptionsParser.h"
+#include "clang/Tooling/Tooling.h"
+#include "llvm/Support/CommandLine.h"
+
+using namespace llvm;
+using namespace clang;
+using namespace clang::tooling;
+
+static cl::OptionCategory ClangDiffCategory("clang-diff options");
+
+static cl::opt
+DumpAST("ast-dump",
+cl::desc("Print the internal representation of the AST as JSON."),
+cl::init(false), cl::cat(ClangDiffCategory));
+
+static cl::opt NoCompilationDatabase(
+"no-compilation-database",
+cl::desc(
+"Do not attempt to load build settings from a compilation database"),
+cl::init(false), cl::cat(ClangDiffCategory));
+
+static cl::opt SourcePath(cl::Positional, cl::desc(""),
+   cl::Required,
+   cl::cat(ClangDiffCategory));
+
+static cl::opt DestinationPath(cl::Positional,
+cl::desc(""),
+cl::Optional,
+cl::cat(ClangDiffCategory));
+
+static std::unique_ptr getAST(const StringRef Filename) {
+  std::string ErrorMessage;
+  std::unique_ptr Compilations;
+  if (!NoCompilationDatabase)
+Compilations =
+CompilationDatabase::autoDetectFromSource(Filename, ErrorMessage);
+  if (!Compilations) {
+if (!NoCompilationDatabase)
+  llvm::errs()
+  << "Error while trying to load a compilation database, running "
+ "without flags.\n"
+  << ErrorMessage;
+Compilations = llvm::make_unique(
+".", std::vector());
+  }
+  std::array Files = {{Filename}};
+  ClangTool Tool(*Compilations, Files);
+  std::vector> ASTs;
+  Tool.buildASTs(ASTs);
+  if (ASTs.size() != Files.size())
+return nullptr;
+  return std::move(ASTs[0]);
+}
+
+int main(int argc, const char **argv) {
+  cl::HideUnrelatedOptions(ClangDiffCategory);
+  if (!cl::ParseCommandLineOptions(argc, argv)) {
+cl::PrintOptionValues();
+return 1;
+  }
+
+  if (DumpAST) {
+if (!DestinationPath.empty()) {
+  llvm::errs() << "Error: Please specify exactly one filename.\n";
+  return 1;
+}
+std::unique_ptr AST = getAST(SourcePath);
+if (!AST)
+  return 1;
+diff::SyntaxTree Tree(AST->getASTContext());
+Tree.printAsJson(llvm::outs());
+return 0;
+  }
+
+  if (DestinationPath.empty()) {
+llvm::errs() << "Error: Exactly two paths are required.\n";
+return 1;
+  }
+
+  std::unique_ptr Src = getAST(SourcePath);
+  std::unique_ptr Dst = getAST(DestinationPath);
+  if (!Src || !Dst)
+return 1;
+
+  diff::ComparisonOptions Options;
+  diff::SyntaxTree SrcTree(Src->getASTContext());
+  diff::SyntaxTree DstTree(Dst->getASTContext());
+  diff::ASTDiff DiffTool(SrcTree, DstTree, Options);
+  for (const auto &Match : DiffTool.getMatches())
+DiffTool.printMatch(llvm::outs(), Match);
+  for (const auto &Change : DiffTool.getChanges())
+DiffTool.printChange(llvm::outs(), Change);
+
+  return 0;
+}
Index: tools/clang-diff/CMakeLists.txt
===
--- /dev/null
+++ tools/clang-diff/CMakeLists.txt
@@ -0,0 +1,13 @@
+set(LLVM_LINK_COMPONENTS
+  Support
+  )
+
+add_clang_executable(clang-diff
+  ClangDiff.cpp
+  )
+
+target_link_libraries(clang-diff
+  clangFrontend
+  clangTooling
+  clangToolingASTDiff
+  )
Index: tools/CMakeLists.txt
===
--- too

[PATCH] D34706: [COFF, ARM64] Add support for Windows ARM64 COFF format

2017-06-27 Thread Mandeep Singh Grang via Phabricator via cfe-commits
mgrang created this revision.
Herald added subscribers: kristof.beyls, aemerson.

This is the clang part of the initial implementation to support Windows ARM64 
COFF format.


https://reviews.llvm.org/D34706

Files:
  lib/Basic/Targets.cpp
  test/Preprocessor/predefined-macros.c


Index: test/Preprocessor/predefined-macros.c
===
--- test/Preprocessor/predefined-macros.c
+++ test/Preprocessor/predefined-macros.c
@@ -185,3 +185,9 @@
 // CHECK-CL20-NOT: #define __FAST_RELAXED_MATH__ 1
 // CHECK-FRM: #define __FAST_RELAXED_MATH__ 1
 
+// RUN: %clang_cc1 -triple aarch64-windows %s -E -dM -o - -x cl \
+// RUN:   | FileCheck -match-full-lines %s --check-prefix=CHECK-ARM64-WIN
+
+// CHECK-ARM64-WIN: #define _M_ARM64 1
+// CHECK-ARM64-WIN: #define _WIN32 1
+// CHECK-ARM64-WIN: #define _WIN64 1
Index: lib/Basic/Targets.cpp
===
--- lib/Basic/Targets.cpp
+++ lib/Basic/Targets.cpp
@@ -6550,6 +6550,43 @@
   }
 };
 
+class MicrosoftARM64leTargetInfo
+: public WindowsTargetInfo {
+  const llvm::Triple Triple;
+
+public:
+  MicrosoftARM64leTargetInfo(const llvm::Triple &Triple,
+ const TargetOptions &Opts)
+  : WindowsTargetInfo(Triple, Opts), Triple(Triple) {
+WCharType = UnsignedShort;
+SizeType = UnsignedLongLong;
+TheCXXABI.set(TargetCXXABI::Microsoft);
+  }
+
+  void setDataLayout() override {
+resetDataLayout("e-m:w-i64:64-i128:128-n32:64-S128");
+  }
+
+  void getVisualStudioDefines(const LangOptions &Opts,
+  MacroBuilder &Builder) const {
+WindowsTargetInfo::getVisualStudioDefines(Opts,
+   Builder);
+Builder.defineMacro("_WIN32", "1");
+Builder.defineMacro("_WIN64", "1");
+Builder.defineMacro("_M_ARM64", "1");
+  }
+
+  void getTargetDefines(const LangOptions &Opts,
+MacroBuilder &Builder) const override {
+WindowsTargetInfo::getTargetDefines(Opts, Builder);
+getVisualStudioDefines(Opts, Builder);
+  }
+
+  BuiltinVaListKind getBuiltinVaListKind() const override {
+return TargetInfo::CharPtrBuiltinVaList;
+  }
+};
+
 class AArch64beTargetInfo : public AArch64TargetInfo {
   void setDataLayout() override {
 assert(!getTriple().isOSBinFormatMachO());
@@ -9264,6 +9301,8 @@
   return new NetBSDTargetInfo(Triple, Opts);
 case llvm::Triple::OpenBSD:
   return new OpenBSDTargetInfo(Triple, Opts);
+   case llvm::Triple::Win32:
+ return new MicrosoftARM64leTargetInfo(Triple, Opts);
 default:
   return new AArch64leTargetInfo(Triple, Opts);
 }


Index: test/Preprocessor/predefined-macros.c
===
--- test/Preprocessor/predefined-macros.c
+++ test/Preprocessor/predefined-macros.c
@@ -185,3 +185,9 @@
 // CHECK-CL20-NOT: #define __FAST_RELAXED_MATH__ 1
 // CHECK-FRM: #define __FAST_RELAXED_MATH__ 1
 
+// RUN: %clang_cc1 -triple aarch64-windows %s -E -dM -o - -x cl \
+// RUN:   | FileCheck -match-full-lines %s --check-prefix=CHECK-ARM64-WIN
+
+// CHECK-ARM64-WIN: #define _M_ARM64 1
+// CHECK-ARM64-WIN: #define _WIN32 1
+// CHECK-ARM64-WIN: #define _WIN64 1
Index: lib/Basic/Targets.cpp
===
--- lib/Basic/Targets.cpp
+++ lib/Basic/Targets.cpp
@@ -6550,6 +6550,43 @@
   }
 };
 
+class MicrosoftARM64leTargetInfo
+: public WindowsTargetInfo {
+  const llvm::Triple Triple;
+
+public:
+  MicrosoftARM64leTargetInfo(const llvm::Triple &Triple,
+ const TargetOptions &Opts)
+  : WindowsTargetInfo(Triple, Opts), Triple(Triple) {
+WCharType = UnsignedShort;
+SizeType = UnsignedLongLong;
+TheCXXABI.set(TargetCXXABI::Microsoft);
+  }
+
+  void setDataLayout() override {
+resetDataLayout("e-m:w-i64:64-i128:128-n32:64-S128");
+  }
+
+  void getVisualStudioDefines(const LangOptions &Opts,
+  MacroBuilder &Builder) const {
+WindowsTargetInfo::getVisualStudioDefines(Opts,
+   Builder);
+Builder.defineMacro("_WIN32", "1");
+Builder.defineMacro("_WIN64", "1");
+Builder.defineMacro("_M_ARM64", "1");
+  }
+
+  void getTargetDefines(const LangOptions &Opts,
+MacroBuilder &Builder) const override {
+WindowsTargetInfo::getTargetDefines(Opts, Builder);
+getVisualStudioDefines(Opts, Builder);
+  }
+
+  BuiltinVaListKind getBuiltinVaListKind() const override {
+return TargetInfo::CharPtrBuiltinVaList;
+  }
+};
+
 class AArch64beTargetInfo : public AArch64TargetInfo {
   void setDataLayout() override {
 assert(!getTriple().isOSBinFormatMachO());
@@ -9264,6 +9301,8 @@
   return new NetBSDTargetInfo(Triple, Opts);
 case llvm::Triple::OpenBSD:
   return new OpenBSDTargetInfo

[PATCH] D34706: [COFF, ARM64] Add support for Windows ARM64 COFF format

2017-06-27 Thread Mandeep Singh Grang via Phabricator via cfe-commits
mgrang added a comment.

Here is the llvm part of this patch: https://reviews.llvm.org/D34705


https://reviews.llvm.org/D34706



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


[PATCH] D34706: [COFF, ARM64] Add support for Windows ARM64 COFF format

2017-06-27 Thread Rui Ueyama via Phabricator via cfe-commits
ruiu added inline comments.



Comment at: lib/Basic/Targets.cpp:6553
 
+class MicrosoftARM64leTargetInfo
+: public WindowsTargetInfo {

I cannot imagine there will be MicrosoftARM64beTargetInfo, so I wonder if we 
should name this MicrosoftARM64TargetInfo.


https://reviews.llvm.org/D34706



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


[PATCH] D32332: Add support for transparent overloadable functions in clang

2017-06-27 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith accepted this revision.
rsmith added a comment.
This revision is now accepted and ready to land.

LGTM, thanks!


https://reviews.llvm.org/D32332



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


RE: r306149 - Emit warning when throw exception in destruct or dealloc functions which has a

2017-06-27 Thread Keane, Erich via cfe-commits
Hi Richard:
I’m not sure if you noticed this, but my coworker did submit a review here: 
https://reviews.llvm.org/D34671 with the changes you suggested.

Thanks,
Erich

From: meta...@gmail.com [mailto:meta...@gmail.com] On Behalf Of Richard Smith
Sent: Monday, June 26, 2017 2:25 PM
To: Keane, Erich 
Cc: cfe-commits 
Subject: Re: r306149 - Emit warning when throw exception in destruct or dealloc 
functions which has a

On 23 June 2017 at 13:22, Erich Keane via cfe-commits 
mailto:cfe-commits@lists.llvm.org>> wrote:
Author: erichkeane
Date: Fri Jun 23 15:22:19 2017
New Revision: 306149

URL: http://llvm.org/viewvc/llvm-project?rev=306149&view=rev
Log:
Emit warning when throw exception in destruct or dealloc functions which has a
(possible implicit) noexcept specifier

Throwing in the destructor is not good (C++11 change try to not allow see 
below).
 But in reality, those codes are exist.
C++11 [class.dtor]p3:

A declaration of a destructor that does not have an exception-specification is
implicitly considered to have the same exception specification as an implicit
declaration.

With this change, the application worked before may now run into runtime
termination. My goal here is to emit a warning to provide only possible info to
where the code may need to be changed.

First there is no way, in compile time to identify the “throw” really throw out
of the function. Things like the call which throw out… To keep this simple,
when “throw” is seen, checking its enclosing function(only destructor and
dealloc functions) with noexcept(true) specifier emit warning.

Here is implementation detail:
A new member function CheckCXXThrowInNonThrowingFunc is added for class Sema
in Sema.h. It is used in the call to both BuildCXXThrow and
TransformCXXThrowExpr.

The function basic check if the enclosing function with non-throwing noexcept
specifer, if so emit warning for it.

The example of warning message like:
k1.cpp:18:3: warning: ''~dependent_warn'' has a (possible implicit) non-throwing

noexcept specifier. Throwing exception may cause termination.
[-Wthrow-in-dtor]
throw 1;
^

k1.cpp:43:30: note: in instantiation of member function

'dependent_warn::~dependent_warn' requested here

dependent_warn f; // cause warning

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


Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
cfe/trunk/test/CXX/except/except.spec/p11.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=306149&r1=306148&r2=306149&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Fri Jun 23 15:22:19 
2017
@@ -6351,6 +6351,15 @@ def err_exceptions_disabled : Error<
   "cannot use '%0' with exceptions disabled">;
 def err_objc_exceptions_disabled : Error<
   "cannot use '%0' with Objective-C exceptions disabled">;
+def warn_throw_in_noexcept_func
+: Warning<"%0 has a non-throwing exception specification but can still "
+  "throw, resulting in unexpected program termination">,

How do you know it's unexpected? :) You also don't know that this leads to 
program termination: a set_unexpected handler could do something else, in 
principle. I would just delete the ", resulting in unexpected program 
termination" part here.

+  InGroup;
+def note_throw_in_dtor
+: Note<"destructor or deallocator has a (possibly implicit) non-throwing "
+  "excepton specification">;

Please figure out which case we're actually in, and just mention that one. You 
can use "hasImplicitExceptionSpec" in SemaExceptionSpec.cpp to determine 
whether the exception specification is implicit.

Also, typo "excepton".

+def note_throw_in_function
+: Note<"non-throwing function declare here">;

declare -> declared, but something like "function declared non-throwing here" 
would be preferable

 def err_seh_try_outside_functions : Error<
   "cannot use SEH '__try' in blocks, captured regions, or Obj-C method decls">;
 def err_mixing_cxx_try_seh_try : Error<

Modified: cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp?rev=306149&r1=306148&r2=306149&view=diff
==
--- cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp (original)
+++ cfe/trunk/lib/Sema/AnalysisBasedWarnings.cpp Fri Jun 23 15:22:19 2017
@@ -279,6 +279,150 @@ static void checkRecursiveFunction(Sema
 }

 
//===--===//
+// Check for throw in a non-throwing function.
+//===--===//
+enum ThrowSta

[PATCH] D30946: [ScopePrinting] Added support to print full scopes of types and declarations.

2017-06-27 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

In https://reviews.llvm.org/D30946#754103, @schroedersi wrote:

> As an alternative to the current solution, the above-mentioned member 
> functions could each be extended by a "PrintingContext" argument, which then 
> contains the variable states.


I'd be interested to see how much complexity that adds, if you're prepared to 
give it a try.

> And a bit of clarification: [...] there is already some kind of temporary 
> suppress scope functionality, but it is called SuppressScope.

Yes, I think that's right -- `SuppressScope` isn't really an externally useful 
"print without scopes" mechanism, it's an internal mechanism / implementation 
detail used for printing an "inner" AST node when we've already printed a scope 
for it based on outer sugar (eg, the entity is a type component of a nested 
name specifier, or the type inside an elaborated type specifier, or the class 
name in a destructor name). It's not really `SuppressScope`, it's 
`ScopeWasAlreadyPrintedForWhateverTopLevelThingIAskedYouToPrint` =)


https://reviews.llvm.org/D30946



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


[PATCH] D34091: Support for querying the exception specification type through libclang

2017-06-27 Thread Andrew J. Bennieston via Phabricator via cfe-commits
ajbennieston added a comment.

Jon, by all means go ahead!


https://reviews.llvm.org/D34091



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


r306467 - [Sema] Allow unmarked overloadable functions.

2017-06-27 Thread George Burgess IV via cfe-commits
Author: gbiv
Date: Tue Jun 27 14:31:31 2017
New Revision: 306467

URL: http://llvm.org/viewvc/llvm-project?rev=306467&view=rev
Log:
[Sema] Allow unmarked overloadable functions.

This patch extends the `overloadable` attribute to allow for one
function with a given name to not be marked with the `overloadable`
attribute. The overload without the `overloadable` attribute will not
have its name mangled.

So, the following code is now legal:

  void foo(void) __attribute__((overloadable));
  void foo(int);
  void foo(float) __attribute__((overloadable));

In addition, this patch fixes a bug where we'd accept code with
`__attribute__((overloadable))` inconsistently applied. In other words,
we used to accept:

  void foo(void);
  void foo(void) __attribute__((overloadable));

But we will do this no longer, since it defeats the original purpose of
requiring `__attribute__((overloadable))` on all redeclarations of a
function.

This breakage seems to not be an issue in practice, since the only code
I could find that had this pattern often looked like:

  void foo(void);
  void foo(void) __attribute__((overloadable)) __asm__("foo");
  void foo(int) __attribute__((overloadable));

...Which can now be simplified by simply removing the asm label and
overloadable attribute from the redeclaration of `void foo(void);`

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

Modified:
cfe/trunk/include/clang/Basic/AttrDocs.td
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Lex/PPMacroExpansion.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/CodeGen/mangle-ms.c
cfe/trunk/test/CodeGen/mangle.c
cfe/trunk/test/CodeGenCXX/mangle-ms.cpp
cfe/trunk/test/PCH/attrs.c
cfe/trunk/test/Sema/overloadable.c

Modified: cfe/trunk/include/clang/Basic/AttrDocs.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/AttrDocs.td?rev=306467&r1=306466&r2=306467&view=diff
==
--- cfe/trunk/include/clang/Basic/AttrDocs.td (original)
+++ cfe/trunk/include/clang/Basic/AttrDocs.td Tue Jun 27 14:31:31 2017
@@ -605,20 +605,27 @@ semantics:
   for ``T`` and ``U`` to be incompatible.
 
 The declaration of ``overloadable`` functions is restricted to function
-declarations and definitions.  Most importantly, if any function with a given
-name is given the ``overloadable`` attribute, then all function declarations
-and definitions with that name (and in that scope) must have the
-``overloadable`` attribute.  This rule even applies to redeclarations of
-functions whose original declaration had the ``overloadable`` attribute, e.g.,
+declarations and definitions.  If a function is marked with the 
``overloadable``
+attribute, then all declarations and definitions of functions with that name,
+except for at most one (see the note below about unmarked overloads), must have
+the ``overloadable`` attribute.  In addition, redeclarations of a function with
+the ``overloadable`` attribute must have the ``overloadable`` attribute, and
+redeclarations of a function without the ``overloadable`` attribute must *not*
+have the ``overloadable`` attribute. e.g.,
 
 .. code-block:: c
 
   int f(int) __attribute__((overloadable));
   float f(float); // error: declaration of "f" must have the "overloadable" 
attribute
+  int f(int); // error: redeclaration of "f" must have the "overloadable" 
attribute
 
   int g(int) __attribute__((overloadable));
   int g(int) { } // error: redeclaration of "g" must also have the 
"overloadable" attribute
 
+  int h(int);
+  int h(int) __attribute__((overloadable)); // error: declaration of "h" must 
not
+// have the "overloadable" 
attribute
+
 Functions marked ``overloadable`` must have prototypes.  Therefore, the
 following code is ill-formed:
 
@@ -651,7 +658,28 @@ caveats to this use of name mangling:
   linkage specification, it's name *will* be mangled in the same way as it
   would in C.
 
-Query for this feature with ``__has_extension(attribute_overloadable)``.
+For the purpose of backwards compatibility, at most one function with the same
+name as other ``overloadable`` functions may omit the ``overloadable``
+attribute. In this case, the function without the ``overloadable`` attribute
+will not have its name mangled.
+
+For example:
+
+.. code-block:: c
+
+  // Notes with mangled names assume Itanium mangling.
+  int f(int);
+  int f(double) __attribute__((overloadable));
+  void foo() {
+f(5); // Emits a call to f (not _Z1fi, as it would with an overload that
+  // was marked with overloadable).
+f(1.0); // Emits a call to _Z1fd.
+  }
+
+Support for unmarked overloads is not present in some versions of clang. You 
may
+query for it using ``__has_extension(overloadable_unmarked)``.
+
+Query for this attribute with ``__has_attribute(overloadable)``.
   }];
 }
 

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td

[PATCH] D32332: Add support for transparent overloadable functions in clang

2017-06-27 Thread George Burgess IV via Phabricator via cfe-commits
george.burgess.iv added a comment.

Woohoo! Thanks again to both of you.


https://reviews.llvm.org/D32332



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


[PATCH] D32332: Add support for transparent overloadable functions in clang

2017-06-27 Thread George Burgess IV via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL306467: [Sema] Allow unmarked overloadable functions. 
(authored by gbiv).

Changed prior to commit:
  https://reviews.llvm.org/D32332?vs=103448&id=104277#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D32332

Files:
  cfe/trunk/include/clang/Basic/AttrDocs.td
  cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
  cfe/trunk/lib/Lex/PPMacroExpansion.cpp
  cfe/trunk/lib/Sema/SemaDecl.cpp
  cfe/trunk/test/CodeGen/mangle-ms.c
  cfe/trunk/test/CodeGen/mangle.c
  cfe/trunk/test/CodeGenCXX/mangle-ms.cpp
  cfe/trunk/test/PCH/attrs.c
  cfe/trunk/test/Sema/overloadable.c

Index: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
===
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3294,13 +3294,15 @@
   "IBOutletCollection properties should be copy/strong and not assign">,
   InGroup;
   
-def err_attribute_overloadable_missing : Error<
-  "%select{overloaded function|redeclaration of}0 %1 must have the "
-  "'overloadable' attribute">;
+def err_attribute_overloadable_mismatch : Error<
+  "redeclaration of %0 must %select{not |}1have the 'overloadable' attribute">;
 def note_attribute_overloadable_prev_overload : Note<
-  "previous overload of function is here">;
+  "previous %select{unmarked |}0overload of function is here">;
 def err_attribute_overloadable_no_prototype : Error<
   "'overloadable' function %0 must have a prototype">;
+def err_attribute_overloadable_multiple_unmarked_overloads : Error<
+  "at most one overload for a given name may lack the 'overloadable' "
+  "attribute">;
 def warn_ns_attribute_wrong_return_type : Warning<
   "%0 attribute only applies to %select{functions|methods|properties}1 that "
   "return %select{an Objective-C object|a pointer|a non-retainable pointer}2">,
Index: cfe/trunk/include/clang/Basic/AttrDocs.td
===
--- cfe/trunk/include/clang/Basic/AttrDocs.td
+++ cfe/trunk/include/clang/Basic/AttrDocs.td
@@ -605,20 +605,27 @@
   for ``T`` and ``U`` to be incompatible.
 
 The declaration of ``overloadable`` functions is restricted to function
-declarations and definitions.  Most importantly, if any function with a given
-name is given the ``overloadable`` attribute, then all function declarations
-and definitions with that name (and in that scope) must have the
-``overloadable`` attribute.  This rule even applies to redeclarations of
-functions whose original declaration had the ``overloadable`` attribute, e.g.,
+declarations and definitions.  If a function is marked with the ``overloadable``
+attribute, then all declarations and definitions of functions with that name,
+except for at most one (see the note below about unmarked overloads), must have
+the ``overloadable`` attribute.  In addition, redeclarations of a function with
+the ``overloadable`` attribute must have the ``overloadable`` attribute, and
+redeclarations of a function without the ``overloadable`` attribute must *not*
+have the ``overloadable`` attribute. e.g.,
 
 .. code-block:: c
 
   int f(int) __attribute__((overloadable));
   float f(float); // error: declaration of "f" must have the "overloadable" attribute
+  int f(int); // error: redeclaration of "f" must have the "overloadable" attribute
 
   int g(int) __attribute__((overloadable));
   int g(int) { } // error: redeclaration of "g" must also have the "overloadable" attribute
 
+  int h(int);
+  int h(int) __attribute__((overloadable)); // error: declaration of "h" must not
+// have the "overloadable" attribute
+
 Functions marked ``overloadable`` must have prototypes.  Therefore, the
 following code is ill-formed:
 
@@ -651,7 +658,28 @@
   linkage specification, it's name *will* be mangled in the same way as it
   would in C.
 
-Query for this feature with ``__has_extension(attribute_overloadable)``.
+For the purpose of backwards compatibility, at most one function with the same
+name as other ``overloadable`` functions may omit the ``overloadable``
+attribute. In this case, the function without the ``overloadable`` attribute
+will not have its name mangled.
+
+For example:
+
+.. code-block:: c
+
+  // Notes with mangled names assume Itanium mangling.
+  int f(int);
+  int f(double) __attribute__((overloadable));
+  void foo() {
+f(5); // Emits a call to f (not _Z1fi, as it would with an overload that
+  // was marked with overloadable).
+f(1.0); // Emits a call to _Z1fd.
+  }
+
+Support for unmarked overloads is not present in some versions of clang. You may
+query for it using ``__has_extension(overloadable_unmarked)``.
+
+Query for this attribute with ``__has_attribute(overloadable)``.
   }];
 }
 
Index: cfe/trunk/test/CodeGenCXX/mangle-ms.cpp
==

[PATCH] D33278: [LLVM][x86][Inline Asm] - Enum support for MS syntax

2017-06-27 Thread coby via Phabricator via cfe-commits
coby added inline comments.



Comment at: lib/Target/X86/AsmParser/X86AsmParser.cpp:1310
 }
-
-bool X86AsmParser::ParseIntelExpression(IntelExprStateMachine &SM, SMLoc &End) 
{
+bool X86AsmParser::ParseIntelExpression(IntelExprStateMachine &SM, SMLoc &End,
+bool &ReplaceEnumIdentifier) {

blank line omitted



Comment at: lib/Target/X86/AsmParser/X86AsmParser.cpp:1378
+// Check if the parsed identifier was a constant Integer. Here we
+// assume Val is of type MCConstantExpr only when it is safe to replace
+// the identifier with its constant value.

assumption ~~> assertion



Comment at: lib/Target/X86/AsmParser/X86AsmParser.cpp:1380
+// the identifier with its constant value.
+if (const MCConstantExpr *CE =
+dyn_cast_or_null(Val)) {

I think this whole section better suites within its own function. something 
like 'ParseInlineAsmEnumValue'



Comment at: lib/Target/X86/AsmParser/X86AsmParser.cpp:1383
+  StringRef ErrMsg;
+  // SM should treat the value as it would an explicit integer in the 
+  // expression.

rephrase



Comment at: lib/Target/X86/AsmParser/X86AsmParser.cpp:1385
+  // expression.
+  if(SM.onInteger(CE->getValue(), ErrMsg)) 
+return Error(IdentLoc, ErrMsg);

clang format



Comment at: lib/Target/X86/AsmParser/X86AsmParser.cpp:1388
+  // In case we are called on a bracketed expression,
+  if (isParsingInlineAsm() && SM.getAddImmPrefix()) {
+// A single rewrite of the integer value is preformed for each enum

'isParsingInlineAsm()' is unnecessary here (you can only reach this piece of 
code when parsing inline asm)



Comment at: lib/Target/X86/AsmParser/X86AsmParser.cpp:1826
   }
-
-  // Rewrite the type operator and the C or C++ type or variable in terms of an
-  // immediate.  E.g. TYPE foo -> $$4
-  unsigned Len = End.getPointer() - TypeLoc.getPointer();
-  InstInfo->AsmRewrites->emplace_back(AOK_Imm, TypeLoc, Len, CVal);
-
+  // Only when in bracketed mode, preform explicit rewrite
+  if (AddImmPrefix) {

Not keen to the use of SM.getAddImmPrefix() as a mean of distinguish whether we 
are parsing a bracketed expression. I know it is currently turned on when 
parsing it, but it isn't asserted/guaranteed.
Regardless - I'm pretty sure we can manage without this rewrite, or at the very 
least - should, now that TYPE/LENGTH/SIZE are part of the State Machine.



Comment at: lib/Target/X86/AsmParser/X86AsmParser.cpp:1907
 unsigned Len = Tok.getLoc().getPointer() - Start.getPointer();
-if (StartTok.getString().size() == Len)
-  // Just add a prefix if this wasn't a complex immediate expression.
-  InstInfo->AsmRewrites->emplace_back(AOK_ImmPrefix, Start);
-else
-  // Otherwise, rewrite the complex expression as a single immediate.
+if (StartTok.getString().size() != Len || ReplaceEnumIdentifier)
+  // Rewrite the complex expression as a single immediate.

you may just perform an AOK_Imm rewrite regardless the complexity of the 
immediate expression, and neglect 'ReplaceEnumIdentifier'


Repository:
  rL LLVM

https://reviews.llvm.org/D33278



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


  1   2   >