[clang] da6187f - [Clang] followup D128745, add a missing ClangABICompat check
Yuanfang Chen via cfe-commits
cfe-commits at lists.llvm.org
Tue Aug 16 18:58:33 PDT 2022
Author: Yuanfang Chen
Date: 2022-08-16T18:40:00-07:00
New Revision: da6187f566b7881cb8350621aea9bd582de569b9
URL: https://github.com/llvm/llvm-project/commit/da6187f566b7881cb8350621aea9bd582de569b9
DIFF: https://github.com/llvm/llvm-project/commit/da6187f566b7881cb8350621aea9bd582de569b9.diff
LOG: [Clang] followup D128745, add a missing ClangABICompat check
Added:
Modified:
clang/lib/Sema/SemaTemplateDeduction.cpp
clang/test/CodeGen/partial-order-variadic.cpp
Removed:
################################################################################
diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp b/clang/lib/Sema/SemaTemplateDeduction.cpp
index 6836f7c090be2..ac0b3fe8e04a2 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -2445,6 +2445,9 @@ static bool isSameTemplateArg(ASTContext &Context,
if (X.getKind() != Y.getKind())
return false;
+ bool ClangABICompat14 =
+ Context.getLangOpts().getClangABICompat() <= LangOptions::ClangABI::Ver14;
+
switch (X.getKind()) {
case TemplateArgument::Null:
llvm_unreachable("Comparing NULL template argument");
@@ -2477,30 +2480,42 @@ static bool isSameTemplateArg(ASTContext &Context,
}
case TemplateArgument::Pack:
- unsigned PackIterationSize = X.pack_size();
- if (X.pack_size() != Y.pack_size()) {
- if (!PartialOrdering)
+ if (ClangABICompat14) {
+ if (X.pack_size() != Y.pack_size())
return false;
- // C++0x [temp.deduct.type]p9:
- // During partial ordering, if Ai was originally a pack expansion:
- // - if P does not contain a template argument corresponding to Ai then
- // Ai is ignored;
- bool XHasMoreArg = X.pack_size() > Y.pack_size();
- if (!(XHasMoreArg && X.pack_elements().back().isPackExpansion()) &&
- !(!XHasMoreArg && Y.pack_elements().back().isPackExpansion()))
- return false;
+ for (TemplateArgument::pack_iterator XP = X.pack_begin(),
+ XPEnd = X.pack_end(),
+ YP = Y.pack_begin();
+ XP != XPEnd; ++XP, ++YP)
+ if (!isSameTemplateArg(Context, *XP, *YP, PackExpansionMatchesPack))
+ return false;
+ } else {
+ unsigned PackIterationSize = X.pack_size();
+ if (X.pack_size() != Y.pack_size()) {
+ if (!PartialOrdering)
+ return false;
+
+ // C++0x [temp.deduct.type]p9:
+ // During partial ordering, if Ai was originally a pack expansion:
+ // - if P does not contain a template argument corresponding to Ai
+ // then Ai is ignored;
+ bool XHasMoreArg = X.pack_size() > Y.pack_size();
+ if (!(XHasMoreArg && X.pack_elements().back().isPackExpansion()) &&
+ !(!XHasMoreArg && Y.pack_elements().back().isPackExpansion()))
+ return false;
+
+ if (XHasMoreArg)
+ PackIterationSize = Y.pack_size();
+ }
- if (XHasMoreArg)
- PackIterationSize = Y.pack_size();
+ ArrayRef<TemplateArgument> XP = X.pack_elements();
+ ArrayRef<TemplateArgument> YP = Y.pack_elements();
+ for (unsigned i = 0; i < PackIterationSize; ++i)
+ if (!isSameTemplateArg(Context, XP[i], YP[i], PartialOrdering,
+ PackExpansionMatchesPack))
+ return false;
}
-
- ArrayRef<TemplateArgument> XP = X.pack_elements();
- ArrayRef<TemplateArgument> YP = Y.pack_elements();
- for (unsigned i = 0; i < PackIterationSize; ++i)
- if (!isSameTemplateArg(Context, XP[i], YP[i], PartialOrdering,
- PackExpansionMatchesPack))
- return false;
return true;
}
diff --git a/clang/test/CodeGen/partial-order-variadic.cpp b/clang/test/CodeGen/partial-order-variadic.cpp
index 496a7da42208a..9a366c83e222c 100644
--- a/clang/test/CodeGen/partial-order-variadic.cpp
+++ b/clang/test/CodeGen/partial-order-variadic.cpp
@@ -3,20 +3,28 @@
#if defined(CLANG_ABI_COMPAT) && CLANG_ABI_COMPAT <= 14
+// CHECK-14: %"struct.temp_func_order_example3::S" = type { i8 }
+
// CHECK-14: define dso_local void @_ZN24temp_func_order_example31hEi(i32 noundef %i)
-// CHECK-14-NEXT: entry:
-// CHECK-14-NEXT: %i.addr = alloca i32, align 4
-// CHECK-14-NEXT: %r = alloca ptr, align 8
-// CHECK-14-NEXT: store i32 %i, ptr %i.addr, align 4
-// CHECK-14-NEXT: %call = call noundef nonnull align 4 dereferenceable(4) ptr @_ZN24temp_func_order_example31gIiJEEERiPT_DpT0_(ptr noundef %i.addr)
-// CHECK-14-NEXT: store ptr %call, ptr %r, align 8
-// CHECK-14-NEXT: ret void
+// CHECK-14-NEXT: entry:
+// CHECK-14-NEXT: %i.addr = alloca i32, align 4
+// CHECK-14-NEXT: %r = alloca ptr, align 8
+// CHECK-14-NEXT: %a = alloca %"struct.temp_func_order_example3::S", align 1
+// CHECK-14-NEXT: store i32 %i, ptr %i.addr, align 4
+// CHECK-14-NEXT: %call = call noundef nonnull align 4 dereferenceable(4) ptr @_ZN24temp_func_order_example31gIiJEEERiPT_DpT0_(ptr noundef %i.addr)
+// CHECK-14-NEXT: store ptr %call, ptr %r, align 8
+// CHECK-14-NEXT: ret void
namespace temp_func_order_example3 {
template <typename T, typename... U> int &g(T *, U...);
template <typename T> void g(T);
+
+ template <typename T, typename... Ts> struct S;
+ template <typename T> struct S<T> {};
+
void h(int i) {
int &r = g(&i);
+ S<int> a;
}
}
More information about the cfe-commits
mailing list