[PATCH] D59756: [clangd] Support dependent bases in type hierarchy

2019-04-21 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added a comment.

Thanks!


Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D59756/new/

https://reviews.llvm.org/D59756



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


[PATCH] D59756: [clangd] Support dependent bases in type hierarchy

2019-04-21 Thread Fangrui Song via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL358866: [clangd] Support dependent bases in type hierarchy 
(authored by MaskRay, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D59756?vs=194002=196026#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D59756/new/

https://reviews.llvm.org/D59756

Files:
  clang-tools-extra/trunk/clangd/XRefs.cpp
  clang-tools-extra/trunk/unittests/clangd/TypeHierarchyTests.cpp

Index: clang-tools-extra/trunk/unittests/clangd/TypeHierarchyTests.cpp
===
--- clang-tools-extra/trunk/unittests/clangd/TypeHierarchyTests.cpp
+++ clang-tools-extra/trunk/unittests/clangd/TypeHierarchyTests.cpp
@@ -291,9 +291,7 @@
   EXPECT_THAT(typeParents(ChildSpec), ElementsAre(Parent));
 }
 
-// This is disabled for now, because support for dependent bases
-// requires additional measures to avoid infinite recursion.
-TEST(DISABLED_TypeParents, DependentBase) {
+TEST(TypeParents, DependentBase) {
   Annotations Source(R"cpp(
 template 
 struct Parent {};
@@ -383,10 +381,10 @@
   }
 }
 
-TEST(TypeHierarchy, RecursiveHierarchy1) {
+TEST(TypeHierarchy, RecursiveHierarchyUnbounded) {
   Annotations Source(R"cpp(
   template 
-  struct S : S {};
+  struct $SDef[[S]] : S {};
 
   S^<0> s;
   )cpp");
@@ -399,62 +397,57 @@
   ASSERT_TRUE(!AST.getDiagnostics().empty());
 
   // Make sure getTypeHierarchy() doesn't get into an infinite recursion.
+  // FIXME(nridge): It would be preferable if the type hierarchy gave us type
+  // names (e.g. "S<0>" for the child and "S<1>" for the parent) rather than
+  // template names (e.g. "S").
   llvm::Optional Result = getTypeHierarchy(
   AST, Source.points()[0], 0, TypeHierarchyDirection::Parents);
   ASSERT_TRUE(bool(Result));
-  EXPECT_THAT(*Result,
-  AllOf(WithName("S"), WithKind(SymbolKind::Struct), Parents()));
+  EXPECT_THAT(
+  *Result,
+  AllOf(WithName("S"), WithKind(SymbolKind::Struct),
+Parents(AllOf(WithName("S"), WithKind(SymbolKind::Struct),
+  SelectionRangeIs(Source.range("SDef")), Parents();
 }
 
-TEST(TypeHierarchy, RecursiveHierarchy2) {
+TEST(TypeHierarchy, RecursiveHierarchyBounded) {
   Annotations Source(R"cpp(
   template 
-  struct S : S {};
+  struct $SDef[[S]] : S {};
 
   template <>
   struct S<0>{};
 
-  S^<2> s;
-  )cpp");
-
-  TestTU TU = TestTU::withCode(Source.code());
-  auto AST = TU.build();
-
-  ASSERT_TRUE(AST.getDiagnostics().empty());
-
-  // Make sure getTypeHierarchy() doesn't get into an infinite recursion.
-  llvm::Optional Result = getTypeHierarchy(
-  AST, Source.points()[0], 0, TypeHierarchyDirection::Parents);
-  ASSERT_TRUE(bool(Result));
-  EXPECT_THAT(*Result,
-  AllOf(WithName("S"), WithKind(SymbolKind::Struct), Parents()));
-}
-
-TEST(TypeHierarchy, RecursiveHierarchy3) {
-  Annotations Source(R"cpp(
-  template 
-  struct S : S {};
-
-  template <>
-  struct S<0>{};
+  S$SRefConcrete^<2> s;
 
   template 
   struct Foo {
-S^ s;
-  };
-  )cpp");
+S$SRefDependent^ s;
+  };)cpp");
 
   TestTU TU = TestTU::withCode(Source.code());
   auto AST = TU.build();
 
   ASSERT_TRUE(AST.getDiagnostics().empty());
 
-  // Make sure getTypeHierarchy() doesn't get into an infinite recursion.
+  // Make sure getTypeHierarchy() doesn't get into an infinite recursion
+  // for either a concrete starting point or a dependent starting point.
   llvm::Optional Result = getTypeHierarchy(
-  AST, Source.points()[0], 0, TypeHierarchyDirection::Parents);
+  AST, Source.point("SRefConcrete"), 0, TypeHierarchyDirection::Parents);
+  ASSERT_TRUE(bool(Result));
+  EXPECT_THAT(
+  *Result,
+  AllOf(WithName("S"), WithKind(SymbolKind::Struct),
+Parents(AllOf(WithName("S"), WithKind(SymbolKind::Struct),
+  SelectionRangeIs(Source.range("SDef")), Parents();
+  Result = getTypeHierarchy(AST, Source.point("SRefDependent"), 0,
+TypeHierarchyDirection::Parents);
   ASSERT_TRUE(bool(Result));
-  EXPECT_THAT(*Result,
-  AllOf(WithName("S"), WithKind(SymbolKind::Struct), Parents()));
+  EXPECT_THAT(
+  *Result,
+  AllOf(WithName("S"), WithKind(SymbolKind::Struct),
+Parents(AllOf(WithName("S"), WithKind(SymbolKind::Struct),
+  SelectionRangeIs(Source.range("SDef")), Parents();
 }
 
 } // namespace
Index: clang-tools-extra/trunk/clangd/XRefs.cpp
===
--- clang-tools-extra/trunk/clangd/XRefs.cpp
+++ clang-tools-extra/trunk/clangd/XRefs.cpp
@@ -876,21 +876,40 @@
   return THI;
 }
 
-static Optional getTypeAncestors(const CXXRecordDecl ,
-ASTContext ) {
+using RecursionProtectionSet = 

[clang-tools-extra] r358866 - [clangd] Support dependent bases in type hierarchy

2019-04-21 Thread Fangrui Song via cfe-commits
Author: maskray
Date: Sun Apr 21 18:38:53 2019
New Revision: 358866

URL: http://llvm.org/viewvc/llvm-project?rev=358866=rev
Log:
[clangd] Support dependent bases in type hierarchy

Patch by Nathan Ridge!

Dependent bases are handled heuristically, by replacing them with the
class template that they are a specialization of, where possible. Care
is taken to avoid infinite recursion.

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

Modified:
clang-tools-extra/trunk/clangd/XRefs.cpp
clang-tools-extra/trunk/unittests/clangd/TypeHierarchyTests.cpp

Modified: clang-tools-extra/trunk/clangd/XRefs.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clangd/XRefs.cpp?rev=358866=358865=358866=diff
==
--- clang-tools-extra/trunk/clangd/XRefs.cpp (original)
+++ clang-tools-extra/trunk/clangd/XRefs.cpp Sun Apr 21 18:38:53 2019
@@ -876,21 +876,40 @@ declToTypeHierarchyItem(ASTContext ,
   return THI;
 }
 
-static Optional getTypeAncestors(const CXXRecordDecl ,
-ASTContext ) {
+using RecursionProtectionSet = llvm::SmallSet;
+
+static Optional
+getTypeAncestors(const CXXRecordDecl , ASTContext ,
+ RecursionProtectionSet ) {
   Optional Result = declToTypeHierarchyItem(ASTCtx, CXXRD);
   if (!Result)
 return Result;
 
   Result->parents.emplace();
 
+  // typeParents() will replace dependent template specializations
+  // with their class template, so to avoid infinite recursion for
+  // certain types of hierarchies, keep the templates encountered
+  // along the parent chain in a set, and stop the recursion if one
+  // starts to repeat.
+  auto *Pattern = CXXRD.getDescribedTemplate() ?  : nullptr;
+  if (Pattern) {
+if (!RPSet.insert(Pattern).second) {
+  return Result;
+}
+  }
+
   for (const CXXRecordDecl *ParentDecl : typeParents()) {
 if (Optional ParentSym =
-getTypeAncestors(*ParentDecl, ASTCtx)) {
+getTypeAncestors(*ParentDecl, ASTCtx, RPSet)) {
   Result->parents->emplace_back(std::move(*ParentSym));
 }
   }
 
+  if (Pattern) {
+RPSet.erase(Pattern);
+  }
+
   return Result;
 }
 
@@ -933,10 +952,17 @@ std::vector typeP
   ParentDecl = RT->getAsCXXRecordDecl();
 }
 
-// For now, do not handle dependent bases such as "Base".
-// We would like to handle them by heuristically choosing the
-// primary template declaration, but we need to take care to
-// avoid infinite recursion.
+if (!ParentDecl) {
+  // Handle a dependent base such as "Base" by using the primary
+  // template.
+  if (const TemplateSpecializationType *TS =
+  Type->getAs()) {
+TemplateName TN = TS->getTemplateName();
+if (TemplateDecl *TD = TN.getAsTemplateDecl()) {
+  ParentDecl = dyn_cast(TD->getTemplatedDecl());
+}
+  }
+}
 
 if (ParentDecl)
   Result.push_back(ParentDecl);
@@ -952,10 +978,13 @@ getTypeHierarchy(ParsedAST , Positio
   if (!CXXRD)
 return llvm::None;
 
+  RecursionProtectionSet RPSet;
   Optional Result =
-  getTypeAncestors(*CXXRD, AST.getASTContext());
+  getTypeAncestors(*CXXRD, AST.getASTContext(), RPSet);
+
   // FIXME(nridge): Resolve type descendants if direction is Children or Both,
   // and ResolveLevels > 0.
+
   return Result;
 }
 

Modified: clang-tools-extra/trunk/unittests/clangd/TypeHierarchyTests.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clangd/TypeHierarchyTests.cpp?rev=358866=358865=358866=diff
==
--- clang-tools-extra/trunk/unittests/clangd/TypeHierarchyTests.cpp (original)
+++ clang-tools-extra/trunk/unittests/clangd/TypeHierarchyTests.cpp Sun Apr 21 
18:38:53 2019
@@ -291,9 +291,7 @@ struct Child : Parent {};
   EXPECT_THAT(typeParents(ChildSpec), ElementsAre(Parent));
 }
 
-// This is disabled for now, because support for dependent bases
-// requires additional measures to avoid infinite recursion.
-TEST(DISABLED_TypeParents, DependentBase) {
+TEST(TypeParents, DependentBase) {
   Annotations Source(R"cpp(
 template 
 struct Parent {};
@@ -383,10 +381,10 @@ int main() {
   }
 }
 
-TEST(TypeHierarchy, RecursiveHierarchy1) {
+TEST(TypeHierarchy, RecursiveHierarchyUnbounded) {
   Annotations Source(R"cpp(
   template 
-  struct S : S {};
+  struct $SDef[[S]] : S {};
 
   S^<0> s;
   )cpp");
@@ -399,62 +397,57 @@ TEST(TypeHierarchy, RecursiveHierarchy1)
   ASSERT_TRUE(!AST.getDiagnostics().empty());
 
   // Make sure getTypeHierarchy() doesn't get into an infinite recursion.
+  // FIXME(nridge): It would be preferable if the type hierarchy gave us type
+  // names (e.g. "S<0>" for the child and "S<1>" for the parent) rather than
+  // template names (e.g. "S").
   llvm::Optional Result = getTypeHierarchy(
   AST, Source.points()[0], 0, 

[PATCH] D60943: Delay diagnosing "n" constraint until after inlining

2019-04-21 Thread Bill Wendling via Phabricator via cfe-commits
void added a comment.

This relies upon D60943 .


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60943/new/

https://reviews.llvm.org/D60943



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


[PATCH] D60570: [Sema] Add more tests for the behavior of argument-dependent name lookup

2019-04-21 Thread Bruno Ricci via Phabricator via cfe-commits
riccibruno accepted this revision.
riccibruno added a comment.
This revision is now accepted and ready to land.

In D60570#1473873 , @Quuxplusone wrote:

> > @Quuxplusone Do you have other objections apart from the template-id issue 
> > ? If not, since D60573  depends on this 
> > patch, I would like to commit this with a comment explaining the issue 
> > instead of the FIXME.
>
> Sure, go for it!


Thanks a lot for your insightful comments and for your time, I really 
appreciate it!


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60570/new/

https://reviews.llvm.org/D60570



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


[PATCH] D60570: [Sema] Add more tests for the behavior of argument-dependent name lookup

2019-04-21 Thread Arthur O'Dwyer via Phabricator via cfe-commits
Quuxplusone added a comment.

> @Quuxplusone Do you have other objections apart from the template-id issue ? 
> If not, since D60573  depends on this patch, 
> I would like to commit this with a comment explaining the issue instead of 
> the FIXME.

Sure, go for it!


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60570/new/

https://reviews.llvm.org/D60570



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


[PATCH] D60523: [clang] Don't segfault on incorrect using directive (PR41400)

2019-04-21 Thread Bruno Ricci via Phabricator via cfe-commits
riccibruno added a reviewer: riccibruno.
riccibruno added a comment.

I will take a look at this tomorrow, I know that it is annoying to get no 
feedback!


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60523/new/

https://reviews.llvm.org/D60523



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


[PATCH] D60570: [Sema] Add more tests for the behavior of argument-dependent name lookup

2019-04-21 Thread Bruno Ricci via Phabricator via cfe-commits
riccibruno added a comment.

@Quuxplusone Do you have other objections apart from the template-id issue ? If 
not, since D60573  depends on this patch, I 
would like to commit this with a comment explaining the issue instead of the 
FIXME.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60570/new/

https://reviews.llvm.org/D60570



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


[PATCH] D60954: [clangd] Test case demonstrating variable template issue

2019-04-21 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added a comment.

Please see further details in this clangd-dev post 
.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60954/new/

https://reviews.llvm.org/D60954



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


[PATCH] D60956: [Sema] Fix the lookup for a declaration conflicting with an enumerator (bogus use of LookupResult::getAsSingle)

2019-04-21 Thread Bruno Ricci via Phabricator via cfe-commits
riccibruno created this revision.
riccibruno added reviewers: aaron.ballman, rnk, rsmith.
riccibruno added a project: clang.
Herald added a subscriber: cfe-commits.

Currently the lookup for a declaration conflicting with an enumerator is pretty 
broken, because of the use of `LookupResult::getAsSingle()` (see the 
tests for examples).

This patch fixes this by removing the bogus use of `getAsSingle()`. 
While we are at it, also do the check for a conflicting declaration before 
calling `CheckShadow` (which implements `Wshadow`). This avoids redundant 
`Wshadow` warnings where we already have an error.

This is not the only place where `getAsSingle` is mistakenly used, but this is 
better addressed in a later patch.


Repository:
  rC Clang

https://reviews.llvm.org/D60956

Files:
  lib/Sema/SemaDecl.cpp
  test/CXX/dcl.dcl/dcl.enum/p11-enumerator_scope.cpp

Index: test/CXX/dcl.dcl/dcl.enum/p11-enumerator_scope.cpp
===
--- test/CXX/dcl.dcl/dcl.enum/p11-enumerator_scope.cpp
+++ test/CXX/dcl.dcl/dcl.enum/p11-enumerator_scope.cpp
@@ -6,37 +6,30 @@
 // enumerator is declared in the scope of the enumeration. These names obey
 // the scope rules defined for all names in 6.3 and 6.4.
 
-// FIXME: Actually implement the redeclaration lookup properly.
 // FIXME: Improve the wording of the error messages (definition vs declaration).
-// FIXME: Only emit the Wshadow warning when the declaration of the
-//enumerator does not conflict with another declaration.
 
-// We also test for -Wshadow since the functionality is closely related,
-// and we don't want to mess up Wshadow by fixing the redeclaration lookup.
+// We also test for -Wshadow since the functionality is closely related.
 
 // Conflict with another declaration at class scope.
 struct S_function {
   void f(); // expected-note 2{{previous definition}}
-// FIXME: Don't emit shadow-note@-1 2{{previous declaration}}
   enum { f };   // expected-error {{redefinition of 'f'}}
-// FIXME: Don't emit shadow-warning@-1 {{declaration shadows}}
   enum E1 { f };// expected-error {{redefinition of 'f'}}
-// FIXME: Don't emit shadow-warning@-1 {{declaration shadows}}
   enum class E2 { f };  // ok
 };
 
 struct S_overloaded_function {
   void f();
-  void f(int);
-  enum { f };   // FIXME: Reject.
-  enum E1 { f };// FIXME: Reject.
+  void f(int);  // expected-note 2{{previous definition}}
+  enum { f };   // expected-error {{redefinition of 'f'}}
+  enum E1 { f };// expected-error {{redefinition of 'f'}}
   enum class E2 { f };  // ok
 };
 
 struct S_function_template {
-  template  void f();
-  enum { f };  // FIXME: Reject.
-  enum E1 { f };   // FIXME: Reject.
+  template  void f(); // expected-note 2{{previous definition}}
+  enum { f };  // expected-error {{redefinition of 'f'}}
+  enum E1 { f };   // expected-error {{redefinition of 'f'}}
   enum class E2 { f }; // ok
 };
 
@@ -52,12 +45,9 @@
 struct S_data_member {
   struct f;
   int f;  // expected-note {{previous definition}}
-  // FIXME: Don't emit shadow-note@-1 {{previous declaration}}
   static int g;   // expected-note {{previous definition}}
-  // FIXME: Don't emit shadow-note@-1 {{previous declaration}}
   enum { f, g };  // expected-error {{redefinition of 'f'}}
   // expected-error@-1 {{redefinition of 'g'}}
-  // FIXME: Don't emit shadow-warning@-2 2{{declaration shadows}}
 };
 
 namespace S_out_of_line_definition {
@@ -78,14 +68,13 @@
 namespace S_using_decl {
 
 struct Base {
-  int f; // FIXME: Don't emit shadow-note {{previous declaration}}
+  int f;
   int g;
 };
 struct OtherBase {};
 struct Der : Base, OtherBase {
-  using Base::f;
-  enum { f }; // FIXME: Reject.
-  // FIXME: Don't emit shadow-warning@-1 {{declaration shadows}}
+  using Base::f; // expected-note {{previous definition}}
+  enum { f }; // expected-error {{redefinition of 'f'}}
   enum { g }; // ok
 
   using OtherBase::OtherBase;
@@ -103,8 +92,8 @@
 };
 
 template  struct Der : Base {
-  using Base::t;
-  enum { t }; // FIXME: Reject.
+  using Base::t; // expected-note {{previous definition}}
+  enum { t };   // expected-error {{redefinition of 't'}}
   // [namespace.udecl]p20:
   //   If a using-declarator uses the keyword typename and specifies a
   //   dependent name (17.6.2), the name introduced by the using-declaration
@@ -122,32 +111,27 @@
 // Conflict with another declaration at namespace scope
 namespace N_function {
   void f(); // expected-note 2{{previous definition}}
-// FIXME: Don't emit shadow-note@-1 2{{previous declaration}}
   enum { f };   // expected-error {{redefinition of 'f'}}
-// FIXME: Don't emit shadow-warning@-1 

[PATCH] D60954: [clangd] Test case demonstrating variable template issue

2019-04-21 Thread Nathan Ridge via Phabricator via cfe-commits
nridge created this revision.
Herald added subscribers: cfe-commits, kadircet, arphaman, jkorous, MaskRay, 
ioeric, ilya-biryukov.
Herald added a project: clang.

This is not meant to be committed, it's meant to demonstrate an
issue with using RecursiveASTVisitor with TestTU on code that contains a
top-level variable template.

The variable template declaration is never visited, for reasons I don't
fully understand.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D60954

Files:
  clang-tools-extra/unittests/clangd/TestTU.cpp


Index: clang-tools-extra/unittests/clangd/TestTU.cpp
===
--- clang-tools-extra/unittests/clangd/TestTU.cpp
+++ clang-tools-extra/unittests/clangd/TestTU.cpp
@@ -141,5 +141,24 @@
   });
 }
 
+class TestVisitor : public RecursiveASTVisitor {
+public:
+  bool VisitVarTemplateDecl(VarTemplateDecl *VTD) {
+seenVarTemplateDecl = true;
+return true;
+  }
+
+  bool seenVarTemplateDecl = false;
+};
+
+TEST(TestTU, VariableTemplate) {
+  TestTU TU = TestTU::withCode("template  int x;");
+  auto AST = TU.build();
+  EXPECT_TRUE(AST.getDiagnostics().empty());
+  TestVisitor Visitor;
+  Visitor.TraverseAST(AST.getASTContext());
+  EXPECT_TRUE(Visitor.seenVarTemplateDecl);
+}
+
 } // namespace clangd
 } // namespace clang


Index: clang-tools-extra/unittests/clangd/TestTU.cpp
===
--- clang-tools-extra/unittests/clangd/TestTU.cpp
+++ clang-tools-extra/unittests/clangd/TestTU.cpp
@@ -141,5 +141,24 @@
   });
 }
 
+class TestVisitor : public RecursiveASTVisitor {
+public:
+  bool VisitVarTemplateDecl(VarTemplateDecl *VTD) {
+seenVarTemplateDecl = true;
+return true;
+  }
+
+  bool seenVarTemplateDecl = false;
+};
+
+TEST(TestTU, VariableTemplate) {
+  TestTU TU = TestTU::withCode("template  int x;");
+  auto AST = TU.build();
+  EXPECT_TRUE(AST.getDiagnostics().empty());
+  TestVisitor Visitor;
+  Visitor.TraverseAST(AST.getASTContext());
+  EXPECT_TRUE(Visitor.seenVarTemplateDecl);
+}
+
 } // namespace clangd
 } // namespace clang
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D59407: [clangd] Add RelationSlab

2019-04-21 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added a comment.

Hi, any update here? I would appreciate some guidance so I can move forward 
with this.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D59407/new/

https://reviews.llvm.org/D59407



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


[PATCH] D59756: [clangd] Support dependent bases in type hierarchy

2019-04-21 Thread Nathan Ridge via Phabricator via cfe-commits
nridge added a comment.

Ping - could this be committed please?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D59756/new/

https://reviews.llvm.org/D59756



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


[PATCH] D60953: [clangd] Respect clang-tidy suppression comments

2019-04-21 Thread Nathan Ridge via Phabricator via cfe-commits
nridge created this revision.
nridge added a reviewer: hokein.
Herald added subscribers: cfe-commits, kadircet, arphaman, jkorous, MaskRay, 
ioeric.
Herald added a project: clang.

This partially fixes https://bugs.llvm.org/show_bug.cgi?id=41218.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D60953

Files:
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
  clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
  clang-tools-extra/clangd/ClangdUnit.cpp

Index: clang-tools-extra/clangd/ClangdUnit.cpp
===
--- clang-tools-extra/clangd/ClangdUnit.cpp
+++ clang-tools-extra/clangd/ClangdUnit.cpp
@@ -237,6 +237,39 @@
   const LangOptions 
 };
 
+// A wrapper around StoreDiags to handle suppression comments for
+// clang-tidy diagnostics (and possibly other clang-tidy customizations in the
+// future).
+class ClangdDiagnosticConsumer : public StoreDiags {
+public:
+  void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel,
+const clang::Diagnostic ) override {
+if (LastErrorWasIgnored && DiagLevel == DiagnosticsEngine::Note)
+  return;
+
+if (CTContext) {
+  bool isClangTidyDiag = !CTContext->getCheckName(Info.getID()).empty();
+  if (isClangTidyDiag &&
+  tidy::ShouldSuppressDiagnostic(DiagLevel, Info, *CTContext)) {
+// Ignored a warning, should ignore related notes as well
+LastErrorWasIgnored = true;
+return;
+  }
+}
+
+LastErrorWasIgnored = false;
+StoreDiags::HandleDiagnostic(DiagLevel, Info);
+  }
+
+  void setClangTidyContext(tidy::ClangTidyContext *CTContext) {
+this->CTContext = CTContext;
+  }
+
+private:
+  bool LastErrorWasIgnored = false;
+  tidy::ClangTidyContext *CTContext = nullptr;
+};
+
 } // namespace
 
 void dumpAST(ParsedAST , llvm::raw_ostream ) {
@@ -256,7 +289,7 @@
   const PrecompiledPreamble *PreamblePCH =
   Preamble ? >Preamble : nullptr;
 
-  StoreDiags ASTDiags;
+  ClangdDiagnosticConsumer ASTDiags;
   std::string Content = Buffer->getBuffer();
 
   auto Clang = prepareCompilerInstance(std::move(CI), PreamblePCH,
@@ -294,6 +327,7 @@
 CTContext->setASTContext(>getASTContext());
 CTContext->setCurrentFile(MainInput.getFile());
 CTFactories.createChecks(CTContext.getPointer(), CTChecks);
+ASTDiags.setClangTidyContext(CTContext.getPointer());
 Preprocessor *PP = >getPreprocessor();
 for (const auto  : CTChecks) {
   // FIXME: the PP callbacks skip the entire preamble.
Index: clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
===
--- clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
+++ clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.h
@@ -217,6 +217,17 @@
   bool AllowEnablingAnalyzerAlphaCheckers;
 };
 
+/// Check whether a given diagnostic should be suppressed due to the presence
+/// of a "NOLINT" suppression comment.
+/// This is exposed so that other tools that present clang-tidy diagnostics
+/// (such as clangd) can respect the same suppression rules as clang-tidy.
+/// This does not handle suppression of notes following a suppressed diagnostic;
+/// that is left to the caller is it requires maintaining state in between calls
+/// to this function.
+bool ShouldSuppressDiagnostic(DiagnosticsEngine::Level DiagLevel,
+  const Diagnostic ,
+  ClangTidyContext );
+
 /// \brief A diagnostic consumer that turns each \c Diagnostic into a
 /// \c SourceManager-independent \c ClangTidyError.
 //
@@ -246,7 +257,7 @@
 
   /// \brief Updates \c LastErrorRelatesToUserCode and LastErrorPassesLineFilter
   /// according to the diagnostic \p Location.
-  void checkFilters(SourceLocation Location, const SourceManager& Sources);
+  void checkFilters(SourceLocation Location, const SourceManager );
   bool passesLineFilter(StringRef FileName, unsigned LineNumber) const;
 
   ClangTidyContext 
Index: clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
===
--- clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
+++ clang-tools-extra/clang-tidy/ClangTidyDiagnosticConsumer.cpp
@@ -160,11 +160,13 @@
 
   bool contains(StringRef S) {
 switch (auto  = Cache[S]) {
-  case Yes: return true;
-  case No: return false;
-  case None:
-Result = Globs.contains(S) ? Yes : No;
-return Result == Yes;
+case Yes:
+  return true;
+case No:
+  return false;
+case None:
+  Result = Globs.contains(S) ? Yes : No;
+  return Result == Yes;
 }
 llvm_unreachable("invalid enum");
   }
@@ -381,16 +383,29 @@
   return false;
 }
 
+namespace clang {
+namespace tidy {
+
+bool ShouldSuppressDiagnostic(DiagnosticsEngine::Level DiagLevel,
+  const Diagnostic ,
+  

[PATCH] D59754: [Sema] Add c++2a designated initializer warnings

2019-04-21 Thread Don Hinton via Phabricator via cfe-commits
hintonda marked an inline comment as done.
hintonda added inline comments.



Comment at: clang/lib/Sema/SemaInit.cpp:2069-2072
+if (!VerifyOnly && HasDesignatedInit && SemaRef.getLangOpts().CPlusPlus2a) 
{
+  SemaRef.Diag(Init->getBeginLoc(), diag::ext_c20_designated_init)
+  << "mixed" << Init->getSourceRange();
+}

rsmith wrote:
> I think it would be preferable to diagnose the "mixed" case in the parser 
> rather than here (it's a grammatical restriction in C++, after all). I'm 
> worried that handling it here will get some cases wrong, such as perhaps:
> 
> ```
> struct A {
>   union { int x, y; };
>   int z;
> };
> A a = { .x = 123, 456 }; // should be rejected, but I think this patch might 
> accept
> ```
> 
> ... and it might also get template instantiation cases wrong for a case like:
> 
> ```
> struct Q { Q(); };
> struct A { Q x, y; };
> template void f() {
>   A a = {.y = Q()};
> }
> void g() { f(); }
> ```
> 
> ... where we might possibly end up passing an `InitListExpr` representing 
> `{Q(), .y = Q()}` into `InitListChecker`.
> 
> I think the only C++20 restriction that it makes sense to check in 
> `InitListChecker` is that the field names are in the right order; everything 
> else should be checked earlier. This would also match the semantics of 
> overload resolution, for which the "fields are in the right order" check is 
> deferred until after a function is selected, whereas all the other checks are 
> performed eagerly.
Will work on moving these to the parser.

Btw, the first one is diagnosed correctly, but doesn't complain about the 
second.  Not sure I grok the problem there either since Q has a default ctor.



Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D59754/new/

https://reviews.llvm.org/D59754



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


Re: r358665 - [clang][CIndex] Use llvm::set_thread_priority

2019-04-21 Thread Nico Weber via cfe-commits
r358858 might help with this.

On Sat, Apr 20, 2019 at 7:15 PM Nico Weber  wrote:

> This breaks building with LLVM_ENABLE_THREADS=OFF. The call probably needs
> to be behind a `#if LLVM_ENABLE_THREADS`.
>
> FAILED: bin/c-index-test
> ...
> lib/libclang.a(CIndex.cpp.o): In function `void llvm::function_ref ()>::callback_fn(long)':
> CIndex.cpp:(.text._ZN4llvm12function_refIFvvEE11callback_fnIZ25clang_saveTranslationUnitEUlvE_EEvl+0x5a):
> undefined reference to `llvm::set_thread_priority(llvm::ThreadPriority)'
> lib/libclang.a(CIndex.cpp.o): In function
> `clang::setThreadBackgroundPriority()':
> CIndex.cpp:(.text._ZN5clang27setThreadBackgroundPriorityEv+0x27):
> undefined reference to `llvm::set_thread_priority(llvm::ThreadPriority)'
> lib/libclang.a(CIndex.cpp.o): In function `clang_saveTranslationUnit':
> CIndex.cpp:(.text.clang_saveTranslationUnit+0x316): undefined reference to
> `llvm::set_thread_priority(llvm::ThreadPriority)'
>
>
> On Thu, Apr 18, 2019 at 9:47 AM Kadir Cetinkaya via cfe-commits <
> cfe-commits@lists.llvm.org> wrote:
>
>> Author: kadircet
>> Date: Thu Apr 18 06:49:20 2019
>> New Revision: 358665
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=358665=rev
>> Log:
>> [clang][CIndex] Use llvm::set_thread_priority
>>
>> Reviewers: jkorous, gribozavr
>>
>> Subscribers: dexonsmith, arphaman, cfe-commits
>>
>> Tags: #clang
>>
>> Differential Revision: https://reviews.llvm.org/D60867
>>
>> Modified:
>> cfe/trunk/tools/libclang/CIndex.cpp
>>
>> Modified: cfe/trunk/tools/libclang/CIndex.cpp
>> URL:
>> http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=358665=358664=358665=diff
>>
>> ==
>> --- cfe/trunk/tools/libclang/CIndex.cpp (original)
>> +++ cfe/trunk/tools/libclang/CIndex.cpp Thu Apr 18 06:49:20 2019
>> @@ -8723,9 +8723,7 @@ void clang::setThreadBackgroundPriority(
>>if (getenv("LIBCLANG_BGPRIO_DISABLE"))
>>  return;
>>
>> -#ifdef USE_DARWIN_THREADS
>> -  setpriority(PRIO_DARWIN_THREAD, 0, PRIO_DARWIN_BG);
>> -#endif
>> +  llvm::set_thread_priority(llvm::ThreadPriority::Background);
>>  }
>>
>>  void cxindex::printDiagsToStderr(ASTUnit *Unit) {
>>
>>
>> ___
>> cfe-commits mailing list
>> cfe-commits@lists.llvm.org
>> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
>>
>
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r358858 - Attempt to fix LLVM_ENABLE_THREADS=OFF build after r358665

2019-04-21 Thread Nico Weber via cfe-commits
Author: nico
Date: Sun Apr 21 12:18:41 2019
New Revision: 358858

URL: http://llvm.org/viewvc/llvm-project?rev=358858=rev
Log:
Attempt to fix LLVM_ENABLE_THREADS=OFF build after r358665

Modified:
cfe/trunk/tools/libclang/CIndex.cpp

Modified: cfe/trunk/tools/libclang/CIndex.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=358858=358857=358858=diff
==
--- cfe/trunk/tools/libclang/CIndex.cpp (original)
+++ cfe/trunk/tools/libclang/CIndex.cpp Sun Apr 21 12:18:41 2019
@@ -8723,7 +8723,9 @@ void clang::setThreadBackgroundPriority(
   if (getenv("LIBCLANG_BGPRIO_DISABLE"))
 return;
 
+#if LLVM_ENABLE_THREADS
   llvm::set_thread_priority(llvm::ThreadPriority::Background);
+#endif
 }
 
 void cxindex::printDiagsToStderr(ASTUnit *Unit) {


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


[PATCH] D59711: PR41183: Don't emit Wstrict-prototypes warning for an implicit function declaration.

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

LGTM


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D59711/new/

https://reviews.llvm.org/D59711



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


[PATCH] D60629: [clang-tidy] Change the namespace for llvm checkers from 'llvm' to 'llvm_check'

2019-04-21 Thread Don Hinton via Phabricator via cfe-commits
hintonda updated this revision to Diff 196011.
hintonda added a comment.

- Address comments.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60629/new/

https://reviews.llvm.org/D60629

Files:
  clang-tools-extra/clang-tidy/add_new_check.py
  clang-tools-extra/clang-tidy/llvm/HeaderGuardCheck.cpp
  clang-tools-extra/clang-tidy/llvm/HeaderGuardCheck.h
  clang-tools-extra/clang-tidy/llvm/IncludeOrderCheck.cpp
  clang-tools-extra/clang-tidy/llvm/IncludeOrderCheck.h
  clang-tools-extra/clang-tidy/llvm/LLVMTidyModule.cpp
  clang-tools-extra/clang-tidy/llvm/TwineLocalCheck.cpp
  clang-tools-extra/clang-tidy/llvm/TwineLocalCheck.h
  clang-tools-extra/clang-tidy/rename_check.py
  clang-tools-extra/unittests/clang-tidy/LLVMModuleTest.cpp

Index: clang-tools-extra/unittests/clang-tidy/LLVMModuleTest.cpp
===
--- clang-tools-extra/unittests/clang-tidy/LLVMModuleTest.cpp
+++ clang-tools-extra/unittests/clang-tidy/LLVMModuleTest.cpp
@@ -3,7 +3,7 @@
 #include "llvm/IncludeOrderCheck.h"
 #include "gtest/gtest.h"
 
-using namespace clang::tidy::llvm;
+using namespace clang::tidy::llvm_check;
 
 namespace clang {
 namespace tidy {
Index: clang-tools-extra/clang-tidy/rename_check.py
===
--- clang-tools-extra/clang-tidy/rename_check.py
+++ clang-tools-extra/clang-tidy/rename_check.py
@@ -14,6 +14,18 @@
 import re
 
 
+def replaceInFileRegex(fileName, sFrom, sTo):
+  if sFrom == sTo:
+return
+  txt = None
+  with open(fileName, "r") as f:
+txt = f.read()
+
+  txt = re.sub(sFrom, sTo, txt)
+  print("Replacing '%s' -> '%s' in '%s'..." % (sFrom, sTo, fileName))
+  with open(fileName, "w") as f:
+f.write(txt)
+
 def replaceInFile(fileName, sFrom, sTo):
   if sFrom == sTo:
 return
@@ -203,6 +215,8 @@
   clang_tidy_path = os.path.dirname(__file__)
 
   header_guard_variants = [
+  (args.old_check_name.replace('-', '_')).upper() + '_CHECK',
+  (old_module + '_' + check_name_camel).upper(),
   (old_module + '_' + new_check_name_camel).upper(),
   args.old_check_name.replace('-', '_').upper()]
   header_guard_new = (new_module + '_' + new_check_name_camel).upper()
@@ -210,18 +224,19 @@
   old_module_path = os.path.join(clang_tidy_path, old_module)
   new_module_path = os.path.join(clang_tidy_path, new_module)
 
-  # Remove the check from the old module.
-  cmake_lists = os.path.join(old_module_path, 'CMakeLists.txt')
-  check_found = deleteMatchingLines(cmake_lists, '\\b' + check_name_camel)
-  if not check_found:
-print("Check name '%s' not found in %s. Exiting." %
+  if (args.old_check_name != args.new_check_name):
+# Remove the check from the old module.
+cmake_lists = os.path.join(old_module_path, 'CMakeLists.txt')
+check_found = deleteMatchingLines(cmake_lists, '\\b' + check_name_camel)
+if not check_found:
+  print("Check name '%s' not found in %s. Exiting." %
 (check_name_camel, cmake_lists))
-return 1
+  return 1
 
-  modulecpp = filter(
-  lambda p: p.lower() == old_module.lower() + 'tidymodule.cpp',
-  os.listdir(old_module_path))[0]
-  deleteMatchingLines(os.path.join(old_module_path, modulecpp),
+modulecpp = filter(
+lambda p: p.lower() == old_module.lower() + 'tidymodule.cpp',
+os.listdir(old_module_path))[0]
+deleteMatchingLines(os.path.join(old_module_path, modulecpp),
   '\\b' + check_name_camel + '|\\b' + args.old_check_name)
 
   for filename in getListOfFiles(clang_tidy_path):
@@ -249,14 +264,21 @@
   new_module + '/' + new_check_name_camel)
 replaceInFile(filename, check_name_camel, new_check_name_camel)
 
-  if old_module != new_module:
+  if new_module == 'llvm':
+new_namespace = new_module + '_check'
+  else:
+new_namespace = new_module
+  if old_module != new_module or new_namespace == 'llvm_check':
 check_implementation_files = glob.glob(
 os.path.join(old_module_path, new_check_name_camel + '*'))
 for filename in check_implementation_files:
   # Move check implementation to the directory of the new module.
   filename = fileRename(filename, old_module_path, new_module_path)
-  replaceInFile(filename, 'namespace ' + old_module,
-'namespace ' + new_module)
+  replaceInFileRegex(filename, 'namespace ' + old_module + '[^ \n]*',
+ 'namespace ' + new_namespace)
+
+  if (args.old_check_name == args.new_check_name):
+return
 
   # Add check to the new module.
   adapt_cmake(new_module_path, new_check_name_camel)
Index: clang-tools-extra/clang-tidy/llvm/TwineLocalCheck.h
===
--- clang-tools-extra/clang-tidy/llvm/TwineLocalCheck.h
+++ clang-tools-extra/clang-tidy/llvm/TwineLocalCheck.h
@@ -6,14 +6,14 @@
 //
 

[PATCH] D50360: [Concepts] Requires Expressions

2019-04-21 Thread Bruno Ricci via Phabricator via cfe-commits
riccibruno added inline comments.



Comment at: include/clang/AST/ExprCXX.h:4671
+  bool IsSatisfied;
+  SourceLocation RequiresKWLoc;
+  RequiresExprBodyDecl *Body;

You can stash these in the bit-field classes of `Stmt` to save some space.



Comment at: include/clang/AST/ExprCXX.h:4674
+  llvm::SmallVector LocalParameters;
+  llvm::SmallVector Requirements;
+  SourceLocation RBraceLoc;

Can you tail-allocate them ?



Comment at: include/clang/AST/ExprCXX.h:4703
+  }
+
+  SourceLocation getRequiresKWLoc() const { return RequiresKWLoc; }

If in general you don't strictly need to modify some internal state of an AST 
node, I think it would be better to not provide the corresponding method.



Comment at: include/clang/AST/ExprCXX.h:4715
+  SourceLocation getBeginLoc() const LLVM_READONLY { return RequiresKWLoc; }
+  SourceLocation getEndLoc() const LLVM_READONLY {
+return RBraceLoc;

`LLVM_READONLY` is pointless here.



Comment at: include/clang/AST/ExprCXX.h:4722
+return child_range(child_iterator(), child_iterator());
+  }
+};

You should also provide the const-qualified version.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D50360/new/

https://reviews.llvm.org/D50360



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


[PATCH] D40381: Parse concept definition

2019-04-21 Thread Saar Raz via Phabricator via cfe-commits
saar.raz updated this revision to Diff 196009.
saar.raz added a comment.
Herald added a reviewer: martong.

Address CR comments by rsmith


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D40381/new/

https://reviews.llvm.org/D40381

Files:
  include/clang/AST/ASTNodeTraverser.h
  include/clang/AST/DeclTemplate.h
  include/clang/AST/RecursiveASTVisitor.h
  include/clang/AST/TextNodeDumper.h
  include/clang/Basic/DeclNodes.td
  include/clang/Basic/DiagnosticParseKinds.td
  include/clang/Basic/DiagnosticSemaKinds.td
  include/clang/Basic/TemplateKinds.h
  include/clang/Parse/Parser.h
  include/clang/Sema/Sema.h
  include/clang/Serialization/ASTBitCodes.h
  lib/AST/ASTStructuralEquivalence.cpp
  lib/AST/DeclBase.cpp
  lib/AST/DeclPrinter.cpp
  lib/AST/DeclTemplate.cpp
  lib/AST/TextNodeDumper.cpp
  lib/CodeGen/CGDecl.cpp
  lib/CodeGen/CodeGenModule.cpp
  lib/Index/IndexDecl.cpp
  lib/Parse/ParseTemplate.cpp
  lib/Sema/SemaDecl.cpp
  lib/Sema/SemaDeclCXX.cpp
  lib/Sema/SemaLookup.cpp
  lib/Sema/SemaTemplate.cpp
  lib/Sema/SemaTemplateInstantiateDecl.cpp
  lib/Serialization/ASTCommon.cpp
  lib/Serialization/ASTReaderDecl.cpp
  lib/Serialization/ASTWriter.cpp
  lib/Serialization/ASTWriterDecl.cpp
  test/CXX/concepts-ts/expr/expr.prim/expr.prim.id/p3.cpp
  test/Parser/cxx-concept-declaration.cpp
  test/Parser/cxx-concepts-ambig-constraint-expr.cpp
  test/Parser/cxx-concepts-requires-clause.cpp
  test/Parser/cxx2a-concept-declaration.cpp
  test/Parser/cxx2a-concepts-ambig-constraint-expr.cpp
  test/Parser/cxx2a-concepts-requires-clause.cpp
  tools/libclang/CIndex.cpp

Index: tools/libclang/CIndex.cpp
===
--- tools/libclang/CIndex.cpp
+++ tools/libclang/CIndex.cpp
@@ -6252,6 +6252,7 @@
   case Decl::PragmaComment:
   case Decl::PragmaDetectMismatch:
   case Decl::UsingPack:
+  case Decl::Concept:
 return C;
 
   // Declaration kinds that don't make any sense here, but are
Index: test/Parser/cxx-concepts-requires-clause.cpp
===
--- /dev/null
+++ test/Parser/cxx-concepts-requires-clause.cpp
@@ -1,82 +0,0 @@
-// RUN: %clang_cc1 -std=c++14 -fconcepts-ts -x c++ %s -verify
-// expected-no-diagnostics
-
-// Test parsing of the optional requires-clause in a template-declaration.
-
-template  requires true
-void foo() { }
-
-
-template  requires !0
-struct A {
-  void foo();
-  struct AA;
-  enum E : int;
-  static int x;
-
-  template  requires true
-  void Mfoo();
-
-  template  requires true
-  struct M;
-
-  template  requires true
-  static int Mx;
-
-  template  requires true
-  using MQ = M;
-};
-
-template  requires !0
-void A::foo() { }
-
-template  requires !0
-struct A::AA { };
-
-template  requires !0
-enum A::E : int { E0 };
-
-template  requires !0
-int A::x = 0;
-
-template  requires !0
-template  requires true
-void A::Mfoo() { }
-
-template  requires !0
-template  requires true
-struct A::M { };
-
-template  requires !0
-template  requires true
-int A::Mx = 0;
-
-
-template  requires true
-int x = 0;
-
-template  requires true
-using Q = A;
-
-struct C {
-  template  requires true
-  void Mfoo();
-
-  template  requires true
-  struct M;
-
-  template  requires true
-  static int Mx;
-
-  template  requires true
-  using MQ = M;
-};
-
-template  requires true
-void C::Mfoo() { }
-
-template  requires true
-struct C::M { };
-
-template  requires true
-int C::Mx = 0;
Index: test/Parser/cxx-concepts-ambig-constraint-expr.cpp
===
--- /dev/null
+++ test/Parser/cxx-concepts-ambig-constraint-expr.cpp
@@ -1,29 +0,0 @@
-// RUN: %clang_cc1 -std=c++14 -fconcepts-ts -x c++ %s -verify
-
-// Test parsing of constraint-expressions in cases where the grammar is
-// ambiguous with the expectation that the longest token sequence which matches
-// the syntax is consumed without backtracking.
-
-// type-specifier-seq in conversion-type-id
-template  requires (bool)::operator short
-unsigned int foo(); // expected-error {{C++ requires a type specifier for all declarations}}
-
-// type-specifier-seq in new-type-id
-template  requires (bool)sizeof new (T::f()) short
-unsigned int bar(); // expected-error {{C++ requires a type specifier for all declarations}}
-
-template requires (bool)sizeof new (T::f()) unsigned // expected-error {{'struct' cannot be signed or unsigned}}
-struct X { }; // expected-error {{'X' cannot be defined in a type specifier}}
-
-// C-style cast
-// of function call on function-style cast
-template  requires (bool(T()))
-T (*fp)(); // expected-error {{use of undeclared identifier 'fp'}}
-
-// function-style cast
-// as the callee in a function call
-struct A {
-  static int t;
-  template  requires bool(T())
-  (A(T ())) { } // expected-error {{called object type 'bool' is not a function or function pointer}}
-};
Index: test/Parser/cxx2a-concept-declaration.cpp

[PATCH] D50860: [libc++][test] Remove non-portable assumption that thread's constructor allocates with ::new

2019-04-21 Thread Casey Carter via Phabricator via cfe-commits
CaseyCarter added a comment.

Ping?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D50860/new/

https://reviews.llvm.org/D50860



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


[PATCH] D60629: [clang-tidy] Change the namespace for llvm checkers from 'llvm' to 'llvm_check'

2019-04-21 Thread Don Hinton via Phabricator via cfe-commits
hintonda marked an inline comment as done.
hintonda added inline comments.



Comment at: clang-tools-extra/clang-tidy/rename_check.py:218
   header_guard_variants = [
+  (args.old_check_name.replace('-', '_') + '_Check').upper(),
+  (old_module + '_' + check_name_camel).upper(),

alexfh wrote:
> s/_Check/_CHECK/, maybe?
Not sure it matters, but args.old_check_name is all lower case, so we have to 
uppercase the entire string.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60629/new/

https://reviews.llvm.org/D60629



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


[PATCH] D60778: Make precompiled headers reproducible by switching OpenCL extension to std::map

2019-04-21 Thread Roman Lebedev via Phabricator via cfe-commits
lebedev.ri added a comment.

Abandon this?
Sorry for this fruitless effort.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60778/new/

https://reviews.llvm.org/D60778



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


[PATCH] D29707: Fix improper microsoft-pure-definition warning on template class

2019-04-21 Thread Phabricator via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rL358849: [Sema][MSVC] Fix bogus microsoft-pure-definition 
warning on member function of… (authored by brunoricci, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D29707?vs=87611=195999#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D29707/new/

https://reviews.llvm.org/D29707

Files:
  cfe/trunk/lib/Sema/SemaDecl.cpp
  cfe/trunk/test/Parser/MicrosoftExtensions.cpp


Index: cfe/trunk/lib/Sema/SemaDecl.cpp
===
--- cfe/trunk/lib/Sema/SemaDecl.cpp
+++ cfe/trunk/lib/Sema/SemaDecl.cpp
@@ -13244,7 +13244,7 @@
 
 // MSVC permits the use of pure specifier (=0) on function definition,
 // defined at class scope, warn about this non-standard construct.
-if (getLangOpts().MicrosoftExt && FD->isPure() && FD->isCanonicalDecl())
+if (getLangOpts().MicrosoftExt && FD->isPure() && !FD->isOutOfLine())
   Diag(FD->getLocation(), diag::ext_pure_function_definition);
 
 if (!FD->isInvalidDecl()) {
Index: cfe/trunk/test/Parser/MicrosoftExtensions.cpp
===
--- cfe/trunk/test/Parser/MicrosoftExtensions.cpp
+++ cfe/trunk/test/Parser/MicrosoftExtensions.cpp
@@ -288,6 +288,18 @@
   virtual ~pure_virtual_dtor_inline() = 0 { }// expected-warning {{function 
definition with pure-specifier is a Microsoft extension}}
 };
 
+template struct pure_virtual_dtor_template {
+  virtual ~pure_virtual_dtor_template() = 0;
+};
+template 
pure_virtual_dtor_template::~pure_virtual_dtor_template() {}
+template struct pure_virtual_dtor_template;
+
+template struct pure_virtual_dtor_template_inline {
+virtual ~pure_virtual_dtor_template_inline() = 0 {}
+// expected-warning@-1 2{{function definition with pure-specifier is a 
Microsoft extension}}
+};
+template struct pure_virtual_dtor_template_inline;
+// expected-note@-1 {{in instantiation of member function}}
 
 int main () {
   // Necessary to force instantiation in -fdelayed-template-parsing mode.


Index: cfe/trunk/lib/Sema/SemaDecl.cpp
===
--- cfe/trunk/lib/Sema/SemaDecl.cpp
+++ cfe/trunk/lib/Sema/SemaDecl.cpp
@@ -13244,7 +13244,7 @@
 
 // MSVC permits the use of pure specifier (=0) on function definition,
 // defined at class scope, warn about this non-standard construct.
-if (getLangOpts().MicrosoftExt && FD->isPure() && FD->isCanonicalDecl())
+if (getLangOpts().MicrosoftExt && FD->isPure() && !FD->isOutOfLine())
   Diag(FD->getLocation(), diag::ext_pure_function_definition);
 
 if (!FD->isInvalidDecl()) {
Index: cfe/trunk/test/Parser/MicrosoftExtensions.cpp
===
--- cfe/trunk/test/Parser/MicrosoftExtensions.cpp
+++ cfe/trunk/test/Parser/MicrosoftExtensions.cpp
@@ -288,6 +288,18 @@
   virtual ~pure_virtual_dtor_inline() = 0 { }// expected-warning {{function definition with pure-specifier is a Microsoft extension}}
 };
 
+template struct pure_virtual_dtor_template {
+  virtual ~pure_virtual_dtor_template() = 0;
+};
+template pure_virtual_dtor_template::~pure_virtual_dtor_template() {}
+template struct pure_virtual_dtor_template;
+
+template struct pure_virtual_dtor_template_inline {
+virtual ~pure_virtual_dtor_template_inline() = 0 {}
+// expected-warning@-1 2{{function definition with pure-specifier is a Microsoft extension}}
+};
+template struct pure_virtual_dtor_template_inline;
+// expected-note@-1 {{in instantiation of member function}}
 
 int main () {
   // Necessary to force instantiation in -fdelayed-template-parsing mode.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


r358849 - [Sema][MSVC] Fix bogus microsoft-pure-definition warning on member function of class template

2019-04-21 Thread Bruno Ricci via cfe-commits
Author: brunoricci
Date: Sun Apr 21 06:12:10 2019
New Revision: 358849

URL: http://llvm.org/viewvc/llvm-project?rev=358849=rev
Log:
[Sema][MSVC] Fix bogus microsoft-pure-definition warning on member function of 
class template

Clang emits a warning when using a pure specifier =0 in a function definition
at class scope (a MS-specific construct), when using -fms-extensions.
However, to detect this, it was using FD->isCanonicalDecl() on function
declaration, which was also detecting out-of-class definition of member
functions of class templates. Fix this by using !FD->isOutOfLine() instead.

Fixes PR21334.

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

Reviewed By: riccibruno

Reviewers: rnk, riccibruno

Patch By: Rudy Pons


Modified:
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/Parser/MicrosoftExtensions.cpp

Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=358849=358848=358849=diff
==
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Sun Apr 21 06:12:10 2019
@@ -13244,7 +13244,7 @@ Decl *Sema::ActOnFinishFunctionBody(Decl
 
 // MSVC permits the use of pure specifier (=0) on function definition,
 // defined at class scope, warn about this non-standard construct.
-if (getLangOpts().MicrosoftExt && FD->isPure() && FD->isCanonicalDecl())
+if (getLangOpts().MicrosoftExt && FD->isPure() && !FD->isOutOfLine())
   Diag(FD->getLocation(), diag::ext_pure_function_definition);
 
 if (!FD->isInvalidDecl()) {

Modified: cfe/trunk/test/Parser/MicrosoftExtensions.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/MicrosoftExtensions.cpp?rev=358849=358848=358849=diff
==
--- cfe/trunk/test/Parser/MicrosoftExtensions.cpp (original)
+++ cfe/trunk/test/Parser/MicrosoftExtensions.cpp Sun Apr 21 06:12:10 2019
@@ -288,6 +288,18 @@ struct pure_virtual_dtor_inline {
   virtual ~pure_virtual_dtor_inline() = 0 { }// expected-warning {{function 
definition with pure-specifier is a Microsoft extension}}
 };
 
+template struct pure_virtual_dtor_template {
+  virtual ~pure_virtual_dtor_template() = 0;
+};
+template 
pure_virtual_dtor_template::~pure_virtual_dtor_template() {}
+template struct pure_virtual_dtor_template;
+
+template struct pure_virtual_dtor_template_inline {
+virtual ~pure_virtual_dtor_template_inline() = 0 {}
+// expected-warning@-1 2{{function definition with pure-specifier is a 
Microsoft extension}}
+};
+template struct pure_virtual_dtor_template_inline;
+// expected-note@-1 {{in instantiation of member function}}
 
 int main () {
   // Necessary to force instantiation in -fdelayed-template-parsing mode.


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


[PATCH] D29707: Fix improper microsoft-pure-definition warning on template class

2019-04-21 Thread Bruno Ricci via Phabricator via cfe-commits
riccibruno accepted this revision.
riccibruno added a comment.
This revision is now accepted and ready to land.

This looks reasonable to me (although I think that the test should be in 
`SemaCXX/` and not in `Parser/`, but the test for the non-template case is 
already in `Parser/` so ok).


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D29707/new/

https://reviews.llvm.org/D29707



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


[PATCH] D60943: Delay diagnosing "n" constraint until after inlining

2019-04-21 Thread Bill Wendling via Phabricator via cfe-commits
void updated this revision to Diff 195994.
void added a comment.
Herald added a subscriber: eraman.

Fix test. Use "e" instead of "n".


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60943/new/

https://reviews.llvm.org/D60943

Files:
  lib/CodeGen/CGStmt.cpp
  lib/Sema/SemaStmtAsm.cpp
  test/Sema/inline-asm-validate-x86.c


Index: test/Sema/inline-asm-validate-x86.c
===
--- test/Sema/inline-asm-validate-x86.c
+++ test/Sema/inline-asm-validate-x86.c
@@ -147,9 +147,9 @@
   // This offset-from-null pointer can be used as an integer constant 
expression.
   __asm__ __volatile__("\n#define S_B abcd%0\n" : : "n"(&((struct s*)0)->b));
   // This pointer cannot be used as an integer constant expression.
-  __asm__ __volatile__("\n#define GLOBAL_A abcd%0\n" : : "n"()); // 
expected-error{{constraint 'n' expects an integer constant expression}}
+  __asm__ __volatile__("\n#define GLOBAL_A abcd%0\n" : : "e"()); // 
expected-error{{constraint 'e' expects an integer constant expression}}
   // Floating-point is also not okay.
-  __asm__ __volatile__("\n#define PI abcd%0\n" : : "n"(3.14f)); // 
expected-error{{constraint 'n' expects an integer constant expression}}
+  __asm__ __volatile__("\n#define PI abcd%0\n" : : "e"(3.14f)); // 
expected-error{{constraint 'e' expects an integer constant expression}}
 #ifdef AMD64
   // This arbitrary pointer is fine.
   __asm__ __volatile__("\n#define BEEF abcd%0\n" : : 
"n"((int*)0xdeadbeef));
Index: lib/Sema/SemaStmtAsm.cpp
===
--- lib/Sema/SemaStmtAsm.cpp
+++ lib/Sema/SemaStmtAsm.cpp
@@ -379,7 +379,7 @@
  << Info.getConstraintStr()
  << InputExpr->getSourceRange());
 } else if (Info.requiresImmediateConstant() && !Info.allowsRegister()) {
-  if (!InputExpr->isValueDependent()) {
+  if (!InputExpr->isValueDependent() && Literal->getString() != "n") {
 Expr::EvalResult EVResult;
 if (!InputExpr->EvaluateAsRValue(EVResult, Context, true))
   return StmtError(
@@ -401,7 +401,6 @@
<< IntResult.toString(10) << Info.getConstraintStr()
<< InputExpr->getSourceRange());
   }
-
 } else {
   ExprResult Result = DefaultFunctionArrayLvalueConversion(Exprs[i]);
   if (Result.isInvalid())
Index: lib/CodeGen/CGStmt.cpp
===
--- lib/CodeGen/CGStmt.cpp
+++ lib/CodeGen/CGStmt.cpp
@@ -1842,11 +1842,13 @@
   InputExpr->EvaluateAsRValue(EVResult, getContext(), true);
 
   llvm::APSInt IntResult;
-  if (!EVResult.Val.toIntegralConstant(IntResult, InputExpr->getType(),
-   getContext()))
-llvm_unreachable("Invalid immediate constant!");
+  if (EVResult.Val.toIntegralConstant(IntResult, InputExpr->getType(),
+  getContext()))
+return llvm::ConstantInt::get(getLLVMContext(), IntResult);
 
-  return llvm::ConstantInt::get(getLLVMContext(), IntResult);
+  if (Info.getConstraintStr() != "n")
+// We can delay diagnosing the "n" constraint until after inlining.
+llvm_unreachable("Invalid immediate constant!");
 }
 
 Expr::EvalResult Result;


Index: test/Sema/inline-asm-validate-x86.c
===
--- test/Sema/inline-asm-validate-x86.c
+++ test/Sema/inline-asm-validate-x86.c
@@ -147,9 +147,9 @@
   // This offset-from-null pointer can be used as an integer constant expression.
   __asm__ __volatile__("\n#define S_B abcd%0\n" : : "n"(&((struct s*)0)->b));
   // This pointer cannot be used as an integer constant expression.
-  __asm__ __volatile__("\n#define GLOBAL_A abcd%0\n" : : "n"()); // expected-error{{constraint 'n' expects an integer constant expression}}
+  __asm__ __volatile__("\n#define GLOBAL_A abcd%0\n" : : "e"()); // expected-error{{constraint 'e' expects an integer constant expression}}
   // Floating-point is also not okay.
-  __asm__ __volatile__("\n#define PI abcd%0\n" : : "n"(3.14f)); // expected-error{{constraint 'n' expects an integer constant expression}}
+  __asm__ __volatile__("\n#define PI abcd%0\n" : : "e"(3.14f)); // expected-error{{constraint 'e' expects an integer constant expression}}
 #ifdef AMD64
   // This arbitrary pointer is fine.
   __asm__ __volatile__("\n#define BEEF abcd%0\n" : : "n"((int*)0xdeadbeef));
Index: lib/Sema/SemaStmtAsm.cpp
===
--- lib/Sema/SemaStmtAsm.cpp
+++ lib/Sema/SemaStmtAsm.cpp
@@ -379,7 +379,7 @@
  << Info.getConstraintStr()
  << InputExpr->getSourceRange());
 } else if (Info.requiresImmediateConstant() && !Info.allowsRegister()) {
-  if 

[PATCH] D60943: Delay diagnosing "n" constraint until after inlining

2019-04-21 Thread Bill Wendling via Phabricator via cfe-commits
void updated this revision to Diff 195992.
void added a comment.

Put constraint string check in the correct place.


Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60943/new/

https://reviews.llvm.org/D60943

Files:
  lib/CodeGen/CGStmt.cpp
  lib/Sema/SemaStmtAsm.cpp


Index: lib/Sema/SemaStmtAsm.cpp
===
--- lib/Sema/SemaStmtAsm.cpp
+++ lib/Sema/SemaStmtAsm.cpp
@@ -379,7 +379,7 @@
  << Info.getConstraintStr()
  << InputExpr->getSourceRange());
 } else if (Info.requiresImmediateConstant() && !Info.allowsRegister()) {
-  if (!InputExpr->isValueDependent()) {
+  if (!InputExpr->isValueDependent() && Literal->getString() != "n") {
 Expr::EvalResult EVResult;
 if (!InputExpr->EvaluateAsRValue(EVResult, Context, true))
   return StmtError(
@@ -401,7 +401,6 @@
<< IntResult.toString(10) << Info.getConstraintStr()
<< InputExpr->getSourceRange());
   }
-
 } else {
   ExprResult Result = DefaultFunctionArrayLvalueConversion(Exprs[i]);
   if (Result.isInvalid())
Index: lib/CodeGen/CGStmt.cpp
===
--- lib/CodeGen/CGStmt.cpp
+++ lib/CodeGen/CGStmt.cpp
@@ -1842,11 +1842,13 @@
   InputExpr->EvaluateAsRValue(EVResult, getContext(), true);
 
   llvm::APSInt IntResult;
-  if (!EVResult.Val.toIntegralConstant(IntResult, InputExpr->getType(),
-   getContext()))
-llvm_unreachable("Invalid immediate constant!");
+  if (EVResult.Val.toIntegralConstant(IntResult, InputExpr->getType(),
+  getContext()))
+return llvm::ConstantInt::get(getLLVMContext(), IntResult);
 
-  return llvm::ConstantInt::get(getLLVMContext(), IntResult);
+  if (Info.getConstraintStr() != "n")
+// We can delay diagnosing the "n" constraint until after inlining.
+llvm_unreachable("Invalid immediate constant!");
 }
 
 Expr::EvalResult Result;


Index: lib/Sema/SemaStmtAsm.cpp
===
--- lib/Sema/SemaStmtAsm.cpp
+++ lib/Sema/SemaStmtAsm.cpp
@@ -379,7 +379,7 @@
  << Info.getConstraintStr()
  << InputExpr->getSourceRange());
 } else if (Info.requiresImmediateConstant() && !Info.allowsRegister()) {
-  if (!InputExpr->isValueDependent()) {
+  if (!InputExpr->isValueDependent() && Literal->getString() != "n") {
 Expr::EvalResult EVResult;
 if (!InputExpr->EvaluateAsRValue(EVResult, Context, true))
   return StmtError(
@@ -401,7 +401,6 @@
<< IntResult.toString(10) << Info.getConstraintStr()
<< InputExpr->getSourceRange());
   }
-
 } else {
   ExprResult Result = DefaultFunctionArrayLvalueConversion(Exprs[i]);
   if (Result.isInvalid())
Index: lib/CodeGen/CGStmt.cpp
===
--- lib/CodeGen/CGStmt.cpp
+++ lib/CodeGen/CGStmt.cpp
@@ -1842,11 +1842,13 @@
   InputExpr->EvaluateAsRValue(EVResult, getContext(), true);
 
   llvm::APSInt IntResult;
-  if (!EVResult.Val.toIntegralConstant(IntResult, InputExpr->getType(),
-   getContext()))
-llvm_unreachable("Invalid immediate constant!");
+  if (EVResult.Val.toIntegralConstant(IntResult, InputExpr->getType(),
+  getContext()))
+return llvm::ConstantInt::get(getLLVMContext(), IntResult);
 
-  return llvm::ConstantInt::get(getLLVMContext(), IntResult);
+  if (Info.getConstraintStr() != "n")
+// We can delay diagnosing the "n" constraint until after inlining.
+llvm_unreachable("Invalid immediate constant!");
 }
 
 Expr::EvalResult Result;
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D60934: [clang] adding explicit(bool) from c++2a

2019-04-21 Thread Gauthier via Phabricator via cfe-commits
Tyker updated this revision to Diff 195990.
Tyker added a comment.

@Quuxplusone @riccibruno  fixed / answered feedback


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60934/new/

https://reviews.llvm.org/D60934

Files:
  clang/include/clang/AST/Decl.h
  clang/include/clang/AST/DeclBase.h
  clang/include/clang/AST/DeclCXX.h
  clang/include/clang/ASTMatchers/ASTMatchers.h
  clang/include/clang/Basic/DiagnosticParseKinds.td
  clang/include/clang/Basic/DiagnosticSemaKinds.td
  clang/include/clang/Basic/Specifiers.h
  clang/include/clang/Sema/DeclSpec.h
  clang/include/clang/Sema/Overload.h
  clang/include/clang/Sema/Sema.h
  clang/include/clang/Serialization/ASTReader.h
  clang/lib/AST/ASTImporter.cpp
  clang/lib/AST/ASTStructuralEquivalence.cpp
  clang/lib/AST/Decl.cpp
  clang/lib/AST/DeclCXX.cpp
  clang/lib/AST/DeclPrinter.cpp
  clang/lib/Parse/ParseDecl.cpp
  clang/lib/Sema/DeclSpec.cpp
  clang/lib/Sema/SemaCodeComplete.cpp
  clang/lib/Sema/SemaDecl.cpp
  clang/lib/Sema/SemaDeclCXX.cpp
  clang/lib/Sema/SemaInit.cpp
  clang/lib/Sema/SemaLambda.cpp
  clang/lib/Sema/SemaLookup.cpp
  clang/lib/Sema/SemaOverload.cpp
  clang/lib/Sema/SemaTemplate.cpp
  clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
  clang/lib/Serialization/ASTReaderDecl.cpp
  clang/lib/Serialization/ASTWriterDecl.cpp
  clang/test/PCH/cxx-explicit-spec.cpp
  clang/test/SemaCXX/cxx2a-explicit-bool.cpp
  clang/test/SemaCXX/explicit.cpp

Index: clang/test/SemaCXX/explicit.cpp
===
--- clang/test/SemaCXX/explicit.cpp
+++ clang/test/SemaCXX/explicit.cpp
@@ -1,4 +1,6 @@
 // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++2a %s
+
 namespace Constructor {
 struct A {
   A(int);
@@ -183,7 +185,8 @@
 const int  = {b};
 const int  = {n}; // expected-error {{no viable conversion}}
   }
-  
+
+#if __cplusplus < 201707L
   void testNew()
   {
 // 5.3.4p6:
@@ -200,7 +203,8 @@
 new int[i];
 new int[ni]; // expected-error {{array size expression of type 'NotInt' requires explicit conversion to type 'int'}}
   }
-  
+#endif
+
   void testDelete()
   {
 // 5.3.5pp2:
Index: clang/test/SemaCXX/cxx2a-explicit-bool.cpp
===
--- /dev/null
+++ clang/test/SemaCXX/cxx2a-explicit-bool.cpp
@@ -0,0 +1,335 @@
+// RUN: %clang_cc1 -std=c++2a -fsyntax-only %s -verify
+
+template
+struct enable_ifv {};
+
+template
+struct enable_ifv {
+  static constexpr auto value = val;
+};
+
+template
+struct is_same {
+static constexpr bool value = false;
+};
+
+template
+struct is_same {
+static constexpr bool value = true;
+};
+
+namespace test0
+{
+
+template
+struct A {
+  explicit(1 << a)
+  //expected-error@-1 {{argument to explicit specifier is not a valid constant expression}}
+  //expected-note@-2 {{negative shift count -1}}
+  A(int);
+};
+
+A<-1> a(0); //expected-note {{in instantiation of template class}}
+
+template
+struct B {
+  explicit(b)
+  // expected-error@-1 {{use of undeclared identifier}}
+  // expected-note@-2 {{this expression is parsed as explicit(bool) since c++2a}}
+  B(int);
+};
+
+}
+
+namespace test1 {
+
+template
+struct A {
+  // expected-note@-1 {{candidate constructor}}
+  // expected-note@-2 {{candidate constructor}}
+  // expected-note@-3 {{candidate function}} expected-note@-3 {{candidate function}}
+  // expected-note@-4 {{candidate function}} expected-note@-4 {{candidate function}}
+  explicit(b) A(int, int = 0);
+  // expected-note@-1 {{explicit constructor declared here}}
+  // expected-note@-2 {{explicit constructor declared here}}
+  // expected-note@-3 {{explicit constructor declared here}}
+};
+
+template
+A::A(int, int) {}
+
+void f()
+{
+  A a0 = 0; // expected-error {{no viable conversion}}
+  A a1( 0);
+  A && a2 = 0;// expected-error {{could not bind}}
+  A && a3( 0);// expected-error {{could not bind}}
+  A a4{ 0};
+  A && a5 = { 0};// expected-error {{chosen constructor is explicit}}
+  A && a6{ 0};
+  A a7 = { 0}; // expected-error {{chosen constructor is explicit in copy-initialization}}
+
+  a0 = 0;
+  a1 = { 0}; // expected-error {{no viable overloaded '='}}
+  a2 = A( 0);
+  a3 = A{ 0};
+
+  A c0 =  ((short)0);
+  A c1( ((short)0));
+  A && c2 =  ((short)0);
+  A && c3( ((short)0));
+  A c4{ ((short)0)};
+  A && c5 = { ((short)0)};
+  A && c6{ ((short)0)};
+
+  A d1( 0, 0);
+  A d2{ 0, 0};
+  A d3 = { 0, 0}; // expected-error {{chosen constructor is explicit in copy-initialization}}
+
+  d1 = { 0, 0}; // expected-error {{no viable overloaded '='}}
+  d2 = A( 0, 0);
+  d3 = A{ 0, 0};
+}
+}
+
+namespace test2 {
+
+template
+struct A {
+// expected-note@-1 {{candidate constructor}} expected-note@-1 {{candidate constructor}}
+// expected-note@-2 {{candidate constructor}} expected-note@-2 {{candidate constructor}}
+  template
+  explicit(a ^ is_same::value)
+// expected-note@-1 {{explicit(bool) specifier resolved to true}} 

[PATCH] D60943: Delay diagnosing "n" constraint until after inlining

2019-04-21 Thread Bill Wendling via Phabricator via cfe-commits
void created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

An inline asm call may result in an immediate input value after inlining.
Therefore, don't emit a diagnostic here if the input isn't an immediate.


Repository:
  rC Clang

https://reviews.llvm.org/D60943

Files:
  lib/CodeGen/CGStmt.cpp
  lib/Sema/SemaStmtAsm.cpp


Index: lib/Sema/SemaStmtAsm.cpp
===
--- lib/Sema/SemaStmtAsm.cpp
+++ lib/Sema/SemaStmtAsm.cpp
@@ -381,7 +381,8 @@
 } else if (Info.requiresImmediateConstant() && !Info.allowsRegister()) {
   if (!InputExpr->isValueDependent()) {
 Expr::EvalResult EVResult;
-if (!InputExpr->EvaluateAsRValue(EVResult, Context, true))
+if (!InputExpr->EvaluateAsRValue(EVResult, Context, true) &&
+Literal->getString() != "n")
   return StmtError(
   Diag(InputExpr->getBeginLoc(), diag::err_asm_immediate_expected)
   << Info.getConstraintStr() << InputExpr->getSourceRange());
@@ -395,7 +396,7 @@
   Diag(InputExpr->getBeginLoc(), diag::err_asm_immediate_expected)
   << Info.getConstraintStr() << InputExpr->getSourceRange());
 
-if (!Info.isValidAsmImmediate(IntResult))
+if (!Info.isValidAsmImmediate(IntResult) && Literal->getString() != 
"n")
   return StmtError(Diag(InputExpr->getBeginLoc(),
 diag::err_invalid_asm_value_for_constraint)
<< IntResult.toString(10) << Info.getConstraintStr()
Index: lib/CodeGen/CGStmt.cpp
===
--- lib/CodeGen/CGStmt.cpp
+++ lib/CodeGen/CGStmt.cpp
@@ -1837,7 +1837,8 @@
   // If this can't be a register or memory, i.e., has to be a constant
   // (immediate or symbolic), try to emit it as such.
   if (!Info.allowsRegister() && !Info.allowsMemory()) {
-if (Info.requiresImmediateConstant()) {
+// We can delay diagnosing the "n" constraint until after inlining.
+if (Info.requiresImmediateConstant() && ConstraintStr != "n") {
   Expr::EvalResult EVResult;
   InputExpr->EvaluateAsRValue(EVResult, getContext(), true);
 


Index: lib/Sema/SemaStmtAsm.cpp
===
--- lib/Sema/SemaStmtAsm.cpp
+++ lib/Sema/SemaStmtAsm.cpp
@@ -381,7 +381,8 @@
 } else if (Info.requiresImmediateConstant() && !Info.allowsRegister()) {
   if (!InputExpr->isValueDependent()) {
 Expr::EvalResult EVResult;
-if (!InputExpr->EvaluateAsRValue(EVResult, Context, true))
+if (!InputExpr->EvaluateAsRValue(EVResult, Context, true) &&
+Literal->getString() != "n")
   return StmtError(
   Diag(InputExpr->getBeginLoc(), diag::err_asm_immediate_expected)
   << Info.getConstraintStr() << InputExpr->getSourceRange());
@@ -395,7 +396,7 @@
   Diag(InputExpr->getBeginLoc(), diag::err_asm_immediate_expected)
   << Info.getConstraintStr() << InputExpr->getSourceRange());
 
-if (!Info.isValidAsmImmediate(IntResult))
+if (!Info.isValidAsmImmediate(IntResult) && Literal->getString() != "n")
   return StmtError(Diag(InputExpr->getBeginLoc(),
 diag::err_invalid_asm_value_for_constraint)
<< IntResult.toString(10) << Info.getConstraintStr()
Index: lib/CodeGen/CGStmt.cpp
===
--- lib/CodeGen/CGStmt.cpp
+++ lib/CodeGen/CGStmt.cpp
@@ -1837,7 +1837,8 @@
   // If this can't be a register or memory, i.e., has to be a constant
   // (immediate or symbolic), try to emit it as such.
   if (!Info.allowsRegister() && !Info.allowsMemory()) {
-if (Info.requiresImmediateConstant()) {
+// We can delay diagnosing the "n" constraint until after inlining.
+if (Info.requiresImmediateConstant() && ConstraintStr != "n") {
   Expr::EvalResult EVResult;
   InputExpr->EvaluateAsRValue(EVResult, getContext(), true);
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits