aboutsummaryrefslogtreecommitdiff
path: root/lldb/test
diff options
context:
space:
mode:
authorMichael Buch <michaelbuch12@gmail.com>2022-07-21 01:04:03 +0100
committerMichael Buch <michaelbuch12@gmail.com>2022-07-21 14:23:41 +0100
commit140bcd369b0fd61f19cdeabf4be2fe68d5f9804b (patch)
tree04471c30caeecf4c2e64991e1cbb80ff00a78681 /lldb/test
parent6703812688b84100a159ec793f677952ea8e3eba (diff)
downloadllvm-140bcd369b0fd61f19cdeabf4be2fe68d5f9804b.zip
llvm-140bcd369b0fd61f19cdeabf4be2fe68d5f9804b.tar.gz
llvm-140bcd369b0fd61f19cdeabf4be2fe68d5f9804b.tar.bz2
[LLDB][ClangExpression] Fix initialization of static enum alias members
`IntegerLiteral::Create` operates on integer types. For that reason when we parse DWARF into an AST, when we encounter a constant initialized enum member variable, we try to determine the underlying integer type before creating the `IntegerLiteral`. However, we currently don't desugar the type and for enum typedefs `dyn_cast<EnumType>` fails. In debug builds this triggers following assert: ``` Assertion failed: (type->isIntegerType() && "Illegal type in IntegerLiteral"), function IntegerLiteral, file Expr.cpp, line 892 ``` This patch turns the `dyn_cast<EnumType>` into a `getAs<EnumType>` which `dyn_cast`s the canonical type, allowing us to get to the underlying integer type. **Testing** * API test * Manual repro is fixed Differential Revision: https://reviews.llvm.org/D130213
Diffstat (limited to 'lldb/test')
-rw-r--r--lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py6
-rw-r--r--lldb/test/API/lang/cpp/const_static_integral_member/main.cpp13
2 files changed, 19 insertions, 0 deletions
diff --git a/lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py b/lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py
index c2bf1fe..09345b9 100644
--- a/lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py
+++ b/lldb/test/API/lang/cpp/const_static_integral_member/TestConstStaticIntegralMember.py
@@ -66,6 +66,12 @@ class TestCase(TestBase):
self.expect_expr("A::scoped_ll_enum_val_neg", result_value="case0")
self.expect_expr("A::scoped_ll_enum_val", result_value="case2")
+ # Test an aliased enum with fixed underlying type.
+ self.expect_expr("ClassWithEnumAlias::enum_alias",
+ result_value="scoped_enum_case2")
+ self.expect_expr("ClassWithEnumAlias::enum_alias_alias",
+ result_value="scoped_enum_case1")
+
# Test taking address.
if lldbplatformutil.getPlatform() == "windows":
# On Windows data members without the out-of-class definitions still have
diff --git a/lldb/test/API/lang/cpp/const_static_integral_member/main.cpp b/lldb/test/API/lang/cpp/const_static_integral_member/main.cpp
index 9762424..b262513 100644
--- a/lldb/test/API/lang/cpp/const_static_integral_member/main.cpp
+++ b/lldb/test/API/lang/cpp/const_static_integral_member/main.cpp
@@ -69,6 +69,15 @@ struct ClassWithConstexprs {
constexpr static ScopedEnum scoped_enum_val = ScopedEnum::scoped_enum_case2;
} cwc;
+struct ClassWithEnumAlias {
+ using EnumAlias = ScopedEnum;
+ static constexpr EnumAlias enum_alias = ScopedEnum::scoped_enum_case2;
+
+ using EnumAliasAlias = EnumAlias;
+ static constexpr EnumAliasAlias enum_alias_alias =
+ ScopedEnum::scoped_enum_case1;
+};
+
int main() {
A a;
@@ -98,5 +107,9 @@ int main() {
se = A::invalid_scoped_enum_val;
ScopedCharEnum sce = A::scoped_char_enum_val;
ScopedLongLongEnum sle = A::scoped_ll_enum_val;
+
+ auto enum_alias_val = ClassWithEnumAlias::enum_alias;
+ auto enum_alias_alias_val = ClassWithEnumAlias::enum_alias_alias;
+
return 0; // break here
}