r339569 - Summary:Add clang::reinitializes attribute

2018-08-13 Thread Martin Bohme via cfe-commits
Author: mboehme
Date: Mon Aug 13 07:11:03 2018
New Revision: 339569

URL: http://llvm.org/viewvc/llvm-project?rev=339569&view=rev
Log:
Summary:Add clang::reinitializes attribute

Summary:
This is for use by clang-tidy's bugprone-use-after-move check -- see
corresponding clang-tidy patch at https://reviews.llvm.org/D49910.

Reviewers: aaron.ballman, rsmith

Reviewed By: aaron.ballman

Subscribers: cfe-commits

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

Added:
cfe/trunk/test/SemaCXX/attr-reinitializes.cpp
Modified:
cfe/trunk/include/clang/Basic/Attr.td
cfe/trunk/include/clang/Basic/AttrDocs.td
cfe/trunk/lib/Sema/SemaDeclAttr.cpp

Modified: cfe/trunk/include/clang/Basic/Attr.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=339569&r1=339568&r2=339569&view=diff
==
--- cfe/trunk/include/clang/Basic/Attr.td (original)
+++ cfe/trunk/include/clang/Basic/Attr.td Mon Aug 13 07:11:03 2018
@@ -90,6 +90,11 @@ def NonBitField : SubsetSubjectisBitField()}],
 "non-bit-field non-static data members">;
 
+def NonStaticNonConstCXXMethod
+: SubsetSubjectisStatic() && !S->isConst()}],
+"non-static non-const member functions">;
+
 def ObjCInstanceMethod : SubsetSubjectisInstanceMethod()}],
"Objective-C instance methods">;
@@ -2974,3 +2979,9 @@ def InternalLinkage : InheritableAttr {
   let Subjects = SubjectList<[Var, Function, CXXRecord]>;
   let Documentation = [InternalLinkageDocs];
 }
+
+def Reinitializes : InheritableAttr {
+  let Spellings = [Clang<"reinitializes", 0>];
+  let Subjects = SubjectList<[NonStaticNonConstCXXMethod], ErrorDiag>;
+  let Documentation = [ReinitializesDocs];
+}

Modified: cfe/trunk/include/clang/Basic/AttrDocs.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/AttrDocs.td?rev=339569&r1=339568&r2=339569&view=diff
==
--- cfe/trunk/include/clang/Basic/AttrDocs.td (original)
+++ cfe/trunk/include/clang/Basic/AttrDocs.td Mon Aug 13 07:11:03 2018
@@ -3458,3 +3458,31 @@ the resulting instructions with the call
 corresponding line within the inlined callee.
   }];
 }
+
+def ReinitializesDocs : Documentation {
+  let Category = DocCatFunction;
+  let Content = [{
+The ``reinitializes`` attribute can be applied to a non-static, non-const C++
+member function to indicate that this member function reinitializes the entire
+object to a known state, independent of the previous state of the object.
+
+This attribute can be interpreted by static analyzers that warn about uses of 
an
+object that has been left in an indeterminate state by a move operation. If a
+member function marked with the ``reinitializes`` attribute is called on a
+moved-from object, the analyzer can conclude that the object is no longer in an
+indeterminate state.
+
+A typical example where this attribute would be used is on functions that clear
+a container class:
+
+.. code-block:: c++
+
+  template 
+  class Container {
+  public:
+...
+[[clang::reinitializes]] void Clear();
+...
+  };
+  }];
+}

Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=339569&r1=339568&r2=339569&view=diff
==
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Mon Aug 13 07:11:03 2018
@@ -6582,6 +6582,11 @@ static void ProcessDeclAttribute(Sema &S
   case ParsedAttr::AT_XRayLogArgs:
 handleXRayLogArgsAttr(S, D, AL);
 break;
+
+  // Move semantics attribute.
+  case ParsedAttr::AT_Reinitializes:
+handleSimpleAttribute(S, D, AL);
+break;
   }
 }
 

