Author: Fangrui Song Date: 2021-09-23T16:15:40-07:00 New Revision: 7647a8413be55568a8a80fae379a872b7359f5b5
URL: https://github.com/llvm/llvm-project/commit/7647a8413be55568a8a80fae379a872b7359f5b5 DIFF: https://github.com/llvm/llvm-project/commit/7647a8413be55568a8a80fae379a872b7359f5b5.diff LOG: Fix -fno-unwind-tables -fasynchronous-unwind-tables to emit unwind tables This matches GCC. Change the CC1 option to encode the unwind table level (1: needed by exceptions, 2: asynchronous) so that we can support two modes in the future. Added: Modified: clang/include/clang/Basic/CodeGenOptions.def clang/include/clang/Driver/Options.td clang/lib/Driver/ToolChains/Clang.cpp clang/test/CodeGen/asan-globals.cpp clang/test/CodeGenCXX/exceptions-seh-filter-uwtable.cpp clang/test/CodeGenCXX/linetable-eh.cpp clang/test/CodeGenCXX/thunks-ehspec.cpp clang/test/CodeGenCXX/thunks.cpp clang/test/Driver/aarch64-features.c clang/test/Driver/clang-translation.c clang/test/Driver/freebsd.c clang/test/Driver/fuchsia.c clang/test/Driver/ppc-features.cpp clang/test/Driver/sanitize_unwind_tables.c clang/test/Driver/win-macho-unwind.c clang/test/Driver/windows-exceptions.cpp clang/test/Preprocessor/unwind-tables.c Removed: ################################################################################ diff --git a/clang/include/clang/Basic/CodeGenOptions.def b/clang/include/clang/Basic/CodeGenOptions.def index 5d1d4f9dc58ee..df4f8db6e16cf 100644 --- a/clang/include/clang/Basic/CodeGenOptions.def +++ b/clang/include/clang/Basic/CodeGenOptions.def @@ -275,7 +275,7 @@ VALUE_CODEGENOPT(TimeTraceGranularity, 32, 500) ///< Minimum time granularity (i CODEGENOPT(UnrollLoops , 1, 0) ///< Control whether loops are unrolled. CODEGENOPT(RerollLoops , 1, 0) ///< Control whether loops are rerolled. CODEGENOPT(NoUseJumpTables , 1, 0) ///< Set when -fno-jump-tables is enabled. -CODEGENOPT(UnwindTables , 1, 0) ///< Emit unwind tables. +VALUE_CODEGENOPT(UnwindTables, 2, 0) ///< Unwind tables (1) or asynchronous unwind tables (2) CODEGENOPT(VectorizeLoop , 1, 0) ///< Run loop vectorizer. CODEGENOPT(VectorizeSLP , 1, 0) ///< Run SLP vectorizer. CODEGENOPT(ProfileSampleAccurate, 1, 0) ///< Sample profile is accurate. diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index b6d0ec76f79bb..28d96b1d08457 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -5024,9 +5024,9 @@ def mregparm : Separate<["-"], "mregparm">, def msmall_data_limit : Separate<["-"], "msmall-data-limit">, HelpText<"Put global and static data smaller than the limit into a special section">, MarshallingInfoInt<CodeGenOpts<"SmallDataLimit">>; -def munwind_tables : Flag<["-"], "munwind-tables">, +def funwind_tables_EQ : Joined<["-"], "funwind-tables=">, HelpText<"Generate unwinding tables for all functions">, - MarshallingInfoFlag<CodeGenOpts<"UnwindTables">>; + MarshallingInfoInt<CodeGenOpts<"UnwindTables">>; def mconstructor_aliases : Flag<["-"], "mconstructor-aliases">, HelpText<"Emit complete constructors and destructors as aliases when possible">, MarshallingInfoFlag<CodeGenOpts<"CXXCtorDtorAliases">>; diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 6c7b8bbcaad79..7642692ced99b 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -5127,16 +5127,18 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, // This is a coarse approximation of what llvm-gcc actually does, both // -fasynchronous-unwind-tables and -fnon-call-exceptions interact in more // complicated ways. - bool UnwindTables = + bool AsyncUnwindTables = Args.hasFlag(options::OPT_fasynchronous_unwind_tables, options::OPT_fno_asynchronous_unwind_tables, (TC.IsUnwindTablesDefault(Args) || TC.getSanitizerArgs().needsUnwindTables()) && !Freestanding); - UnwindTables = Args.hasFlag(options::OPT_funwind_tables, - options::OPT_fno_unwind_tables, UnwindTables); - if (UnwindTables) - CmdArgs.push_back("-munwind-tables"); + bool UnwindTables = Args.hasFlag(options::OPT_funwind_tables, + options::OPT_fno_unwind_tables, false); + if (AsyncUnwindTables) + CmdArgs.push_back("-funwind-tables=2"); + else if (UnwindTables) + CmdArgs.push_back("-funwind-tables=1"); // Prepare `-aux-target-cpu` and `-aux-target-feature` unless // `--gpu-use-aux-triple-only` is specified. @@ -6866,7 +6868,8 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA, CmdArgs.push_back("-faddrsig"); if ((Triple.isOSBinFormatELF() || Triple.isOSBinFormatMachO()) && - (EH || UnwindTables || DebugInfoKind != codegenoptions::NoDebugInfo)) + (EH || AsyncUnwindTables || UnwindTables || + DebugInfoKind != codegenoptions::NoDebugInfo)) CmdArgs.push_back("-D__GCC_HAVE_DWARF2_CFI_ASM=1"); if (Arg *A = Args.getLastArg(options::OPT_fsymbol_partition_EQ)) { diff --git a/clang/test/CodeGen/asan-globals.cpp b/clang/test/CodeGen/asan-globals.cpp index dfa2c3265a918..1db7b9844020b 100644 --- a/clang/test/CodeGen/asan-globals.cpp +++ b/clang/test/CodeGen/asan-globals.cpp @@ -45,7 +45,7 @@ void func() { /// If -fasynchronous-unwind-tables, set the module flag "uwtable". ctor/dtor /// will thus get the uwtable attribute. -// RUN: %clang_cc1 -emit-llvm -fsanitize=address -munwind-tables -o - %s | FileCheck %s --check-prefixes=UWTABLE +// RUN: %clang_cc1 -emit-llvm -fsanitize=address -funwind-tables=2 -o - %s | FileCheck %s --check-prefixes=UWTABLE // UWTABLE: define internal void @asan.module_dtor() #[[#ATTR:]] { // UWTABLE: attributes #[[#ATTR]] = { nounwind uwtable } // UWTABLE: ![[#]] = !{i32 7, !"uwtable", i32 1} diff --git a/clang/test/CodeGenCXX/exceptions-seh-filter-uwtable.cpp b/clang/test/CodeGenCXX/exceptions-seh-filter-uwtable.cpp index f09c6a39c7f5f..17fd01285d3c8 100644 --- a/clang/test/CodeGenCXX/exceptions-seh-filter-uwtable.cpp +++ b/clang/test/CodeGenCXX/exceptions-seh-filter-uwtable.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 "-triple" "arm64-windows" "-munwind-tables" "-fms-compatibility" -emit-llvm -O1 -disable-llvm-passes %s -o - | FileCheck %s +// RUN: %clang_cc1 "-triple" "arm64-windows" "-funwind-tables=2" "-fms-compatibility" -emit-llvm -O1 -disable-llvm-passes %s -o - | FileCheck %s // NOTE: we're passing "-O1 -disable-llvm-passes" to avoid adding optnone and noinline everywhere. # 0 "" 3 diff --git a/clang/test/CodeGenCXX/linetable-eh.cpp b/clang/test/CodeGenCXX/linetable-eh.cpp index 6821655a0bb14..b5c4295b028b5 100644 --- a/clang/test/CodeGenCXX/linetable-eh.cpp +++ b/clang/test/CodeGenCXX/linetable-eh.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -emit-llvm -debug-info-kind=limited -gno-column-info -triple x86_64-apple-macosx10.9.0 -munwind-tables -std=c++11 -fcxx-exceptions -fexceptions %s -o - | FileCheck -allow-deprecated-dag-overlap %s +// RUN: %clang_cc1 -emit-llvm -debug-info-kind=limited -gno-column-info -triple x86_64-apple-macosx10.9.0 -funwind-tables=2 -std=c++11 -fcxx-exceptions -fexceptions %s -o - | FileCheck -allow-deprecated-dag-overlap %s // Test that emitting a landing pad does not affect the line table // entries for the code that triggered it. diff --git a/clang/test/CodeGenCXX/thunks-ehspec.cpp b/clang/test/CodeGenCXX/thunks-ehspec.cpp index 21af391287ea3..41b2294b8eaf9 100644 --- a/clang/test/CodeGenCXX/thunks-ehspec.cpp +++ b/clang/test/CodeGenCXX/thunks-ehspec.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fexceptions -fcxx-exceptions %s -triple=x86_64-pc-linux-gnu -munwind-tables -emit-llvm -o - -O1 -disable-llvm-passes | FileCheck %s +// RUN: %clang_cc1 -fexceptions -fcxx-exceptions %s -triple=x86_64-pc-linux-gnu -funwind-tables=2 -emit-llvm -o - -O1 -disable-llvm-passes | FileCheck %s // When generating the thunk for secondary, do not push terminate scopes for // either the varargs or non-varargs case. Related to PR44987. diff --git a/clang/test/CodeGenCXX/thunks.cpp b/clang/test/CodeGenCXX/thunks.cpp index ec2a5973caa7f..c4109526d28c2 100644 --- a/clang/test/CodeGenCXX/thunks.cpp +++ b/clang/test/CodeGenCXX/thunks.cpp @@ -1,18 +1,18 @@ // Sparc64 doesn't support musttail (yet), so it uses method cloning for // variadic thunks. Use it for testing. -// RUN: %clang_cc1 %s -triple=sparc64-pc-linux-gnu -munwind-tables -emit-llvm -o - \ +// RUN: %clang_cc1 %s -triple=sparc64-pc-linux-gnu -funwind-tables=2 -emit-llvm -o - \ // RUN: | FileCheck --check-prefixes=CHECK,CHECK-CLONE,CHECK-NONOPT %s -// RUN: %clang_cc1 %s -triple=sparc64-pc-linux-gnu -debug-info-kind=standalone -dwarf-version=5 -munwind-tables -emit-llvm -o - \ +// RUN: %clang_cc1 %s -triple=sparc64-pc-linux-gnu -debug-info-kind=standalone -dwarf-version=5 -funwind-tables=2 -emit-llvm -o - \ // RUN: | FileCheck --check-prefixes=CHECK,CHECK-CLONE,CHECK-NONOPT,CHECK-DBG %s -// RUN: %clang_cc1 %s -triple=sparc64-pc-linux-gnu -munwind-tables -emit-llvm -o - -O1 -disable-llvm-passes \ +// RUN: %clang_cc1 %s -triple=sparc64-pc-linux-gnu -funwind-tables=2 -emit-llvm -o - -O1 -disable-llvm-passes \ // RUN: | FileCheck --check-prefixes=CHECK,CHECK-CLONE,CHECK-OPT %s // Test x86_64, which uses musttail for variadic thunks. -// RUN: %clang_cc1 %s -triple=x86_64-pc-linux-gnu -munwind-tables -emit-llvm -o - -O1 -disable-llvm-passes \ +// RUN: %clang_cc1 %s -triple=x86_64-pc-linux-gnu -funwind-tables=2 -emit-llvm -o - -O1 -disable-llvm-passes \ // RUN: | FileCheck --check-prefixes=CHECK,CHECK-TAIL,CHECK-OPT %s // Finally, reuse these tests for the MS ABI. -// RUN: %clang_cc1 %s -triple=x86_64-windows-msvc -munwind-tables -emit-llvm -o - -O1 -disable-llvm-passes \ +// RUN: %clang_cc1 %s -triple=x86_64-windows-msvc -funwind-tables=2 -emit-llvm -o - -O1 -disable-llvm-passes \ // RUN: | FileCheck --check-prefixes=WIN64 %s diff --git a/clang/test/Driver/aarch64-features.c b/clang/test/Driver/aarch64-features.c index 356ed3682a243..15809e1737985 100644 --- a/clang/test/Driver/aarch64-features.c +++ b/clang/test/Driver/aarch64-features.c @@ -1,7 +1,7 @@ // RUN: %clang -target aarch64-none-linux-gnu -### %s -fsyntax-only 2>&1 | FileCheck %s // RUN: %clang -target arm64-none-linux-gnu -### %s -fsyntax-only 2>&1 | FileCheck %s -// CHECK: "-munwind-tables" +// CHECK: "-funwind-tables=2" // The AArch64 PCS states that chars should be unsigned. // CHECK: fno-signed-char diff --git a/clang/test/Driver/clang-translation.c b/clang/test/Driver/clang-translation.c index d1daeb80004b7..42322e579472b 100644 --- a/clang/test/Driver/clang-translation.c +++ b/clang/test/Driver/clang-translation.c @@ -4,13 +4,16 @@ // I386: "-disable-free" // I386: "-mrelocation-model" "static" // I386: "-mframe-pointer=all" -// I386: "-munwind-tables" +// I386: "-funwind-tables=1" // I386: "-Os" // I386: "-fvisibility" // I386: "hidden" // I386: "-o" // I386: clang-translation +// RUN: %clang -target i386-unknown-unknown -### -S %s -fasynchronous-unwind-tables -fno-unwind-tables 2>&1 | FileCheck --check-prefix=UNWIND-TABLES %s +// UNWIND-TABLES: "-funwind-tables=2" + // RUN: %clang -target i386-apple-darwin9 -### -S %s -o %t.s 2>&1 | \ // RUN: FileCheck -check-prefix=YONAH %s // RUN: %clang -target i386-apple-macosx10.11 -### -S %s -o %t.s 2>&1 | \ @@ -75,7 +78,7 @@ // RUN: %clang -target arm64-apple-ios10 -### -S %s -arch arm64 2>&1 | \ // RUN: FileCheck -check-prefix=ARM64-APPLE %s -// ARM64-APPLE: -munwind-table +// ARM64-APPLE: -funwind-tables=2 // RUN: %clang -target arm64-apple-ios10 -### -ffreestanding -S %s -arch arm64 2>&1 | \ // RUN: FileCheck -check-prefix=ARM64-FREESTANDING-APPLE %s @@ -83,7 +86,7 @@ // RUN: %clang -target arm64-apple-ios10 -### -fno-unwind-tables -ffreestanding -S %s -arch arm64 2>&1 | \ // RUN: FileCheck -check-prefix=ARM64-FREESTANDING-APPLE %s // -// ARM64-FREESTANDING-APPLE-NOT: -munwind-table +// ARM64-FREESTANDING-APPLE-NOT: -funwind-tables // RUN: %clang -target arm64-apple-ios10 -### -funwind-tables -S %s -arch arm64 2>&1 | \ // RUN: FileCheck -check-prefix=ARM64-EXPLICIT-UWTABLE-APPLE %s @@ -91,15 +94,15 @@ // RUN: %clang -target arm64-apple-ios10 -### -ffreestanding -funwind-tables -S %s -arch arm64 2>&1 | \ // RUN: FileCheck -check-prefix=ARM64-EXPLICIT-UWTABLE-APPLE %s // -// ARM64-EXPLICIT-UWTABLE-APPLE: -munwind-table +// ARM64-EXPLICIT-UWTABLE-APPLE: -funwind-tables // RUN: %clang -target arm64-apple-ios10 -fno-exceptions -### -S %s -arch arm64 2>&1 | \ // RUN: FileCheck -check-prefix=ARM64-APPLE-EXCEP %s -// ARM64-APPLE-EXCEP-NOT: -munwind-table +// ARM64-APPLE-EXCEP-NOT: -funwind-tables // RUN: %clang -target armv7k-apple-watchos4.0 -### -S %s -arch armv7k 2>&1 | \ // RUN: FileCheck -check-prefix=ARMV7K-APPLE %s -// ARMV7K-APPLE: -munwind-table +// ARMV7K-APPLE: -funwind-tables // RUN: %clang -target arm-linux -### -S %s -march=armv5e 2>&1 | \ // RUN: FileCheck -check-prefix=ARMV5E %s @@ -299,7 +302,7 @@ // AMD64: "-cc1" // AMD64: "-triple" // AMD64: "amd64-unknown-openbsd5.2" -// AMD64: "-munwind-tables" +// AMD64: "-funwind-tables=2" // RUN: %clang -target amd64--mingw32 -### -S %s 2>&1 | \ // RUN: FileCheck -check-prefix=AMD64-MINGW %s @@ -307,7 +310,7 @@ // AMD64-MINGW: "-cc1" // AMD64-MINGW: "-triple" // AMD64-MINGW: "amd64-unknown-windows-gnu" -// AMD64-MINGW: "-munwind-tables" +// AMD64-MINGW: "-funwind-tables=2" // RUN: %clang -target i686-linux-android -### -S %s 2>&1 \ // RUN: --sysroot=%S/Inputs/basic_android_tree/sysroot \ diff --git a/clang/test/Driver/freebsd.c b/clang/test/Driver/freebsd.c index e1143b40fe86b..bed1b927898f6 100644 --- a/clang/test/Driver/freebsd.c +++ b/clang/test/Driver/freebsd.c @@ -204,4 +204,4 @@ // RUN: %clang -target ppc64-unknown-freebsd13.0 -### -S %s 2>&1 | \ // RUN: FileCheck -check-prefix=PPC64-MUNWIND %s -// PPC64-MUNWIND: -munwind-table +// PPC64-MUNWIND: "-funwind-tables=2" diff --git a/clang/test/Driver/fuchsia.c b/clang/test/Driver/fuchsia.c index e9b396991a2c2..b0eb78b7e755f 100644 --- a/clang/test/Driver/fuchsia.c +++ b/clang/test/Driver/fuchsia.c @@ -15,7 +15,7 @@ // CHECK-AARCH64: "-triple" "aarch64-unknown-fuchsia" // CHECK-RISCV64: "-triple" "riscv64-unknown-fuchsia" // CHECK: "--mrelax-relocations" -// CHECK: "-munwind-tables" +// CHECK: "-funwind-tables=2" // CHECK: "-resource-dir" "[[RESOURCE_DIR:[^"]+]]" // CHECK: "-isysroot" "[[SYSROOT:[^"]+]]" // CHECK: "-internal-externc-isystem" "[[SYSROOT]]{{/|\\\\}}include" diff --git a/clang/test/Driver/ppc-features.cpp b/clang/test/Driver/ppc-features.cpp index def96c351b34d..17c9451989a49 100644 --- a/clang/test/Driver/ppc-features.cpp +++ b/clang/test/Driver/ppc-features.cpp @@ -3,7 +3,7 @@ // RUN: %clang -### -target powerpc-unknown-linux-gnu %s 2>&1 | FileCheck --check-prefixes=PPC32,PPC32BELNX %s // RUN: %clang -### -target powerpcle-unknown-freebsd13.0 %s 2>&1 | FileCheck --check-prefixes=PPC32,PPC32LEFBSD %s // RUN: %clang -### -target powerpc-unknown-freebsd13.0 %s 2>&1 | FileCheck --check-prefixes=PPC32,PPC32BEFBSD %s -// PPC32: "-munwind-tables" +// PPC32: "-funwind-tables=2" // PPC32-SAME: "-mfloat-abi" "hard" // PPC32LELNX-NEXT: "-m" "elf32lppclinux" @@ -47,7 +47,7 @@ /// Check default CC1 and linker options for ppc64. // RUN: %clang -### -target powerpc64le-unknown-linux-gnu %s 2>&1 | FileCheck --check-prefixes=PPC64,PPC64LE %s // RUN: %clang -### -target powerpc64-unknown-linux-gnu %s 2>&1 | FileCheck --check-prefixes=PPC64,PPC64BE %s -// PPC64: "-munwind-tables" +// PPC64: "-funwind-tables=2" // PPC64-SAME: "-mfloat-abi" "hard" // PPC64LE: "-m" "elf64lppc" diff --git a/clang/test/Driver/sanitize_unwind_tables.c b/clang/test/Driver/sanitize_unwind_tables.c index d361fbd8b41ba..8f004cdf29bd5 100644 --- a/clang/test/Driver/sanitize_unwind_tables.c +++ b/clang/test/Driver/sanitize_unwind_tables.c @@ -10,4 +10,4 @@ // RUN: %clang -target aarch64-linux-gnu -fsanitize=hwaddress %s -### 2>&1 | FileCheck %s // RUN: %clang -target aarch64-linux-android -fsanitize=hwaddress %s -### 2>&1 | FileCheck %s -// CHECK: -munwind-tables +// CHECK: -funwind-tables=2 diff --git a/clang/test/Driver/win-macho-unwind.c b/clang/test/Driver/win-macho-unwind.c index a2895d2fe8c0d..6aa9115042a68 100644 --- a/clang/test/Driver/win-macho-unwind.c +++ b/clang/test/Driver/win-macho-unwind.c @@ -1,4 +1,4 @@ // RUN: %clang -target x86_64-pc-win32-macho -### -S %s -o %t.s 2>&1 | FileCheck %s // Do not add function attribute "uwtable" for macho targets. -// CHECK-NOT: -munwind-tables +// CHECK-NOT: -funwind-tables=2 diff --git a/clang/test/Driver/windows-exceptions.cpp b/clang/test/Driver/windows-exceptions.cpp index abdd4bb633d3a..84f8e2708f8ee 100644 --- a/clang/test/Driver/windows-exceptions.cpp +++ b/clang/test/Driver/windows-exceptions.cpp @@ -8,5 +8,5 @@ MSVC-NOT: -exception-model=dwarf MSVC-NOT: -exception-model=seh MINGW-DWARF: -exception-model=dwarf -MINGW-SEH: -munwind-tables +MINGW-SEH: -funwind-tables=2 MINGW-SEH: -exception-model=seh diff --git a/clang/test/Preprocessor/unwind-tables.c b/clang/test/Preprocessor/unwind-tables.c index 4eab8e516cdaf..0a863d79adbf6 100644 --- a/clang/test/Preprocessor/unwind-tables.c +++ b/clang/test/Preprocessor/unwind-tables.c @@ -2,6 +2,7 @@ // RUN: %clang %s -dM -E -target x86_64 -fno-asynchronous-unwind-tables | FileCheck %s --check-prefix=NO // RUN: %clang %s -dM -E -target x86_64 | FileCheck %s +// RUN: %clang %s -dM -E -target x86_64 -funwind-tables -fno-asynchronous-unwind-tables -g | FileCheck %s // RUN: %clang %s -dM -E -target aarch64-apple-darwin | FileCheck %s // RUN: %clang %s -dM -E -target x86_64 -fno-asynchronous-unwind-tables -g | FileCheck %s // RUN: %clang %s -dM -E -target x86_64 -fno-asynchronous-unwind-tables -fexceptions | FileCheck %s _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits