[clang] [clang][WebAssembly] Support the `-m(no-)red-zone` flag. (PR #119997)
https://github.com/alexrp edited https://github.com/llvm/llvm-project/pull/119997 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Fix crashes when the macro expansion is empty (PR #119428)
https://github.com/amane-ame updated https://github.com/llvm/llvm-project/pull/119428 From 3a4c1a924faef3a7a09126694fcb943bd7083451 Mon Sep 17 00:00:00 2001 From: amane-ame Date: Wed, 11 Dec 2024 02:13:43 +0800 Subject: [PATCH 1/2] Fix crashes when the macro expansion is empty --- clang/lib/Format/MacroExpander.cpp | 4 1 file changed, 4 insertions(+) diff --git a/clang/lib/Format/MacroExpander.cpp b/clang/lib/Format/MacroExpander.cpp index fd2a16894d643d..ed9e51dfbfef1f 100644 --- a/clang/lib/Format/MacroExpander.cpp +++ b/clang/lib/Format/MacroExpander.cpp @@ -233,6 +233,10 @@ MacroExpander::expand(FormatToken *ID, if (Result.size() > 1) { ++Result[0]->MacroCtx->StartOfExpansion; ++Result[Result.size() - 2]->MacroCtx->EndOfExpansion; + } else { +// If the macro expansion is empty, mark the start and end +Result[0]->MacroCtx->StartOfExpansion = 1; +Result[0]->MacroCtx->EndOfExpansion = 1; } return Result; } From 8bf68f87b897bab9da9464d594082be5012afdb1 Mon Sep 17 00:00:00 2001 From: amane-ame Date: Sun, 15 Dec 2024 15:15:17 +0800 Subject: [PATCH 2/2] [clang-format] Add a testcase for empty macro --- clang/test/Format/empty-macro.cpp | 5 + 1 file changed, 5 insertions(+) create mode 100644 clang/test/Format/empty-macro.cpp diff --git a/clang/test/Format/empty-macro.cpp b/clang/test/Format/empty-macro.cpp new file mode 100644 index 00..81b255219b0c2b --- /dev/null +++ b/clang/test/Format/empty-macro.cpp @@ -0,0 +1,5 @@ +// RUN: grep -Ev "// *[A-Z-]+:" %s | clang-format -style="{Macros: [A(x)=x]}" \ +// RUN: | FileCheck -strict-whitespace %s + +// CHECK: A() +A() ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Detect nesting in template strings (PR #119989)
https://github.com/gedare updated https://github.com/llvm/llvm-project/pull/119989 >From fa8d1b12eee0164f2b4c8223281d0e59dfa693e1 Mon Sep 17 00:00:00 2001 From: Gedare Bloom Date: Sat, 14 Dec 2024 15:25:44 -0700 Subject: [PATCH 1/2] [clang-format] detect nesting in template strings The helper to check if a token is in a template string scans too far backward. It should stop if a different scope is found. Fixes #107571 --- clang/lib/Format/ContinuationIndenter.cpp | 4 +++- clang/unittests/Format/FormatTestJS.cpp | 7 +++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp index aed86c1fb99551..9ffdc044e6784d 100644 --- a/clang/lib/Format/ContinuationIndenter.cpp +++ b/clang/lib/Format/ContinuationIndenter.cpp @@ -826,8 +826,10 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun, for (const auto *Prev = &Tok; Prev; Prev = Prev->Previous) { if (Prev->is(TT_TemplateString) && Prev->opensScope()) return true; - if (Prev->is(TT_TemplateString) && Prev->closesScope()) + if (Prev->opensScope() || + (Prev->is(TT_TemplateString) && Prev->closesScope())) { break; + } } return false; }; diff --git a/clang/unittests/Format/FormatTestJS.cpp b/clang/unittests/Format/FormatTestJS.cpp index 4b15e7b7da3393..678fd1f3fc8d0e 100644 --- a/clang/unittests/Format/FormatTestJS.cpp +++ b/clang/unittests/Format/FormatTestJS.cpp @@ -2157,6 +2157,13 @@ TEST_F(FormatTestJS, TemplateStringMultiLineExpression) { " : a,\n" " : b,\n" "})}`;"); + + verifyFormat("`${\n" + "(\n" + "FOOFOOFOOFOOFOO_FOO_FO_FOO_FOOO -\n" + "(barbarbarbarbar_bar_bar_bar_bar_bar +\n" + " bar_bar_bar_barbarbar___bar_bar_bar + 1),\n" + ")}`;\n"); } TEST_F(FormatTestJS, TemplateStringASI) { >From 77904096ff2ed1a17113e5e4b9c5f040a52d9fb0 Mon Sep 17 00:00:00 2001 From: Gedare Bloom Date: Sat, 14 Dec 2024 22:29:32 -0700 Subject: [PATCH 2/2] Update clang/unittests/Format/FormatTestJS.cpp Co-authored-by: Owen Pan --- clang/unittests/Format/FormatTestJS.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/unittests/Format/FormatTestJS.cpp b/clang/unittests/Format/FormatTestJS.cpp index 678fd1f3fc8d0e..4f41e4779f6ed2 100644 --- a/clang/unittests/Format/FormatTestJS.cpp +++ b/clang/unittests/Format/FormatTestJS.cpp @@ -2163,7 +2163,7 @@ TEST_F(FormatTestJS, TemplateStringMultiLineExpression) { "FOOFOOFOOFOOFOO_FOO_FO_FOO_FOOO -\n" "(barbarbarbarbar_bar_bar_bar_bar_bar +\n" " bar_bar_bar_barbarbar___bar_bar_bar + 1),\n" - ")}`;\n"); + ")}`;"); } TEST_F(FormatTestJS, TemplateStringASI) { ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 8c681a9 - [clang-format][NFC] Add a TypeScript test case
Author: Owen Pan Date: 2024-12-14T19:42:43-08:00 New Revision: 8c681a929b8684f5a4ad2ebd4e3e4f20036a9595 URL: https://github.com/llvm/llvm-project/commit/8c681a929b8684f5a4ad2ebd4e3e4f20036a9595 DIFF: https://github.com/llvm/llvm-project/commit/8c681a929b8684f5a4ad2ebd4e3e4f20036a9595.diff LOG: [clang-format][NFC] Add a TypeScript test case See #108530. Added: Modified: clang/unittests/Format/FormatTestJS.cpp Removed: diff --git a/clang/unittests/Format/FormatTestJS.cpp b/clang/unittests/Format/FormatTestJS.cpp index 4b15e7b7da3393..663b00ca7af628 100644 --- a/clang/unittests/Format/FormatTestJS.cpp +++ b/clang/unittests/Format/FormatTestJS.cpp @@ -1753,6 +1753,10 @@ TEST_F(FormatTestJS, ClassDeclarations) { " x: {y: Z;} = {};\n" " private y: {y: Z;} = {};\n" "}"); + verifyFormat("class Foo {\n" + " private addGrammarCheckOneboxProductInfo(\n" + " productInfo: {[key: string]: string;}) {}\n" + "}"); // ':' is not a type declaration here. verifyFormat("class X {\n" ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][WebAssembly] Support the `-m(no-)red-zone` flag. (PR #119997)
https://github.com/alexrp created https://github.com/llvm/llvm-project/pull/119997 LLVM's WebAssembly backend supports the `noredzone` function attribute, but this support was not exposed in Clang. Note: I don't have commit access. From 28834f7a42511905d8c1e00cb16ea7cdc70bf0c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Sun, 15 Dec 2024 06:15:24 +0100 Subject: [PATCH] [clang][WebAssembly] Support the -m(no-)red-zone flag. LLVM's WebAssembly backend supports the noredzone function attribute, but this support was not exposed in Clang. --- clang/lib/Driver/ToolChains/Clang.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 7ef55a33547c50..21117cd71b651e 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -2404,6 +2404,9 @@ void Clang::AddWebAssemblyTargetArgs(const ArgList &Args, if (!Args.hasArg(options::OPT_fvisibility_EQ, options::OPT_fvisibility_ms_compat)) CmdArgs.push_back("-fvisibility=hidden"); + + if (!Args.hasFlag(options::OPT_mred_zone, options::OPT_mno_red_zone, true)) +CmdArgs.push_back("-disable-red-zone"); } void Clang::AddVETargetArgs(const ArgList &Args, ArgStringList &CmdArgs) const { ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][WebAssembly] Support the `-m(no-)red-zone` flag. (PR #119997)
llvmbot wrote: @llvm/pr-subscribers-clang-driver Author: Alex Rønne Petersen (alexrp) Changes LLVM's WebAssembly backend supports the `noredzone` function attribute, but this support was not exposed in Clang. Note: I don't have commit access. --- Full diff: https://github.com/llvm/llvm-project/pull/119997.diff 1 Files Affected: - (modified) clang/lib/Driver/ToolChains/Clang.cpp (+3) ``diff diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp index 7ef55a33547c50..21117cd71b651e 100644 --- a/clang/lib/Driver/ToolChains/Clang.cpp +++ b/clang/lib/Driver/ToolChains/Clang.cpp @@ -2404,6 +2404,9 @@ void Clang::AddWebAssemblyTargetArgs(const ArgList &Args, if (!Args.hasArg(options::OPT_fvisibility_EQ, options::OPT_fvisibility_ms_compat)) CmdArgs.push_back("-fvisibility=hidden"); + + if (!Args.hasFlag(options::OPT_mred_zone, options::OPT_mno_red_zone, true)) +CmdArgs.push_back("-disable-red-zone"); } void Clang::AddVETargetArgs(const ArgList &Args, ArgStringList &CmdArgs) const { `` https://github.com/llvm/llvm-project/pull/119997 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] Index reserved symbols from `*intrin.h` system headers (PR #119735)
https://github.com/HighCommander4 approved this pull request. LGTM (I made a small tweak to the test name) https://github.com/llvm/llvm-project/pull/119735 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] Index reserved symbols from `*intrin.h` system headers (PR #119735)
HighCommander4 wrote: Hmm, the test is failing for me locally. Is it passing for you? (I'm not quite sure from the Buildkite logs whether it ran this test or not.) https://github.com/llvm/llvm-project/pull/119735 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clangd] Index reserved symbols from `*intrin.h` system headers (PR #119735)
https://github.com/HighCommander4 updated https://github.com/llvm/llvm-project/pull/119735 >From 04757e7d94ce5db11bb397accb0b1c0523d351ba Mon Sep 17 00:00:00 2001 From: Joseph Huber Date: Thu, 12 Dec 2024 12:15:32 -0600 Subject: [PATCH 1/3] [clangd] Index reserved symbols from `*intrin.h` system headers Summary: `clangd` intentionally suppresses indexing symbols from system headers as these are likely implementation details the user does not want. Howver, there are plenty of system headers that provide extensions that we want to index, such as vector intrinsic headers. This patch adds an extra check for these commonly-named '*intrin.h' headers. This is not fully inclusive for all symbols the user might want, but it's a good start. Fixes: https://github.com/llvm/llvm-project/issues/118684 --- clang-tools-extra/clangd/index/SymbolCollector.cpp | 7 ++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/clang-tools-extra/clangd/index/SymbolCollector.cpp b/clang-tools-extra/clangd/index/SymbolCollector.cpp index 81125dbb1aeafc..6d0af20e31260c 100644 --- a/clang-tools-extra/clangd/index/SymbolCollector.cpp +++ b/clang-tools-extra/clangd/index/SymbolCollector.cpp @@ -550,9 +550,14 @@ bool SymbolCollector::shouldCollectSymbol(const NamedDecl &ND, // Avoid indexing internal symbols in protobuf generated headers. if (isPrivateProtoDecl(ND)) return false; + + // System headers that end with `intrin.h` likely contain useful symbols. if (!Opts.CollectReserved && (hasReservedName(ND) || hasReservedScope(*ND.getDeclContext())) && - ASTCtx.getSourceManager().isInSystemHeader(ND.getLocation())) + ASTCtx.getSourceManager().isInSystemHeader(ND.getLocation()) && + !ASTCtx.getSourceManager() + .getFilename(ND.getLocation()) + .ends_with("intrin.h")) return false; return true; >From d320cbbf576fce53f6e3df477c705dd0bf645fca Mon Sep 17 00:00:00 2001 From: Joseph Huber Date: Fri, 13 Dec 2024 07:19:23 -0600 Subject: [PATCH 2/3] test --- .../clangd/unittests/SymbolCollectorTests.cpp | 14 ++ 1 file changed, 14 insertions(+) diff --git a/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp b/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp index e8088cb37fa51c..edc4e8aabe9a91 100644 --- a/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp +++ b/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp @@ -2111,6 +2111,20 @@ TEST_F(SymbolCollectorTest, Reserved) { EXPECT_THAT(Symbols, IsEmpty()); } +TEST_F(SymbolCollectorTest, UnreservedIntrin) { + const char *Header = R"cpp( +#pragma once +void __foo(); + )cpp"; + + TestHeaderName = "xintrin.h"; + TestHeaderURI = URI::create(testPath(TestHeaderName)).toString(); + InMemoryFileSystem = new llvm::vfs::InMemoryFileSystem; + CollectorOpts.FallbackDir = testRoot(); + runSymbolCollector("#pragma GCC system_header\n" + std::string(Header), ""); + EXPECT_THAT(Symbols, UnorderedElementsAre(qName("__foo"))); +} + TEST_F(SymbolCollectorTest, Concepts) { const char *Header = R"cpp( template >From f029a6216559f61f6e86ba62e9dff0e7b6c72c6b Mon Sep 17 00:00:00 2001 From: Nathan Ridge Date: Sun, 15 Dec 2024 02:51:19 -0500 Subject: [PATCH 3/3] tweak test name --- clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp b/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp index edc4e8aabe9a91..7a9703c744e93f 100644 --- a/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp +++ b/clang-tools-extra/clangd/unittests/SymbolCollectorTests.cpp @@ -2111,7 +2111,7 @@ TEST_F(SymbolCollectorTest, Reserved) { EXPECT_THAT(Symbols, IsEmpty()); } -TEST_F(SymbolCollectorTest, UnreservedIntrin) { +TEST_F(SymbolCollectorTest, ReservedSymbolInIntrinsicHeader) { const char *Header = R"cpp( #pragma once void __foo(); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [libunwind] Fix compilation for the x32 ABI. (PR #116608)
https://github.com/alexrp updated https://github.com/llvm/llvm-project/pull/116608 From 3a35fd5823545560041b4e091519895b7f7c89bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Mon, 18 Nov 2024 13:12:30 +0100 Subject: [PATCH] [libunwind] Fix compilation for the x32 ABI. This would previously fail the static assertions in UnwindCursor.hpp due to UnwindCursor's size not matching unw_cursor_t's size. As is done for MIPS N32, this just declares the appropriate size in __libunwind_config.h. --- libunwind/include/__libunwind_config.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libunwind/include/__libunwind_config.h b/libunwind/include/__libunwind_config.h index 028b9e3baa8065..bb7fe4c83a3c17 100644 --- a/libunwind/include/__libunwind_config.h +++ b/libunwind/include/__libunwind_config.h @@ -53,6 +53,9 @@ #else # define _LIBUNWIND_CURSOR_SIZE 66 #endif +# elif defined(__ILP32__) +#define _LIBUNWIND_CONTEXT_SIZE 21 +#define _LIBUNWIND_CURSOR_SIZE 28 # else #define _LIBUNWIND_CONTEXT_SIZE 21 #define _LIBUNWIND_CURSOR_SIZE 33 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[libunwind] [libunwind] Fix compilation for the x32 ABI. (PR #116608)
https://github.com/alexrp updated https://github.com/llvm/llvm-project/pull/116608 From 9955135c2027d268b9260adabaaf021848f91059 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Mon, 18 Nov 2024 13:12:30 +0100 Subject: [PATCH] [libunwind] Fix compilation for the x32 ABI. This would previously fail the static assertions in UnwindCursor.hpp due to UnwindCursor's size not matching unw_cursor_t's size. As is done for MIPS N32, this just declares the appropriate size in __libunwind_config.h. --- libunwind/include/__libunwind_config.h | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libunwind/include/__libunwind_config.h b/libunwind/include/__libunwind_config.h index 028b9e3baa8065..bb7fe4c83a3c17 100644 --- a/libunwind/include/__libunwind_config.h +++ b/libunwind/include/__libunwind_config.h @@ -53,6 +53,9 @@ #else # define _LIBUNWIND_CURSOR_SIZE 66 #endif +# elif defined(__ILP32__) +#define _LIBUNWIND_CONTEXT_SIZE 21 +#define _LIBUNWIND_CURSOR_SIZE 28 # else #define _LIBUNWIND_CONTEXT_SIZE 21 #define _LIBUNWIND_CURSOR_SIZE 33 ___ 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 readability-use-span-first-last check (PR #118074)
@@ -0,0 +1,104 @@ +//===--- UseSpanFirstLastCheck.cpp - clang-tidy -*- 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 "UseSpanFirstLastCheck.h" +#include "../utils/ASTUtils.h" +#include "../utils/Matchers.h" +#include "clang/AST/ASTContext.h" +#include "clang/AST/RecursiveASTVisitor.h" +#include "clang/ASTMatchers/ASTMatchFinder.h" +#include "clang/ASTMatchers/ASTMatchers.h" +#include "clang/Lex/Lexer.h" + +using namespace clang::ast_matchers; +using namespace clang::tidy::matchers; + +namespace clang::tidy::readability { + +void UseSpanFirstLastCheck::registerMatchers(MatchFinder *Finder) { + const auto HasSpanType = + hasType(hasUnqualifiedDesugaredType(recordType(hasDeclaration( + classTemplateSpecializationDecl(hasName("::std::span")); + + // Match span.subspan(0, n) -> first(n) + Finder->addMatcher( + cxxMemberCallExpr( + callee(memberExpr(hasDeclaration(cxxMethodDecl(hasName("subspan"), + on(expr(HasSpanType).bind("span_object")), + hasArgument(0, integerLiteral(equals(0))), + hasArgument(1, expr().bind("count")), argumentCountIs(2)) + .bind("first_subspan"), + this); + + // Match span.subspan(span.size() - n) or span.subspan(std::ranges::size(span) + // - n) + // -> last(n) + const auto SizeCall = anyOf( + cxxMemberCallExpr( + callee(memberExpr(hasDeclaration(cxxMethodDecl(hasName("size"), + on(expr(isStatementIdenticalToBoundNode("span_object", + callExpr(callee(functionDecl( + hasAnyName("::std::size", "::std::ranges::size"))), + hasArgument( + 0, expr(isStatementIdenticalToBoundNode("span_object"); + + Finder->addMatcher( + cxxMemberCallExpr( + callee(memberExpr(hasDeclaration(cxxMethodDecl(hasName("subspan"), + on(expr(HasSpanType).bind("span_object")), + hasArgument(0, binaryOperator(hasOperatorName("-"), hasLHS(SizeCall), +hasRHS(expr().bind("count", + argumentCountIs(1)) + .bind("last_subspan"), + this); +} + +void UseSpanFirstLastCheck::check(const MatchFinder::MatchResult &Result) { + const auto *SpanObj = Result.Nodes.getNodeAs("span_object"); + if (!SpanObj) +return; + + StringRef SpanText = Lexer::getSourceText( + CharSourceRange::getTokenRange(SpanObj->getSourceRange()), + *Result.SourceManager, Result.Context->getLangOpts()); + + if (const auto *FirstCall = hjanuschka wrote: thank you - haven't thought of this, great idea and super improvement! https://github.com/llvm/llvm-project/pull/118074 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 1911919 - Revert "[Driver][OHOS] Fix lld link issue for OHOS (#118192)"
Author: Pavel Kosov Date: 2024-12-14T14:46:47+03:00 New Revision: 1911919682c863643787b30286bb67359c7932f4 URL: https://github.com/llvm/llvm-project/commit/1911919682c863643787b30286bb67359c7932f4 DIFF: https://github.com/llvm/llvm-project/commit/1911919682c863643787b30286bb67359c7932f4.diff LOG: Revert "[Driver][OHOS] Fix lld link issue for OHOS (#118192)" This reverts commit bc28be0a428020ea803c94adb4df48ee4972e9f1. Some issues were discovered with GN buildbot http://45.33.8.238/linux/155432/step_6.txt Need to investigate it Added: Modified: clang/lib/Driver/ToolChains/OHOS.cpp Removed: diff --git a/clang/lib/Driver/ToolChains/OHOS.cpp b/clang/lib/Driver/ToolChains/OHOS.cpp index c9a532771b99e5..6e1a09ae908b2f 100644 --- a/clang/lib/Driver/ToolChains/OHOS.cpp +++ b/clang/lib/Driver/ToolChains/OHOS.cpp @@ -19,8 +19,8 @@ #include "llvm/ProfileData/InstrProf.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/Path.h" -#include "llvm/Support/ScopedPrinter.h" #include "llvm/Support/VirtualFileSystem.h" +#include "llvm/Support/ScopedPrinter.h" using namespace clang::driver; using namespace clang::driver::toolchains; @@ -58,9 +58,11 @@ static bool findOHOSMuslMultilibs(const Driver &D, return false; } -static bool findOHOSMultilibs(const Driver &D, const ToolChain &TC, - const llvm::Triple &TargetTriple, StringRef Path, - const ArgList &Args, DetectedMultilibs &Result) { +static bool findOHOSMultilibs(const Driver &D, + const ToolChain &TC, + const llvm::Triple &TargetTriple, + StringRef Path, const ArgList &Args, + DetectedMultilibs &Result) { Multilib::flags_list Flags; bool IsA7 = false; if (const Arg *A = Args.getLastArg(options::OPT_mcpu_EQ)) @@ -170,7 +172,8 @@ OHOS::OHOS(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) Paths); } -ToolChain::RuntimeLibType OHOS::GetRuntimeLibType(const ArgList &Args) const { +ToolChain::RuntimeLibType OHOS::GetRuntimeLibType( +const ArgList &Args) const { if (Arg *A = Args.getLastArg(clang::driver::options::OPT_rtlib_EQ)) { StringRef Value = A->getValue(); if (Value != "compiler-rt") @@ -181,19 +184,20 @@ ToolChain::RuntimeLibType OHOS::GetRuntimeLibType(const ArgList &Args) const { return ToolChain::RLT_CompilerRT; } -ToolChain::CXXStdlibType OHOS::GetCXXStdlibType(const ArgList &Args) const { +ToolChain::CXXStdlibType +OHOS::GetCXXStdlibType(const ArgList &Args) const { if (Arg *A = Args.getLastArg(options::OPT_stdlib_EQ)) { StringRef Value = A->getValue(); if (Value != "libc++") getDriver().Diag(diag::err_drv_invalid_stdlib_name) - << A->getAsString(Args); +<< A->getAsString(Args); } return ToolChain::CST_Libcxx; } void OHOS::AddClangSystemIncludeArgs(const ArgList &DriverArgs, - ArgStringList &CC1Args) const { +ArgStringList &CC1Args) const { const Driver &D = getDriver(); const llvm::Triple &Triple = getTriple(); std::string SysRoot = computeSysRoot(); @@ -254,7 +258,7 @@ void OHOS::AddClangCXXStdlibIncludeArgs(const ArgList &DriverArgs, } void OHOS::AddCXXStdlibLibArgs(const ArgList &Args, - ArgStringList &CmdArgs) const { + ArgStringList &CmdArgs) const { switch (GetCXXStdlibType(Args)) { case ToolChain::CST_Libcxx: CmdArgs.push_back("-lc++"); @@ -287,8 +291,7 @@ ToolChain::path_list OHOS::getRuntimePaths() const { // First try the triple passed to driver as --target=. P.assign(D.ResourceDir); - llvm::sys::path::append(P, "lib", D.getTargetTriple(), - SelectedMultilib.gccSuffix()); + llvm::sys::path::append(P, "lib", D.getTargetTriple(), SelectedMultilib.gccSuffix()); Paths.push_back(P.c_str()); // Second try the normalized triple. @@ -337,20 +340,26 @@ std::string OHOS::getDynamicLinker(const ArgList &Args) const { std::string OHOS::getCompilerRT(const ArgList &Args, StringRef Component, FileType Type) const { - std::string CRTBasename = - buildCompilerRTBasename(Args, Component, Type, /*AddArch=*/false); - SmallString<128> Path(getDriver().ResourceDir); llvm::sys::path::append(Path, "lib", getMultiarchTriple(getTriple()), - SelectedMultilib.gccSuffix(), CRTBasename); - if (getVFS().exists(Path)) -return std::string(Path); - - std::string NewPath = ToolChain::getCompilerRT(Args, Component, Type); - if (getVFS().exists(NewPath)) -return NewPath; - - return std::string(Path); + SelectedMultilib.gccSuffix());
[clang] [libcxx] [Clang] Add __builtin_invoke (PR #116709)
https://github.com/philnik777 edited https://github.com/llvm/llvm-project/pull/116709 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [libcxx] [Clang] Add __builtin_invoke and use it in libc++ (PR #116709)
https://github.com/philnik777 edited https://github.com/llvm/llvm-project/pull/116709 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [libcxx] [Clang] Add __builtin_invoke and use it in libc++ (PR #116709)
https://github.com/philnik777 edited https://github.com/llvm/llvm-project/pull/116709 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][Sema] Track trivial-relocatability as a type trait (PR #84621)
QrczakMK wrote: It would be great to see progress in this. Lack of detection of trivially relocatable types costs extra memory allocations in my project, and I feel uneasy carving a manual exception for `std::unique_ptr`. https://github.com/llvm/llvm-project/pull/84621 ___ 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 readability-use-span-first-last check (PR #118074)
https://github.com/hjanuschka updated https://github.com/llvm/llvm-project/pull/118074 >From cb748c34d35b8c0c9ca93a67b111dcf5d7665b34 Mon Sep 17 00:00:00 2001 From: Helmut Januschka Date: Fri, 29 Nov 2024 10:17:49 +0100 Subject: [PATCH 01/31] [clang-tidy] Add modernize-use-span-first-last check Add new check that modernizes std::span::subspan() calls to use the more expressive first() and last() member functions where applicable. --- .../clang-tidy/modernize/CMakeLists.txt | 1 + .../modernize/ModernizeTidyModule.cpp | 3 + .../modernize/UseSpanFirstLastCheck.cpp | 97 +++ .../modernize/UseSpanFirstLastCheck.h | 40 clang-tools-extra/docs/ReleaseNotes.rst | 4 + .../checks/modernize/use-span-first-last.rst | 19 .../modernize-subspan-conversion.cpp | 50 ++ 7 files changed, 214 insertions(+) create mode 100644 clang-tools-extra/clang-tidy/modernize/UseSpanFirstLastCheck.cpp create mode 100644 clang-tools-extra/clang-tidy/modernize/UseSpanFirstLastCheck.h create mode 100644 clang-tools-extra/docs/clang-tidy/checks/modernize/use-span-first-last.rst create mode 100644 clang-tools-extra/test/clang-tidy/checkers/modernize/modernize-subspan-conversion.cpp diff --git a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt index c919d49b42873a..47dd12a2640b6c 100644 --- a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt +++ b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt @@ -49,6 +49,7 @@ add_clang_library(clangTidyModernizeModule STATIC UseTransparentFunctorsCheck.cpp UseUncaughtExceptionsCheck.cpp UseUsingCheck.cpp + UseSpanFirstLastCheck.cpp LINK_LIBS clangTidy diff --git a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp index 18607593320635..6fc5de5aad20b7 100644 --- a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp +++ b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp @@ -42,6 +42,7 @@ #include "UseNullptrCheck.h" #include "UseOverrideCheck.h" #include "UseRangesCheck.h" +#include "UseSpanFirstLastCheck.h" #include "UseStartsEndsWithCheck.h" #include "UseStdFormatCheck.h" #include "UseStdNumbersCheck.h" @@ -122,6 +123,8 @@ class ModernizeModule : public ClangTidyModule { CheckFactories.registerCheck( "modernize-use-uncaught-exceptions"); CheckFactories.registerCheck("modernize-use-using"); + CheckFactories.registerCheck("modernize-use-span-first-last"); + } }; diff --git a/clang-tools-extra/clang-tidy/modernize/UseSpanFirstLastCheck.cpp b/clang-tools-extra/clang-tidy/modernize/UseSpanFirstLastCheck.cpp new file mode 100644 index 00..f57571f2aa7c86 --- /dev/null +++ b/clang-tools-extra/clang-tidy/modernize/UseSpanFirstLastCheck.cpp @@ -0,0 +1,97 @@ +//===--- UseSpanFirstLastCheck.cpp - clang-tidy-*- 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 "UseSpanFirstLastCheck.h" +#include "clang/AST/ASTContext.h" +#include "clang/ASTMatchers/ASTMatchFinder.h" +#include "clang/ASTMatchers/ASTMatchers.h" +#include "clang/Lex/Lexer.h" + +using namespace clang::ast_matchers; + +namespace clang::tidy::modernize { + +void UseSpanFirstLastCheck::registerMatchers(MatchFinder *Finder) { + // Match span::subspan calls + const auto HasSpanType = hasType(hasUnqualifiedDesugaredType( + recordType(hasDeclaration(classTemplateSpecializationDecl( + hasName("::std::span")); + + Finder->addMatcher( + cxxMemberCallExpr( + callee(memberExpr(hasDeclaration( + cxxMethodDecl(hasName("subspan"), + on(expr(HasSpanType))) + .bind("subspan"), + this); +} + +void UseSpanFirstLastCheck::check(const MatchFinder::MatchResult &Result) { + const auto *Call = Result.Nodes.getNodeAs("subspan"); + if (!Call) +return; + + handleSubspanCall(Result, Call); +} + +void UseSpanFirstLastCheck::handleSubspanCall( +const MatchFinder::MatchResult &Result, const CXXMemberCallExpr *Call) { + // Get arguments + unsigned NumArgs = Call->getNumArgs(); + if (NumArgs == 0 || NumArgs > 2) +return; + + const Expr *Offset = Call->getArg(0); + const Expr *Count = NumArgs > 1 ? Call->getArg(1) : nullptr; + auto &Context = *Result.Context; + bool IsZeroOffset = false; + + // Check if offset is zero through any implicit casts + const Expr* OffsetE = Offset->IgnoreImpCasts(); + if (const auto *IL = dyn_cast(OffsetE)) { +IsZeroOffset = IL->getValue() == 0; + } + + // Build replacement text + std::string Replacement; + if (IsZeroOffset && Count) { +
[clang-tools-extra] [clang-tidy] Add readability-use-span-first-last check (PR #118074)
https://github.com/hjanuschka commented: ready for re-review https://github.com/llvm/llvm-project/pull/118074 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Fix lld link issue for OHOS (PR #118192)
kpdev wrote: @phuang @nico Reverted. I will reland it after investigating the issue with GN build bot https://github.com/llvm/llvm-project/pull/118192 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Thread safety analysis: Fix substitution for operator calls (PR #116487)
https://github.com/aaronpuchert closed https://github.com/llvm/llvm-project/pull/116487 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] performance-unnecessary-copy-initialization: Consider static functions (PR #119974)
llvmbot wrote: @llvm/pr-subscribers-clang-tools-extra Author: Barnabás Pőcze (pobrn) Changes Static member functions can be considered the same way as free functions are, so do that. --- 1. Not sure how many more tests I should add, since this uses the same code paths as free functions. 2. This is the 5th instance of the `isStatic` matcher in `clang-tidy`. --- Full diff: https://github.com/llvm/llvm-project/pull/119974.diff 2 Files Affected: - (modified) clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp (+5-1) - (modified) clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-copy-initialization.cpp (+24) ``diff diff --git a/clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp b/clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp index 034894c11bf2c0..778d1d00250315 100644 --- a/clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp +++ b/clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp @@ -104,6 +104,10 @@ AST_MATCHER_FUNCTION_P(StatementMatcher, hasArgument(0, hasType(ReceiverType); } +namespace { +AST_MATCHER(CXXMethodDecl, isStatic) { return Node.isStatic(); } +} // namespace + AST_MATCHER_FUNCTION(StatementMatcher, isConstRefReturningFunctionCall) { // Only allow initialization of a const reference from a free function if it // has no arguments. Otherwise it could return an alias to one of its @@ -111,7 +115,7 @@ AST_MATCHER_FUNCTION(StatementMatcher, isConstRefReturningFunctionCall) { return callExpr(callee(functionDecl(returns(hasCanonicalType( matchers::isReferenceToConst( .bind(FunctionDeclId)), - argumentCountIs(0), unless(callee(cxxMethodDecl( + argumentCountIs(0), unless(callee(cxxMethodDecl(unless(isStatic()) .bind(InitFunctionCallId); } diff --git a/clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-copy-initialization.cpp b/clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-copy-initialization.cpp index d02bb98cf583cb..b5325776f54c61 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-copy-initialization.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-copy-initialization.cpp @@ -28,6 +28,8 @@ struct ExpensiveToCopyType { template const A &templatedAccessor() const; operator int() const; // Implicit conversion to int. + + static const ExpensiveToCopyType &instance(); }; template @@ -100,6 +102,28 @@ void PositiveFunctionCall() { VarCopyConstructed.constMethod(); } +void PositiveStaticMethodCall() { + const auto AutoAssigned = ExpensiveToCopyType::instance(); + // CHECK-MESSAGES: [[@LINE-1]]:14: warning: the const qualified variable 'AutoAssigned' is copy-constructed from a const reference; consider making it a const reference [performance-unnecessary-copy-initialization] + // CHECK-FIXES: const auto& AutoAssigned = ExpensiveToCopyType::instance(); + AutoAssigned.constMethod(); + + const auto AutoCopyConstructed(ExpensiveToCopyType::instance()); + // CHECK-MESSAGES: [[@LINE-1]]:14: warning: the const qualified variable 'AutoCopyConstructed' + // CHECK-FIXES: const auto& AutoCopyConstructed(ExpensiveToCopyType::instance()); + AutoCopyConstructed.constMethod(); + + const ExpensiveToCopyType VarAssigned = ExpensiveToCopyType::instance(); + // CHECK-MESSAGES: [[@LINE-1]]:29: warning: the const qualified variable 'VarAssigned' + // CHECK-FIXES: const ExpensiveToCopyType& VarAssigned = ExpensiveToCopyType::instance(); + VarAssigned.constMethod(); + + const ExpensiveToCopyType VarCopyConstructed(ExpensiveToCopyType::instance()); + // CHECK-MESSAGES: [[@LINE-1]]:29: warning: the const qualified variable 'VarCopyConstructed' + // CHECK-FIXES: const ExpensiveToCopyType& VarCopyConstructed(ExpensiveToCopyType::instance()); + VarCopyConstructed.constMethod(); +} + void PositiveMethodCallConstReferenceParam(const ExpensiveToCopyType &Obj) { const auto AutoAssigned = Obj.reference(); // CHECK-MESSAGES: [[@LINE-1]]:14: warning: the const qualified variable 'AutoAssigned' `` https://github.com/llvm/llvm-project/pull/119974 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] performance-unnecessary-copy-initialization: Consider static functions (PR #119974)
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/119974 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] performance-unnecessary-copy-initialization: Consider static functions (PR #119974)
https://github.com/pobrn created https://github.com/llvm/llvm-project/pull/119974 Static member functions can be considered the same way as free functions are, so do that. --- 1. Not sure how many more tests I should add, since this uses the same code paths as free functions. 2. This is the 5th instance of the `isStatic` matcher in `clang-tidy`. From 6a160c92bd1210e1ec340d2d14650cc0c9d91459 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A1s=20P=C5=91cze?= Date: Sat, 14 Dec 2024 16:57:57 +0100 Subject: [PATCH] [clang-tidy] performance-unnecessary-copy-initialization: Consider static functions Static member functions can be considered the same way as free functions are, so do that. --- .../UnnecessaryCopyInitialization.cpp | 6 - .../unnecessary-copy-initialization.cpp | 24 +++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp b/clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp index 034894c11bf2c0..778d1d00250315 100644 --- a/clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp +++ b/clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp @@ -104,6 +104,10 @@ AST_MATCHER_FUNCTION_P(StatementMatcher, hasArgument(0, hasType(ReceiverType); } +namespace { +AST_MATCHER(CXXMethodDecl, isStatic) { return Node.isStatic(); } +} // namespace + AST_MATCHER_FUNCTION(StatementMatcher, isConstRefReturningFunctionCall) { // Only allow initialization of a const reference from a free function if it // has no arguments. Otherwise it could return an alias to one of its @@ -111,7 +115,7 @@ AST_MATCHER_FUNCTION(StatementMatcher, isConstRefReturningFunctionCall) { return callExpr(callee(functionDecl(returns(hasCanonicalType( matchers::isReferenceToConst( .bind(FunctionDeclId)), - argumentCountIs(0), unless(callee(cxxMethodDecl( + argumentCountIs(0), unless(callee(cxxMethodDecl(unless(isStatic()) .bind(InitFunctionCallId); } diff --git a/clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-copy-initialization.cpp b/clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-copy-initialization.cpp index d02bb98cf583cb..b5325776f54c61 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-copy-initialization.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-copy-initialization.cpp @@ -28,6 +28,8 @@ struct ExpensiveToCopyType { template const A &templatedAccessor() const; operator int() const; // Implicit conversion to int. + + static const ExpensiveToCopyType &instance(); }; template @@ -100,6 +102,28 @@ void PositiveFunctionCall() { VarCopyConstructed.constMethod(); } +void PositiveStaticMethodCall() { + const auto AutoAssigned = ExpensiveToCopyType::instance(); + // CHECK-MESSAGES: [[@LINE-1]]:14: warning: the const qualified variable 'AutoAssigned' is copy-constructed from a const reference; consider making it a const reference [performance-unnecessary-copy-initialization] + // CHECK-FIXES: const auto& AutoAssigned = ExpensiveToCopyType::instance(); + AutoAssigned.constMethod(); + + const auto AutoCopyConstructed(ExpensiveToCopyType::instance()); + // CHECK-MESSAGES: [[@LINE-1]]:14: warning: the const qualified variable 'AutoCopyConstructed' + // CHECK-FIXES: const auto& AutoCopyConstructed(ExpensiveToCopyType::instance()); + AutoCopyConstructed.constMethod(); + + const ExpensiveToCopyType VarAssigned = ExpensiveToCopyType::instance(); + // CHECK-MESSAGES: [[@LINE-1]]:29: warning: the const qualified variable 'VarAssigned' + // CHECK-FIXES: const ExpensiveToCopyType& VarAssigned = ExpensiveToCopyType::instance(); + VarAssigned.constMethod(); + + const ExpensiveToCopyType VarCopyConstructed(ExpensiveToCopyType::instance()); + // CHECK-MESSAGES: [[@LINE-1]]:29: warning: the const qualified variable 'VarCopyConstructed' + // CHECK-FIXES: const ExpensiveToCopyType& VarCopyConstructed(ExpensiveToCopyType::instance()); + VarCopyConstructed.constMethod(); +} + void PositiveMethodCallConstReferenceParam(const ExpensiveToCopyType &Obj) { const auto AutoAssigned = Obj.reference(); // CHECK-MESSAGES: [[@LINE-1]]:14: warning: the const qualified variable 'AutoAssigned' ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] a999ab4 - Thread safety analysis: Fix substitution for operator calls (#116487)
Author: Aaron Puchert Date: 2024-12-14T16:54:43+01:00 New Revision: a999ab44be8994d39d2469c1b4d025c4e1131197 URL: https://github.com/llvm/llvm-project/commit/a999ab44be8994d39d2469c1b4d025c4e1131197 DIFF: https://github.com/llvm/llvm-project/commit/a999ab44be8994d39d2469c1b4d025c4e1131197.diff LOG: Thread safety analysis: Fix substitution for operator calls (#116487) For operator calls that go to methods we need to substitute the first parameter for "this" and the following parameters into the function parameters, instead of substituting all of them into the parameters. This revealed an issue about lambdas. An existing test accidentally worked because the substitution bug was covered by a speciality of lambdas: a CXXThisExpr in a lambda CXXMethodDecl does not refer to the implicit this argument of the method, but to a captured "this" from the context the lambda was created in. This can happen for operator calls, where it worked due to the substitution bug (we treated the implicit this argument incorrectly as parameter), and for regular calls (i.e. obj.operator()(args) instead of obj(args)), where it didn't work. The correct fix seems to be to clear the self-argument on a lambda call. Lambdas can only capture "this" inside methods, and calls to the lambda in that scope cannot substitute anything for "this". Added: Modified: clang/lib/Analysis/ThreadSafetyCommon.cpp clang/test/SemaCXX/warn-thread-safety-analysis.cpp Removed: diff --git a/clang/lib/Analysis/ThreadSafetyCommon.cpp b/clang/lib/Analysis/ThreadSafetyCommon.cpp index 211e940ce8b861..050daee1168d4b 100644 --- a/clang/lib/Analysis/ThreadSafetyCommon.cpp +++ b/clang/lib/Analysis/ThreadSafetyCommon.cpp @@ -135,14 +135,30 @@ CapabilityExpr SExprBuilder::translateAttrExpr(const Expr *AttrExp, Ctx.NumArgs = CE->getNumArgs(); Ctx.FunArgs = CE->getArgs(); } else if (const auto *CE = dyn_cast(DeclExp)) { -Ctx.NumArgs = CE->getNumArgs(); -Ctx.FunArgs = CE->getArgs(); +// Calls to operators that are members need to be treated like member calls. +if (isa(CE) && isa(D)) { + Ctx.SelfArg = CE->getArg(0); + Ctx.SelfArrow = false; + Ctx.NumArgs = CE->getNumArgs() - 1; + Ctx.FunArgs = CE->getArgs() + 1; +} else { + Ctx.NumArgs = CE->getNumArgs(); + Ctx.FunArgs = CE->getArgs(); +} } else if (const auto *CE = dyn_cast(DeclExp)) { Ctx.SelfArg = nullptr; // Will be set below Ctx.NumArgs = CE->getNumArgs(); Ctx.FunArgs = CE->getArgs(); } + // Usually we want to substitute the self-argument for "this", but lambdas + // are an exception: "this" on or in a lambda call operator doesn't refer + // to the lambda, but to captured "this" in the context it was created in. + // This can happen for operator calls and member calls, so fix it up here. + if (const auto *CMD = dyn_cast(D)) +if (CMD->getParent()->isLambda()) + Ctx.SelfArg = nullptr; + if (Self) { assert(!Ctx.SelfArg && "Ambiguous self argument"); assert(isa(D) && "Self argument requires function"); diff --git a/clang/test/SemaCXX/warn-thread-safety-analysis.cpp b/clang/test/SemaCXX/warn-thread-safety-analysis.cpp index 8477200456d985..3c52c8165d8529 100644 --- a/clang/test/SemaCXX/warn-thread-safety-analysis.cpp +++ b/clang/test/SemaCXX/warn-thread-safety-analysis.cpp @@ -1593,8 +1593,12 @@ namespace substitution_test { void unlockData() UNLOCK_FUNCTION(mu); void doSomething() EXCLUSIVE_LOCKS_REQUIRED(mu) { } +void operator()() EXCLUSIVE_LOCKS_REQUIRED(mu) { } + +MyData operator+(const MyData& other) const SHARED_LOCKS_REQUIRED(mu, other.mu); }; + MyData operator-(const MyData& a, const MyData& b) SHARED_LOCKS_REQUIRED(a.mu, b.mu); class DataLocker { public: @@ -1607,6 +1611,27 @@ namespace substitution_test { public: void foo(MyData* d) EXCLUSIVE_LOCKS_REQUIRED(d->mu) { } +void subst(MyData& d) { + d.doSomething(); // expected-warning {{calling function 'doSomething' requires holding mutex 'd.mu' exclusively}} + d(); // expected-warning {{calling function 'operator()' requires holding mutex 'd.mu' exclusively}} + d.operator()(); // expected-warning {{calling function 'operator()' requires holding mutex 'd.mu' exclusively}} + + d.lockData(); + d.doSomething(); + d(); + d.operator()(); + d.unlockData(); +} + +void binop(MyData& a, MyData& b) EXCLUSIVE_LOCKS_REQUIRED(a.mu) { + a + b; // expected-warning {{calling function 'operator+' requires holding mutex 'b.mu'}} + // expected-note@-1 {{found near match 'a.mu'}} + b + a; // expected-warning {{calling function 'operator+' requires holding mutex 'b.mu'}} + // expected-note@-1 {{found near match 'a.mu'}} + a - b; // expected-warning {{calling function 'operator-' requires hold
[clang-tools-extra] [clang-tidy] performance-unnecessary-copy-initialization: Consider static functions (PR #119974)
https://github.com/pobrn updated https://github.com/llvm/llvm-project/pull/119974 From 2d72c484291862fd8c9d8cea1a3ebadbe37343be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Barnab=C3=A1s=20P=C5=91cze?= Date: Sat, 14 Dec 2024 16:57:57 +0100 Subject: [PATCH] [clang-tidy] performance-unnecessary-copy-initialization: Consider static functions Static member functions can be considered the same way as free functions are, so do that. --- .../UnnecessaryCopyInitialization.cpp | 6 +++-- .../unnecessary-copy-initialization.cpp | 24 +++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp b/clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp index 034894c11bf2c0..f63be0d33bf0a8 100644 --- a/clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp +++ b/clang-tools-extra/clang-tidy/performance/UnnecessaryCopyInitialization.cpp @@ -104,6 +104,8 @@ AST_MATCHER_FUNCTION_P(StatementMatcher, hasArgument(0, hasType(ReceiverType); } +AST_MATCHER(CXXMethodDecl, isStatic) { return Node.isStatic(); } + AST_MATCHER_FUNCTION(StatementMatcher, isConstRefReturningFunctionCall) { // Only allow initialization of a const reference from a free function if it // has no arguments. Otherwise it could return an alias to one of its @@ -111,7 +113,7 @@ AST_MATCHER_FUNCTION(StatementMatcher, isConstRefReturningFunctionCall) { return callExpr(callee(functionDecl(returns(hasCanonicalType( matchers::isReferenceToConst( .bind(FunctionDeclId)), - argumentCountIs(0), unless(callee(cxxMethodDecl( + argumentCountIs(0), unless(callee(cxxMethodDecl(unless(isStatic()) .bind(InitFunctionCallId); } @@ -232,7 +234,7 @@ UnnecessaryCopyInitialization::UnnecessaryCopyInitialization( Options.get("ExcludedContainerTypes", ""))) {} void UnnecessaryCopyInitialization::registerMatchers(MatchFinder *Finder) { - auto LocalVarCopiedFrom = [this](const internal::Matcher &CopyCtorArg) { + auto LocalVarCopiedFrom = [this](const ast_matchers::internal::Matcher &CopyCtorArg) { return compoundStmt( forEachDescendant( declStmt( diff --git a/clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-copy-initialization.cpp b/clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-copy-initialization.cpp index d02bb98cf583cb..b5325776f54c61 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-copy-initialization.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/performance/unnecessary-copy-initialization.cpp @@ -28,6 +28,8 @@ struct ExpensiveToCopyType { template const A &templatedAccessor() const; operator int() const; // Implicit conversion to int. + + static const ExpensiveToCopyType &instance(); }; template @@ -100,6 +102,28 @@ void PositiveFunctionCall() { VarCopyConstructed.constMethod(); } +void PositiveStaticMethodCall() { + const auto AutoAssigned = ExpensiveToCopyType::instance(); + // CHECK-MESSAGES: [[@LINE-1]]:14: warning: the const qualified variable 'AutoAssigned' is copy-constructed from a const reference; consider making it a const reference [performance-unnecessary-copy-initialization] + // CHECK-FIXES: const auto& AutoAssigned = ExpensiveToCopyType::instance(); + AutoAssigned.constMethod(); + + const auto AutoCopyConstructed(ExpensiveToCopyType::instance()); + // CHECK-MESSAGES: [[@LINE-1]]:14: warning: the const qualified variable 'AutoCopyConstructed' + // CHECK-FIXES: const auto& AutoCopyConstructed(ExpensiveToCopyType::instance()); + AutoCopyConstructed.constMethod(); + + const ExpensiveToCopyType VarAssigned = ExpensiveToCopyType::instance(); + // CHECK-MESSAGES: [[@LINE-1]]:29: warning: the const qualified variable 'VarAssigned' + // CHECK-FIXES: const ExpensiveToCopyType& VarAssigned = ExpensiveToCopyType::instance(); + VarAssigned.constMethod(); + + const ExpensiveToCopyType VarCopyConstructed(ExpensiveToCopyType::instance()); + // CHECK-MESSAGES: [[@LINE-1]]:29: warning: the const qualified variable 'VarCopyConstructed' + // CHECK-FIXES: const ExpensiveToCopyType& VarCopyConstructed(ExpensiveToCopyType::instance()); + VarCopyConstructed.constMethod(); +} + void PositiveMethodCallConstReferenceParam(const ExpensiveToCopyType &Obj) { const auto AutoAssigned = Obj.reference(); // CHECK-MESSAGES: [[@LINE-1]]:14: warning: the const qualified variable 'AutoAssigned' ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [AST] Migrate away from PointerUnion::get (NFC) (PR #119949)
https://github.com/kazutakahirata closed https://github.com/llvm/llvm-project/pull/119949 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] c35108e - [AST] Migrate away from PointerUnion::get (NFC) (#119949)
Author: Kazu Hirata Date: 2024-12-14T09:17:56-08:00 New Revision: c35108e24488af1db1914ec083439189e6a7fce6 URL: https://github.com/llvm/llvm-project/commit/c35108e24488af1db1914ec083439189e6a7fce6 DIFF: https://github.com/llvm/llvm-project/commit/c35108e24488af1db1914ec083439189e6a7fce6.diff LOG: [AST] Migrate away from PointerUnion::get (NFC) (#119949) Note that PointerUnion::get has been soft deprecated in PointerUnion.h: // FIXME: Replace the uses of is(), get() and dyn_cast() with //isa, cast and the llvm::dyn_cast Added: Modified: clang/unittests/AST/ASTImporterTest.cpp Removed: diff --git a/clang/unittests/AST/ASTImporterTest.cpp b/clang/unittests/AST/ASTImporterTest.cpp index abf07d094e62c3..f3f314b723dfc6 100644 --- a/clang/unittests/AST/ASTImporterTest.cpp +++ b/clang/unittests/AST/ASTImporterTest.cpp @@ -9657,7 +9657,7 @@ TEST_P(ASTImporterOptionSpecificTestBase, ImportConflictTypeAliasTemplate) { AST_MATCHER(ClassTemplateSpecializationDecl, hasInstantiatedFromMember) { if (auto Instantiate = Node.getInstantiatedFrom()) { if (auto *FromPartialSpecialization = -Instantiate.get()) { +cast(Instantiate)) { return nullptr != FromPartialSpecialization->getInstantiatedFromMember(); } } ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang-REPL] Fix crash during `__run_exit_handlers` with dynamic libraries. (PR #117475)
yuxuanchen1997 wrote: > @SahilPatidar, could you help us with this? Can we temporarily disable this test when @SahilPatidar is looking for a solution? https://github.com/llvm/llvm-project/pull/117475 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Temporarily disable test `clang/Interpreter/crash.cpp` (PR #119978)
https://github.com/yuxuanchen1997 created https://github.com/llvm/llvm-project/pull/119978 See discussion on https://github.com/llvm/llvm-project/pull/117475#issuecomment-2543223954 This test currently invokes the system ld, which can cause issues on some CI systems where system ld only works with $LDFLAGS and $LIBS. @vgvassilev has suggested to use the `yaml2obj` tool to avoid invoking ld. Before that happens, proposing to disable this test until we find a solution to unblock downstream CI. >From 35886284dc739f9849804fbde849fc0e912d5a4d Mon Sep 17 00:00:00 2001 From: Yuxuan Chen Date: Sat, 14 Dec 2024 10:12:57 -0800 Subject: [PATCH] temporarily disable the test --- clang/test/Interpreter/crash.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/clang/test/Interpreter/crash.cpp b/clang/test/Interpreter/crash.cpp index 9a606983524d82..11ff938aedd5d5 100644 --- a/clang/test/Interpreter/crash.cpp +++ b/clang/test/Interpreter/crash.cpp @@ -1,4 +1,5 @@ // REQUIRES: host-supports-jit, x86_64-linux +// UNSUPPORTED: target={{.*}} // RUN: rm -rf %t // RUN: mkdir -p %t ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Temporarily disable test `clang/Interpreter/crash.cpp` (PR #119978)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Yuxuan Chen (yuxuanchen1997) Changes See discussion on https://github.com/llvm/llvm-project/pull/117475#issuecomment-2543223954 This test currently invokes the system ld, which can cause issues on some CI systems where system ld only works with $LDFLAGS and $LIBS. @vgvassilev has suggested to use the `yaml2obj` tool to avoid invoking ld. Before that happens, proposing to disable this test until we find a solution to unblock downstream CI. --- Full diff: https://github.com/llvm/llvm-project/pull/119978.diff 1 Files Affected: - (modified) clang/test/Interpreter/crash.cpp (+1) ``diff diff --git a/clang/test/Interpreter/crash.cpp b/clang/test/Interpreter/crash.cpp index 9a606983524d82..11ff938aedd5d5 100644 --- a/clang/test/Interpreter/crash.cpp +++ b/clang/test/Interpreter/crash.cpp @@ -1,4 +1,5 @@ // REQUIRES: host-supports-jit, x86_64-linux +// UNSUPPORTED: target={{.*}} // RUN: rm -rf %t // RUN: mkdir -p %t `` https://github.com/llvm/llvm-project/pull/119978 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 9ddcaed - Revert "[Clang] Interpreter test should not depend on system header (#119903)"
Author: Davide Italiano Date: 2024-12-14T18:25:02Z New Revision: 9ddcaed3a64c2a187a0cfff4ba8f989c665ae1e5 URL: https://github.com/llvm/llvm-project/commit/9ddcaed3a64c2a187a0cfff4ba8f989c665ae1e5 DIFF: https://github.com/llvm/llvm-project/commit/9ddcaed3a64c2a187a0cfff4ba8f989c665ae1e5.diff LOG: Revert "[Clang] Interpreter test should not depend on system header (#119903)" This reverts commit 8ab6912831277d87838518c5f775f79d14616860. Added: Modified: clang/test/Interpreter/crash.cpp Removed: clang/test/Interpreter/Inputs/vector diff --git a/clang/test/Interpreter/Inputs/vector b/clang/test/Interpreter/Inputs/vector deleted file mode 100644 index 4fc5d04f4718c7..00 --- a/clang/test/Interpreter/Inputs/vector +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef VECTOR -#define VECTOR -namespace std { -template -class vector { -public: - vector(); -}; -} // namespace std -#endif // VECTOR diff --git a/clang/test/Interpreter/crash.cpp b/clang/test/Interpreter/crash.cpp index 9a606983524d82..1ab24b0febfa15 100644 --- a/clang/test/Interpreter/crash.cpp +++ b/clang/test/Interpreter/crash.cpp @@ -5,7 +5,7 @@ // // RUN: split-file %s %t // -// RUN: %clang++ -Xclang -nostdsysteminc -I%S/Inputs/ -std=c++20 -fPIC -c %t/vec.cpp -o %t/vec.o +// RUN: %clang++ -std=c++20 -fPIC -c %t/vec.cpp -o %t/vec.o // RUN: %clang++ -shared %t/vec.o -o %t/vec.so // // RUN: cat %t/Test.cpp | LD_LIBRARY_PATH=%t:$LD_LIBRARY_PATH clang-repl ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 61ab36a - Revert "[Clang-REPL] Fix crash during `__run_exit_handlers` with dynamic libraries. (#117475)"
Author: Davide Italiano Date: 2024-12-14T18:26:32Z New Revision: 61ab36a3e226df32855286dd31a2c3859800475d URL: https://github.com/llvm/llvm-project/commit/61ab36a3e226df32855286dd31a2c3859800475d DIFF: https://github.com/llvm/llvm-project/commit/61ab36a3e226df32855286dd31a2c3859800475d.diff LOG: Revert "[Clang-REPL] Fix crash during `__run_exit_handlers` with dynamic libraries. (#117475)" This reverts commit 30ad53b92cec0cff9679d559edcc5b933312ba0c as it breaks systems that don't have a systemwide libc++ or libstdc++ installed. It should be rewritten to not invoke the system linker. In the meanwhile, reverting to unblock the bots. Added: Modified: clang/lib/Interpreter/Interpreter.cpp Removed: clang/test/Interpreter/crash.cpp diff --git a/clang/lib/Interpreter/Interpreter.cpp b/clang/lib/Interpreter/Interpreter.cpp index 6cd60a9bcf4f38..fa4c1439c92612 100644 --- a/clang/lib/Interpreter/Interpreter.cpp +++ b/clang/lib/Interpreter/Interpreter.cpp @@ -719,9 +719,7 @@ llvm::Error Interpreter::LoadDynamicLibrary(const char *name) { if (auto DLSG = llvm::orc::DynamicLibrarySearchGenerator::Load( name, DL.getGlobalPrefix())) -// FIXME: Eventually we should put each library in its own JITDylib and -//turn off process symbols by default. -EE->getProcessSymbolsJITDylib()->addGenerator(std::move(*DLSG)); +EE->getMainJITDylib().addGenerator(std::move(*DLSG)); else return DLSG.takeError(); diff --git a/clang/test/Interpreter/crash.cpp b/clang/test/Interpreter/crash.cpp deleted file mode 100644 index 1ab24b0febfa15..00 --- a/clang/test/Interpreter/crash.cpp +++ /dev/null @@ -1,20 +0,0 @@ -// REQUIRES: host-supports-jit, x86_64-linux - -// RUN: rm -rf %t -// RUN: mkdir -p %t -// -// RUN: split-file %s %t -// -// RUN: %clang++ -std=c++20 -fPIC -c %t/vec.cpp -o %t/vec.o -// RUN: %clang++ -shared %t/vec.o -o %t/vec.so -// -// RUN: cat %t/Test.cpp | LD_LIBRARY_PATH=%t:$LD_LIBRARY_PATH clang-repl - -//--- vec.cpp -#include - -//--- Test.cpp -%lib vec.so -#include -std::vector v; -%quit ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang-REPL] Fix crash during `__run_exit_handlers` with dynamic libraries. (PR #117475)
dcci wrote: Given the fix forward didn't work, I reverted this to unblock ``` commit 61ab36a3e226df32855286dd31a2c3859800475d (HEAD -> main, upstream/main) Author: Davide Italiano Date: Sat Dec 14 18:25:50 2024 + Revert "[Clang-REPL] Fix crash during `__run_exit_handlers` with dynamic libraries. (#117475)" This reverts commit 30ad53b92cec0cff9679d559edcc5b933312ba0c as it breaks systems that don't have a systemwide libc++ or libstdc++ installed. It should be rewritten to not invoke the system linker. In the meanwhile, reverting to unblock the bots. commit 9ddcaed3a64c2a187a0cfff4ba8f989c665ae1e5 Author: Davide Italiano Date: Sat Dec 14 18:25:02 2024 + Revert "[Clang] Interpreter test should not depend on system header (#119903)" This reverts commit 8ab6912831277d87838518c5f775f79d14616860. ``` as it seems to need some amount of work. Feel free to ping us so we can try this patch once you have something ready to confirm it fixes the build. https://github.com/llvm/llvm-project/pull/117475 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Temporarily disable test `clang/Interpreter/crash.cpp` (PR #119978)
https://github.com/vgvassilev approved this pull request. LGTM. https://github.com/llvm/llvm-project/pull/119978 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-cl] Don't add implicit NoBuiltinAttr to deleted or defaulted functions (PR #119719)
mgorny wrote: This test is failing on x86: #119979 https://github.com/llvm/llvm-project/pull/119719 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang][transformer] Allow usage of applyFirst with rewriteDescendants (PR #117658)
SherAndrei wrote: > Can you expand on your concern about the clash? The clash is happening in `NodesMap`. See, 1. the matcher which is associated with `rewriteDescendants` gets "Tag0", 2. tags for matchers from `applyfirst` are shifted, they get "Tag1", ... 3. that is why `transformer::detail::findSelectedCase` selects incorrect `Tag` from `NodesMap` (this also leads to error "ID not bound", for expected bound ID from other matcher) Do you want for me to update the description of the commit? https://github.com/llvm/llvm-project/pull/117658 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Fix a bug in annotating arrows after init braces (PR #119958)
https://github.com/owenca created https://github.com/llvm/llvm-project/pull/119958 Fixes #59066. >From 393e153c8ce6ec713ad9653f5f37eacc72b17b39 Mon Sep 17 00:00:00 2001 From: Owen Pan Date: Sat, 14 Dec 2024 00:33:35 -0800 Subject: [PATCH] [clang-format] Fix a bug in annotating arrows after init braces Fixes #59066. --- clang/lib/Format/TokenAnnotator.cpp | 3 ++- clang/lib/Format/UnwrappedLineParser.cpp | 5 +++-- clang/unittests/Format/TokenAnnotatorTest.cpp | 7 +++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 05c86db55641f6..667874853152ed 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -2403,7 +2403,8 @@ class AnnotatingParser { // not auto operator->() -> xxx; Current.setType(TT_TrailingReturnArrow); } else if (Current.is(tok::arrow) && Current.Previous && - Current.Previous->is(tok::r_brace)) { + Current.Previous->is(tok::r_brace) && + Current.Previous->is(BK_Block)) { // Concept implicit conversion constraint needs to be treated like // a trailing return type ... } -> . Current.setType(TT_TrailingReturnArrow); diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index de7e261b21d303..654148a161bd7f 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -570,8 +570,9 @@ void UnwrappedLineParser::calculateBraceTypes(bool ExpectClassBody) { NextTok->isOneOf(Keywords.kw_of, Keywords.kw_in, Keywords.kw_as)); ProbablyBracedList = - ProbablyBracedList || (IsCpp && (PrevTok->Tok.isLiteral() || - NextTok->is(tok::l_paren))); + ProbablyBracedList || + (IsCpp && (PrevTok->Tok.isLiteral() || + NextTok->isOneOf(tok::l_paren, tok::arrow))); // If there is a comma, semicolon or right paren after the closing // brace, we assume this is a braced initializer list. diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp index 38658fcb0e9990..b2fb5227993c3f 100644 --- a/clang/unittests/Format/TokenAnnotatorTest.cpp +++ b/clang/unittests/Format/TokenAnnotatorTest.cpp @@ -2277,6 +2277,13 @@ TEST_F(TokenAnnotatorTest, UnderstandsTrailingReturnArrow) { ASSERT_EQ(Tokens.size(), 21u) << Tokens; EXPECT_TOKEN(Tokens[13], tok::arrow, TT_Unknown); + Tokens = annotate("Class{foo}->func(arg);"); + ASSERT_EQ(Tokens.size(), 14u) << Tokens; + EXPECT_TOKEN(Tokens[4], tok::l_brace, TT_Unknown); // Not FunctionLBrace + EXPECT_BRACE_KIND(Tokens[4], BK_BracedInit); + EXPECT_BRACE_KIND(Tokens[6], BK_BracedInit); + EXPECT_TOKEN(Tokens[7], tok::arrow, TT_Unknown); + auto Style = getLLVMStyle(); Style.StatementAttributeLikeMacros.push_back("emit"); Tokens = annotate("emit foo()->bar;", Style); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Fix a bug in annotating arrows after init braces (PR #119958)
llvmbot wrote: @llvm/pr-subscribers-clang-format Author: Owen Pan (owenca) Changes Fixes #59066. --- Full diff: https://github.com/llvm/llvm-project/pull/119958.diff 3 Files Affected: - (modified) clang/lib/Format/TokenAnnotator.cpp (+2-1) - (modified) clang/lib/Format/UnwrappedLineParser.cpp (+3-2) - (modified) clang/unittests/Format/TokenAnnotatorTest.cpp (+7) ``diff diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 05c86db55641f6..667874853152ed 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -2403,7 +2403,8 @@ class AnnotatingParser { // not auto operator->() -> xxx; Current.setType(TT_TrailingReturnArrow); } else if (Current.is(tok::arrow) && Current.Previous && - Current.Previous->is(tok::r_brace)) { + Current.Previous->is(tok::r_brace) && + Current.Previous->is(BK_Block)) { // Concept implicit conversion constraint needs to be treated like // a trailing return type ... } -> . Current.setType(TT_TrailingReturnArrow); diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index de7e261b21d303..654148a161bd7f 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -570,8 +570,9 @@ void UnwrappedLineParser::calculateBraceTypes(bool ExpectClassBody) { NextTok->isOneOf(Keywords.kw_of, Keywords.kw_in, Keywords.kw_as)); ProbablyBracedList = - ProbablyBracedList || (IsCpp && (PrevTok->Tok.isLiteral() || - NextTok->is(tok::l_paren))); + ProbablyBracedList || + (IsCpp && (PrevTok->Tok.isLiteral() || + NextTok->isOneOf(tok::l_paren, tok::arrow))); // If there is a comma, semicolon or right paren after the closing // brace, we assume this is a braced initializer list. diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp index 38658fcb0e9990..b2fb5227993c3f 100644 --- a/clang/unittests/Format/TokenAnnotatorTest.cpp +++ b/clang/unittests/Format/TokenAnnotatorTest.cpp @@ -2277,6 +2277,13 @@ TEST_F(TokenAnnotatorTest, UnderstandsTrailingReturnArrow) { ASSERT_EQ(Tokens.size(), 21u) << Tokens; EXPECT_TOKEN(Tokens[13], tok::arrow, TT_Unknown); + Tokens = annotate("Class{foo}->func(arg);"); + ASSERT_EQ(Tokens.size(), 14u) << Tokens; + EXPECT_TOKEN(Tokens[4], tok::l_brace, TT_Unknown); // Not FunctionLBrace + EXPECT_BRACE_KIND(Tokens[4], BK_BracedInit); + EXPECT_BRACE_KIND(Tokens[6], BK_BracedInit); + EXPECT_TOKEN(Tokens[7], tok::arrow, TT_Unknown); + auto Style = getLLVMStyle(); Style.StatementAttributeLikeMacros.push_back("emit"); Tokens = annotate("emit foo()->bar;", Style); `` https://github.com/llvm/llvm-project/pull/119958 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang] Fix crashes when passing VLA to va_arg (PR #119563)
https://github.com/amane-ame updated https://github.com/llvm/llvm-project/pull/119563 From 659eda3ec76b63418f8b621b004728d9d7bf26ad Mon Sep 17 00:00:00 2001 From: amane-ame Date: Wed, 11 Dec 2024 22:17:51 +0800 Subject: [PATCH 1/8] [clang] Fix crashes when passing VLA to va_arg --- clang/lib/CodeGen/CGExprAgg.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/clang/lib/CodeGen/CGExprAgg.cpp b/clang/lib/CodeGen/CGExprAgg.cpp index 2ad6587089f101..a4111cb65c8b1c 100644 --- a/clang/lib/CodeGen/CGExprAgg.cpp +++ b/clang/lib/CodeGen/CGExprAgg.cpp @@ -2201,6 +2201,8 @@ void CodeGenFunction::EmitAggregateCopy(LValue Dest, LValue Src, QualType Ty, // But note that getTypeInfo returns 0 for a VLA. if (auto *VAT = dyn_cast_or_null( getContext().getAsArrayType(Ty))) { + assert(Ty->isVariableArrayType()); + EmitVariablyModifiedType(Ty); QualType BaseEltTy; SizeVal = emitArrayLength(VAT, BaseEltTy, DestPtr); TypeInfo = getContext().getTypeInfoInChars(BaseEltTy); From 5937db790ff0a59ea5bf18cb008d38a4524dc7dc Mon Sep 17 00:00:00 2001 From: amane-ame Date: Thu, 12 Dec 2024 13:50:13 +0800 Subject: [PATCH 2/8] [clang] Add a testcase for passing VLA to va_arg --- clang/test/CodeGen/varargs.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/clang/test/CodeGen/varargs.c b/clang/test/CodeGen/varargs.c index 625399b87f7ad7..b7b1b52156be37 100644 --- a/clang/test/CodeGen/varargs.c +++ b/clang/test/CodeGen/varargs.c @@ -20,4 +20,7 @@ void vla(int n, ...) __builtin_va_list ap; void *p; p = __builtin_va_arg(ap, typeof (int (*)[++n])); // CHECK: add nsw i32 {{.*}}, 1 + // Don't crash on some undefined behaviors. + p = __builtin_va_arg(ap, typeof (int [++n])); + p = __builtin_va_arg(ap, typeof (int [n][n])); } From df9f8f61ee21b81c9cfd300d113afea9298b8067 Mon Sep 17 00:00:00 2001 From: amane-ame Date: Thu, 12 Dec 2024 13:52:59 +0800 Subject: [PATCH 3/8] [clang] Move the parsing of VLA in va_arg to EmitVAArg --- clang/lib/CodeGen/CGCall.cpp| 2 ++ clang/lib/CodeGen/CGExprAgg.cpp | 2 -- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp index 3cefc9da66ddb8..4e2812c62f4357 100644 --- a/clang/lib/CodeGen/CGCall.cpp +++ b/clang/lib/CodeGen/CGCall.cpp @@ -6121,6 +6121,8 @@ RValue CodeGenFunction::EmitVAArg(VAArgExpr *VE, Address &VAListAddr, VAListAddr = VE->isMicrosoftABI() ? EmitMSVAListRef(VE->getSubExpr()) : EmitVAListRef(VE->getSubExpr()); QualType Ty = VE->getType(); + if (Ty->isVariableArrayType()) +EmitVariablyModifiedType(Ty); if (VE->isMicrosoftABI()) return CGM.getABIInfo().EmitMSVAArg(*this, VAListAddr, Ty, Slot); return CGM.getABIInfo().EmitVAArg(*this, VAListAddr, Ty, Slot); diff --git a/clang/lib/CodeGen/CGExprAgg.cpp b/clang/lib/CodeGen/CGExprAgg.cpp index a4111cb65c8b1c..2ad6587089f101 100644 --- a/clang/lib/CodeGen/CGExprAgg.cpp +++ b/clang/lib/CodeGen/CGExprAgg.cpp @@ -2201,8 +2201,6 @@ void CodeGenFunction::EmitAggregateCopy(LValue Dest, LValue Src, QualType Ty, // But note that getTypeInfo returns 0 for a VLA. if (auto *VAT = dyn_cast_or_null( getContext().getAsArrayType(Ty))) { - assert(Ty->isVariableArrayType()); - EmitVariablyModifiedType(Ty); QualType BaseEltTy; SizeVal = emitArrayLength(VAT, BaseEltTy, DestPtr); TypeInfo = getContext().getTypeInfoInChars(BaseEltTy); From b38c1d1ee20d3308a4120c3b95a167a936314a6b Mon Sep 17 00:00:00 2001 From: amane-ame Date: Thu, 12 Dec 2024 15:43:35 +0800 Subject: [PATCH 4/8] [clang] Emit an undefined-behavior warning for passing VLA to va_arg --- clang/include/clang/Basic/DiagnosticSemaKinds.td | 4 clang/lib/Sema/SemaExpr.cpp | 7 +++ clang/test/CodeGen/varargs.c | 6 +++--- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 0a245e2077f68f..3a352f23faa353 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -10497,6 +10497,10 @@ def warn_second_parameter_to_va_arg_ownership_qualified : Warning< def warn_second_parameter_to_va_arg_never_compatible : Warning< "second argument to 'va_arg' is of promotable type %0; this va_arg has " "undefined behavior because arguments will be promoted to %1">, InGroup; +def warn_second_parameter_to_va_arg_vla : Warning< + "second argument to 'va_arg' is of variable length array type %0; " + "this va_arg has undefined behavior because arguments will never " + "be compatible with variable length array type">, InGroup; def warn_return_missing_expr : Warning< "non-void %select{function|method}1 %0 should return a value">, DefaultError, diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 15
[clang] [AST] Migrate away from PointerUnion::get (NFC) (PR #119949)
https://github.com/nikic approved this pull request. https://github.com/llvm/llvm-project/pull/119949 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Temporarily disable test `clang/Interpreter/crash.cpp` (PR #119978)
carlocab wrote: Obsoleted by 61ab36a3e226df32855286dd31a2c3859800475d https://github.com/llvm/llvm-project/pull/119978 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] remove misuse of `getLocalOrGlobal` for non common used options (PR #119948)
https://github.com/carlosgalvezp approved this pull request. LGTM, thanks! https://github.com/llvm/llvm-project/pull/119948 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Add AlignAfterOpenBracketOptions (PR #108332)
gedare wrote: > I don't think this is the way to go, or at least not with this name. > > How about going the `Custom` way? Adding a `Custom` option to `AlignAfterOpenBracket` is an interesting proposal. There have been some ideas floated in other Issues and PRs related to this, for example: * #118046 * #80049 My concern with a `Custom` option is what to include. At this point it could be an enumeration of the different kinds of blocks (functions, if/else, for, other) and the different kinds of openers (parens, braces, square brackets, angles), and alignment of the parameters (`Align`, `DontAlign`), and breaking behavior (`DontBreak`, `AlwaysBreak` or better yet `InitialBreak` and `BlockIndent` or better `LastBreak`). At the moment, these alignment and breaking options are fairly complex and bug-prone. https://github.com/llvm/llvm-project/pull/108332 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] 99354f9 - [clang][test] Fix SemaCXX/msvc-pragma-function-no-builtin-attr.cpp for x86 (#119986)
Author: Richard Dzenis Date: 2024-12-15T00:18:09+02:00 New Revision: 99354f968f64659cbad5c82b0301d851ae54f057 URL: https://github.com/llvm/llvm-project/commit/99354f968f64659cbad5c82b0301d851ae54f057 DIFF: https://github.com/llvm/llvm-project/commit/99354f968f64659cbad5c82b0301d851ae54f057.diff LOG: [clang][test] Fix SemaCXX/msvc-pragma-function-no-builtin-attr.cpp for x86 (#119986) Fix test failure from #119719 84b0f0145887bbfe49fd4dc85490b14108a72cee Closes #119979 Added: Modified: clang/test/SemaCXX/msvc-pragma-function-no-builtin-attr.cpp Removed: diff --git a/clang/test/SemaCXX/msvc-pragma-function-no-builtin-attr.cpp b/clang/test/SemaCXX/msvc-pragma-function-no-builtin-attr.cpp index 066c66884e33c1..7262ffd079a92a 100644 --- a/clang/test/SemaCXX/msvc-pragma-function-no-builtin-attr.cpp +++ b/clang/test/SemaCXX/msvc-pragma-function-no-builtin-attr.cpp @@ -18,10 +18,10 @@ int bar() { struct A { int foo() = delete; -// CHECK: CXXMethodDecl {{.*}} foo 'int ()' delete +// CHECK: CXXMethodDecl {{.*}} foo {{.*}} delete // CHECK-NOT: NoBuiltinAttr A() = default; -// CHECK: CXXConstructorDecl {{.*}} A 'void ()' default +// CHECK: CXXConstructorDecl {{.*}} A {{.*}} default // CHECK-NOT: NoBuiltinAttr }; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Fix clang/test/SemaCXX/msvc-pragma-function-no-builtin-attr.cpp for x86 (PR #119986)
https://github.com/RIscRIpt closed https://github.com/llvm/llvm-project/pull/119986 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Add AlignAfterOpenBracketOptions (PR #108332)
@@ -811,10 +816,11 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun, if (!Tok.Previous) return true; if (Tok.Previous->isIf()) - return Style.AlignAfterOpenBracket == FormatStyle::BAS_AlwaysBreak; -return !Tok.Previous->isOneOf(TT_CastRParen, tok::kw_for, tok::kw_while, - tok::kw_switch) && - !(Style.isJavaScript() && Tok.Previous->is(Keywords.kw_await)); + return Style.AlignAfterOpenBracketBreak.InIfConditionalStatements; gedare wrote: It's been refactored into the `IsOtherConditional()`. I may need to look a bit closer at the JavaScript (TypeScript) cases. https://github.com/llvm/llvm-project/pull/108332 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Add AlignAfterOpenBracketOptions (PR #108332)
@@ -1452,6 +1476,7 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind Language) { FormatStyle LLVMStyle; LLVMStyle.AccessModifierOffset = -2; LLVMStyle.AlignAfterOpenBracket = FormatStyle::BAS_Align; + LLVMStyle.AlignAfterOpenBracketBreak = {}; gedare wrote: These options (currently) have no effect when using `BAS_Align`. https://github.com/llvm/llvm-project/pull/108332 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] aaadaee - [clang-tidy] remove misuse of `getLocalOrGlobal` for non common used options (#119948)
Author: Congcong Cai Date: 2024-12-15T05:04:32+08:00 New Revision: aaadaee7b228d7010ff7076f5002ebb96b5e03dc URL: https://github.com/llvm/llvm-project/commit/aaadaee7b228d7010ff7076f5002ebb96b5e03dc DIFF: https://github.com/llvm/llvm-project/commit/aaadaee7b228d7010ff7076f5002ebb96b5e03dc.diff LOG: [clang-tidy] remove misuse of `getLocalOrGlobal` for non common used options (#119948) [RFC](https://discourse.llvm.org/t/rfc-global-option-rules-for-clang-tidy/83647) Added: Modified: clang-tools-extra/clang-tidy/bugprone/UncheckedOptionalAccessCheck.h clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp clang-tools-extra/clang-tidy/cppcoreguidelines/RvalueReferenceParamNotMovedCheck.cpp clang-tools-extra/clang-tidy/performance/InefficientVectorOperationCheck.cpp clang-tools-extra/clang-tidy/readability/RedundantAccessSpecifiersCheck.h clang-tools-extra/clang-tidy/readability/RedundantCastingCheck.cpp clang-tools-extra/clang-tidy/utils/RenamerClangTidyCheck.cpp Removed: diff --git a/clang-tools-extra/clang-tidy/bugprone/UncheckedOptionalAccessCheck.h b/clang-tools-extra/clang-tidy/bugprone/UncheckedOptionalAccessCheck.h index 2d1570f7df8abb..e2fcccbfefb264 100644 --- a/clang-tools-extra/clang-tidy/bugprone/UncheckedOptionalAccessCheck.h +++ b/clang-tools-extra/clang-tidy/bugprone/UncheckedOptionalAccessCheck.h @@ -12,7 +12,6 @@ #include "../ClangTidyCheck.h" #include "clang/ASTMatchers/ASTMatchFinder.h" #include "clang/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.h" -#include namespace clang::tidy::bugprone { @@ -26,8 +25,7 @@ class UncheckedOptionalAccessCheck : public ClangTidyCheck { public: UncheckedOptionalAccessCheck(StringRef Name, ClangTidyContext *Context) : ClangTidyCheck(Name, Context), -ModelOptions{ -Options.getLocalOrGlobal("IgnoreSmartPointerDereference", false)} {} +ModelOptions{Options.get("IgnoreSmartPointerDereference", false)} {} void registerMatchers(ast_matchers::MatchFinder *Finder) override; void check(const ast_matchers::MatchFinder::MatchResult &Result) override; bool isLanguageVersionSupported(const LangOptions &LangOpts) const override { diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp index 225e867c9b24f7..d665c47d12bb4d 100644 --- a/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp +++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/ProTypeMemberInitCheck.cpp @@ -277,7 +277,7 @@ ProTypeMemberInitCheck::ProTypeMemberInitCheck(StringRef Name, ClangTidyContext *Context) : ClangTidyCheck(Name, Context), IgnoreArrays(Options.get("IgnoreArrays", false)), - UseAssignment(Options.getLocalOrGlobal("UseAssignment", false)) {} + UseAssignment(Options.get("UseAssignment", false)) {} void ProTypeMemberInitCheck::registerMatchers(MatchFinder *Finder) { auto IsUserProvidedNonDelegatingConstructor = diff --git a/clang-tools-extra/clang-tidy/cppcoreguidelines/RvalueReferenceParamNotMovedCheck.cpp b/clang-tools-extra/clang-tidy/cppcoreguidelines/RvalueReferenceParamNotMovedCheck.cpp index 7db9e29e8fd0e6..8c386d5bc79451 100644 --- a/clang-tools-extra/clang-tidy/cppcoreguidelines/RvalueReferenceParamNotMovedCheck.cpp +++ b/clang-tools-extra/clang-tidy/cppcoreguidelines/RvalueReferenceParamNotMovedCheck.cpp @@ -119,11 +119,10 @@ void RvalueReferenceParamNotMovedCheck::check( RvalueReferenceParamNotMovedCheck::RvalueReferenceParamNotMovedCheck( StringRef Name, ClangTidyContext *Context) : ClangTidyCheck(Name, Context), - AllowPartialMove(Options.getLocalOrGlobal("AllowPartialMove", false)), - IgnoreUnnamedParams( - Options.getLocalOrGlobal("IgnoreUnnamedParams", false)), + AllowPartialMove(Options.get("AllowPartialMove", false)), + IgnoreUnnamedParams(Options.get("IgnoreUnnamedParams", false)), IgnoreNonDeducedTemplateTypes( - Options.getLocalOrGlobal("IgnoreNonDeducedTemplateTypes", false)) {} + Options.get("IgnoreNonDeducedTemplateTypes", false)) {} void RvalueReferenceParamNotMovedCheck::storeOptions( ClangTidyOptions::OptionMap &Opts) { diff --git a/clang-tools-extra/clang-tidy/performance/InefficientVectorOperationCheck.cpp b/clang-tools-extra/clang-tidy/performance/InefficientVectorOperationCheck.cpp index dc6e0cf9c7d123..94cb7ec38087a5 100644 --- a/clang-tools-extra/clang-tidy/performance/InefficientVectorOperationCheck.cpp +++ b/clang-tools-extra/clang-tidy/performance/InefficientVectorOperationCheck.cpp @@ -77,7 +77,7 @@ InefficientVectorOperationCheck::InefficientVectorOperationCheck( : ClangTidyCheck(Name, Context), VectorLikeClasses(utils::options::pars
[clang-tools-extra] [clang-tidy] remove misuse of `getLocalOrGlobal` for non common used options (PR #119948)
https://github.com/HerrCai0907 closed https://github.com/llvm/llvm-project/pull/119948 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Temporarily disable test `clang/Interpreter/crash.cpp` (PR #119978)
vgvassilev wrote: > Obsoleted by > [61ab36a](https://github.com/llvm/llvm-project/commit/61ab36a3e226df32855286dd31a2c3859800475d) That was the right fix, not the revert... https://github.com/llvm/llvm-project/pull/119978 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] detect nesting in template strings (PR #119989)
https://github.com/gedare created https://github.com/llvm/llvm-project/pull/119989 The helper to check if a token is in a template string scans too far backward. It should stop if a different scope is found. Fixes #107571 >From fa8d1b12eee0164f2b4c8223281d0e59dfa693e1 Mon Sep 17 00:00:00 2001 From: Gedare Bloom Date: Sat, 14 Dec 2024 15:25:44 -0700 Subject: [PATCH] [clang-format] detect nesting in template strings The helper to check if a token is in a template string scans too far backward. It should stop if a different scope is found. Fixes #107571 --- clang/lib/Format/ContinuationIndenter.cpp | 4 +++- clang/unittests/Format/FormatTestJS.cpp | 7 +++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp index aed86c1fb99551..9ffdc044e6784d 100644 --- a/clang/lib/Format/ContinuationIndenter.cpp +++ b/clang/lib/Format/ContinuationIndenter.cpp @@ -826,8 +826,10 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun, for (const auto *Prev = &Tok; Prev; Prev = Prev->Previous) { if (Prev->is(TT_TemplateString) && Prev->opensScope()) return true; - if (Prev->is(TT_TemplateString) && Prev->closesScope()) + if (Prev->opensScope() || + (Prev->is(TT_TemplateString) && Prev->closesScope())) { break; + } } return false; }; diff --git a/clang/unittests/Format/FormatTestJS.cpp b/clang/unittests/Format/FormatTestJS.cpp index 4b15e7b7da3393..678fd1f3fc8d0e 100644 --- a/clang/unittests/Format/FormatTestJS.cpp +++ b/clang/unittests/Format/FormatTestJS.cpp @@ -2157,6 +2157,13 @@ TEST_F(FormatTestJS, TemplateStringMultiLineExpression) { " : a,\n" " : b,\n" "})}`;"); + + verifyFormat("`${\n" + "(\n" + "FOOFOOFOOFOOFOO_FOO_FO_FOO_FOOO -\n" + "(barbarbarbarbar_bar_bar_bar_bar_bar +\n" + " bar_bar_bar_barbarbar___bar_bar_bar + 1),\n" + ")}`;\n"); } TEST_F(FormatTestJS, TemplateStringASI) { ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] detect nesting in template strings (PR #119989)
llvmbot wrote: @llvm/pr-subscribers-clang-format Author: Gedare Bloom (gedare) Changes The helper to check if a token is in a template string scans too far backward. It should stop if a different scope is found. Fixes #107571 --- Full diff: https://github.com/llvm/llvm-project/pull/119989.diff 2 Files Affected: - (modified) clang/lib/Format/ContinuationIndenter.cpp (+3-1) - (modified) clang/unittests/Format/FormatTestJS.cpp (+7) ``diff diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp index aed86c1fb99551..9ffdc044e6784d 100644 --- a/clang/lib/Format/ContinuationIndenter.cpp +++ b/clang/lib/Format/ContinuationIndenter.cpp @@ -826,8 +826,10 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun, for (const auto *Prev = &Tok; Prev; Prev = Prev->Previous) { if (Prev->is(TT_TemplateString) && Prev->opensScope()) return true; - if (Prev->is(TT_TemplateString) && Prev->closesScope()) + if (Prev->opensScope() || + (Prev->is(TT_TemplateString) && Prev->closesScope())) { break; + } } return false; }; diff --git a/clang/unittests/Format/FormatTestJS.cpp b/clang/unittests/Format/FormatTestJS.cpp index 4b15e7b7da3393..678fd1f3fc8d0e 100644 --- a/clang/unittests/Format/FormatTestJS.cpp +++ b/clang/unittests/Format/FormatTestJS.cpp @@ -2157,6 +2157,13 @@ TEST_F(FormatTestJS, TemplateStringMultiLineExpression) { " : a,\n" " : b,\n" "})}`;"); + + verifyFormat("`${\n" + "(\n" + "FOOFOOFOOFOOFOO_FOO_FO_FOO_FOOO -\n" + "(barbarbarbarbar_bar_bar_bar_bar_bar +\n" + " bar_bar_bar_barbarbar___bar_bar_bar + 1),\n" + ")}`;\n"); } TEST_F(FormatTestJS, TemplateStringASI) { `` https://github.com/llvm/llvm-project/pull/119989 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] add BinPackLongBracedLists style option (PR #112482)
https://github.com/gedare updated https://github.com/llvm/llvm-project/pull/112482 >From d625f811a615155b15a007ec3afc9874c52d06c4 Mon Sep 17 00:00:00 2001 From: Gedare Bloom Date: Tue, 15 Oct 2024 23:55:49 -0600 Subject: [PATCH 1/3] [clang-format] add BinPackLongBracedLists style option The use of Cpp11BracedListStyle with BinPackParameters=False avoids bin packing until reaching a hard-coded limit of 20 items. This is an arbitrary choice. Introduce a new style option to allow disabling this limit. --- clang/include/clang/Format/Format.h| 20 + clang/lib/Format/Format.cpp| 2 ++ clang/lib/Format/FormatToken.cpp | 2 +- clang/unittests/Format/ConfigParseTest.cpp | 1 + clang/unittests/Format/FormatTest.cpp | 26 ++ 5 files changed, 50 insertions(+), 1 deletion(-) diff --git a/clang/include/clang/Format/Format.h b/clang/include/clang/Format/Format.h index 6383934afa2c40..cfac20e2d5d55b 100644 --- a/clang/include/clang/Format/Format.h +++ b/clang/include/clang/Format/Format.h @@ -1208,6 +1208,22 @@ struct FormatStyle { /// \version 3.7 bool BinPackArguments; + /// If ``BinPackLongBracedLists`` is ``true`` it overrides + /// ``BinPackArguments`` if there are 20 or more items in a braced + /// initializer list. + /// \code + ///BinPackLongBracedLists: false vs. BinPackLongBracedLists: true + ///vector x{ vector x{1, 2, ..., + /// 20, 21}; + ///1, + ///2, + ///..., + ///20, + ///21}; + /// \endcode + /// \version 20 + bool BinPackLongBracedLists; + /// Different way to try to fit all parameters on a line. enum BinPackParametersStyle : int8_t { /// Bin-pack parameters. @@ -2515,6 +2531,9 @@ struct FormatStyle { /// (e.g. a type or variable name), clang-format formats as if the ``{}`` were /// the parentheses of a function call with that name. If there is no name, /// a zero-length name is assumed. + /// + /// ``BinPackArguments`` may be forced to true for initializer lists with + /// more than 20 items if ``BinPackLongBracedLists`` is true. /// \code ///true: false: ///vector x{1, 2, 3, 4}; vs. vector x{ 1, 2, 3, 4 }; @@ -5172,6 +5191,7 @@ struct FormatStyle { R.AlwaysBreakBeforeMultilineStrings && AttributeMacros == R.AttributeMacros && BinPackArguments == R.BinPackArguments && + BinPackLongBracedLists == R.BinPackLongBracedLists && BinPackParameters == R.BinPackParameters && BitFieldColonSpacing == R.BitFieldColonSpacing && BracedInitializerIndentWidth == R.BracedInitializerIndentWidth && diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index dcaac4b0d42cc5..559ffe56a30afe 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -981,6 +981,7 @@ template <> struct MappingTraits { Style.AlwaysBreakBeforeMultilineStrings); IO.mapOptional("AttributeMacros", Style.AttributeMacros); IO.mapOptional("BinPackArguments", Style.BinPackArguments); +IO.mapOptional("BinPackLongBracedLists", Style.BinPackLongBracedLists); IO.mapOptional("BinPackParameters", Style.BinPackParameters); IO.mapOptional("BitFieldColonSpacing", Style.BitFieldColonSpacing); IO.mapOptional("BracedInitializerIndentWidth", @@ -1484,6 +1485,7 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind Language) { LLVMStyle.AlwaysBreakBeforeMultilineStrings = false; LLVMStyle.AttributeMacros.push_back("__capability"); LLVMStyle.BinPackArguments = true; + LLVMStyle.BinPackLongBracedLists = true; LLVMStyle.BinPackParameters = FormatStyle::BPPS_BinPack; LLVMStyle.BitFieldColonSpacing = FormatStyle::BFCS_Both; LLVMStyle.BracedInitializerIndentWidth = std::nullopt; diff --git a/clang/lib/Format/FormatToken.cpp b/clang/lib/Format/FormatToken.cpp index 963e8f87793fa0..a56a13bd58a519 100644 --- a/clang/lib/Format/FormatToken.cpp +++ b/clang/lib/Format/FormatToken.cpp @@ -174,7 +174,7 @@ void CommaSeparatedList::precomputeFormattingInfos(const FormatToken *Token) { // have many items (20 or more) or we allow bin-packing of function call // arguments. if (Style.Cpp11BracedListStyle && !Style.BinPackArguments && - Commas.size() < 19) { + (Commas.size() < 19 || !Style.BinPackLongBracedLists)) { return; } diff --git a/clang/unittests/Format/ConfigParseTest.cpp b/clang/unittests/Format/ConfigParseTest.cpp index 7fc7492271668b..9c29cd3f57273f 100644 --- a/clang/unittests/Format/ConfigParseTest.cpp +++ b/clang/unittests/Format/ConfigParseTest.cpp @@ -160,6 +160,7 @@ TEST(ConfigParseTest, ParsesConfigurationBools) { CHECK_PARSE_BOOL(AllowShortEnumsOnASingleLine); CHECK_PARSE_BOOL(AllowShortLoops
[clang] [clang-format] add BinPackLongBracedLists style option (PR #112482)
@@ -1208,6 +1208,21 @@ struct FormatStyle { /// \version 3.7 bool BinPackArguments; + /// If ``BinPackArguments`` is ``false`` this option can override it if + /// ``true`` when 20 or more items are in a braced initializer list. gedare wrote: I rewrote it similar to your suggestion. https://github.com/llvm/llvm-project/pull/112482 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] add BinPackLongBracedLists style option (PR #112482)
gedare wrote: > I think it should be merges with `BinPackArguments` to get an enum > > * Never > * TwentyOrAbove (name is debatable) > * Always > * (Leave?) Currently the 20 item limit is only enforced on C++ initializer lists. Making it part of the `BinPackArguments` means it has to apply to any bin packing situation, so the scope of the style option increases. I'm not convinced it is worth doing. https://github.com/llvm/llvm-project/pull/112482 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Fix double-quotes in diagnostic when attempting to access a ext_vector of bools (PR #118186)
https://github.com/smallp-o-p updated https://github.com/llvm/llvm-project/pull/118186 >From 3b7cf6e65bdfedf8d15e393c9c2f819c4ed70386 Mon Sep 17 00:00:00 2001 From: William Tran-Viet Date: Sat, 30 Nov 2024 15:53:32 -0500 Subject: [PATCH 1/4] Fix double-quotes in diagnostic when attempting to access a ext_vector of bools --- clang/lib/Sema/SemaExprMember.cpp | 4 +++- clang/test/SemaCXX/vector-bool.cpp | 8 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/clang/lib/Sema/SemaExprMember.cpp b/clang/lib/Sema/SemaExprMember.cpp index 434768b99d631e..3d843bb84d9d8b 100644 --- a/clang/lib/Sema/SemaExprMember.cpp +++ b/clang/lib/Sema/SemaExprMember.cpp @@ -1655,8 +1655,10 @@ static ExprResult LookupMemberExpr(Sema &S, LookupResult &R, // We disallow element access for ext_vector_type bool. There is no way to // materialize a reference to a vector element as a pointer (each element is // one bit in the vector). +assert(MemberName.isIdentifier() && + "Ext vector component name not an identifier!"); S.Diag(R.getNameLoc(), diag::err_ext_vector_component_name_illegal) -<< MemberName +<< MemberName.getAsIdentifierInfo()->getName() << (BaseExpr.get() ? BaseExpr.get()->getSourceRange() : SourceRange()); return ExprError(); } diff --git a/clang/test/SemaCXX/vector-bool.cpp b/clang/test/SemaCXX/vector-bool.cpp index e99d420e73fab2..cd638056f348b0 100644 --- a/clang/test/SemaCXX/vector-bool.cpp +++ b/clang/test/SemaCXX/vector-bool.cpp @@ -85,10 +85,10 @@ void foo(const bool& X); // Disallow element-wise access. bool* ElementRefs() { - eight_bools.y = false; // expected-error@88 {{illegal vector component name ''y''}} - &eight_bools.z;// expected-error@89 {{illegal vector component name ''z''}} - foo(eight_bools.w);// expected-error@90 {{illegal vector component name ''w''}} - foo(eight_bools.wyx); // expected-error@91 {{illegal vector component name ''wyx''}} + eight_bools.y = false; // expected-error@88 {{illegal vector component name 'y'}} + &eight_bools.z;// expected-error@89 {{illegal vector component name 'z'}} + foo(eight_bools.w);// expected-error@90 {{illegal vector component name 'w'}} + foo(eight_bools.wyx); // expected-error@91 {{illegal vector component name 'wyx'}} } void Sizeof() { >From 664ac70ca6b752eaaca6ee64897885a8e19d84c5 Mon Sep 17 00:00:00 2001 From: William Tran-Viet Date: Fri, 13 Dec 2024 22:50:24 -0500 Subject: [PATCH 2/4] Remove quotation marks from err_ext_vector_component_name_illegal --- clang/include/clang/Basic/DiagnosticSemaKinds.td | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index eb05a6a77978af..3fe837de467cd0 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -3423,7 +3423,7 @@ def warn_typecheck_vector_element_sizes_not_equal : Warning< def err_ext_vector_component_exceeds_length : Error< "vector component access exceeds type %0">; def err_ext_vector_component_name_illegal : Error< - "illegal vector component name '%0'">; + "illegal vector component name %0">; def err_attribute_address_space_negative : Error< "address space is negative">; def err_attribute_address_space_too_high : Error< >From 1bcf41860a914f66ec31eafc739b4e938363ef3c Mon Sep 17 00:00:00 2001 From: William Tran-Viet Date: Fri, 13 Dec 2024 23:53:29 -0500 Subject: [PATCH 3/4] Pass single quotes directly when reporting illegal vector component in CheckExtVector(), and offset the diagnostic arrow so it points to the offending component, rather than the '.' at the start of the component identifier. --- clang/lib/Sema/SemaExprMember.cpp | 6 -- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/clang/lib/Sema/SemaExprMember.cpp b/clang/lib/Sema/SemaExprMember.cpp index 3d843bb84d9d8b..70f51efe193b4b 100644 --- a/clang/lib/Sema/SemaExprMember.cpp +++ b/clang/lib/Sema/SemaExprMember.cpp @@ -434,8 +434,10 @@ CheckExtVectorComponent(Sema &S, QualType baseType, ExprValueKind &VK, if (!HalvingSwizzle && *compStr) { // We didn't get to the end of the string. This means the component names // didn't come from the same set *or* we encountered an illegal name. -S.Diag(OpLoc, diag::err_ext_vector_component_name_illegal) - << StringRef(compStr, 1) << SourceRange(CompLoc); +size_t Offset = compStr - CompName->getNameStart() + 1; +S.Diag(OpLoc.getLocWithOffset(Offset), + diag::err_ext_vector_component_name_illegal) +<< StringRef({'\'', *compStr, '\''}) << SourceRange(CompLoc); return QualType(); } >From ad89f32758a68e47b45b5ffb4e9abba3e9b809df Mon Sep 17 00:00:00 2001 From: William Tran-Viet Date: Sat, 14 Dec 2024 14:43:42 -0500 Subject: [PATCH 4/4] Revert change in ext_vector_type bool element access
[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-ppc64-aix` running on `aix-ppc64` while building `clang,llvm` at step 3 "clean-build-dir". Full details are available at: https://lab.llvm.org/buildbot/#/builders/64/builds/1692 Here is the relevant piece of the build log for the reference ``` Step 3 (clean-build-dir) failure: Delete failed. (failure) (timed out) Step 6 (test-build-unified-tree-check-all) failure: test (failure) TEST 'LLVM :: CodeGen/AArch64/ptrauth-sign-personality.ll' FAILED Exit Code: 1 Command Output (stderr): -- RUN: at line 1: /home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/build/bin/llc -mtriple=aarch64-linux -filetype=asm /home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/llvm-project/llvm/test/CodeGen/AArch64/ptrauth-sign-personality.ll -o - | /home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/build/bin/FileCheck /home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/llvm-project/llvm/test/CodeGen/AArch64/ptrauth-sign-personality.ll + /home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/build/bin/llc -mtriple=aarch64-linux -filetype=asm /home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/llvm-project/llvm/test/CodeGen/AArch64/ptrauth-sign-personality.ll -o - + /home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/build/bin/FileCheck /home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/llvm-project/llvm/test/CodeGen/AArch64/ptrauth-sign-personality.ll /home/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/llvm-project/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/powerllvm/powerllvm_env/aix-ppc64/clang-ppc64-aix/llvm-project/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 ~ >> -- ``` https://github.com/llvm/llvm-project/pull/113148 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] remove misuse of `getLocalOrGlobal` for non common used options (PR #119948)
https://github.com/5chmidti approved this pull request. Thanks https://github.com/llvm/llvm-project/pull/119948 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Fix double-quotes in diagnostic when attempting to access a ext_vector of bools (PR #118186)
https://github.com/smallp-o-p updated https://github.com/llvm/llvm-project/pull/118186 >From 3b7cf6e65bdfedf8d15e393c9c2f819c4ed70386 Mon Sep 17 00:00:00 2001 From: William Tran-Viet Date: Sat, 30 Nov 2024 15:53:32 -0500 Subject: [PATCH 1/4] Fix double-quotes in diagnostic when attempting to access a ext_vector of bools --- clang/lib/Sema/SemaExprMember.cpp | 4 +++- clang/test/SemaCXX/vector-bool.cpp | 8 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/clang/lib/Sema/SemaExprMember.cpp b/clang/lib/Sema/SemaExprMember.cpp index 434768b99d631e..3d843bb84d9d8b 100644 --- a/clang/lib/Sema/SemaExprMember.cpp +++ b/clang/lib/Sema/SemaExprMember.cpp @@ -1655,8 +1655,10 @@ static ExprResult LookupMemberExpr(Sema &S, LookupResult &R, // We disallow element access for ext_vector_type bool. There is no way to // materialize a reference to a vector element as a pointer (each element is // one bit in the vector). +assert(MemberName.isIdentifier() && + "Ext vector component name not an identifier!"); S.Diag(R.getNameLoc(), diag::err_ext_vector_component_name_illegal) -<< MemberName +<< MemberName.getAsIdentifierInfo()->getName() << (BaseExpr.get() ? BaseExpr.get()->getSourceRange() : SourceRange()); return ExprError(); } diff --git a/clang/test/SemaCXX/vector-bool.cpp b/clang/test/SemaCXX/vector-bool.cpp index e99d420e73fab2..cd638056f348b0 100644 --- a/clang/test/SemaCXX/vector-bool.cpp +++ b/clang/test/SemaCXX/vector-bool.cpp @@ -85,10 +85,10 @@ void foo(const bool& X); // Disallow element-wise access. bool* ElementRefs() { - eight_bools.y = false; // expected-error@88 {{illegal vector component name ''y''}} - &eight_bools.z;// expected-error@89 {{illegal vector component name ''z''}} - foo(eight_bools.w);// expected-error@90 {{illegal vector component name ''w''}} - foo(eight_bools.wyx); // expected-error@91 {{illegal vector component name ''wyx''}} + eight_bools.y = false; // expected-error@88 {{illegal vector component name 'y'}} + &eight_bools.z;// expected-error@89 {{illegal vector component name 'z'}} + foo(eight_bools.w);// expected-error@90 {{illegal vector component name 'w'}} + foo(eight_bools.wyx); // expected-error@91 {{illegal vector component name 'wyx'}} } void Sizeof() { >From 664ac70ca6b752eaaca6ee64897885a8e19d84c5 Mon Sep 17 00:00:00 2001 From: William Tran-Viet Date: Fri, 13 Dec 2024 22:50:24 -0500 Subject: [PATCH 2/4] Remove quotation marks from err_ext_vector_component_name_illegal --- clang/include/clang/Basic/DiagnosticSemaKinds.td | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index eb05a6a77978af..3fe837de467cd0 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -3423,7 +3423,7 @@ def warn_typecheck_vector_element_sizes_not_equal : Warning< def err_ext_vector_component_exceeds_length : Error< "vector component access exceeds type %0">; def err_ext_vector_component_name_illegal : Error< - "illegal vector component name '%0'">; + "illegal vector component name %0">; def err_attribute_address_space_negative : Error< "address space is negative">; def err_attribute_address_space_too_high : Error< >From 1bcf41860a914f66ec31eafc739b4e938363ef3c Mon Sep 17 00:00:00 2001 From: William Tran-Viet Date: Fri, 13 Dec 2024 23:53:29 -0500 Subject: [PATCH 3/4] Pass single quotes directly when reporting illegal vector component in CheckExtVector(), and offset the diagnostic arrow so it points to the offending component, rather than the '.' at the start of the component identifier. --- clang/lib/Sema/SemaExprMember.cpp | 6 -- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/clang/lib/Sema/SemaExprMember.cpp b/clang/lib/Sema/SemaExprMember.cpp index 3d843bb84d9d8b..70f51efe193b4b 100644 --- a/clang/lib/Sema/SemaExprMember.cpp +++ b/clang/lib/Sema/SemaExprMember.cpp @@ -434,8 +434,10 @@ CheckExtVectorComponent(Sema &S, QualType baseType, ExprValueKind &VK, if (!HalvingSwizzle && *compStr) { // We didn't get to the end of the string. This means the component names // didn't come from the same set *or* we encountered an illegal name. -S.Diag(OpLoc, diag::err_ext_vector_component_name_illegal) - << StringRef(compStr, 1) << SourceRange(CompLoc); +size_t Offset = compStr - CompName->getNameStart() + 1; +S.Diag(OpLoc.getLocWithOffset(Offset), + diag::err_ext_vector_component_name_illegal) +<< StringRef({'\'', *compStr, '\''}) << SourceRange(CompLoc); return QualType(); } >From 5c135e86f37d1b6a80280cbc8d606b9d1ebea54b Mon Sep 17 00:00:00 2001 From: William Tran-Viet Date: Sat, 14 Dec 2024 14:43:42 -0500 Subject: [PATCH 4/4] Revert change in ext_vector_type bool element access
[clang] [llvm] [BoundsChecking] Add parameters to pass (PR #119894)
https://github.com/vitalybuka updated https://github.com/llvm/llvm-project/pull/119894 >From 6cd26753f380d9ee89d85139a5dc58bc0e4b0632 Mon Sep 17 00:00:00 2001 From: Vitaly Buka Date: Fri, 13 Dec 2024 08:04:56 -0800 Subject: [PATCH 1/2] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20in?= =?UTF-8?q?itial=20version?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Created using spr 1.3.4 --- clang/lib/CodeGen/BackendUtil.cpp | 3 +- .../Instrumentation/BoundsChecking.h | 18 +++- llvm/lib/Passes/PassBuilder.cpp | 27 ++ llvm/lib/Passes/PassRegistry.def | 7 +- .../Instrumentation/BoundsChecking.cpp| 23 + .../BoundsChecking/runtimes.ll| 95 +++ 6 files changed, 170 insertions(+), 3 deletions(-) create mode 100644 llvm/test/Instrumentation/BoundsChecking/runtimes.ll diff --git a/clang/lib/CodeGen/BackendUtil.cpp b/clang/lib/CodeGen/BackendUtil.cpp index 8cf44592a17475..ae0e8b132aa356 100644 --- a/clang/lib/CodeGen/BackendUtil.cpp +++ b/clang/lib/CodeGen/BackendUtil.cpp @@ -1020,7 +1020,8 @@ void EmitAssemblyHelper::RunOptimizationPipeline( if (LangOpts.Sanitize.has(SanitizerKind::LocalBounds)) PB.registerScalarOptimizerLateEPCallback( [](FunctionPassManager &FPM, OptimizationLevel Level) { -FPM.addPass(BoundsCheckingPass()); +FPM.addPass( +BoundsCheckingPass(BoundsCheckingPass::ReportingMode::Trap)); }); if (LangOpts.Sanitize.has(SanitizerKind::Realtime)) { diff --git a/llvm/include/llvm/Transforms/Instrumentation/BoundsChecking.h b/llvm/include/llvm/Transforms/Instrumentation/BoundsChecking.h index b1b1ece3eff5a0..29959acc29101a 100644 --- a/llvm/include/llvm/Transforms/Instrumentation/BoundsChecking.h +++ b/llvm/include/llvm/Transforms/Instrumentation/BoundsChecking.h @@ -16,9 +16,25 @@ class Function; /// A pass to instrument code and perform run-time bounds checking on loads, /// stores, and other memory intrinsics. -struct BoundsCheckingPass : PassInfoMixin { +class BoundsCheckingPass : public PassInfoMixin { +public: + enum class ReportingMode { +Trap, +MinRuntime, +MinRuntimeAbort, +FullRuntime, +FullRuntimeAbort, + }; + +private: + ReportingMode Mode = ReportingMode::Trap; + +public: + BoundsCheckingPass(ReportingMode Mode) {} PreservedAnalyses run(Function &F, FunctionAnalysisManager &AM); static bool isRequired() { return true; } + void printPipeline(raw_ostream &OS, + function_ref MapClassName2PassName); }; } // end namespace llvm diff --git a/llvm/lib/Passes/PassBuilder.cpp b/llvm/lib/Passes/PassBuilder.cpp index 260a34f2e060d6..78df7eed10f31a 100644 --- a/llvm/lib/Passes/PassBuilder.cpp +++ b/llvm/lib/Passes/PassBuilder.cpp @@ -1286,6 +1286,33 @@ Expected parseRtSanPassOptions(StringRef Params) { return Result; } +Expected +parseBoundsCheckingOptions(StringRef Params) { + BoundsCheckingPass::ReportingMode Mode = + BoundsCheckingPass::ReportingMode::Trap; + while (!Params.empty()) { +StringRef ParamName; +std::tie(ParamName, Params) = Params.split(';'); +if (ParamName == "trap") { + Mode = BoundsCheckingPass::ReportingMode::Trap; +} else if (ParamName == "rt") { + Mode = BoundsCheckingPass::ReportingMode::FullRuntime; +} else if (ParamName == "rt-abort") { + Mode = BoundsCheckingPass::ReportingMode::FullRuntimeAbort; +} else if (ParamName == "min-rt") { + Mode = BoundsCheckingPass::ReportingMode::MinRuntime; +} else if (ParamName == "min-rt-abort") { + Mode = BoundsCheckingPass::ReportingMode::MinRuntimeAbort; +} else { + return make_error( + formatv("invalid BoundsChecking pass parameter '{0}' ", ParamName) + .str(), + inconvertibleErrorCode()); +} + } + return Mode; +} + } // namespace /// Tests whether a pass name starts with a valid prefix for a default pipeline diff --git a/llvm/lib/Passes/PassRegistry.def b/llvm/lib/Passes/PassRegistry.def index 825f2f7f9a494a..c86ff0b5a042c2 100644 --- a/llvm/lib/Passes/PassRegistry.def +++ b/llvm/lib/Passes/PassRegistry.def @@ -339,7 +339,6 @@ FUNCTION_PASS("assume-builder", AssumeBuilderPass()) FUNCTION_PASS("assume-simplify", AssumeSimplifyPass()) FUNCTION_PASS("atomic-expand", AtomicExpandPass(TM)) FUNCTION_PASS("bdce", BDCEPass()) -FUNCTION_PASS("bounds-checking", BoundsCheckingPass()) FUNCTION_PASS("break-crit-edges", BreakCriticalEdgesPass()) FUNCTION_PASS("callbr-prepare", CallBrPreparePass()) FUNCTION_PASS("callsite-splitting", CallSiteSplittingPass()) @@ -624,6 +623,12 @@ FUNCTION_PASS_WITH_PARAMS( "rtsan", "RealtimeSanitizerPass", [](RealtimeSanitizerOptions Opts) { return RealtimeSanitizerPass(Opts); }, parseRtSanPassOptions, "") +FUNCTION_PASS_WITH_PARAMS( +"bounds-checking", "BoundsCheckingPass", +[](BoundsCheck
[clang-tools-extra] [clang-tidy] remove misuse of `getLocalOrGlobal` for non common used options (PR #119948)
5chmidti wrote: @HerrCai0907 Could you retroactively add a release note? While this hopefully doesn't exist in anyone's config, but if someone were to look, they'd see why this was done. https://github.com/llvm/llvm-project/pull/119948 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Temporarily disable test `clang/Interpreter/crash.cpp` (PR #119978)
yuxuanchen1997 wrote: May I understand what's the intention of this? I would prefer that the original author figures out a solution that doesn't depend on system linker, which is what I would consider a proper fix. https://github.com/llvm/llvm-project/pull/119978 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Temporarily disable test `clang/Interpreter/crash.cpp` (PR #119978)
https://github.com/yuxuanchen1997 closed https://github.com/llvm/llvm-project/pull/119978 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Fix clang/test/SemaCXX/msvc-pragma-function-no-builtin-attr.cpp for x86 (PR #119986)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Richard Dzenis (RIscRIpt) Changes Fix test failure from #119719 84b0f0145887bbfe49fd4dc85490b14108a72cee Closes #119979 --- Full diff: https://github.com/llvm/llvm-project/pull/119986.diff 1 Files Affected: - (modified) clang/test/SemaCXX/msvc-pragma-function-no-builtin-attr.cpp (+2-2) ``diff diff --git a/clang/test/SemaCXX/msvc-pragma-function-no-builtin-attr.cpp b/clang/test/SemaCXX/msvc-pragma-function-no-builtin-attr.cpp index 066c66884e33c1..7262ffd079a92a 100644 --- a/clang/test/SemaCXX/msvc-pragma-function-no-builtin-attr.cpp +++ b/clang/test/SemaCXX/msvc-pragma-function-no-builtin-attr.cpp @@ -18,10 +18,10 @@ int bar() { struct A { int foo() = delete; -// CHECK: CXXMethodDecl {{.*}} foo 'int ()' delete +// CHECK: CXXMethodDecl {{.*}} foo {{.*}} delete // CHECK-NOT: NoBuiltinAttr A() = default; -// CHECK: CXXConstructorDecl {{.*}} A 'void ()' default +// CHECK: CXXConstructorDecl {{.*}} A {{.*}} default // CHECK-NOT: NoBuiltinAttr }; `` https://github.com/llvm/llvm-project/pull/119986 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Temporarily disable test `clang/Interpreter/crash.cpp` (PR #119978)
carlocab wrote: > > Obsoleted by > > [61ab36a](https://github.com/llvm/llvm-project/commit/61ab36a3e226df32855286dd31a2c3859800475d) > > > > That was the right fix, not the revert... I'm inclined to agree. Could revert the revert then apply this. https://github.com/llvm/llvm-project/pull/119978 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Fix clang/test/SemaCXX/msvc-pragma-function-no-builtin-attr.cpp for x86 (PR #119986)
https://github.com/RIscRIpt created https://github.com/llvm/llvm-project/pull/119986 Fix test failure from #119719 84b0f0145887bbfe49fd4dc85490b14108a72cee Closes #119979 >From 876efed487603b450c56cd4c282449f5bfef52ad Mon Sep 17 00:00:00 2001 From: Richard Dzenis Date: Sat, 14 Dec 2024 23:32:04 +0200 Subject: [PATCH] Fix clang/test/SemaCXX/msvc-pragma-function-no-builtin-attr.cpp for x86 Fix test failure from #119719 84b0f0145887bbfe49fd4dc85490b14108a72cee --- clang/test/SemaCXX/msvc-pragma-function-no-builtin-attr.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clang/test/SemaCXX/msvc-pragma-function-no-builtin-attr.cpp b/clang/test/SemaCXX/msvc-pragma-function-no-builtin-attr.cpp index 066c66884e33c1..7262ffd079a92a 100644 --- a/clang/test/SemaCXX/msvc-pragma-function-no-builtin-attr.cpp +++ b/clang/test/SemaCXX/msvc-pragma-function-no-builtin-attr.cpp @@ -18,10 +18,10 @@ int bar() { struct A { int foo() = delete; -// CHECK: CXXMethodDecl {{.*}} foo 'int ()' delete +// CHECK: CXXMethodDecl {{.*}} foo {{.*}} delete // CHECK-NOT: NoBuiltinAttr A() = default; -// CHECK: CXXConstructorDecl {{.*}} A 'void ()' default +// CHECK: CXXConstructorDecl {{.*}} A {{.*}} default // CHECK-NOT: NoBuiltinAttr }; ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] Fix clang/test/SemaCXX/msvc-pragma-function-no-builtin-attr.cpp for x86 (PR #119986)
RIscRIpt wrote: I reproduced the problem locally by adding `-m32` flag to `%clang_cl`. Changes in this PR fix the test failure. https://github.com/llvm/llvm-project/pull/119986 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Coroutines: Properly Check if `await_suspend` return type is a `std::coroutine_handle` (PR #85684)
yuxuanchen1997 wrote: > I still feel it would be simpler to lookup the function for `await_suspend` > in the awaiter and look for its return type. Then we don't need to care about > the type of the expression. After reading a bit, I think it's possible to do this by duplicating a little bit of lookup logic in `Sema::BuildMemberReferenceExpr`. A better way might be to just see what expr `BuildMemberReferenceExpr` returns and whether that provides a good way to retrieve the member call. https://github.com/llvm/llvm-project/pull/85684 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Detect nesting in template strings (PR #119989)
https://github.com/owenca edited https://github.com/llvm/llvm-project/pull/119989 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Detect nesting in template strings (PR #119989)
@@ -2157,6 +2157,13 @@ TEST_F(FormatTestJS, TemplateStringMultiLineExpression) { " : a,\n" " : b,\n" "})}`;"); + + verifyFormat("`${\n" + "(\n" + "FOOFOOFOOFOOFOO_FOO_FO_FOO_FOOO -\n" + "(barbarbarbarbar_bar_bar_bar_bar_bar +\n" + " bar_bar_bar_barbarbar___bar_bar_bar + 1),\n" + ")}`;\n"); owenca wrote: ```suggestion ")}`;"); ``` https://github.com/llvm/llvm-project/pull/119989 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Detect nesting in template strings (PR #119989)
https://github.com/owenca approved this pull request. https://github.com/llvm/llvm-project/pull/119989 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [Clang] Fix crash for incompatible types in inline assembly (PR #119098)
https://github.com/AdUhTkJm updated https://github.com/llvm/llvm-project/pull/119098 >From 56670608becf2032867405778fa7b2b1a36fb3cf Mon Sep 17 00:00:00 2001 From: AdUhTkJm <2292398...@qq.com> Date: Sun, 8 Dec 2024 08:07:59 +0800 Subject: [PATCH] [Clang] Fix crash for incompatible types in inline assembly --- clang/lib/Sema/SemaStmtAsm.cpp | 7 ++- clang/test/Sema/asm.c | 21 + 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/clang/lib/Sema/SemaStmtAsm.cpp b/clang/lib/Sema/SemaStmtAsm.cpp index 0b272b806391c4..a0b203fbdfec21 100644 --- a/clang/lib/Sema/SemaStmtAsm.cpp +++ b/clang/lib/Sema/SemaStmtAsm.cpp @@ -664,11 +664,16 @@ StmtResult Sema::ActOnGCCAsmStmt(SourceLocation AsmLoc, bool IsSimple, SmallerValueMentioned |= OutSize < InSize; } +// If the input is an integer register while the output is floating point, +// or vice-versa, there is no way they can work together. +bool FPTiedToInt = (InputDomain == AD_FP) ^ (OutputDomain == AD_FP); + // If the smaller value wasn't mentioned in the asm string, and if the // output was a register, just extend the shorter one to the size of the // larger one. -if (!SmallerValueMentioned && InputDomain != AD_Other && +if (!SmallerValueMentioned && !FPTiedToInt && InputDomain != AD_Other && OutputConstraintInfos[TiedTo].allowsRegister()) { + // FIXME: GCC supports the OutSize to be 128 at maximum. Currently codegen // crash when the size larger than the register size. So we limit it here. if (OutTy->isStructureType() && diff --git a/clang/test/Sema/asm.c b/clang/test/Sema/asm.c index a9cff5947ef5d0..a666b45b3150ca 100644 --- a/clang/test/Sema/asm.c +++ b/clang/test/Sema/asm.c @@ -365,3 +365,24 @@ void test19(long long x) // FIXME: This case should be supported by codegen, but it fails now. asm ("" : "=rm" (x): "0" (e)); // expected-error {{unsupported inline asm: input with type 'st_size128' (aka 'struct _st_size128') matching output with type 'long long'}} } + +typedef int int2 __attribute__((ext_vector_type(2))); + +// GH118892 +void test20(char x) { + double d; + float f; + + asm ("fabs" : "=t" (d): "0" (x)); // expected-error {{unsupported inline asm: input with type 'char' matching output with type 'double'}} + asm ("fabs" : "=t" (x): "0" (d)); // expected-error {{unsupported inline asm: input with type 'double' matching output with type 'char'}} + asm ("fabs" : "=t" (f): "0" (d)); // no-error + asm ("fabs" : "=t" (d): "0" (f)); // no-error + + st_size64 a; + asm ("fabs" : "=t" (d): "0" (a)); // expected-error {{unsupported inline asm: input with type 'st_size64' (aka 'struct _st_size64') matching output with type 'double'}} + asm ("fabs" : "=t" (a): "0" (d)); // expected-error {{unsupported inline asm: input with type 'double' matching output with type 'st_size64' (aka 'struct _st_size64')}} + + int2 v; + asm ("fabs" : "=t" (d): "0" (v)); // expected-error {{unsupported inline asm: input with type 'int2' (vector of 2 'int' values) matching output with type 'double'}} + asm ("fabs" : "=t" (v): "0" (d)); // expected-error {{unsupported inline asm: input with type 'double' matching output with type 'int2' (vector of 2 'int' values)}} +} ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Fix crashes when the macro expansion is empty (PR #119428)
owenca wrote: Please add unit tests. https://github.com/llvm/llvm-project/pull/119428 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits