Skip to content

Commit c73876d

Browse files
committed
Reapply "DebugInfo: Add/support new DW_LANG codes for recent C and C++ versions""
This may be a breaking change for consumers if they're trying to detect if code is C or C++, since it'll start using new codes that they may not be ready to recognize, in which case they may fall back to non-C handling. This caused regressions due to PS4 having a different default for C language version than other targets. Those tests were adapted to be relaxed about which C version is used. This reapplies commit 3c312e4 Which was reverted by commit 6ab6085. Differential Revision: https://reviews.llvm.org/D138597
1 parent 512a98e commit c73876d

File tree

5 files changed

+41
-7
lines changed

5 files changed

+41
-7
lines changed

clang/lib/CodeGen/CGDebugInfo.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,8 @@ void CGDebugInfo::CreateCompileUnit() {
526526

527527
// Get absolute path name.
528528
SourceManager &SM = CGM.getContext().getSourceManager();
529-
std::string MainFileName = CGM.getCodeGenOpts().MainFileName;
529+
auto &CGO = CGM.getCodeGenOpts();
530+
std::string MainFileName = CGO.MainFileName;
530531
if (MainFileName.empty())
531532
MainFileName = "<stdin>";
532533

@@ -562,11 +563,11 @@ void CGDebugInfo::CreateCompileUnit() {
562563
if (LO.CPlusPlus) {
563564
if (LO.ObjC)
564565
LangTag = llvm::dwarf::DW_LANG_ObjC_plus_plus;
565-
else if (LO.CPlusPlus14 && (!CGM.getCodeGenOpts().DebugStrictDwarf ||
566-
CGM.getCodeGenOpts().DwarfVersion >= 5))
566+
else if (CGO.DebugStrictDwarf && CGO.DwarfVersion < 5)
567+
LangTag = llvm::dwarf::DW_LANG_C_plus_plus;
568+
else if (LO.CPlusPlus14)
567569
LangTag = llvm::dwarf::DW_LANG_C_plus_plus_14;
568-
else if (LO.CPlusPlus11 && (!CGM.getCodeGenOpts().DebugStrictDwarf ||
569-
CGM.getCodeGenOpts().DwarfVersion >= 5))
570+
else if (LO.CPlusPlus11)
570571
LangTag = llvm::dwarf::DW_LANG_C_plus_plus_11;
571572
else
572573
LangTag = llvm::dwarf::DW_LANG_C_plus_plus;
@@ -577,6 +578,8 @@ void CGDebugInfo::CreateCompileUnit() {
577578
LangTag = llvm::dwarf::DW_LANG_OpenCL;
578579
} else if (LO.RenderScript) {
579580
LangTag = llvm::dwarf::DW_LANG_GOOGLE_RenderScript;
581+
} else if (LO.C11) {
582+
LangTag = llvm::dwarf::DW_LANG_C11;
580583
} else if (LO.C99) {
581584
LangTag = llvm::dwarf::DW_LANG_C99;
582585
} else {

clang/test/CodeGen/debug-info-preprocessed-file.i

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,5 @@
77
# 1 "preprocessed-input.c" 2
88

99
// RUN: %clang -g -c -S -emit-llvm -o - %s | FileCheck %s
10-
// CHECK: !DICompileUnit(language: DW_LANG_C99, file: ![[FILE:[0-9]+]]
10+
// CHECK: !DICompileUnit(language: DW_LANG_C{{.*}}, file: ![[FILE:[0-9]+]]
1111
// CHECK: ![[FILE]] = !DIFile(filename: "/foo/bar/preprocessed-input.c"
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// RUN: %clang_cc1 -dwarf-version=3 -emit-llvm -triple %itanium_abi_triple %s -o - \
2+
// RUN: -x c -std=c11 -O0 -disable-llvm-passes -debug-info-kind=limited \
3+
// RUN: | FileCheck --check-prefix=CHECK-C11 %s
4+
// RUN: %clang_cc1 -dwarf-version=3 -emit-llvm -triple %itanium_abi_triple %s -o - \
5+
// RUN: -x c -std=c17 -O0 -disable-llvm-passes -debug-info-kind=limited \
6+
// RUN: | FileCheck --check-prefix=CHECK-C17 %s
7+
8+
// CHECK-C11: !DICompileUnit(language: DW_LANG_C11
9+
// Update this check once support for DW_LANG_C17 is broadly supported/known in
10+
// consumers. Maybe we'll skip this and go to the DWARFv6 language+version
11+
// encoding that avoids the risk of regression when describing a language
12+
// version newer than what the consumer is aware of.
13+
// CHECK-C17: !DICompileUnit(language: DW_LANG_C11
14+
15+
void f1(void) { }

clang/test/CodeGenCXX/debug-info-programming-language.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@
44
// RUN: %clang_cc1 -dwarf-version=3 -emit-llvm -triple %itanium_abi_triple %s -o - \
55
// RUN: -x c++ -std=c++14 -O0 -disable-llvm-passes -debug-info-kind=limited \
66
// RUN: | FileCheck --check-prefix=CHECK-CPP14 %s
7+
// RUN: %clang_cc1 -dwarf-version=3 -emit-llvm -triple %itanium_abi_triple %s -o - \
8+
// RUN: -x c++ -std=c++17 -O0 -disable-llvm-passes -debug-info-kind=limited \
9+
// RUN: | FileCheck --check-prefix=CHECK-CPP17 %s
10+
// RUN: %clang_cc1 -dwarf-version=3 -emit-llvm -triple %itanium_abi_triple %s -o - \
11+
// RUN: -x c++ -std=c++20 -O0 -disable-llvm-passes -debug-info-kind=limited \
12+
// RUN: | FileCheck --check-prefix=CHECK-CPP20 %s
713
// RUN: %clang_cc1 -dwarf-version=3 -gstrict-dwarf -emit-llvm -triple %itanium_abi_triple %s -o - \
814
// RUN: -x c++ -std=c++14 -O0 -disable-llvm-passes -debug-info-kind=limited | FileCheck %s
915
// RUN: %clang_cc1 -dwarf-version=5 -gstrict-dwarf -emit-llvm -triple %itanium_abi_triple %s -o - \
@@ -14,5 +20,15 @@ int main() {
1420
return 0;
1521
}
1622

23+
// Update these tests once support for DW_LANG_C_plus_plus_17/20 is added - it's
24+
// a complicated tradeoff. The language codes are already published/blessed by
25+
// the DWARF committee, but haven't been released in a published standard yet,
26+
// so consumers might not be ready for these codes & could regress functionality
27+
// (because they wouldn't be able to identify that the language was C++). The
28+
// DWARFv6 language encoding, separating language from language version, would
29+
// remove this problem/not require new codes for new language versions and make
30+
// it possible to identify the base language irrespective of the version.
1731
// CHECK-CPP14: distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14,
32+
// CHECK-CPP17: distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14,
33+
// CHECK-CPP20: distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14,
1834
// CHECK: distinct !DICompileUnit(language: DW_LANG_C_plus_plus,

clang/test/PCH/debug-info-pch-container-path.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
// RUN: cat %t-container.ll | FileCheck %s
1515

1616
// CHECK: distinct !DICompileUnit(
17-
// CHECK-SAME: language: DW_LANG_C99,
17+
// CHECK-SAME: language: DW_LANG_C{{[^,]*}},
1818
// CHECK-SAME: file: ![[FILE:[0-9]+]],
1919
// CHECK: ![[FILE]] = !DIFile(
2020
// CHECK-SAME: filename: "SOURCE/debug-info-limited-struct.h",

0 commit comments

Comments
 (0)