From 2de52cffb18ece90883b3aa4821035ba476adfd7 Mon Sep 17 00:00:00 2001 From: Nikolai Kosjar Date: Wed, 18 Dec 2019 12:23:51 +0100 Subject: [PATCH 1/6] Clang: Fix c++98-compat warnings for MSVC toolchain Clang invoked with --driver-mode=cl will map "-Wall" to "-Weverything", thus enabling -Wc++98-compat-pedantic and way more options. Fix this by escaping "-Wall" in the cl mode, effectively passing in "/clang:-Wall" instead of "-Wall". This fixes what 5675169e564a1af0d4b47d4f1ee872e404cc2d17 addressed also for ClangTools. Change-Id: Ideb7bab923d0359e8039b61e9d53c8765de79c29 Reviewed-by: Cristian Adam Reviewed-by: Alessandro Portale --- .../clangcodemodel/clangeditordocumentprocessor.cpp | 7 ++++++- src/plugins/clangtools/clangtidyclazyrunner.cpp | 10 ++++++++-- src/plugins/cpptools/cpptoolsreuse.cpp | 1 - 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/plugins/clangcodemodel/clangeditordocumentprocessor.cpp b/src/plugins/clangcodemodel/clangeditordocumentprocessor.cpp index 51acd3a5a6c..718b0dad288 100644 --- a/src/plugins/clangcodemodel/clangeditordocumentprocessor.cpp +++ b/src/plugins/clangcodemodel/clangeditordocumentprocessor.cpp @@ -441,6 +441,7 @@ public: { // Determine the driver mode from toolchain and flags. m_builder.evaluateCompilerFlags(); + m_isClMode = m_builder.isClStyle(); addLanguageOptions(); addGlobalDiagnosticOptions(); // Before addDiagnosticOptions() so users still can overwrite. @@ -498,7 +499,10 @@ private: ? CppTools::UseBuildSystemWarnings::Yes : CppTools::UseBuildSystemWarnings::No; - m_options.append(diagnosticConfig.clangOptions()); + const QStringList options = m_isClMode + ? CppTools::clangArgsForCl(diagnosticConfig.clangOptions()) + : diagnosticConfig.clangOptions(); + m_options.append(options); } void addGlobalDiagnosticOptions() @@ -537,6 +541,7 @@ private: Core::Id m_diagnosticConfigId; CppTools::UseBuildSystemWarnings m_useBuildSystemWarnings = CppTools::UseBuildSystemWarnings::No; CppTools::CompilerOptionsBuilder m_builder; + bool m_isClMode = false; QStringList m_options; }; } // namespace diff --git a/src/plugins/clangtools/clangtidyclazyrunner.cpp b/src/plugins/clangtools/clangtidyclazyrunner.cpp index 34a149c8236..976fbd9f9ad 100644 --- a/src/plugins/clangtools/clangtidyclazyrunner.cpp +++ b/src/plugins/clangtools/clangtidyclazyrunner.cpp @@ -48,11 +48,16 @@ using namespace CppTools; namespace ClangTools { namespace Internal { +static bool isClMode(const QStringList &options) +{ + return options.contains("--driver-mode=cl"); +} + static QStringList serializeDiagnosticsArguments(const QStringList &baseOptions, const QString &outputFilePath) { const QStringList serializeArgs{"-serialize-diagnostics", outputFilePath}; - if (baseOptions.contains("--driver-mode=cl")) + if (isClMode(baseOptions)) return clangArgsForCl(serializeArgs); return serializeArgs; } @@ -104,7 +109,8 @@ static QStringList clangArguments(const ClangDiagnosticConfig &diagnosticConfig, { QStringList arguments; arguments << ClangDiagnosticConfigsModel::globalDiagnosticOptions() - << diagnosticConfig.clangOptions() + << (isClMode(baseOptions) ? CppTools::clangArgsForCl(diagnosticConfig.clangOptions()) + : diagnosticConfig.clangOptions()) << baseOptions; if (LOG().isDebugEnabled()) diff --git a/src/plugins/cpptools/cpptoolsreuse.cpp b/src/plugins/cpptools/cpptoolsreuse.cpp index 3e448533743..b8677256916 100644 --- a/src/plugins/cpptools/cpptoolsreuse.cpp +++ b/src/plugins/cpptools/cpptoolsreuse.cpp @@ -366,7 +366,6 @@ static void addBuiltinConfigs(ClangDiagnosticConfigsModel &model) config.setClangOptions({ "-Wall", "-Wextra", - "-Wno-c++98-compat" }); model.appendOrUpdate(config); From 8f9ff0c640b34d45a0ecba10b015ebf64d7bce45 Mon Sep 17 00:00:00 2001 From: David Schulz Date: Thu, 19 Dec 2019 09:52:24 +0100 Subject: [PATCH 2/6] CMake build: disable some warnings for build against llvm Add the same ignore warning flags to the compiler as in clang_installation.pri Change-Id: Ieb3f6ac861cba60b6c7fb3c74e4c9b46a62d22b9 Reviewed-by: Cristian Adam --- CMakeLists.txt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index e29d793d7fd..75ddf7ff9e1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -98,6 +98,12 @@ endif() install(TARGETS OptionalSvg EXPORT QtCreator) find_package(Clang COMPONENTS libclang QUIET) +# silence a lot of warnings from building against llvm +# this would better fit inside a central libclang detection/include cmake file, but since we do not +# have one put it temporary here +if(MSVC AND TARGET libclang) + target_compile_options(libclang INTERFACE /wd4100 /wd4141 /wd4146 /wd4244 /wd4267 /wd4291) +endif() find_package(LLVM QUIET) if (APPLE) From 32018623a444a53038239e911df59b6f879ff89c Mon Sep 17 00:00:00 2001 From: Tobias Hunger Date: Thu, 19 Dec 2019 11:30:20 +0100 Subject: [PATCH 3/6] CMake: Nest nodes below SourceGroups in Project tree Task-number: QTCREATORBUG-23372 Change-Id: I8eccc7b9ce812b3abc9bf3e0057aa9d572f4faf8 Reviewed-by: Tobias Hunger --- src/plugins/cmakeprojectmanager/fileapidataextractor.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/plugins/cmakeprojectmanager/fileapidataextractor.cpp b/src/plugins/cmakeprojectmanager/fileapidataextractor.cpp index 81316f033bf..b98c38d2294 100644 --- a/src/plugins/cmakeprojectmanager/fileapidataextractor.cpp +++ b/src/plugins/cmakeprojectmanager/fileapidataextractor.cpp @@ -456,7 +456,7 @@ void addCompileGroups(ProjectNode *targetRoot, if (sourcePath.isChildOf(buildDirectory) && !inSourceBuild) { buildFileNodes.emplace_back(std::move(node)); } else if (sourcePath.isChildOf(sourceDirectory)) { - sourceGroupNodes[si.sourceGroup]->addNode(std::move(node)); + sourceGroupNodes[si.sourceGroup]->addNestedNode(std::move(node)); } else { otherFileNodes.emplace_back(std::move(node)); } From 4fdd9446179df772c86b0e022712595004272dc8 Mon Sep 17 00:00:00 2001 From: Nikolai Kosjar Date: Thu, 19 Dec 2019 10:56:20 +0100 Subject: [PATCH 4/6] Clang: Fix removing gcc internal include paths Amends 5165c037ebbc3948d777595610bc62beb275a9a8. Gentoo has the standard library headers installed in e.g. /include/g++-v8 and we excluded those. MinGW with the standard library headers in /include/c++ was whitelisted. Instead of whitelistening more dirs that could contain standard library headers, regard /include /include-fixed as gcc internal include paths to remove. These seem to be stable across distributions. Task-number: QTCREATORBUG-23330 Change-Id: I44965d2030b4ea5a9dd269400faf19c3df89f5a6 Reviewed-by: Cristian Adam --- src/plugins/cpptools/headerpathfilter.cpp | 13 ++++--------- tests/unit/unittest/headerpathfilter-test.cpp | 6 ++++-- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/src/plugins/cpptools/headerpathfilter.cpp b/src/plugins/cpptools/headerpathfilter.cpp index b656f8e136e..c7265e40444 100644 --- a/src/plugins/cpptools/headerpathfilter.cpp +++ b/src/plugins/cpptools/headerpathfilter.cpp @@ -71,15 +71,10 @@ void HeaderPathFilter::removeGccInternalIncludePaths() return; const Utils::FilePath gccInstallDir = projectPart.toolChainInstallDir; - auto isGccInternalInclude = [gccInstallDir](const HeaderPath &headerPath){ - const auto includePath = Utils::FilePath::fromString(headerPath.path); - if (includePath.isChildOf(gccInstallDir)) { - const QString remainingPath = headerPath.path.mid(gccInstallDir.toString().size()); - // MinGW ships the standard library headers in "/include/c++". - // Ensure that we do not remove include paths pointing there. - return !remainingPath.startsWith("/include/c++"); - } - return false; + auto isGccInternalInclude = [gccInstallDir](const HeaderPath &headerPath) { + const auto filePath = Utils::FilePath::fromString(headerPath.path); + return filePath == gccInstallDir.pathAppended("include") + || filePath == gccInstallDir.pathAppended("include-fixed"); }; Utils::erase(builtInHeaderPaths, isGccInternalInclude); diff --git a/tests/unit/unittest/headerpathfilter-test.cpp b/tests/unit/unittest/headerpathfilter-test.cpp index da9d735f49d..b5589e8ec35 100644 --- a/tests/unit/unittest/headerpathfilter-test.cpp +++ b/tests/unit/unittest/headerpathfilter-test.cpp @@ -245,7 +245,8 @@ TEST_F(HeaderPathFilter, ClangHeadersAndCppIncludesPathsOrderLinux) HasBuiltIn("/builtin_path"))); } -// Include paths below the installation dir should be removed as they confuse clang. +// GCC-internal include paths like /include and might confuse +// clang and should be filtered out. clang on the command line filters them out, too. TEST_F(HeaderPathFilter, RemoveGccInternalPaths) { projectPart.toolChainInstallDir = Utils::FilePath::fromUtf8("/usr/lib/gcc/x86_64-linux-gnu/7"); @@ -264,7 +265,8 @@ TEST_F(HeaderPathFilter, RemoveGccInternalPaths) ASSERT_THAT(filter.builtInHeaderPaths, ElementsAre(HasBuiltIn(CLANG_RESOURCE_DIR))); } -// MinGW ships the standard library headers in "/include/c++". +// Some distributions ship the standard library headers in "/include/c++" (MinGW) +// or e.g. "/include/g++-v8" (Gentoo). // Ensure that we do not remove include paths pointing there. TEST_F(HeaderPathFilter, RemoveGccInternalPathsExceptForStandardPaths) { From 26693e82126de15145a04c3428a10f6c15120532 Mon Sep 17 00:00:00 2001 From: Nikolai Kosjar Date: Thu, 19 Dec 2019 11:58:24 +0100 Subject: [PATCH 5/6] Revert "Clang: Stop enabling exceptions explicitly" This reverts commit b114f77d8a633341b617a5cadd04e5977beae65d as "--driver-mode=cl" apparently still disables exceptions. Task-number: QTCREATORBUG-23000 Change-Id: I9c49d971fafda5e1aca8445f8921e50f323d368f Reviewed-by: Cristian Adam --- .../cpptools/compileroptionsbuilder.cpp | 12 +++++++++++ src/plugins/cpptools/compileroptionsbuilder.h | 1 + .../unittest/compileroptionsbuilder-test.cpp | 20 +++++++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/src/plugins/cpptools/compileroptionsbuilder.cpp b/src/plugins/cpptools/compileroptionsbuilder.cpp index ee534757ea1..3804c3feb26 100644 --- a/src/plugins/cpptools/compileroptionsbuilder.cpp +++ b/src/plugins/cpptools/compileroptionsbuilder.cpp @@ -136,6 +136,7 @@ QStringList CompilerOptionsBuilder::build(ProjectFile::Kind fileKind, addTargetTriple(); updateFileLanguage(fileKind); addLanguageVersionAndExtensions(); + enableExceptions(); addPrecompiledHeaderOptions(usePrecompiledHeaders); addProjectConfigFileInclude(); @@ -270,6 +271,17 @@ void CompilerOptionsBuilder::addCompilerFlags() add(m_compilerFlags.flags); } +void CompilerOptionsBuilder::enableExceptions() +{ + // With "--driver-mode=cl" exceptions are disabled (clang 8). + // This is most likely due to incomplete exception support of clang. + // However, as we need exception support only in the frontend, + // enabling them explicitly should be fine. + if (m_projectPart.languageVersion > ::Utils::LanguageVersion::LatestC) + add("-fcxx-exceptions"); + add("-fexceptions"); +} + static QString creatorResourcePath() { #ifndef UNIT_TESTS diff --git a/src/plugins/cpptools/compileroptionsbuilder.h b/src/plugins/cpptools/compileroptionsbuilder.h index 5b7c682407e..b2c8313771e 100644 --- a/src/plugins/cpptools/compileroptionsbuilder.h +++ b/src/plugins/cpptools/compileroptionsbuilder.h @@ -69,6 +69,7 @@ public: void addExtraCodeModelFlags(); void addPicIfCompilerFlagsContainsIt(); void addCompilerFlags(); + void enableExceptions(); void insertWrappedQtHeaders(); void addLanguageVersionAndExtensions(); void updateFileLanguage(ProjectFile::Kind fileKind); diff --git a/tests/unit/unittest/compileroptionsbuilder-test.cpp b/tests/unit/unittest/compileroptionsbuilder-test.cpp index df110727071..2a6bfd8462f 100644 --- a/tests/unit/unittest/compileroptionsbuilder-test.cpp +++ b/tests/unit/unittest/compileroptionsbuilder-test.cpp @@ -444,6 +444,22 @@ TEST_F(CompilerOptionsBuilder, AddTargetTriple) ASSERT_THAT(compilerOptionsBuilder.options(), ElementsAre("--target=x86_64-apple-darwin10")); } +TEST_F(CompilerOptionsBuilder, EnableCExceptions) +{ + projectPart.languageVersion = Utils::LanguageVersion::C99; + + compilerOptionsBuilder.enableExceptions(); + + ASSERT_THAT(compilerOptionsBuilder.options(), ElementsAre("-fexceptions")); +} + +TEST_F(CompilerOptionsBuilder, EnableCXXExceptions) +{ + compilerOptionsBuilder.enableExceptions(); + + ASSERT_THAT(compilerOptionsBuilder.options(), ElementsAre("-fcxx-exceptions", "-fexceptions")); +} + TEST_F(CompilerOptionsBuilder, InsertWrappedQtHeaders) { CppTools::CompilerOptionsBuilder compilerOptionsBuilder{projectPart, @@ -601,6 +617,8 @@ TEST_F(CompilerOptionsBuilder, BuildAllOptions) "-x", "c++", "-std=c++17", + "-fcxx-exceptions", + "-fexceptions", "-DprojectFoo=projectBar", "-I", IsPartOfHeader("wrappedQtHeaders"), "-I", IsPartOfHeader(toNative("wrappedQtHeaders/QtCore").toStdString()), @@ -632,6 +650,8 @@ TEST_F(CompilerOptionsBuilder, BuildAllOptionsCl) "--target=x86_64-apple-darwin10", "/TP", "/std:c++17", + "-fcxx-exceptions", + "-fexceptions", "-fms-compatibility-version=19.00", "-DprojectFoo=projectBar", "-D__FUNCSIG__=\"\"", From 4a00f53c17989b5eedb59967dd09fa17e229fe39 Mon Sep 17 00:00:00 2001 From: Eike Ziller Date: Thu, 2 Jan 2020 14:26:27 +0100 Subject: [PATCH 6/6] Work around high DPI issues on Windows Task-number: QTBUG-80934 Change-Id: I4b7dbe7157145db3a9feee83f32be3babaca5ab9 Reviewed-by: David Schulz --- src/app/main.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/app/main.cpp b/src/app/main.cpp index 4b74be64dce..e0c9cd72bd2 100644 --- a/src/app/main.cpp +++ b/src/app/main.cpp @@ -335,6 +335,11 @@ static void setHighDpiEnvironmentVariable() && !qEnvironmentVariableIsSet("QT_SCALE_FACTOR") && !qEnvironmentVariableIsSet("QT_SCREEN_SCALE_FACTORS")) { QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling); +#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) + // work around QTBUG-80934 + QGuiApplication::setHighDpiScaleFactorRoundingPolicy( + Qt::HighDpiScaleFactorRoundingPolicy::Round); +#endif } }