[clang] Fix double-quotes in diagnostic when attempting to access a ext_vector of bools (PR #118186)

2024-12-06 Thread via cfe-commits


@@ -1655,8 +1655,10 @@ static ExprResult LookupMemberExpr(Sema &S, LookupResult 
&R,
 // We disallow element access for ext_vector_type bool.  There is no way to
 // materialize a reference to a vector element as a pointer (each element 
is
 // one bit in the vector).
+assert(MemberName.isIdentifier() &&
+   "Ext vector component name not an identifier!");
 S.Diag(R.getNameLoc(), diag::err_ext_vector_component_name_illegal)
-<< MemberName
+<< MemberName.getAsIdentifierInfo()->getName()

cor3ntin wrote:

Did you try to remove the quotes in DiagnositicSemaKind.td instead?

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


[clang] [llvm] [SystemZ] Add support for __builtin_setjmp and __builtin_longjmp (PR #116642)

2024-12-06 Thread Ulrich Weigand via cfe-commits

https://github.com/uweigand commented:

One last comment, then it looks good to go for me.  Thanks!

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


[clang] [Serialization] Migrate away from PointerUnion::{is,get} (NFC) (PR #118948)

2024-12-06 Thread Kazu Hirata via cfe-commits

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

Note that PointerUnion::{is,get} have been soft deprecated in
PointerUnion.h:

  // FIXME: Replace the uses of is(), get() and dyn_cast() with
  //isa, cast and the llvm::dyn_cast

I'm not touching PointerUnion::dyn_cast for now because it's a bit
complicated; we could blindly migrate it to dyn_cast_if_present, but
we should probably use dyn_cast when the operand is known to be
non-null.


>From e250737a09f902e9b088927daa406920437e0725 Mon Sep 17 00:00:00 2001
From: Kazu Hirata 
Date: Fri, 6 Dec 2024 01:47:44 -0800
Subject: [PATCH] [Serialization] Migrate away from PointerUnion::{is,get}
 (NFC)

Note that PointerUnion::{is,get} have been soft deprecated in
PointerUnion.h:

  // FIXME: Replace the uses of is(), get() and dyn_cast() with
  //isa, cast and the llvm::dyn_cast

I'm not touching PointerUnion::dyn_cast for now because it's a bit
complicated; we could blindly migrate it to dyn_cast_if_present, but
we should probably use dyn_cast when the operand is known to be
non-null.
---
 clang/lib/Serialization/ASTReaderDecl.cpp |  6 +++---
 clang/lib/Serialization/ASTReaderStmt.cpp |  6 +++---
 clang/lib/Serialization/ASTWriter.cpp |  2 +-
 clang/lib/Serialization/ASTWriterDecl.cpp |  6 +++---
 clang/lib/Serialization/ASTWriterStmt.cpp | 11 ++-
 5 files changed, 16 insertions(+), 15 deletions(-)

diff --git a/clang/lib/Serialization/ASTReaderDecl.cpp 
b/clang/lib/Serialization/ASTReaderDecl.cpp
index 0644ff4dfe6827..be77df81b1ddfe 100644
--- a/clang/lib/Serialization/ASTReaderDecl.cpp
+++ b/clang/lib/Serialization/ASTReaderDecl.cpp
@@ -4598,7 +4598,7 @@ void ASTDeclReader::UpdateDecl(Decl *D) {
 .dyn_cast())
   FTSInfo->setPointOfInstantiation(POI);
 else
-  FD->TemplateOrSpecialization.get()
+  cast(FD->TemplateOrSpecialization)
   ->setPointOfInstantiation(POI);
   }
   break;
@@ -4697,8 +4697,8 @@ void ASTDeclReader::UpdateDecl(Decl *D) {
 
   // FIXME: If we already have a partial specialization set,
   // check that it matches.
-  if (!Spec->getSpecializedTemplateOrPartial()
-   .is())
+  if (!isa(
+  Spec->getSpecializedTemplateOrPartial()))
 Spec->setInstantiationOf(PartialSpec, TemplArgList);
 }
   }
diff --git a/clang/lib/Serialization/ASTReaderStmt.cpp 
b/clang/lib/Serialization/ASTReaderStmt.cpp
index 731ad0b64dc850..9f4877b19d8705 100644
--- a/clang/lib/Serialization/ASTReaderStmt.cpp
+++ b/clang/lib/Serialization/ASTReaderStmt.cpp
@@ -911,9 +911,9 @@ void ASTStmtReader::VisitRequiresExpr(RequiresExpr *E) {
   std::move(*Req), Status, SubstitutedConstraintExpr);
 else
   R = new (Record.getContext()) concepts::ExprRequirement(
-  E.get(),
-  RK == concepts::Requirement::RK_Simple, NoexceptLoc,
-  std::move(*Req));
+  cast(E),
+  RK == concepts::Requirement::RK_Simple, NoexceptLoc,
+  std::move(*Req));
   } break;
   case concepts::Requirement::RK_Nested: {
 ASTContext &C = Record.getContext();
diff --git a/clang/lib/Serialization/ASTWriter.cpp 
b/clang/lib/Serialization/ASTWriter.cpp
index 83fbb705e48c7c..e7f898d6a847e2 100644
--- a/clang/lib/Serialization/ASTWriter.cpp
+++ b/clang/lib/Serialization/ASTWriter.cpp
@@ -5111,7 +5111,7 @@ ASTWriter::WriteAST(llvm::PointerUnion Subject,
 
   Sema *SemaPtr = Subject.dyn_cast();
   Preprocessor &PPRef =
-  SemaPtr ? SemaPtr->getPreprocessor() : *Subject.get();
+  SemaPtr ? SemaPtr->getPreprocessor() : *cast(Subject);
 
   ASTHasCompilerErrors = PPRef.getDiagnostics().hasUncompilableErrorOccurred();
 
diff --git a/clang/lib/Serialization/ASTWriterDecl.cpp 
b/clang/lib/Serialization/ASTWriterDecl.cpp
index b3119607a14043..68e2d6b3993904 100644
--- a/clang/lib/Serialization/ASTWriterDecl.cpp
+++ b/clang/lib/Serialization/ASTWriterDecl.cpp
@@ -1694,7 +1694,7 @@ void ASTDeclWriter::VisitFriendDecl(FriendDecl *D) {
   // so as to simplify memory allocation during deserialization.
   Record.push_back(D->NumTPLists);
   VisitDecl(D);
-  bool hasFriendDecl = D->Friend.is();
+  bool hasFriendDecl = isa(D->Friend);
   Record.push_back(hasFriendDecl);
   if (hasFriendDecl)
 Record.AddDeclRef(D->getFriendDecl());
@@ -1795,7 +1795,7 @@ void ASTDeclWriter::VisitClassTemplateSpecializationDecl(
   if (Decl *InstFromD = InstFrom.dyn_cast()) {
 Record.AddDeclRef(InstFromD);
   } else {
-Record.AddDeclRef(InstFrom.get());
+Record.AddDeclRef(cast(InstFrom));
 Record.AddTemplateArgumentList(&D->getTemplateInstantiationArgs());
   }
 
@@ -1873,7 +1873,7 @@ void ASTDeclWriter::VisitVarTemplateSpecializationDecl(
   if (Decl *InstFromD = InstFrom.dyn_cast()) {
 Record.AddDeclRef(InstFromD);
   } else {
-Record.AddDeclRef(InstFrom.get())

[clang] [Serialization] Migrate away from PointerUnion::{is,get} (NFC) (PR #118948)

2024-12-06 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-modules

Author: Kazu Hirata (kazutakahirata)


Changes

Note that PointerUnion::{is,get} have been soft deprecated in
PointerUnion.h:

  // FIXME: Replace the uses of is(), get() and dyn_cast() with
  //isa, cast and the llvm::dyn_cast

I'm not touching PointerUnion::dyn_cast for now because it's a bit
complicated; we could blindly migrate it to dyn_cast_if_present, but
we should probably use dyn_cast when the operand is known to be
non-null.


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


5 Files Affected:

- (modified) clang/lib/Serialization/ASTReaderDecl.cpp (+3-3) 
- (modified) clang/lib/Serialization/ASTReaderStmt.cpp (+3-3) 
- (modified) clang/lib/Serialization/ASTWriter.cpp (+1-1) 
- (modified) clang/lib/Serialization/ASTWriterDecl.cpp (+3-3) 
- (modified) clang/lib/Serialization/ASTWriterStmt.cpp (+6-5) 


``diff
diff --git a/clang/lib/Serialization/ASTReaderDecl.cpp 
b/clang/lib/Serialization/ASTReaderDecl.cpp
index 0644ff4dfe6827..be77df81b1ddfe 100644
--- a/clang/lib/Serialization/ASTReaderDecl.cpp
+++ b/clang/lib/Serialization/ASTReaderDecl.cpp
@@ -4598,7 +4598,7 @@ void ASTDeclReader::UpdateDecl(Decl *D) {
 .dyn_cast())
   FTSInfo->setPointOfInstantiation(POI);
 else
-  FD->TemplateOrSpecialization.get()
+  cast(FD->TemplateOrSpecialization)
   ->setPointOfInstantiation(POI);
   }
   break;
@@ -4697,8 +4697,8 @@ void ASTDeclReader::UpdateDecl(Decl *D) {
 
   // FIXME: If we already have a partial specialization set,
   // check that it matches.
-  if (!Spec->getSpecializedTemplateOrPartial()
-   .is())
+  if (!isa(
+  Spec->getSpecializedTemplateOrPartial()))
 Spec->setInstantiationOf(PartialSpec, TemplArgList);
 }
   }
diff --git a/clang/lib/Serialization/ASTReaderStmt.cpp 
b/clang/lib/Serialization/ASTReaderStmt.cpp
index 731ad0b64dc850..9f4877b19d8705 100644
--- a/clang/lib/Serialization/ASTReaderStmt.cpp
+++ b/clang/lib/Serialization/ASTReaderStmt.cpp
@@ -911,9 +911,9 @@ void ASTStmtReader::VisitRequiresExpr(RequiresExpr *E) {
   std::move(*Req), Status, SubstitutedConstraintExpr);
 else
   R = new (Record.getContext()) concepts::ExprRequirement(
-  E.get(),
-  RK == concepts::Requirement::RK_Simple, NoexceptLoc,
-  std::move(*Req));
+  cast(E),
+  RK == concepts::Requirement::RK_Simple, NoexceptLoc,
+  std::move(*Req));
   } break;
   case concepts::Requirement::RK_Nested: {
 ASTContext &C = Record.getContext();
diff --git a/clang/lib/Serialization/ASTWriter.cpp 
b/clang/lib/Serialization/ASTWriter.cpp
index 83fbb705e48c7c..e7f898d6a847e2 100644
--- a/clang/lib/Serialization/ASTWriter.cpp
+++ b/clang/lib/Serialization/ASTWriter.cpp
@@ -5111,7 +5111,7 @@ ASTWriter::WriteAST(llvm::PointerUnion Subject,
 
   Sema *SemaPtr = Subject.dyn_cast();
   Preprocessor &PPRef =
-  SemaPtr ? SemaPtr->getPreprocessor() : *Subject.get();
+  SemaPtr ? SemaPtr->getPreprocessor() : *cast(Subject);
 
   ASTHasCompilerErrors = PPRef.getDiagnostics().hasUncompilableErrorOccurred();
 
diff --git a/clang/lib/Serialization/ASTWriterDecl.cpp 
b/clang/lib/Serialization/ASTWriterDecl.cpp
index b3119607a14043..68e2d6b3993904 100644
--- a/clang/lib/Serialization/ASTWriterDecl.cpp
+++ b/clang/lib/Serialization/ASTWriterDecl.cpp
@@ -1694,7 +1694,7 @@ void ASTDeclWriter::VisitFriendDecl(FriendDecl *D) {
   // so as to simplify memory allocation during deserialization.
   Record.push_back(D->NumTPLists);
   VisitDecl(D);
-  bool hasFriendDecl = D->Friend.is();
+  bool hasFriendDecl = isa(D->Friend);
   Record.push_back(hasFriendDecl);
   if (hasFriendDecl)
 Record.AddDeclRef(D->getFriendDecl());
@@ -1795,7 +1795,7 @@ void ASTDeclWriter::VisitClassTemplateSpecializationDecl(
   if (Decl *InstFromD = InstFrom.dyn_cast()) {
 Record.AddDeclRef(InstFromD);
   } else {
-Record.AddDeclRef(InstFrom.get());
+Record.AddDeclRef(cast(InstFrom));
 Record.AddTemplateArgumentList(&D->getTemplateInstantiationArgs());
   }
 
@@ -1873,7 +1873,7 @@ void ASTDeclWriter::VisitVarTemplateSpecializationDecl(
   if (Decl *InstFromD = InstFrom.dyn_cast()) {
 Record.AddDeclRef(InstFromD);
   } else {
-Record.AddDeclRef(InstFrom.get());
+Record.AddDeclRef(cast(InstFrom));
 Record.AddTemplateArgumentList(&D->getTemplateInstantiationArgs());
   }
 
diff --git a/clang/lib/Serialization/ASTWriterStmt.cpp 
b/clang/lib/Serialization/ASTWriterStmt.cpp
index 4994047d9fe10f..603aa5707ce9be 100644
--- a/clang/lib/Serialization/ASTWriterStmt.cpp
+++ b/clang/lib/Serialization/ASTWriterStmt.cpp
@@ -480,7 +480,7 @@ addConstraintSatisfaction(ASTRecordWriter &Record,
   if (E)
 Record.AddStmt(E);
   else {
-auto *D

[clang] [llvm] [AArch64] Implement intrinsics for FP8 FCVT/FCVTN/BFCVT (PR #118025)

2024-12-06 Thread via cfe-commits

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

LGTM

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


[clang] [flang] Reland "[flang] Integrate the option -flang-experimental-integer-overflow into -fno-wrapv" (PR #118933)

2024-12-06 Thread Tom Eccles via cfe-commits

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

Thanks for your patience and for bringing this back!

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


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

2024-12-06 Thread Paul Osmialowski via cfe-commits

https://github.com/pawosm-arm updated 
https://github.com/llvm/llvm-project/pull/117573

>From 65958806ff828cb0f41a2587e50abe0d221ae88c Mon Sep 17 00:00:00 2001
From: Pawel Osmialowski 
Date: Mon, 25 Nov 2024 14:46:55 +
Subject: [PATCH] [clang][driver] Special care for linker flags in config files

Currently, if a -l (or -Wl,) flag is added into a config file
(e.g. clang.cfg), it is situated before any object file in the
effective command line. If the library requested by given -l flag is
static, its symbols will not be made visible to any of the object
files provided by the user. Also, the presence of any of the linker
flags in a config file confuses the driver whenever the user invokes
clang without any parameters (see issue #67209).

This patch attempts to solve both of the problems, by allowing a split
of the arguments list into two parts. The head part of the list will
be used as before, but the tail part will be appended after the
command line flags provided by the user and only when it is known
that the linking should occur. The $-prefixed arguments will be added
to the tail part.
---
 clang/docs/UsersManual.rst| 10 +
 clang/include/clang/Driver/Driver.h   |  7 ++-
 clang/lib/Driver/Driver.cpp   | 63 +--
 clang/test/Driver/Inputs/config-l.cfg |  3 ++
 clang/test/Driver/config-file.c   | 26 +++
 flang/test/Driver/Inputs/config-l.cfg |  3 ++
 flang/test/Driver/config-file.f90 | 26 +++
 7 files changed, 122 insertions(+), 16 deletions(-)
 create mode 100644 clang/test/Driver/Inputs/config-l.cfg
 create mode 100644 flang/test/Driver/Inputs/config-l.cfg

diff --git a/clang/docs/UsersManual.rst b/clang/docs/UsersManual.rst
index 43b41a2a826890..5b7a293a4ecc27 100644
--- a/clang/docs/UsersManual.rst
+++ b/clang/docs/UsersManual.rst
@@ -1059,6 +1059,16 @@ In this way, the user may only need to specify a root 
configuration file with
 -L /lib
 -T /ldscripts/link.ld
 
+Usually, config file options are placed before command-line options, regardless
+of the actual operation to be performed. The exception is being made for the
+options prefixed with the ``$`` character. These will be used only when linker
+is being invoked, and added after all of the command-line specified linker
+inputs. Here is some example of ``$``-prefixed options:
+
+::
+$-Wl,-Bstatic $-lm
+$-Wl,-Bshared
+
 Language and Target-Independent Features
 
 
diff --git a/clang/include/clang/Driver/Driver.h 
b/clang/include/clang/Driver/Driver.h
index 9177d56718ee77..c23d037e725bb9 100644
--- a/clang/include/clang/Driver/Driver.h
+++ b/clang/include/clang/Driver/Driver.h
@@ -297,8 +297,11 @@ class Driver {
   /// Object that stores strings read from configuration file.
   llvm::StringSaver Saver;
 
-  /// Arguments originated from configuration file.
-  std::unique_ptr CfgOptions;
+  /// Arguments originated from configuration file (head part).
+  std::unique_ptr CfgOptionsHead;
+
+  /// Arguments originated from configuration file (tail part).
+  std::unique_ptr CfgOptionsTail;
 
   /// Arguments originated from command line.
   std::unique_ptr CLOptions;
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 7de8341b8d2d61..0c25f16ce3076e 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -1039,34 +1039,59 @@ bool Driver::readConfigFile(StringRef FileName,
   }
 
   // Try reading the given file.
-  SmallVector NewCfgArgs;
-  if (llvm::Error Err = ExpCtx.readConfigFile(FileName, NewCfgArgs)) {
+  SmallVector NewCfgFileArgs;
+  if (llvm::Error Err = ExpCtx.readConfigFile(FileName, NewCfgFileArgs)) {
 Diag(diag::err_drv_cannot_read_config_file)
 << FileName << toString(std::move(Err));
 return true;
   }
 
+  // Populate head and tail lists. The tail list is used only when linking.
+  SmallVector NewCfgHeadArgs, NewCfgTailArgs;
+  for (const char *Opt : NewCfgFileArgs) {
+// An $-prefixed option should go to the tail list.
+if (Opt[0] == '$' && Opt[1])
+  NewCfgTailArgs.push_back(Opt + 1);
+else
+  NewCfgHeadArgs.push_back(Opt);
+  }
+
   // Read options from config file.
   llvm::SmallString<128> CfgFileName(FileName);
   llvm::sys::path::native(CfgFileName);
-  bool ContainErrors;
-  auto NewOptions = std::make_unique(
-  ParseArgStrings(NewCfgArgs, /*UseDriverMode=*/true, ContainErrors));
+  bool ContainErrors = false;
+  auto NewHeadOptions = std::make_unique(
+  ParseArgStrings(NewCfgHeadArgs, /*UseDriverMode=*/true, ContainErrors));
+  if (ContainErrors)
+return true;
+  auto NewTailOptions = std::make_unique(
+  ParseArgStrings(NewCfgTailArgs, /*UseDriverMode=*/true, ContainErrors));
   if (ContainErrors)
 return true;
 
   // Claim all arguments that come from a configuration file so that the driver
   // does not warn on any that is unused.
-  for (Arg *A : *NewOptions)
+  for (Arg *A : *NewHeadOptions)
+ 

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

2024-12-06 Thread Paul Osmialowski via cfe-commits


@@ -82,3 +82,29 @@
 // CHECK-TWO-CONFIGS: -isysroot
 // CHECK-TWO-CONFIGS-SAME: /opt/data
 // CHECK-TWO-CONFIGS-SAME: -Wall
+
+//--- The linker input flags should be moved to the end of input list and 
appear only when linking.
+// RUN: %clang --target=aarch64-unknown-linux-gnu --config 
%S/Inputs/config-l.cfg %s -lmylib -Wl,foo.a -### 2>&1 | FileCheck %s 
-check-prefix CHECK-LINKING
+// RUN: %clang --target=aarch64-unknown-linux-gnu --config 
%S/Inputs/config-l.cfg -fopenmp %s -lmylib -Wl,foo.a -### 2>&1 | FileCheck %s 
-check-prefix CHECK-LINKING-LIBOMP-GOES-LAST
+// RUN: %clang --target=aarch64-unknown-linux-gnu --config 
%S/Inputs/config-l.cfg -S %s -### 2>&1 | FileCheck %s -check-prefix 
CHECK-NOLINKING
+// RUN: %clang --target=aarch64-unknown-linux-gnu --config 
%S/Inputs/config-l.cfg -fopenmp -S %s -### 2>&1 | FileCheck %s -check-prefix 
CHECK-NOLINKING-OPENMP
+// RUN: %clang --target=x86_64-pc-windows-msvc--config 
%S/Inputs/config-l.cfg %s -lmylib -Wl,foo.lib -### 2>&1 | FileCheck %s 
-check-prefix CHECK-LINKING-MSVC
+// RUN: %clang --target=x86_64-pc-windows-msvc--config 
%S/Inputs/config-l.cfg -S %s -### 2>&1 | FileCheck %s -check-prefix 
CHECK-NOLINKING-MSVC
+// CHECK-LINKING: Configuration file: {{.*}}Inputs{{.}}config-l.cfg
+// CHECK-LINKING: "-Wall"
+// CHECK-LINKING: "--as-needed" "{{.*}}-{{.*}}.o" "-lmylib" "foo.a" "-lm" 
"-Bstatic" "-lhappy" "-Bdynamic"
+// CHECK-LINKING-LIBOMP-GOES-LAST: Configuration file: 
{{.*}}Inputs{{.}}config-l.cfg
+// CHECK-LINKING-LIBOMP-GOES-LAST: "-Wall" {{.*}}"-fopenmp"

pawosm-arm wrote:

No no, it's the crt... things that are going last. I've renamed `-LAST` to 
`-AFTER` to avoid confusion.


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] Reapply "[clang] Fix name lookup for dependent bases" (PR #118003)

2024-12-06 Thread Mike Hommey via cfe-commits

glandium wrote:

I was creducing it (well, cvise-ing). Here's a reproducer:
```
template  struct MozPromise {
  class Private;

private:
  void *mMagic4;
};
template 
struct MozPromise::Private
: MozPromise {
  void SetTaskPriority() { mMagic4 }
}
```

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


[clang] [llvm] [AArch64] Implement intrinsics for SME FP8 F1CVT/F2CVT and BF1CVT/BF2CVT (PR #118027)

2024-12-06 Thread via cfe-commits

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

LGTM

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


[clang] Reapply "[clang] Fix name lookup for dependent bases" (PR #118003)

2024-12-06 Thread Vladislav Belov via cfe-commits

vbe-sc wrote:

> I was creducing it (well, cvise-ing). Here's a reproducer:
> 
> ```
> template  struct MozPromise {
>   class Private;
> 
> private:
>   void *mMagic4;
> };
> template 
> struct MozPromise::Private
> : MozPromise {
>   void SetTaskPriority() { mMagic4 }
> }
> ```

Thanks, I'll investigate with it 

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


[clang] [Clang] [NFC] Migrate visitors in ARCMigrate (PR #116792)

2024-12-06 Thread via cfe-commits

Sirraide wrote:

>  we intend to open a PR to remove it

@rjmccall Actually, any idea when that might happen? If not, I can take a look 
at that too (the only thing is I might miss a few things that we could remove 
because I’m not really familiar w/ ARCMT).

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


[clang] [llvm] [AArch64] Implement intrinsics for SME FP8 FMOPA (PR #118115)

2024-12-06 Thread via cfe-commits


@@ -305,6 +305,21 @@ multiclass sme_outer_product_fp32 sz, 
ZPRRegOp zpr_ty, string mne
   def : SME_ZA_Tile_TwoPred_TwoVec_Pat;
 }
 
+multiclass sme2_fp8_fmopa_za32 {
+def NAME : sme_fp_outer_product_inst<0, 0b01, 0b00, TileOp32, ZPR8, 
mnemonic>, SMEPseudo2Instr {
+  bits<2> ZAda;
+  let Inst{1-0} = ZAda;
+  let Inst{2}   = 0b0;
+

CarolineConcatto wrote:

Ok, fair enough. 

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


[clang] [llvm] [AArch64] Implement intrinsics for SME FP8 FMOPA (PR #118115)

2024-12-06 Thread via cfe-commits

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

LGTM

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


[clang-tools-extra] [clangd] Re-land "support outgoing calls in call hierarchy" (PR #117673)

2024-12-06 Thread via cfe-commits

pidgeon777 wrote:

Hello everyone, I'm seeking clarification regarding the implementation of 
Outgoing Calls support.

The LSP protocol currently allows to implement two display modes for 
visualizing outgoing function calls:

```c
#include 

void function1(void) {
printf("Executing function 1\n");
}

void function2(void) {
printf("Executing function 2\n");
}

void function3(void) {
printf("Executing function 3\n");
}

int main(void) {
printf("Starting main function\n");
function1();
function2();
function3();
return 0;
}
```

For example, when querying all functions called from `main`, results could be 
presented in two ways:

1. Display all the called function occurrences in `main`:
   - function1()
   - function2()
   - function2()
   - function3()

2. Display the definitions of the functions called in `main`:
   - function1()
   - function2()
   - function3()

According to one of the developers, this feature should provide all the 
necessary data to allow the LSP client to determine the presentation method 
(approach 1 or 2). I previously asked about this in another thread (which I 
cannot locate now), and I would appreciate confirmation that this will indeed 
be possible with the upcoming **clangd** changes.

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


[clang] [flang] [clang][driver] When -fveclib=ArmPL flag is in use, always link against libamath (PR #116432)

2024-12-06 Thread Paul Osmialowski via cfe-commits


@@ -490,6 +490,35 @@ void tools::AddLinkerInputs(const ToolChain &TC, const 
InputInfoList &Inputs,
 else
   A.renderAsInput(Args, CmdArgs);
   }
+  if (const Arg *A = Args.getLastArg(options::OPT_fveclib)) {
+const llvm::Triple &Triple = TC.getTriple();
+StringRef V = A->getValue();
+if (V == "ArmPL" && (Triple.isOSLinux() || Triple.isOSDarwin())) {
+  // To support -fveclib=ArmPL we need to link against libamath.
+  // Some of the libamath functions depend on libm, at the same time,
+  // libamath exports its own implementation of some of the libm
+  // functions. Since here we are interested only in the subset of
+  // libamath functions that is covered by the veclib mappings,
+  // we need to do the following:
+  //
+  // 1. On Linux, link only when actually needed.
+  //
+  // 2. Prefer libm functions over libamath.
+  //
+  // 3. Link against libm to resolve libamath dependencies.
+  //
+  if (Triple.isOSLinux()) {
+CmdArgs.push_back(Args.MakeArgString("--push-state"));
+CmdArgs.push_back(Args.MakeArgString("--as-needed"));
+  }
+  CmdArgs.push_back(Args.MakeArgString("-lm"));

pawosm-arm wrote:

No no, it isn't simply a dependency. It's a matter of prioritizing system-libm 
over libamath which contains faster (and potentially less accurate) 
implementations of some of the libm functions. I was advised, these should not 
be used in normal circumstances (it is just unfortunate that for historical 
reasons, this veclib provider isn't just veclib provider; but for 
-fveclib=ArmPL there is no other, and likely there will be no other). From the 
other side, some of the libamath-only functions depend on libm functions that 
are not in libamath. Is it certain that start/end-group algorithm would look 
into libraries in-order preferring library first to provide looked upon symbol 
(e.g. when given `--start-group -lm -lamath --end-group`)? Besides, Darwin's 
default ld doesn't seem to support --start-group.


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


[clang] [-Wunsafe-buffer-usage] Suppress warning for multi-dimensional constant arrays (PR #118249)

2024-12-06 Thread Malavika Samak via cfe-commits

https://github.com/malavikasamak updated 
https://github.com/llvm/llvm-project/pull/118249

>From 6281b990096f058cfb6ed862631b8d6436db23f7 Mon Sep 17 00:00:00 2001
From: MalavikaSamak 
Date: Fri, 29 Nov 2024 14:53:37 +0530
Subject: [PATCH] [-Wunsafe-buffer-usage] Suppress warning for
 multi-dimensional constant arrays

Do not warn about unsafe buffer access, when multi-dimensional constant arrays
are accessed and their indices are within the bounds of the buffer. Warning in
such cases would be a false positive. Such a suppression already exists for 1-d
arrays and it is now extended to multi-dimensional arrays.

(rdar://137926311)
(rdar://140320139)
---
 clang/lib/Analysis/UnsafeBufferUsage.cpp  | 51 +--
 .../warn-unsafe-buffer-usage-array.cpp| 34 +
 .../warn-unsafe-buffer-usage-field-attr.cpp   |  1 -
 .../test/SemaCXX/warn-unsafe-buffer-usage.cpp | 26 +-
 4 files changed, 71 insertions(+), 41 deletions(-)

diff --git a/clang/lib/Analysis/UnsafeBufferUsage.cpp 
b/clang/lib/Analysis/UnsafeBufferUsage.cpp
index 5f36ffa926b269..e7ba2c324247d7 100644
--- a/clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ b/clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -433,37 +433,36 @@ AST_MATCHER(ArraySubscriptExpr, isSafeArraySubscript) {
   //already duplicated
   //  - call both from Sema and from here
 
-  const auto *BaseDRE =
-  dyn_cast(Node.getBase()->IgnoreParenImpCasts());
-  const auto *SLiteral =
-  dyn_cast(Node.getBase()->IgnoreParenImpCasts());
-  uint64_t size;
-
-  if (!BaseDRE && !SLiteral)
-return false;
-
-  if (BaseDRE) {
-if (!BaseDRE->getDecl())
-  return false;
-const auto *CATy = Finder->getASTContext().getAsConstantArrayType(
-BaseDRE->getDecl()->getType());
-if (!CATy) {
+  std::function CheckBounds =
+  [&CheckBounds](const ArraySubscriptExpr *ASE) -> bool {
+uint64_t limit;
+if (const auto *CATy =
+dyn_cast(ASE->getBase()
+->IgnoreParenImpCasts()
+->getType()
+->getUnqualifiedDesugaredType())) {
+  limit = CATy->getLimitedSize();
+} else if (const auto *SLiteral = dyn_cast(
+   ASE->getBase()->IgnoreParenImpCasts())) {
+  limit = SLiteral->getLength() + 1;
+} else {
   return false;
 }
-size = CATy->getLimitedSize();
-  } else if (SLiteral) {
-size = SLiteral->getLength() + 1;
-  }
 
-  if (const auto *IdxLit = dyn_cast(Node.getIdx())) {
-const APInt ArrIdx = IdxLit->getValue();
-// FIXME: ArrIdx.isNegative() we could immediately emit an error as that's 
a
-// bug
-if (ArrIdx.isNonNegative() && ArrIdx.getLimitedValue() < size)
+if (const auto *IdxLit = dyn_cast(ASE->getIdx())) {
+  const APInt ArrIdx = IdxLit->getValue();
+  if (!ArrIdx.isNonNegative() || ArrIdx.getLimitedValue() >= limit)
+return false;
+  if (const auto *BaseASE = dyn_cast(
+  ASE->getBase()->IgnoreParenImpCasts())) {
+return CheckBounds(BaseASE);
+  }
   return true;
-  }
+}
+return false;
+  };
 
-  return false;
+  return CheckBounds(&Node);
 }
 
 AST_MATCHER_P(CallExpr, hasNumArgs, unsigned, Num) {
diff --git a/clang/test/SemaCXX/warn-unsafe-buffer-usage-array.cpp 
b/clang/test/SemaCXX/warn-unsafe-buffer-usage-array.cpp
index c6c93a27e4b969..2d143a94bf86f4 100644
--- a/clang/test/SemaCXX/warn-unsafe-buffer-usage-array.cpp
+++ b/clang/test/SemaCXX/warn-unsafe-buffer-usage-array.cpp
@@ -52,3 +52,37 @@ void constant_id_string(unsigned idx) {
   unsafe_char = ""[1]; //expected-warning{{unsafe buffer access}} 
   unsafe_char = ""[idx]; //expected-warning{{unsafe buffer access}}
 }
+
+typedef float Float4x4[4][4];
+
+// expected-warning@+1 {{'matrix' is an unsafe buffer that does not perform 
bounds checks}}
+float two_dimension_array(Float4x4& matrix) {
+  // expected-warning@+1{{unsafe buffer access}}
+  float a = matrix[0][4];
+
+  a = matrix[0][3];
+
+  // expected-note@+1{{used in buffer access here}}
+  a = matrix[4][0];
+
+  return matrix[1][1];
+}
+
+typedef float Float2x3x4[2][3][4];
+float multi_dimension_array(Float2x3x4& matrix) {
+  float *f = matrix[0][2];
+  return matrix[1][2][3];
+}
+
+char array_strings[][11] = {
+"Apple", "Banana", "Cherry", "Date", "Elderberry"
+};
+
+char array_string[] = "123456";
+
+char access_strings() {
+  char c = array_strings[0][4];
+  c = array_strings[3][10];
+  c = array_string[5];
+  return c;
+}
diff --git a/clang/test/SemaCXX/warn-unsafe-buffer-usage-field-attr.cpp 
b/clang/test/SemaCXX/warn-unsafe-buffer-usage-field-attr.cpp
index 0ba605475925b9..1636c948da075a 100644
--- a/clang/test/SemaCXX/warn-unsafe-buffer-usage-field-attr.cpp
+++ b/clang/test/SemaCXX/warn-unsafe-buffer-usage-field-attr.cpp
@@ -96,7 +96,6 @@ void test_attribute_multiple_fields (D d) {
 
int v = d.buf[0]; //expected-warning{{field 'buf' prone to u

[clang] [-Wunsafe-buffer-usage] Suppress warning for multi-dimensional constant arrays (PR #118249)

2024-12-06 Thread Malavika Samak via cfe-commits

https://github.com/malavikasamak updated 
https://github.com/llvm/llvm-project/pull/118249

>From 3a73ee44036b4162115061751241f105147f5947 Mon Sep 17 00:00:00 2001
From: MalavikaSamak 
Date: Fri, 29 Nov 2024 14:53:37 +0530
Subject: [PATCH] [-Wunsafe-buffer-usage] Suppress warning for
 multi-dimensional constant arrays

Do not warn about unsafe buffer access, when multi-dimensional constant arrays
are accessed and their indices are within the bounds of the buffer. Warning in
such cases would be a false positive. Such a suppression already exists for 1-d
arrays and it is now extended to multi-dimensional arrays.

(rdar://137926311)
(rdar://140320139)
---
 clang/lib/Analysis/UnsafeBufferUsage.cpp  | 51 +--
 .../warn-unsafe-buffer-usage-array.cpp| 40 +++
 .../warn-unsafe-buffer-usage-field-attr.cpp   |  1 -
 .../test/SemaCXX/warn-unsafe-buffer-usage.cpp | 38 +-
 4 files changed, 89 insertions(+), 41 deletions(-)

diff --git a/clang/lib/Analysis/UnsafeBufferUsage.cpp 
b/clang/lib/Analysis/UnsafeBufferUsage.cpp
index 5f36ffa926b269..e7ba2c324247d7 100644
--- a/clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ b/clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -433,37 +433,36 @@ AST_MATCHER(ArraySubscriptExpr, isSafeArraySubscript) {
   //already duplicated
   //  - call both from Sema and from here
 
-  const auto *BaseDRE =
-  dyn_cast(Node.getBase()->IgnoreParenImpCasts());
-  const auto *SLiteral =
-  dyn_cast(Node.getBase()->IgnoreParenImpCasts());
-  uint64_t size;
-
-  if (!BaseDRE && !SLiteral)
-return false;
-
-  if (BaseDRE) {
-if (!BaseDRE->getDecl())
-  return false;
-const auto *CATy = Finder->getASTContext().getAsConstantArrayType(
-BaseDRE->getDecl()->getType());
-if (!CATy) {
+  std::function CheckBounds =
+  [&CheckBounds](const ArraySubscriptExpr *ASE) -> bool {
+uint64_t limit;
+if (const auto *CATy =
+dyn_cast(ASE->getBase()
+->IgnoreParenImpCasts()
+->getType()
+->getUnqualifiedDesugaredType())) {
+  limit = CATy->getLimitedSize();
+} else if (const auto *SLiteral = dyn_cast(
+   ASE->getBase()->IgnoreParenImpCasts())) {
+  limit = SLiteral->getLength() + 1;
+} else {
   return false;
 }
-size = CATy->getLimitedSize();
-  } else if (SLiteral) {
-size = SLiteral->getLength() + 1;
-  }
 
-  if (const auto *IdxLit = dyn_cast(Node.getIdx())) {
-const APInt ArrIdx = IdxLit->getValue();
-// FIXME: ArrIdx.isNegative() we could immediately emit an error as that's 
a
-// bug
-if (ArrIdx.isNonNegative() && ArrIdx.getLimitedValue() < size)
+if (const auto *IdxLit = dyn_cast(ASE->getIdx())) {
+  const APInt ArrIdx = IdxLit->getValue();
+  if (!ArrIdx.isNonNegative() || ArrIdx.getLimitedValue() >= limit)
+return false;
+  if (const auto *BaseASE = dyn_cast(
+  ASE->getBase()->IgnoreParenImpCasts())) {
+return CheckBounds(BaseASE);
+  }
   return true;
-  }
+}
+return false;
+  };
 
-  return false;
+  return CheckBounds(&Node);
 }
 
 AST_MATCHER_P(CallExpr, hasNumArgs, unsigned, Num) {
diff --git a/clang/test/SemaCXX/warn-unsafe-buffer-usage-array.cpp 
b/clang/test/SemaCXX/warn-unsafe-buffer-usage-array.cpp
index c6c93a27e4b969..7dd6c83dbba2a8 100644
--- a/clang/test/SemaCXX/warn-unsafe-buffer-usage-array.cpp
+++ b/clang/test/SemaCXX/warn-unsafe-buffer-usage-array.cpp
@@ -52,3 +52,43 @@ void constant_id_string(unsigned idx) {
   unsafe_char = ""[1]; //expected-warning{{unsafe buffer access}} 
   unsafe_char = ""[idx]; //expected-warning{{unsafe buffer access}}
 }
+
+typedef float Float4x4[4][4];
+
+// expected-warning@+1 {{'matrix' is an unsafe buffer that does not perform 
bounds checks}}
+float two_dimension_array(Float4x4& matrix, unsigned idx) {
+  // expected-warning@+1{{unsafe buffer access}}
+  float a = matrix[0][4];
+
+  a = matrix[0][3];
+
+  // expected-note@+1{{used in buffer access here}}
+  a = matrix[4][0];
+
+  a = matrix[idx][0]; // expected-note{{used in buffer access here}}
+
+  a = matrix[0][idx]; //expected-warning{{unsafe buffer access}}
+
+  a = matrix[idx][idx]; //expected-warning{{unsafe buffer access}} // 
expected-note{{used in buffer access here}}
+
+  return matrix[1][1];
+}
+
+typedef float Float2x3x4[2][3][4];
+float multi_dimension_array(Float2x3x4& matrix) {
+  float *f = matrix[0][2];
+  return matrix[1][2][3];
+}
+
+char array_strings[][11] = {
+  "Apple", "Banana", "Cherry", "Date", "Elderberry"
+};
+
+char array_string[] = "123456";
+
+char access_strings() {
+  char c = array_strings[0][4];
+  c = array_strings[3][10];
+  c = array_string[5];
+  return c;
+}
diff --git a/clang/test/SemaCXX/warn-unsafe-buffer-usage-field-attr.cpp 
b/clang/test/SemaCXX/warn-unsafe-buffer-usage-field-attr.cpp
index 0ba605475925b9..

[clang] [-Wunsafe-buffer-usage] Suppress warning for multi-dimensional constant arrays (PR #118249)

2024-12-06 Thread Malavika Samak via cfe-commits

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


[clang] [-Wunsafe-buffer-usage] Suppress warning for multi-dimensional constant arrays (PR #118249)

2024-12-06 Thread Malavika Samak via cfe-commits


@@ -52,3 +52,37 @@ void constant_id_string(unsigned idx) {
   unsafe_char = ""[1]; //expected-warning{{unsafe buffer access}} 
   unsafe_char = ""[idx]; //expected-warning{{unsafe buffer access}}
 }
+
+typedef float Float4x4[4][4];
+
+// expected-warning@+1 {{'matrix' is an unsafe buffer that does not perform 
bounds checks}}
+float two_dimension_array(Float4x4& matrix) {
+  // expected-note@+1{{used in buffer access here}}
+  float a = matrix[0][4];

malavikasamak wrote:

Done

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


[clang] [lldb] [lldb] Analyze enum promotion type during parsing (PR #115005)

2024-12-06 Thread Michael Buch via cfe-commits

Michael137 wrote:

> So, is this patch worth pursuing or is it too much code for a too specific 
> use case?

Sorry I was out for a few weeks when you pinged. I'll have another pass/think 
about it early next week (if nobody else gets to it before me).

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


[clang] [clang][bytecode] Check primitive bit casts for indeterminate bits (PR #118954)

2024-12-06 Thread Timm Baeder via cfe-commits

https://github.com/tbaederr updated 
https://github.com/llvm/llvm-project/pull/118954

>From 265be81d34dfc3f24595ccd60f72a1207b700e06 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Fri, 6 Dec 2024 12:04:47 +0100
Subject: [PATCH] [clang][bytecode] Check primitive bit casts for indeterminate
 bits

Record bits ranges of initialized bits and check them in
allInitialized().
---
 clang/lib/AST/ByteCode/BitcastBuffer.cpp  | 51 +++
 clang/lib/AST/ByteCode/BitcastBuffer.h| 31 ---
 clang/lib/AST/ByteCode/Compiler.cpp   |  7 +--
 .../lib/AST/ByteCode/InterpBuiltinBitCast.cpp |  1 +
 .../ByteCode/builtin-bit-cast-bitfields.cpp   | 23 -
 clang/test/AST/ByteCode/builtin-bit-cast.cpp  | 21 +++-
 6 files changed, 105 insertions(+), 29 deletions(-)

diff --git a/clang/lib/AST/ByteCode/BitcastBuffer.cpp 
b/clang/lib/AST/ByteCode/BitcastBuffer.cpp
index 0cc97b0b6bf190..7f29c7c2db0147 100644
--- a/clang/lib/AST/ByteCode/BitcastBuffer.cpp
+++ b/clang/lib/AST/ByteCode/BitcastBuffer.cpp
@@ -6,6 +6,7 @@
 //
 
//===--===//
 #include "BitcastBuffer.h"
+#include "llvm/ADT/STLExtras.h"
 
 using namespace clang;
 using namespace clang::interp;
@@ -60,6 +61,56 @@ BitcastBuffer::copyBits(Bits BitOffset, Bits BitWidth, Bits 
FullBitWidth,
   return Out;
 }
 
+bool BitcastBuffer::allInitialized() const {
+  Bits Sum;
+  for (BitRange BR : InitializedBits)
+Sum += BR.size();
+
+  return Sum == FinalBitSize;
+}
+
+void BitcastBuffer::markInitialized(Bits Offset, Bits Length) {
+  if (Length.isZero())
+return;
+
+  BitRange Element(Offset, Offset + Length - Bits(1));
+  if (InitializedBits.empty()) {
+InitializedBits.push_back(Element);
+return;
+  }
+
+  assert(InitializedBits.size() >= 1);
+  // Common case of just appending.
+  Bits End = InitializedBits.back().End;
+  if (End <= Offset) {
+// Merge this range with the last one.
+// In the best-case scenario, this means we only ever have
+// one single bit range covering all bits.
+if (End == (Offset - Bits(1))) {
+  InitializedBits.back().End = Element.End;
+  return;
+}
+
+// Otherwise, we can simply append.
+InitializedBits.push_back(Element);
+  } else {
+// Insert sorted.
+auto It = std::upper_bound(InitializedBits.begin(), InitializedBits.end(),
+   Element);
+InitializedBits.insert(It, Element);
+  }
+
+#ifndef NDEBUG
+  // Ensure ranges are sorted and non-overlapping.
+  assert(llvm::is_sorted(InitializedBits));
+  for (unsigned I = 1; I != InitializedBits.size(); ++I) {
+[[maybe_unused]] auto Prev = InitializedBits[I - 1];
+[[maybe_unused]] auto Cur = InitializedBits[I];
+assert(Prev.End.N < Cur.Start.N);
+  }
+#endif
+}
+
 #if 0
   template
   static std::string hex(T t) {
diff --git a/clang/lib/AST/ByteCode/BitcastBuffer.h 
b/clang/lib/AST/ByteCode/BitcastBuffer.h
index c7b170ceb168fa..00fbdc9b85421d 100644
--- a/clang/lib/AST/ByteCode/BitcastBuffer.h
+++ b/clang/lib/AST/ByteCode/BitcastBuffer.h
@@ -8,6 +8,7 @@
 #ifndef LLVM_CLANG_AST_INTERP_BITCAST_BUFFER_H
 #define LLVM_CLANG_AST_INTERP_BITCAST_BUFFER_H
 
+#include "llvm/ADT/SmallVector.h"
 #include 
 #include 
 #include 
@@ -30,14 +31,20 @@ struct Bits {
   bool nonZero() const { return N != 0; }
   bool isZero() const { return N == 0; }
 
-  Bits operator-(Bits Other) { return Bits(N - Other.N); }
-  Bits operator+(Bits Other) { return Bits(N + Other.N); }
+  Bits operator-(Bits Other) const { return Bits(N - Other.N); }
+  Bits operator+(Bits Other) const { return Bits(N + Other.N); }
   Bits operator+=(size_t O) {
 N += O;
 return *this;
   }
+  Bits operator+=(Bits O) {
+N += O.N;
+return *this;
+  }
 
-  bool operator>=(Bits Other) { return N >= Other.N; }
+  bool operator>=(Bits Other) const { return N >= Other.N; }
+  bool operator<=(Bits Other) const { return N <= Other.N; }
+  bool operator==(Bits Other) const { return N == Other.N; }
 };
 
 /// A quantity in bytes.
@@ -48,11 +55,21 @@ struct Bytes {
   Bits toBits() const { return Bits(N * 8); }
 };
 
+struct BitRange {
+  Bits Start;
+  Bits End;
+
+  BitRange(Bits Start, Bits End) : Start(Start), End(End) {}
+  Bits size() const { return End - Start + Bits(1); }
+  bool operator<(BitRange Other) const { return Start.N < Other.Start.N; }
+};
+
 /// Track what bits have been initialized to known values and which ones
 /// have indeterminate value.
 struct BitcastBuffer {
   Bits FinalBitSize;
   std::unique_ptr Data;
+  llvm::SmallVector InitializedBits;
 
   BitcastBuffer(Bits FinalBitSize) : FinalBitSize(FinalBitSize) {
 assert(FinalBitSize.isFullByte());
@@ -64,10 +81,10 @@ struct BitcastBuffer {
   Bits size() const { return FinalBitSize; }
 
   /// Returns \c true if all bits in the buffer have been initialized.
-  bool allInitialized() const {
-// FIXME: Implement.
-return true;
-  }
+

[clang] [clang][AArch64] Fix C++11 style initialization of typedef'd vectors (PR #118956)

2024-12-06 Thread Benjamin Maxwell via cfe-commits

https://github.com/MacDue created 
https://github.com/llvm/llvm-project/pull/118956

Previously, this hit an `llvm_unreachable()` assertion as the type of `vec_t` 
did not exactly match the return type of `svdup_s8`, as it was wrapped in a 
typedef.

Comparing the canonical types instead allows the types to match correctly and 
avoids the crash.

Fixes #107609

>From cb9857aad6f84e4ac473f572a828ea5db6d4fd58 Mon Sep 17 00:00:00 2001
From: Benjamin Maxwell 
Date: Fri, 6 Dec 2024 11:42:11 +
Subject: [PATCH] [clang][AArch64] Fix C++11 style initialization of typedef'd
 vectors

Previously, this hit an `llvm_unreachable()` assertion as the type of
`vec_t` did not exactly match the return type of `svdup_s8`, as it was
wrapped in a typedef.

Comparing the canonical types instead allows the types to match
correctly and avoids the crash.

Fixes #107609
---
 clang/lib/CodeGen/CGExprScalar.cpp|  3 ++-
 .../aarch64-sve-vector-init-typedef.cpp   | 23 +++
 2 files changed, 25 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/CodeGenCXX/aarch64-sve-vector-init-typedef.cpp

diff --git a/clang/lib/CodeGen/CGExprScalar.cpp 
b/clang/lib/CodeGen/CGExprScalar.cpp
index 4ae8a2b22b1bba..bbf68a4c66192a 100644
--- a/clang/lib/CodeGen/CGExprScalar.cpp
+++ b/clang/lib/CodeGen/CGExprScalar.cpp
@@ -2102,7 +2102,8 @@ Value *ScalarExprEmitter::VisitInitListExpr(InitListExpr 
*E) {
   Expr *InitVector = E->getInit(0);
 
   // Initialize from another scalable vector of the same type.
-  if (InitVector->getType() == E->getType())
+  if (InitVector->getType().getCanonicalType() ==
+  E->getType().getCanonicalType())
 return Visit(InitVector);
 }
 
diff --git a/clang/test/CodeGenCXX/aarch64-sve-vector-init-typedef.cpp 
b/clang/test/CodeGenCXX/aarch64-sve-vector-init-typedef.cpp
new file mode 100644
index 00..3ac0fc5f39a566
--- /dev/null
+++ b/clang/test/CodeGenCXX/aarch64-sve-vector-init-typedef.cpp
@@ -0,0 +1,23 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 2
+// RUN: %clang_cc1 -fclang-abi-compat=latest -triple aarch64-none-linux-gnu 
-target-feature +sve -emit-llvm -o - %s | FileCheck %s
+
+#include 
+
+using vec_t = svint8_t;
+
+/// From: https://github.com/llvm/llvm-project/issues/107609
+/// The type of `vec` is a typedef of svint8_t, while svdup_s8 returns the 
non-typedef'd type.
+
+// CHECK-LABEL: define dso_local  @_Z20sve_init_dup_typedefv
+// CHECK-SAME: () #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[VEC:%.*]] = alloca , align 16
+// CHECK-NEXT:[[TMP0:%.*]] = call  
@llvm.aarch64.sve.dup.x.nxv16i8(i8 2)
+// CHECK-NEXT:store  [[TMP0]], ptr [[VEC]], align 16
+// CHECK-NEXT:[[TMP1:%.*]] = load , ptr [[VEC]], align 16
+// CHECK-NEXT:ret  [[TMP1]]
+//
+vec_t sve_init_dup_typedef() {
+  vec_t vec{svdup_s8(2)};
+  return vec;
+}

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


[clang] [clang][AArch64] Fix C++11 style initialization of typedef'd vectors (PR #118956)

2024-12-06 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Benjamin Maxwell (MacDue)


Changes

Previously, this hit an `llvm_unreachable()` assertion as the type of `vec_t` 
did not exactly match the return type of `svdup_s8`, as it was wrapped in a 
typedef.

Comparing the canonical types instead allows the types to match correctly and 
avoids the crash.

Fixes #107609

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


2 Files Affected:

- (modified) clang/lib/CodeGen/CGExprScalar.cpp (+2-1) 
- (added) clang/test/CodeGenCXX/aarch64-sve-vector-init-typedef.cpp (+23) 


``diff
diff --git a/clang/lib/CodeGen/CGExprScalar.cpp 
b/clang/lib/CodeGen/CGExprScalar.cpp
index 4ae8a2b22b1bba..bbf68a4c66192a 100644
--- a/clang/lib/CodeGen/CGExprScalar.cpp
+++ b/clang/lib/CodeGen/CGExprScalar.cpp
@@ -2102,7 +2102,8 @@ Value *ScalarExprEmitter::VisitInitListExpr(InitListExpr 
*E) {
   Expr *InitVector = E->getInit(0);
 
   // Initialize from another scalable vector of the same type.
-  if (InitVector->getType() == E->getType())
+  if (InitVector->getType().getCanonicalType() ==
+  E->getType().getCanonicalType())
 return Visit(InitVector);
 }
 
diff --git a/clang/test/CodeGenCXX/aarch64-sve-vector-init-typedef.cpp 
b/clang/test/CodeGenCXX/aarch64-sve-vector-init-typedef.cpp
new file mode 100644
index 00..3ac0fc5f39a566
--- /dev/null
+++ b/clang/test/CodeGenCXX/aarch64-sve-vector-init-typedef.cpp
@@ -0,0 +1,23 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 2
+// RUN: %clang_cc1 -fclang-abi-compat=latest -triple aarch64-none-linux-gnu 
-target-feature +sve -emit-llvm -o - %s | FileCheck %s
+
+#include 
+
+using vec_t = svint8_t;
+
+/// From: https://github.com/llvm/llvm-project/issues/107609
+/// The type of `vec` is a typedef of svint8_t, while svdup_s8 returns the 
non-typedef'd type.
+
+// CHECK-LABEL: define dso_local  @_Z20sve_init_dup_typedefv
+// CHECK-SAME: () #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[VEC:%.*]] = alloca , align 16
+// CHECK-NEXT:[[TMP0:%.*]] = call  
@llvm.aarch64.sve.dup.x.nxv16i8(i8 2)
+// CHECK-NEXT:store  [[TMP0]], ptr [[VEC]], align 16
+// CHECK-NEXT:[[TMP1:%.*]] = load , ptr [[VEC]], align 16
+// CHECK-NEXT:ret  [[TMP1]]
+//
+vec_t sve_init_dup_typedef() {
+  vec_t vec{svdup_s8(2)};
+  return vec;
+}

``




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


[clang] Switch builtin strings to use string tables (PR #118734)

2024-12-06 Thread Nikita Popov via cfe-commits

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

Fails to build with GCC:
```

FAILED: tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/Builtins.cpp.o 
CCACHE_CPP2=yes CCACHE_HASHDIR=yes /usr/bin/ccache /usr/bin/c++ -DCLANG_EXPORTS 
-DGTEST_HAS_RTTI=0 -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS 
-D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS 
-I/tmp/llvm-project-build-stage1/tools/clang/lib/Basic 
-I/var/llvm-compile-time-tracker/llvm-project/clang/lib/Basic 
-I/var/llvm-compile-time-tracker/llvm-project/clang/include 
-I/tmp/llvm-project-build-stage1/tools/clang/include 
-I/tmp/llvm-project-build-stage1/include 
-I/var/llvm-compile-time-tracker/llvm-project/llvm/include -fPIC 
-fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time 
-fno-lifetime-dse -Wall -Wextra -Wno-unused-parameter -Wwrite-strings 
-Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long 
-Wimplicit-fallthrough -Wno-uninitialized -Wno-nonnull -Wno-class-memaccess 
-Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type 
-Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment 
-Wno-misleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color 
-ffunction-sections -fdata-sections -fno-common -Woverloaded-virtual 
-fno-strict-aliasing -O3 -DNDEBUG  -fno-exceptions -funwind-tables -fno-rtti 
-std=c++17 -MD -MT 
tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/Builtins.cpp.o -MF 
tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/Builtins.cpp.o.d -o 
tools/clang/lib/Basic/CMakeFiles/obj.clangBasic.dir/Builtins.cpp.o -c 
/var/llvm-compile-time-tracker/llvm-project/clang/lib/Basic/Builtins.cpp
In file included from 
/var/llvm-compile-time-tracker/llvm-project/clang/lib/Basic/Builtins.cpp:13:
/var/llvm-compile-time-tracker/llvm-project/clang/include/clang/Basic/Builtins.h:137:3:
 error: ‘#pragma’ is not allowed here
  137 |   _Pragma("GCC diagnostic push")
   \
  |   ^~~
/var/llvm-compile-time-tracker/llvm-project/clang/include/clang/Basic/Builtins.h:149:3:
 note: in expansion of macro ‘CLANG_BUILTIN_DETAIL_STR_TABLE’
  149 |   CLANG_BUILTIN_DETAIL_STR_TABLE(#ID "\0" TYPE "\0" ATTRS "\0" 
/*FEATURE*/ "\0")
  |   ^~
/var/llvm-compile-time-tracker/llvm-project/clang/lib/Basic/Builtins.cpp:34:9: 
note: in expansion of macro ‘CLANG_BUILTIN_STR_TABLE’
   34 | CLANG_BUILTIN_STR_TABLE("not a builtin function", "", "")
  | ^~~
/var/llvm-compile-time-tracker/llvm-project/clang/lib/Basic/Builtins.cpp: In 
member function ‘std::pair 
clang::Builtin::Context::getStrTableAndInfo(unsigned int) const’:
/var/llvm-compile-time-tracker/llvm-project/clang/lib/Basic/Builtins.cpp:48:65: 
error: could not convert ‘{, }’ from 
‘’ to ‘std::pair’
   48 | return {BuiltinStorage.StringTable, BuiltinStorage.Infos[ID]};
  | ^
  | |
  | 

```

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


[clang] [HLSL] Fix call convention mismatch for ctor/dtor (PR #118651)

2024-12-06 Thread Nathan Gauër via cfe-commits


@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -x hlsl -emit-llvm 
-O3 -o - %s | FileCheck %s --check-prefixes=CHECK,CHECK-DXIL
+// RUN: %clang_cc1 -triple spirv-vulkan-compute -x hlsl -emit-llvm -O3 -o - %s 
| FileCheck %s --check-prefixes=CHECK,CHECK-SPIRV

Keenuts wrote:

There is the `RWBuffer-constructor.hlsl` test that tests almost the same code, 
but without any optimization passes. Or do you mean another kind of test?

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


[clang] [clang][NFC] Change suppression mapping interfaces to use SourceLocation (PR #118960)

2024-12-06 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: kadir çetinkaya (kadircet)


Changes

This way we can delay getting a presumed location even further, only
performing it for diagnostics that are mapped.


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


4 Files Affected:

- (modified) clang/include/clang/Basic/Diagnostic.h (+3-2) 
- (modified) clang/lib/Basic/Diagnostic.cpp (+16-7) 
- (modified) clang/lib/Basic/DiagnosticIDs.cpp (+2-9) 
- (modified) clang/unittests/Basic/DiagnosticTest.cpp (+25-14) 


``diff
diff --git a/clang/include/clang/Basic/Diagnostic.h 
b/clang/include/clang/Basic/Diagnostic.h
index d271accca3d3b7..510b782e35d065 100644
--- a/clang/include/clang/Basic/Diagnostic.h
+++ b/clang/include/clang/Basic/Diagnostic.h
@@ -560,7 +560,8 @@ class DiagnosticsEngine : public 
RefCountedBase {
   ArgToStringFnTy ArgToStringFn;
 
   /// Whether the diagnostic should be suppressed in FilePath.
-  llvm::unique_function
+  llvm::unique_function
   DiagSuppressionMapping;
 
 public:
@@ -972,7 +973,7 @@ class DiagnosticsEngine : public 
RefCountedBase {
   /// These take presumed locations into account, and can still be overriden by
   /// clang-diagnostics pragmas.
   void setDiagSuppressionMapping(llvm::MemoryBuffer &Input);
-  bool isSuppressedViaMapping(diag::kind DiagId, StringRef FilePath) const;
+  bool isSuppressedViaMapping(diag::kind DiagId, SourceLocation DiagLoc) const;
 
   /// Issue the message to the client.
   ///
diff --git a/clang/lib/Basic/Diagnostic.cpp b/clang/lib/Basic/Diagnostic.cpp
index 2d0e358116362c..682e0a1993 100644
--- a/clang/lib/Basic/Diagnostic.cpp
+++ b/clang/lib/Basic/Diagnostic.cpp
@@ -500,7 +500,8 @@ class WarningsSpecialCaseList : public 
llvm::SpecialCaseList {
   // the last section take precedence in such cases.
   void processSections(DiagnosticsEngine &Diags);
 
-  bool isDiagSuppressed(diag::kind DiagId, StringRef FilePath) const;
+  bool isDiagSuppressed(diag::kind DiagId, SourceLocation DiagLoc,
+const SourceManager &SM) const;
 
 private:
   // Find the longest glob pattern that matches FilePath amongst
@@ -573,13 +574,14 @@ void 
DiagnosticsEngine::setDiagSuppressionMapping(llvm::MemoryBuffer &Input) {
   WarningSuppressionList->processSections(*this);
   DiagSuppressionMapping =
   [WarningSuppressionList(std::move(WarningSuppressionList))](
-  diag::kind DiagId, StringRef Path) {
-return WarningSuppressionList->isDiagSuppressed(DiagId, Path);
+  diag::kind DiagId, SourceLocation DiagLoc, const SourceManager &SM) {
+return WarningSuppressionList->isDiagSuppressed(DiagId, DiagLoc, SM);
   };
 }
 
 bool WarningsSpecialCaseList::isDiagSuppressed(diag::kind DiagId,
-   StringRef FilePath) const {
+   SourceLocation DiagLoc,
+   const SourceManager &SM) const {
   const Section *DiagSection = DiagToSection.lookup(DiagId);
   if (!DiagSection)
 return false;
@@ -589,7 +591,13 @@ bool WarningsSpecialCaseList::isDiagSuppressed(diag::kind 
DiagId,
 return false;
   const llvm::StringMap &CategoriesToMatchers =
   SrcEntriesIt->getValue();
-  return globsMatches(CategoriesToMatchers, FilePath);
+  // We also use presumed locations here to improve reproducibility for
+  // preprocessed inputs.
+  if (PresumedLoc PLoc = SM.getPresumedLoc(DiagLoc); PLoc.isValid())
+return globsMatches(
+CategoriesToMatchers,
+llvm::sys::path::remove_leading_dotslash(PLoc.getFilename()));
+  return false;
 }
 
 bool WarningsSpecialCaseList::globsMatches(
@@ -614,8 +622,9 @@ bool WarningsSpecialCaseList::globsMatches(
 }
 
 bool DiagnosticsEngine::isSuppressedViaMapping(diag::kind DiagId,
-   StringRef FilePath) const {
-  return DiagSuppressionMapping && DiagSuppressionMapping(DiagId, FilePath);
+   SourceLocation DiagLoc) const {
+  if (!hasSourceManager() || !DiagSuppressionMapping) return false;
+  return DiagSuppressionMapping(DiagId, DiagLoc, getSourceManager());
 }
 
 void DiagnosticsEngine::Report(const StoredDiagnostic &storedDiag) {
diff --git a/clang/lib/Basic/DiagnosticIDs.cpp 
b/clang/lib/Basic/DiagnosticIDs.cpp
index 44922aa7872dbf..d77f28c80b2eb2 100644
--- a/clang/lib/Basic/DiagnosticIDs.cpp
+++ b/clang/lib/Basic/DiagnosticIDs.cpp
@@ -601,15 +601,8 @@ DiagnosticIDs::getDiagnosticSeverity(unsigned DiagID, 
SourceLocation Loc,
 return diag::Severity::Ignored;
 
   // Clang-diagnostics pragmas always take precedence over suppression mapping.
-  if (!Mapping.isPragma() && Diag.DiagSuppressionMapping) {
-// We also use presumed locations here to improve reproducibility for
-// preprocessed inputs.
-if (PresumedLoc PLoc = SM.getPresumedLoc(Loc);
-PLoc.isValid() && Diag.isSuppressedViaMapping(
-  

[clang] [clang][NFC] Change suppression mapping interfaces to use SourceLocation (PR #118960)

2024-12-06 Thread kadir çetinkaya via cfe-commits

https://github.com/kadircet created 
https://github.com/llvm/llvm-project/pull/118960

This way we can delay getting a presumed location even further, only
performing it for diagnostics that are mapped.


From 4c52dda9a253d643ef52f1f5f294cd1fd5bcfa76 Mon Sep 17 00:00:00 2001
From: Kadir Cetinkaya 
Date: Fri, 6 Dec 2024 13:13:15 +0100
Subject: [PATCH] [clang][NFC] Change suppression mapping interfaces to use
 SourceLocation

This way we can delay getting a presumed location even further, only
performing it for diagnostics that are mapped.
---
 clang/include/clang/Basic/Diagnostic.h   |  5 +--
 clang/lib/Basic/Diagnostic.cpp   | 23 +-
 clang/lib/Basic/DiagnosticIDs.cpp| 11 ++-
 clang/unittests/Basic/DiagnosticTest.cpp | 39 +++-
 4 files changed, 46 insertions(+), 32 deletions(-)

diff --git a/clang/include/clang/Basic/Diagnostic.h 
b/clang/include/clang/Basic/Diagnostic.h
index d271accca3d3b7..510b782e35d065 100644
--- a/clang/include/clang/Basic/Diagnostic.h
+++ b/clang/include/clang/Basic/Diagnostic.h
@@ -560,7 +560,8 @@ class DiagnosticsEngine : public 
RefCountedBase {
   ArgToStringFnTy ArgToStringFn;
 
   /// Whether the diagnostic should be suppressed in FilePath.
-  llvm::unique_function
+  llvm::unique_function
   DiagSuppressionMapping;
 
 public:
@@ -972,7 +973,7 @@ class DiagnosticsEngine : public 
RefCountedBase {
   /// These take presumed locations into account, and can still be overriden by
   /// clang-diagnostics pragmas.
   void setDiagSuppressionMapping(llvm::MemoryBuffer &Input);
-  bool isSuppressedViaMapping(diag::kind DiagId, StringRef FilePath) const;
+  bool isSuppressedViaMapping(diag::kind DiagId, SourceLocation DiagLoc) const;
 
   /// Issue the message to the client.
   ///
diff --git a/clang/lib/Basic/Diagnostic.cpp b/clang/lib/Basic/Diagnostic.cpp
index 2d0e358116362c..682e0a1993 100644
--- a/clang/lib/Basic/Diagnostic.cpp
+++ b/clang/lib/Basic/Diagnostic.cpp
@@ -500,7 +500,8 @@ class WarningsSpecialCaseList : public 
llvm::SpecialCaseList {
   // the last section take precedence in such cases.
   void processSections(DiagnosticsEngine &Diags);
 
-  bool isDiagSuppressed(diag::kind DiagId, StringRef FilePath) const;
+  bool isDiagSuppressed(diag::kind DiagId, SourceLocation DiagLoc,
+const SourceManager &SM) const;
 
 private:
   // Find the longest glob pattern that matches FilePath amongst
@@ -573,13 +574,14 @@ void 
DiagnosticsEngine::setDiagSuppressionMapping(llvm::MemoryBuffer &Input) {
   WarningSuppressionList->processSections(*this);
   DiagSuppressionMapping =
   [WarningSuppressionList(std::move(WarningSuppressionList))](
-  diag::kind DiagId, StringRef Path) {
-return WarningSuppressionList->isDiagSuppressed(DiagId, Path);
+  diag::kind DiagId, SourceLocation DiagLoc, const SourceManager &SM) {
+return WarningSuppressionList->isDiagSuppressed(DiagId, DiagLoc, SM);
   };
 }
 
 bool WarningsSpecialCaseList::isDiagSuppressed(diag::kind DiagId,
-   StringRef FilePath) const {
+   SourceLocation DiagLoc,
+   const SourceManager &SM) const {
   const Section *DiagSection = DiagToSection.lookup(DiagId);
   if (!DiagSection)
 return false;
@@ -589,7 +591,13 @@ bool WarningsSpecialCaseList::isDiagSuppressed(diag::kind 
DiagId,
 return false;
   const llvm::StringMap &CategoriesToMatchers =
   SrcEntriesIt->getValue();
-  return globsMatches(CategoriesToMatchers, FilePath);
+  // We also use presumed locations here to improve reproducibility for
+  // preprocessed inputs.
+  if (PresumedLoc PLoc = SM.getPresumedLoc(DiagLoc); PLoc.isValid())
+return globsMatches(
+CategoriesToMatchers,
+llvm::sys::path::remove_leading_dotslash(PLoc.getFilename()));
+  return false;
 }
 
 bool WarningsSpecialCaseList::globsMatches(
@@ -614,8 +622,9 @@ bool WarningsSpecialCaseList::globsMatches(
 }
 
 bool DiagnosticsEngine::isSuppressedViaMapping(diag::kind DiagId,
-   StringRef FilePath) const {
-  return DiagSuppressionMapping && DiagSuppressionMapping(DiagId, FilePath);
+   SourceLocation DiagLoc) const {
+  if (!hasSourceManager() || !DiagSuppressionMapping) return false;
+  return DiagSuppressionMapping(DiagId, DiagLoc, getSourceManager());
 }
 
 void DiagnosticsEngine::Report(const StoredDiagnostic &storedDiag) {
diff --git a/clang/lib/Basic/DiagnosticIDs.cpp 
b/clang/lib/Basic/DiagnosticIDs.cpp
index 44922aa7872dbf..d77f28c80b2eb2 100644
--- a/clang/lib/Basic/DiagnosticIDs.cpp
+++ b/clang/lib/Basic/DiagnosticIDs.cpp
@@ -601,15 +601,8 @@ DiagnosticIDs::getDiagnosticSeverity(unsigned DiagID, 
SourceLocation Loc,
 return diag::Severity::Ignored;
 
   // Clang-diagnostics pragmas always take precedence over suppressio

[clang] [clang][NFC] Change suppression mapping interfaces to use SourceLocation (PR #118960)

2024-12-06 Thread via cfe-commits

github-actions[bot] wrote:




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



You can test this locally with the following command:


``bash
git-clang-format --diff 3dbff90b16b5964b9fa468438ff40985be5c1ade 
4c52dda9a253d643ef52f1f5f294cd1fd5bcfa76 --extensions cpp,h -- 
clang/include/clang/Basic/Diagnostic.h clang/lib/Basic/Diagnostic.cpp 
clang/lib/Basic/DiagnosticIDs.cpp clang/unittests/Basic/DiagnosticTest.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Basic/Diagnostic.cpp b/clang/lib/Basic/Diagnostic.cpp
index 682e0a..ae71758bc8 100644
--- a/clang/lib/Basic/Diagnostic.cpp
+++ b/clang/lib/Basic/Diagnostic.cpp
@@ -623,7 +623,8 @@ bool WarningsSpecialCaseList::globsMatches(
 
 bool DiagnosticsEngine::isSuppressedViaMapping(diag::kind DiagId,
SourceLocation DiagLoc) const {
-  if (!hasSourceManager() || !DiagSuppressionMapping) return false;
+  if (!hasSourceManager() || !DiagSuppressionMapping)
+return false;
   return DiagSuppressionMapping(DiagId, DiagLoc, getSourceManager());
 }
 
diff --git a/clang/unittests/Basic/DiagnosticTest.cpp 
b/clang/unittests/Basic/DiagnosticTest.cpp
index 5c3d7934b2..e03d9a464d 100644
--- a/clang/unittests/Basic/DiagnosticTest.cpp
+++ b/clang/unittests/Basic/DiagnosticTest.cpp
@@ -268,8 +268,7 @@ TEST_F(SuppressionMappingTest, SuppressesGroup) {
   EXPECT_THAT(diags(), IsEmpty());
 
   SourceLocation FooLoc = locForFile("foo.cpp");
-  EXPECT_TRUE(
-  Diags.isSuppressedViaMapping(diag::warn_unused_function, FooLoc));
+  EXPECT_TRUE(Diags.isSuppressedViaMapping(diag::warn_unused_function, 
FooLoc));
   EXPECT_FALSE(Diags.isSuppressedViaMapping(diag::warn_deprecated, FooLoc));
 }
 

``




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


[clang] Reland [Clang] skip default argument instantiation for non-defining friend declarations to meet [dcl.fct.default] p4 (PR #115487)

2024-12-06 Thread Oleksandr T. via cfe-commits

https://github.com/a-tarasyuk updated 
https://github.com/llvm/llvm-project/pull/115487

>From 5e24d212f797b5fa1b6da1526c807046373d3c21 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Fri, 8 Nov 2024 16:13:17 +0200
Subject: [PATCH 1/6] [Clang] skip default argument instantiation for
 non-defining friend declarations to meet [dcl.fct.default] p4

---
 clang/docs/ReleaseNotes.rst   |  2 +
 .../lib/Sema/SemaTemplateInstantiateDecl.cpp  |  4 ++
 clang/test/CXX/temp/temp.res/p4.cpp   | 43 +++
 3 files changed, 49 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index d0c43ff11f7bae..e8cf6fc50a1290 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -636,6 +636,8 @@ Bug Fixes to C++ Support
   an implicitly instantiated class template specialization. (#GH51051)
 - Fixed an assertion failure caused by invalid enum forward declarations. 
(#GH112208)
 - Name independent data members were not correctly initialized from default 
member initializers. (#GH114069)
+- Fixed an assertion failure caused by invalid default argument substitutions 
in non-defining
+  friend declarations. (#GH113324).
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 5a001843e2ba46..200519c71c57ab 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -4694,6 +4694,10 @@ bool Sema::InstantiateDefaultArgument(SourceLocation 
CallLoc, FunctionDecl *FD,
   ParmVarDecl *Param) {
   assert(Param->hasUninstantiatedDefaultArg());
 
+  if (FD->getFriendObjectKind() != Decl::FOK_None &&
+  !FD->getTemplateInstantiationPattern())
+return true;
+
   // Instantiate the expression.
   //
   // FIXME: Pass in a correct Pattern argument, otherwise
diff --git a/clang/test/CXX/temp/temp.res/p4.cpp 
b/clang/test/CXX/temp/temp.res/p4.cpp
index f54d8649f5da88..cf6c45b4c351c5 100644
--- a/clang/test/CXX/temp/temp.res/p4.cpp
+++ b/clang/test/CXX/temp/temp.res/p4.cpp
@@ -185,3 +185,46 @@ template struct S {
   friend void X::f(T::type);
 };
 }
+
+namespace GH113324 {
+template  struct S1 {
+  friend void f1(S1, int = 0); // expected-error {{friend declaration 
specifying a default argument must be a definition}}
+  friend void f2(S1 a, S1 = decltype(a){}); // expected-error {{friend 
declaration specifying a default argument must be a definition}}
+};
+
+template  using alias = int;
+template  struct S2 {
+  // FIXME: We miss diagnosing the default argument instantiation failure
+  // (forming reference to void)
+  friend void f3(S2, int a = alias(1)); // expected-error {{friend 
declaration specifying a default argument must be a definition}}
+};
+
+struct S3 {
+  friend void f4(S3, int = 42) { }
+};
+
+template  using __enable_if_t = int;
+template  struct S4 {
+  static const int value = v;
+};
+struct S5 {
+  template <__enable_if_t::value, int> = 0>
+  S5(const char *);
+};
+struct S6 {
+  template 
+  friend void f5(int, S6, a, b, S5 = "") { }
+};
+
+void test() {
+  f1(S1<>{});
+  f2(S1<>{});
+  f3(S2());
+
+  S3 s3;
+  f4(s3);
+
+  S6 s6;
+  auto result = f5(0, s6, [] {}, [] {}); // expected-error {{variable has 
incomplete type 'void}}
+}
+} // namespace GH113324

>From 3ad3b6c5f35730be32f4f6ba2dc8d19f53be0442 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Fri, 8 Nov 2024 16:53:39 +0200
Subject: [PATCH 2/6] update comments

---
 clang/lib/Sema/SemaTemplateInstantiateDecl.cpp | 7 +++
 1 file changed, 7 insertions(+)

diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp 
b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 200519c71c57ab..0bbab95001ad8e 100644
--- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -4694,6 +4694,13 @@ bool Sema::InstantiateDefaultArgument(SourceLocation 
CallLoc, FunctionDecl *FD,
   ParmVarDecl *Param) {
   assert(Param->hasUninstantiatedDefaultArg());
 
+  // FIXME: We don't track member specialization info for non-defining
+  // friend declarations, so we will not be able to later find the function
+  // pattern. As a workaround, don't instantiate the default argument in this
+  // case. This is correct per wording and only an error recovery issue, as per
+  // [dcl.fct.default]p4:
+  //   if a friend declaration D specifies a default argument expression,
+  //   that declaration shall be a definition.
   if (FD->getFriendObjectKind() != Decl::FOK_None &&
   !FD->getTemplateInstantiationPattern())
 return true;

>From 09215dea0212368ef54956d8464788cc4b88cc02 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Thu, 21 Nov 2024 16:56:11 +0200
Subject: [PATCH 3/6] move cases that cause code generation failures to the
 appropriate folder

---
 clang/test/CXX/temp/temp.res/p4.cpp | 23

[clang] [llvm] [AArch64] Fix argument passing for SVE tuples (PR #118961)

2024-12-06 Thread Momchil Velikov via cfe-commits

https://github.com/momchil-velikov created 
https://github.com/llvm/llvm-project/pull/118961

The fix for passing Pure Scalable Types 
(https://github.com/llvm/llvm-project/pull/112747) was incomplete,
it didn't handle correctly tuples of SVE vectors (e.g. `sveboolx2_t`, 
`svfloat32x4_t`, etc).

These types are Pure Scalable Types and should be passed either entirely in 
vector registers
or indirectly in memory, not split.


>From 7e2d60348850619fb7b0c8a88e92ab103f907d34 Mon Sep 17 00:00:00 2001
From: Momchil Velikov 
Date: Fri, 6 Dec 2024 11:08:21 +
Subject: [PATCH 1/2] Handle scalable store size in MemCpyOptimizer

The compiler crashes with an ICE when it tries to create a `memset` with
scalable size.
---
 .../lib/Transforms/Scalar/MemCpyOptimizer.cpp |  3 +-
 .../CodeGen/AArch64/memset-scalable-size.ll   | 56 +++
 2 files changed, 58 insertions(+), 1 deletion(-)
 create mode 100644 llvm/test/CodeGen/AArch64/memset-scalable-size.ll

diff --git a/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp 
b/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
index 0cba5d077da62b..fc5f6ff2b7f377 100644
--- a/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
+++ b/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
@@ -800,8 +800,9 @@ bool MemCpyOptPass::processStore(StoreInst *SI, 
BasicBlock::iterator &BBI) {
 // in subsequent passes.
 auto *T = V->getType();
 if (T->isAggregateType()) {
-  uint64_t Size = DL.getTypeStoreSize(T);
   IRBuilder<> Builder(SI);
+  Value *Size =
+  Builder.CreateTypeSize(Builder.getInt64Ty(), DL.getTypeStoreSize(T));
   auto *M = Builder.CreateMemSet(SI->getPointerOperand(), ByteVal, Size,
  SI->getAlign());
   M->copyMetadata(*SI, LLVMContext::MD_DIAssignID);
diff --git a/llvm/test/CodeGen/AArch64/memset-scalable-size.ll 
b/llvm/test/CodeGen/AArch64/memset-scalable-size.ll
new file mode 100644
index 00..8ea6330f235a69
--- /dev/null
+++ b/llvm/test/CodeGen/AArch64/memset-scalable-size.ll
@@ -0,0 +1,56 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 
UTC_ARGS: --version 5
+; RUN: opt -S --passes=memcpyopt < %s | FileCheck %s
+target triple = "aarch64-unknown-linux"
+
+define void @f0() {
+; CHECK-LABEL: define void @f0() {
+; CHECK-NEXT:  [[ENTRY:.*:]]
+; CHECK-NEXT:[[P:%.*]] = alloca { ,  
}, align 2
+; CHECK-NEXT:[[TMP0:%.*]] = call i64 @llvm.vscale.i64()
+; CHECK-NEXT:[[TMP1:%.*]] = mul i64 [[TMP0]], 4
+; CHECK-NEXT:call void @llvm.memset.p0.i64(ptr align 2 [[P]], i8 0, i64 
[[TMP1]], i1 false)
+; CHECK-NEXT:call void @g(ptr [[P]])
+; CHECK-NEXT:ret void
+;
+entry:
+  %p = alloca { , }, align 2
+  store { ,  } zeroinitializer, ptr %p, 
align 2
+  call void @g(ptr %p)
+  ret void
+}
+
+define void @f1() {
+; CHECK-LABEL: define void @f1() {
+; CHECK-NEXT:  [[ENTRY:.*:]]
+; CHECK-NEXT:[[P:%.*]] = alloca { , ,  }, align 16
+; CHECK-NEXT:[[TMP0:%.*]] = call i64 @llvm.vscale.i64()
+; CHECK-NEXT:[[TMP1:%.*]] = mul i64 [[TMP0]], 48
+; CHECK-NEXT:call void @llvm.memset.p0.i64(ptr align 16 [[P]], i8 0, i64 
[[TMP1]], i1 false)
+; CHECK-NEXT:call void @g(ptr [[P]])
+; CHECK-NEXT:ret void
+;
+entry:
+  %p = alloca {, ,  }, align 16
+  store {, ,  } 
zeroinitializer, ptr %p, align 16
+  call void @g(ptr %p)
+  ret void
+}
+
+define void @f2() {
+; CHECK-LABEL: define void @f2() {
+; CHECK-NEXT:  [[ENTRY:.*:]]
+; CHECK-NEXT:[[P:%.*]] = alloca { , ,  }, align 16
+; CHECK-NEXT:[[TMP0:%.*]] = call i64 @llvm.vscale.i64()
+; CHECK-NEXT:[[TMP1:%.*]] = mul i64 [[TMP0]], 192
+; CHECK-NEXT:call void @llvm.memset.p0.i64(ptr align 16 [[P]], i8 0, i64 
[[TMP1]], i1 false)
+; CHECK-NEXT:call void @g(ptr [[P]])
+; CHECK-NEXT:ret void
+;
+entry:
+  %p = alloca {, ,  }, align 16
+  store {, ,  } 
zeroinitializer, ptr %p, align 16
+  call void @g(ptr %p)
+  ret void
+}
+
+declare void @g(ptr)

>From 83331bbf9d083ec8cba96acc32114ed1518e91f7 Mon Sep 17 00:00:00 2001
From: Momchil Velikov 
Date: Fri, 6 Dec 2024 10:47:43 +
Subject: [PATCH 2/2] Fix SVE tuples

---
 clang/lib/CodeGen/Targets/AArch64.cpp |  68 +++
 .../test/CodeGen/AArch64/pure-scalable-args.c |  19 
 .../CodeGenCXX/aarch64-mangle-sve-vectors.cpp | 106 --
 3 files changed, 111 insertions(+), 82 deletions(-)

diff --git a/clang/lib/CodeGen/Targets/AArch64.cpp 
b/clang/lib/CodeGen/Targets/AArch64.cpp
index be33e26f047841..ad7f405cc72550 100644
--- a/clang/lib/CodeGen/Targets/AArch64.cpp
+++ b/clang/lib/CodeGen/Targets/AArch64.cpp
@@ -52,6 +52,7 @@ class AArch64ABIInfo : public ABIInfo {
 
   bool isIllegalVectorType(QualType Ty) const;
 
+  bool passAsAggregateType(QualType Ty) const;
   bool passAsPureScalableType(QualType Ty, unsigned &NV, unsigned &NP,
   SmallVectorImpl &CoerceToSeq) 
const;
 
@@ -337,6 +338,10 @@ ABIArgInfo 
AArch64ABIInfo::coerceAndExpandPureScalableAggregate(
   NSRN += NVe

[clang] [llvm] [AArch64] Fix argument passing for SVE tuples (PR #118961)

2024-12-06 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-codegen

Author: Momchil Velikov (momchil-velikov)


Changes

The fix for passing Pure Scalable Types 
(https://github.com/llvm/llvm-project/pull/112747) was incomplete,
it didn't handle correctly tuples of SVE vectors (e.g. `sveboolx2_t`, 
`svfloat32x4_t`, etc).

These types are Pure Scalable Types and should be passed either entirely in 
vector registers
or indirectly in memory, not split.


---

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


5 Files Affected:

- (modified) clang/lib/CodeGen/Targets/AArch64.cpp (+44-24) 
- (modified) clang/test/CodeGen/AArch64/pure-scalable-args.c (+19) 
- (modified) clang/test/CodeGenCXX/aarch64-mangle-sve-vectors.cpp (+48-58) 
- (modified) llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp (+2-1) 
- (added) llvm/test/CodeGen/AArch64/memset-scalable-size.ll (+56) 


``diff
diff --git a/clang/lib/CodeGen/Targets/AArch64.cpp 
b/clang/lib/CodeGen/Targets/AArch64.cpp
index be33e26f047841..ad7f405cc72550 100644
--- a/clang/lib/CodeGen/Targets/AArch64.cpp
+++ b/clang/lib/CodeGen/Targets/AArch64.cpp
@@ -52,6 +52,7 @@ class AArch64ABIInfo : public ABIInfo {
 
   bool isIllegalVectorType(QualType Ty) const;
 
+  bool passAsAggregateType(QualType Ty) const;
   bool passAsPureScalableType(QualType Ty, unsigned &NV, unsigned &NP,
   SmallVectorImpl &CoerceToSeq) 
const;
 
@@ -337,6 +338,10 @@ ABIArgInfo 
AArch64ABIInfo::coerceAndExpandPureScalableAggregate(
   NSRN += NVec;
   NPRN += NPred;
 
+  // Handle SVE vector tuples.
+  if (Ty->isSVESizelessBuiltinType())
+return ABIArgInfo::getDirect();
+
   llvm::Type *UnpaddedCoerceToType =
   UnpaddedCoerceToSeq.size() == 1
   ? UnpaddedCoerceToSeq[0]
@@ -362,7 +367,7 @@ ABIArgInfo AArch64ABIInfo::classifyArgumentType(QualType 
Ty, bool IsVariadicFn,
   if (isIllegalVectorType(Ty))
 return coerceIllegalVector(Ty, NSRN, NPRN);
 
-  if (!isAggregateTypeForABI(Ty)) {
+  if (!passAsAggregateType(Ty)) {
 // Treat an enum type as its underlying type.
 if (const EnumType *EnumTy = Ty->getAs())
   Ty = EnumTy->getDecl()->getIntegerType();
@@ -417,7 +422,7 @@ ABIArgInfo AArch64ABIInfo::classifyArgumentType(QualType 
Ty, bool IsVariadicFn,
   // elsewhere for GNU compatibility.
   uint64_t Size = getContext().getTypeSize(Ty);
   bool IsEmpty = isEmptyRecord(getContext(), Ty, true);
-  if (IsEmpty || Size == 0) {
+  if (!Ty->isSVESizelessBuiltinType() && (IsEmpty || Size == 0)) {
 if (!getContext().getLangOpts().CPlusPlus || isDarwinPCS())
   return ABIArgInfo::getIgnore();
 
@@ -504,7 +509,7 @@ ABIArgInfo AArch64ABIInfo::classifyReturnType(QualType 
RetTy,
   if (RetTy->isVectorType() && getContext().getTypeSize(RetTy) > 128)
 return getNaturalAlignIndirect(RetTy);
 
-  if (!isAggregateTypeForABI(RetTy)) {
+  if (!passAsAggregateType(RetTy)) {
 // Treat an enum type as its underlying type.
 if (const EnumType *EnumTy = RetTy->getAs())
   RetTy = EnumTy->getDecl()->getIntegerType();
@@ -519,7 +524,8 @@ ABIArgInfo AArch64ABIInfo::classifyReturnType(QualType 
RetTy,
   }
 
   uint64_t Size = getContext().getTypeSize(RetTy);
-  if (isEmptyRecord(getContext(), RetTy, true) || Size == 0)
+  if (!RetTy->isSVESizelessBuiltinType() &&
+  (isEmptyRecord(getContext(), RetTy, true) || Size == 0))
 return ABIArgInfo::getIgnore();
 
   const Type *Base = nullptr;
@@ -654,6 +660,15 @@ bool 
AArch64ABIInfo::isZeroLengthBitfieldPermittedInHomogeneousAggregate()
   return true;
 }
 
+bool AArch64ABIInfo::passAsAggregateType(QualType Ty) const {
+  if (Kind == AArch64ABIKind::AAPCS && Ty->isSVESizelessBuiltinType()) {
+const auto *BT = Ty->getAs();
+return !BT->isSVECount() &&
+   getContext().getBuiltinVectorTypeInfo(BT).NumVectors > 1;
+  }
+  return isAggregateTypeForABI(Ty);
+}
+
 // Check if a type needs to be passed in registers as a Pure Scalable Type (as
 // defined by AAPCS64). Return the number of data vectors and the number of
 // predicate vectors in the type, into `NVec` and `NPred`, respectively. Upon
@@ -719,37 +734,38 @@ bool AArch64ABIInfo::passAsPureScalableType(
 return true;
   }
 
-  const auto *VT = Ty->getAs();
-  if (!VT)
-return false;
+  if (const auto *VT = Ty->getAs()) {
+if (VT->getVectorKind() == VectorKind::SveFixedLengthPredicate) {
+  ++NPred;
+  if (CoerceToSeq.size() + 1 > 12)
+return false;
+  CoerceToSeq.push_back(convertFixedToScalableVectorType(VT));
+  return true;
+}
 
-  if (VT->getVectorKind() == VectorKind::SveFixedLengthPredicate) {
-++NPred;
-if (CoerceToSeq.size() + 1 > 12)
-  return false;
-CoerceToSeq.push_back(convertFixedToScalableVectorType(VT));
-return true;
-  }
+if (VT->getVectorKind() == VectorKind::SveFixedLengthData) {
+  ++NVec;
+  if (CoerceToSeq.size() + 1 > 12)
+return false;
+  CoerceToSeq.p

[clang] [llvm] [AArch64] Fix argument passing for SVE tuples (PR #118961)

2024-12-06 Thread Momchil Velikov via cfe-commits

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


[clang-tools-extra] 6bb5d6a - [NFC] Use a move instead of a copy to optimize performance. (#118699)

2024-12-06 Thread via cfe-commits

Author: Zahira Ammarguellat
Date: 2024-12-06T07:54:27-05:00
New Revision: 6bb5d6ae23cace42bd108ca14e17e863c73bbb5c

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

LOG: [NFC] Use a move instead of a copy to optimize performance. (#118699)

This is an issue detected by a static analysis tool,

Added: 


Modified: 
clang-tools-extra/clangd/ModulesBuilder.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/ModulesBuilder.cpp 
b/clang-tools-extra/clangd/ModulesBuilder.cpp
index 29508901f85bba..bee31fe51555e0 100644
--- a/clang-tools-extra/clangd/ModulesBuilder.cpp
+++ b/clang-tools-extra/clangd/ModulesBuilder.cpp
@@ -199,7 +199,7 @@ bool IsModuleFileUpToDate(PathRef ModuleFilePath,
 
   SourceManager SourceMgr(*Diags, FileMgr);
 
-  HeaderSearch HeaderInfo(HSOpts, SourceMgr, *Diags, LangOpts,
+  HeaderSearch HeaderInfo(std::move(HSOpts), SourceMgr, *Diags, LangOpts,
   /*Target=*/nullptr);
 
   TrivialModuleLoader ModuleLoader;



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


[clang] [RISCV] Merging RISCVToolChain and BareMetal toolchains (PR #118809)

2024-12-06 Thread Kito Cheng via cfe-commits


@@ -519,9 +650,24 @@ void baremetal::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
 CmdArgs.push_back(Arch == llvm::Triple::aarch64_be ? "-EB" : "-EL");
   }
 
-  if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles,
-   options::OPT_r)) {
-CmdArgs.push_back(Args.MakeArgString(TC.GetFilePath("crt0.o")));
+  bool WantCRTs =
+  !Args.hasArg(options::OPT_nostdlib, options::OPT_nostartfiles);
+
+  const char *crtbegin, *crtend;
+  if (WantCRTs) {
+if (!Args.hasArg(options::OPT_r))
+  CmdArgs.push_back(Args.MakeArgString(TC.GetFilePath("crt0.o")));
+auto RuntimeLib = TC.GetRuntimeLibType(Args);
+if (RuntimeLib == ToolChain::RLT_Libgcc) {
+  crtbegin = "crtbegin.o";
+  crtend = "crtend.o";
+} else {
+  assert(RuntimeLib == ToolChain::RLT_CompilerRT);
+  crtbegin =
+  TC.getCompilerRTArgString(Args, "crtbegin", ToolChain::FT_Object);
+  crtend = TC.getCompilerRTArgString(Args, "crtend", ToolChain::FT_Object);
+}
+CmdArgs.push_back(Args.MakeArgString(TC.GetFilePath(crtbegin)));
   }
 
   Args.addAllArgs(CmdArgs, {options::OPT_L, options::OPT_T_Group,

kito-cheng wrote:

Add `options::OPT_u` here:
e.g.
```suggestion
  Args.addAllArgs(CmdArgs, {options::OPT_L, options::OPT_T_Group, 
options::OPT_u,
```

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


[clang-tools-extra] [NFC] Use a move instead of a copy to optimize performance. (PR #118699)

2024-12-06 Thread Zahira Ammarguellat via cfe-commits

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


[clang] [Driver][OpenMP] Fix OpenMP target-toolchain-option parser (PR #115375)

2024-12-06 Thread Jefferson Le Quellec via cfe-commits

jle-quel wrote:

@MaskRay @alexey-bataev, if everything looks good now, could we go ahead and 
merge this PR? Thanks for your time reviewing!

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


[clang-tools-extra] [clangd] Document the cases in which Dex::Files and IdxContents are populated (PR #118906)

2024-12-06 Thread kadir çetinkaya via cfe-commits


@@ -121,6 +121,8 @@ class Dex : public SymbolIndex {
   llvm::DenseMap, std::vector> 
Relations;
   std::shared_ptr KeepAlive; // poor man's move-only std::any
   // Set of files which were used during this index build.
+  // Files and IdxContents are only populated for dynamic and background
+  // indexes, not static indexes.

kadircet wrote:

i am not sure if it's worthwhile to encode some state of the users into the 
library here. they're likely to get out-of-sync quickly, and I don't think they 
provide any value to the reader. `Dex` is independent of the concepts such as 
dyanmic/static index.

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


[clang-tools-extra] [NFC] Use a move instead of a copy to optimize performance. (PR #118699)

2024-12-06 Thread kadir çetinkaya via cfe-commits

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

this is just a shared-ptr, but still better without the copy, thanks!

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


[clang] [RFC] Initial implementation of P2719 (PR #113510)

2024-12-06 Thread via cfe-commits


@@ -4778,6 +4784,16 @@ class Sema final : public SemaBase {
 
   CXXRecordDecl *getStdBadAlloc() const;
   EnumDecl *getStdAlignValT() const;
+  const ClassTemplateDecl *getStdTypeIdentity() const;
+  ClassTemplateDecl *getStdTypeIdentity();
+  std::optional instantiateSpecializedTypeIdentity(QualType Subject);

cor3ntin wrote:

QualType already has an invalid state, why do we need the optional?

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


[clang] [RFC] Initial implementation of P2719 (PR #113510)

2024-12-06 Thread via cfe-commits


@@ -2709,14 +2831,63 @@ static bool resolveAllocationOverload(
   llvm_unreachable("Unreachable, bad result from BestViableFunction");
 }
 
-bool Sema::FindAllocationFunctions(SourceLocation StartLoc, SourceRange Range,
-   AllocationFunctionScope NewScope,
-   AllocationFunctionScope DeleteScope,
-   QualType AllocType, bool IsArray,
-   bool &PassAlignment, MultiExprArg PlaceArgs,
-   FunctionDecl *&OperatorNew,
-   FunctionDecl *&OperatorDelete,
-   bool Diagnose) {
+enum class DeallocLookupMode { Untyped, OptionallyTyped, RequireTyped };
+
+static void LookupGlobalDeallocationFunctions(Sema &S, SourceLocation Loc,
+  LookupResult &FoundDelete,
+  DeallocLookupMode Mode,
+  DeclarationName Name,
+  QualType DeallocType) {
+  S.LookupQualifiedName(FoundDelete, S.Context.getTranslationUnitDecl());
+  if (Mode == DeallocLookupMode::OptionallyTyped) {
+bool RemoveTypedDecl = Mode == DeallocLookupMode::Untyped;

cor3ntin wrote:

Is all of that dead code (RemoveTypedDecl can't be true, right?) ?

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


[clang] [RFC] Initial implementation of P2719 (PR #113510)

2024-12-06 Thread via cfe-commits


@@ -3130,6 +3130,30 @@ bool Type::isStdByteType() const {
   return false;
 }
 
+const TemplateDecl *Type::getSpecializedTemplateDecl() const {
+  const Type *DesugaredType = getUnqualifiedDesugaredType();
+  if (const auto *Specialization =
+  DesugaredType->getAs())
+return Specialization->getTemplateName().getAsTemplateDecl();
+  if (const auto *Record = DesugaredType->getAsCXXRecordDecl()) {
+if (const auto *CTS = dyn_cast(Record))
+  return CTS->getSpecializedTemplate();
+  }
+  return nullptr;
+}
+
+bool Type::isTypeIdentitySpecialization() const {
+  const TemplateDecl *SpecializedDecl = getSpecializedTemplateDecl();
+  if (!SpecializedDecl)
+return false;
+  IdentifierInfo *II = SpecializedDecl->getIdentifier();
+  if (!II)
+return false;
+  if (!SpecializedDecl->isInStdNamespace())
+return false;
+  return II->isStr("type_identity");

cor3ntin wrote:

Might as well collapse that on a single line

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


[clang] [RFC] Initial implementation of P2719 (PR #113510)

2024-12-06 Thread via cfe-commits


@@ -3543,7 +3543,14 @@ def : Separate<["-"], "fnew-alignment">, 
Alias;
 def : Flag<["-"], "faligned-new">, Alias;
 def : Flag<["-"], "fno-aligned-new">, Alias;
 def faligned_new_EQ : Joined<["-"], "faligned-new=">;
-
+defm cxx_type_aware_allocators : 
BoolFOption<"experimental-cxx-type-aware-allocators",
+  LangOpts<"TypeAwareAllocators">, DefaultFalse,
+  PosFlag,
+  NegFlag, BothFlags<[], [ClangOption, CC1Option]>>;

cor3ntin wrote:

```suggestion
  PosFlag,
  NegFlag, BothFlags<[], [ClangOption, CC1Option]>>;
```

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


[clang] [RFC] Initial implementation of P2719 (PR #113510)

2024-12-06 Thread via cfe-commits


@@ -3482,15 +3486,40 @@ bool FunctionDecl::isDestroyingOperatorDelete() const {
   //   Within a class C, a single object deallocation function with signature
   // (T, std::destroying_delete_t, )
   //   is a destroying operator delete.
-  if (!isa(this) || getOverloadedOperator() != OO_Delete ||
-  getNumParams() < 2)
+  if (!isa(this) || getOverloadedOperator() != OO_Delete)
+return false;
+
+  unsigned NumParams = getNumParams();
+  unsigned DestroyingDeleteTagParam = 1;
+  bool IsTypeAware = false;
+  if (NumParams > 0)
+IsTypeAware = getParamDecl(0)->getType()->isTypeIdentitySpecialization();

cor3ntin wrote:

There is some duplication with Sema::isTypeAwareOperatorNewOrDelete, can we 
simplify?

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


[clang] [RFC] Initial implementation of P2719 (PR #113510)

2024-12-06 Thread via cfe-commits


@@ -3482,15 +3486,40 @@ bool FunctionDecl::isDestroyingOperatorDelete() const {
   //   Within a class C, a single object deallocation function with signature
   // (T, std::destroying_delete_t, )
   //   is a destroying operator delete.
-  if (!isa(this) || getOverloadedOperator() != OO_Delete ||
-  getNumParams() < 2)
+  if (!isa(this) || getOverloadedOperator() != OO_Delete)
+return false;
+

cor3ntin wrote:

We should probably assert this is not an explicit object member function 
(new/delete are treated as implicitly static)

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


[clang] [RFC] Initial implementation of P2719 (PR #113510)

2024-12-06 Thread via cfe-commits


@@ -2146,6 +2146,12 @@ class Sema final : public SemaBase {
isConstantEvaluatedOverride;
   }
 
+  TypeAwareAllocationMode allocationModeInCurrentContext() const {
+if (getLangOpts().TypeAwareAllocators && !isConstantEvaluatedContext())
+  return TypeAwareAllocationMode::Yes;
+return TypeAwareAllocationMode::No;
+  }

cor3ntin wrote:

Damn this is novel. Do we have any concerns with odr or such?
(the alternative is to just modify the evaluation of new expression to ignore 
type information)

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


[clang] [RFC] Initial implementation of P2719 (PR #113510)

2024-12-06 Thread via cfe-commits


@@ -2696,6 +2699,8 @@ class alignas(TypeAlignment) Type : public 
ExtQualsTypeCommonBase {
 return static_cast(TypeBits.Dependence);
   }
 
+  const TemplateDecl *getSpecializedTemplateDecl() const;

cor3ntin wrote:

Does that need to be in the header? (the implementation only work for type, 
it's not exactly generic)

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


[clang] [RFC] Initial implementation of P2719 (PR #113510)

2024-12-06 Thread via cfe-commits


@@ -9712,19 +9712,34 @@ def warn_operator_new_returns_null : Warning<
   "%select{| or 'noexcept'}1">, InGroup;
 
 def err_operator_new_dependent_param_type : Error<
-  "%0 cannot take a dependent type as first parameter; "
-  "use size_t (%1) instead">;
+  "%select{|type aware}1 %0 cannot take a dependent type as 
%select{first|second}1 parameter; "
+  "use size_t (%2) instead">;
 def err_operator_new_param_type : Error<
-  "%0 takes type size_t (%1) as first parameter">;
+  "%select{|type aware}1 %0 takes type size_t (%2) as %select{first|second}1 
parameter">;
 def err_operator_new_default_arg: Error<
   "parameter of %0 cannot have a default argument">;
 def err_operator_delete_dependent_param_type : Error<
-  "%0 cannot take a dependent type as first parameter; use %1 instead">;
+  "%select{|type aware}1 %0 cannot take a dependent type as 
%select{first|second}1 parameter; "
+  "use %2 instead">;
 def err_operator_delete_param_type : Error<
-  "first parameter of %0 must have type %1">;
+  "%select{first|second}1 parameter of%select{|type aware}1 %0 must have type 
%2">;
 def err_destroying_operator_delete_not_usual : Error<
   "destroying operator delete can have only an optional size and optional "
   "alignment parameter">;
+def err_type_aware_destroying_operator_delete : Error<
+  "type aware destroying delete is not permitted, enable with 
'-fexperimental-cxx-type-aware-destroying-delete'">;
+def err_unsupported_type_aware_allocator : Error<
+  "type aware allocation operators are disabled, enable with 
'-fexperimental-cxx-type-aware-allocators'">;

cor3ntin wrote:

Are these useful? The option is defaulted to true anyway right? And it's likely 
to land in 26 in a few weeks

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


[clang] [RFC] Initial implementation of P2719 (PR #113510)

2024-12-06 Thread via cfe-commits


@@ -3543,7 +3543,14 @@ def : Separate<["-"], "fnew-alignment">, 
Alias;
 def : Flag<["-"], "faligned-new">, Alias;
 def : Flag<["-"], "fno-aligned-new">, Alias;
 def faligned_new_EQ : Joined<["-"], "faligned-new=">;
-
+defm cxx_type_aware_allocators : 
BoolFOption<"experimental-cxx-type-aware-allocators",
+  LangOpts<"TypeAwareAllocators">, DefaultFalse,
+  PosFlag,
+  NegFlag, BothFlags<[], [ClangOption, CC1Option]>>;
+defm cxx_type_aware_destroying_delete : 
BoolFOption<"experimental-cxx-type-aware-destroying-delete",
+  LangOpts<"TypeAwareDestroyingDelete">, DefaultFalse,
+  PosFlag,

cor3ntin wrote:

```suggestion
  PosFlag,
```

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


[clang] [RFC] Initial implementation of P2719 (PR #113510)

2024-12-06 Thread via cfe-commits

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


[clang] [RFC] Initial implementation of P2719 (PR #113510)

2024-12-06 Thread via cfe-commits

https://github.com/cor3ntin commented:

A quick first pass

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


[clang] [RFC] Initial implementation of P2719 (PR #113510)

2024-12-06 Thread via cfe-commits


@@ -2709,14 +2831,63 @@ static bool resolveAllocationOverload(
   llvm_unreachable("Unreachable, bad result from BestViableFunction");
 }
 
-bool Sema::FindAllocationFunctions(SourceLocation StartLoc, SourceRange Range,
-   AllocationFunctionScope NewScope,
-   AllocationFunctionScope DeleteScope,
-   QualType AllocType, bool IsArray,
-   bool &PassAlignment, MultiExprArg PlaceArgs,
-   FunctionDecl *&OperatorNew,
-   FunctionDecl *&OperatorDelete,
-   bool Diagnose) {
+enum class DeallocLookupMode { Untyped, OptionallyTyped, RequireTyped };
+
+static void LookupGlobalDeallocationFunctions(Sema &S, SourceLocation Loc,
+  LookupResult &FoundDelete,
+  DeallocLookupMode Mode,
+  DeclarationName Name,
+  QualType DeallocType) {
+  S.LookupQualifiedName(FoundDelete, S.Context.getTranslationUnitDecl());
+  if (Mode == DeallocLookupMode::OptionallyTyped) {
+bool RemoveTypedDecl = Mode == DeallocLookupMode::Untyped;
+LookupResult::Filter Filter = FoundDelete.makeFilter();
+while (Filter.hasNext()) {
+  NamedDecl *Decl = Filter.next()->getUnderlyingDecl();
+  bool DeclIsTypeAware = S.isTypeAwareOperatorNewOrDelete(Decl);
+  if (DeclIsTypeAware && RemoveTypedDecl)
+Filter.erase();
+}
+Filter.done();
+  }
+}
+
+static bool resolveAllocationOverload(
+Sema &S, LookupResult &R, SourceRange Range, SmallVectorImpl &Args,
+ImplicitAllocationParameters &IAP, FunctionDecl *&Operator,
+OverloadCandidateSet *AlignedCandidates, Expr *AlignArg, bool Diagnose) {
+  Operator = nullptr;
+  if (isTypeAwareAllocation(IAP.PassTypeIdentity)) {
+assert(Args[0]->getType()->isTypeIdentitySpecialization());
+SmallVector UntypedParameters;
+UntypedParameters.reserve(Args.size() - 1);
+UntypedParameters.append(Args.begin() + 1, Args.end());
+AlignedAllocationMode InitialAlignmentMode = IAP.PassAlignment;
+if (resolveAllocationOverloadInterior(
+S, R, Range, ResolveMode::Typed, Args, IAP.PassAlignment, Operator,
+AlignedCandidates, AlignArg, Diagnose))
+  return true;
+if (Operator)
+  return false;
+// There's no type aware allocator
+IAP.PassTypeIdentity = TypeAwareAllocationMode::No;
+// Restore alignment requirements
+IAP.PassAlignment = InitialAlignmentMode;
+// Finally prepare the type free parameter list
+Args = UntypedParameters;

cor3ntin wrote:

Can you explain why we need to remove the type?
(also, I think `Args.erase(Args.begin())` would work as well as saving a copy, 
right?)

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


[clang] [RFC] Initial implementation of P2719 (PR #113510)

2024-12-06 Thread via cfe-commits


@@ -3357,6 +3357,10 @@ bool FunctionDecl::isReservedGlobalPlacementOperator() 
const {
 return false;
 
   const auto *proto = getType()->castAs();
+  if (proto->getNumParams() < 2)
+return false;
+  if (proto->getParamType(0)->isTypeIdentitySpecialization())
+return false;

cor3ntin wrote:

We probably don't need to compare getNumParams() twice (line below)

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


[clang] [RFC] Initial implementation of P2719 (PR #113510)

2024-12-06 Thread via cfe-commits


@@ -1847,15 +1913,42 @@ static bool hasNewExtendedAlignment(Sema &S, QualType 
AllocType) {
  S.getASTContext().getTargetInfo().getNewAlign();
 }
 
+static bool CheckDeleteOperator(Sema &S, SourceLocation StartLoc,
+SourceRange Range, bool Diagnose,
+CXXRecordDecl *NamingClass, DeclAccessPair 
Decl,
+FunctionDecl *Operator) {
+  if (S.isTypeAwareOperatorNewOrDelete(Operator)) {
+QualType SelectedTypeIdentityParameter =
+Operator->getParamDecl(0)->getType();
+if (S.RequireCompleteType(StartLoc, SelectedTypeIdentityParameter,
+  diag::err_incomplete_type))
+  return true;
+  }
+
+  // FIXME: DiagnoseUseOfDecl?
+  if (Operator->isDeleted()) {
+if (Diagnose) {
+  StringLiteral *Msg = Operator->getDeletedMessage();
+  S.Diag(StartLoc, diag::err_deleted_function_use)
+  << (Msg != nullptr) << (Msg ? Msg->getString() : StringRef());
+  S.NoteDeletedFunction(Operator);
+}
+return true;
+  }

cor3ntin wrote:

Unrelated to your patch but we should really move that diagnostic in its own 
function - that code is duplicated

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


[clang] [RFC] Initial implementation of P2719 (PR #113510)

2024-12-06 Thread via cfe-commits


@@ -16106,6 +16127,128 @@ bool Sema::CompleteConstructorCall(CXXConstructorDecl 
*Constructor,
   return Invalid;
 }
 
+bool Sema::isTypeIdentitySpecialization(QualType Type) const {
+  const ClassTemplateDecl *TypeIdentity = getStdTypeIdentity();
+  if (!TypeIdentity)
+return false;
+  const TemplateDecl *SpecializedDecl = Type->getSpecializedTemplateDecl();
+  return TypeIdentity == SpecializedDecl;
+}
+
+bool Sema::isTypeAwareOperatorNewOrDelete(const FunctionDecl *FnDecl) const {
+  // Type aware operators
+  if (FnDecl->getNumParams() < 2)
+return false;
+  const ParmVarDecl *ParamDecl = FnDecl->getParamDecl(0);
+  return isTypeIdentitySpecialization(ParamDecl->getType());
+}
+
+bool Sema::isTypeAwareOperatorNewOrDelete(
+const FunctionTemplateDecl *FTD) const {
+  return isTypeAwareOperatorNewOrDelete(FTD->getTemplatedDecl());
+}
+
+bool Sema::isTypeAwareOperatorNewOrDelete(const NamedDecl *ND) const {
+  if (auto *FTD = dyn_cast(ND))
+return isTypeAwareOperatorNewOrDelete(FTD->getTemplatedDecl());
+  if (auto *FnDecl = dyn_cast(ND))
+return isTypeAwareOperatorNewOrDelete(FnDecl);
+  return false;
+}
+
+std::optional
+Sema::instantiateTypeAwareUsualDelete(FunctionTemplateDecl *FnTemplateDecl,
+  QualType DeallocType) {
+  if (!isTypeAwareAllocation(allocationModeInCurrentContext()))

cor3ntin wrote:

Do we need some additional caching for that ? (or is the caching dome in Deduce 
Template Arguments  enough?)

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


[clang] [RFC] Initial implementation of P2719 (PR #113510)

2024-12-06 Thread via cfe-commits


@@ -16106,6 +16127,128 @@ bool Sema::CompleteConstructorCall(CXXConstructorDecl 
*Constructor,
   return Invalid;
 }
 
+bool Sema::isTypeIdentitySpecialization(QualType Type) const {
+  const ClassTemplateDecl *TypeIdentity = getStdTypeIdentity();
+  if (!TypeIdentity)
+return false;
+  const TemplateDecl *SpecializedDecl = Type->getSpecializedTemplateDecl();
+  return TypeIdentity == SpecializedDecl;
+}
+
+bool Sema::isTypeAwareOperatorNewOrDelete(const FunctionDecl *FnDecl) const {
+  // Type aware operators
+  if (FnDecl->getNumParams() < 2)
+return false;
+  const ParmVarDecl *ParamDecl = FnDecl->getParamDecl(0);
+  return isTypeIdentitySpecialization(ParamDecl->getType());
+}
+
+bool Sema::isTypeAwareOperatorNewOrDelete(
+const FunctionTemplateDecl *FTD) const {
+  return isTypeAwareOperatorNewOrDelete(FTD->getTemplatedDecl());
+}
+
+bool Sema::isTypeAwareOperatorNewOrDelete(const NamedDecl *ND) const {
+  if (auto *FTD = dyn_cast(ND))
+return isTypeAwareOperatorNewOrDelete(FTD->getTemplatedDecl());
+  if (auto *FnDecl = dyn_cast(ND))
+return isTypeAwareOperatorNewOrDelete(FnDecl);
+  return false;
+}
+
+std::optional

cor3ntin wrote:

Just returning FunctionDecl * would be enough

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


[clang] [RFC] Initial implementation of P2719 (PR #113510)

2024-12-06 Thread via cfe-commits


@@ -1520,7 +1533,7 @@ static void EnterNewDeleteCleanup(CodeGenFunction &CGF,
   llvm::Value *AllocSize,
   CharUnits AllocAlign,
   const CallArgList &NewArgs) {
-  unsigned NumNonPlacementArgs = E->passAlignment() ? 2 : 1;
+  unsigned NumNonPlacementArgs = E->getNumImplicitArgs();

cor3ntin wrote:

Nah ( they are implicitly static), but adding assertions would not hurt

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


[clang] [llvm] [AArch64] Add initial support for FUJITSU-MONAKA (PR #118432)

2024-12-06 Thread David Green via cfe-commits

davemgreen wrote:

We never know who does and doesn't have commit access. Let us know if you are 
happy and want us to hit submit. Thanks.

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


[clang] [AST] Include clang/Basic/DiagnosticComment.h instead of clang/AST/CommentDiagnostic.h (PR #117499)

2024-12-06 Thread Kazu Hirata via cfe-commits

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


[clang] [AST] Include clang/Basic/DiagnosticComment.h instead of clang/AST/CommentDiagnostic.h (PR #117499)

2024-12-06 Thread Kazu Hirata via cfe-commits

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


[clang] [AST] Include clang/Basic/DiagnosticComment.h instead of clang/AST/CommentDiagnostic.h (PR #117499)

2024-12-06 Thread Kazu Hirata via cfe-commits

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


[clang] efe4bfa - [AST] Include clang/Basic/DiagnosticComment.h instead of clang/AST/CommentDiagnostic.h (#117499)

2024-12-06 Thread via cfe-commits

Author: Kazu Hirata
Date: 2024-12-06T00:32:43-08:00
New Revision: efe4bfa623d40f8221f449c3dd38392101a53599

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

LOG: [AST] Include clang/Basic/DiagnosticComment.h instead of 
clang/AST/CommentDiagnostic.h (#117499)

Since:

  commit d076608d58d1ec55016eb747a995511e3a3f72aa
  Author: Richard Trieu 
  Date:   Sat Dec 8 05:05:03 2018 +

clang/AST/CommentDiagnostic.h has been forwarding to
clang/Basic/DiagnosticComment.h.  This patch includes
clang/Basic/DiagnosticComment.h instead of
clang/AST/CommentDiagnostic.h.

Added: 


Modified: 
clang/lib/AST/CommentLexer.cpp
clang/lib/AST/CommentParser.cpp
clang/lib/AST/CommentSema.cpp
clang/lib/Sema/SemaDecl.cpp

Removed: 




diff  --git a/clang/lib/AST/CommentLexer.cpp b/clang/lib/AST/CommentLexer.cpp
index f0250fc9fd55eb..ec9a5b480aa295 100644
--- a/clang/lib/AST/CommentLexer.cpp
+++ b/clang/lib/AST/CommentLexer.cpp
@@ -8,8 +8,8 @@
 
 #include "clang/AST/CommentLexer.h"
 #include "clang/AST/CommentCommandTraits.h"
-#include "clang/AST/CommentDiagnostic.h"
 #include "clang/Basic/CharInfo.h"
+#include "clang/Basic/DiagnosticComment.h"
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/Support/ConvertUTF.h"

diff  --git a/clang/lib/AST/CommentParser.cpp b/clang/lib/AST/CommentParser.cpp
index 61508fe886efc0..12ed8e3f1b79a0 100644
--- a/clang/lib/AST/CommentParser.cpp
+++ b/clang/lib/AST/CommentParser.cpp
@@ -8,9 +8,9 @@
 
 #include "clang/AST/CommentParser.h"
 #include "clang/AST/CommentCommandTraits.h"
-#include "clang/AST/CommentDiagnostic.h"
 #include "clang/AST/CommentSema.h"
 #include "clang/Basic/CharInfo.h"
+#include "clang/Basic/DiagnosticComment.h"
 #include "clang/Basic/SourceManager.h"
 #include "llvm/Support/ErrorHandling.h"
 

diff  --git a/clang/lib/AST/CommentSema.cpp b/clang/lib/AST/CommentSema.cpp
index 69eda00643a8fa..bd2206bb8a3bc7 100644
--- a/clang/lib/AST/CommentSema.cpp
+++ b/clang/lib/AST/CommentSema.cpp
@@ -9,9 +9,9 @@
 #include "clang/AST/CommentSema.h"
 #include "clang/AST/Attr.h"
 #include "clang/AST/CommentCommandTraits.h"
-#include "clang/AST/CommentDiagnostic.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclTemplate.h"
+#include "clang/Basic/DiagnosticComment.h"
 #include "clang/Basic/LLVM.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Lex/Preprocessor.h"

diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index c4bb73b2924bc9..55e891e3acf20d 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -16,7 +16,6 @@
 #include "clang/AST/ASTLambda.h"
 #include "clang/AST/CXXInheritance.h"
 #include "clang/AST/CharUnits.h"
-#include "clang/AST/CommentDiagnostic.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/DeclCXX.h"
 #include "clang/AST/DeclObjC.h"
@@ -30,6 +29,7 @@
 #include "clang/AST/StmtCXX.h"
 #include "clang/AST/Type.h"
 #include "clang/Basic/Builtins.h"
+#include "clang/Basic/DiagnosticComment.h"
 #include "clang/Basic/PartialDiagnostic.h"
 #include "clang/Basic/SourceManager.h"
 #include "clang/Basic/TargetInfo.h"



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


[clang] [AST] Include clang/Basic/DiagnosticComment.h instead of clang/AST/CommentDiagnostic.h (PR #117499)

2024-12-06 Thread Kazu Hirata via cfe-commits

kazutakahirata wrote:

I'm going to go conservative for now by including 
`clang/Basic/DiagnosticComment.h` instead of `clang/AST/CommentDiagnostic.h`.  
We can revisit this and remove `clang/AST/CommentDiagnostic.h` and update 
`module.modulemap`.

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


[clang] [clang][bytecode] Check primitive bit casts for indeterminate bits (PR #118954)

2024-12-06 Thread Timm Baeder via cfe-commits

https://github.com/tbaederr created 
https://github.com/llvm/llvm-project/pull/118954

Record bits ranges of initialized bits and check them in allInitialized().

>From 89cc19bfa6590d49864797ebeda300396110161b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Fri, 6 Dec 2024 12:04:47 +0100
Subject: [PATCH] [clang][bytecode] Check primitive bit casts for indeterminate
 bits

Record bits ranges of initialized bits and check them in
allInitialized().
---
 clang/lib/AST/ByteCode/BitcastBuffer.cpp  | 51 +++
 clang/lib/AST/ByteCode/BitcastBuffer.h| 31 ---
 clang/lib/AST/ByteCode/Compiler.cpp   |  7 +--
 .../lib/AST/ByteCode/InterpBuiltinBitCast.cpp |  1 +
 .../ByteCode/builtin-bit-cast-bitfields.cpp   | 23 -
 clang/test/AST/ByteCode/builtin-bit-cast.cpp  | 19 +++
 6 files changed, 104 insertions(+), 28 deletions(-)

diff --git a/clang/lib/AST/ByteCode/BitcastBuffer.cpp 
b/clang/lib/AST/ByteCode/BitcastBuffer.cpp
index 0cc97b0b6bf190..7f29c7c2db0147 100644
--- a/clang/lib/AST/ByteCode/BitcastBuffer.cpp
+++ b/clang/lib/AST/ByteCode/BitcastBuffer.cpp
@@ -6,6 +6,7 @@
 //
 
//===--===//
 #include "BitcastBuffer.h"
+#include "llvm/ADT/STLExtras.h"
 
 using namespace clang;
 using namespace clang::interp;
@@ -60,6 +61,56 @@ BitcastBuffer::copyBits(Bits BitOffset, Bits BitWidth, Bits 
FullBitWidth,
   return Out;
 }
 
+bool BitcastBuffer::allInitialized() const {
+  Bits Sum;
+  for (BitRange BR : InitializedBits)
+Sum += BR.size();
+
+  return Sum == FinalBitSize;
+}
+
+void BitcastBuffer::markInitialized(Bits Offset, Bits Length) {
+  if (Length.isZero())
+return;
+
+  BitRange Element(Offset, Offset + Length - Bits(1));
+  if (InitializedBits.empty()) {
+InitializedBits.push_back(Element);
+return;
+  }
+
+  assert(InitializedBits.size() >= 1);
+  // Common case of just appending.
+  Bits End = InitializedBits.back().End;
+  if (End <= Offset) {
+// Merge this range with the last one.
+// In the best-case scenario, this means we only ever have
+// one single bit range covering all bits.
+if (End == (Offset - Bits(1))) {
+  InitializedBits.back().End = Element.End;
+  return;
+}
+
+// Otherwise, we can simply append.
+InitializedBits.push_back(Element);
+  } else {
+// Insert sorted.
+auto It = std::upper_bound(InitializedBits.begin(), InitializedBits.end(),
+   Element);
+InitializedBits.insert(It, Element);
+  }
+
+#ifndef NDEBUG
+  // Ensure ranges are sorted and non-overlapping.
+  assert(llvm::is_sorted(InitializedBits));
+  for (unsigned I = 1; I != InitializedBits.size(); ++I) {
+[[maybe_unused]] auto Prev = InitializedBits[I - 1];
+[[maybe_unused]] auto Cur = InitializedBits[I];
+assert(Prev.End.N < Cur.Start.N);
+  }
+#endif
+}
+
 #if 0
   template
   static std::string hex(T t) {
diff --git a/clang/lib/AST/ByteCode/BitcastBuffer.h 
b/clang/lib/AST/ByteCode/BitcastBuffer.h
index c7b170ceb168fa..00fbdc9b85421d 100644
--- a/clang/lib/AST/ByteCode/BitcastBuffer.h
+++ b/clang/lib/AST/ByteCode/BitcastBuffer.h
@@ -8,6 +8,7 @@
 #ifndef LLVM_CLANG_AST_INTERP_BITCAST_BUFFER_H
 #define LLVM_CLANG_AST_INTERP_BITCAST_BUFFER_H
 
+#include "llvm/ADT/SmallVector.h"
 #include 
 #include 
 #include 
@@ -30,14 +31,20 @@ struct Bits {
   bool nonZero() const { return N != 0; }
   bool isZero() const { return N == 0; }
 
-  Bits operator-(Bits Other) { return Bits(N - Other.N); }
-  Bits operator+(Bits Other) { return Bits(N + Other.N); }
+  Bits operator-(Bits Other) const { return Bits(N - Other.N); }
+  Bits operator+(Bits Other) const { return Bits(N + Other.N); }
   Bits operator+=(size_t O) {
 N += O;
 return *this;
   }
+  Bits operator+=(Bits O) {
+N += O.N;
+return *this;
+  }
 
-  bool operator>=(Bits Other) { return N >= Other.N; }
+  bool operator>=(Bits Other) const { return N >= Other.N; }
+  bool operator<=(Bits Other) const { return N <= Other.N; }
+  bool operator==(Bits Other) const { return N == Other.N; }
 };
 
 /// A quantity in bytes.
@@ -48,11 +55,21 @@ struct Bytes {
   Bits toBits() const { return Bits(N * 8); }
 };
 
+struct BitRange {
+  Bits Start;
+  Bits End;
+
+  BitRange(Bits Start, Bits End) : Start(Start), End(End) {}
+  Bits size() const { return End - Start + Bits(1); }
+  bool operator<(BitRange Other) const { return Start.N < Other.Start.N; }
+};
+
 /// Track what bits have been initialized to known values and which ones
 /// have indeterminate value.
 struct BitcastBuffer {
   Bits FinalBitSize;
   std::unique_ptr Data;
+  llvm::SmallVector InitializedBits;
 
   BitcastBuffer(Bits FinalBitSize) : FinalBitSize(FinalBitSize) {
 assert(FinalBitSize.isFullByte());
@@ -64,10 +81,10 @@ struct BitcastBuffer {
   Bits size() const { return FinalBitSize; }
 
   /// Returns \c true if all bits in the buffer have been initialized.
-  bool 

[clang] [clang][bytecode] Check primitive bit casts for indeterminate bits (PR #118954)

2024-12-06 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)


Changes

Record bits ranges of initialized bits and check them in allInitialized().

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


6 Files Affected:

- (modified) clang/lib/AST/ByteCode/BitcastBuffer.cpp (+51) 
- (modified) clang/lib/AST/ByteCode/BitcastBuffer.h (+24-7) 
- (modified) clang/lib/AST/ByteCode/Compiler.cpp (+1-6) 
- (modified) clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp (+1) 
- (modified) clang/test/AST/ByteCode/builtin-bit-cast-bitfields.cpp (+21-2) 
- (modified) clang/test/AST/ByteCode/builtin-bit-cast.cpp (+6-13) 


``diff
diff --git a/clang/lib/AST/ByteCode/BitcastBuffer.cpp 
b/clang/lib/AST/ByteCode/BitcastBuffer.cpp
index 0cc97b0b6bf190..7f29c7c2db0147 100644
--- a/clang/lib/AST/ByteCode/BitcastBuffer.cpp
+++ b/clang/lib/AST/ByteCode/BitcastBuffer.cpp
@@ -6,6 +6,7 @@
 //
 
//===--===//
 #include "BitcastBuffer.h"
+#include "llvm/ADT/STLExtras.h"
 
 using namespace clang;
 using namespace clang::interp;
@@ -60,6 +61,56 @@ BitcastBuffer::copyBits(Bits BitOffset, Bits BitWidth, Bits 
FullBitWidth,
   return Out;
 }
 
+bool BitcastBuffer::allInitialized() const {
+  Bits Sum;
+  for (BitRange BR : InitializedBits)
+Sum += BR.size();
+
+  return Sum == FinalBitSize;
+}
+
+void BitcastBuffer::markInitialized(Bits Offset, Bits Length) {
+  if (Length.isZero())
+return;
+
+  BitRange Element(Offset, Offset + Length - Bits(1));
+  if (InitializedBits.empty()) {
+InitializedBits.push_back(Element);
+return;
+  }
+
+  assert(InitializedBits.size() >= 1);
+  // Common case of just appending.
+  Bits End = InitializedBits.back().End;
+  if (End <= Offset) {
+// Merge this range with the last one.
+// In the best-case scenario, this means we only ever have
+// one single bit range covering all bits.
+if (End == (Offset - Bits(1))) {
+  InitializedBits.back().End = Element.End;
+  return;
+}
+
+// Otherwise, we can simply append.
+InitializedBits.push_back(Element);
+  } else {
+// Insert sorted.
+auto It = std::upper_bound(InitializedBits.begin(), InitializedBits.end(),
+   Element);
+InitializedBits.insert(It, Element);
+  }
+
+#ifndef NDEBUG
+  // Ensure ranges are sorted and non-overlapping.
+  assert(llvm::is_sorted(InitializedBits));
+  for (unsigned I = 1; I != InitializedBits.size(); ++I) {
+[[maybe_unused]] auto Prev = InitializedBits[I - 1];
+[[maybe_unused]] auto Cur = InitializedBits[I];
+assert(Prev.End.N < Cur.Start.N);
+  }
+#endif
+}
+
 #if 0
   template
   static std::string hex(T t) {
diff --git a/clang/lib/AST/ByteCode/BitcastBuffer.h 
b/clang/lib/AST/ByteCode/BitcastBuffer.h
index c7b170ceb168fa..00fbdc9b85421d 100644
--- a/clang/lib/AST/ByteCode/BitcastBuffer.h
+++ b/clang/lib/AST/ByteCode/BitcastBuffer.h
@@ -8,6 +8,7 @@
 #ifndef LLVM_CLANG_AST_INTERP_BITCAST_BUFFER_H
 #define LLVM_CLANG_AST_INTERP_BITCAST_BUFFER_H
 
+#include "llvm/ADT/SmallVector.h"
 #include 
 #include 
 #include 
@@ -30,14 +31,20 @@ struct Bits {
   bool nonZero() const { return N != 0; }
   bool isZero() const { return N == 0; }
 
-  Bits operator-(Bits Other) { return Bits(N - Other.N); }
-  Bits operator+(Bits Other) { return Bits(N + Other.N); }
+  Bits operator-(Bits Other) const { return Bits(N - Other.N); }
+  Bits operator+(Bits Other) const { return Bits(N + Other.N); }
   Bits operator+=(size_t O) {
 N += O;
 return *this;
   }
+  Bits operator+=(Bits O) {
+N += O.N;
+return *this;
+  }
 
-  bool operator>=(Bits Other) { return N >= Other.N; }
+  bool operator>=(Bits Other) const { return N >= Other.N; }
+  bool operator<=(Bits Other) const { return N <= Other.N; }
+  bool operator==(Bits Other) const { return N == Other.N; }
 };
 
 /// A quantity in bytes.
@@ -48,11 +55,21 @@ struct Bytes {
   Bits toBits() const { return Bits(N * 8); }
 };
 
+struct BitRange {
+  Bits Start;
+  Bits End;
+
+  BitRange(Bits Start, Bits End) : Start(Start), End(End) {}
+  Bits size() const { return End - Start + Bits(1); }
+  bool operator<(BitRange Other) const { return Start.N < Other.Start.N; }
+};
+
 /// Track what bits have been initialized to known values and which ones
 /// have indeterminate value.
 struct BitcastBuffer {
   Bits FinalBitSize;
   std::unique_ptr Data;
+  llvm::SmallVector InitializedBits;
 
   BitcastBuffer(Bits FinalBitSize) : FinalBitSize(FinalBitSize) {
 assert(FinalBitSize.isFullByte());
@@ -64,10 +81,10 @@ struct BitcastBuffer {
   Bits size() const { return FinalBitSize; }
 
   /// Returns \c true if all bits in the buffer have been initialized.
-  bool allInitialized() const {
-// FIXME: Implement.
-return true;
-  }
+  bool allInitialized() const;
+  /// Marks the bits in the given range as initialized.
+  /// FIXME: Can we do this automatically in pushData()?
+  void markI

[clang] [-Wunsafe-buffer-usage] Suppress warning for multi-dimensional constant arrays (PR #118249)

2024-12-06 Thread Malavika Samak via cfe-commits


@@ -8,6 +8,5 @@
 // main function
 int main(int argc, char *argv[]) { // expected-warning{{'argv' is an unsafe 
pointer used for buffer access}}
   char tmp;
-  tmp = argv[5][5];// expected-note{{used in buffer access 
here}} \
- expected-warning{{unsafe buffer access}}

malavikasamak wrote:

Resolved in the latest diff.

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


[clang] [clang-tools-extra] [llvm] [clang] WIP: Improved Context Declaration tracking (PR #107942)

2024-12-06 Thread Younan Zhang via cfe-commits


@@ -247,18 +242,23 @@ getGenericLambdaTemplateParameterList(LambdaScopeInfo 
*LSI, Sema &SemaRef) {
 
 CXXRecordDecl *
 Sema::createLambdaClosureType(SourceRange IntroducerRange, TypeSourceInfo 
*Info,
-  unsigned LambdaDependencyKind,
-  LambdaCaptureDefault CaptureDefault) {
+  LambdaCaptureDefault CaptureDefault,
+  unsigned TemplateDepth) {
   DeclContext *DC = CurContext;
-  while (!(DC->isFunctionOrMethod() || DC->isRecord() || DC->isFileContext()))
-DC = DC->getParent();
 
   bool IsGenericLambda =
   Info && getGenericLambdaTemplateParameterList(getCurLambda(), *this);
   // Start constructing the lambda class.
+  ContextDeclOrLazy ContextDecl = currentEvaluationContext().ContextDecl;
   CXXRecordDecl *Class = CXXRecordDecl::CreateLambda(
-  Context, DC, Info, IntroducerRange.getBegin(), LambdaDependencyKind,
-  IsGenericLambda, CaptureDefault);
+  Context, DC, Info, IntroducerRange.getBegin(), IsGenericLambda,
+  CaptureDefault,
+  ContextDecl.hasValue() ? *ContextDecl
+ : ContextDeclOrSentinel(TemplateDepth),
+  currentEvaluationContext().ContextArgs);
+  if (!ContextDecl.hasValue())

zyn0217 wrote:

I find it more likely for one to conflate the semantics of `hasValue()` with 
those of `operator bool` whereas the latter actually indicates whether this is 
in a null state (i.e. neither the pointer nor the depth is assigned).

For clarity, could we rename it to something more descriptive, like 
`hasDeclPointer()`?

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


[clang] Reapply "[clang] Fix name lookup for dependent bases" (PR #118003)

2024-12-06 Thread Vladislav Belov via cfe-commits

vbe-sc wrote:

> I'm hitting an assertion on some Firefox code after this landed:
> 
> ```
> clang++: /tmp/llvm/llvm/include/llvm/Support/Casting.h:566: decltype(auto) 
> llvm::cast(const From &) [To = cl
> ang::RecordType, From = clang::QualType]: Assertion `isa(Val) && 
> "cast() argument of incompatible ty
> pe!"' failed.
> (...)
> 1.  
> /tmp/g/obj-x86_64-pc-linux-gnu/dist/include/mozilla/MozPromise.h:1348:5 
>  pc-linux-gnu/dist/include/mozilla/MozPromise.h:1348:38>: current parser token 
> '&&'
> 2.  
> /tmp/g/obj-x86_64-pc-linux-gnu/dist/include/mozilla/MozPromise.h:48:1: 
> parsing namespace 'mozilla'
> 3.  
> /tmp/g/obj-x86_64-pc-linux-gnu/dist/include/mozilla/MozPromise.h:1339:1: 
> parsing struct/union/class body 'mozilla::MozPromise::Private'
> 4.  
> /tmp/g/obj-x86_64-pc-linux-gnu/dist/include/mozilla/MozPromise.h:1347:75: 
> parsing function body 'mozilla::MozPromise::Private::Resolve'
> 5.  
> /tmp/g/obj-x86_64-pc-linux-gnu/dist/include/mozilla/MozPromise.h:1347:75: in 
> compound statement ('{}')
> 6.  
> /tmp/g/obj-x86_64-pc-linux-gnu/dist/include/mozilla/MozPromise.h:1348:5 
> :
>  in compound statement ('{}')
>   #0 0x7f5c64d183f9 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) 
> /tmp/llvm/llvm/lib/Support/Unix/Signals.inc:723:11
>   #1 0x7f5c64d188ab PrintStackTraceSignalHandler(void*) 
> /tmp/llvm/llvm/lib/Support/Unix/Signals.inc:798:1 
>   #2 0x7f5c64d16b6f llvm::sys::RunSignalHandlers() 
> /tmp/llvm/llvm/lib/Support/Signals.cpp:105:5
>   #3 0x7f5c64d17d69 llvm::sys::CleanupOnSignal(unsigned long) 
> /tmp/llvm/llvm/lib/Support/Unix/Signals.inc:368:1
>   #4 0x7f5c64bca842 (anonymous 
> namespace)::CrashRecoveryContextImpl::HandleCrash(int, unsigned long) 
> /tmp/llvm/llvm/lib/Support/CrashRecoveryContext.cpp:0:7
>   #5 0x7f5c64bcaba6 CrashRecoverySignalHandler(int) 
> /tmp/llvm/llvm/lib/Support/CrashRecoveryContext.cpp:391:1
>   #6 0x7f5c62e5b050 (/lib/x86_64-linux-gnu/libc.so.6+0x3c050)
>   #7 0x7f5c62ea9ebc __pthread_kill_implementation 
> ./nptl/pthread_kill.c:44:76
>   #8 0x7f5c62e5afb2 raise ./signal/../sysdeps/posix/raise.c:27:6
>   #9 0x7f5c62e45472 abort ./stdlib/abort.c:81:7
>  #10 0x7f5c62e45395 _nl_load_domain ./intl/loadmsgcat.c:1177:9
>  #11 0x7f5c62e53eb2 (/lib/x86_64-linux-gnu/libc.so.6+0x34eb2)
>  #12 0x7f5c72cbf024 decltype(auto) llvm::cast clang::QualType>(clang::QualType const&) 
> /tmp/llvm/llvm/include/llvm/Support/Casting.h:567:43
>  #13 0x7f5c72cbaaa9 clang::RecordType const* 
> clang::Type::castAs() const 
> /tmp/llvm/obj/tools/clang/include/clang/AST/TypeNodes.inc:96:1
>  #14 0x7f5c730e72ca 
> clang::CXXRecordDecl::FindBaseClass(clang::CXXBaseSpecifier const*, 
> clang::CXXBasePath&, clang::CXXRecordDecl const*) 
> /tmp/llvm/clang/lib/AST/CXXInheritance.cpp:371:32
>  #15 0x7f5c730e868c 
> clang::CXXRecordDecl::isDerivedFrom(clang::CXXRecordDecl const*, 
> clang::CXXBasePaths&) const::$_0::operator()(clang::CXXBaseSpecifier const*, 
> clang::CXXBasePath&) const /tmp/llvm/clang/lib/AST/CXXInheritance.cpp:83:16
>  #16 0x7f5c730e8625 bool llvm::function_ref const*, 
> clang::CXXBasePath&)>::callback_fn  const*, clang::CXXBasePaths&) const::$_0>(long, clang::CXXBaseSpecifier 
> const*, clang::CXXBasePath&) 
> /tmp/llvm/llvm/include/llvm/ADT/STLFunctionalExtras.h:46:5
>  #17 0x7f5c730e9cd9 llvm::function_ref const*, clang::CXXBasePath&)>::operator()(clang::CXXBaseSpecifier const*, 
> clang::CXXBasePath&) const 
> /tmp/llvm/llvm/include/llvm/ADT/STLFunctionalExtras.h:69:5
>  #18 0x7f5c730e6e5e 
> clang::CXXBasePaths::lookupInBases(clang::ASTContext&, clang::CXXRecordDecl 
> const*, llvm::function_ref clang::CXXBasePath&)>, bool) /tmp/llvm/clang/lib/AST/CXXInheritance.cpp:242:9
>  #19 0x7f5c730e6586 
> clang::CXXRecordDecl::lookupInBases(llvm::function_ref (clang::CXXBaseSpecifier const*, clang::CXXBasePath&)>, clang::CXXBasePaths&, 
> bool) const /tmp/llvm/clang/lib/AST/CXXInheritance.cpp:314:7
>  #20 0x7f5c730e650e 
> clang::CXXRecordDecl::isDerivedFrom(clang::CXXRecordDecl const*, 
> clang::CXXBasePaths&) const /tmp/llvm/clang/lib/AST/CXXInheritance.cpp:80:3
>  #21 0x7f5c73dd0869 FindBestPath(clang::Sema&, (anonymous 
> namespace)::EffectiveContext const&, (anonymous namespace)::AccessTarget&, 
> clang::AccessSpecifier, clang::CXXBasePaths&) 
> /tmp/llvm/clang/lib/Sema/SemaAccess.cpp:956:8
>  #22 0x7f5c73dcf305 IsAccessible(clang::Sema&, (anonymous 
> namespace)::EffectiveContext const&, (anonymous namespace)::AccessTarget&) 
> /tmp/llvm/clang/lib/Sema/SemaAccess.cpp:1402:16
>  #23 0x7f5c73dccdee CheckEffectiveAccess(clang::Sema&, (anonymous 
> namespace)::EffectiveContext const&, clang::SourceLocation, (anonymous 
> namespace)::AccessTarget&) /tmp/llvm/clang/lib/Sema/SemaAccess.cpp:1437:3
>  #24 0x7f5c73dcd379 CheckAccess(clang::Sema&, clang::SourceLocation, 
> (anonymous namespace)::AccessTarget&) 
> /tmp/llvm/clang/lib/Sema/SemaAccess

[clang] [Clang][Xtensa] Add Xtensa target. (PR #118008)

2024-12-06 Thread Andrzej Warzyński via cfe-commits

banach-space wrote:

I'm not active in this area, so removed myself from the list of reviewers.

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


[clang] [clang-tools-extra] [llvm] [clang] WIP: Improved Context Declaration tracking (PR #107942)

2024-12-06 Thread Younan Zhang via cfe-commits

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


[clang] [clang-tools-extra] [llvm] [clang] WIP: Improved Context Declaration tracking (PR #107942)

2024-12-06 Thread Younan Zhang via cfe-commits

https://github.com/zyn0217 commented:

I took another pass through the code, and it looks good overall.

Given the scale of this patch, input from others would be valuable. It would be 
nice if you could move the patch out of draft status to get more visibility :)

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


[clang] [clang-tools-extra] [llvm] [clang] WIP: Improved Context Declaration tracking (PR #107942)

2024-12-06 Thread Younan Zhang via cfe-commits


@@ -17658,8 +17662,49 @@ HandleImmediateInvocations(Sema &SemaRef,
   }
 }
 
+static void setContextDecl(Sema &S, Decl *Base, Decl *ContextDecl) {
+  switch (Base->getKind()) {
+  case Decl::CXXRecord: {
+auto *RD = cast(Base);
+RD->setLambdaContextDecl(ContextDecl);
+S.handleLambdaNumbering(RD, RD->getLambdaCallOperator(),
+/*NumberingOverride=*/std::nullopt,
+/*InSignature=*/true);
+  } break;
+  case Decl::RequiresExprBody:
+cast(Base)->setContextDecl(ContextDecl);
+break;
+  default:
+llvm_unreachable("Undexpected Decl Kind");
+  }
+}
+
+void Sema::UpdateCurrentContextDecl(Decl *ContextDecl) {
+  assert(ContextDecl);
+  ExpressionEvaluationContextRecord &Rec = ExprEvalContexts.back();
+  assert(!Rec.ContextDecl.hasValue());
+  assert(Rec.LazyContextDeclPos <= PendingLazyContextDecls.size());
+  Rec.ContextDecl = ContextDecl;
+  while (PendingLazyContextDecls.size() > Rec.LazyContextDeclPos)
+setContextDecl(*this, PendingLazyContextDecls.pop_back_val(), ContextDecl);
+}
+
 void Sema::PopExpressionEvaluationContext() {
   ExpressionEvaluationContextRecord& Rec = ExprEvalContexts.back();
+  assert(Rec.LazyContextDeclPos <= PendingLazyContextDecls.size());
+  if (!Rec.HasReusedDeclContext) {
+if (Rec.ContextDecl.hasValue()) {
+  assert(Rec.LazyContextDeclPos == PendingLazyContextDecls.size());
+} else {
+  while (PendingLazyContextDecls.size() > Rec.LazyContextDeclPos) {
+Decl *D = PendingLazyContextDecls.pop_back_val();
+setContextDecl(*this, D, nullptr);

zyn0217 wrote:

Is there anything special for the third argument being null? Both 
`setLambdaContextDecl()` and `handleLambdaNumbering()` would bail out for such 
cases, right?

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


[clang] [clang-tools-extra] [llvm] [clang] WIP: Improved Context Declaration tracking (PR #107942)

2024-12-06 Thread Younan Zhang via cfe-commits


@@ -7946,6 +7980,8 @@ class Sema final : public SemaBase {
   /// A stack of expression evaluation contexts.
   SmallVector ExprEvalContexts;
 
+  SmallVector PendingLazyContextDecls;

zyn0217 wrote:

So from a quick reading, PendingLazyContextDecls is used for lambdas created as 
part of other declarations, such as being part of a default argument for a 
template parameter. Their context declarations are updated only at the end of 
the evaluation context or right after the outer declaration is created.

I think we'd better document its intent, wdyt?

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


[clang] [clang-tools-extra] [llvm] [clang] WIP: Improved Context Declaration tracking (PR #107942)

2024-12-06 Thread Younan Zhang via cfe-commits


@@ -8494,10 +8495,21 @@ DeclResult Sema::ActOnClassTemplateSpecialization(
   return Specialization;
 }
 
-Decl *Sema::ActOnTemplateDeclarator(Scope *S,
-  MultiTemplateParamsArg TemplateParameterLists,
-Declarator &D) {
+Decl *Sema::ActOnTemplateDeclarator(
+Scope *S, MultiTemplateParamsArg TemplateParameterLists, Declarator &D) {
   Decl *NewDecl = HandleDeclarator(S, D, TemplateParameterLists);
+  if (auto *D = NewDecl) {
+if (auto *TD = dyn_cast(D))
+  D = TD->getTemplatedDecl();
+else if (auto *TD = dyn_cast(D))
+  D = TD->getTemplatedDecl();
+else if (!(isa(D) || isa(D) ||
+   isa(D))) {
+  D->dumpColor();
+  llvm_unreachable("FU");

zyn0217 wrote:

FU?

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


[clang] [ExprConst] Handle floating- and char literals in FastEvaluateAsRValue (PR #118294)

2024-12-06 Thread via cfe-commits

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

LGTM

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


[clang] f893b47 - [ARM] Fix instruction selection for MVE vsbciq intrinsic (#118284)

2024-12-06 Thread via cfe-commits

Author: Oliver Stannard
Date: 2024-12-06T08:46:56Z
New Revision: f893b475004fdea48288f329124817325e659792

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

LOG: [ARM] Fix instruction selection for MVE vsbciq intrinsic (#118284)

There were two bugs in the implementation of the MVE vsbciq (subtract
with carry across vector, with initial carry value) intrinsics:
* The VSBCI instruction behaves as if the carry-in is always set, but we
were selecting it when the carry-in is clear.
* The vsbciq intrinsics should generate IR with the carry-in set, but
they were leaving it clear.

These two bugs almost cancelled each other out, but resulted in
incorrect code when the vsbcq intrinsics (with a carry-in) were used,
and the carry-in was a compile time constant.

Added: 


Modified: 
clang/include/clang/Basic/arm_mve.td
clang/test/CodeGen/arm-mve-intrinsics/vadc.c
llvm/lib/Target/ARM/ARMISelDAGToDAG.cpp
llvm/test/CodeGen/Thumb2/mve-intrinsics/vadc.ll
llvm/test/CodeGen/Thumb2/mve-vadc-vsbc-spill.ll

Removed: 




diff  --git a/clang/include/clang/Basic/arm_mve.td 
b/clang/include/clang/Basic/arm_mve.td
index 93abbc47c54dd5..6dd8c52ddfd772 100644
--- a/clang/include/clang/Basic/arm_mve.td
+++ b/clang/include/clang/Basic/arm_mve.td
@@ -1270,13 +1270,13 @@ defm sqrshr: ScalarSaturatingShiftReg;
 def lsll: LongScalarShift $lo, $hi, $sh)>;
 def asrl: LongScalarShift $lo, $hi, $sh)>;
 
-multiclass vadcsbc {
+multiclass vadcsbc {
   def q: Intrinsic:$carry),
   (seq (IRInt $a, $b, (shl (load $carry), 29)):$pair,
(store (and 1, (lshr (xval $pair, 1), 29)), $carry),
(xval $pair, 0))>;
   def iq: Intrinsic:$carry),
-  (seq (IRInt $a, $b, 0):$pair,
+  (seq (IRInt $a, $b, initial_carry_in):$pair,
(store (and 1, (lshr (xval $pair, 1), 29)), $carry),
(xval $pair, 0))>;
   def q_m: Intrinsic:$carry, Predicate:$pred),
   (seq (IRInt $inactive, $a, $b,
-   0, $pred):$pair,
+   initial_carry_in, $pred):$pair,
(store (and 1, (lshr (xval $pair, 1), 29)), $carry),
(xval $pair, 0))>;
 }
 let params = T.Int32 in {
-  defm vadc: vadcsbc;
-  defm vsbc: vadcsbc;
+  defm vadc: vadcsbc<(u32 0)>;
+  defm vsbc: vadcsbc<(shl 1, 29)>;
 }
 
 let params = T.Int in {

diff  --git a/clang/test/CodeGen/arm-mve-intrinsics/vadc.c 
b/clang/test/CodeGen/arm-mve-intrinsics/vadc.c
index 21087b83300c88..29e067d65c6c89 100644
--- a/clang/test/CodeGen/arm-mve-intrinsics/vadc.c
+++ b/clang/test/CodeGen/arm-mve-intrinsics/vadc.c
@@ -92,7 +92,7 @@ int32x4_t test_vadcq_m_s32(int32x4_t inactive, int32x4_t a, 
int32x4_t b, unsigne
 
 // CHECK-LABEL: @test_vsbciq_s32(
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = call { <4 x i32>, i32 } 
@llvm.arm.mve.vsbc.v4i32(<4 x i32> [[A:%.*]], <4 x i32> [[B:%.*]], i32 0)
+// CHECK-NEXT:[[TMP0:%.*]] = call { <4 x i32>, i32 } 
@llvm.arm.mve.vsbc.v4i32(<4 x i32> [[A:%.*]], <4 x i32> [[B:%.*]], i32 
536870912)
 // CHECK-NEXT:[[TMP1:%.*]] = extractvalue { <4 x i32>, i32 } [[TMP0]], 1
 // CHECK-NEXT:[[TMP2:%.*]] = lshr i32 [[TMP1]], 29
 // CHECK-NEXT:[[TMP3:%.*]] = and i32 1, [[TMP2]]
@@ -110,7 +110,7 @@ int32x4_t test_vsbciq_s32(int32x4_t a, int32x4_t b, 
unsigned *carry_out) {
 
 // CHECK-LABEL: @test_vsbciq_u32(
 // CHECK-NEXT:  entry:
-// CHECK-NEXT:[[TMP0:%.*]] = call { <4 x i32>, i32 } 
@llvm.arm.mve.vsbc.v4i32(<4 x i32> [[A:%.*]], <4 x i32> [[B:%.*]], i32 0)
+// CHECK-NEXT:[[TMP0:%.*]] = call { <4 x i32>, i32 } 
@llvm.arm.mve.vsbc.v4i32(<4 x i32> [[A:%.*]], <4 x i32> [[B:%.*]], i32 
536870912)
 // CHECK-NEXT:[[TMP1:%.*]] = extractvalue { <4 x i32>, i32 } [[TMP0]], 1
 // CHECK-NEXT:[[TMP2:%.*]] = lshr i32 [[TMP1]], 29
 // CHECK-NEXT:[[TMP3:%.*]] = and i32 1, [[TMP2]]
@@ -170,7 +170,7 @@ uint32x4_t test_vsbcq_u32(uint32x4_t a, uint32x4_t b, 
unsigned *carry) {
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:[[TMP0:%.*]] = zext i16 [[P:%.*]] to i32
 // CHECK-NEXT:[[TMP1:%.*]] = call <4 x i1> @llvm.arm.mve.pred.i2v.v4i1(i32 
[[TMP0]])
-// CHECK-NEXT:[[TMP2:%.*]] = call { <4 x i32>, i32 } 
@llvm.arm.mve.vsbc.predicated.v4i32.v4i1(<4 x i32> [[INACTIVE:%.*]], <4 x i32> 
[[A:%.*]], <4 x i32> [[B:%.*]], i32 0, <4 x i1> [[TMP1]])
+// CHECK-NEXT:[[TMP2:%.*]] = call { <4 x i32>, i32 } 
@llvm.arm.mve.vsbc.predicated.v4i32.v4i1(<4 x i32> [[INACTIVE:%.*]], <4 x i32> 
[[A:%.*]], <4 x i32> [[B:%.*]], i32 536870912, <4 x i1> [[TMP1]])
 // CHECK-NEXT:[[TMP3:%.*]] = extractvalue { <4 x i32>, i32 } [[TMP2]], 1
 // CHECK-NEXT:[[TMP4:%.*]] = lshr i32 [[TMP3]], 29
 // CHECK-NEXT:[[TMP5:%.*]] = and i32 1, [[TMP4]]
@@ -190,7 +190,7 @@ int32x4_t test_vsbciq_m_s32(int32x4_t inactive, int32x4_t 
a, int32x4_t b, unsign
 // CHECK-NEXT:  entr

[clang] [llvm] [ARM] Fix instruction selection for MVE vsbciq intrinsic (PR #118284)

2024-12-06 Thread Oliver Stannard via cfe-commits

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


[clang] 2d8e8dd - [ARM] Add Cortex-A510 CPU for AArch32 (#118811)

2024-12-06 Thread via cfe-commits

Author: Oliver Stannard
Date: 2024-12-06T08:51:22Z
New Revision: 2d8e8dd2b83da113dd94f01c67fb8b3e3ce38cc9

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

LOG: [ARM] Add Cortex-A510 CPU for AArch32 (#118811)

This core was originally AArch64-only, but the r1p0 revision added
optional support for AArch32 at EL0.

TRM: https://developer.arm.com/documentation/101604/0103

Added: 


Modified: 
clang/test/Driver/arm-cortex-cpus-2.c
clang/test/Misc/target-invalid-cpu-note/arm.c
llvm/include/llvm/TargetParser/ARMTargetParser.def
llvm/lib/Target/ARM/ARMProcessors.td
llvm/lib/Target/ARM/ARMSubtarget.cpp
llvm/test/CodeGen/ARM/build-attributes.ll
llvm/unittests/TargetParser/TargetParserTest.cpp

Removed: 




diff  --git a/clang/test/Driver/arm-cortex-cpus-2.c 
b/clang/test/Driver/arm-cortex-cpus-2.c
index 2f17a081404361..0ee8e05f378efe 100644
--- a/clang/test/Driver/arm-cortex-cpus-2.c
+++ b/clang/test/Driver/arm-cortex-cpus-2.c
@@ -544,6 +544,17 @@
 // CHECK-CORTEX-A78AE-MFPU: "-target-feature" "+sha2"
 // CHECK-CORTEX-A78AE-MFPU: "-target-feature" "+aes"
 
+// RUN: %clang -target armv8a-arm-none-eabi -mcpu=cortex-a510 -### -c %s 2>&1 
| FileCheck -check-prefix=CHECK-CORTEX-A510 %s
+// RUN: %clang -target armv8a-arm-none-eabi -mcpu=cortex-a510 
-mfpu=crypto-neon-fp-armv8 -### -c %s 2>&1 | FileCheck 
-check-prefix=CHECK-CORTEX-A510-MFPU %s
+// CHECK-CORTEX-A510: "-cc1"{{.*}} "-triple" "armv9a-{{.*}} "-target-cpu" 
"cortex-a510"
+// CHECK-CORTEX-A510-NOT: "-target-feature" "{{[+-]}}sm4"
+// CHECK-CORTEX-A510-NOT: "-target-feature" "{{[+-]}}sha3"
+// CHECK-CORTEX-A510: "-target-feature" "-aes"
+// CHECK-CORTEX-A510-SAME: {{$}}
+// CHECK-CORTEX-A510-MFPU: "-cc1"{{.*}} "-target-feature" "+fp-armv8"
+// CHECK-CORTEX-A510-MFPU: "-target-feature" "+sha2"
+// CHECK-CORTEX-A510-MFPU: "-target-feature" "+aes"
+
 // RUN: %clang -target armv8a-arm-none-eabi -mcpu=cortex-a710 -### -c %s 2>&1 
| FileCheck -check-prefix=CHECK-CORTEX-A710 %s
 // RUN: %clang -target armv8a-arm-none-eabi -mcpu=cortex-a710 
-mfpu=crypto-neon-fp-armv8 -### -c %s 2>&1 | FileCheck 
-check-prefix=CHECK-CORTEX-A710-MFPU %s
 // CHECK-CORTEX-A710: "-cc1"{{.*}} "-triple" "armv9a-{{.*}} "-target-cpu" 
"cortex-a710"

diff  --git a/clang/test/Misc/target-invalid-cpu-note/arm.c 
b/clang/test/Misc/target-invalid-cpu-note/arm.c
index 17280a9edd221d..12acdabbb77565 100644
--- a/clang/test/Misc/target-invalid-cpu-note/arm.c
+++ b/clang/test/Misc/target-invalid-cpu-note/arm.c
@@ -84,6 +84,7 @@
 // CHECK-SAME: {{^}}, cortex-a78
 // CHECK-SAME: {{^}}, cortex-a78ae
 // CHECK-SAME: {{^}}, cortex-a78c
+// CHECK-SAME: {{^}}, cortex-a510
 // CHECK-SAME: {{^}}, cortex-a710
 // CHECK-SAME: {{^}}, cortex-x1
 // CHECK-SAME: {{^}}, cortex-x1c

diff  --git a/llvm/include/llvm/TargetParser/ARMTargetParser.def 
b/llvm/include/llvm/TargetParser/ARMTargetParser.def
index c5cd1b1bc63765..6b96c3e83c8c4f 100644
--- a/llvm/include/llvm/TargetParser/ARMTargetParser.def
+++ b/llvm/include/llvm/TargetParser/ARMTargetParser.def
@@ -374,6 +374,9 @@ ARM_CPU_NAME("cortex-a78ae", ARMV8_2A, 
FK_CRYPTO_NEON_FP_ARMV8, false,
  (ARM::AEK_RAS | ARM::AEK_DOTPROD))
 ARM_CPU_NAME("cortex-a78c", ARMV8_2A, FK_CRYPTO_NEON_FP_ARMV8, false,
  ARM::AEK_FP16 | ARM::AEK_DOTPROD)
+ARM_CPU_NAME("cortex-a510", ARMV9A, FK_NEON_FP_ARMV8, false,
+ (ARM::AEK_DOTPROD | ARM::AEK_FP16FML | ARM::AEK_BF16 |
+  ARM::AEK_SB | ARM::AEK_I8MM))
 ARM_CPU_NAME("cortex-a710", ARMV9A, FK_NEON_FP_ARMV8, false,
  (ARM::AEK_DOTPROD | ARM::AEK_FP16FML | ARM::AEK_BF16 |
   ARM::AEK_SB | ARM::AEK_I8MM))

diff  --git a/llvm/lib/Target/ARM/ARMProcessors.td 
b/llvm/lib/Target/ARM/ARMProcessors.td
index 22e7e6893c1a82..213b104bcfdb2f 100644
--- a/llvm/lib/Target/ARM/ARMProcessors.td
+++ b/llvm/lib/Target/ARM/ARMProcessors.td
@@ -45,6 +45,8 @@ def ProcA78AE   : SubtargetFeature<"cortex-a78ae", 
"ARMProcFamily", "CortexA78AE
"Cortex-A78AE ARM processors", []>;
 def ProcA78C: SubtargetFeature<"a78c", "ARMProcFamily", "CortexA78C",
"Cortex-A78C ARM processors", []>;
+def ProcA510: SubtargetFeature<"cortex-a510", "ARMProcFamily",
+   "CortexA510", "Cortex-A510 ARM processors", 
[]>;
 def ProcA710: SubtargetFeature<"cortex-a710", "ARMProcFamily",
"CortexA710", "Cortex-A710 ARM processors", 
[]>;
 def ProcX1  : SubtargetFeature<"cortex-x1", "ARMProcFamily", "CortexX1",
@@ -518,6 +520,14 @@ def : ProcNoItin<"cortex-a78c", 
[ARMv82a, ProcA78C,
  FeatureDotProd,
   

[clang] [llvm] [ARM] Add Cortex-A510 CPU for AArch32 (PR #118811)

2024-12-06 Thread Oliver Stannard via cfe-commits

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


[clang] b569ec6 - [SCCP] Infer nuw for gep nusw with non-negative offsets (#118819)

2024-12-06 Thread via cfe-commits

Author: Nikita Popov
Date: 2024-12-06T09:52:32+01:00
New Revision: b569ec6de6a0c57d6c4b675df7d7e3e28a9f4904

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

LOG: [SCCP] Infer nuw for gep nusw with non-negative offsets (#118819)

If the GEP is nusw/inbounds and has all-non-negative offsets infer nuw
as well.

This doesn't have measurable compile-time impact.

Proof: https://alive2.llvm.org/ce/z/ihztLy

Added: 


Modified: 
clang/test/CodeGen/attr-counted-by.c
llvm/lib/Transforms/Utils/SCCPSolver.cpp
llvm/test/Analysis/LazyCallGraph/blockaddress.ll
llvm/test/Transforms/SCCP/conditions-iter-order.ll
llvm/test/Transforms/SCCP/gep-nuw.ll
llvm/test/Transforms/SCCP/ipsccp-ssa-copy-nested-conds.ll
llvm/test/Transforms/SCCP/pr45185-range-predinfo.ll
llvm/test/Transforms/SCCP/widening.ll

Removed: 




diff  --git a/clang/test/CodeGen/attr-counted-by.c 
b/clang/test/CodeGen/attr-counted-by.c
index c11502c9240d78..6b3cad5708835b 100644
--- a/clang/test/CodeGen/attr-counted-by.c
+++ b/clang/test/CodeGen/attr-counted-by.c
@@ -70,7 +70,7 @@ struct anon_struct {
 // SANITIZE-WITH-ATTR-NEXT:unreachable, !nosanitize [[META2]]
 // SANITIZE-WITH-ATTR:   cont3:
 // SANITIZE-WITH-ATTR-NEXT:[[ARRAY:%.*]] = getelementptr inbounds nuw i8, 
ptr [[P]], i64 12
-// SANITIZE-WITH-ATTR-NEXT:[[ARRAYIDX:%.*]] = getelementptr inbounds [0 x 
i32], ptr [[ARRAY]], i64 0, i64 [[IDXPROM]]
+// SANITIZE-WITH-ATTR-NEXT:[[ARRAYIDX:%.*]] = getelementptr inbounds nuw 
[0 x i32], ptr [[ARRAY]], i64 0, i64 [[IDXPROM]]
 // SANITIZE-WITH-ATTR-NEXT:store i32 [[VAL]], ptr [[ARRAYIDX]], align 4, 
!tbaa [[TBAA4:![0-9]+]]
 // SANITIZE-WITH-ATTR-NEXT:ret void
 //
@@ -282,46 +282,43 @@ size_t test3_bdos(struct annotated *p) {
 // SANITIZE-WITH-ATTR-NEXT:[[TMP4:%.*]] = add i32 [[TMP3]], 244
 // SANITIZE-WITH-ATTR-NEXT:[[TMP5:%.*]] = and i32 [[TMP4]], 252
 // SANITIZE-WITH-ATTR-NEXT:[[CONV1:%.*]] = select i1 [[TMP2]], i32 
[[TMP5]], i32 0
-// SANITIZE-WITH-ATTR-NEXT:[[ARRAYIDX:%.*]] = getelementptr inbounds [0 x 
i32], ptr [[ARRAY]], i64 0, i64 [[IDXPROM]]
+// SANITIZE-WITH-ATTR-NEXT:[[ARRAYIDX:%.*]] = getelementptr inbounds nuw 
[0 x i32], ptr [[ARRAY]], i64 0, i64 [[IDXPROM]]
 // SANITIZE-WITH-ATTR-NEXT:store i32 [[CONV1]], ptr [[ARRAYIDX]], align 4, 
!tbaa [[TBAA4]]
-// SANITIZE-WITH-ATTR-NEXT:[[DOT_COUNTED_BY_LOAD6:%.*]] = load i32, ptr 
[[DOT_COUNTED_BY_GEP]], align 4
 // SANITIZE-WITH-ATTR-NEXT:[[ADD:%.*]] = add nsw i32 [[INDEX]], 1
 // SANITIZE-WITH-ATTR-NEXT:[[IDXPROM12:%.*]] = sext i32 [[ADD]] to i64
-// SANITIZE-WITH-ATTR-NEXT:[[TMP6:%.*]] = zext i32 
[[DOT_COUNTED_BY_LOAD6]] to i64, !nosanitize [[META2]]
-// SANITIZE-WITH-ATTR-NEXT:[[TMP7:%.*]] = icmp ult i64 [[IDXPROM12]], 
[[TMP6]], !nosanitize [[META2]]
-// SANITIZE-WITH-ATTR-NEXT:br i1 [[TMP7]], label [[CONT19:%.*]], label 
[[HANDLER_OUT_OF_BOUNDS15:%.*]], !prof [[PROF3]], !nosanitize [[META2]]
+// SANITIZE-WITH-ATTR-NEXT:[[TMP6:%.*]] = icmp ult i64 [[IDXPROM12]], 
[[TMP0]], !nosanitize [[META2]]
+// SANITIZE-WITH-ATTR-NEXT:br i1 [[TMP6]], label [[CONT19:%.*]], label 
[[HANDLER_OUT_OF_BOUNDS15:%.*]], !prof [[PROF3]], !nosanitize [[META2]]
 // SANITIZE-WITH-ATTR:   handler.out_of_bounds15:
 // SANITIZE-WITH-ATTR-NEXT:tail call void 
@__ubsan_handle_out_of_bounds_abort(ptr nonnull @[[GLOB6:[0-9]+]], i64 
[[IDXPROM12]]) #[[ATTR8]], !nosanitize [[META2]]
 // SANITIZE-WITH-ATTR-NEXT:unreachable, !nosanitize [[META2]]
 // SANITIZE-WITH-ATTR:   cont19:
-// SANITIZE-WITH-ATTR-NEXT:[[TMP8:%.*]] = icmp sgt i32 
[[DOT_COUNTED_BY_LOAD6]], 3
-// SANITIZE-WITH-ATTR-NEXT:[[TMP9:%.*]] = shl i32 
[[DOT_COUNTED_BY_LOAD6]], 2
-// SANITIZE-WITH-ATTR-NEXT:[[TMP10:%.*]] = add i32 [[TMP9]], 240
-// SANITIZE-WITH-ATTR-NEXT:[[TMP11:%.*]] = and i32 [[TMP10]], 252
-// SANITIZE-WITH-ATTR-NEXT:[[CONV8:%.*]] = select i1 [[TMP8]], i32 
[[TMP11]], i32 0
-// SANITIZE-WITH-ATTR-NEXT:[[ARRAYIDX17:%.*]] = getelementptr inbounds [0 
x i32], ptr [[ARRAY]], i64 0, i64 [[IDXPROM12]]
+// SANITIZE-WITH-ATTR-NEXT:[[TMP7:%.*]] = icmp sgt i32 
[[DOT_COUNTED_BY_LOAD]], 3
+// SANITIZE-WITH-ATTR-NEXT:[[TMP8:%.*]] = add i32 [[TMP3]], 240
+// SANITIZE-WITH-ATTR-NEXT:[[TMP9:%.*]] = and i32 [[TMP8]], 252
+// SANITIZE-WITH-ATTR-NEXT:[[CONV8:%.*]] = select i1 [[TMP7]], i32 
[[TMP9]], i32 0
+// SANITIZE-WITH-ATTR-NEXT:[[ARRAYIDX17:%.*]] = getelementptr inbounds nuw 
[0 x i32], ptr [[ARRAY]], i64 0, i64 [[IDXPROM12]]
 // SANITIZE-WITH-ATTR-NEXT:store i32 [[CONV8]], ptr [[ARRAYIDX17]], align 
4, !tbaa [[TBAA4]]
 // SANITIZE-WITH-ATTR-NEXT:[[DOT_COUNTED_BY_LOAD21:%.*]] = load i32, ptr 
[[DOT_COUNTED_BY_GEP]], align 4
 // SANITIZE-WITH-ATTR-NEXT:   

[clang] [llvm] [SCCP] Infer nuw for gep nusw with non-negative offsets (PR #118819)

2024-12-06 Thread Nikita Popov via cfe-commits

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


[clang] [clang-tools-extra] [llvm] [clang] WIP: Improved Context Declaration tracking (PR #107942)

2024-12-06 Thread Younan Zhang via cfe-commits


@@ -17658,8 +17662,49 @@ HandleImmediateInvocations(Sema &SemaRef,
   }
 }
 
+static void setContextDecl(Sema &S, Decl *Base, Decl *ContextDecl) {
+  switch (Base->getKind()) {
+  case Decl::CXXRecord: {
+auto *RD = cast(Base);
+RD->setLambdaContextDecl(ContextDecl);
+S.handleLambdaNumbering(RD, RD->getLambdaCallOperator(),
+/*NumberingOverride=*/std::nullopt,
+/*InSignature=*/true);
+  } break;
+  case Decl::RequiresExprBody:
+cast(Base)->setContextDecl(ContextDecl);
+break;
+  default:
+llvm_unreachable("Undexpected Decl Kind");
+  }
+}
+
+void Sema::UpdateCurrentContextDecl(Decl *ContextDecl) {
+  assert(ContextDecl);
+  ExpressionEvaluationContextRecord &Rec = ExprEvalContexts.back();
+  assert(!Rec.ContextDecl.hasValue());
+  assert(Rec.LazyContextDeclPos <= PendingLazyContextDecls.size());
+  Rec.ContextDecl = ContextDecl;
+  while (PendingLazyContextDecls.size() > Rec.LazyContextDeclPos)
+setContextDecl(*this, PendingLazyContextDecls.pop_back_val(), ContextDecl);
+}
+
 void Sema::PopExpressionEvaluationContext() {
   ExpressionEvaluationContextRecord& Rec = ExprEvalContexts.back();
+  assert(Rec.LazyContextDeclPos <= PendingLazyContextDecls.size());
+  if (!Rec.HasReusedDeclContext) {
+if (Rec.ContextDecl.hasValue()) {
+  assert(Rec.LazyContextDeclPos == PendingLazyContextDecls.size());

zyn0217 wrote:

Is this an assumption for that

1. if the lambda (or something else we want to later add context decl for) is 
aware of its parent context decl at the point of its creation, then there 
should not be any pointer in `PendingLazyContextDecls` tracking the lambda.

2. the subsequent on-stack evaluation contexts should have handled 
PendingLazyContextDecls properly

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


[clang] [CodeGen] Migrate away from PointerUnion::{is, get} (NFC) (PR #118600)

2024-12-06 Thread Nikita Popov via cfe-commits

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


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


[clang] 91d6e10 - [CodeGen] Migrate away from PointerUnion::{is, get} (NFC) (#118600)

2024-12-06 Thread via cfe-commits

Author: Kazu Hirata
Date: 2024-12-06T01:45:56-08:00
New Revision: 91d6e10cca4ea8d50927aba024f33c9076785d3a

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

LOG: [CodeGen] Migrate away from PointerUnion::{is,get} (NFC) (#118600)

Note that PointerUnion::{is,get} have been soft deprecated in
PointerUnion.h:

  // FIXME: Replace the uses of is(), get() and dyn_cast() with
  //isa, cast and the llvm::dyn_cast

I'm not touching PointerUnion::dyn_cast for now because it's a bit
complicated; we could blindly migrate it to dyn_cast_if_present, but
we should probably use dyn_cast when the operand is known to be
non-null.

Added: 


Modified: 
clang/lib/CodeGen/CGCall.cpp
clang/lib/CodeGen/CGOpenMPRuntime.cpp
clang/lib/CodeGen/ConstantInitBuilder.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp
index 7c8d962fa5a920..3cefc9da66ddb8 100644
--- a/clang/lib/CodeGen/CGCall.cpp
+++ b/clang/lib/CodeGen/CGCall.cpp
@@ -4529,7 +4529,7 @@ void CodeGenFunction::EmitCallArgs(
   ArgTypes.assign(MD->param_type_begin() + ParamsToSkip,
   MD->param_type_end());
 } else {
-  const auto *FPT = Prototype.P.get();
+  const auto *FPT = cast(Prototype.P);
   IsVariadic = FPT->isVariadic();
   ExplicitCC = FPT->getExtInfo().getCC();
   ArgTypes.assign(FPT->param_type_begin() + ParamsToSkip,

diff  --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index 6a5860242035b2..2deb91f27e37b9 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -7770,7 +7770,7 @@ class MappableExprsHandler {
   if (const auto *Base = Data.dyn_cast())
 getPlainLayout(Base, Layout, /*AsBase=*/true);
   else
-Layout.push_back(Data.get());
+Layout.push_back(cast(Data));
 }
   }
 
@@ -8333,9 +8333,9 @@ class MappableExprsHandler {
   MapCombinedInfoTy &CombinedInfo, llvm::OpenMPIRBuilder &OMPBuilder,
   const llvm::DenseSet> &SkipVarSet =
   llvm::DenseSet>()) const {
-assert(CurDir.is() &&
+assert(isa(CurDir) &&
"Expect a executable directive");
-const auto *CurExecDir = CurDir.get();
+const auto *CurExecDir = cast(CurDir);
 generateAllInfoForClauses(CurExecDir->clauses(), CombinedInfo, OMPBuilder,
   SkipVarSet);
   }
@@ -8345,9 +8345,9 @@ class MappableExprsHandler {
   /// in \a CombinedInfo).
   void generateAllInfoForMapper(MapCombinedInfoTy &CombinedInfo,
 llvm::OpenMPIRBuilder &OMPBuilder) const {
-assert(CurDir.is() &&
+assert(isa(CurDir) &&
"Expect a declare mapper directive");
-const auto *CurMapperDir = CurDir.get();
+const auto *CurMapperDir = cast(CurDir);
 generateAllInfoForClauses(CurMapperDir->clauses(), CombinedInfo,
   OMPBuilder);
   }
@@ -8519,9 +8519,9 @@ class MappableExprsHandler {
 DeclComponentLists.emplace_back(MCL, OMPC_MAP_tofrom, Unknown,
 /*IsImpicit = */ true, nullptr,
 nullptr);
-assert(CurDir.is() &&
+assert(isa(CurDir) &&
"Expect a executable directive");
-const auto *CurExecDir = CurDir.get();
+const auto *CurExecDir = cast(CurDir);
 bool HasMapBasePtr = false;
 bool HasMapArraySec = false;
 for (const auto *C : CurExecDir->getClausesOfKind()) {

diff  --git a/clang/lib/CodeGen/ConstantInitBuilder.cpp 
b/clang/lib/CodeGen/ConstantInitBuilder.cpp
index 549d5dd66b1230..ddbf3ef743370b 100644
--- a/clang/lib/CodeGen/ConstantInitBuilder.cpp
+++ b/clang/lib/CodeGen/ConstantInitBuilder.cpp
@@ -20,10 +20,10 @@ using namespace CodeGen;
 
 llvm::Type *ConstantInitFuture::getType() const {
   assert(Data && "dereferencing null future");
-  if (Data.is()) {
-return Data.get()->getType();
+  if (const auto *C = dyn_cast(Data)) {
+return C->getType();
   } else {
-return Data.get()->Buffer[0]->getType();
+return cast(Data)->Buffer[0]->getType();
   }
 }
 
@@ -37,10 +37,10 @@ void ConstantInitFuture::abandon() {
 
 void ConstantInitFuture::installInGlobal(llvm::GlobalVariable *GV) {
   assert(Data && "installing null future");
-  if (Data.is()) {
-GV->setInitializer(Data.get());
+  if (auto *C = dyn_cast(Data)) {
+GV->setInitializer(C);
   } else {
-auto &builder = *Data.get();
+auto &builder = *cast(Data);
 assert(builder.Buffer.size() == 1);
 builder.setGlobalInitializer(GV, builder.Buffer[0]);
 builder.Buffer.clear();



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

[clang] [CodeGen] Migrate away from PointerUnion::{is, get} (NFC) (PR #118600)

2024-12-06 Thread Kazu Hirata via cfe-commits

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


[clang] [llvm] [SystemZ] Add support for __builtin_setjmp and __builtin_longjmp (PR #116642)

2024-12-06 Thread Ulrich Weigand via cfe-commits


@@ -374,10 +374,11 @@ overall functioning of this intrinsic is compatible with 
the GCC
 to interoperate.
 
 The single parameter is a pointer to a five word buffer in which the calling
-context is saved. The front end places the frame pointer in the first word, and
-the target implementation of this intrinsic should place the destination 
address
-for a `llvm.eh.sjlj.longjmp`_ in the second word. The following three words are
-available for use in a target-specific manner.
+context is saved. The format and contents of the buffer are target-specific.
+On certain targets, the front end places the frame pointer in the first word
+and the stack pointer in the third word, while the target implementation of
+this intrinsic fills in the remaining words.  On other targets, saving the
+calling context to the buffer is left completely to the target implementation. 

uweigand wrote:

Given @efriedma-quic 's comment, we should specify the targets here.   Maybe 
change the first sentence to "On certain targets (ARM, PowerPC, VE, X86), ..." 
and the second sentence to "On other targets (SystemZ), ..."

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


[clang] [llvm] [SystemZ] Add support for __builtin_setjmp and __builtin_longjmp (PR #116642)

2024-12-06 Thread Ulrich Weigand via cfe-commits

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


[clang] [llvm] [AArch64] Add intrinsics for SME FP8 FDOT LANE instructions (PR #118492)

2024-12-06 Thread Jonathan Thackray via cfe-commits

https://github.com/jthackray updated 
https://github.com/llvm/llvm-project/pull/118492

>From 609cf3fbdb28c155f4b8c787c1e2cb791c8a292f Mon Sep 17 00:00:00 2001
From: Jonathan Thackray 
Date: Fri, 29 Nov 2024 11:27:03 +
Subject: [PATCH 1/6] [AArch64] Add intrinsics for SME FP8 FDOT LANE
 instructions

Co-authored-by: Momchil Velikov 
Co-authored-by: Marian Lukac 
Co-authored-by: Caroline Concatto 
---
 clang/include/clang/Basic/arm_sme.td  |   5 +
 clang/include/clang/Basic/arm_sve_sme_incl.td |   1 +
 clang/lib/CodeGen/CGBuiltin.cpp   |   6 +
 .../sme2-intrinsics/acle_sme2_fp8_fdot.c  |  57 +++
 llvm/include/llvm/IR/IntrinsicsAArch64.td |  22 +++
 .../lib/Target/AArch64/AArch64SMEInstrInfo.td |   4 +-
 llvm/lib/Target/AArch64/SMEInstrFormats.td| 141 ++
 .../AArch64/sme2-intrinsics-fp8-fdot.ll   |  32 
 8 files changed, 266 insertions(+), 2 deletions(-)
 create mode 100644 
clang/test/CodeGen/AArch64/sme2-intrinsics/acle_sme2_fp8_fdot.c
 create mode 100644 llvm/test/CodeGen/AArch64/sme2-intrinsics-fp8-fdot.ll

diff --git a/clang/include/clang/Basic/arm_sme.td 
b/clang/include/clang/Basic/arm_sme.td
index 0f689e82bdb742..87ed68c03430cd 100644
--- a/clang/include/clang/Basic/arm_sme.td
+++ b/clang/include/clang/Basic/arm_sme.td
@@ -740,6 +740,11 @@ let SMETargetGuard = "sme2" in {
   def SVLUTI4_LANE_ZT_X2 : Inst<"svluti4_lane_zt_{d}_x2", "2.di[i", 
"cUcsUsiUibhf", MergeNone, "aarch64_sme_luti4_lane_zt_x2", [IsStreaming, 
IsInZT0], [ImmCheck<0, ImmCheck0_0>, ImmCheck<2, ImmCheck0_3>]>;
 }
 
+// FDOT
+let SMETargetGuard = "sme2,sme-f8f16" in {
+  def SVDOT_LANE_FP8_ZA16_VG1x2 : Inst<"svdot_lane_za16[_mf8]_vg1x2_fpm", 
"vm2di>", "m", MergeNone, "aarch64_sme_fp8_fdot_lane_za16_vg1x2", [IsStreaming, 
IsInOutZA, SetsFPMR, IsOverloadNone], [ImmCheck<3, ImmCheck0_7>]>;
+  def SVDOT_LANE_FP8_ZA16_VG1x4 : Inst<"svdot_lane_za16[_mf8]_vg1x4_fpm", 
"vm4di>", "m", MergeNone, "aarch64_sme_fp8_fdot_lane_za16_vg1x4", [IsStreaming, 
IsInOutZA, SetsFPMR, IsOverloadNone], [ImmCheck<3, ImmCheck0_7>]>;
+}
 

 // SME2p1 - FMOPA, FMOPS (non-widening)
 let SMETargetGuard = "sme-b16b16" in {
diff --git a/clang/include/clang/Basic/arm_sve_sme_incl.td 
b/clang/include/clang/Basic/arm_sve_sme_incl.td
index de10be7bdce0db..e7cc40db7dca6c 100644
--- a/clang/include/clang/Basic/arm_sve_sme_incl.td
+++ b/clang/include/clang/Basic/arm_sve_sme_incl.td
@@ -52,6 +52,7 @@ include "arm_immcheck_incl.td"
 // h: half-float
 // d: double
 // b: bfloat
+// m: mfloat8
 
 // Typespec modifiers
 // --
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 7588f8427cdd38..7de5e8bcd439d7 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -10183,6 +10183,8 @@ CodeGenFunction::getSVEType(const SVETypeFlags 
&TypeFlags) {
   case SVETypeFlags::EltTyInt64:
 return llvm::ScalableVectorType::get(Builder.getInt64Ty(), 2);
 
+ case SVETypeFlags::EltTyMFloat8:
+return llvm::ScalableVectorType::get(Builder.getInt8Ty(), 16);
   case SVETypeFlags::EltTyFloat16:
 return llvm::ScalableVectorType::get(Builder.getHalfTy(), 8);
   case SVETypeFlags::EltTyBFloat16:
@@ -11234,6 +11236,10 @@ Value 
*CodeGenFunction::EmitAArch64SMEBuiltinExpr(unsigned BuiltinID,
BuiltinID == SME::BI__builtin_sme_svstr_za)
 return EmitSMELdrStr(TypeFlags, Ops, Builtin->LLVMIntrinsic);
 
+  // Emit set FPMR for intrinsics that require it
+  if (TypeFlags.setsFPMR())
+Builder.CreateCall(CGM.getIntrinsic(Intrinsic::aarch64_set_fpmr),
+   Ops.pop_back_val());
   // Handle builtins which require their multi-vector operands to be swapped
   swapCommutativeSMEOperands(BuiltinID, Ops);
 
diff --git a/clang/test/CodeGen/AArch64/sme2-intrinsics/acle_sme2_fp8_fdot.c 
b/clang/test/CodeGen/AArch64/sme2-intrinsics/acle_sme2_fp8_fdot.c
new file mode 100644
index 00..999b1940df80c4
--- /dev/null
+++ b/clang/test/CodeGen/AArch64/sme2-intrinsics/acle_sme2_fp8_fdot.c
@@ -0,0 +1,57 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 5
+// REQUIRES: aarch64-registered-target
+#include 
+
+// RUN: %clang_cc1 -triple aarch64 -target-feature +bf16 -target-feature +sme 
-target-feature +sme2 -target-feature +sme-f8f16 -disable-O0-optnone -Werror 
-Wall -emit-llvm -o - %s | opt -S -passes mem2reg,instcombine,tailcallelim | 
FileCheck %s
+// RUN: %clang_cc1 -triple aarch64 -target-feature +bf16 -target-feature +sme 
-target-feature +sme2 -target-feature +sme-f8f16 -disable-O0-optnone -Werror 
-Wall -emit-llvm -o - -x c++ %s | opt -S -passes 
mem2reg,instcombine,tailcallelim | FileCheck %s -check-prefix=CPP-CHECK
+// RUN: %clang_cc1 -DSVE_OVERLOADED_FORMS -triple aarch64 -target-feature 
+bf16 -target-feature +sme -target-feature +sme2 -target-feature +sme-f8f16 
-disable-O0-optnone -We

[clang] [llvm] [AArch64] Add intrinsics for SME FP8 FDOT LANE instructions (PR #118492)

2024-12-06 Thread Jonathan Thackray via cfe-commits


@@ -986,8 +986,8 @@ def LUTI4_S_4ZZT2Z  : sme2_luti4_vector_vg4_strided<0b00, 
0b00, "luti4">;
 
 let Predicates = [HasSMEF8F16] in {
 defm FVDOT_VG2_M2ZZI_BtoH : sme2p1_multi_vec_array_vg2_index_f8f16<"fvdot", 
0b11, 0b110, ZZ_b_mul_r, ZPR4b8>;
-defm FDOT_VG2_M2ZZI_BtoH  : sme2p1_multi_vec_array_vg2_index_f8f16<"fdot",  
0b11, 0b010, ZZ_b_mul_r, ZPR4b8>;
-defm FDOT_VG4_M4ZZI_BtoH  : sme2p1_multi_vec_array_vg4_index_f8f16<"fdot",
0b100, _b_mul_r, ZPR4b8>;
+defm FDOT_VG2_M2ZZI_BtoH  : sme2_fp8_fdot_index_za16_vg1x2<"fdot", 0b11, 
0b010, ZZ_b_mul_r,   int_aarch64_sme_fp8_fdot_lane_za16_vg1x2>;

jthackray wrote:

Thanks, done :)

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


[clang] Switch builtin strings to use string tables (PR #118734)

2024-12-06 Thread Timm Baeder via cfe-commits


@@ -68,23 +69,156 @@ enum ID {
   FirstTSBuiltin
 };
 
+// The info used to represent each builtin.
 struct Info {
-  llvm::StringLiteral Name;
-  const char *Type, *Attributes;
-  const char *Features;
+  // Rather than store pointers to the string literals describing these four
+  // aspects of builtins, we store offsets into a common string table.
+  struct StrOffsets {
+int Name;
+int Type;
+int Attributes;
+int Features;
+  } Offsets;
+
   HeaderDesc Header;
   LanguageID Langs;
 };
 
+// The storage for `N` builtins. This contains a single pointer to the string
+// table used for these builtins and an array of metadata for each builtin.
+template  struct Storage {
+  const char *StringTable;
+
+  std::array Infos;
+
+  // A constexpr function to construct the storage for a a given string table 
in
+  // the first argument and an array in the second argument. This is *only*
+  // expected to be used at compile time, we should mark it `consteval` when
+  // available.
+  //
+  // The `Infos` array is particularly special. This function expects an array
+  // of `Info` structs, where the string offsets of each entry refer to the
+  // *sizes* of those strings rather than their offsets, and for the target
+  // string to be in the provided string table at an offset the sum of all
+  // previous string sizes. This function walks the `Infos` array computing the
+  // running sum and replacing the sizes with the actual offsets in the string
+  // table that should be used. This arrangement is designed to make it easy to
+  // expand `.def` and `.inc` files with X-macros to construct both the string
+  // table and the `Info` structs in the arguments to this function.
+  static constexpr auto Make(const char *Strings,
+ std::array Infos) -> Storage {

tbaederr wrote:

This applies to a few functions added in this PR, but we don't really use 
trailing return types unless it's necessary

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


[clang] [AST] Include clang/Basic/DiagnosticComment.h instead of clang/AST/CommentDiagnostic.h (PR #117499)

2024-12-06 Thread Richard Trieu via cfe-commits

Weverything wrote:

I support getting rid of the Diagnostic.h files outside of the Basic directory, 
at least when they are just forwarding headers.  From a layering point of view, 
Clang_Diagnostics should be the same level as Basic so it shouldn't be having 
things from AST.  Removing the forwarding headers will help clean up the 
layering.

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


[clang] [RFC] Initial implementation of P2719 (PR #113510)

2024-12-06 Thread via cfe-commits


@@ -4778,6 +4784,16 @@ class Sema final : public SemaBase {
 
   CXXRecordDecl *getStdBadAlloc() const;
   EnumDecl *getStdAlignValT() const;
+  const ClassTemplateDecl *getStdTypeIdentity() const;
+  ClassTemplateDecl *getStdTypeIdentity();
+  std::optional instantiateSpecializedTypeIdentity(QualType Subject);
+  bool isTypeIdentitySpecialization(QualType Type) const;
+  bool isTypeAwareOperatorNewOrDelete(const FunctionDecl *FnDecl) const;
+  bool isTypeAwareOperatorNewOrDelete(const FunctionTemplateDecl *FnDecl) 
const;
+  bool isTypeAwareOperatorNewOrDelete(const NamedDecl *FnDecl) const;

cor3ntin wrote:

Do we really need 3 functions there, or can we just expose the `NamedDecl` one 
and dispatch inside of it?

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


[clang-tools-extra] [clangd] Add quick fix to automatically adds NOLINTNEXTLINE comment (PR #114661)

2024-12-06 Thread kadir çetinkaya via cfe-commits

kadircet wrote:

(sorry for the late reply)

> Just want to confirm that this infrastructure isn't currently being used by 
> anything in Clangd.

we do have some out-of-tree usages, but nothing in the tree, apart from tests, 
use this infrastructure yet.

> I assume I should extend FeatureModule to add my NOLINT fix feature and add 
> it in ClangMain.cpp conditioning on command line options. Would that be the 
> correct approach?

yes, we basically should have a new feature-module, from that new 
feature-module we can contribute a tweak. this tweak can look at all the 
diagnostics in the AST, find the ones that intersect with users selection, and 
if they're from clang-tidy emit a code-action that inserts `` // 
NOLINTNEXTLINE(check-name)`.

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


[clang] [RISCV] Merging RISCVToolChain and BareMetal toolchains (PR #118809)

2024-12-06 Thread Kito Cheng via cfe-commits


@@ -503,12 +624,22 @@ void baremetal::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   const llvm::Triple::ArchType Arch = TC.getArch();
   const llvm::Triple &Triple = getToolChain().getEffectiveTriple();
 
-  AddLinkerInputs(TC, Inputs, Args, CmdArgs, JA);
+  if (!D.SysRoot.empty())
+CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot));
 
+  Args.addAllArgs(CmdArgs, {options::OPT_u});

kito-cheng wrote:

Forgot to explicitly mention that here, move this down a little bit, and merge 
together with other linker options.

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


[clang] [C++20] Destroying delete and deleted destructors (PR #118800)

2024-12-06 Thread Aaron Ballman via cfe-commits

https://github.com/AaronBallman updated 
https://github.com/llvm/llvm-project/pull/118800

>From 34d3d3000bc6096bbc9eb35ce85b6ceca50b91ca Mon Sep 17 00:00:00 2001
From: Aaron Ballman 
Date: Thu, 5 Dec 2024 08:31:24 -0500
Subject: [PATCH 1/4] [C++20] Destroying delete and deleted destructors

When a destroying delete overload is selected, the destructor is not
automatically called. Therefore, the destructor can be deleted without
causing the program to be ill-formed.
---
 clang/docs/ReleaseNotes.rst   |  2 ++
 clang/lib/Sema/SemaExprCXX.cpp|  6 +++--
 .../CXX/expr/expr.unary/expr.delete/p10.cpp   | 22 +--
 3 files changed, 26 insertions(+), 4 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e484eb7a76e63a..4a72e4046e2d03 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -663,6 +663,8 @@ Bug Fixes in This Version
 - Fixed a crash when GNU statement expression contains invalid statement 
(#GH113468).
 - Fixed a failed assertion when using ``__attribute__((noderef))`` on an
   ``_Atomic``-qualified type (#GH116124).
+- No longer incorrectly diagnosing use of a deleted destructor when the
+  selected overload of ``operator delete`` for that type is a destroying 
delete.
 
 Bug Fixes to Compiler Builtins
 ^^
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index db9ea7fb66e05a..45840dfa31ac92 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -3792,13 +3792,15 @@ Sema::ActOnCXXDelete(SourceLocation StartLoc, bool 
UseGlobal,
   .HasSizeT;
   }
 
-  if (!PointeeRD->hasIrrelevantDestructor())
+  if (!PointeeRD->hasIrrelevantDestructor() &&
+  (!OperatorDelete || !OperatorDelete->isDestroyingOperatorDelete())) {
 if (CXXDestructorDecl *Dtor = LookupDestructor(PointeeRD)) {
   MarkFunctionReferenced(StartLoc,
-const_cast(Dtor));
+ const_cast(Dtor));
   if (DiagnoseUseOfDecl(Dtor, StartLoc))
 return ExprError();
 }
+  }
 
   CheckVirtualDtorCall(PointeeRD->getDestructor(), StartLoc,
/*IsDelete=*/true, /*CallCanBeVirtual=*/true,
diff --git a/clang/test/CXX/expr/expr.unary/expr.delete/p10.cpp 
b/clang/test/CXX/expr/expr.unary/expr.delete/p10.cpp
index aad2747dd32f24..b2c0a2c79695fc 100644
--- a/clang/test/CXX/expr/expr.unary/expr.delete/p10.cpp
+++ b/clang/test/CXX/expr/expr.unary/expr.delete/p10.cpp
@@ -1,7 +1,14 @@
-// RUN: %clang_cc1 -std=c++1z -verify %s
+// RUN: %clang_cc1 -std=c++20 -verify %s
 
 using size_t = decltype(sizeof(0));
-namespace std { enum class align_val_t : size_t {}; }
+namespace std {
+  enum class align_val_t : size_t {};
+  struct destroying_delete_t {
+explicit destroying_delete_t() = default;
+  };
+
+  inline constexpr destroying_delete_t destroying_delete{};
+}
 
 // Aligned version is preferred over unaligned version,
 // unsized version is preferred over sized version.
@@ -23,3 +30,14 @@ struct alignas(Align) B {
 };
 void f(B<__STDCPP_DEFAULT_NEW_ALIGNMENT__> *p) { delete p; }
 void f(B<__STDCPP_DEFAULT_NEW_ALIGNMENT__ * 2> *p) { delete p; } // 
expected-error {{deleted}}
+
+// Ensure that a deleted destructor is acceptable when the selected overload
+// for operator delete is a destroying delete. See the comments in GH118660.
+struct S {
+  ~S() = delete;
+  void operator delete(S *, std::destroying_delete_t) noexcept {}
+};
+
+void foo(S *s) {
+  delete s; // Was rejected, is intended to be accepted.
+}

>From 133a8aa2934f9d6ed733e74af65180131d59cc91 Mon Sep 17 00:00:00 2001
From: Aaron Ballman 
Date: Thu, 5 Dec 2024 10:14:46 -0500
Subject: [PATCH 2/4] Update based on review feedback

* Added a standards reference
* Added a test case
* Fixed an issue the new test case identified
---
 clang/lib/Sema/SemaExprCXX.cpp | 13 +++--
 clang/test/CXX/expr/expr.unary/expr.delete/p10.cpp | 10 ++
 2 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 45840dfa31ac92..6ac44ae7af28c3 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -3792,6 +3792,14 @@ Sema::ActOnCXXDelete(SourceLocation StartLoc, bool 
UseGlobal,
   .HasSizeT;
   }
 
+  // C++20 [expr.delete]p6: If the value of the operand of the delete-
+  // expression is not a null pointer value and the selected deallocation
+  // function (see below) is not a destroying operator delete, the delete-
+  // expression will invoke the destructor (if any) for the object or the
+  // elements of the array being deleted.
+  //
+  // This means we should not look at the destructor for a destroying
+  // delete operator, as that destructor is never called.
   if (!Pointee

[clang] [clang][AArch64] Fix C++11 style initialization of typedef'd vectors (PR #118956)

2024-12-06 Thread Paul Walker via cfe-commits


@@ -0,0 +1,23 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 2
+// RUN: %clang_cc1 -fclang-abi-compat=latest -triple aarch64-none-linux-gnu 
-target-feature +sve -emit-llvm -o - %s | FileCheck %s
+
+#include 
+
+using vec_t = svint8_t;
+
+/// From: https://github.com/llvm/llvm-project/issues/107609
+/// The type of `vec` is a typedef of svint8_t, while svdup_s8 returns the 
non-typedef'd type.
+
+// CHECK-LABEL: define dso_local  @_Z20sve_init_dup_typedefv
+// CHECK-SAME: () #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  entry:
+// CHECK-NEXT:[[VEC:%.*]] = alloca , align 16
+// CHECK-NEXT:[[TMP0:%.*]] = call  
@llvm.aarch64.sve.dup.x.nxv16i8(i8 2)
+// CHECK-NEXT:store  [[TMP0]], ptr [[VEC]], align 16
+// CHECK-NEXT:[[TMP1:%.*]] = load , ptr [[VEC]], align 16
+// CHECK-NEXT:ret  [[TMP1]]
+//
+vec_t sve_init_dup_typedef() {
+  vec_t vec{svdup_s8(2)};
+  return vec;
+}

paulwalker-arm wrote:

A dedicated test file seems excessive.  Is adding 
```
using vec_t = __SVInt8_t;
void test_copy_s8_typedef(__SVInt8_t a) {
  vec_t vec{a};
}
```
to the bottom of `clang/test/CodeGenCXX/aarch64-sve-vector-init.cpp` sufficient?

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


[clang] [RISCV] Merging RISCVToolChain and BareMetal toolchains (PR #118809)

2024-12-06 Thread Garvit Gupta via cfe-commits


@@ -503,12 +624,22 @@ void baremetal::Linker::ConstructJob(Compilation &C, 
const JobAction &JA,
   const llvm::Triple::ArchType Arch = TC.getArch();
   const llvm::Triple &Triple = getToolChain().getEffectiveTriple();
 
-  AddLinkerInputs(TC, Inputs, Args, CmdArgs, JA);
+  if (!D.SysRoot.empty())
+CmdArgs.push_back(Args.MakeArgString("--sysroot=" + D.SysRoot));
 
+  Args.addAllArgs(CmdArgs, {options::OPT_u});

quic-garvgupt wrote:

Sure, I will be making these changes in the next patchset. However, I wanted to 
clarify if there is any specific reason why, in the RISCVToolchain baremetal 
object, OPT_L and OPT_u are added separately before FilePathLibArgs, and then 
subsequently the rest of the OPT_* options are added. 
https://github.com/llvm/llvm-project/blob/89e919fb0df391da42dbfd48cd8de268335fe672/clang/lib/Driver/ToolChains/RISCVToolchain.cpp#L201

I understand that for gnuld, the order in which flags and object files appear 
on the command line is relevant, unlike for lld. Was this intentional? If so, I 
will maintain that behavior; otherwise, I will add them in a single 
`addAllArgs(...)` function.

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


[clang] [llvm] [AArch64] Refactor implementation of FP8 types (NFC) (PR #118969)

2024-12-06 Thread Momchil Velikov via cfe-commits

https://github.com/momchil-velikov created 
https://github.com/llvm/llvm-project/pull/118969

* The FP8 scalar type (`__mfp8`) was described as a vector type
* The FP8 vector types were described/assumed to have
  integer element type (the element type ought to be `__mfp8`),
* Add support for `m` type specifier (denoting `__mfp8`)
  in `DecodeTypeFromStr` and create SVE builtin prototypes using
  the specifier, instead of `int8_t`.

>From 7e2d60348850619fb7b0c8a88e92ab103f907d34 Mon Sep 17 00:00:00 2001
From: Momchil Velikov 
Date: Fri, 6 Dec 2024 11:08:21 +
Subject: [PATCH 1/3] Handle scalable store size in MemCpyOptimizer

The compiler crashes with an ICE when it tries to create a `memset` with
scalable size.
---
 .../lib/Transforms/Scalar/MemCpyOptimizer.cpp |  3 +-
 .../CodeGen/AArch64/memset-scalable-size.ll   | 56 +++
 2 files changed, 58 insertions(+), 1 deletion(-)
 create mode 100644 llvm/test/CodeGen/AArch64/memset-scalable-size.ll

diff --git a/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp 
b/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
index 0cba5d077da62b..fc5f6ff2b7f377 100644
--- a/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
+++ b/llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp
@@ -800,8 +800,9 @@ bool MemCpyOptPass::processStore(StoreInst *SI, 
BasicBlock::iterator &BBI) {
 // in subsequent passes.
 auto *T = V->getType();
 if (T->isAggregateType()) {
-  uint64_t Size = DL.getTypeStoreSize(T);
   IRBuilder<> Builder(SI);
+  Value *Size =
+  Builder.CreateTypeSize(Builder.getInt64Ty(), DL.getTypeStoreSize(T));
   auto *M = Builder.CreateMemSet(SI->getPointerOperand(), ByteVal, Size,
  SI->getAlign());
   M->copyMetadata(*SI, LLVMContext::MD_DIAssignID);
diff --git a/llvm/test/CodeGen/AArch64/memset-scalable-size.ll 
b/llvm/test/CodeGen/AArch64/memset-scalable-size.ll
new file mode 100644
index 00..8ea6330f235a69
--- /dev/null
+++ b/llvm/test/CodeGen/AArch64/memset-scalable-size.ll
@@ -0,0 +1,56 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 
UTC_ARGS: --version 5
+; RUN: opt -S --passes=memcpyopt < %s | FileCheck %s
+target triple = "aarch64-unknown-linux"
+
+define void @f0() {
+; CHECK-LABEL: define void @f0() {
+; CHECK-NEXT:  [[ENTRY:.*:]]
+; CHECK-NEXT:[[P:%.*]] = alloca { ,  
}, align 2
+; CHECK-NEXT:[[TMP0:%.*]] = call i64 @llvm.vscale.i64()
+; CHECK-NEXT:[[TMP1:%.*]] = mul i64 [[TMP0]], 4
+; CHECK-NEXT:call void @llvm.memset.p0.i64(ptr align 2 [[P]], i8 0, i64 
[[TMP1]], i1 false)
+; CHECK-NEXT:call void @g(ptr [[P]])
+; CHECK-NEXT:ret void
+;
+entry:
+  %p = alloca { , }, align 2
+  store { ,  } zeroinitializer, ptr %p, 
align 2
+  call void @g(ptr %p)
+  ret void
+}
+
+define void @f1() {
+; CHECK-LABEL: define void @f1() {
+; CHECK-NEXT:  [[ENTRY:.*:]]
+; CHECK-NEXT:[[P:%.*]] = alloca { , ,  }, align 16
+; CHECK-NEXT:[[TMP0:%.*]] = call i64 @llvm.vscale.i64()
+; CHECK-NEXT:[[TMP1:%.*]] = mul i64 [[TMP0]], 48
+; CHECK-NEXT:call void @llvm.memset.p0.i64(ptr align 16 [[P]], i8 0, i64 
[[TMP1]], i1 false)
+; CHECK-NEXT:call void @g(ptr [[P]])
+; CHECK-NEXT:ret void
+;
+entry:
+  %p = alloca {, ,  }, align 16
+  store {, ,  } 
zeroinitializer, ptr %p, align 16
+  call void @g(ptr %p)
+  ret void
+}
+
+define void @f2() {
+; CHECK-LABEL: define void @f2() {
+; CHECK-NEXT:  [[ENTRY:.*:]]
+; CHECK-NEXT:[[P:%.*]] = alloca { , ,  }, align 16
+; CHECK-NEXT:[[TMP0:%.*]] = call i64 @llvm.vscale.i64()
+; CHECK-NEXT:[[TMP1:%.*]] = mul i64 [[TMP0]], 192
+; CHECK-NEXT:call void @llvm.memset.p0.i64(ptr align 16 [[P]], i8 0, i64 
[[TMP1]], i1 false)
+; CHECK-NEXT:call void @g(ptr [[P]])
+; CHECK-NEXT:ret void
+;
+entry:
+  %p = alloca {, ,  }, align 16
+  store {, ,  } 
zeroinitializer, ptr %p, align 16
+  call void @g(ptr %p)
+  ret void
+}
+
+declare void @g(ptr)

>From 83331bbf9d083ec8cba96acc32114ed1518e91f7 Mon Sep 17 00:00:00 2001
From: Momchil Velikov 
Date: Fri, 6 Dec 2024 10:47:43 +
Subject: [PATCH 2/3] Fix SVE tuples

---
 clang/lib/CodeGen/Targets/AArch64.cpp |  68 +++
 .../test/CodeGen/AArch64/pure-scalable-args.c |  19 
 .../CodeGenCXX/aarch64-mangle-sve-vectors.cpp | 106 --
 3 files changed, 111 insertions(+), 82 deletions(-)

diff --git a/clang/lib/CodeGen/Targets/AArch64.cpp 
b/clang/lib/CodeGen/Targets/AArch64.cpp
index be33e26f047841..ad7f405cc72550 100644
--- a/clang/lib/CodeGen/Targets/AArch64.cpp
+++ b/clang/lib/CodeGen/Targets/AArch64.cpp
@@ -52,6 +52,7 @@ class AArch64ABIInfo : public ABIInfo {
 
   bool isIllegalVectorType(QualType Ty) const;
 
+  bool passAsAggregateType(QualType Ty) const;
   bool passAsPureScalableType(QualType Ty, unsigned &NV, unsigned &NP,
   SmallVectorImpl &CoerceToSeq) 
const;
 
@@ -337,6 +338,10 @@ ABIArgInfo 
AArch64ABIInfo::coerceAndExpandPureS

[clang] [llvm] [AArch64] Refactor implementation of FP8 types (NFC) (PR #118969)

2024-12-06 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-llvm-transforms

Author: Momchil Velikov (momchil-velikov)


Changes

* The FP8 scalar type (`__mfp8`) was described as a vector type
* The FP8 vector types were described/assumed to have
  integer element type (the element type ought to be `__mfp8`),
* Add support for `m` type specifier (denoting `__mfp8`)
  in `DecodeTypeFromStr` and create SVE builtin prototypes using
  the specifier, instead of `int8_t`.

---

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


12 Files Affected:

- (modified) clang/include/clang/AST/Type.h (+5) 
- (modified) clang/include/clang/Basic/AArch64SVEACLETypes.def (+18-6) 
- (modified) clang/lib/AST/ASTContext.cpp (+30-7) 
- (modified) clang/lib/AST/ItaniumMangle.cpp (+5) 
- (modified) clang/lib/AST/Type.cpp (+1-3) 
- (modified) clang/lib/CodeGen/CodeGenTypes.cpp (+10-3) 
- (modified) clang/lib/CodeGen/Targets/AArch64.cpp (+49-26) 
- (modified) clang/test/CodeGen/AArch64/pure-scalable-args.c (+19) 
- (modified) clang/test/CodeGenCXX/aarch64-mangle-sve-vectors.cpp (+48-58) 
- (modified) clang/utils/TableGen/SveEmitter.cpp (+2-2) 
- (modified) llvm/lib/Transforms/Scalar/MemCpyOptimizer.cpp (+2-1) 
- (added) llvm/test/CodeGen/AArch64/memset-scalable-size.ll (+56) 


``diff
diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h
index 6fd6c73a516f08..626cfea56a47db 100644
--- a/clang/include/clang/AST/Type.h
+++ b/clang/include/clang/AST/Type.h
@@ -2518,6 +2518,7 @@ class alignas(TypeAlignment) Type : public 
ExtQualsTypeCommonBase {
   bool isFloat32Type() const;
   bool isDoubleType() const;
   bool isBFloat16Type() const;
+  bool isMFloat8Type() const;
   bool isFloat128Type() const;
   bool isIbm128Type() const;
   bool isRealType() const; // C99 6.2.5p17 (real floating + integer)
@@ -8532,6 +8533,10 @@ inline bool Type::isBFloat16Type() const {
   return isSpecificBuiltinType(BuiltinType::BFloat16);
 }
 
+inline bool Type::isMFloat8Type() const {
+  return isSpecificBuiltinType(BuiltinType::MFloat8);
+}
+
 inline bool Type::isFloat128Type() const {
   return isSpecificBuiltinType(BuiltinType::Float128);
 }
diff --git a/clang/include/clang/Basic/AArch64SVEACLETypes.def 
b/clang/include/clang/Basic/AArch64SVEACLETypes.def
index 063cac1f4a58ee..6b704b386536c9 100644
--- a/clang/include/clang/Basic/AArch64SVEACLETypes.def
+++ b/clang/include/clang/Basic/AArch64SVEACLETypes.def
@@ -57,6 +57,11 @@
 //  - IsBF true for vector of brain float elements.
 
//===--===//
 
+#ifndef SVE_SCALAR_TYPE
+#define SVE_SCALAR_TYPE(Name, MangledName, Id, SingletonId, Bits) \
+  SVE_TYPE(Name, Id, SingletonId)
+#endif
+
 #ifndef SVE_VECTOR_TYPE
 #define SVE_VECTOR_TYPE(Name, MangledName, Id, SingletonId) \
   SVE_TYPE(Name, Id, SingletonId)
@@ -72,6 +77,11 @@
   SVE_VECTOR_TYPE_DETAILS(Name, MangledName, Id, SingletonId, NumEls, ElBits, 
NF, false, false, true)
 #endif
 
+#ifndef SVE_VECTOR_TYPE_MFLOAT
+#define SVE_VECTOR_TYPE_MFLOAT(Name, MangledName, Id, SingletonId, NumEls, 
ElBits, NF) \
+  SVE_VECTOR_TYPE_DETAILS(Name, MangledName, Id, SingletonId, NumEls, ElBits, 
NF, false, false, false)
+#endif
+
 #ifndef SVE_VECTOR_TYPE_FLOAT
 #define SVE_VECTOR_TYPE_FLOAT(Name, MangledName, Id, SingletonId, NumEls, 
ElBits, NF) \
   SVE_VECTOR_TYPE_DETAILS(Name, MangledName, Id, SingletonId, NumEls, ElBits, 
NF, false, true, false)
@@ -125,8 +135,7 @@ SVE_VECTOR_TYPE_FLOAT("__SVFloat64_t", "__SVFloat64_t", 
SveFloat64, SveFloat64Ty
 
 SVE_VECTOR_TYPE_BFLOAT("__SVBfloat16_t", "__SVBfloat16_t", SveBFloat16, 
SveBFloat16Ty, 8, 16, 1)
 
-// This is a 8 bits opaque type.
-SVE_VECTOR_TYPE_INT("__SVMfloat8_t", "__SVMfloat8_t",  SveMFloat8, 
SveMFloat8Ty, 16, 8, 1, false)
+SVE_VECTOR_TYPE_MFLOAT("__SVMfloat8_t", "__SVMfloat8_t",  SveMFloat8, 
SveMFloat8Ty, 16, 8, 1)
 
 //
 // x2
@@ -148,7 +157,7 @@ SVE_VECTOR_TYPE_FLOAT("__clang_svfloat64x2_t", 
"svfloat64x2_t", SveFloat64x2, Sv
 
 SVE_VECTOR_TYPE_BFLOAT("__clang_svbfloat16x2_t", "svbfloat16x2_t", 
SveBFloat16x2, SveBFloat16x2Ty, 8, 16, 2)
 
-SVE_VECTOR_TYPE_INT("__clang_svmfloat8x2_t", "svmfloat8x2_t", SveMFloat8x2, 
SveMFloat8x2Ty, 16, 8, 2, false)
+SVE_VECTOR_TYPE_MFLOAT("__clang_svmfloat8x2_t", "svmfloat8x2_t", SveMFloat8x2, 
SveMFloat8x2Ty, 16, 8, 2)
 
 //
 // x3
@@ -170,7 +179,7 @@ SVE_VECTOR_TYPE_FLOAT("__clang_svfloat64x3_t", 
"svfloat64x3_t", SveFloat64x3, Sv
 
 SVE_VECTOR_TYPE_BFLOAT("__clang_svbfloat16x3_t", "svbfloat16x3_t", 
SveBFloat16x3, SveBFloat16x3Ty, 8, 16, 3)
 
-SVE_VECTOR_TYPE_INT("__clang_svmfloat8x3_t", "svmfloat8x3_t", SveMFloat8x3, 
SveMFloat8x3Ty, 16, 8, 3, false)
+SVE_VECTOR_TYPE_MFLOAT("__clang_svmfloat8x3_t", "svmfloat8x3_t", SveMFloat8x3, 
SveMFloat8x3Ty, 16, 8, 3)
 
 //
 // x4
@@ -192,7 +201,7 @@ SVE_VECTOR_TYPE_FLOAT("__clang_svfloat64x4_t", 
"svfloat64x4_t", SveFloat64x4, Sv
 
 SVE_VECTOR_TYPE_B

[clang] [clang-tools-extra] [clang] Compute accurate begin location for CallExpr with explicit object parameter (PR #117841)

2024-12-06 Thread Nikita Popov via cfe-commits

nikic wrote:

It looks like this causes a significant compile-time regression: 
https://llvm-compile-time-tracker.com/compare.php?from=2b855dd97092e2178ac5c470a804a17ec440d7e5&to=9ccde12f5eeb91152900082a2ae839e2a9702b31&stat=instructions:u
 (Maybe most clearly seen during clang bootstrap, where this adds 0.5% to many 
compilations: 
https://llvm-compile-time-tracker.com/compare_clang.php?from=2b855dd97092e2178ac5c470a804a17ec440d7e5&to=9ccde12f5eeb91152900082a2ae839e2a9702b31&stat=instructions%3Au&sortBy=interestingness)

Is that expected?

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


  1   2   3   4   5   >