[PATCH] D41458: [libc++][C++17] Elementary string conversions for integral types

2018-01-01 Thread Zhihao Yuan via Phabricator via cfe-commits
lichray updated this revision to Diff 128393.
lichray added a comment.

Just include math.h


Repository:
  rCXX libc++

https://reviews.llvm.org/D41458

Files:
  .gitignore
  include/charconv
  include/support/itoa/
  include/support/itoa/itoa.h
  lib/CMakeLists.txt
  src/support/itoa/
  src/support/itoa/itoa.cpp
  test/std/utilities/charconv/
  test/std/utilities/charconv/charconv.from.chars/
  test/std/utilities/charconv/charconv.from.chars/integral.bool.fail.cpp
  test/std/utilities/charconv/charconv.from.chars/integral.pass.cpp
  test/std/utilities/charconv/charconv.to.chars/
  test/std/utilities/charconv/charconv.to.chars/integral.bool.fail.cpp
  test/std/utilities/charconv/charconv.to.chars/integral.pass.cpp
  test/support/charconv_test_helpers.h

Index: test/support/charconv_test_helpers.h
===
--- /dev/null
+++ test/support/charconv_test_helpers.h
@@ -0,0 +1,233 @@
+//===--===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===//
+
+#ifndef SUPPORT_CHARCONV_TEST_HELPERS_H
+#define SUPPORT_CHARCONV_TEST_HELPERS_H
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "test_macros.h"
+
+using std::false_type;
+using std::true_type;
+
+template 
+constexpr auto
+is_non_narrowing(From a) -> decltype(To{a}, true_type())
+{
+return {};
+}
+
+template 
+constexpr auto
+is_non_narrowing(...) -> false_type
+{
+return {};
+}
+
+template 
+constexpr bool
+_fits_in(T, true_type /* non-narrowing*/, ...)
+{
+return true;
+}
+
+template >
+constexpr bool
+_fits_in(T v, false_type, true_type /* T signed*/, true_type /* X signed */)
+{
+return xl::lowest() <= v && v <= (xl::max)();
+}
+
+template >
+constexpr bool
+_fits_in(T v, false_type, true_type /* T signed */, false_type /* X unsigned*/)
+{
+return 0 <= v && typename std::make_unsigned::type(v) <= (xl::max)();
+}
+
+template >
+constexpr bool
+_fits_in(T v, false_type, false_type /* T unsigned */, ...)
+{
+return v <= typename std::make_unsigned::type((xl::max)());
+}
+
+template 
+constexpr bool
+fits_in(T v)
+{
+return _fits_in(v, is_non_narrowing(v), std::is_signed(),
+   std::is_signed());
+}
+
+template 
+struct to_chars_test_base
+{
+template 
+void test(T v, char const ()[N], Ts... args)
+{
+using std::to_chars;
+std::to_chars_result r;
+
+constexpr size_t len = N - 1;
+static_assert(len > 0, "expected output won't be empty");
+
+if (!fits_in(v))
+return;
+
+r = to_chars(buf, buf + len - 1, X(v), args...);
+LIBCPP_ASSERT(r.ptr == buf + len - 1);
+LIBCPP_ASSERT(r.ec == std::errc::value_too_large);
+
+r = to_chars(buf, buf + sizeof(buf), X(v), args...);
+LIBCPP_ASSERT(r.ptr == buf + len);
+LIBCPP_ASSERT(r.ec == std::errc{});
+LIBCPP_ASSERT(memcmp(buf, expect, len) == 0);
+}
+
+template 
+void test_value(X v, Ts... args)
+{
+using std::to_chars;
+std::to_chars_result r;
+
+r = to_chars(buf, buf + sizeof(buf), v, args...);
+LIBCPP_ASSERT(r.ec == std::errc{});
+*r.ptr = '\0';
+
+auto a = fromchars(buf, r.ptr, args...);
+LIBCPP_ASSERT(v == a);
+
+auto ep = r.ptr - 1;
+r = to_chars(buf, ep, v, args...);
+LIBCPP_ASSERT(r.ptr == ep);
+LIBCPP_ASSERT(r.ec == std::errc::value_too_large);
+}
+
+private:
+using max_t = typename std::conditional::type;
+
+static auto fromchars(char const* p, char const* ep, int base, true_type)
+-> long long
+{
+char* last;
+auto r = strtoll(p, , base);
+LIBCPP_ASSERT(last == ep);
+
+return r;
+}
+
+static auto fromchars(char const* p, char const* ep, int base, false_type)
+-> unsigned long long
+{
+char* last;
+auto r = strtoull(p, , base);
+LIBCPP_ASSERT(last == ep);
+
+return r;
+}
+
+static auto fromchars(char const* p, char const* ep, int base = 10) -> max_t
+{
+return fromchars(p, ep, base, std::is_signed());
+}
+
+char buf[100];
+};
+
+template 
+struct roundtrip_test_base
+{
+template 
+void test(T v, Ts... args)
+{
+using std::from_chars;
+using std::to_chars;
+std::from_chars_result r2;
+std::to_chars_result r;
+X x = 0xc;
+
+if (fits_in(v))
+{
+r = to_chars(buf, buf + sizeof(buf), v, args...);
+LIBCPP_ASSERT(r.ec == std::errc{});
+
+r2 = from_chars(buf, 

[PATCH] D40787: [clang-tidy] Replace the usage of std::uncaught_exception with std::uncaught_exceptions

2018-01-01 Thread Daniel Kolozsvari via Phabricator via cfe-commits
koldaniel added inline comments.



Comment at: clang-tidy/modernize/UseUncaughtExceptionsCheck.cpp:66-67
+}
+Diag << FixItHint::CreateInsertion(BeginLoc.getLocWithOffset(TextLength),
+   "s");
+  }

aaron.ballman wrote:
> koldaniel wrote:
> > aaron.ballman wrote:
> > > Same concerns here as with the previous review: This fixit can break code 
> > > if the code disallows narrowing conversions. e.g.,
> > > ```
> > > bool b{std::uncaught_exception()};
> > > ```
> > > In this case, the fixit will take the deprecated code and make it 
> > > ill-formed instead. Perhaps a better fix-it would be to transform the 
> > > code into (std::uncaught_exceptions() > 0) to keep the resulting 
> > > expression type a bool and still not impact operator precedence. 
> > > Alternatively, you can identify the narrowing conversion case and skip 
> > > the fix-it entirely in that case (only warn).
> > > 
> > > This example should be a test case.
> > If the fix-it would be a transformation to std::uncaught_exceptions() > 0, 
> > the code will break in some cases, for example in case of function pointers 
> > or template instantiations. Narrowing conversions would not lead to errors, 
> > functionality of the code would remain the same.
> > If the fix-it would be a transformation to std::uncaught_exceptions() > 0, 
> > the code will break in some cases, for example in case of function pointers 
> > or template instantiations.
> 
> Very true, this check encompasses more than call expressions, which was 
> another concern of mine. For instance, the function pointer case will also 
> result in the fix-it breaking code. Further, it may change SFINAE results 
> (though changes in SFINAE contexts are less of a concern).
> 
> > Narrowing conversions would not lead to errors, functionality of the code 
> > would remain the same.
> 
> Incorrect; the narrowing conversion will lead to an error depending on the 
> context. https://godbolt.org/g/v8tCWM
Fair point, which confused me is that there is no such issue when compiling the 
code with gcc instead of clang. In this case, I think the way forward would be 
to separate the AST-matchers, and apply a transformation like you proposed when 
needed.


https://reviews.llvm.org/D40787



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


[PATCH] D40787: [clang-tidy] Replace the usage of std::uncaught_exception with std::uncaught_exceptions

2018-01-01 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang-tidy/modernize/UseUncaughtExceptionsCheck.cpp:66-67
+}
+Diag << FixItHint::CreateInsertion(BeginLoc.getLocWithOffset(TextLength),
+   "s");
+  }

koldaniel wrote:
> aaron.ballman wrote:
> > Same concerns here as with the previous review: This fixit can break code 
> > if the code disallows narrowing conversions. e.g.,
> > ```
> > bool b{std::uncaught_exception()};
> > ```
> > In this case, the fixit will take the deprecated code and make it 
> > ill-formed instead. Perhaps a better fix-it would be to transform the code 
> > into (std::uncaught_exceptions() > 0) to keep the resulting expression type 
> > a bool and still not impact operator precedence. Alternatively, you can 
> > identify the narrowing conversion case and skip the fix-it entirely in that 
> > case (only warn).
> > 
> > This example should be a test case.
> If the fix-it would be a transformation to std::uncaught_exceptions() > 0, 
> the code will break in some cases, for example in case of function pointers 
> or template instantiations. Narrowing conversions would not lead to errors, 
> functionality of the code would remain the same.
> If the fix-it would be a transformation to std::uncaught_exceptions() > 0, 
> the code will break in some cases, for example in case of function pointers 
> or template instantiations.

Very true, this check encompasses more than call expressions, which was another 
concern of mine. For instance, the function pointer case will also result in 
the fix-it breaking code. Further, it may change SFINAE results (though changes 
in SFINAE contexts are less of a concern).

> Narrowing conversions would not lead to errors, functionality of the code 
> would remain the same.

Incorrect; the narrowing conversion will lead to an error depending on the 
context. https://godbolt.org/g/v8tCWM


https://reviews.llvm.org/D40787



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


[PATCH] D40787: [clang-tidy] Replace the usage of std::uncaught_exception with std::uncaught_exceptions

2018-01-01 Thread Daniel Kolozsvari via Phabricator via cfe-commits
koldaniel added inline comments.



Comment at: clang-tidy/modernize/UseUncaughtExceptionsCheck.cpp:66-67
+}
+Diag << FixItHint::CreateInsertion(BeginLoc.getLocWithOffset(TextLength),
+   "s");
+  }

aaron.ballman wrote:
> Same concerns here as with the previous review: This fixit can break code if 
> the code disallows narrowing conversions. e.g.,
> ```
> bool b{std::uncaught_exception()};
> ```
> In this case, the fixit will take the deprecated code and make it ill-formed 
> instead. Perhaps a better fix-it would be to transform the code into 
> (std::uncaught_exceptions() > 0) to keep the resulting expression type a bool 
> and still not impact operator precedence. Alternatively, you can identify the 
> narrowing conversion case and skip the fix-it entirely in that case (only 
> warn).
> 
> This example should be a test case.
If the fix-it would be a transformation to std::uncaught_exceptions() > 0, the 
code will break in some cases, for example in case of function pointers or 
template instantiations. Narrowing conversions would not lead to errors, 
functionality of the code would remain the same.


https://reviews.llvm.org/D40787



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


[PATCH] D41512: [Sema] -Wtautological-constant-compare is too good. Cripple it.

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

Ping. Branching is approaching rapidly. This needs to land before that.


Repository:
  rC Clang

https://reviews.llvm.org/D41512



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


[PATCH] D40787: [clang-tidy] Replace the usage of std::uncaught_exception with std::uncaught_exceptions

2018-01-01 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang-tidy/modernize/UseUncaughtExceptionsCheck.cpp:24
+
+  const char *MatchText = "::std::uncaught_exception";
+

You might as well make this a `std::string` rather than `const char *` because 
the `hasName()` matcher accepts that datatype (removes a few implicit 
converting constructor calls).



Comment at: clang-tidy/modernize/UseUncaughtExceptionsCheck.cpp:61
+
+// we don't want to modify template definitions
+Text.consume_front("std::");

Comments are full sentences (with correct capitalization and punctuation).



Comment at: clang-tidy/modernize/UseUncaughtExceptionsCheck.cpp:66-67
+}
+Diag << FixItHint::CreateInsertion(BeginLoc.getLocWithOffset(TextLength),
+   "s");
+  }

Same concerns here as with the previous review: This fixit can break code if 
the code disallows narrowing conversions. e.g.,
```
bool b{std::uncaught_exception()};
```
In this case, the fixit will take the deprecated code and make it ill-formed 
instead. Perhaps a better fix-it would be to transform the code into 
(std::uncaught_exceptions() > 0) to keep the resulting expression type a bool 
and still not impact operator precedence. Alternatively, you can identify the 
narrowing conversion case and skip the fix-it entirely in that case (only warn).

This example should be a test case.



Comment at: clang-tidy/modernize/UseUncaughtExceptionsCheck.h:19
+
+/// This check will warn for the occurrences of std::uncaught_exception and 
replace it with
+/// std::uncaught_exceptions. Since C++17 std::uncaught_exception is 
deprecated. In case of

warn for the occurrences of -> warn on calls to
replace it -> replace them with calls to



Comment at: clang-tidy/modernize/UseUncaughtExceptionsCheck.h:20
+/// This check will warn for the occurrences of std::uncaught_exception and 
replace it with
+/// std::uncaught_exceptions. Since C++17 std::uncaught_exception is 
deprecated. In case of
+/// macro ID there will be only a warning without fixits.

Since C++17... -> std::uncaught_exception was deprecated in C++17.



Comment at: docs/clang-tidy/checks/modernize-use-uncaught-exceptions.rst:6-8
+This check will warn for the occurrences of ``std::uncaught_exception`` and
+replace it with ``std::uncaught_exceptions``. Since C++17
+``std::uncaught_exception`` is deprecated.

Same wording suggestions here as above.


https://reviews.llvm.org/D40787



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


r321628 - Again reverting an attempt to convert the DeclSpec enums into scoped enums.

2018-01-01 Thread Faisal Vali via cfe-commits
Author: faisalv
Date: Mon Jan  1 10:23:28 2018
New Revision: 321628

URL: http://llvm.org/viewvc/llvm-project?rev=321628=rev
Log:
Again reverting an attempt to convert the DeclSpec enums into scoped enums.
  - reverts r321622, r321625, and r321626.
  - the use of bit-fields is still resulting in warnings - even though we can 
