Return actual type from SBType::GetArrayElementType

SBType::GetArrayElementType should return the actual type, not the
canonical type (e.g. int32_t, not the underlying int).

Added a test case to validate the new behavior. I also ran all other
tests on Linux (ninja check-lldb), they all pass.

Differential revision: https://reviews.llvm.org/D90318
This commit is contained in:
Andy Yankovsky 2020-11-03 10:32:42 -08:00 committed by Jonas Devlieghere
parent 107c3a12d6
commit f35a82384d
3 changed files with 18 additions and 4 deletions

View File

@ -213,10 +213,8 @@ SBType SBType::GetArrayElementType() {
if (!IsValid())
return LLDB_RECORD_RESULT(SBType());
CompilerType canonical_type =
m_opaque_sp->GetCompilerType(true).GetCanonicalType();
return LLDB_RECORD_RESULT(SBType(
TypeImplSP(new TypeImpl(canonical_type.GetArrayElementType(nullptr)))));
return LLDB_RECORD_RESULT(SBType(TypeImplSP(new TypeImpl(
m_opaque_sp->GetCompilerType(true).GetArrayElementType(nullptr)))));
}
SBType SBType::GetArrayType(uint64_t size) {

View File

@ -131,3 +131,16 @@ class TypeAndTypeListTestCase(TestBase):
# (lldb-enumerations.h).
int_type = id_type.GetBasicType(lldb.eBasicTypeInt)
self.assertTrue(id_type == int_type)
# Find 'myint_arr' and check the array element type.
myint_arr = frame0.FindVariable('myint_arr')
self.assertTrue(myint_arr, VALID_VARIABLE)
self.DebugSBValue(myint_arr)
myint_arr_type = myint_arr.GetType()
self.DebugSBType(myint_arr_type)
self.assertTrue(myint_arr_type.IsArrayType())
myint_arr_element_type = myint_arr_type.GetArrayElementType()
self.DebugSBType(myint_arr_element_type)
myint_type = target.FindFirstType('myint')
self.DebugSBType(myint_type)
self.assertTrue(myint_arr_element_type == myint_type)

View File

@ -56,5 +56,8 @@ int main (int argc, char const *argv[])
// This corresponds to an empty task list.
Task *empty_task_head = new Task(-1, NULL);
typedef int myint;
myint myint_arr[] = {1, 2, 3};
return 0; // Break at this line
}