[PATCH] D32385: [libcxx] optional: Implement LWG 2900 and P0602

2017-04-30 Thread Casey Carter via Phabricator via cfe-commits
CaseyCarter updated this revision to Diff 97217.
CaseyCarter added a comment.

Update libc++-specific special member test for extended P0602 implementation.


https://reviews.llvm.org/D32385

Files:
  include/optional
  test/libcxx/utilities/optional/optional.object/special_member_gen.pass.cpp
  
test/std/utilities/optional/optional.object/optional.object.assign/copy.pass.cpp
  
test/std/utilities/optional/optional.object/optional.object.assign/move.pass.cpp
  test/std/utilities/optional/optional.object/optional.object.ctor/copy.pass.cpp
  test/std/utilities/optional/optional.object/optional.object.ctor/move.pass.cpp
  test/support/msvc_stdlib_force_include.hpp

Index: test/support/msvc_stdlib_force_include.hpp
===
--- test/support/msvc_stdlib_force_include.hpp
+++ test/support/msvc_stdlib_force_include.hpp
@@ -26,6 +26,11 @@
 #error This header may not be used when targeting libc++
 #endif
 
+// Indicates that we are using the MSVC standard library.
+#ifndef _MSVC_STL_VER
+#define _MSVC_STL_VER 42
+#endif
+
 struct AssertionDialogAvoider {
 AssertionDialogAvoider() {
 _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE);
Index: test/std/utilities/optional/optional.object/optional.object.ctor/move.pass.cpp
===
--- test/std/utilities/optional/optional.object/optional.object.ctor/move.pass.cpp
+++ test/std/utilities/optional/optional.object/optional.object.ctor/move.pass.cpp
@@ -10,7 +10,10 @@
 // UNSUPPORTED: c++98, c++03, c++11, c++14
 // 
 
-// optional(optional&& rhs);
+// constexpr optional(optional&& rhs);
+//   If is_trivially_move_constructible_v is true,
+//this constructor shall be a constexpr constructor.
+
 
 #include 
 #include 
@@ -36,10 +39,10 @@
 void test_throwing_ctor() {
 #ifndef TEST_HAS_NO_EXCEPTIONS
 struct Z {
-  Z() : count(0) {}
-  Z(Z&& o) : count(o.count + 1)
-  { if (count == 2) throw 6; }
-  int count;
+Z() : count(0) {}
+Z(Z&& o) : count(o.count + 1)
+{ if (count == 2) throw 6; }
+int count;
 };
 Z z;
 optional rhs(std::move(z));
@@ -131,6 +134,48 @@
 #endif
 }
 
+constexpr bool test_constexpr()
+{
+{
+using T = int;
+optional o1{};
+optional o2 = std::move(o1);
+static_cast(o2);
+optional o3{T{42}};
+optional o4 = std::move(o3);
+static_cast(o4);
+}
+{
+struct T {
+constexpr T(int) {}
+T(T&&) = default;
+};
+optional o1{};
+optional o2 = std::move(o1);
+static_cast(o2);
+optional o3{T{42}};
+optional o4 = std::move(o3);
+static_cast(o4);
+}
+return true;
+}
+static_assert(test_constexpr(), "");
+
+template
+constexpr bool triviality_test =
+std::is_trivially_move_constructible>::value ==
+std::is_trivially_move_constructible::value;
+
+void test_triviality_extension() {
+#if defined(_LIBCPP_VER) || defined(_MSVC_STL_VER)
+static_assert(triviality_test, "");
+static_assert(triviality_test>, "");
+static_assert(triviality_test, "");
+static_assert(triviality_test, "");
+static_assert(triviality_test, "");
+static_assert(triviality_test, "");
+#endif
+}
 
 int main()
 {
@@ -178,9 +223,9 @@
 test();
 test(42);
 }
-{
-test_throwing_ctor();
-}
+
+test_throwing_ctor();
+
 {
 struct ThrowsMove {
   ThrowsMove() noexcept(false) {}
@@ -195,7 +240,7 @@
 };
 static_assert(std::is_nothrow_move_constructible>::value, "");
 }
-{
-test_reference_extension();
-}
+
+test_reference_extension();
+test_triviality_extension();
 }
Index: test/std/utilities/optional/optional.object/optional.object.ctor/copy.pass.cpp
===
--- test/std/utilities/optional/optional.object/optional.object.ctor/copy.pass.cpp
+++ test/std/utilities/optional/optional.object/optional.object.ctor/copy.pass.cpp
@@ -10,7 +10,9 @@
 // UNSUPPORTED: c++98, c++03, c++11, c++14
 // 
 
-// optional(const optional& rhs);
+// constexpr optional(const optional& rhs);
+//   If is_trivially_copy_constructible_v is true,
+//this constructor shall be a constexpr constructor.
 
 #include 
 #include 
@@ -35,10 +37,10 @@
 void test_throwing_ctor() {
 #ifndef TEST_HAS_NO_EXCEPTIONS
 struct Z {
-  Z() : count(0) {}
-  Z(Z const& o) : count(o.count + 1)
-  { if (count == 2) throw 6; }
-  int count;
+Z() : count(0) {}
+Z(Z const& o) : count(o.count + 1)
+{ if (count == 2) throw 6; }
+int count;
 };
 const Z z;
 const optional rhs(z);
@@ -104,6 +106,48 @@
 #endif
 }
 
