Skip to content

Commit b2323f4

Browse files
author
Chen Zheng
committed
[AIX][Debug] generate an error instead of crash in backend for -gdwarf-5
Before this change -gdwarf-5 on AIX will cause backend crash, because some DWARF5 sections are not defined in XCOFF. Explicitly statement -gdwarf-5 as unsupported in frontend on AIX.
1 parent ca7d944 commit b2323f4

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

clang/lib/Driver/ToolChains/CommonArgs.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2116,8 +2116,12 @@ unsigned tools::getDwarfVersion(const ToolChain &TC,
21162116
const llvm::opt::ArgList &Args) {
21172117
unsigned DwarfVersion = ParseDebugDefaultVersion(TC, Args);
21182118
if (const Arg *GDwarfN = getDwarfNArg(Args))
2119-
if (int N = DwarfVersionNum(GDwarfN->getSpelling()))
2119+
if (int N = DwarfVersionNum(GDwarfN->getSpelling())) {
21202120
DwarfVersion = N;
2121+
if (DwarfVersion == 5 && TC.getTriple().isOSAIX())
2122+
TC.getDriver().Diag(diag::err_drv_unsupported_opt_for_target)
2123+
<< GDwarfN->getSpelling() << TC.getTriple().str();
2124+
}
21212125
if (DwarfVersion == 0) {
21222126
DwarfVersion = TC.GetDefaultDwarfVersion();
21232127
assert(DwarfVersion && "toolchain default DWARF version must be nonzero");

clang/test/CodeGen/dwarf-version.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,10 @@
4646
// RUN: FileCheck %s --check-prefix=VER3
4747
// RUN: %clang -target powerpc-ibm-aix-xcoff -gdwarf-4 -S -emit-llvm -o - %s | \
4848
// RUN: FileCheck %s --check-prefix=VER4
49-
// RUN: %clang -target powerpc-ibm-aix-xcoff -gdwarf-5 -S -emit-llvm -o - %s | \
50-
// RUN: FileCheck %s --check-prefix=VER5
49+
// RUN: not %clang -target powerpc-ibm-aix-xcoff -gdwarf-5 -S -emit-llvm -o - %s 2>&1 | \
50+
// RUN: FileCheck %s --check-prefix=UNSUPPORTED-VER5
51+
// RUN: not %clang -target powerpc64-ibm-aix-xcoff -gdwarf-5 -S -emit-llvm -o - %s 2>&1| \
52+
// RUN: FileCheck %s --check-prefix=UNSUPPORTED-VER5
5153

5254
int main (void) {
5355
return 0;
@@ -59,6 +61,7 @@ int main (void) {
5961
// VER3: !{i32 7, !"Dwarf Version", i32 3}
6062
// VER4: !{i32 7, !"Dwarf Version", i32 4}
6163
// VER5: !{i32 7, !"Dwarf Version", i32 5}
64+
// UNSUPPORTED-VER5: error: unsupported option '-gdwarf-5'
6265

6366
// NODWARF-NOT: !"Dwarf Version"
6467
// CODEVIEW: !{i32 2, !"CodeView", i32 1}

0 commit comments

Comments
 (0)