[clang] [clang-format] Handle function try block with ctor-initializer (PR #95878)
llvm-ci wrote: LLVM Buildbot has detected a new failure on builder `clang-cuda-l4` running on `cuda-l4-0` while building `clang` at step 3 "annotate". Full details are available at: https://lab.llvm.org/buildbot/#/builders/101/builds/278 Here is the relevant piece of the build log for the reference: ``` Step 3 (annotate) failure: '/buildbot/cuda-build --jobs=' (failure) ... NV_LIBCUBLAS_PACKAGE_NAME=libcublas-12-2 NV_LIBCUBLAS_VERSION=12.2.5.6-1 NV_LIBCUSPARSE_VERSION=12.1.2.141-1 NV_LIBNCCL_PACKAGE=libnccl2=2.18.5-1+cuda12.2 NV_LIBNCCL_PACKAGE_NAME=libnccl2 NV_LIBNCCL_PACKAGE_VERSION=2.18.5-1 NV_LIBNPP_PACKAGE=libnpp-12-2=12.2.1.4-1 NV_LIBNPP_VERSION=12.2.1.4-1 NV_NVTX_VERSION=12.2.140-1 PATH=/usr/local/nvidia/bin:/usr/local/cuda/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/buildbot PWD=/buildbot/cuda-l4-0/work/cuda-l4-0/clang-cuda-l4/build SHLVL=1 TERM=dumb WORK_DIR=/buildbot/cuda-l4-0/work _=/usr/local/bin/buildbot-worker using PTY: False ++ echo @@@HALT_ON_FAILURE@@@ ++ readlink -f .. + buildbot_dir=/buildbot/cuda-l4-0/work/cuda-l4-0/clang-cuda-l4 + revision=61571e9046fa6f12661e443123635053186794a1 + GPU_ARCH=sm_89 + CUDA_TEST_JOBS=1 + build_base=/buildbot/cuda-l4-0/work/clang-cuda-l4 + mkdir -p /buildbot/cuda-l4-0/work/clang-cuda-l4 + build_dir=/buildbot/cuda-l4-0/work/clang-cuda-l4/build + libc_build_dir=/buildbot/cuda-l4-0/work/clang-cuda-l4/build-libc + clang_dir=/buildbot/cuda-l4-0/work/clang-cuda-l4/clang + testsuite_dir=/buildbot/cuda-l4-0/work/clang-cuda-l4/llvm-test-suite + llvm_src_dir=/buildbot/cuda-l4-0/work/clang-cuda-l4/llvm + ext_dir=/buildbot/cuda-l4-0/work/clang-cuda-l4/external + inner_pid=612835 + trap 'handle_termination $inner_pid' TERM + do_build_and_test + wait 612835 + fetch_prebuilt_clang 61571e9046fa6f12661e443123635053186794a1 /buildbot/cuda-l4-0/work/clang-cuda-l4/clang + local revision=61571e9046fa6f12661e443123635053186794a1 + local destdir=/buildbot/cuda-l4-0/work/clang-cuda-l4/clang + local 'timeout=10 minutes' ++ date -ud '10 minutes' +%s + local endtime=1718763014 ++ storage_location llvm-61571e9046fa6f12661e443123635053186794a1 ++ local file=llvm-61571e9046fa6f12661e443123635053186794a1 ++ local default_storage_prefix=gs://cudabot-gce-artifacts/ ++ echo gs://cudabot-gce-artifacts/llvm-61571e9046fa6f12661e443123635053186794a1 + local snapshot=gs://cudabot-gce-artifacts/llvm-61571e9046fa6f12661e443123635053186794a1 + step 'Waiting for LLVM & Clang snapshot to be built. ' + local 'name=Waiting for LLVM & Clang snapshot to be built. ' + local summary= + echo '@@@BUILD_STEP Waiting for LLVM & Clang snapshot to be built. @@@' + step_summary_clear ``` https://github.com/llvm/llvm-project/pull/95878 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Handle function try block with ctor-initializer (PR #95878)
https://github.com/owenca closed https://github.com/llvm/llvm-project/pull/95878 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Handle function try block with ctor-initializer (PR #95878)
https://github.com/owenca updated https://github.com/llvm/llvm-project/pull/95878 >From 299924c9f9485e7a784ffedcb6ec4fbccf5ad6f7 Mon Sep 17 00:00:00 2001 From: Owen Pan Date: Mon, 17 Jun 2024 21:13:10 -0700 Subject: [PATCH 1/2] [clang-format] Handle function try block with ctor-initializer Fixes #58987. Fixes #95679. --- clang/lib/Format/UnwrappedLineParser.cpp | 17 +++-- clang/unittests/Format/TokenAnnotatorTest.cpp | 15 +++ 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index df5bb757a99ec..ce877ac2bb9ef 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -2955,9 +2955,15 @@ void UnwrappedLineParser::parseTryCatch() { assert(FormatTok->isOneOf(tok::kw_try, tok::kw___try) && "'try' expected"); nextToken(); bool NeedsUnwrappedLine = false; + bool HasCtorInitializer = false; if (FormatTok->is(tok::colon)) { +auto *Colon = FormatTok; // We are in a function try block, what comes is an initializer list. nextToken(); +if (FormatTok->is(tok::identifier)) { + HasCtorInitializer = true; + Colon->setFinalizedType(TT_CtorInitializerColon); +} // In case identifiers were removed by clang-tidy, what might follow is // multiple commas in sequence - before the first identifier. @@ -2966,14 +2972,11 @@ void UnwrappedLineParser::parseTryCatch() { while (FormatTok->is(tok::identifier)) { nextToken(); - if (FormatTok->is(tok::l_paren)) + if (FormatTok->is(tok::l_paren)) { parseParens(); - if (FormatTok->Previous && FormatTok->Previous->is(tok::identifier) && - FormatTok->is(tok::l_brace)) { -do { - nextToken(); -} while (FormatTok->isNot(tok::r_brace)); + } else if (FormatTok->is(tok::l_brace)) { nextToken(); +parseBracedList(); } // In case identifiers were removed by clang-tidy, what might follow is @@ -2989,6 +2992,8 @@ void UnwrappedLineParser::parseTryCatch() { keepAncestorBraces(); if (FormatTok->is(tok::l_brace)) { +if (HasCtorInitializer) + FormatTok->setFinalizedType(TT_FunctionLBrace); CompoundStatementIndenter Indenter(this, Style, Line->Level); parseBlock(); if (Style.BraceWrapping.BeforeCatch) diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp index 3e9638d9f3c56..487582ee4e10d 100644 --- a/clang/unittests/Format/TokenAnnotatorTest.cpp +++ b/clang/unittests/Format/TokenAnnotatorTest.cpp @@ -3164,6 +3164,21 @@ TEST_F(TokenAnnotatorTest, CppAltOperatorKeywords) { EXPECT_TOKEN(Tokens[1], tok::identifier, TT_StartOfName); } +TEST_F(TokenAnnotatorTest, FunctionTryBlock) { + auto Tokens = + annotate("Ctor::Ctor(int x, int y) try\n" + ": foo{[]() -> std::string { return {}; }(), x}, bar{y} {\n" + "} catch (...) {\n" + "}"); + ASSERT_EQ(Tokens.size(), 47u); + EXPECT_TOKEN(Tokens[11], tok::colon, TT_CtorInitializerColon); + EXPECT_TOKEN(Tokens[14], tok::l_square, TT_LambdaLSquare); + EXPECT_TOKEN(Tokens[18], tok::arrow, TT_TrailingReturnArrow); + EXPECT_TOKEN(Tokens[22], tok::l_brace, TT_LambdaLBrace); + EXPECT_TOKEN(Tokens[33], tok::comma, TT_CtorInitializerComma); + EXPECT_TOKEN(Tokens[38], tok::l_brace, TT_FunctionLBrace); +} + } // namespace } // namespace format } // namespace clang >From 733592d7cebd0b54ad9b08b506ab971f4549d7f0 Mon Sep 17 00:00:00 2001 From: Owen Pan Date: Tue, 18 Jun 2024 17:53:51 -0700 Subject: [PATCH 2/2] Tweak the test case. --- clang/unittests/Format/TokenAnnotatorTest.cpp | 15 --- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp index 487582ee4e10d..3735316dc3478 100644 --- a/clang/unittests/Format/TokenAnnotatorTest.cpp +++ b/clang/unittests/Format/TokenAnnotatorTest.cpp @@ -3166,17 +3166,18 @@ TEST_F(TokenAnnotatorTest, CppAltOperatorKeywords) { TEST_F(TokenAnnotatorTest, FunctionTryBlock) { auto Tokens = - annotate("Ctor::Ctor(int x, int y) try\n" - ": foo{[]() -> std::string { return {}; }(), x}, bar{y} {\n" + annotate("Foo::Foo(int x, int y) try\n" + ": foo{[] -> std::string { return {}; }(), x}, bar{y} {\n" "} catch (...) {\n" "}"); - ASSERT_EQ(Tokens.size(), 47u); + ASSERT_EQ(Tokens.size(), 45u); + EXPECT_TOKEN(Tokens[2], tok::identifier, TT_CtorDtorDeclName); EXPECT_TOKEN(Tokens[11], tok::colon, TT_CtorInitializerColon); EXPECT_TOKEN(Tokens[14], tok::l_square, TT_LambdaLSquare); - EXPECT_TOKEN(Tokens[18], tok::arrow, TT_TrailingReturnArrow); - EXPECT_TOKEN(Tokens[22], tok::l_brace, TT_LambdaLBrace); - EXPECT_TOKEN(Tokens[33], tok::comma,
[clang] [clang-format] Handle function try block with ctor-initializer (PR #95878)
https://github.com/HazardyKnusperkeks approved this pull request. https://github.com/llvm/llvm-project/pull/95878 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Handle function try block with ctor-initializer (PR #95878)
https://github.com/mydeveloperday approved this pull request. https://github.com/llvm/llvm-project/pull/95878 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Handle function try block with ctor-initializer (PR #95878)
llvmbot wrote: @llvm/pr-subscribers-clang-format Author: Owen Pan (owenca) Changes Fixes #58987. Fixes #95679. --- Full diff: https://github.com/llvm/llvm-project/pull/95878.diff 2 Files Affected: - (modified) clang/lib/Format/UnwrappedLineParser.cpp (+11-6) - (modified) clang/unittests/Format/TokenAnnotatorTest.cpp (+15) ``diff diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index df5bb757a99ec..ce877ac2bb9ef 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -2955,9 +2955,15 @@ void UnwrappedLineParser::parseTryCatch() { assert(FormatTok->isOneOf(tok::kw_try, tok::kw___try) && "'try' expected"); nextToken(); bool NeedsUnwrappedLine = false; + bool HasCtorInitializer = false; if (FormatTok->is(tok::colon)) { +auto *Colon = FormatTok; // We are in a function try block, what comes is an initializer list. nextToken(); +if (FormatTok->is(tok::identifier)) { + HasCtorInitializer = true; + Colon->setFinalizedType(TT_CtorInitializerColon); +} // In case identifiers were removed by clang-tidy, what might follow is // multiple commas in sequence - before the first identifier. @@ -2966,14 +2972,11 @@ void UnwrappedLineParser::parseTryCatch() { while (FormatTok->is(tok::identifier)) { nextToken(); - if (FormatTok->is(tok::l_paren)) + if (FormatTok->is(tok::l_paren)) { parseParens(); - if (FormatTok->Previous && FormatTok->Previous->is(tok::identifier) && - FormatTok->is(tok::l_brace)) { -do { - nextToken(); -} while (FormatTok->isNot(tok::r_brace)); + } else if (FormatTok->is(tok::l_brace)) { nextToken(); +parseBracedList(); } // In case identifiers were removed by clang-tidy, what might follow is @@ -2989,6 +2992,8 @@ void UnwrappedLineParser::parseTryCatch() { keepAncestorBraces(); if (FormatTok->is(tok::l_brace)) { +if (HasCtorInitializer) + FormatTok->setFinalizedType(TT_FunctionLBrace); CompoundStatementIndenter Indenter(this, Style, Line->Level); parseBlock(); if (Style.BraceWrapping.BeforeCatch) diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp index 3e9638d9f3c56..487582ee4e10d 100644 --- a/clang/unittests/Format/TokenAnnotatorTest.cpp +++ b/clang/unittests/Format/TokenAnnotatorTest.cpp @@ -3164,6 +3164,21 @@ TEST_F(TokenAnnotatorTest, CppAltOperatorKeywords) { EXPECT_TOKEN(Tokens[1], tok::identifier, TT_StartOfName); } +TEST_F(TokenAnnotatorTest, FunctionTryBlock) { + auto Tokens = + annotate("Ctor::Ctor(int x, int y) try\n" + ": foo{[]() -> std::string { return {}; }(), x}, bar{y} {\n" + "} catch (...) {\n" + "}"); + ASSERT_EQ(Tokens.size(), 47u); + EXPECT_TOKEN(Tokens[11], tok::colon, TT_CtorInitializerColon); + EXPECT_TOKEN(Tokens[14], tok::l_square, TT_LambdaLSquare); + EXPECT_TOKEN(Tokens[18], tok::arrow, TT_TrailingReturnArrow); + EXPECT_TOKEN(Tokens[22], tok::l_brace, TT_LambdaLBrace); + EXPECT_TOKEN(Tokens[33], tok::comma, TT_CtorInitializerComma); + EXPECT_TOKEN(Tokens[38], tok::l_brace, TT_FunctionLBrace); +} + } // namespace } // namespace format } // namespace clang `` https://github.com/llvm/llvm-project/pull/95878 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [clang-format] Handle function try block with ctor-initializer (PR #95878)
https://github.com/owenca created https://github.com/llvm/llvm-project/pull/95878 Fixes #58987. Fixes #95679. >From 299924c9f9485e7a784ffedcb6ec4fbccf5ad6f7 Mon Sep 17 00:00:00 2001 From: Owen Pan Date: Mon, 17 Jun 2024 21:13:10 -0700 Subject: [PATCH] [clang-format] Handle function try block with ctor-initializer Fixes #58987. Fixes #95679. --- clang/lib/Format/UnwrappedLineParser.cpp | 17 +++-- clang/unittests/Format/TokenAnnotatorTest.cpp | 15 +++ 2 files changed, 26 insertions(+), 6 deletions(-) diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index df5bb757a99ec..ce877ac2bb9ef 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -2955,9 +2955,15 @@ void UnwrappedLineParser::parseTryCatch() { assert(FormatTok->isOneOf(tok::kw_try, tok::kw___try) && "'try' expected"); nextToken(); bool NeedsUnwrappedLine = false; + bool HasCtorInitializer = false; if (FormatTok->is(tok::colon)) { +auto *Colon = FormatTok; // We are in a function try block, what comes is an initializer list. nextToken(); +if (FormatTok->is(tok::identifier)) { + HasCtorInitializer = true; + Colon->setFinalizedType(TT_CtorInitializerColon); +} // In case identifiers were removed by clang-tidy, what might follow is // multiple commas in sequence - before the first identifier. @@ -2966,14 +2972,11 @@ void UnwrappedLineParser::parseTryCatch() { while (FormatTok->is(tok::identifier)) { nextToken(); - if (FormatTok->is(tok::l_paren)) + if (FormatTok->is(tok::l_paren)) { parseParens(); - if (FormatTok->Previous && FormatTok->Previous->is(tok::identifier) && - FormatTok->is(tok::l_brace)) { -do { - nextToken(); -} while (FormatTok->isNot(tok::r_brace)); + } else if (FormatTok->is(tok::l_brace)) { nextToken(); +parseBracedList(); } // In case identifiers were removed by clang-tidy, what might follow is @@ -2989,6 +2992,8 @@ void UnwrappedLineParser::parseTryCatch() { keepAncestorBraces(); if (FormatTok->is(tok::l_brace)) { +if (HasCtorInitializer) + FormatTok->setFinalizedType(TT_FunctionLBrace); CompoundStatementIndenter Indenter(this, Style, Line->Level); parseBlock(); if (Style.BraceWrapping.BeforeCatch) diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp index 3e9638d9f3c56..487582ee4e10d 100644 --- a/clang/unittests/Format/TokenAnnotatorTest.cpp +++ b/clang/unittests/Format/TokenAnnotatorTest.cpp @@ -3164,6 +3164,21 @@ TEST_F(TokenAnnotatorTest, CppAltOperatorKeywords) { EXPECT_TOKEN(Tokens[1], tok::identifier, TT_StartOfName); } +TEST_F(TokenAnnotatorTest, FunctionTryBlock) { + auto Tokens = + annotate("Ctor::Ctor(int x, int y) try\n" + ": foo{[]() -> std::string { return {}; }(), x}, bar{y} {\n" + "} catch (...) {\n" + "}"); + ASSERT_EQ(Tokens.size(), 47u); + EXPECT_TOKEN(Tokens[11], tok::colon, TT_CtorInitializerColon); + EXPECT_TOKEN(Tokens[14], tok::l_square, TT_LambdaLSquare); + EXPECT_TOKEN(Tokens[18], tok::arrow, TT_TrailingReturnArrow); + EXPECT_TOKEN(Tokens[22], tok::l_brace, TT_LambdaLBrace); + EXPECT_TOKEN(Tokens[33], tok::comma, TT_CtorInitializerComma); + EXPECT_TOKEN(Tokens[38], tok::l_brace, TT_FunctionLBrace); +} + } // namespace } // namespace format } // namespace clang ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits