[Lldb-commits] [PATCH] D137045: [lldb] Don't crash when printing static enum members with bool as underlying type

Arthur Eubanks via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Sun Oct 30 12:45:39 PDT 2022


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

Extends D135169 <https://reviews.llvm.org/D135169> to work with enums with bool as the underlying type.

Fixes #58383.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137045

Files:
  lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
  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
@@ -5,6 +5,11 @@
   enum_case2 = 2,
 };
 
+enum EnumBool : bool {
+  enum_bool_case1 = false,
+  enum_bool_case2 = true,
+};
+
 enum class ScopedEnum {
   scoped_enum_case1 = 1,
   scoped_enum_case2 = 2,
@@ -51,6 +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 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
@@ -57,6 +57,8 @@
 
         # 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")
 
         # Test a scoped enum.
         self.expect_expr("A::scoped_enum_val", result_value="scoped_enum_case2")
Index: lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
===================================================================
--- lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -3234,6 +3234,14 @@
   const clang::BuiltinType *builtin_type =
       llvm::dyn_cast<clang::BuiltinType>(qual_type->getCanonicalTypeInternal());
 
+  if (!builtin_type) {
+    if (const clang::EnumType *enum_type = llvm::dyn_cast<clang::EnumType>(
+            qual_type->getCanonicalTypeInternal())) {
+      builtin_type = llvm::dyn_cast<clang::BuiltinType>(
+          enum_type->getDecl()->getIntegerType());
+    }
+  }
+
   if (!builtin_type)
     return false;
 
@@ -7597,7 +7605,11 @@
   assert(!var->hasInit() && "variable already initialized");
 
   QualType qt = var->getType();
-  assert(qt->isSpecificBuiltinType(BuiltinType::Bool) &&
+  assert((qt->isSpecificBuiltinType(BuiltinType::Bool) ||
+          cast<clang::EnumType>(qt)
+              ->getDecl()
+              ->getIntegerType()
+              ->isSpecificBuiltinType(BuiltinType::Bool)) &&
          "only boolean supported");
 
   clang::ASTContext &ast = var->getASTContext();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D137045.471856.patch
Type: text/x-patch
Size: 2822 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20221030/9bcfbe9b/attachment.bin>


More information about the lldb-commits mailing list