r347293 - [libclang] Unify getCursorDecl and getCursorParentDecl

2018-11-20 Thread Fangrui Song via cfe-commits
Author: maskray
Date: Tue Nov 20 00:00:00 2018
New Revision: 347293

URL: http://llvm.org/viewvc/llvm-project?rev=347293&view=rev
Log:
[libclang] Unify getCursorDecl and getCursorParentDecl

They do the same thing, thus the latter (which has only 2 call sites) can be 
deleted.

Modified:
cfe/trunk/tools/libclang/CIndex.cpp
cfe/trunk/tools/libclang/CXCursor.cpp
cfe/trunk/tools/libclang/CXCursor.h

Modified: cfe/trunk/tools/libclang/CIndex.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=347293&r1=347292&r2=347293&view=diff
==
--- cfe/trunk/tools/libclang/CIndex.cpp (original)
+++ cfe/trunk/tools/libclang/CIndex.cpp Tue Nov 20 00:00:00 2018
@@ -6940,7 +6940,7 @@ AnnotateTokensWorker::DetermineChildActi
 if (const ImplicitCastExpr *ICE = dyn_cast(Callee)) {
   const Expr *SubExpr = ICE->getSubExpr();
   if (const DeclRefExpr *DRE = dyn_cast(SubExpr)) {
-const Decl *parentDecl = getCursorParentDecl(Cursor);
+const Decl *parentDecl = getCursorDecl(Cursor);
 CXTranslationUnit TU = clang_Cursor_getTranslationUnit(Cursor);
 
 // Visit the DeclRefExpr as last.
@@ -7163,7 +7163,7 @@ AnnotateTokensWorker::Visit(CXCursor cur
   //  MyCXXClass foo; // Make sure we don't annotate 'foo' as a CallExpr 
cursor.
   if (clang_isExpression(cursorK) && MoreTokens()) {
 const Expr *E = getCursorExpr(cursor);
-if (const Decl *D = getCursorParentDecl(cursor)) {
+if (const Decl *D = getCursorDecl(cursor)) {
   const unsigned I = NextToken();
   if (E->getBeginLoc().isValid() && D->getLocation().isValid() &&
   E->getBeginLoc() == D->getLocation() &&

Modified: cfe/trunk/tools/libclang/CXCursor.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CXCursor.cpp?rev=347293&r1=347292&r2=347293&view=diff
==
--- cfe/trunk/tools/libclang/CXCursor.cpp (original)
+++ cfe/trunk/tools/libclang/CXCursor.cpp Tue Nov 20 00:00:00 2018
@@ -1012,10 +1012,6 @@ const Attr *cxcursor::getCursorAttr(CXCu
   return static_cast(Cursor.data[1]);
 }
 
-const Decl *cxcursor::getCursorParentDecl(CXCursor Cursor) {
-  return static_cast(Cursor.data[0]);
-}
-
 ASTContext &cxcursor::getCursorContext(CXCursor Cursor) {
   return getCursorASTUnit(Cursor)->getASTContext();
 }

Modified: cfe/trunk/tools/libclang/CXCursor.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CXCursor.h?rev=347293&r1=347292&r2=347293&view=diff
==
--- cfe/trunk/tools/libclang/CXCursor.h (original)
+++ cfe/trunk/tools/libclang/CXCursor.h Tue Nov 20 00:00:00 2018
@@ -43,11 +43,11 @@ class TemplateName;
 class TypeDecl;
 class VarDecl;
 class IdentifierInfo;
-  
+
 namespace cxcursor {
 
 CXCursor getCursor(CXTranslationUnit, SourceLocation);
-  
+
 CXCursor MakeCXCursor(const clang::Attr *A, const clang::Decl *Parent,
   CXTranslationUnit TU);
 CXCursor MakeCXCursor(const clang::Decl *D, CXTranslationUnit TU,
@@ -125,7 +125,7 @@ std::pair getCursorMemberRef(CXCursor C);
@@ -232,17 +232,16 @@ CXCursor MakeCursorOverloadedDeclRef(Tem
 typedef llvm::PointerUnion3
   OverloadedDeclRefStorage;
-  
+
 /// Unpack an overloaded declaration reference into an expression,
 /// declaration, or template name along with the source location.
 std::pair
   getCursorOverloadedDeclRef(CXCursor C);
-  
+
 const Decl *getCursorDecl(CXCursor Cursor);
 const Expr *getCursorExpr(CXCursor Cursor);
 const Stmt *getCursorStmt(CXCursor Cursor);
 const Attr *getCursorAttr(CXCursor Cursor);
-const Decl *getCursorParentDecl(CXCursor Cursor);
 
 ASTContext &getCursorContext(CXCursor Cursor);
 ASTUnit *getCursorASTUnit(CXCursor Cursor);
@@ -250,14 +249,14 @@ CXTranslationUnit getCursorTU(CXCursor C
 
 void getOverriddenCursors(CXCursor cursor,
   SmallVectorImpl &overridden);
-  
+
 /// Create an opaque pool used for fast generation of overridden
 /// CXCursor arrays.
 void *createOverridenCXCursorsPool();
 
 /// Dispose of the overridden CXCursors pool.
 void disposeOverridenCXCursorsPool(void *pool);
-  
+
 /// Returns a index/location pair for a selector identifier if the cursor
 /// points to one.
 std::pair getSelectorIdentifierIndexAndLoc(CXCursor);
@@ -285,7 +284,7 @@ CXCursor getTypeRefCursor(CXCursor curso
 bool getDeclCursorUSR(const Decl *D, SmallVectorImpl &Buf);
 
 bool operator==(CXCursor X, CXCursor Y);
-  
+
 inline bool operator!=(CXCursor X, CXCursor Y) {
   return !(X == Y);
 }


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


r347294 - Use is.constant intrinsic for __builtin_constant_p

2018-11-20 Thread Bill Wendling via cfe-commits
Author: void
Date: Tue Nov 20 00:53:30 2018
New Revision: 347294

URL: http://llvm.org/viewvc/llvm-project?rev=347294&view=rev
Log:
Use is.constant intrinsic for __builtin_constant_p

Summary:
A __builtin_constant_p may end up with a constant after inlining. Use
the is.constant intrinsic if it's a variable that's in a context where
it may resolve to a constant, e.g., an argument to a function after
inlining.

Reviewers: rsmith, shafik

Subscribers: jfb, kristina, cfe-commits, nickdesaulniers, jyknight

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

Modified:
cfe/trunk/include/clang/AST/Expr.h
cfe/trunk/lib/AST/ASTImporter.cpp
cfe/trunk/lib/AST/Expr.cpp
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/lib/CodeGen/CGBuiltin.cpp
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/lib/Sema/SemaOverload.cpp
cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp
cfe/trunk/lib/Sema/SemaType.cpp
cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
cfe/trunk/test/Analysis/builtin-functions.cpp
cfe/trunk/test/Sema/builtins.c
cfe/trunk/test/SemaCXX/compound-literal.cpp

Modified: cfe/trunk/include/clang/AST/Expr.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=347294&r1=347293&r2=347294&view=diff
==
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Tue Nov 20 00:53:30 2018
@@ -901,10 +901,15 @@ public:
 
 /// ConstantExpr - An expression that occurs in a constant context.
 class ConstantExpr : public FullExpr {
-public:
   ConstantExpr(Expr *subexpr)
 : FullExpr(ConstantExprClass, subexpr) {}
 
+public:
+  static ConstantExpr *Create(const ASTContext &Context, Expr *E) {
+assert(!isa(E));
+return new (Context) ConstantExpr(E);
+  }
+
   /// Build an empty constant expression wrapper.
   explicit ConstantExpr(EmptyShell Empty)
 : FullExpr(ConstantExprClass, Empty) {}
@@ -3091,8 +3096,8 @@ inline Expr *Expr::IgnoreImpCasts() {
   while (true)
 if (ImplicitCastExpr *ice = dyn_cast(e))
   e = ice->getSubExpr();
-else if (ConstantExpr *ce = dyn_cast(e))
-  e = ce->getSubExpr();
+else if (FullExpr *fe = dyn_cast(e))
+  e = fe->getSubExpr();
 else
   break;
   return e;

Modified: cfe/trunk/lib/AST/ASTImporter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTImporter.cpp?rev=347294&r1=347293&r2=347294&view=diff
==
--- cfe/trunk/lib/AST/ASTImporter.cpp (original)
+++ cfe/trunk/lib/AST/ASTImporter.cpp Tue Nov 20 00:53:30 2018
@@ -6375,7 +6375,7 @@ ExpectedStmt ASTNodeImporter::VisitConst
   Expr *ToSubExpr;
   std::tie(ToSubExpr) = *Imp;
 
-  return new (Importer.getToContext()) ConstantExpr(ToSubExpr);
+  return ConstantExpr::Create(Importer.getToContext(), ToSubExpr);
 }
 
 ExpectedStmt ASTNodeImporter::VisitParenExpr(ParenExpr *E) {

Modified: cfe/trunk/lib/AST/Expr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=347294&r1=347293&r2=347294&view=diff
==
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Tue Nov 20 00:53:30 2018
@@ -2594,8 +2594,8 @@ Expr *Expr::IgnoreParenCasts() {
   E = NTTP->getReplacement();
   continue;
 }
-if (ConstantExpr *CE = dyn_cast(E)) {
-  E = CE->getSubExpr();
+if (FullExpr *FE = dyn_cast(E)) {
+  E = FE->getSubExpr();
   continue;
 }
 return E;
@@ -2619,8 +2619,8 @@ Expr *Expr::IgnoreCasts() {
   E = NTTP->getReplacement();
   continue;
 }
-if (ConstantExpr *CE = dyn_cast(E)) {
-  E = CE->getSubExpr();
+if (FullExpr *FE = dyn_cast(E)) {
+  E = FE->getSubExpr();
   continue;
 }
 return E;
@@ -2648,8 +2648,8 @@ Expr *Expr::IgnoreParenLValueCasts() {
   = dyn_cast(E)) 
{
   E = NTTP->getReplacement();
   continue;
-} else if (ConstantExpr *CE = dyn_cast(E)) {
-  E = CE->getSubExpr();
+} else if (FullExpr *FE = dyn_cast(E)) {
+  E = FE->getSubExpr();
   continue;
 }
 break;
@@ -2920,6 +2920,12 @@ bool Expr::isConstantInitializer(ASTCont
 
 break;
   }
+  case ConstantExprClass: {
+// FIXME: We should be able to return "true" here, but it can lead to extra
+// error messages. E.g. in Sema/array-init.c.
+const Expr *Exp = cast(this)->getSubExpr();
+return Exp->isConstantInitializer(Ctx, false, Culprit);
+  }
   case CompoundLiteralExprClass: {
 // This handles gcc's extension that allows global initializers like
 // "struct x {int x;} x = (struct x) {};".

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=347294&r1=347293&r2=347294&view=diff
=

[PATCH] D54355: Use is.constant intrinsic for __builtin_constant_p

2018-11-20 Thread Bill Wendling via Phabricator via cfe-commits
This revision was not accepted when it landed; it landed in state "Needs 
Review".
This revision was automatically updated to reflect the committed changes.
Closed by commit rC347294: Use is.constant intrinsic for __builtin_constant_p 
(authored by void, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D54355?vs=174692&id=174731#toc

Repository:
  rC Clang

https://reviews.llvm.org/D54355

Files:
  include/clang/AST/Expr.h
  lib/AST/ASTImporter.cpp
  lib/AST/Expr.cpp
  lib/AST/ExprConstant.cpp
  lib/CodeGen/CGBuiltin.cpp
  lib/Sema/SemaDeclCXX.cpp
  lib/Sema/SemaExpr.cpp
  lib/Sema/SemaOverload.cpp
  lib/Sema/SemaTemplateDeduction.cpp
  lib/Sema/SemaType.cpp
  lib/StaticAnalyzer/Core/ExprEngine.cpp
  test/Analysis/builtin-functions.cpp
  test/Sema/builtins.c
  test/SemaCXX/compound-literal.cpp

Index: include/clang/AST/Expr.h
===
--- include/clang/AST/Expr.h
+++ include/clang/AST/Expr.h
@@ -901,10 +901,15 @@
 
 /// ConstantExpr - An expression that occurs in a constant context.
 class ConstantExpr : public FullExpr {
-public:
   ConstantExpr(Expr *subexpr)
 : FullExpr(ConstantExprClass, subexpr) {}
 
+public:
+  static ConstantExpr *Create(const ASTContext &Context, Expr *E) {
+assert(!isa(E));
+return new (Context) ConstantExpr(E);
+  }
+
   /// Build an empty constant expression wrapper.
   explicit ConstantExpr(EmptyShell Empty)
 : FullExpr(ConstantExprClass, Empty) {}
@@ -3091,8 +3096,8 @@
   while (true)
 if (ImplicitCastExpr *ice = dyn_cast(e))
   e = ice->getSubExpr();
-else if (ConstantExpr *ce = dyn_cast(e))
-  e = ce->getSubExpr();
+else if (FullExpr *fe = dyn_cast(e))
+  e = fe->getSubExpr();
 else
   break;
   return e;
Index: test/SemaCXX/compound-literal.cpp
===
--- test/SemaCXX/compound-literal.cpp
+++ test/SemaCXX/compound-literal.cpp
@@ -36,8 +36,8 @@
 
   POD p = (POD){1, 2};
   // CHECK-NOT: CXXBindTemporaryExpr {{.*}} 'brace_initializers::POD'
-  // CHECK: ConstantExpr {{.*}} 'brace_initializers::POD'
-  // CHECK-NEXT: CompoundLiteralExpr {{.*}} 'brace_initializers::POD'
+  // CHECK: CompoundLiteralExpr {{.*}} 'brace_initializers::POD'
+  // CHECK-NEXT: ConstantExpr {{.*}} 'brace_initializers::POD'
   // CHECK-NEXT: InitListExpr {{.*}} 'brace_initializers::POD'
   // CHECK-NEXT: IntegerLiteral {{.*}} 1{{$}}
   // CHECK-NEXT: IntegerLiteral {{.*}} 2{{$}}
Index: test/Sema/builtins.c
===
--- test/Sema/builtins.c
+++ test/Sema/builtins.c
@@ -122,6 +122,14 @@
  __builtin_constant_p(1, 2); // expected-error {{too many arguments}}
 }
 
+// __builtin_constant_p cannot resolve non-constants as a file scoped array.
+int expr;
+char y[__builtin_constant_p(expr) ? -1 : 1]; // no warning, the builtin is false.
+
+// no warning, the builtin is false.
+struct foo { int a; };
+struct foo x = (struct foo) { __builtin_constant_p(42) ? 37 : 927 };
+
 const int test17_n = 0;
 const char test17_c[] = {1, 2, 3, 0};
 const char test17_d[] = {1, 2, 3, 4};
@@ -161,6 +169,7 @@
   F(&test17_d);
   F((struct Aggregate){0, 1});
   F((IntVector){0, 1, 2, 3});
+  F(test17);
 
   // Ensure that a technique used in glibc is handled correctly.
 #define OPT(...) (__builtin_constant_p(__VA_ARGS__) && strlen(__VA_ARGS__) < 4)
Index: test/Analysis/builtin-functions.cpp
===
--- test/Analysis/builtin-functions.cpp
+++ test/Analysis/builtin-functions.cpp
@@ -70,14 +70,14 @@
   const int j = 2;
   constexpr int k = 3;
   clang_analyzer_eval(__builtin_constant_p(42) == 1); // expected-warning {{TRUE}}
-  clang_analyzer_eval(__builtin_constant_p(i) == 0); // expected-warning {{TRUE}}
+  clang_analyzer_eval(__builtin_constant_p(i) == 0); // expected-warning {{UNKNOWN}}
   clang_analyzer_eval(__builtin_constant_p(j) == 1); // expected-warning {{TRUE}}
   clang_analyzer_eval(__builtin_constant_p(k) == 1); // expected-warning {{TRUE}}
-  clang_analyzer_eval(__builtin_constant_p(i + 42) == 0); // expected-warning {{TRUE}}
+  clang_analyzer_eval(__builtin_constant_p(i + 42) == 0); // expected-warning {{UNKNOWN}}
   clang_analyzer_eval(__builtin_constant_p(j + 42) == 1); // expected-warning {{TRUE}}
   clang_analyzer_eval(__builtin_constant_p(k + 42) == 1); // expected-warning {{TRUE}}
   clang_analyzer_eval(__builtin_constant_p(" ") == 1); // expected-warning {{TRUE}}
-  clang_analyzer_eval(__builtin_constant_p(test_constant_p) == 0); // expected-warning {{TRUE}}
+  clang_analyzer_eval(__builtin_constant_p(test_constant_p) == 0); // expected-warning {{UNKNOWN}}
   clang_analyzer_eval(__builtin_constant_p(k - 3) == 0); // expected-warning {{FALSE}}
   clang_analyzer_eval(__builtin_constant_p(k - 3) == 1); // expected-warning {{TRUE}}
 }
Index: lib/CodeGen/CGBuiltin.cpp
==

[PATCH] D54401: [analyzer] Prefer returns values to out-params in CheckerRegistry.cpp

2018-11-20 Thread Umann Kristóf via Phabricator via cfe-commits
Szelethus added a comment.
Herald added subscribers: gamesh411, baloghadamsoftware.

Ping


https://reviews.llvm.org/D54401



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


[PATCH] D54262: [clang-tidy] Add `delete this` bugprone check (PR38741)

2018-11-20 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth added a comment.

Ok, Thank you for looking into it. You can abondon the revision in
phabricator (Selection above comment field at the bottom of the page) if
you wish.

Am 19.11.18 um 23:36 schrieb Mateusz Maćkowski via Phabricator:

> m4tx added a comment.
> 
> After thinking about the possible use cases (and the difficulty of 
> implementing heuristics for them) as well as fiddling with Clang Static 
> Analyzer it seems that this patch can be discarded as the Analyzer already 
> handles `delete this` pretty well. I've posted an update to the Bugzilla 
> ticket.
> 
> Repository:
> 
>   rCTE Clang Tools Extra
> 
> https://reviews.llvm.org/D54262


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D54262



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


[PATCH] D54475: [clangd] Allow observation of changes to global CDBs.

2018-11-20 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov accepted this revision.
ilya-biryukov added a comment.
This revision is now accepted and ready to land.

LGTM




Comment at: clangd/Function.h:147
+private:
+  static_assert(std::is_same::type, T>::value,
+"use a plain type: event values are always passed by const&");

sammccall wrote:
> ilya-biryukov wrote:
> > NIT: Maybe move this static_assert to the top of the class?
> > I'd argue this is part of the public interface as it puts constraints on 
> > the template parameters.
> On balance I don't think I agree here.
> 
> I'm not sure about having the static assert at all, unless we have reason to 
> believe it will compile but do the wrong thing. Happy to compromise by 
> including it, but I don't think it belongs up front.
> It's not very human-readable, and computers are just as happy with it in the 
> private section.  It's consistent with some other ways of disallowing 
> compilation, like declaring members private.
Reference collapsing rules can bite us here, e.g. I don't think making 
`Event` and `Event` valid makes sense, even though both would 
compile.

> It's consistent with some other ways of disallowing compilation, like 
> declaring members private.
Would also argue those private members should be declared at the top of the 
class for the same reasons.

But we just have different opinions here, it's not terribly important.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D54475



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


[PATCH] D43871: [modules] No longer include stdlib.h from mm_malloc.h.

2018-11-20 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev added a comment.

ping...


https://reviews.llvm.org/D43871



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


[PATCH] D35559: [CMake][Modules] Tweak Modules-unfriendly builds

2018-11-20 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev added a comment.

Is this change still relevant?


Repository:
  rL LLVM

https://reviews.llvm.org/D35559



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


[PATCH] D54694: [clangd] Replay preamble #includes to clang-tidy checks.

2018-11-20 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov accepted this revision.
ilya-biryukov added a comment.
This revision is now accepted and ready to land.

LGTM


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D54694



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


[PATCH] D54745: [clang-tidy] Don't generate incorrect fixes for class with deleted copy constructor in smart_ptr check.

2018-11-20 Thread Haojian Wu via Phabricator via cfe-commits
hokein created this revision.
hokein added reviewers: JonasToth, aaron.ballman.
Herald added a subscriber: xazax.hun.

The fix for aggregate initialization (`std::make_unique(Foo {1, 2})` needs
to see Foo copy constructor, otherwise we will have a compiler error. So we
only emit the check warning.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D54745

Files:
  clang-tidy/modernize/MakeSmartPtrCheck.cpp
  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
@@ -32,6 +32,10 @@
 
 struct Empty {};
 
+struct NoCopyCtor {
+  NoCopyCtor(const NoCopyCtor&) = delete;
+};
+
 struct E {
   E(std::initializer_list);
   E();
@@ -270,6 +274,11 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:35: warning: use std::make_unique instead
   // CHECK-FIXES: std::unique_ptr PEmpty = 
std::make_unique(Empty{});
 
+  // No fixes for classes with deleted copy constructor.
+  std::unique_ptr PNoCopyCtor = std::unique_ptr(new 
NoCopyCtor{});
+  // CHECK-MESSAGES: :[[@LINE-1]]:45: warning: use std::make_unique instead
+  // CHECK-FIXES: std::unique_ptr PNoCopyCtor = 
std::unique_ptr(new NoCopyCtor{});
+
   // Initialization with default constructor.
   std::unique_ptr PE1 = std::unique_ptr(new E{});
   // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: use std::make_unique instead
Index: clang-tidy/modernize/MakeSmartPtrCheck.cpp
===
--- clang-tidy/modernize/MakeSmartPtrCheck.cpp
+++ clang-tidy/modernize/MakeSmartPtrCheck.cpp
@@ -375,6 +375,17 @@
   //   smart_ptr(new Pair{first, second});
   // Has to be replaced with:
   //   smart_ptr(Pair{first, second});
+  //
+  // The fix (std::make_unique) requires to see the copy constructor of
+  // Pair, so we don't generate fix if the copy consturctor is not visible
+  // or deleted.
+  if (const auto *RD = New->getType()->getPointeeCXXRecordDecl()) {
+for (const auto *Ctor : RD->ctors()) {
+  if (Ctor->isCopyConstructor() &&
+  (Ctor->isDeleted() || Ctor->getAccess() == AS_private))
+return false;
+}
+  }
   InitRange = SourceRange(
   New->getAllocatedTypeSourceInfo()->getTypeLoc().getBeginLoc(),
   New->getInitializer()->getSourceRange().getEnd());


Index: test/clang-tidy/modernize-make-unique.cpp
===
--- test/clang-tidy/modernize-make-unique.cpp
+++ test/clang-tidy/modernize-make-unique.cpp
@@ -32,6 +32,10 @@
 
 struct Empty {};
 
+struct NoCopyCtor {
+  NoCopyCtor(const NoCopyCtor&) = delete;
+};
+
 struct E {
   E(std::initializer_list);
   E();
@@ -270,6 +274,11 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:35: warning: use std::make_unique instead
   // CHECK-FIXES: std::unique_ptr PEmpty = std::make_unique(Empty{});
 
+  // No fixes for classes with deleted copy constructor.
+  std::unique_ptr PNoCopyCtor = std::unique_ptr(new NoCopyCtor{});
+  // CHECK-MESSAGES: :[[@LINE-1]]:45: warning: use std::make_unique instead
+  // CHECK-FIXES: std::unique_ptr PNoCopyCtor = std::unique_ptr(new NoCopyCtor{});
+
   // Initialization with default constructor.
   std::unique_ptr PE1 = std::unique_ptr(new E{});
   // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: use std::make_unique instead
Index: clang-tidy/modernize/MakeSmartPtrCheck.cpp
===
--- clang-tidy/modernize/MakeSmartPtrCheck.cpp
+++ clang-tidy/modernize/MakeSmartPtrCheck.cpp
@@ -375,6 +375,17 @@
   //   smart_ptr(new Pair{first, second});
   // Has to be replaced with:
   //   smart_ptr(Pair{first, second});
+  //
+  // The fix (std::make_unique) requires to see the copy constructor of
+  // Pair, so we don't generate fix if the copy consturctor is not visible
+  // or deleted.
+  if (const auto *RD = New->getType()->getPointeeCXXRecordDecl()) {
+for (const auto *Ctor : RD->ctors()) {
+  if (Ctor->isCopyConstructor() &&
+  (Ctor->isDeleted() || Ctor->getAccess() == AS_private))
+return false;
+}
+  }
   InitRange = SourceRange(
   New->getAllocatedTypeSourceInfo()->getTypeLoc().getBeginLoc(),
   New->getInitializer()->getSourceRange().getEnd());
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D54737: [clang-tidy] Add the abseil-duration-comparison check

2018-11-20 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth added a comment.

Could you please upload the diff with full context? Especially the parts with 
refactoring are harder to judge if the code around is not visible. Thank you :)




Comment at: clang-tidy/abseil/DurationComparisonCheck.cpp:25
+static llvm::Optional getScaleForInverse(llvm::StringRef Name) {
+  static const std::unordered_map ScaleMap(
+  {{"ToDoubleHours", DurationScale::Hours},

I think this could be made a `DenseMap` with just the right amount of dense 
entries. 12 elements seems not too much to me.
Does the key-type need to be `std::string`, or could it be `StringRef`(or 
`StringLiteral` making everything `constexpr` if possible)?
Is there some strange stuff with dangling pointers or other issues going on?



Comment at: clang-tidy/abseil/DurationComparisonCheck.cpp:50
+  static const std::unordered_map>
+  InverseMap(

This variable is a little hard to read. Could you make a little wrapper-struct 
instead of the `tuple` to make clear which element represents what?
Otherwise, why not `std::pair`?

- same `DenseMap` argument
- same `StringRef`/`StringLiteral` instead `string` consideration



Comment at: clang-tidy/abseil/DurationComparisonCheck.cpp:68
+
+  // We know our map contains all the Scale values, so we can skip the
+  // nonexistence check.

The basis for this "we know" might change in the future if `abs::Duration` does 
things differently. Is adding stuff allowed in the `absl::` space? (i am not 
fluent with the guarantees that it gives). You could maybe `assert` that the 
find is always correct, depending on `absl` guarantees.



Comment at: clang-tidy/abseil/DurationComparisonCheck.cpp:78
+DurationScale Scale, const Expr &Node) {
+  auto InverseFunctions = getInverseForScale(Scale);
+  if (auto MaybeCallArg = selectFirst(

Please no `auto` here



Comment at: clang-tidy/abseil/DurationComparisonCheck.cpp:79
+  auto InverseFunctions = getInverseForScale(Scale);
+  if (auto MaybeCallArg = selectFirst(
+  "e", match(callExpr(callee(functionDecl(hasAnyName(

Please use `const auto*` to make it clear that this is a pointer



Comment at: clang-tidy/abseil/DurationComparisonCheck.cpp:99
+  // First check to see if we can undo a complimentary function call.
+  if (auto MaybeRewrite =
+  maybeRewriteInverseDurationCall(Result, Scale, RootNode)) {

please no `auto`, you can ellide the braces



Comment at: clang-tidy/abseil/DurationComparisonCheck.cpp:104
+
+  if (IsLiteralZero(Result, RootNode)) {
+return "absl::ZeroDuration()";

ellide braces



Comment at: clang-tidy/abseil/DurationComparisonCheck.cpp:108
+
+  // TODO(hwright): Check for another condition:
+  //  1. duration-factory-scale

in LLVM the TODO does not contain a name for the author.



Comment at: clang-tidy/abseil/DurationComparisonCheck.cpp:125
+  hasAnyName(
+  "::absl::ToDoubleHours", "::absl::ToDoubleMinutes",
+  "::absl::ToDoubleSeconds", 
"::absl::ToDoubleMilliseconds",

the list here is somewhat duplicated with the static members in the functions 
at the top. it would be best to merge them.
Not sure on how much `constexpr` is supported by the llvm-datastructures, but a 
constexpr `DenseMap.keys()` would be nice. Did you try something along this 
line?



Comment at: clang-tidy/abseil/DurationComparisonCheck.cpp:151
+  // if nothing needs to be done.
+  auto lhs_replacement =
+  rewriteExprFromNumberToDuration(Result, *Scale, Binop->getLHS());

Please follow the naming convention and don't use `auto` here.



Comment at: clang-tidy/abseil/DurationFactoryFloatCheck.cpp:61
+  llvm::Optional SimpleArg = stripFloatCast(Result, *Arg);
+  if (!SimpleArg) {
+SimpleArg = stripFloatLiteralFraction(Result, *Arg);

braces can be ellided here



Comment at: clang-tidy/abseil/DurationRewriter.cpp:51
+bool IsLiteralZero(const MatchFinder::MatchResult &Result, const Expr &Node) {
+  return selectFirst(
+  "val", match(expr(ignoringImpCasts(anyOf(integerLiteral(equals(0)),

This is a implicit pointer-to-bool-conversion, isn't it? I think for 
readability purposes this should be made clear with a binary comparison.



Comment at: clang-tidy/abseil/DurationRewriter.cpp:61
+   const Expr &Node) {
+  if (auto MaybeCastArg = selectFirst(
+  "cast_arg",

`const auto *`



Comment at: clang-tidy/abseil/DurationRewriter.cpp:95
+  // Check for an explicit cast to `float` or `double`.
+  if (auto MaybeArg = stripFloatCast(Result, Node)) {
+return *MaybeAr

[PATCH] D54737: [clang-tidy] Add the abseil-duration-comparison check

2018-11-20 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth added inline comments.



Comment at: test/clang-tidy/abseil-duration-comparison.cpp:89
+  // CHECK-FIXES: d1 > d2;
+
+  // Check against the LHS

JonasToth wrote:
> What would happen for a type, that can implicitly convert to a duration or 
> double/int.
> 
> ```
> struct MetaBenchmarkResults {
> int64_t RunID;
>absl::Duration D;
> 
>   operator absl::Duration() { return D; }
> };
> 
> auto R = MetaBenchmarkResults { /* Foo */ };
> bool WithinReason = Threshold < R;
> ```
> 
> What is the correct behaviour there? I think this should be diagnosed too.
H, I fiddled around in godbolt, and i think there is nothing to trick 
around with conversions, as they wont compile.
If you find something along the lines, please tell me. But i guess this is a 
non-issue.

https://godbolt.org/z/gqhhHo



Comment at: test/clang-tidy/abseil-duration-comparison.cpp:153
+  // Other abseil-duration checks folded into this one
+  b = static_cast(5) > absl::ToDoubleSeconds(d1);
+  // CHECK-MESSAGES: [[@LINE-1]]:7: warning: perform duration comparison in 
the duration domain [abseil-duration-comparison]

Please test the other casts you match on as well (especially c-style)


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D54737



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


[PATCH] D54745: [clang-tidy] Don't generate incorrect fixes for class with deleted copy constructor in smart_ptr check.

2018-11-20 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth added a comment.

Does make_unique require the copy constructor if it could move?
And would the same argument apply to the move-constructors as the arguments are 
forwarded?
What would happen in the obscure case of a public copy-constructor, but private 
move-constructor (not saying it makes sense :))




Comment at: clang-tidy/modernize/MakeSmartPtrCheck.cpp:380
+  // The fix (std::make_unique) requires to see the copy constructor of
+  // Pair, so we don't generate fix if the copy consturctor is not visible
+  // or deleted.

typo: s/consturctor/constructor/



Comment at: test/clang-tidy/modernize-make-unique.cpp:35
 
+struct NoCopyCtor {
+  NoCopyCtor(const NoCopyCtor&) = delete;

please add a case for the `private` copy-constructor as well.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D54745



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


[PATCH] D54746: [clangd] Respect task cancellation in TUScheduler.

2018-11-20 Thread Sam McCall via Phabricator via cfe-commits
sammccall created this revision.
sammccall added a reviewer: ilya-biryukov.
Herald added subscribers: cfe-commits, kadircet, arphaman, jkorous, MaskRay, 
ioeric, javed.absar.

- Reads are never executed if canceled before ready-to run. In practice, we 
finalize cancelled reads eagerly and out-of-order.
- Cancelled reads don't prevent prior updates from being elided, as they don't 
actually depend on the result of the update.
- Updates are downgraded from WantDiagnostics::Yes to WantDiagnostics::Auto 
when cancelled, which allows them to be elided when all dependent reads are 
cancelled and there are subsequent writes. (e.g. when the queue is backed up 
with cancelled requests).

The queue operations aren't optimal (we scan the whole queue for cancelled
tasks every time the scheduler runs, and check cancellation twice in the end).
However I believe these costs are still trivial in practice (compared to any
AST operation) and the logic can be cleanly separated from the rest of the
scheduler.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D54746

Files:
  clangd/Cancellation.cpp
  clangd/Cancellation.h
  clangd/TUScheduler.cpp
  clangd/TUScheduler.h
  unittests/clangd/TUSchedulerTests.cpp

Index: unittests/clangd/TUSchedulerTests.cpp
===
--- unittests/clangd/TUSchedulerTests.cpp
+++ unittests/clangd/TUSchedulerTests.cpp
@@ -209,6 +209,75 @@
   EXPECT_EQ(2, CallbackCount);
 }
 
+TEST_F(TUSchedulerTests, Cancellation) {
+  // We have the following update/read sequence
+  //   U0
+  //   U1(WantDiags=Yes) <-- cancelled
+  //R1   <-- cancelled
+  //   U2(WantDiags=Yes) <-- cancelled
+  //R2A  <-- cancelled
+  //R2B
+  //   U3(WantDiags=Yes)
+  //R3   <-- cancelled
+  std::vector DiagsSeen, ReadsSeen, ReadsCanceled;
+  {
+TUScheduler S(
+getDefaultAsyncThreadsCount(), /*StorePreamblesInMemory=*/true,
+/*ASTCallbacks=*/nullptr,
+/*UpdateDebounce=*/std::chrono::steady_clock::duration::zero(),
+ASTRetentionPolicy());
+auto Path = testPath("foo.cpp");
+// Helper to schedule a named update and return a function to cancel it.
+auto Update = [&](std::string ID) -> Canceler {
+  auto T = cancelableTask();
+  WithContext C(std::move(T.first));
+  S.update(Path, getInputs(Path, "//" + ID), WantDiagnostics::Yes,
+   [&, ID](std::vector Diags) { DiagsSeen.push_back(ID); });
+  return std::move(T.second);
+};
+// Helper to schedule a named read and return a function to cancel it.
+auto Read = [&](std::string ID) -> Canceler {
+  auto T = cancelableTask();
+  WithContext C(std::move(T.first));
+  S.runWithAST(ID, Path, [&, ID](llvm::Expected E) {
+if (auto Err = E.takeError()) {
+  if (Err.isA()) {
+ReadsCanceled.push_back(ID);
+consumeError(std::move(Err));
+  } else {
+ADD_FAILURE() << "Non-cancelled error for " << ID << ": "
+  << llvm::toString(std::move(Err));
+  }
+} else {
+  ReadsSeen.push_back(ID);
+}
+  });
+  return std::move(T.second);
+};
+
+Notification Proceed; // Ensure we schedule everything.
+S.update(Path, getInputs(Path, ""), WantDiagnostics::Yes,
+ [&](std::vector Diags) { Proceed.wait(); });
+// The second parens indicate cancellation, where present.
+Update("U1")();
+Read("R1")();
+Update("U2")();
+Read("R2A")();
+Read("R2B");
+Update("U3");
+Read("R3")();
+Proceed.notify();
+  }
+  EXPECT_THAT(DiagsSeen, ElementsAre("U2", "U3"))
+  << "U1 and all dependent reads were cancelled. "
+ "U2 has a dependent read R2A. "
+ "U3 was not cancelled.";
+  EXPECT_THAT(ReadsSeen, ElementsAre("R2B"))
+  << "All reads other than R2B were cancelled";
+  EXPECT_THAT(ReadsCanceled, ElementsAre("R1", "R2A", "R3"))
+  << "All reads other than R2B were cancelled";
+}
+
 TEST_F(TUSchedulerTests, ManyUpdates) {
   const int FilesCount = 3;
   const int UpdatesPerFile = 10;
Index: clangd/TUScheduler.h
===
--- clangd/TUScheduler.h
+++ clangd/TUScheduler.h
@@ -100,6 +100,9 @@
 
   /// Schedule an update for \p File. Adds \p File to a list of tracked files if
   /// \p File was not part of it before.
+  /// If diagnostics are requested (Yes), and the context is cancelled before
+  /// they are prepared, they may be skipped if eventual-consistency permits it
+  /// (i.e. WantDiagnostics is downgraded to Auto).
   /// FIXME(ibiryukov): remove the callback from this function.
   void update(PathRef File, ParseInputs Inputs, WantDiagnostics WD,
   llvm::unique_function)> OnUpdated);
@@ -117,6 +120,8 @@
   /// \p Action is executed.
   /// If an error occurs during processing, it is forwarded to the \p Action
   /// callback.

[clang-tools-extra] r347297 - [clangd] Allow observation of changes to global CDBs.

2018-11-20 Thread Sam McCall via cfe-commits
Author: sammccall
Date: Tue Nov 20 02:56:03 2018
New Revision: 347297

URL: http://llvm.org/viewvc/llvm-project?rev=347297&view=rev
Log:
[clangd] Allow observation of changes to global CDBs.

Summary:
Currently, changes *within* CDBs are not tracked (CDB has no facility to do so).
However, discovery of new CDBs are tracked (all files are marked as modified).
Also, files whose compilation commands are explicitly set are marked modified.

The intent is to use this for auto-index. Newly discovered files will be indexed
with low priority.

Reviewers: ilya-biryukov

Subscribers: ioeric, MaskRay, jkorous, arphaman, kadircet, cfe-commits

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

Added:
clang-tools-extra/trunk/unittests/clangd/FunctionTests.cpp
Modified:
clang-tools-extra/trunk/clangd/Function.h
clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.cpp
clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.h
clang-tools-extra/trunk/unittests/clangd/CMakeLists.txt
clang-tools-extra/trunk/unittests/clangd/GlobalCompilationDatabaseTests.cpp

Modified: clang-tools-extra/trunk/clangd/Function.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/Function.h?rev=347297&r1=347296&r2=347297&view=diff
==
--- clang-tools-extra/trunk/clangd/Function.h (original)
+++ clang-tools-extra/trunk/clangd/Function.h Tue Nov 20 02:56:03 2018
@@ -16,6 +16,7 @@
 
 #include "llvm/ADT/FunctionExtras.h"
 #include "llvm/Support/Error.h"
+#include 
 #include 
 #include 
 
@@ -83,6 +84,82 @@ ForwardBinder Bind(Func F
   std::make_tuple(std::forward(F), std::forward(As)...));
 }
 
+/// An Event allows events of type T to be broadcast to listeners.
+template  class Event {
+public:
+  // A Listener is the callback through which events are delivered.
+  using Listener = std::function;
+
+  // A subscription defines the scope of when a listener should receive events.
+  // After destroying the subscription, no more events are received.
+  class LLVM_NODISCARD Subscription {
+Event *Parent;
+unsigned ListenerID;
+
+Subscription(Event *Parent, unsigned ListenerID)
+: Parent(Parent), ListenerID(ListenerID) {}
+friend Event;
+
+  public:
+Subscription() : Parent(nullptr) {}
+Subscription(Subscription &&Other) : Parent(nullptr) {
+  *this = std::move(Other);
+}
+Subscription &operator=(Subscription &&Other) {
+  // If *this is active, unsubscribe.
+  if (Parent) {
+std::lock_guard(Parent->ListenersMu);
+llvm::erase_if(Parent->Listeners,
+   [&](const std::pair &P) {
+ return P.second == ListenerID;
+   });
+  }
+  // Take over the other subscription, and mark it inactive.
+  std::tie(Parent, ListenerID) = std::tie(Other.Parent, Other.ListenerID);
+  Other.Parent = nullptr;
+  return *this;
+}
+// Destroying a subscription may block if an event is being broadcast.
+~Subscription() {
+  if (Parent)
+*this = Subscription(); // Unsubscribe.
+}
+  };
+
+  // Adds a listener that will observe all future events until the returned
+  // subscription is destroyed.
+  // May block if an event is currently being broadcast.
+  Subscription observe(Listener L) {
+std::lock_guard Lock(ListenersMu);
+Listeners.push_back({std::move(L), ++ListenerCount});
+return Subscription(this, ListenerCount);
+;
+  }
+
+  // Synchronously sends an event to all registered listeners.
+  // Must not be called from a listener to this event.
+  void broadcast(const T &V) {
+// FIXME: it would be nice to dynamically check non-reentrancy here.
+std::lock_guard Lock(ListenersMu);
+for (const auto &L : Listeners)
+  L.first(V);
+  }
+
+  ~Event() {
+std::lock_guard Lock(ListenersMu);
+assert(Listeners.empty());
+  }
+
+private:
+  static_assert(std::is_same::type, T>::value,
+"use a plain type: event values are always passed by const&");
+
+  std::recursive_mutex ListenersMu;
+  bool IsBroadcasting = false;
+  std::vector> Listeners;
+  unsigned ListenerCount = 0;
+};
+
 } // namespace clangd
 } // namespace clang
 

Modified: clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.cpp?rev=347297&r1=347296&r2=347297&view=diff
==
--- clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.cpp (original)
+++ clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.cpp Tue Nov 20 
02:56:03 2018
@@ -49,17 +49,17 @@ DirectoryBasedGlobalCompilationDatabase:
   return None;
 }
 
-tooling::CompilationDatabase *
+std::pair
 DirectoryBasedGlobalCompilationDatabase::getCDBInDirLocked(PathRef Dir) const {
   // FIXME(ibiryukov): Invalidate cached com

[PATCH] D54475: [clangd] Allow observation of changes to global CDBs.

2018-11-20 Thread Sam McCall via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL347297: [clangd] Allow observation of changes to global 
CDBs. (authored by sammccall, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D54475

Files:
  clang-tools-extra/trunk/clangd/Function.h
  clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.cpp
  clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.h
  clang-tools-extra/trunk/unittests/clangd/CMakeLists.txt
  clang-tools-extra/trunk/unittests/clangd/FunctionTests.cpp
  clang-tools-extra/trunk/unittests/clangd/GlobalCompilationDatabaseTests.cpp

Index: clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.h
===
--- clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.h
+++ clang-tools-extra/trunk/clangd/GlobalCompilationDatabase.h
@@ -10,6 +10,7 @@
 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANGD_GLOBALCOMPILATIONDATABASE_H
 #define LLVM_CLANG_TOOLS_EXTRA_CLANGD_GLOBALCOMPILATIONDATABASE_H
 
+#include "Function.h"
 #include "Path.h"
 #include "llvm/ADT/StringMap.h"
 #include 
@@ -41,8 +42,15 @@
   /// Clangd should treat the results as unreliable.
   virtual tooling::CompileCommand getFallbackCommand(PathRef File) const;
 
-  /// FIXME(ibiryukov): add facilities to track changes to compilation flags of
-  /// existing targets.
+  using CommandChanged = Event>;
+  /// The callback is notified when files may have new compile commands.
+  /// The argument is a list of full file paths.
+  CommandChanged::Subscription watch(CommandChanged::Listener L) const {
+return OnCommandChanged.observe(std::move(L));
+  }
+
+protected:
+  mutable CommandChanged OnCommandChanged;
 };
 
 /// Gets compile args from tooling::CompilationDatabases built for parent
@@ -61,7 +69,8 @@
 
 private:
   tooling::CompilationDatabase *getCDBForFile(PathRef File) const;
-  tooling::CompilationDatabase *getCDBInDirLocked(PathRef File) const;
+  std::pair
+  getCDBInDirLocked(PathRef File) const;
 
   mutable std::mutex Mutex;
   /// Caches compilation databases loaded from directories(keys are
@@ -81,8 +90,7 @@
   // Base may be null, in which case no entries are inherited.
   // FallbackFlags are added to the fallback compile command.
   OverlayCDB(const GlobalCompilationDatabase *Base,
- std::vector FallbackFlags = {})
-  : Base(Base), FallbackFlags(std::move(FallbackFlags)) {}
+ std::vector FallbackFlags = {});
 
   llvm::Optional
   getCompileCommand(PathRef File) const override;
@@ -98,6 +106,7 @@
   llvm::StringMap Commands; /* GUARDED_BY(Mut) */
   const GlobalCompilationDatabase *Base;
   std::vector FallbackFlags;
+  CommandChanged::Subscription BaseChanged;
 };
 
 } // namespace clangd
Index: clang-tools-extra/trunk/clangd/Function.h
===
--- clang-tools-extra/trunk/clangd/Function.h
+++ clang-tools-extra/trunk/clangd/Function.h
@@ -16,6 +16,7 @@
 
 #include "llvm/ADT/FunctionExtras.h"
 #include "llvm/Support/Error.h"
+#include 
 #include 
 #include 
 
@@ -83,6 +84,82 @@
   std::make_tuple(std::forward(F), std::forward(As)...));
 }
 
+/// An Event allows events of type T to be broadcast to listeners.
+template  class Event {
+public:
+  // A Listener is the callback through which events are delivered.
+  using Listener = std::function;
+
+  // A subscription defines the scope of when a listener should receive events.
+  // After destroying the subscription, no more events are received.
+  class LLVM_NODISCARD Subscription {
+Event *Parent;
+unsigned ListenerID;
+
+Subscription(Event *Parent, unsigned ListenerID)
+: Parent(Parent), ListenerID(ListenerID) {}
+friend Event;
+
+  public:
+Subscription() : Parent(nullptr) {}
+Subscription(Subscription &&Other) : Parent(nullptr) {
+  *this = std::move(Other);
+}
+Subscription &operator=(Subscription &&Other) {
+  // If *this is active, unsubscribe.
+  if (Parent) {
+std::lock_guard(Parent->ListenersMu);
+llvm::erase_if(Parent->Listeners,
+   [&](const std::pair &P) {
+ return P.second == ListenerID;
+   });
+  }
+  // Take over the other subscription, and mark it inactive.
+  std::tie(Parent, ListenerID) = std::tie(Other.Parent, Other.ListenerID);
+  Other.Parent = nullptr;
+  return *this;
+}
+// Destroying a subscription may block if an event is being broadcast.
+~Subscription() {
+  if (Parent)
+*this = Subscription(); // Unsubscribe.
+}
+  };
+
+  // Adds a listener that will observe all future events until the returned
+  // subscription is destroyed.
+  // May block if an event is currently being broadcast.
+  Subscription observe(Listener L) {
+std::lock_guard Lock(ListenersMu);
+Listeners.push_back({std::move(L), ++Listene

[PATCH] D54694: [clangd] Replay preamble #includes to clang-tidy checks.

2018-11-20 Thread Sam McCall via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL347298: [clangd] Replay preamble #includes to clang-tidy 
checks. (authored by sammccall, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D54694

Files:
  clang-tools-extra/trunk/clangd/ClangdUnit.cpp
  clang-tools-extra/trunk/clangd/Diagnostics.cpp
  clang-tools-extra/trunk/clangd/Headers.cpp
  clang-tools-extra/trunk/clangd/Headers.h
  clang-tools-extra/trunk/unittests/clangd/ClangdUnitTests.cpp
  clang-tools-extra/trunk/unittests/clangd/HeadersTests.cpp

Index: clang-tools-extra/trunk/clangd/ClangdUnit.cpp
===
--- clang-tools-extra/trunk/clangd/ClangdUnit.cpp
+++ clang-tools-extra/trunk/clangd/ClangdUnit.cpp
@@ -119,6 +119,105 @@
   SourceManager *SourceMgr = nullptr;
 };
 
+// When using a preamble, only preprocessor events outside its bounds are seen.
+// This is almost what we want: replaying transitive preprocessing wastes time.
+// However this confuses clang-tidy checks: they don't see any #includes!
+// So we replay the *non-transitive* #includes that appear in the main-file.
+// It would be nice to replay other events (macro definitions, ifdefs etc) but
+// this addresses the most common cases fairly cheaply.
+class ReplayPreamble : private PPCallbacks {
+public:
+  // Attach preprocessor hooks such that preamble events will be injected at
+  // the appropriate time.
+  // Events will be delivered to the *currently registered* PP callbacks.
+  static void attach(const IncludeStructure &Includes,
+ CompilerInstance &Clang) {
+auto &PP = Clang.getPreprocessor();
+auto *ExistingCallbacks = PP.getPPCallbacks();
+PP.addPPCallbacks(std::unique_ptr(
+new ReplayPreamble(Includes, ExistingCallbacks,
+   Clang.getSourceManager(), PP, Clang.getLangOpts(;
+// We're relying on the fact that addPPCallbacks keeps the old PPCallbacks
+// around, creating a chaining wrapper. Guard against other implementations.
+assert(PP.getPPCallbacks() != ExistingCallbacks &&
+   "Expected chaining implementation");
+  }
+
+private:
+  ReplayPreamble(const IncludeStructure &Includes, PPCallbacks *Delegate,
+ const SourceManager &SM, Preprocessor &PP,
+ const LangOptions &LangOpts)
+  : Includes(Includes), Delegate(Delegate), SM(SM), PP(PP),
+LangOpts(LangOpts) {}
+
+  // In a normal compile, the preamble traverses the following structure:
+  //
+  // mainfile.cpp
+  //   
+  // ... macro definitions like __cplusplus ...
+  // 
+  //   ... macro definitions for args like -Dfoo=bar ...
+  //   "header1.h"
+  // ... header file contents ...
+  //   "header2.h"
+  // ... header file contents ...
+  //   ... main file contents ...
+  //
+  // When using a preamble, the "header1" and "header2" subtrees get skipped.
+  // We insert them right after the built-in header, which still appears.
+  void FileChanged(SourceLocation Loc, FileChangeReason Reason,
+   SrcMgr::CharacteristicKind Kind, FileID PrevFID) override {
+// It'd be nice if there was a better way to identify built-in headers...
+if (Reason == FileChangeReason::ExitFile &&
+SM.getBuffer(PrevFID)->getBufferIdentifier() == "")
+  replay();
+  }
+
+  void replay() {
+for (const auto &Inc : Includes.MainFileIncludes) {
+  const FileEntry *File = nullptr;
+  if (Inc.Resolved != "")
+File = SM.getFileManager().getFile(Inc.Resolved);
+
+  StringRef WrittenFilename =
+  StringRef(Inc.Written).drop_front().drop_back();
+  bool Angled = StringRef(Inc.Written).startswith("<");
+
+  // Re-lex the #include directive to find its interesting parts.
+  StringRef Src = SM.getBufferData(SM.getMainFileID());
+  Lexer RawLexer(SM.getLocForStartOfFile(SM.getMainFileID()), LangOpts,
+ Src.begin(), Src.begin() + Inc.HashOffset, Src.end());
+  Token HashTok, IncludeTok, FilenameTok;
+  RawLexer.LexFromRawLexer(HashTok);
+  assert(HashTok.getKind() == tok::hash);
+  RawLexer.setParsingPreprocessorDirective(true);
+  RawLexer.LexFromRawLexer(IncludeTok);
+  IdentifierInfo *II = PP.getIdentifierInfo(IncludeTok.getRawIdentifier());
+  IncludeTok.setIdentifierInfo(II);
+  IncludeTok.setKind(II->getTokenID());
+  RawLexer.LexIncludeFilename(FilenameTok);
+
+  Delegate->InclusionDirective(
+  HashTok.getLocation(), IncludeTok, WrittenFilename, Angled,
+  CharSourceRange::getCharRange(FilenameTok.getLocation(),
+FilenameTok.getEndLoc()),
+  File, "SearchPath", "RelPath", /*Imported=*/nullptr, Inc.FileKind);
+  if (File)
+Delegate->FileSkipped(*File, FilenameTok, Inc.FileKind);
+  else {
+SmallString<1> UnusedRecover

[clang-tools-extra] r347298 - [clangd] Replay preamble #includes to clang-tidy checks.

2018-11-20 Thread Sam McCall via cfe-commits
Author: sammccall
Date: Tue Nov 20 02:58:48 2018
New Revision: 347298

URL: http://llvm.org/viewvc/llvm-project?rev=347298&view=rev
Log:
[clangd] Replay preamble #includes to clang-tidy checks.

Summary:
This is needed to correctly handle checks that use IncludeInserter,
which is very common.

I couldn't find a totally safe example of a check to enable for testing,
I picked modernize-deprecated-headers which some will probably hate.
We should get configuration working...

This depends on D54691 which ensures our calls to getFile(open=false)
don't break subsequent accesses via the FileManager.

Reviewers: ilya-biryukov

Subscribers: ioeric, MaskRay, jkorous, arphaman, kadircet, cfe-commits

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

Modified:
clang-tools-extra/trunk/clangd/ClangdUnit.cpp
clang-tools-extra/trunk/clangd/Diagnostics.cpp
clang-tools-extra/trunk/clangd/Headers.cpp
clang-tools-extra/trunk/clangd/Headers.h
clang-tools-extra/trunk/unittests/clangd/ClangdUnitTests.cpp
clang-tools-extra/trunk/unittests/clangd/HeadersTests.cpp

Modified: clang-tools-extra/trunk/clangd/ClangdUnit.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/ClangdUnit.cpp?rev=347298&r1=347297&r2=347298&view=diff
==
--- clang-tools-extra/trunk/clangd/ClangdUnit.cpp (original)
+++ clang-tools-extra/trunk/clangd/ClangdUnit.cpp Tue Nov 20 02:58:48 2018
@@ -119,6 +119,105 @@ private:
   SourceManager *SourceMgr = nullptr;
 };
 
+// When using a preamble, only preprocessor events outside its bounds are seen.
+// This is almost what we want: replaying transitive preprocessing wastes time.
+// However this confuses clang-tidy checks: they don't see any #includes!
+// So we replay the *non-transitive* #includes that appear in the main-file.
+// It would be nice to replay other events (macro definitions, ifdefs etc) but
+// this addresses the most common cases fairly cheaply.
+class ReplayPreamble : private PPCallbacks {
+public:
+  // Attach preprocessor hooks such that preamble events will be injected at
+  // the appropriate time.
+  // Events will be delivered to the *currently registered* PP callbacks.
+  static void attach(const IncludeStructure &Includes,
+ CompilerInstance &Clang) {
+auto &PP = Clang.getPreprocessor();
+auto *ExistingCallbacks = PP.getPPCallbacks();
+PP.addPPCallbacks(std::unique_ptr(
+new ReplayPreamble(Includes, ExistingCallbacks,
+   Clang.getSourceManager(), PP, 
Clang.getLangOpts(;
+// We're relying on the fact that addPPCallbacks keeps the old PPCallbacks
+// around, creating a chaining wrapper. Guard against other 
implementations.
+assert(PP.getPPCallbacks() != ExistingCallbacks &&
+   "Expected chaining implementation");
+  }
+
+private:
+  ReplayPreamble(const IncludeStructure &Includes, PPCallbacks *Delegate,
+ const SourceManager &SM, Preprocessor &PP,
+ const LangOptions &LangOpts)
+  : Includes(Includes), Delegate(Delegate), SM(SM), PP(PP),
+LangOpts(LangOpts) {}
+
+  // In a normal compile, the preamble traverses the following structure:
+  //
+  // mainfile.cpp
+  //   
+  // ... macro definitions like __cplusplus ...
+  // 
+  //   ... macro definitions for args like -Dfoo=bar ...
+  //   "header1.h"
+  // ... header file contents ...
+  //   "header2.h"
+  // ... header file contents ...
+  //   ... main file contents ...
+  //
+  // When using a preamble, the "header1" and "header2" subtrees get skipped.
+  // We insert them right after the built-in header, which still appears.
+  void FileChanged(SourceLocation Loc, FileChangeReason Reason,
+   SrcMgr::CharacteristicKind Kind, FileID PrevFID) override {
+// It'd be nice if there was a better way to identify built-in headers...
+if (Reason == FileChangeReason::ExitFile &&
+SM.getBuffer(PrevFID)->getBufferIdentifier() == "")
+  replay();
+  }
+
+  void replay() {
+for (const auto &Inc : Includes.MainFileIncludes) {
+  const FileEntry *File = nullptr;
+  if (Inc.Resolved != "")
+File = SM.getFileManager().getFile(Inc.Resolved);
+
+  StringRef WrittenFilename =
+  StringRef(Inc.Written).drop_front().drop_back();
+  bool Angled = StringRef(Inc.Written).startswith("<");
+
+  // Re-lex the #include directive to find its interesting parts.
+  StringRef Src = SM.getBufferData(SM.getMainFileID());
+  Lexer RawLexer(SM.getLocForStartOfFile(SM.getMainFileID()), LangOpts,
+ Src.begin(), Src.begin() + Inc.HashOffset, Src.end());
+  Token HashTok, IncludeTok, FilenameTok;
+  RawLexer.LexFromRawLexer(HashTok);
+  assert(HashTok.getKind() == tok::hash);
+  RawLexer.setParsingPreprocessorDirective(true);
+  RawLexer.LexFromRawLexer(IncludeTok);
+  Iden

[PATCH] D54694: [clangd] Replay preamble #includes to clang-tidy checks.

2018-11-20 Thread Sam McCall via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rCTE347298: [clangd] Replay preamble #includes to clang-tidy 
checks. (authored by sammccall, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D54694?vs=174621&id=174742#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D54694

Files:
  clangd/ClangdUnit.cpp
  clangd/Diagnostics.cpp
  clangd/Headers.cpp
  clangd/Headers.h
  unittests/clangd/ClangdUnitTests.cpp
  unittests/clangd/HeadersTests.cpp

Index: unittests/clangd/ClangdUnitTests.cpp
===
--- unittests/clangd/ClangdUnitTests.cpp
+++ unittests/clangd/ClangdUnitTests.cpp
@@ -131,19 +131,28 @@
 
 TEST(DiagnosticsTest, ClangTidy) {
   Annotations Test(R"cpp(
+#include $deprecated[["assert.h"]]
+
 #define $macrodef[[SQUARE]](X) (X)*(X)
 int main() {
-  return [[sizeof]](sizeof(int));
+  return $doubled[[sizeof]](sizeof(int));
   int y = 4;
   return SQUARE($macroarg[[++]]y);
 }
   )cpp");
   auto TU = TestTU::withCode(Test.code());
+  TU.HeaderFilename = "assert.h"; // Suppress "not found" error.
   EXPECT_THAT(
   TU.build().getDiagnostics(),
   UnorderedElementsAre(
-  Diag(Test.range(), "suspicious usage of 'sizeof(sizeof(...))' "
- "[bugprone-sizeof-expression]"),
+  AllOf(Diag(Test.range("deprecated"),
+ "inclusion of deprecated C++ header 'assert.h'; consider "
+ "using 'cassert' instead [modernize-deprecated-headers]"),
+WithFix(Fix(Test.range("deprecated"), "",
+"change '\"assert.h\"' to ''"))),
+  Diag(Test.range("doubled"),
+   "suspicious usage of 'sizeof(sizeof(...))' "
+   "[bugprone-sizeof-expression]"),
   AllOf(
   Diag(Test.range("macroarg"),
"side effects in the 1st macro argument 'X' are repeated in "
Index: unittests/clangd/HeadersTests.cpp
===
--- unittests/clangd/HeadersTests.cpp
+++ unittests/clangd/HeadersTests.cpp
@@ -11,6 +11,7 @@
 
 #include "Compiler.h"
 #include "TestFS.h"
+#include "TestTU.h"
 #include "clang/Frontend/CompilerInstance.h"
 #include "clang/Frontend/CompilerInvocation.h"
 #include "clang/Frontend/FrontendActions.h"
@@ -24,6 +25,7 @@
 namespace {
 
 using ::testing::AllOf;
+using ::testing::ElementsAre;
 using ::testing::UnorderedElementsAre;
 
 class HeadersTest : public ::testing::Test {
@@ -132,6 +134,7 @@
 
 MATCHER_P(Written, Name, "") { return arg.Written == Name; }
 MATCHER_P(Resolved, Name, "") { return arg.Resolved == Name; }
+MATCHER_P(IncludeLine, N, "") { return arg.R.start.line == N; }
 
 MATCHER_P2(Distance, File, D, "") {
   if (arg.getKey() != File)
@@ -179,6 +182,21 @@
Distance(testPath("sub/baz.h"), 1u)));
 }
 
+TEST_F(HeadersTest, PreambleIncludesPresentOnce) {
+  // We use TestTU here, to ensure we use the preamble replay logic.
+  // We're testing that the logic doesn't crash, and doesn't result in duplicate
+  // includes. (We'd test more directly, but it's pretty well encapsulated!)
+  auto TU = TestTU::withCode(R"cpp(
+#include "a.h"
+#include "a.h"
+void foo();
+#include "a.h"
+  )cpp");
+  TU.HeaderFilename = "a.h"; // suppress "not found".
+  EXPECT_THAT(TU.build().getIncludeStructure().MainFileIncludes,
+  ElementsAre(IncludeLine(1), IncludeLine(2), IncludeLine(4)));
+}
+
 TEST_F(HeadersTest, UnResolvedInclusion) {
   FS.Files[MainFile] = R"cpp(
 #include "foo.h"
@@ -220,19 +238,20 @@
 }
 
 TEST_F(HeadersTest, DontInsertDuplicatePreferred) {
-  std::vector Inclusions = {
-  {Range(), /*Written*/ "\"bar.h\"", /*Resolved*/ ""}};
-  EXPECT_EQ(calculate(testPath("sub/bar.h"), "\"bar.h\"", Inclusions), "");
-  EXPECT_EQ(calculate("\"x.h\"", "\"bar.h\"", Inclusions), "");
+  Inclusion Inc;
+  Inc.Written = "\"bar.h\"";
+  Inc.Resolved = "";
+  EXPECT_EQ(calculate(testPath("sub/bar.h"), "\"bar.h\"", {Inc}), "");
+  EXPECT_EQ(calculate("\"x.h\"", "\"bar.h\"", {Inc}), "");
 }
 
 TEST_F(HeadersTest, DontInsertDuplicateResolved) {
-  std::string BarHeader = testPath("sub/bar.h");
-  std::vector Inclusions = {
-  {Range(), /*Written*/ "fake-bar.h", /*Resolved*/ BarHeader}};
-  EXPECT_EQ(calculate(BarHeader, "", Inclusions), "");
+  Inclusion Inc;
+  Inc.Written = "fake-bar.h";
+  Inc.Resolved = testPath("sub/bar.h");
+  EXPECT_EQ(calculate(Inc.Resolved, "", {Inc}), "");
   // Do not insert preferred.
-  EXPECT_EQ(calculate(BarHeader, "\"BAR.h\"", Inclusions), "");
+  EXPECT_EQ(calculate(Inc.Resolved, "\"BAR.h\"", {Inc}), "");
 }
 
 TEST_F(HeadersTest, PreferInserted) {
Index: clangd/Headers.cpp
===
--- clangd/Headers.cpp
+++ clangd/Headers.cpp
@@ -34,13 +34,17 @@
   Ch

[PATCH] D53697: [ASTImporter][Structural Eq] Check for isBeingDefined

2018-11-20 Thread Gabor Marton via Phabricator via cfe-commits
martong added a comment.
Herald added a subscriber: gamesh411.

@shafik,

I could run the libcxx tests on my Linux machine (Ubuntu 16.04) by installing 
libcxx: `sudo apt-get install libc++-dev`.
From the logs of your build server seems like the crash happened with a 
`_gmodules` test.
Unfortunately, the gmodules tests are still skipped on Linux:

  Collected 8 tests
  
  1: test_ref_and_ptr_dsym 
(TestDataFormatterLibcxxVector.LibcxxVectorDataFormatterTestCase)
 Test that that file and class static variables display correctly. ... 
skipped 'test case does not fall in any category of interest for this run'
  2: test_ref_and_ptr_dwarf 
(TestDataFormatterLibcxxVector.LibcxxVectorDataFormatterTestCase)
 Test that that file and class static variables display correctly. ... ok
  3: test_ref_and_ptr_dwo 
(TestDataFormatterLibcxxVector.LibcxxVectorDataFormatterTestCase)
 Test that that file and class static variables display correctly. ... ok
  4: test_ref_and_ptr_gmodules 
(TestDataFormatterLibcxxVector.LibcxxVectorDataFormatterTestCase)
 Test that that file and class static variables display correctly. ... 
skipped 'test case does not fall in any category of interest for this run'
  5: test_with_run_command_dsym 
(TestDataFormatterLibcxxVector.LibcxxVectorDataFormatterTestCase)
 Test that that file and class static variables display correctly. ... 
skipped 'test case does not fall in any category of interest for this run'
  6: test_with_run_command_dwarf 
(TestDataFormatterLibcxxVector.LibcxxVectorDataFormatterTestCase)
 Test that that file and class static variables display correctly. ... ok
  7: test_with_run_command_dwo 
(TestDataFormatterLibcxxVector.LibcxxVectorDataFormatterTestCase)
 Test that that file and class static variables display correctly. ... ok
  8: test_with_run_command_gmodules 
(TestDataFormatterLibcxxVector.LibcxxVectorDataFormatterTestCase)
 Test that that file and class static variables display correctly. ... 
skipped 'test case does not fall in any category of interest for this run'
  
  --
  Ran 8 tests in 1.260s

This  is aligned with the content of `test_categories.py`:

  def is_supported_on_platform(category, platform, compiler_path):
  if category == "dwo":
  # -gsplit-dwarf is not implemented by clang on Windows.
  return platform in ["linux", "freebsd"]
  elif category == "dsym":
  return platform in ["darwin", "macosx", "ios", "watchos", "tvos", 
"bridgeos"]
  elif category == "gmodules":
  # First, check to see if the platform can even support gmodules.
  if platform not in ["freebsd", "darwin", "macosx", "ios", "watchos", 
"tvos", "bridgeos"]:
  return False
  return gmodules.is_compiler_clang_with_gmodules(compiler_path)
  return True

So apparently I cannot run `gmodules` tests on Linux.

My next step is trying to reproduce the issue on a real MacOS laptop.


Repository:
  rC Clang

https://reviews.llvm.org/D53697



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


[PATCH] D53076: [analyzer] Enhance ConditionBRVisitor to write out more information

2018-11-20 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso marked 8 inline comments as done.
Charusso added a comment.

@NoQ thanks you for the great explanation! I really wanted to write out known 
constant integers and booleans but I think 'Knowing...' pieces would be more 
cool.

I tried to minimize the changes after a little e-mailing with @george.karpenkov 
on the mailing list. The problem is the following: we go backwards on the 
bug-path, that is why we see range information changes backwards, but the user 
information goes forwards: from the top to the bottom. I have implemented the 
'check upwards' feature, so now everything working fine, but I think it is a 
very time-consuming approach. (The idea is copied from 
`BugReporter.cpp/generateVisitorsDiagnostics()` where I tried to flip the path, 
unsuccessfully: 
http://clang-developers.42468.n3.nabble.com/Visit-nodes-in-the-order-of-the-user-output-to-create-better-reports-td4062898.html
 )


https://reviews.llvm.org/D53076



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


r347304 - Allow force updating the NumCreatedFIDsForFileID.

2018-11-20 Thread Vassil Vassilev via cfe-commits
Author: vvassilev
Date: Tue Nov 20 05:53:20 2018
New Revision: 347304

URL: http://llvm.org/viewvc/llvm-project?rev=347304&view=rev
Log:
Allow force updating the NumCreatedFIDsForFileID.

Our internal clients implement parsing cache based on FileID. In order for the
Preprocessor to reenter the cached FileID it needs to reset its
NumCreatedFIDsForFileID.

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

Modified:
cfe/trunk/include/clang/Basic/SourceManager.h

Modified: cfe/trunk/include/clang/Basic/SourceManager.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/SourceManager.h?rev=347304&r1=347303&r2=347304&view=diff
==
--- cfe/trunk/include/clang/Basic/SourceManager.h (original)
+++ cfe/trunk/include/clang/Basic/SourceManager.h Tue Nov 20 05:53:20 2018
@@ -1024,13 +1024,14 @@ public:
 
   /// Set the number of FileIDs (files and macros) that were created
   /// during preprocessing of \p FID, including it.
-  void setNumCreatedFIDsForFileID(FileID FID, unsigned NumFIDs) const {
+  void setNumCreatedFIDsForFileID(FileID FID, unsigned NumFIDs,
+  bool Force = false) const {
 bool Invalid = false;
 const SrcMgr::SLocEntry &Entry = getSLocEntry(FID, &Invalid);
 if (Invalid || !Entry.isFile())
   return;
 
-assert(Entry.getFile().NumCreatedFIDs == 0 && "Already set!");
+assert((Force || Entry.getFile().NumCreatedFIDs == 0) && "Already set!");
 const_cast(Entry.getFile()).NumCreatedFIDs = NumFIDs;
   }
 


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


[PATCH] D51295: Allow resetting of NumCreatedFIDsForFileID

2018-11-20 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC347304: Allow force updating the NumCreatedFIDsForFileID. 
(authored by vvassilev, committed by ).

Repository:
  rC Clang

https://reviews.llvm.org/D51295

Files:
  include/clang/Basic/SourceManager.h


Index: include/clang/Basic/SourceManager.h
===
--- include/clang/Basic/SourceManager.h
+++ include/clang/Basic/SourceManager.h
@@ -1024,13 +1024,14 @@
 
   /// Set the number of FileIDs (files and macros) that were created
   /// during preprocessing of \p FID, including it.
-  void setNumCreatedFIDsForFileID(FileID FID, unsigned NumFIDs) const {
+  void setNumCreatedFIDsForFileID(FileID FID, unsigned NumFIDs,
+  bool Force = false) const {
 bool Invalid = false;
 const SrcMgr::SLocEntry &Entry = getSLocEntry(FID, &Invalid);
 if (Invalid || !Entry.isFile())
   return;
 
-assert(Entry.getFile().NumCreatedFIDs == 0 && "Already set!");
+assert((Force || Entry.getFile().NumCreatedFIDs == 0) && "Already set!");
 const_cast(Entry.getFile()).NumCreatedFIDs = NumFIDs;
   }
 


Index: include/clang/Basic/SourceManager.h
===
--- include/clang/Basic/SourceManager.h
+++ include/clang/Basic/SourceManager.h
@@ -1024,13 +1024,14 @@
 
   /// Set the number of FileIDs (files and macros) that were created
   /// during preprocessing of \p FID, including it.
-  void setNumCreatedFIDsForFileID(FileID FID, unsigned NumFIDs) const {
+  void setNumCreatedFIDsForFileID(FileID FID, unsigned NumFIDs,
+  bool Force = false) const {
 bool Invalid = false;
 const SrcMgr::SLocEntry &Entry = getSLocEntry(FID, &Invalid);
 if (Invalid || !Entry.isFile())
   return;
 
-assert(Entry.getFile().NumCreatedFIDs == 0 && "Already set!");
+assert((Force || Entry.getFile().NumCreatedFIDs == 0) && "Already set!");
 const_cast(Entry.getFile()).NumCreatedFIDs = NumFIDs;
   }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D54355: Use is.constant intrinsic for __builtin_constant_p

2018-11-20 Thread Ulrich Weigand via Phabricator via cfe-commits
uweigand added a comment.

It seems this patch caused the SystemZ build bots to fail, they're now all 
running into assertion failures:

ICE cannot be evaluated!
UNREACHABLE executed at 
/home/uweigand/sandbox/buildbot/clang-s390x-linux/llvm/tools/clang/lib/AST/ExprConstant.cpp:11442!

See e.g. 
http://lab.llvm.org:8011/builders/clang-s390x-linux/builds/20645/steps/ninja%20check%201/logs/FAIL%3A%20Clang%3A%3Abuiltins-systemz-zvector-error.c


Repository:
  rC Clang

https://reviews.llvm.org/D54355



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


[PATCH] D53076: [analyzer] Enhance ConditionBRVisitor to write out more information

2018-11-20 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso added inline comments.



Comment at: test/Analysis/diagnostics/macros.cpp:33
 void testDoubleMacro(double d) {
-  if (d == DBL_MAX) { // expected-note {{Taking true branch}}
+  if (d == DBL_MAX) { // expected-note {{Assuming 'd' is equal to DBL_MAX}}
+  // expected-note@-1 {{Taking true branch}}

NoQ wrote:
> This one's good. Static Analyzer doesn't understand floats, so this branch is 
> indeed non-trivial. There should indeed be an assuming... piece here.
A little bit misunderstandable, because we do not know anything about doubles. 
May the generic message fit better?



Comment at: test/Analysis/diagnostics/undef-value-param.m:56
 SCDynamicStoreRef ref = anotherCreateRef(&err, x);
-if (err) { 
-   //expected-note@-1{{Assuming 'err' is not equal to 0}}
-   //expected-note@-2{{Taking true branch}}
-CFRelease(ref);
-ref = 0; // expected-note{{nil object reference stored to 'ref'}}
+if (err) { //expected-note{{Taking true branch}}
+  CFRelease(ref);

I am not sure why but the range here [1, (2^64)-1]. There is would not be any 
number like 0?



Comment at: test/Analysis/new-ctor-malloc.cpp:11
   void *x = malloc(size); // expected-note {{Memory is allocated}}
-  if (!x) // expected-note{{Assuming 'x' is non-null}}
-  // expected-note@-1 {{Taking false branch}}
+  if (!x) // expected-note {{Taking false branch}}
 return nullptr;

The range information is [1, (2^64)-1] but as I saw `malloc` could return null. 
Who is lying here?



Comment at: test/Analysis/uninit-vals.m:167
   testObj->origin = makePoint(0.0, 0.0);
-  if (testObj->size > 0) { ; } // expected-note{{Taking false branch}}
+  if (testObj->size > 0) { ; } // expected-note{{Assuming the condition is 
false}}
+   // expected-note@-1{{Taking false branch}}

NoQ wrote:
> These are pretty weird. As far as i understand the test, these should be 
> there. But i'm suddenly unable to debug why were they not shown before, 
> because there's either something wrong with exploded graph dumps or with the 
> exploded graph itself; it appears to be missing an edge right after `size > 
> 0` is assumed. I'll look more into those.
We gather information with `clang-analyzer-eval` functions so the conditions 
would be `Knowing...` pieces but the `BugReporter.cpp` does not know about 
these extra assumptations. Where to teach to do not `Assuming...`, but 
`Knowing...` these?



Comment at: test/Analysis/virtualcall.cpp:172
 #endif
   X x(i - 1);
 #if !PUREONLY

Because this `X x(i - 1);` we assume these conditions? This one is tricky to be 
`Knowing...`.


https://reviews.llvm.org/D53076



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


[PATCH] D54753: [clang-format] JS: don't treat is: as a type matcher

2018-11-20 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir created this revision.
Herald added a subscriber: cfe-commits.

Clang-format is treating all occurences of `is` in js as type matchers. In some
cases this is wrong, as it might be a dict key.


Repository:
  rC Clang

https://reviews.llvm.org/D54753

Files:
  lib/Format/TokenAnnotator.cpp
  unittests/Format/FormatTestJS.cpp


Index: unittests/Format/FormatTestJS.cpp
===
--- unittests/Format/FormatTestJS.cpp
+++ unittests/Format/FormatTestJS.cpp
@@ -1186,6 +1186,16 @@
getGoogleJSStyleWithColumns(25));
 }
 
+TEST_F(FormatTestJS, AddsIsTheDictKeyOnNewline) {
+  // Do not confuse is, the dict key with is, the type matcher. Put is, the 
dict
+  // key, on a newline.
+  verifyFormat("Polymer({\n"
+   "  is: '',  //\n"
+   "  rest: 1\n"
+   "});",
+   getGoogleJSStyleWithColumns(20));
+}
+
 TEST_F(FormatTestJS, AutomaticSemicolonInsertionHeuristic) {
   verifyFormat("a\n"
"b;",
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -3113,8 +3113,21 @@
 // Don't wrap between ":" and "!" of a strict prop init ("field!: type;").
 if (Left.is(tok::exclaim) && Right.is(tok::colon))
   return false;
-if (Right.is(Keywords.kw_is))
-  return false;
+// Look for is type annotations like:
+// function f(): a is B { ... }
+// Do not break before is in these cases.
+if (Right.is(Keywords.kw_is)) {
+  const FormatToken* Next = Right.getNextNonComment();
+  // If `is` is followed by a colon, it's likely that it's a dict key, so
+  // ignore it for this check.
+  // For example this is common in Polymer:
+  // Polymer({
+  //   is: 'name',
+  //   ...
+  // });
+  if (!Next || !Next->is(tok::colon))
+return false;
+}
 if (Left.is(Keywords.kw_in))
   return Style.BreakBeforeBinaryOperators == FormatStyle::BOS_None;
 if (Right.is(Keywords.kw_in))


Index: unittests/Format/FormatTestJS.cpp
===
--- unittests/Format/FormatTestJS.cpp
+++ unittests/Format/FormatTestJS.cpp
@@ -1186,6 +1186,16 @@
getGoogleJSStyleWithColumns(25));
 }
 
+TEST_F(FormatTestJS, AddsIsTheDictKeyOnNewline) {
+  // Do not confuse is, the dict key with is, the type matcher. Put is, the dict
+  // key, on a newline.
+  verifyFormat("Polymer({\n"
+   "  is: '',  //\n"
+   "  rest: 1\n"
+   "});",
+   getGoogleJSStyleWithColumns(20));
+}
+
 TEST_F(FormatTestJS, AutomaticSemicolonInsertionHeuristic) {
   verifyFormat("a\n"
"b;",
Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -3113,8 +3113,21 @@
 // Don't wrap between ":" and "!" of a strict prop init ("field!: type;").
 if (Left.is(tok::exclaim) && Right.is(tok::colon))
   return false;
-if (Right.is(Keywords.kw_is))
-  return false;
+// Look for is type annotations like:
+// function f(): a is B { ... }
+// Do not break before is in these cases.
+if (Right.is(Keywords.kw_is)) {
+  const FormatToken* Next = Right.getNextNonComment();
+  // If `is` is followed by a colon, it's likely that it's a dict key, so
+  // ignore it for this check.
+  // For example this is common in Polymer:
+  // Polymer({
+  //   is: 'name',
+  //   ...
+  // });
+  if (!Next || !Next->is(tok::colon))
+return false;
+}
 if (Left.is(Keywords.kw_in))
   return Style.BreakBeforeBinaryOperators == FormatStyle::BOS_None;
 if (Right.is(Keywords.kw_in))
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D54745: [clang-tidy] Don't generate incorrect fixes for class with deleted copy constructor in smart_ptr check.

2018-11-20 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 174760.
hokein marked 2 inline comments as done.
hokein added a comment.

Address review comments, handle move constructor as well.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D54745

Files:
  clang-tidy/modernize/MakeSmartPtrCheck.cpp
  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
@@ -32,6 +32,38 @@
 
 struct Empty {};
 
+struct NoCopyMoveCtor {
+  NoCopyMoveCtor(const NoCopyMoveCtor &) = delete; // implies move ctor is 
deleted
+};
+
+struct NoCopyMoveCtorVisible {
+private:
+  NoCopyMoveCtorVisible(const NoCopyMoveCtorVisible&) = default;
+  NoCopyMoveCtorVisible(NoCopyMoveCtorVisible&&) = default;
+};
+
+struct OnlyMoveCtor {
+  OnlyMoveCtor() = default;
+  OnlyMoveCtor(OnlyMoveCtor&&) = default;
+  OnlyMoveCtor(const OnlyMoveCtor &) = delete;
+};
+
+struct OnlyCopyCtor {
+  OnlyCopyCtor(const OnlyCopyCtor&) = default;
+  OnlyCopyCtor(OnlyCopyCtor&&) = delete;
+};
+
+struct OnlyCopyCtorVisible {
+  OnlyCopyCtorVisible(const OnlyCopyCtorVisible &) = default;
+
+private:
+  OnlyCopyCtorVisible(OnlyCopyCtorVisible &&) = default;
+};
+
+struct ImplicitDeletedCopyCtor {
+  const OnlyMoveCtor ctor;
+};
+
 struct E {
   E(std::initializer_list);
   E();
@@ -270,6 +302,33 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:35: warning: use std::make_unique instead
   // CHECK-FIXES: std::unique_ptr PEmpty = 
std::make_unique(Empty{});
 
+  // No fixes for classes with deleted copy&move constructors.
+  auto PNoCopyMoveCtor = std::unique_ptr(new NoCopyMoveCtor{});
+  // CHECK-MESSAGES: :[[@LINE-1]]:26: warning: use std::make_unique instead
+  // CHECK-FIXES: auto PNoCopyMoveCtor = std::unique_ptr(new 
NoCopyMoveCtor{});
+
+  auto PNoCopyMoveCtorVisible = std::unique_ptr(new 
NoCopyMoveCtorVisible{});
+  // CHECK-MESSAGES: :[[@LINE-1]]:33: warning: use std::make_unique instead
+  // CHECK-FIXES: auto PNoCopyMoveCtorVisible = 
std::unique_ptr(new NoCopyMoveCtorVisible{});
+
+  auto POnlyMoveCtor = std::unique_ptr(new OnlyMoveCtor{});
+  // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: use std::make_unique instead
+  // CHECK-FIXES: auto POnlyMoveCtor = std::unique_ptr(new 
OnlyMoveCtor{});
+
+  // Fix for classes with classes with move constructor.
+  auto POnlyCopyCtor = std::unique_ptr(new OnlyCopyCtor{});
+  // CHECK-MESSAGES: :[[@LINE-1]]:24: warning: use std::make_unique instead
+  // CHECK-FIXES: auto POnlyCopyCtor = std::unique_ptr(new 
OnlyCopyCtor{});
+
+   // Fix for classes with classes with move constructor.
+  auto POnlyCopyCtorVisible = std::unique_ptr(new 
OnlyCopyCtorVisible{});
+  // CHECK-MESSAGES: :[[@LINE-1]]:31: warning: use std::make_unique instead
+  // CHECK-FIXES: auto POnlyCopyCtorVisible = 
std::unique_ptr(new OnlyCopyCtorVisible{});
+
+  auto PImplicitDeletedCopyCtor = std::unique_ptr(new 
ImplicitDeletedCopyCtor{});
+  // CHECK-MESSAGES: :[[@LINE-1]]:35: warning: use std::make_unique instead
+  // CHECK-FIXES: auto PImplicitDeletedCopyCtor = 
std::unique_ptr(new ImplicitDeletedCopyCtor{});
+
   // Initialization with default constructor.
   std::unique_ptr PE1 = std::unique_ptr(new E{});
   // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: use std::make_unique instead
Index: clang-tidy/modernize/MakeSmartPtrCheck.cpp
===
--- clang-tidy/modernize/MakeSmartPtrCheck.cpp
+++ clang-tidy/modernize/MakeSmartPtrCheck.cpp
@@ -375,6 +375,18 @@
   //   smart_ptr(new Pair{first, second});
   // Has to be replaced with:
   //   smart_ptr(Pair{first, second});
+  //
+  // The fix (std::make_unique) requires to see copy/move constructor of
+  // Pair. If we found any invisible or deleted copy/move constructor, we
+  // stop generating fixes -- as the C++ rule is complicated and we are 
less
+  // certain about the correct fixes.
+  if (const auto *RD = New->getType()->getPointeeCXXRecordDecl()) {
+for (const auto *Ctor : RD->ctors()) {
+  if (Ctor->isCopyOrMoveConstructor() &&
+  (Ctor->isDeleted() || Ctor->getAccess() == AS_private))
+return false;
+}
+  }
   InitRange = SourceRange(
   New->getAllocatedTypeSourceInfo()->getTypeLoc().getBeginLoc(),
   New->getInitializer()->getSourceRange().getEnd());


Index: test/clang-tidy/modernize-make-unique.cpp
===
--- test/clang-tidy/modernize-make-unique.cpp
+++ test/clang-tidy/modernize-make-unique.cpp
@@ -32,6 +32,38 @@
 
 struct Empty {};
 
+struct NoCopyMoveCtor {
+  NoCopyMoveCtor(const NoCopyMoveCtor &) = delete; // implies move ctor is deleted
+};
+
+struct NoCopyMoveCtorVisible {
+private:
+  NoCopyMoveCtorVisible(const NoCopyMoveCtorVisible&) = default;
+  NoCopyMoveCtorVisible

[PATCH] D54745: [clang-tidy] Don't generate incorrect fixes for class with deleted copy constructor in smart_ptr check.

2018-11-20 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a comment.

Thanks for the review.

In https://reviews.llvm.org/D54745#1303972, @JonasToth wrote:

> Does make_unique require the copy constructor if it could move?


No, in that case, move constructor will be used. I have updated the patch to 
include these cases.

> And would the same argument apply to the move-constructors as the arguments 
> are forwarded?
>  What would happen in the obscure case of a public copy-constructor, but 
> private move-constructor (not saying it makes sense :))

This depends. The rule is complicated, for some cases it works, for other 
cases, it won't work.




Comment at: test/clang-tidy/modernize-make-unique.cpp:35
 
+struct NoCopyCtor {
+  NoCopyCtor(const NoCopyCtor&) = delete;

JonasToth wrote:
> please add a case for the `private` copy-constructor as well.
Added more tests.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D54745



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


[PATCH] D54560: [analyzer] MoveChecker Pt.3: Improve warning messages a bit.

2018-11-20 Thread Csaba Dabis via Phabricator via cfe-commits
Charusso added a comment.

In https://reviews.llvm.org/D54560#1301870, @NoQ wrote:

> Write down full messages in tests. When the message was updated from `'x' is 
> moved'` to `Object 'x' is moved`, the tests were not updated because they 
> kept passing because the former is still a sub-string of the latter.


It would not be cool to rewrite this `contains` effect to equality like in the 
regex file-checks? I have ran in the same problem and I was very surprised (for 
an hour) why my error-dumps does not show up on rewriting bug-report messages.


https://reviews.llvm.org/D54560



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


r347306 - [ASTImporter] Set redecl chain of functions before any other import

2018-11-20 Thread Gabor Marton via cfe-commits
Author: martong
Date: Tue Nov 20 06:19:39 2018
New Revision: 347306

URL: http://llvm.org/viewvc/llvm-project?rev=347306&view=rev
Log:
[ASTImporter] Set redecl chain of functions before any other import

Summary:
FunctionDecl import starts with a lookup and then we create a new Decl.
Then in case of CXXConstructorDecl we further import other Decls
(base classes, members through CXXConstructorDecl::inits()) before connecting
the redecl chain.  During those in-between imports structural eq fails
because the canonical decl is different.  This commit fixes this.
Synthesizing a test seemed extremely hard, however, Xerces analysis
reproduces the problem.

Reviewers: a_sidorin, a.sidorin

Subscribers: rnkovacs, dkrupp, Szelethus, cfe-commits

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

Modified:
cfe/trunk/lib/AST/ASTImporter.cpp

Modified: cfe/trunk/lib/AST/ASTImporter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTImporter.cpp?rev=347306&r1=347305&r2=347306&view=diff
==
--- cfe/trunk/lib/AST/ASTImporter.cpp (original)
+++ cfe/trunk/lib/AST/ASTImporter.cpp Tue Nov 20 06:19:39 2018
@@ -3144,19 +3144,6 @@ ExpectedDecl ASTNodeImporter::VisitFunct
 FromConstructor->isExplicit(),
 D->isInlineSpecified(), D->isImplicit(), D->isConstexpr()))
   return ToFunction;
-if (unsigned NumInitializers = FromConstructor->getNumCtorInitializers()) {
-  SmallVector CtorInitializers(NumInitializers);
-  // Import first, then allocate memory and copy if there was no error.
-  if (Error Err = ImportContainerChecked(
-  FromConstructor->inits(), CtorInitializers))
-return std::move(Err);
-  auto **Memory =
-  new (Importer.getToContext()) CXXCtorInitializer *[NumInitializers];
-  std::copy(CtorInitializers.begin(), CtorInitializers.end(), Memory);
-  auto *ToCtor = cast(ToFunction);
-  ToCtor->setCtorInitializers(Memory);
-  ToCtor->setNumCtorInitializers(NumInitializers);
-}
   } else if (isa(D)) {
 if (GetImportedOrCreateDecl(
 ToFunction, D, Importer.getToContext(), cast(DC),
@@ -3184,6 +3171,30 @@ ExpectedDecl ASTNodeImporter::VisitFunct
   return ToFunction;
   }
 
+  // Connect the redecl chain.
+  if (FoundByLookup) {
+auto *Recent = const_cast(
+  FoundByLookup->getMostRecentDecl());
+ToFunction->setPreviousDecl(Recent);
+  }
+
+  // Import Ctor initializers.
+  if (auto *FromConstructor = dyn_cast(D)) {
+if (unsigned NumInitializers = FromConstructor->getNumCtorInitializers()) {
+  SmallVector CtorInitializers(NumInitializers);
+  // Import first, then allocate memory and copy if there was no error.
+  if (Error Err = ImportContainerChecked(
+  FromConstructor->inits(), CtorInitializers))
+return std::move(Err);
+  auto **Memory =
+  new (Importer.getToContext()) CXXCtorInitializer *[NumInitializers];
+  std::copy(CtorInitializers.begin(), CtorInitializers.end(), Memory);
+  auto *ToCtor = cast(ToFunction);
+  ToCtor->setCtorInitializers(Memory);
+  ToCtor->setNumCtorInitializers(NumInitializers);
+}
+  }
+
   ToFunction->setQualifierInfo(ToQualifierLoc);
   ToFunction->setAccess(D->getAccess());
   ToFunction->setLexicalDeclContext(LexicalDC);
@@ -3199,12 +3210,6 @@ ExpectedDecl ASTNodeImporter::VisitFunct
   }
   ToFunction->setParams(Parameters);
 
-  if (FoundByLookup) {
-auto *Recent = const_cast(
-  FoundByLookup->getMostRecentDecl());
-ToFunction->setPreviousDecl(Recent);
-  }
-
   // We need to complete creation of FunctionProtoTypeLoc manually with setting
   // params it refers to.
   if (TInfo) {


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


[PATCH] D53702: [ASTImporter] Set redecl chain of functions before any other import

2018-11-20 Thread Gabor Marton via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC347306: [ASTImporter] Set redecl chain of functions before 
any other import (authored by martong, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D53702?vs=171093&id=174763#toc

Repository:
  rC Clang

https://reviews.llvm.org/D53702

Files:
  lib/AST/ASTImporter.cpp


Index: lib/AST/ASTImporter.cpp
===
--- lib/AST/ASTImporter.cpp
+++ lib/AST/ASTImporter.cpp
@@ -3144,19 +3144,6 @@
 FromConstructor->isExplicit(),
 D->isInlineSpecified(), D->isImplicit(), D->isConstexpr()))
   return ToFunction;
-if (unsigned NumInitializers = FromConstructor->getNumCtorInitializers()) {
-  SmallVector CtorInitializers(NumInitializers);
-  // Import first, then allocate memory and copy if there was no error.
-  if (Error Err = ImportContainerChecked(
-  FromConstructor->inits(), CtorInitializers))
-return std::move(Err);
-  auto **Memory =
-  new (Importer.getToContext()) CXXCtorInitializer *[NumInitializers];
-  std::copy(CtorInitializers.begin(), CtorInitializers.end(), Memory);
-  auto *ToCtor = cast(ToFunction);
-  ToCtor->setCtorInitializers(Memory);
-  ToCtor->setNumCtorInitializers(NumInitializers);
-}
   } else if (isa(D)) {
 if (GetImportedOrCreateDecl(
 ToFunction, D, Importer.getToContext(), cast(DC),
@@ -3184,6 +3171,30 @@
   return ToFunction;
   }
 
+  // Connect the redecl chain.
+  if (FoundByLookup) {
+auto *Recent = const_cast(
+  FoundByLookup->getMostRecentDecl());
+ToFunction->setPreviousDecl(Recent);
+  }
+
+  // Import Ctor initializers.
+  if (auto *FromConstructor = dyn_cast(D)) {
+if (unsigned NumInitializers = FromConstructor->getNumCtorInitializers()) {
+  SmallVector CtorInitializers(NumInitializers);
+  // Import first, then allocate memory and copy if there was no error.
+  if (Error Err = ImportContainerChecked(
+  FromConstructor->inits(), CtorInitializers))
+return std::move(Err);
+  auto **Memory =
+  new (Importer.getToContext()) CXXCtorInitializer *[NumInitializers];
+  std::copy(CtorInitializers.begin(), CtorInitializers.end(), Memory);
+  auto *ToCtor = cast(ToFunction);
+  ToCtor->setCtorInitializers(Memory);
+  ToCtor->setNumCtorInitializers(NumInitializers);
+}
+  }
+
   ToFunction->setQualifierInfo(ToQualifierLoc);
   ToFunction->setAccess(D->getAccess());
   ToFunction->setLexicalDeclContext(LexicalDC);
@@ -3199,12 +3210,6 @@
   }
   ToFunction->setParams(Parameters);
 
-  if (FoundByLookup) {
-auto *Recent = const_cast(
-  FoundByLookup->getMostRecentDecl());
-ToFunction->setPreviousDecl(Recent);
-  }
-
   // We need to complete creation of FunctionProtoTypeLoc manually with setting
   // params it refers to.
   if (TInfo) {


Index: lib/AST/ASTImporter.cpp
===
--- lib/AST/ASTImporter.cpp
+++ lib/AST/ASTImporter.cpp
@@ -3144,19 +3144,6 @@
 FromConstructor->isExplicit(),
 D->isInlineSpecified(), D->isImplicit(), D->isConstexpr()))
   return ToFunction;
-if (unsigned NumInitializers = FromConstructor->getNumCtorInitializers()) {
-  SmallVector CtorInitializers(NumInitializers);
-  // Import first, then allocate memory and copy if there was no error.
-  if (Error Err = ImportContainerChecked(
-  FromConstructor->inits(), CtorInitializers))
-return std::move(Err);
-  auto **Memory =
-  new (Importer.getToContext()) CXXCtorInitializer *[NumInitializers];
-  std::copy(CtorInitializers.begin(), CtorInitializers.end(), Memory);
-  auto *ToCtor = cast(ToFunction);
-  ToCtor->setCtorInitializers(Memory);
-  ToCtor->setNumCtorInitializers(NumInitializers);
-}
   } else if (isa(D)) {
 if (GetImportedOrCreateDecl(
 ToFunction, D, Importer.getToContext(), cast(DC),
@@ -3184,6 +3171,30 @@
   return ToFunction;
   }
 
+  // Connect the redecl chain.
+  if (FoundByLookup) {
+auto *Recent = const_cast(
+  FoundByLookup->getMostRecentDecl());
+ToFunction->setPreviousDecl(Recent);
+  }
+
+  // Import Ctor initializers.
+  if (auto *FromConstructor = dyn_cast(D)) {
+if (unsigned NumInitializers = FromConstructor->getNumCtorInitializers()) {
+  SmallVector CtorInitializers(NumInitializers);
+  // Import first, then allocate memory and copy if there was no error.
+  if (Error Err = ImportContainerChecked(
+  FromConstructor->inits(), CtorInitializers))
+return std::move(Err);
+  auto **Memory =
+  new (Importer.getToContext()) CXXCtorInitializer *[NumInitializers];
+  std::copy(CtorInitializers.begin(), CtorInitializers.end(), Memory);
+  auto *ToCtor = cast(ToFunction);
+  ToCtor->setCtorInitializers(Me

r347307 - [clang-format] JS: don't treat is: as a type matcher

2018-11-20 Thread Krasimir Georgiev via cfe-commits
Author: krasimir
Date: Tue Nov 20 06:22:43 2018
New Revision: 347307

URL: http://llvm.org/viewvc/llvm-project?rev=347307&view=rev
Log:
[clang-format] JS: don't treat is: as a type matcher

Summary:
Clang-format is treating all occurences of `is` in js as type matchers. In some
cases this is wrong, as it might be a dict key.

Reviewers: mprobst

Reviewed By: mprobst

Subscribers: cfe-commits

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

Modified:
cfe/trunk/lib/Format/TokenAnnotator.cpp
cfe/trunk/unittests/Format/FormatTestJS.cpp

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=347307&r1=347306&r2=347307&view=diff
==
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Tue Nov 20 06:22:43 2018
@@ -3113,8 +3113,21 @@ bool TokenAnnotator::canBreakBefore(cons
 // Don't wrap between ":" and "!" of a strict prop init ("field!: type;").
 if (Left.is(tok::exclaim) && Right.is(tok::colon))
   return false;
-if (Right.is(Keywords.kw_is))
-  return false;
+// Look for is type annotations like:
+// function f(): a is B { ... }
+// Do not break before is in these cases.
+if (Right.is(Keywords.kw_is)) {
+  const FormatToken* Next = Right.getNextNonComment();
+  // If `is` is followed by a colon, it's likely that it's a dict key, so
+  // ignore it for this check.
+  // For example this is common in Polymer:
+  // Polymer({
+  //   is: 'name',
+  //   ...
+  // });
+  if (!Next || !Next->is(tok::colon))
+return false;
+}
 if (Left.is(Keywords.kw_in))
   return Style.BreakBeforeBinaryOperators == FormatStyle::BOS_None;
 if (Right.is(Keywords.kw_in))

Modified: cfe/trunk/unittests/Format/FormatTestJS.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJS.cpp?rev=347307&r1=347306&r2=347307&view=diff
==
--- cfe/trunk/unittests/Format/FormatTestJS.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp Tue Nov 20 06:22:43 2018
@@ -1186,6 +1186,16 @@ TEST_F(FormatTestJS, WrapRespectsAutomat
getGoogleJSStyleWithColumns(25));
 }
 
+TEST_F(FormatTestJS, AddsIsTheDictKeyOnNewline) {
+  // Do not confuse is, the dict key with is, the type matcher. Put is, the 
dict
+  // key, on a newline.
+  verifyFormat("Polymer({\n"
+   "  is: '',  //\n"
+   "  rest: 1\n"
+   "});",
+   getGoogleJSStyleWithColumns(20));
+}
+
 TEST_F(FormatTestJS, AutomaticSemicolonInsertionHeuristic) {
   verifyFormat("a\n"
"b;",


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


[PATCH] D54753: [clang-format] JS: don't treat is: as a type matcher

2018-11-20 Thread Krasimir Georgiev via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC347307: [clang-format] JS: don't treat is: as a type 
matcher (authored by krasimir, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D54753?vs=174759&id=174764#toc

Repository:
  rC Clang

https://reviews.llvm.org/D54753

Files:
  lib/Format/TokenAnnotator.cpp
  unittests/Format/FormatTestJS.cpp


Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -3113,8 +3113,21 @@
 // Don't wrap between ":" and "!" of a strict prop init ("field!: type;").
 if (Left.is(tok::exclaim) && Right.is(tok::colon))
   return false;
-if (Right.is(Keywords.kw_is))
-  return false;
+// Look for is type annotations like:
+// function f(): a is B { ... }
+// Do not break before is in these cases.
+if (Right.is(Keywords.kw_is)) {
+  const FormatToken* Next = Right.getNextNonComment();
+  // If `is` is followed by a colon, it's likely that it's a dict key, so
+  // ignore it for this check.
+  // For example this is common in Polymer:
+  // Polymer({
+  //   is: 'name',
+  //   ...
+  // });
+  if (!Next || !Next->is(tok::colon))
+return false;
+}
 if (Left.is(Keywords.kw_in))
   return Style.BreakBeforeBinaryOperators == FormatStyle::BOS_None;
 if (Right.is(Keywords.kw_in))
Index: unittests/Format/FormatTestJS.cpp
===
--- unittests/Format/FormatTestJS.cpp
+++ unittests/Format/FormatTestJS.cpp
@@ -1186,6 +1186,16 @@
getGoogleJSStyleWithColumns(25));
 }
 
+TEST_F(FormatTestJS, AddsIsTheDictKeyOnNewline) {
+  // Do not confuse is, the dict key with is, the type matcher. Put is, the 
dict
+  // key, on a newline.
+  verifyFormat("Polymer({\n"
+   "  is: '',  //\n"
+   "  rest: 1\n"
+   "});",
+   getGoogleJSStyleWithColumns(20));
+}
+
 TEST_F(FormatTestJS, AutomaticSemicolonInsertionHeuristic) {
   verifyFormat("a\n"
"b;",


Index: lib/Format/TokenAnnotator.cpp
===
--- lib/Format/TokenAnnotator.cpp
+++ lib/Format/TokenAnnotator.cpp
@@ -3113,8 +3113,21 @@
 // Don't wrap between ":" and "!" of a strict prop init ("field!: type;").
 if (Left.is(tok::exclaim) && Right.is(tok::colon))
   return false;
-if (Right.is(Keywords.kw_is))
-  return false;
+// Look for is type annotations like:
+// function f(): a is B { ... }
+// Do not break before is in these cases.
+if (Right.is(Keywords.kw_is)) {
+  const FormatToken* Next = Right.getNextNonComment();
+  // If `is` is followed by a colon, it's likely that it's a dict key, so
+  // ignore it for this check.
+  // For example this is common in Polymer:
+  // Polymer({
+  //   is: 'name',
+  //   ...
+  // });
+  if (!Next || !Next->is(tok::colon))
+return false;
+}
 if (Left.is(Keywords.kw_in))
   return Style.BreakBeforeBinaryOperators == FormatStyle::BOS_None;
 if (Right.is(Keywords.kw_in))
Index: unittests/Format/FormatTestJS.cpp
===
--- unittests/Format/FormatTestJS.cpp
+++ unittests/Format/FormatTestJS.cpp
@@ -1186,6 +1186,16 @@
getGoogleJSStyleWithColumns(25));
 }
 
+TEST_F(FormatTestJS, AddsIsTheDictKeyOnNewline) {
+  // Do not confuse is, the dict key with is, the type matcher. Put is, the dict
+  // key, on a newline.
+  verifyFormat("Polymer({\n"
+   "  is: '',  //\n"
+   "  rest: 1\n"
+   "});",
+   getGoogleJSStyleWithColumns(20));
+}
+
 TEST_F(FormatTestJS, AutomaticSemicolonInsertionHeuristic) {
   verifyFormat("a\n"
"b;",
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D54704: [clang-tidy] Don't generate incorrect fixes for class constructed from list-initialized arguments

2018-11-20 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

> Currently the smart_ptr check (modernize-make-unique) generates the fixes 
> that cannot compile for cases like below -- because brace list can not be 
> deduced in make_unique.
> 
>   class Bar { int a, b; };
>   class Foo { Foo(Bar); };
>   auto foo = std::unique_ptr(new Foo({1, 2}));

This code isn't legal in the first place. ;-)

Aside from some small nits, this LGTM.




Comment at: clang-tidy/modernize/MakeSmartPtrCheck.cpp:287
+  //   Foo(Bar{1, 2}) => true
+  //   Foo(1) => false
+  auto HasListIntializedArgument = [](const CXXConstructExpr *CE) {

I assume this is expected to be false? `Foo{1}`



Comment at: clang-tidy/modernize/MakeSmartPtrCheck.cpp:294
+  // std::initializer_list.
+  auto IsStdInitListInitConstructExpr = [](const Expr *E) {
+assert(E);

No need for this lambda (then again, it was in the original code).



Comment at: clang-tidy/modernize/MakeSmartPtrCheck.cpp:295
+  auto IsStdInitListInitConstructExpr = [](const Expr *E) {
+assert(E);
+if (const auto *ImplicitCE = dyn_cast(E)) {

No need to assert this; `dyn_cast<>` does it for you.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D54704



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


[PATCH] D52273: [clangd] Initial implementation of expected types

2018-11-20 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clangd/ExpectedTypes.h:32
+/// this allows the representation to be stored in the index and compared with
+/// types coming from a different AST later.
+class OpaqueType {

ilya-biryukov wrote:
> sammccall wrote:
> > Does this need to be a separate class rather than using `std::string`?
> > There are echoes of `SymbolID` here, but there were some factors that don't 
> > apply here:
> >  - it was fixed-width
> >  - memory layout was important as we stored lots of these in memory
> >  - we hashed them a lot and wanted a specific hash function
> > 
> > I suspect at least initially producing a somewhat readable std::string a la 
> > USRGeneration would be enough.
> Would still want to keep it as a marker type just for the sake of indicating 
> what we return and documentation purposes.
> It also adds some type safety (granted, not much) for some use-cases.
> 
> There's still an option to go strings with `rawStr()` if needed.
For documentation purposes, `using OpaqueType = std::string` or so seems like a 
reasonable compromise?

This is very heavyweight for the amount of typesafety we get.
(Apart from the class itself, you've got `==` and `!=`, we should definitely 
have `<<` as well, `DenseMapInfo<>` and `<` may get added down the line...)



Comment at: clangd/ExpectedTypes.h:15
+//
+// When using clang APIs, we cannot determine if a type coming from an AST is
+// convertible to another type without looking at both types in the same AST.

I think this largely rehashes the second sentence of the above para. I'd 
suggest this one focus more closely on what our model *is*:

  We define an encoding of AST types as opaque strings, which can be stored in 
the index.
  Similar types (such as `string` and `const string&`) are folded together, 
forming equivalence classes with the same encoding.



Comment at: clangd/ExpectedTypes.h:18
+// Unfortunately, we do not have ASTs for index-based completion, so we have 
use
+// a stable encoding for the C++ types and map them into equivalence classes
+// based on convertibility.

("stable" might suggest across versions)



Comment at: clangd/ExpectedTypes.h:42
+  /// completion context.
+  static llvm::Optional fromPreferredType(ASTContext &Ctx,
+  QualType Type);

I'd suggest just `fromType`, exposing this as the primary method, and then on 
`fromCompletionResult` document why it's different.

Having the names suggest the underlying structure (that `fromType` is "more 
fundamental")  aids understanding, and doesn't really feel like we're painting 
ourselves into a corner.

Alternately, `fromCompletionContext` and `fromCompletionResult` would be more 
clearly symmetrical.



Comment at: clangd/ExpectedTypes.h:49
+  /// rely on it.
+  llvm::StringRef rawStr() const { return Data; }
+

nit: if you keep this class, call this raw() for consistency with symbolid?(



Comment at: clangd/ExpectedTypes.h:59
+private:
+  static llvm::Optional encode(ASTContext &Ctx, QualType Type);
+  explicit OpaqueType(std::string Data);

any reason to put this in the header?



Comment at: unittests/clangd/ExpectedTypeTest.cpp:29
+
+class ASTTest : public ::testing::Test {
+protected:

This seems fine as a fixture, but I'd merge with the subclass - tests should be 
easy to read!



Comment at: unittests/clangd/ExpectedTypeTest.cpp:51
+
+class ConvertibleToMatcher
+: public ::testing::MatcherInterface {

"convertible to" is a problematic description for a couple of reasons:
 - it's a relationship between types, but encapsulates unrelated semantics to 
do with completions
 - it's a higher level of abstraction than the code under test

As discussed offline/below, I think the best remedy here is just to drop this 
matcher - it's only used in one test that can now live with something much 
simpler.



Comment at: unittests/clangd/ExpectedTypeTest.cpp:107
+  std::map
+  buildEquivClasses(llvm::ArrayRef Decls) {
+std::map Classes;

nit: any reason this takes Decl*s instead of strings? would be a bit terser not 
to wrap the args in decl()



Comment at: unittests/clangd/ExpectedTypeTest.cpp:110
+for (auto *D : Decls) {
+  auto Type = OpaqueType::fromCompletionResult(
+  ASTCtx(), CodeCompletionResult(D, CCP_Declaration));

I think we could simplify by only testing the type encodings/equiv classes 
here, and relying on the function -> return type conversion happening elsewhere.



Comment at: unittests/clangd/ExpectedTypeTest.cpp:142
+  decl("iptr"), decl("bptr"), decl("user_type")};
+  EXPECT_THAT(buildEquivClasses(Decls), Cla

[PATCH] D52695: [clang][Parse] Diagnose useless null statements (PR39111)

2018-11-20 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman accepted this revision.
aaron.ballman added a comment.
This revision is now accepted and ready to land.

Aside from some small nits, LGTM!




Comment at: docs/ReleaseNotes.rst:53
 
+- ``-Wextra-semi-stmt`` is a new diagnostic, which is, much like
+  ``-Wextra-semi``, diagnoses extra semicolons. This new diagnostic

aaron.ballman wrote:
> , which is, much like `-Wextra-semi`, diagnoses extra semicolons. -> that 
> diagnoses extra semicolons, much like `-Wextra-semi`.
diagnostic, that -> diagnostic that



Comment at: docs/ReleaseNotes.rst:93
+  of ``if``, ``switch``, ``range-based for``, unless: the semicolon directly
+  follows a macro that was expanded nothing or if the semicolon is within the
+  macro itself (both macros from system headers, and normal macros). This

expanded nothing -> expanded to nothing



Comment at: include/clang/Basic/DiagnosticParseKinds.td:57
+def warn_null_statement : Warning<
+  " empty expression statement has no effect; "
+  "remove unnecessary ';' to silence this warning">,

Spurious whitespace at the start of the diagnostic text.


Repository:
  rC Clang

https://reviews.llvm.org/D52695



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


[PATCH] D54450: Get the correct range of tokens for preprocessor conditions

2018-11-20 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added a comment.

Ping.


https://reviews.llvm.org/D54450



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


[PATCH] D54565: Introduce `-Wc++14-compat-ctad` as a subgroup of `-Wc++14-compat`

2018-11-20 Thread Arthur O'Dwyer via Phabricator via cfe-commits
Quuxplusone added a comment.

@lebedev.ri ping?


Repository:
  rC Clang

https://reviews.llvm.org/D54565



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


[PATCH] D47360: Implement as a copy of .

2018-11-20 Thread Arthur O'Dwyer via Phabricator via cfe-commits
Quuxplusone added a comment.
Herald added subscribers: libcxx-commits, jfb.

@ericwf ping? (and https://reviews.llvm.org/D47344 
https://reviews.llvm.org/D47111 https://reviews.llvm.org/D47358)


Repository:
  rCXX libc++

https://reviews.llvm.org/D47360



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


[PATCH] D52274: [clangd] Collect and store expected types in the index

2018-11-20 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clangd/index/Index.cpp:118
+static void own(Symbol &S, UniqueStringSaver &Strings,
+BumpPtrAllocator &Arena) {
   visitStrings(S, [&](StringRef &V) { V = Strings.save(V); });

why these changes?



Comment at: clangd/index/SymbolCollector.h:80
+/// Collect type information. Used to improve code completion ranking.
+bool CollectTypes = true;
   };

Why make this an option? Is it expensive in time/size?



Comment at: clangd/index/YAMLSerialization.cpp:182
 IO.mapOptional("IncludeHeaders", Sym.IncludeHeaders);
+IO.mapOptional("Type", Sym.Type);
   }

also need to update the binary serialization?


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D52274



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


r347312 - Update the documentation for attribute feature tests.

2018-11-20 Thread Aaron Ballman via cfe-commits
Author: aaronballman
Date: Tue Nov 20 07:23:07 2018
New Revision: 347312

URL: http://llvm.org/viewvc/llvm-project?rev=347312&view=rev
Log:
Update the documentation for attribute feature tests.

This clarifies that __has_cpp_attribute is no longer always an extension since 
it's now available in C++2a. Also, Both __has_cpp_attribute and 
__has_c_attribute can accept attribute scope tokens with alternative spelling 
(clang vs _Clang and gnu vs __gnu__).

Modified:
cfe/trunk/docs/LanguageExtensions.rst

Modified: cfe/trunk/docs/LanguageExtensions.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/LanguageExtensions.rst?rev=347312&r1=347311&r2=347312&view=diff
==
--- cfe/trunk/docs/LanguageExtensions.rst (original)
+++ cfe/trunk/docs/LanguageExtensions.rst Tue Nov 20 07:23:07 2018
@@ -112,18 +112,22 @@ of ``cxx_rvalue_references``.
 ``__has_cpp_attribute``
 ---
 
-This function-like macro takes a single argument that is the name of a
-C++11-style attribute. The argument can either be a single identifier, or a
-scoped identifier. If the attribute is supported, a nonzero value is returned.
-If the attribute is a standards-based attribute, this macro returns a nonzero
-value based on the year and month in which the attribute was voted into the
-working draft. If the attribute is not supported by the current compliation
-target, this macro evaluates to 0.  It can be used like this:
+This function-like macro is available in C++2a by default, and is provided as 
an
+extension in earlier language standards. It takes a single argument that is the
+name of a double-square-bracket-style attribute. The argument can either be a
+single identifier or a scoped identifier. If the attribute is supported, a
+nonzero value is returned. If the attribute is a standards-based attribute, 
this
+macro returns a nonzero value based on the year and month in which the 
attribute
+was voted into the working draft. See `WG21 SD-6
+`_
+for the list of values returned for standards-based attributes. If the 
attribute
+is not supported by the current compliation target, this macro evaluates to 0.
+It can be used like this:
 
 .. code-block:: c++
 
-  #ifndef __has_cpp_attribute // Optional of course.
-#define __has_cpp_attribute(x) 0  // Compatibility with non-clang 
compilers.
+  #ifndef __has_cpp_attribute // For backwards compatibility
+#define __has_cpp_attribute(x) 0
   #endif
 
   ...
@@ -134,10 +138,11 @@ target, this macro evaluates to 0.  It c
   #endif
   ...
 
-The attribute identifier (but not scope) can also be specified with a preceding
-and following ``__`` (double underscore) to avoid interference from a macro 
with
-the same name.  For instance, ``gnu::__const__`` can be used instead of
-``gnu::const``.
+The attribute scope tokens ``clang`` and ``_Clang`` are interchangeable, as are
+the attribute scope tokens ``gnu`` and ``__gnu__``. Attribute tokens in either
+of these namespaces can be specified with a preceding and following ``__``
+(double underscore) to avoid interference from a macro with the same name. For
+instance, ``gnu::__const__`` can be used instead of ``gnu::const``.
 
 ``__has_c_attribute``
 -
@@ -162,11 +167,11 @@ current compilation target, this macro e
   #endif
   ...
 
-The attribute identifier (but not scope) can also be specified with a preceding
-and following ``__`` (double underscore) to avoid interference from a macro 
with
-the same name.  For instance, ``gnu::__const__`` can be used instead of
-``gnu::const``.
-
+The attribute scope tokens ``clang`` and ``_Clang`` are interchangeable, as are
+the attribute scope tokens ``gnu`` and ``__gnu__``. Attribute tokens in either
+of these namespaces can be specified with a preceding and following ``__``
+(double underscore) to avoid interference from a macro with the same name. For
+instance, ``gnu::__const__`` can be used instead of ``gnu::const``.
 
 ``__has_attribute``
 ---


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


r347314 - Revert 347294, it turned many bots on lab.llvm.org:8011/console red.

2018-11-20 Thread Nico Weber via cfe-commits
Author: nico
Date: Tue Nov 20 07:27:43 2018
New Revision: 347314

URL: http://llvm.org/viewvc/llvm-project?rev=347314&view=rev
Log:
Revert 347294, it turned many bots on lab.llvm.org:8011/console red.

Modified:
cfe/trunk/include/clang/AST/Expr.h
cfe/trunk/lib/AST/ASTImporter.cpp
cfe/trunk/lib/AST/Expr.cpp
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/lib/CodeGen/CGBuiltin.cpp
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/lib/Sema/SemaOverload.cpp
cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp
cfe/trunk/lib/Sema/SemaType.cpp
cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
cfe/trunk/test/Analysis/builtin-functions.cpp
cfe/trunk/test/Sema/builtins.c
cfe/trunk/test/SemaCXX/compound-literal.cpp

Modified: cfe/trunk/include/clang/AST/Expr.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=347314&r1=347313&r2=347314&view=diff
==
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Tue Nov 20 07:27:43 2018
@@ -901,15 +901,10 @@ public:
 
 /// ConstantExpr - An expression that occurs in a constant context.
 class ConstantExpr : public FullExpr {
+public:
   ConstantExpr(Expr *subexpr)
 : FullExpr(ConstantExprClass, subexpr) {}
 
-public:
-  static ConstantExpr *Create(const ASTContext &Context, Expr *E) {
-assert(!isa(E));
-return new (Context) ConstantExpr(E);
-  }
-
   /// Build an empty constant expression wrapper.
   explicit ConstantExpr(EmptyShell Empty)
 : FullExpr(ConstantExprClass, Empty) {}
@@ -3096,8 +3091,8 @@ inline Expr *Expr::IgnoreImpCasts() {
   while (true)
 if (ImplicitCastExpr *ice = dyn_cast(e))
   e = ice->getSubExpr();
-else if (FullExpr *fe = dyn_cast(e))
-  e = fe->getSubExpr();
+else if (ConstantExpr *ce = dyn_cast(e))
+  e = ce->getSubExpr();
 else
   break;
   return e;

Modified: cfe/trunk/lib/AST/ASTImporter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTImporter.cpp?rev=347314&r1=347313&r2=347314&view=diff
==
--- cfe/trunk/lib/AST/ASTImporter.cpp (original)
+++ cfe/trunk/lib/AST/ASTImporter.cpp Tue Nov 20 07:27:43 2018
@@ -6380,7 +6380,7 @@ ExpectedStmt ASTNodeImporter::VisitConst
   Expr *ToSubExpr;
   std::tie(ToSubExpr) = *Imp;
 
-  return ConstantExpr::Create(Importer.getToContext(), ToSubExpr);
+  return new (Importer.getToContext()) ConstantExpr(ToSubExpr);
 }
 
 ExpectedStmt ASTNodeImporter::VisitParenExpr(ParenExpr *E) {

Modified: cfe/trunk/lib/AST/Expr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=347314&r1=347313&r2=347314&view=diff
==
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Tue Nov 20 07:27:43 2018
@@ -2594,8 +2594,8 @@ Expr *Expr::IgnoreParenCasts() {
   E = NTTP->getReplacement();
   continue;
 }
-if (FullExpr *FE = dyn_cast(E)) {
-  E = FE->getSubExpr();
+if (ConstantExpr *CE = dyn_cast(E)) {
+  E = CE->getSubExpr();
   continue;
 }
 return E;
@@ -2619,8 +2619,8 @@ Expr *Expr::IgnoreCasts() {
   E = NTTP->getReplacement();
   continue;
 }
-if (FullExpr *FE = dyn_cast(E)) {
-  E = FE->getSubExpr();
+if (ConstantExpr *CE = dyn_cast(E)) {
+  E = CE->getSubExpr();
   continue;
 }
 return E;
@@ -2648,8 +2648,8 @@ Expr *Expr::IgnoreParenLValueCasts() {
   = dyn_cast(E)) 
{
   E = NTTP->getReplacement();
   continue;
-} else if (FullExpr *FE = dyn_cast(E)) {
-  E = FE->getSubExpr();
+} else if (ConstantExpr *CE = dyn_cast(E)) {
+  E = CE->getSubExpr();
   continue;
 }
 break;
@@ -2920,12 +2920,6 @@ bool Expr::isConstantInitializer(ASTCont
 
 break;
   }
-  case ConstantExprClass: {
-// FIXME: We should be able to return "true" here, but it can lead to extra
-// error messages. E.g. in Sema/array-init.c.
-const Expr *Exp = cast(this)->getSubExpr();
-return Exp->isConstantInitializer(Ctx, false, Culprit);
-  }
   case CompoundLiteralExprClass: {
 // This handles gcc's extension that allows global initializers like
 // "struct x {int x;} x = (struct x) {};".

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=347314&r1=347313&r2=347314&view=diff
==
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Tue Nov 20 07:27:43 2018
@@ -45,7 +45,6 @@
 #include "clang/AST/TypeLoc.h"
 #include "clang/Basic/Builtins.h"
 #include "clang/Basic/TargetInfo.h"
-#include "llvm/Support/SaveAndRestore.h"
 #include "llvm/Support/raw_ostrea

Re: r347294 - Use is.constant intrinsic for __builtin_constant_p

2018-11-20 Thread Nico Weber via cfe-commits
I reverted this in r347314 for breaking many bots on
lab.llvm.org:8011/console

I've also put a standalone repro at
https://bugs.chromium.org/p/chromium/issues/detail?id=907099#c2.

On Tue, Nov 20, 2018 at 3:56 AM Bill Wendling via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: void
> Date: Tue Nov 20 00:53:30 2018
> New Revision: 347294
>
> URL: http://llvm.org/viewvc/llvm-project?rev=347294&view=rev
> Log:
> Use is.constant intrinsic for __builtin_constant_p
>
> Summary:
> A __builtin_constant_p may end up with a constant after inlining. Use
> the is.constant intrinsic if it's a variable that's in a context where
> it may resolve to a constant, e.g., an argument to a function after
> inlining.
>
> Reviewers: rsmith, shafik
>
> Subscribers: jfb, kristina, cfe-commits, nickdesaulniers, jyknight
>
> Differential Revision: https://reviews.llvm.org/D54355
>
> Modified:
> cfe/trunk/include/clang/AST/Expr.h
> cfe/trunk/lib/AST/ASTImporter.cpp
> cfe/trunk/lib/AST/Expr.cpp
> cfe/trunk/lib/AST/ExprConstant.cpp
> cfe/trunk/lib/CodeGen/CGBuiltin.cpp
> cfe/trunk/lib/Sema/SemaDeclCXX.cpp
> cfe/trunk/lib/Sema/SemaExpr.cpp
> cfe/trunk/lib/Sema/SemaOverload.cpp
> cfe/trunk/lib/Sema/SemaTemplateDeduction.cpp
> cfe/trunk/lib/Sema/SemaType.cpp
> cfe/trunk/lib/StaticAnalyzer/Core/ExprEngine.cpp
> cfe/trunk/test/Analysis/builtin-functions.cpp
> cfe/trunk/test/Sema/builtins.c
> cfe/trunk/test/SemaCXX/compound-literal.cpp
>
> Modified: cfe/trunk/include/clang/AST/Expr.h
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=347294&r1=347293&r2=347294&view=diff
>
> ==
> --- cfe/trunk/include/clang/AST/Expr.h (original)
> +++ cfe/trunk/include/clang/AST/Expr.h Tue Nov 20 00:53:30 2018
> @@ -901,10 +901,15 @@ public:
>
>  /// ConstantExpr - An expression that occurs in a constant context.
>  class ConstantExpr : public FullExpr {
> -public:
>ConstantExpr(Expr *subexpr)
>  : FullExpr(ConstantExprClass, subexpr) {}
>
> +public:
> +  static ConstantExpr *Create(const ASTContext &Context, Expr *E) {
> +assert(!isa(E));
> +return new (Context) ConstantExpr(E);
> +  }
> +
>/// Build an empty constant expression wrapper.
>explicit ConstantExpr(EmptyShell Empty)
>  : FullExpr(ConstantExprClass, Empty) {}
> @@ -3091,8 +3096,8 @@ inline Expr *Expr::IgnoreImpCasts() {
>while (true)
>  if (ImplicitCastExpr *ice = dyn_cast(e))
>e = ice->getSubExpr();
> -else if (ConstantExpr *ce = dyn_cast(e))
> -  e = ce->getSubExpr();
> +else if (FullExpr *fe = dyn_cast(e))
> +  e = fe->getSubExpr();
>  else
>break;
>return e;
>
> Modified: cfe/trunk/lib/AST/ASTImporter.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTImporter.cpp?rev=347294&r1=347293&r2=347294&view=diff
>
> ==
> --- cfe/trunk/lib/AST/ASTImporter.cpp (original)
> +++ cfe/trunk/lib/AST/ASTImporter.cpp Tue Nov 20 00:53:30 2018
> @@ -6375,7 +6375,7 @@ ExpectedStmt ASTNodeImporter::VisitConst
>Expr *ToSubExpr;
>std::tie(ToSubExpr) = *Imp;
>
> -  return new (Importer.getToContext()) ConstantExpr(ToSubExpr);
> +  return ConstantExpr::Create(Importer.getToContext(), ToSubExpr);
>  }
>
>  ExpectedStmt ASTNodeImporter::VisitParenExpr(ParenExpr *E) {
>
> Modified: cfe/trunk/lib/AST/Expr.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=347294&r1=347293&r2=347294&view=diff
>
> ==
> --- cfe/trunk/lib/AST/Expr.cpp (original)
> +++ cfe/trunk/lib/AST/Expr.cpp Tue Nov 20 00:53:30 2018
> @@ -2594,8 +2594,8 @@ Expr *Expr::IgnoreParenCasts() {
>E = NTTP->getReplacement();
>continue;
>  }
> -if (ConstantExpr *CE = dyn_cast(E)) {
> -  E = CE->getSubExpr();
> +if (FullExpr *FE = dyn_cast(E)) {
> +  E = FE->getSubExpr();
>continue;
>  }
>  return E;
> @@ -2619,8 +2619,8 @@ Expr *Expr::IgnoreCasts() {
>E = NTTP->getReplacement();
>continue;
>  }
> -if (ConstantExpr *CE = dyn_cast(E)) {
> -  E = CE->getSubExpr();
> +if (FullExpr *FE = dyn_cast(E)) {
> +  E = FE->getSubExpr();
>continue;
>  }
>  return E;
> @@ -2648,8 +2648,8 @@ Expr *Expr::IgnoreParenLValueCasts() {
>=
> dyn_cast(E)) {
>E = NTTP->getReplacement();
>continue;
> -} else if (ConstantExpr *CE = dyn_cast(E)) {
> -  E = CE->getSubExpr();
> +} else if (FullExpr *FE = dyn_cast(E)) {
> +  E = FE->getSubExpr();
>continue;
>  }
>  break;
> @@ -2920,6 +2920,12 @@ bool Expr::isConstantInitializer(ASTCont
>
>  break;
>}
> +  case ConstantExprClass: {
> +// FIXME: We should be able to return "true" here, but it can 

[PATCH] D52276: [clangd] Add type boosting in code completion

2018-11-20 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clangd/Quality.h:98
+  /// Whether the item matches the type expected in the completion context.
+  bool TypeMatchesPreferred = false;
   /// FIXME: unify with index proximity score - signals should be

you've inserted in the middle of the file proximity stuff :-)



Comment at: clangd/Quality.h:98
+  /// Whether the item matches the type expected in the completion context.
+  bool TypeMatchesPreferred = false;
   /// FIXME: unify with index proximity score - signals should be

sammccall wrote:
> you've inserted in the middle of the file proximity stuff :-)
Generally we'd put both context/symbol types as the signal here, rather than 
just whether they match, unless it's prohibitive. They'd get populated 
manually, and by merge() overloads, respectively.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D52276



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


[PATCH] D52276: [clangd] Add type boosting in code completion

2018-11-20 Thread Sam McCall via Phabricator via cfe-commits
sammccall added inline comments.



Comment at: clangd/Quality.cpp:373
+  if (TypeMatchesPreferred)
+Score *= 2.0;
+

is 2 really enough?


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D52276



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


[PATCH] D54704: [clang-tidy] Don't generate incorrect fixes for class constructed from list-initialized arguments

2018-11-20 Thread Haojian Wu via Phabricator via cfe-commits
hokein updated this revision to Diff 174771.
hokein marked 2 inline comments as done.
hokein added a comment.

address comments.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D54704

Files:
  clang-tidy/modernize/MakeSmartPtrCheck.cpp
  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
@@ -58,6 +58,10 @@
   I(G);
 };
 
+struct J {
+  J(E e, int);
+};
+
 namespace {
 class Foo {};
 } // namespace
@@ -372,6 +376,34 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use std::make_unique instead
   // CHECK-FIXES: PI1 = std::make_unique(G({1, 2, 3}));
 
+  std::unique_ptr PJ1 = std::unique_ptr(new J({1, 2}, 1));
+  // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: use std::make_unique instead
+  // CHECK-FIXES: std::unique_ptr PJ1 = std::unique_ptr(new J({1, 2}, 1));
+  PJ1.reset(new J({1, 2}, 1));
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use std::make_unique instead
+  // CHECK-FIXES: PJ1.reset(new J({1, 2}, 1));
+
+  std::unique_ptr PJ2 = std::unique_ptr(new J(E{1, 2}, 1));
+  // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: use std::make_unique instead
+  // CHECK-FIXES: std::unique_ptr PJ2 = std::make_unique(E{1, 2}, 1);
+  PJ2.reset(new J(E{1, 2}, 1));
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use std::make_unique instead
+  // CHECK-FIXES: PJ2 = std::make_unique(E{1, 2}, 1);
+
+  std::unique_ptr PJ3 = std::unique_ptr(new J{ {1, 2}, 1 });
+  // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: use std::make_unique instead
+  // CHECK-FIXES: std::unique_ptr PJ3 = std::unique_ptr(new J{ {1, 2}, 1 });
+  PJ3.reset(new J{ {1, 2}, 1 });
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use std::make_unique instead
+  // CHECK-FIXES:  PJ3.reset(new J{ {1, 2}, 1 });
+
+  std::unique_ptr PJ4 = std::unique_ptr(new J{E{1, 2}, 1});
+  // CHECK-MESSAGES: :[[@LINE-1]]:28: warning: use std::make_unique instead
+  // CHECK-FIXES: std::unique_ptr PJ4 = std::make_unique(E{1, 2}, 1);
+  PJ4.reset(new J{E{1, 2}, 1});
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use std::make_unique instead
+  // CHECK-FIXES:  PJ4 = std::make_unique(E{1, 2}, 1);
+
   std::unique_ptr FF = std::unique_ptr(new Foo());
   // CHECK-MESSAGES: :[[@LINE-1]]:29: warning:
   // CHECK-FIXES: std::unique_ptr FF = std::make_unique();
Index: clang-tidy/modernize/MakeSmartPtrCheck.cpp
===
--- clang-tidy/modernize/MakeSmartPtrCheck.cpp
+++ clang-tidy/modernize/MakeSmartPtrCheck.cpp
@@ -280,7 +280,27 @@
  SM, getLangOpts())
 .str();
   }
-
+  // Returns true if the given constructor expression has any braced-init-list
+  // argument, e.g.
+  //   Foo({1, 2}, 1) => true
+  //   Foo(Bar{1, 2}) => true
+  //   Foo(1) => false
+  //   Foo{1} => false
+  auto HasListIntializedArgument = [](const CXXConstructExpr *CE) {
+for (const auto *Arg : CE->arguments()) {
+  if (isa(Arg) || isa(Arg))
+return true;
+  // Check whether we implicitly construct a class from a
+  // std::initializer_list.
+  if (const auto *ImplicitCE =
+  dyn_cast(Arg->IgnoreImplicit())) {
+if (ImplicitCE->isStdInitListInitialization())
+  return true;
+  }
+  return false;
+}
+return false;
+  };
   switch (New->getInitializationStyle()) {
   case CXXNewExpr::NoInit: {
 if (ArraySizeExpr.empty()) {
@@ -300,32 +320,20 @@
 // std::make_smart_ptr, we need to specify the type explicitly in the fixes:
 //   struct S { S(std::initializer_list, int); };
 //   struct S2 { S2(std::vector); };
+//   struct S3 { S3(S2, int); };
 //   smart_ptr(new S({1, 2, 3}, 1));  // C++98 call-style initialization
 //   smart_ptr(new S({}, 1));
 //   smart_ptr(new S2({1})); // implicit conversion:
 //   //   std::initializer_list => std::vector
+//   smart_ptr(new S3({1, 2}, 3));
 // The above samples have to be replaced with:
 //   std::make_smart_ptr(std::initializer_list({1, 2, 3}), 1);
 //   std::make_smart_ptr(std::initializer_list({}), 1);
 //   std::make_smart_ptr(std::vector({1}));
+//   std::make_smart_ptr(S2{1, 2}, 3);
 if (const auto *CE = New->getConstructExpr()) {
-  for (const auto *Arg : CE->arguments()) {
-if (isa(Arg)) {
-  return false;
-}
-// Check whether we construct a class from a std::initializer_list.
-// If so, we won't generate the fixes.
-auto IsStdInitListInitConstructExpr = [](const Expr* E) {
-  assert(E);
-  if (const auto *ImplicitCE = dyn_cast(E)) {
-if (ImplicitCE->isStdInitListInitialization())
-  return true;
-  }
-  return false;
-};
-if (IsStdInitListInitConstruct

[PATCH] D54704: [clang-tidy] Don't generate incorrect fixes for class constructed from list-initialized arguments

2018-11-20 Thread Haojian Wu via Phabricator via cfe-commits
hokein added a comment.

In https://reviews.llvm.org/D54704#1304176, @aaron.ballman wrote:

> > Currently the smart_ptr check (modernize-make-unique) generates the fixes 
> > that cannot compile for cases like below -- because brace list can not be 
> > deduced in make_unique.
> > 
> >   class Bar { int a, b; };
> >   class Foo { Foo(Bar); };
> >   auto foo = std::unique_ptr(new Foo({1, 2}));
>
> This code isn't legal in the first place. ;-)


Thanks for the review. Fixed :)




Comment at: clang-tidy/modernize/MakeSmartPtrCheck.cpp:287
+  //   Foo(Bar{1, 2}) => true
+  //   Foo(1) => false
+  auto HasListIntializedArgument = [](const CXXConstructExpr *CE) {

aaron.ballman wrote:
> I assume this is expected to be false? `Foo{1}`
Yes, added this sample to the comment.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D54704



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


[clang-tools-extra] r347315 - [clang-tidy] Don't generate incorrect fixes for class constructed from list-initialized arguments

2018-11-20 Thread Haojian Wu via cfe-commits
Author: hokein
Date: Tue Nov 20 07:45:15 2018
New Revision: 347315

URL: http://llvm.org/viewvc/llvm-project?rev=347315&view=rev
Log:
[clang-tidy] Don't generate incorrect fixes for class constructed from 
list-initialized arguments

Summary:
Currently the smart_ptr check (modernize-make-unique) generates the
fixes that cannot compile for cases like below -- because brace list can
not be deduced in `make_unique`.

```
struct Bar { int a, b; };
struct Foo { Foo(Bar); };
auto foo = std::unique_ptr(new Foo({1, 2}));
```

Reviewers: aaron.ballman

Subscribers: xazax.hun, cfe-commits

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

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=347315&r1=347314&r2=347315&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.cpp Tue Nov 
20 07:45:15 2018
@@ -280,7 +280,27 @@ bool MakeSmartPtrCheck::replaceNew(Diagn
  SM, getLangOpts())
 .str();
   }
-
+  // Returns true if the given constructor expression has any braced-init-list
+  // argument, e.g.
+  //   Foo({1, 2}, 1) => true
+  //   Foo(Bar{1, 2}) => true
+  //   Foo(1) => false
+  //   Foo{1} => false
+  auto HasListIntializedArgument = [](const CXXConstructExpr *CE) {
+for (const auto *Arg : CE->arguments()) {
+  if (isa(Arg) || isa(Arg))
+return true;
+  // Check whether we implicitly construct a class from a
+  // std::initializer_list.
+  if (const auto *ImplicitCE =
+  dyn_cast(Arg->IgnoreImplicit())) {
+if (ImplicitCE->isStdInitListInitialization())
+  return true;
+  }
+  return false;
+}
+return false;
+  };
   switch (New->getInitializationStyle()) {
   case CXXNewExpr::NoInit: {
 if (ArraySizeExpr.empty()) {
@@ -300,32 +320,20 @@ bool MakeSmartPtrCheck::replaceNew(Diagn
 // std::make_smart_ptr, we need to specify the type explicitly in the 
fixes:
 //   struct S { S(std::initializer_list, int); };
 //   struct S2 { S2(std::vector); };
+//   struct S3 { S3(S2, int); };
 //   smart_ptr(new S({1, 2, 3}, 1));  // C++98 call-style initialization
 //   smart_ptr(new S({}, 1));
 //   smart_ptr(new S2({1})); // implicit conversion:
 //   //   std::initializer_list => std::vector
+//   smart_ptr(new S3({1, 2}, 3));
 // The above samples have to be replaced with:
 //   std::make_smart_ptr(std::initializer_list({1, 2, 3}), 1);
 //   std::make_smart_ptr(std::initializer_list({}), 1);
 //   std::make_smart_ptr(std::vector({1}));
+//   std::make_smart_ptr(S2{1, 2}, 3);
 if (const auto *CE = New->getConstructExpr()) {
-  for (const auto *Arg : CE->arguments()) {
-if (isa(Arg)) {
-  return false;
-}
-// Check whether we construct a class from a std::initializer_list.
-// If so, we won't generate the fixes.
-auto IsStdInitListInitConstructExpr = [](const Expr* E) {
-  assert(E);
-  if (const auto *ImplicitCE = dyn_cast(E)) {
-if (ImplicitCE->isStdInitListInitialization())
-  return true;
-  }
-  return false;
-};
-if (IsStdInitListInitConstructExpr(Arg->IgnoreImplicit()))
-  return false;
-  }
+  if (HasListIntializedArgument(CE))
+return false;
 }
 if (ArraySizeExpr.empty()) {
   SourceRange InitRange = New->getDirectInitRange();
@@ -346,16 +354,20 @@ bool MakeSmartPtrCheck::replaceNew(Diagn
 // Range of the substring that we do not want to remove.
 SourceRange InitRange;
 if (const auto *NewConstruct = New->getConstructExpr()) {
-  if (NewConstruct->isStdInitListInitialization()) {
+  if (NewConstruct->isStdInitListInitialization() ||
+  HasListIntializedArgument(NewConstruct)) {
 // FIXME: Add fixes for direct initialization with the initializer-list
 // constructor. Similar to the above CallInit case, the type has to be
 // specified explicitly in the fixes.
 //   struct S { S(std::initializer_list); };
+//   struct S2 { S2(S, int); };
 //   smart_ptr(new S{1, 2, 3});  // C++11 direct list-initialization
 //   smart_ptr(new S{});  // use initializer-list consturctor
+//   smart_ptr()new S2{ {1,2}, 3 }; // have a list-initialized arg
 // The above cases have to be replaced with:
 //   std::make_smart_ptr(std::initializer_list({1, 2, 3}));
 //   std::mak

[PATCH] D54704: [clang-tidy] Don't generate incorrect fixes for class constructed from list-initialized arguments

2018-11-20 Thread Haojian Wu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL347315: [clang-tidy] Don't generate incorrect fixes for 
class constructed from list… (authored by hokein, committed by ).
Herald added a subscriber: llvm-commits.

Repository:
  rL LLVM

https://reviews.llvm.org/D54704

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/clang-tidy/modernize/MakeSmartPtrCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/modernize/MakeSmartPtrCheck.cpp
@@ -280,7 +280,27 @@
  SM, getLangOpts())
 .str();
   }
-
+  // Returns true if the given constructor expression has any braced-init-list
+  // argument, e.g.
+  //   Foo({1, 2}, 1) => true
+  //   Foo(Bar{1, 2}) => true
+  //   Foo(1) => false
+  //   Foo{1} => false
+  auto HasListIntializedArgument = [](const CXXConstructExpr *CE) {
+for (const auto *Arg : CE->arguments()) {
+  if (isa(Arg) || isa(Arg))
+return true;
+  // Check whether we implicitly construct a class from a
+  // std::initializer_list.
+  if (const auto *ImplicitCE =
+  dyn_cast(Arg->IgnoreImplicit())) {
+if (ImplicitCE->isStdInitListInitialization())
+  return true;
+  }
+  return false;
+}
+return false;
+  };
   switch (New->getInitializationStyle()) {
   case CXXNewExpr::NoInit: {
 if (ArraySizeExpr.empty()) {
@@ -300,32 +320,20 @@
 // std::make_smart_ptr, we need to specify the type explicitly in the fixes:
 //   struct S { S(std::initializer_list, int); };
 //   struct S2 { S2(std::vector); };
+//   struct S3 { S3(S2, int); };
 //   smart_ptr(new S({1, 2, 3}, 1));  // C++98 call-style initialization
 //   smart_ptr(new S({}, 1));
 //   smart_ptr(new S2({1})); // implicit conversion:
 //   //   std::initializer_list => std::vector
+//   smart_ptr(new S3({1, 2}, 3));
 // The above samples have to be replaced with:
 //   std::make_smart_ptr(std::initializer_list({1, 2, 3}), 1);
 //   std::make_smart_ptr(std::initializer_list({}), 1);
 //   std::make_smart_ptr(std::vector({1}));
+//   std::make_smart_ptr(S2{1, 2}, 3);
 if (const auto *CE = New->getConstructExpr()) {
-  for (const auto *Arg : CE->arguments()) {
-if (isa(Arg)) {
-  return false;
-}
-// Check whether we construct a class from a std::initializer_list.
-// If so, we won't generate the fixes.
-auto IsStdInitListInitConstructExpr = [](const Expr* E) {
-  assert(E);
-  if (const auto *ImplicitCE = dyn_cast(E)) {
-if (ImplicitCE->isStdInitListInitialization())
-  return true;
-  }
-  return false;
-};
-if (IsStdInitListInitConstructExpr(Arg->IgnoreImplicit()))
-  return false;
-  }
+  if (HasListIntializedArgument(CE))
+return false;
 }
 if (ArraySizeExpr.empty()) {
   SourceRange InitRange = New->getDirectInitRange();
@@ -346,16 +354,20 @@
 // Range of the substring that we do not want to remove.
 SourceRange InitRange;
 if (const auto *NewConstruct = New->getConstructExpr()) {
-  if (NewConstruct->isStdInitListInitialization()) {
+  if (NewConstruct->isStdInitListInitialization() ||
+  HasListIntializedArgument(NewConstruct)) {
 // FIXME: Add fixes for direct initialization with the initializer-list
 // constructor. Similar to the above CallInit case, the type has to be
 // specified explicitly in the fixes.
 //   struct S { S(std::initializer_list); };
+//   struct S2 { S2(S, int); };
 //   smart_ptr(new S{1, 2, 3});  // C++11 direct list-initialization
 //   smart_ptr(new S{});  // use initializer-list consturctor
+//   smart_ptr()new S2{ {1,2}, 3 }; // have a list-initialized arg
 // The above cases have to be replaced with:
 //   std::make_smart_ptr(std::initializer_list({1, 2, 3}));
 //   std::make_smart_ptr(std::initializer_list({}));
+//   std::make_smart_ptr(S{1, 2}, 3);
 return false;
   } else {
 // Direct initialization with ordinary constructors.
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
@@ -58,6 +58,10 @@
   I(G);
 };
 
+struct J {
+  J(E e, int);
+};
+
 namespace {
 class Foo {};
 } // namespace
@@ -372,6 +376,34 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use std::make

[PATCH] D53157: Teach the IRBuilder about constrained fadd and friends

2018-11-20 Thread Kevin P. Neal via Phabricator via cfe-commits
kpn added a comment.

In https://reviews.llvm.org/D53157#1303398, @cameron.mcinally wrote:

> If we all agree upon that, then we simply have to treat the functions that 
> modify the FPEnv, e.g. fesetexcept(...), as barriers. That way it does not 
> matter if a FENV_ACCESS=OFF function is translated with constrained 
> intrinsics or not, since nothing can be scheduled around these barriers.


I thought we couldn't do barriers. No barriers means no way to prevent code 
motion and mixing of constrained with non-constrained FP. That was the reason 
for having all FP in a function be constrained if any of it was.


https://reviews.llvm.org/D53157



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


[PATCH] D54756: [DebugInfo] NFC Clang test changes for DISubprogram flags

2018-11-20 Thread Paul Robinson via Phabricator via cfe-commits
probinson created this revision.
probinson added reviewers: dblaikie, aprantl.
probinson added a project: debug-info.
Herald added a subscriber: eraman.

See https://reviews.llvm.org/D54755


Repository:
  rC Clang

https://reviews.llvm.org/D54756

Files:
  clang/test/CodeGen/debug-info-scope-file.c
  clang/test/CodeGenCXX/PR20038.cpp
  clang/test/CodeGenCXX/dbg-info-all-calls-described.cpp
  clang/test/CodeGenCXX/debug-info-access.cpp
  clang/test/CodeGenCXX/debug-info-blocks.cpp
  clang/test/CodeGenCXX/debug-info-cxx1y.cpp
  clang/test/CodeGenCXX/debug-info-decl-nested.cpp
  clang/test/CodeGenCXX/debug-info-function-context.cpp
  clang/test/CodeGenCXX/debug-info-global-ctor-dtor.cpp
  clang/test/CodeGenCXX/debug-info-inlined.cpp
  clang/test/CodeGenCXX/debug-info-ms-abi.cpp
  clang/test/CodeGenCXX/debug-info-namespace.cpp
  clang/test/CodeGenCXX/debug-info-static-fns.cpp
  clang/test/CodeGenCXX/debug-info-thunk-msabi.cpp
  clang/test/CodeGenCXX/debug-info-thunk.cpp
  clang/test/CodeGenCXX/debug-info.cpp
  clang/test/CodeGenCXX/debug-lambda-expressions.cpp
  clang/test/CodeGenCXX/globalinit-loc.cpp
  clang/test/CodeGenCXX/linetable-fnbegin.cpp
  clang/test/CodeGenObjC/arc-linetable.m
  clang/test/CodeGenObjC/debug-info-category.m
  clang/test/CodeGenObjC/debug-info-synthesis.m
  clang/test/CodeGenObjC/debug-property-synth.m
  clang/test/CodeGenObjC/debuginfo-properties.m

Index: clang/test/CodeGenObjC/debuginfo-properties.m
===
--- clang/test/CodeGenObjC/debuginfo-properties.m
+++ clang/test/CodeGenObjC/debuginfo-properties.m
@@ -13,16 +13,16 @@
 @property (nonatomic, retain) Selection* selection;
 // CHECK: !DISubprogram(name: "-[MyClass selection]"
 // CHECK-SAME:  line: [[@LINE-2]]
-// CHECK-SAME:  isLocal: true, isDefinition: true
+// CHECK-SAME:  DISPFlagLocalToUnit | DISPFlagDefinition
 // CHECK: !DISubprogram(name: "-[MyClass setSelection:]"
 // CHECK-SAME:  line: [[@LINE-5]]
-// CHECK-SAME:  isLocal: true, isDefinition: true
+// CHECK-SAME:  DISPFlagLocalToUnit | DISPFlagDefinition
 // CHECK: !DISubprogram(name: "-[OtherClass selection]"
 // CHECK-SAME:  line: [[@LINE-8]]
-// CHECK-SAME:  isLocal: true, isDefinition: true
+// CHECK-SAME:  DISPFlagLocalToUnit | DISPFlagDefinition
 // CHECK: !DISubprogram(name: "-[OtherClass setSelection:]"
 // CHECK-SAME:  line: [[@LINE-11]]
-// CHECK-SAME:  isLocal: true, isDefinition: true
+// CHECK-SAME:  DISPFlagLocalToUnit | DISPFlagDefinition
 
 @end
 
Index: clang/test/CodeGenObjC/debug-property-synth.m
===
--- clang/test/CodeGenObjC/debug-property-synth.m
+++ clang/test/CodeGenObjC/debug-property-synth.m
@@ -18,9 +18,9 @@
 // CHECK-NOT: ret
 // CHECK: load {{.*}}, !dbg ![[DBG2:[0-9]+]]
 //
-// CHECK: !DISubprogram(name: "-[I p1]",{{.*}} line: [[@LINE+4]],{{.*}} isLocal: true, isDefinition: true
+// CHECK: !DISubprogram(name: "-[I p1]",{{.*}} line: [[@LINE+4]],{{.*}} DISPFlagLocalToUnit | DISPFlagDefinition
 // CHECK: ![[DBG1]] = !DILocation(line: [[@LINE+3]],
-// CHECK: !DISubprogram(name: "-[I setP1:]",{{.*}} line: [[@LINE+2]],{{.*}} isLocal: true, isDefinition: true
+// CHECK: !DISubprogram(name: "-[I setP1:]",{{.*}} line: [[@LINE+2]],{{.*}} DISPFlagLocalToUnit | DISPFlagDefinition
 // CHECK: ![[DBG2]] = !DILocation(line: [[@LINE+1]],
 @property int p1;
 @end
Index: clang/test/CodeGenObjC/debug-info-synthesis.m
===
--- clang/test/CodeGenObjC/debug-info-synthesis.m
+++ clang/test/CodeGenObjC/debug-info-synthesis.m
@@ -34,4 +34,4 @@
 // CHECK: !DISubprogram(name: "-[Foo setDict:]"
 // CHECK-SAME:  file: ![[FILE]],
 // CHECK-SAME:  line: 8,
-// CHECK-SAME:  isLocal: true, isDefinition: true
+// CHECK-SAME:  DISPFlagLocalToUnit | DISPFlagDefinition
Index: clang/test/CodeGenObjC/debug-info-category.m
===
--- clang/test/CodeGenObjC/debug-info-category.m
+++ clang/test/CodeGenObjC/debug-info-category.m
@@ -36,17 +36,18 @@
 
 // CHECK: ![[STRUCT:.*]] = !DICompositeType(tag: DW_TAG_structure_type, name: "Foo"
 
-// DWARF5: !DISubprogram(name: "-[Foo integer]", scope: ![[STRUCT]], {{.*}}isDefinition: false
-// DWARF5: !DISubprogram(name: "-[Foo integer:]", scope: ![[STRUCT]], {{.*}}isDefinition: false
-// DWARF5: !DISubprogram(name: "+[Foo(Bar) zero:]", scope: ![[STRUCT]], {{.*}}isDefinition: false
-// DWARF5: !DISubprogram(name: "-[Foo(Bar) add:]", scope: ![[STRUCT]], {{.*}}isDefinition: false
-
-// DWARF4-NOT: !DISubprogram(name: "-[Foo integer]", scope: ![[STRUCT]], {{.*}}isDefinition: false
-// DWARF4-NOT: !DISubprogram(name: "-[Foo integer:]", scope: ![[STRUCT]], {{.*}}isDefinition: false
-// DWARF4-NOT: !DISubprogram(name: "+[Foo(Bar) zero:]", scope: ![[STRUCT]], {{.*}}isDefinition:

r347317 - [AST][NFC] Pack ArraySubscriptExpr

2018-11-20 Thread Bruno Ricci via cfe-commits
Author: brunoricci
Date: Tue Nov 20 08:03:33 2018
New Revision: 347317

URL: http://llvm.org/viewvc/llvm-project?rev=347317&view=rev
Log:
[AST][NFC] Pack ArraySubscriptExpr

Use the newly available space in the bit-fields of Stmt.
This saves one pointer per ArraySubscriptExpr.


Modified:
cfe/trunk/include/clang/AST/Expr.h
cfe/trunk/include/clang/AST/Stmt.h

Modified: cfe/trunk/include/clang/AST/Expr.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=347317&r1=347316&r2=347317&view=diff
==
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Tue Nov 20 08:03:33 2018
@@ -2315,9 +2315,9 @@ public:
 
 /// ArraySubscriptExpr - [C99 6.5.2.1] Array Subscripting.
 class ArraySubscriptExpr : public Expr {
-  enum { LHS, RHS, END_EXPR=2 };
-  Stmt* SubExprs[END_EXPR];
-  SourceLocation RBracketLoc;
+  enum { LHS, RHS, END_EXPR };
+  Stmt *SubExprs[END_EXPR];
+
 public:
   ArraySubscriptExpr(Expr *lhs, Expr *rhs, QualType t,
  ExprValueKind VK, ExprObjectKind OK,
@@ -2328,10 +2328,10 @@ public:
  (lhs->isInstantiationDependent() ||
   rhs->isInstantiationDependent()),
  (lhs->containsUnexpandedParameterPack() ||
-  rhs->containsUnexpandedParameterPack())),
-RBracketLoc(rbracketloc) {
+  rhs->containsUnexpandedParameterPack())) {
 SubExprs[LHS] = lhs;
 SubExprs[RHS] = rhs;
+ArraySubscriptExprBits.RBracketLoc = rbracketloc;
   }
 
   /// Create an empty array subscript expression.
@@ -2374,10 +2374,14 @@ public:
   SourceLocation getBeginLoc() const LLVM_READONLY {
 return getLHS()->getBeginLoc();
   }
-  SourceLocation getEndLoc() const LLVM_READONLY { return RBracketLoc; }
+  SourceLocation getEndLoc() const { return getRBracketLoc(); }
 
-  SourceLocation getRBracketLoc() const { return RBracketLoc; }
-  void setRBracketLoc(SourceLocation L) { RBracketLoc = L; }
+  SourceLocation getRBracketLoc() const {
+return ArraySubscriptExprBits.RBracketLoc;
+  }
+  void setRBracketLoc(SourceLocation L) {
+ArraySubscriptExprBits.RBracketLoc = L;
+  }
 
   SourceLocation getExprLoc() const LLVM_READONLY {
 return getBase()->getExprLoc();

Modified: cfe/trunk/include/clang/AST/Stmt.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Stmt.h?rev=347317&r1=347316&r2=347317&view=diff
==
--- cfe/trunk/include/clang/AST/Stmt.h (original)
+++ cfe/trunk/include/clang/AST/Stmt.h Tue Nov 20 08:03:33 2018
@@ -416,6 +416,14 @@ protected:
 unsigned IsType : 1; // true if operand is a type, false if an expression.
   };
 
+  class ArraySubscriptExprBitfields {
+friend class ArraySubscriptExpr;
+
+unsigned : NumExprBits;
+
+SourceLocation RBracketLoc;
+  };
+
   class CallExprBitfields {
 friend class CallExpr;
 
@@ -658,6 +666,7 @@ protected:
 CharacterLiteralBitfields CharacterLiteralBits;
 UnaryOperatorBitfields UnaryOperatorBits;
 UnaryExprOrTypeTraitExprBitfields UnaryExprOrTypeTraitExprBits;
+ArraySubscriptExprBitfields ArraySubscriptExprBits;
 CallExprBitfields CallExprBits;
 MemberExprBitfields MemberExprBits;
 CastExprBitfields CastExprBits;


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


r347319 - [AST][NFC] Factor out some repeated code in ArraySubscriptExpr.

2018-11-20 Thread Bruno Ricci via cfe-commits
Author: brunoricci
Date: Tue Nov 20 08:09:45 2018
New Revision: 347319

URL: http://llvm.org/viewvc/llvm-project?rev=347319&view=rev
Log:
[AST][NFC] Factor out some repeated code in ArraySubscriptExpr.

Factor out the test for whether the LHS is the base of the
array subscript expression into a private method lhsIsBase.

NFC.


Modified:
cfe/trunk/include/clang/AST/Expr.h

Modified: cfe/trunk/include/clang/AST/Expr.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=347319&r1=347318&r2=347319&view=diff
==
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Tue Nov 20 08:09:45 2018
@@ -2318,6 +2318,8 @@ class ArraySubscriptExpr : public Expr {
   enum { LHS, RHS, END_EXPR };
   Stmt *SubExprs[END_EXPR];
 
+  bool lhsIsBase() const { return getRHS()->getType()->isIntegerType(); }
+
 public:
   ArraySubscriptExpr(Expr *lhs, Expr *rhs, QualType t,
  ExprValueKind VK, ExprObjectKind OK,
@@ -2355,21 +2357,11 @@ public:
   const Expr *getRHS() const { return cast(SubExprs[RHS]); }
   void setRHS(Expr *E) { SubExprs[RHS] = E; }
 
-  Expr *getBase() {
-return getRHS()->getType()->isIntegerType() ? getLHS() : getRHS();
-  }
-
-  const Expr *getBase() const {
-return getRHS()->getType()->isIntegerType() ? getLHS() : getRHS();
-  }
+  Expr *getBase() { return lhsIsBase() ? getLHS() : getRHS(); }
+  const Expr *getBase() const { return lhsIsBase() ? getLHS() : getRHS(); }
 
-  Expr *getIdx() {
-return getRHS()->getType()->isIntegerType() ? getRHS() : getLHS();
-  }
-
-  const Expr *getIdx() const {
-return getRHS()->getType()->isIntegerType() ? getRHS() : getLHS();
-  }
+  Expr *getIdx() { return lhsIsBase() ? getRHS() : getLHS(); }
+  const Expr *getIdx() const { return lhsIsBase() ? getRHS() : getLHS(); }
 
   SourceLocation getBeginLoc() const LLVM_READONLY {
 return getLHS()->getBeginLoc();


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


[PATCH] D54757: [clang-tidy] new check: bugprone-branch-clone

2018-11-20 Thread Donát Nagy via Phabricator via cfe-commits
donat.nagy created this revision.
donat.nagy added reviewers: alexfh, hokein, aaron.ballman, xazax.hun, 
whisperity.
Herald added subscribers: cfe-commits, gamesh411, Szelethus, dkrupp, rnkovacs, 
mgorny.

Implement a check for detecting if/else if/else chains where two or more
branches are Type I clones of each other (that is, they contain identical code)
and for detecting switch statements where two or more consecutive branches are
Type I clones of each other.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D54757

Files:
  clang-tidy/bugprone/BranchCloneCheck.cpp
  clang-tidy/bugprone/BranchCloneCheck.h
  clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tidy/bugprone/CMakeLists.txt
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/bugprone-branch-clone.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/bugprone-branch-clone.cpp

Index: test/clang-tidy/bugprone-branch-clone.cpp
===
--- /dev/null
+++ test/clang-tidy/bugprone-branch-clone.cpp
@@ -0,0 +1,751 @@
+// RUN: %check_clang_tidy %s bugprone-branch-clone %t
+
+void test_basic1(int in, int &out) {
+  if (in > 77)
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: if with identical then and else branches [bugprone-branch-clone]
+out++;
+  else
+// CHECK-MESSAGES: :[[@LINE-1]]:3: note: else branch starts here
+out++;
+
+  out++;
+}
+
+void test_basic2(int in, int &out) {
+  if (in > 77) {
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: if with identical then and else branches [bugprone-branch-clone]
+out++;
+  }
+  else {
+// CHECK-MESSAGES: :[[@LINE-1]]:3: note: else branch starts here
+out++;
+  }
+
+  out++;
+}
+
+void test_basic3(int in, int &out) {
+  if (in > 77) {
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: if with identical then and else branches [bugprone-branch-clone]
+out++;
+  }
+  else
+// CHECK-MESSAGES: :[[@LINE-1]]:3: note: else branch starts here
+out++;
+
+  out++;
+}
+
+void test_basic4(int in, int &out) {
+  if (in > 77) {
+out--;
+  }
+  else {
+out++;
+  }
+}
+
+void test_basic5(int in, int &out) {
+  if (in > 77) {
+out++;
+  }
+  else {
+out++;
+out++;
+  }
+}
+
+void test_basic6(int in, int &out) {
+  if (in > 77) {
+out++;
+  }
+  else {
+out++, out++;
+  }
+}
+
+void test_basic7(int in, int &out) {
+  if (in > 77) {
+out++;
+out++;
+  }
+  else
+out++;
+
+  out++;
+}
+
+void test_basic8(int in, int &out) {
+  if (in > 77) {
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: if with identical then and else branches [bugprone-branch-clone]
+out++;
+out++;
+  } else {
+// CHECK-MESSAGES: :[[@LINE-1]]:5: note: else branch starts here
+out++;
+out++;
+  }
+
+  if (in % 2)
+out++;
+}
+
+void test_basic9(int in, int &out) {
+  if (in > 77) {
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: if with identical then and else branches [bugprone-branch-clone]
+if (in % 2)
+  out++;
+else
+  out--;
+  } else {
+// CHECK-MESSAGES: :[[@LINE-1]]:5: note: else branch starts here
+if (in % 2)
+  out++;
+else
+  out--;
+  }
+}
+
+// If we remove the braces from the previous example, the check recognizes it
+// as an `else if`.
+void test_basic10(int in, int &out) {
+  if (in > 77)
+if (in % 2)
+  out++;
+else
+  out--;
+  else
+if (in % 2)
+  out++;
+else
+  out--;
+
+}
+
+void test_basic11(int in, int &out) {
+  if (in > 77) {
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: if with identical then and else branches [bugprone-branch-clone]
+if (in % 2)
+  out++;
+else
+  out--;
+if (in % 3)
+  out++;
+else
+  out--;
+  } else {
+// CHECK-MESSAGES: :[[@LINE-1]]:5: note: else branch starts here
+if (in % 2)
+  out++;
+else
+  out--;
+if (in % 3)
+  out++;
+else
+  out--;
+  }
+}
+
+void test_basic12(int in, int &out) {
+  if (in > 77) {
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: if with identical then and else branches [bugprone-branch-clone]
+  } else {
+// CHECK-MESSAGES: :[[@LINE-1]]:5: note: else branch starts here
+  }
+}
+
+void test_basic13(int in, int &out) {
+  if (in > 77) {
+// Empty compound statement is not identical to null statement.
+  } else;
+}
+
+
+void test_chain1(int in, int &out) {
+  if (in > 77)
+// CHECK-MESSAGES: :[[@LINE+1]]:5: warning: repeated branch in conditional chain [bugprone-branch-clone]
+out++;
+// CHECK-MESSAGES: :[[@LINE-1]]:10: note: end of the original
+  else if (in > 55)
+// CHECK-MESSAGES: :[[@LINE+1]]:5: note: clone 1 starts here
+out++;
+
+  out++;
+}
+
+void test_chain2(int in, int &out) {
+  if (in > 77)
+// CHECK-MESSAGES: :[[@LINE+1]]:5: warning: repeated branch in conditional chain [bugprone-branch-clone]
+out++;
+// CHECK-MESSAGES: :[[@LINE-1]]:10: note: end of the original
+  else if (in > 55)
+// CHECK-MESSAGES: :[[@LINE+1]]:5: note: clone 1 starts here
+out++;
+  else if (in > 42)
+out--;
+  else

r347320 - [AST] Store the expressions in ParenListExpr in a trailing array

2018-11-20 Thread Bruno Ricci via cfe-commits
Author: brunoricci
Date: Tue Nov 20 08:20:40 2018
New Revision: 347320

URL: http://llvm.org/viewvc/llvm-project?rev=347320&view=rev
Log:
[AST] Store the expressions in ParenListExpr in a trailing array

Use the newly available space in the bit-fields of Stmt
and store the expressions in a trailing array. This saves
2 pointer per ParenListExpr.

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

Reviewed By: rjmccall


Modified:
cfe/trunk/include/clang/AST/Expr.h
cfe/trunk/include/clang/AST/Stmt.h
cfe/trunk/lib/AST/ASTImporter.cpp
cfe/trunk/lib/AST/Expr.cpp
cfe/trunk/lib/Sema/SemaCoroutine.cpp
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/lib/Serialization/ASTReaderStmt.cpp
cfe/trunk/lib/Serialization/ASTWriterStmt.cpp

Modified: cfe/trunk/include/clang/AST/Expr.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=347320&r1=347319&r2=347320&view=diff
==
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Tue Nov 20 08:20:40 2018
@@ -4844,31 +4844,46 @@ public:
   }
 };
 
-class ParenListExpr : public Expr {
-  Stmt **Exprs;
-  unsigned NumExprs;
+class ParenListExpr final
+: public Expr,
+  private llvm::TrailingObjects {
+  friend class ASTStmtReader;
+  friend TrailingObjects;
+
+  /// The location of the left and right parentheses.
   SourceLocation LParenLoc, RParenLoc;
 
-public:
-  ParenListExpr(const ASTContext& C, SourceLocation lparenloc,
-ArrayRef exprs, SourceLocation rparenloc);
+  /// Build a paren list.
+  ParenListExpr(SourceLocation LParenLoc, ArrayRef Exprs,
+SourceLocation RParenLoc);
 
   /// Build an empty paren list.
-  explicit ParenListExpr(EmptyShell Empty) : Expr(ParenListExprClass, Empty) { 
}
+  ParenListExpr(EmptyShell Empty, unsigned NumExprs);
+
+public:
+  /// Create a paren list.
+  static ParenListExpr *Create(const ASTContext &Ctx, SourceLocation LParenLoc,
+   ArrayRef Exprs,
+   SourceLocation RParenLoc);
+
+  /// Create an empty paren list.
+  static ParenListExpr *CreateEmpty(const ASTContext &Ctx, unsigned NumExprs);
 
-  unsigned getNumExprs() const { return NumExprs; }
+  /// Return the number of expressions in this paren list.
+  unsigned getNumExprs() const { return ParenListExprBits.NumExprs; }
 
-  const Expr* getExpr(unsigned Init) const {
+  Expr *getExpr(unsigned Init) {
 assert(Init < getNumExprs() && "Initializer access out of range!");
-return cast_or_null(Exprs[Init]);
+return getExprs()[Init];
   }
 
-  Expr* getExpr(unsigned Init) {
-assert(Init < getNumExprs() && "Initializer access out of range!");
-return cast_or_null(Exprs[Init]);
+  const Expr *getExpr(unsigned Init) const {
+return const_cast(this)->getExpr(Init);
   }
 
-  Expr **getExprs() { return reinterpret_cast(Exprs); }
+  Expr **getExprs() {
+return reinterpret_cast(getTrailingObjects());
+  }
 
   ArrayRef exprs() {
 return llvm::makeArrayRef(getExprs(), getNumExprs());
@@ -4876,9 +4891,8 @@ public:
 
   SourceLocation getLParenLoc() const { return LParenLoc; }
   SourceLocation getRParenLoc() const { return RParenLoc; }
-
-  SourceLocation getBeginLoc() const LLVM_READONLY { return LParenLoc; }
-  SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
+  SourceLocation getBeginLoc() const { return getLParenLoc(); }
+  SourceLocation getEndLoc() const { return getRParenLoc(); }
 
   static bool classof(const Stmt *T) {
 return T->getStmtClass() == ParenListExprClass;
@@ -4886,14 +4900,13 @@ public:
 
   // Iterators
   child_range children() {
-return child_range(&Exprs[0], &Exprs[0]+NumExprs);
+return child_range(getTrailingObjects(),
+   getTrailingObjects() + getNumExprs());
   }
   const_child_range children() const {
-return const_child_range(&Exprs[0], &Exprs[0] + NumExprs);
+return const_child_range(getTrailingObjects(),
+ getTrailingObjects() + getNumExprs());
   }
-
-  friend class ASTStmtReader;
-  friend class ASTStmtWriter;
 };
 
 /// Represents a C11 generic selection.

Modified: cfe/trunk/include/clang/AST/Stmt.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Stmt.h?rev=347320&r1=347319&r2=347320&view=diff
==
--- cfe/trunk/include/clang/AST/Stmt.h (original)
+++ cfe/trunk/include/clang/AST/Stmt.h Tue Nov 20 08:20:40 2018
@@ -496,6 +496,16 @@ protected:
 unsigned HadArrayRangeDesignator : 1;
   };
 
+  class ParenListExprBitfields {
+friend class ASTStmtReader;
+friend class ParenListExpr;
+
+unsigned : NumExprBits;
+
+/// The number of expressions in the paren list.
+unsigned NumExprs;
+  };
+
   class PseudoObjectExprBitfields {
 fr

[PATCH] D54675: [AST] Store the expressions in ParenListExpr in a trailing array

2018-11-20 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL347320: [AST] Store the expressions in ParenListExpr in a 
trailing array (authored by brunoricci, committed by ).
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D54675?vs=174537&id=174781#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D54675

Files:
  cfe/trunk/include/clang/AST/Expr.h
  cfe/trunk/include/clang/AST/Stmt.h
  cfe/trunk/lib/AST/ASTImporter.cpp
  cfe/trunk/lib/AST/Expr.cpp
  cfe/trunk/lib/Sema/SemaCoroutine.cpp
  cfe/trunk/lib/Sema/SemaDeclCXX.cpp
  cfe/trunk/lib/Sema/SemaExpr.cpp
  cfe/trunk/lib/Serialization/ASTReaderStmt.cpp
  cfe/trunk/lib/Serialization/ASTWriterStmt.cpp

Index: cfe/trunk/lib/AST/Expr.cpp
===
--- cfe/trunk/lib/AST/Expr.cpp
+++ cfe/trunk/lib/AST/Expr.cpp
@@ -4004,27 +4004,48 @@
   return getBase()->getEndLoc();
 }
 
-ParenListExpr::ParenListExpr(const ASTContext& C, SourceLocation lparenloc,
- ArrayRef exprs,
- SourceLocation rparenloc)
-  : Expr(ParenListExprClass, QualType(), VK_RValue, OK_Ordinary,
- false, false, false, false),
-NumExprs(exprs.size()), LParenLoc(lparenloc), RParenLoc(rparenloc) {
-  Exprs = new (C) Stmt*[exprs.size()];
-  for (unsigned i = 0; i != exprs.size(); ++i) {
-if (exprs[i]->isTypeDependent())
+ParenListExpr::ParenListExpr(SourceLocation LParenLoc, ArrayRef Exprs,
+ SourceLocation RParenLoc)
+: Expr(ParenListExprClass, QualType(), VK_RValue, OK_Ordinary, false, false,
+   false, false),
+  LParenLoc(LParenLoc), RParenLoc(RParenLoc) {
+  ParenListExprBits.NumExprs = Exprs.size();
+
+  for (unsigned I = 0, N = Exprs.size(); I != N; ++I) {
+if (Exprs[I]->isTypeDependent())
   ExprBits.TypeDependent = true;
-if (exprs[i]->isValueDependent())
+if (Exprs[I]->isValueDependent())
   ExprBits.ValueDependent = true;
-if (exprs[i]->isInstantiationDependent())
+if (Exprs[I]->isInstantiationDependent())
   ExprBits.InstantiationDependent = true;
-if (exprs[i]->containsUnexpandedParameterPack())
+if (Exprs[I]->containsUnexpandedParameterPack())
   ExprBits.ContainsUnexpandedParameterPack = true;
 
-Exprs[i] = exprs[i];
+getTrailingObjects()[I] = Exprs[I];
   }
 }
 
+ParenListExpr::ParenListExpr(EmptyShell Empty, unsigned NumExprs)
+: Expr(ParenListExprClass, Empty) {
+  ParenListExprBits.NumExprs = NumExprs;
+}
+
+ParenListExpr *ParenListExpr::Create(const ASTContext &Ctx,
+ SourceLocation LParenLoc,
+ ArrayRef Exprs,
+ SourceLocation RParenLoc) {
+  void *Mem = Ctx.Allocate(totalSizeToAlloc(Exprs.size()),
+   alignof(ParenListExpr));
+  return new (Mem) ParenListExpr(LParenLoc, Exprs, RParenLoc);
+}
+
+ParenListExpr *ParenListExpr::CreateEmpty(const ASTContext &Ctx,
+  unsigned NumExprs) {
+  void *Mem =
+  Ctx.Allocate(totalSizeToAlloc(NumExprs), alignof(ParenListExpr));
+  return new (Mem) ParenListExpr(EmptyShell(), NumExprs);
+}
+
 const OpaqueValueExpr *OpaqueValueExpr::findInCopyConstruct(const Expr *e) {
   if (const ExprWithCleanups *ewc = dyn_cast(e))
 e = ewc->getSubExpr();
Index: cfe/trunk/lib/AST/ASTImporter.cpp
===
--- cfe/trunk/lib/AST/ASTImporter.cpp
+++ cfe/trunk/lib/AST/ASTImporter.cpp
@@ -6409,8 +6409,8 @@
   if (!ToRParenLocOrErr)
 return ToRParenLocOrErr.takeError();
 
-  return new (Importer.getToContext()) ParenListExpr(
-  Importer.getToContext(), *ToLParenLocOrErr, ToExprs, *ToRParenLocOrErr);
+  return ParenListExpr::Create(Importer.getToContext(), *ToLParenLocOrErr,
+   ToExprs, *ToRParenLocOrErr);
 }
 
 ExpectedStmt ASTNodeImporter::VisitStmtExpr(StmtExpr *E) {
Index: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
===
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp
@@ -3731,8 +3731,7 @@
   ArrayRef Args,
   SourceLocation RParenLoc,
   SourceLocation EllipsisLoc) {
-  Expr *List = new (Context) ParenListExpr(Context, LParenLoc,
-   Args, RParenLoc);
+  Expr *List = ParenListExpr::Create(Context, LParenLoc, Args, RParenLoc);
   return BuildMemInitializer(ConstructorD, S, SS, MemberOrBase, TemplateTypeTy,
  DS, IdLoc, List, EllipsisLoc);
 }
Index: cfe/trunk/lib/Sema/SemaCoroutine.cpp
===
--- cfe/trunk/lib/Sema/SemaCoroutine.cpp
+++ cfe/trunk/lib/Sema/SemaCoroutine.cpp
@@ -565,8 +565,8 @@
 
   // Create 

[PATCH] D54675: [AST] Store the expressions in ParenListExpr in a trailing array

2018-11-20 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC347320: [AST] Store the expressions in ParenListExpr in a 
trailing array (authored by brunoricci, committed by ).

Repository:
  rC Clang

https://reviews.llvm.org/D54675

Files:
  include/clang/AST/Expr.h
  include/clang/AST/Stmt.h
  lib/AST/ASTImporter.cpp
  lib/AST/Expr.cpp
  lib/Sema/SemaCoroutine.cpp
  lib/Sema/SemaDeclCXX.cpp
  lib/Sema/SemaExpr.cpp
  lib/Serialization/ASTReaderStmt.cpp
  lib/Serialization/ASTWriterStmt.cpp

Index: lib/Serialization/ASTReaderStmt.cpp
===
--- lib/Serialization/ASTReaderStmt.cpp
+++ lib/Serialization/ASTReaderStmt.cpp
@@ -643,10 +643,9 @@
 void ASTStmtReader::VisitParenListExpr(ParenListExpr *E) {
   VisitExpr(E);
   unsigned NumExprs = Record.readInt();
-  E->Exprs = new (Record.getContext()) Stmt*[NumExprs];
-  for (unsigned i = 0; i != NumExprs; ++i)
-E->Exprs[i] = Record.readSubStmt();
-  E->NumExprs = NumExprs;
+  assert((NumExprs == E->getNumExprs()) && "Wrong NumExprs!");
+  for (unsigned I = 0; I != NumExprs; ++I)
+E->getTrailingObjects()[I] = Record.readSubStmt();
   E->LParenLoc = ReadSourceLocation();
   E->RParenLoc = ReadSourceLocation();
 }
@@ -2452,7 +2451,9 @@
   break;
 
 case EXPR_PAREN_LIST:
-  S = new (Context) ParenListExpr(Empty);
+  S = ParenListExpr::CreateEmpty(
+  Context,
+  /* NumExprs=*/Record[ASTStmtReader::NumExprFields + 0]);
   break;
 
 case EXPR_UNARY_OPERATOR:
Index: lib/Serialization/ASTWriterStmt.cpp
===
--- lib/Serialization/ASTWriterStmt.cpp
+++ lib/Serialization/ASTWriterStmt.cpp
@@ -559,11 +559,11 @@
 
 void ASTStmtWriter::VisitParenListExpr(ParenListExpr *E) {
   VisitExpr(E);
-  Record.push_back(E->NumExprs);
-  for (unsigned i=0; i != E->NumExprs; ++i)
-Record.AddStmt(E->Exprs[i]);
-  Record.AddSourceLocation(E->LParenLoc);
-  Record.AddSourceLocation(E->RParenLoc);
+  Record.push_back(E->getNumExprs());
+  for (auto *SubStmt : E->exprs())
+Record.AddStmt(SubStmt);
+  Record.AddSourceLocation(E->getLParenLoc());
+  Record.AddSourceLocation(E->getRParenLoc());
   Code = serialization::EXPR_PAREN_LIST;
 }
 
Index: lib/AST/Expr.cpp
===
--- lib/AST/Expr.cpp
+++ lib/AST/Expr.cpp
@@ -4004,27 +4004,48 @@
   return getBase()->getEndLoc();
 }
 
-ParenListExpr::ParenListExpr(const ASTContext& C, SourceLocation lparenloc,
- ArrayRef exprs,
- SourceLocation rparenloc)
-  : Expr(ParenListExprClass, QualType(), VK_RValue, OK_Ordinary,
- false, false, false, false),
-NumExprs(exprs.size()), LParenLoc(lparenloc), RParenLoc(rparenloc) {
-  Exprs = new (C) Stmt*[exprs.size()];
-  for (unsigned i = 0; i != exprs.size(); ++i) {
-if (exprs[i]->isTypeDependent())
+ParenListExpr::ParenListExpr(SourceLocation LParenLoc, ArrayRef Exprs,
+ SourceLocation RParenLoc)
+: Expr(ParenListExprClass, QualType(), VK_RValue, OK_Ordinary, false, false,
+   false, false),
+  LParenLoc(LParenLoc), RParenLoc(RParenLoc) {
+  ParenListExprBits.NumExprs = Exprs.size();
+
+  for (unsigned I = 0, N = Exprs.size(); I != N; ++I) {
+if (Exprs[I]->isTypeDependent())
   ExprBits.TypeDependent = true;
-if (exprs[i]->isValueDependent())
+if (Exprs[I]->isValueDependent())
   ExprBits.ValueDependent = true;
-if (exprs[i]->isInstantiationDependent())
+if (Exprs[I]->isInstantiationDependent())
   ExprBits.InstantiationDependent = true;
-if (exprs[i]->containsUnexpandedParameterPack())
+if (Exprs[I]->containsUnexpandedParameterPack())
   ExprBits.ContainsUnexpandedParameterPack = true;
 
-Exprs[i] = exprs[i];
+getTrailingObjects()[I] = Exprs[I];
   }
 }
 
+ParenListExpr::ParenListExpr(EmptyShell Empty, unsigned NumExprs)
+: Expr(ParenListExprClass, Empty) {
+  ParenListExprBits.NumExprs = NumExprs;
+}
+
+ParenListExpr *ParenListExpr::Create(const ASTContext &Ctx,
+ SourceLocation LParenLoc,
+ ArrayRef Exprs,
+ SourceLocation RParenLoc) {
+  void *Mem = Ctx.Allocate(totalSizeToAlloc(Exprs.size()),
+   alignof(ParenListExpr));
+  return new (Mem) ParenListExpr(LParenLoc, Exprs, RParenLoc);
+}
+
+ParenListExpr *ParenListExpr::CreateEmpty(const ASTContext &Ctx,
+  unsigned NumExprs) {
+  void *Mem =
+  Ctx.Allocate(totalSizeToAlloc(NumExprs), alignof(ParenListExpr));
+  return new (Mem) ParenListExpr(EmptyShell(), NumExprs);
+}
+
 const OpaqueValueExpr *OpaqueValueExpr::findInCopyConstruct(const Expr *e) {
   if (const ExprWithCleanups *ewc = dyn_cast(e))
 e = ewc->getSubExpr();
Index: lib/AST/ASTImporte

r347322 - [NFC] Remove MS line endings in diagnostics file.

2018-11-20 Thread Erich Keane via cfe-commits
Author: erichkeane
Date: Tue Nov 20 08:32:46 2018
New Revision: 347322

URL: http://llvm.org/viewvc/llvm-project?rev=347322&view=rev
Log:
[NFC] Remove MS line endings in diagnostics file.

Change-Id: I74704acf052e2e8fe707f18230bc5655c2bf2a91

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

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=347322&r1=347321&r2=347322&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Nov 20 08:32:46 
2018
@@ -9478,15 +9478,15 @@ def warn_block_literal_qualifiers_on_omi
   InGroup;
 
 def ext_warn_gnu_final : ExtWarn<
-  "__final is a GNU extension, consider using C++11 final">,
-  InGroup;
-
-def warn_shadow_field : Warning<
-  "%select{parameter|non-static data member}3 %0 %select{|of %1 }3shadows "
-  "member inherited from type %2">, InGroup, DefaultIgnore;
-def note_shadow_field : Note<"declared here">;
-
-def err_multiversion_required_in_redecl : Error<
+  "__final is a GNU extension, consider using C++11 final">,
+  InGroup;
+
+def warn_shadow_field : Warning<
+  "%select{parameter|non-static data member}3 %0 %select{|of %1 }3shadows "
+  "member inherited from type %2">, InGroup, DefaultIgnore;
+def note_shadow_field : Note<"declared here">;
+
+def err_multiversion_required_in_redecl : Error<
   "function declaration is missing %select{'target'|'cpu_specific' or "
   "'cpu_dispatch'}0 attribute in a multiversioned function">;
 def note_multiversioning_caused_here : Note<


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


[PATCH] D53157: Teach the IRBuilder about constrained fadd and friends

2018-11-20 Thread Ulrich Weigand via Phabricator via cfe-commits
uweigand added a comment.

OK, let me try to expand on my point 3 above, which appears to have confused 
everybody :-)

First, let's distinguish two separate requirements: those on floating-point 
operations that explicitly run in regions with non-default control modes, and 
those on floating-point operations that run outside such regions.  (Note that 
those regions are by definition a subset of the regions marked as FENV_ACCESS 
ON, but not necessarily coincide with them.)

For the first class of operations, there are various requirements to constrain 
optimization.  All of those are handled in the current design by simply 
representing those operations via constrained intrinsics.  This can be done 
simply by always using constrained intrinsics whenever we are inside any 
FENV_ACCESS ON region.  (My comments above were not intended to refer to those 
at all.)

Now, for the second class of operations, most of these requirements do not 
apply.  However, there is one critical requirement that still **does** apply: 
such operations may never be moved to **inside** a region with non-default 
control modes.  (Where it makes a difference, the operation can in principle be 
even moved inside a FENV_ACCESS ON region, as long as the control modes 
actually have not yet changed from the default modes.)

As @andrew.w.kaylor mentioned above, to fulfil this requirement if suffices to 
prevent moving any such floating-point operation across any statement that 
modifies the control modes (or inspects the exception flags).  There is only a 
small number of statements that do so directly (those would all be inline asm 
or platform-specific builtins), but the action can be hidden behind a function 
call as well.  This applies in particular to the related C library calls with 
well-known names (which the compiler could detect), but in addition any random 
function call might **indirectly** contain such a statement (which the compiler 
will not know, in general).  Since LLVM today will freely move normal 
floating-point operations across normal function calls, this is a problem that 
needs to be addressed.

Now, one way to do that would be to ensure that any floating-point operation 
outside FENV_ACCESS ON regions is **also** implemented via constrained 
intrinsics, as long as there is any FENV_ACCESS ON present in the function at 
all.  As @cameron.mcinally mentioned above, that would prevent reordering 
(across any function call, even) and therefore solve the problem.  However, I 
believe there were concerns whether we can reliably ensure that property in the 
presence of optimizations like inlining, in particular if LTO is also used.  
Even if this can be resolved, I believe there were additional concerns that 
this might overly constrain optimization and lead to suboptimal performance.

This finally gets to the intent of my point 3 above, where I was trying to see 
if there is any way we can do better, that is correctly handle floating-point 
operations outside FENV_ACCESS ON regions **without** having to turn them all 
into constrained intrinsics.  One way might be to add some new code motion 
barrier in the IR optimizers that would prevent movement of floating-point 
operations across the location of any FENV_ACCESS pragma.  But  -- and this is 
I think what @kpn referered to above -- those locations don't really correspond 
to anything in the IR that could serve as such a barrier.  My observation above 
was simply that if we want to go that way, it in fact isn't really necessary to 
put those barriers at exactly these places.  Instead, we can put the barriers 
at those places that will actually modify (or inspect) the control words -- 
which are either special operations we can explicitly recognize, or general 
function calls -- but only those calls where the call site was originally 
inside a FENV_ACCESS ON region (and was marked by the front-end as such).  This 
has the advantage that a function call site is a natural place to act as 
barrier -- in fact it already acts as such e.g. for global memory accesses. (It 
would also be easy to implement as barrier on the MI / back-end level.)  In 
addition, this approach would not lead to any performance penalty outside of 
FENV_ACCESS ON regions at all.

But given that there is still infrastructure missing in the IR optimizers, I 
also think that at least in the first implementation, we probably should go 
with the original approach and just use constrained intrinsics everywhere in 
the function, and possibly add some function attribute that prevent any 
cross-inlining of functions built with constrained intrinsics with functions 
built with regular floating-point operations.


https://reviews.llvm.org/D53157



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


[PATCH] D54760: [clangd] Cleanup: make the diags callback global in TUScheduler

2018-11-20 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov created this revision.
ilya-biryukov added a reviewer: sammccall.
Herald added subscribers: kadircet, arphaman, jkorous, MaskRay, ioeric, 
javed.absar.

Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D54760

Files:
  clangd/ClangdServer.cpp
  clangd/ClangdServer.h
  clangd/TUScheduler.cpp
  clangd/TUScheduler.h
  unittests/clangd/TUSchedulerTests.cpp

Index: unittests/clangd/TUSchedulerTests.cpp
===
--- unittests/clangd/TUSchedulerTests.cpp
+++ unittests/clangd/TUSchedulerTests.cpp
@@ -10,6 +10,7 @@
 #include "Context.h"
 #include "TUScheduler.h"
 #include "TestFS.h"
+#include "llvm/ADT/ScopeExit.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 #include 
@@ -28,11 +29,49 @@
 using ::testing::Pointee;
 using ::testing::UnorderedElementsAre;
 
-void ignoreUpdate(Optional>) {}
 void ignoreError(Error Err) {
   handleAllErrors(std::move(Err), [](const ErrorInfoBase &) {});
 }
 
+/// Updates a file and executes a callback when the update is finished or
+/// cancelled.
+void updateWithCallback(TUScheduler &S, PathRef File, ParseInputs Inputs,
+WantDiagnostics WD, llvm::unique_function CB) {
+  WithContextValue Ctx(llvm::make_scope_exit(std::move(CB)));
+  S.update(File, std::move(Inputs), WD);
+}
+
+static Key)>>
+DiagsCallbackKey;
+
+/// A diagnostics callback that should be passed to TUScheduler when it's used
+/// in updateWithDiags.
+void captureDiags(PathRef File, std::vector Diags) {
+  auto D = Context::current().get(DiagsCallbackKey);
+  if (!D)
+return;
+  const_cast)> &> (*D)(
+  File, Diags);
+}
+
+/// Schedule an update and call \p CB with the diagnostics it produces, if any.
+/// The TUScheduler should be created with captureDiags as a DiagsCallback for
+/// this to work.
+void updateWithDiags(TUScheduler &S, PathRef File, ParseInputs Inputs,
+ WantDiagnostics WD,
+ llvm::unique_function)> CB) {
+  Path OrigFile = File.str();
+  WithContextValue Ctx(
+  DiagsCallbackKey,
+  Bind(
+  [OrigFile](decltype(CB) CB, PathRef File, std::vector Diags) {
+assert(File == OrigFile);
+CB(std::move(Diags));
+  },
+  std::move(CB)));
+  S.update(File, std::move(Inputs), WD);
+}
+
 class TUSchedulerTests : public ::testing::Test {
 protected:
   ParseInputs getInputs(PathRef File, std::string Contents) {
@@ -57,7 +96,7 @@
   auto Missing = testPath("missing.cpp");
   Files[Missing] = "";
 
-  S.update(Added, getInputs(Added, ""), WantDiagnostics::No, ignoreUpdate);
+  S.update(Added, getInputs(Added, ""), WantDiagnostics::No);
 
   // Assert each operation for missing file is an error (even if it's available
   // in VFS).
@@ -106,23 +145,25 @@
 getDefaultAsyncThreadsCount(),
 /*StorePreamblesInMemory=*/true, /*ASTCallbacks=*/nullptr,
 /*UpdateDebounce=*/std::chrono::steady_clock::duration::zero(),
-ASTRetentionPolicy());
+ASTRetentionPolicy(), captureDiags);
 auto Path = testPath("foo.cpp");
-S.update(Path, getInputs(Path, ""), WantDiagnostics::Yes,
- [&](std::vector) { Ready.wait(); });
-
-S.update(Path, getInputs(Path, "request diags"), WantDiagnostics::Yes,
- [&](std::vector Diags) { ++CallbackCount; });
-S.update(Path, getInputs(Path, "auto (clobbered)"), WantDiagnostics::Auto,
- [&](std::vector Diags) {
-   ADD_FAILURE() << "auto should have been cancelled by auto";
- });
-S.update(Path, getInputs(Path, "request no diags"), WantDiagnostics::No,
- [&](std::vector Diags) {
-   ADD_FAILURE() << "no diags should not be called back";
- });
-S.update(Path, getInputs(Path, "auto (produces)"), WantDiagnostics::Auto,
- [&](std::vector Diags) { ++CallbackCount; });
+updateWithDiags(S, Path, getInputs(Path, ""), WantDiagnostics::Yes,
+[&](std::vector) { Ready.wait(); });
+updateWithDiags(S, Path, getInputs(Path, "request diags"),
+WantDiagnostics::Yes,
+[&](std::vector) { ++CallbackCount; });
+updateWithDiags(S, Path, getInputs(Path, "auto (clobbered)"),
+WantDiagnostics::Auto, [&](std::vector) {
+  ADD_FAILURE()
+  << "auto should have been cancelled by auto";
+});
+updateWithDiags(S, Path, getInputs(Path, "request no diags"),
+WantDiagnostics::No, [&](std::vector) {
+  ADD_FAILURE() << "no diags should not be called back";
+});
+updateWithDiags(S, Path, getInputs(Path, "auto (produces)"),
+WantDiagnostics::Auto,
+[&](std::vector) { ++CallbackCount; });
 Ready.notify();
   }
   EXPECT_EQ(2, CallbackCount);
@@ -134,19 +175,22 @@
 TUScheduler S(getDefaultAs

[PATCH] D54760: [clangd] Cleanup: make the diags callback global in TUScheduler

2018-11-20 Thread Ilya Biryukov via Phabricator via cfe-commits
ilya-biryukov added a comment.

The tests still model the old callbacks using callbacks, unfortunately I see no 
good way to test same things in any other way.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D54760



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


[PATCH] D53157: Teach the IRBuilder about constrained fadd and friends

2018-11-20 Thread Ulrich Weigand via Phabricator via cfe-commits
uweigand added a comment.

In https://reviews.llvm.org/D53157#1303193, @andrew.w.kaylor wrote:

> I agree that it's preferable to re-use these existing options if possible. I 
> have some concerns that -ftrapping-math has a partial implementation in place 
> that doesn't seem to be well aligned with the way fast-math flags are 
> handled, so it might require some work to have that working as expected 
> without breaking existing users. In general though these seem like they 
> should do what we need.


So as far as I can see, the current implementation of -f(no-)trapping-math in 
LLVM is pretty much a stub.  The driver passes the option on to CC1, and in 
addition it disables -menable-unsafe-fp-math and -massociative-math if 
-fno-trapping-math is in effect (the latter may be a minor difference to GCC, 
but should be conservatively compatible).  The compiler itself does nothing 
except mark all functions with the no-trapping-math attribute if 
-fno-trapping-math is in effect.  LLVM itself completely ignores this attribute 
except on ARM, where it is used to set the ABI_FP_exceptions extended 
attribute.  (But since LLVM doesn't really implement the flag in actual 
codegen, setting the attribute to indicate the property seems a bit odd ...)

> Regarding GCC compatibility, I notice that GCC defaults to trapping math 
> being enabled and I don't think that's what we want with clang. It also seems 
> to imply something more than I think we need for constrained handling. For 
> example, the GCC documentation says that -fno-trapping-math "can result in 
> incorrect output for programs that depend on an exact implementation of IEEE 
> or ISO rules/specifications for math functions" so it sounds like maybe it 
> also implies (for GCC)  something like LLVM's "afn" fast math flag.
> 
> So if we are going to use these options, I think we need to have a discussion 
> about whether or not it's OK to diverge from GCC's interpretation of them.

The GCC documentation says:

> -fno-trapping-math
> 
> Compile code assuming that floating-point operations cannot generate 
> user-visible traps.  These traps include division by zero, overflow, 
> underflow, inexact result and invalid operation.  This option requires that 
> -fno-signaling-nans be in effect.  Setting this option may allow faster code 
> if one relies on ``non-stop'' IEEE arithmetic, for example.
> 
> This option should never be turned on by any -O option since it can result in 
> incorrect output for programs that depend on an exact implementation of IEEE 
> or ISO rules/specifications for math functions.
> 
> The default is -ftrapping-math.

As far as I can tell, this does not imply any **additional** differences except 
that -fno-trapping-math may rearrange floating-point operations to eliminate or 
introduce traps or changes to exception flags.  It is **those** changes 
themselves (not anything else) that can result in incorrect output for programs 
that depend on exact IEEE semantics, and therefore this option must not be 
enabled by default at any optimization level, as the second paragraph above 
states.

Note that in GCC, -fno-trapping-math is implied by -funsafe-math-optimizations, 
which in turn is implied by -ffast-math.   Those options all are documented 
using the same "incorrect output for programs that depend on exact IEEE 
semantics" clause: -funsafe-math-optimization is the catch-all for all such 
effects, but it is separated into -fno-signed-zeros, -fno-trapping-math, 
-fassociative-math, and -freciprocal-math that cover the distinct aspects of 
just how IEEE semantics might get violated.

We can of course still have a separate discussion on what the default should 
be.  But even if we choose a different default than GCC (as is already the case 
e.g. for the -ffp-contract option), I think it would be preferable for the two 
explicit options to behave in a compatible way.


https://reviews.llvm.org/D53157



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


[PATCH] D54355: Use is.constant intrinsic for __builtin_constant_p

2018-11-20 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added inline comments.



Comment at: lib/AST/ExprConstant.cpp:11391
 
   llvm_unreachable("Invalid StmtClass!");
 }

@void , I assume this unreachable is the one reported by @uweigand ? Does the 
above switch need a case statement added?


Repository:
  rC Clang

https://reviews.llvm.org/D54355



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


[PATCH] D52695: [clang][Parse] Diagnose useless null statements (PR39111)

2018-11-20 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

In https://reviews.llvm.org/D52695#1304225, @aaron.ballman wrote:

> Aside from some small nits, LGTM!


Thank you for the review!
Will address nits and land.


Repository:
  rC Clang

https://reviews.llvm.org/D52695



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


[PATCH] D54560: [analyzer] MoveChecker Pt.3: Improve warning messages a bit.

2018-11-20 Thread Umann Kristóf via Phabricator via cfe-commits
Szelethus added inline comments.



Comment at: lib/StaticAnalyzer/Checkers/MoveChecker.cpp:385-386
+  }
+  // Provide the caller with the classification of the object
+  // we've obtained here accidentally, for later use.
+  return OK;

NoQ wrote:
> Szelethus wrote:
> > Maybe move this in-class?
> Mmm, what do you mean?
`explain.*` sounds like it either returns a string, or writes a stream object, 
but the return type isn't `void` nor string, maybe it'd be worth to put this 
comment in-class.

But yea, this is over the top nitpicking, I don't insist :)


https://reviews.llvm.org/D54560



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


[PATCH] D54757: [clang-tidy] new check: bugprone-branch-clone

2018-11-20 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: clang-tidy/bugprone/BranchCloneCheck.cpp:19
+
+namespace {
+

Please use anonymous namespaces only for type declarations. See LLV coding 
style guide.



Comment at: clang-tidy/bugprone/BranchCloneCheck.cpp:43
+
+  for (unsigned i = 0; i < LHS.size(); i++) {
+if (!areStatementsIdentical(LHS[i]->stripLabelLikeStatements(),

Please use size_t.



Comment at: clang-tidy/bugprone/BranchCloneCheck.cpp:122
+
+const int N = Branches.size();
+llvm::BitVector KnownAsClone(N);

Please use size_t. Same for loop variables. Clang complains about such 
conversions.



Comment at: docs/ReleaseNotes.rst:70
 
+- New :doc:`bugprone-branch-clone
+  ` check.

Please use alphabetical order for new checks list.



Comment at: docs/clang-tidy/checks/bugprone-branch-clone.rst:6
+
+Finds ``if/else if/else`` chains where two or more branches are Type I clones
+of each other (that is, they contain identical code) and ``switch`` statements

Please first statement same as Release Notes.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D54757



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


[PATCH] D54641: [compiler-rt] [cmake] Fix detecting terminfo library

2018-11-20 Thread Michał Górny via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rCRT347338: [cmake] Fix detecting terminfo library (authored 
by mgorny, committed by ).

Repository:
  rCRT Compiler Runtime

https://reviews.llvm.org/D54641

Files:
  cmake/config-ix.cmake


Index: cmake/config-ix.cmake
===
--- cmake/config-ix.cmake
+++ cmake/config-ix.cmake
@@ -121,10 +121,12 @@
 
 # Look for terminfo library, used in unittests that depend on LLVMSupport.
 if(LLVM_ENABLE_TERMINFO)
-  foreach(library tinfo terminfo curses ncurses ncursesw)
+  foreach(library terminfo tinfo curses ncurses ncursesw)
+string(TOUPPER ${library} library_suffix)
 check_library_exists(
-  ${library} setupterm "" COMPILER_RT_HAS_TERMINFO)
-if(COMPILER_RT_HAS_TERMINFO)
+  ${library} setupterm "" COMPILER_RT_HAS_TERMINFO_${library_suffix})
+if(COMPILER_RT_HAS_TERMINFO_${library_suffix})
+  set(COMPILER_RT_HAS_TERMINFO TRUE)
   set(COMPILER_RT_TERMINFO_LIB "${library}")
   break()
 endif()


Index: cmake/config-ix.cmake
===
--- cmake/config-ix.cmake
+++ cmake/config-ix.cmake
@@ -121,10 +121,12 @@
 
 # Look for terminfo library, used in unittests that depend on LLVMSupport.
 if(LLVM_ENABLE_TERMINFO)
-  foreach(library tinfo terminfo curses ncurses ncursesw)
+  foreach(library terminfo tinfo curses ncurses ncursesw)
+string(TOUPPER ${library} library_suffix)
 check_library_exists(
-  ${library} setupterm "" COMPILER_RT_HAS_TERMINFO)
-if(COMPILER_RT_HAS_TERMINFO)
+  ${library} setupterm "" COMPILER_RT_HAS_TERMINFO_${library_suffix})
+if(COMPILER_RT_HAS_TERMINFO_${library_suffix})
+  set(COMPILER_RT_HAS_TERMINFO TRUE)
   set(COMPILER_RT_TERMINFO_LIB "${library}")
   break()
 endif()
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D54760: [clangd] Cleanup: make the diags callback global in TUScheduler

2018-11-20 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

Nice!
The biggest suggestion I have is merging the callback into ASTCallbacks. That's 
awkward in initialization (`makeUpdateCallbacks` probably needs to be called 
unconditionally with a maybe-null pointer) but it seems like a natural grouping 
in all the places it gets plumbed around to... and there are a lot!




Comment at: clangd/ClangdServer.h:232
+  /// addDocument. Used to avoid races when sending diagnostics to the clients.
+  static Key DocVersionKey;
 

I'm not sure using context here buys much: there aren't many layers, they're 
fairly coupled, and this information would look pretty natural in the 
interfaces.

What about:
 - move the definition of DocVersion to TUScheduler
 - make DocVersion a member of ParseInputs
 - pass (PathRef, DocVersion, vector) to the TUScheduler's diag callback



Comment at: clangd/TUScheduler.h:92
+  ASTRetentionPolicy RetentionPolicy,
+  DiagsCallback OnDiags = nullptr);
   ~TUScheduler();

ISTM the callback would fit nicely on the ASTCallbacks?
It even gets plumbed through to ASTWorker correctly by reference.



Comment at: unittests/clangd/TUSchedulerTests.cpp:32
 
-void ignoreUpdate(Optional>) {}
 void ignoreError(Error Err) {
   handleAllErrors(std::move(Err), [](const ErrorInfoBase &) {});

(up to you if you feel like fixing while here)
this is just llvm::consumeError



Comment at: unittests/clangd/TUSchedulerTests.cpp:36
 
+/// Updates a file and executes a callback when the update is finished or
+/// cancelled.

Yeah, these are messy. I also don't see something better in general.

There's a place or two below where I think we can avoid them without much 
verbosity, which I think is probably worthwhile even if lots of tests need them 
:-/



Comment at: unittests/clangd/TUSchedulerTests.cpp:38
+/// cancelled.
+void updateWithCallback(TUScheduler &S, PathRef File, ParseInputs Inputs,
+WantDiagnostics WD, llvm::unique_function CB) {

ParseInputs is always getInputs(File), you could do that here (similarly for 
`updateWithDiags`) to avoid repetition.



Comment at: unittests/clangd/TUSchedulerTests.cpp:495
   /*UpdateDebounce=*/std::chrono::steady_clock::duration::zero(),
-  ASTRetentionPolicy());
+  ASTRetentionPolicy(), captureDiags);
 

can we just increment a counter in the callback, and have DoUpdate look for a 
delta?


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D54760



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


[PATCH] D52695: [clang][Parse] Diagnose useless null statements (PR39111)

2018-11-20 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC347339: [clang][Parse] Diagnose useless null statements / 
empty init-statements (authored by lebedevri, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D52695?vs=174624&id=174812#toc

Repository:
  rC Clang

https://reviews.llvm.org/D52695

Files:
  docs/ReleaseNotes.rst
  include/clang/Basic/DiagnosticGroups.td
  include/clang/Basic/DiagnosticParseKinds.td
  include/clang/Parse/Parser.h
  lib/Parse/ParseExprCXX.cpp
  lib/Parse/ParseStmt.cpp
  test/Parser/extra-semi-resulting-in-nullstmt-in-init-statement.cpp
  test/Parser/extra-semi-resulting-in-nullstmt.cpp

Index: include/clang/Basic/DiagnosticParseKinds.td
===
--- include/clang/Basic/DiagnosticParseKinds.td
+++ include/clang/Basic/DiagnosticParseKinds.td
@@ -53,6 +53,10 @@
 def warn_extra_semi_after_mem_fn_def : Warning<
   "extra ';' after member function definition">,
   InGroup, DefaultIgnore;
+def warn_null_statement : Warning<
+  "empty expression statement has no effect; "
+  "remove unnecessary ';' to silence this warning">,
+  InGroup, DefaultIgnore;
 
 def ext_thread_before : Extension<"'__thread' before '%0'">;
 def ext_keyword_as_ident : ExtWarn<
@@ -554,6 +558,9 @@
 def warn_cxx17_compat_for_range_init_stmt : Warning<
   "range-based for loop initialization statements are incompatible with "
   "C++ standards before C++2a">, DefaultIgnore, InGroup;
+def warn_empty_init_statement : Warning<
+  "empty initialization statement of '%select{if|switch|range-based for}0' "
+  "has no effect">, InGroup, DefaultIgnore;
 
 // C++ derived classes
 def err_dup_virtual : Error<"duplicate 'virtual' in base specifier">;
Index: include/clang/Basic/DiagnosticGroups.td
===
--- include/clang/Basic/DiagnosticGroups.td
+++ include/clang/Basic/DiagnosticGroups.td
@@ -162,6 +162,8 @@
 def ExtraTokens : DiagGroup<"extra-tokens">;
 def CXX98CompatExtraSemi : DiagGroup<"c++98-compat-extra-semi">;
 def CXX11ExtraSemi : DiagGroup<"c++11-extra-semi">;
+def EmptyInitStatement : DiagGroup<"empty-init-stmt">;
+def ExtraSemiStmt : DiagGroup<"extra-semi-stmt", [EmptyInitStatement]>;
 def ExtraSemi : DiagGroup<"extra-semi", [CXX98CompatExtraSemi,
  CXX11ExtraSemi]>;
 
@@ -768,7 +770,8 @@
 MissingMethodReturnType,
 SignCompare,
 UnusedParameter,
-NullPointerArithmetic
+NullPointerArithmetic,
+EmptyInitStatement
   ]>;
 
 def Most : DiagGroup<"most", [
Index: include/clang/Parse/Parser.h
===
--- include/clang/Parse/Parser.h
+++ include/clang/Parse/Parser.h
@@ -1888,6 +1888,7 @@
   StmtResult ParseCompoundStatement(bool isStmtExpr,
 unsigned ScopeFlags);
   void ParseCompoundStatementLeadingPragmas();
+  bool ConsumeNullStmt(StmtVector &Stmts);
   StmtResult ParseCompoundStatementBody(bool isStmtExpr = false);
   bool ParseParenExprOrCondition(StmtResult *InitStmt,
  Sema::ConditionResult &CondResult,
Index: test/Parser/extra-semi-resulting-in-nullstmt.cpp
===
--- test/Parser/extra-semi-resulting-in-nullstmt.cpp
+++ test/Parser/extra-semi-resulting-in-nullstmt.cpp
@@ -0,0 +1,96 @@
+// RUN: %clang_cc1 -fsyntax-only -Wextra-semi-stmt -verify %s
+// RUN: cp %s %t
+// RUN: %clang_cc1 -x c++ -Wextra-semi-stmt -fixit %t
+// RUN: %clang_cc1 -x c++ -Wextra-semi-stmt -Werror %t
+
+#define GOODMACRO(varname) int varname
+#define BETTERMACRO(varname) GOODMACRO(varname);
+#define NULLMACRO(varname)
+
+enum MyEnum {
+  E1,
+  E2
+};
+
+void test() {
+  ; // expected-warning {{empty expression statement has no effect; remove unnecessary ';' to silence this warning}}
+  ;
+
+  // This removal of extra semi also consumes all the comments.
+  // clang-format: off
+  ;;;
+  // clang-format: on
+
+  // clang-format: off
+  ;NULLMACRO(ZZ);
+  // clang-format: on
+
+  {}; // expected-warning {{empty expression statement has no effect; remove unnecessary ';' to silence this warning}}
+
+  {
+; // expected-warning {{empty expression statement has no effect; remove unnecessary ';' to silence this warning}}
+  }
+
+  if (true) {
+; // expected-warning {{empty expression statement has no effect; remove unnecessary ';' to silence this warning}}
+  }
+
+  GOODMACRO(v0); // OK
+
+  GOODMACRO(v1;) // OK
+
+  BETTERMACRO(v2) // OK
+
+  BETTERMACRO(v3;) // Extra ';', but within macro expansion, so ignored.
+
+  BETTERMACRO(v4); // expected-warning {{empty expression statement has no effect; remove unnecessary ';' to silence this warning}}
+
+  BETTERMACRO(v5;); // expected-warning {{empty expression statement has no effect; remove unnecessary ';' to silence this warning}}
+
+  NULLMACRO(v6) // OK
+
+  NULLMA

r347339 - [clang][Parse] Diagnose useless null statements / empty init-statements

2018-11-20 Thread Roman Lebedev via cfe-commits
Author: lebedevri
Date: Tue Nov 20 10:59:05 2018
New Revision: 347339

URL: http://llvm.org/viewvc/llvm-project?rev=347339&view=rev
Log:
[clang][Parse] Diagnose useless null statements / empty init-statements

Summary:
clang has `-Wextra-semi` (D43162), which is not dictated by the currently 
selected standard.
While that is great, there is at least one more source of need-less semis - 
'null statements'.
Sometimes, they are needed:
```
for(int x = 0; continueToDoWork(x); x++)
  ; // Ugly code, but the semi is needed here.
```

But sometimes they are just there for no reason:
```
switch(X) {
case 0:
  return -2345;
case 5:
  return 0;
default:
  return 42;
}; // <- oops

;;; <- PS, still not diagnosed. Clearly this is junk.
```

Additionally:
```
if(; // <- empty init-statement
   true)
  ;

switch (; // empty init-statement
x) {
  ...
}

for (; // <- empty init-statement
 int y : S())
  ;
}

As usual, things may or may not go sideways in the presence of macros.
While evaluating this diag on my codebase of interest, it was unsurprisingly
discovered that Google Test macros are *very* prone to this.
And it seems many issues are deep within the GTest itself, not
in the snippets passed from the codebase that uses GTest.

So after some thought, i decided not do issue a diagnostic if the semi
is within *any* macro, be it either from the normal header, or system header.

Fixes [[ https://bugs.llvm.org/show_bug.cgi?id=39111 | PR39111 ]]

Reviewers: rsmith, aaron.ballman, efriedma

Reviewed By: aaron.ballman

Subscribers: cfe-commits

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

Added:
cfe/trunk/test/Parser/extra-semi-resulting-in-nullstmt-in-init-statement.cpp
cfe/trunk/test/Parser/extra-semi-resulting-in-nullstmt.cpp
Modified:
cfe/trunk/docs/ReleaseNotes.rst
cfe/trunk/include/clang/Basic/DiagnosticGroups.td
cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
cfe/trunk/include/clang/Parse/Parser.h
cfe/trunk/lib/Parse/ParseExprCXX.cpp
cfe/trunk/lib/Parse/ParseStmt.cpp

Modified: cfe/trunk/docs/ReleaseNotes.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/ReleaseNotes.rst?rev=347339&r1=347338&r2=347339&view=diff
==
--- cfe/trunk/docs/ReleaseNotes.rst (original)
+++ cfe/trunk/docs/ReleaseNotes.rst Tue Nov 20 10:59:05 2018
@@ -55,6 +55,63 @@ Major New Features
 Improvements to Clang's diagnostics
 ^^^
 
+- ``-Wextra-semi-stmt`` is a new diagnostic that diagnoses extra semicolons,
+  much like ``-Wextra-semi``. This new diagnostic diagnoses all *unnecessary*
+  null statements (expression statements without an expression), unless: the
+  semicolon directly follows a macro that was expanded to nothing or if the
+  semicolon is within the macro itself. This applies to macros defined in 
system
+  headers as well as user-defined macros.
+
+  .. code-block:: c++
+
+  #define MACRO(x) int x;
+  #define NULLMACRO(varname)
+
+  void test() {
+; // <- warning: ';' with no preceding expression is a null statement
+
+while (true)
+  ; // OK, it is needed.
+
+switch (my_enum) {
+case E1:
+  // stuff
+  break;
+case E2:
+  ; // OK, it is needed.
+}
+
+MACRO(v0;) // Extra semicolon, but within macro, so ignored.
+
+MACRO(v1); // <- warning: ';' with no preceding expression is a null 
statement
+
+NULLMACRO(v2); // ignored, NULLMACRO expanded to nothing.
+  }
+
+- ``-Wempty-init-stmt`` is a new diagnostic that diagnoses empty 
init-statements
+  of ``if``, ``switch``, ``range-based for``, unless: the semicolon directly
+  follows a macro that was expanded to nothing or if the semicolon is within 
the
+  macro itself (both macros from system headers, and normal macros). This
+  diagnostic is in the ``-Wextra-semi-stmt`` group and is enabled in
+  ``-Wextra``.
+
+  .. code-block:: c++
+
+  void test() {
+if(; // <- warning: init-statement of 'if' is a null statement
+   true)
+  ;
+
+switch (; // <- warning: init-statement of 'switch' is a null statement
+x) {
+  ...
+}
+
+for (; // <- warning: init-statement of 'range-based for' is a null 
statement
+ int y : S())
+  ;
+  }
+
 
 Non-comprehensive list of changes in this release
 -

Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticGroups.td?rev=347339&r1=347338&r2=347339&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticGroups.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td Tue Nov 20 10:59:05 2018
@@ -162,6 +162,8 @@ def GNUEmptyStruct : DiagG

[PATCH] D54757: [clang-tidy] new check: bugprone-branch-clone

2018-11-20 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added inline comments.



Comment at: clang-tidy/bugprone/BranchCloneCheck.cpp:43
+
+  for (unsigned i = 0; i < LHS.size(); i++) {
+if (!areStatementsIdentical(LHS[i]->stripLabelLikeStatements(),

Eugene.Zelenko wrote:
> Please use size_t.
Also
```
for (unsigned i = 0, unsigned Size = LHS.size(); i < Size; i++) {
```


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D54757



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


[PATCH] D51268: [libc++] Implement P0487R1 - Fixing operator>>(basic_istream&, CharT*)

2018-11-20 Thread Louis Dionne via Phabricator via cfe-commits
ldionne accepted this revision.
ldionne added a comment.

LGTM


Repository:
  rCXX libc++

https://reviews.llvm.org/D51268



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


[PATCH] D53210: Revert 344389 "Revert r344375 "[Driver] check for exit code from SIGPIPE""

2018-11-20 Thread Richard Barton via Phabricator via cfe-commits
richard.barton.arm added a comment.

Hi @nickdesaulniers 
I have run into this too recently so would love to see this patch land. Did you 
get anywhere with those lld test failures?
Ta
Rich


Repository:
  rC Clang

https://reviews.llvm.org/D53210



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


[PATCH] D54764: [OpenMP] Update CHECK-DAG usage in for_codegen.cpp

2018-11-20 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny created this revision.
jdenny added a reviewer: ABataev.
Herald added a subscriber: guansong.

This patch adjusts a test not to depend on deprecated FileCheck
behavior that permits overlapping matches within a block of CHECK-DAG
directives.  Thus, this patch also removes uses of FileCheck's
-allow-deprecated-dag-overlap command-line option.

Specifically, the FileCheck variables DBG_LOC_START, DBG_LOC_END, and 
DBG_LOC_CANCEL were all set to the same value.  As a result, three
TERM_DEBUG-DAG patterns, one for each variable, all matched the same
text under the old overlapping behavior.  Under the new 
non-overlapping behavior, that's not permitted.  This patch's solution
is to replace these variables with one variable and replace these
patterns with one pattern.

While I have attempted to preserve this test's original intent, I
might have misunderstood something, so please point out any problems.
Your explanation might prove helpful as I address similar issues in
other tests.


Repository:
  rC Clang

https://reviews.llvm.org/D54764

Files:
  clang/test/OpenMP/for_codegen.cpp


Index: clang/test/OpenMP/for_codegen.cpp
===
--- clang/test/OpenMP/for_codegen.cpp
+++ clang/test/OpenMP/for_codegen.cpp
@@ -1,14 +1,14 @@
-// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple x86_64-unknown-unknown 
-emit-llvm %s -fexceptions -fcxx-exceptions -o - 
-fsanitize-address-use-after-scope | FileCheck -allow-deprecated-dag-overlap %s 
--check-prefix=CHECK --check-prefix=LIFETIME
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple x86_64-unknown-unknown 
-emit-llvm %s -fexceptions -fcxx-exceptions -o - 
-fsanitize-address-use-after-scope | FileCheck %s --check-prefix=CHECK 
--check-prefix=LIFETIME
 // RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple x86_64-unknown-unknown 
-fexceptions -fcxx-exceptions -emit-pch -o %t %s
-// RUN: %clang_cc1 -fopenmp -x c++ -triple x86_64-unknown-unknown -fexceptions 
-fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | 
FileCheck -allow-deprecated-dag-overlap %s
-// RUN: %clang_cc1 -verify -triple x86_64-apple-darwin10 -fopenmp -fexceptions 
-fcxx-exceptions -debug-info-kind=line-tables-only -x c++ -emit-llvm %s -o - | 
FileCheck -allow-deprecated-dag-overlap %s --check-prefix=TERM_DEBUG
-// RUN: %clang_cc1 -main-file-name for_codegen.cpp %s -o - -emit-llvm 
-fprofile-instrument=clang -fprofile-instrument-path=for_codegen-test.profraw | 
FileCheck -allow-deprecated-dag-overlap %s --check-prefix=PROF-INSTR-PATH
+// RUN: %clang_cc1 -fopenmp -x c++ -triple x86_64-unknown-unknown -fexceptions 
-fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | 
FileCheck %s
+// RUN: %clang_cc1 -verify -triple x86_64-apple-darwin10 -fopenmp -fexceptions 
-fcxx-exceptions -debug-info-kind=line-tables-only -x c++ -emit-llvm %s -o - | 
FileCheck %s --check-prefix=TERM_DEBUG
+// RUN: %clang_cc1 -main-file-name for_codegen.cpp %s -o - -emit-llvm 
-fprofile-instrument=clang -fprofile-instrument-path=for_codegen-test.profraw | 
FileCheck %s --check-prefix=PROF-INSTR-PATH
 
-// RUN: %clang_cc1 -verify -fopenmp-simd -x c++ -triple x86_64-unknown-unknown 
-emit-llvm %s -fexceptions -fcxx-exceptions -o - | FileCheck 
-allow-deprecated-dag-overlap --check-prefix SIMD-ONLY0 %s
+// RUN: %clang_cc1 -verify -fopenmp-simd -x c++ -triple x86_64-unknown-unknown 
-emit-llvm %s -fexceptions -fcxx-exceptions -o - | FileCheck --check-prefix 
SIMD-ONLY0 %s
 // RUN: %clang_cc1 -fopenmp-simd -x c++ -std=c++11 -triple 
x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s
-// RUN: %clang_cc1 -fopenmp-simd -x c++ -triple x86_64-unknown-unknown 
-fexceptions -fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm 
-o - | FileCheck -allow-deprecated-dag-overlap --check-prefix SIMD-ONLY0 %s
-// RUN: %clang_cc1 -verify -triple x86_64-apple-darwin10 -fopenmp-simd 
-fexceptions -fcxx-exceptions -debug-info-kind=line-tables-only -x c++ 
-emit-llvm %s -o - | FileCheck -allow-deprecated-dag-overlap --check-prefix 
SIMD-ONLY0 %s
-// RUN: %clang_cc1 -main-file-name for_codegen.cpp %s -o - -emit-llvm 
-fprofile-instrument=clang -fprofile-instrument-path=for_codegen-test.profraw | 
FileCheck -allow-deprecated-dag-overlap --check-prefix SIMD-ONLY0 %s
+// RUN: %clang_cc1 -fopenmp-simd -x c++ -triple x86_64-unknown-unknown 
-fexceptions -fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm 
-o - | FileCheck --check-prefix SIMD-ONLY0 %s
+// RUN: %clang_cc1 -verify -triple x86_64-apple-darwin10 -fopenmp-simd 
-fexceptions -fcxx-exceptions -debug-info-kind=line-tables-only -x c++ 
-emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY0 %s
+// RUN: %clang_cc1 -main-file-name for_codegen.cpp %s -o - -emit-llvm 
-fprofile-instrument=clang -fprofile-instrument-path=for_codegen-test.profraw | 
FileCheck --check-prefix SIMD-ONLY0 %s
 // SIMD-ONLY0-NOT: {{__kmpc|__tgt}}
 //
 // expected-no-diagnostics
@@ -385,22 +

[PATCH] D54550: Mark lambda decl as invalid if a captured variable has an invalid type.

2018-11-20 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

Thanks! Some simplifications are possible here, but otherwise this looks good.




Comment at: clang/lib/Sema/SemaExpr.cpp:14946
+  // as invalid as well.
+  if (const CXXRecordDecl *RD = FieldType->getAsCXXRecordDecl()) {
+if (RD->isInvalidDecl()) {

jgorbe wrote:
> rsmith wrote:
> > You'll need to use `FieldType->getBaseElementTypeUnsafe()` or similar here 
> > to handle the case where the field type is an array whose element type is a 
> > class. (That can happen in a lambda if you capture a local array variable 
> > by value.)
> Done, I ended up using Context.getBaseElementType because the call to 
> RequireCompleteType below required a QualType.
Hah, OK, now you've switched to using `RequireCompleteType` this has become 
redundant again (it'll walk to the base element type for you). =)



Comment at: clang/lib/Sema/SemaExpr.cpp:14952-14958
+  NamedDecl *Def;
+  EltTy->isIncompleteType(&Def);
+  if (Def && Def->isInvalidDecl()) {
+Lambda->setInvalidDecl();
+Field->setInvalidDecl();
+  }
+}

I believe the `else` case here is redundant: if `RequireCompleteType` returns 
`false`, the type is complete and there's nothing more you need to do.



Comment at: clang/test/SemaCXX/lambda-invalid-capture.cpp:8-12
+void h() {
+  g child;
+  auto q = [child]{};
+  const int n = sizeof(q);
+}

Can you also add a test for the "capturing an array of incomplete type" case 
please?


https://reviews.llvm.org/D54550



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


[PATCH] D54765: [OpenMP] Update CHECK-DAG usage in target_parallel_codegen.cpp

2018-11-20 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny created this revision.
jdenny added a reviewer: ABataev.
Herald added a subscriber: guansong.

This patch adjusts a test not to depend on deprecated FileCheck
behavior that permits overlapping matches within a block of CHECK-DAG
directives.  Thus, this patch also removes uses of FileCheck's
-allow-deprecated-dag-overlap command-line option.

There were two issues in this test:

1. There were sets of patterns for store instructions in which a

pattern X could match a superset of a pattern Y.  While X appeared
before Y, Y's intended match appeared before X's intended match.  The 
result was that X matched Y's intended match.  Under the old 
overlapping behavior, Y also matched Y's intended match.  Under the 
new non-overlapping behavior, Y had nothing left to match.  This patch
fixes this by gathering these sets in one place and putting the most
specific patterns (Y) before the more general patterns (X).

2. The CHECK-DAG patterns involving the variables CBPADDR3 and

CBPADDR4 were the same, but there was only one match in the text, so
CBPADDR4 patterns had nothing to match under the new non-overlapping
behavior.  Moreover, a preceding related series of directives had 
variables (SADDR0, BPADDR0, etc.) numbered only 0 through 4, but this
series had variables numbered 0 through 5.  Assuming CBPADDR4's
directives were not intended, this patch removes them.

While I have attempted to preserve this test's original intent, I
might have misunderstood something, so please point out any problems.
Your explanation might prove helpful as I address similar issues in
other tests.


Repository:
  rC Clang

https://reviews.llvm.org/D54765

Files:
  clang/test/OpenMP/target_parallel_codegen.cpp

Index: clang/test/OpenMP/target_parallel_codegen.cpp
===
--- clang/test/OpenMP/target_parallel_codegen.cpp
+++ clang/test/OpenMP/target_parallel_codegen.cpp
@@ -1,37 +1,37 @@
 // Test host codegen.
-// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=45 -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-llvm %s -o - | FileCheck -allow-deprecated-dag-overlap  %s --check-prefix CHECK --check-prefix CHECK-64
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=45 -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-llvm %s -o - | FileCheck %s --check-prefix CHECK --check-prefix CHECK-64
 // RUN: %clang_cc1 -fopenmp -fopenmp-version=45 -x c++ -std=c++11 -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-pch -o %t %s
-// RUN: %clang_cc1 -fopenmp -fopenmp-version=45 -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck -allow-deprecated-dag-overlap  %s --check-prefix CHECK --check-prefix CHECK-64
-// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=45 -x c++ -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-llvm %s -o - | FileCheck -allow-deprecated-dag-overlap  %s --check-prefix CHECK --check-prefix CHECK-32
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=45 -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s --check-prefix CHECK --check-prefix CHECK-64
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=45 -x c++ -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-llvm %s -o - | FileCheck %s --check-prefix CHECK --check-prefix CHECK-32
 // RUN: %clang_cc1 -fopenmp -fopenmp-version=45 -x c++ -std=c++11 -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-pch -o %t %s
-// RUN: %clang_cc1 -fopenmp -fopenmp-version=45 -x c++ -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck -allow-deprecated-dag-overlap  %s --check-prefix CHECK --check-prefix CHECK-32
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=45 -x c++ -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s --check-prefix CHECK --check-prefix CHECK-32
 
-// RUN: %clang_cc1 -verify -fopenmp-simd -fopenmp-version=45 -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-llvm %s -o - | FileCheck -allow-deprecated-dag-overlap  --check-prefix SIMD-ONLY0 %s
+// RUN: %clang_cc1 -verify -fopenmp-simd -fopenmp-version=45 -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY0 %s
 // RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=45 -x c++ -std=c++11 -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-pch -o %t %s
-// RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=45 -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu 

[PATCH] D54764: [OpenMP] Update CHECK-DAG usage in for_codegen.cpp

2018-11-20 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev accepted this revision.
ABataev added a comment.
This revision is now accepted and ready to land.

I'm fine with the patch, the original intention was to handle a possible 
situation where we may have several debug locations with the same line numbers.


Repository:
  rC Clang

https://reviews.llvm.org/D54764



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


[PATCH] D54765: [OpenMP] Update CHECK-DAG usage in target_parallel_codegen.cpp

2018-11-20 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev accepted this revision.
ABataev added a comment.
This revision is now accepted and ready to land.

LG


Repository:
  rC Clang

https://reviews.llvm.org/D54765



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


[PATCH] D54768: Don't speculatively emit VTTs for classes unless we are able to correctly emit references to all the functions they will (directly or indirectly) reference.

2018-11-20 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith created this revision.
rsmith added a reviewer: rjmccall.
Herald added a subscriber: cfe-commits.

This fixes a miscompile where we'd emit a VTT for a class that ends up
referencing an inline virtual member function that we can't actually
emit a body for (because we never instantiated it in the current TU),
which in a corner case of a corner case can lead to link errors.


Repository:
  rC Clang

https://reviews.llvm.org/D54768

Files:
  lib/CodeGen/ItaniumCXXABI.cpp
  test/CodeGenCXX/speculative-vtt.cpp


Index: test/CodeGenCXX/speculative-vtt.cpp
===
--- /dev/null
+++ test/CodeGenCXX/speculative-vtt.cpp
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -triple x86_64-linux-gnu %s -O2 -disable-llvm-passes 
-emit-llvm -o - | FileCheck %s
+struct A { virtual ~A(); };
+template struct B : virtual A {
+  ~B() override {}
+};
+struct C : B, B { C(); ~C() override; };
+struct D : C { ~D() override; };
+
+// We must not create a reference to B::~B() here, because we're not 
going to emit it.
+// CHECK-NOT: @_ZN1BIiED1Ev
+// CHECK-NOT: @_ZTC1D0_1BIiE =
+// CHECK-NOT: @_ZTT1D = available_externally
+D *p = new D;
Index: lib/CodeGen/ItaniumCXXABI.cpp
===
--- lib/CodeGen/ItaniumCXXABI.cpp
+++ lib/CodeGen/ItaniumCXXABI.cpp
@@ -287,6 +287,7 @@
   void emitVirtualInheritanceTables(const CXXRecordDecl *RD) override;
 
   bool canSpeculativelyEmitVTable(const CXXRecordDecl *RD) const override;
+  bool canSpeculativelyEmitVTableAsBaseClass(const CXXRecordDecl *RD) const;
 
   void setThunkLinkage(llvm::Function *Thunk, bool ForVTable, GlobalDecl GD,
bool ReturnAdjustment) override {
@@ -1777,7 +1778,8 @@
   VTables.EmitVTTDefinition(VTT, CGM.getVTableLinkage(RD), RD);
 }
 
-bool ItaniumCXXABI::canSpeculativelyEmitVTable(const CXXRecordDecl *RD) const {
+bool ItaniumCXXABI::canSpeculativelyEmitVTableAsBaseClass(
+const CXXRecordDecl *RD) const {
   // We don't emit available_externally vtables if we are in -fapple-kext mode
   // because kext mode does not permit devirtualization.
   if (CGM.getLangOpts().AppleKext)
@@ -1795,7 +1797,43 @@
   // to emit an available_externally copy of vtable.
   // FIXME we can still emit a copy of the vtable if we
   // can emit definition of the inline functions.
-  return !hasAnyUnusedVirtualInlineFunction(RD);
+  if (hasAnyUnusedVirtualInlineFunction(RD))
+return false;
+
+  // For a class with virtual bases, we must also be able to speculatively
+  // emit the VTT, because CodeGen doesn't have separate notions of "can emit
+  // the vtable" and "can emit the VTT". For a base subobject, this means we
+  // need to be able to emit non-virtual base vtables.
+  if (RD->getNumVBases()) {
+for (const auto &B : RD->bases()) {
+  auto *BRD = B.getType()->getAsCXXRecordDecl();
+  assert(BRD && "no class for base specifier");
+  if (B.isVirtual() || !BRD->isDynamicClass())
+continue;
+  if (!canSpeculativelyEmitVTableAsBaseClass(BRD))
+return false;
+}
+  }
+
+  return true;
+}
+
+bool ItaniumCXXABI::canSpeculativelyEmitVTable(const CXXRecordDecl *RD) const {
+  if (!canSpeculativelyEmitVTableAsBaseClass(RD))
+return false;
+
+  // For a complete-object vtable (or more specifically, for the VTT), we need
+  // to be able to speculatively emit the vtables of all dynamic virtual bases.
+  for (const auto &B : RD->vbases()) {
+auto *BRD = B.getType()->getAsCXXRecordDecl();
+assert(BRD && "no class for base specifier");
+if (!BRD->isDynamicClass())
+  continue;
+if (!canSpeculativelyEmitVTableAsBaseClass(BRD))
+  return false;
+  }
+
+  return true;
 }
 static llvm::Value *performTypeAdjustment(CodeGenFunction &CGF,
   Address InitialPtr,


Index: test/CodeGenCXX/speculative-vtt.cpp
===
--- /dev/null
+++ test/CodeGenCXX/speculative-vtt.cpp
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -triple x86_64-linux-gnu %s -O2 -disable-llvm-passes -emit-llvm -o - | FileCheck %s
+struct A { virtual ~A(); };
+template struct B : virtual A {
+  ~B() override {}
+};
+struct C : B, B { C(); ~C() override; };
+struct D : C { ~D() override; };
+
+// We must not create a reference to B::~B() here, because we're not going to emit it.
+// CHECK-NOT: @_ZN1BIiED1Ev
+// CHECK-NOT: @_ZTC1D0_1BIiE =
+// CHECK-NOT: @_ZTT1D = available_externally
+D *p = new D;
Index: lib/CodeGen/ItaniumCXXABI.cpp
===
--- lib/CodeGen/ItaniumCXXABI.cpp
+++ lib/CodeGen/ItaniumCXXABI.cpp
@@ -287,6 +287,7 @@
   void emitVirtualInheritanceTables(const CXXRecordDecl *RD) override;
 
   bool canSpeculativelyEmitVTable(const CXXRecordDecl *RD) const override;
+  bool canSpeculativelyEmitVTableAsBaseClass(const CXXRecordDecl *RD) const;
 
   void setThunkLinkage(llvm::Function *

[PATCH] D54764: [OpenMP] Update CHECK-DAG usage in for_codegen.cpp

2018-11-20 Thread Joel E. Denny via Phabricator via cfe-commits
jdenny added a comment.

In https://reviews.llvm.org/D54764#1304573, @ABataev wrote:

> I'm fine with the patch,


Thanks for the quick reviews.  I'll push soon.

> the original intention was to handle a possible situation where we may have 
> several debug locations with the same line numbers.

We were afraid of that.  If we find we really need this use case, we'll have to 
find a nicer way to express it.  For reference, this use case is discussed 
under S1 here:

http://lists.llvm.org/pipermail/llvm-dev/2018-May/123258.html


Repository:
  rC Clang

https://reviews.llvm.org/D54764



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


[PATCH] D48866: [clang-tidy] Add incorrect-pointer-cast checker

2018-11-20 Thread Gábor Horváth via Phabricator via cfe-commits
hgabii marked 9 inline comments as done.
hgabii added a comment.

I resolved all comments.




Comment at: docs/ReleaseNotes.rst:60
 
+- New :doc:`misc-incorrect-pointer-cast
+  ` check

Eugene.Zelenko wrote:
> Will be good idea to rebase from trunk and use alphabetical order.
It is rebased. I could not see what should be in an alphabetical order. This is 
inserted to the top of the document by the //add_new_check.py//.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D48866



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


[PATCH] D54764: [OpenMP] Update CHECK-DAG usage in for_codegen.cpp

2018-11-20 Thread Alexey Bataev via Phabricator via cfe-commits
ABataev added a comment.

In https://reviews.llvm.org/D54764#1304606, @jdenny wrote:

> In https://reviews.llvm.org/D54764#1304573, @ABataev wrote:
>
> > I'm fine with the patch,
>
>
> Thanks for the quick reviews.  I'll push soon.
>
> > the original intention was to handle a possible situation where we may have 
> > several debug locations with the same line numbers.
>
> We were afraid of that.  If we find we really need this use case, we'll have 
> to find a nicer way to express it.  For reference, this use case is discussed 
> under S1 here:
>
> http://lists.llvm.org/pipermail/llvm-dev/2018-May/123258.html


Ok, got it. Thanks for the patch!


Repository:
  rC Clang

https://reviews.llvm.org/D54764



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


[PATCH] D48866: [clang-tidy] Add incorrect-pointer-cast checker

2018-11-20 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

`Warn for cases when the pointed to type is wider than the allocated type.`
What does that mean? Is this talking about the size of the allocation, or the 
alignment?

Are you aware of the previous attempts, namely https://reviews.llvm.org/D33826?
Please incorporate the tests from there.

Please add tests with casts (that should normally be diagnosed) from types with 
explicitly specified alignment, that silence the warning.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D48866



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


[PATCH] D53210: Revert 344389 "Revert r344375 "[Driver] check for exit code from SIGPIPE""

2018-11-20 Thread Nick Desaulniers via Phabricator via cfe-commits
nickdesaulniers added a comment.

Hi @richard.barton.arm , this has landed already.  If you click "show older" 
you'll see the UI element that shows this landed as r344536 (Oct 15 2018).  If 
your clang version is later than r344536 (what will become clang-8) and you 
still see this, please open a new bug.  The commit is definitely confusing; it 
looks like a revert, but it's a revert of a revert (double negative) which is 
relanding the patch.  The lld failures were PEBKAC on my part, unrelated to 
this patch.


Repository:
  rC Clang

https://reviews.llvm.org/D53210



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


[PATCH] D48866: [clang-tidy] Add incorrect-pointer-cast checker

2018-11-20 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: docs/ReleaseNotes.rst:60
 
+- New :doc:`misc-incorrect-pointer-cast
+  ` check

hgabii wrote:
> Eugene.Zelenko wrote:
> > Will be good idea to rebase from trunk and use alphabetical order.
> It is rebased. I could not see what should be in an alphabetical order. This 
> is inserted to the top of the document by the //add_new_check.py//.
List of new check should be sorted alphabetically. Unfortunately 
add_new_check.py doesn't do this, so manual edit is necessary.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D48866



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


[PATCH] D54395: [clang-tidy] implement utility-function to add 'const' to variables

2018-11-20 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth updated this revision to Diff 174828.
JonasToth added a comment.

add tests for different template instantiations


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D54395

Files:
  clang-tidy/performance/ForRangeCopyCheck.cpp
  clang-tidy/performance/UnnecessaryCopyInitialization.cpp
  clang-tidy/performance/UnnecessaryValueParamCheck.cpp
  clang-tidy/utils/FixItHintUtils.cpp
  clang-tidy/utils/FixItHintUtils.h
  clang-tidy/utils/LexerUtils.cpp
  clang-tidy/utils/LexerUtils.h
  unittests/clang-tidy/AddConstTest.cpp
  unittests/clang-tidy/CMakeLists.txt

Index: unittests/clang-tidy/CMakeLists.txt
===
--- unittests/clang-tidy/CMakeLists.txt
+++ unittests/clang-tidy/CMakeLists.txt
@@ -7,6 +7,7 @@
 include_directories(${CLANG_LINT_SOURCE_DIR})
 
 add_extra_unittest(ClangTidyTests
+  AddConstTest.cpp
   ClangTidyDiagnosticConsumerTest.cpp
   ClangTidyOptionsTest.cpp
   IncludeInserterTest.cpp
Index: unittests/clang-tidy/AddConstTest.cpp
===
--- /dev/null
+++ unittests/clang-tidy/AddConstTest.cpp
@@ -0,0 +1,857 @@
+#include "../clang-tidy/utils/FixItHintUtils.h"
+#include "ClangTidyTest.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Tooling/Tooling.h"
+#include "gtest/gtest.h"
+
+namespace clang {
+namespace tidy {
+
+namespace {
+using namespace clang::ast_matchers;
+using namespace utils::fixit;
+
+template 
+class ConstTransform : public ClangTidyCheck {
+public:
+  ConstTransform(StringRef CheckName, ClangTidyContext *Context)
+  : ClangTidyCheck(CheckName, Context) {}
+
+  void registerMatchers(MatchFinder *Finder) override {
+Finder->addMatcher(varDecl(hasName("target")).bind("var"), this);
+  }
+
+  void check(const MatchFinder::MatchResult &Result) override {
+const auto *D = Result.Nodes.getNodeAs("var");
+using utils::fixit::changeVarDeclToConst;
+Optional Fix = changeVarDeclToConst(*D, CT, CP, Result.Context);
+auto Diag = diag(D->getBeginLoc(), "doing const transformation");
+if (Fix)
+  Diag << *Fix;
+  }
+};
+} // namespace
+
+namespace test {
+using PointeeLTransform =
+ConstTransform;
+using PointeeRTransform =
+ConstTransform;
+
+using ValueLTransform = ConstTransform;
+using ValueRTransform = ConstTransform;
+
+// 
+// Test Value-like types. Everything with indirection is done later.
+// 
+
+// TODO: Template-code
+
+TEST(Values, Builtin) {
+  StringRef Snippet = "int target = 0;";
+
+  EXPECT_EQ("const int target = 0;", runCheckOnCode(Snippet));
+  EXPECT_EQ("const int target = 0;",
+runCheckOnCode(Snippet));
+
+  EXPECT_EQ("int const target = 0;", runCheckOnCode(Snippet));
+  EXPECT_EQ("int const target = 0;",
+runCheckOnCode(Snippet));
+}
+TEST(Values, TypedefBuiltin) {
+  StringRef T = "typedef int MyInt;";
+  StringRef S = "MyInt target = 0;";
+  auto Cat = [&T](StringRef S) { return (T + S).str(); };
+
+  EXPECT_EQ(Cat("const MyInt target = 0;"),
+runCheckOnCode(Cat(S)));
+  EXPECT_EQ(Cat("const MyInt target = 0;"),
+runCheckOnCode(Cat(S)));
+
+  EXPECT_EQ(Cat("MyInt const target = 0;"),
+runCheckOnCode(Cat(S)));
+  EXPECT_EQ(Cat("MyInt const target = 0;"),
+runCheckOnCode(Cat(S)));
+}
+TEST(Values, TypedefBuiltinPointer) {
+  StringRef T = "typedef int* MyInt;";
+  StringRef S = "MyInt target = nullptr;";
+  auto Cat = [&T](StringRef S) { return (T + S).str(); };
+
+  EXPECT_EQ(Cat("const MyInt target = nullptr;"),
+runCheckOnCode(Cat(S)));
+  EXPECT_EQ(Cat("const MyInt target = nullptr;"),
+runCheckOnCode(Cat(S)));
+
+  EXPECT_EQ(Cat("MyInt const target = nullptr;"),
+runCheckOnCode(Cat(S)));
+  EXPECT_EQ(Cat("MyInt const target = nullptr;"),
+runCheckOnCode(Cat(S)));
+}
+TEST(Values, AutoValue) {
+  StringRef T = "int f() { return 42; }\n";
+  StringRef S = "auto target = f();";
+  auto Cat = [&T](StringRef S) { return (T + S).str(); };
+
+  EXPECT_EQ(Cat("const auto target = f();"),
+runCheckOnCode(Cat(S)));
+  EXPECT_EQ(Cat("const auto target = f();"),
+runCheckOnCode(Cat(S)));
+
+  EXPECT_EQ(Cat("auto const target = f();"),
+runCheckOnCode(Cat(S)));
+  EXPECT_EQ(Cat("auto const target = f();"),
+runCheckOnCode(Cat(S)));
+}
+TEST(Values, AutoPointer) {
+  StringRef T = "int* f() { return nullptr; }\n";
+  StringRef S = "auto target = f();";
+  auto Cat = [&T](StringRef S) { return (T + S).str(); };
+
+  EXPECT_EQ(Cat("const auto target = f();"),
+runCheckOnCode(Cat(S)));
+  EXPECT_EQ(Cat("const auto target = f();"),
+runCheckOnCode(Cat(S)));
+
+  EXPECT_EQ(Cat("auto const target = f();"),
+

[PATCH] D54395: [clang-tidy] implement utility-function to add 'const' to variables

2018-11-20 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth added inline comments.



Comment at: unittests/clang-tidy/AddConstTest.cpp:733
+  StringRef T = "template  void f(T v) \n";
+  StringRef S = "{ T target = v; }";
+  auto Cat = [&T](StringRef S) { return (T + S).str(); };

alexfh wrote:
> It would be interesting to see test cases with multiple instantiations of the 
> template the fix applies to.
I added test for a template function with many instantiations, but there should 
not be a difference between the instantiations, because only the original code 
would be transformed, and there the 'how it looks' counts, so in this case it 
will be treated as a value.
Did I misinterpret your question?


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D54395



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


[PATCH] D54745: [clang-tidy] Don't generate incorrect fixes for class with deleted copy constructor in smart_ptr check.

2018-11-20 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth added a comment.

IMHO this patch is fine, but i think a language expert (not me :D) should take 
a look (@aaron.ballman ?) as its complicated :)


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D54745



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


[PATCH] D52311: [clangd] Add support for hierarchical documentSymbol

2018-11-20 Thread Sam McCall via Phabricator via cfe-commits
sammccall added a comment.

Very nice! Mostly just a few style/structure nits.




Comment at: clangd/AST.cpp:69
+std::string printName(const NamedDecl &ND) {
+  const NamedDecl *NameSource = &ND;
+  std::string Name = llvm::to_string(NameSource->getDeclName());

just use ND?



Comment at: clangd/ClangdLSPServer.cpp:28
+/// Used by the clients that do not support the hierarchical view.
+static std::vector
+flattenDocumentSymbols(llvm::ArrayRef Symbols,

move this nearer the call site?



Comment at: clangd/ClangdLSPServer.cpp:29
+static std::vector
+flattenDocumentSymbols(llvm::ArrayRef Symbols,
+   const URIForFile &FileURI) {

or flattenSymbolHierarchy?



Comment at: clangd/ClangdLSPServer.cpp:31
+   const URIForFile &FileURI) {
+  // A helper struct to keep the state for recursive processing, computes
+  // results on construction.

auto-typed lambdas can't be recursive, but std::function shouldn't be too slow 
here? And clearer I think:

```
vector Results;
std::function Process = [&](const 
DocumentSymbol &Sym, StringRef ParentName) {
  ...
};
for (const auto& TopLevel : Symbols)
  Process(TopLevel);
return Results;
```

failing that, I found this pattern confusing - I'd suggest either making it a 
recursive plain function, or a standard functor object as if it were a lambda 
(with the recursive call being `operator()`)



Comment at: clangd/ClangdLSPServer.cpp:44
+  private:
+void process(const DocumentSymbol &S, llvm::StringRef ParentName) {
+  SymbolInformation SI;

nit: optional for parent name seems slightly neater



Comment at: clangd/FindSymbols.cpp:190
+  index::SymbolInfo SymInfo = index::getSymbolInfo(&ND);
+  SymbolKind SK = indexSymbolKindToSymbolKind(SymInfo.Kind);
 

may want to add a FIXME here: per the tests, it's not classifying 
constructor/destructor/operator correctly (they're all "methods").

cons/dest is just indexSymbolKindToSymbolKind needing an update, but operator 
isn't represented in index::SymbolKind.
Maybe we should stop using index::SymbolKind entirely, it doesn't appear to be 
great.



Comment at: clangd/FindSymbols.cpp:208
+std::vector collectDocSymbols(ParsedAST &AST) {
+  struct CollectSymbols {
+CollectSymbols(ParsedAST &AST, std::vector &Results)

this class seems maybe too long to live inside this function. (I wouldn't worry 
about it being visible to other stuff, the file is small and focused)



Comment at: clangd/FindSymbols.cpp:208
+std::vector collectDocSymbols(ParsedAST &AST) {
+  struct CollectSymbols {
+CollectSymbols(ParsedAST &AST, std::vector &Results)

sammccall wrote:
> this class seems maybe too long to live inside this function. (I wouldn't 
> worry about it being visible to other stuff, the file is small and focused)
(this looks more like a class than a struct?)



Comment at: clangd/FindSymbols.cpp:208
+std::vector collectDocSymbols(ParsedAST &AST) {
+  struct CollectSymbols {
+CollectSymbols(ParsedAST &AST, std::vector &Results)

sammccall wrote:
> sammccall wrote:
> > this class seems maybe too long to live inside this function. (I wouldn't 
> > worry about it being visible to other stuff, the file is small and focused)
> (this looks more like a class than a struct?)
should this be a RecursiveASTVisitor?
I guess not, but please explain why (there's no documentation on the 
implementation strategy, and it's complicated)



Comment at: clangd/FindSymbols.cpp:211
+: Ctx(AST.getASTContext()) {
+  for (auto &TopLevel : AST.getLocalTopLevelDecls())
+traverseDecl(TopLevel, Results);

again, doing the work in the constructor is a bit odd - own the data and expose 
it?



Comment at: clangd/FindSymbols.cpp:253
 
-SymbolInformation SI;
-SI.name = Name;
-SI.kind = SK;
-SI.location = L;
-SI.containerName = Scope;
-Symbols.push_back(std::move(SI));
-return true;
-  }
-};
-} // namespace
+VisitKind shouldVisit(Decl* D) {
+  if (D->isImplicit())

we only consider visiting named decls, maybe reflect that here?
(not needed now but may allow future refinement)



Comment at: clangd/FindSymbols.cpp:264
+// ignored.
+if (auto *Info = Func->getTemplateSpecializationInfo()) {
+  if (!Info->isExplicitInstantiationOrSpecialization())

isn't this covered by D->isImplicit?



Comment at: clangd/FindSymbols.cpp:276
+  // children.
+  //   - implicit instantiations, i.e. not written by the user.
+  // Do not visit at all, they are not present in the code.

isn't this covered by D->isImplicit() above?


=

[PATCH] D53891: [LTO] Pass down LTOUnit codegen flag to bitcode writer

2018-11-20 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson updated this revision to Diff 174835.
tejohnson added a comment.

Update to use new module flag


Repository:
  rC Clang

https://reviews.llvm.org/D53891

Files:
  include/clang/Driver/Options.td
  include/clang/Driver/SanitizerArgs.h
  include/clang/Frontend/CodeGenOptions.def
  lib/CodeGen/BackendUtil.cpp
  lib/Driver/SanitizerArgs.cpp
  lib/Driver/ToolChains/Clang.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/CodeGenCXX/no-lto-unit.cpp
  test/CodeGenCXX/type-metadata-thinlto.cpp
  test/Driver/split-lto-unit.c

Index: test/Driver/split-lto-unit.c
===
--- /dev/null
+++ test/Driver/split-lto-unit.c
@@ -0,0 +1,8 @@
+// RUN: %clang -target x86_64-unknown-linux -### %s -flto=thin 2>&1 | FileCheck --check-prefix=NOUNIT %s
+// RUN: %clang -target x86_64-unknown-linux -### %s -flto=thin -fsplit-lto-unit 2>&1 | FileCheck --check-prefix=UNIT %s
+// RUN: %clang -target x86_64-unknown-linux -### %s -flto=thin -fno-split-lto-unit 2>&1 | FileCheck --check-prefix=NOUNIT %s
+// RUN: %clang -target x86_64-unknown-linux -### %s -flto=thin -fno-split-lto-unit -fwhole-program-vtables 2>&1 | FileCheck --check-prefix=UNIT %s
+// RUN: %clang -target x86_64-unknown-linux -### %s -flto=thin -fno-split-lto-unit -fsanitize=cfi 2>&1 | FileCheck --check-prefix=UNIT %s
+
+// UNIT: "-fsplit-lto-unit"
+// NOUNIT-NOT: "-fsplit-lto-unit"
Index: test/CodeGenCXX/type-metadata-thinlto.cpp
===
--- test/CodeGenCXX/type-metadata-thinlto.cpp
+++ test/CodeGenCXX/type-metadata-thinlto.cpp
@@ -1,5 +1,7 @@
-// RUN: %clang_cc1 -flto=thin -flto-unit -triple x86_64-unknown-linux -fvisibility hidden -emit-llvm-bc -o %t %s
+// RUN: %clang_cc1 -flto=thin -flto-unit -fsplit-lto-unit -triple x86_64-unknown-linux -fvisibility hidden -emit-llvm-bc -o %t %s
 // RUN: llvm-modextract -o - -n 1 %t | llvm-dis | FileCheck %s
+// RUN: llvm-modextract -b -o - -n 1 %t | llvm-bcanalyzer -dump | FileCheck %s --check-prefix=LTOUNIT
+// LTOUNIT: 
 
 // CHECK: @_ZTV1A = linkonce_odr
 class A {
Index: test/CodeGenCXX/no-lto-unit.cpp
===
--- test/CodeGenCXX/no-lto-unit.cpp
+++ test/CodeGenCXX/no-lto-unit.cpp
@@ -2,6 +2,8 @@
 // RUN: llvm-dis -o - %t | FileCheck %s
 // RUN: %clang_cc1 -flto=thin -flto-unit -fno-lto-unit -triple x86_64-unknown-linux -fvisibility hidden -emit-llvm-bc -o %t %s
 // RUN: llvm-dis -o - %t | FileCheck %s
+// RUN: llvm-bcanalyzer -dump %t | FileCheck %s --check-prefix=NOLTOUNIT
+// NOLTOUNIT: 
 
 // CHECK-NOT: !type
 class A {
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -793,6 +793,7 @@
   Diags.Report(diag::err_drv_invalid_value) << A->getAsString(Args) << S;
   }
   Opts.LTOUnit = Args.hasFlag(OPT_flto_unit, OPT_fno_lto_unit, false);
+  Opts.EnableSplitLTOUnit = Args.hasArg(OPT_fsplit_lto_unit);
   if (Arg *A = Args.getLastArg(OPT_fthinlto_index_EQ)) {
 if (IK.getLanguage() != InputKind::LLVM_IR)
   Diags.Report(diag::err_drv_argument_only_allowed_with)
Index: lib/Driver/ToolChains/Clang.cpp
===
--- lib/Driver/ToolChains/Clang.cpp
+++ lib/Driver/ToolChains/Clang.cpp
@@ -5108,6 +5108,12 @@
 CmdArgs.push_back("-fwhole-program-vtables");
   }
 
+  bool EnableSplitLTOUnit = Args.hasFlag(
+  options::OPT_fsplit_lto_unit, options::OPT_fno_split_lto_unit, false);
+  if (EnableSplitLTOUnit || WholeProgramVTables || Sanitize.needsLTO()) {
+CmdArgs.push_back("-fsplit-lto-unit");
+  }
+
   if (Arg *A = Args.getLastArg(options::OPT_fexperimental_isel,
options::OPT_fno_experimental_isel)) {
 CmdArgs.push_back("-mllvm");
Index: lib/Driver/SanitizerArgs.cpp
===
--- lib/Driver/SanitizerArgs.cpp
+++ lib/Driver/SanitizerArgs.cpp
@@ -207,6 +207,8 @@
   return Sanitizers.Mask & NeedsUnwindTables;
 }
 
+bool SanitizerArgs::needsLTO() const { return Sanitizers.Mask & NeedsLTO; }
+
 SanitizerArgs::SanitizerArgs(const ToolChain &TC,
  const llvm::opt::ArgList &Args) {
   SanitizerMask AllRemove = 0;  // During the loop below, the accumulated set of
Index: lib/CodeGen/BackendUtil.cpp
===
--- lib/CodeGen/BackendUtil.cpp
+++ lib/CodeGen/BackendUtil.cpp
@@ -807,6 +807,8 @@
 if (!ThinLinkOS)
   return;
   }
+  TheModule->addModuleFlag(Module::Error, "EnableSplitLTOUnit",
+   CodeGenOpts.EnableSplitLTOUnit);
   PerModulePasses.add(createWriteThinLTOBitcodePass(
   *OS, ThinLinkOS ? &ThinLinkOS->os() : nullptr));
 } else {
@@ -817,12 +819,16 @@
!CodeGenOpts.DisableLLVMPasses &

[PATCH] D54565: Introduce `-Wc++14-compat-ctad` as a subgroup of `-Wc++14-compat`

2018-11-20 Thread Richard Smith - zygoloid via Phabricator via cfe-commits
rsmith added a comment.

In the past, we've been resistant to adding more fine-grained compat warnings, 
because we don't want to encourage subsetting the language (which sounds like 
exactly what you're trying to do here). We generally don't think it's Clang's 
business to enforce coding style conventions (such as "don't use CTAD because 
it makes your code less readable"), but we do consider it to be in-scope for 
Clang to warn on constructs that are error-prone or that have a negative impact 
on portability or compatibility, and so on. On that basis, I think there is a 
case to be made for warning on this specific language feature, because using 
CTAD on class templates that weren't designed for it is dangerous and creates 
source compatibility problems for future changes to that library.

However, if we consider the goal to be to warn only on using CTAD in places 
where the class template author didn't design for it, then:

- this should be a separate warning, not a subgroup of `-Wc++14-compat`
- the warning should be suppressed by any explicitly-declared deduction guides 
for the class
- there should be some fairly obvious way to suppress the warning in the case 
where the deduction guides implied by the constructors already do the right 
thing (maybe an attribute?)

What do you think? Would that cover the use case you're trying to address here, 
or are you really trying to enforce a style rule of "don't use CTAD ever"?


Repository:
  rC Clang

https://reviews.llvm.org/D54565



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


[PATCH] D53524: [ThinLTO] Enable LTOUnit only when it is needed

2018-11-20 Thread Teresa Johnson via Phabricator via cfe-commits
tejohnson abandoned this revision.
tejohnson added a comment.

Abandoned in favor of new approach in 
https://reviews.llvm.org/D53890/https://reviews.llvm.org/D53891.


Repository:
  rC Clang

https://reviews.llvm.org/D53524



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


r347350 - [OpenMP] Update CHECK-DAG usage in for_codegen.cpp

2018-11-20 Thread Joel E. Denny via cfe-commits
Author: jdenny
Date: Tue Nov 20 14:04:45 2018
New Revision: 347350

URL: http://llvm.org/viewvc/llvm-project?rev=347350&view=rev
Log:
[OpenMP] Update CHECK-DAG usage in for_codegen.cpp

This patch adjusts a test not to depend on deprecated FileCheck
behavior that permits overlapping matches within a block of CHECK-DAG
directives.  Thus, this patch also removes uses of FileCheck's
-allow-deprecated-dag-overlap command-line option.

Specifically, the FileCheck variables DBG_LOC_START, DBG_LOC_END, and
DBG_LOC_CANCEL were all set to the same value.  As a result, three
TERM_DEBUG-DAG patterns, one for each variable, all matched the same
text under the old overlapping behavior.  Under the new
non-overlapping behavior, that's not permitted.  This patch's solution
is to replace these variables with one variable and replace these
patterns with one pattern.

Reviewed By: ABataev

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

Modified:
cfe/trunk/test/OpenMP/for_codegen.cpp

Modified: cfe/trunk/test/OpenMP/for_codegen.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/for_codegen.cpp?rev=347350&r1=347349&r2=347350&view=diff
==
--- cfe/trunk/test/OpenMP/for_codegen.cpp (original)
+++ cfe/trunk/test/OpenMP/for_codegen.cpp Tue Nov 20 14:04:45 2018
@@ -1,14 +1,14 @@
-// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple x86_64-unknown-unknown 
-emit-llvm %s -fexceptions -fcxx-exceptions -o - 
-fsanitize-address-use-after-scope | FileCheck -allow-deprecated-dag-overlap %s 
--check-prefix=CHECK --check-prefix=LIFETIME
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple x86_64-unknown-unknown 
-emit-llvm %s -fexceptions -fcxx-exceptions -o - 
-fsanitize-address-use-after-scope | FileCheck %s --check-prefix=CHECK 
--check-prefix=LIFETIME
 // RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple x86_64-unknown-unknown 
-fexceptions -fcxx-exceptions -emit-pch -o %t %s
-// RUN: %clang_cc1 -fopenmp -x c++ -triple x86_64-unknown-unknown -fexceptions 
-fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | 
FileCheck -allow-deprecated-dag-overlap %s
-// RUN: %clang_cc1 -verify -triple x86_64-apple-darwin10 -fopenmp -fexceptions 
-fcxx-exceptions -debug-info-kind=line-tables-only -x c++ -emit-llvm %s -o - | 
FileCheck -allow-deprecated-dag-overlap %s --check-prefix=TERM_DEBUG
-// RUN: %clang_cc1 -main-file-name for_codegen.cpp %s -o - -emit-llvm 
-fprofile-instrument=clang -fprofile-instrument-path=for_codegen-test.profraw | 
FileCheck -allow-deprecated-dag-overlap %s --check-prefix=PROF-INSTR-PATH
+// RUN: %clang_cc1 -fopenmp -x c++ -triple x86_64-unknown-unknown -fexceptions 
-fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | 
FileCheck %s
+// RUN: %clang_cc1 -verify -triple x86_64-apple-darwin10 -fopenmp -fexceptions 
-fcxx-exceptions -debug-info-kind=line-tables-only -x c++ -emit-llvm %s -o - | 
FileCheck %s --check-prefix=TERM_DEBUG
+// RUN: %clang_cc1 -main-file-name for_codegen.cpp %s -o - -emit-llvm 
-fprofile-instrument=clang -fprofile-instrument-path=for_codegen-test.profraw | 
FileCheck %s --check-prefix=PROF-INSTR-PATH
 
-// RUN: %clang_cc1 -verify -fopenmp-simd -x c++ -triple x86_64-unknown-unknown 
-emit-llvm %s -fexceptions -fcxx-exceptions -o - | FileCheck 
-allow-deprecated-dag-overlap --check-prefix SIMD-ONLY0 %s
+// RUN: %clang_cc1 -verify -fopenmp-simd -x c++ -triple x86_64-unknown-unknown 
-emit-llvm %s -fexceptions -fcxx-exceptions -o - | FileCheck --check-prefix 
SIMD-ONLY0 %s
 // RUN: %clang_cc1 -fopenmp-simd -x c++ -std=c++11 -triple 
x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s
-// RUN: %clang_cc1 -fopenmp-simd -x c++ -triple x86_64-unknown-unknown 
-fexceptions -fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm 
-o - | FileCheck -allow-deprecated-dag-overlap --check-prefix SIMD-ONLY0 %s
-// RUN: %clang_cc1 -verify -triple x86_64-apple-darwin10 -fopenmp-simd 
-fexceptions -fcxx-exceptions -debug-info-kind=line-tables-only -x c++ 
-emit-llvm %s -o - | FileCheck -allow-deprecated-dag-overlap --check-prefix 
SIMD-ONLY0 %s
-// RUN: %clang_cc1 -main-file-name for_codegen.cpp %s -o - -emit-llvm 
-fprofile-instrument=clang -fprofile-instrument-path=for_codegen-test.profraw | 
FileCheck -allow-deprecated-dag-overlap --check-prefix SIMD-ONLY0 %s
+// RUN: %clang_cc1 -fopenmp-simd -x c++ -triple x86_64-unknown-unknown 
-fexceptions -fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm 
-o - | FileCheck --check-prefix SIMD-ONLY0 %s
+// RUN: %clang_cc1 -verify -triple x86_64-apple-darwin10 -fopenmp-simd 
-fexceptions -fcxx-exceptions -debug-info-kind=line-tables-only -x c++ 
-emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY0 %s
+// RUN: %clang_cc1 -main-file-name for_codegen.cpp %s -o - -emit-llvm 
-fprofile-instrument=clang -fprofile-instrument-path=for_codegen-test.profraw | 
FileCheck --check-prefix SIMD-ONLY0 %s
 // SI

[PATCH] D54765: [OpenMP] Update CHECK-DAG usage in target_parallel_codegen.cpp

2018-11-20 Thread Joel E. Denny via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC347351: [OpenMP] Update CHECK-DAG usage in 
target_parallel_codegen.cpp (authored by jdenny, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D54765?vs=174817&id=174837#toc

Repository:
  rC Clang

https://reviews.llvm.org/D54765

Files:
  test/OpenMP/target_parallel_codegen.cpp

Index: test/OpenMP/target_parallel_codegen.cpp
===
--- test/OpenMP/target_parallel_codegen.cpp
+++ test/OpenMP/target_parallel_codegen.cpp
@@ -1,37 +1,37 @@
 // Test host codegen.
-// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=45 -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-llvm %s -o - | FileCheck -allow-deprecated-dag-overlap  %s --check-prefix CHECK --check-prefix CHECK-64
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=45 -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-llvm %s -o - | FileCheck %s --check-prefix CHECK --check-prefix CHECK-64
 // RUN: %clang_cc1 -fopenmp -fopenmp-version=45 -x c++ -std=c++11 -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-pch -o %t %s
-// RUN: %clang_cc1 -fopenmp -fopenmp-version=45 -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck -allow-deprecated-dag-overlap  %s --check-prefix CHECK --check-prefix CHECK-64
-// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=45 -x c++ -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-llvm %s -o - | FileCheck -allow-deprecated-dag-overlap  %s --check-prefix CHECK --check-prefix CHECK-32
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=45 -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s --check-prefix CHECK --check-prefix CHECK-64
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=45 -x c++ -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-llvm %s -o - | FileCheck %s --check-prefix CHECK --check-prefix CHECK-32
 // RUN: %clang_cc1 -fopenmp -fopenmp-version=45 -x c++ -std=c++11 -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-pch -o %t %s
-// RUN: %clang_cc1 -fopenmp -fopenmp-version=45 -x c++ -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck -allow-deprecated-dag-overlap  %s --check-prefix CHECK --check-prefix CHECK-32
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=45 -x c++ -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s --check-prefix CHECK --check-prefix CHECK-32
 
-// RUN: %clang_cc1 -verify -fopenmp-simd -fopenmp-version=45 -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-llvm %s -o - | FileCheck -allow-deprecated-dag-overlap  --check-prefix SIMD-ONLY0 %s
+// RUN: %clang_cc1 -verify -fopenmp-simd -fopenmp-version=45 -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY0 %s
 // RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=45 -x c++ -std=c++11 -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -emit-pch -o %t %s
-// RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=45 -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck -allow-deprecated-dag-overlap  --check-prefix SIMD-ONLY0 %s
-// RUN: %clang_cc1 -verify -fopenmp-simd -fopenmp-version=45 -x c++ -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-llvm %s -o - | FileCheck -allow-deprecated-dag-overlap  --check-prefix SIMD-ONLY0 %s
+// RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=45 -x c++ -triple powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck --check-prefix SIMD-ONLY0 %s
+// RUN: %clang_cc1 -verify -fopenmp-simd -fopenmp-version=45 -x c++ -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY0 %s
 // RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=45 -x c++ -std=c++11 -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-pch -o %t %s
-// RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=45 -x c++ -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck -allow-deprecated-dag-overlap  --check-prefix SIMD-ONLY0 %s
+// RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=45 -x c++ -triple i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -std=c++11 -include-pch %t -ve

[PATCH] D54764: [OpenMP] Update CHECK-DAG usage in for_codegen.cpp

2018-11-20 Thread Joel E. Denny via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC347350: [OpenMP] Update CHECK-DAG usage in for_codegen.cpp 
(authored by jdenny, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D54764?vs=174816&id=174836#toc

Repository:
  rC Clang

https://reviews.llvm.org/D54764

Files:
  test/OpenMP/for_codegen.cpp


Index: test/OpenMP/for_codegen.cpp
===
--- test/OpenMP/for_codegen.cpp
+++ test/OpenMP/for_codegen.cpp
@@ -1,14 +1,14 @@
-// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple x86_64-unknown-unknown 
-emit-llvm %s -fexceptions -fcxx-exceptions -o - 
-fsanitize-address-use-after-scope | FileCheck -allow-deprecated-dag-overlap %s 
--check-prefix=CHECK --check-prefix=LIFETIME
+// RUN: %clang_cc1 -verify -fopenmp -x c++ -triple x86_64-unknown-unknown 
-emit-llvm %s -fexceptions -fcxx-exceptions -o - 
-fsanitize-address-use-after-scope | FileCheck %s --check-prefix=CHECK 
--check-prefix=LIFETIME
 // RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -triple x86_64-unknown-unknown 
-fexceptions -fcxx-exceptions -emit-pch -o %t %s
-// RUN: %clang_cc1 -fopenmp -x c++ -triple x86_64-unknown-unknown -fexceptions 
-fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | 
FileCheck -allow-deprecated-dag-overlap %s
-// RUN: %clang_cc1 -verify -triple x86_64-apple-darwin10 -fopenmp -fexceptions 
-fcxx-exceptions -debug-info-kind=line-tables-only -x c++ -emit-llvm %s -o - | 
FileCheck -allow-deprecated-dag-overlap %s --check-prefix=TERM_DEBUG
-// RUN: %clang_cc1 -main-file-name for_codegen.cpp %s -o - -emit-llvm 
-fprofile-instrument=clang -fprofile-instrument-path=for_codegen-test.profraw | 
FileCheck -allow-deprecated-dag-overlap %s --check-prefix=PROF-INSTR-PATH
+// RUN: %clang_cc1 -fopenmp -x c++ -triple x86_64-unknown-unknown -fexceptions 
-fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm -o - | 
FileCheck %s
+// RUN: %clang_cc1 -verify -triple x86_64-apple-darwin10 -fopenmp -fexceptions 
-fcxx-exceptions -debug-info-kind=line-tables-only -x c++ -emit-llvm %s -o - | 
FileCheck %s --check-prefix=TERM_DEBUG
+// RUN: %clang_cc1 -main-file-name for_codegen.cpp %s -o - -emit-llvm 
-fprofile-instrument=clang -fprofile-instrument-path=for_codegen-test.profraw | 
FileCheck %s --check-prefix=PROF-INSTR-PATH
 
-// RUN: %clang_cc1 -verify -fopenmp-simd -x c++ -triple x86_64-unknown-unknown 
-emit-llvm %s -fexceptions -fcxx-exceptions -o - | FileCheck 
-allow-deprecated-dag-overlap --check-prefix SIMD-ONLY0 %s
+// RUN: %clang_cc1 -verify -fopenmp-simd -x c++ -triple x86_64-unknown-unknown 
-emit-llvm %s -fexceptions -fcxx-exceptions -o - | FileCheck --check-prefix 
SIMD-ONLY0 %s
 // RUN: %clang_cc1 -fopenmp-simd -x c++ -std=c++11 -triple 
x86_64-unknown-unknown -fexceptions -fcxx-exceptions -emit-pch -o %t %s
-// RUN: %clang_cc1 -fopenmp-simd -x c++ -triple x86_64-unknown-unknown 
-fexceptions -fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm 
-o - | FileCheck -allow-deprecated-dag-overlap --check-prefix SIMD-ONLY0 %s
-// RUN: %clang_cc1 -verify -triple x86_64-apple-darwin10 -fopenmp-simd 
-fexceptions -fcxx-exceptions -debug-info-kind=line-tables-only -x c++ 
-emit-llvm %s -o - | FileCheck -allow-deprecated-dag-overlap --check-prefix 
SIMD-ONLY0 %s
-// RUN: %clang_cc1 -main-file-name for_codegen.cpp %s -o - -emit-llvm 
-fprofile-instrument=clang -fprofile-instrument-path=for_codegen-test.profraw | 
FileCheck -allow-deprecated-dag-overlap --check-prefix SIMD-ONLY0 %s
+// RUN: %clang_cc1 -fopenmp-simd -x c++ -triple x86_64-unknown-unknown 
-fexceptions -fcxx-exceptions -std=c++11 -include-pch %t -verify %s -emit-llvm 
-o - | FileCheck --check-prefix SIMD-ONLY0 %s
+// RUN: %clang_cc1 -verify -triple x86_64-apple-darwin10 -fopenmp-simd 
-fexceptions -fcxx-exceptions -debug-info-kind=line-tables-only -x c++ 
-emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY0 %s
+// RUN: %clang_cc1 -main-file-name for_codegen.cpp %s -o - -emit-llvm 
-fprofile-instrument=clang -fprofile-instrument-path=for_codegen-test.profraw | 
FileCheck --check-prefix SIMD-ONLY0 %s
 // SIMD-ONLY0-NOT: {{__kmpc|__tgt}}
 //
 // expected-no-diagnostics
@@ -385,22 +385,20 @@
 #pragma omp parallel
 #pragma omp for schedule(static, 5)
   // TERM_DEBUG-NOT: __kmpc_global_thread_num
-  // TERM_DEBUG: call void @__kmpc_for_static_init_4u({{.+}}), !dbg 
[[DBG_LOC_START:![0-9]+]]
+  // TERM_DEBUG: call void @__kmpc_for_static_init_4u({{.+}}), !dbg 
[[DBG_LOC:![0-9]+]]
   // TERM_DEBUG: invoke i32 {{.*}}foo{{.*}}()
   // TERM_DEBUG: unwind label %[[TERM_LPAD:.+]],
   // TERM_DEBUG-NOT: __kmpc_global_thread_num
-  // TERM_DEBUG: call void @__kmpc_for_static_fini({{.+}}), !dbg 
[[DBG_LOC_END:![0-9]+]]
-  // TERM_DEBUG: call {{.+}} @__kmpc_barrier({{.+}}), !dbg 
[[DBG_LOC_CANCEL:![0-9]+]]
+  // TERM_DEBUG: call void @__kmpc_for_static_fini({{.+}}), !dbg 
[[DBG_LOC]]
+  // TERM_DEBUG

r347351 - [OpenMP] Update CHECK-DAG usage in target_parallel_codegen.cpp

2018-11-20 Thread Joel E. Denny via cfe-commits
Author: jdenny
Date: Tue Nov 20 14:05:23 2018
New Revision: 347351

URL: http://llvm.org/viewvc/llvm-project?rev=347351&view=rev
Log:
[OpenMP] Update CHECK-DAG usage in target_parallel_codegen.cpp

This patch adjusts a test not to depend on deprecated FileCheck
behavior that permits overlapping matches within a block of CHECK-DAG
directives.  Thus, this patch also removes uses of FileCheck's
-allow-deprecated-dag-overlap command-line option.

There were two issues in this test:

1. There were sets of patterns for store instructions in which a
pattern X could match a superset of a pattern Y.  While X appeared
before Y, Y's intended match appeared before X's intended match.  The
result was that X matched Y's intended match.  Under the old
overlapping behavior, Y also matched Y's intended match.  Under the
new non-overlapping behavior, Y had nothing left to match.  This patch
fixes this by gathering these sets in one place and putting the most
specific patterns (Y) before the more general patterns (X).

2. The CHECK-DAG patterns involving the variables CBPADDR3 and
CBPADDR4 were the same, but there was only one match in the text, so
CBPADDR4 patterns had nothing to match under the new non-overlapping
behavior.  Moreover, a preceding related series of directives had
variables (SADDR0, BPADDR0, etc.) numbered only 0 through 4, but this
series had variables numbered 0 through 5.  Assuming CBPADDR4's
directives were not intended, this patch removes them.

Reviewed By: ABataev

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

Modified:
cfe/trunk/test/OpenMP/target_parallel_codegen.cpp

Modified: cfe/trunk/test/OpenMP/target_parallel_codegen.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/OpenMP/target_parallel_codegen.cpp?rev=347351&r1=347350&r2=347351&view=diff
==
--- cfe/trunk/test/OpenMP/target_parallel_codegen.cpp (original)
+++ cfe/trunk/test/OpenMP/target_parallel_codegen.cpp Tue Nov 20 14:05:23 2018
@@ -1,37 +1,37 @@
 // Test host codegen.
-// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=45 -x c++ -triple 
powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu 
-emit-llvm %s -o - | FileCheck -allow-deprecated-dag-overlap  %s --check-prefix 
CHECK --check-prefix CHECK-64
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=45 -x c++ -triple 
powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu 
-emit-llvm %s -o - | FileCheck %s --check-prefix CHECK --check-prefix CHECK-64
 // RUN: %clang_cc1 -fopenmp -fopenmp-version=45 -x c++ -std=c++11 -triple 
powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu 
-emit-pch -o %t %s
-// RUN: %clang_cc1 -fopenmp -fopenmp-version=45 -x c++ -triple 
powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu 
-std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck 
-allow-deprecated-dag-overlap  %s --check-prefix CHECK --check-prefix CHECK-64
-// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=45 -x c++ -triple 
i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-llvm %s -o - | 
FileCheck -allow-deprecated-dag-overlap  %s --check-prefix CHECK --check-prefix 
CHECK-32
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=45 -x c++ -triple 
powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu 
-std=c++11 -include-pch %t -verify %s -emit-llvm -o - | FileCheck %s 
--check-prefix CHECK --check-prefix CHECK-64
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=45 -x c++ -triple 
i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-llvm %s -o - | 
FileCheck %s --check-prefix CHECK --check-prefix CHECK-32
 // RUN: %clang_cc1 -fopenmp -fopenmp-version=45 -x c++ -std=c++11 -triple 
i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -emit-pch -o %t %s
-// RUN: %clang_cc1 -fopenmp -fopenmp-version=45 -x c++ -triple 
i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -std=c++11 -include-pch 
%t -verify %s -emit-llvm -o - | FileCheck -allow-deprecated-dag-overlap  %s 
--check-prefix CHECK --check-prefix CHECK-32
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=45 -x c++ -triple 
i386-unknown-unknown -fopenmp-targets=i386-pc-linux-gnu -std=c++11 -include-pch 
%t -verify %s -emit-llvm -o - | FileCheck %s --check-prefix CHECK 
--check-prefix CHECK-32
 
-// RUN: %clang_cc1 -verify -fopenmp-simd -fopenmp-version=45 -x c++ -triple 
powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu 
-emit-llvm %s -o - | FileCheck -allow-deprecated-dag-overlap  --check-prefix 
SIMD-ONLY0 %s
+// RUN: %clang_cc1 -verify -fopenmp-simd -fopenmp-version=45 -x c++ -triple 
powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu 
-emit-llvm %s -o - | FileCheck --check-prefix SIMD-ONLY0 %s
 // RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=45 -x c++ -std=c++11 -triple 
powerpc64le-unknown-unknown -fopenmp-targets=powerpc64le-ibm-linux-gnu 
-emit-pch -o %t %s
-// RUN: %cl

r347352 - [CodeComplete] Penalize inherited ObjC properties for auto-completion

2018-11-20 Thread Sam McCall via cfe-commits
Author: sammccall
Date: Tue Nov 20 14:06:54 2018
New Revision: 347352

URL: http://llvm.org/viewvc/llvm-project?rev=347352&view=rev
Log:
[CodeComplete] Penalize inherited ObjC properties for auto-completion

Summary:
Similar to auto-completion for ObjC methods, inherited properties
should be penalized / direct class and category properties should
be prioritized.

Note that currently, the penalty for using a result from a base class
(CCD_InBaseClass) is equal to the penalty for using a method as a
property (CCD_MethodAsProperty).

Reviewers: jkorous, sammccall, akyrtzi, arphaman, benlangmuir

Reviewed By: sammccall, akyrtzi

Subscribers: arphaman, cfe-commits

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

Modified:
cfe/trunk/lib/Sema/SemaCodeComplete.cpp
cfe/trunk/test/CodeCompletion/objc-protocol-member-access.m
cfe/trunk/test/Index/complete-block-properties.m
cfe/trunk/test/Index/complete-block-property-assignment.m
cfe/trunk/test/Index/complete-member-access.m
cfe/trunk/test/Index/complete-properties.m

Modified: cfe/trunk/lib/Sema/SemaCodeComplete.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaCodeComplete.cpp?rev=347352&r1=347351&r2=347352&view=diff
==
--- cfe/trunk/lib/Sema/SemaCodeComplete.cpp (original)
+++ cfe/trunk/lib/Sema/SemaCodeComplete.cpp Tue Nov 20 14:06:54 2018
@@ -3958,7 +3958,8 @@ static void AddObjCProperties(
 const CodeCompletionContext &CCContext, ObjCContainerDecl *Container,
 bool AllowCategories, bool AllowNullaryMethods, DeclContext *CurContext,
 AddedPropertiesSet &AddedProperties, ResultBuilder &Results,
-bool IsBaseExprStatement = false, bool IsClassProperty = false) {
+bool IsBaseExprStatement = false, bool IsClassProperty = false,
+bool InOriginalClass = true) {
   typedef CodeCompletionResult Result;
 
   // Retrieve the definition.
@@ -3973,8 +3974,10 @@ static void AddObjCProperties(
 // expressions.
 if (!P->getType().getTypePtr()->isBlockPointerType() ||
 !IsBaseExprStatement) {
-  Results.MaybeAddResult(Result(P, Results.getBasePriority(P), nullptr),
- CurContext);
+  Result R = Result(P, Results.getBasePriority(P), nullptr);
+  if (!InOriginalClass)
+setInBaseClass(R);
+  Results.MaybeAddResult(R, CurContext);
   return;
 }
 
@@ -3985,8 +3988,10 @@ static void AddObjCProperties(
 findTypeLocationForBlockDecl(P->getTypeSourceInfo(), BlockLoc,
  BlockProtoLoc);
 if (!BlockLoc) {
-  Results.MaybeAddResult(Result(P, Results.getBasePriority(P), nullptr),
- CurContext);
+  Result R = Result(P, Results.getBasePriority(P), nullptr);
+  if (!InOriginalClass)
+setInBaseClass(R);
+  Results.MaybeAddResult(R, CurContext);
   return;
 }
 
@@ -3997,9 +4002,10 @@ static void AddObjCProperties(
 AddObjCBlockCall(Container->getASTContext(),
  getCompletionPrintingPolicy(Results.getSema()), Builder, 
P,
  BlockLoc, BlockProtoLoc);
-Results.MaybeAddResult(
-Result(Builder.TakeString(), P, Results.getBasePriority(P)),
-CurContext);
+Result R = Result(Builder.TakeString(), P, Results.getBasePriority(P));
+if (!InOriginalClass)
+  setInBaseClass(R);
+Results.MaybeAddResult(R, CurContext);
 
 // Provide additional block setter completion iff the base expression is a
 // statement and the block property is mutable.
@@ -4025,13 +4031,15 @@ static void AddObjCProperties(
   // otherwise the setter completion should show up before the default
   // property completion, as we normally want to use the result of the
   // call.
-  Results.MaybeAddResult(
+  Result R =
   Result(Builder.TakeString(), P,
  Results.getBasePriority(P) +
  (BlockLoc.getTypePtr()->getReturnType()->isVoidType()
   ? CCD_BlockPropertySetter
-  : -CCD_BlockPropertySetter)),
-  CurContext);
+  : -CCD_BlockPropertySetter));
+  if (!InOriginalClass)
+setInBaseClass(R);
+  Results.MaybeAddResult(R, CurContext);
 }
   };
 
@@ -4059,10 +4067,11 @@ static void AddObjCProperties(
   AddResultTypeChunk(Context, Policy, M, CCContext.getBaseType(), Builder);
   Builder.AddTypedTextChunk(
   Results.getAllocator().CopyString(Name->getName()));
-  Results.MaybeAddResult(
-  Result(Builder.TakeString(), M,
- CCP_MemberDeclaration + CCD_MethodAsProperty),
-  CurContext);
+  Result R = Result(Builder.TakeString(), M,
+CCP_MemberDeclaration + CCD_MethodAsProperty);
+  if (!InOriginalClass)
+setInBaseClass(R);
+  Results.MaybeAddResult(R, CurContext);
 };
 
 if (IsC

[PATCH] D53900: [CodeComplete] Penalize inherited ObjC properties for auto-completion

2018-11-20 Thread Sam McCall via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rC347352: [CodeComplete] Penalize inherited ObjC properties 
for auto-completion (authored by sammccall, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D53900?vs=171799&id=174838#toc

Repository:
  rC Clang

https://reviews.llvm.org/D53900

Files:
  lib/Sema/SemaCodeComplete.cpp
  test/CodeCompletion/objc-protocol-member-access.m
  test/Index/complete-block-properties.m
  test/Index/complete-block-property-assignment.m
  test/Index/complete-member-access.m
  test/Index/complete-properties.m

Index: test/Index/complete-block-property-assignment.m
===
--- test/Index/complete-block-property-assignment.m
+++ test/Index/complete-block-property-assignment.m
@@ -34,10 +34,10 @@
 // RUN: c-index-test -code-completion-at=%s:28:27 %s | FileCheck -check-prefix=CHECK-CC1 %s
 // RUN: c-index-test -code-completion-at=%s:29:22 %s | FileCheck -check-prefix=CHECK-CC1 %s
 // RUN: c-index-test -code-completion-at=%s:30:9 %s | FileCheck -check-prefix=CHECK-CC1 %s
-// CHECK-CC1: ObjCPropertyDecl:{ResultType int}{TypedText foo} (35)
+// CHECK-CC1: ObjCPropertyDecl:{ResultType int}{TypedText foo} (37)
 // CHECK-CC1-NEXT: ObjCPropertyDecl:{ResultType Obj *}{TypedText obj} (35)
-// CHECK-CC1-NEXT: ObjCPropertyDecl:{ResultType void}{TypedText onAction}{LeftParen (}{Placeholder Obj *object}{RightParen )} (35)
-// CHECK-CC1-NEXT: ObjCPropertyDecl:{ResultType void (^)(Obj *)}{TypedText onAction}{Equal  = }{Placeholder ^(Obj *object)} (38)
+// CHECK-CC1-NEXT: ObjCPropertyDecl:{ResultType void}{TypedText onAction}{LeftParen (}{Placeholder Obj *object}{RightParen )} (37)
+// CHECK-CC1-NEXT: ObjCPropertyDecl:{ResultType void (^)(Obj *)}{TypedText onAction}{Equal  = }{Placeholder ^(Obj *object)} (40)
 // CHECK-CC1-NEXT: ObjCPropertyDecl:{ResultType void}{TypedText onEventHandler}{LeftParen (}{Placeholder Foo *someParameter}{RightParen )} (35)
 // CHECK-CC1-NEXT: ObjCPropertyDecl:{ResultType FooBlock}{TypedText onEventHandler}{Equal  = }{Placeholder ^(Foo *someParameter)} (38)
 // CHECK-CC1-NEXT: ObjCPropertyDecl:{ResultType void}{TypedText onReadonly}{LeftParen (}{Placeholder int *someParameter}{RightParen )} (35)
@@ -61,17 +61,17 @@
 // RUN: c-index-test -code-completion-at=%s:52:23 %s | FileCheck -check-prefix=CHECK-NO %s
 // RUN: c-index-test -code-completion-at=%s:53:12 %s | FileCheck -check-prefix=CHECK-NO %s
 // RUN: c-index-test -code-completion-at=%s:56:15 %s | FileCheck -check-prefix=CHECK-NO %s
-// CHECK-NO: ObjCPropertyDecl:{ResultType int}{TypedText foo} (35)
+// CHECK-NO: ObjCPropertyDecl:{ResultType int}{TypedText foo} (37)
 // CHECK-NO-NEXT: ObjCPropertyDecl:{ResultType Obj *}{TypedText obj} (35)
-// CHECK-NO-NEXT: ObjCPropertyDecl:{ResultType void (^)(Obj *)}{TypedText onAction} (35)
+// CHECK-NO-NEXT: ObjCPropertyDecl:{ResultType void (^)(Obj *)}{TypedText onAction} (37)
 // CHECK-NO-NEXT: ObjCPropertyDecl:{ResultType FooBlock}{TypedText onEventHandler} (35)
 // CHECK-NO-NEXT: ObjCPropertyDecl:{ResultType void (^)(int *)}{TypedText onReadonly} (35)
 // CHECK-NO-NEXT: ObjCPropertyDecl:{ResultType int (^)(int)}{TypedText processEvent} (35)
 
 // RUN: c-index-test -code-completion-at=%s:54:15 %s | FileCheck -check-prefix=CHECK-NO1 %s
-// CHECK-NO1: ObjCPropertyDecl:{ResultType int}{TypedText foo} (35)
+// CHECK-NO1: ObjCPropertyDecl:{ResultType int}{TypedText foo} (37)
 // CHECK-NO1-NEXT: ObjCPropertyDecl:{ResultType Obj *}{TypedText obj} (35)
-// CHECK-NO1-NEXT: ObjCPropertyDecl:{ResultType void (^)(Obj *)}{TypedText onAction} (35)
+// CHECK-NO1-NEXT: ObjCPropertyDecl:{ResultType void (^)(Obj *)}{TypedText onAction} (37)
 // CHECK-NO1-NEXT: ObjCPropertyDecl:{ResultType FooBlock}{TypedText onEventHandler} (35)
 // CHECK-NO1-NEXT: ObjCPropertyDecl:{ResultType void (^)(int *)}{TypedText onReadonly} (35)
 // CHECK-NO1-NEXT: ObjCPropertyDecl:{ResultType int (^)(int)}{TypedText processEvent} (35)
Index: test/Index/complete-member-access.m
===
--- test/Index/complete-member-access.m
+++ test/Index/complete-member-access.m
@@ -61,8 +61,8 @@
 // RUN: c-index-test -code-completion-at=%s:34:12 %s | FileCheck -check-prefix=CHECK-CC3 %s
 // CHECK-CC3: ObjCInstanceMethodDecl:{ResultType int}{TypedText myOtherPropLikeThing} (37)
 // CHECK-CC3: ObjCPropertyDecl:{ResultType int}{TypedText myProp} (35)
-// CHECK-CC3: ObjCPropertyDecl:{ResultType int}{TypedText prop1} (35)
-// CHECK-CC3: ObjCPropertyDecl:{ResultType float}{TypedText ProtoProp} (35)
+// CHECK-CC3: ObjCPropertyDecl:{ResultType int}{TypedText prop1} (37)
+// CHECK-CC3: ObjCPropertyDecl:{ResultType float}{TypedText ProtoProp} (37)
 // CHECK-CC3: Completion contexts:
 // CHECK-CC3-NEXT: Objective-C property access
 // CHECK-CC3-NEXT: Container Kind: ObjCInterfaceDecl
@@ -72,6 +72,6 @@
 // RUN: c-index-test -code-completion-at=%s:42:20 %s | FileC

[PATCH] D53787: [Sema] Provide -fvisibility-global-new-delete-hidden option

2018-11-20 Thread Petr Hosek via Phabricator via cfe-commits
phosek added a comment.

@rsmith friendly ping?


Repository:
  rC Clang

https://reviews.llvm.org/D53787



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


[PATCH] D54768: Don't speculatively emit VTTs for classes unless we are able to correctly emit references to all the functions they will (directly or indirectly) reference.

2018-11-20 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.

LGTM.


Repository:
  rC Clang

https://reviews.llvm.org/D54768



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


  1   2   >