Skip to content

Commit d65e712

Browse files
authored
[clang] Make "__GCC_HAVE_DWARF2_CFI_ASM" a proper predefined macro (llvm#165731)
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 2de5a17 commit d65e712

File tree

8 files changed

+22
-7
lines changed

8 files changed

+22
-7
lines changed

clang-tools-extra/test/pp-trace/pp-trace-include.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
// CHECK-NEXT: Reason: EnterFile
4040
// CHECK-NEXT: FileType: C_User
4141
// CHECK-NEXT: PrevFID: (invalid)
42-
// CHECK: - Callback: MacroDefined
4342
// CHECK: - Callback: FileChanged
4443
// CHECK-NEXT: Loc: "<built-in>:1:1"
4544
// CHECK-NEXT: Reason: ExitFile

clang-tools-extra/test/pp-trace/pp-trace-macro.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ X
4040
// CHECK-NEXT: MacroNameTok: __STDC_EMBED_EMPTY__
4141
// CHECK-NEXT: MacroDirective: MD_Define
4242
// CHECK: - Callback: MacroDefined
43-
// CHECK: - Callback: MacroDefined
4443
// CHECK-NEXT: MacroNameTok: MACRO
4544
// CHECK-NEXT: MacroDirective: MD_Define
4645
// CHECK-NEXT: - Callback: MacroExpands

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
@@ -2155,8 +2155,12 @@ defm dollars_in_identifiers : BoolFOption<"dollars-in-identifiers",
21552155
PosFlag<SetTrue, [], [ClangOption], "Allow">,
21562156
NegFlag<SetFalse, [], [ClangOption], "Disallow">,
21572157
BothFlags<[], [ClangOption, CC1Option], " '$' in identifiers">>;
2158-
def fdwarf2_cfi_asm : Flag<["-"], "fdwarf2-cfi-asm">, Group<clang_ignored_f_Group>;
2159-
def fno_dwarf2_cfi_asm : Flag<["-"], "fno-dwarf2-cfi-asm">, Group<clang_ignored_f_Group>;
2158+
2159+
defm dwarf2_cfi_asm
2160+
: BoolFOption<"dwarf2-cfi-asm", CodeGenOpts<"Dwarf2CFIAsm">, DefaultFalse,
2161+
PosFlag<SetTrue, [], [ClangOption, CC1Option]>,
2162+
NegFlag<SetFalse>>;
2163+
21602164
defm dwarf_directory_asm : BoolFOption<"dwarf-directory-asm",
21612165
CodeGenOpts<"NoDwarfDirectoryAsm">, DefaultFalse,
21622166
NegFlag<SetTrue, [], [ClangOption, CC1Option]>,

clang/lib/Driver/ToolChains/Clang.cpp

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

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

78877890
if (Arg *A = Args.getLastArg(options::OPT_fsymbol_partition_EQ)) {
78887891
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
}

clang/test/DebugInfo/KeyInstructions/flag.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88

99
// KEY-INSTRUCTIONS: "-gkey-instructions"
1010
// NO-KEY-INSTRUCTIONS-NOT: key-instructions
11+
12+
// Only expect one dwarf related flag.
13+
// NO-DEBUG: -fdwarf2-cfi-asm
1114
// NO-DEBUG-NOT: debug-info-kind
1215
// NO-DEBUG-NOT: dwarf
1316

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)