<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - Segmentation fault when assessing diagnostics via CodeCompletionResults in Python bindings"
href="https://bugs.llvm.org/show_bug.cgi?id=37218">37218</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Segmentation fault when assessing diagnostics via CodeCompletionResults in Python bindings
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>6.0
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>Frontend
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>andrey.torsunov@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>Recorded terminal session with demonstration of the bug:
<a href="https://asciinema.org/a/EP1pXTWvy4z3OwUJaN4PH5FCh">https://asciinema.org/a/EP1pXTWvy4z3OwUJaN4PH5FCh</a>
Test case:
```
from clang.cindex import TranslationUnit, Diagnostic
def test_diagnostics_via_code_complete():
files = [('fake.cpp', 'int f0() {x = 1}\n')]
tu = TranslationUnit.from_source(
'fake.cpp', ['-std=c++98', '-Wall', '-Wextra'],
unsaved_files=files)
cr = tu.codeComplete(
'fake.cpp', 1, 16,
unsaved_files=files)
assert cr is not None
assert len(cr.diagnostics) == 1, len(cr.diagnostics)
# Segfault here
assert cr.diagnostics[0].severity == Diagnostic.Error
assert cr.diagnostics[0].location.line == 1
assert cr.diagnostics[0].location.column == 11
assert (cr.diagnostics[0].spelling == "use of undeclared identifier 'x'")
```
On my local machine I fixed this by replacing `DiagnosticsIter.__getitem__`
with this code:
```
def __getitem__(self, key):
diag = conf.lib.clang_codeCompleteGetDiagnostic(self.ccr, key)
return Diagnostic(diag)
```
and change definition of `clang_codeCompleteGetDiagnostic` to this:
```
(
"clang_codeCompleteGetDiagnostic",
[CodeCompletionResults, c_int],
c_object_p # return type changed
),
```
p.s.: sorry, I don't figure out how to highlight code blocks here</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>