[clang] 3a0309c - [clang] Improve diagnostics for expansion length mismatch

2022-08-30 Thread Matheus Izvekov via cfe-commits

Author: Matheus Izvekov
Date: 2022-08-30T18:58:38+02:00
New Revision: 3a0309c53674be56b5cfce038d78a0c2c6e2a98c

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

LOG: [clang] Improve diagnostics for expansion length mismatch

When checking parameter packs for expansion, instead of basing the diagnostic 
for
length mismatch for outer parameters only on the known number of expansions,
we should also analyze SubstTemplateTypeParmPackType and 
SubstNonTypeTemplateParmPackExpr
for unexpanded packs, so we can emit a diagnostic pointing to a concrete
outer parameter.

Signed-off-by: Matheus Izvekov 

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Sema/Sema.h
clang/include/clang/Sema/SemaInternal.h
clang/lib/Sema/SemaTemplateDeduction.cpp
clang/lib/Sema/SemaTemplateVariadic.cpp
clang/test/CXX/temp/temp.decls/temp.variadic/p5.cpp
clang/test/SemaTemplate/cxx1z-fold-expressions.cpp
clang/test/SemaTemplate/pack-deduction.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 132e282797053..824ab42706334 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -118,6 +118,8 @@ Improvements to Clang's diagnostics
 - Correctly diagnose a future keyword if it exist as a keyword in the higher
   language version and specifies in which version it will be a keyword. This
   supports both c and c++ language.
+- When diagnosing multi-level pack expansions of mismatched lengths, Clang will
+  now, in most cases, be able to point to the relevant outer parameter.
 
 Non-comprehensive list of changes in this release
 -

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 0ee21cf64aa34..bd81d3a7e5ee5 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -238,8 +238,11 @@ namespace threadSafety {
 
 // FIXME: No way to easily map from TemplateTypeParmTypes to
 // TemplateTypeParmDecls, so we have this horrible PointerUnion.
-typedef std::pair,
-  SourceLocation> UnexpandedParameterPack;
+using UnexpandedParameterPack = std::pair<
+llvm::PointerUnion<
+const TemplateTypeParmType *, const SubstTemplateTypeParmPackType *,
+const SubstNonTypeTemplateParmPackExpr *, const NamedDecl *>,
+SourceLocation>;
 
 /// Describes whether we've seen any nullability information for the given
 /// file.

diff  --git a/clang/include/clang/Sema/SemaInternal.h 
b/clang/include/clang/Sema/SemaInternal.h
index 842eec099540c..4eca50919dc7e 100644
--- a/clang/include/clang/Sema/SemaInternal.h
+++ b/clang/include/clang/Sema/SemaInternal.h
@@ -62,7 +62,7 @@ inline InheritableAttr *getDLLAttr(Decl *D) {
 }
 
 /// Retrieve the depth and index of a template parameter.
-inline std::pair getDepthAndIndex(NamedDecl *ND) {
+inline std::pair getDepthAndIndex(const NamedDecl *ND) {
   if (const auto *TTP = dyn_cast(ND))
 return std::make_pair(TTP->getDepth(), TTP->getIndex());
 
@@ -79,7 +79,7 @@ getDepthAndIndex(UnexpandedParameterPack UPP) {
   if (const auto *TTP = UPP.first.dyn_cast())
 return std::make_pair(TTP->getDepth(), TTP->getIndex());
 
-  return getDepthAndIndex(UPP.first.get());
+  return getDepthAndIndex(UPP.first.get());
 }
 
 class TypoCorrectionConsumer : public VisibleDeclConsumer {

diff  --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 
b/clang/lib/Sema/SemaTemplateDeduction.cpp
index 84c4a191ec327..e8837d88f97dd 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -738,8 +738,11 @@ class PackDeductionScope {
   SmallVector Unexpanded;
   S.collectUnexpandedParameterPacks(Pattern, Unexpanded);
   for (unsigned I = 0, N = Unexpanded.size(); I != N; ++I) {
-unsigned Depth, Index;
-std::tie(Depth, Index) = getDepthAndIndex(Unexpanded[I]);
+UnexpandedParameterPack U = Unexpanded[I];
+if (U.first.is() ||
+U.first.is())
+  continue;
+auto [Depth, Index] = getDepthAndIndex(U);
 if (Depth == Info.getDeducedDepth())
   AddPack(Index);
   }

diff  --git a/clang/lib/Sema/SemaTemplateVariadic.cpp 
b/clang/lib/Sema/SemaTemplateVariadic.cpp
index 285bf67398f16..69e0c70bbec53 100644
--- a/clang/lib/Sema/SemaTemplateVariadic.cpp
+++ b/clang/lib/Sema/SemaTemplateVariadic.cpp
@@ -88,6 +88,23 @@ namespace {
   return true;
 }
 
+bool
+VisitSubstTemplateTypeParmPackTypeLoc(SubstTemplateTypeParmPackTypeLoc TL) 
{
+  Unexpanded.push_back({TL.getTypePtr(), TL.getNameLoc()});
+  return true;
+}
+
+bool VisitSubstTemplateTypeParmPackType(SubstTemp

[clang] acb767f - [clang] fix profiling of template arguments of template and declaration kind

2022-09-06 Thread Matheus Izvekov via cfe-commits

Author: Matheus Izvekov
Date: 2022-09-06T18:27:39+02:00
New Revision: acb767f5cda59302aa9100afcf6133d66779d42c

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

LOG: [clang] fix profiling of template arguments of template and declaration 
kind

Template arguments of template and declaration kind were being profiled
only by their canonical properties, which would cause incorrect
uniquing of constrained AutoTypes, leading to a crash in some cases.

This exposed some places in CheckTemplateArgumentList where non-canonical
arguments where being pushed into the resulting converted list.

We also throw in some asserts to catch early and explain the crashes.

Note that the fix for the 'declaration' kind is untestable at this point,
because there should be no cases right now in the AST where we try
to unique a non-canonical converted template argument.

This fixes GH55567.

Signed-off-by: Matheus Izvekov 

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

Added: 


Modified: 
clang/lib/AST/ASTContext.cpp
clang/lib/AST/TemplateBase.cpp
clang/lib/Sema/SemaTemplate.cpp
clang/test/SemaTemplate/concepts.cpp

Removed: 




diff  --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 20fcc8fea4b79..28f4e19893326 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -5116,7 +5116,9 @@ ASTContext::getDependentTemplateSpecializationType(
CanonArgs);
 
 // Find the insert position again.
-DependentTemplateSpecializationTypes.FindNodeOrInsertPos(ID, InsertPos);
+[[maybe_unused]] auto *Nothing =
+DependentTemplateSpecializationTypes.FindNodeOrInsertPos(ID, 
InsertPos);
+assert(!Nothing && "canonical type broken");
   }
 
   void *Mem = Allocate((sizeof(DependentTemplateSpecializationType) +
@@ -5731,7 +5733,9 @@ QualType ASTContext::getAutoTypeInternal(
 Canon = getAutoTypeInternal(QualType(), Keyword, IsDependent, IsPack,
 TypeConstraintConcept, CanonArgs, true);
 // Find the insert position again.
-AutoTypes.FindNodeOrInsertPos(ID, InsertPos);
+[[maybe_unused]] auto *Nothing =
+AutoTypes.FindNodeOrInsertPos(ID, InsertPos);
+assert(!Nothing && "canonical type broken");
   }
 } else {
   Canon = DeducedType.getCanonicalType();

diff  --git a/clang/lib/AST/TemplateBase.cpp b/clang/lib/AST/TemplateBase.cpp
index e0f5916a9a0b7..6d9ab2b8ca718 100644
--- a/clang/lib/AST/TemplateBase.cpp
+++ b/clang/lib/AST/TemplateBase.cpp
@@ -321,26 +321,15 @@ void TemplateArgument::Profile(llvm::FoldingSetNodeID &ID,
 
   case Declaration:
 getParamTypeForDecl().Profile(ID);
-ID.AddPointer(getAsDecl()? getAsDecl()->getCanonicalDecl() : nullptr);
+ID.AddPointer(getAsDecl());
 break;
 
+  case TemplateExpansion:
+ID.AddInteger(TemplateArg.NumExpansions);
+LLVM_FALLTHROUGH;
   case Template:
-  case TemplateExpansion: {
-TemplateName Template = getAsTemplateOrTemplatePattern();
-if (TemplateTemplateParmDecl *TTP
-  = dyn_cast_or_null(
-Template.getAsTemplateDecl())) 
{
-  ID.AddBoolean(true);
-  ID.AddInteger(TTP->getDepth());
-  ID.AddInteger(TTP->getPosition());
-  ID.AddBoolean(TTP->isParameterPack());
-} else {
-  ID.AddBoolean(false);
-  ID.AddPointer(Context.getCanonicalTemplateName(Template)
-  .getAsVoidPointer());
-}
+getAsTemplateOrTemplatePattern().Profile(ID);
 break;
-  }
 
   case Integral:
 getAsIntegral().Profile(ID);

diff  --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index b06612d02797b..e9076bb6633af 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -5643,7 +5643,8 @@ bool Sema::CheckTemplateArgument(NamedDecl *Param,
 if (CheckTemplateTemplateArgument(TempParm, Params, Arg))
   return true;
 
-Converted.push_back(Arg.getArgument());
+Converted.push_back(
+Context.getCanonicalTemplateArgument(Arg.getArgument()));
 break;
 
   case TemplateArgument::Expression:
@@ -5813,13 +5814,14 @@ bool Sema::CheckTemplateArgumentList(
 if (!ArgumentPack.empty()) {
   // If we were part way through filling in an expanded parameter pack,
   // fall back to just producing individual arguments.
-  Converted.insert(Converted.end(),
-   ArgumentPack.begin(), ArgumentPack.end());
+  for (const TemplateArgument &I : ArgumentPack)
+Converted.push_back(Context.getCanonicalTemplateArgument(I));
   ArgumentPack.clear();
 }
 
 

[clang] 94c6dfb - [clang] Implement setting crash_diagnostics_dir through env variable

2022-09-06 Thread Matheus Izvekov via cfe-commits

Author: Matheus Izvekov
Date: 2022-09-06T19:27:37+02:00
New Revision: 94c6dfbaebbd5b9474794b2437757dfb6aedefc3

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

LOG: [clang] Implement setting crash_diagnostics_dir through env variable

This implements setting the equivalent of `-fcrash-diagnostics-dir`
through the environment variable `CLANG_CRASH_DIAGNOSTICS_DIR`.
If present, the flag still takes precedence.

This helps integration with test frameworks and pipelines.

With this feature, we change the libcxx bootstrapping build
pipeline to produce clang crash reproducers as artifacts.

Signed-off-by: Matheus Izvekov 

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

Added: 
clang/test/Driver/crash-diagnostics-dir-3.c

Modified: 
clang/docs/ReleaseNotes.rst
clang/docs/UsersManual.rst
clang/lib/Driver/Driver.cpp
libcxx/utils/ci/buildkite-pipeline.yml

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 146b2149f9d7e..1d381649b6bb4 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -135,6 +135,9 @@ Improvements to Clang's diagnostics
 
 Non-comprehensive list of changes in this release
 -
+- It's now possible to set the crash diagnostics directory through
+  the environment variable ``CLANG_CRASH_DIAGNOSTICS_DIR``.
+  The ``-fcrash-diagnostics-dir`` flag takes precedence.
 
 New Compiler Flags
 --

diff  --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index bf17677274e0c..8afe5cab64cb5 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -687,6 +687,11 @@ of generating a delta reduced test case.
   Specify where to write the crash diagnostics files; defaults to the
   usual location for temporary files.
 
+.. envvar:: CLANG_CRASH_DIAGNOSTICS_DIR=
+
+   Like :option:`-fcrash-diagnostics-dir=`, specifies where to write the
+   crash diagnostics files, but with lower precedence than the option.
+
 Clang is also capable of generating preprocessed source file(s) and associated
 run script(s) even without a crash. This is specially useful when trying to
 generate a reproducer for warnings or errors while using modules.

diff  --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 0a61b5e2d62d4..3743515d3d43f 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -5413,15 +5413,18 @@ const char *Driver::CreateTempFile(Compilation &C, 
StringRef Prefix,
StringRef BoundArch) const {
   SmallString<128> TmpName;
   Arg *A = C.getArgs().getLastArg(options::OPT_fcrash_diagnostics_dir);
-  if (CCGenDiagnostics && A) {
-SmallString<128> CrashDirectory(A->getValue());
-if (!getVFS().exists(CrashDirectory))
-  llvm::sys::fs::create_directories(CrashDirectory);
-llvm::sys::path::append(CrashDirectory, Prefix);
+  Optional CrashDirectory =
+  CCGenDiagnostics && A
+  ? std::string(A->getValue())
+  : llvm::sys::Process::GetEnv("CLANG_CRASH_DIAGNOSTICS_DIR");
+  if (CrashDirectory) {
+if (!getVFS().exists(*CrashDirectory))
+  llvm::sys::fs::create_directories(*CrashDirectory);
+SmallString<128> Path(*CrashDirectory);
+llvm::sys::path::append(Path, Prefix);
 const char *Middle = !Suffix.empty() ? "-%%." : "-%%";
-std::error_code EC = llvm::sys::fs::createUniqueFile(
-CrashDirectory + Middle + Suffix, TmpName);
-if (EC) {
+if (std::error_code EC =
+llvm::sys::fs::createUniqueFile(Path + Middle + Suffix, TmpName)) {
   Diag(clang::diag::err_unable_to_make_temp) << EC.message();
   return "";
 }

diff  --git a/clang/test/Driver/crash-diagnostics-dir-3.c 
b/clang/test/Driver/crash-diagnostics-dir-3.c
new file mode 100644
index 0..9529e30021045
--- /dev/null
+++ b/clang/test/Driver/crash-diagnostics-dir-3.c
@@ -0,0 +1,5 @@
+// RUN: rm -rf %t
+// RUN: not env CLANG_CRASH_DIAGNOSTICS_DIR=%t %clang -c %s -o - 2>&1 | 
FileCheck %s
+#pragma clang __debug parser_crash
+// CHECK: Preprocessed source(s) and associated run script(s) are located at:
+// CHECK: diagnostic msg: 
{{.*}}{{/|\\}}crash-diagnostics-dir-3.c.tmp{{(/|\\).*}}.c

diff  --git a/libcxx/utils/ci/buildkite-pipeline.yml 
b/libcxx/utils/ci/buildkite-pipeline.yml
index d15172980e612..61951720ef650 100644
--- a/libcxx/utils/ci/buildkite-pipeline.yml
+++ b/libcxx/utils/ci/buildkite-pipeline.yml
@@ -369,10 +369,12 @@ steps:
 artifact_paths:
   - "**/test-results.xml"
   - "**/*.abilist"
+  - "**/crash_diagnostics/*"
 env:
 CC: "clang-${LLVM_HEAD_VERSION}"
 CXX: "clang++-${LLVM_HEAD_VERSION}"
 LLVM_SYMBOLIZER_PATH: "/usr/bin/llvm-sy

[clang-tools-extra] d200db3 - [clang] template / auto deduction deduces common sugar

2022-09-08 Thread Matheus Izvekov via cfe-commits

Author: Matheus Izvekov
Date: 2022-09-08T19:17:48+02:00
New Revision: d200db38637884fd0b421802c6094b2a03ceb29e

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

LOG: [clang] template / auto deduction deduces common sugar

After upgrading the type deduction machinery to retain type sugar in
D110216, we were left with a situation where there is no general
well behaved mechanism in Clang to unify the type sugar of multiple
deductions of the same type parameter.

So we ended up making an arbitrary choice: keep the sugar of the first
deduction, ignore subsequent ones.

In general, we already had this problem, but in a smaller scale.
The result of the conditional operator and many other binary ops
could benefit from such a mechanism.

This patch implements such a type sugar unification mechanism.

The basics:

This patch introduces a `getCommonSugaredType(QualType X, QualType Y)`
method to ASTContext which implements this functionality, and uses it
for unifying the results of type deduction and return type deduction.
This will return the most derived type sugar which occurs in both X and
Y.

Example:

Suppose we have these types:
```
using Animal = int;
using Cat = Animal;
using Dog = Animal;

using Tom = Cat;
using Spike = Dog;
using Tyke = Dog;
```
For `X = Tom, Y = Spike`, this will result in `Animal`.
For `X = Spike, Y = Tyke`, this will result in `Dog`.

How it works:

We take two types, X and Y, which we wish to unify as input.
These types must have the same (qualified or unqualified) canonical
type.

We dive down fast through top-level type sugar nodes, to the
underlying canonical node. If these canonical nodes differ, we
build a common one out of the two, unifying any sugar they had.
Note that this might involve a recursive call to unify any children
of those. We then return that canonical node, handling any qualifiers.

If they don't differ, we walk up the list of sugar type nodes we dived
through, finding the last identical pair, and returning that as the
result, again handling qualifiers.

Note that this patch will not unify sugar nodes if they are not
identical already. We will simply strip off top-level sugar nodes that
differ between X and Y. This sugar node unification will instead be
implemented in a subsequent patch.

This patch also implements a few users of this mechanism:
* Template argument deduction.
* Auto deduction, for functions returning auto / decltype(auto), with
  special handling for initializer_list as well.

Further users will be implemented in a subsequent patch.

Signed-off-by: Matheus Izvekov 

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

Added: 


Modified: 
clang-tools-extra/clangd/unittests/ASTTests.cpp
clang-tools-extra/clangd/unittests/HoverTests.cpp
clang/include/clang/AST/ASTContext.h
clang/include/clang/AST/Type.h
clang/include/clang/Sema/Sema.h
clang/lib/AST/ASTContext.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaDeclCXX.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/lib/Sema/SemaOverload.cpp
clang/lib/Sema/SemaStmt.cpp
clang/lib/Sema/SemaTemplate.cpp
clang/lib/Sema/SemaTemplateDeduction.cpp
clang/test/SemaCXX/cxx0x-initializer-stdinitializerlist.cpp
clang/test/SemaCXX/deduced-return-void.cpp
clang/test/SemaCXX/sugared-auto.cpp
clang/test/SemaTemplate/deduction.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/unittests/ASTTests.cpp 
b/clang-tools-extra/clangd/unittests/ASTTests.cpp
index 4bb3e025b87a5..8f67136585308 100644
--- a/clang-tools-extra/clangd/unittests/ASTTests.cpp
+++ b/clang-tools-extra/clangd/unittests/ASTTests.cpp
@@ -84,7 +84,7 @@ TEST(GetDeducedType, KwAutoKwDecltypeExpansion) {
 
   ^auto i = {1,2};
   )cpp",
-  "class std::initializer_list",
+  "std::initializer_list",
   },
   {
   R"cpp( // auto in function return type with trailing return type

diff  --git a/clang-tools-extra/clangd/unittests/HoverTests.cpp 
b/clang-tools-extra/clangd/unittests/HoverTests.cpp
index 663ebf2403739..d5e3e5fd48df7 100644
--- a/clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ b/clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -1940,7 +1940,7 @@ TEST(Hover, All) {
   [](HoverInfo &HI) {
 HI.Name = "auto";
 HI.Kind = index::SymbolKind::TypeAlias;
-HI.Definition = "class std::initializer_list";
+HI.Definition = "std::initializer_list";
   }},
   {
   R"cpp(// User defined conversion to auto

diff  --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index eb52bf5c736a0..8ef7a32e6f09e 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -2807,6 +2807,23

[clang] d42122c - [clang] use getCommonSugar in an assortment of places

2022-09-08 Thread Matheus Izvekov via cfe-commits

Author: Matheus Izvekov
Date: 2022-09-08T19:17:53+02:00
New Revision: d42122cd5db021e6b14a90a98ad1dd09412efb4c

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

LOG: [clang] use getCommonSugar in an assortment of places

For this patch, a simple search was performed for patterns where there are
two types (usually an LHS and an RHS) which are structurally the same, and there
is some result type which is resolved as either one of them (typically LHS for
consistency).

We change those cases to resolve as the common sugared type between those two,
utilizing the new infrastructure created for this purpose.

Depends on D111283

Signed-off-by: Matheus Izvekov 

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

Added: 
clang/test/Sema/sugar-common-types.c
clang/test/SemaCXX/sugar-common-types.cpp

Modified: 
clang-tools-extra/clangd/unittests/tweaks/ExtractVariableTests.cpp

clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/narrowing-conversions-ignoreconversionfromtypes-option.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/test/AST/ast-dump-fpfeatures.cpp
clang/test/CodeGen/compound-assign-overflow.c
clang/test/Sema/matrix-type-operators.c
clang/test/Sema/nullability.c
clang/test/SemaCXX/matrix-type-operators.cpp
clang/test/SemaCXX/sugared-auto.cpp
clang/test/SemaObjC/format-strings-objc.m
compiler-rt/test/ubsan/TestCases/Integer/add-overflow.cpp
compiler-rt/test/ubsan/TestCases/Integer/no-recover.cpp
compiler-rt/test/ubsan/TestCases/Integer/sub-overflow.cpp
compiler-rt/test/ubsan/TestCases/Integer/uadd-overflow.cpp
compiler-rt/test/ubsan/TestCases/Integer/umul-overflow.cpp
compiler-rt/test/ubsan/TestCases/Integer/usub-overflow.cpp
lldb/test/API/commands/expression/rdar42038760/main.c
lldb/test/API/commands/expression/rdar44436068/main.c

Removed: 




diff  --git 
a/clang-tools-extra/clangd/unittests/tweaks/ExtractVariableTests.cpp 
b/clang-tools-extra/clangd/unittests/tweaks/ExtractVariableTests.cpp
index 70ecc202d0b28..6e38ea77ad68d 100644
--- a/clang-tools-extra/clangd/unittests/tweaks/ExtractVariableTests.cpp
+++ b/clang-tools-extra/clangd/unittests/tweaks/ExtractVariableTests.cpp
@@ -330,7 +330,7 @@ TEST_F(ExtractVariableTest, Test) {
  void bar() {
int (*placeholder)(int) = foo('c'); (void)placeholder;
  })cpp"},
-  // Arithmetic on typedef types yields plain integer types
+  // Arithmetic on typedef types preserves typedef types
   {R"cpp(typedef long NSInteger;
  void varDecl() {
 NSInteger a = 2 * 5;
@@ -339,7 +339,7 @@ TEST_F(ExtractVariableTest, Test) {
R"cpp(typedef long NSInteger;
  void varDecl() {
 NSInteger a = 2 * 5;
-long placeholder = a * 7; NSInteger b = placeholder + 3;
+NSInteger placeholder = a * 7; NSInteger b = placeholder + 3;
  })cpp"},
   };
   for (const auto &IO : InputOutputs) {

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/narrowing-conversions-ignoreconversionfromtypes-option.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/narrowing-conversions-ignoreconversionfromtypes-option.cpp
index 2fc5621c2fb8f..34da420fd0cc5 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/narrowing-conversions-ignoreconversionfromtypes-option.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/narrowing-conversions-ignoreconversionfromtypes-option.cpp
@@ -42,7 +42,7 @@ void narrowing_size_method() {
   // IGNORED: Warning is disabled with IgnoreConversionFromTypes=global_size_t.
 
   i = j + v.size();
-  // CHECK-MESSAGES-DEFAULT: :[[@LINE-1]]:7: warning: narrowing conversion 
from 'long long' to signed type 'int' is implementation-defined 
[cppcoreguidelines-narrowing-conversions]
+  // CHECK-MESSAGES-DEFAULT: :[[@LINE-1]]:7: warning: narrowing conversion 
from 'global_size_t' (aka 'long long') to signed type 'int' is 
implementation-defined [cppcoreguidelines-narrowing-conversions]
   // IGNORED: Warning is disabled with IgnoreConversionFromTypes=global_size_t.
 }
 
@@ -51,7 +51,7 @@ void narrowing_size_method_binary_expr() {
   int j;
   vector v;
   i = j + v.size();
-  // CHECK-MESSAGES-DEFAULT: :[[@LINE-1]]:7: warning: narrowing conversion 
from 'long long' to signed type 'int' is implementation-defined 
[cppcoreguidelines-narrowing-conversions]
+  // CHECK-MESSAGES-DEFAULT: :[[@LINE-1]]:7: warning: narrowing conversion 
from 'global_size_t' (aka 'long long') to signed type 'int' is 
implementation-defined [cppcoreguidelines-narrowing-conversions]
   // IGNORED: Warning is disabled with IgnoreConversionF

[clang] 16e5d6d - [clang] extend getCommonSugaredType to merge sugar nodes

2022-09-08 Thread Matheus Izvekov via cfe-commits

Author: Matheus Izvekov
Date: 2022-09-08T19:17:53+02:00
New Revision: 16e5d6d7f98f1119aab3d10ec4f9e59b5aacd359

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

LOG: [clang] extend getCommonSugaredType to merge sugar nodes

This continues D111283 by extending the getCommonSugaredType
implementation to also merge non-canonical type nodes.

We merge these nodes by going up starting from the canonical
node, calculating their merged properties on the way.

If we reach a pair that is too different, or which we could not
otherwise unify, we bail out and don't try to keep going on to
the next pair, in effect striping out all the remaining top-level
sugar nodes. This avoids mismatching 'companion' nodes, such as
ElaboratedType, so that they don't end up elaborating some other
unrelated thing.

Depends on D111509

Signed-off-by: Matheus Izvekov 

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

Added: 


Modified: 
clang/include/clang/AST/ASTContext.h
clang/lib/AST/ASTContext.cpp
clang/lib/Sema/SemaTemplateDeduction.cpp
clang/test/SemaCXX/sugar-common-types.cpp

Removed: 




diff  --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index 8ef7a32e6f09..acde4ff6f942 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -1366,6 +1366,9 @@ class ASTContext : public RefCountedBase {
   CanQualType getDecayedType(CanQualType T) const {
 return CanQualType::CreateUnsafe(getDecayedType((QualType) T));
   }
+  /// Return the uniqued reference to a specified decay from the original
+  /// type to the decayed type.
+  QualType getDecayedType(QualType Orig, QualType Decayed) const;
 
   /// Return the uniqued reference to the atomic type for the specified
   /// type.

diff  --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index d7c626adee19..fe06e8eb18f1 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -3332,6 +3332,26 @@ QualType ASTContext::getAdjustedType(QualType Orig, 
QualType New) const {
   return QualType(AT, 0);
 }
 
+QualType ASTContext::getDecayedType(QualType Orig, QualType Decayed) const {
+  llvm::FoldingSetNodeID ID;
+  AdjustedType::Profile(ID, Orig, Decayed);
+  void *InsertPos = nullptr;
+  AdjustedType *AT = AdjustedTypes.FindNodeOrInsertPos(ID, InsertPos);
+  if (AT)
+return QualType(AT, 0);
+
+  QualType Canonical = getCanonicalType(Decayed);
+
+  // Get the new insert position for the node we care about.
+  AT = AdjustedTypes.FindNodeOrInsertPos(ID, InsertPos);
+  assert(!AT && "Shouldn't be in the map!");
+
+  AT = new (*this, TypeAlignment) DecayedType(Orig, Decayed, Canonical);
+  Types.push_back(AT);
+  AdjustedTypes.InsertNode(AT, InsertPos);
+  return QualType(AT, 0);
+}
+
 QualType ASTContext::getDecayedType(QualType T) const {
   assert((T->isArrayType() || T->isFunctionType()) && "T does not decay");
 
@@ -3352,23 +3372,7 @@ QualType ASTContext::getDecayedType(QualType T) const {
   if (T->isFunctionType())
 Decayed = getPointerType(T);
 
-  llvm::FoldingSetNodeID ID;
-  AdjustedType::Profile(ID, T, Decayed);
-  void *InsertPos = nullptr;
-  AdjustedType *AT = AdjustedTypes.FindNodeOrInsertPos(ID, InsertPos);
-  if (AT)
-return QualType(AT, 0);
-
-  QualType Canonical = getCanonicalType(Decayed);
-
-  // Get the new insert position for the node we care about.
-  AT = AdjustedTypes.FindNodeOrInsertPos(ID, InsertPos);
-  assert(!AT && "Shouldn't be in the map!");
-
-  AT = new (*this, TypeAlignment) DecayedType(T, Decayed, Canonical);
-  Types.push_back(AT);
-  AdjustedTypes.InsertNode(AT, InsertPos);
-  return QualType(AT, 0);
+  return getDecayedType(T, Decayed);
 }
 
 /// getBlockPointerType - Return the uniqued reference to the type for
@@ -12145,9 +12149,8 @@ unsigned ASTContext::getTargetAddressSpace(LangAS AS) 
const {
 // the regular ones.
 
 static Decl *getCommonDecl(Decl *X, Decl *Y) {
-  if (X == Y)
-return X;
-  assert(declaresSameEntity(X, Y));
+  if (!declaresSameEntity(X, Y))
+return nullptr;
   for (const Decl *DX : X->redecls()) {
 // If we reach Y before reaching the first decl, that means X is older.
 if (DX == Y)
@@ -12182,11 +12185,19 @@ static TemplateName getCommonTemplateName(ASTContext 
&Ctx, TemplateName X,
   //with more sugar. For example one could be a SubstTemplateTemplate*
   //replacing the other.
   TemplateName CX = Ctx.getCanonicalTemplateName(X);
-  assert(CX.getAsVoidPointer() ==
- Ctx.getCanonicalTemplateName(Y).getAsVoidPointer());
+  if (CX.getAsVoidPointer() !=
+  Ctx.getCanonicalTemplateName(Y).getAsVoidPointer())
+return TemplateName();
   return CX;
 }
 
+static TemplateName
+getCommonTemplateNameChecked(ASTContext &C

[clang-tools-extra] [clangd] Add test for GH75115 (PR #75116)

2023-12-11 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov created 
https://github.com/llvm/llvm-project/pull/75116

Add test for https://github.com/llvm/llvm-project/issues/75115

>From bd01b0d71c05fa7d728b6db08d14d51fe332ae2c Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Mon, 11 Dec 2023 17:36:44 -0300
Subject: [PATCH] [clangd] Add test for GH75115

Add test for https://github.com/llvm/llvm-project/issues/75115
---
 clang-tools-extra/clangd/test/GH75115.test | 12 
 1 file changed, 12 insertions(+)
 create mode 100644 clang-tools-extra/clangd/test/GH75115.test

diff --git a/clang-tools-extra/clangd/test/GH75115.test 
b/clang-tools-extra/clangd/test/GH75115.test
new file mode 100644
index 0..bf6870c714e64
--- /dev/null
+++ b/clang-tools-extra/clangd/test/GH75115.test
@@ -0,0 +1,12 @@
+// RUN: rm -rf %t.dir && mkdir -p %t.dir
+// RUN: echo '[{"directory": "%/t.dir", "command": "clang 
--target=x86_64-pc-windows-msvc -x c bug.test", "file": "bug.test"}]' > 
%t.dir/compile_commands.json
+// RUN: not clangd -enable-config=0 --compile-commands-dir=%t.dir -check=%s 
2>&1 | FileCheck -strict-whitespace %s
+
+// FIXME: Crashes
+
+// CHECK: Building preamble...
+// CHECK-NEXT: Built preamble
+// CHECK-NEXT: Indexing headers...
+// CHECK-NEXT: Assertion failed: !KeyInfoT::isEqual(Val, EmptyKey) && 
!KeyInfoT::isEqual(Val, TombstoneKey) && "Empty/Tombstone value shouldn't be 
inserted into map!"
+
+#define assert

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


[clang-tools-extra] [clangd] Add test for GH75115 (PR #75116)

2023-12-11 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov updated 
https://github.com/llvm/llvm-project/pull/75116

>From f3c8adf8b08369ba2e90e237957d4205526f64e1 Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Mon, 11 Dec 2023 17:36:44 -0300
Subject: [PATCH] [clangd] Add test for GH75115

Add test for https://github.com/llvm/llvm-project/issues/75115
---
 clang-tools-extra/clangd/test/GH75115.test | 12 
 1 file changed, 12 insertions(+)
 create mode 100644 clang-tools-extra/clangd/test/GH75115.test

diff --git a/clang-tools-extra/clangd/test/GH75115.test 
b/clang-tools-extra/clangd/test/GH75115.test
new file mode 100644
index 00..bae99cf0e456a8
--- /dev/null
+++ b/clang-tools-extra/clangd/test/GH75115.test
@@ -0,0 +1,12 @@
+// RUN: rm -rf %t.dir && mkdir -p %t.dir
+// RUN: echo '[{"directory": "%/t.dir", "command": "clang 
--target=x86_64-pc-windows-msvc -x c GH75115.test", "file": "GH75115.test"}]' > 
%t.dir/compile_commands.json
+// RUN: not clangd -enable-config=0 --compile-commands-dir=%t.dir -check=%s 
2>&1 | FileCheck -strict-whitespace %s
+
+// FIXME: Crashes
+
+// CHECK: Building preamble...
+// CHECK-NEXT: Built preamble
+// CHECK-NEXT: Indexing headers...
+// CHECK-NEXT: Assertion failed: !KeyInfoT::isEqual(Val, EmptyKey) && 
!KeyInfoT::isEqual(Val, TombstoneKey) && "Empty/Tombstone value shouldn't be 
inserted into map!"
+
+#define assert

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


[clang-tools-extra] [clangd] Add test for GH75115 (PR #75116)

2023-12-11 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov updated 
https://github.com/llvm/llvm-project/pull/75116

>From a3971a65e7c7297295a6db154360c205a254c708 Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Mon, 11 Dec 2023 17:36:44 -0300
Subject: [PATCH] [clangd] Add test for GH75115

Add test for https://github.com/llvm/llvm-project/issues/75115
---
 clang-tools-extra/clangd/test/GH75115.test | 12 
 1 file changed, 12 insertions(+)
 create mode 100644 clang-tools-extra/clangd/test/GH75115.test

diff --git a/clang-tools-extra/clangd/test/GH75115.test 
b/clang-tools-extra/clangd/test/GH75115.test
new file mode 100644
index 00..575524f88e728a
--- /dev/null
+++ b/clang-tools-extra/clangd/test/GH75115.test
@@ -0,0 +1,12 @@
+// RUN: rm -rf %t.dir && mkdir -p %t.dir
+// RUN: echo '[{"directory": "%/t.dir", "command": "clang 
--target=x86_64-pc-windows-msvc -x c GH75115.test", "file": "GH75115.test"}]' > 
%t.dir/compile_commands.json
+// RUN: not clangd -enable-config=0 --compile-commands-dir=%t.dir -check=%s 
2>&1 | FileCheck -strict-whitespace %s
+
+// FIXME: Crashes
+
+// CHECK: Building preamble...
+// CHECK-NEXT: Built preamble
+// CHECK-NEXT: Indexing headers...
+// CHECK-NEXT: !KeyInfoT::isEqual(Val, EmptyKey) && !KeyInfoT::isEqual(Val, 
TombstoneKey) && "Empty/Tombstone value shouldn't be inserted into map!"
+
+#define assert

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


[clang-tools-extra] [clangd] Add test for GH75115 (PR #75116)

2023-12-11 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov updated 
https://github.com/llvm/llvm-project/pull/75116

>From 7c18785d74556001cf19d9ae84c8f32f8d95801e Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Mon, 11 Dec 2023 17:36:44 -0300
Subject: [PATCH] [clangd] Add test for GH75115

Add test for https://github.com/llvm/llvm-project/issues/75115
---
 clang-tools-extra/clangd/test/GH75115.test | 12 
 1 file changed, 12 insertions(+)
 create mode 100644 clang-tools-extra/clangd/test/GH75115.test

diff --git a/clang-tools-extra/clangd/test/GH75115.test 
b/clang-tools-extra/clangd/test/GH75115.test
new file mode 100644
index 00..030392f1d69b30
--- /dev/null
+++ b/clang-tools-extra/clangd/test/GH75115.test
@@ -0,0 +1,12 @@
+// RUN: rm -rf %t.dir && mkdir -p %t.dir
+// RUN: echo '[{"directory": "%/t.dir", "command": "clang 
--target=x86_64-pc-windows-msvc -x c GH75115.test", "file": "GH75115.test"}]' > 
%t.dir/compile_commands.json
+// RUN: not --crash clangd -enable-config=0 --compile-commands-dir=%t.dir 
-check=%s 2>&1 | FileCheck -strict-whitespace %s
+
+// FIXME: Crashes
+
+// CHECK: Building preamble...
+// CHECK-NEXT: Built preamble
+// CHECK-NEXT: Indexing headers...
+// CHECK-NEXT: !KeyInfoT::isEqual(Val, EmptyKey) && !KeyInfoT::isEqual(Val, 
TombstoneKey) && "Empty/Tombstone value shouldn't be inserted into map!"
+
+#define assert

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


[clang-tools-extra] [clangd] Add test for GH75115 (PR #75116)

2023-12-12 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov updated 
https://github.com/llvm/llvm-project/pull/75116

>From 1c9690d87f3a3bbe8389cb9a852d00fe2d3cf478 Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Mon, 11 Dec 2023 17:36:44 -0300
Subject: [PATCH] [clangd] Add test for GH75115

Add test for https://github.com/llvm/llvm-project/issues/75115
---
 clang-tools-extra/clangd/test/GH75115.test | 12 
 1 file changed, 12 insertions(+)
 create mode 100644 clang-tools-extra/clangd/test/GH75115.test

diff --git a/clang-tools-extra/clangd/test/GH75115.test 
b/clang-tools-extra/clangd/test/GH75115.test
new file mode 100644
index 00..030392f1d69b30
--- /dev/null
+++ b/clang-tools-extra/clangd/test/GH75115.test
@@ -0,0 +1,12 @@
+// RUN: rm -rf %t.dir && mkdir -p %t.dir
+// RUN: echo '[{"directory": "%/t.dir", "command": "clang 
--target=x86_64-pc-windows-msvc -x c GH75115.test", "file": "GH75115.test"}]' > 
%t.dir/compile_commands.json
+// RUN: not --crash clangd -enable-config=0 --compile-commands-dir=%t.dir 
-check=%s 2>&1 | FileCheck -strict-whitespace %s
+
+// FIXME: Crashes
+
+// CHECK: Building preamble...
+// CHECK-NEXT: Built preamble
+// CHECK-NEXT: Indexing headers...
+// CHECK-NEXT: !KeyInfoT::isEqual(Val, EmptyKey) && !KeyInfoT::isEqual(Val, 
TombstoneKey) && "Empty/Tombstone value shouldn't be inserted into map!"
+
+#define assert

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


[clang-tools-extra] [clangd] Add test for GH75115 (PR #75116)

2023-12-12 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov closed 
https://github.com/llvm/llvm-project/pull/75116
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clangd] check for synthesized symbols when tracking include locations (PR #75128)

2023-12-12 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov edited 
https://github.com/llvm/llvm-project/pull/75128
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clangd] check for synthesized symbols when tracking include locations (PR #75128)

2023-12-12 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov updated 
https://github.com/llvm/llvm-project/pull/75128

>From 6f4cc2d6a9af855a12feb03bd81cbc6f7cbf9caf Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Wed, 13 Dec 2023 01:44:16 -0300
Subject: [PATCH] [clangd] check for synthesized symbols when tracking include
 locations

This fixes https://github.com/llvm/llvm-project/issues/75115

In C mode with MSVC compatibility, when the `assert` macro is defined,
as a workaround, `static_assert` is implicitly defined as well,
if not already so, in order to work around a broken `assert.h`
implementation.
This workaround was implemented in 
https://github.com/llvm/llvm-project/commit/8da090381d567d0ec555840f6b2a651d2997e4b3

A synthesized symbol does not occur in source code, and therefore
should not have valid source location, but this was not checked when
inserting this into a `symbol -> include file` map.

The invalid FileID value is used for empty key representation in
the include file hash table, so it's not valid to insert it.
---
 clang-tools-extra/clangd/index/SymbolCollector.cpp |  8 
 clang-tools-extra/clangd/test/GH75115.test | 11 +++
 2 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/clang-tools-extra/clangd/index/SymbolCollector.cpp 
b/clang-tools-extra/clangd/index/SymbolCollector.cpp
index aac6676a995fe..5d995cdae6d66 100644
--- a/clang-tools-extra/clangd/index/SymbolCollector.cpp
+++ b/clang-tools-extra/clangd/index/SymbolCollector.cpp
@@ -821,7 +821,8 @@ void SymbolCollector::setIncludeLocation(const Symbol &S, 
SourceLocation DefLoc,
 
   // Use the expansion location to get the #include header since this is
   // where the symbol is exposed.
-  IncludeFiles[S.ID] = SM.getDecomposedExpansionLoc(DefLoc).first;
+  if (FileID FID = SM.getDecomposedExpansionLoc(DefLoc).first; FID.isValid())
+IncludeFiles[S.ID] = FID;
 
   // We update providers for a symbol with each occurence, as SymbolCollector
   // might run while parsing, rather than at the end of a translation unit.
@@ -893,16 +894,15 @@ void SymbolCollector::finish() {
 const Symbol *S = Symbols.find(SID);
 if (!S)
   continue;
-assert(IncludeFiles.contains(SID));
 
-const auto FID = IncludeFiles.at(SID);
+FileID FID = IncludeFiles.lookup(SID);
 // Determine if the FID is #include'd or #import'ed.
 Symbol::IncludeDirective Directives = Symbol::Invalid;
 auto CollectDirectives = shouldCollectIncludePath(S->SymInfo.Kind);
 if ((CollectDirectives & Symbol::Include) != 0)
   Directives |= Symbol::Include;
 // Only allow #import for symbols from ObjC-like files.
-if ((CollectDirectives & Symbol::Import) != 0) {
+if ((CollectDirectives & Symbol::Import) != 0 && FID.isValid()) {
   auto [It, Inserted] = FileToContainsImportsOrObjC.try_emplace(FID);
   if (Inserted)
 It->second = FilesWithObjCConstructs.contains(FID) ||
diff --git a/clang-tools-extra/clangd/test/GH75115.test 
b/clang-tools-extra/clangd/test/GH75115.test
index 030392f1d69b3..dc86f5b9a6cee 100644
--- a/clang-tools-extra/clangd/test/GH75115.test
+++ b/clang-tools-extra/clangd/test/GH75115.test
@@ -1,12 +1,15 @@
 // RUN: rm -rf %t.dir && mkdir -p %t.dir
 // RUN: echo '[{"directory": "%/t.dir", "command": "clang 
--target=x86_64-pc-windows-msvc -x c GH75115.test", "file": "GH75115.test"}]' > 
%t.dir/compile_commands.json
-// RUN: not --crash clangd -enable-config=0 --compile-commands-dir=%t.dir 
-check=%s 2>&1 | FileCheck -strict-whitespace %s
-
-// FIXME: Crashes
+// RUN: clangd -enable-config=0 --compile-commands-dir=%t.dir -check=%s 2>&1 | 
FileCheck -strict-whitespace %s
 
 // CHECK: Building preamble...
 // CHECK-NEXT: Built preamble
 // CHECK-NEXT: Indexing headers...
-// CHECK-NEXT: !KeyInfoT::isEqual(Val, EmptyKey) && !KeyInfoT::isEqual(Val, 
TombstoneKey) && "Empty/Tombstone value shouldn't be inserted into map!"
+// CHECK-NEXT: Building AST...
+// CHECK-NEXT: Indexing AST...
+// CHECK-NEXT: Building inlay hints
+// CHECK-NEXT: semantic highlighting
+// CHECK-NEXT: Testing features at each token
+// CHECK-NEXT: All checks completed, 0 errors
 
 #define assert

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


[clang-tools-extra] [clangd] Add test for GH75115 (PR #75116)

2023-12-13 Thread Matheus Izvekov via cfe-commits

mizvekov wrote:

I see, thanks for pointing it out.

I wonder if we support, or otherwise if we should support, a lit requires 
marker for this.

https://github.com/llvm/llvm-project/pull/75116
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clangd] check for synthesized symbols when tracking include locations (PR #75128)

2023-12-13 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov updated 
https://github.com/llvm/llvm-project/pull/75128

>From 8b5fa481b399cc49dcdc39c49ed22c7aed0cb844 Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Mon, 11 Dec 2023 17:36:44 -0300
Subject: [PATCH 1/2] [clangd] Add test for GH75115

Add test for https://github.com/llvm/llvm-project/issues/75115
---
 clang-tools-extra/clangd/test/GH75115.test | 12 
 1 file changed, 12 insertions(+)
 create mode 100644 clang-tools-extra/clangd/test/GH75115.test

diff --git a/clang-tools-extra/clangd/test/GH75115.test 
b/clang-tools-extra/clangd/test/GH75115.test
new file mode 100644
index 00..030392f1d69b30
--- /dev/null
+++ b/clang-tools-extra/clangd/test/GH75115.test
@@ -0,0 +1,12 @@
+// RUN: rm -rf %t.dir && mkdir -p %t.dir
+// RUN: echo '[{"directory": "%/t.dir", "command": "clang 
--target=x86_64-pc-windows-msvc -x c GH75115.test", "file": "GH75115.test"}]' > 
%t.dir/compile_commands.json
+// RUN: not --crash clangd -enable-config=0 --compile-commands-dir=%t.dir 
-check=%s 2>&1 | FileCheck -strict-whitespace %s
+
+// FIXME: Crashes
+
+// CHECK: Building preamble...
+// CHECK-NEXT: Built preamble
+// CHECK-NEXT: Indexing headers...
+// CHECK-NEXT: !KeyInfoT::isEqual(Val, EmptyKey) && !KeyInfoT::isEqual(Val, 
TombstoneKey) && "Empty/Tombstone value shouldn't be inserted into map!"
+
+#define assert

>From 25bc82590687582ecc6e45614c7dd5a15b89ac08 Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Wed, 13 Dec 2023 01:44:16 -0300
Subject: [PATCH 2/2] [clangd] check for synthesized symbols when tracking
 include locations

This fixes https://github.com/llvm/llvm-project/issues/75115

In C mode with MSVC compatibility, when the `assert` macro is defined,
as a workaround, `static_assert` is implicitly defined as well,
if not already so, in order to work around a broken `assert.h`
implementation.
This workaround was implemented in 
https://github.com/llvm/llvm-project/commit/8da090381d567d0ec555840f6b2a651d2997e4b3

A synthesized symbol does not occur in source code, and therefore
should not have valid source location, but this was not checked when
inserting this into a `symbol -> include file` map.

The invalid FileID value is used for empty key representation in
the include file hash table, so it's not valid to insert it.
---
 clang-tools-extra/clangd/index/SymbolCollector.cpp |  8 
 clang-tools-extra/clangd/test/GH75115.test | 11 +++
 2 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/clang-tools-extra/clangd/index/SymbolCollector.cpp 
b/clang-tools-extra/clangd/index/SymbolCollector.cpp
index aac6676a995fed..5d995cdae6d665 100644
--- a/clang-tools-extra/clangd/index/SymbolCollector.cpp
+++ b/clang-tools-extra/clangd/index/SymbolCollector.cpp
@@ -821,7 +821,8 @@ void SymbolCollector::setIncludeLocation(const Symbol &S, 
SourceLocation DefLoc,
 
   // Use the expansion location to get the #include header since this is
   // where the symbol is exposed.
-  IncludeFiles[S.ID] = SM.getDecomposedExpansionLoc(DefLoc).first;
+  if (FileID FID = SM.getDecomposedExpansionLoc(DefLoc).first; FID.isValid())
+IncludeFiles[S.ID] = FID;
 
   // We update providers for a symbol with each occurence, as SymbolCollector
   // might run while parsing, rather than at the end of a translation unit.
@@ -893,16 +894,15 @@ void SymbolCollector::finish() {
 const Symbol *S = Symbols.find(SID);
 if (!S)
   continue;
-assert(IncludeFiles.contains(SID));
 
-const auto FID = IncludeFiles.at(SID);
+FileID FID = IncludeFiles.lookup(SID);
 // Determine if the FID is #include'd or #import'ed.
 Symbol::IncludeDirective Directives = Symbol::Invalid;
 auto CollectDirectives = shouldCollectIncludePath(S->SymInfo.Kind);
 if ((CollectDirectives & Symbol::Include) != 0)
   Directives |= Symbol::Include;
 // Only allow #import for symbols from ObjC-like files.
-if ((CollectDirectives & Symbol::Import) != 0) {
+if ((CollectDirectives & Symbol::Import) != 0 && FID.isValid()) {
   auto [It, Inserted] = FileToContainsImportsOrObjC.try_emplace(FID);
   if (Inserted)
 It->second = FilesWithObjCConstructs.contains(FID) ||
diff --git a/clang-tools-extra/clangd/test/GH75115.test 
b/clang-tools-extra/clangd/test/GH75115.test
index 030392f1d69b30..dc86f5b9a6cee0 100644
--- a/clang-tools-extra/clangd/test/GH75115.test
+++ b/clang-tools-extra/clangd/test/GH75115.test
@@ -1,12 +1,15 @@
 // RUN: rm -rf %t.dir && mkdir -p %t.dir
 // RUN: echo '[{"directory": "%/t.dir", "command": "clang 
--target=x86_64-pc-windows-msvc -x c GH75115.test", "file": "GH75115.test"}]' > 
%t.dir/compile_commands.json
-// RUN: not --crash clangd -enable-config=0 --compile-commands-dir=%t.dir 
-check=%s 2>&1 | FileCheck -strict-whitespace %s
-
-// FIXME: Crashes
+// RUN: clangd -enable-config=0 --compile-commands-dir=%t.dir -check=%s 2>&1 | 
FileCheck -strict-whitespace %s
 
 // CHECK: Building preamble...
 // CHECK-NEXT: Built pr

[clang-tools-extra] [clangd] check for synthesized symbols when tracking include locations (PR #75128)

2023-12-18 Thread Matheus Izvekov via cfe-commits

mizvekov wrote:

@kadircet ping

https://github.com/llvm/llvm-project/pull/75128
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clangd] check for synthesized symbols when tracking include locations (PR #75128)

2023-12-27 Thread Matheus Izvekov via cfe-commits

mizvekov wrote:

@kadircet gentle ping

https://github.com/llvm/llvm-project/pull/75128
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clangd] check for synthesized symbols when tracking include locations (PR #75128)

2024-01-03 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov closed 
https://github.com/llvm/llvm-project/pull/75128
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 1d1a569 - Clang: fix AST representation of expanded template arguments.

2022-08-09 Thread Matheus Izvekov via cfe-commits

Author: Matheus Izvekov
Date: 2022-08-09T14:26:16+02:00
New Revision: 1d1a56929b725f9a79d98877f12d0a14f8418b38

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

LOG: Clang: fix AST representation of expanded template arguments.

Extend clang's SubstTemplateTypeParm to represent the pack substitution index.

Fixes PR56099.

Signed-off-by: Matheus Izvekov 

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

Added: 


Modified: 
clang/include/clang/AST/ASTContext.h
clang/include/clang/AST/JSONNodeDumper.h
clang/include/clang/AST/TextNodeDumper.h
clang/include/clang/AST/Type.h
clang/include/clang/AST/TypeProperties.td
clang/lib/AST/ASTContext.cpp
clang/lib/AST/ASTImporter.cpp
clang/lib/AST/ASTStructuralEquivalence.cpp
clang/lib/AST/JSONNodeDumper.cpp
clang/lib/AST/TextNodeDumper.cpp
clang/lib/AST/Type.cpp
clang/lib/Sema/SemaTemplateInstantiate.cpp
clang/lib/Sema/TreeTransform.h
clang/test/AST/ast-dump-template-decls.cpp
clang/unittests/AST/ASTImporterTest.cpp

Removed: 




diff  --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index d27b978998095..a01a6aa4bd7e4 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -1614,7 +1614,8 @@ class ASTContext : public RefCountedBase {
QualType Wrapped);
 
   QualType getSubstTemplateTypeParmType(const TemplateTypeParmType *Replaced,
-QualType Replacement) const;
+QualType Replacement,
+Optional PackIndex) const;
   QualType getSubstTemplateTypeParmPackType(
   const TemplateTypeParmType *Replaced,
 const TemplateArgument &ArgPack);

diff  --git a/clang/include/clang/AST/JSONNodeDumper.h 
b/clang/include/clang/AST/JSONNodeDumper.h
index a5575d7fd441e..3597903695797 100644
--- a/clang/include/clang/AST/JSONNodeDumper.h
+++ b/clang/include/clang/AST/JSONNodeDumper.h
@@ -220,6 +220,7 @@ class JSONNodeDumper
   void VisitUnaryTransformType(const UnaryTransformType *UTT);
   void VisitTagType(const TagType *TT);
   void VisitTemplateTypeParmType(const TemplateTypeParmType *TTPT);
+  void VisitSubstTemplateTypeParmType(const SubstTemplateTypeParmType *STTPT);
   void VisitAutoType(const AutoType *AT);
   void VisitTemplateSpecializationType(const TemplateSpecializationType *TST);
   void VisitInjectedClassNameType(const InjectedClassNameType *ICNT);

diff  --git a/clang/include/clang/AST/TextNodeDumper.h 
b/clang/include/clang/AST/TextNodeDumper.h
index 2e4bcdd27a8ab..e6853b12ae7e5 100644
--- a/clang/include/clang/AST/TextNodeDumper.h
+++ b/clang/include/clang/AST/TextNodeDumper.h
@@ -317,6 +317,7 @@ class TextNodeDumper
   void VisitUnaryTransformType(const UnaryTransformType *T);
   void VisitTagType(const TagType *T);
   void VisitTemplateTypeParmType(const TemplateTypeParmType *T);
+  void VisitSubstTemplateTypeParmType(const SubstTemplateTypeParmType *T);
   void VisitAutoType(const AutoType *T);
   void VisitDeducedTemplateSpecializationType(
   const DeducedTemplateSpecializationType *T);

diff  --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 1a8cf27dab4bd..ad9835e839a65 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -1790,6 +1790,18 @@ class alignas(8) Type : public ExtQualsTypeCommonBase {
 unsigned NumArgs;
   };
 
+  class SubstTemplateTypeParmTypeBitfields {
+friend class SubstTemplateTypeParmType;
+
+unsigned : NumTypeBits;
+
+/// Represents the index within a pack if this represents a substitution
+/// from a pack expansion.
+/// Positive non-zero number represents the index + 1.
+/// Zero means this is not substituted from an expansion.
+unsigned PackIndex;
+  };
+
   class SubstTemplateTypeParmPackTypeBitfields {
 friend class SubstTemplateTypeParmPackType;
 
@@ -1872,6 +1884,7 @@ class alignas(8) Type : public ExtQualsTypeCommonBase {
 ElaboratedTypeBitfields ElaboratedTypeBits;
 VectorTypeBitfields VectorTypeBits;
 SubstTemplateTypeParmPackTypeBitfields SubstTemplateTypeParmPackTypeBits;
+SubstTemplateTypeParmTypeBitfields SubstTemplateTypeParmTypeBits;
 TemplateSpecializationTypeBitfields TemplateSpecializationTypeBits;
 DependentTemplateSpecializationTypeBitfields
   DependentTemplateSpecializationTypeBits;
@@ -4974,9 +4987,12 @@ class SubstTemplateTypeParmType : public Type, public 
llvm::FoldingSetNode {
   // The original type parameter.
   const TemplateTypeParmType *Replaced;
 
-  SubstTemplateTypeParmType(const Templ

[clang] 1d68eca - [clang] fix oops: enable implicit moves in MSVC compatibility mode

2021-07-20 Thread Matheus Izvekov via cfe-commits

Author: Matheus Izvekov
Date: 2021-07-20T23:32:05+02:00
New Revision: 1d68ecafd6ad9ba8857c78e567abbc58810329c1

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

LOG: [clang] fix oops: enable implicit moves in MSVC compatibility mode

When disabling simpler implicit moves in MSVC compatibility mode as
a workaround in D105518, we forgot to make the opposite change and
enable regular (P1825) implicit moves in the same mode.

As a result, we were not doing any implicit moves at all. OOPS!

This fixes it and adds test for this.

This is a fix to a temporary workaround, there is ongoing
work to replace this, applying the workaround only to
system headers and the ::stl namespace.

Signed-off-by: Matheus Izvekov 

Reviewed By: aaron.ballman

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

Added: 


Modified: 
clang/lib/Sema/SemaStmt.cpp
clang/test/SemaCXX/cxx2b-p2266-disable-with-msvc-compat.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index 643dde437fc94..2ae27de9b2079 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -3483,7 +3483,12 @@ ExprResult
 Sema::PerformMoveOrCopyInitialization(const InitializedEntity &Entity,
   const NamedReturnInfo &NRInfo,
   Expr *Value) {
-  if (!getLangOpts().CPlusPlus2b && NRInfo.isMoveEligible()) {
+  // FIXME: We force P1825 implicit moves here in msvc compatibility mode
+  // because we are disabling simpler implicit moves as a temporary
+  // work around, as the MSVC STL has issues with this change.
+  // We will come back later with a more targeted approach.
+  if ((!getLangOpts().CPlusPlus2b || getLangOpts().MSVCCompat) &&
+  NRInfo.isMoveEligible()) {
 ImplicitCastExpr AsRvalue(ImplicitCastExpr::OnStack, Value->getType(),
   CK_NoOp, Value, VK_XValue, FPOptionsOverride());
 Expr *InitExpr = &AsRvalue;

diff  --git a/clang/test/SemaCXX/cxx2b-p2266-disable-with-msvc-compat.cpp 
b/clang/test/SemaCXX/cxx2b-p2266-disable-with-msvc-compat.cpp
index 2143c0535e606..07db9b8333fa6 100644
--- a/clang/test/SemaCXX/cxx2b-p2266-disable-with-msvc-compat.cpp
+++ b/clang/test/SemaCXX/cxx2b-p2266-disable-with-msvc-compat.cpp
@@ -48,3 +48,5 @@ void test5() try {
   throw x; // new-error {{no matching constructor for initialization}}
 } catch (...) {
 }
+
+MoveOnly test6(MoveOnly x) { return x; }



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


[clang] 20555a1 - [clang] P2266 implicit moves STL workaround

2021-07-26 Thread Matheus Izvekov via cfe-commits

Author: Matheus Izvekov
Date: 2021-07-26T22:21:31+02:00
New Revision: 20555a15a596012ef827e29b665db53a4fc0b86c

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

LOG: [clang] P2266 implicit moves STL workaround

This patch replaces the workaround for simpler implicit moves
implemented in D105518.

The Microsoft STL currently has some issues with P2266.

Where before, with -fms-compatibility, we would disable simpler
implicit moves globally, with this change, we disable it only
when the returned expression is in a context contained by
std namespace and is located within a system header.

Signed-off-by: Matheus Izvekov 

Reviewed By: aaron.ballman, mibintc

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

Added: 


Modified: 
clang/include/clang/Sema/Sema.h
clang/lib/Frontend/InitPreprocessor.cpp
clang/lib/Sema/SemaCoroutine.cpp
clang/lib/Sema/SemaStmt.cpp
clang/test/SemaCXX/cxx2b-p2266-disable-with-msvc-compat.cpp

Removed: 




diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 013722cfbe1e5..83a2d132bf6a4 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -4785,20 +4785,24 @@ class Sema final {
 bool isMoveEligible() const { return S != None; };
 bool isCopyElidable() const { return S == MoveEligibleAndCopyElidable; }
   };
-  NamedReturnInfo getNamedReturnInfo(Expr *&E, bool ForceCXX2b = false);
+  enum class SimplerImplicitMoveMode { ForceOff, Normal, ForceOn };
+  NamedReturnInfo getNamedReturnInfo(
+  Expr *&E, SimplerImplicitMoveMode Mode = 
SimplerImplicitMoveMode::Normal);
   NamedReturnInfo getNamedReturnInfo(const VarDecl *VD);
   const VarDecl *getCopyElisionCandidate(NamedReturnInfo &Info,
  QualType ReturnType);
 
-  ExprResult PerformMoveOrCopyInitialization(const InitializedEntity &Entity,
- const NamedReturnInfo &NRInfo,
- Expr *Value);
+  ExprResult
+  PerformMoveOrCopyInitialization(const InitializedEntity &Entity,
+  const NamedReturnInfo &NRInfo, Expr *Value,
+  bool SupressSimplerImplicitMoves = false);
 
   StmtResult ActOnReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp,
  Scope *CurScope);
   StmtResult BuildReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp);
   StmtResult ActOnCapScopeReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp,
- NamedReturnInfo &NRInfo);
+ NamedReturnInfo &NRInfo,
+ bool SupressSimplerImplicitMoves);
 
   StmtResult ActOnGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
  bool IsVolatile, unsigned NumOutputs,

diff  --git a/clang/lib/Frontend/InitPreprocessor.cpp 
b/clang/lib/Frontend/InitPreprocessor.cpp
index 676421552a757..bca0bb4ada672 100644
--- a/clang/lib/Frontend/InitPreprocessor.cpp
+++ b/clang/lib/Frontend/InitPreprocessor.cpp
@@ -598,8 +598,7 @@ static void InitializeCPlusPlusFeatureTestMacros(const 
LangOptions &LangOpts,
   }
   // C++2b features.
   if (LangOpts.CPlusPlus2b) {
-if (!LangOpts.MSVCCompat)
-  Builder.defineMacro("__cpp_implicit_move", "202011L");
+Builder.defineMacro("__cpp_implicit_move", "202011L");
 Builder.defineMacro("__cpp_size_t_suffix", "202011L");
   }
   if (LangOpts.Char8)

diff  --git a/clang/lib/Sema/SemaCoroutine.cpp 
b/clang/lib/Sema/SemaCoroutine.cpp
index 31a4092b5b604..098fe618865fa 100644
--- a/clang/lib/Sema/SemaCoroutine.cpp
+++ b/clang/lib/Sema/SemaCoroutine.cpp
@@ -977,7 +977,7 @@ StmtResult Sema::BuildCoreturnStmt(SourceLocation Loc, Expr 
*E,
   VarDecl *Promise = FSI->CoroutinePromise;
   ExprResult PC;
   if (E && (isa(E) || !E->getType()->isVoidType())) {
-getNamedReturnInfo(E, /*ForceCXX2b=*/true);
+getNamedReturnInfo(E, SimplerImplicitMoveMode::ForceOn);
 PC = buildPromiseCall(*this, Promise, Loc, "return_value", E);
   } else {
 E = MakeFullDiscardedValueExpr(E).get();

diff  --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index 64c53df0b..3baccec2d7bb4 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -3322,7 +3322,8 @@ Sema::ActOnBreakStmt(SourceLocation BreakLoc, Scope 
*CurScope) {
 /// \returns An aggregate which contains the Candidate and isMoveEligible
 /// and isCopyElidable methods. If Candidate is non-null, it means
 /// isMoveEligible() would be true under the most permissive language standard.
-Sema::NamedReturnInfo Sema::getNamedReturnInfo(Expr *&E, bool ForceCXX2b) {
+Sema::NamedReturnInfo Sema::getNamedReturnInfo(E

[clang] 4819b75 - [clang] NFC: change uses of `Expr->getValueKind` into `is?Value`

2021-07-27 Thread Matheus Izvekov via cfe-commits

Author: Matheus Izvekov
Date: 2021-07-28T03:09:31+02:00
New Revision: 4819b751bd875f458eb0060f7c586aa9ac41965c

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

LOG: [clang] NFC: change uses of `Expr->getValueKind` into `is?Value`

Signed-off-by: Matheus Izvekov 

Reviewed By: rsmith

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

Added: 


Modified: 
clang/include/clang/AST/ExprCXX.h
clang/lib/AST/Expr.cpp
clang/lib/AST/ExprClassification.cpp
clang/lib/CodeGen/CGDecl.cpp
clang/lib/CodeGen/CGExprScalar.cpp
clang/lib/Sema/Sema.cpp
clang/lib/Sema/SemaCoroutine.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/lib/Sema/SemaInit.cpp

Removed: 




diff  --git a/clang/include/clang/AST/ExprCXX.h 
b/clang/include/clang/AST/ExprCXX.h
index 2626f9b925962..161287adce4ca 100644
--- a/clang/include/clang/AST/ExprCXX.h
+++ b/clang/include/clang/AST/ExprCXX.h
@@ -4528,9 +4528,7 @@ class MaterializeTemporaryExpr : public Expr {
 
   /// Determine whether this materialized temporary is bound to an
   /// lvalue reference; otherwise, it's bound to an rvalue reference.
-  bool isBoundToLvalueReference() const {
-return getValueKind() == VK_LValue;
-  }
+  bool isBoundToLvalueReference() const { return isLValue(); }
 
   /// Determine whether this temporary object is usable in constant
   /// expressions, as specified in C++20 [expr.const]p4.

diff  --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index ebf87618e1277..e8b4aaa2b81e6 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -2406,7 +2406,7 @@ bool Expr::isReadIfDiscardedInCPlusPlus11() const {
   // In C++11, discarded-value expressions of a certain form are special,
   // according to [expr]p10:
   //   The lvalue-to-rvalue conversion (4.1) is applied only if the
-  //   expression is an lvalue of volatile-qualified type and it has
+  //   expression is a glvalue of volatile-qualified type and it has
   //   one of the following forms:
   if (!isGLValue() || !getType().isVolatileQualified())
 return false;
@@ -3874,8 +3874,7 @@ Expr::isNullPointerConstant(ASTContext &Ctx,
 const ObjCPropertyRefExpr *Expr::getObjCProperty() const {
   const Expr *E = this;
   while (true) {
-assert((E->getValueKind() == VK_LValue &&
-E->getObjectKind() == OK_ObjCProperty) &&
+assert((E->isLValue() && E->getObjectKind() == OK_ObjCProperty) &&
"expression is not a property reference");
 E = E->IgnoreParenCasts();
 if (const BinaryOperator *BO = dyn_cast(E)) {
@@ -3914,7 +3913,7 @@ FieldDecl *Expr::getSourceBitField() {
 
   while (ImplicitCastExpr *ICE = dyn_cast(E)) {
 if (ICE->getCastKind() == CK_LValueToRValue ||
-(ICE->getValueKind() != VK_PRValue && ICE->getCastKind() == CK_NoOp))
+(ICE->isGLValue() && ICE->getCastKind() == CK_NoOp))
   E = ICE->getSubExpr()->IgnoreParens();
 else
   break;
@@ -3961,7 +3960,7 @@ bool Expr::refersToVectorElement() const {
   const Expr *E = this->IgnoreParens();
 
   while (const ImplicitCastExpr *ICE = dyn_cast(E)) {
-if (ICE->getValueKind() != VK_PRValue && ICE->getCastKind() == CK_NoOp)
+if (ICE->isGLValue() && ICE->getCastKind() == CK_NoOp)
   E = ICE->getSubExpr()->IgnoreParens();
 else
   break;

diff  --git a/clang/lib/AST/ExprClassification.cpp 
b/clang/lib/AST/ExprClassification.cpp
index 07fb44ceef2a4..6998e28fd2ea8 100644
--- a/clang/lib/AST/ExprClassification.cpp
+++ b/clang/lib/AST/ExprClassification.cpp
@@ -53,8 +53,12 @@ Cl Expr::ClassifyImpl(ASTContext &Ctx, SourceLocation *Loc) 
const {
 
   // Enable this assertion for testing.
   switch (kind) {
-  case Cl::CL_LValue: assert(getValueKind() == VK_LValue); break;
-  case Cl::CL_XValue: assert(getValueKind() == VK_XValue); break;
+  case Cl::CL_LValue:
+assert(isLValue());
+break;
+  case Cl::CL_XValue:
+assert(isXValue());
+break;
   case Cl::CL_Function:
   case Cl::CL_Void:
   case Cl::CL_AddressableVoid:
@@ -65,7 +69,7 @@ Cl Expr::ClassifyImpl(ASTContext &Ctx, SourceLocation *Loc) 
const {
   case Cl::CL_ArrayTemporary:
   case Cl::CL_ObjCMessageRValue:
   case Cl::CL_PRValue:
-assert(getValueKind() == VK_PRValue);
+assert(isPRValue());
 break;
   }
 

diff  --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp
index de9f3f6f899c6..5b3d39f20b416 100644
--- a/clang/lib/CodeGen/CGDecl.cpp
+++ b/clang/lib/CodeGen/CGDecl.cpp
@@ -714,10 +714,10 @@ static bool tryEmitARCCopyWeakInit(CodeGenFunction &CGF,
   }
 
   // If it was an l-value, use objc_copyWeak.
-  if (srcExpr->getValueKind() == VK_LValue) {
+  if (srcExpr->isLValue()) {
 CGF.EmitARCCopyWeak(destLV.getAddress(CGF), srcAddr);
   } else {
- 

[clang] 0c7cd4a - [clang] NFC: refactor multiple implementations of getDecltypeForParenthesizedExpr

2021-07-28 Thread Matheus Izvekov via cfe-commits

Author: Matheus Izvekov
Date: 2021-07-28T23:27:43+02:00
New Revision: 0c7cd4a873138f2116403a733274c8cb7dbf925f

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

LOG: [clang] NFC: refactor multiple implementations of 
getDecltypeForParenthesizedExpr

This cleanup patch refactors a bunch of functional duplicates of
getDecltypeForParenthesizedExpr into a common implementation.

Signed-off-by: Matheus Izvekov 

Reviewed By: aaronpuchert

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

Added: 


Modified: 
clang/include/clang/AST/ASTContext.h
clang/include/clang/Sema/Sema.h
clang/lib/AST/ASTContext.cpp
clang/lib/AST/ExprObjC.cpp
clang/lib/Sema/SemaConcept.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/lib/Sema/SemaType.cpp
clang/lib/StaticAnalyzer/Core/CallEvent.cpp

Removed: 




diff  --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index 34299581d89d4..da372e854700b 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -1631,6 +1631,8 @@ class ASTContext : public RefCountedBase {
   QualType getTypeOfExprType(Expr *e) const;
   QualType getTypeOfType(QualType t) const;
 
+  QualType getReferenceQualifiedType(const Expr *e) const;
+
   /// C++11 decltype.
   QualType getDecltypeType(Expr *e, QualType UnderlyingType) const;
 

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 375b650b8ecb3..1a696b4938061 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -2330,7 +2330,6 @@ class Sema final {
  const CXXScopeSpec &SS, QualType T,
  TagDecl *OwnedTagDecl = nullptr);
 
-  QualType getDecltypeForParenthesizedExpr(Expr *E);
   QualType BuildTypeofExprType(Expr *E, SourceLocation Loc);
   /// If AsUnevaluated is false, E is treated as though it were an evaluated
   /// context, such as when building a type for decltype(auto).

diff  --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index e102a3ba508d4..4c16ddc782fa9 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -5454,6 +5454,29 @@ QualType ASTContext::getTypeOfType(QualType tofType) 
const {
   return QualType(tot, 0);
 }
 
+/// getReferenceQualifiedType - Given an expr, will return the type for
+/// that expression, as in [dcl.type.simple]p4 but without taking 
id-expressions
+/// and class member access into account.
+QualType ASTContext::getReferenceQualifiedType(const Expr *E) const {
+  // C++11 [dcl.type.simple]p4:
+  //   [...]
+  QualType T = E->getType();
+  switch (E->getValueKind()) {
+  // - otherwise, if e is an xvalue, decltype(e) is T&&, where T is the
+  //   type of e;
+  case VK_XValue:
+return getRValueReferenceType(T);
+  // - otherwise, if e is an lvalue, decltype(e) is T&, where T is the
+  //   type of e;
+  case VK_LValue:
+return getLValueReferenceType(T);
+  //  - otherwise, decltype(e) is the type of e.
+  case VK_PRValue:
+return T;
+  }
+  llvm_unreachable("Unknown value kind");
+}
+
 /// Unlike many "get" functions, we don't unique DecltypeType
 /// nodes. This would never be helpful, since each such type has its own
 /// expression, and would not give a significant memory saving, since there

diff  --git a/clang/lib/AST/ExprObjC.cpp b/clang/lib/AST/ExprObjC.cpp
index 7d932c8b059da..a3222c2da24fd 100644
--- a/clang/lib/AST/ExprObjC.cpp
+++ b/clang/lib/AST/ExprObjC.cpp
@@ -271,20 +271,7 @@ QualType ObjCMessageExpr::getCallReturnType(ASTContext 
&Ctx) const {
 }
 return QT;
   }
-
-  // Expression type might be 
diff erent from an expected call return type,
-  // as expression type would never be a reference even if call returns a
-  // reference. Reconstruct the original expression type.
-  QualType QT = getType();
-  switch (getValueKind()) {
-  case VK_LValue:
-return Ctx.getLValueReferenceType(QT);
-  case VK_XValue:
-return Ctx.getRValueReferenceType(QT);
-  case VK_PRValue:
-return QT;
-  }
-  llvm_unreachable("Unsupported ExprValueKind");
+  return Ctx.getReferenceQualifiedType(this);
 }
 
 SourceRange ObjCMessageExpr::getReceiverRange() const {

diff  --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp
index f2c70d0a56efb..30f0730671c0a 100644
--- a/clang/lib/Sema/SemaConcept.cpp
+++ b/clang/lib/Sema/SemaConcept.cpp
@@ -461,7 +461,7 @@ static void diagnoseUnsatisfiedRequirement(Sema &S,
 Expr *e = Req->getExpr();
 S.Diag(e->getBeginLoc(),
diag::note_expr_requirement_constraints_not_satisfied_simple)
-<< (int)First << S.getDecltypeForParenthesizedExpr(e)
+<< (int)Firs

[clang] 87aa318 - [clang] fix concepts crash on substitution failure during normalization

2021-07-28 Thread Matheus Izvekov via cfe-commits

Author: Matheus Izvekov
Date: 2021-07-28T23:28:45+02:00
New Revision: 87aa31827b293127619e2ef96e80baf709eae338

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

LOG: [clang] fix concepts crash on substitution failure during normalization

When substitution failed on the first constrained template argument (but
only the first), we would assert / crash. Checking for failure was only
being performed from the second constraint on.

This changes it so the checking is performed in that case,
and the code is also now simplified a little bit to hopefully
avoid this confusion.

Signed-off-by: Matheus Izvekov 

Reviewed By: rsmith

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

Added: 


Modified: 
clang/lib/Sema/SemaConcept.cpp
clang/test/CXX/temp/temp.constr/temp.constr.normal/p1.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp
index 30f0730671c0a..82443be09c062 100644
--- a/clang/lib/Sema/SemaConcept.cpp
+++ b/clang/lib/Sema/SemaConcept.cpp
@@ -742,22 +742,15 @@ Optional
 NormalizedConstraint::fromConstraintExprs(Sema &S, NamedDecl *D,
   ArrayRef E) {
   assert(E.size() != 0);
-  auto First = fromConstraintExpr(S, D, E[0]);
-  if (E.size() == 1)
-return First;
-  auto Second = fromConstraintExpr(S, D, E[1]);
-  if (!Second)
+  auto Conjunction = fromConstraintExpr(S, D, E[0]);
+  if (!Conjunction)
 return None;
-  llvm::Optional Conjunction;
-  Conjunction.emplace(S.Context, std::move(*First), std::move(*Second),
-  CCK_Conjunction);
-  for (unsigned I = 2; I < E.size(); ++I) {
+  for (unsigned I = 1; I < E.size(); ++I) {
 auto Next = fromConstraintExpr(S, D, E[I]);
 if (!Next)
-  return llvm::Optional{};
-NormalizedConstraint NewConjunction(S.Context, std::move(*Conjunction),
+  return None;
+*Conjunction = NormalizedConstraint(S.Context, std::move(*Conjunction),
 std::move(*Next), CCK_Conjunction);
-*Conjunction = std::move(NewConjunction);
   }
   return Conjunction;
 }

diff  --git a/clang/test/CXX/temp/temp.constr/temp.constr.normal/p1.cpp 
b/clang/test/CXX/temp/temp.constr/temp.constr.normal/p1.cpp
index 153d4a56bea31..2134968101470 100644
--- a/clang/test/CXX/temp/temp.constr/temp.constr.normal/p1.cpp
+++ b/clang/test/CXX/temp/temp.constr/temp.constr.normal/p1.cpp
@@ -67,3 +67,18 @@ namespace non_type_pack {
 
   static_assert((foo<1>(), true));
 }
+
+namespace PR47174 {
+// This checks that we don't crash with a failed substitution on the first 
constrained argument when
+// performing normalization.
+template 
+requires true struct S3; // expected-note {{template is declared here}}
+template 
+requires true struct S3; // expected-error {{class template partial 
specialization is not more specialized than the primary template}}
+
+// Same as above, for the second position (but this was already working).
+template 
+requires true struct S4; // expected-note {{template is declared here}}
+template 
+requires true struct S4; // expected-error {{class template partial 
specialization is not more specialized than the primary template}}
+} // namespace PR47174



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


[clang] [C++20] [Modules] Introduce -fskip-odr-check-in-gmf (PR #79959)

2024-01-30 Thread Matheus Izvekov via cfe-commits

mizvekov wrote:

@dwblaikie The flag is for our own use within LLVM test suite. With the 
previous change, we were unconditionally weakening standards conformance and 
runtime checking, because there are a bunch of bugs which are believed to be 
mostly harmless. However, if we do that without some sort of switch, we can't 
keep testing and fixing things on our end, so that we can some day revert to 
the correct behavior.

https://github.com/llvm/llvm-project/pull/79959
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [C++20] [Modules] Introduce -fskip-odr-check-in-gmf (PR #79959)

2024-01-30 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov edited 
https://github.com/llvm/llvm-project/pull/79959
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [C++20] [Modules] Introduce -fskip-odr-check-in-gmf (PR #79959)

2024-01-30 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov commented:

On the Implementation side, this looks good, just some concerns regarding 
documentation.

https://github.com/llvm/llvm-project/pull/79959
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [C++20] [Modules] Introduce -fskip-odr-check-in-gmf (PR #79959)

2024-01-30 Thread Matheus Izvekov via cfe-commits


@@ -457,6 +457,28 @@ Note that **currently** the compiler doesn't consider 
inconsistent macro definit
 Currently Clang would accept the above example. But it may produce surprising 
results if the
 debugging code depends on consistent use of ``NDEBUG`` also in other 
translation units.
 
+Definitions consistency
+^^^
+
+The C++ language defines that same declarations in different translation units 
should have
+the same definition, as known as ODR (One Definition Rule). Prior to modules, 
the translation
+units don't dependent on each other and the compiler itself don't and can't 
perform a strong
+ODR violation check. Sometimes it is the linker does some jobs related to ODR, 
where the
+higher level semantics are missing. With the introduction of modules, now the 
compiler have
+the chance to perform ODR violations with language semantics across 
translation units.

mizvekov wrote:

```suggestion
The C++ language defines that same declarations in different translation units 
should have
the same definition, as known as ODR (One Definition Rule). Prior to modules, 
the translation
units don't dependent on each other and the compiler itself can't perform a 
strong
ODR violation check. With the introduction of modules, now the compiler have
the chance to perform ODR violations with language semantics across translation 
units.
```

https://github.com/llvm/llvm-project/pull/79959
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [C++20] [Modules] Introduce -fskip-odr-check-in-gmf (PR #79959)

2024-01-30 Thread Matheus Izvekov via cfe-commits


@@ -3940,6 +3940,14 @@ static bool RenderModulesOptions(Compilation &C, const 
Driver &D,
 Args.ClaimAllArgs(options::OPT_fmodules_disable_diagnostic_validation);
   }
 
+  // Don't check ODR violations for decls in the global module fragment.
+  // 1. To keep consistent behavior with MSVC, which don't check ODR violations
+  //in the global module fragment too.
+  // 2. Give users better using experience since most issue reports complains
+  //the false positive ODR violations diagnostic and the true positive ODR
+  //violations are rarely reported.
+  CmdArgs.push_back("-fskip-odr-check-in-gmf");

mizvekov wrote:

```suggestion
  // FIXME: We provisionally don't check ODR violations for decls in the global 
module fragment.
  CmdArgs.push_back("-fskip-odr-check-in-gmf");
```

https://github.com/llvm/llvm-project/pull/79959
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [C++20] [Modules] Introduce -fskip-odr-check-in-gmf (PR #79959)

2024-01-30 Thread Matheus Izvekov via cfe-commits


@@ -457,6 +457,28 @@ Note that **currently** the compiler doesn't consider 
inconsistent macro definit
 Currently Clang would accept the above example. But it may produce surprising 
results if the
 debugging code depends on consistent use of ``NDEBUG`` also in other 
translation units.
 
+Definitions consistency
+^^^
+
+The C++ language defines that same declarations in different translation units 
should have
+the same definition, as known as ODR (One Definition Rule). Prior to modules, 
the translation
+units don't dependent on each other and the compiler itself don't and can't 
perform a strong
+ODR violation check. Sometimes it is the linker does some jobs related to ODR, 
where the
+higher level semantics are missing. With the introduction of modules, now the 
compiler have
+the chance to perform ODR violations with language semantics across 
translation units.
+
+However, in the practice we found the existing ODR checking mechanism may be 
too aggressive.
+In the many issue reports about ODR violation diagnostics, most of them are 
false positive
+ODR violations and the true positive ODR violations are rarely reported. Also 
MSVC don't
+perform ODR check for declarations in the global module fragment.

mizvekov wrote:

I think there are many kinds of issues here and the text might not be conveying 
the right idea.

1) There are some clang bugs where wrong semantic analysis occurs when building 
AST from pcm, where otherwise parsing from source produces correct results. 
This is not a problem in ODR checking per se, but it can manifest itself as 
that, and this ends up being helpful.
2) Bugs in the ODR checker itself, where two identical definitions, per the 
standard, are mistaken as different, or the opposite.
3) ODR violations in user code, which can some times be mostly harmless, and 
some times not.

I read this paragraph as talking about 3 in particular, and giving the idea 
that the ODR, as specified, ends up barfing at too many harmless violations, 
and we are finding that it's more trouble than it's worth as we enforce it in 
more situations.

Regarding MSVC, I don't think we normally would relax standards conformance so 
broadly in order to be consistent with another compiler. For example, see how 
we handle compatibility with MSVC regarding delayed template parsing.



https://github.com/llvm/llvm-project/pull/79959
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [C++20] [Modules] Introduce -fskip-odr-check-in-gmf (PR #79959)

2024-01-30 Thread Matheus Izvekov via cfe-commits


@@ -457,6 +457,28 @@ Note that **currently** the compiler doesn't consider 
inconsistent macro definit
 Currently Clang would accept the above example. But it may produce surprising 
results if the
 debugging code depends on consistent use of ``NDEBUG`` also in other 
translation units.
 
+Definitions consistency
+^^^
+
+The C++ language defines that same declarations in different translation units 
should have
+the same definition, as known as ODR (One Definition Rule). Prior to modules, 
the translation
+units don't dependent on each other and the compiler itself don't and can't 
perform a strong
+ODR violation check. Sometimes it is the linker does some jobs related to ODR, 
where the
+higher level semantics are missing. With the introduction of modules, now the 
compiler have
+the chance to perform ODR violations with language semantics across 
translation units.
+
+However, in the practice we found the existing ODR checking mechanism may be 
too aggressive.
+In the many issue reports about ODR violation diagnostics, most of them are 
false positive
+ODR violations and the true positive ODR violations are rarely reported. Also 
MSVC don't
+perform ODR check for declarations in the global module fragment.
+
+So in order to get better user experience, save the time checking ODR and keep 
consistent
+behavior with MSVC, we disabled the ODR check for the declarations in the 
global module
+fragment by default. Users who want more strict check can still use the
+``-Xclang -fno-skip-odr-check-in-gmf`` flag to get the ODR check enabled. It 
is also
+encouraged to report issues if users find false positive ODR violations or 
false negative ODR
+violations with the flag enabled.

mizvekov wrote:

Again I find this paragraph concerning 3). This jusitifies in terms of MSVC 
conformance, but doesn't limit the behavior to that environment. Also I don't 
think we offer compiler switches that decrease standards conformance in order 
to save build time.

https://github.com/llvm/llvm-project/pull/79959
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [C++20] [Modules] Introduce -fskip-odr-check-in-gmf (PR #79959)

2024-01-31 Thread Matheus Izvekov via cfe-commits


@@ -457,6 +457,28 @@ Note that **currently** the compiler doesn't consider 
inconsistent macro definit
 Currently Clang would accept the above example. But it may produce surprising 
results if the
 debugging code depends on consistent use of ``NDEBUG`` also in other 
translation units.
 
+Definitions consistency
+^^^
+
+The C++ language defines that same declarations in different translation units 
should have
+the same definition, as known as ODR (One Definition Rule). Prior to modules, 
the translation
+units don't dependent on each other and the compiler itself don't and can't 
perform a strong
+ODR violation check. Sometimes it is the linker does some jobs related to ODR, 
where the
+higher level semantics are missing. With the introduction of modules, now the 
compiler have
+the chance to perform ODR violations with language semantics across 
translation units.
+
+However, in the practice we found the existing ODR checking mechanism may be 
too aggressive.
+In the many issue reports about ODR violation diagnostics, most of them are 
false positive
+ODR violations and the true positive ODR violations are rarely reported. Also 
MSVC don't
+perform ODR check for declarations in the global module fragment.

mizvekov wrote:

>For 2, I thought the term false positive implies 2. But maybe it is not 
>impressive. So I tried to rewrite this paragraph to make it more explicit.

That is surprising to me, because the issue you linked in the original commit, 
#78850, seems to be a case of 3) to me, mostly harmless but nonetheless an ODR 
violation.

This is not just about the semantics of the resulting program itself, think 
about debug info: There will be two definitions of `fun`, with slightly 
different debug info, because they refer to different declarations for T, even 
if they resolve to the same type.

Even if the standard wording talks about the definitions consisting of the same 
series of tokens, this to me is a case of rule-as-written vs rule-as-intended. 
Ie the tokens not only have to be same textually, but they need to refer to the 
same entity.

> For 1, I don't understand why it is relevant here. I know what you're saying, 
> but I just feel it is not related here. We're talking about ODR checker, 
> right?

See above, but I am also currently internally tracking two separate bugs which 
are a case of 1), and the ODR checker was just an innocent witness.

https://github.com/llvm/llvm-project/pull/79959
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [C++20] [Modules] Introduce -fskip-odr-check-in-gmf (PR #79959)

2024-01-31 Thread Matheus Izvekov via cfe-commits


@@ -457,6 +457,28 @@ Note that **currently** the compiler doesn't consider 
inconsistent macro definit
 Currently Clang would accept the above example. But it may produce surprising 
results if the
 debugging code depends on consistent use of ``NDEBUG`` also in other 
translation units.
 
+Definitions consistency
+^^^
+
+The C++ language defines that same declarations in different translation units 
should have
+the same definition, as known as ODR (One Definition Rule). Prior to modules, 
the translation
+units don't dependent on each other and the compiler itself don't and can't 
perform a strong
+ODR violation check. Sometimes it is the linker does some jobs related to ODR, 
where the
+higher level semantics are missing. With the introduction of modules, now the 
compiler have
+the chance to perform ODR violations with language semantics across 
translation units.
+
+However, in the practice we found the existing ODR checking mechanism may be 
too aggressive.
+In the many issue reports about ODR violation diagnostics, most of them are 
false positive
+ODR violations and the true positive ODR violations are rarely reported. Also 
MSVC don't
+perform ODR check for declarations in the global module fragment.

mizvekov wrote:

> Great insight. I feel this is meaningful. Maybe we need to reach out WG21 to 
> confirm this. Can you access the mailing list of WG21?

I am not a member yet, but I know a few people in there.

> Sorry. I still don't understand why it is related to the patch itself.

So a little background: The issue #78850 that was referenced in the original 
commit, which seems to be the main motivator for that change, was reported as 
two parts:
1) A real-world-like repro where the user is just including different libstdc++ 
headers.
2) The reduced repro, where there is the real ODR violation we were just 
arguing about.

I have reason to believe, based on similarity to clang bug I am currently 
working on, that 2) is unrelated to 1).
Based on the commonality between reproducers of #78850 and the bug I am working 
on.
They both involve UsingShadowDecls, the merging of which is broken, as I will 
show on an upcoming patch.

If you look at this from another angle, this reduction was performed by the 
user / reporter, and reducing a false-positive ODR violation repro is hard, 
because it's so easy you would introduce a real ODR-violation during a 
reduction step.
So it's reasonable to double-check / do some due-dilligence here.

So I feel we are taking a drastic step here based on potentially incorrect 
evidence.

If we can confirm what I am saying, then don't you agree we would be losing the 
whole casus belli against the GMF ODR checker, and we could go back to square 
one, revert the whole thing, and take a better look at this?

Even if that is not the only issue, my perception is that other supposed ODR 
violations could be simple issues like this.
And even if there are ODR violations in shipped system headers, couldn't we:
1) Provide a more targeted workaround rather than disabling the whole thing.
2) Stand our ground, since the whole C++20 modules thing is new, we can expect 
users to be using more recent / fixed system headers.

> 
> But the explanation from MSVC developer moves me. Since the entities in the 
> GMF are basically from headers. Then it wouldn't be a regression in some 
> level.

I have never seen MSVC source code, so I don't know how relevant it would be 
for comparison, but I think clang has enough differences in how sema is applied 
to textual source vs PCM, that this would give me pause and I wouldn't be so 
sure.

On the other hand, this does not seem to be a regression, since the whole C++20 
modules thing is just coming up and we are talking about a new feature and new 
users.

> 
> Also I feel your concern here is about deeper other problems. (e.g., what is 
> ODR violation?) And I want to backport the series patches to 18.x. So I am 
> wondering if we can approve this patch and I can start to backport it. Then 
> we can discuss your concern in other places.

See above. Would you mind waiting a little for my patch, for us to double check 
we are taking this step with solid footing?

https://github.com/llvm/llvm-project/pull/79959
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [C++20] [Modules] Introduce -fskip-odr-check-in-gmf (PR #79959)

2024-01-31 Thread Matheus Izvekov via cfe-commits


@@ -457,6 +457,28 @@ Note that **currently** the compiler doesn't consider 
inconsistent macro definit
 Currently Clang would accept the above example. But it may produce surprising 
results if the
 debugging code depends on consistent use of ``NDEBUG`` also in other 
translation units.
 
+Definitions consistency
+^^^
+
+The C++ language defines that same declarations in different translation units 
should have
+the same definition, as known as ODR (One Definition Rule). Prior to modules, 
the translation
+units don't dependent on each other and the compiler itself don't and can't 
perform a strong
+ODR violation check. Sometimes it is the linker does some jobs related to ODR, 
where the
+higher level semantics are missing. With the introduction of modules, now the 
compiler have
+the chance to perform ODR violations with language semantics across 
translation units.
+
+However, in the practice we found the existing ODR checking mechanism may be 
too aggressive.
+In the many issue reports about ODR violation diagnostics, most of them are 
false positive
+ODR violations and the true positive ODR violations are rarely reported. Also 
MSVC don't
+perform ODR check for declarations in the global module fragment.

mizvekov wrote:

> Do you need me to send this? I feel this is the deepest problem in the 
> discussion.

Sure, we can move that part of the discussion over there.

> 
> Is there an issue report?
> 

Not on the llvm issue tracker yet, I am working on getting issue + patch up 
soon.

> To me, the issue is `the straw that broke the camel's back`. I've seen too 
> many issue reports saying and complaining the false positive ODR violations 
> publicly and privately. It is a long battle.
> 

How are we tracking these issues, is there a special tag for them? We could 
take a better look, attack this systematically.

> My experience is "yes, a lot of false positive ODR violations can be fixed by 
> simple patch". The only problem is that there is **too many**. Or this may be 
> the reason I feel the current ODR checker is not stable enough.

Right, but reducing these issues takes a lot of effort. On the other hand, it's 
possible they all reduce to a few simple cases.
This is my perception so far, working on converting a medium size code base.

> 
> Or let's take a step back. How about always enabling the ODR checker for 
> decls in the GMF but offering a driver flag "-fskip-odr-check-in-gmf"? Then 
> the users can get better experience and offer more precise issue report. Also 
> we don't need to be in the panic of losing standard conformance.

Yeah, one concern is losing the bug reports.
While we do offer driver flags to facilitate testing experimental features, 
which I think C++20 modules falls under, 
this may be too technical detail to expose to users.

So I will go ahead and approve this, even though I feel this might have been 
too hasty, as long as we are running the clang test suite as before, then we 
can make progress in fixing all the problems and circle back to always enabling 
the checker.

> 
> I think it is saying the users converting a repo from headers to modules.

Right, but that's not a regression.


https://github.com/llvm/llvm-project/pull/79959
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [C++20] [Modules] Introduce -fskip-odr-check-in-gmf (PR #79959)

2024-01-31 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov approved this pull request.


https://github.com/llvm/llvm-project/pull/79959
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] Users/mizvekov/bug/clang merge usingshadowdecl (PR #80245)

2024-01-31 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov created 
https://github.com/llvm/llvm-project/pull/80245

[clang] fix merging of UsingShadowDecl

Previously, when deciding if two UsingShadowDecls where mergeable,
we would incorrectly only look for both pointing to the exact redecla
ration, whereas the correct thing is to look for declarations to the
same entity.

This problem has existed as far back as 2013, introduced in commit 
fd8634a09de71.

This problem could manifest itself as ODR check false positives when importing 
modules.

Fixes: #ISSUE_TO_BE_CREATED

>From 23a0d731cfe8593c338fc8ad7920f7aa9270afaa Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Thu, 1 Feb 2024 02:07:16 -0300
Subject: [PATCH 1/2] [NFC] [clang] add test for merging of UsingShadowDecl

---
 clang/test/Modules/cxx20-decls.cppm | 44 +
 1 file changed, 44 insertions(+)
 create mode 100644 clang/test/Modules/cxx20-decls.cppm

diff --git a/clang/test/Modules/cxx20-decls.cppm 
b/clang/test/Modules/cxx20-decls.cppm
new file mode 100644
index 0..052c8e73be247
--- /dev/null
+++ b/clang/test/Modules/cxx20-decls.cppm
@@ -0,0 +1,44 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: cd %t
+//
+// RUN: %clang_cc1 -std=c++20 -I %t %t/A.cppm -emit-module-interface -o 
%t/A.pcm -verify
+// RUN: %clang_cc1 -std=c++20 -I %t %t/B.cpp -fmodule-file=A=%t/A.pcm 
-fsyntax-only -verify -ast-dump-all -ast-dump-filter baz | FileCheck %s
+
+//--- foo.h
+namespace baz {
+  using foo = char;
+  using baz::foo;
+}
+
+//--- A.cppm
+// expected-no-diagnostics
+module;
+#include "foo.h"
+export module A;
+
+//--- B.cpp
+// expected-no-diagnostics
+#include "foo.h"
+import A;
+// Since modules are loaded lazily, force loading by performing a lookup.
+using xxx = baz::foo;
+
+// CHECK-LABEL: Dumping baz:
+// CHECK-NEXT: NamespaceDecl 0x[[BAZ_REDECL_ADDR:[^ ]*]] prev 0x[[BAZ_ADDR:[^ 
]*]] <{{.*}}> line:{{.*}} imported in A. hidden  baz
+// CHECK-NEXT: |-original Namespace 0x[[BAZ_ADDR]] 'baz'
+// CHECK-NEXT: |-TypeAliasDecl 0x[[ALIAS_REDECL_ADDR:[^ ]*]] prev 
0x[[ALIAS_ADDR:[^ ]*]] <{{.*}}> col:{{.*}} imported in A. hidden foo 
'char'
+// CHECK-NEXT: | `-BuiltinType 0x{{[^ ]*}} 'char'
+// CHECK-NEXT: |-UsingDecl 0x{{[^ ]*}} first 0x[[USING_ADDR:[^ ]*]] <{{.*}}> 
col:{{.*}} imported in A. hidden baz::foo
+// CHECK-NEXT: | `-NestedNameSpecifier Namespace 0x[[BAZ_REDECL_ADDR]] 'baz'
+// FIXME: UsingShadowDecl should have been merged
+// CHECK-NOT:  `-UsingShadowDecl 0x{{[^ ]*}} prev 0x{{[^ ]*}} <{{.*}}> 
col:{{.*}} imported in A. hidden implicit TypeAlias 
0x[[ALIAS_REDECL_ADDR]] 'foo'
+// CHECK-NEXT: `-UsingShadowDecl 0x{{[^ ]*}} <{{.*}}> col:{{.*}} imported in 
A. hidden implicit TypeAlias 0x[[ALIAS_REDECL_ADDR]] 'foo'
+
+// CHECK-LABEL: Dumping baz:
+// CHECK-NEXT: NamespaceDecl 0x[[BAZ_ADDR]] <{{.*}}> line:{{.*}} baz
+// CHECK-NEXT: |-TypeAliasDecl 0x[[ALIAS_ADDR]] <{{.*}}> col:{{.*}} referenced 
foo 'char'
+// CHECK-NEXT: | `-BuiltinType 0x{{[^ ]*}} 'char'
+// CHECK-NEXT: |-UsingDecl 0x[[USING_ADDR]] <{{.*}}> col:{{.*}} baz::foo
+// CHECK-NEXT: | `-NestedNameSpecifier Namespace 0x[[BAZ_ADDR]] 'baz'
+// CHECK-NEXT:  `-UsingShadowDecl 0x[[SHADOW_ADDR:[^ ]*]] <{{.*}}> col:{{.*}} 
implicit TypeAlias 0x[[ALIAS_ADDR]] 'foo'

>From b44f1b2ee3d709c627c1679fe3a252ea564bdd3d Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Thu, 1 Feb 2024 02:26:10 -0300
Subject: [PATCH 2/2] [clang] fix merging of UsingShadowDecl

Previously, when deciding if two UsingShadowDecls where mergeable,
we would incorrectly only look for both pointing to the exact redecla
ration, whereas the correct thing is to look for declarations to the
same entity.

This problem has existed as far back as 2013, introduced in commit
fd8634a09de71.

This problem could manifest itself as ODR check false positives
when importing modules.

Fixes: #ISSUE_TO_BE_CREATED
---
 clang/docs/ReleaseNotes.rst | 3 +++
 clang/lib/AST/ASTContext.cpp| 2 +-
 clang/test/Modules/cxx20-decls.cppm | 6 ++
 3 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index b7b11ab3a6b2e..aa14b8e931101 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -181,6 +181,9 @@ Bug Fixes to C++ Support
   and (`#79745 `_)
 - Fix incorrect code generation caused by the object argument of ``static 
operator()`` and ``static operator[]`` calls not being evaluated.
   Fixes (`#67976 `_)
+- Fix incorrect merging of modules which contain using declarations which 
shadow
+  other declarations. This could manifest as ODR checker false positives.
+  Fixes (`#TODO `_)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 71c9c0003d18c..feeb350bf3e0c 100644
--- a/clang/lib/AST/ASTContext.

[clang] [clang] fix merging of UsingShadowDecl (PR #80245)

2024-01-31 Thread Matheus Izvekov via cfe-commits

mizvekov wrote:

Hmm I have been doing user branches for a while, this saves me time in case I 
want to split the patch off in a separate MR.
It's already the case that this is split into test adding + fixing commits.

In any case, the user branch will be deleted as soon as this is merged.

Can we go ahead, and clarify the rules for the next time, since this is such a 
small patch and windows CI takes 3 hours?

https://github.com/llvm/llvm-project/pull/80245
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] fix merging of UsingShadowDecl (PR #80245)

2024-01-31 Thread Matheus Izvekov via cfe-commits


@@ -181,6 +181,9 @@ Bug Fixes to C++ Support
   and (`#79745 `_)
 - Fix incorrect code generation caused by the object argument of ``static 
operator()`` and ``static operator[]`` calls not being evaluated.
   Fixes (`#67976 `_)
+- Fix incorrect merging of modules which contain using declarations which 
shadow
+  other declarations. This could manifest as ODR checker false positives.
+  Fixes (`#TODO `_)

mizvekov wrote:

We usually do small fixups like this during review / post approval, this will 
not be merged like this, don't worry.
People on the LLVM community tend to be quite flexible on these things.

https://github.com/llvm/llvm-project/pull/80245
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] fix merging of UsingShadowDecl (PR #80245)

2024-01-31 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov edited 
https://github.com/llvm/llvm-project/pull/80245
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] fix merging of UsingShadowDecl (PR #80245)

2024-01-31 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov updated 
https://github.com/llvm/llvm-project/pull/80245

>From 23a0d731cfe8593c338fc8ad7920f7aa9270afaa Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Thu, 1 Feb 2024 02:07:16 -0300
Subject: [PATCH 1/2] [NFC] [clang] add test for merging of UsingShadowDecl

---
 clang/test/Modules/cxx20-decls.cppm | 44 +
 1 file changed, 44 insertions(+)
 create mode 100644 clang/test/Modules/cxx20-decls.cppm

diff --git a/clang/test/Modules/cxx20-decls.cppm 
b/clang/test/Modules/cxx20-decls.cppm
new file mode 100644
index 0..052c8e73be247
--- /dev/null
+++ b/clang/test/Modules/cxx20-decls.cppm
@@ -0,0 +1,44 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: cd %t
+//
+// RUN: %clang_cc1 -std=c++20 -I %t %t/A.cppm -emit-module-interface -o 
%t/A.pcm -verify
+// RUN: %clang_cc1 -std=c++20 -I %t %t/B.cpp -fmodule-file=A=%t/A.pcm 
-fsyntax-only -verify -ast-dump-all -ast-dump-filter baz | FileCheck %s
+
+//--- foo.h
+namespace baz {
+  using foo = char;
+  using baz::foo;
+}
+
+//--- A.cppm
+// expected-no-diagnostics
+module;
+#include "foo.h"
+export module A;
+
+//--- B.cpp
+// expected-no-diagnostics
+#include "foo.h"
+import A;
+// Since modules are loaded lazily, force loading by performing a lookup.
+using xxx = baz::foo;
+
+// CHECK-LABEL: Dumping baz:
+// CHECK-NEXT: NamespaceDecl 0x[[BAZ_REDECL_ADDR:[^ ]*]] prev 0x[[BAZ_ADDR:[^ 
]*]] <{{.*}}> line:{{.*}} imported in A. hidden  baz
+// CHECK-NEXT: |-original Namespace 0x[[BAZ_ADDR]] 'baz'
+// CHECK-NEXT: |-TypeAliasDecl 0x[[ALIAS_REDECL_ADDR:[^ ]*]] prev 
0x[[ALIAS_ADDR:[^ ]*]] <{{.*}}> col:{{.*}} imported in A. hidden foo 
'char'
+// CHECK-NEXT: | `-BuiltinType 0x{{[^ ]*}} 'char'
+// CHECK-NEXT: |-UsingDecl 0x{{[^ ]*}} first 0x[[USING_ADDR:[^ ]*]] <{{.*}}> 
col:{{.*}} imported in A. hidden baz::foo
+// CHECK-NEXT: | `-NestedNameSpecifier Namespace 0x[[BAZ_REDECL_ADDR]] 'baz'
+// FIXME: UsingShadowDecl should have been merged
+// CHECK-NOT:  `-UsingShadowDecl 0x{{[^ ]*}} prev 0x{{[^ ]*}} <{{.*}}> 
col:{{.*}} imported in A. hidden implicit TypeAlias 
0x[[ALIAS_REDECL_ADDR]] 'foo'
+// CHECK-NEXT: `-UsingShadowDecl 0x{{[^ ]*}} <{{.*}}> col:{{.*}} imported in 
A. hidden implicit TypeAlias 0x[[ALIAS_REDECL_ADDR]] 'foo'
+
+// CHECK-LABEL: Dumping baz:
+// CHECK-NEXT: NamespaceDecl 0x[[BAZ_ADDR]] <{{.*}}> line:{{.*}} baz
+// CHECK-NEXT: |-TypeAliasDecl 0x[[ALIAS_ADDR]] <{{.*}}> col:{{.*}} referenced 
foo 'char'
+// CHECK-NEXT: | `-BuiltinType 0x{{[^ ]*}} 'char'
+// CHECK-NEXT: |-UsingDecl 0x[[USING_ADDR]] <{{.*}}> col:{{.*}} baz::foo
+// CHECK-NEXT: | `-NestedNameSpecifier Namespace 0x[[BAZ_ADDR]] 'baz'
+// CHECK-NEXT:  `-UsingShadowDecl 0x[[SHADOW_ADDR:[^ ]*]] <{{.*}}> col:{{.*}} 
implicit TypeAlias 0x[[ALIAS_ADDR]] 'foo'

>From 895c615a354d540c4e4404fa728bfad2a962c7bf Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Thu, 1 Feb 2024 02:26:10 -0300
Subject: [PATCH 2/2] [clang] fix merging of UsingShadowDecl

Previously, when deciding if two UsingShadowDecls where mergeable,
we would incorrectly only look for both pointing to the exact redecla
ration, whereas the correct thing is to look for declarations to the
same entity.

This problem has existed as far back as 2013, introduced in commit
fd8634a09de71.

This problem could manifest itself as ODR check false positives
when importing modules.

Fixes: #80252
---
 clang/docs/ReleaseNotes.rst | 3 +++
 clang/test/Modules/cxx20-decls.cppm | 6 ++
 2 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index b7b11ab3a6b2e..a48672951de32 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -181,6 +181,9 @@ Bug Fixes to C++ Support
   and (`#79745 `_)
 - Fix incorrect code generation caused by the object argument of ``static 
operator()`` and ``static operator[]`` calls not being evaluated.
   Fixes (`#67976 `_)
+- Fix incorrect merging of modules which contain using declarations which 
shadow
+  other declarations. This could manifest as ODR checker false positives.
+  Fixes (`#80252 `_)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/test/Modules/cxx20-decls.cppm 
b/clang/test/Modules/cxx20-decls.cppm
index 052c8e73be247..ee9f117278884 100644
--- a/clang/test/Modules/cxx20-decls.cppm
+++ b/clang/test/Modules/cxx20-decls.cppm
@@ -31,9 +31,7 @@ using xxx = baz::foo;
 // CHECK-NEXT: | `-BuiltinType 0x{{[^ ]*}} 'char'
 // CHECK-NEXT: |-UsingDecl 0x{{[^ ]*}} first 0x[[USING_ADDR:[^ ]*]] <{{.*}}> 
col:{{.*}} imported in A. hidden baz::foo
 // CHECK-NEXT: | `-NestedNameSpecifier Namespace 0x[[BAZ_REDECL_ADDR]] 'baz'
-// FIXME: UsingShadowDecl should have been merged
-// CHECK-NOT:  `-UsingShadowDecl 0x{{[^ ]*}} prev 0x{{[^ ]*}} <{{.*}}> 
col:{{.*}} imported in A. hidden impl

[clang] [clang] fix merging of UsingShadowDecl (PR #80245)

2024-01-31 Thread Matheus Izvekov via cfe-commits


@@ -181,6 +181,9 @@ Bug Fixes to C++ Support
   and (`#79745 `_)
 - Fix incorrect code generation caused by the object argument of ``static 
operator()`` and ``static operator[]`` calls not being evaluated.
   Fixes (`#67976 `_)
+- Fix incorrect merging of modules which contain using declarations which 
shadow
+  other declarations. This could manifest as ODR checker false positives.
+  Fixes (`#TODO `_)

mizvekov wrote:

The MR is split in two commits, the first one adds the test, if you click on 
the last commit, you can see the change in the expectation.

https://github.com/llvm/llvm-project/pull/80245
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] fix merging of UsingShadowDecl (PR #80245)

2024-01-31 Thread Matheus Izvekov via cfe-commits


@@ -0,0 +1,42 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: cd %t
+//
+// RUN: %clang_cc1 -std=c++20 -I %t %t/A.cppm -emit-module-interface -o 
%t/A.pcm -verify
+// RUN: %clang_cc1 -std=c++20 -I %t %t/B.cpp -fmodule-file=A=%t/A.pcm 
-fsyntax-only -verify -ast-dump-all -ast-dump-filter baz | FileCheck %s
+
+//--- foo.h
+namespace baz {
+  using foo = char;
+  using baz::foo;
+}
+
+//--- A.cppm
+// expected-no-diagnostics
+module;
+#include "foo.h"
+export module A;
+
+//--- B.cpp
+// expected-no-diagnostics
+#include "foo.h"
+import A;
+// Since modules are loaded lazily, force loading by performing a lookup.
+using xxx = baz::foo;
+
+// CHECK-LABEL: Dumping baz:
+// CHECK-NEXT: NamespaceDecl 0x[[BAZ_REDECL_ADDR:[^ ]*]] prev 0x[[BAZ_ADDR:[^ 
]*]] <{{.*}}> line:{{.*}} imported in A. hidden  baz
+// CHECK-NEXT: |-original Namespace 0x[[BAZ_ADDR]] 'baz'
+// CHECK-NEXT: |-TypeAliasDecl 0x[[ALIAS_REDECL_ADDR:[^ ]*]] prev 
0x[[ALIAS_ADDR:[^ ]*]] <{{.*}}> col:{{.*}} imported in A. hidden foo 
'char'
+// CHECK-NEXT: | `-BuiltinType 0x{{[^ ]*}} 'char'
+// CHECK-NEXT: |-UsingDecl 0x{{[^ ]*}} first 0x[[USING_ADDR:[^ ]*]] <{{.*}}> 
col:{{.*}} imported in A. hidden baz::foo
+// CHECK-NEXT: | `-NestedNameSpecifier Namespace 0x[[BAZ_REDECL_ADDR]] 'baz'
+// CHECK-NEXT: `-UsingShadowDecl 0x{{[^ ]*}} prev 0x[[SHADOW_ADDR:[^ ]*]] 
<{{.*}}> col:{{.*}} imported in A. hidden implicit TypeAlias 
0x[[ALIAS_REDECL_ADDR]] 'foo'

mizvekov wrote:

While normally I would agree, in this case there are no existing AST tests for 
these other kinds of declarations, so I felt appropriate to broaden this test a 
little bit to cover those.

https://github.com/llvm/llvm-project/pull/80245
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] fix merging of UsingShadowDecl (PR #80245)

2024-01-31 Thread Matheus Izvekov via cfe-commits

mizvekov wrote:

The issue is up: https://github.com/llvm/llvm-project/issues/80252

https://github.com/llvm/llvm-project/pull/80245
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] fix merging of UsingShadowDecl (PR #80245)

2024-01-31 Thread Matheus Izvekov via cfe-commits

mizvekov wrote:

> IIRC, in #79959, you're saying the patch have the potential to fix #78850? Is 
> it true?

Yeah, looking at the similarities, there is a decent chance this is the same 
issue, it's worth trying it out.

https://github.com/llvm/llvm-project/pull/80245
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] fix merging of UsingShadowDecl (PR #80245)

2024-02-01 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov updated 
https://github.com/llvm/llvm-project/pull/80245

>From 8823a7ec248c7220395f53634467aa25f5007206 Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Thu, 1 Feb 2024 02:07:16 -0300
Subject: [PATCH 1/2] [NFC] [clang] add tests for merging of UsingShadowDecl

---
 clang/test/Modules/GH80252.cppm | 42 +++
 clang/test/Modules/cxx20-decls.cppm | 44 +
 2 files changed, 86 insertions(+)
 create mode 100644 clang/test/Modules/GH80252.cppm
 create mode 100644 clang/test/Modules/cxx20-decls.cppm

diff --git a/clang/test/Modules/GH80252.cppm b/clang/test/Modules/GH80252.cppm
new file mode 100644
index 0..3212404fbe14c
--- /dev/null
+++ b/clang/test/Modules/GH80252.cppm
@@ -0,0 +1,42 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: cd %t
+//
+// RUN: %clang_cc1 -std=c++20 -I %t %t/A.cppm -emit-module-interface -o 
%t/A.pcm -verify
+// RUN: %clang_cc1 -std=c++20 -I %t %t/B.cppm -emit-module-interface -o 
%t/B.pcm -verify
+// RUN: %clang_cc1 -std=c++20 -I %t %t/C.cpp -fmodule-file=A=%t/A.pcm 
-fmodule-file=B=%t/B.pcm -fsyntax-only -verify
+
+//--- foo.h
+namespace baz {
+  using foo = char;
+  using baz::foo;
+}
+
+//--- bar.h
+class bar {
+  bar(baz::foo);
+};
+
+//--- A.cppm
+// expected-no-diagnostics
+module;
+#include "foo.h"
+export module A;
+
+//--- B.cppm
+// expected-no-diagnostics
+module;
+#include "foo.h"
+#include "bar.h"
+export module B;
+
+//--- C.cpp
+#include "foo.h"
+import A;
+#include "bar.h"
+import B;
+// Since modules are loaded lazily, force loading by performing a lookup.
+using xxx = bar;
+// FIXME: This is a false positive ODR violation.
+// expected-error@bar.h:2 {{'bar' has different definitions in different 
modules; first difference is defined here found constructor with 1st parameter 
of type 'baz::foo' (aka 'char')}}
+// expected-note@bar.h:2 {{but in 'B.' found constructor with 1st 
parameter of type 'baz::foo' (aka 'char')}}
diff --git a/clang/test/Modules/cxx20-decls.cppm 
b/clang/test/Modules/cxx20-decls.cppm
new file mode 100644
index 0..052c8e73be247
--- /dev/null
+++ b/clang/test/Modules/cxx20-decls.cppm
@@ -0,0 +1,44 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: cd %t
+//
+// RUN: %clang_cc1 -std=c++20 -I %t %t/A.cppm -emit-module-interface -o 
%t/A.pcm -verify
+// RUN: %clang_cc1 -std=c++20 -I %t %t/B.cpp -fmodule-file=A=%t/A.pcm 
-fsyntax-only -verify -ast-dump-all -ast-dump-filter baz | FileCheck %s
+
+//--- foo.h
+namespace baz {
+  using foo = char;
+  using baz::foo;
+}
+
+//--- A.cppm
+// expected-no-diagnostics
+module;
+#include "foo.h"
+export module A;
+
+//--- B.cpp
+// expected-no-diagnostics
+#include "foo.h"
+import A;
+// Since modules are loaded lazily, force loading by performing a lookup.
+using xxx = baz::foo;
+
+// CHECK-LABEL: Dumping baz:
+// CHECK-NEXT: NamespaceDecl 0x[[BAZ_REDECL_ADDR:[^ ]*]] prev 0x[[BAZ_ADDR:[^ 
]*]] <{{.*}}> line:{{.*}} imported in A. hidden  baz
+// CHECK-NEXT: |-original Namespace 0x[[BAZ_ADDR]] 'baz'
+// CHECK-NEXT: |-TypeAliasDecl 0x[[ALIAS_REDECL_ADDR:[^ ]*]] prev 
0x[[ALIAS_ADDR:[^ ]*]] <{{.*}}> col:{{.*}} imported in A. hidden foo 
'char'
+// CHECK-NEXT: | `-BuiltinType 0x{{[^ ]*}} 'char'
+// CHECK-NEXT: |-UsingDecl 0x{{[^ ]*}} first 0x[[USING_ADDR:[^ ]*]] <{{.*}}> 
col:{{.*}} imported in A. hidden baz::foo
+// CHECK-NEXT: | `-NestedNameSpecifier Namespace 0x[[BAZ_REDECL_ADDR]] 'baz'
+// FIXME: UsingShadowDecl should have been merged
+// CHECK-NOT:  `-UsingShadowDecl 0x{{[^ ]*}} prev 0x{{[^ ]*}} <{{.*}}> 
col:{{.*}} imported in A. hidden implicit TypeAlias 
0x[[ALIAS_REDECL_ADDR]] 'foo'
+// CHECK-NEXT: `-UsingShadowDecl 0x{{[^ ]*}} <{{.*}}> col:{{.*}} imported in 
A. hidden implicit TypeAlias 0x[[ALIAS_REDECL_ADDR]] 'foo'
+
+// CHECK-LABEL: Dumping baz:
+// CHECK-NEXT: NamespaceDecl 0x[[BAZ_ADDR]] <{{.*}}> line:{{.*}} baz
+// CHECK-NEXT: |-TypeAliasDecl 0x[[ALIAS_ADDR]] <{{.*}}> col:{{.*}} referenced 
foo 'char'
+// CHECK-NEXT: | `-BuiltinType 0x{{[^ ]*}} 'char'
+// CHECK-NEXT: |-UsingDecl 0x[[USING_ADDR]] <{{.*}}> col:{{.*}} baz::foo
+// CHECK-NEXT: | `-NestedNameSpecifier Namespace 0x[[BAZ_ADDR]] 'baz'
+// CHECK-NEXT:  `-UsingShadowDecl 0x[[SHADOW_ADDR:[^ ]*]] <{{.*}}> col:{{.*}} 
implicit TypeAlias 0x[[ALIAS_ADDR]] 'foo'

>From f2e37f079cecdd95ba32912aaea739be68959f9e Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Thu, 1 Feb 2024 02:26:10 -0300
Subject: [PATCH 2/2] [clang] fix merging of UsingShadowDecl

Previously, when deciding if two UsingShadowDecls where mergeable,
we would incorrectly only look for both pointing to the exact redecla
ration, whereas the correct thing is to look for declarations to the
same entity.

This problem has existed as far back as 2013, introduced in commit
fd8634a09de71.

This problem could manifest itself as ODR check false positives
when importing modules.

Fixes: #80252
---
 clang/docs/ReleaseNotes.rst | 3 +++
 clang/lib/AST/ASTContext.cpp  

[clang] [clang] fix merging of UsingShadowDecl (PR #80245)

2024-02-01 Thread Matheus Izvekov via cfe-commits

mizvekov wrote:

I have rebased on top of the change which reenables GMF ODR checker on the test 
suite, so I added a new regression test that exercises the false positive ODR 
violation.

https://github.com/llvm/llvm-project/pull/80245
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] fix merging of UsingShadowDecl (PR #80245)

2024-02-01 Thread Matheus Izvekov via cfe-commits

mizvekov wrote:

I took a look at what sort of complexity unittest would entail here. I don't 
think it's a good compromise complexity wise, it's a lot of boilerplate just to 
test a few AST nodes are correctly linked.

On the other hand, these AST tests don't look particularly out of place 
compared to a lot of other AST tests we have.

However, I have seen that there are a lot of other related merging issues, so I 
will leave the tangentially related tests for another MR.

https://github.com/llvm/llvm-project/pull/80245
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] fix merging of UsingShadowDecl (PR #80245)

2024-02-01 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov updated 
https://github.com/llvm/llvm-project/pull/80245

>From f7340f3781a3e3094169c970aadb9b69414543f5 Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Thu, 1 Feb 2024 02:07:16 -0300
Subject: [PATCH 1/2] [NFC] [clang] add tests for merging of UsingShadowDecl

---
 clang/test/Modules/GH80252.cppm | 42 +++
 clang/test/Modules/cxx20-decls.cppm | 44 +
 2 files changed, 86 insertions(+)
 create mode 100644 clang/test/Modules/GH80252.cppm
 create mode 100644 clang/test/Modules/cxx20-decls.cppm

diff --git a/clang/test/Modules/GH80252.cppm b/clang/test/Modules/GH80252.cppm
new file mode 100644
index 0..3212404fbe14c
--- /dev/null
+++ b/clang/test/Modules/GH80252.cppm
@@ -0,0 +1,42 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: cd %t
+//
+// RUN: %clang_cc1 -std=c++20 -I %t %t/A.cppm -emit-module-interface -o 
%t/A.pcm -verify
+// RUN: %clang_cc1 -std=c++20 -I %t %t/B.cppm -emit-module-interface -o 
%t/B.pcm -verify
+// RUN: %clang_cc1 -std=c++20 -I %t %t/C.cpp -fmodule-file=A=%t/A.pcm 
-fmodule-file=B=%t/B.pcm -fsyntax-only -verify
+
+//--- foo.h
+namespace baz {
+  using foo = char;
+  using baz::foo;
+}
+
+//--- bar.h
+class bar {
+  bar(baz::foo);
+};
+
+//--- A.cppm
+// expected-no-diagnostics
+module;
+#include "foo.h"
+export module A;
+
+//--- B.cppm
+// expected-no-diagnostics
+module;
+#include "foo.h"
+#include "bar.h"
+export module B;
+
+//--- C.cpp
+#include "foo.h"
+import A;
+#include "bar.h"
+import B;
+// Since modules are loaded lazily, force loading by performing a lookup.
+using xxx = bar;
+// FIXME: This is a false positive ODR violation.
+// expected-error@bar.h:2 {{'bar' has different definitions in different 
modules; first difference is defined here found constructor with 1st parameter 
of type 'baz::foo' (aka 'char')}}
+// expected-note@bar.h:2 {{but in 'B.' found constructor with 1st 
parameter of type 'baz::foo' (aka 'char')}}
diff --git a/clang/test/Modules/cxx20-decls.cppm 
b/clang/test/Modules/cxx20-decls.cppm
new file mode 100644
index 0..28af7b4bc47b4
--- /dev/null
+++ b/clang/test/Modules/cxx20-decls.cppm
@@ -0,0 +1,44 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: cd %t
+//
+// RUN: %clang_cc1 -std=c++20 -I %t %t/A.cppm -emit-module-interface -o 
%t/A.pcm -verify
+// RUN: %clang_cc1 -std=c++20 -I %t %t/B.cpp -fmodule-file=A=%t/A.pcm 
-fsyntax-only -verify -ast-dump-all -ast-dump-filter baz | FileCheck %s
+
+//--- foo.h
+namespace baz {
+  using foo = char;
+  using baz::foo;
+}
+
+//--- A.cppm
+// expected-no-diagnostics
+module;
+#include "foo.h"
+export module A;
+
+//--- B.cpp
+// expected-no-diagnostics
+#include "foo.h"
+import A;
+// Since modules are loaded lazily, force loading by performing a lookup.
+using xxx = baz::foo;
+
+// CHECK-LABEL: Dumping baz:
+// CHECK-NEXT: NamespaceDecl {{.*}} imported in A. {{.*}} baz
+// CHECK-NEXT: |-original Namespace {{.*}} 'baz'
+// CHECK-NEXT: |-TypeAliasDecl {{.*}} foo 'char'
+// CHECK-NEXT: | `-BuiltinType {{.*}} 'char'
+// CHECK-NEXT: |-UsingDecl {{.*}} baz::foo
+// CHECK-NEXT: | `-NestedNameSpecifier Namespace {{.*}} 'baz'
+// FIXME: UsingShadowDecl should have been merged
+// CHECK-NOT:  `-UsingShadowDecl 0x{{[^ ]*}} prev 0x{{[^ ]*}} {{.*}} imported 
in A. {{.*}} 'foo'
+// CHECK-NEXT: `-UsingShadowDecl 0x{{[^ ]*}} {{.*}} imported in A. 
{{.*}} 'foo'
+
+// CHECK-LABEL: Dumping baz:
+// CHECK-NEXT: NamespaceDecl {{.*}} baz
+// CHECK-NEXT: |-TypeAliasDecl {{.*}} foo 'char'
+// CHECK-NEXT: | `-BuiltinType {{.*}} 'char'
+// CHECK-NEXT: |-UsingDecl {{.*}} baz::foo
+// CHECK-NEXT: | `-NestedNameSpecifier Namespace {{.*}} 'baz'
+// CHECK-NEXT:  `-UsingShadowDecl 0x[[SHADOW_ADDR:[^ ]*]] {{.*}} 'foo'

>From 1e6827281750a7fe33b8fa1bc66524b6f52d9080 Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Thu, 1 Feb 2024 02:26:10 -0300
Subject: [PATCH 2/2] [clang] fix merging of UsingShadowDecl

Previously, when deciding if two UsingShadowDecls where mergeable,
we would incorrectly only look for both pointing to the exact redecla
ration, whereas the correct thing is to look for declarations to the
same entity.

This problem has existed as far back as 2013, introduced in commit
fd8634a09de71.

This problem could manifest itself as ODR check false positives
when importing modules.

Fixes: #80252
---
 clang/docs/ReleaseNotes.rst | 3 +++
 clang/lib/AST/ASTContext.cpp| 2 +-
 clang/test/Modules/GH80252.cppm | 4 +---
 clang/test/Modules/cxx20-decls.cppm | 6 ++
 4 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 53040aa0f9074..0a9cd242f9d95 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -188,6 +188,9 @@ Bug Fixes to C++ Support
   and (`#79745 `_)
 - Fix incorrect code generation caused by the object argument of ``static 
operator()`` and

[clang] [clang] fix merging of UsingShadowDecl (PR #80245)

2024-02-01 Thread Matheus Izvekov via cfe-commits

mizvekov wrote:

I just pushed the change on this patch. What I meant is this patch will get, 
besides aforementioned regression test involving ODR checker failure, a simpler 
AST test that verifies just the UsingShadowDecl is correctly merged.

https://github.com/llvm/llvm-project/pull/80245
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] fix merging of UsingShadowDecl (PR #80245)

2024-02-01 Thread Matheus Izvekov via cfe-commits

mizvekov wrote:

There is a lot of activity going on just in `clang/test/AST`, with multiple 
commits a day.
I think there is a time and place, and the right tradeoffs for all kinds of 
tests we have. Shall we get others opinions?
Shall we make an RFC so we get the community aligned on this new direction?

https://github.com/llvm/llvm-project/pull/80245
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] fix merging of UsingShadowDecl (PR #80245)

2024-02-01 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov updated 
https://github.com/llvm/llvm-project/pull/80245

>From 7bd920a14240c85442467706236e0644f320aa5c Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Thu, 1 Feb 2024 02:07:16 -0300
Subject: [PATCH 1/2] [NFC] [clang] add tests for merging of UsingShadowDecl

---
 clang/test/Modules/GH80252.cppm | 45 +
 clang/test/Modules/cxx20-decls.cppm | 44 
 2 files changed, 89 insertions(+)
 create mode 100644 clang/test/Modules/GH80252.cppm
 create mode 100644 clang/test/Modules/cxx20-decls.cppm

diff --git a/clang/test/Modules/GH80252.cppm b/clang/test/Modules/GH80252.cppm
new file mode 100644
index 0..f4730a9874197
--- /dev/null
+++ b/clang/test/Modules/GH80252.cppm
@@ -0,0 +1,45 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: cd %t
+//
+// RUN: %clang_cc1 -std=c++20 -I %t %t/A.cppm -emit-module-interface -o 
%t/A.pcm -verify
+// RUN: %clang_cc1 -std=c++20 -I %t %t/B.cppm -emit-module-interface -o 
%t/B.pcm -verify
+// RUN: %clang_cc1 -std=c++20 -I %t %t/C.cpp -fmodule-file=A=%t/A.pcm 
-fmodule-file=B=%t/B.pcm -fsyntax-only -verify
+
+//--- foo.h
+namespace baz {
+  using foo = char;
+  using baz::foo;
+}
+
+//--- bar.h
+class bar {
+  bar(baz::foo);
+};
+
+//--- A.cppm
+// expected-no-diagnostics
+module;
+#include "foo.h"
+export module A;
+export using AX = baz::foo;
+
+//--- B.cppm
+// expected-no-diagnostics
+module;
+#include "foo.h"
+#include "bar.h"
+export module B;
+export using BX = baz::foo;
+export using BY = bar;
+
+//--- C.cpp
+#include "foo.h"
+import A;
+#include "bar.h"
+import B;
+// Since modules are loaded lazily, force loading by performing a lookup.
+using xxx = bar;
+// FIXME: This is a false positive ODR violation.
+// expected-error@bar.h:2 {{'bar' has different definitions in different 
modules; first difference is defined here found constructor with 1st parameter 
of type 'baz::foo' (aka 'char')}}
+// expected-note@bar.h:2 {{but in 'B.' found constructor with 1st 
parameter of type 'baz::foo' (aka 'char')}}
diff --git a/clang/test/Modules/cxx20-decls.cppm 
b/clang/test/Modules/cxx20-decls.cppm
new file mode 100644
index 0..28af7b4bc47b4
--- /dev/null
+++ b/clang/test/Modules/cxx20-decls.cppm
@@ -0,0 +1,44 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: cd %t
+//
+// RUN: %clang_cc1 -std=c++20 -I %t %t/A.cppm -emit-module-interface -o 
%t/A.pcm -verify
+// RUN: %clang_cc1 -std=c++20 -I %t %t/B.cpp -fmodule-file=A=%t/A.pcm 
-fsyntax-only -verify -ast-dump-all -ast-dump-filter baz | FileCheck %s
+
+//--- foo.h
+namespace baz {
+  using foo = char;
+  using baz::foo;
+}
+
+//--- A.cppm
+// expected-no-diagnostics
+module;
+#include "foo.h"
+export module A;
+
+//--- B.cpp
+// expected-no-diagnostics
+#include "foo.h"
+import A;
+// Since modules are loaded lazily, force loading by performing a lookup.
+using xxx = baz::foo;
+
+// CHECK-LABEL: Dumping baz:
+// CHECK-NEXT: NamespaceDecl {{.*}} imported in A. {{.*}} baz
+// CHECK-NEXT: |-original Namespace {{.*}} 'baz'
+// CHECK-NEXT: |-TypeAliasDecl {{.*}} foo 'char'
+// CHECK-NEXT: | `-BuiltinType {{.*}} 'char'
+// CHECK-NEXT: |-UsingDecl {{.*}} baz::foo
+// CHECK-NEXT: | `-NestedNameSpecifier Namespace {{.*}} 'baz'
+// FIXME: UsingShadowDecl should have been merged
+// CHECK-NOT:  `-UsingShadowDecl 0x{{[^ ]*}} prev 0x{{[^ ]*}} {{.*}} imported 
in A. {{.*}} 'foo'
+// CHECK-NEXT: `-UsingShadowDecl 0x{{[^ ]*}} {{.*}} imported in A. 
{{.*}} 'foo'
+
+// CHECK-LABEL: Dumping baz:
+// CHECK-NEXT: NamespaceDecl {{.*}} baz
+// CHECK-NEXT: |-TypeAliasDecl {{.*}} foo 'char'
+// CHECK-NEXT: | `-BuiltinType {{.*}} 'char'
+// CHECK-NEXT: |-UsingDecl {{.*}} baz::foo
+// CHECK-NEXT: | `-NestedNameSpecifier Namespace {{.*}} 'baz'
+// CHECK-NEXT:  `-UsingShadowDecl 0x[[SHADOW_ADDR:[^ ]*]] {{.*}} 'foo'

>From db966f66a148ab5b5ba26250cbf0dab6be5a2c29 Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Thu, 1 Feb 2024 02:26:10 -0300
Subject: [PATCH 2/2] [clang] fix merging of UsingShadowDecl

Previously, when deciding if two UsingShadowDecls where mergeable,
we would incorrectly only look for both pointing to the exact redecla
ration, whereas the correct thing is to look for declarations to the
same entity.

This problem has existed as far back as 2013, introduced in commit
fd8634a09de71.

This problem could manifest itself as ODR check false positives
when importing modules.

Fixes: #80252
---
 clang/docs/ReleaseNotes.rst | 3 +++
 clang/lib/AST/ASTContext.cpp| 2 +-
 clang/test/Modules/GH80252.cppm | 4 +---
 clang/test/Modules/cxx20-decls.cppm | 6 ++
 4 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 53040aa0f9074..0a9cd242f9d95 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -188,6 +188,9 @@ Bug Fixes to C++ Support
   and (`#79745 `_)
 - Fix in

[clang] [clang] fix merging of UsingShadowDecl (PR #80245)

2024-02-01 Thread Matheus Izvekov via cfe-commits


@@ -0,0 +1,40 @@
+// RUN: rm -rf %t
+// RUN: split-file %s %t
+// RUN: cd %t
+//
+// RUN: %clang_cc1 -std=c++20 -I %t %t/A.cppm -emit-module-interface -o 
%t/A.pcm -verify
+// RUN: %clang_cc1 -std=c++20 -I %t %t/B.cppm -emit-module-interface -o 
%t/B.pcm -verify
+// RUN: %clang_cc1 -std=c++20 -I %t %t/C.cpp -fmodule-file=A=%t/A.pcm 
-fmodule-file=B=%t/B.pcm -fsyntax-only -verify
+
+//--- foo.h
+namespace baz {
+  using foo = char;
+  using baz::foo;
+}
+
+//--- bar.h
+class bar {
+  bar(baz::foo);
+};
+
+//--- A.cppm
+// expected-no-diagnostics
+module;
+#include "foo.h"
+export module A;

mizvekov wrote:

Done, slightly different, to keep test simple and avoid introducing more 
shadowing declarations.

https://github.com/llvm/llvm-project/pull/80245
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Make sure the same UsingType is searched and inserted (PR #79182)

2024-01-23 Thread Matheus Izvekov via cfe-commits

mizvekov wrote:

The change is correct. The problem is subtle though. It comes from the 
difference in behavior between the member and non-member Profile functions.

I think we could do better instead with a change which makes it harder to trip 
on this.

I think a simplification like this should work (untested):
```
diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index ea425791fc97..3d411051084c 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -4729,13 +4729,12 @@ public:
   bool typeMatchesDecl() const { return !UsingBits.hasTypeDifferentFromDecl; }

   void Profile(llvm::FoldingSetNodeID &ID) {
-Profile(ID, Found, typeMatchesDecl() ? QualType() : getUnderlyingType());
+Profile(ID, Found, getUnderlyingType());
   }
   static void Profile(llvm::FoldingSetNodeID &ID, const UsingShadowDecl *Found,
   QualType Underlying) {
 ID.AddPointer(Found);
-if (!Underlying.isNull())
-  Underlying.Profile(ID);
+Underlying.Profile(ID);
   }
   static bool classof(const Type *T) { return T->getTypeClass() == Using; }
 };
```

https://github.com/llvm/llvm-project/pull/79182
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Make sure the same UsingType is searched and inserted (PR #79182)

2024-01-23 Thread Matheus Izvekov via cfe-commits

mizvekov wrote:

> Wonder what test should I add here. This only affects the content of the 
> internal folding set so we always create new types but result is still 
> correct.

One possibility is doing an AST test, there are some examples in there that 
show how you can test two different AST nodes have the same address.

The best here would be some kind of performance regression test. We don't have 
anything like that per-se in the test suite unfortunately.
But if you can isolate a good test case, you can make it a normal regression 
test, which with the fix is still within CI limits of time and space, but which 
pushes much farther out without the fix. This would not be without precedent, 
there already exists tests like that.

https://github.com/llvm/llvm-project/pull/79182
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Make sure the same UsingType is searched and inserted (PR #79182)

2024-01-24 Thread Matheus Izvekov via cfe-commits

mizvekov wrote:

LGTM.

Thanks!

https://github.com/llvm/llvm-project/pull/79182
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Make sure the same UsingType is searched and inserted (PR #79182)

2024-01-24 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov approved this pull request.


https://github.com/llvm/llvm-project/pull/79182
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [Docs][LTO] Updated HowToSubmitABug.rst for LTO crashes (PR #68389)

2023-10-19 Thread Matheus Izvekov via cfe-commits


@@ -153,6 +153,67 @@ Please run this, then file a bug with the instructions and 
reduced .bc file
 that bugpoint emits.  If something goes wrong with bugpoint, please submit
 the "foo.bc" file and the option that llc crashes with.
 
+LTO bugs
+---
+
+If you encounter a bug that leads to crashes in the LLVM LTO phase when using
+the `-flto` option, follow these steps to diagnose and report the issue:
+
+Compile your source file to a .bc (Bitcode) file with the following flags,
+in addition to your existing compilation options:
+
+.. code-block:: bash
+
+   export CFLAGS="-flto -fuse-ld=lld" CXXFLAGS="-flto -fuse-ld=lld" 
LDFLAGS="-Wl,-plugin-opt=save-temps"
+
+These flags enable LTO and save temporary files generated during compilation
+for later analysis.
+
+On Windows, you should use lld-link as the linker. Adjust your compilation 
+flags as follows:
+
+.. code-block:: bash
+
+   export CFLAGS="-flto -fuse-ld=lld-link" CXXFLAGS="-flto -fuse-ld=lld-link" 
LDFLAGS="-Wl,-plugin-opt=save-temps"

mizvekov wrote:

Does this actually work? The option is spelled `/lldsavetemps` in the COFF 
linker.

https://github.com/llvm/llvm-project/pull/68389
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Docs][LTO] Updated HowToSubmitABug.rst for LTO crashes (PR #68389)

2023-10-23 Thread Matheus Izvekov via cfe-commits


@@ -153,6 +153,67 @@ Please run this, then file a bug with the instructions and 
reduced .bc file
 that bugpoint emits.  If something goes wrong with bugpoint, please submit
 the "foo.bc" file and the option that llc crashes with.
 
+LTO bugs
+---
+
+If you encounter a bug that leads to crashes in the LLVM LTO phase when using
+the `-flto` option, follow these steps to diagnose and report the issue:
+
+Compile your source file to a .bc (Bitcode) file with the following flags,
+in addition to your existing compilation options:
+
+.. code-block:: bash
+
+   export CFLAGS="-flto -fuse-ld=lld" CXXFLAGS="-flto -fuse-ld=lld" 
LDFLAGS="-Wl,-plugin-opt=save-temps"
+
+These flags enable LTO and save temporary files generated during compilation
+for later analysis.
+
+On Windows, you should use lld-link as the linker. Adjust your compilation 
+flags as follows:
+
+.. code-block:: bash
+
+   export CFLAGS="-flto -fuse-ld=lld-link" CXXFLAGS="-flto -fuse-ld=lld-link" 
LDFLAGS="-Wl,-plugin-opt=save-temps"

mizvekov wrote:

Well, I never mind the bash syntax, as that could be justified as exposition 
only.
And really all combinations are possible here, as bash is available on windows, 
powershell is available on linux, and clang-cl can be used from a linux host as 
well.

Roughly, however you choose to expose this, these are the options the user 
needs to pass:
* The user needs to be using lld-link obviously.
  * On simple cases where the linker is being called from the compiler driver, 
as is the norm on GCC-based compiler drivers, we would already be expecting the 
user to be passing `-fuse-ld=lld-link`, the flag is spelled the same there.
  * However, unlike on GCC world, on MSVC it's normal / expected that the user 
will be calling the linker directly.
* The linker flag that performs save-temps is `/lldsavetemps` as I explained 
earlier.
* Forwarding linker options from the clang-cl driver needs `/link`, like so: 
`/link /lldsavetemps`.

https://github.com/llvm/llvm-project/pull/68389
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [Docs][LTO] Updated HowToSubmitABug.rst for LTO crashes (PR #68389)

2023-10-23 Thread Matheus Izvekov via cfe-commits


@@ -153,6 +153,67 @@ Please run this, then file a bug with the instructions and 
reduced .bc file
 that bugpoint emits.  If something goes wrong with bugpoint, please submit
 the "foo.bc" file and the option that llc crashes with.
 
+LTO bugs
+---
+
+If you encounter a bug that leads to crashes in the LLVM LTO phase when using
+the `-flto` option, follow these steps to diagnose and report the issue:
+
+Compile your source file to a .bc (Bitcode) file with the following flags,
+in addition to your existing compilation options:
+
+.. code-block:: bash
+
+   export CFLAGS="-flto -fuse-ld=lld" CXXFLAGS="-flto -fuse-ld=lld" 
LDFLAGS="-Wl,-plugin-opt=save-temps"
+
+These flags enable LTO and save temporary files generated during compilation
+for later analysis.
+
+On Windows, you should use lld-link as the linker. Adjust your compilation 
+flags as follows:
+
+.. code-block:: bash
+
+   export CFLAGS="-flto -fuse-ld=lld-link" CXXFLAGS="-flto -fuse-ld=lld-link" 
LDFLAGS="-Wl,-plugin-opt=save-temps"

mizvekov wrote:

Well, I never mind the bash syntax, as that could be justified as exposition 
only.
And really all combinations are possible here, as bash is available on windows, 
powershell is available on linux, and clang-cl can be used from a linux host as 
well.

Roughly, however you choose to expose this, these are the options the user 
needs to pass:
* The user needs to be using lld-link obviously.
  * On simple cases where the linker is being called from the compiler driver, 
as is the norm on GCC-based compiler drivers, we would already be expecting the 
user to be passing `-fuse-ld=lld-link`, the flag is spelled the same there.
  * However, unlike on GCC world, on MSVC it's normal / expected that the user 
will be calling the linker directly.
* The linker flag that performs save-temps is `/lldsavetemps` as I explained 
earlier.
* Forwarding linker options from the clang-cl driver needs `/link`, like so: 
`/link /lldsavetemps`.

https://github.com/llvm/llvm-project/pull/68389
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Docs][LTO] Updated HowToSubmitABug.rst for LTO crashes (PR #68389)

2023-10-23 Thread Matheus Izvekov via cfe-commits


@@ -153,6 +153,67 @@ Please run this, then file a bug with the instructions and 
reduced .bc file
 that bugpoint emits.  If something goes wrong with bugpoint, please submit
 the "foo.bc" file and the option that llc crashes with.
 
+LTO bugs
+---
+
+If you encounter a bug that leads to crashes in the LLVM LTO phase when using
+the `-flto` option, follow these steps to diagnose and report the issue:
+
+Compile your source file to a .bc (Bitcode) file with the following flags,
+in addition to your existing compilation options:
+
+.. code-block:: bash
+
+   export CFLAGS="-flto -fuse-ld=lld" CXXFLAGS="-flto -fuse-ld=lld" 
LDFLAGS="-Wl,-plugin-opt=save-temps"
+
+These flags enable LTO and save temporary files generated during compilation
+for later analysis.
+
+On Windows, you should use lld-link as the linker. Adjust your compilation 
+flags as follows:
+
+.. code-block:: bash
+
+   export CFLAGS="-flto -fuse-ld=lld-link" CXXFLAGS="-flto -fuse-ld=lld-link" 
LDFLAGS="-Wl,-plugin-opt=save-temps"

mizvekov wrote:

```suggestion
On Windows, you should be using lld-link as the linker. Adjust your compilation 
flags as follows:
* Add `/lldsavetemps` to the linker flags.
* When linking from the compiler driver, Add `/link /lldsavetemps` in order to 
forward that flag to the linker.

https://github.com/llvm/llvm-project/pull/68389
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [Docs][LTO] Updated HowToSubmitABug.rst for LTO crashes (PR #68389)

2023-10-23 Thread Matheus Izvekov via cfe-commits


@@ -153,6 +153,67 @@ Please run this, then file a bug with the instructions and 
reduced .bc file
 that bugpoint emits.  If something goes wrong with bugpoint, please submit
 the "foo.bc" file and the option that llc crashes with.
 
+LTO bugs
+---
+
+If you encounter a bug that leads to crashes in the LLVM LTO phase when using
+the `-flto` option, follow these steps to diagnose and report the issue:
+
+Compile your source file to a .bc (Bitcode) file with the following flags,
+in addition to your existing compilation options:
+
+.. code-block:: bash
+
+   export CFLAGS="-flto -fuse-ld=lld" CXXFLAGS="-flto -fuse-ld=lld" 
LDFLAGS="-Wl,-plugin-opt=save-temps"
+
+These flags enable LTO and save temporary files generated during compilation
+for later analysis.
+
+On Windows, you should use lld-link as the linker. Adjust your compilation 
+flags as follows:
+
+.. code-block:: bash
+
+   export CFLAGS="-flto -fuse-ld=lld-link" CXXFLAGS="-flto -fuse-ld=lld-link" 
LDFLAGS="-Wl,-plugin-opt=save-temps"

mizvekov wrote:

```suggestion
On Windows, you should be using lld-link as the linker. Adjust your compilation 
flags as follows:
* Add `/lldsavetemps` to the linker flags.
* When linking from the compiler driver, Add `/link /lldsavetemps` in order to 
forward that flag to the linker.

https://github.com/llvm/llvm-project/pull/68389
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Docs][LTO] Updated HowToSubmitABug.rst for LTO crashes (PR #68389)

2023-10-23 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov edited 
https://github.com/llvm/llvm-project/pull/68389
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [Docs][LTO] Updated HowToSubmitABug.rst for LTO crashes (PR #68389)

2023-10-23 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov edited 
https://github.com/llvm/llvm-project/pull/68389
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][Driver] Add new flags to control machine instruction verification (PR #70282)

2023-10-25 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov created 
https://github.com/llvm/llvm-project/pull/70282

Present shortcomings are that this only works for non-LTO builds, and that this 
new pass doesn't work quite the same as the IR verification flag, as it runs 
between every machine pass and is thus much more expensive.

Though I recently discussed this with @aeubanks during the US devmtg and we 
think this is worthwhile as a first step.

>From 8015101a24e302fae53fe19683024d47e9ae4d8d Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Wed, 4 Oct 2023 12:09:15 +0200
Subject: [PATCH] [Clang][Driver] Add new flags to control machine instruction
 verification

---
 clang/docs/ReleaseNotes.rst   | 7 +++
 clang/include/clang/Driver/Options.td | 6 ++
 clang/lib/Driver/ToolChains/Clang.cpp | 8 
 clang/test/Driver/clang_f_opts.c  | 5 +
 4 files changed, 26 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 42f20b9a9bb0410..80cebbe3210983f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -206,6 +206,13 @@ New Compiler Flags
   Since enabling the verifier adds a non-trivial cost of a few percent impact 
on
   build times, it's disabled by default, unless your LLVM distribution itself 
is
   compiled with runtime checks enabled.
+* ``-fverify-machine-code`` and its complement ``-fno-verify-machine-code``.
+  Enable or disable the verification of the generated machine code.
+  Users can pass this to turn on extra verification to catch certain types of
+  compiler bugs at the cost of extra compile time.
+  This verifier adds a huge overhead to compile time, it's expected that build 
times
+  can double, so this is disabled by default.
+  This flag is currently limited to non-LTO builds.
 * ``-fkeep-system-includes`` modifies the behavior of the ``-E`` option,
   preserving ``#include`` directives for "system" headers instead of copying
   the preprocessed text to the output. This can greatly reduce the size of the
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index c6b1903a32a0621..c190af69d1e1145 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1926,6 +1926,12 @@ def fverify_intermediate_code : Flag<["-"], 
"fverify-intermediate-code">,
 def fno_verify_intermediate_code : Flag<["-"], "fno-verify-intermediate-code">,
   Group, Visibility<[ClangOption, CLOption, DXCOption]>,
   HelpText<"Disable verification of LLVM IR">, Flags<[NoXarchOption]>;
+def fverify_machine_code : Flag<["-"], "fverify-machine-code">,
+  Group, Visibility<[ClangOption, CLOption, DXCOption]>,
+  HelpText<"Enable verification of generated machine code">, 
Flags<[NoXarchOption]>;
+def fno_verify_machine_code : Flag<["-"], "fno-verify-machine-code">,
+  Group, Visibility<[ClangOption, CLOption, DXCOption]>,
+  HelpText<"Disable verification of generated machine code">, 
Flags<[NoXarchOption]>;
 def fdiscard_value_names : Flag<["-"], "fdiscard-value-names">,
   Group, Visibility<[ClangOption, DXCOption]>,
   HelpText<"Discard value names in LLVM IR">, Flags<[NoXarchOption]>;
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 601bbfb927746fc..6b7ae896863e4da 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -5175,6 +5175,14 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
 CmdArgs.push_back("-disable-llvm-verifier");
   }
 
+  // Enable the machine code verification pass. Note that this is force enabled
+  // elsewhere with LLVM_ENABLE_EXPENSIVE_CHECKS.
+  if (Args.hasFlag(options::OPT_fverify_machine_code,
+   options::OPT_fno_verify_machine_code, false)) {
+CmdArgs.push_back("-mllvm");
+CmdArgs.push_back("-verify-machineinstrs");
+  }
+
   // Discard value names in assert builds unless otherwise specified.
   if (Args.hasFlag(options::OPT_fdiscard_value_names,
options::OPT_fno_discard_value_names, !IsAssertBuild)) {
diff --git a/clang/test/Driver/clang_f_opts.c b/clang/test/Driver/clang_f_opts.c
index ebe8a0520bf0fca..e6bb6f80f00368b 100644
--- a/clang/test/Driver/clang_f_opts.c
+++ b/clang/test/Driver/clang_f_opts.c
@@ -525,6 +525,11 @@
 // CHECK-VERIFY-INTERMEDIATE-CODE-NOT: "-disable-llvm-verifier"
 // CHECK-NO-VERIFY-INTERMEDIATE-CODE: "-disable-llvm-verifier"
 
+// RUN: %clang -### -S -fverify-machine-code %s 2>&1 | FileCheck 
-check-prefix=CHECK-VERIFY-MACHINE-CODE %s
+// RUN: %clang -### -S -fno-verify-machine-code %s 2>&1 | FileCheck 
-check-prefix=CHECK-NO-VERIFY-MACHINE-CODE %s
+// CHECK-VERIFY-MACHINE-CODE: "-mllvm" "-verify-machineinstrs"
+// CHECK-NO-VERIFY-MACHINE-CODE-NOT: "-mllvm" "-verify-machineinstrs"
+
 // RUN: %clang -### -S -fdiscard-value-names %s 2>&1 | FileCheck 
-check-prefix=CHECK-DISCARD-NAMES %s
 // RUN: %clang -### -S -fno-discard-value-names %s 2>&1 | FileCheck 
-check-prefix=CHECK

[clang] [Clang][Driver] Add new flags to control machine instruction verification (PR #70282)

2023-10-25 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov updated 
https://github.com/llvm/llvm-project/pull/70282

>From 9f3711c112159c57becae105561bc988a0caaeb5 Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Thu, 26 Oct 2023 06:07:57 +0200
Subject: [PATCH 1/2] [clang][driver] remove accidentally added NoXarchOption
 flag

This flag was accidentally added in 6da382d27bb5c21dfce8ae5239ab5797bc191cab
Explained in 
https://github.com/llvm/llvm-project/pull/70282#discussion_r1372537230
---
 clang/include/clang/Driver/Options.td | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index c6b1903a32a0621..f9bf170c32ba25e 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1922,10 +1922,10 @@ defm safe_buffer_usage_suggestions : 
BoolFOption<"safe-buffer-usage-suggestions"
   NegFlag>;
 def fverify_intermediate_code : Flag<["-"], "fverify-intermediate-code">,
   Group, Visibility<[ClangOption, CLOption, DXCOption]>,
-  HelpText<"Enable verification of LLVM IR">, Flags<[NoXarchOption]>;
+  HelpText<"Enable verification of LLVM IR">;
 def fno_verify_intermediate_code : Flag<["-"], "fno-verify-intermediate-code">,
   Group, Visibility<[ClangOption, CLOption, DXCOption]>,
-  HelpText<"Disable verification of LLVM IR">, Flags<[NoXarchOption]>;
+  HelpText<"Disable verification of LLVM IR">;
 def fdiscard_value_names : Flag<["-"], "fdiscard-value-names">,
   Group, Visibility<[ClangOption, DXCOption]>,
   HelpText<"Discard value names in LLVM IR">, Flags<[NoXarchOption]>;

>From c4b858b791792626e0a5584a0a2aeb877a0151c9 Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Wed, 4 Oct 2023 12:09:15 +0200
Subject: [PATCH 2/2] [Clang][Driver] Add new flags to control machine
 instruction verification

---
 clang/docs/ReleaseNotes.rst   | 7 +++
 clang/include/clang/Driver/Options.td | 6 ++
 clang/lib/Driver/ToolChains/Clang.cpp | 8 
 clang/test/Driver/clang_f_opts.c  | 5 +
 4 files changed, 26 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 42f20b9a9bb0410..80cebbe3210983f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -206,6 +206,13 @@ New Compiler Flags
   Since enabling the verifier adds a non-trivial cost of a few percent impact 
on
   build times, it's disabled by default, unless your LLVM distribution itself 
is
   compiled with runtime checks enabled.
+* ``-fverify-machine-code`` and its complement ``-fno-verify-machine-code``.
+  Enable or disable the verification of the generated machine code.
+  Users can pass this to turn on extra verification to catch certain types of
+  compiler bugs at the cost of extra compile time.
+  This verifier adds a huge overhead to compile time, it's expected that build 
times
+  can double, so this is disabled by default.
+  This flag is currently limited to non-LTO builds.
 * ``-fkeep-system-includes`` modifies the behavior of the ``-E`` option,
   preserving ``#include`` directives for "system" headers instead of copying
   the preprocessed text to the output. This can greatly reduce the size of the
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index f9bf170c32ba25e..092b54967ccdab0 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1926,6 +1926,12 @@ def fverify_intermediate_code : Flag<["-"], 
"fverify-intermediate-code">,
 def fno_verify_intermediate_code : Flag<["-"], "fno-verify-intermediate-code">,
   Group, Visibility<[ClangOption, CLOption, DXCOption]>,
   HelpText<"Disable verification of LLVM IR">;
+def fverify_machine_code : Flag<["-"], "fverify-machine-code">,
+  Group, Visibility<[ClangOption, CLOption, DXCOption]>,
+  HelpText<"Enable verification of generated machine code">;
+def fno_verify_machine_code : Flag<["-"], "fno-verify-machine-code">,
+  Group, Visibility<[ClangOption, CLOption, DXCOption]>,
+  HelpText<"Disable verification of generated machine code">;
 def fdiscard_value_names : Flag<["-"], "fdiscard-value-names">,
   Group, Visibility<[ClangOption, DXCOption]>,
   HelpText<"Discard value names in LLVM IR">, Flags<[NoXarchOption]>;
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 601bbfb927746fc..6b7ae896863e4da 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -5175,6 +5175,14 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
 CmdArgs.push_back("-disable-llvm-verifier");
   }
 
+  // Enable the machine code verification pass. Note that this is force enabled
+  // elsewhere with LLVM_ENABLE_EXPENSIVE_CHECKS.
+  if (Args.hasFlag(options::OPT_fverify_machine_code,
+   options::OPT_fno_verify_machine_code, false)) {
+CmdArgs.push_back("-mllvm");
+CmdArgs.push_back("-verify-machineinstrs");
+  }
+
   //

[clang] [Clang][Driver] Add new flags to control machine instruction verification (PR #70282)

2023-10-25 Thread Matheus Izvekov via cfe-commits


@@ -1926,6 +1926,12 @@ def fverify_intermediate_code : Flag<["-"], 
"fverify-intermediate-code">,
 def fno_verify_intermediate_code : Flag<["-"], "fno-verify-intermediate-code">,
   Group, Visibility<[ClangOption, CLOption, DXCOption]>,
   HelpText<"Disable verification of LLVM IR">, Flags<[NoXarchOption]>;
+def fverify_machine_code : Flag<["-"], "fverify-machine-code">,
+  Group, Visibility<[ClangOption, CLOption, DXCOption]>,
+  HelpText<"Enable verification of generated machine code">, 
Flags<[NoXarchOption]>;

mizvekov wrote:

Done. I also fixed in a separate commit the related flag above it, which I 
added recently.

https://github.com/llvm/llvm-project/pull/70282
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][Driver] Add new flags to control machine instruction verification (PR #70282)

2023-10-25 Thread Matheus Izvekov via cfe-commits

https://github.com/mizvekov updated 
https://github.com/llvm/llvm-project/pull/70282

>From b2006f46ebfd1da17014cf6c577da4700c355d00 Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Wed, 4 Oct 2023 12:09:15 +0200
Subject: [PATCH] [Clang][Driver] Add new flags to control machine instruction
 verification

---
 clang/docs/ReleaseNotes.rst   | 7 +++
 clang/include/clang/Driver/Options.td | 6 ++
 clang/lib/Driver/ToolChains/Clang.cpp | 8 
 clang/test/Driver/clang_f_opts.c  | 5 +
 4 files changed, 26 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 42f20b9a9bb0410..80cebbe3210983f 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -206,6 +206,13 @@ New Compiler Flags
   Since enabling the verifier adds a non-trivial cost of a few percent impact 
on
   build times, it's disabled by default, unless your LLVM distribution itself 
is
   compiled with runtime checks enabled.
+* ``-fverify-machine-code`` and its complement ``-fno-verify-machine-code``.
+  Enable or disable the verification of the generated machine code.
+  Users can pass this to turn on extra verification to catch certain types of
+  compiler bugs at the cost of extra compile time.
+  This verifier adds a huge overhead to compile time, it's expected that build 
times
+  can double, so this is disabled by default.
+  This flag is currently limited to non-LTO builds.
 * ``-fkeep-system-includes`` modifies the behavior of the ``-E`` option,
   preserving ``#include`` directives for "system" headers instead of copying
   the preprocessed text to the output. This can greatly reduce the size of the
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 2eb86caa6e6d40e..bda5312d016d231 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -1925,6 +1925,12 @@ def fverify_intermediate_code : Flag<["-"], 
"fverify-intermediate-code">,
 def fno_verify_intermediate_code : Flag<["-"], "fno-verify-intermediate-code">,
   Group, Visibility<[ClangOption, CLOption, DXCOption]>,
   HelpText<"Disable verification of LLVM IR">;
+def fverify_machine_code : Flag<["-"], "fverify-machine-code">,
+  Group, Visibility<[ClangOption, CLOption, DXCOption]>,
+  HelpText<"Enable verification of generated machine code">;
+def fno_verify_machine_code : Flag<["-"], "fno-verify-machine-code">,
+  Group, Visibility<[ClangOption, CLOption, DXCOption]>,
+  HelpText<"Disable verification of generated machine code">;
 def fdiscard_value_names : Flag<["-"], "fdiscard-value-names">,
   Group, Visibility<[ClangOption, DXCOption]>,
   HelpText<"Discard value names in LLVM IR">;
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 601bbfb927746fc..6b7ae896863e4da 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -5175,6 +5175,14 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
 CmdArgs.push_back("-disable-llvm-verifier");
   }
 
+  // Enable the machine code verification pass. Note that this is force enabled
+  // elsewhere with LLVM_ENABLE_EXPENSIVE_CHECKS.
+  if (Args.hasFlag(options::OPT_fverify_machine_code,
+   options::OPT_fno_verify_machine_code, false)) {
+CmdArgs.push_back("-mllvm");
+CmdArgs.push_back("-verify-machineinstrs");
+  }
+
   // Discard value names in assert builds unless otherwise specified.
   if (Args.hasFlag(options::OPT_fdiscard_value_names,
options::OPT_fno_discard_value_names, !IsAssertBuild)) {
diff --git a/clang/test/Driver/clang_f_opts.c b/clang/test/Driver/clang_f_opts.c
index ebe8a0520bf0fca..e6bb6f80f00368b 100644
--- a/clang/test/Driver/clang_f_opts.c
+++ b/clang/test/Driver/clang_f_opts.c
@@ -525,6 +525,11 @@
 // CHECK-VERIFY-INTERMEDIATE-CODE-NOT: "-disable-llvm-verifier"
 // CHECK-NO-VERIFY-INTERMEDIATE-CODE: "-disable-llvm-verifier"
 
+// RUN: %clang -### -S -fverify-machine-code %s 2>&1 | FileCheck 
-check-prefix=CHECK-VERIFY-MACHINE-CODE %s
+// RUN: %clang -### -S -fno-verify-machine-code %s 2>&1 | FileCheck 
-check-prefix=CHECK-NO-VERIFY-MACHINE-CODE %s
+// CHECK-VERIFY-MACHINE-CODE: "-mllvm" "-verify-machineinstrs"
+// CHECK-NO-VERIFY-MACHINE-CODE-NOT: "-mllvm" "-verify-machineinstrs"
+
 // RUN: %clang -### -S -fdiscard-value-names %s 2>&1 | FileCheck 
-check-prefix=CHECK-DISCARD-NAMES %s
 // RUN: %clang -### -S -fno-discard-value-names %s 2>&1 | FileCheck 
-check-prefix=CHECK-NO-DISCARD-NAMES %s
 // CHECK-DISCARD-NAMES: "-discard-value-names"

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


[clang] [Clang][Driver] Add new flags to control machine instruction verification (PR #70282)

2023-10-25 Thread Matheus Izvekov via cfe-commits


@@ -1926,6 +1926,12 @@ def fverify_intermediate_code : Flag<["-"], 
"fverify-intermediate-code">,
 def fno_verify_intermediate_code : Flag<["-"], "fno-verify-intermediate-code">,
   Group, Visibility<[ClangOption, CLOption, DXCOption]>,
   HelpText<"Disable verification of LLVM IR">, Flags<[NoXarchOption]>;
+def fverify_machine_code : Flag<["-"], "fverify-machine-code">,
+  Group, Visibility<[ClangOption, CLOption, DXCOption]>,
+  HelpText<"Enable verification of generated machine code">, 
Flags<[NoXarchOption]>;

mizvekov wrote:

Ops nevermind the separate fix, you beat me to it :)

https://github.com/llvm/llvm-project/pull/70282
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang][Driver] Add new flags to control machine instruction verification (PR #70282)

2023-10-26 Thread Matheus Izvekov via cfe-commits

mizvekov wrote:

I don't disagree that if we stop at this step, then the flag doesn't buy much. 
But it would be worthwhile if we ever implemented LTO integration or 
implemented a lightweight machine verification which runs the pass 1 or 2 
times, which would work similarly to the IR verification flag.

So shall we put this MR to sleep until we have that, or otherwise abandon this 
effort?
Either way works for me.

https://github.com/llvm/llvm-project/pull/70282
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] d9308aa - [clang] don't mark as Elidable CXXConstruct expressions used in NRVO

2021-09-21 Thread Matheus Izvekov via cfe-commits

Author: Matheus Izvekov
Date: 2021-09-21T21:41:20+02:00
New Revision: d9308aa39b236064a680ca57178af3c731e13e49

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

LOG: [clang] don't mark as Elidable CXXConstruct expressions used in NRVO

See PR51862.

The consumers of the Elidable flag in CXXConstructExpr assume that
an elidable construction just goes through a single copy/move construction,
so that the source object is immediately passed as an argument and is the same
type as the parameter itself.

With the implementation of P2266 and after some adjustments to the
implementation of P1825, we started (correctly, as per standard)
allowing more cases where the copy initialization goes through
user defined conversions.

With this patch we stop using this flag in NRVO contexts, to preserve code
that relies on that assumption.
This causes no known functional changes, we just stop firing some asserts
in a cople of included test cases.

Reviewed By: rsmith

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

Added: 
clang/test/CodeGenCXX/copy-elision.cpp

Modified: 
clang/include/clang/Sema/Initialization.h
clang/lib/AST/ExprConstant.cpp
clang/lib/CodeGen/CGExprCXX.cpp
clang/lib/Sema/Sema.cpp
clang/lib/Sema/SemaCoroutine.cpp
clang/lib/Sema/SemaDeclCXX.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/lib/Sema/SemaLambda.cpp
clang/lib/Sema/SemaObjCProperty.cpp
clang/lib/Sema/SemaStmt.cpp
clang/test/CodeGen/nrvo-tracking.cpp

Removed: 




diff  --git a/clang/include/clang/Sema/Initialization.h 
b/clang/include/clang/Sema/Initialization.h
index 4664861c4e32a..8c1856f208279 100644
--- a/clang/include/clang/Sema/Initialization.h
+++ b/clang/include/clang/Sema/Initialization.h
@@ -298,8 +298,8 @@ class alignas(8) InitializedEntity {
 
   /// Create the initialization entity for the result of a function.
   static InitializedEntity InitializeResult(SourceLocation ReturnLoc,
-QualType Type, bool NRVO) {
-return InitializedEntity(EK_Result, ReturnLoc, Type, NRVO);
+QualType Type) {
+return InitializedEntity(EK_Result, ReturnLoc, Type);
   }
 
   static InitializedEntity InitializeStmtExprResult(SourceLocation ReturnLoc,
@@ -308,20 +308,20 @@ class alignas(8) InitializedEntity {
   }
 
   static InitializedEntity InitializeBlock(SourceLocation BlockVarLoc,
-   QualType Type, bool NRVO) {
-return InitializedEntity(EK_BlockElement, BlockVarLoc, Type, NRVO);
+   QualType Type) {
+return InitializedEntity(EK_BlockElement, BlockVarLoc, Type);
   }
 
   static InitializedEntity InitializeLambdaToBlock(SourceLocation BlockVarLoc,
-   QualType Type, bool NRVO) {
+   QualType Type) {
 return InitializedEntity(EK_LambdaToBlockConversionBlockElement,
- BlockVarLoc, Type, NRVO);
+ BlockVarLoc, Type);
   }
 
   /// Create the initialization entity for an exception object.
   static InitializedEntity InitializeException(SourceLocation ThrowLoc,
-   QualType Type, bool NRVO) {
-return InitializedEntity(EK_Exception, ThrowLoc, Type, NRVO);
+   QualType Type) {
+return InitializedEntity(EK_Exception, ThrowLoc, Type);
   }
 
   /// Create the initialization entity for an object allocated via new.

diff  --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 296e9e7e5995e..ea7818c43e321 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -9933,10 +9933,19 @@ bool RecordExprEvaluator::VisitCXXConstructExpr(const 
CXXConstructExpr *E,
 return false;
 
   // Avoid materializing a temporary for an elidable copy/move constructor.
-  if (E->isElidable() && !ZeroInit)
-if (const MaterializeTemporaryExpr *ME
-  = dyn_cast(E->getArg(0)))
+  if (E->isElidable() && !ZeroInit) {
+// FIXME: This only handles the simplest case, where the source object
+//is passed directly as the first argument to the constructor.
+//This should also handle stepping though implicit casts and
+//and conversion sequences which involve two steps, with a
+//conversion operator followed by a converting constructor.
+const Expr *SrcObj = E->getArg(0);
+assert(SrcObj->isTemporaryObject(Info.Ctx, FD->getParent()));
+assert(Info.Ctx.hasSameUnqualifiedType(E->getType(), SrcObj->getType()));
+if (const MaterializeTemporaryEx

[clang] 37adc4f - [clang] set templates as invalid when any of the parameters are invalid

2021-09-24 Thread Matheus Izvekov via cfe-commits

Author: Matheus Izvekov
Date: 2021-09-25T04:04:47+02:00
New Revision: 37adc4f957c2383a625e2e593ba1d18a25d92b91

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

LOG: [clang] set templates as invalid when any of the parameters are invalid

See PR51872 for the original repro.

This fixes a crash when converting a templated constructor into a deduction
guide, in case any of the template parameters were invalid.

Signed-off-by: Matheus Izvekov 

Reviewed By: rsmith

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

Added: 


Modified: 
clang/lib/AST/DeclTemplate.cpp
clang/test/SemaTemplate/deduction-crash.cpp

Removed: 




diff  --git a/clang/lib/AST/DeclTemplate.cpp b/clang/lib/AST/DeclTemplate.cpp
index a25185067b9c5..fa73c53866490 100644
--- a/clang/lib/AST/DeclTemplate.cpp
+++ b/clang/lib/AST/DeclTemplate.cpp
@@ -165,14 +165,20 @@ unsigned TemplateParameterList::getDepth() const {
 return cast(FirstParm)->getDepth();
 }
 
-static void AdoptTemplateParameterList(TemplateParameterList *Params,
+static bool AdoptTemplateParameterList(TemplateParameterList *Params,
DeclContext *Owner) {
+  bool Invalid = false;
   for (NamedDecl *P : *Params) {
 P->setDeclContext(Owner);
 
 if (const auto *TTP = dyn_cast(P))
-  AdoptTemplateParameterList(TTP->getTemplateParameters(), Owner);
+  if (AdoptTemplateParameterList(TTP->getTemplateParameters(), Owner))
+Invalid = true;
+
+if (P->isInvalidDecl())
+  Invalid = true;
   }
+  return Invalid;
 }
 
 void TemplateParameterList::
@@ -339,14 +345,15 @@ void RedeclarableTemplateDecl::addSpecializationImpl(
 // FunctionTemplateDecl Implementation
 
//===--===//
 
-FunctionTemplateDecl *FunctionTemplateDecl::Create(ASTContext &C,
-   DeclContext *DC,
-   SourceLocation L,
-   DeclarationName Name,
-   TemplateParameterList *Params,
-   NamedDecl *Decl) {
-  AdoptTemplateParameterList(Params, cast(Decl));
-  return new (C, DC) FunctionTemplateDecl(C, DC, L, Name, Params, Decl);
+FunctionTemplateDecl *
+FunctionTemplateDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L,
+ DeclarationName Name,
+ TemplateParameterList *Params, NamedDecl *Decl) {
+  bool Invalid = AdoptTemplateParameterList(Params, cast(Decl));
+  auto *TD = new (C, DC) FunctionTemplateDecl(C, DC, L, Name, Params, Decl);
+  if (Invalid)
+TD->setInvalidDecl();
+  return TD;
 }
 
 FunctionTemplateDecl *FunctionTemplateDecl::CreateDeserialized(ASTContext &C,
@@ -438,15 +445,16 @@ void 
FunctionTemplateDecl::mergePrevDecl(FunctionTemplateDecl *Prev) {
 // ClassTemplateDecl Implementation
 
//===--===//
 
-ClassTemplateDecl *ClassTemplateDecl::Create(ASTContext &C,
- DeclContext *DC,
+ClassTemplateDecl *ClassTemplateDecl::Create(ASTContext &C, DeclContext *DC,
  SourceLocation L,
  DeclarationName Name,
  TemplateParameterList *Params,
  NamedDecl *Decl) {
-  AdoptTemplateParameterList(Params, cast(Decl));
-
-  return new (C, DC) ClassTemplateDecl(C, DC, L, Name, Params, Decl);
+  bool Invalid = AdoptTemplateParameterList(Params, cast(Decl));
+  auto *TD = new (C, DC) ClassTemplateDecl(C, DC, L, Name, Params, Decl);
+  if (Invalid)
+TD->setInvalidDecl();
+  return TD;
 }
 
 ClassTemplateDecl *ClassTemplateDecl::CreateDeserialized(ASTContext &C,
@@ -1005,8 +1013,11 @@ ConceptDecl *ConceptDecl::Create(ASTContext &C, 
DeclContext *DC,
  SourceLocation L, DeclarationName Name,
  TemplateParameterList *Params,
  Expr *ConstraintExpr) {
-  AdoptTemplateParameterList(Params, DC);
-  return new (C, DC) ConceptDecl(DC, L, Name, Params, ConstraintExpr);
+  bool Invalid = AdoptTemplateParameterList(Params, DC);
+  auto *TD = new (C, DC) ConceptDecl(DC, L, Name, Params, ConstraintExpr);
+  if (Invalid)
+TD->setInvalidDecl();
+  return TD;
 }
 
 ConceptDecl *ConceptDecl::CreateDeserialized(ASTContext &C,
@@ -1039,7 +1050,8 @@ ClassTemplatePartialSpecializationDecl(ASTContext 
&Context, TagKind TK,
   SpecializedTemplate, Args, Prev

[clang] 1f6458c - [clang] NFC: remove duplicated code around type constraint and templ arg subst

2021-09-29 Thread Matheus Izvekov via cfe-commits

Author: Matheus Izvekov
Date: 2021-09-29T23:05:46+02:00
New Revision: 1f6458cb1944b69f052db463e5f2c6304f16b256

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

LOG: [clang] NFC: remove duplicated code around type constraint and templ arg 
subst

Signed-off-by: Matheus Izvekov 

Reviewed By: rsmith

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

Added: 


Modified: 
clang/include/clang/AST/DeclTemplate.h
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaTemplate.cpp
clang/lib/Sema/SemaTemplateDeduction.cpp
clang/lib/Sema/SemaTemplateInstantiate.cpp
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp

Removed: 




diff  --git a/clang/include/clang/AST/DeclTemplate.h 
b/clang/include/clang/AST/DeclTemplate.h
index d59a0549f4c10..2408f50c074bb 100644
--- a/clang/include/clang/AST/DeclTemplate.h
+++ b/clang/include/clang/AST/DeclTemplate.h
@@ -729,6 +729,10 @@ class DependentFunctionTemplateSpecializationInfo final
   /// Returns the number of explicit template arguments that were given.
   unsigned getNumTemplateArgs() const { return NumArgs; }
 
+  llvm::ArrayRef arguments() const {
+return llvm::makeArrayRef(getTemplateArgs(), getNumTemplateArgs());
+  }
+
   /// Returns the nth template argument.
   const TemplateArgumentLoc &getTemplateArg(unsigned I) const {
 assert(I < getNumTemplateArgs() && "template arg index out of range");

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index bd5cf12183712..64863e3a57813 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -9483,9 +9483,9 @@ class Sema final {
   SubstTemplateName(NestedNameSpecifierLoc QualifierLoc, TemplateName Name,
 SourceLocation Loc,
 const MultiLevelTemplateArgumentList &TemplateArgs);
-  bool Subst(const TemplateArgumentLoc *Args, unsigned NumArgs,
- TemplateArgumentListInfo &Result,
- const MultiLevelTemplateArgumentList &TemplateArgs);
+
+  bool SubstTypeConstraint(TemplateTypeParmDecl *Inst, const TypeConstraint 
*TC,
+   const MultiLevelTemplateArgumentList &TemplateArgs);
 
   bool InstantiateDefaultArgument(SourceLocation CallLoc, FunctionDecl *FD,
   ParmVarDecl *Param);

diff  --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 00fe811860e5f..de05450d48eb1 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -2267,22 +2267,8 @@ struct ConvertConstructorToDeductionGuideTransform {
   TTP->isParameterPack(), TTP->hasTypeConstraint(),
   TTP->isExpandedParameterPack() ?
   llvm::Optional(TTP->getNumExpansionParameters()) : None);
-  if (const auto *TC = TTP->getTypeConstraint()) {
-TemplateArgumentListInfo TransformedArgs;
-const auto *ArgsAsWritten = TC->getTemplateArgsAsWritten();
-if (!ArgsAsWritten ||
-SemaRef.Subst(ArgsAsWritten->getTemplateArgs(),
-  ArgsAsWritten->NumTemplateArgs, TransformedArgs,
-  Args))
-  SemaRef.AttachTypeConstraint(
-  TC->getNestedNameSpecifierLoc(), TC->getConceptNameInfo(),
-  TC->getNamedConcept(), ArgsAsWritten ? &TransformedArgs : 
nullptr,
-  NewTTP,
-  NewTTP->isParameterPack()
- ? cast(TC->getImmediatelyDeclaredConstraint())
- ->getEllipsisLoc()
- : SourceLocation());
-  }
+  if (const auto *TC = TTP->getTypeConstraint())
+SemaRef.SubstTypeConstraint(NewTTP, TC, Args);
   if (TTP->hasDefaultArgument()) {
 TypeSourceInfo *InstantiatedDefaultArg =
 SemaRef.SubstType(TTP->getDefaultArgumentInfo(), Args,

diff  --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 
b/clang/lib/Sema/SemaTemplateDeduction.cpp
index 060f42bf9d644..424342df7725b 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -2979,14 +2979,13 @@ FinishTemplateArgumentDeduction(
   auto *Template = Partial->getSpecializedTemplate();
   const ASTTemplateArgumentListInfo *PartialTemplArgInfo =
   Partial->getTemplateArgsAsWritten();
-  const TemplateArgumentLoc *PartialTemplateArgs =
-  PartialTemplArgInfo->getTemplateArgs();
 
   TemplateArgumentListInfo InstArgs(PartialTemplArgInfo->LAngleLoc,
 PartialTemplArgInfo->RAngleLoc);
 
-  if (S.Subst(PartialTemplateArgs, PartialTemplArgInfo->NumTemplateArgs,
-  InstArgs, MultiLevelTemplateArgumentList(*DeducedArgumentList))) 
{
+  if (S.SubstTemplateArguments(
+  PartialTemplArgInfo->arguments(),
+  MultiLevelTemp

[clang] af10d6f - [clang] don't instantiate templates with injected arguments

2021-09-29 Thread Matheus Izvekov via cfe-commits

Author: Matheus Izvekov
Date: 2021-09-29T23:19:13+02:00
New Revision: af10d6f350ff3e92c6ffae66cc9dac36884cdd55

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

LOG: [clang] don't instantiate templates with injected arguments

There is a special situation with templates in local classes,
as can be seen in this example with generic lambdas in function scope:
```
template void foo() {
(void)[]() {
  struct S {
void bar() { (void)[](T2) {}; }
  };
};
};
template void foo();
```

As a consequence of the resolution of DR1484, bar is instantiated during the
substitution of foo, and in this context we would substitute the lambda within
it with it's own parameters "injected" (turned into arguments).

This can't be properly dealt with for at least a couple of reasons:
* The 'TemplateTypeParm' type itself can only deal with canonical replacement
  types, which the injected arguments are not.
* If T3 were constrained in the example above, our (non-conforming) eager
  substitution of type constraints would just leave that parameter dangling.

Instead of substituting with injected parameters, this patch just leaves those
inner levels unreplaced.

Since injected arguments appear to be unused within the users of
`getTemplateInstantiationArgs`, this patch just removes that support there and
leaves a couple of asserts in place.

Signed-off-by: Matheus Izvekov 

Reviewed By: rsmith

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

Added: 
clang/test/SemaTemplate/generic-lambda.cpp

Modified: 
clang/lib/Sema/SemaTemplateInstantiate.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index 3a09badf84960..a0f4d0cd8c241 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -161,10 +161,9 @@ Sema::getTemplateInstantiationArgs(NamedDecl *D,
 if (isGenericLambdaCallOperatorOrStaticInvokerSpecialization(Function))
   break;
 
-  } else if (FunctionTemplateDecl *FunTmpl
-   = Function->getDescribedFunctionTemplate()) 
{
-// Add the "injected" template arguments.
-Result.addOuterTemplateArguments(FunTmpl->getInjectedTemplateArgs());
+  } else if (Function->getDescribedFunctionTemplate()) {
+assert(Result.getNumSubstitutedLevels() == 0 &&
+   "Outer template not instantiated?");
   }
 
   // If this is a friend declaration and it declares an entity at
@@ -180,11 +179,8 @@ Sema::getTemplateInstantiationArgs(NamedDecl *D,
   }
 } else if (CXXRecordDecl *Rec = dyn_cast(Ctx)) {
   if (ClassTemplateDecl *ClassTemplate = Rec->getDescribedClassTemplate()) 
{
-QualType T = ClassTemplate->getInjectedClassNameSpecialization();
-const TemplateSpecializationType *TST =
-cast(Context.getCanonicalType(T));
-Result.addOuterTemplateArguments(
-llvm::makeArrayRef(TST->getArgs(), TST->getNumArgs()));
+assert(Result.getNumSubstitutedLevels() == 0 &&
+   "Outer template not instantiated?");
 if (ClassTemplate->isMemberSpecialization())
   break;
   }

diff  --git a/clang/test/SemaTemplate/generic-lambda.cpp 
b/clang/test/SemaTemplate/generic-lambda.cpp
new file mode 100644
index 0..fb5fa09ebcc1f
--- /dev/null
+++ b/clang/test/SemaTemplate/generic-lambda.cpp
@@ -0,0 +1,62 @@
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s
+
+// expected-no-diagnostics
+
+template  constexpr bool is_same_v = false;
+template  constexpr bool is_same_v = true;
+template 
+concept is_same = is_same_v;
+
+template  struct X {};
+template 
+concept C1 = is_same>;
+
+template  X>> t1() {
+  return [](T2) -> X> {
+struct S {
+  static X> f() {
+return [](T3) -> X {
+  static_assert(is_same>);
+  static_assert(is_same>);
+  return X();
+}(X());
+  }
+};
+return S::f();
+  }(X());
+};
+template X>> t1();
+
+#if 0 // FIXME: crashes
+template auto t2() {
+  return [](T2) {
+struct S {
+  static auto f() {
+return [](T3) {
+  static_assert(is_same>);
+  static_assert(is_same>);
+  return X();
+}(X());
+  }
+};
+return S::f();
+  }(X());
+};
+template auto t2();
+static_assert(is_same()), X>>>);
+
+template C1>> auto t3() {
+  return [] T2>(T2) -> C1> auto {
+struct S {
+  static auto f() {
+return [] T3>(T3) -> C1 auto {
+  return X();
+}(X());
+  }
+};
+return S::f();
+  }(X());
+};
+template C1>> auto t3();
+static_assert(is_same()), X>>>);
+#endif



___
cfe-commits mailin

[clang] c25572b - [clang] NFC: rename SK_CastDerivedToBaseRValue to SK_CastDerivedToBasePRValue

2021-06-09 Thread Matheus Izvekov via cfe-commits

Author: Matheus Izvekov
Date: 2021-06-09T12:38:59+02:00
New Revision: c25572bf2993438f24b57d859d072e8b2aa975d2

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

LOG: [clang] NFC: rename SK_CastDerivedToBaseRValue to 
SK_CastDerivedToBasePRValue

This is a follow up to the "rvalue-to-prvalue" rename at D103720.

Signed-off-by: Matheus Izvekov 

Depends on D103720

Reviewed By: rsmith

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

Added: 


Modified: 
clang/include/clang/Sema/Initialization.h
clang/lib/Sema/SemaInit.cpp

Removed: 




diff  --git a/clang/include/clang/Sema/Initialization.h 
b/clang/include/clang/Sema/Initialization.h
index 9889d5bcced5..8feb66995f95 100644
--- a/clang/include/clang/Sema/Initialization.h
+++ b/clang/include/clang/Sema/Initialization.h
@@ -804,7 +804,7 @@ class InitializationSequence {
 SK_ResolveAddressOfOverloadedFunction,
 
 /// Perform a derived-to-base cast, producing an rvalue.
-SK_CastDerivedToBaseRValue,
+SK_CastDerivedToBasePRValue,
 
 /// Perform a derived-to-base cast, producing an xvalue.
 SK_CastDerivedToBaseXValue,

diff  --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp
index 430b14853d38..26d681b1340d 100644
--- a/clang/lib/Sema/SemaInit.cpp
+++ b/clang/lib/Sema/SemaInit.cpp
@@ -3457,7 +3457,7 @@ LLVM_DUMP_METHOD void InitializedEntity::dump() const {
 void InitializationSequence::Step::Destroy() {
   switch (Kind) {
   case SK_ResolveAddressOfOverloadedFunction:
-  case SK_CastDerivedToBaseRValue:
+  case SK_CastDerivedToBasePRValue:
   case SK_CastDerivedToBaseXValue:
   case SK_CastDerivedToBaseLValue:
   case SK_BindReference:
@@ -3585,7 +3585,7 @@ void 
InitializationSequence::AddDerivedToBaseCastStep(QualType BaseType,
   Step S;
   switch (VK) {
   case VK_PRValue:
-S.Kind = SK_CastDerivedToBaseRValue;
+S.Kind = SK_CastDerivedToBasePRValue;
 break;
   case VK_XValue: S.Kind = SK_CastDerivedToBaseXValue; break;
   case VK_LValue: S.Kind = SK_CastDerivedToBaseLValue; break;
@@ -8106,7 +8106,7 @@ ExprResult InitializationSequence::Perform(Sema &S,
   // initializer.
   switch (Steps.front().Kind) {
   case SK_ResolveAddressOfOverloadedFunction:
-  case SK_CastDerivedToBaseRValue:
+  case SK_CastDerivedToBasePRValue:
   case SK_CastDerivedToBaseXValue:
   case SK_CastDerivedToBaseLValue:
   case SK_BindReference:
@@ -8191,7 +8191,7 @@ ExprResult InitializationSequence::Perform(Sema &S,
  Step->Function.Function);
   break;
 
-case SK_CastDerivedToBaseRValue:
+case SK_CastDerivedToBasePRValue:
 case SK_CastDerivedToBaseXValue:
 case SK_CastDerivedToBaseLValue: {
   // We have a derived-to-base cast that produces either an rvalue or an
@@ -9617,8 +9617,8 @@ void InitializationSequence::dump(raw_ostream &OS) const {
   OS << "resolve address of overloaded function";
   break;
 
-case SK_CastDerivedToBaseRValue:
-  OS << "derived-to-base (rvalue)";
+case SK_CastDerivedToBasePRValue:
+  OS << "derived-to-base (prvalue)";
   break;
 
 case SK_CastDerivedToBaseXValue:



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


[clang] 667fbcd - [clang] NRVO: Improvements and handling of more cases.

2021-06-10 Thread Matheus Izvekov via cfe-commits

Author: Matheus Izvekov
Date: 2021-06-10T23:02:51+02:00
New Revision: 667fbcdd0b2ee5e78f5ce9789b862e3bbca94644

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

LOG: [clang] NRVO: Improvements and handling of more cases.

This expands NRVO propagation for more cases:

Parse analysis improvement:
* Lambdas and Blocks with dependent return type can have their variables
  marked as NRVO Candidates.

Variable instantiation improvements:
* Fixes crash when instantiating NRVO variables in Blocks.
* Functions, Lambdas, and Blocks which have auto return type have their
  variables' NRVO status propagated. For Blocks with non-auto return type,
  as a limitation, this propagation does not consider the actual return
  type.

This also implements exclusion of VarDecls which are references to
dependent types.

Signed-off-by: Matheus Izvekov 

Reviewed By: Quuxplusone

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

Added: 


Modified: 
clang/include/clang/Sema/Sema.h
clang/lib/Sema/Sema.cpp
clang/lib/Sema/SemaCoroutine.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/lib/Sema/SemaStmt.cpp
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
clang/test/CodeGen/nrvo-tracking.cpp

Removed: 




diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 6ade9d769126..f7ec89a33e00 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -3455,12 +3455,6 @@ class Sema final {
   bool DiagnoseMultipleUserDefinedConversion(Expr *From, QualType ToType);
   bool isSameOrCompatibleFunctionType(CanQualType Param, CanQualType Arg);
 
-  ExprResult PerformMoveOrCopyInitialization(const InitializedEntity &Entity,
- const VarDecl *NRVOCandidate,
- QualType ResultType,
- Expr *Value,
- bool AllowNRVO = true);
-
   bool CanPerformAggregateInitializationForOverloadResolution(
   const InitializedEntity &Entity, InitListExpr *From);
 
@@ -4760,28 +4754,30 @@ class Sema final {
SourceLocation Loc,
unsigned NumParams);
 
-  enum CopyElisionSemanticsKind {
-CES_Strict = 0,
-CES_AllowParameters = 1,
-CES_AllowDifferentTypes = 2,
-CES_AllowExceptionVariables = 4,
-CES_AllowRValueReferenceType = 8,
-CES_ImplicitlyMovableCXX11CXX14CXX17 =
-(CES_AllowParameters | CES_AllowDifferentTypes),
-CES_ImplicitlyMovableCXX20 =
-(CES_AllowParameters | CES_AllowDifferentTypes |
- CES_AllowExceptionVariables | CES_AllowRValueReferenceType),
+  struct NamedReturnInfo {
+const VarDecl *Candidate;
+
+enum Status : uint8_t { None, MoveEligible, MoveEligibleAndCopyElidable };
+Status S;
+
+bool isMoveEligible() const { return S != None; };
+bool isCopyElidable() const { return S == MoveEligibleAndCopyElidable; }
   };
+  NamedReturnInfo getNamedReturnInfo(const Expr *E, bool ForceCXX20 = false);
+  NamedReturnInfo getNamedReturnInfo(const VarDecl *VD,
+ bool ForceCXX20 = false);
+  const VarDecl *getCopyElisionCandidate(NamedReturnInfo &Info,
+ QualType ReturnType);
 
-  VarDecl *getCopyElisionCandidate(QualType ReturnType, Expr *E,
-   CopyElisionSemanticsKind CESK);
-  bool isCopyElisionCandidate(QualType ReturnType, const VarDecl *VD,
-  CopyElisionSemanticsKind CESK);
+  ExprResult PerformMoveOrCopyInitialization(const InitializedEntity &Entity,
+ const NamedReturnInfo &NRInfo,
+ Expr *Value);
 
   StmtResult ActOnReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp,
  Scope *CurScope);
   StmtResult BuildReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp);
-  StmtResult ActOnCapScopeReturnStmt(SourceLocation ReturnLoc, Expr 
*RetValExp);
+  StmtResult ActOnCapScopeReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp,
+ NamedReturnInfo &NRInfo);
 
   StmtResult ActOnGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
  bool IsVolatile, unsigned NumOutputs,

diff  --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index 8fd4c680d3bf..9af247e0ab4f 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -1949,9 +1949,10 @@ static void checkEscapingByref(VarDecl *VD, Sema &S) {
   SourceLocation Loc = VD->getLocation();
   Expr *VarRef =
   new (S.Context) DeclRefExpr(S.Context, VD, false, T, VK

[clang] cbd0054 - [clang] Implement P2266 Simpler implicit move

2021-06-10 Thread Matheus Izvekov via cfe-commits

Author: Matheus Izvekov
Date: 2021-06-11T00:56:06+02:00
New Revision: cbd0054b9eb17ec48f0702e3828209646c8f5ebd

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

LOG: [clang] Implement P2266 Simpler implicit move

This Implements 
[[http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p2266r1.html|P2266 
Simpler implicit move]].

Signed-off-by: Matheus Izvekov 

Reviewed By: Quuxplusone

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

Added: 


Modified: 
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaCoroutine.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/lib/Sema/SemaStmt.cpp
clang/lib/Sema/SemaType.cpp
clang/test/CXX/class/class.init/class.copy.elision/p3.cpp
clang/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p7-cxx14.cpp
clang/test/CXX/drs/dr3xx.cpp
clang/test/CXX/expr/expr.prim/expr.prim.lambda/p4-cxx14.cpp
clang/test/CXX/temp/temp.decls/temp.mem/p5.cpp
clang/test/SemaCXX/constant-expression-cxx11.cpp
clang/test/SemaCXX/constant-expression-cxx14.cpp
clang/test/SemaCXX/coroutine-rvo.cpp
clang/test/SemaCXX/coroutines.cpp
clang/test/SemaCXX/deduced-return-type-cxx14.cpp
clang/test/SemaCXX/return-stack-addr.cpp
clang/test/SemaCXX/warn-return-std-move.cpp

Removed: 




diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index f7ec89a33e00..db389922ae3a 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -4763,7 +4763,7 @@ class Sema final {
 bool isMoveEligible() const { return S != None; };
 bool isCopyElidable() const { return S == MoveEligibleAndCopyElidable; }
   };
-  NamedReturnInfo getNamedReturnInfo(const Expr *E, bool ForceCXX20 = false);
+  NamedReturnInfo getNamedReturnInfo(Expr *&E, bool ForceCXX2b = false);
   NamedReturnInfo getNamedReturnInfo(const VarDecl *VD,
  bool ForceCXX20 = false);
   const VarDecl *getCopyElisionCandidate(NamedReturnInfo &Info,

diff  --git a/clang/lib/Sema/SemaCoroutine.cpp 
b/clang/lib/Sema/SemaCoroutine.cpp
index 187e7a0516d1..cec80436d575 100644
--- a/clang/lib/Sema/SemaCoroutine.cpp
+++ b/clang/lib/Sema/SemaCoroutine.cpp
@@ -994,22 +994,10 @@ StmtResult Sema::BuildCoreturnStmt(SourceLocation Loc, 
Expr *E,
 E = R.get();
   }
 
-  // Move the return value if we can
-  NamedReturnInfo NRInfo = getNamedReturnInfo(E, /*ForceCXX20=*/true);
-  if (NRInfo.isMoveEligible()) {
-InitializedEntity Entity = InitializedEntity::InitializeResult(
-Loc, E->getType(), NRInfo.Candidate);
-ExprResult MoveResult = PerformMoveOrCopyInitialization(Entity, NRInfo, E);
-if (MoveResult.get())
-  E = MoveResult.get();
-  }
-
-  // FIXME: If the operand is a reference to a variable that's about to go out
-  // of scope, we should treat the operand as an xvalue for this overload
-  // resolution.
   VarDecl *Promise = FSI->CoroutinePromise;
   ExprResult PC;
   if (E && (isa(E) || !E->getType()->isVoidType())) {
+getNamedReturnInfo(E, /*ForceCXX2b=*/true);
 PC = buildPromiseCall(*this, Promise, Loc, "return_value", E);
   } else {
 E = MakeFullDiscardedValueExpr(E).get();

diff  --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 784da7889091..a76976070cc5 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -854,10 +854,6 @@ ExprResult Sema::BuildCXXThrow(SourceLocation OpLoc, Expr 
*Ex,
 Diag(OpLoc, diag::err_omp_simd_region_cannot_use_stmt) << "throw";
 
   if (Ex && !Ex->isTypeDependent()) {
-QualType ExceptionObjectTy = Context.getExceptionObjectType(Ex->getType());
-if (CheckCXXThrowOperand(OpLoc, ExceptionObjectTy, Ex))
-  return ExprError();
-
 // Initialize the exception result.  This implicitly weeds out
 // abstract types or types with inaccessible copy constructors.
 
@@ -876,6 +872,10 @@ ExprResult Sema::BuildCXXThrow(SourceLocation OpLoc, Expr 
*Ex,
 NamedReturnInfo NRInfo =
 IsThrownVarInScope ? getNamedReturnInfo(Ex) : NamedReturnInfo();
 
+QualType ExceptionObjectTy = Context.getExceptionObjectType(Ex->getType());
+if (CheckCXXThrowOperand(OpLoc, ExceptionObjectTy, Ex))
+  return ExprError();
+
 InitializedEntity Entity = InitializedEntity::InitializeException(
 OpLoc, ExceptionObjectTy,
 /*NRVO=*/NRInfo.isCopyElidable());

diff  --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index 35d29b8f12dd..7ef50b327678 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -3312,15 +3312,16 @@ Sema::ActOnBreakStmt(SourceLocation BreakLoc, Scope 
*CurScope) {
 /// without considering function return type, if applicable.
 ///
 /// \param E The expression being returned from

[clang] 1e50c3d - [clang] NRVO: Improvements and handling of more cases.

2021-06-12 Thread Matheus Izvekov via cfe-commits

Author: Matheus Izvekov
Date: 2021-06-12T16:43:32+02:00
New Revision: 1e50c3d785f4563873ab1ce86559f2a1285b5678

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

LOG: [clang] NRVO: Improvements and handling of more cases.

This expands NRVO propagation for more cases:

Parse analysis improvement:
* Lambdas and Blocks with dependent return type can have their variables
  marked as NRVO Candidates.

Variable instantiation improvements:
* Fixes crash when instantiating NRVO variables in Blocks.
* Functions, Lambdas, and Blocks which have auto return type have their
  variables' NRVO status propagated. For Blocks with non-auto return type,
  as a limitation, this propagation does not consider the actual return
  type.

This also implements exclusion of VarDecls which are references to
dependent types.

Signed-off-by: Matheus Izvekov 

Reviewed By: Quuxplusone

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

Added: 


Modified: 
clang/include/clang/Sema/Sema.h
clang/lib/Sema/Sema.cpp
clang/lib/Sema/SemaCoroutine.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/lib/Sema/SemaStmt.cpp
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
clang/test/CodeGen/nrvo-tracking.cpp

Removed: 




diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 6ade9d7691266..f7ec89a33e00c 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -3455,12 +3455,6 @@ class Sema final {
   bool DiagnoseMultipleUserDefinedConversion(Expr *From, QualType ToType);
   bool isSameOrCompatibleFunctionType(CanQualType Param, CanQualType Arg);
 
-  ExprResult PerformMoveOrCopyInitialization(const InitializedEntity &Entity,
- const VarDecl *NRVOCandidate,
- QualType ResultType,
- Expr *Value,
- bool AllowNRVO = true);
-
   bool CanPerformAggregateInitializationForOverloadResolution(
   const InitializedEntity &Entity, InitListExpr *From);
 
@@ -4760,28 +4754,30 @@ class Sema final {
SourceLocation Loc,
unsigned NumParams);
 
-  enum CopyElisionSemanticsKind {
-CES_Strict = 0,
-CES_AllowParameters = 1,
-CES_AllowDifferentTypes = 2,
-CES_AllowExceptionVariables = 4,
-CES_AllowRValueReferenceType = 8,
-CES_ImplicitlyMovableCXX11CXX14CXX17 =
-(CES_AllowParameters | CES_AllowDifferentTypes),
-CES_ImplicitlyMovableCXX20 =
-(CES_AllowParameters | CES_AllowDifferentTypes |
- CES_AllowExceptionVariables | CES_AllowRValueReferenceType),
+  struct NamedReturnInfo {
+const VarDecl *Candidate;
+
+enum Status : uint8_t { None, MoveEligible, MoveEligibleAndCopyElidable };
+Status S;
+
+bool isMoveEligible() const { return S != None; };
+bool isCopyElidable() const { return S == MoveEligibleAndCopyElidable; }
   };
+  NamedReturnInfo getNamedReturnInfo(const Expr *E, bool ForceCXX20 = false);
+  NamedReturnInfo getNamedReturnInfo(const VarDecl *VD,
+ bool ForceCXX20 = false);
+  const VarDecl *getCopyElisionCandidate(NamedReturnInfo &Info,
+ QualType ReturnType);
 
-  VarDecl *getCopyElisionCandidate(QualType ReturnType, Expr *E,
-   CopyElisionSemanticsKind CESK);
-  bool isCopyElisionCandidate(QualType ReturnType, const VarDecl *VD,
-  CopyElisionSemanticsKind CESK);
+  ExprResult PerformMoveOrCopyInitialization(const InitializedEntity &Entity,
+ const NamedReturnInfo &NRInfo,
+ Expr *Value);
 
   StmtResult ActOnReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp,
  Scope *CurScope);
   StmtResult BuildReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp);
-  StmtResult ActOnCapScopeReturnStmt(SourceLocation ReturnLoc, Expr 
*RetValExp);
+  StmtResult ActOnCapScopeReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp,
+ NamedReturnInfo &NRInfo);
 
   StmtResult ActOnGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
  bool IsVolatile, unsigned NumOutputs,

diff  --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index 850c189cc51a3..cdde9a83a6d02 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -1962,9 +1962,10 @@ static void checkEscapingByref(VarDecl *VD, Sema &S) {
   SourceLocation Loc = VD->getLocation();
   Expr *VarRef =
   new (S.Context) DeclRefExpr(S.Context, VD, false, T

[clang] bf20631 - [clang] Implement P2266 Simpler implicit move

2021-06-13 Thread Matheus Izvekov via cfe-commits

Author: Matheus Izvekov
Date: 2021-06-13T12:10:56+02:00
New Revision: bf20631782183cd19e0bb7219e908c2bbb01a75f

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

LOG: [clang] Implement P2266 Simpler implicit move

This Implements 
[[http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p2266r1.html|P2266 
Simpler implicit move]].

Signed-off-by: Matheus Izvekov 

Reviewed By: Quuxplusone

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

Added: 


Modified: 
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaCoroutine.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/lib/Sema/SemaStmt.cpp
clang/lib/Sema/SemaType.cpp
clang/test/CXX/class/class.init/class.copy.elision/p3.cpp
clang/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p7-cxx14.cpp
clang/test/CXX/drs/dr3xx.cpp
clang/test/CXX/expr/expr.prim/expr.prim.lambda/p4-cxx14.cpp
clang/test/CXX/temp/temp.decls/temp.mem/p5.cpp
clang/test/SemaCXX/constant-expression-cxx11.cpp
clang/test/SemaCXX/constant-expression-cxx14.cpp
clang/test/SemaCXX/coroutine-rvo.cpp
clang/test/SemaCXX/coroutines.cpp
clang/test/SemaCXX/deduced-return-type-cxx14.cpp
clang/test/SemaCXX/return-stack-addr.cpp
clang/test/SemaCXX/warn-return-std-move.cpp

Removed: 




diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index f7ec89a33e00c..db389922ae3a1 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -4763,7 +4763,7 @@ class Sema final {
 bool isMoveEligible() const { return S != None; };
 bool isCopyElidable() const { return S == MoveEligibleAndCopyElidable; }
   };
-  NamedReturnInfo getNamedReturnInfo(const Expr *E, bool ForceCXX20 = false);
+  NamedReturnInfo getNamedReturnInfo(Expr *&E, bool ForceCXX2b = false);
   NamedReturnInfo getNamedReturnInfo(const VarDecl *VD,
  bool ForceCXX20 = false);
   const VarDecl *getCopyElisionCandidate(NamedReturnInfo &Info,

diff  --git a/clang/lib/Sema/SemaCoroutine.cpp 
b/clang/lib/Sema/SemaCoroutine.cpp
index 187e7a0516d10..cec80436d575e 100644
--- a/clang/lib/Sema/SemaCoroutine.cpp
+++ b/clang/lib/Sema/SemaCoroutine.cpp
@@ -994,22 +994,10 @@ StmtResult Sema::BuildCoreturnStmt(SourceLocation Loc, 
Expr *E,
 E = R.get();
   }
 
-  // Move the return value if we can
-  NamedReturnInfo NRInfo = getNamedReturnInfo(E, /*ForceCXX20=*/true);
-  if (NRInfo.isMoveEligible()) {
-InitializedEntity Entity = InitializedEntity::InitializeResult(
-Loc, E->getType(), NRInfo.Candidate);
-ExprResult MoveResult = PerformMoveOrCopyInitialization(Entity, NRInfo, E);
-if (MoveResult.get())
-  E = MoveResult.get();
-  }
-
-  // FIXME: If the operand is a reference to a variable that's about to go out
-  // of scope, we should treat the operand as an xvalue for this overload
-  // resolution.
   VarDecl *Promise = FSI->CoroutinePromise;
   ExprResult PC;
   if (E && (isa(E) || !E->getType()->isVoidType())) {
+getNamedReturnInfo(E, /*ForceCXX2b=*/true);
 PC = buildPromiseCall(*this, Promise, Loc, "return_value", E);
   } else {
 E = MakeFullDiscardedValueExpr(E).get();

diff  --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index e9ab2bcd67c2e..20925f95f18e7 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -854,10 +854,6 @@ ExprResult Sema::BuildCXXThrow(SourceLocation OpLoc, Expr 
*Ex,
 Diag(OpLoc, diag::err_omp_simd_region_cannot_use_stmt) << "throw";
 
   if (Ex && !Ex->isTypeDependent()) {
-QualType ExceptionObjectTy = Context.getExceptionObjectType(Ex->getType());
-if (CheckCXXThrowOperand(OpLoc, ExceptionObjectTy, Ex))
-  return ExprError();
-
 // Initialize the exception result.  This implicitly weeds out
 // abstract types or types with inaccessible copy constructors.
 
@@ -876,6 +872,10 @@ ExprResult Sema::BuildCXXThrow(SourceLocation OpLoc, Expr 
*Ex,
 NamedReturnInfo NRInfo =
 IsThrownVarInScope ? getNamedReturnInfo(Ex) : NamedReturnInfo();
 
+QualType ExceptionObjectTy = Context.getExceptionObjectType(Ex->getType());
+if (CheckCXXThrowOperand(OpLoc, ExceptionObjectTy, Ex))
+  return ExprError();
+
 InitializedEntity Entity = InitializedEntity::InitializeException(
 OpLoc, ExceptionObjectTy,
 /*NRVO=*/NRInfo.isCopyElidable());

diff  --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index 136e39198c728..afea878b299a6 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -3312,15 +3312,16 @@ Sema::ActOnBreakStmt(SourceLocation BreakLoc, Scope 
*CurScope) {
 /// without considering function return type, if applicable.
 ///
 /// \param E The expression being retur

[clang] 12c90e2 - [clang] NRVO: Improvements and handling of more cases.

2021-06-16 Thread Matheus Izvekov via cfe-commits

Author: Matheus Izvekov
Date: 2021-06-17T01:56:38+02:00
New Revision: 12c90e2e25dfd1d38250055efc21acb42d158912

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

LOG: [clang] NRVO: Improvements and handling of more cases.

This expands NRVO propagation for more cases:

Parse analysis improvement:
* Lambdas and Blocks with dependent return type can have their variables
  marked as NRVO Candidates.

Variable instantiation improvements:
* Fixes crash when instantiating NRVO variables in Blocks.
* Functions, Lambdas, and Blocks which have auto return type have their
  variables' NRVO status propagated. For Blocks with non-auto return type,
  as a limitation, this propagation does not consider the actual return
  type.

This also implements exclusion of VarDecls which are references to
dependent types.

Signed-off-by: Matheus Izvekov 

Reviewed By: Quuxplusone

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

Added: 
clang/test/SemaObjCXX/block-capture.mm

Modified: 
clang/include/clang/Sema/Sema.h
clang/lib/Sema/Sema.cpp
clang/lib/Sema/SemaCoroutine.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/lib/Sema/SemaStmt.cpp
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
clang/test/CodeGen/nrvo-tracking.cpp

Removed: 




diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 6ade9d7691266..f7ec89a33e00c 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -3455,12 +3455,6 @@ class Sema final {
   bool DiagnoseMultipleUserDefinedConversion(Expr *From, QualType ToType);
   bool isSameOrCompatibleFunctionType(CanQualType Param, CanQualType Arg);
 
-  ExprResult PerformMoveOrCopyInitialization(const InitializedEntity &Entity,
- const VarDecl *NRVOCandidate,
- QualType ResultType,
- Expr *Value,
- bool AllowNRVO = true);
-
   bool CanPerformAggregateInitializationForOverloadResolution(
   const InitializedEntity &Entity, InitListExpr *From);
 
@@ -4760,28 +4754,30 @@ class Sema final {
SourceLocation Loc,
unsigned NumParams);
 
-  enum CopyElisionSemanticsKind {
-CES_Strict = 0,
-CES_AllowParameters = 1,
-CES_AllowDifferentTypes = 2,
-CES_AllowExceptionVariables = 4,
-CES_AllowRValueReferenceType = 8,
-CES_ImplicitlyMovableCXX11CXX14CXX17 =
-(CES_AllowParameters | CES_AllowDifferentTypes),
-CES_ImplicitlyMovableCXX20 =
-(CES_AllowParameters | CES_AllowDifferentTypes |
- CES_AllowExceptionVariables | CES_AllowRValueReferenceType),
+  struct NamedReturnInfo {
+const VarDecl *Candidate;
+
+enum Status : uint8_t { None, MoveEligible, MoveEligibleAndCopyElidable };
+Status S;
+
+bool isMoveEligible() const { return S != None; };
+bool isCopyElidable() const { return S == MoveEligibleAndCopyElidable; }
   };
+  NamedReturnInfo getNamedReturnInfo(const Expr *E, bool ForceCXX20 = false);
+  NamedReturnInfo getNamedReturnInfo(const VarDecl *VD,
+ bool ForceCXX20 = false);
+  const VarDecl *getCopyElisionCandidate(NamedReturnInfo &Info,
+ QualType ReturnType);
 
-  VarDecl *getCopyElisionCandidate(QualType ReturnType, Expr *E,
-   CopyElisionSemanticsKind CESK);
-  bool isCopyElisionCandidate(QualType ReturnType, const VarDecl *VD,
-  CopyElisionSemanticsKind CESK);
+  ExprResult PerformMoveOrCopyInitialization(const InitializedEntity &Entity,
+ const NamedReturnInfo &NRInfo,
+ Expr *Value);
 
   StmtResult ActOnReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp,
  Scope *CurScope);
   StmtResult BuildReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp);
-  StmtResult ActOnCapScopeReturnStmt(SourceLocation ReturnLoc, Expr 
*RetValExp);
+  StmtResult ActOnCapScopeReturnStmt(SourceLocation ReturnLoc, Expr *RetValExp,
+ NamedReturnInfo &NRInfo);
 
   StmtResult ActOnGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple,
  bool IsVolatile, unsigned NumOutputs,

diff  --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index 850c189cc51a3..b87e2c2bea80d 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -1955,6 +1955,9 @@ void Sema::RecordParsingTemplateParameterDepth(unsigned 
Depth) {
 
 // Check that the type of the VarDecl has an accessible copy constru

[clang] b88eb85 - [clang] use correct builtin type for defaulted comparison analyzer

2021-06-16 Thread Matheus Izvekov via cfe-commits

Author: Matheus Izvekov
Date: 2021-06-17T02:08:31+02:00
New Revision: b88eb855b53184161ad1ea0eea1962100941cf0b

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

LOG: [clang] use correct builtin type for defaulted comparison analyzer

Fixes PR50591.

When analyzing classes with members which have user-defined conversion
operators to builtin types, the defaulted comparison analyzer was
picking the member type instead of the type for the builtin operator
which was selected as the best match.

This could either result in wrong comparison category being selected,
or a crash when runtime checks are enabled.

Signed-off-by: Matheus Izvekov 

Reviewed By: rsmith

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

Added: 


Modified: 
clang/lib/Sema/SemaDeclCXX.cpp
clang/test/CXX/class/class.compare/class.spaceship/p2.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index fd2d93e490c92..d39837d277045 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -7863,8 +7863,13 @@ class DefaultedComparisonAnalyzer
 return Result::deleted();
   }
 } else {
+  QualType T = Best->BuiltinParamTypes[0];
+  assert(T == Best->BuiltinParamTypes[1] &&
+ "builtin comparison for 
diff erent types?");
+  assert(Best->BuiltinParamTypes[2].isNull() &&
+ "invalid builtin comparison");
   Optional Cat =
-  getComparisonCategoryForBuiltinCmp(Args[0]->getType());
+  getComparisonCategoryForBuiltinCmp(T);
   assert(Cat && "no category for builtin comparison?");
   R.Category = *Cat;
 }

diff  --git a/clang/test/CXX/class/class.compare/class.spaceship/p2.cpp 
b/clang/test/CXX/class/class.compare/class.spaceship/p2.cpp
index 06126a48acf1a..47b14cb5f9616 100644
--- a/clang/test/CXX/class/class.compare/class.spaceship/p2.cpp
+++ b/clang/test/CXX/class/class.compare/class.spaceship/p2.cpp
@@ -172,3 +172,23 @@ namespace PR48856 {
 int C::*x;   // expected-note {{because 
there is no viable three-way comparison function for member 'x'}}
   };
 }
+
+namespace PR50591 {
+  struct a1 {
+operator int() const;
+  };
+  struct b1 {
+auto operator<=>(b1 const &) const = default;
+a1 f;
+  };
+  std::strong_ordering cmp_b1 = b1() <=> b1();
+
+  struct a2 {
+operator float() const;
+  };
+  struct b2 {
+auto operator<=>(b2 const &) const = default;
+a2 f;
+  };
+  std::partial_ordering cmp_b2 = b2() <=> b2();
+}



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


[clang] 7ddd15c - [clang] Exclude function pointers on DefaultedComparisonAnalyzer

2021-06-18 Thread Matheus Izvekov via cfe-commits

Author: Matheus Izvekov
Date: 2021-06-18T13:07:47+02:00
New Revision: 7ddd15cd5dea76a19a9c5315e2a9903d74a49be8

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

LOG: [clang] Exclude function pointers on DefaultedComparisonAnalyzer

This implements a more comprehensive fix than was done at D95409.
Instead of excluding just function pointer subobjects, we also
exclude any user-defined function pointer conversion operators.

Signed-off-by: Matheus Izvekov 

Reviewed By: rsmith

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

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaDeclCXX.cpp
clang/test/CXX/class/class.compare/class.spaceship/p2.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index c07e6f9d7421a..33aa5d0483e9c 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -9143,6 +9143,9 @@ def 
note_defaulted_comparison_cannot_deduce_undeduced_auto : Note<
   "%select{|member|base class}0 %1 declared here">;
 def note_defaulted_comparison_cannot_deduce_callee : Note<
   "selected 'operator<=>' for %select{|member|base class}0 %1 declared here">;
+def note_defaulted_comparison_selected_invalid : Note<
+  "would compare %select{|member|base class}0 %1 "
+  "as %2, which does not support relational comparisons">;
 def err_incorrect_defaulted_comparison_constexpr : Error<
   "defaulted definition of %select{%sub{select_defaulted_comparison_kind}1|"
   "three-way comparison operator}0 "

diff  --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index d39837d277045..5109f1e877a26 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -7749,16 +7749,11 @@ class DefaultedComparisonAnalyzer
 
 if (Args[0]->getType()->isOverloadableType())
   S.LookupOverloadedBinOp(CandidateSet, OO, Fns, Args);
-else if (OO == OO_EqualEqual ||
- !Args[0]->getType()->isFunctionPointerType()) {
+else
   // FIXME: We determine whether this is a valid expression by checking to
   // see if there's a viable builtin operator candidate for it. That isn't
   // really what the rules ask us to do, but should give the right results.
-  //
-  // Note that the builtin operator for relational comparisons on function
-  // pointers is the only known case which cannot be used.
   S.AddBuiltinOperatorCandidates(OO, FD->getLocation(), Args, 
CandidateSet);
-}
 
 Result R;
 
@@ -7802,11 +7797,14 @@ class DefaultedComparisonAnalyzer
   return Result::deleted();
   }
 
-  // C++2a [class.compare.default]p3 [P2002R0]:
-  //   A defaulted comparison function is constexpr-compatible if [...]
-  //   no overlod resolution performed [...] results in a non-constexpr
-  //   function.
+  bool NeedsDeducing =
+  OO == OO_Spaceship && FD->getReturnType()->isUndeducedAutoType();
+
   if (FunctionDecl *BestFD = Best->Function) {
+// C++2a [class.compare.default]p3 [P2002R0]:
+//   A defaulted comparison function is constexpr-compatible if
+//   [...] no overlod resolution performed [...] results in a
+//   non-constexpr function.
 assert(!BestFD->isDeleted() && "wrong overload resolution result");
 // If it's not constexpr, explain why not.
 if (Diagnose == ExplainConstexpr && !BestFD->isConstexpr()) {
@@ -7819,10 +7817,8 @@ class DefaultedComparisonAnalyzer
   return Result::deleted();
 }
 R.Constexpr &= BestFD->isConstexpr();
-  }
 
-  if (OO == OO_Spaceship && FD->getReturnType()->isUndeducedAutoType()) {
-if (auto *BestFD = Best->Function) {
+if (NeedsDeducing) {
   // If any callee has an undeduced return type, deduce it now.
   // FIXME: It's not clear how a failure here should be handled. For
   // now, we produce an eager diagnostic, because that is forward
@@ -7848,10 +7844,9 @@ class DefaultedComparisonAnalyzer
 }
 return Result::deleted();
   }
-  if (auto *Info = S.Context.CompCategories.lookupInfoForType(
-  BestFD->getCallResultType())) {
-R.Category = Info->Kind;
-  } else {
+  auto *Info = S.Context.CompCategories.lookupInfoForType(
+  BestFD->getCallResultType());
+  if (!Info) {
 if (Diagnose == ExplainDeleted) {
   S.Diag(Subobj.Loc, diag::note_defaulted_comparison_cannot_deduce)
   << Subobj.Kind << Subobj.Decl
@@ -7862,12 +7857,25 @@ class DefaultedComparisonAnalyzer
 }
   

[clang] ced6b20 - [clang] Implement P2266 Simpler implicit move

2021-06-18 Thread Matheus Izvekov via cfe-commits

Author: Matheus Izvekov
Date: 2021-06-18T17:08:59+02:00
New Revision: ced6b204d18e6eed611f8ebf27122ec19147ea7a

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

LOG: [clang] Implement P2266 Simpler implicit move

This Implements 
[[http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2021/p2266r1.html|P2266 
Simpler implicit move]].

Signed-off-by: Matheus Izvekov 

Reviewed By: Quuxplusone

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

Added: 


Modified: 
clang/include/clang/Sema/Sema.h
clang/lib/Sema/Sema.cpp
clang/lib/Sema/SemaCoroutine.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/lib/Sema/SemaStmt.cpp
clang/lib/Sema/SemaType.cpp
clang/test/CXX/class/class.init/class.copy.elision/p3.cpp
clang/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p7-cxx14.cpp
clang/test/CXX/drs/dr3xx.cpp
clang/test/CXX/expr/expr.prim/expr.prim.lambda/p4-cxx14.cpp
clang/test/CXX/temp/temp.decls/temp.mem/p5.cpp
clang/test/SemaCXX/constant-expression-cxx11.cpp
clang/test/SemaCXX/constant-expression-cxx14.cpp
clang/test/SemaCXX/coroutine-rvo.cpp
clang/test/SemaCXX/coroutines.cpp
clang/test/SemaCXX/deduced-return-type-cxx14.cpp
clang/test/SemaCXX/return-stack-addr.cpp
clang/test/SemaCXX/warn-return-std-move.cpp
clang/test/SemaObjCXX/block-capture.mm
clang/www/cxx_status.html

Removed: 




diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index f7ec89a33e00c..db389922ae3a1 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -4763,7 +4763,7 @@ class Sema final {
 bool isMoveEligible() const { return S != None; };
 bool isCopyElidable() const { return S == MoveEligibleAndCopyElidable; }
   };
-  NamedReturnInfo getNamedReturnInfo(const Expr *E, bool ForceCXX20 = false);
+  NamedReturnInfo getNamedReturnInfo(Expr *&E, bool ForceCXX2b = false);
   NamedReturnInfo getNamedReturnInfo(const VarDecl *VD,
  bool ForceCXX20 = false);
   const VarDecl *getCopyElisionCandidate(NamedReturnInfo &Info,

diff  --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index b87e2c2bea80d..b450216dcc8b7 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -1965,9 +1965,17 @@ static void checkEscapingByref(VarDecl *VD, Sema &S) {
   SourceLocation Loc = VD->getLocation();
   Expr *VarRef =
   new (S.Context) DeclRefExpr(S.Context, VD, false, T, VK_LValue, Loc);
-  ExprResult Result = S.PerformMoveOrCopyInitialization(
-  InitializedEntity::InitializeBlock(Loc, T, false),
-  Sema::NamedReturnInfo{VD, Sema::NamedReturnInfo::MoveEligible}, VarRef);
+  ExprResult Result;
+  auto IE = InitializedEntity::InitializeBlock(Loc, T, false);
+  if (S.getLangOpts().CPlusPlus2b) {
+auto *E = ImplicitCastExpr::Create(S.Context, T, CK_NoOp, VarRef, nullptr,
+   VK_XValue, FPOptionsOverride());
+Result = S.PerformCopyInitialization(IE, SourceLocation(), E);
+  } else {
+Result = S.PerformMoveOrCopyInitialization(
+IE, Sema::NamedReturnInfo{VD, Sema::NamedReturnInfo::MoveEligible},
+VarRef);
+  }
 
   if (!Result.isInvalid()) {
 Result = S.MaybeCreateExprWithCleanups(Result);

diff  --git a/clang/lib/Sema/SemaCoroutine.cpp 
b/clang/lib/Sema/SemaCoroutine.cpp
index 187e7a0516d10..cec80436d575e 100644
--- a/clang/lib/Sema/SemaCoroutine.cpp
+++ b/clang/lib/Sema/SemaCoroutine.cpp
@@ -994,22 +994,10 @@ StmtResult Sema::BuildCoreturnStmt(SourceLocation Loc, 
Expr *E,
 E = R.get();
   }
 
-  // Move the return value if we can
-  NamedReturnInfo NRInfo = getNamedReturnInfo(E, /*ForceCXX20=*/true);
-  if (NRInfo.isMoveEligible()) {
-InitializedEntity Entity = InitializedEntity::InitializeResult(
-Loc, E->getType(), NRInfo.Candidate);
-ExprResult MoveResult = PerformMoveOrCopyInitialization(Entity, NRInfo, E);
-if (MoveResult.get())
-  E = MoveResult.get();
-  }
-
-  // FIXME: If the operand is a reference to a variable that's about to go out
-  // of scope, we should treat the operand as an xvalue for this overload
-  // resolution.
   VarDecl *Promise = FSI->CoroutinePromise;
   ExprResult PC;
   if (E && (isa(E) || !E->getType()->isVoidType())) {
+getNamedReturnInfo(E, /*ForceCXX2b=*/true);
 PC = buildPromiseCall(*this, Promise, Loc, "return_value", E);
   } else {
 E = MakeFullDiscardedValueExpr(E).get();

diff  --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 9d554b5b3a909..a57c5ad198e1b 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -854,10 +854,6 @@ ExprResult Sema::BuildCXXThrow(SourceLocation OpLoc, Expr 
*Ex,
 Diag(OpLoc, diag::err_omp_simd_region_ca

[clang] 219790c - [clang] fix canonicalization of nested name specifiers

2021-08-03 Thread Matheus Izvekov via cfe-commits

Author: Matheus Izvekov
Date: 2021-08-03T22:39:48+02:00
New Revision: 219790c1f53665a8b5f7578472e5c2675f9bec6a

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

LOG: [clang] fix canonicalization of nested name specifiers

See PR47174.

When canonicalizing nested name specifiers of the type kind,
the prefix for 'DependentTemplateSpecialization' types was being
dropped, leading to malformed types which would cause failures
when rebuilding template names.

Signed-off-by: Matheus Izvekov 

Reviewed By: rsmith

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

Added: 


Modified: 
clang/include/clang/Sema/Sema.h
clang/lib/AST/ASTContext.cpp
clang/lib/Sema/SemaDeclCXX.cpp
clang/lib/Sema/SemaTemplate.cpp
clang/test/CXX/temp/temp.constr/temp.constr.normal/p1.cpp

Removed: 




diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 07b7e61821f7..854070aee428 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -7830,8 +7830,7 @@ class Sema final {
  TemplateArgumentLoc &Arg,
SmallVectorImpl &Converted);
 
-  bool CheckTemplateArgument(TemplateTypeParmDecl *Param,
- TypeSourceInfo *Arg);
+  bool CheckTemplateArgument(TypeSourceInfo *Arg);
   ExprResult CheckTemplateArgument(NonTypeTemplateParmDecl *Param,
QualType InstantiatedParamType, Expr *Arg,
TemplateArgument &Converted,

diff  --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 4c16ddc782fa..4ff2aa5307bb 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -6089,9 +6089,11 @@ 
ASTContext::getCanonicalNestedNameSpecifier(NestedNameSpecifier *NNS) const {
 NNS->getAsNamespaceAlias()->getNamespace()
   
->getOriginalNamespace());
 
+  // The 
diff erence between TypeSpec and TypeSpecWithTemplate is that the
+  // latter will have the 'template' keyword when printed.
   case NestedNameSpecifier::TypeSpec:
   case NestedNameSpecifier::TypeSpecWithTemplate: {
-QualType T = getCanonicalType(QualType(NNS->getAsType(), 0));
+const Type *T = getCanonicalType(NNS->getAsType());
 
 // If we have some kind of dependent-named type (e.g., "typename T::type"),
 // break it apart into its prefix and identifier, then reconsititute those
@@ -6101,14 +6103,16 @@ 
ASTContext::getCanonicalNestedNameSpecifier(NestedNameSpecifier *NNS) const {
 //   typedef typename T::type T1;
 //   typedef typename T1::type T2;
 if (const auto *DNT = T->getAs())
-  return NestedNameSpecifier::Create(*this, DNT->getQualifier(),
-   const_cast(DNT->getIdentifier()));
-
-// Otherwise, just canonicalize the type, and force it to be a TypeSpec.
-// FIXME: Why are TypeSpec and TypeSpecWithTemplate distinct in the
-// first place?
+  return NestedNameSpecifier::Create(
+  *this, DNT->getQualifier(),
+  const_cast(DNT->getIdentifier()));
+if (const auto *DTST = T->getAs())
+  return NestedNameSpecifier::Create(*this, DTST->getQualifier(), true,
+ const_cast(T));
+
+// TODO: Set 'Template' parameter to true for other template types.
 return NestedNameSpecifier::Create(*this, nullptr, false,
-   const_cast(T.getTypePtr()));
+   const_cast(T));
   }
 
   case NestedNameSpecifier::Global:

diff  --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 72b277821978..708b5cd8cb76 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -12472,6 +12472,8 @@ bool Sema::CheckUsingDeclRedeclaration(SourceLocation 
UsingLoc,
 return false;
   }
 
+  const NestedNameSpecifier *CNNS =
+  Context.getCanonicalNestedNameSpecifier(Qual);
   for (LookupResult::iterator I = Prev.begin(), E = Prev.end(); I != E; ++I) {
 NamedDecl *D = *I;
 
@@ -12497,8 +12499,7 @@ bool Sema::CheckUsingDeclRedeclaration(SourceLocation 
UsingLoc,
 // using decls 
diff er if they name 
diff erent scopes (but note that
 // template instantiation can cause this check to trigger when it
 // didn't before instantiation).
-if (Context.getCanonicalNestedNameSpecifier(Qual) !=
-Context.getCanonicalNestedNameSpecifier(DQual))
+if (CNNS != Context.getCanonicalNestedNameSpecifier(DQual))
   continue;
 
 Diag(NameLoc, diag::err_using_decl_redeclaration) << SS.getRange();

diff  --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplat

[clang] e64e692 - [clang] fix crash on template instantiation of invalid requires expressions

2021-08-03 Thread Matheus Izvekov via cfe-commits

Author: Matheus Izvekov
Date: 2021-08-03T23:16:04+02:00
New Revision: e64e6924b8aef8d48117beb6e87162109ac2512c

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

LOG: [clang] fix crash on template instantiation of invalid requires expressions

See PR48656.

The implementation of the template instantiation of requires expressions
was incorrectly trying to get the expression from an 'ExprRequirement'
before checking if it was an error state.

Signed-off-by: Matheus Izvekov 

Reviewed By: rsmith

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

Added: 


Modified: 
clang/lib/Sema/SemaTemplateInstantiate.cpp
clang/test/CXX/expr/expr.prim/expr.prim.req/type-requirement.cpp
clang/test/CXX/temp/temp.constr/temp.constr.normal/p1.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index f18f77d3442a..74889aa3ca88 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -1934,25 +1934,23 @@ 
TemplateInstantiator::TransformExprRequirement(concepts::ExprRequirement *Req) {
 return Req;
 
   Sema::SFINAETrap Trap(SemaRef);
-  TemplateDeductionInfo Info(Req->getExpr()->getBeginLoc());
 
   llvm::PointerUnion
   TransExpr;
   if (Req->isExprSubstitutionFailure())
 TransExpr = Req->getExprSubstitutionDiagnostic();
   else {
-Sema::InstantiatingTemplate ExprInst(SemaRef, 
Req->getExpr()->getBeginLoc(),
- Req, Info,
- Req->getExpr()->getSourceRange());
+Expr *E = Req->getExpr();
+TemplateDeductionInfo Info(E->getBeginLoc());
+Sema::InstantiatingTemplate ExprInst(SemaRef, E->getBeginLoc(), Req, Info,
+ E->getSourceRange());
 if (ExprInst.isInvalid())
   return nullptr;
-ExprResult TransExprRes = TransformExpr(Req->getExpr());
+ExprResult TransExprRes = TransformExpr(E);
 if (TransExprRes.isInvalid() || Trap.hasErrorOccurred())
-  TransExpr = createSubstDiag(SemaRef, Info,
-  [&] (llvm::raw_ostream& OS) {
-  Req->getExpr()->printPretty(OS, nullptr,
-  SemaRef.getPrintingPolicy());
-  });
+  TransExpr = createSubstDiag(SemaRef, Info, [&](llvm::raw_ostream &OS) {
+E->printPretty(OS, nullptr, SemaRef.getPrintingPolicy());
+  });
 else
   TransExpr = TransExprRes.get();
   }
@@ -1966,6 +1964,7 @@ 
TemplateInstantiator::TransformExprRequirement(concepts::ExprRequirement *Req) {
   else if (RetReq.isTypeConstraint()) {
 TemplateParameterList *OrigTPL =
 RetReq.getTypeConstraintTemplateParameterList();
+TemplateDeductionInfo Info(OrigTPL->getTemplateLoc());
 Sema::InstantiatingTemplate TPLInst(SemaRef, OrigTPL->getTemplateLoc(),
 Req, Info, OrigTPL->getSourceRange());
 if (TPLInst.isInvalid())

diff  --git a/clang/test/CXX/expr/expr.prim/expr.prim.req/type-requirement.cpp 
b/clang/test/CXX/expr/expr.prim/expr.prim.req/type-requirement.cpp
index 15cbe6637845..5433cfb21955 100644
--- a/clang/test/CXX/expr/expr.prim/expr.prim.req/type-requirement.cpp
+++ b/clang/test/CXX/expr/expr.prim/expr.prim.req/type-requirement.cpp
@@ -192,3 +192,29 @@ namespace std_example {
   using c3 = C2_check; // expected-error{{constraints not satisfied 
for class template 'C2_check' [with T = std_example::has_inner]}}
   using c4 = C3_check; // expected-error{{constraints not satisfied for 
class template 'C3_check' [with T = void]}}
 }
+
+namespace PR48656 {
+
+template  concept C = requires { requires requires { T::a; }; };
+// expected-note@-1 {{because 'T::a' would be invalid: no member named 'a' in 
'PR48656::T1'}}
+
+template  struct A {};
+// expected-note@-1 {{because 'PR48656::T1' does not satisfy 'C'}}
+
+struct T1 {};
+template struct A; // expected-error {{constraints not satisfied for class 
template 'A' [with $0 = ]}}
+
+struct T2 { static constexpr bool a = false; };
+template struct A;
+
+template  struct T3 {
+  static void m(auto) requires requires { T::fail; } {}
+  // expected-note@-1 {{constraints not satisfied}}
+  // expected-note@-2 {{type 'int' cannot be used prior to '::'}}
+};
+template  void t3(Args... args) { (..., T3::m(args)); }
+// expected-error@-1 {{no matching function for call to 'm'}}
+
+template void t3(int); // expected-note {{requested here}}
+
+} // namespace PR48656

diff  --git a/clang/test/CXX/temp/temp.constr/temp.constr.normal/p1.cpp 
b/clang/test/CXX/temp/temp.constr/temp.constr.normal/p1.cpp
index 593902c6b74d..d80710937cdf 100644
--- a/clang/test/CXX/temp/temp.constr/temp.constr.normal/p1.cpp
+++ b/clang/test/CXX/temp/temp.c

[clang] ad14b5b - [clang] Stop providing builtin overload candidate for relational function pointer comparisons

2021-06-25 Thread Matheus Izvekov via cfe-commits

Author: Matheus Izvekov
Date: 2021-06-26T00:08:02+02:00
New Revision: ad14b5b008e2f643cb989ec645f12bf26a8659bb

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

LOG: [clang] Stop providing builtin overload candidate for relational function 
pointer comparisons

Word on the grapevine was that the committee had some discussion that
ended with unanimous agreement on eliminating relational function pointer 
comparisons.

We wanted to be bold and just ban all of them cold turkey.
But then we chickened out at the last second and are going for
eliminating just the spaceship overload candidate instead, for now.

See D104680 for reference.

This should be fine and "safe", because the only possible semantic change this
would cause is that overload resolution could possibly be ambiguous if
there was another viable candidate equally as good.

But to save face a little we are going to:
* Issue an "error" for three-way comparisons on function pointers.
  But all this is doing really is changing one vague error message,
  from an "invalid operands to binary expression" into an
  "ordered comparison of function pointers", which sounds more like we mean 
business.
* Otherwise "warn" that comparing function pointers like that is totally
  not cool (unless we are told to keep quiet about this).

Signed-off-by: Matheus Izvekov 

Reviewed By: rsmith

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

Added: 
clang/test/SemaCXX/compare-function-pointer.cpp

Modified: 
clang/include/clang/Basic/DiagnosticGroups.td
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaDeclCXX.cpp
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaOverload.cpp
clang/test/CXX/class/class.compare/class.spaceship/p2.cpp
clang/test/CXX/drs/dr15xx.cpp
clang/test/CXX/drs/dr3xx.cpp
clang/test/CXX/expr/expr.const/p2-0x.cpp
clang/test/FixIt/fixit.cpp
clang/test/Parser/cxx-template-argument.cpp
clang/test/Sema/compare.c
clang/test/SemaCXX/compare-cxx2a.cpp
clang/test/SemaTemplate/resolve-single-template-id.cpp
compiler-rt/test/asan/TestCases/Posix/coverage-module-unloaded.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index ca8e05f27fc5..f35c105964a3 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -525,6 +525,7 @@ def OpenCLUnsupportedRGBA: 
DiagGroup<"opencl-unsupported-rgba">;
 def UnderalignedExceptionObject : DiagGroup<"underaligned-exception-object">;
 def DeprecatedObjCIsaUsage : DiagGroup<"deprecated-objc-isa-usage">;
 def ExplicitInitializeCall : DiagGroup<"explicit-initialize-call">;
+def OrderedCompareFunctionPointers : 
DiagGroup<"ordered-compare-function-pointers">;
 def Packed : DiagGroup<"packed">;
 def Padded : DiagGroup<"padded">;
 

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index b114cdff1d94..b5b8bc6aa3c5 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -6794,9 +6794,14 @@ def ext_typecheck_compare_complete_incomplete_pointers : 
Extension<
   "%0 is %select{|in}2complete and "
   "%1 is %select{|in}3complete">,
   InGroup;
+def warn_typecheck_ordered_comparison_of_function_pointers : Warning<
+  "ordered comparison of function pointers (%0 and %1)">,
+  InGroup;
 def ext_typecheck_ordered_comparison_of_function_pointers : ExtWarn<
   "ordered comparison of function pointers (%0 and %1)">,
-  InGroup>;
+  InGroup;
+def err_typecheck_ordered_comparison_of_function_pointers : Error<
+  "ordered comparison of function pointers (%0 and %1)">;
 def ext_typecheck_comparison_of_fptr_to_void : Extension<
   "equality comparison between function pointer and void pointer (%0 and %1)">;
 def err_typecheck_comparison_of_fptr_to_void : Error<
@@ -9143,9 +9148,6 @@ def 
note_defaulted_comparison_cannot_deduce_undeduced_auto : Note<
   "%select{|member|base class}0 %1 declared here">;
 def note_defaulted_comparison_cannot_deduce_callee : Note<
   "selected 'operator<=>' for %select{|member|base class}0 %1 declared here">;
-def note_defaulted_comparison_selected_invalid : Note<
-  "would compare %select{|member|base class}0 %1 "
-  "as %2, which does not support relational comparisons">;
 def err_incorrect_defaulted_comparison_constexpr : Error<
   "defaulted definition of %select{%sub{select_defaulted_comparison_kind}1|"
   "three-way comparison operator}0 "

diff  --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index a68a06eb4d27..83c97626ff7e 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -7869,15 +7869,6 @@

[clang] d6144c3 - [clang] add C++ feature test macro for P2266 simpler implicit move

2021-06-26 Thread Matheus Izvekov via cfe-commits

Author: Matheus Izvekov
Date: 2021-06-26T23:05:23+02:00
New Revision: d6144c30fb6ae7ac15c82d512f8da7572577c2d2

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

LOG: [clang] add C++ feature test macro for P2266 simpler implicit move

The feature was implemented in D99005, but we forgot to add the test
macro.

Reviewed By: Quuxplusone

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

Added: 


Modified: 
clang/lib/Frontend/InitPreprocessor.cpp
clang/test/Lexer/cxx-features.cpp

Removed: 




diff  --git a/clang/lib/Frontend/InitPreprocessor.cpp 
b/clang/lib/Frontend/InitPreprocessor.cpp
index af1196f131925..bca0bb4ada672 100644
--- a/clang/lib/Frontend/InitPreprocessor.cpp
+++ b/clang/lib/Frontend/InitPreprocessor.cpp
@@ -597,8 +597,10 @@ static void InitializeCPlusPlusFeatureTestMacros(const 
LangOptions &LangOpts,
 Builder.defineMacro("__cpp_using_enum", "201907L");
   }
   // C++2b features.
-  if (LangOpts.CPlusPlus2b)
+  if (LangOpts.CPlusPlus2b) {
+Builder.defineMacro("__cpp_implicit_move", "202011L");
 Builder.defineMacro("__cpp_size_t_suffix", "202011L");
+  }
   if (LangOpts.Char8)
 Builder.defineMacro("__cpp_char8_t", "201811L");
   Builder.defineMacro("__cpp_impl_destroying_delete", "201806L");

diff  --git a/clang/test/Lexer/cxx-features.cpp 
b/clang/test/Lexer/cxx-features.cpp
index 8f283dd8c8d9f..40c73f6019420 100644
--- a/clang/test/Lexer/cxx-features.cpp
+++ b/clang/test/Lexer/cxx-features.cpp
@@ -31,6 +31,10 @@
 
 // --- C++2b features ---
 
+#if check(implicit_move, 0, 0, 0, 0, 0, 202011)
+#error "wrong value for __cpp_implicit_move"
+#endif
+
 #if check(size_t_suffix, 0, 0, 0, 0, 0, 202011)
 #error "wrong value for __cpp_size_t_suffix"
 #endif



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


[clang] 7d2d5a3 - [clang] Apply P1825 as Defect Report from C++11 up to C++20.

2021-07-01 Thread Matheus Izvekov via cfe-commits

Author: Matheus Izvekov
Date: 2021-07-01T12:10:06+02:00
New Revision: 7d2d5a3a6d7aaa40468c30250bf6b0938ef02c08

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

LOG: [clang] Apply P1825 as Defect Report from C++11 up to C++20.

This extends the effects of [[ 
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1825r0.html | P1825 ]] 
to all C++ standards from C++11 up to C++20.

According to Motion 23 from Cologne 2019, P1825R0 was accepted as a Defect 
Report, so we retroactively apply this all the way back to C++11.

Note that we also remove implicit moves from C++98 as an extension
altogether, since the expanded first overload resolution from P1825
can cause some meaning changes in C++98.
For example it can change which copy constructor is picked when both const
and non-const ones are available.

This also rips out warn_return_std_move since there are no cases where it would 
be worthwhile to suggest it.

This also fixes a bug with bailing into the second overload resolution
when encountering a non-rvref qualified conversion operator.
This was unnoticed until now, so two new test cases cover these.

Signed-off-by: Matheus Izvekov 

Reviewed By: rsmith

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

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaStmt.cpp
clang/test/CXX/class/class.init/class.copy.elision/p3.cpp
clang/test/SemaCXX/P1155.cpp
clang/test/SemaCXX/conversion-function.cpp
clang/test/SemaObjCXX/block-capture.mm

Removed: 
clang/test/SemaCXX/warn-return-std-move.cpp



diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 22c2a1a39ea13..a9d7388950331 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -6485,12 +6485,6 @@ def warn_pessimizing_move_on_initialization : Warning<
   InGroup, DefaultIgnore;
 def note_remove_move : Note<"remove std::move call here">;
 
-def warn_return_std_move : Warning<
-  "local variable %0 will be copied despite being %select{returned|thrown}1 by 
name">,
-  InGroup, DefaultIgnore;
-def note_add_std_move : Note<
-  "call 'std::move' explicitly to avoid copying">;
-
 def warn_string_plus_int : Warning<
   "adding %0 to a string does not append to the string">,
   InGroup;

diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 3f7db9bc5be8b..ad987dffac03a 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -4782,8 +4782,7 @@ class Sema final {
 bool isCopyElidable() const { return S == MoveEligibleAndCopyElidable; }
   };
   NamedReturnInfo getNamedReturnInfo(Expr *&E, bool ForceCXX2b = false);
-  NamedReturnInfo getNamedReturnInfo(const VarDecl *VD,
- bool ForceCXX20 = false);
+  NamedReturnInfo getNamedReturnInfo(const VarDecl *VD);
   const VarDecl *getCopyElisionCandidate(NamedReturnInfo &Info,
  QualType ReturnType);
 

diff  --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index afea878b299a6..1e86f382f060b 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -3332,7 +3332,7 @@ Sema::NamedReturnInfo Sema::getNamedReturnInfo(Expr *&E, 
bool ForceCXX2b) {
   const auto *VD = dyn_cast(DR->getDecl());
   if (!VD)
 return NamedReturnInfo();
-  NamedReturnInfo Res = getNamedReturnInfo(VD, /*ForceCXX20=*/ForceCXX2b);
+  NamedReturnInfo Res = getNamedReturnInfo(VD);
   if (Res.Candidate && !E->isXValue() &&
   (ForceCXX2b || getLangOpts().CPlusPlus2b)) {
 E = ImplicitCastExpr::Create(Context, VD->getType().getNonReferenceType(),
@@ -3342,46 +3342,28 @@ Sema::NamedReturnInfo Sema::getNamedReturnInfo(Expr 
*&E, bool ForceCXX2b) {
   return Res;
 }
 
-/// Updates the status in the given NamedReturnInfo object to disallow
-/// copy elision, and optionally also implicit move.
-///
-/// \param Info The NamedReturnInfo object to update.
-///
-/// \param CanMove If true, disallow only copy elision.
-/// If false, also disallow implcit move.
-static void disallowNRVO(Sema::NamedReturnInfo &Info, bool CanMove) {
-  Info.S = std::min(Info.S, CanMove ? Sema::NamedReturnInfo::MoveEligible
-: Sema::NamedReturnInfo::None);
-}
-
 /// Determine whether the given NRVO candidate variable is move-eligible or
 /// copy-elidable, without considering function return type.
 ///
 /// \param VD The NRVO candidate variable.
 ///
-/// \param ForceCXX20 Overrides detection of current language mode
-/// and uses the rules for C++20.
-///
 /// \returns An aggregate which contains the Candidate and

[clang] 2110638 - [clang] fixes named return of variables with dependent alignment

2021-07-05 Thread Matheus Izvekov via cfe-commits

Author: Matheus Izvekov
Date: 2021-07-06T02:30:44+02:00
New Revision: 21106388eb96c87b3f580c42a322c76a61605261

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

LOG: [clang] fixes named return of variables with dependent alignment

Named return of a variable with aligned attribute would
trip an assert in case alignment was dependent.

Signed-off-by: Matheus Izvekov 

Reviewed By: rsmith

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

Added: 


Modified: 
clang/include/clang/AST/Decl.h
clang/lib/AST/Decl.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaStmt.cpp
clang/test/CodeGen/nrvo-tracking.cpp

Removed: 




diff  --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index 020df62755706..d22594ae8442a 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -1494,6 +1494,9 @@ class VarDecl : public DeclaratorDecl, public 
Redeclarable {
 NonParmVarDeclBits.EscapingByref = true;
   }
 
+  /// Determines if this variable's alignment is dependent.
+  bool hasDependentAlignment() const;
+
   /// Retrieve the variable declaration from which this variable could
   /// be instantiated, if it is an instantiation (rather than a non-template).
   VarDecl *getTemplateInstantiationPattern() const;

diff  --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index 5047dc19b0c6f..a92d3726e8474 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -2534,6 +2534,13 @@ bool VarDecl::isNonEscapingByref() const {
   return hasAttr() && !NonParmVarDeclBits.EscapingByref;
 }
 
+bool VarDecl::hasDependentAlignment() const {
+  return getType()->isDependentType() ||
+ llvm::any_of(specific_attrs(), [](const AlignedAttr *AA) 
{
+   return AA->isAlignmentDependent();
+ });
+}
+
 VarDecl *VarDecl::getTemplateInstantiationPattern() const {
   const VarDecl *VD = this;
 

diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 0075464552321..9e1f42a15e556 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -13310,16 +13310,6 @@ void Sema::CheckCompleteVariableDeclaration(VarDecl 
*var) {
 CheckCompleteDecompositionDeclaration(DD);
 }
 
-/// Determines if a variable's alignment is dependent.
-static bool hasDependentAlignment(VarDecl *VD) {
-  if (VD->getType()->isDependentType())
-return true;
-  for (auto *I : VD->specific_attrs())
-if (I->isAlignmentDependent())
-  return true;
-  return false;
-}
-
 /// Check if VD needs to be dllexport/dllimport due to being in a
 /// dllexport/import function.
 void Sema::CheckStaticLocalForDllExport(VarDecl *VD) {
@@ -13408,7 +13398,7 @@ void Sema::FinalizeDeclaration(Decl *ThisDecl) {
   if (unsigned MaxAlign = Context.getTargetInfo().getMaxTLSAlign()) {
 // Protect the check so that it's not performed on dependent types and
 // dependent alignments (we can't determine the alignment in that case).
-if (VD->getTLSKind() && !hasDependentAlignment(VD) &&
+if (VD->getTLSKind() && !VD->hasDependentAlignment() &&
 !VD->isInvalidDecl()) {
   CharUnits MaxAlignChars = Context.toCharUnitsFromBits(MaxAlign);
   if (Context.getDeclAlign(VD) > MaxAlignChars) {

diff  --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index 1e86f382f060b..506c06b412b6f 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -3395,7 +3395,7 @@ Sema::NamedReturnInfo Sema::getNamedReturnInfo(const 
VarDecl *VD) {
 
   // Variables with higher required alignment than their type's ABI
   // alignment cannot use NRVO.
-  if (!VDType->isDependentType() && VD->hasAttr() &&
+  if (!VD->hasDependentAlignment() &&
   Context.getDeclAlign(VD) > Context.getTypeAlignInChars(VDType))
 Info.S = NamedReturnInfo::MoveEligible;
 

diff  --git a/clang/test/CodeGen/nrvo-tracking.cpp 
b/clang/test/CodeGen/nrvo-tracking.cpp
index 7893140e1010a..2d6eb9efeca20 100644
--- a/clang/test/CodeGen/nrvo-tracking.cpp
+++ b/clang/test/CodeGen/nrvo-tracking.cpp
@@ -1,9 +1,9 @@
 // RUN: %clang_cc1 -std=c++20 -fblocks -Wno-return-stack-address -triple 
x86_64-unknown-unknown-gnu -emit-llvm -O1 -fexperimental-new-pass-manager -o - 
%s | FileCheck %s
 
-struct X {
-X();
-X(const X&);
-X(X&&);
+struct alignas(4) X {
+  X();
+  X(const X &);
+  X(X &&);
 };
 
 #define L(A, B, C) void l##A() {\
@@ -210,3 +210,75 @@ void b_attr() {
 };
   }()();
 }
+
+namespace test_alignas {
+
+template  X t1() {
+  X a [[gnu::aligned(A)]];
+  return a;
+}
+
+// CHECK-LABEL: define{{.*}} void @_ZN12test_alignas2t1ILi1EEE1Xv
+// CHECK:   call {{.*}} @_ZN1XC1Ev
+// CHECK-NEXT:  ret void
+template X t1<1>();
+
+// CHECK-LABEL: define{{.*}} void @_ZN12test_alignas2t1ILi4EEE1Xv

[clang] f2d5fce - [clang] fixes named return of variables with dependent alignment

2021-07-06 Thread Matheus Izvekov via cfe-commits

Author: Matheus Izvekov
Date: 2021-07-07T02:54:55+02:00
New Revision: f2d5fce86e81a8b37fbc0829a1c68b6eb48f8365

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

LOG: [clang] fixes named return of variables with dependent alignment

Named return of a variable with aligned attribute would
trip an assert in case alignment was dependent.

Signed-off-by: Matheus Izvekov 

Reviewed By: rsmith

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

Added: 


Modified: 
clang/include/clang/AST/Decl.h
clang/lib/AST/Decl.cpp
clang/lib/Sema/SemaDecl.cpp
clang/lib/Sema/SemaStmt.cpp
clang/test/CXX/class/class.init/class.copy.elision/p3.cpp
clang/test/CodeGen/nrvo-tracking.cpp

Removed: 




diff  --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index 020df62755706..d22594ae8442a 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -1494,6 +1494,9 @@ class VarDecl : public DeclaratorDecl, public 
Redeclarable {
 NonParmVarDeclBits.EscapingByref = true;
   }
 
+  /// Determines if this variable's alignment is dependent.
+  bool hasDependentAlignment() const;
+
   /// Retrieve the variable declaration from which this variable could
   /// be instantiated, if it is an instantiation (rather than a non-template).
   VarDecl *getTemplateInstantiationPattern() const;

diff  --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index 5047dc19b0c6f..5dcfca45a54b6 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -2534,6 +2534,14 @@ bool VarDecl::isNonEscapingByref() const {
   return hasAttr() && !NonParmVarDeclBits.EscapingByref;
 }
 
+bool VarDecl::hasDependentAlignment() const {
+  QualType T = getType();
+  return T->isDependentType() || T->isUndeducedAutoType() ||
+ llvm::any_of(specific_attrs(), [](const AlignedAttr *AA) 
{
+   return AA->isAlignmentDependent();
+ });
+}
+
 VarDecl *VarDecl::getTemplateInstantiationPattern() const {
   const VarDecl *VD = this;
 

diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 0075464552321..700a6db7fea89 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -13310,16 +13310,6 @@ void Sema::CheckCompleteVariableDeclaration(VarDecl 
*var) {
 CheckCompleteDecompositionDeclaration(DD);
 }
 
-/// Determines if a variable's alignment is dependent.
-static bool hasDependentAlignment(VarDecl *VD) {
-  if (VD->getType()->isDependentType())
-return true;
-  for (auto *I : VD->specific_attrs())
-if (I->isAlignmentDependent())
-  return true;
-  return false;
-}
-
 /// Check if VD needs to be dllexport/dllimport due to being in a
 /// dllexport/import function.
 void Sema::CheckStaticLocalForDllExport(VarDecl *VD) {
@@ -13408,8 +13398,7 @@ void Sema::FinalizeDeclaration(Decl *ThisDecl) {
   if (unsigned MaxAlign = Context.getTargetInfo().getMaxTLSAlign()) {
 // Protect the check so that it's not performed on dependent types and
 // dependent alignments (we can't determine the alignment in that case).
-if (VD->getTLSKind() && !hasDependentAlignment(VD) &&
-!VD->isInvalidDecl()) {
+if (VD->getTLSKind() && !VD->hasDependentAlignment()) {
   CharUnits MaxAlignChars = Context.toCharUnitsFromBits(MaxAlign);
   if (Context.getDeclAlign(VD) > MaxAlignChars) {
 Diag(VD->getLocation(), diag::err_tls_var_aligned_over_maximum)

diff  --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index 1e86f382f060b..506c06b412b6f 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -3395,7 +3395,7 @@ Sema::NamedReturnInfo Sema::getNamedReturnInfo(const 
VarDecl *VD) {
 
   // Variables with higher required alignment than their type's ABI
   // alignment cannot use NRVO.
-  if (!VDType->isDependentType() && VD->hasAttr() &&
+  if (!VD->hasDependentAlignment() &&
   Context.getDeclAlign(VD) > Context.getTypeAlignInChars(VDType))
 Info.S = NamedReturnInfo::MoveEligible;
 

diff  --git a/clang/test/CXX/class/class.init/class.copy.elision/p3.cpp 
b/clang/test/CXX/class/class.init/class.copy.elision/p3.cpp
index ed6bec97e0bf2..a85475ece7bf5 100644
--- a/clang/test/CXX/class/class.init/class.copy.elision/p3.cpp
+++ b/clang/test/CXX/class/class.init/class.copy.elision/p3.cpp
@@ -487,3 +487,29 @@ void test5() try {
 }
 
 } // namespace test_simpler_implicit_move
+
+namespace test_auto_variables {
+
+struct S {};
+
+template  struct range {
+  S *begin() const;
+  S *end() const;
+};
+
+template  S test_dependent_ranged_for() {
+  for (auto x : range())
+return x;
+  return S();
+}
+template S test_dependent_ranged_for();
+
+template  struct X {};
+
+template  X test_dependent_invalid_decl() {
+  auto x = X().foo(); // expe

[clang] 2c60d22 - [clang] disable P2266 simpler implicit moves under -fms-compatibility

2021-07-07 Thread Matheus Izvekov via cfe-commits

Author: Matheus Izvekov
Date: 2021-07-08T00:13:11+02:00
New Revision: 2c60d22610325bcd6fb4c4bcc8b522b9fdfb46ee

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

LOG: [clang] disable P2266 simpler implicit moves under -fms-compatibility

The Microsoft STL currently has some issues with P2266.
We disable it for now in that mode, but we might come back later with a
more targetted approach.

Signed-off-by: Matheus Izvekov 

Reviewed By: aaron.ballman

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

Added: 
clang/test/SemaCXX/cxx2b-p2266-disable-with-msvc-compat.cpp

Modified: 
clang/lib/Frontend/InitPreprocessor.cpp
clang/lib/Sema/SemaStmt.cpp

Removed: 




diff  --git a/clang/lib/Frontend/InitPreprocessor.cpp 
b/clang/lib/Frontend/InitPreprocessor.cpp
index bca0bb4ada672..676421552a757 100644
--- a/clang/lib/Frontend/InitPreprocessor.cpp
+++ b/clang/lib/Frontend/InitPreprocessor.cpp
@@ -598,7 +598,8 @@ static void InitializeCPlusPlusFeatureTestMacros(const 
LangOptions &LangOpts,
   }
   // C++2b features.
   if (LangOpts.CPlusPlus2b) {
-Builder.defineMacro("__cpp_implicit_move", "202011L");
+if (!LangOpts.MSVCCompat)
+  Builder.defineMacro("__cpp_implicit_move", "202011L");
 Builder.defineMacro("__cpp_size_t_suffix", "202011L");
   }
   if (LangOpts.Char8)

diff  --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index 506c06b412b6f..59e64c4b1c5b1 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -,8 +,13 @@ Sema::NamedReturnInfo Sema::getNamedReturnInfo(Expr *&E, 
bool ForceCXX2b) {
   if (!VD)
 return NamedReturnInfo();
   NamedReturnInfo Res = getNamedReturnInfo(VD);
+  // FIXME: We supress simpler implicit move here (unless ForceCXX2b is true)
+  //in msvc compatibility mode just as a temporary work around,
+  //as the MSVC STL has issues with this change.
+  //We will come back later with a more targeted approach.
   if (Res.Candidate && !E->isXValue() &&
-  (ForceCXX2b || getLangOpts().CPlusPlus2b)) {
+  (ForceCXX2b ||
+   (getLangOpts().CPlusPlus2b && !getLangOpts().MSVCCompat))) {
 E = ImplicitCastExpr::Create(Context, VD->getType().getNonReferenceType(),
  CK_NoOp, E, nullptr, VK_XValue,
  FPOptionsOverride());

diff  --git a/clang/test/SemaCXX/cxx2b-p2266-disable-with-msvc-compat.cpp 
b/clang/test/SemaCXX/cxx2b-p2266-disable-with-msvc-compat.cpp
new file mode 100644
index 0..2143c0535e606
--- /dev/null
+++ b/clang/test/SemaCXX/cxx2b-p2266-disable-with-msvc-compat.cpp
@@ -0,0 +1,50 @@
+// RUN: %clang_cc1 -std=c++2b -fsyntax-only -fcxx-exceptions   
 -verify=new %s
+// RUN: %clang_cc1 -std=c++2b -fsyntax-only -fcxx-exceptions 
-fms-compatibility -verify=old %s
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -fcxx-exceptions   
 -verify=old %s
+
+// FIXME: This is a test for a temporary workaround where we disable simpler 
implicit moves
+//when compiling with -fms-compatibility, because the MSVC STL does 
not compile.
+//A better workaround is under discussion.
+//The test cases here are just a copy from 
`CXX/class/class.init/class.copy.elision/p3.cpp`,
+//so feel free to delete this file when the workaround is not needed 
anymore.
+
+struct CopyOnly {
+  CopyOnly(); // new-note {{candidate constructor not viable: requires 0 
arguments, but 1 was provided}}
+  // new-note@-1 {{candidate constructor not viable: requires 0 arguments, but 
1 was provided}}
+  CopyOnly(CopyOnly &); // new-note {{candidate constructor not viable: 
expects an lvalue for 1st argument}}
+  // new-note@-1 {{candidate constructor not viable: expects an lvalue for 1st 
argument}}
+};
+struct MoveOnly {
+  MoveOnly();
+  MoveOnly(MoveOnly &&);
+};
+MoveOnly &&rref();
+
+MoveOnly &&test1(MoveOnly &&w) {
+  return w; // old-error {{cannot bind to lvalue of type}}
+}
+
+CopyOnly test2(bool b) {
+  static CopyOnly w1;
+  CopyOnly w2;
+  if (b) {
+return w1;
+  } else {
+return w2; // new-error {{no matching constructor for initialization}}
+  }
+}
+
+template  T &&test3(T &&x) { return x; } // old-error {{cannot bind 
to lvalue of type}}
+template MoveOnly &test3(MoveOnly &);
+template MoveOnly &&test3(MoveOnly &&); // old-note {{in 
instantiation of function template specialization}}
+
+MoveOnly &&test4() {
+  MoveOnly &&x = rref();
+  return x; // old-error {{cannot bind to lvalue of type}}
+}
+
+void test5() try {
+  CopyOnly x;
+  throw x; // new-error {{no matching constructor for initialization}}
+} catch (...) {
+}



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https:/

[clang] 5a1c504 - [clang] fix constexpr code generation for user conversions.

2021-07-08 Thread Matheus Izvekov via cfe-commits

Author: Matheus Izvekov
Date: 2021-07-08T20:23:19+02:00
New Revision: 5a1c50410ccc1973a1a0a4acca0c01677c28e9b6

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

LOG: [clang] fix constexpr code generation for user conversions.

When building the member call to a user conversion function during an
implicit cast, the expression was not being checked for immediate
invocation, so we were never adding the ConstantExpr node to AST.

This would cause the call to the user conversion operator to be emitted
even if it was constantexpr evaluated, and this would even trip an
assert when said user conversion was declared consteval:
`Assertion failed: !cast(GD.getDecl())->isConsteval() && 
"consteval function should never be emitted", file 
clang\lib\CodeGen\CodeGenModule.cpp, line 3530`

Fixes PR48855.

Signed-off-by: Matheus Izvekov 

Reviewed By: rsmith

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

Added: 


Modified: 
clang/lib/AST/Expr.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/test/CodeGenCXX/cxx2a-consteval.cpp

Removed: 




diff  --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index 03dc65eeb6b03..842b9c0a8a0e2 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -1913,6 +1913,7 @@ Expr *CastExpr::getSubExprAsWritten() {
   SubExpr =
 
skipImplicitTemporary(cast(SubExpr->IgnoreImplicit())->getArg(0));
 else if (E->getCastKind() == CK_UserDefinedConversion) {
+  SubExpr = SubExpr->IgnoreImplicit();
   assert((isa(SubExpr) ||
   isa(SubExpr)) &&
  "Unexpected SubExpr for CK_UserDefinedConversion.");

diff  --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index b0b6b3dca5f6a..2e9e9a4a88dff 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -7786,7 +7786,7 @@ ExprResult Sema::BuildCXXMemberCallExpr(Expr *E, 
NamedDecl *FoundDecl,
 Method->getType()->castAs()))
 return ExprError();
 
-  return CE;
+  return CheckForImmediateInvocation(CE, CE->getMethodDecl());
 }
 
 ExprResult Sema::BuildCXXNoexceptExpr(SourceLocation KeyLoc, Expr *Operand,

diff  --git a/clang/test/CodeGenCXX/cxx2a-consteval.cpp 
b/clang/test/CodeGenCXX/cxx2a-consteval.cpp
index e5bd99c6ca537..7ee693ca2 100644
--- a/clang/test/CodeGenCXX/cxx2a-consteval.cpp
+++ b/clang/test/CodeGenCXX/cxx2a-consteval.cpp
@@ -210,3 +210,36 @@ long test_AggCtor() {
   AggCtor C(i);
   return C.a + C.b;
 }
+
+struct UserConv {
+  consteval operator int() const noexcept { return 42; }
+};
+
+// EVAL-FN-LABEL: @_Z13test_UserConvv(
+// EVAL-FN-NEXT:  entry:
+// EVAL-FN-NEXT:ret i32 42
+//
+int test_UserConv() {
+  return UserConv();
+}
+
+int test_UserConvOverload_helper(int a) { return a; }
+
+// EVAL-FN-LABEL: @_Z21test_UserConvOverloadv(
+// EVAL-FN-NEXT:  entry:
+// EVAL-FN-NEXT:%call = call i32 @_Z28test_UserConvOverload_helperi(i32 42)
+// EVAL-FN-NEXT:ret i32 %call
+//
+int test_UserConvOverload() {
+  return test_UserConvOverload_helper(UserConv());
+}
+
+consteval int test_UserConvOverload_helper_ceval(int a) { return a; }
+
+// EVAL-FN-LABEL: @_Z27test_UserConvOverload_cevalv(
+// EVAL-FN-NEXT:  entry:
+// EVAL-FN-NEXT:ret i32 42
+//
+int test_UserConvOverload_ceval() {
+  return test_UserConvOverload_helper_ceval(UserConv());
+}



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


[clang] 03282f2 - [clang] C++98 implicit moves are back with a vengeance

2021-07-13 Thread Matheus Izvekov via cfe-commits

Author: Matheus Izvekov
Date: 2021-07-13T19:16:49+02:00
New Revision: 03282f2fe14e9dd61aaeeda3785f56c7ccb4f3c9

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

LOG: [clang] C++98 implicit moves are back with a vengeance

After taking C++98 implicit moves out in D104500,
we put it back in, but now in a new form which preserves
compatibility with pure C++98 programs, while at the same time
giving almost all the goodies from P1825.

* We use the exact same rules as C++20 with regards to which
  id-expressions are move eligible. The previous
  incarnation would only benefit from the proper subset which is
  copy ellidable. This means we can implicit move, in addition:
  * Parameters.
  * RValue references.
  * Exception variables.
  * Variables with higher-than-natural required alignment.
  * Objects with different type from the function return type.
* We preserve the two-overload resolution, with one small tweak to the
  first one: If we either pick a (possibly converting) constructor which
  does not take an rvalue reference, or a user conversion operator which
  is not ref-qualified, we abort into the second overload resolution.

This gives C++98 almost all the implicit move patterns which we had created test
cases for, while at the same time preserving the meaning of these
three patterns, which are found in pure C++98 programs:
* Classes with both const and non-const copy constructors, but no move
  constructors, continue to have their non-const copy constructor
  selected.
* We continue to reject as ambiguous the following pattern:
```
struct A { A(B &); };
struct B { operator A(); };
A foo(B x) { return x; }
```
* We continue to pick the copy constructor in the following pattern:
```
class AutoPtrRef { };
struct AutoPtr {
  AutoPtr(AutoPtr &);
  AutoPtr();

  AutoPtr(AutoPtrRef);
  operator AutoPtrRef();
};
AutoPtr test_auto_ptr() {
  AutoPtr p;
  return p;
}
```

Signed-off-by: Matheus Izvekov 

Reviewed By: Quuxplusone

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

Added: 


Modified: 
clang/lib/Sema/SemaStmt.cpp
clang/test/CXX/class/class.init/class.copy.elision/p3.cpp
clang/test/SemaCXX/conversion-function.cpp
clang/test/SemaObjCXX/block-capture.mm

Removed: 




diff  --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index fa798c2d557ca..643dde437fc94 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -3451,6 +3451,28 @@ const VarDecl 
*Sema::getCopyElisionCandidate(NamedReturnInfo &Info,
   return Info.isCopyElidable() ? Info.Candidate : nullptr;
 }
 
+/// Verify that the initialization sequence that was picked for the
+/// first overload resolution is permissible under C++98.
+///
+/// Reject (possibly converting) contructors not taking an rvalue reference,
+/// or user conversion operators which are not ref-qualified.
+static bool
+VerifyInitializationSequenceCXX98(const Sema &S,
+  const InitializationSequence &Seq) {
+  const auto *Step = llvm::find_if(Seq.steps(), [](const auto &Step) {
+return Step.Kind == InitializationSequence::SK_ConstructorInitialization ||
+   Step.Kind == InitializationSequence::SK_UserConversion;
+  });
+  if (Step != Seq.step_end()) {
+const auto *FD = Step->Function.Function;
+if (isa(FD)
+? !FD->getParamDecl(0)->getType()->isRValueReferenceType()
+: cast(FD)->getRefQualifier() == RQ_None)
+  return false;
+  }
+  return true;
+}
+
 /// Perform the initialization of a potentially-movable value, which
 /// is the result of return value.
 ///
@@ -3461,8 +3483,7 @@ ExprResult
 Sema::PerformMoveOrCopyInitialization(const InitializedEntity &Entity,
   const NamedReturnInfo &NRInfo,
   Expr *Value) {
-  if (getLangOpts().CPlusPlus11 && !getLangOpts().CPlusPlus2b &&
-  NRInfo.isMoveEligible()) {
+  if (!getLangOpts().CPlusPlus2b && NRInfo.isMoveEligible()) {
 ImplicitCastExpr AsRvalue(ImplicitCastExpr::OnStack, Value->getType(),
   CK_NoOp, Value, VK_XValue, FPOptionsOverride());
 Expr *InitExpr = &AsRvalue;
@@ -3470,7 +3491,9 @@ Sema::PerformMoveOrCopyInitialization(const 
InitializedEntity &Entity,
Value->getBeginLoc());
 InitializationSequence Seq(*this, Entity, Kind, InitExpr);
 auto Res = Seq.getFailedOverloadResult();
-if (Res == OR_Success || Res == OR_Deleted) {
+if ((Res == OR_Success || Res == OR_Deleted) &&
+(getLangOpts().CPlusPlus11 ||
+ VerifyInitializationSequenceCXX98(*this, Seq))) {
   // Promote "AsRvalue" to the heap, since we now need this
   // expression node to persist.
   Value

[clang] 2d7fba5 - [clang] deprecate frelaxed-template-template-args, make it on by default

2021-10-27 Thread Matheus Izvekov via cfe-commits

Author: Matheus Izvekov
Date: 2021-10-27T22:48:27+02:00
New Revision: 2d7fba5f95f0614f6f2c4a4ed966b307d617898b

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

LOG: [clang] deprecate frelaxed-template-template-args, make it on by default

A resolution to the ambiguity issues created by P0522, which is a DR solving
CWG 150, did not come as expected, so we are just going to accept the change,
and watch how users digest it.

For now we deprecate the flag with a warning, and make it on by default.
We don't remove the flag completely in order to give users a chance to
work around any problems by disabling it.

Signed-off-by: Matheus Izvekov 

Reviewed By: rsmith

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

Added: 
clang/test/Driver/frelaxed-template-template-args.cpp

Modified: 
clang/include/clang/Basic/DiagnosticDriverKinds.td
clang/include/clang/Basic/LangOptions.def
clang/include/clang/Driver/Options.td
clang/lib/Driver/SanitizerArgs.cpp
clang/lib/Driver/ToolChains/Clang.cpp
clang/lib/Driver/ToolChains/CommonArgs.cpp
clang/lib/Sema/SemaTemplate.cpp
clang/test/CXX/temp/temp.arg/temp.arg.template/p3-2a.cpp
clang/test/Lexer/cxx-features.cpp
clang/test/SemaTemplate/deduction.cpp
clang/test/SemaTemplate/default-arguments.cpp
clang/test/SemaTemplate/instantiate-template-template-parm.cpp
clang/test/SemaTemplate/nested-template.cpp
clang/test/SemaTemplate/temp_arg_template.cpp
clang/test/SemaTemplate/temp_arg_template_cxx1z.cpp
clang/www/cxx_status.html

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticDriverKinds.td 
b/clang/include/clang/Basic/DiagnosticDriverKinds.td
index 0cf49ed397f60..e013cf25db809 100644
--- a/clang/include/clang/Basic/DiagnosticDriverKinds.td
+++ b/clang/include/clang/Basic/DiagnosticDriverKinds.td
@@ -355,7 +355,7 @@ def warn_drv_diagnostics_hotness_requires_pgo : Warning<
 def warn_drv_clang_unsupported : Warning<
   "the clang compiler does not support '%0'">;
 def warn_drv_deprecated_arg : Warning<
-  "argument '%0' is deprecated, use '%1' instead">, InGroup;
+  "argument '%0' is deprecated%select{|, use '%2' instead}1">, 
InGroup;
 def warn_drv_assuming_mfloat_abi_is : Warning<
   "unknown platform, assuming -mfloat-abi=%0">;
 def warn_ignoring_ftabstop_value : Warning<

diff  --git a/clang/include/clang/Basic/LangOptions.def 
b/clang/include/clang/Basic/LangOptions.def
index 4651f4fff6aa0..565ecd94f977c 100644
--- a/clang/include/clang/Basic/LangOptions.def
+++ b/clang/include/clang/Basic/LangOptions.def
@@ -149,7 +149,7 @@ LANGOPT(NoMathBuiltin , 1, 0, "disable math builtin 
functions")
 LANGOPT(GNUAsm, 1, 1, "GNU-style inline assembly")
 LANGOPT(Coroutines, 1, 0, "C++20 coroutines")
 LANGOPT(DllExportInlines  , 1, 1, "dllexported classes dllexport inline 
methods")
-LANGOPT(RelaxedTemplateTemplateArgs, 1, 0, "C++17 relaxed matching of template 
template arguments")
+LANGOPT(RelaxedTemplateTemplateArgs, 1, 1, "C++17 relaxed matching of template 
template arguments")
 
 LANGOPT(DoubleSquareBracketAttributes, 1, 0, "'[[]]' attributes extension for 
all language standard modes")
 

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index b4a2411fa5c5c..0d3c053e89ae4 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2335,9 +2335,9 @@ defm application_extension : 
BoolFOption<"application-extension",
   PosFlag,
   NegFlag>;
 defm relaxed_template_template_args : 
BoolFOption<"relaxed-template-template-args",
-  LangOpts<"RelaxedTemplateTemplateArgs">, DefaultFalse,
-  PosFlag,
-  NegFlag>;
+  LangOpts<"RelaxedTemplateTemplateArgs">, DefaultTrue,
+  PosFlag,
+  NegFlag>;
 defm sized_deallocation : BoolFOption<"sized-deallocation",
   LangOpts<"SizedDeallocation">, DefaultFalse,
   PosFlag,

diff  --git a/clang/lib/Driver/SanitizerArgs.cpp 
b/clang/lib/Driver/SanitizerArgs.cpp
index bef0dec64d4e1..44692e131d3e1 100644
--- a/clang/lib/Driver/SanitizerArgs.cpp
+++ b/clang/lib/Driver/SanitizerArgs.cpp
@@ -683,7 +683,8 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
 Arg->claim();
 if (LegacySanitizeCoverage != 0) {
   D.Diag(diag::warn_drv_deprecated_arg)
-  << Arg->getAsString(Args) << 
"-fsanitize-coverage=trace-pc-guard";
+  << Arg->getAsString(Args) << true
+  << "-fsanitize-coverage=trace-pc-guard";
 }
 continue;
   }
@@ -718,11 +719,11 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
   // enabled.
   if (CoverageFeatures & CoverageTraceBB)
 D.Diag(clang::diag::warn_drv_deprecated_arg)
-<< "-fsanitize-coverage=trace-bb"
+<< "-fsanitize-coverage=trace

[clang] 086e111 - [clang] NFC: include non friendly types and missing sugar in test expectations

2021-10-27 Thread Matheus Izvekov via cfe-commits

Author: Matheus Izvekov
Date: 2021-10-27T23:03:29+02:00
New Revision: 086e111216bc4fb8065aa7ef4bc226380d1c237e

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

LOG: [clang] NFC: include non friendly types and missing sugar in test 
expectations

The dump of all diagnostics of all tests under 
`clang/test/{CXX,SemaCXX,SemaTemplate}` was analyzed , and all the cases where 
there were obviously bad canonical types being printed, like 
`type-parameter-*-*` and `` were identified. Also a 
small amount of cases of missing sugar were analyzed.

This patch then spells those explicitly in the test expectations, as 
preparatory work for future fixes for these problems.

Signed-off-by: Matheus Izvekov 

Reviewed By: rsmith

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

Added: 


Modified: 
clang/test/CXX/expr/expr.prim/expr.prim.lambda/p4-cxx14.cpp

clang/test/CXX/over/over.match/over.match.funcs/over.match.class.deduct/p2.cpp
clang/test/CXX/stmt.stmt/stmt.iter/stmt.ranged/p1.cpp
clang/test/CXX/temp/temp.decls/temp.class.spec/p6.cpp
clang/test/CXX/temp/temp.decls/temp.mem/p5.cpp
clang/test/CXX/temp/temp.decls/temp.variadic/multi-level-substitution.cpp
clang/test/SemaCXX/conversion-function.cpp
clang/test/SemaCXX/cxx1y-generic-lambdas-variadics.cpp
clang/test/SemaCXX/cxx1y-generic-lambdas.cpp
clang/test/SemaCXX/cxx1z-decomposition.cpp
clang/test/SemaCXX/deduced-return-type-cxx14.cpp
clang/test/SemaCXX/recovery-expr-type.cpp
clang/test/SemaCXX/redeclared-alias-template.cpp
clang/test/SemaTemplate/instantiate-var-template.cpp
clang/test/SemaTemplate/temp_arg_nontype.cpp
clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp

Removed: 




diff  --git a/clang/test/CXX/expr/expr.prim/expr.prim.lambda/p4-cxx14.cpp 
b/clang/test/CXX/expr/expr.prim/expr.prim.lambda/p4-cxx14.cpp
index f780bf796ee43..2933532627d4c 100644
--- a/clang/test/CXX/expr/expr.prim/expr.prim.lambda/p4-cxx14.cpp
+++ b/clang/test/CXX/expr/expr.prim/expr.prim.lambda/p4-cxx14.cpp
@@ -7,7 +7,7 @@ int &b = [] (int &r) -> decltype(auto) { return r; } (a);
 int &c = [] (int &r) -> decltype(auto) { return (r); } (a);
 int &d = [] (int &r) -> auto & { return r; } (a);
 int &e = [] (int &r) -> auto { return r; } (a); // expected-error {{cannot 
bind to a temporary}}
-int &f = [] (int r) -> decltype(auto) { return r; } (a); // expected-error 
{{cannot bind to a temporary}}
+int &f = [] (int r) -> decltype(auto) { return r; } (a); // expected-error 
{{non-const lvalue reference to type 'int' cannot bind to a temporary of type 
'int'}}
 int &g = [] (int r) -> decltype(auto) { return (r); } (a); // expected-warning 
{{reference to stack}}
 // cxx2b-error@-1 {{non-const lvalue reference to type 'int' cannot bind to a 
temporary of type 'int'}}
 

diff  --git 
a/clang/test/CXX/over/over.match/over.match.funcs/over.match.class.deduct/p2.cpp
 
b/clang/test/CXX/over/over.match/over.match.funcs/over.match.class.deduct/p2.cpp
index cb9541caaddd4..cb9407b1db88b 100644
--- 
a/clang/test/CXX/over/over.match/over.match.funcs/over.match.class.deduct/p2.cpp
+++ 
b/clang/test/CXX/over/over.match/over.match.funcs/over.match.class.deduct/p2.cpp
@@ -36,7 +36,7 @@ namespace std {
 
 namespace p0702r1 {
   template struct X { // expected-note {{candidate}}
-X(std::initializer_list); // expected-note {{candidate}}
+X(std::initializer_list); // expected-note {{candidate template 
ignored: could not match 'initializer_list' against 
'p0702r1::Z'}}
   };
 
   X xi = {0};
@@ -84,4 +84,4 @@ int main() {
 }
 
 
-}
\ No newline at end of file
+}

diff  --git a/clang/test/CXX/stmt.stmt/stmt.iter/stmt.ranged/p1.cpp 
b/clang/test/CXX/stmt.stmt/stmt.iter/stmt.ranged/p1.cpp
index d6d171470c21d..0963dd23724a8 100644
--- a/clang/test/CXX/stmt.stmt/stmt.iter/stmt.ranged/p1.cpp
+++ b/clang/test/CXX/stmt.stmt/stmt.iter/stmt.ranged/p1.cpp
@@ -336,9 +336,9 @@ namespace p0962r1 {
   void use(NA::A a, NB::B b, NC::C c, ND::D d, NE::E e, NF::F f) {
 for (auto x : a) {}
 for (auto x : b) {}
-for (auto x : c) {} // expected-error {{no viable 'end' function}}
-for (auto x : d) {} // expected-error {{no viable 'begin' function}}
-for (auto x : e) {} // expected-error {{no viable 'begin' function}}
-for (auto x : f) {} // expected-error {{no viable 'end' function}}
+for (auto x : c) {} // expected-error {{invalid range expression of type 
'p0962r1::NC::C'; no viable 'end' function available}}
+for (auto x : d) {} // expected-error {{invalid range expression of type 
'p0962r1::ND::D'; no viable 'begin' function available}}
+for (auto x : e) {} // expected-error {{invalid range expression of type 
'p0962r1::NE::E'; no viable 'begin' function available}}
+for (auto x : f) {

[clang] c9fd92d - [clang] Improve diagnostics on implicitly deleted defaulted comparisons

2021-03-12 Thread Matheus Izvekov via cfe-commits

Author: Matheus Izvekov
Date: 2021-03-13T01:13:52+01:00
New Revision: c9fd92d573988c59b7a613f07909596cdad36095

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

LOG: [clang] Improve diagnostics on implicitly deleted defaulted comparisons

This patch just makes the error message clearer by reinforcing the cause
was a lack of viable **three-way** comparison function for the
**complete object**.

Signed-off-by: Matheus Izvekov 

Reviewed By: rsmith

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

Added: 


Modified: 
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaDeclCXX.cpp
clang/test/CXX/class/class.compare/class.compare.default/p1.cpp
clang/test/CXX/class/class.compare/class.compare.default/p2.cpp
clang/test/CXX/class/class.compare/class.compare.default/p4.cpp
clang/test/CXX/class/class.compare/class.eq/p2.cpp
clang/test/CXX/class/class.compare/class.spaceship/p1.cpp
clang/test/CXX/class/class.compare/class.spaceship/p2.cpp

Removed: 




diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index d4578c5263a0..8e037260288f 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -8979,8 +8979,8 @@ def note_defaulted_comparison_calls_deleted : Note<
   "defaulted %0 is implicitly deleted because it would invoke a deleted "
   "comparison function%select{| for member %2| for base class %2}1">;
 def note_defaulted_comparison_no_viable_function : Note<
-  "defaulted %0 is implicitly deleted because there is no viable comparison "
-  "function%select{| for member %2| for base class %2}1">;
+  "defaulted %0 is implicitly deleted because there is no viable three-way "
+  "comparison function for%select{| member| base class}1 %2">;
 def note_defaulted_comparison_no_viable_function_synthesized : Note<
   "three-way comparison cannot be synthesized because there is no viable "
   "function for %select{'=='|'<'}0 comparison">;

diff  --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 940ef796ce5e..0365d77cfc4e 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -7632,7 +7632,7 @@ class DefaultedComparisonAnalyzer
 
 private:
   Subobject getCompleteObject() {
-return Subobject{Subobject::CompleteObject, nullptr, FD->getLocation()};
+return Subobject{Subobject::CompleteObject, RD, FD->getLocation()};
   }
 
   Subobject getBase(CXXBaseSpecifier *Base) {

diff  --git a/clang/test/CXX/class/class.compare/class.compare.default/p1.cpp 
b/clang/test/CXX/class/class.compare/class.compare.default/p1.cpp
index 1a0ccc91741b..dd622988d458 100644
--- a/clang/test/CXX/class/class.compare/class.compare.default/p1.cpp
+++ b/clang/test/CXX/class/class.compare/class.compare.default/p1.cpp
@@ -127,7 +127,7 @@ namespace P1946 {
 friend bool operator==(A &, A &); // expected-note {{would lose const 
qualifier}}
   };
   struct B {
-A a; // expected-note {{no viable comparison}}
+A a; // expected-note {{no viable three-way comparison}}
 friend bool operator==(B, B) = default; // ok
 friend bool operator==(const B&, const B&) = default; // expected-warning 
{{deleted}}
   };

diff  --git a/clang/test/CXX/class/class.compare/class.compare.default/p2.cpp 
b/clang/test/CXX/class/class.compare/class.compare.default/p2.cpp
index 226245ce8a44..a1653d85abbf 100644
--- a/clang/test/CXX/class/class.compare/class.compare.default/p2.cpp
+++ b/clang/test/CXX/class/class.compare/class.compare.default/p2.cpp
@@ -44,7 +44,7 @@ struct A3 {
 
   bool operator==(const A3 &) const = default; // expected-warning 
{{implicitly deleted}}
   bool operator<(const A3 &) const = default;  // expected-warning 
{{implicitly deleted}}
-  // expected-note@-1 {{because there is no viable comparison function}}
+  // expected-note@-1 {{because there is no viable three-way comparison 
function for 'A3'}}
 };
 
 struct B1 {

diff  --git a/clang/test/CXX/class/class.compare/class.compare.default/p4.cpp 
b/clang/test/CXX/class/class.compare/class.compare.default/p4.cpp
index 8c303c63d899..02adf3d51ded 100644
--- a/clang/test/CXX/class/class.compare/class.compare.default/p4.cpp
+++ b/clang/test/CXX/class/class.compare/class.compare.default/p4.cpp
@@ -99,7 +99,7 @@ namespace DeleteAfterFirstDecl {
   struct Q {
 struct X {
   friend std::strong_ordering operator<=>(const X&, const X&);
-} x; // expected-note {{no viable comparison}}
+} x; // expected-note {{no viable three-way comparison}}
 // expected-error@+1 {{defaulting the corresponding implicit 'operator==' 
for this defaulted 'operator<=>' would delete it after its first declaration}}
 friend std::strong

[clang] d4a8c73 - [clang] Fix ICE on invalid type parameters for concepts

2021-03-12 Thread Matheus Izvekov via cfe-commits

Author: Matheus Izvekov
Date: 2021-03-13T01:23:02+01:00
New Revision: d4a8c7359b57bafc7bfa2a9dea30017fb0153c1a

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

LOG: [clang] Fix ICE on invalid type parameters for concepts

See PR48593.

Constraints with invalid type parameters were causing a null pointer
dereference.

Signed-off-by: Matheus Izvekov 

Reviewed By: rsmith

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

Added: 


Modified: 
clang/lib/Sema/SemaType.cpp
clang/test/CXX/dcl/dcl.spec/dcl.type/dcl.spec.auto/p6.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 5f5b0361eab5..ffd431608b82 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -1256,25 +1256,6 @@ getImageAccess(const ParsedAttributesView &Attrs) {
   return OpenCLAccessAttr::Keyword_read_only;
 }
 
-static QualType ConvertConstrainedAutoDeclSpecToType(Sema &S, DeclSpec &DS,
- AutoTypeKeyword AutoKW) {
-  assert(DS.isConstrainedAuto());
-  TemplateIdAnnotation *TemplateId = DS.getRepAsTemplateId();
-  TemplateArgumentListInfo TemplateArgsInfo;
-  TemplateArgsInfo.setLAngleLoc(TemplateId->LAngleLoc);
-  TemplateArgsInfo.setRAngleLoc(TemplateId->RAngleLoc);
-  ASTTemplateArgsPtr TemplateArgsPtr(TemplateId->getTemplateArgs(),
- TemplateId->NumArgs);
-  S.translateTemplateArguments(TemplateArgsPtr, TemplateArgsInfo);
-  llvm::SmallVector TemplateArgs;
-  for (auto &ArgLoc : TemplateArgsInfo.arguments())
-TemplateArgs.push_back(ArgLoc.getArgument());
-  return S.Context.getAutoType(
-  QualType(), AutoKW, false, /*IsPack=*/false,
-  cast(TemplateId->Template.get().getAsTemplateDecl()),
-  TemplateArgs);
-}
-
 /// Convert the specified declspec to the appropriate type
 /// object.
 /// \param state Specifies the declarator containing the declaration specifier
@@ -1655,29 +1636,39 @@ static QualType 
ConvertDeclSpecToType(TypeProcessingState &state) {
 break;
 
   case DeclSpec::TST_auto:
+  case DeclSpec::TST_decltype_auto: {
+auto AutoKW = DS.getTypeSpecType() == DeclSpec::TST_decltype_auto
+  ? AutoTypeKeyword::DecltypeAuto
+  : AutoTypeKeyword::Auto;
+
+ConceptDecl *TypeConstraintConcept = nullptr;
+llvm::SmallVector TemplateArgs;
 if (DS.isConstrainedAuto()) {
-  Result = ConvertConstrainedAutoDeclSpecToType(S, DS,
-AutoTypeKeyword::Auto);
-  break;
+  if (TemplateIdAnnotation *TemplateId = DS.getRepAsTemplateId()) {
+TypeConstraintConcept =
+cast(TemplateId->Template.get().getAsTemplateDecl());
+TemplateArgumentListInfo TemplateArgsInfo;
+TemplateArgsInfo.setLAngleLoc(TemplateId->LAngleLoc);
+TemplateArgsInfo.setRAngleLoc(TemplateId->RAngleLoc);
+ASTTemplateArgsPtr TemplateArgsPtr(TemplateId->getTemplateArgs(),
+   TemplateId->NumArgs);
+S.translateTemplateArguments(TemplateArgsPtr, TemplateArgsInfo);
+for (const auto &ArgLoc : TemplateArgsInfo.arguments())
+  TemplateArgs.push_back(ArgLoc.getArgument());
+  } else {
+declarator.setInvalidType(true);
+  }
 }
-Result = Context.getAutoType(QualType(), AutoTypeKeyword::Auto, false);
+Result = S.Context.getAutoType(QualType(), AutoKW,
+   /*IsDependent*/ false, /*IsPack=*/false,
+   TypeConstraintConcept, TemplateArgs);
 break;
+  }
 
   case DeclSpec::TST_auto_type:
 Result = Context.getAutoType(QualType(), AutoTypeKeyword::GNUAutoType, 
false);
 break;
 
-  case DeclSpec::TST_decltype_auto:
-if (DS.isConstrainedAuto()) {
-  Result =
-  ConvertConstrainedAutoDeclSpecToType(S, DS,
-   AutoTypeKeyword::DecltypeAuto);
-  break;
-}
-Result = Context.getAutoType(QualType(), AutoTypeKeyword::DecltypeAuto,
- /*IsDependent*/ false);
-break;
-
   case DeclSpec::TST_unknown_anytype:
 Result = Context.UnknownAnyTy;
 break;
@@ -5962,6 +5953,8 @@ namespace {
   if (!DS.isConstrainedAuto())
 return;
   TemplateIdAnnotation *TemplateId = DS.getRepAsTemplateId();
+  if (!TemplateId)
+return;
   if (DS.getTypeSpecScope().isNotEmpty())
 TL.setNestedNameSpecifierLoc(
 DS.getTypeSpecScope().getWithLocInContext(Context));

diff  --git a/clang/test/CXX/dcl/dcl.spec/dcl.type/dcl.spec.auto/p6.cpp 
b/clang/test/CXX/dcl/dcl.spec/dcl.type/dcl.spec.auto/p6.cpp
index 44539bd125ff..7830d1f43526 100644
--- 

[clang] 9fec50f - [cmake] use project relative paths when generating ASTNodeAPI.json

2021-11-15 Thread Matheus Izvekov via cfe-commits

Author: Matheus Izvekov
Date: 2021-11-15T12:35:34+01:00
New Revision: 9fec50f001b1ab86ff36c6e92336ae1c1d3fcdef

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

LOG: [cmake] use project relative paths when generating ASTNodeAPI.json

Signed-off-by: Matheus Izvekov 

Reviewed By: stephenneuendorffer

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

Added: 


Modified: 
clang/lib/Tooling/CMakeLists.txt

Removed: 




diff  --git a/clang/lib/Tooling/CMakeLists.txt 
b/clang/lib/Tooling/CMakeLists.txt
index 558385b0eb5a..403d2dfb45e8 100644
--- a/clang/lib/Tooling/CMakeLists.txt
+++ b/clang/lib/Tooling/CMakeLists.txt
@@ -60,11 +60,11 @@ else()
   $
 # Skip this in debug mode because parsing AST.h is too slow
 --skip-processing=${skip_expensive_processing}
--I ${CMAKE_BINARY_DIR}/lib/clang/${CLANG_VERSION}/include
--I ${CMAKE_SOURCE_DIR}/../clang/include
--I ${CMAKE_BINARY_DIR}/tools/clang/include
--I ${CMAKE_BINARY_DIR}/include
--I ${CMAKE_SOURCE_DIR}/include
+-I ${LLVM_BINARY_DIR}/lib/clang/${CLANG_VERSION}/include
+-I ${CLANG_SOURCE_DIR}/include
+-I ${LLVM_BINARY_DIR}/tools/clang/include
+-I ${LLVM_BINARY_DIR}/include
+-I ${LLVM_SOURCE_DIR}/include
 ${implicitDirs}
 --json-output-path ${CMAKE_CURRENT_BINARY_DIR}/ASTNodeAPI.json
   )



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


[clang] 21ed00b - [clang] NFC: rename internal `IsPossiblyOpaquelyQualifiedType` overload

2021-11-15 Thread Matheus Izvekov via cfe-commits

Author: Matheus Izvekov
Date: 2021-11-16T03:09:50+01:00
New Revision: 21ed00bc1bfd2b0b81d288f7f096a31079c24c4a

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

LOG: [clang] NFC: rename internal `IsPossiblyOpaquelyQualifiedType` overload

Rename `IsPossiblyOpaquelyQualifiedType` overload taking a Type*
as `IsPossiblyOpaquelyQualifiedTypeInternal` instead.

Signed-off-by: Matheus Izvekov 

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

Added: 


Modified: 
clang/lib/Sema/SemaTemplateDeduction.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 
b/clang/lib/Sema/SemaTemplateDeduction.cpp
index a1722c45b632..3c67b5b5072e 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -603,7 +603,7 @@ DeduceTemplateSpecArguments(Sema &S, TemplateParameterList 
*TemplateParams,
  /*NumberOfArgumentsMustMatch=*/true);
 }
 
-static bool IsPossiblyOpaquelyQualifiedType(const Type *T) {
+static bool IsPossiblyOpaquelyQualifiedTypeInternal(const Type *T) {
   assert(T->isCanonicalUnqualified());
 
   switch (T->getTypeClass()) {
@@ -619,7 +619,7 @@ static bool IsPossiblyOpaquelyQualifiedType(const Type *T) {
   case Type::IncompleteArray:
   case Type::VariableArray:
   case Type::DependentSizedArray:
-return IsPossiblyOpaquelyQualifiedType(
+return IsPossiblyOpaquelyQualifiedTypeInternal(
 cast(T)->getElementType().getTypePtr());
 
   default:
@@ -630,7 +630,7 @@ static bool IsPossiblyOpaquelyQualifiedType(const Type *T) {
 /// Determines whether the given type is an opaque type that
 /// might be more qualified when instantiated.
 static bool IsPossiblyOpaquelyQualifiedType(QualType T) {
-  return IsPossiblyOpaquelyQualifiedType(
+  return IsPossiblyOpaquelyQualifiedTypeInternal(
   T->getCanonicalTypeInternal().getTypePtr());
 }
 



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


[clang] 85914b7 - [clang] fix regression deducing pack expansion arguments introduced by D110216

2021-11-18 Thread Matheus Izvekov via cfe-commits

Author: Matheus Izvekov
Date: 2021-11-19T03:36:20+01:00
New Revision: 85914b757015dfbc780dc254696acb95b8dc7679

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

LOG: [clang] fix regression deducing pack expansion arguments introduced by 
D110216

This test case had been missing when the original code
was introduced by 2fcb863b2b278.

Signed-off-by: Matheus Izvekov 

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

Added: 


Modified: 
clang/lib/Sema/SemaTemplateDeduction.cpp
clang/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.partial/p12.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 
b/clang/lib/Sema/SemaTemplateDeduction.cpp
index 3c67b5b5072e..81edae10335d 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -1337,6 +1337,13 @@ static Sema::TemplateDeductionResult 
DeduceTemplateArgumentsByTypeMatch(
 TemplateDeductionInfo &Info,
 SmallVectorImpl &Deduced, unsigned TDF,
 bool PartialOrdering, bool DeducedFromArrayBound) {
+
+  // If the argument type is a pack expansion, look at its pattern.
+  // This isn't explicitly called out
+  if (const auto *AExp = dyn_cast(A))
+A = AExp->getPattern();
+  assert(!isa(A.getCanonicalType()));
+
   if (PartialOrdering) {
 // C++11 [temp.deduct.partial]p5:
 //   Before the partial ordering is done, certain transformations are

diff  --git 
a/clang/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.partial/p12.cpp 
b/clang/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.partial/p12.cpp
index ec7e8970b1b5..bb7f9da58eda 100644
--- a/clang/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.partial/p12.cpp
+++ b/clang/test/CXX/temp/temp.fct.spec/temp.deduct/temp.deduct.partial/p12.cpp
@@ -1,5 +1,4 @@
 // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
-// expected-no-diagnostics
 
 // Note: Partial ordering of function templates containing template
 // parameter packs is independent of the number of deduced arguments
@@ -26,3 +25,15 @@ void test_h() {
   double &dr1 = h((int(*)(int, float&))0);
   double &dr2 = h((int(*)(int))0);
 }
+
+namespace test_j {
+
+template  struct ref {};
+
+template  void map(ref...);
+template  void map(ref x, ref... xs); // 
expected-note {{here}}
+
+template void map<0, 1>(ref<0>, ref<1>);
+// expected-error@-1 {{explicit instantiation of undefined function template 
'map'}}
+
+} // namespace test_j



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


  1   2   3   4   5   6   7   8   9   10   >