[clang-tools-extra] [clang-tidy] add depercation warning for non-whitelisted global options (PR #121057)
@@ -0,0 +1,3 @@ +// RUN: clang-tidy %s --config="{CheckOptions:{StrictMode: true}}" -checks="-*,modernize-use-std-format" | FileCheck %s + +// CHECK: warning: deprecation global option 'StrictMode', please use 'modernize-use-std-format.StrictMode'. [clang-tidy-config] HerrCai0907 wrote: ```suggestion // CHECK: warning: global option 'StrictMode' is deprecated, please use 'modernize-use-std-format.StrictMode' instead. [clang-tidy-config] ``` https://github.com/llvm/llvm-project/pull/121057 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Add `AllowShortNamespacesOnASingleLine` option (PR #105597)
https://github.com/owenca edited https://github.com/llvm/llvm-project/pull/105597 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Make regex stricter (PR #121243)
llvmbot wrote: @llvm/pr-subscribers-clang @llvm/pr-subscribers-clang-driver Author: Vitaly Buka (vitalybuka) Changes Follow up to #121221. --- Full diff: https://github.com/llvm/llvm-project/pull/121243.diff 1 Files Affected: - (modified) clang/test/Driver/sanitizer-ld.c (+8-4) ``diff diff --git a/clang/test/Driver/sanitizer-ld.c b/clang/test/Driver/sanitizer-ld.c index 4e4cfbae27e113..17766cef86d2a8 100644 --- a/clang/test/Driver/sanitizer-ld.c +++ b/clang/test/Driver/sanitizer-ld.c @@ -1,9 +1,13 @@ // Test sanitizers ld flags. -// Match all libclang_rt, excluding platform-inconsistent libs, like -// libclang_rt.builtins, libclang_rt.osx etc. - -// DEFINE: %{filecheck} = FileCheck %s --implicit-check-not="libclang_rt.{{([^.]+san|scudo|cfi|safestack|stats|fuzzer|undefined)}}" +// Match all sanitizer related libclang_rt, we are not interested in +// libclang_rt.builtins, libclang_rt.osx, libclang_rt.ios, libclang_rt.watchos +// etc. +// +// If we need to add sanitizer with name starting with excluded laters, e.g. +// `bsan`, we can extend expression like this: `([^iow]|b[^u])`. +// +// DEFINE: %{filecheck} = FileCheck %s --implicit-check-not="libclang_rt.{{([^biow])}}" // RUN: %clang -### %s 2>&1 \ // RUN: --target=i386-unknown-linux -fuse-ld=ld -fsanitize=address \ `` https://github.com/llvm/llvm-project/pull/121243 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Make regex stricter (PR #121243)
https://github.com/vitalybuka created https://github.com/llvm/llvm-project/pull/121243 Follow up to #121221. >From 85581e8a0481388781b2c715fd746c908ea5fa04 Mon Sep 17 00:00:00 2001 From: Vitaly Buka Date: Fri, 27 Dec 2024 18:32:15 -0800 Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?= =?UTF-8?q?l=20version?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Created using spr 1.3.4 --- clang/test/Driver/sanitizer-ld.c | 12 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/clang/test/Driver/sanitizer-ld.c b/clang/test/Driver/sanitizer-ld.c index 4e4cfbae27e113..17766cef86d2a8 100644 --- a/clang/test/Driver/sanitizer-ld.c +++ b/clang/test/Driver/sanitizer-ld.c @@ -1,9 +1,13 @@ // Test sanitizers ld flags. -// Match all libclang_rt, excluding platform-inconsistent libs, like -// libclang_rt.builtins, libclang_rt.osx etc. - -// DEFINE: %{filecheck} = FileCheck %s --implicit-check-not="libclang_rt.{{([^.]+san|scudo|cfi|safestack|stats|fuzzer|undefined)}}" +// Match all sanitizer related libclang_rt, we are not interested in +// libclang_rt.builtins, libclang_rt.osx, libclang_rt.ios, libclang_rt.watchos +// etc. +// +// If we need to add sanitizer with name starting with excluded laters, e.g. +// `bsan`, we can extend expression like this: `([^iow]|b[^u])`. +// +// DEFINE: %{filecheck} = FileCheck %s --implicit-check-not="libclang_rt.{{([^biow])}}" // RUN: %clang -### %s 2>&1 \ // RUN: --target=i386-unknown-linux -fuse-ld=ld -fsanitize=address \ ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Make regex stricter (PR #121243)
https://github.com/vitalybuka closed https://github.com/llvm/llvm-project/pull/121243 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [SYCL] Basic diagnostics for the sycl_kernel_entry_point attribute. (PR #120327)
@@ -15978,6 +15988,24 @@ Decl *Sema::ActOnFinishFunctionBody(Decl *dcl, Stmt *Body, CheckCoroutineWrapper(FD); } + // Diagnose invalid SYCL kernel entry point function declarations. + if (FD && !FD->isInvalidDecl() && !FD->isTemplated() && tahonermann wrote: It turned out to be pretty straight forward to enable diagnostics for dependent contexts. No additional changes were needed to diagnose coroutines. For deleted and defaulted functions, I had to duplicate the checks here in `SemaSYCL::CheckSYCLEntryPointFunctionDecl()`; the checks here handle non-dependent cases and the checks in `SemaSYCL::CheckSYCLEntryPointFunctionDecl()` handle dependent cases. https://github.com/llvm/llvm-project/pull/120327 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Add `AllowShortNamespacesOnASingleLine` option (PR #105597)
https://github.com/owenca edited https://github.com/llvm/llvm-project/pull/105597 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 092966a - [Driver] Make regex stricter (#121243)
Author: Vitaly Buka Date: 2024-12-27T19:32:06-08:00 New Revision: 092966a44d1793e6bd53c191efeb5a5425fecde3 URL: https://github.com/llvm/llvm-project/commit/092966a44d1793e6bd53c191efeb5a5425fecde3 DIFF: https://github.com/llvm/llvm-project/commit/092966a44d1793e6bd53c191efeb5a5425fecde3.diff LOG: [Driver] Make regex stricter (#121243) Follow up to #121221. Added: Modified: clang/test/Driver/sanitizer-ld.c Removed: diff --git a/clang/test/Driver/sanitizer-ld.c b/clang/test/Driver/sanitizer-ld.c index 4e4cfbae27e113..17766cef86d2a8 100644 --- a/clang/test/Driver/sanitizer-ld.c +++ b/clang/test/Driver/sanitizer-ld.c @@ -1,9 +1,13 @@ // Test sanitizers ld flags. -// Match all libclang_rt, excluding platform-inconsistent libs, like -// libclang_rt.builtins, libclang_rt.osx etc. - -// DEFINE: %{filecheck} = FileCheck %s --implicit-check-not="libclang_rt.{{([^.]+san|scudo|cfi|safestack|stats|fuzzer|undefined)}}" +// Match all sanitizer related libclang_rt, we are not interested in +// libclang_rt.builtins, libclang_rt.osx, libclang_rt.ios, libclang_rt.watchos +// etc. +// +// If we need to add sanitizer with name starting with excluded laters, e.g. +// `bsan`, we can extend expression like this: `([^iow]|b[^u])`. +// +// DEFINE: %{filecheck} = FileCheck %s --implicit-check-not="libclang_rt.{{([^biow])}}" // RUN: %clang -### %s 2>&1 \ // RUN: --target=i386-unknown-linux -fuse-ld=ld -fsanitize=address \ ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] Added options to readability-implicit-bool-conversion (PR #120087)
https://github.com/4m4n-x-B4w4ne updated https://github.com/llvm/llvm-project/pull/120087 >From 03f536888ddc5b7be2514c2d880c6d3119b7f4ee Mon Sep 17 00:00:00 2001 From: 4m4n-x-B4w4ne <125849251+4m4n-x-b4w...@users.noreply.github.com> Date: Mon, 16 Dec 2024 19:43:42 +0530 Subject: [PATCH 01/34] Update ImplicitBoolConversionCheck.cpp Added new options in ImplicitBoolConversionCheck CheckConversionToBool and CheckConversionFromBool. --- .../readability/ImplicitBoolConversionCheck.cpp | 15 +-- 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp index f9fd1d903e231e..517a5d2b982751 100644 --- a/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp @@ -258,14 +258,17 @@ ImplicitBoolConversionCheck::ImplicitBoolConversionCheck( : ClangTidyCheck(Name, Context), AllowIntegerConditions(Options.get("AllowIntegerConditions", false)), AllowPointerConditions(Options.get("AllowPointerConditions", false)), - UseUpperCaseLiteralSuffix( - Options.get("UseUpperCaseLiteralSuffix", false)) {} + UseUpperCaseLiteralSuffix(Options.get("UseUpperCaseLiteralSuffix", false)), + CheckConversionsToBool(Options.get("CheckConversionsToBool",true)), + CheckConversionsFromBool(Options.get("CheckConversionsFromBool",true)) {} void ImplicitBoolConversionCheck::storeOptions( ClangTidyOptions::OptionMap &Opts) { Options.store(Opts, "AllowIntegerConditions", AllowIntegerConditions); Options.store(Opts, "AllowPointerConditions", AllowPointerConditions); Options.store(Opts, "UseUpperCaseLiteralSuffix", UseUpperCaseLiteralSuffix); + Options.store(Opts,"CheckConversionsToBool",CheckConversionsToBool); + Options.store(Opts,"CheckConversionsFromBool",CheckConversionsFromBool); } void ImplicitBoolConversionCheck::registerMatchers(MatchFinder *Finder) { @@ -358,14 +361,14 @@ void ImplicitBoolConversionCheck::registerMatchers(MatchFinder *Finder) { void ImplicitBoolConversionCheck::check( const MatchFinder::MatchResult &Result) { - if (const auto *CastToBool = - Result.Nodes.getNodeAs("implicitCastToBool")) { + if (CheckConversionsToBool && (const auto *CastToBool = + Result.Nodes.getNodeAs("implicitCastToBool"))) { const auto *Parent = Result.Nodes.getNodeAs("parentStmt"); return handleCastToBool(CastToBool, Parent, *Result.Context); } - if (const auto *CastFromBool = - Result.Nodes.getNodeAs("implicitCastFromBool")) { + if (CheckConversionsFromBool && (const auto *CastFromBool = + Result.Nodes.getNodeAs("implicitCastFromBool"))) { const auto *NextImplicitCast = Result.Nodes.getNodeAs("furtherImplicitCast"); return handleCastFromBool(CastFromBool, NextImplicitCast, *Result.Context); >From 16c7c95939b4c0c38ebccbbc6cd1da3739244a24 Mon Sep 17 00:00:00 2001 From: 4m4n-x-B4w4ne <125849251+4m4n-x-b4w...@users.noreply.github.com> Date: Mon, 16 Dec 2024 19:45:37 +0530 Subject: [PATCH 02/34] Update ImplicitBoolConversionCheck.h Added CheckConversionToBool and CheckConversionFromBool Options in the header --- .../clang-tidy/readability/ImplicitBoolConversionCheck.h| 2 ++ 1 file changed, 2 insertions(+) diff --git a/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.h b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.h index 5947f7316e67cc..b0c3c2943e649c 100644 --- a/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.h +++ b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.h @@ -37,6 +37,8 @@ class ImplicitBoolConversionCheck : public ClangTidyCheck { const bool AllowIntegerConditions; const bool AllowPointerConditions; const bool UseUpperCaseLiteralSuffix; + const bool CheckConversionsToBool; + const bool CheckConversionsFromBool; }; } // namespace clang::tidy::readability >From 0d6fae8b08a4a365c9295ac8a96de2aba9974c98 Mon Sep 17 00:00:00 2001 From: 4m4n-x-B4w4ne <125849251+4m4n-x-b4w...@users.noreply.github.com> Date: Mon, 16 Dec 2024 19:48:48 +0530 Subject: [PATCH 03/34] Create implicit-bool-conversion-check.cpp Added new test to check the new options added in the ImplicitBoolConversionCheck.cpp --- .../implicit-bool-conversion-check.cpp| 92 +++ 1 file changed, 92 insertions(+) create mode 100644 clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion-check.cpp diff --git a/clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion-check.cpp b/clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion-check.cpp new file mode 100644 index 00..506769d5a57322 --- /dev/null +++ b/clang-tools-extra/test/clang-tidy/checkers
[clang-tools-extra] Added options to readability-implicit-bool-conversion (PR #120087)
@@ -319,10 +319,11 @@ Changes in existing checks diagnostic. - Improved :doc:`readability-implicit-bool-conversion - ` check - by adding the option `UseUpperCaseLiteralSuffix` to select the - case of the literal suffix in fixes and fixing false positive for implicit - conversion of comparison result in C23. + ` check by adding the + option `UseUpperCaseLiteralSuffix` to select the case of the literal suffix in + fixes and fixing false positive for implicit conversion of comparison result in + C23 , and by adding the option `CheckConversionsToBool` or 4m4n-x-B4w4ne wrote: Done Thanks. https://github.com/llvm/llvm-project/pull/120087 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] Add a unit test suite for HeuristicResolver (PR #121246)
llvmbot wrote: @llvm/pr-subscribers-clang-tools-extra Author: Nathan Ridge (HighCommander4) Changes Fixes https://github.com/clangd/clangd/issues/2154 --- Full diff: https://github.com/llvm/llvm-project/pull/121246.diff 3 Files Affected: - (modified) clang-tools-extra/clangd/HeuristicResolver.h (+3-2) - (modified) clang-tools-extra/clangd/unittests/CMakeLists.txt (+1) - (added) clang-tools-extra/clangd/unittests/HeuristicResolverTests.cpp (+521) ``diff diff --git a/clang-tools-extra/clangd/HeuristicResolver.h b/clang-tools-extra/clangd/HeuristicResolver.h index dcc063bbc4adc0..c130e0677e86dd 100644 --- a/clang-tools-extra/clangd/HeuristicResolver.h +++ b/clang-tools-extra/clangd/HeuristicResolver.h @@ -26,13 +26,14 @@ class UnresolvedUsingValueDecl; namespace clangd { -// This class heuristic resolution of declarations and types in template code. +// This class handles heuristic resolution of declarations and types in template +// code. // // As a compiler, clang only needs to perform certain types of processing on // template code (such as resolving dependent names to declarations, or // resolving the type of a dependent expression) after instantiation. Indeed, // C++ language features such as template specialization mean such resolution -// cannot be done accurately before instantiation +// cannot be done accurately before instantiation. // // However, template code is written and read in uninstantiated form, and clangd // would like to provide editor features like go-to-definition in template code diff --git a/clang-tools-extra/clangd/unittests/CMakeLists.txt b/clang-tools-extra/clangd/unittests/CMakeLists.txt index dffdcd5d014ca9..8dba8088908d5e 100644 --- a/clang-tools-extra/clangd/unittests/CMakeLists.txt +++ b/clang-tools-extra/clangd/unittests/CMakeLists.txt @@ -64,6 +64,7 @@ add_unittest(ClangdUnitTests ClangdTests GlobalCompilationDatabaseTests.cpp HeadersTests.cpp HeaderSourceSwitchTests.cpp + HeuristicResolverTests.cpp HoverTests.cpp IncludeCleanerTests.cpp IndexActionTests.cpp diff --git a/clang-tools-extra/clangd/unittests/HeuristicResolverTests.cpp b/clang-tools-extra/clangd/unittests/HeuristicResolverTests.cpp new file mode 100644 index 00..1e6cd3e266e600 --- /dev/null +++ b/clang-tools-extra/clangd/unittests/HeuristicResolverTests.cpp @@ -0,0 +1,521 @@ +//===-- HeuristicResolverTests.cpp --*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// +#include "HeuristicResolver.h" +#include "clang/ASTMatchers/ASTMatchFinder.h" +#include "clang/ASTMatchers/ASTMatchers.h" +#include "clang/Tooling/Tooling.h" +#include "gmock/gmock-matchers.h" +#include "gtest/gtest.h" + +using namespace clang::ast_matchers; +using clang::clangd::HeuristicResolver; +using testing::ElementsAre; + +namespace clang { +namespace { + +// Helper for matching a sequence of elements with a variadic list of matchers. +// Usage: `ElementsAre(matchAdapter(Vs, MatchFunction)...)`, where `Vs...` is +//a variadic list of matchers. +// For each `V` in `Vs`, this will match the corresponding element `E` if +// `MatchFunction(V, E)` is true. +MATCHER_P2(matchAdapter, MatcherForElement, MatchFunction, "matchAdapter") { + return MatchFunction(MatcherForElement, arg); +} + +template +using ResolveFnT = std::function( +const HeuristicResolver *, const InputNode *)>; + +// Test heuristic resolution on `Code` using the resolution procedure +// `ResolveFn`, which takes a `HeuristicResolver` and an input AST node of type +// `InputNode` and returns a `std::vector`. +// `InputMatcher` should be an AST matcher that matches a single node to pass as +// input to `ResolveFn`, bound to the ID "input". `OutputMatchers` should be AST +// matchers that each match a single node, bound to the ID "output". +template +void expectResolution(llvm::StringRef Code, ResolveFnT ResolveFn, + const InputMatcher &IM, const OutputMatchers &...OMS) { + auto TU = tooling::buildASTFromCodeWithArgs(Code, {"-std=c++20"}); + auto &Ctx = TU->getASTContext(); + auto InputMatches = match(IM, Ctx); + ASSERT_EQ(1u, InputMatches.size()); + const auto *Input = InputMatches[0].template getNodeAs("input"); + ASSERT_TRUE(Input); + + auto OutputNodeMatches = [&](auto &OutputMatcher, auto &Actual) { +auto OutputMatches = match(OutputMatcher, Ctx); +if (OutputMatches.size() != 1u) + return false; +const auto *ExpectedOutput = +OutputMatches[0].template getNodeAs("output"); +if (!ExpectedOutput) + return false; +return ExpectedOutput == Actual; + }; + + HeuristicResolver H(Ctx); + auto Results = ResolveFn(&H, Input); + EXPECT_THAT(Results, Elem
[clang] Delay marking pending incomplete decl chains until the end of `finishPendingActions`. (PR #121245)
https://github.com/mpark edited https://github.com/llvm/llvm-project/pull/121245 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Delay marking pending incomplete decl chains until the end of `finishPendingActions`. (PR #121245)
https://github.com/mpark created https://github.com/llvm/llvm-project/pull/121245 This is fix for an unreachable code path being reached, for an internal use case at Meta. I'm unfortunately still not able to reproduce a minimal example that I can share 😞 # Description There is a defaulted constructor `_Hashtable_alloc() = default;` which ends up in [`CodeGenFunction::GenerateCode`](https://github.com/llvm/llvm-project/blob/48bf0a9457fd60d0872d9b9b4804a95c833a72e1/clang/lib/CodeGen/CodeGenFunction.cpp#L1448) and eventually calls [`FunctionProtoType::canThrow`](https://github.com/llvm/llvm-project/blob/48bf0a9457fd60d0872d9b9b4804a95c833a72e1/clang/lib/AST/Type.cpp#L3758) with `EST_Unevaluated`. In the "good" cases I observed, I see that the decl is also loaded with the `noexcept-unevaluated` state, but it gets fixed up later by a [call to `adjustExceptionSpec`](https://github.com/llvm/llvm-project/blob/48bf0a9457fd60d0872d9b9b4804a95c833a72e1/clang/lib/Serialization/ASTReader.cpp#L10656). The update gets [added to `PendingExceptionSpecUpdates` here](https://github.com/llvm/llvm-project/blob/48bf0a9457fd60d0872d9b9b4804a95c833a72e1/clang/lib/Serialization/ASTReaderDecl.cpp#L4749-L4752). In the "bad" case, the update does not get added to `PendingExceptionSpecUpdates` and hence the call to `adjustExceptionSpec` also does not occur. # Observations I made two observations in Clang Discord: [[1](https://discord.com/channels/636084430946959380/636732781086638081/1317290104431185921)] and [[2](https://discord.com/channels/636084430946959380/636732781086638081/1317291980413206608)]. 1. [FinishedDeserializating](https://github.com/llvm/llvm-project/blob/main/clang/lib/Serialization/ASTReader.cpp#L10641) can exit with stuff still in `PendingIncompleteDeclChains`. `FinishedDeserializing` [calls `finishPendingActions` only if `NumCurrentElementsDeserializing == 1`](https://github.com/llvm/llvm-project/blob/main/clang/lib/Serialization/ASTReader.cpp#L10647). In [`finishPendingActions`](https://github.com/llvm/llvm-project/blob/main/clang/lib/Serialization/ASTReader.cpp#L10028), it tries to [clear out `PendingIncompleteDeclChains`](https://github.com/llvm/llvm-project/blob/main/clang/lib/Serialization/ASTReader.cpp#L10082-L10087). This is done in a loop, which is fine. But, later in `finishPendingActions`, it calls things like `hasBody` [here](https://github.com/llvm/llvm-project/blob/main/clang/lib/Serialization/ASTReader.cpp#L10296). These can call `getMostRecentDecl` / `getNextRedeclaration` that ultimately calls [`CompleteDeclChain`](https://github.com/llvm/llvm-project/blob/main/clang/lib/Serialization/ASTReader.cpp#L7719). `CompleteDeclChain` is "called each time we need the most recent declaration of a declaration after the generation count is incremented." according to [this comment](https://github.com/llvm/llvm-project/blob/main/clang/include/clang/AST/ExternalASTSource.h#L213-L215). Anyway, since we're still in `finishPendingActions` with `NumCurrentElementsDeserializing == 1`, calls to `CompleteDeclChain` simply [adds more stuff to `PendingIncompleteDeclChains`](https://github.com/llvm/llvm-project/blob/main/clang/lib/Serialization/ASTReader.cpp#L7725). ~~I think the emptying out of `PendingIncompleteDeclChains` should actually happen in `FinishedDeserializing`, in [this loop](https://github.com/llvm/llvm-project/blob/main/clang/lib/Serialization/ASTReader.cpp#L10657-L10658) instead.~~ 2. `LazyGenerationalUpdatePtr::get` seems a bit dubious. In the `LazyData` case, it does [the following](https://github.com/llvm/llvm-project/blob/main/clang/include/clang/AST/ExternalASTSource.h#L482-L486): ```cpp if (LazyVal->LastGeneration != LazyVal->ExternalSource->getGeneration()) { LazyVal->LastGeneration = LazyVal->ExternalSource->getGeneration(); (LazyVal->ExternalSource->*Update)(O); } return LazyVal->LastValue; ``` so for example, after `markIncomplete`, `LastGeneration` gets set to `0` to force the update. For example, `LazyVal->LastGeneration == 0` and `LazyVal->ExternalSource->getGeneration() == 6`. The `Update` function pointer calls `CompleteDeclChain`, which, if we're in the middle of deserialization, do nothing and just add the decl to `PendingIncompleteDeclChains`. So the update was not completed, but the `LastGeneration` is updated to `6` now... that seems potentially problematic, since subsequent calls will simply return `LazyVal->LastValue` since the generation numbers match now. I would've maybe expected something like: ``` if (LazyVal->LastGeneration != LazyVal->ExternalSource->getGeneration() && (LazyVal->ExternalSource->*Update)(O)) { LazyVal->LastGeneration = LazyVal->ExternalSource->getGeneration(); } return LazyVal->LastValue; ``` where the generation is updated once the intended update actually happens. # Solution The proposed solution is to perform the marking of
[clang] Delay marking pending incomplete decl chains until the end of `finishPendingActions`. (PR #121245)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Michael Park (mpark) Changes This is fix for an unreachable code path being reached, for an internal use case at Meta. I'm unfortunately still not able to reproduce a minimal example that I can share 😞 # Description There is a defaulted constructor `_Hashtable_alloc() = default;` which ends up in [`CodeGenFunction::GenerateCode`](https://github.com/llvm/llvm-project/blob/48bf0a9457fd60d0872d9b9b4804a95c833a72e1/clang/lib/CodeGen/CodeGenFunction.cpp#L1448) and eventually calls [`FunctionProtoType::canThrow`](https://github.com/llvm/llvm-project/blob/48bf0a9457fd60d0872d9b9b4804a95c833a72e1/clang/lib/AST/Type.cpp#L3758) with `EST_Unevaluated`. In the "good" cases I observed, I see that the decl is also loaded with the `noexcept-unevaluated` state, but it gets fixed up later by a [call to `adjustExceptionSpec`](https://github.com/llvm/llvm-project/blob/48bf0a9457fd60d0872d9b9b4804a95c833a72e1/clang/lib/Serialization/ASTReader.cpp#L10656). The update gets [added to `PendingExceptionSpecUpdates` here](https://github.com/llvm/llvm-project/blob/48bf0a9457fd60d0872d9b9b4804a95c833a72e1/clang/lib/Serialization/ASTReaderDecl.cpp#L4749-L4752). In the "bad" case, the update does not get added to `PendingExceptionSpecUpdates` and hence the call to `adjustExceptionSpec` also does not occur. # Observations I made two observations in Clang Discord: [[1](https://discord.com/channels/636084430946959380/636732781086638081/1317290104431185921)] and [[2](https://discord.com/channels/636084430946959380/636732781086638081/1317291980413206608)]. 1. [FinishedDeserializating](https://github.com/llvm/llvm-project/blob/main/clang/lib/Serialization/ASTReader.cpp#L10641) can exit with stuff still in `PendingIncompleteDeclChains`. `FinishedDeserializing` [calls `finishPendingActions` only if `NumCurrentElementsDeserializing == 1`](https://github.com/llvm/llvm-project/blob/main/clang/lib/Serialization/ASTReader.cpp#L10647). In [`finishPendingActions`](https://github.com/llvm/llvm-project/blob/main/clang/lib/Serialization/ASTReader.cpp#L10028), it tries to [clear out `PendingIncompleteDeclChains`](https://github.com/llvm/llvm-project/blob/main/clang/lib/Serialization/ASTReader.cpp#L10082-L10087). This is done in a loop, which is fine. But, later in `finishPendingActions`, it calls things like `hasBody` [here](https://github.com/llvm/llvm-project/blob/main/clang/lib/Serialization/ASTReader.cpp#L10296). These can call `getMostRecentDecl` / `getNextRedeclaration` that ultimately calls [`CompleteDeclChain`](https://github.com/llvm/llvm-project/blob/main/clang/lib/Serialization/ASTReader.cpp#L7719). `CompleteDeclChain` is "called each time we need the most recent declaration of a declaration after the generation count is incremented." according to [this comment](https://github.com/llvm/llvm-project/blob/main/clang/include/clang/AST/ExternalASTSource.h#L213-L215). Anyway, since we're still in `finishPendingActions` with `NumCurrentElementsDeserializing == 1`, calls to `CompleteDeclChain` simply [adds more stuff to `PendingIncompleteDeclChains`](https://github.com/llvm/llvm-project/blob/main/clang/lib/Serialization/ASTReader.cpp#L7725). ~~I think the emptying out of `PendingIncompleteDeclChains` should actually happen in `FinishedDeserializing`, in [this loop](https://github.com/llvm/llvm-project/blob/main/clang/lib/Serialization/ASTReader.cpp#L10657-L10658) instead.~~ 2. `LazyGenerationalUpdatePtr::get` seems a bit dubious. In the `LazyData` case, it does [the following](https://github.com/llvm/llvm-project/blob/main/clang/include/clang/AST/ExternalASTSource.h#L482-L486): ```cpp if (LazyVal->LastGeneration != LazyVal->ExternalSource->getGeneration()) { LazyVal->LastGeneration = LazyVal->ExternalSource->getGeneration(); (LazyVal->ExternalSource->*Update)(O); } return LazyVal->LastValue; ``` so for example, after `markIncomplete`, `LastGeneration` gets set to `0` to force the update. For example, `LazyVal->LastGeneration == 0` and `LazyVal->ExternalSource->getGeneration() == 6`. The `Update` function pointer calls `CompleteDeclChain`, which, if we're in the middle of deserialization, do nothing and just add the decl to `PendingIncompleteDeclChains`. So the update was not completed, but the `LastGeneration` is updated to `6` now... that seems potentially problematic, since subsequent calls will simply return `LazyVal->LastValue` since the generation numbers match now. I would've maybe expected something like: ``` if (LazyVal->LastGeneration != LazyVal->ExternalSource->getGeneration() && (LazyVal->ExternalSource->*Update)(O)) { LazyVal->LastGeneration = LazyVal->ExternalSource->getGeneration(); } return LazyVal->LastValue; ``` where the generation is updated once the intended update actually happens. # Solution The proposed solution is to perform the mar
[clang-tools-extra] Added options to readability-implicit-bool-conversion (PR #120087)
4m4n-x-B4w4ne wrote: @HerrCai0907 , Thanks I dont have any write permissions. Can you please help me to merge? https://github.com/llvm/llvm-project/pull/120087 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Delay marking pending incomplete decl chains until the end of `finishPendingActions`. (PR #121245)
https://github.com/mpark edited https://github.com/llvm/llvm-project/pull/121245 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Fix zext assertion failure in loop unrolling (PR #121203)
@@ -283,10 +283,12 @@ static bool shouldCompletelyUnroll(const Stmt *LoopStmt, ASTContext &ASTCtx, llvm::APInt InitNum = Matches[0].getNodeAs("initNum")->getValue(); auto CondOp = Matches[0].getNodeAs("conditionOperator"); - if (InitNum.getBitWidth() != BoundNum.getBitWidth()) { -InitNum = InitNum.zext(BoundNum.getBitWidth()); -BoundNum = BoundNum.zext(InitNum.getBitWidth()); - } + unsigned MaxWidth = std::max(InitNum.getBitWidth(), BoundNum.getBitWidth()); shenjunjiekoda wrote: Thank you for your thoughtful feedback! In Clang's AST, `IntegerLiteral` represents unsigned integer values. To represent a literal like `-1`, the AST typically uses a combination of `UnaryOperator(-)` and `IntegerLiteral`. Regarding zero extension (`zext`), it is semantically correct here because `APInt` (the return type of `IntegerLiteral::getValue()`) inherently represents unsigned values. I considered whether tools like `APSIntType` could simplify this logic. However, since this operation deals specifically with unsigned integers (APInt), using APSIntType would introduce unnecessary complexity for signed semantics, which is not required here. The current use of APInt ensures precision and correctness. On whether we could switch to `int64`, I think converting to int64 might not simplify the code too much. Let me know if further clarification or adjustments are needed! https://github.com/llvm/llvm-project/pull/121203 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] Added options to readability-implicit-bool-conversion (PR #120087)
github-actions[bot] wrote: @4m4n-x-B4w4ne Congratulations on having your first Pull Request (PR) merged into the LLVM Project! Your changes will be combined with recent changes from other authors, then tested by our [build bots](https://lab.llvm.org/buildbot/). If there is a problem with a build, you may receive a report in an email or a comment on this PR. Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues. How to do this, and the rest of the post-merge process, is covered in detail [here](https://llvm.org/docs/MyFirstTypoFix.html#myfirsttypofix-issues-after-landing-your-pr). If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of [LLVM development](https://llvm.org/docs/DeveloperPolicy.html#patch-reversion-policy). You can fix your changes and open a new PR to merge them again. If you don't get any reports, no action is required from you. Your changes are working as expected, well done! https://github.com/llvm/llvm-project/pull/120087 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] Added options to readability-implicit-bool-conversion (PR #120087)
llvm-ci wrote: LLVM Buildbot has detected a new failure on builder `clang-aarch64-quick` running on `linaro-clang-aarch64-quick` while building `clang-tools-extra` at step 5 "ninja check 1". Full details are available at: https://lab.llvm.org/buildbot/#/builders/65/builds/9909 Here is the relevant piece of the build log for the reference ``` Step 5 (ninja check 1) failure: stage 1 checked (failure) TEST 'Clang Tools :: clang-tidy/checkers/readability/implicit-bool-conversion-check.cpp' FAILED Exit Code: 1 Command Output (stdout): -- Running ['clang-tidy', '/home/tcwg-buildbot/worker/clang-aarch64-quick/stage1/tools/clang/tools/extra/test/clang-tidy/checkers/readability/Output/implicit-bool-conversion-check.cpp.tmp.cpp', '-fix', '--checks=-*,readability-implicit-bool-conversion', '-config={CheckOptions: { readability-implicit-bool-conversion.CheckConversionsToBool: false, readability-implicit-bool-conversion.CheckConversionsFromBool: true }}', '--', '-std=c23', '-std=c++11', '-nostdinc++']... clang-tidy output --- 3 warnings generated. /home/tcwg-buildbot/worker/clang-aarch64-quick/stage1/tools/clang/tools/extra/test/clang-tidy/checkers/readability/Output/implicit-bool-conversion-check.cpp.tmp.cpp:49:23: warning: implicit conversion 'bool' -> 'int' [readability-implicit-bool-conversion] 49 | int intFromBool = boolValue; // | ^ | static_cast( ) /home/tcwg-buildbot/worker/clang-aarch64-quick/stage1/tools/clang/tools/extra/test/clang-tidy/checkers/readability/Output/implicit-bool-conversion-check.cpp.tmp.cpp:49:23: note: FIX-IT applied suggested code changes /home/tcwg-buildbot/worker/clang-aarch64-quick/stage1/tools/clang/tools/extra/test/clang-tidy/checkers/readability/Output/implicit-bool-conversion-check.cpp.tmp.cpp:49:32: note: FIX-IT applied suggested code changes 49 | int intFromBool = boolValue; // |^ /home/tcwg-buildbot/worker/clang-aarch64-quick/stage1/tools/clang/tools/extra/test/clang-tidy/checkers/readability/Output/implicit-bool-conversion-check.cpp.tmp.cpp:52:27: warning: implicit conversion 'bool' -> 'float' [readability-implicit-bool-conversion] 52 | float floatFromBool = boolValue; // | ^ | static_cast( ) /home/tcwg-buildbot/worker/clang-aarch64-quick/stage1/tools/clang/tools/extra/test/clang-tidy/checkers/readability/Output/implicit-bool-conversion-check.cpp.tmp.cpp:52:27: note: FIX-IT applied suggested code changes /home/tcwg-buildbot/worker/clang-aarch64-quick/stage1/tools/clang/tools/extra/test/clang-tidy/checkers/readability/Output/implicit-bool-conversion-check.cpp.tmp.cpp:52:36: note: FIX-IT applied suggested code changes 52 | float floatFromBool = boolValue; // |^ /home/tcwg-buildbot/worker/clang-aarch64-quick/stage1/tools/clang/tools/extra/test/clang-tidy/checkers/readability/Output/implicit-bool-conversion-check.cpp.tmp.cpp:55:25: warning: implicit conversion 'bool' -> 'char' [readability-implicit-bool-conversion] 55 | char charFromBool = boolValue; // | ^ | static_cast( ) /home/tcwg-buildbot/worker/clang-aarch64-quick/stage1/tools/clang/tools/extra/test/clang-tidy/checkers/readability/Output/implicit-bool-conversion-check.cpp.tmp.cpp:55:25: note: FIX-IT applied suggested code changes /home/tcwg-buildbot/worker/clang-aarch64-quick/stage1/tools/clang/tools/extra/test/clang-tidy/checkers/readability/Output/implicit-bool-conversion-check.cpp.tmp.cpp:55:34: note: FIX-IT applied suggested code changes 55 | char charFromBool = boolValue; // | ^ clang-tidy applied 6 of 6 suggested fixes. -- diff -u /home/tcwg-buildbot/worker/clang-aarch64-quick/stage1/tools/clang/tools/extra/test/clang-tidy/checkers/readability/Output/implicit-bool-conversion-check.cpp.tmp.orig /home/tcwg-buildbot/worker/clang-aarch64-quick/stage1/tools/clang/tools/extra/test/clang-tidy/checkers/readability/Output/implicit-bool-conversion-check.cpp.tmp.cpp failed: --- /home/tcwg-buildbot/worker/clang-aarch64-quick/stage1/tools/clang/tools/extra/test/clang-tidy/checkers/readability/Output/implicit-bool-conversion-check.cpp.tmp.orig 2024-12-28 07:42:25.253479184 + +++ /home/tcwg-buildbot/worker/clang-aarch64-quick/stage1/tools/clang/tools/extra/test/clang-tidy/checkers/readability/Output/implicit-bool-conversion-check.cpp.tmp.cpp 2024-12-28 07:42:25.357479722 + @@ -46,12 +46,12 @@ // Conversions from bool to other types bool boolValue = true; -int intFromBool = boolValue; // +int intFromBool = static_cast(boolValue);
[clang-tools-extra] [clangd] Allow specifying what headers are always included via "" or <> (PR #67749)
HighCommander4 wrote: Thank you @kleinesfilmroellchen for your contribution! https://github.com/llvm/llvm-project/pull/67749 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] add depercation warning for non-whitelisted global options (PR #121057)
https://github.com/HerrCai0907 updated https://github.com/llvm/llvm-project/pull/121057 >From 98d65a0b9a1189ce73d97d76527b458f93f17b43 Mon Sep 17 00:00:00 2001 From: Congcong Cai Date: Tue, 24 Dec 2024 23:32:02 +0800 Subject: [PATCH 1/3] [clang-tidy] add depercation warning for non-whitelisted global options --- .../clang-tidy/ClangTidyCheck.cpp | 32 --- .../checkers/modernize/use-std-format-fmt.cpp | 2 +- .../deprecation-global-option.cpp | 3 ++ 3 files changed, 25 insertions(+), 12 deletions(-) create mode 100644 clang-tools-extra/test/clang-tidy/infrastructure/deprecation-global-option.cpp diff --git a/clang-tools-extra/clang-tidy/ClangTidyCheck.cpp b/clang-tools-extra/clang-tidy/ClangTidyCheck.cpp index 6028bb2258136b..5161ffeedf70df 100644 --- a/clang-tools-extra/clang-tidy/ClangTidyCheck.cpp +++ b/clang-tools-extra/clang-tidy/ClangTidyCheck.cpp @@ -7,11 +7,11 @@ //===--===// #include "ClangTidyCheck.h" -#include "llvm/ADT/SmallString.h" #include "llvm/ADT/StringRef.h" -#include "llvm/Support/Error.h" +#include "llvm/ADT/StringSet.h" #include "llvm/Support/YAMLParser.h" #include +#include namespace clang::tidy { @@ -62,16 +62,29 @@ ClangTidyCheck::OptionsView::get(StringRef LocalName) const { return std::nullopt; } +static const llvm::StringSet<> DeprecatedGlobalOptions{ +"StrictMode", +"IgnoreMacros", +}; + static ClangTidyOptions::OptionMap::const_iterator findPriorityOption(const ClangTidyOptions::OptionMap &Options, StringRef NamePrefix, StringRef LocalName, - llvm::StringSet<> *Collector) { + ClangTidyContext *Context) { + llvm::StringSet<> *Collector = Context->getOptionsCollector(); if (Collector) { Collector->insert((NamePrefix + LocalName).str()); Collector->insert(LocalName); } auto IterLocal = Options.find((NamePrefix + LocalName).str()); auto IterGlobal = Options.find(LocalName); + // FIXME: temporary solution for deprecation warnings, should be removed + // after 22.x. + if (IterGlobal != Options.end() && + DeprecatedGlobalOptions.contains(LocalName)) +Context->configurationDiag( +"deprecation global option '%0', please use '%1%0'.") +<< LocalName << NamePrefix; if (IterLocal == Options.end()) return IterGlobal; if (IterGlobal == Options.end()) @@ -83,8 +96,7 @@ findPriorityOption(const ClangTidyOptions::OptionMap &Options, std::optional ClangTidyCheck::OptionsView::getLocalOrGlobal(StringRef LocalName) const { - auto Iter = findPriorityOption(CheckOptions, NamePrefix, LocalName, - Context->getOptionsCollector()); + auto Iter = findPriorityOption(CheckOptions, NamePrefix, LocalName, Context); if (Iter != CheckOptions.end()) return StringRef(Iter->getValue().Value); return std::nullopt; @@ -117,8 +129,7 @@ ClangTidyCheck::OptionsView::get(StringRef LocalName) const { template <> std::optional ClangTidyCheck::OptionsView::getLocalOrGlobal(StringRef LocalName) const { - auto Iter = findPriorityOption(CheckOptions, NamePrefix, LocalName, - Context->getOptionsCollector()); + auto Iter = findPriorityOption(CheckOptions, NamePrefix, LocalName, Context); if (Iter != CheckOptions.end()) { if (auto Result = getAsBool(Iter->getValue().Value, Iter->getKey())) return Result; @@ -157,10 +168,9 @@ std::optional ClangTidyCheck::OptionsView::getEnumInt( bool IgnoreCase) const { if (!CheckGlobal && Context->getOptionsCollector()) Context->getOptionsCollector()->insert((NamePrefix + LocalName).str()); - auto Iter = CheckGlobal - ? findPriorityOption(CheckOptions, NamePrefix, LocalName, - Context->getOptionsCollector()) - : CheckOptions.find((NamePrefix + LocalName).str()); + auto Iter = CheckGlobal ? findPriorityOption(CheckOptions, NamePrefix, + LocalName, Context) + : CheckOptions.find((NamePrefix + LocalName).str()); if (Iter == CheckOptions.end()) return std::nullopt; diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-format-fmt.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-format-fmt.cpp index 1eaf18ac119966..71c8af190467cf 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-format-fmt.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-format-fmt.cpp @@ -1,6 +1,6 @@ // RUN: %check_clang_tidy %s modernize-use-std-format %t -- \ // RUN: -config="{CheckOptions: { \ -// RUN: StrictMode: true, \ +// RUN: modernize-use-std-format.StrictMode: true, \ // RUN: modernize-use-std-format.StrFormatLikeFunctions: 'fmt::sprintf', \ // RUN:
[clang] [clang-format] Add `AllowShortNamespacesOnASingleLine` option (PR #105597)
https://github.com/owenca edited https://github.com/llvm/llvm-project/pull/105597 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [libcxx] [Clang] Add __builtin_common_reference (PR #121199)
github-actions[bot] wrote: :warning: C/C++ code formatter, clang-format found issues in your code. :warning: You can test this locally with the following command: ``bash git-clang-format --diff f334db92be168876b618db72dc93078ce23ffa89 e0db7316b2705398a2ac7e69cd1e3e83ece52613 --extensions h,cpp -- clang/test/SemaCXX/type-trait-common-reference.cpp clang/include/clang/AST/ASTContext.h clang/include/clang/AST/ASTNodeTraverser.h clang/include/clang/AST/DeclID.h clang/include/clang/AST/DeclTemplate.h clang/include/clang/AST/RecursiveASTVisitor.h clang/include/clang/Basic/Builtins.h clang/include/clang/Sema/Sema.h clang/lib/AST/ASTContext.cpp clang/lib/AST/ASTImporter.cpp clang/lib/AST/DeclBase.cpp clang/lib/AST/DeclTemplate.cpp clang/lib/CodeGen/CGDecl.cpp clang/lib/Lex/PPMacroExpansion.cpp clang/lib/Sema/SemaExprCXX.cpp clang/lib/Sema/SemaLookup.cpp clang/lib/Sema/SemaTemplate.cpp clang/lib/Sema/SemaTemplateInstantiateDecl.cpp clang/lib/Sema/SemaType.cpp clang/lib/Serialization/ASTCommon.cpp clang/lib/Serialization/ASTReader.cpp clang/lib/Serialization/ASTWriter.cpp clang/tools/libclang/CIndex.cpp libcxx/include/__type_traits/common_reference.h `` View the diff from clang-format here. ``diff diff --git a/clang/include/clang/AST/DeclTemplate.h b/clang/include/clang/AST/DeclTemplate.h index b765e0d17c..e94dcdb612 100644 --- a/clang/include/clang/AST/DeclTemplate.h +++ b/clang/include/clang/AST/DeclTemplate.h @@ -1807,9 +1807,7 @@ public: return new (C, DC) CVRefQualifyingTemplateDecl(C, DC, Ref); } - SourceRange getSourceRange() const override LLVM_READONLY { -return {}; - } + SourceRange getSourceRange() const override LLVM_READONLY { return {}; } CVRefQuals getQuals() { return Quals; } }; diff --git a/clang/lib/AST/DeclTemplate.cpp b/clang/lib/AST/DeclTemplate.cpp index 635e2eb348..c43ebb2086 100644 --- a/clang/lib/AST/DeclTemplate.cpp +++ b/clang/lib/AST/DeclTemplate.cpp @@ -1697,11 +1697,9 @@ static TemplateParameterList *createBuiltinCommonTypeList(const ASTContext &C, nullptr); } -static TemplateTypeParmDecl *BICreateTemplateParm(const ASTContext &C, - DeclContext *DC, - unsigned Depth, - unsigned Position, - bool ParameterPack = false) { +static TemplateTypeParmDecl * +BICreateTemplateParm(const ASTContext &C, DeclContext *DC, unsigned Depth, + unsigned Position, bool ParameterPack = false) { return TemplateTypeParmDecl::Create( C, DC, SourceLocation(), SourceLocation(), Depth, Position, /*Id=*/nullptr, /*Typename=*/false, ParameterPack); @@ -1733,8 +1731,8 @@ createBuiltinCommonReferenceBasicCommonReferenceT(const ASTContext &C, /*Position=*/0); } -static TemplateParameterList *createBuiltinCommonReferenceList(const ASTContext &C, - DeclContext *DC) { +static TemplateParameterList * +createBuiltinCommonReferenceList(const ASTContext &C, DeclContext *DC) { // template class, template class> // class auto *BasicCommonReference = diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp index 4706013ff7..6672fdedd0 100644 --- a/clang/lib/Sema/SemaTemplate.cpp +++ b/clang/lib/Sema/SemaTemplate.cpp @@ -3232,26 +3232,24 @@ static QualType CondRes(Sema &S, QualType X, QualType Y, SourceLocation Loc) { Sema::ContextRAII TUContext(S, S.Context.getTranslationUnitDecl()); // false - OpaqueValueExpr CondExpr(SourceLocation(), S.Context.BoolTy, -VK_PRValue); + OpaqueValueExpr CondExpr(SourceLocation(), S.Context.BoolTy, VK_PRValue); ExprResult Cond = &CondExpr; // declval()() OpaqueValueExpr LHSExpr(Loc, X.getNonLValueExprType(S.Context), - Expr::getValueKindForType(X)); + Expr::getValueKindForType(X)); ExprResult LHS = &LHSExpr; // declval()() OpaqueValueExpr RHSExpr(Loc, Y.getNonLValueExprType(S.Context), - Expr::getValueKindForType(Y)); + Expr::getValueKindForType(Y)); ExprResult RHS = &RHSExpr; ExprValueKind VK = VK_PRValue; ExprObjectKind OK = OK_Ordinary; // decltype(false ? declval()() : declval()()) - QualType Result = - S.CheckConditionalOperands(Cond, LHS, RHS, VK, OK, Loc); + QualType Result = S.CheckConditionalOperands(Cond, LHS, RHS, VK, OK, Loc); if (SFINAE.hasErrorOccurred()) return QualType(); @@ -3260,8 +3258,7 @@ static QualType CondRes(Sema &S, QualType X, QualType Y, SourceLocation Loc) { return Result; } -static QualType CommonRef(Sema &S, QualType A, QualType B, - SourceLocation Loc) { +static QualType CommonRef(Se
[clang] [Clang] Add float type support to __builtin_reduce_add and __builtin_reduce_multipy (PR #120367)
https://github.com/farzonl updated https://github.com/llvm/llvm-project/pull/120367 >From d72983f1666cc6952edd9a721a4f1dc2d1a5a8ed Mon Sep 17 00:00:00 2001 From: Farzon Lotfi Date: Wed, 18 Dec 2024 01:44:42 -0500 Subject: [PATCH 1/2] [Clang] Add float type support to __builtin_reduce_add and __builtin_reduce_multipy --- .../clang/Basic/DiagnosticSemaKinds.td| 3 +- clang/lib/AST/ByteCode/InterpBuiltin.cpp | 12 clang/lib/CodeGen/CGBuiltin.cpp | 29 +-- clang/lib/Sema/SemaChecking.cpp | 26 +++-- clang/test/AST/ByteCode/builtin-functions.cpp | 15 ++ clang/test/CodeGen/builtins-reduction-math.c | 21 ++ clang/test/Sema/builtins-reduction-math.c | 16 +- clang/test/Sema/constant_builtins_vector.cpp | 12 8 files changed, 120 insertions(+), 14 deletions(-) diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 330ae045616aba..5d3ea41565257c 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -12355,7 +12355,8 @@ def err_builtin_invalid_arg_type: Error < "a vector of integers|" "an unsigned integer|" "an 'int'|" - "a vector of floating points}1 (was %2)">; + "a vector of floating points|" + "a vector of integers or floating points}1 (was %2)">; def err_builtin_matrix_disabled: Error< "matrix types extension is disabled. Pass -fenable-matrix to enable it">; diff --git a/clang/lib/AST/ByteCode/InterpBuiltin.cpp b/clang/lib/AST/ByteCode/InterpBuiltin.cpp index 2ae91feb2d9e8e..78f52eeac750c7 100644 --- a/clang/lib/AST/ByteCode/InterpBuiltin.cpp +++ b/clang/lib/AST/ByteCode/InterpBuiltin.cpp @@ -7,6 +7,7 @@ //===--===// #include "../ExprConstShared.h" #include "Boolean.h" +#include "ByteCode/Floating.h" #include "Compiler.h" #include "EvalEmitter.h" #include "Interp.h" @@ -1754,6 +1755,17 @@ static bool interp__builtin_vector_reduce(InterpState &S, CodePtr OpPC, PrimType ElemT = *S.getContext().classify(ElemType); unsigned NumElems = Arg.getNumElems(); + if (ElemType->isRealFloatingType()) { +if (ID != Builtin::BI__builtin_reduce_add && +ID != Builtin::BI__builtin_reduce_mul) + llvm_unreachable("Only reduce_add and reduce_mul are supported for " + "floating-point types."); +// Floating-point arithmetic is not valid for constant expression +// initialization. Returning false defers checks to integral constant +// expression validation, preventing a bad deref of Floating as an integer. +return false; + } + INT_TYPE_SWITCH_NO_BOOL(ElemT, { T Result = Arg.atIndex(0).deref(); unsigned BitWidth = Result.bitWidth(); diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp index 4d4b7428abd505..12e3cb18bdb89d 100644 --- a/clang/lib/CodeGen/CGBuiltin.cpp +++ b/clang/lib/CodeGen/CGBuiltin.cpp @@ -4274,12 +4274,37 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID, *this, E, GetIntrinsicID(E->getArg(0)->getType()), "rdx.min")); } - case Builtin::BI__builtin_reduce_add: + case Builtin::BI__builtin_reduce_add: { +// Note: vector_reduce_fadd takes two arguments a +// scalar start value and a vector. That would mean to +// correctly call it we would need emitBuiltinWithOneOverloadedType<2> +// To keep the builtin sema behavior the same despite type we will +// popululate vector_reduce_fadd scalar value with a 0. +if (E->getArg(0)->getType()->hasFloatingRepresentation()) { + Value *X = EmitScalarExpr(E->getArg(0)); + auto EltTy = X->getType()->getScalarType(); + Value *Seed = ConstantFP::get(EltTy, 0); + return RValue::get(Builder.CreateIntrinsic( + /*ReturnType=*/EltTy, llvm::Intrinsic::vector_reduce_fadd, + ArrayRef{Seed, X}, nullptr, "rdx.fadd")); +} +assert(E->getArg(0)->getType()->hasIntegerRepresentation()); return RValue::get(emitBuiltinWithOneOverloadedType<1>( *this, E, llvm::Intrinsic::vector_reduce_add, "rdx.add")); - case Builtin::BI__builtin_reduce_mul: + } + case Builtin::BI__builtin_reduce_mul: { +if (E->getArg(0)->getType()->hasFloatingRepresentation()) { + Value *X = EmitScalarExpr(E->getArg(0)); + auto EltTy = X->getType()->getScalarType(); + Value *Seed = ConstantFP::get(EltTy, 0); + return RValue::get(Builder.CreateIntrinsic( + /*ReturnType=*/EltTy, llvm::Intrinsic::vector_reduce_fmul, + ArrayRef{Seed, X}, nullptr, "rdx.fmul")); +} +assert(E->getArg(0)->getType()->hasIntegerRepresentation()); return RValue::get(emitBuiltinWithOneOverloadedType<1>( *this, E, llvm::Intrinsic::vector_reduce_mul, "rdx.mul")); + } case Builtin::BI__builtin_reduce_xor: return RV
[clang] [compiler-rt] [llvm] [Coverage] Move SingleByteCoverage out of CountedRegion (PR #110966)
https://github.com/chapuni edited https://github.com/llvm/llvm-project/pull/110966 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Added nullptr check to getFriendDecl access (PR #121056)
@@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s +// expected-no-diagnostics + +// Ensure the following out of line friend declaration doesn't cause the compiler to crash. + +class A { + friend bool operator==(const A&, const A&); + friend class B; +}; + +bool operator==(const A&, const A&) = default; + cor3ntin wrote: I found a couple additional tests that are interesting (the second of which happens to crash gcc) https://compiler-explorer.com/z/eb6PeP6ar https://github.com/llvm/llvm-project/pull/121056 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libcxx] [libcxxabi] [libunwind] [llvm] [libc++] Enable -Wmissing-prototypes (PR #116261)
https://github.com/philnik777 updated https://github.com/llvm/llvm-project/pull/116261 >From 4efe922727331e091d27c8eb3e2431d6349b1a40 Mon Sep 17 00:00:00 2001 From: Nikolas Klauser Date: Thu, 14 Nov 2024 18:30:39 +0100 Subject: [PATCH] [libc++] Enable -Wmissing-prototypes --- libcxx/src/charconv.cpp| 5 - libcxx/src/experimental/time_zone.cpp | 2 +- libcxx/src/experimental/tzdb.cpp | 3 +++ libcxx/src/filesystem/int128_builtins.cpp | 2 ++ libcxx/src/include/from_chars_floating_point.h | 4 ++-- libcxxabi/src/cxa_personality.cpp | 5 + libcxxabi/src/private_typeinfo.cpp | 6 ++ libunwind/src/UnwindLevel1.c | 1 - libunwind/src/libunwind_ext.h | 1 + runtimes/cmake/Modules/WarningFlags.cmake | 1 + 10 files changed, 25 insertions(+), 5 deletions(-) diff --git a/libcxx/src/charconv.cpp b/libcxx/src/charconv.cpp index 5e8cb7d97703b4..4621df05066997 100644 --- a/libcxx/src/charconv.cpp +++ b/libcxx/src/charconv.cpp @@ -18,9 +18,12 @@ _LIBCPP_BEGIN_NAMESPACE_STD namespace __itoa { +_LIBCPP_DIAGNOSTIC_PUSH +_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wmissing-prototypes") +// These functions exist for ABI compatibility, so we don't ever want a declaration. _LIBCPP_EXPORTED_FROM_ABI char* __u32toa(uint32_t value, char* buffer) noexcept { return __base_10_u32(buffer, value); } - _LIBCPP_EXPORTED_FROM_ABI char* __u64toa(uint64_t value, char* buffer) noexcept { return __base_10_u64(buffer, value); } +_LIBCPP_DIAGNOSTIC_POP } // namespace __itoa diff --git a/libcxx/src/experimental/time_zone.cpp b/libcxx/src/experimental/time_zone.cpp index 764a89ab513c86..c5ba94321e07ce 100644 --- a/libcxx/src/experimental/time_zone.cpp +++ b/libcxx/src/experimental/time_zone.cpp @@ -711,7 +711,7 @@ __get_sys_info(sys_seconds __time, // Iff the "offsets" are the same '__current.__end' is replaced with // '__next.__end', which effectively merges the two objects in one object. The // function returns true if a merge occurred. -[[nodiscard]] bool __merge_continuation(sys_info& __current, const sys_info& __next) { +[[nodiscard]] static bool __merge_continuation(sys_info& __current, const sys_info& __next) { if (__current.end != __next.begin) return false; diff --git a/libcxx/src/experimental/tzdb.cpp b/libcxx/src/experimental/tzdb.cpp index d22de21c998198..10333795274212 100644 --- a/libcxx/src/experimental/tzdb.cpp +++ b/libcxx/src/experimental/tzdb.cpp @@ -45,6 +45,8 @@ _LIBCPP_BEGIN_NAMESPACE_STD namespace chrono { +_LIBCPP_DIAGNOSTIC_PUSH +_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wmissing-prototypes") // This function is weak so it can be overriden in the tests. The // declaration is in the test header test/support/test_tzdb.h _LIBCPP_WEAK string_view __libcpp_tzdb_directory() { @@ -54,6 +56,7 @@ _LIBCPP_WEAK string_view __libcpp_tzdb_directory() { # error "unknown path to the IANA Time Zone Database" #endif } +_LIBCPP_DIAGNOSTIC_POP //===--===// // Details diff --git a/libcxx/src/filesystem/int128_builtins.cpp b/libcxx/src/filesystem/int128_builtins.cpp index da6f39e7d78b60..e811b3e6f912db 100644 --- a/libcxx/src/filesystem/int128_builtins.cpp +++ b/libcxx/src/filesystem/int128_builtins.cpp @@ -16,6 +16,8 @@ #include <__config> #include +_LIBCPP_CLANG_DIAGNOSTIC_IGNORED("-Wmissing-prototypes") // See the FIXME above + #if _LIBCPP_HAS_INT128 extern "C" __attribute__((no_sanitize("undefined"))) _LIBCPP_EXPORTED_FROM_ABI __int128_t diff --git a/libcxx/src/include/from_chars_floating_point.h b/libcxx/src/include/from_chars_floating_point.h index 19eeeb28fb08d2..81d2180cc94805 100644 --- a/libcxx/src/include/from_chars_floating_point.h +++ b/libcxx/src/include/from_chars_floating_point.h @@ -193,7 +193,7 @@ struct __exponent_result { // __offset, 0, false. This allows using the results unconditionally, the // __present is important for the scientific notation, where the value is // mandatory. -__exponent_result __parse_exponent(const char* __input, size_t __n, size_t __offset, char __marker) { +static __exponent_result __parse_exponent(const char* __input, size_t __n, size_t __offset, char __marker) { if (__offset + 1 < __n && // an exponent always needs at least one digit. std::tolower(__input[__offset]) == __marker && // !std::isspace(__input[__offset + 1]) // leading whitespace is not allowed. @@ -213,7 +213,7 @@ __exponent_result __parse_exponent(const char* __input, size_t __n, size_t __off } // Here we do this operation as int64 to avoid overflow. -int32_t __merge_exponents(int64_t __fractional, int64_t __exponent, int __max_biased_exponent) { +static int32_t __merge_exponents(int64_t __fractional, int64_t __exponent, int __max_biased_exponent) { int64_t __sum = __fractional + __exponent;
[clang] [libcxx] [Clang] Add __builtin_common_reference (PR #121199)
https://github.com/philnik777 created https://github.com/llvm/llvm-project/pull/121199 None >From e0db7316b2705398a2ac7e69cd1e3e83ece52613 Mon Sep 17 00:00:00 2001 From: Nikolas Klauser Date: Fri, 27 Sep 2024 22:11:14 +0200 Subject: [PATCH] [Clang] Add __builtin_common_reference --- clang/docs/LanguageExtensions.rst | 17 ++ clang/include/clang/AST/ASTContext.h | 13 + clang/include/clang/AST/ASTNodeTraverser.h| 4 + clang/include/clang/AST/DeclID.h | 3 + clang/include/clang/AST/DeclTemplate.h| 37 +++ clang/include/clang/AST/RecursiveASTVisitor.h | 4 + clang/include/clang/Basic/Builtins.h | 3 + clang/include/clang/Basic/DeclNodes.td| 1 + clang/include/clang/Sema/Sema.h | 19 ++ clang/lib/AST/ASTContext.cpp | 31 ++ clang/lib/AST/ASTImporter.cpp | 3 + clang/lib/AST/DeclBase.cpp| 1 + clang/lib/AST/DeclTemplate.cpp| 102 +++ clang/lib/CodeGen/CGDecl.cpp | 1 + clang/lib/Lex/PPMacroExpansion.cpp| 1 + clang/lib/Sema/SemaExprCXX.cpp| 92 +- clang/lib/Sema/SemaLookup.cpp | 4 + clang/lib/Sema/SemaTemplate.cpp | 275 -- .../lib/Sema/SemaTemplateInstantiateDecl.cpp | 5 + clang/lib/Sema/SemaType.cpp | 73 + clang/lib/Serialization/ASTCommon.cpp | 1 + clang/lib/Serialization/ASTReader.cpp | 6 + clang/lib/Serialization/ASTWriter.cpp | 2 + .../SemaCXX/type-trait-common-reference.cpp | 120 clang/tools/libclang/CIndex.cpp | 1 + .../include/__type_traits/common_reference.h | 36 ++- 26 files changed, 738 insertions(+), 117 deletions(-) create mode 100644 clang/test/SemaCXX/type-trait-common-reference.cpp diff --git a/clang/docs/LanguageExtensions.rst b/clang/docs/LanguageExtensions.rst index 3d4f68b818bce7..09311f3e1233d9 100644 --- a/clang/docs/LanguageExtensions.rst +++ b/clang/docs/LanguageExtensions.rst @@ -1546,6 +1546,23 @@ Builtin type aliases Clang provides a few builtin aliases to improve the throughput of certain metaprogramming facilities. +__builtin_common_reference +-- + +.. code-block:: c++ + + template class, template class> class BasicCommonReferenceT, +template CommonTypeT, +template HasTypeMember, +class HasNoTypeMember, +class... Ts> + using __builtin_common_reference = ...; + +This alias is used for implementing ``std::common_refernce``. If ``std::common_reference`` should contain a ``type`` +member, it is an alias to ``HasTypeMember``. Otherwse it is an alias to ``HasNoTypeMember``. The +``CommonTypeT`` is usually ``std::common_type_t``. ``BasicCommonReferenceT`` is usually an alias template to +``basic_common_reference::type``. + __builtin_common_type - diff --git a/clang/include/clang/AST/ASTContext.h b/clang/include/clang/AST/ASTContext.h index 1e89a6805ce9c6..3c18e73cdc391a 100644 --- a/clang/include/clang/AST/ASTContext.h +++ b/clang/include/clang/AST/ASTContext.h @@ -419,6 +419,9 @@ class ASTContext : public RefCountedBase { /// The identifier '__builtin_common_type'. mutable IdentifierInfo *BuiltinCommonTypeName = nullptr; + /// The identifier '__builtin_common_reference'. + mutable IdentifierInfo *BuiltinCommonReferenceName = nullptr; + QualType ObjCConstantStringType; mutable RecordDecl *CFConstantStringTagDecl = nullptr; mutable TypedefDecl *CFConstantStringTypeDecl = nullptr; @@ -627,6 +630,8 @@ class ASTContext : public RefCountedBase { mutable BuiltinTemplateDecl *MakeIntegerSeqDecl = nullptr; mutable BuiltinTemplateDecl *TypePackElementDecl = nullptr; mutable BuiltinTemplateDecl *BuiltinCommonTypeDecl = nullptr; + mutable BuiltinTemplateDecl *BuiltinCommonReferenceDecl = nullptr; + mutable CVRefQualifyingTemplateDecl *CVRefQualifyingDecls[12] = {}; /// The associated SourceManager object. SourceManager &SourceMgr; @@ -1155,6 +1160,8 @@ class ASTContext : public RefCountedBase { BuiltinTemplateDecl *getMakeIntegerSeqDecl() const; BuiltinTemplateDecl *getTypePackElementDecl() const; BuiltinTemplateDecl *getBuiltinCommonTypeDecl() const; + BuiltinTemplateDecl *getBuiltinCommonReferenceDecl() const; + CVRefQualifyingTemplateDecl *getCVRefQualifyingAliasDecl(QualType From) const; // Builtin Types. CanQualType VoidTy; @@ -2072,6 +2079,12 @@ class ASTContext : public RefCountedBase { return BuiltinCommonTypeName; } + IdentifierInfo *getBuiltinCommonReferenceName() const { +if (!BuiltinCommonReferenceName) + BuiltinCommonReferenceName = &Idents.get("__builtin_common_reference"); +return BuiltinCommonReferenceName; + } + /// Retrieve the Objective-C "instancetype" type, if already known; /// otherwise, returns a NULL type;
[clang] [analyzer] Fix zext assertion failure in loop unrolling (PR #121203)
github-actions[bot] wrote: :warning: C/C++ code formatter, clang-format found issues in your code. :warning: You can test this locally with the following command: ``bash git-clang-format --diff 223521b13e7465bc177f43e22de526b777d6ff74 3bcf5c8f05df2f62a9ef13537b813e7df2871d1b --extensions cpp -- clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp `` View the diff from clang-format here. ``diff diff --git a/clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp b/clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp index e3b27e2271..9227a7876c 100644 --- a/clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp +++ b/clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp @@ -286,9 +286,9 @@ static bool shouldCompletelyUnroll(const Stmt *LoopStmt, ASTContext &ASTCtx, unsigned MaxWidth = std::max(InitNum.getBitWidth(), BoundNum.getBitWidth()); if (InitNum.getBitWidth() != MaxWidth) - InitNum = InitNum.zext(MaxWidth); +InitNum = InitNum.zext(MaxWidth); if (BoundNum.getBitWidth() != MaxWidth) - BoundNum = BoundNum.zext(MaxWidth); +BoundNum = BoundNum.zext(MaxWidth); if (CondOp->getOpcode() == BO_GE || CondOp->getOpcode() == BO_LE) maxStep = (BoundNum - InitNum + 1).abs().getZExtValue(); `` https://github.com/llvm/llvm-project/pull/121203 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Fix zext assertion failure in loop unrolling (PR #121203)
steakhal wrote: Hey, could you add a test for this PR that would crash on main, but wouldn't with this patch? https://github.com/llvm/llvm-project/pull/121203 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Fix zext assertion failure in loop unrolling (PR #121203)
https://github.com/shenjunjiekoda updated https://github.com/llvm/llvm-project/pull/121203 >From 2cee5fc2abd0cf2979c9ba975906e659adcd4463 Mon Sep 17 00:00:00 2001 From: shenjunjie Date: Fri, 27 Dec 2024 14:08:55 + Subject: [PATCH] [analyzer] Fix zext assertion failure in loop unrolling --- clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp | 10 ++ 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp b/clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp index 96f5d7c44baf89..9227a7876c0b2f 100644 --- a/clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp +++ b/clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp @@ -283,10 +283,12 @@ static bool shouldCompletelyUnroll(const Stmt *LoopStmt, ASTContext &ASTCtx, llvm::APInt InitNum = Matches[0].getNodeAs("initNum")->getValue(); auto CondOp = Matches[0].getNodeAs("conditionOperator"); - if (InitNum.getBitWidth() != BoundNum.getBitWidth()) { -InitNum = InitNum.zext(BoundNum.getBitWidth()); -BoundNum = BoundNum.zext(InitNum.getBitWidth()); - } + unsigned MaxWidth = std::max(InitNum.getBitWidth(), BoundNum.getBitWidth()); + + if (InitNum.getBitWidth() != MaxWidth) +InitNum = InitNum.zext(MaxWidth); + if (BoundNum.getBitWidth() != MaxWidth) +BoundNum = BoundNum.zext(MaxWidth); if (CondOp->getOpcode() == BO_GE || CondOp->getOpcode() == BO_LE) maxStep = (BoundNum - InitNum + 1).abs().getZExtValue(); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [RISCV] Add Qualcomm uC Xqciac (Load-Store Adress calculation) extension (PR #121037)
@@ -184,6 +191,37 @@ let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in { } // hasSideEffects = 0, mayLoad = 0, mayStore = 0 } // Predicates = [HasVendorXqcia, IsRV32], DecoderNamespace = "Xqcia" +let Predicates = [HasVendorXqciac, IsRV32], DecoderNamespace = "Xqciac" in { +let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in { + def QC_C_MULADDI : RVInst16CL<0b001, 0b10, (outs GPRC:$rd_wb), + (ins GPRC:$rd, GPRC:$rs1, uimm5:$uimm), + "qc.c.muladdi", "$rd, $rs1, $uimm"> { +let Constraints = "$rd = $rd_wb"; +bits<5> uimm; + +let Inst{12-10} = uimm{3-1}; +let Inst{6} = uimm{0}; +let Inst{5} = uimm{4}; + } topperc wrote: Why does the whole extension depend on Zca instead of just qc.c.muladdi? https://github.com/llvm/llvm-project/pull/121037 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Fix zext assertion failure in loop unrolling (PR #121203)
https://github.com/shenjunjiekoda updated https://github.com/llvm/llvm-project/pull/121203 >From 2cee5fc2abd0cf2979c9ba975906e659adcd4463 Mon Sep 17 00:00:00 2001 From: shenjunjie Date: Fri, 27 Dec 2024 14:08:55 + Subject: [PATCH 1/5] [analyzer] Fix zext assertion failure in loop unrolling --- clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp | 10 ++ 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp b/clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp index 96f5d7c44baf89..9227a7876c0b2f 100644 --- a/clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp +++ b/clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp @@ -283,10 +283,12 @@ static bool shouldCompletelyUnroll(const Stmt *LoopStmt, ASTContext &ASTCtx, llvm::APInt InitNum = Matches[0].getNodeAs("initNum")->getValue(); auto CondOp = Matches[0].getNodeAs("conditionOperator"); - if (InitNum.getBitWidth() != BoundNum.getBitWidth()) { -InitNum = InitNum.zext(BoundNum.getBitWidth()); -BoundNum = BoundNum.zext(InitNum.getBitWidth()); - } + unsigned MaxWidth = std::max(InitNum.getBitWidth(), BoundNum.getBitWidth()); + + if (InitNum.getBitWidth() != MaxWidth) +InitNum = InitNum.zext(MaxWidth); + if (BoundNum.getBitWidth() != MaxWidth) +BoundNum = BoundNum.zext(MaxWidth); if (CondOp->getOpcode() == BO_GE || CondOp->getOpcode() == BO_LE) maxStep = (BoundNum - InitNum + 1).abs().getZExtValue(); >From a4d3a24ea797c5f53c5171e05f7172434096bd65 Mon Sep 17 00:00:00 2001 From: shenjunjie Date: Fri, 27 Dec 2024 14:20:23 + Subject: [PATCH 2/5] add testcase --- clang/test/Analysis/PR121201.cpp | 50 1 file changed, 50 insertions(+) create mode 100644 clang/test/Analysis/PR121201.cpp diff --git a/clang/test/Analysis/PR121201.cpp b/clang/test/Analysis/PR121201.cpp new file mode 100644 index 00..a2cea89dc10b79 --- /dev/null +++ b/clang/test/Analysis/PR121201.cpp @@ -0,0 +1,50 @@ + +template < bool, typename T, typename > using conditional_t = T; +class basic_format_arg; +template < typename > struct formatter; +template < typename Context > struct value { + template < typename T > value(T) { +using value_type = T; +format_custom_arg< +value_type, typename Context::template formatter_type< value_type > >; + } + template < typename, typename Formatter > static void format_custom_arg() { +Context ctx; +auto f = Formatter(); +f.format(0, ctx); + } +}; +struct context { + template < typename T > using formatter_type = formatter< T >; +}; +enum { max_packed_args }; +template < typename Context, long > +using arg_t = +conditional_t< max_packed_args, value< Context >, basic_format_arg >; +template < int NUM_ARGS > struct format_arg_store { + arg_t< context, NUM_ARGS > args; +}; +template < typename... T, long NUM_ARGS = sizeof...(T) > +auto make_format_args(T... args) -> format_arg_store< NUM_ARGS > { + return {args...}; +} +template < typename F > void write_padded(F write) { write(0); } +template < typename... T > void format(T... args) { make_format_args(args...); } +template < int > struct bitset { + bitset(long); +}; +template < long N > struct formatter< bitset< N > > { + struct writer { +bitset< N > bs; +template < typename OutputIt > void operator()(OutputIt) { + for (auto pos = N; pos > 0; --pos) +; +} + }; + template < typename FormatContext > + void format(bitset< N > bs, FormatContext) { +write_padded(writer{bs}); + } +}; +bitset< 6 > TestBody_bs(2); +void TestBody() { format(TestBody_bs); } \ No newline at end of file >From ee331f6f1e257c7636913616c4f223de49d10641 Mon Sep 17 00:00:00 2001 From: shenjunjie Date: Fri, 27 Dec 2024 14:35:12 + Subject: [PATCH 3/5] fix testcase --- clang/test/Analysis/PR121201.cpp | 67 1 file changed, 42 insertions(+), 25 deletions(-) diff --git a/clang/test/Analysis/PR121201.cpp b/clang/test/Analysis/PR121201.cpp index a2cea89dc10b79..49ce92957ad8a8 100644 --- a/clang/test/Analysis/PR121201.cpp +++ b/clang/test/Analysis/PR121201.cpp @@ -1,50 +1,67 @@ +// RUN: %clang_analyze_cc1 -analyzer-checker=core -analyzer-config +// unroll-loops=true -verify %s -template < bool, typename T, typename > using conditional_t = T; +// expected-no-diagnostics + +template using conditional_t = T; class basic_format_arg; -template < typename > struct formatter; -template < typename Context > struct value { - template < typename T > value(T) { +template struct formatter; + +template struct value { + template value(T) { using value_type = T; -format_custom_arg< -value_type, typename Context::template formatter_type< value_type > >; +format_custom_arg>; } - template < typename, typename Formatter > static void format_custom_arg() { + + template static void format_custom_arg() { Context ctx; auto f = Formatter(); f.format(0, ctx); }
[clang] [analyzer] Fix zext assertion failure in loop unrolling (PR #121203)
https://github.com/steakhal edited https://github.com/llvm/llvm-project/pull/121203 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Fix zext assertion failure in loop unrolling (PR #121203)
https://github.com/steakhal commented: Thanks for the nice reproducer! The test looks a bit verbose to my taste, but it's okay as-is. I had some deeper thoughts of the fix inline to settle before we could merge this. Thanks again for working on this issue! https://github.com/llvm/llvm-project/pull/121203 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Fix zext assertion failure in loop unrolling (PR #121203)
@@ -283,10 +283,12 @@ static bool shouldCompletelyUnroll(const Stmt *LoopStmt, ASTContext &ASTCtx, llvm::APInt InitNum = Matches[0].getNodeAs("initNum")->getValue(); auto CondOp = Matches[0].getNodeAs("conditionOperator"); - if (InitNum.getBitWidth() != BoundNum.getBitWidth()) { -InitNum = InitNum.zext(BoundNum.getBitWidth()); -BoundNum = BoundNum.zext(InitNum.getBitWidth()); - } + unsigned MaxWidth = std::max(InitNum.getBitWidth(), BoundNum.getBitWidth()); steakhal wrote: Have you checked if there is a utility achieving this for us? Like the `APSIntType` type? (IDK, I rarely ever use it) I also wonder if we actually need to operate at an APSInt level, maybe we could just convert both of these into int64 and do the math on those. Is zero extension is actually correct in semantics? What if the `InitNum` was negative, léike `-1`, then shouldn't we use sign extension? https://github.com/llvm/llvm-project/pull/121203 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Add -fuse-lipo option (PR #121231)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Ashley Hauck (khyperia) Changes This is my first LLVM PR! Please feel free to provide feedback/etc. - I am especially unsure about the `Options.td` change - I just kind of guessed here. Partially fixes https://github.com/llvm/llvm-project/issues/59552 - opting for `-fuse-lipo=llvm-lipo` rather than `-fuse-llvm-darwin-tools` since it solves my use case, and I figure that if `-fuse-llvm-darwin-tools` is eventually added, it'll still be nice to have the fine-grained control with `-fuse-lipo`. --- My use case is that I'm cross compiling from Windows to Mac (creating an arm/x86 dylib), so I don't have the native `lipo`. Additionally, the binaries included in the release file `LLVM-19.1.0-Windows-X64.tar.xz` only includes `llvm-lipo.exe`, no `lipo.exe` alias/link, so clang fails to find `lipo` when making a universal dylib. The release file `LLVM-19.1.6-win64.exe` does not include `llvm-lipo.exe` at all. I'm going to look into including that next. --- Full diff: https://github.com/llvm/llvm-project/pull/121231.diff 2 Files Affected: - (modified) clang/include/clang/Driver/Options.td (+1) - (modified) clang/lib/Driver/ToolChains/Darwin.cpp (+2-1) ``diff diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index d922709db17786..6cd23de87bacde 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -6654,6 +6654,7 @@ def fbinutils_version_EQ : Joined<["-"], "fbinutils-version=">, def fuse_ld_EQ : Joined<["-"], "fuse-ld=">, Group, Flags<[LinkOption]>, Visibility<[ClangOption, FlangOption, CLOption]>; def ld_path_EQ : Joined<["--"], "ld-path=">, Group; +def fuse_lipo_EQ : Joined<["-"], "fuse-lipo=">, Group, Flags<[LinkOption]>; defm align_labels : BooleanFFlag<"align-labels">, Group; def falign_labels_EQ : Joined<["-"], "falign-labels=">, Group; diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp b/clang/lib/Driver/ToolChains/Darwin.cpp index 4105d38d15d7d8..c23f6830b8c764 100644 --- a/clang/lib/Driver/ToolChains/Darwin.cpp +++ b/clang/lib/Driver/ToolChains/Darwin.cpp @@ -910,7 +910,8 @@ void darwin::Lipo::ConstructJob(Compilation &C, const JobAction &JA, CmdArgs.push_back(II.getFilename()); } - const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("lipo")); + std::string LipoName = std::string(Args.getLastArgValue(options::OPT_fuse_lipo_EQ, "lipo")); + const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath(LipoName.c_str())); C.addCommand(std::make_unique(JA, *this, ResponseFileSupport::None(), Exec, CmdArgs, Inputs, Output)); } `` https://github.com/llvm/llvm-project/pull/121231 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Add -fuse-lipo option (PR #121231)
llvmbot wrote: @llvm/pr-subscribers-clang-driver Author: Ashley Hauck (khyperia) Changes This is my first LLVM PR! Please feel free to provide feedback/etc. - I am especially unsure about the `Options.td` change - I just kind of guessed here. Partially fixes https://github.com/llvm/llvm-project/issues/59552 - opting for `-fuse-lipo=llvm-lipo` rather than `-fuse-llvm-darwin-tools` since it solves my use case, and I figure that if `-fuse-llvm-darwin-tools` is eventually added, it'll still be nice to have the fine-grained control with `-fuse-lipo`. --- My use case is that I'm cross compiling from Windows to Mac (creating an arm/x86 dylib), so I don't have the native `lipo`. Additionally, the binaries included in the release file `LLVM-19.1.0-Windows-X64.tar.xz` only includes `llvm-lipo.exe`, no `lipo.exe` alias/link, so clang fails to find `lipo` when making a universal dylib. The release file `LLVM-19.1.6-win64.exe` does not include `llvm-lipo.exe` at all. I'm going to look into including that next. --- Full diff: https://github.com/llvm/llvm-project/pull/121231.diff 2 Files Affected: - (modified) clang/include/clang/Driver/Options.td (+1) - (modified) clang/lib/Driver/ToolChains/Darwin.cpp (+2-1) ``diff diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index d922709db17786..6cd23de87bacde 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -6654,6 +6654,7 @@ def fbinutils_version_EQ : Joined<["-"], "fbinutils-version=">, def fuse_ld_EQ : Joined<["-"], "fuse-ld=">, Group, Flags<[LinkOption]>, Visibility<[ClangOption, FlangOption, CLOption]>; def ld_path_EQ : Joined<["--"], "ld-path=">, Group; +def fuse_lipo_EQ : Joined<["-"], "fuse-lipo=">, Group, Flags<[LinkOption]>; defm align_labels : BooleanFFlag<"align-labels">, Group; def falign_labels_EQ : Joined<["-"], "falign-labels=">, Group; diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp b/clang/lib/Driver/ToolChains/Darwin.cpp index 4105d38d15d7d8..c23f6830b8c764 100644 --- a/clang/lib/Driver/ToolChains/Darwin.cpp +++ b/clang/lib/Driver/ToolChains/Darwin.cpp @@ -910,7 +910,8 @@ void darwin::Lipo::ConstructJob(Compilation &C, const JobAction &JA, CmdArgs.push_back(II.getFilename()); } - const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("lipo")); + std::string LipoName = std::string(Args.getLastArgValue(options::OPT_fuse_lipo_EQ, "lipo")); + const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath(LipoName.c_str())); C.addCommand(std::make_unique(JA, *this, ResponseFileSupport::None(), Exec, CmdArgs, Inputs, Output)); } `` https://github.com/llvm/llvm-project/pull/121231 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Add -fuse-lipo option (PR #121231)
github-actions[bot] wrote: Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using `@` followed by their GitHub username. If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the [LLVM GitHub User Guide](https://llvm.org/docs/GitHub.html). You can also ask questions in a comment on this PR, on the [LLVM Discord](https://discord.com/invite/xS7Z362) or on the [forums](https://discourse.llvm.org/). https://github.com/llvm/llvm-project/pull/121231 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Add -fuse-lipo option (PR #121231)
https://github.com/khyperia created https://github.com/llvm/llvm-project/pull/121231 This is my first LLVM PR! Please feel free to provide feedback/etc. - I am especially unsure about the `Options.td` change - I just kind of guessed here. Partially fixes https://github.com/llvm/llvm-project/issues/59552 - opting for `-fuse-lipo=llvm-lipo` rather than `-fuse-llvm-darwin-tools` since it solves my use case, and I figure that if `-fuse-llvm-darwin-tools` is eventually added, it'll still be nice to have the fine-grained control with `-fuse-lipo`. --- My use case is that I'm cross compiling from Windows to Mac (creating an arm/x86 dylib), so I don't have the native `lipo`. Additionally, the binaries included in the release file `LLVM-19.1.0-Windows-X64.tar.xz` only includes `llvm-lipo.exe`, no `lipo.exe` alias/link, so clang fails to find `lipo` when making a universal dylib. The release file `LLVM-19.1.6-win64.exe` does not include `llvm-lipo.exe` at all. I'm going to look into including that next. >From 51401ec4a8af7d926ba3c9faa818ecb9c68c0db7 Mon Sep 17 00:00:00 2001 From: khyperia <953151+khype...@users.noreply.github.com> Date: Fri, 27 Dec 2024 22:12:52 +0100 Subject: [PATCH] Add -fuse-lipo option --- clang/include/clang/Driver/Options.td | 1 + clang/lib/Driver/ToolChains/Darwin.cpp | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index d922709db17786..6cd23de87bacde 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -6654,6 +6654,7 @@ def fbinutils_version_EQ : Joined<["-"], "fbinutils-version=">, def fuse_ld_EQ : Joined<["-"], "fuse-ld=">, Group, Flags<[LinkOption]>, Visibility<[ClangOption, FlangOption, CLOption]>; def ld_path_EQ : Joined<["--"], "ld-path=">, Group; +def fuse_lipo_EQ : Joined<["-"], "fuse-lipo=">, Group, Flags<[LinkOption]>; defm align_labels : BooleanFFlag<"align-labels">, Group; def falign_labels_EQ : Joined<["-"], "falign-labels=">, Group; diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp b/clang/lib/Driver/ToolChains/Darwin.cpp index 4105d38d15d7d8..c23f6830b8c764 100644 --- a/clang/lib/Driver/ToolChains/Darwin.cpp +++ b/clang/lib/Driver/ToolChains/Darwin.cpp @@ -910,7 +910,8 @@ void darwin::Lipo::ConstructJob(Compilation &C, const JobAction &JA, CmdArgs.push_back(II.getFilename()); } - const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("lipo")); + std::string LipoName = std::string(Args.getLastArgValue(options::OPT_fuse_lipo_EQ, "lipo")); + const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath(LipoName.c_str())); C.addCommand(std::make_unique(JA, *this, ResponseFileSupport::None(), Exec, CmdArgs, Inputs, Output)); } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Add -fuse-lipo option (PR #121231)
github-actions[bot] wrote: ⚠️ We detected that you are using a GitHub private e-mail address to contribute to the repo. Please turn off [Keep my email addresses private](https://github.com/settings/emails) setting in your account. See [LLVM Discourse](https://discourse.llvm.org/t/hidden-emails-on-github-should-we-do-something-about-it) for more information. https://github.com/llvm/llvm-project/pull/121231 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Add -fuse-lipo option (PR #121231)
github-actions[bot] wrote: :warning: C/C++ code formatter, clang-format found issues in your code. :warning: You can test this locally with the following command: ``bash git-clang-format --diff 815343e7dd32cc4c5c903ac52daf87aaa4e4cd6e 51401ec4a8af7d926ba3c9faa818ecb9c68c0db7 --extensions cpp -- clang/lib/Driver/ToolChains/Darwin.cpp `` View the diff from clang-format here. ``diff diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp b/clang/lib/Driver/ToolChains/Darwin.cpp index c23f6830b8..0d3cbb5736 100644 --- a/clang/lib/Driver/ToolChains/Darwin.cpp +++ b/clang/lib/Driver/ToolChains/Darwin.cpp @@ -910,8 +910,10 @@ void darwin::Lipo::ConstructJob(Compilation &C, const JobAction &JA, CmdArgs.push_back(II.getFilename()); } - std::string LipoName = std::string(Args.getLastArgValue(options::OPT_fuse_lipo_EQ, "lipo")); - const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath(LipoName.c_str())); + std::string LipoName = + std::string(Args.getLastArgValue(options::OPT_fuse_lipo_EQ, "lipo")); + const char *Exec = + Args.MakeArgString(getToolChain().GetProgramPath(LipoName.c_str())); C.addCommand(std::make_unique(JA, *this, ResponseFileSupport::None(), Exec, CmdArgs, Inputs, Output)); } `` https://github.com/llvm/llvm-project/pull/121231 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Add -fuse-lipo option (PR #121231)
https://github.com/khyperia updated https://github.com/llvm/llvm-project/pull/121231 >From 33b542152876b9ccbf42cc3d070d582c32145477 Mon Sep 17 00:00:00 2001 From: khyperia Date: Fri, 27 Dec 2024 23:03:58 +0100 Subject: [PATCH] Add -fuse-lipo option --- clang/include/clang/Driver/Options.td | 1 + clang/lib/Driver/ToolChains/Darwin.cpp | 5 - 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/clang/include/clang/Driver/Options.td b/clang/include/clang/Driver/Options.td index d922709db17786..6cd23de87bacde 100644 --- a/clang/include/clang/Driver/Options.td +++ b/clang/include/clang/Driver/Options.td @@ -6654,6 +6654,7 @@ def fbinutils_version_EQ : Joined<["-"], "fbinutils-version=">, def fuse_ld_EQ : Joined<["-"], "fuse-ld=">, Group, Flags<[LinkOption]>, Visibility<[ClangOption, FlangOption, CLOption]>; def ld_path_EQ : Joined<["--"], "ld-path=">, Group; +def fuse_lipo_EQ : Joined<["-"], "fuse-lipo=">, Group, Flags<[LinkOption]>; defm align_labels : BooleanFFlag<"align-labels">, Group; def falign_labels_EQ : Joined<["-"], "falign-labels=">, Group; diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp b/clang/lib/Driver/ToolChains/Darwin.cpp index 4105d38d15d7d8..0d3cbb57362164 100644 --- a/clang/lib/Driver/ToolChains/Darwin.cpp +++ b/clang/lib/Driver/ToolChains/Darwin.cpp @@ -910,7 +910,10 @@ void darwin::Lipo::ConstructJob(Compilation &C, const JobAction &JA, CmdArgs.push_back(II.getFilename()); } - const char *Exec = Args.MakeArgString(getToolChain().GetProgramPath("lipo")); + std::string LipoName = + std::string(Args.getLastArgValue(options::OPT_fuse_lipo_EQ, "lipo")); + const char *Exec = + Args.MakeArgString(getToolChain().GetProgramPath(LipoName.c_str())); C.addCommand(std::make_unique(JA, *this, ResponseFileSupport::None(), Exec, CmdArgs, Inputs, Output)); } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Handle [[assume(cond)]] as __builtin_assume(cond) (PR #116462)
steakhal wrote: So we had the following assertion failure: ``` clang/lib/Analysis/ThreadSafety.cpp:529: LocalVariableMap::addDefinition: Assertion `!Ctx.contains(D)' failed. ``` On `libcxx/test/std/algorithms/alg.modifying.operations/alg.fill/pstl.fill_n.pass.cpp`. I wish I could come back to this to see why that assert fails. I don't have the bandwidth. Maybe at some point in January. https://github.com/llvm/llvm-project/pull/116462 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Fix zext assertion failure in loop unrolling (PR #121203)
https://github.com/shenjunjiekoda updated https://github.com/llvm/llvm-project/pull/121203 >From 2cee5fc2abd0cf2979c9ba975906e659adcd4463 Mon Sep 17 00:00:00 2001 From: shenjunjie Date: Fri, 27 Dec 2024 14:08:55 + Subject: [PATCH 1/2] [analyzer] Fix zext assertion failure in loop unrolling --- clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp | 10 ++ 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp b/clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp index 96f5d7c44baf89..9227a7876c0b2f 100644 --- a/clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp +++ b/clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp @@ -283,10 +283,12 @@ static bool shouldCompletelyUnroll(const Stmt *LoopStmt, ASTContext &ASTCtx, llvm::APInt InitNum = Matches[0].getNodeAs("initNum")->getValue(); auto CondOp = Matches[0].getNodeAs("conditionOperator"); - if (InitNum.getBitWidth() != BoundNum.getBitWidth()) { -InitNum = InitNum.zext(BoundNum.getBitWidth()); -BoundNum = BoundNum.zext(InitNum.getBitWidth()); - } + unsigned MaxWidth = std::max(InitNum.getBitWidth(), BoundNum.getBitWidth()); + + if (InitNum.getBitWidth() != MaxWidth) +InitNum = InitNum.zext(MaxWidth); + if (BoundNum.getBitWidth() != MaxWidth) +BoundNum = BoundNum.zext(MaxWidth); if (CondOp->getOpcode() == BO_GE || CondOp->getOpcode() == BO_LE) maxStep = (BoundNum - InitNum + 1).abs().getZExtValue(); >From a4d3a24ea797c5f53c5171e05f7172434096bd65 Mon Sep 17 00:00:00 2001 From: shenjunjie Date: Fri, 27 Dec 2024 14:20:23 + Subject: [PATCH 2/2] add testcase --- clang/test/Analysis/PR121201.cpp | 50 1 file changed, 50 insertions(+) create mode 100644 clang/test/Analysis/PR121201.cpp diff --git a/clang/test/Analysis/PR121201.cpp b/clang/test/Analysis/PR121201.cpp new file mode 100644 index 00..a2cea89dc10b79 --- /dev/null +++ b/clang/test/Analysis/PR121201.cpp @@ -0,0 +1,50 @@ + +template < bool, typename T, typename > using conditional_t = T; +class basic_format_arg; +template < typename > struct formatter; +template < typename Context > struct value { + template < typename T > value(T) { +using value_type = T; +format_custom_arg< +value_type, typename Context::template formatter_type< value_type > >; + } + template < typename, typename Formatter > static void format_custom_arg() { +Context ctx; +auto f = Formatter(); +f.format(0, ctx); + } +}; +struct context { + template < typename T > using formatter_type = formatter< T >; +}; +enum { max_packed_args }; +template < typename Context, long > +using arg_t = +conditional_t< max_packed_args, value< Context >, basic_format_arg >; +template < int NUM_ARGS > struct format_arg_store { + arg_t< context, NUM_ARGS > args; +}; +template < typename... T, long NUM_ARGS = sizeof...(T) > +auto make_format_args(T... args) -> format_arg_store< NUM_ARGS > { + return {args...}; +} +template < typename F > void write_padded(F write) { write(0); } +template < typename... T > void format(T... args) { make_format_args(args...); } +template < int > struct bitset { + bitset(long); +}; +template < long N > struct formatter< bitset< N > > { + struct writer { +bitset< N > bs; +template < typename OutputIt > void operator()(OutputIt) { + for (auto pos = N; pos > 0; --pos) +; +} + }; + template < typename FormatContext > + void format(bitset< N > bs, FormatContext) { +write_padded(writer{bs}); + } +}; +bitset< 6 > TestBody_bs(2); +void TestBody() { format(TestBody_bs); } \ No newline at end of file ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [libcxx] [llvm] [libc++] implement views::concat (PR #120920)
https://github.com/changkhothuychung updated https://github.com/llvm/llvm-project/pull/120920 error: too big or took too long to generate ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Added nullptr check to getFriendDecl access (PR #121056)
@@ -0,0 +1,12 @@ +// RUN: %clang_cc1 -std=c++20 -fsyntax-only -verify %s +// expected-no-diagnostics + +// Ensure the following out of line friend declaration doesn't cause the compiler to crash. + +class A { + friend bool operator==(const A&, const A&); + friend class B; +}; + +bool operator==(const A&, const A&) = default; + GrumpyPigSkin wrote: Ahh okay, what is the other test? I was messing around and found a test that passes on clang and fails on gcc/msvc, https://compiler-explorer.com/z/5ve41Mo9b, I don't see why it shouldn't pass on the other two. What other tests do you think are worth implementing? https://github.com/llvm/llvm-project/pull/121056 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [libcxx] [llvm] [libc++] implement views::concat (PR #120920)
https://github.com/changkhothuychung updated https://github.com/llvm/llvm-project/pull/120920 error: too big or took too long to generate ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Annotate darwin check (PR #121217)
https://github.com/Caslyn created https://github.com/llvm/llvm-project/pull/121217 None >From d82b90749a5381af4a022c8102802012e78b107c Mon Sep 17 00:00:00 2001 From: Caslyn Tonelli Date: Fri, 27 Dec 2024 09:56:10 -0800 Subject: [PATCH] [Driver] Annotate darwin check --- clang/test/Driver/sanitizer-ld.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/test/Driver/sanitizer-ld.c b/clang/test/Driver/sanitizer-ld.c index 5befbb159183e9..6cf17b8391a288 100644 --- a/clang/test/Driver/sanitizer-ld.c +++ b/clang/test/Driver/sanitizer-ld.c @@ -37,7 +37,7 @@ // RUN: | %{filecheck} --check-prefix=CHECK-ASAN-NO-LINK-RUNTIME-DARWIN // // CHECK-ASAN-NO-LINK-RUNTIME-DARWIN: "{{.*}}ld" -// CHECK-ASAN-NO-LINK-RUNTIME-DARWIN: libclang_rt.osx.a" +// CHECK-ASAN-NO-LINK-RUNTIME-DARWIN: "--whole-archive" libclang_rt.osx.a" "--no-whole-archive" // RUN: %clang -fsanitize=address -### %s 2>&1 \ // RUN: --target=x86_64-unknown-linux -fuse-ld=ld \ ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Annotate darwin check (PR #121217)
https://github.com/Caslyn updated https://github.com/llvm/llvm-project/pull/121217 >From 40f56960789e48b2f9221b077c3aec6cc4c21838 Mon Sep 17 00:00:00 2001 From: Caslyn Tonelli Date: Fri, 27 Dec 2024 09:56:10 -0800 Subject: [PATCH] [Driver] Annotate darwin check --- clang/test/Driver/sanitizer-ld.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/test/Driver/sanitizer-ld.c b/clang/test/Driver/sanitizer-ld.c index 5befbb159183e9..8f93851c5b1b37 100644 --- a/clang/test/Driver/sanitizer-ld.c +++ b/clang/test/Driver/sanitizer-ld.c @@ -37,7 +37,7 @@ // RUN: | %{filecheck} --check-prefix=CHECK-ASAN-NO-LINK-RUNTIME-DARWIN // // CHECK-ASAN-NO-LINK-RUNTIME-DARWIN: "{{.*}}ld" -// CHECK-ASAN-NO-LINK-RUNTIME-DARWIN: libclang_rt.osx.a" +// CHECK-ASAN-NO-LINK-RUNTIME-DARWIN: "--whole-archive" "{{.*}}libclang_rt.osx.a" "--no-whole-archive" // RUN: %clang -fsanitize=address -### %s 2>&1 \ // RUN: --target=x86_64-unknown-linux -fuse-ld=ld \ ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Fix zext assertion failure in loop unrolling (PR #121203)
llvmbot wrote: @llvm/pr-subscribers-clang-static-analyzer-1 Author: JOSTAR (shenjunjiekoda) Changes The current implementation of APInt extension in the code can trigger an assertion failure when the `zext` function is called with a target width smaller than the current bit width. For example: ```cpp if (InitNum.getBitWidth() != BoundNum.getBitWidth()) { InitNum = InitNum.zext(BoundNum.getBitWidth()); BoundNum = BoundNum.zext(InitNum.getBitWidth()); } ``` This logic does not guarantee that the `zext` target width is always greater than or equal to the current bit width, leading to potential crashes. Expected Behavior: - Ensure InitNum and BoundNum are extended to the maximum of their respective widths. - Prevent assertion failures by enforcing correct `zext` usage. Depend on ##121201 --- Full diff: https://github.com/llvm/llvm-project/pull/121203.diff 1 Files Affected: - (modified) clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp (+6-4) ``diff diff --git a/clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp b/clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp index 96f5d7c44baf89..e3b27e22712b58 100644 --- a/clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp +++ b/clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp @@ -283,10 +283,12 @@ static bool shouldCompletelyUnroll(const Stmt *LoopStmt, ASTContext &ASTCtx, llvm::APInt InitNum = Matches[0].getNodeAs("initNum")->getValue(); auto CondOp = Matches[0].getNodeAs("conditionOperator"); - if (InitNum.getBitWidth() != BoundNum.getBitWidth()) { -InitNum = InitNum.zext(BoundNum.getBitWidth()); -BoundNum = BoundNum.zext(InitNum.getBitWidth()); - } + unsigned MaxWidth = std::max(InitNum.getBitWidth(), BoundNum.getBitWidth()); + + if (InitNum.getBitWidth() != MaxWidth) + InitNum = InitNum.zext(MaxWidth); + if (BoundNum.getBitWidth() != MaxWidth) + BoundNum = BoundNum.zext(MaxWidth); if (CondOp->getOpcode() == BO_GE || CondOp->getOpcode() == BO_LE) maxStep = (BoundNum - InitNum + 1).abs().getZExtValue(); `` https://github.com/llvm/llvm-project/pull/121203 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Fix zext assertion failure in loop unrolling (PR #121203)
https://github.com/shenjunjiekoda created https://github.com/llvm/llvm-project/pull/121203 The current implementation of APInt extension in the code can trigger an assertion failure when the `zext` function is called with a target width smaller than the current bit width. For example: ```cpp if (InitNum.getBitWidth() != BoundNum.getBitWidth()) { InitNum = InitNum.zext(BoundNum.getBitWidth()); BoundNum = BoundNum.zext(InitNum.getBitWidth()); } ``` This logic does not guarantee that the `zext` target width is always greater than or equal to the current bit width, leading to potential crashes. Expected Behavior: - Ensure InitNum and BoundNum are extended to the maximum of their respective widths. - Prevent assertion failures by enforcing correct `zext` usage. Depend on ##121201 >From 3bcf5c8f05df2f62a9ef13537b813e7df2871d1b Mon Sep 17 00:00:00 2001 From: shenjunjie Date: Fri, 27 Dec 2024 11:00:27 + Subject: [PATCH] [analyzer] Fix zext assertion failure in loop unrolling --- clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp | 10 ++ 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp b/clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp index 96f5d7c44baf89..e3b27e22712b58 100644 --- a/clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp +++ b/clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp @@ -283,10 +283,12 @@ static bool shouldCompletelyUnroll(const Stmt *LoopStmt, ASTContext &ASTCtx, llvm::APInt InitNum = Matches[0].getNodeAs("initNum")->getValue(); auto CondOp = Matches[0].getNodeAs("conditionOperator"); - if (InitNum.getBitWidth() != BoundNum.getBitWidth()) { -InitNum = InitNum.zext(BoundNum.getBitWidth()); -BoundNum = BoundNum.zext(InitNum.getBitWidth()); - } + unsigned MaxWidth = std::max(InitNum.getBitWidth(), BoundNum.getBitWidth()); + + if (InitNum.getBitWidth() != MaxWidth) + InitNum = InitNum.zext(MaxWidth); + if (BoundNum.getBitWidth() != MaxWidth) + BoundNum = BoundNum.zext(MaxWidth); if (CondOp->getOpcode() == BO_GE || CondOp->getOpcode() == BO_LE) maxStep = (BoundNum - InitNum + 1).abs().getZExtValue(); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Fix zext assertion failure in loop unrolling (PR #121203)
llvmbot wrote: @llvm/pr-subscribers-clang Author: JOSTAR (shenjunjiekoda) Changes The current implementation of APInt extension in the code can trigger an assertion failure when the `zext` function is called with a target width smaller than the current bit width. For example: ```cpp if (InitNum.getBitWidth() != BoundNum.getBitWidth()) { InitNum = InitNum.zext(BoundNum.getBitWidth()); BoundNum = BoundNum.zext(InitNum.getBitWidth()); } ``` This logic does not guarantee that the `zext` target width is always greater than or equal to the current bit width, leading to potential crashes. Expected Behavior: - Ensure InitNum and BoundNum are extended to the maximum of their respective widths. - Prevent assertion failures by enforcing correct `zext` usage. Depend on ##121201 --- Full diff: https://github.com/llvm/llvm-project/pull/121203.diff 1 Files Affected: - (modified) clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp (+6-4) ``diff diff --git a/clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp b/clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp index 96f5d7c44baf89..e3b27e22712b58 100644 --- a/clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp +++ b/clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp @@ -283,10 +283,12 @@ static bool shouldCompletelyUnroll(const Stmt *LoopStmt, ASTContext &ASTCtx, llvm::APInt InitNum = Matches[0].getNodeAs("initNum")->getValue(); auto CondOp = Matches[0].getNodeAs("conditionOperator"); - if (InitNum.getBitWidth() != BoundNum.getBitWidth()) { -InitNum = InitNum.zext(BoundNum.getBitWidth()); -BoundNum = BoundNum.zext(InitNum.getBitWidth()); - } + unsigned MaxWidth = std::max(InitNum.getBitWidth(), BoundNum.getBitWidth()); + + if (InitNum.getBitWidth() != MaxWidth) + InitNum = InitNum.zext(MaxWidth); + if (BoundNum.getBitWidth() != MaxWidth) + BoundNum = BoundNum.zext(MaxWidth); if (CondOp->getOpcode() == BO_GE || CondOp->getOpcode() == BO_LE) maxStep = (BoundNum - InitNum + 1).abs().getZExtValue(); `` https://github.com/llvm/llvm-project/pull/121203 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [compiler-rt] [llvm] [Coverage] Move SingleByteCoverage out of CountedRegion (PR #110966)
https://github.com/chapuni closed https://github.com/llvm/llvm-project/pull/110966 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [libcxx] [llvm] [libc++] implement views::concat (PR #120920)
https://github.com/changkhothuychung updated https://github.com/llvm/llvm-project/pull/120920 error: too big or took too long to generate ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [libcxx] [llvm] [libc++] implement views::concat (PR #120920)
https://github.com/changkhothuychung updated https://github.com/llvm/llvm-project/pull/120920 error: too big or took too long to generate ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [ARM] Save floating point registers and status registers with save_fp function attribute (PR #89654)
@@ -80,13 +80,47 @@ ARMBaseRegisterInfo::getCalleeSavedRegs(const MachineFunction *MF) const { ? CSR_ATPCS_SplitPush_SwiftTail_SaveList : CSR_AAPCS_SwiftTail_SaveList); } else if (F.hasFnAttribute("interrupt")) { + +// Don't bother saving the floating point registers if target is not hard +// float. This will prevent the Thumb1FrameLowering (cortex-m0) from +// crashing due to an llvm_unreachable being triggered when a D-class +// register is in the calling convention. +if (STI.isTargetHardFloat() && F.hasFnAttribute("save-fp")) { pestctrl wrote: How about we check for if if the subtarget has FP registers? ``` if (STI.hasFPRegs() && F.hasFnAttribute("save-fp")) ``` https://github.com/llvm/llvm-project/pull/89654 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Fix implicit-check-not regex (PR #121221)
llvm-ci wrote: LLVM Buildbot has detected a new failure on builder `sanitizer-x86_64-linux-bootstrap-asan` running on `sanitizer-buildbot1` while building `clang` at step 2 "annotate". Full details are available at: https://lab.llvm.org/buildbot/#/builders/52/builds/4825 Here is the relevant piece of the build log for the reference ``` Step 2 (annotate) failure: 'python ../sanitizer_buildbot/sanitizers/zorg/buildbot/builders/sanitizers/buildbot_selector.py' (failure) ... llvm-lit: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506: note: using lld-link: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/lld-link llvm-lit: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506: note: using ld64.lld: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/ld64.lld llvm-lit: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506: note: using wasm-ld: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/wasm-ld llvm-lit: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506: note: using ld.lld: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/ld.lld llvm-lit: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506: note: using lld-link: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/lld-link llvm-lit: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506: note: using ld64.lld: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/ld64.lld llvm-lit: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506: note: using wasm-ld: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/wasm-ld llvm-lit: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/main.py:72: note: The test suite configuration requested an individual test timeout of 0 seconds but a timeout of 900 seconds was requested on the command line. Forcing timeout to be 900 seconds. -- Testing: 88040 tests, 88 workers -- Testing: 0.. 10 FAIL: Clang :: Interpreter/inline-virtual.cpp (12674 of 88040) TEST 'Clang :: Interpreter/inline-virtual.cpp' FAILED Exit Code: 1 Command Output (stderr): -- RUN: at line 6: cat /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/clang/test/Interpreter/inline-virtual.cpp | /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/clang-repl -Xcc -fno-rtti -Xcc -fno-sized-deallocation | /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/FileCheck /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/clang/test/Interpreter/inline-virtual.cpp + cat /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/clang/test/Interpreter/inline-virtual.cpp + /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/FileCheck /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/clang/test/Interpreter/inline-virtual.cpp + /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/clang-repl -Xcc -fno-rtti -Xcc -fno-sized-deallocation JIT session error: In graph incr_module_23-jitted-objectbuffer, section .text.startup: relocation target "_ZN1AD2Ev" at address 0x7ac6f6a2f040 is out of range of Delta32 fixup at 0x76c6f610f02d ( @ 0x76c6f610f010 + 0x1d) error: Failed to materialize symbols: { (main, { a2, $.incr_module_23.__inits.0, __orc_init_func.incr_module_23 }) } error: Failed to materialize symbols: { (main, { __orc_init_func.incr_module_23 }) } /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/clang/test/Interpreter/inline-virtual.cpp:26:11: error: CHECK: expected string not found in input // CHECK: ~A(2) ^ :1:262: note: scanning from here clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl... clang-repl> clang-repl... clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> ~A(1) ^ Input file: Check file: /home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/clang/test/Interpreter/inline-virtual.cpp -dump-input=help explains the following input dump. Input was: << 1: clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl> clang-repl... clang-repl> clang-repl... clang-repl> cl
[clang] [clang-tools-extra] [libcxx] [llvm] [libc++] implement views::concat (PR #120920)
@@ -0,0 +1,54 @@ +//===--===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===--===// + +// UNSUPPORTED: c++03, c++11, c++14, c++17 changkhothuychung wrote: Hi, can you elaborate a bit more, what do I need to change in these test files? https://github.com/llvm/llvm-project/pull/120920 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-tools-extra] [libcxx] [llvm] [libc++] implement views::concat (PR #120920)
https://github.com/changkhothuychung updated https://github.com/llvm/llvm-project/pull/120920 error: too big or took too long to generate ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [PAC][ELF][AArch64] Support signed personality function pointer (PR #113148)
llvm-ci wrote: LLVM Buildbot has detected a new failure on builder `clang-s390x-linux-multistage` running on `systemz-1` while building `clang,llvm` at step 5 "ninja check 1". Full details are available at: https://lab.llvm.org/buildbot/#/builders/98/builds/811 Here is the relevant piece of the build log for the reference ``` Step 5 (ninja check 1) failure: stage 1 checked (failure) TEST 'LLVM :: CodeGen/AArch64/ptrauth-sign-personality.ll' FAILED Exit Code: 1 Command Output (stderr): -- RUN: at line 1: /home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/stage1/bin/llc -mtriple=aarch64-linux -filetype=asm /home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/llvm/test/CodeGen/AArch64/ptrauth-sign-personality.ll -o - | /home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/stage1/bin/FileCheck /home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/llvm/test/CodeGen/AArch64/ptrauth-sign-personality.ll + /home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/stage1/bin/llc -mtriple=aarch64-linux -filetype=asm /home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/llvm/test/CodeGen/AArch64/ptrauth-sign-personality.ll -o - + /home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/stage1/bin/FileCheck /home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/llvm/test/CodeGen/AArch64/ptrauth-sign-personality.ll /home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/llvm/test/CodeGen/AArch64/ptrauth-sign-personality.ll:30:15: error: CHECK-NEXT: expected string not found in input ; CHECK-NEXT: .xword __gxx_personality_v0@AUTH(ia,32429,addr) ^ :68:29: note: scanning from here DW.ref.__gxx_personality_v0: ^ :69:2: note: possible intended match here .xword __gxx_personality_v0 ^ Input file: Check file: /home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/llvm/test/CodeGen/AArch64/ptrauth-sign-personality.ll -dump-input=help explains the following input dump. Input was: << . . . 63: .weak DW.ref.__gxx_personality_v0 64: .section .data.DW.ref.__gxx_personality_v0,"awG",@progbits,DW.ref.__gxx_personality_v0,comdat 65: .p2align 3, 0x0 66: .type DW.ref.__gxx_personality_v0,@object 67: .size DW.ref.__gxx_personality_v0, 8 68: DW.ref.__gxx_personality_v0: next:30'0 X error: no match found 69: .xword __gxx_personality_v0 next:30'0 ~ next:30'1 ?possible intended match 70: .section ".note.GNU-stack","",@progbits next:30'0 ~ >> -- Step 11 (ninja check 2) failure: stage 2 checked (failure) TEST 'LLVM :: CodeGen/AArch64/ptrauth-sign-personality.ll' FAILED Exit Code: 1 Command Output (stderr): -- RUN: at line 1: /home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/stage2/bin/llc -mtriple=aarch64-linux -filetype=asm /home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/llvm/test/CodeGen/AArch64/ptrauth-sign-personality.ll -o - | /home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/stage2/bin/FileCheck /home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/llvm/test/CodeGen/AArch64/ptrauth-sign-personality.ll + /home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/stage2/bin/llc -mtriple=aarch64-linux -filetype=asm /home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/llvm/test/CodeGen/AArch64/ptrauth-sign-personality.ll -o - + /home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/stage2/bin/FileCheck /home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/llvm/test/CodeGen/AArch64/ptrauth-sign-personality.ll /home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/llvm/test/CodeGen/AArch64/ptrauth-sign-personality.ll:30:15: error: CHECK-NEXT: expected string not found in input ; CHECK-NEXT: .xword __gxx_personality_v0@AUTH(ia,32429,addr) ^ :68:29: note: scanning from here DW.ref.__gxx_personality_v0: ^ :69:2: note: possible intended match here .xword __gxx_personality_v0 ^ Input file: Check file: /home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/llvm/test/CodeGen/AArch64/ptrauth-sign-personality.ll -dump-input=help explains the following input dump. Input was: << . . . 63: .weak DW.ref.__gxx_personality_v0 64: .section .data.DW.ref.__gxx_personality_v0,"awG",@progbits,DW.ref.__gxx_personality_v0,comdat 65: .p2align 3, 0x0 66: .type DW.ref.__gxx_personality_v0,@object 67: .size DW.ref.__gxx_personality_v0, 8 68: DW.ref.__
[clang] b2fd0a7 - [Driver] Fix implicit-check-not regex (#121221)
Author: Vitaly Buka Date: 2024-12-27T13:02:51-08:00 New Revision: b2fd0a7a7065658ab4a3355399978523c1370615 URL: https://github.com/llvm/llvm-project/commit/b2fd0a7a7065658ab4a3355399978523c1370615 DIFF: https://github.com/llvm/llvm-project/commit/b2fd0a7a7065658ab4a3355399978523c1370615.diff LOG: [Driver] Fix implicit-check-not regex (#121221) We need to exclude more than builtins, but it's tricky with FileCheck regex. So switching to list of libs we want to check. Added: Modified: clang/test/Driver/sanitizer-ld.c Removed: diff --git a/clang/test/Driver/sanitizer-ld.c b/clang/test/Driver/sanitizer-ld.c index 5befbb159183e9..4e4cfbae27e113 100644 --- a/clang/test/Driver/sanitizer-ld.c +++ b/clang/test/Driver/sanitizer-ld.c @@ -1,8 +1,9 @@ // Test sanitizers ld flags. -// Match all libclang_rt, excluding platform-inconsistent builtins. +// Match all libclang_rt, excluding platform-inconsistent libs, like +// libclang_rt.builtins, libclang_rt.osx etc. -// DEFINE: %{filecheck} = FileCheck %s --implicit-check-not="libclang_rt.{{([^b]..|.[^u].|..[^i]).*}}" +// DEFINE: %{filecheck} = FileCheck %s --implicit-check-not="libclang_rt.{{([^.]+san|scudo|cfi|safestack|stats|fuzzer|undefined)}}" // RUN: %clang -### %s 2>&1 \ // RUN: --target=i386-unknown-linux -fuse-ld=ld -fsanitize=address \ @@ -37,7 +38,6 @@ // RUN: | %{filecheck} --check-prefix=CHECK-ASAN-NO-LINK-RUNTIME-DARWIN // // CHECK-ASAN-NO-LINK-RUNTIME-DARWIN: "{{.*}}ld" -// CHECK-ASAN-NO-LINK-RUNTIME-DARWIN: libclang_rt.osx.a" // RUN: %clang -fsanitize=address -### %s 2>&1 \ // RUN: --target=x86_64-unknown-linux -fuse-ld=ld \ @@ -366,7 +366,6 @@ // RUN: | %{filecheck} --check-prefix=CHECK-TYSAN-DARWIN-CXX // CHECK-TYSAN-DARWIN-CXX: "{{.*}}ld" // CHECK-TYSAN-DARWIN-CXX: libclang_rt.tysan_osx_dynamic.dylib -// CHECK-TYSAN-DARWIN-CXX: libclang_rt.osx.a // CHECK-TYSAN-DARWIN-CXX-NOT: -lc++abi // RUN: %clangxx -### %s 2>&1 \ @@ -403,7 +402,7 @@ // RUN: --sysroot=%S/Inputs/basic_linux_tree \ // RUN: | %{filecheck} --check-prefix=CHECK-TSAN-NO-LINK-RUNTIME-DARWIN // -// CHECK-TSAN-NO-LINK-RUNTIME-DARWIN: libclang_rt.ios.a +// CHECK-TSAN-NO-LINK-RUNTIME-DARWIN: "{{(.*[^-.0-9A-Z_a-z])?}}ld" // RUN: %clangxx -### %s 2>&1 \ // RUN: --target=x86_64-unknown-linux -fuse-ld=ld -stdlib=platform -lstdc++ \ @@ -473,7 +472,6 @@ // RUN: | %{filecheck} --check-prefix=CHECK-UBSAN-NO-LINK-RUNTIME-DARWIN // // CHECK-UBSAN-NO-LINK-RUNTIME-DARWIN: "{{.*}}ld" -// CHECK-UBSAN-NO-LINK-RUNTIME-DARWIN: libclang_rt.osx.a // RUN: %clang -fsanitize=fuzzer -fno-sanitize-link-runtime -### %s 2>&1 \ // RUN: --target=arm64e-apple-watchos -fuse-ld=ld \ @@ -482,7 +480,6 @@ // RUN: | %{filecheck} --check-prefix=CHECK-FUZZER-NO-LINK-RUNTIME-DARWIN // // CHECK-FUZZER-NO-LINK-RUNTIME-DARWIN: "{{.*}}ld" -// CHECK-FUZZER-NO-LINK-RUNTIME-DARWIN: libclang_rt.watchos.a // RUN: %clang -fsanitize=undefined -### %s 2>&1 \ // RUN: --target=i386-unknown-linux -fuse-ld=ld \ @@ -838,7 +835,6 @@ // CHECK-ASAN-DARWIN106-CXX: "{{.*}}ld" // CHECK-ASAN-DARWIN106-CXX: libclang_rt.asan_osx_dynamic.dylib // CHECK-ASAN-DARWIN106-CXX-NOT: -lc++abi -// CHECK-ASAN-DARWIN106-CXX: libclang_rt.osx.a // RUN: %clangxx -fsanitize=leak -### %s 2>&1 \ // RUN: -mmacos-version-min=10.6 \ @@ -849,7 +845,6 @@ // CHECK-LSAN-DARWIN106-CXX: "{{.*}}ld" // CHECK-LSAN-DARWIN106-CXX: libclang_rt.lsan_osx_dynamic.dylib // CHECK-LSAN-DARWIN106-CXX-NOT: -lc++abi -// CHECK-LSAN-DARWIN106-CXX: libclang_rt.osx.a // RUN: %clang -### %s 2>&1 \ // RUN: --target=x86_64-unknown-linux -fuse-ld=ld -fsanitize=safe-stack \ ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Fix implicit-check-not regex (PR #121221)
https://github.com/vitalybuka closed https://github.com/llvm/llvm-project/pull/121221 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Fix zext assertion failure in loop unrolling (PR #121203)
https://github.com/steakhal edited https://github.com/llvm/llvm-project/pull/121203 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Fix zext assertion failure in loop unrolling (PR #121203)
https://github.com/shenjunjiekoda updated https://github.com/llvm/llvm-project/pull/121203 >From 2cee5fc2abd0cf2979c9ba975906e659adcd4463 Mon Sep 17 00:00:00 2001 From: shenjunjie Date: Fri, 27 Dec 2024 14:08:55 + Subject: [PATCH 1/4] [analyzer] Fix zext assertion failure in loop unrolling --- clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp | 10 ++ 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp b/clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp index 96f5d7c44baf89..9227a7876c0b2f 100644 --- a/clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp +++ b/clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp @@ -283,10 +283,12 @@ static bool shouldCompletelyUnroll(const Stmt *LoopStmt, ASTContext &ASTCtx, llvm::APInt InitNum = Matches[0].getNodeAs("initNum")->getValue(); auto CondOp = Matches[0].getNodeAs("conditionOperator"); - if (InitNum.getBitWidth() != BoundNum.getBitWidth()) { -InitNum = InitNum.zext(BoundNum.getBitWidth()); -BoundNum = BoundNum.zext(InitNum.getBitWidth()); - } + unsigned MaxWidth = std::max(InitNum.getBitWidth(), BoundNum.getBitWidth()); + + if (InitNum.getBitWidth() != MaxWidth) +InitNum = InitNum.zext(MaxWidth); + if (BoundNum.getBitWidth() != MaxWidth) +BoundNum = BoundNum.zext(MaxWidth); if (CondOp->getOpcode() == BO_GE || CondOp->getOpcode() == BO_LE) maxStep = (BoundNum - InitNum + 1).abs().getZExtValue(); >From a4d3a24ea797c5f53c5171e05f7172434096bd65 Mon Sep 17 00:00:00 2001 From: shenjunjie Date: Fri, 27 Dec 2024 14:20:23 + Subject: [PATCH 2/4] add testcase --- clang/test/Analysis/PR121201.cpp | 50 1 file changed, 50 insertions(+) create mode 100644 clang/test/Analysis/PR121201.cpp diff --git a/clang/test/Analysis/PR121201.cpp b/clang/test/Analysis/PR121201.cpp new file mode 100644 index 00..a2cea89dc10b79 --- /dev/null +++ b/clang/test/Analysis/PR121201.cpp @@ -0,0 +1,50 @@ + +template < bool, typename T, typename > using conditional_t = T; +class basic_format_arg; +template < typename > struct formatter; +template < typename Context > struct value { + template < typename T > value(T) { +using value_type = T; +format_custom_arg< +value_type, typename Context::template formatter_type< value_type > >; + } + template < typename, typename Formatter > static void format_custom_arg() { +Context ctx; +auto f = Formatter(); +f.format(0, ctx); + } +}; +struct context { + template < typename T > using formatter_type = formatter< T >; +}; +enum { max_packed_args }; +template < typename Context, long > +using arg_t = +conditional_t< max_packed_args, value< Context >, basic_format_arg >; +template < int NUM_ARGS > struct format_arg_store { + arg_t< context, NUM_ARGS > args; +}; +template < typename... T, long NUM_ARGS = sizeof...(T) > +auto make_format_args(T... args) -> format_arg_store< NUM_ARGS > { + return {args...}; +} +template < typename F > void write_padded(F write) { write(0); } +template < typename... T > void format(T... args) { make_format_args(args...); } +template < int > struct bitset { + bitset(long); +}; +template < long N > struct formatter< bitset< N > > { + struct writer { +bitset< N > bs; +template < typename OutputIt > void operator()(OutputIt) { + for (auto pos = N; pos > 0; --pos) +; +} + }; + template < typename FormatContext > + void format(bitset< N > bs, FormatContext) { +write_padded(writer{bs}); + } +}; +bitset< 6 > TestBody_bs(2); +void TestBody() { format(TestBody_bs); } \ No newline at end of file >From ee331f6f1e257c7636913616c4f223de49d10641 Mon Sep 17 00:00:00 2001 From: shenjunjie Date: Fri, 27 Dec 2024 14:35:12 + Subject: [PATCH 3/4] fix testcase --- clang/test/Analysis/PR121201.cpp | 67 1 file changed, 42 insertions(+), 25 deletions(-) diff --git a/clang/test/Analysis/PR121201.cpp b/clang/test/Analysis/PR121201.cpp index a2cea89dc10b79..49ce92957ad8a8 100644 --- a/clang/test/Analysis/PR121201.cpp +++ b/clang/test/Analysis/PR121201.cpp @@ -1,50 +1,67 @@ +// RUN: %clang_analyze_cc1 -analyzer-checker=core -analyzer-config +// unroll-loops=true -verify %s -template < bool, typename T, typename > using conditional_t = T; +// expected-no-diagnostics + +template using conditional_t = T; class basic_format_arg; -template < typename > struct formatter; -template < typename Context > struct value { - template < typename T > value(T) { +template struct formatter; + +template struct value { + template value(T) { using value_type = T; -format_custom_arg< -value_type, typename Context::template formatter_type< value_type > >; +format_custom_arg>; } - template < typename, typename Formatter > static void format_custom_arg() { + + template static void format_custom_arg() { Context ctx; auto f = Formatter(); f.format(0, ctx); }
[clang] [analyzer] Fix zext assertion failure in loop unrolling (PR #121203)
steakhal wrote: Could you please add a RUN line to the test, and a `// no-crash` comment at the line where previously crashed during interpretation? I'd also prefer a `clang-formated` test file if possible. Are you sure the test case is minimal and couldn't be minimized further now that you know why it crashes? https://github.com/llvm/llvm-project/pull/121203 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] Added options to readability-implicit-bool-conversion (PR #120087)
github-actions[bot] wrote: :warning: C/C++ code formatter, clang-format found issues in your code. :warning: You can test this locally with the following command: ``bash git-clang-format --diff 6d34cfac53b993a6cdf3d6669e017eac3a2296c8 75fe805c9e2b45632e2653b3e3a1b7874ede2507 --extensions h,cpp -- clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion-check.cpp clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.h `` View the diff from clang-format here. ``diff diff --git a/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp index 6c5456ef60..48851da143 100644 --- a/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp @@ -349,26 +349,27 @@ void ImplicitBoolConversionCheck::registerMatchers(MatchFinder *Finder) { forField(hasBitWidth(1); Finder->addMatcher( -traverse(TK_AsIs, implicitCastExpr( - ImplicitCastFromBool, unless(ExceptionCases), - // Exclude comparisons of bools, as they are - // always cast to integers in such context: - // bool_expr_a == bool_expr_b - // bool_expr_a != bool_expr_b - unless(hasParent(binaryOperator(anyOf( - BoolComparison, BoolXor, BoolOpAssignment, - BitfieldAssignment, - implicitCastExpr().bind("implicitCastFromBool"), - unless(hasParent(BitfieldConstruct)), - // Check also for nested casts, for example: - // bool -> int -> float. - anyOf(hasParent(implicitCastExpr().bind( -"furtherImplicitCast")), -anything()), - unless(isInTemplateInstantiation()), - unless(IsInCompilerGeneratedFunction))), +traverse( +TK_AsIs, +implicitCastExpr( +ImplicitCastFromBool, unless(ExceptionCases), +// Exclude comparisons of bools, as they are +// always cast to integers in such context: +// bool_expr_a == bool_expr_b +// bool_expr_a != bool_expr_b +unless(hasParent(binaryOperator(anyOf(BoolComparison, BoolXor, + BoolOpAssignment, + BitfieldAssignment, +implicitCastExpr().bind("implicitCastFromBool"), +unless(hasParent(BitfieldConstruct)), +// Check also for nested casts, for example: +// bool -> int -> float. + anyOf(hasParent(implicitCastExpr().bind("furtherImplicitCast")), + anything()), +unless(isInTemplateInstantiation()), +unless(IsInCompilerGeneratedFunction))), this); - } + } } void ImplicitBoolConversionCheck::check( `` https://github.com/llvm/llvm-project/pull/120087 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Fix zext assertion failure in loop unrolling (PR #121203)
shenjunjiekoda wrote: > Contributor The crash occurred due to a failed assertion in the `zext` method of APInt. The `zext` function requires the following condition to be met: ```cpp // Zero extend to a new width. APInt APInt::zext(unsigned width) const { assert(width >= BitWidth && "Invalid APInt ZeroExtend request"); // ... } ``` However, the original logic in `clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp` used an inequality check (!=) to determine if the widths were mismatched. This could lead to a scenario where one of the `zext `calls in the if block triggers the assertion failure internally: ```cpp static bool shouldCompletelyUnroll(const Stmt *LoopStmt, ASTContext &ASTCtx, ExplodedNode *Pred, unsigned &maxStep) { // ... if (InitNum.getBitWidth() != BoundNum.getBitWidth()) { InitNum = InitNum.zext(BoundNum.getBitWidth()); BoundNum = BoundNum.zext(InitNum.getBitWidth()); } ``` For the test case, I used the `cvise` tool to simplify `the test/std-test.cc` file from the `libfmt` repo while ensuring it remained free of compilation errors. This test case appears to be the minimal version that `cvise` could produce. https://github.com/llvm/llvm-project/pull/121203 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [analyzer] Fix zext assertion failure in loop unrolling (PR #121203)
https://github.com/shenjunjiekoda updated https://github.com/llvm/llvm-project/pull/121203 >From 2cee5fc2abd0cf2979c9ba975906e659adcd4463 Mon Sep 17 00:00:00 2001 From: shenjunjie Date: Fri, 27 Dec 2024 14:08:55 + Subject: [PATCH 1/6] [analyzer] Fix zext assertion failure in loop unrolling --- clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp | 10 ++ 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp b/clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp index 96f5d7c44baf89..9227a7876c0b2f 100644 --- a/clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp +++ b/clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp @@ -283,10 +283,12 @@ static bool shouldCompletelyUnroll(const Stmt *LoopStmt, ASTContext &ASTCtx, llvm::APInt InitNum = Matches[0].getNodeAs("initNum")->getValue(); auto CondOp = Matches[0].getNodeAs("conditionOperator"); - if (InitNum.getBitWidth() != BoundNum.getBitWidth()) { -InitNum = InitNum.zext(BoundNum.getBitWidth()); -BoundNum = BoundNum.zext(InitNum.getBitWidth()); - } + unsigned MaxWidth = std::max(InitNum.getBitWidth(), BoundNum.getBitWidth()); + + if (InitNum.getBitWidth() != MaxWidth) +InitNum = InitNum.zext(MaxWidth); + if (BoundNum.getBitWidth() != MaxWidth) +BoundNum = BoundNum.zext(MaxWidth); if (CondOp->getOpcode() == BO_GE || CondOp->getOpcode() == BO_LE) maxStep = (BoundNum - InitNum + 1).abs().getZExtValue(); >From a4d3a24ea797c5f53c5171e05f7172434096bd65 Mon Sep 17 00:00:00 2001 From: shenjunjie Date: Fri, 27 Dec 2024 14:20:23 + Subject: [PATCH 2/6] add testcase --- clang/test/Analysis/PR121201.cpp | 50 1 file changed, 50 insertions(+) create mode 100644 clang/test/Analysis/PR121201.cpp diff --git a/clang/test/Analysis/PR121201.cpp b/clang/test/Analysis/PR121201.cpp new file mode 100644 index 00..a2cea89dc10b79 --- /dev/null +++ b/clang/test/Analysis/PR121201.cpp @@ -0,0 +1,50 @@ + +template < bool, typename T, typename > using conditional_t = T; +class basic_format_arg; +template < typename > struct formatter; +template < typename Context > struct value { + template < typename T > value(T) { +using value_type = T; +format_custom_arg< +value_type, typename Context::template formatter_type< value_type > >; + } + template < typename, typename Formatter > static void format_custom_arg() { +Context ctx; +auto f = Formatter(); +f.format(0, ctx); + } +}; +struct context { + template < typename T > using formatter_type = formatter< T >; +}; +enum { max_packed_args }; +template < typename Context, long > +using arg_t = +conditional_t< max_packed_args, value< Context >, basic_format_arg >; +template < int NUM_ARGS > struct format_arg_store { + arg_t< context, NUM_ARGS > args; +}; +template < typename... T, long NUM_ARGS = sizeof...(T) > +auto make_format_args(T... args) -> format_arg_store< NUM_ARGS > { + return {args...}; +} +template < typename F > void write_padded(F write) { write(0); } +template < typename... T > void format(T... args) { make_format_args(args...); } +template < int > struct bitset { + bitset(long); +}; +template < long N > struct formatter< bitset< N > > { + struct writer { +bitset< N > bs; +template < typename OutputIt > void operator()(OutputIt) { + for (auto pos = N; pos > 0; --pos) +; +} + }; + template < typename FormatContext > + void format(bitset< N > bs, FormatContext) { +write_padded(writer{bs}); + } +}; +bitset< 6 > TestBody_bs(2); +void TestBody() { format(TestBody_bs); } \ No newline at end of file >From ee331f6f1e257c7636913616c4f223de49d10641 Mon Sep 17 00:00:00 2001 From: shenjunjie Date: Fri, 27 Dec 2024 14:35:12 + Subject: [PATCH 3/6] fix testcase --- clang/test/Analysis/PR121201.cpp | 67 1 file changed, 42 insertions(+), 25 deletions(-) diff --git a/clang/test/Analysis/PR121201.cpp b/clang/test/Analysis/PR121201.cpp index a2cea89dc10b79..49ce92957ad8a8 100644 --- a/clang/test/Analysis/PR121201.cpp +++ b/clang/test/Analysis/PR121201.cpp @@ -1,50 +1,67 @@ +// RUN: %clang_analyze_cc1 -analyzer-checker=core -analyzer-config +// unroll-loops=true -verify %s -template < bool, typename T, typename > using conditional_t = T; +// expected-no-diagnostics + +template using conditional_t = T; class basic_format_arg; -template < typename > struct formatter; -template < typename Context > struct value { - template < typename T > value(T) { +template struct formatter; + +template struct value { + template value(T) { using value_type = T; -format_custom_arg< -value_type, typename Context::template formatter_type< value_type > >; +format_custom_arg>; } - template < typename, typename Formatter > static void format_custom_arg() { + + template static void format_custom_arg() { Context ctx; auto f = Formatter(); f.format(0, ctx); }
[clang-tools-extra] Added options to readability-implicit-bool-conversion (PR #120087)
@@ -319,10 +319,11 @@ Changes in existing checks diagnostic. - Improved :doc:`readability-implicit-bool-conversion - ` check - by adding the option `UseUpperCaseLiteralSuffix` to select the - case of the literal suffix in fixes and fixing false positive for implicit - conversion of comparison result in C23. + ` check by adding the + option `UseUpperCaseLiteralSuffix` to select the case of the literal suffix in + fixes and fixing false positive for implicit conversion of comparison result in + C23 , and by adding the option `CheckConversionsToBool` or EugeneZelenko wrote: Please fix Clang-format complains. https://github.com/llvm/llvm-project/pull/120087 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Fix implicit-check-not regex (PR #121221)
https://github.com/vitalybuka created https://github.com/llvm/llvm-project/pull/121221 We need to exclude more than builtins, but it's tricky with FileCheck regex. So switching to list of libs we want to check. >From a2d45112466ba69eeb8ca9236469a653d6ff700c Mon Sep 17 00:00:00 2001 From: Vitaly Buka Date: Fri, 27 Dec 2024 10:51:15 -0800 Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20initia?= =?UTF-8?q?l=20version?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Created using spr 1.3.4 --- clang/test/Driver/sanitizer-ld.c | 13 - 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/clang/test/Driver/sanitizer-ld.c b/clang/test/Driver/sanitizer-ld.c index 5befbb159183e9..4e4cfbae27e113 100644 --- a/clang/test/Driver/sanitizer-ld.c +++ b/clang/test/Driver/sanitizer-ld.c @@ -1,8 +1,9 @@ // Test sanitizers ld flags. -// Match all libclang_rt, excluding platform-inconsistent builtins. +// Match all libclang_rt, excluding platform-inconsistent libs, like +// libclang_rt.builtins, libclang_rt.osx etc. -// DEFINE: %{filecheck} = FileCheck %s --implicit-check-not="libclang_rt.{{([^b]..|.[^u].|..[^i]).*}}" +// DEFINE: %{filecheck} = FileCheck %s --implicit-check-not="libclang_rt.{{([^.]+san|scudo|cfi|safestack|stats|fuzzer|undefined)}}" // RUN: %clang -### %s 2>&1 \ // RUN: --target=i386-unknown-linux -fuse-ld=ld -fsanitize=address \ @@ -37,7 +38,6 @@ // RUN: | %{filecheck} --check-prefix=CHECK-ASAN-NO-LINK-RUNTIME-DARWIN // // CHECK-ASAN-NO-LINK-RUNTIME-DARWIN: "{{.*}}ld" -// CHECK-ASAN-NO-LINK-RUNTIME-DARWIN: libclang_rt.osx.a" // RUN: %clang -fsanitize=address -### %s 2>&1 \ // RUN: --target=x86_64-unknown-linux -fuse-ld=ld \ @@ -366,7 +366,6 @@ // RUN: | %{filecheck} --check-prefix=CHECK-TYSAN-DARWIN-CXX // CHECK-TYSAN-DARWIN-CXX: "{{.*}}ld" // CHECK-TYSAN-DARWIN-CXX: libclang_rt.tysan_osx_dynamic.dylib -// CHECK-TYSAN-DARWIN-CXX: libclang_rt.osx.a // CHECK-TYSAN-DARWIN-CXX-NOT: -lc++abi // RUN: %clangxx -### %s 2>&1 \ @@ -403,7 +402,7 @@ // RUN: --sysroot=%S/Inputs/basic_linux_tree \ // RUN: | %{filecheck} --check-prefix=CHECK-TSAN-NO-LINK-RUNTIME-DARWIN // -// CHECK-TSAN-NO-LINK-RUNTIME-DARWIN: libclang_rt.ios.a +// CHECK-TSAN-NO-LINK-RUNTIME-DARWIN: "{{(.*[^-.0-9A-Z_a-z])?}}ld" // RUN: %clangxx -### %s 2>&1 \ // RUN: --target=x86_64-unknown-linux -fuse-ld=ld -stdlib=platform -lstdc++ \ @@ -473,7 +472,6 @@ // RUN: | %{filecheck} --check-prefix=CHECK-UBSAN-NO-LINK-RUNTIME-DARWIN // // CHECK-UBSAN-NO-LINK-RUNTIME-DARWIN: "{{.*}}ld" -// CHECK-UBSAN-NO-LINK-RUNTIME-DARWIN: libclang_rt.osx.a // RUN: %clang -fsanitize=fuzzer -fno-sanitize-link-runtime -### %s 2>&1 \ // RUN: --target=arm64e-apple-watchos -fuse-ld=ld \ @@ -482,7 +480,6 @@ // RUN: | %{filecheck} --check-prefix=CHECK-FUZZER-NO-LINK-RUNTIME-DARWIN // // CHECK-FUZZER-NO-LINK-RUNTIME-DARWIN: "{{.*}}ld" -// CHECK-FUZZER-NO-LINK-RUNTIME-DARWIN: libclang_rt.watchos.a // RUN: %clang -fsanitize=undefined -### %s 2>&1 \ // RUN: --target=i386-unknown-linux -fuse-ld=ld \ @@ -838,7 +835,6 @@ // CHECK-ASAN-DARWIN106-CXX: "{{.*}}ld" // CHECK-ASAN-DARWIN106-CXX: libclang_rt.asan_osx_dynamic.dylib // CHECK-ASAN-DARWIN106-CXX-NOT: -lc++abi -// CHECK-ASAN-DARWIN106-CXX: libclang_rt.osx.a // RUN: %clangxx -fsanitize=leak -### %s 2>&1 \ // RUN: -mmacos-version-min=10.6 \ @@ -849,7 +845,6 @@ // CHECK-LSAN-DARWIN106-CXX: "{{.*}}ld" // CHECK-LSAN-DARWIN106-CXX: libclang_rt.lsan_osx_dynamic.dylib // CHECK-LSAN-DARWIN106-CXX-NOT: -lc++abi -// CHECK-LSAN-DARWIN106-CXX: libclang_rt.osx.a // RUN: %clang -### %s 2>&1 \ // RUN: --target=x86_64-unknown-linux -fuse-ld=ld -fsanitize=safe-stack \ ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Fix implicit-check-not regex (PR #121221)
vitalybuka wrote: @MaskRay in case you have a nicer suggestion how to implement this check in better way. I'd like to force match of all libclang_rt. except specific list. With `([^b]..|.[^u].|..[^i]).*` I can exclude only one, and expressions like `(?!(ABC|XYZ)).*`, are not supported https://github.com/llvm/llvm-project/pull/121221 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Annotate darwin check (PR #121217)
https://github.com/Caslyn closed https://github.com/llvm/llvm-project/pull/121217 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Fix implicit-check-not regex (PR #121221)
llvmbot wrote: @llvm/pr-subscribers-clang-driver Author: Vitaly Buka (vitalybuka) Changes We need to exclude more than builtins, but it's tricky with FileCheck regex. So switching to list of libs we want to check. --- Full diff: https://github.com/llvm/llvm-project/pull/121221.diff 1 Files Affected: - (modified) clang/test/Driver/sanitizer-ld.c (+4-9) ``diff diff --git a/clang/test/Driver/sanitizer-ld.c b/clang/test/Driver/sanitizer-ld.c index 5befbb159183e9..4e4cfbae27e113 100644 --- a/clang/test/Driver/sanitizer-ld.c +++ b/clang/test/Driver/sanitizer-ld.c @@ -1,8 +1,9 @@ // Test sanitizers ld flags. -// Match all libclang_rt, excluding platform-inconsistent builtins. +// Match all libclang_rt, excluding platform-inconsistent libs, like +// libclang_rt.builtins, libclang_rt.osx etc. -// DEFINE: %{filecheck} = FileCheck %s --implicit-check-not="libclang_rt.{{([^b]..|.[^u].|..[^i]).*}}" +// DEFINE: %{filecheck} = FileCheck %s --implicit-check-not="libclang_rt.{{([^.]+san|scudo|cfi|safestack|stats|fuzzer|undefined)}}" // RUN: %clang -### %s 2>&1 \ // RUN: --target=i386-unknown-linux -fuse-ld=ld -fsanitize=address \ @@ -37,7 +38,6 @@ // RUN: | %{filecheck} --check-prefix=CHECK-ASAN-NO-LINK-RUNTIME-DARWIN // // CHECK-ASAN-NO-LINK-RUNTIME-DARWIN: "{{.*}}ld" -// CHECK-ASAN-NO-LINK-RUNTIME-DARWIN: libclang_rt.osx.a" // RUN: %clang -fsanitize=address -### %s 2>&1 \ // RUN: --target=x86_64-unknown-linux -fuse-ld=ld \ @@ -366,7 +366,6 @@ // RUN: | %{filecheck} --check-prefix=CHECK-TYSAN-DARWIN-CXX // CHECK-TYSAN-DARWIN-CXX: "{{.*}}ld" // CHECK-TYSAN-DARWIN-CXX: libclang_rt.tysan_osx_dynamic.dylib -// CHECK-TYSAN-DARWIN-CXX: libclang_rt.osx.a // CHECK-TYSAN-DARWIN-CXX-NOT: -lc++abi // RUN: %clangxx -### %s 2>&1 \ @@ -403,7 +402,7 @@ // RUN: --sysroot=%S/Inputs/basic_linux_tree \ // RUN: | %{filecheck} --check-prefix=CHECK-TSAN-NO-LINK-RUNTIME-DARWIN // -// CHECK-TSAN-NO-LINK-RUNTIME-DARWIN: libclang_rt.ios.a +// CHECK-TSAN-NO-LINK-RUNTIME-DARWIN: "{{(.*[^-.0-9A-Z_a-z])?}}ld" // RUN: %clangxx -### %s 2>&1 \ // RUN: --target=x86_64-unknown-linux -fuse-ld=ld -stdlib=platform -lstdc++ \ @@ -473,7 +472,6 @@ // RUN: | %{filecheck} --check-prefix=CHECK-UBSAN-NO-LINK-RUNTIME-DARWIN // // CHECK-UBSAN-NO-LINK-RUNTIME-DARWIN: "{{.*}}ld" -// CHECK-UBSAN-NO-LINK-RUNTIME-DARWIN: libclang_rt.osx.a // RUN: %clang -fsanitize=fuzzer -fno-sanitize-link-runtime -### %s 2>&1 \ // RUN: --target=arm64e-apple-watchos -fuse-ld=ld \ @@ -482,7 +480,6 @@ // RUN: | %{filecheck} --check-prefix=CHECK-FUZZER-NO-LINK-RUNTIME-DARWIN // // CHECK-FUZZER-NO-LINK-RUNTIME-DARWIN: "{{.*}}ld" -// CHECK-FUZZER-NO-LINK-RUNTIME-DARWIN: libclang_rt.watchos.a // RUN: %clang -fsanitize=undefined -### %s 2>&1 \ // RUN: --target=i386-unknown-linux -fuse-ld=ld \ @@ -838,7 +835,6 @@ // CHECK-ASAN-DARWIN106-CXX: "{{.*}}ld" // CHECK-ASAN-DARWIN106-CXX: libclang_rt.asan_osx_dynamic.dylib // CHECK-ASAN-DARWIN106-CXX-NOT: -lc++abi -// CHECK-ASAN-DARWIN106-CXX: libclang_rt.osx.a // RUN: %clangxx -fsanitize=leak -### %s 2>&1 \ // RUN: -mmacos-version-min=10.6 \ @@ -849,7 +845,6 @@ // CHECK-LSAN-DARWIN106-CXX: "{{.*}}ld" // CHECK-LSAN-DARWIN106-CXX: libclang_rt.lsan_osx_dynamic.dylib // CHECK-LSAN-DARWIN106-CXX-NOT: -lc++abi -// CHECK-LSAN-DARWIN106-CXX: libclang_rt.osx.a // RUN: %clang -### %s 2>&1 \ // RUN: --target=x86_64-unknown-linux -fuse-ld=ld -fsanitize=safe-stack \ `` https://github.com/llvm/llvm-project/pull/121221 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Fix implicit-check-not regex (PR #121221)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Vitaly Buka (vitalybuka) Changes We need to exclude more than builtins, but it's tricky with FileCheck regex. So switching to list of libs we want to check. --- Full diff: https://github.com/llvm/llvm-project/pull/121221.diff 1 Files Affected: - (modified) clang/test/Driver/sanitizer-ld.c (+4-9) ``diff diff --git a/clang/test/Driver/sanitizer-ld.c b/clang/test/Driver/sanitizer-ld.c index 5befbb159183e9..4e4cfbae27e113 100644 --- a/clang/test/Driver/sanitizer-ld.c +++ b/clang/test/Driver/sanitizer-ld.c @@ -1,8 +1,9 @@ // Test sanitizers ld flags. -// Match all libclang_rt, excluding platform-inconsistent builtins. +// Match all libclang_rt, excluding platform-inconsistent libs, like +// libclang_rt.builtins, libclang_rt.osx etc. -// DEFINE: %{filecheck} = FileCheck %s --implicit-check-not="libclang_rt.{{([^b]..|.[^u].|..[^i]).*}}" +// DEFINE: %{filecheck} = FileCheck %s --implicit-check-not="libclang_rt.{{([^.]+san|scudo|cfi|safestack|stats|fuzzer|undefined)}}" // RUN: %clang -### %s 2>&1 \ // RUN: --target=i386-unknown-linux -fuse-ld=ld -fsanitize=address \ @@ -37,7 +38,6 @@ // RUN: | %{filecheck} --check-prefix=CHECK-ASAN-NO-LINK-RUNTIME-DARWIN // // CHECK-ASAN-NO-LINK-RUNTIME-DARWIN: "{{.*}}ld" -// CHECK-ASAN-NO-LINK-RUNTIME-DARWIN: libclang_rt.osx.a" // RUN: %clang -fsanitize=address -### %s 2>&1 \ // RUN: --target=x86_64-unknown-linux -fuse-ld=ld \ @@ -366,7 +366,6 @@ // RUN: | %{filecheck} --check-prefix=CHECK-TYSAN-DARWIN-CXX // CHECK-TYSAN-DARWIN-CXX: "{{.*}}ld" // CHECK-TYSAN-DARWIN-CXX: libclang_rt.tysan_osx_dynamic.dylib -// CHECK-TYSAN-DARWIN-CXX: libclang_rt.osx.a // CHECK-TYSAN-DARWIN-CXX-NOT: -lc++abi // RUN: %clangxx -### %s 2>&1 \ @@ -403,7 +402,7 @@ // RUN: --sysroot=%S/Inputs/basic_linux_tree \ // RUN: | %{filecheck} --check-prefix=CHECK-TSAN-NO-LINK-RUNTIME-DARWIN // -// CHECK-TSAN-NO-LINK-RUNTIME-DARWIN: libclang_rt.ios.a +// CHECK-TSAN-NO-LINK-RUNTIME-DARWIN: "{{(.*[^-.0-9A-Z_a-z])?}}ld" // RUN: %clangxx -### %s 2>&1 \ // RUN: --target=x86_64-unknown-linux -fuse-ld=ld -stdlib=platform -lstdc++ \ @@ -473,7 +472,6 @@ // RUN: | %{filecheck} --check-prefix=CHECK-UBSAN-NO-LINK-RUNTIME-DARWIN // // CHECK-UBSAN-NO-LINK-RUNTIME-DARWIN: "{{.*}}ld" -// CHECK-UBSAN-NO-LINK-RUNTIME-DARWIN: libclang_rt.osx.a // RUN: %clang -fsanitize=fuzzer -fno-sanitize-link-runtime -### %s 2>&1 \ // RUN: --target=arm64e-apple-watchos -fuse-ld=ld \ @@ -482,7 +480,6 @@ // RUN: | %{filecheck} --check-prefix=CHECK-FUZZER-NO-LINK-RUNTIME-DARWIN // // CHECK-FUZZER-NO-LINK-RUNTIME-DARWIN: "{{.*}}ld" -// CHECK-FUZZER-NO-LINK-RUNTIME-DARWIN: libclang_rt.watchos.a // RUN: %clang -fsanitize=undefined -### %s 2>&1 \ // RUN: --target=i386-unknown-linux -fuse-ld=ld \ @@ -838,7 +835,6 @@ // CHECK-ASAN-DARWIN106-CXX: "{{.*}}ld" // CHECK-ASAN-DARWIN106-CXX: libclang_rt.asan_osx_dynamic.dylib // CHECK-ASAN-DARWIN106-CXX-NOT: -lc++abi -// CHECK-ASAN-DARWIN106-CXX: libclang_rt.osx.a // RUN: %clangxx -fsanitize=leak -### %s 2>&1 \ // RUN: -mmacos-version-min=10.6 \ @@ -849,7 +845,6 @@ // CHECK-LSAN-DARWIN106-CXX: "{{.*}}ld" // CHECK-LSAN-DARWIN106-CXX: libclang_rt.lsan_osx_dynamic.dylib // CHECK-LSAN-DARWIN106-CXX-NOT: -lc++abi -// CHECK-LSAN-DARWIN106-CXX: libclang_rt.osx.a // RUN: %clang -### %s 2>&1 \ // RUN: --target=x86_64-unknown-linux -fuse-ld=ld -fsanitize=safe-stack \ `` https://github.com/llvm/llvm-project/pull/121221 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] Allow specifying what headers are always included via "" or <> (PR #67749)
HighCommander4 wrote: The rebased patch has green buildkite runs, so I will go ahead and merge it. https://github.com/llvm/llvm-project/pull/67749 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Driver] Annotate darwin check (PR #121217)
Caslyn wrote: Fixed under https://github.com/llvm/llvm-project/pull/121221. https://github.com/llvm/llvm-project/pull/121217 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] 1f90797 - [clangd] Allow specifying what headers are always included via "" or <> (#67749)
Author: kleines Filmröllchen Date: 2024-12-27T14:14:29-05:00 New Revision: 1f90797f6a9d91d61e0f66b465b0467e4c66d0e0 URL: https://github.com/llvm/llvm-project/commit/1f90797f6a9d91d61e0f66b465b0467e4c66d0e0 DIFF: https://github.com/llvm/llvm-project/commit/1f90797f6a9d91d61e0f66b465b0467e4c66d0e0.diff LOG: [clangd] Allow specifying what headers are always included via "" or <> (#67749) Projects can now add config fragments like this to their .clangd: ```yaml Style: QuotedHeaders: "src/.*" AngledHeaders: ["path/sdk/.*", "third-party/.*"] ``` to force headers inserted via the --header-insertion=iwyu mode matching at least one of the regexes to have <> (AngledHeaders) or "" (QuotedHeaders) around them, respectively. For other headers (and in conflicting cases where both styles have a matching regex), the current system header detection remains. Fixes https://github.com/clangd/clangd/issues/1247 Added: Modified: clang-tools-extra/clangd/CodeComplete.cpp clang-tools-extra/clangd/Config.h clang-tools-extra/clangd/ConfigCompile.cpp clang-tools-extra/clangd/ConfigFragment.h clang-tools-extra/clangd/ConfigYAML.cpp clang-tools-extra/clangd/Headers.cpp clang-tools-extra/clangd/Headers.h clang-tools-extra/clangd/IncludeCleaner.h clang-tools-extra/clangd/ParsedAST.cpp clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp clang-tools-extra/clangd/unittests/ConfigCompileTests.cpp clang-tools-extra/clangd/unittests/ConfigYAMLTests.cpp clang-tools-extra/clangd/unittests/HeadersTests.cpp Removed: diff --git a/clang-tools-extra/clangd/CodeComplete.cpp b/clang-tools-extra/clangd/CodeComplete.cpp index 2c2d5f0b5ac924..fb39b7b292242f 100644 --- a/clang-tools-extra/clangd/CodeComplete.cpp +++ b/clang-tools-extra/clangd/CodeComplete.cpp @@ -807,8 +807,8 @@ SpecifiedScope getQueryScopes(CodeCompletionContext &CCContext, llvm::StringRef SpelledSpecifier = Lexer::getSourceText( CharSourceRange::getCharRange(SemaSpecifier->getRange()), CCSema.SourceMgr, clang::LangOptions()); - if (SpelledSpecifier.consume_front("::")) - Scopes.QueryScopes = {""}; + if (SpelledSpecifier.consume_front("::")) +Scopes.QueryScopes = {""}; Scopes.UnresolvedQualifier = std::string(SpelledSpecifier); // Sema excludes the trailing "::". if (!Scopes.UnresolvedQualifier->empty()) @@ -1604,7 +1604,7 @@ class CodeCompleteFlow { CompletionPrefix HeuristicPrefix; std::optional Filter; // Initialized once Sema runs. Range ReplacedRange; - std::vector QueryScopes; // Initialized once Sema runs. + std::vector QueryScopes; // Initialized once Sema runs. std::vector AccessibleScopes; // Initialized once Sema runs. // Initialized once QueryScopes is initialized, if there are scopes. std::optional ScopeProximity; @@ -1663,7 +1663,9 @@ class CodeCompleteFlow { Inserter.emplace( SemaCCInput.FileName, SemaCCInput.ParseInput.Contents, Style, SemaCCInput.ParseInput.CompileCommand.Directory, - &Recorder->CCSema->getPreprocessor().getHeaderSearchInfo()); + &Recorder->CCSema->getPreprocessor().getHeaderSearchInfo(), + Config::current().Style.QuotedHeaders, + Config::current().Style.AngledHeaders); for (const auto &Inc : Includes.MainFileIncludes) Inserter->addExisting(Inc); @@ -1746,7 +1748,9 @@ class CodeCompleteFlow { auto Style = getFormatStyleForFile(FileName, Content, TFS, false); // This will only insert verbatim headers. Inserter.emplace(FileName, Content, Style, - /*BuildDir=*/"", /*HeaderSearchInfo=*/nullptr); + /*BuildDir=*/"", /*HeaderSearchInfo=*/nullptr, + Config::current().Style.QuotedHeaders, + Config::current().Style.AngledHeaders); auto Identifiers = collectIdentifiers(Content, Style); std::vector IdentifierResults; diff --git a/clang-tools-extra/clangd/Config.h b/clang-tools-extra/clangd/Config.h index e174f7fabe344e..586d031d58481d 100644 --- a/clang-tools-extra/clangd/Config.h +++ b/clang-tools-extra/clangd/Config.h @@ -124,6 +124,10 @@ struct Config { // declarations, always spell out the whole name (with or without leading // ::). All nested namespaces are affected as well. std::vector FullyQualifiedNamespaces; + +// List of matcher functions for inserting certain headers with <> or "". +std::vector> QuotedHeaders; +std::vector> AngledHeaders; } Style; /// controls the completion options for argument lists. diff --git a/clang-tools-extra/clangd/ConfigCompile.cpp b/clang-tools-extra/clangd/ConfigCompile.cpp index fb7692998d05c7..aa2561e081047b 100644 --- a/clang-tools-extra/clangd/ConfigCompile.cpp +++ b/clang-tools-extra/clangd/ConfigCompile.cpp @@ -482,6 +482,55 @@ struct FragmentCompiler {
[clang-tools-extra] [clangd] Allow specifying what headers are always included via "" or <> (PR #67749)
https://github.com/HighCommander4 closed https://github.com/llvm/llvm-project/pull/67749 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][P1061] Fix template arguments in local classes (PR #121225)
https://github.com/ricejasonf created https://github.com/llvm/llvm-project/pull/121225 In the development of P1061 (Structured Bindings Introduce a Patch), I found this bug in the template instantiation of a local class. The issue is caused by the instantiation of the original template and not the partially instantiated template. In the example (sans the fix) the instantiation uses the first template parameter from the previous instantiation and not the current one so the error hits an assertion when it is expecting an NTTP. If they were both types then it might gladly accept the type from the wrong template which is kind of scary. In the test, the reference to `i` is substituted with a placeholder AST object that represents the resolved value when instantiating `g`. However, since the old template is used, the instantiation sees an AST object that only contains the template argument index in the context of instantiating the lambda which has a type template parameter (ie auto). I question if we should use `getTemplateInstantiationPattern` at all here. Other errors involving local classes in nested templates could also be caused by the misuse of this function (because it gets the uninstantiated template). >From f1058d13315682b8bd6c3ac06a3225060d11ec61 Mon Sep 17 00:00:00 2001 From: Jason Rice Date: Mon, 5 Aug 2024 13:53:33 -0700 Subject: [PATCH] [Clang][P1061] Fix template arguments in local classes --- clang/lib/Sema/SemaTemplateInstantiate.cpp | 6 +- .../SemaCXX/local-class-template-param-crash.cpp | 14 ++ 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 clang/test/SemaCXX/local-class-template-param-crash.cpp diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp b/clang/lib/Sema/SemaTemplateInstantiate.cpp index fb0f38df62a744..baa5ff35295349 100644 --- a/clang/lib/Sema/SemaTemplateInstantiate.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp @@ -4433,8 +4433,12 @@ Sema::InstantiateClassMembers(SourceLocation PointOfInstantiation, // No need to instantiate in-class initializers during explicit // instantiation. if (Field->hasInClassInitializer() && TSK == TSK_ImplicitInstantiation) { +// Handle local classes which could have substituted template params. CXXRecordDecl *ClassPattern = -Instantiation->getTemplateInstantiationPattern(); +Instantiation->isLocalClass() +? Instantiation->getInstantiatedFromMemberClass() +: Instantiation->getTemplateInstantiationPattern(); + DeclContext::lookup_result Lookup = ClassPattern->lookup(Field->getDeclName()); FieldDecl *Pattern = Lookup.find_first(); diff --git a/clang/test/SemaCXX/local-class-template-param-crash.cpp b/clang/test/SemaCXX/local-class-template-param-crash.cpp new file mode 100644 index 00..ffa8590eaf77d8 --- /dev/null +++ b/clang/test/SemaCXX/local-class-template-param-crash.cpp @@ -0,0 +1,14 @@ +// RUN: %clang_cc1 -fsyntax-only %s -verify +// expected-no-diagnostics + +template +int g() { + return [] (auto) -> int { +struct L { + int m = i; +}; +return 0; + } (42); +} + +int v = g<1>(); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang][P1061] Fix template arguments in local classes (PR #121225)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Jason Rice (ricejasonf) Changes In the development of P1061 (Structured Bindings Introduce a Patch), I found this bug in the template instantiation of a local class. The issue is caused by the instantiation of the original template and not the partially instantiated template. In the example (sans the fix) the instantiation uses the first template parameter from the previous instantiation and not the current one so the error hits an assertion when it is expecting an NTTP. If they were both types then it might gladly accept the type from the wrong template which is kind of scary. In the test, the reference to `i` is substituted with a placeholder AST object that represents the resolved value when instantiating `g`. However, since the old template is used, the instantiation sees an AST object that only contains the template argument index in the context of instantiating the lambda which has a type template parameter (ie auto). I question if we should use `getTemplateInstantiationPattern` at all here. Other errors involving local classes in nested templates could also be caused by the misuse of this function (because it gets the uninstantiated template). --- Full diff: https://github.com/llvm/llvm-project/pull/121225.diff 2 Files Affected: - (modified) clang/lib/Sema/SemaTemplateInstantiate.cpp (+5-1) - (added) clang/test/SemaCXX/local-class-template-param-crash.cpp (+14) ``diff diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp b/clang/lib/Sema/SemaTemplateInstantiate.cpp index fb0f38df62a744..baa5ff35295349 100644 --- a/clang/lib/Sema/SemaTemplateInstantiate.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp @@ -4433,8 +4433,12 @@ Sema::InstantiateClassMembers(SourceLocation PointOfInstantiation, // No need to instantiate in-class initializers during explicit // instantiation. if (Field->hasInClassInitializer() && TSK == TSK_ImplicitInstantiation) { +// Handle local classes which could have substituted template params. CXXRecordDecl *ClassPattern = -Instantiation->getTemplateInstantiationPattern(); +Instantiation->isLocalClass() +? Instantiation->getInstantiatedFromMemberClass() +: Instantiation->getTemplateInstantiationPattern(); + DeclContext::lookup_result Lookup = ClassPattern->lookup(Field->getDeclName()); FieldDecl *Pattern = Lookup.find_first(); diff --git a/clang/test/SemaCXX/local-class-template-param-crash.cpp b/clang/test/SemaCXX/local-class-template-param-crash.cpp new file mode 100644 index 00..ffa8590eaf77d8 --- /dev/null +++ b/clang/test/SemaCXX/local-class-template-param-crash.cpp @@ -0,0 +1,14 @@ +// RUN: %clang_cc1 -fsyntax-only %s -verify +// expected-no-diagnostics + +template +int g() { + return [] (auto) -> int { +struct L { + int m = i; +}; +return 0; + } (42); +} + +int v = g<1>(); `` https://github.com/llvm/llvm-project/pull/121225 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] add depercation warning for non-whitelisted global options (PR #121057)
HerrCai0907 wrote: > I wonder however how it will work for people who are stuck in old clang-tidy > files for whatever reason Good point, maybe we can use more smart way to do warning: only warn the global option is set but local option is not. Have some redundant options is not the aim for this deprecation things, we only want to avoid user suddenly find the behaviors of lots of check are changed. So we only need to warn for config which rely on global option and no local option. https://github.com/llvm/llvm-project/pull/121057 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [llvm] [RISCV] Add Qualcomm uC Xqciac (Load-Store Adress calculation) extension (PR #121037)
@@ -184,6 +191,37 @@ let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in { } // hasSideEffects = 0, mayLoad = 0, mayStore = 0 } // Predicates = [HasVendorXqcia, IsRV32], DecoderNamespace = "Xqcia" +let Predicates = [HasVendorXqciac, IsRV32], DecoderNamespace = "Xqciac" in { +let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in { + def QC_C_MULADDI : RVInst16CL<0b001, 0b10, (outs GPRC:$rd_wb), + (ins GPRC:$rd, GPRC:$rs1, uimm5:$uimm), + "qc.c.muladdi", "$rd, $rs1, $uimm"> { +let Constraints = "$rd = $rd_wb"; +bits<5> uimm; + +let Inst{12-10} = uimm{3-1}; +let Inst{6} = uimm{0}; +let Inst{5} = uimm{4}; + } lenary wrote: @topperc there are other issues with adding compresspats for Xqci instructions which we are aware of and making plans to address - mostly around the fact there's no way to switch compresspats off for a pat where the larger and smaller instruction are in the same extension. We have a sketch of the solution internally but I've not finished it because we see CompressPats as an optimisation, not part of base assembler/linker support. https://github.com/llvm/llvm-project/pull/121037 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy][clangd] Fixed removeFunctionArgs don't remove comma for use-ranges check (PR #118568)
@@ -164,6 +164,33 @@ void UseRangesCheck::registerMatchers(MatchFinder *Finder) { static void removeFunctionArgs(DiagnosticBuilder &Diag, const CallExpr &Call, ArrayRef Indexes, const ASTContext &Ctx) { + auto GetCommaLoc = + [&](SourceLocation BeginLoc, + SourceLocation EndLoc) -> std::optional { +auto Invalid = false; +auto SourceText = Lexer::getSourceText( HerrCai0907 wrote: avoid to use `auto` when type explicitly appears later. https://github.com/llvm/llvm-project/pull/118568 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy][clangd] Fixed removeFunctionArgs don't remove comma for use-ranges check (PR #118568)
@@ -164,6 +164,33 @@ void UseRangesCheck::registerMatchers(MatchFinder *Finder) { static void removeFunctionArgs(DiagnosticBuilder &Diag, const CallExpr &Call, ArrayRef Indexes, const ASTContext &Ctx) { + auto GetCommaLoc = + [&](SourceLocation BeginLoc, + SourceLocation EndLoc) -> std::optional { +auto Invalid = false; +auto SourceText = Lexer::getSourceText( +CharSourceRange::getCharRange({BeginLoc, EndLoc}), +Ctx.getSourceManager(), Ctx.getLangOpts(), &Invalid); +assert(!Invalid); + +size_t I = 0; +while (I < SourceText.size() && SourceText[I] != ',') { + I++; +} + +if (I < SourceText.size()) { + // also remove space after , + size_t J = I + 1; + while (J < SourceText.size() && SourceText[J] == ' ') { +J++; + } HerrCai0907 wrote: replace with `find_first_of` https://github.com/llvm/llvm-project/pull/118568 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] swap cppcoreguidelines-narrowing-conversions and bugprone-narrowing-conversions (PR #120245)
https://github.com/HerrCai0907 updated https://github.com/llvm/llvm-project/pull/120245 >From 9e47698969dc59df1abaa8abd243b97e8fa038c3 Mon Sep 17 00:00:00 2001 From: Congcong Cai Date: Tue, 17 Dec 2024 23:31:52 +0800 Subject: [PATCH 1/5] [clang-tidy][NFC] swap cppcoreguidelines-narrowing-conversions and bugprone-narrowing-conversions According to #116591. > Coding guidelines should "cherry-pick" (and posddsibly configure/harden/make > more strict) base checks. We should move narrowing conversion to bugprone and keep alias in cppcoreguidelines --- .../bugprone/BugproneTidyModule.cpp | 4 +- .../clang-tidy/bugprone/CMakeLists.txt| 1 + .../NarrowingConversionsCheck.cpp | 2 +- .../NarrowingConversionsCheck.h | 2 +- .../cppcoreguidelines/CMakeLists.txt | 1 - .../CppCoreGuidelinesTidyModule.cpp | 4 +- .../checks/bugprone/narrowing-conversions.rst | 93 +- .../narrowing-conversions.rst | 91 + .../narrowing-conversions-bitfields.cpp | 4 +- ...-conversions-equivalentbitwidth-option.cpp | 20 ++-- ...sions-ignoreconversionfromtypes-option.cpp | 28 +++--- ...rrowing-conversions-intemplates-option.cpp | 12 +-- .../narrowing-conversions-long-is-32bits.cpp | 6 +- ...versions-narrowingfloatingpoint-option.cpp | 24 ++--- ...ng-conversions-narrowinginteger-option.cpp | 16 +-- ...narrowingintegertofloatingpoint-option.cpp | 19 ...rowing-conversions-pedanticmode-option.cpp | 12 +-- .../narrowing-conversions-unsigned-char.cpp | 22 ++--- .../narrowing-conversions.cpp | 98 +-- ...narrowingintegertofloatingpoint-option.cpp | 19 20 files changed, 240 insertions(+), 238 deletions(-) rename clang-tools-extra/clang-tidy/{cppcoreguidelines => bugprone}/NarrowingConversionsCheck.cpp (99%) rename clang-tools-extra/clang-tidy/{cppcoreguidelines => bugprone}/NarrowingConversionsCheck.h (99%) rename clang-tools-extra/test/clang-tidy/checkers/{cppcoreguidelines => bugprone}/narrowing-conversions-bitfields.cpp (97%) rename clang-tools-extra/test/clang-tidy/checkers/{cppcoreguidelines => bugprone}/narrowing-conversions-equivalentbitwidth-option.cpp (66%) rename clang-tools-extra/test/clang-tidy/checkers/{cppcoreguidelines => bugprone}/narrowing-conversions-ignoreconversionfromtypes-option.cpp (75%) rename clang-tools-extra/test/clang-tidy/checkers/{cppcoreguidelines => bugprone}/narrowing-conversions-intemplates-option.cpp (73%) rename clang-tools-extra/test/clang-tidy/checkers/{cppcoreguidelines => bugprone}/narrowing-conversions-long-is-32bits.cpp (84%) rename clang-tools-extra/test/clang-tidy/checkers/{cppcoreguidelines => bugprone}/narrowing-conversions-narrowingfloatingpoint-option.cpp (70%) rename clang-tools-extra/test/clang-tidy/checkers/{cppcoreguidelines => bugprone}/narrowing-conversions-narrowinginteger-option.cpp (59%) create mode 100644 clang-tools-extra/test/clang-tidy/checkers/bugprone/narrowing-conversions-narrowingintegertofloatingpoint-option.cpp rename clang-tools-extra/test/clang-tidy/checkers/{cppcoreguidelines => bugprone}/narrowing-conversions-pedanticmode-option.cpp (52%) rename clang-tools-extra/test/clang-tidy/checkers/{cppcoreguidelines => bugprone}/narrowing-conversions-unsigned-char.cpp (80%) rename clang-tools-extra/test/clang-tidy/checkers/{cppcoreguidelines => bugprone}/narrowing-conversions.cpp (77%) delete mode 100644 clang-tools-extra/test/clang-tidy/checkers/cppcoreguidelines/narrowing-conversions-narrowingintegertofloatingpoint-option.cpp diff --git a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp index 33ac65e715ce81..c55acf0f4e1803 100644 --- a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp +++ b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp @@ -9,7 +9,6 @@ #include "../ClangTidy.h" #include "../ClangTidyModule.h" #include "../ClangTidyModuleRegistry.h" -#include "../cppcoreguidelines/NarrowingConversionsCheck.h" #include "ArgumentCommentCheck.h" #include "AssertSideEffectCheck.h" #include "AssignmentInIfConditionCheck.h" @@ -17,6 +16,7 @@ #include "BitwisePointerCastCheck.h" #include "BoolPointerImplicitConversionCheck.h" #include "BranchCloneCheck.h" +#include "NarrowingConversionsCheck.h" #include "CastingThroughVoidCheck.h" #include "ChainedComparisonCheck.h" #include "ComparePointerToMemberVirtualFunctionCheck.h" @@ -183,7 +183,7 @@ class BugproneModule : public ClangTidyModule { "bugprone-pointer-arithmetic-on-polymorphic-object"); CheckFactories.registerCheck( "bugprone-redundant-branch-condition"); -CheckFactories.registerCheck( +CheckFactories.registerCheck( "bugprone-narrowing-conversions"); CheckFactories.registerCheck("bugprone-no-escape"); CheckFactories.registerCheck( diff --git a/clang-tools-extra/cla
[clang-tools-extra] [clang-tidy] swap cppcoreguidelines-narrowing-conversions and bugprone-narrowing-conversions (PR #120245)
HerrCai0907 wrote: sorry for forgetting it https://github.com/llvm/llvm-project/pull/120245 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] Added options to readability-implicit-bool-conversion (PR #120087)
https://github.com/HerrCai0907 approved this pull request. LGTM. If you do not have write access, please ping me. we can help you to do merge. https://github.com/llvm/llvm-project/pull/120087 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] add depercation warning for non-whitelisted global options (PR #121057)
https://github.com/HerrCai0907 updated https://github.com/llvm/llvm-project/pull/121057 >From 98d65a0b9a1189ce73d97d76527b458f93f17b43 Mon Sep 17 00:00:00 2001 From: Congcong Cai Date: Tue, 24 Dec 2024 23:32:02 +0800 Subject: [PATCH 1/2] [clang-tidy] add depercation warning for non-whitelisted global options --- .../clang-tidy/ClangTidyCheck.cpp | 32 --- .../checkers/modernize/use-std-format-fmt.cpp | 2 +- .../deprecation-global-option.cpp | 3 ++ 3 files changed, 25 insertions(+), 12 deletions(-) create mode 100644 clang-tools-extra/test/clang-tidy/infrastructure/deprecation-global-option.cpp diff --git a/clang-tools-extra/clang-tidy/ClangTidyCheck.cpp b/clang-tools-extra/clang-tidy/ClangTidyCheck.cpp index 6028bb2258136b..5161ffeedf70df 100644 --- a/clang-tools-extra/clang-tidy/ClangTidyCheck.cpp +++ b/clang-tools-extra/clang-tidy/ClangTidyCheck.cpp @@ -7,11 +7,11 @@ //===--===// #include "ClangTidyCheck.h" -#include "llvm/ADT/SmallString.h" #include "llvm/ADT/StringRef.h" -#include "llvm/Support/Error.h" +#include "llvm/ADT/StringSet.h" #include "llvm/Support/YAMLParser.h" #include +#include namespace clang::tidy { @@ -62,16 +62,29 @@ ClangTidyCheck::OptionsView::get(StringRef LocalName) const { return std::nullopt; } +static const llvm::StringSet<> DeprecatedGlobalOptions{ +"StrictMode", +"IgnoreMacros", +}; + static ClangTidyOptions::OptionMap::const_iterator findPriorityOption(const ClangTidyOptions::OptionMap &Options, StringRef NamePrefix, StringRef LocalName, - llvm::StringSet<> *Collector) { + ClangTidyContext *Context) { + llvm::StringSet<> *Collector = Context->getOptionsCollector(); if (Collector) { Collector->insert((NamePrefix + LocalName).str()); Collector->insert(LocalName); } auto IterLocal = Options.find((NamePrefix + LocalName).str()); auto IterGlobal = Options.find(LocalName); + // FIXME: temporary solution for deprecation warnings, should be removed + // after 22.x. + if (IterGlobal != Options.end() && + DeprecatedGlobalOptions.contains(LocalName)) +Context->configurationDiag( +"deprecation global option '%0', please use '%1%0'.") +<< LocalName << NamePrefix; if (IterLocal == Options.end()) return IterGlobal; if (IterGlobal == Options.end()) @@ -83,8 +96,7 @@ findPriorityOption(const ClangTidyOptions::OptionMap &Options, std::optional ClangTidyCheck::OptionsView::getLocalOrGlobal(StringRef LocalName) const { - auto Iter = findPriorityOption(CheckOptions, NamePrefix, LocalName, - Context->getOptionsCollector()); + auto Iter = findPriorityOption(CheckOptions, NamePrefix, LocalName, Context); if (Iter != CheckOptions.end()) return StringRef(Iter->getValue().Value); return std::nullopt; @@ -117,8 +129,7 @@ ClangTidyCheck::OptionsView::get(StringRef LocalName) const { template <> std::optional ClangTidyCheck::OptionsView::getLocalOrGlobal(StringRef LocalName) const { - auto Iter = findPriorityOption(CheckOptions, NamePrefix, LocalName, - Context->getOptionsCollector()); + auto Iter = findPriorityOption(CheckOptions, NamePrefix, LocalName, Context); if (Iter != CheckOptions.end()) { if (auto Result = getAsBool(Iter->getValue().Value, Iter->getKey())) return Result; @@ -157,10 +168,9 @@ std::optional ClangTidyCheck::OptionsView::getEnumInt( bool IgnoreCase) const { if (!CheckGlobal && Context->getOptionsCollector()) Context->getOptionsCollector()->insert((NamePrefix + LocalName).str()); - auto Iter = CheckGlobal - ? findPriorityOption(CheckOptions, NamePrefix, LocalName, - Context->getOptionsCollector()) - : CheckOptions.find((NamePrefix + LocalName).str()); + auto Iter = CheckGlobal ? findPriorityOption(CheckOptions, NamePrefix, + LocalName, Context) + : CheckOptions.find((NamePrefix + LocalName).str()); if (Iter == CheckOptions.end()) return std::nullopt; diff --git a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-format-fmt.cpp b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-format-fmt.cpp index 1eaf18ac119966..71c8af190467cf 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-format-fmt.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-format-fmt.cpp @@ -1,6 +1,6 @@ // RUN: %check_clang_tidy %s modernize-use-std-format %t -- \ // RUN: -config="{CheckOptions: { \ -// RUN: StrictMode: true, \ +// RUN: modernize-use-std-format.StrictMode: true, \ // RUN: modernize-use-std-format.StrFormatLikeFunctions: 'fmt::sprintf', \ // RUN:
[clang] [clang-format] Add `AllowShortNamespacesOnASingleLine` option (PR #105597)
https://github.com/galenelias updated https://github.com/llvm/llvm-project/pull/105597 >From 93eb3d89652607173f4f68fce7dcc5b2bd33f266 Mon Sep 17 00:00:00 2001 From: Galen Elias Date: Wed, 21 Aug 2024 16:33:42 -0700 Subject: [PATCH 01/14] clang-format: Add "AllowShortNamespacesOnASingleLine" option This addresses: https://github.com/llvm/llvm-project/issues/101363 which is a resurrection of a previously opened but never completed review: https://reviews.llvm.org/D11851 The feature is to allow code like the following not to be broken across multiple lines: ``` namespace foo { class bar; } namespace foo { namespace bar { class baz; } } ``` Code like this is commonly used for forward declarations, which are ideally kept compact. This is also apparently the format that include-what-you-use will insert for forward declarations. --- clang/include/clang/Format/Format.h | 5 + clang/lib/Format/Format.cpp | 3 + clang/lib/Format/UnwrappedLineFormatter.cpp | 82 ++ clang/unittests/Format/FormatTest.cpp | 112 4 files changed, 202 insertions(+) diff --git a/clang/include/clang/Format/Format.h b/clang/include/clang/Format/Format.h index 6383934afa2c40..26cd673685942e 100644 --- a/clang/include/clang/Format/Format.h +++ b/clang/include/clang/Format/Format.h @@ -988,6 +988,11 @@ struct FormatStyle { /// \version 3.7 bool AllowShortLoopsOnASingleLine; + /// If ``true``, ``namespace a { class b; }`` can be put on a single a single + /// line. + /// \version 19 + bool AllowShortNamespacesOnASingleLine; + /// Different ways to break after the function definition return type. /// This option is **deprecated** and is retained for backwards compatibility. enum DefinitionReturnTypeBreakingStyle : int8_t { diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index 95129a8fe9240c..8f44e9f00212cf 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -975,6 +975,8 @@ template <> struct MappingTraits { Style.AllowShortLambdasOnASingleLine); IO.mapOptional("AllowShortLoopsOnASingleLine", Style.AllowShortLoopsOnASingleLine); +IO.mapOptional("AllowShortNamespacesOnASingleLine", + Style.AllowShortNamespacesOnASingleLine); IO.mapOptional("AlwaysBreakAfterDefinitionReturnType", Style.AlwaysBreakAfterDefinitionReturnType); IO.mapOptional("AlwaysBreakBeforeMultilineStrings", @@ -1480,6 +1482,7 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind Language) { LLVMStyle.AllowShortIfStatementsOnASingleLine = FormatStyle::SIS_Never; LLVMStyle.AllowShortLambdasOnASingleLine = FormatStyle::SLS_All; LLVMStyle.AllowShortLoopsOnASingleLine = false; + LLVMStyle.AllowShortNamespacesOnASingleLine = false; LLVMStyle.AlwaysBreakAfterDefinitionReturnType = FormatStyle::DRTBS_None; LLVMStyle.AlwaysBreakBeforeMultilineStrings = false; LLVMStyle.AttributeMacros.push_back("__capability"); diff --git a/clang/lib/Format/UnwrappedLineFormatter.cpp b/clang/lib/Format/UnwrappedLineFormatter.cpp index 1804c1437fd41d..971eac1978bb71 100644 --- a/clang/lib/Format/UnwrappedLineFormatter.cpp +++ b/clang/lib/Format/UnwrappedLineFormatter.cpp @@ -420,6 +420,15 @@ class LineJoiner { TheLine->First != LastNonComment) { return MergeShortFunctions ? tryMergeSimpleBlock(I, E, Limit) : 0; } + +if (TheLine->Last->is(tok::l_brace)) { + if (Style.AllowShortNamespacesOnASingleLine && + TheLine->First->is(tok::kw_namespace)) { +if (unsigned result = tryMergeNamespace(I, E, Limit)) + return result; + } +} + // Try to merge a control statement block with left brace unwrapped. if (TheLine->Last->is(tok::l_brace) && FirstNonComment != TheLine->Last && FirstNonComment->isOneOf(tok::kw_if, tok::kw_while, tok::kw_for, @@ -616,6 +625,62 @@ class LineJoiner { return 1; } + unsigned tryMergeNamespace(SmallVectorImpl::const_iterator I, + SmallVectorImpl::const_iterator E, + unsigned Limit) { +if (Limit == 0) + return 0; +if (I[1]->InPPDirective != (*I)->InPPDirective || +(I[1]->InPPDirective && I[1]->First->HasUnescapedNewline)) { + return 0; +} +if (I + 2 == E || I[2]->Type == LT_Invalid) + return 0; + +Limit = limitConsideringMacros(I + 1, E, Limit); + +if (!nextTwoLinesFitInto(I, Limit)) + return 0; + +// Check if it's a namespace inside a namespace, and call recursively if so +// '3' is the sizes of the whitespace and closing brace for " _inner_ }" +if (I[1]->First->is(tok::kw_namespace)) { + if (I[1]->Last->is(TT_LineComment)) +return 0; + + unsigned inner_limit = Limit - I[1]->Last->TotalLength - 3; + unsigned inner_result = tryMergeNamespace(I + 1, E, inner_limit); + if (!inner_result) +
[clang] [clang][bytecode] Add support for typeid pointers (PR #121251)
https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/121251 Add it as another kind of pointer, saving both a `Type*` for the result of the typeid() expression as well as one for the type of the typeid expression. >From aad3e96d970be36964faceec8d0a6df3dd27e5ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= Date: Thu, 26 Dec 2024 08:54:48 +0100 Subject: [PATCH] [clang][bytecode] Add support for typeid pointers Add it as another kind of pointer, saving both a `Type*` for the result of the typeid() expression as well as one for the type of the typeid expression. --- clang/lib/AST/ByteCode/Compiler.cpp | 32 +++ clang/lib/AST/ByteCode/Compiler.h | 1 + clang/lib/AST/ByteCode/Interp.cpp | 82 + clang/lib/AST/ByteCode/Interp.h | 63 +++--- clang/lib/AST/ByteCode/Opcodes.td | 4 ++ clang/lib/AST/ByteCode/Pointer.cpp | 14 + clang/lib/AST/ByteCode/Pointer.h| 25 +++-- clang/test/AST/ByteCode/cxx2a.cpp | 60 + 8 files changed, 222 insertions(+), 59 deletions(-) diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp index 68c75b01e6f6df..036f9608bf3ca1 100644 --- a/clang/lib/AST/ByteCode/Compiler.cpp +++ b/clang/lib/AST/ByteCode/Compiler.cpp @@ -3426,6 +3426,38 @@ bool Compiler::VisitBlockExpr(const BlockExpr *E) { return this->emitGetFnPtr(Func, E); } +template +bool Compiler::VisitCXXTypeidExpr(const CXXTypeidExpr *E) { + const Type *TypeInfoType = E->getType().getTypePtr(); + + if (!E->isPotentiallyEvaluated()) { +if (DiscardResult) + return true; + +if (E->isTypeOperand()) + return this->emitGetTypeid( + E->getTypeOperand(Ctx.getASTContext()).getTypePtr(), TypeInfoType, E); +return this->emitGetTypeid(E->getExprOperand()->getType().getTypePtr(), + TypeInfoType, E); + } + + // Otherwise, we need to evaluate the expression operand. + assert(E->getExprOperand()); + assert(E->getExprOperand()->isLValue()); + + if (!Ctx.getLangOpts().CPlusPlus20 && !this->emitDiagTypeid(E)) +return false; + + if (!this->visit(E->getExprOperand())) +return false; + + if (!this->emitGetTypeidPtr(TypeInfoType, E)) +return false; + if (DiscardResult) +return this->emitPopPtr(E); + return true; +} + template bool Compiler::VisitExpressionTraitExpr(const ExpressionTraitExpr *E) { assert(Ctx.getLangOpts().CPlusPlus); diff --git a/clang/lib/AST/ByteCode/Compiler.h b/clang/lib/AST/ByteCode/Compiler.h index 2a94f5ec76b6c5..71765b18cb1a90 100644 --- a/clang/lib/AST/ByteCode/Compiler.h +++ b/clang/lib/AST/ByteCode/Compiler.h @@ -205,6 +205,7 @@ class Compiler : public ConstStmtVisitor, bool>, bool VisitCXXNewExpr(const CXXNewExpr *E); bool VisitCXXDeleteExpr(const CXXDeleteExpr *E); bool VisitBlockExpr(const BlockExpr *E); + bool VisitCXXTypeidExpr(const CXXTypeidExpr *E); // Statements. bool visitCompoundStmt(const CompoundStmt *S); diff --git a/clang/lib/AST/ByteCode/Interp.cpp b/clang/lib/AST/ByteCode/Interp.cpp index 7c7752080746e9..cb0ce886f66809 100644 --- a/clang/lib/AST/ByteCode/Interp.cpp +++ b/clang/lib/AST/ByteCode/Interp.cpp @@ -1154,6 +1154,53 @@ bool CheckLiteralType(InterpState &S, CodePtr OpPC, const Type *T) { return false; } +static bool getField(InterpState &S, CodePtr OpPC, const Pointer &Ptr, + uint32_t Off) { + if (S.getLangOpts().CPlusPlus && S.inConstantContext() && + !CheckNull(S, OpPC, Ptr, CSK_Field)) +return false; + + if (!CheckExtern(S, OpPC, Ptr)) +return false; + if (!CheckRange(S, OpPC, Ptr, CSK_Field)) +return false; + if (!CheckArray(S, OpPC, Ptr)) +return false; + if (!CheckSubobject(S, OpPC, Ptr, CSK_Field)) +return false; + + if (Ptr.isIntegralPointer()) { +S.Stk.push(Ptr.asIntPointer().atOffset(S.getASTContext(), Off)); +return true; + } + + if (!Ptr.isBlockPointer()) { +// FIXME: The only time we (seem to) get here is when trying to access a +// field of a typeid pointer. In that case, we're supposed to diagnose e.g. +// `typeid(int).name`, but we currently diagnose `&typeid(int)`. +S.FFDiag(S.Current->getSource(OpPC), + diag::note_constexpr_access_unreadable_object) +<< AK_Read << Ptr.toDiagnosticString(S.getASTContext()); +return false; + } + + if (Off > Ptr.block()->getSize()) +return false; + + S.Stk.push(Ptr.atField(Off)); + return true; +} + +bool GetPtrField(InterpState &S, CodePtr OpPC, uint32_t Off) { + const auto &Ptr = S.Stk.peek(); + return getField(S, OpPC, Ptr, Off); +} + +bool GetPtrFieldPop(InterpState &S, CodePtr OpPC, uint32_t Off) { + const auto &Ptr = S.Stk.pop(); + return getField(S, OpPC, Ptr, Off); +} + static bool checkConstructor(InterpState &S, CodePtr OpPC, const Function *Func, const Pointer &ThisPtr) { assert(Func->isConstructo
[clang] [clang][bytecode] Move a local variable to a later point (PR #121250)
https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/121250 We don't need `E` before. >From 3ecbfa862eee6b6c1f009dfcf6b9791e77af97b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Timm=20B=C3=A4der?= Date: Sat, 28 Dec 2024 06:38:52 +0100 Subject: [PATCH] [clang][bytecode] Move a local variable to a later point We don't need `E` before. --- clang/lib/AST/ByteCode/Pointer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/lib/AST/ByteCode/Pointer.cpp b/clang/lib/AST/ByteCode/Pointer.cpp index 54484853fcdaea..01e642310aad37 100644 --- a/clang/lib/AST/ByteCode/Pointer.cpp +++ b/clang/lib/AST/ByteCode/Pointer.cpp @@ -476,10 +476,10 @@ bool Pointer::pointsToLiteral() const { if (isZero() || !isBlockPointer()) return false; - const Expr *E = block()->getDescriptor()->asExpr(); if (block()->isDynamic()) return false; + const Expr *E = block()->getDescriptor()->asExpr(); return E && !isa(E); } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][bytecode] Add support for typeid pointers (PR #121251)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Timm Baeder (tbaederr) Changes Add it as another kind of pointer, saving both a `Type*` for the result of the typeid() expression as well as one for the type of the typeid expression. --- Full diff: https://github.com/llvm/llvm-project/pull/121251.diff 8 Files Affected: - (modified) clang/lib/AST/ByteCode/Compiler.cpp (+32) - (modified) clang/lib/AST/ByteCode/Compiler.h (+1) - (modified) clang/lib/AST/ByteCode/Interp.cpp (+82) - (modified) clang/lib/AST/ByteCode/Interp.h (+8-55) - (modified) clang/lib/AST/ByteCode/Opcodes.td (+4) - (modified) clang/lib/AST/ByteCode/Pointer.cpp (+14) - (modified) clang/lib/AST/ByteCode/Pointer.h (+21-4) - (modified) clang/test/AST/ByteCode/cxx2a.cpp (+60) ``diff diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp index 68c75b01e6f6df..036f9608bf3ca1 100644 --- a/clang/lib/AST/ByteCode/Compiler.cpp +++ b/clang/lib/AST/ByteCode/Compiler.cpp @@ -3426,6 +3426,38 @@ bool Compiler::VisitBlockExpr(const BlockExpr *E) { return this->emitGetFnPtr(Func, E); } +template +bool Compiler::VisitCXXTypeidExpr(const CXXTypeidExpr *E) { + const Type *TypeInfoType = E->getType().getTypePtr(); + + if (!E->isPotentiallyEvaluated()) { +if (DiscardResult) + return true; + +if (E->isTypeOperand()) + return this->emitGetTypeid( + E->getTypeOperand(Ctx.getASTContext()).getTypePtr(), TypeInfoType, E); +return this->emitGetTypeid(E->getExprOperand()->getType().getTypePtr(), + TypeInfoType, E); + } + + // Otherwise, we need to evaluate the expression operand. + assert(E->getExprOperand()); + assert(E->getExprOperand()->isLValue()); + + if (!Ctx.getLangOpts().CPlusPlus20 && !this->emitDiagTypeid(E)) +return false; + + if (!this->visit(E->getExprOperand())) +return false; + + if (!this->emitGetTypeidPtr(TypeInfoType, E)) +return false; + if (DiscardResult) +return this->emitPopPtr(E); + return true; +} + template bool Compiler::VisitExpressionTraitExpr(const ExpressionTraitExpr *E) { assert(Ctx.getLangOpts().CPlusPlus); diff --git a/clang/lib/AST/ByteCode/Compiler.h b/clang/lib/AST/ByteCode/Compiler.h index 2a94f5ec76b6c5..71765b18cb1a90 100644 --- a/clang/lib/AST/ByteCode/Compiler.h +++ b/clang/lib/AST/ByteCode/Compiler.h @@ -205,6 +205,7 @@ class Compiler : public ConstStmtVisitor, bool>, bool VisitCXXNewExpr(const CXXNewExpr *E); bool VisitCXXDeleteExpr(const CXXDeleteExpr *E); bool VisitBlockExpr(const BlockExpr *E); + bool VisitCXXTypeidExpr(const CXXTypeidExpr *E); // Statements. bool visitCompoundStmt(const CompoundStmt *S); diff --git a/clang/lib/AST/ByteCode/Interp.cpp b/clang/lib/AST/ByteCode/Interp.cpp index 7c7752080746e9..cb0ce886f66809 100644 --- a/clang/lib/AST/ByteCode/Interp.cpp +++ b/clang/lib/AST/ByteCode/Interp.cpp @@ -1154,6 +1154,53 @@ bool CheckLiteralType(InterpState &S, CodePtr OpPC, const Type *T) { return false; } +static bool getField(InterpState &S, CodePtr OpPC, const Pointer &Ptr, + uint32_t Off) { + if (S.getLangOpts().CPlusPlus && S.inConstantContext() && + !CheckNull(S, OpPC, Ptr, CSK_Field)) +return false; + + if (!CheckExtern(S, OpPC, Ptr)) +return false; + if (!CheckRange(S, OpPC, Ptr, CSK_Field)) +return false; + if (!CheckArray(S, OpPC, Ptr)) +return false; + if (!CheckSubobject(S, OpPC, Ptr, CSK_Field)) +return false; + + if (Ptr.isIntegralPointer()) { +S.Stk.push(Ptr.asIntPointer().atOffset(S.getASTContext(), Off)); +return true; + } + + if (!Ptr.isBlockPointer()) { +// FIXME: The only time we (seem to) get here is when trying to access a +// field of a typeid pointer. In that case, we're supposed to diagnose e.g. +// `typeid(int).name`, but we currently diagnose `&typeid(int)`. +S.FFDiag(S.Current->getSource(OpPC), + diag::note_constexpr_access_unreadable_object) +<< AK_Read << Ptr.toDiagnosticString(S.getASTContext()); +return false; + } + + if (Off > Ptr.block()->getSize()) +return false; + + S.Stk.push(Ptr.atField(Off)); + return true; +} + +bool GetPtrField(InterpState &S, CodePtr OpPC, uint32_t Off) { + const auto &Ptr = S.Stk.peek(); + return getField(S, OpPC, Ptr, Off); +} + +bool GetPtrFieldPop(InterpState &S, CodePtr OpPC, uint32_t Off) { + const auto &Ptr = S.Stk.pop(); + return getField(S, OpPC, Ptr, Off); +} + static bool checkConstructor(InterpState &S, CodePtr OpPC, const Function *Func, const Pointer &ThisPtr) { assert(Func->isConstructor()); @@ -1595,6 +1642,41 @@ bool CheckBitCast(InterpState &S, CodePtr OpPC, bool HasIndeterminateBits, return false; } +bool GetTypeid(InterpState &S, CodePtr OpPC, const Type *TypePtr, + const Type *TypeInfoType) { + S.Stk.push(TypePtr, TypeInfoType); + return true; +} + +bool GetTypeidPtr(InterpState
[clang] [clang][bytecode] Move a local variable to a later point (PR #121250)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Timm Baeder (tbaederr) Changes We don't need `E` before. --- Full diff: https://github.com/llvm/llvm-project/pull/121250.diff 1 Files Affected: - (modified) clang/lib/AST/ByteCode/Pointer.cpp (+1-1) ``diff diff --git a/clang/lib/AST/ByteCode/Pointer.cpp b/clang/lib/AST/ByteCode/Pointer.cpp index 54484853fcdaea..01e642310aad37 100644 --- a/clang/lib/AST/ByteCode/Pointer.cpp +++ b/clang/lib/AST/ByteCode/Pointer.cpp @@ -476,10 +476,10 @@ bool Pointer::pointsToLiteral() const { if (isZero() || !isBlockPointer()) return false; - const Expr *E = block()->getDescriptor()->asExpr(); if (block()->isDynamic()) return false; + const Expr *E = block()->getDescriptor()->asExpr(); return E && !isa(E); } `` https://github.com/llvm/llvm-project/pull/121250 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] Added options to readability-implicit-bool-conversion (PR #120087)
https://github.com/HerrCai0907 closed https://github.com/llvm/llvm-project/pull/120087 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] 5bec2b7 - Added options to readability-implicit-bool-conversion (#120087)
Author: 4m4n-x-B4w4ne Date: 2024-12-28T15:35:30+08:00 New Revision: 5bec2b71b44ddff44aa4d8534b58a5561389bb1d URL: https://github.com/llvm/llvm-project/commit/5bec2b71b44ddff44aa4d8534b58a5561389bb1d DIFF: https://github.com/llvm/llvm-project/commit/5bec2b71b44ddff44aa4d8534b58a5561389bb1d.diff LOG: Added options to readability-implicit-bool-conversion (#120087) As given in the issue #36323 , I added two new options in the clang-tools-extra/clan-tidy/readibility/ImplicitBoolConversionCheck.cpp and header file. I have also written new test cases to test these new options in test/readibility directory. Added: clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion-check.cpp Modified: clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.h clang-tools-extra/docs/ReleaseNotes.rst clang-tools-extra/docs/clang-tidy/checks/readability/implicit-bool-conversion.rst Removed: diff --git a/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp index f9fd1d903e231e..48851da143068f 100644 --- a/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp @@ -259,13 +259,17 @@ ImplicitBoolConversionCheck::ImplicitBoolConversionCheck( AllowIntegerConditions(Options.get("AllowIntegerConditions", false)), AllowPointerConditions(Options.get("AllowPointerConditions", false)), UseUpperCaseLiteralSuffix( - Options.get("UseUpperCaseLiteralSuffix", false)) {} + Options.get("UseUpperCaseLiteralSuffix", false)), + CheckConversionsToBool(Options.get("CheckConversionsToBool", true)), + CheckConversionsFromBool(Options.get("CheckConversionsFromBool", true)) {} void ImplicitBoolConversionCheck::storeOptions( ClangTidyOptions::OptionMap &Opts) { Options.store(Opts, "AllowIntegerConditions", AllowIntegerConditions); Options.store(Opts, "AllowPointerConditions", AllowPointerConditions); Options.store(Opts, "UseUpperCaseLiteralSuffix", UseUpperCaseLiteralSuffix); + Options.store(Opts, "CheckConversionsToBool", CheckConversionsToBool); + Options.store(Opts, "CheckConversionsFromBool", CheckConversionsFromBool); } void ImplicitBoolConversionCheck::registerMatchers(MatchFinder *Finder) { @@ -277,6 +281,7 @@ void ImplicitBoolConversionCheck::registerMatchers(MatchFinder *Finder) { expr(hasType(qualType().bind("type")), hasParent(initListExpr(hasParent(explicitCastExpr( hasType(qualType(equalsBoundNode("type")); + auto ImplicitCastFromBool = implicitCastExpr( anyOf(hasCastKind(CK_IntegralCast), hasCastKind(CK_IntegralToFloating), // Prior to C++11 cast from bool literal to pointer was allowed. @@ -287,72 +292,84 @@ void ImplicitBoolConversionCheck::registerMatchers(MatchFinder *Finder) { auto BoolXor = binaryOperator(hasOperatorName("^"), hasLHS(ImplicitCastFromBool), hasRHS(ImplicitCastFromBool)); - auto ComparisonInCall = allOf( - hasParent(callExpr()), - hasSourceExpression(binaryOperator(hasAnyOperatorName("==", "!="; - auto IsInCompilerGeneratedFunction = hasAncestor(namedDecl(anyOf( isImplicit(), functionDecl(isDefaulted()), functionTemplateDecl(; - Finder->addMatcher( - traverse(TK_AsIs, - implicitCastExpr( - anyOf(hasCastKind(CK_IntegralToBoolean), - hasCastKind(CK_FloatingToBoolean), - hasCastKind(CK_PointerToBoolean), - hasCastKind(CK_MemberPointerToBoolean)), - // Exclude cases of C23 comparison result. - unless(allOf(isC23(), -hasSourceExpression(ignoringParens( -binaryOperator(hasAnyOperatorName( -">", ">=", "==", "!=", "<", "<=")), - // Exclude case of using if or while statements with variable - // declaration, e.g.: - // if (int var = functionCall()) {} - unless(hasParent( - stmt(anyOf(ifStmt(), whileStmt()), has(declStmt(), - // Exclude cases common to implicit cast to and from bool. - unless(ExceptionCases), unless(has(BoolXor)), - // Exclude C23 cases common to implicit cast to bool. - unless(ComparisonInCall), - // Retrieve also parent statement, to check if we need - // additional parens in replacement. -
[clang-tools-extra] Added options to readability-implicit-bool-conversion (PR #120087)
llvm-ci wrote: LLVM Buildbot has detected a new failure on builder `clang-armv8-quick` running on `linaro-clang-armv8-quick` while building `clang-tools-extra` at step 5 "ninja check 1". Full details are available at: https://lab.llvm.org/buildbot/#/builders/154/builds/9576 Here is the relevant piece of the build log for the reference ``` Step 5 (ninja check 1) failure: stage 1 checked (failure) TEST 'Clang Tools :: clang-tidy/checkers/readability/implicit-bool-conversion-check.cpp' FAILED Exit Code: 1 Command Output (stdout): -- Running ['clang-tidy', '/home/tcwg-buildbot/worker/clang-armv8-quick/stage1/tools/clang/tools/extra/test/clang-tidy/checkers/readability/Output/implicit-bool-conversion-check.cpp.tmp.cpp', '-fix', '--checks=-*,readability-implicit-bool-conversion', '-config={CheckOptions: { readability-implicit-bool-conversion.CheckConversionsToBool: false, readability-implicit-bool-conversion.CheckConversionsFromBool: true }}', '--', '-std=c23', '-std=c++11', '-nostdinc++']... clang-tidy output --- 3 warnings generated. /home/tcwg-buildbot/worker/clang-armv8-quick/stage1/tools/clang/tools/extra/test/clang-tidy/checkers/readability/Output/implicit-bool-conversion-check.cpp.tmp.cpp:49:23: warning: implicit conversion 'bool' -> 'int' [readability-implicit-bool-conversion] 49 | int intFromBool = boolValue; // | ^ | static_cast( ) /home/tcwg-buildbot/worker/clang-armv8-quick/stage1/tools/clang/tools/extra/test/clang-tidy/checkers/readability/Output/implicit-bool-conversion-check.cpp.tmp.cpp:49:23: note: FIX-IT applied suggested code changes /home/tcwg-buildbot/worker/clang-armv8-quick/stage1/tools/clang/tools/extra/test/clang-tidy/checkers/readability/Output/implicit-bool-conversion-check.cpp.tmp.cpp:49:32: note: FIX-IT applied suggested code changes 49 | int intFromBool = boolValue; // |^ /home/tcwg-buildbot/worker/clang-armv8-quick/stage1/tools/clang/tools/extra/test/clang-tidy/checkers/readability/Output/implicit-bool-conversion-check.cpp.tmp.cpp:52:27: warning: implicit conversion 'bool' -> 'float' [readability-implicit-bool-conversion] 52 | float floatFromBool = boolValue; // | ^ | static_cast( ) /home/tcwg-buildbot/worker/clang-armv8-quick/stage1/tools/clang/tools/extra/test/clang-tidy/checkers/readability/Output/implicit-bool-conversion-check.cpp.tmp.cpp:52:27: note: FIX-IT applied suggested code changes /home/tcwg-buildbot/worker/clang-armv8-quick/stage1/tools/clang/tools/extra/test/clang-tidy/checkers/readability/Output/implicit-bool-conversion-check.cpp.tmp.cpp:52:36: note: FIX-IT applied suggested code changes 52 | float floatFromBool = boolValue; // |^ /home/tcwg-buildbot/worker/clang-armv8-quick/stage1/tools/clang/tools/extra/test/clang-tidy/checkers/readability/Output/implicit-bool-conversion-check.cpp.tmp.cpp:55:25: warning: implicit conversion 'bool' -> 'char' [readability-implicit-bool-conversion] 55 | char charFromBool = boolValue; // | ^ | static_cast( ) /home/tcwg-buildbot/worker/clang-armv8-quick/stage1/tools/clang/tools/extra/test/clang-tidy/checkers/readability/Output/implicit-bool-conversion-check.cpp.tmp.cpp:55:25: note: FIX-IT applied suggested code changes /home/tcwg-buildbot/worker/clang-armv8-quick/stage1/tools/clang/tools/extra/test/clang-tidy/checkers/readability/Output/implicit-bool-conversion-check.cpp.tmp.cpp:55:34: note: FIX-IT applied suggested code changes 55 | char charFromBool = boolValue; // | ^ clang-tidy applied 6 of 6 suggested fixes. -- diff -u /home/tcwg-buildbot/worker/clang-armv8-quick/stage1/tools/clang/tools/extra/test/clang-tidy/checkers/readability/Output/implicit-bool-conversion-check.cpp.tmp.orig /home/tcwg-buildbot/worker/clang-armv8-quick/stage1/tools/clang/tools/extra/test/clang-tidy/checkers/readability/Output/implicit-bool-conversion-check.cpp.tmp.cpp failed: --- /home/tcwg-buildbot/worker/clang-armv8-quick/stage1/tools/clang/tools/extra/test/clang-tidy/checkers/readability/Output/implicit-bool-conversion-check.cpp.tmp.orig 2024-12-28 07:46:09.330637388 + +++ /home/tcwg-buildbot/worker/clang-armv8-quick/stage1/tools/clang/tools/extra/test/clang-tidy/checkers/readability/Output/implicit-bool-conversion-check.cpp.tmp.cpp 2024-12-28 07:46:09.378637636 + @@ -46,12 +46,12 @@ // Conversions from bool to other types bool boolValue = true; -int intFromBool = boolValue; // +int intFromBool = static_cast(boolValue); // //
[clang] [Clang][ASTMatcher] Add `dependentScopeDeclRefExpr` Matcher (PR #120996)
AmrDeveloper wrote: > #121240 Sure, i am interested, Thank you :D https://github.com/llvm/llvm-project/pull/120996 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Delay marking pending incomplete decl chains until the end of `finishPendingActions`. (PR #121245)
https://github.com/mpark edited https://github.com/llvm/llvm-project/pull/121245 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Delay marking pending incomplete decl chains until the end of `finishPendingActions`. (PR #121245)
https://github.com/mpark edited https://github.com/llvm/llvm-project/pull/121245 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits