Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 71c65a65 authored by Thomas Schöps's avatar Thomas Schöps Committed by Kevin Funk

Clang plugin: Handle CUDA files better

Summary:
This fixes two issues in how KDevelop's clang plugin handles CUDA files (.cu source files and .cuh headers):
1) Those file types were not treated as source files, therefore if such a file was modified, it was not passed among the list of modified source files to clang for re-parsing. The re-parsing thus incorrectly used the unmodified file on disk instead. This is addressed by the change to documentfinderhelpers.cpp and kdevclang.xml.
2) The patch passes the general code parser settings also to CUDA files (change in parsesession.cpp). This is for example important to get flags such as -std=c++11 that are required for correct parsing. However, it is not correct: the build system may use separate options for CUDA files (e.g., CMake's CUDA_NVCC_FLAGS). But it might still be better than the previous behavior of not passing any options except -xcuda, since it might be somewhat likely that it is a reasonable guess.

Additional comments:
a) I am not sure whether the change in clanghelpers.cpp is required, but it seems coherent.
b) I changed the CUDA mime types in kdevclang.xml to inherit from text/x-c++src/hdr instead of text/x-csrc/hdr since the CUDA files can contain C++ code.
c) This patch is not sufficient to enable proper CUDA support. I'll post to the kdevelop-devel mailing list for that.

Test Plan: Tested manually.

Reviewers: #kdevelop, kfunk

Reviewed By: #kdevelop, kfunk

Subscribers: kfunk, apol, kdevelop-devel

Tags: #kdevelop

Differential Revision: https://phabricator.kde.org/D17909
parent 41a0f0ce
......@@ -311,6 +311,7 @@ QStringList ClangHelpers::headerExtensions()
QStringLiteral("hxx"),
QStringLiteral("hpp"),
QStringLiteral("tlh"),
QStringLiteral("cuh"),
QStringLiteral("h++"),
};
return headerExtensions;
......@@ -325,6 +326,7 @@ QStringList ClangHelpers::sourceExtensions()
QStringLiteral("c++"),
QStringLiteral("cxx"),
QStringLiteral("C"),
QStringLiteral("cu"),
QStringLiteral("m"),
QStringLiteral("mm"),
QStringLiteral("M"),
......
......@@ -179,8 +179,10 @@ QStringList mimeTypesList()
static const QStringList mimeTypes = {
QStringLiteral("text/x-chdr"),
QStringLiteral("text/x-c++hdr"),
QStringLiteral("text/vnd.nvidia.cuda.chdr"),
QStringLiteral("text/x-csrc"),
QStringLiteral("text/x-c++src"),
QStringLiteral("text/vnd.nvidia.cuda.csrc"),
QStringLiteral("text/x-objcsrc")
};
return mimeTypes;
......
......@@ -102,8 +102,11 @@ QVector<QByteArray> argsForSession(const QString& path, ParseSessionData::Option
// TODO: No proper mime type detection possible yet
// cf. https://bugs.freedesktop.org/show_bug.cgi?id=23700
if (path.endsWith(QLatin1String(".cu"), Qt::CaseInsensitive)) {
return {QByteArrayLiteral("-xcuda")};
if (path.endsWith(QLatin1String(".cu"), Qt::CaseInsensitive) ||
path.endsWith(QLatin1String(".cuh"), Qt::CaseInsensitive)) {
auto result = parserSettings.toClangAPI();
result.append(QByteArrayLiteral("-xcuda"));
return result;
}
if (parserSettings.parserOptions.isEmpty()) {
......
......@@ -54,7 +54,13 @@
<comment xml:lang="tr">NVIDIA CUDA C kaynak kodu</comment>
<comment xml:lang="uk">початковий код C NVIDIA CUDA</comment>
<comment xml:lang="zh_CN">NVIDIA CUDA C 源代码</comment>
<sub-class-of type="text/x-csrc"/>
<sub-class-of type="text/x-c++src"/>
<glob pattern="*.cu"/>
</mime-type>
<mime-type type="text/vnd.nvidia.cuda.chdr">
<comment>NVIDIA CUDA C header</comment>
<sub-class-of type="text/x-c++hdr"/>
<glob pattern="*.cuh"/>
</mime-type>
</mime-info>
......@@ -72,6 +72,7 @@
"text/x-c++src",
"text/x-opencl-src",
"text/vnd.nvidia.cuda.csrc",
"text/vnd.nvidia.cuda.chdr",
"text/x-objcsrc"
]
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment