[libc] [openmp] [llvm] [mlir] [clang-tools-extra] [lldb] [libcxx] [flang] [clang] [compiler-rt] [libc++][span] P2821R5: `span.at()` (PR #74994)

2023-12-25 Thread Hristo Hristov via cfe-commits

https://github.com/H-G-Hristov edited 
https://github.com/llvm/llvm-project/pull/74994
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libc] [openmp] [llvm] [mlir] [clang-tools-extra] [lldb] [libcxx] [flang] [lld] [clang] [compiler-rt] [libc++][memory] P1132R8: `out_ptr` - a scalable output pointer abstraction (PR #73618)

2023-12-25 Thread Hristo Hristov via cfe-commits

https://github.com/H-G-Hristov edited 
https://github.com/llvm/llvm-project/pull/73618
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] [Clang][IR] add TBAA metadata on pointer, union and array types. (PR #75177)

2023-12-25 Thread Bushev Dmitry via cfe-commits

dybv-sc wrote:

> (As usual, please make any LLVM changes separately from Clang changes, 
> especially if they affect IR design.)

I splitted commit into 2 parts for llvm and clang. Should I make separate PRs 
for them as well?

https://github.com/llvm/llvm-project/pull/75177
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Clang][IR] add TBAA metadata on pointer, union and array types. (PR #75177)

2023-12-25 Thread Bushev Dmitry via cfe-commits

dybv-sc wrote:

I made separate PR for llvm's part: 
https://github.com/llvm/llvm-project/pull/76356
It should me merged first, because clang's part depends on it.

https://github.com/llvm/llvm-project/pull/75177
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Reword apologetic Clang diagnostic messages (PR #76310)

2023-12-25 Thread Sam James via cfe-commits


@@ -9913,11 +9913,11 @@ def warn_new_dangling_initializer_list : Warning<
   "will be destroyed at the end of the full-expression">,
   InGroup;
 def warn_unsupported_lifetime_extension : Warning<
-  "sorry, lifetime extension of "
+  "lifetime extension of "
   "%select{temporary|backing array of initializer list}0 created "
-  "by aggregate initialization using default member initializer "
+  "by aggregate initialization using a default member initializer "
   "is not supported; lifetime of %select{temporary|backing array}0 "

thesamesam wrote:

Perhaps "is not yet supported" or similar. As noted at 
https://github.com/llvm/llvm-project/issues/61256#issuecomment-1477097827, the 
"sorry" kind of indicated that it was Clang's fault, rather than the code doing 
something wrong.

https://github.com/llvm/llvm-project/pull/76310
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] introduce a unused local non trival variable check (PR #76101)

2023-12-25 Thread Tyler Rockwood via cfe-commits

rockwotj wrote:

Changed 

https://github.com/llvm/llvm-project/pull/76101
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [RFC][RISCV] Support RISC-V Profiles in -march option (PR #76357)

2023-12-25 Thread Wang Pengcheng via cfe-commits

https://github.com/wangpc-pp created 
https://github.com/llvm/llvm-project/pull/76357

This PR implements the draft
https://github.com/riscv-non-isa/riscv-toolchain-conventions/pull/36.

Currently, we replace specified profile in `-march` with standard
arch string.

We may need to pass it to backend so that we can emit an ELF attr
proposed by
https://github.com/riscv-non-isa/riscv-elf-psabi-doc/pull/409.


>From f9d4a2be0f1e1b8815d2feaebdc918d501c776da Mon Sep 17 00:00:00 2001
From: wangpc 
Date: Mon, 25 Dec 2023 18:52:36 +0800
Subject: [PATCH] [RFC][RISCV] Support RISC-V Profiles in -march option

This PR implements the draft
https://github.com/riscv-non-isa/riscv-toolchain-conventions/pull/36.

Currently, we replace specified profile in `-march` with standard
arch string.

We may need to pass it to backend so that we can emit an ELF attr
proposed by
https://github.com/riscv-non-isa/riscv-elf-psabi-doc/pull/409.
---
 clang/lib/Driver/ToolChains/Arch/RISCV.cpp|  7 +-
 clang/test/Driver/riscv-profiles.c| 79 +++
 llvm/include/llvm/TargetParser/CMakeLists.txt |  1 +
 .../llvm/TargetParser/RISCVTargetParser.h |  1 +
 llvm/lib/Target/RISCV/RISCV.td|  6 ++
 llvm/lib/Target/RISCV/RISCVProfiles.td| 70 
 llvm/lib/TargetParser/RISCVTargetParser.cpp   | 24 ++
 llvm/utils/TableGen/RISCVTargetDefEmitter.cpp | 19 +
 8 files changed, 205 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/Driver/riscv-profiles.c
 create mode 100644 llvm/lib/Target/RISCV/RISCVProfiles.td

diff --git a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp 
b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
index 25b43cefce6b57..87ec51b89547c5 100644
--- a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
@@ -277,8 +277,11 @@ StringRef riscv::getRISCVArch(const llvm::opt::ArgList 
&Args,
   // instead of `rv{XLEN}gc` though they are (currently) equivalent.
 
   // 1. If `-march=` is specified, use it.
-  if (const Arg *A = Args.getLastArg(options::OPT_march_EQ))
-return A->getValue();
+  if (const Arg *A = Args.getLastArg(options::OPT_march_EQ)) {
+StringRef Value = A->getValue();
+StringRef MArchFromProfile = llvm::RISCV::getMArchFromProfile(Value);
+return MArchFromProfile.empty() ? Value : MArchFromProfile;
+  }
 
   // 2. Get march (isa string) based on `-mcpu=`
   if (const Arg *A = Args.getLastArg(options::OPT_mcpu_EQ)) {
diff --git a/clang/test/Driver/riscv-profiles.c 
b/clang/test/Driver/riscv-profiles.c
new file mode 100644
index 00..375d4fc10db6ca
--- /dev/null
+++ b/clang/test/Driver/riscv-profiles.c
@@ -0,0 +1,79 @@
+// RUN: %clang -### -c %s 2>&1 -march=RVI20U32 | FileCheck 
-check-prefix=RVI20U32 %s
+// RVI20U32: "-target-cpu" "generic-rv32"
+// RVI20U32: "-target-feature" "-a"
+// RVI20U32: "-target-feature" "-c"
+// RVI20U32: "-target-feature" "-d"
+// RVI20U32: "-target-feature" "-f"
+// RVI20U32: "-target-feature" "-m"
+// RVI20U32: "-target-abi" "ilp32"
+
+// RUN: %clang -### -c %s 2>&1 -march=RVI20U64 | FileCheck 
-check-prefix=RVI20U64 %s
+// RVI20U64: "-target-cpu" "generic-rv64"
+// RVI20U64: "-target-feature" "-a"
+// RVI20U64: "-target-feature" "-c"
+// RVI20U64: "-target-feature" "-d"
+// RVI20U64: "-target-feature" "-f"
+// RVI20U64: "-target-feature" "-m"
+// RVI20U64: "-target-abi" "lp64"
+
+// RUN: %clang -### -c %s 2>&1 -march=RVA20U64 | FileCheck 
-check-prefix=RVA20U64 %s
+// RVA20U64: "-target-cpu" "generic-rv64"
+// RVA20U64: "-target-feature" "+m"
+// RVA20U64: "-target-feature" "+a"
+// RVA20U64: "-target-feature" "+f"
+// RVA20U64: "-target-feature" "+d"
+// RVA20U64: "-target-feature" "+c"
+// RVA20U64: "-target-feature" "+zicsr"
+// RVA20U64: "-target-abi" "lp64d"
+
+// RUN: %clang -### -c %s 2>&1 -march=RVA20S64 | FileCheck 
-check-prefix=RVA20S64 %s
+// RVA20S64: "-target-cpu" "generic-rv64"
+// RVA20S64: "-target-feature" "+m"
+// RVA20S64: "-target-feature" "+a"
+// RVA20S64: "-target-feature" "+f"
+// RVA20S64: "-target-feature" "+d"
+// RVA20S64: "-target-feature" "+c"
+// RVA20S64: "-target-feature" "+zicsr"
+// RVA20S64: "-target-feature" "+zifencei"
+// RVA20S64: "-target-abi" "lp64d"
+
+// RUN: %clang -### -c %s 2>&1 -march=RVA22U64 | FileCheck 
-check-prefix=RVA22U64 %s
+// RVA22U64: "-target-cpu" "generic-rv64"
+// RVA22U64: "-target-feature" "+m"
+// RVA22U64: "-target-feature" "+a"
+// RVA22U64: "-target-feature" "+f"
+// RVA22U64: "-target-feature" "+d"
+// RVA22U64: "-target-feature" "+c"
+// RVA22U64: "-target-feature" "+zicbom"
+// RVA22U64: "-target-feature" "+zicbop"
+// RVA22U64: "-target-feature" "+zicboz"
+// RVA22U64: "-target-feature" "+zicsr"
+// RVA22U64: "-target-feature" "+zihintpause"
+// RVA22U64: "-target-feature" "+zfhmin" 
+// RVA22U64: "-target-feature" "+zba"
+// RVA22U64: "-target-feature" "+zbb"
+// RVA22U64: "-target-feature" "+zbs"
+// RVA22U64: "-target-feature" "+zkt"
+// RVA22U64: "-target-abi" "lp64d"
+
+// RUN: %

[clang] [llvm] [RFC][RISCV] Support RISC-V Profiles in -march option (PR #76357)

2023-12-25 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff 48f36c6e742e743e33f931536c653bf4e23568fb 
f9d4a2be0f1e1b8815d2feaebdc918d501c776da -- clang/test/Driver/riscv-profiles.c 
clang/lib/Driver/ToolChains/Arch/RISCV.cpp 
llvm/include/llvm/TargetParser/RISCVTargetParser.h 
llvm/lib/TargetParser/RISCVTargetParser.cpp 
llvm/utils/TableGen/RISCVTargetDefEmitter.cpp
``





View the diff from clang-format here.


``diff
diff --git a/llvm/utils/TableGen/RISCVTargetDefEmitter.cpp 
b/llvm/utils/TableGen/RISCVTargetDefEmitter.cpp
index 6cfb1708f3..6f177ed272 100644
--- a/llvm/utils/TableGen/RISCVTargetDefEmitter.cpp
+++ b/llvm/utils/TableGen/RISCVTargetDefEmitter.cpp
@@ -94,9 +94,9 @@ static void emitRISCVProfileDef(RecordKeeper &RK, raw_ostream 
&OS) {
   for (const Record *Rec : RK.getAllDerivedDefinitions("RISCVProfile")) {
 std::string MArch = getMArch(*Rec);
 
-OS << "PROFILE(" << Rec->getName() << ", " << "{\""
-   << Rec->getValueAsString("Name") << "\"}, " << "{\"" << MArch
-   << "\"})\n";
+OS << "PROFILE(" << Rec->getName() << ", "
+   << "{\"" << Rec->getValueAsString("Name") << "\"}, "
+   << "{\"" << MArch << "\"})\n";
   }
   OS << "\n#undef PROFILE\n";
 }

``




https://github.com/llvm/llvm-project/pull/76357
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [RFC][RISCV] Support RISC-V Profiles in -march option (PR #76357)

2023-12-25 Thread Wang Pengcheng via cfe-commits

https://github.com/wangpc-pp updated 
https://github.com/llvm/llvm-project/pull/76357

>From 806babf92282735c364b7ac88faa5256d04f2742 Mon Sep 17 00:00:00 2001
From: wangpc 
Date: Mon, 25 Dec 2023 18:52:36 +0800
Subject: [PATCH] [RFC][RISCV] Support RISC-V Profiles in -march option

This PR implements the draft
https://github.com/riscv-non-isa/riscv-toolchain-conventions/pull/36.

Currently, we replace specified profile in `-march` with standard
arch string.

We may need to pass it to backend so that we can emit an ELF attr
proposed by
https://github.com/riscv-non-isa/riscv-elf-psabi-doc/pull/409.
---
 clang/lib/Driver/ToolChains/Arch/RISCV.cpp|  7 +-
 clang/test/Driver/riscv-profiles.c| 79 +++
 llvm/include/llvm/TargetParser/CMakeLists.txt |  1 +
 .../llvm/TargetParser/RISCVTargetParser.h |  1 +
 llvm/lib/Target/RISCV/RISCV.td|  6 ++
 llvm/lib/Target/RISCV/RISCVProfiles.td| 70 
 llvm/lib/TargetParser/RISCVTargetParser.cpp   | 24 ++
 llvm/utils/TableGen/RISCVTargetDefEmitter.cpp | 19 +
 8 files changed, 205 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/Driver/riscv-profiles.c
 create mode 100644 llvm/lib/Target/RISCV/RISCVProfiles.td

diff --git a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp 
b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
index 25b43cefce6b57..87ec51b89547c5 100644
--- a/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
+++ b/clang/lib/Driver/ToolChains/Arch/RISCV.cpp
@@ -277,8 +277,11 @@ StringRef riscv::getRISCVArch(const llvm::opt::ArgList 
&Args,
   // instead of `rv{XLEN}gc` though they are (currently) equivalent.
 
   // 1. If `-march=` is specified, use it.
-  if (const Arg *A = Args.getLastArg(options::OPT_march_EQ))
-return A->getValue();
+  if (const Arg *A = Args.getLastArg(options::OPT_march_EQ)) {
+StringRef Value = A->getValue();
+StringRef MArchFromProfile = llvm::RISCV::getMArchFromProfile(Value);
+return MArchFromProfile.empty() ? Value : MArchFromProfile;
+  }
 
   // 2. Get march (isa string) based on `-mcpu=`
   if (const Arg *A = Args.getLastArg(options::OPT_mcpu_EQ)) {
diff --git a/clang/test/Driver/riscv-profiles.c 
b/clang/test/Driver/riscv-profiles.c
new file mode 100644
index 00..375d4fc10db6ca
--- /dev/null
+++ b/clang/test/Driver/riscv-profiles.c
@@ -0,0 +1,79 @@
+// RUN: %clang -### -c %s 2>&1 -march=RVI20U32 | FileCheck 
-check-prefix=RVI20U32 %s
+// RVI20U32: "-target-cpu" "generic-rv32"
+// RVI20U32: "-target-feature" "-a"
+// RVI20U32: "-target-feature" "-c"
+// RVI20U32: "-target-feature" "-d"
+// RVI20U32: "-target-feature" "-f"
+// RVI20U32: "-target-feature" "-m"
+// RVI20U32: "-target-abi" "ilp32"
+
+// RUN: %clang -### -c %s 2>&1 -march=RVI20U64 | FileCheck 
-check-prefix=RVI20U64 %s
+// RVI20U64: "-target-cpu" "generic-rv64"
+// RVI20U64: "-target-feature" "-a"
+// RVI20U64: "-target-feature" "-c"
+// RVI20U64: "-target-feature" "-d"
+// RVI20U64: "-target-feature" "-f"
+// RVI20U64: "-target-feature" "-m"
+// RVI20U64: "-target-abi" "lp64"
+
+// RUN: %clang -### -c %s 2>&1 -march=RVA20U64 | FileCheck 
-check-prefix=RVA20U64 %s
+// RVA20U64: "-target-cpu" "generic-rv64"
+// RVA20U64: "-target-feature" "+m"
+// RVA20U64: "-target-feature" "+a"
+// RVA20U64: "-target-feature" "+f"
+// RVA20U64: "-target-feature" "+d"
+// RVA20U64: "-target-feature" "+c"
+// RVA20U64: "-target-feature" "+zicsr"
+// RVA20U64: "-target-abi" "lp64d"
+
+// RUN: %clang -### -c %s 2>&1 -march=RVA20S64 | FileCheck 
-check-prefix=RVA20S64 %s
+// RVA20S64: "-target-cpu" "generic-rv64"
+// RVA20S64: "-target-feature" "+m"
+// RVA20S64: "-target-feature" "+a"
+// RVA20S64: "-target-feature" "+f"
+// RVA20S64: "-target-feature" "+d"
+// RVA20S64: "-target-feature" "+c"
+// RVA20S64: "-target-feature" "+zicsr"
+// RVA20S64: "-target-feature" "+zifencei"
+// RVA20S64: "-target-abi" "lp64d"
+
+// RUN: %clang -### -c %s 2>&1 -march=RVA22U64 | FileCheck 
-check-prefix=RVA22U64 %s
+// RVA22U64: "-target-cpu" "generic-rv64"
+// RVA22U64: "-target-feature" "+m"
+// RVA22U64: "-target-feature" "+a"
+// RVA22U64: "-target-feature" "+f"
+// RVA22U64: "-target-feature" "+d"
+// RVA22U64: "-target-feature" "+c"
+// RVA22U64: "-target-feature" "+zicbom"
+// RVA22U64: "-target-feature" "+zicbop"
+// RVA22U64: "-target-feature" "+zicboz"
+// RVA22U64: "-target-feature" "+zicsr"
+// RVA22U64: "-target-feature" "+zihintpause"
+// RVA22U64: "-target-feature" "+zfhmin" 
+// RVA22U64: "-target-feature" "+zba"
+// RVA22U64: "-target-feature" "+zbb"
+// RVA22U64: "-target-feature" "+zbs"
+// RVA22U64: "-target-feature" "+zkt"
+// RVA22U64: "-target-abi" "lp64d"
+
+// RUN: %clang -### -c %s 2>&1 -march=RVA22S64 | FileCheck 
-check-prefix=RVA22S64 %s
+// RVA22S64: "-target-cpu" "generic-rv64"
+// RVA22S64: "-target-feature" "+m"
+// RVA22S64: "-target-feature" "+a"
+// RVA22S64: "-target-feature" "+f"
+// RVA22S64: "-target-feature" "+d"
+// RVA22S64: "-target-feature" "+c"
+// RVA22S64: "-ta

[clang-tools-extra] 952d344 - [clang-tidy] introduce a unused local non trival variable check (#76101)

2023-12-25 Thread via cfe-commits

Author: Tyler Rockwood
Date: 2023-12-25T12:19:53+01:00
New Revision: 952d344f3e25a352bc5f2f1f5f611e96bd7acb91

URL: 
https://github.com/llvm/llvm-project/commit/952d344f3e25a352bc5f2f1f5f611e96bd7acb91
DIFF: 
https://github.com/llvm/llvm-project/commit/952d344f3e25a352bc5f2f1f5f611e96bd7acb91.diff

LOG: [clang-tidy] introduce a unused local non trival variable check (#76101)

Introduce a new (off by default) clang tidy check to ensure that
variables of a specific type are always used even if -Wunused-variables
wouldn't generate a warning.

This check has already caught a couple of different bugs on the codebase
I work on, where not handling a future means that lifetimes may not be
kept alive properly as an async chunk of code may run after a class has
been destroyed, etc.

I would like to upstream it because I believe there could be other
applications of this check that would be useful in different contexts.

-

Signed-off-by: Tyler Rockwood 

Added: 
clang-tools-extra/clang-tidy/bugprone/UnusedLocalNonTrivialVariableCheck.cpp
clang-tools-extra/clang-tidy/bugprone/UnusedLocalNonTrivialVariableCheck.h

clang-tools-extra/docs/clang-tidy/checks/bugprone/unused-local-non-trivial-variable.rst

clang-tools-extra/test/clang-tidy/checkers/bugprone/unused-local-non-trivial-variable.cpp

Modified: 
clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/docs/clang-tidy/checks/list.rst

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp 
b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
index 7a910037368c83..435cb1e3fbcff3 100644
--- a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
@@ -83,6 +83,7 @@
 #include "UnhandledSelfAssignmentCheck.h"
 #include "UniquePtrArrayMismatchCheck.h"
 #include "UnsafeFunctionsCheck.h"
+#include "UnusedLocalNonTrivialVariableCheck.h"
 #include "UnusedRaiiCheck.h"
 #include "UnusedReturnValueCheck.h"
 #include "UseAfterMoveCheck.h"
@@ -235,6 +236,8 @@ class BugproneModule : public ClangTidyModule {
 "bugprone-unique-ptr-array-mismatch");
 CheckFactories.registerCheck(
 "bugprone-unsafe-functions");
+CheckFactories.registerCheck(
+"bugprone-unused-local-non-trivial-variable");
 CheckFactories.registerCheck("bugprone-unused-raii");
 CheckFactories.registerCheck(
 "bugprone-unused-return-value");

diff  --git a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
index d443fd8d1452f1..70e7fbc7ec0c14 100644
--- a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
@@ -79,6 +79,7 @@ add_clang_library(clangTidyBugproneModule
   UnhandledSelfAssignmentCheck.cpp
   UniquePtrArrayMismatchCheck.cpp
   UnsafeFunctionsCheck.cpp
+  UnusedLocalNonTrivialVariableCheck.cpp
   UnusedRaiiCheck.cpp
   UnusedReturnValueCheck.cpp
   UseAfterMoveCheck.cpp

diff  --git 
a/clang-tools-extra/clang-tidy/bugprone/UnusedLocalNonTrivialVariableCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/UnusedLocalNonTrivialVariableCheck.cpp
new file mode 100644
index 00..ee7f365320ff9c
--- /dev/null
+++ 
b/clang-tools-extra/clang-tidy/bugprone/UnusedLocalNonTrivialVariableCheck.cpp
@@ -0,0 +1,91 @@
+//===--- UnusedLocalNonTrivialVariableCheck.cpp - clang-tidy 
--===//
+//
+// 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 "UnusedLocalNonTrivialVariableCheck.h"
+#include "../utils/Matchers.h"
+#include "../utils/OptionsUtils.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/ASTTypeTraits.h"
+#include "clang/AST/Type.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/ASTMatchers/ASTMatchersMacros.h"
+
+using namespace clang::ast_matchers;
+using namespace clang::tidy::matchers;
+
+namespace clang::tidy::bugprone {
+
+namespace {
+static constexpr StringRef DefaultIncludeTypeRegex =
+"::std::.*mutex;::std::future;::std::basic_string;::std::basic_regex;"
+"::std::base_istringstream;::std::base_stringstream;::std::bitset;"
+"::std::filesystem::path";
+
+AST_MATCHER(VarDecl, isLocalVarDecl) { return Node.isLocalVarDecl(); }
+AST_MATCHER(VarDecl, isReferenced) { return Node.isReferenced(); }
+AST_MATCHER(Type, isReferenceType) { return Node.isReferenceType(); }
+AST_MATCHER(QualType, isTrivial) {
+  return Node.isTrivialType(Finder->getASTContext()) ||
+

[clang-tools-extra] [clang-tidy] introduce a unused local non trival variable check (PR #76101)

2023-12-25 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL closed 
https://github.com/llvm/llvm-project/pull/76101
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[libcxx] [mlir] [polly] [llvm] [lld] [clang-tools-extra] [clang] [compiler-rt] [emacs][lsp][tblgen] add tblgen-lsp-server support for emacs lsp-mode (PR #76337)

2023-12-25 Thread via cfe-commits

https://github.com/mgcsysinfcat updated 
https://github.com/llvm/llvm-project/pull/76337

>From b530c6dfc9d2e098b3634ea720f0b0bfde0d411f Mon Sep 17 00:00:00 2001
From: mgcsysinfcat 
Date: Sun, 24 Dec 2023 23:00:00 +0800
Subject: [PATCH] add tblgen-lsp-server support for lsp-mode

---
 mlir/utils/emacs/tblgen-lsp.el | 45 ++
 1 file changed, 45 insertions(+)
 create mode 100644 mlir/utils/emacs/tblgen-lsp.el

diff --git a/mlir/utils/emacs/tblgen-lsp.el b/mlir/utils/emacs/tblgen-lsp.el
new file mode 100644
index 00..607459549193a1
--- /dev/null
+++ b/mlir/utils/emacs/tblgen-lsp.el
@@ -0,0 +1,45 @@
+;;; tblgen-lsp.el --- Description -*- lexical-binding: t; -*-
+;;
+;; Package-Requires: ((emacs "24.3"))
+;;
+;; This file is not part of GNU Emacs.
+;;
+;;; Commentary:
+;;  LSP clinet to use with `tablegen-mode' that uses `tblgen-lsp-server' or any
+;;  user made compatible server.
+;;
+;;
+;;; Code:
+
+
+(defgroup lsp-tblgen nil
+  "LSP support for Tablegen."
+  :group 'lsp-mode
+  :link '(url-link "https://mlir.llvm.org/docs/Tools/MLIRLSP/";))
+
+(defcustom lsp-tblgen-server-executable "tblgen-lsp-server"
+  "Command to start the mlir language server."
+  :group 'lsp-tblgen
+  :risky t
+  :type 'file)
+
+
+(defcustom lsp-tblgen-server-args ""
+  "Args of LSP client for TableGen "
+  :group 'lsp-tblgen
+  :risky t
+  :type 'file)
+
+(defun lsp-tblgen-setup ()
+  "Setup the LSP client for TableGen."
+  (add-to-list 'lsp-language-id-configuration '(tablegen-mode . "tablegen"))
+
+  (lsp-register-client
+   (make-lsp-client
+:new-connection (lsp-stdio-connection (lambda () (cons 
lsp-tblgen-server-executable lsp-tblgen-server-args))); (concat 
"--tablegen-compilation-database=" lsp-tblgen-compilation-database-location) )))
+:activation-fn (lsp-activate-on "tablegen")
+:priority -1
+:server-id 'tblgen-lsp-server)))
+
+(provide 'tblgen-lsp)
+;;; tblgen-lsp.el ends here

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] 007ed0d - [clang-tidy][NFC] Enable exceptions in test for bugprone-unused-local-non-trivial-variable

2023-12-25 Thread Piotr Zegar via cfe-commits

Author: Piotr Zegar
Date: 2023-12-25T11:30:02Z
New Revision: 007ed0dccd6a3d19f331eb7cd91438d792754439

URL: 
https://github.com/llvm/llvm-project/commit/007ed0dccd6a3d19f331eb7cd91438d792754439
DIFF: 
https://github.com/llvm/llvm-project/commit/007ed0dccd6a3d19f331eb7cd91438d792754439.diff

LOG: [clang-tidy][NFC] Enable exceptions in test for 
bugprone-unused-local-non-trivial-variable

Added -fexceptions switch to test.
It were missing in #76101.

Added: 


Modified: 

clang-tools-extra/test/clang-tidy/checkers/bugprone/unused-local-non-trivial-variable.cpp

Removed: 




diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone/unused-local-non-trivial-variable.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/unused-local-non-trivial-variable.cpp
index 9bbf3d116885f3..49000203716416 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone/unused-local-non-trivial-variable.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/unused-local-non-trivial-variable.cpp
@@ -1,6 +1,6 @@
 // RUN: %check_clang_tidy -std=c++17-or-later %s 
bugprone-unused-local-non-trivial-variable %t -- \
 // RUN:   -config="{CheckOptions: 
{bugprone-unused-local-non-trivial-variable.IncludeTypes: 
'::async::Future;::async::Foo.*', 
bugprone-unused-local-non-trivial-variable.ExcludeTypes: '::async::FooBar'}}"
-
+// RUN:   -- -fexceptions
 
 namespace async {
 template 
@@ -19,7 +19,7 @@ class Ptr {
 
 template
 class Future {
-public:
+public:
 T get() {
 return Pending;
 }



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] 37fc9c6 - [clang-tidy][NFC] Enable exceptions in test for bugprone-unused-local-non-trivial-variable

2023-12-25 Thread Piotr Zegar via cfe-commits

Author: Piotr Zegar
Date: 2023-12-25T11:38:06Z
New Revision: 37fc9c6a4227b1736cc643eb95636d9f7ec30190

URL: 
https://github.com/llvm/llvm-project/commit/37fc9c6a4227b1736cc643eb95636d9f7ec30190
DIFF: 
https://github.com/llvm/llvm-project/commit/37fc9c6a4227b1736cc643eb95636d9f7ec30190.diff

LOG: [clang-tidy][NFC] Enable exceptions in test for 
bugprone-unused-local-non-trivial-variable

Added -fexceptions switch to test.
Added missing Fixes for #76101.

Added: 


Modified: 

clang-tools-extra/test/clang-tidy/checkers/bugprone/unused-local-non-trivial-variable.cpp

Removed: 




diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone/unused-local-non-trivial-variable.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/unused-local-non-trivial-variable.cpp
index 49000203716416..19f2344de4a650 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/bugprone/unused-local-non-trivial-variable.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/bugprone/unused-local-non-trivial-variable.cpp
@@ -1,5 +1,5 @@
 // RUN: %check_clang_tidy -std=c++17-or-later %s 
bugprone-unused-local-non-trivial-variable %t -- \
-// RUN:   -config="{CheckOptions: 
{bugprone-unused-local-non-trivial-variable.IncludeTypes: 
'::async::Future;::async::Foo.*', 
bugprone-unused-local-non-trivial-variable.ExcludeTypes: '::async::FooBar'}}"
+// RUN:   -config="{CheckOptions: 
{bugprone-unused-local-non-trivial-variable.IncludeTypes: 
'::async::Future;::async::Foo.*', 
bugprone-unused-local-non-trivial-variable.ExcludeTypes: '::async::FooBar'}}" \
 // RUN:   -- -fexceptions
 
 namespace async {



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] 9fba1d5 - [clang-tidy] Fixes for bugprone-unused-local-non-trivial-variable

2023-12-25 Thread Piotr Zegar via cfe-commits

Author: Piotr Zegar
Date: 2023-12-25T13:09:12Z
New Revision: 9fba1d5f3a52af0ae62f386d0c494bd9510fa845

URL: 
https://github.com/llvm/llvm-project/commit/9fba1d5f3a52af0ae62f386d0c494bd9510fa845
DIFF: 
https://github.com/llvm/llvm-project/commit/9fba1d5f3a52af0ae62f386d0c494bd9510fa845.diff

LOG: [clang-tidy] Fixes for bugprone-unused-local-non-trivial-variable

Fixed spelling of some classes in code and in documentation.
Fixes for #76101

Added: 


Modified: 
clang-tools-extra/clang-tidy/bugprone/UnusedLocalNonTrivialVariableCheck.cpp

clang-tools-extra/docs/clang-tidy/checks/bugprone/unused-local-non-trivial-variable.rst

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/bugprone/UnusedLocalNonTrivialVariableCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/UnusedLocalNonTrivialVariableCheck.cpp
index ee7f365320ff9c..1b763d291082b6 100644
--- 
a/clang-tools-extra/clang-tidy/bugprone/UnusedLocalNonTrivialVariableCheck.cpp
+++ 
b/clang-tools-extra/clang-tidy/bugprone/UnusedLocalNonTrivialVariableCheck.cpp
@@ -24,7 +24,7 @@ namespace clang::tidy::bugprone {
 namespace {
 static constexpr StringRef DefaultIncludeTypeRegex =
 "::std::.*mutex;::std::future;::std::basic_string;::std::basic_regex;"
-"::std::base_istringstream;::std::base_stringstream;::std::bitset;"
+"::std::basic_istringstream;::std::basic_stringstream;::std::bitset;"
 "::std::filesystem::path";
 
 AST_MATCHER(VarDecl, isLocalVarDecl) { return Node.isLocalVarDecl(); }

diff  --git 
a/clang-tools-extra/docs/clang-tidy/checks/bugprone/unused-local-non-trivial-variable.rst
 
b/clang-tools-extra/docs/clang-tidy/checks/bugprone/unused-local-non-trivial-variable.rst
index 7a72a08d8f3aa8..7531f19f3ebc15 100644
--- 
a/clang-tools-extra/docs/clang-tidy/checks/bugprone/unused-local-non-trivial-variable.rst
+++ 
b/clang-tools-extra/docs/clang-tidy/checks/bugprone/unused-local-non-trivial-variable.rst
@@ -38,19 +38,18 @@ Options
 .. option:: IncludeTypes
 
Semicolon-separated list of regular expressions matching types of variables
-   to check. 
-   By default the following types are checked: 
+   to check. By default the following types are checked:
 
* `::std::.*mutex`
* `::std::future`
-   * `::std::string`
+   * `::std::basic_string`
* `::std::basic_regex`
* `::std::basic_istringstream`
* `::std::basic_stringstream`
* `::std::bitset`
-   * `::std::path`
+   * `::std::filesystem::path`
 
 .. option:: ExcludeTypes
 
-   A semicolon-separated list of regular expressions matching types that are 
+   A semicolon-separated list of regular expressions matching types that are
excluded from the `IncludeTypes` matches. By default it is an empty list.



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [flang][driver] Remove Fortain_main static library from linking stages (PR #75816)

2023-12-25 Thread via cfe-commits

https://github.com/kkwli edited https://github.com/llvm/llvm-project/pull/75816
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[flang] [clang] [flang][driver] Remove Fortain_main static library from linking stages (PR #75816)

2023-12-25 Thread via cfe-commits


@@ -163,6 +163,63 @@ forward compiler options to the frontend driver, 
`flang-new -fc1`.
 You can read more on the design of `clangDriver` in Clang's [Driver Design &
 Internals](https://clang.llvm.org/docs/DriverInternals.html).
 
+## Linker Driver
+When used as a linker, Flang's frontend driver assembles the command line for 
an
+external linker command (e.g., LLVM's `lld`) and invokes it to create the final
+executable by linking static and shared libraries together with all the
+translation units supplied as object files.
+
+By default, the Flang linker driver adds several libraries to the linker
+invocation to make sure that all entrypoints for program start
+(Fortran's program unit) and runtime routines can be resolved by the linker.
+
+An abridged example (only showing the Fortran specific linker flags, omission
+indicated by `[...]`) for such a linker invocation on a Linux system would look
+like this:
+
+```
+$ flang -v -o example example.o
+"/usr/bin/ld" [...] example.o [...] "--whole-archive" "-lFortran_main"
+"--no-whole-archive" "-lFortranRuntime" "-lFortranDecimal" [...]
+```
+
+The automatically added libraries are:
+
+* `Fortran_main`: Provides the main entry point `main` that then invokes
+  `_QQmain` with the Fortran program unit.  This library has a dependency to
+  the `FortranRuntime` library.
+* `FortranRuntime`: Provides most of the Flang runtime library.
+* `FortranDecimal`: Provides operations for decimal numbers.
+
+The default is that, when using Flang as the linker, one of the Fortran
+translation units provides the program unit and therefore it is assumed that
+Fortran is the main code part (calling into C/C++ routines via `BIND (C)`
+interfaces).  When composing the linker commandline, Flang uses
+`--whole-archive` and `--no-whole-archive` (Windows: `/WHOLEARCHIVE:`,
+Darwin & AIX: *not implemented yet*) to make sure that all for `Fortran_main`
+is processed by the linker.  This is done to issue a proper error message when
+multiple definitions of `main` occur.  This happens, for instance, when linking
+a code that has a Fortran program unit with a C/C++ code that also defines a
+`main` function.  A user may be required to explicitly provide the C++ runtime
+libraries at link time (e.g., via `-lstdc++` for STL)
+
+If the code is C/C++ based and invokes Fortran routines, one can either use 
Clang
+or Flang as the linker driver.  If Clang is used, it will automatically all
+required runtime libraries needed by C++ (e.g., for STL) to the linker 
invocation.
+In this case, one has to explicitly provide the Fortran runtime libraries
+`FortranRuntime` and/or `FortranDecimal`.  An alternative is to use Flang to 
link
+and use the `-fno-fortran-main` flag.  This flag removes
+`Fortran_main` from the linker stage and hence requires one of the C/C++
+translation units to provide a definition of the `main` function. In this case,
+it may be required to explicitly supply C++ runtime libraries as mentioned 
above.
+
+When creating shared or static libraries using Flang with -shared or -static

kkwli wrote:

```suggestion
When creating shared or static libraries using Flang with `-shared` or `-static`
```

https://github.com/llvm/llvm-project/pull/75816
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [flang] [flang][driver] Remove Fortain_main static library from linking stages (PR #75816)

2023-12-25 Thread via cfe-commits

https://github.com/kkwli approved this pull request.

LG. Thanks.


https://github.com/llvm/llvm-project/pull/75816
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Implement P2718R0 "Lifetime extension in range-based for loops" (PR #76361)

2023-12-25 Thread via cfe-commits

https://github.com/yronglin created 
https://github.com/llvm/llvm-project/pull/76361

 Implement P2718R0 "Lifetime extension in range-based for loops" 
(https://wg21.link/P2718R0)

Differential Revision: https://reviews.llvm.org/D153701

>From a2eee6194f710c53bc478d57838477d1bc912024 Mon Sep 17 00:00:00 2001
From: yronglin 
Date: Sun, 26 Nov 2023 22:52:03 +0800
Subject: [PATCH] [Clang] Implement P2718R0 "Lifetime extension in range-based
 for loops"

 Implement P2718R0 "Lifetime extension in range-based for loops" 
(https://wg21.link/P2718R0)

Differential Revision: https://reviews.llvm.org/D153701
---
 clang/include/clang/Parse/Parser.h|   2 +-
 clang/include/clang/Sema/Sema.h   |  34 +-
 clang/lib/Parse/ParseDecl.cpp |  19 +
 clang/lib/Parse/ParseStmt.cpp |   2 +-
 clang/lib/Sema/SemaExpr.cpp   |  22 +-
 clang/lib/Sema/SemaExprCXX.cpp|  46 ++-
 clang/lib/Sema/SemaInit.cpp   |   4 +
 clang/lib/Sema/SemaStmt.cpp   |  10 +-
 .../test/AST/ast-dump-for-range-lifetime.cpp  | 355 ++
 clang/test/CXX/special/class.temporary/p6.cpp | 234 
 10 files changed, 700 insertions(+), 28 deletions(-)
 create mode 100644 clang/test/AST/ast-dump-for-range-lifetime.cpp

diff --git a/clang/include/clang/Parse/Parser.h 
b/clang/include/clang/Parse/Parser.h
index 2dbe090bd0932f..a467ff6157962c 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -2377,7 +2377,7 @@ class Parser : public CodeCompletionHandler {
   struct ForRangeInit {
 SourceLocation ColonLoc;
 ExprResult RangeExpr;
-
+SmallVector LifetimeExtendTemps;
 bool ParsedForRangeDecl() { return !ColonLoc.isInvalid(); }
   };
   struct ForRangeInfo : ForRangeInit {
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 5e3b57ea33220b..250194f90d503c 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -1338,6 +1338,12 @@ class Sema final {
 /// context not already known to be immediately invoked.
 llvm::SmallPtrSet ReferenceToConsteval;
 
+/// P2718R0 - Lifetime extension in range-based for loops.
+/// MaterializeTemporaryExprs in for-range-init expression which need to
+/// extend lifetime. Add MaterializeTemporaryExpr* if the value of
+/// IsInLifetimeExtendingContext is true.
+SmallVector ForRangeLifetimeExtendTemps;
+
 /// \brief Describes whether we are in an expression constext which we have
 /// to handle differently.
 enum ExpressionKind {
@@ -1357,6 +1363,19 @@ class Sema final {
 // VLAs).
 bool InConditionallyConstantEvaluateContext = false;
 
+/// Whether we are currently in a context in which temporaries must be
+/// lifetime-extended (Eg. in a for-range initializer).
+bool IsInLifetimeExtendingContext = false;
+
+/// Whether we should materialize temporaries in discarded expressions.
+///
+/// [C++23][class.temporary]/p2.6 when a prvalue that has type other than 
cv
+/// void appears as a discarded-value expression ([expr.context]).
+///
+/// We do not materialize temporaries by default in order to avoid creating
+/// unnecessary temporary objects.
+bool MaterializePRValueInDiscardedExpression = false;
+
 // When evaluating immediate functions in the initializer of a default
 // argument or default member initializer, this is the declaration whose
 // default initializer is being evaluated and the location of the call
@@ -5215,7 +5234,8 @@ class Sema final {
   Stmt *LoopVar,
   SourceLocation ColonLoc, Expr *Collection,
   SourceLocation RParenLoc,
-  BuildForRangeKind Kind);
+  BuildForRangeKind Kind,
+  ArrayRef 
LifetimeExtendTemps = {});
   StmtResult BuildCXXForRangeStmt(SourceLocation ForLoc,
   SourceLocation CoawaitLoc,
   Stmt *InitStmt,
@@ -9956,6 +9976,18 @@ class Sema final {
 return currentEvaluationContext().isImmediateFunctionContext();
   }
 
+  bool isInLifetimeExtendingContext() const {
+assert(!ExprEvalContexts.empty() &&
+   "Must be in an expression evaluation context");
+return ExprEvalContexts.back().IsInLifetimeExtendingContext;
+  }
+
+  bool ShouldMaterializePRValueInDiscardedExpression() const {
+assert(!ExprEvalContexts.empty() &&
+   "Must be in an expression evaluation context");
+return ExprEvalContexts.back().MaterializePRValueInDiscardedExpression;
+  }
+
   bool isCheckingDefaultArgumentOrInitializer() const {
 const ExpressionEvaluationContextRecord &Ctx = currentEvaluationContext();
 return (Ctx.Context ==
diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Par

[clang] [Clang] Implement P2718R0 "Lifetime extension in range-based for loops" (PR #76361)

2023-12-25 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (yronglin)


Changes

 Implement P2718R0 "Lifetime extension in range-based for loops" 
(https://wg21.link/P2718R0)

Differential Revision: https://reviews.llvm.org/D153701

---

Patch is 43.09 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/76361.diff


10 Files Affected:

- (modified) clang/include/clang/Parse/Parser.h (+1-1) 
- (modified) clang/include/clang/Sema/Sema.h (+33-1) 
- (modified) clang/lib/Parse/ParseDecl.cpp (+19) 
- (modified) clang/lib/Parse/ParseStmt.cpp (+1-1) 
- (modified) clang/lib/Sema/SemaExpr.cpp (+18-4) 
- (modified) clang/lib/Sema/SemaExprCXX.cpp (+26-20) 
- (modified) clang/lib/Sema/SemaInit.cpp (+4) 
- (modified) clang/lib/Sema/SemaStmt.cpp (+9-1) 
- (added) clang/test/AST/ast-dump-for-range-lifetime.cpp (+355) 
- (modified) clang/test/CXX/special/class.temporary/p6.cpp (+234) 


``diff
diff --git a/clang/include/clang/Parse/Parser.h 
b/clang/include/clang/Parse/Parser.h
index 2dbe090bd0932f..a467ff6157962c 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -2377,7 +2377,7 @@ class Parser : public CodeCompletionHandler {
   struct ForRangeInit {
 SourceLocation ColonLoc;
 ExprResult RangeExpr;
-
+SmallVector LifetimeExtendTemps;
 bool ParsedForRangeDecl() { return !ColonLoc.isInvalid(); }
   };
   struct ForRangeInfo : ForRangeInit {
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 5e3b57ea33220b..250194f90d503c 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -1338,6 +1338,12 @@ class Sema final {
 /// context not already known to be immediately invoked.
 llvm::SmallPtrSet ReferenceToConsteval;
 
+/// P2718R0 - Lifetime extension in range-based for loops.
+/// MaterializeTemporaryExprs in for-range-init expression which need to
+/// extend lifetime. Add MaterializeTemporaryExpr* if the value of
+/// IsInLifetimeExtendingContext is true.
+SmallVector ForRangeLifetimeExtendTemps;
+
 /// \brief Describes whether we are in an expression constext which we have
 /// to handle differently.
 enum ExpressionKind {
@@ -1357,6 +1363,19 @@ class Sema final {
 // VLAs).
 bool InConditionallyConstantEvaluateContext = false;
 
+/// Whether we are currently in a context in which temporaries must be
+/// lifetime-extended (Eg. in a for-range initializer).
+bool IsInLifetimeExtendingContext = false;
+
+/// Whether we should materialize temporaries in discarded expressions.
+///
+/// [C++23][class.temporary]/p2.6 when a prvalue that has type other than 
cv
+/// void appears as a discarded-value expression ([expr.context]).
+///
+/// We do not materialize temporaries by default in order to avoid creating
+/// unnecessary temporary objects.
+bool MaterializePRValueInDiscardedExpression = false;
+
 // When evaluating immediate functions in the initializer of a default
 // argument or default member initializer, this is the declaration whose
 // default initializer is being evaluated and the location of the call
@@ -5215,7 +5234,8 @@ class Sema final {
   Stmt *LoopVar,
   SourceLocation ColonLoc, Expr *Collection,
   SourceLocation RParenLoc,
-  BuildForRangeKind Kind);
+  BuildForRangeKind Kind,
+  ArrayRef 
LifetimeExtendTemps = {});
   StmtResult BuildCXXForRangeStmt(SourceLocation ForLoc,
   SourceLocation CoawaitLoc,
   Stmt *InitStmt,
@@ -9956,6 +9976,18 @@ class Sema final {
 return currentEvaluationContext().isImmediateFunctionContext();
   }
 
+  bool isInLifetimeExtendingContext() const {
+assert(!ExprEvalContexts.empty() &&
+   "Must be in an expression evaluation context");
+return ExprEvalContexts.back().IsInLifetimeExtendingContext;
+  }
+
+  bool ShouldMaterializePRValueInDiscardedExpression() const {
+assert(!ExprEvalContexts.empty() &&
+   "Must be in an expression evaluation context");
+return ExprEvalContexts.back().MaterializePRValueInDiscardedExpression;
+  }
+
   bool isCheckingDefaultArgumentOrInitializer() const {
 const ExpressionEvaluationContextRecord &Ctx = currentEvaluationContext();
 return (Ctx.Context ==
diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp
index ed006f9d67de45..8b809aa9c3df26 100644
--- a/clang/lib/Parse/ParseDecl.cpp
+++ b/clang/lib/Parse/ParseDecl.cpp
@@ -2312,12 +2312,31 @@ Parser::DeclGroupPtrTy 
Parser::ParseDeclGroup(ParsingDeclSpec &DS,
 bool IsForRangeLoop = false;
 if (TryConsumeToken(tok::colon, FRI->ColonLoc)) {
   IsForRangeLoop = true;
+  EnterExpressionEvaluationCo

[clang] [Clang] Implement P2718R0 "Lifetime extension in range-based for loops" (PR #76361)

2023-12-25 Thread via cfe-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff 6452395561eaae59e38f1df84f5413dffdb9169f 
a2eee6194f710c53bc478d57838477d1bc912024 -- 
clang/test/AST/ast-dump-for-range-lifetime.cpp 
clang/include/clang/Parse/Parser.h clang/include/clang/Sema/Sema.h 
clang/lib/Parse/ParseDecl.cpp clang/lib/Parse/ParseStmt.cpp 
clang/lib/Sema/SemaExpr.cpp clang/lib/Sema/SemaExprCXX.cpp 
clang/lib/Sema/SemaInit.cpp clang/lib/Sema/SemaStmt.cpp 
clang/test/CXX/special/class.temporary/p6.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 250194f90d..fc2b3881d5 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -5228,14 +5228,11 @@ public:
 BFRK_Check
   };
 
-  StmtResult ActOnCXXForRangeStmt(Scope *S, SourceLocation ForLoc,
-  SourceLocation CoawaitLoc,
-  Stmt *InitStmt,
-  Stmt *LoopVar,
-  SourceLocation ColonLoc, Expr *Collection,
-  SourceLocation RParenLoc,
-  BuildForRangeKind Kind,
-  ArrayRef 
LifetimeExtendTemps = {});
+  StmtResult ActOnCXXForRangeStmt(
+  Scope *S, SourceLocation ForLoc, SourceLocation CoawaitLoc,
+  Stmt *InitStmt, Stmt *LoopVar, SourceLocation ColonLoc, Expr *Collection,
+  SourceLocation RParenLoc, BuildForRangeKind Kind,
+  ArrayRef LifetimeExtendTemps = {});
   StmtResult BuildCXXForRangeStmt(SourceLocation ForLoc,
   SourceLocation CoawaitLoc,
   Stmt *InitStmt,
diff --git a/clang/lib/Parse/ParseStmt.cpp b/clang/lib/Parse/ParseStmt.cpp
index de883eb997..858b4f9fa9 100644
--- a/clang/lib/Parse/ParseStmt.cpp
+++ b/clang/lib/Parse/ParseStmt.cpp
@@ -2288,10 +2288,11 @@ StmtResult Parser::ParseForStatement(SourceLocation 
*TrailingElseLoc) {
 ForRangeStmt = Actions.ActOnCXXForRangeStmt(
 getCurScope(), ForLoc, CoawaitLoc, FirstPart.get(),
 ForRangeInfo.LoopVar.get(), ForRangeInfo.ColonLoc, 
CorrectedRange.get(),
-T.getCloseLocation(), Sema::BFRK_Build, 
ForRangeInfo.LifetimeExtendTemps);
+T.getCloseLocation(), Sema::BFRK_Build,
+ForRangeInfo.LifetimeExtendTemps);
 
-  // Similarly, we need to do the semantic analysis for a for-range
-  // statement immediately in order to close over temporaries correctly.
+// Similarly, we need to do the semantic analysis for a for-range
+// statement immediately in order to close over temporaries correctly.
   } else if (ForEach) {
 ForEachStmt = Actions.ActOnObjCForCollectionStmt(ForLoc,
  FirstPart.get(),
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 3590582fb5..8a44b2a704 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -8233,8 +8233,9 @@ ExprResult Sema::IgnoredValueConversions(Expr *E) {
 // unnecessary temporary objects. If we skip this step, IR generation is
 // able to synthesize the storage for itself in the aggregate case, and
 // adding the extra node to the AST is just clutter.
-if (ShouldMaterializePRValueInDiscardedExpression() && 
getLangOpts().CPlusPlus17 &&
-E->isPRValue() && !E->getType()->isVoidType()) {
+if (ShouldMaterializePRValueInDiscardedExpression() &&
+getLangOpts().CPlusPlus17 && E->isPRValue() &&
+!E->getType()->isVoidType()) {
   ExprResult Res = TemporaryMaterializationConversion(E);
   if (Res.isInvalid())
 return E;
diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index 759453f319..f69a8a168f 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -2483,12 +2483,11 @@ static bool ObjCEnumerationCollection(Expr *Collection) 
{
 ///
 /// The body of the loop is not available yet, since it cannot be analysed 
until
 /// we have determined the type of the for-range-declaration.
-StmtResult Sema::ActOnCXXForRangeStmt(Scope *S, SourceLocation ForLoc,
-  SourceLocation CoawaitLoc, Stmt 
*InitStmt,
-  Stmt *First, SourceLocation ColonLoc,
-  Expr *Range, SourceLocation RParenLoc,
-  BuildForRangeKind Kind,
-  ArrayRef 
LifetimeExtendTemps) {
+StmtResult Sema::ActOnCXXForRangeStmt(
+Scope *S, SourceLocation ForLoc, SourceLocation CoawaitLoc, Stmt *InitStmt,
+Stmt *First, SourceLocation ColonLoc, Expr *Range, SourceLocation 
RParenLoc,
+BuildForRangeKind Kind,
+Arr

[clang] [Clang] Implement P2718R0 "Lifetime extension in range-based for loops" (PR #76361)

2023-12-25 Thread via cfe-commits

https://github.com/yronglin updated 
https://github.com/llvm/llvm-project/pull/76361

>From 82367b98393c987df6422b6c1c112e9f5d681047 Mon Sep 17 00:00:00 2001
From: yronglin 
Date: Sun, 26 Nov 2023 22:52:03 +0800
Subject: [PATCH] [Clang] Implement P2718R0 "Lifetime extension in range-based
 for loops"

 Implement P2718R0 "Lifetime extension in range-based for loops" 
(https://wg21.link/P2718R0)

Differential Revision: https://reviews.llvm.org/D153701
---
 clang/include/clang/Parse/Parser.h|   2 +-
 clang/include/clang/Sema/Sema.h   |  43 ++-
 clang/lib/Parse/ParseDecl.cpp |  19 +
 clang/lib/Parse/ParseStmt.cpp |   7 +-
 clang/lib/Sema/SemaExpr.cpp   |  22 +-
 clang/lib/Sema/SemaExprCXX.cpp|  47 ++-
 clang/lib/Sema/SemaInit.cpp   |   4 +
 clang/lib/Sema/SemaStmt.cpp   |  17 +-
 .../test/AST/ast-dump-for-range-lifetime.cpp  | 355 ++
 clang/test/CXX/special/class.temporary/p6.cpp | 234 
 10 files changed, 710 insertions(+), 40 deletions(-)
 create mode 100644 clang/test/AST/ast-dump-for-range-lifetime.cpp

diff --git a/clang/include/clang/Parse/Parser.h 
b/clang/include/clang/Parse/Parser.h
index 2dbe090bd0932f..a467ff6157962c 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -2377,7 +2377,7 @@ class Parser : public CodeCompletionHandler {
   struct ForRangeInit {
 SourceLocation ColonLoc;
 ExprResult RangeExpr;
-
+SmallVector LifetimeExtendTemps;
 bool ParsedForRangeDecl() { return !ColonLoc.isInvalid(); }
   };
   struct ForRangeInfo : ForRangeInit {
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 5e3b57ea33220b..fc2b3881d5c062 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -1338,6 +1338,12 @@ class Sema final {
 /// context not already known to be immediately invoked.
 llvm::SmallPtrSet ReferenceToConsteval;
 
+/// P2718R0 - Lifetime extension in range-based for loops.
+/// MaterializeTemporaryExprs in for-range-init expression which need to
+/// extend lifetime. Add MaterializeTemporaryExpr* if the value of
+/// IsInLifetimeExtendingContext is true.
+SmallVector ForRangeLifetimeExtendTemps;
+
 /// \brief Describes whether we are in an expression constext which we have
 /// to handle differently.
 enum ExpressionKind {
@@ -1357,6 +1363,19 @@ class Sema final {
 // VLAs).
 bool InConditionallyConstantEvaluateContext = false;
 
+/// Whether we are currently in a context in which temporaries must be
+/// lifetime-extended (Eg. in a for-range initializer).
+bool IsInLifetimeExtendingContext = false;
+
+/// Whether we should materialize temporaries in discarded expressions.
+///
+/// [C++23][class.temporary]/p2.6 when a prvalue that has type other than 
cv
+/// void appears as a discarded-value expression ([expr.context]).
+///
+/// We do not materialize temporaries by default in order to avoid creating
+/// unnecessary temporary objects.
+bool MaterializePRValueInDiscardedExpression = false;
+
 // When evaluating immediate functions in the initializer of a default
 // argument or default member initializer, this is the declaration whose
 // default initializer is being evaluated and the location of the call
@@ -5209,13 +5228,11 @@ class Sema final {
 BFRK_Check
   };
 
-  StmtResult ActOnCXXForRangeStmt(Scope *S, SourceLocation ForLoc,
-  SourceLocation CoawaitLoc,
-  Stmt *InitStmt,
-  Stmt *LoopVar,
-  SourceLocation ColonLoc, Expr *Collection,
-  SourceLocation RParenLoc,
-  BuildForRangeKind Kind);
+  StmtResult ActOnCXXForRangeStmt(
+  Scope *S, SourceLocation ForLoc, SourceLocation CoawaitLoc,
+  Stmt *InitStmt, Stmt *LoopVar, SourceLocation ColonLoc, Expr *Collection,
+  SourceLocation RParenLoc, BuildForRangeKind Kind,
+  ArrayRef LifetimeExtendTemps = {});
   StmtResult BuildCXXForRangeStmt(SourceLocation ForLoc,
   SourceLocation CoawaitLoc,
   Stmt *InitStmt,
@@ -9956,6 +9973,18 @@ class Sema final {
 return currentEvaluationContext().isImmediateFunctionContext();
   }
 
+  bool isInLifetimeExtendingContext() const {
+assert(!ExprEvalContexts.empty() &&
+   "Must be in an expression evaluation context");
+return ExprEvalContexts.back().IsInLifetimeExtendingContext;
+  }
+
+  bool ShouldMaterializePRValueInDiscardedExpression() const {
+assert(!ExprEvalContexts.empty() &&
+   "Must be in an expression evaluation context");
+return ExprEvalContexts.back().MaterializePRValueInDiscardedExpression;
+  }
+
   bool isChec

[clang-tools-extra] [clangd] Ensure `-isysroot` in the original command is respected (PR #75694)

2023-12-25 Thread via cfe-commits

https://github.com/kon72 updated https://github.com/llvm/llvm-project/pull/75694

>From 5a295dd5a4bfe10cf0ea7ba94f9f687b951a68c3 Mon Sep 17 00:00:00 2001
From: kon72 
Date: Sat, 16 Dec 2023 17:39:46 +0900
Subject: [PATCH] [clangd] Fix sysroot flag handling in CommandMangler to
 prevent duplicates

CommandMangler should guess the sysroot path of the host system and add that 
through `-isysroot` flag only when there is no `--sysroot` or `-isysroot` flag 
in the original compile command to avoid duplicate sysroot.

Previously, CommandMangler appropriately avoided adding a guessed sysroot flag 
if the original command had an argument in the form of `--sysroot=`, 
`--sysroot `, or `-isysroot `.
However, when presented as `-isysroot` (without spaces after 
`-isysroot`), CommandMangler mistakenly appended the guessed sysroot flag, 
resulting in duplicated sysroot in the final command.

This commit fixes it, ensuring the final command has no duplicate sysroot flags.
Also adds unit tests for this fix.
---
 clang-tools-extra/clangd/CompileCommands.cpp  | 23 +++---
 .../clangd/unittests/CompileCommandsTests.cpp | 81 ++-
 2 files changed, 91 insertions(+), 13 deletions(-)

diff --git a/clang-tools-extra/clangd/CompileCommands.cpp 
b/clang-tools-extra/clangd/CompileCommands.cpp
index f43ce928463b90..a3c6f3f41118e4 100644
--- a/clang-tools-extra/clangd/CompileCommands.cpp
+++ b/clang-tools-extra/clangd/CompileCommands.cpp
@@ -328,13 +328,15 @@ void CommandMangler::operator()(tooling::CompileCommand 
&Command,
 
   tooling::addTargetAndModeForProgramName(Cmd, Cmd.front());
 
-  // Check whether the flag exists, either as -flag or -flag=*
-  auto Has = [&](llvm::StringRef Flag) {
-for (llvm::StringRef Arg : Cmd) {
-  if (Arg.consume_front(Flag) && (Arg.empty() || Arg[0] == '='))
-return true;
-}
-return false;
+  // Check whether the flag exists in the command.
+  auto HasExact = [&](llvm::StringRef Flag) {
+return llvm::any_of(Cmd, [&](llvm::StringRef Arg) { return Arg == Flag; });
+  };
+
+  // Check whether the flag appears in the command as a prefix.
+  auto HasPrefix = [&](llvm::StringRef Flag) {
+return llvm::any_of(
+Cmd, [&](llvm::StringRef Arg) { return Arg.startswith(Flag); });
   };
 
   llvm::erase_if(Cmd, [](llvm::StringRef Elem) {
@@ -342,12 +344,13 @@ void CommandMangler::operator()(tooling::CompileCommand 
&Command,
   });
 
   std::vector ToAppend;
-  if (ResourceDir && !Has("-resource-dir"))
+  if (ResourceDir && !HasExact("-resource-dir") && 
!HasPrefix("-resource-dir="))
 ToAppend.push_back(("-resource-dir=" + *ResourceDir));
 
   // Don't set `-isysroot` if it is already set or if `--sysroot` is set.
   // `--sysroot` is a superset of the `-isysroot` argument.
-  if (Sysroot && !Has("-isysroot") && !Has("--sysroot")) {
+  if (Sysroot && !HasPrefix("-isysroot") && !HasExact("--sysroot") &&
+  !HasPrefix("--sysroot=")) {
 ToAppend.push_back("-isysroot");
 ToAppend.push_back(*Sysroot);
   }
@@ -358,7 +361,7 @@ void CommandMangler::operator()(tooling::CompileCommand 
&Command,
   }
 
   if (!Cmd.empty()) {
-bool FollowSymlink = !Has("-no-canonical-prefixes");
+bool FollowSymlink = !HasExact("-no-canonical-prefixes");
 Cmd.front() =
 (FollowSymlink ? ResolvedDrivers : ResolvedDriversNoFollow)
 .get(Cmd.front(), [&, this] {
diff --git a/clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp 
b/clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
index 28f0d85d332caa..cad135923f71c1 100644
--- a/clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
+++ b/clang-tools-extra/clangd/unittests/CompileCommandsTests.cpp
@@ -385,9 +385,8 @@ TEST(ArgStripperTest, OrderDependent) {
 }
 
 TEST(PrintArgvTest, All) {
-  std::vector Args = {
-  "one", "two", "thr ee", "f\"o\"ur", "fi\\ve", "$"
-  };
+  std::vector Args = {"one",  "two","thr ee",
+   "f\"o\"ur", "fi\\ve", "$"};
   const char *Expected = R"(one two "thr ee" "f\"o\"ur" "fi\\ve" $)";
   EXPECT_EQ(Expected, printArgv(Args));
 }
@@ -465,6 +464,82 @@ TEST(CommandMangler, PathsAsPositional) {
   Mangler(Cmd, "a.cc");
   EXPECT_THAT(Cmd.CommandLine, Contains("foo"));
 }
+
+TEST(CommandMangler, RespectsOriginalResourceDir) {
+  auto Mangler = CommandMangler::forTests();
+  Mangler.ResourceDir = testPath("fake/resources");
+
+  {
+tooling::CompileCommand Cmd;
+Cmd.CommandLine = {"clang++", "-resource-dir", testPath("true/resources"),
+   "foo.cc"};
+Mangler(Cmd, "foo.cc");
+EXPECT_THAT(llvm::join(Cmd.CommandLine, " "),
+HasSubstr("-resource-dir " + testPath("true/resources")));
+EXPECT_THAT(llvm::join(Cmd.CommandLine, " "),
+Not(HasSubstr(testPath("fake/resources";
+  }
+
+  {
+tooling::CompileCommand Cmd;
+Cmd.CommandLine = {"clang++", "-resource-dir=" + 
testPath("true/resources"),
+   "foo.cc"

[clang-tools-extra] [clangd] Ensure `-isysroot` in the original command is respected (PR #75694)

2023-12-25 Thread via cfe-commits

https://github.com/kon72 edited https://github.com/llvm/llvm-project/pull/75694
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] Implement P2718R0 "Lifetime extension in range-based for loops" (PR #76361)

2023-12-25 Thread via cfe-commits

https://github.com/yronglin updated 
https://github.com/llvm/llvm-project/pull/76361

>From af44c06aabab3f6ae15d60b2473ff03934a6f39a Mon Sep 17 00:00:00 2001
From: yronglin 
Date: Tue, 26 Dec 2023 00:15:25 +0800
Subject: [PATCH] [Clang] Implement P2718R0 "Lifetime extension in range-based
 for loops"

 Implement P2718R0 "Lifetime extension in range-based for loops" 
(https://wg21.link/P2718R0)

Differential Revision: https://reviews.llvm.org/D153701
---
 clang/include/clang/Parse/Parser.h|   2 +-
 clang/include/clang/Sema/Sema.h   |  43 ++-
 clang/lib/Parse/ParseDecl.cpp |  19 +
 clang/lib/Parse/ParseStmt.cpp |   7 +-
 clang/lib/Sema/SemaExpr.cpp   |  22 +-
 clang/lib/Sema/SemaExprCXX.cpp|  47 ++-
 clang/lib/Sema/SemaInit.cpp   |   4 +
 clang/lib/Sema/SemaStmt.cpp   |  17 +-
 .../test/AST/ast-dump-for-range-lifetime.cpp  | 355 ++
 clang/test/CXX/special/class.temporary/p6.cpp | 234 
 10 files changed, 710 insertions(+), 40 deletions(-)
 create mode 100644 clang/test/AST/ast-dump-for-range-lifetime.cpp

diff --git a/clang/include/clang/Parse/Parser.h 
b/clang/include/clang/Parse/Parser.h
index 2dbe090bd0932f..a467ff6157962c 100644
--- a/clang/include/clang/Parse/Parser.h
+++ b/clang/include/clang/Parse/Parser.h
@@ -2377,7 +2377,7 @@ class Parser : public CodeCompletionHandler {
   struct ForRangeInit {
 SourceLocation ColonLoc;
 ExprResult RangeExpr;
-
+SmallVector LifetimeExtendTemps;
 bool ParsedForRangeDecl() { return !ColonLoc.isInvalid(); }
   };
   struct ForRangeInfo : ForRangeInit {
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 5e3b57ea33220b..fc2b3881d5c062 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -1338,6 +1338,12 @@ class Sema final {
 /// context not already known to be immediately invoked.
 llvm::SmallPtrSet ReferenceToConsteval;
 
+/// P2718R0 - Lifetime extension in range-based for loops.
+/// MaterializeTemporaryExprs in for-range-init expression which need to
+/// extend lifetime. Add MaterializeTemporaryExpr* if the value of
+/// IsInLifetimeExtendingContext is true.
+SmallVector ForRangeLifetimeExtendTemps;
+
 /// \brief Describes whether we are in an expression constext which we have
 /// to handle differently.
 enum ExpressionKind {
@@ -1357,6 +1363,19 @@ class Sema final {
 // VLAs).
 bool InConditionallyConstantEvaluateContext = false;
 
+/// Whether we are currently in a context in which temporaries must be
+/// lifetime-extended (Eg. in a for-range initializer).
+bool IsInLifetimeExtendingContext = false;
+
+/// Whether we should materialize temporaries in discarded expressions.
+///
+/// [C++23][class.temporary]/p2.6 when a prvalue that has type other than 
cv
+/// void appears as a discarded-value expression ([expr.context]).
+///
+/// We do not materialize temporaries by default in order to avoid creating
+/// unnecessary temporary objects.
+bool MaterializePRValueInDiscardedExpression = false;
+
 // When evaluating immediate functions in the initializer of a default
 // argument or default member initializer, this is the declaration whose
 // default initializer is being evaluated and the location of the call
@@ -5209,13 +5228,11 @@ class Sema final {
 BFRK_Check
   };
 
-  StmtResult ActOnCXXForRangeStmt(Scope *S, SourceLocation ForLoc,
-  SourceLocation CoawaitLoc,
-  Stmt *InitStmt,
-  Stmt *LoopVar,
-  SourceLocation ColonLoc, Expr *Collection,
-  SourceLocation RParenLoc,
-  BuildForRangeKind Kind);
+  StmtResult ActOnCXXForRangeStmt(
+  Scope *S, SourceLocation ForLoc, SourceLocation CoawaitLoc,
+  Stmt *InitStmt, Stmt *LoopVar, SourceLocation ColonLoc, Expr *Collection,
+  SourceLocation RParenLoc, BuildForRangeKind Kind,
+  ArrayRef LifetimeExtendTemps = {});
   StmtResult BuildCXXForRangeStmt(SourceLocation ForLoc,
   SourceLocation CoawaitLoc,
   Stmt *InitStmt,
@@ -9956,6 +9973,18 @@ class Sema final {
 return currentEvaluationContext().isImmediateFunctionContext();
   }
 
+  bool isInLifetimeExtendingContext() const {
+assert(!ExprEvalContexts.empty() &&
+   "Must be in an expression evaluation context");
+return ExprEvalContexts.back().IsInLifetimeExtendingContext;
+  }
+
+  bool ShouldMaterializePRValueInDiscardedExpression() const {
+assert(!ExprEvalContexts.empty() &&
+   "Must be in an expression evaluation context");
+return ExprEvalContexts.back().MaterializePRValueInDiscardedExpression;
+  }
+
   bool isChec

[clang-tools-extra] [clangd] Fix sysroot flag handling in CommandMangler to prevent duplicates (PR #75694)

2023-12-25 Thread via cfe-commits

https://github.com/kon72 edited https://github.com/llvm/llvm-project/pull/75694
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[flang] [clang] [flang][driver] Remove Fortain_main static library from linking stages (PR #75816)

2023-12-25 Thread Michael Klemm via cfe-commits

https://github.com/mjklemm updated 
https://github.com/llvm/llvm-project/pull/75816

>From b3fa63a02f63e6fe0dacc25d584eba2012a5a8c5 Mon Sep 17 00:00:00 2001
From: Michael Klemm 
Date: Sat, 16 Dec 2023 20:15:17 +0100
Subject: [PATCH 1/7] Remove -lFortran_main from the link line when -shared is
 present

---
 clang/lib/Driver/ToolChains/CommonArgs.cpp | 22 ++
 1 file changed, 22 insertions(+)

diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 6eb0ed8f3fed9a..939a719c7c7e29 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1133,6 +1133,17 @@ static bool isWholeArchivePresent(const ArgList &Args) {
   return WholeArchiveActive;
 }
 
+static bool isSharedLinkage(const ArgList &Args) {
+  bool FoundSharedFlag = false;
+  for (auto *Arg : Args.filtered(options::OPT_shared)) {
+if (Arg) {
+  FoundSharedFlag = true;
+}
+  }
+
+  return FoundSharedFlag;
+}
+
 /// Add Fortran runtime libs for MSVC
 static void addFortranRuntimeLibsMSVC(const ArgList &Args,
   llvm::opt::ArgStringList &CmdArgs) {
@@ -1164,6 +1175,17 @@ static void addFortranRuntimeLibsMSVC(const ArgList 
&Args,
 // Add FortranMain runtime lib
 static void addFortranMain(const ToolChain &TC, const ArgList &Args,
llvm::opt::ArgStringList &CmdArgs) {
+  // 0. Shared-library linkage
+  // If we are attempting to link a shared library, we should not add
+  // -lFortran_main.a to the link line, as the `main` symbol is not
+  // required for a shared library and should also be provided by one
+  // of the translation units of the code that this shared library
+  // will be linked against eventually.
+  if (isSharedLinkage(Args)) {
+printf("MK: --> shared linkage, do not add -lFortranMain\n");
+return;
+  }
+
   // 1. MSVC
   if (TC.getTriple().isKnownWindowsMSVCEnvironment()) {
 addFortranRuntimeLibsMSVC(Args, CmdArgs);

>From a480e16ac94451c635fc6d47df727c47ff3f1b21 Mon Sep 17 00:00:00 2001
From: Michael Klemm 
Date: Mon, 18 Dec 2023 11:27:59 +0100
Subject: [PATCH 2/7] Update dynamic_linker.f90 test and clean up a bit

---
 clang/lib/Driver/ToolChains/CommonArgs.cpp | 22 ++
 flang/test/Driver/dynamic-linker.f90   |  6 +-
 2 files changed, 15 insertions(+), 13 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 939a719c7c7e29..3b29e1bc75850f 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1133,15 +1133,14 @@ static bool isWholeArchivePresent(const ArgList &Args) {
   return WholeArchiveActive;
 }
 
+/// Determine if driver is invoked to create a shared object library (-static)
 static bool isSharedLinkage(const ArgList &Args) {
-  bool FoundSharedFlag = false;
-  for (auto *Arg : Args.filtered(options::OPT_shared)) {
-if (Arg) {
-  FoundSharedFlag = true;
-}
-  }
+  return Args.hasArg(options::OPT_shared);
+}
 
-  return FoundSharedFlag;
+/// Determine if driver is invoked to create a static object library (-shared)
+static bool isStaticLinkage(const ArgList &Args) {
+  return Args.hasArg(options::OPT_static);
 }
 
 /// Add Fortran runtime libs for MSVC
@@ -1176,13 +1175,12 @@ static void addFortranRuntimeLibsMSVC(const ArgList 
&Args,
 static void addFortranMain(const ToolChain &TC, const ArgList &Args,
llvm::opt::ArgStringList &CmdArgs) {
   // 0. Shared-library linkage
-  // If we are attempting to link a shared library, we should not add
+  // If we are attempting to link a library, we should not add
   // -lFortran_main.a to the link line, as the `main` symbol is not
-  // required for a shared library and should also be provided by one
-  // of the translation units of the code that this shared library
+  // required for a library and should also be provided by one of
+  // the translation units of the code that this shared library
   // will be linked against eventually.
-  if (isSharedLinkage(Args)) {
-printf("MK: --> shared linkage, do not add -lFortranMain\n");
+  if (isSharedLinkage(Args) || isStaticLinkage(Args)) {
 return;
   }
 
diff --git a/flang/test/Driver/dynamic-linker.f90 
b/flang/test/Driver/dynamic-linker.f90
index 1cbd407d21ce09..069b51870c91ff 100644
--- a/flang/test/Driver/dynamic-linker.f90
+++ b/flang/test/Driver/dynamic-linker.f90
@@ -3,10 +3,12 @@
 
 ! RUN: %flang -### --target=x86_64-linux-gnu -rpath /path/to/dir -shared \
 ! RUN: -static %s 2>&1 | FileCheck \
-! RUN: --check-prefixes=GNU-LINKER-OPTIONS %s
+! RUN: --check-prefixes=GNU-LINKER-OPTIONS \
+! RUN: --implicit-check-not=GNU-LINKER-OPTIONS-NOT %s
 ! RUN: %flang -### --target=x86_64-windows-msvc -rpath /path/to/dir -shared \
 ! RUN: -static %s 2>&1 | FileCheck \
 ! RUN: --check-prefixes=MSVC-LINKER-OPTIONS %s
+! RUN: -

[flang] [clang] [flang][driver] Remove Fortain_main static library from linking stages (PR #75816)

2023-12-25 Thread Michael Klemm via cfe-commits

https://github.com/mjklemm updated 
https://github.com/llvm/llvm-project/pull/75816

>From b3fa63a02f63e6fe0dacc25d584eba2012a5a8c5 Mon Sep 17 00:00:00 2001
From: Michael Klemm 
Date: Sat, 16 Dec 2023 20:15:17 +0100
Subject: [PATCH 1/8] Remove -lFortran_main from the link line when -shared is
 present

---
 clang/lib/Driver/ToolChains/CommonArgs.cpp | 22 ++
 1 file changed, 22 insertions(+)

diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 6eb0ed8f3fed9a..939a719c7c7e29 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1133,6 +1133,17 @@ static bool isWholeArchivePresent(const ArgList &Args) {
   return WholeArchiveActive;
 }
 
+static bool isSharedLinkage(const ArgList &Args) {
+  bool FoundSharedFlag = false;
+  for (auto *Arg : Args.filtered(options::OPT_shared)) {
+if (Arg) {
+  FoundSharedFlag = true;
+}
+  }
+
+  return FoundSharedFlag;
+}
+
 /// Add Fortran runtime libs for MSVC
 static void addFortranRuntimeLibsMSVC(const ArgList &Args,
   llvm::opt::ArgStringList &CmdArgs) {
@@ -1164,6 +1175,17 @@ static void addFortranRuntimeLibsMSVC(const ArgList 
&Args,
 // Add FortranMain runtime lib
 static void addFortranMain(const ToolChain &TC, const ArgList &Args,
llvm::opt::ArgStringList &CmdArgs) {
+  // 0. Shared-library linkage
+  // If we are attempting to link a shared library, we should not add
+  // -lFortran_main.a to the link line, as the `main` symbol is not
+  // required for a shared library and should also be provided by one
+  // of the translation units of the code that this shared library
+  // will be linked against eventually.
+  if (isSharedLinkage(Args)) {
+printf("MK: --> shared linkage, do not add -lFortranMain\n");
+return;
+  }
+
   // 1. MSVC
   if (TC.getTriple().isKnownWindowsMSVCEnvironment()) {
 addFortranRuntimeLibsMSVC(Args, CmdArgs);

>From a480e16ac94451c635fc6d47df727c47ff3f1b21 Mon Sep 17 00:00:00 2001
From: Michael Klemm 
Date: Mon, 18 Dec 2023 11:27:59 +0100
Subject: [PATCH 2/8] Update dynamic_linker.f90 test and clean up a bit

---
 clang/lib/Driver/ToolChains/CommonArgs.cpp | 22 ++
 flang/test/Driver/dynamic-linker.f90   |  6 +-
 2 files changed, 15 insertions(+), 13 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 939a719c7c7e29..3b29e1bc75850f 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1133,15 +1133,14 @@ static bool isWholeArchivePresent(const ArgList &Args) {
   return WholeArchiveActive;
 }
 
+/// Determine if driver is invoked to create a shared object library (-static)
 static bool isSharedLinkage(const ArgList &Args) {
-  bool FoundSharedFlag = false;
-  for (auto *Arg : Args.filtered(options::OPT_shared)) {
-if (Arg) {
-  FoundSharedFlag = true;
-}
-  }
+  return Args.hasArg(options::OPT_shared);
+}
 
-  return FoundSharedFlag;
+/// Determine if driver is invoked to create a static object library (-shared)
+static bool isStaticLinkage(const ArgList &Args) {
+  return Args.hasArg(options::OPT_static);
 }
 
 /// Add Fortran runtime libs for MSVC
@@ -1176,13 +1175,12 @@ static void addFortranRuntimeLibsMSVC(const ArgList 
&Args,
 static void addFortranMain(const ToolChain &TC, const ArgList &Args,
llvm::opt::ArgStringList &CmdArgs) {
   // 0. Shared-library linkage
-  // If we are attempting to link a shared library, we should not add
+  // If we are attempting to link a library, we should not add
   // -lFortran_main.a to the link line, as the `main` symbol is not
-  // required for a shared library and should also be provided by one
-  // of the translation units of the code that this shared library
+  // required for a library and should also be provided by one of
+  // the translation units of the code that this shared library
   // will be linked against eventually.
-  if (isSharedLinkage(Args)) {
-printf("MK: --> shared linkage, do not add -lFortranMain\n");
+  if (isSharedLinkage(Args) || isStaticLinkage(Args)) {
 return;
   }
 
diff --git a/flang/test/Driver/dynamic-linker.f90 
b/flang/test/Driver/dynamic-linker.f90
index 1cbd407d21ce09..069b51870c91ff 100644
--- a/flang/test/Driver/dynamic-linker.f90
+++ b/flang/test/Driver/dynamic-linker.f90
@@ -3,10 +3,12 @@
 
 ! RUN: %flang -### --target=x86_64-linux-gnu -rpath /path/to/dir -shared \
 ! RUN: -static %s 2>&1 | FileCheck \
-! RUN: --check-prefixes=GNU-LINKER-OPTIONS %s
+! RUN: --check-prefixes=GNU-LINKER-OPTIONS \
+! RUN: --implicit-check-not=GNU-LINKER-OPTIONS-NOT %s
 ! RUN: %flang -### --target=x86_64-windows-msvc -rpath /path/to/dir -shared \
 ! RUN: -static %s 2>&1 | FileCheck \
 ! RUN: --check-prefixes=MSVC-LINKER-OPTIONS %s
+! RUN: -

[clang-tools-extra] [clang-tidy] Add bugprone-chained-comparison check (PR #76365)

2023-12-25 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL created 
https://github.com/llvm/llvm-project/pull/76365

Check that flags chained comparison expressions,
such as a < b < c or a == b == c, which may have
unintended behavior due to implicit operator
associativity.

Moved from Phabricator  (D144429).


>From 5ece73a5b14e86172b900f4ae9d63d8fa1590d4a Mon Sep 17 00:00:00 2001
From: Piotr Zegar 
Date: Mon, 25 Dec 2023 16:18:45 +
Subject: [PATCH] [clang-tidy] Add bugprone-chained-comparison check

Check that flags chained comparison expressions,
such as a < b < c or a == b == c, which may have
unintended behavior due to implicit operator
associativity.
---
 .../bugprone/BugproneTidyModule.cpp   |   3 +
 .../clang-tidy/bugprone/CMakeLists.txt|   1 +
 .../bugprone/ChainedComparisonCheck.cpp   | 161 ++
 .../bugprone/ChainedComparisonCheck.h |  37 
 clang-tools-extra/docs/ReleaseNotes.rst   |   6 +
 .../checks/bugprone/chained-comparison.rst|  73 
 .../docs/clang-tidy/checks/list.rst   |   1 +
 .../checkers/bugprone/chained-comparison.cpp  |  91 ++
 8 files changed, 373 insertions(+)
 create mode 100644 
clang-tools-extra/clang-tidy/bugprone/ChainedComparisonCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/bugprone/ChainedComparisonCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/bugprone/chained-comparison.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/chained-comparison.cpp

diff --git a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp 
b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
index 435cb1e3fbcff3..a8a23b045f80bb 100644
--- a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
@@ -17,6 +17,7 @@
 #include "BoolPointerImplicitConversionCheck.h"
 #include "BranchCloneCheck.h"
 #include "CastingThroughVoidCheck.h"
+#include "ChainedComparisonCheck.h"
 #include "ComparePointerToMemberVirtualFunctionCheck.h"
 #include "CopyConstructorInitCheck.h"
 #include "DanglingHandleCheck.h"
@@ -108,6 +109,8 @@ class BugproneModule : public ClangTidyModule {
 CheckFactories.registerCheck("bugprone-branch-clone");
 CheckFactories.registerCheck(
 "bugprone-casting-through-void");
+CheckFactories.registerCheck(
+"bugprone-chained-comparison");
 CheckFactories.registerCheck(
 "bugprone-compare-pointer-to-member-virtual-function");
 CheckFactories.registerCheck(
diff --git a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
index 70e7fbc7ec0c14..1cd6fb207d7625 100644
--- a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
@@ -12,6 +12,7 @@ add_clang_library(clangTidyBugproneModule
   BranchCloneCheck.cpp
   BugproneTidyModule.cpp
   CastingThroughVoidCheck.cpp
+  ChainedComparisonCheck.cpp
   ComparePointerToMemberVirtualFunctionCheck.cpp
   CopyConstructorInitCheck.cpp
   DanglingHandleCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/bugprone/ChainedComparisonCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/ChainedComparisonCheck.cpp
new file mode 100644
index 00..07f65d062e51cf
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/bugprone/ChainedComparisonCheck.cpp
@@ -0,0 +1,161 @@
+//===--- ChainedComparisonCheck.cpp - clang-tidy 
--===//
+//
+// 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 "ChainedComparisonCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/SmallVector.h"
+#include 
+#include 
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+namespace {
+
+bool isExprAComparisonOperator(const Expr *E) {
+  if (const auto *Op = dyn_cast_or_null(E->IgnoreImplicit()))
+return Op->isComparisonOp();
+  if (const auto *Op =
+  dyn_cast_or_null(E->IgnoreImplicit()))
+return Op->isComparisonOp();
+  return false;
+}
+
+AST_MATCHER(BinaryOperator,
+hasBinaryOperatorAChildComparisonOperatorWithoutParen) {
+  return isExprAComparisonOperator(Node.getLHS()) ||
+ isExprAComparisonOperator(Node.getRHS());
+}
+
+AST_MATCHER(CXXOperatorCallExpr,
+hasCppOperatorAChildComparisonOperatorWithoutParen) {
+  return std::any_of(Node.arg_begin(), Node.arg_end(),
+ isExprAComparisonOperator);
+}
+
+constexpr std::array Letters = {
+"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m",
+"n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"};
+
+struct ChainedC

[clang-tools-extra] [clang-tidy] Add bugprone-chained-comparison check (PR #76365)

2023-12-25 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-tidy

Author: Piotr Zegar (PiotrZSL)


Changes

Check that flags chained comparison expressions,
such as a < b < c or a == b == c, which may have
unintended behavior due to implicit operator
associativity.

Moved from Phabricator  (D144429).


---
Full diff: https://github.com/llvm/llvm-project/pull/76365.diff


8 Files Affected:

- (modified) clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp (+3) 
- (modified) clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt (+1) 
- (added) clang-tools-extra/clang-tidy/bugprone/ChainedComparisonCheck.cpp 
(+161) 
- (added) clang-tools-extra/clang-tidy/bugprone/ChainedComparisonCheck.h (+37) 
- (modified) clang-tools-extra/docs/ReleaseNotes.rst (+6) 
- (added) 
clang-tools-extra/docs/clang-tidy/checks/bugprone/chained-comparison.rst (+73) 
- (modified) clang-tools-extra/docs/clang-tidy/checks/list.rst (+1) 
- (added) 
clang-tools-extra/test/clang-tidy/checkers/bugprone/chained-comparison.cpp 
(+91) 


``diff
diff --git a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp 
b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
index 435cb1e3fbcff3..a8a23b045f80bb 100644
--- a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
@@ -17,6 +17,7 @@
 #include "BoolPointerImplicitConversionCheck.h"
 #include "BranchCloneCheck.h"
 #include "CastingThroughVoidCheck.h"
+#include "ChainedComparisonCheck.h"
 #include "ComparePointerToMemberVirtualFunctionCheck.h"
 #include "CopyConstructorInitCheck.h"
 #include "DanglingHandleCheck.h"
@@ -108,6 +109,8 @@ class BugproneModule : public ClangTidyModule {
 CheckFactories.registerCheck("bugprone-branch-clone");
 CheckFactories.registerCheck(
 "bugprone-casting-through-void");
+CheckFactories.registerCheck(
+"bugprone-chained-comparison");
 CheckFactories.registerCheck(
 "bugprone-compare-pointer-to-member-virtual-function");
 CheckFactories.registerCheck(
diff --git a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
index 70e7fbc7ec0c14..1cd6fb207d7625 100644
--- a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
@@ -12,6 +12,7 @@ add_clang_library(clangTidyBugproneModule
   BranchCloneCheck.cpp
   BugproneTidyModule.cpp
   CastingThroughVoidCheck.cpp
+  ChainedComparisonCheck.cpp
   ComparePointerToMemberVirtualFunctionCheck.cpp
   CopyConstructorInitCheck.cpp
   DanglingHandleCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/bugprone/ChainedComparisonCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/ChainedComparisonCheck.cpp
new file mode 100644
index 00..07f65d062e51cf
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/bugprone/ChainedComparisonCheck.cpp
@@ -0,0 +1,161 @@
+//===--- ChainedComparisonCheck.cpp - clang-tidy 
--===//
+//
+// 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 "ChainedComparisonCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "llvm/ADT/SmallString.h"
+#include "llvm/ADT/SmallVector.h"
+#include 
+#include 
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+namespace {
+
+bool isExprAComparisonOperator(const Expr *E) {
+  if (const auto *Op = dyn_cast_or_null(E->IgnoreImplicit()))
+return Op->isComparisonOp();
+  if (const auto *Op =
+  dyn_cast_or_null(E->IgnoreImplicit()))
+return Op->isComparisonOp();
+  return false;
+}
+
+AST_MATCHER(BinaryOperator,
+hasBinaryOperatorAChildComparisonOperatorWithoutParen) {
+  return isExprAComparisonOperator(Node.getLHS()) ||
+ isExprAComparisonOperator(Node.getRHS());
+}
+
+AST_MATCHER(CXXOperatorCallExpr,
+hasCppOperatorAChildComparisonOperatorWithoutParen) {
+  return std::any_of(Node.arg_begin(), Node.arg_end(),
+ isExprAComparisonOperator);
+}
+
+constexpr std::array Letters = {
+"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m",
+"n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"};
+
+struct ChainedComparisonData {
+  llvm::SmallString<256U> Name;
+  llvm::SmallVector Operands;
+  bool Full = false;
+
+  void Add(const Expr *Operand) {
+if (Full)
+  return;
+if (!Name.empty())
+  Name += ' ';
+Name += Letters[Operands.size()];
+Operands.push_back(Operand);
+
+if (Operands.size() == Letters.size()) {
+  Name += " ...";
+  Full = true;
+}
+  }
+
+  void Add(llvm::StringRef Opcode) {
+if (Full)
+  return;
+
+Name += ' ';
+Name +

[clang] 9d6837d - [flang][driver] Remove Fortain_main static library from linking stages (#75816)

2023-12-25 Thread via cfe-commits

Author: Michael Klemm
Date: 2023-12-25T19:15:00+01:00
New Revision: 9d6837d595719904720e5ff68ec1f1a2665bdc2f

URL: 
https://github.com/llvm/llvm-project/commit/9d6837d595719904720e5ff68ec1f1a2665bdc2f
DIFF: 
https://github.com/llvm/llvm-project/commit/9d6837d595719904720e5ff68ec1f1a2665bdc2f.diff

LOG: [flang][driver] Remove Fortain_main static library from linking stages 
(#75816)

At present, when building static or shared libraries, Flang adds
`-lFortran_main.a` (or `/WHOLEARCHIVE:Fortran.*.lib` pon Windows) to the
link line. This leads to the problem that `_QQmain` and
`_QQEnvironmentDefaults` (as of the time of this PR) are symbols marked
as used, while `main` is being defined. This should not happen and this
PR fixes this by detecting if `-shared` or `-static` is used on the
Flang command line and removing the static `Fortran_main` library.

-

Co-authored-by: kkwli 

Added: 


Modified: 
clang/lib/Driver/ToolChains/CommonArgs.cpp
flang/docs/FlangDriver.md
flang/test/Driver/dynamic-linker.f90

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 6eb0ed8f3fed9a..3b29e1bc75850f 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -1133,6 +1133,16 @@ static bool isWholeArchivePresent(const ArgList &Args) {
   return WholeArchiveActive;
 }
 
+/// Determine if driver is invoked to create a shared object library (-static)
+static bool isSharedLinkage(const ArgList &Args) {
+  return Args.hasArg(options::OPT_shared);
+}
+
+/// Determine if driver is invoked to create a static object library (-shared)
+static bool isStaticLinkage(const ArgList &Args) {
+  return Args.hasArg(options::OPT_static);
+}
+
 /// Add Fortran runtime libs for MSVC
 static void addFortranRuntimeLibsMSVC(const ArgList &Args,
   llvm::opt::ArgStringList &CmdArgs) {
@@ -1164,6 +1174,16 @@ static void addFortranRuntimeLibsMSVC(const ArgList 
&Args,
 // Add FortranMain runtime lib
 static void addFortranMain(const ToolChain &TC, const ArgList &Args,
llvm::opt::ArgStringList &CmdArgs) {
+  // 0. Shared-library linkage
+  // If we are attempting to link a library, we should not add
+  // -lFortran_main.a to the link line, as the `main` symbol is not
+  // required for a library and should also be provided by one of
+  // the translation units of the code that this shared library
+  // will be linked against eventually.
+  if (isSharedLinkage(Args) || isStaticLinkage(Args)) {
+return;
+  }
+
   // 1. MSVC
   if (TC.getTriple().isKnownWindowsMSVCEnvironment()) {
 addFortranRuntimeLibsMSVC(Args, CmdArgs);

diff  --git a/flang/docs/FlangDriver.md b/flang/docs/FlangDriver.md
index 5231e78335f6ad..fa39889927e0eb 100644
--- a/flang/docs/FlangDriver.md
+++ b/flang/docs/FlangDriver.md
@@ -163,6 +163,63 @@ forward compiler options to the frontend driver, 
`flang-new -fc1`.
 You can read more on the design of `clangDriver` in Clang's [Driver Design &
 Internals](https://clang.llvm.org/docs/DriverInternals.html).
 
+## Linker Driver
+When used as a linker, Flang's frontend driver assembles the command line for 
an
+external linker command (e.g., LLVM's `lld`) and invokes it to create the final
+executable by linking static and shared libraries together with all the
+translation units supplied as object files.
+
+By default, the Flang linker driver adds several libraries to the linker
+invocation to make sure that all entrypoints for program start
+(Fortran's program unit) and runtime routines can be resolved by the linker.
+
+An abridged example (only showing the Fortran specific linker flags, omission
+indicated by `[...]`) for such a linker invocation on a Linux system would look
+like this:
+
+```
+$ flang -v -o example example.o
+"/usr/bin/ld" [...] example.o [...] "--whole-archive" "-lFortran_main"
+"--no-whole-archive" "-lFortranRuntime" "-lFortranDecimal" [...]
+```
+
+The automatically added libraries are:
+
+* `Fortran_main`: Provides the main entry point `main` that then invokes
+  `_QQmain` with the Fortran program unit.  This library has a dependency to
+  the `FortranRuntime` library.
+* `FortranRuntime`: Provides most of the Flang runtime library.
+* `FortranDecimal`: Provides operations for decimal numbers.
+
+The default is that, when using Flang as the linker, one of the Fortran
+translation units provides the program unit and therefore it is assumed that
+Fortran is the main code part (calling into C/C++ routines via `BIND (C)`
+interfaces).  When composing the linker commandline, Flang uses
+`--whole-archive` and `--no-whole-archive` (Windows: `/WHOLEARCHIVE:`,
+Darwin & AIX: *not implemented yet*) to make sure that all for `Fortran_main`
+is processed by the linker.  This is done to issue a proper error message when
+multiple definit

[flang] [clang] [flang][driver] Remove Fortain_main static library from linking stages (PR #75816)

2023-12-25 Thread Michael Klemm via cfe-commits

https://github.com/mjklemm closed 
https://github.com/llvm/llvm-project/pull/75816
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] Fix #75686: add iter_swap and iter_move to the matched name (PR #76117)

2023-12-25 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL requested changes to this pull request.

Missing tests, documentation, release notes.

https://github.com/llvm/llvm-project/pull/76117
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] 8c24422 - [clang-tidy] add std::span to the default types. (#76116)

2023-12-25 Thread via cfe-commits

Author: Da-Viper
Date: 2023-12-25T19:59:08+01:00
New Revision: 8c24422cd4a5ec458950e135f62d9b14a96e75cc

URL: 
https://github.com/llvm/llvm-project/commit/8c24422cd4a5ec458950e135f62d9b14a96e75cc
DIFF: 
https://github.com/llvm/llvm-project/commit/8c24422cd4a5ec458950e135f62d9b14a96e75cc.diff

LOG: [clang-tidy] add std::span to the default types. (#76116)

Change default configuration of readability-simplify-subscript-expr to include 
std::span.
Fixes #75687

Added: 


Modified: 
clang-tools-extra/clang-tidy/readability/SimplifySubscriptExprCheck.cpp

clang-tools-extra/docs/clang-tidy/checks/readability/simplify-subscript-expr.rst

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/readability/SimplifySubscriptExprCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/SimplifySubscriptExprCheck.cpp
index d274abcbfabe8a..7d4698d27ed160 100644
--- a/clang-tools-extra/clang-tidy/readability/SimplifySubscriptExprCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/SimplifySubscriptExprCheck.cpp
@@ -16,7 +16,8 @@ using namespace clang::ast_matchers;
 namespace clang::tidy::readability {
 
 static const char KDefaultTypes[] =
-"::std::basic_string;::std::basic_string_view;::std::vector;::std::array";
+
"::std::basic_string;::std::basic_string_view;::std::vector;::std::array;::"
+"std::span";
 
 SimplifySubscriptExprCheck::SimplifySubscriptExprCheck(
 StringRef Name, ClangTidyContext *Context)

diff  --git 
a/clang-tools-extra/docs/clang-tidy/checks/readability/simplify-subscript-expr.rst
 
b/clang-tools-extra/docs/clang-tidy/checks/readability/simplify-subscript-expr.rst
index f3f44bedcf74c5..4b7d7f2ddcf417 100644
--- 
a/clang-tools-extra/docs/clang-tidy/checks/readability/simplify-subscript-expr.rst
+++ 
b/clang-tools-extra/docs/clang-tidy/checks/readability/simplify-subscript-expr.rst
@@ -20,4 +20,4 @@ Options
 .. option:: Types
 
The list of type(s) that triggers this check. Default is
-   `::std::basic_string;::std::basic_string_view;::std::vector;::std::array`
+   
`::std::basic_string;::std::basic_string_view;::std::vector;::std::array;::std::span`



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] Fix #75687: add std::span to the default types. (PR #76116)

2023-12-25 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL closed 
https://github.com/llvm/llvm-project/pull/76116
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] 9e98f8d - [clng-tidy][NFC] Update documentation for readability-simplify-subscript-expr

2023-12-25 Thread Piotr Zegar via cfe-commits

Author: Piotr Zegar
Date: 2023-12-25T20:33:19Z
New Revision: 9e98f8d7ac11c63768b1ed69c11ea75c8b794063

URL: 
https://github.com/llvm/llvm-project/commit/9e98f8d7ac11c63768b1ed69c11ea75c8b794063
DIFF: 
https://github.com/llvm/llvm-project/commit/9e98f8d7ac11c63768b1ed69c11ea75c8b794063.diff

LOG: [clng-tidy][NFC] Update documentation for 
readability-simplify-subscript-expr

Add release notes and mention ::std::span in documentation.
Change is related to #76116.

Added: 


Modified: 
clang-tools-extra/docs/ReleaseNotes.rst

Removed: 




diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 6e7554e0433c25..c843efac754ce0 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -458,6 +458,10 @@ Changes in existing checks
   ` check to ignore
   false-positives in initializer list of record.
 
+- Improved :doc:`readability-simplify-subscript-expr
+  ` check by extending
+  the default value of the `Types` option to include ``std::span``.
+
 - Improved :doc:`readability-static-accessed-through-instance
   ` check to
   identify calls to static member functions with out-of-class inline 
definitions.



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 68f832f - [clang] Use StringRef::consume_front (NFC)

2023-12-25 Thread Kazu Hirata via cfe-commits

Author: Kazu Hirata
Date: 2023-12-25T12:54:35-08:00
New Revision: 68f832f56da1af0e5fc77003f640648ec7d901ad

URL: 
https://github.com/llvm/llvm-project/commit/68f832f56da1af0e5fc77003f640648ec7d901ad
DIFF: 
https://github.com/llvm/llvm-project/commit/68f832f56da1af0e5fc77003f640648ec7d901ad.diff

LOG: [clang] Use StringRef::consume_front (NFC)

Added: 


Modified: 
clang/lib/CodeGen/CodeGenAction.cpp
clang/lib/Driver/ToolChains/CommonArgs.cpp
clang/lib/Frontend/DependencyGraph.cpp
clang/lib/Frontend/VerifyDiagnosticConsumer.cpp
clang/lib/Sema/SemaChecking.cpp
clang/lib/Sema/SemaDeclAttr.cpp
clang/lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp
clang/lib/Tooling/Refactoring/Lookup.cpp
clang/lib/Tooling/Tooling.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CodeGenAction.cpp 
b/clang/lib/CodeGen/CodeGenAction.cpp
index 753a8fd74fa696..f8038497d90a7b 100644
--- a/clang/lib/CodeGen/CodeGenAction.cpp
+++ b/clang/lib/CodeGen/CodeGenAction.cpp
@@ -1139,8 +1139,7 @@ CodeGenAction::loadModule(MemoryBufferRef MBRef) {
 
   // Strip off a leading diagnostic code if there is one.
   StringRef Msg = Err.getMessage();
-  if (Msg.starts_with("error: "))
-Msg = Msg.substr(7);
+  Msg.consume_front("error: ");
 
   unsigned DiagID =
   CI.getDiagnostics().getCustomDiagID(DiagnosticsEngine::Error, "%0");

diff  --git a/clang/lib/Driver/ToolChains/CommonArgs.cpp 
b/clang/lib/Driver/ToolChains/CommonArgs.cpp
index 3b29e1bc75850f..2340191ca97d98 100644
--- a/clang/lib/Driver/ToolChains/CommonArgs.cpp
+++ b/clang/lib/Driver/ToolChains/CommonArgs.cpp
@@ -2388,8 +2388,7 @@ static void GetSDLFromOffloadArchive(
   FoundAOB = true;
 }
   } else {
-if (Lib.starts_with("-l"))
-  Lib = Lib.drop_front(2);
+Lib.consume_front("-l");
 for (auto LPath : LibraryPaths) {
   ArchiveOfBundles.clear();
   auto LibFile = (Lib.starts_with(":") ? Lib.drop_front()

diff  --git a/clang/lib/Frontend/DependencyGraph.cpp 
b/clang/lib/Frontend/DependencyGraph.cpp
index e96669f856bb18..b471471f3528a7 100644
--- a/clang/lib/Frontend/DependencyGraph.cpp
+++ b/clang/lib/Frontend/DependencyGraph.cpp
@@ -110,8 +110,7 @@ void DependencyGraphCallback::OutputGraphFile() {
 writeNodeReference(OS, AllFiles[I]);
 OS << " [ shape=\"box\", label=\"";
 StringRef FileName = AllFiles[I].getName();
-if (FileName.starts_with(SysRoot))
-  FileName = FileName.substr(SysRoot.size());
+FileName.consume_front(SysRoot);
 
 OS << DOT::EscapeString(std::string(FileName)) << "\"];\n";
   }

diff  --git a/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp 
b/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp
index 09c1460d54e1d7..8a3d2286cd168c 100644
--- a/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp
+++ b/clang/lib/Frontend/VerifyDiagnosticConsumer.cpp
@@ -1144,8 +1144,7 @@ std::unique_ptr Directive::create(bool 
RegexKind,
   std::string RegexStr;
   StringRef S = Text;
   while (!S.empty()) {
-if (S.starts_with("{{")) {
-  S = S.drop_front(2);
+if (S.consume_front("{{")) {
   size_t RegexMatchLength = S.find("}}");
   assert(RegexMatchLength != StringRef::npos);
   // Append the regex, enclosed in parentheses.

diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 2a69325f029514..66dac99b8d9922 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -1219,8 +1219,8 @@ void 
Sema::checkFortifiedBuiltinMemoryFunction(FunctionDecl *FD,
 if (IsChkVariant) {
   FunctionName = FunctionName.drop_front(std::strlen("__builtin___"));
   FunctionName = FunctionName.drop_back(std::strlen("_chk"));
-} else if (FunctionName.starts_with("__builtin_")) {
-  FunctionName = FunctionName.drop_front(std::strlen("__builtin_"));
+} else {
+  FunctionName.consume_front("__builtin_");
 }
 return FunctionName;
   };

diff  --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index af8b90ecfed973..4a385a396fa62b 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -5825,8 +5825,7 @@ struct IntrinToName {
 static bool ArmBuiltinAliasValid(unsigned BuiltinID, StringRef AliasName,
  ArrayRef Map,
  const char *IntrinNames) {
-  if (AliasName.starts_with("__arm_"))
-AliasName = AliasName.substr(6);
+  AliasName.consume_front("__arm_");
   const IntrinToName *It =
   llvm::lower_bound(Map, BuiltinID, [](const IntrinToName &L, unsigned Id) 
{
 return L.Id < Id;

diff  --git a/clang/lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp 
b/clang/lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp
index afc5e6b48008d8..ce05d2d3c90585 100644
--- a/clang/lib/StaticAnalyzer/Checkers/CheckSecuritySyntaxOnly.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/CheckSecurit

[clang] [clang] Fix --entry command line option (PR #69114)

2023-12-25 Thread Sergei Barannikov via cfe-commits

s-barannikov wrote:

We do use this option with gcc, this is why I filed the issue.


https://github.com/llvm/llvm-project/pull/69114
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] Recommit [RISCV] Update the interface of sifive vqmaccqoq (#74284) (PR #75768)

2023-12-25 Thread Brandon Wu via cfe-commits


@@ -553,29 +560,40 @@ class GetFTypeInfo {
 }
 
 multiclass VPatVMACC info_pairs, ValueType vec_m1> {
+ list info_pairs, ValueType vec_m1,
+ bit lmul_follows_vd = 0> {

4vtomat wrote:

Oh, that's right.

https://github.com/llvm/llvm-project/pull/75768
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Stop aligning the to continuation lines (PR #76378)

2023-12-25 Thread via cfe-commits

https://github.com/sstwcw created 
https://github.com/llvm/llvm-project/pull/76378

Some unwrapped lines are marked as continuations of the previous lines, for 
example the ports in a Verilog module header.  Previously, if the first line 
following the ports lines was changed, and git-clang-format was run, the 
changed line would be indented by an extra continuation indentation.

>From 7a8939bcd41cdfafe0546502064a6378ba117d60 Mon Sep 17 00:00:00 2001
From: sstwcw 
Date: Tue, 26 Dec 2023 03:07:58 +
Subject: [PATCH] [clang-format] Stop aligning the to continuation lines

Some unwrapped lines are marked as continuations of the previous lines,
for example the ports in a Verilog module header.  Previously, if the
first line following the ports lines was changed, and git-clang-format
was run, the changed line would be indented by an extra continuation
indentation.
---
 clang/lib/Format/UnwrappedLineFormatter.cpp  |  2 +-
 clang/unittests/Format/FormatTestCSharp.cpp  | 12 
 clang/unittests/Format/FormatTestVerilog.cpp | 11 +++
 3 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Format/UnwrappedLineFormatter.cpp 
b/clang/lib/Format/UnwrappedLineFormatter.cpp
index 56077499c39d53..2fc15d8828e4be 100644
--- a/clang/lib/Format/UnwrappedLineFormatter.cpp
+++ b/clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -95,7 +95,7 @@ class LevelIndentTracker {
   /// level to the same indent.
   /// Note that \c nextLine must have been called before this method.
   void adjustToUnmodifiedLine(const AnnotatedLine &Line) {
-if (Line.InPPDirective)
+if (Line.InPPDirective || Line.IsContinuation)
   return;
 assert(Line.Level < IndentForLevel.size());
 if (Line.First->is(tok::comment) && IndentForLevel[Line.Level] != -1)
diff --git a/clang/unittests/Format/FormatTestCSharp.cpp 
b/clang/unittests/Format/FormatTestCSharp.cpp
index 4a0840d32341e8..c27e2b576adf73 100644
--- a/clang/unittests/Format/FormatTestCSharp.cpp
+++ b/clang/unittests/Format/FormatTestCSharp.cpp
@@ -1304,6 +1304,18 @@ TEST_F(FormatTestCSharp, CSharpGenericTypeConstraints) {
"}",
Style);
 
+  // When the where line is not to be formatted, following lines should not 
take
+  // on its indentation.
+  verifyFormat("class ItemFactory\n"
+   "where T : new() {\n"
+   "  int f() {}\n"
+   "}",
+   "class ItemFactory\n"
+   "where T : new() {\n"
+   "  int f() {}\n"
+   "}",
+   Style, {tooling::Range(43, 13)});
+
   verifyFormat("class Dictionary\n"
"where TKey : IComparable\n"
"where TVal : IMyInterface {\n"
diff --git a/clang/unittests/Format/FormatTestVerilog.cpp 
b/clang/unittests/Format/FormatTestVerilog.cpp
index fcda05df182687..abebf9f7d4c785 100644
--- a/clang/unittests/Format/FormatTestVerilog.cpp
+++ b/clang/unittests/Format/FormatTestVerilog.cpp
@@ -613,6 +613,17 @@ TEST_F(FormatTestVerilog, Headers) {
"  (input var x aaa``x, \\\n"
"   b);",
Style);
+  // When the ports line is not to be formatted, following lines should not 
take
+  // on its indentation.
+  verifyFormat("module x\n"
+   "(output x);\n"
+   "  assign x = 0;\n"
+   "endmodule",
+   "module x\n"
+   "(output x);\n"
+   "assign x = 0;\n"
+   "endmodule",
+   getDefaultStyle(), {tooling::Range(25, 18)});
 }
 
 TEST_F(FormatTestVerilog, Hierarchy) {

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Stop aligning the to continuation lines (PR #76378)

2023-12-25 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-format

Author: None (sstwcw)


Changes

Some unwrapped lines are marked as continuations of the previous lines, for 
example the ports in a Verilog module header.  Previously, if the first line 
following the ports lines was changed, and git-clang-format was run, the 
changed line would be indented by an extra continuation indentation.

---
Full diff: https://github.com/llvm/llvm-project/pull/76378.diff


3 Files Affected:

- (modified) clang/lib/Format/UnwrappedLineFormatter.cpp (+1-1) 
- (modified) clang/unittests/Format/FormatTestCSharp.cpp (+12) 
- (modified) clang/unittests/Format/FormatTestVerilog.cpp (+11) 


``diff
diff --git a/clang/lib/Format/UnwrappedLineFormatter.cpp 
b/clang/lib/Format/UnwrappedLineFormatter.cpp
index 56077499c39d53..2fc15d8828e4be 100644
--- a/clang/lib/Format/UnwrappedLineFormatter.cpp
+++ b/clang/lib/Format/UnwrappedLineFormatter.cpp
@@ -95,7 +95,7 @@ class LevelIndentTracker {
   /// level to the same indent.
   /// Note that \c nextLine must have been called before this method.
   void adjustToUnmodifiedLine(const AnnotatedLine &Line) {
-if (Line.InPPDirective)
+if (Line.InPPDirective || Line.IsContinuation)
   return;
 assert(Line.Level < IndentForLevel.size());
 if (Line.First->is(tok::comment) && IndentForLevel[Line.Level] != -1)
diff --git a/clang/unittests/Format/FormatTestCSharp.cpp 
b/clang/unittests/Format/FormatTestCSharp.cpp
index 4a0840d32341e8..c27e2b576adf73 100644
--- a/clang/unittests/Format/FormatTestCSharp.cpp
+++ b/clang/unittests/Format/FormatTestCSharp.cpp
@@ -1304,6 +1304,18 @@ TEST_F(FormatTestCSharp, CSharpGenericTypeConstraints) {
"}",
Style);
 
+  // When the where line is not to be formatted, following lines should not 
take
+  // on its indentation.
+  verifyFormat("class ItemFactory\n"
+   "where T : new() {\n"
+   "  int f() {}\n"
+   "}",
+   "class ItemFactory\n"
+   "where T : new() {\n"
+   "  int f() {}\n"
+   "}",
+   Style, {tooling::Range(43, 13)});
+
   verifyFormat("class Dictionary\n"
"where TKey : IComparable\n"
"where TVal : IMyInterface {\n"
diff --git a/clang/unittests/Format/FormatTestVerilog.cpp 
b/clang/unittests/Format/FormatTestVerilog.cpp
index fcda05df182687..abebf9f7d4c785 100644
--- a/clang/unittests/Format/FormatTestVerilog.cpp
+++ b/clang/unittests/Format/FormatTestVerilog.cpp
@@ -613,6 +613,17 @@ TEST_F(FormatTestVerilog, Headers) {
"  (input var x aaa``x, \\\n"
"   b);",
Style);
+  // When the ports line is not to be formatted, following lines should not 
take
+  // on its indentation.
+  verifyFormat("module x\n"
+   "(output x);\n"
+   "  assign x = 0;\n"
+   "endmodule",
+   "module x\n"
+   "(output x);\n"
+   "assign x = 0;\n"
+   "endmodule",
+   getDefaultStyle(), {tooling::Range(25, 18)});
 }
 
 TEST_F(FormatTestVerilog, Hierarchy) {

``




https://github.com/llvm/llvm-project/pull/76378
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] Recommit [RISCV] Update the interface of sifive vqmaccqoq (#74284) (PR #75768)

2023-12-25 Thread Craig Topper via cfe-commits

https://github.com/topperc approved this pull request.

Lgtm

https://github.com/llvm/llvm-project/pull/75768
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] support vector subscript expressions in constant evaluator (PR #76379)

2023-12-25 Thread Vikram Hegde via cfe-commits

https://github.com/vikramRH created 
https://github.com/llvm/llvm-project/pull/76379

Feel free to add additional reviewers as relevant,

I'm yet to update float test cases as I'm not sure whether it would be safe to 
directly compare float results in static assert. Would it okay to integer cast 
the results and compare them ?

>From 181a4629f08e7a0e7ec5b3a2406519c26c0d476b Mon Sep 17 00:00:00 2001
From: Vikram 
Date: Wed, 20 Dec 2023 05:36:40 +
Subject: [PATCH] [Clang] support vector subscript expressions in constant
 evaluator

---
 clang/lib/AST/ExprConstant.cpp   |  61 +-
 clang/test/CodeGenCXX/temporaries.cpp|  12 +-
 clang/test/SemaCXX/constexpr-vectors.cpp | 746 ++-
 3 files changed, 668 insertions(+), 151 deletions(-)

diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index f6aeee1a4e935d..0074b8aa00fc75 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -226,6 +226,12 @@ namespace {
 ArraySize = 0;
 MostDerivedLength = I + 1;
 IsArray = false;
+  } else if (Type->isVectorType()) {
+const VectorType *CT = Type->castAs();
+Type = CT->getElementType();
+ArraySize = CT->getNumElements();
+MostDerivedLength = I + 1;
+IsArray = true;
   } else {
 // Path[I] describes a base class.
 ArraySize = 0;
@@ -437,6 +443,15 @@ namespace {
   MostDerivedArraySize = 2;
   MostDerivedPathLength = Entries.size();
 }
+/// Update this designator to refer to the given vector component.
+void addVectorUnchecked(const VectorType *VecTy) {
+  Entries.push_back(PathEntry::ArrayIndex(0));
+
+  MostDerivedType = VecTy->getElementType();
+  MostDerivedIsArrayElement = true;
+  MostDerivedArraySize = VecTy->getNumElements();
+  MostDerivedPathLength = Entries.size();
+}
 void diagnoseUnsizedArrayPointerArithmetic(EvalInfo &Info, const Expr *E);
 void diagnosePointerArithmetic(EvalInfo &Info, const Expr *E,
const APSInt &N);
@@ -1732,6 +1747,10 @@ namespace {
   if (checkSubobject(Info, E, Imag ? CSK_Imag : CSK_Real))
 Designator.addComplexUnchecked(EltTy, Imag);
 }
+void addVector(EvalInfo &Info, const Expr *E, const VectorType *VecTy) {
+  if (checkSubobject(Info, E, CSK_ArrayIndex))
+Designator.addVectorUnchecked(VecTy);
+}
 void clearIsNullPointer() {
   IsNullPtr = false;
 }
@@ -1890,6 +1909,8 @@ static bool EvaluateFixedPointOrInteger(const Expr *E, 
APFixedPoint &Result,
 static bool EvaluateFixedPoint(const Expr *E, APFixedPoint &Result,
EvalInfo &Info);
 
+static bool EvaluateVector(const Expr *E, APValue &Result, EvalInfo &Info);
+
 
//===--===//
 // Misc utilities
 
//===--===//
@@ -3278,6 +3299,19 @@ static bool HandleLValueComplexElement(EvalInfo &Info, 
const Expr *E,
   return true;
 }
 
+static bool HandeLValueVectorComponent(EvalInfo &Info, const Expr *E,
+   LValue &LVal, const VectorType *VecTy,
+   APSInt &Adjustment) {
+  LVal.addVector(Info, E, VecTy);
+
+  CharUnits SizeOfComponent;
+  if (!HandleSizeof(Info, E->getExprLoc(), VecTy->getElementType(),
+SizeOfComponent))
+return false;
+  LVal.adjustOffsetAndIndex(Info, E, Adjustment, SizeOfComponent);
+  return true;
+}
+
 /// Try to evaluate the initializer for a variable declaration.
 ///
 /// \param Info   Information about the ongoing evaluation.
@@ -3718,7 +3752,8 @@ findSubobject(EvalInfo &Info, const Expr *E, const 
CompleteObject &Obj,
 }
 
 // If this is our last pass, check that the final object type is OK.
-if (I == N || (I == N - 1 && ObjType->isAnyComplexType())) {
+if (I == N || (I == N - 1 &&
+   (ObjType->isAnyComplexType() || ObjType->isVectorType( {
   // Accesses to volatile objects are prohibited.
   if (ObjType.isVolatileQualified() && isFormalAccess(handler.AccessKind)) 
{
 if (Info.getLangOpts().CPlusPlus) {
@@ -3823,6 +3858,10 @@ findSubobject(EvalInfo &Info, const Expr *E, const 
CompleteObject &Obj,
 return handler.found(Index ? O->getComplexFloatImag()
: O->getComplexFloatReal(), ObjType);
   }
+} else if (ObjType->isVectorType()) {
+  // Next Subobject is a vector element
+  uint64_t Index = Sub.Entries[I].getAsArrayIndex();
+  O = &O->getVectorElt(Index);
 } else if (const FieldDecl *Field = getAsField(Sub.Entries[I])) {
   if (Field->isMutable() &&
   !Obj.mayAccessMutableMembers(Info, handler.AccessKind)) {
@@ -8756,14 +8795,28 @@ bool LValueExprEvaluator::VisitMemberExpr(const 
MemberExpr *E) {
 }
 
 bool LValueExprEvaluat

[clang] [Clang] support vector subscript expressions in constant evaluator (WIP) (PR #76379)

2023-12-25 Thread Vikram Hegde via cfe-commits

https://github.com/vikramRH edited 
https://github.com/llvm/llvm-project/pull/76379
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] support vector subscript expressions in constant evaluator (WIP) (PR #76379)

2023-12-25 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Vikram Hegde (vikramRH)


Changes

Feel free to add additional reviewers as relevant,

I'm yet to update float test cases as I'm not sure whether it would be safe to 
directly compare float results in static assert. Would it okay to integer cast 
the results and compare them ?

---

Patch is 42.71 KiB, truncated to 20.00 KiB below, full version: 
https://github.com/llvm/llvm-project/pull/76379.diff


3 Files Affected:

- (modified) clang/lib/AST/ExprConstant.cpp (+57-4) 
- (modified) clang/test/CodeGenCXX/temporaries.cpp (+4-8) 
- (modified) clang/test/SemaCXX/constexpr-vectors.cpp (+607-139) 


``diff
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index f6aeee1a4e935d..0074b8aa00fc75 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -226,6 +226,12 @@ namespace {
 ArraySize = 0;
 MostDerivedLength = I + 1;
 IsArray = false;
+  } else if (Type->isVectorType()) {
+const VectorType *CT = Type->castAs();
+Type = CT->getElementType();
+ArraySize = CT->getNumElements();
+MostDerivedLength = I + 1;
+IsArray = true;
   } else {
 // Path[I] describes a base class.
 ArraySize = 0;
@@ -437,6 +443,15 @@ namespace {
   MostDerivedArraySize = 2;
   MostDerivedPathLength = Entries.size();
 }
+/// Update this designator to refer to the given vector component.
+void addVectorUnchecked(const VectorType *VecTy) {
+  Entries.push_back(PathEntry::ArrayIndex(0));
+
+  MostDerivedType = VecTy->getElementType();
+  MostDerivedIsArrayElement = true;
+  MostDerivedArraySize = VecTy->getNumElements();
+  MostDerivedPathLength = Entries.size();
+}
 void diagnoseUnsizedArrayPointerArithmetic(EvalInfo &Info, const Expr *E);
 void diagnosePointerArithmetic(EvalInfo &Info, const Expr *E,
const APSInt &N);
@@ -1732,6 +1747,10 @@ namespace {
   if (checkSubobject(Info, E, Imag ? CSK_Imag : CSK_Real))
 Designator.addComplexUnchecked(EltTy, Imag);
 }
+void addVector(EvalInfo &Info, const Expr *E, const VectorType *VecTy) {
+  if (checkSubobject(Info, E, CSK_ArrayIndex))
+Designator.addVectorUnchecked(VecTy);
+}
 void clearIsNullPointer() {
   IsNullPtr = false;
 }
@@ -1890,6 +1909,8 @@ static bool EvaluateFixedPointOrInteger(const Expr *E, 
APFixedPoint &Result,
 static bool EvaluateFixedPoint(const Expr *E, APFixedPoint &Result,
EvalInfo &Info);
 
+static bool EvaluateVector(const Expr *E, APValue &Result, EvalInfo &Info);
+
 
//===--===//
 // Misc utilities
 
//===--===//
@@ -3278,6 +3299,19 @@ static bool HandleLValueComplexElement(EvalInfo &Info, 
const Expr *E,
   return true;
 }
 
+static bool HandeLValueVectorComponent(EvalInfo &Info, const Expr *E,
+   LValue &LVal, const VectorType *VecTy,
+   APSInt &Adjustment) {
+  LVal.addVector(Info, E, VecTy);
+
+  CharUnits SizeOfComponent;
+  if (!HandleSizeof(Info, E->getExprLoc(), VecTy->getElementType(),
+SizeOfComponent))
+return false;
+  LVal.adjustOffsetAndIndex(Info, E, Adjustment, SizeOfComponent);
+  return true;
+}
+
 /// Try to evaluate the initializer for a variable declaration.
 ///
 /// \param Info   Information about the ongoing evaluation.
@@ -3718,7 +3752,8 @@ findSubobject(EvalInfo &Info, const Expr *E, const 
CompleteObject &Obj,
 }
 
 // If this is our last pass, check that the final object type is OK.
-if (I == N || (I == N - 1 && ObjType->isAnyComplexType())) {
+if (I == N || (I == N - 1 &&
+   (ObjType->isAnyComplexType() || ObjType->isVectorType( {
   // Accesses to volatile objects are prohibited.
   if (ObjType.isVolatileQualified() && isFormalAccess(handler.AccessKind)) 
{
 if (Info.getLangOpts().CPlusPlus) {
@@ -3823,6 +3858,10 @@ findSubobject(EvalInfo &Info, const Expr *E, const 
CompleteObject &Obj,
 return handler.found(Index ? O->getComplexFloatImag()
: O->getComplexFloatReal(), ObjType);
   }
+} else if (ObjType->isVectorType()) {
+  // Next Subobject is a vector element
+  uint64_t Index = Sub.Entries[I].getAsArrayIndex();
+  O = &O->getVectorElt(Index);
 } else if (const FieldDecl *Field = getAsField(Sub.Entries[I])) {
   if (Field->isMutable() &&
   !Obj.mayAccessMutableMembers(Info, handler.AccessKind)) {
@@ -8756,14 +8795,28 @@ bool LValueExprEvaluator::VisitMemberExpr(const 
MemberExpr *E) {
 }
 
 bool LValueExprEvaluator::VisitArraySubscriptExpr(const ArraySubscriptExpr *E) 
{
-  // FIXME: Deal with vectors as array 

[llvm] [clang] Recommit [RISCV] Update the interface of sifive vqmaccqoq (#74284) (PR #75768)

2023-12-25 Thread Brandon Wu via cfe-commits

https://github.com/4vtomat closed 
https://github.com/llvm/llvm-project/pull/75768
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [Clang] support vector subscript expressions in constant evaluator (WIP) (PR #76379)

2023-12-25 Thread Vikram Hegde via cfe-commits

vikramRH wrote:

It seems there are few crashes with systemZ vectors. Looking into them

https://github.com/llvm/llvm-project/pull/76379
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [RISCV] Add MC layer support for Zicfiss. (PR #66043)

2023-12-25 Thread Yeting Kuo via cfe-commits

yetingk wrote:

Ping.

https://github.com/llvm/llvm-project/pull/66043
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [X86] Emit Warnings for frontend options to enable knl/knm. (PR #75580)

2023-12-25 Thread Freddy Ye via cfe-commits

FreddyLeaf wrote:

> Can you give me a better idea of the stages you intend to follow with this. 
> The patch title suggests removing all KNL/KNM handling but the patch itself 
> looks to be just about the KNL/KNM specific features.

I have created a draft PR to do removal in next release: 
https://github.com/llvm/llvm-project/pull/76383. Comments are welcome there. 
For this PR, I added warnings to features only but not cpuname, mainly to 
reduce efforts. Especially when using `-march=native` on a knl machine, these 
warnings can also be emitted.

https://github.com/llvm/llvm-project/pull/75580
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [X86] Emit Warnings for frontend options to enable knl/knm. (PR #75580)

2023-12-25 Thread Freddy Ye via cfe-commits

https://github.com/FreddyLeaf updated 
https://github.com/llvm/llvm-project/pull/75580

>From e16afbdc9f0c04bad0e8f80f90c0eb26c13d3326 Mon Sep 17 00:00:00 2001
From: Freddy Ye 
Date: Fri, 15 Dec 2023 16:50:23 +0800
Subject: [PATCH 1/5] [X86] Emit Warnings for frontend options to enable
 knl/knm.

Since Knight Landing and Knight Mill microarchitectures are EOL, we
would like to remove its support in LLVM 19. In LLVM 18, we will first
emit a warning for the usage.
---
 clang/include/clang/Basic/DiagnosticCommonKinds.td |  2 ++
 clang/lib/Basic/Targets/X86.cpp|  3 +++
 clang/test/CodeGen/X86/avx512er-builtins.c |  2 +-
 clang/test/CodeGen/X86/avx512pf-builtins.c |  2 +-
 clang/test/Driver/cl-x86-flags.c   | 10 --
 clang/test/Frontend/x86-target-cpu.c   | 10 --
 clang/test/Misc/warning-flags.c|  3 ++-
 7 files changed, 25 insertions(+), 7 deletions(-)

diff --git a/clang/include/clang/Basic/DiagnosticCommonKinds.td 
b/clang/include/clang/Basic/DiagnosticCommonKinds.td
index 65a33f61a6948a..40841e9df547bc 100644
--- a/clang/include/clang/Basic/DiagnosticCommonKinds.td
+++ b/clang/include/clang/Basic/DiagnosticCommonKinds.td
@@ -349,6 +349,8 @@ def warn_invalid_feature_combination : Warning<
 def warn_target_unrecognized_env : Warning<
   "mismatch between architecture and environment in target triple '%0'; did 
you mean '%1'?">,
   InGroup;
+def warn_knl_knm_target_supports_remove : Warning<
+  "KNL/KNM's feature support will be removed in LLVM 19.">;
 
 // Source manager
 def err_cannot_open_file : Error<"cannot open file '%0': %1">, DefaultFatal;
diff --git a/clang/lib/Basic/Targets/X86.cpp b/clang/lib/Basic/Targets/X86.cpp
index b97f88647fa49f..dc56524d378104 100644
--- a/clang/lib/Basic/Targets/X86.cpp
+++ b/clang/lib/Basic/Targets/X86.cpp
@@ -295,11 +295,13 @@ bool 
X86TargetInfo::handleTargetFeatures(std::vector &Features,
   HasAVX512BF16 = true;
 } else if (Feature == "+avx512er") {
   HasAVX512ER = true;
+  Diags.Report(diag::warn_knl_knm_target_supports_remove);
 } else if (Feature == "+avx512fp16") {
   HasAVX512FP16 = true;
   HasLegalHalfType = true;
 } else if (Feature == "+avx512pf") {
   HasAVX512PF = true;
+  Diags.Report(diag::warn_knl_knm_target_supports_remove);
 } else if (Feature == "+avx512dq") {
   HasAVX512DQ = true;
 } else if (Feature == "+avx512bitalg") {
@@ -358,6 +360,7 @@ bool 
X86TargetInfo::handleTargetFeatures(std::vector &Features,
   HasPREFETCHI = true;
 } else if (Feature == "+prefetchwt1") {
   HasPREFETCHWT1 = true;
+  Diags.Report(diag::warn_knl_knm_target_supports_remove);
 } else if (Feature == "+clzero") {
   HasCLZERO = true;
 } else if (Feature == "+cldemote") {
diff --git a/clang/test/CodeGen/X86/avx512er-builtins.c 
b/clang/test/CodeGen/X86/avx512er-builtins.c
index ee31236a3c01aa..11ec6aabec1e3f 100644
--- a/clang/test/CodeGen/X86/avx512er-builtins.c
+++ b/clang/test/CodeGen/X86/avx512er-builtins.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -flax-vector-conversions=none -ffreestanding %s 
-triple=x86_64-apple-darwin -target-feature +avx512f -target-feature +avx512er 
-emit-llvm -o - -Wall -Werror | FileCheck %s
+// RUN: %clang_cc1 -flax-vector-conversions=none -ffreestanding %s 
-triple=x86_64-apple-darwin -target-feature +avx512f -target-feature +avx512er 
-emit-llvm -o - -Wall | FileCheck %s
 
 
 #include 
diff --git a/clang/test/CodeGen/X86/avx512pf-builtins.c 
b/clang/test/CodeGen/X86/avx512pf-builtins.c
index 4ca70f5787968b..3a117ed6a9460e 100644
--- a/clang/test/CodeGen/X86/avx512pf-builtins.c
+++ b/clang/test/CodeGen/X86/avx512pf-builtins.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -flax-vector-conversions=none -ffreestanding %s 
-triple=x86_64-apple-darwin -target-feature +avx512pf -emit-llvm -o - -Wall 
-Werror | FileCheck %s
+// RUN: %clang_cc1 -flax-vector-conversions=none -ffreestanding %s 
-triple=x86_64-apple-darwin -target-feature +avx512pf -emit-llvm -o - -Wall | 
FileCheck %s
 
 
 #include 
diff --git a/clang/test/Driver/cl-x86-flags.c b/clang/test/Driver/cl-x86-flags.c
index 51b16f0ce35463..ae35a312fe8a4b 100644
--- a/clang/test/Driver/cl-x86-flags.c
+++ b/clang/test/Driver/cl-x86-flags.c
@@ -69,7 +69,10 @@
 // RUN: %clang_cl -m32 -arch:avx2 --target=i386-pc-windows -### -- 2>&1 %s | 
FileCheck -check-prefix=avx2 %s
 // avx2: invalid /arch: argument
 
-// RUN: %clang_cl -m32 -arch:AVX512F --target=i386-pc-windows /c /Fo%t.obj 
-Xclang -verify -DTEST_32_ARCH_AVX512F -- %s
+// RUN: %clang_cl -m32 -arch:AVX512F --target=i386-pc-windows /c /Fo%t.obj 
-Xclang -verify=KNL1 -DTEST_32_ARCH_AVX512F -- %s
+// KNL1-warning@*:* {{KNL/KNM's feature support will be removed in LLVM 19.}}
+// KNL1-warning@*:* {{KNL/KNM's feature support will be removed in LLVM 19.}}
+// KNL1-warning@*:* {{KNL/KNM's feature support will be removed in LLVM 19.}}
 #if defined(TEST_32_ARCH_AVX512F)
 #if _M_IX86_FP !=

[clang] [clang-tools-extra] [llvm] [MCP] Enhance MCP copy Instruction removal for special case(reapply) (PR #74239)

2023-12-25 Thread via cfe-commits

https://github.com/LWenH updated https://github.com/llvm/llvm-project/pull/74239

>From 8e7399015e74059731ea19468d2ee514a9a3e9a4 Mon Sep 17 00:00:00 2001
From: LWenH <924105...@qq.com>
Date: Sun, 3 Dec 2023 19:59:49 +0800
Subject: [PATCH 1/2] [mcp] Bug fix for reverted patch 70778

In pr 70778, when we clobbering a register (Def), we also locate and remove the 
entry in the Copy Maps that indicates
Src defined Def. If the "DefRegs" record is empty after deletion, we directly 
remove the corresponding SrcCopy entry
from the Copy Maps.  However, since the SrcCopy may also have documented other 
Def' records, directly removing
it is unsafe. We need to enhance the criteria for removing empty records to 
ensure safety.
---
 llvm/lib/CodeGen/MachineCopyPropagation.cpp   | 42 ++-
 .../CodeGen/AMDGPU/mcp-implicit-clobber.mir   | 26 
 .../RISCV/rvv/fixed-vectors-nearbyint-vp.ll   |  1 -
 llvm/test/CodeGen/X86/shift-i128.ll   |  4 --
 llvm/test/CodeGen/X86/shift-i256.ll   |  1 -
 .../X86/smulo-128-legalisation-lowering.ll|  2 +-
 .../vector-interleaved-load-i16-stride-7.ll   |  4 +-
 .../vector-interleaved-load-i64-stride-7.ll   |  2 +-
 .../vector-interleaved-load-i8-stride-5.ll|  3 +-
 .../vector-interleaved-load-i8-stride-7.ll| 26 ++--
 .../vector-interleaved-load-i8-stride-8.ll|  4 +-
 .../vector-interleaved-store-i16-stride-7.ll  |  3 +-
 .../X86/wide-scalar-shift-legalization.ll | 18 ++--
 13 files changed, 89 insertions(+), 47 deletions(-)
 create mode 100644 llvm/test/CodeGen/AMDGPU/mcp-implicit-clobber.mir

diff --git a/llvm/lib/CodeGen/MachineCopyPropagation.cpp 
b/llvm/lib/CodeGen/MachineCopyPropagation.cpp
index a032b31a1fc7c6..51e944d0279f27 100644
--- a/llvm/lib/CodeGen/MachineCopyPropagation.cpp
+++ b/llvm/lib/CodeGen/MachineCopyPropagation.cpp
@@ -175,8 +175,46 @@ class CopyTracker {
 if (MachineInstr *MI = I->second.MI) {
   std::optional CopyOperands =
   isCopyInstr(*MI, TII, UseCopyInstr);
-  markRegsUnavailable({CopyOperands->Destination->getReg().asMCReg()},
-  TRI);
+
+  MCRegister Def = CopyOperands->Destination->getReg().asMCReg();
+  MCRegister Src = CopyOperands->Source->getReg().asMCReg();
+
+  markRegsUnavailable(Def, TRI);
+
+  // Since we clobber the destination of a copy, the semantic of Src's
+  // "DefRegs" to contain Def is no longer effectual. We will also need
+  // to remove the record from the copy maps that indicates Src defined
+  // Def. Failing to do so might cause the target to miss some
+  // opportunities to further eliminate redundant copy instructions.
+  // Consider the following sequence during the
+  // ForwardCopyPropagateBlock procedure:
+  // L1: r0 = COPY r9 <- TrackMI
+  // L2: r0 = COPY r8 <- TrackMI (Remove r9 defined r0 from 
tracker)
+  // L3: use r0   <- Remove L2 from MaybeDeadCopies
+  // L4: early-clobber r9 <- Clobber r9 (L2 is still valid in tracker)
+  // L5: r0 = COPY r8 <- Remove NopCopy
+  for (MCRegUnit SrcUnit : TRI.regunits(Src)) {
+auto SrcCopy = Copies.find(SrcUnit);
+if (SrcCopy != Copies.end() && SrcCopy->second.LastSeenUseInCopy) {
+  // If SrcCopy defines multiple values, we only need
+  // to erase the record for Def in DefRegs.
+  for (auto itr = SrcCopy->second.DefRegs.begin();
+   itr != SrcCopy->second.DefRegs.end(); itr++) {
+if (*itr == Def) {
+  SrcCopy->second.DefRegs.erase(itr);
+  // If DefReg becomes empty after removal, we can remove the
+  // SrcCopy from the tracker's copy maps. We only remove those
+  // entries solely record the Def is defined by Src. If an
+  // entry also contains the definition record of other Def'
+  // registers, it cannot be cleared.
+  if (SrcCopy->second.DefRegs.empty() && !SrcCopy->second.MI) {
+Copies.erase(SrcCopy);
+  }
+  break;
+}
+  }
+}
+  }
 }
 // Now we can erase the copy.
 Copies.erase(I);
diff --git a/llvm/test/CodeGen/AMDGPU/mcp-implicit-clobber.mir 
b/llvm/test/CodeGen/AMDGPU/mcp-implicit-clobber.mir
new file mode 100644
index 00..6e613243e38c59
--- /dev/null
+++ b/llvm/test/CodeGen/AMDGPU/mcp-implicit-clobber.mir
@@ -0,0 +1,26 @@
+# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py 
UTC_ARGS: --version 4
+# RUN:  llc -march=amdgcn -mcpu=gfx900 %s -o - -run-pass machine-cp 
-verify-machineinstrs | FileCheck %s
+
+# The MachineCopyPropagation Pass should not treat the subsequent
+# instruction "$sgpr2_sgpr3 = COPY $sgpr6_sgpr7" as a NopCopy.

[clang] [flang] [flang][driver] Remove Fortain_main static library from linking stages (PR #75816)

2023-12-25 Thread Michael Klemm via cfe-commits

mjklemm wrote:

Thanks for all the good suggestions! 

https://github.com/llvm/llvm-project/pull/75816
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [RISCV] Add MC layer support for Zicfiss. (PR #66043)

2023-12-25 Thread Craig Topper via cfe-commits

https://github.com/topperc approved this pull request.

LGTM

https://github.com/llvm/llvm-project/pull/66043
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] Allow to pass config file to clang-tidy-diff (PR #75457)

2023-12-25 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL closed 
https://github.com/llvm/llvm-project/pull/75457
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] c019ed9 - Allow to pass config file to clang-tidy-diff (#75457)

2023-12-25 Thread via cfe-commits

Author: Michael Lettrich
Date: 2023-12-26T08:40:40+01:00
New Revision: c019ed972f95cd17838b6d01257383539a5d889c

URL: 
https://github.com/llvm/llvm-project/commit/c019ed972f95cd17838b6d01257383539a5d889c
DIFF: 
https://github.com/llvm/llvm-project/commit/c019ed972f95cd17838b6d01257383539a5d889c.diff

LOG: Allow to pass config file to clang-tidy-diff (#75457)

Adds a `-config-file` command line option that passes on the path of
.`clang-tidy` or custom config file to the `clang-tidy` executable.

Added: 


Modified: 
clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
clang-tools-extra/docs/ReleaseNotes.rst

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/tool/clang-tidy-
diff .py b/clang-tools-extra/clang-tidy/tool/clang-tidy-
diff .py
index 8817e2914f6e25..d96b3450fdbe81 100755
--- a/clang-tools-extra/clang-tidy/tool/clang-tidy-
diff .py
+++ b/clang-tools-extra/clang-tidy/tool/clang-tidy-
diff .py
@@ -173,6 +173,12 @@ def main():
 help="checks filter, when not specified, use clang-tidy " "default",
 default="",
 )
+parser.add_argument(
+"-config-file",
+dest="config_file",
+help="Specify the path of .clang-tidy or custom config file",
+default="",
+)
 parser.add_argument("-use-color", action="store_true", help="Use colors in 
output")
 parser.add_argument(
 "-path", dest="build_path", help="Path used to read a compile command 
database."
@@ -313,6 +319,8 @@ def main():
 common_clang_tidy_args.append("-fix")
 if args.checks != "":
 common_clang_tidy_args.append("-checks=" + args.checks)
+if args.config_file != "":
+common_clang_tidy_args.append("-config-file=" + args.config_file)
 if args.quiet:
 common_clang_tidy_args.append("-quiet")
 if args.build_path is not None:

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index c843efac754ce0..00f570bcd21842 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -119,15 +119,22 @@ Improvements to clang-tidy
 
 - Improved `--dump-config` to print check options in alphabetical order.
 
-- Improved :program:`clang-tidy-
diff .py` script. It now returns exit code `1`
-  if any :program:`clang-tidy` subprocess exits with a non-zero code or if
-  exporting fixes fails. It now accepts a directory as a value for
-  `-export-fixes` to export individual yaml files for each compilation unit.
+- Improved :program:`clang-tidy-
diff .py` script. 
+* Return exit code `1` if any :program:`clang-tidy` subprocess exits with
+  a non-zero code or if exporting fixes fails.
+
+* Accept a directory as a value for `-export-fixes` to export individual
+  yaml files for each compilation unit.
+
+* Introduce a `-config-file` option that forwards a configuration file to
+  :program:`clang-tidy`. Corresponds to the `--config-file` option in
+  :program:`clang-tidy`.
 
 - Improved :program:`run-clang-tidy.py` script. It now accepts a directory
   as a value for `-export-fixes` to export individual yaml files for each
   compilation unit.
 
+
 New checks
 ^^
 



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [RISCV] Add MC layer support for Zicfiss. (PR #66043)

2023-12-25 Thread Wang Pengcheng via cfe-commits

wangpc-pp wrote:

Should this be rebased on 
Zimop(https://github.com/llvm/llvm-project/pull/75182) commit? Though I don't 
know why it has been merged yet...

https://github.com/llvm/llvm-project/pull/66043
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-tools-extra] [llvm] [MCP] Enhance MCP copy Instruction removal for special case(reapply) (PR #74239)

2023-12-25 Thread via cfe-commits

LWenH wrote:

Since the corner case bug of https://github.com/llvm/llvm-project/issues/73512 
has been addressed and fixed, and the original patch for this reapply 
https://github.com/llvm/llvm-project/pull/70778 has been approved, I try to 
recommit this patch :-)

https://github.com/llvm/llvm-project/pull/74239
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits