Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert "[c++20] P1907R1: Support for generalized non-type template arguments of scalar type." #79302

Closed
wants to merge 1 commit into from

Conversation

erichkeane
Copy link
Collaborator

Reverts #78041

Based on this comment: #78041 (comment)

and the author's nonavailability to get to it quickly, we're reverting (and will have to revert from the release branch). Hopefully this can be reapplied for 19.

@erichkeane
Copy link
Collaborator Author

Waiting on CI bots, then I'll submit this revert, then request this for cherry-pick to the 18 branch.

@erichkeane erichkeane marked this pull request as ready for review January 24, 2024 15:15
@llvmbot llvmbot added clang Clang issues not falling into any other category clang-tools-extra lldb clangd clang:frontend Language frontend issues, e.g. anything involving "Sema" clang:modules C++20 modules and Clang Header Modules clang:codegen debuginfo labels Jan 24, 2024
Copy link

⚠️ C/C++ code formatter, clang-format found issues in your code. ⚠️

You can test this locally with the following command:
git-clang-format --diff aaa93ce7323332d8290b8f563d4d71689c1094c5 7d1982f62bfc9ec897d8dc8837100c6c2f2de156 -- clang-tools-extra/clangd/DumpAST.cpp clang-tools-extra/clangd/FindTarget.cpp clang/include/clang/AST/ODRHash.h clang/include/clang/AST/RecursiveASTVisitor.h clang/include/clang/AST/TemplateArgumentVisitor.h clang/include/clang/AST/TemplateBase.h clang/include/clang/Sema/Sema.h clang/lib/AST/ASTContext.cpp clang/lib/AST/ASTImporter.cpp clang/lib/AST/ASTStructuralEquivalence.cpp clang/lib/AST/Decl.cpp clang/lib/AST/ItaniumMangle.cpp clang/lib/AST/MicrosoftMangle.cpp clang/lib/AST/ODRHash.cpp clang/lib/AST/StmtProfile.cpp clang/lib/AST/TemplateBase.cpp clang/lib/AST/TypeLoc.cpp clang/lib/CodeGen/CGDebugInfo.cpp clang/lib/CodeGen/CGExpr.cpp clang/lib/Index/USRGeneration.cpp clang/lib/Sema/SemaLookup.cpp clang/lib/Sema/SemaOverload.cpp clang/lib/Sema/SemaTemplate.cpp clang/lib/Sema/SemaTemplateDeduction.cpp clang/lib/Sema/SemaTemplateInstantiate.cpp clang/lib/Sema/SemaTemplateVariadic.cpp clang/lib/Sema/TreeTransform.h clang/lib/Serialization/ASTReader.cpp clang/lib/Serialization/ASTWriter.cpp clang/test/CXX/drs/dr18xx.cpp clang/test/CXX/temp/temp.arg/temp.arg.nontype/p1.cpp clang/test/CodeGenCXX/mangle-ms-templates.cpp clang/test/CodeGenCXX/mangle-template.cpp clang/test/Modules/odr_hash.cpp clang/test/SemaCXX/warn-bool-conversion.cpp clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp clang/test/SemaTemplate/temp_arg_nontype_cxx20.cpp clang/tools/libclang/CIndex.cpp clang/tools/libclang/CXCursor.cpp lldb/include/lldb/lldb-enumerations.h lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
View the diff from clang-format here.
diff --git a/clang/include/clang/AST/TemplateBase.h b/clang/include/clang/AST/TemplateBase.h
index b7cd71f17c..d5e348eb50 100644
--- a/clang/include/clang/AST/TemplateBase.h
+++ b/clang/include/clang/AST/TemplateBase.h
@@ -297,7 +297,7 @@ public:
   /// Retrieve the type for a type template argument.
   QualType getAsType() const {
     assert(getKind() == Type && "Unexpected kind");
-    return QualType::getFromOpaquePtr(reinterpret_cast<void*>(TypeOrValue.V));
+    return QualType::getFromOpaquePtr(reinterpret_cast<void *>(TypeOrValue.V));
   }
 
   /// Retrieve the declaration for a declaration non-type
@@ -315,7 +315,7 @@ public:
   /// Retrieve the type for null non-type template argument.
   QualType getNullPtrType() const {
     assert(getKind() == NullPtr && "Unexpected kind");
-    return QualType::getFromOpaquePtr(reinterpret_cast<void*>(TypeOrValue.V));
+    return QualType::getFromOpaquePtr(reinterpret_cast<void *>(TypeOrValue.V));
   }
 
   /// Retrieve the template name for a template name argument.
