diff options
author | Greg Clayton <gclayton@apple.com> | 2016-06-24 23:48:00 +0000 |
---|---|---|
committer | Greg Clayton <gclayton@apple.com> | 2016-06-24 23:48:00 +0000 |
commit | d7f71add86c892ced324fc26cb0945911f3e26a5 (patch) | |
tree | 9ed27eb7686df44798786a1e5b80a0d9ec5c2e7f | |
parent | 4d32eb6939d77f8059683c008bb807167110e930 (diff) | |
download | bcm5719-llvm-d7f71add86c892ced324fc26cb0945911f3e26a5.tar.gz bcm5719-llvm-d7f71add86c892ced324fc26cb0945911f3e26a5.zip |
Made templates that have Enumeration values as arguments work correctly.
We were checking for integer types only before this. So I added the ability for CompilerType objects to check for integer and enum types.
Then I searched for places that were using the CompilerType::IsIntegerType(...) function. Many of these places also wanted to be checking for enumeration types as well, so I have fixed those places. These are in the ABI plug-ins where we are figuring out which arguments would go in where in regisers/stack when making a function call, or determining where the return value would live. The real fix for this is to use clang to compiler a CGFunctionInfo and then modify the code to be able to take the IR and a calling convention and have the backend answer the questions correctly for us so we don't need to create a really bad copy of the ABI in each plug-in, but that is beyond the scope of this bug fix.
Also added a test case to ensure this doesn't regress in the future.
llvm-svn: 273750
20 files changed, 158 insertions, 44 deletions
diff --git a/lldb/include/lldb/Symbol/ClangASTContext.h b/lldb/include/lldb/Symbol/ClangASTContext.h index 5475a418467..08f7b6b412d 100644 --- a/lldb/include/lldb/Symbol/ClangASTContext.h +++ b/lldb/include/lldb/Symbol/ClangASTContext.h @@ -689,7 +689,10 @@ public: bool IsIntegerType (lldb::opaque_compiler_type_t type, bool &is_signed) override; - + + bool + IsEnumerationType (lldb::opaque_compiler_type_t type, bool &is_signed) override; + static bool IsObjCClassType (const CompilerType& type); diff --git a/lldb/include/lldb/Symbol/CompilerType.h b/lldb/include/lldb/Symbol/CompilerType.h index c2d1d75d5d4..36f6ef3ba6e 100644 --- a/lldb/include/lldb/Symbol/CompilerType.h +++ b/lldb/include/lldb/Symbol/CompilerType.h @@ -153,7 +153,13 @@ public: bool IsIntegerType (bool &is_signed) const; - + + bool + IsEnumerationType (bool &is_signed) const; + + bool + IsIntegerOrEnumerationType (bool &is_signed) const; + bool IsPolymorphicClass () const; diff --git a/lldb/include/lldb/Symbol/TypeSystem.h b/lldb/include/lldb/Symbol/TypeSystem.h index 6b0e73d4217..466699366f0 100644 --- a/lldb/include/lldb/Symbol/TypeSystem.h +++ b/lldb/include/lldb/Symbol/TypeSystem.h @@ -208,7 +208,14 @@ public: virtual bool IsIntegerType (lldb::opaque_compiler_type_t type, bool &is_signed) = 0; - + + virtual bool + IsEnumerationType (lldb::opaque_compiler_type_t type, bool &is_signed) + { + is_signed = false; + return false; + } + virtual bool IsPossibleDynamicType (lldb::opaque_compiler_type_t type, CompilerType *target_type, // Can pass NULL diff --git a/lldb/packages/Python/lldbsuite/test/lang/cpp/template/TestTemplateIntegerArgs.py b/lldb/packages/Python/lldbsuite/test/lang/cpp/template/TestTemplateIntegerArgs.py index 15b18e34f71..0e4c6664930 100644 --- a/lldb/packages/Python/lldbsuite/test/lang/cpp/template/TestTemplateIntegerArgs.py +++ b/lldb/packages/Python/lldbsuite/test/lang/cpp/template/TestTemplateIntegerArgs.py @@ -47,6 +47,7 @@ class TemplateIntegerArgsTestCase(TestBase): testpos = frame.FindVariable('testpos') self.assertTrue(testpos.IsValid(), 'make sure we find a local variabble named "testpos"') self.assertTrue(testpos.GetType().GetName() == 'TestObj<1>') + expr_result = frame.EvaluateExpression("testpos.getArg()") self.assertTrue(expr_result.IsValid(), 'got a valid expression result from expression "testpos.getArg()"'); self.assertTrue(expr_result.GetValue() == "1", "testpos.getArg() == 1") @@ -60,3 +61,23 @@ class TemplateIntegerArgsTestCase(TestBase): self.assertTrue(expr_result.IsValid(), 'got a valid expression result from expression "testneg.getArg()"'); self.assertTrue(expr_result.GetValue() == "-1", "testneg.getArg() == -1") self.assertTrue(expr_result.GetType().GetName() == "int", 'expr_result.GetType().GetName() == "int"') + + # Make sure "member" can be displayed and also used in an expression correctly + member = frame.FindVariable('member') + self.assertTrue(member.IsValid(), 'make sure we find a local variabble named "member"') + self.assertTrue(member.GetType().GetName() == 'EnumTemplate<EnumType::Member>') + + expr_result = frame.EvaluateExpression("member.getMember()") + self.assertTrue(expr_result.IsValid(), 'got a valid expression result from expression "member.getMember()"'); + self.assertTrue(expr_result.GetValue() == "123", "member.getMember() == 123") + self.assertTrue(expr_result.GetType().GetName() == "int", 'expr_result.GetType().GetName() == "int"') + + # Make sure "subclass" can be displayed and also used in an expression correctly + subclass = frame.FindVariable('subclass') + self.assertTrue(subclass.IsValid(), 'make sure we find a local variabble named "subclass"') + self.assertTrue(subclass.GetType().GetName() == 'EnumTemplate<EnumType::Subclass>') + + expr_result = frame.EvaluateExpression("subclass.getMember()") + self.assertTrue(expr_result.IsValid(), 'got a valid expression result from expression "subclass.getMember()"'); + self.assertTrue(expr_result.GetValue() == "246", "subclass.getMember() == 246") + self.assertTrue(expr_result.GetType().GetName() == "int", 'expr_result.GetType().GetName() == "int"') diff --git a/lldb/packages/Python/lldbsuite/test/lang/cpp/template/main.cpp b/lldb/packages/Python/lldbsuite/test/lang/cpp/template/main.cpp index 10a4bec62e9..9c33a642091 100644 --- a/lldb/packages/Python/lldbsuite/test/lang/cpp/template/main.cpp +++ b/lldb/packages/Python/lldbsuite/test/lang/cpp/template/main.cpp @@ -17,9 +17,56 @@ public: } }; +//---------------------------------------------------------------------- +// Define a template class that we can specialize with an enumeration +//---------------------------------------------------------------------- +enum class EnumType +{ + Member, + Subclass +}; + +template <EnumType Arg> class EnumTemplate; + +//---------------------------------------------------------------------- +// Specialization for use when "Arg" is "EnumType::Member" +//---------------------------------------------------------------------- +template <> +class EnumTemplate<EnumType::Member> +{ +public: + EnumTemplate(int m) : + m_member(m) + { + } + + int getMember() const + { + return m_member; + } + +protected: + int m_member; +}; + +//---------------------------------------------------------------------- +// Specialization for use when "Arg" is "EnumType::Subclass" +//---------------------------------------------------------------------- +template <> +class EnumTemplate<EnumType::Subclass> : + public EnumTemplate<EnumType::Member> +{ +public: + EnumTemplate(int m) : EnumTemplate<EnumType::Member>(m) + { + } +}; + int main(int argc, char **argv) { TestObj<1> testpos; TestObj<-1> testneg; - return testpos.getArg() - testneg.getArg(); // Breakpoint 1 + EnumTemplate<EnumType::Member> member(123); + EnumTemplate<EnumType::Subclass> subclass(123*2); + return testpos.getArg() - testneg.getArg() + member.getMember()*2 - subclass.getMember(); // Breakpoint 1 } diff --git a/lldb/source/Plugins/ABI/MacOSX-arm/ABIMacOSX_arm.cpp b/lldb/source/Plugins/ABI/MacOSX-arm/ABIMacOSX_arm.cpp index 36cf718792f..ea906f61389 100644 --- a/lldb/source/Plugins/ABI/MacOSX-arm/ABIMacOSX_arm.cpp +++ b/lldb/source/Plugins/ABI/MacOSX-arm/ABIMacOSX_arm.cpp @@ -341,7 +341,7 @@ ABIMacOSX_arm::GetArgumentValues (Thread &thread, { bool is_signed = false; size_t bit_width = 0; - if (compiler_type.IsIntegerType (is_signed)) + if (compiler_type.IsIntegerOrEnumerationType (is_signed)) { bit_width = compiler_type.GetBitSize(&thread); } @@ -459,7 +459,7 @@ ABIMacOSX_arm::GetReturnValueObjectImpl (Thread &thread, // when reading data const RegisterInfo *r0_reg_info = reg_ctx->GetRegisterInfoByName("r0", 0); - if (compiler_type.IsIntegerType (is_signed)) + if (compiler_type.IsIntegerOrEnumerationType (is_signed)) { size_t bit_width = compiler_type.GetBitSize(&thread); @@ -598,7 +598,7 @@ ABIMacOSX_arm::SetReturnValueObject(lldb::StackFrameSP &frame_sp, lldb::ValueObj RegisterContext *reg_ctx = thread->GetRegisterContext().get(); bool set_it_simple = false; - if (compiler_type.IsIntegerType (is_signed) || compiler_type.IsPointerType()) + if (compiler_type.IsIntegerOrEnumerationType (is_signed) || compiler_type.IsPointerType()) { DataExtractor data; Error data_error; diff --git a/lldb/source/Plugins/ABI/MacOSX-arm64/ABIMacOSX_arm64.cpp b/lldb/source/Plugins/ABI/MacOSX-arm64/ABIMacOSX_arm64.cpp index 72d276aa7a5..ad3d8cb03b8 100644 --- a/lldb/source/Plugins/ABI/MacOSX-arm64/ABIMacOSX_arm64.cpp +++ b/lldb/source/Plugins/ABI/MacOSX-arm64/ABIMacOSX_arm64.cpp @@ -327,7 +327,7 @@ ABIMacOSX_arm64::GetArgumentValues (Thread &thread, ValueList &values) const { bool is_signed = false; size_t bit_width = 0; - if (value_type.IsIntegerType (is_signed)) + if (value_type.IsIntegerOrEnumerationType (is_signed)) { bit_width = value_type.GetBitSize(&thread); } diff --git a/lldb/source/Plugins/ABI/MacOSX-i386/ABIMacOSX_i386.cpp b/lldb/source/Plugins/ABI/MacOSX-i386/ABIMacOSX_i386.cpp index 1a814427bc3..70c7adb8e5b 100644 --- a/lldb/source/Plugins/ABI/MacOSX-i386/ABIMacOSX_i386.cpp +++ b/lldb/source/Plugins/ABI/MacOSX-i386/ABIMacOSX_i386.cpp @@ -315,7 +315,7 @@ ABIMacOSX_i386::GetArgumentValues (Thread &thread, { bool is_signed; - if (compiler_type.IsIntegerType (is_signed)) + if (compiler_type.IsIntegerOrEnumerationType (is_signed)) { ReadIntegerArgument(value->GetScalar(), compiler_type.GetBitSize(&thread), @@ -363,7 +363,7 @@ ABIMacOSX_i386::SetReturnValueObject(lldb::StackFrameSP &frame_sp, lldb::ValueOb RegisterContext *reg_ctx = thread->GetRegisterContext().get(); bool set_it_simple = false; - if (compiler_type.IsIntegerType (is_signed) || compiler_type.IsPointerType()) + if (compiler_type.IsIntegerOrEnumerationType (is_signed) || compiler_type.IsPointerType()) { DataExtractor data; Error data_error; @@ -436,7 +436,7 @@ ABIMacOSX_i386::GetReturnValueObjectImpl (Thread &thread, bool is_signed; - if (compiler_type.IsIntegerType (is_signed)) + if (compiler_type.IsIntegerOrEnumerationType (is_signed)) { size_t bit_width = compiler_type.GetBitSize(&thread); diff --git a/lldb/source/Plugins/ABI/SysV-arm/ABISysV_arm.cpp b/lldb/source/Plugins/ABI/SysV-arm/ABISysV_arm.cpp index 4059e05a969..c23b41c11cc 100644 --- a/lldb/source/Plugins/ABI/SysV-arm/ABISysV_arm.cpp +++ b/lldb/source/Plugins/ABI/SysV-arm/ABISysV_arm.cpp @@ -341,7 +341,7 @@ ABISysV_arm::GetArgumentValues (Thread &thread, { bool is_signed = false; size_t bit_width = 0; - if (compiler_type.IsIntegerType (is_signed)) + if (compiler_type.IsIntegerOrEnumerationType (is_signed)) { bit_width = compiler_type.GetBitSize(&thread); } @@ -463,7 +463,7 @@ ABISysV_arm::GetReturnValueObjectImpl (Thread &thread, size_t bit_width = compiler_type.GetBitSize(&thread); size_t byte_size = compiler_type.GetByteSize(&thread); - if (compiler_type.IsIntegerType (is_signed)) + if (compiler_type.IsIntegerOrEnumerationType (is_signed)) { switch (bit_width) { @@ -775,7 +775,7 @@ ABISysV_arm::SetReturnValueObject(lldb::StackFrameSP &frame_sp, lldb::ValueObjec RegisterContext *reg_ctx = thread->GetRegisterContext().get(); bool set_it_simple = false; - if (compiler_type.IsIntegerType (is_signed) || compiler_type.IsPointerType()) + if (compiler_type.IsIntegerOrEnumerationType (is_signed) || compiler_type.IsPointerType()) { DataExtractor data; Error data_error; diff --git a/lldb/source/Plugins/ABI/SysV-arm64/ABISysV_arm64.cpp b/lldb/source/Plugins/ABI/SysV-arm64/ABISysV_arm64.cpp index 3f2c654f725..e4ed523b9d0 100644 --- a/lldb/source/Plugins/ABI/SysV-arm64/ABISysV_arm64.cpp +++ b/lldb/source/Plugins/ABI/SysV-arm64/ABISysV_arm64.cpp @@ -322,7 +322,7 @@ ABISysV_arm64::GetArgumentValues (Thread &thread, ValueList &values) const { bool is_signed = false; size_t bit_width = 0; - if (value_type.IsIntegerType (is_signed)) + if (value_type.IsIntegerOrEnumerationType (is_signed)) { bit_width = value_type.GetBitSize(&thread); } diff --git a/lldb/source/Plugins/ABI/SysV-i386/ABISysV_i386.cpp b/lldb/source/Plugins/ABI/SysV-i386/ABISysV_i386.cpp index 3c668541627..d23afe9956b 100755 --- a/lldb/source/Plugins/ABI/SysV-i386/ABISysV_i386.cpp +++ b/lldb/source/Plugins/ABI/SysV-i386/ABISysV_i386.cpp @@ -325,7 +325,7 @@ ABISysV_i386::GetArgumentValues (Thread &thread, if (compiler_type) { bool is_signed; - if (compiler_type.IsIntegerType (is_signed)) + if (compiler_type.IsIntegerOrEnumerationType (is_signed)) { ReadIntegerArgument(value->GetScalar(), compiler_type.GetBitSize(&thread), diff --git a/lldb/source/Plugins/ABI/SysV-mips/ABISysV_mips.cpp b/lldb/source/Plugins/ABI/SysV-mips/ABISysV_mips.cpp index 52df7d97117..d6b57f9f393 100644 --- a/lldb/source/Plugins/ABI/SysV-mips/ABISysV_mips.cpp +++ b/lldb/source/Plugins/ABI/SysV-mips/ABISysV_mips.cpp @@ -322,7 +322,7 @@ ABISysV_mips::SetReturnValueObject(lldb::StackFrameSP &frame_sp, lldb::ValueObje RegisterContext *reg_ctx = thread->GetRegisterContext().get(); bool set_it_simple = false; - if (compiler_type.IsIntegerType (is_signed) || compiler_type.IsPointerType()) + if (compiler_type.IsIntegerOrEnumerationType (is_signed) || compiler_type.IsPointerType()) { DataExtractor data; Error data_error; @@ -414,7 +414,7 @@ ABISysV_mips::GetReturnValueObjectImpl (Thread &thread, CompilerType &return_com // In MIPS register "r2" (v0) holds the integer function return values const RegisterInfo *r2_reg_info = reg_ctx->GetRegisterInfoByName("r2", 0); size_t bit_width = return_compiler_type.GetBitSize(&thread); - if (return_compiler_type.IsIntegerType (is_signed)) + if (return_compiler_type.IsIntegerOrEnumerationType (is_signed)) { switch (bit_width) { diff --git a/lldb/source/Plugins/ABI/SysV-mips64/ABISysV_mips64.cpp b/lldb/source/Plugins/ABI/SysV-mips64/ABISysV_mips64.cpp index a301dea2178..f74871544b6 100644 --- a/lldb/source/Plugins/ABI/SysV-mips64/ABISysV_mips64.cpp +++ b/lldb/source/Plugins/ABI/SysV-mips64/ABISysV_mips64.cpp @@ -686,7 +686,7 @@ ABISysV_mips64::GetReturnValueObjectImpl (Thread &thread, CompilerType &return_c uint32_t field_byte_offset = field_bit_offset/8; - if (field_compiler_type.IsIntegerType (is_signed) + if (field_compiler_type.IsIntegerOrEnumerationType (is_signed) || field_compiler_type.IsPointerType () || field_compiler_type.IsFloatingPointType (count, is_complex)) { diff --git a/lldb/source/Plugins/ABI/SysV-ppc/ABISysV_ppc.cpp b/lldb/source/Plugins/ABI/SysV-ppc/ABISysV_ppc.cpp index d88c8bd1561..20ff17d0b76 100644 --- a/lldb/source/Plugins/ABI/SysV-ppc/ABISysV_ppc.cpp +++ b/lldb/source/Plugins/ABI/SysV-ppc/ABISysV_ppc.cpp @@ -403,7 +403,7 @@ ABISysV_ppc::GetArgumentValues (Thread &thread, return false; bool is_signed; - if (compiler_type.IsIntegerType (is_signed)) + if (compiler_type.IsIntegerOrEnumerationType (is_signed)) { ReadIntegerArgument(value->GetScalar(), compiler_type.GetBitSize(&thread), @@ -454,7 +454,7 @@ ABISysV_ppc::SetReturnValueObject(lldb::StackFrameSP &frame_sp, lldb::ValueObjec RegisterContext *reg_ctx = thread->GetRegisterContext().get(); bool set_it_simple = false; - if (compiler_type.IsIntegerType (is_signed) || compiler_type.IsPointerType()) + if (compiler_type.IsIntegerOrEnumerationType (is_signed) || compiler_type.IsPointerType()) { const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoByName("r3", 0); @@ -755,7 +755,7 @@ ABISysV_ppc::GetReturnValueObjectImpl (Thread &thread, CompilerType &return_comp DataExtractor *copy_from_extractor = nullptr; uint32_t copy_from_offset = 0; - if (field_compiler_type.IsIntegerType (is_signed) || field_compiler_type.IsPointerType ()) + if (field_compiler_type.IsIntegerOrEnumerationType (is_signed) || field_compiler_type.IsPointerType ()) { if (integer_bytes < 8) { @@ -819,7 +819,7 @@ ABISysV_ppc::GetReturnValueObjectImpl (Thread &thread, CompilerType &return_comp &next_field_bit_offset, nullptr, nullptr); - if (next_field_compiler_type.IsIntegerType (is_signed)) + if (next_field_compiler_type.IsIntegerOrEnumerationType (is_signed)) in_gpr = true; else { @@ -842,7 +842,7 @@ ABISysV_ppc::GetReturnValueObjectImpl (Thread &thread, CompilerType &return_comp &prev_field_bit_offset, nullptr, nullptr); - if (prev_field_compiler_type.IsIntegerType (is_signed)) + if (prev_field_compiler_type.IsIntegerOrEnumerationType (is_signed)) in_gpr = true; else { diff --git a/lldb/source/Plugins/ABI/SysV-ppc64/ABISysV_ppc64.cpp b/lldb/source/Plugins/ABI/SysV-ppc64/ABISysV_ppc64.cpp index 45e45588d9b..fea847dd17e 100644 --- a/lldb/source/Plugins/ABI/SysV-ppc64/ABISysV_ppc64.cpp +++ b/lldb/source/Plugins/ABI/SysV-ppc64/ABISysV_ppc64.cpp @@ -403,7 +403,7 @@ ABISysV_ppc64::GetArgumentValues (Thread &thread, return false; bool is_signed; - if (compiler_type.IsIntegerType (is_signed)) + if (compiler_type.IsIntegerOrEnumerationType (is_signed)) { ReadIntegerArgument(value->GetScalar(), compiler_type.GetBitSize(&thread), @@ -454,7 +454,7 @@ ABISysV_ppc64::SetReturnValueObject(lldb::StackFrameSP &frame_sp, lldb::ValueObj RegisterContext *reg_ctx = thread->GetRegisterContext().get(); bool set_it_simple = false; - if (compiler_type.IsIntegerType (is_signed) || compiler_type.IsPointerType()) + if (compiler_type.IsIntegerOrEnumerationType (is_signed) || compiler_type.IsPointerType()) { const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoByName("r3", 0); @@ -755,7 +755,7 @@ ABISysV_ppc64::GetReturnValueObjectImpl (Thread &thread, CompilerType &return_co DataExtractor *copy_from_extractor = nullptr; uint32_t copy_from_offset = 0; - if (field_compiler_type.IsIntegerType (is_signed) || field_compiler_type.IsPointerType ()) + if (field_compiler_type.IsIntegerOrEnumerationType (is_signed) || field_compiler_type.IsPointerType ()) { if (integer_bytes < 8) { @@ -820,7 +820,7 @@ ABISysV_ppc64::GetReturnValueObjectImpl (Thread &thread, CompilerType &return_co &next_field_bit_offset, nullptr, nullptr); - if (next_field_compiler_type.IsIntegerType (is_signed)) + if (next_field_compiler_type.IsIntegerOrEnumerationType (is_signed)) in_gpr = true; else { @@ -843,7 +843,7 @@ ABISysV_ppc64::GetReturnValueObjectImpl (Thread &thread, CompilerType &return_co &prev_field_bit_offset, nullptr, nullptr); - if (prev_field_compiler_type.IsIntegerType (is_signed)) + if (prev_field_compiler_type.IsIntegerOrEnumerationType (is_signed)) in_gpr = true; else { diff --git a/lldb/source/Plugins/ABI/SysV-s390x/ABISysV_s390x.cpp b/lldb/source/Plugins/ABI/SysV-s390x/ABISysV_s390x.cpp index ea194a39984..055905523f8 100644 --- a/lldb/source/Plugins/ABI/SysV-s390x/ABISysV_s390x.cpp +++ b/lldb/source/Plugins/ABI/SysV-s390x/ABISysV_s390x.cpp @@ -396,7 +396,7 @@ ABISysV_s390x::GetArgumentValues(Thread &thread, ValueList &values) const return false; bool is_signed; - if (compiler_type.IsIntegerType(is_signed)) + if (compiler_type.IsIntegerOrEnumerationType(is_signed)) { ReadIntegerArgument(value->GetScalar(), compiler_type.GetBitSize(&thread), is_signed, thread, argument_register_ids, current_argument_register, current_stack_argument); @@ -437,7 +437,7 @@ ABISysV_s390x::SetReturnValueObject(lldb::StackFrameSP &frame_sp, lldb::ValueObj RegisterContext *reg_ctx = thread->GetRegisterContext().get(); bool set_it_simple = false; - if (compiler_type.IsIntegerType(is_signed) || compiler_type.IsPointerType()) + if (compiler_type.IsIntegerOrEnumerationType(is_signed) || compiler_type.IsPointerType()) { const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoByName("r2", 0); diff --git a/lldb/source/Plugins/ABI/SysV-x86_64/ABISysV_x86_64.cpp b/lldb/source/Plugins/ABI/SysV-x86_64/ABISysV_x86_64.cpp index 88c614f99ae..136f46a1d25 100644 --- a/lldb/source/Plugins/ABI/SysV-x86_64/ABISysV_x86_64.cpp +++ b/lldb/source/Plugins/ABI/SysV-x86_64/ABISysV_x86_64.cpp @@ -432,7 +432,7 @@ ABISysV_x86_64::GetArgumentValues (Thread &thread, return false; bool is_signed; - if (compiler_type.IsIntegerType (is_signed)) + if (compiler_type.IsIntegerOrEnumerationType (is_signed)) { ReadIntegerArgument(value->GetScalar(), compiler_type.GetBitSize(&thread), @@ -483,7 +483,7 @@ ABISysV_x86_64::SetReturnValueObject(lldb::StackFrameSP &frame_sp, lldb::ValueOb RegisterContext *reg_ctx = thread->GetRegisterContext().get(); bool set_it_simple = false; - if (compiler_type.IsIntegerType (is_signed) || compiler_type.IsPointerType()) + if (compiler_type.IsIntegerOrEnumerationType (is_signed) || compiler_type.IsPointerType()) { const RegisterInfo *reg_info = reg_ctx->GetRegisterInfoByName("rax", 0); @@ -844,7 +844,7 @@ ABISysV_x86_64::GetReturnValueObjectImpl (Thread &thread, CompilerType &return_c DataExtractor *copy_from_extractor = nullptr; uint32_t copy_from_offset = 0; - if (field_compiler_type.IsIntegerType (is_signed) || field_compiler_type.IsPointerType ()) + if (field_compiler_type.IsIntegerOrEnumerationType (is_signed) || field_compiler_type.IsPointerType ()) { if (integer_bytes < 8) { @@ -914,7 +914,7 @@ ABISysV_x86_64::GetReturnValueObjectImpl (Thread &thread, CompilerType &return_c &next_field_bit_offset, nullptr, nullptr); - if (next_field_compiler_type.IsIntegerType (is_signed)) + if (next_field_compiler_type.IsIntegerOrEnumerationType (is_signed)) in_gpr = true; else { @@ -937,7 +937,7 @@ ABISysV_x86_64::GetReturnValueObjectImpl (Thread &thread, CompilerType &return_c &prev_field_bit_offset, nullptr, nullptr); - if (prev_field_compiler_type.IsIntegerType (is_signed)) + if (prev_field_compiler_type.IsIntegerOrEnumerationType (is_signed)) in_gpr = true; else { diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp index 1a7af84803e..c2f53fbb709 100644 --- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp +++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp @@ -1995,8 +1995,7 @@ DWARFASTParserClang::ParseTemplateDIE (const DWARFDIE &die, { DWARFAttributes attributes; const size_t num_attributes = die.GetAttributes (attributes); - const char *name = NULL; - Type *lldb_type = NULL; + const char *name = nullptr; CompilerType clang_type; uint64_t uval64 = 0; bool uval64_valid = false; @@ -2017,7 +2016,7 @@ DWARFASTParserClang::ParseTemplateDIE (const DWARFDIE &die, case DW_AT_type: if (attributes.ExtractFormValueAtIndex(i, form_value)) { - lldb_type = die.ResolveTypeUID(DIERef(form_value)); + Type *lldb_type = die.ResolveTypeUID(DIERef(form_value)); if (lldb_type) clang_type = lldb_type->GetForwardCompilerType (); } @@ -2047,12 +2046,12 @@ DWARFASTParserClang::ParseTemplateDIE (const DWARFDIE &die, else template_param_infos.names.push_back(NULL); - if (tag == DW_TAG_template_value_parameter && - lldb_type != NULL && - clang_type.IsIntegerType (is_signed) && - uval64_valid) + // Get the signed value for any integer or enumeration if available + clang_type.IsIntegerOrEnumerationType (is_signed); + + if (tag == DW_TAG_template_value_parameter && uval64_valid) { - llvm::APInt apint (lldb_type->GetByteSize() * 8, uval64, is_signed); + llvm::APInt apint (clang_type.GetBitSize(nullptr), uval64, is_signed); template_param_infos.args.push_back( clang::TemplateArgument(*ast, llvm::APSInt(apint, !is_signed), ClangUtil::GetQualType(clang_type))); } diff --git a/lldb/source/Symbol/ClangASTContext.cpp b/lldb/source/Symbol/ClangASTContext.cpp index 39cb977ffdc..ad90096d41c 100644 --- a/lldb/source/Symbol/ClangASTContext.cpp +++ b/lldb/source/Symbol/ClangASTContext.cpp @@ -3293,6 +3293,23 @@ ClangASTContext::IsIntegerType (lldb::opaque_compiler_type_t type, bool &is_sign } bool +ClangASTContext::IsEnumerationType(lldb::opaque_compiler_type_t type, bool &is_signed) +{ + if (type) + { + const clang::EnumType *enum_type = llvm::dyn_cast<clang::EnumType>(GetCanonicalQualType(type)->getCanonicalTypeInternal()); + + if (enum_type) + { + IsIntegerType(enum_type->getDecl()->getIntegerType().getAsOpaquePtr(), is_signed); + return true; + } + } + + return false; +} + +bool ClangASTContext::IsPointerType (lldb::opaque_compiler_type_t type, CompilerType *pointee_type) { if (type) diff --git a/lldb/source/Symbol/CompilerType.cpp b/lldb/source/Symbol/CompilerType.cpp index e5be597c146..2b06c93c3f0 100644 --- a/lldb/source/Symbol/CompilerType.cpp +++ b/lldb/source/Symbol/CompilerType.cpp @@ -196,6 +196,20 @@ CompilerType::IsIntegerType (bool &is_signed) const } bool +CompilerType::IsEnumerationType (bool &is_signed) const +{ + if (IsValid()) + return m_type_system->IsEnumerationType(m_type, is_signed); + return false; +} + +bool +CompilerType::IsIntegerOrEnumerationType (bool &is_signed) const +{ + return IsIntegerType(is_signed) || IsEnumerationType(is_signed); +} + +bool CompilerType::IsPointerType (CompilerType *pointee_type) const { if (IsValid()) |