use static-asserts to harden the code and ensure the bit-fields are wide 
enough.  The bots still complain of warnings being seen.
  - to silence the warnings requires specifying the bit-fields with the 
underlying enum type (as opposed to the enum type itself), which then requires 
lots of unnecessary static casts of each enumerator within DeclSpec to the 
underlying-type, which even though could be seen as implementation details, it 
does hamper readability - and given the additional litterings, makes me 
question the value of the change.

So in short - I give up (for now at least).  

Sorry about the noise.

Modified:
cfe/trunk/include/clang/AST/Type.h
cfe/trunk/include/clang/AST/TypeLoc.h
cfe/trunk/include/clang/Basic/Specifiers.h
cfe/trunk/include/clang/Parse/Parser.h
cfe/trunk/include/clang/Sema/DeclSpec.h
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/AST/Type.cpp
cfe/trunk/lib/AST/TypeLoc.cpp
cfe/trunk/lib/Parse/ParseDecl.cpp
cfe/trunk/lib/Parse/ParseDeclCXX.cpp
cfe/trunk/lib/Parse/ParseExpr.cpp
cfe/trunk/lib/Parse/ParseExprCXX.cpp
cfe/trunk/lib/Parse/ParseObjc.cpp
cfe/trunk/lib/Parse/Parser.cpp
cfe/trunk/lib/Sema/DeclSpec.cpp
cfe/trunk/lib/Sema/SemaCodeComplete.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/lib/Sema/SemaTemplate.cpp
cfe/trunk/lib/Sema/SemaTemplateVariadic.cpp
cfe/trunk/lib/Sema/SemaType.cpp
cfe/trunk/lib/Serialization/ASTWriter.cpp

Modified: cfe/trunk/include/clang/AST/Type.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=321628=321627=321628=diff
==
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Mon Jan  1 10:23:28 2018
@@ -4747,11 +4747,11 @@ public:
   }
 
   /// Converts a type specifier (DeclSpec::TST) into an elaborated type 
keyword.
-  static ElaboratedTypeKeyword getKeywordForTypeSpec(TypeSpecifierType 
TypeSpec);
+  static ElaboratedTypeKeyword getKeywordForTypeSpec(unsigned TypeSpec);
 
   /// Converts a type specifier (DeclSpec::TST) into a tag type kind.
   /// It is an error to provide a type specifier which *isn't* a tag kind here.
-  static TagTypeKind getTagTypeKindForTypeSpec(TypeSpecifierType TypeSpec);
+  static TagTypeKind getTagTypeKindForTypeSpec(unsigned TypeSpec);
 
   /// Converts a TagTypeKind into an elaborated type keyword.
   static ElaboratedTypeKeyword getKeywordForTagTypeKind(TagTypeKind Tag);

Modified: cfe/trunk/include/clang/AST/TypeLoc.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/TypeLoc.h?rev=321628=321627=321628=diff
==
--- cfe/trunk/include/clang/AST/TypeLoc.h (original)
+++ cfe/trunk/include/clang/AST/TypeLoc.h Mon Jan  1 10:23:28 2018
@@ -598,43 +598,43 @@ public:
 if (needsExtraLocalData())
   return static_cast(getWrittenBuiltinSpecs().Sign);
 else
-  return TypeSpecifierSign::TSS_unspecified;
+  return TSS_unspecified;
   }
 
   bool hasWrittenSignSpec() const {
-return getWrittenSignSpec() != TypeSpecifierSign::TSS_unspecified;
+return getWrittenSignSpec() != TSS_unspecified;
   }
 
   void setWrittenSignSpec(TypeSpecifierSign written) {
 if (needsExtraLocalData())
-  getWrittenBuiltinSpecs().Sign = static_cast(written);
+  getWrittenBuiltinSpecs().Sign = written;
   }
 
   TypeSpecifierWidth getWrittenWidthSpec() const {
 if (needsExtraLocalData())
   return static_cast(getWrittenBuiltinSpecs().Width);
 else
-  return TypeSpecifierWidth::TSW_unspecified;
+  return TSW_unspecified;
   }
 
   bool hasWrittenWidthSpec() const {
-return getWrittenWidthSpec() != TypeSpecifierWidth::TSW_unspecified;
+return getWrittenWidthSpec() != TSW_unspecified;
   }
 
   void setWrittenWidthSpec(TypeSpecifierWidth written) {
 if (needsExtraLocalData())
-  getWrittenBuiltinSpecs().Width = static_cast(written);
+  getWrittenBuiltinSpecs().Width = written;
   }
 
   TypeSpecifierType getWrittenTypeSpec() const;
 
   bool hasWrittenTypeSpec() const {
-return getWrittenTypeSpec() != TypeSpecifierType::TST_unspecified;
+return getWrittenTypeSpec() != TST_unspecified;
   }
 
   void setWrittenTypeSpec(TypeSpecifierType written) {
 if (needsExtraLocalData())
-  getWrittenBuiltinSpecs().Type = static_cast(written);
+  getWrittenBuiltinSpecs().Type = written;
   }
 
   bool hasModeAttr() const {
@@ -653,10 +653,9 @@ public:
 setBuiltinLoc(Loc);
 if 

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

2018-01-01 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman added inline comments.



Comment at: clang-tidy/bugprone/UnusedReturnValueCheck.cpp:62-63
+void UnusedReturnValueCheck::check(const MatchFinder::MatchResult ) {
+  if (const auto Matched = Result.Nodes.getNodeAs("match")) {
+diag(Matched->getLocStart(), "unused return value");
+  }

`const auto Matched` -> `const auto *Matched`

You can elide the curly braces.

The diagnostic doesn't really help the user understand what's wrong with the 
code. How about "the value returned by this function should be used" and add a 
note diagnostic that says "cast expression to void to silence warning". Also, 
you should pass in the `SourceRange` for the function call expression to the 
call to `diag()` so that it highlights the call in question.



Comment at: test/clang-tidy/bugprone-unused-return-value.cpp:200
+  increment(1);
+}

Can you also add a test for ignoring the result of a call to 
`std::empty(SomeContainerWithAnEmptyMethod)`?


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] D40787: [clang-tidy] Replace the usage of std::uncaught_exception with std::uncaught_exceptions

2018-01-01 Thread Daniel Kolozsvari via Phabricator via cfe-commits
koldaniel updated this revision to Diff 128390.

https://reviews.llvm.org/D40787

Files:
  clang-tidy/modernize/CMakeLists.txt
  clang-tidy/modernize/ModernizeTidyModule.cpp
  clang-tidy/modernize/UseUncaughtExceptionsCheck.cpp
  clang-tidy/modernize/UseUncaughtExceptionsCheck.h
  docs/ReleaseNotes.rst
  docs/clang-tidy/checks/list.rst
  docs/clang-tidy/checks/modernize-use-uncaught-exceptions.rst
  test/clang-tidy/modernize-use-uncaught-exceptions.cpp

