LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 36168 - [DebugInfo] Wrong representation of enumerator values in debug info metadata
Summary: [DebugInfo] Wrong representation of enumerator values in debug info metadata
Status: RESOLVED FIXED
Alias: None
Product: clang
Classification: Unclassified
Component: LLVM Codegen (show other bugs)
Version: trunk
Hardware: PC Linux
: P normal
Assignee: Momchil Velikov
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-01-31 06:05 PST by Momchil Velikov
Modified: 2019-01-08 08:31 PST (History)
4 users (show)

See Also:
Fixed By Commit(s): 350636


Attachments
C language test case (345 bytes, text/x-csrc)
2018-01-31 06:05 PST, Momchil Velikov
Details
C++ language testcase (475 bytes, text/x-c++src)
2018-01-31 06:06 PST, Momchil Velikov
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Momchil Velikov 2018-01-31 06:05:32 PST
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)
```
Comment 1 Momchil Velikov 2018-01-31 06:06:03 PST
Created attachment 19781 [details]
C++ language testcase
Comment 2 Paul Robinson 2019-01-07 09:01:23 PST
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
Comment 3 Paul Robinson 2019-01-08 08:31:42 PST
Fixed by r350636.  I'll follow up to rename the flag but the functional
part is done.