diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp --- a/clang/lib/CodeGen/CGDebugInfo.cpp +++ b/clang/lib/CodeGen/CGDebugInfo.cpp @@ -526,7 +526,8 @@ // Get absolute path name. SourceManager &SM = CGM.getContext().getSourceManager(); - std::string MainFileName = CGM.getCodeGenOpts().MainFileName; + auto &CGO = CGM.getCodeGenOpts(); + std::string MainFileName = CGO.MainFileName; if (MainFileName.empty()) MainFileName = ""; @@ -562,11 +563,11 @@ if (LO.CPlusPlus) { if (LO.ObjC) LangTag = llvm::dwarf::DW_LANG_ObjC_plus_plus; - else if (LO.CPlusPlus14 && (!CGM.getCodeGenOpts().DebugStrictDwarf || - CGM.getCodeGenOpts().DwarfVersion >= 5)) + else if (CGO.DebugStrictDwarf && CGO.DwarfVersion < 5) + LangTag = llvm::dwarf::DW_LANG_C_plus_plus; + else if (LO.CPlusPlus14) LangTag = llvm::dwarf::DW_LANG_C_plus_plus_14; - else if (LO.CPlusPlus11 && (!CGM.getCodeGenOpts().DebugStrictDwarf || - CGM.getCodeGenOpts().DwarfVersion >= 5)) + else if (LO.CPlusPlus11) LangTag = llvm::dwarf::DW_LANG_C_plus_plus_11; else LangTag = llvm::dwarf::DW_LANG_C_plus_plus; @@ -577,6 +578,8 @@ LangTag = llvm::dwarf::DW_LANG_OpenCL; } else if (LO.RenderScript) { LangTag = llvm::dwarf::DW_LANG_GOOGLE_RenderScript; + } else if (LO.C11) { + LangTag = llvm::dwarf::DW_LANG_C11; } else if (LO.C99) { LangTag = llvm::dwarf::DW_LANG_C99; } else { diff --git a/clang/test/CodeGen/debug-info-preprocessed-file.i b/clang/test/CodeGen/debug-info-preprocessed-file.i --- a/clang/test/CodeGen/debug-info-preprocessed-file.i +++ b/clang/test/CodeGen/debug-info-preprocessed-file.i @@ -7,5 +7,5 @@ # 1 "preprocessed-input.c" 2 // RUN: %clang -g -c -S -emit-llvm -o - %s | FileCheck %s -// CHECK: !DICompileUnit(language: DW_LANG_C99, file: ![[FILE:[0-9]+]] +// CHECK: !DICompileUnit(language: DW_LANG_C{{.*}}, file: ![[FILE:[0-9]+]] // CHECK: ![[FILE]] = !DIFile(filename: "/foo/bar/preprocessed-input.c" diff --git a/clang/test/CodeGen/debug-info-programming-language.c b/clang/test/CodeGen/debug-info-programming-language.c new file mode 100644 --- /dev/null +++ b/clang/test/CodeGen/debug-info-programming-language.c @@ -0,0 +1,15 @@ +// RUN: %clang_cc1 -dwarf-version=3 -emit-llvm -triple %itanium_abi_triple %s -o - \ +// RUN: -x c -std=c11 -O0 -disable-llvm-passes -debug-info-kind=limited \ +// RUN: | FileCheck --check-prefix=CHECK-C11 %s +// RUN: %clang_cc1 -dwarf-version=3 -emit-llvm -triple %itanium_abi_triple %s -o - \ +// RUN: -x c -std=c17 -O0 -disable-llvm-passes -debug-info-kind=limited \ +// RUN: | FileCheck --check-prefix=CHECK-C17 %s + +// CHECK-C11: !DICompileUnit(language: DW_LANG_C11 +// Update this check once support for DW_LANG_C17 is broadly supported/known in +// consumers. Maybe we'll skip this and go to the DWARFv6 language+version +// encoding that avoids the risk of regression when describing a language +// version newer than what the consumer is aware of. +// CHECK-C17: !DICompileUnit(language: DW_LANG_C11 + +void f1(void) { } diff --git a/clang/test/CodeGenCXX/debug-info-programming-language.cpp b/clang/test/CodeGenCXX/debug-info-programming-language.cpp --- a/clang/test/CodeGenCXX/debug-info-programming-language.cpp +++ b/clang/test/CodeGenCXX/debug-info-programming-language.cpp @@ -4,6 +4,12 @@ // RUN: %clang_cc1 -dwarf-version=3 -emit-llvm -triple %itanium_abi_triple %s -o - \ // RUN: -x c++ -std=c++14 -O0 -disable-llvm-passes -debug-info-kind=limited \ // RUN: | FileCheck --check-prefix=CHECK-CPP14 %s +// RUN: %clang_cc1 -dwarf-version=3 -emit-llvm -triple %itanium_abi_triple %s -o - \ +// RUN: -x c++ -std=c++17 -O0 -disable-llvm-passes -debug-info-kind=limited \ +// RUN: | FileCheck --check-prefix=CHECK-CPP17 %s +// RUN: %clang_cc1 -dwarf-version=3 -emit-llvm -triple %itanium_abi_triple %s -o - \ +// RUN: -x c++ -std=c++20 -O0 -disable-llvm-passes -debug-info-kind=limited \ +// RUN: | FileCheck --check-prefix=CHECK-CPP20 %s // RUN: %clang_cc1 -dwarf-version=3 -gstrict-dwarf -emit-llvm -triple %itanium_abi_triple %s -o - \ // RUN: -x c++ -std=c++14 -O0 -disable-llvm-passes -debug-info-kind=limited | FileCheck %s // RUN: %clang_cc1 -dwarf-version=5 -gstrict-dwarf -emit-llvm -triple %itanium_abi_triple %s -o - \ @@ -14,5 +20,15 @@ return 0; } +// Update these tests once support for DW_LANG_C_plus_plus_17/20 is added - it's +// a complicated tradeoff. The language codes are already published/blessed by +// the DWARF committee, but haven't been released in a published standard yet, +// so consumers might not be ready for these codes & could regress functionality +// (because they wouldn't be able to identify that the language was C++). The +// DWARFv6 language encoding, separating language from language version, would +// remove this problem/not require new codes for new language versions and make +// it possible to identify the base language irrespective of the version. // CHECK-CPP14: distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, +// CHECK-CPP17: distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, +// CHECK-CPP20: distinct !DICompileUnit(language: DW_LANG_C_plus_plus_14, // CHECK: distinct !DICompileUnit(language: DW_LANG_C_plus_plus, diff --git a/clang/test/PCH/debug-info-pch-container-path.c b/clang/test/PCH/debug-info-pch-container-path.c --- a/clang/test/PCH/debug-info-pch-container-path.c +++ b/clang/test/PCH/debug-info-pch-container-path.c @@ -14,7 +14,7 @@ // RUN: cat %t-container.ll | FileCheck %s // CHECK: distinct !DICompileUnit( -// CHECK-SAME: language: DW_LANG_C99, +// CHECK-SAME: language: DW_LANG_C{{[^,]*}}, // CHECK-SAME: file: ![[FILE:[0-9]+]], // CHECK: ![[FILE]] = !DIFile( // CHECK-SAME: filename: "SOURCE/debug-info-limited-struct.h",