Index: test/clang-tidy/modernize-use-uncaught-exceptions.cpp
===
--- /dev/null
+++ test/clang-tidy/modernize-use-uncaught-exceptions.cpp
@@ -0,0 +1,71 @@
+// RUN: %check_clang_tidy %s modernize-use-uncaught-exceptions %t -- -- -std=c++1z
+#define MACRO std::uncaught_exception
+// CHECK-FIXES: #define MACRO std::uncaught_exception
+
+int uncaught_exception() {
+  return 0;
+}
+
+namespace std {
+  int uncaught_exception() {
+return 0;
+  }
+}
+
+template 
+int doSomething(T t) { 
+  return t();
+  // CHECK-FIXES: return t();
+}
+
+template 
+int doSomething2() { 
+  return T();
+  // CHECK-MESSAGES: [[@LINE-1]]:12: warning: 'std::uncaught_exception' is deprecated, use 'std::uncaught_exceptions' instead
+  // CHECK-FIXES: return T();
+}
+
+int main() {
+  int res;
+
+  res = uncaught_exception();
+  // CHECK-FIXES: res = uncaught_exception();
+
+  res = doSomething(uncaught_exception);
+  // CHECK-FIXES: res = doSomething(uncaught_exception);
+
+  res = MACRO();
+  // CHECK-MESSAGES: [[@LINE-1]]:9: warning: 'std::uncaught_exception' is deprecated, use 'std::uncaught_exceptions' instead
+  // CHECK-FIXES: res = MACRO();
+
+  res = std::uncaught_exception();
+  // CHECK-MESSAGES: [[@LINE-1]]:9: warning: 'std::uncaught_exception' is deprecated, use 'std::uncaught_exceptions' instead
+  // CHECK-FIXES: res = std::uncaught_exceptions();
+
+  using std::uncaught_exception;
+  // CHECK-MESSAGES: [[@LINE-1]]:14: warning: 'std::uncaught_exception' is deprecated, use 'std::uncaught_exceptions' instead
+  // CHECK-FIXES: using std::uncaught_exceptions;
+
+  res = uncaught_exception();
+  // CHECK-MESSAGES: [[@LINE-1]]:9: warning: 'std::uncaught_exception' is deprecated, use 'std::uncaught_exceptions' instead
+  // CHECK-FIXES: res = uncaught_exceptions();
+
+  res = doSomething(std::uncaught_exception);
+  // CHECK-MESSAGES: [[@LINE-1]]:21: warning: 'std::uncaught_exception' is deprecated, use 'std::uncaught_exceptions' instead
+  // CHECK-FIXES: res = doSomething(std::uncaught_exceptions);
+
+  res = doSomething(uncaught_exception);
+  // CHECK-MESSAGES: [[@LINE-1]]:21: warning: 'std::uncaught_exception' is deprecated, use 'std::uncaught_exceptions' instead
+  // CHECK-FIXES: res = doSomething(uncaught_exceptions);
+
+  int (*foo)();
+  foo = _exception;
+  // CHECK-MESSAGES: [[@LINE-1]]:10: warning: 'std::uncaught_exception' is deprecated, use 'std::uncaught_exceptions' instead
+  // CHECK-FIXES: foo = _exceptions;
+
+  res = doSomething2();
+  // CHECK-MESSAGES: [[@LINE-1]]:22: warning: 'std::uncaught_exception' is deprecated, use 'std::uncaught_exceptions' instead
+  // CHECK-FIXES: res = doSomething2();
+
+  return res;
+}
Index: docs/clang-tidy/checks/modernize-use-uncaught-exceptions.rst
===
--- /dev/null
+++ docs/clang-tidy/checks/modernize-use-uncaught-exceptions.rst
@@ -0,0 +1,64 @@
+.. title:: clang-tidy - modernize-use-uncaught-exceptions
+
+modernize-use-uncaught-exceptions
+
+
+This check will warn for the occurrences of ``std::uncaught_exception`` and
+replace it with ``std::uncaught_exceptions``. Since C++17
+``std::uncaught_exception`` is deprecated.
+
+Below are a few examples of what kind of occurrences will be found and what
+they will be replaced with.
+
+.. code-block:: c++
+
+#define MACRO1 std::uncaught_exception
+#define MACRO2 std::uncaught_exception
+
+int uncaught_exception() {
+return 0;
+}
+
+int main() {
+int res;
+
+res = uncaught_exception();
+// No warning, since it is not the deprecated function from namespace std
+
+res = MACRO2();
+// Warning, but will not be replaced
+
+res = std::uncaught_exception();
+// Warning and replaced
+
+using std::uncaught_exception;
+// Warning and replaced
+
+res = uncaught_exception();
+// Warning and replaced
+}
+
+After applying the fixes the code will look like the following:
+
+.. code-block:: c++
+
+#define MACRO1 std::uncaught_exception
+#define MACRO2 std::uncaught_exception
+
+int uncaught_exception() {
+return 0;
+}
+
+int main() {
+int res;
+
+res = uncaught_exception();
+
+res = MACRO2();
+
+res = std::uncaught_exceptions();
+
+using std::uncaught_exceptions;
+
+res = uncaught_exceptions();
+}
\ No newline at end of file
Index: 

r321609 - [Sema] Improve diagnostics for const- and ref-qualified member functions

2018-01-01 Thread Jacob Bandes-Storch via cfe-commits
Author: jtbandes
Date: Sun Dec 31 10:27:29 2017
New Revision: 321609

URL: http://llvm.org/viewvc/llvm-project?rev=321609=rev
Log:
[Sema] Improve diagnostics for const- and ref-qualified member functions

(Re-submission of D39937 with fixed tests.)

Adjust wording for const-qualification mismatch to be a little more clear.

Also add another diagnostic for a ref qualifier mismatch, which previously 
produced a useless error (this error path is simply very old; see rL119336):

Before:
  error: cannot initialize object parameter of type 'X0' with an expression of 
type 'X0'

After:
  error: 'this' argument to member function 'rvalue' is an lvalue, but function 
has rvalue ref-qualifier

Reviewers: aaron.ballman

Reviewed By: aaron.ballman

Subscribers: lebedev.ri, cfe-commits

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

Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaOverload.cpp
cfe/trunk/test/CXX/over/over.match/over.match.funcs/p4-0x.cpp
cfe/trunk/test/CXX/stmt.stmt/stmt.iter/stmt.ranged/p1.cpp
cfe/trunk/test/SemaCXX/copy-initialization.cpp
cfe/trunk/test/SemaCXX/cxx1y-contextual-conversion-tweaks.cpp
cfe/trunk/test/SemaCXX/cxx2a-pointer-to-const-ref-member.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=321609=321608=321609=diff
==
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Sun Dec 31 10:27:29 
2017
@@ -1589,12 +1589,20 @@ def err_non_virtual_pure : Error<
 def ext_pure_function_definition : ExtWarn<
   "function definition with pure-specifier is a Microsoft extension">,
   InGroup;
