Skip to content

Commit 4d77531

Browse files
committed
[clang] Make "__GCC_HAVE_DWARF2_CFI_ASM" a proper predefined macro
Use a flag to determine whether this macro should be set when intializing the preprocessor. This macro was added to the driver in 9d117e7 because it can be conditionally disabled, but before that, the flag to gate behavior was removed under the assumption it wasn't conditional in b5b622a. This patch is to connect the macro with the preexisting flag
1 parent 03e66ae commit 4d77531

File tree

5 files changed

+19
-5
lines changed

5 files changed

+19
-5
lines changed

clang/include/clang/Basic/DebugOptions.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ ENUM_DEBUGOPT(EmitDwarfUnwind, EmitDwarfUnwindType, 2,
4646
DEBUGOPT(NoDwarfDirectoryAsm , 1, 0, Benign) ///< Set when -fno-dwarf-directory-asm
4747
///< is enabled.
4848

49+
DEBUGOPT(Dwarf2CFIAsm, 1, 0, NotCompatible) ///< Set when -fdwarf2-cfi-asm is enabled.
50+
4951
DEBUGOPT(NoInlineLineTables, 1, 0, Benign) ///< Whether debug info should contain
5052
///< inline line tables.
5153

clang/include/clang/Driver/Options.td

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2154,8 +2154,12 @@ defm dollars_in_identifiers : BoolFOption<"dollars-in-identifiers",
21542154
PosFlag<SetTrue, [], [ClangOption], "Allow">,
21552155
NegFlag<SetFalse, [], [ClangOption], "Disallow">,
21562156
BothFlags<[], [ClangOption, CC1Option], " '$' in identifiers">>;
2157-
def fdwarf2_cfi_asm : Flag<["-"], "fdwarf2-cfi-asm">, Group<clang_ignored_f_Group>;
2158-
def fno_dwarf2_cfi_asm : Flag<["-"], "fno-dwarf2-cfi-asm">, Group<clang_ignored_f_Group>;
2157+
2158+
defm dwarf2_cfi_asm
2159+
: BoolFOption<"dwarf2-cfi-asm", CodeGenOpts<"Dwarf2CFIAsm">, DefaultFalse,
2160+
PosFlag<SetTrue, [], [ClangOption, CC1Option]>,
2161+
NegFlag<SetFalse>>;
2162+
21592163
defm dwarf_directory_asm : BoolFOption<"dwarf-directory-asm",
21602164
CodeGenOpts<"NoDwarfDirectoryAsm">, DefaultFalse,
21612165
NegFlag<SetTrue, [], [ClangOption, CC1Option]>,

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7878,10 +7878,13 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
78787878
!TC.getTriple().isAndroid() && TC.useIntegratedAs()))
78797879
CmdArgs.push_back("-faddrsig");
78807880

7881-
if ((Triple.isOSBinFormatELF() || Triple.isOSBinFormatMachO()) &&
7881+
const bool HasDefaultDwarf2CFIASM =
7882+
(Triple.isOSBinFormatELF() || Triple.isOSBinFormatMachO()) &&
78827883
(EH || UnwindTables || AsyncUnwindTables ||
7883-
DebugInfoKind != llvm::codegenoptions::NoDebugInfo))
7884-
CmdArgs.push_back("-D__GCC_HAVE_DWARF2_CFI_ASM=1");
7884+
DebugInfoKind != llvm::codegenoptions::NoDebugInfo);
7885+
if (Args.hasFlag(options::OPT_fdwarf2_cfi_asm,
7886+
options::OPT_fno_dwarf2_cfi_asm, HasDefaultDwarf2CFIASM))
7887+
CmdArgs.push_back("-fdwarf2-cfi-asm");
78857888

78867889
if (Arg *A = Args.getLastArg(options::OPT_fsymbol_partition_EQ)) {
78877890
std::string Str = A->getAsString(Args);

clang/lib/Frontend/InitPreprocessor.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1516,6 +1516,9 @@ static void InitializePredefinedMacros(const TargetInfo &TI,
15161516
if (LangOpts.PointerAuthIntrinsics)
15171517
Builder.defineMacro("__PTRAUTH__");
15181518

1519+
if (CGOpts.Dwarf2CFIAsm)
1520+
Builder.defineMacro("__GCC_HAVE_DWARF2_CFI_ASM");
1521+
15191522
// Get other target #defines.
15201523
TI.getTargetDefines(LangOpts, Builder);
15211524
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
// RUN: %clang %s -dM -E -target x86_64-windows | FileCheck %s --check-prefix=NO
22
// RUN: %clang %s -dM -E -target x86_64 -fno-asynchronous-unwind-tables | FileCheck %s --check-prefix=NO
3+
// RUN: %clang %s -dM -E -target x86_64 -fno-dwarf2-cfi-asm | FileCheck %s --check-prefix=NO
34

45
// RUN: %clang %s -dM -E -target x86_64 | FileCheck %s
56
// RUN: %clang %s -dM -E -target x86_64 -funwind-tables -fno-asynchronous-unwind-tables -g | FileCheck %s
67
// RUN: %clang %s -dM -E -target aarch64-apple-darwin | FileCheck %s
78
// RUN: %clang %s -dM -E -target x86_64 -fno-asynchronous-unwind-tables -g | FileCheck %s
89
// RUN: %clang %s -dM -E -target x86_64 -fno-asynchronous-unwind-tables -fexceptions | FileCheck %s
10+
// RUN: %clang %s -dM -E -target x86_64-windows -fdwarf2-cfi-asm | FileCheck %s
911

1012
// NO-NOT: #define __GCC_HAVE_DWARF2_CFI_ASM
1113
// CHECK: #define __GCC_HAVE_DWARF2_CFI_ASM 1

0 commit comments

Comments
 (0)