[Lldb-commits] [PATCH] D137793: [lldb][test] TestConstStaticIntegralMember.py: fix for clang-{9, 11, 13}

Michael Buch via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Thu Nov 10 10:56:05 PST 2022


Michael137 created this revision.
Michael137 added a reviewer: aeubanks.
Herald added a subscriber: kristof.beyls.
Herald added a project: All.
Michael137 requested review of this revision.
Herald added a project: LLDB.
Herald added a subscriber: lldb-commits.

**Summary**

The public lldb matrix bot is failing for tests compiled with clang-9, clang-11, clang-13.

This patch addresses these failures by evaluating the enum case that
doesn't cause malformed DWARF in older version of clang.

There was no particular reason we had to use `true` enum case
to reproduce the bug in #58383, so simply switch to use `false`
to get all bots passing again.

**Details**

In older versions of clang, the following snippet:

  enum EnumBool : bool {
    enum_bool_case1 = false,
    enum_bool_case2 = true,
  };
  
  struct A {
    const static EnumBool enum_bool_val = enum_bool_case2;
  };

…results in following DWARF:

  0x00000052:   DW_TAG_structure_type
                  DW_AT_calling_convention        (DW_CC_pass_by_value)
                  DW_AT_name      ("A")
                  DW_AT_byte_size (0x01)
                  DW_AT_decl_file ("/Users/michaelbuch/Git/llvm-project/lldb/test/API/lang/cpp/const_static_integral_member/repro.cpp")
                  DW_AT_decl_line (6)
  
  0x0000005b:     DW_TAG_member
                    DW_AT_name    ("enum_bool_val")
                    DW_AT_type    (0x0000000000000068 "const EnumBool")
                    DW_AT_decl_file       ("/Users/michaelbuch/Git/llvm-project/lldb/test/API/lang/cpp/const_static_integral_member/repro.cpp")
                    DW_AT_decl_line       (7)
                    DW_AT_external        (true)
                    DW_AT_declaration     (true)
                    DW_AT_const_value     (-1)

Note the `DW_AT_const_value == -1`

When evaluating `A::enum_bool_val` in the lldb we get:

  (lldb) p A::enum_bool_val
  error: expression failed to parse:
  error: Couldn't lookup symbols:
    __ZN1A13enum_bool_valE

Enabling the DWARF logs we see:

  (arm64) clang-13.out: DWARFASTParserClang::ParseTypeFromDWARF (die = 0x00000068, decl_ctx = 0x136ac1e30 (die 0x0000000b)) DW_TAG_const_type name = '(null)')
  Failed to add const value to variable A::enum_bool_val: Can't store unsigned value 18446744073709551615 in integer with 1 bits.

This occurs because a boolean enum is considered an unsigned integer
type, but we try to initialize it with a `-1`.

**Testing**

- Confirmed locally that top-of-tree lldb correctly evaluates the previously failing expression when the test program is compiled with clang-13


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137793

Files:
  lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py
  lldb/test/API/lang/cpp/const_static_integral_member/main.cpp


Index: lldb/test/API/lang/cpp/const_static_integral_member/main.cpp
===================================================================
--- lldb/test/API/lang/cpp/const_static_integral_member/main.cpp
+++ lldb/test/API/lang/cpp/const_static_integral_member/main.cpp
@@ -56,7 +56,7 @@
   const static auto wchar_min = std::numeric_limits<wchar_t>::min();
 
   const static Enum enum_val = enum_case2;
-  const static EnumBool enum_bool_val = enum_bool_case2;
+  const static EnumBool enum_bool_val = enum_bool_case1;
   const static ScopedEnum scoped_enum_val = ScopedEnum::scoped_enum_case2;
   const static ScopedEnum not_enumerator_scoped_enum_val = static_cast<ScopedEnum>(5);
   const static ScopedEnum not_enumerator_scoped_enum_val_2 =
Index: lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py
===================================================================
--- lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py
+++ lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py
@@ -58,7 +58,7 @@
         # Test an unscoped enum.
         self.expect_expr("A::enum_val", result_value="enum_case2")
         # Test an unscoped enum with bool as the underlying type.
-        self.expect_expr("A::enum_bool_val", result_value="enum_bool_case2")
+        self.expect_expr("A::enum_bool_val", result_value="enum_bool_case1")
 
         # Test a scoped enum.
         self.expect_expr("A::scoped_enum_val", result_value="scoped_enum_case2")


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D137793.474576.patch
Type: text/x-patch
Size: 1538 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20221110/94c5e800/attachment.bin>


More information about the lldb-commits mailing list