-def err_implicit_object_parameter_init : Error<
-  "cannot initialize object parameter of type %0 with an expression "
-  "of type %1">;
 def err_qualified_member_of_unrelated : Error<
   "%q0 is not a member of class %1">;
 
+def err_member_function_call_bad_cvr : Error<
+  "'this' argument to member function %0 has type %1, but function is not 
marked "
+  "%select{const|restrict|const or restrict|volatile|const or volatile|"
+  "volatile or restrict|const, volatile, or restrict}2">;
+def err_member_function_call_bad_ref : Error<
+  "'this' argument to member function %0 is an %select{lvalue|rvalue}1, "
+  "but function has %select{non-const lvalue|rvalue}2 ref-qualifier">;
+def err_member_function_call_bad_type : Error<
+  "cannot initialize object parameter of type %0 with an expression "
+  "of type %1">;
+
 def warn_call_to_pure_virtual_member_function_from_ctor_dtor : Warning<
   "call to pure virtual member function %0 has undefined behavior; "
   "overrides of %0 in subclasses are not available in the "
@@ -1815,10 +1823,6 @@ def warn_temporary_array_to_pointer_deca
 def err_init_list_bad_dest_type : Error<
   "%select{|non-aggregate }0type %1 cannot be initialized with an initializer "
   "list">;
-def err_member_function_call_bad_cvr : Error<"member function %0 not viable: "
-"'this' argument has type %1, but function is not marked "
-"%select{const|restrict|const or restrict|volatile|const or volatile|"
-"volatile or restrict|const, volatile, or restrict}2">;
 
 def err_reference_bind_to_bitfield : Error<
   "%select{non-const|volatile}0 reference cannot bind to "

Modified: cfe/trunk/lib/Sema/SemaOverload.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaOverload.cpp?rev=321609=321608=321609=diff
==
--- cfe/trunk/lib/Sema/SemaOverload.cpp (original)
+++ cfe/trunk/lib/Sema/SemaOverload.cpp Sun Dec 31 10:27:29 2017
@@ -5145,7 +5145,8 @@ Sema::PerformObjectArgumentInitializatio
   *this, From->getLocStart(), From->getType(), FromClassification, Method,
   Method->getParent());
   if (ICS.isBad()) {
-if (ICS.Bad.Kind == BadConversionSequence::bad_qualifiers) {
+switch (ICS.Bad.Kind) {
+case BadConversionSequence::bad_qualifiers: {
   Qualifiers FromQs = FromRecordType.getQualifiers();
   Qualifiers ToQs = DestType.getQualifiers();
   unsigned CVR = FromQs.getCVRQualifiers() & ~ToQs.getCVRQualifiers();
@@ -5158,10 +5159,28 @@ Sema::PerformObjectArgumentInitializatio
   << Method->getDeclName();
 return ExprError();
   }
+  break;
+}
+
+case BadConversionSequence::lvalue_ref_to_rvalue:
+case BadConversionSequence::rvalue_ref_to_lvalue: {
+  bool IsRValueQualified =
+Method->getRefQualifier() == RefQualifierKind::RQ_RValue;
+  Diag(From->getLocStart(), diag::err_member_function_call_bad_ref)
+<< Method->getDeclName() << FromClassification.isRValue()
+<< IsRValueQualified;
+  Diag(Method->getLocation(), diag::note_previous_decl)
+<< Method->getDeclName();
+ 

r321626 - [Sema] Fix build with GCC

2018-01-01 Thread Benjamin Kramer via cfe-commits
Author: d0k
Date: Mon Jan  1 09:07:23 2018
New Revision: 321626

URL: http://llvm.org/viewvc/llvm-project?rev=321626=rev
Log:
[Sema] Fix build with GCC

tools/clang/lib/Sema/DeclSpec.cpp: In member function 'void 
clang::DeclSpec::Finish(clang::Sema&, const clang::PrintingPolicy&)':
tools/clang/lib/Sema/DeclSpec.cpp:1116:8: error: could not convert 
'clang::DeclSpec::TSW_unspecified' from 'const TSW {aka const 
clang::TypeSpecifierWidth}' to 'int'
tools/clang/lib/Sema/DeclSpec.cpp:1117:8: error: could not convert 
'clang::DeclSpec::TSW_short' from 'const TSW {aka const 
clang::TypeSpecifierWidth}' to 'int'
tools/clang/lib/Sema/DeclSpec.cpp:1118:8: error: could not convert 
'clang::DeclSpec::TSW_longlong' from 'const TSW {aka const 
clang::TypeSpecifierWidth}' to 'int'
tools/clang/lib/Sema/DeclSpec.cpp:1128:8: error: could not convert 
'clang::DeclSpec::TSW_long' from 'const TSW {aka const 
clang::TypeSpecifierWidth}' to 'int'

Modified:
cfe/trunk/lib/Sema/DeclSpec.cpp

Modified: cfe/trunk/lib/Sema/DeclSpec.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/DeclSpec.cpp?rev=321626=321625=321626=diff
==
--- cfe/trunk/lib/Sema/DeclSpec.cpp (original)
+++ cfe/trunk/lib/Sema/DeclSpec.cpp Mon Jan  1 09:07:23 2018
@@ -1112,7 +1112,7 @@ void DeclSpec::Finish(Sema , const Pri
   }
 
   // Validate the width of the type.
-  switch (TypeSpecWidth) {
+  switch (static_cast(TypeSpecWidth)) {
   case TSW_unspecified: break;
   case TSW_short:// short int
   case TSW_longlong: // long long int


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


r321625 - Use 'unsigned int' instead of enum bit-fields to silence some warnings from r321622

2018-01-01 Thread Faisal Vali via cfe-commits
Author: faisalv
Date: Mon Jan  1 08:36:47 2018
New Revision: 321625

URL: http://llvm.org/viewvc/llvm-project?rev=321625=rev
Log:
Use 'unsigned int' instead of enum bit-fields to silence some warnings from 
r321622
  - bots were complaining that the bit-field width was less than the width of 
the underlying type (note, underlying types of enums can not be bit-fields)
  - add static_asserts for TSS and TSW to ensure that the bit-fields can hold 
all the enumerators - and add comments next to the last enumerator warning not 
to reorder.

See https://reviews.llvm.org/rC321622 for the patch that introduced the 
warnings.

  

Modified:
cfe/trunk/include/clang/AST/TypeLoc.h
cfe/trunk/include/clang/Basic/Specifiers.h
cfe/trunk/lib/Sema/DeclSpec.cpp

Modified: cfe/trunk/include/clang/AST/TypeLoc.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/TypeLoc.h?rev=321625=321624=321625=diff
==
--- cfe/trunk/include/clang/AST/TypeLoc.h (original)
+++ cfe/trunk/include/clang/AST/TypeLoc.h Mon Jan  1 08:36:47 2018
@@ -607,7 +607,7 @@ public:
 
   void setWrittenSignSpec(TypeSpecifierSign written) {
 if (needsExtraLocalData())
-  getWrittenBuiltinSpecs().Sign = written;
+  getWrittenBuiltinSpecs().Sign = static_cast(written);
   }
 
   TypeSpecifierWidth getWrittenWidthSpec() const {
@@ -623,7 +623,7 @@ public:
 
   void setWrittenWidthSpec(TypeSpecifierWidth written) {
 if (needsExtraLocalData())
-  getWrittenBuiltinSpecs().Width = written;
+  getWrittenBuiltinSpecs().Width = static_cast(written);
   }
 
   TypeSpecifierType getWrittenTypeSpec() const;
@@ -634,7 +634,7 @@ public:
 
   void setWrittenTypeSpec(TypeSpecifierType written) {
 if (needsExtraLocalData())
-  getWrittenBuiltinSpecs().Type = written;
+  getWrittenBuiltinSpecs().Type = static_cast(written);
   }
 
   bool hasModeAttr() const {
@@ -653,9 +653,10 @@ public:
 setBuiltinLoc(Loc);
 if (needsExtraLocalData()) {
   WrittenBuiltinSpecs  = getWrittenBuiltinSpecs();
-  wbs.Sign = TypeSpecifierSign::TSS_unspecified;
-  wbs.Width = TypeSpecifierWidth::TSW_unspecified;
-  wbs.Type = TypeSpecifierType::TST_unspecified;
+  wbs.Sign = static_cast(TypeSpecifierSign::TSS_unspecified);
+  wbs.Width =
+  static_cast(TypeSpecifierWidth::TSW_unspecified);
+  wbs.Type = static_cast(TypeSpecifierType::TST_unspecified);
   wbs.ModeAttr = false;
 }
   }

Modified: cfe/trunk/include/clang/Basic/Specifiers.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Specifiers.h?rev=321625=321624=321625=diff
==
--- cfe/trunk/include/clang/Basic/Specifiers.h (original)
+++ cfe/trunk/include/clang/Basic/Specifiers.h Mon Jan  1 08:36:47 2018
@@ -26,16 +26,18 @@ namespace clang {
 TSW_unspecified,
 TSW_short,
 TSW_long,
-TSW_longlong
+TSW_longlong // This must be the last enumerator (see struct
+ // WrittenBuiltinSpecs below prior to reordering).
   };
   
   /// \brief Specifies the signedness of a type, e.g., signed or unsigned.
   enum class TypeSpecifierSign : unsigned char {
 TSS_unspecified,
 TSS_signed,
-TSS_unsigned
+TSS_unsigned // This must be the last enumerator (see struct
+ // WrittenBuiltinSpecs below prior to reordering).
   };
-  
+
   enum TypeSpecifiersPipe {
 TSP_unspecified,
 TSP_pipe
@@ -46,49 +48,61 @@ namespace clang {
 TST_unspecified,
 TST_void,
 TST_char,
-TST_wchar,// C++ wchar_t
-TST_char16,   // C++11 char16_t
-TST_char32,   // C++11 char32_t
+TST_wchar,  // C++ wchar_t
+TST_char16, // C++11 char16_t
+TST_char32, // C++11 char32_t
 TST_int,
 TST_int128,
-TST_half, // OpenCL half, ARM NEON __fp16
-TST_Float16,  // C11 extension ISO/IEC TS 18661-3
+TST_half,// OpenCL half, ARM NEON __fp16
+TST_Float16, // C11 extension ISO/IEC TS 18661-3
 TST_float,
 TST_double,
 TST_float128,
-TST_bool, // _Bool
-TST_decimal32,// _Decimal32
-TST_decimal64,// _Decimal64
-TST_decimal128,   // _Decimal128
+TST_bool,   // _Bool
+TST_decimal32,  // _Decimal32
+TST_decimal64,  // _Decimal64
+TST_decimal128, // _Decimal128
 TST_enum,
 TST_union,
 TST_struct,
-TST_class,// C++ class type
-TST_interface,// C++ (Microsoft-specific) __interface type
-TST_typename, // Typedef, C++ class-name or enum name, etc.
+TST_class, // C++ class type
+TST_interface, // C++ (Microsoft-specific) __interface type
+TST_typename,  // Typedef, C++ class-name or enum name, etc.
 TST_typeofType,
 TST_typeofExpr,
-TST_decltype, // C++11 decltype
-TST_underlyingType,   // __underlying_type for C++11
-TST_auto,  

r321623 - Fixed markup formatting

2018-01-01 Thread Serge Pavlov via cfe-commits
Author: sepavloff
Date: Mon Jan  1 07:53:16 2018
New Revision: 321623

URL: http://llvm.org/viewvc/llvm-project?rev=321623=rev
Log:
Fixed markup formatting

Modified:
cfe/trunk/docs/UsersManual.rst

Modified: cfe/trunk/docs/UsersManual.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/UsersManual.rst?rev=321623=321622=321623=diff
==
--- cfe/trunk/docs/UsersManual.rst (original)
+++ cfe/trunk/docs/UsersManual.rst Mon Jan  1 07:53:16 2018
@@ -731,7 +731,7 @@ directory where Clang resides.
 If a driver mode is specified in invocation, Clang tries to find a file 
specific
 for the specified mode. For example, if the executable file is named
 `x86_64-clang-cl`, Clang first looks for `x86_64-cl.cfg` and if it is not 
found,
-looks for `x86_64.cfg'.
+looks for `x86_64.cfg`.
 
 If the command line contains options that effectively change target 
architecture
 (these are -m32, -EL, and some others) and the configuration file starts with 
an


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


r321622 - [NFC] Modernize enums TypeSpecifierWidth, TypeSpecifierSign & TypeSpecifierType into scoped enums with underlying types.

2018-01-01 Thread Faisal Vali via cfe-commits
Author: faisalv
Date: Mon Jan  1 07:42:13 2018
New Revision: 321622

URL: http://llvm.org/viewvc/llvm-project?rev=321622=rev
Log:
[NFC] Modernize enums TypeSpecifierWidth, TypeSpecifierSign & TypeSpecifierType 
into scoped enums with underlying types.
  - Since these enums are used as bit-fields - for the bit-fields to be 
interpreted as unsigned, the underlying type must be specified as unsigned.

Previous failed attempt - wherein I did not specify an underlying type - was 
the sum of:
https://reviews.llvm.org/rC321614
https://reviews.llvm.org/rC321615


Modified:
cfe/trunk/include/clang/AST/Type.h
cfe/trunk/include/clang/AST/TypeLoc.h
cfe/trunk/include/clang/Basic/Specifiers.h
cfe/trunk/include/clang/Parse/Parser.h
cfe/trunk/include/clang/Sema/DeclSpec.h
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/lib/AST/Type.cpp
cfe/trunk/lib/AST/TypeLoc.cpp
cfe/trunk/lib/Parse/ParseDecl.cpp
cfe/trunk/lib/Parse/ParseDeclCXX.cpp
cfe/trunk/lib/Parse/ParseExpr.cpp
cfe/trunk/lib/Parse/ParseExprCXX.cpp
cfe/trunk/lib/Parse/ParseObjc.cpp
cfe/trunk/lib/Parse/Parser.cpp
cfe/trunk/lib/Sema/DeclSpec.cpp
cfe/trunk/lib/Sema/SemaCodeComplete.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/lib/Sema/SemaTemplate.cpp
cfe/trunk/lib/Sema/SemaTemplateVariadic.cpp
cfe/trunk/lib/Sema/SemaType.cpp
cfe/trunk/lib/Serialization/ASTWriter.cpp

Modified: cfe/trunk/include/clang/AST/Type.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=321622=321621=321622=diff
==
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Mon Jan  1 07:42:13 2018
@@ -4747,11 +4747,11 @@ public:
   }
 
   /// Converts a type specifier (DeclSpec::TST) into an elaborated type 
keyword.
-  static ElaboratedTypeKeyword getKeywordForTypeSpec(unsigned TypeSpec);
+  static ElaboratedTypeKeyword getKeywordForTypeSpec(TypeSpecifierType 
TypeSpec);
 
   /// Converts a type specifier (DeclSpec::TST) into a tag type kind.
   /// It is an error to provide a type specifier which *isn't* a tag kind here.
-  static TagTypeKind getTagTypeKindForTypeSpec(unsigned TypeSpec);
+  static TagTypeKind getTagTypeKindForTypeSpec(TypeSpecifierType TypeSpec);
 
   /// Converts a TagTypeKind into an elaborated type keyword.
   static ElaboratedTypeKeyword getKeywordForTagTypeKind(TagTypeKind Tag);

Modified: cfe/trunk/include/clang/AST/TypeLoc.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/TypeLoc.h?rev=321622=321621=321622=diff
==
--- cfe/trunk/include/clang/AST/TypeLoc.h (original)
+++ cfe/trunk/include/clang/AST/TypeLoc.h Mon Jan  1 07:42:13 2018
@@ -598,11 +598,11 @@ public:
 if (needsExtraLocalData())
   return static_cast(getWrittenBuiltinSpecs().Sign);
 else
-  return TSS_unspecified;
+  return TypeSpecifierSign::TSS_unspecified;
   }
 
   bool hasWrittenSignSpec() const {
-return getWrittenSignSpec() != TSS_unspecified;
+return getWrittenSignSpec() != TypeSpecifierSign::TSS_unspecified;
   }
 
   void setWrittenSignSpec(TypeSpecifierSign written) {
@@ -614,11 +614,11 @@ public:
 if (needsExtraLocalData())
   return static_cast(getWrittenBuiltinSpecs().Width);
 else
-  return TSW_unspecified;
+  return TypeSpecifierWidth::TSW_unspecified;
   }
 
   bool hasWrittenWidthSpec() const {
-return getWrittenWidthSpec() != TSW_unspecified;
+return getWrittenWidthSpec() != TypeSpecifierWidth::TSW_unspecified;
   }
 
   void setWrittenWidthSpec(TypeSpecifierWidth written) {
@@ -629,7 +629,7 @@ public:
   TypeSpecifierType getWrittenTypeSpec() const;
 
   bool hasWrittenTypeSpec() const {
-return getWrittenTypeSpec() != TST_unspecified;
+return getWrittenTypeSpec() != TypeSpecifierType::TST_unspecified;
   }
 
   void setWrittenTypeSpec(TypeSpecifierType written) {
@@ -653,9 +653,9 @@ public:
 setBuiltinLoc(Loc);
 if (needsExtraLocalData()) {
   WrittenBuiltinSpecs  = getWrittenBuiltinSpecs();
-  wbs.Sign = TSS_unspecified;
-  wbs.Width = TSW_unspecified;
-  wbs.Type = TST_unspecified;
+  wbs.Sign = TypeSpecifierSign::TSS_unspecified;
+  wbs.Width = TypeSpecifierWidth::TSW_unspecified;
+  wbs.Type = TypeSpecifierType::TST_unspecified;
   wbs.ModeAttr = false;
 }
   }

Modified: cfe/trunk/include/clang/Basic/Specifiers.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/Specifiers.h?rev=321622=321621=321622=diff
==
--- cfe/trunk/include/clang/Basic/Specifiers.h (original)
+++ cfe/trunk/include/clang/Basic/Specifiers.h Mon Jan  1 07:42:13 2018
@@ -22,7 +22,7 @@
 
 namespace clang {
   /// \brief Specifies the width of a type, e.g., short, 

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

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

Guidelines issue is here: 
https://github.com/isocpp/CppCoreGuidelines/issues/1120


Repository:
  rCTE Clang Tools Extra

https://reviews.llvm.org/D40854



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


r321621 - Enable configuration files in clang

2018-01-01 Thread Serge Pavlov via cfe-commits
Author: sepavloff
Date: Mon Jan  1 05:27:01 2018
New Revision: 321621

URL: http://llvm.org/viewvc/llvm-project?rev=321621=rev
Log:
Enable configuration files in clang

Clang is inherently a cross compiler and can generate code for any target
enabled during build. It however requires to specify many parameters in the
invocation, which could be hardcoded during configuration process in the
case of single-target compiler. The purpose of configuration files is to
make specifying clang arguments easier.

A configuration file is a collection of driver options, which are inserted
into command line before other options specified in the clang invocation.
It groups related options together and allows specifying them in simpler,
more flexible and less error prone way than just listing the options
somewhere in build scripts. Configuration file may be thought as a "macro"
that names an option set and is expanded when the driver is called.

Use of configuration files is described in `UserManual.rst`.

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

Added:
cfe/trunk/test/Driver/Inputs/config/
cfe/trunk/test/Driver/Inputs/config-1.cfg
cfe/trunk/test/Driver/Inputs/config-2.cfg
cfe/trunk/test/Driver/Inputs/config-2a.cfg
cfe/trunk/test/Driver/Inputs/config-3.cfg
cfe/trunk/test/Driver/Inputs/config-4.cfg
cfe/trunk/test/Driver/Inputs/config-5.cfg
cfe/trunk/test/Driver/Inputs/config-6.cfg
cfe/trunk/test/Driver/Inputs/config/config-4.cfg
cfe/trunk/test/Driver/Inputs/config/i386-qqq.cfg
cfe/trunk/test/Driver/Inputs/config/i386-qqq3.cfg
cfe/trunk/test/Driver/Inputs/config/x86_64-qqq.cfg
cfe/trunk/test/Driver/Inputs/config/x86_64-qqq2.cfg
cfe/trunk/test/Driver/Inputs/config/x86_64.cfg
cfe/trunk/test/Driver/Inputs/config2/
cfe/trunk/test/Driver/Inputs/config2/config-4.cfg
cfe/trunk/test/Driver/Inputs/config2/i386.cfg
cfe/trunk/test/Driver/config-file-errs.c
cfe/trunk/test/Driver/config-file.c
cfe/trunk/test/Driver/config-file2.c
cfe/trunk/test/Driver/config-file3.c
Modified:
cfe/trunk/docs/UsersManual.rst
cfe/trunk/include/clang/Basic/DiagnosticDriverKinds.td
cfe/trunk/include/clang/Config/config.h.cmake
cfe/trunk/include/clang/Driver/Driver.h
cfe/trunk/include/clang/Driver/Options.td
cfe/trunk/lib/Driver/Driver.cpp

Modified: cfe/trunk/docs/UsersManual.rst
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/docs/UsersManual.rst?rev=321621=321620=321621=diff
==
--- cfe/trunk/docs/UsersManual.rst (original)
+++ cfe/trunk/docs/UsersManual.rst Mon Jan  1 05:27:01 2018
@@ -694,6 +694,79 @@ a special character, which is the conven
 option tells Clang to put double-quotes around the entire filename, which
 is the convention used by NMake and Jom.
 
+Configuration files
+---
+
+Configuration files group command-line options and allow all of them to be
+specified just by referencing the configuration file. They may be used, for
+example, to collect options required to tune compilation for particular
+target, such as -L, -I, -l, --sysroot, codegen options, etc.
+
+The command line option `--config` can be used to specify configuration
+file in a Clang invocation. For example:
+
+::
+
+clang --config /home/user/cfgs/testing.txt
+clang --config debug.cfg
+
+If the provided argument contains a directory separator, it is considered as
+a file path, and options are read from that file. Otherwise the argument is
+treated as a file name and is searched for sequentially in the directories:
+
+- user directory,
+- system directory,
+- the directory where Clang executable resides.
+
+Both user and system directories for configuration files are specified during
+clang build using CMake parameters, CLANG_CONFIG_FILE_USER_DIR and
+CLANG_CONFIG_FILE_SYSTEM_DIR respectively. The first file found is used. It is
+an error if the required file cannot be found.
+
+Another way to specify a configuration file is to encode it in executable name.
+For example, if the Clang executable is named `armv7l-clang` (it may be a
+symbolic link to `clang`), then Clang will search for file `armv7l.cfg` in the
+directory where Clang resides.
+
+If a driver mode is specified in invocation, Clang tries to find a file 
specific
+for the specified mode. For example, if the executable file is named
+`x86_64-clang-cl`, Clang first looks for `x86_64-cl.cfg` and if it is not 
found,
+looks for `x86_64.cfg'.
+
+If the command line contains options that effectively change target 
architecture
+(these are -m32, -EL, and some others) and the configuration file starts with 
an
+architecture name, Clang tries to load the configuration file for the effective
+architecture. For example, invocation:
+
+::
+
+x86_64-clang -m32 abc.c
+
+causes Clang search for a file `i368.cfg` first, and if no such file is found,
+Clang looks for the file `x86_64.cfg`.
+
+The 

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

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

I think it would be more user friendly if the configured list can be a list and 
the `|` concatenation is done within your code.




Comment at: clang-tidy/bugprone/UnusedReturnValueCheck.cpp:29
+  llvm::raw_svector_ostream OS(InlinedName);
+  auto Policy = Node.getASTContext().getPrintingPolicy();
+  Policy.SuppressUnwrittenScope = true;

Don't use auto here, because the type is not written somewhere



Comment at: clang-tidy/bugprone/UnusedReturnValueCheck.cpp:53
+  // Detect unused return values by finding CallExprs with CompoundStmt parent,
+  // ignoring any implicit nodes and parentheses in between
+  Finder->addMatcher(

Missing full stop.


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] D41655: [clang-tidy] New check bugprone-unused-return-value

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



Comment at: clang-tidy/bugprone/UnusedReturnValueCheck.cpp:13
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;

Please include cassert, Regex.h, raw_ostream.h, SmallString.h.



Comment at: clang-tidy/bugprone/UnusedReturnValueCheck.h:14
+#include "../ClangTidy.h"
+
+namespace clang {

Please include string.



Comment at: docs/clang-tidy/checks/bugprone-unused-return-value.rst:17
+
+   - ``std::async``. Not using the return value makes the call synchronous.
+   - ``std::launder``. Not using the return value usually means that the

Please add round brackets to all functions/methods here and below.


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] D41648: [clang-tidy] implement cppcoreguidelines macro rules

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



Comment at: clang-tidy/cppcoreguidelines/MacroUsageCheck.cpp:13
+#include "clang/Lex/PPCallbacks.h"
+
+namespace clang {

Please include string and STLExtras.h.



Comment at: docs/clang-tidy/checks/cppcoreguidelines-macro-usage.rst:8
+constructs exist for the task.
+

Will be good idea to add link to relevant section in documentation.


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] D41056: [clang-tidy] New check misc-uniqueptr-release-unused-retval

2018-01-01 Thread Kalle Huttunen via Phabricator via cfe-commits
khuttun abandoned this revision.
khuttun added a comment.

Closing this as more general check is being reviewed here: 
https://reviews.llvm.org/D41655


Repository:
  rL LLVM

https://reviews.llvm.org/D41056



___
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-01 Thread Kalle Huttunen via Phabricator via cfe-commits
khuttun created this revision.
khuttun added reviewers: alexfh, aaron.ballman.
khuttun added a project: clang-tools-extra.
Herald added subscribers: xazax.hun, mgorny.

Detects function calls where the return value is unused.

Checked functions can be configured.


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,200 @@
+// 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 &&...);
+
+// 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: unused return value [bugprone-unused-return-value]
+
+  std::async(std::launch::async, increment, 42);
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: unused return value [bugprone-unused-return-value]
+
+  Foo F;
+  std::launder();
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: unused return value [bugprone-unused-return-value]
+
+  std::unique_ptr UP;
+  UP.release();
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: unused return value [bugprone-unused-return-value]
+
+  std::allocator FA;
+  FA.allocate(1);
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: unused return value [bugprone-unused-return-value]
+  FA.allocate(1, nullptr);
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: unused return value [bugprone-unused-return-value]
+
+  std::allocator_traits::allocate(FA, 1);
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: unused return value [bugprone-unused-return-value]
+  std::allocator_traits::allocate(FA, 1, nullptr);
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: unused return value [bugprone-unused-return-value]
+
+  std::scoped_allocator_adaptor SAA;
+  SAA.allocate(1);
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: unused return value [bugprone-unused-return-value]
+  SAA.allocate(1, nullptr);
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: unused return value [bugprone-unused-return-value]
+
+  std::pmr::memory_resource MR;
+  MR.allocate(1);
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: unused return value [bugprone-unused-return-value]
+
+  std::pmr::polymorphic_allocator PA;
+  PA.allocate(1);
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: unused return value [bugprone-unused-return-value]
+
+  std::vector FV;
+  FV.empty();
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: unused return value [bugprone-unused-return-value]
+
+  std::filesystem::path P;
+  P.empty();
+  // CHECK-MESSAGES: [[@LINE-1]]:3: warning: unused return value [bugprone-unused-return-value]
+}
+