[clang-tools-extra] [clang-tidy] Create bugprone-incorrect-enable-shared-from-this check (PR #102299)

2024-11-09 Thread via cfe-commits

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


[clang-tools-extra] Fix false positive in bugprone-throw-keyword-missing (PR #115302)

2024-11-09 Thread Piotr Zegar via cfe-commits

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


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


[clang-tools-extra] [clang-tidy] Create bugprone-incorrect-enable-shared-from-this check (PR #102299)

2024-11-09 Thread via cfe-commits

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


[clang-tools-extra] [clang-tidy] Create bugprone-incorrect-enable-shared-from-this check (PR #102299)

2024-11-09 Thread via cfe-commits


@@ -0,0 +1,62 @@
+//===--- IncorrectEnableSharedFromThisCheck.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 "IncorrectEnableSharedFromThisCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/DeclCXX.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+void IncorrectEnableSharedFromThisCheck::registerMatchers(MatchFinder *Finder) 
{
+  const auto EnableSharedFromThis =
+  cxxRecordDecl(hasName("enable_shared_from_this"), isInStdNamespace());
+  const auto QType = hasCanonicalType(hasDeclaration(
+  cxxRecordDecl(
+  anyOf(EnableSharedFromThis.bind("enable_rec"),
+cxxRecordDecl(hasAnyBase(cxxBaseSpecifier(
+isPublic(), hasType(hasCanonicalType(
+hasDeclaration(EnableSharedFromThis
+  .bind("base_rec")));
+  Finder->addMatcher(
+  cxxRecordDecl(
+  hasDirectBase(cxxBaseSpecifier(unless(isPublic()), hasType(QType))
+.bind("base")))
+  .bind("derived"),
+  this);
+}
+
+void IncorrectEnableSharedFromThisCheck::check(
+const MatchFinder::MatchResult &Result) {
+  const auto *BaseSpec = Result.Nodes.getNodeAs("base");
+  const auto *Base = Result.Nodes.getNodeAs("base_rec");
+  const auto *Derived = Result.Nodes.getNodeAs("derived");
+  const bool IsEnableSharedFromThisDirectBase =
+  Result.Nodes.getNodeAs("enable_rec") == Base;
+  const SourceRange ReplacementRange = BaseSpec->getSourceRange();
+  const std::string ReplacementString =
+  // BaseSpec->getType().getAsString() results in
+  // std::enable_shared_from_this or
+  // alias/typedefs of std::enable_shared_from_this
+  "public " + BaseSpec->getType().getAsString();

MichelleCDjunaidi wrote:

approach confirmed to not work due to getBaseTypeLoc() not including the 
virtual or the access specifier. As a result, doing a blind 
SourceRange(BaseSpec->getBeginLoc(), BaseSpec->getBaseTypeLoc()) replacement 
with "public" just ends up with 

```
 //alias the template itself
 template  using esft_template = std::enable_shared_from_this;
 
-class PrivateAliasTemplateClassBase : private 
esft_template {};
+class PrivateAliasTemplateClassBase : public {};
 //
 //
 
-class DefaultAliasTemplateClassBase : 
esft_template {}; 
+class DefaultAliasTemplateClassBase : public 
{}; 
 //
 //
 
 class PublicAliasTemplateClassBase : public 
esft_template {}; 
 
-struct PrivateAliasTemplateStructBase : private 
esft_template {}; 
+struct PrivateAliasTemplateStructBase : public 
{}; 
 //
 //

 struct A : std::enable_shared_from_this {};
 #define MACRO_A A
-class B : MACRO_A {};
-class C : private MACRO_A {};
+class B : public {};
+class C : public {};
```

advice would be appreciated, because as it stands it doesn't seem possible to 
extract only the access specifier range. Current approach in my head is 
probably having a dedicated if statement just for macros, but that's kind of 
not ideal @5chmidti 

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


[clang-tools-extra] [clang-tidy] fix insertion location for function pointers in cppcoreguidelines-init-variables (PR #112091)

2024-11-09 Thread Piotr Zegar via cfe-commits

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

LGTM

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


[clang-tools-extra] [clang-tidy] Create bugprone-incorrect-enable-shared-from-this check (PR #102299)

2024-11-09 Thread via cfe-commits

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


[clang-tools-extra] [clang-tidy] Create bugprone-incorrect-enable-shared-from-this check (PR #102299)

2024-11-09 Thread via cfe-commits

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


[clang-tools-extra] [clang-tidy] Create bugprone-incorrect-enable-shared-from-this check (PR #102299)

2024-11-09 Thread via cfe-commits


@@ -0,0 +1,62 @@
+//===--- IncorrectEnableSharedFromThisCheck.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 "IncorrectEnableSharedFromThisCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/DeclCXX.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+void IncorrectEnableSharedFromThisCheck::registerMatchers(MatchFinder *Finder) 
{
+  const auto EnableSharedFromThis =
+  cxxRecordDecl(hasName("enable_shared_from_this"), isInStdNamespace());
+  const auto QType = hasCanonicalType(hasDeclaration(
+  cxxRecordDecl(
+  anyOf(EnableSharedFromThis.bind("enable_rec"),
+cxxRecordDecl(hasAnyBase(cxxBaseSpecifier(
+isPublic(), hasType(hasCanonicalType(
+hasDeclaration(EnableSharedFromThis
+  .bind("base_rec")));
+  Finder->addMatcher(
+  cxxRecordDecl(
+  hasDirectBase(cxxBaseSpecifier(unless(isPublic()), hasType(QType))
+.bind("base")))
+  .bind("derived"),
+  this);
+}
+
+void IncorrectEnableSharedFromThisCheck::check(
+const MatchFinder::MatchResult &Result) {
+  const auto *BaseSpec = Result.Nodes.getNodeAs("base");
+  const auto *Base = Result.Nodes.getNodeAs("base_rec");
+  const auto *Derived = Result.Nodes.getNodeAs("derived");
+  const bool IsEnableSharedFromThisDirectBase =
+  Result.Nodes.getNodeAs("enable_rec") == Base;
+  const SourceRange ReplacementRange = BaseSpec->getSourceRange();
+  const std::string ReplacementString =
+  // BaseSpec->getType().getAsString() results in
+  // std::enable_shared_from_this or
+  // alias/typedefs of std::enable_shared_from_this
+  "public " + BaseSpec->getType().getAsString();

MichelleCDjunaidi wrote:

also, side note: MACRO_A doesn't count as direct inheritance either, so the fix 
won't emit on MACRO_A if we do the "issue FixItHint on direct inheritance only"

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


[clang] [llvm] [RFC][RISCV] Use the 'B' extension in RISC-V profile definitions (PR #113942)

2024-11-09 Thread Alex Bradbury via cfe-commits

https://github.com/asb updated https://github.com/llvm/llvm-project/pull/113942

>From 47418b35a6e3e02eb20ff7b81f45571bf1322f5b Mon Sep 17 00:00:00 2001
From: Alex Bradbury 
Date: Mon, 28 Oct 2024 14:42:44 +
Subject: [PATCH 1/3] [RISCV] Mark RVB23U64 and RVB23S64 as non-experimental

The specification was recently ratified
.
---
 clang/test/Driver/print-supported-extensions-riscv.c | 4 ++--
 clang/test/Driver/riscv-profiles.c   | 4 ++--
 llvm/docs/RISCVUsage.rst | 4 ++--
 llvm/docs/ReleaseNotes.md| 3 ++-
 llvm/lib/Target/RISCV/RISCVProfiles.td   | 4 ++--
 llvm/test/CodeGen/RISCV/attributes.ll| 4 ++--
 llvm/unittests/TargetParser/RISCVISAInfoTest.cpp | 4 ++--
 7 files changed, 14 insertions(+), 13 deletions(-)

diff --git a/clang/test/Driver/print-supported-extensions-riscv.c 
b/clang/test/Driver/print-supported-extensions-riscv.c
index e39847b9c31a8e..68acde65a74bfb 100644
--- a/clang/test/Driver/print-supported-extensions-riscv.c
+++ b/clang/test/Driver/print-supported-extensions-riscv.c
@@ -193,12 +193,12 @@
 // CHECK-NEXT: rva22u64
 // CHECK-NEXT: rva23s64
 // CHECK-NEXT: rva23u64
+// CHECK-NEXT: rvb23s64
+// CHECK-NEXT: rvb23u64
 // CHECK-NEXT: rvi20u32
 // CHECK-NEXT: rvi20u64
 // CHECK-EMPTY:
 // CHECK-NEXT: Experimental Profiles
-// CHECK-NEXT: rvb23s64
-// CHECK-NEXT: rvb23u64
 // CHECK-NEXT: rvm23u32
 // CHECK-EMPTY:
 // CHECK-NEXT: Use -march to specify the target's extension.
diff --git a/clang/test/Driver/riscv-profiles.c 
b/clang/test/Driver/riscv-profiles.c
index d85ac8baf4edd9..2b4d19422874cf 100644
--- a/clang/test/Driver/riscv-profiles.c
+++ b/clang/test/Driver/riscv-profiles.c
@@ -207,7 +207,7 @@
 // RVA23S64: "-target-feature" "+svnapot"
 // RVA23S64: "-target-feature" "+svpbmt"
 
-// RUN: %clang --target=riscv64 -### -c %s 2>&1 -march=rvb23u64 
-menable-experimental-extensions \
+// RUN: %clang --target=riscv64 -### -c %s 2>&1 -march=rvb23u64 \
 // RUN:   | FileCheck -check-prefix=RVB23U64 %s
 // RVB23U64: "-target-feature" "+m"
 // RVB23U64: "-target-feature" "+a"
@@ -239,7 +239,7 @@
 // RVB23U64: "-target-feature" "+zbs"
 // RVB23U64: "-target-feature" "+zkt"
 
-// RUN: %clang --target=riscv64 -### -c %s 2>&1 -march=rvb23s64 
-menable-experimental-extensions \
+// RUN: %clang --target=riscv64 -### -c %s 2>&1 -march=rvb23s64 \
 // RUN:   | FileCheck -check-prefix=RVB23S64 %s
 // RVB23S64: "-target-feature" "+m"
 // RVB23S64: "-target-feature" "+a"
diff --git a/llvm/docs/RISCVUsage.rst b/llvm/docs/RISCVUsage.rst
index 04f2c357766d44..f6f2eb45c49c17 100644
--- a/llvm/docs/RISCVUsage.rst
+++ b/llvm/docs/RISCVUsage.rst
@@ -84,6 +84,8 @@ ISA naming string. Currently supported profiles:
 * ``rva22s64``
 * ``rva23u64``
 * ``rva23s64``
+* ``rvb23u64``
+* ``rvb23s64``
 
 Note that you can also append additional extension names to be enabled, e.g.
 ``rva20u64_zicond`` will enable the ``zicond`` extension in addition to those
@@ -93,8 +95,6 @@ Profiles that are not yet ratified cannot be used unless
 ``-menable-experimental-extensions`` (or equivalent for other tools) is
 specified. This applies to the following profiles:
 
-* ``rvb23u64``
-* ``rvb23s64``
 * ``rvm23u32``
 
 .. _riscv-extensions:
diff --git a/llvm/docs/ReleaseNotes.md b/llvm/docs/ReleaseNotes.md
index ac7a795daf791a..92a45d845f1db8 100644
--- a/llvm/docs/ReleaseNotes.md
+++ b/llvm/docs/ReleaseNotes.md
@@ -184,7 +184,8 @@ Changes to the RISC-V Backend
 * The `Smmpm`, `Smnpm`, `Ssnpm`, `Supm`, and `Sspm` pointer masking extensions
   are no longer marked as experimental.
 * The `Sha` extension is now supported.
-* The RVA23U64 and RVA23S64 profiles are no longer marked as experimental.
+* The RVA23U64, RVA23S64, RVB23U64, and RVB23S64 profiles are no longer marked
+  as experimental.
 
 Changes to the WebAssembly Backend
 --
diff --git a/llvm/lib/Target/RISCV/RISCVProfiles.td 
b/llvm/lib/Target/RISCV/RISCVProfiles.td
index ea0fe08abd7a14..cbf2a2eddf38ed 100644
--- a/llvm/lib/Target/RISCV/RISCVProfiles.td
+++ b/llvm/lib/Target/RISCV/RISCVProfiles.td
@@ -163,6 +163,6 @@ def RVA22U64 : RISCVProfile<"rva22u64", RVA22U64Features>;
 def RVA22S64 : RISCVProfile<"rva22s64", RVA22S64Features>;
 def RVA23U64 : RISCVProfile<"rva23u64", RVA23U64Features>;
 def RVA23S64 : RISCVProfile<"rva23s64", RVA23S64Features>;
-def RVB23U64 : RISCVExperimentalProfile<"rvb23u64", RVB23U64Features>;
-def RVB23S64 : RISCVExperimentalProfile<"rvb23s64", RVB23S64Features>;
+def RVB23U64 : RISCVProfile<"rvb23u64", RVB23U64Features>;
+def RVB23S64 : RISCVProfile<"rvb23s64", RVB23S64Features>;
 def RVM23U32 : RISCVExperimentalProfile<"rvm23u32", RVM23U32Features>;
diff --git a/llvm/test/CodeGen/RISCV/attributes.ll 
b/llvm/test/CodeGen/RISCV/attributes.ll
index 2545c7075e4cf5..c03108c0617e75 100644
--- a/llvm/test/C

[clang] [llvm] [RISCV] Use the 'B' extension in RISC-V profile definitions (PR #113942)

2024-11-09 Thread Alex Bradbury via cfe-commits

asb wrote:

I've added the CHECK lines to riscv-profiles.c as spotted by @topperc, and 
based on the above discussion I think this is now ready to review.

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


[clang] [llvm] [RFC][RISCV] Use the 'B' extension in RISC-V profile definitions (PR #113942)

2024-11-09 Thread Alex Bradbury via cfe-commits

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


[clang] [llvm] [RISCV] Use the 'B' extension in RISC-V profile definitions (PR #113942)

2024-11-09 Thread Alex Bradbury via cfe-commits

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


[clang] [MS] Add /Zc:tlsGuards option to control tls guard emission (PR #113830)

2024-11-09 Thread Maurice Heumann via cfe-commits

momo5502 wrote:

@efriedma-quic is the PR fine like that?

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


[clang] [Webkit Checkers] Treat const member variables as a safe origin (PR #115594)

2024-11-09 Thread Ryosuke Niwa via cfe-commits

https://github.com/rniwa created 
https://github.com/llvm/llvm-project/pull/115594

Treat const Ref, RefPtr, CheckedRef, CheckedPtr member variables as safe 
pointer origin in WebKit's local variable and call arguments checkers.

>From 28ee8321eb6e405fd1ebae9043c3ffafe20a4b35 Mon Sep 17 00:00:00 2001
From: Ryosuke Niwa 
Date: Sat, 9 Nov 2024 00:14:36 -0800
Subject: [PATCH] [Webkit Checkers] Treat const member variables as a safe
 origin

Treat const Ref, RefPtr, CheckedRef, CheckedPtr member variables as safe 
pointer origin
in WebKit's local variable and call arguments checkers.
---
 .../Checkers/WebKit/ASTUtils.cpp  |  6 +++
 .../WebKit/RawPtrRefLocalVarsChecker.cpp  |  8 +++
 .../WebKit/call-args-checked-const-member.cpp | 43 
 .../WebKit/call-args-counted-const-member.cpp | 43 
 .../local-vars-checked-const-member.cpp   | 50 +++
 .../local-vars-counted-const-member.cpp   | 50 +++
 .../Analysis/Checkers/WebKit/mock-types.h | 25 --
 7 files changed, 211 insertions(+), 14 deletions(-)
 create mode 100644 
clang/test/Analysis/Checkers/WebKit/call-args-checked-const-member.cpp
 create mode 100644 
clang/test/Analysis/Checkers/WebKit/call-args-counted-const-member.cpp
 create mode 100644 
clang/test/Analysis/Checkers/WebKit/local-vars-checked-const-member.cpp
 create mode 100644 
clang/test/Analysis/Checkers/WebKit/local-vars-counted-const-member.cpp

diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
index 9d34dfd3cea636..ad2be6f6793cea 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
@@ -142,6 +142,12 @@ bool isASafeCallArg(const Expr *E) {
 return true;
 }
   }
+  if (auto *ME = dyn_cast(E)) {
+if (auto *D = ME->getMemberDecl()) {
+  auto T = D->getType();
+  return isSafePtrType(T) && T.isConstQualified();
+}
+  }
 
   // TODO: checker for method calls on non-refcounted objects
   return isa(E);
diff --git 
a/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefLocalVarsChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefLocalVarsChecker.cpp
index 06f8f43cee8151..be954ad3026c22 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefLocalVarsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefLocalVarsChecker.cpp
@@ -281,6 +281,14 @@ class RawPtrRefLocalVarsChecker
 if (isa(InitArgOrigin))
   return true;
 
+if (auto *ME = dyn_cast(InitArgOrigin)) {
+  if (auto *D = ME->getMemberDecl()) {
+auto T = D->getType();
+if (isSafePtrType(T) && T.isConstQualified())
+  return true;
+  }
+}
+
 if (auto *Ref = llvm::dyn_cast(InitArgOrigin)) {
   if (auto *MaybeGuardian =
   dyn_cast_or_null(Ref->getFoundDecl())) {
diff --git 
a/clang/test/Analysis/Checkers/WebKit/call-args-checked-const-member.cpp 
b/clang/test/Analysis/Checkers/WebKit/call-args-checked-const-member.cpp
new file mode 100644
index 00..6a54ac7b2ca791
--- /dev/null
+++ b/clang/test/Analysis/Checkers/WebKit/call-args-checked-const-member.cpp
@@ -0,0 +1,43 @@
+// RUN: %clang_analyze_cc1 
-analyzer-checker=alpha.webkit.UncheckedCallArgsChecker -verify %s
+
+#include "mock-types.h"
+
+namespace call_args_const_checkedptr_member {
+
+class Foo {
+public:
+  Foo();
+  void bar();
+
+private:
+  const CheckedPtr m_obj1;
+  CheckedPtr m_obj2;
+};
+
+void Foo::bar() {
+  m_obj1->method();
+  m_obj2->method();
+  // expected-warning@-1{{Call argument for 'this' parameter is unchecked and 
unsafe}}
+}
+
+} // namespace call_args_const_checkedptr_member
+
+namespace call_args_const_checkedref_member {
+
+class Foo {
+public:
+  Foo();
+  void bar();
+
+private:
+  const CheckedRef m_obj1;
+  CheckedRef m_obj2;
+};
+
+void Foo::bar() {
+  m_obj1->method();
+  m_obj2->method();
+  // expected-warning@-1{{Call argument for 'this' parameter is unchecked and 
unsafe}}
+}
+
+} // namespace call_args_const_checkedref_member
diff --git 
a/clang/test/Analysis/Checkers/WebKit/call-args-counted-const-member.cpp 
b/clang/test/Analysis/Checkers/WebKit/call-args-counted-const-member.cpp
new file mode 100644
index 00..33af5ad9014de4
--- /dev/null
+++ b/clang/test/Analysis/Checkers/WebKit/call-args-counted-const-member.cpp
@@ -0,0 +1,43 @@
+// RUN: %clang_analyze_cc1 
-analyzer-checker=alpha.webkit.UncountedCallArgsChecker -verify %s
+
+#include "mock-types.h"
+
+namespace call_args_const_refptr_member {
+
+class Foo {
+public:
+  Foo();
+  void bar();
+
+private:
+  const RefPtr m_obj1;
+  RefPtr m_obj2;
+};
+
+void Foo::bar() {
+  m_obj1->method();
+  m_obj2->method();
+  // expected-warning@-1{{Call argument for 'this' parameter is unco

[clang] [Webkit Checkers] Treat const member variables as a safe origin (PR #115594)

2024-11-09 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Ryosuke Niwa (rniwa)


Changes

Treat const Ref, RefPtr, CheckedRef, CheckedPtr member variables as safe 
pointer origin in WebKit's local variable and call arguments checkers.

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


7 Files Affected:

- (modified) clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp (+6) 
- (modified) 
clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefLocalVarsChecker.cpp (+8) 
- (added) 
clang/test/Analysis/Checkers/WebKit/call-args-checked-const-member.cpp (+43) 
- (added) 
clang/test/Analysis/Checkers/WebKit/call-args-counted-const-member.cpp (+43) 
- (added) 
clang/test/Analysis/Checkers/WebKit/local-vars-checked-const-member.cpp (+50) 
- (added) 
clang/test/Analysis/Checkers/WebKit/local-vars-counted-const-member.cpp (+50) 
- (modified) clang/test/Analysis/Checkers/WebKit/mock-types.h (+11-14) 


``diff
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
index 9d34dfd3cea636..ad2be6f6793cea 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
@@ -142,6 +142,12 @@ bool isASafeCallArg(const Expr *E) {
 return true;
 }
   }
+  if (auto *ME = dyn_cast(E)) {
+if (auto *D = ME->getMemberDecl()) {
+  auto T = D->getType();
+  return isSafePtrType(T) && T.isConstQualified();
+}
+  }
 
   // TODO: checker for method calls on non-refcounted objects
   return isa(E);
diff --git 
a/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefLocalVarsChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefLocalVarsChecker.cpp
index 06f8f43cee8151..be954ad3026c22 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefLocalVarsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/RawPtrRefLocalVarsChecker.cpp
@@ -281,6 +281,14 @@ class RawPtrRefLocalVarsChecker
 if (isa(InitArgOrigin))
   return true;
 
+if (auto *ME = dyn_cast(InitArgOrigin)) {
+  if (auto *D = ME->getMemberDecl()) {
+auto T = D->getType();
+if (isSafePtrType(T) && T.isConstQualified())
+  return true;
+  }
+}
+
 if (auto *Ref = llvm::dyn_cast(InitArgOrigin)) {
   if (auto *MaybeGuardian =
   dyn_cast_or_null(Ref->getFoundDecl())) {
diff --git 
a/clang/test/Analysis/Checkers/WebKit/call-args-checked-const-member.cpp 
b/clang/test/Analysis/Checkers/WebKit/call-args-checked-const-member.cpp
new file mode 100644
index 00..6a54ac7b2ca791
--- /dev/null
+++ b/clang/test/Analysis/Checkers/WebKit/call-args-checked-const-member.cpp
@@ -0,0 +1,43 @@
+// RUN: %clang_analyze_cc1 
-analyzer-checker=alpha.webkit.UncheckedCallArgsChecker -verify %s
+
+#include "mock-types.h"
+
+namespace call_args_const_checkedptr_member {
+
+class Foo {
+public:
+  Foo();
+  void bar();
+
+private:
+  const CheckedPtr m_obj1;
+  CheckedPtr m_obj2;
+};
+
+void Foo::bar() {
+  m_obj1->method();
+  m_obj2->method();
+  // expected-warning@-1{{Call argument for 'this' parameter is unchecked and 
unsafe}}
+}
+
+} // namespace call_args_const_checkedptr_member
+
+namespace call_args_const_checkedref_member {
+
+class Foo {
+public:
+  Foo();
+  void bar();
+
+private:
+  const CheckedRef m_obj1;
+  CheckedRef m_obj2;
+};
+
+void Foo::bar() {
+  m_obj1->method();
+  m_obj2->method();
+  // expected-warning@-1{{Call argument for 'this' parameter is unchecked and 
unsafe}}
+}
+
+} // namespace call_args_const_checkedref_member
diff --git 
a/clang/test/Analysis/Checkers/WebKit/call-args-counted-const-member.cpp 
b/clang/test/Analysis/Checkers/WebKit/call-args-counted-const-member.cpp
new file mode 100644
index 00..33af5ad9014de4
--- /dev/null
+++ b/clang/test/Analysis/Checkers/WebKit/call-args-counted-const-member.cpp
@@ -0,0 +1,43 @@
+// RUN: %clang_analyze_cc1 
-analyzer-checker=alpha.webkit.UncountedCallArgsChecker -verify %s
+
+#include "mock-types.h"
+
+namespace call_args_const_refptr_member {
+
+class Foo {
+public:
+  Foo();
+  void bar();
+
+private:
+  const RefPtr m_obj1;
+  RefPtr m_obj2;
+};
+
+void Foo::bar() {
+  m_obj1->method();
+  m_obj2->method();
+  // expected-warning@-1{{Call argument for 'this' parameter is uncounted and 
unsafe}}
+}
+
+} // namespace call_args_const_refptr_member
+
+namespace call_args_const_ref_member {
+
+class Foo {
+public:
+  Foo();
+  void bar();
+
+private:
+  const Ref m_obj1;
+  Ref m_obj2;
+};
+
+void Foo::bar() {
+  m_obj1->method();
+  m_obj2->method();
+  // expected-warning@-1{{Call argument for 'this' parameter is uncounted and 
unsafe}}
+}
+
+} // namespace call_args_const_ref_member
diff --git 
a/clang/test/Analysis/Checkers/WebKit/local-vars-checked-const-member.cpp 
b/clang/test/Analysis/Checkers/WebKit

[clang] [llvm] [X86][AMX] Support AMX-MOVRS (PR #115151)

2024-11-09 Thread Phoebe Wang via cfe-commits


@@ -151,6 +151,7 @@ set(x86_files
   amxfp8intrin.h
   amxintrin.h
   amxtransposeintrin.h
+  amxmovrsintrin.h

phoebewang wrote:

alphabetical order

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


[clang] [llvm] [X86][AMX] Support AMX-MOVRS (PR #115151)

2024-11-09 Thread Phoebe Wang via cfe-commits


@@ -17,6 +17,9 @@
 
 #define __DEFAULT_FN_ATTRS_TRANSPOSE   
\
   __attribute__((__always_inline__, __nodebug__, __target__("amx-transpose")))
+#define __DEFAULT_FN_ATTRS_TRANSPOSE_MOVRS 
\
+  __attribute__((__always_inline__, __nodebug__,   
\
+ __target__("amx-transpose,amx-movrs")))

phoebewang wrote:

Do not put them in amxtransposeintrin.h, put them in a new file like 
amxmovrstransposeintrin.h

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


[clang-tools-extra] Add bugprone-undefined-sprintf-overlap (PR #114244)

2024-11-09 Thread Nicolas van Kempen via cfe-commits


@@ -0,0 +1,82 @@
+//===--- UndefinedSprintfOverlapCheck.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 "UndefinedSprintfOverlapCheck.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+AST_MATCHER_P(IntegerLiteral, hasSameValueAs, std::string, ID) {
+  return Builder->removeBindings(
+  [this, &Node](const ast_matchers::internal::BoundNodesMap &Nodes) {
+const DynTypedNode &BN = Nodes.getNode(ID);
+if (const auto *Lit = BN.get()) {
+  return Lit->getValue() != Node.getValue();
+}
+return true;
+  });
+}
+
+UndefinedSprintfOverlapCheck::UndefinedSprintfOverlapCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  SprintfRegex(Options.get("SprintfFunction", "(::std)?::(sn?printf)")) {}
+
+void UndefinedSprintfOverlapCheck::registerMatchers(MatchFinder *Finder) {
+  auto FirstArg = declRefExpr(to(varDecl().bind("firstArgDecl")));
+  auto OtherRefToArg = 
declRefExpr(to(varDecl(equalsBoundNode("firstArgDecl"
+   .bind("overlappingArg");
+  Finder->addMatcher(
+  callExpr(
+  callee(functionDecl(matchesName(SprintfRegex)).bind("decl")),
+  allOf(hasArgument(
+0, expr(anyOf(FirstArg,
+  arraySubscriptExpr(
+  hasBase(FirstArg),
+  
hasIndex(integerLiteral().bind("index"))),
+  memberExpr(member(decl().bind("member")),
+ hasObjectExpression(FirstArg
+   .bind("firstArgExpr")),
+hasAnyArgument(expr(
+unless(equalsBoundNode("firstArgExpr")),
+anyOf(OtherRefToArg,
+  arraySubscriptExpr(hasBase(OtherRefToArg),
+ hasIndex(integerLiteral(
+ hasSameValueAs("index",
+  memberExpr(member(decl(equalsBoundNode("member"))),
+ hasObjectExpression(OtherRefToArg))),
+  this);
+}
+
+void UndefinedSprintfOverlapCheck::check(
+const MatchFinder::MatchResult &Result) {
+  const auto *OverlappingArg =
+  Result.Nodes.getNodeAs("overlappingArg");
+  const auto *FirstArg = Result.Nodes.getNodeAs("firstArgExpr");
+  const auto *FnDecl = Result.Nodes.getNodeAs("decl");
+
+  llvm::StringRef FirstArgText =
+  Lexer::getSourceText(CharSourceRange::getTokenRange(

nicovank wrote:

I'm worried this is going to give an ugly warning message when there is 
whitespace or macro usage, or when the argument in source is a very long 
expression. Maybe safer to give the argument number?

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


[clang-tools-extra] Add bugprone-undefined-sprintf-overlap (PR #114244)

2024-11-09 Thread Nicolas van Kempen via cfe-commits


@@ -0,0 +1,36 @@
+//===--- UndefinedSprintfOverlapCheck.h - clang-tidy *- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef 
LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_UNDEFINEDSPRINTFOVERLAPCHECK_H
+#define 
LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_UNDEFINEDSPRINTFOVERLAPCHECK_H
+
+#include "../ClangTidyCheck.h"
+
+namespace clang::tidy::bugprone {
+
+/// FIXME: Write a short description.
+///
+/// For the user-facing documentation see:
+/// 
http://clang.llvm.org/extra/clang-tidy/checks/bugprone/undefined-sprintf-overlap.html
+class UndefinedSprintfOverlapCheck : public ClangTidyCheck {
+public:
+  UndefinedSprintfOverlapCheck(StringRef Name, ClangTidyContext *Context);
+  void registerMatchers(ast_matchers::MatchFinder *Finder) override;
+  void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+  void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
+  std::optional getCheckTraversalKind() const override {
+return TK_IgnoreUnlessSpelledInSource;
+  }
+

nicovank wrote:

Add `isLanguageVersionSupported`.

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


[clang-tools-extra] Add bugprone-undefined-sprintf-overlap (PR #114244)

2024-11-09 Thread Nicolas van Kempen via cfe-commits


@@ -0,0 +1,82 @@
+//===--- UndefinedSprintfOverlapCheck.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 "UndefinedSprintfOverlapCheck.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+AST_MATCHER_P(IntegerLiteral, hasSameValueAs, std::string, ID) {
+  return Builder->removeBindings(
+  [this, &Node](const ast_matchers::internal::BoundNodesMap &Nodes) {
+const DynTypedNode &BN = Nodes.getNode(ID);
+if (const auto *Lit = BN.get()) {
+  return Lit->getValue() != Node.getValue();
+}
+return true;
+  });
+}
+
+UndefinedSprintfOverlapCheck::UndefinedSprintfOverlapCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  SprintfRegex(Options.get("SprintfFunction", "(::std)?::(sn?printf)")) {}
+
+void UndefinedSprintfOverlapCheck::registerMatchers(MatchFinder *Finder) {
+  auto FirstArg = declRefExpr(to(varDecl().bind("firstArgDecl")));
+  auto OtherRefToArg = 
declRefExpr(to(varDecl(equalsBoundNode("firstArgDecl"
+   .bind("overlappingArg");
+  Finder->addMatcher(
+  callExpr(
+  callee(functionDecl(matchesName(SprintfRegex)).bind("decl")),
+  allOf(hasArgument(
+0, expr(anyOf(FirstArg,
+  arraySubscriptExpr(
+  hasBase(FirstArg),
+  
hasIndex(integerLiteral().bind("index"))),
+  memberExpr(member(decl().bind("member")),
+ hasObjectExpression(FirstArg
+   .bind("firstArgExpr")),
+hasAnyArgument(expr(
+unless(equalsBoundNode("firstArgExpr")),
+anyOf(OtherRefToArg,
+  arraySubscriptExpr(hasBase(OtherRefToArg),
+ hasIndex(integerLiteral(
+ hasSameValueAs("index",
+  memberExpr(member(decl(equalsBoundNode("member"))),
+ hasObjectExpression(OtherRefToArg))),
+  this);
+}
+
+void UndefinedSprintfOverlapCheck::check(
+const MatchFinder::MatchResult &Result) {
+  const auto *OverlappingArg =
+  Result.Nodes.getNodeAs("overlappingArg");
+  const auto *FirstArg = Result.Nodes.getNodeAs("firstArgExpr");
+  const auto *FnDecl = Result.Nodes.getNodeAs("decl");
+
+  llvm::StringRef FirstArgText =

nicovank wrote:

```suggestion
  const llvm::StringRef FirstArgText =
```

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


[clang-tools-extra] Add bugprone-undefined-sprintf-overlap (PR #114244)

2024-11-09 Thread Nicolas van Kempen via cfe-commits


@@ -0,0 +1,59 @@
+// RUN: %check_clang_tidy %s bugprone-undefined-sprintf-overlap %t
+
+using size_t = decltype(sizeof(int));
+
+extern "C" int sprintf(char *s, const char *format, ...);
+extern "C" int snprintf(char *s, size_t n, const char *format, ...);
+
+namespace std {
+  int snprintf(char *s, size_t n, const char *format, ...);
+}
+
+struct st_t {
+  char buf[10];
+  char buf2[10];
+};
+
+void first_arg_overlaps() {
+  char buf[10];
+  sprintf(buf, "%s", buf);

nicovank wrote:

Add a test case where `buf` is the the first argument, e.g. `sprintf(buf, 
"%d%s", 0, buf);` to catch possible regressions.

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


[clang-tools-extra] Add bugprone-undefined-sprintf-overlap (PR #114244)

2024-11-09 Thread Nicolas van Kempen via cfe-commits


@@ -0,0 +1,82 @@
+//===--- UndefinedSprintfOverlapCheck.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 "UndefinedSprintfOverlapCheck.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+AST_MATCHER_P(IntegerLiteral, hasSameValueAs, std::string, ID) {
+  return Builder->removeBindings(
+  [this, &Node](const ast_matchers::internal::BoundNodesMap &Nodes) {
+const DynTypedNode &BN = Nodes.getNode(ID);
+if (const auto *Lit = BN.get()) {
+  return Lit->getValue() != Node.getValue();
+}
+return true;
+  });
+}
+
+UndefinedSprintfOverlapCheck::UndefinedSprintfOverlapCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  SprintfRegex(Options.get("SprintfFunction", "(::std)?::(sn?printf)")) {}
+
+void UndefinedSprintfOverlapCheck::registerMatchers(MatchFinder *Finder) {
+  auto FirstArg = declRefExpr(to(varDecl().bind("firstArgDecl")));
+  auto OtherRefToArg = 
declRefExpr(to(varDecl(equalsBoundNode("firstArgDecl"
+   .bind("overlappingArg");
+  Finder->addMatcher(
+  callExpr(
+  callee(functionDecl(matchesName(SprintfRegex)).bind("decl")),
+  allOf(hasArgument(
+0, expr(anyOf(FirstArg,
+  arraySubscriptExpr(
+  hasBase(FirstArg),
+  
hasIndex(integerLiteral().bind("index"))),
+  memberExpr(member(decl().bind("member")),
+ hasObjectExpression(FirstArg
+   .bind("firstArgExpr")),
+hasAnyArgument(expr(
+unless(equalsBoundNode("firstArgExpr")),
+anyOf(OtherRefToArg,
+  arraySubscriptExpr(hasBase(OtherRefToArg),
+ hasIndex(integerLiteral(
+ hasSameValueAs("index",
+  memberExpr(member(decl(equalsBoundNode("member"))),
+ hasObjectExpression(OtherRefToArg))),
+  this);
+}
+
+void UndefinedSprintfOverlapCheck::check(
+const MatchFinder::MatchResult &Result) {
+  const auto *OverlappingArg =
+  Result.Nodes.getNodeAs("overlappingArg");
+  const auto *FirstArg = Result.Nodes.getNodeAs("firstArgExpr");
+  const auto *FnDecl = Result.Nodes.getNodeAs("decl");
+
+  llvm::StringRef FirstArgText =
+  Lexer::getSourceText(CharSourceRange::getTokenRange(
+   FirstArg->getBeginLoc(), FirstArg->getEndLoc()),

nicovank wrote:

They are supposed to be the same, but shouldn't this be `OverlappingArg`'s 
begin and end location?

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


[clang-tools-extra] Add bugprone-undefined-sprintf-overlap (PR #114244)

2024-11-09 Thread Nicolas van Kempen via cfe-commits


@@ -0,0 +1,82 @@
+//===--- UndefinedSprintfOverlapCheck.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 "UndefinedSprintfOverlapCheck.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+AST_MATCHER_P(IntegerLiteral, hasSameValueAs, std::string, ID) {
+  return Builder->removeBindings(
+  [this, &Node](const ast_matchers::internal::BoundNodesMap &Nodes) {
+const DynTypedNode &BN = Nodes.getNode(ID);
+if (const auto *Lit = BN.get()) {
+  return Lit->getValue() != Node.getValue();
+}
+return true;
+  });
+}
+
+UndefinedSprintfOverlapCheck::UndefinedSprintfOverlapCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  SprintfRegex(Options.get("SprintfFunction", "(::std)?::(sn?printf)")) {}
+
+void UndefinedSprintfOverlapCheck::registerMatchers(MatchFinder *Finder) {
+  auto FirstArg = declRefExpr(to(varDecl().bind("firstArgDecl")));
+  auto OtherRefToArg = 
declRefExpr(to(varDecl(equalsBoundNode("firstArgDecl"
+   .bind("overlappingArg");
+  Finder->addMatcher(
+  callExpr(
+  callee(functionDecl(matchesName(SprintfRegex)).bind("decl")),
+  allOf(hasArgument(
+0, expr(anyOf(FirstArg,
+  arraySubscriptExpr(
+  hasBase(FirstArg),
+  
hasIndex(integerLiteral().bind("index"))),
+  memberExpr(member(decl().bind("member")),
+ hasObjectExpression(FirstArg
+   .bind("firstArgExpr")),

nicovank wrote:

This might be able to be simplified with `utils::areStatementsIdentical`.

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


[clang-tools-extra] Add bugprone-undefined-sprintf-overlap (PR #114244)

2024-11-09 Thread Nicolas van Kempen via cfe-commits

https://github.com/nicovank commented:

I have questions regarding the motivation behind adding this check:
 1. How common is this bug?
 2. What happens in practice at runtime?
 3. What are existing ways of detecting this, if any?

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


[clang-tools-extra] Add bugprone-undefined-sprintf-overlap (PR #114244)

2024-11-09 Thread Nicolas van Kempen via cfe-commits

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


[clang] e149528 - [RISCV] Use the 'B' extension in RISC-V profile definitions (#113942)

2024-11-09 Thread via cfe-commits

Author: Alex Bradbury
Date: 2024-11-10T07:18:05Z
New Revision: e1495283cf74590fbdeb6d46ad815b4d10b1902f

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

LOG: [RISCV] Use the 'B' extension in RISC-V profile definitions (#113942)

RVA22 has retroactively been defined as including 'B' (as it's a
shorthand for Zba+Zbb+Zbs, which were previously explicitly enumerated)
and RV{A,B,M}23 are defined featuring B. We don't currently infer B
whenever Zba+Zbb+Zbs are present due to concerns about compatibility
with external assemblers such as gas.

We don't believe that adding B to RVA22 will cause issues for users who
(for instance) build with clang and assemble with binutils as looking at
the binutils commit history:
zic64b support was only committed in
25f05199bb7e35820c23e802424484accb7936b1 in July 2024
B support was committed in c144f638337944101131d9fe6de4ab908f6d4c2d in
May 2024

So given we emit zic64b anyway (as it has always been in the RVA22
spec), no binutils that would have previously successfully assembled our
rva22u64 output should fail due to the addition of 'B'.

Added: 


Modified: 
clang/test/Driver/riscv-profiles.c
llvm/lib/Target/RISCV/RISCVProfiles.td
llvm/test/CodeGen/RISCV/attributes.ll

Removed: 




diff  --git a/clang/test/Driver/riscv-profiles.c 
b/clang/test/Driver/riscv-profiles.c
index 67e09d0e69ebc3..c87ec5a27822c5 100644
--- a/clang/test/Driver/riscv-profiles.c
+++ b/clang/test/Driver/riscv-profiles.c
@@ -57,6 +57,7 @@
 // RVA22U64: "-target-feature" "+f"
 // RVA22U64: "-target-feature" "+d"
 // RVA22U64: "-target-feature" "+c"
+// RVA22U64: "-target-feature" "+b"
 // RVA22U64: "-target-feature" "+zic64b"
 // RVA22U64: "-target-feature" "+zicbom"
 // RVA22U64: "-target-feature" "+zicbop"
@@ -83,6 +84,7 @@
 // RVA22S64: "-target-feature" "+f"
 // RVA22S64: "-target-feature" "+d"
 // RVA22S64: "-target-feature" "+c"
+// RVA22S64: "-target-feature" "+b"
 // RVA22S64: "-target-feature" "+zic64b"
 // RVA22S64: "-target-feature" "+zicbom"
 // RVA22S64: "-target-feature" "+zicbop"
@@ -118,6 +120,7 @@
 // RVA23U64: "-target-feature" "+f"
 // RVA23U64: "-target-feature" "+d"
 // RVA23U64: "-target-feature" "+c"
+// RVA23U64: "-target-feature" "+b"
 // RVA23U64: "-target-feature" "+v"
 // RVA23U64: "-target-feature" "+zic64b"
 // RVA23U64: "-target-feature" "+zicbom"
@@ -156,6 +159,7 @@
 // RVA23S64: "-target-feature" "+f"
 // RVA23S64: "-target-feature" "+d"
 // RVA23S64: "-target-feature" "+c"
+// RVA23S64: "-target-feature" "+b"
 // RVA23S64: "-target-feature" "+v"
 // RVA23S64: "-target-feature" "+h"
 // RVA23S64: "-target-feature" "+zic64b"
@@ -217,6 +221,7 @@
 // RVB23U64: "-target-feature" "+f"
 // RVB23U64: "-target-feature" "+d"
 // RVB23U64: "-target-feature" "+c"
+// RVB23U64: "-target-feature" "+b"
 // RVB23U64: "-target-feature" "+zic64b"
 // RVB23U64: "-target-feature" "+zicbom"
 // RVB23U64: "-target-feature" "+zicbop"
@@ -249,6 +254,7 @@
 // RVB23S64: "-target-feature" "+f"
 // RVB23S64: "-target-feature" "+d"
 // RVB23S64: "-target-feature" "+c"
+// RVB23S64: "-target-feature" "+b"
 // RVB23S64: "-target-feature" "+zic64b"
 // RVB23S64: "-target-feature" "+zicbom"
 // RVB23S64: "-target-feature" "+zicbop"
@@ -290,6 +296,7 @@
 // RUN: %clang --target=riscv32 -### -c %s 2>&1 -march=rvm23u32 
-menable-experimental-extensions \
 // RUN:   | FileCheck -check-prefix=RVM23U32 %s
 // RVM23U32: "-target-feature" "+m"
+// RVM23U32: "-target-feature" "+b"
 // RVM23U32: "-target-feature" "+zicbop"
 // RVM23U32: "-target-feature" "+zicond"
 // RVM23U32: "-target-feature" "+zicsr"
@@ -309,6 +316,7 @@
 // PROFILE-WITH-ADDITIONAL: "-target-feature" "+f"
 // PROFILE-WITH-ADDITIONAL: "-target-feature" "+d"
 // PROFILE-WITH-ADDITIONAL: "-target-feature" "+c"
+// PROFILE-WITH-ADDITIONAL: "-target-feature" "+b"
 // PROFILE-WITH-ADDITIONAL: "-target-feature" "+zicbom"
 // PROFILE-WITH-ADDITIONAL: "-target-feature" "+zicbop"
 // PROFILE-WITH-ADDITIONAL: "-target-feature" "+zicboz"

diff  --git a/llvm/lib/Target/RISCV/RISCVProfiles.td 
b/llvm/lib/Target/RISCV/RISCVProfiles.td
index cbf2a2eddf38ed..bcb776e682aea7 100644
--- a/llvm/lib/Target/RISCV/RISCVProfiles.td
+++ b/llvm/lib/Target/RISCV/RISCVProfiles.td
@@ -45,9 +45,7 @@ defvar RVA22U64Features = !listconcat(RVA20U64BaseFeatures,
   [FeatureStdExtZa64rs,
FeatureStdExtZihpm,
FeatureStdExtZihintpause,
-   FeatureStdExtZba,
-   FeatureStdExtZbb,
-   FeatureStdExtZbs,
+   FeatureStdExtB,
FeatureStdExtZic64b,

[clang] [llvm] [RISCV] Use the 'B' extension in RISC-V profile definitions (PR #113942)

2024-11-09 Thread Alex Bradbury via cfe-commits

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


[clang] [llvm] [clang] Introduce [[clang::lifetime_capture_by(X)]] (PR #111499)

2024-11-09 Thread Utkarsh Saxena via cfe-commits

https://github.com/usx95 updated 
https://github.com/llvm/llvm-project/pull/111499

>From 1aae3527ccba1eeaa8da4dd4309dcbdf590c4adf Mon Sep 17 00:00:00 2001
From: Sergei Barannikov 
Date: Sun, 3 Nov 2024 20:37:26 +0300
Subject: [PATCH] [MC] Make generated `MCInstPrinter::getMnemonic` const (NFC)
 (#114682)

The value returned from the function depends only on the instruction opcode.

As a drive-by, change the type of the argument to const-reference.
---
 bolt/lib/Core/HashUtilities.cpp   |   2 +-
 clang/include/clang/Basic/Attr.td |  40 +++
 .../clang/Basic/DiagnosticSemaKinds.td|  15 +++
 clang/include/clang/Sema/Sema.h   |   7 ++
 clang/lib/AST/TypePrinter.cpp |   9 ++
 clang/lib/Sema/SemaDecl.cpp   |   1 +
 clang/lib/Sema/SemaDeclAttr.cpp   | 103 ++
 .../test/SemaCXX/attr-lifetime-capture-by.cpp |  40 +++
 llvm/include/llvm/MC/MCInstPrinter.h  |   3 +-
 llvm/include/llvm/MC/MCStreamer.h |   2 +-
 llvm/lib/MC/MCAsmStreamer.cpp |   4 +-
 .../AArch64/MCTargetDesc/AArch64InstPrinter.h |   6 +-
 .../AMDGPU/MCTargetDesc/AMDGPUInstPrinter.h   |   3 +-
 .../AMDGPU/MCTargetDesc/R600InstPrinter.h |   3 +-
 .../Target/ARC/MCTargetDesc/ARCInstPrinter.h  |   3 +-
 .../Target/ARM/MCTargetDesc/ARMInstPrinter.h  |   3 +-
 .../Target/AVR/MCTargetDesc/AVRInstPrinter.h  |   3 +-
 .../Target/BPF/MCTargetDesc/BPFInstPrinter.h  |   3 +-
 .../CSKY/MCTargetDesc/CSKYInstPrinter.h   |   3 +-
 .../MCTargetDesc/DirectXMCTargetDesc.cpp  |   3 +-
 .../Hexagon/MCTargetDesc/HexagonInstPrinter.h |   3 +-
 .../Lanai/MCTargetDesc/LanaiInstPrinter.h |   3 +-
 .../MCTargetDesc/LoongArchInstPrinter.h   |   3 +-
 .../M68k/MCTargetDesc/M68kInstPrinter.h   |   3 +-
 .../MSP430/MCTargetDesc/MSP430InstPrinter.h   |   3 +-
 .../Mips/MCTargetDesc/MipsInstPrinter.h   |   3 +-
 .../NVPTX/MCTargetDesc/NVPTXInstPrinter.h |   3 +-
 .../PowerPC/MCTargetDesc/PPCInstPrinter.h |   3 +-
 .../RISCV/MCTargetDesc/RISCVInstPrinter.h |   3 +-
 .../SPIRV/MCTargetDesc/SPIRVInstPrinter.h |   3 +-
 .../Sparc/MCTargetDesc/SparcInstPrinter.h |   3 +-
 .../MCTargetDesc/SystemZGNUInstPrinter.h  |   3 +-
 .../MCTargetDesc/SystemZHLASMInstPrinter.h|   3 +-
 .../Target/VE/MCTargetDesc/VEInstPrinter.h|   3 +-
 .../MCTargetDesc/WebAssemblyInstPrinter.cpp   |   2 +-
 .../MCTargetDesc/WebAssemblyInstPrinter.h |   3 +-
 .../X86/MCTargetDesc/X86ATTInstPrinter.h  |   3 +-
 .../X86/MCTargetDesc/X86IntelInstPrinter.h|   3 +-
 .../XCore/MCTargetDesc/XCoreInstPrinter.h |   3 +-
 .../Xtensa/MCTargetDesc/XtensaInstPrinter.h   |   3 +-
 llvm/utils/TableGen/AsmWriterEmitter.cpp  |   9 +-
 41 files changed, 285 insertions(+), 39 deletions(-)
 create mode 100644 clang/test/SemaCXX/attr-lifetime-capture-by.cpp

diff --git a/bolt/lib/Core/HashUtilities.cpp b/bolt/lib/Core/HashUtilities.cpp
index dfbbdb8a968fe6..6bdf30460f340b 100644
--- a/bolt/lib/Core/HashUtilities.cpp
+++ b/bolt/lib/Core/HashUtilities.cpp
@@ -145,7 +145,7 @@ std::string hashBlockLoose(BinaryContext &BC, const 
BinaryBasicBlock &BB) {
   continue;
 }
 
-std::string Mnemonic = BC.InstPrinter->getMnemonic(&Inst).first;
+std::string Mnemonic = BC.InstPrinter->getMnemonic(Inst).first;
 llvm::erase_if(Mnemonic, [](unsigned char ch) { return std::isspace(ch); 
});
 Opcodes.insert(Mnemonic);
   }
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 156fbd1c4442eb..cb56ace6eaff47 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1873,6 +1873,46 @@ def LifetimeBound : DeclOrTypeAttr {
   let SimpleHandler = 1;
 }
 
+def LifetimeCaptureBy : DeclOrTypeAttr {
+  let Spellings = [Clang<"lifetime_capture_by", 0>];
+  let Subjects = SubjectList<[ParmVar, ImplicitObjectParameter], ErrorDiag>;
+  let Args = [VariadicParamOrParamIdxArgument<"Params">];
+  let Documentation = [LifetimeBoundDocs];
+  let LangOpts = [CPlusPlus];
+
+  // let SimpleHandler = 1;
+  // let LateParsed = LateAttrParseStandard;
+  // let HasCustomParsing = 1;
+  // let ParseArgumentsAsUnevaluated = 1;
+
+  let AdditionalMembers = [{
+private:
+  SmallVector ArgIdents;
+  SmallVector ArgLocs;
+
+public:
+  static constexpr int INVALID = -2;
+  static constexpr int UNKNOWN = -1;
+  static constexpr int GLOBAL = -1;
+  static constexpr int THIS = 0;
+
+  void setArgs(SmallVector Idents,
+   SmallVector Locs) { 
+assert(Idents.size() == Locs.size());
+assert(Idents.size() == params_Size);
+ArgIdents = std::move(Idents);
+ArgLocs = std::move(Locs);
+  }
+  
+  const SmallVector& getArgIdents() const { return 
ArgIdents; }
+  const SmallVector& getArgLocs() const { return ArgLocs; }
+  void setParamIdx(size_t Idx, int Val) { 
+assert(Idx < params_Size);
+params_[Idx] = Val;
+  }
+}];
+}
+
 def TrivialABI : Inherita

[clang] [clang] Introduce [[clang::lifetime_capture_by(X)]] (PR #111499)

2024-11-09 Thread Utkarsh Saxena via cfe-commits

https://github.com/usx95 updated 
https://github.com/llvm/llvm-project/pull/111499

>From fa191212f1d0e381503c250c3387e10a5f244576 Mon Sep 17 00:00:00 2001
From: Utkarsh Saxena 
Date: Sun, 10 Nov 2024 07:42:49 +
Subject: [PATCH] Introduce [[clang::lifetime_capture_by]]

---
 clang/include/clang/Basic/Attr.td |  40 +++
 .../clang/Basic/DiagnosticSemaKinds.td|  12 ++
 clang/include/clang/Sema/Sema.h   |   7 ++
 clang/lib/AST/TypePrinter.cpp |   9 ++
 clang/lib/Sema/SemaDecl.cpp   |   1 +
 clang/lib/Sema/SemaDeclAttr.cpp   | 103 ++
 .../test/SemaCXX/attr-lifetime-capture-by.cpp |  40 +++
 7 files changed, 212 insertions(+)
 create mode 100644 clang/test/SemaCXX/attr-lifetime-capture-by.cpp

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 156fbd1c4442eb..cb56ace6eaff47 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1873,6 +1873,46 @@ def LifetimeBound : DeclOrTypeAttr {
   let SimpleHandler = 1;
 }
 
+def LifetimeCaptureBy : DeclOrTypeAttr {
+  let Spellings = [Clang<"lifetime_capture_by", 0>];
+  let Subjects = SubjectList<[ParmVar, ImplicitObjectParameter], ErrorDiag>;
+  let Args = [VariadicParamOrParamIdxArgument<"Params">];
+  let Documentation = [LifetimeBoundDocs];
+  let LangOpts = [CPlusPlus];
+
+  // let SimpleHandler = 1;
+  // let LateParsed = LateAttrParseStandard;
+  // let HasCustomParsing = 1;
+  // let ParseArgumentsAsUnevaluated = 1;
+
+  let AdditionalMembers = [{
+private:
+  SmallVector ArgIdents;
+  SmallVector ArgLocs;
+
+public:
+  static constexpr int INVALID = -2;
+  static constexpr int UNKNOWN = -1;
+  static constexpr int GLOBAL = -1;
+  static constexpr int THIS = 0;
+
+  void setArgs(SmallVector Idents,
+   SmallVector Locs) { 
+assert(Idents.size() == Locs.size());
+assert(Idents.size() == params_Size);
+ArgIdents = std::move(Idents);
+ArgLocs = std::move(Locs);
+  }
+  
+  const SmallVector& getArgIdents() const { return 
ArgIdents; }
+  const SmallVector& getArgLocs() const { return ArgLocs; }
+  void setParamIdx(size_t Idx, int Val) { 
+assert(Idx < params_Size);
+params_[Idx] = Val;
+  }
+}];
+}
+
 def TrivialABI : InheritableAttr {
   // This attribute does not have a C [[]] spelling because it requires the
   // CPlusPlus language option.
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index d697e6d61afa9a..cd36ef43113507 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -3383,6 +3383,18 @@ def err_callback_callee_is_variadic : Error<
   "'callback' attribute callee may not be variadic">;
 def err_callback_implicit_this_not_available : Error<
   "'callback' argument at position %0 references unavailable implicit 'this'">;
+
+def err_capture_by_attribute_multiple : Error<
+  "multiple 'lifetime_capture' attributes specified">;
+def err_capture_by_attribute_no_entity : Error<
+  "'lifetime_capture_by' attribute specifies no capturing entity">;
+def err_capture_by_implicit_this_not_available : Error<
+  "'lifetime_capture_by' argument references unavailable implicit 'this'">;
+def err_capture_by_attribute_argument_unknown : Error<
+  "'lifetime_capture_by' attribute argument %0 is not a known function 
parameter"
+  ". Must be a function parameter of one of 'this', 'global' or 'unknown'">;
+def err_capture_by_references_itself : Error<"'lifetime_capture_by' argument 
references itself">;
+
 def err_init_method_bad_return_type : Error<
   "init methods must return an object pointer type, not %0">;
 def err_attribute_invalid_size : Error<
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 93d98e1cbb9c81..9eb158d223bf5a 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -1760,6 +1760,10 @@ class Sema final : public SemaBase {
   /// Add [[gsl::Pointer]] attributes for std:: types.
   void inferGslPointerAttribute(TypedefNameDecl *TD);
 
+  LifetimeCaptureByAttr *ParseLifetimeCaptureByAttr(const ParsedAttr &AL,
+StringRef ParamName);
+  void LazyProcessLifetimeCaptureByParams(FunctionDecl *FD);
+
   /// Add _Nullable attributes for std:: types.
   void inferNullableClassAttribute(CXXRecordDecl *CRD);
 
@@ -2315,6 +2319,9 @@ class Sema final : public SemaBase {
   bool BuiltinVectorMath(CallExpr *TheCall, QualType &Res, bool FPOnly = 
false);
   bool BuiltinVectorToScalarMath(CallExpr *TheCall);
 
+  void checkLifetimeCaptureBy(FunctionDecl *FDecl, bool IsMemberFunction,
+  const Expr *ThisArg, ArrayRef 
Args);
+
   /// Handles the checks for format strings, non-POD arguments to vararg
   /// functions, NULL arguments passed to non-NULL parameters, diagnose_if
   /// attributes 

[clang] [llvm] [X86][AMX] Support AMX-TF32 (PR #115625)

2024-11-09 Thread Feng Zou via cfe-commits

https://github.com/fzou1 created 
https://github.com/llvm/llvm-project/pull/115625

Ref.: https://cdrdv2.intel.com/v1/dl/getContent/671368

>From b1d9799b99b45b5af2b63868c4c3b139dbf9378c Mon Sep 17 00:00:00 2001
From: Feng Zou 
Date: Sat, 26 Oct 2024 18:44:32 +0800
Subject: [PATCH] [X86][AMX] Support AMX-TF32

Ref.: https://cdrdv2.intel.com/v1/dl/getContent/671368
---
 clang/docs/ReleaseNotes.rst   |   1 +
 clang/include/clang/Basic/BuiltinsX86_64.def  |  15 +-
 clang/include/clang/Driver/Options.td |   2 +
 clang/lib/Basic/Targets/X86.cpp   |   6 +
 clang/lib/Basic/Targets/X86.h |   1 +
 clang/lib/Headers/CMakeLists.txt  |   1 +
 clang/lib/Headers/amxtf32intrin.h | 194 ++
 clang/lib/Headers/immintrin.h |   4 +
 clang/lib/Sema/SemaX86.cpp|   2 +
 clang/test/CodeGen/X86/amx_tf32.c |  17 ++
 clang/test/CodeGen/X86/amx_tf32_api.c |  27 +++
 clang/test/CodeGen/X86/amx_tf32_errors.c  |  23 +++
 clang/test/CodeGen/X86/amx_tf32_inline_asm.c  |  18 ++
 clang/test/Driver/x86-target-features.c   |   7 +
 clang/test/Preprocessor/x86_target_features.c |   9 +
 llvm/include/llvm/IR/IntrinsicsX86.td |  19 ++
 .../llvm/TargetParser/X86TargetParser.def |   1 +
 llvm/lib/Target/X86/X86.td|   3 +
 llvm/lib/Target/X86/X86ExpandPseudo.cpp   |  11 +-
 llvm/lib/Target/X86/X86ISelLowering.cpp   |  22 ++
 llvm/lib/Target/X86/X86InstrAMX.td|  52 +
 llvm/lib/Target/X86/X86InstrPredicates.td |   1 +
 llvm/lib/Target/X86/X86LowerAMXType.cpp   |  20 +-
 llvm/lib/Target/X86/X86RegisterInfo.cpp   |   4 +-
 llvm/lib/TargetParser/Host.cpp|   1 +
 llvm/lib/TargetParser/X86TargetParser.cpp |   1 +
 llvm/test/CodeGen/X86/amx-tf32-internal.ll|  47 +
 llvm/test/CodeGen/X86/amx-tf32-intrinsics.ll  |  23 +++
 .../Disassembler/X86/AMX/x86-64-amx-tf32.txt  |  19 ++
 llvm/test/MC/X86/AMX/x86-64-amx-tf32-att.s|  17 ++
 llvm/test/MC/X86/AMX/x86-64-amx-tf32-intel.s  |  17 ++
 31 files changed, 578 insertions(+), 7 deletions(-)
 create mode 100644 clang/lib/Headers/amxtf32intrin.h
 create mode 100644 clang/test/CodeGen/X86/amx_tf32.c
 create mode 100644 clang/test/CodeGen/X86/amx_tf32_api.c
 create mode 100644 clang/test/CodeGen/X86/amx_tf32_errors.c
 create mode 100644 clang/test/CodeGen/X86/amx_tf32_inline_asm.c
 create mode 100644 llvm/test/CodeGen/X86/amx-tf32-internal.ll
 create mode 100644 llvm/test/CodeGen/X86/amx-tf32-intrinsics.ll
 create mode 100644 llvm/test/MC/Disassembler/X86/AMX/x86-64-amx-tf32.txt
 create mode 100644 llvm/test/MC/X86/AMX/x86-64-amx-tf32-att.s
 create mode 100644 llvm/test/MC/X86/AMX/x86-64-amx-tf32-intel.s

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index c3424e0e6f34c9..e235a04f78112b 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -740,6 +740,7 @@ X86 Support
 - Support ISA of ``AMX-FP8``.
 - Support ISA of ``AMX-TRANSPOSE``.
 - Support ISA of ``AMX-AVX512``.
+- Support ISA of ``AMX-TF32``.
 
 Arm and AArch64 Support
 ^^^
diff --git a/clang/include/clang/Basic/BuiltinsX86_64.def 
b/clang/include/clang/Basic/BuiltinsX86_64.def
index 9f7462b1e0d962..25c10d39df32e2 100644
--- a/clang/include/clang/Basic/BuiltinsX86_64.def
+++ b/clang/include/clang/Basic/BuiltinsX86_64.def
@@ -139,6 +139,9 @@ TARGET_BUILTIN(__builtin_ia32_tcvtrowps2pbf16l_internal, 
"V32yUsUsV256iUi", "n",
 TARGET_BUILTIN(__builtin_ia32_tcvtrowps2phh_internal, "V32xUsUsV256iUi", "n", 
"amx-avx512,avx10.2-512")
 TARGET_BUILTIN(__builtin_ia32_tcvtrowps2phl_internal, "V32xUsUsV256iUi", "n", 
"amx-avx512,avx10.2-512")
 TARGET_BUILTIN(__builtin_ia32_tilemovrow_internal, "V16iUsUsV256iUi", "n", 
"amx-avx512,avx10.2-512")
+TARGET_BUILTIN(__builtin_ia32_tmmultf32ps_internal, 
"V256iUsUsUsV256iV256iV256i", "n", "amx-tf32")
+TARGET_BUILTIN(__builtin_ia32_ttmmultf32ps_internal, 
"V256iUsUsUsV256iV256iV256i", "n", "amx-tf32,amx-transpose")
+
 // AMX
 TARGET_BUILTIN(__builtin_ia32_tile_loadconfig, "vvC*", "n", "amx-tile")
 TARGET_BUILTIN(__builtin_ia32_tile_storeconfig, "vvC*", "n", "amx-tile")
@@ -172,10 +175,6 @@ TARGET_BUILTIN(__builtin_ia32_tcvtrowps2phh, "V32xIUcUi", 
"n", "amx-avx512,avx10
 TARGET_BUILTIN(__builtin_ia32_tcvtrowps2phl, "V32xIUcUi", "n", 
"amx-avx512,avx10.2-512")
 TARGET_BUILTIN(__builtin_ia32_tilemovrow, "V16iIUcUi", "n", 
"amx-avx512,avx10.2-512")
 
-TARGET_BUILTIN(__builtin_ia32_prefetchi, "vvC*Ui", "nc", "prefetchi")
-TARGET_BUILTIN(__builtin_ia32_cmpccxadd32, "Siv*SiSiIi", "n", "cmpccxadd")
-TARGET_BUILTIN(__builtin_ia32_cmpccxadd64, "SLLiSLLi*SLLiSLLiIi", "n", 
"cmpccxadd")
-
 // AMX_FP16 FP16
 TARGET_BUILTIN(__builtin_ia32_tdpfp16ps, "vIUcIUcIUc", "n", "amx-fp16")
 
@@ -185,6 +184,14 @@ TARGET_BUILTIN(__builtin_ia32_tdpbhf8ps, "vIUcUIcUIc", 
"n", "amx-fp8")
 TARGET_BUILTIN(__builtin_ia32_tdphbf8ps, "vIUcUIcUIc",

[clang] [StaticAnalyzer] early return if sym is concrete on assuming (PR #115579)

2024-11-09 Thread Ding Fei via cfe-commits

danix800 wrote:

Yes these two are related.

Solver is the root cause, the checker crash is the effect. Either fix could 
cover the crash
but not enough without the other.

The solver is inherently incapable of solving some constraints, which would 
brings in
some overly constrainted states. We could try to improve the  solver's 
precision as much
as possible. In this case these impossible states would crash the checker.

The checker should protectively test against impossible states since they're 
inevitable.

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


[clang] [llvm] [X86][AMX] Support AMX-TF32 (PR #115625)

2024-11-09 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Feng Zou (fzou1)


Changes

Ref.: https://cdrdv2.intel.com/v1/dl/getContent/671368

---

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


31 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+1) 
- (modified) clang/include/clang/Basic/BuiltinsX86_64.def (+11-4) 
- (modified) clang/include/clang/Driver/Options.td (+2) 
- (modified) clang/lib/Basic/Targets/X86.cpp (+6) 
- (modified) clang/lib/Basic/Targets/X86.h (+1) 
- (modified) clang/lib/Headers/CMakeLists.txt (+1) 
- (added) clang/lib/Headers/amxtf32intrin.h (+194) 
- (modified) clang/lib/Headers/immintrin.h (+4) 
- (modified) clang/lib/Sema/SemaX86.cpp (+2) 
- (added) clang/test/CodeGen/X86/amx_tf32.c (+17) 
- (added) clang/test/CodeGen/X86/amx_tf32_api.c (+27) 
- (added) clang/test/CodeGen/X86/amx_tf32_errors.c (+23) 
- (added) clang/test/CodeGen/X86/amx_tf32_inline_asm.c (+18) 
- (modified) clang/test/Driver/x86-target-features.c (+7) 
- (modified) clang/test/Preprocessor/x86_target_features.c (+9) 
- (modified) llvm/include/llvm/IR/IntrinsicsX86.td (+19) 
- (modified) llvm/include/llvm/TargetParser/X86TargetParser.def (+1) 
- (modified) llvm/lib/Target/X86/X86.td (+3) 
- (modified) llvm/lib/Target/X86/X86ExpandPseudo.cpp (+10-1) 
- (modified) llvm/lib/Target/X86/X86ISelLowering.cpp (+22) 
- (modified) llvm/lib/Target/X86/X86InstrAMX.td (+52) 
- (modified) llvm/lib/Target/X86/X86InstrPredicates.td (+1) 
- (modified) llvm/lib/Target/X86/X86LowerAMXType.cpp (+19-1) 
- (modified) llvm/lib/Target/X86/X86RegisterInfo.cpp (+3-1) 
- (modified) llvm/lib/TargetParser/Host.cpp (+1) 
- (modified) llvm/lib/TargetParser/X86TargetParser.cpp (+1) 
- (added) llvm/test/CodeGen/X86/amx-tf32-internal.ll (+47) 
- (added) llvm/test/CodeGen/X86/amx-tf32-intrinsics.ll (+23) 
- (added) llvm/test/MC/Disassembler/X86/AMX/x86-64-amx-tf32.txt (+19) 
- (added) llvm/test/MC/X86/AMX/x86-64-amx-tf32-att.s (+17) 
- (added) llvm/test/MC/X86/AMX/x86-64-amx-tf32-intel.s (+17) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index c3424e0e6f34c9..e235a04f78112b 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -740,6 +740,7 @@ X86 Support
 - Support ISA of ``AMX-FP8``.
 - Support ISA of ``AMX-TRANSPOSE``.
 - Support ISA of ``AMX-AVX512``.
+- Support ISA of ``AMX-TF32``.
 
 Arm and AArch64 Support
 ^^^
diff --git a/clang/include/clang/Basic/BuiltinsX86_64.def 
b/clang/include/clang/Basic/BuiltinsX86_64.def
index 9f7462b1e0d962..25c10d39df32e2 100644
--- a/clang/include/clang/Basic/BuiltinsX86_64.def
+++ b/clang/include/clang/Basic/BuiltinsX86_64.def
@@ -139,6 +139,9 @@ TARGET_BUILTIN(__builtin_ia32_tcvtrowps2pbf16l_internal, 
"V32yUsUsV256iUi", "n",
 TARGET_BUILTIN(__builtin_ia32_tcvtrowps2phh_internal, "V32xUsUsV256iUi", "n", 
"amx-avx512,avx10.2-512")
 TARGET_BUILTIN(__builtin_ia32_tcvtrowps2phl_internal, "V32xUsUsV256iUi", "n", 
"amx-avx512,avx10.2-512")
 TARGET_BUILTIN(__builtin_ia32_tilemovrow_internal, "V16iUsUsV256iUi", "n", 
"amx-avx512,avx10.2-512")
+TARGET_BUILTIN(__builtin_ia32_tmmultf32ps_internal, 
"V256iUsUsUsV256iV256iV256i", "n", "amx-tf32")
+TARGET_BUILTIN(__builtin_ia32_ttmmultf32ps_internal, 
"V256iUsUsUsV256iV256iV256i", "n", "amx-tf32,amx-transpose")
+
 // AMX
 TARGET_BUILTIN(__builtin_ia32_tile_loadconfig, "vvC*", "n", "amx-tile")
 TARGET_BUILTIN(__builtin_ia32_tile_storeconfig, "vvC*", "n", "amx-tile")
@@ -172,10 +175,6 @@ TARGET_BUILTIN(__builtin_ia32_tcvtrowps2phh, "V32xIUcUi", 
"n", "amx-avx512,avx10
 TARGET_BUILTIN(__builtin_ia32_tcvtrowps2phl, "V32xIUcUi", "n", 
"amx-avx512,avx10.2-512")
 TARGET_BUILTIN(__builtin_ia32_tilemovrow, "V16iIUcUi", "n", 
"amx-avx512,avx10.2-512")
 
-TARGET_BUILTIN(__builtin_ia32_prefetchi, "vvC*Ui", "nc", "prefetchi")
-TARGET_BUILTIN(__builtin_ia32_cmpccxadd32, "Siv*SiSiIi", "n", "cmpccxadd")
-TARGET_BUILTIN(__builtin_ia32_cmpccxadd64, "SLLiSLLi*SLLiSLLiIi", "n", 
"cmpccxadd")
-
 // AMX_FP16 FP16
 TARGET_BUILTIN(__builtin_ia32_tdpfp16ps, "vIUcIUcIUc", "n", "amx-fp16")
 
@@ -185,6 +184,14 @@ TARGET_BUILTIN(__builtin_ia32_tdpbhf8ps, "vIUcUIcUIc", 
"n", "amx-fp8")
 TARGET_BUILTIN(__builtin_ia32_tdphbf8ps, "vIUcUIcUIc", "n", "amx-fp8")
 TARGET_BUILTIN(__builtin_ia32_tdphf8ps, "vIUcUIcUIc", "n", "amx-fp8")
 
+// AMX TF32
+TARGET_BUILTIN(__builtin_ia32_tmmultf32ps, "vIUcIUcIUc", "n", "amx-tf32")
+TARGET_BUILTIN(__builtin_ia32_ttmmultf32ps, "vIUcIUcIUc", "n", 
"amx-tf32,amx-transpose")
+
+TARGET_BUILTIN(__builtin_ia32_prefetchi, "vvC*Ui", "nc", "prefetchi")
+TARGET_BUILTIN(__builtin_ia32_cmpccxadd32, "Siv*SiSiIi", "n", "cmpccxadd")
+TARGET_BUILTIN(__builtin_ia32_cmpccxadd64, "SLLiSLLi*SLLiSLLiIi", "n", 
"cmpccxadd")
+
 // RAO-INT
 TARGET_BUILTIN(__builtin_ia32_aadd64, "vv*SOi", "n", "raoint")
 TARGET_BUILTIN(__builtin_ia32_aand64, "vv*SOi", "n", "raoint")
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/inclu

[clang] [llvm] [X86][AMX] Support AMX-MOVRS (PR #115151)

2024-11-09 Thread Phoebe Wang via cfe-commits


@@ -5189,6 +5193,33 @@ void X86DAGToDAGISel::Select(SDNode *Node) {
   ReplaceNode(Node, CNode);
   return;
 }
+case Intrinsic::x86_tileloaddrs64_internal:
+case Intrinsic::x86_tileloaddrst164_internal: {
+  if (!Subtarget->hasAMXMOVRS())
+break;

phoebewang wrote:

Merge with above, you can write like:
```
case Intrinsic::x86_tileloaddrs64_internal:
case Intrinsic::x86_tileloaddrst164_internal:
  if (!Subtarget->hasAMXMOVRS())
break;
  [[fallthrough]];
case Intrinsic::x86_tileloadd64_internal:
case Intrinsic::x86_tileloaddt164_internal: {
  if (!Subtarget->hasAMXTILE())
```

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


[clang] [llvm] [X86][AMX] Support AMX-MOVRS (PR #115151)

2024-11-09 Thread Phoebe Wang via cfe-commits

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


[clang] [llvm] [X86][AMX] Support AMX-MOVRS (PR #115151)

2024-11-09 Thread Phoebe Wang via cfe-commits


@@ -27291,6 +27291,13 @@ static SDValue LowerINTRINSIC_W_CHAIN(SDValue Op, 
const X86Subtarget &Subtarget,
   return DAG.getNode(ISD::MERGE_VALUES, dl, Op->getVTList(), SetCC,
  Operation.getValue(1));
 }
+case Intrinsic::x86_t2rpntlvwz0rs_internal:
+case Intrinsic::x86_t2rpntlvwz0rst1_internal:
+case Intrinsic::x86_t2rpntlvwz1rs_internal:
+case Intrinsic::x86_t2rpntlvwz1rst1_internal:
+  if (!Subtarget.hasAMXTRANSPOSE() || !Subtarget.hasAMXMOVRS())
+break;

phoebewang wrote:

Checking `Subtarget.hasAMXMOVRS()` only.

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


[clang] [llvm] [X86][AMX] Support AMX-TF32 (PR #115625)

2024-11-09 Thread Feng Zou via cfe-commits

https://github.com/fzou1 updated 
https://github.com/llvm/llvm-project/pull/115625

>From b1d9799b99b45b5af2b63868c4c3b139dbf9378c Mon Sep 17 00:00:00 2001
From: Feng Zou 
Date: Sat, 26 Oct 2024 18:44:32 +0800
Subject: [PATCH 1/2] [X86][AMX] Support AMX-TF32

Ref.: https://cdrdv2.intel.com/v1/dl/getContent/671368
---
 clang/docs/ReleaseNotes.rst   |   1 +
 clang/include/clang/Basic/BuiltinsX86_64.def  |  15 +-
 clang/include/clang/Driver/Options.td |   2 +
 clang/lib/Basic/Targets/X86.cpp   |   6 +
 clang/lib/Basic/Targets/X86.h |   1 +
 clang/lib/Headers/CMakeLists.txt  |   1 +
 clang/lib/Headers/amxtf32intrin.h | 194 ++
 clang/lib/Headers/immintrin.h |   4 +
 clang/lib/Sema/SemaX86.cpp|   2 +
 clang/test/CodeGen/X86/amx_tf32.c |  17 ++
 clang/test/CodeGen/X86/amx_tf32_api.c |  27 +++
 clang/test/CodeGen/X86/amx_tf32_errors.c  |  23 +++
 clang/test/CodeGen/X86/amx_tf32_inline_asm.c  |  18 ++
 clang/test/Driver/x86-target-features.c   |   7 +
 clang/test/Preprocessor/x86_target_features.c |   9 +
 llvm/include/llvm/IR/IntrinsicsX86.td |  19 ++
 .../llvm/TargetParser/X86TargetParser.def |   1 +
 llvm/lib/Target/X86/X86.td|   3 +
 llvm/lib/Target/X86/X86ExpandPseudo.cpp   |  11 +-
 llvm/lib/Target/X86/X86ISelLowering.cpp   |  22 ++
 llvm/lib/Target/X86/X86InstrAMX.td|  52 +
 llvm/lib/Target/X86/X86InstrPredicates.td |   1 +
 llvm/lib/Target/X86/X86LowerAMXType.cpp   |  20 +-
 llvm/lib/Target/X86/X86RegisterInfo.cpp   |   4 +-
 llvm/lib/TargetParser/Host.cpp|   1 +
 llvm/lib/TargetParser/X86TargetParser.cpp |   1 +
 llvm/test/CodeGen/X86/amx-tf32-internal.ll|  47 +
 llvm/test/CodeGen/X86/amx-tf32-intrinsics.ll  |  23 +++
 .../Disassembler/X86/AMX/x86-64-amx-tf32.txt  |  19 ++
 llvm/test/MC/X86/AMX/x86-64-amx-tf32-att.s|  17 ++
 llvm/test/MC/X86/AMX/x86-64-amx-tf32-intel.s  |  17 ++
 31 files changed, 578 insertions(+), 7 deletions(-)
 create mode 100644 clang/lib/Headers/amxtf32intrin.h
 create mode 100644 clang/test/CodeGen/X86/amx_tf32.c
 create mode 100644 clang/test/CodeGen/X86/amx_tf32_api.c
 create mode 100644 clang/test/CodeGen/X86/amx_tf32_errors.c
 create mode 100644 clang/test/CodeGen/X86/amx_tf32_inline_asm.c
 create mode 100644 llvm/test/CodeGen/X86/amx-tf32-internal.ll
 create mode 100644 llvm/test/CodeGen/X86/amx-tf32-intrinsics.ll
 create mode 100644 llvm/test/MC/Disassembler/X86/AMX/x86-64-amx-tf32.txt
 create mode 100644 llvm/test/MC/X86/AMX/x86-64-amx-tf32-att.s
 create mode 100644 llvm/test/MC/X86/AMX/x86-64-amx-tf32-intel.s

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index c3424e0e6f34c9..e235a04f78112b 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -740,6 +740,7 @@ X86 Support
 - Support ISA of ``AMX-FP8``.
 - Support ISA of ``AMX-TRANSPOSE``.
 - Support ISA of ``AMX-AVX512``.
+- Support ISA of ``AMX-TF32``.
 
 Arm and AArch64 Support
 ^^^
diff --git a/clang/include/clang/Basic/BuiltinsX86_64.def 
b/clang/include/clang/Basic/BuiltinsX86_64.def
index 9f7462b1e0d962..25c10d39df32e2 100644
--- a/clang/include/clang/Basic/BuiltinsX86_64.def
+++ b/clang/include/clang/Basic/BuiltinsX86_64.def
@@ -139,6 +139,9 @@ TARGET_BUILTIN(__builtin_ia32_tcvtrowps2pbf16l_internal, 
"V32yUsUsV256iUi", "n",
 TARGET_BUILTIN(__builtin_ia32_tcvtrowps2phh_internal, "V32xUsUsV256iUi", "n", 
"amx-avx512,avx10.2-512")
 TARGET_BUILTIN(__builtin_ia32_tcvtrowps2phl_internal, "V32xUsUsV256iUi", "n", 
"amx-avx512,avx10.2-512")
 TARGET_BUILTIN(__builtin_ia32_tilemovrow_internal, "V16iUsUsV256iUi", "n", 
"amx-avx512,avx10.2-512")
+TARGET_BUILTIN(__builtin_ia32_tmmultf32ps_internal, 
"V256iUsUsUsV256iV256iV256i", "n", "amx-tf32")
+TARGET_BUILTIN(__builtin_ia32_ttmmultf32ps_internal, 
"V256iUsUsUsV256iV256iV256i", "n", "amx-tf32,amx-transpose")
+
 // AMX
 TARGET_BUILTIN(__builtin_ia32_tile_loadconfig, "vvC*", "n", "amx-tile")
 TARGET_BUILTIN(__builtin_ia32_tile_storeconfig, "vvC*", "n", "amx-tile")
@@ -172,10 +175,6 @@ TARGET_BUILTIN(__builtin_ia32_tcvtrowps2phh, "V32xIUcUi", 
"n", "amx-avx512,avx10
 TARGET_BUILTIN(__builtin_ia32_tcvtrowps2phl, "V32xIUcUi", "n", 
"amx-avx512,avx10.2-512")
 TARGET_BUILTIN(__builtin_ia32_tilemovrow, "V16iIUcUi", "n", 
"amx-avx512,avx10.2-512")
 
-TARGET_BUILTIN(__builtin_ia32_prefetchi, "vvC*Ui", "nc", "prefetchi")
-TARGET_BUILTIN(__builtin_ia32_cmpccxadd32, "Siv*SiSiIi", "n", "cmpccxadd")
-TARGET_BUILTIN(__builtin_ia32_cmpccxadd64, "SLLiSLLi*SLLiSLLiIi", "n", 
"cmpccxadd")
-
 // AMX_FP16 FP16
 TARGET_BUILTIN(__builtin_ia32_tdpfp16ps, "vIUcIUcIUc", "n", "amx-fp16")
 
@@ -185,6 +184,14 @@ TARGET_BUILTIN(__builtin_ia32_tdpbhf8ps, "vIUcUIcUIc", 
"n", "amx-fp8")
 TARGET_BUILTIN(__builtin_ia32_tdphbf8ps, "vIUcUIcUIc", "n", "amx-fp8")
 TARGET_BUILTIN(__builtin_ia32_tdph

[clang] [llvm] [X86][AMX] Support AMX-MOVRS (PR #115151)

2024-11-09 Thread Phoebe Wang via cfe-commits


@@ -558,6 +558,15 @@ bool X86ExpandPseudo::expandMI(MachineBasicBlock &MBB,
 MI.setDesc(TII->get(GET_EGPR_IF_ENABLED(X86::LDTILECFG)));
 return true;
   }
+  case X86::PTILELOADDRSV:
+  case X86::PTILELOADDRST1V: {
+for (unsigned i = 2; i > 0; --i)
+  MI.removeOperand(i);
+unsigned Opc =
+Opcode == X86::PTILELOADDRSV ? X86::TILELOADDRS : X86::TILELOADDRST1;
+MI.setDesc(TII->get(Opc));
+return true;
+  }

phoebewang wrote:

Rebase and merge with `X86::PTILELOADDV`

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


[clang] [llvm] [X86][AMX] Support AMX-MOVRS (PR #115151)

2024-11-09 Thread Phoebe Wang via cfe-commits


@@ -687,6 +696,32 @@ bool X86ExpandPseudo::expandMI(MachineBasicBlock &MBB,
 MI.setDesc(TII->get(Opc));
 return true;
   }
+  case X86::PT2RPNTLVWZ0RSV:
+  case X86::PT2RPNTLVWZ0RST1V:
+  case X86::PT2RPNTLVWZ1RSV:
+  case X86::PT2RPNTLVWZ1RST1V: {

phoebewang wrote:

Merge with `X86::PT2RPNTLVWZ0V`

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


[clang] [llvm] [X86][AMX] Support AMX-MOVRS (PR #115151)

2024-11-09 Thread Phoebe Wang via cfe-commits


@@ -5342,9 +5411,45 @@ void X86DAGToDAGISel::Select(SDNode *Node) {
   SDValue Disp = CurDAG->getTargetConstant(0, dl, MVT::i32);
   SDValue Segment = CurDAG->getRegister(0, MVT::i16);
   SDValue Chain = Node->getOperand(0);
-  MachineSDNode *CNode;
   SDValue Ops[] = {TReg, Base, Scale, Index, Disp, Segment, Chain};
-  CNode = CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops);
+  MachineSDNode *CNode = CurDAG->getMachineNode(Opc, dl, MVT::Other, Ops);
+  ReplaceNode(Node, CNode);
+  return;
+}
+case Intrinsic::x86_t2rpntlvwz0rs:
+case Intrinsic::x86_t2rpntlvwz0rst1:
+case Intrinsic::x86_t2rpntlvwz1rs:
+case Intrinsic::x86_t2rpntlvwz1rst1: {
+  if (!Subtarget->hasAMXTRANSPOSE() || !Subtarget->hasAMXMOVRS())
+break;

phoebewang wrote:

ditto.

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


[clang] [llvm] [X86][AMX] Support AMX-MOVRS (PR #115151)

2024-11-09 Thread Phoebe Wang via cfe-commits


@@ -5307,6 +5338,44 @@ void X86DAGToDAGISel::Select(SDNode *Node) {
   ReplaceNode(Node, CNode);
   return;
 }
+case Intrinsic::x86_tileloaddrs64:
+case Intrinsic::x86_tileloaddrst164: {

phoebewang wrote:

ditto.

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


[clang] [llvm] [X86][AMX] Support AMX-TF32 (PR #115625)

2024-11-09 Thread Feng Zou via cfe-commits

https://github.com/fzou1 updated 
https://github.com/llvm/llvm-project/pull/115625

>From b1d9799b99b45b5af2b63868c4c3b139dbf9378c Mon Sep 17 00:00:00 2001
From: Feng Zou 
Date: Sat, 26 Oct 2024 18:44:32 +0800
Subject: [PATCH 1/3] [X86][AMX] Support AMX-TF32

Ref.: https://cdrdv2.intel.com/v1/dl/getContent/671368
---
 clang/docs/ReleaseNotes.rst   |   1 +
 clang/include/clang/Basic/BuiltinsX86_64.def  |  15 +-
 clang/include/clang/Driver/Options.td |   2 +
 clang/lib/Basic/Targets/X86.cpp   |   6 +
 clang/lib/Basic/Targets/X86.h |   1 +
 clang/lib/Headers/CMakeLists.txt  |   1 +
 clang/lib/Headers/amxtf32intrin.h | 194 ++
 clang/lib/Headers/immintrin.h |   4 +
 clang/lib/Sema/SemaX86.cpp|   2 +
 clang/test/CodeGen/X86/amx_tf32.c |  17 ++
 clang/test/CodeGen/X86/amx_tf32_api.c |  27 +++
 clang/test/CodeGen/X86/amx_tf32_errors.c  |  23 +++
 clang/test/CodeGen/X86/amx_tf32_inline_asm.c  |  18 ++
 clang/test/Driver/x86-target-features.c   |   7 +
 clang/test/Preprocessor/x86_target_features.c |   9 +
 llvm/include/llvm/IR/IntrinsicsX86.td |  19 ++
 .../llvm/TargetParser/X86TargetParser.def |   1 +
 llvm/lib/Target/X86/X86.td|   3 +
 llvm/lib/Target/X86/X86ExpandPseudo.cpp   |  11 +-
 llvm/lib/Target/X86/X86ISelLowering.cpp   |  22 ++
 llvm/lib/Target/X86/X86InstrAMX.td|  52 +
 llvm/lib/Target/X86/X86InstrPredicates.td |   1 +
 llvm/lib/Target/X86/X86LowerAMXType.cpp   |  20 +-
 llvm/lib/Target/X86/X86RegisterInfo.cpp   |   4 +-
 llvm/lib/TargetParser/Host.cpp|   1 +
 llvm/lib/TargetParser/X86TargetParser.cpp |   1 +
 llvm/test/CodeGen/X86/amx-tf32-internal.ll|  47 +
 llvm/test/CodeGen/X86/amx-tf32-intrinsics.ll  |  23 +++
 .../Disassembler/X86/AMX/x86-64-amx-tf32.txt  |  19 ++
 llvm/test/MC/X86/AMX/x86-64-amx-tf32-att.s|  17 ++
 llvm/test/MC/X86/AMX/x86-64-amx-tf32-intel.s  |  17 ++
 31 files changed, 578 insertions(+), 7 deletions(-)
 create mode 100644 clang/lib/Headers/amxtf32intrin.h
 create mode 100644 clang/test/CodeGen/X86/amx_tf32.c
 create mode 100644 clang/test/CodeGen/X86/amx_tf32_api.c
 create mode 100644 clang/test/CodeGen/X86/amx_tf32_errors.c
 create mode 100644 clang/test/CodeGen/X86/amx_tf32_inline_asm.c
 create mode 100644 llvm/test/CodeGen/X86/amx-tf32-internal.ll
 create mode 100644 llvm/test/CodeGen/X86/amx-tf32-intrinsics.ll
 create mode 100644 llvm/test/MC/Disassembler/X86/AMX/x86-64-amx-tf32.txt
 create mode 100644 llvm/test/MC/X86/AMX/x86-64-amx-tf32-att.s
 create mode 100644 llvm/test/MC/X86/AMX/x86-64-amx-tf32-intel.s

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index c3424e0e6f34c9..e235a04f78112b 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -740,6 +740,7 @@ X86 Support
 - Support ISA of ``AMX-FP8``.
 - Support ISA of ``AMX-TRANSPOSE``.
 - Support ISA of ``AMX-AVX512``.
+- Support ISA of ``AMX-TF32``.
 
 Arm and AArch64 Support
 ^^^
diff --git a/clang/include/clang/Basic/BuiltinsX86_64.def 
b/clang/include/clang/Basic/BuiltinsX86_64.def
index 9f7462b1e0d962..25c10d39df32e2 100644
--- a/clang/include/clang/Basic/BuiltinsX86_64.def
+++ b/clang/include/clang/Basic/BuiltinsX86_64.def
@@ -139,6 +139,9 @@ TARGET_BUILTIN(__builtin_ia32_tcvtrowps2pbf16l_internal, 
"V32yUsUsV256iUi", "n",
 TARGET_BUILTIN(__builtin_ia32_tcvtrowps2phh_internal, "V32xUsUsV256iUi", "n", 
"amx-avx512,avx10.2-512")
 TARGET_BUILTIN(__builtin_ia32_tcvtrowps2phl_internal, "V32xUsUsV256iUi", "n", 
"amx-avx512,avx10.2-512")
 TARGET_BUILTIN(__builtin_ia32_tilemovrow_internal, "V16iUsUsV256iUi", "n", 
"amx-avx512,avx10.2-512")
+TARGET_BUILTIN(__builtin_ia32_tmmultf32ps_internal, 
"V256iUsUsUsV256iV256iV256i", "n", "amx-tf32")
+TARGET_BUILTIN(__builtin_ia32_ttmmultf32ps_internal, 
"V256iUsUsUsV256iV256iV256i", "n", "amx-tf32,amx-transpose")
+
 // AMX
 TARGET_BUILTIN(__builtin_ia32_tile_loadconfig, "vvC*", "n", "amx-tile")
 TARGET_BUILTIN(__builtin_ia32_tile_storeconfig, "vvC*", "n", "amx-tile")
@@ -172,10 +175,6 @@ TARGET_BUILTIN(__builtin_ia32_tcvtrowps2phh, "V32xIUcUi", 
"n", "amx-avx512,avx10
 TARGET_BUILTIN(__builtin_ia32_tcvtrowps2phl, "V32xIUcUi", "n", 
"amx-avx512,avx10.2-512")
 TARGET_BUILTIN(__builtin_ia32_tilemovrow, "V16iIUcUi", "n", 
"amx-avx512,avx10.2-512")
 
-TARGET_BUILTIN(__builtin_ia32_prefetchi, "vvC*Ui", "nc", "prefetchi")
-TARGET_BUILTIN(__builtin_ia32_cmpccxadd32, "Siv*SiSiIi", "n", "cmpccxadd")
-TARGET_BUILTIN(__builtin_ia32_cmpccxadd64, "SLLiSLLi*SLLiSLLiIi", "n", 
"cmpccxadd")
-
 // AMX_FP16 FP16
 TARGET_BUILTIN(__builtin_ia32_tdpfp16ps, "vIUcIUcIUc", "n", "amx-fp16")
 
@@ -185,6 +184,14 @@ TARGET_BUILTIN(__builtin_ia32_tdpbhf8ps, "vIUcUIcUIc", 
"n", "amx-fp8")
 TARGET_BUILTIN(__builtin_ia32_tdphbf8ps, "vIUcUIcUIc", "n", "amx-fp8")
 TARGET_BUILTIN(__builtin_ia32_tdph

[clang] [llvm] [X86][AMX] Support AMX-MOVRS (PR #115151)

2024-11-09 Thread Phoebe Wang via cfe-commits


@@ -369,3 +369,94 @@ let Predicates = [HasAMXTRANSPOSE, In64BitMode] in {
 }
   }
 } // HasAMXTILE, HasAMXTRANSPOSE
+
+let Predicates = [HasAMXMOVRS, HasAMXTRANSPOSE, In64BitMode], SchedRW = 
[WriteSystem] in {
+  def T2RPNTLVWZ0RS   : I<0xf8, MRMSrcMemFSIB, (outs TILEPair:$dst),
+(ins sibmem:$src1),
+"t2rpntlvwz0rs\t{$src1, $dst|$dst, $src1}",
+[]>, VEX, T_MAP5;
+  def T2RPNTLVWZ0RST1 : I<0xf9, MRMSrcMemFSIB, (outs TILEPair:$dst),
+(ins sibmem:$src1),
+"t2rpntlvwz0rst1\t{$src1, $dst|$dst, $src1}",
+[]>, VEX, T_MAP5;
+  def T2RPNTLVWZ1RS   : I<0xf8, MRMSrcMemFSIB, (outs TILEPair:$dst),
+(ins sibmem:$src1),
+"t2rpntlvwz1rs\t{$src1, $dst|$dst, $src1}",
+[]>, VEX, T_MAP5, PD;
+  def T2RPNTLVWZ1RST1 : I<0xf9, MRMSrcMemFSIB, (outs TILEPair:$dst),
+(ins sibmem:$src1),
+"t2rpntlvwz1rst1\t{$src1, $dst|$dst, $src1}",
+[]>, VEX, T_MAP5, PD;
+  let isPseudo = true in {
+def PT2RPNTLVWZ0RSV   : PseudoI<(outs TILEPair:$dst),
+  (ins GR16:$src1, GR16:$src2, GR16:$src3, 
opaquemem:$src4),
+  []>;
+def PT2RPNTLVWZ0RST1V : PseudoI<(outs TILEPair:$dst),
+  (ins GR16:$src1, GR16:$src2, GR16:$src3, 
opaquemem:$src4),
+  []>;
+def PT2RPNTLVWZ1RSV   : PseudoI<(outs TILEPair:$dst),
+  (ins GR16:$src1, GR16:$src2, GR16:$src3, 
opaquemem:$src4),
+  []>;
+def PT2RPNTLVWZ1RST1V : PseudoI<(outs TILEPair:$dst),
+  (ins GR16:$src1, GR16:$src2, GR16:$src3, 
opaquemem:$src4),
+  []>;
+  }
+  let  usesCustomInserter = 1 in {
+def PT2RPNTLVWZ0RS   : PseudoI<(outs), (ins u8imm:$dst, sibmem:$src1), []>;
+def PT2RPNTLVWZ0RST1 : PseudoI<(outs), (ins u8imm:$dst, sibmem:$src1), []>;
+def PT2RPNTLVWZ1RS   : PseudoI<(outs), (ins u8imm:$dst, sibmem:$src1), []>;
+def PT2RPNTLVWZ1RST1 : PseudoI<(outs), (ins u8imm:$dst, sibmem:$src1), []>;
+  }
+} // HasAMXMOVRS, HasAMXTRANSPOSE
+
+let Predicates = [HasAMXMOVRS, In64BitMode], SchedRW = [WriteSystem] in {
+  def TILELOADDRS : I<0x4a, MRMSrcMemFSIB, (outs TILE:$dst),
+(ins sibmem:$src1),
+"tileloaddrs\t{$src1, $dst|$dst, $src1}",
+[]>, VEX, T8, XD;
+  def TILELOADDRST1 : I<0x4a, MRMSrcMemFSIB, (outs TILE:$dst),
+(ins sibmem:$src1),
+"tileloaddrst1\t{$src1, $dst|$dst, $src1}",
+[]>, VEX, T8, PD;
+
+  let isPseudo = true, mayLoad = 1 in
+  def PTILELOADDRSV : PseudoI<(outs TILE:$dst), (ins GR16:$src1,
+GR16:$src2,
+opaquemem:$src3), []>;
+  let isPseudo = true, mayLoad = 1 in
+  def PTILELOADDRST1V : PseudoI<(outs TILE:$dst), (ins GR16:$src1,
+  GR16:$src2,
+  opaquemem:$src3), []>;
+  let  usesCustomInserter = 1 in {
+let mayLoad = 1 in
+def PTILELOADDRS : PseudoI<(outs), (ins u8imm:$src1, sibmem:$src2), []>;
+let mayLoad = 1 in
+def PTILELOADDRST1 : PseudoI<(outs), (ins u8imm:$src1, sibmem:$src2), []>;
+  }
+
+  def TILELOADDRSrm_EVEX : I<0x4a, MRMSrcMemFSIB, (outs TILE:$dst),
+ (ins sibmem:$src1),
+ "tileloaddrs\t{$src1, $dst|$dst, $src1}",
+ []>, EVEX, NoCD8, T8, XD;
+  def TILELOADDRST1rm_EVEX : I<0x4a, MRMSrcMemFSIB, (outs TILE:$dst),
+   (ins sibmem:$src1),
+   "tileloaddrst1\t{$src1, $dst|$dst, $src1}",
+   []>, EVEX, NoCD8, T8, PD;
+
+  def T2RPNTLVWZ0RS_EVEX : I<0xf8, MRMSrcMemFSIB, (outs TILEPair:$dst),
+ (ins sibmem:$src1),
+ "t2rpntlvwz0rs\t{$src1, $dst|$dst, $src1}",
+ []>, EVEX, NoCD8, T_MAP5;
+  def T2RPNTLVWZ0RST1_EVEX : I<0xf9, MRMSrcMemFSIB, (outs TILEPair:$dst),
+   (ins sibmem:$src1),
+"t2rpntlvwz0rst1\t{$src1, $dst|$dst, $src1}",
+   []>, EVEX, NoCD8, T_MAP5;
+  def T2RPNTLVWZ1RS_EVEX : I<0xf8, MRMSrcMemFSIB, (outs TILEPair:$dst),
+   (ins sibmem:$src1),
+   "t2rpntlvwz1rs\t{$src1, $dst|$dst, $src1}",
+   []>, EVEX, NoCD8, T_MAP5, PD;
+  def T2RPNTLVWZ1RST1_EVEX : I<0xf9, MRMSrcMemFSIB, (outs TILEPair:$dst),
+   (ins sibmem:$src1),
+   "t2rpntlvwz1

[clang] [llvm] [X86][AMX] Support AMX-TF32 (PR #115625)

2024-11-09 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 0ac4821b718dd14e80d3856efa532d52df6878bb 
556c19502b877c2ffa918047517553521bf287af --extensions h,c,cpp -- 
clang/lib/Headers/amxtf32intrin.h clang/lib/Headers/amxtf32transposeintrin.h 
clang/test/CodeGen/X86/amx_tf32.c clang/test/CodeGen/X86/amx_tf32_api.c 
clang/test/CodeGen/X86/amx_tf32_errors.c 
clang/test/CodeGen/X86/amx_tf32_inline_asm.c clang/lib/Basic/Targets/X86.cpp 
clang/lib/Basic/Targets/X86.h clang/lib/Headers/immintrin.h 
clang/lib/Sema/SemaX86.cpp clang/test/Driver/x86-target-features.c 
clang/test/Preprocessor/x86_target_features.c 
llvm/lib/Target/X86/X86ExpandPseudo.cpp llvm/lib/Target/X86/X86ISelLowering.cpp 
llvm/lib/Target/X86/X86LowerAMXType.cpp llvm/lib/Target/X86/X86RegisterInfo.cpp 
llvm/lib/TargetParser/Host.cpp llvm/lib/TargetParser/X86TargetParser.cpp
``





View the diff from clang-format here.


``diff
diff --git a/llvm/lib/Target/X86/X86ISelLowering.cpp 
b/llvm/lib/Target/X86/X86ISelLowering.cpp
index b01a60e31a..8597ccd2a3 100644
--- a/llvm/lib/Target/X86/X86ISelLowering.cpp
+++ b/llvm/lib/Target/X86/X86ISelLowering.cpp
@@ -37489,7 +37489,7 @@ 
X86TargetLowering::EmitInstrWithCustomInserter(MachineInstr &MI,
 case X86::PTDPHF8PS: Opc = X86::TDPHF8PS; break;
 case X86::PTMMULTF32PS: Opc = X86::TMMULTF32PS; break;
 case X86::PTTMMULTF32PS: Opc = X86::TTMMULTF32PS; break;
-// clang-format on
+  // clang-format on
 }
 
 MachineInstrBuilder MIB = BuildMI(*BB, MI, MIMD, TII->get(Opc));

``




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


[clang] [llvm] [X86][AMX] Support AMX-MOVRS (PR #115151)

2024-11-09 Thread Phoebe Wang via cfe-commits


@@ -37605,6 +37653,39 @@ 
X86TargetLowering::EmitInstrWithCustomInserter(MachineInstr &MI,
 MI.eraseFromParent();  // The pseudo is gone now.
 return BB;
   }
+  case X86::PT2RPNTLVWZ0RS:
+  case X86::PT2RPNTLVWZ0RST1:
+  case X86::PT2RPNTLVWZ1RS:
+  case X86::PT2RPNTLVWZ1RST1: {

phoebewang wrote:

ditto.

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


[clang] [llvm] [X86][AMX] Support AMX-MOVRS (PR #115151)

2024-11-09 Thread Phoebe Wang via cfe-commits


@@ -37553,6 +37572,35 @@ 
X86TargetLowering::EmitInstrWithCustomInserter(MachineInstr &MI,
 MI.eraseFromParent(); // The pseudo is gone now.
 return BB;
   }
+  case X86::PTILELOADDRS:
+  case X86::PTILELOADDRST1: {

phoebewang wrote:

Merge with above.

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


[clang] [llvm] [X86][AMX] Support AMX-TF32 (PR #115625)

2024-11-09 Thread Phoebe Wang via cfe-commits


@@ -6101,6 +6101,25 @@ let TargetPrefix = "x86" in {
   Intrinsic<[llvm_v16i32_ty],
 [llvm_i16_ty, llvm_i16_ty, llvm_x86amx_ty, 
llvm_i32_ty],
 []>;
+
+  def int_x86_tmmultf32ps : ClangBuiltin<"__builtin_ia32_tmmultf32ps">,
+  Intrinsic<[], [llvm_i8_ty, llvm_i8_ty, llvm_i8_ty],
+  [ImmArg>, ImmArg>, ImmArg>]>;
+  def int_x86_ttmmultf32ps : ClangBuiltin<"__builtin_ia32_ttmmultf32ps">,
+  Intrinsic<[], [llvm_i8_ty, llvm_i8_ty, llvm_i8_ty],
+  [ImmArg>, ImmArg>, ImmArg>]>;

phoebewang wrote:

Align within `<`

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


[clang] [llvm] [X86][AMX] Support AMX-TF32 (PR #115625)

2024-11-09 Thread Phoebe Wang via cfe-commits


@@ -660,6 +660,10 @@ _storebe_i64(void * __P, long long __D) {
 #include 
 #endif
 
+#if !defined(__SCE__) || __has_feature(modules) || defined(__AMX_TF32__)
+#include 
+#endif
+

phoebewang wrote:

ditto.

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


[clang] [llvm] [X86][AMX] Support AMX-TF32 (PR #115625)

2024-11-09 Thread Phoebe Wang via cfe-commits


@@ -151,6 +151,7 @@ set(x86_files
   amxfp16intrin.h
   amxfp8intrin.h
   amxintrin.h
+  amxtf32intrin.h

phoebewang wrote:

Missing the new file.

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


[clang] [llvm] [X86][AMX] Support AMX-MOVRS (PR #115151)

2024-11-09 Thread Phoebe Wang via cfe-commits


@@ -27291,6 +27291,13 @@ static SDValue LowerINTRINSIC_W_CHAIN(SDValue Op, 
const X86Subtarget &Subtarget,
   return DAG.getNode(ISD::MERGE_VALUES, dl, Op->getVTList(), SetCC,
  Operation.getValue(1));
 }
+case Intrinsic::x86_t2rpntlvwz0rs_internal:
+case Intrinsic::x86_t2rpntlvwz0rst1_internal:
+case Intrinsic::x86_t2rpntlvwz1rs_internal:
+case Intrinsic::x86_t2rpntlvwz1rst1_internal:
+  if (!Subtarget.hasAMXTRANSPOSE() || !Subtarget.hasAMXMOVRS())
+break;
+  [[fallthrough]];

phoebewang wrote:

Remove the check. We don't need check for target intrinsics.

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


[clang] [RISCV][Clang] Add RequiredFeatures to zvfh intrinsics (PR #115436)

2024-11-09 Thread Brandon Wu via cfe-commits

https://github.com/4vtomat approved this pull request.

Somehow I missed [this](https://github.com/llvm/llvm-project/issues/94306) 
issue, thanks for fixing this!

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


[clang] [llvm] [X86][AMX] Support AMX-MOVRS (PR #115151)

2024-11-09 Thread Phoebe Wang via cfe-commits

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


[clang-tools-extra] Fix false positive in bugprone-throw-keyword-missing (PR #115302)

2024-11-09 Thread LLVM Continuous Integration via cfe-commits
Carlos =?utf-8?q?Gálvez?= 
Message-ID:
In-Reply-To: 


llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`sanitizer-aarch64-linux-bootstrap-asan` running on `sanitizer-buildbot7` while 
building `clang-tools-extra` at step 2 "annotate".

Full details are available at: 
https://lab.llvm.org/buildbot/#/builders/24/builds/2580


Here is the relevant piece of the build log for the reference

```
Step 2 (annotate) failure: 'python 
../sanitizer_buildbot/sanitizers/zorg/buildbot/builders/sanitizers/buildbot_selector.py'
 (failure)
...
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using lld-link: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/bin/lld-link
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using ld64.lld: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/bin/ld64.lld
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using wasm-ld: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/bin/wasm-ld
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using ld.lld: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/bin/ld.lld
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using lld-link: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/bin/lld-link
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using ld64.lld: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/bin/ld64.lld
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using wasm-ld: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/bin/wasm-ld
llvm-lit: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/main.py:72:
 note: The test suite configuration requested an individual test timeout of 0 
seconds but a timeout of 900 seconds was requested on the command line. Forcing 
timeout to be 900 seconds.
-- Testing: 83643 of 83644 tests, 48 workers --
Testing:  0.. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 90..
FAIL: lld :: ELF/riscv-attributes.s (82787 of 83643)
 TEST 'lld :: ELF/riscv-attributes.s' FAILED 

Exit Code: 1

Command Output (stderr):
--
RUN: at line 3: rm -rf 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/tools/lld/test/ELF/Output/riscv-attributes.s.tmp
 && split-file 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/lld/test/ELF/riscv-attributes.s
 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/tools/lld/test/ELF/Output/riscv-attributes.s.tmp
 && cd 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/tools/lld/test/ELF/Output/riscv-attributes.s.tmp
+ rm -rf 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/tools/lld/test/ELF/Output/riscv-attributes.s.tmp
+ split-file 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/lld/test/ELF/riscv-attributes.s
 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/tools/lld/test/ELF/Output/riscv-attributes.s.tmp
+ cd 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/tools/lld/test/ELF/Output/riscv-attributes.s.tmp
RUN: at line 4: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/bin/llvm-mc
 -filetype=obj -triple=riscv64 a.s -o a.o
+ 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/bin/llvm-mc
 -filetype=obj -triple=riscv64 a.s -o a.o
RUN: at line 5: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/bin/ld.lld 
-e 0 a.o -o out 2>&1 | 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/bin/count 0
+ 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/bin/ld.lld 
-e 0 a.o -o out
+ 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/bin/count 0
RUN: at line 6: 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/bin/llvm-readelf
 -S -l --arch-specific out | 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/bin/FileCheck
 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/lld/test/ELF/riscv-attributes.s
 --check-prefixes=HDR,CHECK
+ 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/bin/llvm-readelf
 -S -l --arch-specific out
+ 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm_build_asan/bin/FileCheck
 
/home/b/sanitizer-aarch64-linux-bootstrap-asan/build/llvm-project/lld/test/ELF/riscv-attributes.s
 --check-prefixes=HDR,CHECK
RU

[clang] [TableGen] Use heterogenous lookups with std::map (NFC) (PR #115633)

2024-11-09 Thread Kazu Hirata via cfe-commits

https://github.com/kazutakahirata created 
https://github.com/llvm/llvm-project/pull/115633

Heterogenous lookups allow us to call find with StringRef, avoiding a
temporary heap allocation of std::string.


>From 555068b382041e37e00891416fee3cac7982f071 Mon Sep 17 00:00:00 2001
From: Kazu Hirata 
Date: Sat, 9 Nov 2024 14:59:35 -0800
Subject: [PATCH] [TableGen] Use heterogenous lookups with std::map (NFC)

Heterogenous lookups allow us to call find with StringRef, avoiding a
temporary heap allocation of std::string.
---
 clang/utils/TableGen/NeonEmitter.cpp | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/clang/utils/TableGen/NeonEmitter.cpp 
b/clang/utils/TableGen/NeonEmitter.cpp
index c6d82646b40de2..7081e5c9ae93e8 100644
--- a/clang/utils/TableGen/NeonEmitter.cpp
+++ b/clang/utils/TableGen/NeonEmitter.cpp
@@ -578,7 +578,7 @@ class Intrinsic {
 class NeonEmitter {
   const RecordKeeper &Records;
   DenseMap ClassMap;
-  std::map> IntrinsicMap;
+  std::map, std::less<>> IntrinsicMap;
   unsigned UniqueNumber;
 
   void createIntrinsic(const Record *R, SmallVectorImpl &Out);
@@ -1937,9 +1937,9 @@ void Intrinsic::indexBody() {
 Intrinsic &NeonEmitter::getIntrinsic(StringRef Name, ArrayRef Types,
  std::optional MangledName) {
   // First, look up the name in the intrinsic map.
-  assert_with_loc(IntrinsicMap.find(Name.str()) != IntrinsicMap.end(),
+  assert_with_loc(IntrinsicMap.find(Name) != IntrinsicMap.end(),
   ("Intrinsic '" + Name + "' not found!").str());
-  auto &V = IntrinsicMap.find(Name.str())->second;
+  auto &V = IntrinsicMap.find(Name)->second;
   std::vector GoodVec;
 
   // Create a string to print if we end up failing.

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


[clang] [TableGen] Use heterogenous lookups with std::map (NFC) (PR #115633)

2024-11-09 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Kazu Hirata (kazutakahirata)


Changes

Heterogenous lookups allow us to call find with StringRef, avoiding a
temporary heap allocation of std::string.


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


1 Files Affected:

- (modified) clang/utils/TableGen/NeonEmitter.cpp (+3-3) 


``diff
diff --git a/clang/utils/TableGen/NeonEmitter.cpp 
b/clang/utils/TableGen/NeonEmitter.cpp
index c6d82646b40de2..7081e5c9ae93e8 100644
--- a/clang/utils/TableGen/NeonEmitter.cpp
+++ b/clang/utils/TableGen/NeonEmitter.cpp
@@ -578,7 +578,7 @@ class Intrinsic {
 class NeonEmitter {
   const RecordKeeper &Records;
   DenseMap ClassMap;
-  std::map> IntrinsicMap;
+  std::map, std::less<>> IntrinsicMap;
   unsigned UniqueNumber;
 
   void createIntrinsic(const Record *R, SmallVectorImpl &Out);
@@ -1937,9 +1937,9 @@ void Intrinsic::indexBody() {
 Intrinsic &NeonEmitter::getIntrinsic(StringRef Name, ArrayRef Types,
  std::optional MangledName) {
   // First, look up the name in the intrinsic map.
-  assert_with_loc(IntrinsicMap.find(Name.str()) != IntrinsicMap.end(),
+  assert_with_loc(IntrinsicMap.find(Name) != IntrinsicMap.end(),
   ("Intrinsic '" + Name + "' not found!").str());
-  auto &V = IntrinsicMap.find(Name.str())->second;
+  auto &V = IntrinsicMap.find(Name)->second;
   std::vector GoodVec;
 
   // Create a string to print if we end up failing.

``




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


[clang] clang: Relax LangOpts checks when lexing quoted numbers during preprocessing (PR #95798)

2024-11-09 Thread Nishith Kumar M Shah via cfe-commits


@@ -2068,7 +2068,8 @@ bool Lexer::LexNumericConstant(Token &Result, const char 
*CurPtr) {
   }
 
   // If we have a digit separator, continue.
-  if (C == '\'' && (LangOpts.CPlusPlus14 || LangOpts.C23)) {
+  if (C == '\'' &&
+  (LangOpts.CPlusPlus14 || LangOpts.C23 || ParsingPreprocessorDirective)) {

nishithshah2211 wrote:

@AaronBallman @jansvoboda11 @cor3ntin wanted to continue more on this after a 
long gap I took. How can we reach a consensus? Unfortunately, I am pretty new 
to Clang and do not understand the implications of making a choice one way or 
another (which is what this thread is about, so thank you all for nice 
discussion!).

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


[clang] [clang] Introduce [[clang::lifetime_capture_by(X)]] (PR #111499)

2024-11-09 Thread Utkarsh Saxena via cfe-commits

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


[clang] [clang] Introduce [[clang::lifetime_capture_by(X)]] (PR #111499)

2024-11-09 Thread Utkarsh Saxena via cfe-commits

usx95 wrote:

> I did not get to the end of this PR yet, but I was wondering if it would make 
> sense to split it up. One PR could add the attribute with the semantic 
> analysis (e.g., warnings for ill-formed arguments). The second PR could 
> introduce the lifetime analysis part. WDYT?

Makes sense. I will do this now.

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


[compiler-rt] [libcxx] [libcxxabi] [libunwind] [libunwind][libcxx][libcxxabi][compiler-rt-builtins] Fix Exception Handling build for wasm (PR #79667)

2024-11-09 Thread via cfe-commits

https://github.com/trcrsired updated 
https://github.com/llvm/llvm-project/pull/79667

>From 2b526821d4e70f3ea83f95d25f804d9fbcf82612 Mon Sep 17 00:00:00 2001
From: cqwrteur <100043421+trcrsi...@users.noreply.github.com>
Date: Sat, 1 Jun 2024 02:55:50 -0400
Subject: [PATCH] [libunwind][libcxx][libcxxabi] Fix Exception Handling build
 for wasm

The wasm unwind build appears to be dysfunctional, likely because the author 
has only supplied a customized LLVM build on request, rather than a fully 
functional patch.

This patch fixes the build

Apply formatting patch proposed by github bot

use "" to prevent CMAKE_SYSTEM_PROCESSOR not defined

[libunwind] logAPI functions should also be built

[libcxxabi] Fix function signatures for wasm

wasm does not define the function signatures correctly for cxxabi
Fix them

Fix formatting issues for libcxxabi's wasm eh change

Merge remote-tracking branch 'parent/main' into wasmlibunwindfix

remove unwanted changes in unwind-wasm.c

Make Unwind-wasm.c compile correctly without workaround in
CMakeLists.txt

using __wasm__ macro to guard against all wasm eh build

fix UnwindLevel.c's formatting issue

ISO C requires a translation unit to contain at least one declaration 
[-Werror,-Wempty-translation-unit]

compiler-rt does not define CMP_RESULT correct on wasm64
Fixed

Merge code
---
 compiler-rt/lib/builtins/fp_compare_impl.inc |   2 +-
 libcxx/include/__exception/exception_ptr.h   |  21 +-
 libcxxabi/include/cxxabi.h   | 134 ++--
 libcxxabi/src/cxa_exception.cpp  | 710 ---
 libcxxabi/src/cxa_exception.h|   7 +-
 libunwind/include/libunwind.h|   2 +
 libunwind/src/Unwind-wasm.c  |  13 +-
 libunwind/src/UnwindRegistersRestore.S   |   3 +-
 libunwind/src/UnwindRegistersSave.S  |   3 +
 libunwind/src/assembly.h |   2 +
 libunwind/src/cet_unwind.h   |   3 +
 libunwind/src/config.h   |  15 +-
 libunwind/src/libunwind.cpp  |   2 +
 libunwind/src/libunwind_ext.h|   2 +
 14 files changed, 403 insertions(+), 516 deletions(-)

diff --git a/compiler-rt/lib/builtins/fp_compare_impl.inc 
b/compiler-rt/lib/builtins/fp_compare_impl.inc
index a9a4f6fbf5dfe4..83bdea46a45da4 100644
--- a/compiler-rt/lib/builtins/fp_compare_impl.inc
+++ b/compiler-rt/lib/builtins/fp_compare_impl.inc
@@ -12,7 +12,7 @@
 // functions. We need to ensure that the return value is sign-extended in the
 // same way as GCC expects (since otherwise GCC-generated __builtin_isinf
 // returns true for finite 128-bit floating-point numbers).
-#ifdef __aarch64__
+#if defined(__aarch64__) || defined(__wasm__)
 // AArch64 GCC overrides libgcc_cmp_return to use int instead of long.
 typedef int CMP_RESULT;
 #elif __SIZEOF_POINTER__ == 8 && __SIZEOF_LONG__ == 4
diff --git a/libcxx/include/__exception/exception_ptr.h 
b/libcxx/include/__exception/exception_ptr.h
index 9e5351f534a1c1..84a78d378cc19f 100644
--- a/libcxx/include/__exception/exception_ptr.h
+++ b/libcxx/include/__exception/exception_ptr.h
@@ -29,22 +29,21 @@
 
 namespace __cxxabiv1 {
 
+#if defined(__wasm__)
+typedef void* (*__libcpp_exception_destructor_func)(void*);
+#elif defined(_WIN32)
+typedef void(__thiscall* __libcpp_exception_destructor_func)(void*);
+#else
+typedef void (*__libcpp_exception_destructor_func)(void*);
+#endif
+
 extern "C" {
 _LIBCPP_OVERRIDABLE_FUNC_VIS void* __cxa_allocate_exception(size_t) throw();
 _LIBCPP_OVERRIDABLE_FUNC_VIS void __cxa_free_exception(void*) throw();
 
 struct __cxa_exception;
-_LIBCPP_OVERRIDABLE_FUNC_VIS __cxa_exception* __cxa_init_primary_exception(
-void*,
-std::type_info*,
-#if defined(_WIN32)
-void(__thiscall*)(void*)) throw();
-#elif defined(__wasm__)
-// In Wasm, a destructor returns its argument
-void* (*)(void*)) throw();
-#else
-void (*)(void*)) throw();
-#endif
+_LIBCPP_OVERRIDABLE_FUNC_VIS __cxa_exception*
+__cxa_init_primary_exception(void*, std::type_info*, 
__libcpp_exception_destructor_func) throw();
 }
 
 } // namespace __cxxabiv1
diff --git a/libcxxabi/include/cxxabi.h b/libcxxabi/include/cxxabi.h
index 9ea93680f62e06..cf0cc40ff42b9e 100644
--- a/libcxxabi/include/cxxabi.h
+++ b/libcxxabi/include/cxxabi.h
@@ -20,49 +20,41 @@
 #include <__cxxabi_config.h>
 
 #define _LIBCPPABI_VERSION 15000
-#define _LIBCXXABI_NORETURN  __attribute__((noreturn))
+#define _LIBCXXABI_NORETURN __attribute__((noreturn))
 #define _LIBCXXABI_ALWAYS_COLD __attribute__((cold))
 
 #ifdef __cplusplus
 
 namespace std {
-#if defined(_WIN32)
+#  if defined(_WIN32)
 class _LIBCXXABI_TYPE_VIS type_info; // forward declaration
-#else
+#  else
 class type_info; // forward declaration
-#endif
-}
-
+#  endif
+} // namespace std
 
 // runtime routines use C calling conventions, but are in __cxxabiv1 namespace
 namespace __cxxabiv1 {
 
 struct __cxa_exception;
+#  if defined(__wasm__)
+typedef 

[clang-tools-extra] Add bugprone-undefined-sprintf-overlap (PR #114244)

2024-11-09 Thread Julian Schmidt via cfe-commits


@@ -0,0 +1,82 @@
+//===--- UndefinedSprintfOverlapCheck.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 "UndefinedSprintfOverlapCheck.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+AST_MATCHER_P(IntegerLiteral, hasSameValueAs, std::string, ID) {
+  return Builder->removeBindings(
+  [this, &Node](const ast_matchers::internal::BoundNodesMap &Nodes) {
+const DynTypedNode &BN = Nodes.getNode(ID);
+if (const auto *Lit = BN.get()) {
+  return Lit->getValue() != Node.getValue();
+}
+return true;
+  });
+}
+
+UndefinedSprintfOverlapCheck::UndefinedSprintfOverlapCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  SprintfRegex(Options.get("SprintfFunction", "(::std)?::(sn?printf)")) {}
+
+void UndefinedSprintfOverlapCheck::registerMatchers(MatchFinder *Finder) {
+  auto FirstArg = declRefExpr(to(varDecl().bind("firstArgDecl")));
+  auto OtherRefToArg = 
declRefExpr(to(varDecl(equalsBoundNode("firstArgDecl"
+   .bind("overlappingArg");
+  Finder->addMatcher(
+  callExpr(
+  callee(functionDecl(matchesName(SprintfRegex)).bind("decl")),
+  allOf(hasArgument(
+0, expr(anyOf(FirstArg,
+  arraySubscriptExpr(
+  hasBase(FirstArg),
+  
hasIndex(integerLiteral().bind("index"))),
+  memberExpr(member(decl().bind("member")),
+ hasObjectExpression(FirstArg
+   .bind("firstArgExpr")),

5chmidti wrote:

Together with `Expr::hasSideEffects`, this could work and detect more cases.

Not overlapping due to side-effect (this isn't good of course: 
`clang-diagnostic-unsequenced`)
```c++
void foo(char**buf) {
  int i = 0;
  sprintf(buf[++i], "%s", buf[++i]);
}
```

One issue is, that `Expr::hasSideEffects` is relatively simple, and would 
ignore things like `std::vector::operator[]`, because it is not marked with 
the `const` or `pure` attributes.

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


[clang] [llvm] [Clang-Repl] Add support for out-of-process execution. (PR #110418)

2024-11-09 Thread via cfe-commits

https://github.com/SahilPatidar updated 
https://github.com/llvm/llvm-project/pull/110418

>From 519dd2c99bc2200d364a184e416ec03b609e1910 Mon Sep 17 00:00:00 2001
From: SahilPatidar 
Date: Fri, 7 Jun 2024 13:30:08 +0530
Subject: [PATCH 01/13] [Clang-Repl] Implement out-of-process execution
 interface for clang-repl

---
 clang/include/clang/Interpreter/Interpreter.h |   9 +-
 clang/lib/Interpreter/Interpreter.cpp |  33 ++-
 clang/tools/clang-repl/CMakeLists.txt |   2 +
 clang/tools/clang-repl/ClangRepl.cpp  |  75 ++-
 clang/tools/clang-repl/RemoteJITUtils.cpp | 208 ++
 clang/tools/clang-repl/RemoteJITUtils.h   |  42 
 llvm/lib/ExecutionEngine/Orc/LLJIT.cpp|   3 +
 7 files changed, 364 insertions(+), 8 deletions(-)
 create mode 100644 clang/tools/clang-repl/RemoteJITUtils.cpp
 create mode 100644 clang/tools/clang-repl/RemoteJITUtils.h

diff --git a/clang/include/clang/Interpreter/Interpreter.h 
b/clang/include/clang/Interpreter/Interpreter.h
index 1230a3a7016fae..147794c5870335 100644
--- a/clang/include/clang/Interpreter/Interpreter.h
+++ b/clang/include/clang/Interpreter/Interpreter.h
@@ -21,6 +21,7 @@
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ExecutionEngine/JITSymbol.h"
 #include "llvm/ExecutionEngine/Orc/Shared/ExecutorAddress.h"
+#include "llvm/ExecutionEngine/Orc/ExecutorProcessControl.h"
 #include "llvm/Support/Error.h"
 #include 
 #include 
@@ -129,7 +130,13 @@ class Interpreter {
 public:
   virtual ~Interpreter();
   static llvm::Expected>
-  create(std::unique_ptr CI);
+  create(std::unique_ptr CI,
+ std::unique_ptr JITBuilder = nullptr);
+  static llvm::Expected>
+  createWithOOPExecutor(
+  std::unique_ptr CI,
+  std::unique_ptr EI,
+  llvm::StringRef OrcRuntimePath);
   static llvm::Expected>
   createWithCUDA(std::unique_ptr CI,
  std::unique_ptr DCI);
diff --git a/clang/lib/Interpreter/Interpreter.cpp 
b/clang/lib/Interpreter/Interpreter.cpp
index bc96da811d44cb..21507906618c39 100644
--- a/clang/lib/Interpreter/Interpreter.cpp
+++ b/clang/lib/Interpreter/Interpreter.cpp
@@ -45,6 +45,7 @@
 #include "clang/Serialization/ObjectFilePCHContainerReader.h"
 #include "llvm/ExecutionEngine/JITSymbol.h"
 #include "llvm/ExecutionEngine/Orc/LLJIT.h"
+#include "llvm/ExecutionEngine/Orc/EPCDynamicLibrarySearchGenerator.h"
 #include "llvm/IR/Module.h"
 #include "llvm/Support/Errc.h"
 #include "llvm/Support/ErrorHandling.h"
@@ -456,10 +457,12 @@ const char *const Runtimes = R"(
 )";
 
 llvm::Expected>
-Interpreter::create(std::unique_ptr CI) {
+Interpreter::create(std::unique_ptr CI,
+std::unique_ptr JB) {
   llvm::Error Err = llvm::Error::success();
   auto Interp =
-  std::unique_ptr(new Interpreter(std::move(CI), Err));
+  std::unique_ptr(new Interpreter(std::move(CI), Err,
+   JB? std::move(JB): 
nullptr));
   if (Err)
 return std::move(Err);
 
@@ -578,6 +581,26 @@ createJITTargetMachineBuilder(const std::string &TT) {
   return llvm::orc::JITTargetMachineBuilder(llvm::Triple(TT));
 }
 
+llvm::Expected>
+Interpreter::createWithOOPExecutor(
+std::unique_ptr CI,
+std::unique_ptr EPC,
+llvm::StringRef OrcRuntimePath) {
+  const std::string &TT = CI->getTargetOpts().Triple;
+  auto JTMB = createJITTargetMachineBuilder(TT);
+  if (!JTMB)
+return JTMB.takeError();
+  auto JB = IncrementalExecutor::createDefaultJITBuilder(std::move(*JTMB));
+  if (!JB)
+return JB.takeError();
+  if (EPC) {
+JB.get()->setExecutorProcessControl(std::move(EPC));
+
JB.get()->setPlatformSetUp(llvm::orc::ExecutorNativePlatform(OrcRuntimePath.str()));
+  }
+
+  return Interpreter::create(std::move(CI), std::move(*JB));
+}
+
 llvm::Error Interpreter::CreateExecutor() {
   if (IncrExecutor)
 return llvm::make_error("Operation failed. "
@@ -702,10 +725,10 @@ llvm::Error Interpreter::LoadDynamicLibrary(const char 
*name) {
   if (!EE)
 return EE.takeError();
 
-  auto &DL = EE->getDataLayout();
+  // auto &DL = EE->getDataLayout();
 
-  if (auto DLSG = llvm::orc::DynamicLibrarySearchGenerator::Load(
-  name, DL.getGlobalPrefix()))
+  if (auto DLSG = llvm::orc::EPCDynamicLibrarySearchGenerator::Load(
+  EE->getExecutionSession(), name))
 EE->getMainJITDylib().addGenerator(std::move(*DLSG));
   else
 return DLSG.takeError();
diff --git a/clang/tools/clang-repl/CMakeLists.txt 
b/clang/tools/clang-repl/CMakeLists.txt
index 7aebbe7a19436a..11164e3b8f5c65 100644
--- a/clang/tools/clang-repl/CMakeLists.txt
+++ b/clang/tools/clang-repl/CMakeLists.txt
@@ -4,7 +4,9 @@ set( LLVM_LINK_COMPONENTS
   LineEditor
   Option
   OrcJIT
+  OrcShared
   Support
+  TargetParser
   )
 
 add_clang_tool(clang-repl
diff --git a/clang/tools/clang-repl/ClangRepl.cpp 
b/clang/tools/clang-repl/ClangRepl.cpp
index 08c54e6cafa901..21359df01c270f 100644
--- a/clang/tools/clang-repl/ClangRepl.cpp
+++ b/clang/tools/clang-repl/C

[clang-tools-extra] [clang-tidy] fix bugprone-sizeof-expression when sizeof expression with template types (PR #115275)

2024-11-09 Thread Julian Schmidt via cfe-commits

https://github.com/5chmidti approved this pull request.


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


[clang-tools-extra] Add bugprone-undefined-sprintf-overlap (PR #114244)

2024-11-09 Thread Nicolas van Kempen via cfe-commits


@@ -0,0 +1,23 @@
+.. title:: clang-tidy - bugprone-undefined-sprintf-overlap
+
+bugprone-undefined-sprintf-overlap
+==
+
+Warns if any arguments to the ``sprintf`` family of functions overlap with the
+first argument.
+
+.. code-block:: c++
+
+char buf[20] = {"hi"};
+sprintf(buf, "%s%d", buf, 0);
+
+C99 and POSIX.1-2001 states that if copying were to take place between objects
+that overlap, the result is undefined.

nicovank wrote:

```suggestion
If copying takes place between objects that overlap, the behavior is undefined.
This is stated in the `C23/N3220 standard
`_
(sections 7.23.6.5 and 7.23.6.6), as well as the `POSIX.1-2024 standard
`_.
```

Maybe this should also say something about what can happen in practice 
(unexpected results? segmentation faults?).

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


[clang-tools-extra] Add bugprone-undefined-sprintf-overlap (PR #114244)

2024-11-09 Thread Nicolas van Kempen via cfe-commits


@@ -0,0 +1,23 @@
+.. title:: clang-tidy - bugprone-undefined-sprintf-overlap
+
+bugprone-undefined-sprintf-overlap

nicovank wrote:

Just to throw another option out there, `bugprone-sprintf-argument-overlap`. 
Others might have opinions.

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


[clang-tools-extra] Add bugprone-undefined-sprintf-overlap (PR #114244)

2024-11-09 Thread Nicolas van Kempen via cfe-commits


@@ -153,6 +153,7 @@ Clang-Tidy Checks
:doc:`bugprone-too-small-loop-variable `,
:doc:`bugprone-unchecked-optional-access 
`,
:doc:`bugprone-undefined-memory-manipulation 
`,
+   :doc:`bugprone-undefined-sprintf-overlap 
`, "Yes"

nicovank wrote:

```suggestion
   :doc:`bugprone-undefined-sprintf-overlap 
`,
```

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


[clang-tools-extra] Add bugprone-undefined-sprintf-overlap (PR #114244)

2024-11-09 Thread Nicolas van Kempen via cfe-commits

nicovank wrote:

Oops, crossed signals with @5chmidti. Hopefully not too much overlap sorry.

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


[clang-tools-extra] Add bugprone-undefined-sprintf-overlap (PR #114244)

2024-11-09 Thread Nicolas van Kempen via cfe-commits


@@ -0,0 +1,36 @@
+//===--- UndefinedSprintfOverlapCheck.h - clang-tidy *- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef 
LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_UNDEFINEDSPRINTFOVERLAPCHECK_H
+#define 
LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_UNDEFINEDSPRINTFOVERLAPCHECK_H
+
+#include "../ClangTidyCheck.h"
+
+namespace clang::tidy::bugprone {
+
+/// FIXME: Write a short description.

nicovank wrote:

Sync with documentation.

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


[clang-tools-extra] Add bugprone-undefined-sprintf-overlap (PR #114244)

2024-11-09 Thread Nicolas van Kempen via cfe-commits

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


[clang-tools-extra] Add bugprone-undefined-sprintf-overlap (PR #114244)

2024-11-09 Thread Julian Schmidt via cfe-commits


@@ -0,0 +1,82 @@
+//===--- UndefinedSprintfOverlapCheck.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 "UndefinedSprintfOverlapCheck.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+AST_MATCHER_P(IntegerLiteral, hasSameValueAs, std::string, ID) {
+  return Builder->removeBindings(
+  [this, &Node](const ast_matchers::internal::BoundNodesMap &Nodes) {
+const DynTypedNode &BN = Nodes.getNode(ID);
+if (const auto *Lit = BN.get()) {
+  return Lit->getValue() != Node.getValue();
+}
+return true;
+  });
+}
+
+UndefinedSprintfOverlapCheck::UndefinedSprintfOverlapCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  SprintfRegex(Options.get("SprintfFunction", "(::std)?::(sn?printf)")) {}
+
+void UndefinedSprintfOverlapCheck::registerMatchers(MatchFinder *Finder) {
+  auto FirstArg = declRefExpr(to(varDecl().bind("firstArgDecl")));
+  auto OtherRefToArg = 
declRefExpr(to(varDecl(equalsBoundNode("firstArgDecl"
+   .bind("overlappingArg");
+  Finder->addMatcher(

5chmidti wrote:

People may also use `*(ptr + 10)` instead of `ptr[10]`. Please add support for 
this, and keeping `index` as a common bound-node name between the two would 
also mean that mixing them is supported: `sprintf(bufs[1], "%s", *(bufs + 1));`

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


[clang] [llvm] [X86][AMX] Support AMX-TF32 (PR #115625)

2024-11-09 Thread Phoebe Wang via cfe-commits


@@ -37686,6 +37686,28 @@ 
X86TargetLowering::EmitInstrWithCustomInserter(MachineInstr &MI,
 MI.eraseFromParent(); // The pseudo is gone now.
 return BB;
   }
+  case X86::PTMMULTF32PS:
+  case X86::PTTMMULTF32PS: {
+const DebugLoc &DL = MI.getDebugLoc();
+unsigned Opc;
+switch (MI.getOpcode()) {
+default:
+  llvm_unreachable("Unexpected instruction!");
+case X86::PTMMULTF32PS:
+  Opc = X86::TMMULTF32PS;
+  break;
+case X86::PTTMMULTF32PS:
+  Opc = X86::TTMMULTF32PS;
+  break;
+}
+MachineInstrBuilder MIB = BuildMI(*BB, MI, DL, TII->get(Opc));
+MIB.addReg(TMMImmToTMMReg(MI.getOperand(0).getImm()), RegState::Define);
+MIB.addReg(TMMImmToTMMReg(MI.getOperand(0).getImm()), RegState::Undef);
+MIB.addReg(TMMImmToTMMReg(MI.getOperand(1).getImm()), RegState::Undef);
+MIB.addReg(TMMImmToTMMReg(MI.getOperand(2).getImm()), RegState::Undef);
+MI.eraseFromParent();
+return BB;
+  }

phoebewang wrote:

Merge to line 37473

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


[clang] [llvm] [X86][AMX] Support AMX-TF32 (PR #115625)

2024-11-09 Thread Phoebe Wang via cfe-commits


@@ -0,0 +1,47 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc < %s -mtriple=x86_64-unknown-unknown -mattr=+amx-tile,+avx512f, \
+; RUN: -mattr=+amx-tf32,+amx-transpose -verify-machineinstrs | FileCheck %s
+
+define void @test_amx(i8* %pointer, i8* %base, i64 %stride) {
+; CHECK-LABEL: test_amx:
+; CHECK:   # %bb.0:
+; CHECK-NEXT:vxorps %xmm0, %xmm0, %xmm0
+; CHECK-NEXT:vmovups %zmm0, -{{[0-9]+}}(%rsp)
+; CHECK-NEXT:movb $1, -{{[0-9]+}}(%rsp)
+; CHECK-NEXT:movb $8, -{{[0-9]+}}(%rsp)
+; CHECK-NEXT:movw $8, -{{[0-9]+}}(%rsp)
+; CHECK-NEXT:movb $8, -{{[0-9]+}}(%rsp)
+; CHECK-NEXT:movw $8, -{{[0-9]+}}(%rsp)
+; CHECK-NEXT:movb $8, -{{[0-9]+}}(%rsp)
+; CHECK-NEXT:movw $8, -{{[0-9]+}}(%rsp)
+; CHECK-NEXT:ldtilecfg -{{[0-9]+}}(%rsp)
+; CHECK-NEXT:movw $8, %ax
+; CHECK-NEXT:tileloadd (%rsi,%rdx), %tmm0
+; CHECK-NEXT:tilezero %tmm1
+; CHECK-NEXT:tilezero %tmm2
+; CHECK-NEXT:tmmultf32ps %tmm1, %tmm0, %tmm2
+; CHECK-NEXT:ttmmultf32ps %tmm1, %tmm0, %tmm2
+; CHECK-NEXT:tilestored %tmm2, (%rdi,%rdx)
+; CHECK-NEXT:tilerelease
+; CHECK-NEXT:vzeroupper
+; CHECK-NEXT:retq
+
+  %a = call x86_amx @llvm.x86.tileloadd64.internal(i16 8, i16 8, i8* %base, 
i64 %stride)
+  %b = call x86_amx @llvm.x86.tilezero.internal(i16 8, i16 8)
+  %c = call x86_amx @llvm.x86.tilezero.internal(i16 8, i16 8)
+
+  %c1 = call x86_amx @llvm.x86.tmmultf32ps.internal(i16 8, i16 8, i16 8, 
x86_amx %c, x86_amx %a, x86_amx %b)
+  %c2 = call x86_amx @llvm.x86.ttmmultf32ps.internal(i16 8, i16 8, i16 8, 
x86_amx %c1, x86_amx %a, x86_amx %b)
+
+  call void @llvm.x86.tilestored64.internal(i16 8, i16 8, i8* %pointer, i64 
%stride, x86_amx %c2)
+  ret void
+}
+
+declare x86_amx @llvm.x86.tilezero.internal(i16, i16)
+declare x86_amx @llvm.x86.tileloadd64.internal(i16, i16, i8*, i64)
+declare x86_amx @llvm.x86.tileloaddt164.internal(i16, i16, i8*, i64)

phoebewang wrote:

Not used.

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


[clang-tools-extra] Fix false positive in bugprone-throw-keyword-missing (PR #115302)

2024-11-09 Thread LLVM Continuous Integration via cfe-commits
Carlos =?utf-8?q?Gálvez?= 
Message-ID:
In-Reply-To: 


llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`sanitizer-x86_64-linux-bootstrap-asan` running on `sanitizer-buildbot1` while 
building `clang-tools-extra` at step 2 "annotate".

Full details are available at: 
https://lab.llvm.org/buildbot/#/builders/52/builds/3602


Here is the relevant piece of the build log for the reference

```
Step 2 (annotate) failure: 'python 
../sanitizer_buildbot/sanitizers/zorg/buildbot/builders/sanitizers/buildbot_selector.py'
 (failure)
...
llvm-lit: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using lld-link: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/lld-link
llvm-lit: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using ld64.lld: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/ld64.lld
llvm-lit: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using wasm-ld: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/wasm-ld
llvm-lit: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using ld.lld: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/ld.lld
llvm-lit: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using lld-link: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/lld-link
llvm-lit: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using ld64.lld: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/ld64.lld
llvm-lit: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/llvm/config.py:506:
 note: using wasm-ld: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/wasm-ld
llvm-lit: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/llvm/utils/lit/lit/main.py:72:
 note: The test suite configuration requested an individual test timeout of 0 
seconds but a timeout of 900 seconds was requested on the command line. Forcing 
timeout to be 900 seconds.
-- Testing: 87034 of 87035 tests, 88 workers --
Testing:  0.. 10.. 20.. 30.. 40.. 50.. 60.. 70.. 80.. 90..
FAIL: lld :: MachO/why-live.s (86731 of 87034)
 TEST 'lld :: MachO/why-live.s' FAILED 
Exit Code: 1

Command Output (stderr):
--
RUN: at line 3: 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/llvm-mc 
-filetype=obj -triple=x86_64-apple-macos 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/lld/test/MachO/why-live.s
 -o 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/tools/lld/test/MachO/Output/why-live.s.tmp.o
+ 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/llvm-mc 
-filetype=obj -triple=x86_64-apple-macos 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/lld/test/MachO/why-live.s
 -o 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/tools/lld/test/MachO/Output/why-live.s.tmp.o
RUN: at line 4: ld64.lld -arch x86_64 -platform_version macos 11.0 11.0 
-syslibroot 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/lld/test/MachO/Inputs/MacOSX.sdk
 -lSystem -fatal_warnings -lSystem -dead_strip -why_live _foo -why_live _undef 
-U _undef-why_live _support -why_live _support_refs_dylib_fun-why_live 
_abs 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/tools/lld/test/MachO/Output/why-live.s.tmp.o
 -o /dev/null 2>&1 | 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/FileCheck
 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/lld/test/MachO/why-live.s
+ ld64.lld -arch x86_64 -platform_version macos 11.0 11.0 -syslibroot 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/lld/test/MachO/Inputs/MacOSX.sdk
 -lSystem -fatal_warnings -lSystem -dead_strip -why_live _foo -why_live _undef 
-U _undef -why_live _support -why_live _support_refs_dylib_fun -why_live _abs 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/tools/lld/test/MachO/Output/why-live.s.tmp.o
 -o /dev/null
+ 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/bin/FileCheck
 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/lld/test/MachO/why-live.s
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm-project/lld/test/MachO/why-live.s:25:15:
 error: CHECK-EMPTY: is not on the line after the previous match
# CHECK-EMPTY:
  ^
:11:1: note: 'next' match was here

^
:9:124: note: previous match ended here
 _foo from 
/home/b/sanitizer-x86_64-linux-bootstrap-asan/build/llvm_build_asan/tools/lld/test/

[clang-tools-extra] [clang-tidy] fix bugprone-sizeof-expression when sizeof expression with template types (PR #115275)

2024-11-09 Thread Julian Schmidt via cfe-commits


@@ -175,7 +175,8 @@ Changes in existing checks
 - Improved :doc:`bugprone-sizeof-expression
   ` check to find suspicious
   usages of ``sizeof()``, ``alignof()``, and ``offsetof()`` when adding or
-  subtracting from a pointer directly or when used to scale a numeric value.
+  subtracting from a pointer directly or when used to scale a numeric value and
+  fix false positive when sizeof expression with template types.

5chmidti wrote:

> If there were no releases since this change, then there is no need for the 
> release note entry. Basically you're hotfixing a change that is coming out in 
> the same hypothetical next release.

I'm not sure what you meant here. There should be a release note, unless the 
issue was introduced in the current, release cycle. The diagnostic reproduces 
in clang-tidy 18 for me, or did you mean something different (e.g., general 
*in-case-of* comment)?

> clang-tidy release-note always combines the all changes of rule in one item 
> instead of spilt them.

+1, that's the current approach

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


[clang-tools-extra] Add bugprone-undefined-sprintf-overlap (PR #114244)

2024-11-09 Thread Julian Schmidt via cfe-commits


@@ -0,0 +1,82 @@
+//===--- UndefinedSprintfOverlapCheck.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 "UndefinedSprintfOverlapCheck.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+AST_MATCHER_P(IntegerLiteral, hasSameValueAs, std::string, ID) {
+  return Builder->removeBindings(
+  [this, &Node](const ast_matchers::internal::BoundNodesMap &Nodes) {
+const DynTypedNode &BN = Nodes.getNode(ID);
+if (const auto *Lit = BN.get()) {
+  return Lit->getValue() != Node.getValue();
+}

5chmidti wrote:

nit: single stmt if -> no braces

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


[clang-tools-extra] Add bugprone-undefined-sprintf-overlap (PR #114244)

2024-11-09 Thread Julian Schmidt via cfe-commits

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


[clang-tools-extra] Add bugprone-undefined-sprintf-overlap (PR #114244)

2024-11-09 Thread Julian Schmidt via cfe-commits


@@ -0,0 +1,36 @@
+//===--- UndefinedSprintfOverlapCheck.h - clang-tidy *- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef 
LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_UNDEFINEDSPRINTFOVERLAPCHECK_H
+#define 
LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_UNDEFINEDSPRINTFOVERLAPCHECK_H
+
+#include "../ClangTidyCheck.h"
+
+namespace clang::tidy::bugprone {
+
+/// FIXME: Write a short description.

5chmidti wrote:

Please update this with the sentence from the docs/release notes

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


[clang-tools-extra] Add bugprone-undefined-sprintf-overlap (PR #114244)

2024-11-09 Thread Julian Schmidt via cfe-commits


@@ -0,0 +1,82 @@
+//===--- UndefinedSprintfOverlapCheck.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 "UndefinedSprintfOverlapCheck.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+AST_MATCHER_P(IntegerLiteral, hasSameValueAs, std::string, ID) {
+  return Builder->removeBindings(
+  [this, &Node](const ast_matchers::internal::BoundNodesMap &Nodes) {
+const DynTypedNode &BN = Nodes.getNode(ID);
+if (const auto *Lit = BN.get()) {
+  return Lit->getValue() != Node.getValue();
+}
+return true;
+  });
+}
+
+UndefinedSprintfOverlapCheck::UndefinedSprintfOverlapCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  SprintfRegex(Options.get("SprintfFunction", "(::std)?::(sn?printf)")) {}

5chmidti wrote:

The second pair of parentheses are not needed

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


[clang-tools-extra] Add bugprone-undefined-sprintf-overlap (PR #114244)

2024-11-09 Thread Julian Schmidt via cfe-commits


@@ -0,0 +1,23 @@
+.. title:: clang-tidy - bugprone-undefined-sprintf-overlap
+
+bugprone-undefined-sprintf-overlap
+==
+
+Warns if any arguments to the ``sprintf`` family of functions overlap with the
+first argument.

5chmidti wrote:

The first argument is always the buffer that is written to, calling it that 
here would make the issue a bit clearer.

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


[clang-tools-extra] Add bugprone-undefined-sprintf-overlap (PR #114244)

2024-11-09 Thread Julian Schmidt via cfe-commits

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

There are some false-negatives that exist for this check:

E.g.,

```c++
  // from tests
  char bufss[10][10][10];
  sprintf(bufss[0][1], "%s", bufss[0][1]);
```

or `*( *(bufss + 0) + 1)`. Though these can border on requiring, e.g., symbolic 
execution due to the potential complexity, and there is IMO no need to support 
expressions that are arbitrarily complex, but two levels of pointer 
indirections sounds like a solid basis to me. (the note on complexity also 
applies to the other points)

Also, `obj.bufs[1]`.

The check is also only considering subscript operators that are using integer 
literals as offsets, and not expressions that evaluate to a constant at compile 
time (`1+1`), or plain variables. If the expression inside `[]` has no side 
effects, they will be the same and the access is overlapping: `sprintf(bufs[n], 
"%s". bufs[n])`.

WDYT? It would be nice to have some of those cases detectable

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


[clang-tools-extra] Add bugprone-undefined-sprintf-overlap (PR #114244)

2024-11-09 Thread Julian Schmidt via cfe-commits


@@ -0,0 +1,82 @@
+//===--- UndefinedSprintfOverlapCheck.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 "UndefinedSprintfOverlapCheck.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+AST_MATCHER_P(IntegerLiteral, hasSameValueAs, std::string, ID) {
+  return Builder->removeBindings(
+  [this, &Node](const ast_matchers::internal::BoundNodesMap &Nodes) {
+const DynTypedNode &BN = Nodes.getNode(ID);
+if (const auto *Lit = BN.get()) {
+  return Lit->getValue() != Node.getValue();
+}
+return true;
+  });
+}
+
+UndefinedSprintfOverlapCheck::UndefinedSprintfOverlapCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  SprintfRegex(Options.get("SprintfFunction", "(::std)?::(sn?printf)")) {}
+
+void UndefinedSprintfOverlapCheck::registerMatchers(MatchFinder *Finder) {
+  auto FirstArg = declRefExpr(to(varDecl().bind("firstArgDecl")));
+  auto OtherRefToArg = 
declRefExpr(to(varDecl(equalsBoundNode("firstArgDecl"
+   .bind("overlappingArg");
+  Finder->addMatcher(
+  callExpr(
+  callee(functionDecl(matchesName(SprintfRegex)).bind("decl")),
+  allOf(hasArgument(

5chmidti wrote:

This `allOf` is not needed because `callExpr` is an all-of variadic matcher

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


[clang-tools-extra] Add bugprone-undefined-sprintf-overlap (PR #114244)

2024-11-09 Thread Julian Schmidt via cfe-commits


@@ -0,0 +1,82 @@
+//===--- UndefinedSprintfOverlapCheck.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 "UndefinedSprintfOverlapCheck.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+AST_MATCHER_P(IntegerLiteral, hasSameValueAs, std::string, ID) {
+  return Builder->removeBindings(
+  [this, &Node](const ast_matchers::internal::BoundNodesMap &Nodes) {
+const DynTypedNode &BN = Nodes.getNode(ID);
+if (const auto *Lit = BN.get()) {
+  return Lit->getValue() != Node.getValue();
+}
+return true;
+  });
+}
+
+UndefinedSprintfOverlapCheck::UndefinedSprintfOverlapCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  SprintfRegex(Options.get("SprintfFunction", "(::std)?::(sn?printf)")) {}
+
+void UndefinedSprintfOverlapCheck::registerMatchers(MatchFinder *Finder) {
+  auto FirstArg = declRefExpr(to(varDecl().bind("firstArgDecl")));
+  auto OtherRefToArg = 
declRefExpr(to(varDecl(equalsBoundNode("firstArgDecl"
+   .bind("overlappingArg");
+  Finder->addMatcher(
+  callExpr(
+  callee(functionDecl(matchesName(SprintfRegex)).bind("decl")),
+  allOf(hasArgument(
+0, expr(anyOf(FirstArg,
+  arraySubscriptExpr(
+  hasBase(FirstArg),
+  
hasIndex(integerLiteral().bind("index"))),
+  memberExpr(member(decl().bind("member")),
+ hasObjectExpression(FirstArg
+   .bind("firstArgExpr")),
+hasAnyArgument(expr(
+unless(equalsBoundNode("firstArgExpr")),
+anyOf(OtherRefToArg,
+  arraySubscriptExpr(hasBase(OtherRefToArg),
+ hasIndex(integerLiteral(
+ hasSameValueAs("index",
+  memberExpr(member(decl(equalsBoundNode("member"))),
+ hasObjectExpression(OtherRefToArg))),
+  this);
+}
+
+void UndefinedSprintfOverlapCheck::check(
+const MatchFinder::MatchResult &Result) {
+  const auto *OverlappingArg =
+  Result.Nodes.getNodeAs("overlappingArg");
+  const auto *FirstArg = Result.Nodes.getNodeAs("firstArgExpr");
+  const auto *FnDecl = Result.Nodes.getNodeAs("decl");
+
+  llvm::StringRef FirstArgText =
+  Lexer::getSourceText(CharSourceRange::getTokenRange(
+   FirstArg->getBeginLoc(), FirstArg->getEndLoc()),
+   *Result.SourceManager, getLangOpts());
+
+  diag(OverlappingArg->getLocation(),
+   "argument '%0' overlaps the first argument "
+   "in %1, which is undefined behavior")
+  << FirstArgText << FnDecl;

5chmidti wrote:

Please stream the source range of both arguments into the diagnostic so that 
their ranges are underlined and not only have a `^`

E.g., 
```c++
sprintf(buf, "%s", buf);
//  ^~~^~~
```

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


[clang-tools-extra] Add bugprone-undefined-sprintf-overlap (PR #114244)

2024-11-09 Thread Julian Schmidt via cfe-commits


@@ -0,0 +1,82 @@
+//===--- UndefinedSprintfOverlapCheck.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 "UndefinedSprintfOverlapCheck.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/Lex/Lexer.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+AST_MATCHER_P(IntegerLiteral, hasSameValueAs, std::string, ID) {
+  return Builder->removeBindings(
+  [this, &Node](const ast_matchers::internal::BoundNodesMap &Nodes) {
+const DynTypedNode &BN = Nodes.getNode(ID);
+if (const auto *Lit = BN.get()) {
+  return Lit->getValue() != Node.getValue();
+}
+return true;
+  });
+}
+
+UndefinedSprintfOverlapCheck::UndefinedSprintfOverlapCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context),
+  SprintfRegex(Options.get("SprintfFunction", "(::std)?::(sn?printf)")) {}
+
+void UndefinedSprintfOverlapCheck::registerMatchers(MatchFinder *Finder) {
+  auto FirstArg = declRefExpr(to(varDecl().bind("firstArgDecl")));
+  auto OtherRefToArg = 
declRefExpr(to(varDecl(equalsBoundNode("firstArgDecl"
+   .bind("overlappingArg");
+  Finder->addMatcher(
+  callExpr(
+  callee(functionDecl(matchesName(SprintfRegex)).bind("decl")),
+  allOf(hasArgument(
+0, expr(anyOf(FirstArg,
+  arraySubscriptExpr(
+  hasBase(FirstArg),
+  
hasIndex(integerLiteral().bind("index"))),
+  memberExpr(member(decl().bind("member")),
+ hasObjectExpression(FirstArg
+   .bind("firstArgExpr")),
+hasAnyArgument(expr(
+unless(equalsBoundNode("firstArgExpr")),
+anyOf(OtherRefToArg,
+  arraySubscriptExpr(hasBase(OtherRefToArg),
+ hasIndex(integerLiteral(
+ hasSameValueAs("index",
+  memberExpr(member(decl(equalsBoundNode("member"))),
+ hasObjectExpression(OtherRefToArg))),
+  this);
+}
+
+void UndefinedSprintfOverlapCheck::check(
+const MatchFinder::MatchResult &Result) {
+  const auto *OverlappingArg =
+  Result.Nodes.getNodeAs("overlappingArg");
+  const auto *FirstArg = Result.Nodes.getNodeAs("firstArgExpr");
+  const auto *FnDecl = Result.Nodes.getNodeAs("decl");
+
+  llvm::StringRef FirstArgText =
+  Lexer::getSourceText(CharSourceRange::getTokenRange(
+   FirstArg->getBeginLoc(), FirstArg->getEndLoc()),
+   *Result.SourceManager, getLangOpts());

5chmidti wrote:

You can use `CharSourceRange::getTokenRange(FirstArg->getSourceRange())` 
instead of using the begin and end variants

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


[clang] [llvm] [X86][AMX] Support AMX-TF32 (PR #115625)

2024-11-09 Thread Phoebe Wang via cfe-commits


@@ -0,0 +1,194 @@
+/*===- amxtf32intrin.h - AMX_TF32 intrinsics -*- 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
+ *
+ 
*======
+ */
+
+#ifndef __IMMINTRIN_H
+#error "Never use  directly; include  instead."
+#endif // __IMMINTRIN_H
+
+#ifndef __AMX_TF32INTRIN_H
+#define __AMX_TF32INTRIN_H
+#ifdef __x86_64__
+
+#define __DEFAULT_FN_ATTRS_TF32
\
+  __attribute__((__always_inline__, __nodebug__, __target__("amx-tf32")))
+
+#define __DEFAULT_FN_ATTRS_TF32_TRANSPOSE  
\
+  __attribute__((__always_inline__, __nodebug__,   
\
+ __target__("amx-tf32,amx-transpose")))

phoebewang wrote:

We should split transpose intrinsics to a seperate file with macro
```
#if !defined(__SCE__) || __has_feature(modules) ||
   (defined(__AMX_TF32__) && defined(__AMX_TRANSPOSE__))
#include 
#endif
```

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


[clang] [llvm] [RISCV][VLS] Support RISCV VLS calling convention (PR #100346)

2024-11-09 Thread Brandon Wu via cfe-commits

https://github.com/4vtomat updated 
https://github.com/llvm/llvm-project/pull/100346

>From 1c8201daa6925cac510ff8751ffd79a6b95f2315 Mon Sep 17 00:00:00 2001
From: Brandon Wu 
Date: Sun, 21 Jul 2024 09:49:11 -0700
Subject: [PATCH 1/2] [RISCV][VLS] Support RISCV VLS calling convention

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.

An option `-mriscv-abi-vlen=N` is also added to specify the `ABI_VLEN`
globally, it's used for every functions are being compiled, however if
both function attribute and option are specified, the function attribute
has higher priority than the option which means the function attribute
overwrites the `ABI_VLEN` specified by the option.

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.
---
 clang/include/clang-c/Index.h |  1 +
 clang/include/clang/AST/Type.h| 26 +-
 clang/include/clang/AST/TypeProperties.td |  7 +-
 clang/include/clang/Basic/Attr.td |  8 ++
 clang/include/clang/Basic/AttrDocs.td | 11 +++
 clang/include/clang/Basic/CodeGenOptions.def  |  3 +
 clang/include/clang/Basic/Specifiers.h|  1 +
 clang/include/clang/CodeGen/CGFunctionInfo.h  |  9 +-
 clang/include/clang/Driver/Options.td |  5 +-
 clang/lib/AST/ASTContext.cpp  |  2 +
 clang/lib/AST/ItaniumMangle.cpp   |  1 +
 clang/lib/AST/Type.cpp|  2 +
 clang/lib/AST/TypePrinter.cpp |  6 ++
 clang/lib/Basic/Targets/RISCV.cpp |  1 +
 clang/lib/CodeGen/CGCall.cpp  |  5 +
 clang/lib/CodeGen/CGDebugInfo.cpp |  2 +
 clang/lib/CodeGen/CodeGenModule.cpp   |  3 +-
 clang/lib/CodeGen/TargetInfo.h|  2 +-
 clang/lib/CodeGen/Targets/RISCV.cpp   | 91 +--
 clang/lib/Driver/ToolChains/Arch/RISCV.cpp|  4 +
 clang/lib/Driver/ToolChains/Clang.cpp | 15 +++
 clang/lib/Sema/SemaDeclAttr.cpp   | 40 +++-
 clang/lib/Sema/SemaType.cpp   | 26 +-
 .../RISCV/riscv-vector-callingconv-llvm-ir.c  | 40 
 .../riscv-vector-callingconv-llvm-ir.cpp  | 22 +
 .../CodeGen/RISCV/riscv-vector-callingconv.c  | 18 
 .../RISCV/riscv-vector-callingconv.cpp| 18 
 clang/tools/libclang/CXType.cpp   |  1 +
 llvm/include/llvm/AsmParser/LLToken.h |  1 +
 llvm/include/llvm/BinaryFormat/Dwarf.def  |  1 +
 llvm/include/llvm/IR/CallingConv.h|  3 +
 llvm/lib/AsmParser/LLLexer.cpp|  1 +
 llvm/lib/AsmParser/LLParser.cpp   |  4 +
 llvm/lib/IR/AsmWriter.cpp |  3 +
 llvm/lib/Target/RISCV/RISCVISelLowering.cpp   |  1 +
 llvm/test/Assembler/riscv_vls_cc.ll   | 12 +++
 llvm/test/Bitcode/compatibility.ll|  4 +
 37 files changed, 358 insertions(+), 42 deletions(-)
 create mode 100644 llvm/test/Assembler/riscv_vls_cc.ll

diff --git a/clang/include/clang-c/Index.h b/clang/include/clang-c/Index.h
index 0c5ac80772e2b9..696f9ca59546c6 100644
--- a/clang/include/clang-c/Index.h
+++ b/clang/include/clang-c/Index.h
@@ -3013,6 +3013,7 @@ enum CXCallingConv {
   CXCallingConv_M68kRTD = 19,
   CXCallingConv_PreserveNone = 20,
   CXCallingConv_RISCVVectorCall = 21,
+  CXCallingConv_RISCVVLSCall = 22,
 
   CXCallingConv_Invalid = 100,
   CXCallingConv_Unexposed = 200
diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 1bcc7ee0b70dee..5b30a31d1787db 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -1953,7 +1953,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 : 18;
 
 /// The ref-qualifier associated with a \c FunctionProtoType.
 ///
@@ -4440,6 +444

[clang] [llvm] [X86][AMX] Support AMX-MOVRS (PR #115151)

2024-11-09 Thread Phoebe Wang via cfe-commits

https://github.com/phoebewang commented:

Add Clang release note
Add `Features["amx-movrs"]` in Host.cpp
Add `AMX_MOVRS` in X86TargetParser.def
Add `ImpliedFeaturesAMX_MOVRS` in X86TargetParser.cpp


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


[clang] [llvm] [X86][AMX] Support AMX-MOVRS (PR #115151)

2024-11-09 Thread Phoebe Wang via cfe-commits


@@ -4738,6 +4738,7 @@ static bool isAMXOpcode(unsigned Opc) {
   case X86::TILELOADD_EVEX:
   case X86::TILESTORED_EVEX:
   case X86::PTILEPAIRLOAD:
+  case X86::TILELOADDRS:

phoebewang wrote:

This is not needed.

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


[clang] [llvm] [X86][AMX] Support AMX-MOVRS (PR #115151)

2024-11-09 Thread Phoebe Wang via cfe-commits

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


[clang-tools-extra] [clang-tidy] Improved readability redundant casting with enums (PR #111424)

2024-11-09 Thread Julian Schmidt via cfe-commits
=?utf-8?q?Félix-Antoine?= Constantin,
=?utf-8?q?Félix-Antoine?= Constantin,
=?utf-8?q?Félix-Antoine?= Constantin
Message-ID:
In-Reply-To: 


https://github.com/5chmidti approved this pull request.

LGTM

+- some people may want to control this behavior and keep the explicit cast for 
enums, WDYT?

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


[clang] [Clang] Add [[clang::no_specializations]] (PR #101469)

2024-11-09 Thread Nikolas Klauser via cfe-commits

https://github.com/philnik777 updated 
https://github.com/llvm/llvm-project/pull/101469

>From 82ab798fc72c6de64ae527d96393f0dc67307e98 Mon Sep 17 00:00:00 2001
From: Nikolas Klauser 
Date: Thu, 1 Aug 2024 12:30:22 +0200
Subject: [PATCH 1/6] [Clang] Add [[clang::diagnose_specializations]]

---
 clang/include/clang/Basic/Attr.td | 13 ++-
 clang/include/clang/Basic/AttrDocs.td | 14 ++--
 clang/include/clang/Basic/DiagnosticGroups.td |  1 +
 .../clang/Basic/DiagnosticSemaKinds.td|  3 ++
 clang/lib/Sema/SemaDeclAttr.cpp   |  9 +
 clang/lib/Sema/SemaTemplate.cpp   |  6 
 .../SemaCXX/attr-diagnose-specializations.cpp | 34 +++
 7 files changed, 76 insertions(+), 4 deletions(-)
 create mode 100644 clang/test/SemaCXX/attr-diagnose-specializations.cpp

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 8ac2079099c854..e074cc8b285a95 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -103,6 +103,9 @@ def NonParmVar : SubsetSubjecthasLocalStorage()}],
 "variables with non-local storage">;
+def VarTmpl : SubsetSubjectgetDescribedVarTemplate()}],
+"variable template">;
+
 def NonBitField : SubsetSubjectisBitField()}],
 "non-bit-field non-static data members">;
@@ -3327,6 +3330,14 @@ def DiagnoseIf : InheritableAttr {
   let Documentation = [DiagnoseIfDocs];
 }
 
+def DiagnoseSpecializations : InheritableAttr {
+  let Spellings = [Clang<"diagnose_specializations", /*AllowInC*/0>];
+  let Subjects = SubjectList<[ClassTmpl, VarTmpl]>;
+  let Documentation = [DiagnoseSpecializationsDocs];
+  let MeaningfulToClassTemplateDefinition = 1;
+  let TemplateDependent = 1;
+}
+
 def ArcWeakrefUnavailable : InheritableAttr {
   let Spellings = [Clang<"objc_arc_weak_reference_unavailable">];
   let Subjects = SubjectList<[ObjCInterface], ErrorDiag>;
@@ -4581,7 +4592,7 @@ def HLSLResource : InheritableAttr {
   let Spellings = [];
   let Subjects = SubjectList<[Struct]>;
   let LangOpts = [HLSL];
-  let Args = [
+  let Args = [
 EnumArgument<
 "ResourceKind", "llvm::hlsl::ResourceKind",
 /*is_string=*/0,
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 94c284fc731589..4ca67a63714d4b 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/include/clang/Basic/AttrDocs.td
@@ -975,6 +975,15 @@ Query for this feature with 
``__has_attribute(diagnose_if)``.
   }];
 }
 
+def DiagnoseSpecializationsDocs : Documentation {
+  let Category = DocCatDecl;
+  let Content = [{
+``clang::diagnose_specializations`` can be appied to class templates which
+should not be specialized by users. This is primarily used to diagnose user
+specializations of standard library type traits.
+  }];
+}
+
 def PassObjectSizeDocs : Documentation {
   let Category = DocCatVariable; // Technically it's a parameter doc, but eh.
   let Heading = "pass_object_size, pass_dynamic_object_size";
@@ -7388,10 +7397,10 @@ def HLSLLoopHintDocs : Documentation {
   let Content = [{
 The ``[loop]`` directive allows loop optimization hints to be
 specified for the subsequent loop. The directive allows unrolling to
-be disabled and is not compatible with [unroll(x)]. 
+be disabled and is not compatible with [unroll(x)].
 
 Specifying the parameter, ``[loop]``, directs the
-unroller to not unroll the loop. 
+unroller to not unroll the loop.
 
 .. code-block:: hlsl
 
@@ -8306,4 +8315,3 @@ Declares that a function potentially allocates heap 
memory, and prevents any pot
 of ``nonallocating`` by the compiler.
   }];
 }
-
diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index 19c3f1e0433496..d6f6111f708684 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -472,6 +472,7 @@ def ExpansionToDefined : DiagGroup<"expansion-to-defined">;
 def FlagEnum : DiagGroup<"flag-enum">;
 def IncrementBool : DiagGroup<"increment-bool", [DeprecatedIncrementBool]>;
 def InfiniteRecursion : DiagGroup<"infinite-recursion">;
+def InvalidSpecialization : DiagGroup<"invalid-specialization">;
 def PureVirtualCallFromCtorDtor: 
DiagGroup<"call-to-pure-virtual-from-ctor-dtor">;
 def GNUImaginaryConstant : DiagGroup<"gnu-imaginary-constant">;
 def IgnoredGCH : DiagGroup<"ignored-gch">;
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 581434d33c5c9a..5972d630347ec4 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -5407,6 +5407,9 @@ def note_dependent_function_template_spec_discard_reason 
: Note<
   "candidate ignored: %select{not a function template|"
   "not a member of the enclosing %select{class template|"
   "namespace; did y

[clang] [Clang] Add [[clang::no_specializations]] (PR #101469)

2024-11-09 Thread Nikolas Klauser via cfe-commits

philnik777 wrote:

I went for only adding `[[clang::no_specialization]]` to function templates, 
since the other cases seem even more unlikely to me and seem to have a higher 
implementation complexity. Is that OK?

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


[clang] [Clang] Add [[clang::no_specializations]] (PR #101469)

2024-11-09 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 bfe486fe764667d514124faf2b39afb7e7322640 
5dd5dd4e7a7733412fb20368202c657f97b635a2 --extensions cpp -- 
clang/test/SemaCXX/attr-no-specializations.cpp clang/lib/Sema/SemaDeclAttr.cpp 
clang/lib/Sema/SemaTemplate.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index b8d9a3ebe8..ad5a6f51bd 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -1215,8 +1215,7 @@ static void handlePreferredName(Sema &S, Decl *D, const 
ParsedAttr &AL) {
 << TT->getDecl();
 }
 
-static void handleNoSpecializations(Sema &S, Decl *D,
-  const ParsedAttr &AL) {
+static void handleNoSpecializations(Sema &S, Decl *D, const ParsedAttr &AL) {
   StringRef Message;
   if (AL.getNumArgs() != 0)
 S.checkStringLiteralArgumentAttr(AL, 0, Message);

``




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


[clang-tools-extra] [clang-tidy] Create bugprone-incorrect-enable-shared-from-this check (PR #102299)

2024-11-09 Thread Julian Schmidt via cfe-commits

https://github.com/5chmidti approved this pull request.

Minus my comment, this looks good to me. Thanks for working on this.

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


[clang-tools-extra] [clang-tidy] Create bugprone-incorrect-enable-shared-from-this check (PR #102299)

2024-11-09 Thread Julian Schmidt via cfe-commits

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


[clang-tools-extra] [clang-tidy] Create bugprone-incorrect-enable-shared-from-this check (PR #102299)

2024-11-09 Thread Julian Schmidt via cfe-commits


@@ -0,0 +1,62 @@
+//===--- IncorrectEnableSharedFromThisCheck.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 "IncorrectEnableSharedFromThisCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/DeclCXX.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+void IncorrectEnableSharedFromThisCheck::registerMatchers(MatchFinder *Finder) 
{
+  const auto EnableSharedFromThis =
+  cxxRecordDecl(hasName("enable_shared_from_this"), isInStdNamespace());
+  const auto QType = hasCanonicalType(hasDeclaration(
+  cxxRecordDecl(
+  anyOf(EnableSharedFromThis.bind("enable_rec"),
+cxxRecordDecl(hasAnyBase(cxxBaseSpecifier(
+isPublic(), hasType(hasCanonicalType(
+hasDeclaration(EnableSharedFromThis
+  .bind("base_rec")));
+  Finder->addMatcher(
+  cxxRecordDecl(
+  hasDirectBase(cxxBaseSpecifier(unless(isPublic()), hasType(QType))
+.bind("base")))
+  .bind("derived"),
+  this);
+}
+
+void IncorrectEnableSharedFromThisCheck::check(
+const MatchFinder::MatchResult &Result) {
+  const auto *BaseSpec = Result.Nodes.getNodeAs("base");
+  const auto *Base = Result.Nodes.getNodeAs("base_rec");
+  const auto *Derived = Result.Nodes.getNodeAs("derived");
+  const bool IsEnableSharedFromThisDirectBase =
+  Result.Nodes.getNodeAs("enable_rec") == Base;
+  const SourceRange ReplacementRange = BaseSpec->getSourceRange();
+  const std::string ReplacementString =
+  // BaseSpec->getType().getAsString() results in
+  // std::enable_shared_from_this or
+  // alias/typedefs of std::enable_shared_from_this
+  "public " + BaseSpec->getType().getAsString();

5chmidti wrote:

> also, side note: MACRO_A doesn't count as direct inheritance either, so the 
> fix won't emit on MACRO_A if we do the "issue FixItHint on direct inheritance 
> only", which sort of resolves this comment indirectly as the issue is with 
> FixItHint.

IMO macros are similar to aliases in this context, and we can do a replacement 
as well.

---

I found a way that works:

```diff
-  const SourceRange ReplacementRange = BaseSpec->getSourceRange();
-  const std::string ReplacementString =
-  // BaseSpec->getType().getAsString() results in
-  // std::enable_shared_from_this or
-  // alias/typedefs of std::enable_shared_from_this
-  "public " + BaseSpec->getType().getAsString();
+  const bool HasWrittenAccessSpecifier =
+  BaseSpec->getAccessSpecifierAsWritten() != AS_none;
+  const auto ReplacementRange = CharSourceRange(
+  SourceRange(BaseSpec->getBeginLoc(), BaseSpec->getBeginLoc()),
+  HasWrittenAccessSpecifier);
+  const llvm::StringRef Replacement =
+  HasWrittenAccessSpecifier ? "public" : "public ";
   const FixItHint Hint =
   IsEnableSharedFromThisDirectBase
-  ? FixItHint::CreateReplacement(ReplacementRange, ReplacementString)
+  ? FixItHint::CreateReplacement(ReplacementRange, Replacement)
```

with the following tests:
```c++
#define MACRO_PARAM(CLASS) std::enable_shared_from_this
class E : MACRO_PARAM(E) {};
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: 'E' is not publicly inheriting from 
'std::enable_shared_from_this', which will cause unintended behaviour when 
using 'shared_from_this'; make the inheritance public 
[bugprone-incorrect-enable-shared-from-this]
// CHECK-FIXES: class E : public MACRO_PARAM(E) {};
class F : private MACRO_PARAM(F) {};
// CHECK-MESSAGES: :[[@LINE-1]]:7: warning: 'F' is not publicly inheriting from 
'std::enable_shared_from_this', which will cause unintended behaviour when 
using 'shared_from_this'; make the inheritance public 
[bugprone-incorrect-enable-shared-from-this]
// CHECK-FIXES: class F : public MACRO_PARAM(F) {};
class G : public MACRO_PARAM(G) {};
```

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


[clang] [llvm] [clang-format] Add CI check confirming ClangFormatStyleOptions.rst is up-to-date. (PR #111513)

2024-11-09 Thread Iuri Chaer via cfe-commits


@@ -53,3 +53,10 @@ foreach (file IN LISTS files)
 endforeach ()
 
 add_custom_target(clang-format-check-format DEPENDS ${check_format_depends})
+
+add_custom_target(clang-format-style-options
+COMMAND "${Python3_EXECUTABLE}" dump_format_style.py
+WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/../../docs/tools"
+DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/../../include/clang/Format/Format.h"
+
"${CMAKE_CURRENT_SOURCE_DIR}/../../include/clang/Tooling/Inclusions/IncludeStyle.h")

ichaer wrote:

Sorry for the silence, @owenca, crazy days!

Your suggestion is much cleaner, thank you :)

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


[clang] [llvm] [clang-format] Add CI check confirming ClangFormatStyleOptions.rst is up-to-date. (PR #111513)

2024-11-09 Thread Iuri Chaer via cfe-commits

https://github.com/ichaer updated 
https://github.com/llvm/llvm-project/pull/111513

>From 7db80ba448fe4f434362de505330f504b9362844 Mon Sep 17 00:00:00 2001
From: Iuri Chaer 
Date: Tue, 8 Oct 2024 10:52:13 +0100
Subject: [PATCH 1/6] [clang-format] Add CI check confirming
 ClangFormatStyleOptions.rst is up-to-date.

As discussed in 
https://github.com/llvm/llvm-project/pull/96804#discussion_r1718407404
---
 .github/workflows/docs.yml | 12 
 clang/docs/CMakeLists.txt  |  6 ++
 2 files changed, 18 insertions(+)

diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml
index 800e9291573533..25eff4dcabc4a2 100644
--- a/.github/workflows/docs.yml
+++ b/.github/workflows/docs.yml
@@ -75,6 +75,9 @@ jobs:
   - 'clang/include/clang/Basic/AttrDocs.td'
   - 'clang/include/clang/Driver/ClangOptionDocs.td'
   - 'clang/include/clang/Basic/DiagnosticDocs.td'
+clang-format_style-headers:
+  - 'clang/include/clang/Format/Format.h'
+  - 'clang/include/clang/Tooling/Inclusions/IncludeStyle.h'
 clang-tools-extra:
   - 'clang-tools-extra/docs/**'
 lldb:
@@ -122,6 +125,15 @@ jobs:
 run: |
   cmake -B clang-build -GNinja -DCMAKE_BUILD_TYPE=Release 
-DLLVM_ENABLE_PROJECTS="clang" -DLLVM_ENABLE_SPHINX=ON ./llvm
   TZ=UTC ninja -C clang-build docs-clang-html docs-clang-man
+  - name: Confirm ClangFormatStyleOptions.rst is up-to-date
+if: 
steps.docs-changed-subprojects.outputs.clang-format_style-headers_any_changed 
== 'true'
+run: |
+  cmake -B clang-build -GNinja -DCMAKE_BUILD_TYPE=Release 
-DLLVM_ENABLE_PROJECTS="clang" -DLLVM_ENABLE_SPHINX=ON ./llvm
+  TZ=UTC ninja -C clang-build clang-format-style-options
+  GIT_STATUS="$(git status --porcelain=v1 
clang/docs/ClangFormatStyleOptions.rst)"
+  if [ ! -z "${GIT_STATUS}" ]; then
+echo "Error: you must build the 'clang-format-style-options' 
target and commit any changes to 'clang/docs/ClangFormatStyleOptions.rst'"
+  fi
   - name: Build clang-tools-extra docs
 if: 
steps.docs-changed-subprojects.outputs.clang-tools-extra_any_changed == 'true'
 run: |
diff --git a/clang/docs/CMakeLists.txt b/clang/docs/CMakeLists.txt
index 51e9db29f887f3..cdc65e4455f87b 100644
--- a/clang/docs/CMakeLists.txt
+++ b/clang/docs/CMakeLists.txt
@@ -1,3 +1,9 @@
+add_custom_target(clang-format-style-options
+COMMAND "${Python3_EXECUTABLE}" dump_format_style.py
+WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/tools"
+DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/../include/clang/Format/Format.h"
+
"${CMAKE_CURRENT_SOURCE_DIR}/../include/clang/Tooling/Inclusions/IncludeStyle.h")
+add_dependencies(clang-format clang-format-style-options)
 
 if (DOXYGEN_FOUND)
 if (LLVM_ENABLE_DOXYGEN)

>From 584828b05034cffd28a87778e5c70c8575d81a5b Mon Sep 17 00:00:00 2001
From: Iuri Chaer 
Date: Tue, 8 Oct 2024 10:57:02 +0100
Subject: [PATCH 2/6] REVERT BEFORE MERGING

Add a change to clang/include/clang/Format/Format.h so we can see the new CI 
check working.
---
 clang/include/clang/Format/Format.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index ef6c76a070bfaa..546b971a2ab35a 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -3791,7 +3791,7 @@ struct FormatStyle {
   enum ReferenceAlignmentStyle : int8_t {
 /// Align reference like ``PointerAlignment``.
 RAS_Pointer,
-/// Align reference to the left.
+/// Align reference to the left FOOBAR CHANGE TO VALIDATE NEW CI CHECK.
 /// \code
 ///   int& a;
 /// \endcode

>From e269710fb69b691aafd0b660271c95dbc50cb0a6 Mon Sep 17 00:00:00 2001
From: Iuri Chaer 
Date: Tue, 8 Oct 2024 11:20:26 +0100
Subject: [PATCH 3/6] lol, what a thing to forget

---
 .github/workflows/docs.yml | 1 +
 1 file changed, 1 insertion(+)

diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml
index 25eff4dcabc4a2..f559fbd237a99d 100644
--- a/.github/workflows/docs.yml
+++ b/.github/workflows/docs.yml
@@ -133,6 +133,7 @@ jobs:
   GIT_STATUS="$(git status --porcelain=v1 
clang/docs/ClangFormatStyleOptions.rst)"
   if [ ! -z "${GIT_STATUS}" ]; then
 echo "Error: you must build the 'clang-format-style-options' 
target and commit any changes to 'clang/docs/ClangFormatStyleOptions.rst'"
+exit 1
   fi
   - name: Build clang-tools-extra docs
 if: 
steps.docs-changed-subprojects.outputs.clang-tools-extra_any_changed == 'true'

>From 261ac339ac4c433f54e87de8d1632b428df32e96 Mon Sep 17 00:00:00 2001
From: Iuri Chaer 
Date: Tue, 8 Oct 2024 11:22:13 +0100
Subject: [PATCH 4/6] Revert "REVERT BEFORE MERGING"

This reverts commit 584828b05034cffd28a87778e5c70c8575d81a5b.
---
 clang/include/clang/Format/Format.h | 2 +-

[clang] [llvm] [clang-format] Add new cmake target, `clang-format-style-options`, for updating ClangFormatStyleOptions.rst. (PR #111513)

2024-11-09 Thread Iuri Chaer via cfe-commits

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


[clang] [llvm] [clang-format] Add new cmake target, `clang-format-style-options`, for updating ClangFormatStyleOptions.rst. (PR #111513)

2024-11-09 Thread Iuri Chaer via cfe-commits

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


[clang] [llvm] [clang-format] Add CI check confirming ClangFormatStyleOptions.rst is up-to-date. (PR #111513)

2024-11-09 Thread Iuri Chaer via cfe-commits

https://github.com/ichaer updated 
https://github.com/llvm/llvm-project/pull/111513

>From 7db80ba448fe4f434362de505330f504b9362844 Mon Sep 17 00:00:00 2001
From: Iuri Chaer 
Date: Tue, 8 Oct 2024 10:52:13 +0100
Subject: [PATCH 1/7] [clang-format] Add CI check confirming
 ClangFormatStyleOptions.rst is up-to-date.

As discussed in 
https://github.com/llvm/llvm-project/pull/96804#discussion_r1718407404
---
 .github/workflows/docs.yml | 12 
 clang/docs/CMakeLists.txt  |  6 ++
 2 files changed, 18 insertions(+)

diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml
index 800e9291573533..25eff4dcabc4a2 100644
--- a/.github/workflows/docs.yml
+++ b/.github/workflows/docs.yml
@@ -75,6 +75,9 @@ jobs:
   - 'clang/include/clang/Basic/AttrDocs.td'
   - 'clang/include/clang/Driver/ClangOptionDocs.td'
   - 'clang/include/clang/Basic/DiagnosticDocs.td'
+clang-format_style-headers:
+  - 'clang/include/clang/Format/Format.h'
+  - 'clang/include/clang/Tooling/Inclusions/IncludeStyle.h'
 clang-tools-extra:
   - 'clang-tools-extra/docs/**'
 lldb:
@@ -122,6 +125,15 @@ jobs:
 run: |
   cmake -B clang-build -GNinja -DCMAKE_BUILD_TYPE=Release 
-DLLVM_ENABLE_PROJECTS="clang" -DLLVM_ENABLE_SPHINX=ON ./llvm
   TZ=UTC ninja -C clang-build docs-clang-html docs-clang-man
+  - name: Confirm ClangFormatStyleOptions.rst is up-to-date
+if: 
steps.docs-changed-subprojects.outputs.clang-format_style-headers_any_changed 
== 'true'
+run: |
+  cmake -B clang-build -GNinja -DCMAKE_BUILD_TYPE=Release 
-DLLVM_ENABLE_PROJECTS="clang" -DLLVM_ENABLE_SPHINX=ON ./llvm
+  TZ=UTC ninja -C clang-build clang-format-style-options
+  GIT_STATUS="$(git status --porcelain=v1 
clang/docs/ClangFormatStyleOptions.rst)"
+  if [ ! -z "${GIT_STATUS}" ]; then
+echo "Error: you must build the 'clang-format-style-options' 
target and commit any changes to 'clang/docs/ClangFormatStyleOptions.rst'"
+  fi
   - name: Build clang-tools-extra docs
 if: 
steps.docs-changed-subprojects.outputs.clang-tools-extra_any_changed == 'true'
 run: |
diff --git a/clang/docs/CMakeLists.txt b/clang/docs/CMakeLists.txt
index 51e9db29f887f3..cdc65e4455f87b 100644
--- a/clang/docs/CMakeLists.txt
+++ b/clang/docs/CMakeLists.txt
@@ -1,3 +1,9 @@
+add_custom_target(clang-format-style-options
+COMMAND "${Python3_EXECUTABLE}" dump_format_style.py
+WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/tools"
+DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/../include/clang/Format/Format.h"
+
"${CMAKE_CURRENT_SOURCE_DIR}/../include/clang/Tooling/Inclusions/IncludeStyle.h")
+add_dependencies(clang-format clang-format-style-options)
 
 if (DOXYGEN_FOUND)
 if (LLVM_ENABLE_DOXYGEN)

>From 584828b05034cffd28a87778e5c70c8575d81a5b Mon Sep 17 00:00:00 2001
From: Iuri Chaer 
Date: Tue, 8 Oct 2024 10:57:02 +0100
Subject: [PATCH 2/7] REVERT BEFORE MERGING

Add a change to clang/include/clang/Format/Format.h so we can see the new CI 
check working.
---
 clang/include/clang/Format/Format.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index ef6c76a070bfaa..546b971a2ab35a 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -3791,7 +3791,7 @@ struct FormatStyle {
   enum ReferenceAlignmentStyle : int8_t {
 /// Align reference like ``PointerAlignment``.
 RAS_Pointer,
-/// Align reference to the left.
+/// Align reference to the left FOOBAR CHANGE TO VALIDATE NEW CI CHECK.
 /// \code
 ///   int& a;
 /// \endcode

>From e269710fb69b691aafd0b660271c95dbc50cb0a6 Mon Sep 17 00:00:00 2001
From: Iuri Chaer 
Date: Tue, 8 Oct 2024 11:20:26 +0100
Subject: [PATCH 3/7] lol, what a thing to forget

---
 .github/workflows/docs.yml | 1 +
 1 file changed, 1 insertion(+)

diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml
index 25eff4dcabc4a2..f559fbd237a99d 100644
--- a/.github/workflows/docs.yml
+++ b/.github/workflows/docs.yml
@@ -133,6 +133,7 @@ jobs:
   GIT_STATUS="$(git status --porcelain=v1 
clang/docs/ClangFormatStyleOptions.rst)"
   if [ ! -z "${GIT_STATUS}" ]; then
 echo "Error: you must build the 'clang-format-style-options' 
target and commit any changes to 'clang/docs/ClangFormatStyleOptions.rst'"
+exit 1
   fi
   - name: Build clang-tools-extra docs
 if: 
steps.docs-changed-subprojects.outputs.clang-tools-extra_any_changed == 'true'

>From 261ac339ac4c433f54e87de8d1632b428df32e96 Mon Sep 17 00:00:00 2001
From: Iuri Chaer 
Date: Tue, 8 Oct 2024 11:22:13 +0100
Subject: [PATCH 4/7] Revert "REVERT BEFORE MERGING"

This reverts commit 584828b05034cffd28a87778e5c70c8575d81a5b.
---
 clang/include/clang/Format/Format.h | 2 +-

[clang] [llvm] [clang-format] Add CI check confirming ClangFormatStyleOptions.rst is up-to-date. (PR #111513)

2024-11-09 Thread Iuri Chaer via cfe-commits

ichaer wrote:

> @ichaer I suggest that you split the workflow part to another patch so that 
> we can get the cmake part approved.

It's a bit sad, but I get your point, let's make it more focused. 

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


[clang] [analyzer] Refine LCV handling in Store for better taint propagation (PR #114835)

2024-11-09 Thread Balazs Benics via cfe-commits

https://github.com/steakhal updated 
https://github.com/llvm/llvm-project/pull/114835

>From 26f0cfabe3328c8eb8a861dd5d1d541921499f0c Mon Sep 17 00:00:00 2001
From: Balazs Benics 
Date: Sat, 9 Nov 2024 15:55:08 +0100
Subject: [PATCH 1/5] [analyzer][NFC] Make RegionStore dumps deterministic

Dump the memory space clusters before the other clusters, in
alphabetical order. Then default bindings over direct bindings, and if
any has symbolic offset, then those should come before the ones with
concrete offsets.
In theory, we should either have a symbolic offset OR concrete offsets,
but never both at the same time.
---
 clang/lib/StaticAnalyzer/Core/RegionStore.cpp | 86 ---
 1 file changed, 73 insertions(+), 13 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Core/RegionStore.cpp 
b/clang/lib/StaticAnalyzer/Core/RegionStore.cpp
index 674099dd7e1f0f..6bad9a93a30169 100644
--- a/clang/lib/StaticAnalyzer/Core/RegionStore.cpp
+++ b/clang/lib/StaticAnalyzer/Core/RegionStore.cpp
@@ -67,9 +67,10 @@ class BindingKey {
 isa(r)) &&
"Not a base");
   }
-public:
 
+public:
   bool isDirect() const { return P.getInt() & Direct; }
+  bool isDefault() const { return !isDirect(); }
   bool hasSymbolicOffset() const { return P.getInt() & Symbolic; }
 
   const MemRegion *getRegion() const { return P.getPointer(); }
@@ -232,27 +233,86 @@ class RegionBindingsRef : public 
llvm::ImmutableMapRef StringifyCache;
+auto ToString = [&StringifyCache](const MemRegion *R) {
+  auto [Place, Inserted] = StringifyCache.try_emplace(R);
+  if (!Inserted)
+return Place->second;
+  std::string Res;
+  raw_string_ostream OS(Res);
+  OS << R;
+  Place->second = Res;
+  return Res;
+};
+
+using Cluster =
+std::pair>;
+using Binding = std::pair;
+
+const auto MemSpaceBeforeRegionName = [&ToString](const Cluster *L,
+  const Cluster *R) {
+  if (isa(L->first) && !isa(R->first))
+return true;
+  if (!isa(L->first) && isa(R->first))
+return false;
+  return ToString(L->first) < ToString(R->first);
+};
+
+const auto SymbolicBeforeOffset = [&ToString](const BindingKey &L,
+  const BindingKey &R) {
+  if (L.hasSymbolicOffset() && !R.hasSymbolicOffset())
+return true;
+  if (!L.hasSymbolicOffset() && R.hasSymbolicOffset())
+return false;
+  if (L.hasSymbolicOffset() && R.hasSymbolicOffset())
+return ToString(L.getRegion()) < ToString(R.getRegion());
+  return L.getOffset() < R.getOffset();
+};
+
+const auto DefaultBindingBeforeDirectBindings =
+[&SymbolicBeforeOffset](const Binding *LPtr, const Binding *RPtr) {
+  const BindingKey &L = LPtr->first;
+  const BindingKey &R = RPtr->first;
+  if (L.isDefault() && !R.isDefault())
+return true;
+  if (!L.isDefault() && R.isDefault())
+return false;
+  assert(L.isDefault() == R.isDefault());
+  return SymbolicBeforeOffset(L, R);
+};
+
+const auto AddrOf = [](const auto &Item) { return &Item; };
+
+std::vector SortedClusters;
+SortedClusters.reserve(std::distance(begin(), end()));
+append_range(SortedClusters, map_range(*this, AddrOf));
+llvm::sort(SortedClusters, MemSpaceBeforeRegionName);
+
+for (auto [Idx, C] : llvm::enumerate(SortedClusters)) {
+  const auto &[BaseRegion, Bindings] = *C;
   Indent(Out, Space, IsDot)
-  << "{ \"cluster\": \"" << I.getKey() << "\", \"pointer\": \""
-  << (const void *)I.getKey() << "\", \"items\": [" << NL;
+  << "{ \"cluster\": \"" << BaseRegion << "\", \"pointer\": \""
+  << (const void *)BaseRegion << "\", \"items\": [" << NL;
+
+  std::vector SortedBindings;
+  SortedBindings.reserve(std::distance(Bindings.begin(), Bindings.end()));
+  append_range(SortedBindings, map_range(Bindings, AddrOf));
+  llvm::sort(SortedBindings, DefaultBindingBeforeDirectBindings);
 
   ++Space;
-  const ClusterBindings &CB = I.getData();
-  for (ClusterBindings::iterator CI = CB.begin(), CE = CB.end(); CI != CE;
-   ++CI) {
-Indent(Out, Space, IsDot) << "{ " << CI.getKey() << ", \"value\": ";
-CI.getData().printJson(Out, /*AddQuotes=*/true);
+  for (auto [Idx, B] : llvm::enumerate(SortedBindings)) {
+const auto &[Key, Value] = *B;
+Indent(Out, Space, IsDot) << "{ " << Key << ", \"value\": ";
+Value.printJson(Out, /*AddQuotes=*/true);
 Out << " }";
-if (std::next(CI) != CE)
+if (Idx != SortedBindings.size() - 1)
   Out << ',';
 Out << NL;
   }
-
   --Space;
   Indent(Out, Space, IsDot) << "]}";
-  if (std::next(I) != E)
+  if (Idx != SortedClusters.size() - 1)
 Out << ',';
   Out << NL;
 }

>From efa54ca20448e3

  1   2   >