Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 33 additions & 17 deletions llvm/include/llvm/BinaryFormat/Dwarf.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,22 @@ enum LLVMConstants : uint32_t {
DW_ARANGES_VERSION = 2, ///< Section version number for .debug_aranges.
/// \}

/// DWARFv6 DW_AT_language_version constants:
/// https://dwarfstd.org/languages-v6.html
/// \{
DW_LANG_VERSION_C89 = 198912,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what the best naming convention here would be. The DW_LANG_ prefix might get confused with the DW_LANG_ language codes.

DW_LANG_VERSION_C99 = 199901,
DW_LANG_VERSION_C11 = 201112,
DW_LANG_VERSION_C17 = 201710,
DW_LANG_VERSION_C23 = 202311,
DW_LANG_VERSION_C_plus_plus_98 = 199711,
DW_LANG_VERSION_C_plus_plus_11 = 201103,
DW_LANG_VERSION_C_plus_plus_14 = 201402,
DW_LANG_VERSION_C_plus_plus_17 = 201703,
DW_LANG_VERSION_C_plus_plus_20 = 202002,
DW_LANG_VERSION_C_plus_plus_23 = 202302,
/// \}

/// Identifiers we use to distinguish vendor extensions.
/// \{
DWARF_VENDOR_DWARF = 0, ///< Defined in v2 or later of the DWARF standard.
Expand Down Expand Up @@ -246,29 +262,29 @@ inline std::optional<SourceLanguage> toDW_LANG(SourceLanguageName name,
case DW_LNAME_C: // YYYYMM, K&R 000000
if (version == 0)
return DW_LANG_C;
if (version <= 198912)
if (version <= DW_LANG_VERSION_C89)
Copy link
Collaborator

@adrian-prantl adrian-prantl Oct 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about adding a table to Dwarf.def that ties these together, such as:

HANDLE_DW_LANG_VERSION(DW_LANG_C99, "C99", 199901)

?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm how would we be able to re-use it in this function though? Because we're enumerating DW_LNAME_, not DW_LANG_. And DW_LNAME_ doesn't encode versions

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, we would either need one macro per language or a real lookup table. And wether the table lives in code or data doesn't make a huge difference.

return DW_LANG_C89;
if (version <= 199901)
if (version <= DW_LANG_VERSION_C99)
return DW_LANG_C99;
if (version <= 201112)
if (version <= DW_LANG_VERSION_C11)
return DW_LANG_C11;
if (version <= 201710)
if (version <= DW_LANG_VERSION_C17)
return DW_LANG_C17;
return {};
case DW_LNAME_C_plus_plus: // YYYYMM
if (version == 0)
return DW_LANG_C_plus_plus;
if (version <= 199711)
if (version <= DW_LANG_VERSION_C_plus_plus_98)
return DW_LANG_C_plus_plus;
if (version <= 200310)
return DW_LANG_C_plus_plus_03;
if (version <= 201103)
if (version <= DW_LANG_VERSION_C_plus_plus_11)
return DW_LANG_C_plus_plus_11;
if (version <= 201402)
if (version <= DW_LANG_VERSION_C_plus_plus_14)
return DW_LANG_C_plus_plus_14;
if (version <= 201703)
if (version <= DW_LANG_VERSION_C_plus_plus_17)
return DW_LANG_C_plus_plus_17;
if (version <= 202002)
if (version <= DW_LANG_VERSION_C_plus_plus_20)
return DW_LANG_C_plus_plus_20;
return {};
case DW_LNAME_Cobol: // YYYY
Expand Down Expand Up @@ -384,25 +400,25 @@ toDW_LNAME(SourceLanguage language) {
case DW_LANG_C:
return {{DW_LNAME_C, 0}};
case DW_LANG_C89:
return {{DW_LNAME_C, 198912}};
return {{DW_LNAME_C, DW_LANG_VERSION_C89}};
case DW_LANG_C99:
return {{DW_LNAME_C, 199901}};
return {{DW_LNAME_C, DW_LANG_VERSION_C99}};
case DW_LANG_C11:
return {{DW_LNAME_C, 201112}};
return {{DW_LNAME_C, DW_LANG_VERSION_C11}};
case DW_LANG_C17:
return {{DW_LNAME_C, 201710}};
return {{DW_LNAME_C, DW_LANG_VERSION_C17}};
case DW_LANG_C_plus_plus:
return {{DW_LNAME_C_plus_plus, 0}};
case DW_LANG_C_plus_plus_03:
return {{DW_LNAME_C_plus_plus, 200310}};
case DW_LANG_C_plus_plus_11:
return {{DW_LNAME_C_plus_plus, 201103}};
return {{DW_LNAME_C_plus_plus, DW_LANG_VERSION_C_plus_plus_11}};
case DW_LANG_C_plus_plus_14:
return {{DW_LNAME_C_plus_plus, 201402}};
return {{DW_LNAME_C_plus_plus, DW_LANG_VERSION_C_plus_plus_14}};
case DW_LANG_C_plus_plus_17:
return {{DW_LNAME_C_plus_plus, 201703}};
return {{DW_LNAME_C_plus_plus, DW_LANG_VERSION_C_plus_plus_17}};
case DW_LANG_C_plus_plus_20:
return {{DW_LNAME_C_plus_plus, 202002}};
return {{DW_LNAME_C_plus_plus, DW_LANG_VERSION_C_plus_plus_20}};
case DW_LANG_Cobol74:
return {{DW_LNAME_Cobol, 1974}};
case DW_LANG_Cobol85:
Expand Down
18 changes: 9 additions & 9 deletions llvm/lib/BinaryFormat/Dwarf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -513,30 +513,30 @@ StringRef llvm::dwarf::LanguageDescription(dwarf::SourceLanguageName Name,
case DW_LNAME_C: {
if (Version == 0)
break;
if (Version <= 198912)
if (Version <= DW_LANG_VERSION_C89)
return "C89";
if (Version <= 199901)
if (Version <= DW_LANG_VERSION_C99)
return "C99";
if (Version <= 201112)
if (Version <= DW_LANG_VERSION_C11)
return "C11";
if (Version <= 201710)
if (Version <= DW_LANG_VERSION_C17)
return "C17";
} break;

case DW_LNAME_C_plus_plus: {
if (Version == 0)
break;
if (Version <= 199711)
if (Version <= DW_LANG_VERSION_C_plus_plus_98)
return "C++98";
if (Version <= 200310)
return "C++03";
if (Version <= 201103)
if (Version <= DW_LANG_VERSION_C_plus_plus_11)
return "C++11";
if (Version <= 201402)
if (Version <= DW_LANG_VERSION_C_plus_plus_14)
return "C++14";
if (Version <= 201703)
if (Version <= DW_LANG_VERSION_C_plus_plus_17)
return "C++17";
if (Version <= 202002)
if (Version <= DW_LANG_VERSION_C_plus_plus_20)
return "C++20";
} break;

Expand Down
18 changes: 9 additions & 9 deletions llvm/unittests/BinaryFormat/DwarfTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,32 +296,32 @@ LanguageDescriptionTestCase LanguageDescriptionTestCases[] = {
{DW_LNAME_Fortran, 2019, "ISO Fortran"},
{DW_LNAME_C, 0, "C (K&R and ISO)"},
{DW_LNAME_C, 198911, "C89"},
{DW_LNAME_C, 198912, "C89"},
{DW_LNAME_C, 199901, "C99"},
{DW_LNAME_C, DW_LANG_VERSION_C89, "C89"},
{DW_LNAME_C, DW_LANG_VERSION_C99, "C99"},
{DW_LNAME_C, 199902, "C11"},
{DW_LNAME_C, 201111, "C11"},
{DW_LNAME_C, 201112, "C11"},
{DW_LNAME_C, DW_LANG_VERSION_C11, "C11"},
{DW_LNAME_C, 201201, "C17"},
{DW_LNAME_C, 201709, "C17"},
{DW_LNAME_C, 201710, "C17"},
{DW_LNAME_C, DW_LANG_VERSION_C17, "C17"},
{DW_LNAME_C, 201711, "C (K&R and ISO)"},
{DW_LNAME_C_plus_plus, 0, "ISO C++"},
{DW_LNAME_C_plus_plus, 199710, "C++98"},
{DW_LNAME_C_plus_plus, 199711, "C++98"},
{DW_LNAME_C_plus_plus, DW_LANG_VERSION_C_plus_plus_98, "C++98"},
{DW_LNAME_C_plus_plus, 199712, "C++03"},
{DW_LNAME_C_plus_plus, 200310, "C++03"},
{DW_LNAME_C_plus_plus, 200311, "C++11"},
{DW_LNAME_C_plus_plus, 201102, "C++11"},
{DW_LNAME_C_plus_plus, 201103, "C++11"},
{DW_LNAME_C_plus_plus, DW_LANG_VERSION_C_plus_plus_11, "C++11"},
{DW_LNAME_C_plus_plus, 201104, "C++14"},
{DW_LNAME_C_plus_plus, 201401, "C++14"},
{DW_LNAME_C_plus_plus, 201402, "C++14"},
{DW_LNAME_C_plus_plus, DW_LANG_VERSION_C_plus_plus_14, "C++14"},
{DW_LNAME_C_plus_plus, 201403, "C++17"},
{DW_LNAME_C_plus_plus, 201702, "C++17"},
{DW_LNAME_C_plus_plus, 201703, "C++17"},
{DW_LNAME_C_plus_plus, DW_LANG_VERSION_C_plus_plus_17, "C++17"},
{DW_LNAME_C_plus_plus, 201704, "C++20"},
{DW_LNAME_C_plus_plus, 202001, "C++20"},
{DW_LNAME_C_plus_plus, 202002, "C++20"},
{DW_LNAME_C_plus_plus, DW_LANG_VERSION_C_plus_plus_20, "C++20"},
{DW_LNAME_C_plus_plus, 202003, "ISO C++"},
{DW_LNAME_ObjC_plus_plus, 0, LanguageDescription(DW_LNAME_ObjC_plus_plus)},
{DW_LNAME_ObjC_plus_plus, 1, LanguageDescription(DW_LNAME_ObjC_plus_plus)},
Expand Down