Added: cfe/trunk/test/SemaCXX/attr-reinitializes.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/attr-reinitializes.cpp?rev=339569&view=auto
==
--- cfe/trunk/test/SemaCXX/attr-reinitializes.cpp (added)
+++ cfe/trunk/test/SemaCXX/attr-reinitializes.cpp Mon Aug 13 07:11:03 2018
@@ -0,0 +1,15 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
+
+[[clang::reinitializes]] int a; // expected-error {{'reinitializes' attribute 
only applies to non-static non-const member functions}}
+
+[[clang::reinitializes]] void f(); // expected-error {{only applies to}}
+
+struct A {
+  [[clang::reinitializes]] void foo();
+  __attribute__((reinitializes)) void gnu_foo();
+  [[clang::reinitializes]] void bar() const; // expected-error {{only applies 
to}}
+  [[clang::reinitializes]] static void baz(); // expected-error {{only applies 
to}}
+  [[clang::reinitializes]] int a; // expected-error {{only applies to}}
+
+  [[clang::reinitializes("arg")]] void qux(); // expected-error 
{{'reinitia

[clang-tools-extra] r339571 - [clang-tidy] Recognize [[clang::reinitializes]] attribute in bugprone-use-after-move

2018-08-13 Thread Martin Bohme via cfe-commits
Author: mboehme
Date: Mon Aug 13 07:24:52 2018
New Revision: 339571

URL: http://llvm.org/viewvc/llvm-project?rev=339571&view=rev
Log:
[clang-tidy] Recognize [[clang::reinitializes]] attribute in 
bugprone-use-after-move

Summary:
This allows member functions to be marked as reinitializing the object. After a
moved-from object has been reinitialized, the check will no longer consider it
to be in an indeterminate state.

The patch that adds the attribute itself is at https://reviews.llvm.org/D49911

Reviewers: ilya-biryukov, aaron.ballman, alexfh, hokein, rsmith

Reviewed By: aaron.ballman

Subscribers: dblaikie, xazax.hun, cfe-commits

Tags: #clang-tools-extra

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

Modified:
clang-tools-extra/trunk/clang-tidy/bugprone/UseAfterMoveCheck.cpp
clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-use-after-move.rst
clang-tools-extra/trunk/test/clang-tidy/bugprone-use-after-move.cpp

Modified: clang-tools-extra/trunk/clang-tidy/bugprone/UseAfterMoveCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/UseAfterMoveCheck.cpp?rev=339571&r1=339570&r2=339571&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/bugprone/UseAfterMoveCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/UseAfterMoveCheck.cpp Mon Aug 
13 07:24:52 2018
@@ -308,6 +308,10 @@ void UseAfterMoveFinder::getReinits(
cxxMemberCallExpr(
on(allOf(DeclRefMatcher, StandardSmartPointerTypeMatcher)),
callee(cxxMethodDecl(hasName("reset",
+   // Methods that have the [[clang::reinitializes]] attribute.
+   cxxMemberCallExpr(
+   on(DeclRefMatcher),
+   callee(cxxMethodDecl(hasAttr(clang::attr::Reinitializes,
// Passing variable to a function as a non-const pointer.
callExpr(forEachArgumentWithParam(
unaryOperator(hasOperatorName("&"),

Modified: 
clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-use-after-move.rst
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-use-after-move.rst?rev=339571&r1=339570&r2=339571&view=diff
==
--- clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-use-after-move.rst 
(original)
+++ clang-tools-extra/trunk/docs/clang-tidy/checks/bugprone-use-after-move.rst 
Mon Aug 13 07:24:52 2018
@@ -178,6 +178,9 @@ The check considers a variable to be rei
   - ``reset()`` is called on the variable and the variable is of type
 ``std::unique_ptr``, ``std::shared_ptr`` or ``std::weak_ptr``.
 
+  - A member function marked with the ``[[clang::reinitializes]]`` attribute is
+called on the variable.
+
 If the variable in question is a struct and an individual member variable of
 that struct is written to, the check does not consider this to be a
 reinitialization -- even if, eventually, all member variables of the struct are

Modified: clang-tools-extra/trunk/test/clang-tidy/bugprone-use-after-move.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/bugprone-use-after-move.cpp?rev=339571&r1=339570&r2=339571&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/bugprone-use-after-move.cpp 
(original)
+++ clang-tools-extra/trunk/test/clang-tidy/bugprone-use-after-move.cpp Mon Aug 
13 07:24:52 2018
@@ -107,6 +107,15 @@ public:
   int i;
 };
 
+template 
+class AnnotatedContainer {
+public:
+  AnnotatedContainer();
+
+  void foo() const;
+  [[clang::reinitializes]] void clear();
+};
+
 

 // General tests.
 
@@ -898,6 +907,32 @@ void standardSmartPointerResetIsReinit()
   }
 }
 
+void reinitAnnotation() {
+  {
+AnnotatedContainer obj;
+std::move(obj);
+obj.foo();
+// CHECK-MESSAGES: [[@LINE-1]]:5: warning: 'obj' used after it was
+// CHECK-MESSAGES: [[@LINE-3]]:5: note: move occurred here
+  }
+  {
+AnnotatedContainer obj;
+std::move(obj);
+obj.clear();
+obj.foo();
+  }
+  {
+// Calling clear() on a different object to the one that was moved is not
+// considered a reinitialization.
+AnnotatedContainer obj1, obj2;
+std::move(obj1);
+obj2.clear();
+obj1.foo();
+// CHECK-MESSAGES: [[@LINE-1]]:5: warning: 'obj1' used after it was
+// CHECK-MESSAGES: [[@LINE-4]]:5: note: move occurred here
+  }
+}
+
 

 // Tests related to order of evaluation within expressions
 


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

[clang-tools-extra] r338932 - [clang-tidy] Sequence init statements, declarations, and conditions correctly in if, switch, and while

2018-08-03 Thread Martin Bohme via cfe-commits
Author: mboehme
Date: Fri Aug  3 15:20:04 2018
New Revision: 338932

URL: http://llvm.org/viewvc/llvm-project?rev=338932&view=rev
Log:
[clang-tidy] Sequence init statements, declarations, and conditions correctly 
in if, switch, and while

Summary: Fixes https://bugs.llvm.org/show_bug.cgi?id=36516.

Reviewers: ilya-biryukov, alexfh, aaron.ballman, hokein

Reviewed By: alexfh

Subscribers: xazax.hun, cfe-commits

Tags: #clang-tools-extra

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

Modified:
clang-tools-extra/trunk/clang-tidy/utils/ExprSequence.cpp
clang-tools-extra/trunk/test/clang-tidy/bugprone-use-after-move.cpp

Modified: clang-tools-extra/trunk/clang-tidy/utils/ExprSequence.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/utils/ExprSequence.cpp?rev=338932&r1=338931&r2=338932&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/utils/ExprSequence.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/utils/ExprSequence.cpp Fri Aug  3 
15:20:04 2018
@@ -139,11 +139,26 @@ const Stmt *ExprSequence::getSequenceSuc
   if (S == ForRange->getLoopVarStmt())
 return ForRange->getBody();
 } else if (const auto *TheIfStmt = dyn_cast(Parent)) {
-  // If statement: If a variable is declared inside the condition, the
-  // expression used to initialize the variable is sequenced before the
-  // evaluation of the condition.
+  // If statement:
+  // - Sequence init statement before variable declaration.
+  // - Sequence variable declaration (along with the expression used to
+  //   initialize it) before the evaluation of the condition.
+  if (S == TheIfStmt->getInit())
+return TheIfStmt->getConditionVariableDeclStmt();
   if (S == TheIfStmt->getConditionVariableDeclStmt())
 return TheIfStmt->getCond();
+} else if (const auto *TheSwitchStmt = dyn_cast(Parent)) {
+  // Ditto for switch statements.
+  if (S == TheSwitchStmt->getInit())
+return TheSwitchStmt->getConditionVariableDeclStmt();
+  if (S == TheSwitchStmt->getConditionVariableDeclStmt())
+return TheSwitchStmt->getCond();
+} else if (const auto *TheWhileStmt = dyn_cast(Parent)) {
+  // While statement: Sequence variable declaration (along with the
+  // expression used to initialize it) before the evaluation of the
+  // condition.
+  if (S == TheWhileStmt->getConditionVariableDeclStmt())
+return TheWhileStmt->getCond();
 }
   }
 

Modified: clang-tools-extra/trunk/test/clang-tidy/bugprone-use-after-move.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/bugprone-use-after-move.cpp?rev=338932&r1=338931&r2=338932&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/bugprone-use-after-move.cpp 
(original)
+++ clang-tools-extra/trunk/test/clang-tidy/bugprone-use-after-move.cpp Fri Aug 
 3 15:20:04 2018
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy %s bugprone-use-after-move %t -- -- -std=c++11 
-fno-delayed-template-parsing
+// RUN: %check_clang_tidy %s bugprone-use-after-move %t -- -- -std=c++17 
-fno-delayed-template-parsing
 
 typedef decltype(nullptr) nullptr_t;
 
@@ -1132,13 +1132,30 @@ void forRangeSequences() {
   }
 }
 
-// If a variable is declared in an if statement, the declaration of the 
variable
-// (which is treated like a reinitialization by the check) is sequenced before
-// the evaluation of the condition (which constitutes a use).
-void ifStmtSequencesDeclAndCondition() {
+// If a variable is declared in an if, while or switch statement, the init
+// statement (for if and switch) is sequenced before the variable declaration,
+// which in turn is sequenced before the evaluation of the condition.
+void ifWhileAndSwitchSequenceInitDeclAndCondition() {
   for (int i = 0; i < 10; ++i) {
-if (A a = A()) {
-  std::move(a);
+A a1;
+if (A a2 = std::move(a1)) {
+  std::move(a2);
+}
+  }
+  for (int i = 0; i < 10; ++i) {
+A a1;
+if (A a2 = std::move(a1); A a3 = std::move(a2)) {
+  std::move(a3);
+}
+  }
+  while (A a = A()) {
+std::move(a);
+  }
+  for (int i = 0; i < 10; ++i) {
+A a1;
+switch (A a2 = a1; A a3 = std::move(a2)) {
+  case true:
+std::move(a3);
 }
   }
 }


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


r325236 - Add -no-canonical-prefixes to allow different build modes.

2018-02-15 Thread Martin Bohme via cfe-commits
Author: mboehme
Date: Thu Feb 15 05:50:07 2018
New Revision: 325236

URL: http://llvm.org/viewvc/llvm-project?rev=325236&view=rev
Log:
Add -no-canonical-prefixes to allow different build modes.

Modified:
cfe/trunk/test/Driver/amdgcn-toolchain-pic.cl

Modified: cfe/trunk/test/Driver/amdgcn-toolchain-pic.cl
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/amdgcn-toolchain-pic.cl?rev=325236&r1=325235&r2=325236&view=diff
==
--- cfe/trunk/test/Driver/amdgcn-toolchain-pic.cl (original)
+++ cfe/trunk/test/Driver/amdgcn-toolchain-pic.cl Thu Feb 15 05:50:07 2018
@@ -1,7 +1,7 @@
-// RUN: %clang -### -target amdgcn-- -mcpu=gfx803 %s 2>&1 | FileCheck %s
-// RUN: %clang -### -target amdgcn-amd- -mcpu=gfx803 %s 2>&1 | FileCheck %s
-// RUN: %clang -### -target amdgcn-amd-amdhsa -mcpu=gfx803 %s 2>&1 | FileCheck 
%s
-// RUN: %clang -### -target amdgcn-amd-amdpal -mcpu=gfx803 %s 2>&1 | FileCheck 
%s
-// RUN: %clang -### -target amdgcn-amd-mesa3d -mcpu=gfx803 %s 2>&1 | FileCheck 
%s
+// RUN: %clang -no-canonical-prefixes -### -target amdgcn-- -mcpu=gfx803 %s 
2>&1 | FileCheck %s
+// RUN: %clang -no-canonical-prefixes -### -target amdgcn-amd- -mcpu=gfx803 %s 
2>&1 | FileCheck %s
+// RUN: %clang -no-canonical-prefixes -### -target amdgcn-amd-amdhsa 
-mcpu=gfx803 %s 2>&1 | FileCheck %s
+// RUN: %clang -no-canonical-prefixes -### -target amdgcn-amd-amdpal 
-mcpu=gfx803 %s 2>&1 | FileCheck %s
+// RUN: %clang -no-canonical-prefixes -### -target amdgcn-amd-mesa3d 
-mcpu=gfx803 %s 2>&1 | FileCheck %s
 
 // CHECK: clang{{.*}} "-mrelocation-model" "pic" "-pic-level" "1"


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


r320971 - [X86] Use {{.*}} instead of hardcoded %1 in knot test.

2017-12-18 Thread Martin Bohme via cfe-commits
Author: mboehme
Date: Mon Dec 18 03:29:21 2017
New Revision: 320971

URL: http://llvm.org/viewvc/llvm-project?rev=320971&view=rev
Log:
[X86] Use {{.*}} instead of hardcoded %1 in knot test.

This makes the test more resilient and consistent with the other tests
introduced in r320919.

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

Modified: cfe/trunk/test/CodeGen/avx512f-builtins.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/avx512f-builtins.c?rev=320971&r1=320970&r2=320971&view=diff
==
--- cfe/trunk/test/CodeGen/avx512f-builtins.c (original)
+++ cfe/trunk/test/CodeGen/avx512f-builtins.c Mon Dec 18 03:29:21 2017
@@ -385,7 +385,7 @@ __m512d test_mm512_set1_pd(double d)
 __mmask16 test_mm512_knot(__mmask16 a)
 {
   // CHECK-LABEL: @test_mm512_knot
-  // CHECK: [[IN:%.*]] = bitcast i16 %1 to <16 x i1>
+  // CHECK: [[IN:%.*]] = bitcast i16 %{{.*}} to <16 x i1>
   // CHECK: [[NOT:%.*]] = xor <16 x i1> [[IN]], 
   // CHECK: bitcast <16 x i1> [[NOT]] to i16
   return _mm512_knot(a);


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


[clang-tools-extra] r321156 - [clangd] Add "../" to Logger.h included from parent directory.

2017-12-20 Thread Martin Bohme via cfe-commits
Author: mboehme
Date: Wed Dec 20 01:17:31 2017
New Revision: 321156

URL: http://llvm.org/viewvc/llvm-project?rev=321156&view=rev
Log:
[clangd] Add "../" to Logger.h included from parent directory.

Modified:
clang-tools-extra/trunk/clangd/index/MemIndex.cpp

Modified: clang-tools-extra/trunk/clangd/index/MemIndex.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/index/MemIndex.cpp?rev=321156&r1=321155&r2=321156&view=diff
==
--- clang-tools-extra/trunk/clangd/index/MemIndex.cpp (original)
+++ clang-tools-extra/trunk/clangd/index/MemIndex.cpp Wed Dec 20 01:17:31 2017
@@ -8,7 +8,7 @@
 //===---===//
 
 #include "MemIndex.h"
-#include "Logger.h"
+#include "../Logger.h"
 
 namespace clang {
 namespace clangd {


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


[clang-tools-extra] r351303 - [clang-tidy] Treat references to smart pointers correctly in use-after-move.

2019-01-15 Thread Martin Bohme via cfe-commits
Author: mboehme
Date: Tue Jan 15 23:53:25 2019
New Revision: 351303

URL: http://llvm.org/viewvc/llvm-project?rev=351303&view=rev
Log:
[clang-tidy] Treat references to smart pointers correctly in use-after-move.

Summary:
Previously, we weren't recognizing these as smart pointers and thus
weren't allowing non-dereference accesses as we should -- see new test
cases which fail without the fix.

Reviewers: alexfh, hokein, aaron.ballman, JonasToth

Reviewed By: JonasToth

Subscribers: xazax.hun, cfe-commits

Tags: #clang-tools-extra

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

Modified:
clang-tools-extra/trunk/clang-tidy/bugprone/UseAfterMoveCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/bugprone-use-after-move.cpp

Modified: clang-tools-extra/trunk/clang-tidy/bugprone/UseAfterMoveCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/UseAfterMoveCheck.cpp?rev=351303&r1=351302&r2=351303&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/bugprone/UseAfterMoveCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/UseAfterMoveCheck.cpp Tue Jan 
15 23:53:25 2019
@@ -207,7 +207,7 @@ void UseAfterMoveFinder::getUsesAndReini
 }
 
 bool isStandardSmartPointer(const ValueDecl *VD) {
-  const Type *TheType = VD->getType().getTypePtrOrNull();
+  const Type *TheType = VD->getType().getNonReferenceType().getTypePtrOrNull();
   if (!TheType)
 return false;
 

Modified: clang-tools-extra/trunk/test/clang-tidy/bugprone-use-after-move.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/bugprone-use-after-move.cpp?rev=351303&r1=351302&r2=351303&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/bugprone-use-after-move.cpp 
(original)
+++ clang-tools-extra/trunk/test/clang-tidy/bugprone-use-after-move.cpp Tue Jan 
15 23:53:25 2019
@@ -244,6 +244,19 @@ void standardSmartPtr() {
 std::move(ptr);
 ptr.get();
   }
+  // Make sure we treat references to smart pointers correctly.
+  {
+std::unique_ptr ptr;
+std::unique_ptr& ref_to_ptr = ptr;
+std::move(ref_to_ptr);
+ref_to_ptr.get();
+  }
+  {
+std::unique_ptr ptr;
+std::unique_ptr&& rvalue_ref_to_ptr = std::move(ptr);
+std::move(rvalue_ref_to_ptr);
+rvalue_ref_to_ptr.get();
+  }
   // We don't give any special treatment to types that are called "unique_ptr"
   // or "shared_ptr" but are not in the "::std" namespace.
   {


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


[clang-tools-extra] r343768 - [clang-tidy] Sequence statements with multiple parents correctly (PR39149)

2018-10-04 Thread Martin Bohme via cfe-commits
Author: mboehme
Date: Thu Oct  4 04:36:39 2018
New Revision: 343768

URL: http://llvm.org/viewvc/llvm-project?rev=343768&view=rev
Log:
[clang-tidy] Sequence statements with multiple parents correctly (PR39149)

Summary:
Before this fix, the bugprone-use-after-move check could incorrectly
conclude that a use and move in a function template were not sequenced.
For details, see

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

Reviewers: alexfh, hokein, aaron.ballman, JonasToth

Reviewed By: aaron.ballman

Subscribers: xazax.hun, cfe-commits

Tags: #clang-tools-extra

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

Modified:
clang-tools-extra/trunk/clang-tidy/bugprone/UseAfterMoveCheck.cpp
clang-tools-extra/trunk/clang-tidy/utils/ExprSequence.cpp
clang-tools-extra/trunk/clang-tidy/utils/ExprSequence.h
clang-tools-extra/trunk/test/clang-tidy/bugprone-use-after-move.cpp

Modified: clang-tools-extra/trunk/clang-tidy/bugprone/UseAfterMoveCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/UseAfterMoveCheck.cpp?rev=343768&r1=343767&r2=343768&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/bugprone/UseAfterMoveCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/UseAfterMoveCheck.cpp Thu Oct  
4 04:36:39 2018
@@ -102,8 +102,9 @@ bool UseAfterMoveFinder::find(Stmt *Func
   if (!TheCFG)
 return false;
 
-  Sequence.reset(new ExprSequence(TheCFG.get(), Context));
-  BlockMap.reset(new StmtToBlockMap(TheCFG.get(), Context));
+  Sequence =
+  llvm::make_unique(TheCFG.get(), FunctionBody, Context);
+  BlockMap = llvm::make_unique(TheCFG.get(), Context);
   Visited.clear();
 
   const CFGBlock *Block = BlockMap->blockContainingStmt(MovingCall);

Modified: clang-tools-extra/trunk/clang-tidy/utils/ExprSequence.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/utils/ExprSequence.cpp?rev=343768&r1=343767&r2=343768&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/utils/ExprSequence.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/utils/ExprSequence.cpp Thu Oct  4 
04:36:39 2018
@@ -63,8 +63,9 @@ bool isDescendantOrEqual(const Stmt *Des
 }
 }
 
-ExprSequence::ExprSequence(const CFG *TheCFG, ASTContext *TheContext)
-: Context(TheContext) {
+ExprSequence::ExprSequence(const CFG *TheCFG, const Stmt *Root,
+   ASTContext *TheContext)
+: Context(TheContext), Root(Root) {
   for (const auto &SyntheticStmt : TheCFG->synthetic_stmts()) {
 SyntheticStmtSourceMap[SyntheticStmt.first] = SyntheticStmt.second;
   }
@@ -99,6 +100,11 @@ bool ExprSequence::potentiallyAfter(cons
 
 const Stmt *ExprSequence::getSequenceSuccessor(const Stmt *S) const {
   for (const Stmt *Parent : getParentStmts(S, Context)) {
+// If a statement has multiple parents, make sure we're using the parent
+// that lies within the sub-tree under Root.
+if (!isDescendantOrEqual(Parent, Root, Context))
+  continue;
+
 if (const auto *BO = dyn_cast(Parent)) {
   // Comma operator: Right-hand side is sequenced after the left-hand side.
   if (BO->getLHS() == S && BO->getOpcode() == BO_Comma)

Modified: clang-tools-extra/trunk/clang-tidy/utils/ExprSequence.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/utils/ExprSequence.h?rev=343768&r1=343767&r2=343768&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/utils/ExprSequence.h (original)
+++ clang-tools-extra/trunk/clang-tidy/utils/ExprSequence.h Thu Oct  4 04:36:39 
2018
@@ -69,8 +69,8 @@ namespace utils {
 class ExprSequence {
 public:
   /// Initializes this `ExprSequence` with sequence information for the given
-  /// `CFG`.
-  ExprSequence(const CFG *TheCFG, ASTContext *TheContext);
+  /// `CFG`. `Root` is the root statement the CFG was built from.
+  ExprSequence(const CFG *TheCFG, const Stmt *Root, ASTContext *TheContext);
 
   /// Returns whether \p Before is sequenced before \p After.
   bool inSequence(const Stmt *Before, const Stmt *After) const;
@@ -94,6 +94,7 @@ private:
   const Stmt *resolveSyntheticStmt(const Stmt *S) const;
 
   ASTContext *Context;
+  const Stmt *Root;
 
   llvm::DenseMap SyntheticStmtSourceMap;
 };

Modified: clang-tools-extra/trunk/test/clang-tidy/bugprone-use-after-move.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/bugprone-use-after-move.cpp?rev=343768&r1=343767&r2=343768&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/bugprone-use-after-move.cpp 
(original)
+++ clang-tools-extra/trunk/test/clang-tidy/bugprone-use-after-move.cpp Thu Oct 
 4 04:36:39 2018
@@ -1195,6 +1195,18 @@ void ifWhileAndSwitchSequenceInitDeclAnd
  

r312108 - Revert "Improve constant expression evaluation of arrays of unknown bound."

2017-08-30 Thread Martin Bohme via cfe-commits
Author: mboehme
Date: Wed Aug 30 03:44:46 2017
New Revision: 312108

URL: http://llvm.org/viewvc/llvm-project?rev=312108&view=rev
Log:
Revert "Improve constant expression evaluation of arrays of unknown bound."

This reverts commit r311970.

Breaks internal tests.

Modified:
cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td
cfe/trunk/include/clang/Basic/DiagnosticIDs.h
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td?rev=312108&r1=312107&r2=312108&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticASTKinds.td Wed Aug 30 03:44:46 2017
@@ -127,10 +127,6 @@ def note_constexpr_access_null : Note<
 def note_constexpr_access_past_end : Note<
   "%select{read of|assignment to|increment of|decrement of}0 "
   "dereferenced one-past-the-end pointer is not allowed in a constant 
expression">;
-def note_constexpr_access_unsized_array : Note<
-  "%select{read of|assignment to|increment of|decrement of}0 "
-  "pointer to element of array without known bound "
-  "is not allowed in a constant expression">;
 def note_constexpr_access_inactive_union_member : Note<
   "%select{read of|assignment to|increment of|decrement of}0 "
   "member %1 of union with %select{active member %3|no active member}2 "
@@ -158,11 +154,6 @@ def note_constexpr_baa_insufficient_alig
 def note_constexpr_baa_value_insufficient_alignment : Note<
   "value of the aligned pointer (%0) is not a multiple of the asserted %1 "
   "%plural{1:byte|:bytes}1">;
-def note_constexpr_unsupported_unsized_array : Note<
-  "array-to-pointer decay of array member without known bound is not 
supported">;
-def note_constexpr_unsized_array_indexed : Note<
-  "indexing of array without known bound is not allowed "
-  "in a constant expression">;
 
 def warn_integer_constant_overflow : Warning<
   "overflow in expression; result is %0 with type %1">,

Modified: cfe/trunk/include/clang/Basic/DiagnosticIDs.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticIDs.h?rev=312108&r1=312107&r2=312108&view=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticIDs.h (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticIDs.h Wed Aug 30 03:44:46 2017
@@ -34,7 +34,7 @@ namespace clang {
   DIAG_SIZE_SERIALIZATION =  120,
   DIAG_SIZE_LEX   =  400,
   DIAG_SIZE_PARSE =  500,
-  DIAG_SIZE_AST   =  150,
+  DIAG_SIZE_AST   =  110,
   DIAG_SIZE_COMMENT   =  100,
   DIAG_SIZE_SEMA  = 3500,
   DIAG_SIZE_ANALYSIS  =  100

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=312108&r1=312107&r2=312108&view=diff
==
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Wed Aug 30 03:44:46 2017
@@ -141,12 +141,6 @@ namespace {
 return E && E->getType()->isPointerType() && tryUnwrapAllocSizeCall(E);
   }
 
-  /// The bound to claim that an array of unknown bound has.
-  /// The value in MostDerivedArraySize is undefined in this case. So, set it
-  /// to an arbitrary value that's likely to loudly break things if it's used.
-  static const uint64_t AssumedSizeForUnsizedArray =
-  std::numeric_limits::max() / 2;
-
   /// Determines if an LValue with the given LValueBase will have an unsized
   /// array in its designator.
   /// Find the path length and type of the most-derived subobject in the given
@@ -154,8 +148,7 @@ namespace {
   static unsigned
   findMostDerivedSubobject(ASTContext &Ctx, APValue::LValueBase Base,
ArrayRef Path,
-   uint64_t &ArraySize, QualType &Type, bool &IsArray,
-   bool &FirstEntryIsUnsizedArray) {
+   uint64_t &ArraySize, QualType &Type, bool &IsArray) 
{
 // This only accepts LValueBases from APValues, and APValues don't support
 // arrays that lack size info.
 assert(!isBaseAnAllocSizeCall(Base) &&
@@ -165,18 +158,12 @@ namespace {
 
 for (unsigned I = 0, N = Path.size(); I != N; ++I) {
   if (Type->isArrayType()) {
-const ArrayType *AT = Ctx.getAsArrayType(Type);
-Type = AT->getElementType();
+const ConstantArrayType *CAT =
+cast(Ctx.getAsArrayType(Type));
+Type = CAT->getElementType();
+ArraySize = CAT->getSize().getZExtValue();
 MostDerivedLength = I + 1;
 IsArray = true;
-
-if (auto *CAT = dyn_cast(AT)) {
-  ArraySize = CAT->getSize(

r312109 - Add test case that was broken by r311970.

2017-08-30 Thread Martin Bohme via cfe-commits
Author: mboehme
Date: Wed Aug 30 03:44:51 2017
New Revision: 312109

URL: http://llvm.org/viewvc/llvm-project?rev=312109&view=rev
Log:
Add test case that was broken by r311970.

See also discussion here:
https://reviews.llvm.org/rL301963

As far as I can tell, this discussion was never resolved.

Modified:
cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp

Modified: cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp?rev=312109&r1=312108&r2=312109&view=diff
==
--- cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp (original)
+++ cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp Wed Aug 30 03:44:51 
2017
@@ -604,6 +604,22 @@ static_assert(NATDCArray{}[1][1].n == 0,
 
 }
 
+// Tests for indexes into arrays of unknown bounds.
+namespace ArrayOfUnknownBound {
+  // This is a corner case of the language where it's not clear whether this
+  // should be an error: When we see the initializer for Z::a, the bounds of
+  // Z::b aren't known yet, but they will be known by the end of the 
translation
+  // unit, so the compiler can in theory check the indexing into Z::b.
+  // For the time being, as long as this is unclear, we want to make sure that
+  // this compiles.
+  struct Z {
+static const void *const a[];
+static const void *const b[];
+  };
+  constexpr const void *Z::a[] = {&b[0], &b[1]};
+  constexpr const void *Z::b[] = {&a[0], &a[1]};
+}
+
 namespace DependentValues {
 
 struct I { int n; typedef I V[10]; };


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


[clang-tools-extra] r284235 - [clang-tidy] Add additional diagnostic to misc-use-after-move

2016-10-14 Thread Martin Bohme via cfe-commits
Author: mboehme
Date: Fri Oct 14 08:23:39 2016
New Revision: 284235

URL: http://llvm.org/viewvc/llvm-project?rev=284235&view=rev
Log:
[clang-tidy] Add additional diagnostic to misc-use-after-move

Summary:
This adds a diagnostic to the misc-use-after-move check that is output when the
use happens on a later loop iteration than the move, for example:

A a;
for (int i = 0; i < 10; ++i) {
  a.foo();
  std::move(a);
}

This situation can be confusing to users because, in terms of source code
location, the use is above the move. This can make it look as if the warning
is a false positive, particularly if the loop is long but the use and move are
close together.

In cases like these, misc-use-after-move will now output an additional
diagnostic:

  a.cpp:393:7: note: the use happens in a later loop iteration than the move

Reviewers: hokein

Subscribers: cfe-commits

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

Modified:
clang-tools-extra/trunk/clang-tidy/misc/UseAfterMoveCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/misc-use-after-move.cpp

Modified: clang-tools-extra/trunk/clang-tidy/misc/UseAfterMoveCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/UseAfterMoveCheck.cpp?rev=284235&r1=284234&r2=284235&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/misc/UseAfterMoveCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/UseAfterMoveCheck.cpp Fri Oct 14 
08:23:39 2016
@@ -562,18 +562,24 @@ void UseAfterMoveFinder::getReinits(
 }
 
 static void emitDiagnostic(const Expr *MovingCall,
-   const ValueDecl *MovedVariable,
+   const DeclRefExpr *MoveArg,
const UseAfterMove &Use, ClangTidyCheck *Check,
ASTContext *Context) {
-  Check->diag(Use.DeclRef->getExprLoc(), "'%0' used after it was moved")
-  << MovedVariable->getName();
-  Check->diag(MovingCall->getExprLoc(), "move occurred here",
-  DiagnosticIDs::Note);
+  SourceLocation UseLoc = Use.DeclRef->getExprLoc();
+  SourceLocation MoveLoc = MovingCall->getExprLoc();
+
+  Check->diag(UseLoc, "'%0' used after it was moved")
+  << MoveArg->getDecl()->getName();
+  Check->diag(MoveLoc, "move occurred here", DiagnosticIDs::Note);
   if (Use.EvaluationOrderUndefined) {
-Check->diag(Use.DeclRef->getExprLoc(),
+Check->diag(UseLoc,
 "the use and move are unsequenced, i.e. there is no guarantee "
 "about the order in which they are evaluated",
 DiagnosticIDs::Note);
+  } else if (UseLoc < MoveLoc || Use.DeclRef == MoveArg) {
+Check->diag(UseLoc,
+"the use happens in a later loop iteration than the move",
+DiagnosticIDs::Note);
   }
 }
 
@@ -625,8 +631,6 @@ void UseAfterMoveCheck::check(const Matc
   else
 return;
 
-  const ValueDecl *MovedVariable = Arg->getDecl();
-
   // Ignore the std::move if the variable that was passed to it isn't a local
   // variable.
   if (!Arg->getDecl()->getDeclContext()->isFunctionOrMethod())
@@ -634,8 +638,8 @@ void UseAfterMoveCheck::check(const Matc
 
   UseAfterMoveFinder finder(Result.Context);
   UseAfterMove Use;
-  if (finder.find(FunctionBody, MovingCall, MovedVariable, &Use))
-emitDiagnostic(MovingCall, MovedVariable, Use, this, Result.Context);
+  if (finder.find(FunctionBody, MovingCall, Arg->getDecl(), &Use))
+emitDiagnostic(MovingCall, Arg, Use, this, Result.Context);
 }
 
 } // namespace misc

Modified: clang-tools-extra/trunk/test/clang-tidy/misc-use-after-move.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/misc-use-after-move.cpp?rev=284235&r1=284234&r2=284235&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/misc-use-after-move.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/misc-use-after-move.cpp Fri Oct 14 
08:23:39 2016
@@ -133,6 +133,7 @@ void moveAfterMove() {
   std::move(a);
   // CHECK-MESSAGES: [[@LINE-1]]:17: warning: 'a' used after it was moved
   // CHECK-MESSAGES: [[@LINE-2]]:7: note: move occurred here
+  // CHECK-MESSAGES: [[@LINE-3]]:17: note: the use happens in a later loop
 }
   }
 }
@@ -391,7 +392,8 @@ void useAndMoveInLoop() {
 for (int i = 0; i < 10; ++i) {
   a.foo();
   // CHECK-MESSAGES: [[@LINE-1]]:7: warning: 'a' used after it was moved
-  // CHECK-MESSAGES: [[@LINE+1]]:7: note: move occurred here
+  // CHECK-MESSAGES: [[@LINE+2]]:7: note: move occurred here
+  // CHECK-MESSAGES: [[@LINE-3]]:7: note: the use happens in a later loop
   std::move(a);
 }
   }
@@ -586,7 +588,7 @@ void assignments(int i) {
   }
 }
 
-// Passing the object to a function through a non-const pointer or refernce
+// Passing the object to a functio

r278933 - Visit lambda capture inits from RecursiveASTVisitor::TraverseLambdaCapture().

2016-08-17 Thread Martin Bohme via cfe-commits
Author: mboehme
Date: Wed Aug 17 09:59:53 2016
New Revision: 278933

URL: http://llvm.org/viewvc/llvm-project?rev=278933&view=rev
Log:
Visit lambda capture inits from RecursiveASTVisitor::TraverseLambdaCapture().

Summary:
rL277342 made RecursiveASTVisitor visit lambda capture initialization
expressions (these are the Exprs in LambdaExpr::capture_inits()).

jdennett identified two issues with rL277342 (see comments there for details):

- It visits initialization expressions for implicit lambda captures, even if
  shouldVisitImplicitCode() returns false.

- It visits initialization expressions for init captures twice (because these
  were already traveresed in TraverseLambdaCapture() before rL277342)

This patch fixes these issues and moves the code for traversing initialization
expressions into TraverseLambdaCapture().

This patch also makes two changes required for the tests:

- It adds Lang_CXX14 to the Language enum in TestVisitor.

- It adds a parameter to ExpectedLocationVisitor::ExpectMatch() that specifies
  the number of times a match is expected to be seen.

Reviewers: klimek, jdennett, alexfh

Subscribers: cfe-commits

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

Modified:
cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
cfe/trunk/lib/Index/IndexBody.cpp
cfe/trunk/unittests/Tooling/RecursiveASTVisitorTestExprVisitor.cpp
cfe/trunk/unittests/Tooling/TestVisitor.h

Modified: cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/RecursiveASTVisitor.h?rev=278933&r1=278932&r2=278933&view=diff
==
--- cfe/trunk/include/clang/AST/RecursiveASTVisitor.h (original)
+++ cfe/trunk/include/clang/AST/RecursiveASTVisitor.h Wed Aug 17 09:59:53 2016
@@ -264,10 +264,12 @@ public:
   /// \returns false if the visitation was terminated early, true otherwise.
   bool TraverseConstructorInitializer(CXXCtorInitializer *Init);
 
-  /// \brief Recursively visit a lambda capture.
+  /// \brief Recursively visit a lambda capture. \c Init is the expression that
+  /// will be used to initialize the capture.
   ///
   /// \returns false if the visitation was terminated early, true otherwise.
-  bool TraverseLambdaCapture(LambdaExpr *LE, const LambdaCapture *C);
+  bool TraverseLambdaCapture(LambdaExpr *LE, const LambdaCapture *C,
+ Expr *Init);
 
   /// \brief Recursively visit the body of a lambda expression.
   ///
@@ -885,9 +887,12 @@ bool RecursiveASTVisitor::Trave
 template 
 bool
 RecursiveASTVisitor::TraverseLambdaCapture(LambdaExpr *LE,
-const LambdaCapture *C) {
+const LambdaCapture *C,
+Expr *Init) {
   if (LE->isInitCapture(C))
 TRY_TO(TraverseDecl(C->getCapturedVar()));
+  else
+TRY_TO(TraverseStmt(Init));
   return true;
 }
 
@@ -2261,13 +2266,11 @@ DEF_TRAVERSE_STMT(CXXTemporaryObjectExpr
 
 // Walk only the visible parts of lambda expressions.
 DEF_TRAVERSE_STMT(LambdaExpr, {
-  for (LambdaExpr::capture_iterator C = S->explicit_capture_begin(),
-CEnd = S->explicit_capture_end();
-   C != CEnd; ++C) {
-TRY_TO(TraverseLambdaCapture(S, C));
-  }
-  for (Expr *Init : S->capture_inits()) {
-TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(Init);
+  for (unsigned I = 0, N = S->capture_size(); I != N; ++I) {
+const LambdaCapture *C = S->capture_begin() + I;
+if (C->isExplicit() || getDerived().shouldVisitImplicitCode()) {
+  TRY_TO(TraverseLambdaCapture(S, C, S->capture_init_begin()[I]));
+}
   }
 
   TypeLoc TL = S->getCallOperator()->getTypeSourceInfo()->getTypeLoc();

Modified: cfe/trunk/lib/Index/IndexBody.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Index/IndexBody.cpp?rev=278933&r1=278932&r2=278933&view=diff
==
--- cfe/trunk/lib/Index/IndexBody.cpp (original)
+++ cfe/trunk/lib/Index/IndexBody.cpp Wed Aug 17 09:59:53 2016
@@ -276,7 +276,8 @@ public:
 return true;
   }
 
-  bool TraverseLambdaCapture(LambdaExpr *LE, const LambdaCapture *C) {
+  bool TraverseLambdaCapture(LambdaExpr *LE, const LambdaCapture *C,
+ Expr *Init) {
 if (C->capturesThis() || C->capturesVLAType())
   return true;
 

Modified: cfe/trunk/unittests/Tooling/RecursiveASTVisitorTestExprVisitor.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Tooling/RecursiveASTVisitorTestExprVisitor.cpp?rev=278933&r1=278932&r2=278933&view=diff
==
--- cfe/trunk/unittests/Tooling/RecursiveASTVisitorTestExprVisitor.cpp 
(original)
+++ cfe/trunk/unittests/Tooling/RecursiveASTVisitorTestExprVisitor.cpp Wed Aug 
17 09:59:53 2016
@@ -161,10 +161,2

[clang-tools-extra] r278934 - Adapt to TraverseLambdaCapture interface change from D23204

2016-08-17 Thread Martin Bohme via cfe-commits
Author: mboehme
Date: Wed Aug 17 10:00:22 2016
New Revision: 278934

URL: http://llvm.org/viewvc/llvm-project?rev=278934&view=rev
Log:
Adapt to TraverseLambdaCapture interface change from D23204

Summary:
Depends on D23204.

This is intended to be submitted immediately after D23204 lands.

Reviewers: jdennett, alexfh

Subscribers: cfe-commits

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

Modified:
clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertUtils.cpp
clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertUtils.h
clang-tools-extra/trunk/modularize/Modularize.cpp

Modified: clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertUtils.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertUtils.cpp?rev=278934&r1=278933&r2=278934&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertUtils.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertUtils.cpp Wed Aug 
17 10:00:22 2016
@@ -763,7 +763,8 @@ bool ForLoopIndexUseVisitor::VisitDeclRe
 ///   }
 /// \endcode
 bool ForLoopIndexUseVisitor::TraverseLambdaCapture(LambdaExpr *LE,
-   const LambdaCapture *C) {
+   const LambdaCapture *C,
+   Expr *Init) {
   if (C->capturesVariable()) {
 const VarDecl *VDecl = C->getCapturedVar();
 if (areSameVariable(IndexVar, cast(VDecl))) {
@@ -776,7 +777,7 @@ bool ForLoopIndexUseVisitor::TraverseLam
  C->getLocation()));
 }
   }
-  return VisitorBase::TraverseLambdaCapture(LE, C);
+  return VisitorBase::TraverseLambdaCapture(LE, C, Init);
 }
 
 /// \brief If we find that another variable is created just to refer to the 
loop

Modified: clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertUtils.h
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertUtils.h?rev=278934&r1=278933&r2=278934&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertUtils.h (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertUtils.h Wed Aug 17 
10:00:22 2016
@@ -337,7 +337,8 @@ private:
   bool TraverseArraySubscriptExpr(ArraySubscriptExpr *E);
   bool TraverseCXXMemberCallExpr(CXXMemberCallExpr *MemberCall);
   bool TraverseCXXOperatorCallExpr(CXXOperatorCallExpr *OpCall);
-  bool TraverseLambdaCapture(LambdaExpr *LE, const LambdaCapture *C);
+  bool TraverseLambdaCapture(LambdaExpr *LE, const LambdaCapture *C,
+ Expr *Init);
   bool TraverseMemberExpr(MemberExpr *Member);
   bool TraverseUnaryDeref(UnaryOperator *Uop);
   bool VisitDeclRefExpr(DeclRefExpr *E);

Modified: clang-tools-extra/trunk/modularize/Modularize.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/modularize/Modularize.cpp?rev=278934&r1=278933&r2=278934&view=diff
==
--- clang-tools-extra/trunk/modularize/Modularize.cpp (original)
+++ clang-tools-extra/trunk/modularize/Modularize.cpp Wed Aug 17 10:00:22 2016
@@ -571,7 +571,10 @@ public:
 return true;
   }
   bool TraverseConstructorInitializer(CXXCtorInitializer *Init) { return true; 
}
-  bool TraverseLambdaCapture(LambdaCapture C) { return true; }
+  bool TraverseLambdaCapture(LambdaExpr *LE, const LambdaCapture *C,
+ Expr *Init) {
+return true;
+  }
 
   // Check 'extern "*" {}' block for #include directives.
   bool VisitLinkageSpecDecl(LinkageSpecDecl *D) {
@@ -756,7 +759,10 @@ public:
 return true;
   }
   bool TraverseConstructorInitializer(CXXCtorInitializer *Init) { return true; 
}
-  bool TraverseLambdaCapture(LambdaCapture C) { return true; }
+  bool TraverseLambdaCapture(LambdaExpr *LE, const LambdaCapture *C,
+ Expr *Init) {
+return true;
+  }
 
   // Check 'extern "*" {}' block for #include directives.
   bool VisitLinkageSpecDecl(LinkageSpecDecl *D) {


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


[clang-tools-extra] r280077 - [clang-tidy] Add check 'misc-move-forwarding-reference'

2016-08-30 Thread Martin Bohme via cfe-commits
Author: mboehme
Date: Tue Aug 30 07:11:12 2016
New Revision: 280077

URL: http://llvm.org/viewvc/llvm-project?rev=280077&view=rev
Log:
[clang-tidy] Add check 'misc-move-forwarding-reference'

Summary:
The check emits a warning if std::move() is applied to a forwarding reference, 
i.e. an rvalue reference of a function template argument type.

If a developer is unaware of the special rules for template argument deduction 
on forwarding references, it will seem reasonable to apply std::move() to the 
forwarding reference, in the same way that this would be done for a "normal" 
rvalue reference.

This has a consequence that is usually unwanted and possibly surprising: If the 
function that takes the forwarding reference as its parameter is called with an 
lvalue, that lvalue will be moved from (and hence placed into an indeterminate 
state) even though no std::move() was applied to the lvalue at the callsite.

As a fix, the check will suggest replacing the std::move() with a 
std::forward().

This patch requires D23004 to be submitted before it.

Reviewers: sbenza, aaron.ballman

Subscribers: klimek, etienneb, alexfh, aaron.ballman, Prazek, Eugene.Zelenko, 
mgehre, cfe-commits

Projects: #clang-tools-extra

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

Added:
clang-tools-extra/trunk/clang-tidy/misc/MoveForwardingReferenceCheck.cpp
clang-tools-extra/trunk/clang-tidy/misc/MoveForwardingReferenceCheck.h

clang-tools-extra/trunk/docs/clang-tidy/checks/misc-move-forwarding-reference.rst
clang-tools-extra/trunk/test/clang-tidy/misc-move-forwarding-reference.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/misc/MiscTidyModule.cpp
clang-tools-extra/trunk/docs/ReleaseNotes.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst

Modified: clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt?rev=280077&r1=280076&r2=280077&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt Tue Aug 30 07:11:12 
2016
@@ -19,6 +19,7 @@ add_clang_library(clangTidyMiscModule
   MisplacedWideningCastCheck.cpp
   MoveConstantArgumentCheck.cpp
   MoveConstructorInitCheck.cpp
+  MoveForwardingReferenceCheck.cpp
   MultipleStatementMacroCheck.cpp
   NewDeleteOverloadsCheck.cpp
   NoexceptMoveConstructorCheck.cpp

Modified: clang-tools-extra/trunk/clang-tidy/misc/MiscTidyModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/MiscTidyModule.cpp?rev=280077&r1=280076&r2=280077&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/misc/MiscTidyModule.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/MiscTidyModule.cpp Tue Aug 30 
07:11:12 2016
@@ -27,6 +27,7 @@
 #include "MisplacedWideningCastCheck.h"
 #include "MoveConstantArgumentCheck.h"
 #include "MoveConstructorInitCheck.h"
+#include "MoveForwardingReferenceCheck.h"
 #include "MultipleStatementMacroCheck.h"
 #include "NewDeleteOverloadsCheck.h"
 #include "NoexceptMoveConstructorCheck.h"
@@ -92,6 +93,8 @@ public:
 "misc-move-const-arg");
 CheckFactories.registerCheck(
 "misc-move-constructor-init");
+CheckFactories.registerCheck(
+"misc-move-forwarding-reference");
 CheckFactories.registerCheck(
 "misc-multiple-statement-macro");
 CheckFactories.registerCheck(

Added: clang-tools-extra/trunk/clang-tidy/misc/MoveForwardingReferenceCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/MoveForwardingReferenceCheck.cpp?rev=280077&view=auto
==
--- clang-tools-extra/trunk/clang-tidy/misc/MoveForwardingReferenceCheck.cpp 
(added)
+++ clang-tools-extra/trunk/clang-tidy/misc/MoveForwardingReferenceCheck.cpp 
Tue Aug 30 07:11:12 2016
@@ -0,0 +1,134 @@
+//===--- MoveForwardingReferenceCheck.cpp - clang-tidy 
===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "MoveForwardingReferenceCheck.h"
+#include "clang/Lex/Lexer.h"
+#include "llvm/Support/raw_ostream.h"
+
+#include 
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace misc {
+
+static void replaceMoveWithForward(const UnresolvedLookupExpr *Callee,
+   const ParmVarDecl *ParmVar,
+   const TemplateTypeParmDecl *TypeParmDecl,
+   Diagnost

r281200 - [CFG] Add iterator_ranges to CFG and CFGBlock.

2016-09-12 Thread Martin Bohme via cfe-commits
Author: mboehme
Date: Mon Sep 12 03:28:21 2016
New Revision: 281200

URL: http://llvm.org/viewvc/llvm-project?rev=281200&view=rev
Log:
[CFG] Add iterator_ranges to CFG and CFGBlock.

Summary: (Needed for D23353.)

Reviewers: alexfh

Subscribers: cfe-commits

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

Modified:
cfe/trunk/include/clang/Analysis/CFG.h

Modified: cfe/trunk/include/clang/Analysis/CFG.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/CFG.h?rev=281200&r1=281199&r2=281200&view=diff
==
--- cfe/trunk/include/clang/Analysis/CFG.h (original)
+++ cfe/trunk/include/clang/Analysis/CFG.h Mon Sep 12 03:28:21 2016
@@ -22,6 +22,7 @@
 #include "llvm/ADT/GraphTraits.h"
 #include "llvm/ADT/Optional.h"
 #include "llvm/ADT/PointerIntPair.h"
+#include "llvm/ADT/iterator_range.h"
 #include "llvm/Support/Allocator.h"
 #include "llvm/Support/Casting.h"
 #include "llvm/Support/raw_ostream.h"
@@ -522,11 +523,15 @@ public:
   typedef AdjacentBlocks::const_iterator  const_pred_iterator;
   typedef AdjacentBlocks::reverse_iterator  pred_reverse_iterator;
   typedef AdjacentBlocks::const_reverse_iterator  const_pred_reverse_iterator;
+  typedef llvm::iterator_range  pred_range;
+  typedef llvm::iterator_range  pred_const_range;
 
   typedef AdjacentBlocks::iterator  succ_iterator;
   typedef AdjacentBlocks::const_iterator  const_succ_iterator;
   typedef AdjacentBlocks::reverse_iterator  succ_reverse_iterator;
   typedef AdjacentBlocks::const_reverse_iterator  const_succ_reverse_iterator;
+  typedef llvm::iterator_range  succ_range;
+  typedef llvm::iterator_range  succ_const_range;
 
   pred_iteratorpred_begin(){ return Preds.begin();   }
   pred_iteratorpred_end()  { return Preds.end(); }
@@ -538,6 +543,13 @@ public:
   const_pred_reverse_iterator  pred_rbegin() const { return Preds.rbegin();  }
   const_pred_reverse_iterator  pred_rend()   const { return Preds.rend();}
 
+  pred_range   preds() {
+return pred_range(pred_begin(), pred_end());
+  }
+  pred_const_range preds() const {
+return pred_const_range(pred_begin(), pred_end());
+  }
+
   succ_iteratorsucc_begin(){ return Succs.begin();   }
   succ_iteratorsucc_end()  { return Succs.end(); }
   const_succ_iterator  succ_begin()  const { return Succs.begin();   }
@@ -548,6 +560,13 @@ public:
   const_succ_reverse_iterator  succ_rbegin() const { return Succs.rbegin();  }
   const_succ_reverse_iterator  succ_rend()   const { return Succs.rend();}
 
+  succ_range   succs() {
+return succ_range(succ_begin(), succ_end());
+  }
+  succ_const_range succs() const {
+return succ_const_range(succ_begin(), succ_end());
+  }
+
   unsigned succ_size()   const { return Succs.size();}
   bool succ_empty()  const { return Succs.empty();   }
 
@@ -840,6 +859,7 @@ public:
 
   typedef llvm::DenseMap::const_iterator
 synthetic_stmt_iterator;
+  typedef llvm::iterator_range synthetic_stmt_range;
 
   /// Iterates over synthetic DeclStmts in the CFG.
   ///
@@ -855,6 +875,11 @@ public:
 return SyntheticDeclStmts.end();
   }
 
+  /// \sa synthetic_stmt_begin
+  synthetic_stmt_range synthetic_stmts() const {
+return synthetic_stmt_range(synthetic_stmt_begin(), synthetic_stmt_end());
+  }
+
   
//======//
   // Member templates useful for various batch operations over CFGs.
   
//======//


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


[clang-tools-extra] r281453 - [clang-tidy] Add check 'misc-use-after-move'

2016-09-14 Thread Martin Bohme via cfe-commits
Author: mboehme
Date: Wed Sep 14 05:29:32 2016
New Revision: 281453

URL: http://llvm.org/viewvc/llvm-project?rev=281453&view=rev
Log:
[clang-tidy] Add check 'misc-use-after-move'

Summary:
The check warns if an object is used after it has been moved, without an
intervening reinitialization.

See user-facing documentation for details.

Reviewers: sbenza, Prazek, alexfh

Subscribers: beanz, mgorny, shadeware, omtcyfz, Eugene.Zelenko, Prazek, fowles, 
ioeric, cfe-commits

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

Added:
clang-tools-extra/trunk/clang-tidy/misc/UseAfterMoveCheck.cpp
clang-tools-extra/trunk/clang-tidy/misc/UseAfterMoveCheck.h
clang-tools-extra/trunk/docs/clang-tidy/checks/misc-use-after-move.rst
clang-tools-extra/trunk/test/clang-tidy/misc-use-after-move.cpp
Modified:
clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt
clang-tools-extra/trunk/clang-tidy/misc/MiscTidyModule.cpp
clang-tools-extra/trunk/docs/ReleaseNotes.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/list.rst

Modified: clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt?rev=281453&r1=281452&r2=281453&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt Wed Sep 14 05:29:32 
2016
@@ -43,6 +43,7 @@ add_clang_library(clangTidyMiscModule
   UnusedParametersCheck.cpp
   UnusedRAIICheck.cpp
   UnusedUsingDeclsCheck.cpp
+  UseAfterMoveCheck.cpp
   VirtualNearMissCheck.cpp
 
   LINK_LIBS

Modified: clang-tools-extra/trunk/clang-tidy/misc/MiscTidyModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/MiscTidyModule.cpp?rev=281453&r1=281452&r2=281453&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/misc/MiscTidyModule.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/MiscTidyModule.cpp Wed Sep 14 
05:29:32 2016
@@ -51,6 +51,7 @@
 #include "UnusedParametersCheck.h"
 #include "UnusedRAIICheck.h"
 #include "UnusedUsingDeclsCheck.h"
+#include "UseAfterMoveCheck.h"
 #include "VirtualNearMissCheck.h"
 
 namespace clang {
@@ -139,6 +140,7 @@ public:
 CheckFactories.registerCheck("misc-unused-raii");
 CheckFactories.registerCheck(
 "misc-unused-using-decls");
+CheckFactories.registerCheck("misc-use-after-move");
 CheckFactories.registerCheck(
 "misc-virtual-near-miss");
   }

Added: clang-tools-extra/trunk/clang-tidy/misc/UseAfterMoveCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/UseAfterMoveCheck.cpp?rev=281453&view=auto
==
--- clang-tools-extra/trunk/clang-tidy/misc/UseAfterMoveCheck.cpp (added)
+++ clang-tools-extra/trunk/clang-tidy/misc/UseAfterMoveCheck.cpp Wed Sep 14 
05:29:32 2016
@@ -0,0 +1,643 @@
+//===--- UseAfterMoveCheck.cpp - clang-tidy 
---===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#include "UseAfterMoveCheck.h"
+
+#include "clang/Analysis/CFG.h"
+#include "clang/Lex/Lexer.h"
+#include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/SmallPtrSet.h"
+#include "llvm/ADT/SmallVector.h"
+
+#include 
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace misc {
+
+namespace {
+
+/// Provides information about the evaluation order of (sub-)expressions within
+/// a `CFGBlock`.
+///
+/// While a `CFGBlock` does contain individual `CFGElement`s for some
+/// sub-expressions, the order in which those `CFGElement`s appear reflects
+/// only one possible order in which the sub-expressions may be evaluated.
+/// However, we want to warn if any of the potential evaluation orders can lead
+/// to a use-after-move, not just the one contained in the `CFGBlock`.
+///
+/// This class implements only a simplified version of the C++ sequencing rules
+/// that is, however, sufficient for the purposes of this check. The main
+/// limitation is that we do not distinguish between value computation and side
+/// effect -- see the "Implementation" section for more details.
+///
+/// Note: `SequenceChecker` from SemaChecking.cpp does a similar job (and much
+/// more thoroughly), but using it would require
+/// - Pulling `SequenceChecker` out into a header file (i.e. making it part of
+///   the API),
+/// - Removing the dependency of `SequenceChecker` on `Sema`, and
+/// - (Probably) modifying `SequenceChecker` to make it suitable to be used in
+///   this context.
+/// For the moment, it se

[clang-tools-extra] r281455 - [clang-tidy] Make test for misc-use-after-move pass under Windows

2016-09-14 Thread Martin Bohme via cfe-commits
Author: mboehme
Date: Wed Sep 14 07:22:35 2016
New Revision: 281455

URL: http://llvm.org/viewvc/llvm-project?rev=281455&view=rev
Log:
[clang-tidy] Make test for misc-use-after-move pass under Windows

Summary: Adds -fno-delayed-template-parsing

Reviewers: alexfh

Subscribers: cfe-commits

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

Modified:
clang-tools-extra/trunk/test/clang-tidy/misc-use-after-move.cpp

Modified: clang-tools-extra/trunk/test/clang-tidy/misc-use-after-move.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/misc-use-after-move.cpp?rev=281455&r1=281454&r2=281455&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/misc-use-after-move.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/misc-use-after-move.cpp Wed Sep 14 
07:22:35 2016
@@ -1,4 +1,4 @@
-// RUN: %check_clang_tidy %s misc-use-after-move %t
+// RUN: %check_clang_tidy %s misc-use-after-move %t -- -- -std=c++11 
-fno-delayed-template-parsing
 
 typedef decltype(nullptr) nullptr_t;
 


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


[clang-tools-extra] r281460 - [clang-tidy] Add dependency on clangAnalysis to clangTidyMiscModule

2016-09-14 Thread Martin Bohme via cfe-commits
Author: mboehme
Date: Wed Sep 14 08:33:11 2016
New Revision: 281460

URL: http://llvm.org/viewvc/llvm-project?rev=281460&view=rev
Log:
[clang-tidy] Add dependency on clangAnalysis to clangTidyMiscModule

Summary:
This is needed for the recently submitted misc-use-after-move check (rL281453).
For some reason, this still built under Linux, but it caused the PPC build bot
to fail.

Subscribers: beanz, cfe-commits, mgorny

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

Modified:
clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt

Modified: clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt?rev=281460&r1=281459&r2=281460&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/CMakeLists.txt Wed Sep 14 08:33:11 
2016
@@ -47,6 +47,7 @@ add_clang_library(clangTidyMiscModule
   VirtualNearMissCheck.cpp
 
   LINK_LIBS
+  clangAnalysis
   clangAST
   clangASTMatchers
   clangBasic


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


r298503 - Revert "iFix Test deprecation behavior in C89 mode as a result of r298410"

2017-03-22 Thread Martin Bohme via cfe-commits
Author: mboehme
Date: Wed Mar 22 08:33:03 2017
New Revision: 298503

URL: http://llvm.org/viewvc/llvm-project?rev=298503&view=rev
Log:
Revert "iFix Test deprecation behavior in C89 mode as a result of r298410"

This reverts commit r298433. (Required to revert r298410, see comments
there.)

Modified:
cfe/trunk/test/Sema/attr-deprecated.c

Modified: cfe/trunk/test/Sema/attr-deprecated.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/attr-deprecated.c?rev=298503&r1=298502&r2=298503&view=diff
==
--- cfe/trunk/test/Sema/attr-deprecated.c (original)
+++ cfe/trunk/test/Sema/attr-deprecated.c Wed Mar 22 08:33:03 2017
@@ -1,6 +1,4 @@
 // RUN: %clang_cc1 %s -verify -fsyntax-only
-// RUN: %clang_cc1 %s -std=c99 -verify -fsyntax-only
-// RUN: %clang_cc1 %s -std=c89 -verify -fsyntax-only
 
 int f() __attribute__((deprecated)); // expected-note 2 {{'f' has been 
explicitly marked deprecated here}}
 void g() __attribute__((deprecated));// expected-note {{'g' has been 
explicitly marked deprecated here}}
@@ -123,12 +121,11 @@ struct test22 {
   __attribute((deprecated)) foo_dep e, f;
 };
 
-typedef int test23_ty __attribute((deprecated)); 
+typedef int test23_ty __attribute((deprecated)); // expected-note 
{{'test23_ty' has been explicitly marked deprecated here}}
 // Redefining a typedef is a C11 feature.
 #if __STDC_VERSION__ <= 199901L
 // expected-note@-3 {{'test23_ty' has been explicitly marked deprecated here}}
 #else
-// expected-note@-5 {{'test23_ty' has been explicitly marked deprecated here}}
 typedef int test23_ty; 
 #endif
 test23_ty test23_v; // expected-warning {{'test23_ty' is deprecated}}


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


r298504 - Revert "Correct class-template deprecation behavior"

2017-03-22 Thread Martin Bohme via cfe-commits
Author: mboehme
Date: Wed Mar 22 08:34:37 2017
New Revision: 298504

URL: http://llvm.org/viewvc/llvm-project?rev=298504&view=rev
Log:
Revert "Correct class-template deprecation behavior"

This reverts commit r298410 (which produces incorrect warnings, see
comments on https://reviews.llvm.org/rL298410).

Modified:
cfe/trunk/include/clang/Basic/Attr.td
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Sema/SemaDeclAttr.cpp
cfe/trunk/lib/Sema/SemaTemplate.cpp
cfe/trunk/lib/Sema/SemaTemplateInstantiate.cpp
cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
cfe/trunk/test/CXX/dcl.dcl/dcl.attr/dcl.attr.deprecated/p1.cpp
cfe/trunk/test/Sema/attr-deprecated.c
cfe/trunk/test/SemaCXX/attr-deprecated.cpp
cfe/trunk/test/SemaObjC/attr-deprecated.m
cfe/trunk/test/SemaObjC/special-dep-unavail-warning.m
cfe/trunk/test/SemaObjC/warn-deprecated-implementations.m
cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp

Modified: cfe/trunk/include/clang/Basic/Attr.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Attr.td?rev=298504&r1=298503&r2=298504&view=diff
==
--- cfe/trunk/include/clang/Basic/Attr.td (original)
+++ cfe/trunk/include/clang/Basic/Attr.td Wed Mar 22 08:34:37 2017
@@ -302,9 +302,6 @@ class Attr {
   // Set to true if this attribute can be duplicated on a subject when merging
   // attributes. By default, attributes are not merged.
   bit DuplicatesAllowedWhileMerging = 0;
-  // Set to true if this attribute is meaningful when applied to or inherited 
-  // in a class template definition.
-  bit MeaningfulToClassTemplateDefinition = 0;
   // Lists language options, one of which is required to be true for the
   // attribute to be applicable. If empty, no language options are required.
   list LangOpts = [];
@@ -376,7 +373,6 @@ def AbiTag : Attr {
   let Args = [VariadicStringArgument<"Tags">];
   let Subjects = SubjectList<[Struct, Var, Function, Namespace], ErrorDiag,
   "ExpectedStructClassVariableFunctionOrInlineNamespace">;
-  let MeaningfulToClassTemplateDefinition = 1;
   let Documentation = [AbiTagsDocs];
 }
 
@@ -809,7 +805,6 @@ def Deprecated : InheritableAttr {
   // An optional string argument that enables us to provide a
   // Fix-It.
   StringArgument<"Replacement", 1>];
-  let MeaningfulToClassTemplateDefinition = 1;
   let Documentation = [DeprecatedDocs];
 }
 
@@ -1728,7 +1723,6 @@ def Visibility : InheritableAttr {
   let Args = [EnumArgument<"Visibility", "VisibilityType",
["default", "hidden", "internal", "protected"],
["Default", "Hidden", "Hidden", "Protected"]>];
-  let MeaningfulToClassTemplateDefinition = 1;
   let Documentation = [Undocumented];
 }
 

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=298504&r1=298503&r2=298504&view=diff
==
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Wed Mar 22 08:34:37 2017
@@ -7505,12 +7505,6 @@ public:
 LateInstantiatedAttrVec *LateAttrs = nullptr,
 LocalInstantiationScope *OuterMostScope = nullptr);
 
-  void
-  InstantiateAttrsForDecl(const MultiLevelTemplateArgumentList &TemplateArgs,
-  const Decl *Pattern, Decl *Inst,
-  LateInstantiatedAttrVec *LateAttrs = nullptr,
-  LocalInstantiationScope *OuterMostScope = nullptr);
-
   bool
   InstantiateClassTemplateSpecialization(SourceLocation PointOfInstantiation,
ClassTemplateSpecializationDecl *ClassTemplateSpec,

Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=298504&r1=298503&r2=298504&view=diff
==
--- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Wed Mar 22 08:34:37 2017
@@ -6723,7 +6723,6 @@ static void DoEmitAvailabilityWarning(Se
   // Diagnostics for deprecated or unavailable.
   unsigned diag, diag_message, diag_fwdclass_message;
   unsigned diag_available_here = diag::note_availability_specified_here;
-  SourceLocation NoteLocation = D->getLocation();
 
   // Matches 'diag::note_property_attribute' options.
   unsigned property_note_select;
@@ -6746,8 +6745,6 @@ static void DoEmitAvailabilityWarning(Se
 diag_fwdclass_message = diag::warn_deprecated_fwdclass_message;
 property_note_select = /* deprecated */ 0;
 available_here_select_kind = /* deprecated */ 2;
-if (auto *attr = D->getAttr())
-  NoteLocation = attr->getLocation();
 break;
 
   case AR_Unavailable:
@@ -6866,7 +6863,7 @@ static void D

r292791 - Revert "IRGen: Start using the WriteThinLTOBitcode pass."

2017-01-23 Thread Martin Bohme via cfe-commits
Author: mboehme
Date: Mon Jan 23 08:33:42 2017
New Revision: 292791

URL: http://llvm.org/viewvc/llvm-project?rev=292791&view=rev
Log:
Revert "IRGen: Start using the WriteThinLTOBitcode pass."

Summary:
This reverts commit r292662.

This change broke internal builds. Will provide a reproducer internally.

Subscribers: pcc, mehdi_amini, cfe-commits, mgorny

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

Removed:
cfe/trunk/test/CodeGenCXX/type-metadata-thinlto.cpp
Modified:
cfe/trunk/lib/CodeGen/BackendUtil.cpp
cfe/trunk/test/CMakeLists.txt

Modified: cfe/trunk/lib/CodeGen/BackendUtil.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/BackendUtil.cpp?rev=292791&r1=292790&r2=292791&view=diff
==
--- cfe/trunk/lib/CodeGen/BackendUtil.cpp (original)
+++ cfe/trunk/lib/CodeGen/BackendUtil.cpp Mon Jan 23 08:33:42 2017
@@ -689,11 +689,9 @@ void EmitAssemblyHelper::EmitAssembly(Ba
 break;
 
   case Backend_EmitBC:
-if (CodeGenOpts.EmitSummaryIndex)
-  PerModulePasses.add(createWriteThinLTOBitcodePass(*OS));
-else
-  PerModulePasses.add(
-  createBitcodeWriterPass(*OS, CodeGenOpts.EmitLLVMUseLists));
+PerModulePasses.add(createBitcodeWriterPass(
+*OS, CodeGenOpts.EmitLLVMUseLists, CodeGenOpts.EmitSummaryIndex,
+CodeGenOpts.EmitSummaryIndex));
 break;
 
   case Backend_EmitLL:

Modified: cfe/trunk/test/CMakeLists.txt
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CMakeLists.txt?rev=292791&r1=292790&r2=292791&view=diff
==
--- cfe/trunk/test/CMakeLists.txt (original)
+++ cfe/trunk/test/CMakeLists.txt Mon Jan 23 08:33:42 2017
@@ -80,7 +80,6 @@ if( NOT CLANG_BUILT_STANDALONE )
 llc
 llvm-bcanalyzer
 llvm-dis
-llvm-modextract
 llvm-nm
 llvm-objdump
 llvm-profdata

Removed: cfe/trunk/test/CodeGenCXX/type-metadata-thinlto.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/type-metadata-thinlto.cpp?rev=292790&view=auto
==
--- cfe/trunk/test/CodeGenCXX/type-metadata-thinlto.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/type-metadata-thinlto.cpp (removed)
@@ -1,11 +0,0 @@
-// RUN: %clang_cc1 -flto=thin -flto-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
-
-// CHECK: @_ZTV1A = linkonce_odr
-class A {
-  virtual void f() {}
-};
-
-A *f() {
-  return new A;
-}


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


r293051 - [Driver] Prevent no-arc-exception-silence.m test from writing output.

2017-01-25 Thread Martin Bohme via cfe-commits
Author: mboehme
Date: Wed Jan 25 06:55:53 2017
New Revision: 293051

URL: http://llvm.org/viewvc/llvm-project?rev=293051&view=rev
Log:
[Driver] Prevent no-arc-exception-silence.m test from writing output.

Summary: This enables the test to run on systems where output cannot be written.

Reviewers: compnerd

Subscribers: cfe-commits

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

Modified:
cfe/trunk/test/Driver/no-arc-exception-silence.m

Modified: cfe/trunk/test/Driver/no-arc-exception-silence.m
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/no-arc-exception-silence.m?rev=293051&r1=293050&r2=293051&view=diff
==
--- cfe/trunk/test/Driver/no-arc-exception-silence.m (original)
+++ cfe/trunk/test/Driver/no-arc-exception-silence.m Wed Jan 25 06:55:53 2017
@@ -1,2 +1,2 @@
-// RUN: %clang -Werror -fobjc-arc -fobjc-arc-exceptions -fno-objc-arc -Xclang 
-verify -c %s
+// RUN: %clang -Werror -fobjc-arc -fobjc-arc-exceptions -fno-objc-arc -Xclang 
-verify -c -o /dev/null %s
 // expected-no-diagnostics


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


[clang-tools-extra] r297004 - [clang-tidy] misc-use-after-move: Fix failing assertion

2017-03-06 Thread Martin Bohme via cfe-commits
Author: mboehme
Date: Mon Mar  6 02:55:42 2017
New Revision: 297004

URL: http://llvm.org/viewvc/llvm-project?rev=297004&view=rev
Log:
[clang-tidy] misc-use-after-move: Fix failing assertion

Summary:
I've added a test case that (without the fix) triggers the assertion,
which happens when a move happens in an implicitly called conversion
operator.

Reviewers: alexfh

Reviewed By: alexfh

Subscribers: JDevlieghere, cfe-commits

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

Modified:
clang-tools-extra/trunk/clang-tidy/misc/UseAfterMoveCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/misc-use-after-move.cpp

Modified: clang-tools-extra/trunk/clang-tidy/misc/UseAfterMoveCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/UseAfterMoveCheck.cpp?rev=297004&r1=297003&r2=297004&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/misc/UseAfterMoveCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/UseAfterMoveCheck.cpp Mon Mar  6 
02:55:42 2017
@@ -398,7 +398,7 @@ void UseAfterMoveCheck::check(const Matc
   const auto *MovingCall = Result.Nodes.getNodeAs("moving-call");
   const auto *Arg = Result.Nodes.getNodeAs("arg");
 
-  if (!MovingCall)
+  if (!MovingCall || !MovingCall->getExprLoc().isValid())
 MovingCall = CallMove;
 
   Stmt *FunctionBody = nullptr;

Modified: clang-tools-extra/trunk/test/clang-tidy/misc-use-after-move.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/misc-use-after-move.cpp?rev=297004&r1=297003&r2=297004&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/misc-use-after-move.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/misc-use-after-move.cpp Mon Mar  6 
02:55:42 2017
@@ -282,7 +282,7 @@ void moveInInitList() {
   S s{std::move(a)};
   a.foo();
   // CHECK-MESSAGES: [[@LINE-1]]:3: warning: 'a' used after it was moved
-  // CHECK-MESSAGES: [[@LINE-3]]:6: note: move occurred here
+  // CHECK-MESSAGES: [[@LINE-3]]:7: note: move occurred here
 }
 
 void lambdas() {
@@ -397,6 +397,21 @@ void movedTypeIsDependentType() {
 }
 template void movedTypeIsDependentType();
 
+// We handle the case correctly where the move consists of an implicit call
+// to a conversion operator.
+void implicitConversionOperator() {
+  struct Convertible {
+operator A() && { return A(); }
+  };
+  void takeA(A a);
+
+  Convertible convertible;
+  takeA(std::move(convertible));
+  convertible;
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: 'convertible' used after it was 
moved
+  // CHECK-MESSAGES: [[@LINE-3]]:9: note: move occurred here
+}
+
 // Using decltype on an expression is not a use.
 void decltypeIsNotUse() {
   A a;


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


[clang-tools-extra] r297006 - Revert "[clang-tidy] misc-use-after-move: Fix failing assertion"

2017-03-06 Thread Martin Bohme via cfe-commits
Author: mboehme
Date: Mon Mar  6 03:46:27 2017
New Revision: 297006

URL: http://llvm.org/viewvc/llvm-project?rev=297006&view=rev
Log:
Revert "[clang-tidy] misc-use-after-move: Fix failing assertion"

This reverts commit r297004; it was causing buildbots to fail.

Modified:
clang-tools-extra/trunk/clang-tidy/misc/UseAfterMoveCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/misc-use-after-move.cpp

Modified: clang-tools-extra/trunk/clang-tidy/misc/UseAfterMoveCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/UseAfterMoveCheck.cpp?rev=297006&r1=297005&r2=297006&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/misc/UseAfterMoveCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/UseAfterMoveCheck.cpp Mon Mar  6 
03:46:27 2017
@@ -398,7 +398,7 @@ void UseAfterMoveCheck::check(const Matc
   const auto *MovingCall = Result.Nodes.getNodeAs("moving-call");
   const auto *Arg = Result.Nodes.getNodeAs("arg");
 
-  if (!MovingCall || !MovingCall->getExprLoc().isValid())
+  if (!MovingCall)
 MovingCall = CallMove;
 
   Stmt *FunctionBody = nullptr;

Modified: clang-tools-extra/trunk/test/clang-tidy/misc-use-after-move.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/misc-use-after-move.cpp?rev=297006&r1=297005&r2=297006&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/misc-use-after-move.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/misc-use-after-move.cpp Mon Mar  6 
03:46:27 2017
@@ -282,7 +282,7 @@ void moveInInitList() {
   S s{std::move(a)};
   a.foo();
   // CHECK-MESSAGES: [[@LINE-1]]:3: warning: 'a' used after it was moved
-  // CHECK-MESSAGES: [[@LINE-3]]:7: note: move occurred here
+  // CHECK-MESSAGES: [[@LINE-3]]:6: note: move occurred here
 }
 
 void lambdas() {
@@ -397,21 +397,6 @@ void movedTypeIsDependentType() {
 }
 template void movedTypeIsDependentType();
 
-// We handle the case correctly where the move consists of an implicit call
-// to a conversion operator.
-void implicitConversionOperator() {
-  struct Convertible {
-operator A() && { return A(); }
-  };
-  void takeA(A a);
-
-  Convertible convertible;
-  takeA(std::move(convertible));
-  convertible;
-  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: 'convertible' used after it was 
moved
-  // CHECK-MESSAGES: [[@LINE-3]]:9: note: move occurred here
-}
-
 // Using decltype on an expression is not a use.
 void decltypeIsNotUse() {
   A a;


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


r297129 - [analyzer] Fix crash when building CFG with variable of incomplete type

2017-03-07 Thread Martin Bohme via cfe-commits
Author: mboehme
Date: Tue Mar  7 02:42:37 2017
New Revision: 297129

URL: http://llvm.org/viewvc/llvm-project?rev=297129&view=rev
Log:
[analyzer] Fix crash when building CFG with variable of incomplete type

Summary:
I've included a unit test with a function template containing a variable
of incomplete type. Clang compiles this without errors (the standard
does not require a diagnostic in this case). Without the fix, this case
triggers the crash.

Reviewers: klimek

Reviewed By: klimek

Subscribers: cfe-commits

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

Modified:
cfe/trunk/lib/Analysis/CFG.cpp
cfe/trunk/unittests/Analysis/CFGTest.cpp

Modified: cfe/trunk/lib/Analysis/CFG.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CFG.cpp?rev=297129&r1=297128&r2=297129&view=diff
==
--- cfe/trunk/lib/Analysis/CFG.cpp (original)
+++ cfe/trunk/lib/Analysis/CFG.cpp Tue Mar  7 02:42:37 2017
@@ -1390,7 +1390,7 @@ LocalScope* CFGBuilder::addLocalScopeFor
 
   // Check if type is a C++ class with non-trivial destructor.
   if (const CXXRecordDecl *CD = QT->getAsCXXRecordDecl())
-if (!CD->hasTrivialDestructor()) {
+if (CD->hasDefinition() && !CD->hasTrivialDestructor()) {
   // Add the variable to scope
   Scope = createOrReuseLocalScope(Scope);
   Scope->addVar(VD);

Modified: cfe/trunk/unittests/Analysis/CFGTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Analysis/CFGTest.cpp?rev=297129&r1=297128&r2=297129&view=diff
==
--- cfe/trunk/unittests/Analysis/CFGTest.cpp (original)
+++ cfe/trunk/unittests/Analysis/CFGTest.cpp Tue Mar  7 02:42:37 2017
@@ -35,7 +35,9 @@ public:
 if (!Body)
   return;
 TheBuildResult = SawFunctionBody;
-if (CFG::buildCFG(nullptr, Body, Result.Context, CFG::BuildOptions()))
+CFG::BuildOptions Options;
+Options.AddImplicitDtors = true;
+if (CFG::buildCFG(nullptr, Body, Result.Context, Options))
 TheBuildResult = BuiltCFG;
   }
 };
@@ -74,6 +76,16 @@ TEST(CFG, DeleteExpressionOnDependentTyp
  "}\n";
   EXPECT_EQ(BuiltCFG, BuildCFG(Code));
 }
+
+// Constructing a CFG on a function template with a variable of incomplete type
+// should not crash.
+TEST(CFG, VariableOfIncompleteType) {
+  const char *Code = "template void f() {\n"
+ "  class Undefined;\n"
+ "  Undefined u;\n"
+ "}\n";
+  EXPECT_EQ(BuiltCFG, BuildCFG(Code));
+}
 
 } // namespace
 } // namespace analysis


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


[clang-tools-extra] r297272 - [clang-tidy] misc-use-after-move: Fix failing assertion

2017-03-08 Thread Martin Bohme via cfe-commits
Author: mboehme
Date: Wed Mar  8 06:34:51 2017
New Revision: 297272

URL: http://llvm.org/viewvc/llvm-project?rev=297272&view=rev
Log:
[clang-tidy] misc-use-after-move: Fix failing assertion

Summary:
I've added a test case that (without the fix) triggers the assertion,
which happens when a move happens in an implicitly called conversion
operator.

This patch also fixes nondeterministic behavior in the source code
location reported for the move when the move is constained in an init list;
this was causing buildbot failures in the previous attempt to submit
this patch (see D30569 and rL297004).

Reviewers: alexfh

Reviewed By: alexfh

Subscribers: Eugene.Zelenko, JDevlieghere, cfe-commits

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

Modified:
clang-tools-extra/trunk/clang-tidy/misc/UseAfterMoveCheck.cpp
clang-tools-extra/trunk/test/clang-tidy/misc-use-after-move.cpp

Modified: clang-tools-extra/trunk/clang-tidy/misc/UseAfterMoveCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/UseAfterMoveCheck.cpp?rev=297272&r1=297271&r2=297272&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/misc/UseAfterMoveCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/UseAfterMoveCheck.cpp Wed Mar  8 
06:34:51 2017
@@ -384,6 +384,13 @@ void UseAfterMoveCheck::registerMatchers
   // the direct ancestor of the std::move() that isn't one of the node
   // types ignored by ignoringParenImpCasts().
   stmt(forEach(expr(ignoringParenImpCasts(CallMoveMatcher))),
+   // Don't allow an InitListExpr to be the moving call. An 
InitListExpr
+   // has both a syntactic and a semantic form, and the parent-child
+   // relationships are different between the two. This could cause an
+   // InitListExpr to be analyzed as the moving call in addition to the
+   // Expr that we actually want, resulting in two diagnostics with
+   // different code locations for the same move.
+   unless(initListExpr()),
unless(expr(ignoringParenImpCasts(equalsBoundNode("call-move")
   .bind("moving-call"),
   this);
@@ -398,7 +405,7 @@ void UseAfterMoveCheck::check(const Matc
   const auto *MovingCall = Result.Nodes.getNodeAs("moving-call");
   const auto *Arg = Result.Nodes.getNodeAs("arg");
 
-  if (!MovingCall)
+  if (!MovingCall || !MovingCall->getExprLoc().isValid())
 MovingCall = CallMove;
 
   Stmt *FunctionBody = nullptr;

Modified: clang-tools-extra/trunk/test/clang-tidy/misc-use-after-move.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/misc-use-after-move.cpp?rev=297272&r1=297271&r2=297272&view=diff
==
--- clang-tools-extra/trunk/test/clang-tidy/misc-use-after-move.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/misc-use-after-move.cpp Wed Mar  8 
06:34:51 2017
@@ -282,7 +282,7 @@ void moveInInitList() {
   S s{std::move(a)};
   a.foo();
   // CHECK-MESSAGES: [[@LINE-1]]:3: warning: 'a' used after it was moved
-  // CHECK-MESSAGES: [[@LINE-3]]:6: note: move occurred here
+  // CHECK-MESSAGES: [[@LINE-3]]:7: note: move occurred here
 }
 
 void lambdas() {
@@ -397,6 +397,21 @@ void movedTypeIsDependentType() {
 }
 template void movedTypeIsDependentType();
 
+// We handle the case correctly where the move consists of an implicit call
+// to a conversion operator.
+void implicitConversionOperator() {
+  struct Convertible {
+operator A() && { return A(); }
+  };
+  void takeA(A a);
+
+  Convertible convertible;
+  takeA(std::move(convertible));
+  convertible;
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: 'convertible' used after it was 
moved
+  // CHECK-MESSAGES: [[@LINE-3]]:9: note: move occurred here
+}
+
 // Using decltype on an expression is not a use.
 void decltypeIsNotUse() {
   A a;


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


r288665 - CFGBuilder: Fix crash when visiting delete expression on dependent type

2016-12-05 Thread Martin Bohme via cfe-commits
Author: mboehme
Date: Mon Dec  5 05:33:19 2016
New Revision: 288665

URL: http://llvm.org/viewvc/llvm-project?rev=288665&view=rev
Log:
CFGBuilder: Fix crash when visiting delete expression on dependent type

Summary:
CXXDeleteExpr::getDestroyedType() can return a null QualType if the destroyed
type is a dependent type. This patch protects against this.

Reviewers: klimek

Subscribers: cfe-commits

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

Modified:
cfe/trunk/lib/Analysis/CFG.cpp
cfe/trunk/unittests/Analysis/CFGTest.cpp

Modified: cfe/trunk/lib/Analysis/CFG.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Analysis/CFG.cpp?rev=288665&r1=288664&r2=288665&view=diff
==
--- cfe/trunk/lib/Analysis/CFG.cpp (original)
+++ cfe/trunk/lib/Analysis/CFG.cpp Mon Dec  5 05:33:19 2016
@@ -3581,11 +3581,13 @@ CFGBlock *CFGBuilder::VisitCXXDeleteExpr
   autoCreateBlock();
   appendStmt(Block, DE);
   QualType DTy = DE->getDestroyedType();
-  DTy = DTy.getNonReferenceType();
-  CXXRecordDecl *RD = Context->getBaseElementType(DTy)->getAsCXXRecordDecl();
-  if (RD) {
-if (RD->isCompleteDefinition() && !RD->hasTrivialDestructor())
-  appendDeleteDtor(Block, RD, DE);
+  if (!DTy.isNull()) {
+DTy = DTy.getNonReferenceType();
+CXXRecordDecl *RD = Context->getBaseElementType(DTy)->getAsCXXRecordDecl();
+if (RD) {
+  if (RD->isCompleteDefinition() && !RD->hasTrivialDestructor())
+appendDeleteDtor(Block, RD, DE);
+}
   }
 
   return VisitChildren(DE);

Modified: cfe/trunk/unittests/Analysis/CFGTest.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Analysis/CFGTest.cpp?rev=288665&r1=288664&r2=288665&view=diff
==
--- cfe/trunk/unittests/Analysis/CFGTest.cpp (original)
+++ cfe/trunk/unittests/Analysis/CFGTest.cpp Mon Dec  5 05:33:19 2016
@@ -18,6 +18,41 @@ namespace clang {
 namespace analysis {
 namespace {
 
+enum BuildResult {
+  ToolFailed,
+  ToolRan,
+  SawFunctionBody,
+  BuiltCFG,
+};
+
+class CFGCallback : public ast_matchers::MatchFinder::MatchCallback {
+public:
+  BuildResult TheBuildResult = ToolRan;
+
+  void run(const ast_matchers::MatchFinder::MatchResult &Result) override {
+const auto *Func = Result.Nodes.getNodeAs("func");
+Stmt *Body = Func->getBody();
+if (!Body)
+  return;
+TheBuildResult = SawFunctionBody;
+if (CFG::buildCFG(nullptr, Body, Result.Context, CFG::BuildOptions()))
+TheBuildResult = BuiltCFG;
+  }
+};
+
+BuildResult BuildCFG(const char *Code) {
+  CFGCallback Callback;
+
+  ast_matchers::MatchFinder Finder;
+  Finder.addMatcher(ast_matchers::functionDecl().bind("func"), &Callback);
+  std::unique_ptr Factory(
+  tooling::newFrontendActionFactory(&Finder));
+  std::vector Args = {"-std=c++11", 
"-fno-delayed-template-parsing"};
+  if (!tooling::runToolOnCodeWithArgs(Factory->create(), Code, Args))
+return ToolFailed;
+  return Callback.TheBuildResult;
+}
+
 // Constructing a CFG for a range-based for over a dependent type fails (but
 // should not crash).
 TEST(CFG, RangeBasedForOverDependentType) {
@@ -27,30 +62,17 @@ TEST(CFG, RangeBasedForOverDependentType
  "  for (const Foo *TheFoo : Range) {\n"
  "  }\n"
  "}\n";
+  EXPECT_EQ(SawFunctionBody, BuildCFG(Code));
+}
 
-  class CFGCallback : public ast_matchers::MatchFinder::MatchCallback {
-  public:
-bool SawFunctionBody = false;
-
-void run(const ast_matchers::MatchFinder::MatchResult &Result) override {
-  const auto *Func = Result.Nodes.getNodeAs("func");
-  Stmt *Body = Func->getBody();
-  if (!Body)
-return;
-  SawFunctionBody = true;
-  std::unique_ptr cfg =
-  CFG::buildCFG(nullptr, Body, Result.Context, CFG::BuildOptions());
-  EXPECT_EQ(nullptr, cfg);
-}
-  } Callback;
-
-  ast_matchers::MatchFinder Finder;
-  Finder.addMatcher(ast_matchers::functionDecl().bind("func"), &Callback);
-  std::unique_ptr Factory(
-  tooling::newFrontendActionFactory(&Finder));
-  std::vector Args = {"-std=c++11", 
"-fno-delayed-template-parsing"};
-  ASSERT_TRUE(tooling::runToolOnCodeWithArgs(Factory->create(), Code, Args));
-  EXPECT_TRUE(Callback.SawFunctionBody);
+// Constructing a CFG containing a delete expression on a dependent type should
+// not crash.
+TEST(CFG, DeleteExpressionOnDependentType) {
+  const char *Code = "template\n"
+ "void f(T t) {\n"
+ "  delete t;\n"
+ "}\n";
+  EXPECT_EQ(BuiltCFG, BuildCFG(Code));
 }
 
 } // namespace


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


[clang-tools-extra] r285842 - [clang-tidy] Extend misc-use-after-move to support unique_ptr and shared_ptr.

2016-11-02 Thread Martin Bohme via cfe-commits
Author: mboehme
Date: Wed Nov  2 12:34:47 2016
New Revision: 285842

URL: http://llvm.org/viewvc/llvm-project?rev=285842&view=rev
Log:
[clang-tidy] Extend misc-use-after-move to support unique_ptr and shared_ptr.

Summary:
As a unique_ptr or shared_ptr that has been moved from is guaranteed to be null,
we only warn if the pointer is dereferenced.

Reviewers: hokein, alexfh, aaron.ballman

Subscribers: Prazek, cfe-commits

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

Modified:
clang-tools-extra/trunk/clang-tidy/misc/UseAfterMoveCheck.cpp
clang-tools-extra/trunk/docs/clang-tidy/checks/misc-use-after-move.rst
clang-tools-extra/trunk/test/clang-tidy/misc-use-after-move.cpp

Modified: clang-tools-extra/trunk/clang-tidy/misc/UseAfterMoveCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/UseAfterMoveCheck.cpp?rev=285842&r1=285841&r2=285842&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/misc/UseAfterMoveCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/misc/UseAfterMoveCheck.cpp Wed Nov  2 
12:34:47 2016
@@ -463,6 +463,26 @@ void UseAfterMoveFinder::getUsesAndReini
 });
 }
 
+bool isStandardSmartPointer(const ValueDecl *VD) {
+  const Type *TheType = VD->getType().getTypePtrOrNull();
+  if (!TheType)
+return false;
+
+  const CXXRecordDecl *RecordDecl = TheType->getAsCXXRecordDecl();
+  if (!RecordDecl)
+return false;
+
+  const IdentifierInfo *ID = RecordDecl->getIdentifier();
+  if (!ID)
+return false;
+
+  StringRef Name = ID->getName();
+  if (Name != "unique_ptr" && Name != "shared_ptr" && Name != "weak_ptr")
+return false;
+
+  return RecordDecl->getDeclContext()->isStdNamespace();
+}
+
 void UseAfterMoveFinder::getDeclRefs(
 const CFGBlock *Block, const Decl *MovedVariable,
 llvm::SmallPtrSetImpl *DeclRefs) {
@@ -472,17 +492,33 @@ void UseAfterMoveFinder::getDeclRefs(
 if (!S)
   continue;
 
-SmallVector Matches =
-match(findAll(declRefExpr(hasDeclaration(equalsNode(MovedVariable)),
-  unless(inDecltypeOrTemplateArg()))
-  .bind("declref")),
-  *S->getStmt(), *Context);
+auto addDeclRefs = [this, Block,
+DeclRefs](const ArrayRef Matches) {
+  for (const auto &Match : Matches) {
+const auto *DeclRef = Match.getNodeAs("declref");
+const auto *Operator = 
Match.getNodeAs("operator");
+if (DeclRef && BlockMap->blockContainingStmt(DeclRef) == Block) {
+  // Ignore uses of a standard smart pointer that don't dereference the
+  // pointer.
+  if (Operator || !isStandardSmartPointer(DeclRef->getDecl())) {
+DeclRefs->insert(DeclRef);
+  }
+}
+  }
+};
 
-for (const auto &Match : Matches) {
-  const auto *DeclRef = Match.getNodeAs("declref");
-  if (DeclRef && BlockMap->blockContainingStmt(DeclRef) == Block)
-DeclRefs->insert(DeclRef);
-}
+auto DeclRefMatcher = 
declRefExpr(hasDeclaration(equalsNode(MovedVariable)),
+  unless(inDecltypeOrTemplateArg()))
+  .bind("declref");
+
+addDeclRefs(match(findAll(DeclRefMatcher), *S->getStmt(), *Context));
+addDeclRefs(match(
+findAll(cxxOperatorCallExpr(anyOf(hasOverloadedOperatorName("*"),
+  hasOverloadedOperatorName("->"),
+  hasOverloadedOperatorName("[]")),
+hasArgument(0, DeclRefMatcher))
+.bind("operator")),
+*S->getStmt(), *Context));
   }
 }
 
@@ -500,6 +536,9 @@ void UseAfterMoveFinder::getReinits(
  "::std::unordered_set", "::std::unordered_map",
  "::std::unordered_multiset", "::std::unordered_multimap")));
 
+  auto StandardSmartPointerTypeMatcher = hasType(cxxRecordDecl(
+  hasAnyName("::std::unique_ptr", "::std::shared_ptr", 
"::std::weak_ptr")));
+
   // Matches different types of reinitialization.
   auto ReinitMatcher =
   stmt(anyOf(
@@ -521,6 +560,10 @@ void UseAfterMoveFinder::getReinits(
// is called on any of the other containers, this will be
// flagged by a compile error anyway.
callee(cxxMethodDecl(hasAnyName("clear", "assign",
+   // reset() on standard smart pointers.
+   cxxMemberCallExpr(
+   on(allOf(DeclRefMatcher, StandardSmartPointerTypeMatcher)),
+   callee(cxxMethodDecl(hasName("reset",
// Passing variable to a function as a non-const pointer.
callExpr(forEachArgumentWithParam(
unaryOperator(hasOperatorName("&"),
@@ -587,15 +630,10 @@ void UseAfterMoveCheck::registerMatchers
   if (!getLangOpts()

[clang-tools-extra] r276746 - Test commit -- adding a newline

2016-07-26 Thread Martin Bohme via cfe-commits
Author: mboehme
Date: Tue Jul 26 09:01:48 2016
New Revision: 276746

URL: http://llvm.org/viewvc/llvm-project?rev=276746&view=rev
Log:
Test commit -- adding a newline

Modified:
clang-tools-extra/trunk/clang-tidy/misc/MoveConstantArgumentCheck.cpp

Modified: clang-tools-extra/trunk/clang-tidy/misc/MoveConstantArgumentCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/MoveConstantArgumentCheck.cpp?rev=276746&r1=276745&r2=276746&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/misc/MoveConstantArgumentCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/misc/MoveConstantArgumentCheck.cpp Tue 
Jul 26 09:01:48 2016
@@ -9,6 +9,7 @@
 
 #include "MoveConstantArgumentCheck.h"
 
+
 #include "clang/Lex/Lexer.h"
 
 using namespace clang::ast_matchers;


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


[clang-tools-extra] r276752 - Revert test commit

2016-07-26 Thread Martin Bohme via cfe-commits
Author: mboehme
Date: Tue Jul 26 09:37:39 2016
New Revision: 276752

URL: http://llvm.org/viewvc/llvm-project?rev=276752&view=rev
Log:
Revert test commit

This reverts rL276746.

Modified:
clang-tools-extra/trunk/clang-tidy/misc/MoveConstantArgumentCheck.cpp

Modified: clang-tools-extra/trunk/clang-tidy/misc/MoveConstantArgumentCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/misc/MoveConstantArgumentCheck.cpp?rev=276752&r1=276751&r2=276752&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/misc/MoveConstantArgumentCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/misc/MoveConstantArgumentCheck.cpp Tue 
Jul 26 09:37:39 2016
@@ -9,7 +9,6 @@
 
 #include "MoveConstantArgumentCheck.h"
 
-
 #include "clang/Lex/Lexer.h"
 
 using namespace clang::ast_matchers;


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


r276755 - Make RecursiveASTVisitor visit lambda capture initialization expressions

2016-07-26 Thread Martin Bohme via cfe-commits
Author: mboehme
Date: Tue Jul 26 10:19:10 2016
New Revision: 276755

URL: http://llvm.org/viewvc/llvm-project?rev=276755&view=rev
Log:
Make RecursiveASTVisitor visit lambda capture initialization expressions

Summary:
Lambda capture initializations are part of the explicit source code and 
therefore should be visited by default but, so far, RecursiveASTVisitor does 
not visit them.

This appears to be an oversight. Because the lambda body needs custom handling 
(calling TraverseLambdaBody()), the DEF_TRAVERSE_STMT for LambdaExpr sets 
ShouldVisitChildren to false but then neglects to visit the lambda capture 
initializations. This patch adds code to visit the expressions associated with 
lambda capture initializations.

Reviewers: klimek

Subscribers: klimek, cfe-commits

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

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

Modified: cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/RecursiveASTVisitor.h?rev=276755&r1=276754&r2=276755&view=diff
==
--- cfe/trunk/include/clang/AST/RecursiveASTVisitor.h (original)
+++ cfe/trunk/include/clang/AST/RecursiveASTVisitor.h Tue Jul 26 10:19:10 2016
@@ -2266,6 +2266,9 @@ DEF_TRAVERSE_STMT(LambdaExpr, {
C != CEnd; ++C) {
 TRY_TO(TraverseLambdaCapture(S, C));
   }
+  for (Expr *Init : S->capture_inits()) {
+TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(Init);
+  }
 
   TypeLoc TL = S->getCallOperator()->getTypeSourceInfo()->getTypeLoc();
   FunctionProtoTypeLoc Proto = TL.castAs();

Modified: cfe/trunk/unittests/Tooling/RecursiveASTVisitorTestExprVisitor.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Tooling/RecursiveASTVisitorTestExprVisitor.cpp?rev=276755&r1=276754&r2=276755&view=diff
==
--- cfe/trunk/unittests/Tooling/RecursiveASTVisitorTestExprVisitor.cpp 
(original)
+++ cfe/trunk/unittests/Tooling/RecursiveASTVisitorTestExprVisitor.cpp Tue Jul 
26 10:19:10 2016
@@ -191,6 +191,14 @@ TEST(RecursiveASTVisitor, VisitsCallExpr
 "void x(); void y() { x(); }"));
 }
 
+TEST(RecursiveASTVisitor, VisitsLambdaCaptureInit) {
+  DeclRefExprVisitor Visitor;
+  Visitor.ExpectMatch("i", 1, 20);
+  EXPECT_TRUE(Visitor.runOver(
+"void f() { int i; [i]{}; };",
+DeclRefExprVisitor::Lang_CXX11));
+}
+
 /* FIXME: According to Richard Smith this is a bug in the AST.
 TEST(RecursiveASTVisitor, VisitsBaseClassTemplateArgumentsInInstantiation) {
   DeclRefExprVisitor Visitor;


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


r276759 - Revert "Make RecursiveASTVisitor visit lambda capture initialization expressions"

2016-07-26 Thread Martin Bohme via cfe-commits
Author: mboehme
Date: Tue Jul 26 11:01:55 2016
New Revision: 276759

URL: http://llvm.org/viewvc/llvm-project?rev=276759&view=rev
Log:
Revert "Make RecursiveASTVisitor visit lambda capture initialization 
expressions"

This reverts commit r276755.

(Broke clang-tidy check modernize-loop-convert.)

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

Modified: cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/RecursiveASTVisitor.h?rev=276759&r1=276758&r2=276759&view=diff
==
--- cfe/trunk/include/clang/AST/RecursiveASTVisitor.h (original)
+++ cfe/trunk/include/clang/AST/RecursiveASTVisitor.h Tue Jul 26 11:01:55 2016
@@ -2266,9 +2266,6 @@ DEF_TRAVERSE_STMT(LambdaExpr, {
C != CEnd; ++C) {
 TRY_TO(TraverseLambdaCapture(S, C));
   }
-  for (Expr *Init : S->capture_inits()) {
-TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(Init);
-  }
 
   TypeLoc TL = S->getCallOperator()->getTypeSourceInfo()->getTypeLoc();
   FunctionProtoTypeLoc Proto = TL.castAs();

Modified: cfe/trunk/unittests/Tooling/RecursiveASTVisitorTestExprVisitor.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Tooling/RecursiveASTVisitorTestExprVisitor.cpp?rev=276759&r1=276758&r2=276759&view=diff
==
--- cfe/trunk/unittests/Tooling/RecursiveASTVisitorTestExprVisitor.cpp 
(original)
+++ cfe/trunk/unittests/Tooling/RecursiveASTVisitorTestExprVisitor.cpp Tue Jul 
26 11:01:55 2016
@@ -191,14 +191,6 @@ TEST(RecursiveASTVisitor, VisitsCallExpr
 "void x(); void y() { x(); }"));
 }
 
-TEST(RecursiveASTVisitor, VisitsLambdaCaptureInit) {
-  DeclRefExprVisitor Visitor;
-  Visitor.ExpectMatch("i", 1, 20);
-  EXPECT_TRUE(Visitor.runOver(
-"void f() { int i; [i]{}; };",
-DeclRefExprVisitor::Lang_CXX11));
-}
-
 /* FIXME: According to Richard Smith this is a bug in the AST.
 TEST(RecursiveASTVisitor, VisitsBaseClassTemplateArgumentsInInstantiation) {
   DeclRefExprVisitor Visitor;


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


[clang-tools-extra] r277339 - [clang-tidy] Prepare modernize-loop-convert for upcoming changes in D22566

2016-08-01 Thread Martin Bohme via cfe-commits
Author: mboehme
Date: Mon Aug  1 06:29:17 2016
New Revision: 277339

URL: http://llvm.org/viewvc/llvm-project?rev=277339&view=rev
Log:
[clang-tidy] Prepare modernize-loop-convert for upcoming changes in D22566

Summary:
D22566 will change RecursiveASTVisitor so that it descends into the 
initialization expressions for lambda captures.

modernize-loop-convert needs to be prepared for this so that it does not 
interpret these initialization expressions as invalid uses of the loop 
variable. The change has no ill effects without D22566 in place, i.e. the 
change does not depend on D22566.

Reviewers: klimek

Subscribers: cfe-commits

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

Modified:
clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertUtils.cpp

Modified: clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertUtils.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertUtils.cpp?rev=277339&r1=277338&r2=277339&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertUtils.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertUtils.cpp Mon Aug  
1 06:29:17 2016
@@ -805,6 +805,18 @@ bool ForLoopIndexUseVisitor::VisitDeclSt
 }
 
 bool ForLoopIndexUseVisitor::TraverseStmt(Stmt *S) {
+  // If this is an initialization expression for a lambda capture, prune the
+  // traversal so that we don't end up diagnosing the contained DeclRefExpr as
+  // inconsistent usage. No need to record the usage here -- this is done in
+  // TraverseLambdaCapture().
+  if (const auto *LE = dyn_cast_or_null(NextStmtParent)) {
+// Any child of a LambdaExpr that isn't the body is an initialization
+// expression.
+if (S != LE->getBody()) {
+  return true;
+}
+  }
+
   // All this pointer swapping is a mechanism for tracking immediate parentage
   // of Stmts.
   const Stmt *OldNextParent = NextStmtParent;


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


r277342 - Make RecursiveASTVisitor visit lambda capture initialization expressions

2016-08-01 Thread Martin Bohme via cfe-commits
Author: mboehme
Date: Mon Aug  1 07:15:46 2016
New Revision: 277342

URL: http://llvm.org/viewvc/llvm-project?rev=277342&view=rev
Log:
Make RecursiveASTVisitor visit lambda capture initialization expressions

Summary:
Lambda capture initializations are part of the explicit source code and
therefore should be visited by default but, so far, RecursiveASTVisitor does not
visit them.

This appears to be an oversight. Because the lambda body needs custom handling
(calling TraverseLambdaBody()), the DEF_TRAVERSE_STMT for LambdaExpr sets
ShouldVisitChildren to false but then neglects to visit the lambda capture
initializations. This patch adds code to visit the expressions associated with
lambda capture initializations.

Reviewers: klimek

Subscribers: cfe-commits

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

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

Modified: cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/RecursiveASTVisitor.h?rev=277342&r1=277341&r2=277342&view=diff
==
--- cfe/trunk/include/clang/AST/RecursiveASTVisitor.h (original)
+++ cfe/trunk/include/clang/AST/RecursiveASTVisitor.h Mon Aug  1 07:15:46 2016
@@ -2266,6 +2266,9 @@ DEF_TRAVERSE_STMT(LambdaExpr, {
C != CEnd; ++C) {
 TRY_TO(TraverseLambdaCapture(S, C));
   }
+  for (Expr *Init : S->capture_inits()) {
+TRY_TO_TRAVERSE_OR_ENQUEUE_STMT(Init);
+  }
 
   TypeLoc TL = S->getCallOperator()->getTypeSourceInfo()->getTypeLoc();
   FunctionProtoTypeLoc Proto = TL.castAs();

Modified: cfe/trunk/unittests/Tooling/RecursiveASTVisitorTestExprVisitor.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Tooling/RecursiveASTVisitorTestExprVisitor.cpp?rev=277342&r1=277341&r2=277342&view=diff
==
--- cfe/trunk/unittests/Tooling/RecursiveASTVisitorTestExprVisitor.cpp 
(original)
+++ cfe/trunk/unittests/Tooling/RecursiveASTVisitorTestExprVisitor.cpp Mon Aug  
1 07:15:46 2016
@@ -191,6 +191,14 @@ TEST(RecursiveASTVisitor, VisitsCallExpr
 "void x(); void y() { x(); }"));
 }
 
+TEST(RecursiveASTVisitor, VisitsLambdaCaptureInit) {
+  DeclRefExprVisitor Visitor;
+  Visitor.ExpectMatch("i", 1, 20);
+  EXPECT_TRUE(Visitor.runOver(
+"void f() { int i; [i]{}; };",
+DeclRefExprVisitor::Lang_CXX11));
+}
+
 /* FIXME: According to Richard Smith this is a bug in the AST.
 TEST(RecursiveASTVisitor, VisitsBaseClassTemplateArgumentsInInstantiation) {
   DeclRefExprVisitor Visitor;


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


r278123 - [ASTMatchers] Add matchers canReferToDecl() and hasUnderlyingDecl()

2016-08-09 Thread Martin Bohme via cfe-commits
Author: mboehme
Date: Tue Aug  9 10:07:52 2016
New Revision: 278123

URL: http://llvm.org/viewvc/llvm-project?rev=278123&view=rev
Log:
[ASTMatchers] Add matchers canReferToDecl() and hasUnderlyingDecl()

Summary: Required for D0

Reviewers: sbenza, klimek, aaron.ballman, alexfh

Subscribers: alexfh, klimek, cfe-commits

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

Modified:
cfe/trunk/docs/LibASTMatchersReference.html
cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp
cfe/trunk/unittests/ASTMatchers/ASTMatchersTraversalTest.cpp

Modified: cfe/trunk/docs/LibASTMatchersReference.html
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/LibASTMatchersReference.html?rev=278123&r1=278122&r2=278123&view=diff
==
--- cfe/trunk/docs/LibASTMatchersReference.html (original)
+++ cfe/trunk/docs/LibASTMatchersReference.html Tue Aug  9 10:07:52 2016
@@ -4970,6 +4970,19 @@ Usable as: MatcherNamedDecl>hasUnderlyingDeclMatcherNamedDecl>
 InnerMatcher
+Matches a 
NamedDecl whose underlying declaration matches the given
+matcher.
+
+Given
+  namespace N { template void f(T t); }
+  template  void g() { using N::f; f(T()); }
+unresolvedLookupExpr(hasAnyDeclaration(
+namedDecl(hasUnderlyingDecl(hasName("::N::f")
+  matches the use of f in g() .
+
+
+
 MatcherNestedNameSpecifierLoc>hasPrefixMatcherNestedNameSpecifierLoc>
 InnerMatcher
 Matches on the prefix of 
a NestedNameSpecifierLoc.
 
@@ -5057,6 +5070,23 @@ matches the [webView ...] message invoca
 
 
 
+MatcherOverloadExpr>hasAnyDeclarationMatcherDecl> 
InnerMatcher
+Matches an 
OverloadExpr if any of the declarations in the set of
+overloads matches the given matcher.
+
+Given
+  template  void foo(T);
+  template  void bar(T);
+  template  void baz(T t) {
+foo(t);
+bar(t);
+  }
+unresolvedLookupExpr(hasAnyDeclaration(
+functionTemplateDecl(hasName("foo"
+  matches foo in foo(t); but not bar in bar(t);
+
+
+
 MatcherParenType>innerTypeMatcherType>
 Matches ParenType nodes 
where the inner type is a specific type.
 

Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h?rev=278123&r1=278122&r2=278123&view=diff
==
--- cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h (original)
+++ cfe/trunk/include/clang/ASTMatchers/ASTMatchers.h Tue Aug  9 10:07:52 2016
@@ -2468,6 +2468,25 @@ hasDeclaration(const internal::Matcher(InnerMatcher);
 }
 
+/// \brief Matches a \c NamedDecl whose underlying declaration matches the 
given
+/// matcher.
+///
+/// Given
+/// \code
+///   namespace N { template void f(T t); }
+///   template  void g() { using N::f; f(T()); }
+/// \endcode
+/// \c unresolvedLookupExpr(hasAnyDeclaration(
+/// namedDecl(hasUnderlyingDecl(hasName("::N::f")
+///   matches the use of \c f in \c g() .
+AST_MATCHER_P(NamedDecl, hasUnderlyingDecl, internal::Matcher,
+  InnerMatcher) {
+  const NamedDecl *UnderlyingDecl = Node.getUnderlyingDecl();
+
+  return UnderlyingDecl != nullptr &&
+ InnerMatcher.matches(*UnderlyingDecl, Finder, Builder);
+}
+
 /// \brief Matches on the implicit object argument of a member call expression.
 ///
 /// Example matches y.x()
@@ -2823,6 +2842,27 @@ AST_MATCHER_P(DeclRefExpr, throughUsingD
   return false;
 }
 
+/// \brief Matches an \c OverloadExpr if any of the declarations in the set of
+/// overloads matches the given matcher.
+///
+/// Given
+/// \code
+///   template  void foo(T);
+///   template  void bar(T);
+///   template  void baz(T t) {
+/// foo(t);
+/// bar(t);
+///   }
+/// \endcode
+/// unresolvedLookupExpr(hasAnyDeclaration(
+/// functionTemplateDecl(hasName("foo"
+///   matches \c foo in \c foo(t); but not \c bar in \c bar(t);
+AST_MATCHER_P(OverloadExpr, hasAnyDeclaration, internal::Matcher,
+  InnerMatcher) {
+  return matchesFirstInPointerRange(InnerMatcher, Node.decls_begin(),
+Node.decls_end(), Finder, Builder);
+}
+
 /// \brief Matches the Decl of a DeclStmt which has a single declaration.
 ///
 /// Given

Modified: cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp
URL: 
http://llvm.org/viewvc/llvm-proj

r278213 - [ASTMatchers] Extend documentation for match()

2016-08-10 Thread Martin Bohme via cfe-commits
Author: mboehme
Date: Wed Aug 10 06:22:57 2016
New Revision: 278213

URL: http://llvm.org/viewvc/llvm-project?rev=278213&view=rev
Log:
[ASTMatchers] Extend documentation for match()

Summary:
Adds an explanation of how to use findAll() to find all matches in a subtree.

Modified:
cfe/trunk/include/clang/ASTMatchers/ASTMatchFinder.h

Modified: cfe/trunk/include/clang/ASTMatchers/ASTMatchFinder.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/ASTMatchers/ASTMatchFinder.h?rev=278213&r1=278212&r2=278213&view=diff
==
--- cfe/trunk/include/clang/ASTMatchers/ASTMatchFinder.h (original)
+++ cfe/trunk/include/clang/ASTMatchers/ASTMatchFinder.h Wed Aug 10 06:22:57 
2016
@@ -229,6 +229,10 @@ private:
 /// Multiple results occur when using matchers like \c forEachDescendant,
 /// which generate a result for each sub-match.
 ///
+/// If you want to find all matches on the sub-tree rooted at \c Node (rather
+/// than only the matches on \c Node itself), surround the \c Matcher with a
+/// \c findAll().
+///
 /// \see selectFirst
 /// @{
 template 


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


r278507 - [ASTMatchers] Add templateTypeParmDecl() to Registry.cpp

2016-08-12 Thread Martin Bohme via cfe-commits
Author: mboehme
Date: Fri Aug 12 08:51:00 2016
New Revision: 278507

URL: http://llvm.org/viewvc/llvm-project?rev=278507&view=rev
Log:
[ASTMatchers] Add templateTypeParmDecl() to Registry.cpp

Summary:
This appears to have been forgotten when templateTypeParmDecl() was initially
added.

Reviewers: alexfh, aaron.ballman

Subscribers: aaron.ballman, klimek, aemerson, rengolin, samparker, cfe-commits

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

Modified:
cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp

Modified: cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp?rev=278507&r1=278506&r2=278507&view=diff
==
--- cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp (original)
+++ cfe/trunk/lib/ASTMatchers/Dynamic/Registry.cpp Fri Aug 12 08:51:00 2016
@@ -396,6 +396,7 @@ RegistryMaps::RegistryMaps() {
   REGISTER_MATCHER(templateName);
   REGISTER_MATCHER(templateArgumentCountIs);
   REGISTER_MATCHER(templateSpecializationType);
+  REGISTER_MATCHER(templateTypeParmDecl);
   REGISTER_MATCHER(templateTypeParmType);
   REGISTER_MATCHER(throughUsingDecl);
   REGISTER_MATCHER(to);


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