[clang] [Clang] prevent errors for deduction guides using deduced type aliases (PR #117450)

2024-11-25 Thread Younan Zhang via cfe-commits


@@ -33,7 +33,7 @@ template typename TT> struct E { // 
expected-note 2{{template
 };
 
 A(int) -> int; // expected-error {{deduced type 'int' of deduction guide is 
not a specialization of template 'A'}}
-template  A(T)->B; // expected-error {{deduced type 
'B' (aka 'A') of deduction guide is not written as a specialization of 
template 'A'}}
+template  A(T)->B;

zyn0217 wrote:

I think this is probably sufficient to prove GH54909 has been fixed?

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


[clang] [Clang] prevent errors for deduction guides using deduced type aliases (PR #117450)

2024-11-25 Thread Younan Zhang via cfe-commits


@@ -11451,7 +11451,11 @@ bool Sema::CheckDeductionGuideDeclarator(Declarator 
&D, QualType &R,
 bool MightInstantiateToSpecialization = false;
 if (auto RetTST =
 TSI->getTypeLoc().getAsAdjusted()) {
-  TemplateName SpecifiedName = RetTST.getTypePtr()->getTemplateName();
+  const TemplateSpecializationType *TST = RetTST.getTypePtr();
+  while (TST->isTypeAlias())
+TST = TST->getAliasedType()->getAs();

zyn0217 wrote:

What will happen if `->getAs()` returns null? We 
should ensure TST is always present

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


[clang] 0fe12a7 - [clang-format][NFC] Remove a pointer in ContinuationIndenter

2024-11-25 Thread Owen Pan via cfe-commits

Author: Owen Pan
Date: 2024-11-25T00:35:50-08:00
New Revision: 0fe12a7db3f6663c9f2572ff0232e56f1bd411ae

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

LOG: [clang-format][NFC] Remove a pointer in ContinuationIndenter

Added: 


Modified: 
clang/lib/Format/ContinuationIndenter.cpp

Removed: 




diff  --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index fd53969e4b3b33..aed86c1fb99551 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -693,17 +693,14 @@ void 
ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun,
 
   bool DisallowLineBreaksOnThisLine =
   Style.LambdaBodyIndentation == FormatStyle::LBI_Signature &&
-  Style.isCpp() && [&Current] {
-// Deal with lambda arguments in C++. The aim here is to ensure that we
-// don't over-indent lambda function bodies when lambdas are passed as
-// arguments to function calls. We do this by ensuring that either all
-// arguments (including any lambdas) go on the same line as the 
function
-// call, or we break before the first argument.
-const auto *Prev = Current.Previous;
-if (!Prev)
-  return false;
+  // Deal with lambda arguments in C++. The aim here is to ensure that we
+  // don't over-indent lambda function bodies when lambdas are passed as
+  // arguments to function calls. We do this by ensuring that either all
+  // arguments (including any lambdas) go on the same line as the function
+  // call, or we break before the first argument.
+  Style.isCpp() && [&] {
 // For example, `/*Newline=*/false`.
-if (Prev->is(TT_BlockComment) && Current.SpacesRequiredBefore == 0)
+if (Previous.is(TT_BlockComment) && Current.SpacesRequiredBefore == 0)
   return false;
 const auto *PrevNonComment = Current.getPreviousNonComment();
 if (!PrevNonComment || PrevNonComment->isNot(tok::l_paren))



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


[clang] [clang] Fix a crash issue that caused by handling of fields with initializers in nested anonymous unions (PR #113049)

2024-11-25 Thread Haojian Wu via cfe-commits

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


[clang] [flang] [llvm] seq_cst is allowed in Flush since OpenMP 5.1. (PR #114072)

2024-11-25 Thread CHANDRA GHALE via cfe-commits

https://github.com/chandraghale updated 
https://github.com/llvm/llvm-project/pull/114072

>From 4b49b221a67bd77db98ca765610f7c1ace0772a0 Mon Sep 17 00:00:00 2001
From: Shashwathi N 
Date: Tue, 29 Oct 2024 09:16:04 -0500
Subject: [PATCH 1/3] Added support for seq_cst clause for flush directive

---
 clang/include/clang/AST/OpenMPClause.h|  4 ++--
 .../clang/Basic/DiagnosticSemaKinds.td|  2 +-
 clang/lib/Sema/SemaOpenMP.cpp |  3 ++-
 clang/test/OpenMP/flush_ast_print.cpp | 18 +++--
 clang/test/OpenMP/flush_codegen.cpp   | 20 ++-
 clang/test/OpenMP/flush_messages.cpp  |  6 ++
 .../Semantics/OpenMP/clause-validity01.f90|  3 +--
 flang/test/Semantics/OpenMP/flush02.f90   |  4 +---
 llvm/include/llvm/Frontend/OpenMP/OMP.td  |  1 +
 9 files changed, 33 insertions(+), 28 deletions(-)

diff --git a/clang/include/clang/AST/OpenMPClause.h 
b/clang/include/clang/AST/OpenMPClause.h
index 9cf46f73f6e46d..8a1f16f96ddc27 100644
--- a/clang/include/clang/AST/OpenMPClause.h
+++ b/clang/include/clang/AST/OpenMPClause.h
@@ -2645,8 +2645,8 @@ class OMPCompareClause final : public OMPClause {
   }
 };
 
-/// This represents 'seq_cst' clause in the '#pragma omp atomic'
-/// directive.
+/// This represents 'seq_cst' clause in the '#pragma omp atomic|flush'
+/// directives.
 ///
 /// \code
 /// #pragma omp atomic seq_cst
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 34ff49d7238a7f..6ce969988491c1 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -11360,7 +11360,7 @@ def err_omp_atomic_weak_no_equality : Error<"expected 
'==' operator for 'weak' c
 def err_omp_atomic_several_clauses : Error<
   "directive '#pragma omp atomic' cannot contain more than one 'read', 
'write', 'update', 'capture', or 'compare' clause">;
 def err_omp_several_mem_order_clauses : Error<
-  "directive '#pragma omp %0' cannot contain more than one %select{'seq_cst', 
'relaxed', |}1'acq_rel', 'acquire' or 'release' clause">;
+  "directive '#pragma omp %0' cannot contain more than one 'seq_cst',%select{ 
'relaxed',|}1 'acq_rel', 'acquire' or 'release' clause">;
 def err_omp_atomic_incompatible_mem_order_clause : Error<
   "directive '#pragma omp atomic%select{ %0|}1' cannot be used with '%2' 
clause">;
 def note_omp_previous_mem_order_clause : Note<
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 79e1536288e602..d794d572d07ead 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -11105,7 +11105,8 @@ StmtResult 
SemaOpenMP::ActOnOpenMPFlushDirective(ArrayRef Clauses,
   for (const OMPClause *C : Clauses) {
 if (C->getClauseKind() == OMPC_acq_rel ||
 C->getClauseKind() == OMPC_acquire ||
-C->getClauseKind() == OMPC_release) {
+C->getClauseKind() == OMPC_release ||
+C->getClauseKind() == OMPC_seq_cst /*OpenMP 5.1*/) {
   if (MemOrderKind != OMPC_unknown) {
 Diag(C->getBeginLoc(), diag::err_omp_several_mem_order_clauses)
 << getOpenMPDirectiveName(OMPD_flush) << 1
diff --git a/clang/test/OpenMP/flush_ast_print.cpp 
b/clang/test/OpenMP/flush_ast_print.cpp
index 9578ada020227a..768282422032fd 100644
--- a/clang/test/OpenMP/flush_ast_print.cpp
+++ b/clang/test/OpenMP/flush_ast_print.cpp
@@ -1,10 +1,10 @@
-// RUN: %clang_cc1 -verify -fopenmp -ast-print %s | FileCheck %s
-// RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -emit-pch -o %t %s
-// RUN: %clang_cc1 -fopenmp -std=c++11 -include-pch %t -verify %s -ast-print | 
FileCheck %s
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=51 -ast-print %s | 
FileCheck %s
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=51 -x c++ -std=c++11 -emit-pch -o 
%t %s
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=51 -std=c++11 -include-pch %t  
-verify %s -ast-print | FileCheck %s
 
-// RUN: %clang_cc1 -verify -fopenmp-simd -ast-print %s | FileCheck %s
-// RUN: %clang_cc1 -fopenmp-simd -x c++ -std=c++11 -emit-pch -o %t %s
-// RUN: %clang_cc1 -fopenmp-simd -std=c++11 -include-pch %t -verify %s 
-ast-print | FileCheck %s
+// RUN: %clang_cc1 -verify -fopenmp-simd -fopenmp-version=51 -ast-print %s | 
FileCheck %s
+// RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=51 -x c++ -std=c++11 
-emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=51 -std=c++11 -include-pch 
%t -verify %s -ast-print | FileCheck %s
 // expected-no-diagnostics
 
 #ifndef HEADER
@@ -19,6 +19,7 @@ T tmain(T argc) {
 #pragma omp flush acq_rel
 #pragma omp flush acquire
 #pragma omp flush release
+#pragma omp flush seq_cst
 #pragma omp flush(a)
   return a + argc;
 }
@@ -27,18 +28,21 @@ T tmain(T argc) {
 // CHECK-NEXT: #pragma omp flush acq_rel{{$}}
 // CHECK-NEXT: #pragma omp flush acquire{{$}}
 // CHECK-NEXT: #pragma omp flush release{{$}}
+// CHECK-NEXT: #pragma omp flush seq_cst{{$}}
 // CHECK

[clang] [Clang] Emit stub version of OpenCL Kernel (PR #115821)

2024-11-25 Thread Aniket Lal via cfe-commits

https://github.com/lalaniket8 updated 
https://github.com/llvm/llvm-project/pull/115821

>From 61c90047a2e82e8dd051363f9e56e52e9931c481 Mon Sep 17 00:00:00 2001
From: anikelal 
Date: Mon, 25 Nov 2024 14:18:36 +0530
Subject: [PATCH] OpenCL allows a kernel function to call another kernel
 function. To facilitate this we emit a stub version of each kernel function
 with different name mangling scheme, and replace the kernel callsite
 appropriately.

https://github.com/llvm/llvm-project/issues/60313
https://ontrack-internal.amd.com/browse/SWDEV-245936
---
 clang/include/clang/AST/GlobalDecl.h  | 37 +
 clang/lib/AST/Expr.cpp|  3 +-
 clang/lib/AST/ItaniumMangle.cpp   | 15 ++
 clang/lib/AST/Mangle.cpp  |  2 +-
 clang/lib/AST/MicrosoftMangle.cpp |  6 +++
 clang/lib/CodeGen/CGCall.cpp  | 11 +++-
 clang/lib/CodeGen/CGExpr.cpp  |  5 +-
 clang/lib/CodeGen/CGOpenCLRuntime.cpp |  5 +-
 clang/lib/CodeGen/CodeGenModule.cpp   |  7 +++
 .../test/CodeGenOpenCL/opencl-kernel-call.cl  | 43 +++
 clang/test/CodeGenOpenCL/reflect.cl   |  2 +-
 clang/test/CodeGenOpenCL/spir-calling-conv.cl |  4 +-
 clang/test/CodeGenOpenCL/visibility.cl| 53 ++-
 13 files changed, 160 insertions(+), 33 deletions(-)
 create mode 100644 clang/test/CodeGenOpenCL/opencl-kernel-call.cl

diff --git a/clang/include/clang/AST/GlobalDecl.h 
b/clang/include/clang/AST/GlobalDecl.h
index 386693cabb1fbb..8a9f4b4c60e5e5 100644
--- a/clang/include/clang/AST/GlobalDecl.h
+++ b/clang/include/clang/AST/GlobalDecl.h
@@ -71,6 +71,10 @@ class GlobalDecl {
   GlobalDecl(const FunctionDecl *D, unsigned MVIndex = 0)
   : MultiVersionIndex(MVIndex) {
 if (!D->hasAttr()) {
+  if (D->hasAttr()) {
+Value.setPointerAndInt(D, unsigned(KernelReferenceKind::Kernel));
+return;
+  }
   Init(D);
   return;
 }
@@ -78,7 +82,8 @@ class GlobalDecl {
   }
   GlobalDecl(const FunctionDecl *D, KernelReferenceKind Kind)
   : Value(D, unsigned(Kind)) {
-assert(D->hasAttr() && "Decl is not a GPU kernel!");
+assert((D->hasAttr() && "Decl is not a GPU kernel!") ||
+   (D->hasAttr() && "Decl is not a OpenCL kernel!"));
   }
   GlobalDecl(const NamedDecl *D) { Init(D); }
   GlobalDecl(const BlockDecl *D) { Init(D); }
@@ -130,13 +135,15 @@ class GlobalDecl {
   }
 
   KernelReferenceKind getKernelReferenceKind() const {
-assert(((isa(getDecl()) &&
- cast(getDecl())->hasAttr()) ||
-(isa(getDecl()) &&
- cast(getDecl())
- ->getTemplatedDecl()
- ->hasAttr())) &&
-   "Decl is not a GPU kernel!");
+assertisa(getDecl()) &&
+  cast(getDecl())->hasAttr()) ||
+ (isa(getDecl()) &&
+  cast(getDecl())
+  ->getTemplatedDecl()
+  ->hasAttr())) &&
+"Decl is not a GPU kernel!") ||
+   (isDeclOpenCLKernel() && "Decl is not a OpenCL kernel!"));
+
 return static_cast(Value.getInt());
   }
 
@@ -196,13 +203,21 @@ class GlobalDecl {
   }
 
   GlobalDecl getWithKernelReferenceKind(KernelReferenceKind Kind) {
-assert(isa(getDecl()) &&
-   cast(getDecl())->hasAttr() &&
-   "Decl is not a GPU kernel!");
+assert((isa(getDecl()) &&
+cast(getDecl())->hasAttr() &&
+"Decl is not a GPU kernel!") ||
+   (isDeclOpenCLKernel() && "Decl is not a OpenCL kernel!"));
 GlobalDecl Result(*this);
 Result.Value.setInt(unsigned(Kind));
 return Result;
   }
+
+  bool isDeclOpenCLKernel() const {
+auto FD = dyn_cast(getDecl());
+if (FD)
+  return FD->hasAttr();
+return FD;
+  }
 };
 
 } // namespace clang
diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index a4fb4d5a1f2ec4..ddd88ac6a21050 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -693,7 +693,8 @@ std::string PredefinedExpr::ComputeName(PredefinedIdentKind 
IK,
   GD = GlobalDecl(CD, Ctor_Base);
 else if (const CXXDestructorDecl *DD = dyn_cast(ND))
   GD = GlobalDecl(DD, Dtor_Base);
-else if (ND->hasAttr())
+else if (ND->hasAttr() ||
+ ND->hasAttr())
   GD = GlobalDecl(cast(ND));
 else
   GD = GlobalDecl(ND);
diff --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp
index 27a993a631dae9..7e46d6c520fb69 100644
--- a/clang/lib/AST/ItaniumMangle.cpp
+++ b/clang/lib/AST/ItaniumMangle.cpp
@@ -526,6 +526,7 @@ class CXXNameMangler {
   void mangleSourceName(const IdentifierInfo *II);
   void mangleRegCallName(const IdentifierInfo *II);
   void mangleDeviceStubName(const IdentifierInfo *II);
+  void mangleOCLDeviceStubName(const IdentifierInfo *II);
   void mangleSourceNameWithAbiTags(
   const NamedDecl *ND, const AbiTagList *AdditionalAbiTags = nullptr);

[clang] [Clang-REPL] Fix crash during `__run_exit_handlers` with dynamic libraries. (PR #117475)

2024-11-25 Thread via cfe-commits

SahilPatidar wrote:

I have added a test, but it should only run on Darwin (macOS) platforms.
```cpp
// REQUIRES: host-supports-jit

// RUN: cat %s | env SDKROOT=$(xcrun --show-sdk-path) 
DYLD_LIBRARY_PATH=%S/Inputs:$DYLD_LIBRARY_PATH clang-repl

%lib vec.dylib
#include 
std::vector v;
%quit

```

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


[clang] [clang][AArch64] Avoid a crash when a non-reserved register is used (PR #117419)

2024-11-25 Thread David Spickett via cfe-commits

DavidSpickett wrote:

Please check if this fixes https://github.com/llvm/llvm-project/issues/109778 
too. Seems very similar.

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


[clang] [Clang] Emit stub version of OpenCL Kernel (PR #115821)

2024-11-25 Thread Aniket Lal via cfe-commits


@@ -127,7 +127,10 @@ static const BlockExpr *getBlockExpr(const Expr *E) {
 void CGOpenCLRuntime::recordBlockInfo(const BlockExpr *E,
   llvm::Function *InvokeF,
   llvm::Value *Block, llvm::Type *BlockTy) 
{
-  assert(!EnqueuedBlockMap.contains(E) && "Block expression emitted twice");
+
+  // FIXME: Since OpenCL Kernels are emitted twice (kernel version and stub
+  // version), its constituent BlockExpr will also be emitted twice.
+  // assert(!EnqueuedBlockMap.contains(E) && "Block expression emitted twice");

lalaniket8 wrote:

If Kernel function contains BlockExpr, the BlockExpr *E is emitted twice (once 
during emission of kernel function and other while emission of its device 
variant). This leads to a failing assert which finds BlockExpr pointer E stored 
in EnqueuedBlockMap. 

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


[clang] [C++20][Modules] Load function body from the module that gives canonical decl (PR #111992)

2024-11-25 Thread Ilya Biryukov via cfe-commits

ilya-biryukov wrote:

> @ilya-biryukov unfortunately it seems that the reproducer is very sensitive 
> to the exact clang revision.

I should have clarified this better. It **does not** reproduce for me either 
with this example, but it's the exact code (and module structure) that causes 
the issue with our internal build system. I'm still trying to figure out which 
details I'm missing.

> The warning/error about "inline function not defined" is very familiar to me 
> and I'm reducing it now in our code...

I can confirm, we're definitely seeing a lot of them too when shaking up the 
build graph or seeing other Clang changes. This probably just surfaces some 
other error that we were lucky to avoid.

> In your example strong_int.h is not a part of its own module so clang merges 
> it and it causes issue for friend inside template class.

Right, and the different deserialization order is probably causing this error 
to resurface. This is actually a supported use-case for modules (it's possible 
to get the same effect with global module fragment in C++20 modules) and 
modularizing all functions that define these widely-used friend functions (like 
`AbslHashValue`) might be tough on our side.
My intuition is that we'd rather help fixing the underlying issues than go 
through this big refactoring for the whole codebase. Although, we'd need to see 
how hard that would be.

So far, I'm still focused on getting a proper repro and understanding what's 
going on exactly. After we have that, we can see whether fixing it is on the 
table.


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


[clang] [Clang] [Sema] Reject non-power-of-2 `_BitInt` matrix element types (PR #117487)

2024-11-25 Thread Florian Hahn via cfe-commits

https://github.com/fhahn commented:

Makes sense to me, but do we have tests that make sure codegen for matrixes 
with power-of-2 bitints is sane?

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


[clang-tools-extra] Rename CODE_OWNERS -> Maintainers (PR #114544)

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

5chmidti wrote:

@PiotrZSL The ping was in case you want to be added as a maintainer to 
clang-tidy as well. I’m mentioning it just to make sure.

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


[clang] [clang] Fix a crash issue that caused by handling of fields with initializers in nested anonymous unions (PR #113049)

2024-11-25 Thread Haojian Wu via cfe-commits

https://github.com/hokein commented:

Attaching an empty RecoveryExpr as an initializer to indicate that 
initialization was attempted but failed seems reasonable to me. I'll leave the 
approval to @efriedma-quic.

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


[clang-tools-extra] WIP: [clang-tidy] Add SmartPtrName to MakeSmartPtrCheck for flexible … (PR #117529)

2024-11-25 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-tidy

Author: Helmut Januschka (hjanuschka)


Changes

Introduced a `SmartPtrName` field in `MakeSmartPtrCheck` to allow matching on 
other smart pointer types, such as `base::scoped_refptr`, in addition to 
`std::shared_ptr`. This enables more versatile usage of the check without 
duplicating matcher logic.


WIP, TODO:
  - add test case.



```
#include 

namespace base {
template 
class scoped_refptr {
 public:
  explicit scoped_refptr(T* p) : ptr_(p) {}

  void reset(T* p) {
delete ptr_;
ptr_ = p;
  }

  // For demonstration purposes
  T* get() const { return ptr_; }

  ~scoped_refptr() {
delete ptr_;
  }

 private:
  T* ptr_;  // Raw pointer to the managed object
};

// Mock MakeRefCounted function
template 
scoped_refptr MakeRefCounted(Args&&... args) {
  return scoped_refptr(new T(std::forward(args)...));
}

class Foo {
 public:
  Foo() { std::cout << "Foo constructed.\n"; }
  ~Foo() { std::cout << "Foo destroyed.\n"; }
};

}  // namespace base

// Test case
int main() {
  auto ptr = base::MakeRefCounted();  // Create a scoped_refptr
  ptr.reset(new base::Foo());  // Reset with a new instance
  return 0;
}

```

works, but need to figure out why turning this into a llvm-lit does not work

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


5 Files Affected:

- (modified) clang-tools-extra/clang-tidy/modernize/MakeSharedCheck.cpp (+3-2) 
- (modified) clang-tools-extra/clang-tidy/modernize/MakeSharedCheck.h (+3) 
- (modified) clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp 
(+3-3) 
- (modified) clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.h (+1) 
- (modified) clang-tools-extra/docs/clang-tidy/checks/modernize/make-shared.rst 
(+6) 


``diff
diff --git a/clang-tools-extra/clang-tidy/modernize/MakeSharedCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/MakeSharedCheck.cpp
index 69f7d9f69eeed0..34009046fec6ae 100644
--- a/clang-tools-extra/clang-tidy/modernize/MakeSharedCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/MakeSharedCheck.cpp
@@ -16,13 +16,14 @@ using namespace clang::ast_matchers;
 namespace clang::tidy::modernize {
 
 MakeSharedCheck::MakeSharedCheck(StringRef Name, ClangTidyContext *Context)
-: MakeSmartPtrCheck(Name, Context, "std::make_shared") {}
+: MakeSmartPtrCheck(Name, Context, "std::make_shared"),
+  MakeSmartPtrType(Options.get("MakeSmartPtrType", "::std::shared_ptr")) {}
 
 MakeSharedCheck::SmartPtrTypeMatcher
 MakeSharedCheck::getSmartPointerTypeMatcher() const {
   return qualType(hasUnqualifiedDesugaredType(
   recordType(hasDeclaration(classTemplateSpecializationDecl(
-  hasName("::std::shared_ptr"), templateArgumentCountIs(1),
+  hasName(MakeSmartPtrType), templateArgumentCountIs(1),
   hasTemplateArgument(0, templateArgument(refersToType(
  qualType().bind(PointerType);
 }
diff --git a/clang-tools-extra/clang-tidy/modernize/MakeSharedCheck.h 
b/clang-tools-extra/clang-tidy/modernize/MakeSharedCheck.h
index caaf4ae403c34f..932796e3a147f1 100644
--- a/clang-tools-extra/clang-tidy/modernize/MakeSharedCheck.h
+++ b/clang-tools-extra/clang-tidy/modernize/MakeSharedCheck.h
@@ -26,6 +26,9 @@ namespace clang::tidy::modernize {
 /// For the user-facing documentation see:
 /// http://clang.llvm.org/extra/clang-tidy/checks/modernize/make-shared.html
 class MakeSharedCheck : public MakeSmartPtrCheck {
+private:
+  const StringRef MakeSmartPtrType;
+
 public:
   MakeSharedCheck(StringRef Name, ClangTidyContext *Context);
 
diff --git a/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp
index d1d7e9dcfa9c0d..3f77e6727d19f8 100644
--- a/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp
@@ -46,6 +46,7 @@ MakeSmartPtrCheck::MakeSmartPtrCheck(StringRef Name, 
ClangTidyContext *Context,
areDiagsSelfContained()),
   MakeSmartPtrFunctionHeader(
   Options.get("MakeSmartPtrFunctionHeader", "")),
+  MakeSmartPtrType(Options.get("MakeSmartPtrType", "::std::shared_ptr")),
   MakeSmartPtrFunctionName(
   Options.get("MakeSmartPtrFunction", MakeSmartPtrFunctionName)),
   IgnoreMacros(Options.getLocalOrGlobal("IgnoreMacros", true)),
@@ -55,6 +56,7 @@ MakeSmartPtrCheck::MakeSmartPtrCheck(StringRef Name, 
ClangTidyContext *Context,
 void MakeSmartPtrCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
   Options.store(Opts, "IncludeStyle", Inserter.getStyle());
   Options.store(Opts, "MakeSmartPtrFunctionHeader", 
MakeSmartPtrFunctionHeader);
+  Options.store(Opts, "MakeSmartPtrType", MakeSmartPtrType);
   Options.store(Opts, "MakeSmartPtrFunction", MakeSmartPtrFunctionName);
   Options.store(Opts, "IgnoreMacros", IgnoreMacros);
 

[clang-tools-extra] WIP: [clang-tidy] Add SmartPtrName to MakeSmartPtrCheck for flexible … (PR #117529)

2024-11-25 Thread Helmut Januschka via cfe-commits

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


[clang-tools-extra] WIP: [clang-tidy] Add SmartPtrName to MakeSmartPtrCheck for flexible … (PR #117529)

2024-11-25 Thread Helmut Januschka via cfe-commits

https://github.com/hjanuschka created 
https://github.com/llvm/llvm-project/pull/117529

Introduced a `SmartPtrName` field in `MakeSmartPtrCheck` to allow matching on 
other smart pointer types, such as `base::scoped_refptr`, in addition to 
`std::shared_ptr`. This enables more versatile usage of the check without 
duplicating matcher logic.


WIP, TODO:
  - add test case.



```
#include 

namespace base {
template 
class scoped_refptr {
 public:
  explicit scoped_refptr(T* p) : ptr_(p) {}

  void reset(T* p) {
delete ptr_;
ptr_ = p;
  }

  // For demonstration purposes
  T* get() const { return ptr_; }

  ~scoped_refptr() {
delete ptr_;
  }

 private:
  T* ptr_;  // Raw pointer to the managed object
};

// Mock MakeRefCounted function
template 
scoped_refptr MakeRefCounted(Args&&... args) {
  return scoped_refptr(new T(std::forward(args)...));
}

class Foo {
 public:
  Foo() { std::cout << "Foo constructed.\n"; }
  ~Foo() { std::cout << "Foo destroyed.\n"; }
};

}  // namespace base

// Test case
int main() {
  auto ptr = base::MakeRefCounted();  // Create a scoped_refptr
  ptr.reset(new base::Foo());  // Reset with a new instance
  return 0;
}

```

works, but need to figure out why turning this into a llvm-lit does not work

>From 9466fb73adfb050e9eac426459c18a7a5bca1982 Mon Sep 17 00:00:00 2001
From: Helmut Januschka 
Date: Mon, 25 Nov 2024 09:59:21 +0100
Subject: [PATCH] WIP: [clang-tidy] Add SmartPtrName to MakeSmartPtrCheck for
 flexible type matching

Introduced a `SmartPtrName` field in `MakeSmartPtrCheck` to allow matching on 
other smart pointer types, such as `base::scoped_refptr`, in addition to 
`std::shared_ptr`. This enables more versatile usage of the check without 
duplicating matcher logic.
---
 clang-tools-extra/clang-tidy/modernize/MakeSharedCheck.cpp  | 5 +++--
 clang-tools-extra/clang-tidy/modernize/MakeSharedCheck.h| 3 +++
 .../clang-tidy/modernize/MakeSmartPtrCheck.cpp  | 6 +++---
 clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.h  | 1 +
 .../docs/clang-tidy/checks/modernize/make-shared.rst| 6 ++
 5 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/modernize/MakeSharedCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/MakeSharedCheck.cpp
index 69f7d9f69eeed0..34009046fec6ae 100644
--- a/clang-tools-extra/clang-tidy/modernize/MakeSharedCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/MakeSharedCheck.cpp
@@ -16,13 +16,14 @@ using namespace clang::ast_matchers;
 namespace clang::tidy::modernize {
 
 MakeSharedCheck::MakeSharedCheck(StringRef Name, ClangTidyContext *Context)
-: MakeSmartPtrCheck(Name, Context, "std::make_shared") {}
+: MakeSmartPtrCheck(Name, Context, "std::make_shared"),
+  MakeSmartPtrType(Options.get("MakeSmartPtrType", "::std::shared_ptr")) {}
 
 MakeSharedCheck::SmartPtrTypeMatcher
 MakeSharedCheck::getSmartPointerTypeMatcher() const {
   return qualType(hasUnqualifiedDesugaredType(
   recordType(hasDeclaration(classTemplateSpecializationDecl(
-  hasName("::std::shared_ptr"), templateArgumentCountIs(1),
+  hasName(MakeSmartPtrType), templateArgumentCountIs(1),
   hasTemplateArgument(0, templateArgument(refersToType(
  qualType().bind(PointerType);
 }
diff --git a/clang-tools-extra/clang-tidy/modernize/MakeSharedCheck.h 
b/clang-tools-extra/clang-tidy/modernize/MakeSharedCheck.h
index caaf4ae403c34f..932796e3a147f1 100644
--- a/clang-tools-extra/clang-tidy/modernize/MakeSharedCheck.h
+++ b/clang-tools-extra/clang-tidy/modernize/MakeSharedCheck.h
@@ -26,6 +26,9 @@ namespace clang::tidy::modernize {
 /// For the user-facing documentation see:
 /// http://clang.llvm.org/extra/clang-tidy/checks/modernize/make-shared.html
 class MakeSharedCheck : public MakeSmartPtrCheck {
+private:
+  const StringRef MakeSmartPtrType;
+
 public:
   MakeSharedCheck(StringRef Name, ClangTidyContext *Context);
 
diff --git a/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp
index d1d7e9dcfa9c0d..3f77e6727d19f8 100644
--- a/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp
@@ -46,6 +46,7 @@ MakeSmartPtrCheck::MakeSmartPtrCheck(StringRef Name, 
ClangTidyContext *Context,
areDiagsSelfContained()),
   MakeSmartPtrFunctionHeader(
   Options.get("MakeSmartPtrFunctionHeader", "")),
+  MakeSmartPtrType(Options.get("MakeSmartPtrType", "::std::shared_ptr")),
   MakeSmartPtrFunctionName(
   Options.get("MakeSmartPtrFunction", MakeSmartPtrFunctionName)),
   IgnoreMacros(Options.getLocalOrGlobal("IgnoreMacros", true)),
@@ -55,6 +56,7 @@ MakeSmartPtrCheck::MakeSmartPtrCheck(StringRef Name, 
ClangTidyContext *Context,
 void MakeSmartPtrCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
   Options.store(Opts, "IncludeStyl

[clang-tools-extra] WIP: [clang-tidy] Add SmartPtrName to MakeSmartPtrCheck for flexible … (PR #117529)

2024-11-25 Thread via cfe-commits

github-actions[bot] wrote:



Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this 
page.

If this is not working for you, it is probably because you do not have write 
permissions for the repository. In which case you can instead tag reviewers by 
name in a comment by using `@` followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a 
review by "ping"ing the PR by adding a comment “Ping”. The common courtesy 
"ping" rate is once a week. Please remember that you are asking for valuable 
time from other developers.

If you have further questions, they may be answered by the [LLVM GitHub User 
Guide](https://llvm.org/docs/GitHub.html).

You can also ask questions in a comment on this PR, on the [LLVM 
Discord](https://discord.com/invite/xS7Z362) or on the 
[forums](https://discourse.llvm.org/).

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


[clang] [clang] Fix a crash issue that caused by handling of fields with initializers in nested anonymous unions (PR #113049)

2024-11-25 Thread Haojian Wu via cfe-commits


@@ -115,3 +115,14 @@ namespace nested_union {
   // of Test3, or we should exclude f(Test3) as a candidate.
   static_assert(f({1}) == 2, ""); // expected-error {{call to 'f' is 
ambiguous}}
 }
+
+// Fix crash issue https://github.com/llvm/llvm-project/issues/112560.
+// Make sure clang compiles the following code without crashing:
+namespace GH112560 {
+union U {
+  int f = ; // expected-error {{expected expression}}

hokein wrote:

Can you add an ast-dump testcase in `ast-dump-recovery.cpp` as well?

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


[clang] [Clang] use begin member expr location for call expr with deducing this (PR #117345)

2024-11-25 Thread Younan Zhang via cfe-commits

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

LGTM modulo a release note.

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


[clang-tools-extra] WIP: [clang-tidy] Add SmartPtrName to MakeSmartPtrCheck for flexible … (PR #117529)

2024-11-25 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-tools-extra

Author: Helmut Januschka (hjanuschka)


Changes

Introduced a `SmartPtrName` field in `MakeSmartPtrCheck` to allow matching on 
other smart pointer types, such as `base::scoped_refptr`, in addition to 
`std::shared_ptr`. This enables more versatile usage of the check without 
duplicating matcher logic.


WIP, TODO:
  - add test case.



```
#include 

namespace base {
template 
class scoped_refptr {
 public:
  explicit scoped_refptr(T* p) : ptr_(p) {}

  void reset(T* p) {
delete ptr_;
ptr_ = p;
  }

  // For demonstration purposes
  T* get() const { return ptr_; }

  ~scoped_refptr() {
delete ptr_;
  }

 private:
  T* ptr_;  // Raw pointer to the managed object
};

// Mock MakeRefCounted function
template 
scoped_refptr MakeRefCounted(Args&&... args) {
  return scoped_refptr(new T(std::forward(args)...));
}

class Foo {
 public:
  Foo() { std::cout << "Foo constructed.\n"; }
  ~Foo() { std::cout << "Foo destroyed.\n"; }
};

}  // namespace base

// Test case
int main() {
  auto ptr = base::MakeRefCounted();  // Create a scoped_refptr
  ptr.reset(new base::Foo());  // Reset with a new instance
  return 0;
}

```

works, but need to figure out why turning this into a llvm-lit does not work

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


5 Files Affected:

- (modified) clang-tools-extra/clang-tidy/modernize/MakeSharedCheck.cpp (+3-2) 
- (modified) clang-tools-extra/clang-tidy/modernize/MakeSharedCheck.h (+3) 
- (modified) clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp 
(+3-3) 
- (modified) clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.h (+1) 
- (modified) clang-tools-extra/docs/clang-tidy/checks/modernize/make-shared.rst 
(+6) 


``diff
diff --git a/clang-tools-extra/clang-tidy/modernize/MakeSharedCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/MakeSharedCheck.cpp
index 69f7d9f69eeed0..34009046fec6ae 100644
--- a/clang-tools-extra/clang-tidy/modernize/MakeSharedCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/MakeSharedCheck.cpp
@@ -16,13 +16,14 @@ using namespace clang::ast_matchers;
 namespace clang::tidy::modernize {
 
 MakeSharedCheck::MakeSharedCheck(StringRef Name, ClangTidyContext *Context)
-: MakeSmartPtrCheck(Name, Context, "std::make_shared") {}
+: MakeSmartPtrCheck(Name, Context, "std::make_shared"),
+  MakeSmartPtrType(Options.get("MakeSmartPtrType", "::std::shared_ptr")) {}
 
 MakeSharedCheck::SmartPtrTypeMatcher
 MakeSharedCheck::getSmartPointerTypeMatcher() const {
   return qualType(hasUnqualifiedDesugaredType(
   recordType(hasDeclaration(classTemplateSpecializationDecl(
-  hasName("::std::shared_ptr"), templateArgumentCountIs(1),
+  hasName(MakeSmartPtrType), templateArgumentCountIs(1),
   hasTemplateArgument(0, templateArgument(refersToType(
  qualType().bind(PointerType);
 }
diff --git a/clang-tools-extra/clang-tidy/modernize/MakeSharedCheck.h 
b/clang-tools-extra/clang-tidy/modernize/MakeSharedCheck.h
index caaf4ae403c34f..932796e3a147f1 100644
--- a/clang-tools-extra/clang-tidy/modernize/MakeSharedCheck.h
+++ b/clang-tools-extra/clang-tidy/modernize/MakeSharedCheck.h
@@ -26,6 +26,9 @@ namespace clang::tidy::modernize {
 /// For the user-facing documentation see:
 /// http://clang.llvm.org/extra/clang-tidy/checks/modernize/make-shared.html
 class MakeSharedCheck : public MakeSmartPtrCheck {
+private:
+  const StringRef MakeSmartPtrType;
+
 public:
   MakeSharedCheck(StringRef Name, ClangTidyContext *Context);
 
diff --git a/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp
index d1d7e9dcfa9c0d..3f77e6727d19f8 100644
--- a/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp
@@ -46,6 +46,7 @@ MakeSmartPtrCheck::MakeSmartPtrCheck(StringRef Name, 
ClangTidyContext *Context,
areDiagsSelfContained()),
   MakeSmartPtrFunctionHeader(
   Options.get("MakeSmartPtrFunctionHeader", "")),
+  MakeSmartPtrType(Options.get("MakeSmartPtrType", "::std::shared_ptr")),
   MakeSmartPtrFunctionName(
   Options.get("MakeSmartPtrFunction", MakeSmartPtrFunctionName)),
   IgnoreMacros(Options.getLocalOrGlobal("IgnoreMacros", true)),
@@ -55,6 +56,7 @@ MakeSmartPtrCheck::MakeSmartPtrCheck(StringRef Name, 
ClangTidyContext *Context,
 void MakeSmartPtrCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
   Options.store(Opts, "IncludeStyle", Inserter.getStyle());
   Options.store(Opts, "MakeSmartPtrFunctionHeader", 
MakeSmartPtrFunctionHeader);
+  Options.store(Opts, "MakeSmartPtrType", MakeSmartPtrType);
   Options.store(Opts, "MakeSmartPtrFunction", MakeSmartPtrFunctionName);
   Options.store(Opts, "IgnoreMacros", IgnoreMac

[clang] [Clang] [Sema] Reject non-power-of-2 `_BitInt` matrix element types (PR #117487)

2024-11-25 Thread Mariya Podchishchaeva via cfe-commits


@@ -2312,6 +2312,18 @@ QualType Sema::BuildArrayType(QualType T, 
ArraySizeModifier ASM,
   return T;
 }
 
+bool CheckBitIntElementType(Sema &S, SourceLocation AttrLoc,
+const BitIntType *BIT, bool ForMatrixType = false) 
{
+  // Only support _BitInt elements with byte-sized power of 2 NumBits.
+  unsigned NumBits = BIT->getNumBits();
+  if (!llvm::isPowerOf2_32(NumBits) || NumBits < 8) {
+S.Diag(AttrLoc, diag::err_attribute_invalid_bitint_vector_type)
+<< ForMatrixType << (NumBits < 8);
+return true;

Fznamznon wrote:

AFAIK you can do
```suggestion
return S.Diag(AttrLoc, diag::err_attribute_invalid_bitint_vector_type)
<< ForMatrixType << (NumBits < 8);
```

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


[clang] [Clang] [Sema] Reject non-power-of-2 `_BitInt` matrix element types (PR #117487)

2024-11-25 Thread Mariya Podchishchaeva via cfe-commits

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


[clang] [Clang] [Sema] Reject non-power-of-2 `_BitInt` matrix element types (PR #117487)

2024-11-25 Thread Mariya Podchishchaeva via cfe-commits


@@ -2455,6 +2456,10 @@ QualType Sema::BuildMatrixType(QualType ElementTy, Expr 
*NumRows, Expr *NumCols,
 return QualType();
   }
 
+  if (const auto *BIT = ElementTy->getAs();
+  BIT && CheckBitIntElementType(*this, AttrLoc, BIT, true))

Fznamznon wrote:

```suggestion
  BIT && CheckBitIntElementType(*this, AttrLoc, BIT, 
/*ForMatrixType=*/true))
```


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


[clang] [Clang] [Sema] Reject non-power-of-2 `_BitInt` matrix element types (PR #117487)

2024-11-25 Thread Mariya Podchishchaeva via cfe-commits

https://github.com/Fznamznon commented:

It feels like that the non-power-of-2 _BitInt vectors were disabled because it 
wasn't known how to handle them. https://reviews.llvm.org/D133634#3793653
It probably is still so, however, does it make sense to document the new 
behavior? 
Hopefully also, since this never worked properly, this is not a breaking change.

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


[clang-tools-extra] [clangd] Support outgoing calls in call hierarchy (PR #77556)

2024-11-25 Thread Igor V. Kovalenko via cfe-commits


@@ -1700,6 +1700,7 @@ declToHierarchyItem(const NamedDecl &ND, llvm::StringRef 
TUPath) {
 
   HierarchyItem HI;
   HI.name = printName(Ctx, ND);
+  // FIXME: Populate HI.detail the way we do in symbolToHierarchyItem?

i-garrison wrote:

I see. Ideally there should be some recommended use model for `c++` which call 
hierarchy clients/visualisers (e.g. lsp4e) could implement to show expected 
function signatures. Like "obtain details field from call hierarchy item and 
use it as function signature" and then lsp4e could append details to name. We 
probably can later tune xrefs.cpp implementation to provide required details 
where needed. Note that function return value is still not available, and as 
far as I can see there is no place in protocol to put it in.

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


[clang] [llvm] [AArch64][SVE] Change the immediate argument in svextq (PR #115340)

2024-11-25 Thread via cfe-commits

SpencerAbson wrote:

@aemerson Planning to land this today as long as that is fine with your folk?

Thanks

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


[clang-tools-extra] [clangd] Support outgoing calls in call hierarchy (PR #77556)

2024-11-25 Thread Igor V. Kovalenko via cfe-commits

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


[clang] [clang-tools-extra] [analyzer] Remove alpha.core.IdenticalExpr Checker (PR #114715)

2024-11-25 Thread via cfe-commits


@@ -102,6 +102,210 @@ void BranchCloneCheck::registerMatchers(MatchFinder 
*Finder) {
   this);
   Finder->addMatcher(switchStmt().bind("switch"), this);
   Finder->addMatcher(conditionalOperator().bind("condOp"), this);
+  
Finder->addMatcher(ifStmt(hasDescendant(ifStmt())).bind("ifWithDescendantIf"),

vabridgers wrote:

Thanks @5chmidti. I think I had resolved the comment from @HerrCai0907 by 
narrowing the match. Would you agree that's sufficient, or would you like to 
see an improvement in this area before moving forward here? Thanks

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


[clang] 48ec59c - [llvm][AMDGPU] Fold `llvm.amdgcn.wavefrontsize` early (#114481)

2024-11-25 Thread via cfe-commits

Author: Alex Voicu
Date: 2024-11-25T10:29:50Z
New Revision: 48ec59c234ce267a0454b15e9a79a326e21a4a97

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

LOG: [llvm][AMDGPU] Fold `llvm.amdgcn.wavefrontsize` early (#114481)

Fold `llvm.amdgcn.wavefrontsize` early, during InstCombine, so that it's
concrete value is used throughout subsequent optimisation passes.

Added: 
llvm/test/Transforms/InstCombine/AMDGPU/llvm.amdgcn.wavefrontsize.ll

Modified: 
clang/test/CodeGenOpenCL/builtins-amdgcn.cl
llvm/lib/Target/AMDGPU/AMDGPUInstCombineIntrinsic.cpp
llvm/test/CodeGen/AMDGPU/llvm.amdgcn.wavefrontsize.ll

Removed: 




diff  --git a/clang/test/CodeGenOpenCL/builtins-amdgcn.cl 
b/clang/test/CodeGenOpenCL/builtins-amdgcn.cl
index 3bc6107b7fd40d..c22a43146a8c89 100644
--- a/clang/test/CodeGenOpenCL/builtins-amdgcn.cl
+++ b/clang/test/CodeGenOpenCL/builtins-amdgcn.cl
@@ -1,6 +1,6 @@
 // REQUIRES: amdgpu-registered-target
 // RUN: %clang_cc1 -cl-std=CL2.0 -triple amdgcn-unknown-unknown -target-cpu 
tahiti -emit-llvm -o - %s | FileCheck -enable-var-scope 
--check-prefixes=CHECK-AMDGCN,CHECK %s
-// RUN: %clang_cc1 -cl-std=CL2.0 -triple spirv64-amd-amdhsa -emit-llvm -o - %s 
| FileCheck -enable-var-scope --check-prefix=CHECK %s
+// RUN: %clang_cc1 -cl-std=CL2.0 -triple spirv64-amd-amdhsa -emit-llvm -o - %s 
| FileCheck -enable-var-scope --check-prefixes=CHECK,CHECK-SPIRV %s
 
 
 #pragma OPENCL EXTENSION cl_khr_fp64 : enable
@@ -866,7 +866,8 @@ void test_atomic_inc_dec(__attribute__((address_space(3))) 
uint *lptr, __attribu
 // CHECK-LABEL test_wavefrontsize(
 unsigned test_wavefrontsize() {
 
-  // CHECK: {{.*}}call{{.*}} i32 @llvm.amdgcn.wavefrontsize()
+  // CHECK-AMDGCN: ret i32 {{[0-9]+}}
+  // CHECK-SPIRV: {{.*}}call{{.*}} i32 @llvm.amdgcn.wavefrontsize()
   return __builtin_amdgcn_wavefrontsize();
 }
 

diff  --git a/llvm/lib/Target/AMDGPU/AMDGPUInstCombineIntrinsic.cpp 
b/llvm/lib/Target/AMDGPU/AMDGPUInstCombineIntrinsic.cpp
index 087de1bed86f76..18a09c39a06387 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUInstCombineIntrinsic.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPUInstCombineIntrinsic.cpp
@@ -1024,6 +1024,12 @@ GCNTTIImpl::instCombineIntrinsic(InstCombiner &IC, 
IntrinsicInst &II) const {
 }
 break;
   }
+  case Intrinsic::amdgcn_wavefrontsize: {
+if (ST->isWaveSizeKnown())
+  return IC.replaceInstUsesWith(
+  II, ConstantInt::get(II.getType(), ST->getWavefrontSize()));
+break;
+  }
   case Intrinsic::amdgcn_wqm_vote: {
 // wqm_vote is identity when the argument is constant.
 if (!isa(II.getArgOperand(0)))

diff  --git a/llvm/test/CodeGen/AMDGPU/llvm.amdgcn.wavefrontsize.ll 
b/llvm/test/CodeGen/AMDGPU/llvm.amdgcn.wavefrontsize.ll
index 824d3708c027db..33dd2bd540ad06 100644
--- a/llvm/test/CodeGen/AMDGPU/llvm.amdgcn.wavefrontsize.ll
+++ b/llvm/test/CodeGen/AMDGPU/llvm.amdgcn.wavefrontsize.ll
@@ -4,29 +4,15 @@
 ; RUN: llc -mtriple=amdgcn -mcpu=gfx1100 -mattr=+wavefrontsize32 
-verify-machineinstrs -amdgpu-enable-vopd=0 < %s | FileCheck 
-check-prefixes=GCN,W32 %s
 ; RUN: llc -mtriple=amdgcn -mcpu=gfx1100 -mattr=+wavefrontsize64 
-verify-machineinstrs < %s | FileCheck -check-prefixes=GCN,W64 %s
 
-; RUN: opt -O3 -S < %s | FileCheck -check-prefix=OPT %s
-; RUN: opt -mtriple=amdgcn-- -O3 -S < %s | FileCheck -check-prefix=OPT %s
-; RUN: opt -mtriple=amdgcn-- -O3 -mattr=+wavefrontsize32 -S < %s | FileCheck 
-check-prefix=OPT %s
-; RUN: opt -mtriple=amdgcn-- -passes='default' -mattr=+wavefrontsize32 -S 
< %s | FileCheck -check-prefix=OPT %s
-; RUN: opt -mtriple=amdgcn-- -O3 -mattr=+wavefrontsize64 -S < %s | FileCheck 
-check-prefix=OPT %s
-; RUN: opt -mtriple=amdgcn-- -mcpu=tonga -O3 -S < %s | FileCheck 
-check-prefix=OPT %s
-; RUN: opt -mtriple=amdgcn-- -mcpu=gfx1010 -O3 -mattr=+wavefrontsize32 -S < %s 
| FileCheck -check-prefix=OPT %s
-; RUN: opt -mtriple=amdgcn-- -mcpu=gfx1010 -O3 -mattr=+wavefrontsize64 -S < %s 
| FileCheck -check-prefix=OPT %s
-; RUN: opt -mtriple=amdgcn-- -mcpu=gfx1100 -O3 -mattr=+wavefrontsize32 -S < %s 
| FileCheck -check-prefix=OPT %s
-; RUN: opt -mtriple=amdgcn-- -mcpu=gfx1100 -O3 -mattr=+wavefrontsize64 -S < %s 
| FileCheck -check-prefix=OPT %s
-
 ; GCN-LABEL: {{^}}fold_wavefrontsize:
-; OPT-LABEL: define amdgpu_kernel void @fold_wavefrontsize(
 
 ; W32:   v_mov_b32_e32 [[V:v[0-9]+]], 32
 ; W64:   v_mov_b32_e32 [[V:v[0-9]+]], 64
 ; GCN:   store_{{dword|b32}} v{{.+}}, [[V]]
 
-; OPT:   %tmp = tail call i32 @llvm.amdgcn.wavefrontsize()
-; OPT:   store i32 %tmp, ptr addrspace(1) %arg, align 4
-; OPT-NEXT:  ret void
 
 define amdgpu_kernel void @fold_wavefrontsize(ptr addrspace(1) nocapture %arg) 
{
+
 bb:
   %tmp = tail call i32 @llvm.amdgcn.wavefrontsize() #0
   store i32 %tmp, ptr addrspace(1) %arg, align 4
@@ -34,18

[clang] [llvm] [llvm][AMDGPU] Fold `llvm.amdgcn.wavefrontsize` early (PR #114481)

2024-11-25 Thread Alex Voicu via cfe-commits

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


[clang] 612f8ec - seq_cst is allowed in Flush since OpenMP 5.1. (#114072)

2024-11-25 Thread via cfe-commits

Author: ShashwathiNavada
Date: 2024-11-25T16:08:39+05:30
New Revision: 612f8ec7ac5dcddd16fb027aad64e2e353faa528

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

LOG: seq_cst is allowed in Flush since OpenMP 5.1. (#114072)

This PR adds support seq_cst (sequential consistency) clause for the
flush directive in OpenMP. The seq_cst clause enforces a stricter memory
ordering, ensuring that all threads observe the memory effects of the
flush in the same order, improving consistency in memory operations
across threads.

-

Co-authored-by: Shashwathi N 
Co-authored-by: CHANDRA GHALE 

Added: 
flang/test/Lower/OpenMP/Todo/flush-seq-cst.f90

Modified: 
clang/docs/OpenMPSupport.rst
clang/include/clang/AST/OpenMPClause.h
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaOpenMP.cpp
clang/test/OpenMP/flush_ast_print.cpp
clang/test/OpenMP/flush_codegen.cpp
clang/test/OpenMP/flush_messages.cpp
flang/test/Semantics/OpenMP/clause-validity01.f90
flang/test/Semantics/OpenMP/flush02.f90
llvm/include/llvm/Frontend/OpenMP/OMP.td

Removed: 




diff  --git a/clang/docs/OpenMPSupport.rst b/clang/docs/OpenMPSupport.rst
index 3f996ceaff156c..481362dba3f51d 100644
--- a/clang/docs/OpenMPSupport.rst
+++ b/clang/docs/OpenMPSupport.rst
@@ -290,7 +290,7 @@ implementation.
 
+--+--+--+---+
 | memory management| changes to omp_alloctrait_key enum
   | :none:`unclaimed`| 
  |
 
+--+--+--+---+
-| memory model | seq_cst clause on flush construct 
   | :none:`unclaimed`| 
  |
+| memory model | seq_cst clause on flush construct 
   | :good:`done` | 
https://github.com/llvm/llvm-project/pull/114072  |
 
+--+--+--+---+
 | misc | 'omp_all_memory' keyword and use in 'depend' 
clause  | :good:`done` | D125828, D126321   
   |
 
+--+--+--+---+

diff  --git a/clang/include/clang/AST/OpenMPClause.h 
b/clang/include/clang/AST/OpenMPClause.h
index 00c87e71bde31b..d2f5267e4da5ea 100644
--- a/clang/include/clang/AST/OpenMPClause.h
+++ b/clang/include/clang/AST/OpenMPClause.h
@@ -2670,8 +2670,8 @@ class OMPCompareClause final : public OMPClause {
   }
 };
 
-/// This represents 'seq_cst' clause in the '#pragma omp atomic'
-/// directive.
+/// This represents 'seq_cst' clause in the '#pragma omp atomic|flush'
+/// directives.
 ///
 /// \code
 /// #pragma omp atomic seq_cst

diff  --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index eb05a6a77978af..6ff24c2bc8faad 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -11396,7 +11396,7 @@ def err_omp_atomic_weak_no_equality : Error<"expected 
'==' operator for 'weak' c
 def err_omp_atomic_several_clauses : Error<
   "directive '#pragma omp atomic' cannot contain more than one 'read', 
'write', 'update', 'capture', or 'compare' clause">;
 def err_omp_several_mem_order_clauses : Error<
-  "directive '#pragma omp %0' cannot contain more than one %select{'seq_cst', 
'relaxed', |}1'acq_rel', 'acquire' or 'release' clause">;
+  "directive '#pragma omp %0' cannot contain more than one 'seq_cst',%select{ 
'relaxed',|}1 'acq_rel', 'acquire' or 'release' clause">;
 def err_omp_atomic_incompatible_mem_order_clause : Error<
   "directive '#pragma omp atomic%select{ %0|}1' cannot be used with '%2' 
clause">;
 def note_omp_previous_mem_order_clause : Note<

diff  --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 5d6b835e6da82e..976d48e1249136 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -11102,7 +11102,8 @@ StmtResult 
SemaOpenMP::ActOnOpenMPFlushDirective

[clang] [flang] [llvm] seq_cst is allowed in Flush since OpenMP 5.1. (PR #114072)

2024-11-25 Thread via cfe-commits

github-actions[bot] wrote:



@ShashwathiNavada Congratulations on having your first Pull Request (PR) merged 
into the LLVM Project!

Your changes will be combined with recent changes from other authors, then 
tested by our [build bots](https://lab.llvm.org/buildbot/). If there is a 
problem with a build, you may receive a report in an email or a comment on this 
PR.

Please check whether problems have been caused by your change specifically, as 
the builds can include changes from many authors. It is not uncommon for your 
change to be included in a build that fails due to someone else's changes, or 
infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail 
[here](https://llvm.org/docs/MyFirstTypoFix.html#myfirsttypofix-issues-after-landing-your-pr).

If your change does cause a problem, it may be reverted, or you can revert it 
yourself. This is a normal part of [LLVM 
development](https://llvm.org/docs/DeveloperPolicy.html#patch-reversion-policy).
 You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are 
working as expected, well done!


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


[clang] [flang] [llvm] seq_cst is allowed in Flush since OpenMP 5.1. (PR #114072)

2024-11-25 Thread CHANDRA GHALE via cfe-commits

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


[clang-tools-extra] WIP: [clang-tidy] Add SmartPtrName to MakeSmartPtrCheck for flexible … (PR #117529)

2024-11-25 Thread Helmut Januschka via cfe-commits

https://github.com/hjanuschka updated 
https://github.com/llvm/llvm-project/pull/117529

>From 9466fb73adfb050e9eac426459c18a7a5bca1982 Mon Sep 17 00:00:00 2001
From: Helmut Januschka 
Date: Mon, 25 Nov 2024 09:59:21 +0100
Subject: [PATCH 1/2] WIP: [clang-tidy] Add SmartPtrName to MakeSmartPtrCheck
 for flexible type matching

Introduced a `SmartPtrName` field in `MakeSmartPtrCheck` to allow matching on 
other smart pointer types, such as `base::scoped_refptr`, in addition to 
`std::shared_ptr`. This enables more versatile usage of the check without 
duplicating matcher logic.
---
 clang-tools-extra/clang-tidy/modernize/MakeSharedCheck.cpp  | 5 +++--
 clang-tools-extra/clang-tidy/modernize/MakeSharedCheck.h| 3 +++
 .../clang-tidy/modernize/MakeSmartPtrCheck.cpp  | 6 +++---
 clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.h  | 1 +
 .../docs/clang-tidy/checks/modernize/make-shared.rst| 6 ++
 5 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/modernize/MakeSharedCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/MakeSharedCheck.cpp
index 69f7d9f69eeed0..34009046fec6ae 100644
--- a/clang-tools-extra/clang-tidy/modernize/MakeSharedCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/MakeSharedCheck.cpp
@@ -16,13 +16,14 @@ using namespace clang::ast_matchers;
 namespace clang::tidy::modernize {
 
 MakeSharedCheck::MakeSharedCheck(StringRef Name, ClangTidyContext *Context)
-: MakeSmartPtrCheck(Name, Context, "std::make_shared") {}
+: MakeSmartPtrCheck(Name, Context, "std::make_shared"),
+  MakeSmartPtrType(Options.get("MakeSmartPtrType", "::std::shared_ptr")) {}
 
 MakeSharedCheck::SmartPtrTypeMatcher
 MakeSharedCheck::getSmartPointerTypeMatcher() const {
   return qualType(hasUnqualifiedDesugaredType(
   recordType(hasDeclaration(classTemplateSpecializationDecl(
-  hasName("::std::shared_ptr"), templateArgumentCountIs(1),
+  hasName(MakeSmartPtrType), templateArgumentCountIs(1),
   hasTemplateArgument(0, templateArgument(refersToType(
  qualType().bind(PointerType);
 }
diff --git a/clang-tools-extra/clang-tidy/modernize/MakeSharedCheck.h 
b/clang-tools-extra/clang-tidy/modernize/MakeSharedCheck.h
index caaf4ae403c34f..932796e3a147f1 100644
--- a/clang-tools-extra/clang-tidy/modernize/MakeSharedCheck.h
+++ b/clang-tools-extra/clang-tidy/modernize/MakeSharedCheck.h
@@ -26,6 +26,9 @@ namespace clang::tidy::modernize {
 /// For the user-facing documentation see:
 /// http://clang.llvm.org/extra/clang-tidy/checks/modernize/make-shared.html
 class MakeSharedCheck : public MakeSmartPtrCheck {
+private:
+  const StringRef MakeSmartPtrType;
+
 public:
   MakeSharedCheck(StringRef Name, ClangTidyContext *Context);
 
diff --git a/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp
index d1d7e9dcfa9c0d..3f77e6727d19f8 100644
--- a/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/MakeSmartPtrCheck.cpp
@@ -46,6 +46,7 @@ MakeSmartPtrCheck::MakeSmartPtrCheck(StringRef Name, 
ClangTidyContext *Context,
areDiagsSelfContained()),
   MakeSmartPtrFunctionHeader(
   Options.get("MakeSmartPtrFunctionHeader", "")),
+  MakeSmartPtrType(Options.get("MakeSmartPtrType", "::std::shared_ptr")),
   MakeSmartPtrFunctionName(
   Options.get("MakeSmartPtrFunction", MakeSmartPtrFunctionName)),
   IgnoreMacros(Options.getLocalOrGlobal("IgnoreMacros", true)),
@@ -55,6 +56,7 @@ MakeSmartPtrCheck::MakeSmartPtrCheck(StringRef Name, 
ClangTidyContext *Context,
 void MakeSmartPtrCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
   Options.store(Opts, "IncludeStyle", Inserter.getStyle());
   Options.store(Opts, "MakeSmartPtrFunctionHeader", 
MakeSmartPtrFunctionHeader);
+  Options.store(Opts, "MakeSmartPtrType", MakeSmartPtrType);
   Options.store(Opts, "MakeSmartPtrFunction", MakeSmartPtrFunctionName);
   Options.store(Opts, "IgnoreMacros", IgnoreMacros);
   Options.store(Opts, "IgnoreDefaultInitialization",
@@ -115,7 +117,6 @@ void MakeSmartPtrCheck::check(const 
MatchFinder::MatchResult &Result) {
   // 'smart_ptr' refers to 'std::shared_ptr' or 'std::unique_ptr' or other
   // pointer, 'make_smart_ptr' refers to 'std::make_shared' or
   // 'std::make_unique' or other function that creates smart_ptr.
-
   SourceManager &SM = *Result.SourceManager;
   const auto *Construct =
   Result.Nodes.getNodeAs(ConstructorCall);
@@ -361,8 +362,7 @@ bool MakeSmartPtrCheck::replaceNew(DiagnosticBuilder &Diag,
   Diag << FixItHint::CreateRemoval(
   SourceRange(NewStart, InitRange.getBegin()));
   Diag << FixItHint::CreateRemoval(SourceRange(InitRange.getEnd(), 
NewEnd));
-}
-else {
+} else {
   // New array expression with default/value initialization:
   //   smart_ptr(new int[5]

[libclc] [libclc] Move sign to the CLC builtins library (PR #115699)

2024-11-25 Thread Fraser Cormack via cfe-commits


@@ -0,0 +1,38 @@
+#include 
+#include 
+#include 
+
+#define CLC_SIGN(TYPE, F)  
\
+  _CLC_DEF _CLC_OVERLOAD TYPE __clc_sign(TYPE x) { 
\
+if (__clc_isnan(x)) {  
\
+  return 0.0F; 
\
+}  
\
+if (x > 0.0F) {
\
+  return 1.0F; 
\
+}  
\
+if (x < 0.0F) {
\
+  return -1.0F;
\
+}  
\
+return x; /* -0.0 or +0.0 */   
\

frasercrmck wrote:

True, my mistake. Forgetting the NaNs, though, my first sentence holds: 
`copysign(0.0, x < 0.0)` doesn't return `1.0` if `x > 0` nor `-1.0` if `x < 0` 
as OpenCL's `sign` is required to. I'm assuming you're saying `float sign(float 
x) { return copysign(0.0, x < 0); }` is a correct implementation of `sign`.

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


[clang-tools-extra] [clangd] Support outgoing calls in call hierarchy (PR #77556)

2024-11-25 Thread Christian Kandeler via cfe-commits

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

Appears to work fine.
Regarding the slight memory increase: If anyone feels strongly about it, they 
had plenty of time to chime in.

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


[clang] [llvm] AMDGPU: Add support for load transpose instructions for gfx950 (PR #117378)

2024-11-25 Thread Matt Arsenault via cfe-commits

https://github.com/arsenm updated 
https://github.com/llvm/llvm-project/pull/117378

>From 0faa36e6240f21d77d94e981712f4b57bc4b5d11 Mon Sep 17 00:00:00 2001
From: Sirish Pande 
Date: Wed, 7 Feb 2024 10:12:03 -0600
Subject: [PATCH] AMDGPU: Add support for load transpose instructions for
 gfx950

This patch support for intrinsics in clang, as well as assembly
instructions in the backend.

Co-authored-by: Sirish Pande 
---
 clang/include/clang/Basic/BuiltinsAMDGPU.def  |   5 +
 clang/lib/CodeGen/CGBuiltin.cpp   |  19 ++-
 .../builtins-amdgcn-gfx950-read-tr.cl |  50 
 llvm/include/llvm/IR/IntrinsicsAMDGPU.td  |   4 +
 .../Target/AMDGPU/AMDGPURegisterBankInfo.cpp  |   4 +
 .../Target/AMDGPU/AMDGPUSearchableTables.td   |   5 +
 llvm/lib/Target/AMDGPU/DSInstructions.td  |  33 ++
 llvm/lib/Target/AMDGPU/SIISelLowering.cpp |  10 +-
 .../UniformityAnalysis/AMDGPU/intrinsics.ll   |  44 +++
 .../AMDGPU/llvm.amdgcn.ds.read.tr.gfx950.ll   | 108 ++
 llvm/test/MC/AMDGPU/gfx950-unsupported.s  |  77 +
 llvm/test/MC/AMDGPU/gfx950_asm_read_tr.s  |  34 ++
 .../AMDGPU/gfx950_dasm_ds_read_tr.txt |  37 ++
 13 files changed, 427 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/CodeGenOpenCL/builtins-amdgcn-gfx950-read-tr.cl
 create mode 100644 llvm/test/CodeGen/AMDGPU/llvm.amdgcn.ds.read.tr.gfx950.ll
 create mode 100644 llvm/test/MC/AMDGPU/gfx950_asm_read_tr.s
 create mode 100644 llvm/test/MC/Disassembler/AMDGPU/gfx950_dasm_ds_read_tr.txt

diff --git a/clang/include/clang/Basic/BuiltinsAMDGPU.def 
b/clang/include/clang/Basic/BuiltinsAMDGPU.def
index 548bcc8ad55f48..a42ad56ce4f998 100644
--- a/clang/include/clang/Basic/BuiltinsAMDGPU.def
+++ b/clang/include/clang/Basic/BuiltinsAMDGPU.def
@@ -462,6 +462,11 @@ 
TARGET_BUILTIN(__builtin_amdgcn_smfmac_f32_32x32x64_fp8_fp8, "V16fV4iV8iV16fiIiI
 TARGET_BUILTIN(__builtin_amdgcn_permlane16_swap, "V2UiUiUiIbIb", "nc", 
"permlane16-swap")
 TARGET_BUILTIN(__builtin_amdgcn_permlane32_swap, "V2UiUiUiIbIb", "nc", 
"permlane32-swap")
 
+TARGET_BUILTIN(__builtin_amdgcn_ds_read_tr4_b64_v2i32, "V2iV2i*3", "nc", 
"gfx950-insts")
+TARGET_BUILTIN(__builtin_amdgcn_ds_read_tr6_b96_v3i32, "V3iV3i*3", "nc", 
"gfx950-insts")
+TARGET_BUILTIN(__builtin_amdgcn_ds_read_tr8_b64_v2i32, "V2iV2i*3", "nc", 
"gfx950-insts")
+TARGET_BUILTIN(__builtin_amdgcn_ds_read_tr16_b64_v4i16, "V4sV4s*3", "nc", 
"gfx950-insts")
+
 
//===--===//
 // GFX12+ only builtins.
 
//===--===//
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 3db439c87fa326..91b70b4fdf3d20 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -19697,8 +19697,11 @@ Value *CodeGenFunction::EmitAMDGPUBuiltinExpr(unsigned 
BuiltinID,
   case AMDGPU::BI__builtin_amdgcn_global_load_tr_b128_v4bf16:
   case AMDGPU::BI__builtin_amdgcn_global_load_tr_b128_v8i16:
   case AMDGPU::BI__builtin_amdgcn_global_load_tr_b128_v8f16:
-  case AMDGPU::BI__builtin_amdgcn_global_load_tr_b128_v8bf16: {
-
+  case AMDGPU::BI__builtin_amdgcn_global_load_tr_b128_v8bf16:
+  case AMDGPU::BI__builtin_amdgcn_ds_read_tr4_b64_v2i32:
+  case AMDGPU::BI__builtin_amdgcn_ds_read_tr8_b64_v2i32:
+  case AMDGPU::BI__builtin_amdgcn_ds_read_tr6_b96_v3i32:
+  case AMDGPU::BI__builtin_amdgcn_ds_read_tr16_b64_v4i16: {
 Intrinsic::ID IID;
 switch (BuiltinID) {
 case AMDGPU::BI__builtin_amdgcn_global_load_tr_b64_i32:
@@ -19713,6 +19716,18 @@ Value *CodeGenFunction::EmitAMDGPUBuiltinExpr(unsigned 
BuiltinID,
 case AMDGPU::BI__builtin_amdgcn_global_load_tr_b128_v8bf16:
   IID = Intrinsic::amdgcn_global_load_tr_b128;
   break;
+case AMDGPU::BI__builtin_amdgcn_ds_read_tr4_b64_v2i32:
+  IID = Intrinsic::amdgcn_ds_read_tr4_b64;
+  break;
+case AMDGPU::BI__builtin_amdgcn_ds_read_tr8_b64_v2i32:
+  IID = Intrinsic::amdgcn_ds_read_tr8_b64;
+  break;
+case AMDGPU::BI__builtin_amdgcn_ds_read_tr6_b96_v3i32:
+  IID = Intrinsic::amdgcn_ds_read_tr6_b96;
+  break;
+case AMDGPU::BI__builtin_amdgcn_ds_read_tr16_b64_v4i16:
+  IID = Intrinsic::amdgcn_ds_read_tr16_b64;
+  break;
 }
 llvm::Type *LoadTy = ConvertType(E->getType());
 llvm::Value *Addr = EmitScalarExpr(E->getArg(0));
diff --git a/clang/test/CodeGenOpenCL/builtins-amdgcn-gfx950-read-tr.cl 
b/clang/test/CodeGenOpenCL/builtins-amdgcn-gfx950-read-tr.cl
new file mode 100644
index 00..39fa46d5845f42
--- /dev/null
+++ b/clang/test/CodeGenOpenCL/builtins-amdgcn-gfx950-read-tr.cl
@@ -0,0 +1,50 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 4
+// RUN: %clang_cc1 -triple amdgcn-unknown-unknown -target-cpu gfx950 
-emit-llvm -o - %s | FileCheck --check-prefix=GFX950 %s
+
+typedef intv2i   __attribute__((ext_vecto

[clang] [llvm] AMDGPU: Add support for load transpose instructions for gfx950 (PR #117378)

2024-11-25 Thread Matt Arsenault via cfe-commits

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


[clang] [clang-tools-extra] [analyzer] Remove alpha.core.IdenticalExpr Checker (PR #114715)

2024-11-25 Thread via cfe-commits

vabridgers wrote:

Hi @HerrCai0907 and @5chmidti , I see that @HerrCai0907 approved the review. Is 
it ok if I merge the change? Just wanted to make sure I'm not missing any 
comments specifically from @5chmidti . Thanks! 

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


[clang] [clang] hexagon: fix link order for libc/builtins (PR #117057)

2024-11-25 Thread Brian Cain via cfe-commits

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


[clang-tools-extra] WIP: [clang-tidy] modernize-make-shared: Add MakeSmartPtrType option (PR #117529)

2024-11-25 Thread Helmut Januschka via cfe-commits

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


[clang] 9cc2502 - [clang] hexagon: fix link order for libc/builtins (#117057)

2024-11-25 Thread via cfe-commits

Author: Brian Cain
Date: 2024-11-25T11:35:45-06:00
New Revision: 9cc2502c048b1403ba8ba5cc5a655d867c329d12

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

LOG: [clang] hexagon: fix link order for libc/builtins (#117057)

When linking programs with `eld`, we get a link error like below:

Error:
/inst/clang+llvm-19.1.0-cross-hexagon-unknown-linux-musl/x86_64-linux-gnu/bin/../target/hexagon-unknown-linux-musl//usr/lib/libc.a(scalbn.lo)(.text.scalbn+0x3c):
undefined reference to `__hexagon_muldf3'

libc has references to the clang_rt builtins library, so the order of
the libraries should be reversed.

Added: 


Modified: 
clang/lib/Driver/ToolChains/Hexagon.cpp
clang/test/Driver/hexagon-toolchain-linux.c

Removed: 




diff  --git a/clang/lib/Driver/ToolChains/Hexagon.cpp 
b/clang/lib/Driver/ToolChains/Hexagon.cpp
index 29781399cbab44..383dc8387e75e7 100644
--- a/clang/lib/Driver/ToolChains/Hexagon.cpp
+++ b/clang/lib/Driver/ToolChains/Hexagon.cpp
@@ -378,9 +378,9 @@ constructHexagonLinkArgs(Compilation &C, const JobAction 
&JA,
   if (NeedsXRayDeps)
 linkXRayRuntimeDeps(HTC, Args, CmdArgs);
 
-  CmdArgs.push_back("-lclang_rt.builtins-hexagon");
   if (!Args.hasArg(options::OPT_nolibc))
 CmdArgs.push_back("-lc");
+  CmdArgs.push_back("-lclang_rt.builtins-hexagon");
 }
 if (D.CCCIsCXX()) {
   if (HTC.ShouldLinkCXXStdlib(Args))

diff  --git a/clang/test/Driver/hexagon-toolchain-linux.c 
b/clang/test/Driver/hexagon-toolchain-linux.c
index 86cc9a30e932c6..6f7f3b20f9141f 100644
--- a/clang/test/Driver/hexagon-toolchain-linux.c
+++ b/clang/test/Driver/hexagon-toolchain-linux.c
@@ -11,7 +11,7 @@
 // CHECK000-NOT:  
{{.*}}basic_linux_libcxx_tree{{/|}}usr{{/|}}lib{{/|}}crti.o
 // CHECK000:  "-dynamic-linker={{/|}}lib{{/|}}ld-musl-hexagon.so.1"
 // CHECK000:  
"{{.*}}basic_linux_libcxx_tree{{/|}}usr{{/|}}lib{{/|}}crt1.o"
-// CHECK000:  "-lclang_rt.builtins-hexagon" "-lc"
+// CHECK000:  "-lc" "-lclang_rt.builtins-hexagon"
 // 
-
 // Passing --musl --shared
 // 
-
@@ -21,7 +21,7 @@
 // RUN:   --sysroot=%S/Inputs/basic_linux_libcxx_tree -shared %s 2>&1 | 
FileCheck -check-prefix=CHECK001 %s
 // CHECK001-NOT:-dynamic-linker={{/|}}lib{{/|}}ld-musl-hexagon.so.1
 // CHECK001:
"{{.*}}basic_linux_libcxx_tree{{/|}}usr{{/|}}lib{{/|}}crti.o"
-// CHECK001:"-lclang_rt.builtins-hexagon" "-lc"
+// CHECK001:"-lc" "-lclang_rt.builtins-hexagon"
 // CHECK001-NOT:
{{.*}}basic_linux_libcxx_tree{{/|}}usr{{/|}}lib{{/|}}crt1.o
 // 
-
 // Passing --musl -nostdlib
@@ -33,8 +33,8 @@
 // CHECK002:   
"-dynamic-linker={{/|}}lib{{/|}}ld-musl-hexagon.so.1"
 // CHECK002-NOT:   
{{.*}}basic_linux_libcxx_tree{{/|}}usr{{/|}}lib{{/|}}crti.o
 // CHECK002-NOT:   
{{.*}}basic_linux_libcxx_tree{{/|}}usr{{/|}}lib{{/|}}crt1.o
-// CHECK002-NOT:   "-lclang_rt.builtins-hexagon"
 // CHECK002-NOT:   "-lc"
+// CHECK002-NOT:   "-lclang_rt.builtins-hexagon"
 // 
-
 // Passing --musl -nostartfiles
 // 
-
@@ -45,7 +45,7 @@
 // CHECK003:   
"-dynamic-linker={{/|}}lib{{/|}}ld-musl-hexagon.so.1"
 // CHECK003-NOT:   
{{.*}}basic_linux_libcxx_tree{{/|}}usr{{/|}}lib{{/|}}Scrt1.o
 // CHECK003-NOT:   
{{.*}}basic_linux_libcxx_tree{{/|}}usr{{/|}}lib{{/|}}crt1.o
-// CHECK003:   "-lclang_rt.builtins-hexagon" "-lc"
+// CHECK003:   "-lc" "-lclang_rt.builtins-hexagon"
 // 
-
 // Passing --musl -nodefaultlibs
 // 
-
@@ -55,8 +55,8 @@
 // RUN:   --sysroot=%S/Inputs/basic_linux_libcxx_tree -nodefaultlibs %s 2>&1 | 
FileCheck -check-prefix=CHECK004 %s
 // CHECK004:   
"-dynamic-linker={{/|}}lib{{/|}}ld-musl-hexagon.so.1"
 // CHECK004:   
"{{.*}}basic_linux_libcxx_tree{{/|}}usr{{/|}}lib{{/|}}crt1.o"
-// CHECK004-NOT:   "-lclang_rt.builtins-hexagon"
 // CHECK004-NOT:   "-lc"
+// CHECK004-NOT:   "-lclang_rt.builtins-hexagon"
 // 
-
 // Passing --musl -nolibc
 // 
-



___
cfe-co

[clang-tools-extra] WIP: [clang-tidy] modernize-make-shared: Add MakeSmartPtrType option (PR #117529)

2024-11-25 Thread Helmut Januschka via cfe-commits

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


[clang] [llvm] AMDGPU: Add support for load transpose instructions for gfx950 (PR #117378)

2024-11-25 Thread Matt Arsenault via cfe-commits

https://github.com/arsenm updated 
https://github.com/llvm/llvm-project/pull/117378

>From 403db2f7d09c9ff1c358b8eff83407a84c6fc965 Mon Sep 17 00:00:00 2001
From: Sirish Pande 
Date: Wed, 7 Feb 2024 10:12:03 -0600
Subject: [PATCH] AMDGPU: Add support for load transpose instructions for
 gfx950

This patch support for intrinsics in clang, as well as assembly
instructions in the backend.

Co-authored-by: Sirish Pande 
---
 clang/include/clang/Basic/BuiltinsAMDGPU.def  |   5 +
 clang/lib/CodeGen/CGBuiltin.cpp   |  19 ++-
 .../builtins-amdgcn-gfx950-read-tr.cl |  50 
 llvm/include/llvm/IR/IntrinsicsAMDGPU.td  |   4 +
 .../Target/AMDGPU/AMDGPURegisterBankInfo.cpp  |   4 +
 .../Target/AMDGPU/AMDGPUSearchableTables.td   |   5 +
 llvm/lib/Target/AMDGPU/DSInstructions.td  |  33 ++
 llvm/lib/Target/AMDGPU/SIISelLowering.cpp |  10 +-
 .../UniformityAnalysis/AMDGPU/intrinsics.ll   |  44 +++
 .../AMDGPU/llvm.amdgcn.ds.read.tr.gfx950.ll   | 108 ++
 llvm/test/MC/AMDGPU/gfx950-unsupported.s  |  77 +
 llvm/test/MC/AMDGPU/gfx950_asm_read_tr.s  |  34 ++
 .../AMDGPU/gfx950_dasm_ds_read_tr.txt |  37 ++
 13 files changed, 427 insertions(+), 3 deletions(-)
 create mode 100644 clang/test/CodeGenOpenCL/builtins-amdgcn-gfx950-read-tr.cl
 create mode 100644 llvm/test/CodeGen/AMDGPU/llvm.amdgcn.ds.read.tr.gfx950.ll
 create mode 100644 llvm/test/MC/AMDGPU/gfx950_asm_read_tr.s
 create mode 100644 llvm/test/MC/Disassembler/AMDGPU/gfx950_dasm_ds_read_tr.txt

diff --git a/clang/include/clang/Basic/BuiltinsAMDGPU.def 
b/clang/include/clang/Basic/BuiltinsAMDGPU.def
index 548bcc8ad55f48..a42ad56ce4f998 100644
--- a/clang/include/clang/Basic/BuiltinsAMDGPU.def
+++ b/clang/include/clang/Basic/BuiltinsAMDGPU.def
@@ -462,6 +462,11 @@ 
TARGET_BUILTIN(__builtin_amdgcn_smfmac_f32_32x32x64_fp8_fp8, "V16fV4iV8iV16fiIiI
 TARGET_BUILTIN(__builtin_amdgcn_permlane16_swap, "V2UiUiUiIbIb", "nc", 
"permlane16-swap")
 TARGET_BUILTIN(__builtin_amdgcn_permlane32_swap, "V2UiUiUiIbIb", "nc", 
"permlane32-swap")
 
+TARGET_BUILTIN(__builtin_amdgcn_ds_read_tr4_b64_v2i32, "V2iV2i*3", "nc", 
"gfx950-insts")
+TARGET_BUILTIN(__builtin_amdgcn_ds_read_tr6_b96_v3i32, "V3iV3i*3", "nc", 
"gfx950-insts")
+TARGET_BUILTIN(__builtin_amdgcn_ds_read_tr8_b64_v2i32, "V2iV2i*3", "nc", 
"gfx950-insts")
+TARGET_BUILTIN(__builtin_amdgcn_ds_read_tr16_b64_v4i16, "V4sV4s*3", "nc", 
"gfx950-insts")
+
 
//===--===//
 // GFX12+ only builtins.
 
//===--===//
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 3db439c87fa326..91b70b4fdf3d20 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -19697,8 +19697,11 @@ Value *CodeGenFunction::EmitAMDGPUBuiltinExpr(unsigned 
BuiltinID,
   case AMDGPU::BI__builtin_amdgcn_global_load_tr_b128_v4bf16:
   case AMDGPU::BI__builtin_amdgcn_global_load_tr_b128_v8i16:
   case AMDGPU::BI__builtin_amdgcn_global_load_tr_b128_v8f16:
-  case AMDGPU::BI__builtin_amdgcn_global_load_tr_b128_v8bf16: {
-
+  case AMDGPU::BI__builtin_amdgcn_global_load_tr_b128_v8bf16:
+  case AMDGPU::BI__builtin_amdgcn_ds_read_tr4_b64_v2i32:
+  case AMDGPU::BI__builtin_amdgcn_ds_read_tr8_b64_v2i32:
+  case AMDGPU::BI__builtin_amdgcn_ds_read_tr6_b96_v3i32:
+  case AMDGPU::BI__builtin_amdgcn_ds_read_tr16_b64_v4i16: {
 Intrinsic::ID IID;
 switch (BuiltinID) {
 case AMDGPU::BI__builtin_amdgcn_global_load_tr_b64_i32:
@@ -19713,6 +19716,18 @@ Value *CodeGenFunction::EmitAMDGPUBuiltinExpr(unsigned 
BuiltinID,
 case AMDGPU::BI__builtin_amdgcn_global_load_tr_b128_v8bf16:
   IID = Intrinsic::amdgcn_global_load_tr_b128;
   break;
+case AMDGPU::BI__builtin_amdgcn_ds_read_tr4_b64_v2i32:
+  IID = Intrinsic::amdgcn_ds_read_tr4_b64;
+  break;
+case AMDGPU::BI__builtin_amdgcn_ds_read_tr8_b64_v2i32:
+  IID = Intrinsic::amdgcn_ds_read_tr8_b64;
+  break;
+case AMDGPU::BI__builtin_amdgcn_ds_read_tr6_b96_v3i32:
+  IID = Intrinsic::amdgcn_ds_read_tr6_b96;
+  break;
+case AMDGPU::BI__builtin_amdgcn_ds_read_tr16_b64_v4i16:
+  IID = Intrinsic::amdgcn_ds_read_tr16_b64;
+  break;
 }
 llvm::Type *LoadTy = ConvertType(E->getType());
 llvm::Value *Addr = EmitScalarExpr(E->getArg(0));
diff --git a/clang/test/CodeGenOpenCL/builtins-amdgcn-gfx950-read-tr.cl 
b/clang/test/CodeGenOpenCL/builtins-amdgcn-gfx950-read-tr.cl
new file mode 100644
index 00..39fa46d5845f42
--- /dev/null
+++ b/clang/test/CodeGenOpenCL/builtins-amdgcn-gfx950-read-tr.cl
@@ -0,0 +1,50 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 4
+// RUN: %clang_cc1 -triple amdgcn-unknown-unknown -target-cpu gfx950 
-emit-llvm -o - %s | FileCheck --check-prefix=GFX950 %s
+
+typedef intv2i   __attribute__((ext_vecto

[clang-tools-extra] [clang-tidy] modernize-make-shared: Add MakeSmartPtrType option (PR #117529)

2024-11-25 Thread Helmut Januschka via cfe-commits

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


[clang-tools-extra] [clang-tidy] modernize-make-shared: Add MakeSmartPtrType option (PR #117529)

2024-11-25 Thread Helmut Januschka via cfe-commits

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


[clang-tools-extra] [clang-tidy] modernize-make-shared: Add MakeSmartPtrType option (PR #117529)

2024-11-25 Thread Helmut Januschka via cfe-commits

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


[clang] e97fb22 - AMDGPU: Add support for load transpose instructions for gfx950 (#117378)

2024-11-25 Thread via cfe-commits

Author: Matt Arsenault
Date: 2024-11-25T09:39:04-08:00
New Revision: e97fb2207e1ef6235a6268dbbd3cc08d437b07ef

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

LOG: AMDGPU: Add support for load transpose instructions for gfx950 (#117378)

This patch support for intrinsics in clang, as well as assembly
instructions in the backend.

Co-authored-by: Sirish Pande 

Added: 
clang/test/CodeGenOpenCL/builtins-amdgcn-gfx950-read-tr.cl
llvm/test/CodeGen/AMDGPU/llvm.amdgcn.ds.read.tr.gfx950.ll
llvm/test/MC/AMDGPU/gfx950_asm_read_tr.s
llvm/test/MC/Disassembler/AMDGPU/gfx950_dasm_ds_read_tr.txt

Modified: 
clang/include/clang/Basic/BuiltinsAMDGPU.def
clang/lib/CodeGen/CGBuiltin.cpp
llvm/include/llvm/IR/IntrinsicsAMDGPU.td
llvm/lib/Target/AMDGPU/AMDGPURegisterBankInfo.cpp
llvm/lib/Target/AMDGPU/AMDGPUSearchableTables.td
llvm/lib/Target/AMDGPU/DSInstructions.td
llvm/lib/Target/AMDGPU/SIISelLowering.cpp
llvm/test/Analysis/UniformityAnalysis/AMDGPU/intrinsics.ll
llvm/test/MC/AMDGPU/gfx950-unsupported.s

Removed: 




diff  --git a/clang/include/clang/Basic/BuiltinsAMDGPU.def 
b/clang/include/clang/Basic/BuiltinsAMDGPU.def
index 548bcc8ad55f48..a42ad56ce4f998 100644
--- a/clang/include/clang/Basic/BuiltinsAMDGPU.def
+++ b/clang/include/clang/Basic/BuiltinsAMDGPU.def
@@ -462,6 +462,11 @@ 
TARGET_BUILTIN(__builtin_amdgcn_smfmac_f32_32x32x64_fp8_fp8, "V16fV4iV8iV16fiIiI
 TARGET_BUILTIN(__builtin_amdgcn_permlane16_swap, "V2UiUiUiIbIb", "nc", 
"permlane16-swap")
 TARGET_BUILTIN(__builtin_amdgcn_permlane32_swap, "V2UiUiUiIbIb", "nc", 
"permlane32-swap")
 
+TARGET_BUILTIN(__builtin_amdgcn_ds_read_tr4_b64_v2i32, "V2iV2i*3", "nc", 
"gfx950-insts")
+TARGET_BUILTIN(__builtin_amdgcn_ds_read_tr6_b96_v3i32, "V3iV3i*3", "nc", 
"gfx950-insts")
+TARGET_BUILTIN(__builtin_amdgcn_ds_read_tr8_b64_v2i32, "V2iV2i*3", "nc", 
"gfx950-insts")
+TARGET_BUILTIN(__builtin_amdgcn_ds_read_tr16_b64_v4i16, "V4sV4s*3", "nc", 
"gfx950-insts")
+
 
//===--===//
 // GFX12+ only builtins.
 
//===--===//

diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 3db439c87fa326..91b70b4fdf3d20 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -19697,8 +19697,11 @@ Value *CodeGenFunction::EmitAMDGPUBuiltinExpr(unsigned 
BuiltinID,
   case AMDGPU::BI__builtin_amdgcn_global_load_tr_b128_v4bf16:
   case AMDGPU::BI__builtin_amdgcn_global_load_tr_b128_v8i16:
   case AMDGPU::BI__builtin_amdgcn_global_load_tr_b128_v8f16:
-  case AMDGPU::BI__builtin_amdgcn_global_load_tr_b128_v8bf16: {
-
+  case AMDGPU::BI__builtin_amdgcn_global_load_tr_b128_v8bf16:
+  case AMDGPU::BI__builtin_amdgcn_ds_read_tr4_b64_v2i32:
+  case AMDGPU::BI__builtin_amdgcn_ds_read_tr8_b64_v2i32:
+  case AMDGPU::BI__builtin_amdgcn_ds_read_tr6_b96_v3i32:
+  case AMDGPU::BI__builtin_amdgcn_ds_read_tr16_b64_v4i16: {
 Intrinsic::ID IID;
 switch (BuiltinID) {
 case AMDGPU::BI__builtin_amdgcn_global_load_tr_b64_i32:
@@ -19713,6 +19716,18 @@ Value *CodeGenFunction::EmitAMDGPUBuiltinExpr(unsigned 
BuiltinID,
 case AMDGPU::BI__builtin_amdgcn_global_load_tr_b128_v8bf16:
   IID = Intrinsic::amdgcn_global_load_tr_b128;
   break;
+case AMDGPU::BI__builtin_amdgcn_ds_read_tr4_b64_v2i32:
+  IID = Intrinsic::amdgcn_ds_read_tr4_b64;
+  break;
+case AMDGPU::BI__builtin_amdgcn_ds_read_tr8_b64_v2i32:
+  IID = Intrinsic::amdgcn_ds_read_tr8_b64;
+  break;
+case AMDGPU::BI__builtin_amdgcn_ds_read_tr6_b96_v3i32:
+  IID = Intrinsic::amdgcn_ds_read_tr6_b96;
+  break;
+case AMDGPU::BI__builtin_amdgcn_ds_read_tr16_b64_v4i16:
+  IID = Intrinsic::amdgcn_ds_read_tr16_b64;
+  break;
 }
 llvm::Type *LoadTy = ConvertType(E->getType());
 llvm::Value *Addr = EmitScalarExpr(E->getArg(0));

diff  --git a/clang/test/CodeGenOpenCL/builtins-amdgcn-gfx950-read-tr.cl 
b/clang/test/CodeGenOpenCL/builtins-amdgcn-gfx950-read-tr.cl
new file mode 100644
index 00..39fa46d5845f42
--- /dev/null
+++ b/clang/test/CodeGenOpenCL/builtins-amdgcn-gfx950-read-tr.cl
@@ -0,0 +1,50 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 4
+// RUN: %clang_cc1 -triple amdgcn-unknown-unknown -target-cpu gfx950 
-emit-llvm -o - %s | FileCheck --check-prefix=GFX950 %s
+
+typedef intv2i   __attribute__((ext_vector_type(2)));
+typedef intv3i   __attribute__((ext_vector_type(3)));
+typedef short  v4s   __attribute__((ext_vector_type(4)));
+
+// GFX950-LABEL: define dso_local <2 x i32> 
@test_amdgcn_ds_read_b64_tr_b4_v2i32(
+// GFX950-SAME: ptr addrspace(3) no

[clang] [Clang] Only ignore special methods for unused private fields in BuildFieldReferenceExpr (PR #116965)

2024-11-25 Thread Mészáros Gergely via cfe-commits

https://github.com/Maetveis updated 
https://github.com/llvm/llvm-project/pull/116965

From 90febd4a613fc2e76548da6912b32d50bc88a0ac Mon Sep 17 00:00:00 2001
From: Gergely Meszaros 
Date: Wed, 20 Nov 2024 12:55:59 +
Subject: [PATCH 1/2] [Clang] Only ignore special methods for unused private
 fields in BuildFieldReferenceExpr

The original code assumed that only special methods might be defined
as defaulted. Since C++20 comparison operators might be defaulted too,
and we *do* want to consider those as using the fields of the class.

Fixes: #116961
---
 clang/lib/Sema/SemaExprMember.cpp| 12 ++--
 clang/test/SemaCXX/warn-unused-private-field.cpp | 14 ++
 2 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Sema/SemaExprMember.cpp 
b/clang/lib/Sema/SemaExprMember.cpp
index 434768b99d631e..85d5dfcb3db6de 100644
--- a/clang/lib/Sema/SemaExprMember.cpp
+++ b/clang/lib/Sema/SemaExprMember.cpp
@@ -1874,8 +1874,16 @@ Sema::BuildFieldReferenceExpr(Expr *BaseExpr, bool 
IsArrow,
   Context.getAttributedType(attr::NoDeref, MemberType, MemberType);
   }
 
-  auto *CurMethod = dyn_cast(CurContext);
-  if (!(CurMethod && CurMethod->isDefaulted()))
+  auto isDefaultedSpecialMember = [this](const DeclContext *Ctx) {
+auto *Method = dyn_cast(CurContext);
+if (!Method || !Method->isDefaulted())
+  return false;
+
+return getDefaultedFunctionKind(Method).isSpecialMember();
+  };
+
+  // Implicit special members should not mark fields as used.
+  if (!isDefaultedSpecialMember(CurContext))
 UnusedPrivateFields.remove(Field);
 
   ExprResult Base = PerformObjectMemberConversion(BaseExpr, SS.getScopeRep(),
diff --git a/clang/test/SemaCXX/warn-unused-private-field.cpp 
b/clang/test/SemaCXX/warn-unused-private-field.cpp
index 1128eacc309d9f..9913dbaafb7a57 100644
--- a/clang/test/SemaCXX/warn-unused-private-field.cpp
+++ b/clang/test/SemaCXX/warn-unused-private-field.cpp
@@ -20,6 +20,20 @@ class SpaceShipDefaultCompare {
   int operator<=>(const SpaceShipDefaultCompare &) const = default;
 };
 
+class EqDefaultCompareOutOfClass {
+  int used;
+  bool operator==(const EqDefaultCompareOutOfClass &) const;
+};
+
+bool EqDefaultCompareOutOfClass::operator==(const EqDefaultCompareOutOfClass 
&) const = default;
+
+class FriendEqDefaultCompareOutOfClass {
+  int used;
+  friend bool operator==(const FriendEqDefaultCompareOutOfClass &, const 
FriendEqDefaultCompareOutOfClass &);
+};
+
+bool operator==(const FriendEqDefaultCompareOutOfClass &, const 
FriendEqDefaultCompareOutOfClass &) = default;
+
 #endif
 
 class NotFullyDefined {

From acffecafadf20037211d73acee7ce9d715123cba Mon Sep 17 00:00:00 2001
From: Gergely 
Date: Mon, 25 Nov 2024 17:35:03 +
Subject: [PATCH 2/2] Add Release Notes and comments to test

---
 clang/docs/ReleaseNotes.rst  | 2 ++
 clang/test/SemaCXX/warn-unused-private-field.cpp | 4 ++--
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index b9986434d09d24..367c1ae2803e0a 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -585,6 +585,8 @@ Improvements to Clang's diagnostics
 - For an rvalue reference bound to a temporary struct with an integer member, 
Clang will detect constant integer overflow
   in the initializer for the integer member (#GH46755).
 
+- Fixed a false negative ``-Wunused-private-field`` diagnostic when a 
defaulted comparison operator is defined out of class (#GH116961).
+
 Improvements to Clang's time-trace
 --
 
diff --git a/clang/test/SemaCXX/warn-unused-private-field.cpp 
b/clang/test/SemaCXX/warn-unused-private-field.cpp
index 9913dbaafb7a57..047204e68617a1 100644
--- a/clang/test/SemaCXX/warn-unused-private-field.cpp
+++ b/clang/test/SemaCXX/warn-unused-private-field.cpp
@@ -21,14 +21,14 @@ class SpaceShipDefaultCompare {
 };
 
 class EqDefaultCompareOutOfClass {
-  int used;
+  int used; // no warning
   bool operator==(const EqDefaultCompareOutOfClass &) const;
 };
 
 bool EqDefaultCompareOutOfClass::operator==(const EqDefaultCompareOutOfClass 
&) const = default;
 
 class FriendEqDefaultCompareOutOfClass {
-  int used;
+  int used; // no warning
   friend bool operator==(const FriendEqDefaultCompareOutOfClass &, const 
FriendEqDefaultCompareOutOfClass &);
 };
 

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


[clang] [llvm] AMDGPU: Add support for load transpose instructions for gfx950 (PR #117378)

2024-11-25 Thread Matt Arsenault via cfe-commits

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


[clang] [llvm] AMDGPU: Add MC support for gfx950 V_BITOP3_B32/B16 (PR #117379)

2024-11-25 Thread Matt Arsenault via cfe-commits

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


[clang] [Clang][AArch64] Include SME attributes in the name mangling of function types (PR #114209)

2024-11-25 Thread Sander de Smalen via cfe-commits


@@ -3535,6 +3536,74 @@ void CXXNameMangler::mangleExtFunctionInfo(const 
FunctionType *T) {
   // FIXME: noreturn
 }
 
+enum SMEState {
+  Normal = 0,
+  SM_Enabled = 1 << 0,
+  SM_Compatible = 1 << 1,
+  ZA_Agnostic = 1 << 2,
+  ZA_Shift = 3,
+  ZT0_Shift = 6,

sdesmalen-arm wrote:

```suggestion
  ArmStreamingBit = 1 << 0,
  ArmStreamingCompatibleBit = 1 << 1,
  ArmAgnosticSMEZAStateBit << 2,
  ZA_Shift = 3,
  ZT0_Shift = 6,
```

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


[clang] [Clang][AArch64] Include SME attributes in the name mangling of function types (PR #114209)

2024-11-25 Thread Sander de Smalen via cfe-commits


@@ -3535,6 +3536,74 @@ void CXXNameMangler::mangleExtFunctionInfo(const 
FunctionType *T) {
   // FIXME: noreturn
 }
 
+enum SMEState {
+  Normal = 0,
+  SM_Enabled = 1 << 0,
+  SM_Compatible = 1 << 1,
+  ZA_Agnostic = 1 << 2,
+  ZA_Shift = 3,
+  ZT0_Shift = 6,
+  None = 0b000,
+  In = 0b001,
+  Out = 0b010,
+  InOut = 0b011,
+  Preserves = 0b100
+};
+
+unsigned encodeZAState(unsigned SMEAttrs) {
+  switch (SMEAttrs) {
+  case FunctionType::ARM_None:
+return SMEState::None;
+  case FunctionType::ARM_In:
+return SMEState::In;
+  case FunctionType::ARM_Out:
+return SMEState::Out;
+  case FunctionType::ARM_InOut:
+return SMEState::InOut;
+  case FunctionType::ARM_Preserves:
+return SMEState::Preserves;
+  }
+  llvm_unreachable("Unrecognised SME attribute");
+}
+
+// As described in the AArch64 ACLE, the mangling scheme for function types
+// which have SME attributes is implemented as a "pseudo" template:
+//
+//   '__SME_ATTRS<, >'
+//
+// Combining the function type with a bitmask representing the streaming and ZA
+// properties of the function's interface.
+//
+// The mangling scheme is otherwise defined in the appendices to the Procedure
+// Call Standard for the Arm Architecture, see
+// 
https://github.com/ARM-software/abi-aa/blob/main/aapcs64/aapcs64.rst#appendix-c-mangling
+//
+void CXXNameMangler::mangleSMEAttrs(unsigned SMEAttrs) {
+  if (!SMEAttrs)
+return;
+
+  // Streaming Mode
+  unsigned Bitmask = SMEState::Normal;
+  if (SMEAttrs & FunctionType::SME_PStateSMEnabledMask)
+Bitmask |= SMEState::SM_Enabled;
+  else if (SMEAttrs & FunctionType::SME_PStateSMCompatibleMask)
+Bitmask |= SMEState::SM_Compatible;
+
+  // TODO: Must represent __arm_agnostic("sme_za_state")
+
+  // ZA-State

sdesmalen-arm wrote:

nit: remove comment (same below).

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


[clang] [Clang][AArch64] Include SME attributes in the name mangling of function types (PR #114209)

2024-11-25 Thread Sander de Smalen via cfe-commits


@@ -3535,6 +3536,74 @@ void CXXNameMangler::mangleExtFunctionInfo(const 
FunctionType *T) {
   // FIXME: noreturn
 }
 
+enum SMEState {
+  Normal = 0,

sdesmalen-arm wrote:

nit: I'd remove `Normal` and just keep these values for bits that would be set.

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


[clang] [Clang][AArch64] Include SME attributes in the name mangling of function types (PR #114209)

2024-11-25 Thread Sander de Smalen via cfe-commits


@@ -3535,6 +3536,74 @@ void CXXNameMangler::mangleExtFunctionInfo(const 
FunctionType *T) {
   // FIXME: noreturn
 }
 
+enum SMEState {
+  Normal = 0,
+  SM_Enabled = 1 << 0,
+  SM_Compatible = 1 << 1,
+  ZA_Agnostic = 1 << 2,
+  ZA_Shift = 3,
+  ZT0_Shift = 6,
+  None = 0b000,
+  In = 0b001,
+  Out = 0b010,
+  InOut = 0b011,
+  Preserves = 0b100
+};
+
+unsigned encodeZAState(unsigned SMEAttrs) {
+  switch (SMEAttrs) {
+  case FunctionType::ARM_None:
+return SMEState::None;
+  case FunctionType::ARM_In:
+return SMEState::In;
+  case FunctionType::ARM_Out:
+return SMEState::Out;
+  case FunctionType::ARM_InOut:
+return SMEState::InOut;
+  case FunctionType::ARM_Preserves:
+return SMEState::Preserves;
+  }
+  llvm_unreachable("Unrecognised SME attribute");
+}
+
+// As described in the AArch64 ACLE, the mangling scheme for function types
+// which have SME attributes is implemented as a "pseudo" template:
+//
+//   '__SME_ATTRS<, >'
+//
+// Combining the function type with a bitmask representing the streaming and ZA
+// properties of the function's interface.
+//
+// The mangling scheme is otherwise defined in the appendices to the Procedure
+// Call Standard for the Arm Architecture, see
+// 
https://github.com/ARM-software/abi-aa/blob/main/aapcs64/aapcs64.rst#appendix-c-mangling
+//
+void CXXNameMangler::mangleSMEAttrs(unsigned SMEAttrs) {
+  if (!SMEAttrs)
+return;
+
+  // Streaming Mode
+  unsigned Bitmask = SMEState::Normal;
+  if (SMEAttrs & FunctionType::SME_PStateSMEnabledMask)
+Bitmask |= SMEState::SM_Enabled;
+  else if (SMEAttrs & FunctionType::SME_PStateSMCompatibleMask)
+Bitmask |= SMEState::SM_Compatible;
+
+  // TODO: Must represent __arm_agnostic("sme_za_state")
+
+  // ZA-State
+  Bitmask |= encodeZAState(FunctionType::getArmZAState(SMEAttrs))
+ << SMEState::ZA_Shift;
+
+  // ZT0 State
+  Bitmask |= encodeZAState(FunctionType::getArmZT0State(SMEAttrs))
+ << SMEState::ZT0_Shift;
+
+  Out << "Lj" << Bitmask << "EE";
+
+  return;

sdesmalen-arm wrote:

no need for `return;`

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


[clang] [Clang][AArch64] Include SME attributes in the name mangling of function types (PR #114209)

2024-11-25 Thread Sander de Smalen via cfe-commits


@@ -3535,6 +3536,74 @@ void CXXNameMangler::mangleExtFunctionInfo(const 
FunctionType *T) {
   // FIXME: noreturn
 }
 
+enum SMEState {

sdesmalen-arm wrote:

Please make this an `enum class` instead. Also, I'd recommend renaming this 
class so that it's clear that this relates to AAPCS type mangling.

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


[clang] [Clang][AArch64] Include SME attributes in the name mangling of function types (PR #114209)

2024-11-25 Thread Sander de Smalen via cfe-commits


@@ -3535,6 +3536,74 @@ void CXXNameMangler::mangleExtFunctionInfo(const 
FunctionType *T) {
   // FIXME: noreturn
 }
 
+enum SMEState {
+  Normal = 0,
+  SM_Enabled = 1 << 0,
+  SM_Compatible = 1 << 1,
+  ZA_Agnostic = 1 << 2,
+  ZA_Shift = 3,
+  ZT0_Shift = 6,
+  None = 0b000,
+  In = 0b001,
+  Out = 0b010,
+  InOut = 0b011,
+  Preserves = 0b100
+};
+
+unsigned encodeZAState(unsigned SMEAttrs) {
+  switch (SMEAttrs) {
+  case FunctionType::ARM_None:
+return SMEState::None;
+  case FunctionType::ARM_In:
+return SMEState::In;
+  case FunctionType::ARM_Out:
+return SMEState::Out;
+  case FunctionType::ARM_InOut:
+return SMEState::InOut;
+  case FunctionType::ARM_Preserves:
+return SMEState::Preserves;
+  }
+  llvm_unreachable("Unrecognised SME attribute");

sdesmalen-arm wrote:

This is missing a `default` (would otherwise result in warning diagnostic), you 
could move the `llvm_unreachable` under the `default` case.

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


[clang] [Clang][AArch64] Include SME attributes in the name mangling of function types (PR #114209)

2024-11-25 Thread Sander de Smalen via cfe-commits


@@ -3535,6 +3536,74 @@ void CXXNameMangler::mangleExtFunctionInfo(const 
FunctionType *T) {
   // FIXME: noreturn
 }
 
+enum SMEState {
+  Normal = 0,
+  SM_Enabled = 1 << 0,
+  SM_Compatible = 1 << 1,
+  ZA_Agnostic = 1 << 2,
+  ZA_Shift = 3,
+  ZT0_Shift = 6,
+  None = 0b000,
+  In = 0b001,
+  Out = 0b010,
+  InOut = 0b011,
+  Preserves = 0b100
+};
+
+unsigned encodeZAState(unsigned SMEAttrs) {
+  switch (SMEAttrs) {
+  case FunctionType::ARM_None:
+return SMEState::None;
+  case FunctionType::ARM_In:
+return SMEState::In;
+  case FunctionType::ARM_Out:
+return SMEState::Out;
+  case FunctionType::ARM_InOut:
+return SMEState::InOut;
+  case FunctionType::ARM_Preserves:
+return SMEState::Preserves;
+  }
+  llvm_unreachable("Unrecognised SME attribute");
+}
+
+// As described in the AArch64 ACLE, the mangling scheme for function types
+// which have SME attributes is implemented as a "pseudo" template:
+//
+//   '__SME_ATTRS<, >'
+//
+// Combining the function type with a bitmask representing the streaming and ZA
+// properties of the function's interface.
+//
+// The mangling scheme is otherwise defined in the appendices to the Procedure
+// Call Standard for the Arm Architecture, see
+// 
https://github.com/ARM-software/abi-aa/blob/main/aapcs64/aapcs64.rst#appendix-c-mangling

sdesmalen-arm wrote:

Sorry, I got confused and thought this was added to the AAPCS. Could you add 
the link to the ACLE section instead?

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


[clang] [compiler-rt] [libunwind] [llvm] [clang] recognize any *-ld.lld variant (PR #117338)

2024-11-25 Thread Fangrui Song via cfe-commits


@@ -0,0 +1,80 @@
+if (NOT DEFINED LLVM_PATH)

MaskRay wrote:

I am not sure that these cmake changes should be included in this patch. Many 
folks concerned with cmake changes will likely notice that this PR has these 
changes.

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


[clang] [Clang][AArch64] Include SME attributes in the name mangling of function types (PR #114209)

2024-11-25 Thread Sander de Smalen via cfe-commits


@@ -3535,6 +3536,74 @@ void CXXNameMangler::mangleExtFunctionInfo(const 
FunctionType *T) {
   // FIXME: noreturn
 }
 
+enum SMEState {
+  Normal = 0,
+  SM_Enabled = 1 << 0,
+  SM_Compatible = 1 << 1,
+  ZA_Agnostic = 1 << 2,
+  ZA_Shift = 3,
+  ZT0_Shift = 6,
+  None = 0b000,
+  In = 0b001,
+  Out = 0b010,
+  InOut = 0b011,
+  Preserves = 0b100

sdesmalen-arm wrote:

```suggestion
  NoState = 0b000,
  ArmIn = 0b001,
  ArmOut = 0b010,
  ArmInOut = 0b011,
  ArmPreserves = 0b100
```

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


[clang] [Clang][AArch64] Include SME attributes in the name mangling of function types (PR #114209)

2024-11-25 Thread Sander de Smalen via cfe-commits


@@ -3535,6 +3536,74 @@ void CXXNameMangler::mangleExtFunctionInfo(const 
FunctionType *T) {
   // FIXME: noreturn
 }
 
+enum SMEState {
+  Normal = 0,
+  SM_Enabled = 1 << 0,
+  SM_Compatible = 1 << 1,
+  ZA_Agnostic = 1 << 2,
+  ZA_Shift = 3,
+  ZT0_Shift = 6,
+  None = 0b000,
+  In = 0b001,
+  Out = 0b010,
+  InOut = 0b011,
+  Preserves = 0b100
+};
+
+unsigned encodeZAState(unsigned SMEAttrs) {
+  switch (SMEAttrs) {
+  case FunctionType::ARM_None:
+return SMEState::None;
+  case FunctionType::ARM_In:
+return SMEState::In;
+  case FunctionType::ARM_Out:
+return SMEState::Out;
+  case FunctionType::ARM_InOut:
+return SMEState::InOut;
+  case FunctionType::ARM_Preserves:
+return SMEState::Preserves;
+  }
+  llvm_unreachable("Unrecognised SME attribute");
+}
+
+// As described in the AArch64 ACLE, the mangling scheme for function types
+// which have SME attributes is implemented as a "pseudo" template:
+//
+//   '__SME_ATTRS<, >'
+//
+// Combining the function type with a bitmask representing the streaming and ZA
+// properties of the function's interface.
+//
+// The mangling scheme is otherwise defined in the appendices to the Procedure
+// Call Standard for the Arm Architecture, see
+// 
https://github.com/ARM-software/abi-aa/blob/main/aapcs64/aapcs64.rst#appendix-c-mangling
+//
+void CXXNameMangler::mangleSMEAttrs(unsigned SMEAttrs) {
+  if (!SMEAttrs)
+return;
+
+  // Streaming Mode
+  unsigned Bitmask = SMEState::Normal;

sdesmalen-arm wrote:

```suggestion
  unsigned Bitmask = 0;
```

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


[clang] [Clang][AArch64] Include SME attributes in the name mangling of function types (PR #114209)

2024-11-25 Thread Kerry McLaughlin via cfe-commits

https://github.com/kmclaughlin-arm updated 
https://github.com/llvm/llvm-project/pull/114209

>From ff5b6defc0df704f63fffabc731bcd38a1e24d3b Mon Sep 17 00:00:00 2001
From: Kerry McLaughlin 
Date: Tue, 15 Oct 2024 15:22:56 +
Subject: [PATCH 1/3] [Clang][AArch64] Include SME attributes in the name
 mangling of function types.

Similar to arm_sve_vector_bits, the mangling of function types is implemented as
a pseudo template if there are any SME attributes present, i.e.

  __SME_ATTRS

For example, the following function:

  void f(svint8_t (*fn)() __arm_streaming) { fn(); }

is mangled as:

  fP9__SME_ATTRSIFu10__SVInt8_tELj1ELj0ELj0EE

See https://github.com/ARM-software/abi-aa/pull/290
---
 clang/lib/AST/ItaniumMangle.cpp   | 41 
 .../CodeGenCXX/aarch64-mangle-sme-atts.cpp| 65 +++
 2 files changed, 106 insertions(+)
 create mode 100644 clang/test/CodeGenCXX/aarch64-mangle-sme-atts.cpp

diff --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp
index b3e46508cf596d..2a015b4c45297e 100644
--- a/clang/lib/AST/ItaniumMangle.cpp
+++ b/clang/lib/AST/ItaniumMangle.cpp
@@ -575,6 +575,7 @@ class CXXNameMangler {
   static StringRef getCallingConvQualifierName(CallingConv CC);
   void mangleExtParameterInfo(FunctionProtoType::ExtParameterInfo info);
   void mangleExtFunctionInfo(const FunctionType *T);
+  void mangleSMEAttrs(unsigned SMEAttrs);
   void mangleBareFunctionType(const FunctionProtoType *T, bool 
MangleReturnType,
   const FunctionDecl *FD = nullptr);
   void mangleNeonVectorType(const VectorType *T);
@@ -3535,6 +3536,39 @@ void CXXNameMangler::mangleExtFunctionInfo(const 
FunctionType *T) {
   // FIXME: noreturn
 }
 
+bool hasSharedState(unsigned SMEAttrs) {
+  switch (SMEAttrs) {
+  case FunctionType::ARM_In:
+  case FunctionType::ARM_Out:
+  case FunctionType::ARM_InOut:
+  case FunctionType::ARM_Preserves:
+return true;
+  default:
+return false;
+  }
+}
+
+void CXXNameMangler::mangleSMEAttrs(unsigned SMEAttrs) {
+  if (!SMEAttrs)
+return;
+
+  // Streaming Mode
+  if (SMEAttrs & FunctionType::SME_PStateSMEnabledMask)
+Out << "Lj1E";
+  else if (SMEAttrs & FunctionType::SME_PStateSMCompatibleMask)
+Out << "Lj2E";
+  else
+Out << "Lj0E";
+
+  // ZA & ZT0 State
+  Out << (hasSharedState(FunctionType::getArmZAState(SMEAttrs)) ? "Lj1E"
+: "Lj0E");
+  Out << (hasSharedState(FunctionType::getArmZT0State(SMEAttrs)) ? "Lj1E"
+ : "Lj0E");
+
+  return;
+}
+
 void
 CXXNameMangler::mangleExtParameterInfo(FunctionProtoType::ExtParameterInfo PI) 
{
   // Vendor-specific qualifiers are emitted in reverse alphabetical order.
@@ -3572,6 +3606,11 @@ 
CXXNameMangler::mangleExtParameterInfo(FunctionProtoType::ExtParameterInfo PI) {
 //  ::= [] F [Y]
 //   [] E
 void CXXNameMangler::mangleType(const FunctionProtoType *T) {
+  unsigned SMEAttrs = T->getAArch64SMEAttributes();
+
+  if (SMEAttrs)
+Out << "11__SME_ATTRSI";
+
   mangleExtFunctionInfo(T);
 
   // Mangle CV-qualifiers, if present.  These are 'this' qualifiers,
@@ -3605,6 +3644,8 @@ void CXXNameMangler::mangleType(const FunctionProtoType 
*T) {
   // Mangle the ref-qualifier, if present.
   mangleRefQualifier(T->getRefQualifier());
 
+  mangleSMEAttrs(SMEAttrs);
+
   Out << 'E';
 }
 
diff --git a/clang/test/CodeGenCXX/aarch64-mangle-sme-atts.cpp 
b/clang/test/CodeGenCXX/aarch64-mangle-sme-atts.cpp
new file mode 100644
index 00..16d4111cdfaaa1
--- /dev/null
+++ b/clang/test/CodeGenCXX/aarch64-mangle-sme-atts.cpp
@@ -0,0 +1,65 @@
+// RUN: %clang_cc1 -triple aarch64-none-linux-gnu -target-feature +sve 
-target-feature +sme -target-feature +sme2 %s -emit-llvm -o - | FileCheck %s
+
+typedef __attribute__((neon_vector_type(2))) int int32x2_t;
+
+//
+// Streaming-Mode Attributes
+//
+
+// CHECK: define dso_local void 
@_Z12fn_streamingP11__SME_ATTRSIFvvLj1ELj0ELj0EE( 
+void fn_streaming(void (*foo)() __arm_streaming) { foo(); }
+
+// CHECK: define dso_local void 
@_Z12fn_streamingP11__SME_ATTRSIFivLj2ELj0ELj0EE(
+void fn_streaming(int (*foo)() __arm_streaming_compatible) { foo(); }
+
+//
+// ZA Attributes
+//
+
+// CHECK: define dso_local void 
@_Z15fn_za_preservedP11__SME_ATTRSIF11__Int32x2_tvLj0ELj1ELj0EE(
+__arm_new("za") void fn_za_preserved(int32x2_t (*foo)() __arm_preserves("za")) 
{ foo(); }
+
+// CHECK: define dso_local void 
@_Z8fn_za_inP11__SME_ATTRSIFvu13__SVFloat64_tLj0ELj1ELj0EES_(
+__arm_new("za") void fn_za_in(void (*foo)(__SVFloat64_t) __arm_in("za"), 
__SVFloat64_t x) { foo(x); }
+
+// CHECK: define dso_local noundef i32 
@_Z9fn_za_outP11__SME_ATTRSIFivLj0ELj1ELj0EE(
+__arm_new("za") int fn_za_out(int (*foo)() __arm_out("za")) { return foo(); }
+
+// CHECK: define dso_local void 
@_Z11fn_za_inoutP11__SME_ATTRSIFvvLj0ELj1ELj0EE(
+__arm_new("za") void fn_za_inout(void (*foo)

[clang] [flang] [clang][driver] Special care for -l flags in config files (PR #117573)

2024-11-25 Thread Michał Górny via cfe-commits


@@ -0,0 +1 @@
+-ffast-math -lm -lhappy

mgorny wrote:

Could you also include some "positional" `-Wl` flags, like `-Wl,-Bstatic` and 
`-Wl,-Bdynamic`?

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


[clang] [llvm] [HLSL] Disallow named struct types as parameters in target extension types (PR #115971)

2024-11-25 Thread Joshua Batista via cfe-commits

https://github.com/bob80905 updated 
https://github.com/llvm/llvm-project/pull/115971

>From 7413ceb21a6e0ac9212ef6317763ee0eff559612 Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Tue, 12 Nov 2024 16:44:00 -0800
Subject: [PATCH 1/9] print struct body within target ext ty context

---
 .../test/AST/HLSL/StructuredBuffer-AST-2.hlsl | 30 +++
 llvm/lib/IR/AsmWriter.cpp | 10 +--
 2 files changed, 38 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/AST/HLSL/StructuredBuffer-AST-2.hlsl

diff --git a/clang/test/AST/HLSL/StructuredBuffer-AST-2.hlsl 
b/clang/test/AST/HLSL/StructuredBuffer-AST-2.hlsl
new file mode 100644
index 00..73073b3f6f2839
--- /dev/null
+++ b/clang/test/AST/HLSL/StructuredBuffer-AST-2.hlsl
@@ -0,0 +1,30 @@
+// RUN: %clang_dxc -T cs_6_6 %s | FileCheck %s
+
+// The purpose of this test is to ensure that the AST writer
+// only emits struct bodies when within the context of a 
+// larger object that is being outputted on the RHS.
+
+
+// note that "{ <4 x float> }" in the check below is a struct type, but only 
the
+// body is emitted on the RHS because we are already in the context of a
+// target extension type definition (class.hlsl::StructuredBuffer)
+// CHECK: %"class.hlsl::StructuredBuffer" = type { target("dx.RawBuffer", { <4 
x float> }, 0, 0), %struct.mystruct }
+// CHECK: %struct.mystruct = type { <4 x float> }
+// CHECK: %dx.types.Handle = type { ptr }
+// CHECK: %dx.types.ResBind = type { i32, i32, i32, i8 }
+// CHECK: %dx.types.ResourceProperties = type { i32, i32 }
+
+struct mystruct
+{
+float4 Color;
+};
+
+StructuredBuffer my_buffer : register(t2, space4);
+
+export float4 test()
+{
+return my_buffer[0].Color;
+}
+
+[numthreads(1,1,1)]
+void main() {}
diff --git a/llvm/lib/IR/AsmWriter.cpp b/llvm/lib/IR/AsmWriter.cpp
index 3c1cb76622bbb7..d2705ff4b30fb8 100644
--- a/llvm/lib/IR/AsmWriter.cpp
+++ b/llvm/lib/IR/AsmWriter.cpp
@@ -649,8 +649,14 @@ void TypePrinting::print(Type *Ty, raw_ostream &OS) {
 OS << "target(\"";
 printEscapedString(Ty->getTargetExtName(), OS);
 OS << "\"";
-for (Type *Inner : TETy->type_params())
-  OS << ", " << *Inner;
+for (Type *Inner : TETy->type_params()) {
+  OS << ", ";
+  if (Inner->isStructTy()) {
+StructType *STy = cast(Inner);
+printStructBody(STy, OS);
+  } else
+OS << *Inner;
+}
 for (unsigned IntParam : TETy->int_params())
   OS << ", " << IntParam;
 OS << ")";

>From 69d90f218b9702f4bd194507e54b5af86e38d3b3 Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Wed, 13 Nov 2024 11:55:28 -0800
Subject: [PATCH 2/9] fix runline

---
 clang/test/AST/HLSL/StructuredBuffer-AST-2.hlsl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/test/AST/HLSL/StructuredBuffer-AST-2.hlsl 
b/clang/test/AST/HLSL/StructuredBuffer-AST-2.hlsl
index 73073b3f6f2839..6b71ddd567249f 100644
--- a/clang/test/AST/HLSL/StructuredBuffer-AST-2.hlsl
+++ b/clang/test/AST/HLSL/StructuredBuffer-AST-2.hlsl
@@ -1,4 +1,4 @@
-// RUN: %clang_dxc -T cs_6_6 %s | FileCheck %s
+// RUN: %clang_cc1 -triple dxil-unknown-shadermodel6.6-compute -S 
-finclude-default-header -o - %s | FileCheck %s
 
 // The purpose of this test is to ensure that the AST writer
 // only emits struct bodies when within the context of a 

>From 3a1bdbacf556e2abffc2172721d66291e5f1e3ce Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Wed, 13 Nov 2024 13:54:54 -0800
Subject: [PATCH 3/9] undo change

---
 llvm/lib/IR/AsmWriter.cpp | 10 ++
 1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/llvm/lib/IR/AsmWriter.cpp b/llvm/lib/IR/AsmWriter.cpp
index d2705ff4b30fb8..e1c8fa834984d9 100644
--- a/llvm/lib/IR/AsmWriter.cpp
+++ b/llvm/lib/IR/AsmWriter.cpp
@@ -649,14 +649,8 @@ void TypePrinting::print(Type *Ty, raw_ostream &OS) {
 OS << "target(\"";
 printEscapedString(Ty->getTargetExtName(), OS);
 OS << "\"";
-for (Type *Inner : TETy->type_params()) {
-  OS << ", ";
-  if (Inner->isStructTy()) {
-StructType *STy = cast(Inner);
-printStructBody(STy, OS);
-  } else
-OS << *Inner;
-}
+for (Type *Inner : TETy->type_params()) 
+  OS << ", " << *Inner;
 for (unsigned IntParam : TETy->int_params())
   OS << ", " << IntParam;
 OS << ")";

>From c3e6120c0d3efb7b5aeae864e164976a1d869b6f Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Thu, 21 Nov 2024 17:08:57 -0800
Subject: [PATCH 4/9] convert named to anonymous structs when creating target
 ext types

---
 clang/test/AST/HLSL/StructuredBuffer-AST-2.hlsl |  9 +
 llvm/lib/IR/Type.cpp| 13 +++--
 2 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/clang/test/AST/HLSL/StructuredBuffer-AST-2.hlsl 
b/clang/test/AST/HLSL/StructuredBuffer-AST-2.hlsl
index 6b71ddd567249f..1edec7835f16c7 100644
--- a/clang/test/AST/HLSL/StructuredBuffer-AST-2.hlsl
+++ b/clang/test/AS

[clang] [Clang] Only ignore special methods for unused private fields in BuildFieldReferenceExpr (PR #116965)

2024-11-25 Thread Mészáros Gergely via cfe-commits

https://github.com/Maetveis updated 
https://github.com/llvm/llvm-project/pull/116965

From 0dd94643cd32992e4b54463eea8a73d377b9169e Mon Sep 17 00:00:00 2001
From: Gergely Meszaros 
Date: Wed, 20 Nov 2024 12:55:59 +
Subject: [PATCH 1/2] [Clang] Only ignore special methods for unused private
 fields in BuildFieldReferenceExpr

The original code assumed that only special methods might be defined
as defaulted. Since C++20 comparison operators might be defaulted too,
and we *do* want to consider those as using the fields of the class.

Fixes: #116961
---
 clang/lib/Sema/SemaExprMember.cpp| 12 ++--
 clang/test/SemaCXX/warn-unused-private-field.cpp | 14 ++
 2 files changed, 24 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Sema/SemaExprMember.cpp 
b/clang/lib/Sema/SemaExprMember.cpp
index c32df607692813..46821dc8746b2a 100644
--- a/clang/lib/Sema/SemaExprMember.cpp
+++ b/clang/lib/Sema/SemaExprMember.cpp
@@ -1874,8 +1874,16 @@ Sema::BuildFieldReferenceExpr(Expr *BaseExpr, bool 
IsArrow,
   Context.getAttributedType(attr::NoDeref, MemberType, MemberType);
   }
 
-  auto *CurMethod = dyn_cast(CurContext);
-  if (!(CurMethod && CurMethod->isDefaulted()))
+  auto isDefaultedSpecialMember = [this](const DeclContext *Ctx) {
+auto *Method = dyn_cast(CurContext);
+if (!Method || !Method->isDefaulted())
+  return false;
+
+return getDefaultedFunctionKind(Method).isSpecialMember();
+  };
+
+  // Implicit special members should not mark fields as used.
+  if (!isDefaultedSpecialMember(CurContext))
 UnusedPrivateFields.remove(Field);
 
   ExprResult Base = PerformObjectMemberConversion(BaseExpr, SS.getScopeRep(),
diff --git a/clang/test/SemaCXX/warn-unused-private-field.cpp 
b/clang/test/SemaCXX/warn-unused-private-field.cpp
index 1128eacc309d9f..9913dbaafb7a57 100644
--- a/clang/test/SemaCXX/warn-unused-private-field.cpp
+++ b/clang/test/SemaCXX/warn-unused-private-field.cpp
@@ -20,6 +20,20 @@ class SpaceShipDefaultCompare {
   int operator<=>(const SpaceShipDefaultCompare &) const = default;
 };
 
+class EqDefaultCompareOutOfClass {
+  int used;
+  bool operator==(const EqDefaultCompareOutOfClass &) const;
+};
+
+bool EqDefaultCompareOutOfClass::operator==(const EqDefaultCompareOutOfClass 
&) const = default;
+
+class FriendEqDefaultCompareOutOfClass {
+  int used;
+  friend bool operator==(const FriendEqDefaultCompareOutOfClass &, const 
FriendEqDefaultCompareOutOfClass &);
+};
+
+bool operator==(const FriendEqDefaultCompareOutOfClass &, const 
FriendEqDefaultCompareOutOfClass &) = default;
+
 #endif
 
 class NotFullyDefined {

From af60ae1f09ecd199a9eea99b61595293efe5599f Mon Sep 17 00:00:00 2001
From: Gergely 
Date: Mon, 25 Nov 2024 17:35:03 +
Subject: [PATCH 2/2] Add Release Notes and comments to test

---
 clang/docs/ReleaseNotes.rst  | 2 ++
 clang/test/SemaCXX/warn-unused-private-field.cpp | 4 ++--
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index fcbb3a9e6c6f81..17220e7f41b72b 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -559,6 +559,8 @@ Improvements to Clang's diagnostics
 
 - Clang now diagnoses ``= delete("reason")`` extension warnings only in 
pedantic mode rather than on by default. (#GH109311).
 
+- Fixed a false negative ``-Wunused-private-field`` diagnostic when a 
defaulted comparison operator is defined out of class (#GH116961).
+
 Improvements to Clang's time-trace
 --
 
diff --git a/clang/test/SemaCXX/warn-unused-private-field.cpp 
b/clang/test/SemaCXX/warn-unused-private-field.cpp
index 9913dbaafb7a57..047204e68617a1 100644
--- a/clang/test/SemaCXX/warn-unused-private-field.cpp
+++ b/clang/test/SemaCXX/warn-unused-private-field.cpp
@@ -21,14 +21,14 @@ class SpaceShipDefaultCompare {
 };
 
 class EqDefaultCompareOutOfClass {
-  int used;
+  int used; // no warning
   bool operator==(const EqDefaultCompareOutOfClass &) const;
 };
 
 bool EqDefaultCompareOutOfClass::operator==(const EqDefaultCompareOutOfClass 
&) const = default;
 
 class FriendEqDefaultCompareOutOfClass {
-  int used;
+  int used; // no warning
   friend bool operator==(const FriendEqDefaultCompareOutOfClass &, const 
FriendEqDefaultCompareOutOfClass &);
 };
 

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


[clang] [Driver] Support fprofile-sample-use= for CL (PR #117282)

2024-11-25 Thread Fangrui Song via cfe-commits


@@ -8484,6 +8484,9 @@ def _SLASH_fp_strict : CLFlag<"fp:strict">, HelpText<"">, 
Alias, A
 def _SLASH_fsanitize_EQ_address : CLFlag<"fsanitize=address">,
   HelpText<"Enable AddressSanitizer">,
   Alias, AliasArgs<["address"]>;
+def : CLJoined<"fno-profile-sample-use">, Alias;

MaskRay wrote:

Do we really need these aliases?

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


[clang] [llvm] AMDGPU: MC support for v_cvt_scale_[f16|f32]_bf8 of gfx950. (PR #117381)

2024-11-25 Thread Matt Arsenault via cfe-commits

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


[clang] [clang] Implement P2582R1: CTAD from inherited constructors (PR #98788)

2024-11-25 Thread Erich Keane via cfe-commits

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


[clang] [clang] Implement P2582R1: CTAD from inherited constructors (PR #98788)

2024-11-25 Thread Erich Keane via cfe-commits


@@ -1960,24 +1960,44 @@ class ExplicitSpecifier {
 class CXXDeductionGuideDecl : public FunctionDecl {
   void anchor() override;
 
+public:
+  // Represents the relationship between this deduction guide and the
+  // deduction guide that it was generated from (or lack thereof).
+  // See the SourceDeductionGuide member for more details.
+  enum class SourceDeductionGuideKind : unsigned char {

erichkeane wrote:

```suggestion
  enum class SourceDeductionGuideKind : uint8_t {
```

I thought I saw elsewhere we do this reasonably consistently?  Else, feel free 
to ignore.

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


[clang] [clang] Implement P2582R1: CTAD from inherited constructors (PR #98788)

2024-11-25 Thread Erich Keane via cfe-commits


@@ -2246,18 +2246,21 @@ CXXDeductionGuideDecl *CXXDeductionGuideDecl::Create(
 ASTContext &C, DeclContext *DC, SourceLocation StartLoc,
 ExplicitSpecifier ES, const DeclarationNameInfo &NameInfo, QualType T,
 TypeSourceInfo *TInfo, SourceLocation EndLocation, CXXConstructorDecl 
*Ctor,
-DeductionCandidate Kind, Expr *TrailingRequiresClause) {
-  return new (C, DC)
-  CXXDeductionGuideDecl(C, DC, StartLoc, ES, NameInfo, T, TInfo,
-EndLocation, Ctor, Kind, TrailingRequiresClause);
+DeductionCandidate Kind, Expr *TrailingRequiresClause,
+const CXXDeductionGuideDecl *GeneratedFrom,
+SourceDeductionGuideKind SourceKind) {
+  return new (C, DC) CXXDeductionGuideDecl(
+  C, DC, StartLoc, ES, NameInfo, T, TInfo, EndLocation, Ctor, Kind,
+  TrailingRequiresClause, GeneratedFrom, SourceKind);
 }
 
 CXXDeductionGuideDecl *
 CXXDeductionGuideDecl::CreateDeserialized(ASTContext &C, GlobalDeclID ID) {
   return new (C, ID) CXXDeductionGuideDecl(

erichkeane wrote:

For `Expr`s we usually have a `CreateEmpty` that has an `empty`/`empty-ish` 
private constructor associated with it. or something like that this is very 
much making me wish we had the same for this one.

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


[clang] [clang] Implement P2582R1: CTAD from inherited constructors (PR #98788)

2024-11-25 Thread Erich Keane via cfe-commits


@@ -942,34 +946,145 @@ getRHSTemplateDeclAndArgs(Sema &SemaRef, 
TypeAliasTemplateDecl *AliasTemplate) {
   return {Template, AliasRhsTemplateArgs};
 }
 
+struct InheritedConstructorDeductionInfo {
+  // Class template for which we are declaring deduction guides
+  // This is `C` in the standard wording
+  TemplateDecl *DerivedClassTemplate;
+
+  // `template CC` in the standard wording
+  // This is the type of template that is substituted in the deduction guide
+  // return type `CC`
+  TypeSourceInfo *CCType;
+};
+
+// Build the function type and return type for a deduction guide generated from
+// an inherited constructor C++23 [over.match.class.deduct]p1.10:
+// ... the set contains the guides of A with the return type R
+// of each guide replaced with `typename CC::type` ...
+std::pair
+buildInheritedConstructorDeductionGuideType(
+Sema &SemaRef, const InheritedConstructorDeductionInfo &Info,
+TypeSourceInfo *SourceGuideTSI) {
+  ASTContext &Context = SemaRef.Context;
+  const auto *FPT = SourceGuideTSI->getType()->getAs();
+  assert(FPT && "Source Guide type should be a FunctionProtoType");
+
+  // This substitution can fail in cases where the source return type
+  // is not dependent and the derived class is not deducible
+  // FIXME: There is currently no diagnostic emitted in this case,
+  // as it is nontrivial to propagate substitution failure messages up
+  // to the point where deduction guides are used-- we do not have a type
+  // with which we can create a deduction guide AST node and must encode the
+  // SFINAE message.
+  Sema::SFINAETrap Trap(SemaRef);
+
+  MultiLevelTemplateArgumentList Args;
+  Args.addOuterTemplateArguments(Info.DerivedClassTemplate,
+ TemplateArgument(FPT->getReturnType()),
+ /*Final=*/false);
+  Args.addOuterRetainedLevels(Info.DerivedClassTemplate->getTemplateDepth());

erichkeane wrote:

As we sure this is sufficient and shouldn't be calling the 
`getInstantiationArgs`?  It might need help with Deduction guides, but is meant 
to get the full depth of the deduction guide.  But `OuterRetainedLevels` means 
it won't fully instantiate (and those levels will just not fill anything in).  
Though is that perhaps what is intended here?

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


[clang] [clang] Implement P2582R1: CTAD from inherited constructors (PR #98788)

2024-11-25 Thread Erich Keane via cfe-commits

https://github.com/erichkeane commented:

I don't think I'm needed on this review again, but did a pass through and had 
some comments/suggestions.  Nothing binding, so I'll let others discuss 
this/accept this.

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


[clang] [clang] Implement P2582R1: CTAD from inherited constructors (PR #98788)

2024-11-25 Thread Erich Keane via cfe-commits


@@ -2010,6 +2032,25 @@ class CXXDeductionGuideDecl : public FunctionDecl {
   /// this is an implicit deduction guide.
   CXXConstructorDecl *getCorrespondingConstructor() const { return Ctor; }
 
+  /// Get the deduction guide from which this deduction guide was generated,
+  /// if it was generated as part of alias template deduction or from an
+  /// inherited constructor.
+  const CXXDeductionGuideDecl *getSourceDeductionGuide() const {
+return SourceDeductionGuide.getPointer();
+  }
+
+  void setSourceDeductionGuide(CXXDeductionGuideDecl *DG) {
+SourceDeductionGuide.setPointer(DG);

erichkeane wrote:

Do we want to assert for `!DG`?

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


[clang] [clang] Implement P2582R1: CTAD from inherited constructors (PR #98788)

2024-11-25 Thread Erich Keane via cfe-commits


@@ -942,34 +946,145 @@ getRHSTemplateDeclAndArgs(Sema &SemaRef, 
TypeAliasTemplateDecl *AliasTemplate) {
   return {Template, AliasRhsTemplateArgs};
 }
 
+struct InheritedConstructorDeductionInfo {
+  // Class template for which we are declaring deduction guides
+  // This is `C` in the standard wording

erichkeane wrote:

Comments are supposed to end in full-stops, so I think there is a sprinkling of 
`.` required here/elsewhere here (other than standards quotes).

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


[clang] [clang] Implement P2582R1: CTAD from inherited constructors (PR #98788)

2024-11-25 Thread Erich Keane via cfe-commits


@@ -10615,6 +10615,40 @@ bool clang::isBetterOverloadCandidate(
 auto *Guide1 = dyn_cast_or_null(Cand1.Function);
 auto *Guide2 = dyn_cast_or_null(Cand2.Function);
 if (Guide1 && Guide2) {
+  //  -- F1 and F2 are generated from class template argument deduction
+  //  for a class D, and F2 is generated from inheriting constructors
+  //  from a base class of D while F1 is not, ...
+  bool G1Inherited = Guide1->getSourceDeductionGuide() &&
+ Guide1->getSourceDeductionGuideKind() ==
+ CXXDeductionGuideDecl::SourceDeductionGuideKind::
+ InheritedConstructor;
+  bool G2Inherited = Guide2->getSourceDeductionGuide() &&
+ Guide2->getSourceDeductionGuideKind() ==
+ CXXDeductionGuideDecl::SourceDeductionGuideKind::
+ InheritedConstructor;
+  if (Guide1->isImplicit() && Guide2->isImplicit() &&
+  G1Inherited != G2Inherited) {
+const FunctionProtoType *FPT1 =
+Guide1->getType()->getAs();
+const FunctionProtoType *FPT2 =
+Guide2->getType()->getAs();
+assert(FPT1 && FPT2);
+
+// ... and for each explicit function argument, the parameters of F1 
and
+// F2 are either both ellipses or have the same type
+if (FPT1->isVariadic() == FPT2->isVariadic() &&
+FPT1->getNumParams() == FPT2->getNumParams()) {

erichkeane wrote:

Is there a reason we can't just check the types of the functions here instead?  
I would assume their prototypes to compare equal.  That said, the wording of 
`parameters are both ellipses or have the same type` seems intentionally 
designed for the purpose of excluding the return type (or, perhaps reference/cv 
specifiers?)?  

If so, I think I'd rather a variant of `hasSameType` that for something like, 
`hasSameParameterList`.  At that point, we could have IT check for similar 
variadics as well. We probably want to make sure that `(int, ...)` works too.

Also, I don't think the initial check is right?  Shouldn't that be an 'or' 
there instead of '&&'?  If both are `NumParams == 0 && isVariadic`, then we 
want to hit this condition as well.

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


[clang] [llvm] AMDGPU: MC support for v_cvt_scalef32_pk_{fp8|bf8}_f32 of gfx950. (PR #117382)

2024-11-25 Thread Matt Arsenault via cfe-commits

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


[clang] [clang] Allow delayed function instantiation at TU end if initial instantiation fails (PR #117167)

2024-11-25 Thread Erich Keane via cfe-commits


@@ -0,0 +1,26 @@
+// RUN: %clang_cc1 -std=c++20 -verify %s
+// expected-no-diagnostics
+
+template 
+auto foo(T const& arg) -> T;
+
+template 
+auto dispatch(Fp fp, Vis vis) {
+  return fp(vis);
+}
+
+auto baz(int v) {
+  auto callable = [](Arg const& arg) -> int {
+return foo(arg);
+  };
+  return dispatch(callable, v);
+}
+
+template 
+auto foo(T const& arg) -> T {
+  return arg;
+}
+
+int main() {
+  return baz(5);
+}

erichkeane wrote:

newline needed at the end of test.  

Also, would like to see a codegen test that shows that we are properly 
generating the right instantiations.

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


[clang] [Clang] [Parser] Fixing all callers of `ParseExternalDeclaration` that didn't parse gnu attributes (PR #117148)

2024-11-25 Thread Mathys Gasnier via cfe-commits


@@ -2314,10 +2314,12 @@ Parser::DeclGroupPtrTy 
Parser::ParseOpenMPDeclarativeDirectiveWithExtDecl(
   // Here we expect to see some function declaration.
   if (AS == AS_none) {
 assert(TagType == DeclSpec::TST_unspecified);
-ParsedAttributes EmptyDeclSpecAttrs(AttrFactory);
-MaybeParseCXX11Attributes(Attrs);
+ParsedAttributes DeclSpecAttrs(AttrFactory);

Mathys-Gasnier wrote:

Because `Attrs` is not a local variable but an argument passed to 
`ParseOpenMPDeclarativeDirectiveWithExtDecl`

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


[clang] [llvm] [ARM] Emit an error when the hard-float ABI is enabled but can't be used. (PR #111334)

2024-11-25 Thread Peter Smith via cfe-commits


@@ -16,7 +16,7 @@
 
 // RUN: %clang --target=arm-none-eabi -mcpu=cortex-m33 -mfloat-abi=hard -O1 %s 
-flto=thin -c -o %t.call_thin.bc -DCALL_LIB
 // RUN: %clang --target=arm-none-eabi -mcpu=cortex-m33 -mfloat-abi=hard -O1 %s 
-flto=thin -c -o %t.define_thin.bc -DDEFINE_LIB
-// RUN: llvm-lto2 run -o %t.lto_thin -save-temps %t.call_thin.bc 
%t.define_thin.bc \
+// RUN: llvm-lto2 run --mcpu=cortex-m33 --float-abi=hard -o %t.lto_thin 
-save-temps %t.call_thin.bc %t.define_thin.bc \

smithp35 wrote:

Thanks for the investigation. I think that this use case of LTO needs to work 
without an error as while we can provide the target for this specific test 
case, it may cause other uses of LTO without a target on the linker driver to 
fail. This may mean that we have to fix this in LTO.

>From git annotate the test case was added in https://reviews.llvm.org/D89573 
>ostensibly to make sure that if LTO calls a C function it uses the correct ABI.

Looking at llvm.lifetime.start this is a lifetime marker intrinsic 
https://llvm.org/docs/LangRef.html#llvm-lifetime-start-intrinsic . IIUC 
lifetime markers are for communicating lifetimes of objects to optimisers, so 
while they influence code-generation they don't get code generated for them.

It may be an area where the subtarget for the function isn't being passed 
through correctly, although in the case of lifetime markers it is benign. This 
is an area that needs a lot more in depth expertise of LLVM and LTO than I 
posess. I can ask around internally to see if anyone is willing to take a look.

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


[clang] [clang] Allow delayed function instantiation at TU end if initial instantiation fails (PR #117167)

2024-11-25 Thread Erich Keane via cfe-commits

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


[clang] [clang] Allow delayed function instantiation at TU end if initial instantiation fails (PR #117167)

2024-11-25 Thread Erich Keane via cfe-commits

https://github.com/erichkeane commented:

I am not particularly comfortable/knowledgable in how this all works, but I 
don't see a problem here.

My current concern is that we're going to get the same error 2x for the same 
failed instantiation, and that seems unfortunate.

Also, we need a release note.

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


[clang] [clang] Allow delayed function instantiation at TU end if initial instantiation fails (PR #117167)

2024-11-25 Thread Erich Keane via cfe-commits


@@ -13523,7 +13525,9 @@ class Sema final : public SemaBase {
   S.PendingLocalImplicitInstantiations);
 }
 
-void perform() { S.PerformPendingInstantiations(/*LocalOnly=*/true); }
+void perform() {

erichkeane wrote:

unrelated formatting change.

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


[clang] [Clang] Permit noescape on non-pointer types (PR #117344)

2024-11-25 Thread Erich Keane via cfe-commits


@@ -1,7 +1,12 @@
 // RUN: %clang_cc1 -fsyntax-only -verify %s
 
+// expected-no-diagnostics
+
 template
 void test1(T __attribute__((noescape)) arr, int size);
 
-// expected-warning@+1 {{'noescape' attribute only applies to pointer 
arguments}}
-void test2(int __attribute__((noescape)) arr, int size);
\ No newline at end of file
+void test2(int __attribute__((noescape)) arr, int size);
+
+#if !__has_feature(attribute_noescape_nonpointer)

erichkeane wrote:

I don't get this macro/error here.  This will never happen in clang, we support 
this feature.

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


[clang] [Clang] Permit noescape on non-pointer types (PR #117344)

2024-11-25 Thread Erich Keane via cfe-commits

https://github.com/erichkeane commented:

I see you've enabled it, but the tests don't actually show that this has any 
effect besides suppressing a diagnostic.  I want to see something that shows 
that the attribute is actually DOING something on non-pointer types.

Also, requires a release note.

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


[clang] [Clang] Permit noescape on non-pointer types (PR #117344)

2024-11-25 Thread Erich Keane via cfe-commits

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


[clang] [Clang] [Parser] Fixing all callers of `ParseExternalDeclaration` that didn't parse gnu attributes (PR #117148)

2024-11-25 Thread Mathys Gasnier via cfe-commits


@@ -480,10 +468,7 @@ Decl *Parser::ParseExportDeclaration() {
 
   while (!tryParseMisplacedModuleImport() && Tok.isNot(tok::r_brace) &&
  Tok.isNot(tok::eof)) {
-ParsedAttributes DeclAttrs(AttrFactory);
-MaybeParseCXX11Attributes(DeclAttrs);

Mathys-Gasnier wrote:

Probably not, some place still use it, and we aren't able to replace it with 
the new function due to branching depending on different tokens. For example 
see ParseDeclCXX.cpp in `ParseLinkage`

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


[clang] [Clang] [Parser] Fixing all callers of `ParseExternalDeclaration` that didn't parse gnu attributes (PR #117148)

2024-11-25 Thread Erich Keane via cfe-commits


@@ -2314,10 +2314,12 @@ Parser::DeclGroupPtrTy 
Parser::ParseOpenMPDeclarativeDirectiveWithExtDecl(
   // Here we expect to see some function declaration.
   if (AS == AS_none) {
 assert(TagType == DeclSpec::TST_unspecified);
-ParsedAttributes EmptyDeclSpecAttrs(AttrFactory);
-MaybeParseCXX11Attributes(Attrs);
+ParsedAttributes DeclSpecAttrs(AttrFactory);

erichkeane wrote:

Ah!  I missed that, thanks!  @alexey-bataev : Are we sure this is intentional?  
Basically, we perhaps should be parsing these attributes 'together', and it 
isn't clear to me looking at this that this doesn't 'fix' a bug/should have 
some attention.

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


[clang] [clang][bytecode] Handle bitcasts involving bitfields (PR #116843)

2024-11-25 Thread Timm Baeder via cfe-commits
Timm =?utf-8?q?B=C3=A4der?= 
Message-ID:
In-Reply-To: 


tbaederr wrote:

Ping

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


[clang] [llvm] [HLSL] Disallow named struct types as parameters in target extension types (PR #115971)

2024-11-25 Thread Joshua Batista via cfe-commits

https://github.com/bob80905 updated 
https://github.com/llvm/llvm-project/pull/115971

>From 7413ceb21a6e0ac9212ef6317763ee0eff559612 Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Tue, 12 Nov 2024 16:44:00 -0800
Subject: [PATCH 01/10] print struct body within target ext ty context

---
 .../test/AST/HLSL/StructuredBuffer-AST-2.hlsl | 30 +++
 llvm/lib/IR/AsmWriter.cpp | 10 +--
 2 files changed, 38 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/AST/HLSL/StructuredBuffer-AST-2.hlsl

diff --git a/clang/test/AST/HLSL/StructuredBuffer-AST-2.hlsl 
b/clang/test/AST/HLSL/StructuredBuffer-AST-2.hlsl
new file mode 100644
index 00..73073b3f6f2839
--- /dev/null
+++ b/clang/test/AST/HLSL/StructuredBuffer-AST-2.hlsl
@@ -0,0 +1,30 @@
+// RUN: %clang_dxc -T cs_6_6 %s | FileCheck %s
+
+// The purpose of this test is to ensure that the AST writer
+// only emits struct bodies when within the context of a 
+// larger object that is being outputted on the RHS.
+
+
+// note that "{ <4 x float> }" in the check below is a struct type, but only 
the
+// body is emitted on the RHS because we are already in the context of a
+// target extension type definition (class.hlsl::StructuredBuffer)
+// CHECK: %"class.hlsl::StructuredBuffer" = type { target("dx.RawBuffer", { <4 
x float> }, 0, 0), %struct.mystruct }
+// CHECK: %struct.mystruct = type { <4 x float> }
+// CHECK: %dx.types.Handle = type { ptr }
+// CHECK: %dx.types.ResBind = type { i32, i32, i32, i8 }
+// CHECK: %dx.types.ResourceProperties = type { i32, i32 }
+
+struct mystruct
+{
+float4 Color;
+};
+
+StructuredBuffer my_buffer : register(t2, space4);
+
+export float4 test()
+{
+return my_buffer[0].Color;
+}
+
+[numthreads(1,1,1)]
+void main() {}
diff --git a/llvm/lib/IR/AsmWriter.cpp b/llvm/lib/IR/AsmWriter.cpp
index 3c1cb76622bbb7..d2705ff4b30fb8 100644
--- a/llvm/lib/IR/AsmWriter.cpp
+++ b/llvm/lib/IR/AsmWriter.cpp
@@ -649,8 +649,14 @@ void TypePrinting::print(Type *Ty, raw_ostream &OS) {
 OS << "target(\"";
 printEscapedString(Ty->getTargetExtName(), OS);
 OS << "\"";
-for (Type *Inner : TETy->type_params())
-  OS << ", " << *Inner;
+for (Type *Inner : TETy->type_params()) {
+  OS << ", ";
+  if (Inner->isStructTy()) {
+StructType *STy = cast(Inner);
+printStructBody(STy, OS);
+  } else
+OS << *Inner;
+}
 for (unsigned IntParam : TETy->int_params())
   OS << ", " << IntParam;
 OS << ")";

>From 69d90f218b9702f4bd194507e54b5af86e38d3b3 Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Wed, 13 Nov 2024 11:55:28 -0800
Subject: [PATCH 02/10] fix runline

---
 clang/test/AST/HLSL/StructuredBuffer-AST-2.hlsl | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/test/AST/HLSL/StructuredBuffer-AST-2.hlsl 
b/clang/test/AST/HLSL/StructuredBuffer-AST-2.hlsl
index 73073b3f6f2839..6b71ddd567249f 100644
--- a/clang/test/AST/HLSL/StructuredBuffer-AST-2.hlsl
+++ b/clang/test/AST/HLSL/StructuredBuffer-AST-2.hlsl
@@ -1,4 +1,4 @@
-// RUN: %clang_dxc -T cs_6_6 %s | FileCheck %s
+// RUN: %clang_cc1 -triple dxil-unknown-shadermodel6.6-compute -S 
-finclude-default-header -o - %s | FileCheck %s
 
 // The purpose of this test is to ensure that the AST writer
 // only emits struct bodies when within the context of a 

>From 3a1bdbacf556e2abffc2172721d66291e5f1e3ce Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Wed, 13 Nov 2024 13:54:54 -0800
Subject: [PATCH 03/10] undo change

---
 llvm/lib/IR/AsmWriter.cpp | 10 ++
 1 file changed, 2 insertions(+), 8 deletions(-)

diff --git a/llvm/lib/IR/AsmWriter.cpp b/llvm/lib/IR/AsmWriter.cpp
index d2705ff4b30fb8..e1c8fa834984d9 100644
--- a/llvm/lib/IR/AsmWriter.cpp
+++ b/llvm/lib/IR/AsmWriter.cpp
@@ -649,14 +649,8 @@ void TypePrinting::print(Type *Ty, raw_ostream &OS) {
 OS << "target(\"";
 printEscapedString(Ty->getTargetExtName(), OS);
 OS << "\"";
-for (Type *Inner : TETy->type_params()) {
-  OS << ", ";
-  if (Inner->isStructTy()) {
-StructType *STy = cast(Inner);
-printStructBody(STy, OS);
-  } else
-OS << *Inner;
-}
+for (Type *Inner : TETy->type_params()) 
+  OS << ", " << *Inner;
 for (unsigned IntParam : TETy->int_params())
   OS << ", " << IntParam;
 OS << ")";

>From c3e6120c0d3efb7b5aeae864e164976a1d869b6f Mon Sep 17 00:00:00 2001
From: Joshua Batista 
Date: Thu, 21 Nov 2024 17:08:57 -0800
Subject: [PATCH 04/10] convert named to anonymous structs when creating target
 ext types

---
 clang/test/AST/HLSL/StructuredBuffer-AST-2.hlsl |  9 +
 llvm/lib/IR/Type.cpp| 13 +++--
 2 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/clang/test/AST/HLSL/StructuredBuffer-AST-2.hlsl 
b/clang/test/AST/HLSL/StructuredBuffer-AST-2.hlsl
index 6b71ddd567249f..1edec7835f16c7 100644
--- a/clang/test/AST/HLSL/StructuredBuffer-AST-2.hlsl
+++ b/clang

[clang] [llvm] [X86] Enhance kCFI type IDs with a 3-bit arity indicator. (PR #117121)

2024-11-25 Thread Scott Constable via cfe-commits


@@ -208,10 +209,34 @@ void llvm::setKCFIType(Module &M, Function &F, StringRef 
MangledType) {
   std::string Type = MangledType.str();
   if (M.getModuleFlag("cfi-normalize-integers"))
 Type += ".normalized";
+
+  uint32_t OutHash = static_cast(llvm::xxHash64(Type));
+  auto T = Triple(Twine(M.getTargetTriple()));
+  if (T.isX86() && T.isArch64Bit() && T.isOSLinux()) {
+// Estimate the function's arity (i.e., the number of arguments) at the ABI
+// level by counting the number of parameters that are likely to be passed
+// as registers, such as pointers and 64-bit (or smaller) integers. The
+// Linux x86-64 ABI allows up to 6 parameters to be passed in GPRs.
+// Additional parameters or parameters larger than 64 bits may be passed on
+// the stack, in which case the arity is denoted as 7.
+size_t NumParams = F.arg_size();
+bool MayHaveStackArgs = NumParams > 6;
+
+for (unsigned int i = 0; !MayHaveStackArgs && i < NumParams; ++i) {
+  const llvm::Type *PT = F.getArg(i)->getType();
+  if (!(PT->isPointerTy() || PT->getIntegerBitWidth() <= 64))

scottconstable wrote:

Hi @phoebewang, KCFI only computes hashes for indirect calls, not direct ones. 
The example you cited uses `CallBase::getCalledFunction()`, whose documentation 
reads "Returns the function called, or null if this is an indirect function 
invocation or the function signature does not match the call signature."

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


[clang] bb88fd1 - [DirectX] Calculate resource binding offsets using the lower bound (#117303)

2024-11-25 Thread via cfe-commits

Author: Justin Bogner
Date: 2024-11-25T10:44:01-08:00
New Revision: bb88fd171a6be892cec36969860a9034b48b8656

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

LOG: [DirectX] Calculate resource binding offsets using the lower bound 
(#117303)

In the DXIL CreateHandle and CreateHandleFromBinding ops, resource
bindings are
indexed from the beginning of the binding space, not from the binding
itself.
Translate from an index into the binding to one from the beginning of
the space
when lowering to these operations.

Added: 
clang/test/CodeGenHLSL/resource-bindings.hlsl

Modified: 
llvm/docs/DirectX/DXILResources.rst
llvm/lib/Target/DirectX/DXILOpLowering.cpp
llvm/test/CodeGen/DirectX/CreateHandle.ll
llvm/test/CodeGen/DirectX/CreateHandleFromBinding.ll

Removed: 




diff  --git a/clang/test/CodeGenHLSL/resource-bindings.hlsl 
b/clang/test/CodeGenHLSL/resource-bindings.hlsl
new file mode 100644
index 00..bfec90e1871f8b
--- /dev/null
+++ b/clang/test/CodeGenHLSL/resource-bindings.hlsl
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -triple dxil--shadermodel6.6-compute -x hlsl 
-finclude-default-header -emit-llvm -o - %s | FileCheck %s
+
+// CHECK: define internal void @_init_resource_bindings() {
+
+// CHECK: %U0S0_h = call target("dx.TypedBuffer", <4 x float>, 1, 0, 0) 
@llvm.dx.handle.fromBinding.tdx.TypedBuffer_v4f32_1_0_0t(i32 0, i32 0, i32 1, 
i32 0, i1 false)
+RWBuffer U0S0 : register(u0);
+
+// CHECK: %U5S3_h = call target("dx.TypedBuffer", float, 1, 0, 0) 
@llvm.dx.handle.fromBinding.tdx.TypedBuffer_f32_1_0_0t(i32 3, i32 5, i32 1, i32 
0, i1 false)
+RWBuffer U5S3 : register(u5, space3);
+
+// CHECK: %T2S2_h = call target("dx.RawBuffer", i32, 0, 0) 
@llvm.dx.handle.fromBinding.tdx.RawBuffer_i32_0_0t(i32 2, i32 2, i32 1, i32 0, 
i1 false)
+StructuredBuffer T2S2 : register(t2, space2);
+struct S {
+  float4 f;
+  int i;
+};
+
+// CHECK: %T3S0_h = call target("dx.RawBuffer", %struct.S = type { <4 x 
float>, i32, [12 x i8] }, 0, 0) 
@llvm.dx.handle.fromBinding.tdx.RawBuffer_s_struct.Ss_0_0t(i32 0, i32 3, i32 1, 
i32 0, i1 false)
+StructuredBuffer T3S0 : register(t3);

diff  --git a/llvm/docs/DirectX/DXILResources.rst 
b/llvm/docs/DirectX/DXILResources.rst
index ad8ede9c59fbfa..dcec9611d8aaa0 100644
--- a/llvm/docs/DirectX/DXILResources.rst
+++ b/llvm/docs/DirectX/DXILResources.rst
@@ -162,9 +162,10 @@ the subsequent ``dx.op.annotateHandle`` operation in. Note 
that we don't have
 an analogue for `dx.op.createHandle`_, since ``dx.op.createHandleFromBinding``
 subsumes it.
 
-For simplicity of lowering, we match DXIL in using an index from the beginning
-of the binding space rather than an index from the lower bound of the binding
-itself.
+We diverge from DXIL and index from the beginning of the binding rather than
+indexing from the beginning of the binding space. This matches the semantics
+more clearly and avoids a non-obvious invariant in what constitutes valid
+arguments.
 
 .. _dx.op.createHandle: 
https://github.com/microsoft/DirectXShaderCompiler/blob/main/docs/DXIL.rst#resource-handles
 
@@ -194,7 +195,7 @@ itself.
* - ``%index``
  - 4
  - ``i32``
- - Index from the beginning of the binding space to access.
+ - Index from the beginning of the binding.
* - ``%non-uniform``
  - 5
  - i1
@@ -233,6 +234,12 @@ Examples:
@llvm.dx.handle.fromBinding.tdx.RawBuffer_i8_0_0t(
i32 1, i32 8, i32 1, i32 0, i1 false)
 
+   ; RWBuffer Global[3] : register(u6, space5)
+   ; RWBuffer Buf = Global[2];
+   %buf = call target("dx.TypedBuffer", <4 x float>, 1, 0, 0)
+   @llvm.dx.handle.fromBinding.tdx.TypedBuffer_f32_1_0(
+   i32 5, i32 6, i32 3, i32 2, i1 false)
+
 .. list-table:: ``@llvm.dx.handle.fromHeap``
:header-rows: 1
 

diff  --git a/llvm/lib/Target/DirectX/DXILOpLowering.cpp 
b/llvm/lib/Target/DirectX/DXILOpLowering.cpp
index 9f124394363a38..047c5412e1f3ae 100644
--- a/llvm/lib/Target/DirectX/DXILOpLowering.cpp
+++ b/llvm/lib/Target/DirectX/DXILOpLowering.cpp
@@ -236,9 +236,14 @@ class OpLowerer {
   dxil::ResourceInfo &RI = *It;
   const auto &Binding = RI.getBinding();
 
+  Value *IndexOp = CI->getArgOperand(3);
+  if (Binding.LowerBound != 0)
+IndexOp = IRB.CreateAdd(IndexOp,
+ConstantInt::get(Int32Ty, Binding.LowerBound));
+
   std::array Args{
   ConstantInt::get(Int8Ty, llvm::to_underlying(RI.getResourceClass())),
-  ConstantInt::get(Int32Ty, Binding.RecordID), CI->getArgOperand(3),
+  ConstantInt::get(Int32Ty, Binding.RecordID), IndexOp,
   CI->getArgOperand(4)};
   Expected OpCall =
   OpBuilder.tryCreateOp(OpCode::CreateHandle, Args, CI->getName());
@@ -257,6 +262

[clang] [llvm] [DirectX] Calculate resource binding offsets using the lower bound (PR #117303)

2024-11-25 Thread Justin Bogner via cfe-commits

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


[clang] Enable AST mutation in the constant evaluator (PR #115168)

2024-11-25 Thread Vlad Serebrennikov via cfe-commits

https://github.com/Endilll updated 
https://github.com/llvm/llvm-project/pull/115168

>From 5ca48e03412b1b8e9253f13356b9cc957f6fd9e5 Mon Sep 17 00:00:00 2001
From: Vlad Serebrennikov 
Date: Wed, 6 Nov 2024 17:58:43 +0300
Subject: [PATCH 01/13] Add EvalASTMutator interface with
 `InstantiateFunctionDefinition` function

---
 clang/include/clang/AST/ASTContext.h  |  2 +-
 clang/include/clang/AST/Decl.h| 22 ++---
 clang/include/clang/AST/Expr.h|  3 +-
 clang/include/clang/Sema/Sema.h   | 17 ++
 clang/lib/AST/ASTContext.cpp  |  4 +--
 clang/lib/AST/Decl.cpp| 16 +-
 clang/lib/AST/ExprConstant.cpp| 24 +++---
 clang/lib/Sema/Sema.cpp   | 11 ++-
 clang/lib/Sema/SemaDecl.cpp   |  5 +--
 .../constexpr-function-instantiation.cpp  | 31 +++
 10 files changed, 113 insertions(+), 22 deletions(-)
 create mode 100644 clang/test/SemaCXX/constexpr-function-instantiation.cpp

diff --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index a4d36f2eacd5d1..d143591de9f2cd 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -3258,7 +3258,7 @@ class ASTContext : public RefCountedBase {
   ///
   /// \returns true if the function/var must be CodeGen'ed/deserialized even if
   /// it is not used.
-  bool DeclMustBeEmitted(const Decl *D);
+  bool DeclMustBeEmitted(const Decl *D, EvalASTMutator *ASTMutator = nullptr);
 
   /// Visits all versions of a multiversioned function with the passed
   /// predicate.
diff --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h
index 7ff35d73df5997..89a2833c82194d 100644
--- a/clang/include/clang/AST/Decl.h
+++ b/clang/include/clang/AST/Decl.h
@@ -78,6 +78,18 @@ class UnresolvedSetImpl;
 class VarTemplateDecl;
 enum class ImplicitParamKind;
 
+/// Interface that allows constant evaluator to mutate AST.
+/// When constant evaluation is triggered by Sema, it can supply a proper
+/// implementation of this interface.
+struct EvalASTMutator {
+  virtual ~EvalASTMutator() = default;
+
+  virtual void
+  InstantiateFunctionDefinition(SourceLocation PointOfInstantiation,
+FunctionDecl *Function, bool Recursive,
+bool DefinitionRequired, bool AtEndOfTU) = 0;
+};
+
 /// The top declaration context.
 class TranslationUnitDecl : public Decl,
 public DeclContext,
@@ -1355,11 +1367,12 @@ class VarDecl : public DeclaratorDecl, public 
Redeclarable {
   /// Attempt to evaluate the value of the initializer attached to this
   /// declaration, and produce notes explaining why it cannot be evaluated.
   /// Returns a pointer to the value if evaluation succeeded, 0 otherwise.
-  APValue *evaluateValue() const;
+  APValue *evaluateValue(EvalASTMutator *ASTMutator = nullptr) const;
 
 private:
   APValue *evaluateValueImpl(SmallVectorImpl &Notes,
- bool IsConstantInitialization) const;
+ bool IsConstantInitialization,
+ EvalASTMutator *ASTMutator = nullptr) const;
 
 public:
   /// Return the already-evaluated value of this variable's
@@ -1391,8 +1404,9 @@ class VarDecl : public DeclaratorDecl, public 
Redeclarable {
   /// Evaluate the initializer of this variable to determine whether it's a
   /// constant initializer. Should only be called once, after completing the
   /// definition of the variable.
-  bool checkForConstantInitialization(
-  SmallVectorImpl &Notes) const;
+  bool
+  checkForConstantInitialization(SmallVectorImpl &Notes,
+ EvalASTMutator *ASTMutator = nullptr) const;
 
   void setInitStyle(InitializationStyle Style) {
 VarDeclBits.InitStyle = Style;
diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index 466c65a9685ad3..ccf7fd226b5a8f 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -734,7 +734,8 @@ class Expr : public ValueStmt {
   bool EvaluateAsInitializer(APValue &Result, const ASTContext &Ctx,
  const VarDecl *VD,
  SmallVectorImpl &Notes,
- bool IsConstantInitializer) const;
+ bool IsConstantInitializer,
+ EvalASTMutator *ASTMutator = nullptr) const;
 
   /// EvaluateWithSubstitution - Evaluate an expression as if from the context
   /// of a call to the given function with the given arguments, inside an
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 93d98e1cbb9c81..1c0c6949573335 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -153,6 +153,7 @@ enum class OverloadCandidateParamOrder : char;
 enum OverloadCandidateRew

[clang] [ObjC] Enable diagnose_if on Objective-C methods (PR #115056)

2024-11-25 Thread Erich Keane via cfe-commits


@@ -515,26 +515,94 @@ namespace {
 Call
   };
 
+  /// Either a FunctionDecl or an ObjCMethodDecl. This struct papers over the
+  /// fact that their common ancestors are DeclContext and NamedDecl, which
+  /// does not allow the enumeration of their parameters very easily.
+  class CallableDecl {

erichkeane wrote:

This type seems unnecessary.  We have some variant-like tagged-union types that 
would just as easily be usable here. Easiest is probably `llvm::PointerUnion`.

That said, there is interest I thought in representing `callable` at the AST 
level.  Though, I'm not sure how much lambdas, functions, methods, ObjC 
Methods, Blocks, etc share that would make this worth-while.

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


[clang] [llvm] [RISCV] Add stack clash protection (PR #117612)

2024-11-25 Thread Raphael Moreira Zinsly via cfe-commits

https://github.com/rzinsly created 
https://github.com/llvm/llvm-project/pull/117612

Enable `-fstack-clash-protection` for RISCV and stack probe for function 
prologues.
We probe the stack by creating a loop that allocates and probe the stack in 
ProbeSize chunks.
We emit an unrolled probe loop for small allocations and emit a variable length 
probe loop for bigger ones.

>From d17432b5a6c6d7b5de662726c15919e5ad242e87 Mon Sep 17 00:00:00 2001
From: Raphael Moreira Zinsly 
Date: Mon, 25 Nov 2024 14:51:35 -0300
Subject: [PATCH 1/2] [RISCV] Add initial stack clash protection

Enable `-fstack-clash-protection` for RISCV and stack probe for function
prologues.
We probe the stack by creating an unrolled loop that allocates and probe
the stack in ProbeSize chunks, this is not ideal if the loop has many
iterations.
---
 clang/lib/Driver/ToolChains/Clang.cpp |  3 +-
 llvm/lib/Target/RISCV/RISCVFrameLowering.cpp  | 93 ++-
 llvm/lib/Target/RISCV/RISCVFrameLowering.h|  4 +-
 llvm/lib/Target/RISCV/RISCVISelLowering.cpp   | 22 +
 llvm/lib/Target/RISCV/RISCVISelLowering.h |  6 ++
 .../Target/RISCV/RISCVMachineFunctionInfo.cpp | 30 ++
 .../Target/RISCV/RISCVMachineFunctionInfo.h   |  7 +-
 llvm/lib/Target/RISCV/RISCVTargetMachine.cpp  |  4 +-
 .../RISCV/stack-clash-prologue-nounwind.ll| 47 ++
 .../CodeGen/RISCV/stack-clash-prologue.ll | 78 
 10 files changed, 267 insertions(+), 27 deletions(-)
 create mode 100644 llvm/test/CodeGen/RISCV/stack-clash-prologue-nounwind.ll
 create mode 100644 llvm/test/CodeGen/RISCV/stack-clash-prologue.ll

diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index d3eec9fea0d498..48fc43a8f968bc 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -3774,7 +3774,8 @@ static void RenderSCPOptions(const ToolChain &TC, const 
ArgList &Args,
 return;
 
   if (!EffectiveTriple.isX86() && !EffectiveTriple.isSystemZ() &&
-  !EffectiveTriple.isPPC64() && !EffectiveTriple.isAArch64())
+  !EffectiveTriple.isPPC64() && !EffectiveTriple.isAArch64() &&
+  !EffectiveTriple.isRISCV())
 return;
 
   Args.addOptInFlag(CmdArgs, options::OPT_fstack_clash_protection,
diff --git a/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp 
b/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
index 1ff435b76ad68a..c2412b5c17174d 100644
--- a/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
+++ b/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
@@ -610,23 +610,74 @@ static MCCFIInstruction createDefCFAOffset(const 
TargetRegisterInfo &TRI,
 Comment.str());
 }
 
+// Allocate stack space and probe it if necessary.
 void RISCVFrameLowering::allocateStack(MachineBasicBlock &MBB,
MachineBasicBlock::iterator MBBI,
-   StackOffset Offset, bool EmitCFI,
-   unsigned CFIIndex) const {
+   MachineFunction &MF, uint64_t Offset,
+   uint64_t RealStackSize, bool EmitCFI,
+   bool NeedProbe,
+   uint64_t ProbeSize) const {
   DebugLoc DL;
   const RISCVRegisterInfo *RI = STI.getRegisterInfo();
   const RISCVInstrInfo *TII = STI.getInstrInfo();
 
-  RI->adjustReg(MBB, MBBI, DL, SPReg, SPReg, Offset, MachineInstr::FrameSetup,
-getStackAlign());
+  // Simply allocate the stack if it's not big enough to require a probe.
+  if (!NeedProbe || Offset <= ProbeSize) {
+RI->adjustReg(MBB, MBBI, DL, SPReg, SPReg, StackOffset::getFixed(-Offset),
+  MachineInstr::FrameSetup, getStackAlign());
 
-  if (EmitCFI) {
-// Emit ".cfi_def_cfa_offset StackSize"
-BuildMI(MBB, MBBI, DL, TII->get(TargetOpcode::CFI_INSTRUCTION))
-.addCFIIndex(CFIIndex)
-.setMIFlag(MachineInstr::FrameSetup);
+if (EmitCFI) {
+  // Emit ".cfi_def_cfa_offset RealStackSize"
+  unsigned CFIIndex = MF.addFrameInst(
+  MCCFIInstruction::cfiDefCfaOffset(nullptr, RealStackSize));
+  BuildMI(MBB, MBBI, DL, TII->get(TargetOpcode::CFI_INSTRUCTION))
+  .addCFIIndex(CFIIndex)
+  .setMIFlag(MachineInstr::FrameSetup);
+}
+
+return;
+  }
+
+  // Do an unrolled probe loop.
+  uint64_t CurrentOffset = 0;
+  bool IsRV64 = STI.hasFeature(RISCV::Feature64Bit);
+  while (CurrentOffset + ProbeSize <= Offset) {
+RI->adjustReg(MBB, MBBI, DL, SPReg, SPReg,
+  StackOffset::getFixed(-ProbeSize), MachineInstr::FrameSetup,
+  getStackAlign());
+// s[d|w] zero, 0(sp)
+BuildMI(MBB, MBBI, DL, TII->get(IsRV64 ? RISCV::SD : RISCV::SW))
+.addReg(RISCV::X0)
+.addReg(SPReg)
+.addImm(0)
+.setMIFlags(MachineInstr::FrameSetup);
+
+CurrentOffset += ProbeSize;
+if (EmitCFI) {
+  // Emit

[clang] [llvm] [RISCV] Add stack clash protection (PR #117612)

2024-11-25 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-driver

Author: Raphael Moreira Zinsly (rzinsly)


Changes

Enable `-fstack-clash-protection` for RISCV and stack probe for function 
prologues.
We probe the stack by creating a loop that allocates and probe the stack in 
ProbeSize chunks.
We emit an unrolled probe loop for small allocations and emit a variable length 
probe loop for bigger ones.

---

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


11 Files Affected:

- (modified) clang/lib/Driver/ToolChains/Clang.cpp (+2-1) 
- (modified) llvm/lib/Target/RISCV/RISCVFrameLowering.cpp (+197-18) 
- (modified) llvm/lib/Target/RISCV/RISCVFrameLowering.h (+6-1) 
- (modified) llvm/lib/Target/RISCV/RISCVISelLowering.cpp (+22) 
- (modified) llvm/lib/Target/RISCV/RISCVISelLowering.h (+6) 
- (modified) llvm/lib/Target/RISCV/RISCVInstrInfo.td (+11) 
- (modified) llvm/lib/Target/RISCV/RISCVMachineFunctionInfo.cpp (+30) 
- (modified) llvm/lib/Target/RISCV/RISCVMachineFunctionInfo.h (+6-1) 
- (modified) llvm/lib/Target/RISCV/RISCVTargetMachine.cpp (+2-2) 
- (added) llvm/test/CodeGen/RISCV/stack-clash-prologue-nounwind.ll (+208) 
- (added) llvm/test/CodeGen/RISCV/stack-clash-prologue.ll (+537) 


``diff
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index d3eec9fea0d498..48fc43a8f968bc 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -3774,7 +3774,8 @@ static void RenderSCPOptions(const ToolChain &TC, const 
ArgList &Args,
 return;
 
   if (!EffectiveTriple.isX86() && !EffectiveTriple.isSystemZ() &&
-  !EffectiveTriple.isPPC64() && !EffectiveTriple.isAArch64())
+  !EffectiveTriple.isPPC64() && !EffectiveTriple.isAArch64() &&
+  !EffectiveTriple.isRISCV())
 return;
 
   Args.addOptInFlag(CmdArgs, options::OPT_fstack_clash_protection,
diff --git a/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp 
b/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
index 1ff435b76ad68a..0b6e89a0e29bf4 100644
--- a/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
+++ b/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
@@ -610,22 +610,134 @@ static MCCFIInstruction createDefCFAOffset(const 
TargetRegisterInfo &TRI,
 Comment.str());
 }
 
+// Allocate stack space and probe it if necessary.
 void RISCVFrameLowering::allocateStack(MachineBasicBlock &MBB,
MachineBasicBlock::iterator MBBI,
-   StackOffset Offset, bool EmitCFI,
-   unsigned CFIIndex) const {
+   MachineFunction &MF, uint64_t Offset,
+   uint64_t RealStackSize, bool EmitCFI,
+   bool NeedProbe,
+   uint64_t ProbeSize) const {
   DebugLoc DL;
   const RISCVRegisterInfo *RI = STI.getRegisterInfo();
   const RISCVInstrInfo *TII = STI.getInstrInfo();
 
-  RI->adjustReg(MBB, MBBI, DL, SPReg, SPReg, Offset, MachineInstr::FrameSetup,
+  // Simply allocate the stack if it's not big enough to require a probe.
+  if (!NeedProbe || Offset <= ProbeSize) {
+RI->adjustReg(MBB, MBBI, DL, SPReg, SPReg, StackOffset::getFixed(-Offset),
+  MachineInstr::FrameSetup, getStackAlign());
+
+if (EmitCFI) {
+  // Emit ".cfi_def_cfa_offset RealStackSize"
+  unsigned CFIIndex = MF.addFrameInst(
+  MCCFIInstruction::cfiDefCfaOffset(nullptr, RealStackSize));
+  BuildMI(MBB, MBBI, DL, TII->get(TargetOpcode::CFI_INSTRUCTION))
+  .addCFIIndex(CFIIndex)
+  .setMIFlag(MachineInstr::FrameSetup);
+}
+
+return;
+  }
+
+  // Unroll the probe loop depending on the number of iterations.
+  if (Offset < ProbeSize * 5) {
+uint64_t CurrentOffset = 0;
+bool IsRV64 = STI.hasFeature(RISCV::Feature64Bit);
+while (CurrentOffset + ProbeSize <= Offset) {
+  RI->adjustReg(MBB, MBBI, DL, SPReg, SPReg,
+StackOffset::getFixed(-ProbeSize), 
MachineInstr::FrameSetup,
+getStackAlign());
+  // s[d|w] zero, 0(sp)
+  BuildMI(MBB, MBBI, DL, TII->get(IsRV64 ? RISCV::SD : RISCV::SW))
+  .addReg(RISCV::X0)
+  .addReg(SPReg)
+  .addImm(0)
+  .setMIFlags(MachineInstr::FrameSetup);
+
+  CurrentOffset += ProbeSize;
+  if (EmitCFI) {
+// Emit ".cfi_def_cfa_offset CurrentOffset"
+unsigned CFIIndex = MF.addFrameInst(
+MCCFIInstruction::cfiDefCfaOffset(nullptr, CurrentOffset));
+BuildMI(MBB, MBBI, DL, TII->get(TargetOpcode::CFI_INSTRUCTION))
+.addCFIIndex(CFIIndex)
+.setMIFlag(MachineInstr::FrameSetup);
+  }
+}
+
+uint64_t Residual = Offset - CurrentOffset;
+if (Residual) {
+  RI->adjustReg(MBB, MBBI, DL, SPReg, SPReg,
+ 

[clang] [llvm] [RISCV] Add stack clash protection (PR #117612)

2024-11-25 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-risc-v

Author: Raphael Moreira Zinsly (rzinsly)


Changes

Enable `-fstack-clash-protection` for RISCV and stack probe for function 
prologues.
We probe the stack by creating a loop that allocates and probe the stack in 
ProbeSize chunks.
We emit an unrolled probe loop for small allocations and emit a variable length 
probe loop for bigger ones.

---

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


11 Files Affected:

- (modified) clang/lib/Driver/ToolChains/Clang.cpp (+2-1) 
- (modified) llvm/lib/Target/RISCV/RISCVFrameLowering.cpp (+197-18) 
- (modified) llvm/lib/Target/RISCV/RISCVFrameLowering.h (+6-1) 
- (modified) llvm/lib/Target/RISCV/RISCVISelLowering.cpp (+22) 
- (modified) llvm/lib/Target/RISCV/RISCVISelLowering.h (+6) 
- (modified) llvm/lib/Target/RISCV/RISCVInstrInfo.td (+11) 
- (modified) llvm/lib/Target/RISCV/RISCVMachineFunctionInfo.cpp (+30) 
- (modified) llvm/lib/Target/RISCV/RISCVMachineFunctionInfo.h (+6-1) 
- (modified) llvm/lib/Target/RISCV/RISCVTargetMachine.cpp (+2-2) 
- (added) llvm/test/CodeGen/RISCV/stack-clash-prologue-nounwind.ll (+208) 
- (added) llvm/test/CodeGen/RISCV/stack-clash-prologue.ll (+537) 


``diff
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index d3eec9fea0d498..48fc43a8f968bc 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -3774,7 +3774,8 @@ static void RenderSCPOptions(const ToolChain &TC, const 
ArgList &Args,
 return;
 
   if (!EffectiveTriple.isX86() && !EffectiveTriple.isSystemZ() &&
-  !EffectiveTriple.isPPC64() && !EffectiveTriple.isAArch64())
+  !EffectiveTriple.isPPC64() && !EffectiveTriple.isAArch64() &&
+  !EffectiveTriple.isRISCV())
 return;
 
   Args.addOptInFlag(CmdArgs, options::OPT_fstack_clash_protection,
diff --git a/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp 
b/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
index 1ff435b76ad68a..0b6e89a0e29bf4 100644
--- a/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
+++ b/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
@@ -610,22 +610,134 @@ static MCCFIInstruction createDefCFAOffset(const 
TargetRegisterInfo &TRI,
 Comment.str());
 }
 
+// Allocate stack space and probe it if necessary.
 void RISCVFrameLowering::allocateStack(MachineBasicBlock &MBB,
MachineBasicBlock::iterator MBBI,
-   StackOffset Offset, bool EmitCFI,
-   unsigned CFIIndex) const {
+   MachineFunction &MF, uint64_t Offset,
+   uint64_t RealStackSize, bool EmitCFI,
+   bool NeedProbe,
+   uint64_t ProbeSize) const {
   DebugLoc DL;
   const RISCVRegisterInfo *RI = STI.getRegisterInfo();
   const RISCVInstrInfo *TII = STI.getInstrInfo();
 
-  RI->adjustReg(MBB, MBBI, DL, SPReg, SPReg, Offset, MachineInstr::FrameSetup,
+  // Simply allocate the stack if it's not big enough to require a probe.
+  if (!NeedProbe || Offset <= ProbeSize) {
+RI->adjustReg(MBB, MBBI, DL, SPReg, SPReg, StackOffset::getFixed(-Offset),
+  MachineInstr::FrameSetup, getStackAlign());
+
+if (EmitCFI) {
+  // Emit ".cfi_def_cfa_offset RealStackSize"
+  unsigned CFIIndex = MF.addFrameInst(
+  MCCFIInstruction::cfiDefCfaOffset(nullptr, RealStackSize));
+  BuildMI(MBB, MBBI, DL, TII->get(TargetOpcode::CFI_INSTRUCTION))
+  .addCFIIndex(CFIIndex)
+  .setMIFlag(MachineInstr::FrameSetup);
+}
+
+return;
+  }
+
+  // Unroll the probe loop depending on the number of iterations.
+  if (Offset < ProbeSize * 5) {
+uint64_t CurrentOffset = 0;
+bool IsRV64 = STI.hasFeature(RISCV::Feature64Bit);
+while (CurrentOffset + ProbeSize <= Offset) {
+  RI->adjustReg(MBB, MBBI, DL, SPReg, SPReg,
+StackOffset::getFixed(-ProbeSize), 
MachineInstr::FrameSetup,
+getStackAlign());
+  // s[d|w] zero, 0(sp)
+  BuildMI(MBB, MBBI, DL, TII->get(IsRV64 ? RISCV::SD : RISCV::SW))
+  .addReg(RISCV::X0)
+  .addReg(SPReg)
+  .addImm(0)
+  .setMIFlags(MachineInstr::FrameSetup);
+
+  CurrentOffset += ProbeSize;
+  if (EmitCFI) {
+// Emit ".cfi_def_cfa_offset CurrentOffset"
+unsigned CFIIndex = MF.addFrameInst(
+MCCFIInstruction::cfiDefCfaOffset(nullptr, CurrentOffset));
+BuildMI(MBB, MBBI, DL, TII->get(TargetOpcode::CFI_INSTRUCTION))
+.addCFIIndex(CFIIndex)
+.setMIFlag(MachineInstr::FrameSetup);
+  }
+}
+
+uint64_t Residual = Offset - CurrentOffset;
+if (Residual) {
+  RI->adjustReg(MBB, MBBI, DL, SPReg, SPReg,
+StackO

[clang] [clang][sema] Add support and documentation for `__has_extension(c_fixed_enum)` (PR #117507)

2024-11-25 Thread Aidan Goldfarb via cfe-commits

https://github.com/AidanGoldfarb updated 
https://github.com/llvm/llvm-project/pull/117507

>From a6c9b5ca52f35fe451a52c590ce93584c2b4f3ac Mon Sep 17 00:00:00 2001
From: Aidan Goldfarb <47676355+aidangoldf...@users.noreply.github.com>
Date: Fri, 22 Nov 2024 19:06:29 -0500
Subject: [PATCH 1/6] Update LanguageExtensions.rst

---
 clang/docs/LanguageExtensions.rst | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index 3c9078bcdf8118..1c400d87c4948b 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -1986,7 +1986,7 @@ Enumerations with a fixed underlying type
 -
 
 Clang provides support for C++11 enumerations with a fixed underlying type
-within Objective-C.  For example, one can write an enumeration type as:
+within Objective-C and C `prior to C23 
`_.  For example, one 
can write an enumeration type as:
 
 .. code-block:: c++
 
@@ -1998,6 +1998,9 @@ value, is ``unsigned char``.
 Use ``__has_feature(objc_fixed_enum)`` to determine whether support for fixed
 underlying types is available in Objective-C.
 
+Use ``__has_extension(c_fixed_enum)`` to determine whether support for fixed
+underlying types is available in C.
+
 Interoperability with C++11 lambdas
 ---
 

>From d9e06150893a723cfeee0e08a7b8e652f2facf5c Mon Sep 17 00:00:00 2001
From: Aidan 
Date: Sun, 24 Nov 2024 15:09:02 -0500
Subject: [PATCH 2/6] Updated Features.def to include c_fixed_enum. Updated
 enum.c test to check for support of enums with a fixed underlying type in C23
 and https://github.com/llvm/llvm-project/issues/116880
+#if __STDC_VERSION__ >= 202311L
+typedef enum : unsigned char { Pink, Black, Cyan } Color;
+#else
+_Static_assert(__has_extension(c_fixed_enum), "Ensure language extension 
support for enumerations with a fixed underlying type in = 202311L
 // FIXME: GCC picks __uint128_t as the underlying type for the enumeration
 // value and Clang picks unsigned long long.

>From 9fd4a259bea6df7c1e9db8e2c8fe79654937dc9a Mon Sep 17 00:00:00 2001
From: Aidan 
Date: Sun, 24 Nov 2024 15:57:31 -0500
Subject: [PATCH 3/6] Added c_fixed_enum as an extension. Cleaned up enum.c

---
 clang/include/clang/Basic/Features.def | 5 -
 clang/test/Sema/enum.c | 1 -
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/Basic/Features.def 
b/clang/include/clang/Basic/Features.def
index c63f4ab75deda2..ab963a876db342 100644
--- a/clang/include/clang/Basic/Features.def
+++ b/clang/include/clang/Basic/Features.def
@@ -131,7 +131,6 @@ FEATURE(objc_arc_fields, true)
 FEATURE(objc_arc_weak, LangOpts.ObjCWeak)
 FEATURE(objc_default_synthesize_properties, LangOpts.ObjC)
 FEATURE(objc_fixed_enum, LangOpts.ObjC)
-FEATURE(c_fixed_enum, true)
 FEATURE(objc_instancetype, LangOpts.ObjC)
 FEATURE(objc_kindof, LangOpts.ObjC)
 FEATURE(objc_modules, LangOpts.ObjC && LangOpts.Modules)
@@ -309,6 +308,10 @@ EXTENSION(datasizeof, LangOpts.CPlusPlus)
 
 FEATURE(cxx_abi_relative_vtable, LangOpts.CPlusPlus && 
LangOpts.RelativeCXXABIVTables)
 
+//Fixed enum feature and extension, to be relocated in this file
+FEATURE(c_fixed_enum, true)
+EXTENSION(c_fixed_enum, true)  
+
 // CUDA/HIP Features
 FEATURE(cuda_noinline_keyword, LangOpts.CUDA)
 EXTENSION(cuda_implicit_host_device_templates, LangOpts.CUDA && 
LangOpts.OffloadImplicitHostDeviceTemplates)
diff --git a/clang/test/Sema/enum.c b/clang/test/Sema/enum.c
index 053053192e4ad5..3b30b24a6c13f1 100644
--- a/clang/test/Sema/enum.c
+++ b/clang/test/Sema/enum.c
@@ -185,7 +185,6 @@ enum IncOverflow {
   V3 // pre-c23-warning {{incremented enumerator value which exceeds the range 
of 'int' is a C23 extension}}
 };
 
-
 #if __STDC_VERSION__ >= 202311L
 // FIXME: GCC picks __uint128_t as the underlying type for the enumeration
 // value and Clang picks unsigned long long.

>From 53ba18d1453b310fd778e0095b75faddf68ec75b Mon Sep 17 00:00:00 2001
From: Aidan 
Date: Sun, 24 Nov 2024 16:27:04 -0500
Subject: [PATCH 4/6] formatting changes

---
 clang/test/Sema/enum.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/clang/test/Sema/enum.c b/clang/test/Sema/enum.c
index 3b30b24a6c13f1..7b3f7d30e91d82 100644
--- a/clang/test/Sema/enum.c
+++ b/clang/test/Sema/enum.c
@@ -130,8 +130,6 @@ typedef struct Color NewColor; // expected-error {{use of 
'Color' with tag type
 typedef enum : unsigned char { Pink, Black, Cyan } Color; // 
expected-warning {{enumeration types with a fixed underlying type are a C23 
extension}}
 #endif
 
-
-
 // PR28903
 // In C it is valid to define tags inside enums.
 struct PR28903 {

>From 8722c53336e6073e3b521140a07c4c9c0aa18fdc Mon Sep 17 00:00:00 2001
From: Aidan 
Date: Mon, 25 Nov 2024 11:14:02 -0500
Subject: [PATCH 5/6] fixed enum.c typed enum logic

---
 clang/test/Sema/enum.c | 7 ---
 1 

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

2024-11-25 Thread Erich Keane via cfe-commits

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

Nits only, otherwise LGTM.

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-25 Thread Erich Keane via cfe-commits


@@ -7197,10 +7206,10 @@ alternatives, though the attribute can be used even 
when the fix can't be automa
   and then use the attribute on the original ``baz()`` to help the users
   update their code to use the new function.
 
-* Attribute attached to fields: The attribute should only be attached to 

erichkeane wrote:

Same comments on trailing WS here :/

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


  1   2   3   4   5   6   >