[Lldb-commits] [lldb] [lldb] Mark enum types as scalar in clang typesystem (PR #192711)
via lldb-commits
lldb-commits at lists.llvm.org
Fri Apr 17 11:43:32 PDT 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-lldb
Author: Ebuka Ezike (da-viper)
<details>
<summary>Changes</summary>
This is to differentiate enums in other languages that has non scalar enums.
---
Full diff: https://github.com/llvm/llvm-project/pull/192711.diff
4 Files Affected:
- (modified) lldb/source/Plugins/TypeSystem/Clang/TypeSystemClang.cpp (+1-1)
- (modified) lldb/source/ValueObject/ValueObject.cpp (+1-1)
- (modified) lldb/test/API/lang/c/enum_types/TestEnumTypes.py (+3)
- (modified) lldb/unittests/Symbol/TestTypeSystemClang.cpp (+4)
``````````diff
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());
}
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/192711
More information about the lldb-commits
mailing list