+constexpr bool test_constexpr()
+{
+{
+using T = int;
+optional o1{};
+optional o2 = o1;
+static_cast(o2);
+

[PATCH] D32309: [libcxx] [test] Resolve compiler warnings in LCM/GCD tests

2017-04-30 Thread Casey Carter via Phabricator via cfe-commits
CaseyCarter added inline comments.



Comment at: test/std/numerics/numeric.ops/numeric.ops.lcm/lcm.pass.cpp:144
+auto res1 = std::lcm(static_cast(1234), INT32_MIN);
+(void)std::lcm(INT_MIN, 2UL);  // this used to trigger UBSAN
+static_assert(std::is_same::value, "");

`INT_MIN` is in `` .


https://reviews.llvm.org/D32309



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


[PATCH] D32678: [clang-tidy] Fix naming convention in modernize-use-empace

2017-04-30 Thread Jakub Kuderski via Phabricator via cfe-commits
kuhar created this revision.
kuhar added a project: clang-tools-extra.

Conform to llvm naming convention for local variables in modernize-use-emplace 
check.


https://reviews.llvm.org/D32678

Files:
  clang-tidy/modernize/UseEmplaceCheck.cpp


Index: clang-tidy/modernize/UseEmplaceCheck.cpp
===
--- clang-tidy/modernize/UseEmplaceCheck.cpp
+++ clang-tidy/modernize/UseEmplaceCheck.cpp
@@ -45,63 +45,63 @@
   // because this requires special treatment (it could cause performance
   // regression)
   // + match for emplace calls that should be replaced with insertion
-  auto callPushBack = cxxMemberCallExpr(
+  auto CallPushBack = cxxMemberCallExpr(
   hasDeclaration(functionDecl(hasName("push_back"))),
   on(hasType(cxxRecordDecl(hasAnyName(SmallVector(
   ContainersWithPushBack.begin(), ContainersWithPushBack.end()));
 
   // We can't replace push_backs of smart pointer because
   // if emplacement fails (f.e. bad_alloc in vector) we will have leak of
   // passed pointer because smart pointer won't be constructed
   // (and destructed) as in push_back case.
-  auto isCtorOfSmartPtr = hasDeclaration(cxxConstructorDecl(ofClass(hasAnyName(
+  auto IsCtorOfSmartPtr = hasDeclaration(cxxConstructorDecl(ofClass(hasAnyName(
   SmallVector(SmartPointers.begin(), 
SmartPointers.end());
 
   // Bitfields binds only to consts and emplace_back take it by universal ref.
-  auto bitFieldAsArgument = hasAnyArgument(
+  auto BitFieldAsArgument = hasAnyArgument(
   ignoringImplicit(memberExpr(hasDeclaration(fieldDecl(isBitField());
 
   // Initializer list can't be passed to universal reference.
-  auto initializerListAsArgument = hasAnyArgument(
+  auto InitializerListAsArgument = hasAnyArgument(
   ignoringImplicit(cxxConstructExpr(isListInitialization(;
 
   // We could have leak of resource.
-  auto newExprAsArgument = hasAnyArgument(ignoringImplicit(cxxNewExpr()));
+  auto NewExprAsArgument = hasAnyArgument(ignoringImplicit(cxxNewExpr()));
   // We would call another constructor.
-  auto constructingDerived =
+  auto ConstructingDerived =
   hasParent(implicitCastExpr(hasCastKind(CastKind::CK_DerivedToBase)));
 
   // emplace_back can't access private constructor.
-  auto isPrivateCtor = hasDeclaration(cxxConstructorDecl(isPrivate()));
+  auto IsPrivateCtor = hasDeclaration(cxxConstructorDecl(isPrivate()));
 
-  auto hasInitList = has(ignoringImplicit(initListExpr()));
+  auto HasInitList = has(ignoringImplicit(initListExpr()));
   // FIXME: Discard 0/NULL (as nullptr), static inline const data members,
   // overloaded functions and template names.
-  auto soughtConstructExpr =
+  auto SoughtConstructExpr =
   cxxConstructExpr(
-  unless(anyOf(isCtorOfSmartPtr, hasInitList, bitFieldAsArgument,
-   initializerListAsArgument, newExprAsArgument,
-   constructingDerived, isPrivateCtor)))
+  unless(anyOf(IsCtorOfSmartPtr, HasInitList, BitFieldAsArgument,
+   InitializerListAsArgument, NewExprAsArgument,
+   ConstructingDerived, IsPrivateCtor)))
   .bind("ctor");
-  auto hasConstructExpr = has(ignoringImplicit(soughtConstructExpr));
+  auto HasConstructExpr = has(ignoringImplicit(SoughtConstructExpr));
 
-  auto makePair = ignoringImplicit(
+  auto MakePair = ignoringImplicit(
   callExpr(callee(expr(ignoringImplicit(
   declRefExpr(unless(hasExplicitTemplateArgs()),
   to(functionDecl(hasName("::std::make_pair"
   .bind("make_pair"));
 
   // make_pair can return type convertible to container's element type.
   // Allow the conversion only on containers of pairs.
-  auto makePairCtor = ignoringImplicit(cxxConstructExpr(
-  has(materializeTemporaryExpr(makePair)),
+  auto MakePairCtor = ignoringImplicit(cxxConstructExpr(
+  has(materializeTemporaryExpr(MakePair)),
   hasDeclaration(cxxConstructorDecl(ofClass(hasName("::std::pair"));
 
-  auto soughtParam = materializeTemporaryExpr(
-  anyOf(has(makePair), has(makePairCtor),
-hasConstructExpr, has(cxxFunctionalCastExpr(hasConstructExpr;
+  auto SoughtParam = materializeTemporaryExpr(
+  anyOf(has(MakePair), has(MakePairCtor),
+HasConstructExpr, has(cxxFunctionalCastExpr(HasConstructExpr;
 
-  Finder->addMatcher(cxxMemberCallExpr(callPushBack, has(soughtParam),
+  Finder->addMatcher(cxxMemberCallExpr(CallPushBack, has(SoughtParam),
unless(isInTemplateInstantiation()))
  .bind("call"),
  this);


Index: clang-tidy/modernize/UseEmplaceCheck.cpp
===
--- clang-tidy/modernize/UseEmplaceCheck.cpp
+++ clang-tidy/modernize/UseEmplaceCheck.cpp
@@ -45,63 +45,63 @@
   // because this requires special treatment (it could cause p

[PATCH] D32646: Fix a bug that -Wmissing-braces fires on system headers

2017-04-30 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev added a comment.

LGTM, modulo the comment.




Comment at: lib/Sema/SemaInit.cpp:892
+  SpellingLoc = SemaRef.getSourceManager().getSpellingLoc(SpellingLoc);
+  if (!(SpellingLoc.isValid() && 
+SemaRef.getSourceManager().isInSystemHeader(SpellingLoc))) {

I'd avoid double negations. Could you use `isInvalid` instead of `!isValid`. 
That would make the condition more readable.


https://reviews.llvm.org/D32646



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


[PATCH] D31495: Fix a bug that -isysroot is completely ignored on Unix

2017-04-30 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev accepted this revision.
v.g.vassilev added a comment.
This revision is now accepted and ready to land.

LGTM.


https://reviews.llvm.org/D31495



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


[PATCH] D32341: Fix a bug that warnings generated with -M or -MM flags

2017-04-30 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev added a comment.

@teemperor, is this ok with you?


https://reviews.llvm.org/D32341



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


[PATCH] D32646: Fix a bug that -Wmissing-braces fires on system headers

2017-04-30 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi marked 2 inline comments as done.
yamaguchi added inline comments.



Comment at: lib/Sema/SemaInit.cpp:892
+  SpellingLoc = SemaRef.getSourceManager().getSpellingLoc(SpellingLoc);
+  if (!(SpellingLoc.isValid() && 
+SemaRef.getSourceManager().isInSystemHeader(SpellingLoc))) {

v.g.vassilev wrote:
> I'd avoid double negations. Could you use `isInvalid` instead of `!isValid`. 
> That would make the condition more readable.
It's not (!SpellingLoc.isValid()) but is !((SpellingLoc.isValid() && 
SemaRef.getSourceManager().isInSystemHeader(SpellingLoc))



https://reviews.llvm.org/D32646



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


[PATCH] D32678: [clang-tidy] Fix naming convention in modernize-use-emplace

2017-04-30 Thread Piotr Padlewski via Phabricator via cfe-commits
Prazek accepted this revision.
Prazek added a comment.
This revision is now accepted and ready to land.

Lgtm


https://reviews.llvm.org/D32678



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


[PATCH] D25051: Fix PR 10758: Infinite recursion when dealing with copy-initialization

2017-04-30 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev added a comment.

I am not very familiar with this code here. This seems a reasonable fix to me. 
Unless @rsmith and @ahatanak have objections, please go ahead and land it some 
time next week.


Repository:
  rL LLVM

https://reviews.llvm.org/D25051



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


[PATCH] D32646: Fix a bug that -Wmissing-braces fires on system headers

2017-04-30 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev added inline comments.



Comment at: lib/Sema/SemaInit.cpp:892
+  SpellingLoc = SemaRef.getSourceManager().getSpellingLoc(SpellingLoc);
+  if (!(SpellingLoc.isValid() && 
+SemaRef.getSourceManager().isInSystemHeader(SpellingLoc))) {

yamaguchi wrote:
> v.g.vassilev wrote:
> > I'd avoid double negations. Could you use `isInvalid` instead of 
> > `!isValid`. That would make the condition more readable.
> It's not (!SpellingLoc.isValid()) but is !((SpellingLoc.isValid() && 
> SemaRef.getSourceManager().isInSystemHeader(SpellingLoc))
> 
I'd rewrite this using early returns:
```
if (SpellingLoc.isInvalid() || 
SemaRef.getSourceManager().isInSystemHeader(SpellingLoc))
  return;
...
```


https://reviews.llvm.org/D32646



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


[PATCH] D32646: Fix a bug that -Wmissing-braces fires on system headers

2017-04-30 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi added inline comments.



Comment at: lib/Sema/SemaInit.cpp:892
+  SpellingLoc = SemaRef.getSourceManager().getSpellingLoc(SpellingLoc);
+  if (!(SpellingLoc.isValid() && 
+SemaRef.getSourceManager().isInSystemHeader(SpellingLoc))) {

v.g.vassilev wrote:
> yamaguchi wrote:
> > v.g.vassilev wrote:
> > > I'd avoid double negations. Could you use `isInvalid` instead of 
> > > `!isValid`. That would make the condition more readable.
> > It's not (!SpellingLoc.isValid()) but is !((SpellingLoc.isValid() &&
> >  SemaRef.getSourceManager().isInSystemHeader(SpellingLoc))
> > 
> I'd rewrite this using early returns:
> ```
> if (SpellingLoc.isInvalid() || 
> SemaRef.getSourceManager().isInSystemHeader(SpellingLoc))
>   return;
> ...
> ```
Do you think I should change this to (SpellingLoc.isInvalid() || 
!(SemaRef.getSourceManager().isInSystemHeader(SpellingLoc)) ??


https://reviews.llvm.org/D32646



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


[PATCH] D32646: Fix a bug that -Wmissing-braces fires on system headers

2017-04-30 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi added inline comments.



Comment at: lib/Sema/SemaInit.cpp:892
+  SpellingLoc = SemaRef.getSourceManager().getSpellingLoc(SpellingLoc);
+  if (!(SpellingLoc.isValid() && 
+SemaRef.getSourceManager().isInSystemHeader(SpellingLoc))) {

yamaguchi wrote:
> v.g.vassilev wrote:
> > yamaguchi wrote:
> > > v.g.vassilev wrote:
> > > > I'd avoid double negations. Could you use `isInvalid` instead of 
> > > > `!isValid`. That would make the condition more readable.
> > > It's not (!SpellingLoc.isValid()) but is !((SpellingLoc.isValid() &&  
> > >SemaRef.getSourceManager().isInSystemHeader(SpellingLoc))
> > > 
> > I'd rewrite this using early returns:
> > ```
> > if (SpellingLoc.isInvalid() || 
> > SemaRef.getSourceManager().isInSystemHeader(SpellingLoc))
> >   return;
> > ...
> > ```
> Do you think I should change this to (SpellingLoc.isInvalid() || 
> !(SemaRef.getSourceManager().isInSystemHeader(SpellingLoc)) ??
Oh, I see. 
Sorry I didn't see your reply because I was typing mine.


https://reviews.llvm.org/D32646



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


[PATCH] D32646: Fix a bug that -Wmissing-braces fires on system headers

2017-04-30 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi updated this revision to Diff 97224.
yamaguchi added a comment.

@v.g.vassilev 
I don't think early return is good idea, because someone might want to add some 
code under this function in the future.


https://reviews.llvm.org/D32646

Files:
  lib/Sema/SemaInit.cpp
  test/Sema/warn-missing-braces.c


Index: test/Sema/warn-missing-braces.c
===
--- test/Sema/warn-missing-braces.c
+++ test/Sema/warn-missing-braces.c
@@ -1,3 +1,21 @@
 // RUN: %clang_cc1 -fsyntax-only -Wmissing-braces -verify %s
 
+#ifdef BE_THE_HEADER
+#pragma clang system_header
+
+typedef struct _foo {
+unsigned char Data[2];
+} foo;
+
+#define BAR { 0 }
+
+#else
+
+#define BE_THE_HEADER
+#include __FILE__
+
 int a[2][2] = { 0, 1, 2, 3 }; // expected-warning{{suggest braces}} 
expected-warning{{suggest braces}}
+
+foo g = BAR; // should not show warnings
+
+#endif
Index: lib/Sema/SemaInit.cpp
===
--- lib/Sema/SemaInit.cpp
+++ lib/Sema/SemaInit.cpp
@@ -885,17 +885,22 @@
   StructuredSubobjectInitList->setRBraceLoc(EndLoc);
 }
 
-// Complain about missing braces.
+// Complain about missing braces when rhs is not a macro from system 
header.
 if (T->isArrayType() || T->isRecordType()) {
-  SemaRef.Diag(StructuredSubobjectInitList->getLocStart(),
-   diag::warn_missing_braces)
-  << StructuredSubobjectInitList->getSourceRange()
-  << FixItHint::CreateInsertion(
- StructuredSubobjectInitList->getLocStart(), "{")
-  << FixItHint::CreateInsertion(
- SemaRef.getLocForEndOfToken(
- StructuredSubobjectInitList->getLocEnd()),
- "}");
+  SourceLocation SpellingLoc = StructuredSubobjectInitList->getLocStart();
+  SpellingLoc = SemaRef.getSourceManager().getSpellingLoc(SpellingLoc);
+  if (SpellingLoc.isInvalid() || 
+!(SemaRef.getSourceManager().isInSystemHeader(SpellingLoc))) {
+SemaRef.Diag(StructuredSubobjectInitList->getLocStart(),
+ diag::warn_missing_braces)
+<< StructuredSubobjectInitList->getSourceRange()
+<< FixItHint::CreateInsertion(
+   StructuredSubobjectInitList->getLocStart(), "{")
+<< FixItHint::CreateInsertion(
+   SemaRef.getLocForEndOfToken(
+   StructuredSubobjectInitList->getLocEnd()),
+   "}");
+  }
 }
   }
 }


Index: test/Sema/warn-missing-braces.c
===
--- test/Sema/warn-missing-braces.c
+++ test/Sema/warn-missing-braces.c
@@ -1,3 +1,21 @@
 // RUN: %clang_cc1 -fsyntax-only -Wmissing-braces -verify %s
 
+#ifdef BE_THE_HEADER
+#pragma clang system_header
+
+typedef struct _foo {
+unsigned char Data[2];
+} foo;
+
+#define BAR { 0 }
+
+#else
+
+#define BE_THE_HEADER
+#include __FILE__
+
 int a[2][2] = { 0, 1, 2, 3 }; // expected-warning{{suggest braces}} expected-warning{{suggest braces}}
+
+foo g = BAR; // should not show warnings
+
+#endif
Index: lib/Sema/SemaInit.cpp
===
--- lib/Sema/SemaInit.cpp
+++ lib/Sema/SemaInit.cpp
@@ -885,17 +885,22 @@
   StructuredSubobjectInitList->setRBraceLoc(EndLoc);
 }
 
-// Complain about missing braces.
+// Complain about missing braces when rhs is not a macro from system header.
 if (T->isArrayType() || T->isRecordType()) {
-  SemaRef.Diag(StructuredSubobjectInitList->getLocStart(),
-   diag::warn_missing_braces)
-  << StructuredSubobjectInitList->getSourceRange()
-  << FixItHint::CreateInsertion(
- StructuredSubobjectInitList->getLocStart(), "{")
-  << FixItHint::CreateInsertion(
- SemaRef.getLocForEndOfToken(
- StructuredSubobjectInitList->getLocEnd()),
- "}");
+  SourceLocation SpellingLoc = StructuredSubobjectInitList->getLocStart();
+  SpellingLoc = SemaRef.getSourceManager().getSpellingLoc(SpellingLoc);
+  if (SpellingLoc.isInvalid() || 
+!(SemaRef.getSourceManager().isInSystemHeader(SpellingLoc))) {
+SemaRef.Diag(StructuredSubobjectInitList->getLocStart(),
+ diag::warn_missing_braces)
+<< StructuredSubobjectInitList->getSourceRange()
+<< FixItHint::CreateInsertion(
+   StructuredSubobjectInitList->getLocStart(), "{")
+<< FixItHint::CreateInsertion(
+   SemaRef.getLocForEndOfToken(
+   StructuredSubobjectInitList->getLocEnd()),
+   "}");
+  }
 }
   }
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D32646: Fix a bug that -Wmissing-braces fires on system headers

2017-04-30 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev added a comment.

I don't think we should worry about that. Please also see: 
http://llvm.org/docs/CodingStandards.html#use-early-exits-and-continue-to-simplify-code


https://reviews.llvm.org/D32646



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


[PATCH] D32646: Fix a bug that -Wmissing-braces fires on system headers

2017-04-30 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi updated this revision to Diff 97227.
yamaguchi marked 5 inline comments as done.
yamaguchi added a comment.

Changed to early return.


https://reviews.llvm.org/D32646

Files:
  lib/Sema/SemaInit.cpp
  test/Sema/warn-missing-braces.c


Index: test/Sema/warn-missing-braces.c
===
--- test/Sema/warn-missing-braces.c
+++ test/Sema/warn-missing-braces.c
@@ -1,3 +1,21 @@
 // RUN: %clang_cc1 -fsyntax-only -Wmissing-braces -verify %s
 
+#ifdef BE_THE_HEADER
+#pragma clang system_header
+
+typedef struct _foo {
+unsigned char Data[2];
+} foo;
+
+#define BAR { 0 }
+
+#else
+
+#define BE_THE_HEADER
+#include __FILE__
+
 int a[2][2] = { 0, 1, 2, 3 }; // expected-warning{{suggest braces}} 
expected-warning{{suggest braces}}
+
+foo g = BAR; // should not show warnings
+
+#endif
Index: lib/Sema/SemaInit.cpp
===
--- lib/Sema/SemaInit.cpp
+++ lib/Sema/SemaInit.cpp
@@ -885,8 +885,13 @@
   StructuredSubobjectInitList->setRBraceLoc(EndLoc);
 }
 
-// Complain about missing braces.
+// Complain about missing braces when rhs is not a macro from system 
header.
 if (T->isArrayType() || T->isRecordType()) {
+  SourceLocation SpellingLoc = StructuredSubobjectInitList->getLocStart();
+  SpellingLoc = SemaRef.getSourceManager().getSpellingLoc(SpellingLoc);
+  if (SpellingLoc.isValid() && 
+SemaRef.getSourceManager().isInSystemHeader(SpellingLoc)) 
+  return;
   SemaRef.Diag(StructuredSubobjectInitList->getLocStart(),
diag::warn_missing_braces)
   << StructuredSubobjectInitList->getSourceRange()


Index: test/Sema/warn-missing-braces.c
===
--- test/Sema/warn-missing-braces.c
+++ test/Sema/warn-missing-braces.c
@@ -1,3 +1,21 @@
 // RUN: %clang_cc1 -fsyntax-only -Wmissing-braces -verify %s
 
+#ifdef BE_THE_HEADER
+#pragma clang system_header
+
+typedef struct _foo {
+unsigned char Data[2];
+} foo;
+
+#define BAR { 0 }
+
+#else
+
+#define BE_THE_HEADER
+#include __FILE__
+
 int a[2][2] = { 0, 1, 2, 3 }; // expected-warning{{suggest braces}} expected-warning{{suggest braces}}
+
+foo g = BAR; // should not show warnings
+
+#endif
Index: lib/Sema/SemaInit.cpp
===
--- lib/Sema/SemaInit.cpp
+++ lib/Sema/SemaInit.cpp
@@ -885,8 +885,13 @@
   StructuredSubobjectInitList->setRBraceLoc(EndLoc);
 }
 
-// Complain about missing braces.
+// Complain about missing braces when rhs is not a macro from system header.
 if (T->isArrayType() || T->isRecordType()) {
+  SourceLocation SpellingLoc = StructuredSubobjectInitList->getLocStart();
+  SpellingLoc = SemaRef.getSourceManager().getSpellingLoc(SpellingLoc);
+  if (SpellingLoc.isValid() && 
+SemaRef.getSourceManager().isInSystemHeader(SpellingLoc)) 
+  return;
   SemaRef.Diag(StructuredSubobjectInitList->getLocStart(),
diag::warn_missing_braces)
   << StructuredSubobjectInitList->getSourceRange()
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D32646: Fix a bug that -Wmissing-braces fires on system headers

2017-04-30 Thread Vassil Vassilev via Phabricator via cfe-commits
v.g.vassilev added a comment.

Did you incorporate the comment from here: 
https://bugs.llvm.org/show_bug.cgi?id=24007#c2


https://reviews.llvm.org/D32646



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


[PATCH] D32646: Fix a bug that -Wmissing-braces fires on system headers

2017-04-30 Thread Yuka Takahashi via Phabricator via cfe-commits
yamaguchi updated this revision to Diff 97228.
yamaguchi added a comment.

Add check if there is -Wmissing-braces enabled or not.


https://reviews.llvm.org/D32646

Files:
  lib/Sema/SemaInit.cpp
  test/Sema/warn-missing-braces.c


Index: test/Sema/warn-missing-braces.c
===
--- test/Sema/warn-missing-braces.c
+++ test/Sema/warn-missing-braces.c
@@ -1,3 +1,21 @@
 // RUN: %clang_cc1 -fsyntax-only -Wmissing-braces -verify %s
 
+#ifdef BE_THE_HEADER
+#pragma clang system_header
+
+typedef struct _foo {
+unsigned char Data[2];
+} foo;
+
+#define BAR { 0 }
+
+#else
+
+#define BE_THE_HEADER
+#include __FILE__
+
 int a[2][2] = { 0, 1, 2, 3 }; // expected-warning{{suggest braces}} 
expected-warning{{suggest braces}}
+
+foo g = BAR; // should not show warnings
+
+#endif
Index: lib/Sema/SemaInit.cpp
===
--- lib/Sema/SemaInit.cpp
+++ lib/Sema/SemaInit.cpp
@@ -885,8 +885,16 @@
   StructuredSubobjectInitList->setRBraceLoc(EndLoc);
 }
 
-// Complain about missing braces.
-if (T->isArrayType() || T->isRecordType()) {
+// Complain about missing braces when rhs is not a macro from system 
header.
+// getSpellingLoc() isn't cheap, so only call it if the warning is enabled.
+if ((T->isArrayType() || T->isRecordType()) &&
+!SemaRef.Diags.isIgnored(diag::warn_missing_braces,
+ StructuredSubobjectInitList->getLocStart())) {
+  SourceLocation SpellingLoc = StructuredSubobjectInitList->getLocStart();
+  SpellingLoc = SemaRef.getSourceManager().getSpellingLoc(SpellingLoc);
+  if (SpellingLoc.isValid() && 
+SemaRef.getSourceManager().isInSystemHeader(SpellingLoc)) 
+  return;
   SemaRef.Diag(StructuredSubobjectInitList->getLocStart(),
diag::warn_missing_braces)
   << StructuredSubobjectInitList->getSourceRange()


Index: test/Sema/warn-missing-braces.c
===
--- test/Sema/warn-missing-braces.c
+++ test/Sema/warn-missing-braces.c
@@ -1,3 +1,21 @@
 // RUN: %clang_cc1 -fsyntax-only -Wmissing-braces -verify %s
 
+#ifdef BE_THE_HEADER
+#pragma clang system_header
+
+typedef struct _foo {
+unsigned char Data[2];
+} foo;
+
+#define BAR { 0 }
+
+#else
+
+#define BE_THE_HEADER
+#include __FILE__
+
 int a[2][2] = { 0, 1, 2, 3 }; // expected-warning{{suggest braces}} expected-warning{{suggest braces}}
+
+foo g = BAR; // should not show warnings
+
+#endif
Index: lib/Sema/SemaInit.cpp
===
--- lib/Sema/SemaInit.cpp
+++ lib/Sema/SemaInit.cpp
@@ -885,8 +885,16 @@
   StructuredSubobjectInitList->setRBraceLoc(EndLoc);
 }
 
-// Complain about missing braces.
-if (T->isArrayType() || T->isRecordType()) {
+// Complain about missing braces when rhs is not a macro from system header.
+// getSpellingLoc() isn't cheap, so only call it if the warning is enabled.
+if ((T->isArrayType() || T->isRecordType()) &&
+!SemaRef.Diags.isIgnored(diag::warn_missing_braces,
+ StructuredSubobjectInitList->getLocStart())) {
+  SourceLocation SpellingLoc = StructuredSubobjectInitList->getLocStart();
+  SpellingLoc = SemaRef.getSourceManager().getSpellingLoc(SpellingLoc);
+  if (SpellingLoc.isValid() && 
+SemaRef.getSourceManager().isInSystemHeader(SpellingLoc)) 
+  return;
   SemaRef.Diag(StructuredSubobjectInitList->getLocStart(),
diag::warn_missing_braces)
   << StructuredSubobjectInitList->getSourceRange()
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D32646: Fix a bug that -Wmissing-braces fires on system headers

2017-04-30 Thread Rui Ueyama via Phabricator via cfe-commits
ruiu added inline comments.



Comment at: lib/Sema/SemaInit.cpp:875
 
   if (!VerifyOnly) {
 StructuredSubobjectInitList->setType(T);

Is it intentional that you run the new code only when !VerifyOnly?



Comment at: lib/Sema/SemaInit.cpp:890-891
 if (T->isArrayType() || T->isRecordType()) {
+  SourceLocation SpellingLoc = StructuredSubobjectInitList->getLocStart();
+  SpellingLoc = SemaRef.getSourceManager().getSpellingLoc(SpellingLoc);
+  if (SpellingLoc.isValid() && 

This piece of code seems a bit puzzling as you initialize a variable to some 
value and immediately re-assign to some other value. It's better to initialize 
it only once.

  SourceLocation SpellingLoc = SemaRef.getSourceManager().getSpellingLoc(
StructuredSubobjectInitList->getLocStart());



https://reviews.llvm.org/D32646



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


[PATCH] D32646: Fix a bug that -Wmissing-braces fires on system headers

2017-04-30 Thread Rui Ueyama via Phabricator via cfe-commits
ruiu added inline comments.



Comment at: lib/Sema/SemaInit.cpp:897
+SemaRef.getSourceManager().isInSystemHeader(SpellingLoc)) 
+  return;
   SemaRef.Diag(StructuredSubobjectInitList->getLocStart(),

Please use clang-format to format your code.


https://reviews.llvm.org/D32646



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


Missing comma diagnostics patch

2017-04-30 Thread Zaid Alkhishman via cfe-commits
Hello,

This patch adds missing comma diagnostics to initializer lists.

I'm attaching
the .diff (git),
an input .c
and the compilation output .out

Let me know if there are any required changes.

Regards,

Zaid

zaid.al.khish...@gmail.com

(Note, I tried subscribing to cfe-commits but it said the subscription has
to be confirmed first, so I'm not even sure if this email is gonna go
through, but if it does for now I won't be getting any replies I suppose :/)
diff --git include/clang/Basic/DiagnosticParseKinds.td 
include/clang/Basic/DiagnosticParseKinds.td
index f04ed8ed4c..ef913ce947 100644
--- include/clang/Basic/DiagnosticParseKinds.td
+++ include/clang/Basic/DiagnosticParseKinds.td
@@ -164,6 +164,7 @@ def err_function_declared_typedef : Error<
 def err_at_defs_cxx : Error<"@defs is not supported in Objective-C++">;
 def err_at_in_class : Error<"unexpected '@' in member specification">;
 def err_unexpected_semi : Error<"unexpected ';' before %0">;
+def err_expected_comma : Error<"expected ',' before initializer">;
 
 def err_expected_fn_body : Error<
   "expected function body after function declarator">;
diff --git include/clang/Parse/RAIIObjectsForParser.h 
include/clang/Parse/RAIIObjectsForParser.h
index 0422b038da..938df69b95 100644
--- include/clang/Parse/RAIIObjectsForParser.h
+++ include/clang/Parse/RAIIObjectsForParser.h
@@ -440,6 +440,13 @@ namespace clang {
   
   return diagnoseMissingClose();
 }
+
+bool willClose(){
+  if (P.Tok.is(Close))
+return false;
+  return true;
+}
+
 void skipToEnd();
   };
 
diff --git lib/Parse/ParseInit.cpp lib/Parse/ParseInit.cpp
index f48d01e0f6..2454162b2e 100644
--- lib/Parse/ParseInit.cpp
+++ lib/Parse/ParseInit.cpp
@@ -409,6 +409,8 @@ ExprResult Parser::ParseBraceInitializer() {
   Actions, EnterExpressionEvaluationContext::InitList);
 
   bool InitExprsOk = true;
+  bool maybeMissingComma = false;
+  Token startOfNextIni;
 
   while (1) {
 // Handle Microsoft __if_exists/if_not_exists if necessary.
@@ -427,6 +429,8 @@ ExprResult Parser::ParseBraceInitializer() {
 // If we know that this cannot be a designation, just parse the nested
 // initializer directly.
 ExprResult SubElt;
+startOfNextIni = Tok;
+
 if (MayBeDesignationStart())
   SubElt = ParseInitializerWithPotentialDesignator();
 else
@@ -457,8 +461,24 @@ ExprResult Parser::ParseBraceInitializer() {
   }
 }
 
-// If we don't have a comma continued list, we're done.
-if (Tok.isNot(tok::comma)) break;
+if(maybeMissingComma){
+  //Here we would have checked if InitExprsOk is true,
+  //but it's implied to be ok because of the previous break
+  //Now we know the compilee  very likely forgot the comma
+  Diag(startOfNextIni.getLocation(), diag::err_expected_comma)
+   << 
FixItHint::CreateInsertion(startOfNextIni.getLocation().getLocWithOffset(-1), 
",");
+  maybeMissingComma = false;
+}
+
+// If we don't have a comma continued list, we're done (maybe).
+if (Tok.isNot(tok::comma)){
+  if(!T.willClose()){
+//This is a ok list, no missing commas.
+break;
+  }
+  maybeMissingComma = true;
+  continue;
+}
 
 // TODO: save comma locations if some client cares.
 ConsumeToken();


missingCommasDiag.in
Description: Binary data


missingCommasDiag.out
Description: Binary data
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D32678: [clang-tidy] Fix naming convention in modernize-use-emplace

2017-04-30 Thread Alexander Kornienko via Phabricator via cfe-commits
alexfh accepted this revision.
alexfh added a comment.

LG


https://reviews.llvm.org/D32678



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


[PATCH] D32678: [clang-tidy] Fix naming convention in modernize-use-emplace

2017-04-30 Thread Jakub Kuderski via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL301780: [clang-tidy] Fix naming convention in 
modernize-use-emplace (authored by kuhar).

Changed prior to commit:
  https://reviews.llvm.org/D32678?vs=97221&id=97243#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D32678

Files:
  clang-tools-extra/trunk/clang-tidy/modernize/UseEmplaceCheck.cpp


Index: clang-tools-extra/trunk/clang-tidy/modernize/UseEmplaceCheck.cpp
===
--- clang-tools-extra/trunk/clang-tidy/modernize/UseEmplaceCheck.cpp
+++ clang-tools-extra/trunk/clang-tidy/modernize/UseEmplaceCheck.cpp
@@ -45,63 +45,63 @@
   // because this requires special treatment (it could cause performance
   // regression)
   // + match for emplace calls that should be replaced with insertion
-  auto callPushBack = cxxMemberCallExpr(
+  auto CallPushBack = cxxMemberCallExpr(
   hasDeclaration(functionDecl(hasName("push_back"))),
   on(hasType(cxxRecordDecl(hasAnyName(SmallVector(
   ContainersWithPushBack.begin(), ContainersWithPushBack.end()));
 
   // We can't replace push_backs of smart pointer because
   // if emplacement fails (f.e. bad_alloc in vector) we will have leak of
   // passed pointer because smart pointer won't be constructed
   // (and destructed) as in push_back case.
-  auto isCtorOfSmartPtr = hasDeclaration(cxxConstructorDecl(ofClass(hasAnyName(
+  auto IsCtorOfSmartPtr = hasDeclaration(cxxConstructorDecl(ofClass(hasAnyName(
   SmallVector(SmartPointers.begin(), 
SmartPointers.end());
 
   // Bitfields binds only to consts and emplace_back take it by universal ref.
-  auto bitFieldAsArgument = hasAnyArgument(
+  auto BitFieldAsArgument = hasAnyArgument(
   ignoringImplicit(memberExpr(hasDeclaration(fieldDecl(isBitField());
 
   // Initializer list can't be passed to universal reference.
-  auto initializerListAsArgument = hasAnyArgument(
+  auto InitializerListAsArgument = hasAnyArgument(
   ignoringImplicit(cxxConstructExpr(isListInitialization(;
 
   // We could have leak of resource.
-  auto newExprAsArgument = hasAnyArgument(ignoringImplicit(cxxNewExpr()));
+  auto NewExprAsArgument = hasAnyArgument(ignoringImplicit(cxxNewExpr()));
   // We would call another constructor.
-  auto constructingDerived =
+  auto ConstructingDerived =
   hasParent(implicitCastExpr(hasCastKind(CastKind::CK_DerivedToBase)));
 
   // emplace_back can't access private constructor.
-  auto isPrivateCtor = hasDeclaration(cxxConstructorDecl(isPrivate()));
+  auto IsPrivateCtor = hasDeclaration(cxxConstructorDecl(isPrivate()));
 
-  auto hasInitList = has(ignoringImplicit(initListExpr()));
+  auto HasInitList = has(ignoringImplicit(initListExpr()));
   // FIXME: Discard 0/NULL (as nullptr), static inline const data members,
   // overloaded functions and template names.
-  auto soughtConstructExpr =
+  auto SoughtConstructExpr =
   cxxConstructExpr(
-  unless(anyOf(isCtorOfSmartPtr, hasInitList, bitFieldAsArgument,
-   initializerListAsArgument, newExprAsArgument,
-   constructingDerived, isPrivateCtor)))
+  unless(anyOf(IsCtorOfSmartPtr, HasInitList, BitFieldAsArgument,
+   InitializerListAsArgument, NewExprAsArgument,
+   ConstructingDerived, IsPrivateCtor)))
   .bind("ctor");
-  auto hasConstructExpr = has(ignoringImplicit(soughtConstructExpr));
+  auto HasConstructExpr = has(ignoringImplicit(SoughtConstructExpr));
 
-  auto makePair = ignoringImplicit(
+  auto MakePair = ignoringImplicit(
   callExpr(callee(expr(ignoringImplicit(
   declRefExpr(unless(hasExplicitTemplateArgs()),
   to(functionDecl(hasName("::std::make_pair"
   .bind("make_pair"));
 
   // make_pair can return type convertible to container's element type.
   // Allow the conversion only on containers of pairs.
-  auto makePairCtor = ignoringImplicit(cxxConstructExpr(
-  has(materializeTemporaryExpr(makePair)),
+  auto MakePairCtor = ignoringImplicit(cxxConstructExpr(
+  has(materializeTemporaryExpr(MakePair)),
   hasDeclaration(cxxConstructorDecl(ofClass(hasName("::std::pair"));
 
-  auto soughtParam = materializeTemporaryExpr(
-  anyOf(has(makePair), has(makePairCtor),
-hasConstructExpr, has(cxxFunctionalCastExpr(hasConstructExpr;
+  auto SoughtParam = materializeTemporaryExpr(
+  anyOf(has(MakePair), has(MakePairCtor),
+HasConstructExpr, has(cxxFunctionalCastExpr(HasConstructExpr;
 
-  Finder->addMatcher(cxxMemberCallExpr(callPushBack, has(soughtParam),
+  Finder->addMatcher(cxxMemberCallExpr(CallPushBack, has(SoughtParam),
unless(isInTemplateInstantiation()))
  .bind("call"),
  this);


Index: clang-tools-extra/trunk/clang-tidy/modernize/UseEmplaceChe

[clang-tools-extra] r301780 - [clang-tidy] Fix naming convention in modernize-use-emplace

2017-04-30 Thread Jakub Kuderski via cfe-commits
Author: kuhar
Date: Sun Apr 30 16:12:56 2017
New Revision: 301780

URL: http://llvm.org/viewvc/llvm-project?rev=301780&view=rev
Log:
[clang-tidy] Fix naming convention in modernize-use-emplace

Summary: Conform to the llvm naming convention for local variables in 
modernize-use-emplace check.

Reviewers: Prazek, JonasToth, alexfh

Reviewed By: Prazek, JonasToth, alexfh

Subscribers: cfe-commits

Tags: #clang-tools-extra

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

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

Modified: clang-tools-extra/trunk/clang-tidy/modernize/UseEmplaceCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/UseEmplaceCheck.cpp?rev=301780&r1=301779&r2=301780&view=diff
==
--- clang-tools-extra/trunk/clang-tidy/modernize/UseEmplaceCheck.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/UseEmplaceCheck.cpp Sun Apr 30 
16:12:56 2017
@@ -45,7 +45,7 @@ void UseEmplaceCheck::registerMatchers(M
   // because this requires special treatment (it could cause performance
   // regression)
   // + match for emplace calls that should be replaced with insertion
-  auto callPushBack = cxxMemberCallExpr(
+  auto CallPushBack = cxxMemberCallExpr(
   hasDeclaration(functionDecl(hasName("push_back"))),
   on(hasType(cxxRecordDecl(hasAnyName(SmallVector(
   ContainersWithPushBack.begin(), ContainersWithPushBack.end()));
@@ -54,38 +54,38 @@ void UseEmplaceCheck::registerMatchers(M
   // if emplacement fails (f.e. bad_alloc in vector) we will have leak of
   // passed pointer because smart pointer won't be constructed
   // (and destructed) as in push_back case.
-  auto isCtorOfSmartPtr = hasDeclaration(cxxConstructorDecl(ofClass(hasAnyName(
+  auto IsCtorOfSmartPtr = hasDeclaration(cxxConstructorDecl(ofClass(hasAnyName(
   SmallVector(SmartPointers.begin(), 
SmartPointers.end());
 
   // Bitfields binds only to consts and emplace_back take it by universal ref.
-  auto bitFieldAsArgument = hasAnyArgument(
+  auto BitFieldAsArgument = hasAnyArgument(
   ignoringImplicit(memberExpr(hasDeclaration(fieldDecl(isBitField());
 
   // Initializer list can't be passed to universal reference.
-  auto initializerListAsArgument = hasAnyArgument(
+  auto InitializerListAsArgument = hasAnyArgument(
   ignoringImplicit(cxxConstructExpr(isListInitialization(;
 
   // We could have leak of resource.
-  auto newExprAsArgument = hasAnyArgument(ignoringImplicit(cxxNewExpr()));
+  auto NewExprAsArgument = hasAnyArgument(ignoringImplicit(cxxNewExpr()));
   // We would call another constructor.
-  auto constructingDerived =
+  auto ConstructingDerived =
   hasParent(implicitCastExpr(hasCastKind(CastKind::CK_DerivedToBase)));
 
   // emplace_back can't access private constructor.
-  auto isPrivateCtor = hasDeclaration(cxxConstructorDecl(isPrivate()));
+  auto IsPrivateCtor = hasDeclaration(cxxConstructorDecl(isPrivate()));
 
-  auto hasInitList = has(ignoringImplicit(initListExpr()));
+  auto HasInitList = has(ignoringImplicit(initListExpr()));
   // FIXME: Discard 0/NULL (as nullptr), static inline const data members,
   // overloaded functions and template names.
-  auto soughtConstructExpr =
+  auto SoughtConstructExpr =
   cxxConstructExpr(
-  unless(anyOf(isCtorOfSmartPtr, hasInitList, bitFieldAsArgument,
-   initializerListAsArgument, newExprAsArgument,
-   constructingDerived, isPrivateCtor)))
+  unless(anyOf(IsCtorOfSmartPtr, HasInitList, BitFieldAsArgument,
+   InitializerListAsArgument, NewExprAsArgument,
+   ConstructingDerived, IsPrivateCtor)))
   .bind("ctor");
-  auto hasConstructExpr = has(ignoringImplicit(soughtConstructExpr));
+  auto HasConstructExpr = has(ignoringImplicit(SoughtConstructExpr));
 
-  auto makePair = ignoringImplicit(
+  auto MakePair = ignoringImplicit(
   callExpr(callee(expr(ignoringImplicit(
   declRefExpr(unless(hasExplicitTemplateArgs()),
   to(functionDecl(hasName("::std::make_pair"
@@ -93,15 +93,15 @@ void UseEmplaceCheck::registerMatchers(M
 
   // make_pair can return type convertible to container's element type.
   // Allow the conversion only on containers of pairs.
-  auto makePairCtor = ignoringImplicit(cxxConstructExpr(
-  has(materializeTemporaryExpr(makePair)),
+  auto MakePairCtor = ignoringImplicit(cxxConstructExpr(
+  has(materializeTemporaryExpr(MakePair)),
   hasDeclaration(cxxConstructorDecl(ofClass(hasName("::std::pair"));
 
-  auto soughtParam = materializeTemporaryExpr(
-  anyOf(has(makePair), has(makePairCtor),
-hasConstructExpr, has(cxxFunctionalCastExpr(hasConstructExpr;
+  auto SoughtParam = materializeTemporaryExpr(
+  anyOf(has(MakePair), has(MakePairCtor),
+

[PATCH] D32690: [clang-tidy] modernize-use-emplace: Remove unnecessary make_tuple calls

2017-04-30 Thread Jakub Kuderski via Phabricator via cfe-commits
kuhar created this revision.
kuhar added a project: clang-tools-extra.

This patch makes modernize-use-emplace remove unnecessary make_tuple calls from 
push_back calls and turn them into emplace_back -- the same way make_pair calls 
are handled.

Eq.

  std::vector> v;
  v.push_back(std::make_tuple(1, 'A', true)); // --> v.emplace_back(1, 'A', 
true);


https://reviews.llvm.org/D32690

Files:
  clang-tidy/modernize/UseEmplaceCheck.cpp
  docs/ReleaseNotes.rst
  test/clang-tidy/modernize-use-emplace.cpp

Index: test/clang-tidy/modernize-use-emplace.cpp
===
--- test/clang-tidy/modernize-use-emplace.cpp
+++ test/clang-tidy/modernize-use-emplace.cpp
@@ -36,27 +36,54 @@
   ~deque();
 };
 
-template 
-class pair {
+template  struct remove_reference { using type = T; };
+template  struct remove_reference { using type = T; };
+template  struct remove_reference { using type = T; };
+
+template  class pair {
 public:
   pair() = default;
   pair(const pair &) = default;
   pair(pair &&) = default;
 
   pair(const T1 &, const T2 &) {}
   pair(T1 &&, T2 &&) {}
 
-  template 
-  pair(const pair &p){};
-  template 
-  pair(pair &&p){};
+  template  pair(const pair &){};
+  template  pair(pair &&){};
 };
 
 template 
-pair make_pair(T1&&, T2&&) {
+pair::type, typename remove_reference::type>
+make_pair(T1 &&, T2 &&) {
   return {};
 };
 
+template  class tuple {
+public:
+  tuple() = default;
+  tuple(const tuple &) = default;
+  tuple(tuple &&) = default;
+
+  tuple(const Ts &...) {}
+  tuple(Ts &&...) {}
+
+  template  tuple(const tuple &){};
+  template  tuple(tuple &&) {}
+
+  template  tuple(const pair &) {
+static_assert(sizeof...(Ts) == 2, "Wrong tuple size");
+  };
+  template  tuple(pair &&) {
+static_assert(sizeof...(Ts) == 2, "Wrong tuple size");
+  };
+};
+
+template 
+tuple::type...> make_tuple(Ts &&...) {
+  return {};
+}
+
 template 
 class unique_ptr {
 public:
@@ -197,6 +224,30 @@
   // CHECK-FIXES: v2.emplace_back(Something(42, 42), Zoz(Something(21, 37)));
 }
 
+void testTuple() {
+  std::vector> v;
+  v.push_back(std::tuple(false, 'x', 1));
+  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use emplace_back
+  // CHECK-FIXES: v.emplace_back(false, 'x', 1);
+
+  v.push_back(std::tuple{false, 'y', 2});
+  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use emplace_back
+  // CHECK-FIXES: v.emplace_back(false, 'y', 2);
+
+  v.push_back({true, 'z', 3});
+  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use emplace_back
+  // CHECK-FIXES: v.emplace_back(true, 'z', 3);
+
+  std::vector> x;
+  x.push_back(std::make_pair(1, false));
+  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use emplace_back
+  // CHECK-FIXES: x.emplace_back(1, false);
+
+  x.push_back(std::make_pair(2LL, 1));
+  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use emplace_back
+  // CHECK-FIXES: x.emplace_back(2LL, 1);
+}
+
 struct Base {
   Base(int, int *, int = 42);
 };
@@ -318,6 +369,23 @@
   // make_pair cannot be removed here, as Y is not constructible with two ints.
 }
 
+void testMakeTuple() {
+  std::vector> v;
+  v.push_back(std::make_tuple(1, true, 'v'));
+  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use emplace_back
+  // CHECK-FIXES: v.emplace_back(1, true, 'v');
+
+  v.push_back(std::make_tuple(2ULL, 1, 0));
+  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use emplace_back
+  // CHECK-FIXES: v.emplace_back(2ULL, 1, 0);
+
+  v.push_back(std::make_tuple(3LL, 1, 0));
+  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use emplace_back
+  // CHECK-FIXES: v.emplace_back(std::make_tuple(3LL, 1, 0));
+  // make_tuple is not removed when there are explicit template
+  // arguments provided.
+}
+
 void testOtherContainers() {
   std::list l;
   l.push_back(Something(42, 41));
@@ -437,7 +505,7 @@
   void doStuff() {
 std::vector v;
 // This should not change it because emplace back doesn't have permission.
-// Check currently doesn't support friend delcarations because pretty much
+// Check currently doesn't support friend declarations because pretty much
 // nobody would want to be friend with std::vector :(.
 v.push_back(PrivateCtor(42));
   }
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -109,8 +109,8 @@
 - Improved `modernize-use-emplace
   `_ check
 
-  Removes unnecessary std::make_pair calls in push_back(std::make_pair(a, b)) calls and turns them
-  into emplace_back(a, b).
+  Removes unnecessary ``std::make_pair`` and ``std::make_tuple`` calls in push_back calls
+  and turns them into emplace_back.
 
 Improvements to include-fixer
 -
Index: clang-tidy/modernize/UseEmplaceCheck.cpp
===
--- clang-tidy/modernize/UseEmplaceCheck.cpp
+++ clang-tidy/modernize/UseEmplaceCheck.cpp
@@ -85,21 +85

[PATCH] D32690: [clang-tidy] modernize-use-emplace: Remove unnecessary make_tuple calls

2017-04-30 Thread Jakub Kuderski via Phabricator via cfe-commits
kuhar updated this revision to Diff 97248.
kuhar added a comment.

Cosmetic changes.


https://reviews.llvm.org/D32690

Files:
  clang-tidy/modernize/UseEmplaceCheck.cpp
  docs/ReleaseNotes.rst
  test/clang-tidy/modernize-use-emplace.cpp

Index: test/clang-tidy/modernize-use-emplace.cpp
===
--- test/clang-tidy/modernize-use-emplace.cpp
+++ test/clang-tidy/modernize-use-emplace.cpp
@@ -36,27 +36,54 @@
   ~deque();
 };
 
-template 
-class pair {
+template  struct remove_reference { using type = T; };
+template  struct remove_reference { using type = T; };
+template  struct remove_reference { using type = T; };
+
+template  class pair {
 public:
   pair() = default;
   pair(const pair &) = default;
   pair(pair &&) = default;
 
   pair(const T1 &, const T2 &) {}
   pair(T1 &&, T2 &&) {}
 
-  template 
-  pair(const pair &p){};
-  template 
-  pair(pair &&p){};
+  template  pair(const pair &){};
+  template  pair(pair &&){};
 };
 
 template 
-pair make_pair(T1&&, T2&&) {
+pair::type, typename remove_reference::type>
+make_pair(T1 &&, T2 &&) {
   return {};
 };
 
+template  class tuple {
+public:
+  tuple() = default;
+  tuple(const tuple &) = default;
+  tuple(tuple &&) = default;
+
+  tuple(const Ts &...) {}
+  tuple(Ts &&...) {}
+
+  template  tuple(const tuple &){};
+  template  tuple(tuple &&) {}
+
+  template  tuple(const pair &) {
+static_assert(sizeof...(Ts) == 2, "Wrong tuple size");
+  };
+  template  tuple(pair &&) {
+static_assert(sizeof...(Ts) == 2, "Wrong tuple size");
+  };
+};
+
+template 
+tuple::type...> make_tuple(Ts &&...) {
+  return {};
+}
+
 template 
 class unique_ptr {
 public:
@@ -197,6 +224,30 @@
   // CHECK-FIXES: v2.emplace_back(Something(42, 42), Zoz(Something(21, 37)));
 }
 
+void testTuple() {
+  std::vector> v;
+  v.push_back(std::tuple(false, 'x', 1));
+  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use emplace_back
+  // CHECK-FIXES: v.emplace_back(false, 'x', 1);
+
+  v.push_back(std::tuple{false, 'y', 2});
+  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use emplace_back
+  // CHECK-FIXES: v.emplace_back(false, 'y', 2);
+
+  v.push_back({true, 'z', 3});
+  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use emplace_back
+  // CHECK-FIXES: v.emplace_back(true, 'z', 3);
+
+  std::vector> x;
+  x.push_back(std::make_pair(1, false));
+  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use emplace_back
+  // CHECK-FIXES: x.emplace_back(1, false);
+
+  x.push_back(std::make_pair(2LL, 1));
+  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use emplace_back
+  // CHECK-FIXES: x.emplace_back(2LL, 1);
+}
+
 struct Base {
   Base(int, int *, int = 42);
 };
@@ -318,6 +369,23 @@
   // make_pair cannot be removed here, as Y is not constructible with two ints.
 }
 
+void testMakeTuple() {
+  std::vector> v;
+  v.push_back(std::make_tuple(1, true, 'v'));
+  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use emplace_back
+  // CHECK-FIXES: v.emplace_back(1, true, 'v');
+
+  v.push_back(std::make_tuple(2ULL, 1, 0));
+  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use emplace_back
+  // CHECK-FIXES: v.emplace_back(2ULL, 1, 0);
+
+  v.push_back(std::make_tuple(3LL, 1, 0));
+  // CHECK-MESSAGES: :[[@LINE-1]]:5: warning: use emplace_back
+  // CHECK-FIXES: v.emplace_back(std::make_tuple(3LL, 1, 0));
+  // make_tuple is not removed when there are explicit template
+  // arguments provided.
+}
+
 void testOtherContainers() {
   std::list l;
   l.push_back(Something(42, 41));
@@ -437,7 +505,7 @@
   void doStuff() {
 std::vector v;
 // This should not change it because emplace back doesn't have permission.
-// Check currently doesn't support friend delcarations because pretty much
+// Check currently doesn't support friend declarations because pretty much
 // nobody would want to be friend with std::vector :(.
 v.push_back(PrivateCtor(42));
   }
Index: docs/ReleaseNotes.rst
===
--- docs/ReleaseNotes.rst
+++ docs/ReleaseNotes.rst
@@ -109,8 +109,8 @@
 - Improved `modernize-use-emplace
   `_ check
 
-  Removes unnecessary std::make_pair calls in push_back(std::make_pair(a, b)) calls and turns them
-  into emplace_back(a, b).
+  Removes unnecessary ``std::make_pair`` and ``std::make_tuple`` calls in push_back calls
+  and turns them into emplace_back.
 
 Improvements to include-fixer
 -
Index: clang-tidy/modernize/UseEmplaceCheck.cpp
===
--- clang-tidy/modernize/UseEmplaceCheck.cpp
+++ clang-tidy/modernize/UseEmplaceCheck.cpp
@@ -85,20 +85,22 @@
   .bind("ctor");
   auto HasConstructExpr = has(ignoringImplicit(SoughtConstructExpr));
 
-  auto MakePair = ignoringImplicit(
-  callExpr(callee(expr(ignoringImplicit(
-  declRefExpr(unless(hasExplicitTemplateArgs()),
-  

[PATCH] D32690: [clang-tidy] modernize-use-emplace: Remove unnecessary make_tuple calls

2017-04-30 Thread Jonas Toth via Phabricator via cfe-commits
JonasToth added a comment.

Nothing to complain from my side.
Would it make sense to add boost pairs/tuples support?
 I could imagine modernize checks that would transform boost structures into 
the stl ones, but that's another discussion probably.

Something for a later check: the same logic should apply for `insert` and 
`emplace`, we should add support for these methods too.


https://reviews.llvm.org/D32690



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


[PATCH] D32690: [clang-tidy] modernize-use-emplace: Remove unnecessary make_tuple calls

2017-04-30 Thread Jakub Kuderski via Phabricator via cfe-commits
kuhar added a comment.

In https://reviews.llvm.org/D32690#741952, @JonasToth wrote:

> Would it make sense to add boost pairs/tuples support?


I think it can be added the same way it is possible to specify smart pointers 
and vector-like containers now. It would require users to provide both types 
and make functions (eg. thingy and make_thingy). I'm not sure if that would be 
any useful in practise, though.

> Something for a later check: the same logic should apply for `insert` and 
> `emplace`, we should add support for these methods too.

Yeah, I plan to do that a few patches from now, after other things are improved.


https://reviews.llvm.org/D32690



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


r301783 - utils: Silence -Wpedantic warning

2017-04-30 Thread Saleem Abdulrasool via cfe-commits
Author: compnerd
Date: Sun Apr 30 19:26:59 2017
New Revision: 301783

URL: http://llvm.org/viewvc/llvm-project?rev=301783&view=rev
Log:
utils: Silence -Wpedantic warning

llvm/tools/clang/utils/TableGen/ClangAttrEmitter.cpp:1673:67: warning: default 
argument specified for lambda parameter [-Wpedantic]
const Record *Constraint = nullptr) {
   ^~~

Found by gcc 5.4.0.

Modified:
cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp

Modified: cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp?rev=301783&r1=301782&r2=301783&view=diff
==
--- cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp (original)
+++ cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp Sun Apr 30 19:26:59 2017
@@ -1670,7 +1670,7 @@ PragmaClangAttributeSupport::PragmaClang
   Records.getAllDerivedDefinitions("AttrSubjectMatcherRule");
   auto MapFromSubjectsToRules = [this](const Record *SubjectContainer,
const Record *MetaSubject,
-   const Record *Constraint = nullptr) {
+   const Record *Constraint) {
 Rules.emplace_back(MetaSubject, Constraint);
 std::vector ApplicableSubjects =
 SubjectContainer->getValueAsListOfDefs("Subjects");
@@ -1688,7 +1688,7 @@ PragmaClangAttributeSupport::PragmaClang
 }
   };
   for (const auto *MetaSubject : MetaSubjects) {
-MapFromSubjectsToRules(MetaSubject, MetaSubject);
+MapFromSubjectsToRules(MetaSubject, MetaSubject, /*Constraints=*/nullptr);
 std::vector Constraints =
 MetaSubject->getValueAsListOfDefs("Constraints");
 for (const auto *Constraint : Constraints)


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


[PATCH] D32675: in expression evaluator, treat non-literal types as discarded value expressions if EvalInfo says to continue evaluating them

2017-04-30 Thread Richard Smith via Phabricator via cfe-commits
rsmith accepted this revision.
rsmith added a comment.
This revision is now accepted and ready to land.

Thanks. Could you also add something like:

  struct A {};
  struct B : virtual A {};
  constexpr A &a = (A&)*(B*)0;

to test/SemaCXX/constant-expression-cxx11.cpp to ensure we produce a suitable 
diagnostic, please?


https://reviews.llvm.org/D32675



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


[PATCH] D31839: make -Winteger-overflow find overflows in function arguments

2017-04-30 Thread Nick Lewycky via Phabricator via cfe-commits
nlewycky updated this revision to Diff 97253.
nlewycky added a comment.

Use an RAII object to always evaluate the arguments, except if 
HandleFunctionCall does it.


https://reviews.llvm.org/D31839

Files:
  lib/AST/ExprConstant.cpp
  test/Sema/integer-overflow.c


Index: test/Sema/integer-overflow.c
===
--- test/Sema/integer-overflow.c
+++ test/Sema/integer-overflow.c
@@ -151,6 +151,14 @@
   uint64_t *b;
   uint64_t b2 = b[4608 * 1024 * 1024] + 1;
 
+// expected-warning@+1 {{overflow in expression; result is 536870912 with type 
'int'}} 
+  f0(4608 * 1024 * 1024);
+  f0(4608ul * 1024 * 1024);
+// expected-warning@+1 2{{overflow in expression; result is 536870912 with 
type 'int'}} 
+  f1(4608 * 1024 * 1024, 4608 * 1024 * 1024);
+// expected-warning@+1 2{{overflow in expression; result is 536870912 with 
type 'int'}} 
+  f2(4608 * 1024 * 1024, 4608 * 1024 * 1024);
+
 // expected-warning@+1 2{{overflow in expression; result is 536870912 with 
type 'int'}}
   int j1 = i ? (4608 * 1024 * 1024) : (4608 * 1024 * 1024);
 
Index: lib/AST/ExprConstant.cpp
===
--- lib/AST/ExprConstant.cpp
+++ lib/AST/ExprConstant.cpp
@@ -4579,15 +4579,32 @@
   }
 
   bool handleCallExpr(const CallExpr *E, APValue &Result,
- const LValue *ResultSlot) {
+  const LValue *ResultSlot) {
 const Expr *Callee = E->getCallee()->IgnoreParens();
 QualType CalleeType = Callee->getType();
 
 const FunctionDecl *FD = nullptr;
 LValue *This = nullptr, ThisVal;
 auto Args = llvm::makeArrayRef(E->getArgs(), E->getNumArgs());
 bool HasQualifier = false;
 
+struct EvaluateIgnoredRAII {
+public:
+  EvaluateIgnoredRAII(EvalInfo &Info, llvm::ArrayRef ToEval)
+  : Info(Info), ToEval(ToEval) {}
+  ~EvaluateIgnoredRAII() {
+if (Info.noteFailure()) {
+  for (auto E : ToEval)
+EvaluateIgnoredValue(Info, E);
+}
+  }
+  void cancel() { ToEval = {}; }
+  void drop_front() { ToEval = ToEval.drop_front(); }
+private:
+  EvalInfo &Info;
+  llvm::ArrayRef ToEval;
+} EvalArguments(Info, Args);
+
 // Extract function decl and 'this' pointer from the callee.
 if (CalleeType->isSpecificBuiltinType(BuiltinType::BoundMember)) {
   const ValueDecl *Member = nullptr;
@@ -4637,10 +4654,12 @@
 if (Args.empty())
   return Error(E);
 
-if (!EvaluateObjectArgument(Info, Args[0], ThisVal))
+const Expr *FirstArg = Args[0];
+Args = Args.drop_front();
+EvalArguments.drop_front();
+if (!EvaluateObjectArgument(Info, FirstArg, ThisVal))
   return false;
 This = &ThisVal;
-Args = Args.slice(1);
   } else if (MD && MD->isLambdaStaticInvoker()) {   
 // Map the static invoker for the lambda back to the call operator.
 // Conveniently, we don't have to slice out the 'this' argument (as is
@@ -4692,8 +4711,12 @@
 const FunctionDecl *Definition = nullptr;
 Stmt *Body = FD->getBody(Definition);
 
-if (!CheckConstexprFunction(Info, E->getExprLoc(), FD, Definition, Body) ||
-!HandleFunctionCall(E->getExprLoc(), Definition, This, Args, Body, 
Info,
+if (!CheckConstexprFunction(Info, E->getExprLoc(), FD, Definition, Body))
+  return false;
+
+EvalArguments.cancel();
+
+if (!HandleFunctionCall(E->getExprLoc(), Definition, This, Args, Body, 
Info,
 Result, ResultSlot))
   return false;
 


Index: test/Sema/integer-overflow.c
===
--- test/Sema/integer-overflow.c
+++ test/Sema/integer-overflow.c
@@ -151,6 +151,14 @@
   uint64_t *b;
   uint64_t b2 = b[4608 * 1024 * 1024] + 1;
 
+// expected-warning@+1 {{overflow in expression; result is 536870912 with type 'int'}} 
+  f0(4608 * 1024 * 1024);
+  f0(4608ul * 1024 * 1024);
+// expected-warning@+1 2{{overflow in expression; result is 536870912 with type 'int'}} 
+  f1(4608 * 1024 * 1024, 4608 * 1024 * 1024);
+// expected-warning@+1 2{{overflow in expression; result is 536870912 with type 'int'}} 
+  f2(4608 * 1024 * 1024, 4608 * 1024 * 1024);
+
 // expected-warning@+1 2{{overflow in expression; result is 536870912 with type 'int'}}
   int j1 = i ? (4608 * 1024 * 1024) : (4608 * 1024 * 1024);
 
Index: lib/AST/ExprConstant.cpp
===
--- lib/AST/ExprConstant.cpp
+++ lib/AST/ExprConstant.cpp
@@ -4579,15 +4579,32 @@
   }
 
   bool handleCallExpr(const CallExpr *E, APValue &Result,
- const LValue *ResultSlot) {
+  const LValue *ResultSlot) {
 const Expr *Callee = E->getCallee()->IgnoreParens();
 QualType CalleeType = Callee->getType();
 
 const FunctionDecl *FD = nullptr;
 LValue *This = nullptr, ThisVal;
 auto Args = llvm::m

r301785 - Handle expressions with non-literal types like ignored expressions if we are supposed to continue evaluating them.

2017-04-30 Thread Nick Lewycky via cfe-commits
Author: nicholas
Date: Sun Apr 30 21:03:23 2017
New Revision: 301785

URL: http://llvm.org/viewvc/llvm-project?rev=301785&view=rev
Log:
Handle expressions with non-literal types like ignored expressions if we are 
supposed to continue evaluating them.

Also fix a crash casting a derived nullptr to a virtual base.

Modified:
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/test/Sema/integer-overflow.c
cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=301785&r1=301784&r2=301785&view=diff
==
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Sun Apr 30 21:03:23 2017
@@ -2169,6 +2169,9 @@ static bool HandleLValueBase(EvalInfo &I
   if (!Base->isVirtual())
 return HandleLValueDirectBase(Info, E, Obj, DerivedDecl, BaseDecl);
 
+  if (!Obj.checkNullPointer(Info, E, CSK_Base))
+return false;
+
   SubobjectDesignator &D = Obj.Designator;
   if (D.Invalid)
 return false;
@@ -9913,8 +9916,11 @@ static bool EvaluateAsRValue(EvalInfo &I
   if (E->getType().isNull())
 return false;
 
-  if (!CheckLiteralType(Info, E))
+  if (!CheckLiteralType(Info, E)) {
+if (Info.noteFailure())
+  EvaluateIgnoredValue(Info, E);
 return false;
+  }
 
   if (!::Evaluate(Result, Info, E))
 return false;

Modified: cfe/trunk/test/Sema/integer-overflow.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/integer-overflow.c?rev=301785&r1=301784&r2=301785&view=diff
==
--- cfe/trunk/test/Sema/integer-overflow.c (original)
+++ cfe/trunk/test/Sema/integer-overflow.c Sun Apr 30 21:03:23 2017
@@ -149,16 +149,16 @@ uint64_t check_integer_overflows(int i)
 
 // expected-warning@+2 {{overflow in expression; result is 536870912 with type 
'int'}}
   uint64_t *b;
-  uint64_t b2 = b[4608 * 1024 * 1024] + 1;
+  (void)b[4608 * 1024 * 1024] + 1;
 
 // expected-warning@+1 2{{overflow in expression; result is 536870912 with 
type 'int'}}
-  int j1 = i ? (4608 * 1024 * 1024) : (4608 * 1024 * 1024);
+  (void)(i ? (4608 * 1024 * 1024) : (4608 * 1024 * 1024));
 
 // expected-warning@+1 {{overflow in expression; result is 536870912 with type 
'int'}}
-  int j2 = -(4608 * 1024 * 1024);
+  (void)(-(4608 * 1024 * 1024));
 
 // expected-warning@+1 {{overflow in expression; result is 536870912 with type 
'int'}}
-  uint64_t j3 = b[4608 * 1024 * 1024];
+  (void)b[4608 * 1024 * 1024];
 
 // expected-warning@+1 2{{overflow in expression; result is 536870912 with 
type 'int'}}
   return ((4608 * 1024 * 1024) + ((uint64_t)(4608 * 1024 * 1024)));

Modified: cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp?rev=301785&r1=301784&r2=301785&view=diff
==
--- cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp (original)
+++ cfe/trunk/test/SemaCXX/constant-expression-cxx11.cpp Sun Apr 30 21:03:23 
2017
@@ -60,6 +60,10 @@ namespace DerivedToVBaseCast {
   static_assert((U*)&d == w, "");
   static_assert((U*)&d == x, "");
 
+  // expected-error@+2 {{constexpr variable 'a' must be initialized by a 
constant expression}}
+  // expected-warning@+1 {{binding dereferenced null pointer to reference has 
undefined behavior}}
+  constexpr A &a = *((B*)0);  // expected-note {{cannot access base class of 
null pointer}}
+
   struct X {};
   struct Y1 : virtual X {};
   struct Y2 : X {};


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


r301786 - Fix line endings (dos -> unix) and clang-format while I'm here

2017-04-30 Thread David Blaikie via cfe-commits
Author: dblaikie
Date: Sun Apr 30 21:11:39 2017
New Revision: 301786

URL: http://llvm.org/viewvc/llvm-project?rev=301786&view=rev
Log:
Fix line endings (dos -> unix) and clang-format while I'm here

Modified:
cfe/trunk/test/SemaCXX/cxx1z-lambda-star-this.cpp

Modified: cfe/trunk/test/SemaCXX/cxx1z-lambda-star-this.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/cxx1z-lambda-star-this.cpp?rev=301786&r1=301785&r2=301786&view=diff
==
--- cfe/trunk/test/SemaCXX/cxx1z-lambda-star-this.cpp (original)
+++ cfe/trunk/test/SemaCXX/cxx1z-lambda-star-this.cpp Sun Apr 30 21:11:39 2017
@@ -1,297 +1,293 @@
-// RUN: %clang_cc1 -std=c++1z -verify -fsyntax-only -fblocks -emit-llvm-only %s
-// RUN: %clang_cc1 -std=c++1z -verify -fsyntax-only -fblocks 
-fdelayed-template-parsing %s -DDELAYED_TEMPLATE_PARSING
-// RUN: %clang_cc1 -std=c++1z -verify -fsyntax-only -fblocks -fms-extensions 
%s -DMS_EXTENSIONS
-// RUN: %clang_cc1 -std=c++1z -verify -fsyntax-only -fblocks 
-fdelayed-template-parsing -fms-extensions %s -DMS_EXTENSIONS 
-DDELAYED_TEMPLATE_PARSING
-
-template constexpr bool is_same = false;
-template constexpr bool is_same = true;
-
-namespace test_star_this {
-namespace ns1 {
-class A {
-  int x = 345;
-  auto foo() {
-(void) [*this, this] { };  //expected-error{{'this' can appear only once}}
-(void) [this] { ++x; };
-(void) [*this] { ++x; };  //expected-error{{read-only variable}}
-(void) [*this] () mutable { ++x; };
-(void) [=] { return x; };
-(void) [&, this] { return x; };
-(void) [=, *this] { return x; };
-(void) [&, *this] { return x; };
-  }
-};
-} // end ns1
-
-namespace ns2 {
-  class B {
-B(const B&) = delete; //expected-note{{deleted here}}
-int *x = (int *) 456;
-void foo() {
-  (void)[this] { return x; };
-  (void)[*this] { return x; }; //expected-error{{call to deleted}}
-}
-  };
-} // end ns2
-namespace ns3 {
-  class B {
-B(const B&) = delete; //expected-note2{{deleted here}}
-
-int *x = (int *) 456;
-public: 
-template
-void foo() {
-  (void)[this] { return x; };
-  (void)[*this] { return x; }; //expected-error2{{call to deleted}}
-}
-
-B() = default;
-  } b;
-  B *c = (b.foo(), nullptr); //expected-note{{in instantiation}}
-} // end ns3
-
-namespace ns4 {
-template
-class B {
-  B(const B&) = delete; //expected-note{{deleted here}}
-  double d = 3.14;
-  public: 
-  template
-  auto foo() {
-const auto &L = [*this] (auto a) mutable { //expected-error{{call to 
deleted}}
-  d += a; 
-  return [this] (auto b) { return d +=b; }; 
-}; 
-  }
-  
-  B() = default;
-};
-void main() {
-  B b;
-  b.foo(); //expected-note{{in instantiation}}
-} // end main  
-} // end ns4
-namespace ns5 {
-
-struct X {
-  double d = 3.14;
-  X(const volatile X&);
-  void foo() {
-  
-  }
-  
-  void foo() const { //expected-note{{const}}
-
-auto L = [*this] () mutable { 
-  static_assert(is_same);
-  ++d;
-  auto M = [this] { 
-static_assert(is_same);  
-++d;
-auto N = [] {
-  static_assert(is_same); 
-};
-  };
-};
-
-auto L1 = [*this] { 
-  static_assert(is_same);
-  auto M = [this] () mutable { 
-static_assert(is_same);  
-auto N = [] {
-  static_assert(is_same); 
-};
-  };
-  auto M2 = [*this] () mutable { 
-static_assert(is_same);  
-auto N = [] {
-  static_assert(is_same); 
-};
-  };
-};
-
-auto GL1 = [*this] (auto a) { 
-  static_assert(is_same);
-  auto M = [this] (auto b) mutable { 
-static_assert(is_same);  
-auto N = [] (auto c) {
-  static_assert(is_same); 
-};
-return N;
-  };
-  
-  auto M2 = [*this] (auto a) mutable { 
-static_assert(is_same);  
-auto N = [] (auto b) {
-  static_assert(is_same); 
-};
-return N;
-  };
-  return [=](auto a) mutable { M(a)(a); M2(a)(a); };
-};
-
-GL1("abc")("abc");
-
-
-auto L2 = [this] () mutable {
-  static_assert(is_same);  
-  ++d; //expected-error{{cannot assign}}
-};
-auto GL = [*this] (auto a) mutable {
-  static_assert(is_same);
-  ++d;
-  auto M = [this] (auto b) { 
-static_assert(is_same);  
-++d;
-auto N = [] (auto c) {
-  static_assert(is_same); 
-};
-N(3.14);
-  };
-  M("abc");
-};
-GL(3.14);
- 
-  }
-  void foo() volatile const {
-auto L = [this] () {
-  static_assert(is_same);
-  auto M = [*this] () mutable { 
-static_assert(is_same);
-auto N = [this] {
-  static_assert(is_same);
-  auto M = [] {
-static_assert(is_same);
-  };
-};
-auto N2 = [*this] {
-  static_assert(is_same

r301787 - Fix test that was incorrected merged between patches.

2017-04-30 Thread Nick Lewycky via cfe-commits
Author: nicholas
Date: Sun Apr 30 21:20:06 2017
New Revision: 301787

URL: http://llvm.org/viewvc/llvm-project?rev=301787&view=rev
Log:
Fix test that was incorrected merged between patches.

Modified:
cfe/trunk/test/Sema/integer-overflow.c

Modified: cfe/trunk/test/Sema/integer-overflow.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/integer-overflow.c?rev=301787&r1=301786&r2=301787&view=diff
==
--- cfe/trunk/test/Sema/integer-overflow.c (original)
+++ cfe/trunk/test/Sema/integer-overflow.c Sun Apr 30 21:20:06 2017
@@ -149,7 +149,7 @@ uint64_t check_integer_overflows(int i)
 
 // expected-warning@+2 {{overflow in expression; result is 536870912 with type 
'int'}}
   uint64_t *b;
-  (void)b[4608 * 1024 * 1024] + 1;
+  (void)b[4608 * 1024 * 1024];
 
 // expected-warning@+1 2{{overflow in expression; result is 536870912 with 
type 'int'}}
   (void)(i ? (4608 * 1024 * 1024) : (4608 * 1024 * 1024));


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


[PATCH] D32378: Insert invariant.group.barrier for pointers comparisons

2017-04-30 Thread Hubert Tong via Phabricator via cfe-commits
hubert.reinterpretcast added a comment.

Has it been discussed whether this is something to be addressed in the 
optimizer as opposed to the front-end?




Comment at: lib/CodeGen/CGExprScalar.cpp:3069
+  !isa(RHS)) {
+// Based on comparisons of pointers to dynamic objects, the optimizer
+// can replace one pointer with another. This might result in

Consider:
```
extern "C" int printf(const char *, ...);
void *operator new(decltype(sizeof 0), void *);

struct A {
  virtual void foo() { printf("%s\n", __PRETTY_FUNCTION__); }
  int m;
  int *zip() { return &m; }
};

struct B : A {
  virtual void foo() { printf("%s\n", __PRETTY_FUNCTION__); }
};

int main(void) {
  A *ap = new A;
  ap->foo();
  int *const apz = ap->zip();
  B *bp = new (ap) B;
  if (apz == bp->zip()) {
bp->foo();
  }
}
```


https://reviews.llvm.org/D32378



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


r301789 - Remove unneeded struct; NFC

2017-04-30 Thread Sanjoy Das via cfe-commits
Author: sanjoy
Date: Mon May  1 01:12:13 2017
New Revision: 301789

URL: http://llvm.org/viewvc/llvm-project?rev=301789&view=rev
Log:
Remove unneeded struct; NFC

Summary:
Unless I'm missing something, the DeferredGlobal struct's GV field is
unused, removing which makes the struct itself trivial.

Reviewers: rafael, chandlerc

Subscribers: mcrosier, llvm-commits

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

Modified:
cfe/trunk/lib/CodeGen/CodeGenModule.cpp
cfe/trunk/lib/CodeGen/CodeGenModule.h

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=301789&r1=301788&r2=301789&view=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Mon May  1 01:12:13 2017
@@ -1328,13 +1328,10 @@ void CodeGenModule::EmitDeferred() {
 
   // Grab the list of decls to emit. If EmitGlobalDefinition schedules more
   // work, it will not interfere with this.
-  std::vector CurDeclsToEmit;
+  std::vector CurDeclsToEmit;
   CurDeclsToEmit.swap(DeferredDeclsToEmit);
 
-  for (DeferredGlobal &G : CurDeclsToEmit) {
-GlobalDecl D = G.GD;
-G.GV = nullptr;
-
+  for (GlobalDecl &D : CurDeclsToEmit) {
 // We should call GetAddrOfGlobal with IsForDefinition set to true in order
 // to get GlobalValue with exactly the type we need, not something that
 // might had been created for another decl with the same mangled name but
@@ -1711,13 +1708,13 @@ void CodeGenModule::EmitGlobal(GlobalDec
   }
 
   StringRef MangledName = getMangledName(GD);
-  if (llvm::GlobalValue *GV = GetGlobalValue(MangledName)) {
+  if (GetGlobalValue(MangledName) != nullptr) {
 // The value has already been used and should therefore be emitted.
-addDeferredDeclToEmit(GV, GD);
+addDeferredDeclToEmit(GD);
   } else if (MustBeEmitted(Global)) {
 // The value must be emitted, but cannot be emitted eagerly.
 assert(!MayBeEmittedEagerly(Global));
-addDeferredDeclToEmit(/*GV=*/nullptr, GD);
+addDeferredDeclToEmit(GD);
   } else {
 // Otherwise, remember that we saw a deferred decl with this name.  The
 // first use of the mangled name will cause it to move into
@@ -2044,7 +2041,7 @@ llvm::Constant *CodeGenModule::GetOrCrea
 if (D && isa(D) &&
 getCXXABI().useThunkForDtorVariant(cast(D),
GD.getDtorType()))
-  addDeferredDeclToEmit(F, GD);
+  addDeferredDeclToEmit(GD);
 
 // This is the first use or definition of a mangled name.  If there is a
 // deferred decl with this name, remember that we need to emit it at the 
end
@@ -2054,7 +2051,7 @@ llvm::Constant *CodeGenModule::GetOrCrea
   // Move the potentially referenced deferred decl to the
   // DeferredDeclsToEmit list, and remove it from DeferredDecls (since we
   // don't need it anymore).
-  addDeferredDeclToEmit(F, DDI->second);
+  addDeferredDeclToEmit(DDI->second);
   DeferredDecls.erase(DDI);
 
   // Otherwise, there are cases we have to worry about where we're
@@ -2074,7 +2071,7 @@ llvm::Constant *CodeGenModule::GetOrCrea
FD = FD->getPreviousDecl()) {
 if (isa(FD->getLexicalDeclContext())) {
   if (FD->doesThisDeclarationHaveABody()) {
-addDeferredDeclToEmit(F, GD.getWithDecl(FD));
+addDeferredDeclToEmit(GD.getWithDecl(FD));
 break;
   }
 }
@@ -2302,7 +2299,7 @@ CodeGenModule::GetOrCreateLLVMGlobal(Str
   if (DDI != DeferredDecls.end()) {
 // Move the potentially referenced deferred decl to the DeferredDeclsToEmit
 // list, and remove it from DeferredDecls (since we don't need it anymore).
-addDeferredDeclToEmit(GV, DDI->second);
+addDeferredDeclToEmit(DDI->second);
 DeferredDecls.erase(DDI);
   }
 

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.h?rev=301789&r1=301788&r2=301789&view=diff
==
--- cfe/trunk/lib/CodeGen/CodeGenModule.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.h Mon May  1 01:12:13 2017
@@ -315,14 +315,9 @@ private:
 
   /// This is a list of deferred decls which we have seen that *are* actually
   /// referenced. These get code generated when the module is done.
-  struct DeferredGlobal {
-DeferredGlobal(llvm::GlobalValue *GV, GlobalDecl GD) : GV(GV), GD(GD) {}
-llvm::TrackingVH GV;
-GlobalDecl GD;
-  };
-  std::vector DeferredDeclsToEmit;
-  void addDeferredDeclToEmit(llvm::GlobalValue *GV, GlobalDecl GD) {
-DeferredDeclsToEmit.emplace_back(GV, GD);
+  std::vector DeferredDeclsToEmit;
+  void addDeferredDeclToEmit(GlobalDecl GD) {
+DeferredDeclsToEmit.emplace_back(GD);
   }
 
   /// List of alias we have emitted. Used to make sure that what t