[clang] [Clang] Do not try to classify dependant call expression (PR #68078)

via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 3 01:30:08 PDT 2023


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-clang

<details>
<summary>Changes</summary>

when the callee is an object.

When implementing deducing this, we changed
`DeduceTemplateArgumentsFromCallArgument` to take an argument classification because we need to deduce the type of argument for which we might not have an expression yet.

However classifying a dependent call expression whose type is just some sort of record or elaborated type is not supported.

We avoid that by adding a `DeduceTemplateArgumentsFromCallArgument` that takes a `IsLvalue` boolean so that we don't have to call `Classify`.

The alternative might be to change `getCallReturnType` to support callees with type is a record type.

Fixes #<!-- -->68024

---
Full diff: https://github.com/llvm/llvm-project/pull/68078.diff


1 Files Affected:

- (modified) clang/lib/Sema/SemaTemplateDeduction.cpp (+39-19) 


``````````diff
diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp b/clang/lib/Sema/SemaTemplateDeduction.cpp
index 69b857d3510dc63..53975068751e128 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -3877,9 +3877,8 @@ ResolveOverloadForDeduction(Sema &S, TemplateParameterList *TemplateParams,
 /// overloaded function set that could not be resolved.
 static bool AdjustFunctionParmAndArgTypesForDeduction(
     Sema &S, TemplateParameterList *TemplateParams, unsigned FirstInnerIndex,
-    QualType &ParamType, QualType &ArgType,
-    Expr::Classification ArgClassification, Expr *Arg, unsigned &TDF,
-    TemplateSpecCandidateSet *FailedTSC = nullptr) {
+    QualType &ParamType, QualType &ArgType, bool IsLValue, Expr *Arg,
+    unsigned &TDF, TemplateSpecCandidateSet *FailedTSC = nullptr) {
   // C++0x [temp.deduct.call]p3:
   //   If P is a cv-qualified type, the top level cv-qualifiers of P's type
   //   are ignored for type deduction.
@@ -3914,7 +3913,7 @@ static bool AdjustFunctionParmAndArgTypesForDeduction(
     //   If P is a forwarding reference and the argument is an lvalue, the type
     //   "lvalue reference to A" is used in place of A for type deduction.
     if (isForwardingReference(QualType(ParamRefType, 0), FirstInnerIndex) &&
-        ArgClassification.isLValue()) {
+        IsLValue) {
       if (S.getLangOpts().OpenCL && !ArgType.hasAddressSpace())
         ArgType = S.Context.getAddrSpaceQualType(
             ArgType, S.Context.getDefaultOpenCLPointeeAddrSpace());
@@ -3973,6 +3972,15 @@ static bool
 hasDeducibleTemplateParameters(Sema &S, FunctionTemplateDecl *FunctionTemplate,
                                QualType T);
 
+static Sema::TemplateDeductionResult DeduceTemplateArgumentsFromCallArgument(
+    Sema &S, TemplateParameterList *TemplateParams, unsigned FirstInnerIndex,
+    QualType ParamType, QualType ArgType, bool IsLValue, Expr *Arg,
+    TemplateDeductionInfo &Info,
+    SmallVectorImpl<DeducedTemplateArgument> &Deduced,
+    SmallVectorImpl<Sema::OriginalCallArg> &OriginalCallArgs,
+    bool DecomposedParam, unsigned ArgIdx, unsigned TDF,
+    TemplateSpecCandidateSet *FailedTSC = nullptr);
+
 static Sema::TemplateDeductionResult DeduceTemplateArgumentsFromCallArgument(
     Sema &S, TemplateParameterList *TemplateParams, unsigned FirstInnerIndex,
     QualType ParamType, QualType ArgType,
@@ -4022,9 +4030,8 @@ static Sema::TemplateDeductionResult DeduceFromInitializerList(
   if (ElTy->isDependentType()) {
     for (Expr *E : ILE->inits()) {
       if (auto Result = DeduceTemplateArgumentsFromCallArgument(
-              S, TemplateParams, 0, ElTy, E->getType(),
-              E->Classify(S.getASTContext()), E, Info, Deduced,
-              OriginalCallArgs, true, ArgIdx, TDF))
+              S, TemplateParams, 0, ElTy, E->getType(), E->isLValue(), E, Info,
+              Deduced, OriginalCallArgs, true, ArgIdx, TDF))
         return Result;
     }
   }
@@ -4055,8 +4062,7 @@ static Sema::TemplateDeductionResult DeduceFromInitializerList(
 ///        single parameter / argument pair.
 static Sema::TemplateDeductionResult DeduceTemplateArgumentsFromCallArgument(
     Sema &S, TemplateParameterList *TemplateParams, unsigned FirstInnerIndex,
-    QualType ParamType, QualType ArgType,
-    Expr::Classification ArgClassification, Expr *Arg,
+    QualType ParamType, QualType ArgType, bool IsLValue, Expr *Arg,
     TemplateDeductionInfo &Info,
     SmallVectorImpl<DeducedTemplateArgument> &Deduced,
     SmallVectorImpl<Sema::OriginalCallArg> &OriginalCallArgs,
@@ -4068,8 +4074,8 @@ static Sema::TemplateDeductionResult DeduceTemplateArgumentsFromCallArgument(
   //   If P is a reference type [...]
   //   If P is a cv-qualified type [...]
   if (AdjustFunctionParmAndArgTypesForDeduction(
-          S, TemplateParams, FirstInnerIndex, ParamType, ArgType,
-          ArgClassification, Arg, TDF, FailedTSC))
+          S, TemplateParams, FirstInnerIndex, ParamType, ArgType, IsLValue, Arg,
+          TDF, FailedTSC))
     return Sema::TDK_Success;
 
   //   If [...] the argument is a non-empty initializer list [...]
@@ -4089,6 +4095,22 @@ static Sema::TemplateDeductionResult DeduceTemplateArgumentsFromCallArgument(
                                             ArgType, Info, Deduced, TDF);
 }
 
+static Sema::TemplateDeductionResult DeduceTemplateArgumentsFromCallArgument(
+    Sema &S, TemplateParameterList *TemplateParams, unsigned FirstInnerIndex,
+    QualType ParamType, QualType ArgType,
+    Expr::Classification ArgClassification, Expr *Arg,
+    TemplateDeductionInfo &Info,
+    SmallVectorImpl<DeducedTemplateArgument> &Deduced,
+    SmallVectorImpl<Sema::OriginalCallArg> &OriginalCallArgs,
+    bool DecomposedParam, unsigned ArgIdx, unsigned TDF,
+    TemplateSpecCandidateSet *FailedTSC) {
+
+  return DeduceTemplateArgumentsFromCallArgument(
+      S, TemplateParams, FirstInnerIndex, ParamType, ArgType,
+      ArgClassification.isLValue(), Arg, Info, Deduced, OriginalCallArgs,
+      DecomposedParam, ArgIdx, TDF, FailedTSC);
+}
+
 /// Perform template argument deduction from a function call
 /// (C++ [temp.deduct.call]).
 ///
@@ -4200,9 +4222,8 @@ Sema::TemplateDeductionResult Sema::DeduceTemplateArguments(
     //   ... with the type of the corresponding argument
     return DeduceTemplateArgumentsFromCallArgument(
         *this, TemplateParams, FirstInnerIndex, ParamType,
-        Args[ArgIdx]->getType(), Args[ArgIdx]->Classify(getASTContext()),
-        Args[ArgIdx], Info, Deduced, OriginalCallArgs, /*Decomposed*/ false,
-        ArgIdx, /*TDF*/ 0);
+        Args[ArgIdx]->getType(), Args[ArgIdx]->isLValue(), Args[ArgIdx], Info,
+        Deduced, OriginalCallArgs, /*Decomposed*/ false, ArgIdx, /*TDF*/ 0);
   };
 
   // Deduce template arguments from the function parameters.
@@ -4904,8 +4925,8 @@ Sema::DeduceAutoType(TypeLoc Type, Expr *Init, QualType &Result,
           return TDK_Invalid;
         if (auto TDK = DeduceTemplateArgumentsFromCallArgument(
                 *this, TemplateParamsSt.get(), 0, TemplArg, Init->getType(),
-                Init->Classify(getASTContext()), Init, Info, Deduced,
-                OriginalCallArgs, /*Decomposed=*/true,
+                Init->isLValue(), Init, Info, Deduced, OriginalCallArgs,
+                /*Decomposed=*/true,
                 /*ArgIdx=*/0, /*TDF=*/0)) {
           if (TDK == TDK_Inconsistent) {
             Diag(Info.getLocation(), diag::err_auto_inconsistent_deduction)
@@ -4931,9 +4952,8 @@ Sema::DeduceAutoType(TypeLoc Type, Expr *Init, QualType &Result,
              "substituting template parameter for 'auto' failed");
       if (auto TDK = DeduceTemplateArgumentsFromCallArgument(
               *this, TemplateParamsSt.get(), 0, FuncParam, Init->getType(),
-              Init->Classify(getASTContext()), Init, Info, Deduced,
-              OriginalCallArgs, /*Decomposed=*/false, /*ArgIdx=*/0, /*TDF=*/0,
-              FailedTSC))
+              Init->isLValue(), Init, Info, Deduced, OriginalCallArgs,
+              /*Decomposed=*/false, /*ArgIdx=*/0, /*TDF=*/0, FailedTSC))
         return DeductionFailed(TDK);
     }
 

``````````

</details>


https://github.com/llvm/llvm-project/pull/68078


More information about the cfe-commits mailing list