From 088ba8efeb4921deb49534714ddefb14a91afe46 Mon Sep 17 00:00:00 2001 From: Yuanfang Chen Date: Tue, 23 Aug 2022 10:25:02 -0700 Subject: [PATCH] [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 --- clang/docs/ReleaseNotes.rst | 2 +- clang/include/clang/Basic/LangOptions.h | 5 ++ clang/lib/Frontend/CompilerInvocation.cpp | 4 + clang/lib/Sema/SemaTemplateDeduction.cpp | 18 ++--- .../temp/temp.decls/temp.class.spec/p8-0x.cpp | 1 + clang/test/CodeGen/partial-order-variadic.cpp | 79 ++++++------------- 6 files changed, 45 insertions(+), 64 deletions(-) diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 0ba35edd5dcb..64a2ce2bb2b8 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -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 diff --git a/clang/include/clang/Basic/LangOptions.h b/clang/include/clang/Basic/LangOptions.h index 3a1c13dd7256..dd2a7920a5f1 100644 --- a/clang/include/clang/Basic/LangOptions.h +++ b/clang/include/clang/Basic/LangOptions.h @@ -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 diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp index 6b5baa75fd27..574514bdd0b0 100644 --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -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(); diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp b/clang/lib/Sema/SemaTemplateDeduction.cpp index 99119bcb2e4e..84c4a191ec32 100644 --- a/clang/lib/Sema/SemaTemplateDeduction.cpp +++ b/clang/lib/Sema/SemaTemplateDeduction.cpp @@ -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(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(); auto *TST2 = T2->castAs(); diff --git a/clang/test/CXX/temp/temp.decls/temp.class.spec/p8-0x.cpp b/clang/test/CXX/temp/temp.decls/temp.class.spec/p8-0x.cpp index 52fbd9457422..e3726bd32fb2 100644 --- a/clang/test/CXX/temp/temp.decls/temp.class.spec/p8-0x.cpp +++ b/clang/test/CXX/temp/temp.decls/temp.class.spec/p8-0x.cpp @@ -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 struct X1; diff --git a/clang/test/CodeGen/partial-order-variadic.cpp b/clang/test/CodeGen/partial-order-variadic.cpp index 9a366c83e222..a10cd6812f98 100644 --- a/clang/test/CodeGen/partial-order-variadic.cpp +++ b/clang/test/CodeGen/partial-order-variadic.cpp @@ -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 int &g(T *, U...); - template void g(T); - - template struct S; - template struct S {}; - - void h(int i) { - int &r = g(&i); - S a; - } +// CHECK: %struct.S = type { i8 } +// CHECK: @_Z2ggiRi +// CHECK: @_Z1gIiJEERiPT_DpT0_ +template int &g(T *, U...); +template void g(T); +template struct S; +template struct S {}; +void gg(int i, int &r) { + r = g(&i); + S a; } -#else +// CHECK: @_Z1hIJiEEvDpPT_ +template void h(T*...) {} +template 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 void f(T*, U...){} +template 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 struct A; - template struct A {}; - template struct A; - template struct A; - void f() { A a; } -} - -namespace temp_deduct_type_example3 { - template void f(T*, U...){} - template void f(T){} - template void f(int*); -} +template struct A; +template struct A {}; +template struct A; +template struct A; #endif