[clang] b8a1b69 - [clang] fix missing initialization of original number of expansions

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

Author: Matheus Izvekov
Date: 2022-08-15T17:39:38+02:00
New Revision: b8a1b698afb2fc84819c7596090aabf4d826b436

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

LOG: [clang] fix missing initialization of original number of expansions

When expanding undeclared function parameters, we should initialize
the original number of expansions, if known, before trying to expand
them, otherwise a length mismatch with an outer pack might not be
diagnosed.

Fixes PR56094.

Signed-off-by: Matheus Izvekov 

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

Added: 


Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Sema/TreeTransform.h
clang/test/CXX/temp/temp.decls/temp.variadic/p5.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index a635b734c47aa..ded0b39c27ea5 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -71,6 +71,9 @@ Bug Fixes
 - Fix `#57008 `_ - Builtin
   C++ language extension type traits instantiated by a template with unexpected
   number of arguments cause an assertion fault.
+- Fix multi-level pack expansion of undeclared function parameters.
+  This fixes `Issue 56094 
`_.
+
 
 Improvements to Clang's diagnostics
 ^^^

diff  --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index 07e71a2be4f2c..dd684d42665b2 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -5792,6 +5792,7 @@ bool TreeTransform::TransformFunctionTypeParams(
= dyn_cast(OldType)) 
{
   // We have a function parameter pack that may need to be expanded.
   QualType Pattern = Expansion->getPattern();
+  NumExpansions = Expansion->getNumExpansions();
   SmallVector Unexpanded;
   getSema().collectUnexpandedParameterPacks(Pattern, Unexpanded);
 

diff  --git a/clang/test/CXX/temp/temp.decls/temp.variadic/p5.cpp 
b/clang/test/CXX/temp/temp.decls/temp.variadic/p5.cpp
index 206e9f73e9f05..6c4c260cdf8f0 100644
--- a/clang/test/CXX/temp/temp.decls/temp.variadic/p5.cpp
+++ b/clang/test/CXX/temp/temp.decls/temp.variadic/p5.cpp
@@ -469,3 +469,25 @@ int fn() {
   bar(b);
 }
 }
+
+namespace pr56094 {
+template  struct D {
+  template  using B = int(int (*...p)(T, U));
+  // expected-error@-1 {{pack expansion contains parameter pack 'U' that has a 
diff erent length (1 vs. 2) from outer parameter packs}}
+  template  D(B *);
+  // expected-note@-1 {{in instantiation of template type alias 'B' requested 
here}}
+};
+using t1 = D::B;
+// expected-note@-1 {{in instantiation of template class 'pr56094::D' 
requested here}}
+
+template  struct F {};
+template  struct G {};
+template  struct E {
+  template  using B = G...>;
+  // expected-error@-1 {{pack expansion contains parameter pack 'U' that has a 
diff erent length (1 vs. 2) from outer parameter packs}}
+  template  E(B *);
+  // expected-note@-1 {{in instantiation of template type alias 'B' requested 
here}}
+};
+using t2 = E::B;
+// expected-note@-1 {{in instantiation of template class 'pr56094::E' 
requested here}}
+} // namespace pr56094



___
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 );

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 

[clang] 271cc58 - [NFC] clang: Implement tests for PR56099

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

Author: Matheus Izvekov
Date: 2022-06-21T18:35:17+02:00
New Revision: 271cc588054a90abf0d82f57af272c3db749ff56

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

LOG: [NFC] clang: Implement tests for PR56099

Signed-off-by: Matheus Izvekov 

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

Added: 


Modified: 
clang/test/AST/ast-dump-template-decls.cpp

Removed: 




diff  --git a/clang/test/AST/ast-dump-template-decls.cpp 
b/clang/test/AST/ast-dump-template-decls.cpp
index 616a96902eff4..13050eee7aeda 100644
--- a/clang/test/AST/ast-dump-template-decls.cpp
+++ b/clang/test/AST/ast-dump-template-decls.cpp
@@ -127,3 +127,38 @@ using type2 = typename C::type1;
 // CHECK-NEXT: SubstTemplateTypeParmType 0x{{[^ ]*}} 'int' sugar
 // CHECK-NEXT: TemplateTypeParmType 0x{{[^ ]*}} 'T' dependent depth 0 index 0
 } // namespace PR55886
+
+namespace PR56099 {
+template  struct Y;
+template  using Z = Y;
+template  struct foo {
+  template  using bind = Z;
+};
+using t1 = foo::bind;
+// CHECK:  TemplateSpecializationType 0x{{[^ ]*}} 'Y' sugar Y
+// CHECK:  SubstTemplateTypeParmType 0x{{[^ ]*}} 'char' sugar
+// CHECK-NEXT: TemplateTypeParmType 0x{{[^ ]*}} 'Bs' dependent 
contains_unexpanded_pack depth 0 index 0 pack
+// CHECK:  SubstTemplateTypeParmType 0x{{[^ ]*}} 'float' sugar
+// CHECK-NEXT: TemplateTypeParmType 0x{{[^ ]*}} 'Bs' dependent 
contains_unexpanded_pack depth 0 index 0 pack
+// CHECK:  SubstTemplateTypeParmType 0x{{[^ ]*}} 'int' sugar
+// CHECK-NEXT: TemplateTypeParmType 0x{{[^ ]*}} 'Bs' dependent 
contains_unexpanded_pack depth 0 index 0 pack
+// CHECK:  SubstTemplateTypeParmType 0x{{[^ ]*}} 'short' sugar
+// CHECK-NEXT: TemplateTypeParmType 0x{{[^ ]*}} 'Bs' dependent 
contains_unexpanded_pack depth 0 index 0 pack
+
+template  struct D {
+  template  using B = int(int (*...p)(T, U));
+};
+using t2 = D::B;
+// CHECK:  TemplateSpecializationType 0x{{[^ ]*}} 'B' sugar 
alias B
+// CHECK:  FunctionProtoType 0x{{[^ ]*}} 'int (int (*)(float, int), int 
(*)(char, short))' cdecl
+// CHECK:  FunctionProtoType 0x{{[^ ]*}} 'int (float, int)' cdecl
+// CHECK:  SubstTemplateTypeParmType 0x{{[^ ]*}} 'float' sugar
+// CHECK-NEXT: TemplateTypeParmType 0x{{[^ ]*}} 'T' dependent 
contains_unexpanded_pack depth 0 index 0 pack
+// CHECK:  SubstTemplateTypeParmType 0x{{[^ ]*}} 'int' sugar
+// CHECK-NEXT: TemplateTypeParmType 0x{{[^ ]*}} 'U' dependent 
contains_unexpanded_pack depth 0 index 0 pack
+// CHECK:  FunctionProtoType 0x{{[^ ]*}} 'int (char, short)' cdecl
+// CHECK:  SubstTemplateTypeParmType 0x{{[^ ]*}} 'char' sugar
+// CHECK-NEXT: TemplateTypeParmType 0x{{[^ ]*}} 'T' dependent 
contains_unexpanded_pack depth 0 index 0 pack
+// CHECK:  SubstTemplateTypeParmType 0x{{[^ ]*}} 'short' sugar
+// CHECK-NEXT: TemplateTypeParmType 0x{{[^ ]*}} 'U' dependent 
contains_unexpanded_pack depth 0 index 0 pack
+} // namespace PR56099



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


[clang] e35096a - cmake: configure clang lit to use hmaptool from source directly

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

Author: Matheus Izvekov
Date: 2022-06-16T13:08:50+02:00
New Revision: e35096ae961eb25843f0489847cdb6c1c586ad30

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

LOG: cmake: configure clang lit to use hmaptool from source directly

Signed-off-by: Matheus Izvekov 

Reviewed By: dyung

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

Added: 


Modified: 
clang/test/lit.cfg.py
clang/utils/hmaptool/CMakeLists.txt

Removed: 




diff  --git a/clang/test/lit.cfg.py b/clang/test/lit.cfg.py
index bf1fa141fc48b..fd86353c8cc36 100644
--- a/clang/test/lit.cfg.py
+++ b/clang/test/lit.cfg.py
@@ -111,7 +111,7 @@ def have_host_jit_support():
 
 config.substitutions.append(
 ('%hmaptool', "'%s' %s" % (config.python_executable,
- os.path.join(config.clang_tools_dir, 
'hmaptool'
+ os.path.join(config.clang_src_dir, 'utils', 
'hmaptool', 'hmaptool'
 
 config.substitutions.append(
 ('%deps-to-rsp',

diff  --git a/clang/utils/hmaptool/CMakeLists.txt 
b/clang/utils/hmaptool/CMakeLists.txt
index 1b77727fa791b..72915ec665044 100644
--- a/clang/utils/hmaptool/CMakeLists.txt
+++ b/clang/utils/hmaptool/CMakeLists.txt
@@ -1,14 +1,5 @@
-# FIXME: ideally we would just provide CURRENT_TOOLS_DIR globally instead of
-#computing it just for function(configure_lit_site_cfg)
-set_llvm_build_mode()
-string(REPLACE "${CMAKE_CFG_INTDIR}" "${LLVM_BUILD_MODE}" CURRENT_TOOLS_DIR 
"${LLVM_RUNTIME_OUTPUT_INTDIR}")
-
-add_custom_command(OUTPUT "${CURRENT_TOOLS_DIR}/hmaptool"
-   COMMAND "${CMAKE_COMMAND}" -E copy 
"${CMAKE_CURRENT_SOURCE_DIR}/hmaptool" "${CURRENT_TOOLS_DIR}"
-   DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/hmaptool")
-
 install(PROGRAMS hmaptool DESTINATION "${LLVM_TOOLS_INSTALL_DIR}" COMPONENT 
hmaptool)
-add_custom_target(hmaptool ALL DEPENDS "${CURRENT_TOOLS_DIR}/hmaptool")
+add_custom_target(hmaptool ALL DEPENDS "hmaptool")
 set_target_properties(hmaptool PROPERTIES FOLDER "Utils")
 
 if(NOT LLVM_ENABLE_IDE)



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


[clang] 671eb7d - [clang] AST/Print: honor AlwaysIncludeTypeForTemplateArgument policy

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

Author: Matheus Izvekov
Date: 2022-06-14T18:18:24+02:00
New Revision: 671eb7dc1e69fec251e115f4f49865895a43513a

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

LOG: [clang] AST/Print: honor AlwaysIncludeTypeForTemplateArgument policy

This redoes D103040 in a way that `AlwaysIncludeTypeForTemplateArgument = false`
policy is honored for printing template specialization types.
This can be seen for example when printing a canonicalized
dependent TemplateSpecializationType which has integral arguments.

Signed-off-by: Matheus Izvekov 

Reviewed By: v.g.vassilev

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

Added: 


Modified: 
clang/lib/AST/TypePrinter.cpp
clang/test/CXX/temp/temp.decls/temp.class.spec/p6.cpp

Removed: 




diff  --git a/clang/lib/AST/TypePrinter.cpp b/clang/lib/AST/TypePrinter.cpp
index b5286de5b1cab..38b5a5ab222f5 100644
--- a/clang/lib/AST/TypePrinter.cpp
+++ b/clang/lib/AST/TypePrinter.cpp
@@ -80,6 +80,21 @@ namespace {
 }
   };
 
+  class DefaultTemplateArgsPolicyRAII {
+PrintingPolicy 
+bool Old;
+
+  public:
+explicit DefaultTemplateArgsPolicyRAII(PrintingPolicy )
+: Policy(Policy), Old(Policy.SuppressDefaultTemplateArgs) {
+  Policy.SuppressDefaultTemplateArgs = false;
+}
+
+~DefaultTemplateArgsPolicyRAII() {
+  Policy.SuppressDefaultTemplateArgs = Old;
+}
+  };
+
   class ElaboratedTypePolicyRAII {
 PrintingPolicy 
 bool SuppressTagKeyword;
@@ -1470,6 +1485,7 @@ void TypePrinter::printTemplateId(const 
TemplateSpecializationType *T,
   IncludeStrongLifetimeRAII Strong(Policy);
 
   TemplateDecl *TD = T->getTemplateName().getAsTemplateDecl();
+  // FIXME: Null TD never excercised in test suite.
   if (FullyQualify && TD) {
 if (!Policy.SuppressScope)
   AppendScope(TD->getDeclContext(), OS, TD->getDeclName());
@@ -1479,7 +1495,9 @@ void TypePrinter::printTemplateId(const 
TemplateSpecializationType *T,
 T->getTemplateName().print(OS, Policy);
   }
 
-  printTemplateArgumentList(OS, T->template_arguments(), Policy);
+  DefaultTemplateArgsPolicyRAII TemplateArgs(Policy);
+  const TemplateParameterList *TPL = TD ? TD->getTemplateParameters() : 
nullptr;
+  printTemplateArgumentList(OS, T->template_arguments(), Policy, TPL);
   spaceBeforePlaceHolder(OS);
 }
 

diff  --git a/clang/test/CXX/temp/temp.decls/temp.class.spec/p6.cpp 
b/clang/test/CXX/temp/temp.decls/temp.class.spec/p6.cpp
index 7eddef1cb71f3..871bdc2a58c7b 100644
--- a/clang/test/CXX/temp/temp.decls/temp.class.spec/p6.cpp
+++ b/clang/test/CXX/temp/temp.decls/temp.class.spec/p6.cpp
@@ -80,7 +80,7 @@ namespace print_dependent_TemplateSpecializationType {
 template  struct Foo {
   template  struct Bar;
   template  struct Bar<0, T, Y> {};
-  // expected-note-re@-1 {{previous declaration {{.*}} 'Bar<0UL, int, 
type-parameter-0-0>' is here}}
+  // expected-note-re@-1 {{previous declaration {{.*}} 'Bar<0, int, 
type-parameter-0-0>' is here}}
   template  struct Bar<0, U, Y> {};
   // expected-error@-1 {{partial specialization 'Bar<0, int, Y>' cannot be 
redeclared}}
 };



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


[clang] 5160851 - cmake: use llvm dir variables for clang/utils/hmaptool

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

Author: Matheus Izvekov
Date: 2022-06-09T12:25:38+02:00
New Revision: 51608515faa74c87ae09877be24eeb6a8226ff7e

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

LOG: cmake: use llvm dir variables for clang/utils/hmaptool

Copy hmaptool using the paths for CURRENT_TOOLS_DIR, so
everything goes in the right place in case llvm is included
from a top level CMakeLists.txt.

Signed-off-by: Matheus Izvekov 

Reviewed By: stephenneuendorffer

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

Added: 


Modified: 
clang/utils/hmaptool/CMakeLists.txt

Removed: 




diff  --git a/clang/utils/hmaptool/CMakeLists.txt 
b/clang/utils/hmaptool/CMakeLists.txt
index f0d9866782b88..1b77727fa791b 100644
--- a/clang/utils/hmaptool/CMakeLists.txt
+++ b/clang/utils/hmaptool/CMakeLists.txt
@@ -1,19 +1,14 @@
-set(CLANG_HMAPTOOL hmaptool)
+# FIXME: ideally we would just provide CURRENT_TOOLS_DIR globally instead of
+#computing it just for function(configure_lit_site_cfg)
+set_llvm_build_mode()
+string(REPLACE "${CMAKE_CFG_INTDIR}" "${LLVM_BUILD_MODE}" CURRENT_TOOLS_DIR 
"${LLVM_RUNTIME_OUTPUT_INTDIR}")
 
-add_custom_command(OUTPUT 
${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin/${CLANG_HMAPTOOL}
-   COMMAND ${CMAKE_COMMAND} -E make_directory
- ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin
-   COMMAND ${CMAKE_COMMAND} -E copy
- ${CMAKE_CURRENT_SOURCE_DIR}/${CLANG_HMAPTOOL}
- ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin/
-   DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${CLANG_HMAPTOOL})
+add_custom_command(OUTPUT "${CURRENT_TOOLS_DIR}/hmaptool"
+   COMMAND "${CMAKE_COMMAND}" -E copy 
"${CMAKE_CURRENT_SOURCE_DIR}/hmaptool" "${CURRENT_TOOLS_DIR}"
+   DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/hmaptool")
 
-list(APPEND Depends 
${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin/${CLANG_HMAPTOOL})
-install(PROGRAMS ${CLANG_HMAPTOOL}
-DESTINATION "${CMAKE_INSTALL_BINDIR}"
-COMPONENT hmaptool)
-
-add_custom_target(hmaptool ALL DEPENDS ${Depends})
+install(PROGRAMS hmaptool DESTINATION "${LLVM_TOOLS_INSTALL_DIR}" COMPONENT 
hmaptool)
+add_custom_target(hmaptool ALL DEPENDS "${CURRENT_TOOLS_DIR}/hmaptool")
 set_target_properties(hmaptool PROPERTIES FOLDER "Utils")
 
 if(NOT LLVM_ENABLE_IDE)



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


[clang] cfda534 - [NFC] clang: add test for PR55886

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

Author: Matheus Izvekov
Date: 2022-06-09T01:20:58+02:00
New Revision: cfda534b9944571bf55f0b275982d578361ab7d7

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

LOG: [NFC] clang: add test for PR55886

Signed-off-by: Matheus Izvekov 

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

Added: 


Modified: 
clang/test/AST/ast-dump-template-decls.cpp

Removed: 




diff  --git a/clang/test/AST/ast-dump-template-decls.cpp 
b/clang/test/AST/ast-dump-template-decls.cpp
index 51ec673ab8f3..616a96902eff 100644
--- a/clang/test/AST/ast-dump-template-decls.cpp
+++ b/clang/test/AST/ast-dump-template-decls.cpp
@@ -108,3 +108,22 @@ template 
 // CHECK: FunctionTemplateDecl 0x{{[^ ]*}} parent 0x{{[^ ]*}} prev 0x{{[^ ]*}} 
 col:13 f
 // CHECK-NEXT: TemplateTypeParmDecl 0x{{[^ ]*}}  
col:20 typename depth 1 index 0 Uy
 void V::f() {}
+
+namespace PR55886 {
+template  struct C {
+  template  using type1 = U(T);
+};
+using type2 = typename C::type1;
+// CHECK:  TypeAliasDecl 0x{{[^ ]*}}  col:7 
type2 'typename C::type1':'void (int)'
+// CHECK-NEXT: ElaboratedType 0x{{[^ ]*}} 'typename C::type1' sugar
+// CHECK-NEXT: TemplateSpecializationType 0x{{[^ ]*}} 'type1' sugar 
alias type1
+// CHECK-NEXT: TemplateArgument type 'void'
+// CHECK-NEXT: BuiltinType 0x{{[^ ]*}} 'void'
+// CHECK-NEXT: FunctionProtoType 0x{{[^ ]*}} 'void (int)' cdecl
+// CHECK-NEXT: SubstTemplateTypeParmType 0x{{[^ ]*}} 'void' sugar
+// CHECK-NEXT: TemplateTypeParmType 0x{{[^ ]*}} 'U' dependent depth 0 index 0
+// CHECK-NEXT: TemplateTypeParm 0x{{[^ ]*}} 'U'
+// CHECK-NEXT: BuiltinType 0x{{[^ ]*}} 'void'
+// CHECK-NEXT: SubstTemplateTypeParmType 0x{{[^ ]*}} 'int' sugar
+// CHECK-NEXT: TemplateTypeParmType 0x{{[^ ]*}} 'T' dependent depth 0 index 0
+} // namespace PR55886



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


[clang] 43ef17c - [clang] P2266: apply move elision rules on throw expr nested in function prototypes

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

Author: Matheus Izvekov
Date: 2022-06-07T00:08:24+02:00
New Revision: 43ef17cac172229f8b176b42cf0e5ae6c82adbde

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

LOG: [clang] P2266: apply move elision rules on throw expr nested in function 
prototypes

Our rules to determine if the throw expression are within the variable
scope were giving a false negative result in case the throw expression
would appear within a decltype in a nested function declaration.

Per P2266R3, the relevant rule is: [expr.prim.id.unqual]/2
```
if the id-expression (possibly parenthesized) is the operand of a 
throw-expression, and names an implicitly movable entity that belongs to a 
scope that does not contain the compound-statement of the innermost 
lambda-expression, try-block , or function-try-block (if any) whose 
compound-statement or ctor-initializer encloses the throw-expression.
```

This fixes PR54341.

Signed-off-by: Matheus Izvekov 

Reviewed By: rsmith

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

Added: 


Modified: 
clang/lib/Sema/SemaExprCXX.cpp
clang/test/CXX/class/class.init/class.copy.elision/p3.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 27ec863e7a35e..6c2c61639be77 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -843,10 +843,10 @@ Sema::ActOnCXXThrow(Scope *S, SourceLocation OpLoc, Expr 
*Ex) {
   break;
 }
 
+// FIXME: Many of the scope checks here seem incorrect.
 if (S->getFlags() &
 (Scope::FnScope | Scope::ClassScope | Scope::BlockScope |
- Scope::FunctionPrototypeScope | Scope::ObjCMethodScope |
- Scope::TryScope))
+ Scope::ObjCMethodScope | Scope::TryScope))
   break;
   }
 }

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 d7b52c561a547..975557c5187bb 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
@@ -98,7 +98,7 @@ struct A1 {
   A1(const A1 &);
   A1(A1 &&) = delete;
   // expected-note@-1 2{{'A1' has been explicitly marked deleted here}}
-  // cxx11_2b-note@-2  {{'A1' has been explicitly marked deleted here}}
+  // cxx11_2b-note@-2 3{{'A1' has been explicitly marked deleted here}}
 };
 void test1() {
   try {
@@ -132,10 +132,10 @@ void test3(A1 a) try {
 namespace PR54341 {
 void test4(A1 a) {
   void f(decltype((throw a, 0)));
-  // expected-warning@-1 {{has no effect}}
+  // expected-error@-1 {{call to deleted constructor of 
'test_throw_parameter::A1'}}
 
   void g(int = decltype(throw a, 0){});
-  // expected-warning@-1 {{has no effect}}
+  // expected-error@-1 {{call to deleted constructor of 
'test_throw_parameter::A1'}}
 }
 
 void test5(A1 a, int = decltype(throw a, 0){}) {}



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


[clang] f62433f - [NFC] Add test cases reported in PR54341

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

Author: Matheus Izvekov
Date: 2022-06-05T20:34:28+02:00
New Revision: f62433f17c304a8bd8458a60eb32cd86ecf507a4

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

LOG: [NFC] Add test cases reported in PR54341

Signed-off-by: Matheus Izvekov 

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

Added: 


Modified: 
clang/test/CXX/class/class.init/class.copy.elision/p3.cpp

Removed: 




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 7055acad6ccf..d7b52c561a54 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
@@ -96,7 +96,9 @@ void func();
 
 struct A1 {
   A1(const A1 &);
-  A1(A1 &&) = delete; // expected-note 2{{'A1' has been explicitly marked 
deleted here}}
+  A1(A1 &&) = delete;
+  // expected-note@-1 2{{'A1' has been explicitly marked deleted here}}
+  // cxx11_2b-note@-2  {{'A1' has been explicitly marked deleted here}}
 };
 void test1() {
   try {
@@ -125,6 +127,22 @@ void test3(A1 a) try {
 } catch (...) {
   throw a; // expected-error {{call to deleted constructor of 
'test_throw_parameter::A1'}}
 }
+
+#if __cplusplus >= 201103L
+namespace PR54341 {
+void test4(A1 a) {
+  void f(decltype((throw a, 0)));
+  // expected-warning@-1 {{has no effect}}
+
+  void g(int = decltype(throw a, 0){});
+  // expected-warning@-1 {{has no effect}}
+}
+
+void test5(A1 a, int = decltype(throw a, 0){}) {}
+// expected-error@-1 {{call to deleted constructor of 
'test_throw_parameter::A1'}}
+} // namespace PR54341
+#endif
+
 } // namespace test_throw_parameter
 
 // During the first overload resolution, the selected function no



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


[clang] c825abd - [clang] NFC: introduce test for D126620

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

Author: Matheus Izvekov
Date: 2022-05-30T22:45:57+02:00
New Revision: c825abd6b0198fb088d9752f556a70705bc99dfd

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

LOG: [clang] NFC: introduce test for D126620

Signed-off-by: Matheus Izvekov 

Reviewed By: v.g.vassilev

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

Added: 


Modified: 
clang/test/CXX/temp/temp.decls/temp.class.spec/p6.cpp

Removed: 




diff  --git a/clang/test/CXX/temp/temp.decls/temp.class.spec/p6.cpp 
b/clang/test/CXX/temp/temp.decls/temp.class.spec/p6.cpp
index 38dde7367fea..7eddef1cb71f 100644
--- a/clang/test/CXX/temp/temp.decls/temp.class.spec/p6.cpp
+++ b/clang/test/CXX/temp/temp.decls/temp.class.spec/p6.cpp
@@ -74,3 +74,16 @@ namespace rdar8651930 {
   int array0[Outer::Inner::value? 1 : -1];
   int array1[Outer::Inner::value? -1 : 1];
 }
+
+namespace print_dependent_TemplateSpecializationType {
+
+template  struct Foo {
+  template  struct Bar;
+  template  struct Bar<0, T, Y> {};
+  // expected-note-re@-1 {{previous declaration {{.*}} 'Bar<0UL, int, 
type-parameter-0-0>' is here}}
+  template  struct Bar<0, U, Y> {};
+  // expected-error@-1 {{partial specialization 'Bar<0, int, Y>' cannot be 
redeclared}}
+};
+template struct Foo; // expected-note {{requested here}}
+
+} // namespace print_dependent_TemplateSpecializationType



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


[clang] 9331912 - cmake: fix clang standalone build

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

Author: Matheus Izvekov
Date: 2022-05-30T21:56:38+02:00
New Revision: 93319128d0d4eda22ce8d531ba668cb8c7c8c8e8

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

LOG: cmake: fix clang standalone build

D126308 broke building clang standalone, as LLVM_UTILS_INSTALL_DIR is
not exported.

Signed-off-by: Matheus Izvekov 

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

Added: 


Modified: 
clang/utils/hmaptool/CMakeLists.txt

Removed: 




diff  --git a/clang/utils/hmaptool/CMakeLists.txt 
b/clang/utils/hmaptool/CMakeLists.txt
index 375d7b044882..01b6a920fb94 100644
--- a/clang/utils/hmaptool/CMakeLists.txt
+++ b/clang/utils/hmaptool/CMakeLists.txt
@@ -2,7 +2,7 @@ add_custom_command(OUTPUT "${LLVM_TOOLS_BINARY_DIR}/hmaptool"
COMMAND "${CMAKE_COMMAND}" -E copy 
"${CMAKE_CURRENT_SOURCE_DIR}/hmaptool" "${LLVM_TOOLS_BINARY_DIR}"
DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/hmaptool")
 
-install(PROGRAMS hmaptool DESTINATION "${LLVM_UTILS_INSTALL_DIR}" COMPONENT 
hmaptool)
+install(PROGRAMS hmaptool DESTINATION "${LLVM_TOOLS_INSTALL_DIR}" COMPONENT 
hmaptool)
 add_custom_target(hmaptool ALL DEPENDS "${LLVM_TOOLS_BINARY_DIR}/hmaptool")
 set_target_properties(hmaptool PROPERTIES FOLDER "Utils")
 



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


[clang] bf1ab1f - cmake: use llvm dir variables for clang/utils/hmaptool

2022-05-27 Thread Matheus Izvekov via cfe-commits

Author: Matheus Izvekov
Date: 2022-05-27T18:44:58+02:00
New Revision: bf1ab1f0eb9578914343f48096229ecccd0ecf52

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

LOG: cmake: use llvm dir variables for clang/utils/hmaptool

Install hmaptool using the LLVM specific variables, so
everything goes in the right place in case llvm is included
from a top level CMakeLists.txt.

Signed-off-by: Matheus Izvekov 

Reviewed By: stephenneuendorffer

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

Added: 


Modified: 
clang/utils/hmaptool/CMakeLists.txt

Removed: 




diff  --git a/clang/utils/hmaptool/CMakeLists.txt 
b/clang/utils/hmaptool/CMakeLists.txt
index f0d9866782b8..320a24da346d 100644
--- a/clang/utils/hmaptool/CMakeLists.txt
+++ b/clang/utils/hmaptool/CMakeLists.txt
@@ -1,19 +1,9 @@
-set(CLANG_HMAPTOOL hmaptool)
+add_custom_command(OUTPUT "${LLVM_TOOLS_BINARY_DIR}/hmaptool"
+   COMMAND "${CMAKE_COMMAND}" -E copy 
"${CMAKE_CURRENT_SOURCE_DIR}/hmaptool" "${LLVM_TOOLS_BINARY_DIR}"
+   DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/hmaptool")
 
-add_custom_command(OUTPUT 
${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin/${CLANG_HMAPTOOL}
-   COMMAND ${CMAKE_COMMAND} -E make_directory
- ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin
-   COMMAND ${CMAKE_COMMAND} -E copy
- ${CMAKE_CURRENT_SOURCE_DIR}/${CLANG_HMAPTOOL}
- ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin/
-   DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${CLANG_HMAPTOOL})
-
-list(APPEND Depends 
${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin/${CLANG_HMAPTOOL})
-install(PROGRAMS ${CLANG_HMAPTOOL}
-DESTINATION "${CMAKE_INSTALL_BINDIR}"
-COMPONENT hmaptool)
-
-add_custom_target(hmaptool ALL DEPENDS ${Depends})
+install(PROGRAMS hmaptool DESTINATION "${LLVM_UTILS_INSTALL_DIR}}" COMPONENT 
hmaptool)
+add_custom_target(hmaptool ALL DEPENDS "${LLVM_TOOLS_BINARY_DIR}/hmaptool")
 set_target_properties(hmaptool PROPERTIES FOLDER "Utils")
 
 if(NOT LLVM_ENABLE_IDE)



___
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 ,
 SmallVectorImpl , 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  = h((int(*)(int, float&))0);
   double  = 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


[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 , 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] 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] 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  = [] (int ) -> decltype(auto) { return r; } (a);
 int  = [] (int ) -> decltype(auto) { return (r); } (a);
 int  = [] (int ) -> auto & { return r; } (a);
 int  = [] (int ) -> auto { return r; } (a); // expected-error {{cannot 
bind to a temporary}}
-int  = [] (int r) -> decltype(auto) { return r; } (a); // expected-error 
{{cannot bind to a temporary}}
+int  = [] (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  = [] (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) {} // expected-error 

[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 ,
 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 ,
   // enabled.
   if (CoverageFeatures & CoverageTraceBB)
 D.Diag(clang::diag::warn_drv_deprecated_arg)
-<< "-fsanitize-coverage=trace-bb"
+<< "-fsanitize-coverage=trace-bb" 

[clang] 489561d - [clang] fix typo correction not looking for candidates in base classes.

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

Author: Matheus Izvekov
Date: 2021-10-16T00:35:22+02:00
New Revision: 489561d46381d41a068beed1a2e18e00f0660248

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

LOG: [clang] fix typo correction not looking for candidates in base classes.

RecordMemberExprValidator was not looking through ElaboratedType
nodes when looking for candidates which occur in base classes.

Signed-off-by: Matheus Izvekov 

Reviewed By: rsmith

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

Added: 


Modified: 
clang/lib/Sema/SemaExprMember.cpp
clang/test/CXX/drs/dr1xx.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaExprMember.cpp 
b/clang/lib/Sema/SemaExprMember.cpp
index 2a3b696417d8..83006f9d804a 100644
--- a/clang/lib/Sema/SemaExprMember.cpp
+++ b/clang/lib/Sema/SemaExprMember.cpp
@@ -611,11 +611,10 @@ class RecordMemberExprValidatorCCC final : public 
CorrectionCandidateCallback {
 if (Record->containsDecl(ND))
   return true;
 
-if (const CXXRecordDecl *RD = dyn_cast(Record)) {
+if (const auto *RD = dyn_cast(Record)) {
   // Accept candidates that occur in any of the current class' base 
classes.
   for (const auto  : RD->bases()) {
-if (const RecordType *BSTy =
-dyn_cast_or_null(BS.getType().getTypePtrOrNull())) 
{
+if (const auto *BSTy = BS.getType()->getAs()) {
   if (BSTy->getDecl()->containsDecl(ND))
 return true;
 }

diff  --git a/clang/test/CXX/drs/dr1xx.cpp b/clang/test/CXX/drs/dr1xx.cpp
index 4efa2e2fa943..51abb36dc9e3 100644
--- a/clang/test/CXX/drs/dr1xx.cpp
+++ b/clang/test/CXX/drs/dr1xx.cpp
@@ -477,7 +477,7 @@ namespace dr140 { // dr140: yes
 
 namespace dr141 { // dr141: yes
   template void f();
-  template struct S { int n; };
+  template struct S { int n; }; // expected-note 
{{'::dr141::S::n' declared here}}
   struct A : S {
 template void f();
 template struct S {};
@@ -485,7 +485,7 @@ namespace dr141 { // dr141: yes
   struct B : S {} b;
   void g() {
 a.f();
-(void)a.S::n; // expected-error {{no member named 'n'}}
+(void)a.S::n; // expected-error {{no member named 'n' in 
'dr141::A::S'; did you mean '::dr141::S::n'?}}
 #if __cplusplus < 201103L
 // expected-error@-2 {{ambiguous}}
 // expected-note@-11 {{lookup from the current scope}}



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


[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 

[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 (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 );
-  bool Subst(const TemplateArgumentLoc *Args, unsigned NumArgs,
- TemplateArgumentListInfo ,
- const MultiLevelTemplateArgumentList );
+
+  bool SubstTypeConstraint(TemplateTypeParmDecl *Inst, const TypeConstraint 
*TC,
+   const MultiLevelTemplateArgumentList );
 
   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 ?  : 
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(),
+  MultiLevelTemplateArgumentList(*DeducedArgumentList), InstArgs)) {
 unsigned ArgIdx = 

[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 ,
-   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 , 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 ,
@@ -438,15 +445,16 @@ void 
FunctionTemplateDecl::mergePrevDecl(FunctionTemplateDecl *Prev) {
 // ClassTemplateDecl Implementation
 
//===--===//
 
-ClassTemplateDecl *ClassTemplateDecl::Create(ASTContext ,
- DeclContext *DC,
+ClassTemplateDecl *ClassTemplateDecl::Create(ASTContext , 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 ,
@@ -1005,8 +1013,11 @@ ConceptDecl *ConceptDecl::Create(ASTContext , 
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 ,
@@ -1039,7 +1050,8 @@ ClassTemplatePartialSpecializationDecl(ASTContext 
, TagKind TK,
   SpecializedTemplate, Args, PrevDecl),
   

[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 

[clang] 2d6829b - [clang] disable implicit moves when not in CPlusPLus

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

Author: Matheus Izvekov
Date: 2021-09-14T11:29:47+02:00
New Revision: 2d6829bbbe6877920d9be1db93b9f3fc85b43d10

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

LOG: [clang] disable implicit moves when not in CPlusPLus

See PR51842.

This fixes an assert firing in the static analyzer, triggered by implicit moves
in blocks in C mode:

This also simplifies the AST a little bit when compiling non C++ code,
as the xvalue implicit casts are not inserted.

We keep and test that the nrvo flag is still being set on the VarDecls,
as that is still a bit beneficial while not really making anything
more complicated.

Signed-off-by: Matheus Izvekov 

Reviewed By: NoQ

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

Added: 
clang/test/AST/nrvo.c
clang/test/Analysis/blocks-nrvo.c

Modified: 
clang/lib/Sema/SemaStmt.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index dc93e9e1c51c5..813925460241e 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -3481,7 +3481,8 @@ VerifyInitializationSequenceCXX98(const Sema ,
 ExprResult Sema::PerformMoveOrCopyInitialization(
 const InitializedEntity , const NamedReturnInfo , Expr 
*Value,
 bool SupressSimplerImplicitMoves) {
-  if ((!getLangOpts().CPlusPlus2b || SupressSimplerImplicitMoves) &&
+  if (getLangOpts().CPlusPlus &&
+  (!getLangOpts().CPlusPlus2b || SupressSimplerImplicitMoves) &&
   NRInfo.isMoveEligible()) {
 ImplicitCastExpr AsRvalue(ImplicitCastExpr::OnStack, Value->getType(),
   CK_NoOp, Value, VK_XValue, FPOptionsOverride());

diff  --git a/clang/test/AST/nrvo.c b/clang/test/AST/nrvo.c
new file mode 100644
index 0..4f50d6a1e384b
--- /dev/null
+++ b/clang/test/AST/nrvo.c
@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -ast-dump -fblocks %s | FileCheck -strict-whitespace %s
+
+struct A {};
+
+struct A f1() {
+  // CHECK:  FunctionDecl 0x{{[^ ]*}}  line:[[@LINE-1]]:10 f1 'struct A ()'
+  // CHECK-NEXT: CompoundStmt 0x{{[^ ]*}} 
+  struct A a;
+  // CHECK-NEXT: DeclStmt 0x{{[^ ]*}} 
+  // CHECK-NEXT: VarDecl 0x{{[^ ]*}}  col:12 used a 'struct 
A':'struct A' nrvo
+  return a;
+  // CHECK-NEXT: ReturnStmt 0x{{[^ ]*}} 
+  // CHECK-NEXT: ImplicitCastExpr 0x{{[^ ]*}}  'struct A':'struct A' 

+  // CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}}  'struct A':'struct A' lvalue 
Var 0x{{[^ ]*}} 'a' 'struct A':'struct A'
+}
+
+void f2() {
+  (void)^{
+// CHECK:  BlockDecl 0x{{[^ ]*}}  line:[[@LINE-1]]:9
+// CHECK-NEXT: CompoundStmt 0x{{[^ ]*}} 
+struct A a;
+// CHECK-NEXT: DeclStmt 0x{{[^ ]*}} 
+// CHECK-NEXT: VarDecl 0x{{[^ ]*}}  col:14 used a 'struct 
A':'struct A' nrvo
+return a;
+// CHECK-NEXT: ReturnStmt 0x{{[^ ]*}} 
+// CHECK-NEXT: ImplicitCastExpr 0x{{[^ ]*}}  'struct A':'struct A' 

+// CHECK-NEXT: DeclRefExpr 0x{{[^ ]*}}  'struct A':'struct A' 
lvalue Var 0x{{[^ ]*}} 'a' 'struct A':'struct A'
+  }();
+}

diff  --git a/clang/test/Analysis/blocks-nrvo.c 
b/clang/test/Analysis/blocks-nrvo.c
new file mode 100644
index 0..bb0be869ee767
--- /dev/null
+++ b/clang/test/Analysis/blocks-nrvo.c
@@ -0,0 +1,14 @@
+// RUN: %clang_analyze_cc1 -w -analyzer-checker=core -fblocks -verify %s
+
+// expected-no-diagnostics
+
+typedef struct {
+  int x;
+} S;
+
+void foo() {
+  ^{
+S s;
+return s; // no-crash
+  };
+}



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


[clang] 68b9d8e - [clang] fix transformation of template arguments of 'auto' type constraints

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

Author: Matheus Izvekov
Date: 2021-09-08T03:22:34+02:00
New Revision: 68b9d8ed7abe4046992ae1557990edfbb3a772bc

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

LOG: [clang] fix transformation of template arguments of 'auto' type constraints

See PR48617.

When assigning the new template arguments to the new TypeLoc, we were looping
on the argument count of the original TypeLoc instead of the new one,
which can be different when packs are present.

Signed-off-by: Matheus Izvekov 

Reviewed By: rsmith

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

Added: 


Modified: 
clang/lib/Sema/TreeTransform.h
clang/test/CXX/dcl/dcl.spec/dcl.type/dcl.spec.auto/p6.cpp

Removed: 




diff  --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index 8841b2e00d40f..2a7ceaf6425ee 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -6578,7 +6578,7 @@ QualType 
TreeTransform::TransformAutoType(TypeLocBuilder ,
   NewTL.setFoundDecl(TL.getFoundDecl());
   NewTL.setLAngleLoc(TL.getLAngleLoc());
   NewTL.setRAngleLoc(TL.getRAngleLoc());
-  for (unsigned I = 0; I < TL.getNumArgs(); ++I)
+  for (unsigned I = 0; I < NewTL.getNumArgs(); ++I)
 NewTL.setArgLocInfo(I, NewTemplateArgs.arguments()[I].getLocInfo());
 
   return Result;

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 7830d1f435262..4941027423217 100644
--- 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
@@ -76,3 +76,25 @@ namespace PR48593 {
   template concept d = true;
   d<,> auto e = 0; // expected-error{{expected expression}}
 }
+
+namespace PR48617 {
+  template  concept C = true;
+  template  class A {};
+
+  template  C auto e(A) { return 0; }
+
+  // FIXME: The error here does not make sense.
+  template auto e<>(A<>);
+  // expected-error@-1 {{explicit instantiation of 'e' does not refer to a 
function template}}
+  // expected-note@-5  {{candidate template ignored: failed template argument 
deduction}}
+
+  // FIXME: Should be able to instantiate this with no errors.
+  template C auto e(A);
+  // expected-error@-1 {{explicit instantiation of 'e' does not refer to a 
function template}}
+  // expected-note@-10 {{candidate template ignored: could not match 'C auto' against 'C auto'}}
+  
+  template C<> auto e<>(A<>);
+
+  template  A c(Ts...);
+  int f = e(c(1, 2));
+}



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


[clang] d98c34f - [clang] fix error recovery ICE on copy elision when returing invalid variable

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

Author: Matheus Izvekov
Date: 2021-09-03T20:34:08+02:00
New Revision: d98c34f4d7950f531661ba3f498222ccf6239a0f

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

LOG: [clang] fix error recovery ICE on copy elision when returing invalid 
variable

See PR51708.

Attempting copy elision in dependent contexts with invalid variable,
such as a variable with incomplete type, would cause a crash when attempting
to calculate it's alignment.

The fix is to just skip this optimization on invalid VarDecl, as otherwise this
provides no benefit to error recovery: This functionality does not try to
diagnose anything, it only calculates a flag which will affect where the
variable will be allocated during codegen.

Signed-off-by: Matheus Izvekov 

Reviewed By: rtrieu

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

Added: 


Modified: 
clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
clang/test/CXX/class/class.init/class.copy.elision/p3.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index d33c2545b4844..54ba12e0e644f 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -1087,7 +1087,7 @@ Decl *TemplateDeclInstantiator::VisitVarDecl(VarDecl *D,
 
   SemaRef.BuildVariableInstantiation(Var, D, TemplateArgs, LateAttrs, Owner,
  StartingScope, InstantiatingVarTemplate);
-  if (D->isNRVOVariable()) {
+  if (D->isNRVOVariable() && !Var->isInvalidDecl()) {
 QualType RT;
 if (auto *F = dyn_cast(DC))
   RT = F->getReturnType();

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 cd981264c9b69..7055acad6ccf9 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
@@ -518,3 +518,37 @@ template  X test_dependent_invalid_decl() {
 template X test_dependent_invalid_decl(); // expected-note 
{{requested here}}
 
 } // namespace test_auto_variables
+
+namespace PR51708 {
+
+class a1;  // expected-note 4 {{forward declaration of 
'PR51708::a1'}}
+template  class A2; // expected-note 4 {{template is declared here}}
+using a2 = A2;
+
+template  b f() {
+  // expected-error@-1 {{incomplete result type 'PR51708::a1' in function 
definition}}
+  // expected-error@-2 {{implicit instantiation of undefined template 
'PR51708::A2}}
+
+  b d;
+  // expected-error@-1 {{variable has incomplete type 'PR51708::a1'}}
+  // expected-error@-2 {{implicit instantiation of undefined template 
'PR51708::A2}}
+
+  return d;
+}
+template a1 f(); // expected-note-re {{in instantiation {{.*}} requested 
here}}
+template a2 f(); // expected-note-re {{in instantiation {{.*}} requested 
here}}
+
+template  b g() {
+  // expected-error@-1 {{incomplete result type 'PR51708::a1' in function 
definition}}
+  // expected-error@-2 {{implicit instantiation of undefined template 
'PR51708::A2}}
+
+  b d __attribute__((aligned(1)));
+  // expected-error@-1 {{variable has incomplete type 'PR51708::a1'}}
+  // expected-error@-2 {{implicit instantiation of undefined template 
'PR51708::A2}}
+
+  return d;
+}
+template a1 g(); // expected-note-re {{in instantiation {{.*}} requested 
here}}
+template a2 g(); // expected-note-re {{in instantiation {{.*}} requested 
here}}
+
+} // namespace PR51708



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


[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 ) {
+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
+++ 

[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 ,
SmallVectorImpl );
 
-  bool CheckTemplateArgument(TemplateTypeParmDecl *Param,
- TypeSourceInfo *Arg);
+  bool CheckTemplateArgument(TypeSourceInfo *Arg);
   ExprResult CheckTemplateArgument(NonTypeTemplateParmDecl *Param,
QualType InstantiatedParamType, Expr *Arg,
TemplateArgument ,

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/SemaTemplate.cpp
index 

[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 , 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] 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 , 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 
) 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 ,
 Expr *e = Req->getExpr();
 S.Diag(e->getBeginLoc(),
diag::note_expr_requirement_constraints_not_satisfied_simple)
-<< (int)First << S.getDecltypeForParenthesizedExpr(e)
+<< (int)First << 

[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 ,
 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 , 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 , 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 ,
   }
 
   // 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] 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 *, bool ForceCXX2b = false);
+  enum class SimplerImplicitMoveMode { ForceOff, Normal, ForceOn };
+  NamedReturnInfo getNamedReturnInfo(
+  Expr *, SimplerImplicitMoveMode Mode = 
SimplerImplicitMoveMode::Normal);
   NamedReturnInfo getNamedReturnInfo(const VarDecl *VD);
   const VarDecl *getCopyElisionCandidate(NamedReturnInfo ,
  QualType ReturnType);
 
-  ExprResult PerformMoveOrCopyInitialization(const InitializedEntity ,
- const NamedReturnInfo ,
- Expr *Value);
+  ExprResult
+  PerformMoveOrCopyInitialization(const InitializedEntity ,
+  const NamedReturnInfo , 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 );
+ NamedReturnInfo ,
+ 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 ,
   }
   // 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 *, bool ForceCXX2b) {
+Sema::NamedReturnInfo Sema::getNamedReturnInfo(Expr *,
+   

[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 ,
   const NamedReturnInfo ,
   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 = 

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] 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 ,
   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 ,
+  const InitializationSequence ) {
+  const auto *Step = llvm::find_if(Seq.steps(), [](const auto ) {
+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 ,
   const NamedReturnInfo ,
   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 = 
@@ -3470,7 +3491,9 @@ Sema::PerformMoveOrCopyInitialization(const 
InitializedEntity ,
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 =

diff  --git 

[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] 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 ,
   }
   // 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 *, 
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 &();
+
+MoveOnly &(MoveOnly &) {
+  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 &(T &) { return x; } // old-error {{cannot bind 
to lvalue of type}}
+template MoveOnly (MoveOnly &);
+template MoveOnly &(MoveOnly &&); // old-note {{in 
instantiation of function template specialization}}
+
+MoveOnly &() {
+  MoveOnly & = 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

[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(); // 

[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 

[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 *, bool ForceCXX2b = false);
-  NamedReturnInfo getNamedReturnInfo(const VarDecl *VD,
- bool ForceCXX20 = false);
+  NamedReturnInfo getNamedReturnInfo(const VarDecl *VD);
   const VarDecl *getCopyElisionCandidate(NamedReturnInfo ,
  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 *, 
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 
*, 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 , 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 isMoveEligible

[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 ,
 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] 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] 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 *, bool ForceCXX2b = false);
   NamedReturnInfo getNamedReturnInfo(const VarDecl *VD,
  bool ForceCXX20 = false);
   const VarDecl *getCopyElisionCandidate(NamedReturnInfo ,

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 ) {
   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, 

[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] 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] 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 ,
- const VarDecl *NRVOCandidate,
- QualType ResultType,
- Expr *Value,
- bool AllowNRVO = true);
-
   bool CanPerformAggregateInitializationForOverloadResolution(
   const InitializedEntity , 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 ,
+ QualType ReturnType);
 
-  VarDecl *getCopyElisionCandidate(QualType ReturnType, Expr *E,
-   CopyElisionSemanticsKind CESK);
-  bool isCopyElisionCandidate(QualType ReturnType, const VarDecl *VD,
-  CopyElisionSemanticsKind CESK);
+  ExprResult PerformMoveOrCopyInitialization(const InitializedEntity ,
+ const NamedReturnInfo ,
+ 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 );
 
   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 constructor and
 // resolve its destructor's 

[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 *, bool ForceCXX2b = false);
   NamedReturnInfo getNamedReturnInfo(const VarDecl *VD,
  bool ForceCXX20 = false);
   const VarDecl *getCopyElisionCandidate(NamedReturnInfo ,

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 returned 

[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 ,
- const VarDecl *NRVOCandidate,
- QualType ResultType,
- Expr *Value,
- bool AllowNRVO = true);
-
   bool CanPerformAggregateInitializationForOverloadResolution(
   const InitializedEntity , 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 ,
+ QualType ReturnType);
 
-  VarDecl *getCopyElisionCandidate(QualType ReturnType, Expr *E,
-   CopyElisionSemanticsKind CESK);
-  bool isCopyElisionCandidate(QualType ReturnType, const VarDecl *VD,
-  CopyElisionSemanticsKind CESK);
+  ExprResult PerformMoveOrCopyInitialization(const InitializedEntity ,
+ const NamedReturnInfo ,
+ 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 );
 
   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 ) {
   SourceLocation Loc = VD->getLocation();
   Expr *VarRef =
   new (S.Context) DeclRefExpr(S.Context, VD, false, T, VK_LValue, Loc);
-  ExprResult Result = 

[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 *, bool ForceCXX2b = false);
   NamedReturnInfo getNamedReturnInfo(const VarDecl *VD,
  bool ForceCXX20 = false);
   const VarDecl *getCopyElisionCandidate(NamedReturnInfo ,

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 the 

[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 ,
- const VarDecl *NRVOCandidate,
- QualType ResultType,
- Expr *Value,
- bool AllowNRVO = true);
-
   bool CanPerformAggregateInitializationForOverloadResolution(
   const InitializedEntity , 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 ,
+ QualType ReturnType);
 
-  VarDecl *getCopyElisionCandidate(QualType ReturnType, Expr *E,
-   CopyElisionSemanticsKind CESK);
-  bool isCopyElisionCandidate(QualType ReturnType, const VarDecl *VD,
-  CopyElisionSemanticsKind CESK);
+  ExprResult PerformMoveOrCopyInitialization(const InitializedEntity ,
+ const NamedReturnInfo ,
+ 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 );
 
   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 ) {
   SourceLocation Loc = VD->getLocation();
   Expr *VarRef =
   new (S.Context) DeclRefExpr(S.Context, VD, false, T, VK_LValue, Loc);
-  ExprResult Result = 

[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 ,
   // 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 ,
  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 ) 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] 1819222 - [clang] tests: cleanup, update and add some new ones

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

Author: Matheus Izvekov
Date: 2021-04-09T17:24:08+02:00
New Revision: 18192228602c6a8093fb0eefa863ab854dd03e59

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

LOG: [clang] tests: cleanup, update and add some new ones

This reworks a small set of tests, as preparatory work for implementing
P2266.
* Run for more standard versions, including c++2b.
* Normalize file names and run commands.
* Adds some extra tests.

New Coroutine tests taken from Aaron Puchert's D68845.

Signed-off-by: Matheus Izvekov 

Reviewed By: thakis

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

Added: 
clang/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p7-cxx14.cpp
clang/test/CXX/expr/expr.prim/expr.prim.lambda/p4-cxx14.cpp
clang/test/CXX/special/class.copy/p3-cxx11.cpp
clang/test/CodeGen/nrvo-tracking.cpp
clang/test/SemaCXX/constant-expression-cxx14.cpp
clang/test/SemaCXX/deduced-return-type-cxx14.cpp

Modified: 
clang/test/CXX/class/class.init/class.copy.elision/p3.cpp
clang/test/CXX/drs/dr3xx.cpp
clang/test/CXX/temp/temp.decls/temp.mem/p5.cpp
clang/test/SemaCXX/P1155.cpp
clang/test/SemaCXX/constant-expression-cxx11.cpp
clang/test/SemaCXX/conversion-function.cpp
clang/test/SemaCXX/coroutine-rvo.cpp
clang/test/SemaCXX/coroutines.cpp
clang/test/SemaCXX/return-stack-addr.cpp
clang/test/SemaCXX/warn-return-std-move.cpp

Removed: 
clang/test/CXX/dcl.dcl/dcl.spec/dcl.type/dcl.spec.auto/p7-1y.cpp
clang/test/CXX/expr/expr.prim/expr.prim.lambda/p4-1y.cpp
clang/test/CXX/special/class.copy/p33-0x.cpp
clang/test/SemaCXX/constant-expression-cxx1y.cpp
clang/test/SemaCXX/cxx1y-deduced-return-type.cpp



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 e4056221b4f3c..9d1d7d9a0d8bd 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
@@ -1,7 +1,8 @@
-// RUN: %clang_cc1 -std=c++20 -fsyntax-only -fcxx-exceptions 
-verify=expected,cxx20 %s
-// RUN: %clang_cc1 -std=c++17 -fsyntax-only -fcxx-exceptions 
-verify=expected,cxx11_14_17 %s
-// RUN: %clang_cc1 -std=c++14 -fsyntax-only -fcxx-exceptions 
-verify=expected,cxx11_14_17 %s
-// RUN: %clang_cc1 -std=c++11 -fsyntax-only -fcxx-exceptions 
-verify=expected,cxx11_14_17 %s
+// RUN: %clang_cc1 -std=c++2b -fsyntax-only -fcxx-exceptions 
-verify=expected,cxx20_2b %s
+// RUN: %clang_cc1 -std=c++20 -fsyntax-only -fcxx-exceptions 
-verify=expected,cxx20_2b %s
+// RUN: %clang_cc1 -std=c++17 -fsyntax-only -fcxx-exceptions 
-verify=expected,cxx11_17 %s
+// RUN: %clang_cc1 -std=c++14 -fsyntax-only -fcxx-exceptions 
-verify=expected,cxx11_17 %s
+// RUN: %clang_cc1 -std=c++11 -fsyntax-only -fcxx-exceptions 
-verify=expected,cxx11_17 %s
 
 namespace test_delete_function {
 struct A1 {
@@ -54,38 +55,38 @@ B2 test4() {
 namespace test_implicitly_movable_rvalue_ref {
 struct A1 {
   A1(A1 &&);
-  A1(const A1 &) = delete; // cxx11_14_17-note {{'A1' has been explicitly 
marked deleted here}}
+  A1(const A1 &) = delete; // cxx11_17-note {{'A1' has been explicitly marked 
deleted here}}
 };
 A1 test1(A1 &) {
-  return a; // cxx11_14_17-error {{call to deleted constructor of 
'test_implicitly_movable_rvalue_ref::A1'}}
+  return a; // cxx11_17-error {{call to deleted constructor of 
'test_implicitly_movable_rvalue_ref::A1'}}
 }
 
 struct A2 {
   A2(A2 &&);
 
 private:
-  A2(const A2 &); // cxx11_14_17-note {{declared private here}}
+  A2(const A2 &); // cxx11_17-note {{declared private here}}
 };
 A2 test2(A2 &) {
-  return a; // cxx11_14_17-error {{calling a private constructor of class 
'test_implicitly_movable_rvalue_ref::A2'}}
+  return a; // cxx11_17-error {{calling a private constructor of class 
'test_implicitly_movable_rvalue_ref::A2'}}
 }
 
 struct B1 {
   B1(const B1 &);
-  B1(B1 &&) = delete; // cxx20-note {{'B1' has been explicitly marked deleted 
here}}
+  B1(B1 &&) = delete; // cxx20_2b-note {{'B1' has been explicitly marked 
deleted here}}
 };
 B1 test3(B1 &) {
-  return b; // cxx20-error {{call to deleted constructor of 
'test_implicitly_movable_rvalue_ref::B1'}}
+  return b; // cxx20_2b-error {{call to deleted constructor of 
'test_implicitly_movable_rvalue_ref::B1'}}
 }
 
 struct B2 {
   B2(const B2 &);
 
 private:
-  B2(B2 &&); // cxx20-note {{declared private here}}
+  B2(B2 &&); // cxx20_2b-note {{declared private here}}
 };
 B2 test4(B2 &) {
-  return b; // cxx20-error {{calling a private constructor of class 
'test_implicitly_movable_rvalue_ref::B2'}}
+  return b; // cxx20_2b-error {{calling a private constructor of class 
'test_implicitly_movable_rvalue_ref::B2'}}
 }
 } // namespace test_implicitly_movable_rvalue_ref
 
@@ 

[clang] bac74a5 - [clang] NFC: remove trailing white spaces from some tests

2021-04-02 Thread Matheus Izvekov via cfe-commits

Author: Matheus Izvekov
Date: 2021-04-03T03:18:22+02:00
New Revision: bac74a50e99f3d014d6e5a67272fd3b20eeb7fed

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

LOG: [clang] NFC: remove trailing white spaces from some tests

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

Added: 


Modified: 
clang/test/CXX/drs/dr3xx.cpp
clang/test/CXX/expr/expr.prim/expr.prim.lambda/p4-1y.cpp
clang/test/CXX/special/class.copy/p33-0x.cpp
clang/test/CXX/temp/temp.decls/temp.mem/p5.cpp
clang/test/SemaCXX/conversion-function.cpp
clang/test/SemaCXX/cxx1y-deduced-return-type.cpp

Removed: 




diff  --git a/clang/test/CXX/drs/dr3xx.cpp b/clang/test/CXX/drs/dr3xx.cpp
index 5eb6e05126295..239a04c685d73 100644
--- a/clang/test/CXX/drs/dr3xx.cpp
+++ b/clang/test/CXX/drs/dr3xx.cpp
@@ -1103,7 +1103,7 @@ namespace dr384 { // dr384: yes
 }
 
 namespace dr385 { // dr385: yes
-  struct A { protected: void f(); }; 
+  struct A { protected: void f(); };
   struct B : A { using A::f; };
   struct C : A { void g(B b) { b.f(); } };
   void h(B b) { b.f(); }

diff  --git a/clang/test/CXX/expr/expr.prim/expr.prim.lambda/p4-1y.cpp 
b/clang/test/CXX/expr/expr.prim/expr.prim.lambda/p4-1y.cpp
index f2b0e26e29f94..95ae7f7588088 100644
--- a/clang/test/CXX/expr/expr.prim/expr.prim.lambda/p4-1y.cpp
+++ b/clang/test/CXX/expr/expr.prim/expr.prim.lambda/p4-1y.cpp
@@ -9,7 +9,7 @@ int  = [] (int r) -> decltype(auto) { return r; } (a); // 
expected-error {{can
 int  = [] (int r) -> decltype(auto) { return (r); } (a); // expected-warning 
{{reference to stack}}
 
 
-int test_explicit_auto_return() 
+int test_explicit_auto_return()
 {
 struct X {};
 auto L = [](auto F, auto a) { return F(a); };
@@ -18,32 +18,32 @@ int test_explicit_auto_return()
 auto MPtr = [](auto c) -> auto* { return  }; 
//expected-warning{{address of stack}}
 auto MDeclType = [](auto&& d) -> decltype(auto) { return 
static_cast(d); }; //OK
 M(3);
-
+
 auto & = MDeclType(X{});
 auto & = M(X{});
 auto & = MRef(X{});//expected-note{{in instantiation of}}
 auto & = MPtr(X{}); //expected-note{{in instantiation of}}
-return 0;
+return 0;
 }
 
-int test_implicit_auto_return() 
-{  
+int test_implicit_auto_return()
+{
   {
 auto M = [](auto a) { return a; };
 struct X {};
 X x = M(X{});
-
+
   }
 }
- 
+
 int test_multiple_returns()  {
-auto M = [](auto a) { 
+auto M = [](auto a) {
   bool k;
   if (k)
 return a;
   else
 return 5; //expected-error{{deduced as 'int' here}}
-}; 
+};
 M(3); // OK
 M('a'); //expected-note{{in instantiation of}}
   return 0;
@@ -60,7 +60,7 @@ int test_no_parameter_list()
 }
 
 int test_conditional_in_return() {
-  auto Fac = [](auto f, auto n) { 
+  auto Fac = [](auto f, auto n) {
 return n <= 0 ? n : f(f, n - 1) * n;
   };
   // FIXME: this test causes a recursive limit - need to error more gracefully.

diff  --git a/clang/test/CXX/special/class.copy/p33-0x.cpp 
b/clang/test/CXX/special/class.copy/p33-0x.cpp
index 28cd4f33a8aa6..ab6be4782e17d 100644
--- a/clang/test/CXX/special/class.copy/p33-0x.cpp
+++ b/clang/test/CXX/special/class.copy/p33-0x.cpp
@@ -22,7 +22,7 @@ void throw_move_only(X x) {
   throw x;
   throw x2;
 }
-  
+
 namespace PR10142 {
   struct X {
 X();

diff  --git a/clang/test/CXX/temp/temp.decls/temp.mem/p5.cpp 
b/clang/test/CXX/temp/temp.decls/temp.mem/p5.cpp
index a41ea6b5e109e..10f4988ec5a73 100644
--- a/clang/test/CXX/temp/temp.decls/temp.mem/p5.cpp
+++ b/clang/test/CXX/temp/temp.decls/temp.mem/p5.cpp
@@ -1,15 +1,15 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s
-struct A { 
+struct A {
   template  operator T*();
-}; 
+};
 
 template  A::operator T*() { return 0; }
 template <> A::operator char*(){ return 0; } // specialization
 template A::operator void*(); // explicit instantiation
 
-int main() { 
+int main() {
   A a;
-  int *ip; 
+  int *ip;
   ip = a.operator int*();
 }
 
@@ -33,7 +33,7 @@ namespace PR5742 {
 class Foo {
  public:
   template  operator T();
-  
+
   template 
   T As() {
 return this->operator T();
@@ -43,7 +43,7 @@ class Foo {
   T As2() {
 return operator T();
   }
-  
+
   int AsInt() {
 return this->operator int();
   }
@@ -58,9 +58,9 @@ struct X0 {
 T x = 1; // expected-note{{variable 'x' declared const here}}
 x = 17; // expected-error{{cannot assign to variable 'x' with 
const-qualified type 'const int'}}
   }
-  
+
   template operator T*() const; // expected-note{{explicit 
instantiation refers here}}
-  
+
   template operator const T*() const {
 T x = T();
 return x; // expected-error{{cannot initialize return object of type 
'const char *' with an lvalue of type 'char'}} \

diff  --git 

[clang] 3ad6dd5 - [clang] Use decltype((E)) for compound requirement type constraint

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

Author: Matheus Izvekov
Date: 2021-03-30T22:00:33+02:00
New Revision: 3ad6dd5d8f0a70756f665e8179ad7c5210022c11

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

LOG: [clang] Use decltype((E)) for compound requirement type constraint

See PR45088.

Compound requirement type constraints were using decltype(E) instead of
decltype((E)), as per `[expr.prim.req]p1.3.3`.

Since neither instantiation nor type dependence should matter for
the constraints, this uses an approach where a `decltype` type is not built,
and just the canonical type of the expression after template instantiation
is used on the requirement.

Signed-off-by: Matheus Izvekov 

Reviewed By: rsmith

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

Added: 


Modified: 
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaConcept.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/lib/Sema/SemaType.cpp
clang/test/CXX/expr/expr.prim/expr.prim.req/compound-requirement.cpp

Removed: 




diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index efabc78b45ba9..8e1bc3f2dbdab 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -2293,6 +2293,7 @@ class Sema final {
  const CXXScopeSpec , 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/Sema/SemaConcept.cpp b/clang/lib/Sema/SemaConcept.cpp
index 1ff7b1cdd5155..592bf5633ea5f 100644
--- a/clang/lib/Sema/SemaConcept.cpp
+++ b/clang/lib/Sema/SemaConcept.cpp
@@ -439,18 +439,19 @@ static void diagnoseUnsatisfiedRequirement(Sema ,
 case concepts::ExprRequirement::SS_ConstraintsNotSatisfied: {
   ConceptSpecializationExpr *ConstraintExpr =
   Req->getReturnTypeRequirementSubstitutedConstraintExpr();
-  if (ConstraintExpr->getTemplateArgsAsWritten()->NumTemplateArgs == 1)
+  if (ConstraintExpr->getTemplateArgsAsWritten()->NumTemplateArgs == 1) {
 // A simple case - expr type is the type being constrained and the 
concept
 // was not provided arguments.
-S.Diag(ConstraintExpr->getBeginLoc(),
+Expr *e = Req->getExpr();
+S.Diag(e->getBeginLoc(),
diag::note_expr_requirement_constraints_not_satisfied_simple)
-<< (int)First << S.BuildDecltypeType(Req->getExpr(),
- Req->getExpr()->getBeginLoc())
+<< (int)First << S.getDecltypeForParenthesizedExpr(e)
 << ConstraintExpr->getNamedConcept();
-  else
+  } else {
 S.Diag(ConstraintExpr->getBeginLoc(),
diag::note_expr_requirement_constraints_not_satisfied)
 << (int)First << ConstraintExpr;
+  }
   S.DiagnoseUnsatisfiedConstraint(ConstraintExpr->getSatisfaction());
   break;
 }

diff  --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 720e7b81c6378..4a4c8116d6f13 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -8663,7 +8663,7 @@ Sema::BuildExprRequirement(
 TemplateParameterList *TPL =
 ReturnTypeRequirement.getTypeConstraintTemplateParameterList();
 QualType MatchedType =
-BuildDecltypeType(E, E->getBeginLoc()).getCanonicalType();
+getDecltypeForParenthesizedExpr(E).getCanonicalType();
 llvm::SmallVector Args;
 Args.push_back(TemplateArgument(MatchedType));
 TemplateArgumentList TAL(TemplateArgumentList::OnStack, Args);

diff  --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 97971b3009817..ed0480ec2ac3c 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -8830,6 +8830,29 @@ QualType Sema::BuildTypeofExprType(Expr *E, 
SourceLocation Loc) {
   return Context.getTypeOfExprType(E);
 }
 
+/// getDecltypeForParenthesizedExpr - 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 Sema::getDecltypeForParenthesizedExpr(Expr *E) {
+  // 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 Context.getRValueReferenceType(T);
+  // - otherwise, if e is an lvalue, decltype(e) is T&, where T is the
+  //   type of e;
+  case VK_LValue:
+return 

[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 ) {
   return OpenCLAccessAttr::Keyword_read_only;
 }
 
-static QualType ConvertConstrainedAutoDeclSpecToType(Sema , DeclSpec ,
- 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  : 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 ) {
 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  : 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] 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 

<    1   2   3   4   5   6