r289787 - Re-commit r289252 and r289285, and fix PR31374

2016-12-15 Thread Yaxun Liu via cfe-commits
Author: yaxunl
Date: Thu Dec 15 02:09:08 2016
New Revision: 289787

URL: http://llvm.org/viewvc/llvm-project?rev=289787&view=rev
Log:
Re-commit r289252 and r289285, and fix PR31374

Added:
cfe/trunk/test/CodeGenOpenCL/amdgpu-nullptr.cl
Modified:
cfe/trunk/include/clang/AST/APValue.h
cfe/trunk/include/clang/AST/ASTContext.h
cfe/trunk/include/clang/Basic/TargetInfo.h
cfe/trunk/lib/AST/APValue.cpp
cfe/trunk/lib/AST/ASTContext.cpp
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/lib/Basic/Targets.cpp
cfe/trunk/lib/CodeGen/CGDecl.cpp
cfe/trunk/lib/CodeGen/CGExprAgg.cpp
cfe/trunk/lib/CodeGen/CGExprConstant.cpp
cfe/trunk/lib/CodeGen/CGExprScalar.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.h
cfe/trunk/lib/CodeGen/CodeGenTypes.cpp
cfe/trunk/lib/CodeGen/CodeGenTypes.h
cfe/trunk/lib/CodeGen/TargetInfo.cpp
cfe/trunk/lib/CodeGen/TargetInfo.h

Modified: cfe/trunk/include/clang/AST/APValue.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/APValue.h?rev=289787&r1=289786&r2=289787&view=diff
==
--- cfe/trunk/include/clang/AST/APValue.h (original)
+++ cfe/trunk/include/clang/AST/APValue.h Thu Dec 15 02:09:08 2016
@@ -135,14 +135,15 @@ public:
   }
   APValue(const APValue &RHS);
   APValue(APValue &&RHS) : Kind(Uninitialized) { swap(RHS); }
-  APValue(LValueBase B, const CharUnits &O, NoLValuePath N, unsigned CallIndex)
+  APValue(LValueBase B, const CharUnits &O, NoLValuePath N, unsigned CallIndex,
+  bool IsNullPtr = false)
   : Kind(Uninitialized) {
-MakeLValue(); setLValue(B, O, N, CallIndex);
+MakeLValue(); setLValue(B, O, N, CallIndex, IsNullPtr);
   }
   APValue(LValueBase B, const CharUnits &O, ArrayRef Path,
-  bool OnePastTheEnd, unsigned CallIndex)
+  bool OnePastTheEnd, unsigned CallIndex, bool IsNullPtr = false)
   : Kind(Uninitialized) {
-MakeLValue(); setLValue(B, O, Path, OnePastTheEnd, CallIndex);
+MakeLValue(); setLValue(B, O, Path, OnePastTheEnd, CallIndex, IsNullPtr);
   }
   APValue(UninitArray, unsigned InitElts, unsigned Size) : Kind(Uninitialized) 
{
 MakeArray(InitElts, Size);
@@ -254,6 +255,7 @@ public:
   bool hasLValuePath() const;
   ArrayRef getLValuePath() const;
   unsigned getLValueCallIndex() const;
+  bool isNullPointer() const;
 
   APValue &getVectorElt(unsigned I) {
 assert(isVector() && "Invalid accessor");
@@ -374,10 +376,10 @@ public:
 ((ComplexAPFloat *)(char *)Data.buffer)->Imag = std::move(I);
   }
   void setLValue(LValueBase B, const CharUnits &O, NoLValuePath,
- unsigned CallIndex);
+ unsigned CallIndex, bool IsNullPtr);
   void setLValue(LValueBase B, const CharUnits &O,
  ArrayRef Path, bool OnePastTheEnd,
- unsigned CallIndex);
+ unsigned CallIndex, bool IsNullPtr);
   void setUnion(const FieldDecl *Field, const APValue &Value) {
 assert(isUnion() && "Invalid accessor");
 ((UnionData*)(char*)Data.buffer)->Field = Field;

Modified: cfe/trunk/include/clang/AST/ASTContext.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ASTContext.h?rev=289787&r1=289786&r2=289787&view=diff
==
--- cfe/trunk/include/clang/AST/ASTContext.h (original)
+++ cfe/trunk/include/clang/AST/ASTContext.h Thu Dec 15 02:09:08 2016
@@ -2299,6 +2299,10 @@ public:
   return (*AddrSpaceMap)[AS - LangAS::Offset];
   }
 
+  /// Get target-dependent integer value for null pointer which is used for
+  /// constant folding.
+  uint64_t getTargetNullPointerValue(QualType QT) const;
+
   bool addressSpaceMapManglingFor(unsigned AS) const {
 return AddrSpaceMapMangling || 
AS < LangAS::Offset || 

Modified: cfe/trunk/include/clang/Basic/TargetInfo.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/TargetInfo.h?rev=289787&r1=289786&r2=289787&view=diff
==
--- cfe/trunk/include/clang/Basic/TargetInfo.h (original)
+++ cfe/trunk/include/clang/Basic/TargetInfo.h Thu Dec 15 02:09:08 2016
@@ -42,6 +42,7 @@ class DiagnosticsEngine;
 class LangOptions;
 class CodeGenOptions;
 class MacroBuilder;
+class QualType;
 class SourceLocation;
 class SourceManager;
 
@@ -300,6 +301,12 @@ public:
 return PointerWidth;
   }
 
+  /// \brief Get integer value for null pointer.
+  /// \param AddrSpace address space of pointee in source language.
+  virtual uint64_t getNullPointerValue(unsigned AddrSpace) const {
+return 0;
+  }
+
   /// \brief Return the size of '_Bool' and C++ 'bool' for this target, in 
bits.
   unsigned getBoolWidth() const { return BoolWidth; }
 

Modified: cfe/trunk/lib/AST/APValue.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/APValue.cpp?re

[PATCH] D27166: [clang-tidy] Enhance modernize-use-auto to templated function casts

2016-12-15 Thread Malcolm Parsons via Phabricator via cfe-commits
malcolm.parsons updated this revision to Diff 81540.
malcolm.parsons added a comment.

Add FIXME comment.


https://reviews.llvm.org/D27166

Files:
  clang-tidy/modernize/UseAutoCheck.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/modernize-use-auto.rst
  test/clang-tidy/modernize-use-auto-cast-remove-stars.cpp
  test/clang-tidy/modernize-use-auto-cast.cpp

Index: test/clang-tidy/modernize-use-auto-cast.cpp
===
--- test/clang-tidy/modernize-use-auto-cast.cpp
+++ test/clang-tidy/modernize-use-auto-cast.cpp
@@ -138,3 +138,95 @@
   B b;
   A a = A(b);
 }
+
+class StringRef
+{
+public:
+  StringRef(const char *);
+  const char *begin() const;
+  const char *end() const;
+};
+
+template 
+T template_value_cast(const U &u);
+
+template 
+T *template_pointer_cast(U *u);
+
+template 
+T &template_reference_cast(U &u);
+
+template 
+const T *template_const_pointer_cast(const U *u);
+
+template 
+const T &template_const_reference_cast(const U &u);
+
+template 
+T template_value_get(StringRef s);
+
+struct S {
+  template 
+  const T *template_member_get();
+};
+
+template 
+T max(T t1, T t2);
+
+void f_template_cast()
+{
+  double d = 0;
+  int i1 = template_value_cast(d);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a template cast to avoid duplicating the type name
+  // CHECK-FIXES: auto i1 = template_value_cast(d);
+
+  A *a = new B();
+  B *b1 = template_value_cast(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a template cast to avoid duplicating the type name
+  // CHECK-FIXES: auto *b1 = template_value_cast(a);
+  B &b2 = template_value_cast(*a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a template cast to avoid duplicating the type name
+  // CHECK-FIXES: auto &b2 = template_value_cast(*a);
+  B *b3 = template_pointer_cast(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a template cast to avoid duplicating the type name
+  // CHECK-FIXES: auto *b3 = template_pointer_cast(a);
+  B &b4 = template_reference_cast(*a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a template cast to avoid duplicating the type name
+  // CHECK-FIXES: auto &b4 = template_reference_cast(*a);
+  const B *b5 = template_const_pointer_cast(a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: use auto when initializing with a template cast to avoid duplicating the type name
+  // CHECK-FIXES: const auto *b5 = template_const_pointer_cast(a);
+  const B &b6 = template_const_reference_cast(*a);
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: use auto when initializing with a template cast to avoid duplicating the type name
+  // CHECK-FIXES: const auto &b6 = template_const_reference_cast(*a);
+  B *b7 = template_value_get("foo");
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a template cast to avoid duplicating the type name
+  // CHECK-FIXES: auto *b7 = template_value_get("foo");
+  B *b8 = template_value_get("foo"), *b9 = template_value_get("bar");
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a template cast to avoid duplicating the type name
+  // CHECK-FIXES: auto *b8 = template_value_get("foo"), *b9 = template_value_get("bar");
+
+  S s;
+  const B *b10 = s.template_member_get();
+  // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: use auto when initializing with a template cast to avoid duplicating the type name
+  // CHECK-FIXES: const auto *b10 = s.template_member_get();
+
+  // Don't warn when auto is already being used.
+  auto i2 = template_value_cast(d);
+  auto *i3 = template_value_cast(d);
+  auto **i4 = template_value_cast(d);
+  auto &i5 = template_reference_cast(d);
+
+  // Don't warn for implicit template arguments.
+  int i6 = max(i1, i2);
+
+  // Don't warn for mismatched var and initializer types.
+  A *a1 = template_value_cast(a);
+
+  // Don't warn for mismatched var types.
+  B *b11 = template_value_get("foo"), b12 = template_value_get("bar");
+
+  // Don't warn for implicit variables.
+  for (auto &c : template_reference_cast(*a)) {
+  }
+}
Index: test/clang-tidy/modernize-use-auto-cast-remove-stars.cpp
===
--- test/clang-tidy/modernize-use-auto-cast-remove-stars.cpp
+++ test/clang-tidy/modernize-use-auto-cast-remove-stars.cpp
@@ -44,7 +44,7 @@
 
   const B *b3 = static_cast(a);
   // CHECK-MESSAGES: :[[@LINE-1]]:9: warning: use auto when initializing with a cast to avoid duplicating the type name
-  // CHECK-FIXES: auto b3 = static_cast(a);
+  // CHECK-FIXES: const auto b3 = static_cast(a);
 
   B &b4 = static_cast(*a);
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid duplicating the type name
@@ -58,6 +58,9 @@
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use auto when initializing with a cast to avoid dupl

[PATCH] D27800: Add overload of TransformToPotentiallyEvaluated for TypeSourceInfo

2016-12-15 Thread Paulo Matos via Phabricator via cfe-commits
pmatos created this revision.
pmatos added a reviewer: efriedma.
pmatos added a subscriber: cfe-commits.

Adds overload of ransformToPotentiallyEvaluated for TypeSourceInfo to properly 
deal with VLAs in nested calls of sizeof and typeof. Fixes #31042.


https://reviews.llvm.org/D27800

Files:
  include/clang/Sema/Sema.h
  lib/Sema/SemaExpr.cpp


Index: lib/Sema/SemaExpr.cpp
===
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -4014,6 +4014,10 @@
   }
 
   // C99 6.5.3.4p4: the type (an unsigned integer type) is size_t.
+  if (isUnevaluatedContext() && ExprKind == UETT_SizeOf &&
+  TInfo->getType()->isVariablyModifiedType())
+TInfo = TransformToPotentiallyEvaluated(TInfo);
+  
   return new (Context) UnaryExprOrTypeTraitExpr(
   ExprKind, TInfo, Context.getSizeType(), OpLoc, R.getEnd());
 }
@@ -13041,6 +13045,17 @@
   return TransformToPE(*this).TransformExpr(E);
 }
 
+
+TypeSourceInfo *Sema::TransformToPotentiallyEvaluated(TypeSourceInfo *TInfo) {
+  assert(isUnevaluatedContext() &&
+ "Should only transform unevaluated expressions");
+  ExprEvalContexts.back().Context =
+  ExprEvalContexts[ExprEvalContexts.size()-2].Context;
+  if (isUnevaluatedContext())
+return TInfo;
+  return TransformToPE(*this).TransformType(TInfo);
+}
+
 void
 Sema::PushExpressionEvaluationContext(ExpressionEvaluationContext NewContext,
   Decl *LambdaContextDecl,
Index: include/clang/Sema/Sema.h
===
--- include/clang/Sema/Sema.h
+++ include/clang/Sema/Sema.h
@@ -3720,6 +3720,7 @@
   void DiscardCleanupsInEvaluationContext();
 
   ExprResult TransformToPotentiallyEvaluated(Expr *E);
+  TypeSourceInfo *TransformToPotentiallyEvaluated(TypeSourceInfo *TInfo);
   ExprResult HandleExprEvaluationContextForTypeof(Expr *E);
 
   ExprResult ActOnConstantExpression(ExprResult Res);


Index: lib/Sema/SemaExpr.cpp
===
--- lib/Sema/SemaExpr.cpp
+++ lib/Sema/SemaExpr.cpp
@@ -4014,6 +4014,10 @@
   }
 
   // C99 6.5.3.4p4: the type (an unsigned integer type) is size_t.
+  if (isUnevaluatedContext() && ExprKind == UETT_SizeOf &&
+  TInfo->getType()->isVariablyModifiedType())
+TInfo = TransformToPotentiallyEvaluated(TInfo);
+  
   return new (Context) UnaryExprOrTypeTraitExpr(
   ExprKind, TInfo, Context.getSizeType(), OpLoc, R.getEnd());
 }
@@ -13041,6 +13045,17 @@
   return TransformToPE(*this).TransformExpr(E);
 }
 
+
+TypeSourceInfo *Sema::TransformToPotentiallyEvaluated(TypeSourceInfo *TInfo) {
+  assert(isUnevaluatedContext() &&
+ "Should only transform unevaluated expressions");
+  ExprEvalContexts.back().Context =
+  ExprEvalContexts[ExprEvalContexts.size()-2].Context;
+  if (isUnevaluatedContext())
+return TInfo;
+  return TransformToPE(*this).TransformType(TInfo);
+}
+
 void
 Sema::PushExpressionEvaluationContext(ExpressionEvaluationContext NewContext,
   Decl *LambdaContextDecl,
Index: include/clang/Sema/Sema.h
===
--- include/clang/Sema/Sema.h
+++ include/clang/Sema/Sema.h
@@ -3720,6 +3720,7 @@
   void DiscardCleanupsInEvaluationContext();
 
   ExprResult TransformToPotentiallyEvaluated(Expr *E);
+  TypeSourceInfo *TransformToPotentiallyEvaluated(TypeSourceInfo *TInfo);
   ExprResult HandleExprEvaluationContextForTypeof(Expr *E);
 
   ExprResult ActOnConstantExpression(ExprResult Res);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D26843: Make sizeof expression context partially evaluated

2016-12-15 Thread Paulo Matos via Phabricator via cfe-commits
pmatos added a comment.

Please refer to the new one: https://reviews.llvm.org/D27800


https://reviews.llvm.org/D26843



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


[PATCH] D27800: Add overload of TransformToPotentiallyEvaluated for TypeSourceInfo

2016-12-15 Thread Paulo Matos via Phabricator via cfe-commits
pmatos added a comment.

@efriedma Here's the new patch, thanks for your help getting here.


https://reviews.llvm.org/D27800



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


[PATCH] D26843: Make sizeof expression context partially evaluated

2016-12-15 Thread Paulo Matos via Phabricator via cfe-commits
pmatos accepted this revision.
pmatos added a reviewer: pmatos.
pmatos added a comment.
This revision is now accepted and ready to land.

Abandoning this revision.


https://reviews.llvm.org/D26843



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


[PATCH] D26843: Make sizeof expression context partially evaluated

2016-12-15 Thread Paulo Matos via Phabricator via cfe-commits
pmatos closed this revision.
pmatos added a comment.

This is not supposed to be marked as accepted.


https://reviews.llvm.org/D26843



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


[PATCH] D27754: [clang-format] Implement comment reflowing (again).

2016-12-15 Thread Krasimir Georgiev via Phabricator via cfe-commits
krasimir updated this revision to Diff 81551.
krasimir added a comment.

- Split BreakableComment back into a BreakableBlockComment and 
BreakableLineCommentSection
- Extract common reflow computation functionality


https://reviews.llvm.org/D27754

Files:
  lib/Format/BreakableToken.cpp
  lib/Format/BreakableToken.h
  lib/Format/CMakeLists.txt
  lib/Format/Comments.cpp
  lib/Format/Comments.h
  lib/Format/ContinuationIndenter.cpp
  lib/Format/TokenAnnotator.cpp
  lib/Format/UnwrappedLineParser.cpp
  unittests/Format/FormatTest.cpp
  unittests/Format/FormatTestSelective.cpp

Index: unittests/Format/FormatTestSelective.cpp
===
--- unittests/Format/FormatTestSelective.cpp
+++ unittests/Format/FormatTestSelective.cpp
@@ -111,13 +111,19 @@
 format("int   a; // comment\n"
"intb; // comment",
0, 0));
-  EXPECT_EQ("int   a; // comment\n"
-" // line 2\n"
+  EXPECT_EQ("int a; // comment\n"
+"   // line 2\n"
 "int b;",
 format("int   a; // comment\n"
"// line 2\n"
"int b;",
28, 0));
+  EXPECT_EQ("int   a; // comment\n"
+"// comment 2\n"
+"int b;",
+format("int   a; // comment\n"
+   "// comment 2\n"
+   "int b;", 28, 0));
   EXPECT_EQ("int aa; // comment\n"
 "int b;\n"
 "int c; // unrelated comment",
Index: unittests/Format/FormatTest.cpp
===
--- unittests/Format/FormatTest.cpp
+++ unittests/Format/FormatTest.cpp
@@ -1783,6 +1783,410 @@
"0x00, 0x00, 0x00, 0x00};// comment\n");
 }
 
+TEST_F(FormatTest, ReflowsComments) {
+  // Break a long line and reflow with the full next line.
+  EXPECT_EQ("// long long long\n"
+"// long long",
+format("// long long long long\n"
+   "// long",
+   getLLVMStyleWithColumns(20)));
+
+  // Keep the trailing newline while reflowing.
+  EXPECT_EQ("// long long long\n"
+"// long long\n",
+format("// long long long long\n"
+   "// long\n",
+   getLLVMStyleWithColumns(20)));
+
+  // Break a long line and reflow with a part of the next line.
+  EXPECT_EQ("// long long long\n"
+"// long long\n"
+"// long_long",
+format("// long long long long\n"
+   "// long long_long",
+   getLLVMStyleWithColumns(20)));
+
+  // Break but do not reflow if the first word from the next line is too long.
+  EXPECT_EQ("// long long long\n"
+"// long\n"
+"// long_long_long\n",
+format("// long long long long\n"
+   "// long_long_long\n",
+   getLLVMStyleWithColumns(20)));
+
+  // Don't break or reflow short lines.
+  verifyFormat("// long\n"
+   "// long long long lo\n"
+   "// long long long lo\n"
+   "// long",
+   getLLVMStyleWithColumns(20));
+
+  // Keep prefixes and decorations while reflowing.
+  EXPECT_EQ("/// long long long\n"
+"/// long long\n",
+format("/// long long long long\n"
+   "/// long\n",
+   getLLVMStyleWithColumns(20)));
+  EXPECT_EQ("//! long long long\n"
+"//! long long\n",
+format("//! long long long long\n"
+   "//! long\n",
+   getLLVMStyleWithColumns(20)));
+  EXPECT_EQ("/* long long long\n"
+" * long long */",
+format("/* long long long long\n"
+   " * long */",
+   getLLVMStyleWithColumns(20)));
+
+  // Don't bring leading whitespace up while reflowing.
+  EXPECT_EQ("/*  long long long\n"
+" * long long long\n"
+" */",
+format("/*  long long long long\n"
+   " *  long long\n"
+   " */",
+   getLLVMStyleWithColumns(20)));
+
+  // Reflow the last line of a block comment with its trailing '*/'.
+  EXPECT_EQ("/* long long long\n"
+"   long long */",
+format("/* long long long long\n"
+   "   long */",
+   getLLVMStyleWithColumns(20)));
+
+  // Reflow two short lines; keep the postfix of the last one.
+  EXPECT_EQ("/* long long long\n"
+" * long long long */",
+format("/* long long long long\n"
+   " * long\n"
+   " * long */",
+   getLLVMStyleWithColumns(20)));
+
+  // Put the postfix of the last short reflow line on a newline if it doesn't
+  // fit.
+  EXPECT_EQ("/* long long long\n"
+" * long long longg\n"
+" */",
+format("/* long long long long\n"
+ 

[PATCH] D27575: [libcxxabi] Introduce an externally threaded libc++abi variant (take-2)

2016-12-15 Thread Asiri Rathnayake via Phabricator via cfe-commits
rmaprath added a comment.

Gentle ping.


https://reviews.llvm.org/D27575



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


[PATCH] D27576: [libcxx] libc++ changes necessary for the externally threaded libcxxabi variant

2016-12-15 Thread Asiri Rathnayake via Phabricator via cfe-commits
rmaprath marked an inline comment as done.
rmaprath added a comment.

Gentle ping.


https://reviews.llvm.org/D27576



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


[PATCH] D27801: [change-namespace] handling templated type aliases correctly.

2016-12-15 Thread Eric Liu via Phabricator via cfe-commits
ioeric created this revision.
ioeric added a reviewer: hokein.
ioeric added a subscriber: cfe-commits.

This fixes templated type aliases and templated type aliases in classes.


https://reviews.llvm.org/D27801

Files:
  change-namespace/ChangeNamespace.cpp
  unittests/change-namespace/ChangeNamespaceTests.cpp

Index: unittests/change-namespace/ChangeNamespaceTests.cpp
===
--- unittests/change-namespace/ChangeNamespaceTests.cpp
+++ unittests/change-namespace/ChangeNamespaceTests.cpp
@@ -1317,6 +1317,88 @@
   EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
 }
 
+TEST_F(ChangeNamespaceTest, UsingAliasInTemplate) {
+  NewNamespace = "na::nb::nc";
+  std::string Code = "namespace some_ns {\n"
+ "template \n"
+ "class G {};\n"
+ "}\n"
+ "namespace na {\n"
+ "template\n"
+ "using GG = some_ns::G;\n"
+ "}\n"
+ "namespace na {\n"
+ "namespace nb {\n"
+ "void f() {\n"
+ "  GG g;\n"
+ "}\n"
+ "} // namespace nb\n"
+ "} // namespace na\n";
+  std::string Expected = "namespace some_ns {\n"
+ "template \n"
+ "class G {};\n"
+ "}\n"
+ "namespace na {\n"
+ "template\n"
+ "using GG = some_ns::G;\n"
+ "}\n"
+ "namespace na {\n"
+ "namespace nb {\n"
+ "namespace nc {\n"
+ "void f() {\n"
+ "  GG g;\n"
+ "}\n"
+ "} // namespace nc\n\n"
+ "} // namespace nb\n"
+ "} // namespace na\n";
+  EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
+}
+
+TEST_F(ChangeNamespaceTest, TemplateUsingAliasInBaseClass) {
+  NewNamespace = "na::nb::nc";
+  std::string Code = "namespace some_ns {\n"
+ "template \n"
+ "class G {};\n"
+ "}\n"
+ "namespace na {\n"
+ "class Base {\n"
+ "public:\n"
+ "  template\n"
+ "  using GG = some_ns::G;\n"
+ "};\n"
+ "class Derived : public Base {};\n"
+ "}\n"
+ "namespace na {\n"
+ "namespace nb {\n"
+ "void f() {\n"
+ "  Derived::GG g;\n"
+ "}\n"
+ "} // namespace nb\n"
+ "} // namespace na\n";
+  std::string Expected = "namespace some_ns {\n"
+ "template \n"
+ "class G {};\n"
+ "}\n"
+ "namespace na {\n"
+ "class Base {\n"
+ "public:\n"
+ "  template\n"
+ "  using GG = some_ns::G;\n"
+ "};\n"
+ "class Derived : public Base {};\n"
+ "}\n"
+ "namespace na {\n"
+ "namespace nb {\n"
+ "namespace nc {\n"
+ "void f() {\n"
+ "  Derived::GG g;\n"
+ "}\n"
+ "} // namespace nc\n\n"
+ "} // namespace nb\n"
+ "} // namespace na\n";
+  EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
+}
+
 } // anonymous namespace
 } // namespace change_namespace
 } // namespace clang
