[llvm-bugs] [Bug 37218] New: Segmentation fault when assessing diagnostics via CodeCompletionResults in Python bindings

via llvm-bugs llvm-bugs at lists.llvm.org
Mon Apr 23 14:31:15 PDT 2018


https://bugs.llvm.org/show_bug.cgi?id=37218

            Bug ID: 37218
           Summary: Segmentation fault when assessing diagnostics via
                    CodeCompletionResults in Python bindings
           Product: clang
           Version: 6.0
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Frontend
          Assignee: unassignedclangbugs at nondot.org
          Reporter: andrey.torsunov at gmail.com
                CC: llvm-bugs at lists.llvm.org

Recorded terminal session with demonstration of the bug:
https://asciinema.org/a/EP1pXTWvy4z3OwUJaN4PH5FCh

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

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180423/240db736/attachment-0001.html>


More information about the llvm-bugs mailing list