[Lldb-commits] [lldb] [lldb] Mark enum types as scalar in clang typesystem (PR #192711)

Ebuka Ezike via lldb-commits lldb-commits at lists.llvm.org
Fri Apr 17 11:42:59 PDT 2026


https://github.com/da-viper created https://github.com/llvm/llvm-project/pull/192711

This is to differentiate enums in other languages that has non scalar enums.

>From 3346383b5feceb9bc4ee4741b0941012c4418096 Mon Sep 17 00:00:00 2001
From: Ebuka Ezike <yerimyah1 at gmail.com>
Date: Fri, 17 Apr 2026 19:32:36 +0100
Subject: [PATCH] [lldb] Mark enumeration types as scalar in clang typesystem

This is to differenciate enums in other languages
that has non scalar enums.
---
 lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp | 2 +-
 lldb/source/ValueObject/ValueObject.cpp                  | 2 +-
 lldb/test/API/lang/c/enum_types/TestEnumTypes.py         | 3 +++
 lldb/unittests/Symbol/TestTypeSystemClang.cpp            | 4 ++++
 4 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
index e63d247c01d11..f3ec92ad34b45 100644
--- a/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
+++ b/lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp
@@ -3909,7 +3909,7 @@ TypeSystemClang::GetTypeInfo(lldb::opaque_compiler_type_t type,
                                 ->getDefinitionOrSelf()
                                 ->getIntegerType()
                                 .getAsOpaquePtr());
-    return eTypeIsEnumeration | eTypeHasValue;
+    return eTypeIsEnumeration | eTypeHasValue | eTypeIsScalar;
 
   case clang::Type::FunctionProto:
     return eTypeIsFuncPrototype | eTypeHasValue;
diff --git a/lldb/source/ValueObject/ValueObject.cpp b/lldb/source/ValueObject/ValueObject.cpp
index 6a12a2e45b2e1..5eb91a8029035 100644
--- a/lldb/source/ValueObject/ValueObject.cpp
+++ b/lldb/source/ValueObject/ValueObject.cpp
@@ -3202,7 +3202,7 @@ lldb::ValueObjectSP ValueObject::CastToBasicType(CompilerType type) {
   }
 
   if (type.IsInteger()) {
-    if (!is_scalar || is_integer) {
+    if ((is_enum && is_scalar) || !is_scalar || is_integer) {
       auto int_value_or_err = GetValueAsAPSInt();
       if (int_value_or_err) {
         // Get the value as APSInt and extend or truncate it to the requested
diff --git a/lldb/test/API/lang/c/enum_types/TestEnumTypes.py b/lldb/test/API/lang/c/enum_types/TestEnumTypes.py
index d4bbe9bcfac81..6ce651d3b4738 100644
--- a/lldb/test/API/lang/c/enum_types/TestEnumTypes.py
+++ b/lldb/test/API/lang/c/enum_types/TestEnumTypes.py
@@ -151,6 +151,9 @@ def check_enum_members(self, members):
             self.assertEqual(
                 member.signed, value_matches[idx], "Value matches for %d" % (idx)
             )
+            member_type_flags = member.GetType().GetTypeFlags()
+            is_scalar = (member_type_flags & lldb.eTypeIsScalar) == lldb.eTypeIsScalar
+            self.assertTrue(is_scalar, f"expects enum: {member.name} is a scalar value")
 
     def test_api(self):
         """Test that the SBTypeEnumMember API's work correctly for enum_test_days"""
diff --git a/lldb/unittests/Symbol/TestTypeSystemClang.cpp b/lldb/unittests/Symbol/TestTypeSystemClang.cpp
index 2b5c8f6e14048..f4077897ee278 100644
--- a/lldb/unittests/Symbol/TestTypeSystemClang.cpp
+++ b/lldb/unittests/Symbol/TestTypeSystemClang.cpp
@@ -463,6 +463,7 @@ TEST_F(TestTypeSystemClang, TestIsEnumerationType) {
     EXPECT_TRUE(enum_type.IsEnumerationType(is_signed));
     EXPECT_TRUE(is_signed);
     EXPECT_FALSE(enum_type.IsIntegerType(is_signed));
+    EXPECT_TRUE(enum_type.IsScalarType());
   }
 
   // Scoped unsigned enum
@@ -477,6 +478,7 @@ TEST_F(TestTypeSystemClang, TestIsEnumerationType) {
     EXPECT_TRUE(enum_type.IsEnumerationType(is_signed));
     EXPECT_FALSE(is_signed);
     EXPECT_FALSE(enum_type.IsIntegerType(is_signed));
+    EXPECT_TRUE(enum_type.IsScalarType());
   }
 
   // Unscoped signed enum
@@ -491,6 +493,7 @@ TEST_F(TestTypeSystemClang, TestIsEnumerationType) {
     EXPECT_TRUE(enum_type.IsEnumerationType(is_signed));
     EXPECT_TRUE(is_signed);
     EXPECT_FALSE(enum_type.IsIntegerType(is_signed));
+    EXPECT_TRUE(enum_type.IsScalarType());
   }
 
   // Unscoped unsigned enum
@@ -505,6 +508,7 @@ TEST_F(TestTypeSystemClang, TestIsEnumerationType) {
     EXPECT_TRUE(enum_type.IsEnumerationType(is_signed));
     EXPECT_FALSE(is_signed);
     EXPECT_FALSE(enum_type.IsIntegerType(is_signed));
+    EXPECT_TRUE(enum_type.IsScalarType());
   }
 }
 



More information about the lldb-commits mailing list