Deferred cursor.mangled_name access - on some versions of libclang this causes sigsegv when accessing certain cursor's mangled_name

PiperOrigin-RevId: 334360148
Change-Id: I27ef72b1938052d68b65f99d05d34dcb9f7433f8
This commit is contained in:
Maciej Szawłowski 2020-09-29 05:47:58 -07:00 committed by Copybara-Service
parent 376ca05c56
commit d806e0df3b
2 changed files with 3 additions and 4 deletions

View File

@ -492,7 +492,6 @@ class Function(object):
self._tu = tu
self.cursor = cursor # type: cindex.Index
self.name = cursor.spelling # type: Text
self.mangled_name = cursor.mangled_name # type: Text
self.result = ReturnType(self, cursor.result_type)
self.original_definition = '{} {}'.format(
cursor.result_type.spelling, self.cursor.displayname) # type: Text
@ -542,7 +541,7 @@ class Function(object):
def is_mangled(self):
# type: () -> bool
return self.name != self.mangled_name
return self.cursor.mangled_name != self.cursor.spelling
def __hash__(self):
# type: () -> int
@ -550,7 +549,7 @@ class Function(object):
def __eq__(self, other):
# type: (Function) -> bool
return self.mangled_name == other.mangled_name
return self.cursor.mangled_name == other.cursor.mangled_name
class _TranslationUnit(object):

View File

@ -832,7 +832,7 @@ class CodeAnalysisTest(parameterized.TestCase):
functions = tu.get_functions()
self.assertLen(functions, 2)
mangled_names = [f.mangled_name for f in functions]
mangled_names = [f.cursor.mangled_name for f in functions]
self.assertSameElements(mangled_names, ['sum', '_Z3sumif'])