[PATCH] D41326: [clang-tidy] Added diagnostics about incorrect usage of NOLINT comment

2018-01-07 Thread Anton via Phabricator via cfe-commits
xgsa updated this revision to Diff 128893.
xgsa added a comment.

Fixed showing the check in -list-checks.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41326

Files:
  clang-tidy/ClangTidy.cpp
  clang-tidy/ClangTidyDiagnosticConsumer.cpp
  clang-tidy/ClangTidyDiagnosticConsumer.h
  test/clang-tidy/nolint.cpp
  test/clang-tidy/nolintnextline.cpp
  test/clang-tidy/readability-nolint-usage.cpp

Index: test/clang-tidy/readability-nolint-usage.cpp
===
--- /dev/null
+++ test/clang-tidy/readability-nolint-usage.cpp
@@ -0,0 +1,171 @@
+// RUN: %check_clang_tidy %s readability-nolint-usage,google-explicit-constructor,misc-unused-parameters %t --
+
+// Case: NO_LINT on line with an error.
+class A1 { A1(int i); }; // NOLINT
+
+// Case: NO_LINT on line without errors.
+class A2 { explicit A2(int i); }; // NOLINT
+// CHECK-MESSAGES: :[[@LINE-1]]:38: warning: there are no diagnostics on this line
+
+// Case: NO_LINT for the specific check on line with an error on it.
+class A3 { A3(int i); }; // NOLINT(google-explicit-constructor)
+
+// Case: NO_LINT for the specific check on line with an error on another check.
+class A4 { A4(int i); }; // NOLINT(misc-unused-parameters)
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: single-argument constructors must be marked explicit
+// CHECK-MESSAGES: :[[@LINE-2]]:29: warning: there are no diagnostics for 'misc-unused-parameters' on this line
+
+// Case: NO_LINT for the specific check on line without errors.
+class A5 { explicit A5(int i); }; // NOLINT(google-explicit-constructor)
+// CHECK-MESSAGES: :[[@LINE-1]]:38: warning: there are no diagnostics for 'google-explicit-constructor' on this line
+
+// Case: NO_LINT for unknown check on line with an error on some check.
+class A6 { A6(int i); }; // NOLINT(unknown-check)
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: single-argument constructors must be marked explicit
+// CHECK-MESSAGES: :[[@LINE-2]]:29: warning: unknown check name 'unknown-check' specified in NOLINT comment
+
+// Case: NO_LINT for unknown check on line without errors.
+class A7 { explicit A7(int i); }; // NOLINT(unknown-check)
+// CHECK-MESSAGES: :[[@LINE-1]]:38: warning: unknown check name 'unknown-check' specified in NOLINT comment
+
+// Case: NO_LINT with not closed parenthesis without check names.
+class A8 { A8(int i); }; // NOLINT(
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: unbalanced parentheses in NOLINT comment; all diagnostics silenced for this line
+
+// Case: NO_LINT with not closed parenthesis with check names.
+class A9 { A9(int i); }; // NOLINT(unknown-check
+// CHECK-MESSAGES: :[[@LINE-1]]:29: warning: unbalanced parentheses in NOLINT comment; all diagnostics silenced for this line
+
+// Case: NO_LINT with clang diagnostics
+int f() {
+  int i = 0; // NOLINT
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: there are no diagnostics on this line
+  int j = 0; // NOLINT(clang-diagnostic-unused-variable)
+// CHECK-MESSAGES: :[[@LINE-1]]:17: warning: there are no diagnostics for 'clang-diagnostic-unused-variable' on this line
+  return i + j;
+}
+
+#define MACRO(X) class X { explicit X(int i); };
+
+// Case: NO_LINT on macro instantiation line
+MACRO(M1) // NOLINT
+// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: there are no diagnostics on this line
+
+// Case: NO_LINT with the specific check on macro instantiation line
+MACRO(M2) // NOLINT(google-explicit-constructor)
+// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: there are no diagnostics for 'google-explicit-constructor' on this line
+
+// Case: NO_LINT on macro line
+#define MACRO2(X) class X { explicit X(int i); }; // NOLINT
+MACRO2(M3)
+// CHECK-MESSAGES: :[[@LINE-2]]:54: warning: there are no diagnostics on this line
+
+// Case: NO_LINT with the specific check on macro line
+#define MACRO3(X) class X { explicit X(int i); }; // NOLINT(google-explicit-constructor)
+MACRO(M4)
+// CHECK-MESSAGES: :[[@LINE-2]]:54: warning: there are no diagnostics for 'google-explicit-constructor' on this line
+
+// Case: NO_LINT with readability-nolint-usage on line without errors.
+class B1 { explicit B1(int i); }; // NOLINT(readability-nolint-usage)
+
+// Case: NO_LINT with the specific check and readability-nolint-usage on line without errors.
+class B2 { explicit B2(int i); }; // NOLINT(google-explicit-constructor, readability-nolint-usage)
+
+// Case: NO_LINT with the unknown check and readability-nolint-usage on line without errors.
+class B3 { explicit B3(int i); }; // NOLINT(unknown-check, readability-nolint-usage)
+
+
+// Case: NO_LINT_NEXT_LINE before line with an error.
+// NOLINTNEXTLINE
+class C1 { C1(int i); };
+
+// Case: NO_LINT_NEXT_LINE before line without errors.
+// NOLINTNEXTLINE
+class C2 { explicit C2(int i); };
+// CHECK-MESSAGES: :[[@LINE-2]]:4: warning: there are no diagnostics on the next line
+
+// Case: NO_LINT_NEXT_LINE for the specific check before line with an error on it.
+// 

Re: [libcxx] r321937 - Correct mistake in pragma usage for Windows

2018-01-07 Thread Shoaib Meenai via cfe-commits
Hah, we all missed this during review.

From: cfe-commits  on behalf of Saleem 
Abdulrasool via cfe-commits 
Reply-To: Saleem Abdulrasool 
Date: Saturday, January 6, 2018 at 10:48 AM
To: "cfe-commits@lists.llvm.org" 
Subject: [libcxx] r321937 - Correct mistake in pragma usage for Windows

Author: compnerd
Date: Sat Jan  6 10:47:03 2018
New Revision: 321937

URL: 
https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject-3Frev-3D321937-26view-3Drev=DwIGaQ=5VD0RTtNlTh3ycd41b3MUw=o3kDXzdBUE3ljQXKeTWOMw=AGe8lTmLFGMlGPm9sLEnF6Id8r0AU2mMf23PCSg_Z-A=0Lbt7xk05gsFMXV9JaPHaAuJKJNPL2uAMqa8KGVB0Zc=
Log:
Correct mistake in pragma usage for Windows

The autolink pragma was missing the pragma name itself.  This would
result in the pragma being silently dropped.

Modified:
libcxx/trunk/include/__config

Modified: libcxx/trunk/include/__config
URL: 
https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_libcxx_trunk_include_-5F-5Fconfig-3Frev-3D321937-26r1-3D321936-26r2-3D321937-26view-3Ddiff=DwIGaQ=5VD0RTtNlTh3ycd41b3MUw=o3kDXzdBUE3ljQXKeTWOMw=AGe8lTmLFGMlGPm9sLEnF6Id8r0AU2mMf23PCSg_Z-A=XCRMWiLWYMeL6yqcmwRIbUGdeeQ4izrIJs4X9733ddA=
==
--- libcxx/trunk/include/__config (original)
+++ libcxx/trunk/include/__config Sat Jan  6 10:47:03 2018
@@ -1278,9 +1278,9 @@ _LIBCPP_FUNC_VIS extern "C" void __sanit
#if defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_BUILDING_LIBRARY)
# if defined(_DLL)
-#   pragma(lib, "c++.lib")
+#   pragma comment(lib, "c++.lib")
# else
-#   pragma(lib, "libc++.lib")
+#   pragma comment(lib, "libc++.lib")
# endif
#endif // defined(_LIBCPP_ABI_MICROSOFT) && !defined(_LIBCPP_BUILDING_LIBRARY)


___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://urldefense.proofpoint.com/v2/url?u=http-3A__lists.llvm.org_cgi-2Dbin_mailman_listinfo_cfe-2Dcommits=DwIGaQ=5VD0RTtNlTh3ycd41b3MUw=o3kDXzdBUE3ljQXKeTWOMw=AGe8lTmLFGMlGPm9sLEnF6Id8r0AU2mMf23PCSg_Z-A=1QAEIzWyLnmjbZXGswXGKna_StGDQ_8ZWCXJcv9b-2g=

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


r321977 - Remove bogus check for template specialization from self-comparison warning.

2018-01-07 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Sun Jan  7 14:25:55 2018
New Revision: 321977

URL: http://llvm.org/viewvc/llvm-project?rev=321977=rev
Log:
Remove bogus check for template specialization from self-comparison warning.

The important check is that we're not within a template *instantiation*, which
we check separately.

Modified:
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/test/SemaCXX/self-comparison.cpp

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=321977=321976=321977=diff
==
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Sun Jan  7 14:25:55 2018
@@ -9300,16 +9300,6 @@ QualType Sema::CheckShiftOperands(ExprRe
   return LHSType;
 }
 
-static bool IsWithinTemplateSpecialization(Decl *D) {
-  if (DeclContext *DC = D->getDeclContext()) {
-if (isa(DC))
-  return true;
-if (FunctionDecl *FD = dyn_cast(DC))
-  return FD->isFunctionTemplateSpecialization();
-  }
-  return false;
-}
-
 /// If two different enums are compared, raise a warning.
 static void checkEnumComparison(Sema , SourceLocation Loc, Expr *LHS,
 Expr *RHS) {
@@ -9621,14 +9611,13 @@ static void diagnoseTautologicalComparis
   //
   // NOTE: Don't warn about comparison expressions resulting from macro
   // expansion. Also don't warn about comparisons which are only self
-  // comparisons within a template specialization. The warnings should catch
+  // comparisons within a template instantiation. The warnings should catch
   // obvious cases in the definition of the template anyways. The idea is to
   // warn when the typed comparison operator will always evaluate to the same
   // result.
   ValueDecl *DL = getCompareDecl(LHSStripped);
   ValueDecl *DR = getCompareDecl(RHSStripped);
-  if (DL && DR && declaresSameEntity(DL, DR) &&
-  !IsWithinTemplateSpecialization(DL)) {
+  if (DL && DR && declaresSameEntity(DL, DR)) {
 StringRef Result;
 switch (Opc) {
 case BO_EQ: case BO_LE: case BO_GE:

Modified: cfe/trunk/test/SemaCXX/self-comparison.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/self-comparison.cpp?rev=321977=321976=321977=diff
==
--- cfe/trunk/test/SemaCXX/self-comparison.cpp (original)
+++ cfe/trunk/test/SemaCXX/self-comparison.cpp Sun Jan  7 14:25:55 2018
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fsyntax-only -verify %s -std=c++2a
 
 int foo(int x) {
   return x == x; // expected-warning {{self-comparison always evaluates to 
true}}
@@ -25,3 +25,18 @@ struct A {
 namespace NA { extern "C" int x[3]; }
 namespace NB { extern "C" int x[3]; }
 bool k = NA::x == NB::x; // expected-warning {{self-comparison always 
evaluates to true}}
+
+template struct Y { static inline int n; };
+bool f() {
+  return
+Y::n == Y::n || // expected-warning {{self-comparison always 
evaluates to true}}
+Y::n == Y::n;
+}
+template
+bool g() {
+  // FIXME: Ideally we'd produce a self-comparison warning on the first of 
these.
+  return
+Y::n == Y::n ||
+Y::n == Y::n;
+}
+template bool g(); // should not produce any warnings


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


r321976 - Fix a couple of wrong self-comparison diagnostics.

2018-01-07 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Sun Jan  7 14:18:05 2018
New Revision: 321976

URL: http://llvm.org/viewvc/llvm-project?rev=321976=rev
Log:
Fix a couple of wrong self-comparison diagnostics.

Check whether we are comparing the same entity, not merely the same
declaration, and don't assume that weak declarations resolve to distinct
entities.

Modified:
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/test/Sema/self-comparison.c
cfe/trunk/test/SemaCXX/self-comparison.cpp

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=321976=321975=321976=diff
==
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Sun Jan  7 14:18:05 2018
@@ -9627,7 +9627,8 @@ static void diagnoseTautologicalComparis
   // result.
   ValueDecl *DL = getCompareDecl(LHSStripped);
   ValueDecl *DR = getCompareDecl(RHSStripped);
-  if (DL && DR && DL == DR && !IsWithinTemplateSpecialization(DL)) {
+  if (DL && DR && declaresSameEntity(DL, DR) &&
+  !IsWithinTemplateSpecialization(DL)) {
 StringRef Result;
 switch (Opc) {
 case BO_EQ: case BO_LE: case BO_GE:
@@ -9648,10 +9649,9 @@ static void diagnoseTautologicalComparis
   << Result);
   } else if (DL && DR && LHSType->isArrayType() && RHSType->isArrayType() &&
  !DL->getType()->isReferenceType() &&
- !DR->getType()->isReferenceType()) {
+ !DR->getType()->isReferenceType() &&
+ !DL->isWeak() && !DR->isWeak()) {
 // What is it always going to evaluate to?
-// FIXME: This is wrong if DL and DR are different Decls for the same
-// entity. It's also wrong if DL and/or DR are weak declarations.
 StringRef Result;
 switch(Opc) {
 case BO_EQ: // e.g. array1 == array2

Modified: cfe/trunk/test/Sema/self-comparison.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/self-comparison.c?rev=321976=321975=321976=diff
==
--- cfe/trunk/test/Sema/self-comparison.c (original)
+++ cfe/trunk/test/Sema/self-comparison.c Sun Jan  7 14:18:05 2018
@@ -86,3 +86,8 @@ int R8435950(int i) {
   return 1;
 }
 
+__attribute__((weak)) int weak_1[3];
+__attribute__((weak)) int weak_2[3];
+_Bool compare_weak() {
+  return weak_1 == weak_2;
+}

Modified: cfe/trunk/test/SemaCXX/self-comparison.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/self-comparison.cpp?rev=321976=321975=321976=diff
==
--- cfe/trunk/test/SemaCXX/self-comparison.cpp (original)
+++ cfe/trunk/test/SemaCXX/self-comparison.cpp Sun Jan  7 14:18:05 2018
@@ -21,3 +21,7 @@ struct A {
 return a == c; // expected-warning {{array comparison always evaluates to 
false}}
   }
 };
+
+namespace NA { extern "C" int x[3]; }
+namespace NB { extern "C" int x[3]; }
+bool k = NA::x == NB::x; // expected-warning {{self-comparison always 
evaluates to true}}


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


