Skip to content

Commit 3ea9080

Browse files
author
git apple-llvm automerger
committed
Merge commit '64075837b553' from llvm.org/release/19.x into stable/20240723
2 parents c77ee3f + 6407583 commit 3ea9080

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8794,6 +8794,32 @@ void ClangAs::ConstructJob(Compilation &C, const JobAction &JA,
87948794
WantDebug = !A->getOption().matches(options::OPT_g0) &&
87958795
!A->getOption().matches(options::OPT_ggdb0);
87968796

8797+
// If a -gdwarf argument appeared, remember it.
8798+
bool EmitDwarf = false;
8799+
if (const Arg *A = getDwarfNArg(Args))
8800+
EmitDwarf = checkDebugInfoOption(A, Args, D, getToolChain());
8801+
8802+
bool EmitCodeView = false;
8803+
if (const Arg *A = Args.getLastArg(options::OPT_gcodeview))
8804+
EmitCodeView = checkDebugInfoOption(A, Args, D, getToolChain());
8805+
8806+
// If the user asked for debug info but did not explicitly specify -gcodeview
8807+
// or -gdwarf, ask the toolchain for the default format.
8808+
if (!EmitCodeView && !EmitDwarf && WantDebug) {
8809+
switch (getToolChain().getDefaultDebugFormat()) {
8810+
case llvm::codegenoptions::DIF_CodeView:
8811+
EmitCodeView = true;
8812+
break;
8813+
case llvm::codegenoptions::DIF_DWARF:
8814+
EmitDwarf = true;
8815+
break;
8816+
}
8817+
}
8818+
8819+
// If the arguments don't imply DWARF, don't emit any debug info here.
8820+
if (!EmitDwarf)
8821+
WantDebug = false;
8822+
87978823
llvm::codegenoptions::DebugInfoKind DebugInfoKind =
87988824
llvm::codegenoptions::NoDebugInfo;
87998825

clang/test/Driver/debug-options-as.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,27 @@
1919
// GGDB0-NOT: -debug-info-kind=
2020

2121
// Check to make sure clang with -g on a .s file gets passed.
22-
// RUN: %clang -### -c -integrated-as -g -x assembler %s 2>&1 \
22+
// This requires a target that defaults to DWARF.
23+
// RUN: %clang -### --target=x86_64-linux-gnu -c -integrated-as -g -x assembler %s 2>&1 \
2324
// RUN: | FileCheck %s
2425
//
2526
// CHECK: "-cc1as"
2627
// CHECK: "-debug-info-kind=constructor"
2728

29+
// Check that a plain -g, without any -gdwarf, for a MSVC target, doesn't
30+
// trigger producing DWARF output.
31+
// RUN: %clang -### --target=x86_64-windows-msvc -c -integrated-as -g -x assembler %s 2>&1 \
32+
// RUN: | FileCheck -check-prefix=MSVC %s
33+
//
34+
// MSVC: "-cc1as"
35+
// MSVC-NOT: "-debug-info-kind=constructor"
36+
37+
// Check that clang-cl with the -Z7 option works the same, not triggering
38+
// any DWARF output.
39+
//
40+
// RUN: %clang_cl -### --target=x86_64-pc-windows-msvc -c -Z7 -x assembler -- %s 2>&1 \
41+
// RUN: | FileCheck -check-prefix=MSVC %s
42+
2843
// Check to make sure clang with -g on a .s file gets passed -dwarf-debug-producer.
2944
// RUN: %clang -### -c -integrated-as -g -x assembler %s 2>&1 \
3045
// RUN: | FileCheck -check-prefix=P %s

0 commit comments

Comments
 (0)