[Clang] follow-up D128745, use ClangABICompat15 instead of ClangABICompat14

Since the patch missed release 15.x and will be included in release 16.x. Also, simplify related tests.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D132414
This commit is contained in:
Yuanfang Chen 2022-08-23 10:25:02 -07:00
parent 1959a55591
commit 088ba8efeb
6 changed files with 45 additions and 64 deletions

View File

@ -144,7 +144,7 @@ C2x Feature Support
C++ Language Changes in Clang
-----------------------------
- Implemented DR692, DR1395 and DR1432. Use the ``-fclang-abi-compat=14`` option
- Implemented DR692, DR1395 and DR1432. Use the ``-fclang-abi-compat=15`` option
to get the old partial ordering behavior regarding packs.
C++20 Feature Support

View File

@ -223,6 +223,11 @@ public:
/// implicit declaration.
Ver14,
/// Attempt to be ABI-compatible with code generated by Clang 15.0.x.
/// This causes clang to:
/// - Reverse the implementation for DR692, DR1395 and DR1432.
Ver15,
/// Conform to the underlying platform's C and C++ ABIs as closely
/// as we can.
Latest

View File

@ -3522,6 +3522,8 @@ void CompilerInvocation::GenerateLangArgs(const LangOptions &Opts,
GenerateArg(Args, OPT_fclang_abi_compat_EQ, "12.0", SA);
else if (Opts.getClangABICompat() == LangOptions::ClangABI::Ver14)
GenerateArg(Args, OPT_fclang_abi_compat_EQ, "14.0", SA);
else if (Opts.getClangABICompat() == LangOptions::ClangABI::Ver15)
GenerateArg(Args, OPT_fclang_abi_compat_EQ, "15.0", SA);
if (Opts.getSignReturnAddressScope() ==
LangOptions::SignReturnAddressScopeKind::All)
@ -4014,6 +4016,8 @@ bool CompilerInvocation::ParseLangArgs(LangOptions &Opts, ArgList &Args,
Opts.setClangABICompat(LangOptions::ClangABI::Ver12);
else if (Major <= 14)
Opts.setClangABICompat(LangOptions::ClangABI::Ver14);
else if (Major <= 15)
Opts.setClangABICompat(LangOptions::ClangABI::Ver15);
} else if (Ver != "latest") {
Diags.Report(diag::err_drv_invalid_value)
<< A->getAsString(Args) << A->getValue();

View File

@ -1107,9 +1107,9 @@ DeduceTemplateArguments(Sema &S,
// During partial ordering, if Ai was originally a function parameter pack:
// - if P does not contain a function parameter type corresponding to Ai then
// Ai is ignored;
bool ClangABICompat14 = S.Context.getLangOpts().getClangABICompat() <=
LangOptions::ClangABI::Ver14;
if (!ClangABICompat14 && PartialOrdering && ArgIdx + 1 == NumArgs &&
bool ClangABICompat15 = S.Context.getLangOpts().getClangABICompat() <=
LangOptions::ClangABI::Ver15;
if (!ClangABICompat15 && PartialOrdering && ArgIdx + 1 == NumArgs &&
isa<PackExpansionType>(Args[ArgIdx]))
return Sema::TDK_Success;
@ -2445,8 +2445,8 @@ static bool isSameTemplateArg(ASTContext &Context,
if (X.getKind() != Y.getKind())
return false;
bool ClangABICompat14 =
Context.getLangOpts().getClangABICompat() <= LangOptions::ClangABI::Ver14;
bool ClangABICompat15 =
Context.getLangOpts().getClangABICompat() <= LangOptions::ClangABI::Ver15;
switch (X.getKind()) {
case TemplateArgument::Null:
@ -2480,7 +2480,7 @@ static bool isSameTemplateArg(ASTContext &Context,
}
case TemplateArgument::Pack:
if (ClangABICompat14) {
if (ClangABICompat15) {
if (X.pack_size() != Y.pack_size())
return false;
@ -5464,9 +5464,9 @@ getMoreSpecialized(Sema &S, QualType T1, QualType T2, TemplateLikeDecl *P1,
return nullptr;
if (Better1 && Better2) {
bool ClangABICompat14 = S.Context.getLangOpts().getClangABICompat() <=
LangOptions::ClangABI::Ver14;
if (!ClangABICompat14) {
bool ClangABICompat15 = S.Context.getLangOpts().getClangABICompat() <=
LangOptions::ClangABI::Ver15;
if (!ClangABICompat15) {
// Consider this a fix for CWG1432. Similar to the fix for CWG1395.
auto *TST1 = T1->castAs<TemplateSpecializationType>();
auto *TST2 = T2->castAs<TemplateSpecializationType>();

View File

@ -1,4 +1,5 @@
// RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
// RUN: %clang_cc1 -fclang-abi-compat=15.0 -std=c++11 -fsyntax-only -verify %s
template<int ...Values> struct X1;

View File

@ -1,62 +1,33 @@
// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fclang-abi-compat=14 -DCLANG_ABI_COMPAT=14 %s -emit-llvm -disable-llvm-passes -o - | FileCheck %s --check-prefix=CHECK-14
// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -emit-llvm -disable-llvm-passes -o - | FileCheck %s
// RUN: %clang_cc1 -triple x86_64-unknown-unknown -fclang-abi-compat=15 -DCLANG_ABI_COMPAT=15 %s -emit-llvm -disable-llvm-passes -o - | FileCheck %s
// RUN: %clang_cc1 -triple x86_64-unknown-unknown %s -emit-llvm -disable-llvm-passes -o - | FileCheck %s --check-prefixes=CHECK,AFTER-15
#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: %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;
}
// CHECK: %struct.S = type { i8 }
// CHECK: @_Z2ggiRi
// CHECK: @_Z1gIiJEERiPT_DpT0_
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 gg(int i, int &r) {
r = g(&i);
S<int> a;
}
#else
// CHECK: @_Z1hIJiEEvDpPT_
template<class ...T> void h(T*...) {}
template<class T> void h(const T&) {}
template void h(int*);
// CHECK: %"struct.temp_deduct_type_example1::A" = type { i8 }
#if !defined(CLANG_ABI_COMPAT)
// CHECK: $_ZN25temp_deduct_type_example31fIiJEEEvPT_DpT0_ = comdat any
// AFTER-15: @_Z1fIiJEEvPT_DpT0_
template<class T, class... U> void f(T*, U...){}
template<class T> void f(T){}
template void f(int*);
// CHECK: define dso_local void @_ZN25temp_deduct_type_example11fEv()
// CHECK-NEXT: entry:
// CHECK-NEXT: %a = alloca %"struct.temp_deduct_type_example1::A", align 1
// CHECK-NEXT: ret void
// CHECK: define weak_odr void @_ZN25temp_deduct_type_example31fIiJEEEvPT_DpT0_(ptr noundef %0)
// CHECK-NEXT: entry:
// CHECK-NEXT: %.addr = alloca ptr, align 8
// CHECK-NEXT: store ptr %0, ptr %.addr, align 8
// CHECK-NEXT: ret void
namespace temp_deduct_type_example1 {
template<class T, class... U> struct A;
template<class T1, class T2, class... U> struct A<T1,T2*,U...> {};
template<class T1, class T2> struct A<T1,T2>;
template struct A<int, int*>;
void f() { A<int, int*> a; }
}
namespace temp_deduct_type_example3 {
template<class T, class... U> void f(T*, U...){}
template<class T> void f(T){}
template void f(int*);
}
template<class T, class... U> struct A;
template<class T1, class T2, class... U> struct A<T1,T2*,U...> {};
template<class T1, class T2> struct A<T1,T2>;
template struct A<int, int*>;
#endif