Skip to content

Commit

Permalink
[AIX][Debug] generate an error instead of crash in backend for -gdwarf-5
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
chenzheng1030 committed Apr 19, 2024
1 parent ca7d944 commit b2323f4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
6 changes: 5 additions & 1 deletion clang/lib/Driver/ToolChains/CommonArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2116,8 +2116,12 @@ unsigned tools::getDwarfVersion(const ToolChain &TC,
const llvm::opt::ArgList &Args) {
unsigned DwarfVersion = ParseDebugDefaultVersion(TC, Args);
if (const Arg *GDwarfN = getDwarfNArg(Args))
if (int N = DwarfVersionNum(GDwarfN->getSpelling()))
if (int N = DwarfVersionNum(GDwarfN->getSpelling())) {
DwarfVersion = N;
if (DwarfVersion == 5 && TC.getTriple().isOSAIX())
TC.getDriver().Diag(diag::err_drv_unsupported_opt_for_target)
<< GDwarfN->getSpelling() << TC.getTriple().str();
}
if (DwarfVersion == 0) {
DwarfVersion = TC.GetDefaultDwarfVersion();
assert(DwarfVersion && "toolchain default DWARF version must be nonzero");
Expand Down
7 changes: 5 additions & 2 deletions clang/test/CodeGen/dwarf-version.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@
// RUN: FileCheck %s --check-prefix=VER3
// RUN: %clang -target powerpc-ibm-aix-xcoff -gdwarf-4 -S -emit-llvm -o - %s | \
// RUN: FileCheck %s --check-prefix=VER4
// RUN: %clang -target powerpc-ibm-aix-xcoff -gdwarf-5 -S -emit-llvm -o - %s | \
// RUN: FileCheck %s --check-prefix=VER5
// RUN: not %clang -target powerpc-ibm-aix-xcoff -gdwarf-5 -S -emit-llvm -o - %s 2>&1 | \
// RUN: FileCheck %s --check-prefix=UNSUPPORTED-VER5
// RUN: not %clang -target powerpc64-ibm-aix-xcoff -gdwarf-5 -S -emit-llvm -o - %s 2>&1| \
// RUN: FileCheck %s --check-prefix=UNSUPPORTED-VER5

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

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

0 comments on commit b2323f4

Please sign in to comment.