Re: [PATCH] D18821: Add modernize-bool-to-integer-conversion

2016-04-09 Thread Piotr Padlewski via cfe-commits
Prazek updated this revision to Diff 53113.
Prazek marked 2 inline comments as done.

http://reviews.llvm.org/D18821

Files:
  clang-tidy/modernize/BoolToIntegerConversionCheck.cpp
  clang-tidy/modernize/BoolToIntegerConversionCheck.h
  clang-tidy/modernize/CMakeLists.txt
  clang-tidy/modernize/ModernizeTidyModule.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/modernize-bool-to-integer-conversion.rst
  test/clang-tidy/modernize-bool-to-integer-conversion.cpp

Index: test/clang-tidy/modernize-bool-to-integer-conversion.cpp
===
--- /dev/null
+++ test/clang-tidy/modernize-bool-to-integer-conversion.cpp
@@ -0,0 +1,58 @@
+// RUN: %check_clang_tidy %s modernize-bool-to-integer-conversion %t
+
+const int is42Answer = true;
+// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: implicitly converting bool literal to 'int'; use integer literal instead [modernize-bool-to-integer-conversion]
+// CHECK-FIXES: const int is42Answer = 1;{{$}}
+
+volatile int noItsNot = false;
+// CHECK-MESSAGES: :[[@LINE-1]]:25: warning: implicitly converting bool literal to 'int'; {{..}}
+// CHECK-FIXES: volatile int noItsNot = 0;{{$}}
+int a = 42;
+int az = a;
+
+long long ll = true;
+// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: implicitly converting bool literal to 'long long';{{..}}
+// CHECK-FIXES: long long ll = 1;{{$}}
+
+void fun(int) {}
+#define ONE true
+
+// No fixup for macros.
+int one = ONE;
+// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: implicitly converting bool literal to 'int' inside a macro; use integer literal instead [modernize-bool-to-integer-conversion]
+
+void test() {
+  fun(ONE);
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: implicitly converting bool{{..}}
+
+  fun(42);
+  fun(true);
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: implicitly {{..}}
+// CHECK-FIXES: fun(1);{{$}}
+}
+
+char c = true;
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: implicitly {{..}}
+// CHECK-FIXES: char c = 1;
+
+float f = false;
+// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: implicitly converting bool literal to 'float';{{..}}
+// CHECK-FIXES: float f = 0;
+
+struct Blah {
+  Blah(int blah) { }
+};
+
+const int &ref = false;
+// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: implicitly converting bool literal to 'int'{{..}}
+// CHECK-FIXES: const int &ref = 0;
+
+Blah bla = true;
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: implicitly converting bool literal to 'int'{{..}}
+// CHECK-FIXES: Blah bla = 1;
+
+Blah bla2 = 1;
+
+char c2 = 1;
+char c3 = '0';
+bool b = true;
Index: docs/clang-tidy/checks/modernize-bool-to-integer-conversion.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/modernize-bool-to-integer-conversion.rst
@@ -0,0 +1,17 @@
+.. title:: clang-tidy - modernize-bool-to-integer-conversion
+
+modernize-bool-to-integer-conversion
+
+
+This check looks for implicit conversion from bool literals to integer types
+
+.. code-block:: C++
+
+  int a = false;
+  vector v(true); // Makes vector of one element
+
+  // Changes it to
+  int a = 0;
+  vector v(1); // Makes vector of one element
+
+
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -31,9 +31,9 @@
google-build-using-namespace
google-explicit-constructor
google-global-names-in-headers
-   google-readability-braces-around-statements (redirects to readability-braces-around-statements) 
+   google-readability-braces-around-statements (redirects to readability-braces-around-statements) 
google-readability-casting
-   google-readability-function-size (redirects to readability-function-size) 
+   google-readability-function-size (redirects to readability-function-size) 
google-readability-namespace-comments
google-readability-redundant-smartptr-get
google-readability-todo
@@ -76,6 +76,7 @@
misc-unused-parameters
misc-unused-raii
misc-virtual-near-miss
+   modernize-bool-to-integer-conversion
modernize-deprecated-headers
modernize-loop-convert
modernize-make-unique
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -113,6 +113,11 @@
 
   Replaces C standard library headers with their C++ alternatives.
 
+- New `modernize-bool-to-integer-conversion
+  `_ check
+
+  Replaces bool literals which are being implicitly cast to integers with integer literals.
+
 - New `modernize-raw-string-literal
   `_ check
 
Index: clang-tidy/modernize/ModernizeTidyModule.cpp
===
--- clang-tidy/modernize/Mod

Re: [PATCH] D18821: Add modernize-bool-to-integer-conversion

2016-04-09 Thread Piotr Padlewski via cfe-commits
Prazek updated this revision to Diff 53114.
Prazek marked 2 inline comments as done.
Prazek added a comment.

Used isMacroID to determinate if it's macro


http://reviews.llvm.org/D18821

Files:
  clang-tidy/modernize/BoolToIntegerConversionCheck.cpp
  clang-tidy/modernize/BoolToIntegerConversionCheck.h
  clang-tidy/modernize/CMakeLists.txt
  clang-tidy/modernize/ModernizeTidyModule.cpp
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/modernize-bool-to-integer-conversion.rst
  test/clang-tidy/modernize-bool-to-integer-conversion.cpp