Index: change-namespace/ChangeNamespace.cpp
===
--- change-namespace/ChangeNamespace.cpp
+++ change-namespace/ChangeNamespace.cpp
@@ -454,6 +454,17 @@
 BaseCtorInitializerTypeLocs.push_back(
 BaseInitializer->getTypeSourceInfo()->getTypeLoc());
   } else if (const auto *TLoc = Result.Nodes.getNodeAs("type")) {
+// This avoids fixing types with record types as qualifier, which is not
+// filtered by matchers in some cases, e.g. the type is templated. We should
+// handle the record type qualifier instead.
+if (TLoc->getTypeLocClass() == TypeLoc::Elaborated) {
+  NestedNameSpecifierLoc NestedNameSpecifier =
+  TLoc->castAs().getQualifierLoc();
+  const Type *SpecifierType =
+  NestedNameSpecifier.getNestedNameSpecifier()->getAsType();
+  if (SpecifierType && SpecifierType->isRecordType())
+return;
+}
 fixTypeLoc(Result, startLocationForType(*TLoc), endLoc

[clang-tools-extra] r289797 - [clang-tidy] Enhance modernize-use-auto to templated function casts

2016-12-15 Thread Malcolm Parsons via cfe-commits
Author: malcolm.parsons
Date: Thu Dec 15 04:19:56 2016
New Revision: 289797

URL: http://llvm.org/viewvc/llvm-project?rev=289797&view=rev
Log:
[clang-tidy] Enhance modernize-use-auto to templated function casts

Summary:
Use auto when declaring variables that are initialized by calling a templated
function that returns its explicit first argument.

Fixes PR26763.

Reviewers: aaron.ballman, alexfh, staronj, Prazek

Subscribers: Eugene.Zelenko, JDevlieghere, cfe-commits

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

Modified:
clang-tools-extra/trunk/clang-tidy/modernize/UseAutoCheck.cpp
clang-tools-extra/trunk/docs/ReleaseNotes.rst
clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-use-auto.rst

clang-tools-extra/trunk/test/clang-tidy/modernize-use-auto-cast-remove-stars.cpp
clang-tools-extra/trunk/test/clang-tidy/modernize-use-auto-cast.cpp

Modified: clang-tools-extra/trunk/clang-tidy/modernize/UseAutoCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/UseAutoCheck.cpp?rev=289797&r1=289796&r2=289797&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/modernize/UseAutoCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/UseAutoCheck.cpp Thu Dec 15 
04:19:56 2016
@@ -24,6 +24,7 @@ namespace {
 const char IteratorDeclStmtId[] = "iterator_decl";
 const char DeclWithNewId[] = "decl_new";
 const char DeclWithCastId[] = "decl_cast";
+const char DeclWithTemplateCastId[] = "decl_template";
 
 /// \brief Matches variable declarations that have explicit initializers that
 /// are not initializer lists.
@@ -169,6 +170,14 @@ AST_MATCHER(Decl, isFromStdNamespace) {
   return (Info && Info->isStr("std"));
 }
 
+/// Matches declaration reference or member expressions with explicit template
+/// arguments.
+AST_POLYMORPHIC_MATCHER(hasExplicitTemplateArgs,
+AST_POLYMORPHIC_SUPPORTED_TYPES(DeclRefExpr,
+MemberExpr)) {
+  return Node.hasExplicitTemplateArgs();
+}
+
 /// \brief Returns a DeclarationMatcher that matches standard iterators nested
 /// inside records with a standard container name.
 DeclarationMatcher standardIterator() {
@@ -240,18 +249,38 @@ StatementMatcher makeDeclWithCastMatcher
   .bind(DeclWithCastId);
 }
 
+StatementMatcher makeDeclWithTemplateCastMatcher() {
+  auto ST =
+  substTemplateTypeParmType(hasReplacementType(equalsBoundNode("arg")));
+
+  auto ExplicitCall =
+  anyOf(has(memberExpr(hasExplicitTemplateArgs())),
+has(ignoringImpCasts(declRefExpr(hasExplicitTemplateArgs();
+
+  auto TemplateArg =
+  hasTemplateArgument(0, refersToType(qualType().bind("arg")));
+
+  auto TemplateCall = callExpr(
+  ExplicitCall,
+  callee(functionDecl(TemplateArg,
+  returns(anyOf(ST, pointsTo(ST), references(ST));
+
+  return declStmt(unless(has(varDecl(
+  
unless(hasInitializer(ignoringImplicit(TemplateCall)))
+  .bind(DeclWithTemplateCastId);
+}
+
 StatementMatcher makeCombinedMatcher() {
   return declStmt(
   // At least one varDecl should be a child of the declStmt to ensure
   // it's a declaration list and avoid matching other declarations,
   // e.g. using directives.
-  has(varDecl()),
+  has(varDecl(unless(isImplicit(,
   // Skip declarations that are already using auto.
   unless(has(varDecl(anyOf(hasType(autoType()),
-   hasType(pointerType(pointee(autoType(,
-   hasType(referenceType(pointee(autoType(,
+   
hasType(qualType(hasDescendant(autoType(,
   anyOf(makeIteratorDeclMatcher(), makeDeclWithNewMatcher(),
-makeDeclWithCastMatcher()));
+makeDeclWithCastMatcher(), makeDeclWithTemplateCastMatcher()));
 }
 
 } // namespace
@@ -389,6 +418,8 @@ void UseAutoCheck::replaceExpr(const Dec
 
   // Space after 'auto' to handle cases where the '*' in the pointer type is
   // next to the identifier. This avoids changing 'int *p' into 'autop'.
+  // FIXME: This doesn't work for function pointers because the variable name
+  // is inside the type.
   Diag << FixItHint::CreateReplacement(Range, RemoveStars ? "auto " : "auto")
<< StarRemovals;
 }
@@ -411,6 +442,17 @@ void UseAutoCheck::check(const MatchFind
 },
 "use auto when initializing with a cast to avoid duplicating the type "
 "name");
+  } else if (const auto *Decl =
+ Result.Nodes.getNodeAs(DeclWithTemplateCastId)) {
+replaceExpr(
+Decl, Result.Context,
+[](const Expr *Expr) {
+  return cast(Expr->IgnoreImplicit())
+  ->getDirectCallee()
+  ->getReturnType();
+},
+"use auto when initializing with a template cast to avoid duplicating "
+

[PATCH] D27166: [clang-tidy] Enhance modernize-use-auto to templated function casts

2016-12-15 Thread Malcolm Parsons via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL289797: [clang-tidy] Enhance modernize-use-auto to templated 
function casts (authored by malcolm.parsons).

Changed prior to commit:
  https://reviews.llvm.org/D27166?vs=81540&id=81554#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D27166

Files:
  clang-tools-extra/trunk/clang-tidy/modernize/UseAutoCheck.cpp
  clang-tools-extra/trunk/docs/ReleaseNotes.rst
  clang-tools-extra/trunk/docs/clang-tidy/checks/modernize-use-auto.rst
  
clang-tools-extra/trunk/test/clang-tidy/modernize-use-auto-cast-remove-stars.cpp
  clang-tools-extra/trunk/test/clang-tidy/modernize-use-auto-cast.cpp

Index: clang-tools-extra/trunk/clang-tidy/modernize/UseAutoCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/modernize/UseAutoCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/modernize/UseAutoCheck.cpp
@@ -24,6 +24,7 @@
 const char IteratorDeclStmtId[] = "iterator_decl";
 const char DeclWithNewId[] = "decl_new";
 const char DeclWithCastId[] = "decl_cast";
+const char DeclWithTemplateCastId[] = "decl_template";
 
 /// \brief Matches variable declarations that have explicit initializers that
 /// are not initializer lists.
@@ -169,6 +170,14 @@
   return (Info && Info->isStr("std"));
 }
 
+/// Matches declaration reference or member expressions with explicit template
+/// arguments.
+AST_POLYMORPHIC_MATCHER(hasExplicitTemplateArgs,
+AST_POLYMORPHIC_SUPPORTED_TYPES(DeclRefExpr,
+MemberExpr)) {
+  return Node.hasExplicitTemplateArgs();
+}
+
 /// \brief Returns a DeclarationMatcher that matches standard iterators nested
 /// inside records with a standard container name.
 DeclarationMatcher standardIterator() {
@@ -240,18 +249,38 @@
   .bind(DeclWithCastId);
 }
 
+StatementMatcher makeDeclWithTemplateCastMatcher() {
+  auto ST =
+  substTemplateTypeParmType(hasReplacementType(equalsBoundNode("arg")));
+
+  auto ExplicitCall =
+  anyOf(has(memberExpr(hasExplicitTemplateArgs())),
+has(ignoringImpCasts(declRefExpr(hasExplicitTemplateArgs();
+
+  auto TemplateArg =
+  hasTemplateArgument(0, refersToType(qualType().bind("arg")));
+
+  auto TemplateCall = callExpr(
+  ExplicitCall,
+  callee(functionDecl(TemplateArg,
+  returns(anyOf(ST, pointsTo(ST), references(ST));
+
+  return declStmt(unless(has(varDecl(
+  unless(hasInitializer(ignoringImplicit(TemplateCall)))
+  .bind(DeclWithTemplateCastId);
+}
+
 StatementMatcher makeCombinedMatcher() {
   return declStmt(
   // At least one varDecl should be a child of the declStmt to ensure
   // it's a declaration list and avoid matching other declarations,
   // e.g. using directives.
-  has(varDecl()),
+  has(varDecl(unless(isImplicit(,
   // Skip declarations that are already using auto.
   unless(has(varDecl(anyOf(hasType(autoType()),
-   hasType(pointerType(pointee(autoType(,
-   hasType(referenceType(pointee(autoType(,
+   hasType(qualType(hasDescendant(autoType(,
   anyOf(makeIteratorDeclMatcher(), makeDeclWithNewMatcher(),
-makeDeclWithCastMatcher()));
+makeDeclWithCastMatcher(), makeDeclWithTemplateCastMatcher()));
 }
 
 } // namespace
@@ -389,6 +418,8 @@
 
   // Space after 'auto' to handle cases where the '*' in the pointer type is
   // next to the identifier. This avoids changing 'int *p' into 'autop'.
+  // FIXME: This doesn't work for function pointers because the variable name
+  // is inside the type.
   Diag << FixItHint::CreateReplacement(Range, RemoveStars ? "auto " : "auto")
<< StarRemovals;
 }
@@ -411,6 +442,17 @@
 },
 "use auto when initializing with a cast to avoid duplicating the type "
 "name");
+  } else if (const auto *Decl =
+ Result.Nodes.getNodeAs(DeclWithTemplateCastId)) {
+replaceExpr(
+Decl, Result.Context,
+[](const Expr *Expr) {
+  return cast(Expr->IgnoreImplicit())
+  ->getDirectCallee()
+  ->getReturnType();
+},
+"use auto when initializing with a template cast to avoid duplicating "
+"the type name");
   } else {
 llvm_unreachable("Bad Callback. No node provided.");
   }
Index: clang-tools-extra/trunk/docs/ReleaseNotes.rst
===
--- clang-tools-extra/trunk/docs/ReleaseNotes.rst
+++ clang-tools-extra/trunk/docs/ReleaseNotes.rst
@@ -93,7 +93,8 @@
 
 - The `modernize-use-auto
   `_ check
-  now warns about variable declarations that are initialized with a cast.
+  now warns about variable declarations that are

[PATCH] D27163: Introduce -f[no-]strict-return flag that controls code generation for C++'s undefined behaviour return optimisation

2016-12-15 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added a comment.

Ping.


Repository:
  rL LLVM

https://reviews.llvm.org/D27163



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


[PATCH] D27801: [change-namespace] handling templated type aliases correctly.

2016-12-15 Thread Haojian Wu via Phabricator via cfe-commits
hokein accepted this revision.
hokein added a comment.
This revision is now accepted and ready to land.

LGTM.




Comment at: change-namespace/ChangeNamespace.cpp:730
+  // Make `FromDecl` the immediate declaration that `Type` refers to, i.e. if
+  // `Type` is an alias type, we make `FromDecl` the type aias declaration.
+  // Also, don't fix the \p Type if it refers to a type alias decl in the moved

s/aias/alias



Comment at: unittests/change-namespace/ChangeNamespaceTests.cpp:1329
+ "using GG = some_ns::G;\n"
+ "}\n"
+ "namespace na {\n"

Add a trailing `// namespace na`. The same below.


https://reviews.llvm.org/D27801



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


[PATCH] D27801: [change-namespace] handling templated type aliases correctly.

2016-12-15 Thread Eric Liu via Phabricator via cfe-commits
ioeric updated this revision to Diff 81555.
ioeric marked 2 inline comments as done.
ioeric added a comment.

- Comments addressed


https://reviews.llvm.org/D27801

Files:
  change-namespace/ChangeNamespace.cpp
  unittests/change-namespace/ChangeNamespaceTests.cpp

Index: unittests/change-namespace/ChangeNamespaceTests.cpp
===
--- unittests/change-namespace/ChangeNamespaceTests.cpp
+++ unittests/change-namespace/ChangeNamespaceTests.cpp
@@ -1317,6 +1317,88 @@
   EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
 }
 
+TEST_F(ChangeNamespaceTest, UsingAliasInTemplate) {
+  NewNamespace = "na::nb::nc";
+  std::string Code = "namespace some_ns {\n"
+ "template \n"
+ "class G {};\n"
+ "} // namespace some_ns\n"
+ "namespace na {\n"
+ "template\n"
+ "using GG = some_ns::G;\n"
+ "} // namespace na\n"
+ "namespace na {\n"
+ "namespace nb {\n"
+ "void f() {\n"
+ "  GG g;\n"
+ "}\n"
+ "} // namespace nb\n"
+ "} // namespace na\n";
+  std::string Expected = "namespace some_ns {\n"
+ "template \n"
+ "class G {};\n"
+ "} // namespace some_ns\n"
+ "namespace na {\n"
+ "template\n"
+ "using GG = some_ns::G;\n"
+ "} // namespace na\n"
+ "namespace na {\n"
+ "namespace nb {\n"
+ "namespace nc {\n"
+ "void f() {\n"
+ "  GG g;\n"
+ "}\n"
+ "} // namespace nc\n\n"
+ "} // namespace nb\n"
+ "} // namespace na\n";
+  EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
+}
+
+TEST_F(ChangeNamespaceTest, TemplateUsingAliasInBaseClass) {
+  NewNamespace = "na::nb::nc";
+  std::string Code = "namespace some_ns {\n"
+ "template \n"
+ "class G {};\n"
+ "} // namespace some_ns\n"
+ "namespace na {\n"
+ "class Base {\n"
+ "public:\n"
+ "  template\n"
+ "  using GG = some_ns::G;\n"
+ "};\n"
+ "class Derived : public Base {};\n"
+ "} // namespace na\n"
+ "namespace na {\n"
+ "namespace nb {\n"
+ "void f() {\n"
+ "  Derived::GG g;\n"
+ "}\n"
+ "} // namespace nb\n"
+ "} // namespace na\n";
+  std::string Expected = "namespace some_ns {\n"
+ "template \n"
+ "class G {};\n"
+ "} // namespace some_ns\n"
+ "namespace na {\n"
+ "class Base {\n"
+ "public:\n"
+ "  template\n"
+ "  using GG = some_ns::G;\n"
+ "};\n"
+ "class Derived : public Base {};\n"
+ "} // namespace na\n"
+ "namespace na {\n"
+ "namespace nb {\n"
+ "namespace nc {\n"
+ "void f() {\n"
+ "  Derived::GG g;\n"
+ "}\n"
+ "} // namespace nc\n\n"
+ "} // namespace nb\n"
+ "} // namespace na\n";
+  EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
+}
+
 } // anonymous namespace
 } // namespace change_namespace
 } // namespace clang
Index: change-namespace/ChangeNamespace.cpp
===
--- change-namespace/ChangeNamespace.cpp
+++ change-namespace/ChangeNamespace.cpp
@@ -454,6 +454,17 @@
 BaseCtorInitializerTypeLocs.push_back(
 BaseInitializer->getTypeSourceInfo()->getTypeLoc());
   } else if (const auto *TLoc = Result.Nodes.getNodeAs("type")) {
+// This avoids fixing types with record types as qualifier, which is not
+// filtered by matchers in some cases, e.g. the type is templated. We should
+// handle the record type qualifier instead.
+if (TLoc->getTypeLocClass() == TypeLoc::Elaborated) {
+  NestedNameSpecifierLoc NestedNameSpecifier =
+  TLoc->castAs().getQualifierLoc();
+  const Type *SpecifierType =
+  NestedNameSpecifier.getNestedNameSpecifier()->getAsType();
+  if (SpecifierType && SpecifierTyp

[clang-tools-extra] r289799 - [change-namespace] handling templated type aliases correctly.

2016-12-15 Thread Eric Liu via cfe-commits
Author: ioeric
Date: Thu Dec 15 04:42:35 2016
New Revision: 289799

URL: http://llvm.org/viewvc/llvm-project?rev=289799&view=rev
Log:
[change-namespace] handling templated type aliases correctly.

Summary: This fixes templated type aliases and templated type aliases in 
classes.

Reviewers: hokein

Subscribers: cfe-commits

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

Modified:
clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp
clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp

Modified: clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp?rev=289799&r1=289798&r2=289799&view=diff
==
--- clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp (original)
+++ clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp Thu Dec 15 
04:42:35 2016
@@ -454,6 +454,17 @@ void ChangeNamespaceTool::run(
 BaseCtorInitializerTypeLocs.push_back(
 BaseInitializer->getTypeSourceInfo()->getTypeLoc());
   } else if (const auto *TLoc = Result.Nodes.getNodeAs("type")) {
+// This avoids fixing types with record types as qualifier, which is not
+// filtered by matchers in some cases, e.g. the type is templated. We 
should
+// handle the record type qualifier instead.
+if (TLoc->getTypeLocClass() == TypeLoc::Elaborated) {
+  NestedNameSpecifierLoc NestedNameSpecifier =
+  TLoc->castAs().getQualifierLoc();
+  const Type *SpecifierType =
+  NestedNameSpecifier.getNestedNameSpecifier()->getAsType();
+  if (SpecifierType && SpecifierType->isRecordType())
+return;
+}
 fixTypeLoc(Result, startLocationForType(*TLoc), endLocationForType(*TLoc),
*TLoc);
   } else if (const auto *VarRef =
@@ -705,27 +716,32 @@ void ChangeNamespaceTool::fixTypeLoc(
   const auto *FromDecl = Result.Nodes.getNodeAs("from_decl");
   // `hasDeclaration` gives underlying declaration, but if the type is
   // a typedef type, we need to use the typedef type instead.
+  auto IsInMovedNs = [&](const NamedDecl *D) {
+if (!llvm::StringRef(D->getQualifiedNameAsString())
+ .startswith(OldNamespace + "::"))
+  return false;
+auto ExpansionLoc = 
Result.SourceManager->getExpansionLoc(D->getLocStart());
+if (ExpansionLoc.isInvalid())
+  return false;
+llvm::StringRef Filename = Result.SourceManager->getFilename(ExpansionLoc);
+return FilePatternRE.match(Filename);
+  };
+  // Make `FromDecl` the immediate declaration that `Type` refers to, i.e. if
+  // `Type` is an alias type, we make `FromDecl` the type alias declaration.
+  // Also, don't fix the \p Type if it refers to a type alias decl in the moved
+  // namespace since the alias decl will be moved along with the type 
reference.
   if (auto *Typedef = Type.getType()->getAs()) {
 FromDecl = Typedef->getDecl();
-auto IsInMovedNs = [&](const NamedDecl *D) {
-  if (!llvm::StringRef(D->getQualifiedNameAsString())
-   .startswith(OldNamespace + "::"))
-return false;
-  auto ExpansionLoc =
-  Result.SourceManager->getExpansionLoc(D->getLocStart());
-  if (ExpansionLoc.isInvalid())
-return false;
-  llvm::StringRef Filename =
-  Result.SourceManager->getFilename(ExpansionLoc);
-  return FilePatternRE.match(Filename);
-};
-// Don't fix the \p Type if it refers to a type alias decl in the moved
-// namespace since the alias decl will be moved along with the type
-// reference.
 if (IsInMovedNs(FromDecl))
   return;
+  } else if (auto *TemplateType =
+ Type.getType()->getAs()) {
+if (TemplateType->isTypeAlias()) {
+  FromDecl = TemplateType->getTemplateName().getAsTemplateDecl();
+  if (IsInMovedNs(FromDecl))
+return;
+}
   }
-
   const auto *DeclCtx = Result.Nodes.getNodeAs("dc");
   assert(DeclCtx && "Empty decl context.");
   replaceQualifiedSymbolInDeclContext(Result, DeclCtx->getDeclContext(), Start,

Modified: 
clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp?rev=289799&r1=289798&r2=289799&view=diff
==
--- clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp 
(original)
+++ clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp 
Thu Dec 15 04:42:35 2016
@@ -1317,6 +1317,88 @@ TEST_F(ChangeNamespaceTest, KeepGlobalSp
   EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
 }
 
+TEST_F(ChangeNamespaceTest, UsingAliasInTemplate) {
+  NewNamespace = "na::nb::nc";
+  std::string Code = "namespace some_ns {\n"
+ "template \n"
+   

[PATCH] D27801: [change-namespace] handling templated type aliases correctly.

2016-12-15 Thread Eric Liu via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL289799: [change-namespace] handling templated type aliases 
correctly. (authored by ioeric).

Changed prior to commit:
  https://reviews.llvm.org/D27801?vs=81555&id=81557#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D27801

Files:
  clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp
  clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp

Index: clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp
===
--- clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp
+++ clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp
@@ -1317,6 +1317,88 @@
   EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
 }
 
+TEST_F(ChangeNamespaceTest, UsingAliasInTemplate) {
+  NewNamespace = "na::nb::nc";
+  std::string Code = "namespace some_ns {\n"
+ "template \n"
+ "class G {};\n"
+ "} // namespace some_ns\n"
+ "namespace na {\n"
+ "template\n"
+ "using GG = some_ns::G;\n"
+ "} // namespace na\n"
+ "namespace na {\n"
+ "namespace nb {\n"
+ "void f() {\n"
+ "  GG g;\n"
+ "}\n"
+ "} // namespace nb\n"
+ "} // namespace na\n";
+  std::string Expected = "namespace some_ns {\n"
+ "template \n"
+ "class G {};\n"
+ "} // namespace some_ns\n"
+ "namespace na {\n"
+ "template\n"
+ "using GG = some_ns::G;\n"
+ "} // namespace na\n"
+ "namespace na {\n"
+ "namespace nb {\n"
+ "namespace nc {\n"
+ "void f() {\n"
+ "  GG g;\n"
+ "}\n"
+ "} // namespace nc\n\n"
+ "} // namespace nb\n"
+ "} // namespace na\n";
+  EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
+}
+
+TEST_F(ChangeNamespaceTest, TemplateUsingAliasInBaseClass) {
+  NewNamespace = "na::nb::nc";
+  std::string Code = "namespace some_ns {\n"
+ "template \n"
+ "class G {};\n"
+ "} // namespace some_ns\n"
+ "namespace na {\n"
+ "class Base {\n"
+ "public:\n"
+ "  template\n"
+ "  using GG = some_ns::G;\n"
+ "};\n"
+ "class Derived : public Base {};\n"
+ "} // namespace na\n"
+ "namespace na {\n"
+ "namespace nb {\n"
+ "void f() {\n"
+ "  Derived::GG g;\n"
+ "}\n"
+ "} // namespace nb\n"
+ "} // namespace na\n";
+  std::string Expected = "namespace some_ns {\n"
+ "template \n"
+ "class G {};\n"
+ "} // namespace some_ns\n"
+ "namespace na {\n"
+ "class Base {\n"
+ "public:\n"
+ "  template\n"
+ "  using GG = some_ns::G;\n"
+ "};\n"
+ "class Derived : public Base {};\n"
+ "} // namespace na\n"
+ "namespace na {\n"
+ "namespace nb {\n"
+ "namespace nc {\n"
+ "void f() {\n"
+ "  Derived::GG g;\n"
+ "}\n"
+ "} // namespace nc\n\n"
+ "} // namespace nb\n"
+ "} // namespace na\n";
+  EXPECT_EQ(format(Expected), runChangeNamespaceOnCode(Code));
+}
+
 } // anonymous namespace
 } // namespace change_namespace
 } // namespace clang
Index: clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp
===
--- clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp
+++ clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp
@@ -454,6 +454,17 @@
 BaseCtorInitializerTypeLocs.push_back(
 BaseInitializer->getTypeSourceInfo()->getTypeLoc());
   } else if (const auto *TLoc = Result.Nodes.getNodeAs("type")) {
+// This avoids fixing types with record types as qualifier, which is not
+// filtered by matchers in some cases, e.g. the type is templated. We should

[libcxx] r289802 - Fix XFAILS for is_trivially_destructible trait

2016-12-15 Thread Eric Fiselier via cfe-commits
Author: ericwf
Date: Thu Dec 15 05:00:07 2016
New Revision: 289802

URL: http://llvm.org/viewvc/llvm-project?rev=289802&view=rev
Log:
Fix XFAILS for is_trivially_destructible trait

Modified:
libcxx/trunk/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/dtor.pass.cpp
libcxx/trunk/test/std/utilities/utility/pairs/pairs.pair/dtor.pass.cpp

Modified: 
libcxx/trunk/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/dtor.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/dtor.pass.cpp?rev=289802&r1=289801&r2=289802&view=diff
==
--- libcxx/trunk/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/dtor.pass.cpp 
(original)
+++ libcxx/trunk/test/std/utilities/tuple/tuple.tuple/tuple.cnstr/dtor.pass.cpp 
Thu Dec 15 05:00:07 2016
@@ -9,9 +9,6 @@
 
 // UNSUPPORTED: c++98, c++03
 
-// Doesn't pass due to use of is_trivially_* trait.
-// XFAIL: gcc-4.9
-
 // 
 
 // template  class tuple;

Modified: libcxx/trunk/test/std/utilities/utility/pairs/pairs.pair/dtor.pass.cpp
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/utilities/utility/pairs/pairs.pair/dtor.pass.cpp?rev=289802&r1=289801&r2=289802&view=diff
==
--- libcxx/trunk/test/std/utilities/utility/pairs/pairs.pair/dtor.pass.cpp 
(original)
+++ libcxx/trunk/test/std/utilities/utility/pairs/pairs.pair/dtor.pass.cpp Thu 
Dec 15 05:00:07 2016
@@ -9,9 +9,6 @@
 
 // UNSUPPORTED: c++98, c++03
 
-// Doesn't pass due to use of is_trivially_* trait.
-// XFAIL: gcc-4.9
-
 // 
 
 // template  struct pair


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


[PATCH] D27673: [clang-move] Only move used helper declarations.

2016-12-15 Thread Eric Liu via Phabricator via cfe-commits
ioeric added a comment.

Second rounds. Will start reviewing `CallGraph` code next.




Comment at: clang-move/ClangMove.cpp:492
+  isDefinition(), unless(InMovedClass), InOldCC,
+  anyOf(isStaticStorageClass(), hasParent(namespaceDecl(isAnonymous();
+  auto HelperFuncOrVar = namedDecl(anyOf(functionDecl(IsOldCCHelperDefinition),

hokein wrote:
> ioeric wrote:
> > It seems that `isStaticStorageClass` is preventing combining matchers for 
> > functions, variables, and classes. Maybe only apply this matcher on 
> > `functionDecl` and `varDecl` below, so that helper classes can be matched 
> > with the same matcher?
> Seems that it is hard to reuse the same matcher for `functionDecl`/`varDecl` 
> and `CXXRecordDecl` since `isStaticStorageClass` is not available to  
> `CXXRecordDecl`. So we have to match helper classes, helper functions/vars 
> separately.  Have cleaned the code to make it clearer.
I mean merging helper classes into `helperFuncOrVar` (maybe need to be renamed) 
so that class helpers are parallel with `functionDecl` and `varDecl` here.



Comment at: clang-move/ClangMove.cpp:459
   
//
-  auto InOldCCNamedOrGlobalNamespace =
-  allOf(hasParent(decl(anyOf(namespaceDecl(unless(isAnonymous())),
- translationUnitDecl(,
-InOldCC);
-  // Matching using decls/type alias decls which are in named namespace or
-  // global namespace. Those in classes, functions and anonymous namespaces are
-  // covered in other matchers.
+  auto InOldCCNamespace = allOf(
+  hasParent(decl(anyOf(namespaceDecl(), translationUnitDecl(, InOldCC);

I got the meaning here, but the name is a bit inaccurate since this also 
includes `TranslationUnitDecl`.



Comment at: clang-move/ClangMove.cpp:461
+  hasParent(decl(anyOf(namespaceDecl(), translationUnitDecl(, InOldCC);
+  // Matching using decls/type alias decls which are in named/anonymous/global
+  // namespace. Those in classes, functions are covered in other matchers.

Maybe also explain a bit on how you handle these using and alias decls here.

Are they always copied/moved regardless where they are?



Comment at: clang-move/ClangMove.cpp:493
+ varDecl(IsOldCCHelperDefinition)));
+  auto HelperClasses =
+  cxxRecordDecl(isDefinition(), unless(InMovedClass), InOldCC,

Thinking about this some more. Helpers might be (incorrectly) defined in 
non-anonymous namespaces without static qualifier. Do we want to consider these?



Comment at: clang-move/ClangMove.cpp:698
+// Filter out unused helper declarations.
+// We only move the used helper declarations (including transversely used
+// helpers) and the given symbols being moved.

transitively?



Comment at: clang-move/UsedHelperDeclFinder.cpp:20
+// outmost eclosing class declaration or function declaration if exists.
+// Because we consider that all method declarations in a class are represented
+// by a single node which belongs to that class.

s/Because.*$/We treat a class and all its members as one single node in the 
call graph/?



Comment at: clang-move/UsedHelperDeclFinder.h:22
+
+// Call graph for helper declarations in a single translation unit e.g. old.cc.
+// Helper declarations include following types:

hokein wrote:
> ioeric wrote:
> > What's the relationship between this and the `CallGraph` class in 
> > `clang/Analysis/CallGraph.h`?
> There is no relationship between them. We build our own CallGraph class to 
> meet our use cases. The CallGraph in `clang/Analysis` only supports function 
> decls, and it seems hard to reuse it. The thing we reuse is the 
> `CallGraphNode`. 
So, this should be named something like reference graph instead of call graph? 
Call graph might be confusing for readers without context.



Comment at: clang-move/UsedHelperDeclFinder.h:34
+//
+// To construct the graph, we use AST matcher to find interested Decls (usually
+// a pair of Caller and Callee), and add an edge from the Caller node to the

s/interested/interesting/



Comment at: clang-move/UsedHelperDeclFinder.h:45
+// definition is in old.cc, the representing graph node for this function is
+// associated with the FunctionDecl in old.h, because there are two
+// different FunctionDecl pointers in the AST implementation, we want to make 
it

what is this `because...` associated with?


https://reviews.llvm.org/D27673



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


[PATCH] D27163: Introduce -f[no-]strict-return flag that controls code generation for C++'s undefined behaviour return optimisation

2016-12-15 Thread Arthur O'Dwyer via Phabricator via cfe-commits
Quuxplusone added inline comments.



Comment at: include/clang/Sema/AnalysisBasedWarnings.h:93
 
-  void IssueWarnings(Policy P, FunctionScopeInfo *fscope,
- const Decl *D, const BlockExpr *blkExpr);
+  void IssueWarnings(Policy P, FunctionScopeInfo *fscope, Decl *D,
+ const BlockExpr *blkExpr);

If you remove the coupling between -fno-strict-return and -Wreturn-type, then 
you won't need to remove `const` in all these places. I think that alone is a 
good enough reason not to couple them.



Comment at: lib/CodeGen/CodeGenFunction.cpp:1078
+  QualType T = FD->getReturnType();
+  if (T.isTriviallyCopyableType(Context)) {
+// Avoid the optimization for functions that return trivially copyable

Peanut-gallery question: Does `isTriviallyCopyableType` also check that the 
type is trivially destructible and/or default-constructible? Do those things 
matter?



Comment at: lib/CodeGen/CodeGenFunction.cpp:1173
+} else if (CGM.getCodeGenOpts().StrictReturn ||
+   shouldUseUndefinedBehaviorReturnOptimization(FD, getContext())) 
{
+  if (CGM.getCodeGenOpts().OptimizationLevel == 0)

I'd expect this to look more like

bool ShouldOmitUnreachable = !CGM.getCodeGenOpts().StrictReturn && 
FD->getReturnType().isTriviallyCopyableType(Context);
// same ifs as the old code
if (!ShouldOmitUnreachable) {
Builder.CreateUnreachable();
Builder.ClearInsertionPoint();
}

Or in fact, is there a good reason this codepath isn't piggybacking on 
`FD->hasImplicitReturnZero()`?  Why not just give every function 
`hasImplicitReturnZero` when `-fno-strict-return` is in effect?

At which point, `-fno-strict-return` might seem like the wrong name; you could 
just call it something like `-fimplicit-return-zero`, which would also have the 
minor benefit of making the `-fno-*` option the default.


Repository:
  rL LLVM

https://reviews.llvm.org/D27163



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


r289809 - [TESTS] Initial commit of tests, by Andrew Tischenko

2016-12-15 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Thu Dec 15 06:06:27 2016
New Revision: 289809

URL: http://llvm.org/viewvc/llvm-project?rev=289809&view=rev
Log:
[TESTS] Initial commit of tests, by Andrew Tischenko

Added:
cfe/trunk/test/CodeGen/vector-sqrt.c

Added: cfe/trunk/test/CodeGen/vector-sqrt.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/vector-sqrt.c?rev=289809&view=auto
==
--- cfe/trunk/test/CodeGen/vector-sqrt.c (added)
+++ cfe/trunk/test/CodeGen/vector-sqrt.c Thu Dec 15 06:06:27 2016
@@ -0,0 +1,27 @@
+// RUN: %clang %s -march=haswell -O3 -S -o - | FileCheck %s
+
+#include 
+
+// CHECK-LABEL: sqrtd2
+// CHECK:   vsqrtsd (%rdi), %xmm0, %xmm0
+// CHECK-NEXT:  vsqrtsd 8(%rdi), %xmm1, %xmm1
+// CHECK-NEXT:  vunpcklpd %xmm1, %xmm0, %xmm0 # xmm0 = xmm0[0],xmm1[0]
+// CHECK-NEXT:  retq
+
+__m128d sqrtd2(double* v) {
+  return _mm_setr_pd(__builtin_sqrt(v[0]), __builtin_sqrt(v[1]));
+}
+
+// CHECK-LABEL: sqrtf4
+// CHECK:   vsqrtss (%rdi), %xmm0, %xmm0
+// CHECK-NEXT:  vsqrtss 4(%rdi), %xmm1, %xmm1
+// CHECK-NEXT:  vsqrtss 8(%rdi), %xmm2, %xmm2
+// CHECK-NEXT:  vsqrtss 12(%rdi), %xmm3, %xmm3
+// CHECK-NEXT:  vinsertps $16, %xmm1, %xmm0, %xmm0 # xmm0 = 
xmm0[0],xmm1[0],xmm0[2,3]
+// CHECK-NEXT:  vinsertps $32, %xmm2, %xmm0, %xmm0 # xmm0 = 
xmm0[0,1],xmm2[0],xmm0[3]
+// CHECK-NEXT:  vinsertps $48, %xmm3, %xmm0, %xmm0 # xmm0 = xmm0[0,1,2],xmm3[0]
+// CHECK-NEXT:  retq
+
+__m128 sqrtf4(float* v) {
+  return _mm_setr_ps(__builtin_sqrtf(v[0]), __builtin_sqrtf(v[1]), 
__builtin_sqrtf(v[2]), __builtin_sqrtf(v[3]));
+}


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


r289812 - Revert "[TESTS] Initial commit of tests, by Andrew Tischenko"

2016-12-15 Thread Alexey Bataev via cfe-commits
Author: abataev
Date: Thu Dec 15 06:24:20 2016
New Revision: 289812

URL: http://llvm.org/viewvc/llvm-project?rev=289812&view=rev
Log:
Revert "[TESTS] Initial commit of tests, by Andrew Tischenko"

This reverts commit 5898c713bee5e96aae87c73e11f3f4a7d19c74ed.

Removed:
cfe/trunk/test/CodeGen/vector-sqrt.c

Removed: cfe/trunk/test/CodeGen/vector-sqrt.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/vector-sqrt.c?rev=289811&view=auto
==
--- cfe/trunk/test/CodeGen/vector-sqrt.c (original)
+++ cfe/trunk/test/CodeGen/vector-sqrt.c (removed)
@@ -1,27 +0,0 @@
-// RUN: %clang %s -march=haswell -O3 -S -o - | FileCheck %s
-
-#include 
-
-// CHECK-LABEL: sqrtd2
-// CHECK:   vsqrtsd (%rdi), %xmm0, %xmm0
-// CHECK-NEXT:  vsqrtsd 8(%rdi), %xmm1, %xmm1
-// CHECK-NEXT:  vunpcklpd %xmm1, %xmm0, %xmm0 # xmm0 = xmm0[0],xmm1[0]
-// CHECK-NEXT:  retq
-
-__m128d sqrtd2(double* v) {
-  return _mm_setr_pd(__builtin_sqrt(v[0]), __builtin_sqrt(v[1]));
-}
-
-// CHECK-LABEL: sqrtf4
-// CHECK:   vsqrtss (%rdi), %xmm0, %xmm0
-// CHECK-NEXT:  vsqrtss 4(%rdi), %xmm1, %xmm1
-// CHECK-NEXT:  vsqrtss 8(%rdi), %xmm2, %xmm2
-// CHECK-NEXT:  vsqrtss 12(%rdi), %xmm3, %xmm3
-// CHECK-NEXT:  vinsertps $16, %xmm1, %xmm0, %xmm0 # xmm0 = 
xmm0[0],xmm1[0],xmm0[2,3]
-// CHECK-NEXT:  vinsertps $32, %xmm2, %xmm0, %xmm0 # xmm0 = 
xmm0[0,1],xmm2[0],xmm0[3]
-// CHECK-NEXT:  vinsertps $48, %xmm3, %xmm0, %xmm0 # xmm0 = xmm0[0,1,2],xmm3[0]
-// CHECK-NEXT:  retq
-
-__m128 sqrtf4(float* v) {
-  return _mm_setr_ps(__builtin_sqrtf(v[0]), __builtin_sqrtf(v[1]), 
__builtin_sqrtf(v[2]), __builtin_sqrtf(v[3]));
-}


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


[PATCH] D27752: [clang] Use after move bug fixes

2016-12-15 Thread Stanisław Barzowski via Phabricator via cfe-commits
sbarzowski accepted this revision.
sbarzowski added a reviewer: sbarzowski.
sbarzowski added a comment.

LGTM


https://reviews.llvm.org/D27752



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


[clang-tools-extra] r289816 - [change-namespace] fix a case references to templated using alias are qualified types.

2016-12-15 Thread Eric Liu via cfe-commits
Author: ioeric
Date: Thu Dec 15 07:02:41 2016
New Revision: 289816

URL: http://llvm.org/viewvc/llvm-project?rev=289816&view=rev
Log:
[change-namespace] fix a case references to templated using alias are qualified 
types.

Modified:
clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp
clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp

Modified: clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp?rev=289816&r1=289815&r2=289816&view=diff
==
--- clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp (original)
+++ clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp Thu Dec 15 
07:02:41 2016
@@ -457,16 +457,18 @@ void ChangeNamespaceTool::run(
 // This avoids fixing types with record types as qualifier, which is not
 // filtered by matchers in some cases, e.g. the type is templated. We 
should
 // handle the record type qualifier instead.
-if (TLoc->getTypeLocClass() == TypeLoc::Elaborated) {
+TypeLoc Loc = *TLoc;
+while (Loc.getTypeLocClass() == TypeLoc::Qualified)
+  Loc = Loc.getNextTypeLoc();
+if (Loc.getTypeLocClass() == TypeLoc::Elaborated) {
   NestedNameSpecifierLoc NestedNameSpecifier =
-  TLoc->castAs().getQualifierLoc();
+  Loc.castAs().getQualifierLoc();
   const Type *SpecifierType =
   NestedNameSpecifier.getNestedNameSpecifier()->getAsType();
   if (SpecifierType && SpecifierType->isRecordType())
 return;
 }
-fixTypeLoc(Result, startLocationForType(*TLoc), endLocationForType(*TLoc),
-   *TLoc);
+fixTypeLoc(Result, startLocationForType(Loc), endLocationForType(Loc), 
Loc);
   } else if (const auto *VarRef =
  Result.Nodes.getNodeAs("var_ref")) {
 const auto *Var = Result.Nodes.getNodeAs("var_decl");

Modified: 
clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp?rev=289816&r1=289815&r2=289816&view=diff
==
--- clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp 
(original)
+++ clang-tools-extra/trunk/unittests/change-namespace/ChangeNamespaceTests.cpp 
Thu Dec 15 07:02:41 2016
@@ -1365,6 +1365,8 @@ TEST_F(ChangeNamespaceTest, TemplateUsin
  "public:\n"
  "  template\n"
  "  using GG = some_ns::G;\n"
+ "\n"
+ "  struct Nested {};\n"
  "};\n"
  "class Derived : public Base {};\n"
  "} // namespace na\n"
@@ -1372,6 +1374,10 @@ TEST_F(ChangeNamespaceTest, TemplateUsin
  "namespace nb {\n"
  "void f() {\n"
  "  Derived::GG g;\n"
+ "  const Derived::GG gg;\n"
+ "  const Derived::GG* gg_ptr;\n"
+ "  struct Derived::Nested nested;\n"
+ "  const struct Derived::Nested *nested_ptr;\n"
  "}\n"
  "} // namespace nb\n"
  "} // namespace na\n";
@@ -1384,6 +1390,8 @@ TEST_F(ChangeNamespaceTest, TemplateUsin
  "public:\n"
  "  template\n"
  "  using GG = some_ns::G;\n"
+ "\n"
+ "  struct Nested {};\n"
  "};\n"
  "class Derived : public Base {};\n"
  "} // namespace na\n"
@@ -1392,6 +1400,10 @@ TEST_F(ChangeNamespaceTest, TemplateUsin
  "namespace nc {\n"
  "void f() {\n"
  "  Derived::GG g;\n"
+ "  const Derived::GG gg;\n"
+ "  const Derived::GG* gg_ptr;\n"
+ "  struct Derived::Nested nested;\n"
+ "  const struct Derived::Nested *nested_ptr;\n"
  "}\n"
  "} // namespace nc\n\n"
  "} // namespace nb\n"


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


[PATCH] D27806: [clang-tidy] Add misc-invalid-range

2016-12-15 Thread Piotr Padlewski via Phabricator via cfe-commits
Prazek created this revision.
Prazek added reviewers: alexfh, malcolm.parsons.
Prazek added a subscriber: cfe-commits.
Herald added subscribers: JDevlieghere, mgorny.

Warns if algorithm is used with ``.begin()`` and ``.end()`` from
different variables.


https://reviews.llvm.org/D27806

Files:
  clang-tidy/ClangTidy.cpp
  clang-tidy/misc/CMakeLists.txt
  clang-tidy/misc/InvalidRangeCheck.cpp
  clang-tidy/misc/InvalidRangeCheck.h
  clang-tidy/misc/MiscTidyModule.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/misc-invalid-range.rst
  test/clang-tidy/misc-invalid-range.cpp

Index: test/clang-tidy/misc-invalid-range.cpp
===
--- /dev/null
+++ test/clang-tidy/misc-invalid-range.cpp
@@ -0,0 +1,47 @@
+// RUN: %check_clang_tidy %s misc-invalid-range %t
+
+namespace std {
+
+template 
+OutputIterator copy(InputIterator first, InputIterator last, OutputIterator result) {
+  return result;
+}
+
+template 
+OutputIterator move(InputIterator first, InputIterator last, OutputIterator result) {
+  return result;
+}
+
+template 
+T move(T &&) { return T(); }
+
+template 
+void fill(InputIterator first, InputIterator last, const Val &v) {
+}
+
+template 
+class vector {
+public:
+  T *begin();
+  T *end();
+};
+}
+
+void test_copy() {
+  std::vector v, v2;
+  std::copy(v.begin(), v2.end(), v2.begin());
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: call to algorithm with begin and end from different objects [misc-invalid-range]
+
+  std::copy(v.begin(), v.end(), v2.begin());
+}
+
+void test_move() {
+  std::vector v;
+  auto &v2 = v;
+  std::move(v.begin(), v2.end(), v2.begin());
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: call to algorithm with begin and end from different objects [misc-invalid-range]
+
+  std::move(v.begin(), v.end(), v2.begin());
+  std::move(v.begin());
+  test_copy();
+}
Index: docs/clang-tidy/checks/misc-invalid-range.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/misc-invalid-range.rst
@@ -0,0 +1,17 @@
+.. title:: clang-tidy - misc-invalid-range
+
+misc-invalid-range
+==
+
+This check finds invalid calls to algorithms with obviously invalid range of
+iterators like:
+
+.. code-block:: c++
+std::fill(v.begin(), v2.end(), it);
+
+It checks if first and second argument of call is call to ``begin()``
+and ``end()``, but on different objects (having different name).
+
+By default it looks for all algorithms from . This can be
+changed by using ``AlgorithmNames`` option, where empty list means that any
+function name will be accepted.
\ No newline at end of file
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -65,6 +65,7 @@
misc-inaccurate-erase
misc-incorrect-roundings
misc-inefficient-algorithm
+   misc-invalid-range
misc-macro-parentheses
misc-macro-repeated-side-effects
misc-misplaced-const
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -81,6 +81,12 @@
   Warns if an object is used after it has been moved, without an intervening
   reinitialization.
 
+- New `misc-invalid-range
+  `_ check
+
+  Warns if algorithm is used with ``.begin()`` and ``.end()`` from different
+  variables.
+
 - `modernize-make-unique
   `_
   and `modernize-make-shared
Index: clang-tidy/misc/MiscTidyModule.cpp
===
--- clang-tidy/misc/MiscTidyModule.cpp
+++ clang-tidy/misc/MiscTidyModule.cpp
@@ -20,6 +20,7 @@
 #include "InaccurateEraseCheck.h"
 #include "IncorrectRoundings.h"
 #include "InefficientAlgorithmCheck.h"
+#include "InvalidRangeCheck.h"
 #include "MacroParenthesesCheck.h"
 #include "MacroRepeatedSideEffectsCheck.h"
 #include "MisplacedConstCheck.h"
@@ -63,6 +64,7 @@
 CheckFactories.registerCheck("misc-argument-comment");
 CheckFactories.registerCheck(
 "misc-assert-side-effect");
+CheckFactories.registerCheck("misc-invalid-range");
 CheckFactories.registerCheck("misc-misplaced-const");
 CheckFactories.registerCheck(
 "misc-unconventional-assign-operator");
Index: clang-tidy/misc/InvalidRangeCheck.h
===
--- /dev/null
+++ clang-tidy/misc/InvalidRangeCheck.h
@@ -0,0 +1,40 @@
+//===--- InvalidRangeCheck.h - clang-tidy*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===-

[PATCH] D19667: [ubsan] Minimize size of data for type_mismatch

2016-12-15 Thread Filipe Cabecinhas via Phabricator via cfe-commits
filcab abandoned this revision.
filcab added a comment.

I will post a new patch, using the features from 
https://reviews.llvm.org/rL289444.


https://reviews.llvm.org/D19667



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


[PATCH] D27810: Normalize all filenames before searching FileManager caches

2016-12-15 Thread Erik Verbruggen via Phabricator via cfe-commits
erikjv created this revision.
erikjv added reviewers: bkramer, klimek.
erikjv added a subscriber: cfe-commits.

The problem on windows is that both forward-slashes and back-slashes are
accepted as path separators. However, the FileManager stores the path as
reported by the OS after opening the file. For example: d:\dev/foo.cc
will be stored with the key d:\dev\foo.cc. Subsequent lookups for the
case with the forward slash then miss that cache entry, and clang ends
up doing many more file accesses than needed.

It also had the nasty side-effect of not closing the file the second
time it was loaded (until the FileManager was destroyed): the lexer
would create a buffer by file-id, and the buffer cache would return the
buffer created the previous time the file was opened. And because
creating the buffer also closes the file, this would not happen. As long
as the FileManager was around (i.e. as long as the translation unit for
e.g. libclang was around), and IDE couldn't save that file.


https://reviews.llvm.org/D27810

Files:
  lib/Basic/FileManager.cpp


Index: lib/Basic/FileManager.cpp
===
--- lib/Basic/FileManager.cpp
+++ lib/Basic/FileManager.cpp
@@ -214,6 +214,12 @@
 
 const FileEntry *FileManager::getFile(StringRef Filename, bool openFile,
   bool CacheFailure) {
+#ifdef LLVM_ON_WIN32
+  SmallString<128> NormalizedPath(Filename.str());
+  llvm::sys::path::native(NormalizedPath);
+  Filename = NormalizedPath;
+#endif // LLVM_ON_WIN32
+
   ++NumFileLookups;
 
   // See if there is already an entry in the map.


Index: lib/Basic/FileManager.cpp
===
--- lib/Basic/FileManager.cpp
+++ lib/Basic/FileManager.cpp
@@ -214,6 +214,12 @@
 
 const FileEntry *FileManager::getFile(StringRef Filename, bool openFile,
   bool CacheFailure) {
+#ifdef LLVM_ON_WIN32
+  SmallString<128> NormalizedPath(Filename.str());
+  llvm::sys::path::native(NormalizedPath);
+  Filename = NormalizedPath;
+#endif // LLVM_ON_WIN32
+
   ++NumFileLookups;
 
   // See if there is already an entry in the map.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D27163: Introduce -f[no-]strict-return flag that controls code generation for C++'s undefined behaviour return optimisation

2016-12-15 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman updated this revision to Diff 81584.
arphaman marked 3 inline comments as done.
arphaman added a comment.

The updated patch removes the dependency on the "-Wreturn-type" diagnostic and 
verifies that functions that return a type with a non-trivial default 
constructor are always optimized.


Repository:
  rL LLVM

https://reviews.llvm.org/D27163

Files:
  include/clang/Driver/Options.td
  include/clang/Frontend/CodeGenOptions.def
  lib/CodeGen/CodeGenFunction.cpp
  lib/Driver/Tools.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/CodeGenCXX/return.cpp
  test/CodeGenObjCXX/return.mm
  test/Driver/clang_f_opts.c

Index: test/Driver/clang_f_opts.c
===
--- test/Driver/clang_f_opts.c
+++ test/Driver/clang_f_opts.c
@@ -469,3 +469,8 @@
 // CHECK-WCHAR2: -fshort-wchar
 // CHECK-WCHAR2-NOT: -fno-short-wchar
 // DELIMITERS: {{^ *"}}
+
+// RUN: %clang -### -S -fstrict-return %s 2>&1 | FileCheck -check-prefix=CHECK-STRICT-RETURN %s
+// RUN: %clang -### -S -fno-strict-return %s 2>&1 | FileCheck -check-prefix=CHECK-NO-STRICT-RETURN %s
+// CHECK-STRICT-RETURN-NOT: "-fno-strict-return"
+// CHECK-NO-STRICT-RETURN: "-fno-strict-return"
Index: test/CodeGenObjCXX/return.mm
===
--- /dev/null
+++ test/CodeGenObjCXX/return.mm
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -emit-llvm -fblocks -triple x86_64-apple-darwin -fstrict-return -o - %s | FileCheck %s
+// RUN: %clang_cc1 -emit-llvm -fblocks -triple x86_64-apple-darwin -fstrict-return -O -o - %s | FileCheck %s
+
+@interface I
+@end
+
+@implementation I
+
+- (int)method {
+}
+
+@end
+
+enum Enum {
+  a
+};
+
+int (^block)(Enum) = ^int(Enum e) {
+  switch (e) {
+  case a:
+return 1;
+  }
+};
+
+// Ensure that both methods and blocks don't use the -fstrict-return undefined
+// behaviour optimization.
+
+// CHECK-NOT: call void @llvm.trap
+// CHECK-NOT: unreachable
Index: test/CodeGenCXX/return.cpp
===
--- test/CodeGenCXX/return.cpp
+++ test/CodeGenCXX/return.cpp
@@ -1,12 +1,105 @@
-// RUN: %clang_cc1 -emit-llvm -triple %itanium_abi_triple -o - %s | FileCheck %s
-// RUN: %clang_cc1 -emit-llvm -triple %itanium_abi_triple -O -o - %s | FileCheck %s --check-prefix=CHECK-OPT
+// RUN: %clang_cc1 -emit-llvm -triple %itanium_abi_triple -std=c++11 -o - %s | FileCheck --check-prefixes=CHECK,CHECK-COMMON %s
+// RUN: %clang_cc1 -emit-llvm -triple %itanium_abi_triple -std=c++11 -O -o - %s | FileCheck %s --check-prefixes=CHECK-OPT,CHECK-COMMON
+// RUN: %clang_cc1 -emit-llvm -triple %itanium_abi_triple -std=c++11 -fno-strict-return -o - %s | FileCheck %s --check-prefixes=CHECK-NOSTRICT,CHECK-COMMON
+// RUN: %clang_cc1 -emit-llvm -triple %itanium_abi_triple -std=c++11 -fno-strict-return -Wno-return-type -o - %s | FileCheck %s --check-prefixes=CHECK-NOSTRICT,CHECK-COMMON
+// RUN: %clang_cc1 -emit-llvm -triple %itanium_abi_triple -std=c++11 -fno-strict-return -O -o - %s | FileCheck %s --check-prefixes=CHECK-NOSTRICT-OPT,CHECK-COMMON
 
-// CHECK: @_Z9no_return
-// CHECK-OPT: @_Z9no_return
+// CHECK-COMMON-LABEL: @_Z9no_return
 int no_return() {
   // CHECK:  call void @llvm.trap
   // CHECK-NEXT: unreachable
 
   // CHECK-OPT-NOT: call void @llvm.trap
   // CHECK-OPT: unreachable
+
+  // -fno-strict-return should not emit trap + unreachable but it should return
+  // an undefined value instead.
+
+  // CHECK-NOSTRICT: entry:
+  // CHECK-NOSTRICT-NEXT: alloca
+  // CHECK-NOSTRICT-NEXT: load
+  // CHECK-NOSTRICT-NEXT: ret i32
+  // CHECK-NOSTRICT-NEXT: }
+
+  // CHECK-NOSTRICT-OPT: entry:
+  // CHECK-NOSTRICT-OPT: ret i32 undef
+}
+
+enum Enum {
+  A, B
+};
+
+// CHECK-COMMON-LABEL: @_Z27returnNotViableDontOptimize4Enum
+int returnNotViableDontOptimize(Enum e) {
+  switch (e) {
+  case A: return 1;
+  case B: return 2;
+  }
+  // Undefined behaviour optimization shouldn't be used when -fno-strict-return
+  // is turned on, even if all the enum cases are covered in this function.
+
+  // CHECK-NOSTRICT-NOT: call void @llvm.trap
+  // CHECK-NOSTRICT-NOT: unreachable
+}
+
+struct Trivial {
+  int x;
+};
+
+// CHECK-NOSTRICT-LABEL: @_Z7trivialv
+Trivial trivial() {
+  // This function returns a trivial record so -fno-strict-return should avoid
+  // the undefined behaviour optimization.
+
+  // CHECK-NOSTRICT-NOT: call void @llvm.trap
+  // CHECK-NOSTRICT-NOT: unreachable
+}
+
+// Functions that return non-trivial records should always use the
+// -fstrict-return optimization.
+
+struct NonTrivialCopy {
+  NonTrivialCopy(const NonTrivialCopy &);
+};
+
+// CHECK-NOSTRICT-LABEL: @_Z14nonTrivialCopyv
+NonTrivialCopy nonTrivialCopy() {
+  // CHECK-NOSTRICT: call void @llvm.trap
+  // CHECK-NOSTRICT-NEXT: unreachable
+}
+
+struct NonTrivialDestructor {
+  ~NonTrivialDestructor();
+};
+
+// CHECK-NOSTRICT-LABEL: @_Z20nonTrivialDestructorv
+NonTrivialDestructor nonTrivialDestructor() {
+  // CHECK-NOSTRIC

[PATCH] D27163: Introduce -f[no-]strict-return flag that controls code generation for C++'s undefined behaviour return optimisation

2016-12-15 Thread Alex Lorenz via Phabricator via cfe-commits
arphaman added inline comments.



Comment at: include/clang/Sema/AnalysisBasedWarnings.h:93
 
-  void IssueWarnings(Policy P, FunctionScopeInfo *fscope,
- const Decl *D, const BlockExpr *blkExpr);
+  void IssueWarnings(Policy P, FunctionScopeInfo *fscope, Decl *D,
+ const BlockExpr *blkExpr);

Quuxplusone wrote:
> If you remove the coupling between -fno-strict-return and -Wreturn-type, then 
> you won't need to remove `const` in all these places. I think that alone is a 
> good enough reason not to couple them.
That's a fair point, I've thought about it a bit more and decided to get rid of 
the "-Wreturn-type" heuristic. If anything I can try a follow-up patch later if 
we really end up needing it, but I don't think so.



Comment at: lib/CodeGen/CodeGenFunction.cpp:1078
+  QualType T = FD->getReturnType();
+  if (T.isTriviallyCopyableType(Context)) {
+// Avoid the optimization for functions that return trivially copyable

Quuxplusone wrote:
> Peanut-gallery question: Does `isTriviallyCopyableType` also check that the 
> type is trivially destructible and/or default-constructible? Do those things 
> matter?
Yes for trivially destructible, since it calls 
`CXXRecordDecl::isTriviallyCopyable()` which checks. No for trivially 
default-constructible, I fixed that. 

I think that for us it doesn't really matter that much, since we're mostly 
worried about C code compiled in C++ mode.



Comment at: lib/CodeGen/CodeGenFunction.cpp:1173
+} else if (CGM.getCodeGenOpts().StrictReturn ||
+   shouldUseUndefinedBehaviorReturnOptimization(FD, getContext())) 
{
+  if (CGM.getCodeGenOpts().OptimizationLevel == 0)

Quuxplusone wrote:
> I'd expect this to look more like
> 
> bool ShouldOmitUnreachable = !CGM.getCodeGenOpts().StrictReturn && 
> FD->getReturnType().isTriviallyCopyableType(Context);
> // same ifs as the old code
> if (!ShouldOmitUnreachable) {
> Builder.CreateUnreachable();
> Builder.ClearInsertionPoint();
> }
> 
> Or in fact, is there a good reason this codepath isn't piggybacking on 
> `FD->hasImplicitReturnZero()`?  Why not just give every function 
> `hasImplicitReturnZero` when `-fno-strict-return` is in effect?
> 
> At which point, `-fno-strict-return` might seem like the wrong name; you 
> could just call it something like `-fimplicit-return-zero`, which would also 
> have the minor benefit of making the `-fno-*` option the default.
> Or in fact, is there a good reason this codepath isn't piggybacking on 
> FD->hasImplicitReturnZero()? Why not just give every function 
> hasImplicitReturnZero when -fno-strict-return is in effect?

I understand your suggestion, but I'd prefer not to set `hasImplicitReturnZero` 
for all functions, since then Sema won't warn about the missing return, which 
we still want.

> At which point, -fno-strict-return might seem like the wrong name; you could 
> just call it something like -fimplicit-return-zero, which would also have the 
> minor benefit of making the -fno-* option the default.

I don't think a name like "-fimplicit-return-zero" is appropriate, since it 
implies that the compiler guarantees a return of a zero value. This might 
mislead users as they might think that they can use the return value without 
triggering undefined behaviour, which isn't true.



Repository:
  rL LLVM

https://reviews.llvm.org/D27163



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


[PATCH] D27806: [clang-tidy] Add misc-invalid-range

2016-12-15 Thread Malcolm Parsons via Phabricator via cfe-commits
malcolm.parsons added inline comments.



Comment at: clang-tidy/ClangTidy.cpp:296
   const auto &RegisteredCheckers =
-  AnalyzerOptions::getRegisteredCheckers(/*IncludeExperimental=*/false);
+  AnalyzerOptions::getRegisteredCheckers(/*IncludeExperimental=*/true);
   bool AnalyzerChecksEnabled = false;

Is this intentional?



Comment at: clang-tidy/misc/InvalidRangeCheck.cpp:40
+CXX_AlgorithmNames +
+"; std::all_of; std::any_of; std::none_of; std::find_if_not; "
+"std::is_permutation; std::copy_n; std::copy_if; std::move; "

Extra `;` in string here or on line 36?



Comment at: docs/ReleaseNotes.rst:84
 
+- New `misc-invalid-range
+  `_ 
check

"invalid" < "use"



Comment at: docs/clang-tidy/checks/misc-invalid-range.rst:12
+
+It checks if first and second argument of call is call to ``begin()``
+and ``end()``, but on different objects (having different name).

What about the parallel versions of algorithms?


https://reviews.llvm.org/D27806



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


[PATCH] D27767: NFC Changes from modernize-use-auto

2016-12-15 Thread Malcolm Parsons via Phabricator via cfe-commits
malcolm.parsons added inline comments.



Comment at: lib/StaticAnalyzer/Checkers/TestAfterDivZeroChecker.cpp:106
 
   if (Optional P = Succ->getLocationAs())
+if (const auto *BO = P->getStmtAs()) {

The check missed this one.


https://reviews.llvm.org/D27767



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


Re: [clang-tools-extra] r289656 - modernize-use-auto NFC fixes

2016-12-15 Thread Alexander Kornienko via cfe-commits
For most loop changes here applying modernize-loop-convert would be better
;)

On Wed, Dec 14, 2016 at 4:29 PM, Piotr Padlewski via cfe-commits <
cfe-commits@lists.llvm.org> wrote:

> Author: prazek
> Date: Wed Dec 14 09:29:23 2016
> New Revision: 289656
>
> URL: http://llvm.org/viewvc/llvm-project?rev=289656&view=rev
> Log:
> modernize-use-auto NFC fixes
>
> Modified:
> clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp
> clang-tools-extra/trunk/clang-apply-replacements/lib/
> Tooling/ApplyReplacements.cpp
> clang-tools-extra/trunk/clang-query/Query.cpp
> clang-tools-extra/trunk/clang-query/QueryParser.cpp
> clang-tools-extra/trunk/clang-query/tool/ClangQuery.cpp
> clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/
> ProTypeMemberInitCheck.cpp
> clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/
> SpecialMemberFunctionsCheck.cpp
> clang-tools-extra/trunk/clang-tidy/google/ExplicitConstructorCheck.cpp
> clang-tools-extra/trunk/clang-tidy/google/NonConstReferences.cpp
> clang-tools-extra/trunk/clang-tidy/llvm/TwineLocalCheck.cpp
> clang-tools-extra/trunk/clang-tidy/misc/ArgumentCommentCheck.cpp
> clang-tools-extra/trunk/clang-tidy/misc/MoveForwardingReferenceCheck.
> cpp
> clang-tools-extra/trunk/clang-tidy/misc/MultipleStatementMacroCheck.
> cpp
> clang-tools-extra/trunk/clang-tidy/misc/ThrowByValueCatchByReferenceCh
> eck.cpp
> clang-tools-extra/trunk/clang-tidy/modernize/UseNullptrCheck.cpp
> clang-tools-extra/trunk/clang-tidy/modernize/UseOverrideCheck.cpp
> clang-tools-extra/trunk/clang-tidy/mpi/TypeMismatchCheck.cpp
> clang-tools-extra/trunk/clang-tidy/readability/
> ImplicitBoolCastCheck.cpp
> clang-tools-extra/trunk/clang-tidy/readability/
> NamespaceCommentCheck.cpp
> clang-tools-extra/trunk/clang-tidy/readability/
> RedundantDeclarationCheck.cpp
> clang-tools-extra/trunk/clang-tidy/readability/
> RedundantSmartptrGetCheck.cpp
> clang-tools-extra/trunk/include-fixer/find-all-
> symbols/FindAllSymbols.cpp
> clang-tools-extra/trunk/modularize/CoverageChecker.cpp
> clang-tools-extra/trunk/modularize/Modularize.cpp
> clang-tools-extra/trunk/modularize/ModularizeUtilities.cpp
> clang-tools-extra/trunk/modularize/ModuleAssistant.cpp
> clang-tools-extra/trunk/modularize/PreprocessorTracker.cpp
> clang-tools-extra/trunk/pp-trace/PPTrace.cpp
> clang-tools-extra/trunk/unittests/clang-tidy/
> ClangTidyDiagnosticConsumerTest.cpp
> clang-tools-extra/trunk/unittests/clang-tidy/NamespaceAliaserTest.cpp
> clang-tools-extra/trunk/unittests/clang-tidy/UsingInserterTest.cpp
>
> Modified: clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp
> URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/
> trunk/change-namespace/ChangeNamespace.cpp?rev=289656&r1=289655&r2=289656&
> view=diff
> 
> ==
> --- clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp
> (original)
> +++ clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp Wed Dec
> 14 09:29:23 2016
> @@ -709,7 +709,7 @@ void ChangeNamespaceTool::fixTypeLoc(
>return;
>}
>
> -  const Decl *DeclCtx = Result.Nodes.getNodeAs("dc");
> +  const auto *DeclCtx = Result.Nodes.getNodeAs("dc");
>assert(DeclCtx && "Empty decl context.");
>replaceQualifiedSymbolInDeclContext(Result, DeclCtx->getDeclContext(),
> Start,
>End, FromDecl);
>
> Modified: clang-tools-extra/trunk/clang-apply-replacements/lib/
> Tooling/ApplyReplacements.cpp
> URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/
> trunk/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp?rev=
> 289656&r1=289655&r2=289656&view=diff
> 
> ==
> --- 
> clang-tools-extra/trunk/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp
> (original)
> +++ 
> clang-tools-extra/trunk/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp
> Wed Dec 14 09:29:23 2016
> @@ -124,9 +124,7 @@ static void reportConflict(
>  bool applyAllReplacements(const std::vector
> &Replaces,
>Rewriter &Rewrite) {
>bool Result = true;
> -  for (std::vector::const_iterator I =
> Replaces.begin(),
> - E =
> Replaces.end();
> -   I != E; ++I) {
> +  for (auto I = Replaces.begin(), E = Replaces.end(); I != E; ++I) {
>  if (I->isApplicable()) {
>Result = I->apply(Rewrite) && Result;
>  } else {
> @@ -293,8 +291,7 @@ RangeVector calculateChangedRanges(
>
>  bool writeFiles(const clang::Rewriter &Rewrites) {
>
> -  for (Rewriter::const_buffer_iterator BufferI = Rewrites.buffer_begin(),
> -   BufferE = Rewrites.buffer_end();
> +  for (auto BufferI = Rewrites.buffer_begin(), BufferE =
> Rewrites.buffer_end();
> BufferI != Bu

[PATCH] D27812: [test] Extend llvm_shlib_dir fix to unittests

2016-12-15 Thread Michał Górny via Phabricator via cfe-commits
mgorny created this revision.
mgorny added reviewers: chapuni, gribozavr, ddunbar, beanz.
mgorny added a subscriber: cfe-commits.

Extend the fix from https://reviews.llvm.org/rL286952 to unittests. The fix 
added clang built
library directories (via llvm_shlib_dir) to LD_LIBRARY_PATH.
The previous logic has used llvm_libs_dir only which points to installed
LLVM when doing stand-alone builds.

The patch also removes the redundant win32 code that is no longer
necessary now that shlibdir is used unconditionally.


https://reviews.llvm.org/D27812

Files:
  test/Unit/lit.cfg


Index: test/Unit/lit.cfg
===
--- test/Unit/lit.cfg
+++ test/Unit/lit.cfg
@@ -94,15 +94,16 @@
 elif platform.system() == 'Windows':
 shlibpath_var = 'PATH'
 
+# in stand-alone builds, shlibdir is clang's build tree
+# while llvm_libs_dir is installed LLVM (and possibly older clang)
+llvm_shlib_dir = getattr(config, 'shlibdir', None)
+if not llvm_shlib_dir:
+lit_config.fatal('No shlibdir set!')
 # Point the dynamic loader at dynamic libraries in 'lib'.
 llvm_libs_dir = getattr(config, 'llvm_libs_dir', None)
 if not llvm_libs_dir:
 lit_config.fatal('No LLVM libs dir set!')
-shlibpath = os.path.pathsep.join((llvm_libs_dir,
+shlibpath = os.path.pathsep.join((llvm_shlib_dir, llvm_libs_dir,
  config.environment.get(shlibpath_var,'')))
 
-# Win32 seeks DLLs along %PATH%.
-if sys.platform in ['win32', 'cygwin'] and os.path.isdir(config.shlibdir):
-shlibpath = os.path.pathsep.join((config.shlibdir, shlibpath))
-
 config.environment[shlibpath_var] = shlibpath


Index: test/Unit/lit.cfg
===
--- test/Unit/lit.cfg
+++ test/Unit/lit.cfg
@@ -94,15 +94,16 @@
 elif platform.system() == 'Windows':
 shlibpath_var = 'PATH'
 
+# in stand-alone builds, shlibdir is clang's build tree
+# while llvm_libs_dir is installed LLVM (and possibly older clang)
+llvm_shlib_dir = getattr(config, 'shlibdir', None)
+if not llvm_shlib_dir:
+lit_config.fatal('No shlibdir set!')
 # Point the dynamic loader at dynamic libraries in 'lib'.
 llvm_libs_dir = getattr(config, 'llvm_libs_dir', None)
 if not llvm_libs_dir:
 lit_config.fatal('No LLVM libs dir set!')
-shlibpath = os.path.pathsep.join((llvm_libs_dir,
+shlibpath = os.path.pathsep.join((llvm_shlib_dir, llvm_libs_dir,
  config.environment.get(shlibpath_var,'')))
 
-# Win32 seeks DLLs along %PATH%.
-if sys.platform in ['win32', 'cygwin'] and os.path.isdir(config.shlibdir):
-shlibpath = os.path.pathsep.join((config.shlibdir, shlibpath))
-
 config.environment[shlibpath_var] = shlibpath
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D27673: [clang-move] Only move used helper declarations.

2016-12-15 Thread Eric Liu via Phabricator via cfe-commits
ioeric added inline comments.



Comment at: clang-move/UsedHelperDeclFinder.cpp:22
+// by a single node which belongs to that class.
+const Decl *getOutmostEnclosingClassOrFunDecl(const Decl *D) {
+  const auto *DC = D->getDeclContext();

Maybe just `getOutermostDecls` and add FIXME for other data types.



Comment at: clang-move/UsedHelperDeclFinder.cpp:30
+  Result = FD;
+  if (const auto *RD = dyn_cast(FD->getParent()))
+Result = RD;

Why do you need this? And when is a function's parent a class?



Comment at: clang-move/UsedHelperDeclFinder.cpp:103
+
+UsedHelperDeclFinder::HelperDeclsSet UsedHelperDeclFinder::getUsedHelperDecls(
+const std::vector &Decls) const {

Do you assume that all nodes/decls in the graph are helpers?

What if some moved `Decl` refers to unmoved decls?



Comment at: clang-move/UsedHelperDeclFinder.cpp:125
+const ast_matchers::MatchFinder::MatchResult &Result) {
+  if (const clang::DeclRefExpr *FR =
+  Result.Nodes.getNodeAs("func_ref")) {

I find abbreviations hurt readability in general. Maybe just `FuncRef`.



Comment at: clang-move/UsedHelperDeclFinder.cpp:128
+const auto *DC = Result.Nodes.getNodeAs("dc");
+if (!DC)
+  return;

When would `DC` be null? Shouldn't we assert this instead of ignoring?



Comment at: clang-move/UsedHelperDeclFinder.cpp:132
+// definition.
+const auto *T = DC->getPreviousDecl();
+if (!T)

Shouldn't we use `getCanonicalDecl` instead so that we can always get the same 
Decl for all canonical declaration?

And if you are doing this when adding nodes, shouldn't you also do 
`getPreviousDecl` or `getCanonicalDecl` for `getNode` and `getOrInsertNode` etc?



Comment at: clang-move/UsedHelperDeclFinder.cpp:145
+// whose outmost enclosing declaration is the "CLASS" CXXRecord 
Declaration.
+if (T == D)
+  return;

I'd move this check into `addNodeForDecl`.



Comment at: clang-move/UsedHelperDeclFinder.h:59
+  // Add a directed edge from the caller node to the callee node.
+  // A new node will be created if the node for Caller/Callee isn't existed.
+  //

s/isn't existed/doesn't exist/



Comment at: clang-move/UsedHelperDeclFinder.h:61
+  //
+  // Note that, all methods/variables declarations of a class are represented 
by
+  // a single node in the graph. The corresponding Decl of this node is the

maybe just "all members"?



Comment at: clang-move/UsedHelperDeclFinder.h:64
+  // class declaration.
+  void addNodeForDecl(const Decl *Caller, const Decl *Callee);
+  CallGraphNode *getNode(const Decl *D) const;

So, this is not adding node?



Comment at: clang-move/UsedHelperDeclFinder.h:107
+  HelperDeclsSet
+  getUsedHelperDecls(const std::vector &Decls) const;
+

Maybe add `FIXME` somewhere in the code for other kinds of declarations.



Comment at: clang-move/UsedHelperDeclFinder.h:110
+  // Check whether the given declaration D is in the HelperDeclsSet.
+  static bool isUsed(const Decl *D, const HelperDeclsSet &UsedDecls);
+

This function is quite confusing for me. The comment indicates that this checks 
if `D` is in `UsedDecls`?  But the implementation does more than that. I think 
we need a better name and comment for this.


https://reviews.llvm.org/D27673



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


r289829 - CodeGen: ubsan is built static on windows, give handlers local storage

2016-12-15 Thread Saleem Abdulrasool via cfe-commits
Author: compnerd
Date: Thu Dec 15 10:30:20 2016
New Revision: 289829

URL: http://llvm.org/viewvc/llvm-project?rev=289829&view=rev
Log:
CodeGen: ubsan is built static on windows, give handlers local storage

The UBSAN runtime is built static on Windows.  This requires that we give local
storage always.  This impacts Windows where the linker would otherwise have to
generate a thunk to access the symbol via the IAT.  This should repair the
windows clang build bots.

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

Modified: cfe/trunk/lib/CodeGen/CGExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGExpr.cpp?rev=289829&r1=289828&r2=289829&view=diff
==
--- cfe/trunk/lib/CodeGen/CGExpr.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGExpr.cpp Thu Dec 15 10:30:20 2016
@@ -2545,7 +2545,8 @@ static void emitCheckHandlerCall(CodeGen
   llvm::Value *Fn = CGF.CGM.CreateRuntimeFunction(
   FnType, FnName,
   llvm::AttributeSet::get(CGF.getLLVMContext(),
-  llvm::AttributeSet::FunctionIndex, B));
+  llvm::AttributeSet::FunctionIndex, B),
+  /*Local=*/true);
   llvm::CallInst *HandlerCall = CGF.EmitNounwindRuntimeCall(Fn, FnArgs);
   if (!MayReturn) {
 HandlerCall->setDoesNotReturn();


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


[PATCH] D27621: [clang-tidy] check to find declarations declaring more than one name

2016-12-15 Thread Firat Kasmis via Phabricator via cfe-commits
firolino updated this revision to Diff 81591.
firolino added a comment.

- small improvements
- re-added lost handling for:

  bool defPre = false,
  #ifdef IS_ENABLED
 defTest = false;
  #else
 defTest = true;
  #endif

- added support for new test cases:

  int /* :: */ S::*pp2 = &S::a, var1 = 0;
  void /*(*/ ( /*(*/ *f3)(int), (*g3)(int, float);
  /* *& */ int /* *& */ ** /* *& */ pp,*xx;


https://reviews.llvm.org/D27621

Files:
  clang-tidy/readability/CMakeLists.txt
  clang-tidy/readability/OneNamePerDeclarationCheck.cpp
  clang-tidy/readability/OneNamePerDeclarationCheck.h
  clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tidy/utils/LexerUtils.cpp
  clang-tidy/utils/LexerUtils.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/readability-one-name-per-declaration.rst
  test/clang-tidy/readability-one-name-per-declaration-complex.cpp
  test/clang-tidy/readability-one-name-per-declaration-modern.cpp
  test/clang-tidy/readability-one-name-per-declaration-simple.cpp

Index: test/clang-tidy/readability-one-name-per-declaration-simple.cpp
===
--- /dev/null
+++ test/clang-tidy/readability-one-name-per-declaration-simple.cpp
@@ -0,0 +1,137 @@
+// RUN: %check_clang_tidy %s readability-one-name-per-declaration %t
+
+int cantTouchA, cantTouchB;
+
+void simple() 
+{
+int dontTouchC;
+
+long empty;
+long long1 = 11, *long2 = &empty, * long3 = ∅
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: declaration statement can be split up into single line declarations [readability-one-name-per-declaration]
+// CHECK-FIXES: {{^}}long long1 = 11;
+// CHECK-FIXES: {{^}}long *long2 = ∅
+// CHECK-FIXES: {{^}}long * long3 = ∅
+
+long ** lint1, lint2 = 0, * lint3, **linn;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: declaration statement can be split up into single line declarations [readability-one-name-per-declaration]
+// CHECK-FIXES: {{^}}long ** lint1;
+// CHECK-FIXES: {{^}}long lint2 = 0;
+// CHECK-FIXES: {{^}}long * lint3;
+// CHECK-FIXES: {{^}}long **linn;
+
+	long int* lint4, *lint5,  lint6;
+	// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: declaration statement can be split up into single line declarations [readability-one-name-per-declaration]
+	// CHECK-FIXES: {{^	}}long int* lint4;
+	// CHECK-FIXES: {{^	}}long int *lint5;
+	// CHECK-FIXES: {{^	}}long int lint6;
+
+/* *& */ int /* *& */ ** /* *& */ pp,*xx;
+// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: declaration statement can be split up into single line declarations [readability-one-name-per-declaration]
+// CHECK-FIXES: {{^}}/* *& */ int /* *& */ ** /* *& */ pp;
+// CHECK-FIXES: {{^}}int *xx;
+
+unsigned int uint1 = 0,uint2 = 44u, uint3, uint4=4;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: declaration statement can be split up into single line declarations [readability-one-name-per-declaration]
+// CHECK-FIXES: {{^}}unsigned int uint1 = 0;
+// CHECK-FIXES: {{^}}unsigned int uint2 = 44u;
+// CHECK-FIXES: {{^}}unsigned int uint3;
+// CHECK-FIXES: {{^}}unsigned int uint4=4;
+
+double darray1[] = {}, darray2[] = {1,	2},dv1 = 3,dv2;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: declaration statement can be split up into single line declarations [readability-one-name-per-declaration]
+// CHECK-FIXES: {{^}}double darray1[] = {};
+// CHECK-FIXES: {{^}}double darray2[] = {1,	2};
+// CHECK-FIXES: {{^}}double dv1 = 3;
+// CHECK-FIXES: {{^}}double dv2;
+
+int notransform[] =   {
+  1,
+  2
+  };
+
+const int cx = 1, cy = 2;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: declaration statement can be split up into single line declarations [readability-one-name-per-declaration]
+// CHECK-FIXES: {{^}}const int cx = 1;
+// CHECK-FIXES: {{^}}const int cy = 2;
+
+volatile int vx, vy;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: declaration statement can be split up into single line declarations [readability-one-name-per-declaration]
+// CHECK-FIXES: {{^}}volatile int vx;
+// CHECK-FIXES: {{^}}volatile int vy;
+
+signed char sc1 = 'h', sc2;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: declaration statement can be split up into single line declarations [readability-one-name-per-declaration]
+// CHECK-FIXES: {{^}}signed char sc1 = 'h';
+// CHECK-FIXES: {{^}}signed char sc2;
+
+long long ll1, ll2, ***ft;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: declaration statement can be split up into single line declarations [readability-one-name-per-declaration]
+// CHECK-FIXES: {{^}}long long ll1;
+// CHECK-FIXES: {{^}}long long ll2;
+// CHECK-FIX

[PATCH] D27621: [clang-tidy] check to find declarations declaring more than one name

2016-12-15 Thread Firat Kasmis via Phabricator via cfe-commits
firolino added a comment.

Unfortunately, I am not able to make getUserWrittenType easier right now. 
TypeLoc does not give me the desired range. See also:

- http://lists.llvm.org/pipermail/cfe-dev/2013-March/028467.html
- http://lists.llvm.org/pipermail/cfe-dev/2010-April/008664.html
- https://reviews.llvm.org/D27621#619756


https://reviews.llvm.org/D27621



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


[PATCH] D27813: [clang-tidy] fix missing anchor for MPI Module

2016-12-15 Thread Piotr Padlewski via Phabricator via cfe-commits
Prazek created this revision.
Prazek added reviewers: alexfh, Alexander_Droste, hokein.
Prazek added a subscriber: cfe-commits.
Herald added a subscriber: JDevlieghere.

MPIModule was not linked to plugins


https://reviews.llvm.org/D27813

Files:
  clang-tidy/plugin/ClangTidyPlugin.cpp


Index: clang-tidy/plugin/ClangTidyPlugin.cpp
===
--- clang-tidy/plugin/ClangTidyPlugin.cpp
+++ clang-tidy/plugin/ClangTidyPlugin.cpp
@@ -108,6 +108,11 @@
 static int LLVM_ATTRIBUTE_UNUSED ModernizeModuleAnchorDestination =
 ModernizeModuleAnchorSource;
 
+// This anchor is used to force the linker to link the MPIModule.
+extern volatile int MPIModuleAnchorSource;
+static int LLVM_ATTRIBUTE_UNUSED MPIModuleAnchorDestination =
+  MPIModuleAnchorSource;
+
 // This anchor is used to force the linker to link the PerformanceModule.
 extern volatile int PerformanceModuleAnchorSource;
 static int LLVM_ATTRIBUTE_UNUSED PerformanceModuleAnchorDestination =


Index: clang-tidy/plugin/ClangTidyPlugin.cpp
===
--- clang-tidy/plugin/ClangTidyPlugin.cpp
+++ clang-tidy/plugin/ClangTidyPlugin.cpp
@@ -108,6 +108,11 @@
 static int LLVM_ATTRIBUTE_UNUSED ModernizeModuleAnchorDestination =
 ModernizeModuleAnchorSource;
 
+// This anchor is used to force the linker to link the MPIModule.
+extern volatile int MPIModuleAnchorSource;
+static int LLVM_ATTRIBUTE_UNUSED MPIModuleAnchorDestination =
+  MPIModuleAnchorSource;
+
 // This anchor is used to force the linker to link the PerformanceModule.
 extern volatile int PerformanceModuleAnchorSource;
 static int LLVM_ATTRIBUTE_UNUSED PerformanceModuleAnchorDestination =
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D24084: [CMake] Cleanup libunwind lookup code.

2016-12-15 Thread Logan Chien via Phabricator via cfe-commits
logan added a comment.

Hi @rengolin:

Yeah.  It is a kind of similar.  Another route is to move the code from 
`/include/unwind.h` to `/lib/Headers` and then ship a shim 
layer with `libc++abi` and/or `libunwind` for old clang.


https://reviews.llvm.org/D24084



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


[PATCH] D24083: [CMake] Fix libc++abi __aeabi_idiv() link error.

2016-12-15 Thread Logan Chien via Phabricator via cfe-commits
logan added a comment.

Sorry, I don't have time to work on this recently.  Here's the plan:

1. Add another flag to specify the path to `libclang_rt-builtin.a`.

2. If that flag was not specified and the compiler is `clang`, then run `clang 
-###` to extract for `-L` option and `-l` option for `libclang_rt-builtin.a`.

3. If neither (1) nor (2) are available, then report an error.

I hope I can get back to this next week.


https://reviews.llvm.org/D24083



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


[PATCH] D24487: [Clang] Fix some Clang-tidy modernize-use-bool-literals and Include What You Use warnings in AST; other minor fixes

2016-12-15 Thread Piotr Padlewski via Phabricator via cfe-commits
Prazek added inline comments.



Comment at: lib/ASTMatchers/Dynamic/Parser.cpp:617
 
-}  // namespace dynamic
-}  // namespace ast_matchers
-}  // namespace clang
+} // end namespace dynamic
+} // end namespace ast_matchers

I think check should not warn in these cases.


Repository:
  rL LLVM

https://reviews.llvm.org/D24487



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


[PATCH] D27767: NFC Changes from modernize-use-auto

2016-12-15 Thread Piotr Padlewski via Phabricator via cfe-commits
Prazek added inline comments.



Comment at: lib/StaticAnalyzer/Checkers/TestAfterDivZeroChecker.cpp:106
 
   if (Optional P = Succ->getLocationAs())
+if (const auto *BO = P->getStmtAs()) {

malcolm.parsons wrote:
> The check missed this one.
I don't think it is miss if getLocationAs returns Optional, because that 
would suggest that it returns T


https://reviews.llvm.org/D27767



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


[PATCH] D27180: Testbed and skeleton of a new expression parser

2016-12-15 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev added a comment.

Could you move the Build* functions in a utility class/namespace. I need 
something very similar for my ongoing work on the libInterpreter patch and I'd 
like to reuse that part of the patch.


Repository:
  rL LLVM

https://reviews.llvm.org/D27180



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


[PATCH] D27806: [clang-tidy] Add misc-invalid-range

2016-12-15 Thread Piotr Padlewski via Phabricator via cfe-commits
Prazek marked an inline comment as done.
Prazek added inline comments.



Comment at: clang-tidy/ClangTidy.cpp:296
   const auto &RegisteredCheckers =
-  AnalyzerOptions::getRegisteredCheckers(/*IncludeExperimental=*/false);
+  AnalyzerOptions::getRegisteredCheckers(/*IncludeExperimental=*/true);
   bool AnalyzerChecksEnabled = false;

malcolm.parsons wrote:
> Is this intentional?
actually not, good catch. I was testing alpha checks



Comment at: docs/clang-tidy/checks/misc-invalid-range.rst:12
+
+It checks if first and second argument of call is call to ``begin()``
+and ``end()``, but on different objects (having different name).

malcolm.parsons wrote:
> What about the parallel versions of algorithms?
parallel version won't take iterator as first argument, so it won't gonna match.
I don't think it makes sense to support parallel algorithms now because they 
don't have that many users yet.


https://reviews.llvm.org/D27806



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


[PATCH] D27815: [clang-tidy] Add obvious module for obvious bugs

2016-12-15 Thread Piotr Padlewski via Phabricator via cfe-commits
Prazek created this revision.
Prazek added reviewers: alexfh, malcolm.parsons.
Prazek added a subscriber: cfe-commits.
Herald added subscribers: JDevlieghere, mgorny.

Module for checks for obvious bugs that probably won't be found
in working code, but can be found while looking for an
obvious bug in broken code.


https://reviews.llvm.org/D27815

Files:
  clang-tidy/CMakeLists.txt
  clang-tidy/obvious/CMakeLists.txt
  clang-tidy/obvious/ObviousTidyModule.cpp
  clang-tidy/plugin/CMakeLists.txt
  clang-tidy/plugin/ClangTidyPlugin.cpp
  clang-tidy/tool/CMakeLists.txt
  clang-tidy/tool/ClangTidyMain.cpp
  docs/clang-tidy/index.rst

Index: docs/clang-tidy/index.rst
===
--- docs/clang-tidy/index.rst
+++ docs/clang-tidy/index.rst
@@ -65,6 +65,9 @@
 ``modernize-`` Checks that advocate usage of modern (currently "modern"
means "C++11") language constructs.
 ``mpi-``   Checks related to MPI (Message Passing Interface).
+``obvious-``   Checks for obvious bugs that probably won't be found
+   in working code, but can be found while looking for an
+   obvious bug in broken code.
 ``performance-``   Checks that target performance-related issues.
 ``readability-``   Checks that target readability-related issues that don't
relate to any particular coding style.
Index: clang-tidy/tool/ClangTidyMain.cpp
===
--- clang-tidy/tool/ClangTidyMain.cpp
+++ clang-tidy/tool/ClangTidyMain.cpp
@@ -465,6 +465,11 @@
 static int LLVM_ATTRIBUTE_UNUSED MPIModuleAnchorDestination =
 MPIModuleAnchorSource;
 
+// This anchor is used to force the linker to link the ObviousModule.
+extern volatile int ObviousModuleAnchorSource;
+static int LLVM_ATTRIBUTE_UNUSED ObviousModuleAnchorDestination =
+  ObviousModuleAnchorSource;
+
 // This anchor is used to force the linker to link the PerformanceModule.
 extern volatile int PerformanceModuleAnchorSource;
 static int LLVM_ATTRIBUTE_UNUSED PerformanceModuleAnchorDestination =
Index: clang-tidy/tool/CMakeLists.txt
===
--- clang-tidy/tool/CMakeLists.txt
+++ clang-tidy/tool/CMakeLists.txt
@@ -21,6 +21,7 @@
   clangTidyMiscModule
   clangTidyModernizeModule
   clangTidyMPIModule
+  clangTidyObviousModule
   clangTidyPerformanceModule
   clangTidyReadabilityModule
   clangTooling
Index: clang-tidy/plugin/ClangTidyPlugin.cpp
===
--- clang-tidy/plugin/ClangTidyPlugin.cpp
+++ clang-tidy/plugin/ClangTidyPlugin.cpp
@@ -108,6 +108,11 @@
 static int LLVM_ATTRIBUTE_UNUSED ModernizeModuleAnchorDestination =
 ModernizeModuleAnchorSource;
 
+// This anchor is used to force the linker to link the ObviousModule.
+extern volatile int ObviousModuleAnchorSource;
+static int LLVM_ATTRIBUTE_UNUSED ObviousModuleAnchorDestination =
+ObviousModuleAnchorSource;
+
 // This anchor is used to force the linker to link the PerformanceModule.
 extern volatile int PerformanceModuleAnchorSource;
 static int LLVM_ATTRIBUTE_UNUSED PerformanceModuleAnchorDestination =
Index: clang-tidy/plugin/CMakeLists.txt
===
--- clang-tidy/plugin/CMakeLists.txt
+++ clang-tidy/plugin/CMakeLists.txt
@@ -15,6 +15,7 @@
   clangTidyLLVMModule
   clangTidyMiscModule
   clangTidyModernizeModule
+  clangTidyObviousModule
   clangTidyMPIModule
   clangTidyPerformanceModule
   clangTidyReadabilityModule
Index: clang-tidy/obvious/ObviousTidyModule.cpp
===
--- /dev/null
+++ clang-tidy/obvious/ObviousTidyModule.cpp
@@ -0,0 +1,38 @@
+//===--- ObviousTidyModule.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 "../ClangTidy.h"
+#include "../ClangTidyModule.h"
+#include "../ClangTidyModuleRegistry.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang {
+namespace tidy {
+namespace obvious {
+
+class ObviousModule : public ClangTidyModule {
+public:
+  void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
+// Add obvious checks here.
+  }
+};
+
+// Register the ObviousModule using this statically initialized variable.
+static ClangTidyModuleRegistry::Add X("obvious-module",
+ "Add obvious checks.");
+
+} // namespace obvious
+
+// This anchor is used to force the linker to link in the generated object file
+// and thus register the ObviousModule.
+volatile int ObviousModuleAnchorSource = 0;
+
+} //

[PATCH] D27806: [clang-tidy] Add misc-invalid-range

2016-12-15 Thread Piotr Padlewski via Phabricator via cfe-commits
Prazek updated this revision to Diff 81597.
Prazek added a comment.

- Moved to obvious


https://reviews.llvm.org/D27806

Files:
  clang-tidy/ClangTidy.cpp
  clang-tidy/obvious/CMakeLists.txt
  clang-tidy/obvious/InvalidRangeCheck.cpp
  clang-tidy/obvious/InvalidRangeCheck.h
  clang-tidy/obvious/ObviousTidyModule.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/misc-invalid-range.rst
  test/clang-tidy/misc-invalid-range.cpp

Index: test/clang-tidy/misc-invalid-range.cpp
===
--- /dev/null
+++ test/clang-tidy/misc-invalid-range.cpp
@@ -0,0 +1,47 @@
+// RUN: %check_clang_tidy %s misc-invalid-range %t
+
+namespace std {
+
+template 
+OutputIterator copy(InputIterator first, InputIterator last, OutputIterator result) {
+  return result;
+}
+
+template 
+OutputIterator move(InputIterator first, InputIterator last, OutputIterator result) {
+  return result;
+}
+
+template 
+T move(T &&) { return T(); }
+
+template 
+void fill(InputIterator first, InputIterator last, const Val &v) {
+}
+
+template 
+class vector {
+public:
+  T *begin();
+  T *end();
+};
+}
+
+void test_copy() {
+  std::vector v, v2;
+  std::copy(v.begin(), v2.end(), v2.begin());
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: call to algorithm with begin and end from different objects [misc-invalid-range]
+
+  std::copy(v.begin(), v.end(), v2.begin());
+}
+
+void test_move() {
+  std::vector v;
+  auto &v2 = v;
+  std::move(v.begin(), v2.end(), v2.begin());
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: call to algorithm with begin and end from different objects [misc-invalid-range]
+
+  std::move(v.begin(), v.end(), v2.begin());
+  std::move(v.begin());
+  test_copy();
+}
Index: docs/clang-tidy/checks/misc-invalid-range.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/misc-invalid-range.rst
@@ -0,0 +1,17 @@
+.. title:: clang-tidy - misc-invalid-range
+
+misc-invalid-range
+==
+
+This check finds invalid calls to algorithms with obviously invalid range of
+iterators like:
+
+.. code-block:: c++
+std::fill(v.begin(), v2.end(), it);
+
+It checks if first and second argument of call is call to ``begin()``
+and ``end()``, but on different objects (having different name).
+
+By default it looks for all algorithms from . This can be
+changed by using ``AlgorithmNames`` option, where empty list means that any
+function name will be accepted.
\ No newline at end of file
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -65,6 +65,7 @@
misc-inaccurate-erase
misc-incorrect-roundings
misc-inefficient-algorithm
+   misc-invalid-range
misc-macro-parentheses
misc-macro-repeated-side-effects
misc-misplaced-const
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -81,6 +81,12 @@
   Warns if an object is used after it has been moved, without an intervening
   reinitialization.
 
+- New `misc-invalid-range
+  `_ check
+
+  Warns if algorithm is used with ``.begin()`` and ``.end()`` from different
+  variables.
+
 - `modernize-make-unique
   `_
   and `modernize-make-shared
Index: clang-tidy/obvious/ObviousTidyModule.cpp
===
--- clang-tidy/obvious/ObviousTidyModule.cpp
+++ clang-tidy/obvious/ObviousTidyModule.cpp
@@ -11,6 +11,7 @@
 #include "../ClangTidyModule.h"
 #include "../ClangTidyModuleRegistry.h"
 
+#include "InvalidRangeCheck.h"
 using namespace clang::ast_matchers;
 
 namespace clang {
@@ -20,7 +21,7 @@
 class ObviousModule : public ClangTidyModule {
 public:
   void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
-// Add obvious checks here.
+CheckFactories.registerCheck("misc-invalid-range");
   }
 };
 
Index: clang-tidy/obvious/InvalidRangeCheck.h
===
--- /dev/null
+++ clang-tidy/obvious/InvalidRangeCheck.h
@@ -0,0 +1,40 @@
+//===--- InvalidRangeCheck.h - clang-tidy*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_OBVIOUS_INVALID_RANGE_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_OBVIOUS_INVALID_RANGE_H
+
+#include "../ClangTidy.h"
+#include 
+#include 
+
+namespace clang {
+namespace tidy {
+namespace obvious {
+
+/// F

[PATCH] D27800: Add overload of TransformToPotentiallyEvaluated for TypeSourceInfo

2016-12-15 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak added a comment.

Can you add a test case?


https://reviews.llvm.org/D27800



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


[PATCH] D25475: [analyzer] Add a new SVal to support pointer-to-member operations.

2016-12-15 Thread Kirill Romanenkov via Phabricator via cfe-commits
kromanenkov updated this revision to Diff 81598.
kromanenkov added a comment.

Fix issues pointed by @dcoughlin and rebase patch on master.


https://reviews.llvm.org/D25475

Files:
  include/clang/StaticAnalyzer/Core/PathSensitive/BasicValueFactory.h
  include/clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h
  include/clang/StaticAnalyzer/Core/PathSensitive/SValBuilder.h
  include/clang/StaticAnalyzer/Core/PathSensitive/SVals.def
  include/clang/StaticAnalyzer/Core/PathSensitive/SVals.h
  lib/StaticAnalyzer/Core/BasicValueFactory.cpp
  lib/StaticAnalyzer/Core/ExprEngineC.cpp
  lib/StaticAnalyzer/Core/SValBuilder.cpp
  lib/StaticAnalyzer/Core/SVals.cpp
  lib/StaticAnalyzer/Core/SimpleConstraintManager.cpp
  lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
  test/Analysis/pointer-to-member.cpp

Index: test/Analysis/pointer-to-member.cpp
===
--- test/Analysis/pointer-to-member.cpp
+++ test/Analysis/pointer-to-member.cpp
@@ -35,8 +35,7 @@
   clang_analyzer_eval(&A::getPtr == &A::getPtr); // expected-warning{{TRUE}}
   clang_analyzer_eval(&A::getPtr == 0); // expected-warning{{FALSE}}
 
-  // FIXME: Should be TRUE.
-  clang_analyzer_eval(&A::m_ptr == &A::m_ptr); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(&A::m_ptr == &A::m_ptr); // expected-warning{{TRUE}}
 }
 
 namespace PR15742 {
@@ -62,21 +61,156 @@
   }
 }
 
-// ---
-// FALSE NEGATIVES
-// ---
-
 bool testDereferencing() {
   A obj;
   obj.m_ptr = 0;
 
   A::MemberPointer member = &A::m_ptr;
 
-  // FIXME: Should be TRUE.
-  clang_analyzer_eval(obj.*member == 0); // expected-warning{{UNKNOWN}}
+  clang_analyzer_eval(obj.*member == 0); // expected-warning{{TRUE}}
 
   member = 0;
 
-  // FIXME: Should emit a null dereference.
-  return obj.*member; // no-warning
+  return obj.*member; // expected-warning{{The result of the '.*' expression is undefined}}
+}
+
+namespace testPointerToMemberFunction {
+  struct A {
+virtual int foo() { return 1; }
+int bar() { return 2;  }
+  };
+
+  struct B : public A {
+virtual int foo() { return 3; }
+  };
+
+  typedef int (A::*AFnPointer)();
+  typedef int (B::*BFnPointer)();
+
+  void testPointerToMemberCasts() {
+AFnPointer AFP = &A::bar;
+BFnPointer StaticCastedBase2Derived = static_cast(&A::bar),
+   CCastedBase2Derived = (BFnPointer) (&A::bar);
+A a;
+B b;
+
+clang_analyzer_eval((a.*AFP)() == 2); // expected-warning{{TRUE}}
+clang_analyzer_eval((b.*StaticCastedBase2Derived)() == 2); // expected-warning{{TRUE}}
+clang_analyzer_eval(((b.*CCastedBase2Derived)() == 2)); // expected-warning{{TRUE}}
+  }
+
+  void testPointerToMemberVirtualCall() {
+A a;
+B b;
+A *APtr = &a;
+AFnPointer AFP = &A::foo;
+
+clang_analyzer_eval((APtr->*AFP)() == 1); // expected-warning{{TRUE}}
+
+APtr = &b;
+
+clang_analyzer_eval((APtr->*AFP)() == 3); // expected-warning{{TRUE}}
+  }
+} // end of testPointerToMemberFunction namespace
+
+namespace testPointerToMemberData {
+  struct A {
+int i;
+  };
+
+  void testPointerToMemberData() {
+int A::*AMdPointer = &A::i;
+A a;
+
+a.i = 42;
+a.*AMdPointer += 1;
+
+clang_analyzer_eval(a.i == 43); // expected-warning{{TRUE}}
+  }
+} // end of testPointerToMemberData namespace
+
+namespace testPointerToMemberMiscCasts {
+struct B {
+  int f;
+};
+
+struct D : public B {
+  int g;
+};
+
+void foo() {
+  D d;
+  d.f = 7;
+
+  int B::* pfb = &B::f;
+  int D::* pfd = pfb;
+  int v = d.*pfd;
+
+  clang_analyzer_eval(v == 7); // expected-warning{{TRUE}}
+}
+} // end of testPointerToMemberMiscCasts namespace
+
+namespace testPointerToMemberMiscCasts2 {
+struct B {
+  int f;
+};
+struct L : public B { };
+struct R : public B { };
+struct D : public L, R { };
+
+void foo() {
+  D d;
+
+  int B::* pb = &B::f;
+  int L::* pl = pb;
+  int R::* pr = pb;
+
+  int D::* pdl = pl;
+  int D::* pdr = pr;
+
+  clang_analyzer_eval(pdl == pdr); // expected-warning{{FALSE}}
+  clang_analyzer_eval(pb == pl); // expected-warning{{TRUE}}
+}
+} // end of testPointerToMemberMiscCasts2 namespace
+
+namespace testPointerToMemberDiamond {
+struct B {
+  int f;
+};
+struct L1 : public B { };
+struct R1 : public B { };
+struct M : public L1, R1 { };
+struct L2 : public M { };
+struct R2 : public M { };
+struct D2 : public L2, R2 { };
+
+void diamond() {
+  M m;
+
+  static_cast(&m)->f = 7;
+  static_cast(&m)->f = 16;
+
+  int L1::* pl1 = &B::f;
+  int M::* pm_via_l1 = pl1;
+
+  int R1::* pr1 = &B::f;
+  int M::* pm_via_r1 = pr1;
+
+  clang_analyzer_eval(m.*(pm_via_l1) == 7); // expected-warning {{TRUE}}
+  clang_analyzer_eval(m.*(pm_via_r1) == 16); // expected-warning {{TRUE}}
+}
+
+void double_diamond() {
+  D2 d2;
+
+  static_cast(static_cast(&d2))->f = 1;
+  static_cast(static_cast(&d2))->f = 2;
+  static_cast(static_cast(&d2))->f = 3;
+  static_cast(static_cast(&d2))->f = 4;
+
+  clang_analyzer_eval(d2.*(static_cast(static_cast(sta

[PATCH] D27806: [clang-tidy] Add misc-invalid-range

2016-12-15 Thread Piotr Padlewski via Phabricator via cfe-commits
Prazek marked 2 inline comments as done.
Prazek added inline comments.



Comment at: docs/ReleaseNotes.rst:84
 
+- New `misc-invalid-range
+  `_ 
check

malcolm.parsons wrote:
> "invalid" < "use"
You mean to change "invalid" to "use"?
It is not about using range, it is about finding broken range.


https://reviews.llvm.org/D27806



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


[PATCH] D27806: [clang-tidy] Add misc-invalid-range

2016-12-15 Thread Piotr Padlewski via Phabricator via cfe-commits
Prazek updated this revision to Diff 81600.
Prazek added a comment.

- Small fixes


https://reviews.llvm.org/D27806

Files:
  clang-tidy/obvious/CMakeLists.txt
  clang-tidy/obvious/InvalidRangeCheck.cpp
  clang-tidy/obvious/InvalidRangeCheck.h
  clang-tidy/obvious/ObviousTidyModule.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/misc-invalid-range.rst
  test/clang-tidy/misc-invalid-range.cpp

Index: test/clang-tidy/misc-invalid-range.cpp
===
--- /dev/null
+++ test/clang-tidy/misc-invalid-range.cpp
@@ -0,0 +1,47 @@
+// RUN: %check_clang_tidy %s misc-invalid-range %t
+
+namespace std {
+
+template 
+OutputIterator copy(InputIterator first, InputIterator last, OutputIterator result) {
+  return result;
+}
+
+template 
+OutputIterator move(InputIterator first, InputIterator last, OutputIterator result) {
+  return result;
+}
+
+template 
+T move(T &&) { return T(); }
+
+template 
+void fill(InputIterator first, InputIterator last, const Val &v) {
+}
+
+template 
+class vector {
+public:
+  T *begin();
+  T *end();
+};
+}
+
+void test_copy() {
+  std::vector v, v2;
+  std::copy(v.begin(), v2.end(), v2.begin());
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: call to algorithm with begin and end from different objects [misc-invalid-range]
+
+  std::copy(v.begin(), v.end(), v2.begin());
+}
+
+void test_move() {
+  std::vector v;
+  auto &v2 = v;
+  std::move(v.begin(), v2.end(), v2.begin());
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: call to algorithm with begin and end from different objects [misc-invalid-range]
+
+  std::move(v.begin(), v.end(), v2.begin());
+  std::move(v.begin());
+  test_copy();
+}
Index: docs/clang-tidy/checks/misc-invalid-range.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/misc-invalid-range.rst
@@ -0,0 +1,17 @@
+.. title:: clang-tidy - misc-invalid-range
+
+misc-invalid-range
+==
+
+This check finds invalid calls to algorithms with obviously invalid range of
+iterators like:
+
+.. code-block:: c++
+std::fill(v.begin(), v2.end(), it);
+
+It checks if first and second argument of call is call to ``begin()``
+and ``end()``, but on different objects (having different name).
+
+By default it looks for all algorithms from . This can be
+changed by using ``AlgorithmNames`` option, where empty list means that any
+function name will be accepted.
\ No newline at end of file
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -65,6 +65,7 @@
misc-inaccurate-erase
misc-incorrect-roundings
misc-inefficient-algorithm
+   misc-invalid-range
misc-macro-parentheses
misc-macro-repeated-side-effects
misc-misplaced-const
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -114,6 +114,15 @@
 
   Flags MPI function calls with a buffer type and MPI data type mismatch.
 
+- New obvious module with checks for obvious bugs that probably won't be found
+  in working code, but can be found while looking for an obvious bug in broken
+  code.
+- New `obvious-invalid-range
+  `_ check
+
+  Warns if algorithm is used with ``.begin()`` and ``.end()`` from different
+  variables.
+
 - New `performance-inefficient-string-concatenation
   `_ check
 
Index: clang-tidy/obvious/ObviousTidyModule.cpp
===
--- clang-tidy/obvious/ObviousTidyModule.cpp
+++ clang-tidy/obvious/ObviousTidyModule.cpp
@@ -11,6 +11,7 @@
 #include "../ClangTidyModule.h"
 #include "../ClangTidyModuleRegistry.h"
 
+#include "InvalidRangeCheck.h"
 using namespace clang::ast_matchers;
 
 namespace clang {
@@ -20,7 +21,7 @@
 class ObviousModule : public ClangTidyModule {
 public:
   void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
-// Add obvious checks here.
+CheckFactories.registerCheck("misc-invalid-range");
   }
 };
 
Index: clang-tidy/obvious/InvalidRangeCheck.h
===
--- /dev/null
+++ clang-tidy/obvious/InvalidRangeCheck.h
@@ -0,0 +1,40 @@
+//===--- InvalidRangeCheck.h - clang-tidy*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_OBVIOUS_INVALID_RANGE_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_

[PATCH] D27773: [analyzer] Add checker modeling gtest APIs.

2016-12-15 Thread Aleksei Sidorin via Phabricator via cfe-commits
a.sidorin added a comment.

Thank you Devin!




Comment at: lib/StaticAnalyzer/Checkers/GTestChecker.cpp:30
+//
+// The gtest unit testing API provides macros for assertions that that expand
+// into an if statement that calls a series of constructors and returns

"that that"



Comment at: lib/StaticAnalyzer/Checkers/GTestChecker.cpp:105
+  void modelAssertionResultBoolConstructor(const CXXConstructorCall *Call,
+   CheckerContext &C) const;
+

Misalignment here and below



Comment at: lib/StaticAnalyzer/Checkers/GTestChecker.cpp:182
+
+  SVal ThisSuccess = getAssertionResultSuccessFieldValue(AssertResultClassDecl,
+ ThisVal, State);

Shouldn't we just bind OtherSuccess to our field?


https://reviews.llvm.org/D27773



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


[PATCH] D27163: Introduce -f[no-]strict-return flag that controls code generation for C++'s undefined behaviour return optimisation

2016-12-15 Thread David Majnemer via Phabricator via cfe-commits
majnemer added a comment.

My 2 cents: If making this a target-specific default is not OK, why not turn on 
-fno-strict-return if -fapple-kext is specified? I believe that would cover the 
critical use case in question.


Repository:
  rL LLVM

https://reviews.llvm.org/D27163



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


[PATCH] D27806: [clang-tidy] Add obvious-invalid-range

2016-12-15 Thread Malcolm Parsons via Phabricator via cfe-commits
malcolm.parsons added a comment.

What about arguments 3 and 4 of `std::list::splice(It, list, It, It)`?




Comment at: clang-tidy/obvious/ObviousTidyModule.cpp:24
   void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
-// Add obvious checks here.
+CheckFactories.registerCheck("misc-invalid-range");
   }

misc?



Comment at: docs/ReleaseNotes.rst:84
 
+- New `misc-invalid-range
+  `_ 
check

Prazek wrote:
> malcolm.parsons wrote:
> > "invalid" < "use"
> You mean to change "invalid" to "use"?
> It is not about using range, it is about finding broken range.
The release notes should be in alphabetical order.


https://reviews.llvm.org/D27806



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


[PATCH] D27806: [clang-tidy] Add obvious-invalid-range

2016-12-15 Thread Piotr Padlewski via Phabricator via cfe-commits
Prazek marked 3 inline comments as done.
Prazek added inline comments.



Comment at: docs/ReleaseNotes.rst:84
 
+- New `misc-invalid-range
+  `_ 
check

malcolm.parsons wrote:
> Prazek wrote:
> > malcolm.parsons wrote:
> > > "invalid" < "use"
> > You mean to change "invalid" to "use"?
> > It is not about using range, it is about finding broken range.
> The release notes should be in alphabetical order.
oh sure, fixed that.


https://reviews.llvm.org/D27806



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


[PATCH] D27806: [clang-tidy] Add obvious-invalid-range

2016-12-15 Thread Piotr Padlewski via Phabricator via cfe-commits
Prazek updated this revision to Diff 81603.
Prazek marked 2 inline comments as done.
Prazek added a comment.

- Small fixes


https://reviews.llvm.org/D27806

Files:
  clang-tidy/obvious/CMakeLists.txt
  clang-tidy/obvious/InvalidRangeCheck.cpp
  clang-tidy/obvious/InvalidRangeCheck.h
  clang-tidy/obvious/ObviousTidyModule.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/misc-invalid-range.rst
  test/clang-tidy/misc-invalid-range.cpp

Index: test/clang-tidy/misc-invalid-range.cpp
===
--- /dev/null
+++ test/clang-tidy/misc-invalid-range.cpp
@@ -0,0 +1,47 @@
+// RUN: %check_clang_tidy %s misc-invalid-range %t
+
+namespace std {
+
+template 
+OutputIterator copy(InputIterator first, InputIterator last, OutputIterator result) {
+  return result;
+}
+
+template 
+OutputIterator move(InputIterator first, InputIterator last, OutputIterator result) {
+  return result;
+}
+
+template 
+T move(T &&) { return T(); }
+
+template 
+void fill(InputIterator first, InputIterator last, const Val &v) {
+}
+
+template 
+class vector {
+public:
+  T *begin();
+  T *end();
+};
+}
+
+void test_copy() {
+  std::vector v, v2;
+  std::copy(v.begin(), v2.end(), v2.begin());
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: call to algorithm with begin and end from different objects [misc-invalid-range]
+
+  std::copy(v.begin(), v.end(), v2.begin());
+}
+
+void test_move() {
+  std::vector v;
+  auto &v2 = v;
+  std::move(v.begin(), v2.end(), v2.begin());
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: call to algorithm with begin and end from different objects [misc-invalid-range]
+
+  std::move(v.begin(), v.end(), v2.begin());
+  std::move(v.begin());
+  test_copy();
+}
Index: docs/clang-tidy/checks/misc-invalid-range.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/misc-invalid-range.rst
@@ -0,0 +1,17 @@
+.. title:: clang-tidy - misc-invalid-range
+
+misc-invalid-range
+==
+
+This check finds invalid calls to algorithms with obviously invalid range of
+iterators like:
+
+.. code-block:: c++
+std::fill(v.begin(), v2.end(), it);
+
+It checks if first and second argument of call is call to ``begin()``
+and ``end()``, but on different objects (having different name).
+
+By default it looks for all algorithms from . This can be
+changed by using ``AlgorithmNames`` option, where empty list means that any
+function name will be accepted.
\ No newline at end of file
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -65,6 +65,7 @@
misc-inaccurate-erase
misc-incorrect-roundings
misc-inefficient-algorithm
+   misc-invalid-range
misc-macro-parentheses
misc-macro-repeated-side-effects
misc-misplaced-const
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -114,6 +114,15 @@
 
   Flags MPI function calls with a buffer type and MPI data type mismatch.
 
+- New obvious module with checks for obvious bugs that probably won't be found
+  in working code, but can be found while looking for an obvious bug in broken
+  code.
+- New `obvious-invalid-range
+  `_ check
+
+  Warns if algorithm is used with ``.begin()`` and ``.end()`` from different
+  variables.
+
 - New `performance-inefficient-string-concatenation
   `_ check
 
Index: clang-tidy/obvious/ObviousTidyModule.cpp
===
--- clang-tidy/obvious/ObviousTidyModule.cpp
+++ clang-tidy/obvious/ObviousTidyModule.cpp
@@ -11,6 +11,7 @@
 #include "../ClangTidyModule.h"
 #include "../ClangTidyModuleRegistry.h"
 
+#include "InvalidRangeCheck.h"
 using namespace clang::ast_matchers;
 
 namespace clang {
@@ -20,7 +21,7 @@
 class ObviousModule : public ClangTidyModule {
 public:
   void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
-// Add obvious checks here.
+CheckFactories.registerCheck("obvious-invalid-range");
   }
 };
 
Index: clang-tidy/obvious/InvalidRangeCheck.h
===
--- /dev/null
+++ clang-tidy/obvious/InvalidRangeCheck.h
@@ -0,0 +1,40 @@
+//===--- InvalidRangeCheck.h - clang-tidy*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_OBVIOUS_INVALID_RA

[PATCH] D27806: [clang-tidy] Add obvious-invalid-range

2016-12-15 Thread Piotr Padlewski via Phabricator via cfe-commits
Prazek marked an inline comment as done.
Prazek added a comment.

In https://reviews.llvm.org/D27806#623838, @malcolm.parsons wrote:

> What about arguments 3 and 4 of `std::list::splice(It, list, It, It)`?


I am aware of that, but I wanted to make a bunch of simple checks to fill 
obvious module without taking too much time.
So does FIXIT comment satisfies you for this patch?


https://reviews.llvm.org/D27806



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


[PATCH] D27753: [analyzer] alpha.security.DirtyScalar Checker

2016-12-15 Thread Aleksei Sidorin via Phabricator via cfe-commits
a.sidorin added a comment.

Thank you for your work, Zoltán!
Did you checked if same warnings may be emitted by another checkers? For 
example, ArrayBoundChecker may warn if index is tainted.
I also have some comments below.




Comment at: lib/StaticAnalyzer/Checkers/DirtyScalarChecker.cpp:47
+  void checkPreStmt(const BinaryOperator *BO, CheckerContext &C) const;
+  void checkBranchCondition(const Stmt *Cond, CheckerContext &Ctx) const;
+

`CheckerContext &C` to unify naming.



Comment at: lib/StaticAnalyzer/Checkers/DirtyScalarChecker.cpp:51
+  void checkLoopCond(const Stmt *Cond, CheckerContext &C,
+ int RecurseLimit = 3) const;
+  void checkUnbounded(CheckerContext &C, ProgramStateRef PS,

The default choice of such a value needs some explanation. It is also good to 
move a hard-coded value to a named constant, or, maybe a separate checker 
option.



Comment at: lib/StaticAnalyzer/Checkers/DirtyScalarChecker.cpp:52
+ int RecurseLimit = 3) const;
+  void checkUnbounded(CheckerContext &C, ProgramStateRef PS,
+  const Stmt *ST) const;

`ProgramStateRef State, const Stmt *S)`.
These names are usually used in analyzer and LLVM for ProgramState and Stmt, 
correspondingly.



Comment at: lib/StaticAnalyzer/Checkers/DirtyScalarChecker.cpp:54
+  const Stmt *ST) const;
+  bool isUnbounded(CheckerContext &C, ProgramStateRef PS, SVal &V) const;
+  void reportBug(CheckerContext &C, ProgramStateRef PS, SVal &V) const;

We pass `V` by non-const reference, but it is not changed inside the function. 
So, we may use a constant reference here or even pass it by value (because it 
is small enough).



Comment at: lib/StaticAnalyzer/Checkers/DirtyScalarChecker.cpp:62
+  CheckerContext &C) const {
+  const CallExpr *CE = dyn_cast(Call.getOriginExpr());
+  const FunctionDecl *FDecl = C.getCalleeDecl(CE);

`CallEvent::getOriginExpr()` may return `nullptr` (in case of implicit 
destructor calls, for example) so we need to check the result before `dyn_cast` 
or dereference.



Comment at: lib/StaticAnalyzer/Checkers/DirtyScalarChecker.cpp:82
+  ProgramStateRef PS = C.getState();
+  for (unsigned int i = 0; i < CE->getNumArgs(); ++i) {
+const Expr *Arg = CE->getArg(i);

1. Variable names should start with capital letter to follow LLVM naming 
convention.
2. We may move CE->getNumArgs out of the loop in order not to re-evaluate it 
every time so the code will look like
`for (unsigned int I = 0, E = CE->getNumArgs(); I < E; ++I) {`.

We also can C++11-fy this loop:

```
for (const Expr *Arg : CE->arguments())
  checkUnbounded(C, State, Arg);
```



Comment at: test/Analysis/dirty-scalar-unbounded.cpp:1
+// RUN: %clang_cc1 -analyze 
-analyzer-checker=alpha.security.taint,alpha.security.DirtyScalar -verify 
-analyzer-config alpha.security.DirtyScalar:criticalOnly=false %s
+

1. It will be good to have tests for option set to true.
2. Is there any test that makes usage of 'RecurseLimit` variable?


https://reviews.llvm.org/D27753



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


[PATCH] D27806: [clang-tidy] Add obvious-invalid-range

2016-12-15 Thread Piotr Padlewski via Phabricator via cfe-commits
Prazek updated this revision to Diff 81604.
Prazek added a comment.

- Small fixes


https://reviews.llvm.org/D27806

Files:
  clang-tidy/obvious/CMakeLists.txt
  clang-tidy/obvious/InvalidRangeCheck.cpp
  clang-tidy/obvious/InvalidRangeCheck.h
  clang-tidy/obvious/ObviousTidyModule.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/misc-invalid-range.rst
  test/clang-tidy/misc-invalid-range.cpp

Index: test/clang-tidy/misc-invalid-range.cpp
===
--- /dev/null
+++ test/clang-tidy/misc-invalid-range.cpp
@@ -0,0 +1,47 @@
+// RUN: %check_clang_tidy %s misc-invalid-range %t
+
+namespace std {
+
+template 
+OutputIterator copy(InputIterator first, InputIterator last, OutputIterator result) {
+  return result;
+}
+
+template 
+OutputIterator move(InputIterator first, InputIterator last, OutputIterator result) {
+  return result;
+}
+
+template 
+T move(T &&) { return T(); }
+
+template 
+void fill(InputIterator first, InputIterator last, const Val &v) {
+}
+
+template 
+class vector {
+public:
+  T *begin();
+  T *end();
+};
+}
+
+void test_copy() {
+  std::vector v, v2;
+  std::copy(v.begin(), v2.end(), v2.begin());
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: call to algorithm with begin and end from different objects [misc-invalid-range]
+
+  std::copy(v.begin(), v.end(), v2.begin());
+}
+
+void test_move() {
+  std::vector v;
+  auto &v2 = v;
+  std::move(v.begin(), v2.end(), v2.begin());
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: call to algorithm with begin and end from different objects [misc-invalid-range]
+
+  std::move(v.begin(), v.end(), v2.begin());
+  std::move(v.begin());
+  test_copy();
+}
Index: docs/clang-tidy/checks/misc-invalid-range.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/misc-invalid-range.rst
@@ -0,0 +1,17 @@
+.. title:: clang-tidy - misc-invalid-range
+
+misc-invalid-range
+==
+
+This check finds invalid calls to algorithms with obviously invalid range of
+iterators like:
+
+.. code-block:: c++
+std::fill(v.begin(), v2.end(), it);
+
+It checks if first and second argument of call is call to ``begin()``
+and ``end()``, but on different objects (having different name).
+
+By default it looks for all algorithms from . This can be
+changed by using ``AlgorithmNames`` option, where empty list means that any
+function name will be accepted.
\ No newline at end of file
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -65,6 +65,7 @@
misc-inaccurate-erase
misc-incorrect-roundings
misc-inefficient-algorithm
+   misc-invalid-range
misc-macro-parentheses
misc-macro-repeated-side-effects
misc-misplaced-const
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -114,6 +114,15 @@
 
   Flags MPI function calls with a buffer type and MPI data type mismatch.
 
+- New obvious module with checks for obvious bugs that probably won't be found
+  in working code, but can be found while looking for an obvious bug in broken
+  code.
+- New `obvious-invalid-range
+  `_ check
+
+  Warns if algorithm is used with ``.begin()`` and ``.end()`` from different
+  variables.
+
 - New `performance-inefficient-string-concatenation
   `_ check
 
Index: clang-tidy/obvious/ObviousTidyModule.cpp
===
--- clang-tidy/obvious/ObviousTidyModule.cpp
+++ clang-tidy/obvious/ObviousTidyModule.cpp
@@ -11,6 +11,7 @@
 #include "../ClangTidyModule.h"
 #include "../ClangTidyModuleRegistry.h"
 
+#include "InvalidRangeCheck.h"
 using namespace clang::ast_matchers;
 
 namespace clang {
@@ -20,7 +21,7 @@
 class ObviousModule : public ClangTidyModule {
 public:
   void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
-// Add obvious checks here.
+CheckFactories.registerCheck("obvious-invalid-range");
   }
 };
 
Index: clang-tidy/obvious/InvalidRangeCheck.h
===
--- /dev/null
+++ clang-tidy/obvious/InvalidRangeCheck.h
@@ -0,0 +1,40 @@
+//===--- InvalidRangeCheck.h - clang-tidy*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_OBVIOUS_INVALID_RANGE_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLA

[PATCH] D27163: Introduce -f[no-]strict-return flag that controls code generation for C++'s undefined behaviour return optimisation

2016-12-15 Thread Mehdi AMINI via Phabricator via cfe-commits
mehdi_amini accepted this revision.
mehdi_amini added a comment.
This revision is now accepted and ready to land.

LGTM.




Comment at: lib/CodeGen/CodeGenFunction.cpp:1086
+  }
+  return true;
+}

Just a nit: reversing the if condition allows early exit.


Repository:
  rL LLVM

https://reviews.llvm.org/D27163



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


[PATCH] D27806: [clang-tidy] Add obvious-invalid-range

2016-12-15 Thread Malcolm Parsons via Phabricator via cfe-commits
malcolm.parsons added a comment.

In https://reviews.llvm.org/D27806#623856, @Prazek wrote:

> So does FIXIT comment satisfies you for this patch?


Yes.




Comment at: clang-tidy/obvious/InvalidRangeCheck.cpp:80
+void InvalidRangeCheck::check(const MatchFinder::MatchResult &Result) {
+
+  const auto *FirstArg = Result.Nodes.getNodeAs("first_arg");

blank line at start of function.



Comment at: docs/clang-tidy/checks/misc-invalid-range.rst:1
+.. title:: clang-tidy - misc-invalid-range
+

misc.



Comment at: test/clang-tidy/misc-invalid-range.cpp:1
+// RUN: %check_clang_tidy %s misc-invalid-range %t
+

misc


https://reviews.llvm.org/D27806



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


[PATCH] D26753: ASTImporter: improve support for C++ templates

2016-12-15 Thread Aleksei Sidorin via Phabricator via cfe-commits
a.sidorin added a comment.

I didn't notice this failure but I'll recheck this. Thank you Kareem!


https://reviews.llvm.org/D26753



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


[PATCH] D27621: [clang-tidy] check to find declarations declaring more than one name

2016-12-15 Thread Firat Kasmis via Phabricator via cfe-commits
firolino updated this revision to Diff 81605.
firolino added a comment.

Added fix and test case for `const int * const`.


https://reviews.llvm.org/D27621

Files:
  clang-tidy/readability/CMakeLists.txt
  clang-tidy/readability/OneNamePerDeclarationCheck.cpp
  clang-tidy/readability/OneNamePerDeclarationCheck.h
  clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tidy/utils/LexerUtils.cpp
  clang-tidy/utils/LexerUtils.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/readability-one-name-per-declaration.rst
  test/clang-tidy/readability-one-name-per-declaration-complex.cpp
  test/clang-tidy/readability-one-name-per-declaration-modern.cpp
  test/clang-tidy/readability-one-name-per-declaration-simple.cpp

Index: test/clang-tidy/readability-one-name-per-declaration-simple.cpp
===
--- /dev/null
+++ test/clang-tidy/readability-one-name-per-declaration-simple.cpp
@@ -0,0 +1,142 @@
+// RUN: %check_clang_tidy %s readability-one-name-per-declaration %t
+
+int cantTouchA, cantTouchB;
+
+void simple() 
+{
+int dontTouchC;
+
+long empty;
+long long1 = 11, *long2 = &empty, * long3 = ∅
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: declaration statement can be split up into single line declarations [readability-one-name-per-declaration]
+// CHECK-FIXES: {{^}}long long1 = 11;
+// CHECK-FIXES: {{^}}long *long2 = ∅
+// CHECK-FIXES: {{^}}long * long3 = ∅
+
+long ** lint1, lint2 = 0, * lint3, **linn;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: declaration statement can be split up into single line declarations [readability-one-name-per-declaration]
+// CHECK-FIXES: {{^}}long ** lint1;
+// CHECK-FIXES: {{^}}long lint2 = 0;
+// CHECK-FIXES: {{^}}long * lint3;
+// CHECK-FIXES: {{^}}long **linn;
+
+	long int* lint4, *lint5,  lint6;
+	// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: declaration statement can be split up into single line declarations [readability-one-name-per-declaration]
+	// CHECK-FIXES: {{^	}}long int* lint4;
+	// CHECK-FIXES: {{^	}}long int *lint5;
+	// CHECK-FIXES: {{^	}}long int lint6;
+
+/* *& */ int /* *& */ ** /* *& */ pp,*xx;
+// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: declaration statement can be split up into single line declarations [readability-one-name-per-declaration]
+// CHECK-FIXES: {{^}}/* *& */ int /* *& */ ** /* *& */ pp;
+// CHECK-FIXES: {{^}}int *xx;
+
+unsigned int uint1 = 0,uint2 = 44u, uint3, uint4=4;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: declaration statement can be split up into single line declarations [readability-one-name-per-declaration]
+// CHECK-FIXES: {{^}}unsigned int uint1 = 0;
+// CHECK-FIXES: {{^}}unsigned int uint2 = 44u;
+// CHECK-FIXES: {{^}}unsigned int uint3;
+// CHECK-FIXES: {{^}}unsigned int uint4=4;
+
+const int * const cpc = &dontTouchC, simple = 0;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: declaration statement can be split up into single line declarations [readability-one-name-per-declaration]
+// CHECK-FIXES: {{^}}const int * const cpc = &dontTouchC;
+// CHECK-FIXES: {{^}}const int simple = 0;
+
+double darray1[] = {}, darray2[] = {1,	2},dv1 = 3,dv2;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: declaration statement can be split up into single line declarations [readability-one-name-per-declaration]
+// CHECK-FIXES: {{^}}double darray1[] = {};
+// CHECK-FIXES: {{^}}double darray2[] = {1,	2};
+// CHECK-FIXES: {{^}}double dv1 = 3;
+// CHECK-FIXES: {{^}}double dv2;
+
+int notransform[] =   {
+  1,
+  2
+  };
+
+const int cx = 1, cy = 2;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: declaration statement can be split up into single line declarations [readability-one-name-per-declaration]
+// CHECK-FIXES: {{^}}const int cx = 1;
+// CHECK-FIXES: {{^}}const int cy = 2;
+
+volatile int vx, vy;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: declaration statement can be split up into single line declarations [readability-one-name-per-declaration]
+// CHECK-FIXES: {{^}}volatile int vx;
+// CHECK-FIXES: {{^}}volatile int vy;
+
+signed char sc1 = 'h', sc2;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: declaration statement can be split up into single line declarations [readability-one-name-per-declaration]
+// CHECK-FIXES: {{^}}signed char sc1 = 'h';
+// CHECK-FIXES: {{^}}signed char sc2;
+
+long long ll1, ll2, ***ft;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: declaration statement can be split up into single line declarations [readability-one-name-per-declaration]
+// CHECK-FIXES: {{^}}long long ll1;
+// CHECK-FI

[PATCH] D27806: [clang-tidy] Add obvious-invalid-range

2016-12-15 Thread Malcolm Parsons via Phabricator via cfe-commits
malcolm.parsons added inline comments.



Comment at: test/clang-tidy/misc-invalid-range.cpp:41
+  auto &v2 = v;
+  std::move(v.begin(), v2.end(), v2.begin());
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: call to algorithm with begin 
and end from different objects [misc-invalid-range]

They're the same object...


https://reviews.llvm.org/D27806



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


[PATCH] D27806: [clang-tidy] Add obvious-invalid-range

2016-12-15 Thread Piotr Padlewski via Phabricator via cfe-commits
Prazek updated this revision to Diff 81606.
Prazek added a comment.

- Small fixes


https://reviews.llvm.org/D27806

Files:
  clang-tidy/obvious/CMakeLists.txt
  clang-tidy/obvious/InvalidRangeCheck.cpp
  clang-tidy/obvious/InvalidRangeCheck.h
  clang-tidy/obvious/ObviousTidyModule.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/obvious-invalid-range.rst
  test/clang-tidy/obvious-invalid-range.cpp

Index: test/clang-tidy/obvious-invalid-range.cpp
===
--- /dev/null
+++ test/clang-tidy/obvious-invalid-range.cpp
@@ -0,0 +1,47 @@
+// RUN: %check_clang_tidy %s obvious-invalid-range %t
+
+namespace std {
+
+template 
+OutputIterator copy(InputIterator first, InputIterator last, OutputIterator result) {
+  return result;
+}
+
+template 
+OutputIterator move(InputIterator first, InputIterator last, OutputIterator result) {
+  return result;
+}
+
+template 
+T move(T &&) { return T(); }
+
+template 
+void fill(InputIterator first, InputIterator last, const Val &v) {
+}
+
+template 
+class vector {
+public:
+  T *begin();
+  T *end();
+};
+}
+
+void test_copy() {
+  std::vector v, v2;
+  std::copy(v.begin(), v2.end(), v2.begin());
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: call to algorithm with begin and end from different objects [obvious-invalid-range]
+
+  std::copy(v.begin(), v.end(), v2.begin());
+}
+
+void test_move() {
+  std::vector v;
+  auto &v2 = v;
+  std::move(v.begin(), v2.end(), v2.begin());
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: call to algorithm with begin and end from different objects
+
+  std::move(v.begin(), v.end(), v2.begin());
+  std::move(v.begin());
+  test_copy();
+}
Index: docs/clang-tidy/checks/obvious-invalid-range.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/obvious-invalid-range.rst
@@ -0,0 +1,17 @@
+.. title:: clang-tidy - obvious-invalid-range
+
+obvious-invalid-range
+=
+
+This check finds invalid calls to algorithms with obviously invalid range of
+iterators like:
+
+.. code-block:: c++
+std::fill(v.begin(), v2.end(), it);
+
+It checks if first and second argument of call is call to ``begin()``
+and ``end()``, but on different objects (having different name).
+
+By default it looks for all algorithms from . This can be
+changed by using ``AlgorithmNames`` option, where empty list means that any
+function name will be accepted.
\ No newline at end of file
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -65,6 +65,7 @@
misc-inaccurate-erase
misc-incorrect-roundings
misc-inefficient-algorithm
+   misc-invalid-range
misc-macro-parentheses
misc-macro-repeated-side-effects
misc-misplaced-const
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -114,6 +114,15 @@
 
   Flags MPI function calls with a buffer type and MPI data type mismatch.
 
+- New obvious module with checks for obvious bugs that probably won't be found
+  in working code, but can be found while looking for an obvious bug in broken
+  code.
+- New `obvious-invalid-range
+  `_ check
+
+  Warns if algorithm is used with ``.begin()`` and ``.end()`` from different
+  variables.
+
 - New `performance-inefficient-string-concatenation
   `_ check
 
Index: clang-tidy/obvious/ObviousTidyModule.cpp
===
--- clang-tidy/obvious/ObviousTidyModule.cpp
+++ clang-tidy/obvious/ObviousTidyModule.cpp
@@ -11,6 +11,7 @@
 #include "../ClangTidyModule.h"
 #include "../ClangTidyModuleRegistry.h"
 
+#include "InvalidRangeCheck.h"
 using namespace clang::ast_matchers;
 
 namespace clang {
@@ -20,7 +21,7 @@
 class ObviousModule : public ClangTidyModule {
 public:
   void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
-// Add obvious checks here.
+CheckFactories.registerCheck("obvious-invalid-range");
   }
 };
 
Index: clang-tidy/obvious/InvalidRangeCheck.h
===
--- /dev/null
+++ clang-tidy/obvious/InvalidRangeCheck.h
@@ -0,0 +1,40 @@
+//===--- InvalidRangeCheck.h - clang-tidy*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_OBVIOUS_INVALID_RANGE_H
+#define LLVM_CLANG_TOO

[PATCH] D27806: [clang-tidy] Add obvious-invalid-range

2016-12-15 Thread Piotr Padlewski via Phabricator via cfe-commits
Prazek added inline comments.



Comment at: test/clang-tidy/misc-invalid-range.cpp:41
+  auto &v2 = v;
+  std::move(v.begin(), v2.end(), v2.begin());
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: call to algorithm with begin 
and end from different objects [misc-invalid-range]

malcolm.parsons wrote:
> They're the same object...
Yep, but this type of code stinks, so it is probably a bug


https://reviews.llvm.org/D27806



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


[PATCH] D27163: Introduce -f[no-]strict-return flag that controls code generation for C++'s undefined behaviour return optimisation

2016-12-15 Thread Mehdi AMINI via Phabricator via cfe-commits
mehdi_amini added a comment.

(Wait a little in case @Quuxplusone still has comments.)


Repository:
  rL LLVM

https://reviews.llvm.org/D27163



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


[PATCH] D27806: [clang-tidy] Add obvious-invalid-range

2016-12-15 Thread Malcolm Parsons via Phabricator via cfe-commits
malcolm.parsons added inline comments.



Comment at: docs/clang-tidy/checks/list.rst:68
misc-inefficient-algorithm
+   misc-invalid-range
misc-macro-parentheses

misc.
add_new_check.py can fix it.


https://reviews.llvm.org/D27806



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


r289836 - Fix typo in comment. NFC.

2016-12-15 Thread Kelvin Li via cfe-commits
Author: kli
Date: Thu Dec 15 11:55:32 2016
New Revision: 289836

URL: http://llvm.org/viewvc/llvm-project?rev=289836&view=rev
Log:
Fix typo in comment.  NFC.

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

Modified: cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp?rev=289836&r1=289835&r2=289836&view=diff
==
--- cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGStmtOpenMP.cpp Thu Dec 15 11:55:32 2016
@@ -3439,7 +3439,7 @@ static void emitCommonOMPTeamsDirective(
 }
 
 void CodeGenFunction::EmitOMPTeamsDirective(const OMPTeamsDirective &S) {
-  // Emit parallel region as a standalone region.
+  // Emit teams region as a standalone region.
   auto &&CodeGen = [&S](CodeGenFunction &CGF, PrePostActionTy &) {
 OMPPrivateScope PrivateScope(CGF);
 (void)CGF.EmitOMPFirstprivateClause(S, PrivateScope);


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


[PATCH] D25435: Add -femit-accurate-debug-info to emit more debug info for sample pgo profile collection

2016-12-15 Thread Dehao Chen via Phabricator via cfe-commits
danielcdh updated this revision to Diff 81609.
danielcdh added a comment.

update option name


https://reviews.llvm.org/D25435

Files:
  include/clang/Driver/Options.td
  include/clang/Frontend/CodeGenOptions.def
  lib/CodeGen/BackendUtil.cpp
  lib/CodeGen/CGDebugInfo.cpp
  lib/Driver/Tools.cpp
  lib/Frontend/CompilerInvocation.cpp
  test/Driver/clang_f_opts.c


Index: test/Driver/clang_f_opts.c
===
--- test/Driver/clang_f_opts.c
+++ test/Driver/clang_f_opts.c
@@ -469,3 +469,8 @@
 // CHECK-WCHAR2: -fshort-wchar
 // CHECK-WCHAR2-NOT: -fno-short-wchar
 // DELIMITERS: {{^ *"}}
+
+// RUN: %clang -### -S -fno-debug-info-for-profiling 
-fdebug-info-for-profiling %s 2>&1 | FileCheck 
-check-prefix=CHECK-PROFILE-DEBUG %s
+// RUN: %clang -### -S -fdebug-info-for-profiling 
-fno-debug-info-for-profiling %s 2>&1 | FileCheck 
-check-prefix=CHECK-NO-PROFILE-DEBUG %s
+// CHECK-PROFILE-DEBUG: -fdebug-info-for-profiling
+// CHECK-NO-PROFILE-DEBUG-NOT: -fdebug-info-for-profiling
Index: lib/Frontend/CompilerInvocation.cpp
===
--- lib/Frontend/CompilerInvocation.cpp
+++ lib/Frontend/CompilerInvocation.cpp
@@ -538,6 +538,8 @@
   Opts.DisableIntegratedAS = Args.hasArg(OPT_fno_integrated_as);
   Opts.Autolink = !Args.hasArg(OPT_fno_autolink);
   Opts.SampleProfileFile = Args.getLastArgValue(OPT_fprofile_sample_use_EQ);
+  Opts.DebugInfoForProfiling = Args.hasFlag(
+  OPT_fdebug_info_for_profiling, OPT_fno_debug_info_for_profiling, false);
 
   setPGOInstrumentor(Opts, Args, Diags);
   Opts.InstrProfileOutput =
Index: lib/Driver/Tools.cpp
===
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -5565,6 +5565,10 @@
   A->render(Args, CmdArgs);
   }
 
+  if (Args.hasFlag(options::OPT_fdebug_info_for_profiling,
+   options::OPT_fno_debug_info_for_profiling, false))
+CmdArgs.push_back("-fdebug-info-for-profiling");
+
   // -fbuiltin is default unless -mkernel is used.
   bool UseBuiltins =
   Args.hasFlag(options::OPT_fbuiltin, options::OPT_fno_builtin,
Index: lib/CodeGen/CGDebugInfo.cpp
===
--- lib/CodeGen/CGDebugInfo.cpp
+++ lib/CodeGen/CGDebugInfo.cpp
@@ -2741,9 +2741,10 @@
   }
   // No need to replicate the linkage name if it isn't different from the
   // subprogram name, no need to have it at all unless coverage is enabled or
-  // debug is set to more than just line tables.
+  // debug is set to more than just line tables or extra debug info is needed.
   if (LinkageName == Name || (!CGM.getCodeGenOpts().EmitGcovArcs &&
   !CGM.getCodeGenOpts().EmitGcovNotes &&
+  !CGM.getCodeGenOpts().DebugInfoForProfiling &&
   DebugKind <= 
codegenoptions::DebugLineTablesOnly))
 LinkageName = StringRef();
 
Index: lib/CodeGen/BackendUtil.cpp
===
--- lib/CodeGen/BackendUtil.cpp
+++ lib/CodeGen/BackendUtil.cpp
@@ -575,6 +575,7 @@
   Options.DisableIntegratedAS = CodeGenOpts.DisableIntegratedAS;
   Options.CompressDebugSections = CodeGenOpts.CompressDebugSections;
   Options.RelaxELFRelocations = CodeGenOpts.RelaxELFRelocations;
+  Options.DebugInfoForProfiling = CodeGenOpts.DebugInfoForProfiling;
 
   // Set EABI version.
   Options.EABIVersion = llvm::StringSwitch(TargetOpts.EABIVersion)
Index: include/clang/Frontend/CodeGenOptions.def
===
--- include/clang/Frontend/CodeGenOptions.def
+++ include/clang/Frontend/CodeGenOptions.def
@@ -255,6 +255,9 @@
 /// Whether copy relocations support is available when building as PIE.
 CODEGENOPT(PIECopyRelocations, 1, 0)
 
+/// Whether emit extra debug info for sample pgo profile collection.
+CODEGENOPT(DebugInfoForProfiling, 1, 0)
+
 #undef CODEGENOPT
 #undef ENUM_CODEGENOPT
 #undef VALUE_CODEGENOPT
Index: include/clang/Driver/Options.td
===
--- include/clang/Driver/Options.td
+++ include/clang/Driver/Options.td
@@ -514,6 +514,12 @@
 HelpText<"Enable sample-based profile guided optimizations">;
 def fauto_profile_EQ : Joined<["-"], "fauto-profile=">,
 Alias;
+def fdebug_info_for_profiling : Flag<["-"], "fdebug-info-for-profiling">, 
Group,
+Flags<[CC1Option]>,
+HelpText<"Emit extra debug info to make sample profile more accurate.">;
+def fno_debug_info_for_profiling : Flag<["-"], 
"fno-debug-info-for-profiling">, Group,
+Flags<[DriverOption]>,
+HelpText<"Do not emit extra debug info for sample profiler.">;
 def fprofile_instr_generate : Flag<["-"], "fprofile-instr-generate">,
 Group, Flags<[CoreOption]>,
 HelpText<"Generate instrumented code to collect execution counts into 
default.profraw file (overriden by '=

[PATCH] D27210: [clang-tidy] misc-string-compare. Adding a new check to clang-tidy

2016-12-15 Thread Mads Ravn via Phabricator via cfe-commits
madsravn updated this revision to Diff 81610.
madsravn added a comment.

Updated the matcher to find suggested occurences.


https://reviews.llvm.org/D27210

Files:
  clang-tidy/misc/CMakeLists.txt
  clang-tidy/misc/MiscTidyModule.cpp
  clang-tidy/misc/StringCompareCheck.cpp
  clang-tidy/misc/StringCompareCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/misc-string-compare.rst
  test/clang-tidy/misc-string-compare.cpp

Index: test/clang-tidy/misc-string-compare.cpp
===
--- test/clang-tidy/misc-string-compare.cpp
+++ test/clang-tidy/misc-string-compare.cpp
@@ -0,0 +1,111 @@
+// RUN: %check_clang_tidy %s misc-string-compare %t -- -- -std=c++11
+
+namespace std {
+template 
+class allocator {};
+template 
+class char_traits {};
+template , typename A = std::allocator>
+class basic_string {
+public:
+  basic_string();
+  basic_string(const C *, unsigned int size);
+  int compare(const basic_string &str) const;
+  int compare(const C *) const;
+  int compare(int, int, const basic_string &str) const;
+  bool empty();
+};
+bool operator==(const basic_string &lhs, const basic_string &rhs);
+bool operator!=(const basic_string &lhs, const basic_string &rhs);
+bool operator==(const basic_string &lhs, const char *&rhs);
+typedef basic_string string;
+}
+
+void func(bool b);
+
+std::string comp() {
+  std::string str("a", 1);
+  return str;
+}
+
+void Test() {
+  std::string str1("a", 1);
+  std::string str2("b", 1);
+
+  if (str1.compare(str2)) {
+  }
+  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings; use the string equality operator instead [misc-string-compare]
+  if (!str1.compare(str2)) {
+  }
+  // CHECK-MESSAGES: [[@LINE-2]]:8: warning: do not use 'compare' to test equality of strings; use the string equality operator instead [misc-string-compare]
+  if (str1.compare(str2) == 0) {
+  }
+  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings;
+  // CHECK-FIXES: if (str1 == str2) {
+  if (str1.compare(str2) != 0) {
+  }
+  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings;
+  // CHECK-FIXES: if (str1 != str2) {
+  if (str1.compare("foo") == 0) {
+  }
+  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings;
+  // CHECK-FIXES: if (str1 == "foo") {
+  if (0 == str1.compare(str2)) {
+  }
+  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings;
+  // CHECK-FIXES: if (str2 == str1) {
+  if (0 != str1.compare(str2)) {
+  }
+  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings;
+  // CHECK-FIXES: if (str2 != str1) {
+  func(str1.compare(str2));
+  // CHECK-MESSAGES: [[@LINE-1]]:8: warning: do not use 'compare' to test equality of strings;
+  if (str2.empty() || str1.compare(str2) != 0) {
+  }
+  // CHECK-MESSAGES: [[@LINE-2]]:23: warning: do not use 'compare' to test equality of strings;
+  // CHECK-FIXES: if (str2.empty() || str1 != str2) {
+  std::string *str3 = &str1;
+  if (str3->compare(str2)) {
+  }
+  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings;
+  if (str3->compare(str2) == 0) {
+  }
+  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings;
+  // CHECK-FIXES: if (*str3 == str2) {
+  if (str2.compare(*str3) == 0) {
+  }
+  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings;
+  // CHECK-FIXES: if (str2 == *str3) {
+  if (comp().compare(str1) == 0) {
+  }
+  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings;
+  // CHECK-FIXES: if (comp() == str1) {
+  if (str1.compare(comp()) == 0) {
+  }
+  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings;
+  // CHECK-FIXES: if (str1 == comp()) {
+  if (str1.compare(comp())) {
+  }
+  // CHECK-MESSAGES: [[@LINE-2]]:7: warning: do not use 'compare' to test equality of strings;
+}
+
+void Valid() {
+  std::string str1("a", 1);
+  std::string str2("b", 1);
+  if (str1 == str2) {
+  }
+  if (str1 != str2) {
+  }
+  if (str1.compare(str2) == 1) {
+  }
+  if (str1.compare(str2) == str1.compare(str2)) {
+  }
+  if (0 == 0) {
+  }
+  if (1 == str1.compare(str2)) {
+  }
+  if (str1.compare(str2) > 0) {
+  }
+  if (str1.compare(1, 3, str2)) {
+  }
+}
Index: docs/clang-tidy/checks/misc-string-compare.rst
===
--- docs/clang-tidy/checks/misc-string-compare.rst
+++ docs/clang-tidy/checks/misc-string-compare.rst
@@ -0,0 +1,54 @@
+.. title:: clang-tidy - misc-string-compare
+
+misc-string-compare
+===
+
+Finds string comparisons using the compare method.
+
+A common mistake is to use the string's ``compare`` method instead of using the 
+equality or inequality operato

[PATCH] D27753: [analyzer] alpha.security.DirtyScalar Checker

2016-12-15 Thread Anna Zaks via Phabricator via cfe-commits
zaks.anna added a comment.

> Did you checked if same warnings may be emitted by another checkers? For 
> example, 
>  ArrayBoundChecker may warn if index is tainted.

I second that. The GenericTaintChecker also reports uses of tainted values. It 
is not clear that we should add a new separate checker instead of adding the 
missing cases to the existing checkers.

Thank you!
Anna.


https://reviews.llvm.org/D27753



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


r289839 - [Driver] Bump default x86 cpu to Penryn when targeting macosx10.12+.

2016-12-15 Thread Ahmed Bougacha via cfe-commits
Author: ab
Date: Thu Dec 15 12:14:27 2016
New Revision: 289839

URL: http://llvm.org/viewvc/llvm-project?rev=289839&view=rev
Log:
[Driver] Bump default x86 cpu to Penryn when targeting macosx10.12+.

10.12 dropped support for all pre-Penryn Macs.

Modified:
cfe/trunk/lib/Driver/Tools.cpp
cfe/trunk/test/Driver/clang-translation.c

Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=289839&r1=289838&r2=289839&view=diff
==
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Thu Dec 15 12:14:27 2016
@@ -2015,6 +2015,11 @@ static const char *getX86TargetCPU(const
   if (Triple.isOSDarwin()) {
 if (Triple.getArchName() == "x86_64h")
   return "core-avx2";
+// macosx10.12 drops support for all pre-Penryn Macs.
+// Simulators can still run on 10.11 though, like Xcode.
+if (Triple.isMacOSX() && !Triple.isOSVersionLT(10, 12))
+  return "penryn";
+// The oldest x86_64 Macs have core2/Merom; the oldest x86 Macs have Yonah.
 return Is64Bit ? "core2" : "yonah";
   }
 

Modified: cfe/trunk/test/Driver/clang-translation.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/clang-translation.c?rev=289839&r1=289838&r2=289839&view=diff
==
--- cfe/trunk/test/Driver/clang-translation.c (original)
+++ cfe/trunk/test/Driver/clang-translation.c Thu Dec 15 12:14:27 2016
@@ -11,19 +11,36 @@
 // I386: "hidden"
 // I386: "-o"
 // I386: clang-translation
+
 // RUN: %clang -target i386-apple-darwin9 -### -S %s -o %t.s 2>&1 | \
 // RUN: FileCheck -check-prefix=YONAH %s
+// RUN: %clang -target i386-apple-macosx10.11 -### -S %s -o %t.s 2>&1 | \
+// RUN: FileCheck -check-prefix=YONAH %s
 // YONAH: "-target-cpu"
 // YONAH: "yonah"
+
 // RUN: %clang -target x86_64-apple-darwin9 -### -S %s -o %t.s 2>&1 | \
 // RUN: FileCheck -check-prefix=CORE2 %s
+// RUN: %clang -target x86_64-apple-macosx10.11 -### -S %s -o %t.s 2>&1 | \
+// RUN: FileCheck -check-prefix=CORE2 %s
 // CORE2: "-target-cpu"
 // CORE2: "core2"
+
 // RUN: %clang -target x86_64h-apple-darwin -### -S %s -o %t.s 2>&1 | \
 // RUN: FileCheck -check-prefix=AVX2 %s
+// RUN: %clang -target x86_64h-apple-macosx10.12 -### -S %s -o %t.s 2>&1 | \
+// RUN: FileCheck -check-prefix=AVX2 %s
 // AVX2: "-target-cpu"
 // AVX2: "core-avx2"
 
+// RUN: %clang -target i386-apple-macosx10.12 -### -S %s -o %t.s 2>&1 | \
+// RUN: FileCheck -check-prefix=PENRYN %s
+// RUN: %clang -target x86_64-apple-macosx10.12 -### -S %s -o %t.s 2>&1 | \
+// RUN: FileCheck -check-prefix=PENRYN %s
+// PENRYN: "-target-cpu"
+// PENRYN: "penryn"
+
+
 // RUN: %clang -target x86_64-apple-darwin10 -### -S %s -arch armv7 2>&1 | \
 // RUN: FileCheck -check-prefix=ARMV7_DEFAULT %s
 // ARMV7_DEFAULT: clang


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


[PATCH] D24487: [Clang] Fix some Clang-tidy modernize-use-bool-literals and Include What You Use warnings in AST; other minor fixes

2016-12-15 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: lib/ASTMatchers/Dynamic/Parser.cpp:617
 
-}  // namespace dynamic
-}  // namespace ast_matchers
-}  // namespace clang
+} // end namespace dynamic
+} // end namespace ast_matchers

Prazek wrote:
> I think check should not warn in these cases.
I think it's reasonable to unify such comments. Three different styles are too 
much for one project :-)


Repository:
  rL LLVM

https://reviews.llvm.org/D24487



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


[PATCH] D27806: [clang-tidy] Add obvious-invalid-range

2016-12-15 Thread Piotr Padlewski via Phabricator via cfe-commits
Prazek added inline comments.



Comment at: docs/clang-tidy/checks/list.rst:68
misc-inefficient-algorithm
+   misc-invalid-range
misc-macro-parentheses

malcolm.parsons wrote:
> misc.
> add_new_check.py can fix it.
How? I added new check with this script, but unfortunatelly rename_check 
doesn't move check from module to module, so I have to make all the changes by 
hand.


https://reviews.llvm.org/D27806



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


[PATCH] D27806: [clang-tidy] Add obvious-invalid-range

2016-12-15 Thread Eugene Zelenko via Phabricator via cfe-commits
Eugene.Zelenko added inline comments.



Comment at: clang-tidy/misc/InvalidRangeCheck.cpp:78
+void InvalidRangeCheck::check(const MatchFinder::MatchResult &Result) {
+
+  const auto *FirstArg = Result.Nodes.getNodeAs("first_arg");

Please remove empty line.



Comment at: docs/ReleaseNotes.rst:88
+  Warns if algorithm is used with ``.begin()`` and ``.end()`` from different
+  variables.
+

Probably container will be better word. Same for documentation.



Comment at: test/clang-tidy/misc-invalid-range.cpp:28
+};
+}
+

Please add closing namespace comment and empty line bfore.


https://reviews.llvm.org/D27806



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


[PATCH] D27806: [clang-tidy] Add obvious-invalid-range

2016-12-15 Thread Piotr Padlewski via Phabricator via cfe-commits
Prazek updated this revision to Diff 81616.
Prazek marked an inline comment as done.
Prazek added a comment.

- removed misc


https://reviews.llvm.org/D27806

Files:
  clang-tidy/obvious/CMakeLists.txt
  clang-tidy/obvious/InvalidRangeCheck.cpp
  clang-tidy/obvious/InvalidRangeCheck.h
  clang-tidy/obvious/ObviousTidyModule.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/obvious-invalid-range.rst
  test/clang-tidy/obvious-invalid-range.cpp

Index: test/clang-tidy/obvious-invalid-range.cpp
===
--- /dev/null
+++ test/clang-tidy/obvious-invalid-range.cpp
@@ -0,0 +1,47 @@
+// RUN: %check_clang_tidy %s obvious-invalid-range %t
+
+namespace std {
+
+template 
+OutputIterator copy(InputIterator first, InputIterator last, OutputIterator result) {
+  return result;
+}
+
+template 
+OutputIterator move(InputIterator first, InputIterator last, OutputIterator result) {
+  return result;
+}
+
+template 
+T move(T &&) { return T(); }
+
+template 
+void fill(InputIterator first, InputIterator last, const Val &v) {
+}
+
+template 
+class vector {
+public:
+  T *begin();
+  T *end();
+};
+}
+
+void test_copy() {
+  std::vector v, v2;
+  std::copy(v.begin(), v2.end(), v2.begin());
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: call to algorithm with begin and end from different objects [obvious-invalid-range]
+
+  std::copy(v.begin(), v.end(), v2.begin());
+}
+
+void test_move() {
+  std::vector v;
+  auto &v2 = v;
+  std::move(v.begin(), v2.end(), v2.begin());
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: call to algorithm with begin and end from different objects
+
+  std::move(v.begin(), v.end(), v2.begin());
+  std::move(v.begin());
+  test_copy();
+}
Index: docs/clang-tidy/checks/obvious-invalid-range.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/obvious-invalid-range.rst
@@ -0,0 +1,17 @@
+.. title:: clang-tidy - obvious-invalid-range
+
+obvious-invalid-range
+=
+
+This check finds invalid calls to algorithms with obviously invalid range of
+iterators like:
+
+.. code-block:: c++
+std::fill(v.begin(), v2.end(), it);
+
+It checks if first and second argument of call is call to ``begin()``
+and ``end()``, but on different objects (having different name).
+
+By default it looks for all algorithms from . This can be
+changed by using ``AlgorithmNames`` option, where empty list means that any
+function name will be accepted.
\ No newline at end of file
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -118,6 +118,7 @@
modernize-use-using
mpi-buffer-deref
mpi-type-mismatch
+   obvious-invalid-range
performance-faster-string-find
performance-for-range-copy
performance-implicit-cast-in-loop
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -114,6 +114,15 @@
 
   Flags MPI function calls with a buffer type and MPI data type mismatch.
 
+- New obvious module with checks for obvious bugs that probably won't be found
+  in working code, but can be found while looking for an obvious bug in broken
+  code.
+- New `obvious-invalid-range
+  `_ check
+
+  Warns if algorithm is used with ``.begin()`` and ``.end()`` from different
+  variables.
+
 - New `performance-inefficient-string-concatenation
   `_ check
 
Index: clang-tidy/obvious/ObviousTidyModule.cpp
===
--- clang-tidy/obvious/ObviousTidyModule.cpp
+++ clang-tidy/obvious/ObviousTidyModule.cpp
@@ -11,6 +11,7 @@
 #include "../ClangTidyModule.h"
 #include "../ClangTidyModuleRegistry.h"
 
+#include "InvalidRangeCheck.h"
 using namespace clang::ast_matchers;
 
 namespace clang {
@@ -20,7 +21,7 @@
 class ObviousModule : public ClangTidyModule {
 public:
   void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
-// Add obvious checks here.
+CheckFactories.registerCheck("obvious-invalid-range");
   }
 };
 
Index: clang-tidy/obvious/InvalidRangeCheck.h
===
--- /dev/null
+++ clang-tidy/obvious/InvalidRangeCheck.h
@@ -0,0 +1,40 @@
+//===--- InvalidRangeCheck.h - clang-tidy*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_O

[PATCH] D27569: [OpenCL] Enabling the usage of CLK_NULL_QUEUE as compare operand.

2016-12-15 Thread Anastasia Stulova via Phabricator via cfe-commits
Anastasia added inline comments.



Comment at: lib/Sema/SemaOverload.cpp:1784
 FromType = ToType;
+  } else if (ToType->isQueueT() &&
+ From->isIntegerConstantExpr(S.getASTContext()) &&

Is this covered with testing? I have a feeling we might need a test with 
overloading functions here?



Comment at: test/CodeGenOpenCL/null_queue.cl:12
+void init() {
+  queue_t q = 0;
+  // CHECK: store %opencl.queue_t* null, %opencl.queue_t** %q

I think it would make sense to have a negative test checking that all other 
integer literals are rejected.



Comment at: test/CodeGenOpenCL/null_queue.cl:13
+  queue_t q = 0;
+  // CHECK: store %opencl.queue_t* null, %opencl.queue_t** %q
+}

Could we also add a function with a queue_t parameter and check that 0 is 
accepted to be passed in?


https://reviews.llvm.org/D27569



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


[PATCH] D27163: Introduce -f[no-]strict-return flag that controls code generation for C++'s undefined behaviour return optimisation

2016-12-15 Thread Arthur O'Dwyer via Phabricator via cfe-commits
Quuxplusone added a comment.

LGTM.  I wonder if rsmith is happy with the exact semantics of 
"shouldUseUndefinedBehaviorReturnOptimization"... but that seems like a tiny 
nit that's fixable post-commit anyway.




Comment at: include/clang/Driver/Options.td:1324
+  HelpText<"Use C++ undefined behaviour optimization for control flow paths"
+ "that reach the end of the function without executing a required return">;
+def fno_strict_return : Flag<["-"], "fno-strict-return">, Group,

Nit: looks like Clang spells it "behavior"?

Nit: I'm still pedantically uncomfortable with describing the strict-return 
behavior as an "optimization". I suggest rephrasing this as "-fstrict-return: 
Treat control flow paths that fall off the end of a non-void function as 
unreachable."

(I notice that neither -fstrict-aliasing nor -fstrict-overflow have any help 
text at all.)



Comment at: lib/CodeGen/CodeGenFunction.cpp:1173
+} else if (CGM.getCodeGenOpts().StrictReturn ||
+   shouldUseUndefinedBehaviorReturnOptimization(FD, getContext())) 
{
+  if (CGM.getCodeGenOpts().OptimizationLevel == 0)

arphaman wrote:
> Quuxplusone wrote:
> > I'd expect this to look more like
> > 
> > bool ShouldOmitUnreachable = !CGM.getCodeGenOpts().StrictReturn && 
> > FD->getReturnType().isTriviallyCopyableType(Context);
> > // same ifs as the old code
> > if (!ShouldOmitUnreachable) {
> > Builder.CreateUnreachable();
> > Builder.ClearInsertionPoint();
> > }
> > 
> > Or in fact, is there a good reason this codepath isn't piggybacking on 
> > `FD->hasImplicitReturnZero()`?  Why not just give every function 
> > `hasImplicitReturnZero` when `-fno-strict-return` is in effect?
> > 
> > At which point, `-fno-strict-return` might seem like the wrong name; you 
> > could just call it something like `-fimplicit-return-zero`, which would 
> > also have the minor benefit of making the `-fno-*` option the default.
> > Or in fact, is there a good reason this codepath isn't piggybacking on 
> > FD->hasImplicitReturnZero()? Why not just give every function 
> > hasImplicitReturnZero when -fno-strict-return is in effect?
> 
> I understand your suggestion, but I'd prefer not to set 
> `hasImplicitReturnZero` for all functions, since then Sema won't warn about 
> the missing return, which we still want.
> 
> > At which point, -fno-strict-return might seem like the wrong name; you 
> > could just call it something like -fimplicit-return-zero, which would also 
> > have the minor benefit of making the -fno-* option the default.
> 
> I don't think a name like "-fimplicit-return-zero" is appropriate, since it 
> implies that the compiler guarantees a return of a zero value. This might 
> mislead users as they might think that they can use the return value without 
> triggering undefined behaviour, which isn't true.
> 
> since then Sema won't warn about the missing return

Ah. Yeah, that makes sense.



Comment at: lib/CodeGen/CodeGenFunction.cpp:1071
+/// Return true if the given function \p FD should use the undefined behavior
+/// return optimization.
+static bool

Nit: this code comment is not particularly useful to the reader.


Repository:
  rL LLVM

https://reviews.llvm.org/D27163



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


[PATCH] D27806: [clang-tidy] Add obvious-invalid-range

2016-12-15 Thread Piotr Padlewski via Phabricator via cfe-commits
Prazek updated this revision to Diff 81617.
Prazek marked an inline comment as done.
Prazek added a comment.

- Small fixes


https://reviews.llvm.org/D27806

Files:
  clang-tidy/obvious/CMakeLists.txt
  clang-tidy/obvious/InvalidRangeCheck.cpp
  clang-tidy/obvious/InvalidRangeCheck.h
  clang-tidy/obvious/ObviousTidyModule.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/obvious-invalid-range.rst
  test/clang-tidy/obvious-invalid-range.cpp

Index: test/clang-tidy/obvious-invalid-range.cpp
===
--- /dev/null
+++ test/clang-tidy/obvious-invalid-range.cpp
@@ -0,0 +1,47 @@
+// RUN: %check_clang_tidy %s obvious-invalid-range %t
+
+namespace std {
+
+template 
+OutputIterator copy(InputIterator first, InputIterator last, OutputIterator result) {
+  return result;
+}
+
+template 
+OutputIterator move(InputIterator first, InputIterator last, OutputIterator result) {
+  return result;
+}
+
+template 
+T move(T &&) { return T(); }
+
+template 
+void fill(InputIterator first, InputIterator last, const Val &v) {
+}
+
+template 
+class vector {
+public:
+  T *begin();
+  T *end();
+};
+}
+
+void test_copy() {
+  std::vector v, v2;
+  std::copy(v.begin(), v2.end(), v2.begin());
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: call to algorithm with begin and end from different objects [obvious-invalid-range]
+
+  std::copy(v.begin(), v.end(), v2.begin());
+}
+
+void test_move() {
+  std::vector v;
+  auto &v2 = v;
+  std::move(v.begin(), v2.end(), v2.begin());
+  // CHECK-MESSAGES: :[[@LINE-1]]:13: warning: call to algorithm with begin and end from different objects
+
+  std::move(v.begin(), v.end(), v2.begin());
+  std::move(v.begin());
+  test_copy();
+}
Index: docs/clang-tidy/checks/obvious-invalid-range.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/obvious-invalid-range.rst
@@ -0,0 +1,17 @@
+.. title:: clang-tidy - obvious-invalid-range
+
+obvious-invalid-range
+=
+
+This check finds invalid calls to algorithms with obviously invalid range of
+iterators like:
+
+.. code-block:: c++
+std::fill(v.begin(), v2.end(), it);
+
+It checks if first and second argument of call is method call to ``begin()``
+and ``end()``, but on different objects (having different name).
+
+By default it looks for all algorithms from . This can be
+changed by using ``AlgorithmNames`` option, where empty list means that any
+function name will be accepted.
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -118,6 +118,7 @@
modernize-use-using
mpi-buffer-deref
mpi-type-mismatch
+   obvious-invalid-range
performance-faster-string-find
performance-for-range-copy
performance-implicit-cast-in-loop
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -114,6 +114,15 @@
 
   Flags MPI function calls with a buffer type and MPI data type mismatch.
 
+- New obvious module with checks for obvious bugs that probably won't be found
+  in working code, but can be found while looking for an obvious bug in broken
+  code.
+- New `obvious-invalid-range
+  `_ check
+
+  Warns if algorithm is used with ``.begin()`` and ``.end()`` from different
+  container.
+
 - New `performance-inefficient-string-concatenation
   `_ check
 
Index: clang-tidy/obvious/ObviousTidyModule.cpp
===
--- clang-tidy/obvious/ObviousTidyModule.cpp
+++ clang-tidy/obvious/ObviousTidyModule.cpp
@@ -11,6 +11,7 @@
 #include "../ClangTidyModule.h"
 #include "../ClangTidyModuleRegistry.h"
 
+#include "InvalidRangeCheck.h"
 using namespace clang::ast_matchers;
 
 namespace clang {
@@ -20,7 +21,7 @@
 class ObviousModule : public ClangTidyModule {
 public:
   void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override {
-// Add obvious checks here.
+CheckFactories.registerCheck("obvious-invalid-range");
   }
 };
 
Index: clang-tidy/obvious/InvalidRangeCheck.h
===
--- /dev/null
+++ clang-tidy/obvious/InvalidRangeCheck.h
@@ -0,0 +1,40 @@
+//===--- InvalidRangeCheck.h - clang-tidy*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_OBVIOUS_INVALID_RANGE_H

[PATCH] D27813: [clang-tidy] fix missing anchor for MPI Module

2016-12-15 Thread Alexander Droste via Phabricator via cfe-commits
Alexander_Droste added a comment.

Thanks for adding!


https://reviews.llvm.org/D27813



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


[PATCH] D27806: [clang-tidy] Add obvious-invalid-range

2016-12-15 Thread Piotr Padlewski via Phabricator via cfe-commits
Prazek added a comment.

Also please review https://reviews.llvm.org/D27815 to make it happen


https://reviews.llvm.org/D27806



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


[PATCH] D27794: Make some diagnostic tests C++11 clean

2016-12-15 Thread Paul Robinson via Phabricator via cfe-commits
probinson added a reviewer: ABataev.
probinson added a comment.

+abataev for OpenMP.


https://reviews.llvm.org/D27794



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


[PATCH] D24487: [Clang] Fix some Clang-tidy modernize-use-bool-literals and Include What You Use warnings in AST; other minor fixes

2016-12-15 Thread Piotr Padlewski via Phabricator via cfe-commits
Prazek added a comment.

I would say that as long as most of the people don't see big difference between 
"end namespace X" and "namespace X" or even "X" then we should not be so 
strict. For me "end" is redundant. 
Even checks added by add_new_check uses "namespace clang" instead of "end 
namespace clang"


Repository:
  rL LLVM

https://reviews.llvm.org/D24487



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


[PATCH] D27813: [clang-tidy] fix missing anchor for MPI Module

2016-12-15 Thread Piotr Padlewski via Phabricator via cfe-commits
Prazek added a comment.

In https://reviews.llvm.org/D27813#623978, @Alexander_Droste wrote:

> Thanks for adding!


I also forgot about that one once. It is simple bugfix so I guess I need small 
LGTM to push it


https://reviews.llvm.org/D27813



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


r289847 - [CUDA] Add --ptxas-path= flag.

2016-12-15 Thread Justin Lebar via cfe-commits
Author: jlebar
Date: Thu Dec 15 12:44:57 2016
New Revision: 289847

URL: http://llvm.org/viewvc/llvm-project?rev=289847&view=rev
Log:
[CUDA] Add --ptxas-path= flag.

Summary:
This lets you build with one CUDA installation but use ptxas from
another install.

This is useful e.g. if you want to avoid bugs in an old ptxas without
actually upgrading wholesale to a newer CUDA version.

Reviewers: tra

Subscribers: cfe-commits

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

Added:
cfe/trunk/test/Driver/cuda-ptxas-path.cu
Modified:
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/lib/Driver/Tools.cpp

Modified: cfe/trunk/include/clang/Driver/Options.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Driver/Options.td?rev=289847&r1=289846&r2=289847&view=diff
==
--- cfe/trunk/include/clang/Driver/Options.td (original)
+++ cfe/trunk/include/clang/Driver/Options.td Thu Dec 15 12:44:57 2016
@@ -425,6 +425,8 @@ def no_cuda_version_check : Flag<["--"],
 def no_cuda_noopt_device_debug : Flag<["--"], "no-cuda-noopt-device-debug">;
 def cuda_path_EQ : Joined<["--"], "cuda-path=">, Group,
   HelpText<"CUDA installation path">;
+def ptxas_path_EQ : Joined<["--"], "ptxas-path=">, Group,
+  HelpText<"Path to ptxas (used for compiling CUDA code)">;
 def fcuda_flush_denormals_to_zero : Flag<["-"], 
"fcuda-flush-denormals-to-zero">,
   Flags<[CC1Option]>, HelpText<"Flush denormal floating point values to zero 
in CUDA device mode.">;
 def fno_cuda_flush_denormals_to_zero : Flag<["-"], 
"fno-cuda-flush-denormals-to-zero">;

Modified: cfe/trunk/lib/Driver/Tools.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/Tools.cpp?rev=289847&r1=289846&r2=289847&view=diff
==
--- cfe/trunk/lib/Driver/Tools.cpp (original)
+++ cfe/trunk/lib/Driver/Tools.cpp Thu Dec 15 12:44:57 2016
@@ -12105,7 +12105,11 @@ void NVPTX::Assembler::ConstructJob(Comp
   for (const auto& A : Args.getAllArgValues(options::OPT_Xcuda_ptxas))
 CmdArgs.push_back(Args.MakeArgString(A));
 
-  const char *Exec = Args.MakeArgString(TC.GetProgramPath("ptxas"));
+  const char *Exec;
+  if (Arg *A = Args.getLastArg(options::OPT_ptxas_path_EQ))
+Exec = A->getValue();
+  else
+Exec = Args.MakeArgString(TC.GetProgramPath("ptxas"));
   C.addCommand(llvm::make_unique(JA, *this, Exec, CmdArgs, Inputs));
 }
 

Added: cfe/trunk/test/Driver/cuda-ptxas-path.cu
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/cuda-ptxas-path.cu?rev=289847&view=auto
==
--- cfe/trunk/test/Driver/cuda-ptxas-path.cu (added)
+++ cfe/trunk/test/Driver/cuda-ptxas-path.cu Thu Dec 15 12:44:57 2016
@@ -0,0 +1,12 @@
+// REQUIRES: clang-driver
+// REQUIRES: x86-registered-target
+// REQUIRES: nvptx-registered-target
+
+// RUN: %clang -### --target=i386-unknown-linux \
+// RUN:   --cuda-path=%S/Inputs/CUDA_80/usr/local/cuda \
+// RUN:   --ptxas-path=/some/path/to/ptxas %s 2>&1 \
+// RUN: | FileCheck %s
+
+// CHECK-NOT: "ptxas"
+// CHECK: "/some/path/to/ptxas"
+// CHECK-SAME: "--gpu-name" "sm_20"


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


[PATCH] D27788: [CUDA] Add --ptxas-path= flag.

2016-12-15 Thread Justin Lebar via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL289847: [CUDA] Add --ptxas-path= flag. (authored by jlebar).

Changed prior to commit:
  https://reviews.llvm.org/D27788?vs=81501&id=81620#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D27788

Files:
  cfe/trunk/include/clang/Driver/Options.td
  cfe/trunk/lib/Driver/Tools.cpp
  cfe/trunk/test/Driver/cuda-ptxas-path.cu


Index: cfe/trunk/include/clang/Driver/Options.td
===
--- cfe/trunk/include/clang/Driver/Options.td
+++ cfe/trunk/include/clang/Driver/Options.td
@@ -425,6 +425,8 @@
 def no_cuda_noopt_device_debug : Flag<["--"], "no-cuda-noopt-device-debug">;
 def cuda_path_EQ : Joined<["--"], "cuda-path=">, Group,
   HelpText<"CUDA installation path">;
+def ptxas_path_EQ : Joined<["--"], "ptxas-path=">, Group,
+  HelpText<"Path to ptxas (used for compiling CUDA code)">;
 def fcuda_flush_denormals_to_zero : Flag<["-"], 
"fcuda-flush-denormals-to-zero">,
   Flags<[CC1Option]>, HelpText<"Flush denormal floating point values to zero 
in CUDA device mode.">;
 def fno_cuda_flush_denormals_to_zero : Flag<["-"], 
"fno-cuda-flush-denormals-to-zero">;
Index: cfe/trunk/test/Driver/cuda-ptxas-path.cu
===
--- cfe/trunk/test/Driver/cuda-ptxas-path.cu
+++ cfe/trunk/test/Driver/cuda-ptxas-path.cu
@@ -0,0 +1,12 @@
+// REQUIRES: clang-driver
+// REQUIRES: x86-registered-target
+// REQUIRES: nvptx-registered-target
+
+// RUN: %clang -### --target=i386-unknown-linux \
+// RUN:   --cuda-path=%S/Inputs/CUDA_80/usr/local/cuda \
+// RUN:   --ptxas-path=/some/path/to/ptxas %s 2>&1 \
+// RUN: | FileCheck %s
+
+// CHECK-NOT: "ptxas"
+// CHECK: "/some/path/to/ptxas"
+// CHECK-SAME: "--gpu-name" "sm_20"
Index: cfe/trunk/lib/Driver/Tools.cpp
===
--- cfe/trunk/lib/Driver/Tools.cpp
+++ cfe/trunk/lib/Driver/Tools.cpp
@@ -12105,7 +12105,11 @@
   for (const auto& A : Args.getAllArgValues(options::OPT_Xcuda_ptxas))
 CmdArgs.push_back(Args.MakeArgString(A));
 
-  const char *Exec = Args.MakeArgString(TC.GetProgramPath("ptxas"));
+  const char *Exec;
+  if (Arg *A = Args.getLastArg(options::OPT_ptxas_path_EQ))
+Exec = A->getValue();
+  else
+Exec = Args.MakeArgString(TC.GetProgramPath("ptxas"));
   C.addCommand(llvm::make_unique(JA, *this, Exec, CmdArgs, Inputs));
 }
 


Index: cfe/trunk/include/clang/Driver/Options.td
===
--- cfe/trunk/include/clang/Driver/Options.td
+++ cfe/trunk/include/clang/Driver/Options.td
@@ -425,6 +425,8 @@
 def no_cuda_noopt_device_debug : Flag<["--"], "no-cuda-noopt-device-debug">;
 def cuda_path_EQ : Joined<["--"], "cuda-path=">, Group,
   HelpText<"CUDA installation path">;
+def ptxas_path_EQ : Joined<["--"], "ptxas-path=">, Group,
+  HelpText<"Path to ptxas (used for compiling CUDA code)">;
 def fcuda_flush_denormals_to_zero : Flag<["-"], "fcuda-flush-denormals-to-zero">,
   Flags<[CC1Option]>, HelpText<"Flush denormal floating point values to zero in CUDA device mode.">;
 def fno_cuda_flush_denormals_to_zero : Flag<["-"], "fno-cuda-flush-denormals-to-zero">;
Index: cfe/trunk/test/Driver/cuda-ptxas-path.cu
===
--- cfe/trunk/test/Driver/cuda-ptxas-path.cu
+++ cfe/trunk/test/Driver/cuda-ptxas-path.cu
@@ -0,0 +1,12 @@
+// REQUIRES: clang-driver
+// REQUIRES: x86-registered-target
+// REQUIRES: nvptx-registered-target
+
+// RUN: %clang -### --target=i386-unknown-linux \
+// RUN:   --cuda-path=%S/Inputs/CUDA_80/usr/local/cuda \
+// RUN:   --ptxas-path=/some/path/to/ptxas %s 2>&1 \
+// RUN: | FileCheck %s
+
+// CHECK-NOT: "ptxas"
+// CHECK: "/some/path/to/ptxas"
+// CHECK-SAME: "--gpu-name" "sm_20"
Index: cfe/trunk/lib/Driver/Tools.cpp
===
--- cfe/trunk/lib/Driver/Tools.cpp
+++ cfe/trunk/lib/Driver/Tools.cpp
@@ -12105,7 +12105,11 @@
   for (const auto& A : Args.getAllArgValues(options::OPT_Xcuda_ptxas))
 CmdArgs.push_back(Args.MakeArgString(A));
 
-  const char *Exec = Args.MakeArgString(TC.GetProgramPath("ptxas"));
+  const char *Exec;
+  if (Arg *A = Args.getLastArg(options::OPT_ptxas_path_EQ))
+Exec = A->getValue();
+  else
+Exec = Args.MakeArgString(TC.GetProgramPath("ptxas"));
   C.addCommand(llvm::make_unique(JA, *this, Exec, CmdArgs, Inputs));
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [clang-tools-extra] r289656 - modernize-use-auto NFC fixes

2016-12-15 Thread Piotr Padlewski via cfe-commits
Sure, I am planning to do so. I just wanted to firstly make all auto's and
the change was small enough that I though you would not mind pushing it
without review.
BTW the same thing in clang needs review: https://reviews.llvm.org/D27767

2016-12-15 17:08 GMT+01:00 Alexander Kornienko :

> For most loop changes here applying modernize-loop-convert would be better
> ;)
>
> On Wed, Dec 14, 2016 at 4:29 PM, Piotr Padlewski via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> Author: prazek
>> Date: Wed Dec 14 09:29:23 2016
>> New Revision: 289656
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=289656&view=rev
>> Log:
>> modernize-use-auto NFC fixes
>>
>> Modified:
>> clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp
>> clang-tools-extra/trunk/clang-apply-replacements/lib/Tooling
>> /ApplyReplacements.cpp
>> clang-tools-extra/trunk/clang-query/Query.cpp
>> clang-tools-extra/trunk/clang-query/QueryParser.cpp
>> clang-tools-extra/trunk/clang-query/tool/ClangQuery.cpp
>> clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/ProType
>> MemberInitCheck.cpp
>> clang-tools-extra/trunk/clang-tidy/cppcoreguidelines/Special
>> MemberFunctionsCheck.cpp
>> clang-tools-extra/trunk/clang-tidy/google/ExplicitConstructo
>> rCheck.cpp
>> clang-tools-extra/trunk/clang-tidy/google/NonConstReferences.cpp
>> clang-tools-extra/trunk/clang-tidy/llvm/TwineLocalCheck.cpp
>> clang-tools-extra/trunk/clang-tidy/misc/ArgumentCommentCheck.cpp
>> clang-tools-extra/trunk/clang-tidy/misc/MoveForwardingRefere
>> nceCheck.cpp
>> clang-tools-extra/trunk/clang-tidy/misc/MultipleStatementMac
>> roCheck.cpp
>> clang-tools-extra/trunk/clang-tidy/misc/ThrowByValueCatchByR
>> eferenceCheck.cpp
>> clang-tools-extra/trunk/clang-tidy/modernize/UseNullptrCheck.cpp
>> clang-tools-extra/trunk/clang-tidy/modernize/UseOverrideCheck.cpp
>> clang-tools-extra/trunk/clang-tidy/mpi/TypeMismatchCheck.cpp
>> clang-tools-extra/trunk/clang-tidy/readability/ImplicitBoolC
>> astCheck.cpp
>> clang-tools-extra/trunk/clang-tidy/readability/NamespaceComm
>> entCheck.cpp
>> clang-tools-extra/trunk/clang-tidy/readability/RedundantDecl
>> arationCheck.cpp
>> clang-tools-extra/trunk/clang-tidy/readability/RedundantSmar
>> tptrGetCheck.cpp
>> clang-tools-extra/trunk/include-fixer/find-all-symbols/
>> FindAllSymbols.cpp
>> clang-tools-extra/trunk/modularize/CoverageChecker.cpp
>> clang-tools-extra/trunk/modularize/Modularize.cpp
>> clang-tools-extra/trunk/modularize/ModularizeUtilities.cpp
>> clang-tools-extra/trunk/modularize/ModuleAssistant.cpp
>> clang-tools-extra/trunk/modularize/PreprocessorTracker.cpp
>> clang-tools-extra/trunk/pp-trace/PPTrace.cpp
>> clang-tools-extra/trunk/unittests/clang-tidy/ClangTidyDiagno
>> sticConsumerTest.cpp
>> clang-tools-extra/trunk/unittests/clang-tidy/NamespaceAliaserTest.cpp
>> clang-tools-extra/trunk/unittests/clang-tidy/UsingInserterTest.cpp
>>
>> Modified: clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp
>> URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/
>> change-namespace/ChangeNamespace.cpp?rev=289656&r1=289655&
>> r2=289656&view=diff
>> 
>> ==
>> --- clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp
>> (original)
>> +++ clang-tools-extra/trunk/change-namespace/ChangeNamespace.cpp Wed Dec
>> 14 09:29:23 2016
>> @@ -709,7 +709,7 @@ void ChangeNamespaceTool::fixTypeLoc(
>>return;
>>}
>>
>> -  const Decl *DeclCtx = Result.Nodes.getNodeAs("dc");
>> +  const auto *DeclCtx = Result.Nodes.getNodeAs("dc");
>>assert(DeclCtx && "Empty decl context.");
>>replaceQualifiedSymbolInDeclContext(Result,
>> DeclCtx->getDeclContext(), Start,
>>End, FromDecl);
>>
>> Modified: clang-tools-extra/trunk/clang-apply-replacements/lib/Tooling
>> /ApplyReplacements.cpp
>> URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/
>> clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp?
>> rev=289656&r1=289655&r2=289656&view=diff
>> 
>> ==
>> --- 
>> clang-tools-extra/trunk/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp
>> (original)
>> +++ 
>> clang-tools-extra/trunk/clang-apply-replacements/lib/Tooling/ApplyReplacements.cpp
>> Wed Dec 14 09:29:23 2016
>> @@ -124,9 +124,7 @@ static void reportConflict(
>>  bool applyAllReplacements(const std::vector
>> &Replaces,
>>Rewriter &Rewrite) {
>>bool Result = true;
>> -  for (std::vector::const_iterator I =
>> Replaces.begin(),
>> - E =
>> Replaces.end();
>> -   I != E; ++I) {
>> +  for (auto I = Replaces.begin(), E = Replaces.end(); I != E; ++I) {
>>  if (I->isApplicable()) {
>>Result = I->apply(Rewrite) &

[PATCH] D27163: Introduce -f[no-]strict-return flag that controls code generation for C++'s undefined behaviour return optimisation

2016-12-15 Thread Mehdi AMINI via Phabricator via cfe-commits
mehdi_amini added inline comments.



Comment at: include/clang/Driver/Options.td:1324
+  HelpText<"Use C++ undefined behaviour optimization for control flow paths"
+ "that reach the end of the function without executing a required return">;
+def fno_strict_return : Flag<["-"], "fno-strict-return">, Group,

Quuxplusone wrote:
> Nit: looks like Clang spells it "behavior"?
> 
> Nit: I'm still pedantically uncomfortable with describing the strict-return 
> behavior as an "optimization". I suggest rephrasing this as "-fstrict-return: 
> Treat control flow paths that fall off the end of a non-void function as 
> unreachable."
> 
> (I notice that neither -fstrict-aliasing nor -fstrict-overflow have any help 
> text at all.)
>  I suggest rephrasing this as "-fstrict-return: Treat control flow paths that 
> fall off the end of a non-void function as unreachable."

Is it an accurate description? `-fno-strict-return` would only disable this for 
trivial types.


Repository:
  rL LLVM

https://reviews.llvm.org/D27163



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


[PATCH] D27796: Fix printf specifier handling: invalid specifier should not be marked as "consuming data arguments"

2016-12-15 Thread Bruno Cardoso Lopes via Phabricator via cfe-commits
bruno accepted this revision.
bruno added a comment.
This revision is now accepted and ready to land.

LGTM


https://reviews.llvm.org/D27796



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


r289850 - Fix printf specifier handling: invalid specifier should not be marked as "consuming data arguments"

2016-12-15 Thread Mehdi Amini via cfe-commits
Author: mehdi_amini
Date: Thu Dec 15 12:54:00 2016
New Revision: 289850

URL: http://llvm.org/viewvc/llvm-project?rev=289850&view=rev
Log:
Fix printf specifier handling: invalid specifier should not be marked as 
"consuming data arguments"

Reviewers: rsmith, bruno, dexonsmith

Subscribers: cfe-commits

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

Modified:
cfe/trunk/include/clang/Analysis/Analyses/FormatString.h
cfe/trunk/test/CodeGen/builtins.c
cfe/trunk/test/Sema/format-strings.c
cfe/trunk/test/SemaObjC/format-strings-objc.m

Modified: cfe/trunk/include/clang/Analysis/Analyses/FormatString.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Analysis/Analyses/FormatString.h?rev=289850&r1=289849&r2=289850&view=diff
==
--- cfe/trunk/include/clang/Analysis/Analyses/FormatString.h (original)
+++ cfe/trunk/include/clang/Analysis/Analyses/FormatString.h Thu Dec 15 
12:54:00 2016
@@ -211,6 +211,8 @@ public:
 return false;
   case PercentArg:
 return false;
+  case InvalidSpecifier:
+return false;
   default:
 return true;
 }

Modified: cfe/trunk/test/CodeGen/builtins.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/builtins.c?rev=289850&r1=289849&r2=289850&view=diff
==
--- cfe/trunk/test/CodeGen/builtins.c (original)
+++ cfe/trunk/test/CodeGen/builtins.c Thu Dec 15 12:54:00 2016
@@ -538,6 +538,34 @@ void test_builtin_os_log_precision_width
   __builtin_os_log_format(buf, "Hello %*.*s World", precision, width, data);
 }
 
+// CHECK-LABEL: define void @test_builtin_os_log_invalid
+// CHECK: (i8* [[BUF:%.*]], i32 [[DATA:%.*]])
+void test_builtin_os_log_invalid(void *buf, int data) {
+  volatile int len;
+  // CHECK: store i8* [[BUF]], i8** [[BUF_ADDR:%.*]], align 8
+  // CHECK: store i32 [[DATA]], i32* [[DATA_ADDR:%.*]]
+
+  // CHECK: store volatile i32 8,
+  len = __builtin_os_log_format_buffer_size("invalid specifier %: %d even a 
trailing one%", data);
+
+  // CHECK: [[BUF2:%.*]] = load i8*, i8** [[BUF_ADDR]]
+  // CHECK: [[SUMMARY:%.*]] = getelementptr i8, i8* [[BUF2]], i64 0
+  // CHECK: store i8 0, i8* [[SUMMARY]]
+  // CHECK: [[NUM_ARGS:%.*]] = getelementptr i8, i8* [[BUF2]], i64 1
+  // CHECK: store i8 1, i8* [[NUM_ARGS]]
+
+  // CHECK: [[ARG1_DESC:%.*]] = getelementptr i8, i8* [[BUF2]], i64 2
+  // CHECK: store i8 0, i8* [[ARG1_DESC]]
+  // CHECK: [[ARG1_SIZE:%.*]] = getelementptr i8, i8* [[BUF2]], i64 3
+  // CHECK: store i8 4, i8* [[ARG1_SIZE]]
+  // CHECK: [[ARG1:%.*]] = getelementptr i8, i8* [[BUF2]], i64 4
+  // CHECK: [[ARG1_INT:%.*]] = bitcast i8* [[ARG1]] to i32*
+  // CHECK: [[ARG1_VAL:%.*]] = load i32, i32* [[DATA_ADDR]]
+  // CHECK: store i32 [[ARG1_VAL]], i32* [[ARG1_INT]]
+
+  __builtin_os_log_format(buf, "invalid specifier %: %d even a trailing one%", 
data);
+}
+
 // CHECK-LABEL: define void @test_builtin_os_log_percent
 // CHECK: (i8* [[BUF:%.*]], i8* [[DATA1:%.*]], i8* [[DATA2:%.*]])
 // Check that the %% which does not consume any argument is correctly handled

Modified: cfe/trunk/test/Sema/format-strings.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/format-strings.c?rev=289850&r1=289849&r2=289850&view=diff
==
--- cfe/trunk/test/Sema/format-strings.c (original)
+++ cfe/trunk/test/Sema/format-strings.c Thu Dec 15 12:54:00 2016
@@ -156,10 +156,10 @@ void check_writeback_specifier()
 
 void check_invalid_specifier(FILE* fp, char *buf)
 {
-  printf("%s%lb%d","unix",10,20); // expected-warning {{invalid conversion 
specifier 'b'}}
+  printf("%s%lb%d","unix",10,20); // expected-warning {{invalid conversion 
specifier 'b'}} expected-warning {{data argument not used by format string}}
   fprintf(fp,"%%%l"); // expected-warning {{incomplete format specifier}}
   sprintf(buf,"%ld%d%d", 1, 2, 3); // expected-warning{{format specifies 
type 'long' but the argument has type 'int'}}
-  snprintf(buf, 2, "%ld%;%d", 1, 2, 3); // expected-warning{{format 
specifies type 'long' but the argument has type 'int'}} expected-warning 
{{invalid conversion specifier ';'}}
+  snprintf(buf, 2, "%ld%;%d", 1, 2, 3); // expected-warning{{format 
specifies type 'long' but the argument has type 'int'}} expected-warning 
{{invalid conversion specifier ';'}} expected-warning {{data argument not used 
by format string}}
 }
 
 void check_null_char_string(char* b)
@@ -251,7 +251,7 @@ void test10(int x, float f, int i, long
   printf("%**\n"); // expected-warning{{invalid conversion specifier '*'}}
   printf("%d%d\n", x); // expected-warning{{more '%' conversions than data 
arguments}}
   printf("%d\n", x, x); // expected-warning{{data argument not used by format 
string}}
-  printf("%W%d\n", x, x); // expected-warning{{invalid conversion specifier 
'W'}}
+  printf(

Re: [libcxx] r286789 - Add check-cxx-abilist target when supported.

2016-12-15 Thread Chris Bieneman via cfe-commits
(+Bogner, I think he originally added this)

My understanding is that we only did this copy step if you are building with a 
clang that isn't installed so that the non-installed clang could find these 
headers.

I'm pretty sure compiler-rt finds libcxx via the sources, not the build 
directory.

I'll put together a fix later today.

-Chris

> On Dec 14, 2016, at 11:49 PM, Eric Fiselier  wrote:
> 
>  
> Eric, this part of this change seems wrong to me. It causes the headers to be 
> installed into the libcxx build directory instead of the LLVM one. If you 
> build using the LLVM runtimes directory this puts the headers in the wrong 
> place for clang to find them.
> 
> Is there a reason you're copying them into the libcxx binary dir? I generally 
> don't think the headers are needed there.
> 
> 
> If it seems wrong for building in the LLVM runtimes directory then it 
> probably is. I don't think there is a good reason why we need to copy the 
> headers into the build directory, although we should double check compiler-rt 
> uses the headers from the source directory.
> 
> If you know how to fix this feel free to commit a patch. If not I'll look 
> into this more on Friday.
> 
> @Dan, @Jonathan: Do you guys use, or see a need for, this behavior?
> 

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


[PATCH] D27796: Fix printf specifier handling: invalid specifier should not be marked as "consuming data arguments"

2016-12-15 Thread Mehdi AMINI via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL289850: Fix printf specifier handling: invalid specifier 
should not be marked as… (authored by mehdi_amini).

Changed prior to commit:
  https://reviews.llvm.org/D27796?vs=81532&id=81621#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D27796

Files:
  cfe/trunk/include/clang/Analysis/Analyses/FormatString.h
  cfe/trunk/test/CodeGen/builtins.c
  cfe/trunk/test/Sema/format-strings.c
  cfe/trunk/test/SemaObjC/format-strings-objc.m


Index: cfe/trunk/include/clang/Analysis/Analyses/FormatString.h
===
--- cfe/trunk/include/clang/Analysis/Analyses/FormatString.h
+++ cfe/trunk/include/clang/Analysis/Analyses/FormatString.h
@@ -211,6 +211,8 @@
 return false;
   case PercentArg:
 return false;
+  case InvalidSpecifier:
+return false;
   default:
 return true;
 }
Index: cfe/trunk/test/Sema/format-strings.c
===
--- cfe/trunk/test/Sema/format-strings.c
+++ cfe/trunk/test/Sema/format-strings.c
@@ -156,10 +156,10 @@
 
 void check_invalid_specifier(FILE* fp, char *buf)
 {
-  printf("%s%lb%d","unix",10,20); // expected-warning {{invalid conversion 
specifier 'b'}}
+  printf("%s%lb%d","unix",10,20); // expected-warning {{invalid conversion 
specifier 'b'}} expected-warning {{data argument not used by format string}}
   fprintf(fp,"%%%l"); // expected-warning {{incomplete format specifier}}
   sprintf(buf,"%ld%d%d", 1, 2, 3); // expected-warning{{format specifies 
type 'long' but the argument has type 'int'}}
-  snprintf(buf, 2, "%ld%;%d", 1, 2, 3); // expected-warning{{format 
specifies type 'long' but the argument has type 'int'}} expected-warning 
{{invalid conversion specifier ';'}}
+  snprintf(buf, 2, "%ld%;%d", 1, 2, 3); // expected-warning{{format 
specifies type 'long' but the argument has type 'int'}} expected-warning 
{{invalid conversion specifier ';'}} expected-warning {{data argument not used 
by format string}}
 }
 
 void check_null_char_string(char* b)
@@ -251,7 +251,7 @@
   printf("%**\n"); // expected-warning{{invalid conversion specifier '*'}}
   printf("%d%d\n", x); // expected-warning{{more '%' conversions than data 
arguments}}
   printf("%d\n", x, x); // expected-warning{{data argument not used by format 
string}}
-  printf("%W%d\n", x, x); // expected-warning{{invalid conversion specifier 
'W'}}
+  printf("%W%d\n", x, x); // expected-warning{{invalid conversion specifier 
'W'}}  expected-warning {{data argument not used by format string}}
   printf("%"); // expected-warning{{incomplete format specifier}}
   printf("%.d", x); // no-warning
   printf("%.", x);  // expected-warning{{incomplete format specifier}}
@@ -270,7 +270,7 @@
   printf("%.0Lf", (long double) 1.0); // no-warning
   printf("%c\n", "x"); // expected-warning{{format specifies type 'int' but 
the argument has type 'char *'}}
   printf("%c\n", 1.23); // expected-warning{{format specifies type 'int' but 
the argument has type 'double'}}
-  printf("Format %d, is %! %f", 1, 2, 4.4); // expected-warning{{invalid 
conversion specifier '!'}}
+  printf("Format %d, is %! %f", 1, 4.4); // expected-warning{{invalid 
conversion specifier '!'}}
 }
 
 typedef unsigned char uint8_t;
Index: cfe/trunk/test/SemaObjC/format-strings-objc.m
===
--- cfe/trunk/test/SemaObjC/format-strings-objc.m
+++ cfe/trunk/test/SemaObjC/format-strings-objc.m
@@ -47,7 +47,7 @@
 
 void check_nslog(unsigned k) {
   NSLog(@"%d%%", k); // no-warning
-  NSLog(@"%s%lb%d", "unix", 10,20); // expected-warning {{invalid conversion 
specifier 'b'}}
+  NSLog(@"%s%lb%d", "unix", 10, 20); // expected-warning {{invalid conversion 
specifier 'b'}} expected-warning {{data argument not used by format string}}
 }
 
 // Check type validation
Index: cfe/trunk/test/CodeGen/builtins.c
===
--- cfe/trunk/test/CodeGen/builtins.c
+++ cfe/trunk/test/CodeGen/builtins.c
@@ -538,6 +538,34 @@
   __builtin_os_log_format(buf, "Hello %*.*s World", precision, width, data);
 }
 
+// CHECK-LABEL: define void @test_builtin_os_log_invalid
+// CHECK: (i8* [[BUF:%.*]], i32 [[DATA:%.*]])
+void test_builtin_os_log_invalid(void *buf, int data) {
+  volatile int len;
+  // CHECK: store i8* [[BUF]], i8** [[BUF_ADDR:%.*]], align 8
+  // CHECK: store i32 [[DATA]], i32* [[DATA_ADDR:%.*]]
+
+  // CHECK: store volatile i32 8,
+  len = __builtin_os_log_format_buffer_size("invalid specifier %: %d even a 
trailing one%", data);
+
+  // CHECK: [[BUF2:%.*]] = load i8*, i8** [[BUF_ADDR]]
+  // CHECK: [[SUMMARY:%.*]] = getelementptr i8, i8* [[BUF2]], i64 0
+  // CHECK: store i8 0, i8* [[SUMMARY]]
+  // CHECK: [[NUM_ARGS:%.*]] = getelementptr i8, i8* [[BUF2]], i64 1
+  // CHECK: store i8 1, i8* [[NUM_ARGS]]
+
+  // CHECK: [[

[PATCH] D27740: [analyzer] Include type name in Retain Count Checker diagnostics

2016-12-15 Thread Devin Coughlin via Phabricator via cfe-commits
dcoughlin accepted this revision.
dcoughlin added a comment.
This revision is now accepted and ready to land.

LGTM.


https://reviews.llvm.org/D27740



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


[PATCH] D27600: [analyzer] Refine the diagnostics in the nullability checker to differentiate between nil and null

2016-12-15 Thread Devin Coughlin via Phabricator via cfe-commits
dcoughlin accepted this revision.
dcoughlin added a comment.
This revision is now accepted and ready to land.

Looks good.

While you are here, you might consider changing: the checkBind() diagnostic to 
match the other diagnostics:

"Null assigned to a pointer which is expected to have non-null value" --> "Null 
assigned to a pointer which is expected to have *a* non-null value"


https://reviews.llvm.org/D27600



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


[PATCH] D27210: [clang-tidy] misc-string-compare. Adding a new check to clang-tidy

2016-12-15 Thread Piotr Padlewski via Phabricator via cfe-commits
Prazek added a comment.

Good job.
I think it is resonable to warn in cases like:

  if (str.compare(str2) == 1)

or even

  if(str.compare(str2) == -1)

Sometimes people check for 1 or -1 instead of > 0 and < 0. If I remember 
corectly PVS studio found some bugs like this.




Comment at: clang-tidy/misc/StringCompareCheck.cpp:27
+   hasName("::std::basic_string"),
+  hasArgument(0, declRefExpr()), callee(memberExpr()));
+

malcolm.parsons wrote:
> I don't think you need to check what the first argument is.
+1, just check if you are calling function with 1 argument.
you can still use hasArgument(0, expr().bind("str2")) to bind argument



Comment at: clang-tidy/misc/StringCompareCheck.cpp:25
+return;
+  const auto strCompare = cxxMemberCallExpr(
+  callee(cxxMethodDecl(hasName("compare"),

Start with upper case


https://reviews.llvm.org/D27210



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


[PATCH] D27806: [clang-tidy] Add obvious-invalid-range

2016-12-15 Thread Malcolm Parsons via Phabricator via cfe-commits
malcolm.parsons added inline comments.



Comment at: docs/clang-tidy/checks/list.rst:68
misc-inefficient-algorithm
+   misc-invalid-range
misc-macro-parentheses

Prazek wrote:
> malcolm.parsons wrote:
> > misc.
> > add_new_check.py can fix it.
> How? I added new check with this script, but unfortunatelly rename_check 
> doesn't move check from module to module, so I have to make all the changes 
> by hand.
add_new_check.py --update-docs


https://reviews.llvm.org/D27806



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


[PATCH] D27812: [test] Extend llvm_shlib_dir fix to unittests

2016-12-15 Thread Chris Bieneman via Phabricator via cfe-commits
beanz accepted this revision.
beanz added a comment.
This revision is now accepted and ready to land.

Looks reasonable to me.


https://reviews.llvm.org/D27812



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


[PATCH] D27806: [clang-tidy] Add obvious-invalid-range

2016-12-15 Thread Piotr Padlewski via Phabricator via cfe-commits
Prazek added inline comments.



Comment at: docs/clang-tidy/checks/list.rst:68
misc-inefficient-algorithm
+   misc-invalid-range
misc-macro-parentheses

malcolm.parsons wrote:
> Prazek wrote:
> > malcolm.parsons wrote:
> > > misc.
> > > add_new_check.py can fix it.
> > How? I added new check with this script, but unfortunatelly rename_check 
> > doesn't move check from module to module, so I have to make all the changes 
> > by hand.
> add_new_check.py --update-docs
Didn't know about it, cool


https://reviews.llvm.org/D27806



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


[PATCH] D27821: [OpenMP] support is_device_ptr clause with 'target parallel' pragma

2016-12-15 Thread Kelvin Li via Phabricator via cfe-commits
kkwli0 created this revision.
kkwli0 added reviewers: ABataev, hfinkel, carlo.bertolli, sfantao, 
arpith-jacob, mikerice.
kkwli0 added a subscriber: cfe-commits.

This patch is to add support of the 'is_device_ptr' clause in the 'target 
parallel' pragma.


https://reviews.llvm.org/D27821

Files:
  include/clang/Basic/OpenMPKinds.def
  lib/Sema/SemaOpenMP.cpp
  test/OpenMP/target_parallel_is_device_ptr_ast_print.cpp
  test/OpenMP/target_parallel_is_device_ptr_messages.cpp

Index: test/OpenMP/target_parallel_is_device_ptr_messages.cpp
===
--- /dev/null
+++ test/OpenMP/target_parallel_is_device_ptr_messages.cpp
@@ -0,0 +1,268 @@
+// RUN: %clang_cc1 -std=c++11 -verify -fopenmp -ferror-limit 200 %s
+struct ST {
+  int *a;
+};
+typedef int arr[10];
+typedef ST STarr[10];
+struct SA {
+  const int d = 5;
+  const int da[5] = { 0 };
+  ST e;
+  ST g[10];
+  STarr &rg = g;
+  int i;
+  int &j = i;
+  int *k = &j;
+  int *&z = k;
+  int aa[10];
+  arr &raa = aa;
+  void func(int arg) {
+#pragma omp target parallel is_device_ptr // expected-error {{expected '(' after 'is_device_ptr'}}
+{}
+#pragma omp target parallel is_device_ptr( // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error {{expected expression}}
+{}
+#pragma omp target parallel is_device_ptr() // expected-error {{expected expression}}
+{}
+#pragma omp target parallel is_device_ptr(alloc) // expected-error {{use of undeclared identifier 'alloc'}}
+{}
+#pragma omp target parallel is_device_ptr(arg // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error {{expected pointer, array, reference to pointer, or reference to array in 'is_device_ptr clause'}}
+{}
+#pragma omp target parallel is_device_ptr(i) // expected-error {{expected pointer, array, reference to pointer, or reference to array in 'is_device_ptr clause'}}
+{}
+#pragma omp target parallel is_device_ptr(j) // expected-error {{expected pointer, array, reference to pointer, or reference to array in 'is_device_ptr clause'}}
+{}
+#pragma omp target parallel is_device_ptr(k) // OK
+{}
+#pragma omp target parallel is_device_ptr(z) // OK
+{}
+#pragma omp target parallel is_device_ptr(aa) // OK
+{}
+#pragma omp target parallel is_device_ptr(raa) // OK
+{}
+#pragma omp target parallel is_device_ptr(e) // expected-error{{expected pointer, array, reference to pointer, or reference to array in 'is_device_ptr clause'}}
+{}
+#pragma omp target parallel is_device_ptr(g) // OK
+{}
+#pragma omp target parallel is_device_ptr(rg) // OK
+{}
+#pragma omp target parallel is_device_ptr(k,i,j) // expected-error2 {{expected pointer, array, reference to pointer, or reference to array in 'is_device_ptr clause'}}
+{}
+#pragma omp target parallel is_device_ptr(d) // expected-error{{expected pointer, array, reference to pointer, or reference to array in 'is_device_ptr clause'}}
+{}
+#pragma omp target parallel is_device_ptr(da) // OK
+{}
+  return;
+ }
+};
+struct SB {
+  unsigned A;
+  unsigned B;
+  float Arr[100];
+  float *Ptr;
+  float *foo() {
+return &Arr[0];
+  }
+};
+
+struct SC {
+  unsigned A : 2;
+  unsigned B : 3;
+  unsigned C;
+  unsigned D;
+  float Arr[100];
+  SB S;
+  SB ArrS[100];
+  SB *PtrS;
+  SB *&RPtrS;
+  float *Ptr;
+
+  SC(SB *&_RPtrS) : RPtrS(_RPtrS) {}
+};
+
+union SD {
+  unsigned A;
+  float B;
+};
+
+struct S1;
+extern S1 a;
+class S2 {
+  mutable int a;
+public:
+  S2():a(0) { }
+  S2(S2 &s2):a(s2.a) { }
+  static float S2s;
+  static const float S2sc;
+};
+const float S2::S2sc = 0;
+const S2 b;
+const S2 ba[5];
+class S3 {
+  int a;
+public:
+  S3():a(0) { }
+  S3(S3 &s3):a(s3.a) { }
+};
+const S3 c;
+const S3 ca[5];
+extern const int f;
+class S4 {
+  int a;
+  S4();
+  S4(const S4 &s4);
+public:
+  S4(int v):a(v) { }
+};
+class S5 {
+  int a;
+  S5():a(0) {}
+  S5(const S5 &s5):a(s5.a) { }
+public:
+  S5(int v):a(v) { }
+};
+
+S3 h;
+#pragma omp threadprivate(h)
+
+typedef struct {
+  int a;
+} S6;
+
+template 
+T tmain(T argc) {
+  const T d = 5;
+  const T da[5] = { 0 };
+  S4 e(4);
+  S5 g(5);
+  S6 h[10];
+  auto &rh = h;
+  T i;
+  T &j = i;
+  T *k = &j;
+  T *&z = k;
+  T aa[10];
+  auto &raa = aa;
+  S6 *ps;
+#pragma omp target parallel is_device_ptr // expected-error {{expected '(' after 'is_device_ptr'}}
+  {}
+#pragma omp target parallel is_device_ptr( // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error {{expected expression}}
+  {}
+#pragma omp target parallel is_device_ptr() // expected-error {{expected expression}}
+  {}
+#pragma omp target parallel is_device_ptr(alloc) // expected-error {{use of undeclared identifier 'alloc'}}
+  {}
+#pragma omp target parallel is_device_ptr(argc // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error{{expected pointer, array, reference to pointer, or reference to array in 'is_device

  1   2   >