diff options
author | Friedemann Kleint <Friedemann.Kleint@qt.io> | 2021-02-01 17:34:02 +0100 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2021-02-01 20:12:16 +0000 |
commit | 8f19ff1b7f258303c983ee05cee28e1b7b3a6a85 (patch) | |
tree | 91432213b346325b50b480ceb861c4862fa616e0 | |
parent | dd2c23e75604403728573c67eaeb5a51ab8280a4 (diff) |
shiboken6: Fix a crash when printing clang diagnostics
The CXFile struct used in the Diagnostic struct representing
a diagnostic message is invalid after clang parsing has finished
and causes a crash when printing.
Expand it to a QString at creation time.
Apparently, this occurred with recent clang versions.
Change-Id: I297014e272d6814f04e8f0273e8ae79ab8264138
Reviewed-by: Christian Tismer <tismer@stackless.com>
(cherry picked from commit 9da07f8145b38f4483fed94fbc3148af872b08ec)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r-- | sources/shiboken6/ApiExtractor/clangparser/clangutils.cpp | 15 | ||||
-rw-r--r-- | sources/shiboken6/ApiExtractor/clangparser/clangutils.h | 8 |
2 files changed, 18 insertions, 5 deletions
diff --git a/sources/shiboken6/ApiExtractor/clangparser/clangutils.cpp b/sources/shiboken6/ApiExtractor/clangparser/clangutils.cpp index 5b108b2e7..bf568f30d 100644 --- a/sources/shiboken6/ApiExtractor/clangparser/clangutils.cpp +++ b/sources/shiboken6/ApiExtractor/clangparser/clangutils.cpp @@ -139,8 +139,9 @@ QString getTypeName(const CXType &type) } Diagnostic::Diagnostic(const QString &m, const CXCursor &c, CXDiagnosticSeverity s) - : message(m), location(getCursorLocation(c)), source(Other), severity(s) + : message(m), source(Other), severity(s) { + setLocation(getCursorLocation(c)); } Diagnostic Diagnostic::fromCXDiagnostic(CXDiagnostic cd) @@ -151,7 +152,7 @@ Diagnostic Diagnostic::fromCXDiagnostic(CXDiagnostic cd) result.message = QString::fromUtf8(clang_getCString(spelling)); clang_disposeString(spelling); result.severity = clang_getDiagnosticSeverity(cd); - result.location = getExpansionLocation(clang_getDiagnosticLocation(cd)); + result.setLocation(getExpansionLocation(clang_getDiagnosticLocation(cd))); CXDiagnosticSet childDiagnostics = clang_getChildDiagnostics(cd); if (const unsigned childCount = clang_getNumDiagnosticsInSet(childDiagnostics)) { @@ -169,6 +170,14 @@ Diagnostic Diagnostic::fromCXDiagnostic(CXDiagnostic cd) return result; } +void Diagnostic::setLocation(const SourceLocation &sourceLocation) +{ + file = getFileName(sourceLocation.file); + line = sourceLocation.line; + column = sourceLocation.column; + offset = sourceLocation.offset; +} + QList<Diagnostic> getDiagnostics(CXTranslationUnit tu) { QList<Diagnostic> result; @@ -249,7 +258,7 @@ QDebug operator<<(QDebug s, const Diagnostic &d) QDebugStateSaver saver(s); s.nospace(); s.noquote(); - s << d.location << ": "; + s << d.file << ':'<< d.line << ':' << d.column << ": "; switch (d.severity) { case CXDiagnostic_Ignored: s << "ignored"; diff --git a/sources/shiboken6/ApiExtractor/clangparser/clangutils.h b/sources/shiboken6/ApiExtractor/clangparser/clangutils.h index d29addd2b..0182c0dde 100644 --- a/sources/shiboken6/ApiExtractor/clangparser/clangutils.h +++ b/sources/shiboken6/ApiExtractor/clangparser/clangutils.h @@ -68,7 +68,7 @@ struct SourceLocation { bool equals(const SourceLocation &rhs) const; - CXFile file; + CXFile file = nullptr; unsigned line = 0; unsigned column = 0; unsigned offset = 0; @@ -96,10 +96,14 @@ struct Diagnostic { static Diagnostic fromCXDiagnostic(CXDiagnostic cd); // Other explicit Diagnostic(const QString &m, const CXCursor &c, CXDiagnosticSeverity s = CXDiagnostic_Warning); + void setLocation(const SourceLocation &); QString message; QStringList childMessages; - SourceLocation location; + QString file; + unsigned line = 0; + unsigned column = 0; + unsigned offset = 0; Source source = Clang; CXDiagnosticSeverity severity = CXDiagnostic_Warning; }; |