Index: test/clang-tidy/modernize-bool-to-integer-conversion.cpp
===
--- /dev/null
+++ test/clang-tidy/modernize-bool-to-integer-conversion.cpp
@@ -0,0 +1,58 @@
+// RUN: %check_clang_tidy %s modernize-bool-to-integer-conversion %t
+
+const int is42Answer = true;
+// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: implicitly converting bool literal to 'int'; use integer literal instead [modernize-bool-to-integer-conversion]
+// CHECK-FIXES: const int is42Answer = 1;{{$}}
+
+volatile int noItsNot = false;
+// CHECK-MESSAGES: :[[@LINE-1]]:25: warning: implicitly converting bool literal to 'int'; {{..}}
+// CHECK-FIXES: volatile int noItsNot = 0;{{$}}
+int a = 42;
+int az = a;
+
+long long ll = true;
+// CHECK-MESSAGES: :[[@LINE-1]]:16: warning: implicitly converting bool literal to 'long long';{{..}}
+// CHECK-FIXES: long long ll = 1;{{$}}
+
+void fun(int) {}
+#define ONE true
+
+// No fixup for macros.
+int one = ONE;
+// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: implicitly converting bool literal to 'int' inside a macro; use integer literal instead [modernize-bool-to-integer-conversion]
+
+void test() {
+  fun(ONE);
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: implicitly converting bool{{..}}
+
+  fun(42);
+  fun(true);
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: implicitly {{..}}
+// CHECK-FIXES: fun(1);{{$}}
+}
+
+char c = true;
+// CHECK-MESSAGES: :[[@LINE-1]]:10: warning: implicitly {{..}}
+// CHECK-FIXES: char c = 1;
+
+float f = false;
+// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: implicitly converting bool literal to 'float';{{..}}
+// CHECK-FIXES: float f = 0;
+
+struct Blah {
+  Blah(int blah) { }
+};
+
+const int &ref = false;
+// CHECK-MESSAGES: :[[@LINE-1]]:18: warning: implicitly converting bool literal to 'int'{{..}}
+// CHECK-FIXES: const int &ref = 0;
+
+Blah bla = true;
+// CHECK-MESSAGES: :[[@LINE-1]]:12: warning: implicitly converting bool literal to 'int'{{..}}
+// CHECK-FIXES: Blah bla = 1;
+
+Blah bla2 = 1;
+
+char c2 = 1;
+char c3 = '0';
+bool b = true;
Index: docs/clang-tidy/checks/modernize-bool-to-integer-conversion.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/modernize-bool-to-integer-conversion.rst
@@ -0,0 +1,17 @@
+.. title:: clang-tidy - modernize-bool-to-integer-conversion
+
+modernize-bool-to-integer-conversion
+
+
+This check looks for implicit conversion from bool literals to integer types
+
+.. code-block:: C++
+
+  int a = false;
+  vector v(true); // Makes vector of one element
+
+  // Changes it to
+  int a = 0;
+  vector v(1); // Makes vector of one element
+
+
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -31,9 +31,9 @@
google-build-using-namespace
google-explicit-constructor
google-global-names-in-headers
-   google-readability-braces-around-statements (redirects to readability-braces-around-statements) 
+   google-readability-braces-around-statements (redirects to readability-braces-around-statements) 
google-readability-casting
-   google-readability-function-size (redirects to readability-function-size) 
+   google-readability-function-size (redirects to readability-function-size) 
google-readability-namespace-comments
google-readability-redundant-smartptr-get
google-readability-todo
@@ -76,6 +76,7 @@
misc-unused-parameters
misc-unused-raii
misc-virtual-near-miss
+   modernize-bool-to-integer-conversion
modernize-deprecated-headers
modernize-loop-convert
modernize-make-unique
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -113,6 +113,11 @@
 
   Replaces C standard library headers with their C++ alternatives.
 
+- New `modernize-bool-to-integer-conversion
+  `_ check
+
+  Replaces bool literals which are being implicitly cast to integers with integer literals.
+
 - New `modernize-raw-string-literal
   `_ check
 
Index: clang-tidy/modernize/ModernizeTidyModule.cpp
==

Re: [PATCH] D18914: [clang-tidy] new readability-redundant-inline

2016-04-09 Thread Matthias Gehre via cfe-commits
mgehre updated this revision to Diff 53118.
mgehre added a comment.

Update for review comments


http://reviews.llvm.org/D18914

Files:
  clang-tidy/readability/CMakeLists.txt
  clang-tidy/readability/ReadabilityTidyModule.cpp
  clang-tidy/readability/RedundantInlineCheck.cpp
  clang-tidy/readability/RedundantInlineCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/readability-redundant-inline.rst
  test/clang-tidy/readability-redundant-inline.cpp

Index: test/clang-tidy/readability-redundant-inline.cpp
===
--- /dev/null
+++ test/clang-tidy/readability-redundant-inline.cpp
@@ -0,0 +1,67 @@
+// RUN: %check_clang_tidy %s readability-redundant-inline %t
+
+struct S {
+  inline int f1() {
+// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: 'inline' is redundant because method body is defined inside class [readability-redundant-inline]
+// CHECK-FIXES: {{^}}  int f1()
+return 0;
+  }
+  inline int f2(); // OK
+  
+  inline constexpr int f3() {
+// CHECK-MESSAGES: :[[@LINE-1]]:24: warning: 'inline' is redundant because 'constexpr' implies 'inline' [readability-redundant-inline]
+// CHECK-FIXES: {{^}}  constexpr int f3()
+return 0;
+  }
+  static inline constexpr int f4() {
+// CHECK-MESSAGES: :[[@LINE-1]]:31: warning: 'inline' is redundant because 'constexpr' implies 'inline'
+// CHECK-FIXES: {{^}}  static constexpr int f4()
+return 0;
+  }
+  
+  static inline int f5();
+
+  static inline int f6() {
+// CHECK-MESSAGES: :[[@LINE-1]]:21: warning: 'inline' is redundant because method body is defined inside class
+// CHECK-FIXES: {{^}}  static int f6()
+return 0;
+  }
+
+  inline friend int f7() {
+// CHECK-MESSAGES: :[[@LINE-1]]:21: warning: 'inline' is redundant because function body is defined inside class [readability-redundant-inline]
+// CHECK-FIXES: {{^}}  friend int f7()
+  return 0;
+  }
+
+  inline friend int f8(); // OK
+};
+
+class S2 {
+  inline int f1() {
+// CHECK-MESSAGES: :[[@LINE-1]]:14: warning: 'inline' is redundant because method body is defined inside class
+// CHECK-FIXES: {{^}}  int f1()
+return 0;
+  }
+};
+
+inline int S::f2() { // OK
+  return 0;
+}
+
+inline int S::f5() { // OK
+  return 0;
+}
+
+inline int f3() { // OK
+  return 0;
+}
+
+inline constexpr int f4() {
+// CHECK-MESSAGES: :[[@LINE-1]]:22: warning: 'inline' is redundant because 'constexpr' implies 'inline'
+// CHECK-FIXES: {{^}}constexpr int f4()
+  return 1;
+}
+
+constexpr int f5() { // OK
+  return 1;
+}
\ No newline at end of file
Index: docs/clang-tidy/checks/readability-redundant-inline.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/readability-redundant-inline.rst
@@ -0,0 +1,16 @@
+.. title:: clang-tidy - readability-redundant-inline
+
+readability-redundant-inline
+
+
+This check flags redundant ``inline`` specifiers.
+It flags ``inline`` on member functions defined inside a class definition like
+.. code-block:: c++
+
+  struct S {
+inline int f() {
+	  return 0;
+	}
+  };
+
+and ``inline`` specifiers on functions that are also declared ``constexpr``.
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -105,6 +105,7 @@
readability-inconsistent-declaration-parameter-name
readability-named-parameter
readability-redundant-control-flow
+   readability-redundant-inline
readability-redundant-smartptr-get
readability-redundant-string-cstr
readability-redundant-string-init
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -160,6 +160,12 @@
   Looks for procedures (functions returning no value) with ``return`` statements
   at the end of the function.  Such `return` statements are redundant.
 
+- New `readability-redundant-inline
+  `_ check
+
+  Looks for redundant ``inline`` specifiers which are implied by defining a body within a class definition
+  or by ``constexpr``.
+
 - New `readability-redundant-string-init
   `_ check
 
Index: clang-tidy/readability/RedundantInlineCheck.h
===
--- /dev/null
+++ clang-tidy/readability/RedundantInlineCheck.h
@@ -0,0 +1,35 @@
+//===--- RedundantInlineCheck.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_T

Re: [PATCH] D18914: [clang-tidy] new readability-redundant-inline

2016-04-09 Thread Matthias Gehre via cfe-commits
mgehre added a comment.

I'm thinking about extending the check to the following issue and would like to 
hear your opinion.
In C++, the following three code snippets all have identical meaning
1:

  struct S {
int f();
  };
  
  inline int S::f() {
   return 0;
  }

2:

  struct S {
inline int f();
  };
  int S::f() {
   return 0;
  }

