[clang] c804e86 - [RISCV][VLS] Support RISCV VLS calling convention (#100346)

2025-03-02 Thread via cfe-commits

Author: Brandon Wu
Date: 2025-03-03T12:39:35+08:00
New Revision: c804e86f558a42f328946331af391d700747fa90

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

LOG: [RISCV][VLS] Support RISCV VLS calling convention (#100346)

This patch adds a function attribute `riscv_vls_cc` for RISCV VLS
calling
convention which takes 0 or 1 argument, the argument is the `ABI_VLEN`
which is the `VLEN` for passing the fixed-vector arguments, it wraps the
argument as a scalable vector(VLA) using the `ABI_VLEN` and uses the
corresponding mechanism to handle it. The range of `ABI_VLEN` is [32,
65536],
if not specified, the default value is 128.

Here is an example of VLS argument passing:
Non-VLS call:
```
  void original_call(__attribute__((vector_size(16))) int arg) {}
=>
  define void @original_call(i128 noundef %arg) {
  entry:
...
ret void
  }
```
VLS call:
```
  void __attribute__((riscv_vls_cc(256))) 
vls_call(__attribute__((vector_size(16))) int arg) {}
=>
  define riscv_vls_cc void @vls_call( %arg) {
  entry:
...
ret void
  }
}
```

The first Non-VLS call passes generic vector argument of 16 bytes by
flattened integer.
On the contrary, the VLS call uses `ABI_VLEN=256` which wraps the
vector to  where the number of scalable vector
elements
is calaulated by: `ORIG_ELTS * RVV_BITS_PER_BLOCK / ABI_VLEN`.
Note: ORIG_ELTS = Vector Size / Type Size = 128 / 32 = 4.

PsABI PR: https://github.com/riscv-non-isa/riscv-elf-psabi-doc/pull/418
C-API PR: https://github.com/riscv-non-isa/riscv-c-api-doc/pull/68

Added: 
llvm/test/Assembler/riscv_vls_cc.ll

Modified: 
clang/include/clang-c/Index.h
clang/include/clang/AST/Type.h
clang/include/clang/Basic/Attr.td
clang/include/clang/Basic/AttrDocs.td
clang/include/clang/Basic/Specifiers.h
clang/lib/AST/ItaniumMangle.cpp
clang/lib/AST/Type.cpp
clang/lib/AST/TypePrinter.cpp
clang/lib/Basic/Targets/RISCV.cpp
clang/lib/CodeGen/CGCall.cpp
clang/lib/CodeGen/CGDebugInfo.cpp
clang/lib/CodeGen/Targets/RISCV.cpp
clang/lib/Sema/SemaDeclAttr.cpp
clang/lib/Sema/SemaType.cpp
clang/test/CodeGen/RISCV/riscv-vector-callingconv-llvm-ir.c
clang/test/CodeGen/RISCV/riscv-vector-callingconv-llvm-ir.cpp
clang/test/CodeGen/RISCV/riscv-vector-callingconv.c
clang/test/CodeGen/RISCV/riscv-vector-callingconv.cpp
clang/tools/libclang/CXType.cpp
llvm/include/llvm/AsmParser/LLToken.h
llvm/include/llvm/BinaryFormat/Dwarf.def
llvm/include/llvm/IR/CallingConv.h
llvm/lib/AsmParser/LLLexer.cpp
llvm/lib/AsmParser/LLParser.cpp
llvm/lib/IR/AsmWriter.cpp
llvm/lib/Target/RISCV/RISCVISelLowering.cpp
llvm/test/Bitcode/compatibility.ll

Removed: 




diff  --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h
index 3a511de553ad4..c50410dc365b6 100644
--- a/clang/include/clang-c/Index.h
+++ b/clang/include/clang-c/Index.h
@@ -3061,6 +3061,18 @@ enum CXCallingConv {
   CXCallingConv_M68kRTD = 19,
   CXCallingConv_PreserveNone = 20,
   CXCallingConv_RISCVVectorCall = 21,
+  CXCallingConv_RISCVVLSCall_32 = 22,
+  CXCallingConv_RISCVVLSCall_64 = 23,
+  CXCallingConv_RISCVVLSCall_128 = 24,
+  CXCallingConv_RISCVVLSCall_256 = 25,
+  CXCallingConv_RISCVVLSCall_512 = 26,
+  CXCallingConv_RISCVVLSCall_1024 = 27,
+  CXCallingConv_RISCVVLSCall_2048 = 28,
+  CXCallingConv_RISCVVLSCall_4096 = 29,
+  CXCallingConv_RISCVVLSCall_8192 = 30,
+  CXCallingConv_RISCVVLSCall_16384 = 31,
+  CXCallingConv_RISCVVLSCall_32768 = 32,
+  CXCallingConv_RISCVVLSCall_65536 = 33,
 
   CXCallingConv_Invalid = 100,
   CXCallingConv_Unexposed = 200

diff  --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index c3ff7ebd88516..3cd2be2d2170a 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -1946,7 +1946,7 @@ class alignas(TypeAlignment) Type : public 
ExtQualsTypeCommonBase {
 /// Extra information which affects how the function is called, like
 /// regparm and the calling convention.
 LLVM_PREFERRED_TYPE(CallingConv)
-unsigned ExtInfo : 13;
+unsigned ExtInfo : 14;
 
 /// The ref-qualifier associated with a \c FunctionProtoType.
 ///
@@ -4438,19 +4438,16 @@ class FunctionType : public Type {
 // Type::FunctionTypeBitfields::ExtInfo as well.
 
 // |  CC  
|noreturn|produces|nocallersavedregs|regparm|nocfcheck|cmsenscall|
-// |0 .. 4|   5|6   |   7 |8 .. 10|11   |12
|
+// |0 .. 5|   6|7   |   8 |9 .. 11|12   |13
|
 //
 // regparm is either 0 (no regparm attribute) or the regparm value+1.
-enum { CallConvMask = 0x1F };
-enum { NoReturnMask = 0x20 };
-enum { ProducesResultMask = 0x40 };
-enum { NoCallerSavedRegsMask = 0x80 };
-

[clang-tools-extra] [clang-tidy] Add new check `readability-use-numeric-limits` (PR #127430)

2025-03-02 Thread Katherine Whitlock via cfe-commits


@@ -0,0 +1,163 @@
+//===--- UseNumericLimitsCheck.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 "UseNumericLimitsCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Preprocessor.h"
+#include 
+#include 
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::readability {
+
+UseNumericLimitsCheck::UseNumericLimitsCheck(StringRef Name,
+ ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  SignedConstants{
+  {std::numeric_limits::min(),
+   "std::numeric_limits::min()"},
+  {std::numeric_limits::max(),
+   "std::numeric_limits::max()"},
+  {std::numeric_limits::min(),
+   "std::numeric_limits::min()"},
+  {std::numeric_limits::max(),
+   "std::numeric_limits::max()"},
+  {std::numeric_limits::min(),
+   "std::numeric_limits::min()"},
+  {std::numeric_limits::max(),
+   "std::numeric_limits::max()"},
+  {std::numeric_limits::min(),
+   "std::numeric_limits::min()"},
+  {std::numeric_limits::max(),
+   "std::numeric_limits::max()"},
+  },
+  UnsignedConstants{
+  {std::numeric_limits::max(),
+   "std::numeric_limits::max()"},
+  {std::numeric_limits::max(),
+   "std::numeric_limits::max()"},
+  {std::numeric_limits::max(),
+   "std::numeric_limits::max()"},
+  {std::numeric_limits::max(),
+   "std::numeric_limits::max()"},
+  },
+  Inserter(Options.getLocalOrGlobal("IncludeStyle",
+utils::IncludeSorter::IS_LLVM),
+   areDiagsSelfContained()) {}
+
+void UseNumericLimitsCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
+  Options.store(Opts, "IncludeStyle", Inserter.getStyle());
+}
+
+void UseNumericLimitsCheck::registerMatchers(MatchFinder *Finder) {
+  auto PositiveIntegerMatcher = [](auto Value) {
+return unaryOperator(
+hasOperatorName("+"),
+hasUnaryOperand(
+integerLiteral(equals(Value)).bind("positive-integer-literal")));
+  };
+
+  auto NegativeIntegerMatcher = [](auto Value) {
+return unaryOperator(
+hasOperatorName("-"),
+hasUnaryOperand(
+integerLiteral(equals(-Value)).bind("negative-integer-literal")));
+  };
+
+  auto BareIntegerMatcher = [](auto Value) {
+return integerLiteral(allOf(unless(hasParent(unaryOperator(
+hasAnyOperatorName("-", "+",
+equals(Value)))
+.bind("bare-integer-literal");
+  };
+
+  for (const auto &[Value, _] : SignedConstants) {
+if (Value < 0) {
+  Finder->addMatcher(
+  expr(NegativeIntegerMatcher(Value)).bind("unary-op-exp"), this);
+} else {
+  Finder->addMatcher(
+  expr(anyOf(PositiveIntegerMatcher(Value), BareIntegerMatcher(Value)))
+  .bind("unary-op-exp"),
+  this);
+}
+  }
+
+  for (const auto &[Value, _] : UnsignedConstants) {
+Finder->addMatcher(
+expr(anyOf(PositiveIntegerMatcher(Value), BareIntegerMatcher(Value)))
+.bind("unary-op-exp"),
+this);
+  }
+}
+
+void UseNumericLimitsCheck::registerPPCallbacks(
+const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) 
{
+  Inserter.registerPreprocessor(PP);
+}
+
+void UseNumericLimitsCheck::check(const MatchFinder::MatchResult &Result) {
+  const IntegerLiteral *MatchedDecl = nullptr;
+
+  const IntegerLiteral *NegativeMatchedDecl =
+  Result.Nodes.getNodeAs("negative-integer-literal");
+  const IntegerLiteral *PositiveMatchedDecl =
+  Result.Nodes.getNodeAs("positive-integer-literal");
+  const IntegerLiteral *BareMatchedDecl =
+  Result.Nodes.getNodeAs("bare-integer-literal");
+
+  if (NegativeMatchedDecl != nullptr) {
+MatchedDecl = NegativeMatchedDecl;
+  } else if (PositiveMatchedDecl != nullptr) {
+MatchedDecl = PositiveMatchedDecl;
+  } else if (BareMatchedDecl != nullptr) {
+MatchedDecl = BareMatchedDecl;
+  }
+
+  const llvm::APInt MatchedIntegerConstant = MatchedDecl->getValue();
+
+  auto Fixer = [&](auto SourceValue, auto Value,
+   const std::string &Replacement) {

stellar-aria wrote:

if I use a template parameter list as in
```c++
auto Fixer = [&](ValueType SourceValue, ValueType Value, ...
```
I get a warning that explicit template parameter lists for lambdas are a C++20 
extension?

Using a static_assert like
```c++
static_assert(std::is_same_v);
```
and/or an enable_if a

[clang] e6aae2a - [analyzer] Handle structured bindings in alpha.webkit.UncountedCallArgsChecker (#129424)

2025-03-02 Thread via cfe-commits

Author: Oliver Hunt
Date: 2025-03-02T20:30:06-08:00
New Revision: e6aae2a4905982c10412e7f35b4f3c940a1a86f5

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

LOG: [analyzer] Handle structured bindings in 
alpha.webkit.UncountedCallArgsChecker (#129424)

Simply add awareness of BindingDecl to the logic for identifying local
assignments.

Added: 
clang/test/Analysis/Checkers/WebKit/binding-to-refptr.cpp

Modified: 
clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
index dc86c4fcc64b1..58020ec4e084d 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
@@ -140,9 +140,14 @@ bool tryToFindPtrOrigin(
 bool isASafeCallArg(const Expr *E) {
   assert(E);
   if (auto *Ref = dyn_cast(E)) {
-if (auto *D = dyn_cast_or_null(Ref->getFoundDecl())) {
+auto *FoundDecl = Ref->getFoundDecl();
+if (auto *D = dyn_cast_or_null(FoundDecl)) {
   if (isa(D) || D->isLocalVarDecl())
 return true;
+} else if (auto *BD = dyn_cast_or_null(FoundDecl)) {
+  VarDecl *VD = BD->getHoldingVar();
+  if (VD && (isa(VD) || VD->isLocalVarDecl()))
+return true;
 }
   }
   if (isConstOwnerPtrMemberExpr(E))

diff  --git a/clang/test/Analysis/Checkers/WebKit/binding-to-refptr.cpp 
b/clang/test/Analysis/Checkers/WebKit/binding-to-refptr.cpp
new file mode 100644
index 0..012868fcb329a
--- /dev/null
+++ b/clang/test/Analysis/Checkers/WebKit/binding-to-refptr.cpp
@@ -0,0 +1,36 @@
+// RUN: %clang_analyze_cc1 
-analyzer-checker=alpha.webkit.UncountedCallArgsChecker -verify %s -std=c++2c
+// RUN: %clang_analyze_cc1 
-analyzer-checker=alpha.webkit.UncheckedLocalVarsChecker -verify %s -std=c++2c
+
+// expected-no-diagnostics
+
+#include "mock-types.h"
+
+class Node {
+public:
+Node* nextSibling() const;
+
+void ref() const;
+void deref() const;
+};
+
+template  struct pair {
+  A a;
+  B b;
+  template  requires ( I == 0 ) A& get();
+  template  requires ( I == 1 ) B& get();
+};
+
+namespace std {
+template  struct tuple_size;
+template  struct tuple_element;
+template  struct tuple_size<::pair> { static 
constexpr int value = 2; };
+template  struct tuple_element<0, ::pair> { using 
type = A; };
+template  struct tuple_element<1, ::pair> { using 
type = B; };
+}
+
+pair, RefPtr> &getPair();
+
+static void testUnpackedAssignment() {
+auto [a, b] = getPair();
+a->nextSibling();
+}



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


[clang-tools-extra] e9c8d42 - [clang-tidy] `misc-unused-using-decls`: add correct handling of `operator""` with template parametes (#129392)

2025-03-02 Thread via cfe-commits

Author: Baranov Victor
Date: 2025-03-03T13:14:27+08:00
New Revision: e9c8d42b895fe4934a149478788fa020bd69f7bf

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

LOG: [clang-tidy] `misc-unused-using-decls`: add correct handling of 
`operator""` with template parametes (#129392)

Fixes false-positives when operator"" has template paremetes, e.g.
```cpp
template 
int operator""_r() {
return {};
}
```
Closes https://github.com/llvm/llvm-project/issues/53444.

-

Co-authored-by: Congcong Cai 

Added: 


Modified: 
clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/test/clang-tidy/checkers/misc/unused-using-decls.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
index 5d74907aa9fab..d5c5fa3364d63 100644
--- a/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/UnusedUsingDeclsCheck.cpp
@@ -184,8 +184,16 @@ void UnusedUsingDeclsCheck::check(const 
MatchFinder::MatchResult &Result) {
 return;
   }
   // Check user-defined literals
-  if (const auto *UDL = Result.Nodes.getNodeAs("used"))
-removeFromFoundDecls(UDL->getCalleeDecl());
+  if (const auto *UDL = Result.Nodes.getNodeAs("used")) {
+const Decl *CalleeDecl = UDL->getCalleeDecl();
+if (const auto *FD = dyn_cast(CalleeDecl)) {
+  if (const FunctionTemplateDecl *FPT = FD->getPrimaryTemplate()) {
+removeFromFoundDecls(FPT);
+return;
+  }
+}
+removeFromFoundDecls(CalleeDecl);
+  }
 }
 
 void UnusedUsingDeclsCheck::removeFromFoundDecls(const Decl *D) {

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 71edb704b49d6..ce1418a2a7d58 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -138,6 +138,10 @@ Changes in existing checks
   ` check by fixing false 
negatives
   on ternary operators calling ``std::move``.
 
+- Improved :doc:`misc-unused-using-decls
+  ` check by fixing false positives
+  on ``operator""`` with template parameters.
+
 Removed checks
 ^^
 

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/misc/unused-using-decls.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/misc/unused-using-decls.cpp
index 12fc18f340f21..62aa17b0b1c22 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/misc/unused-using-decls.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/misc/unused-using-decls.cpp
@@ -222,3 +222,19 @@ using gh69714::StructGH69714_1;
 using gh69714::StructGH69714_2;
 struct StructGH69714_1 a;
 struct StructGH69714_2 *b;
+
+namespace gh53444 {
+namespace my_literals {
+  template 
+  int operator""_r() {
+return {};
+  }
+}
+
+using my_literals::operator"" _r;
+
+int foo() {
+  auto x2 = 123_r;
+}
+
+}



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


[clang] f5f3612 - [clang][LoongArch] Add OHOS target (#127555)

2025-03-02 Thread via cfe-commits

Author: Ami-zhang
Date: 2025-03-03T09:25:49+08:00
New Revision: f5f3612453fb3568a76056daea41f67df82636af

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

LOG: [clang][LoongArch] Add OHOS target (#127555)

Add support for OHOS on loongarch64.

Added: 

clang/test/Driver/Inputs/ohos_native_tree/llvm/lib/clang/x.y.z/lib/loongarch64-linux-ohos/.keep

clang/test/Driver/Inputs/ohos_native_tree/llvm/lib/clang/x.y.z/lib/loongarch64-linux-ohos/clang_rt.crtbegin.o

clang/test/Driver/Inputs/ohos_native_tree/llvm/lib/clang/x.y.z/lib/loongarch64-linux-ohos/clang_rt.crtend.o

clang/test/Driver/Inputs/ohos_native_tree/llvm/lib/clang/x.y.z/lib/loongarch64-linux-ohos/libclang_rt.builtins.a

clang/test/Driver/Inputs/ohos_native_tree/sysroot/usr/include/loongarch64-linux-ohos/.keep

clang/test/Driver/Inputs/ohos_native_tree/sysroot/usr/lib/loongarch64-linux-ohos/.keep

Modified: 
clang/lib/Basic/Targets.cpp
clang/lib/Driver/ToolChains/OHOS.cpp
clang/test/Driver/ohos.c
clang/test/Preprocessor/ohos.c

Removed: 




diff  --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp
index 281aebdb1c35d..c6d228fe98100 100644
--- a/clang/lib/Basic/Targets.cpp
+++ b/clang/lib/Basic/Targets.cpp
@@ -749,8 +749,14 @@ std::unique_ptr AllocateTarget(const 
llvm::Triple &Triple,
   case llvm::Triple::loongarch64:
 switch (os) {
 case llvm::Triple::Linux:
-  return std::make_unique>(Triple,
-  Opts);
+  switch (Triple.getEnvironment()) {
+  default:
+return std::make_unique>(Triple,
+Opts);
+  case llvm::Triple::OpenHOS:
+return std::make_unique>(Triple,
+   Opts);
+  }
 case llvm::Triple::FreeBSD:
   return std::make_unique>(Triple,
 Opts);

diff  --git a/clang/lib/Driver/ToolChains/OHOS.cpp 
b/clang/lib/Driver/ToolChains/OHOS.cpp
index 6e1a09ae908b2..e213c695a9fef 100644
--- a/clang/lib/Driver/ToolChains/OHOS.cpp
+++ b/clang/lib/Driver/ToolChains/OHOS.cpp
@@ -111,6 +111,8 @@ std::string OHOS::getMultiarchTriple(const llvm::Triple &T) 
const {
 return "x86_64-linux-ohos";
   case llvm::Triple::aarch64:
 return "aarch64-linux-ohos";
+  case llvm::Triple::loongarch64:
+return "loongarch64-linux-ohos";
   }
   return T.str();
 }
@@ -368,7 +370,9 @@ void OHOS::addExtraOpts(llvm::opt::ArgStringList &CmdArgs) 
const {
   CmdArgs.push_back("-z");
   CmdArgs.push_back("relro");
   CmdArgs.push_back("-z");
-  CmdArgs.push_back("max-page-size=4096");
+  CmdArgs.push_back(getArch() == llvm::Triple::loongarch64
+? "max-page-size=16384"
+: "max-page-size=4096");
   // .gnu.hash section is not compatible with the MIPS target
   if (getArch() != llvm::Triple::mipsel)
 CmdArgs.push_back("--hash-style=both");

diff  --git 
a/clang/test/Driver/Inputs/ohos_native_tree/llvm/lib/clang/x.y.z/lib/loongarch64-linux-ohos/.keep
 
b/clang/test/Driver/Inputs/ohos_native_tree/llvm/lib/clang/x.y.z/lib/loongarch64-linux-ohos/.keep
new file mode 100644
index 0..e69de29bb2d1d

diff  --git 
a/clang/test/Driver/Inputs/ohos_native_tree/llvm/lib/clang/x.y.z/lib/loongarch64-linux-ohos/clang_rt.crtbegin.o
 
b/clang/test/Driver/Inputs/ohos_native_tree/llvm/lib/clang/x.y.z/lib/loongarch64-linux-ohos/clang_rt.crtbegin.o
new file mode 100644
index 0..e69de29bb2d1d

diff  --git 
a/clang/test/Driver/Inputs/ohos_native_tree/llvm/lib/clang/x.y.z/lib/loongarch64-linux-ohos/clang_rt.crtend.o
 
b/clang/test/Driver/Inputs/ohos_native_tree/llvm/lib/clang/x.y.z/lib/loongarch64-linux-ohos/clang_rt.crtend.o
new file mode 100644
index 0..e69de29bb2d1d

diff  --git 
a/clang/test/Driver/Inputs/ohos_native_tree/llvm/lib/clang/x.y.z/lib/loongarch64-linux-ohos/libclang_rt.builtins.a
 
b/clang/test/Driver/Inputs/ohos_native_tree/llvm/lib/clang/x.y.z/lib/loongarch64-linux-ohos/libclang_rt.builtins.a
new file mode 100644
index 0..e69de29bb2d1d

diff  --git 
a/clang/test/Driver/Inputs/ohos_native_tree/sysroot/usr/include/loongarch64-linux-ohos/.keep
 
b/clang/test/Driver/Inputs/ohos_native_tree/sysroot/usr/include/loongarch64-linux-ohos/.keep
new file mode 100644
index 0..e69de29bb2d1d

diff  --git 
a/clang/test/Driver/Inputs/ohos_native_tree/sysroot/usr/lib/loongarch64-linux-ohos/.keep
 
b/clang/test/Driver/Inputs/ohos_native_tree/sysroot/usr/lib/loongarch64-linux-ohos/.keep
new file mode 100644
index 0..e69de29bb2d1d

diff  --git a/clang/test/Driver/ohos.c b/clang/test/Drive

[clang] [CIR] Realign CIR-to-LLVM IR lowering code with incubator (PR #129293)

2025-03-02 Thread Andy Kaylor via cfe-commits

https://github.com/andykaylor updated 
https://github.com/llvm/llvm-project/pull/129293

>From bb41af68d0d0f66c5610c69d6deb8a615d644fe5 Mon Sep 17 00:00:00 2001
From: Andy Kaylor 
Date: Fri, 28 Feb 2025 10:54:09 -0800
Subject: [PATCH 1/3] [CIR] Replace CIRAttrVisitor with TypeSwitch

We previously discussed having an mlir-tblgen utility to complete the
CIRAttrVisitor implementation with all support attribute types, but
when I proposed an implementation to do this, a reviewer suggested
using TypeSwitch instead, and I have done that in the incubator.

See https://github.com/llvm/llvm-project/pull/126332

This change brings the TypeSwitch implementation into the upstream repo
to replace the visitor class.
---
 .../clang/CIR/Dialect/IR/CIRAttrVisitor.h | 52 ---
 .../CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp | 31 +++
 2 files changed, 22 insertions(+), 61 deletions(-)
 delete mode 100644 clang/include/clang/CIR/Dialect/IR/CIRAttrVisitor.h

diff --git a/clang/include/clang/CIR/Dialect/IR/CIRAttrVisitor.h 
b/clang/include/clang/CIR/Dialect/IR/CIRAttrVisitor.h
deleted file mode 100644
index bbba89cb7e3fd..0
--- a/clang/include/clang/CIR/Dialect/IR/CIRAttrVisitor.h
+++ /dev/null
@@ -1,52 +0,0 @@
-//===- CIRAttrVisitor.h - Visitor for CIR attributes *- C++ 
-*-===//
-//
-// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-//
-//===--===//
-//
-// This file defines the CirAttrVisitor interface.
-//
-//===--===//
-
-#ifndef LLVM_CLANG_CIR_DIALECT_IR_CIRATTRVISITOR_H
-#define LLVM_CLANG_CIR_DIALECT_IR_CIRATTRVISITOR_H
-
-#include "clang/CIR/Dialect/IR/CIRAttrs.h"
-
-namespace cir {
-
-template  class CirAttrVisitor {
-public:
-  // FIXME: Create a TableGen list to automatically handle new attributes
-  RetTy visit(mlir::Attribute attr) {
-if (const auto intAttr = mlir::dyn_cast(attr))
-  return getImpl().visitCirIntAttr(intAttr);
-if (const auto fltAttr = mlir::dyn_cast(attr))
-  return getImpl().visitCirFPAttr(fltAttr);
-if (const auto ptrAttr = mlir::dyn_cast(attr))
-  return getImpl().visitCirConstPtrAttr(ptrAttr);
-llvm_unreachable("unhandled attribute type");
-  }
-
-  // If the implementation chooses not to implement a certain visit
-  // method, fall back to the parent.
-  RetTy visitCirIntAttr(cir::IntAttr attr) {
-return getImpl().visitCirAttr(attr);
-  }
-  RetTy visitCirFPAttr(cir::FPAttr attr) {
-return getImpl().visitCirAttr(attr);
-  }
-  RetTy visitCirConstPtrAttr(cir::ConstPtrAttr attr) {
-return getImpl().visitCirAttr(attr);
-  }
-
-  RetTy visitCirAttr(mlir::Attribute attr) { return RetTy(); }
-
-  ImplClass &getImpl() { return *static_cast(this); }
-};
-
-} // namespace cir
-
-#endif // LLVM_CLANG_CIR_DIALECT_IR_CIRATTRVISITOR_H
diff --git a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp 
b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
index ba7fab2865116..7bf4b5fd27b61 100644
--- a/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
+++ b/clang/lib/CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp
@@ -24,10 +24,10 @@
 #include "mlir/Target/LLVMIR/Dialect/LLVMIR/LLVMToLLVMIRTranslation.h"
 #include "mlir/Target/LLVMIR/Export.h"
 #include "mlir/Transforms/DialectConversion.h"
-#include "clang/CIR/Dialect/IR/CIRAttrVisitor.h"
 #include "clang/CIR/Dialect/IR/CIRDialect.h"
 #include "clang/CIR/MissingFeatures.h"
 #include "clang/CIR/Passes.h"
+#include "llvm/ADT/TypeSwitch.h"
 #include "llvm/IR/Module.h"
 #include "llvm/Support/TimeProfiler.h"
 
@@ -37,7 +37,7 @@ using namespace llvm;
 namespace cir {
 namespace direct {
 
-class CIRAttrToValue : public CirAttrVisitor {
+class CIRAttrToValue {
 public:
   CIRAttrToValue(mlir::Operation *parentOp,
  mlir::ConversionPatternRewriter &rewriter,
@@ -46,19 +46,26 @@ class CIRAttrToValue : public 
CirAttrVisitor {
 
   mlir::Value lowerCirAttrAsValue(mlir::Attribute attr) { return visit(attr); }
 
-  mlir::Value visitCirIntAttr(cir::IntAttr intAttr) {
+  mlir::Value visit(mlir::Attribute attr) {
+return llvm::TypeSwitch(attr)
+.Case(
+[&](auto attrT) { return visitCirAttr(attrT); })
+.Default([&](auto attrT) { return mlir::Value(); });
+  }
+
+  mlir::Value visitCirAttr(cir::IntAttr intAttr) {
 mlir::Location loc = parentOp->getLoc();
 return rewriter.create(
 loc, converter->convertType(intAttr.getType()), intAttr.getValue());
   }
 
-  mlir::Value visitCirFPAttr(cir::FPAttr fltAttr) {
+  mlir::Value visitCirAttr(cir::FPAttr fltAttr) {
 mlir::Location loc = parentOp->getLoc();
 return rewriter.create(
 loc, converter->convertType(fltAttr.getType()), fltAttr.getValue());
   }
 
-  mlir::Value visitCirCons

[clang] 3a11d5a - [clang][diagnostics] add `-Wundef-true` warning option (#128265)

2025-03-02 Thread via cfe-commits

Author: isuckatcs
Date: 2025-03-02T19:00:27+01:00
New Revision: 3a11d5a8dfb6c95a5ba0c6b4463e15494005a369

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

LOG: [clang][diagnostics] add `-Wundef-true` warning option (#128265)

New option `-Wundef-true` added and enabled by default to warn when `true` is 
used in the C preprocessor without being defined before C23.

Added: 
clang/test/Preprocessor/warn-macro-undef-true.c

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/DiagnosticGroups.td
clang/include/clang/Basic/DiagnosticLexKinds.td
clang/lib/Lex/PPExpressions.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index c97bbc372fcb7..d2fc1ce07dd79 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -114,6 +114,8 @@ Non-comprehensive list of changes in this release
 New Compiler Flags
 --
 
+- New option ``-Wundef-true`` added and enabled by default to warn when `true` 
is used in the C preprocessor without being defined before C23.
+
 - New option ``-fprofile-continuous`` added to enable continuous profile 
syncing to file (#GH124353, `docs 
`_).
   The feature has `existed 
`_)
   for a while and this is just a user facing option.

diff  --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 77520447b813d..fac80fb4009aa 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -791,6 +791,8 @@ def ReservedIdAsMacroAlias : DiagGroup<"reserved-id-macro", 
[ReservedIdAsMacro]>
 def ReservedAttributeIdentifier : DiagGroup<"reserved-attribute-identifier">;
 def RestrictExpansionMacro : DiagGroup<"restrict-expansion">;
 def FinalMacro : DiagGroup<"final-macro">;
+def UndefinedTrueIdentifier : DiagGroup<"undef-true">;
+def UndefinedIdentifier : DiagGroup<"undef", [UndefinedTrueIdentifier]>;
 
 // Just silence warnings about -Wstrict-aliasing for now.
 def : DiagGroup<"strict-aliasing=0">;

diff  --git a/clang/include/clang/Basic/DiagnosticLexKinds.td 
b/clang/include/clang/Basic/DiagnosticLexKinds.td
index 2b1cc81677b08..8daf3602450f0 100644
--- a/clang/include/clang/Basic/DiagnosticLexKinds.td
+++ b/clang/include/clang/Basic/DiagnosticLexKinds.td
@@ -392,7 +392,10 @@ def pp_macro_not_used : Warning<"macro is not used">, 
DefaultIgnore,
   InGroup>;
 def warn_pp_undef_identifier : Warning<
   "%0 is not defined, evaluates to 0">,
-  InGroup>, DefaultIgnore;
+  InGroup, DefaultIgnore;
+def warn_pp_undef_true_identifier : Warning<
+  "'true' is not defined, evaluates to 0">,
+  InGroup;
 def warn_pp_undef_prefix : Warning<
   "%0 is not defined, evaluates to 0">,
   InGroup>, DefaultIgnore;

diff  --git a/clang/lib/Lex/PPExpressions.cpp b/clang/lib/Lex/PPExpressions.cpp
index a3b1384f0fa1d..b031571907441 100644
--- a/clang/lib/Lex/PPExpressions.cpp
+++ b/clang/lib/Lex/PPExpressions.cpp
@@ -257,12 +257,14 @@ static bool EvaluateValue(PPValue &Result, Token 
&PeekTok, DefinedTracker &DT,
 // preprocessor keywords and it wasn't macro expanded, it turns
 // into a simple 0
 if (ValueLive) {
-  PP.Diag(PeekTok, diag::warn_pp_undef_identifier) << II;
+  unsigned DiagID = II->getName() == "true"
+? diag::warn_pp_undef_true_identifier
+: diag::warn_pp_undef_identifier;
+  PP.Diag(PeekTok, DiagID) << II;
 
   const DiagnosticsEngine &DiagEngine = PP.getDiagnostics();
   // If 'Wundef' is enabled, do not emit 'undef-prefix' diagnostics.
-  if (DiagEngine.isIgnored(diag::warn_pp_undef_identifier,
-   PeekTok.getLocation())) {
+  if (DiagEngine.isIgnored(DiagID, PeekTok.getLocation())) {
 const std::vector UndefPrefixes =
 DiagEngine.getDiagnosticOptions().UndefPrefixes;
 const StringRef IdentifierName = II->getName();

diff  --git a/clang/test/Preprocessor/warn-macro-undef-true.c 
b/clang/test/Preprocessor/warn-macro-undef-true.c
new file mode 100644
index 0..9a64d577a96ed
--- /dev/null
+++ b/clang/test/Preprocessor/warn-macro-undef-true.c
@@ -0,0 +1,78 @@
+// RUN: %clang_cc1 %s -Eonly -std=c89 -verify=undef-true
+// RUN: %clang_cc1 %s -Eonly -std=c99 -verify=undef-true
+// RUN: %clang_cc1 %s -Eonly -std=c11 -verify=undef-true
+// RUN: %clang_cc1 %s -Eonly -std=c17 -verify=undef-true
+// RUN: %clang_cc1 %s -Eonly -std=c23 -verify=undef-true
+
+#if __STDC_VERSION__ >= 202311L
+/* undef-true-no-d

[clang] 2c1e9f1 - [clang][bytecode] Explicit composite array descriptor types (#129376)

2025-03-02 Thread via cfe-commits

Author: Timm Baeder
Date: 2025-03-02T09:40:56+01:00
New Revision: 2c1e9f14be32c30f6f561274292bef1f52635f82

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

LOG: [clang][bytecode] Explicit composite array descriptor types (#129376)

When creating descriptor for array element types, we only save the
original source, e.g. int[2][2][2]. So later calls to getType() of the
element descriptors will also return int[2][2][2], instead of e.g.
int[2][2] for the second dimension.
Fix this by explicitly tracking the array types.
The last attached test case used to have an lvalue offset of 32 instead
of 24.

We should do this for more desriptor types though and not just composite
array, but I'm leaving that to a later patch.

Added: 


Modified: 
clang/lib/AST/ByteCode/Descriptor.cpp
clang/lib/AST/ByteCode/Descriptor.h
clang/lib/AST/ByteCode/DynamicAllocator.cpp
clang/lib/AST/ByteCode/Program.cpp
clang/unittests/AST/ByteCode/toAPValue.cpp

Removed: 




diff  --git a/clang/lib/AST/ByteCode/Descriptor.cpp 
b/clang/lib/AST/ByteCode/Descriptor.cpp
index 6017f6dd61cb3..bcd9f6f3d078a 100644
--- a/clang/lib/AST/ByteCode/Descriptor.cpp
+++ b/clang/lib/AST/ByteCode/Descriptor.cpp
@@ -367,10 +367,12 @@ Descriptor::Descriptor(const DeclTy &D, PrimType Type, 
MetadataSize MD,
 }
 
 /// Arrays of composite elements.
-Descriptor::Descriptor(const DeclTy &D, const Descriptor *Elem, MetadataSize 
MD,
+Descriptor::Descriptor(const DeclTy &D, const Type *SourceTy,
+   const Descriptor *Elem, MetadataSize MD,
unsigned NumElems, bool IsConst, bool IsTemporary,
bool IsMutable)
-: Source(D), ElemSize(Elem->getAllocSize() + sizeof(InlineDescriptor)),
+: Source(D), SourceType(SourceTy),
+  ElemSize(Elem->getAllocSize() + sizeof(InlineDescriptor)),
   Size(ElemSize * NumElems), MDSize(MD.value_or(0)),
   AllocSize(std::max(alignof(void *), Size) + MDSize),
   ElemDesc(Elem), IsConst(IsConst), IsMutable(IsMutable),
@@ -410,6 +412,8 @@ Descriptor::Descriptor(const DeclTy &D)
 }
 
 QualType Descriptor::getType() const {
+  if (SourceType)
+return QualType(SourceType, 0);
   if (const auto *D = asValueDecl())
 return D->getType();
   if (const auto *T = dyn_cast_if_present(asDecl()))

diff  --git a/clang/lib/AST/ByteCode/Descriptor.h 
b/clang/lib/AST/ByteCode/Descriptor.h
index 01fa4b198de67..b2e9f1b6bded4 100644
--- a/clang/lib/AST/ByteCode/Descriptor.h
+++ b/clang/lib/AST/ByteCode/Descriptor.h
@@ -124,6 +124,7 @@ struct Descriptor final {
 private:
   /// Original declaration, used to emit the error message.
   const DeclTy Source;
+  const Type *SourceType = nullptr;
   /// Size of an element, in host bytes.
   const unsigned ElemSize;
   /// Size of the storage, in host bytes.
@@ -186,8 +187,9 @@ struct Descriptor final {
  bool IsTemporary, UnknownSize);
 
   /// Allocates a descriptor for an array of composites.
-  Descriptor(const DeclTy &D, const Descriptor *Elem, MetadataSize MD,
- unsigned NumElems, bool IsConst, bool IsTemporary, bool 
IsMutable);
+  Descriptor(const DeclTy &D, const Type *SourceTy, const Descriptor *Elem,
+ MetadataSize MD, unsigned NumElems, bool IsConst, bool 
IsTemporary,
+ bool IsMutable);
 
   /// Allocates a descriptor for an array of composites of unknown size.
   Descriptor(const DeclTy &D, const Descriptor *Elem, MetadataSize MD,

diff  --git a/clang/lib/AST/ByteCode/DynamicAllocator.cpp 
b/clang/lib/AST/ByteCode/DynamicAllocator.cpp
index 3ef8c2e1f3e7c..728bd75d7d141 100644
--- a/clang/lib/AST/ByteCode/DynamicAllocator.cpp
+++ b/clang/lib/AST/ByteCode/DynamicAllocator.cpp
@@ -57,8 +57,10 @@ Block *DynamicAllocator::allocate(const Descriptor 
*ElementDesc,
   assert(ElementDesc->getMetadataSize() == 0);
   // Create a new descriptor for an array of the specified size and
   // element type.
+  // FIXME: Pass proper element type.
   const Descriptor *D = allocateDescriptor(
-  ElementDesc->asExpr(), ElementDesc, Descriptor::InlineDescMD, 
NumElements,
+  ElementDesc->asExpr(), nullptr, ElementDesc, Descriptor::InlineDescMD,
+  NumElements,
   /*IsConst=*/false, /*IsTemporary=*/false, /*IsMutable=*/false);
   return allocate(D, EvalID, AllocForm);
 }

diff  --git a/clang/lib/AST/ByteCode/Program.cpp 
b/clang/lib/AST/ByteCode/Program.cpp
index 0754e259b7cb3..cc2cfc9b03b41 100644
--- a/clang/lib/AST/ByteCode/Program.cpp
+++ b/clang/lib/AST/ByteCode/Program.cpp
@@ -419,7 +419,7 @@ Descriptor *Program::createDescriptor(const DeclTy &D, 
const Type *Ty,
 unsigned ElemSize = ElemDesc->getAllocSize() + 
sizeof(InlineDescriptor);
 if (std::numeric_limits::max() / ElemSize <= NumElems)
   re

[clang-tools-extra] [clang-tidy] Fix invalid fixit from modernize-use-ranges for nullptr used with std::unique_ptr (PR #127162)

2025-03-02 Thread via cfe-commits

Andrewyuan34 wrote:

> ping me if you want to merge it.

I‘m sorry for requesting approval again. But I'm really confused that should I 
make sure my branch is alwasy up-to-date?

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


[clang] [CIR] Upstream floating point literal expressions (PR #129304)

2025-03-02 Thread Bruno Cardoso Lopes via cfe-commits

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

LGTM after any extra feedback on format

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


[clang] 60afce2 - [clang-tidy] fix fp when modifying variant by ``operator[]`` with template in parameters (#128407)

2025-03-02 Thread via cfe-commits

Author: Congcong Cai
Date: 2025-03-02T19:39:49+08:00
New Revision: 60afce2df97d1f8fd78405a039e8e818c5154565

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

LOG: [clang-tidy] fix fp when modifying variant by ``operator[]`` with template 
in parameters (#128407)

`ArraySubscriptExpr` can switch base and idx. For dependent array
subscript access, we should check both base and idx conservatively.

Added: 


Modified: 
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values.cpp
clang/lib/Analysis/ExprMutationAnalyzer.cpp
clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp

Removed: 




diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 07a79d6bbe807..71edb704b49d6 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -122,7 +122,8 @@ Changes in existing checks
 - Improved :doc:`misc-const-correctness
   ` check by adding the option
   `AllowedTypes`, that excludes specified types from const-correctness
-  checking.
+  checking and fixing false positives when modifying variant by ``operator[]``
+  with template in parameters.
 
 - Improved :doc:`misc-redundant-expression
   ` check by providing additional

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values.cpp
index 5efb64bca2374..654deead4efc8 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values.cpp
@@ -998,3 +998,11 @@ void member_pointer_const(Value &x, 
PointerToConstMemberFunction m) {
   // CHECK-MESSAGES:[[@LINE-1]]:3: warning: variable 'member_pointer_tmp' of 
type 'Value &' can be declared 'const'
   (member_pointer_tmp.*m)();
 }
+
+namespace gh127776_false_positive {
+template  struct vector { T &operator[](int t); };
+template  void f() {
+  vector x;
+  x[T{}] = 3;
+}
+} // namespace gh127776_false_positive

diff  --git a/clang/lib/Analysis/ExprMutationAnalyzer.cpp 
b/clang/lib/Analysis/ExprMutationAnalyzer.cpp
index 8944343484e58..823d7543f085f 100644
--- a/clang/lib/Analysis/ExprMutationAnalyzer.cpp
+++ b/clang/lib/Analysis/ExprMutationAnalyzer.cpp
@@ -80,6 +80,17 @@ static bool canExprResolveTo(const Expr *Source, const Expr 
*Target) {
 
 namespace {
 
+// `ArraySubscriptExpr` can switch base and idx, e.g. `a[4]` is the same as
+// `4[a]`. When type is dependent, we conservatively assume both sides are 
base.
+AST_MATCHER_P(ArraySubscriptExpr, hasBaseConservative,
+  ast_matchers::internal::Matcher, InnerMatcher) {
+  if (Node.isTypeDependent()) {
+return InnerMatcher.matches(*Node.getLHS(), Finder, Builder) ||
+   InnerMatcher.matches(*Node.getRHS(), Finder, Builder);
+  }
+  return InnerMatcher.matches(*Node.getBase(), Finder, Builder);
+}
+
 AST_MATCHER(Type, isDependentType) { return Node.isDependentType(); }
 
 AST_MATCHER_P(LambdaExpr, hasCaptureInit, const Expr *, E) {
@@ -513,8 +524,8 @@ 
ExprMutationAnalyzer::Analyzer::findArrayElementMutation(const Expr *Exp) {
   // Check whether any element of an array is mutated.
   const auto SubscriptExprs = match(
   findAll(arraySubscriptExpr(
-  anyOf(hasBase(canResolveToExpr(Exp)),
-hasBase(implicitCastExpr(allOf(
+  anyOf(hasBaseConservative(canResolveToExpr(Exp)),
+hasBaseConservative(implicitCastExpr(allOf(
 hasCastKind(CK_ArrayToPointerDecay),
 hasSourceExpression(canResolveToExpr(Exp)))
   .bind(NodeID::value)),
@@ -716,7 +727,8 @@ 
ExprMutationAnalyzer::Analyzer::findPointeeValueMutation(const Expr *Exp) {
unaryOperator(hasOperatorName("*"),
  
hasUnaryOperand(canResolveToExprPointee(Exp))),
// deref by []
-   arraySubscriptExpr(hasBase(canResolveToExprPointee(Exp)
+   arraySubscriptExpr(
+   hasBaseConservative(canResolveToExprPointee(Exp)
   .bind(NodeID::value))),
   Stm, Context);
   return findExprMutation(Matches);

diff  --git a/clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp 
b/clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp
index cc277d56b37a2..720999207083d 100644
--- a/clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp
+++ b/clang/unittests/Analysis/ExprMutationAnalyzerTest.cpp
@@ -870,6 +870,19 @@ TEST(ExprMutationAnalyzerTest, 
TemplateWithArrayToPointerDecay) {
   EXPECT_THAT(mutatedBy(ResultsY, AST.get()

[clang-tools-extra] [clang-tidy] Fix invalid fixit from modernize-use-ranges for nullptr used with std::unique_ptr (PR #127162)

2025-03-02 Thread via cfe-commits

https://github.com/Andrewyuan34 updated 
https://github.com/llvm/llvm-project/pull/127162

>From 09b809d803ca319f194eba6b6d8a78fa6dbbf9f3 Mon Sep 17 00:00:00 2001
From: Andrewyuan34 
Date: Thu, 13 Feb 2025 22:35:36 -0500
Subject: [PATCH] [clang-tidy] Fix invalid fixit from modernize-use-ranges for
 nullptr used with std::unique_ptr

---
 .../clang-tidy/utils/UseRangesCheck.cpp   | 13 ++
 clang-tools-extra/docs/ReleaseNotes.rst   |  4 +++
 .../checkers/modernize/use-ranges.cpp | 26 ---
 3 files changed, 40 insertions(+), 3 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp 
b/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp
index aba4d17ccd035..f7a19cd72d500 100644
--- a/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp
+++ b/clang-tools-extra/clang-tidy/utils/UseRangesCheck.cpp
@@ -215,6 +215,19 @@ void UseRangesCheck::check(const MatchFinder::MatchResult 
&Result) {
 const auto *Call = Result.Nodes.getNodeAs(Buffer);
 if (!Call)
   continue;
+
+// FIXME: This check specifically handles `CXXNullPtrLiteralExpr`, but
+// a more general solution might be needed.
+if (Function->getName() == "find") {
+  const unsigned ValueArgIndex = 2;
+  if (Call->getNumArgs() <= ValueArgIndex)
+continue;
+  const Expr *ValueExpr =
+  Call->getArg(ValueArgIndex)->IgnoreParenImpCasts();
+  if (isa(ValueExpr))
+return;
+}
+
 auto Diag = createDiag(*Call);
 if (auto ReplaceName = Replacer->getReplaceName(*Function))
   Diag << FixItHint::CreateReplacement(Call->getCallee()->getSourceRange(),
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index a8d17d19fda1d..becd3713e6ad0 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -126,6 +126,10 @@ Changes in existing checks
 - Improved :doc:`misc-redundant-expression
   ` check by providing additional
   examples and fixing some macro related false positives.
+  
+- Improved :doc:`modernize-use-ranges
+  ` check by updating suppress 
+  warnings logic for ``nullptr`` in ``std::find``.
 
 - Improved :doc:`performance/unnecessary-value-param
   ` check performance by
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-ranges.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-ranges.cpp
index b022efebfdf4d..5aa026038b1cd 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/modernize/use-ranges.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/modernize/use-ranges.cpp
@@ -1,14 +1,25 @@
-// RUN: %check_clang_tidy -std=c++20 %s modernize-use-ranges %t -- -- -I 
%S/Inputs/use-ranges/
-// RUN: %check_clang_tidy -std=c++23 %s modernize-use-ranges %t 
-check-suffixes=,CPP23 -- -I %S/Inputs/use-ranges/
+// RUN: %check_clang_tidy -std=c++20 %s modernize-use-ranges %t -- -- -I 
%S/Inputs/
+// RUN: %check_clang_tidy -std=c++23 %s modernize-use-ranges %t 
-check-suffixes=,CPP23 -- -I %S/Inputs/
+// Example: ./check_clang_tidy.py -std=c++20 checkers/modernize/use-ranges.cpp 
modernize-use-ranges temp.txt -- -- -I 
~/llvm-project/clang-tools-extra/test/clang-tidy/checkers/modernize/Inputs/
 
 // CHECK-FIXES: #include 
 // CHECK-FIXES-CPP23: #include 
 // CHECK-FIXES: #include 
 
-#include "fake_std.h"
+#include "use-ranges/fake_std.h"
+#include "smart-ptr/unique_ptr.h"
 
 void Positives() {
   std::vector I, J;
+  std::vector> K;
+
+  // Expect to have no check messages
+  std::find(K.begin(), K.end(), nullptr);
+
+  std::find(K.begin(), K.end(), std::unique_ptr());
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a ranges version of this 
algorithm
+  // CHECK-FIXES: std::ranges::find(K, std::unique_ptr());
+
   std::find(I.begin(), I.end(), 0);
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a ranges version of this 
algorithm
   // CHECK-FIXES: std::ranges::find(I, 0);
@@ -76,6 +87,15 @@ void Positives() {
 
 void Reverse(){
   std::vector I, J;
+  std::vector> K;
+  
+  // Expect to have no check messages
+  std::find(K.rbegin(), K.rend(), nullptr);
+
+  std::find(K.rbegin(), K.rend(), std::unique_ptr());
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a ranges version of this 
algorithm
+  // CHECK-FIXES: std::ranges::find(std::ranges::reverse_view(K), 
std::unique_ptr());
+
   std::find(I.rbegin(), I.rend(), 0);
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: use a ranges version of this 
algorithm
   // CHECK-FIXES: std::ranges::find(std::ranges::reverse_view(I), 0);

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


[clang] [llvm] [memprof] Export __memprof_default_options_str on Darwin (PR #128920)

2025-03-02 Thread Teresa Johnson via cfe-commits

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

lgtm

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


[clang] [Clang][diagnostics] Fix structured binding shadows template param loc (PR #129116)

2025-03-02 Thread Erich Keane via cfe-commits


@@ -214,6 +214,8 @@ Improvements to Clang's diagnostics
   :doc:`ThreadSafetyAnalysis` still does not perform alias analysis. The
   feature will be default-enabled with ``-Wthread-safety`` in a future release.
 
+- Improve the diagnostics for shadows template parameter.

erichkeane wrote:

This should probably mention the bug# as well as slightly better clarify that 
it is giving a more correct location.

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


[clang] 527af30 - Add support for dynamic libraries in CLANG_BOLT (#127020)

2025-03-02 Thread via cfe-commits

Author: serge-sans-paille
Date: 2025-03-02T20:21:44Z
New Revision: 527af302b90eaf686959dfe569dceadd8e58d611

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

LOG: Add support for dynamic libraries in CLANG_BOLT (#127020)

Added: 


Modified: 
clang/cmake/caches/BOLT.cmake
clang/tools/driver/CMakeLists.txt
clang/utils/perf-training/perf-helper.py

Removed: 




diff  --git a/clang/cmake/caches/BOLT.cmake b/clang/cmake/caches/BOLT.cmake
index eba2346b2f4ca..1956c10463148 100644
--- a/clang/cmake/caches/BOLT.cmake
+++ b/clang/cmake/caches/BOLT.cmake
@@ -1,6 +1,7 @@
 set(CMAKE_BUILD_TYPE Release CACHE STRING "")
 set(CLANG_BOLT "INSTRUMENT" CACHE STRING "")
 set(CMAKE_EXE_LINKER_FLAGS "-Wl,--emit-relocs,-znow" CACHE STRING "")
+set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--emit-relocs,-znow" CACHE STRING "")
 
 set(LLVM_ENABLE_PROJECTS "bolt;clang" CACHE STRING "")
 set(LLVM_TARGETS_TO_BUILD Native CACHE STRING "")

diff  --git a/clang/tools/driver/CMakeLists.txt 
b/clang/tools/driver/CMakeLists.txt
index 5d7962769014a..10ea5de387220 100644
--- a/clang/tools/driver/CMakeLists.txt
+++ b/clang/tools/driver/CMakeLists.txt
@@ -168,6 +168,28 @@ if (CLANG_BOLT AND NOT LLVM_BUILD_INSTRUMENTED)
   )
   set(LIT_COMMAND "${lit_base_dir}/${lit_file_name}")
 
+  set(CLANG_BOLT_INPUTS $)
+  set(CLANG_INSTRUMENTED_OUTPUTS ${CLANG_INSTRUMENTED})
+
+  # Add in dynamically linked libraries, if needs be. Currently only supported
+  # on Linux because it relies on LD_PRELOAD for instrumentation.
+  if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
+if (CLANG_LINK_CLANG_DYLIB)
+ set(CLANG_CPP_BOLT_INSTRUMENTED "clang-cxx-bolt.inst" CACHE STRING
+   "Name of BOLT-instrumented Clang library")
+ set(CLANG_CPP_INSTRUMENTED 
${LLVM_RUNTIME_OUTPUT_INTDIR}/${CLANG_CPP_BOLT_INSTRUMENTED})
+ list(APPEND CLANG_BOLT_INPUTS $)
+ list(APPEND CLANG_INSTRUMENTED_OUTPUTS ${CLANG_CPP_INSTRUMENTED})
+endif()
+if (LLVM_LINK_LLVM_DYLIB)
+  set(LLVM_BOLT_INSTRUMENTED "LLVM-bolt.inst" CACHE STRING
+"Name of BOLT-instrumented LLVM library")
+  set(LLVM_INSTRUMENTED 
${LLVM_RUNTIME_OUTPUT_INTDIR}/${LLVM_BOLT_INSTRUMENTED})
+  list(APPEND CLANG_BOLT_INPUTS $)
+  list(APPEND CLANG_INSTRUMENTED_OUTPUTS ${LLVM_INSTRUMENTED})
+endif()
+  endif()
+
   # This POST_BUILD command is executed unconditionally even if the clang 
target
   # is already built.  We need to wrap the whole bolt optimization process in
   # a single python wrapper, so that we can first check if the binary has
@@ -176,15 +198,15 @@ if (CLANG_BOLT AND NOT LLVM_BUILD_INSTRUMENTED)
 TARGET clang POST_BUILD
 COMMAND  "${Python3_EXECUTABLE}" 
${CMAKE_CURRENT_SOURCE_DIR}/../../utils/perf-training/perf-helper.py
  bolt-optimize
---method ${CLANG_BOLT}
---input $
---instrumented-output ${CLANG_INSTRUMENTED}
---fdata ${BOLT_FDATA}
---perf-training-binary-dir ${PERF_TRAINING_BINARY_DIR}
---readelf $
---bolt $
---lit "${LIT_COMMAND}"
---merge-fdata $
+ --method ${CLANG_BOLT}
+ --input "${CLANG_BOLT_INPUTS}"
+ --instrumented-output "${CLANG_INSTRUMENTED_OUTPUTS}"
+ --fdata ${BOLT_FDATA}
+ --perf-training-binary-dir ${PERF_TRAINING_BINARY_DIR}
+ --readelf $
+ --bolt $
+ --lit "${LIT_COMMAND}"
+ --merge-fdata $
 COMMENT "Optimizing Clang with BOLT"
 USES_TERMINAL
 VERBATIM

diff  --git a/clang/utils/perf-training/perf-helper.py 
b/clang/utils/perf-training/perf-helper.py
index 55c5160a71c4f..cdb6c39f6c50e 100644
--- a/clang/utils/perf-training/perf-helper.py
+++ b/clang/utils/perf-training/perf-helper.py
@@ -560,6 +560,23 @@ def genOrderFile(args):
 return 0
 
 
+def filter_bolt_optimized(inputs, instrumented_outputs):
+new_inputs = []
+new_instrumented_ouputs = []
+for input, instrumented_output in zip(inputs, instrumented_outputs):
+output = subprocess.check_output(
+[opts.readelf, "-WS", input], universal_newlines=True
+)
+
+# This binary has already been bolt-optimized, so skip further 
processing.
+if re.search("\\.bolt\\.org\\.text", output, re.MULTILINE):
+print(f"Skipping {input}, it's already instrumented")
+else:
+new_inputs.append(input)
+new_instrumented_ouputs.append(instrumented_output)
+return new_inputs, new_instrumented_ouputs
+
+
 def bolt_optimize(args):
 parser = argparse.ArgumentParser("%prog  [options] ")
 parser.add_argument("--method", choices=["INSTRUMENT", "PERF", "LBR"])
@@ -574,47 +591,67 @@ def bolt_optimize(args):
 
 opts = parser.pars