From 5a6c625c5e46aef442689a2bc691679da7a562db Mon Sep 17 00:00:00 2001 From: Cristian Adam Date: Fri, 3 Dec 2021 13:52:21 +0100 Subject: [PATCH] CppEditor: Fix codemodel highlighting for QNX The code model will get the necessary bits so that it can successfully parse the QNX code. Fixes: QTCREATORBUG-23483 Change-Id: Id9488f644ace23952edf7a7cb5da7ca138182134 Reviewed-by: Christian Kandeler --- .../cppeditor/compileroptionsbuilder.cpp | 18 ++++++++++++++++-- src/plugins/cppeditor/compileroptionsbuilder.h | 2 ++ src/plugins/qnx/qnxtoolchain.cpp | 8 +++++++- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/plugins/cppeditor/compileroptionsbuilder.cpp b/src/plugins/cppeditor/compileroptionsbuilder.cpp index e80de33f2b4..73994fd9c98 100644 --- a/src/plugins/cppeditor/compileroptionsbuilder.cpp +++ b/src/plugins/cppeditor/compileroptionsbuilder.cpp @@ -35,6 +35,8 @@ #include #include +#include + #include #include #include @@ -152,6 +154,7 @@ QStringList CompilerOptionsBuilder::build(ProjectFile::Kind fileKind, undefineClangVersionMacrosForMsvc(); undefineCppLanguageFeatureMacrosForMsvc2015(); addDefineFunctionMacrosMsvc(); + addDefineFunctionMacrosQnx(); addHeaderPathOptions(); @@ -404,8 +407,8 @@ void CompilerOptionsBuilder::addProjectMacros() static const int useMacros = qEnvironmentVariableIntValue("QTC_CLANG_USE_TOOLCHAIN_MACROS"); if (m_projectPart.toolchainType == ProjectExplorer::Constants::CUSTOM_TOOLCHAIN_TYPEID - || m_projectPart.toolchainType.name().contains("BareMetal") - || useMacros) { + || m_projectPart.toolchainType == Qnx::Constants::QNX_TOOLCHAIN_ID + || m_projectPart.toolchainType.name().contains("BareMetal") || useMacros) { addMacros(m_projectPart.toolChainMacros); } @@ -771,6 +774,17 @@ void CompilerOptionsBuilder::undefineClangVersionMacrosForMsvc() } } +void CompilerOptionsBuilder::addDefineFunctionMacrosQnx() +{ + // QNX 7.0+ uses GCC with LIBCPP from Clang, and in that context GCC is giving + // the builtin operator new and delete. + // + // In our case we have only Clang and need to instruct LIBCPP that it doesn't + // have these operators. This makes the code model happy and doesn't produce errors. + if (m_projectPart.toolchainType == Qnx::Constants::QNX_TOOLCHAIN_ID) + addMacros({{"_LIBCPP_HAS_NO_BUILTIN_OPERATOR_NEW_DELETE"}}); +} + void CompilerOptionsBuilder::reset() { m_options.clear(); diff --git a/src/plugins/cppeditor/compileroptionsbuilder.h b/src/plugins/cppeditor/compileroptionsbuilder.h index cc75e984bed..6ae97323354 100644 --- a/src/plugins/cppeditor/compileroptionsbuilder.h +++ b/src/plugins/cppeditor/compileroptionsbuilder.h @@ -84,6 +84,8 @@ public: void addProjectConfigFileInclude(); void undefineClangVersionMacrosForMsvc(); + void addDefineFunctionMacrosQnx(); + // Add custom options void add(const QString &arg, bool gccOnlyOption = false); void prepend(const QString &arg); diff --git a/src/plugins/qnx/qnxtoolchain.cpp b/src/plugins/qnx/qnxtoolchain.cpp index 984d593b4e0..354de0bb93f 100644 --- a/src/plugins/qnx/qnxtoolchain.cpp +++ b/src/plugins/qnx/qnxtoolchain.cpp @@ -185,7 +185,13 @@ void QnxToolChain::setCpuDir(const QString &cpuDir) GccToolChain::DetectedAbisResult QnxToolChain::detectSupportedAbis() const { - return detectTargetAbis(m_sdpPath); + // "unknown-qnx-gnu"is needed to get the "--target=xxx" parameter sent code model, + // which gets translated as "x86_64-qnx-gnu", which gets Clang to happily parse + // the QNX code. + // + // Without it on Windows Clang defaults to a MSVC mode, which breaks with + // the QNX code, which is mostly GNU based. + return GccToolChain::DetectedAbisResult{detectTargetAbis(m_sdpPath), "unknown-qnx-gnu"}; } bool QnxToolChain::operator ==(const ToolChain &other) const