[Lldb-commits] [lldb] r205782 - Fix the GetArrayElementType() call so it will not crash when called on a non-array thing

Enrico Granata egranata at apple.com
Tue Apr 8 11:36:09 PDT 2014


Author: enrico
Date: Tue Apr  8 13:36:09 2014
New Revision: 205782

URL: http://llvm.org/viewvc/llvm-project?rev=205782&view=rev
Log:
Fix the GetArrayElementType() call so it will not crash when called on a non-array thing
Also, the stride is now a pointer so one can avoid passing it if it's not required


Modified:
    lldb/trunk/include/lldb/Symbol/ClangASTType.h
    lldb/trunk/source/Symbol/ClangASTType.cpp

Modified: lldb/trunk/include/lldb/Symbol/ClangASTType.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Symbol/ClangASTType.h?rev=205782&r1=205781&r2=205782&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Symbol/ClangASTType.h (original)
+++ lldb/trunk/include/lldb/Symbol/ClangASTType.h Tue Apr  8 13:36:09 2014
@@ -312,7 +312,7 @@ public:
                        clang::DeclContext *decl_ctx) const;
     
     ClangASTType
-    GetArrayElementType (uint64_t& stride) const;
+    GetArrayElementType (uint64_t *stride = nullptr) const;
     
     ClangASTType
     GetCanonicalType () const;

Modified: lldb/trunk/source/Symbol/ClangASTType.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Symbol/ClangASTType.cpp?rev=205782&r1=205781&r2=205782&view=diff
==============================================================================
--- lldb/trunk/source/Symbol/ClangASTType.cpp (original)
+++ lldb/trunk/source/Symbol/ClangASTType.cpp Tue Apr  8 13:36:09 2014
@@ -1638,16 +1638,22 @@ ClangASTType::AddVolatileModifier () con
 }
 
 ClangASTType
-ClangASTType::GetArrayElementType (uint64_t& stride) const
+ClangASTType::GetArrayElementType (uint64_t *stride) const
 {
     if (IsValid())
     {
         QualType qual_type(GetCanonicalQualType());
         
-        ClangASTType element_type (m_ast, qual_type.getTypePtr()->getArrayElementTypeNoTypeQual()->getCanonicalTypeUnqualified());
+        const clang::Type *array_elem_type = qual_type.getTypePtr()->getArrayElementTypeNoTypeQual();
+        
+        if (!array_elem_type)
+            return ClangASTType();
+        
+        ClangASTType element_type (m_ast, array_elem_type->getCanonicalTypeUnqualified());
         
         // TODO: the real stride will be >= this value.. find the real one!
-        stride = element_type.GetByteSize();
+        if (stride)
+            *stride = element_type.GetByteSize();
         
         return element_type;
         





More information about the lldb-commits mailing list