r321973 - Add tests for three-way self- and array comparison.

2018-01-07 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Sun Jan  7 14:03:44 2018
New Revision: 321973

URL: http://llvm.org/viewvc/llvm-project?rev=321973=rev
Log:
Add tests for three-way self- and array comparison.

Modified:
cfe/trunk/test/SemaCXX/compare-cxx2a.cpp

Modified: cfe/trunk/test/SemaCXX/compare-cxx2a.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/compare-cxx2a.cpp?rev=321973=321972=321973=diff
==
--- cfe/trunk/test/SemaCXX/compare-cxx2a.cpp (original)
+++ cfe/trunk/test/SemaCXX/compare-cxx2a.cpp Sun Jan  7 14:03:44 2018
@@ -3,6 +3,14 @@
 
 // RUN: %clang_cc1 -triple x86_64-apple-darwin -fsyntax-only -pedantic -verify 
-Wsign-compare -std=c++2a %s
 
+void self_compare() {
+  int a;
+  int b[3], c[3];
+  (void)(a <=> a); // expected-warning {{self-comparison always evaluates to 
'std::strong_ordering::equal'}}
+  (void)(b <=> b); // expected-warning {{self-comparison always evaluates to 
'std::strong_ordering::equal'}}
+  (void)(b <=> c); // expected-warning {{array comparison always evaluates to 
a constant}}
+}
+
 void test0(long a, unsigned long b) {
   enum EnumA {A};
   enum EnumB {B};


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


r321972 - Factor out common tautological comparison code from scalar and vector compare checking.

2018-01-07 Thread Richard Smith via cfe-commits
Author: rsmith
Date: Sun Jan  7 13:57:48 2018
New Revision: 321972

URL: http://llvm.org/viewvc/llvm-project?rev=321972=rev
Log:
Factor out common tautological comparison code from scalar and vector compare 
checking.

In passing, improve vector compare diagnostic to match scalar compare 
diagnostic.

Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/test/Sema/ext_vector_comparisons.c

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=321972=321971=321972=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Sun Jan  7 13:57:48 
2018
@@ -7906,7 +7906,7 @@ def note_ref_subobject_of_member_declare
 // should result in a warning, since these always evaluate to a constant.
 // Array comparisons have similar warnings
 def warn_comparison_always : Warning<
-  "%select{self-|array }0comparison always evaluates to %select{false|true|a 
constant}1">,
+  "%select{self-|array }0comparison always evaluates to %select{a 
constant|%2}1">,
   InGroup;
 def warn_comparison_bitwise_always : Warning<
   "bitwise comparison always evaluates to %select{false|true}0">,

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=321972=321971=321972=diff
==
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Sun Jan  7 13:57:48 2018
@@ -9580,7 +9580,8 @@ public:
bool AllowBothBool, bool AllowBoolConversion);
   QualType GetSignedVectorType(QualType V);
   QualType CheckVectorCompareOperands(ExprResult , ExprResult ,
-  SourceLocation Loc, bool isRelational);
+  SourceLocation Loc,
+  BinaryOperatorKind Opc);
   QualType CheckVectorLogicalOperands(ExprResult , ExprResult ,
   SourceLocation Loc);
 

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=321972=321971=321972=diff
==
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Sun Jan  7 13:57:48 2018
@@ -9587,19 +9587,119 @@ static void diagnoseLogicalNotOnLHSofChe
 // Get the decl for a simple expression: a reference to a variable,
 // an implicit C++ field reference, or an implicit ObjC ivar reference.
 static ValueDecl *getCompareDecl(Expr *E) {
-  if (DeclRefExpr* DR = dyn_cast(E))
+  if (DeclRefExpr *DR = dyn_cast(E))
 return DR->getDecl();
-  if (ObjCIvarRefExpr* Ivar = dyn_cast(E)) {
+  if (ObjCIvarRefExpr *Ivar = dyn_cast(E)) {
 if (Ivar->isFreeIvar())
   return Ivar->getDecl();
   }
-  if (MemberExpr* Mem = dyn_cast(E)) {
+  if (MemberExpr *Mem = dyn_cast(E)) {
 if (Mem->isImplicitAccess())
   return Mem->getMemberDecl();
   }
   return nullptr;
 }
 
+/// Diagnose some forms of syntactically-obvious tautological comparison.
+static void diagnoseTautologicalComparison(Sema , SourceLocation Loc,
+   Expr *LHS, Expr *RHS,
+   BinaryOperatorKind Opc) {
+  Expr *LHSStripped = LHS->IgnoreParenImpCasts();
+  Expr *RHSStripped = RHS->IgnoreParenImpCasts();
+
+  QualType LHSType = LHS->getType();
+  QualType RHSType = RHS->getType();
+  if (LHSType->hasFloatingRepresentation() ||
+  (LHSType->isBlockPointerType() && !BinaryOperator::isEqualityOp(Opc)) ||
+  LHS->getLocStart().isMacroID() || RHS->getLocStart().isMacroID() ||
+  S.inTemplateInstantiation())
+return;
+
+  // For non-floating point types, check for self-comparisons of the form
+  // x == x, x != x, x < x, etc.  These always evaluate to a constant, and
+  // often indicate logic errors in the program.
+  //
+  // NOTE: Don't warn about comparison expressions resulting from macro
+  // expansion. Also don't warn about comparisons which are only self
+  // comparisons within a template specialization. The warnings should catch
+  // obvious cases in the definition of the template anyways. The idea is to
+  // warn when the typed comparison operator will always evaluate to the same
+  // result.
+  ValueDecl *DL = getCompareDecl(LHSStripped);
+  ValueDecl *DR = getCompareDecl(RHSStripped);
+  if (DL && DR && DL == DR && !IsWithinTemplateSpecialization(DL)) {
+StringRef Result;
+switch (Opc) {
+case BO_EQ: case BO_LE: case BO_GE:
+  Result = "true";
+  break;
+case BO_NE: case BO_LT: 

[PATCH] D41809: Clang counterpart change for buzzer FreeBSD support

2018-01-07 Thread Kim Gräsman via Phabricator via cfe-commits
kimgr requested changes to this revision.
kimgr added a comment.
This revision now requires changes to proceed.

Typo in the commit title: buzzer :)


Repository:
  rC Clang

https://reviews.llvm.org/D41809



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


[PATCH] D41655: [clang-tidy] New check bugprone-unused-return-value

2018-01-07 Thread Kalle Huttunen via Phabricator via cfe-commits
khuttun updated this revision to Diff 128879.
khuttun added a comment.

Fix review comments


https://reviews.llvm.org/D41655

Files:
  clang-tidy/bugprone/BugproneTidyModule.cpp
  clang-tidy/bugprone/CMakeLists.txt
  clang-tidy/bugprone/UnusedReturnValueCheck.cpp
  clang-tidy/bugprone/UnusedReturnValueCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/bugprone-unused-return-value.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/bugprone-unused-return-value-custom.cpp
  test/clang-tidy/bugprone-unused-return-value.cpp

Index: test/clang-tidy/bugprone-unused-return-value.cpp
===
--- /dev/null
+++ test/clang-tidy/bugprone-unused-return-value.cpp
@@ -0,0 +1,208 @@
+// RUN: %check_clang_tidy %s bugprone-unused-return-value %t
+
+namespace std {
+
+using size_t = decltype(sizeof(int));
+
+using max_align_t = long double;
+
+struct future {};
+
+enum class launch {
+  async,
+  deferred
+};
+
+template 
+future async(Function &&, Args &&...);
+
+template 
+future async(launch, Function &&, Args &&...);
+
+template 
+bool empty(const T&);
+
+// the check should be able to match std lib calls even if the functions are
+// declared inside inline namespaces
+inline namespace v1 {
+
+template 
+T *launder(T *);
+
+} // namespace v1
+
+template 
+struct allocator {
+  using value_type = T;
+  T *allocate(std::size_t);
+  T *allocate(std::size_t, const void *);
+};
+
+template 
+struct allocator_traits {
+  using value_type = typename Alloc::value_type;
+  using pointer = value_type *;
+  using size_type = size_t;
+  using const_void_pointer = const void *;
+  static pointer allocate(Alloc &, size_type);
+  static pointer allocate(Alloc &, size_type, const_void_pointer);
+};
+
+template 
+struct scoped_allocator_adaptor : public OuterAlloc {
+  using pointer = typename allocator_traits::pointer;
+  using size_type = typename allocator_traits::size_type;
+  using const_void_pointer = typename allocator_traits::const_void_pointer;
+  pointer allocate(size_type);
+  pointer allocate(size_type, const_void_pointer);
+};
+
+template 
+struct default_delete {};
+
+template >
+struct unique_ptr {
+  using pointer = T *;
+  pointer release() noexcept;
+};
+
+template >
+struct vector {
+  bool empty() const noexcept;
+};
+
+namespace filesystem {
+
+struct path {
+  bool empty() const noexcept;
+};
+
+} // namespace filesystem
+
+namespace pmr {
+
+struct memory_resource {
+  void *allocate(size_t, size_t = alignof(max_align_t));
+};
+
+template 
+struct polymorphic_allocator {
+  T *allocate(size_t);
+};
+
+} // namespace pmr
+
+} // namespace std
+
+struct Foo {
+  void f();
+};
+
+int increment(int i) {
+  return i + 1;
+}
+
+void useFuture(const std::future );
+
+struct FooAlloc {
+  using value_type = Foo;
+};
+
+void warning() {
+  std::async(increment, 42);
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: the value returned by this function should be used [bugprone-unused-return-value]
+
+  std::async(std::launch::async, increment, 42);
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: the value returned by this function should be used [bugprone-unused-return-value]
+
+  Foo F;
+  std::launder();
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: the value returned by this function should be used [bugprone-unused-return-value]
+
+  std::unique_ptr UP;
+  UP.release();
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: the value returned by this function should be used [bugprone-unused-return-value]
+
+  std::allocator FA;
+  FA.allocate(1);
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: the value returned by this function should be used [bugprone-unused-return-value]
+  FA.allocate(1, nullptr);
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: the value returned by this function should be used [bugprone-unused-return-value]
+
+  std::allocator_traits::allocate(FA, 1);
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: the value returned by this function should be used [bugprone-unused-return-value]
+  std::allocator_traits::allocate(FA, 1, nullptr);
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: the value returned by this function should be used [bugprone-unused-return-value]
+
+  std::scoped_allocator_adaptor SAA;
+  SAA.allocate(1);
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: the value returned by this function should be used [bugprone-unused-return-value]
+  SAA.allocate(1, nullptr);
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: the value returned by this function should be used [bugprone-unused-return-value]
+
+  std::pmr::memory_resource MR;
+  MR.allocate(1);
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: the value returned by this function should be used [bugprone-unused-return-value]
+
+  std::pmr::polymorphic_allocator PA;
+  PA.allocate(1);
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: the value returned by this function should be used [bugprone-unused-return-value]
+
+  std::vector FV;
+  FV.empty();
+  // 

[PATCH] D41655: [clang-tidy] New check bugprone-unused-return-value

2018-01-07 Thread Kalle Huttunen via Phabricator via cfe-commits
khuttun marked 2 inline comments as done.
khuttun added inline comments.



Comment at: test/clang-tidy/bugprone-unused-return-value.cpp:163
+
+void noWarning() {
+  auto AsyncRetval1 = std::async(increment, 42);

aaron.ballman wrote:
> Sorry, I just realized that we're missing a test case for a common situation 
> -- where the result is used as part of another call expression. Can you add a 
> test to `noWarning()` to make sure this does not warn:
> ```
> std::vector v;
> extern void f(bool);
> 
> f(v.empty()); // Should not warn
> ```
See line 199 in this file.


https://reviews.llvm.org/D41655



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


[PATCH] D41809: Clang counterpart change for buzzer FreeBSD support

2018-01-07 Thread David CARLIER via Phabricator via cfe-commits
devnexen created this revision.
Herald added subscribers: cfe-commits, emaste.

Repository:
  rC Clang

https://reviews.llvm.org/D41809

Files:
  lib/Driver/ToolChains/FreeBSD.cpp


Index: lib/Driver/ToolChains/FreeBSD.cpp
===
--- lib/Driver/ToolChains/FreeBSD.cpp
+++ lib/Driver/ToolChains/FreeBSD.cpp
@@ -386,6 +386,8 @@
   SanitizerMask Res = ToolChain::getSupportedSanitizers();
   Res |= SanitizerKind::Address;
   Res |= SanitizerKind::Vptr;
+  Res |= SanitizerKind::Fuzzer;
+  Res |= SanitizerKind::FuzzerNoLink;
   if (IsX86_64 || IsMIPS64) {
 Res |= SanitizerKind::Leak;
 Res |= SanitizerKind::Thread;


Index: lib/Driver/ToolChains/FreeBSD.cpp
===
--- lib/Driver/ToolChains/FreeBSD.cpp
+++ lib/Driver/ToolChains/FreeBSD.cpp
@@ -386,6 +386,8 @@
   SanitizerMask Res = ToolChain::getSupportedSanitizers();
   Res |= SanitizerKind::Address;
   Res |= SanitizerKind::Vptr;
+  Res |= SanitizerKind::Fuzzer;
+  Res |= SanitizerKind::FuzzerNoLink;
   if (IsX86_64 || IsMIPS64) {
 Res |= SanitizerKind::Leak;
 Res |= SanitizerKind::Thread;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


Re: [libcxx] r321966 - Mark the transparent version set::count() as const. Thanks to Ivan Matek for the bug report.

2018-01-07 Thread Roman Lebedev via cfe-commits
It seems the test is missing?

On Sun, Jan 7, 2018 at 8:39 PM, Marshall Clow via cfe-commits
 wrote:
> Author: marshall
> Date: Sun Jan  7 09:39:57 2018
> New Revision: 321966
>
> URL: http://llvm.org/viewvc/llvm-project?rev=321966=rev
> Log:
> Mark the transparent version set::count() as const. Thanks to Ivan Matek for 
> the bug report.
>
> Modified:
> libcxx/trunk/include/set
>
> Modified: libcxx/trunk/include/set
> URL: 
> http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/set?rev=321966=321965=321966=diff
> ==
> --- libcxx/trunk/include/set (original)
> +++ libcxx/trunk/include/set Sun Jan  7 09:39:57 2018
> @@ -1077,7 +1077,7 @@ public:
>  template 
>  _LIBCPP_INLINE_VISIBILITY
>  typename enable_if<__is_transparent<_Compare, 
> _K2>::value,size_type>::type
> -count(const _K2& __k)  {return 
> __tree_.__count_multi(__k);}
> +count(const _K2& __k) const{return 
> __tree_.__count_multi(__k);}
>  #endif
>
>  _LIBCPP_INLINE_VISIBILITY
>
>
> ___
> cfe-commits mailing list
> cfe-commits@lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libcxx] r321966 - Mark the transparent version set::count() as const. Thanks to Ivan Matek for the bug report.

2018-01-07 Thread Marshall Clow via cfe-commits
Author: marshall
Date: Sun Jan  7 09:39:57 2018
New Revision: 321966

URL: http://llvm.org/viewvc/llvm-project?rev=321966=rev
Log:
Mark the transparent version set::count() as const. Thanks to Ivan Matek for 
the bug report.

Modified:
libcxx/trunk/include/set

Modified: libcxx/trunk/include/set
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/set?rev=321966=321965=321966=diff
==
--- libcxx/trunk/include/set (original)
+++ libcxx/trunk/include/set Sun Jan  7 09:39:57 2018
@@ -1077,7 +1077,7 @@ public:
 template 
 _LIBCPP_INLINE_VISIBILITY
 typename enable_if<__is_transparent<_Compare, _K2>::value,size_type>::type
-count(const _K2& __k)  {return __tree_.__count_multi(__k);}
+count(const _K2& __k) const{return __tree_.__count_multi(__k);}
 #endif
 
 _LIBCPP_INLINE_VISIBILITY


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


[PATCH] D41805: Add pre-C++11 is_constructible wrappers for 3 arguments

2018-01-07 Thread Dimitry Andric via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rCXX321963: Add pre-C++11 is_constructible wrappers for 3 
arguments (authored by dim, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D41805?vs=128860=128873#toc

Repository:
  rCXX libc++

https://reviews.llvm.org/D41805

Files:
  include/type_traits
  test/std/utilities/meta/meta.unary/meta.unary.prop/is_constructible.pass.cpp

Index: include/type_traits
===
--- include/type_traits
+++ include/type_traits
@@ -3172,6 +3172,14 @@
 false_type
 __is_constructible2_test(__any, _A0&, _A1&);
 
+template 
+decltype((_Tp(_VSTD::declval<_A0>(), _VSTD::declval<_A1>(), _VSTD::declval<_A2>()), true_type()))
+__is_constructible3_test(_Tp&, _A0&, _A1&, _A2&);
+
+template 
+false_type
+__is_constructible3_test(__any, _A0&, _A1&, _A2&);
+
 template 
 struct __is_constructible0_imp // false, _Tp is not a scalar
 : public common_type
@@ -3196,6 +3204,14 @@
  >::type
 {};
 
+template 
+struct __is_constructible3_imp // false, _Tp is not a scalar
+: public common_type
+ <
+ decltype(__is_constructible3_test(declval<_Tp&>(), declval<_A0>(), declval<_A1>(), declval<_A2>()))
+ >::type
+{};
+
 //  handle scalars and reference types
 
 //  Scalars are default constructible, references are not
@@ -3215,6 +3231,11 @@
 : public false_type
 {};
 
+template 
+struct __is_constructible3_imp
+: public false_type
+{};
+
 //  Treat scalars and reference types separately
 
 template 
@@ -3235,6 +3256,12 @@
 _Tp, _A0, _A1>
 {};
 
+template 
+struct __is_constructible3_void_check
+: public __is_constructible3_imp::value || is_reference<_Tp>::value,
+_Tp, _A0, _A1, _A2>
+{};
+
 //  If any of T or Args is void, is_constructible should be false
 
 template 
@@ -3252,17 +3279,24 @@
 : public false_type
 {};
 
+template 
+struct __is_constructible3_void_check
+: public false_type
+{};
+
 //  is_constructible entry point
 
 template 
+ class _A1 = __is_construct::__nat,
+ class _A2 = __is_construct::__nat>
 struct _LIBCPP_TEMPLATE_VIS is_constructible
-: public __is_constructible2_void_check::value
+: public __is_constructible3_void_check::value
 || is_abstract<_Tp>::value
 || is_function<_Tp>::value
 || is_void<_A0>::value
-|| is_void<_A1>::value,
-   _Tp, _A0, _A1>
+|| is_void<_A1>::value
+|| is_void<_A2>::value,
+   _Tp, _A0, _A1, _A2>
 {};
 
 template 
@@ -3282,6 +3316,16 @@
_Tp, _A0>
 {};
 
+template 
+struct _LIBCPP_TEMPLATE_VIS is_constructible<_Tp, _A0, _A1, __is_construct::__nat>
+: public __is_constructible2_void_check::value
+|| is_abstract<_Tp>::value
+|| is_function<_Tp>::value
+|| is_void<_A0>::value
+|| is_void<_A1>::value,
+   _Tp, _A0, _A1>
+{};
+
 //  Array types are default constructible if their element type
 //  is default constructible
 
@@ -3300,6 +3344,11 @@
 : public false_type
 {};
 
+template 
+struct __is_constructible3_imp
+: public false_type
+{};
+
 //  Incomplete array types are not constructible
 
 template 
@@ -3317,6 +3366,11 @@
 : public false_type
 {};
 
+template 
+struct __is_constructible3_imp
+: public false_type
+{};
+
 #endif // __has_feature(is_constructible)
 
 
Index: test/std/utilities/meta/meta.unary/meta.unary.prop/is_constructible.pass.cpp
===
--- test/std/utilities/meta/meta.unary/meta.unary.prop/is_constructible.pass.cpp
+++ test/std/utilities/meta/meta.unary/meta.unary.prop/is_constructible.pass.cpp
@@ -30,6 +30,7 @@
 {
 explicit A(int);
 A(int, double);
+A(int, long, double);
 #if TEST_STD_VER >= 11
 private:
 #endif
@@ -106,6 +107,16 @@
 #endif
 }
 
+template 
+void test_is_constructible()
+{
+static_assert(( std::is_constructible::value), "");
+

[libcxx] r321963 - Add pre-C++11 is_constructible wrappers for 3 arguments

2018-01-07 Thread Dimitry Andric via cfe-commits
Author: dim
Date: Sun Jan  7 08:45:11 2018
New Revision: 321963

URL: http://llvm.org/viewvc/llvm-project?rev=321963=rev
Log:
Add pre-C++11 is_constructible wrappers for 3 arguments

Summary:
After rL319736 for D28253 (which fixes PR28929), gcc cannot compile `` 
anymore in pre-C+11 modes, complaining:

```
In file included from /usr/include/c++/v1/memory:648:0,
 from test.cpp:1:
/usr/include/c++/v1/memory: In static member function 'static 
std::__1::shared_ptr<_Tp> std::__1::shared_ptr<_Tp>::make_shared(_A0&, _A1&, 
_A2&)':
/usr/include/c++/v1/memory:4365:5: error: wrong number of template arguments 
(4, should be at least 1)
 static_assert((is_constructible<_Tp, _A0, _A1, _A2>::value), "Can't 
construct object in make_shared" );
 ^
In file included from /usr/include/c++/v1/memory:649:0,
 from test.cpp:1:
/usr/include/c++/v1/type_traits:3198:29: note: provided for 'template struct std::__1::is_constructible'
 struct _LIBCPP_TEMPLATE_VIS is_constructible
 ^~~~
In file included from /usr/include/c++/v1/memory:648:0,
 from test.cpp:1:
/usr/include/c++/v1/memory:4365:5: error: template argument 1 is invalid
 static_assert((is_constructible<_Tp, _A0, _A1, _A2>::value), "Can't 
construct object in make_shared" );
 ^
/usr/include/c++/v1/memory: In static member function 'static 
std::__1::shared_ptr<_Tp> std::__1::shared_ptr<_Tp>::allocate_shared(const 
_Alloc&, _A0&, _A1&, _A2&)':
/usr/include/c++/v1/memory::5: error: wrong number of template arguments 
(4, should be at least 1)
 static_assert((is_constructible<_Tp, _A0, _A1, _A2>::value), "Can't 
construct object in allocate_shared" );
 ^
In file included from /usr/include/c++/v1/memory:649:0,
 from test.cpp:1:
/usr/include/c++/v1/type_traits:3198:29: note: provided for 'template struct std::__1::is_constructible'
 struct _LIBCPP_TEMPLATE_VIS is_constructible
 ^~~~
In file included from /usr/include/c++/v1/memory:648:0,
 from test.cpp:1:
/usr/include/c++/v1/memory::5: error: template argument 1 is invalid
 static_assert((is_constructible<_Tp, _A0, _A1, _A2>::value), "Can't 
construct object in allocate_shared" );
 ^
```

This is also reported in https://bugs.freebsd.org/224946 (FreeBSD is apparently 
one of the very few projects that regularly builds programs against libc++ with 
gcc).

The reason is that the static assertions are invoking `is_constructible` with 
three arguments, while gcc does not have the built-in `is_constructible` 
feature, and the pre-C++11 `is_constructible` wrappers in `` only 
provide up to two arguments.

I have added additional wrappers for three arguments, modified the 
`is_constructible` entry point to take three arguments instead, and added a 
simple test to is_constructible.pass.cpp.

Reviewers: EricWF, mclow.lists

Reviewed By: EricWF

Subscribers: krytarowski, cfe-commits, emaste

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

Modified:
libcxx/trunk/include/type_traits

libcxx/trunk/test/std/utilities/meta/meta.unary/meta.unary.prop/is_constructible.pass.cpp

Modified: libcxx/trunk/include/type_traits
URL: 
http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/type_traits?rev=321963=321962=321963=diff
==
--- libcxx/trunk/include/type_traits (original)
+++ libcxx/trunk/include/type_traits Sun Jan  7 08:45:11 2018
@@ -3172,6 +3172,14 @@ template 
 false_type
 __is_constructible2_test(__any, _A0&, _A1&);
 
+template 
+decltype((_Tp(_VSTD::declval<_A0>(), _VSTD::declval<_A1>(), 
_VSTD::declval<_A2>()), true_type()))
+__is_constructible3_test(_Tp&, _A0&, _A1&, _A2&);
+
+template 
+false_type
+__is_constructible3_test(__any, _A0&, _A1&, _A2&);
+
 template 
 struct __is_constructible0_imp // false, _Tp is not a scalar
 : public common_type
@@ -3196,6 +3204,14 @@ struct __is_constructible2_imp // false,
  >::type
 {};
 
+template 
+struct __is_constructible3_imp // false, _Tp is not a scalar
+: public common_type
+ <
+ decltype(__is_constructible3_test(declval<_Tp&>(), 
declval<_A0>(), declval<_A1>(), declval<_A2>()))
+ >::type
+{};
+
 //  handle scalars and reference types
 
 //  Scalars are default constructible, references are not
@@ -3215,6 +3231,11 @@ struct __is_constructible2_imp
+: public false_type
+{};
+
 //  Treat scalars and reference types separately
 
 template 
@@ -3235,6 +3256,12 @@ struct __is_constructible2_void_check
 _Tp, _A0, _A1>
 {};
 
+template 
+struct 

[PATCH] D41808: Rename clang link from clang-X.Y to clang-X

2018-01-07 Thread Sylvestre Ledru via Phabricator via cfe-commits
sylvestre.ledru created this revision.
sylvestre.ledru added a reviewer: tstellar.
Herald added a subscriber: mgorny.

As we are only doing X.0.Z releases (not using the minor version), there is no 
need to keep -X.Y in the version.
So, instead, I propose the following:
Instead of having clang-7.0 in bin/, we will have clang-7

Since also matches was gcc is doing.


https://reviews.llvm.org/D41808

Files:
  CMakeLists.txt


Index: CMakeLists.txt
===
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -418,10 +418,10 @@
 
 # Clang version information
 set(CLANG_EXECUTABLE_VERSION
- "${CLANG_VERSION_MAJOR}.${CLANG_VERSION_MINOR}" CACHE STRING
+ "${CLANG_VERSION_MAJOR}" CACHE STRING
 "Version number that will be placed into the clang executable, in the form 
XX.YY")
 set(LIBCLANG_LIBRARY_VERSION
- "${CLANG_VERSION_MAJOR}.${CLANG_VERSION_MINOR}" CACHE STRING
+ "${CLANG_VERSION_MAJOR}" CACHE STRING
 "Version number that will be placed into the libclang library , in the 
form XX.YY")
 mark_as_advanced(CLANG_EXECUTABLE_VERSION LIBCLANG_LIBRARY_VERSION)
 


Index: CMakeLists.txt
===
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -418,10 +418,10 @@
 
 # Clang version information
 set(CLANG_EXECUTABLE_VERSION
- "${CLANG_VERSION_MAJOR}.${CLANG_VERSION_MINOR}" CACHE STRING
+ "${CLANG_VERSION_MAJOR}" CACHE STRING
 "Version number that will be placed into the clang executable, in the form XX.YY")
 set(LIBCLANG_LIBRARY_VERSION
- "${CLANG_VERSION_MAJOR}.${CLANG_VERSION_MINOR}" CACHE STRING
+ "${CLANG_VERSION_MAJOR}" CACHE STRING
 "Version number that will be placed into the libclang library , in the form XX.YY")
 mark_as_advanced(CLANG_EXECUTABLE_VERSION LIBCLANG_LIBRARY_VERSION)
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D41648: [clang-tidy] implement cppcoreguidelines macro rules

2018-01-07 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth added a comment.

> Yes, and I'm saying that the guidelines aren't useful for real code bases 
> because they restrict more than is reasonable. So while I think the check is 
> largely implementing what the guidelines recommend, I think that some of 
> these scenarios should be brought back to the guideline authors to weigh in 
> on before we expose the check to users.

I see. Are u willing to identify some of the exceptions with me or don't you 
have enough time? I would like to propose the first list here. My opinion is, 
that we should leave some useful macros (e.g. `Ensure` from guidelines) left 
for manual inspection and to disable the check for these specific macros.

> I don't think a whitelist is going to cut it here...

The whitelist could be a regex or something similar. Configuring the check to 
allow everything with a prefix would allow poor mans namespaces for macros. For 
llvm it would be `LLVM_*`, blaze could be `BLAZE_*`. These are the bigger 
codebases i know where macro usage was reasonable. :)

> ... -- users are not going to try to figure out every conditional compilation 
> or attribute macro definition used in their large code base;

Conditional compilation can be done with empty macros.

  #define ALLOW_EXCEPTION
  
  #ifdef ALLOW_EXCEPTION
  // exception code
  #else
  // no exception code
  #endif

That usecase is in my eyes pretty much like an include guard an therfore 
acceptable, and i think not diagnosed with the check currently.

> For example, look at Compiler.h in LLVM and try to see how you would rewrite 
> that code to perform the same purposes without triggering diagnostics from 
> this check. That sort of file is common to almost every production code base 
> I've ever come across.
>  One way to make this less chatty would be to check whether the macro 
> replacement list is defining a source construct that cannot be replaced by 
> constexpr variables or inline functions (such as 
> LLVM_ATTRIBUTE_ALWAYS_INLINE). If we had whole-program analysis, I think we 
> could do something further like scan the uses of the macros to determine 
> whether they're used for conditional compilation (such as 
> LLVM_ENABLE_EXCEPTIONS). However, I have no idea how we would handle cases 
> like LLVM_LIKELY and LLVM_UNLIKELY, but expecting users to NOLINT 500+ lines 
> of common macro code doesn't seem like a good first approach. I'd be curious 
> to know what the C++ Core Guidelines folks think about those use cases and 
> how they would recommend rewriting the code to adhere to their guidelines. Do 
> they really expect users to use *no* macros in C++ code outside of header 
> include guards and noop definitions even when asked about reasonable use 
> cases like cross-compiler attributes or builtins? I mean, many of these 
> things cannot even use the attribute the C++ Core Guidelines require for 
> silencing such diagnostics -- how do they want to use gsl::suppress to 
> silence a diagnostic on a macro definition?

Common constructs that I would identify as valid:

1. Compiler specific Attributes. `#define ALWAYS_INLINE 
__attribute__((always_inline))`

Attributes could be identified when inspecting the tokens the macro expands to. 
I have no clue how to implement, but i think that should even possible with 
string manipulations.

2. Compiler intrinsics

These are similar to attributes and could maybe even treated the same.

3. Compatibility with older C++ Standards

Stuff like `#define OVERRIDE override` if the code is compiled with C++11 or 
newer might be acceptable for stepwise modernization.
This can can be considered as program text manipulation that was explicitly 
forbidden but does not obscure code so an exception could be made.
Such macros can be detected with string comparisons.

4. Debugging/Logging stuff that contains the Line and file.

These can not be modeled with current C++(?), but `LineInfo` or similar exists. 
I don't know what its status is. I think it is ok to require manual silencing 
for such macros.

@aaron.ballman Do you agree with the list? I would ask the guideline authors 
about the issue and propose exceptions to the strict rules.


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41648



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


[PATCH] D40854: [clang-tidy] WIP implement cppcoreguidelines check for mixed integer arithmetic

2018-01-07 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth updated this revision to Diff 128870.
JonasToth added a comment.

- rebase after release of 6.0


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D40854

Files:
  clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  clang-tidy/cppcoreguidelines/MixedIntArithmeticCheck.cpp
  clang-tidy/cppcoreguidelines/MixedIntArithmeticCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/cppcoreguidelines-mixed-int-arithmetic.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/cppcoreguidelines-mixed-int-arithmetic.cpp

Index: test/clang-tidy/cppcoreguidelines-mixed-int-arithmetic.cpp
===
--- /dev/null
+++ test/clang-tidy/cppcoreguidelines-mixed-int-arithmetic.cpp
@@ -0,0 +1,188 @@
+// RUN: %check_clang_tidy %s cppcoreguidelines-mixed-int-arithmetic %t
+
+enum UnsignedEnum : unsigned char {
+  UEnum1,
+  UEnum2
+};
+
+enum SignedEnum : signed char {
+  SEnum1,
+  SEnum2
+};
+
+unsigned char returnUnsignedCharacter() { return 42; }
+unsigned returnUnsignedNumber() { return 42u; }
+long returnBigNumber() { return 42; }
+float unrelatedThing() { return 42.f; }
+SignedEnum returnSignedEnum() { return SEnum1; }
+UnsignedEnum returnUnsignedEnum() { return UEnum1; }
+
+void mixed_binary() {
+  unsigned int UInt1 = 42;
+  signed int SInt1 = 42;
+  UnsignedEnum UE1 = UEnum1;
+  SignedEnum SE1 = SEnum1;
+  float UnrelatedFloat = 42.f;
+
+  // Test traditional integer types.
+  auto R1 = UInt1 + SInt1;
+  // CHECK-MESSAGES: [[@LINE-1]]:13: warning: mixed signed and unsigned arithmetic; prefer signed integers and use unsigned types only for modulo arithmetic
+  // CHECK-MESSAGES: [[@LINE-2]]:21: note: signed operand
+  // CHECK-MESSAGES: [[@LINE-3]]:13: note: unsigned operand
+
+  int R2 = UInt1 - SInt1;
+  // CHECK-MESSAGES: [[@LINE-1]]:12: warning: mixed signed and unsigned arithmetic; prefer signed integers and use unsigned types only for modulo arithmetic
+  // CHECK-MESSAGES: [[@LINE-2]]:20: note: signed operand
+  // CHECK-MESSAGES: [[@LINE-3]]:12: note: unsigned operand
+
+  unsigned int R3 = UInt1 * SInt1;
+  // CHECK-MESSAGES: [[@LINE-1]]:21: warning: mixed signed and unsigned arithmetic; prefer signed integers and use unsigned types only for modulo arithmetic
+  // CHECK-MESSAGES: [[@LINE-2]]:29: note: signed operand
+  // CHECK-MESSAGES: [[@LINE-3]]:21: note: unsigned operand
+
+  unsigned int R4 = UInt1 / returnBigNumber();
+  // CHECK-MESSAGES: [[@LINE-1]]:21: warning: mixed signed and unsigned arithmetic; prefer signed integers and use unsigned types only for modulo arithmetic
+  // CHECK-MESSAGES: [[@LINE-2]]:29: note: signed operand
+  // CHECK-MESSAGES: [[@LINE-3]]:21: note: unsigned operand
+
+  char R5 = returnUnsignedCharacter() + SInt1;
+  // CHECK-MESSAGES: [[@LINE-1]]:13: warning: mixed signed and unsigned arithmetic; prefer signed integers and use unsigned types only for modulo arithmetic
+  // CHECK-MESSAGES: [[@LINE-2]]:41: note: signed operand
+  // CHECK-MESSAGES: [[@LINE-3]]:13: note: unsigned operand
+
+  auto R6 = SInt1 - 10u;
+  // CHECK-MESSAGES: [[@LINE-1]]:13: warning: mixed signed and unsigned arithmetic; prefer signed integers and use unsigned types only for modulo arithmetic
+  // CHECK-MESSAGES: [[@LINE-2]]:13: note: signed operand
+  // CHECK-MESSAGES: [[@LINE-3]]:21: note: unsigned operand
+
+  auto R7 = UInt1 * 10;
+  // CHECK-MESSAGES: [[@LINE-1]]:13: warning: mixed signed and unsigned arithmetic; prefer signed integers and use unsigned types only for modulo arithmetic
+  // CHECK-MESSAGES: [[@LINE-2]]:21: note: signed operand
+  // CHECK-MESSAGES: [[@LINE-3]]:13: note: unsigned operand
+
+  auto R8 = 10u / returnBigNumber();
+  // CHECK-MESSAGES: [[@LINE-1]]:13: warning: mixed signed and unsigned arithmetic; prefer signed integers and use unsigned types only for modulo arithmetic
+  // CHECK-MESSAGES: [[@LINE-2]]:19: note: signed operand
+  // CHECK-MESSAGES: [[@LINE-3]]:13: note: unsigned operand
+
+  auto R9 = 10 + returnUnsignedCharacter();
+  // CHECK-MESSAGES: [[@LINE-1]]:13: warning: mixed signed and unsigned arithmetic; prefer signed integers and use unsigned types only for modulo arithmetic
+  // CHECK-MESSAGES: [[@LINE-2]]:13: note: signed operand
+  // CHECK-MESSAGES: [[@LINE-3]]:18: note: unsigned operand
+
+  // Test enum types.
+  char R10 = returnUnsignedEnum() - SInt1;
+  // CHECK-MESSAGES: [[@LINE-1]]:14: warning: mixed signed and unsigned arithmetic; prefer signed integers and use unsigned types only for modulo arithmetic
+  // CHECK-MESSAGES: [[@LINE-2]]:37: note: signed operand
+  // CHECK-MESSAGES: [[@LINE-3]]:14: note: unsigned operand
+
+  unsigned char R11 = returnSignedEnum() * UInt1;
+  // CHECK-MESSAGES: [[@LINE-1]]:23: warning: mixed signed and unsigned arithmetic; prefer signed integers and use unsigned types only for modulo arithmetic
+  // CHECK-MESSAGES: [[@LINE-2]]:23: note: signed operand
+  // 

[PATCH] D41648: [clang-tidy] implement cppcoreguidelines macro rules

2018-01-07 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth updated this revision to Diff 128869.
JonasToth added a comment.

- rebase after release for 6.0


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D41648

Files:
  clang-tidy/cppcoreguidelines/CMakeLists.txt
  clang-tidy/cppcoreguidelines/CppCoreGuidelinesTidyModule.cpp
  clang-tidy/cppcoreguidelines/MacroUsageCheck.cpp
  clang-tidy/cppcoreguidelines/MacroUsageCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/cppcoreguidelines-macro-usage.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/cppcoreguidelines-macro-usage.cpp

Index: test/clang-tidy/cppcoreguidelines-macro-usage.cpp
===
--- /dev/null
+++ test/clang-tidy/cppcoreguidelines-macro-usage.cpp
@@ -0,0 +1,15 @@
+// RUN: %check_clang_tidy %s cppcoreguidelines-macro-usage %t
+
+#ifndef INCLUDE_GUARD
+#define INCLUDE_GUARD
+
+#define PROBLEMATIC_CONSTANT 0
+// CHECK-MESSAGES: [[@LINE-1]]:9: warning: don't use macros to declare constants
+
+#define PROBLEMATIC_FUNCTION(x,y) ((a) > (b) ? (a) : (b))
+// CHECK-MESSAGES: [[@LINE-1]]:9: warning: don't use macros to simulate functions
+
+#define PROBLEMATIC_VARIADIC(...) (__VA_ARGS__)
+// CHECK-MESSAGES: [[@LINE-1]]:9: warning: don't use macros to simulate variadic templates
+
+#endif
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -54,6 +54,7 @@
cert-oop11-cpp (redirects to performance-move-constructor-init) 
cppcoreguidelines-c-copy-assignment-signature (redirects to misc-unconventional-assign-operator) 
cppcoreguidelines-interfaces-global-init
+   cppcoreguidelines-macro-usage
cppcoreguidelines-no-malloc
cppcoreguidelines-owning-memory
cppcoreguidelines-pro-bounds-array-to-pointer-decay
Index: docs/clang-tidy/checks/cppcoreguidelines-macro-usage.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/cppcoreguidelines-macro-usage.rst
@@ -0,0 +1,8 @@
+.. title:: clang-tidy - cppcoreguidelines-macro-usage
+
+cppcoreguidelines-macro-usage
+=
+
+Find macro usage that is considered problematic because better language
+constructs exist for the task.
+
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -57,7 +57,11 @@
 Improvements to clang-tidy
 --
 
-- ...
+- New `cppcoreguidelines-macro-usage
+  `_ check
+
+  Find macro usage that is considered problematic because better language
+  constructs exist for the task.
 
 Improvements to include-fixer
 -
Index: clang-tidy/cppcoreguidelines/MacroUsageCheck.h
===
--- /dev/null
+++ clang-tidy/cppcoreguidelines/MacroUsageCheck.h
@@ -0,0 +1,38 @@
+//===--- MacroUsageCheck.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_CPPCOREGUIDELINES_MACROUSAGECHECK_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_MACROUSAGECHECK_H
+
+#include "../ClangTidy.h"
+#include "clang/Lex/Preprocessor.h"
+
+namespace clang {
+namespace tidy {
+namespace cppcoreguidelines {
+
+enum class MacroUsageMode { Constant, Function, Variadic };
+/// Find macro usage that is considered problematic because better language
+/// constructs exist for the task.
+///
+/// For the user-facing documentation see:
+/// http://clang.llvm.org/extra/clang-tidy/checks/cppcoreguidelines-macro-usage.html
+class MacroUsageCheck : public ClangTidyCheck {
+public:
+  MacroUsageCheck(StringRef Name, ClangTidyContext *Context)
+  : ClangTidyCheck(Name, Context) {}
+  void registerPPCallbacks(CompilerInstance ) override;
+  void warnMacro(const MacroDirective *MD);
+};
+
+} // namespace cppcoreguidelines
+} // namespace tidy
+} // namespace clang
+
+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_MACROUSAGECHECK_H
Index: clang-tidy/cppcoreguidelines/MacroUsageCheck.cpp
===
--- /dev/null
+++ clang-tidy/cppcoreguidelines/MacroUsageCheck.cpp
@@ -0,0 +1,62 @@
+//===--- MacroUsageCheck.cpp - clang-tidy--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//

[PATCH] D41507: avxintrin.h documentation fixes and updates

2018-01-07 Thread Simon Pilgrim via Phabricator via cfe-commits
RKSimon accepted this revision.
RKSimon added a comment.
This revision is now accepted and ready to land.

LGTM


https://reviews.llvm.org/D41507



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


r321960 - Remove outdated doxygen comment [-Wdocumentation]

2018-01-07 Thread Benjamin Kramer via cfe-commits
Author: d0k
Date: Sun Jan  7 01:11:16 2018
New Revision: 321960

URL: http://llvm.org/viewvc/llvm-project?rev=321960=rev
Log:
Remove outdated doxygen comment [-Wdocumentation]

No functionality change.

Modified:
cfe/trunk/include/clang/Lex/ModuleMap.h

Modified: cfe/trunk/include/clang/Lex/ModuleMap.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Lex/ModuleMap.h?rev=321960=321959=321960=diff
==
--- cfe/trunk/include/clang/Lex/ModuleMap.h (original)
+++ cfe/trunk/include/clang/Lex/ModuleMap.h Sun Jan  7 01:11:16 2018
@@ -636,10 +636,6 @@ public:
   /// \param ExternModuleLoc The location of the "extern module" declaration
   ///that caused us to load this module map file, if any.
   ///
-  /// \param IsExplicitlyProvided Whether this module map file was provided
-  /// explicitly by the user (e.g. -fmodule-map-file), rather than found
-  /// implicitly.
-  ///
   /// \returns true if an error occurred, false otherwise.
   bool parseModuleMapFile(const FileEntry *File, bool IsSystem,
   const DirectoryEntry *HomeDir,


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


[PATCH] D41805: Add pre-C++11 is_constructible wrappers for 3 arguments

2018-01-07 Thread Eric Fiselier via Phabricator via cfe-commits
EricWF accepted this revision.
EricWF added a comment.
This revision is now accepted and ready to land.

LGTM.


Repository:
  rCXX libc++

https://reviews.llvm.org/D41805



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