diff --git a/clang-tools-extra/test/pp-trace/pp-trace-include.cpp b/clang-tools-extra/test/pp-trace/pp-trace-include.cpp index ea9896e1cfde2..fccbd9b3740bd 100644 --- a/clang-tools-extra/test/pp-trace/pp-trace-include.cpp +++ b/clang-tools-extra/test/pp-trace/pp-trace-include.cpp @@ -39,7 +39,6 @@ // CHECK-NEXT: Reason: EnterFile // CHECK-NEXT: FileType: C_User // CHECK-NEXT: PrevFID: (invalid) -// CHECK: - Callback: MacroDefined // CHECK: - Callback: FileChanged // CHECK-NEXT: Loc: ":1:1" // CHECK-NEXT: Reason: ExitFile diff --git a/clang-tools-extra/test/pp-trace/pp-trace-macro.cpp b/clang-tools-extra/test/pp-trace/pp-trace-macro.cpp index 7c2a231101070..5bd38e0dade28 100644 --- a/clang-tools-extra/test/pp-trace/pp-trace-macro.cpp +++ b/clang-tools-extra/test/pp-trace/pp-trace-macro.cpp @@ -40,7 +40,6 @@ X // CHECK-NEXT: MacroNameTok: __STDC_EMBED_EMPTY__ // CHECK-NEXT: MacroDirective: MD_Define // CHECK: - Callback: MacroDefined -// CHECK: - Callback: MacroDefined // CHECK-NEXT: MacroNameTok: MACRO // CHECK-NEXT: MacroDirective: MD_Define // CHECK-NEXT: - Callback: MacroExpands diff --git a/clang/include/clang/Basic/DebugOptions.def b/clang/include/clang/Basic/DebugOptions.def index e3f9635edb70c..407f441231e67 100644 --- a/clang/include/clang/Basic/DebugOptions.def +++ b/clang/include/clang/Basic/DebugOptions.def @@ -46,6 +46,8 @@ ENUM_DEBUGOPT(EmitDwarfUnwind, llvm::EmitDwarfUnwindType, 2, DEBUGOPT(NoDwarfDirectoryAsm , 1, 0, Benign) ///< Set when -fno-dwarf-directory-asm ///< is enabled. +DEBUGOPT(Dwarf2CFIAsm, 1, 0, Affecting) ///< Set when -fdwarf2-cfi-asm is enabled. + DEBUGOPT(NoInlineLineTables, 1, 0, Benign) ///< Whether debug info should contain ///< inline line tables. diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index c4f3950202bb3..cac11389b7ee7 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -2310,8 +2310,12 @@ defm dollars_in_identifiers : BoolFOption<"dollars-in-identifiers", PosFlag, NegFlag, BothFlags<[], [ClangOption, CC1Option], " '$' in identifiers">>; -def fdwarf2_cfi_asm : Flag<["-"], "fdwarf2-cfi-asm">, Group; -def fno_dwarf2_cfi_asm : Flag<["-"], "fno-dwarf2-cfi-asm">, Group; + +defm dwarf2_cfi_asm + : BoolFOption<"dwarf2-cfi-asm", CodeGenOpts<"Dwarf2CFIAsm">, DefaultFalse, + PosFlag, + NegFlag>; + defm dwarf_directory_asm : BoolFOption<"dwarf-directory-asm", CodeGenOpts<"NoDwarfDirectoryAsm">, DefaultFalse, NegFlag, diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 3983f9c3867d4..0eac0bb8d2053 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -8328,10 +8328,13 @@ void Clang::ConstructJob(Compilation &C, const JobAction &Job, !TC.getTriple().isAndroid() && TC.useIntegratedAs())) CmdArgs.push_back("-faddrsig"); - if ((Triple.isOSBinFormatELF() || Triple.isOSBinFormatMachO()) && + const bool HasDefaultDwarf2CFIASM = + (Triple.isOSBinFormatELF() || Triple.isOSBinFormatMachO()) && (EH || UnwindTables || AsyncUnwindTables || - DebugInfoKind != llvm::codegenoptions::NoDebugInfo)) - CmdArgs.push_back("-D__GCC_HAVE_DWARF2_CFI_ASM=1"); + DebugInfoKind != llvm::codegenoptions::NoDebugInfo); + if (Args.hasFlag(options::OPT_fdwarf2_cfi_asm, + options::OPT_fno_dwarf2_cfi_asm, HasDefaultDwarf2CFIASM)) + CmdArgs.push_back("-fdwarf2-cfi-asm"); if (Arg *A = Args.getLastArg(options::OPT_fsymbol_partition_EQ)) { std::string Str = A->getAsString(Args); diff --git a/clang/lib/Frontend/InitPreprocessor.cpp b/clang/lib/Frontend/InitPreprocessor.cpp index cce8392950b03..0abaa71799d65 100644 --- a/clang/lib/Frontend/InitPreprocessor.cpp +++ b/clang/lib/Frontend/InitPreprocessor.cpp @@ -1596,6 +1596,9 @@ void clang::InitializePreprocessor(Preprocessor &PP, } } + if (CodeGenOpts.Dwarf2CFIAsm) + Builder.defineMacro("__GCC_HAVE_DWARF2_CFI_ASM"); + // Even with predefines off, some macros are still predefined. // These should all be defined in the preprocessor according to the // current language configuration. diff --git a/clang/test/Preprocessor/unwind-tables.c b/clang/test/Preprocessor/unwind-tables.c index 0a863d79adbf6..5ff990d0c40a6 100644 --- a/clang/test/Preprocessor/unwind-tables.c +++ b/clang/test/Preprocessor/unwind-tables.c @@ -1,11 +1,13 @@ // RUN: %clang %s -dM -E -target x86_64-windows | FileCheck %s --check-prefix=NO // 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 -fno-dwarf2-cfi-asm | 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 +// RUN: %clang %s -dM -E -target x86_64-windows -fdwarf2-cfi-asm | FileCheck %s // NO-NOT: #define __GCC_HAVE_DWARF2_CFI_ASM // CHECK: #define __GCC_HAVE_DWARF2_CFI_ASM 1