3:

  struct S {
inline int f();
  };
  
  inline int S::f() {
   return 0;
  }

I personally think that 1) should be used, because late one could move the 
function definition to a source file (removing the inline) without having to 
touch
the class declaration. I can extend this patch to transform 2) and 3) into 1).

Alternatively, I could add an option to choose between 1), 2) or 3).
What do you think?


http://reviews.llvm.org/D18914



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


Re: [PATCH] D18136: boost-use-to-string check

2016-04-09 Thread Piotr Padlewski via cfe-commits
Prazek updated the summary for this revision.
Prazek updated this revision to Diff 53121.
Prazek marked 5 inline comments as done.

http://reviews.llvm.org/D18136

Files:
  clang-tidy/boost/BoostTidyModule.cpp
  clang-tidy/boost/CMakeLists.txt
  clang-tidy/boost/UseToStringCheck.cpp
  clang-tidy/boost/UseToStringCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/boost-use-to-string.rst
  docs/clang-tidy/checks/list.rst
  test/clang-tidy/boost-use-to-string.cpp

Index: test/clang-tidy/boost-use-to-string.cpp
===
--- /dev/null
+++ test/clang-tidy/boost-use-to-string.cpp
@@ -0,0 +1,146 @@
+// RUN: %check_clang_tidy %s boost-use-to-string %t
+
+
+namespace std {
+
+template  class basic_string {};
+
+using string = basic_string;
+using wstring = basic_string;
+}
+
+namespace boost {
+template 
+T lexical_cast(const V&) {
+  return T();
+};
+}
+
+struct my_weird_type {};
+
+std::string fun(const std::string &) {}
+
+void test_to_string1() {
+
+  auto xa = boost::lexical_cast(5);
+// CHECK-MESSAGES: :[[@LINE-1]]:13: warning: use std::to_string instead of boost::lexical_cast [boost-use-to-string]
+// CHECK-FIXES: auto xa = std::to_string(5);
+
+ auto z = boost::lexical_cast(42LL);
+// CHECK-MESSAGES: :[[@LINE-1]]:11: warning: use std::to_string {{..}}
+// CHECK-FIXES: auto z = std::to_string(42LL);
+
+  // this should not trigger
+  fun(boost::lexical_cast(42.0));
+  auto non = boost::lexical_cast(42);
+  boost::lexical_cast("12");
+}
+
+void test_to_string2() {
+  int a;
+  long b;
+  long long c;
+  unsigned d;
+  unsigned long e;
+  unsigned long long f;
+  float g;
+  double h;
+  long double i;
+  bool j;
+
+  fun(boost::lexical_cast(a));
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use std::to_string {{..}}
+// CHECK-FIXES: fun(std::to_string(a));
+  fun(boost::lexical_cast(b));
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use std::to_string {{..}}
+// CHECK-FIXES: fun(std::to_string(b));
+  fun(boost::lexical_cast(c));
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use std::to_string {{..}}
+// CHECK-FIXES: fun(std::to_string(c));
+  fun(boost::lexical_cast(d));
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use std::to_string {{..}}
+// CHECK-FIXES: fun(std::to_string(d));
+  fun(boost::lexical_cast(e));
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use std::to_string {{..}}
+// CHECK-FIXES: fun(std::to_string(e));
+  fun(boost::lexical_cast(f));
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use std::to_string {{..}}
+// CHECK-FIXES: fun(std::to_string(f));
+
+  // No change for floating numbers.
+  fun(boost::lexical_cast(g));
+  fun(boost::lexical_cast(h));
+  fun(boost::lexical_cast(i));
+  // And bool.
+  fun(boost::lexical_cast(j));
+}
+
+std::string fun(const std::wstring &) {}
+
+void test_to_wstring() {
+  int a;
+  long b;
+  long long c;
+  unsigned d;
+  unsigned long e;
+  unsigned long long f;
+  float g;
+  double h;
+  long double i;
+  bool j;
+
+  fun(boost::lexical_cast(a));
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use std::to_wstring instead of boost::lexical_cast [boost-use-to-string]
+// CHECK-FIXES: fun(std::to_wstring(a));
+  fun(boost::lexical_cast(b));
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use std::to_wstring {{..}}
+// CHECK-FIXES: fun(std::to_wstring(b));
+  fun(boost::lexical_cast(c));
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use std::to_wstring {{..}}
+// CHECK-FIXES: fun(std::to_wstring(c));
+  fun(boost::lexical_cast(d));
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use std::to_wstring {{..}}
+// CHECK-FIXES: fun(std::to_wstring(d));
+  fun(boost::lexical_cast(e));
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use std::to_wstring {{..}}
+// CHECK-FIXES: fun(std::to_wstring(e));
+  fun(boost::lexical_cast(f));
+// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: use std::to_wstring {{..}}
+// CHECK-FIXES: fun(std::to_wstring(f));
+
+  // No change for floating numbers
+  fun(boost::lexical_cast(g));
+  fun(boost::lexical_cast(h));
+  fun(boost::lexical_cast(i));
+  // and bool.
+  fun(boost::lexical_cast(j));
+}
+
+const auto glob = boost::lexical_cast(42);
+// CHECK-MESSAGES: :[[@LINE-1]]:19: warning: use std::to_string{{..}}
+// CHECK-FIXES: const auto glob = std::to_string(42);
+
+template 
+void string_as_T(T t = T()) {
+  boost::lexical_cast(42);
+// CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use std::to_string{{..}}
+// CHECK-FIXES: std::to_string(42);
+
+  boost::lexical_cast(42);
+  string_as_T(boost::lexical_cast(42));
+  auto p = boost::lexical_cast(42);
+  auto p2 = (T)boost::lexical_cast(42);
+  auto p3 = static_cast(boost::lexical_cast(42));
+}
+
+
+void no_warnings() {
+  fun(boost::lexical_cast("abc"));
+  fun(boost::lexical_cast("abc"));
+  fun(boost::lexical_cast(my_weird_type{}));
+  string_as_T();
+  string_as_T();
+}
+
+
+
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks

Re: [PATCH] D18919: Add check "modernize use using"

2016-04-09 Thread Piotr Padlewski via cfe-commits
Prazek added inline comments.


Comment at: docs/clang-tidy/checks/modernize-use-using.rst:13
@@ +12,3 @@
+  typedef int variable;
+
+After:

add cases with pointers to function / members


http://reviews.llvm.org/D18919



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


[PATCH] D18919: Add check "modernize use using"

2016-04-09 Thread Krystyna via cfe-commits
krystyna created this revision.
krystyna added reviewers: Prazek, mnbvmar, staronj, alexfh.
krystyna added a subscriber: cfe-commits.

http://reviews.llvm.org/D18919

Files:
  clang-tidy/modernize/CMakeLists.txt
  clang-tidy/modernize/ModernizeTidyModule.cpp
  clang-tidy/modernize/UseUsingCheck.cpp
  clang-tidy/modernize/UseUsingCheck.h
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/modernize-use-using.rst
  test/clang-tidy/modernize-use-using.cpp

Index: test/clang-tidy/modernize-use-using.cpp
===
--- /dev/null
+++ test/clang-tidy/modernize-use-using.cpp
@@ -0,0 +1,75 @@
+// RUN: %check_clang_tidy %s modernize-use-using %t
+
+
+typedef int Type;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use using instead of typedef [modernize-use-using]
+// CHECK-FIXES: using Type = int;
+
+typedef long LL;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use using instead of typedef [modernize-use-using]
+// CHECK-FIXES: using LL = long;
+
+typedef int Bla;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use using instead of typedef [modernize-use-using]
+// CHECK-FIXES: using Bla = int;
+
+typedef Bla Bla2;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use using instead of typedef [modernize-use-using]
+// CHECK-FIXES: using Bla2 = Bla;
+
+typedef void (*type)(int);
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use using instead of typedef [modernize-use-using]
+// CHECK-FIXES: using type = void (*)(int);
+
+typedef void (*type2)();
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use using instead of typedef [modernize-use-using]
+// CHECK-FIXES: using type2 = void (*)();
+
+class Class {
+typedef long long Type;
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use using instead of typedef [modernize-use-using]
+	// CHECK-FIXES: using Type = long long;
+};
+
+typedef void (Class::* MyPtrType)(Bla) const;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use using instead of typedef [modernize-use-using]
+// CHECK-FIXES: using MyPtrType = void (Class::*)(Bla) const;
+
+class Iterable {
+public:
+	class Iterator {};
+};
+
+template
+class Test {
+typedef typename T::iterator Iter;
+	// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use using instead of typedef [modernize-use-using]
+	// CHECK-FIXES: using Iter = typename T::iterator;
+};
+
+using balba = long long;
+
+union A {};
+
+typedef void (A::*PtrType)(int, int) const;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use using instead of typedef [modernize-use-using]
+// CHECK-FIXES: using PtrType = void (A::*)(int, int) const;
+
+typedef Class some_class;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use using instead of typedef [modernize-use-using]
+// CHECK-FIXES: using some_class = Class;
+
+typedef Class Cclass;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use using instead of typedef [modernize-use-using]
+// CHECK-FIXES: using Cclass = Class;
+typedef Cclass cclass2;
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use using instead of typedef [modernize-use-using]
+// CHECK-FIXES: using cclass2 = Cclass;
+
+class cclass {
+
+};
+
+typedef void (cclass::* MyPtrType3)(Bla);
+// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: use using instead of typedef [modernize-use-using]
+// CHECK-FIXES: using MyPtrType3 = void (cclass::*)(Bla);
\ No newline at end of file
Index: docs/clang-tidy/checks/modernize-use-using.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/modernize-use-using.rst
@@ -0,0 +1,18 @@
+.. title:: clang-tidy - modernize-use-using
+
+modernize-use-using
+===
+
+Use C++11's ``using`` instead of ``typedef``.
+
+Before:
+
+.. code:: c++
+
+  typedef int variable;
+
+After:
+
+.. code:: c++
+
+  using varible = int;
Index: docs/clang-tidy/checks/list.rst
===
--- docs/clang-tidy/checks/list.rst
+++ docs/clang-tidy/checks/list.rst
@@ -85,6 +85,7 @@
modernize-use-default
modernize-use-nullptr
modernize-use-override
+   modernize-use-using
performance-faster-string-find
performance-for-range-copy
performance-implicit-cast-in-loop
Index: clang-tidy/modernize/UseUsingCheck.h
===
--- /dev/null
+++ clang-tidy/modernize/UseUsingCheck.h
@@ -0,0 +1,35 @@
+//===--- UseUsingCheck.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_MODERNIZE_USE_USING_H
+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MODERNIZE_USE_USING_H
+
+#include "../ClangTidy.h"
+
+namespace clang {
+namespace tidy {
+namespace modernize {
+
+/// FIXME: Write a short description.
+///
+/// For the user-facing do

Re: [PATCH] D18919: Add check "modernize use using"

2016-04-09 Thread Jakub StaroĊ„ via cfe-commits
staronj added inline comments.


Comment at: clang-tidy/modernize/UseUsingCheck.h:19
@@ +18,3 @@
+
+/// FIXME: Write a short description.
+///

Fix the FIXME.


Comment at: test/clang-tidy/modernize-use-using.cpp:76
@@ +75,1 @@
+// CHECK-FIXES: using MyPtrType3 = void (cclass::*)(Bla);
\ No newline at end of file


Add end of line at the end of file.


http://reviews.llvm.org/D18919



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


r265877 - ObjC kindof: check the context when inserting methods to global pool.

2016-04-09 Thread Manman Ren via cfe-commits
Author: mren
Date: Sat Apr  9 13:59:48 2016
New Revision: 265877

URL: http://llvm.org/viewvc/llvm-project?rev=265877&view=rev
Log:
ObjC kindof: check the context when inserting methods to global pool.

To make kindof lookup work, we need to insert methods with different
context into the global pool, even though they have the same siganture.

Since diagnosis of availability is performed on the best candidate,
which is often the first candidate from the global pool, we prioritize
the methods that are unavaible or deprecated to the head of the list.

Since we now have more methods in the global pool, we need to watch
out for performance impact.

rdar://25635831

Modified:
cfe/trunk/include/clang/Sema/ObjCMethodList.h
cfe/trunk/lib/Sema/SemaDeclObjC.cpp
cfe/trunk/test/FixIt/typo.m
cfe/trunk/test/SemaObjC/kindof.m
cfe/trunk/test/SemaObjC/multiple-method-names.m
cfe/trunk/test/SemaObjC/warn-strict-selector-match.m

Modified: cfe/trunk/include/clang/Sema/ObjCMethodList.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/ObjCMethodList.h?rev=265877&r1=265876&r2=265877&view=diff
==
--- cfe/trunk/include/clang/Sema/ObjCMethodList.h (original)
+++ cfe/trunk/include/clang/Sema/ObjCMethodList.h Sat Apr  9 13:59:48 2016
@@ -33,6 +33,9 @@ struct ObjCMethodList {
   ObjCMethodList() { }
   ObjCMethodList(ObjCMethodDecl *M)
   : MethodAndHasMoreThanOneDecl(M, 0) {}
+  ObjCMethodList(const ObjCMethodList &L)
+  : MethodAndHasMoreThanOneDecl(L.MethodAndHasMoreThanOneDecl),
+NextAndExtraBits(L.NextAndExtraBits) {}
 
   ObjCMethodList *getNext() const { return NextAndExtraBits.getPointer(); }
   unsigned getBits() const { return NextAndExtraBits.getInt(); }

Modified: cfe/trunk/lib/Sema/SemaDeclObjC.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclObjC.cpp?rev=265877&r1=265876&r2=265877&view=diff
==
--- cfe/trunk/lib/Sema/SemaDeclObjC.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclObjC.cpp Sat Apr  9 13:59:48 2016
@@ -3167,6 +3167,26 @@ bool Sema::MatchTwoMethodDeclarations(co
   return true;
 }
 
+static bool isMethodContextSameForKindofLookup(ObjCMethodDecl *Method,
+   ObjCMethodDecl *MethodInList) {
+  auto *MethodProtocol = dyn_cast(Method->getDeclContext());
+  auto *MethodInListProtocol =
+  dyn_cast(MethodInList->getDeclContext());
+  // If this method belongs to a protocol but the method in list does not, or
+  // vice versa, we say the context is not the same.
+  if ((MethodProtocol && !MethodInListProtocol) ||
+  (!MethodProtocol && MethodInListProtocol))
+return false;
+
+  if (MethodProtocol && MethodInListProtocol)
+return true;
+
+  ObjCInterfaceDecl *MethodInterface = Method->getClassInterface();
+  ObjCInterfaceDecl *MethodInListInterface =
+  MethodInList->getClassInterface();
+  return MethodInterface == MethodInListInterface;
+}
+
 void Sema::addMethodToGlobalList(ObjCMethodList *List,
  ObjCMethodDecl *Method) {
   // Record at the head of the list whether there were 0, 1, or >= 2 methods
@@ -3185,13 +3205,17 @@ void Sema::addMethodToGlobalList(ObjCMet
 
   // We've seen a method with this name, see if we have already seen this type
   // signature.
+  ObjCMethodList *Head = List;
   ObjCMethodList *Previous = List;
   for (; List; Previous = List, List = List->getNext()) {
 // If we are building a module, keep all of the methods.
 if (getLangOpts().CompilingModule)
   continue;
 
-if (!MatchTwoMethodDeclarations(Method, List->getMethod())) {
+// Looking for method with a type bound requires the correct context 
exists.
+// We need to insert this method into the list if the context is different.
+if (!MatchTwoMethodDeclarations(Method, List->getMethod()) ||
+!isMethodContextSameForKindofLookup(Method, List->getMethod())) {
   // Even if two method types do not match, we would like to say
   // there is more than one declaration so unavailability/deprecated
   // warning is not too noisy.
@@ -3232,6 +3256,19 @@ void Sema::addMethodToGlobalList(ObjCMet
   // We have a new signature for an existing method - add it.
   // This is extremely rare. Only 1% of Cocoa selectors are "overloaded".
   ObjCMethodList *Mem = BumpAlloc.Allocate();
+
+  // We tried to prioritize the list by putting deprecated and unavailable
+  // methods in the front.
+  if ((Method->isDeprecated() && !Head->getMethod()->isDeprecated()) ||
+  (Method->isUnavailable() &&
+   Head->getMethod()->getAvailability() < AR_Deprecated)) {
+auto *List = new (Mem) ObjCMethodList(*Head);
+// FIXME: should we clear the other bits in Head?
+Head->setMethod(Method);
+Head->setNext(List);
+return;
+  }
+
   Previous->setNext(new (Mem) ObjCMethodList(Met

Re: [PATCH] D18919: [Clang-tidy] Add check "modernize use using"

2016-04-09 Thread Eugene Zelenko via cfe-commits
Eugene.Zelenko added a subscriber: Eugene.Zelenko.
Eugene.Zelenko added a comment.

Please mention this check in docs/ReleaseNotes.rst (in alphabetical order).


Repository:
  rL LLVM

http://reviews.llvm.org/D18919



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


r265878 - Basic: thread TargetOptions into TargetInfo

2016-04-09 Thread Saleem Abdulrasool via cfe-commits
Author: compnerd
Date: Sat Apr  9 14:09:25 2016
New Revision: 265878

URL: http://llvm.org/viewvc/llvm-project?rev=265878&view=rev
Log:
Basic: thread TargetOptions into TargetInfo

This threads TargetOptions into the TargetInfo hierarchy.  This is a rework of
the original attempt to thread additional information into the TargetInfo to
make decisions based on additional ABI related options.

Modified:
cfe/trunk/lib/Basic/Targets.cpp

Modified: cfe/trunk/lib/Basic/Targets.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=265878&r1=265877&r2=265878&view=diff
==
--- cfe/trunk/lib/Basic/Targets.cpp (original)
+++ cfe/trunk/lib/Basic/Targets.cpp Sat Apr  9 14:09:25 2016
@@ -76,7 +76,8 @@ protected:
   virtual void getOSDefines(const LangOptions &Opts, const llvm::Triple 
&Triple,
 MacroBuilder &Builder) const=0;
 public:
-  OSTargetInfo(const llvm::Triple &Triple) : TgtInfo(Triple) {}
+  OSTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
+  : TgtInfo(Triple, Opts) {}
   void getTargetDefines(const LangOptions &Opts,
 MacroBuilder &Builder) const override {
 TgtInfo::getTargetDefines(Opts, Builder);
@@ -101,8 +102,8 @@ protected:
   }
 
 public:
-  CloudABITargetInfo(const llvm::Triple &Triple)
-  : OSTargetInfo(Triple) {}
+  CloudABITargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
+  : OSTargetInfo(Triple, Opts) {}
 };
 
 static void getDarwinDefines(MacroBuilder &Builder, const LangOptions &Opts,
@@ -220,7 +221,8 @@ protected:
   }
 
 public:
-  DarwinTargetInfo(const llvm::Triple &Triple) : OSTargetInfo(Triple) {
+  DarwinTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
+  : OSTargetInfo(Triple, Opts) {
 // By default, no TLS, and we whitelist permitted architecture/OS
 // combinations.
 this->TLSSupported = false;
@@ -287,8 +289,8 @@ protected:
 DefineStd(Builder, "unix", Opts);
   }
 public:
-  DragonFlyBSDTargetInfo(const llvm::Triple &Triple)
-  : OSTargetInfo(Triple) {
+  DragonFlyBSDTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
+  : OSTargetInfo(Triple, Opts) {
 switch (Triple.getArch()) {
 default:
 case llvm::Triple::x86:
@@ -329,7 +331,8 @@ protected:
 Builder.defineMacro("__STDC_MB_MIGHT_NEQ_WC__", "1");
   }
 public:
-  FreeBSDTargetInfo(const llvm::Triple &Triple) : OSTargetInfo(Triple) 
{
+  FreeBSDTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
+  : OSTargetInfo(Triple, Opts) {
 switch (Triple.getArch()) {
 default:
 case llvm::Triple::x86:
@@ -368,8 +371,8 @@ protected:
   Builder.defineMacro("_GNU_SOURCE");
   }
 public:
-  KFreeBSDTargetInfo(const llvm::Triple &Triple)
-  : OSTargetInfo(Triple) {}
+  KFreeBSDTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
+  : OSTargetInfo(Triple, Opts) {}
 };
 
 // Minix Target
@@ -391,7 +394,8 @@ protected:
 DefineStd(Builder, "unix", Opts);
   }
 public:
-  MinixTargetInfo(const llvm::Triple &Triple) : OSTargetInfo(Triple) {}
+  MinixTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
+  : OSTargetInfo(Triple, Opts) {}
 };
 
 // Linux target
@@ -418,7 +422,8 @@ protected:
   Builder.defineMacro("_GNU_SOURCE");
   }
 public:
-  LinuxTargetInfo(const llvm::Triple &Triple) : OSTargetInfo(Triple) {
+  LinuxTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
+  : OSTargetInfo(Triple, Opts) {
 this->WIntType = TargetInfo::UnsignedInt;
 
 switch (Triple.getArch()) {
@@ -462,7 +467,8 @@ protected:
 }
   }
 public:
-  NetBSDTargetInfo(const llvm::Triple &Triple) : OSTargetInfo(Triple) {
+  NetBSDTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
+  : OSTargetInfo(Triple, Opts) {
 this->MCountName = "_mcount";
   }
 };
@@ -482,7 +488,8 @@ protected:
   Builder.defineMacro("_REENTRANT");
   }
 public:
-  OpenBSDTargetInfo(const llvm::Triple &Triple) : OSTargetInfo(Triple) 
{
+  OpenBSDTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
+  : OSTargetInfo(Triple, Opts) {
 this->TLSSupported = false;
 
   switch (Triple.getArch()) {
@@ -529,7 +536,8 @@ protected:
 }
   }
 public:
-  BitrigTargetInfo(const llvm::Triple &Triple) : OSTargetInfo(Triple) {
+  BitrigTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
+  : OSTargetInfo(Triple, Opts) {
 this->MCountName = "__mcount";
   }
 };
@@ -566,7 +574,8 @@ protected:
 Builder.defineMacro("__powerpc64__");
   }
 public:
-  PS3PPUTargetInfo(const llvm::Triple &Triple) : OSTargetInfo(Triple) {
+  PS3PPUTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
+  : OSTargetInfo(Triple, Opts) {
 this->LongWidth = this->LongAlign = 32;
 this->PointerWidth = this->PointerAlign = 32;
 this->IntMaxType = TargetInfo::Sig

Re: [PATCH] D18919: [Clang-tidy] Add check "modernize use using"

2016-04-09 Thread Piotr Padlewski via cfe-commits
Prazek added inline comments.


Comment at: clang-tidy/modernize/UseUsingCheck.cpp:26
@@ +25,3 @@
+/// AST representation of type.
+std::string removeExtraASTWords(std::string subject) {
+  std::pair subs[] = {

add static 


Comment at: clang-tidy/modernize/UseUsingCheck.cpp:27
@@ +26,3 @@
+std::string removeExtraASTWords(std::string subject) {
+  std::pair subs[] = {
+  {"class ", ""}, {"struct ", ""}, {"union ", ""}, {"(void)", "()"}};

Stick to the LLVM coding style - local variables starts with capital letter.
Also add const here


Comment at: clang-tidy/modernize/UseUsingCheck.cpp:32-35
@@ +31,6 @@
+std::string replace = p.second;
+size_t pos = 0;
+while ((pos = subject.find(search, pos)) != std::string::npos) {
+  subject.replace(pos, search.length(), replace);
+  pos += replace.length();
+}

you can extract this to another static function 
static void replaceAll(std::string &s, const std::string &search, const 
std::string replace);


Comment at: clang-tidy/modernize/UseUsingCheck.cpp:48
@@ +47,3 @@
+  << FixItHint::CreateReplacement(
+ MatchedDecl->getSourceRange(),
+ "using " + MatchedDecl->getNameAsString() + " = " +

check if it is clang-formatted


Repository:
  rL LLVM

http://reviews.llvm.org/D18919



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


Re: [PATCH] D18868: [Sema] PR27155: Fix a template argument deduction bug with base classes

2016-04-09 Thread Erik Pilkington via cfe-commits
erik.pilkington updated this revision to Diff 53164.
erik.pilkington marked an inline comment as done.
erik.pilkington added a comment.

Avoid another copy when Arg is not a record type.

Richard: I don't think it's possible to avoid copying Deduced when Arg is not a 
complete type, because we only try to complete it when we know that the 
deduction would otherwise fail (therefore clobbering Deduced).

If this looks good, would you mind committing it? Thanks for reviewing!


http://reviews.llvm.org/D18868

Files:
  lib/Sema/SemaTemplateDeduction.cpp
  test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.call/p3.cpp

Index: test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.call/p3.cpp
===
--- test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.call/p3.cpp
+++ test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.call/p3.cpp
@@ -146,3 +146,17 @@
   }
 
 }
+
+namespace PR27155 {
+
+struct B {};
+
+template struct D : T {};
+template void Foo(D);
+
+int fn() {
+  D, 0> f;
+  Foo(f);
+}
+
+}
Index: lib/Sema/SemaTemplateDeduction.cpp
===
--- lib/Sema/SemaTemplateDeduction.cpp
+++ lib/Sema/SemaTemplateDeduction.cpp
@@ -1418,87 +1418,94 @@
 // TT
 // TT<>
 case Type::TemplateSpecialization: {
-  const TemplateSpecializationType *SpecParam
-= cast(Param);
-
-  // Try to deduce template arguments from the template-id.
-  Sema::TemplateDeductionResult Result
-= DeduceTemplateArguments(S, TemplateParams, SpecParam, Arg,
-  Info, Deduced);
-
-  if (Result && (TDF & TDF_DerivedClass)) {
-// C++ [temp.deduct.call]p3b3:
-//   If P is a class, and P has the form template-id, then A can be a
-//   derived class of the deduced A. Likewise, if P is a pointer to a
-//   class of the form template-id, A can be a pointer to a derived
-//   class pointed to by the deduced A.
-//
-// More importantly:
-//   These alternatives are considered only if type deduction would
-//   otherwise fail.
-if (const RecordType *RecordT = Arg->getAs()) {
-  // We cannot inspect base classes as part of deduction when the type
-  // is incomplete, so either instantiate any templates necessary to
-  // complete the type, or skip over it if it cannot be completed.
-  if (!S.isCompleteType(Info.getLocation(), Arg))
-return Result;
-
-  // Use data recursion to crawl through the list of base classes.
-  // Visited contains the set of nodes we have already visited, while
-  // ToVisit is our stack of records that we still need to visit.
-  llvm::SmallPtrSet Visited;
-  SmallVector ToVisit;
-  ToVisit.push_back(RecordT);
-  bool Successful = false;
-  SmallVector DeducedOrig(Deduced.begin(),
-  Deduced.end());
-  while (!ToVisit.empty()) {
-// Retrieve the next class in the inheritance hierarchy.
-const RecordType *NextT = ToVisit.pop_back_val();
-
-// If we have already seen this type, skip it.
-if (!Visited.insert(NextT).second)
-  continue;
-
-// If this is a base class, try to perform template argument
-// deduction from it.
-if (NextT != RecordT) {
-  TemplateDeductionInfo BaseInfo(Info.getLocation());
-  Sema::TemplateDeductionResult BaseResult
-= DeduceTemplateArguments(S, TemplateParams, SpecParam,
-  QualType(NextT, 0), BaseInfo,
-  Deduced);
-
-  // If template argument deduction for this base was successful,
-  // note that we had some success. Otherwise, ignore any deductions
-  // from this base class.
-  if (BaseResult == Sema::TDK_Success) {
-Successful = true;
-DeducedOrig.clear();
-DeducedOrig.append(Deduced.begin(), Deduced.end());
-Info.Param = BaseInfo.Param;
-Info.FirstArg = BaseInfo.FirstArg;
-Info.SecondArg = BaseInfo.SecondArg;
-  }
-  else
-Deduced = DeducedOrig;
-}
-
-// Visit base classes
-CXXRecordDecl *Next = cast(NextT->getDecl());
-for (const auto &Base : Next->bases()) {
-  assert(Base.getType()->isRecordType() &&
- "Base class that isn't a record?");
-  ToVisit.push_back(Base.getType()->getAs());
-}
-  }
+  const TemplateSpecializationType *SpecParam =
+  cast(Param);
+
+  // When Arg cannot be a derived class, we can just try to deduce template

r265888 - Add support for __gnu_mcount_nc as the pg interface

2016-04-09 Thread Saleem Abdulrasool via cfe-commits
Author: compnerd
Date: Sat Apr  9 22:19:47 2016
New Revision: 265888

URL: http://llvm.org/viewvc/llvm-project?rev=265888&view=rev
Log:
Add support for __gnu_mcount_nc as the pg interface

This adds support to optionally support using `__gnu_mcount_nc` as the mcount
interface rather than `mcount` for Linux and EABI.  The other targets do not
provide an implementation for `__gnu_mcount_nc`.  This can be activated via the
`-meabi gnu` flag.

Resolves PR23969.

Added:
cfe/trunk/test/Frontend/gnu-mcount.c
Modified:
cfe/trunk/lib/Basic/Targets.cpp

Modified: cfe/trunk/lib/Basic/Targets.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/Targets.cpp?rev=265888&r1=265887&r2=265888&view=diff
==
--- cfe/trunk/lib/Basic/Targets.cpp (original)
+++ cfe/trunk/lib/Basic/Targets.cpp Sat Apr  9 22:19:47 2016
@@ -4675,6 +4675,11 @@ public:
 // that follows it, `bar', `bar' will be aligned as the  type of the
 // zero length bitfield.
 UseZeroLengthBitfieldAlignment = true;
+
+if (Triple.getOS() == llvm::Triple::Linux ||
+Triple.getOS() == llvm::Triple::UnknownOS)
+  this->MCountName =
+  Opts.EABIVersion == "gnu" ? "\01__gnu_mcount_nc" : "\01mcount";
   }
 
   StringRef getABI() const override { return ABI; }
@@ -5423,9 +5428,8 @@ class AArch64TargetInfo : public TargetI
   std::string ABI;
 
 public:
-  AArch64TargetInfo(const llvm::Triple &Triple, const TargetOptions &)
+  AArch64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
   : TargetInfo(Triple), ABI("aapcs") {
-
 if (getTriple().getOS() == llvm::Triple::NetBSD) {
   WCharType = SignedInt;
 
@@ -5460,6 +5464,11 @@ public:
 
 // AArch64 targets default to using the ARM C++ ABI.
 TheCXXABI.set(TargetCXXABI::GenericAArch64);
+
+if (Triple.getOS() == llvm::Triple::Linux ||
+Triple.getOS() == llvm::Triple::UnknownOS)
+  this->MCountName =
+  Opts.EABIVersion == "gnu" ? "\01__gnu_mcount_nc" : "\01mcount";
   }
 
   StringRef getABI() const override { return ABI; }

Added: cfe/trunk/test/Frontend/gnu-mcount.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Frontend/gnu-mcount.c?rev=265888&view=auto
==
--- cfe/trunk/test/Frontend/gnu-mcount.c (added)
+++ cfe/trunk/test/Frontend/gnu-mcount.c Sat Apr  9 22:19:47 2016
@@ -0,0 +1,44 @@
+// RUN: %clang -target armv7-unknown-none-eabi -pg -S -emit-llvm -o - %s | 
FileCheck %s -check-prefix CHECK -check-prefix CHECK-ARM-EABI
+// RUN: %clang -target armv7-unknown-none-eabi -pg -meabi gnu -S -emit-llvm -o 
- %s | FileCheck %s -check-prefix CHECK -check-prefix CHECK-ARM-EABI-MEABI-GNU
+// RUN: %clang -target armv7-unknown-linux-gnueabi -pg -S -emit-llvm -o - %s | 
FileCheck %s -check-prefix CHECK -check-prefix CHECK-ARM-EABI
+// RUN: %clang -target armv7-unknown-linux-gnueabi -meabi gnu -pg -S 
-emit-llvm -o - %s | FileCheck %s -check-prefix CHECK -check-prefix 
CHECK-ARM-EABI-MEABI-GNU
+// RUN: %clang -target armv7-unknown-linux-gnueabihf -pg -S -emit-llvm -o - %s 
| FileCheck %s -check-prefix CHECK -check-prefix CHECK-ARM-EABI
+// RUN: %clang -target armv7-unknown-linux-gnueabihf -meabi gnu -pg -S 
-emit-llvm -o - %s | FileCheck %s -check-prefix CHECK -check-prefix 
CHECK-ARM-EABI-MEABI-GNU
+// RUN: %clang -target armv7-unknown-freebsd-gnueabihf -pg -S -emit-llvm -o - 
%s | FileCheck %s -check-prefix CHECK -check-prefix CHECK-ARM-EABI-FREEBSD
+// RUN: %clang -target armv7-unknown-freebsd-gnueabihf -meabi gnu -pg -S 
-emit-llvm -o - %s | FileCheck %s -check-prefix CHECK -check-prefix 
CHECK-ARM-EABI-FREEBSD
+// RUN: %clang -target armv7-unknown-openbsd-gnueabihf -pg -S -emit-llvm -o - 
%s | FileCheck %s -check-prefix CHECK -check-prefix CHECK-ARM-EABI-OPENBSD
+// RUN: %clang -target armv7-unknown-openbsd-gnueabihf -meabi gnu -pg -S 
-emit-llvm -o - %s | FileCheck %s -check-prefix CHECK -check-prefix 
CHECK-ARM-EABI-OPENBSD
+// RUN: %clang -target armv7-unknown-netbsd-gnueabihf -pg -S -emit-llvm -o - 
%s | FileCheck %s -check-prefix CHECK -check-prefix CHECK-ARM-EABI-NETBSD
+// RUN: %clang -target armv7-unknown-netbsd-gnueabihf -meabi gnu -pg -S 
-emit-llvm -o - %s | FileCheck %s -check-prefix CHECK -check-prefix 
CHECK-ARM-EABI-NETBSD
+// RUN: %clang -target armv7-apple-ios -pg -S -emit-llvm -o - %s | FileCheck 
%s -check-prefix CHECK -check-prefix CHECK-ARM-IOS
+// RUN: %clang -target armv7-apple-ios -pg -meabi gnu -S -emit-llvm -o - %s | 
FileCheck %s -check-prefix CHECK -check-prefix CHECK-ARM-IOS
+// RUN: %clang -target armv7-unknown-bitrig-gnueabihf -pg -S -emit-llvm -o - 
%s | FileCheck %s -check-prefix CHECK -check-prefix CHECK-ARM-EABI-BIGRIG
+// RUN: %clang -target armv7-unknown-bitrig-gnueabihf -meabi gnu -pg -S 
-emit-llvm -o - %s | FileCheck %s -check-prefix CHECK -check-prefix 
CHECK-ARM-EABI-BIGRIG
+// RUN: %clang -target armv7-unknown-rtems-g

r265889 - test: add additional tests for SVN r265888

2016-04-09 Thread Saleem Abdulrasool via cfe-commits
Author: compnerd
Date: Sat Apr  9 22:31:09 2016
New Revision: 265889

URL: http://llvm.org/viewvc/llvm-project?rev=265889&view=rev
Log:
test: add additional tests for SVN r265888

Add test cases for AArch64 as well as that was changed as part of that change.

Modified:
cfe/trunk/test/Frontend/gnu-mcount.c

Modified: cfe/trunk/test/Frontend/gnu-mcount.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Frontend/gnu-mcount.c?rev=265889&r1=265888&r2=265889&view=diff
==
--- cfe/trunk/test/Frontend/gnu-mcount.c (original)
+++ cfe/trunk/test/Frontend/gnu-mcount.c Sat Apr  9 22:31:09 2016
@@ -1,23 +1,43 @@
 // RUN: %clang -target armv7-unknown-none-eabi -pg -S -emit-llvm -o - %s | 
FileCheck %s -check-prefix CHECK -check-prefix CHECK-ARM-EABI
 // RUN: %clang -target armv7-unknown-none-eabi -pg -meabi gnu -S -emit-llvm -o 
- %s | FileCheck %s -check-prefix CHECK -check-prefix CHECK-ARM-EABI-MEABI-GNU
+// RUN: %clang -target aarch64-unknown-none-eabi -pg -S -emit-llvm -o - %s | 
FileCheck %s -check-prefix CHECK -check-prefix CHECK-ARM-EABI
+// RUN: %clang -target aarch64-unknown-none-eabi -pg -meabi gnu -S -emit-llvm 
-o - %s | FileCheck %s -check-prefix CHECK -check-prefix 
CHECK-ARM-EABI-MEABI-GNU
 // RUN: %clang -target armv7-unknown-linux-gnueabi -pg -S -emit-llvm -o - %s | 
FileCheck %s -check-prefix CHECK -check-prefix CHECK-ARM-EABI
 // RUN: %clang -target armv7-unknown-linux-gnueabi -meabi gnu -pg -S 
-emit-llvm -o - %s | FileCheck %s -check-prefix CHECK -check-prefix 
CHECK-ARM-EABI-MEABI-GNU
+// RUN: %clang -target aarch64-unknown-linux-gnueabi -pg -S -emit-llvm -o - %s 
| FileCheck %s -check-prefix CHECK -check-prefix CHECK-ARM-EABI
+// RUN: %clang -target aarch64-unknown-linux-gnueabi -meabi gnu -pg -S 
-emit-llvm -o - %s | FileCheck %s -check-prefix CHECK -check-prefix 
CHECK-ARM-EABI-MEABI-GNU
 // RUN: %clang -target armv7-unknown-linux-gnueabihf -pg -S -emit-llvm -o - %s 
| FileCheck %s -check-prefix CHECK -check-prefix CHECK-ARM-EABI
 // RUN: %clang -target armv7-unknown-linux-gnueabihf -meabi gnu -pg -S 
-emit-llvm -o - %s | FileCheck %s -check-prefix CHECK -check-prefix 
CHECK-ARM-EABI-MEABI-GNU
+// RUN: %clang -target aarch64-unknown-linux-gnueabihf -pg -S -emit-llvm -o - 
%s | FileCheck %s -check-prefix CHECK -check-prefix CHECK-ARM-EABI
+// RUN: %clang -target aarch64-unknown-linux-gnueabihf -meabi gnu -pg -S 
-emit-llvm -o - %s | FileCheck %s -check-prefix CHECK -check-prefix 
CHECK-ARM-EABI-MEABI-GNU
 // RUN: %clang -target armv7-unknown-freebsd-gnueabihf -pg -S -emit-llvm -o - 
%s | FileCheck %s -check-prefix CHECK -check-prefix CHECK-ARM-EABI-FREEBSD
 // RUN: %clang -target armv7-unknown-freebsd-gnueabihf -meabi gnu -pg -S 
-emit-llvm -o - %s | FileCheck %s -check-prefix CHECK -check-prefix 
CHECK-ARM-EABI-FREEBSD
+// RUN: %clang -target aarch64-unknown-freebsd-gnueabihf -pg -S -emit-llvm -o 
- %s | FileCheck %s -check-prefix CHECK -check-prefix CHECK-ARM64-EABI-FREEBSD
+// RUN: %clang -target aarch64-unknown-freebsd-gnueabihf -meabi gnu -pg -S 
-emit-llvm -o - %s | FileCheck %s -check-prefix CHECK -check-prefix 
CHECK-ARM64-EABI-FREEBSD
 // RUN: %clang -target armv7-unknown-openbsd-gnueabihf -pg -S -emit-llvm -o - 
%s | FileCheck %s -check-prefix CHECK -check-prefix CHECK-ARM-EABI-OPENBSD
 // RUN: %clang -target armv7-unknown-openbsd-gnueabihf -meabi gnu -pg -S 
-emit-llvm -o - %s | FileCheck %s -check-prefix CHECK -check-prefix 
CHECK-ARM-EABI-OPENBSD
+// RUN: %clang -target aarch64-unknown-openbsd-gnueabihf -pg -S -emit-llvm -o 
- %s | FileCheck %s -check-prefix CHECK -check-prefix CHECK-ARM64-EABI-OPENBSD
+// RUN: %clang -target aarch64-unknown-openbsd-gnueabihf -meabi gnu -pg -S 
-emit-llvm -o - %s | FileCheck %s -check-prefix CHECK -check-prefix 
CHECK-ARM64-EABI-OPENBSD
 // RUN: %clang -target armv7-unknown-netbsd-gnueabihf -pg -S -emit-llvm -o - 
%s | FileCheck %s -check-prefix CHECK -check-prefix CHECK-ARM-EABI-NETBSD
 // RUN: %clang -target armv7-unknown-netbsd-gnueabihf -meabi gnu -pg -S 
-emit-llvm -o - %s | FileCheck %s -check-prefix CHECK -check-prefix 
CHECK-ARM-EABI-NETBSD
+// RUN: %clang -target aarch64-unknown-netbsd-gnueabihf -pg -S -emit-llvm -o - 
%s | FileCheck %s -check-prefix CHECK -check-prefix CHECK-ARM-EABI-NETBSD
+// RUN: %clang -target aarch64-unknown-netbsd-gnueabihf -meabi gnu -pg -S 
-emit-llvm -o - %s | FileCheck %s -check-prefix CHECK -check-prefix 
CHECK-ARM-EABI-NETBSD
 // RUN: %clang -target armv7-apple-ios -pg -S -emit-llvm -o - %s | FileCheck 
%s -check-prefix CHECK -check-prefix CHECK-ARM-IOS
 // RUN: %clang -target armv7-apple-ios -pg -meabi gnu -S -emit-llvm -o - %s | 
FileCheck %s -check-prefix CHECK -check-prefix CHECK-ARM-IOS
+// RUN: %clang -target arm64-apple-ios -pg -S -emit-llvm -o - %s | FileCheck 
%s -check-prefix CHECK -check-prefix CHECK-ARM-IOS
+// RUN: %clang -target arm64-apple-ios -pg -meabi gnu -S -emit-llvm -o - %s | 
FileCheck %s -check-prefix CH