Created attachment 19780 [details] C language test case There are a few issue with the representation of enumeration types in the debug info metadata as well as in DWARF. The representation of enumerator values uses a single `int64_t`, which does not convey enough information about the enumerator value. For example, when compiling the attached `e.c`, `clang` encodes the values of `A5` and `A7` wrong in the DWARF debug info: ``` $ clang -c -g e.c && llvm-dwarfdump --debug-info e.o | grep -A1 A[0-9] DW_AT_name ("A0") DW_AT_const_value (-128) -- DW_AT_name ("A1") DW_AT_const_value (255) -- DW_AT_name ("A2") DW_AT_const_value (-32768) -- DW_AT_name ("A3") DW_AT_const_value (65535) -- DW_AT_name ("A4") DW_AT_const_value (-2147483648) -- DW_AT_name ("A5") DW_AT_const_value (-1) -- DW_AT_name ("A6") DW_AT_const_value (-9223372036854775808) -- DW_AT_name ("A7") DW_AT_const_value (-9223372036854775808) ``` Compiling the same program as C++ and using the `-fshort-enums` gets wrong the value of A3 as well: > $ clang -fshort-enums -x c++ -c -g e.c && llvm-dwarfdump --debug-info e.o | grep -A1 A3 > DW_AT_name ("A3") > DW_AT_const_value (-1) > Similar issues are present with C++11 enumerations with a fixed underlying type, e.g. compiling the attached `e.cc`, yields wrong values for `A1`, `A3`, `A5`, and `A7`: ``` $ clang -c -g e.cc && llvm-dwarfdump --debug-info e.o | grep -A1 A[0-9] DW_AT_name ("A0") DW_AT_const_value (-128) -- DW_AT_name ("A1") DW_AT_const_value (-1) -- DW_AT_name ("A2") DW_AT_const_value (-32768) -- DW_AT_name ("A3") DW_AT_const_value (-1) -- DW_AT_name ("A4") DW_AT_const_value (-2147483648) -- DW_AT_name ("A5") DW_AT_const_value (-1) -- DW_AT_name ("A6") DW_AT_const_value (-9223372036854775808) -- DW_AT_name ("A7") DW_AT_const_value (-9223372036854775808) ```
Created attachment 19781 [details] C++ language testcase
A patch for this was committed by OP in r324899 (LLVM) and r324900 (Clang). However, that patch emitted DW_AT_enum_class too often. The difference is: enum Fixed : int { F1 = 1 }; // fixed base type enum class Class { C1 = 1 }; // scoped enum names DW_AT_enum_class should apply only to the second case. Patch at https://reviews.llvm.org/D56393
Fixed by r350636. I'll follow up to rename the flag but the functional part is done.