[clang] f4dccf1 - [clang] Add a matcher for template template parameters.

2020-08-11 Thread Bruno Ricci via cfe-commits

Author: Bruno Ricci
Date: 2020-08-11T16:01:36+01:00
New Revision: f4dccf115cc198e552b520fda0ee623457015db7

URL: 
https://github.com/llvm/llvm-project/commit/f4dccf115cc198e552b520fda0ee623457015db7
DIFF: 
https://github.com/llvm/llvm-project/commit/f4dccf115cc198e552b520fda0ee623457015db7.diff

LOG: [clang] Add a matcher for template template parameters.

There are already matchers for type template parameters and non-type template
parameters, but somehow no matcher exists for template template parameters
and I need it to write unit tests.

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

Reviewed By: aaron.ballman

Added: 


Modified: 
clang/include/clang/ASTMatchers/ASTMatchers.h
clang/lib/ASTMatchers/ASTMatchersInternal.cpp
clang/lib/ASTMatchers/Dynamic/Registry.cpp
clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp

Removed: 




diff  --git a/clang/include/clang/ASTMatchers/ASTMatchers.h 
b/clang/include/clang/ASTMatchers/ASTMatchers.h
index e37c68a8f156..f5c4fe63182f 100644
--- a/clang/include/clang/ASTMatchers/ASTMatchers.h
+++ b/clang/include/clang/ASTMatchers/ASTMatchers.h
@@ -562,6 +562,18 @@ extern const internal::VariadicDynCastAllOfMatcher
 templateTypeParmDecl;
 
+/// Matches template template parameter declarations.
+///
+/// Given
+/// \code
+///   template  class Z, int N> struct C {};
+/// \endcode
+/// templateTypeParmDecl()
+///   matches 'Z', but not 'N'.
+extern const internal::VariadicDynCastAllOfMatcher
+templateTemplateParmDecl;
+
 /// Matches public C++ declarations and C++ base specifers that specify public
 /// inheritance.
 ///

diff  --git a/clang/lib/ASTMatchers/ASTMatchersInternal.cpp 
b/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
index 5b9476f3098a..6b17bd0cda0b 100644
--- a/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
+++ b/clang/lib/ASTMatchers/ASTMatchersInternal.cpp
@@ -740,6 +740,9 @@ const internal::VariadicDynCastAllOfMatcher
 nonTypeTemplateParmDecl;
 const internal::VariadicDynCastAllOfMatcher
 templateTypeParmDecl;
+const internal::VariadicDynCastAllOfMatcher
+templateTemplateParmDecl;
+
 const internal::VariadicAllOfMatcher qualType;
 const internal::VariadicAllOfMatcher type;
 const internal::VariadicAllOfMatcher typeLoc;

diff  --git a/clang/lib/ASTMatchers/Dynamic/Registry.cpp 
b/clang/lib/ASTMatchers/Dynamic/Registry.cpp
index ec2215804c09..058dabde 100644
--- a/clang/lib/ASTMatchers/Dynamic/Registry.cpp
+++ b/clang/lib/ASTMatchers/Dynamic/Registry.cpp
@@ -514,6 +514,7 @@ RegistryMaps::RegistryMaps() {
   REGISTER_MATCHER(templateArgumentCountIs);
   REGISTER_MATCHER(templateName);
   REGISTER_MATCHER(templateSpecializationType);
+  REGISTER_MATCHER(templateTemplateParmDecl);
   REGISTER_MATCHER(templateTypeParmDecl);
   REGISTER_MATCHER(templateTypeParmType);
   REGISTER_MATCHER(throughUsingDecl);

diff  --git a/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp 
b/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
index 895c8ae48adc..f4e929752ea0 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -408,6 +408,15 @@ TEST_P(ASTMatchersTest, TemplateTypeParmDecl) {
   EXPECT_TRUE(notMatches("template  void f();", 
templateTypeParmDecl()));
 }
 
+TEST_P(ASTMatchersTest, TemplateTemplateParmDecl) {
+  if (!GetParam().isCXX())
+return;
+  EXPECT_TRUE(matches("template  class Z> void f();",
+  templateTemplateParmDecl(hasName("Z";
+  EXPECT_TRUE(notMatches("template  void f();",
+ templateTemplateParmDecl()));
+}
+
 TEST_P(ASTMatchersTest, UserDefinedLiteral) {
   if (!GetParam().isCXX11OrLater()) {
 return;



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


[clang] 4dcbb9c - [clang] Add -fno-delayed-template-parsing to the added unit tests in DeclPrinterTest.cpp

2020-08-05 Thread Bruno Ricci via cfe-commits

Author: Bruno Ricci
Date: 2020-08-05T14:13:05+01:00
New Revision: 4dcbb9cef71afa549afe8f6b4d335b1c996f8079

URL: 
https://github.com/llvm/llvm-project/commit/4dcbb9cef71afa549afe8f6b4d335b1c996f8079
DIFF: 
https://github.com/llvm/llvm-project/commit/4dcbb9cef71afa549afe8f6b4d335b1c996f8079.diff

LOG: [clang] Add -fno-delayed-template-parsing to the added unit tests in 
DeclPrinterTest.cpp

Added: 


Modified: 
clang/unittests/AST/DeclPrinterTest.cpp

Removed: 




diff  --git a/clang/unittests/AST/DeclPrinterTest.cpp 
b/clang/unittests/AST/DeclPrinterTest.cpp
index 38e46a378b47..6b7ceac3cb02 100644
--- a/clang/unittests/AST/DeclPrinterTest.cpp
+++ b/clang/unittests/AST/DeclPrinterTest.cpp
@@ -153,8 +153,7 @@ ::testing::AssertionResult PrintedDeclCXX11nonMSCMatches(
   StringRef Code,
   const DeclarationMatcher ,
   StringRef ExpectedPrinted) {
-  std::vector Args(1, "-std=c++11");
-  Args.push_back("-fno-delayed-template-parsing");
+  std::vector Args{"-std=c++11", "-fno-delayed-template-parsing"};
   return PrintedDeclMatches(Code,
 Args,
 NodeMatch,
@@ -166,7 +165,7 @@ ::testing::AssertionResult
 PrintedDeclCXX17Matches(StringRef Code, const DeclarationMatcher ,
 StringRef ExpectedPrinted,
 PrintingPolicyModifier PolicyModifier = nullptr) {
-  std::vector Args(1, "-std=c++17");
+  std::vector Args{"-std=c++17", "-fno-delayed-template-parsing"};
   return PrintedDeclMatches(Code, Args, NodeMatch, ExpectedPrinted, "input.cc",
 PolicyModifier);
 }



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


[clang] 94b4311 - [clang][NFCI] Get rid of ConstantMatrixTypeBitfields to avoid increasing the size of every type.

2020-08-05 Thread Bruno Ricci via cfe-commits

Author: Bruno Ricci
Date: 2020-08-05T13:54:37+01:00
New Revision: 94b43118e2203fed8ca0377ae762c08189aa6f3d

URL: 
https://github.com/llvm/llvm-project/commit/94b43118e2203fed8ca0377ae762c08189aa6f3d
DIFF: 
https://github.com/llvm/llvm-project/commit/94b43118e2203fed8ca0377ae762c08189aa6f3d.diff

LOG: [clang][NFCI] Get rid of ConstantMatrixTypeBitfields to avoid increasing 
the size of every type.

sizeof(ConstantMatrixTypeBitfields) > 8 which increases the size of every type.
This was not detected because no corresponding static_assert for its size was
added.

To prevent this from occuring again replace the various static_asserts for
the size of each of the bit-field classes by a single static_assert for the
size of Type.

I have left ConstantMatrixType::MaxElementsPerDimension unchanged since
the limit is exercised by multiple tests.

Added: 


Modified: 
clang/include/clang/AST/Type.h
clang/lib/AST/Type.cpp

Removed: 




diff  --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 7d943ebc78c0..df9c926ce902 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -1680,19 +1680,6 @@ class alignas(8) Type : public ExtQualsTypeCommonBase {
 uint32_t NumElements;
   };
 
-  class ConstantMatrixTypeBitfields {
-friend class ConstantMatrixType;
-
-unsigned : NumTypeBits;
-
-/// Number of rows and columns. Using 20 bits allows supporting very large
-/// matrixes, while keeping 24 bits to accommodate NumTypeBits.
-unsigned NumRows : 20;
-unsigned NumColumns : 20;
-
-static constexpr uint32_t MaxElementsPerDimension = (1 << 20) - 1;
-  };
-
   class AttributedTypeBitfields {
 friend class AttributedType;
 
@@ -1802,46 +1789,11 @@ class alignas(8) Type : public ExtQualsTypeCommonBase {
 TypeWithKeywordBitfields TypeWithKeywordBits;
 ElaboratedTypeBitfields ElaboratedTypeBits;
 VectorTypeBitfields VectorTypeBits;
-ConstantMatrixTypeBitfields ConstantMatrixTypeBits;
 SubstTemplateTypeParmPackTypeBitfields SubstTemplateTypeParmPackTypeBits;
 TemplateSpecializationTypeBitfields TemplateSpecializationTypeBits;
 DependentTemplateSpecializationTypeBitfields
   DependentTemplateSpecializationTypeBits;
 PackExpansionTypeBitfields PackExpansionTypeBits;
-
-static_assert(sizeof(TypeBitfields) <= 8,
-  "TypeBitfields is larger than 8 bytes!");
-static_assert(sizeof(ArrayTypeBitfields) <= 8,
-  "ArrayTypeBitfields is larger than 8 bytes!");
-static_assert(sizeof(AttributedTypeBitfields) <= 8,
-  "AttributedTypeBitfields is larger than 8 bytes!");
-static_assert(sizeof(AutoTypeBitfields) <= 8,
-  "AutoTypeBitfields is larger than 8 bytes!");
-static_assert(sizeof(BuiltinTypeBitfields) <= 8,
-  "BuiltinTypeBitfields is larger than 8 bytes!");
-static_assert(sizeof(FunctionTypeBitfields) <= 8,
-  "FunctionTypeBitfields is larger than 8 bytes!");
-static_assert(sizeof(ObjCObjectTypeBitfields) <= 8,
-  "ObjCObjectTypeBitfields is larger than 8 bytes!");
-static_assert(sizeof(ReferenceTypeBitfields) <= 8,
-  "ReferenceTypeBitfields is larger than 8 bytes!");
-static_assert(sizeof(TypeWithKeywordBitfields) <= 8,
-  "TypeWithKeywordBitfields is larger than 8 bytes!");
-static_assert(sizeof(ElaboratedTypeBitfields) <= 8,
-  "ElaboratedTypeBitfields is larger than 8 bytes!");
-static_assert(sizeof(VectorTypeBitfields) <= 8,
-  "VectorTypeBitfields is larger than 8 bytes!");
-static_assert(sizeof(SubstTemplateTypeParmPackTypeBitfields) <= 8,
-  "SubstTemplateTypeParmPackTypeBitfields is larger"
-  " than 8 bytes!");
-static_assert(sizeof(TemplateSpecializationTypeBitfields) <= 8,
-  "TemplateSpecializationTypeBitfields is larger"
-  " than 8 bytes!");
-static_assert(sizeof(DependentTemplateSpecializationTypeBitfields) <= 8,
-  "DependentTemplateSpecializationTypeBitfields is larger"
-  " than 8 bytes!");
-static_assert(sizeof(PackExpansionTypeBitfields) <= 8,
-  "PackExpansionTypeBitfields is larger than 8 bytes");
   };
 
 private:
@@ -1858,6 +1810,10 @@ class alignas(8) Type : public ExtQualsTypeCommonBase {
   Type(TypeClass tc, QualType canon, TypeDependence Dependence)
   : ExtQualsTypeCommonBase(this,
canon.isNull() ? QualType(this_(), 0) : canon) {
+static_assert(sizeof(*this) <= 8 + sizeof(ExtQualsTypeCommonBase),
+  "changing bitfields changed sizeof(Type)!");
+static_assert(alignof(decltype(*this)) % sizeof(void *) == 0,
+  "Insufficient alignment!");
 TypeBits.TC = tc;
 

[clang] 98b4b45 - [clang][NFC] Add a test showcasing an unnamed template parameter in a diagnostic

2020-08-05 Thread Bruno Ricci via cfe-commits

Author: Bruno Ricci
Date: 2020-08-05T13:54:36+01:00
New Revision: 98b4b4570542a255e9a81e4a349183402a2d478d

URL: 
https://github.com/llvm/llvm-project/commit/98b4b4570542a255e9a81e4a349183402a2d478d
DIFF: 
https://github.com/llvm/llvm-project/commit/98b4b4570542a255e9a81e4a349183402a2d478d.diff

LOG: [clang][NFC] Add a test showcasing an unnamed template parameter in a 
diagnostic

Added: 


Modified: 
clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp

Removed: 




diff  --git a/clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp 
b/clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp
index 2a3f312ebd8e..e992c7c916f3 100644
--- a/clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp
+++ b/clang/test/SemaCXX/cxx1z-class-template-argument-deduction.cpp
@@ -172,6 +172,10 @@ namespace nondeducible {
   template
   X(float) -> X; // ok
+
+  template  struct UnnamedTemplateParam {};
+  template   // expected-note 
{{non-deducible template parameter (anonymous)}}
+  UnnamedTemplateParam() -> UnnamedTemplateParam; // expected-error 
{{deduction guide template contains a template parameter that cannot be 
deduced}}
 }
 
 namespace default_args_from_ctor {



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


[clang] f7a039d - [clang][NFC] DeclPrinter: use NamedDecl::getDeclName instead of NamedDecl::printName to print the name of enumerations, namespaces and template parameters.

2020-08-05 Thread Bruno Ricci via cfe-commits

Author: Bruno Ricci
Date: 2020-08-05T13:54:38+01:00
New Revision: f7a039de7af7b83105f3e0345d65dceda1a0e0d4

URL: 
https://github.com/llvm/llvm-project/commit/f7a039de7af7b83105f3e0345d65dceda1a0e0d4
DIFF: 
https://github.com/llvm/llvm-project/commit/f7a039de7af7b83105f3e0345d65dceda1a0e0d4.diff

LOG: [clang][NFC] DeclPrinter: use NamedDecl::getDeclName instead of 
NamedDecl::printName to print the name of enumerations, namespaces and template 
parameters.

NamedDecl::printName will print the pretty-printed name of the entity, which
is not what we want here (we should print "enum { e };" instead of "enum
(unnamed enum at input.cc:1:5) { e };").

For now only DecompositionDecl and MDGuidDecl have an overloaded printName so
this does not result in any functional change, but this change is needed since
I will be adding overloads to better handle unnamed entities in diagnostics.

Added: 


Modified: 
clang/lib/AST/DeclPrinter.cpp
clang/unittests/AST/DeclPrinterTest.cpp

Removed: 




diff  --git a/clang/lib/AST/DeclPrinter.cpp b/clang/lib/AST/DeclPrinter.cpp
index 2e48b2b46c4d..ca64f8f6cfbe 100644
--- a/clang/lib/AST/DeclPrinter.cpp
+++ b/clang/lib/AST/DeclPrinter.cpp
@@ -528,7 +528,8 @@ void DeclPrinter::VisitEnumDecl(EnumDecl *D) {
 
   prettyPrintAttributes(D);
 
-  Out << ' ' << *D;
+  if (D->getDeclName())
+Out << ' ' << D->getDeclName();
 
   if (D->isFixed())
 Out << " : " << D->getIntegerType().stream(Policy);
@@ -933,7 +934,12 @@ void DeclPrinter::VisitStaticAssertDecl(StaticAssertDecl 
*D) {
 void DeclPrinter::VisitNamespaceDecl(NamespaceDecl *D) {
   if (D->isInline())
 Out << "inline ";
-  Out << "namespace " << *D << " {\n";
+
+  Out << "namespace ";
+  if (D->getDeclName())
+Out << D->getDeclName() << ' ';
+  Out << "{\n";
+
   VisitDeclContext(D);
   Indent() << "}";
 }
@@ -1091,10 +1097,15 @@ void DeclPrinter::VisitTemplateDecl(const TemplateDecl 
*D) {
 
   if (const TemplateTemplateParmDecl *TTP =
 dyn_cast(D)) {
-Out << "class ";
+Out << "class";
+
 if (TTP->isParameterPack())
-  Out << "...";
-Out << D->getName();
+  Out << " ...";
+else if (TTP->getDeclName())
+  Out << ' ';
+
+if (TTP->getDeclName())
+  Out << TTP->getDeclName();
   } else if (auto *TD = D->getTemplatedDecl())
 Visit(TD);
   else if (const auto *Concept = dyn_cast(D)) {
@@ -1216,7 +1227,7 @@ void DeclPrinter::PrintObjCTypeParams(ObjCTypeParamList 
*Params) {
   break;
 }
 
-Out << Param->getDeclName().getAsString();
+Out << Param->getDeclName();
 
 if (Param->hasExplicitBound()) {
   Out << " : " << Param->getUnderlyingType().getAsString(Policy);
@@ -1695,10 +1706,11 @@ void DeclPrinter::VisitTemplateTypeParmDecl(const 
TemplateTypeParmDecl *TTP) {
 
   if (TTP->isParameterPack())
 Out << " ...";
-  else if (!TTP->getName().empty())
+  else if (TTP->getDeclName())
 Out << ' ';
 
-  Out << *TTP;
+  if (TTP->getDeclName())
+Out << TTP->getDeclName();
 
   if (TTP->hasDefaultArgument()) {
 Out << " = ";

diff  --git a/clang/unittests/AST/DeclPrinterTest.cpp 
b/clang/unittests/AST/DeclPrinterTest.cpp
index 939c8b52c12c..38e46a378b47 100644
--- a/clang/unittests/AST/DeclPrinterTest.cpp
+++ b/clang/unittests/AST/DeclPrinterTest.cpp
@@ -37,6 +37,7 @@ void PrintDecl(raw_ostream , const ASTContext *Context, 
const Decl *D,
PrintingPolicyModifier PolicyModifier) {
   PrintingPolicy Policy = Context->getPrintingPolicy();
   Policy.TerseOutput = true;
+  Policy.Indentation = 0;
   if (PolicyModifier)
 PolicyModifier(Policy);
   D->print(Out, Policy, /*Indentation*/ 0, /*PrintInstantiation*/ false);
@@ -162,14 +163,21 @@ ::testing::AssertionResult PrintedDeclCXX11nonMSCMatches(
 }
 
 ::testing::AssertionResult
-PrintedDeclCXX1ZMatches(StringRef Code, const DeclarationMatcher ,
-StringRef ExpectedPrinted) {
-  std::vector Args(1, "-std=c++1z");
-  return PrintedDeclMatches(Code,
-Args,
-NodeMatch,
-ExpectedPrinted,
-"input.cc");
+PrintedDeclCXX17Matches(StringRef Code, const DeclarationMatcher ,
+StringRef ExpectedPrinted,
+PrintingPolicyModifier PolicyModifier = nullptr) {
+  std::vector Args(1, "-std=c++17");
+  return PrintedDeclMatches(Code, Args, NodeMatch, ExpectedPrinted, "input.cc",
+PolicyModifier);
+}
+
+::testing::AssertionResult
+PrintedDeclC11Matches(StringRef Code, const DeclarationMatcher ,
+  StringRef ExpectedPrinted,
+  PrintingPolicyModifier PolicyModifier = nullptr) {
+  std::vector Args(1, "-std=c11");
+  return PrintedDeclMatches(Code, Args, NodeMatch, ExpectedPrinted, "input.c",
+PolicyModifier);
 }
 
 

[clang] 1970145 - [clang][nearly-NFC] Remove some superfluous uses of NamedDecl::getNameAsString

2020-08-05 Thread Bruno Ricci via cfe-commits

Author: Bruno Ricci
Date: 2020-08-05T13:54:37+01:00
New Revision: 19701458d4691ee7ec59e5aa7217a479b0fb10e7

URL: 
https://github.com/llvm/llvm-project/commit/19701458d4691ee7ec59e5aa7217a479b0fb10e7
DIFF: 
https://github.com/llvm/llvm-project/commit/19701458d4691ee7ec59e5aa7217a479b0fb10e7.diff

LOG: [clang][nearly-NFC] Remove some superfluous uses of 
NamedDecl::getNameAsString

`OS << ND->getDeclName();` is equivalent to `OS << ND->getNameAsString();`
without the extra temporary string.

This is not quite a NFC since two uses of `getNameAsString` in a
diagnostic are replaced, which results in the named entity being
quoted with additional "'"s (ie: 'var' instead of var).

Added: 


Modified: 
clang-tools-extra/clang-include-fixer/find-all-symbols/FindAllSymbols.cpp
clang-tools-extra/clang-move/HelperDeclRefGraph.cpp
clang-tools-extra/clang-move/Move.cpp
clang/lib/AST/ASTDiagnostic.cpp
clang/lib/AST/Interp/Disasm.cpp
clang/lib/AST/TextNodeDumper.cpp
clang/lib/Frontend/FrontendAction.cpp
clang/lib/Index/FileIndexRecord.cpp
clang/lib/Sema/AnalysisBasedWarnings.cpp
clang/lib/Sema/SemaChecking.cpp
clang/lib/StaticAnalyzer/Checkers/CastValueChecker.cpp
clang/lib/StaticAnalyzer/Checkers/FuchsiaHandleChecker.cpp
clang/lib/StaticAnalyzer/Checkers/MallocChecker.cpp
clang/lib/StaticAnalyzer/Checkers/MoveChecker.cpp

clang/lib/StaticAnalyzer/Checkers/RetainCountChecker/RetainCountDiagnostics.cpp
clang/lib/StaticAnalyzer/Checkers/VirtualCallChecker.cpp
clang/lib/StaticAnalyzer/Core/ExprEngine.cpp
clang/lib/Tooling/Refactoring/ASTSelection.cpp
clang/test/Index/error-on-deserialized.c
clang/test/SemaCXX/warn-msvc-enum-bitfield.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-include-fixer/find-all-symbols/FindAllSymbols.cpp 
b/clang-tools-extra/clang-include-fixer/find-all-symbols/FindAllSymbols.cpp
index 7d540d83037b..70d4d7cfdff3 100644
--- a/clang-tools-extra/clang-include-fixer/find-all-symbols/FindAllSymbols.cpp
+++ b/clang-tools-extra/clang-include-fixer/find-all-symbols/FindAllSymbols.cpp
@@ -99,7 +99,7 @@ CreateSymbolInfo(const NamedDecl *ND, const SourceManager ,
 
   SourceLocation Loc = SM.getExpansionLoc(ND->getLocation());
   if (!Loc.isValid()) {
-llvm::errs() << "Declaration " << ND->getNameAsString() << "("
+llvm::errs() << "Declaration " << ND->getDeclName() << "("
  << ND->getDeclKindName()
  << ") has invalid declaration location.";
 return llvm::None;

diff  --git a/clang-tools-extra/clang-move/HelperDeclRefGraph.cpp 
b/clang-tools-extra/clang-move/HelperDeclRefGraph.cpp
index 271bd3d6ef20..a9b773353fe6 100644
--- a/clang-tools-extra/clang-move/HelperDeclRefGraph.cpp
+++ b/clang-tools-extra/clang-move/HelperDeclRefGraph.cpp
@@ -116,7 +116,7 @@ void HelperDeclRGBuilder::run(
 const auto *DC = Result.Nodes.getNodeAs("dc");
 assert(DC);
 LLVM_DEBUG(llvm::dbgs() << "Find helper function usage: "
-<< FuncRef->getDecl()->getNameAsString() << " ("
+<< FuncRef->getDecl()->getDeclName() << " ("
 << FuncRef->getDecl() << ")\n");
 RG->addEdge(
 getOutmostClassOrFunDecl(DC->getCanonicalDecl()),
@@ -126,7 +126,7 @@ void HelperDeclRGBuilder::run(
 const auto *DC = Result.Nodes.getNodeAs("dc");
 assert(DC);
 LLVM_DEBUG(llvm::dbgs()
-   << "Find helper class usage: " << UsedClass->getNameAsString()
+   << "Find helper class usage: " << UsedClass->getDeclName()
<< " (" << UsedClass << ")\n");
 RG->addEdge(getOutmostClassOrFunDecl(DC->getCanonicalDecl()), UsedClass);
   }

diff  --git a/clang-tools-extra/clang-move/Move.cpp 
b/clang-tools-extra/clang-move/Move.cpp
index 3f09f68a8046..24f819ca4ca2 100644
--- a/clang-tools-extra/clang-move/Move.cpp
+++ b/clang-tools-extra/clang-move/Move.cpp
@@ -675,8 +675,8 @@ void ClangMoveTool::run(const 
ast_matchers::MatchFinder::MatchResult ) {
  Result.Nodes.getNodeAs("helper_decls")) {
 MovedDecls.push_back(ND);
 HelperDeclarations.push_back(ND);
-LLVM_DEBUG(llvm::dbgs() << "Add helper : " << ND->getNameAsString() << " ("
-<< ND << ")\n");
+LLVM_DEBUG(llvm::dbgs()
+   << "Add helper : " << ND->getDeclName() << " (" << ND << ")\n");
   } else if (const auto *UD = Result.Nodes.getNodeAs("using_decl")) 
{
 MovedDecls.push_back(UD);
   }
@@ -735,12 +735,12 @@ void ClangMoveTool::removeDeclsInOldFiles() {
 // We remove the helper declarations which are not used in the old.cc after
 // moving the given declarations.
 for (const auto *D : HelperDeclarations) {
-  LLVM_DEBUG(llvm::dbgs() << "Check helper is used: "
-  << D->getNameAsString() << " (" << D << ")\n");
+  

[clang] 6f2fa9d - [clang][NFC] Document NamedDecl::printName

2020-08-05 Thread Bruno Ricci via cfe-commits

Author: Bruno Ricci
Date: 2020-08-05T13:54:37+01:00
New Revision: 6f2fa9d312fcea2448706a8e410c7bc1b6436ea7

URL: 
https://github.com/llvm/llvm-project/commit/6f2fa9d312fcea2448706a8e410c7bc1b6436ea7
DIFF: 
https://github.com/llvm/llvm-project/commit/6f2fa9d312fcea2448706a8e410c7bc1b6436ea7.diff

LOG: [clang][NFC] Document NamedDecl::printName

Added: 


Modified: 
clang/include/clang/AST/Decl.h

Removed: 




diff  --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index 4dd5e14d36e1..c2511514fe72 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -265,6 +265,8 @@ class NamedDecl : public Decl {
   // FIXME: Deprecated, move clients to getName().
   std::string getNameAsString() const { return Name.getAsString(); }
 
+  /// Pretty-print the unqualified name of this declaration. Can be overloaded
+  /// by derived classes to provide a more user-friendly name when appropriate.
   virtual void printName(raw_ostream ) const;
 
   /// Get the actual, stored name of the declaration, which may be a special



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


[clang] bc29634 - [clang][NFC] Remove an old workaround for MSVC 2013

2020-08-05 Thread Bruno Ricci via cfe-commits

Author: Bruno Ricci
Date: 2020-08-05T13:54:37+01:00
New Revision: bc29634b93acf2e55c82dd906f0d9af196c66ff3

URL: 
https://github.com/llvm/llvm-project/commit/bc29634b93acf2e55c82dd906f0d9af196c66ff3
DIFF: 
https://github.com/llvm/llvm-project/commit/bc29634b93acf2e55c82dd906f0d9af196c66ff3.diff

LOG: [clang][NFC] Remove an old workaround for MSVC 2013

Added: 


Modified: 
clang/include/clang/AST/DeclTemplate.h

Removed: 




diff  --git a/clang/include/clang/AST/DeclTemplate.h 
b/clang/include/clang/AST/DeclTemplate.h
index e9c4879b41e8..4feb1d45251d 100644
--- a/clang/include/clang/AST/DeclTemplate.h
+++ b/clang/include/clang/AST/DeclTemplate.h
@@ -204,10 +204,6 @@ class TemplateParameterList final
  bool OmitTemplateKW = false) const;
   void print(raw_ostream , const ASTContext ,
  const PrintingPolicy , bool OmitTemplateKW = false) const;
-
-public:
-  // FIXME: workaround for MSVC 2013; remove when no longer needed
-  using FixedSizeStorageOwner = TrailingObjects::FixedSizeStorageOwner;
 };
 
 /// Stores a list of template parameters and the associated



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


[clang] 00b89f6 - [clang][NFC] Remove spurious +x flag on DeclTemplate.cpp and DeclTemplate.h

2020-08-05 Thread Bruno Ricci via cfe-commits

Author: Bruno Ricci
Date: 2020-08-05T13:54:30+01:00
New Revision: 00b89f66f988e9ec6f366ed46a51ace39fac07c8

URL: 
https://github.com/llvm/llvm-project/commit/00b89f66f988e9ec6f366ed46a51ace39fac07c8
DIFF: 
https://github.com/llvm/llvm-project/commit/00b89f66f988e9ec6f366ed46a51ace39fac07c8.diff

LOG: [clang][NFC] Remove spurious +x flag on DeclTemplate.cpp and DeclTemplate.h

Added: 


Modified: 
clang/include/clang/AST/DeclTemplate.h
clang/lib/AST/DeclTemplate.cpp

Removed: 




diff  --git a/clang/include/clang/AST/DeclTemplate.h 
b/clang/include/clang/AST/DeclTemplate.h
old mode 100755
new mode 100644

diff  --git a/clang/lib/AST/DeclTemplate.cpp b/clang/lib/AST/DeclTemplate.cpp
old mode 100755
new mode 100644



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


[clang] 38d3e75 - [clang] Use the location of the void parameters when complaining that only a single void parameter should be present.

2020-07-31 Thread Bruno Ricci via cfe-commits

Author: Jaydeep Chauhan
Date: 2020-07-31T20:36:58+01:00
New Revision: 38d3e7533279fd4bfefcd88eac7d3b64f804c53a

URL: 
https://github.com/llvm/llvm-project/commit/38d3e7533279fd4bfefcd88eac7d3b64f804c53a
DIFF: 
https://github.com/llvm/llvm-project/commit/38d3e7533279fd4bfefcd88eac7d3b64f804c53a.diff

LOG: [clang] Use the location of the void parameters when complaining that only 
a single void parameter should be present.

Fixes PR46417.

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

Reviewed By: aaron.ballman

Added: 
clang/test/SemaCXX/void-argument.cpp

Modified: 
clang/lib/Sema/SemaType.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index abf1d6450036..ff5223c0795e 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -5114,7 +5114,7 @@ static TypeSourceInfo 
*GetFullTypeForDeclarator(TypeProcessingState ,
 // is an incomplete type (C99 6.2.5p19) and function decls cannot
 // have parameters of incomplete type.
 if (FTI.NumParams != 1 || FTI.isVariadic) {
-  S.Diag(DeclType.Loc, diag::err_void_only_param);
+  S.Diag(FTI.Params[i].IdentLoc, diag::err_void_only_param);
   ParamTy = Context.IntTy;
   Param->setType(ParamTy);
 } else if (FTI.Params[i].Ident) {

diff  --git a/clang/test/SemaCXX/void-argument.cpp 
b/clang/test/SemaCXX/void-argument.cpp
new file mode 100644
index ..8354347f5559
--- /dev/null
+++ b/clang/test/SemaCXX/void-argument.cpp
@@ -0,0 +1,25 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+void fun(
+void a, // expected-error{{'void' must be the first and only parameter if 
specified}}
+double b,
+int c,
+void d, // expected-error{{'void' must be the first and only parameter if 
specified}}
+int e,
+void f) // expected-error{{'void' must be the first and only parameter if 
specified}}
+{}
+
+void foo(
+int a,
+void, // expected-error{{'void' must be the first and only parameter if 
specified}}
+int b);
+
+void bar(
+void, // expected-error{{'void' must be the first and only parameter if 
specified}}
+...);
+
+struct S {
+  S(
+  void,  // expected-error{{'void' must be the first and only parameter if 
specified}}
+  void); // expected-error{{'void' must be the first and only parameter if 
specified}}
+};



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


[clang] 517fe05 - [clang][NFC] clang-format fix after eb10b065f2a870b425dcc2040b9955e0eee464b4

2020-07-29 Thread Bruno Ricci via cfe-commits

Author: Bruno Ricci
Date: 2020-07-29T14:55:16+01:00
New Revision: 517fe058d42a1f937e14de4b61a5ac2ad326c850

URL: 
https://github.com/llvm/llvm-project/commit/517fe058d42a1f937e14de4b61a5ac2ad326c850
DIFF: 
https://github.com/llvm/llvm-project/commit/517fe058d42a1f937e14de4b61a5ac2ad326c850.diff

LOG: [clang][NFC] clang-format fix after 
eb10b065f2a870b425dcc2040b9955e0eee464b4

Added: 


Modified: 
clang/lib/Sema/SemaDeclAttr.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index 58602a4c58d4..d46c791b0e3a 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -3640,15 +3640,15 @@ static void handleTransparentUnionAttr(Sema , Decl 
*D, const ParsedAttr ) {
 S.Context.getTypeAlign(FieldType) > FirstAlign) {
   // Warn if we drop the attribute.
   bool isSize = S.Context.getTypeSize(FieldType) != FirstSize;
-  unsigned FieldBits = isSize? S.Context.getTypeSize(FieldType)
- : S.Context.getTypeAlign(FieldType);
+  unsigned FieldBits = isSize ? S.Context.getTypeSize(FieldType)
+  : S.Context.getTypeAlign(FieldType);
   S.Diag(Field->getLocation(),
  diag::warn_transparent_union_attribute_field_size_align)
   << isSize << *Field << FieldBits;
-  unsigned FirstBits = isSize? FirstSize : FirstAlign;
+  unsigned FirstBits = isSize ? FirstSize : FirstAlign;
   S.Diag(FirstField->getLocation(),
  diag::note_transparent_union_first_field_size_align)
-<< isSize << FirstBits;
+  << isSize << FirstBits;
   return;
 }
   }



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


[clang] 1ae63b4 - [clang][NFC] Pass the ASTContext to CXXRecordDecl::setCaptures

2020-07-29 Thread Bruno Ricci via cfe-commits

Author: Bruno Ricci
Date: 2020-07-29T14:55:15+01:00
New Revision: 1ae63b4179c222431cd6a4b2397abceaa5bc3d30

URL: 
https://github.com/llvm/llvm-project/commit/1ae63b4179c222431cd6a4b2397abceaa5bc3d30
DIFF: 
https://github.com/llvm/llvm-project/commit/1ae63b4179c222431cd6a4b2397abceaa5bc3d30.diff

LOG: [clang][NFC] Pass the ASTContext to CXXRecordDecl::setCaptures

In general Decl::getASTContext() is relatively expensive and here the changes
are non-invasive. NFC.

Added: 


Modified: 
clang/include/clang/AST/DeclCXX.h
clang/lib/AST/ASTImporter.cpp
clang/lib/AST/DeclCXX.cpp
clang/lib/Sema/SemaLambda.cpp

Removed: 




diff  --git a/clang/include/clang/AST/DeclCXX.h 
b/clang/include/clang/AST/DeclCXX.h
index 2b8d7e879a0a..20f058b87e7f 100644
--- a/clang/include/clang/AST/DeclCXX.h
+++ b/clang/include/clang/AST/DeclCXX.h
@@ -1025,7 +1025,7 @@ class CXXRecordDecl : public RecordDecl {
   }
 
   /// Set the captures for this lambda closure type.
-  void setCaptures(ArrayRef Captures);
+  void setCaptures(ASTContext , ArrayRef Captures);
 
   /// For a closure type, retrieve the mapping from captured
   /// variables and \c this to the non-static data members that store the

diff  --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index e0bca8f08bb4..12dcd14c06bf 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -1900,7 +1900,8 @@ Error ASTNodeImporter::ImportDefinition(
   else
 return ToCaptureOrErr.takeError();
 }
-cast(To)->setCaptures(ToCaptures);
+cast(To)->setCaptures(Importer.getToContext(),
+ ToCaptures);
   }
 
   Error Result = ImportDeclContext(From, /*ForceImport=*/true);

diff  --git a/clang/lib/AST/DeclCXX.cpp b/clang/lib/AST/DeclCXX.cpp
index 6f1fd2f14ede..59ae5cb300f7 100644
--- a/clang/lib/AST/DeclCXX.cpp
+++ b/clang/lib/AST/DeclCXX.cpp
@@ -1383,8 +1383,8 @@ void 
CXXRecordDecl::finishedDefaultedOrDeletedMember(CXXMethodDecl *D) {
 data().DeclaredNonTrivialSpecialMembers |= SMKind;
 }
 
-void CXXRecordDecl::setCaptures(ArrayRef Captures) {
-  ASTContext  = getASTContext();
+void CXXRecordDecl::setCaptures(ASTContext ,
+ArrayRef Captures) {
   CXXRecordDecl::LambdaDefinitionData  = getLambdaData();
 
   // Copy captures.

diff  --git a/clang/lib/Sema/SemaLambda.cpp b/clang/lib/Sema/SemaLambda.cpp
index dc74f6e2f7dc..c9f2854f7acc 100644
--- a/clang/lib/Sema/SemaLambda.cpp
+++ b/clang/lib/Sema/SemaLambda.cpp
@@ -1624,8 +1624,9 @@ FieldDecl *Sema::BuildCaptureField(RecordDecl *RD,
 
   // Build the non-static data member.
   FieldDecl *Field =
-  FieldDecl::Create(Context, RD, Loc, Loc, nullptr, FieldType, TSI, 
nullptr,
-false, ICIS_NoInit);
+  FieldDecl::Create(Context, RD, /*StartLoc=*/Loc, /*IdLoc=*/Loc,
+/*Id=*/nullptr, FieldType, TSI, /*BW=*/nullptr,
+/*Mutable=*/false, ICIS_NoInit);
   // If the variable being captured has an invalid type, mark the class as
   // invalid as well.
   if (!FieldType->isDependentType()) {
@@ -1785,7 +1786,7 @@ ExprResult Sema::BuildLambdaExpr(SourceLocation StartLoc, 
SourceLocation EndLoc,
 CUDACheckLambdaCapture(CallOperator, From);
 }
 
-Class->setCaptures(Captures);
+Class->setCaptures(Context, Captures);
 
 // C++11 [expr.prim.lambda]p6:
 //   The closure type for a lambda-expression with no lambda-capture



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


[clang] 984cf99 - [clang][NFC] Add some documentation about the use of NamedDecl::getDeclName in diagnostics.

2020-07-28 Thread Bruno Ricci via cfe-commits

Author: Bruno Ricci
Date: 2020-07-28T15:39:17+01:00
New Revision: 984cf99055a292b3afe4535c013d38914a3da880

URL: 
https://github.com/llvm/llvm-project/commit/984cf99055a292b3afe4535c013d38914a3da880
DIFF: 
https://github.com/llvm/llvm-project/commit/984cf99055a292b3afe4535c013d38914a3da880.diff

LOG: [clang][NFC] Add some documentation about the use of 
NamedDecl::getDeclName in diagnostics.

As explained in eb10b065f2a870b425dcc2040b9955e0eee464b4, sending a NamedDecl*
in a diagnostic should generally be preferred over sending the DeclarationName
from getDeclName(). Let's document that.

Added: 


Modified: 
clang/include/clang/AST/Decl.h

Removed: 




diff  --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index 28faa2c1fc78..4dd5e14d36e1 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -269,6 +269,19 @@ class NamedDecl : public Decl {
 
   /// Get the actual, stored name of the declaration, which may be a special
   /// name.
+  ///
+  /// Note that generally in diagnostics, the non-null \p NamedDecl* itself
+  /// should be sent into the diagnostic instead of using the result of
+  /// \p getDeclName().
+  ///
+  /// A \p DeclarationName in a diagnostic will just be streamed to the output,
+  /// which will directly result in a call to \p DeclarationName::print.
+  ///
+  /// A \p NamedDecl* in a diagnostic will also ultimately result in a call to
+  /// \p DeclarationName::print, but with two customisation points along the
+  /// way (\p getNameForDiagnostic and \p printName). These are used to print
+  /// the template arguments if any, and to provide a user-friendly name for
+  /// some entities (such as unnamed variables and anonymous records).
   DeclarationName getDeclName() const { return Name; }
 
   /// Set the name of this declaration.



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


[clang] b81fd5a - [clang-format][NFC] Fix a Wdocumentation warning in TokenAnnotator.cpp

2020-07-28 Thread Bruno Ricci via cfe-commits

Author: Bruno Ricci
Date: 2020-07-28T10:58:52+01:00
New Revision: b81fd5aeecd8047ef62348b67cab2cf9a1577d8e

URL: 
https://github.com/llvm/llvm-project/commit/b81fd5aeecd8047ef62348b67cab2cf9a1577d8e
DIFF: 
https://github.com/llvm/llvm-project/commit/b81fd5aeecd8047ef62348b67cab2cf9a1577d8e.diff

LOG: [clang-format][NFC] Fix a Wdocumentation warning in TokenAnnotator.cpp

Added: 


Modified: 
clang/lib/Format/TokenAnnotator.cpp

Removed: 




diff  --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index b19fc34bcc80..6cbaf8a30812 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -27,7 +27,7 @@ namespace format {
 namespace {
 
 /// Returns \c true if the token can be used as an identifier in
-/// an Objective-C \c @selector, \c false otherwise.
+/// an Objective-C \c \@selector, \c false otherwise.
 ///
 /// Because getFormattingLangOpts() always lexes source code as
 /// Objective-C++, C++ keywords like \c new and \c delete are



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


[clang] eb10b06 - [clang] Pass the NamedDecl* instead of the DeclarationName into many diagnostics.

2020-07-28 Thread Bruno Ricci via cfe-commits

Author: Bruno Ricci
Date: 2020-07-28T10:30:35+01:00
New Revision: eb10b065f2a870b425dcc2040b9955e0eee464b4

URL: 
https://github.com/llvm/llvm-project/commit/eb10b065f2a870b425dcc2040b9955e0eee464b4
DIFF: 
https://github.com/llvm/llvm-project/commit/eb10b065f2a870b425dcc2040b9955e0eee464b4.diff

LOG: [clang] Pass the NamedDecl* instead of the DeclarationName into many 
diagnostics.

Background:
---
There are two related argument types which can be sent into a diagnostic to
display the name of an entity: DeclarationName (ak_declarationname) or
NamedDecl* (ak_nameddecl) (there is also ak_identifierinfo for
IdentifierInfo*, but we are not concerned with it here).

A DeclarationName in a diagnostic will just be streamed to the output,
which will directly result in a call to DeclarationName::print.

A NamedDecl* in a diagnostic will also ultimately result in a call to
DeclarationName::print, but with two customisation points along the way:

The first customisation point is NamedDecl::getNameForDiagnostic which is
overloaded by FunctionDecl, ClassTemplateSpecializationDecl and
VarTemplateSpecializationDecl to print the template arguments, if any.

The second customisation point is NamedDecl::printName. By default it just
streams the stored DeclarationName into the output but it can be customised
to provide a user-friendly name for an entity. It is currently overloaded by
DecompositionDecl and MSGuidDecl.

What this patch does:
-
For many diagnostics a DeclarationName is used instead of the NamedDecl*.
This bypasses the two customisation points mentioned above. This patches fix
this for diagnostics in Sema.cpp, SemaCast.cpp, SemaChecking.cpp, SemaDecl.cpp,
SemaDeclAttr.cpp, SemaDecl.cpp, SemaOverload.cpp and SemaStmt.cpp.

I have only modified diagnostics where I could construct a test-case which
demonstrates that the change is appropriate (either with this patch or the next
one).

Reviewed By: erichkeane, aaron.ballman

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

Added: 


Modified: 
clang/lib/Sema/Sema.cpp
clang/lib/Sema/SemaCast.cpp
clang/lib/Sema/SemaChecking.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaDeclAttr.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaOverload.cpp
clang/lib/Sema/SemaStmt.cpp
clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.noreturn/p1.cpp
clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct/p3.cpp
clang/test/CXX/stmt.stmt/stmt.iter/stmt.ranged/p1.cpp
clang/test/CXX/temp/temp.param/p15-cxx0x.cpp
clang/test/Modules/module-private.cpp
clang/test/SemaCXX/array-bounds.cpp
clang/test/SemaCXX/attr-unused.cpp
clang/test/SemaCXX/cxx1y-variable-templates_in_class.cpp
clang/test/SemaCXX/default2.cpp
clang/test/SemaCXX/incomplete-call.cpp
clang/test/SemaCXX/references.cpp
clang/test/SemaCXX/return-void.cpp
clang/test/SemaCXX/warn-func-not-needed.cpp
clang/test/SemaCXX/warn-large-by-value-copy.cpp
clang/test/SemaCXX/warn-member-not-needed.cpp
clang/test/SemaCXX/warn-pure-virtual-call-from-ctor-dtor.cpp
clang/test/SemaCXX/warn-pure-virtual-kext.cpp
clang/test/SemaCXX/warn-unused-filescoped.cpp
clang/test/SemaCXX/warn-variable-not-needed.cpp

Removed: 




diff  --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index 9c8f3fdcda4a..7415d0d0766b 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -1197,7 +1197,7 @@ void Sema::ActOnEndOfTranslationUnit() {
 if (DiagD->isReferenced()) {
   if (isa(DiagD))
 Diag(DiagD->getLocation(), diag::warn_unneeded_member_function)
-  << DiagD->getDeclName();
+<< DiagD;
   else {
 if (FD->getStorageClass() == SC_Static &&
 !FD->isInlineSpecified() &&
@@ -1205,20 +1205,20 @@ void Sema::ActOnEndOfTranslationUnit() {
SourceMgr.getExpansionLoc(FD->getLocation(
   Diag(DiagD->getLocation(),
diag::warn_unneeded_static_internal_decl)
-  << DiagD->getDeclName();
+  << DiagD;
 else
   Diag(DiagD->getLocation(), diag::warn_unneeded_internal_decl)
-   << /*function*/0 << DiagD->getDeclName();
+  << /*function*/ 0 << DiagD;
   }
 } else {
   if (FD->getDescribedFunctionTemplate())
 Diag(DiagD->getLocation(), diag::warn_unused_template)
-  << /*function*/0 << DiagD->getDeclName();
+<< /*function*/ 0 << DiagD;
   else
-Diag(DiagD->getLocation(),
- isa(DiagD) ? diag::warn_unused_member_function
+Diag(DiagD->getLocation(), isa(DiagD)
+   ? diag::warn_unused_member_function
: diag::warn_unused_function)

[clang] f5acd11 - [clang-format][NFC] Be more careful about the layout of FormatToken.

2020-07-28 Thread Bruno Ricci via cfe-commits

Author: Bruno Ricci
Date: 2020-07-28T10:30:28+01:00
New Revision: f5acd11d2c0ea228452aa5ed3abbc2c502009d56

URL: 
https://github.com/llvm/llvm-project/commit/f5acd11d2c0ea228452aa5ed3abbc2c502009d56
DIFF: 
https://github.com/llvm/llvm-project/commit/f5acd11d2c0ea228452aa5ed3abbc2c502009d56.diff

LOG: [clang-format][NFC] Be more careful about the layout of FormatToken.

The underlying ABI forces FormatToken to have a lot of padding.

Currently (on x86-64 linux) `sizeof(FormatToken) == 288`. After this patch
`sizeof(FormatToken) == 232`.

No functional changes.

Reviewed By: MyDeveloperDay

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

Added: 


Modified: 
clang/lib/Format/ContinuationIndenter.cpp
clang/lib/Format/Format.cpp
clang/lib/Format/FormatToken.cpp
clang/lib/Format/FormatToken.h
clang/lib/Format/TokenAnnotator.cpp
clang/lib/Format/UnwrappedLineFormatter.cpp
clang/lib/Format/UnwrappedLineParser.cpp
clang/lib/Format/WhitespaceManager.cpp

Removed: 




diff  --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index b1497651a8fe..f3202bcb5bc1 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -284,7 +284,7 @@ bool ContinuationIndenter::canBreak(const LineState ) 
{
   // The opening "{" of a braced list has to be on the same line as the first
   // element if it is nested in another braced init list or function call.
   if (!Current.MustBreakBefore && Previous.is(tok::l_brace) &&
-  Previous.isNot(TT_DictLiteral) && Previous.BlockKind == BK_BracedInit &&
+  Previous.isNot(TT_DictLiteral) && Previous.is(BK_BracedInit) &&
   Previous.Previous &&
   Previous.Previous->isOneOf(tok::l_brace, tok::l_paren, tok::comma))
 return false;
@@ -501,7 +501,7 @@ bool ContinuationIndenter::mustBreak(const LineState 
) {
   // The following could be precomputed as they do not depend on the state.
   // However, as they should take effect only if the UnwrappedLine does not fit
   // into the ColumnLimit, they are checked here in the ContinuationIndenter.
-  if (Style.ColumnLimit != 0 && Previous.BlockKind == BK_Block &&
+  if (Style.ColumnLimit != 0 && Previous.is(BK_Block) &&
   Previous.is(tok::l_brace) && !Current.isOneOf(tok::r_brace, 
tok::comment))
 return true;
 
@@ -627,7 +627,7 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState 
, bool DryRun,
   // opening parenthesis. Don't break if it doesn't conserve columns.
   if (Style.AlignAfterOpenBracket == FormatStyle::BAS_AlwaysBreak &&
   (Previous.isOneOf(tok::l_paren, TT_TemplateOpener, tok::l_square) ||
-   (Previous.is(tok::l_brace) && Previous.BlockKind != BK_Block &&
+   (Previous.is(tok::l_brace) && Previous.isNot(BK_Block) &&
 Style.Cpp11BracedListStyle)) &&
   State.Column > getNewLineColumn(State) &&
   (!Previous.Previous || !Previous.Previous->isOneOf(
@@ -648,7 +648,7 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState 
, bool DryRun,
   if (Style.AlignAfterOpenBracket != FormatStyle::BAS_DontAlign &&
   !State.Stack.back().IsCSharpGenericTypeConstraint &&
   Previous.opensScope() && Previous.isNot(TT_ObjCMethodExpr) &&
-  (Current.isNot(TT_LineComment) || Previous.BlockKind == BK_BracedInit)) {
+  (Current.isNot(TT_LineComment) || Previous.is(BK_BracedInit))) {
 State.Stack.back().Indent = State.Column + Spaces;
 State.Stack.back().IsAligned = true;
   }
@@ -972,7 +972,7 @@ unsigned ContinuationIndenter::getNewLineColumn(const 
LineState ) {
 return (Style.IndentWidth * State.Line->First->IndentLevel) +
Style.IndentWidth;
 
-  if (NextNonComment->is(tok::l_brace) && NextNonComment->BlockKind == 
BK_Block)
+  if (NextNonComment->is(tok::l_brace) && NextNonComment->is(BK_Block))
 return Current.NestingLevel == 0 ? State.FirstIndent
  : State.Stack.back().Indent;
   if ((Current.isOneOf(tok::r_brace, tok::r_square) ||
@@ -982,8 +982,7 @@ unsigned ContinuationIndenter::getNewLineColumn(const 
LineState ) {
   State.Stack.size() > 1) {
 if (Current.closesBlockOrBlockTypeList(Style))
   return State.Stack[State.Stack.size() - 2].NestedBlockIndent;
-if (Current.MatchingParen &&
-Current.MatchingParen->BlockKind == BK_BracedInit)
+if (Current.MatchingParen && Current.MatchingParen->is(BK_BracedInit))
   return State.Stack[State.Stack.size() - 2].LastSpace;
 return State.FirstIndent;
   }
@@ -1417,7 +1416,7 @@ void 
ContinuationIndenter::moveStatePastScopeOpener(LineState ,
   State.Stack.back().IsCSharpGenericTypeConstraint)
 return;
 
-  if (Current.MatchingParen && Current.BlockKind == BK_Block) {
+  if (Current.MatchingParen && Current.is(BK_Block)) {
 moveStateToNewBlock(State);
 return;
   }
@@ -1486,9 +1485,8 @@ void 

[clang] a2f83d5 - [clang][NFC] Add tests for the use of NamedDecl::getDeclName in the unused/unneeded diagnostics.

2020-07-26 Thread Bruno Ricci via cfe-commits

Author: Bruno Ricci
Date: 2020-07-26T17:20:56+01:00
New Revision: a2f83d5a07daf7a9b717fff8916c44cd7cc1c678

URL: 
https://github.com/llvm/llvm-project/commit/a2f83d5a07daf7a9b717fff8916c44cd7cc1c678
DIFF: 
https://github.com/llvm/llvm-project/commit/a2f83d5a07daf7a9b717fff8916c44cd7cc1c678.diff

LOG: [clang][NFC] Add tests for the use of NamedDecl::getDeclName in the 
unused/unneeded diagnostics.

Added: 


Modified: 
clang/test/SemaCXX/warn-func-not-needed.cpp
clang/test/SemaCXX/warn-member-not-needed.cpp
clang/test/SemaCXX/warn-unused-filescoped.cpp
clang/test/SemaCXX/warn-variable-not-needed.cpp

Removed: 




diff  --git a/clang/test/SemaCXX/warn-func-not-needed.cpp 
b/clang/test/SemaCXX/warn-func-not-needed.cpp
index 65721f44f570..5040aaad9460 100644
--- a/clang/test/SemaCXX/warn-func-not-needed.cpp
+++ b/clang/test/SemaCXX/warn-func-not-needed.cpp
@@ -1,13 +1,23 @@
 // RUN: %clang_cc1 -fsyntax-only -verify -Wall %s
 
 namespace test1 {
-  static void f() {} // expected-warning {{is not needed and will not be 
emitted}}
-  static void f();
-  template 
-  void foo() {
-f();
-  }
+static void f() {} // expected-warning {{function 'f' is not needed and will 
not be emitted}}
+static void f();
+template 
+void foo() {
+  f();
+}
+}
+
+namespace test1_template {
+template  static void f() {}
+template <> void f() {} // expected-warning {{function 'f' is not needed 
and will not be emitted}}
+template 
+void foo() {
+  f();
+  f();
 }
+} // namespace test1_template
 
 namespace test2 {
   static void f() {}

diff  --git a/clang/test/SemaCXX/warn-member-not-needed.cpp 
b/clang/test/SemaCXX/warn-member-not-needed.cpp
index 61bb3488c611..95241f4f7fee 100644
--- a/clang/test/SemaCXX/warn-member-not-needed.cpp
+++ b/clang/test/SemaCXX/warn-member-not-needed.cpp
@@ -1,11 +1,19 @@
-// RUN: %clang_cc1 -fsyntax-only -verify -Wunneeded-member-function %s
+// RUN: %clang_cc1 -fsyntax-only -verify -Wunneeded-member-function 
-Wno-unused-template %s
 
 namespace {
   class A {
-void g() {} // expected-warning {{is not needed and will not be emitted}}
+void g() {} // expected-warning {{member function 'g' is not needed and 
will not be emitted}}
+template  void gt(T) {}
+template <> void gt(int) {} // expected-warning {{member function 
'gt' is not needed and will not be emitted}}
+template <> void gt(float) {}// expected-warning {{member function 
'gt' is not needed and will not be emitted}}
+
 template 
 void foo() {
   g();
+  gt(0);
+  gt(0.0f);
+  gt(0.0);
 }
   };
+  template void A::gt(double); // no-warning
 }

diff  --git a/clang/test/SemaCXX/warn-unused-filescoped.cpp 
b/clang/test/SemaCXX/warn-unused-filescoped.cpp
index 7ea398feb2b1..056543d5eeb0 100644
--- a/clang/test/SemaCXX/warn-unused-filescoped.cpp
+++ b/clang/test/SemaCXX/warn-unused-filescoped.cpp
@@ -1,14 +1,15 @@
-// RUN: %clang_cc1 -fsyntax-only -verify -Wunused -Wunused-template 
-Wunused-member-function -Wno-unused-local-typedefs -Wno-c++11-extensions 
-std=c++98 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -Wunused -Wunused-template 
-Wunused-member-function -Wno-unused-local-typedefs \
+// RUN:-Wno-c++11-extensions -Wno-c++14-extensions -std=c++98 %s
 // RUN: %clang_cc1 -fsyntax-only -verify -Wunused -Wunused-template 
-Wunused-member-function -Wno-unused-local-typedefs -std=c++14 %s
 
 #ifdef HEADER
 
-static void headerstatic() {}  // expected-warning{{unused}}
+static void headerstatic() {} // expected-warning{{unused function 
'headerstatic'}}
 static inline void headerstaticinline() {}
 
 namespace {
-  void headeranon() {}  // expected-warning{{unused}}
-  inline void headerinlineanon() {}
+void headeranon() {} // expected-warning{{unused function 'headeranon'}}
+inline void headerinlineanon() {}
 }
 
 namespace test7
@@ -43,31 +44,31 @@ namespace pr19713 {
 #define HEADER
 #include "warn-unused-filescoped.cpp"
 
-static void f1(); // expected-warning{{unused}}
+static void f1(); // expected-warning{{unused function 'f1'}}
 
 namespace {
-  void f2();  // expected-warning{{unused}}
+void f2(); // expected-warning{{unused function 'f2'}}
 
-  void f3() { }  // expected-warning{{unused}}
+void f3() {} // expected-warning{{unused function 'f3'}}
 
-  struct S {
-void m1() { }  // expected-warning{{unused}}
-void m2();  // expected-warning{{unused}}
-void m3();
-S(const S&);
-void operator=(const S&);
-  };
+struct S {
+  void m1() {} // expected-warning{{unused member function 'm1'}}
+  void m2();   // expected-warning{{unused member function 'm2'}}
+  void m3();
+  S(const S &);
+  void operator=(const S &);
+};
 
   template 
   struct TS {
 void m();
   };
-  template <> void TS::m() { }  // expected-warning{{unused}}
+  template <> void TS::m() {} // expected-warning{{unused member function 
'm'}}
 
   template 
-  void tf() { }  // 

[clang] b0512ee - [clang][NFC] Add a test for __attribute__((flag_enum)) with an unnamed enumeration.

2020-07-26 Thread Bruno Ricci via cfe-commits

Author: Bruno Ricci
Date: 2020-07-26T17:24:43+01:00
New Revision: b0512eed1e9dc03dba4ef8cccee73c13d3487565

URL: 
https://github.com/llvm/llvm-project/commit/b0512eed1e9dc03dba4ef8cccee73c13d3487565
DIFF: 
https://github.com/llvm/llvm-project/commit/b0512eed1e9dc03dba4ef8cccee73c13d3487565.diff

LOG: [clang][NFC] Add a test for __attribute__((flag_enum)) with an unnamed 
enumeration.

Added: 


Modified: 
clang/test/Sema/attr-flag-enum.c

Removed: 




diff  --git a/clang/test/Sema/attr-flag-enum.c 
b/clang/test/Sema/attr-flag-enum.c
index ae3e3ad5ab99..467afd950973 100644
--- a/clang/test/Sema/attr-flag-enum.c
+++ b/clang/test/Sema/attr-flag-enum.c
@@ -6,6 +6,10 @@ enum __attribute__((flag_enum)) flag {
   ec = 0x8,
 };
 
+enum __attribute__((flag_enum)) {
+  g = 0x7,  // expected-warning {{enumeration value 'g' is out of range of 
flags in enumeration type ''}}
+};
+
 enum __attribute__((flag_enum)) flag2 {
   ga = 0x1,
   gb = 0x4,



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


[clang] ca9bfc2 - [clang][NFC] Remove spurious +x flag on SemaConcept.cpp

2020-07-26 Thread Bruno Ricci via cfe-commits

Author: Bruno Ricci
Date: 2020-07-26T17:10:59+01:00
New Revision: ca9bfc20f48c82a9f223ec814697714a16d1a22d

URL: 
https://github.com/llvm/llvm-project/commit/ca9bfc20f48c82a9f223ec814697714a16d1a22d
DIFF: 
https://github.com/llvm/llvm-project/commit/ca9bfc20f48c82a9f223ec814697714a16d1a22d.diff

LOG: [clang][NFC] Remove spurious +x flag on SemaConcept.cpp

Added: 


Modified: 
clang/lib/Sema/SemaConcept.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp
old mode 100755
new mode 100644



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


[clang] 7b5bddf - [clang] Partially revert "Disable a few formatting options for test/"

2020-07-21 Thread Bruno Ricci via cfe-commits

Author: Bruno Ricci
Date: 2020-07-21T14:53:37+01:00
New Revision: 7b5bddfd034ef42c92c67731743399df844d5f43

URL: 
https://github.com/llvm/llvm-project/commit/7b5bddfd034ef42c92c67731743399df844d5f43
DIFF: 
https://github.com/llvm/llvm-project/commit/7b5bddfd034ef42c92c67731743399df844d5f43.diff

LOG: [clang] Partially revert "Disable a few formatting options for test/"

The changes to "AlignTrailingComments" and "CommentPragmas" did not
result in what I expected (just leave the special comments alone).

Instead now the following:
  void test() {
int i; // expected-error
   // expected-warning
  }

is formatted into:
  void test() {
int i; // expected-error
// expected-warning
  }

which is even worse.

Added: 


Modified: 
clang/test/.clang-format

Removed: 




diff  --git a/clang/test/.clang-format b/clang/test/.clang-format
index a6176c2e0013..f7fb083d1055 100644
--- a/clang/test/.clang-format
+++ b/clang/test/.clang-format
@@ -1,5 +1,3 @@
 BasedOnStyle: LLVM
 ColumnLimit: 0
-AlignTrailingComments: false
-CommentPragmas: "(^ ?CHECK|^ ?expected-)"
 AlwaysBreakTemplateDeclarations: No



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


[clang] 13316a7 - [clang] Disable a few formatting options for test/

2020-07-19 Thread Bruno Ricci via cfe-commits

Author: Bruno Ricci
Date: 2020-07-19T17:07:24+01:00
New Revision: 13316a77053514be552a0dad932e3455413b4f82

URL: 
https://github.com/llvm/llvm-project/commit/13316a77053514be552a0dad932e3455413b4f82
DIFF: 
https://github.com/llvm/llvm-project/commit/13316a77053514be552a0dad932e3455413b4f82.diff

LOG: [clang] Disable a few formatting options for test/

Hopefully this will make the bot a little less noisy. Rationale for each:

AlignTrailingComments: We don't want to force-align the various expected-error
   and friends.

CommentPragmas:   Tell clang-format to leave the "// CHECK:" and the
  "// expected-" alone.

AlwaysBreakTemplateDeclarations: Templates in tests often have no break between
 the template-head and the declaration.

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

Added: 


Modified: 
clang/test/.clang-format

Removed: 




diff  --git a/clang/test/.clang-format b/clang/test/.clang-format
index 4799b66f3e9a..a6176c2e0013 100644
--- a/clang/test/.clang-format
+++ b/clang/test/.clang-format
@@ -1,2 +1,5 @@
 BasedOnStyle: LLVM
 ColumnLimit: 0
+AlignTrailingComments: false
+CommentPragmas: "(^ ?CHECK|^ ?expected-)"
+AlwaysBreakTemplateDeclarations: No



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


[clang] 89ff9bf - [clang] Fix the warning for a non-void consteval function without a return value to actually say "consteval".

2020-07-19 Thread Bruno Ricci via cfe-commits

Author: Bruno Ricci
Date: 2020-07-19T17:08:17+01:00
New Revision: 89ff9bf061b4985d11cd4785958d8f8156d10f5d

URL: 
https://github.com/llvm/llvm-project/commit/89ff9bf061b4985d11cd4785958d8f8156d10f5d
DIFF: 
https://github.com/llvm/llvm-project/commit/89ff9bf061b4985d11cd4785958d8f8156d10f5d.diff

LOG: [clang] Fix the warning for a non-void consteval function without a return 
value to actually say "consteval".

This warning was modified in 796ed03b8412 to use the term "consteval"
for consteval functions. However the warning has never worked as
intended since the diagnostic's arguments are used in the wrong order.

This was unfortunately missed by 796ed03b8412 since no test did exercise
this specific warning.

Additionally send the NamedDecl* into the diagnostic instead of just the
IdentifierInfo* to correctly work with special names and template
arguments.

Added: 


Modified: 
clang/lib/Sema/SemaStmt.cpp
clang/test/SemaCXX/constant-expression-cxx11.cpp
clang/test/SemaCXX/consteval-return-void.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index 73f3183c163f..948c187804dc 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -3766,25 +3766,26 @@ StmtResult Sema::BuildReturnStmt(SourceLocation 
ReturnLoc, Expr *RetValExp) {
   } else if (!RetValExp && !HasDependentReturnType) {
 FunctionDecl *FD = getCurFunctionDecl();
 
-unsigned DiagID;
 if (getLangOpts().CPlusPlus11 && FD && FD->isConstexpr()) {
   // C++11 [stmt.return]p2
-  DiagID = diag::err_constexpr_return_missing_expr;
+  Diag(ReturnLoc, diag::err_constexpr_return_missing_expr)
+  << FD << FD->isConsteval();
   FD->setInvalidDecl();
-} else if (getLangOpts().C99) {
-  // C99 6.8.6.4p1 (ext_ since GCC warns)
-  DiagID = diag::ext_return_missing_expr;
 } else {
+  // C99 6.8.6.4p1 (ext_ since GCC warns)
   // C90 6.6.6.4p4
-  DiagID = diag::warn_return_missing_expr;
+  unsigned DiagID = getLangOpts().C99 ? diag::ext_return_missing_expr
+  : diag::warn_return_missing_expr;
+  // Note that at this point one of getCurFunctionDecl() or
+  // getCurMethodDecl() must be non-null (see above).
+  assert((getCurFunctionDecl() || getCurMethodDecl()) &&
+ "Not in a FunctionDecl or ObjCMethodDecl?");
+  bool IsMethod = FD == nullptr;
+  const NamedDecl *ND =
+  IsMethod ? cast(getCurMethodDecl()) : cast(FD);
+  Diag(ReturnLoc, DiagID) << ND << IsMethod;
 }
 
-if (FD)
-  Diag(ReturnLoc, DiagID)
-  << FD->getIdentifier() << 0 /*fn*/ << FD->isConsteval();
-else
-  Diag(ReturnLoc, DiagID) << getCurMethodDecl()->getDeclName() << 
1/*meth*/;
-
 Result = ReturnStmt::Create(Context, ReturnLoc, /* RetExpr=*/nullptr,
 /* NRVOCandidate=*/nullptr);
   } else {

diff  --git a/clang/test/SemaCXX/constant-expression-cxx11.cpp 
b/clang/test/SemaCXX/constant-expression-cxx11.cpp
index 7ff260c37c69..eac0256c4fb2 100644
--- a/clang/test/SemaCXX/constant-expression-cxx11.cpp
+++ b/clang/test/SemaCXX/constant-expression-cxx11.cpp
@@ -2171,7 +2171,7 @@ namespace PR21859 {
   template  constexpr int FunT1() { return; } // expected-error 
{{non-void constexpr function 'FunT1' should return a value}}
   template  constexpr int FunT2() { return 0; }
   template <> constexpr int FunT2() { return 0; }
-  template <> constexpr int FunT2() { return; } // expected-error 
{{non-void constexpr function 'FunT2' should return a value}}
+  template <> constexpr int FunT2() { return; } // expected-error 
{{non-void constexpr function 'FunT2' should return a value}}
 }
 
 struct InvalidRedef {

diff  --git a/clang/test/SemaCXX/consteval-return-void.cpp 
b/clang/test/SemaCXX/consteval-return-void.cpp
index a5207f41bf2c..39e1418306f5 100644
--- a/clang/test/SemaCXX/consteval-return-void.cpp
+++ b/clang/test/SemaCXX/consteval-return-void.cpp
@@ -1,10 +1,20 @@
 // RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s
 
-consteval int Fun() { return; } // expected-error {{non-void constexpr 
function 'Fun' should return a value}}
+consteval int Fun() { return; } // expected-error {{non-void consteval 
function 'Fun' should return a value}}
 
-// FIXME: The diagnostic is wrong; should be "consteval".
-
-template  consteval int FunT1() { return; } // expected-error 
{{non-void constexpr function 'FunT1' should return a value}}
+template  consteval int FunT1() { return; } // expected-error 
{{non-void consteval function 'FunT1' should return a value}}
 template  consteval int FunT2() { return 0; }
 template <> consteval int FunT2() { return 0; }
-template <> consteval int FunT2() { return; } // expected-error 
{{non-void constexpr function 'FunT2' should return a value}}
+template <> consteval int FunT2() { return; } // 

[clang] be8e5fe - [clang][NFC] Tests showing the problems with some uses of NamedDecl::getDeclName in diagnostics, SemaExpr.cpp part

2020-07-18 Thread Bruno Ricci via cfe-commits

Author: Bruno Ricci
Date: 2020-07-18T20:39:16+01:00
New Revision: be8e5fee91b44522056f1e780cdc861427f8738f

URL: 
https://github.com/llvm/llvm-project/commit/be8e5fee91b44522056f1e780cdc861427f8738f
DIFF: 
https://github.com/llvm/llvm-project/commit/be8e5fee91b44522056f1e780cdc861427f8738f.diff

LOG: [clang][NFC] Tests showing the problems with some uses of 
NamedDecl::getDeclName in diagnostics, SemaExpr.cpp part

Added: 


Modified: 
clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p7.cpp
clang/test/SemaCXX/attr-unused.cpp
clang/test/SemaCXX/default2.cpp
clang/test/SemaCXX/incomplete-call.cpp
clang/test/SemaCXX/lambda-expressions.cpp

Removed: 




diff  --git a/clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p7.cpp 
b/clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p7.cpp
index af2e7cf09ceb..52986faa4e85 100644
--- a/clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p7.cpp
+++ b/clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p7.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -std=c++17 -fsyntax-only -verify %s
 
 void h() {
   int i1 = 0;
@@ -16,4 +16,16 @@ void h() {
   const int i4 = 0;
   extern void h4(int x = sizeof(i4)); // ok, not odr-use
   extern void h5(int x = decltype(i4 + 4)()); // ok, not odr-use
+
+  union {
+int i5;
+  };
+
+  extern void h6(int = i5);
+  // expected-error@-1 {{default argument references local variable '' of 
enclosing function}}
+
+  struct S { int i; };
+  auto [x] = S();
+
+  extern void h7(int = x); // FIXME: reject
 }

diff  --git a/clang/test/SemaCXX/attr-unused.cpp 
b/clang/test/SemaCXX/attr-unused.cpp
index b74bc915ce07..e3878152eca9 100644
--- a/clang/test/SemaCXX/attr-unused.cpp
+++ b/clang/test/SemaCXX/attr-unused.cpp
@@ -3,7 +3,17 @@
 namespace ns_unused { typedef int Int_unused __attribute__((unused)); }
 namespace ns_not_unused { typedef int Int_not_unused; }
 
+template  class C;
+template <> class __attribute__((unused)) C {};
+
 void f() {
   ns_not_unused::Int_not_unused i1; // expected-warning {{unused variable}}
   ns_unused::Int_unused i0; // expected-warning {{'Int_unused' was marked 
unused but was used}}
+
+  union __attribute__((unused)) { // expected-warning {{'' was marked unused 
but was used}}
+int i;
+  };
+  (void) i;
+
+  C(); // expected-warning {{'C' was marked unused but was used}}
 }

diff  --git a/clang/test/SemaCXX/default2.cpp b/clang/test/SemaCXX/default2.cpp
index 4c8e8ce6941a..7651233f8636 100644
--- a/clang/test/SemaCXX/default2.cpp
+++ b/clang/test/SemaCXX/default2.cpp
@@ -117,6 +117,12 @@ class C2 {
   static int f(int = 10); // expected-note{{default argument declared here}}
 };
 
+template  class C3;
+template <> class C3 {
+  static void g(int = f()); // expected-error {{use of default argument to 
function 'f' that is declared later in class 'C3'}}
+  static int f(int = 10); // expected-note {{default argument declared here}}
+};
+
 // Make sure we actually parse the default argument for an inline definition
 class XX {
   void A(int length = -1 ) {  } 

diff  --git a/clang/test/SemaCXX/incomplete-call.cpp 
b/clang/test/SemaCXX/incomplete-call.cpp
index 0fb1ef5f07a5..46f470e4a881 100644
--- a/clang/test/SemaCXX/incomplete-call.cpp
+++ b/clang/test/SemaCXX/incomplete-call.cpp
@@ -1,7 +1,8 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s
-struct A; // expected-note 14 {{forward declaration of 'A'}}
+struct A; // expected-note 15 {{forward declaration of 'A'}}
 
 A f(); // expected-note {{'f' declared here}}
+template  A ft(T); // expected-note {{'ft' declared here}}
 
 struct B {
   A f(); // expected-note {{'f' declared here}}
@@ -38,7 +39,8 @@ void g() {
   
   A (B::*mfp)() = 0;
   (b.*mfp)(); // expected-error {{calling function with incomplete return type 
'A'}}
-  
+
+  ft(42); // expected-error {{calling 'ft' with incomplete return type 'A'}}
 }
 
 

diff  --git a/clang/test/SemaCXX/lambda-expressions.cpp 
b/clang/test/SemaCXX/lambda-expressions.cpp
index 3240d5351fc5..7f7f9c570487 100644
--- a/clang/test/SemaCXX/lambda-expressions.cpp
+++ b/clang/test/SemaCXX/lambda-expressions.cpp
@@ -649,3 +649,14 @@ void Run(const int& points) {
 void operator_parens() {
   [&](int x){ operator()(); }(0); // expected-error {{undeclared 'operator()'}}
 }
+
+namespace captured_name {
+void Test() {
+  union {   // expected-note {{'' declared here}}
+int i;
+  };
+  [] { return i; }; // expected-error {{variable '' cannot be implicitly 
captured in a lambda with no capture-default specified}}
+// expected-note@-1 {{lambda expression begins here}}
+
+}
+};



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


[clang] 32db24a - [clang] Provide a more specific diagnostic for a misplaced lambda capture-default.

2020-07-18 Thread Bruno Ricci via cfe-commits

Author: Bruno Ricci
Date: 2020-07-18T20:35:16+01:00
New Revision: 32db24a7f24236d78beaeb5cfd96b115d67a5c21

URL: 
https://github.com/llvm/llvm-project/commit/32db24a7f24236d78beaeb5cfd96b115d67a5c21
DIFF: 
https://github.com/llvm/llvm-project/commit/32db24a7f24236d78beaeb5cfd96b115d67a5c21.diff

LOG: [clang] Provide a more specific diagnostic for a misplaced lambda 
capture-default.

Currently a capture-default which is not the first element in the lambda-capture
is diagnosed with a generic expected variable name or 'this' in lambda capture
list, which is true but not very helpful.

If we don't have already parsed a capture-default then a lone "&" or "=" is
likely to be a misplaced capture-default, so diagnose it as such.

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

Reviewed By: aaron.ballman

Added: 
clang/test/Parser/lambda-misplaced-capture-default.cpp

Modified: 
clang/include/clang/Basic/DiagnosticParseKinds.td
clang/lib/Parse/ParseExprCXX.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticParseKinds.td 
b/clang/include/clang/Basic/DiagnosticParseKinds.td
index 1038a4119d4c..a10191e91be3 100644
--- a/clang/include/clang/Basic/DiagnosticParseKinds.td
+++ b/clang/include/clang/Basic/DiagnosticParseKinds.td
@@ -934,6 +934,8 @@ def err_lambda_capture_misplaced_ellipsis : Error<
   "the name of the capture">;
 def err_lambda_capture_multiple_ellipses : Error<
   "multiple ellipses in pack capture">;
+def err_capture_default_first : Error<
+  "capture default must be first">;
 // C++17 lambda expressions
 def err_expected_star_this_capture : Error<
   "expected 'this' following '*' in lambda capture list">;

diff  --git a/clang/lib/Parse/ParseExprCXX.cpp 
b/clang/lib/Parse/ParseExprCXX.cpp
index aa35200c33b6..b225bb7c8b36 100644
--- a/clang/lib/Parse/ParseExprCXX.cpp
+++ b/clang/lib/Parse/ParseExprCXX.cpp
@@ -926,6 +926,15 @@ bool Parser::ParseLambdaIntroducer(LambdaIntroducer ,
 } else if (Tok.is(tok::kw_this)) {
   Kind = LCK_This;
   Loc = ConsumeToken();
+} else if (Tok.isOneOf(tok::amp, tok::equal) &&
+   NextToken().isOneOf(tok::comma, tok::r_square) &&
+   Intro.Default == LCD_None) {
+  // We have a lone "&" or "=" which is either a misplaced capture-default
+  // or the start of a capture (in the "&" case) with the rest of the
+  // capture missing. Both are an error but a misplaced capture-default
+  // is more likely if we don't already have a capture default.
+  return Invalid(
+  [&] { Diag(Tok.getLocation(), diag::err_capture_default_first); });
 } else {
   TryConsumeToken(tok::ellipsis, EllipsisLocs[0]);
 

diff  --git a/clang/test/Parser/lambda-misplaced-capture-default.cpp 
b/clang/test/Parser/lambda-misplaced-capture-default.cpp
new file mode 100644
index ..d65b875102da
--- /dev/null
+++ b/clang/test/Parser/lambda-misplaced-capture-default.cpp
@@ -0,0 +1,38 @@
+// RUN: %clang_cc1 -std=c++20 -Wno-unused-value -fsyntax-only -verify %s
+
+namespace misplaced_capture_default {
+void Test() {
+  int i = 0;
+  [&, i, &] {};   // expected-error {{expected variable name or 'this' in 
lambda capture list}}
+  [&, i, = ] {};  // expected-error {{expected variable name or 'this' in 
lambda capture list}}
+  [=, , &] {};  // expected-error {{expected variable name or 'this' in 
lambda capture list}}
+  [=, , = ] {}; // expected-error {{expected variable name or 'this' in 
lambda capture list}}
+
+  [i, &] {};   // expected-error {{capture default must be first}}
+  [i, = ] {};  // expected-error {{capture default must be first}}
+  [i, = x] {}; // expected-error {{expected variable name or 'this' in lambda 
capture list}}
+  [=, ] {};  // ok
+  [&, ] {};  // expected-error {{'&' cannot precede a capture when the 
capture default is '&'}}
+  [ = i] {}; // ok
+  [=,  = i] {};  // ok
+  [x = ] {}; // ok
+  [=,  = ] {}; // expected-error {{non-const lvalue reference to type 'int 
*' cannot bind to a temporary of type 'int *'}}
+  [&, this] {}; // expected-error {{'this' cannot be captured in this context}}
+
+  [i, &, x = 2] {}; // expected-error {{capture default must be first}}
+  [i, =, x = 2] {}; // expected-error {{capture default must be first}}
+}
+} // namespace misplaced_capture_default
+
+namespace misplaced_capture_default_pack {
+template  void Test(Args... args) {
+  [&, args...] {}; // ok
+  [args..., &] {}; // expected-error {{capture default must be first}}
+  [=, ] {};// ok
+  [&, ... xs = ] {};  // ok
+  [&, ... xs = &] {};  // expected-error {{expected expression}}
+  [... xs = &] {}; // expected-error {{expected expression}}
+  [... xs = , = ] {}; // expected-error {{capture default must be first}}
+  [... xs = , &] {};  // expected-error {{capture default must be first}}
+}
+} // namespace misplaced_capture_default_pack




[clang] acf3bdc - [clang][NFC] Tests showing the problems with some uses of NamedDecl::getDeclName in diagnostics, SemaOverload.cpp+SemaStmt.cpp part

2020-07-18 Thread Bruno Ricci via cfe-commits

Author: Bruno Ricci
Date: 2020-07-18T20:44:06+01:00
New Revision: acf3bdc283ecf6e2c3a85a391a24becc4814b8b8

URL: 
https://github.com/llvm/llvm-project/commit/acf3bdc283ecf6e2c3a85a391a24becc4814b8b8
DIFF: 
https://github.com/llvm/llvm-project/commit/acf3bdc283ecf6e2c3a85a391a24becc4814b8b8.diff

LOG: [clang][NFC] Tests showing the problems with some uses of 
NamedDecl::getDeclName in diagnostics, SemaOverload.cpp+SemaStmt.cpp part

Added: 
clang/test/Sema/return-non-void.c
clang/test/SemaCXX/consteval-return-void.cpp
clang/test/SemaCXX/return-void.cpp
clang/test/SemaObjC/method-return-void.m

Modified: 
clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.noreturn/p1.cpp
clang/test/SemaCXX/constant-expression-cxx11.cpp
clang/test/SemaCXX/return.cpp
clang/test/SemaCXX/warn-pure-virtual-call-from-ctor-dtor.cpp
clang/test/SemaCXX/warn-pure-virtual-kext.cpp

Removed: 




diff  --git a/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.noreturn/p1.cpp 
b/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.noreturn/p1.cpp
index 59cac367dbf2..0d4d34ac0e14 100644
--- a/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.noreturn/p1.cpp
+++ b/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.noreturn/p1.cpp
@@ -7,6 +7,12 @@ void a2 [[noreturn]] () {
   return; // expected-warning {{function 'a2' declared 'noreturn' should not 
return}}
 }
 
+template  void a3 [[noreturn]] () {}
+template <> void a3 () { return; } // expected-warning {{function 'a3' 
declared 'noreturn' should not return}}
+
+template  void a4 [[noreturn]] () { return; } // expected-warning 
2{{function 'a4' declared 'noreturn' should not return}}
+void a4_test() { a4(); } // expected-note {{in instantiation of function 
template specialization 'a4' requested here}}
+
 [[noreturn, noreturn]] void b() { throw 0; } // expected-error {{attribute 
'noreturn' cannot appear multiple times in an attribute specifier}}
 [[noreturn]] [[noreturn]] void b2() { throw 0; } // ok
 

diff  --git a/clang/test/Sema/return-non-void.c 
b/clang/test/Sema/return-non-void.c
new file mode 100644
index ..f1ee3722af48
--- /dev/null
+++ b/clang/test/Sema/return-non-void.c
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -Wreturn-type -std=c99 -fsyntax-only -verify=c99 %s
+// RUN: %clang_cc1 -Wreturn-type -std=c90 -fsyntax-only -verify=c90 %s
+
+int foo(void) { return; } // c99-error {{non-void function 'foo' should return 
a value}}
+  // c90-error@-1 {{non-void function 'foo' should 
return a value}}

diff  --git a/clang/test/SemaCXX/constant-expression-cxx11.cpp 
b/clang/test/SemaCXX/constant-expression-cxx11.cpp
index b69bcb2fef9d..7ff260c37c69 100644
--- a/clang/test/SemaCXX/constant-expression-cxx11.cpp
+++ b/clang/test/SemaCXX/constant-expression-cxx11.cpp
@@ -2167,6 +2167,11 @@ namespace PR21786 {
 namespace PR21859 {
   constexpr int Fun() { return; } // expected-error {{non-void constexpr 
function 'Fun' should return a value}}
   constexpr int Var = Fun();
+
+  template  constexpr int FunT1() { return; } // expected-error 
{{non-void constexpr function 'FunT1' should return a value}}
+  template  constexpr int FunT2() { return 0; }
+  template <> constexpr int FunT2() { return 0; }
+  template <> constexpr int FunT2() { return; } // expected-error 
{{non-void constexpr function 'FunT2' should return a value}}
 }
 
 struct InvalidRedef {

diff  --git a/clang/test/SemaCXX/consteval-return-void.cpp 
b/clang/test/SemaCXX/consteval-return-void.cpp
new file mode 100644
index ..a5207f41bf2c
--- /dev/null
+++ b/clang/test/SemaCXX/consteval-return-void.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s
+
+consteval int Fun() { return; } // expected-error {{non-void constexpr 
function 'Fun' should return a value}}
+
+// FIXME: The diagnostic is wrong; should be "consteval".
+
+template  consteval int FunT1() { return; } // expected-error 
{{non-void constexpr function 'FunT1' should return a value}}
+template  consteval int FunT2() { return 0; }
+template <> consteval int FunT2() { return 0; }
+template <> consteval int FunT2() { return; } // expected-error 
{{non-void constexpr function 'FunT2' should return a value}}

diff  --git a/clang/test/SemaCXX/return-void.cpp 
b/clang/test/SemaCXX/return-void.cpp
new file mode 100644
index ..b3aa203133dc
--- /dev/null
+++ b/clang/test/SemaCXX/return-void.cpp
@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 %s -std=c++11 -fsyntax-only -verify
+
+void f1() { return {1,2}; } // expected-error {{void function 'f1' must not 
return a value}}
+
+template  void f2() { return {1,2}; } // expected-error {{void 
function 'f2' must not return a value}}
+
+template <> void f2() { return {1,2}; } // expected-error {{void 
function 'f2' must not return a value}}
+
+void test_f2() {
+  f2();
+  f2();
+}
+
+struct S {
+  void f3() { return {1,2}; } // expected-error {{void function 'f3' must not 
return a value}}
+  S() 

[clang] 1ba6fb9 - [clang] Fix a crash when passing a C structure of incompatible type to a function with a reference parameter.

2020-07-08 Thread Bruno Ricci via cfe-commits

Author: Aleksandr Platonov
Date: 2020-07-08T16:57:54+01:00
New Revision: 1ba6fb9293967de21ae33be10603bf5ae0ce1c96

URL: 
https://github.com/llvm/llvm-project/commit/1ba6fb9293967de21ae33be10603bf5ae0ce1c96
DIFF: 
https://github.com/llvm/llvm-project/commit/1ba6fb9293967de21ae33be10603bf5ae0ce1c96.diff

LOG: [clang] Fix a crash when passing a C structure of incompatible type to a 
function with a reference parameter.

__builtin_va_*() and __builtin_ms_va_*() are declared as functions with a
parameter of reference type.

This patch fixes a crash when using these functions in C where an argument
of structure type is incompatible with the parameter type.

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

Reviewed By: riccibruno

Patch by: Aleksandr Platonov 

Added: 
clang/test/Sema/init-ref-c.c

Modified: 
clang/lib/Sema/SemaInit.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index d46e7f86d6b3..eb07de65d266 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -4693,6 +4693,9 @@ static bool isNonReferenceableGLValue(Expr *E) {
 }
 
 /// Reference initialization without resolving overloaded functions.
+///
+/// We also can get here in C if we call a builtin which is declared as
+/// a function with a parameter of reference type (such as __builtin_va_end()).
 static void TryReferenceInitializationCore(Sema ,
const InitializedEntity ,
const InitializationKind ,
@@ -4769,15 +4772,20 @@ static void TryReferenceInitializationCore(Sema ,
 // an rvalue. DR1287 removed the "implicitly" here.
 if (RefRelationship == Sema::Ref_Incompatible && T2->isRecordType() &&
 (isLValueRef || InitCategory.isRValue())) {
-  ConvOvlResult = TryRefInitWithConversionFunction(
-  S, Entity, Kind, Initializer, /*AllowRValues*/ isRValueRef,
-  /*IsLValueRef*/ isLValueRef, Sequence);
-  if (ConvOvlResult == OR_Success)
-return;
-  if (ConvOvlResult != OR_No_Viable_Function)
-Sequence.SetOverloadFailure(
-InitializationSequence::FK_ReferenceInitOverloadFailed,
-ConvOvlResult);
+  if (S.getLangOpts().CPlusPlus) {
+// Try conversion functions only for C++.
+ConvOvlResult = TryRefInitWithConversionFunction(
+S, Entity, Kind, Initializer, /*AllowRValues*/ isRValueRef,
+/*IsLValueRef*/ isLValueRef, Sequence);
+if (ConvOvlResult == OR_Success)
+  return;
+if (ConvOvlResult != OR_No_Viable_Function)
+  Sequence.SetOverloadFailure(
+  InitializationSequence::FK_ReferenceInitOverloadFailed,
+  ConvOvlResult);
+  } else {
+ConvOvlResult = OR_No_Viable_Function;
+  }
 }
   }
 

diff  --git a/clang/test/Sema/init-ref-c.c b/clang/test/Sema/init-ref-c.c
new file mode 100644
index ..38d8c44e2fdf
--- /dev/null
+++ b/clang/test/Sema/init-ref-c.c
@@ -0,0 +1,7 @@
+// RUN: %clang_cc1 -triple arm-unknown-gnu -fsyntax-only -verify %s
+
+void f() {
+  struct EmptyStruct {};
+  struct EmptyStruct S;
+  __builtin_va_end(S); // no-crash, expected-error {{non-const lvalue 
reference to type '__builtin_va_list' cannot bind to a value of unrelated type 
'struct EmptyStruct'}}
+}
\ No newline at end of file



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


[clang] 7a7d50e - [clang][NFC] Also test for serialization in test/AST/ast-dump-APValue-*

2020-07-08 Thread Bruno Ricci via cfe-commits

Author: Bruno Ricci
Date: 2020-07-08T16:39:11+01:00
New Revision: 7a7d50e1f0d84c701fd2aa1b84a73a3e194fb91a

URL: 
https://github.com/llvm/llvm-project/commit/7a7d50e1f0d84c701fd2aa1b84a73a3e194fb91a
DIFF: 
https://github.com/llvm/llvm-project/commit/7a7d50e1f0d84c701fd2aa1b84a73a3e194fb91a.diff

LOG: [clang][NFC] Also test for serialization in test/AST/ast-dump-APValue-*

This does not actually exercise the serialization of APValue, but it
will at least prevent a regression in the future. NFC.

Added: 


Modified: 
clang/test/AST/ast-dump-APValue-anon-union.cpp
clang/test/AST/ast-dump-APValue-arithmetic.cpp
clang/test/AST/ast-dump-APValue-array.cpp
clang/test/AST/ast-dump-APValue-struct.cpp
clang/test/AST/ast-dump-APValue-todo.cpp
clang/test/AST/ast-dump-APValue-union.cpp
clang/test/AST/ast-dump-APValue-vector.cpp

Removed: 




diff  --git a/clang/test/AST/ast-dump-APValue-anon-union.cpp 
b/clang/test/AST/ast-dump-APValue-anon-union.cpp
index c50fe70be911..1c9480c5a943 100644
--- a/clang/test/AST/ast-dump-APValue-anon-union.cpp
+++ b/clang/test/AST/ast-dump-APValue-anon-union.cpp
@@ -1,6 +1,14 @@
+// Test without serialization:
 // RUN: %clang_cc1 -triple x86_64-unknown-unknown -Wno-unused-value 
-std=gnu++17 \
 // RUN:-ast-dump %s -ast-dump-filter Test \
 // RUN: | FileCheck --strict-whitespace --match-full-lines %s
+//
+// Test with serialization:
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -Wno-unused-value 
-std=gnu++17 -emit-pch -o %t %s
+// RUN: %clang_cc1 -x c++ -triple x86_64-unknown-unknown -Wno-unused-value 
-std=gnu++17 \
+// RUN:   -include-pch %t -ast-dump-all -ast-dump-filter Test 
/dev/null \
+// RUN: | sed -e "s/ //" -e "s/ imported//" \
+// RUN: | FileCheck --strict-whitespace --match-full-lines %s
 
 struct S0 {
   union {

diff  --git a/clang/test/AST/ast-dump-APValue-arithmetic.cpp 
b/clang/test/AST/ast-dump-APValue-arithmetic.cpp
index a4e1d82eeb37..835d8c810834 100644
--- a/clang/test/AST/ast-dump-APValue-arithmetic.cpp
+++ b/clang/test/AST/ast-dump-APValue-arithmetic.cpp
@@ -1,6 +1,14 @@
+// Test without serialization:
 // RUN: %clang_cc1 -triple x86_64-unknown-unknown -Wno-unused-value 
-std=gnu++17 \
 // RUN:-ast-dump %s -ast-dump-filter Test \
 // RUN: | FileCheck --strict-whitespace --match-full-lines %s
+//
+// Test with serialization:
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -Wno-unused-value 
-std=gnu++17 -emit-pch -o %t %s
+// RUN: %clang_cc1 -x c++ -triple x86_64-unknown-unknown -Wno-unused-value 
-std=gnu++17 \
+// RUN:   -include-pch %t -ast-dump-all -ast-dump-filter Test 
/dev/null \
+// RUN: | sed -e "s/ //" -e "s/ imported//" \
+// RUN: | FileCheck --strict-whitespace --match-full-lines %s
 
 void Test() {
   constexpr int Int = 42;

diff  --git a/clang/test/AST/ast-dump-APValue-array.cpp 
b/clang/test/AST/ast-dump-APValue-array.cpp
index 4b7dfab09eaf..f9b38ec332a5 100644
--- a/clang/test/AST/ast-dump-APValue-array.cpp
+++ b/clang/test/AST/ast-dump-APValue-array.cpp
@@ -1,6 +1,14 @@
+// Test without serialization:
 // RUN: %clang_cc1 -triple x86_64-unknown-unknown -Wno-unused-value 
-std=gnu++17 \
 // RUN:-ast-dump %s -ast-dump-filter Test \
 // RUN: | FileCheck --strict-whitespace --match-full-lines %s
+//
+// Test with serialization:
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -Wno-unused-value 
-std=gnu++17 -emit-pch -o %t %s
+// RUN: %clang_cc1 -x c++ -triple x86_64-unknown-unknown -Wno-unused-value 
-std=gnu++17 \
+// RUN:   -include-pch %t -ast-dump-all -ast-dump-filter Test 
/dev/null \
+// RUN: | sed -e "s/ //" -e "s/ imported//" \
+// RUN: | FileCheck --strict-whitespace --match-full-lines %s
 
 struct S0 {
   int arr[2];

diff  --git a/clang/test/AST/ast-dump-APValue-struct.cpp 
b/clang/test/AST/ast-dump-APValue-struct.cpp
index d69ddffda031..4730404abc28 100644
--- a/clang/test/AST/ast-dump-APValue-struct.cpp
+++ b/clang/test/AST/ast-dump-APValue-struct.cpp
@@ -1,6 +1,14 @@
+// Test without serialization:
 // RUN: %clang_cc1 -triple x86_64-unknown-unknown -Wno-unused-value 
-std=gnu++17 \
 // RUN:-ast-dump %s -ast-dump-filter Test \
 // RUN: | FileCheck --strict-whitespace --match-full-lines %s
+//
+// Test with serialization:
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -Wno-unused-value 
-std=gnu++17 -emit-pch -o %t %s
+// RUN: %clang_cc1 -x c++ -triple x86_64-unknown-unknown -Wno-unused-value 
-std=gnu++17 \
+// RUN:   -include-pch %t -ast-dump-all -ast-dump-filter Test 
/dev/null \
+// RUN: | sed -e "s/ //" -e "s/ imported//" \
+// RUN: | FileCheck --strict-whitespace --match-full-lines %s
 
 struct S0 {
   int i = 0;

diff  --git a/clang/test/AST/ast-dump-APValue-todo.cpp 
b/clang/test/AST/ast-dump-APValue-todo.cpp
index 5de8146910f7..78cc9cf36c73 100644
--- a/clang/test/AST/ast-dump-APValue-todo.cpp
+++ 

[clang] f63e3ea - [clang] Rework how and when APValues are dumped

2020-07-06 Thread Bruno Ricci via cfe-commits

Author: Bruno Ricci
Date: 2020-07-06T22:03:08+01:00
New Revision: f63e3ea558bbe14826b5b775367eac617b35e041

URL: 
https://github.com/llvm/llvm-project/commit/f63e3ea558bbe14826b5b775367eac617b35e041
DIFF: 
https://github.com/llvm/llvm-project/commit/f63e3ea558bbe14826b5b775367eac617b35e041.diff

LOG: [clang] Rework how and when APValues are dumped

Currently APValues are dumped as a single string. This becomes quickly
completely unreadable since APValue is a tree-like structure. Even a simple
example is not pretty:

  struct S { int arr[4]; float f; };
  constexpr S s = { .arr = {1,2}, .f = 3.1415f };
  // Struct  fields: Array: Int: 1, Int: 2, 2 x Int: 0, Float: 3.141500e+00

With this patch this becomes:

  -Struct
   |-field: Array size=4
   | |-elements: Int 1, Int 2
   | `-filler: 2 x Int 0
   `-field: Float 3.141500e+00

Additionally APValues are currently only dumped as part of visiting a
ConstantExpr. This patch also dump the value of the initializer of constexpr
variable declarations:

  constexpr int foo(int a, int b) { return a + b - 42; }
  constexpr int a = 1, b = 2;
  constexpr int c = foo(a, b) > 0 ? foo(a, b) : foo(b, a);
  // VarDecl 0x6218aec8  col:17 c 'const int' constexpr cinit
  // |-value: Int -39
  // `-ConditionalOperator 0x6218b4d0  'int'
  // 

Do the above by moving the dump functions to TextNodeDumper which already has
the machinery to display trees. The cases APValue::LValue, 
APValue::MemberPointer
and APValue::AddrLabelDiff are left as they were before (unimplemented).

We try to display multiple elements on the same line if they are considered to
be "simple". This is to avoid wasting large amounts of vertical space in an
example like:

  constexpr int arr[8] = {0,1,2,3,4,5,6,7};
  // VarDecl 0x6218bb78  col:17 arr 'int const[8]' constexpr 
cinit
  // |-value: Array size=8
  // | |-elements: Int 0, Int 1, Int 2, Int 3
  // | `-elements: Int 4, Int 5, Int 6, Int 7

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

Reviewed By: aaron.ballman

Added: 
clang/test/AST/ast-dump-APValue-anon-union.cpp
clang/test/AST/ast-dump-APValue-arithmetic.cpp
clang/test/AST/ast-dump-APValue-array.cpp
clang/test/AST/ast-dump-APValue-struct.cpp
clang/test/AST/ast-dump-APValue-todo.cpp
clang/test/AST/ast-dump-APValue-union.cpp
clang/test/AST/ast-dump-APValue-vector.cpp

Modified: 
clang/include/clang/AST/APValue.h
clang/include/clang/AST/ASTNodeTraverser.h
clang/include/clang/AST/JSONNodeDumper.h
clang/include/clang/AST/TextNodeDumper.h
clang/lib/AST/APValue.cpp
clang/lib/AST/ASTDumper.cpp
clang/lib/AST/JSONNodeDumper.cpp
clang/lib/AST/TextNodeDumper.cpp
clang/test/AST/alignas_maybe_odr_cleanup.cpp
clang/test/AST/ast-dump-attr.cpp
clang/test/AST/ast-dump-color.cpp
clang/test/AST/ast-dump-constant-expr.cpp
clang/test/AST/ast-dump-decl.cpp
clang/test/AST/ast-dump-records.cpp
clang/test/AST/ast-dump-stmt.cpp
clang/test/AST/pr43983.cpp
clang/test/Import/switch-stmt/test.cpp
clang/test/Tooling/clang-check-ast-dump.cpp

Removed: 




diff  --git a/clang/include/clang/AST/APValue.h 
b/clang/include/clang/AST/APValue.h
index c69974c63c71..cca92b5f8235 100644
--- a/clang/include/clang/AST/APValue.h
+++ b/clang/include/clang/AST/APValue.h
@@ -372,7 +372,7 @@ class APValue {
   bool isAddrLabelDiff() const { return Kind == AddrLabelDiff; }
 
   void dump() const;
-  void dump(raw_ostream , const ASTContext *Context) const;
+  void dump(raw_ostream , const ASTContext ) const;
 
   void printPretty(raw_ostream , const ASTContext , QualType Ty) const;
   std::string getAsString(const ASTContext , QualType Ty) const;

diff  --git a/clang/include/clang/AST/ASTNodeTraverser.h 
b/clang/include/clang/AST/ASTNodeTraverser.h
index f1c98193df6c..26656b7162b6 100644
--- a/clang/include/clang/AST/ASTNodeTraverser.h
+++ b/clang/include/clang/AST/ASTNodeTraverser.h
@@ -22,10 +22,13 @@
 #include "clang/AST/LocInfoType.h"
 #include "clang/AST/StmtVisitor.h"
 #include "clang/AST/TemplateArgumentVisitor.h"
+#include "clang/AST/Type.h"
 #include "clang/AST/TypeVisitor.h"
 
 namespace clang {
 
+class APValue;
+
 /**
 
 ASTNodeTraverser traverses the Clang AST for dumping purposes.
@@ -50,6 +53,7 @@ struct {
   void Visit(const OMPClause *C);
   void Visit(const BlockDecl::Capture );
   void Visit(const GenericSelectionExpr::ConstAssociation );
+  void Visit(const APValue , QualType Ty);
 };
 */
 template 
@@ -211,6 +215,10 @@ class ASTNodeTraverser
 });
   }
 
+  void Visit(const APValue , QualType Ty) {
+getNodeDelegate().AddChild([=] { getNodeDelegate().Visit(Value, Ty); });
+  }
+
   void Visit(const comments::Comment *C, const comments::FullComment *FC) {
 getNodeDelegate().AddChild([=] {
   getNodeDelegate().Visit(C, FC);

diff  --git a/clang/include/clang/AST/JSONNodeDumper.h 

[clang] cf0b3af - [clang][utils] make-ast-dump-check.sh: strip line and column numbers when generating serialization tests

2020-07-06 Thread Bruno Ricci via cfe-commits

Author: Bruno Ricci
Date: 2020-07-06T16:52:35+01:00
New Revision: cf0b3affed47811b02127383c7eec27285ac35a3

URL: 
https://github.com/llvm/llvm-project/commit/cf0b3affed47811b02127383c7eec27285ac35a3
DIFF: 
https://github.com/llvm/llvm-project/commit/cf0b3affed47811b02127383c7eec27285ac35a3.diff

LOG: [clang][utils] make-ast-dump-check.sh: strip line and column numbers when 
generating serialization tests

Added: 


Modified: 
clang/utils/make-ast-dump-check.sh

Removed: 




diff  --git a/clang/utils/make-ast-dump-check.sh 
b/clang/utils/make-ast-dump-check.sh
index f0c268c883e9..365f227cc1c6 100755
--- a/clang/utils/make-ast-dump-check.sh
+++ b/clang/utils/make-ast-dump-check.sh
@@ -70,6 +70,10 @@ BEGIN {
   if ($generate_serialization_test == 1) {
 gsub(" imported", "{{( imported)?}}", s)
 gsub(" ", "{{( )?}}", s)
+gsub("line:[0-9]+:[0-9]+", "line:{{.*}}", s)
+gsub("line:[0-9]+", "line:{{.*}}", s)
+gsub("col:[0-9]+", "col:{{.*}}", s)
+gsub(":[0-9]+:[0-9]+", "{{.*}}", s)
   }
 }
 



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


[clang] 54eb425 - [clang][NFC] Also test for serialization in test/AST/ast-dump-comment.cpp

2020-07-03 Thread Bruno Ricci via cfe-commits

Author: Bruno Ricci
Date: 2020-07-03T13:59:23+01:00
New Revision: 54eb42537e8c566fa15046bc0302bf5390d26f08

URL: 
https://github.com/llvm/llvm-project/commit/54eb42537e8c566fa15046bc0302bf5390d26f08
DIFF: 
https://github.com/llvm/llvm-project/commit/54eb42537e8c566fa15046bc0302bf5390d26f08.diff

LOG: [clang][NFC] Also test for serialization in test/AST/ast-dump-comment.cpp

Added: 


Modified: 
clang/test/AST/ast-dump-comment.cpp

Removed: 




diff  --git a/clang/test/AST/ast-dump-comment.cpp 
b/clang/test/AST/ast-dump-comment.cpp
index da73483f041a..8df0416cd092 100644
--- a/clang/test/AST/ast-dump-comment.cpp
+++ b/clang/test/AST/ast-dump-comment.cpp
@@ -1,4 +1,12 @@
-// RUN: %clang_cc1 -Wdocumentation -ast-dump -ast-dump-filter Test %s | 
FileCheck -strict-whitespace %s
+// Without serialization:
+// RUN: %clang_cc1 -Wdocumentation -ast-dump -ast-dump-filter Test %s \
+// RUN: | FileCheck -strict-whitespace %s
+//
+// With serialization:
+// RUN: %clang_cc1 -Wdocumentation -emit-pch -o %t %s
+// RUN: %clang_cc1 -x c++ -Wdocumentation -include-pch %t -ast-dump-all 
-ast-dump-filter Test /dev/null \
+// RUN: | sed -e "s/ //" -e "s/ imported//" \
+// RUN: | FileCheck --strict-whitespace %s
 
 /// Aaa
 int TestLocation;



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


[clang-tools-extra] 473fbc9 - [clang][NFC] Store a pointer to the ASTContext in ASTDumper and TextNodeDumper

2020-07-03 Thread Bruno Ricci via cfe-commits

Author: Bruno Ricci
Date: 2020-07-03T13:59:22+01:00
New Revision: 473fbc90d1fbf17e16594dfb17248c4f50b4d399

URL: 
https://github.com/llvm/llvm-project/commit/473fbc90d1fbf17e16594dfb17248c4f50b4d399
DIFF: 
https://github.com/llvm/llvm-project/commit/473fbc90d1fbf17e16594dfb17248c4f50b4d399.diff

LOG: [clang][NFC] Store a pointer to the ASTContext in ASTDumper and 
TextNodeDumper

In general there is no way to get to the ASTContext from most AST nodes
(Decls are one of the exception). This will be a problem when implementing
the rest of APValue::dump since we need the ASTContext to dump some kinds of
APValues.

The ASTContext* in ASTDumper and TextNodeDumper is not always non-null.
This is because we still want to be able to use the various dump() functions
in a debugger.

No functional changes intended.

Reverted in fcf4d5e4499a391dff42ea1a096f146db44147b6 since a few dump()
functions in lldb where missed.

Added: 


Modified: 
clang-tools-extra/clang-query/Query.cpp
clang-tools-extra/clangd/refactor/tweaks/DumpAST.cpp
clang/include/clang/AST/APValue.h
clang/include/clang/AST/ASTDumper.h
clang/include/clang/AST/ASTTypeTraits.h
clang/include/clang/AST/Comment.h
clang/include/clang/AST/Stmt.h
clang/include/clang/AST/TextNodeDumper.h
clang/include/clang/AST/Type.h
clang/lib/AST/APValue.cpp
clang/lib/AST/ASTDumper.cpp
clang/lib/AST/ASTTypeTraits.cpp
clang/lib/AST/TextNodeDumper.cpp
clang/lib/ASTMatchers/ASTMatchFinder.cpp
clang/lib/CodeGen/CGExprComplex.cpp
clang/lib/CodeGen/CGExprScalar.cpp
clang/lib/Frontend/ASTConsumers.cpp
clang/unittests/AST/CommentParser.cpp
clang/unittests/AST/MatchVerifier.h
lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-query/Query.cpp 
b/clang-tools-extra/clang-query/Query.cpp
index 2fc7af6a56e1..4fe7110daed3 100644
--- a/clang-tools-extra/clang-query/Query.cpp
+++ b/clang-tools-extra/clang-query/Query.cpp
@@ -157,8 +157,7 @@ bool MatchQuery::run(llvm::raw_ostream , QuerySession 
) const {
   OS << "Binding for \"" << BI->first << "\":\n";
   const ASTContext  = AST->getASTContext();
   const SourceManager  = Ctx.getSourceManager();
-  ASTDumper Dumper(OS, (), ,
-SM.getDiagnostics().getShowColors(), Ctx.getPrintingPolicy());
+  ASTDumper Dumper(OS, Ctx, SM.getDiagnostics().getShowColors());
   Dumper.SetTraversalKind(QS.TK);
   Dumper.Visit(BI->second);
   OS << "\n";

diff  --git a/clang-tools-extra/clangd/refactor/tweaks/DumpAST.cpp 
b/clang-tools-extra/clangd/refactor/tweaks/DumpAST.cpp
index 616e100adf08..b2b883d64567 100644
--- a/clang-tools-extra/clangd/refactor/tweaks/DumpAST.cpp
+++ b/clang-tools-extra/clangd/refactor/tweaks/DumpAST.cpp
@@ -62,7 +62,7 @@ REGISTER_TWEAK(DumpAST)
 llvm::Expected DumpAST::apply(const Selection ) {
   std::string Str;
   llvm::raw_string_ostream OS(Str);
-  Node->dump(OS, Inputs.AST->getSourceManager());
+  Node->dump(OS, Inputs.AST->getASTContext());
   return Effect::showMessage(std::move(OS.str()));
 }
 

diff  --git a/clang/include/clang/AST/APValue.h 
b/clang/include/clang/AST/APValue.h
index 63359294ef63..c69974c63c71 100644
--- a/clang/include/clang/AST/APValue.h
+++ b/clang/include/clang/AST/APValue.h
@@ -372,7 +372,7 @@ class APValue {
   bool isAddrLabelDiff() const { return Kind == AddrLabelDiff; }
 
   void dump() const;
-  void dump(raw_ostream ) const;
+  void dump(raw_ostream , const ASTContext *Context) const;
 
   void printPretty(raw_ostream , const ASTContext , QualType Ty) const;
   std::string getAsString(const ASTContext , QualType Ty) const;

diff  --git a/clang/include/clang/AST/ASTDumper.h 
b/clang/include/clang/AST/ASTDumper.h
index f46ffb960db6..a154bc2db3a7 100644
--- a/clang/include/clang/AST/ASTDumper.h
+++ b/clang/include/clang/AST/ASTDumper.h
@@ -24,18 +24,11 @@ class ASTDumper : public ASTNodeTraverser {
   const bool ShowColors;
 
 public:
-  ASTDumper(raw_ostream , const comments::CommandTraits *Traits,
-const SourceManager *SM)
-  : ASTDumper(OS, Traits, SM, SM && SM->getDiagnostics().getShowColors()) 
{}
-
-  ASTDumper(raw_ostream , const comments::CommandTraits *Traits,
-const SourceManager *SM, bool ShowColors)
-  : ASTDumper(OS, Traits, SM, ShowColors, LangOptions()) {}
-  ASTDumper(raw_ostream , const comments::CommandTraits *Traits,
-const SourceManager *SM, bool ShowColors,
-const PrintingPolicy )
-  : NodeDumper(OS, ShowColors, SM, PrintPolicy, Traits), OS(OS),
-ShowColors(ShowColors) {}
+  ASTDumper(raw_ostream , const ASTContext , bool ShowColors)
+  : NodeDumper(OS, Context, ShowColors), OS(OS), ShowColors(ShowColors) {}
+
+  ASTDumper(raw_ostream , bool ShowColors)
+  : NodeDumper(OS, ShowColors), OS(OS), 

[clang] c10295e - [clang][NFC] Add a missing /dev/null in test/AST/ast-dump-lambda.cpp

2020-07-03 Thread Bruno Ricci via cfe-commits

Author: Bruno Ricci
Date: 2020-07-03T13:59:23+01:00
New Revision: c10295e1bdbf892946bf1db6c3c8feb1219c4070

URL: 
https://github.com/llvm/llvm-project/commit/c10295e1bdbf892946bf1db6c3c8feb1219c4070
DIFF: 
https://github.com/llvm/llvm-project/commit/c10295e1bdbf892946bf1db6c3c8feb1219c4070.diff

LOG: [clang][NFC] Add a missing /dev/null in test/AST/ast-dump-lambda.cpp

Added: 


Modified: 
clang/test/AST/ast-dump-lambda.cpp

Removed: 




diff  --git a/clang/test/AST/ast-dump-lambda.cpp 
b/clang/test/AST/ast-dump-lambda.cpp
index a3ca4a8fc534..37fb62ef9930 100644
--- a/clang/test/AST/ast-dump-lambda.cpp
+++ b/clang/test/AST/ast-dump-lambda.cpp
@@ -7,7 +7,7 @@
 // RUN: %clang_cc1 -triple x86_64-unknown-unknown -Wno-unused-value 
-std=gnu++17 \
 // RUN:-emit-pch -o %t %s
 // RUN: %clang_cc1 -triple x86_64-unknown-unknown -Wno-unused-value 
-std=gnu++17 \
-// RUN:-x c++ -include-pch %t -ast-dump-all -ast-dump-filter test \
+// RUN:-x c++ -include-pch %t -ast-dump-all -ast-dump-filter test 
/dev/null \
 // RUN: | FileCheck -strict-whitespace --match-full-lines %s
 
 



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


[clang] fcf4d5e - Revert "[clang][NFC] Store a pointer to the ASTContext in ASTDumper and TextNodeDumper"

2020-07-02 Thread Bruno Ricci via cfe-commits

Author: Bruno Ricci
Date: 2020-07-02T19:40:09+01:00
New Revision: fcf4d5e4499a391dff42ea1a096f146db44147b6

URL: 
https://github.com/llvm/llvm-project/commit/fcf4d5e4499a391dff42ea1a096f146db44147b6
DIFF: 
https://github.com/llvm/llvm-project/commit/fcf4d5e4499a391dff42ea1a096f146db44147b6.diff

LOG: Revert "[clang][NFC] Store a pointer to the ASTContext in ASTDumper and 
TextNodeDumper"

This reverts commit aa7fd905e4e1bc510448431da9310e8cf5197523.

I missed some dump() functions.

Added: 


Modified: 
clang-tools-extra/clang-query/Query.cpp
clang-tools-extra/clangd/refactor/tweaks/DumpAST.cpp
clang/include/clang/AST/APValue.h
clang/include/clang/AST/ASTDumper.h
clang/include/clang/AST/ASTTypeTraits.h
clang/include/clang/AST/Comment.h
clang/include/clang/AST/Stmt.h
clang/include/clang/AST/TextNodeDumper.h
clang/include/clang/AST/Type.h
clang/lib/AST/APValue.cpp
clang/lib/AST/ASTDumper.cpp
clang/lib/AST/ASTTypeTraits.cpp
clang/lib/AST/TextNodeDumper.cpp
clang/lib/ASTMatchers/ASTMatchFinder.cpp
clang/lib/CodeGen/CGExprComplex.cpp
clang/lib/CodeGen/CGExprScalar.cpp
clang/lib/Frontend/ASTConsumers.cpp
clang/unittests/AST/CommentParser.cpp
clang/unittests/AST/MatchVerifier.h

Removed: 




diff  --git a/clang-tools-extra/clang-query/Query.cpp 
b/clang-tools-extra/clang-query/Query.cpp
index 4fe7110daed3..2fc7af6a56e1 100644
--- a/clang-tools-extra/clang-query/Query.cpp
+++ b/clang-tools-extra/clang-query/Query.cpp
@@ -157,7 +157,8 @@ bool MatchQuery::run(llvm::raw_ostream , QuerySession 
) const {
   OS << "Binding for \"" << BI->first << "\":\n";
   const ASTContext  = AST->getASTContext();
   const SourceManager  = Ctx.getSourceManager();
-  ASTDumper Dumper(OS, Ctx, SM.getDiagnostics().getShowColors());
+  ASTDumper Dumper(OS, (), ,
+SM.getDiagnostics().getShowColors(), Ctx.getPrintingPolicy());
   Dumper.SetTraversalKind(QS.TK);
   Dumper.Visit(BI->second);
   OS << "\n";

diff  --git a/clang-tools-extra/clangd/refactor/tweaks/DumpAST.cpp 
b/clang-tools-extra/clangd/refactor/tweaks/DumpAST.cpp
index b2b883d64567..616e100adf08 100644
--- a/clang-tools-extra/clangd/refactor/tweaks/DumpAST.cpp
+++ b/clang-tools-extra/clangd/refactor/tweaks/DumpAST.cpp
@@ -62,7 +62,7 @@ REGISTER_TWEAK(DumpAST)
 llvm::Expected DumpAST::apply(const Selection ) {
   std::string Str;
   llvm::raw_string_ostream OS(Str);
-  Node->dump(OS, Inputs.AST->getASTContext());
+  Node->dump(OS, Inputs.AST->getSourceManager());
   return Effect::showMessage(std::move(OS.str()));
 }
 

diff  --git a/clang/include/clang/AST/APValue.h 
b/clang/include/clang/AST/APValue.h
index c69974c63c71..63359294ef63 100644
--- a/clang/include/clang/AST/APValue.h
+++ b/clang/include/clang/AST/APValue.h
@@ -372,7 +372,7 @@ class APValue {
   bool isAddrLabelDiff() const { return Kind == AddrLabelDiff; }
 
   void dump() const;
-  void dump(raw_ostream , const ASTContext *Context) const;
+  void dump(raw_ostream ) const;
 
   void printPretty(raw_ostream , const ASTContext , QualType Ty) const;
   std::string getAsString(const ASTContext , QualType Ty) const;

diff  --git a/clang/include/clang/AST/ASTDumper.h 
b/clang/include/clang/AST/ASTDumper.h
index a154bc2db3a7..f46ffb960db6 100644
--- a/clang/include/clang/AST/ASTDumper.h
+++ b/clang/include/clang/AST/ASTDumper.h
@@ -24,11 +24,18 @@ class ASTDumper : public ASTNodeTraverser {
   const bool ShowColors;
 
 public:
-  ASTDumper(raw_ostream , const ASTContext , bool ShowColors)
-  : NodeDumper(OS, Context, ShowColors), OS(OS), ShowColors(ShowColors) {}
-
-  ASTDumper(raw_ostream , bool ShowColors)
-  : NodeDumper(OS, ShowColors), OS(OS), ShowColors(ShowColors) {}
+  ASTDumper(raw_ostream , const comments::CommandTraits *Traits,
+const SourceManager *SM)
+  : ASTDumper(OS, Traits, SM, SM && SM->getDiagnostics().getShowColors()) 
{}
+
+  ASTDumper(raw_ostream , const comments::CommandTraits *Traits,
+const SourceManager *SM, bool ShowColors)
+  : ASTDumper(OS, Traits, SM, ShowColors, LangOptions()) {}
+  ASTDumper(raw_ostream , const comments::CommandTraits *Traits,
+const SourceManager *SM, bool ShowColors,
+const PrintingPolicy )
+  : NodeDumper(OS, ShowColors, SM, PrintPolicy, Traits), OS(OS),
+ShowColors(ShowColors) {}
 
   TextNodeDumper () { return NodeDumper; }
 

diff  --git a/clang/include/clang/AST/ASTTypeTraits.h 
b/clang/include/clang/AST/ASTTypeTraits.h
index 328b7bce6ba5..67fa4ab1b6a4 100644
--- a/clang/include/clang/AST/ASTTypeTraits.h
+++ b/clang/include/clang/AST/ASTTypeTraits.h
@@ -278,7 +278,7 @@ class DynTypedNode {
   void print(llvm::raw_ostream , const PrintingPolicy ) const;
 
   /// Dumps the node to the given output stream.
-  void dump(llvm::raw_ostream , const 

[clang] aa7fd90 - [clang][NFC] Store a pointer to the ASTContext in ASTDumper and TextNodeDumper

2020-07-02 Thread Bruno Ricci via cfe-commits

Author: Bruno Ricci
Date: 2020-07-02T19:29:02+01:00
New Revision: aa7fd905e4e1bc510448431da9310e8cf5197523

URL: 
https://github.com/llvm/llvm-project/commit/aa7fd905e4e1bc510448431da9310e8cf5197523
DIFF: 
https://github.com/llvm/llvm-project/commit/aa7fd905e4e1bc510448431da9310e8cf5197523.diff

LOG: [clang][NFC] Store a pointer to the ASTContext in ASTDumper and 
TextNodeDumper

In general there is no way to get to the ASTContext from most AST nodes
(Decls are one of the exception). This will be a problem when implementing
the rest of APValue::dump since we need the ASTContext to dump some kinds of
APValues.

The ASTContext* in ASTDumper and TextNodeDumper is not always
non-null. This is because we still want to be able to use the various
dump() functions in a debugger.

No functional changes intended.

Added: 


Modified: 
clang-tools-extra/clang-query/Query.cpp
clang-tools-extra/clangd/refactor/tweaks/DumpAST.cpp
clang/include/clang/AST/APValue.h
clang/include/clang/AST/ASTDumper.h
clang/include/clang/AST/ASTTypeTraits.h
clang/include/clang/AST/Comment.h
clang/include/clang/AST/Stmt.h
clang/include/clang/AST/TextNodeDumper.h
clang/include/clang/AST/Type.h
clang/lib/AST/APValue.cpp
clang/lib/AST/ASTDumper.cpp
clang/lib/AST/ASTTypeTraits.cpp
clang/lib/AST/TextNodeDumper.cpp
clang/lib/ASTMatchers/ASTMatchFinder.cpp
clang/lib/CodeGen/CGExprComplex.cpp
clang/lib/CodeGen/CGExprScalar.cpp
clang/lib/Frontend/ASTConsumers.cpp
clang/unittests/AST/CommentParser.cpp
clang/unittests/AST/MatchVerifier.h

Removed: 




diff  --git a/clang-tools-extra/clang-query/Query.cpp 
b/clang-tools-extra/clang-query/Query.cpp
index 2fc7af6a56e1..4fe7110daed3 100644
--- a/clang-tools-extra/clang-query/Query.cpp
+++ b/clang-tools-extra/clang-query/Query.cpp
@@ -157,8 +157,7 @@ bool MatchQuery::run(llvm::raw_ostream , QuerySession 
) const {
   OS << "Binding for \"" << BI->first << "\":\n";
   const ASTContext  = AST->getASTContext();
   const SourceManager  = Ctx.getSourceManager();
-  ASTDumper Dumper(OS, (), ,
-SM.getDiagnostics().getShowColors(), Ctx.getPrintingPolicy());
+  ASTDumper Dumper(OS, Ctx, SM.getDiagnostics().getShowColors());
   Dumper.SetTraversalKind(QS.TK);
   Dumper.Visit(BI->second);
   OS << "\n";

diff  --git a/clang-tools-extra/clangd/refactor/tweaks/DumpAST.cpp 
b/clang-tools-extra/clangd/refactor/tweaks/DumpAST.cpp
index 616e100adf08..b2b883d64567 100644
--- a/clang-tools-extra/clangd/refactor/tweaks/DumpAST.cpp
+++ b/clang-tools-extra/clangd/refactor/tweaks/DumpAST.cpp
@@ -62,7 +62,7 @@ REGISTER_TWEAK(DumpAST)
 llvm::Expected DumpAST::apply(const Selection ) {
   std::string Str;
   llvm::raw_string_ostream OS(Str);
-  Node->dump(OS, Inputs.AST->getSourceManager());
+  Node->dump(OS, Inputs.AST->getASTContext());
   return Effect::showMessage(std::move(OS.str()));
 }
 

diff  --git a/clang/include/clang/AST/APValue.h 
b/clang/include/clang/AST/APValue.h
index 63359294ef63..c69974c63c71 100644
--- a/clang/include/clang/AST/APValue.h
+++ b/clang/include/clang/AST/APValue.h
@@ -372,7 +372,7 @@ class APValue {
   bool isAddrLabelDiff() const { return Kind == AddrLabelDiff; }
 
   void dump() const;
-  void dump(raw_ostream ) const;
+  void dump(raw_ostream , const ASTContext *Context) const;
 
   void printPretty(raw_ostream , const ASTContext , QualType Ty) const;
   std::string getAsString(const ASTContext , QualType Ty) const;

diff  --git a/clang/include/clang/AST/ASTDumper.h 
b/clang/include/clang/AST/ASTDumper.h
index f46ffb960db6..a154bc2db3a7 100644
--- a/clang/include/clang/AST/ASTDumper.h
+++ b/clang/include/clang/AST/ASTDumper.h
@@ -24,18 +24,11 @@ class ASTDumper : public ASTNodeTraverser {
   const bool ShowColors;
 
 public:
-  ASTDumper(raw_ostream , const comments::CommandTraits *Traits,
-const SourceManager *SM)
-  : ASTDumper(OS, Traits, SM, SM && SM->getDiagnostics().getShowColors()) 
{}
-
-  ASTDumper(raw_ostream , const comments::CommandTraits *Traits,
-const SourceManager *SM, bool ShowColors)
-  : ASTDumper(OS, Traits, SM, ShowColors, LangOptions()) {}
-  ASTDumper(raw_ostream , const comments::CommandTraits *Traits,
-const SourceManager *SM, bool ShowColors,
-const PrintingPolicy )
-  : NodeDumper(OS, ShowColors, SM, PrintPolicy, Traits), OS(OS),
-ShowColors(ShowColors) {}
+  ASTDumper(raw_ostream , const ASTContext , bool ShowColors)
+  : NodeDumper(OS, Context, ShowColors), OS(OS), ShowColors(ShowColors) {}
+
+  ASTDumper(raw_ostream , bool ShowColors)
+  : NodeDumper(OS, ShowColors), OS(OS), ShowColors(ShowColors) {}
 
   TextNodeDumper () { return NodeDumper; }
 

diff  --git a/clang/include/clang/AST/ASTTypeTraits.h 
b/clang/include/clang/AST/ASTTypeTraits.h
index 

[clang] e4d178a - [clang][Serialization] Don't duplicate the body of LambdaExpr during deserialization

2020-07-02 Thread Bruno Ricci via cfe-commits

Author: Bruno Ricci
Date: 2020-07-02T14:13:35+01:00
New Revision: e4d178a75253f0ab8d2b9085087208aa8296

URL: 
https://github.com/llvm/llvm-project/commit/e4d178a75253f0ab8d2b9085087208aa8296
DIFF: 
https://github.com/llvm/llvm-project/commit/e4d178a75253f0ab8d2b9085087208aa8296.diff

LOG: [clang][Serialization] Don't duplicate the body of LambdaExpr during 
deserialization

05843dc6ab97a00cbde7aa4f08bf3692eb83109d changed the serialization of the body
of LambdaExpr to avoid a mutation in LambdaExpr::getBody and to avoid a missing
body in LambdaExpr::children.

Unfortunately this replaced one bug by another: we are now duplicating the body
during deserialization; that is after deserialization the identity:

E->getBody() == E->getCallOperator()->getBody() does not hold.

Fix that by instead lazily loading the body from the call operator when needed.

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

Reviewed By: martong, aaron.ballman, vabridgers

Added: 
clang/test/AST/ast-dump-lambda-body-not-duplicated.cpp

Modified: 
clang/include/clang/AST/ExprCXX.h
clang/lib/AST/ExprCXX.cpp
clang/lib/Serialization/ASTReaderStmt.cpp
clang/lib/Serialization/ASTWriterStmt.cpp

Removed: 




diff  --git a/clang/include/clang/AST/ExprCXX.h 
b/clang/include/clang/AST/ExprCXX.h
index 9906cd9df074..178f4db77061 100644
--- a/clang/include/clang/AST/ExprCXX.h
+++ b/clang/include/clang/AST/ExprCXX.h
@@ -1852,6 +1852,8 @@ class LambdaExpr final : public Expr,
   Stmt **getStoredStmts() { return getTrailingObjects(); }
   Stmt *const *getStoredStmts() const { return getTrailingObjects(); }
 
+  void initBodyIfNeeded() const;
+
 public:
   friend class ASTStmtReader;
   friend class ASTStmtWriter;
@@ -2000,17 +2002,12 @@ class LambdaExpr final : public Expr,
   /// a \p CompoundStmt, but can also be \p CoroutineBodyStmt wrapping
   /// a \p CompoundStmt. Note that unlike functions, lambda-expressions
   /// cannot have a function-try-block.
-  Stmt *getBody() const { return getStoredStmts()[capture_size()]; }
+  Stmt *getBody() const;
 
   /// Retrieve the \p CompoundStmt representing the body of the lambda.
   /// This is a convenience function for callers who do not need
   /// to handle node(s) which may wrap a \p CompoundStmt.
-  const CompoundStmt *getCompoundStmtBody() const {
-Stmt *Body = getBody();
-if (const auto *CoroBody = dyn_cast(Body))
-  return cast(CoroBody->getBody());
-return cast(Body);
-  }
+  const CompoundStmt *getCompoundStmtBody() const;
   CompoundStmt *getCompoundStmtBody() {
 const auto *ConstThis = this;
 return const_cast(ConstThis->getCompoundStmtBody());
@@ -2039,15 +2036,9 @@ class LambdaExpr final : public Expr,
 
   SourceLocation getEndLoc() const LLVM_READONLY { return ClosingBrace; }
 
-  child_range children() {
-// Includes initialization exprs plus body stmt
-return child_range(getStoredStmts(), getStoredStmts() + capture_size() + 
1);
-  }
-
-  const_child_range children() const {
-return const_child_range(getStoredStmts(),
- getStoredStmts() + capture_size() + 1);
-  }
+  /// Includes the captures and the body of the lambda.
+  child_range children();
+  const_child_range children() const;
 };
 
 /// An expression "T()" which creates a value-initialized rvalue of type

diff  --git a/clang/lib/AST/ExprCXX.cpp b/clang/lib/AST/ExprCXX.cpp
index 2889604308dd..5d99f61c579f 100644
--- a/clang/lib/AST/ExprCXX.cpp
+++ b/clang/lib/AST/ExprCXX.cpp
@@ -1118,6 +1118,10 @@ LambdaExpr::LambdaExpr(QualType T, SourceRange 
IntroducerRange,
 LambdaExpr::LambdaExpr(EmptyShell Empty, unsigned NumCaptures)
 : Expr(LambdaExprClass, Empty) {
   LambdaExprBits.NumCaptures = NumCaptures;
+
+  // Initially don't initialize the body of the LambdaExpr. The body will
+  // be lazily deserialized when needed.
+  getStoredStmts()[NumCaptures] = nullptr; // Not one past the end.
 }
 
 LambdaExpr *LambdaExpr::Create(const ASTContext , CXXRecordDecl *Class,
@@ -1147,6 +1151,25 @@ LambdaExpr *LambdaExpr::CreateDeserialized(const 
ASTContext ,
   return new (Mem) LambdaExpr(EmptyShell(), NumCaptures);
 }
 
+void LambdaExpr::initBodyIfNeeded() const {
+  if (!getStoredStmts()[capture_size()]) {
+auto *This = const_cast(this);
+This->getStoredStmts()[capture_size()] = getCallOperator()->getBody();
+  }
+}
+
+Stmt *LambdaExpr::getBody() const {
+  initBodyIfNeeded();
+  return getStoredStmts()[capture_size()];
+}
+
+const CompoundStmt *LambdaExpr::getCompoundStmtBody() const {
+  Stmt *Body = getBody();
+  if (const auto *CoroBody = dyn_cast(Body))
+return cast(CoroBody->getBody());
+  return cast(Body);
+}
+
 bool LambdaExpr::isInitCapture(const LambdaCapture *C) const {
   return (C->capturesVariable() && C->getCapturedVar()->isInitCapture() &&
   (getCallOperator() == C->getCapturedVar()->getDeclContext()));
@@ 

[clang] 0dbeffd - [clang][utils] Minor tweak to make-ast-dump-check.sh

2020-06-21 Thread Bruno Ricci via cfe-commits

Author: Bruno Ricci
Date: 2020-06-21T13:59:10+01:00
New Revision: 0dbeffddd1decda612f00e552c35cbcdb59907ab

URL: 
https://github.com/llvm/llvm-project/commit/0dbeffddd1decda612f00e552c35cbcdb59907ab
DIFF: 
https://github.com/llvm/llvm-project/commit/0dbeffddd1decda612f00e552c35cbcdb59907ab.diff

LOG: [clang][utils] Minor tweak to make-ast-dump-check.sh

Remove the space after the "CHECK:" on each line. This space makes the use
of FileCheck --match-full-lines impossible.

Added: 


Modified: 
clang/utils/make-ast-dump-check.sh

Removed: 




diff  --git a/clang/utils/make-ast-dump-check.sh 
b/clang/utils/make-ast-dump-check.sh
index 4e8a1c198608..f0c268c883e9 100755
--- a/clang/utils/make-ast-dump-check.sh
+++ b/clang/utils/make-ast-dump-check.sh
@@ -74,11 +74,11 @@ BEGIN {
 }
 
 matched_last_line == 0 {
-  print "// ${prefix}: " s
+  print "// ${prefix}:" s
 }
 
 matched_last_line == 1 {
-  print "// ${prefix}-NEXT: " s
+  print "// ${prefix}-NEXT:" s
 }
 
 {



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


[clang] ecbf2f5 - [clang][test][NFC] Also test for serialization in AST dump tests, part 2/n.

2020-06-21 Thread Bruno Ricci via cfe-commits

Author: Bruno Ricci
Date: 2020-06-21T13:59:11+01:00
New Revision: ecbf2f5f3d2e2868c6059320c185897f8f23de41

URL: 
https://github.com/llvm/llvm-project/commit/ecbf2f5f3d2e2868c6059320c185897f8f23de41
DIFF: 
https://github.com/llvm/llvm-project/commit/ecbf2f5f3d2e2868c6059320c185897f8f23de41.diff

LOG: [clang][test][NFC] Also test for serialization in AST dump tests, part 2/n.

The outputs between the direct ast-dump test and the ast-dump test after
deserialization should match modulo a few differences.

For hand-written tests, strip the ""s and
the "imported"s with sed.

For tests generated with "make-ast-dump-check.sh", regenerate the
output.

Part 2/n.

Added: 


Modified: 
clang/test/AST/address_space_attribute.cpp
clang/test/AST/alignas_maybe_odr_cleanup.cpp
clang/test/AST/ast-dump-aarch64-sve-types.c
clang/test/AST/ast-dump-arm-attr.c
clang/test/AST/ast-dump-array.cpp
clang/test/AST/ast-dump-attr.cpp
clang/test/AST/ast-dump-attr.m
clang/test/AST/ast-dump-c-attr.c
clang/test/AST/ast-dump-decl-stmts.cpp
clang/test/AST/ast-dump-decl.c
clang/test/AST/ast-dump-decl.cpp
clang/test/AST/ast-dump-decl.m
clang/test/AST/ast-dump-decl.mm
clang/test/AST/ast-dump-expr.c
clang/test/AST/ast-dump-expr.cpp
clang/test/AST/ast-dump-funcs.cpp
clang/test/AST/ast-dump-msp430-attr.c

Removed: 




diff  --git a/clang/test/AST/address_space_attribute.cpp 
b/clang/test/AST/address_space_attribute.cpp
index 554c9ba0a113..50777ddc7506 100644
--- a/clang/test/AST/address_space_attribute.cpp
+++ b/clang/test/AST/address_space_attribute.cpp
@@ -1,4 +1,11 @@
+// Test without serialization:
 // RUN: %clang_cc1 %s -ast-dump | FileCheck %s
+//
+// Test with serialization:
+// RUN: %clang_cc1 -emit-pch -o %t %s
+// RUN: %clang_cc1 -x c++ -include-pch %t -ast-dump-all /dev/null \
+// RUN: | sed -e "s/ //" -e "s/ imported//" \
+// RUN: | FileCheck %s
 
 // Veryify the ordering of the address_space attribute still comes before the
 // type whereas other attributes are still printed after.

diff  --git a/clang/test/AST/alignas_maybe_odr_cleanup.cpp 
b/clang/test/AST/alignas_maybe_odr_cleanup.cpp
index ebc09084528e..cdff1bfe8b80 100644
--- a/clang/test/AST/alignas_maybe_odr_cleanup.cpp
+++ b/clang/test/AST/alignas_maybe_odr_cleanup.cpp
@@ -1,4 +1,11 @@
+// Test without serialization:
 // RUN: %clang_cc1 -fsyntax-only %s -ast-dump | FileCheck %s
+//
+// Test with serialization:
+// RUN: %clang_cc1 -emit-pch -o %t %s
+// RUN: %clang_cc1 -x c++ -include-pch %t -ast-dump-all /dev/null \
+// RUN: | sed -e "s/ //" -e "s/ imported//" \
+// RUN: | FileCheck %s
 
 struct FOO {
   static const int vec_align_bytes = 32;

diff  --git a/clang/test/AST/ast-dump-aarch64-sve-types.c 
b/clang/test/AST/ast-dump-aarch64-sve-types.c
index a522164124a3..bfb8bc220e8d 100644
--- a/clang/test/AST/ast-dump-aarch64-sve-types.c
+++ b/clang/test/AST/ast-dump-aarch64-sve-types.c
@@ -1,5 +1,13 @@
+// Test without serialization:
 // RUN: %clang_cc1 -triple aarch64-linux-gnu -ast-dump \
 // RUN:   -ast-dump-filter __SV %s | FileCheck %s
+//
+// Test with serialization:
+// RUN: %clang_cc1 -triple aarch64-linux-gnu -emit-pch -o %t %s
+// RUN: %clang_cc1 -x c -triple aarch64-linux-gnu -include-pch %t \
+// RUN: -ast-dump-all -ast-dump-filter __SV /dev/null \
+// RUN: | sed -e "s/ //" -e "s/ imported//" \
+// RUN: | FileCheck %s
 
 // CHECK: TypedefDecl {{.*}} implicit __SVInt8_t '__SVInt8_t'
 // CHECK-NEXT: -BuiltinType {{.*}} '__SVInt8_t'

diff  --git a/clang/test/AST/ast-dump-arm-attr.c 
b/clang/test/AST/ast-dump-arm-attr.c
index 82a797615009..78f557d4eb0b 100644
--- a/clang/test/AST/ast-dump-arm-attr.c
+++ b/clang/test/AST/ast-dump-arm-attr.c
@@ -1,5 +1,20 @@
-// RUN: %clang_cc1 -triple arm-apple-darwin -ast-dump -ast-dump-filter Test %s 
| FileCheck --strict-whitespace %s
-// RUN: %clang_cc1 -triple armv8m.base-none-eabi -mcmse -ast-dump 
-ast-dump-filter Test %s | FileCheck --strict-whitespace %s 
--check-prefix=CHECK-CMSE
+// Tests without serialization:
+// RUN: %clang_cc1 -triple arm-apple-darwin -ast-dump -ast-dump-filter Test %s 
\
+// RUN: | FileCheck --strict-whitespace %s
+//
+// RUN: %clang_cc1 -triple armv8m.base-none-eabi -mcmse -ast-dump 
-ast-dump-filter Test %s \
+// RUN: | FileCheck --strict-whitespace %s --check-prefix=CHECK-CMSE
+//
+// Tests with serialization:
+// RUN: %clang_cc1 -triple arm-apple-darwin -emit-pch -o %t %s
+// RUN: %clang_cc1 -x c -triple arm-apple-darwin -include-pch %t -ast-dump-all 
-ast-dump-filter Test /dev/null \
+// RUN: | sed -e "s/ //" -e "s/ imported//" \
+// RUN: | FileCheck --strict-whitespace %s
+//
+// RUN: %clang_cc1 -triple armv8m.base-none-eabi -mcmse -emit-pch -o %t %s
+// RUN: %clang_cc1 -x c -triple armv8m.base-none-eabi -mcmse -include-pch %t 
-ast-dump-all -ast-dump-filter Test /dev/null \
+// RUN: | sed -e "s/ //" -e "s/ imported//" \
+// RUN: | FileCheck 

[clang] ef3adbf - [clang][NFC] Fix typos/wording in the comments of ConstantExpr.

2020-06-21 Thread Bruno Ricci via cfe-commits

Author: Bruno Ricci
Date: 2020-06-21T13:59:10+01:00
New Revision: ef3adbfc70bd593e14430c2db31c1426d3834fb4

URL: 
https://github.com/llvm/llvm-project/commit/ef3adbfc70bd593e14430c2db31c1426d3834fb4
DIFF: 
https://github.com/llvm/llvm-project/commit/ef3adbfc70bd593e14430c2db31c1426d3834fb4.diff

LOG: [clang][NFC] Fix typos/wording in the comments of ConstantExpr.

It is "trailing objects" and "tail-allocated storage".

Added: 


Modified: 
clang/include/clang/AST/Expr.h
clang/include/clang/AST/Stmt.h

Removed: 




diff  --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index d31f582264b5..f8f104b5580b 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -988,11 +988,11 @@ class ConstantExpr final
 : public FullExpr,
   private llvm::TrailingObjects {
   static_assert(std::is_same::value,
-"this class assumes llvm::APInt::WordType is uint64_t for "
-"trail-allocated storage");
+"ConstantExpr assumes that llvm::APInt::WordType is uint64_t "
+"for tail-allocated storage");
 
 public:
-  /// Describes the kind of result that can be trail-allocated.
+  /// Describes the kind of result that can be tail-allocated.
   enum ResultStorageKind { RSK_None, RSK_Int64, RSK_APValue };
 
 private:

diff  --git a/clang/include/clang/AST/Stmt.h b/clang/include/clang/AST/Stmt.h
index 5c5c20b3676b..d76d99b65551 100644
--- a/clang/include/clang/AST/Stmt.h
+++ b/clang/include/clang/AST/Stmt.h
@@ -322,26 +322,26 @@ class alignas(void *) Stmt {
 
 unsigned : NumExprBits;
 
-/// The kind of result that is trail-allocated.
+/// The kind of result that is tail-allocated.
 unsigned ResultKind : 2;
 
-/// Kind of Result as defined by APValue::Kind
+/// The kind of Result as defined by APValue::Kind
 unsigned APValueKind : 4;
 
-/// When ResultKind == RSK_Int64. whether the trail-allocated integer is
-/// signed.
+/// When ResultKind == RSK_Int64, true if the tail-allocated integer is
+/// unsigned.
 unsigned IsUnsigned : 1;
 
-/// When ResultKind == RSK_Int64. the BitWidth of the trail-allocated
-/// integer. 7 bits because it is the minimal number of bit to represent a
-/// value from 0 to 64 (the size of the trail-allocated number).
+/// When ResultKind == RSK_Int64. the BitWidth of the tail-allocated
+/// integer. 7 bits because it is the minimal number of bits to represent a
+/// value from 0 to 64 (the size of the tail-allocated integer).
 unsigned BitWidth : 7;
 
-/// When ResultKind == RSK_APValue. Wether the ASTContext will cleanup the
-/// destructor on the trail-allocated APValue.
+/// When ResultKind == RSK_APValue, true if the ASTContext will cleanup the
+/// tail-allocated APValue.
 unsigned HasCleanup : 1;
 
-/// Whether this ConstantExpr was created for immediate invocation.
+/// True if this ConstantExpr was created for immediate invocation.
 unsigned IsImmediateInvocation : 1;
   };
 



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


[clang] e7ce052 - [clang][Serialization] Fix the serialization of ConstantExpr.

2020-06-21 Thread Bruno Ricci via cfe-commits

Author: Bruno Ricci
Date: 2020-06-21T13:59:10+01:00
New Revision: e7ce0528202306d8b751f132d9d3a6519ce4e688

URL: 
https://github.com/llvm/llvm-project/commit/e7ce0528202306d8b751f132d9d3a6519ce4e688
DIFF: 
https://github.com/llvm/llvm-project/commit/e7ce0528202306d8b751f132d9d3a6519ce4e688.diff

LOG: [clang][Serialization] Fix the serialization of ConstantExpr.

The serialization of ConstantExpr has currently a number of problems:

- Some fields are just not serialized (ConstantExprBits.APValueKind and
  ConstantExprBits.IsImmediateInvocation).

- ASTStmtReader::VisitConstantExpr forgets to add the trailing APValue
  to the list of objects to be destroyed when the APValue needs cleanup.

While we are at it, bring the serialization of ConstantExpr more in-line
with what is done with the other expressions by doing the following NFCs:

- Get rid of ConstantExpr::DefaultInit. It is better to not initialize
  the fields of an empty ConstantExpr since this will allow msan to
  detect if a field was not deserialized.

- Move the initialization of the fields of ConstantExpr to the constructor;
  ConstantExpr::Create allocates the memory and ConstantExpr::ConstantExpr
  is responsible for the initialization.

Review after commit since this is a straightforward mechanical fix
similar to the other serialization fixes.

Added: 
clang/test/AST/ast-dump-constant-expr.cpp

Modified: 
clang/include/clang/AST/Expr.h
clang/include/clang/AST/Stmt.h
clang/lib/AST/Expr.cpp
clang/lib/Serialization/ASTReaderStmt.cpp
clang/lib/Serialization/ASTWriterStmt.cpp

Removed: 




diff  --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index f8f104b5580b..8ee8aa96ae63 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -990,6 +990,9 @@ class ConstantExpr final
   static_assert(std::is_same::value,
 "ConstantExpr assumes that llvm::APInt::WordType is uint64_t "
 "for tail-allocated storage");
+  friend TrailingObjects;
+  friend class ASTStmtReader;
+  friend class ASTStmtWriter;
 
 public:
   /// Describes the kind of result that can be tail-allocated.
@@ -1003,7 +1006,6 @@ class ConstantExpr final
 return ConstantExprBits.ResultKind == ConstantExpr::RSK_Int64;
   }
 
-  void DefaultInit(ResultStorageKind StorageKind);
   uint64_t () {
 assert(ConstantExprBits.ResultKind == ConstantExpr::RSK_Int64 &&
"invalid accessor");
@@ -1021,21 +1023,18 @@ class ConstantExpr final
 return const_cast(this)->APValueResult();
   }
 
-  ConstantExpr(Expr *subexpr, ResultStorageKind StorageKind);
-  ConstantExpr(ResultStorageKind StorageKind, EmptyShell Empty);
+  ConstantExpr(Expr *SubExpr, ResultStorageKind StorageKind,
+   bool IsImmediateInvocation);
+  ConstantExpr(EmptyShell Empty, ResultStorageKind StorageKind);
 
 public:
-  friend TrailingObjects;
-  friend class ASTStmtReader;
-  friend class ASTStmtWriter;
   static ConstantExpr *Create(const ASTContext , Expr *E,
   const APValue );
   static ConstantExpr *Create(const ASTContext , Expr *E,
   ResultStorageKind Storage = RSK_None,
   bool IsImmediateInvocation = false);
   static ConstantExpr *CreateEmpty(const ASTContext ,
-   ResultStorageKind StorageKind,
-   EmptyShell Empty);
+   ResultStorageKind StorageKind);
 
   static ResultStorageKind getStorageKind(const APValue );
   static ResultStorageKind getStorageKind(const Type *T,

diff  --git a/clang/include/clang/AST/Stmt.h b/clang/include/clang/AST/Stmt.h
index d76d99b65551..a226790aa76c 100644
--- a/clang/include/clang/AST/Stmt.h
+++ b/clang/include/clang/AST/Stmt.h
@@ -325,7 +325,7 @@ class alignas(void *) Stmt {
 /// The kind of result that is tail-allocated.
 unsigned ResultKind : 2;
 
-/// The kind of Result as defined by APValue::Kind
+/// The kind of Result as defined by APValue::Kind.
 unsigned APValueKind : 4;
 
 /// When ResultKind == RSK_Int64, true if the tail-allocated integer is

diff  --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index 27a12b880a7b..5cbd66f11601 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -244,6 +244,7 @@ static void 
AssertResultStorageKind(ConstantExpr::ResultStorageKind Kind) {
   assert((Kind == ConstantExpr::RSK_APValue ||
   Kind == ConstantExpr::RSK_Int64 || Kind == ConstantExpr::RSK_None) &&
  "Invalid StorageKind Value");
+  (void)Kind;
 }
 
 ConstantExpr::ResultStorageKind
@@ -268,33 +269,31 @@ ConstantExpr::getStorageKind(const Type *T, const 
ASTContext ) {
   return ConstantExpr::RSK_APValue;
 }
 
-void ConstantExpr::DefaultInit(ResultStorageKind StorageKind) {
+ConstantExpr::ConstantExpr(Expr *SubExpr, 

[clang] e560280 - [clang][NFC] Regenerate test/AST/ast-dump-lambda.cpp with --match-full-lines.

2020-06-21 Thread Bruno Ricci via cfe-commits

Author: Bruno Ricci
Date: 2020-06-21T13:59:11+01:00
New Revision: e560280cd5739503cd9a75e05da769a6742918b5

URL: 
https://github.com/llvm/llvm-project/commit/e560280cd5739503cd9a75e05da769a6742918b5
DIFF: 
https://github.com/llvm/llvm-project/commit/e560280cd5739503cd9a75e05da769a6742918b5.diff

LOG: [clang][NFC] Regenerate test/AST/ast-dump-lambda.cpp with 
--match-full-lines.

Added: 


Modified: 
clang/test/AST/ast-dump-lambda.cpp

Removed: 




diff  --git a/clang/test/AST/ast-dump-lambda.cpp 
b/clang/test/AST/ast-dump-lambda.cpp
index 4b53b17aa284..a3ca4a8fc534 100644
--- a/clang/test/AST/ast-dump-lambda.cpp
+++ b/clang/test/AST/ast-dump-lambda.cpp
@@ -1,12 +1,14 @@
 // Test without serialization:
 // RUN: %clang_cc1 -triple x86_64-unknown-unknown -Wno-unused-value 
-std=gnu++17 \
-// RUN: -ast-dump %s | FileCheck 
-strict-whitespace %s
+// RUN: -ast-dump %s -ast-dump-filter 
test \
+// RUN: | FileCheck -strict-whitespace --match-full-lines %s
 
 // Test with serialization:
 // RUN: %clang_cc1 -triple x86_64-unknown-unknown -Wno-unused-value 
-std=gnu++17 \
 // RUN:-emit-pch -o %t %s
 // RUN: %clang_cc1 -triple x86_64-unknown-unknown -Wno-unused-value 
-std=gnu++17 \
-// RUN:-x c++ -include-pch %t -ast-dump-all | FileCheck 
-strict-whitespace %s
+// RUN:-x c++ -include-pch %t -ast-dump-all -ast-dump-filter test \
+// RUN: | FileCheck -strict-whitespace --match-full-lines %s
 
 
 
@@ -32,262 +34,262 @@ template  void test(Ts... a) {
   []() noexcept {};
   []() -> int { return 0; };
 }
-// CHECK: TranslationUnitDecl {{.*}} <> {{( 
)?}}
-// CHECK: `-FunctionTemplateDecl {{.*}} <{{.*}}ast-dump-lambda.cpp:13:1, 
line:34:1> line:13:32{{( imported)?}} test
-// CHECK-NEXT:   |-TemplateTypeParmDecl {{.*}}  col:23{{( 
imported)?}} referenced typename depth 0 index 0 ... Ts
-// CHECK-NEXT:   `-FunctionDecl {{.*}}  line:13:32{{( 
imported)?}} test 'void (Ts...)'
-// CHECK-NEXT: |-ParmVarDecl {{.*}}  col:43{{( 
imported)?}} referenced a 'Ts...' pack
-// CHECK-NEXT: `-CompoundStmt {{.*}} 
-// CHECK-NEXT:   |-DeclStmt {{.*}} 
-// CHECK-NEXT:   | `-CXXRecordDecl {{.*}}  
line:14:10{{( imported)?}}{{( )?}} struct V 
definition
-// CHECK-NEXT:   |   |-DefinitionData empty aggregate standard_layout 
trivially_copyable pod trivial literal has_constexpr_non_copy_move_ctor 
can_const_default_init
-// CHECK-NEXT:   |   | |-DefaultConstructor exists trivial constexpr 
needs_implicit defaulted_is_constexpr
-// CHECK-NEXT:   |   | |-CopyConstructor simple trivial has_const_param 
needs_implicit implicit_has_const_param
-// CHECK-NEXT:   |   | |-MoveConstructor exists simple trivial 
needs_implicit
-// CHECK-NEXT:   |   | |-CopyAssignment simple trivial has_const_param 
needs_implicit implicit_has_const_param
-// CHECK-NEXT:   |   | |-MoveAssignment exists simple trivial 
needs_implicit
-// CHECK-NEXT:   |   | `-Destructor simple irrelevant trivial 
needs_implicit
-// CHECK-NEXT:   |   |-CXXRecordDecl {{.*}}  col:10{{( 
imported)?}} implicit struct V
-// CHECK-NEXT:   |   `-CXXMethodDecl {{.*}}  
line:15:10{{( imported)?}} f 'void ()'
-// CHECK-NEXT:   | `-CompoundStmt {{.*}} 
-// CHECK-NEXT:   |   |-LambdaExpr {{.*}}  '(lambda 
at {{.*}}ast-dump-lambda.cpp:16:7)'
-// CHECK-NEXT:   |   | |-CXXRecordDecl {{.*}}  col:7{{( 
imported)?}} implicit{{( )?}} class definition
-// CHECK-NEXT:   |   | | |-DefinitionData lambda standard_layout 
trivially_copyable can_const_default_init
-// CHECK-NEXT:   |   | | | |-DefaultConstructor
-// CHECK-NEXT:   |   | | | |-CopyConstructor simple trivial 
has_const_param needs_implicit implicit_has_const_param
-// CHECK-NEXT:   |   | | | |-MoveConstructor exists simple trivial 
needs_implicit
-// CHECK-NEXT:   |   | | | |-CopyAssignment trivial has_const_param 
needs_implicit implicit_has_const_param
-// CHECK-NEXT:   |   | | | |-MoveAssignment
-// CHECK-NEXT:   |   | | | `-Destructor simple irrelevant trivial 
needs_implicit
-// CHECK-NEXT:   |   | | |-CXXMethodDecl {{.*}}  
col:7{{( imported)?}} operator() 'auto () const -> auto' inline
-// CHECK-NEXT:   |   | | | `-CompoundStmt {{.*}} 
-// CHECK-NEXT:   |   | | `-FieldDecl {{.*}}  col:8{{( 
imported)?}} implicit 'V *'
-// CHECK-NEXT:   |   | |-ParenListExpr {{.*}}  'NULL TYPE'
-// CHECK-NEXT:   |   | | `-CXXThisExpr {{.*}}  'V *' this
-// CHECK-NEXT:   |   | `-CompoundStmt {{.*}} 
-// CHECK-NEXT:   |   `-LambdaExpr {{.*}}  '(lambda 
at {{.*}}ast-dump-lambda.cpp:17:7)'
-// CHECK-NEXT:   | |-CXXRecordDecl {{.*}}  col:7{{( 
imported)?}} implicit{{( )?}} class definition
-// CHECK-NEXT:   | | |-DefinitionData lambda standard_layout 

[clang] cddc999 - [clang][test][NFC] Also test for serialization in AST dump tests, part 3/n.

2020-06-21 Thread Bruno Ricci via cfe-commits

Author: Bruno Ricci
Date: 2020-06-21T13:59:11+01:00
New Revision: cddc9993eafd76f08989beea037d085521d48127

URL: 
https://github.com/llvm/llvm-project/commit/cddc9993eafd76f08989beea037d085521d48127
DIFF: 
https://github.com/llvm/llvm-project/commit/cddc9993eafd76f08989beea037d085521d48127.diff

LOG: [clang][test][NFC] Also test for serialization in AST dump tests, part 3/n.

The outputs between the direct ast-dump test and the ast-dump test after
deserialization should match modulo a few differences.

For hand-written tests, strip the ""s and
the "imported"s with sed.

For tests generated with "make-ast-dump-check.sh", regenerate the output.

Part 3/n.

Added: 


Modified: 
clang/test/AST/atomic-expr.cpp
clang/test/AST/c-casts.c
clang/test/AST/category-attribute.m
clang/test/AST/coroutine-source-location-crash.cpp
clang/test/AST/deduction-guides.cpp
clang/test/AST/fixed_point.c
clang/test/AST/fixed_point_to_string.c
clang/test/AST/float16.cpp
clang/test/AST/implicit-cast-dump.c
clang/test/AST/language_address_space_attribute.cpp
clang/test/AST/multistep-explicit-cast.c
clang/test/AST/multistep-explicit-cast.cpp
clang/test/AST/pr43983.cpp
clang/test/AST/property-atomic-bool.m
clang/test/AST/template-implicit-vars.cpp
clang/test/AST/variadic-promotion.c

Removed: 




diff  --git a/clang/test/AST/atomic-expr.cpp b/clang/test/AST/atomic-expr.cpp
index e7fb6ba833e5..db21d61e98c2 100644
--- a/clang/test/AST/atomic-expr.cpp
+++ b/clang/test/AST/atomic-expr.cpp
@@ -1,4 +1,11 @@
+// Test without serialization:
 // RUN: %clang_cc1 -ast-dump %s | FileCheck %s
+//
+// Test with serialization:
+// RUN: %clang_cc1 -emit-pch -o %t %s
+// RUN: %clang_cc1 -x c++ -include-pch %t -ast-dump-all /dev/null \
+// RUN: | sed -e "s/ //" -e "s/ imported//" \
+// RUN: | FileCheck %s
 
 template
 void pr43370() {
@@ -17,14 +24,14 @@ void useage(){
   foo();
 }
 
-// CHECK:FunctionTemplateDecl 0x{{[0-9a-f]+}} <{{[^,]+}}, line:7:1> line:4:6 
pr43370
+// CHECK:FunctionTemplateDecl 0x{{[0-9a-f]+}} <{{[^,]+}}, line:{{.*}}:1> 
line:{{.*}}:6 pr43370
 // CHECK: AtomicExpr
 // CHECK-NEXT: ImplicitCastExpr
 // CHECK-SAME: 
 // CHECK-NEXT: DeclRefExpr 0x{{[0-9a-f]+}} <{{[^:]+}}:20> 'int [2]' lvalue Var 
0x{{[0-9a-f]+}} 'arr' 'int [2]'
 // CHECK-NEXT: IntegerLiteral 0x{{[0-9a-f]+}} <{{[^:]+}}:28> 'int' 5
 // CHECK-NEXT: IntegerLiteral 0x{{[0-9a-f]+}} <{{[^:]+}}:25> 'int' 0
-// CHECK:FunctionDecl 0x{{[0-9a-f]+}}  line:4:6 used 
pr43370
+// CHECK:FunctionDecl 0x{{[0-9a-f]+}}  
line:{{.*}}:6 used pr43370
 // CHECK: AtomicExpr
 // CHECK-NEXT: ImplicitCastExpr
 // CHECK-SAME: 
@@ -32,7 +39,7 @@ void useage(){
 // CHECK-NEXT: IntegerLiteral 0x{{[0-9a-f]+}} <{{[^:]+}}:28> 'int' 5
 // CHECK-NEXT: IntegerLiteral 0x{{[0-9a-f]+}} <{{[^:]+}}:25> 'int' 0
 
-// CHECK:FunctionTemplateDecl 0x{{[0-9a-f]+}}  line:10:6 
foo
+// CHECK:FunctionTemplateDecl 0x{{[0-9a-f]+}}  
line:{{.*}}:6 foo
 // CHECK: AtomicExpr
 // CHECK-NEXT: ImplicitCastExpr
 // CHECK-SAME: 
@@ -45,7 +52,7 @@ void useage(){
 // CHECK-NEXT: IntegerLiteral 0x{{[0-9a-f]+}} <{{[^:]+}}:47> 'int' 1
 // CHECK-NEXT: ImplicitCastExpr
 // CHECK-NEXT: IntegerLiteral 0x{{[0-9a-f]+}} <{{[^:]+}}:50> 'int' 0
-// CHECK:FunctionDecl 0x{{[0-9a-f]+}}  line:10:6 used foo
+// CHECK:FunctionDecl 0x{{[0-9a-f]+}}  
line:{{.*}}:6 used foo
 // CHECK: AtomicExpr
 // CHECK-NEXT: ImplicitCastExpr
 // CHECK-SAME: 

diff  --git a/clang/test/AST/c-casts.c b/clang/test/AST/c-casts.c
index c3a58ed8274c..5eaa4aaf2345 100644
--- a/clang/test/AST/c-casts.c
+++ b/clang/test/AST/c-casts.c
@@ -1,4 +1,11 @@
+// Test without serialization:
 // RUN: %clang_cc1 -w -ast-dump %s | FileCheck %s
+//
+// Test with serialization:
+// RUN: %clang_cc1 -w -emit-pch -o %t %s
+// RUN: %clang_cc1 -w -x c -include-pch %t -ast-dump-all /dev/null \
+// RUN: | sed -e "s/ //" -e "s/ imported//" \
+// RUN: | FileCheck %s
 
 // The cast construction code both for implicit and c-style casts is very
 // 
diff erent in C vs C++. This file is intended to test the C behavior.

diff  --git a/clang/test/AST/category-attribute.m 
b/clang/test/AST/category-attribute.m
index 7efe3df00ec8..e74f1a1ffbc1 100644
--- a/clang/test/AST/category-attribute.m
+++ b/clang/test/AST/category-attribute.m
@@ -1,5 +1,13 @@
+// Test without serialization:
 // RUN: %clang_cc1 -fsyntax-only -verify %s
 // RUN: %clang_cc1 -fsyntax-only -ast-dump %s | FileCheck %s
+//
+// Test with serialization:
+// RUN: %clang_cc1 -emit-pch -o %t %s
+// RUN: %clang_cc1 -x objective-c -include-pch %t -ast-dump-all /dev/null \
+// RUN: | sed -e "s/ //" -e "s/ imported//" \
+// RUN: | FileCheck %s
+//
 // expected-no-diagnostics
 
 __attribute__ ((external_source_symbol(language= "Swift", defined_in="A")))

diff  --git a/clang/test/AST/coroutine-source-location-crash.cpp 
b/clang/test/AST/coroutine-source-location-crash.cpp
index 

[clang] f5bbe39 - [clang] SequenceChecker: C++17 sequencing rule for overloaded operators.

2020-06-20 Thread Bruno Ricci via cfe-commits

Author: Bruno Ricci
Date: 2020-06-20T10:51:46+01:00
New Revision: f5bbe390d23d7da0ffb110cdb24b583c2dc87eba

URL: 
https://github.com/llvm/llvm-project/commit/f5bbe390d23d7da0ffb110cdb24b583c2dc87eba
DIFF: 
https://github.com/llvm/llvm-project/commit/f5bbe390d23d7da0ffb110cdb24b583c2dc87eba.diff

LOG: [clang] SequenceChecker: C++17 sequencing rule for overloaded operators.

In C++17 the operand(s) of an overloaded operator are sequenced as for
the corresponding built-in operator when the overloaded operator is
called with the operator notation ([over.match.oper]p2).

Reported in PR35340.

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

Reviewed By: rsmith

Added: 


Modified: 
clang/lib/Sema/SemaChecking.cpp
clang/test/SemaCXX/warn-unsequenced.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index f5f6b7bfb0f0..883ff17eb279 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -13031,6 +13031,130 @@ class SequenceChecker : public 
ConstEvaluatedExprVisitor {
 });
   }
 
+  void VisitCXXOperatorCallExpr(const CXXOperatorCallExpr *CXXOCE) {
+// C++17 [over.match.oper]p2:
+//   [...] the operator notation is first transformed to the equivalent
+//   function-call notation as summarized in Table 12 (where @ denotes one
+//   of the operators covered in the specified subclause). However, the
+//   operands are sequenced in the order prescribed for the built-in
+//   operator (Clause 8).
+//
+// From the above only overloaded binary operators and overloaded call
+// operators have sequencing rules in C++17 that we need to handle
+// separately.
+if (!SemaRef.getLangOpts().CPlusPlus17 ||
+(CXXOCE->getNumArgs() != 2 && CXXOCE->getOperator() != OO_Call))
+  return VisitCallExpr(CXXOCE);
+
+enum {
+  NoSequencing,
+  LHSBeforeRHS,
+  RHSBeforeLHS,
+  LHSBeforeRest
+} SequencingKind;
+switch (CXXOCE->getOperator()) {
+case OO_Equal:
+case OO_PlusEqual:
+case OO_MinusEqual:
+case OO_StarEqual:
+case OO_SlashEqual:
+case OO_PercentEqual:
+case OO_CaretEqual:
+case OO_AmpEqual:
+case OO_PipeEqual:
+case OO_LessLessEqual:
+case OO_GreaterGreaterEqual:
+  SequencingKind = RHSBeforeLHS;
+  break;
+
+case OO_LessLess:
+case OO_GreaterGreater:
+case OO_AmpAmp:
+case OO_PipePipe:
+case OO_Comma:
+case OO_ArrowStar:
+case OO_Subscript:
+  SequencingKind = LHSBeforeRHS;
+  break;
+
+case OO_Call:
+  SequencingKind = LHSBeforeRest;
+  break;
+
+default:
+  SequencingKind = NoSequencing;
+  break;
+}
+
+if (SequencingKind == NoSequencing)
+  return VisitCallExpr(CXXOCE);
+
+// This is a call, so all subexpressions are sequenced before the result.
+SequencedSubexpression Sequenced(*this);
+
+SemaRef.runWithSufficientStackSpace(CXXOCE->getExprLoc(), [&] {
+  assert(SemaRef.getLangOpts().CPlusPlus17 &&
+ "Should only get there with C++17 and above!");
+  assert((CXXOCE->getNumArgs() == 2 || CXXOCE->getOperator() == OO_Call) &&
+ "Should only get there with an overloaded binary operator"
+ " or an overloaded call operator!");
+
+  if (SequencingKind == LHSBeforeRest) {
+assert(CXXOCE->getOperator() == OO_Call &&
+   "We should only have an overloaded call operator here!");
+
+// This is very similar to VisitCallExpr, except that we only have the
+// C++17 case. The postfix-expression is the first argument of the
+// CXXOperatorCallExpr. The expressions in the expression-list, if any,
+// are in the following arguments.
+//
+// Note that we intentionally do not visit the callee expression since
+// it is just a decayed reference to a function.
+SequenceTree::Seq PostfixExprRegion = Tree.allocate(Region);
+SequenceTree::Seq ArgsRegion = Tree.allocate(Region);
+SequenceTree::Seq OldRegion = Region;
+
+assert(CXXOCE->getNumArgs() >= 1 &&
+   "An overloaded call operator must have at least one argument"
+   " for the postfix-expression!");
+const Expr *PostfixExpr = CXXOCE->getArgs()[0];
+llvm::ArrayRef Args(CXXOCE->getArgs() + 1,
+  CXXOCE->getNumArgs() - 1);
+
+// Visit the postfix-expression first.
+{
+  Region = PostfixExprRegion;
+  SequencedSubexpression Sequenced(*this);
+  Visit(PostfixExpr);
+}
+
+// Then visit the argument expressions.
+Region = ArgsRegion;
+for (const Expr *Arg : Args)
+  Visit(Arg);
+
+Region = OldRegion;
+Tree.merge(PostfixExprRegion);
+Tree.merge(ArgsRegion);
+  } 

[clang] d3b7528 - [clang][test][NFC] Also test for serialization in AST dump tests, part 1/n.

2020-06-19 Thread Bruno Ricci via cfe-commits

Author: Bruno Ricci
Date: 2020-06-19T13:40:20+01:00
New Revision: d3b752845df0331348dad48000fc8b82afb3de5b

URL: 
https://github.com/llvm/llvm-project/commit/d3b752845df0331348dad48000fc8b82afb3de5b
DIFF: 
https://github.com/llvm/llvm-project/commit/d3b752845df0331348dad48000fc8b82afb3de5b.diff

LOG: [clang][test][NFC] Also test for serialization in AST dump tests, part 1/n.

The outputs between the direct ast-dump test and the ast-dump test after
deserialization should match modulo a few differences.

For hand-written tests, strip the ""s and
the "imported"s with sed.

For tests generated with "make-ast-dump-check.sh", regenerate the
output.

Part 1/n.

Added: 


Modified: 
clang/test/AST/ast-dump-overloaded-operators.cpp
clang/test/AST/ast-dump-pipe.cl
clang/test/AST/ast-dump-record-definition-data.cpp
clang/test/AST/ast-dump-records.c
clang/test/AST/ast-dump-records.cpp
clang/test/AST/ast-dump-special-member-functions.cpp
clang/test/AST/ast-dump-stmt.c
clang/test/AST/ast-dump-stmt.cpp
clang/test/AST/ast-dump-stmt.m
clang/test/AST/ast-dump-template-decls.cpp
clang/test/AST/ast-dump-traits.cpp
clang/test/AST/ast-dump-wasm-attr-export.c
clang/test/AST/ast-dump-wasm-attr-import.c
clang/test/AST/ast-dump-wchar.cpp

Removed: 




diff  --git a/clang/test/AST/ast-dump-overloaded-operators.cpp 
b/clang/test/AST/ast-dump-overloaded-operators.cpp
index cd4e14be9f1a..639a0d9874eb 100644
--- a/clang/test/AST/ast-dump-overloaded-operators.cpp
+++ b/clang/test/AST/ast-dump-overloaded-operators.cpp
@@ -1,4 +1,11 @@
-// RUN: %clang_cc1 -triple x86_64-unknown-unknown -ast-dump %s | FileCheck 
-strict-whitespace %s
+// Test without serialization:
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -ast-dump %s \
+// RUN: | FileCheck -strict-whitespace %s
+//
+// Test with serialization:
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-pch -o %t %s
+// RUN: %clang_cc1 -x c++ -triple x86_64-unknown-unknown -include-pch %t 
-ast-dump-all /dev/null \
+// RUN: | FileCheck -strict-whitespace %s
 
 enum E {};
 void operator+(E,E);
@@ -9,19 +16,26 @@ void test() {
   e + e;
   e , e;
 }
-// CHECK: TranslationUnitDecl {{.*}} <> 
-// CHECK: `-FunctionDecl {{.*}}  line:7:6 test 'void ()'
-// CHECK-NEXT:   `-CompoundStmt {{.*}} 
-// CHECK-NEXT: |-DeclStmt {{.*}} 
-// CHECK-NEXT: | `-VarDecl {{.*}}  col:5 used e 'E'
-// CHECK-NEXT: |-CXXOperatorCallExpr {{.*}}  'void' '+'
+// CHECK: TranslationUnitDecl {{.*}} <> {{( 
)?}}
+// CHECK: |-EnumDecl {{.*}} <{{.*}}ast-dump-overloaded-operators.cpp:10:1, 
col:9> col:6{{( imported)?}} referenced E
+// CHECK-NEXT: |-FunctionDecl {{.*}}  col:6{{( imported)?}} 
used operator+ 'void (E, E)'
+// CHECK-NEXT: | |-ParmVarDecl {{.*}}  col:17{{( imported)?}} 'E'
+// CHECK-NEXT: | `-ParmVarDecl {{.*}}  col:19{{( imported)?}} 'E'
+// CHECK-NEXT: |-FunctionDecl {{.*}}  col:6{{( imported)?}} 
used operator, 'void (E, E)'
+// CHECK-NEXT: | |-ParmVarDecl {{.*}}  col:17{{( imported)?}} 'E'
+// CHECK-NEXT: | `-ParmVarDecl {{.*}}  col:19{{( imported)?}} 'E'
+// CHECK-NEXT: `-FunctionDecl {{.*}}  line:14:6{{( 
imported)?}} test 'void ()'
+// CHECK-NEXT:   `-CompoundStmt {{.*}} 
+// CHECK-NEXT: |-DeclStmt {{.*}} 
+// CHECK-NEXT: | `-VarDecl {{.*}}  col:5{{( imported)?}} 
used e 'E'
+// CHECK-NEXT: |-CXXOperatorCallExpr {{.*}}  'void' '+'
 // CHECK-NEXT: | |-ImplicitCastExpr {{.*}}  'void (*)(E, E)' 

 // CHECK-NEXT: | | `-DeclRefExpr {{.*}}  'void (E, E)' lvalue 
Function {{.*}} 'operator+' 'void (E, E)'
 // CHECK-NEXT: | |-ImplicitCastExpr {{.*}}  'E' 
 // CHECK-NEXT: | | `-DeclRefExpr {{.*}}  'E' lvalue Var {{.*}} 'e' 
'E'
 // CHECK-NEXT: | `-ImplicitCastExpr {{.*}}  'E' 
 // CHECK-NEXT: |   `-DeclRefExpr {{.*}}  'E' lvalue Var {{.*}} 'e' 
'E'
-// CHECK-NEXT: `-CXXOperatorCallExpr {{.*}}  'void' ','
+// CHECK-NEXT: `-CXXOperatorCallExpr {{.*}}  'void' ','
 // CHECK-NEXT:   |-ImplicitCastExpr {{.*}}  'void (*)(E, E)' 

 // CHECK-NEXT:   | `-DeclRefExpr {{.*}}  'void (E, E)' lvalue 
Function {{.*}} 'operator,' 'void (E, E)'
 // CHECK-NEXT:   |-ImplicitCastExpr {{.*}}  'E' 

diff  --git a/clang/test/AST/ast-dump-pipe.cl b/clang/test/AST/ast-dump-pipe.cl
index ceed2f6f8992..b4f78e1a7412 100644
--- a/clang/test/AST/ast-dump-pipe.cl
+++ b/clang/test/AST/ast-dump-pipe.cl
@@ -1,4 +1,13 @@
-// RUN: %clang_cc1 -triple spir64 -cl-std=CL2.0 -ast-dump -ast-dump-filter 
pipetype %s | FileCheck -strict-whitespace %s
+// Test without serialization:
+// RUN: %clang_cc1 -triple spir64 -cl-std=CL2.0 -ast-dump -ast-dump-filter 
pipetype %s \
+// RUN: | FileCheck -strict-whitespace %s
+//
+// Test with serialization:
+// RUN: %clang_cc1 -triple spir64 -cl-std=CL2.0 -emit-pch -o %t %s
+// RUN: %clang_cc1 -x cl -triple spir64 -cl-std=CL2.0 -include-pch %t 
-ast-dump-all -ast-dump-filter pipetype /dev/null \
+// RUN: 

[clang] 70f952b - [clang][utils] Also match "col:" when looking for the end of builtins

2020-06-19 Thread Bruno Ricci via cfe-commits

Author: Bruno Ricci
Date: 2020-06-19T13:40:20+01:00
New Revision: 70f952bebe38f8117e6ce8986cd39f735b7b3d69

URL: 
https://github.com/llvm/llvm-project/commit/70f952bebe38f8117e6ce8986cd39f735b7b3d69
DIFF: 
https://github.com/llvm/llvm-project/commit/70f952bebe38f8117e6ce8986cd39f735b7b3d69.diff

LOG: [clang][utils] Also match "col:" when looking for the end of builtins

Some AST dump tests have no "line:" at all. See "ast-dump-wchar.cpp" for
an example.

Added: 


Modified: 
clang/utils/make-ast-dump-check.sh

Removed: 




diff  --git a/clang/utils/make-ast-dump-check.sh 
b/clang/utils/make-ast-dump-check.sh
index 578c725f48b1..4e8a1c198608 100755
--- a/clang/utils/make-ast-dump-check.sh
+++ b/clang/utils/make-ast-dump-check.sh
@@ -48,6 +48,10 @@ BEGIN {
   skipping_builtins = 0
 }
 
+/^[\`|].* col:/ {
+  skipping_builtins = 0
+}
+
 {
   if (skipping_builtins == 1) {
 matched_last_line = 0



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


[clang] 05843dc - [clang] Fix the serialization of LambdaExpr and the bogus mutation in LambdaExpr::getBody

2020-06-18 Thread Bruno Ricci via cfe-commits

Author: Bruno Ricci
Date: 2020-06-18T13:37:24+01:00
New Revision: 05843dc6ab97a00cbde7aa4f08bf3692eb83109d

URL: 
https://github.com/llvm/llvm-project/commit/05843dc6ab97a00cbde7aa4f08bf3692eb83109d
DIFF: 
https://github.com/llvm/llvm-project/commit/05843dc6ab97a00cbde7aa4f08bf3692eb83109d.diff

LOG: [clang] Fix the serialization of LambdaExpr and the bogus mutation in 
LambdaExpr::getBody

The body of LambdaExpr is currently not properly serialized. Instead
LambdaExpr::getBody checks if the body has been already deserialized and if
not mutates LambdaExpr. This can be observed with an AST dump test, where
the body of the LambdaExpr will be null.

The mutation in LambdaExpr::getBody was left because of another bug: it is not
true that the body of a LambdaExpr is always a CompoundStmt; it can also be
a CoroutineBodyStmt wrapping a CompoundStmt. This is fixed by returning a
Stmt * from getBody and introducing a convenience function getCompoundStmtBody
which always returns a CompoundStmt *. This function can be used by callers who
do not care about the coroutine node.

Happily all but one user of getBody treat it as a Stmt * and so this change
is non-intrusive.

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

Reviewed By: aaron.ballman

Added: 


Modified: 
clang/include/clang/AST/ExprCXX.h
clang/lib/AST/ExprCXX.cpp
clang/lib/AST/StmtPrinter.cpp
clang/lib/Serialization/ASTReaderStmt.cpp
clang/lib/Serialization/ASTWriterStmt.cpp
clang/test/AST/ast-dump-lambda.cpp

Removed: 




diff  --git a/clang/include/clang/AST/ExprCXX.h 
b/clang/include/clang/AST/ExprCXX.h
index 822025a7503f..4c65daaa63fc 100644
--- a/clang/include/clang/AST/ExprCXX.h
+++ b/clang/include/clang/AST/ExprCXX.h
@@ -26,6 +26,7 @@
 #include "clang/AST/NestedNameSpecifier.h"
 #include "clang/AST/OperationKinds.h"
 #include "clang/AST/Stmt.h"
+#include "clang/AST/StmtCXX.h"
 #include "clang/AST/TemplateBase.h"
 #include "clang/AST/Type.h"
 #include "clang/AST/UnresolvedSet.h"
@@ -2004,8 +2005,25 @@ class LambdaExpr final : public Expr,
   /// Whether this is a generic lambda.
   bool isGenericLambda() const { return getTemplateParameterList(); }
 
-  /// Retrieve the body of the lambda.
-  CompoundStmt *getBody() const;
+  /// Retrieve the body of the lambda. This will be most of the time
+  /// a \p CompoundStmt, but can also be \p CoroutineBodyStmt wrapping
+  /// a \p CompoundStmt. Note that unlike functions, lambda-expressions
+  /// cannot have a function-try-block.
+  Stmt *getBody() const { return getStoredStmts()[capture_size()]; }
+
+  /// Retrieve the \p CompoundStmt representing the body of the lambda.
+  /// This is a convenience function for callers who do not need
+  /// to handle node(s) which may wrap a \p CompoundStmt.
+  const CompoundStmt *getCompoundStmtBody() const {
+Stmt *Body = getBody();
+if (const auto *CoroBody = dyn_cast(Body))
+  return cast(CoroBody->getBody());
+return cast(Body);
+  }
+  CompoundStmt *getCompoundStmtBody() {
+const auto *ConstThis = this;
+return const_cast(ConstThis->getCompoundStmtBody());
+  }
 
   /// Determine whether the lambda is mutable, meaning that any
   /// captures values can be modified.

diff  --git a/clang/lib/AST/ExprCXX.cpp b/clang/lib/AST/ExprCXX.cpp
index 8588e9b47d65..f9f825b29ed0 100644
--- a/clang/lib/AST/ExprCXX.cpp
+++ b/clang/lib/AST/ExprCXX.cpp
@@ -1118,15 +1118,6 @@ LambdaExpr::LambdaExpr(QualType T, SourceRange 
IntroducerRange,
 LambdaExpr::LambdaExpr(EmptyShell Empty, unsigned NumCaptures)
 : Expr(LambdaExprClass, Empty) {
   LambdaExprBits.NumCaptures = NumCaptures;
-
-  // FIXME: There is no need to do this since these members should be
-  // initialized during deserialization.
-  LambdaExprBits.CaptureDefault = LCD_None;
-  LambdaExprBits.ExplicitParams = false;
-  LambdaExprBits.ExplicitResultType = false;
-
-  // FIXME: Remove once the bug in LambdaExpr::getBody is fixed.
-  getStoredStmts()[capture_size()] = nullptr;
 }
 
 LambdaExpr *LambdaExpr::Create(const ASTContext , CXXRecordDecl *Class,
@@ -1223,17 +1214,6 @@ ArrayRef 
LambdaExpr::getExplicitTemplateParameters() const {
   return Record->getLambdaExplicitTemplateParameters();
 }
 
-CompoundStmt *LambdaExpr::getBody() const {
-  // FIXME: this mutation in getBody is bogus. It should be
-  // initialized in ASTStmtReader::VisitLambdaExpr, but for reasons I
-  // don't understand, that doesn't work.
-  if (!getStoredStmts()[capture_size()])
-*const_cast(()[capture_size()]) =
-getCallOperator()->getBody();
-
-  return static_cast(getStoredStmts()[capture_size()]);
-}
-
 bool LambdaExpr::isMutable() const { return !getCallOperator()->isConst(); }
 
 ExprWithCleanups::ExprWithCleanups(Expr *subexpr,

diff  --git a/clang/lib/AST/StmtPrinter.cpp b/clang/lib/AST/StmtPrinter.cpp
index d5d025335aa2..11e222f95176 100644
--- a/clang/lib/AST/StmtPrinter.cpp
+++ 

[clang] c7350a3 - [clang][utils] Modify make-ast-dump-check.sh to generate AST serialization dump tests

2020-06-18 Thread Bruno Ricci via cfe-commits

Author: Bruno Ricci
Date: 2020-06-18T13:37:29+01:00
New Revision: c7350a3bab14eb633f39a949f85ac0e690cd9b4d

URL: 
https://github.com/llvm/llvm-project/commit/c7350a3bab14eb633f39a949f85ac0e690cd9b4d
DIFF: 
https://github.com/llvm/llvm-project/commit/c7350a3bab14eb633f39a949f85ac0e690cd9b4d.diff

LOG: [clang][utils] Modify make-ast-dump-check.sh to generate AST serialization 
dump tests

An AST serialization dump test is a test which compares the output of -ast-dump
on the source and of -ast-dump-all on a PCH generated from the source. Modulo
a few differences the outputs should match.

This patch to make-ast-dump-check.sh enables automatically generating
these tests.

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

Reviewed By: aaron.ballman, lebedev.ri

Added: 


Modified: 
clang/utils/make-ast-dump-check.sh

Removed: 




diff  --git a/clang/utils/make-ast-dump-check.sh 
b/clang/utils/make-ast-dump-check.sh
index 2a9cf40a884c..578c725f48b1 100755
--- a/clang/utils/make-ast-dump-check.sh
+++ b/clang/utils/make-ast-dump-check.sh
@@ -3,12 +3,21 @@
 # This script is intended as a FileCheck replacement to update the test
 # expectations in a -ast-dump test.
 #
-# Usage:
+# Usage (to generate normal AST dump tests):
 #
 # $ lit -DFileCheck=$PWD/utils/make-ast-dump-check.sh 
test/AST/ast-dump-openmp-*
+#
+# Usage (to generate serialization AST dump tests):
+#
+# $ lit -DFileCheck="generate_serialization_test=1 
$PWD/utils/make-ast-dump-check.sh"
+# test/AST/ast-dump-openmp-*
 
 prefix=CHECK
 
+if [ -z ${generate_serialization_test+x} ];
+  then generate_serialization_test=0;
+fi
+
 while [[ "$#" -ne 0 ]]; do
   case "$1" in
   --check-prefix)
@@ -54,6 +63,10 @@ BEGIN {
   s = \$0
   gsub("0x[0-9a-fA-F]+", "{{.*}}", s)
   gsub("$testdir/", "{{.*}}", s)
+  if ($generate_serialization_test == 1) {
+gsub(" imported", "{{( imported)?}}", s)
+gsub(" ", "{{( )?}}", s)
+  }
 }
 
 matched_last_line == 0 {



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


[clang] c669a1e - [clang][NFC] Pack LambdaExpr

2020-06-13 Thread Bruno Ricci via cfe-commits

Author: Bruno Ricci
Date: 2020-06-13T14:31:13+01:00
New Revision: c669a1ed6386d57a75a602b53266466dae1e1d84

URL: 
https://github.com/llvm/llvm-project/commit/c669a1ed6386d57a75a602b53266466dae1e1d84
DIFF: 
https://github.com/llvm/llvm-project/commit/c669a1ed6386d57a75a602b53266466dae1e1d84.diff

LOG: [clang][NFC] Pack LambdaExpr

This saves sizeof(void *) bytes per LambdaExpr.

Review-after-commit since this is a straightforward change similar
to the work done on other nodes. NFC.

Added: 


Modified: 
clang/include/clang/AST/ExprCXX.h
clang/include/clang/AST/Stmt.h
clang/lib/AST/ExprCXX.cpp
clang/lib/Serialization/ASTReaderStmt.cpp
clang/lib/Serialization/ASTWriterStmt.cpp

Removed: 




diff  --git a/clang/include/clang/AST/ExprCXX.h 
b/clang/include/clang/AST/ExprCXX.h
index 82036a295002..822025a7503f 100644
--- a/clang/include/clang/AST/ExprCXX.h
+++ b/clang/include/clang/AST/ExprCXX.h
@@ -1829,26 +1829,14 @@ Stmt **CXXConstructExpr::getTrailingArgs() {
 /// and which can never occur implicitly.
 class LambdaExpr final : public Expr,
  private llvm::TrailingObjects {
+  // LambdaExpr has some data stored in LambdaExprBits.
+
   /// The source range that covers the lambda introducer ([...]).
   SourceRange IntroducerRange;
 
   /// The source location of this lambda's capture-default ('=' or '&').
   SourceLocation CaptureDefaultLoc;
 
-  /// The number of captures.
-  unsigned NumCaptures : 16;
-
-  /// The default capture kind, which is a value of type
-  /// LambdaCaptureDefault.
-  unsigned CaptureDefault : 2;
-
-  /// Whether this lambda had an explicit parameter list vs. an
-  /// implicit (and empty) parameter list.
-  unsigned ExplicitParams : 1;
-
-  /// Whether this lambda had the result type explicitly specified.
-  unsigned ExplicitResultType : 1;
-
   /// The location of the closing brace ('}') that completes
   /// the lambda.
   ///
@@ -1867,15 +1855,9 @@ class LambdaExpr final : public Expr,
  SourceLocation ClosingBrace, bool 
ContainsUnexpandedParameterPack);
 
   /// Construct an empty lambda expression.
-  LambdaExpr(EmptyShell Empty, unsigned NumCaptures)
-  : Expr(LambdaExprClass, Empty), NumCaptures(NumCaptures),
-CaptureDefault(LCD_None), ExplicitParams(false),
-ExplicitResultType(false) {
-getStoredStmts()[NumCaptures] = nullptr;
-  }
+  LambdaExpr(EmptyShell Empty, unsigned NumCaptures);
 
   Stmt **getStoredStmts() { return getTrailingObjects(); }
-
   Stmt *const *getStoredStmts() const { return getTrailingObjects(); }
 
 public:
@@ -1898,13 +1880,11 @@ class LambdaExpr final : public Expr,
 
   /// Determine the default capture kind for this lambda.
   LambdaCaptureDefault getCaptureDefault() const {
-return static_cast(CaptureDefault);
+return static_cast(LambdaExprBits.CaptureDefault);
   }
 
   /// Retrieve the location of this lambda's capture-default, if any.
-  SourceLocation getCaptureDefaultLoc() const {
-return CaptureDefaultLoc;
-  }
+  SourceLocation getCaptureDefaultLoc() const { return CaptureDefaultLoc; }
 
   /// Determine whether one of this lambda's captures is an init-capture.
   bool isInitCapture(const LambdaCapture *Capture) const;
@@ -1927,7 +1907,7 @@ class LambdaExpr final : public Expr,
   capture_iterator capture_end() const;
 
   /// Determine the number of captures in this lambda.
-  unsigned capture_size() const { return NumCaptures; }
+  unsigned capture_size() const { return LambdaExprBits.NumCaptures; }
 
   /// Retrieve this lambda's explicit captures.
   capture_range explicit_captures() const;
@@ -1984,13 +1964,13 @@ class LambdaExpr final : public Expr,
   /// Retrieve the iterator pointing one past the last
   /// initialization argument for this lambda expression.
   capture_init_iterator capture_init_end() {
-return capture_init_begin() + NumCaptures;
+return capture_init_begin() + capture_size();
   }
 
   /// Retrieve the iterator pointing one past the last
   /// initialization argument for this lambda expression.
   const_capture_init_iterator capture_init_end() const {
-return capture_init_begin() + NumCaptures;
+return capture_init_begin() + capture_size();
   }
 
   /// Retrieve the source range covering the lambda introducer,
@@ -2033,10 +2013,12 @@ class LambdaExpr final : public Expr,
 
   /// Determine whether this lambda has an explicit parameter
   /// list vs. an implicit (empty) parameter list.
-  bool hasExplicitParameters() const { return ExplicitParams; }
+  bool hasExplicitParameters() const { return LambdaExprBits.ExplicitParams; }
 
   /// Whether this lambda had its result type explicitly specified.
-  bool hasExplicitResultType() const { return ExplicitResultType; }
+  bool hasExplicitResultType() const {
+return LambdaExprBits.ExplicitResultType;
+  }
 
   static bool classof(const Stmt *T) {
 return 

[clang] f13d704 - [clang][NFC] Mark CWG 1443 (Default arguments and non-static data members)...

2020-06-13 Thread Bruno Ricci via cfe-commits

Author: Bruno Ricci
Date: 2020-06-13T13:59:54+01:00
New Revision: f13d704a5014fa28d56240a6da7d1aa0b1c01f4d

URL: 
https://github.com/llvm/llvm-project/commit/f13d704a5014fa28d56240a6da7d1aa0b1c01f4d
DIFF: 
https://github.com/llvm/llvm-project/commit/f13d704a5014fa28d56240a6da7d1aa0b1c01f4d.diff

LOG: [clang][NFC] Mark CWG 1443 (Default arguments and non-static data 
members)...

...as done. This is a NAD which has always been implemented correctly.

Added: 


Modified: 
clang/test/CXX/drs/dr14xx.cpp

Removed: 




diff  --git a/clang/test/CXX/drs/dr14xx.cpp b/clang/test/CXX/drs/dr14xx.cpp
index d55427f5de8c..50b0396a4b79 100644
--- a/clang/test/CXX/drs/dr14xx.cpp
+++ b/clang/test/CXX/drs/dr14xx.cpp
@@ -4,10 +4,6 @@
 // RUN: %clang_cc1 -std=c++17 %s -verify -fexceptions -fcxx-exceptions 
-pedantic-errors
 // RUN: %clang_cc1 -std=c++2a %s -verify -fexceptions -fcxx-exceptions 
-pedantic-errors
 
-#if __cplusplus < 201103L
-// expected-no-diagnostics
-#endif
-
 namespace dr1423 { // dr1423: 11
 #if __cplusplus >= 201103L
   bool b1 = nullptr; // expected-error {{cannot initialize}}
@@ -17,6 +13,13 @@ namespace dr1423 { // dr1423: 11
 #endif
 }
 
+namespace dr1443 { // dr1443: yes
+struct A {
+  int i;
+  A() { void foo(int=i); } // expected-error {{default argument references 
'this'}}
+};
+}
+
 // dr1425: na abi
 
 namespace dr1460 { // dr1460: 3.5



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


[clang] 6a79f5a - [clang][NFC] Add an AST dump test for LambdaExpr

2020-06-13 Thread Bruno Ricci via cfe-commits

Author: Bruno Ricci
Date: 2020-06-13T14:03:25+01:00
New Revision: 6a79f5aa5dbc2528444b4dfb92bb68039c5a32e9

URL: 
https://github.com/llvm/llvm-project/commit/6a79f5aa5dbc2528444b4dfb92bb68039c5a32e9
DIFF: 
https://github.com/llvm/llvm-project/commit/6a79f5aa5dbc2528444b4dfb92bb68039c5a32e9.diff

LOG: [clang][NFC] Add an AST dump test for LambdaExpr

This test illustrate the bug fixed in D81787.

Added: 
clang/test/AST/ast-dump-lambda.cpp

Modified: 


Removed: 




diff  --git a/clang/test/AST/ast-dump-lambda.cpp 
b/clang/test/AST/ast-dump-lambda.cpp
new file mode 100644
index ..3f10d12bdd6f
--- /dev/null
+++ b/clang/test/AST/ast-dump-lambda.cpp
@@ -0,0 +1,281 @@
+// Test without serialization:
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -Wno-unused-value 
-std=gnu++17 \
+// RUN: -ast-dump %s | FileCheck 
-strict-whitespace %s
+
+// Test with serialization:
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -Wno-unused-value 
-std=gnu++17 \
+// RUN:-emit-pch -o %t %s
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -Wno-unused-value 
-std=gnu++17 \
+// RUN:-x c++ -include-pch %t -ast-dump-all | FileCheck 
-strict-whitespace %s
+
+// XFAIL: *
+
+template  void test(Ts... a) {
+  struct V {
+void f() {
+  [this] {};
+  [*this] {};
+}
+  };
+  int b, c;
+  []() {};
+  [](int a, ...) {};
+  [a...] {};
+  [=] {};
+  [=] { return b; };
+  [&] {};
+  [&] { return c; };
+  [b, ] { return b + c; };
+  [a..., x = 12] {};
+  []() constexpr {};
+  []() mutable {};
+  []() noexcept {};
+  []() -> int { return 0; };
+}
+// CHECK: TranslationUnitDecl {{.*}} <> {{( 
)?}}
+// CHECK: `-FunctionTemplateDecl {{.*}} <{{.*}}ast-dump-lambda.cpp:13:1, 
line:34:1> line:13:32{{( imported)?}} test
+// CHECK-NEXT:   |-TemplateTypeParmDecl {{.*}}  col:23{{( 
imported)?}} referenced typename depth 0 index 0 ... Ts
+// CHECK-NEXT:   `-FunctionDecl {{.*}}  line:13:32{{( 
imported)?}} test 'void (Ts...)'
+// CHECK-NEXT: |-ParmVarDecl {{.*}}  col:43{{( 
imported)?}} referenced a 'Ts...' pack
+// CHECK-NEXT: `-CompoundStmt {{.*}} 
+// CHECK-NEXT:   |-DeclStmt {{.*}} 
+// CHECK-NEXT:   | `-CXXRecordDecl {{.*}}  
line:14:10{{( imported)?}}{{( )?}} struct V 
definition
+// CHECK-NEXT:   |   |-DefinitionData empty aggregate standard_layout 
trivially_copyable pod trivial literal has_constexpr_non_copy_move_ctor 
can_const_default_init
+// CHECK-NEXT:   |   | |-DefaultConstructor exists trivial constexpr 
needs_implicit defaulted_is_constexpr
+// CHECK-NEXT:   |   | |-CopyConstructor simple trivial has_const_param 
needs_implicit implicit_has_const_param
+// CHECK-NEXT:   |   | |-MoveConstructor exists simple trivial 
needs_implicit
+// CHECK-NEXT:   |   | |-CopyAssignment simple trivial has_const_param 
needs_implicit implicit_has_const_param
+// CHECK-NEXT:   |   | |-MoveAssignment exists simple trivial 
needs_implicit
+// CHECK-NEXT:   |   | `-Destructor simple irrelevant trivial 
needs_implicit
+// CHECK-NEXT:   |   |-CXXRecordDecl {{.*}}  col:10{{( 
imported)?}} implicit struct V
+// CHECK-NEXT:   |   `-CXXMethodDecl {{.*}}  
line:15:10{{( imported)?}} f 'void ()'
+// CHECK-NEXT:   | `-CompoundStmt {{.*}} 
+// CHECK-NEXT:   |   |-LambdaExpr {{.*}}  '(lambda 
at {{.*}}ast-dump-lambda.cpp:16:7)'
+// CHECK-NEXT:   |   | |-CXXRecordDecl {{.*}}  col:7{{( 
imported)?}} implicit{{( )?}} class definition
+// CHECK-NEXT:   |   | | |-DefinitionData lambda standard_layout 
trivially_copyable can_const_default_init
+// CHECK-NEXT:   |   | | | |-DefaultConstructor
+// CHECK-NEXT:   |   | | | |-CopyConstructor simple trivial 
has_const_param needs_implicit implicit_has_const_param
+// CHECK-NEXT:   |   | | | |-MoveConstructor exists simple trivial 
needs_implicit
+// CHECK-NEXT:   |   | | | |-CopyAssignment trivial has_const_param 
needs_implicit implicit_has_const_param
+// CHECK-NEXT:   |   | | | |-MoveAssignment
+// CHECK-NEXT:   |   | | | `-Destructor simple irrelevant trivial 
needs_implicit
+// CHECK-NEXT:   |   | | |-CXXMethodDecl {{.*}}  
col:7{{( imported)?}} operator() 'auto () const -> auto' inline
+// CHECK-NEXT:   |   | | | `-CompoundStmt {{.*}} 
+// CHECK-NEXT:   |   | | `-FieldDecl {{.*}}  col:8{{( 
imported)?}} implicit 'V *'
+// CHECK-NEXT:   |   | |-ParenListExpr {{.*}}  'NULL TYPE'
+// CHECK-NEXT:   |   | | `-CXXThisExpr {{.*}}  'V *' this
+// CHECK-NEXT:   |   | `-<<>>
+// CHECK-NEXT:   |   `-LambdaExpr {{.*}}  '(lambda 
at {{.*}}ast-dump-lambda.cpp:17:7)'
+// CHECK-NEXT:   | |-CXXRecordDecl {{.*}}  col:7{{( 
imported)?}} implicit{{( )?}} class definition
+// CHECK-NEXT:   | | |-DefinitionData lambda standard_layout 
trivially_copyable 

[clang] eb614db - [clang][NFC] Mark CWG 974 and 1814 (default argument in a...

2020-06-13 Thread Bruno Ricci via cfe-commits

Author: Bruno Ricci
Date: 2020-06-13T13:49:07+01:00
New Revision: eb614db0a0b41734ef52c2cdd87461f0ca62a900

URL: 
https://github.com/llvm/llvm-project/commit/eb614db0a0b41734ef52c2cdd87461f0ca62a900
DIFF: 
https://github.com/llvm/llvm-project/commit/eb614db0a0b41734ef52c2cdd87461f0ca62a900.diff

LOG: [clang][NFC] Mark CWG 974 and 1814 (default argument in a...

...lambda-expression) as done. They have been allowed since at least clang 3.3.

Added: 


Modified: 
clang/test/CXX/drs/dr18xx.cpp
clang/test/CXX/drs/dr9xx.cpp

Removed: 




diff  --git a/clang/test/CXX/drs/dr18xx.cpp b/clang/test/CXX/drs/dr18xx.cpp
index 33c0452b6c09..6cf526345af3 100644
--- a/clang/test/CXX/drs/dr18xx.cpp
+++ b/clang/test/CXX/drs/dr18xx.cpp
@@ -31,6 +31,14 @@ namespace dr1813 { // dr1813: 7
   static_assert(!__is_standard_layout(U), "");
 }
 
+namespace dr1814 { // dr1814: yes
+#if __cplusplus >= 201103L
+  void test() {
+auto lam = [](int x = 42) { return x; };
+  }
+#endif
+}
+
 namespace dr1815 { // dr1815: no
 #if __cplusplus >= 201402L
   // FIXME: needs codegen test

diff  --git a/clang/test/CXX/drs/dr9xx.cpp b/clang/test/CXX/drs/dr9xx.cpp
index b37e17d6b098..e8c22b2972ce 100644
--- a/clang/test/CXX/drs/dr9xx.cpp
+++ b/clang/test/CXX/drs/dr9xx.cpp
@@ -73,3 +73,11 @@ namespace dr948 { // dr948: 3.7
   }
 #endif
 }
+
+namespace dr974 { // dr974: yes
+#if __cplusplus >= 201103L
+  void test() {
+auto lam = [](int x = 42) { return x; };
+  }
+#endif
+}



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


[clang] efb0413 - [clang][NFC] Assert that the enumerator value of {Type,ArrayType,UnaryExprOrType,Expression}Traits

2020-06-11 Thread Bruno Ricci via cfe-commits

Author: Bruno Ricci
Date: 2020-06-11T20:27:40+01:00
New Revision: efb0413a5cf9b1481c9b6169c8685f8d71f6de84

URL: 
https://github.com/llvm/llvm-project/commit/efb0413a5cf9b1481c9b6169c8685f8d71f6de84
DIFF: 
https://github.com/llvm/llvm-project/commit/efb0413a5cf9b1481c9b6169c8685f8d71f6de84.diff

LOG: [clang][NFC] Assert that the enumerator value of 
{Type,ArrayType,UnaryExprOrType,Expression}Traits

is valid and does not overflow in the bit-field for its storage in more places.
This is a follow-up to 78e636b3f2f0b0487130b31fade4f95ab179a18c. NFC.

Added: 


Modified: 
clang/include/clang/AST/Expr.h
clang/include/clang/AST/ExprCXX.h
clang/lib/AST/Expr.cpp
clang/lib/AST/ExprCXX.cpp

Removed: 




diff  --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index 670c0fe80b4e..d31f582264b5 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -2509,7 +2509,11 @@ class UnaryExprOrTypeTraitExpr : public Expr {
SourceLocation rp)
   : Expr(UnaryExprOrTypeTraitExprClass, resultType, VK_RValue, 
OK_Ordinary),
 OpLoc(op), RParenLoc(rp) {
+assert(ExprKind <= UETT_Last && "invalid enum value!");
 UnaryExprOrTypeTraitExprBits.Kind = ExprKind;
+assert(static_cast(ExprKind) ==
+   UnaryExprOrTypeTraitExprBits.Kind &&
+   "UnaryExprOrTypeTraitExprBits.Kind overflow!");
 UnaryExprOrTypeTraitExprBits.IsType = true;
 Argument.Ty = TInfo;
 setDependence(computeDependence(this));
@@ -2526,7 +2530,12 @@ class UnaryExprOrTypeTraitExpr : public Expr {
   UnaryExprOrTypeTrait getKind() const {
 return 
static_cast(UnaryExprOrTypeTraitExprBits.Kind);
   }
-  void setKind(UnaryExprOrTypeTrait K) { UnaryExprOrTypeTraitExprBits.Kind = 
K;}
+  void setKind(UnaryExprOrTypeTrait K) {
+assert(K <= UETT_Last && "invalid enum value!");
+UnaryExprOrTypeTraitExprBits.Kind = K;
+assert(static_cast(K) == UnaryExprOrTypeTraitExprBits.Kind &&
+   "UnaryExprOrTypeTraitExprBits.Kind overflow!");
+  }
 
   bool isArgumentType() const { return UnaryExprOrTypeTraitExprBits.IsType; }
   QualType getArgumentType() const {

diff  --git a/clang/include/clang/AST/ExprCXX.h 
b/clang/include/clang/AST/ExprCXX.h
index 379f762275c6..82036a295002 100644
--- a/clang/include/clang/AST/ExprCXX.h
+++ b/clang/include/clang/AST/ExprCXX.h
@@ -2749,6 +2749,8 @@ class ArrayTypeTraitExpr : public Expr {
   : Expr(ArrayTypeTraitExprClass, ty, VK_RValue, OK_Ordinary), ATT(att),
 Value(value), Dimension(dimension), Loc(loc), RParen(rparen),
 QueriedType(queried) {
+assert(att <= ATT_Last && "invalid enum value!");
+assert(static_cast(att) == ATT && "ATT overflow!");
 setDependence(computeDependence(this));
   }
 
@@ -2813,6 +2815,8 @@ class ExpressionTraitExpr : public Expr {
   : Expr(ExpressionTraitExprClass, resultType, VK_RValue, OK_Ordinary),
 ET(et), Value(value), Loc(loc), RParen(rparen),
 QueriedExpression(queried) {
+assert(et <= ET_Last && "invalid enum value!");
+assert(static_cast(et) == ET && "ET overflow!");
 setDependence(computeDependence(this));
   }
 

diff  --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index 71cc159d06fb..89eb8e9c0220 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -1535,7 +1535,10 @@ UnaryExprOrTypeTraitExpr::UnaryExprOrTypeTraitExpr(
 SourceLocation op, SourceLocation rp)
 : Expr(UnaryExprOrTypeTraitExprClass, resultType, VK_RValue, OK_Ordinary),
   OpLoc(op), RParenLoc(rp) {
+  assert(ExprKind <= UETT_Last && "invalid enum value!");
   UnaryExprOrTypeTraitExprBits.Kind = ExprKind;
+  assert(static_cast(ExprKind) == UnaryExprOrTypeTraitExprBits.Kind 
&&
+ "UnaryExprOrTypeTraitExprBits.Kind overflow!");
   UnaryExprOrTypeTraitExprBits.IsType = false;
   Argument.Ex = E;
   setDependence(computeDependence(this));

diff  --git a/clang/lib/AST/ExprCXX.cpp b/clang/lib/AST/ExprCXX.cpp
index 9d285550ef90..9d4df28c7473 100644
--- a/clang/lib/AST/ExprCXX.cpp
+++ b/clang/lib/AST/ExprCXX.cpp
@@ -1579,6 +1579,7 @@ TypeTraitExpr::TypeTraitExpr(QualType T, SourceLocation 
Loc, TypeTrait Kind,
  SourceLocation RParenLoc, bool Value)
 : Expr(TypeTraitExprClass, T, VK_RValue, OK_Ordinary), Loc(Loc),
   RParenLoc(RParenLoc) {
+  assert(Kind <= TT_Last && "invalid enum value!");
   TypeTraitExprBits.Kind = Kind;
   assert(static_cast(Kind) == TypeTraitExprBits.Kind &&
  "TypeTraitExprBits.Kind overflow!");



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


[clang] a9250c2 - [clang] TextNodeDumper: Dump the trait spelling of {Type,ArrayType,Expression}TraitExpr

2020-06-11 Thread Bruno Ricci via cfe-commits

Author: Bruno Ricci
Date: 2020-06-11T20:27:40+01:00
New Revision: a9250c281a875d91fb5dd1c8f4ad8ee4ff61b75d

URL: 
https://github.com/llvm/llvm-project/commit/a9250c281a875d91fb5dd1c8f4ad8ee4ff61b75d
DIFF: 
https://github.com/llvm/llvm-project/commit/a9250c281a875d91fb5dd1c8f4ad8ee4ff61b75d.diff

LOG: [clang] TextNodeDumper: Dump the trait spelling of 
{Type,ArrayType,Expression}TraitExpr

nodes using the new helper functions introduced
in 78e636b3f2f0b0487130b31fade4f95ab179a18c.

Added: 
clang/test/AST/ast-dump-traits.cpp

Modified: 
clang/include/clang/AST/TextNodeDumper.h
clang/lib/AST/TextNodeDumper.cpp

Removed: 




diff  --git a/clang/include/clang/AST/TextNodeDumper.h 
b/clang/include/clang/AST/TextNodeDumper.h
index 4636c8ef65d3..b069bd09287a 100644
--- a/clang/include/clang/AST/TextNodeDumper.h
+++ b/clang/include/clang/AST/TextNodeDumper.h
@@ -259,6 +259,9 @@ class TextNodeDumper
   void VisitCXXBindTemporaryExpr(const CXXBindTemporaryExpr *Node);
   void VisitCXXNewExpr(const CXXNewExpr *Node);
   void VisitCXXDeleteExpr(const CXXDeleteExpr *Node);
+  void VisitTypeTraitExpr(const TypeTraitExpr *Node);
+  void VisitArrayTypeTraitExpr(const ArrayTypeTraitExpr *Node);
+  void VisitExpressionTraitExpr(const ExpressionTraitExpr *Node);
   void VisitMaterializeTemporaryExpr(const MaterializeTemporaryExpr *Node);
   void VisitExprWithCleanups(const ExprWithCleanups *Node);
   void VisitUnresolvedLookupExpr(const UnresolvedLookupExpr *Node);

diff  --git a/clang/lib/AST/TextNodeDumper.cpp 
b/clang/lib/AST/TextNodeDumper.cpp
index 609a9d7ac2df..7007aa833f3f 100644
--- a/clang/lib/AST/TextNodeDumper.cpp
+++ b/clang/lib/AST/TextNodeDumper.cpp
@@ -949,6 +949,18 @@ void TextNodeDumper::VisitCXXDeleteExpr(const 
CXXDeleteExpr *Node) {
   }
 }
 
+void TextNodeDumper::VisitTypeTraitExpr(const TypeTraitExpr *Node) {
+  OS << " " << getTraitSpelling(Node->getTrait());
+}
+
+void TextNodeDumper::VisitArrayTypeTraitExpr(const ArrayTypeTraitExpr *Node) {
+  OS << " " << getTraitSpelling(Node->getTrait());
+}
+
+void TextNodeDumper::VisitExpressionTraitExpr(const ExpressionTraitExpr *Node) 
{
+  OS << " " << getTraitSpelling(Node->getTrait());
+}
+
 void TextNodeDumper::VisitMaterializeTemporaryExpr(
 const MaterializeTemporaryExpr *Node) {
   if (const ValueDecl *VD = Node->getExtendingDecl()) {

diff  --git a/clang/test/AST/ast-dump-traits.cpp 
b/clang/test/AST/ast-dump-traits.cpp
new file mode 100644
index ..92931e2ac67a
--- /dev/null
+++ b/clang/test/AST/ast-dump-traits.cpp
@@ -0,0 +1,55 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -ast-dump %s | FileCheck 
-strict-whitespace %s
+
+void test_type_trait() {
+  // An unary type trait.
+  enum E {};
+  (void) __is_enum(E);
+  // A binary type trait.
+  (void) __is_same(int ,float);
+  // An n-ary type trait.
+  (void) __is_constructible(int, int, int, int);
+}
+
+void test_array_type_trait() {
+  // An array type trait.
+  (void) __array_rank(int[10][20]);
+}
+
+void test_expression_trait() {
+  // An expression trait.
+  (void) __is_lvalue_expr(1);
+}
+
+void test_unary_expr_or_type_trait() {
+  // Some UETTs.
+  (void) sizeof(int);
+  (void) alignof(int);
+  (void) __alignof(int);
+}
+// CHECK: TranslationUnitDecl {{.*}} <> 
+// CHECK: |-FunctionDecl {{.*}} <{{.*}}ast-dump-traits.cpp:3:1, line:11:1> 
line:3:6 test_type_trait 'void ()'
+// CHECK-NEXT: | `-CompoundStmt {{.*}} 
+// CHECK-NEXT: |   |-DeclStmt {{.*}} 
+// CHECK-NEXT: |   | `-EnumDecl {{.*}}  col:8 referenced E
+// CHECK-NEXT: |   |-CStyleCastExpr {{.*}}  'void' 
+// CHECK-NEXT: |   | `-TypeTraitExpr {{.*}}  'bool' __is_enum
+// CHECK-NEXT: |   |-CStyleCastExpr {{.*}}  'void' 
+// CHECK-NEXT: |   | `-TypeTraitExpr {{.*}}  'bool' __is_same
+// CHECK-NEXT: |   `-CStyleCastExpr {{.*}}  'void' 
+// CHECK-NEXT: | `-TypeTraitExpr {{.*}}  'bool' 
__is_constructible
+// CHECK-NEXT: |-FunctionDecl {{.*}}  line:13:6 
test_array_type_trait 'void ()'
+// CHECK-NEXT: | `-CompoundStmt {{.*}} 
+// CHECK-NEXT: |   `-CStyleCastExpr {{.*}}  'void' 
+// CHECK-NEXT: | `-ArrayTypeTraitExpr {{.*}}  'unsigned 
long' __array_rank
+// CHECK-NEXT: |-FunctionDecl {{.*}}  line:18:6 
test_expression_trait 'void ()'
+// CHECK-NEXT: | `-CompoundStmt {{.*}} 
+// CHECK-NEXT: |   `-CStyleCastExpr {{.*}}  'void' 
+// CHECK-NEXT: | `-ExpressionTraitExpr {{.*}}  'bool' 
__is_lvalue_expr
+// CHECK-NEXT: `-FunctionDecl {{.*}}  line:23:6 
test_unary_expr_or_type_trait 'void ()'
+// CHECK-NEXT:   `-CompoundStmt {{.*}} 
+// CHECK-NEXT: |-CStyleCastExpr {{.*}}  'void' 
+// CHECK-NEXT: | `-UnaryExprOrTypeTraitExpr {{.*}}  
'unsigned long' sizeof 'int'
+// CHECK-NEXT: |-CStyleCastExpr {{.*}}  'void' 
+// CHECK-NEXT: | `-UnaryExprOrTypeTraitExpr {{.*}}  
'unsigned long' alignof 'int'
+// CHECK-NEXT: `-CStyleCastExpr {{.*}}  'void' 
+// CHECK-NEXT:   `-UnaryExprOrTypeTraitExpr {{.*}}  

[clang] a06f000 - [clang][NFC] Remove two hard-coded lists of ArrayTypeTrait and ExpressionTrait

2020-06-11 Thread Bruno Ricci via cfe-commits

Author: Bruno Ricci
Date: 2020-06-11T20:27:40+01:00
New Revision: a06f000326e3362ffb5634957447dd434abab0f9

URL: 
https://github.com/llvm/llvm-project/commit/a06f000326e3362ffb5634957447dd434abab0f9
DIFF: 
https://github.com/llvm/llvm-project/commit/a06f000326e3362ffb5634957447dd434abab0f9.diff

LOG: [clang][NFC] Remove two hard-coded lists of ArrayTypeTrait and 
ExpressionTrait

These two were missed in 78e636b3f2f0b0487130b31fade4f95ab179a18c.

Added: 


Modified: 
clang/lib/Parse/ParseExprCXX.cpp

Removed: 




diff  --git a/clang/lib/Parse/ParseExprCXX.cpp 
b/clang/lib/Parse/ParseExprCXX.cpp
index d794977a..48277dc85466 100644
--- a/clang/lib/Parse/ParseExprCXX.cpp
+++ b/clang/lib/Parse/ParseExprCXX.cpp
@@ -3649,18 +3649,24 @@ case tok::kw_ ## Spelling: return BTT_ ## Name;
 }
 
 static ArrayTypeTrait ArrayTypeTraitFromTokKind(tok::TokenKind kind) {
-  switch(kind) {
-  default: llvm_unreachable("Not a known binary type trait");
-  case tok::kw___array_rank: return ATT_ArrayRank;
-  case tok::kw___array_extent:   return ATT_ArrayExtent;
+  switch (kind) {
+  default:
+llvm_unreachable("Not a known array type trait");
+#define ARRAY_TYPE_TRAIT(Spelling, Name, Key)  
\
+  case tok::kw_##Spelling: 
\
+return ATT_##Name;
+#include "clang/Basic/TokenKinds.def"
   }
 }
 
 static ExpressionTrait ExpressionTraitFromTokKind(tok::TokenKind kind) {
-  switch(kind) {
-  default: llvm_unreachable("Not a known unary expression trait.");
-  case tok::kw___is_lvalue_expr: return ET_IsLValueExpr;
-  case tok::kw___is_rvalue_expr: return ET_IsRValueExpr;
+  switch (kind) {
+  default:
+llvm_unreachable("Not a known unary expression trait.");
+#define EXPRESSION_TRAIT(Spelling, Name, Key)  
\
+  case tok::kw_##Spelling: 
\
+return ET_##Name;
+#include "clang/Basic/TokenKinds.def"
   }
 }
 



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


[clang] 78e636b - [clang][NFC] Generate the {Type,ArrayType,UnaryExprOrType,Expression}Traits...

2020-06-11 Thread Bruno Ricci via cfe-commits

Author: Bruno Ricci
Date: 2020-06-11T14:35:52+01:00
New Revision: 78e636b3f2f0b0487130b31fade4f95ab179a18c

URL: 
https://github.com/llvm/llvm-project/commit/78e636b3f2f0b0487130b31fade4f95ab179a18c
DIFF: 
https://github.com/llvm/llvm-project/commit/78e636b3f2f0b0487130b31fade4f95ab179a18c.diff

LOG: [clang][NFC] Generate the 
{Type,ArrayType,UnaryExprOrType,Expression}Traits...

...enumerations from TokenKinds.def and use the new macros from TokenKinds.def
to remove the hard-coded lists of traits.

All the information needed to generate these enumerations is already present
in TokenKinds.def. The motivation here is to be able to dump the trait spelling
without hard-coding the list in yet another place.

Note that this change the order of the enumerators in the enumerations (except
that in the TypeTrait enumeration all unary type traits are before all binary
type traits, and all binary type traits are before all n-ary type traits).

Apart from the aforementioned ordering which is relied upon, after this patch
no code in clang or in the various clang tools depend on the specific ordering
of the enumerators.

No functional changes intended.

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

Reviewed By: aaron.ballman

Added: 
clang/lib/Basic/ExpressionTraits.cpp
clang/lib/Basic/TypeTraits.cpp

Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Basic/ExpressionTraits.h
clang/include/clang/Basic/TokenKinds.def
clang/include/clang/Basic/TypeTraits.h
clang/lib/AST/JSONNodeDumper.cpp
clang/lib/AST/StmtPrinter.cpp
clang/lib/AST/TextNodeDumper.cpp
clang/lib/ASTMatchers/Dynamic/Marshallers.cpp
clang/lib/ASTMatchers/Dynamic/Marshallers.h
clang/lib/Basic/CMakeLists.txt
clang/lib/Sema/SemaExpr.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 1f68ef0d8dae..a295b3778cf0 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -6009,24 +6009,16 @@ def err_atomic_specifier_bad_type
 "1 byte of precision|with a non power of 2 precision}0">;
 
 // Expressions.
-def select_unary_expr_or_type_trait_kind : TextSubstitution<
-  "%select{sizeof|alignof|vec_step|__builtin_omp_required_simd_align|"
-  "__alignof}0">;
 def ext_sizeof_alignof_function_type : Extension<
-  "invalid application of '%sub{select_unary_expr_or_type_trait_kind}0' "
-  "to a function type">, InGroup;
+  "invalid application of '%0' to a function type">, InGroup;
 def ext_sizeof_alignof_void_type : Extension<
-  "invalid application of '%sub{select_unary_expr_or_type_trait_kind}0' "
-  "to a void type">, InGroup;
+  "invalid application of '%0' to a void type">, InGroup;
 def err_opencl_sizeof_alignof_type : Error<
-  "invalid application of '%sub{select_unary_expr_or_type_trait_kind}0' "
-  "to a void type">;
+  "invalid application of '%0' to a void type">;
 def err_sizeof_alignof_incomplete_or_sizeless_type : Error<
-  "invalid application of '%sub{select_unary_expr_or_type_trait_kind}0' "
-  "to %select{an incomplete|sizeless}1 type %2">;
+  "invalid application of '%0' to %select{an incomplete|sizeless}1 type %2">;
 def err_sizeof_alignof_function_type : Error<
-  "invalid application of '%sub{select_unary_expr_or_type_trait_kind}0' "
-  "to a function type">;
+  "invalid application of '%0' to a function type">;
 def err_openmp_default_simd_align_expr : Error<
   "invalid application of '__builtin_omp_required_simd_align' to an 
expression, only type is allowed">;
 def err_sizeof_alignof_typeof_bitfield : Error<

diff  --git a/clang/include/clang/Basic/ExpressionTraits.h 
b/clang/include/clang/Basic/ExpressionTraits.h
index 85005330a0af..b38ebd9ac60b 100644
--- a/clang/include/clang/Basic/ExpressionTraits.h
+++ b/clang/include/clang/Basic/ExpressionTraits.h
@@ -14,12 +14,24 @@
 #ifndef LLVM_CLANG_BASIC_EXPRESSIONTRAITS_H
 #define LLVM_CLANG_BASIC_EXPRESSIONTRAITS_H
 
+#include "llvm/Support/Compiler.h"
+
 namespace clang {
 
-  enum ExpressionTrait {
-ET_IsLValueExpr,
-ET_IsRValueExpr
-  };
-}
+enum ExpressionTrait {
+#define EXPRESSION_TRAIT(Spelling, Name, Key) ET_##Name,
+#include "clang/Basic/TokenKinds.def"
+  ET_Last = -1 // ET_Last == last ET_XX in the enum.
+#define EXPRESSION_TRAIT(Spelling, Name, Key) +1
+#include "clang/Basic/TokenKinds.def"
+};
+
+/// Return the internal name of type trait \p T. Never null.
+const char *getTraitName(ExpressionTrait T) LLVM_READONLY;
+
+/// Return the spelling of the type trait \p TT. Never null.
+const char *getTraitSpelling(ExpressionTrait T) LLVM_READONLY;
+
+} // namespace clang
 
 #endif

diff  --git a/clang/include/clang/Basic/TokenKinds.def 
b/clang/include/clang/Basic/TokenKinds.def
index 141470abecf4..2b353269ed52 100644
--- 

[clang] acb8922 - [clang][NFC] Fix a Wdocumentation warning in Basic/TargetInfo.h

2020-06-11 Thread Bruno Ricci via cfe-commits

Author: Bruno Ricci
Date: 2020-06-11T13:30:26+01:00
New Revision: acb892233d4c51579c350ad632a1f391ba13bac2

URL: 
https://github.com/llvm/llvm-project/commit/acb892233d4c51579c350ad632a1f391ba13bac2
DIFF: 
https://github.com/llvm/llvm-project/commit/acb892233d4c51579c350ad632a1f391ba13bac2.diff

LOG: [clang][NFC] Fix a Wdocumentation warning in Basic/TargetInfo.h

Added: 


Modified: 
clang/include/clang/Basic/TargetInfo.h

Removed: 




diff  --git a/clang/include/clang/Basic/TargetInfo.h 
b/clang/include/clang/Basic/TargetInfo.h
index b1a4017b4c76..140f55ff66b1 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -1326,7 +1326,7 @@ class TargetInfo : public virtual TransferrableTargetInfo,
 return LangAS::Default;
   }
 
-  /// Return a target-specific GPU grid value based on the GVIDX enum \param gv
+  /// Return a target-specific GPU grid value based on the GVIDX enum \p gv
   unsigned getGridValue(llvm::omp::GVIDX gv) const {
 assert(GridValues != nullptr && "GridValues not initialized");
 return GridValues[gv];



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


[clang] 40ea01f - [clang] Convert a default argument expression to the parameter type...

2020-06-11 Thread Bruno Ricci via cfe-commits

Author: Bruno Ricci
Date: 2020-06-11T13:18:45+01:00
New Revision: 40ea01f6543d0d4aa2701d1b27a6c5413340e7d5

URL: 
https://github.com/llvm/llvm-project/commit/40ea01f6543d0d4aa2701d1b27a6c5413340e7d5
DIFF: 
https://github.com/llvm/llvm-project/commit/40ea01f6543d0d4aa2701d1b27a6c5413340e7d5.diff

LOG: [clang] Convert a default argument expression to the parameter type...

...before checking that the default argument is valid with
CheckDefaultArgumentVisitor.

Currently the restrictions on a default argument are checked with the visitor
CheckDefaultArgumentVisitor in ActOnParamDefaultArgument before
performing the conversion to the parameter type in SetParamDefaultArgument.

This was fine before the previous patch but now some valid code post-CWG 2346
is rejected:

void test() {
  const int i2 = 0;
  extern void h2a(int x = i2); // FIXME: ok, not odr-use
  extern void h2b(int x = i2 + 0); // ok, not odr-use
}

This is because the reference to i2 in h2a has not been marked yet with
NOUR_Constant. i2 is marked NOUR_Constant when the conversion to the parameter
type is done, which is done just after.

The solution is to do the conversion to the parameter type before checking
the restrictions on default arguments with CheckDefaultArgumentVisitor.
This has the side-benefit of improving some diagnostics.

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

Reviewed By: rsmith

Added: 


Modified: 
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaDeclCXX.cpp
clang/lib/Sema/SemaTemplateInstantiate.cpp
clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p7.cpp
clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p8.cpp
clang/test/SemaCXX/vartemplate-lambda.cpp
clang/test/SemaTemplate/instantiate-local-class.cpp

Removed: 




diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 6f074fb941af..3416f339768f 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -2381,11 +2381,13 @@ class Sema final {
   void ActOnParamDefaultArgument(Decl *param,
  SourceLocation EqualLoc,
  Expr *defarg);
-  void ActOnParamUnparsedDefaultArgument(Decl *param,
- SourceLocation EqualLoc,
+  void ActOnParamUnparsedDefaultArgument(Decl *param, SourceLocation EqualLoc,
  SourceLocation ArgLoc);
   void ActOnParamDefaultArgumentError(Decl *param, SourceLocation EqualLoc);
-  bool SetParamDefaultArgument(ParmVarDecl *Param, Expr *DefaultArg,
+  ExprResult ConvertParamDefaultArgument(const ParmVarDecl *Param,
+ Expr *DefaultArg,
+ SourceLocation EqualLoc);
+  void SetParamDefaultArgument(ParmVarDecl *Param, Expr *DefaultArg,
SourceLocation EqualLoc);
 
   // Contexts where using non-trivial C union types can be disallowed. This is

diff  --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 28a84d27c038..a77f7a460242 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -254,14 +254,12 @@ void 
Sema::ImplicitExceptionSpecification::CalledStmt(Stmt *S) {
 ComputedEST = EST_None;
 }
 
-bool
-Sema::SetParamDefaultArgument(ParmVarDecl *Param, Expr *Arg,
-  SourceLocation EqualLoc) {
+ExprResult Sema::ConvertParamDefaultArgument(const ParmVarDecl *Param,
+ Expr *Arg,
+ SourceLocation EqualLoc) {
   if (RequireCompleteType(Param->getLocation(), Param->getType(),
-  diag::err_typecheck_decl_incomplete_type)) {
-Param->setInvalidDecl();
+  diag::err_typecheck_decl_incomplete_type))
 return true;
-  }
 
   // C++ [dcl.fct.default]p5
   //   A default argument expression is implicitly converted (clause
@@ -282,7 +280,12 @@ Sema::SetParamDefaultArgument(ParmVarDecl *Param, Expr 
*Arg,
   CheckCompletedExpr(Arg, EqualLoc);
   Arg = MaybeCreateExprWithCleanups(Arg);
 
-  // Okay: add the default argument to the parameter
+  return Arg;
+}
+
+void Sema::SetParamDefaultArgument(ParmVarDecl *Param, Expr *Arg,
+   SourceLocation EqualLoc) {
+  // Add the default argument to the parameter
   Param->setDefaultArg(Arg);
 
   // We have already instantiated this parameter; provide each of the
@@ -296,8 +299,6 @@ Sema::SetParamDefaultArgument(ParmVarDecl *Param, Expr *Arg,
 // We're done tracking this parameter's instantiations.
 UnparsedDefaultArgInstantiations.erase(InstPos);
   }
-
-  return false;
 }
 
 /// ActOnParamDefaultArgument - Check whether the default argument
@@ -341,13 +342,18 @@ Sema::ActOnParamDefaultArgument(Decl *param, 
SourceLocation 

[clang] 5951ff4 - [clang] CWG 2082 and 2346: loosen the restrictions on parameters and local variables in default arguments.

2020-06-11 Thread Bruno Ricci via cfe-commits

Author: Bruno Ricci
Date: 2020-06-11T12:41:08+01:00
New Revision: 5951ff4512332fff9d191da8661143a883d3b8aa

URL: 
https://github.com/llvm/llvm-project/commit/5951ff4512332fff9d191da8661143a883d3b8aa
DIFF: 
https://github.com/llvm/llvm-project/commit/5951ff4512332fff9d191da8661143a883d3b8aa.diff

LOG: [clang] CWG 2082 and 2346: loosen the restrictions on parameters and local 
variables in default arguments.

This patch implements the resolution of CWG 2082 and CWG 2346.

The resolution of CWG 2082 changed [dcl.fct.default]p7 and p9 to allow
a parameter or local variable to appear in a default argument if not
in a potentially-evaluated expression.

The resolution of CWG 2346 changed [dcl.fct.default]p7 to allow a local
variable to appear in a default argument if not odr-used.

An issue remains after this patch
(see the FIXME in test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p7.cpp).
This is addressed by the next patch.

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

Reviewed By: rsmith, erichkeane

Added: 
clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p9.cpp

Modified: 
clang/lib/Sema/SemaDeclCXX.cpp
clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p7.cpp
clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p8.cpp
clang/test/CXX/drs/dr20xx.cpp
clang/test/CXX/drs/dr23xx.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index e33df2527d2c..28a84d27c038 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -87,22 +87,31 @@ bool CheckDefaultArgumentVisitor::VisitExpr(const Expr 
*Node) {
 bool CheckDefaultArgumentVisitor::VisitDeclRefExpr(const DeclRefExpr *DRE) {
   const NamedDecl *Decl = DRE->getDecl();
   if (const auto *Param = dyn_cast(Decl)) {
-// C++ [dcl.fct.default]p9
-//   Default arguments are evaluated each time the function is
-//   called. The order of evaluation of function arguments is
-//   unspecified. Consequently, parameters of a function shall not
-//   be used in default argument expressions, even if they are not
-//   evaluated. Parameters of a function declared before a default
-//   argument expression are in scope and can hide namespace and
-//   class member names.
-return S.Diag(DRE->getBeginLoc(),
-  diag::err_param_default_argument_references_param)
-   << Param->getDeclName() << DefaultArg->getSourceRange();
+// C++ [dcl.fct.default]p9:
+//   [...] parameters of a function shall not be used in default
+//   argument expressions, even if they are not evaluated. [...]
+//
+// C++17 [dcl.fct.default]p9 (by CWG 2082):
+//   [...] A parameter shall not appear as a potentially-evaluated
+//   expression in a default argument. [...]
+//
+if (DRE->isNonOdrUse() != NOUR_Unevaluated)
+  return S.Diag(DRE->getBeginLoc(),
+diag::err_param_default_argument_references_param)
+ << Param->getDeclName() << DefaultArg->getSourceRange();
   } else if (const auto *VDecl = dyn_cast(Decl)) {
-// C++ [dcl.fct.default]p7
+// C++ [dcl.fct.default]p7:
 //   Local variables shall not be used in default argument
 //   expressions.
-if (VDecl->isLocalVarDecl())
+//
+// C++17 [dcl.fct.default]p7 (by CWG 2082):
+//   A local variable shall not appear as a potentially-evaluated
+//   expression in a default argument.
+//
+// C++20 [dcl.fct.default]p7 (DR as part of P0588R1, see also CWG 2346):
+//   Note: A local variable cannot be odr-used (6.3) in a default argument.
+//
+if (VDecl->isLocalVarDecl() && !DRE->isNonOdrUse())
   return S.Diag(DRE->getBeginLoc(),
 diag::err_param_default_argument_references_local)
  << VDecl->getDeclName() << DefaultArg->getSourceRange();

diff  --git a/clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p7.cpp 
b/clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p7.cpp
index 164eb3682f31..07b527bbdc20 100644
--- a/clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p7.cpp
+++ b/clang/test/CXX/dcl.decl/dcl.meaning/dcl.fct.default/p7.cpp
@@ -1,7 +1,20 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s
 
-void h()
-{
-  int i;
-  extern void h2(int x = sizeof(i)); // expected-error {{default argument 
references local variable 'i' of enclosing function}}
+void h() {
+  int i1 = 0;
+  extern void h1(int x = i1);
+  // expected-error@-1 {{default argument references local variable 'i1' of 
enclosing function}}
+
+  const int i2 = 0;
+  extern void h2a(int x = i2); // FIXME: ok, not odr-use
+  // expected-error@-1 {{default argument references local variable 'i2' of 
enclosing function}}
+  extern void h2b(int x = i2 + 0); // ok, not odr-use
+
+  const int i3 = 0;
+  extern void h3(const int *x = );
+  // expected-error@-1 {{default argument references local variable 

[clang] 0418005 - [clang][NFC] Various NFCs in CheckDefaultArgumentVisitor

2020-06-11 Thread Bruno Ricci via cfe-commits

Author: Bruno Ricci
Date: 2020-06-11T12:19:45+01:00
New Revision: 0418005c0e2f280f0cdab9ad7b5a1a7bd03d9c10

URL: 
https://github.com/llvm/llvm-project/commit/0418005c0e2f280f0cdab9ad7b5a1a7bd03d9c10
DIFF: 
https://github.com/llvm/llvm-project/commit/0418005c0e2f280f0cdab9ad7b5a1a7bd03d9c10.diff

LOG: [clang][NFC] Various NFCs in CheckDefaultArgumentVisitor

Before the next patches do the following NFCs:
  - Make it a const visitor; CheckDefaultArgumentVisitor should
really not modify the visited nodes.

  - clang-format

  - Take a reference to Sema instead of a pointer and pass it
as the first argument to the constructor. This is for
consistency with the other similar visitors.

  - Use range for loops when appropriate as per the style guide.

  - Use `const auto *" when appropriate as per the style guide.

Added: 


Modified: 
clang/lib/Sema/SemaDeclCXX.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 26a5e129efdf..e33df2527d2c 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -52,102 +52,100 @@ using namespace clang;
 
//===--===//
 
 namespace {
-  /// CheckDefaultArgumentVisitor - C++ [dcl.fct.default] Traverses
-  /// the default argument of a parameter to determine whether it
-  /// contains any ill-formed subexpressions. For example, this will
-  /// diagnose the use of local variables or parameters within the
-  /// default argument expression.
-  class CheckDefaultArgumentVisitor
-: public StmtVisitor {
-Expr *DefaultArg;
-Sema *S;
-
-  public:
-CheckDefaultArgumentVisitor(Expr *defarg, Sema *s)
-: DefaultArg(defarg), S(s) {}
-
-bool VisitExpr(Expr *Node);
-bool VisitDeclRefExpr(DeclRefExpr *DRE);
-bool VisitCXXThisExpr(CXXThisExpr *ThisE);
-bool VisitLambdaExpr(LambdaExpr *Lambda);
-bool VisitPseudoObjectExpr(PseudoObjectExpr *POE);
-  };
-
-  /// VisitExpr - Visit all of the children of this expression.
-  bool CheckDefaultArgumentVisitor::VisitExpr(Expr *Node) {
-bool IsInvalid = false;
-for (Stmt *SubStmt : Node->children())
-  IsInvalid |= Visit(SubStmt);
-return IsInvalid;
-  }
-
-  /// VisitDeclRefExpr - Visit a reference to a declaration, to
-  /// determine whether this declaration can be used in the default
-  /// argument expression.
-  bool CheckDefaultArgumentVisitor::VisitDeclRefExpr(DeclRefExpr *DRE) {
-NamedDecl *Decl = DRE->getDecl();
-if (ParmVarDecl *Param = dyn_cast(Decl)) {
-  // C++ [dcl.fct.default]p9
-  //   Default arguments are evaluated each time the function is
-  //   called. The order of evaluation of function arguments is
-  //   unspecified. Consequently, parameters of a function shall not
-  //   be used in default argument expressions, even if they are not
-  //   evaluated. Parameters of a function declared before a default
-  //   argument expression are in scope and can hide namespace and
-  //   class member names.
-  return S->Diag(DRE->getBeginLoc(),
- diag::err_param_default_argument_references_param)
- << Param->getDeclName() << DefaultArg->getSourceRange();
-} else if (VarDecl *VDecl = dyn_cast(Decl)) {
-  // C++ [dcl.fct.default]p7
-  //   Local variables shall not be used in default argument
-  //   expressions.
-  if (VDecl->isLocalVarDecl())
-return S->Diag(DRE->getBeginLoc(),
-   diag::err_param_default_argument_references_local)
-   << VDecl->getDeclName() << DefaultArg->getSourceRange();
-}
+/// CheckDefaultArgumentVisitor - C++ [dcl.fct.default] Traverses
+/// the default argument of a parameter to determine whether it
+/// contains any ill-formed subexpressions. For example, this will
+/// diagnose the use of local variables or parameters within the
+/// default argument expression.
+class CheckDefaultArgumentVisitor
+: public ConstStmtVisitor {
+  Sema 
+  const Expr *DefaultArg;
 
-return false;
-  }
+public:
+  CheckDefaultArgumentVisitor(Sema , const Expr *DefaultArg)
+  : S(S), DefaultArg(DefaultArg) {}
+
+  bool VisitExpr(const Expr *Node);
+  bool VisitDeclRefExpr(const DeclRefExpr *DRE);
+  bool VisitCXXThisExpr(const CXXThisExpr *ThisE);
+  bool VisitLambdaExpr(const LambdaExpr *Lambda);
+  bool VisitPseudoObjectExpr(const PseudoObjectExpr *POE);
+};
 
-  /// VisitCXXThisExpr - Visit a C++ "this" expression.
-  bool CheckDefaultArgumentVisitor::VisitCXXThisExpr(CXXThisExpr *ThisE) {
-// C++ [dcl.fct.default]p8:
-//   The keyword this shall not be used in a default argument of a
-//   member function.
-return S->Diag(ThisE->getBeginLoc(),
-   diag::err_param_default_argument_references_this)
-   << ThisE->getSourceRange();
+/// 

[clang] 856ba63 - [clang][NFC] Fix and simplify the test added in 8dcc7eecb75b39d723fd6fee566369bf67e43fdf

2020-06-09 Thread Bruno Ricci via cfe-commits

Author: Bruno Ricci
Date: 2020-06-09T21:17:19+01:00
New Revision: 856ba638d57ead6df85a4ff39531282c6c110232

URL: 
https://github.com/llvm/llvm-project/commit/856ba638d57ead6df85a4ff39531282c6c110232
DIFF: 
https://github.com/llvm/llvm-project/commit/856ba638d57ead6df85a4ff39531282c6c110232.diff

LOG: [clang][NFC] Fix and simplify the test added in 
8dcc7eecb75b39d723fd6fee566369bf67e43fdf

We only have to create a TypeTraitExpr node with 16 bits worth of
arguments to detect an overflow with the assertion added in the
constructor of TypeTraitExpr. Moreover the static_assert in
original test is pointless since __is_constructible only check
that the corresponding expression is well-formed.

Added: 


Modified: 
clang/test/SemaCXX/type-traits.cpp

Removed: 




diff  --git a/clang/test/SemaCXX/type-traits.cpp 
b/clang/test/SemaCXX/type-traits.cpp
index 59ae31130528..5adb1f99c27f 100644
--- a/clang/test/SemaCXX/type-traits.cpp
+++ b/clang/test/SemaCXX/type-traits.cpp
@@ -2831,13 +2831,7 @@ namespace ConstClass {
 }
 
 namespace type_trait_expr_numargs_overflow {
-  // Make sure that TypeTraitExpr can store 16 bits worth of arguments.
-  struct S {
-  template  S(Ts... ts) {
-static_assert(sizeof...(ts) == 32768+1, "");
-  }
-};
-
+// Make sure that TypeTraitExpr can store 16 bits worth of arguments.
 #define T4(X) X,X,X,X
 #define T16(X) T4(X),T4(X),T4(X),T4(X)
 #define T64(X) T16(X),T16(X),T16(X),T16(X)
@@ -2846,11 +2840,7 @@ namespace type_trait_expr_numargs_overflow {
 #define T4096(X) T1024(X),T1024(X),T1024(X),T1024(X)
 #define T16384(X) T4096(X),T4096(X),T4096(X),T4096(X)
 #define T32768(X) T16384(X),T16384(X)
-
-void test() {
-  static_assert(__is_constructible(S, T32768(int), float), "");
-}
-
+void test() { (void) __is_constructible(int, T32768(int)); }
 #undef T4
 #undef T16
 #undef T64
@@ -2859,5 +2849,4 @@ void test() {
 #undef T4096
 #undef T16384
 #undef T32768
-
 } // namespace type_trait_expr_numargs_overflow



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


[clang] 8dcc7ee - [clang][AST] Widen TypeTraitExprBitfields.NumArgs to 16 bits.

2020-06-09 Thread Bruno Ricci via cfe-commits

Author: Bruno Ricci
Date: 2020-06-09T15:18:15+01:00
New Revision: 8dcc7eecb75b39d723fd6fee566369bf67e43fdf

URL: 
https://github.com/llvm/llvm-project/commit/8dcc7eecb75b39d723fd6fee566369bf67e43fdf
DIFF: 
https://github.com/llvm/llvm-project/commit/8dcc7eecb75b39d723fd6fee566369bf67e43fdf.diff

LOG: [clang][AST] Widen TypeTraitExprBitfields.NumArgs to 16 bits.

`32 - 8 - 1 - NumExprBits` is now only equal to 6, which is way too small.
Add a test so that this does not happen again.

Added: 


Modified: 
clang/include/clang/AST/Stmt.h
clang/lib/AST/ExprCXX.cpp
clang/test/SemaCXX/type-traits.cpp

Removed: 




diff  --git a/clang/include/clang/AST/Stmt.h b/clang/include/clang/AST/Stmt.h
index 530fb1029c7e..fdcc213a6aed 100644
--- a/clang/include/clang/AST/Stmt.h
+++ b/clang/include/clang/AST/Stmt.h
@@ -775,8 +775,10 @@ class alignas(void *) Stmt {
 /// the trait evaluated true or false.
 unsigned Value : 1;
 
-/// The number of arguments to this type trait.
-unsigned NumArgs : 32 - 8 - 1 - NumExprBits;
+/// The number of arguments to this type trait. According to [implimits]
+/// 8 bits would be enough, but we require (and test for) at least 16 bits
+/// to mirror FunctionType.
+unsigned NumArgs;
   };
 
   class DependentScopeDeclRefExprBitfields {

diff  --git a/clang/lib/AST/ExprCXX.cpp b/clang/lib/AST/ExprCXX.cpp
index 3aff2826a1dd..9d285550ef90 100644
--- a/clang/lib/AST/ExprCXX.cpp
+++ b/clang/lib/AST/ExprCXX.cpp
@@ -1580,8 +1580,12 @@ TypeTraitExpr::TypeTraitExpr(QualType T, SourceLocation 
Loc, TypeTrait Kind,
 : Expr(TypeTraitExprClass, T, VK_RValue, OK_Ordinary), Loc(Loc),
   RParenLoc(RParenLoc) {
   TypeTraitExprBits.Kind = Kind;
+  assert(static_cast(Kind) == TypeTraitExprBits.Kind &&
+ "TypeTraitExprBits.Kind overflow!");
   TypeTraitExprBits.Value = Value;
   TypeTraitExprBits.NumArgs = Args.size();
+  assert(Args.size() == TypeTraitExprBits.NumArgs &&
+ "TypeTraitExprBits.NumArgs overflow!");
 
   auto **ToArgs = getTrailingObjects();
   for (unsigned I = 0, N = Args.size(); I != N; ++I)

diff  --git a/clang/test/SemaCXX/type-traits.cpp 
b/clang/test/SemaCXX/type-traits.cpp
index 9104bfcb2ea4..59ae31130528 100644
--- a/clang/test/SemaCXX/type-traits.cpp
+++ b/clang/test/SemaCXX/type-traits.cpp
@@ -2829,3 +2829,35 @@ namespace ConstClass {
   };
   static_assert(!__is_trivially_assignable(B&, const B&), "");
 }
+
+namespace type_trait_expr_numargs_overflow {
+  // Make sure that TypeTraitExpr can store 16 bits worth of arguments.
+  struct S {
+  template  S(Ts... ts) {
+static_assert(sizeof...(ts) == 32768+1, "");
+  }
+};
+
+#define T4(X) X,X,X,X
+#define T16(X) T4(X),T4(X),T4(X),T4(X)
+#define T64(X) T16(X),T16(X),T16(X),T16(X)
+#define T256(X) T64(X),T64(X),T64(X),T64(X)
+#define T1024(X) T256(X),T256(X),T256(X),T256(X)
+#define T4096(X) T1024(X),T1024(X),T1024(X),T1024(X)
+#define T16384(X) T4096(X),T4096(X),T4096(X),T4096(X)
+#define T32768(X) T16384(X),T16384(X)
+
+void test() {
+  static_assert(__is_constructible(S, T32768(int), float), "");
+}
+
+#undef T4
+#undef T16
+#undef T64
+#undef T256
+#undef T1024
+#undef T4096
+#undef T16384
+#undef T32768
+
+} // namespace type_trait_expr_numargs_overflow



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


[clang] 6d0f834 - [clang][AST] TextNodeDumper: dump the operator spelling for overloaded operators.

2020-06-09 Thread Bruno Ricci via cfe-commits

Author: Bruno Ricci
Date: 2020-06-09T15:18:14+01:00
New Revision: 6d0f8345ac195990aea3776722f6de6e2957e6c2

URL: 
https://github.com/llvm/llvm-project/commit/6d0f8345ac195990aea3776722f6de6e2957e6c2
DIFF: 
https://github.com/llvm/llvm-project/commit/6d0f8345ac195990aea3776722f6de6e2957e6c2.diff

LOG: [clang][AST] TextNodeDumper: dump the operator spelling for overloaded 
operators.

This mirrors what is done for built-in operators.

Added: 
clang/test/AST/ast-dump-overloaded-operators.cpp

Modified: 
clang/include/clang/AST/TextNodeDumper.h
clang/lib/AST/TextNodeDumper.cpp
clang/test/Import/call-expr/test.cpp

Removed: 




diff  --git a/clang/include/clang/AST/TextNodeDumper.h 
b/clang/include/clang/AST/TextNodeDumper.h
index 0fb4baf0ca4d..4636c8ef65d3 100644
--- a/clang/include/clang/AST/TextNodeDumper.h
+++ b/clang/include/clang/AST/TextNodeDumper.h
@@ -231,6 +231,7 @@ class TextNodeDumper
   void VisitCaseStmt(const CaseStmt *Node);
   void VisitConstantExpr(const ConstantExpr *Node);
   void VisitCallExpr(const CallExpr *Node);
+  void VisitCXXOperatorCallExpr(const CXXOperatorCallExpr *Node);
   void VisitCastExpr(const CastExpr *Node);
   void VisitImplicitCastExpr(const ImplicitCastExpr *Node);
   void VisitDeclRefExpr(const DeclRefExpr *Node);

diff  --git a/clang/lib/AST/TextNodeDumper.cpp 
b/clang/lib/AST/TextNodeDumper.cpp
index 72f0ba37e3e7..84f9738ade8d 100644
--- a/clang/lib/AST/TextNodeDumper.cpp
+++ b/clang/lib/AST/TextNodeDumper.cpp
@@ -715,6 +715,14 @@ void TextNodeDumper::VisitCallExpr(const CallExpr *Node) {
 OS << " adl";
 }
 
+void TextNodeDumper::VisitCXXOperatorCallExpr(const CXXOperatorCallExpr *Node) 
{
+  const char *OperatorSpelling = 
clang::getOperatorSpelling(Node->getOperator());
+  if (OperatorSpelling)
+OS << " '" << OperatorSpelling << "'";
+
+  VisitCallExpr(Node);
+}
+
 void TextNodeDumper::VisitCastExpr(const CastExpr *Node) {
   OS << " <";
   {

diff  --git a/clang/test/AST/ast-dump-overloaded-operators.cpp 
b/clang/test/AST/ast-dump-overloaded-operators.cpp
new file mode 100644
index ..cd4e14be9f1a
--- /dev/null
+++ b/clang/test/AST/ast-dump-overloaded-operators.cpp
@@ -0,0 +1,30 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -ast-dump %s | FileCheck 
-strict-whitespace %s
+
+enum E {};
+void operator+(E,E);
+void operator,(E,E);
+
+void test() {
+  E e;
+  e + e;
+  e , e;
+}
+// CHECK: TranslationUnitDecl {{.*}} <> 
+// CHECK: `-FunctionDecl {{.*}}  line:7:6 test 'void ()'
+// CHECK-NEXT:   `-CompoundStmt {{.*}} 
+// CHECK-NEXT: |-DeclStmt {{.*}} 
+// CHECK-NEXT: | `-VarDecl {{.*}}  col:5 used e 'E'
+// CHECK-NEXT: |-CXXOperatorCallExpr {{.*}}  'void' '+'
+// CHECK-NEXT: | |-ImplicitCastExpr {{.*}}  'void (*)(E, E)' 

+// CHECK-NEXT: | | `-DeclRefExpr {{.*}}  'void (E, E)' lvalue 
Function {{.*}} 'operator+' 'void (E, E)'
+// CHECK-NEXT: | |-ImplicitCastExpr {{.*}}  'E' 
+// CHECK-NEXT: | | `-DeclRefExpr {{.*}}  'E' lvalue Var {{.*}} 'e' 
'E'
+// CHECK-NEXT: | `-ImplicitCastExpr {{.*}}  'E' 
+// CHECK-NEXT: |   `-DeclRefExpr {{.*}}  'E' lvalue Var {{.*}} 'e' 
'E'
+// CHECK-NEXT: `-CXXOperatorCallExpr {{.*}}  'void' ','
+// CHECK-NEXT:   |-ImplicitCastExpr {{.*}}  'void (*)(E, E)' 

+// CHECK-NEXT:   | `-DeclRefExpr {{.*}}  'void (E, E)' lvalue 
Function {{.*}} 'operator,' 'void (E, E)'
+// CHECK-NEXT:   |-ImplicitCastExpr {{.*}}  'E' 
+// CHECK-NEXT:   | `-DeclRefExpr {{.*}}  'E' lvalue Var {{.*}} 'e' 
'E'
+// CHECK-NEXT:   `-ImplicitCastExpr {{.*}}  'E' 
+// CHECK-NEXT: `-DeclRefExpr {{.*}}  'E' lvalue Var {{.*}} 'e' 
'E'

diff  --git a/clang/test/Import/call-expr/test.cpp 
b/clang/test/Import/call-expr/test.cpp
index 86c1b50c47d6..e2836a2bb9de 100644
--- a/clang/test/Import/call-expr/test.cpp
+++ b/clang/test/Import/call-expr/test.cpp
@@ -5,4 +5,4 @@ void expr() {
 
 // CHECK: FunctionDecl 0x{{[^ ]*}} <{{[^>]*}}> line:{{.*}}:{{[^ ]*}} used f 
'void ()'
 // CHECK: -CallExpr 0x{{[^ ]*}} <{{[^>]*}}> 'void' adl
-// CHECK: -CXXOperatorCallExpr 0x{{[^ ]*}} <{{[^>]*}}> 'void' adl
+// CHECK: -CXXOperatorCallExpr 0x{{[^ ]*}} <{{[^>]*}}> 'void' '+' adl



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


[clang] a2f32bf - [clang][Sema] SequenceChecker: C++17 sequencing rule for call expressions.

2020-06-03 Thread Bruno Ricci via cfe-commits

Author: Bruno Ricci
Date: 2020-06-03T12:35:12+01:00
New Revision: a2f32bfcc7cd6828785011ce90f6e0314d096e89

URL: 
https://github.com/llvm/llvm-project/commit/a2f32bfcc7cd6828785011ce90f6e0314d096e89
DIFF: 
https://github.com/llvm/llvm-project/commit/a2f32bfcc7cd6828785011ce90f6e0314d096e89.diff

LOG: [clang][Sema] SequenceChecker: C++17 sequencing rule for call expressions.

In C++17 the postfix-expression of a call expression is sequenced before
each expression in the expression-list and any default argument.

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

Reviewed By: rsmith

Added: 


Modified: 
clang/lib/Sema/SemaChecking.cpp
clang/test/SemaCXX/warn-unsequenced.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index c9fa2b993c1e..64df2740145b 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -12928,6 +12928,11 @@ class SequenceChecker : public 
ConstEvaluatedExprVisitor {
   }
 
   void VisitCallExpr(const CallExpr *CE) {
+// FIXME: CXXNewExpr and CXXDeleteExpr implicitly call functions.
+
+if (CE->isUnevaluatedBuiltinCall(Context))
+  return;
+
 // C++11 [intro.execution]p15:
 //   When calling a function [...], every value computation and side effect
 //   associated with any argument expression, or with the postfix 
expression
@@ -12935,10 +12940,41 @@ class SequenceChecker : public 
ConstEvaluatedExprVisitor {
 //   expression or statement in the body of the function [and thus before
 //   the value computation of its result].
 SequencedSubexpression Sequenced(*this);
-SemaRef.runWithSufficientStackSpace(CE->getExprLoc(),
-[&] { Base::VisitCallExpr(CE); });
+SemaRef.runWithSufficientStackSpace(CE->getExprLoc(), [&] {
+  // C++17 [expr.call]p5
+  //   The postfix-expression is sequenced before each expression in the
+  //   expression-list and any default argument. [...]
+  SequenceTree::Seq CalleeRegion;
+  SequenceTree::Seq OtherRegion;
+  if (SemaRef.getLangOpts().CPlusPlus17) {
+CalleeRegion = Tree.allocate(Region);
+OtherRegion = Tree.allocate(Region);
+  } else {
+CalleeRegion = Region;
+OtherRegion = Region;
+  }
+  SequenceTree::Seq OldRegion = Region;
 
-// FIXME: CXXNewExpr and CXXDeleteExpr implicitly call functions.
+  // Visit the callee expression first.
+  Region = CalleeRegion;
+  if (SemaRef.getLangOpts().CPlusPlus17) {
+SequencedSubexpression Sequenced(*this);
+Visit(CE->getCallee());
+  } else {
+Visit(CE->getCallee());
+  }
+
+  // Then visit the argument expressions.
+  Region = OtherRegion;
+  for (const Expr *Argument : CE->arguments())
+Visit(Argument);
+
+  Region = OldRegion;
+  if (SemaRef.getLangOpts().CPlusPlus17) {
+Tree.merge(CalleeRegion);
+Tree.merge(OtherRegion);
+  }
+});
   }
 
   void VisitCXXConstructExpr(const CXXConstructExpr *CCE) {

diff  --git a/clang/test/SemaCXX/warn-unsequenced.cpp 
b/clang/test/SemaCXX/warn-unsequenced.cpp
index 62f725bd0712..84b0f9fd5b2f 100644
--- a/clang/test/SemaCXX/warn-unsequenced.cpp
+++ b/clang/test/SemaCXX/warn-unsequenced.cpp
@@ -15,7 +15,6 @@ struct S {
   int n;
 };
 
-// TODO: Implement the C++17 sequencing rules.
 void test() {
   int a;
   int xs[10];
@@ -256,6 +255,27 @@ void test() {
   p[i++] = (i = 42); // cxx11-warning {{multiple unsequenced modifications to 
'i'}}
   p++[i++] = (i = p ? i++ : i++); // cxx11-warning {{unsequenced modification 
and access to 'p'}}
   // cxx11-warning@-1 {{multiple unsequenced 
modifications to 'i'}}
+
+  (i++, f)(i++, 42); // cxx11-warning {{multiple unsequenced modifications to 
'i'}}
+  (i++ + i++, f)(42, 42); // cxx11-warning {{multiple unsequenced 
modifications to 'i'}}
+  // cxx17-warning@-1 {{multiple unsequenced 
modifications to 'i'}}
+  int (*pf)(int, int);
+  (pf = f)(pf != nullptr, pf != nullptr); // cxx11-warning {{unsequenced 
modification and access to 'pf'}}
+  pf((pf = f) != nullptr, 42); // cxx11-warning {{unsequenced modification and 
access to 'pf'}}
+  f((pf = f, 42), (pf = f, 42)); // cxx11-warning {{multiple unsequenced 
modifications to 'pf'}}
+ // cxx17-warning@-1 {{multiple unsequenced 
modifications to 'pf'}}
+  pf((pf = f) != nullptr, pf == nullptr); // cxx11-warning {{unsequenced 
modification and access to 'pf'}}
+  // cxx17-warning@-1 {{unsequenced 
modification and access to 'pf'}}
+}
+
+namespace PR20819 {
+  struct foo { void bar(int); };
+  foo get_foo(int);
+
+  void g() {
+int a = 0;
+get_foo(a).bar(a++);  // cxx11-warning {{unsequenced modification and 
access to 'a'}}
+  }
 }
 

[clang] 7394c15 - [Sema] SequenceChecker: C++17 sequencing rules for built-in operators <<, >>, .*, ->*, =, op=

2019-12-22 Thread Bruno Ricci via cfe-commits

Author: Bruno Ricci
Date: 2019-12-22T12:41:14Z
New Revision: 7394c15178ed9cb7bd04585526a1e73396e60e17

URL: 
https://github.com/llvm/llvm-project/commit/7394c15178ed9cb7bd04585526a1e73396e60e17
DIFF: 
https://github.com/llvm/llvm-project/commit/7394c15178ed9cb7bd04585526a1e73396e60e17.diff

LOG: [Sema] SequenceChecker: C++17 sequencing rules for built-in operators <<, 
>>, .*, ->*, =, op=

Implement the C++17 sequencing rules for the built-in operators <<, >>, .*,
 ->*, = and op=.

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

Reviewed By: rsmith

Added: 


Modified: 
clang/lib/Sema/SemaChecking.cpp
clang/test/CXX/drs/dr2xx.cpp
clang/test/CXX/drs/dr6xx.cpp
clang/test/SemaCXX/warn-unsequenced.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 2cbe3632be3a..b8295bc741eb 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -12832,8 +12832,37 @@ class SequenceChecker : public 
ConstEvaluatedExprVisitor {
 //   expression E1 is sequenced before the expression E2.
 if (SemaRef.getLangOpts().CPlusPlus17)
   VisitSequencedExpressions(ASE->getLHS(), ASE->getRHS());
-else
-  Base::VisitStmt(ASE);
+else {
+  Visit(ASE->getLHS());
+  Visit(ASE->getRHS());
+}
+  }
+
+  void VisitBinPtrMemD(const BinaryOperator *BO) { VisitBinPtrMem(BO); }
+  void VisitBinPtrMemI(const BinaryOperator *BO) { VisitBinPtrMem(BO); }
+  void VisitBinPtrMem(const BinaryOperator *BO) {
+// C++17 [expr.mptr.oper]p4:
+//  Abbreviating pm-expression.*cast-expression as E1.*E2, [...]
+//  the expression E1 is sequenced before the expression E2.
+if (SemaRef.getLangOpts().CPlusPlus17)
+  VisitSequencedExpressions(BO->getLHS(), BO->getRHS());
+else {
+  Visit(BO->getLHS());
+  Visit(BO->getRHS());
+}
+  }
+
+  void VisitBinShl(const BinaryOperator *BO) { VisitBinShlShr(BO); }
+  void VisitBinShr(const BinaryOperator *BO) { VisitBinShlShr(BO); }
+  void VisitBinShlShr(const BinaryOperator *BO) {
+// C++17 [expr.shift]p4:
+//  The expression E1 is sequenced before the expression E2.
+if (SemaRef.getLangOpts().CPlusPlus17)
+  VisitSequencedExpressions(BO->getLHS(), BO->getRHS());
+else {
+  Visit(BO->getLHS());
+  Visit(BO->getRHS());
+}
   }
 
   void VisitBinComma(const BinaryOperator *BO) {
@@ -12845,38 +12874,67 @@ class SequenceChecker : public 
ConstEvaluatedExprVisitor {
   }
 
   void VisitBinAssign(const BinaryOperator *BO) {
-// The modification is sequenced after the value computation of the LHS
-// and RHS, so check it before inspecting the operands and update the
+SequenceTree::Seq RHSRegion;
+SequenceTree::Seq LHSRegion;
+if (SemaRef.getLangOpts().CPlusPlus17) {
+  RHSRegion = Tree.allocate(Region);
+  LHSRegion = Tree.allocate(Region);
+} else {
+  RHSRegion = Region;
+  LHSRegion = Region;
+}
+SequenceTree::Seq OldRegion = Region;
+
+// C++11 [expr.ass]p1:
+//  [...] the assignment is sequenced after the value computation
+//  of the right and left operands, [...]
+//
+// so check it before inspecting the operands and update the
 // map afterwards.
-Object O = getObject(BO->getLHS(), true);
-if (!O)
-  return VisitExpr(BO);
+Object O = getObject(BO->getLHS(), /*Mod=*/true);
+if (O)
+  notePreMod(O, BO);
+
+if (SemaRef.getLangOpts().CPlusPlus17) {
+  // C++17 [expr.ass]p1:
+  //  [...] The right operand is sequenced before the left operand. [...]
+  {
+SequencedSubexpression SeqBefore(*this);
+Region = RHSRegion;
+Visit(BO->getRHS());
+  }
 
-notePreMod(O, BO);
+  Region = LHSRegion;
+  Visit(BO->getLHS());
 
-// C++11 [expr.ass]p7:
-//   E1 op= E2 is equivalent to E1 = E1 op E2, except that E1 is evaluated
-//   only once.
-//
-// Therefore, for a compound assignment operator, O is considered used
-// everywhere except within the evaluation of E1 itself.
-if (isa(BO))
-  notePreUse(O, BO);
+  if (O && isa(BO))
+notePostUse(O, BO);
 
-Visit(BO->getLHS());
+} else {
+  // C++11 does not specify any sequencing between the LHS and RHS.
+  Region = LHSRegion;
+  Visit(BO->getLHS());
 
-if (isa(BO))
-  notePostUse(O, BO);
+  if (O && isa(BO))
+notePostUse(O, BO);
 
-Visit(BO->getRHS());
+  Region = RHSRegion;
+  Visit(BO->getRHS());
+}
 
 // C++11 [expr.ass]p1:
-//   the assignment is sequenced [...] before the value computation of the
-//   assignment expression.
+//  the assignment is sequenced [...] before the value computation of the
+//  assignment expression.
 // C11 6.5.16/3 has no such rule.
-notePostMod(O, BO,
-SemaRef.getLangOpts().CPlusPlus 

[clang] 8a57153 - [Sema] SequenceChecker: Fix handling of operator ||, && and ?:

2019-12-22 Thread Bruno Ricci via cfe-commits

Author: Bruno Ricci
Date: 2019-12-22T12:27:31Z
New Revision: 8a571538dff6dbc1b7f4fed6aed8be7ec1a00a8d

URL: 
https://github.com/llvm/llvm-project/commit/8a571538dff6dbc1b7f4fed6aed8be7ec1a00a8d
DIFF: 
https://github.com/llvm/llvm-project/commit/8a571538dff6dbc1b7f4fed6aed8be7ec1a00a8d.diff

LOG: [Sema] SequenceChecker: Fix handling of operator ||, && and ?:

The current handling of the operators ||, && and ?: has a number of false
positive and false negative. The issues for operator || and && are:

1. We need to add sequencing regions for the LHS and RHS as is done for the
   comma operator. Not doing so causes false positives in expressions like
   `((a++, false) || (a++, false))` (from PR39779, see PR22197 for another
example).

2. In the current implementation when the evaluation of the LHS fails, the RHS
   is added to a worklist to be processed later. This results in false negatives
   in expressions like `(a && a++) + a`.

Fix these issues by introducing sequencing regions for the LHS and RHS, and by
not deferring the visitation of the RHS.

The issues with the ternary operator ?: are similar, with the added twist that
we should not warn on expressions like `(x ? y += 1 : y += 2)` since exactly
one of the 2nd and 3rd expression is going to be evaluated, but we should still
warn on expressions like `(x ? y += 1 : y += 2) = y`.

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

Reviewed By: rsmith

Added: 


Modified: 
clang/lib/Sema/SemaChecking.cpp
clang/test/Sema/warn-unsequenced.c
clang/test/SemaCXX/warn-unsequenced.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 445a10b5eb8f..2cbe3632be3a 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -12779,6 +12779,9 @@ class SequenceChecker : public 
ConstEvaluatedExprVisitor {
   SmallVectorImpl )
   : Base(S.Context), SemaRef(S), Region(Tree.root()), WorkList(WorkList) {
 Visit(E);
+// Silence a -Wunused-private-field since WorkList is now unused.
+// TODO: Evaluate if it can be used, and if not remove it.
+(void)this->WorkList;
   }
 
   void VisitStmt(const Stmt *S) {
@@ -12908,64 +12911,126 @@ class SequenceChecker : public 
ConstEvaluatedExprVisitor {
 notePostMod(O, UO, UK_ModAsSideEffect);
   }
 
-  /// Don't visit the RHS of '&&' or '||' if it might not be evaluated.
   void VisitBinLOr(const BinaryOperator *BO) {
-// The side-effects of the LHS of an '&&' are sequenced before the
-// value computation of the RHS, and hence before the value computation
-// of the '&&' itself, unless the LHS evaluates to zero. We treat them
-// as if they were unconditionally sequenced.
+// C++11 [expr.log.or]p2:
+//  If the second expression is evaluated, every value computation and
+//  side effect associated with the first expression is sequenced before
+//  every value computation and side effect associated with the
+//  second expression.
+SequenceTree::Seq LHSRegion = Tree.allocate(Region);
+SequenceTree::Seq RHSRegion = Tree.allocate(Region);
+SequenceTree::Seq OldRegion = Region;
+
 EvaluationTracker Eval(*this);
 {
   SequencedSubexpression Sequenced(*this);
+  Region = LHSRegion;
   Visit(BO->getLHS());
 }
 
-bool Result;
-if (Eval.evaluate(BO->getLHS(), Result)) {
-  if (!Result)
-Visit(BO->getRHS());
-} else {
-  // Check for unsequenced operations in the RHS, treating it as an
-  // entirely separate evaluation.
-  //
-  // FIXME: If there are operations in the RHS which are unsequenced
-  // with respect to operations outside the RHS, and those operations
-  // are unconditionally evaluated, diagnose them.
-  WorkList.push_back(BO->getRHS());
+// C++11 [expr.log.or]p1:
+//  [...] the second operand is not evaluated if the first operand
+//  evaluates to true.
+bool EvalResult = false;
+bool EvalOK = Eval.evaluate(BO->getLHS(), EvalResult);
+bool ShouldVisitRHS = !EvalOK || (EvalOK && !EvalResult);
+if (ShouldVisitRHS) {
+  Region = RHSRegion;
+  Visit(BO->getRHS());
 }
+
+Region = OldRegion;
+Tree.merge(LHSRegion);
+Tree.merge(RHSRegion);
   }
+
   void VisitBinLAnd(const BinaryOperator *BO) {
+// C++11 [expr.log.and]p2:
+//  If the second expression is evaluated, every value computation and
+//  side effect associated with the first expression is sequenced before
+//  every value computation and side effect associated with the
+//  second expression.
+SequenceTree::Seq LHSRegion = Tree.allocate(Region);
+SequenceTree::Seq RHSRegion = Tree.allocate(Region);
+SequenceTree::Seq OldRegion = Region;
+
 EvaluationTracker Eval(*this);
 {
   SequencedSubexpression Sequenced(*this);
+  Region = 

[clang] b6eba31 - [Sema] SequenceChecker: Add some comments + related small NFCs

2019-12-22 Thread Bruno Ricci via cfe-commits

Author: Bruno Ricci
Date: 2019-12-22T12:07:26Z
New Revision: b6eba3129291639dcd72ba31ed4b6f0b4dbe09e7

URL: 
https://github.com/llvm/llvm-project/commit/b6eba3129291639dcd72ba31ed4b6f0b4dbe09e7
DIFF: 
https://github.com/llvm/llvm-project/commit/b6eba3129291639dcd72ba31ed4b6f0b4dbe09e7.diff

LOG: [Sema] SequenceChecker: Add some comments + related small NFCs

NFCs factored out of the following patches:
- Change all of the `Expr *` to `const Expr *` in SequenceChecker for
  const-correctness. SequenceChecker should not modify AST nodes.
- Add some comments.
- clang-format

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

Reviewed By: xbolva00

Added: 


Modified: 
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaChecking.cpp

Removed: 




diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 07eba0306c98..1507010f7432 100755
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -11620,7 +11620,7 @@ class Sema final {
   void CheckImplicitConversions(Expr *E, SourceLocation CC = SourceLocation());
   void CheckBoolLikeConversion(Expr *E, SourceLocation CC);
   void CheckForIntOverflow(Expr *E);
-  void CheckUnsequencedOperations(Expr *E);
+  void CheckUnsequencedOperations(const Expr *E);
 
   /// Perform semantic checks on a completed expression. This will either
   /// be a full-expression or a default argument expression.

diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index cc091b27fe56..445a10b5eb8f 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -12466,8 +12466,8 @@ namespace {
 
 /// Visitor for expressions which looks for unsequenced operations on the
 /// same object.
-class SequenceChecker : public EvaluatedExprVisitor {
-  using Base = EvaluatedExprVisitor;
+class SequenceChecker : public ConstEvaluatedExprVisitor {
+  using Base = ConstEvaluatedExprVisitor;
 
   /// A tree of sequenced regions within an expression. Two regions are
   /// unsequenced if one is an ancestor or a descendent of the other. When we
@@ -12537,7 +12537,7 @@ class SequenceChecker : public 
EvaluatedExprVisitor {
   };
 
   /// An object for which we can track unsequenced uses.
-  using Object = NamedDecl *;
+  using Object = const NamedDecl *;
 
   /// Different flavors of object usage which we track. We only track the
   /// least-sequenced usage of each kind.
@@ -12556,17 +12556,19 @@ class SequenceChecker : public 
EvaluatedExprVisitor {
 UK_Count = UK_ModAsSideEffect + 1
   };
 
+  /// Bundle together a sequencing region and the expression corresponding
+  /// to a specific usage. One Usage is stored for each usage kind in 
UsageInfo.
   struct Usage {
-Expr *Use;
+const Expr *UsageExpr;
 SequenceTree::Seq Seq;
 
-Usage() : Use(nullptr), Seq() {}
+Usage() : UsageExpr(nullptr), Seq() {}
   };
 
   struct UsageInfo {
 Usage Uses[UK_Count];
 
-/// Have we issued a diagnostic for this variable already?
+/// Have we issued a diagnostic for this object already?
 bool Diagnosed;
 
 UsageInfo() : Uses(), Diagnosed(false) {}
@@ -12590,7 +12592,7 @@ class SequenceChecker : public 
EvaluatedExprVisitor {
 
   /// Expressions to check later. We defer checking these to reduce
   /// stack usage.
-  SmallVectorImpl 
+  SmallVectorImpl 
 
   /// RAII object wrapping the visitation of a sequenced subexpression of an
   /// expression. At the end of this process, the side-effects of the 
evaluation
@@ -12604,10 +12606,13 @@ class SequenceChecker : public 
EvaluatedExprVisitor {
 }
 
 ~SequencedSubexpression() {
-  for (auto  : llvm::reverse(ModAsSideEffect)) {
-UsageInfo  = Self.UsageMap[M.first];
-auto  = U.Uses[UK_ModAsSideEffect];
-Self.addUsage(U, M.first, SideEffectUsage.Use, UK_ModAsValue);
+  for (const std::pair  : llvm::reverse(ModAsSideEffect)) 
{
+// Add a new usage with usage kind UK_ModAsValue, and then restore
+// the previous usage with UK_ModAsSideEffect (thus clearing it if
+// the previous one was empty).
+UsageInfo  = Self.UsageMap[M.first];
+auto  = UI.Uses[UK_ModAsSideEffect];
+Self.addUsage(M.first, UI, SideEffectUsage.UsageExpr, UK_ModAsValue);
 SideEffectUsage = M.second;
   }
   Self.ModAsSideEffect = OldModAsSideEffect;
@@ -12651,49 +12656,60 @@ class SequenceChecker : public 
EvaluatedExprVisitor {
 
   /// Find the object which is produced by the specified expression,
   /// if any.
-  Object getObject(Expr *E, bool Mod) const {
+  Object getObject(const Expr *E, bool Mod) const {
 E = E->IgnoreParenCasts();
-if (UnaryOperator *UO = dyn_cast(E)) {
+if (const UnaryOperator *UO = dyn_cast(E)) {
   if (Mod && (UO->getOpcode() == UO_PreInc || UO->getOpcode() == 
UO_PreDec))
 return getObject(UO->getSubExpr(), 

r370044 - [clang] Ensure that statements, expressions and types are trivially destructible

2019-08-27 Thread Bruno Ricci via cfe-commits
Author: brunoricci
Date: Tue Aug 27 04:35:49 2019
New Revision: 370044

URL: http://llvm.org/viewvc/llvm-project?rev=370044=rev
Log:
[clang] Ensure that statements, expressions and types are trivially destructible

Since statements, expressions and types are allocated with the BumpPtrAllocator
from ASTContext their destructor is not executed. Two classes are currently
exempted from the check : InitListExpr due to its ASTVector and
ConstantArrayType due to its APInt.

No functional changes.

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

Reviewed By: lebedev.ri, gribozavr

Modified:
cfe/trunk/lib/AST/Stmt.cpp
cfe/trunk/lib/AST/Type.cpp

Modified: cfe/trunk/lib/AST/Stmt.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Stmt.cpp?rev=370044=370043=370044=diff
==
--- cfe/trunk/lib/AST/Stmt.cpp (original)
+++ cfe/trunk/lib/AST/Stmt.cpp Tue Aug 27 04:35:49 2019
@@ -41,6 +41,7 @@
 #include 
 #include 
 #include 
+#include 
 
 using namespace clang;
 
@@ -83,6 +84,16 @@ const char *Stmt::getStmtClassName() con
 #CLASS " should not be polymorphic!");
 #include "clang/AST/StmtNodes.inc"
 
+// Check that no statement / expression class has a non-trival destructor.
+// Statements and expressions are allocated with the BumpPtrAllocator from
+// ASTContext and therefore their destructor is not executed.
+#define STMT(CLASS, PARENT)
\
+  static_assert(std::is_trivially_destructible::value,  
\
+#CLASS " should be trivially destructible!");
+// FIXME: InitListExpr is not trivially destructible due to its ASTVector.
+#define INITLISTEXPR(CLASS, PARENT)
+#include "clang/AST/StmtNodes.inc"
+
 void Stmt::PrintStats() {
   // Ensure the table is primed.
   getStmtInfoTableEntry(Stmt::NullStmtClass);

Modified: cfe/trunk/lib/AST/Type.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Type.cpp?rev=370044=370043=370044=diff
==
--- cfe/trunk/lib/AST/Type.cpp (original)
+++ cfe/trunk/lib/AST/Type.cpp Tue Aug 27 04:35:49 2019
@@ -50,6 +50,7 @@
 #include 
 #include 
 #include 
+#include 
 
 using namespace clang;
 
@@ -299,6 +300,18 @@ QualType QualType::getSingleStepDesugare
 #CLASS "Type should not be polymorphic!");
 #include "clang/AST/TypeNodes.def"
 
+// Check that no type class has a non-trival destructor. Types are
+// allocated with the BumpPtrAllocator from ASTContext and therefore
+// their destructor is not executed.
+//
+// FIXME: ConstantArrayType is not trivially destructible because of its
+// APInt member. It should be replaced in favor of ASTContext allocation.
+#define TYPE(CLASS, BASE)  
\
+  static_assert(std::is_trivially_destructible::value ||  
\
+std::is_same::value,   
\
+#CLASS "Type should be trivially destructible!");
+#include "clang/AST/TypeNodes.def"
+
 QualType Type::getLocallyUnqualifiedSingleStepDesugaredType() const {
   switch (getTypeClass()) {
 #define ABSTRACT_TYPE(Class, Parent)


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


r370041 - [clang] Ensure that comment classes are trivially destructible

2019-08-27 Thread Bruno Ricci via cfe-commits
Author: brunoricci
Date: Tue Aug 27 04:21:00 2019
New Revision: 370041

URL: http://llvm.org/viewvc/llvm-project?rev=370041=rev
Log:
[clang] Ensure that comment classes are trivially destructible

As in D66646, these classes are also allocated with a BumpPtrAllocator,
and therefore should be trivially destructible.

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

Reviewed By: Mordante, gribozavr

Modified:
cfe/trunk/lib/AST/Comment.cpp

Modified: cfe/trunk/lib/AST/Comment.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Comment.cpp?rev=370041=370040=370041=diff
==
--- cfe/trunk/lib/AST/Comment.cpp (original)
+++ cfe/trunk/lib/AST/Comment.cpp Tue Aug 27 04:21:00 2019
@@ -13,10 +13,25 @@
 #include "clang/AST/DeclTemplate.h"
 #include "clang/Basic/CharInfo.h"
 #include "llvm/Support/ErrorHandling.h"
+#include 
 
 namespace clang {
 namespace comments {
 
+// Check that no comment class has a non-trival destructor. They are allocated
+// with a BumpPtrAllocator and therefore their destructor is not executed.
+#define ABSTRACT_COMMENT(COMMENT)
+#define COMMENT(CLASS, PARENT) 
\
+  static_assert(std::is_trivially_destructible::value,  
\
+#CLASS " should be trivially destructible!");
+#include "clang/AST/CommentNodes.inc"
+#undef COMMENT
+#undef ABSTRACT_COMMENT
+
+// DeclInfo is also allocated with a BumpPtrAllocator.
+static_assert(std::is_trivially_destructible::value,
+  "DeclInfo should be trivially destructible!");
+
 const char *Comment::getCommentKindName() const {
   switch (getCommentKind()) {
   case NoCommentKind: return "NoCommentKind";


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


r358882 - [Sema] ADL: Associated namespaces for class types and enumeration types (CWG 1691)

2019-04-22 Thread Bruno Ricci via cfe-commits
Author: brunoricci
Date: Mon Apr 22 05:19:00 2019
New Revision: 358882

URL: http://llvm.org/viewvc/llvm-project?rev=358882=rev
Log:
[Sema] ADL: Associated namespaces for class types and enumeration types (CWG 
1691)

CWG 1691 changed the definition of the namespaces associated with a class
type or enumeration type.

For a class type, the associated namespaces are the innermost enclosing
namespaces of the associated classes. For an enumeration type, the associated
namespace is the innermost enclosing namespace of its declaration.

This also fixes CWG 1690 and CWG 1692.

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

Reviewed By: rjmccall, rsmith


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

cfe/trunk/test/CXX/basic/basic.lookup/basic.lookup.argdep/p2-associated-namespaces-classes.cpp
cfe/trunk/test/CXX/drs/dr16xx.cpp

Modified: cfe/trunk/lib/Sema/SemaLookup.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaLookup.cpp?rev=358882=358881=358882=diff
==
--- cfe/trunk/lib/Sema/SemaLookup.cpp (original)
+++ cfe/trunk/lib/Sema/SemaLookup.cpp Mon Apr 22 05:19:00 2019
@@ -2471,30 +2471,38 @@ namespace {
 static void
 addAssociatedClassesAndNamespaces(AssociatedLookup , QualType T);
 
+// Given the declaration context \param Ctx of a class, class template or
+// enumeration, add the associated namespaces to \param Namespaces as described
+// in [basic.lookup.argdep]p2.
 static void CollectEnclosingNamespace(Sema::AssociatedNamespaceSet ,
   DeclContext *Ctx) {
-  // Add the associated namespace for this class.
-
-  // We don't use DeclContext::getEnclosingNamespaceContext() as this may
-  // be a locally scoped record.
+  // The exact wording has been changed in C++14 as a result of
+  // CWG 1691 (see also CWG 1690 and CWG 1692). We apply it unconditionally
+  // to all language versions since it is possible to return a local type
+  // from a lambda in C++11.
+  //
+  // C++14 [basic.lookup.argdep]p2:
+  //   If T is a class type [...]. Its associated namespaces are the innermost
+  //   enclosing namespaces of its associated classes. [...]
+  //
+  //   If T is an enumeration type, its associated namespace is the innermost
+  //   enclosing namespace of its declaration. [...]
 
-  // We skip out of inline namespaces. The innermost non-inline namespace
+  // We additionally skip inline namespaces. The innermost non-inline namespace
   // contains all names of all its nested inline namespaces anyway, so we can
   // replace the entire inline namespace tree with its root.
-  while (Ctx->isRecord() || Ctx->isTransparentContext() ||
- Ctx->isInlineNamespace())
+  while (!Ctx->isFileContext() || Ctx->isInlineNamespace())
 Ctx = Ctx->getParent();
 
-  if (Ctx->isFileContext())
-Namespaces.insert(Ctx->getPrimaryContext());
+  Namespaces.insert(Ctx->getPrimaryContext());
 }
 
 // Add the associated classes and namespaces for argument-dependent
-// lookup that involves a template argument (C++ [basic.lookup.koenig]p2).
+// lookup that involves a template argument (C++ [basic.lookup.argdep]p2).
 static void
 addAssociatedClassesAndNamespaces(AssociatedLookup ,
   const TemplateArgument ) {
-  // C++ [basic.lookup.koenig]p2, last bullet:
+  // C++ [basic.lookup.argdep]p2, last bullet:
   //   -- [...] ;
   switch (Arg.getKind()) {
 case TemplateArgument::Null:
@@ -2539,9 +2547,8 @@ addAssociatedClassesAndNamespaces(Associ
   }
 }
 
-// Add the associated classes and namespaces for
-// argument-dependent lookup with an argument of class type
-// (C++ [basic.lookup.koenig]p2).
+// Add the associated classes and namespaces for argument-dependent lookup
+// with an argument of class type (C++ [basic.lookup.argdep]p2).
 static void
 addAssociatedClassesAndNamespaces(AssociatedLookup ,
   CXXRecordDecl *Class) {
@@ -2550,18 +2557,19 @@ addAssociatedClassesAndNamespaces(Associ
   if (Class->getDeclName() == Result.S.VAListTagName)
 return;
 
-  // C++ [basic.lookup.koenig]p2:
+  // C++ [basic.lookup.argdep]p2:
   //   [...]
   // -- If T is a class type (including unions), its associated
   //classes are: the class itself; the class of which it is a
-  //member, if any; and its direct and indirect base
-  //classes. Its associated namespaces are the namespaces in
-  //which its associated classes are defined.
+  //member, if any; and its direct and indirect base classes.
+  //Its associated namespaces are the innermost enclosing
+  //namespaces of its associated classes.
 
   // Add the class of which it is a member, if any.
   DeclContext *Ctx = Class->getDeclContext();
   if (CXXRecordDecl *EnclosingClass = dyn_cast(Ctx))
 Result.Classes.insert(EnclosingClass);
+
   // Add the associated namespace for this class.
   

r358881 - [Sema][NFC] Add more tests for the behavior of argument-dependent name lookup

2019-04-22 Thread Bruno Ricci via cfe-commits
Author: brunoricci
Date: Mon Apr 22 04:40:31 2019
New Revision: 358881

URL: http://llvm.org/viewvc/llvm-project?rev=358881=rev
Log:
[Sema][NFC] Add more tests for the behavior of argument-dependent name lookup

The goal here is to exercise each rule in [basic.lookup.argdep] at least once.
These new tests expose what I believe are 2 issues:

1. CWG 1691 needs to be implemented (p2:  [...] Its associated namespaces are
   the innermost enclosing namespaces of its associated classes [...]) The
   corresponding tests are adl_class_type::X2 and adl_class_type::X5.

2. The end of paragraph 2 ([...] Additionally, if the aforementioned set of
   overloaded functions is named with a template-id, its associated classes
   and namespaces also include those of its type template-arguments and its
   template template-arguments.) is not implemented. Closely related, the
   restriction on non-dependent parameter types in this same paragraph needs
   to be removed. The corresponding tests are in adl_overload_set (both issues
   are from CWG 997).

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

Reviewed By: riccibruno, Quuxplusone


Added:

cfe/trunk/test/CXX/basic/basic.lookup/basic.lookup.argdep/p2-associated-namespaces-classes.cpp

cfe/trunk/test/CXX/basic/basic.lookup/basic.lookup.argdep/p2-inline-namespace.cpp
Modified:
cfe/trunk/test/CXX/basic/basic.lookup/basic.lookup.argdep/p2.cpp
cfe/trunk/test/CXX/basic/basic.lookup/basic.lookup.argdep/p3.cpp
cfe/trunk/test/CXX/basic/basic.lookup/basic.lookup.argdep/p4.cpp

Added: 
cfe/trunk/test/CXX/basic/basic.lookup/basic.lookup.argdep/p2-associated-namespaces-classes.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/basic/basic.lookup/basic.lookup.argdep/p2-associated-namespaces-classes.cpp?rev=358881=auto
==
--- 
cfe/trunk/test/CXX/basic/basic.lookup/basic.lookup.argdep/p2-associated-namespaces-classes.cpp
 (added)
+++ 
cfe/trunk/test/CXX/basic/basic.lookup/basic.lookup.argdep/p2-associated-namespaces-classes.cpp
 Mon Apr 22 04:40:31 2019
@@ -0,0 +1,336 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++17 %s
+
+// Attempt to test each rule for forming associated namespaces
+// and classes as described in [basic.lookup.argdep]p2.
+
+// fundamental type: no associated namespace and no associated class
+namespace adl_fundamental_type {
+  constexpr int g(char) { return 1; } // #1
+  template  constexpr int foo(T t) { return g(t); }
+  constexpr int g(int) { return 2; } // #2 not found
+  void test() {
+static_assert(foo(0) == 1); // ok, #1
+  }
+}
+
+// class type:
+//   associated classes: itself, the class of which it is a member (if any),
+//   direct and indirect base classes
+//   associated namespaces: innermost enclosing namespaces of associated 
classes
+namespace adl_class_type {
+  // associated class: itself, simple case
+  namespace X1 {
+namespace N {
+  struct S {};
+  void f(S); // found
+}
+void g(N::S); // not found
+  };
+  void test1() {
+f(X1::N::S{}); // ok
+g(X1::N::S{}); // expected-error {{use of undeclared identifier}}
+  }
+
+  // associated class: itself, local type
+  namespace X2 {
+auto foo() {
+  struct S {} s;
+  return s;
+}
+using S = decltype(foo());
+void f(S); // expected-note {{'X2::f' declared here}}
+  }
+  void test2() {
+f(X2::S{}); // FIXME: This is well-formed; X2 is the innermost enclosing 
namespace
+// of the local struct S.
+// expected-error@-2 {{use of undeclared identifier 'f'}}
+  }
+
+  // associated class: the parent class
+  namespace X3 {
+struct S {
+  struct T {};
+  friend void f(T);
+};
+  }
+  void test3() {
+f(X3::S::T{}); // ok
+  }
+
+  // associated class: direct and indirect base classes
+  namespace X4 {
+namespace IndirectBaseNamespace {
+  struct IndirectBase {};
+  void f(IndirectBase); // #1
+}
+namespace DirectBaseNamespace {
+  struct DirectBase : IndirectBaseNamespace::IndirectBase {};
+  void g(DirectBase); // #2
+}
+struct S : DirectBaseNamespace::DirectBase {};
+  }
+  void test4() {
+f(X4::S{}); // ok, #1
+g(X4::S{}); // ok, #2
+  }
+
+  // associated class: itself, lambda
+  namespace X5 {
+namespace N {
+  auto get_lambda() { return [](){}; }
+  void f(decltype(get_lambda()));
+}
+
+void test5() {
+  auto lambda = N::get_lambda();
+  f(lambda); // FIXME: This is well-formed. expected-error {{use of 
undeclared}}
+}
+  }
+
+  // The parameter types and return type of a lambda's operator() do not
+  // contribute to the associated namespaces and classes of the lambda itself.
+  namespace X6 {
+namespace N {
+  struct A {};
+  template constexpr int f(T) { return 1; }
+}
+
+constexpr int f(N::A (*)()) { return 2; }
+constexpr int f(void (*)(N::A)) { 

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


r358679 - [Sema][NFC] Mark DR1563 as done (List-initialization and overloaded function disambiguation)

2019-04-18 Thread Bruno Ricci via cfe-commits
Author: brunoricci
Date: Thu Apr 18 08:45:08 2019
New Revision: 358679

URL: http://llvm.org/viewvc/llvm-project?rev=358679=rev
Log:
[Sema][NFC] Mark DR1563 as done (List-initialization and overloaded function 
disambiguation)

It has been supported since at least clang 3.1 so just mark it as done.


Modified:
cfe/trunk/test/CXX/drs/dr15xx.cpp

Modified: cfe/trunk/test/CXX/drs/dr15xx.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/drs/dr15xx.cpp?rev=358679=358678=358679=diff
==
--- cfe/trunk/test/CXX/drs/dr15xx.cpp (original)
+++ cfe/trunk/test/CXX/drs/dr15xx.cpp Thu Apr 18 08:45:08 2019
@@ -236,6 +236,16 @@ namespace dr1560 { // dr1560: 3.5
   const X  = true ? get() : throw 0;
 }
 
+namespace dr1563 { // dr1563: yes
+#if __cplusplus >= 201103L
+  double bar(double) { return 0.0; }
+  float bar(float) { return 0.0f; }
+
+  using fun = double(double);
+  fun {bar}; // ok
+#endif
+}
+
 namespace dr1573 { // dr1573: 3.9
 #if __cplusplus >= 201103L
   // ellipsis is inherited (p0136r1 supersedes this part).


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


r358678 - [Sema][NFC] Mark DR705 (Suppressing argument-dependent lookup via parentheses) as done

2019-04-18 Thread Bruno Ricci via cfe-commits
Author: brunoricci
Date: Thu Apr 18 08:34:03 2019
New Revision: 358678

URL: http://llvm.org/viewvc/llvm-project?rev=358678=rev
Log:
[Sema][NFC] Mark DR705 (Suppressing argument-dependent lookup via parentheses) 
as done

It was supported since at least clang 3 so just mark it as done.


Modified:
cfe/trunk/test/CXX/drs/dr7xx.cpp

Modified: cfe/trunk/test/CXX/drs/dr7xx.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/drs/dr7xx.cpp?rev=358678=358677=358678=diff
==
--- cfe/trunk/test/CXX/drs/dr7xx.cpp (original)
+++ cfe/trunk/test/CXX/drs/dr7xx.cpp Thu Apr 18 08:34:03 2019
@@ -3,6 +3,19 @@
 // RUN: %clang_cc1 -std=c++14 %s -verify -fexceptions -fcxx-exceptions 
-pedantic-errors
 // RUN: %clang_cc1 -std=c++1z %s -verify -fexceptions -fcxx-exceptions 
-pedantic-errors
 
+namespace dr705 { // dr705: yes
+  namespace N {
+struct S {};
+void f(S); // expected-note {{declared here}}
+  }
+
+  void g() {
+N::S s;
+f(s);  // ok
+(f)(s);// expected-error {{use of undeclared}}
+  }
+}
+
 namespace dr727 { // dr727: partial
   struct A {
 template struct C; // expected-note 6{{here}}


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


r358674 - [Serialization] Stable serialization order for OpenCLTypeExtMap and OpenCLDeclExtMap

2019-04-18 Thread Bruno Ricci via cfe-commits
Author: brunoricci
Date: Thu Apr 18 08:13:27 2019
New Revision: 358674

URL: http://llvm.org/viewvc/llvm-project?rev=358674=rev
Log:
[Serialization] Stable serialization order for OpenCLTypeExtMap and 
OpenCLDeclExtMap

Sort the elements of Sema::OpenCLTypeExtMap and Sema::OpenCLDeclExtMap
by TypeIDs and DeclIDs to guarantee a stable serialization order.

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

Reviewed By: Anastasia

Reviewers: Anastasia, lebedev.ri


Modified:
cfe/trunk/lib/Serialization/ASTWriter.cpp

Modified: cfe/trunk/lib/Serialization/ASTWriter.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTWriter.cpp?rev=358674=358673=358674=diff
==
--- cfe/trunk/lib/Serialization/ASTWriter.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTWriter.cpp Thu Apr 18 08:13:27 2019
@@ -4278,14 +4278,32 @@ void ASTWriter::WriteOpenCLExtensionType
   if (!SemaRef.Context.getLangOpts().OpenCL)
 return;
 
+  // Sort the elements of the map OpenCLTypeExtMap by TypeIDs,
+  // without copying them.
+  const llvm::DenseMap>  =
+  SemaRef.OpenCLTypeExtMap;
+  using ElementTy = std::pair *>;
+  llvm::SmallVector StableOpenCLTypeExtMap;
+  StableOpenCLTypeExtMap.reserve(OpenCLTypeExtMap.size());
+
+  for (const auto  : OpenCLTypeExtMap)
+StableOpenCLTypeExtMap.emplace_back(
+getTypeID(I.first->getCanonicalTypeInternal()), );
+
+  auto CompareByTypeID = [](const ElementTy , const ElementTy ) -> bool {
+return E1.first < E2.first;
+  };
+  llvm::sort(StableOpenCLTypeExtMap, CompareByTypeID);
+
   RecordData Record;
-  for (const auto  : SemaRef.OpenCLTypeExtMap) {
-Record.push_back(
-static_cast(getTypeID(I.first->getCanonicalTypeInternal(;
-Record.push_back(I.second.size());
-for (auto Ext : I.second)
+  for (const ElementTy  : StableOpenCLTypeExtMap) {
+Record.push_back(E.first); // TypeID
+const std::set *ExtSet = E.second;
+Record.push_back(static_cast(ExtSet->size()));
+for (const std::string  : *ExtSet)
   AddString(Ext, Record);
   }
+
   Stream.EmitRecord(OPENCL_EXTENSION_TYPES, Record);
 }
 
@@ -4293,13 +4311,31 @@ void ASTWriter::WriteOpenCLExtensionDecl
   if (!SemaRef.Context.getLangOpts().OpenCL)
 return;
 
+  // Sort the elements of the map OpenCLDeclExtMap by DeclIDs,
+  // without copying them.
+  const llvm::DenseMap>  =
+  SemaRef.OpenCLDeclExtMap;
+  using ElementTy = std::pair *>;
+  llvm::SmallVector StableOpenCLDeclExtMap;
+  StableOpenCLDeclExtMap.reserve(OpenCLDeclExtMap.size());
+
+  for (const auto  : OpenCLDeclExtMap)
+StableOpenCLDeclExtMap.emplace_back(getDeclID(I.first), );
+
+  auto CompareByDeclID = [](const ElementTy , const ElementTy ) -> bool {
+return E1.first < E2.first;
+  };
+  llvm::sort(StableOpenCLDeclExtMap, CompareByDeclID);
+
   RecordData Record;
-  for (const auto  : SemaRef.OpenCLDeclExtMap) {
-Record.push_back(getDeclID(I.first));
-Record.push_back(static_cast(I.second.size()));
-for (auto Ext : I.second)
+  for (const ElementTy  : StableOpenCLDeclExtMap) {
+Record.push_back(E.first); // DeclID
+const std::set *ExtSet = E.second;
+Record.push_back(static_cast(ExtSet->size()));
+for (const std::string  : *ExtSet)
   AddString(Ext, Record);
   }
+
   Stream.EmitRecord(OPENCL_EXTENSION_DECLS, Record);
 }
 


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


r358288 - [AST][NFC] Add const children() accessors to all AST nodes

2019-04-12 Thread Bruno Ricci via cfe-commits
Author: brunoricci
Date: Fri Apr 12 08:36:02 2019
New Revision: 358288

URL: http://llvm.org/viewvc/llvm-project?rev=358288=rev
Log:
[AST][NFC] Add const children() accessors to all AST nodes

Systematically add the const-qualified version of children()
to all statement/expression nodes. Previously the const-qualified
variant was only defined for some nodes. NFC.

Patch by: Nicolas Manichon

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

Reviewed By: riccibruno


Modified:
cfe/trunk/include/clang/AST/Expr.h
cfe/trunk/include/clang/AST/ExprCXX.h
cfe/trunk/include/clang/AST/ExprObjC.h
cfe/trunk/include/clang/AST/ExprOpenMP.h
cfe/trunk/include/clang/AST/OpenMPClause.h
cfe/trunk/include/clang/AST/Stmt.h
cfe/trunk/include/clang/AST/StmtCXX.h
cfe/trunk/include/clang/AST/StmtObjC.h
cfe/trunk/include/clang/AST/StmtOpenMP.h
cfe/trunk/lib/AST/ExprObjC.cpp
cfe/trunk/lib/AST/Stmt.cpp

Modified: cfe/trunk/include/clang/AST/Expr.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=358288=358287=358288=diff
==
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Fri Apr 12 08:36:02 2019
@@ -1870,6 +1870,11 @@ public:
 return child_range(getTrailingObjects(),
getTrailingObjects() + hasFunctionName());
   }
+
+  const_child_range children() const {
+return const_child_range(getTrailingObjects(),
+ getTrailingObjects() + hasFunctionName());
+  }
 };
 
 /// ParenExpr - This represents a parethesized expression, e.g. "(1)".  This

Modified: cfe/trunk/include/clang/AST/ExprCXX.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ExprCXX.h?rev=358288=358287=358288=diff
==
--- cfe/trunk/include/clang/AST/ExprCXX.h (original)
+++ cfe/trunk/include/clang/AST/ExprCXX.h Fri Apr 12 08:36:02 2019
@@ -587,6 +587,10 @@ public:
   child_range children() {
 return child_range(child_iterator(), child_iterator());
   }
+
+  const_child_range children() const {
+return const_child_range(const_child_iterator(), const_child_iterator());
+  }
 };
 
 /// The null pointer literal (C++11 [lex.nullptr])
@@ -616,6 +620,10 @@ public:
   child_range children() {
 return child_range(child_iterator(), child_iterator());
   }
+
+  const_child_range children() const {
+return const_child_range(const_child_iterator(), const_child_iterator());
+  }
 };
 
 /// Implicit construction of a std::initializer_list object from an
@@ -658,6 +666,10 @@ public:
   }
 
   child_range children() { return child_range(,  + 1); }
+
+  const_child_range children() const {
+return const_child_range(,  + 1);
+  }
 };
 
 /// A C++ \c typeid expression (C++ [expr.typeid]), which gets
@@ -748,6 +760,15 @@ public:
 auto **begin = reinterpret_cast();
 return child_range(begin, begin + 1);
   }
+
+  const_child_range children() const {
+if (isTypeOperand())
+  return const_child_range(const_child_iterator(), const_child_iterator());
+
+auto **begin =
+reinterpret_cast(_cast(this)->Operand);
+return const_child_range(begin, begin + 1);
+  }
 };
 
 /// A member reference to an MSPropertyDecl.
@@ -802,6 +823,11 @@ public:
 return child_range((Stmt**), (Stmt**) + 1);
   }
 
+  const_child_range children() const {
+auto Children = const_cast(this)->children();
+return const_child_range(Children.begin(), Children.end());
+  }
+
   static bool classof(const Stmt *T) {
 return T->getStmtClass() == MSPropertyRefExprClass;
   }
@@ -877,6 +903,10 @@ public:
   child_range children() {
 return child_range([0], [0] + NUM_SUBEXPRS);
   }
+
+  const_child_range children() const {
+return const_child_range([0], [0] + NUM_SUBEXPRS);
+  }
 };
 
 /// A Microsoft C++ @c __uuidof expression, which gets
@@ -958,6 +988,14 @@ public:
 auto **begin = reinterpret_cast();
 return child_range(begin, begin + 1);
   }
+
+  const_child_range children() const {
+if (isTypeOperand())
+  return const_child_range(const_child_iterator(), const_child_iterator());
+auto **begin =
+reinterpret_cast(_cast(this)->Operand);
+return const_child_range(begin, begin + 1);
+  }
 };
 
 /// Represents the \c this expression in C++.
@@ -1004,6 +1042,10 @@ public:
   child_range children() {
 return child_range(child_iterator(), child_iterator());
   }
+
+  const_child_range children() const {
+return const_child_range(const_child_iterator(), const_child_iterator());
+  }
 };
 
 /// A C++ throw-expression (C++ [except.throw]).
@@ -1062,6 +1104,10 @@ public:
   child_range children() {
 return child_range(, Operand ?  + 1 : );
   }
+
+  const_child_range children() const {
+return const_child_range(, Operand ?  + 1 : );
+  }
 };
 
 /// A default argument (C++ 

Re: [clangd] Print template arguments helper

2019-04-12 Thread Bruno Ricci via cfe-commits
Hi,

It seems that one of r358272, r358273 or r358274 is causing some asan
failure on my machine. Not sure why it is not spotted by the bots.

Failure log attached.

Bruno
FAIL: Extra Tools Unit Tests :: 
clangd/./ClangdTests/ASTUtilsTests/ASTUtils.PrintTemplateArgs/1 (878 of 1313)
 TEST 'Extra Tools Unit Tests :: 
clangd/./ClangdTests/ASTUtilsTests/ASTUtils.PrintTemplateArgs/1' FAILED 

Note: Google Test filter = ASTUtilsTests/ASTUtils.PrintTemplateArgs/1
[==] Running 1 test from 1 test case.
[--] Global test environment set-up.
[--] 1 test from ASTUtilsTests/ASTUtils
[ RUN  ] ASTUtilsTests/ASTUtils.PrintTemplateArgs/1
Preamble for file /clangd-test/TestTU.cpp cannot be reused. Attempting to 
rebuild it.
Built preamble of size 199084 for file /clangd-test/TestTU.cpp
=
==14611==ERROR: AddressSanitizer: heap-buffer-overflow on address 
0x602075a0 at pc 0x020df0e5 bp 0x7ffd01321e30 sp 0x7ffd01321e28
READ of size 4 at 0x602075a0 thread T0
#0 0x20df0e4 in __eq 
/usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/tuple:1388:36
#1 0x20df0e4 in operator== /usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/tuple:1421
#2 0x20df0e4 in operator== 
/home/bruno/software/llvm/tools/clang/tools/extra/clangd/Protocol.h:136
#3 0x20df0e4 in operator!= 
/home/bruno/software/llvm/tools/clang/tools/extra/clangd/Protocol.h:140
#4 0x20df0e4 in VisitNamedDecl 
/home/bruno/software/llvm/tools/clang/tools/extra/unittests/clangd/PrintASTTests.cpp:42
#5 0x20df0e4 in clang::RecursiveASTVisitor::WalkUpFromNamedDecl(clang::NamedDecl*)
 /mnt/data/llvm-asan-build/tools/clang/include/clang/AST/DeclNodes.inc:95
#6 0x20a7307 in WalkUpFromTypeDecl 
/mnt/data/llvm-asan-build/tools/clang/include/clang/AST/DeclNodes.inc:233:1
#7 0x20a7307 in WalkUpFromTemplateTypeParmDecl 
/mnt/data/llvm-asan-build/tools/clang/include/clang/AST/DeclNodes.inc:281
#8 0x20a7307 in TraverseTemplateTypeParmDecl 
/home/bruno/software/llvm/tools/clang/include/clang/AST/RecursiveASTVisitor.h:1770
#9 0x20a7307 in clang::RecursiveASTVisitor::TraverseDecl(clang::Decl*)
 /mnt/data/llvm-asan-build/tools/clang/include/clang/AST/DeclNodes.inc:281
#10 0x20a7685 in TraverseClassTemplatePartialSpecializationDecl 
/home/bruno/software/llvm/tools/clang/include/clang/AST/RecursiveASTVisitor.h:1910:1
#11 0x20a7685 in clang::RecursiveASTVisitor::TraverseDecl(clang::Decl*)
 /mnt/data/llvm-asan-build/tools/clang/include/clang/AST/DeclNodes.inc:259
#12 0x20ad76a in clang::RecursiveASTVisitor::TraverseDeclContextHelper(clang::DeclContext*)
 
/home/bruno/software/llvm/tools/clang/include/clang/AST/RecursiveASTVisitor.h:1387:7
#13 0x20a7116 in clang::RecursiveASTVisitor::TraverseDecl(clang::Decl*)
 /home/bruno/software/llvm/tools/clang/include/clang/AST/Decl.h
#14 0x20a5cf9 in clang::clangd::(anonymous 
namespace)::ASTUtils_PrintTemplateArgs_Test::TestBody() 
/home/bruno/software/llvm/tools/clang/tools/extra/unittests/clangd/PrintASTTests.cpp:51:5
#15 0x2d17dd8 in testing::Test::Run() 
/home/bruno/software/llvm/utils/unittest/googletest/src/gtest.cc
#16 0x2d1ca4a in testing::TestInfo::Run() 
/home/bruno/software/llvm/utils/unittest/googletest/src/gtest.cc:2656:11
#17 0x2d1e280 in testing::TestCase::Run() 
/home/bruno/software/llvm/utils/unittest/googletest/src/gtest.cc:2774:28
#18 0x2d37d9d in testing::internal::UnitTestImpl::RunAllTests() 
/home/bruno/software/llvm/utils/unittest/googletest/src/gtest.cc:4649:43
#19 0x2d365b6 in testing::UnitTest::Run() 
/home/bruno/software/llvm/utils/unittest/googletest/src/gtest.cc
#20 0x2cfef66 in RUN_ALL_TESTS 
/home/bruno/software/llvm/utils/unittest/googletest/include/gtest/gtest.h:2233:46
#21 0x2cfef66 in main 
/home/bruno/software/llvm/utils/unittest/UnitTestMain/TestMain.cpp:50
#22 0x7f04a1a8a09a in __libc_start_main 
/build/glibc-B9XfQf/glibc-2.28/csu/../csu/libc-start.c:308:16
#23 0x1f97029 in _start 
(/mnt/data/llvm-asan-build/tools/clang/tools/extra/unittests/clangd/ClangdTests+0x1f97029)

0x602075a0 is located 0 bytes to the right of 16-byte region 
[0x60207590,0x602075a0)
allocated by thread T0 here:
#0 0x20984c0 in operator new(unsigned long) 
(/mnt/data/llvm-asan-build/tools/clang/tools/extra/unittests/clangd/ClangdTests+0x20984c0)
#1 0x209ec66 in allocate 
/usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/ext/new_allocator.h:111:27
#2 0x209ec66 in allocate 
/usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/bits/alloc_traits.h:436
#3 0x209ec66 in _M_allocate 
/usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/bits/stl_vector.h:296
#4 0x209ec66 in _M_range_initialize 
/usr/bin/../lib/gcc/x86_64-linux-gnu/8/../../../../include/c++/8/bits/stl_vector.h:1466
#5 0x209ec66 in _M_initialize_dispatch 

r358283 - [AST] Forbid copy/move of statements/types

2019-04-12 Thread Bruno Ricci via cfe-commits
Author: brunoricci
Date: Fri Apr 12 06:26:55 2019
New Revision: 358283

URL: http://llvm.org/viewvc/llvm-project?rev=358283=rev
Log:
[AST] Forbid copy/move of statements/types

Statements, expressions and types are not supposed to be copied/moved,
and trying to do so is only going to result in tears. Someone tripped
on this a few days ago on the mailing list. NFC.

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

Reviewed By: aaron.ballman


Modified:
cfe/trunk/include/clang/AST/Stmt.h
cfe/trunk/include/clang/AST/Type.h

Modified: cfe/trunk/include/clang/AST/Stmt.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Stmt.h?rev=358283=358282=358283=diff
==
--- cfe/trunk/include/clang/AST/Stmt.h (original)
+++ cfe/trunk/include/clang/AST/Stmt.h Fri Apr 12 06:26:55 2019
@@ -1042,6 +1042,11 @@ public:
 return static_cast(StmtBits.sClass);
   }
 
+  Stmt(const Stmt &) = delete;
+  Stmt(Stmt &&) = delete;
+  Stmt =(const Stmt &) = delete;
+  Stmt =(Stmt &&) = delete;
+
   const char *getStmtClassName() const;
 
   bool isOMPStructuredBlock() const { return StmtBits.IsOMPStructuredBlock; }

Modified: cfe/trunk/include/clang/AST/Type.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Type.h?rev=358283=358282=358283=diff
==
--- cfe/trunk/include/clang/AST/Type.h (original)
+++ cfe/trunk/include/clang/AST/Type.h Fri Apr 12 06:26:55 2019
@@ -1813,7 +1813,9 @@ public:
   friend class ASTWriter;
 
   Type(const Type &) = delete;
+  Type(Type &&) = delete;
   Type =(const Type &) = delete;
+  Type =(Type &&) = delete;
 
   TypeClass getTypeClass() const { return static_cast(TypeBits.TC); 
}
 


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


r356957 - [Sema] Don't check for array bounds when the types in the base expression are dependent

2019-03-25 Thread Bruno Ricci via cfe-commits
Author: brunoricci
Date: Mon Mar 25 14:37:10 2019
New Revision: 356957

URL: http://llvm.org/viewvc/llvm-project?rev=356957=rev
Log:
[Sema] Don't check for array bounds when the types in the base expression are 
dependent

Bail-out of CheckArrayAccess when the types of the base expression before
and after eventual casts are dependent. We will get another chance to check
for array bounds during instantiation. Fixes PR41087.

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

Reviewed By: efriedma


Modified:
cfe/trunk/lib/Sema/SemaChecking.cpp
cfe/trunk/test/SemaCXX/array-bounds.cpp

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=356957=356956=356957=diff
==
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Mon Mar 25 14:37:10 2019
@@ -12522,6 +12522,8 @@ void Sema::CheckArrayAccess(const Expr *
 return;
 
   const Type *BaseType = ArrayTy->getElementType().getTypePtr();
+  if (EffectiveType->isDependentType() || BaseType->isDependentType())
+return;
 
   Expr::EvalResult Result;
   if (!IndexExpr->EvaluateAsInt(Result, Context, Expr::SE_AllowSideEffects))

Modified: cfe/trunk/test/SemaCXX/array-bounds.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/array-bounds.cpp?rev=356957=356956=356957=diff
==
--- cfe/trunk/test/SemaCXX/array-bounds.cpp (original)
+++ cfe/trunk/test/SemaCXX/array-bounds.cpp Mon Mar 25 14:37:10 2019
@@ -296,3 +296,16 @@ namespace PR39746 {
   // We can still diagnose this.
   C () { return reinterpret_cast(xxx)[-1]; } // expected-warning 
{{array index -1 is before the beginning of the array}}
 }
+
+namespace PR41087 {
+  template  void foo() {
+Ty buffer[2]; // expected-note 3{{array 'buffer' declared here}}
+((char *)buffer)[2] = 'A'; // expected-warning 1{{array index 2 is past 
the end of the array (which contains 2 elements)}}
+((char *)buffer)[-1] = 'A'; // expected-warning 2{{array index -1 is 
before the beginning of the array}}
+  }
+
+  void f() {
+foo(); // expected-note 1{{in instantiation of function template 
specialization}}
+foo(); // expected-note 1{{in instantiation of function template 
specialization}}
+  };
+}


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


r356925 - [Sema][NFCI] Don't allocate storage for the various CorrectionCandidateCallback unless we are going to do some typo correction

2019-03-25 Thread Bruno Ricci via cfe-commits
Author: brunoricci
Date: Mon Mar 25 10:08:51 2019
New Revision: 356925

URL: http://llvm.org/viewvc/llvm-project?rev=356925=rev
Log:
[Sema][NFCI] Don't allocate storage for the various CorrectionCandidateCallback 
unless we are going to do some typo correction

The various CorrectionCandidateCallbacks are currently heap-allocated
unconditionally. This was needed because of delayed typo correction.
However these allocations represent currently 15.4% of all allocations
(number of allocations) when parsing all of Boost (!), mostly because
of ParseCastExpression, ParseStatementOrDeclarationAfterAttrtibutes
and isCXXDeclarationSpecifier. Note that all of these callback objects
are small. Let's not do this.

Instead initially allocate the callback on the stack, and only do a
heap allocation if we are going to do some typo correction. Do this by:

1. Adding a clone function to each callback, which will do a polymorphic
   clone of the callback. This clone function is required to be implemented
   by every callback (of which there is a fair amount). Make sure this is
   the case by making it pure virtual.

2. Use this clone function when we are going to try to correct a typo.

This additionally cut the time of -fsyntax-only on all of Boost by 0.5%
(not that much, but still something). No functional changes intended.

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

Reviewed By: rnk


Modified:
cfe/trunk/include/clang/Parse/Parser.h
cfe/trunk/include/clang/Sema/Sema.h
cfe/trunk/include/clang/Sema/TypoCorrection.h
cfe/trunk/lib/Parse/ParseDecl.cpp
cfe/trunk/lib/Parse/ParseExpr.cpp
cfe/trunk/lib/Parse/ParseExprCXX.cpp
cfe/trunk/lib/Parse/ParseStmt.cpp
cfe/trunk/lib/Parse/ParseTentative.cpp
cfe/trunk/lib/Parse/Parser.cpp
cfe/trunk/lib/Sema/SemaCXXScopeSpec.cpp
cfe/trunk/lib/Sema/SemaCodeComplete.cpp
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/lib/Sema/SemaDeclObjC.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/lib/Sema/SemaExprMember.cpp
cfe/trunk/lib/Sema/SemaExprObjC.cpp
cfe/trunk/lib/Sema/SemaInit.cpp
cfe/trunk/lib/Sema/SemaLambda.cpp
cfe/trunk/lib/Sema/SemaLookup.cpp
cfe/trunk/lib/Sema/SemaOpenMP.cpp
cfe/trunk/lib/Sema/SemaOverload.cpp
cfe/trunk/lib/Sema/SemaTemplate.cpp
cfe/trunk/lib/Sema/SemaTemplateVariadic.cpp
cfe/trunk/lib/Sema/SemaType.cpp

Modified: cfe/trunk/include/clang/Parse/Parser.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=356925=356924=356925=diff
==
--- cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/trunk/include/clang/Parse/Parser.h Mon Mar 25 10:08:51 2019
@@ -789,9 +789,8 @@ private:
 /// Annotation was successful.
 ANK_Success
   };
-  AnnotatedNameKind
-  TryAnnotateName(bool IsAddressOfOperand,
-  std::unique_ptr CCC = nullptr);
+  AnnotatedNameKind TryAnnotateName(bool IsAddressOfOperand,
+CorrectionCandidateCallback *CCC = 
nullptr);
 
   /// Push a tok::annot_cxxscope token onto the token stream.
   void AnnotateScopeToken(CXXScopeSpec , bool IsNewAnnotation);

Modified: cfe/trunk/include/clang/Sema/Sema.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Sema/Sema.h?rev=356925=356924=356925=diff
==
--- cfe/trunk/include/clang/Sema/Sema.h (original)
+++ cfe/trunk/include/clang/Sema/Sema.h Mon Mar 25 10:08:51 2019
@@ -1914,11 +1914,11 @@ public:
   ///expression.
   ///
   /// \param CCC The correction callback, if typo correction is desired.
-  NameClassification
-  ClassifyName(Scope *S, CXXScopeSpec , IdentifierInfo *,
-   SourceLocation NameLoc, const Token ,
-   bool IsAddressOfOperand,
-   std::unique_ptr CCC = nullptr);
+  NameClassification ClassifyName(Scope *S, CXXScopeSpec ,
+  IdentifierInfo *, SourceLocation 
NameLoc,
+  const Token ,
+  bool IsAddressOfOperand,
+  CorrectionCandidateCallback *CCC = nullptr);
 
   /// Describes the detailed kind of a template name. Used in diagnostics.
   enum class TemplateNameKindForDiagnostics {
@@ -3266,7 +3266,7 @@ private:
   makeTypoCorrectionConsumer(const DeclarationNameInfo ,
  Sema::LookupNameKind LookupKind, Scope *S,
  CXXScopeSpec *SS,
- std::unique_ptr CCC,
+ CorrectionCandidateCallback ,
  DeclContext *MemberContext, bool EnteringContext,
  const ObjCObjectPointerType *OPT,
  bool ErrorRecovery);
@@ -3350,7 +3350,7 @@ public:
   TypoCorrection 

r354728 - [NFC] Fix Wdocumentation warning in OMPToClause

2019-02-23 Thread Bruno Ricci via cfe-commits
Author: brunoricci
Date: Sat Feb 23 08:40:30 2019
New Revision: 354728

URL: http://llvm.org/viewvc/llvm-project?rev=354728=rev
Log:
[NFC] Fix Wdocumentation warning in OMPToClause


Modified:
cfe/trunk/include/clang/AST/OpenMPClause.h

Modified: cfe/trunk/include/clang/AST/OpenMPClause.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/OpenMPClause.h?rev=354728=354727=354728=diff
==
--- cfe/trunk/include/clang/AST/OpenMPClause.h (original)
+++ cfe/trunk/include/clang/AST/OpenMPClause.h Sat Feb 23 08:40:30 2019
@@ -4979,7 +4979,6 @@ class OMPToClause final : public OMPMapp
   /// \param MapperQualifierLoc C++ nested name specifier for the associated
   /// user-defined mapper.
   /// \param MapperIdInfo The identifier of associated user-defined mapper.
-  /// \param MapType Map type.
   /// \param Locs Locations needed to build a mappable clause. It includes 1)
   /// StartLoc: starting location of the clause (the clause keyword); 2)
   /// LParenLoc: location of '('; 3) EndLoc: ending location of the clause.


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


r354727 - [Sema][NFC] SequenceChecker: More tests in preparation for D57660

2019-02-23 Thread Bruno Ricci via cfe-commits
Author: brunoricci
Date: Sat Feb 23 08:25:00 2019
New Revision: 354727

URL: http://llvm.org/viewvc/llvm-project?rev=354727=rev
Log:
[Sema][NFC] SequenceChecker: More tests in preparation for D57660


Modified:
cfe/trunk/test/SemaCXX/warn-unsequenced.cpp

Modified: cfe/trunk/test/SemaCXX/warn-unsequenced.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-unsequenced.cpp?rev=354727=354726=354727=diff
==
--- cfe/trunk/test/SemaCXX/warn-unsequenced.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-unsequenced.cpp Sat Feb 23 08:25:00 2019
@@ -1,5 +1,7 @@
-// RUN: %clang_cc1 -fsyntax-only -verify=cxx11 -std=c++11 -Wno-unused 
-Wno-uninitialized -Wunsequenced %s
-// RUN: %clang_cc1 -fsyntax-only -verify=cxx17 -std=c++17 -Wno-unused 
-Wno-uninitialized -Wunsequenced %s
+// RUN: %clang_cc1 -fsyntax-only -verify=cxx11 -std=c++11 -Wno-unused 
-Wno-uninitialized \
+// RUN:-Wunsequenced -Wno-c++17-extensions -Wno-c++14-extensions %s
+// RUN: %clang_cc1 -fsyntax-only -verify=cxx17 -std=c++17 -Wno-unused 
-Wno-uninitialized \
+// RUN:-Wunsequenced -Wno-c++17-extensions -Wno-c++14-extensions %s
 
 int f(int, int = 0);
 
@@ -154,13 +156,11 @@ struct S1 {
   unsigned bf2 : 2;
   unsigned a;
   unsigned b;
-
+  static unsigned x;
   void member_f(S1 );
 };
 
 void S1::member_f(S1 ) {
-  int xs[10];
-
   ++a + ++a; // cxx11-warning {{multiple unsequenced modifications to 'a'}}
  // cxx17-warning@-1 {{multiple unsequenced modifications to 'a'}}
   a + ++a; // cxx11-warning {{unsequenced modification and access to 'a'}}
@@ -197,6 +197,25 @@ void S1::member_f(S1 ) {
   bf1 + ++s.bf1; // no-warning
   ++bf1 + ++s.bf2; // no-warning
   bf1 + ++s.bf2; // no-warning
+
+  struct Der : S1 {};
+  Der d;
+  Der _ref = d;
+  S1 _ref = d_ref;
+
+  ++s1_ref.a + ++d_ref.a; // no-warning TODO {{multiple unsequenced 
modifications to member 'a' of 'd'}}
+  ++s1_ref.a + d_ref.a; // no-warning TODO {{unsequenced modification and 
access to member 'a' of 'd'}}
+  ++s1_ref.a + ++d_ref.b; // no-warning
+  ++s1_ref.a + d_ref.b; // no-warning
+
+  ++x + ++x; // cxx11-warning {{multiple unsequenced modifications to 'x'}}
+ // cxx17-warning@-1 {{multiple unsequenced modifications to 'x'}}
+  ++x + x; // cxx11-warning {{unsequenced modification and access to 'x'}}
+   // cxx17-warning@-1 {{unsequenced modification and access to 'x'}}
+  ++s.x + x; // no-warning TODO {{unsequenced modification and access to 
static member 'x' of 'S1'}}
+  ++this->x + x; // cxx11-warning {{unsequenced modification and access to 
'x'}}
+ // cxx17-warning@-1 {{unsequenced modification and access to 
'x'}}
+  ++d_ref.x + ++S1::x; // no-warning TODO {{unsequenced modification and 
access to static member 'x' of 'S1'}}
 }
 
 struct S2 {
@@ -319,6 +338,119 @@ void reference_f() {
 }
 } // namespace references
 
+namespace std {
+  using size_t = decltype(sizeof(0));
+  template struct tuple_size;
+  template struct tuple_element { using type = int; };
+}
+namespace bindings {
+
+  struct A { int x, y; };
+  typedef int B[2];
+  struct C { template int get(); };
+  struct D : A {};
+
+} // namespace bindings
+template<> struct std::tuple_size { enum { value = 2 }; };
+namespace bindings {
+void testa() {
+  A a;
+  {
+auto [x, y] = a;
+++x + ++x; // cxx11-warning {{multiple unsequenced modifications to 'x'}}
+   // cxx17-warning@-1 {{multiple unsequenced modifications to 
'x'}}
+++x + x; // cxx11-warning {{unsequenced modification and access to 'x'}}
+ // cxx17-warning@-1 {{unsequenced modification and access to 'x'}}
+++x + ++y; // no-warning
+++x + y; // no-warning
+++x + ++a.x; // no-warning
+++x + a.x; // no-warning
+  }
+  {
+auto &[x, y] = a;
+++x + ++x; // cxx11-warning {{multiple unsequenced modifications to 'x'}}
+   // cxx17-warning@-1 {{multiple unsequenced modifications to 
'x'}}
+++x + x; // cxx11-warning {{unsequenced modification and access to 'x'}}
+ // cxx17-warning@-1 {{unsequenced modification and access to 'x'}}
+++x + ++y; // no-warning
+++x + y; // no-warning
+++x + ++a.x; // no-warning TODO
+++x + a.x; // no-warning TODO
+  }
+}
+void testb() {
+  B b;
+  {
+auto [x, y] = b;
+++x + ++x; // cxx11-warning {{multiple unsequenced modifications to 'x'}}
+   // cxx17-warning@-1 {{multiple unsequenced modifications to 
'x'}}
+++x + x; // cxx11-warning {{unsequenced modification and access to 'x'}}
+ // cxx17-warning@-1 {{unsequenced modification and access to 'x'}}
+++x + ++y; // no-warning
+++x + y; // no-warning
+++x + ++b[0]; // no-warning
+++x + b[0]; // no-warning
+  }
+  {
+auto &[x, y] = b;
+++x + ++x; // cxx11-warning {{multiple unsequenced modifications to 'x'}}
+   // cxx17-warning@-1 {{multiple unsequenced 

r354233 - [NFC] Add a llvm_unreachable to silence a warning in SubstObjCTypeArgsVisitor

2019-02-17 Thread Bruno Ricci via cfe-commits
Author: brunoricci
Date: Sun Feb 17 11:18:38 2019
New Revision: 354233

URL: http://llvm.org/viewvc/llvm-project?rev=354233=rev
Log:
[NFC] Add a llvm_unreachable to silence a warning in SubstObjCTypeArgsVisitor

All cases in the switch are covered. NFC.


Modified:
cfe/trunk/lib/AST/Type.cpp

Modified: cfe/trunk/lib/AST/Type.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Type.cpp?rev=354233=354232=354233=diff
==
--- cfe/trunk/lib/AST/Type.cpp (original)
+++ cfe/trunk/lib/AST/Type.cpp Sun Feb 17 11:18:38 2019
@@ -1184,6 +1184,7 @@ struct SubstObjCTypeArgsVisitor
   return Ctx.getObjCObjectPointerType(resultTy);
   }
 }
+llvm_unreachable("Unexpected ObjCSubstitutionContext!");
   }
 
   QualType VisitFunctionType(const FunctionType *funcType) {


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


r354232 - Recommit "[AST] Factor out the logic of the various Expr::Ignore*"

2019-02-17 Thread Bruno Ricci via cfe-commits
Author: brunoricci
Date: Sun Feb 17 10:50:51 2019
New Revision: 354232

URL: http://llvm.org/viewvc/llvm-project?rev=354232=rev
Log:
Recommit "[AST] Factor out the logic of the various Expr::Ignore*"

(Originally commited in r354215 and reverted in r354216 because of a
 missed failing clang-tidy test (fix in r354228))

Now that the implementation of all of the Expr::Ignore* is in Expr.cpp
we can try to remove some duplication. Do this by separating the logic
of the Expr::Ignore* from the iterative loop.

This is NFC, except for one change: IgnoreParenImpCasts now skips,
among other things, everything that IgnoreImpCasts skips. This means
FullExpr are now skipped by IgnoreParenImpCasts. This was likely an
oversight when FullExpr was added to the nodes skipped by IgnoreImpCasts.

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

Reviewed By: aaron.ballman (with comments from void and rnk)


Modified:
cfe/trunk/include/clang/AST/Expr.h
cfe/trunk/lib/AST/Expr.cpp

Modified: cfe/trunk/include/clang/AST/Expr.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=354232=354231=354232=diff
==
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Sun Feb 17 10:50:51 2019
@@ -794,7 +794,7 @@ public:
   /// IgnoreParens() + IgnoreImpCasts() until reaching a fixed point. However
   /// this is currently not the case. Instead IgnoreParenImpCasts() skips:
   /// * What IgnoreParens() skips
-  /// * ImplicitCastExpr
+  /// * What IgnoreImpCasts() skips
   /// * MaterializeTemporaryExpr
   /// * SubstNonTypeTemplateParmExpr
   Expr *IgnoreParenImpCasts() LLVM_READONLY;

Modified: cfe/trunk/lib/AST/Expr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=354232=354231=354232=diff
==
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Sun Feb 17 10:50:51 2019
@@ -2556,185 +2556,173 @@ QualType Expr::findBoundMemberType(const
   return QualType();
 }
 
-Expr *Expr::IgnoreImpCasts() {
-  Expr *E = this;
-  while (true) {
-if (auto *ICE = dyn_cast(E))
-  E = ICE->getSubExpr();
-else if (auto *FE = dyn_cast(E))
-  E = FE->getSubExpr();
-else
-  break;
-  }
+static Expr *IgnoreImpCastsSingleStep(Expr *E) {
+  if (auto *ICE = dyn_cast(E))
+return ICE->getSubExpr();
+
+  if (auto *FE = dyn_cast(E))
+return FE->getSubExpr();
+
   return E;
 }
 
-Expr *Expr::IgnoreImplicit() {
-  Expr *E = this;
-  Expr *LastE = nullptr;
-  while (E != LastE) {
-LastE = E;
+static Expr *IgnoreImpCastsExtraSingleStep(Expr *E) {
+  // FIXME: Skip MaterializeTemporaryExpr and SubstNonTypeTemplateParmExpr in
+  // addition to what IgnoreImpCasts() skips to account for the current
+  // behaviour of IgnoreParenImpCasts().
+  Expr *SubE = IgnoreImpCastsSingleStep(E);
+  if (SubE != E)
+return SubE;
 
-if (auto *ICE = dyn_cast(E))
-  E = ICE->getSubExpr();
+  if (auto *MTE = dyn_cast(E))
+return MTE->GetTemporaryExpr();
 
-if (auto *FE = dyn_cast(E))
-  E = FE->getSubExpr();
+  if (auto *NTTP = dyn_cast(E))
+return NTTP->getReplacement();
 
-if (auto *MTE = dyn_cast(E))
-  E = MTE->GetTemporaryExpr();
+  return E;
+}
+
+static Expr *IgnoreCastsSingleStep(Expr *E) {
+  if (auto *CE = dyn_cast(E))
+return CE->getSubExpr();
+
+  if (auto *FE = dyn_cast(E))
+return FE->getSubExpr();
+
+  if (auto *MTE = dyn_cast(E))
+return MTE->GetTemporaryExpr();
+
+  if (auto *NTTP = dyn_cast(E))
+return NTTP->getReplacement();
 
-if (auto *BTE = dyn_cast(E))
-  E = BTE->getSubExpr();
-  }
   return E;
 }
 
-Expr *Expr::IgnoreParens() {
-  Expr *E = this;
-  while (true) {
-if (auto *PE = dyn_cast(E)) {
-  E = PE->getSubExpr();
-  continue;
-}
-if (auto *UO = dyn_cast(E)) {
-  if (UO->getOpcode() == UO_Extension) {
-E = UO->getSubExpr();
-continue;
-  }
-}
-if (auto *GSE = dyn_cast(E)) {
-  if (!GSE->isResultDependent()) {
-E = GSE->getResultExpr();
-continue;
-  }
-}
-if (auto *CE = dyn_cast(E)) {
-  if (!CE->isConditionDependent()) {
-E = CE->getChosenSubExpr();
-continue;
-  }
-}
-if (auto *CE = dyn_cast(E)) {
-  E = CE->getSubExpr();
-  continue;
-}
-return E;
-  }
+static Expr *IgnoreLValueCastsSingleStep(Expr *E) {
+  // Skip what IgnoreCastsSingleStep skips, except that only
+  // lvalue-to-rvalue casts are skipped.
+  if (auto *CE = dyn_cast(E))
+if (CE->getCastKind() != CK_LValueToRValue)
+  return E;
+
+  return IgnoreCastsSingleStep(E);
+}
+
+static Expr *IgnoreBaseCastsSingleStep(Expr *E) {
+  if (auto *CE = dyn_cast(E))
+if (CE->getCastKind() == CK_DerivedToBase ||
+CE->getCastKind() == CK_UncheckedDerivedToBase ||
+CE->getCastKind() == 

[clang-tools-extra] r354228 - [clang-tidy][NFCI] DanglingHandleCheck: Remove a superflous IgnoreParenImpCasts

2019-02-17 Thread Bruno Ricci via cfe-commits
Author: brunoricci
Date: Sun Feb 17 10:21:54 2019
New Revision: 354228

URL: http://llvm.org/viewvc/llvm-project?rev=354228=rev
Log:
[clang-tidy][NFCI] DanglingHandleCheck: Remove a superflous IgnoreParenImpCasts

ExprWithCleanups is currently not skipped by IgnoreParenImpCasts, but is skipped
by IgnoreImpCasts. In view of fixing this inconsistency in D57267, remove the
IgnoreParenImpCasts between the ReturnStmt and the ExprWithCleanups which
is not needed since ExprWithCleanups is always created as a direct child of
ReturnStmt (by inspection of each ReturnStmt::Create in Sema/SemaStmt.cpp).

NFC intended.


Modified:
clang-tools-extra/trunk/clang-tidy/bugprone/DanglingHandleCheck.cpp

Modified: clang-tools-extra/trunk/clang-tidy/bugprone/DanglingHandleCheck.cpp
URL: 
http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/bugprone/DanglingHandleCheck.cpp?rev=354228=354227=354228=diff
==
--- clang-tools-extra/trunk/clang-tidy/bugprone/DanglingHandleCheck.cpp 
(original)
+++ clang-tools-extra/trunk/clang-tidy/bugprone/DanglingHandleCheck.cpp Sun Feb 
17 10:21:54 2019
@@ -163,9 +163,8 @@ void DanglingHandleCheck::registerMatche
 
   // Return a temporary.
   Finder->addMatcher(
-  returnStmt(
-  has(ignoringParenImpCasts(exprWithCleanups(has(ignoringParenImpCasts(
-  handleFrom(IsAHandle, handleFromTemporaryValue(IsAHandle
+  returnStmt(has(exprWithCleanups(has(ignoringParenImpCasts(handleFrom(
+ IsAHandle, handleFromTemporaryValue(IsAHandle)))
   .bind("bad_stmt"),
   this);
 }


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


r354216 - Revert "[AST] Factor out the logic of the various Expr::Ignore*"

2019-02-17 Thread Bruno Ricci via cfe-commits
Author: brunoricci
Date: Sun Feb 17 05:47:29 2019
New Revision: 354216

URL: http://llvm.org/viewvc/llvm-project?rev=354216=rev
Log:
Revert "[AST] Factor out the logic of the various Expr::Ignore*"

This breaks some clang-tidy checks. For some reason they were
not included in check-clang ?


Modified:
cfe/trunk/include/clang/AST/Expr.h
cfe/trunk/lib/AST/Expr.cpp

Modified: cfe/trunk/include/clang/AST/Expr.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=354216=354215=354216=diff
==
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Sun Feb 17 05:47:29 2019
@@ -794,7 +794,7 @@ public:
   /// IgnoreParens() + IgnoreImpCasts() until reaching a fixed point. However
   /// this is currently not the case. Instead IgnoreParenImpCasts() skips:
   /// * What IgnoreParens() skips
-  /// * What IgnoreImpCasts() skips
+  /// * ImplicitCastExpr
   /// * MaterializeTemporaryExpr
   /// * SubstNonTypeTemplateParmExpr
   Expr *IgnoreParenImpCasts() LLVM_READONLY;

Modified: cfe/trunk/lib/AST/Expr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=354216=354215=354216=diff
==
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Sun Feb 17 05:47:29 2019
@@ -2556,173 +2556,185 @@ QualType Expr::findBoundMemberType(const
   return QualType();
 }
 
-static Expr *IgnoreImpCastsSingleStep(Expr *E) {
-  if (auto *ICE = dyn_cast(E))
-return ICE->getSubExpr();
-
-  if (auto *FE = dyn_cast(E))
-return FE->getSubExpr();
-
-  return E;
-}
-
-static Expr *IgnoreImpCastsExtraSingleStep(Expr *E) {
-  // FIXME: Skip MaterializeTemporaryExpr and SubstNonTypeTemplateParmExpr in
-  // addition to what IgnoreImpCasts() skips to account for the current
-  // behaviour of IgnoreParenImpCasts().
-  Expr *SubE = IgnoreImpCastsSingleStep(E);
-  if (SubE != E)
-return SubE;
-
-  if (auto *MTE = dyn_cast(E))
-return MTE->GetTemporaryExpr();
-
-  if (auto *NTTP = dyn_cast(E))
-return NTTP->getReplacement();
-
-  return E;
-}
-
-static Expr *IgnoreCastsSingleStep(Expr *E) {
-  if (auto *CE = dyn_cast(E))
-return CE->getSubExpr();
-
-  if (auto *FE = dyn_cast(E))
-return FE->getSubExpr();
-
-  if (auto *MTE = dyn_cast(E))
-return MTE->GetTemporaryExpr();
-
-  if (auto *NTTP = dyn_cast(E))
-return NTTP->getReplacement();
-
+Expr *Expr::IgnoreImpCasts() {
+  Expr *E = this;
+  while (true) {
+if (auto *ICE = dyn_cast(E))
+  E = ICE->getSubExpr();
+else if (auto *FE = dyn_cast(E))
+  E = FE->getSubExpr();
+else
+  break;
+  }
   return E;
 }
 
-static Expr *IgnoreLValueCastsSingleStep(Expr *E) {
-  // Skip what IgnoreCastsSingleStep skips, except that only
-  // lvalue-to-rvalue casts are skipped.
-  if (auto *CE = dyn_cast(E))
-if (CE->getCastKind() != CK_LValueToRValue)
-  return E;
-
-  return IgnoreCastsSingleStep(E);
-}
-
-static Expr *IgnoreBaseCastsSingleStep(Expr *E) {
-  if (auto *CE = dyn_cast(E))
-if (CE->getCastKind() == CK_DerivedToBase ||
-CE->getCastKind() == CK_UncheckedDerivedToBase ||
-CE->getCastKind() == CK_NoOp)
-  return CE->getSubExpr();
-
-  return E;
-}
+Expr *Expr::IgnoreImplicit() {
+  Expr *E = this;
+  Expr *LastE = nullptr;
+  while (E != LastE) {
+LastE = E;
 
-static Expr *IgnoreImplicitSingleStep(Expr *E) {
-  Expr *SubE = IgnoreImpCastsSingleStep(E);
-  if (SubE != E)
-return SubE;
+if (auto *ICE = dyn_cast(E))
+  E = ICE->getSubExpr();
 
-  if (auto *MTE = dyn_cast(E))
-return MTE->GetTemporaryExpr();
+if (auto *FE = dyn_cast(E))
+  E = FE->getSubExpr();
 
-  if (auto *BTE = dyn_cast(E))
-return BTE->getSubExpr();
+if (auto *MTE = dyn_cast(E))
+  E = MTE->GetTemporaryExpr();
 
+if (auto *BTE = dyn_cast(E))
+  E = BTE->getSubExpr();
+  }
   return E;
 }
 
-static Expr *IgnoreParensSingleStep(Expr *E) {
-  if (auto *PE = dyn_cast(E))
-return PE->getSubExpr();
-
-  if (auto *UO = dyn_cast(E)) {
-if (UO->getOpcode() == UO_Extension)
-  return UO->getSubExpr();
-  }
-
-  else if (auto *GSE = dyn_cast(E)) {
-if (!GSE->isResultDependent())
-  return GSE->getResultExpr();
-  }
-
-  else if (auto *CE = dyn_cast(E)) {
-if (!CE->isConditionDependent())
-  return CE->getChosenSubExpr();
+Expr *Expr::IgnoreParens() {
+  Expr *E = this;
+  while (true) {
+if (auto *PE = dyn_cast(E)) {
+  E = PE->getSubExpr();
+  continue;
+}
+if (auto *UO = dyn_cast(E)) {
+  if (UO->getOpcode() == UO_Extension) {
+E = UO->getSubExpr();
+continue;
+  }
+}
+if (auto *GSE = dyn_cast(E)) {
+  if (!GSE->isResultDependent()) {
+E = GSE->getResultExpr();
+continue;
+  }
+}
+if (auto *CE = dyn_cast(E)) {
+  if 

r354215 - [AST] Factor out the logic of the various Expr::Ignore*

2019-02-17 Thread Bruno Ricci via cfe-commits
Author: brunoricci
Date: Sun Feb 17 05:32:39 2019
New Revision: 354215

URL: http://llvm.org/viewvc/llvm-project?rev=354215=rev
Log:
[AST] Factor out the logic of the various Expr::Ignore*

Now that the implementation of all of the Expr::Ignore* is in Expr.cpp
we can try to remove some duplication. Do this by separating the logic of
the Expr::Ignore* from the iterative loop.

This is NFC, except for one change: IgnoreParenImpCasts now skips, among
other things, everything that IgnoreImpCasts skips. This means FullExpr
are now skipped by IgnoreParenImpCasts. This was likely an oversight when
FullExpr was added to the nodes skipped by IgnoreImpCasts.

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

Reviewed By: aaron.ballman (with comments from void and rnk)


Modified:
cfe/trunk/include/clang/AST/Expr.h
cfe/trunk/lib/AST/Expr.cpp

Modified: cfe/trunk/include/clang/AST/Expr.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=354215=354214=354215=diff
==
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Sun Feb 17 05:32:39 2019
@@ -794,7 +794,7 @@ public:
   /// IgnoreParens() + IgnoreImpCasts() until reaching a fixed point. However
   /// this is currently not the case. Instead IgnoreParenImpCasts() skips:
   /// * What IgnoreParens() skips
-  /// * ImplicitCastExpr
+  /// * What IgnoreImpCasts() skips
   /// * MaterializeTemporaryExpr
   /// * SubstNonTypeTemplateParmExpr
   Expr *IgnoreParenImpCasts() LLVM_READONLY;

Modified: cfe/trunk/lib/AST/Expr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Expr.cpp?rev=354215=354214=354215=diff
==
--- cfe/trunk/lib/AST/Expr.cpp (original)
+++ cfe/trunk/lib/AST/Expr.cpp Sun Feb 17 05:32:39 2019
@@ -2556,185 +2556,173 @@ QualType Expr::findBoundMemberType(const
   return QualType();
 }
 
-Expr *Expr::IgnoreImpCasts() {
-  Expr *E = this;
-  while (true) {
-if (auto *ICE = dyn_cast(E))
-  E = ICE->getSubExpr();
-else if (auto *FE = dyn_cast(E))
-  E = FE->getSubExpr();
-else
-  break;
-  }
+static Expr *IgnoreImpCastsSingleStep(Expr *E) {
+  if (auto *ICE = dyn_cast(E))
+return ICE->getSubExpr();
+
+  if (auto *FE = dyn_cast(E))
+return FE->getSubExpr();
+
   return E;
 }
 
-Expr *Expr::IgnoreImplicit() {
-  Expr *E = this;
-  Expr *LastE = nullptr;
-  while (E != LastE) {
-LastE = E;
+static Expr *IgnoreImpCastsExtraSingleStep(Expr *E) {
+  // FIXME: Skip MaterializeTemporaryExpr and SubstNonTypeTemplateParmExpr in
+  // addition to what IgnoreImpCasts() skips to account for the current
+  // behaviour of IgnoreParenImpCasts().
+  Expr *SubE = IgnoreImpCastsSingleStep(E);
+  if (SubE != E)
+return SubE;
 
-if (auto *ICE = dyn_cast(E))
-  E = ICE->getSubExpr();
+  if (auto *MTE = dyn_cast(E))
+return MTE->GetTemporaryExpr();
 
-if (auto *FE = dyn_cast(E))
-  E = FE->getSubExpr();
+  if (auto *NTTP = dyn_cast(E))
+return NTTP->getReplacement();
 
-if (auto *MTE = dyn_cast(E))
-  E = MTE->GetTemporaryExpr();
+  return E;
+}
+
+static Expr *IgnoreCastsSingleStep(Expr *E) {
+  if (auto *CE = dyn_cast(E))
+return CE->getSubExpr();
+
+  if (auto *FE = dyn_cast(E))
+return FE->getSubExpr();
+
+  if (auto *MTE = dyn_cast(E))
+return MTE->GetTemporaryExpr();
+
+  if (auto *NTTP = dyn_cast(E))
+return NTTP->getReplacement();
 
-if (auto *BTE = dyn_cast(E))
-  E = BTE->getSubExpr();
-  }
   return E;
 }
 
-Expr *Expr::IgnoreParens() {
-  Expr *E = this;
-  while (true) {
-if (auto *PE = dyn_cast(E)) {
-  E = PE->getSubExpr();
-  continue;
-}
-if (auto *UO = dyn_cast(E)) {
-  if (UO->getOpcode() == UO_Extension) {
-E = UO->getSubExpr();
-continue;
-  }
-}
-if (auto *GSE = dyn_cast(E)) {
-  if (!GSE->isResultDependent()) {
-E = GSE->getResultExpr();
-continue;
-  }
-}
-if (auto *CE = dyn_cast(E)) {
-  if (!CE->isConditionDependent()) {
-E = CE->getChosenSubExpr();
-continue;
-  }
-}
-if (auto *CE = dyn_cast(E)) {
-  E = CE->getSubExpr();
-  continue;
-}
-return E;
-  }
+static Expr *IgnoreLValueCastsSingleStep(Expr *E) {
+  // Skip what IgnoreCastsSingleStep skips, except that only
+  // lvalue-to-rvalue casts are skipped.
+  if (auto *CE = dyn_cast(E))
+if (CE->getCastKind() != CK_LValueToRValue)
+  return E;
+
+  return IgnoreCastsSingleStep(E);
+}
+
+static Expr *IgnoreBaseCastsSingleStep(Expr *E) {
+  if (auto *CE = dyn_cast(E))
+if (CE->getCastKind() == CK_DerivedToBase ||
+CE->getCastKind() == CK_UncheckedDerivedToBase ||
+CE->getCastKind() == CK_NoOp)
+  return CE->getSubExpr();
+
+  return E;
 }
 
-/// IgnoreParenCasts - Ignore parentheses and casts.  Strip off any 

r354151 - [Sema][NFC] SequenceChecker: Add tests for references/members, and prepare for the C++17 tests

2019-02-15 Thread Bruno Ricci via cfe-commits
Author: brunoricci
Date: Fri Feb 15 10:12:58 2019
New Revision: 354151

URL: http://llvm.org/viewvc/llvm-project?rev=354151=rev
Log:
[Sema][NFC] SequenceChecker: Add tests for references/members, and prepare for 
the C++17 tests

Add some tests for unsequenced operations with members and references.
For now most of it is unhandled but it shows what work needs to be done.

Also merge the tests for the C++17 sequencing rules in warn-unsequenced.cpp
since we want to make sure that the appropriate warnings are still present
in C++17 without duplicating the whole content of warn-unsequenced.cpp.


Removed:
cfe/trunk/test/SemaCXX/warn-unsequenced-cxx17.cpp
Modified:
cfe/trunk/test/SemaCXX/warn-unsequenced.cpp

Removed: cfe/trunk/test/SemaCXX/warn-unsequenced-cxx17.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-unsequenced-cxx17.cpp?rev=354150=auto
==
--- cfe/trunk/test/SemaCXX/warn-unsequenced-cxx17.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-unsequenced-cxx17.cpp (removed)
@@ -1,8 +0,0 @@
-// RUN: %clang_cc1 -fsyntax-only -verify -std=c++17 -Wno-unused %s
-
-void test() {
-  int xs[10];
-  int *p = xs;
-  // expected-no-diagnostics
-  p[(long long unsigned)(p = 0)]; // ok
-}

Modified: cfe/trunk/test/SemaCXX/warn-unsequenced.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-unsequenced.cpp?rev=354151=354150=354151=diff
==
--- cfe/trunk/test/SemaCXX/warn-unsequenced.cpp (original)
+++ cfe/trunk/test/SemaCXX/warn-unsequenced.cpp Fri Feb 15 10:12:58 2019
@@ -1,4 +1,5 @@
-// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 -Wno-unused %s
+// RUN: %clang_cc1 -fsyntax-only -verify=cxx11 -std=c++11 -Wno-unused 
-Wno-uninitialized -Wunsequenced %s
+// RUN: %clang_cc1 -fsyntax-only -verify=cxx17 -std=c++17 -Wno-unused 
-Wno-uninitialized -Wunsequenced %s
 
 int f(int, int = 0);
 
@@ -10,81 +11,107 @@ struct S {
   int n;
 };
 
+// TODO: Implement the C++17 sequencing rules.
 void test() {
   int a;
   int xs[10];
   ++a = 0; // ok
-  a + ++a; // expected-warning {{unsequenced modification and access to 'a'}}
+  a + ++a; // cxx11-warning {{unsequenced modification and access to 'a'}}
+   // cxx17-warning@-1 {{unsequenced modification and access to 'a'}}
   a = ++a; // ok
-  a + a++; // expected-warning {{unsequenced modification and access to 'a'}}
-  a = a++; // expected-warning {{multiple unsequenced modifications to 'a'}}
+  a + a++; // cxx11-warning {{unsequenced modification and access to 'a'}}
+   // cxx17-warning@-1 {{unsequenced modification and access to 'a'}}
+  a = a++; // cxx11-warning {{multiple unsequenced modifications to 'a'}}
+   // TODO cxx17-warning@-1 {{multiple unsequenced modifications to 
'a'}}
   ++ ++a; // ok
   (a++, a++); // ok
-  ++a + ++a; // expected-warning {{multiple unsequenced modifications to 'a'}}
-  a++ + a++; // expected-warning {{multiple unsequenced modifications}}
+  ++a + ++a; // cxx11-warning {{multiple unsequenced modifications to 'a'}}
+ // cxx17-warning@-1 {{multiple unsequenced modifications to 'a'}}
+  a++ + a++; // cxx11-warning {{multiple unsequenced modifications to 'a'}}
+ // cxx17-warning@-1 {{multiple unsequenced modifications to 'a'}}
   (a++, a) = 0; // ok, increment is sequenced before value computation of LHS
   a = xs[++a]; // ok
-  a = xs[a++]; // expected-warning {{multiple unsequenced modifications}}
-  (a ? xs[0] : xs[1]) = ++a; // expected-warning {{unsequenced modification 
and access}}
+  a = xs[a++]; // cxx11-warning {{multiple unsequenced modifications to 'a'}}
+   // TODO cxx17-warning@-1 {{multiple unsequenced modifications 
to 'a'}}
+  (a ? xs[0] : xs[1]) = ++a; // cxx11-warning {{unsequenced modification and 
access to 'a'}}
+ // TODO cxx17-warning@-1 {{unsequenced 
modification and access to 'a'}}
   a = (++a, ++a); // ok
   a = (a++, ++a); // ok
-  a = (a++, a++); // expected-warning {{multiple unsequenced modifications}}
+  a = (a++, a++); // cxx11-warning {{multiple unsequenced modifications to 
'a'}}
+  // TODO cxx17-warning@-1 {{multiple unsequenced 
modifications to 'a'}}
   f(a, a); // ok
-  f(a = 0, a); // expected-warning {{unsequenced modification and access}}
-  f(a, a += 0); // expected-warning {{unsequenced modification and access}}
-  f(a = 0, a = 0); // expected-warning {{multiple unsequenced modifications}}
+  f(a = 0, a); // cxx11-warning {{unsequenced modification and access to 'a'}}
+   // cxx17-warning@-1 {{unsequenced modification and access to 
'a'}}
+  f(a, a += 0); // cxx11-warning {{unsequenced modification and access to 'a'}}
+// cxx17-warning@-1 {{unsequenced modification and access to 
'a'}}
+  f(a = 0, a = 0); // cxx11-warning {{multiple unsequenced modifications to 
'a'}}
+   

r354035 - [Sema] Fix a regression introduced in "[AST][Sema] Remove CallExpr::setNumArgs"

2019-02-14 Thread Bruno Ricci via cfe-commits
Author: brunoricci
Date: Thu Feb 14 07:43:17 2019
New Revision: 354035

URL: http://llvm.org/viewvc/llvm-project?rev=354035=rev
Log:
[Sema] Fix a regression introduced in "[AST][Sema] Remove CallExpr::setNumArgs"

D54902 removed CallExpr::setNumArgs in preparation of tail-allocating the
arguments of CallExpr. It did this by allocating storage for
max(number of arguments, number of parameters in the prototype). The
temporarily nulled arguments however causes issues in BuildResolvedCallExpr
when typo correction is done just after the creation of the call expression.

This was unfortunately missed by the tests /:

To fix this, delay setting the number of arguments to
max(number of arguments, number of parameters in the prototype) until we are
ready for it. It would be nice to have this encapsulated in CallExpr but this
is the best I can come up with under the constraint that we cannot add
anything the CallExpr.

Fixes PR40286.

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

Reviewed By: aaron.ballman


Modified:
cfe/trunk/include/clang/AST/Expr.h
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/test/Sema/typo-correction.c

Modified: cfe/trunk/include/clang/AST/Expr.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=354035=354034=354035=diff
==
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Thu Feb 14 07:43:17 2019
@@ -2610,6 +2610,11 @@ public:
 NumArgs = NewNumArgs;
   }
 
+  /// Bluntly set a new number of arguments without doing any checks 
whatsoever.
+  /// Only used during construction of a CallExpr in a few places in Sema.
+  /// FIXME: Find a way to remove it.
+  void setNumArgsUnsafe(unsigned NewNumArgs) { NumArgs = NewNumArgs; }
+
   typedef ExprIterator arg_iterator;
   typedef ConstExprIterator const_arg_iterator;
   typedef llvm::iterator_range arg_range;

Modified: cfe/trunk/lib/Sema/SemaExpr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=354035=354034=354035=diff
==
--- cfe/trunk/lib/Sema/SemaExpr.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExpr.cpp Thu Feb 14 07:43:17 2019
@@ -5793,18 +5793,36 @@ ExprResult Sema::BuildResolvedCallExpr(E
   }
 
   if (!getLangOpts().CPlusPlus) {
+// Forget about the nulled arguments since typo correction
+// do not handle them well.
+TheCall->shrinkNumArgs(Args.size());
 // C cannot always handle TypoExpr nodes in builtin calls and direct
 // function calls as their argument checking don't necessarily handle
 // dependent types properly, so make sure any TypoExprs have been
 // dealt with.
 ExprResult Result = CorrectDelayedTyposInExpr(TheCall);
 if (!Result.isUsable()) return ExprError();
+CallExpr *TheOldCall = TheCall;
 TheCall = dyn_cast(Result.get());
+bool CorrectedTypos = TheCall != TheOldCall;
 if (!TheCall) return Result;
-// TheCall at this point has max(Args.size(), NumParams) arguments,
-// with extra arguments nulled. We don't want to introduce nulled
-// arguments in Args and so we only take the first Args.size() arguments.
-Args = llvm::makeArrayRef(TheCall->getArgs(), Args.size());
+Args = llvm::makeArrayRef(TheCall->getArgs(), TheCall->getNumArgs());
+
+// A new call expression node was created if some typos were corrected.
+// However it may not have been constructed with enough storage. In this
+// case, rebuild the node with enough storage. The waste of space is
+// immaterial since this only happens when some typos were corrected.
+if (CorrectedTypos && Args.size() < NumParams) {
+  if (Config)
+TheCall = CUDAKernelCallExpr::Create(
+Context, Fn, cast(Config), Args, ResultTy, VK_RValue,
+RParenLoc, NumParams);
+  else
+TheCall = CallExpr::Create(Context, Fn, Args, ResultTy, VK_RValue,
+   RParenLoc, NumParams, UsesADL);
+}
+// We can now handle the nulled arguments for the default arguments.
+TheCall->setNumArgsUnsafe(std::max(Args.size(), NumParams));
   }
 
   // Bail out early if calling a builtin with custom type checking.

Modified: cfe/trunk/test/Sema/typo-correction.c
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/typo-correction.c?rev=354035=354034=354035=diff
==
--- cfe/trunk/test/Sema/typo-correction.c (original)
+++ cfe/trunk/test/Sema/typo-correction.c Thu Feb 14 07:43:17 2019
@@ -100,3 +100,18 @@ void rdar38642201_caller() {
   structVar1.fieldName1.member1, //expected-error{{use of undeclared 
identifier 'structVar1'}}
   structVar2.fieldName2.member2); //expected-error{{use of undeclared 
identifier 'structVar2'}}
 }
+
+void PR40286_g(int x, int y);
+void PR40286_h(int x, int 

r353006 - [AST] Update the comments of the various Expr::Ignore* + Related cleanups

2019-02-03 Thread Bruno Ricci via cfe-commits
Author: brunoricci
Date: Sun Feb  3 11:50:56 2019
New Revision: 353006

URL: http://llvm.org/viewvc/llvm-project?rev=353006=rev
Log:
[AST] Update the comments of the various Expr::Ignore* + Related cleanups

The description of what the various Expr::Ignore* do has drifted from the
actual implementation.

Inspection reveals that IgnoreParenImpCasts() is not equivalent to doing
IgnoreParens() + IgnoreImpCasts() until reaching a fixed point, but
IgnoreParenCasts() is equivalent to doing IgnoreParens() + IgnoreCasts()
until reaching a fixed point. There is also a fair amount of duplication
in the various Expr::Ignore* functions which increase the chance of further
future inconsistencies. In preparation for the next patch which will factor
out the implementation of the various Expr::Ignore*, do the following cleanups:

Remove Stmt::IgnoreImplicit, in favor of Expr::IgnoreImplicit. IgnoreImplicit
is the only function among all of the Expr::Ignore* which is available in Stmt.
There are only a few users of Stmt::IgnoreImplicit. They can just use instead
Expr::IgnoreImplicit like they have to do for the other Ignore*.

Move Expr::IgnoreImpCasts() from Expr.h to Expr.cpp. This made no difference
in the run-time with my usual benchmark (-fsyntax-only on all of Boost).

While we are at it, make IgnoreParenNoopCasts take a const reference to the
ASTContext for const correctness.

Update the comments to match what the Expr::Ignore* are actually doing.
I am not sure that listing exactly what each Expr::Ignore* do is optimal,
but it certainly looks better than the current state which is in my opinion
between misleading and just plain wrong.

The whole patch is NFC (if you count removing Stmt::IgnoreImplicit as NFC).

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

Reviewed By: aaron.ballman


Modified:
cfe/trunk/include/clang/AST/Expr.h
cfe/trunk/include/clang/AST/Stmt.h
cfe/trunk/lib/ARCMigrate/TransRetainReleaseDealloc.cpp
cfe/trunk/lib/ARCMigrate/TransformActions.cpp
cfe/trunk/lib/ARCMigrate/Transforms.cpp
cfe/trunk/lib/AST/Expr.cpp
cfe/trunk/lib/AST/Stmt.cpp
cfe/trunk/lib/Analysis/ReachableCode.cpp
cfe/trunk/lib/Tooling/ASTDiff/ASTDiff.cpp

Modified: cfe/trunk/include/clang/AST/Expr.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=353006=353005=353006=diff
==
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Sun Feb  3 11:50:56 2019
@@ -746,67 +746,110 @@ public:
   /// member expression.
   static QualType findBoundMemberType(const Expr *expr);
 
-  /// IgnoreImpCasts - Skip past any implicit casts which might
-  /// surround this expression.  Only skips ImplicitCastExprs.
+  /// Skip past any implicit casts which might surround this expression until
+  /// reaching a fixed point. Skips:
+  /// * ImplicitCastExpr
+  /// * FullExpr
   Expr *IgnoreImpCasts() LLVM_READONLY;
-
-  /// IgnoreImplicit - Skip past any implicit AST nodes which might
-  /// surround this expression.
-  Expr *IgnoreImplicit() LLVM_READONLY {
-return cast(Stmt::IgnoreImplicit());
+  const Expr *IgnoreImpCasts() const {
+return const_cast(this)->IgnoreImpCasts();
   }
 
-  const Expr *IgnoreImplicit() const LLVM_READONLY {
-return const_cast(this)->IgnoreImplicit();
+  /// Skip past any casts which might surround this expression until reaching
+  /// a fixed point. Skips:
+  /// * CastExpr
+  /// * FullExpr
+  /// * MaterializeTemporaryExpr
+  /// * SubstNonTypeTemplateParmExpr
+  Expr *IgnoreCasts() LLVM_READONLY;
+  const Expr *IgnoreCasts() const {
+return const_cast(this)->IgnoreCasts();
   }
 
-  /// IgnoreParens - Ignore parentheses.  If this Expr is a ParenExpr, return
-  ///  its subexpression.  If that subexpression is also a ParenExpr,
-  ///  then this method recursively returns its subexpression, and so forth.
-  ///  Otherwise, the method returns the current Expr.
+  /// Skip past any implicit AST nodes which might surround this expression
+  /// until reaching a fixed point. Skips:
+  /// * What IgnoreImpCasts() skips
+  /// * MaterializeTemporaryExpr
+  /// * CXXBindTemporaryExpr
+  Expr *IgnoreImplicit() LLVM_READONLY;
+  const Expr *IgnoreImplicit() const {
+return const_cast(this)->IgnoreImplicit();
+  }
+
+  /// Skip past any parentheses which might surround this expression until
+  /// reaching a fixed point. Skips:
+  /// * ParenExpr
+  /// * UnaryOperator if `UO_Extension`
+  /// * GenericSelectionExpr if `!isResultDependent()`
+  /// * ChooseExpr if `!isConditionDependent()`
+  /// * ConstantExpr
   Expr *IgnoreParens() LLVM_READONLY;
+  const Expr *IgnoreParens() const {
+return const_cast(this)->IgnoreParens();
+  }
 
-  /// IgnoreParenCasts - Ignore parentheses and casts.  Strip off any ParenExpr
-  /// or CastExprs, returning their operand.
-  Expr *IgnoreParenCasts() LLVM_READONLY;
-
-  /// Ignore casts.  

r353003 - [ASTDump] Add a flag indicating whether a CXXThisExpr is implicit

2019-02-03 Thread Bruno Ricci via cfe-commits
Author: brunoricci
Date: Sun Feb  3 10:20:27 2019
New Revision: 353003

URL: http://llvm.org/viewvc/llvm-project?rev=353003=rev
Log:
[ASTDump] Add a flag indicating whether a CXXThisExpr is implicit

There is currently no way to distinguish implicit from explicit
CXXThisExpr in the AST dump output.

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

Reviewed By: steveire


Modified:
cfe/trunk/lib/AST/TextNodeDumper.cpp
cfe/trunk/test/AST/ast-dump-expr.cpp
cfe/trunk/test/AST/dump.cpp
cfe/trunk/test/AST/float16.cpp

Modified: cfe/trunk/lib/AST/TextNodeDumper.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/TextNodeDumper.cpp?rev=353003=353002=353003=diff
==
--- cfe/trunk/lib/AST/TextNodeDumper.cpp (original)
+++ cfe/trunk/lib/AST/TextNodeDumper.cpp Sun Feb  3 10:20:27 2019
@@ -854,6 +854,8 @@ void TextNodeDumper::VisitCXXBoolLiteral
 }
 
 void TextNodeDumper::VisitCXXThisExpr(const CXXThisExpr *Node) {
+  if (Node->isImplicit())
+OS << " implicit";
   OS << " this";
 }
 

Modified: cfe/trunk/test/AST/ast-dump-expr.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/AST/ast-dump-expr.cpp?rev=353003=353002=353003=diff
==
--- cfe/trunk/test/AST/ast-dump-expr.cpp (original)
+++ cfe/trunk/test/AST/ast-dump-expr.cpp Sun Feb  3 10:20:27 2019
@@ -255,7 +255,7 @@ void PrimaryExpressions(Ts... a) {
   // CHECK-NEXT: FieldDecl 0x{{[^ ]*}}  col:8 implicit 'V *'
   // CHECK-NEXT: CXXMethodDecl
   // CHECK-NEXT: CompoundStmt
-  // CHECK-NEXT: CXXThisExpr 0x{{[^ ]*}}  'V *' this
+  // CHECK-NEXT: CXXThisExpr 0x{{[^ ]*}}  'V *' implicit this
 
   [*this]{};
   // CHECK: LambdaExpr 0x{{[^ ]*}} 
@@ -272,7 +272,7 @@ void PrimaryExpressions(Ts... a) {
   // CHECK-NEXT: CompoundStmt
   // CHECK-NEXT: ParenListExpr 0x{{[^ ]*}}  'NULL TYPE'
   // CHECK-NEXT: UnaryOperator 0x{{[^ ]*}}  '' 
prefix '*' cannot overflow
-  // CHECK-NEXT: CXXThisExpr 0x{{[^ ]*}}  'V *' this
+  // CHECK-NEXT: CXXThisExpr 0x{{[^ ]*}}  'V *' implicit this
 }
   };
 

Modified: cfe/trunk/test/AST/dump.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/AST/dump.cpp?rev=353003=353002=353003=diff
==
--- cfe/trunk/test/AST/dump.cpp (original)
+++ cfe/trunk/test/AST/dump.cpp Sun Feb  3 10:20:27 2019
@@ -56,7 +56,7 @@ struct S {
 // CHECK-NEXT: |   | `-DeclRefExpr {{.+}}  'int' lvalue 
OMPCapturedExpr {{.+}} 'a' 'int &'
 // CHECK-NEXT: |   |-OMPSharedClause {{.+}} 
 // CHECK-NEXT: |   | `-MemberExpr {{.+}}  'int' lvalue ->b
-// CHECK-NEXT: |   |   `-CXXThisExpr {{.+}}  'S *' this
+// CHECK-NEXT: |   |   `-CXXThisExpr {{.+}}  'S *' implicit this
 // CHECK-NEXT: |   |-OMPScheduleClause {{.+}} 
 // CHECK-NEXT: |   | `-ImplicitCastExpr {{.+}}  'int' 

 // CHECK-NEXT: |   |   `-DeclRefExpr {{.+}}  'int' lvalue 
OMPCapturedExpr {{.+}} '.capture_expr.' 'int'

Modified: cfe/trunk/test/AST/float16.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/AST/float16.cpp?rev=353003=353002=353003=diff
==
--- cfe/trunk/test/AST/float16.cpp (original)
+++ cfe/trunk/test/AST/float16.cpp Sun Feb  3 10:20:27 2019
@@ -132,7 +132,7 @@ public:
 //CHECK-NEXT: | | `-BinaryOperator {{.*}} '_Float16' '+'
 //CHECK-NEXT: | |   |-ImplicitCastExpr {{.*}} '_Float16' 
 //CHECK-NEXT: | |   | `-MemberExpr {{.*}} '_Float16' lvalue ->f1c 0x{{.*}}
-//CHECK-NEXT: | |   |   `-CXXThisExpr {{.*}} 'C1 *' this
+//CHECK-NEXT: | |   |   `-CXXThisExpr {{.*}} 'C1 *' implicit this
 //CHECK-NEXT: | |   `-ImplicitCastExpr {{.*}} '_Float16' 
 //CHECK-NEXT: | | `-DeclRefExpr {{.*}} '_Float16' lvalue ParmVar 
0x{{.*}} 'arg' '_Float16'
 //CHECK-NEXT: | |-CXXMethodDecl {{.*}} used func2c '_Float16 (_Float16)' static


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


r352486 - Re-commit "[AST] Introduce GenericSelectionExpr::Association"

2019-01-29 Thread Bruno Ricci via cfe-commits
Author: brunoricci
Date: Tue Jan 29 04:57:11 2019
New Revision: 352486

URL: http://llvm.org/viewvc/llvm-project?rev=352486=rev
Log:
Re-commit "[AST] Introduce GenericSelectionExpr::Association"

This time with a fix to make gcc 4.8 happy.


Modified:
cfe/trunk/include/clang/AST/Expr.h
cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
cfe/trunk/include/clang/AST/StmtDataCollectors.td
cfe/trunk/lib/AST/ASTDumper.cpp
cfe/trunk/lib/AST/StmtPrinter.cpp
cfe/trunk/lib/AST/StmtProfile.cpp
cfe/trunk/lib/Sema/SemaExprObjC.cpp
cfe/trunk/lib/Sema/SemaPseudoObject.cpp
cfe/trunk/lib/Sema/TreeTransform.h

Modified: cfe/trunk/include/clang/AST/Expr.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=352486=352485=352486=diff
==
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Tue Jan 29 04:57:11 2019
@@ -28,6 +28,8 @@
 #include "clang/Basic/TypeTraits.h"
 #include "llvm/ADT/APFloat.h"
 #include "llvm/ADT/APSInt.h"
+#include "llvm/ADT/iterator.h"
+#include "llvm/ADT/iterator_range.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/AtomicOrdering.h"
@@ -5052,6 +5054,86 @@ class GenericSelectionExpr final
 return getNumAssocs();
   }
 
+  template  class AssociationIteratorTy;
+  /// Bundle together an association expression and its TypeSourceInfo.
+  /// The Const template parameter is for the const and non-const versions
+  /// of AssociationTy.
+  template  class AssociationTy {
+friend class GenericSelectionExpr;
+template  friend class AssociationIteratorTy;
+using ExprPtrTy =
+typename std::conditional::type;
+using TSIPtrTy = typename std::conditional::type;
+ExprPtrTy E;
+TSIPtrTy TSI;
+bool Selected;
+AssociationTy(ExprPtrTy E, TSIPtrTy TSI, bool Selected)
+: E(E), TSI(TSI), Selected(Selected) {}
+
+  public:
+ExprPtrTy getAssociationExpr() const { return E; }
+TSIPtrTy getTypeSourceInfo() const { return TSI; }
+QualType getType() const { return TSI ? TSI->getType() : QualType(); }
+bool isSelected() const { return Selected; }
+AssociationTy *operator->() { return this; }
+const AssociationTy *operator->() const { return this; }
+  }; // class AssociationTy
+
+  /// Iterator over const and non-const Association objects. The Association
+  /// objects are created on the fly when the iterator is dereferenced.
+  /// This abstract over how exactly the association expressions and the
+  /// corresponding TypeSourceInfo * are stored.
+  template 
+  class AssociationIteratorTy
+  : public llvm::iterator_facade_base<
+AssociationIteratorTy, std::input_iterator_tag,
+AssociationTy, std::ptrdiff_t, AssociationTy,
+AssociationTy> {
+friend class GenericSelectionExpr;
+// FIXME: This iterator could conceptually be a random access iterator, and
+// it would be nice if we could strengthen the iterator category someday.
+// However this iterator does not satisfy two requirements of forward
+// iterators:
+// a) reference = T& or reference = const T&
+// b) If It1 and It2 are both dereferenceable, then It1 == It2 if and only
+//if *It1 and *It2 are bound to the same objects.
+// An alternative design approach was discussed during review;
+// store an Association object inside the iterator, and return a reference
+// to it when dereferenced. This idea was discarded beacuse of nasty
+// lifetime issues:
+//AssociationIterator It = ...;
+//const Association  = *It++; // Oops, Assoc is dangling.
+using BaseTy = typename AssociationIteratorTy::iterator_facade_base;
+using StmtPtrPtrTy =
+typename std::conditional::type;
+using TSIPtrPtrTy =
+typename std::conditional::type;
+StmtPtrPtrTy E; // = nullptr; FIXME: Once support for gcc 4.8 is dropped.
+TSIPtrPtrTy TSI; // Kept in sync with E.
+unsigned Offset = 0, SelectedOffset = 0;
+AssociationIteratorTy(StmtPtrPtrTy E, TSIPtrPtrTy TSI, unsigned Offset,
+  unsigned SelectedOffset)
+: E(E), TSI(TSI), Offset(Offset), SelectedOffset(SelectedOffset) {}
+
+  public:
+AssociationIteratorTy() : E(nullptr), TSI(nullptr) {}
+typename BaseTy::reference operator*() const {
+  return AssociationTy(cast(*E), *TSI,
+  Offset == SelectedOffset);
+}
+typename BaseTy::pointer operator->() const { return **this; }
+using BaseTy::operator++;
+AssociationIteratorTy ++() {
+  ++E;
+  ++TSI;
+  ++Offset;
+  return *this;
+}
+bool operator==(AssociationIteratorTy Other) const { return E == Other.E; }
+  }; // class AssociationIterator
+
   /// Build a non-result-dependent generic selection expression.
   GenericSelectionExpr(const ASTContext , 

r352403 - Revert "[AST] Introduce GenericSelectionExpr::Association"

2019-01-28 Thread Bruno Ricci via cfe-commits
Author: brunoricci
Date: Mon Jan 28 10:40:26 2019
New Revision: 352403

URL: http://llvm.org/viewvc/llvm-project?rev=352403=rev
Log:
Revert "[AST] Introduce GenericSelectionExpr::Association"

This breaks GCC 4.8.4. Reported by email by Hans Wennborg.


Modified:
cfe/trunk/include/clang/AST/Expr.h
cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
cfe/trunk/include/clang/AST/StmtDataCollectors.td
cfe/trunk/lib/AST/ASTDumper.cpp
cfe/trunk/lib/AST/StmtPrinter.cpp
cfe/trunk/lib/AST/StmtProfile.cpp
cfe/trunk/lib/Sema/SemaExprObjC.cpp
cfe/trunk/lib/Sema/SemaPseudoObject.cpp
cfe/trunk/lib/Sema/TreeTransform.h

Modified: cfe/trunk/include/clang/AST/Expr.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=352403=352402=352403=diff
==
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Mon Jan 28 10:40:26 2019
@@ -28,8 +28,6 @@
 #include "clang/Basic/TypeTraits.h"
 #include "llvm/ADT/APFloat.h"
 #include "llvm/ADT/APSInt.h"
-#include "llvm/ADT/iterator.h"
-#include "llvm/ADT/iterator_range.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/AtomicOrdering.h"
@@ -5054,86 +5052,6 @@ class GenericSelectionExpr final
 return getNumAssocs();
   }
 
-  template  class AssociationIteratorTy;
-  /// Bundle together an association expression and its TypeSourceInfo.
-  /// The Const template parameter is for the const and non-const versions
-  /// of AssociationTy.
-  template  class AssociationTy {
-friend class GenericSelectionExpr;
-template  friend class AssociationIteratorTy;
-using ExprPtrTy =
-typename std::conditional::type;
-using TSIPtrTy = typename std::conditional::type;
-ExprPtrTy E;
-TSIPtrTy TSI;
-bool Selected;
-AssociationTy(ExprPtrTy E, TSIPtrTy TSI, bool Selected)
-: E(E), TSI(TSI), Selected(Selected) {}
-
-  public:
-ExprPtrTy getAssociationExpr() const { return E; }
-TSIPtrTy getTypeSourceInfo() const { return TSI; }
-QualType getType() const { return TSI ? TSI->getType() : QualType(); }
-bool isSelected() const { return Selected; }
-AssociationTy *operator->() { return this; }
-const AssociationTy *operator->() const { return this; }
-  }; // class AssociationTy
-
-  /// Iterator over const and non-const Association objects. The Association
-  /// objects are created on the fly when the iterator is dereferenced.
-  /// This abstract over how exactly the association expressions and the
-  /// corresponding TypeSourceInfo * are stored.
-  template 
-  class AssociationIteratorTy
-  : public llvm::iterator_facade_base<
-AssociationIteratorTy, std::input_iterator_tag,
-AssociationTy, std::ptrdiff_t, AssociationTy,
-AssociationTy> {
-friend class GenericSelectionExpr;
-// FIXME: This iterator could conceptually be a random access iterator, and
-// it would be nice if we could strengthen the iterator category someday.
-// However this iterator does not satisfy two requirements of forward
-// iterators:
-// a) reference = T& or reference = const T&
-// b) If It1 and It2 are both dereferenceable, then It1 == It2 if and only
-//if *It1 and *It2 are bound to the same objects.
-// An alternative design approach was discussed during review;
-// store an Association object inside the iterator, and return a reference
-// to it when dereferenced. This idea was discarded beacuse of nasty
-// lifetime issues:
-//AssociationIterator It = ...;
-//const Association  = *It++; // Oops, Assoc is dangling.
-using BaseTy = typename AssociationIteratorTy::iterator_facade_base;
-using StmtPtrPtrTy =
-typename std::conditional::type;
-using TSIPtrPtrTy =
-typename std::conditional::type;
-StmtPtrPtrTy E = nullptr;
-TSIPtrPtrTy TSI = nullptr; // Kept in sync with E.
-unsigned Offset = 0, SelectedOffset = 0;
-AssociationIteratorTy(StmtPtrPtrTy E, TSIPtrPtrTy TSI, unsigned Offset,
-  unsigned SelectedOffset)
-: E(E), TSI(TSI), Offset(Offset), SelectedOffset(SelectedOffset) {}
-
-  public:
-AssociationIteratorTy() = default;
-typename BaseTy::reference operator*() const {
-  return AssociationTy(cast(*E), *TSI,
-  Offset == SelectedOffset);
-}
-typename BaseTy::pointer operator->() const { return **this; }
-using BaseTy::operator++;
-AssociationIteratorTy ++() {
-  ++E;
-  ++TSI;
-  ++Offset;
-  return *this;
-}
-bool operator==(AssociationIteratorTy Other) const { return E == Other.E; }
-  }; // class AssociationIterator
-
   /// Build a non-result-dependent generic selection expression.
   GenericSelectionExpr(const ASTContext , SourceLocation GenericLoc,
  

r352369 - [AST] Introduce GenericSelectionExpr::Association

2019-01-28 Thread Bruno Ricci via cfe-commits
Author: brunoricci
Date: Mon Jan 28 06:18:11 2019
New Revision: 352369

URL: http://llvm.org/viewvc/llvm-project?rev=352369=rev
Log:
[AST] Introduce GenericSelectionExpr::Association

Introduce a new class GenericSelectionExpr::Association which bundle together
an association expression and its TypeSourceInfo.

An iterator GenericSelectionExpr::AssociationIterator is additionally added to
make it possible to iterate over ranges of Associations. This iterator is a
kind of proxy iterator which abstract over how exactly the expressions and the
TypeSourceInfos are stored.

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

Reviewed By: aaron.ballman

Reviewers: aaron.ballman, steveire, dblaikie, mclow.lists


Modified:
cfe/trunk/include/clang/AST/Expr.h
cfe/trunk/include/clang/AST/RecursiveASTVisitor.h
cfe/trunk/include/clang/AST/StmtDataCollectors.td
cfe/trunk/lib/AST/ASTDumper.cpp
cfe/trunk/lib/AST/StmtPrinter.cpp
cfe/trunk/lib/AST/StmtProfile.cpp
cfe/trunk/lib/Sema/SemaExprObjC.cpp
cfe/trunk/lib/Sema/SemaPseudoObject.cpp
cfe/trunk/lib/Sema/TreeTransform.h

Modified: cfe/trunk/include/clang/AST/Expr.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=352369=352368=352369=diff
==
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Mon Jan 28 06:18:11 2019
@@ -28,6 +28,8 @@
 #include "clang/Basic/TypeTraits.h"
 #include "llvm/ADT/APFloat.h"
 #include "llvm/ADT/APSInt.h"
+#include "llvm/ADT/iterator.h"
+#include "llvm/ADT/iterator_range.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
 #include "llvm/Support/AtomicOrdering.h"
@@ -5052,6 +5054,86 @@ class GenericSelectionExpr final
 return getNumAssocs();
   }
 
+  template  class AssociationIteratorTy;
+  /// Bundle together an association expression and its TypeSourceInfo.
+  /// The Const template parameter is for the const and non-const versions
+  /// of AssociationTy.
+  template  class AssociationTy {
+friend class GenericSelectionExpr;
+template  friend class AssociationIteratorTy;
+using ExprPtrTy =
+typename std::conditional::type;
+using TSIPtrTy = typename std::conditional::type;
+ExprPtrTy E;
+TSIPtrTy TSI;
+bool Selected;
+AssociationTy(ExprPtrTy E, TSIPtrTy TSI, bool Selected)
+: E(E), TSI(TSI), Selected(Selected) {}
+
+  public:
+ExprPtrTy getAssociationExpr() const { return E; }
+TSIPtrTy getTypeSourceInfo() const { return TSI; }
+QualType getType() const { return TSI ? TSI->getType() : QualType(); }
+bool isSelected() const { return Selected; }
+AssociationTy *operator->() { return this; }
+const AssociationTy *operator->() const { return this; }
+  }; // class AssociationTy
+
+  /// Iterator over const and non-const Association objects. The Association
+  /// objects are created on the fly when the iterator is dereferenced.
+  /// This abstract over how exactly the association expressions and the
+  /// corresponding TypeSourceInfo * are stored.
+  template 
+  class AssociationIteratorTy
+  : public llvm::iterator_facade_base<
+AssociationIteratorTy, std::input_iterator_tag,
+AssociationTy, std::ptrdiff_t, AssociationTy,
+AssociationTy> {
+friend class GenericSelectionExpr;
+// FIXME: This iterator could conceptually be a random access iterator, and
+// it would be nice if we could strengthen the iterator category someday.
+// However this iterator does not satisfy two requirements of forward
+// iterators:
+// a) reference = T& or reference = const T&
+// b) If It1 and It2 are both dereferenceable, then It1 == It2 if and only
+//if *It1 and *It2 are bound to the same objects.
+// An alternative design approach was discussed during review;
+// store an Association object inside the iterator, and return a reference
+// to it when dereferenced. This idea was discarded beacuse of nasty
+// lifetime issues:
+//AssociationIterator It = ...;
+//const Association  = *It++; // Oops, Assoc is dangling.
+using BaseTy = typename AssociationIteratorTy::iterator_facade_base;
+using StmtPtrPtrTy =
+typename std::conditional::type;
+using TSIPtrPtrTy =
+typename std::conditional::type;
+StmtPtrPtrTy E = nullptr;
+TSIPtrPtrTy TSI = nullptr; // Kept in sync with E.
+unsigned Offset = 0, SelectedOffset = 0;
+AssociationIteratorTy(StmtPtrPtrTy E, TSIPtrPtrTy TSI, unsigned Offset,
+  unsigned SelectedOffset)
+: E(E), TSI(TSI), Offset(Offset), SelectedOffset(SelectedOffset) {}
+
+  public:
+AssociationIteratorTy() = default;
+typename BaseTy::reference operator*() const {
+  return AssociationTy(cast(*E), *TSI,
+  Offset == SelectedOffset);
+}
+typename 

r352276 - [AST] Pack GenericSelectionExpr

2019-01-26 Thread Bruno Ricci via cfe-commits
Author: brunoricci
Date: Sat Jan 26 06:15:10 2019
New Revision: 352276

URL: http://llvm.org/viewvc/llvm-project?rev=352276=rev
Log:
[AST] Pack GenericSelectionExpr

Store the controlling expression, the association expressions and the
corresponding TypeSourceInfos as trailing objects.

Additionally use the bit-fields of Stmt to store one SourceLocation,
saving one additional pointer. This saves 3 pointers in total per
GenericSelectionExpr.

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

Reviewed By: aaron.ballman

Reviewers: aaron.ballman, steveire


Modified:
cfe/trunk/include/clang/AST/Expr.h
cfe/trunk/include/clang/AST/Stmt.h
cfe/trunk/lib/AST/Expr.cpp
cfe/trunk/lib/Sema/SemaExpr.cpp
cfe/trunk/lib/Sema/SemaExprObjC.cpp
cfe/trunk/lib/Sema/SemaOverload.cpp
cfe/trunk/lib/Sema/SemaPseudoObject.cpp
cfe/trunk/lib/Serialization/ASTReaderStmt.cpp
cfe/trunk/lib/Serialization/ASTWriterStmt.cpp

Modified: cfe/trunk/include/clang/AST/Expr.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=352276=352275=352276=diff
==
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Sat Jan 26 06:15:10 2019
@@ -5013,9 +5013,13 @@ public:
 /// which names a dependent type in its association list is result-dependent,
 /// which means that the choice of result expression is dependent.
 /// Result-dependent generic associations are both type- and value-dependent.
-class GenericSelectionExpr : public Expr {
+class GenericSelectionExpr final
+: public Expr,
+  private llvm::TrailingObjects {
   friend class ASTStmtReader;
   friend class ASTStmtWriter;
+  friend TrailingObjects;
 
   /// The number of association expressions and the index of the result
   /// expression in the case where the generic selection expression is not
@@ -5028,13 +5032,27 @@ class GenericSelectionExpr : public Expr
 AssocExprStartIndex = 1
   };
 
-  /// The location of the "_Generic", "default" and of the right parenthesis.
-  SourceLocation GenericLoc, DefaultLoc, RParenLoc;
+  /// The location of the "default" and of the right parenthesis.
+  SourceLocation DefaultLoc, RParenLoc;
 
-  TypeSourceInfo **AssocTypes;
-  Stmt **SubExprs;
+  // GenericSelectionExpr is followed by several trailing objects.
+  // They are (in order):
+  //
+  // * A single Stmt * for the controlling expression.
+  // * An array of getNumAssocs() Stmt * for the association expressions.
+  // * An array of getNumAssocs() TypeSourceInfo *, one for each of the
+  //   association expressions.
+  unsigned numTrailingObjects(OverloadToken) const {
+// Add one to account for the controlling expression; the remainder
+// are the associated expressions.
+return 1 + getNumAssocs();
+  }
 
-public:
+  unsigned numTrailingObjects(OverloadToken) const {
+return getNumAssocs();
+  }
+
+  /// Build a non-result-dependent generic selection expression.
   GenericSelectionExpr(const ASTContext , SourceLocation GenericLoc,
Expr *ControllingExpr,
ArrayRef AssocTypes,
@@ -5043,7 +5061,7 @@ public:
bool ContainsUnexpandedParameterPack,
unsigned ResultIndex);
 
-  /// This constructor is used in the result-dependent case.
+  /// Build a result-dependent generic selection expression.
   GenericSelectionExpr(const ASTContext , SourceLocation GenericLoc,
Expr *ControllingExpr,
ArrayRef AssocTypes,
@@ -5051,8 +5069,28 @@ public:
SourceLocation RParenLoc,
bool ContainsUnexpandedParameterPack);
 
-  explicit GenericSelectionExpr(EmptyShell Empty)
-  : Expr(GenericSelectionExprClass, Empty) {}
+  /// Build an empty generic selection expression for deserialization.
+  explicit GenericSelectionExpr(EmptyShell Empty, unsigned NumAssocs);
+
+public:
+  /// Create a non-result-dependent generic selection expression.
+  static GenericSelectionExpr *
+  Create(const ASTContext , SourceLocation GenericLoc,
+ Expr *ControllingExpr, ArrayRef AssocTypes,
+ ArrayRef AssocExprs, SourceLocation DefaultLoc,
+ SourceLocation RParenLoc, bool ContainsUnexpandedParameterPack,
+ unsigned ResultIndex);
+
+  /// Create a result-dependent generic selection expression.
+  static GenericSelectionExpr *
+  Create(const ASTContext , SourceLocation GenericLoc,
+ Expr *ControllingExpr, ArrayRef AssocTypes,
+ ArrayRef AssocExprs, SourceLocation DefaultLoc,
+ SourceLocation RParenLoc, bool ContainsUnexpandedParameterPack);
+
+  /// Create an empty generic selection expression for deserialization.
+  static GenericSelectionExpr *CreateEmpty(const ASTContext ,
+   unsigned NumAssocs);
 
   /// The number of association expressions.
   

r352275 - [AST][NFC] Various cleanups to GenericSelectionExpr

2019-01-26 Thread Bruno Ricci via cfe-commits
Author: brunoricci
Date: Sat Jan 26 05:58:15 2019
New Revision: 352275

URL: http://llvm.org/viewvc/llvm-project?rev=352275=rev
Log:
[AST][NFC] Various cleanups to GenericSelectionExpr

Various cleanups to GenericSelectionExpr factored out of D57104. In particular:

1. Move the friend declaration to the top.
2. Introduce a constant ResultDependentIndex instead of the magic "-1".
3. clang-format
4. Group the member function together so that they can be removed as one block
   by D57106.

NFC.

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

Reviewed By: aaron.ballman


Modified:
cfe/trunk/include/clang/AST/Expr.h
cfe/trunk/lib/AST/Expr.cpp
cfe/trunk/lib/Serialization/ASTReaderStmt.cpp
cfe/trunk/lib/Serialization/ASTWriterStmt.cpp

Modified: cfe/trunk/include/clang/AST/Expr.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=352275=352274=352275=diff
==
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Sat Jan 26 05:58:15 2019
@@ -5014,98 +5014,118 @@ public:
 /// which means that the choice of result expression is dependent.
 /// Result-dependent generic associations are both type- and value-dependent.
 class GenericSelectionExpr : public Expr {
-  enum { CONTROLLING, END_EXPR };
-  TypeSourceInfo **AssocTypes;
-  Stmt **SubExprs;
+  friend class ASTStmtReader;
+  friend class ASTStmtWriter;
+
+  /// The number of association expressions and the index of the result
+  /// expression in the case where the generic selection expression is not
+  /// result-dependent. The result index is equal to ResultDependentIndex
+  /// if and only if the generic selection expression is result-dependent.
   unsigned NumAssocs, ResultIndex;
+  enum : unsigned {
+ResultDependentIndex = std::numeric_limits::max(),
+ControllingIndex = 0,
+AssocExprStartIndex = 1
+  };
+
+  /// The location of the "_Generic", "default" and of the right parenthesis.
   SourceLocation GenericLoc, DefaultLoc, RParenLoc;
 
+  TypeSourceInfo **AssocTypes;
+  Stmt **SubExprs;
+
 public:
-  GenericSelectionExpr(const ASTContext ,
-   SourceLocation GenericLoc, Expr *ControllingExpr,
-   ArrayRef AssocTypes,
-   ArrayRef AssocExprs,
-   SourceLocation DefaultLoc, SourceLocation RParenLoc,
+  GenericSelectionExpr(const ASTContext , SourceLocation GenericLoc,
+   Expr *ControllingExpr,
+   ArrayRef AssocTypes,
+   ArrayRef AssocExprs, SourceLocation DefaultLoc,
+   SourceLocation RParenLoc,
bool ContainsUnexpandedParameterPack,
unsigned ResultIndex);
 
   /// This constructor is used in the result-dependent case.
-  GenericSelectionExpr(const ASTContext ,
-   SourceLocation GenericLoc, Expr *ControllingExpr,
-   ArrayRef AssocTypes,
-   ArrayRef AssocExprs,
-   SourceLocation DefaultLoc, SourceLocation RParenLoc,
+  GenericSelectionExpr(const ASTContext , SourceLocation GenericLoc,
+   Expr *ControllingExpr,
+   ArrayRef AssocTypes,
+   ArrayRef AssocExprs, SourceLocation DefaultLoc,
+   SourceLocation RParenLoc,
bool ContainsUnexpandedParameterPack);
 
   explicit GenericSelectionExpr(EmptyShell Empty)
-: Expr(GenericSelectionExprClass, Empty) { }
+  : Expr(GenericSelectionExprClass, Empty) {}
 
+  /// The number of association expressions.
   unsigned getNumAssocs() const { return NumAssocs; }
 
-  SourceLocation getGenericLoc() const { return GenericLoc; }
-  SourceLocation getDefaultLoc() const { return DefaultLoc; }
-  SourceLocation getRParenLoc() const { return RParenLoc; }
+  /// The zero-based index of the result expression's generic association in
+  /// the generic selection's association list.  Defined only if the
+  /// generic selection is not result-dependent.
+  unsigned getResultIndex() const {
+assert(!isResultDependent() &&
+   "Generic selection is result-dependent but getResultIndex called!");
+return ResultIndex;
+  }
 
-  const Expr *getAssocExpr(unsigned i) const {
-return cast(SubExprs[END_EXPR+i]);
+  /// Whether this generic selection is result-dependent.
+  bool isResultDependent() const { return ResultIndex == ResultDependentIndex; 
}
+
+  /// Return the controlling expression of this generic selection expression.
+  Expr *getControllingExpr() { return cast(SubExprs[ControllingIndex]); }
+  const Expr *getControllingExpr() const {
+return cast(SubExprs[ControllingIndex]);
   }
-  Expr *getAssocExpr(unsigned i) { return cast(SubExprs[END_EXPR+i]); }
-  ArrayRef getAssocExprs() const {
-return NumAssocs
-   ? 

r352047 - [Sema] Don't crash when recovering from a misspelled pseudo destructor call to an incomplete type.

2019-01-24 Thread Bruno Ricci via cfe-commits
Author: brunoricci
Date: Thu Jan 24 05:52:47 2019
New Revision: 352047

URL: http://llvm.org/viewvc/llvm-project?rev=352047=rev
Log:
[Sema] Don't crash when recovering from a misspelled pseudo destructor call to 
an incomplete type.

When attempting to correct a misspelled pseudo destructor call as in:

struct Foo;
void foo(Foo *p) {
  p.~Foo();
}

a call is made in canRecoverDotPseudoDestructorCallsOnPointerObjects
to LookupDestructor without checking that the record has a definition.

This causes an assertion later in LookupSpecialMember which assumes that
the record has a definition.

Patch By Roman Zhikharevich!

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

Reviewed By: riccibruno


Modified:
cfe/trunk/lib/Sema/SemaExprCXX.cpp
cfe/trunk/test/SemaCXX/incomplete-call.cpp

Modified: cfe/trunk/lib/Sema/SemaExprCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExprCXX.cpp?rev=352047=352046=352047=diff
==
--- cfe/trunk/lib/Sema/SemaExprCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaExprCXX.cpp Thu Jan 24 05:52:47 2019
@@ -6854,8 +6854,9 @@ canRecoverDotPseudoDestructorCallsOnPoin
QualType DestructedType) {
   // If this is a record type, check if its destructor is callable.
   if (auto *RD = DestructedType->getAsCXXRecordDecl()) {
-if (CXXDestructorDecl *D = SemaRef.LookupDestructor(RD))
-  return SemaRef.CanUseDecl(D, /*TreatUnavailableAsInvalid=*/false);
+if (RD->hasDefinition())
+  if (CXXDestructorDecl *D = SemaRef.LookupDestructor(RD))
+return SemaRef.CanUseDecl(D, /*TreatUnavailableAsInvalid=*/false);
 return false;
   }
 

Modified: cfe/trunk/test/SemaCXX/incomplete-call.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/incomplete-call.cpp?rev=352047=352046=352047=diff
==
--- cfe/trunk/test/SemaCXX/incomplete-call.cpp (original)
+++ cfe/trunk/test/SemaCXX/incomplete-call.cpp Thu Jan 24 05:52:47 2019
@@ -48,6 +48,10 @@ void test_incomplete_object_call(C& c) {
   c(); // expected-error{{incomplete type in call to object of type}}
 }
 
+void test_incomplete_object_dtor(C *p) {
+  p.~C(); // expected-error{{member reference type 'C *' is a pointer; did you 
mean to use '->'?}}
+}
+
 namespace pr18542 {
   struct X {
 int count;


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


r350741 - [AST] Move back BasePathSize to the bit-fields of CastExpr

2019-01-09 Thread Bruno Ricci via cfe-commits
Author: brunoricci
Date: Wed Jan  9 08:41:33 2019
New Revision: 350741

URL: http://llvm.org/viewvc/llvm-project?rev=350741=rev
Log:
[AST] Move back BasePathSize to the bit-fields of CastExpr

The number of trailing CXXBaseSpecifiers in CastExpr was moved from
CastExprBitfields to a trailing object in r338489 (D50050). At this time these
bit-fields classes were only 32 bits wide. However later r345459 widened these
bit-field classes to 64 bits.

The reason for this change was that on 64 bit archs alignment requirements
caused 4 bytes of padding after the Stmt sub-object in nearly all expression
classes. Reusing this padding yielded an >10% reduction in the size used by all
statement/expressions when parsing all of Boost (on a 64 bit arch). This
increased the size of statement/expressions for 32 bits archs, but this can be
mitigated by moving more data to the bit-fields of Stmt (and moreover most
people now care about 64 bits archs as a host).

Therefore move back the number of CXXBaseSpecifiers in CastExpr to the
bit-fields of Stmt. This in effect mostly revert r338489 while keeping the
added test.

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

Reviewed By: lebedev.ri

Reviewers: lebedev.ri, rjmccall


Modified:
cfe/trunk/include/clang/AST/Expr.h
cfe/trunk/include/clang/AST/ExprCXX.h
cfe/trunk/include/clang/AST/ExprObjC.h
cfe/trunk/include/clang/AST/Stmt.h
cfe/trunk/lib/AST/Expr.cpp
cfe/trunk/lib/AST/ExprCXX.cpp

Modified: cfe/trunk/include/clang/AST/Expr.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Expr.h?rev=350741=350740=350741=diff
==
--- cfe/trunk/include/clang/AST/Expr.h (original)
+++ cfe/trunk/include/clang/AST/Expr.h Wed Jan  9 08:41:33 2019
@@ -2996,28 +2996,15 @@ public:
 /// representation in the source code (ExplicitCastExpr's derived
 /// classes).
 class CastExpr : public Expr {
-public:
-  using BasePathSizeTy = unsigned int;
-  static_assert(std::numeric_limits::max() >= 16384,
-"[implimits] Direct and indirect base classes [16384].");
-
-private:
   Stmt *Op;
 
   bool CastConsistency() const;
 
-  BasePathSizeTy *BasePathSize();
-
   const CXXBaseSpecifier * const *path_buffer() const {
 return const_cast(this)->path_buffer();
   }
   CXXBaseSpecifier **path_buffer();
 
-  void setBasePathSize(BasePathSizeTy basePathSize) {
-assert(!path_empty() && basePathSize != 0);
-*(BasePathSize()) = basePathSize;
-  }
-
 protected:
   CastExpr(StmtClass SC, QualType ty, ExprValueKind VK, const CastKind kind,
Expr *op, unsigned BasePathSize)
@@ -3038,9 +3025,9 @@ protected:
 Op(op) {
 CastExprBits.Kind = kind;
 CastExprBits.PartOfExplicitCast = false;
-CastExprBits.BasePathIsEmpty = BasePathSize == 0;
-if (!path_empty())
-  setBasePathSize(BasePathSize);
+CastExprBits.BasePathSize = BasePathSize;
+assert((CastExprBits.BasePathSize == BasePathSize) &&
+   "BasePathSize overflow!");
 assert(CastConsistency());
   }
 
@@ -3048,9 +3035,9 @@ protected:
   CastExpr(StmtClass SC, EmptyShell Empty, unsigned BasePathSize)
 : Expr(SC, Empty) {
 CastExprBits.PartOfExplicitCast = false;
-CastExprBits.BasePathIsEmpty = BasePathSize == 0;
-if (!path_empty())
-  setBasePathSize(BasePathSize);
+CastExprBits.BasePathSize = BasePathSize;
+assert((CastExprBits.BasePathSize == BasePathSize) &&
+   "BasePathSize overflow!");
   }
 
 public:
@@ -3077,13 +3064,9 @@ public:
   NamedDecl *getConversionFunction() const;
 
   typedef CXXBaseSpecifier **path_iterator;
-  typedef const CXXBaseSpecifier * const *path_const_iterator;
-  bool path_empty() const { return CastExprBits.BasePathIsEmpty; }
-  unsigned path_size() const {
-if (path_empty())
-  return 0U;
-return *(const_cast(this)->BasePathSize());
-  }
+  typedef const CXXBaseSpecifier *const *path_const_iterator;
+  bool path_empty() const { return path_size() == 0; }
+  unsigned path_size() const { return CastExprBits.BasePathSize; }
   path_iterator path_begin() { return path_buffer(); }
   path_iterator path_end() { return path_buffer() + path_size(); }
   path_const_iterator path_begin() const { return path_buffer(); }
@@ -3131,13 +3114,8 @@ public:
 /// @endcode
 class ImplicitCastExpr final
 : public CastExpr,
-  private llvm::TrailingObjects {
-  size_t numTrailingObjects(OverloadToken) const {
-return path_empty() ? 0 : 1;
-  }
+  private llvm::TrailingObjects {
 
-private:
   ImplicitCastExpr(QualType ty, CastKind kind, Expr *op,
unsigned BasePathLength, ExprValueKind VK)
 : CastExpr(ImplicitCastExprClass, ty, VK, kind, op, BasePathLength) { }
@@ -3245,8 +3223,7 @@ public:
 /// (Type)expr. For example: @c (int)f.
 class CStyleCastExpr final
 : public ExplicitCastExpr,
-  private llvm::TrailingObjects {
+  private llvm::TrailingObjects {
   

r350732 - [AST] Store the results in OverloadExpr in a trailing array

2019-01-09 Thread Bruno Ricci via cfe-commits
Author: brunoricci
Date: Wed Jan  9 07:43:19 2019
New Revision: 350732

URL: http://llvm.org/viewvc/llvm-project?rev=350732=rev
Log:
[AST] Store the results in OverloadExpr in a trailing array

Use the newly available space in the bit-fields of Stmt to pack
OverloadExpr, UnresolvedLookupExpr and UnresolvedMemberExpr.

Additionally store the results in the overload set in a trailing array.
This saves 1 pointer + 8 bytes per UnresolvedLookupExpr and
UnresolvedMemberExpr.

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

Reviewed By: rjmccall


Modified:
cfe/trunk/include/clang/AST/ExprCXX.h
cfe/trunk/include/clang/AST/Stmt.h
cfe/trunk/lib/AST/ExprCXX.cpp
cfe/trunk/lib/Serialization/ASTReaderStmt.cpp
cfe/trunk/lib/Serialization/ASTWriterStmt.cpp

Modified: cfe/trunk/include/clang/AST/ExprCXX.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ExprCXX.h?rev=350732=350731=350732=diff
==
--- cfe/trunk/include/clang/AST/ExprCXX.h (original)
+++ cfe/trunk/include/clang/AST/ExprCXX.h Wed Jan  9 07:43:19 2019
@@ -2658,58 +2658,54 @@ public:
 /// A reference to an overloaded function set, either an
 /// \c UnresolvedLookupExpr or an \c UnresolvedMemberExpr.
 class OverloadExpr : public Expr {
+  friend class ASTStmtReader;
+  friend class ASTStmtWriter;
+
   /// The common name of these declarations.
   DeclarationNameInfo NameInfo;
 
   /// The nested-name-specifier that qualifies the name, if any.
   NestedNameSpecifierLoc QualifierLoc;
 
-  /// The results.  These are undesugared, which is to say, they may
-  /// include UsingShadowDecls.  Access is relative to the naming
-  /// class.
-  // FIXME: Allocate this data after the OverloadExpr subclass.
-  DeclAccessPair *Results = nullptr;
-
-  unsigned NumResults = 0;
-
 protected:
-  /// Whether the name includes info for explicit template
-  /// keyword and arguments.
-  bool HasTemplateKWAndArgsInfo = false;
-
-  OverloadExpr(StmtClass K, const ASTContext ,
+  OverloadExpr(StmtClass SC, const ASTContext ,
NestedNameSpecifierLoc QualifierLoc,
SourceLocation TemplateKWLoc,
const DeclarationNameInfo ,
const TemplateArgumentListInfo *TemplateArgs,
UnresolvedSetIterator Begin, UnresolvedSetIterator End,
-   bool KnownDependent,
-   bool KnownInstantiationDependent,
+   bool KnownDependent, bool KnownInstantiationDependent,
bool KnownContainsUnexpandedParameterPack);
 
-  OverloadExpr(StmtClass K, EmptyShell Empty) : Expr(K, Empty) {}
+  OverloadExpr(StmtClass SC, EmptyShell Empty, unsigned NumResults,
+   bool HasTemplateKWAndArgsInfo);
 
-  /// Return the optional template keyword and arguments info.
-  ASTTemplateKWAndArgsInfo *
-  getTrailingASTTemplateKWAndArgsInfo(); // defined far below.
+  /// Return the results. Defined after UnresolvedMemberExpr.
+  inline DeclAccessPair *getTrailingResults();
+  const DeclAccessPair *getTrailingResults() const {
+return const_cast(this)->getTrailingResults();
+  }
 
   /// Return the optional template keyword and arguments info.
+  /// Defined after UnresolvedMemberExpr.
+  inline ASTTemplateKWAndArgsInfo *getTrailingASTTemplateKWAndArgsInfo();
   const ASTTemplateKWAndArgsInfo *getTrailingASTTemplateKWAndArgsInfo() const {
 return const_cast(this)
 ->getTrailingASTTemplateKWAndArgsInfo();
   }
 
-  /// Return the optional template arguments.
-  TemplateArgumentLoc *getTrailingTemplateArgumentLoc(); // defined far below
+  /// Return the optional template arguments. Defined after
+  /// UnresolvedMemberExpr.
+  inline TemplateArgumentLoc *getTrailingTemplateArgumentLoc();
+  const TemplateArgumentLoc *getTrailingTemplateArgumentLoc() const {
+return const_cast(this)->getTrailingTemplateArgumentLoc();
+  }
 
-  void initializeResults(const ASTContext ,
- UnresolvedSetIterator Begin,
- UnresolvedSetIterator End);
+  bool hasTemplateKWAndArgsInfo() const {
+return OverloadExprBits.HasTemplateKWAndArgsInfo;
+  }
 
 public:
-  friend class ASTStmtReader;
-  friend class ASTStmtWriter;
-
   struct FindResult {
 OverloadExpr *Expression;
 bool IsAddressOfOperand;
@@ -2745,20 +2741,26 @@ public:
   }
 
   /// Gets the naming class of this lookup, if any.
-  CXXRecordDecl *getNamingClass() const;
+  /// Defined after UnresolvedMemberExpr.
+  inline CXXRecordDecl *getNamingClass();
+  const CXXRecordDecl *getNamingClass() const {
+return const_cast(this)->getNamingClass();
+  }
 
   using decls_iterator = UnresolvedSetImpl::iterator;
 
-  decls_iterator decls_begin() const { return UnresolvedSetIterator(Results); }
+  decls_iterator decls_begin() const {
+return UnresolvedSetIterator(getTrailingResults());
+  }
   decls_iterator decls_end() const {
-return 

r350635 - [AST][NFC] Pack CXXScalarValueInitExpr

2019-01-08 Thread Bruno Ricci via cfe-commits
Author: brunoricci
Date: Tue Jan  8 08:08:54 2019
New Revision: 350635

URL: http://llvm.org/viewvc/llvm-project?rev=350635=rev
Log:
[AST][NFC] Pack CXXScalarValueInitExpr

Use the newly available space in the bit-fields of Stmt.
This saves one pointer per CXXScalarValueInitExpr. NFC.


Modified:
cfe/trunk/include/clang/AST/ExprCXX.h
cfe/trunk/include/clang/AST/Stmt.h
cfe/trunk/lib/AST/ExprCXX.cpp
cfe/trunk/lib/Serialization/ASTReaderStmt.cpp

Modified: cfe/trunk/include/clang/AST/ExprCXX.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ExprCXX.h?rev=350635=350634=350635=diff
==
--- cfe/trunk/include/clang/AST/ExprCXX.h (original)
+++ cfe/trunk/include/clang/AST/ExprCXX.h Tue Jan  8 08:08:54 2019
@@ -1896,18 +1896,19 @@ public:
 class CXXScalarValueInitExpr : public Expr {
   friend class ASTStmtReader;
 
-  SourceLocation RParenLoc;
   TypeSourceInfo *TypeInfo;
 
 public:
   /// Create an explicitly-written scalar-value initialization
   /// expression.
   CXXScalarValueInitExpr(QualType Type, TypeSourceInfo *TypeInfo,
- SourceLocation rParenLoc)
-  : Expr(CXXScalarValueInitExprClass, Type, VK_RValue, OK_Ordinary,
- false, false, Type->isInstantiationDependentType(),
+ SourceLocation RParenLoc)
+  : Expr(CXXScalarValueInitExprClass, Type, VK_RValue, OK_Ordinary, false,
+ false, Type->isInstantiationDependentType(),
  Type->containsUnexpandedParameterPack()),
-RParenLoc(rParenLoc), TypeInfo(TypeInfo) {}
+TypeInfo(TypeInfo) {
+CXXScalarValueInitExprBits.RParenLoc = RParenLoc;
+  }
 
   explicit CXXScalarValueInitExpr(EmptyShell Shell)
   : Expr(CXXScalarValueInitExprClass, Shell) {}
@@ -1916,10 +1917,12 @@ public:
 return TypeInfo;
   }
 
-  SourceLocation getRParenLoc() const { return RParenLoc; }
+  SourceLocation getRParenLoc() const {
+return CXXScalarValueInitExprBits.RParenLoc;
+  }
 
   SourceLocation getBeginLoc() const LLVM_READONLY;
-  SourceLocation getEndLoc() const LLVM_READONLY { return RParenLoc; }
+  SourceLocation getEndLoc() const { return getRParenLoc(); }
 
   static bool classof(const Stmt *T) {
 return T->getStmtClass() == CXXScalarValueInitExprClass;

Modified: cfe/trunk/include/clang/AST/Stmt.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Stmt.h?rev=350635=350634=350635=diff
==
--- cfe/trunk/include/clang/AST/Stmt.h (original)
+++ cfe/trunk/include/clang/AST/Stmt.h Tue Jan  8 08:08:54 2019
@@ -612,6 +612,15 @@ protected:
 SourceLocation Loc;
   };
 
+  class CXXScalarValueInitExprBitfields {
+friend class ASTStmtReader;
+friend class CXXScalarValueInitExpr;
+
+unsigned : NumExprBits;
+
+SourceLocation RParenLoc;
+  };
+
   class CXXNewExprBitfields {
 friend class ASTStmtReader;
 friend class ASTStmtWriter;
@@ -859,6 +868,7 @@ protected:
 CXXThrowExprBitfields CXXThrowExprBits;
 CXXDefaultArgExprBitfields CXXDefaultArgExprBits;
 CXXDefaultInitExprBitfields CXXDefaultInitExprBits;
+CXXScalarValueInitExprBitfields CXXScalarValueInitExprBits;
 CXXNewExprBitfields CXXNewExprBits;
 CXXDeleteExprBitfields CXXDeleteExprBits;
 TypeTraitExprBitfields TypeTraitExprBits;

Modified: cfe/trunk/lib/AST/ExprCXX.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprCXX.cpp?rev=350635=350634=350635=diff
==
--- cfe/trunk/lib/AST/ExprCXX.cpp (original)
+++ cfe/trunk/lib/AST/ExprCXX.cpp Tue Jan  8 08:08:54 2019
@@ -90,7 +90,7 @@ QualType CXXUuidofExpr::getTypeOperand(A
 
 // CXXScalarValueInitExpr
 SourceLocation CXXScalarValueInitExpr::getBeginLoc() const {
-  return TypeInfo ? TypeInfo->getTypeLoc().getBeginLoc() : RParenLoc;
+  return TypeInfo ? TypeInfo->getTypeLoc().getBeginLoc() : getRParenLoc();
 }
 
 // CXXNewExpr

Modified: cfe/trunk/lib/Serialization/ASTReaderStmt.cpp
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Serialization/ASTReaderStmt.cpp?rev=350635=350634=350635=diff
==
--- cfe/trunk/lib/Serialization/ASTReaderStmt.cpp (original)
+++ cfe/trunk/lib/Serialization/ASTReaderStmt.cpp Tue Jan  8 08:08:54 2019
@@ -1502,7 +1502,7 @@ void ASTStmtReader::VisitCXXBindTemporar
 void ASTStmtReader::VisitCXXScalarValueInitExpr(CXXScalarValueInitExpr *E) {
   VisitExpr(E);
   E->TypeInfo = GetTypeSourceInfo();
-  E->RParenLoc = ReadSourceLocation();
+  E->CXXScalarValueInitExprBits.RParenLoc = ReadSourceLocation();
 }
 
 void ASTStmtReader::VisitCXXNewExpr(CXXNewExpr *E) {


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


r350627 - [AST][NFC] Pack CXXNoexceptExpr and SubstNonTypeTemplateParmExpr

2019-01-08 Thread Bruno Ricci via cfe-commits
Author: brunoricci
Date: Tue Jan  8 06:44:34 2019
New Revision: 350627

URL: http://llvm.org/viewvc/llvm-project?rev=350627=rev
Log:
[AST][NFC] Pack CXXNoexceptExpr and SubstNonTypeTemplateParmExpr

Use the newly available space in the bit-fields of Stmt.
This saves one pointer per CXXNoexceptExpr/SubstNonTypeTemplateParmExpr.

Use this opportunity to run clang-format on these two classes and
fix some style issues. NFC overall.


Modified:
cfe/trunk/include/clang/AST/ExprCXX.h
cfe/trunk/include/clang/AST/Stmt.h
cfe/trunk/lib/Serialization/ASTReaderStmt.cpp

Modified: cfe/trunk/include/clang/AST/ExprCXX.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ExprCXX.h?rev=350627=350626=350627=diff
==
--- cfe/trunk/include/clang/AST/ExprCXX.h (original)
+++ cfe/trunk/include/clang/AST/ExprCXX.h Tue Jan  8 06:44:34 2019
@@ -3720,7 +3720,6 @@ inline TemplateArgumentLoc *OverloadExpr
 class CXXNoexceptExpr : public Expr {
   friend class ASTStmtReader;
 
-  bool Value : 1;
   Stmt *Operand;
   SourceRange Range;
 
@@ -3728,21 +3727,23 @@ public:
   CXXNoexceptExpr(QualType Ty, Expr *Operand, CanThrowResult Val,
   SourceLocation Keyword, SourceLocation RParen)
   : Expr(CXXNoexceptExprClass, Ty, VK_RValue, OK_Ordinary,
- /*TypeDependent*/false,
- /*ValueDependent*/Val == CT_Dependent,
+ /*TypeDependent*/ false,
+ /*ValueDependent*/ Val == CT_Dependent,
  Val == CT_Dependent || Operand->isInstantiationDependent(),
  Operand->containsUnexpandedParameterPack()),
-Value(Val == CT_Cannot), Operand(Operand), Range(Keyword, RParen) {}
+Operand(Operand), Range(Keyword, RParen) {
+CXXNoexceptExprBits.Value = Val == CT_Cannot;
+  }
 
   CXXNoexceptExpr(EmptyShell Empty) : Expr(CXXNoexceptExprClass, Empty) {}
 
-  Expr *getOperand() const { return static_cast(Operand); }
+  Expr *getOperand() const { return static_cast(Operand); }
 
-  SourceLocation getBeginLoc() const LLVM_READONLY { return Range.getBegin(); }
-  SourceLocation getEndLoc() const LLVM_READONLY { return Range.getEnd(); }
-  SourceRange getSourceRange() const LLVM_READONLY { return Range; }
+  SourceLocation getBeginLoc() const { return Range.getBegin(); }
+  SourceLocation getEndLoc() const { return Range.getEnd(); }
+  SourceRange getSourceRange() const { return Range; }
 
-  bool getValue() const { return Value; }
+  bool getValue() const { return CXXNoexceptExprBits.Value; }
 
   static bool classof(const Stmt *T) {
 return T->getStmtClass() == CXXNoexceptExprClass;
@@ -3965,27 +3966,27 @@ class SubstNonTypeTemplateParmExpr : pub
   /// The replacement expression.
   Stmt *Replacement;
 
-  /// The location of the non-type template parameter reference.
-  SourceLocation NameLoc;
-
   explicit SubstNonTypeTemplateParmExpr(EmptyShell Empty)
   : Expr(SubstNonTypeTemplateParmExprClass, Empty) {}
 
 public:
-  SubstNonTypeTemplateParmExpr(QualType type,
-   ExprValueKind valueKind,
-   SourceLocation loc,
-   NonTypeTemplateParmDecl *param,
-   Expr *replacement)
-  : Expr(SubstNonTypeTemplateParmExprClass, type, valueKind, OK_Ordinary,
- replacement->isTypeDependent(), replacement->isValueDependent(),
- replacement->isInstantiationDependent(),
- replacement->containsUnexpandedParameterPack()),
-Param(param), Replacement(replacement), NameLoc(loc) {}
-
-  SourceLocation getNameLoc() const { return NameLoc; }
-  SourceLocation getBeginLoc() const LLVM_READONLY { return NameLoc; }
-  SourceLocation getEndLoc() const LLVM_READONLY { return NameLoc; }
+  SubstNonTypeTemplateParmExpr(QualType Ty, ExprValueKind ValueKind,
+   SourceLocation Loc,
+   NonTypeTemplateParmDecl *Param,
+   Expr *Replacement)
+  : Expr(SubstNonTypeTemplateParmExprClass, Ty, ValueKind, OK_Ordinary,
+ Replacement->isTypeDependent(), Replacement->isValueDependent(),
+ Replacement->isInstantiationDependent(),
+ Replacement->containsUnexpandedParameterPack()),
+Param(Param), Replacement(Replacement) {
+SubstNonTypeTemplateParmExprBits.NameLoc = Loc;
+  }
+
+  SourceLocation getNameLoc() const {
+return SubstNonTypeTemplateParmExprBits.NameLoc;
+  }
+  SourceLocation getBeginLoc() const { return getNameLoc(); }
+  SourceLocation getEndLoc() const { return getNameLoc(); }
 
   Expr *getReplacement() const { return cast(Replacement); }
 
@@ -3996,7 +3997,7 @@ public:
   }
 
   // Iterators
-  child_range children() { return child_range(, +1); }
+  child_range children() { return child_range(,  + 1); 
}
 };
 
 /// Represents a reference to a non-type template parameter pack that

r350625 - [AST] Pack CXXDependentScopeMemberExpr

2019-01-08 Thread Bruno Ricci via cfe-commits
Author: brunoricci
Date: Tue Jan  8 06:17:00 2019
New Revision: 350625

URL: http://llvm.org/viewvc/llvm-project?rev=350625=rev
Log:
[AST] Pack CXXDependentScopeMemberExpr

Use the newly available space in the bit-fields of Stmt. Additionally store
FirstQualifierFoundInScope as a trailing object since it is most of the time
null (non-null for 2 of the 35446 CXXDependentScopeMemberExpr when parsing
all of Boost).

It would be possible to move the data for the nested-name-specifier to a
trailing object too to save another 2 pointers, however doing so did actually
regress the time taken to parse all of Boost slightly.

This saves 8 bytes + 1 pointer per CXXDependentScopeMemberExpr in the vast
majority of cases.

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

Reviewed By: rjmccall


Modified:
cfe/trunk/include/clang/AST/ExprCXX.h
cfe/trunk/include/clang/AST/Stmt.h
cfe/trunk/lib/AST/ExprCXX.cpp
cfe/trunk/lib/Serialization/ASTReaderStmt.cpp
cfe/trunk/lib/Serialization/ASTWriterStmt.cpp

Modified: cfe/trunk/include/clang/AST/ExprCXX.h
URL: 
http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/ExprCXX.h?rev=350625=350624=350625=diff
==
--- cfe/trunk/include/clang/AST/ExprCXX.h (original)
+++ cfe/trunk/include/clang/AST/ExprCXX.h Tue Jan  8 06:17:00 2019
@@ -3306,7 +3306,11 @@ class CXXDependentScopeMemberExpr final
 : public Expr,
   private llvm::TrailingObjects {
+TemplateArgumentLoc, NamedDecl *> {
+  friend class ASTStmtReader;
+  friend class ASTStmtWriter;
+  friend TrailingObjects;
+
   /// The expression for the base pointer or class reference,
   /// e.g., the \c x in x.f.  Can be null in implicit accesses.
   Stmt *Base;
@@ -3315,40 +3319,53 @@ class CXXDependentScopeMemberExpr final
   /// implicit accesses.
   QualType BaseType;
 
-  /// Whether this member expression used the '->' operator or
-  /// the '.' operator.
-  bool IsArrow : 1;
-
-  /// Whether this member expression has info for explicit template
-  /// keyword and arguments.
-  bool HasTemplateKWAndArgsInfo : 1;
-
-  /// The location of the '->' or '.' operator.
-  SourceLocation OperatorLoc;
-
   /// The nested-name-specifier that precedes the member name, if any.
+  /// FIXME: This could be in principle store as a trailing object.
+  /// However the performance impact of doing so should be investigated first.
   NestedNameSpecifierLoc QualifierLoc;
 
-  /// In a qualified member access expression such as t->Base::f, this
-  /// member stores the resolves of name lookup in the context of the member
-  /// access expression, to be used at instantiation time.
-  ///
-  /// FIXME: This member, along with the QualifierLoc, could
-  /// be stuck into a structure that is optionally allocated at the end of
-  /// the CXXDependentScopeMemberExpr, to save space in the common case.
-  NamedDecl *FirstQualifierFoundInScope;
-
   /// The member to which this member expression refers, which
   /// can be name, overloaded operator, or destructor.
   ///
   /// FIXME: could also be a template-id
   DeclarationNameInfo MemberNameInfo;
 
-  size_t numTrailingObjects(OverloadToken) const {
-return HasTemplateKWAndArgsInfo ? 1 : 0;
+  // CXXDependentScopeMemberExpr is followed by several trailing objects,
+  // some of which optional. They are in order:
+  //
+  // * An optional ASTTemplateKWAndArgsInfo for the explicitly specified
+  //   template keyword and arguments. Present if and only if
+  //   hasTemplateKWAndArgsInfo().
+  //
+  // * An array of getNumTemplateArgs() TemplateArgumentLoc containing location
+  //   information for the explicitly specified template arguments.
+  //
+  // * An optional NamedDecl *. In a qualified member access expression such
+  //   as t->Base::f, this member stores the resolves of name lookup in the
+  //   context of the member access expression, to be used at instantiation
+  //   time. Present if and only if hasFirstQualifierFoundInScope().
+
+  bool hasTemplateKWAndArgsInfo() const {
+return CXXDependentScopeMemberExprBits.HasTemplateKWAndArgsInfo;
+  }
+
+  bool hasFirstQualifierFoundInScope() const {
+return CXXDependentScopeMemberExprBits.HasFirstQualifierFoundInScope;
+  }
+
+  unsigned numTrailingObjects(OverloadToken) const {
+return hasTemplateKWAndArgsInfo();
+  }
+
+  unsigned numTrailingObjects(OverloadToken) const {
+return getNumTemplateArgs();
   }
 
-  CXXDependentScopeMemberExpr(const ASTContext , Expr *Base,
+  unsigned numTrailingObjects(OverloadToken) const {
+return hasFirstQualifierFoundInScope();
+  }
+
+  CXXDependentScopeMemberExpr(const ASTContext , Expr *Base,
   QualType BaseType, bool IsArrow,
   SourceLocation OperatorLoc,
   NestedNameSpecifierLoc QualifierLoc,
@@ -3357,33 +3374,29 @@ class CXXDependentScopeMemberExpr 

  1   2   >