@@ -541,13 +541,9 @@ public:
   /// - Fetches the full source range of the argument.
   SourceRange getSourceRange() const LLVM_READONLY;
 
-  const TemplateArgument &getArgument() const {
-    return Argument;
-  }
+  const TemplateArgument &getArgument() const { return Argument; }
 
-  TemplateArgumentLocInfo getLocInfo() const {
-    return LocInfo;
-  }
+  TemplateArgumentLocInfo getLocInfo() const { return LocInfo; }
 
   TypeSourceInfo *getTypeSourceInfo() const {
     if (Argument.getKind() != TemplateArgument::Type)
@@ -606,8 +602,7 @@ class TemplateArgumentListInfo {
 public:
   TemplateArgumentListInfo() = default;
 
-  TemplateArgumentListInfo(SourceLocation LAngleLoc,
-                           SourceLocation RAngleLoc)
+  TemplateArgumentListInfo(SourceLocation LAngleLoc, SourceLocation RAngleLoc)
       : LAngleLoc(LAngleLoc), RAngleLoc(RAngleLoc) {}
 
   // This can leak if used in an AST node, use ASTTemplateArgumentListInfo
@@ -626,21 +621,15 @@ public:
     return Arguments.data();
   }
 
-  llvm::ArrayRef<TemplateArgumentLoc> arguments() const {
-    return Arguments;
-  }
+  llvm::ArrayRef<TemplateArgumentLoc> arguments() const { return Arguments; }
 
   const TemplateArgumentLoc &operator[](unsigned I) const {
     return Arguments[I];
   }
 
-  TemplateArgumentLoc &operator[](unsigned I) {
-    return Arguments[I];
-  }
+  TemplateArgumentLoc &operator[](unsigned I) { return Arguments[I]; }
 
-  void addArgument(const TemplateArgumentLoc &Loc) {
-    Arguments.push_back(Loc);
-  }
+  void addArgument(const TemplateArgumentLoc &Loc) { Arguments.push_back(Loc); }
 };
 
 /// Represents an explicit template argument list in C++, e.g.,
diff --git a/clang/lib/AST/ODRHash.cpp b/clang/lib/AST/ODRHash.cpp
index c5aa91a81d..2ed26754db 100644
--- a/clang/lib/AST/ODRHash.cpp
+++ b/clang/lib/AST/ODRHash.cpp
@@ -1293,6 +1293,4 @@ void ODRHash::AddQualType(QualType T) {
   AddType(split.Ty);
 }
 
-void ODRHash::AddBoolean(bool Value) {
-  Bools.push_back(Value);
-}
+void ODRHash::AddBoolean(bool Value) { Bools.push_back(Value); }
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 839d508b91..9a63bfcb7f 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -7439,7 +7439,7 @@ ExprResult Sema::CheckTemplateArgument(NonTypeTemplateParmDecl *Param,
         return ExprError();
       }
 
-      auto *VD = const_cast<ValueDecl*>(Value.getMemberPointerDecl());
+      auto *VD = const_cast<ValueDecl *>(Value.getMemberPointerDecl());
       SugaredConverted = VD ? TemplateArgument(VD, ParamType)
                             : TemplateArgument(ParamType, /*isNullPtr=*/true);
       CanonicalConverted =
@@ -8129,8 +8129,8 @@ Sema::BuildExpressionFromIntegralTemplateArgument(const TemplateArgument &Arg,
     else
       Kind = CharacterLiteralKind::Ascii;
 
-    E = new (Context) CharacterLiteral(Arg.getAsIntegral().getZExtValue(),
-                                       Kind, T, Loc);
+    E = new (Context)
+        CharacterLiteral(Arg.getAsIntegral().getZExtValue(), Kind, T, Loc);
   } else if (T->isBooleanType()) {
     E = CXXBoolLiteralExpr::Create(Context, Arg.getAsIntegral().getBoolValue(),
                                    T, Loc);

@llvmbot
Copy link
Collaborator

llvmbot commented Jan 24, 2024

@llvm/pr-subscribers-lldb
@llvm/pr-subscribers-debuginfo
@llvm/pr-subscribers-clang-tools-extra

@llvm/pr-subscribers-clang-codegen

Author: Erich Keane (erichkeane)

Changes

Reverts llvm/llvm-project#78041

Based on this comment: #78041 (comment)

and the author's nonavailability to get to it quickly, we're reverting (and will have to revert from the release branch). Hopefully this can be reapplied for 19.


Patch is 100.32 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/79302.diff

46 Files Affected:

  • (modified) clang-tools-extra/clangd/DumpAST.cpp (-1)
  • (modified) clang-tools-extra/clangd/FindTarget.cpp (-1)
  • (modified) clang/include/clang/AST/ODRHash.h (-3)
  • (modified) clang/include/clang/AST/PropertiesBase.td (-14)
  • (modified) clang/include/clang/AST/RecursiveASTVisitor.h (-2)
  • (modified) clang/include/clang/AST/TemplateArgumentVisitor.h (-2)
  • (modified) clang/include/clang/AST/TemplateBase.h (+31-55)
  • (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+5)
  • (modified) clang/include/clang/Sema/Sema.h (+2-2)
  • (modified) clang/lib/AST/ASTContext.cpp (-5)
  • (modified) clang/lib/AST/ASTImporter.cpp (-13)
  • (modified) clang/lib/AST/ASTStructuralEquivalence.cpp (-3)
  • (modified) clang/lib/AST/Decl.cpp (-4)
  • (modified) clang/lib/AST/ItaniumMangle.cpp (+2-34)
  • (modified) clang/lib/AST/MicrosoftMangle.cpp (+16-62)
  • (modified) clang/lib/AST/ODRHash.cpp (-67)
  • (modified) clang/lib/AST/StmtProfile.cpp (-6)
  • (modified) clang/lib/AST/TemplateBase.cpp (+3-110)
  • (modified) clang/lib/AST/TypeLoc.cpp (-1)
  • (modified) clang/lib/CodeGen/CGDebugInfo.cpp (-10)
  • (modified) clang/lib/CodeGen/CGExpr.cpp (+3-9)
  • (modified) clang/lib/Index/USRGeneration.cpp (-10)
  • (modified) clang/lib/Sema/SemaLookup.cpp (-1)
  • (modified) clang/lib/Sema/SemaOverload.cpp (+1-9)
  • (modified) clang/lib/Sema/SemaTemplate.cpp (+88-130)
  • (modified) clang/lib/Sema/SemaTemplateDeduction.cpp (+18-46)
  • (modified) clang/lib/Sema/SemaTemplateInstantiate.cpp (+8-6)
  • (modified) clang/lib/Sema/SemaTemplateVariadic.cpp (-2)
  • (modified) clang/lib/Sema/TreeTransform.h (+2-10)
  • (modified) clang/lib/Serialization/ASTReader.cpp (-1)
  • (modified) clang/lib/Serialization/ASTWriter.cpp (-1)
  • (modified) clang/test/CXX/drs/dr18xx.cpp (+2-2)
  • (modified) clang/test/CXX/temp/temp.arg/temp.arg.nontype/p1.cpp (+1-3)
  • (modified) clang/test/CodeGenCXX/mangle-ms-templates.cpp (-48)
  • (modified) clang/test/CodeGenCXX/mangle-template.cpp (+1-39)
  • (removed) clang/test/CodeGenCXX/template-arguments.cpp (-113)
  • (removed) clang/test/Index/USR/structural-value-tpl-arg.cpp (-23)
  • (modified) clang/test/Modules/odr_hash.cpp (+3-190)
  • (modified) clang/test/SemaCXX/warn-bool-conversion.cpp (-2)
  • (modified) clang/test/SemaTemplate/temp_arg_nontype_cxx1z.cpp (+21-19)
  • (modified) clang/test/SemaTemplate/temp_arg_nontype_cxx20.cpp (+18-22)
  • (modified) clang/tools/libclang/CIndex.cpp (-5)
  • (modified) clang/tools/libclang/CXCursor.cpp (-3)
  • (modified) clang/www/cxx_status.html (+5-13)
  • (modified) lldb/include/lldb/lldb-enumerations.h (-1)
  • (modified) lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp (-3)
diff --git a/clang-tools-extra/clangd/DumpAST.cpp b/clang-tools-extra/clangd/DumpAST.cpp
index 9a525efb938e8d5..b0cec65c39fa31d 100644
--- a/clang-tools-extra/clangd/DumpAST.cpp
+++ b/clang-tools-extra/clangd/DumpAST.cpp
@@ -143,7 +143,6 @@ class DumpVisitor : public RecursiveASTVisitor<DumpVisitor> {
       TEMPLATE_ARGUMENT_KIND(Declaration);
       TEMPLATE_ARGUMENT_KIND(Template);
       TEMPLATE_ARGUMENT_KIND(TemplateExpansion);
-      TEMPLATE_ARGUMENT_KIND(StructuralValue);
 #undef TEMPLATE_ARGUMENT_KIND
     }
     llvm_unreachable("Unhandled ArgKind enum");
diff --git a/clang-tools-extra/clangd/FindTarget.cpp b/clang-tools-extra/clangd/FindTarget.cpp
index e702c6b3537a098..3d73e77b16aff4e 100644
--- a/clang-tools-extra/clangd/FindTarget.cpp
+++ b/clang-tools-extra/clangd/FindTarget.cpp
@@ -1039,7 +1039,6 @@ class ExplicitReferenceCollector
     case TemplateArgument::Pack:
     case TemplateArgument::Type:
     case TemplateArgument::Expression:
-    case TemplateArgument::StructuralValue:
       break; // Handled by VisitType and VisitExpression.
     };
     return RecursiveASTVisitor::TraverseTemplateArgumentLoc(A);
