diff --git a/clang/lib/Frontend/CompilerInvocation.cpp b/clang/lib/Frontend/CompilerInvocation.cpp --- a/clang/lib/Frontend/CompilerInvocation.cpp +++ b/clang/lib/Frontend/CompilerInvocation.cpp @@ -4045,8 +4045,8 @@ static bool ParsePreprocessorArgs(PreprocessorOptions &Opts, ArgList &Args, DiagnosticsEngine &Diags, - frontend::ActionKind Action, - const FrontendOptions &FrontendOpts) { + const FrontendOptions &FrontendOpts, + const llvm::Triple &T) { PreprocessorOptions *PreprocessorOpts = &Opts; bool Success = true; @@ -4101,6 +4101,10 @@ Opts.addMacroDef("__CET__=3"); } + if (Args.hasArg(OPT_munwind_tables) && + (T.isOSBinFormatELF() || T.isOSBinFormatMachO())) + Opts.addMacroDef("__GCC_HAVE_DWARF2_CFI_ASM=1"); + // Add macros from the command line. for (const auto *A : Args.filtered(OPT_D, OPT_U)) { if (A->getOption().matches(OPT_D)) @@ -4130,7 +4134,7 @@ // Always avoid lexing editor placeholders when we're just running the // preprocessor as we never want to emit the // "editor placeholder in source file" error in PP only mode. - if (isStrictlyPreprocessorAction(Action)) + if (isStrictlyPreprocessorAction(FrontendOpts.ProgramAction)) Opts.LexEditorPlaceholders = false; return Success; @@ -4325,8 +4329,7 @@ !LangOpts.Sanitize.has(SanitizerKind::KernelMemory); ParsePreprocessorArgs(Res.getPreprocessorOpts(), Args, Diags, - Res.getFrontendOpts().ProgramAction, - Res.getFrontendOpts()); + Res.getFrontendOpts(), T); ParsePreprocessorOutputArgs(Res.getPreprocessorOutputOpts(), Args, Diags, Res.getFrontendOpts().ProgramAction); diff --git a/clang/test/Preprocessor/unwind-tables.c b/clang/test/Preprocessor/unwind-tables.c new file mode 100644 --- /dev/null +++ b/clang/test/Preprocessor/unwind-tables.c @@ -0,0 +1,15 @@ +// RUN: %clang_cc1 %s -verify -munwind-tables -DCFI_ASM -triple x86_64-unknown-elf +// RUN: %clang_cc1 %s -verify -munwind-tables -DCFI_ASM -triple aarch64-apple-darwin +// RUN: %clang_cc1 %s -verify -munwind-tables -triple x86_64-windows + +// expected-no-diagnostics + +#ifdef CFI_ASM + #if __GCC_HAVE_DWARF2_CFI_ASM != 1 + #error "__GCC_HAVE_DWARF2_CFI_ASM not defined" + #endif +#else + #ifdef __GCC_HAVE_DWARF2_CFI_ASM + #error "__GCC_HAVE_DWARF2_CFI_ASM defined" + #endif +#endif