diff --git a/clang/include/clang/AST/ODRHash.h b/clang/include/clang/AST/ODRHash.h
index a1caa6d39a87c3c..cedf644520fc320 100644
--- a/clang/include/clang/AST/ODRHash.h
+++ b/clang/include/clang/AST/ODRHash.h
@@ -25,7 +25,6 @@
 
 namespace clang {
 
-class APValue;
 class Decl;
 class IdentifierInfo;
 class NestedNameSpecifier;
@@ -102,8 +101,6 @@ class ODRHash {
   // Save booleans until the end to lower the size of data to process.
   void AddBoolean(bool value);
 
-  void AddStructuralValue(const APValue &);
-
   static bool isSubDeclToBeProcessed(const Decl *D, const DeclContext *Parent);
 
 private:
diff --git a/clang/include/clang/AST/PropertiesBase.td b/clang/include/clang/AST/PropertiesBase.td
index 0270c086d06b6ad..d86c4eba6a22511 100644
--- a/clang/include/clang/AST/PropertiesBase.td
+++ b/clang/include/clang/AST/PropertiesBase.td
@@ -808,20 +808,6 @@ let Class = PropertyTypeCase<TemplateArgument, "Integral"> in {
     return TemplateArgument(ctx, value, type, isDefaulted);
   }]>;
 }
-let Class = PropertyTypeCase<TemplateArgument, "StructuralValue"> in {
-  def : Property<"value", APValue> {
-    let Read = [{ node.getAsStructuralValue() }];
-  }
-  def : Property<"type", QualType> {
-    let Read = [{ node.getStructuralValueType() }];
-  }
-  def : Property<"isDefaulted", Bool> {
-    let Read = [{ node.getIsDefaulted() }];
-  }
-  def : Creator<[{
-    return TemplateArgument(ctx, type, value, isDefaulted);
-  }]>;
-}
 let Class = PropertyTypeCase<TemplateArgument, "Template"> in {
   def : Property<"name", TemplateName> {
     let Read = [{ node.getAsTemplateOrTemplatePattern() }];
diff --git a/clang/include/clang/AST/RecursiveASTVisitor.h b/clang/include/clang/AST/RecursiveASTVisitor.h
index 2aee6a947141b6c..8f2714e142bbe3e 100644
--- a/clang/include/clang/AST/RecursiveASTVisitor.h
+++ b/clang/include/clang/AST/RecursiveASTVisitor.h
@@ -850,7 +850,6 @@ bool RecursiveASTVisitor<Derived>::TraverseTemplateArgument(
   case TemplateArgument::Declaration:
   case TemplateArgument::Integral:
   case TemplateArgument::NullPtr:
-  case TemplateArgument::StructuralValue:
     return true;
 
   case TemplateArgument::Type:
@@ -883,7 +882,6 @@ bool RecursiveASTVisitor<Derived>::TraverseTemplateArgumentLoc(
   case TemplateArgument::Declaration:
   case TemplateArgument::Integral:
   case TemplateArgument::NullPtr:
-  case TemplateArgument::StructuralValue:
     return true;
 
   case TemplateArgument::Type: {
diff --git a/clang/include/clang/AST/TemplateArgumentVisitor.h b/clang/include/clang/AST/TemplateArgumentVisitor.h
index cf0d32201580633..190aa97adf45516 100644
--- a/clang/include/clang/AST/TemplateArgumentVisitor.h
+++ b/clang/include/clang/AST/TemplateArgumentVisitor.h
@@ -37,7 +37,6 @@ class Base {
       DISPATCH(Declaration);
       DISPATCH(NullPtr);
       DISPATCH(Integral);
-      DISPATCH(StructuralValue);
       DISPATCH(Template);
       DISPATCH(TemplateExpansion);
       DISPATCH(Expression);
@@ -60,7 +59,6 @@ class Base {
   VISIT_METHOD(Declaration);
   VISIT_METHOD(NullPtr);
   VISIT_METHOD(Integral);
-  VISIT_METHOD(StructuralValue);
   VISIT_METHOD(Template);
   VISIT_METHOD(TemplateExpansion);
   VISIT_METHOD(Expression);
diff --git a/clang/include/clang/AST/TemplateBase.h b/clang/include/clang/AST/TemplateBase.h
index fea2c8ccfee675e..b7cd71f17c9442c 100644
--- a/clang/include/clang/AST/TemplateBase.h
+++ b/clang/include/clang/AST/TemplateBase.h
@@ -50,7 +50,6 @@ template <> struct PointerLikeTypeTraits<clang::Expr *> {
 
 namespace clang {
 
-class APValue;
 class ASTContext;
 class Expr;
 struct PrintingPolicy;
@@ -81,13 +80,6 @@ class TemplateArgument {
     /// that was provided for an integral non-type template parameter.
     Integral,
 
-    /// The template argument is a non-type template argument that can't be
-    /// represented by the special-case Declaration, NullPtr, or Integral
-    /// forms. These values are only ever produced by constant evaluation,
-    /// so cannot be dependent.
-    /// TODO: merge Declaration, NullPtr and Integral into this?
-    StructuralValue,
-
     /// The template argument is a template name that was provided for a
     /// template template parameter.
     Template,
@@ -138,14 +130,6 @@ class TemplateArgument {
     };
     void *Type;
   };
-  struct V {
-    LLVM_PREFERRED_TYPE(ArgKind)
-    unsigned Kind : 31;
-    LLVM_PREFERRED_TYPE(bool)
-    unsigned IsDefaulted : 1;
-    APValue *Value;
-    void *Type;
-  };
   struct A {
     LLVM_PREFERRED_TYPE(ArgKind)
     unsigned Kind : 31;
@@ -172,19 +156,11 @@ class TemplateArgument {
   union {
     struct DA DeclArg;
     struct I Integer;
-    struct V Value;
     struct A Args;
     struct TA TemplateArg;
     struct TV TypeOrValue;
   };
 
-  void initFromType(QualType T, bool IsNullPtr, bool IsDefaulted);
-  void initFromDeclaration(ValueDecl *D, QualType QT, bool IsDefaulted);
-  void initFromIntegral(const ASTContext &Ctx, const llvm::APSInt &Value,
-                        QualType Type, bool IsDefaulted);
-  void initFromStructural(const ASTContext &Ctx, QualType Type,
-                          const APValue &V, bool IsDefaulted);
-
 public:
   /// Construct an empty, invalid template argument.
   constexpr TemplateArgument() : TypeOrValue({Null, 0, /* IsDefaulted */ 0}) {}
@@ -192,22 +168,25 @@ class TemplateArgument {
   /// Construct a template type argument.
   TemplateArgument(QualType T, bool isNullPtr = false,
                    bool IsDefaulted = false) {
-    initFromType(T, isNullPtr, IsDefaulted);
+    TypeOrValue.Kind = isNullPtr ? NullPtr : Type;
+    TypeOrValue.IsDefaulted = IsDefaulted;
+    TypeOrValue.V = reinterpret_cast<uintptr_t>(T.getAsOpaquePtr());
   }
 
-  /// Construct a template argument that refers to a (non-dependent)
-  /// declaration.
+  /// Construct a template argument that refers to a
+  /// declaration, which is either an external declaration or a
+  /// template declaration.
   TemplateArgument(ValueDecl *D, QualType QT, bool IsDefaulted = false) {
-    initFromDeclaration(D, QT, IsDefaulted);
+    assert(D && "Expected decl");
+    DeclArg.Kind = Declaration;
+    DeclArg.IsDefaulted = IsDefaulted;
+    DeclArg.QT = QT.getAsOpaquePtr();
+    DeclArg.D = D;
   }
 
   /// Construct an integral constant template argument. The memory to
   /// store the value is allocated with Ctx.
-  TemplateArgument(const ASTContext &Ctx, const llvm::APSInt &Value,
-                   QualType Type, bool IsDefaulted = false);
-
-  /// Construct a template argument from an arbitrary constant value.
-  TemplateArgument(const ASTContext &Ctx, QualType Type, const APValue &Value,
+  TemplateArgument(ASTContext &Ctx, const llvm::APSInt &Value, QualType Type,
                    bool IsDefaulted = false);
 
   /// Construct an integral constant template argument with the same
@@ -318,7 +297,7 @@ class TemplateArgument {
   /// Retrieve the type for a type template argument.
   QualType getAsType() const {
     assert(getKind() == Type && "Unexpected kind");
-    return QualType::getFromOpaquePtr(reinterpret_cast<void *>(TypeOrValue.V));
+    return QualType::getFromOpaquePtr(reinterpret_cast<void*>(TypeOrValue.V));
   }
 
   /// Retrieve the declaration for a declaration non-type
@@ -336,7 +315,7 @@ class TemplateArgument {
   /// Retrieve the type for null non-type template argument.
   QualType getNullPtrType() const {
     assert(getKind() == NullPtr && "Unexpected kind");
-    return QualType::getFromOpaquePtr(reinterpret_cast<void *>(TypeOrValue.V));
+    return QualType::getFromOpaquePtr(reinterpret_cast<void*>(TypeOrValue.V));
   }
 
   /// Retrieve the template name for a template name argument.
@@ -392,14 +371,6 @@ class TemplateArgument {
   /// default template parameter.
   bool getIsDefaulted() const { return (bool)TypeOrValue.IsDefaulted; }
 
-  /// Get the value of a StructuralValue.
-  const APValue &getAsStructuralValue() const { return *Value.Value; }
-
-  /// Get the type of a StructuralValue.
-  QualType getStructuralValueType() const {
-    return QualType::getFromOpaquePtr(Value.Type);
-  }
-
   /// If this is a non-type template argument, get its type. Otherwise,
   /// returns a null QualType.
   QualType getNonTypeTemplateArgumentType() const;
@@ -545,7 +516,6 @@ class TemplateArgumentLoc {
     assert(Argument.getKind() == TemplateArgument::NullPtr ||
            Argument.getKind() == TemplateArgument::Integral ||
            Argument.getKind() == TemplateArgument::Declaration ||
-           Argument.getKind() == TemplateArgument::StructuralValue ||
            Argument.getKind() == TemplateArgument::Expression);
   }
 
@@ -571,9 +541,13 @@ class TemplateArgumentLoc {
   /// - Fetches the full source range of the argument.
   SourceRange getSourceRange() const LLVM_READONLY;
 
-  const TemplateArgument &getArgument() const { return Argument; }
+  const TemplateArgument &getArgument() const {
+    return Argument;
+  }
 
-  TemplateArgumentLocInfo getLocInfo() const { return LocInfo; }
+  TemplateArgumentLocInfo getLocInfo() const {
+    return LocInfo;
+  }
 
   TypeSourceInfo *getTypeSourceInfo() const {
     if (Argument.getKind() != TemplateArgument::Type)
@@ -601,11 +575,6 @@ class TemplateArgumentLoc {
     return LocInfo.getAsExpr();
   }
 
-  Expr *getSourceStructuralValueExpression() const {
-    assert(Argument.getKind() == TemplateArgument::StructuralValue);
-    return LocInfo.getAsExpr();
-  }
-
   NestedNameSpecifierLoc getTemplateQualifierLoc() const {
     if (Argument.getKind() != TemplateArgument::Template &&
         Argument.getKind() != TemplateArgument::TemplateExpansion)
@@ -637,7 +606,8 @@ class TemplateArgumentListInfo {
 public:
   TemplateArgumentListInfo() = default;
 
-  TemplateArgumentListInfo(SourceLocation LAngleLoc, SourceLocation RAngleLoc)
+  TemplateArgumentListInfo(SourceLocation LAngleLoc,
+                           SourceLocation RAngleLoc)
       : LAngleLoc(LAngleLoc), RAngleLoc(RAngleLoc) {}
 
   // This can leak if used in an AST node, use ASTTemplateArgumentListInfo
@@ -656,15 +626,21 @@ class TemplateArgumentListInfo {
     return Arguments.data();
   }
 
-  llvm::ArrayRef<TemplateArgumentLoc> arguments() const { return Arguments; }
+  llvm::ArrayRef<TemplateArgumentLoc> arguments() const {
+    return Arguments;
+  }
 
   const TemplateArgumentLoc &operator[](unsigned I) const {
     return Arguments[I];
   }
 
-  TemplateArgumentLoc &operator[](unsigned I) { return Arguments[I]; }
+  TemplateArgumentLoc &operator[](unsigned I) {
+    return Arguments[I];
+  }
 
-  void addArgument(const TemplateArgumentLoc &Loc) { Arguments.push_back(Loc); }
+  void addArgument(const TemplateArgumentLoc &Loc) {
+    Arguments.push_back(Loc);
+  }
 };
 
 /// Represents an explicit template argument list in C++, e.g.,
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index a1c32abb4dcd880..cce58b571a584b3 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -5161,6 +5161,8 @@ def err_non_type_template_arg_subobject : Error<
   "non-type template argument refers to subobject '%0'">;
 def err_non_type_template_arg_addr_label_diff : Error<
   "template argument / label address difference / what did you expect?">;
+def err_non_type_template_arg_unsupported : Error<
+  "non-type template argument of type %0 is not yet supported">;
 def err_template_arg_not_convertible : Error<
   "non-type template argument of type %0 cannot be converted to a value "
   "of type %1">;
@@ -5212,6 +5214,9 @@ def err_template_arg_not_object_or_func : Error<
   "non-type template argument does not refer to an object or function">;
 def err_template_arg_not_pointer_to_member_form : Error<
   "non-type template argument is not a pointer to member constant">;
+def err_template_arg_member_ptr_base_derived_not_supported : Error<
+  "non-type template argument of pointer-to-member type %1 that refers "
+  "to member %q0 of a different class is not supported yet">;
 def err_template_arg_invalid : Error<
   "non-type template argument '%0' is invalid">;
 def ext_template_arg_extra_parens : ExtWarn<
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 1f1cbd11ff73581..d4c33dd65bb96f1 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -8595,8 +8595,8 @@ class Sema final {
                                           QualType ParamType,
                                           SourceLocation Loc);
   ExprResult
-  BuildExpressionFromNonTypeTemplateArgument(const TemplateArgument &Arg,
-                                             SourceLocation Loc);
+  BuildExpressionFromIntegralTemplateArgument(const TemplateArgument &Arg,
+                                              SourceLocation Loc);
 
   /// Enumeration describing how template parameter lists are compared
   /// for equality.
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 5eb7aa3664569dd..0fc0831b221aab3 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -6754,11 +6754,6 @@ ASTContext::getCanonicalTemplateArgument(const TemplateArgument &Arg) const {
     case TemplateArgument::Integral:
       return TemplateArgument(Arg, getCanonicalType(Arg.getIntegralType()));
 
-    case TemplateArgument::StructuralValue:
-      return TemplateArgument(*this,
-                              getCanonicalType(Arg.getStructuralValueType()),
-                              Arg.getAsStructuralValue());
-
     case TemplateArgument::Type:
       return TemplateArgument(getCanonicalType(Arg.getAsType()),
                               /*isNullPtr*/ false, Arg.getIsDefaulted());
diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index 12734d62ed9fb76..b364796073022bd 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -823,17 +823,6 @@ ASTNodeImporter::import(const TemplateArgument &From) {
                             From.getIsDefaulted());
   }
 
-  case TemplateArgument::StructuralValue: {
-    ExpectedType ToTypeOrErr = import(From.getStructuralValueType());
-    if (!ToTypeOrErr)
-      return ToTypeOrErr.takeError();
-    Expected<APValue> ToValueOrErr = import(From.getAsStructuralValue());
-    if (!ToValueOrErr)
-      return ToValueOrErr.takeError();
-    return TemplateArgument(Importer.getToContext(), *ToTypeOrErr,
-                            *ToValueOrErr);
-  }
-
   case TemplateArgument::Template: {
     Expected<TemplateName> ToTemplateOrErr = import(From.getAsTemplate());
     if (!ToTemplateOrErr)
@@ -3583,8 +3572,6 @@ class IsTypeDeclaredInsideVisitor
     case TemplateArgument::NullPtr:
       // FIXME: The type is not allowed to be in the function?
       return CheckType(Arg.getNullPtrType());
-    case TemplateArgument::StructuralValue:
-      return CheckType(Arg.getStructuralValueType());
     case TemplateArgument::Pack:
       for (const auto &PackArg : Arg.getPackAsArray())
         if (checkTemplateArgument(PackArg))
diff --git a/clang/lib/AST/ASTStructuralEquivalence.cpp b/clang/lib/AST/ASTStructuralEquivalence.cpp
index be7a850a2982c73..5103fc86a800513 100644
--- a/clang/lib/AST/ASTStructuralEquivalence.cpp
+++ b/clang/lib/AST/ASTStructuralEquivalence.cpp
@@ -685,9 +685,6 @@ static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
     return IsStructurallyEquivalent(Context, Arg1.getAsExpr(),
                                     Arg2.getAsExpr());
 
-  case TemplateArgument::StructuralValue:
-    return Arg1.structurallyEquals(Arg2);
-
   case TemplateArgument::Pack:
     return IsStructurallyEquivalent(Context, Arg1.pack_elements(),
                                     Arg2.pack_elements());
diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index 26fdfa040796ed4..2c3a0afee8cefc2 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -343,10 +343,6 @@ LinkageComputer::getLVForTemplateArgumentList(ArrayRef<TemplateArgument> Args,
       LV.merge(getTypeLinkageAndVisibility(Arg.getNullPtrType()));
       continue;
 
-    case TemplateArgument::StructuralValue:
-      LV.merge(getLVForValue(Arg.getAsStructuralValue(), computation));
-      continue;
-
     case TemplateArgument::Template:
     case TemplateArgument::TemplateExpansion:
       if (TemplateDecl *Template =
diff --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp
index 40b1e086ddd0c61..f78265df0713f55 100644
--- a/clang/lib/AST/ItaniumMangle.cpp
+++ b/clang/lib/AST/ItaniumMangle.cpp
@@ -4833,23 +4833,9 @@ void CXXNameMangler::mangleExpression(const Expr *E, unsigned Arity,
     E = cast<CXXStdInitializerListExpr>(E)->getSubExpr();
     goto recurse;
 
-  case Expr::SubstNonTypeTemplateParmExprClass: {
-    // Mangle a substituted parameter the same way we mangle the template
-    // argument.
-    auto *SNTTPE = cast<SubstNonTypeTemplateParmExpr>(E);
-    if (auto *CE = dyn_cast<ConstantExpr>(SNTTPE->getReplacement())) {
-      // Pull out the constant value and mangle it as a template argument.
-      QualType ParamType = SNTTPE->getParameterType(Context.getASTContext());
-      assert(CE->hasAPValueResult() && "expected the NTTP to have an APValue");
-      mangleValueInTemplateArg(ParamType, CE->getAPValueResult(), false,
-                               /*NeedExactType=*/true);
-      break;
-    }
-    // The remaining cases all happen to be substituted with expressions that
-    // mangle the same as a corresponding template argument anyway.
+  case Expr::SubstNonTypeTemplateParmExprClass:
     E = cast<SubstNonTypeTemplateParmExpr>(E)->getReplacement();
     goto recurse;
-  }
 
   case Expr::UserDefinedLiteralClass:
     // We follow g++'s approach of mangling a UDL as a call to the literal
@@ -6078,11 +6064,6 @@ void CXXNameMangler::mangleTemplateArg(TemplateArgument A, bool NeedExactType) {
     mangleNullPointer(A.getNullPtrType());
     break;
   }
-  case TemplateArgument::StructuralValue:
-    mangleValueInTemplateArg(A.getStructuralValueType(),
-                             A.getAsStructuralValue(),
-                             /*TopLevel=*/true, NeedExactType);
-    break;
   case TemplateArgument::Pack: {
     //  <template-arg> ::= J <template-arg>* E
     Out << 'J';
@@ -6491,20 +6472,7 @@ void CXXNameMangler::mangleValueInTemplateArg(QualType T, const APValue &V,
       Out << "plcvPcad";
       Kind = Offset;
     } else {
-      // Clang 11 and before mangled an array subject to array-to-pointer decay
-      // as if it were the declaration itself.
-      bool IsArrayToPointerDecayMangledAsDecl = false;
-      if (TopLevel && Ctx.getLangOpts().getClangABICompat() <=
-                          LangOptions::ClangABI::Ver11) {
-        QualType BType = B.getType();
-        IsArrayToPointerDecayMangledAsDecl =
-            BType->isArrayType() && V.getLValuePath().size() == 1 &&
-            V.getLValuePath()[0].getAsArrayIndex() == 0 &&
-            Ctx.hasSimilarType(T, Ctx.getDecayedType(BType));
-      }
-
-      if ((!V.getLValuePath().empty() || V.isLValueOnePastTheEnd()) &&
-          !IsArrayToPointerDecayMangledAsDecl) {
+      if (!V.getLValuePath().empty() || V.i...
[truncated]

@cor3ntin
Copy link
Contributor

This is rather unfortunate, I hope we can figure that out quickly

@erichkeane
Copy link
Collaborator Author

Fixed in : e3ee376

@erichkeane erichkeane closed this Jan 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:codegen clang:frontend Language frontend issues, e.g. anything involving "Sema" clang:modules C++20 modules and Clang Header Modules clang Clang issues not falling into any other category clang-tools-extra clangd debuginfo lldb
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants