[clang] [PowerPC] Support local-dynamic TLS relocation on AIX (PR #66316)

2023-09-25 Thread Kai Luo via cfe-commits

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


[clang] [InstCombine] Add combines/simplifications for `llvm.ptrmask` (PR #67166)

2023-09-25 Thread Yingwei Zheng via cfe-commits

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


[clang] [InstCombine] Add combines/simplifications for `llvm.ptrmask` (PR #67166)

2023-09-25 Thread Yingwei Zheng via cfe-commits

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


[clang] [PowerPC] Support local-dynamic TLS relocation on AIX (PR #66316)

2023-09-25 Thread Felix via cfe-commits

orcguru wrote:

Currently obj mode has one issue: define more than one __thread variable, and 
all access return the first variable.

I'm investigating the root cause and will update patch accordingly. ASM mode is 
fine.



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


[PATCH] D156605: [clangd][CodeComplete] Improve FunctionCanBeCall

2023-09-25 Thread Nathan Ridge via Phabricator via cfe-commits
nridge accepted this revision.
nridge added a comment.
This revision is now accepted and ready to land.

Thank you, the updates look good! Please go ahead and merge after addressing 
the last minor nits.




Comment at: clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp:594
+Contains(AllOf(named("generic"),
+   signature("(U, V)"),
+   snippetSuffix("<${1:typename T}, ${2:typename U}>";

It seems a bit inconsistent that the signature includes parameters with default 
arguments in the non-call case, and not in the call case. I guess the reason 
for this is that in the non-call case, the parameters with defaults become a 
`CK_Optional` chunk which clangd adds to the signature 
[here](https://searchfox.org/llvm/rev/4c241a9335c3046e418e1b4afc162bc576c072fd/clang-tools-extra/clangd/CodeCompletionStrings.cpp#213-214),
 while in the call case the deduced parameters (which include the ones with 
defaults) are omitted from the completion string altogether.

It may be more consistent to put the deduced parameters into an optional chunk 
as well, and let the consumer of the CodeCompletionString decide whether to use 
them?

Anyways, that's an idea for the future, no change needed now.



Comment at: clang/lib/Sema/SemaCodeComplete.cpp:1301
+
+  // When completing a non-static member function (and not via
+  // dot/arrow member access) and we're not inside that class' scope,

nit: let's shorten this comment to just "If we're not inside the scope of the 
method's class, it can't be a call"

(The parts about non-static and dot/arrow member access are checked and 
explained in `canFunctionBeCalled()`)



Comment at: clang/lib/Sema/SemaCodeComplete.cpp:3589
 llvm::SmallBitVector Deduced;
-Sema::MarkDeducedTemplateParameters(Ctx, FunTmpl, Deduced);
+// Avoid running it if this is not a call: We'd emit *all* template
+// parameters.

nit: "We'd" --> "We should"


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156605/new/

https://reviews.llvm.org/D156605

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


[clang] clang/OpenCL: set sqrt fp accuracy on call to Z4sqrt (PR #66651)

2023-09-25 Thread Romaric Jodin via cfe-commits

rjodinchr wrote:

@arsenm Could you review this PR again please?

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


[PATCH] D158824: [RISCV][MC] MC layer support for xcvmem and xcvelw extensions

2023-09-25 Thread Liao Chunyu via Phabricator via cfe-commits
liaolucy added a comment.

ping


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D158824/new/

https://reviews.llvm.org/D158824

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


[clang] clang/OpenCL: set sqrt fp accuracy on call to Z4sqrt (PR #66651)

2023-09-25 Thread Matt Arsenault via cfe-commits


@@ -5612,6 +5612,10 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo 
&CallInfo,
   BundleList);
 EmitBlock(Cont);
   }
+  if (CI->getCalledFunction() && CI->getCalledFunction()->hasName() &&
+  CI->getCalledFunction()->getName().startswith("_Z4sqrt")) {

arsenm wrote:

This isn't a specific enough filter. Exactly match the full name for all the 
types?

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


[clang] [clang] Preserve UDL nodes in RemoveNestedImmediateInvocation (PR #66641)

2023-09-25 Thread Nathan Ridge via cfe-commits

HighCommander4 wrote:

I wonder if `TreeTransform::TransformUserDefinedLiteral()` should be doing 
something like `RebuildUserDefinedLiteral()`.

Anyways, the patch looks reasonable to me but someone more familiar with Sema 
should review it.

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


[clang] clang/OpenCL: set sqrt fp accuracy on call to Z4sqrt (PR #66651)

2023-09-25 Thread Matt Arsenault via cfe-commits


@@ -5612,6 +5612,10 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo 
&CallInfo,
   BundleList);
 EmitBlock(Cont);
   }
+  if (CI->getCalledFunction() && CI->getCalledFunction()->hasName() &&
+  CI->getCalledFunction()->getName().startswith("_Z4sqrt")) {

arsenm wrote:

Maybe it's good enough, I guess the Z4 filters out other prefixes. Not sure 
about arbitrary custom ext_vector_type

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


[PATCH] D154262: [clang][Interp] LambdaThisCaptures

2023-09-25 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added a comment.

Ping


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154262/new/

https://reviews.llvm.org/D154262

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


[PATCH] D157252: [clang][ExprConst] Handle 0 type size in builtin_memcpy etc.

2023-09-25 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added a comment.

Ping


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D157252/new/

https://reviews.llvm.org/D157252

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


[PATCH] D154581: [clang][Interp] Track existing InitMaps in InterpState

2023-09-25 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added a comment.

Ping


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D154581/new/

https://reviews.llvm.org/D154581

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


[PATCH] D156453: [clang][Interp] Create only globals when initializing a global variable

2023-09-25 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added a comment.

Ping


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156453/new/

https://reviews.llvm.org/D156453

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


[PATCH] D158516: [clang][Interp] Only lazily visit constant globals

2023-09-25 Thread Timm Bäder via Phabricator via cfe-commits
tbaeder added a comment.

Ping


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D158516/new/

https://reviews.llvm.org/D158516

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


[clang] [NVPTX] Add support for maxclusterrank in launch_bounds (PR #66496)

2023-09-25 Thread Jakub Chlanda via cfe-commits

https://github.com/jchlanda updated 
https://github.com/llvm/llvm-project/pull/66496

>From 9c8caed3c8def15ccdbfdf831f36d0befed1fc84 Mon Sep 17 00:00:00 2001
From: Jakub Chlanda 
Date: Fri, 15 Sep 2023 12:08:04 +0100
Subject: [PATCH 1/6] [NVPTX] Add support for maxclusterrank in launch_bounds

Since SM_90 CUDA supports specifying additional argument to the
launch_bounds attribute: maxBlocksPerCluster, to express the maximum
number of CTAs that can be part of the cluster. See:
https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#cluster-dimension-directives-maxclusterrank
and
https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#launch-bounds
for details.
---
 clang/include/clang/Basic/Attr.td |  3 +-
 .../clang/Basic/DiagnosticSemaKinds.td|  4 +
 clang/include/clang/Sema/Sema.h   |  5 +-
 clang/lib/CodeGen/Targets/NVPTX.cpp   | 12 ++-
 clang/lib/Parse/ParseOpenMP.cpp   |  3 +-
 clang/lib/Sema/SemaDeclAttr.cpp   | 46 +--
 .../lib/Sema/SemaTemplateInstantiateDecl.cpp  | 10 ++-
 clang/test/CodeGenCUDA/launch-bounds.cu   | 69 
 clang/test/SemaCUDA/launch_bounds.cu  |  4 +-
 clang/test/SemaCUDA/launch_bounds_sm_90.cu| 45 +++
 llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp | 79 +--
 llvm/lib/Target/NVPTX/NVPTXUtilities.cpp  |  4 +
 llvm/lib/Target/NVPTX/NVPTXUtilities.h|  1 +
 13 files changed, 227 insertions(+), 58 deletions(-)
 create mode 100644 clang/test/SemaCUDA/launch_bounds_sm_90.cu

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index c95db7e8049d47a..3c51261bd3eb081 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1267,7 +1267,8 @@ def CUDAInvalidTarget : InheritableAttr {
 
 def CUDALaunchBounds : InheritableAttr {
   let Spellings = [GNU<"launch_bounds">, Declspec<"__launch_bounds__">];
-  let Args = [ExprArgument<"MaxThreads">, ExprArgument<"MinBlocks", 1>];
+  let Args = [ExprArgument<"MaxThreads">, ExprArgument<"MinBlocks", 1>,
+  ExprArgument<"MaxBlocks", 1>];
   let LangOpts = [CUDA];
   let Subjects = SubjectList<[ObjCMethod, FunctionLike]>;
   // An AST node is created for this attribute, but is not used by other parts
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 0ac4df8edb242f6..088e3a45c7babba 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -11836,6 +11836,10 @@ def err_sycl_special_type_num_init_method : Error<
   "types with 'sycl_special_class' attribute must have one and only one 
'__init' "
   "method defined">;
 
+def warn_cuda_maxclusterrank_sm_90 : Warning<
+  "maxclusterrank requires sm_90 or higher, CUDA arch provided: %0, ignoring "
+  "%1 attribute">, InGroup;
+
 def err_bit_int_bad_size : Error<"%select{signed|unsigned}0 _BitInt must "
  "have a bit size of at least %select{2|1}0">;
 def err_bit_int_max_size : Error<"%select{signed|unsigned}0 _BitInt of bit "
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 47379e00a7445e3..dca7b66da3796d9 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -11051,12 +11051,13 @@ class Sema final {
   /// Create an CUDALaunchBoundsAttr attribute.
   CUDALaunchBoundsAttr *CreateLaunchBoundsAttr(const AttributeCommonInfo &CI,
Expr *MaxThreads,
-   Expr *MinBlocks);
+   Expr *MinBlocks,
+   Expr *MaxBlocks);
 
   /// AddLaunchBoundsAttr - Adds a launch_bounds attribute to a particular
   /// declaration.
   void AddLaunchBoundsAttr(Decl *D, const AttributeCommonInfo &CI,
-   Expr *MaxThreads, Expr *MinBlocks);
+   Expr *MaxThreads, Expr *MinBlocks, Expr *MaxBlocks);
 
   /// AddModeAttr - Adds a mode attribute to a particular declaration.
   void AddModeAttr(Decl *D, const AttributeCommonInfo &CI, IdentifierInfo 
*Name,
diff --git a/clang/lib/CodeGen/Targets/NVPTX.cpp 
b/clang/lib/CodeGen/Targets/NVPTX.cpp
index 0d4bbd795648008..64d019a10514d60 100644
--- a/clang/lib/CodeGen/Targets/NVPTX.cpp
+++ b/clang/lib/CodeGen/Targets/NVPTX.cpp
@@ -296,8 +296,8 @@ void CodeGenModule::handleCUDALaunchBoundsAttr(
 NVPTXTargetCodeGenInfo::addNVVMMetadata(F, "maxntidx",
 MaxThreads.getExtValue());
 
-  // min blocks is an optional argument for CUDALaunchBoundsAttr. If it was
-  // not specified in __launch_bounds__ or if the user specified a 0 value,
+  // min and max blocks is an optional argument for CUDALaunchBoundsAttr. If it
+  // was not specified in __launch_bounds__ or if the user specified

[clang] [NVPTX] Add support for maxclusterrank in launch_bounds (PR #66496)

2023-09-25 Thread Jakub Chlanda via cfe-commits


@@ -5607,6 +5607,21 @@ bool Sema::CheckRegparmAttr(const ParsedAttr &AL, 
unsigned &numParams) {
   return false;
 }
 
+// Helper to get CudaArch.
+static CudaArch getCudaArch(const TargetInfo &TI) {

jchlanda wrote:

Done in: 3c17966b26a613f3b1a117f992d45b751cbff463

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


[clang] [clang-analysis]Fix false positive in mutation check when using pointer to member function (PR #66846)

2023-09-25 Thread via cfe-commits


@@ -274,8 +288,8 @@ const Stmt *ExprMutationAnalyzer::findDirectMutation(const 
Expr *Exp) {
   const auto NonConstMethod = cxxMethodDecl(unless(isConst()));
 
   const auto AsNonConstThis = expr(anyOf(
-  cxxMemberCallExpr(callee(NonConstMethod),
-on(canResolveToExpr(equalsNode(Exp,
+  cxxMemberCallExpr(on(canResolveToExpr(equalsNode(Exp))),
+unless(isConstCallee())),

mzyKi wrote:

```unless(isConstCallee())``` This condition is unnecessary. I have tested your 
code in my machine.
In such testcase example,
```cpp
#include 

class X {
public:
  int a;
  int b;
};

void func(X &x, int X::*m) {
  /*const*/ X &tmp = x;

  tmp.*m = 77;
}

int main() {
  X x;
  x.a = 0;
  x.b = 0;

  std::cout << x.a << " " << x.b << std::endl;

  func(x, &X::a);

  std::cout << x.a << " " << x.b << std::endl;

  return 0;
}
```
 use ```cxxMemberCallExpr(callee(NonConstMethod),
on(canResolveToExpr(equalsNode(Exp,``` 
cxxMemberCallExpr matcher do not produce false positive




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


[clang] [clang-analysis]Fix false positive in mutation check when using pointer to member function (PR #66846)

2023-09-25 Thread via cfe-commits

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


[clang-tools-extra] [clang-analysis]Fix false positive in mutation check when using pointer to member function (PR #66846)

2023-09-25 Thread via cfe-commits

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


[clang] Introduce paged vector (PR #66430)

2023-09-25 Thread Giulio Eulisse via cfe-commits

https://github.com/ktf updated https://github.com/llvm/llvm-project/pull/66430

>From b5f984b5521c5b226a7c5297d19eb53953481890 Mon Sep 17 00:00:00 2001
From: Giulio Eulisse <10544+...@users.noreply.github.com>
Date: Thu, 14 Sep 2023 21:58:21 +0200
Subject: [PATCH] Introduce PagedVector class

The goal of the class is to be an (almost) drop in replacement for
SmallVector and std::vector when those are presized and filled later,
as it happens in SourceManager and ASTReader.

By splitting the actual vector in pages of the same size and allocating
the pages only when they are needed, using this containers reduces the
memory usage by a factor 4 for the cases relevant to the ALICE
experiment ROOT / cling usage.
---
 clang/include/clang/Basic/SourceManager.h |   3 +-
 clang/include/clang/Serialization/ASTReader.h |   5 +-
 clang/lib/Basic/SourceManager.cpp |  10 +-
 clang/lib/Serialization/ASTReader.cpp |   5 +-
 llvm/docs/ProgrammersManual.rst   |  33 ++
 llvm/include/llvm/ADT/PagedVector.h   | 316 
 llvm/unittests/ADT/CMakeLists.txt |   1 +
 llvm/unittests/ADT/PagedVectorTest.cpp| 342 ++
 8 files changed, 705 insertions(+), 10 deletions(-)
 create mode 100644 llvm/include/llvm/ADT/PagedVector.h
 create mode 100644 llvm/unittests/ADT/PagedVectorTest.cpp

diff --git a/clang/include/clang/Basic/SourceManager.h 
b/clang/include/clang/Basic/SourceManager.h
index 2f846502d6f3327..e37caa2252532f9 100644
--- a/clang/include/clang/Basic/SourceManager.h
+++ b/clang/include/clang/Basic/SourceManager.h
@@ -43,6 +43,7 @@
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/DenseSet.h"
 #include "llvm/ADT/IntrusiveRefCntPtr.h"
+#include "llvm/ADT/PagedVector.h"
 #include "llvm/ADT/PointerIntPair.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
@@ -699,7 +700,7 @@ class SourceManager : public RefCountedBase {
   ///
   /// Negative FileIDs are indexes into this table. To get from ID to an index,
   /// use (-ID - 2).
-  SmallVector LoadedSLocEntryTable;
+  llvm::PagedVector LoadedSLocEntryTable;
 
   /// The starting offset of the next local SLocEntry.
   ///
diff --git a/clang/include/clang/Serialization/ASTReader.h 
b/clang/include/clang/Serialization/ASTReader.h
index dc1eb21c27801fe..65e19c6e44cf571 100644
--- a/clang/include/clang/Serialization/ASTReader.h
+++ b/clang/include/clang/Serialization/ASTReader.h
@@ -38,6 +38,7 @@
 #include "llvm/ADT/DenseSet.h"
 #include "llvm/ADT/IntrusiveRefCntPtr.h"
 #include "llvm/ADT/MapVector.h"
+#include "llvm/ADT/PagedVector.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SetVector.h"
 #include "llvm/ADT/SmallPtrSet.h"
@@ -487,7 +488,7 @@ class ASTReader
   ///
   /// When the pointer at index I is non-NULL, the type with
   /// ID = (I + 1) << FastQual::Width has already been loaded
-  std::vector TypesLoaded;
+  llvm::PagedVector TypesLoaded;
 
   using GlobalTypeMapType =
   ContinuousRangeMap;
@@ -501,7 +502,7 @@ class ASTReader
   ///
   /// When the pointer at index I is non-NULL, the declaration with ID
   /// = I + 1 has already been loaded.
-  std::vector DeclsLoaded;
+  llvm::PagedVector DeclsLoaded;
 
   using GlobalDeclMapType =
   ContinuousRangeMap;
diff --git a/clang/lib/Basic/SourceManager.cpp 
b/clang/lib/Basic/SourceManager.cpp
index 0521ac7b30339ab..7fa8b8096ac4931 100644
--- a/clang/lib/Basic/SourceManager.cpp
+++ b/clang/lib/Basic/SourceManager.cpp
@@ -2344,11 +2344,11 @@ SourceManager::MemoryBufferSizes 
SourceManager::getMemoryBufferSizes() const {
 }
 
 size_t SourceManager::getDataStructureSizes() const {
-  size_t size = llvm::capacity_in_bytes(MemBufferInfos)
-+ llvm::capacity_in_bytes(LocalSLocEntryTable)
-+ llvm::capacity_in_bytes(LoadedSLocEntryTable)
-+ llvm::capacity_in_bytes(SLocEntryLoaded)
-+ llvm::capacity_in_bytes(FileInfos);
+  size_t size = llvm::capacity_in_bytes(MemBufferInfos) +
+llvm::capacity_in_bytes(LocalSLocEntryTable) +
+llvm::capacity_in_bytes(LoadedSLocEntryTable) +
+llvm::capacity_in_bytes(SLocEntryLoaded) +
+llvm::capacity_in_bytes(FileInfos);
 
   if (OverriddenFilesInfo)
 size += llvm::capacity_in_bytes(OverriddenFilesInfo->OverriddenFiles);
diff --git a/clang/lib/Serialization/ASTReader.cpp 
b/clang/lib/Serialization/ASTReader.cpp
index 0952244d037a77c..badd54987af18dd 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -7944,9 +7944,10 @@ void ASTReader::PrintStats() {
   std::fprintf(stderr, "*** AST File Statistics:\n");
 
   unsigned NumTypesLoaded =
-  TypesLoaded.size() - llvm::count(TypesLoaded, QualType());
+  TypesLoaded.size() - llvm::count(TypesLoaded.materialised(), QualType());
   unsigned NumDeclsLoaded =
-  DeclsLoaded.size() - llvm::count(DeclsLoaded, (Decl *)nullptr);
+  DeclsLoaded.size() -
+  llvm::count(DeclsLoaded.materialised(), (

[clang] Introduce paged vector (PR #66430)

2023-09-25 Thread Giulio Eulisse via cfe-commits


@@ -0,0 +1,307 @@
+//===- llvm/ADT/PagedVector.h - 'Lazyly allocated' vectors *- C++
+//-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This file defines the PagedVector class.
+//
+//===--===//
+#ifndef LLVM_ADT_PAGEDVECTOR_H
+#define LLVM_ADT_PAGEDVECTOR_H
+
+#include "llvm/ADT/PointerIntPair.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/iterator_range.h"
+#include "llvm/Support/Allocator.h"
+#include 
+#include 
+
+namespace llvm {
+// A vector that allocates memory in pages.
+//
+// Order is kept, but memory is allocated only when one element of the page is
+// accessed. This introduces a level of indirection, but it is useful when you
+// have a sparsely initialised vector where the full size is allocated upfront.
+//
+// As a side effect the elements are initialised later than in a normal vector.
+// On the first access to one of the elements of a given page all, the elements
+// of the page are initialised. This also means that the elements of the page
+// are initialised beyond the size of the vector.
+//
+// Similarly on destruction the elements are destroyed only when the page is
+// not needed anymore, delaying invoking the destructor of the elements.
+//
+// Notice that this does not have iterators, because if you have iterators it
+// probably means you are going to touch all the memory in any case, so better
+// use a std::vector in the first place.

ktf wrote:

Done.

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


[clang] [PowerPC] Disable float128 on AIX in Clang (PR #67298)

2023-09-25 Thread Qiu Chaofan via cfe-commits

https://github.com/ecnelises created 
https://github.com/llvm/llvm-project/pull/67298

PowerPC AIX backend does not support float128 at all. Diagnose even when 
specifying -mfloat128 to avoid backend crash.

>From 58cd725354eae6aa733c98374a804de0ef595c60 Mon Sep 17 00:00:00 2001
From: Qiu Chaofan 
Date: Mon, 25 Sep 2023 16:57:39 +0800
Subject: [PATCH] [PowerPC] Disable float128 on AIX in Clang

PowerPC AIX backend does not support float128 at all. Diagnose even when
specifying -mfloat128 to avoid backend crash.
---
 clang/lib/Basic/Targets/PPC.cpp | 2 +-
 clang/test/Sema/128bitfloat.cpp | 1 +
 2 files changed, 2 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Basic/Targets/PPC.cpp b/clang/lib/Basic/Targets/PPC.cpp
index e0abc069032e1ce..119ed9c1ac4504e 100644
--- a/clang/lib/Basic/Targets/PPC.cpp
+++ b/clang/lib/Basic/Targets/PPC.cpp
@@ -52,7 +52,7 @@ bool 
PPCTargetInfo::handleTargetFeatures(std::vector &Features,
   HasDirectMove = true;
 } else if (Feature == "+htm") {
   HasHTM = true;
-} else if (Feature == "+float128") {
+} else if (Feature == "+float128" && !getTriple().isOSAIX()) {
   HasFloat128 = true;
 } else if (Feature == "+power9-vector") {
   HasP9Vector = true;
diff --git a/clang/test/Sema/128bitfloat.cpp b/clang/test/Sema/128bitfloat.cpp
index b98b42496e8db27..bd9f2889c98f6aa 100644
--- a/clang/test/Sema/128bitfloat.cpp
+++ b/clang/test/Sema/128bitfloat.cpp
@@ -1,6 +1,7 @@
 // RUN: %clang_cc1 -verify -std=gnu++11 %s
 // RUN: %clang_cc1 -verify -std=c++11 %s
 // RUN: %clang_cc1 -triple powerpc64-linux -verify -std=c++11 %s
+// RUN: %clang_cc1 -triple powerpc64-ibm-aix -target-feature +float128 -verify 
-std=c++11 %s
 // RUN: %clang_cc1 -triple i686-windows-gnu -verify -std=c++11 %s
 // RUN: %clang_cc1 -triple x86_64-windows-gnu -verify -std=c++11 %s
 // RUN: %clang_cc1 -triple x86_64-windows-msvc -verify -std=c++11 %s

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


[PATCH] D159159: [PowerPC] Disable float128 on AIX in Clang

2023-09-25 Thread Qiu Chaofan via Phabricator via cfe-commits
qiucf abandoned this revision.
qiucf added a comment.

Migrated to https://github.com/llvm/llvm-project/pull/67298


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D159159/new/

https://reviews.llvm.org/D159159

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


[clang] [PowerPC] Disable float128 on AIX in Clang (PR #67298)

2023-09-25 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang


Changes

PowerPC AIX backend does not support float128 at all. Diagnose even when 
specifying -mfloat128 to avoid backend crash.

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


2 Files Affected:

- (modified) clang/lib/Basic/Targets/PPC.cpp (+1-1) 
- (modified) clang/test/Sema/128bitfloat.cpp (+1) 


``diff
diff --git a/clang/lib/Basic/Targets/PPC.cpp b/clang/lib/Basic/Targets/PPC.cpp
index e0abc069032e1ce..119ed9c1ac4504e 100644
--- a/clang/lib/Basic/Targets/PPC.cpp
+++ b/clang/lib/Basic/Targets/PPC.cpp
@@ -52,7 +52,7 @@ bool 
PPCTargetInfo::handleTargetFeatures(std::vector &Features,
   HasDirectMove = true;
 } else if (Feature == "+htm") {
   HasHTM = true;
-} else if (Feature == "+float128") {
+} else if (Feature == "+float128" && !getTriple().isOSAIX()) {
   HasFloat128 = true;
 } else if (Feature == "+power9-vector") {
   HasP9Vector = true;
diff --git a/clang/test/Sema/128bitfloat.cpp b/clang/test/Sema/128bitfloat.cpp
index b98b42496e8db27..bd9f2889c98f6aa 100644
--- a/clang/test/Sema/128bitfloat.cpp
+++ b/clang/test/Sema/128bitfloat.cpp
@@ -1,6 +1,7 @@
 // RUN: %clang_cc1 -verify -std=gnu++11 %s
 // RUN: %clang_cc1 -verify -std=c++11 %s
 // RUN: %clang_cc1 -triple powerpc64-linux -verify -std=c++11 %s
+// RUN: %clang_cc1 -triple powerpc64-ibm-aix -target-feature +float128 -verify 
-std=c++11 %s
 // RUN: %clang_cc1 -triple i686-windows-gnu -verify -std=c++11 %s
 // RUN: %clang_cc1 -triple x86_64-windows-gnu -verify -std=c++11 %s
 // RUN: %clang_cc1 -triple x86_64-windows-msvc -verify -std=c++11 %s

``




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


[clang] [PowerPC] Fix use of FPSCR builtins in smmintrin.h (PR #67299)

2023-09-25 Thread Qiu Chaofan via cfe-commits

https://github.com/ecnelises created 
https://github.com/llvm/llvm-project/pull/67299

smmintrin.h uses __builtin_mffs, __builtin_mffsl, __builtin_mtfsf and 
__builtin_set_fpscr_rn. This patch replaces the uses with ppc prefix and 
implement the missing ones.

This fixes issue #64664.

>From 5abcf8964394eb5124d606b00a94781147fd8f8d Mon Sep 17 00:00:00 2001
From: Qiu Chaofan 
Date: Mon, 25 Sep 2023 17:06:26 +0800
Subject: [PATCH] [PowerPC] Fix use of FPSCR builtins in smmintrin.h

smmintrin.h uses __builtin_mffs, __builtin_mffsl, __builtin_mtfsf and
__builtin_set_fpscr_rn. This patch replaces the uses with ppc prefix and
implement the missing ones.

This fixes issue #64664.
---
 clang/include/clang/Basic/BuiltinsPPC.def |  2 +
 clang/lib/Basic/Targets/PPC.cpp   |  4 ++
 clang/lib/CodeGen/CGBuiltin.cpp   |  5 ++
 clang/lib/Headers/ppc_wrappers/smmintrin.h| 50 +--
 clang/test/CodeGen/PowerPC/builtins-ppc.c | 13 -
 clang/test/CodeGen/PowerPC/ppc-emmintrin.c|  5 ++
 clang/test/CodeGen/PowerPC/ppc-mmintrin.c |  5 ++
 clang/test/CodeGen/PowerPC/ppc-pmmintrin.c|  3 ++
 clang/test/CodeGen/PowerPC/ppc-smmintrin.c| 37 --
 clang/test/CodeGen/PowerPC/ppc-tmmintrin.c|  3 ++
 clang/test/CodeGen/PowerPC/ppc-x86gprintrin.c |  3 ++
 11 files changed, 99 insertions(+), 31 deletions(-)

diff --git a/clang/include/clang/Basic/BuiltinsPPC.def 
b/clang/include/clang/Basic/BuiltinsPPC.def
index 18a1186053481ed..a35488ed3dfa565 100644
--- a/clang/include/clang/Basic/BuiltinsPPC.def
+++ b/clang/include/clang/Basic/BuiltinsPPC.def
@@ -151,9 +151,11 @@ TARGET_BUILTIN(__builtin_ppc_extract_exp, "Uid", "", 
"power9-vector")
 TARGET_BUILTIN(__builtin_ppc_extract_sig, "ULLid", "", "power9-vector")
 BUILTIN(__builtin_ppc_mtfsb0, "vUIi", "")
 BUILTIN(__builtin_ppc_mtfsb1, "vUIi", "")
+BUILTIN(__builtin_ppc_mffs, "d", "")
 TARGET_BUILTIN(__builtin_ppc_mffsl, "d", "", "isa-v30-instructions")
 BUILTIN(__builtin_ppc_mtfsf, "vUIiUi", "")
 BUILTIN(__builtin_ppc_mtfsfi, "vUIiUIi", "")
+BUILTIN(__builtin_ppc_set_fpscr_rn, "di", "")
 TARGET_BUILTIN(__builtin_ppc_insert_exp, "ddULLi", "", "power9-vector")
 BUILTIN(__builtin_ppc_fmsub, "", "")
 BUILTIN(__builtin_ppc_fmsubs, "", "")
diff --git a/clang/lib/Basic/Targets/PPC.cpp b/clang/lib/Basic/Targets/PPC.cpp
index e0abc069032e1ce..34fe9df60cea473 100644
--- a/clang/lib/Basic/Targets/PPC.cpp
+++ b/clang/lib/Basic/Targets/PPC.cpp
@@ -264,6 +264,10 @@ static void defineXLCompatMacros(MacroBuilder &Builder) {
   Builder.defineMacro("__builtin_minfe", "__builtin_ppc_minfe");
   Builder.defineMacro("__builtin_minfl", "__builtin_ppc_minfl");
   Builder.defineMacro("__builtin_minfs", "__builtin_ppc_minfs");
+  Builder.defineMacro("__builtin_mffs", "__builtin_ppc_mffs");
+  Builder.defineMacro("__builtin_mffsl", "__builtin_ppc_mffsl");
+  Builder.defineMacro("__builtin_mtfsf", "__builtin_ppc_mtfsf");
+  Builder.defineMacro("__builtin_set_fpscr_rn", "__builtin_ppc_set_fpscr_rn");
 }
 
 /// PPCTargetInfo::getTargetDefines - Return a set of the PowerPC-specific
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index c175f274319b8c4..f64cb995fa1898a 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -17237,6 +17237,11 @@ Value *CodeGenFunction::EmitPPCBuiltinExpr(unsigned 
BuiltinID,
 Value *Op1 = EmitScalarExpr(E->getArg(1));
 return Builder.CreateFDiv(Op0, Op1, "swdiv");
   }
+  case PPC::BI__builtin_ppc_set_fpscr_rn:
+return Builder.CreateCall(CGM.getIntrinsic(Intrinsic::ppc_setrnd),
+  {EmitScalarExpr(E->getArg(0))});
+  case PPC::BI__builtin_ppc_mffs:
+return Builder.CreateCall(CGM.getIntrinsic(Intrinsic::ppc_readflm));
   }
 }
 
diff --git a/clang/lib/Headers/ppc_wrappers/smmintrin.h 
b/clang/lib/Headers/ppc_wrappers/smmintrin.h
index 349b395c4f00b92..19cdecb18d2b83f 100644
--- a/clang/lib/Headers/ppc_wrappers/smmintrin.h
+++ b/clang/lib/Headers/ppc_wrappers/smmintrin.h
@@ -14,7 +14,7 @@
 
 #ifndef NO_WARN_X86_INTRINSICS
 /* This header is distributed to simplify porting x86_64 code that
-   makes explicit use of Intel intrinsics to powerp64/powerpc64le.
+   makes explicit use of Intel intrinsics to powerpc64/powerpc64le.
 
It is the user's responsibility to determine if the results are
acceptable and make additional changes as necessary.
@@ -68,10 +68,10 @@ extern __inline __m128d
 __asm__("mffsce %0" : "=f"(__fpscr_save.__fr));
 __enables_save.__fpscr = __fpscr_save.__fpscr & 0xf8;
 #else
-__fpscr_save.__fr = __builtin_mffs();
+__fpscr_save.__fr = __builtin_ppc_mffs();
 __enables_save.__fpscr = __fpscr_save.__fpscr & 0xf8;
 __fpscr_save.__fpscr &= ~0xf8;
-__builtin_mtfsf(0b0011, __fpscr_save.__fr);
+__builtin_ppc_mtfsf(0b0011, __fpscr_save.__fr);
 #endif
 /* Insert an artificial "read/write" reference to the variable
read below, to ensure the c

[PATCH] D158066: [PowerPC] Fix use of FPSCR builtins in smmintrin.h

2023-09-25 Thread Qiu Chaofan via Phabricator via cfe-commits
qiucf abandoned this revision.
qiucf added a comment.

Migrated to https://github.com/llvm/llvm-project/pull/67299


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D158066/new/

https://reviews.llvm.org/D158066

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


[clang] [PowerPC] Fix use of FPSCR builtins in smmintrin.h (PR #67299)

2023-09-25 Thread Qiu Chaofan via cfe-commits

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


[clang] [clang][dataflow] Remove declarations from `DeclToLoc` when their lifetime ends. (PR #67300)

2023-09-25 Thread via cfe-commits

https://github.com/martinboehme created 
https://github.com/llvm/llvm-project/pull/67300

After https://reviews.llvm.org/D153273, we're now able to use `CFGLifetimeEnds`
together with the other CFG options we use.


>From baa1bbf7bfe684fc81b37fa3e1795170f5ee6156 Mon Sep 17 00:00:00 2001
From: Martin Braenne 
Date: Mon, 25 Sep 2023 09:07:34 +
Subject: [PATCH] [clang][dataflow] Remove declarations from `DeclToLoc` when
 their lifetime ends.

After https://reviews.llvm.org/D153273, we're now able to use `CFGLifetimeEnds`
together with the other CFG options we use.
---
 .../FlowSensitive/DataflowEnvironment.h   |  7 ++
 .../FlowSensitive/ControlFlowContext.cpp  |  1 +
 .../FlowSensitive/DataflowEnvironment.cpp | 24 +++
 .../TypeErasedDataflowAnalysis.cpp| 22 -
 .../Analysis/FlowSensitive/TransferTest.cpp   |  5 +---
 .../TypeErasedDataflowAnalysisTest.cpp|  3 ++-
 6 files changed, 41 insertions(+), 21 deletions(-)

diff --git a/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h 
b/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
index c128ee4ea85c928..73f747ff88cf447 100644
--- a/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
+++ b/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
@@ -260,6 +260,13 @@ class Environment {
   /// if `D` isn't assigned a storage location in the environment.
   StorageLocation *getStorageLocation(const ValueDecl &D) const;
 
+  /// Removes the location assigned to `D` in the environment.
+  ///
+  /// Requirements:
+  ///
+  ///  `D` must have a storage location assigned in the environment.
+  void removeDecl(const ValueDecl &D);
+
   /// Assigns `Loc` as the storage location of the glvalue `E` in the
   /// environment.
   ///
diff --git a/clang/lib/Analysis/FlowSensitive/ControlFlowContext.cpp 
b/clang/lib/Analysis/FlowSensitive/ControlFlowContext.cpp
index 004b7711a869d17..56246066e4aa13a 100644
--- a/clang/lib/Analysis/FlowSensitive/ControlFlowContext.cpp
+++ b/clang/lib/Analysis/FlowSensitive/ControlFlowContext.cpp
@@ -97,6 +97,7 @@ ControlFlowContext::build(const Decl &D, Stmt &S, ASTContext 
&C) {
   Options.AddTemporaryDtors = true;
   Options.AddInitializers = true;
   Options.AddCXXDefaultInitExprInCtors = true;
+  Options.AddLifetime = true;
 
   // Ensure that all sub-expressions in basic blocks are evaluated.
   Options.setAllAlwaysAdd();
diff --git a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp 
b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
index 9dc528567038ac4..1ea40927ac58adc 100644
--- a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -35,6 +35,20 @@ namespace dataflow {
 static constexpr int MaxCompositeValueDepth = 3;
 static constexpr int MaxCompositeValueSize = 1000;
 
+/// Returns whether all declarations that `DeclToLoc1` and `DeclToLoc2` have in
+/// common map to the same storage location in both maps.
+bool declToLocConsistent(
+const llvm::DenseMap &DeclToLoc1,
+const llvm::DenseMap &DeclToLoc2) {
+  for (auto &Entry : DeclToLoc1) {
+auto It = DeclToLoc2.find(Entry.first);
+if (It != DeclToLoc2.end() && Entry.second != It->second)
+  return false;
+  }
+
+  return true;
+}
+
 /// Returns a map consisting of key-value entries that are present in both 
maps.
 template 
 llvm::DenseMap intersectDenseMaps(const llvm::DenseMap &Map1,
@@ -636,10 +650,7 @@ Environment Environment::join(const Environment &EnvA, 
const Environment &EnvB,
   else
 JoinedEnv.ReturnLoc = nullptr;
 
-  // FIXME: Once we're able to remove declarations from `DeclToLoc` when their
-  // lifetime ends, add an assertion that there aren't any entries in
-  // `DeclToLoc` and `Other.DeclToLoc` that map the same declaration to
-  // different storage locations.
+  assert(declToLocConsistent(EnvA.DeclToLoc, EnvB.DeclToLoc));
   JoinedEnv.DeclToLoc = intersectDenseMaps(EnvA.DeclToLoc, EnvB.DeclToLoc);
 
   JoinedEnv.ExprToLoc = intersectDenseMaps(EnvA.ExprToLoc, EnvB.ExprToLoc);
@@ -691,6 +702,11 @@ StorageLocation *Environment::getStorageLocation(const 
ValueDecl &D) const {
   return Loc;
 }
 
+void Environment::removeDecl(const ValueDecl &D) {
+  assert(DeclToLoc.contains(&D));
+  DeclToLoc.erase(&D);
+}
+
 void Environment::setStorageLocation(const Expr &E, StorageLocation &Loc) {
   // `DeclRefExpr`s to builtin function types aren't glvalues, for some reason,
   // but we still want to be able to associate a `StorageLocation` with them,
diff --git a/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp 
b/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
index 01b397787430ac6..6b167891c1a3ac8 100644
--- a/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
+++ b/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
@@ -439,19 +439,17 @@ static void builtinTransfer(const CFGElement &Elt,

[clang] [PowerPC] Fix use of FPSCR builtins in smmintrin.h (PR #67299)

2023-09-25 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang


Changes

smmintrin.h uses __builtin_mffs, __builtin_mffsl, __builtin_mtfsf and 
__builtin_set_fpscr_rn. This patch replaces the uses with ppc prefix and 
implement the missing ones.

This fixes issue #64664.

Migrated from https://reviews.llvm.org/D158066

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


11 Files Affected:

- (modified) clang/include/clang/Basic/BuiltinsPPC.def (+2) 
- (modified) clang/lib/Basic/Targets/PPC.cpp (+4) 
- (modified) clang/lib/CodeGen/CGBuiltin.cpp (+5) 
- (modified) clang/lib/Headers/ppc_wrappers/smmintrin.h (+35-15) 
- (modified) clang/test/CodeGen/PowerPC/builtins-ppc.c (+11-2) 
- (modified) clang/test/CodeGen/PowerPC/ppc-emmintrin.c (+5) 
- (modified) clang/test/CodeGen/PowerPC/ppc-mmintrin.c (+5) 
- (modified) clang/test/CodeGen/PowerPC/ppc-pmmintrin.c (+3) 
- (modified) clang/test/CodeGen/PowerPC/ppc-smmintrin.c (+23-14) 
- (modified) clang/test/CodeGen/PowerPC/ppc-tmmintrin.c (+3) 
- (modified) clang/test/CodeGen/PowerPC/ppc-x86gprintrin.c (+3) 


``diff
diff --git a/clang/include/clang/Basic/BuiltinsPPC.def 
b/clang/include/clang/Basic/BuiltinsPPC.def
index 18a1186053481ed..a35488ed3dfa565 100644
--- a/clang/include/clang/Basic/BuiltinsPPC.def
+++ b/clang/include/clang/Basic/BuiltinsPPC.def
@@ -151,9 +151,11 @@ TARGET_BUILTIN(__builtin_ppc_extract_exp, "Uid", "", 
"power9-vector")
 TARGET_BUILTIN(__builtin_ppc_extract_sig, "ULLid", "", "power9-vector")
 BUILTIN(__builtin_ppc_mtfsb0, "vUIi", "")
 BUILTIN(__builtin_ppc_mtfsb1, "vUIi", "")
+BUILTIN(__builtin_ppc_mffs, "d", "")
 TARGET_BUILTIN(__builtin_ppc_mffsl, "d", "", "isa-v30-instructions")
 BUILTIN(__builtin_ppc_mtfsf, "vUIiUi", "")
 BUILTIN(__builtin_ppc_mtfsfi, "vUIiUIi", "")
+BUILTIN(__builtin_ppc_set_fpscr_rn, "di", "")
 TARGET_BUILTIN(__builtin_ppc_insert_exp, "ddULLi", "", "power9-vector")
 BUILTIN(__builtin_ppc_fmsub, "", "")
 BUILTIN(__builtin_ppc_fmsubs, "", "")
diff --git a/clang/lib/Basic/Targets/PPC.cpp b/clang/lib/Basic/Targets/PPC.cpp
index e0abc069032e1ce..34fe9df60cea473 100644
--- a/clang/lib/Basic/Targets/PPC.cpp
+++ b/clang/lib/Basic/Targets/PPC.cpp
@@ -264,6 +264,10 @@ static void defineXLCompatMacros(MacroBuilder &Builder) {
   Builder.defineMacro("__builtin_minfe", "__builtin_ppc_minfe");
   Builder.defineMacro("__builtin_minfl", "__builtin_ppc_minfl");
   Builder.defineMacro("__builtin_minfs", "__builtin_ppc_minfs");
+  Builder.defineMacro("__builtin_mffs", "__builtin_ppc_mffs");
+  Builder.defineMacro("__builtin_mffsl", "__builtin_ppc_mffsl");
+  Builder.defineMacro("__builtin_mtfsf", "__builtin_ppc_mtfsf");
+  Builder.defineMacro("__builtin_set_fpscr_rn", "__builtin_ppc_set_fpscr_rn");
 }
 
 /// PPCTargetInfo::getTargetDefines - Return a set of the PowerPC-specific
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index c175f274319b8c4..f64cb995fa1898a 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -17237,6 +17237,11 @@ Value *CodeGenFunction::EmitPPCBuiltinExpr(unsigned 
BuiltinID,
 Value *Op1 = EmitScalarExpr(E->getArg(1));
 return Builder.CreateFDiv(Op0, Op1, "swdiv");
   }
+  case PPC::BI__builtin_ppc_set_fpscr_rn:
+return Builder.CreateCall(CGM.getIntrinsic(Intrinsic::ppc_setrnd),
+  {EmitScalarExpr(E->getArg(0))});
+  case PPC::BI__builtin_ppc_mffs:
+return Builder.CreateCall(CGM.getIntrinsic(Intrinsic::ppc_readflm));
   }
 }
 
diff --git a/clang/lib/Headers/ppc_wrappers/smmintrin.h 
b/clang/lib/Headers/ppc_wrappers/smmintrin.h
index 349b395c4f00b92..19cdecb18d2b83f 100644
--- a/clang/lib/Headers/ppc_wrappers/smmintrin.h
+++ b/clang/lib/Headers/ppc_wrappers/smmintrin.h
@@ -14,7 +14,7 @@
 
 #ifndef NO_WARN_X86_INTRINSICS
 /* This header is distributed to simplify porting x86_64 code that
-   makes explicit use of Intel intrinsics to powerp64/powerpc64le.
+   makes explicit use of Intel intrinsics to powerpc64/powerpc64le.
 
It is the user's responsibility to determine if the results are
acceptable and make additional changes as necessary.
@@ -68,10 +68,10 @@ extern __inline __m128d
 __asm__("mffsce %0" : "=f"(__fpscr_save.__fr));
 __enables_save.__fpscr = __fpscr_save.__fpscr & 0xf8;
 #else
-__fpscr_save.__fr = __builtin_mffs();
+__fpscr_save.__fr = __builtin_ppc_mffs();
 __enables_save.__fpscr = __fpscr_save.__fpscr & 0xf8;
 __fpscr_save.__fpscr &= ~0xf8;
-__builtin_mtfsf(0b0011, __fpscr_save.__fr);
+__builtin_ppc_mtfsf(0b0011, __fpscr_save.__fr);
 #endif
 /* Insert an artificial "read/write" reference to the variable
read below, to ensure the compiler does not schedule
@@ -83,10 +83,15 @@ extern __inline __m128d
 
   switch (__rounding) {
   case _MM_FROUND_TO_NEAREST_INT:
-__fpscr_save.__fr = __builtin_mffsl();
+#ifdef _ARCH_PWR9
+__fpscr_save.__fr = __builtin_ppc_mffsl();
+#else
+__fpscr_save.__fr = __builtin_ppc_mffs

[clang] Introduce paged vector (PR #66430)

2023-09-25 Thread via cfe-commits

github-actions[bot] wrote:




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



You can test this locally with the following command:


``bash
git-clang-format --diff af199ee00db0796bd007e768d9056447d9bef999 
b5f984b5521c5b226a7c5297d19eb53953481890 -- llvm/include/llvm/ADT/PagedVector.h 
llvm/unittests/ADT/PagedVectorTest.cpp 
clang/include/clang/Basic/SourceManager.h 
clang/include/clang/Serialization/ASTReader.h clang/lib/Basic/SourceManager.cpp 
clang/lib/Serialization/ASTReader.cpp
``





View the diff from clang-format here.


``diff
diff --git a/llvm/include/llvm/ADT/PagedVector.h 
b/llvm/include/llvm/ADT/PagedVector.h
index 35a9f5216b83..3f8d8c02376d 100644
--- a/llvm/include/llvm/ADT/PagedVector.h
+++ b/llvm/include/llvm/ADT/PagedVector.h
@@ -74,7 +74,8 @@ public:
 
   /// Look up an element at position `Index`.
   /// If the associated page is not filled, it will be filled with default
-  /// constructed elements. If the associated page is filled, return the 
element.
+  /// constructed elements. If the associated page is filled, return the
+  /// element.
   T &operator[](size_t Index) const {
 assert(Index < Size);
 assert(Index / PageSize < PageToDataPtrs.size());
@@ -93,8 +94,8 @@ public:
 return *((Index % PageSize) + PagePtr);
   }
 
-  /// Return the capacity of the vector. I.e. the maximum size it can be 
expanded
-  /// to with the resize method without allocating more pages.
+  /// Return the capacity of the vector. I.e. the maximum size it can be
+  /// expanded to with the resize method without allocating more pages.
   [[nodiscard]] size_t capacity() const {
 return PageToDataPtrs.size() * PageSize;
   }

``




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


[clang] [clang][dataflow] Remove declarations from `DeclToLoc` when their lifetime ends. (PR #67300)

2023-09-25 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-analysis


Changes

After https://reviews.llvm.org/D153273, we're now able to use `CFGLifetimeEnds`
together with the other CFG options we use.


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


6 Files Affected:

- (modified) clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h 
(+7) 
- (modified) clang/lib/Analysis/FlowSensitive/ControlFlowContext.cpp (+1) 
- (modified) clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp (+20-4) 
- (modified) clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp 
(+10-12) 
- (modified) clang/unittests/Analysis/FlowSensitive/TransferTest.cpp (+1-4) 
- (modified) 
clang/unittests/Analysis/FlowSensitive/TypeErasedDataflowAnalysisTest.cpp 
(+2-1) 


``diff
diff --git a/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h 
b/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
index c128ee4ea85c928..73f747ff88cf447 100644
--- a/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
+++ b/clang/include/clang/Analysis/FlowSensitive/DataflowEnvironment.h
@@ -260,6 +260,13 @@ class Environment {
   /// if `D` isn't assigned a storage location in the environment.
   StorageLocation *getStorageLocation(const ValueDecl &D) const;
 
+  /// Removes the location assigned to `D` in the environment.
+  ///
+  /// Requirements:
+  ///
+  ///  `D` must have a storage location assigned in the environment.
+  void removeDecl(const ValueDecl &D);
+
   /// Assigns `Loc` as the storage location of the glvalue `E` in the
   /// environment.
   ///
diff --git a/clang/lib/Analysis/FlowSensitive/ControlFlowContext.cpp 
b/clang/lib/Analysis/FlowSensitive/ControlFlowContext.cpp
index 004b7711a869d17..56246066e4aa13a 100644
--- a/clang/lib/Analysis/FlowSensitive/ControlFlowContext.cpp
+++ b/clang/lib/Analysis/FlowSensitive/ControlFlowContext.cpp
@@ -97,6 +97,7 @@ ControlFlowContext::build(const Decl &D, Stmt &S, ASTContext 
&C) {
   Options.AddTemporaryDtors = true;
   Options.AddInitializers = true;
   Options.AddCXXDefaultInitExprInCtors = true;
+  Options.AddLifetime = true;
 
   // Ensure that all sub-expressions in basic blocks are evaluated.
   Options.setAllAlwaysAdd();
diff --git a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp 
b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
index 9dc528567038ac4..1ea40927ac58adc 100644
--- a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -35,6 +35,20 @@ namespace dataflow {
 static constexpr int MaxCompositeValueDepth = 3;
 static constexpr int MaxCompositeValueSize = 1000;
 
+/// Returns whether all declarations that `DeclToLoc1` and `DeclToLoc2` have in
+/// common map to the same storage location in both maps.
+bool declToLocConsistent(
+const llvm::DenseMap &DeclToLoc1,
+const llvm::DenseMap &DeclToLoc2) {
+  for (auto &Entry : DeclToLoc1) {
+auto It = DeclToLoc2.find(Entry.first);
+if (It != DeclToLoc2.end() && Entry.second != It->second)
+  return false;
+  }
+
+  return true;
+}
+
 /// Returns a map consisting of key-value entries that are present in both 
maps.
 template 
 llvm::DenseMap intersectDenseMaps(const llvm::DenseMap &Map1,
@@ -636,10 +650,7 @@ Environment Environment::join(const Environment &EnvA, 
const Environment &EnvB,
   else
 JoinedEnv.ReturnLoc = nullptr;
 
-  // FIXME: Once we're able to remove declarations from `DeclToLoc` when their
-  // lifetime ends, add an assertion that there aren't any entries in
-  // `DeclToLoc` and `Other.DeclToLoc` that map the same declaration to
-  // different storage locations.
+  assert(declToLocConsistent(EnvA.DeclToLoc, EnvB.DeclToLoc));
   JoinedEnv.DeclToLoc = intersectDenseMaps(EnvA.DeclToLoc, EnvB.DeclToLoc);
 
   JoinedEnv.ExprToLoc = intersectDenseMaps(EnvA.ExprToLoc, EnvB.ExprToLoc);
@@ -691,6 +702,11 @@ StorageLocation *Environment::getStorageLocation(const 
ValueDecl &D) const {
   return Loc;
 }
 
+void Environment::removeDecl(const ValueDecl &D) {
+  assert(DeclToLoc.contains(&D));
+  DeclToLoc.erase(&D);
+}
+
 void Environment::setStorageLocation(const Expr &E, StorageLocation &Loc) {
   // `DeclRefExpr`s to builtin function types aren't glvalues, for some reason,
   // but we still want to be able to associate a `StorageLocation` with them,
diff --git a/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp 
b/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
index 01b397787430ac6..6b167891c1a3ac8 100644
--- a/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
+++ b/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
@@ -439,19 +439,17 @@ static void builtinTransfer(const CFGElement &Elt,
   case CFGElement::Initializer:
 builtinTransferInitializer(Elt.castAs(), State);
 break;
+  case CFGElement::LifetimeEnds:
+// Removing declarations when their lifetime ends serves two

[clang] [clang][CodeGen] Simplify code based on opaque pointers (PR #65624)

2023-09-25 Thread Björn Pettersson via cfe-commits

https://github.com/bjope updated https://github.com/llvm/llvm-project/pull/65624

From caa626ea4e813c7061b44f6b4336f31fce511f4b Mon Sep 17 00:00:00 2001
From: Bjorn Pettersson 
Date: Thu, 7 Sep 2023 13:08:22 +0200
Subject: [PATCH] [clang][CodeGen] Simplify code based on opaque pointers

- Update CodeGenTypeCache to use a single union for all pointers in
  address space zero.
- Introduce a UnqualPtrTy in CodeGenTypeCache, and use that (for
  example instead of llvm::PointerType::getUnqual) in some places.
- Drop some redundant bit/pointers casts from ptr to ptr.
---
 clang/lib/CodeGen/CGAtomic.cpp|  3 +-
 clang/lib/CodeGen/CGBlocks.cpp| 20 ++
 clang/lib/CodeGen/CGBuiltin.cpp   | 99 ---
 clang/lib/CodeGen/CGCUDANV.cpp|  9 +--
 clang/lib/CodeGen/CGExpr.cpp  |  4 +-
 clang/lib/CodeGen/CGObjCRuntime.cpp   |  4 +-
 clang/lib/CodeGen/CGOpenCLRuntime.cpp | 16 ++---
 clang/lib/CodeGen/CodeGenModule.cpp   | 13 ++--
 clang/lib/CodeGen/CodeGenTypeCache.h  |  7 +-
 clang/lib/CodeGen/ItaniumCXXABI.cpp   | 39 +--
 clang/lib/CodeGen/Targets/PPC.cpp |  2 +-
 clang/lib/CodeGen/Targets/Sparc.cpp   |  2 +-
 clang/lib/CodeGen/Targets/X86.cpp | 10 +--
 13 files changed, 81 insertions(+), 147 deletions(-)

diff --git a/clang/lib/CodeGen/CGAtomic.cpp b/clang/lib/CodeGen/CGAtomic.cpp
index 222b0a192c85e20..83ad6739015b8d2 100644
--- a/clang/lib/CodeGen/CGAtomic.cpp
+++ b/clang/lib/CodeGen/CGAtomic.cpp
@@ -87,8 +87,7 @@ namespace {
 llvm::Value *StoragePtr = CGF.Builder.CreateConstGEP1_64(
 CGF.Int8Ty, BitFieldPtr, OffsetInChars.getQuantity());
 StoragePtr = CGF.Builder.CreateAddrSpaceCast(
-StoragePtr, llvm::PointerType::getUnqual(CGF.getLLVMContext()),
-"atomic_bitfield_base");
+StoragePtr, CGF.UnqualPtrTy, "atomic_bitfield_base");
 BFI = OrigBFI;
 BFI.Offset = Offset;
 BFI.StorageSize = AtomicSizeInBits;
diff --git a/clang/lib/CodeGen/CGBlocks.cpp b/clang/lib/CodeGen/CGBlocks.cpp
index 4f64012fc1a5c39..aa3e730d28efae5 100644
--- a/clang/lib/CodeGen/CGBlocks.cpp
+++ b/clang/lib/CodeGen/CGBlocks.cpp
@@ -1189,8 +1189,8 @@ RValue CodeGenFunction::EmitBlockCallExpr(const CallExpr 
*E,
 }
   } else {
 // Bitcast the block literal to a generic block literal.
-BlockPtr = Builder.CreatePointerCast(
-BlockPtr, llvm::PointerType::get(GenBlockTy, 0), "block.literal");
+BlockPtr =
+Builder.CreatePointerCast(BlockPtr, UnqualPtrTy, "block.literal");
 // Get pointer to the block invoke function
 llvm::Value *FuncPtr = Builder.CreateStructGEP(GenBlockTy, BlockPtr, 3);
 
@@ -1208,12 +1208,6 @@ RValue CodeGenFunction::EmitBlockCallExpr(const CallExpr 
*E,
   const CGFunctionInfo &FnInfo =
 CGM.getTypes().arrangeBlockFunctionCall(Args, FuncTy);
 
-  // Cast the function pointer to the right type.
-  llvm::Type *BlockFTy = CGM.getTypes().GetFunctionType(FnInfo);
-
-  llvm::Type *BlockFTyPtr = llvm::PointerType::getUnqual(BlockFTy);
-  Func = Builder.CreatePointerCast(Func, BlockFTyPtr);
-
   // Prepare the callee.
   CGCallee Callee(CGCalleeInfo(), Func);
 
@@ -2589,11 +2583,11 @@ const BlockByrefInfo 
&CodeGenFunction::getBlockByrefInfo(const VarDecl *D) {
   SmallVector types;
 
   // void *__isa;
-  types.push_back(Int8PtrTy);
+  types.push_back(VoidPtrTy);
   size += getPointerSize();
 
   // void *__forwarding;
-  types.push_back(llvm::PointerType::getUnqual(byrefType));
+  types.push_back(VoidPtrTy);
   size += getPointerSize();
 
   // int32_t __flags;
@@ -2608,11 +2602,11 @@ const BlockByrefInfo 
&CodeGenFunction::getBlockByrefInfo(const VarDecl *D) {
   bool hasCopyAndDispose = getContext().BlockRequiresCopying(Ty, D);
   if (hasCopyAndDispose) {
 /// void *__copy_helper;
-types.push_back(Int8PtrTy);
+types.push_back(VoidPtrTy);
 size += getPointerSize();
 
 /// void *__destroy_helper;
-types.push_back(Int8PtrTy);
+types.push_back(VoidPtrTy);
 size += getPointerSize();
   }
 
@@ -2621,7 +2615,7 @@ const BlockByrefInfo 
&CodeGenFunction::getBlockByrefInfo(const VarDecl *D) {
   if (getContext().getByrefLifetime(Ty, Lifetime, HasByrefExtendedLayout) &&
   HasByrefExtendedLayout) {
 /// void *__byref_variable_layout;
-types.push_back(Int8PtrTy);
+types.push_back(VoidPtrTy);
 size += CharUnits::fromQuantity(PointerSizeInBytes);
   }
 
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index c175f274319b8c4..d14cf0dccb09982 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -978,9 +978,8 @@ static llvm::Value *EmitX86BitTestIntrinsic(CodeGenFunction 
&CGF,
   llvm::IntegerType *IntType = llvm::IntegerType::get(
   CGF.getLLVMContext(),
   CGF.getContext().getTypeSize(E->getArg(1)->getType()));
-  llvm::Type *PtrType = llvm::PointerType::getUnqual(CGF.getLLVMContext());
   llvm::FunctionType *FTy =
-  llvm::Funct

[clang] [llvm][tblgen] Add `SourcePath` for `emitSourceFileHeader` (PR #65744)

2023-09-25 Thread Shao-Ce SUN via cfe-commits

sunshaoce wrote:

> ⚠️ C/C++ code formatter, clang-format found issues in your code. ⚠️
> 
> You can test this locally with the following command:
> ```shell
> git-clang-format --diff b8b4ee6b450766796b162b4811a6b3f723d07268 
> d07486764071679c8cbcd5e7c4905eb41b4770b3 -- 
> clang/utils/TableGen/ClangASTNodesEmitter.cpp 
> clang/utils/TableGen/ClangASTPropertiesEmitter.cpp 
> clang/utils/TableGen/ClangAttrEmitter.cpp 
> clang/utils/TableGen/ClangCommentCommandInfoEmitter.cpp 
> clang/utils/TableGen/ClangCommentHTMLNamedCharacterReferenceEmitter.cpp 
> clang/utils/TableGen/ClangCommentHTMLTagsEmitter.cpp 
> clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp 
> clang/utils/TableGen/ClangSyntaxEmitter.cpp 
> clang/utils/TableGen/ClangTypeNodesEmitter.cpp 
> lldb/utils/TableGen/LLDBOptionDefEmitter.cpp 
> lldb/utils/TableGen/LLDBPropertyDefEmitter.cpp 
> llvm/include/llvm/TableGen/TableGenBackend.h 
> llvm/lib/TableGen/TableGenBackend.cpp 
> llvm/utils/TableGen/AsmMatcherEmitter.cpp 
> llvm/utils/TableGen/AsmWriterEmitter.cpp llvm/utils/TableGen/VTEmitter.cpp 
> mlir/tools/mlir-tblgen/DialectGen.cpp mlir/tools/mlir-tblgen/EnumsGen.cpp 
> mlir/tools/mlir-tblgen/LLVMIRIntrinsicGen.cpp 
> mlir/tools/mlir-tblgen/OpDefinitionsGen.cpp 
> mlir/tools/mlir-tblgen/RewriterGen.cpp 
> mlir/tools/mlir-tblgen/SPIRVUtilsGen.cpp
> ```
> 
> View the diff from clang-format here.
> ```diff
> diff --git a/clang/utils/TableGen/ClangAttrEmitter.cpp 
> b/clang/utils/TableGen/ClangAttrEmitter.cpp
> index 6ba82a22df1e..dddc9b9896ef 100644
> --- a/clang/utils/TableGen/ClangAttrEmitter.cpp
> +++ b/clang/utils/TableGen/ClangAttrEmitter.cpp
> @@ -3170,27 +3170,27 @@ namespace clang {
>  
>  // Emits the enumeration list for attributes.
>  void EmitClangAttrList(RecordKeeper &Records, raw_ostream &OS) {
> -  emitSourceFileHeader("List of all attributes that Clang recognizes", OS,
> -   Records);
> +emitSourceFileHeader("List of all attributes that Clang recognizes", OS,
> + Records);
>  
> -  AttrClassHierarchy Hierarchy(Records);
> +AttrClassHierarchy Hierarchy(Records);
>  
> -  // Add defaulting macro definitions.
> -  Hierarchy.emitDefaultDefines(OS);
> -  emitDefaultDefine(OS, "PRAGMA_SPELLING_ATTR", nullptr);
> +// Add defaulting macro definitions.
> +Hierarchy.emitDefaultDefines(OS);
> +emitDefaultDefine(OS, "PRAGMA_SPELLING_ATTR", nullptr);
>  
> -  std::vector Attrs = Records.getAllDerivedDefinitions("Attr");
> -  std::vector PragmaAttrs;
> -  for (auto *Attr : Attrs) {
> -if (!Attr->getValueAsBit("ASTNode"))
> -  continue;
> +std::vector Attrs = Records.getAllDerivedDefinitions("Attr");
> +std::vector PragmaAttrs;
> +for (auto *Attr : Attrs) {
> +  if (!Attr->getValueAsBit("ASTNode"))
> +continue;
>  
> -// Add the attribute to the ad-hoc groups.
> -if (AttrHasPragmaSpelling(Attr))
> -  PragmaAttrs.push_back(Attr);
> +  // Add the attribute to the ad-hoc groups.
> +  if (AttrHasPragmaSpelling(Attr))
> +PragmaAttrs.push_back(Attr);
>  
> -// Place it in the hierarchy.
> -Hierarchy.classifyAttr(Attr);
> +  // Place it in the hierarchy.
> +  Hierarchy.classifyAttr(Attr);
>}
>  
>// Emit the main attribute list.
> ```

Is this suggestion correct?

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


[clang] [clang][CodeGen] Simplify code based on opaque pointers (PR #65624)

2023-09-25 Thread Björn Pettersson via cfe-commits

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


[clang] b4858c6 - [clang][CodeGen] Simplify code based on opaque pointers (#65624)

2023-09-25 Thread via cfe-commits

Author: Björn Pettersson
Date: 2023-09-25T11:21:24+02:00
New Revision: b4858c634e35e70627d59f5070d4ddcd8604e4f3

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

LOG: [clang][CodeGen] Simplify code based on opaque pointers (#65624)

- Update CodeGenTypeCache to use a single union for all pointers in
  address space zero.
- Introduce a UnqualPtrTy in CodeGenTypeCache, and use that (for
  example instead of llvm::PointerType::getUnqual) in some places.
- Drop some redundant bit/pointers casts from ptr to ptr.

Added: 


Modified: 
clang/lib/CodeGen/CGAtomic.cpp
clang/lib/CodeGen/CGBlocks.cpp
clang/lib/CodeGen/CGBuiltin.cpp
clang/lib/CodeGen/CGCUDANV.cpp
clang/lib/CodeGen/CGExpr.cpp
clang/lib/CodeGen/CGObjCRuntime.cpp
clang/lib/CodeGen/CGOpenCLRuntime.cpp
clang/lib/CodeGen/CodeGenModule.cpp
clang/lib/CodeGen/CodeGenTypeCache.h
clang/lib/CodeGen/ItaniumCXXABI.cpp
clang/lib/CodeGen/Targets/PPC.cpp
clang/lib/CodeGen/Targets/Sparc.cpp
clang/lib/CodeGen/Targets/X86.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGAtomic.cpp b/clang/lib/CodeGen/CGAtomic.cpp
index 222b0a192c85e20..83ad6739015b8d2 100644
--- a/clang/lib/CodeGen/CGAtomic.cpp
+++ b/clang/lib/CodeGen/CGAtomic.cpp
@@ -87,8 +87,7 @@ namespace {
 llvm::Value *StoragePtr = CGF.Builder.CreateConstGEP1_64(
 CGF.Int8Ty, BitFieldPtr, OffsetInChars.getQuantity());
 StoragePtr = CGF.Builder.CreateAddrSpaceCast(
-StoragePtr, llvm::PointerType::getUnqual(CGF.getLLVMContext()),
-"atomic_bitfield_base");
+StoragePtr, CGF.UnqualPtrTy, "atomic_bitfield_base");
 BFI = OrigBFI;
 BFI.Offset = Offset;
 BFI.StorageSize = AtomicSizeInBits;

diff  --git a/clang/lib/CodeGen/CGBlocks.cpp b/clang/lib/CodeGen/CGBlocks.cpp
index 4f64012fc1a5c39..aa3e730d28efae5 100644
--- a/clang/lib/CodeGen/CGBlocks.cpp
+++ b/clang/lib/CodeGen/CGBlocks.cpp
@@ -1189,8 +1189,8 @@ RValue CodeGenFunction::EmitBlockCallExpr(const CallExpr 
*E,
 }
   } else {
 // Bitcast the block literal to a generic block literal.
-BlockPtr = Builder.CreatePointerCast(
-BlockPtr, llvm::PointerType::get(GenBlockTy, 0), "block.literal");
+BlockPtr =
+Builder.CreatePointerCast(BlockPtr, UnqualPtrTy, "block.literal");
 // Get pointer to the block invoke function
 llvm::Value *FuncPtr = Builder.CreateStructGEP(GenBlockTy, BlockPtr, 3);
 
@@ -1208,12 +1208,6 @@ RValue CodeGenFunction::EmitBlockCallExpr(const CallExpr 
*E,
   const CGFunctionInfo &FnInfo =
 CGM.getTypes().arrangeBlockFunctionCall(Args, FuncTy);
 
-  // Cast the function pointer to the right type.
-  llvm::Type *BlockFTy = CGM.getTypes().GetFunctionType(FnInfo);
-
-  llvm::Type *BlockFTyPtr = llvm::PointerType::getUnqual(BlockFTy);
-  Func = Builder.CreatePointerCast(Func, BlockFTyPtr);
-
   // Prepare the callee.
   CGCallee Callee(CGCalleeInfo(), Func);
 
@@ -2589,11 +2583,11 @@ const BlockByrefInfo 
&CodeGenFunction::getBlockByrefInfo(const VarDecl *D) {
   SmallVector types;
 
   // void *__isa;
-  types.push_back(Int8PtrTy);
+  types.push_back(VoidPtrTy);
   size += getPointerSize();
 
   // void *__forwarding;
-  types.push_back(llvm::PointerType::getUnqual(byrefType));
+  types.push_back(VoidPtrTy);
   size += getPointerSize();
 
   // int32_t __flags;
@@ -2608,11 +2602,11 @@ const BlockByrefInfo 
&CodeGenFunction::getBlockByrefInfo(const VarDecl *D) {
   bool hasCopyAndDispose = getContext().BlockRequiresCopying(Ty, D);
   if (hasCopyAndDispose) {
 /// void *__copy_helper;
-types.push_back(Int8PtrTy);
+types.push_back(VoidPtrTy);
 size += getPointerSize();
 
 /// void *__destroy_helper;
-types.push_back(Int8PtrTy);
+types.push_back(VoidPtrTy);
 size += getPointerSize();
   }
 
@@ -2621,7 +2615,7 @@ const BlockByrefInfo 
&CodeGenFunction::getBlockByrefInfo(const VarDecl *D) {
   if (getContext().getByrefLifetime(Ty, Lifetime, HasByrefExtendedLayout) &&
   HasByrefExtendedLayout) {
 /// void *__byref_variable_layout;
-types.push_back(Int8PtrTy);
+types.push_back(VoidPtrTy);
 size += CharUnits::fromQuantity(PointerSizeInBytes);
   }
 

diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index c175f274319b8c4..d14cf0dccb09982 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -978,9 +978,8 @@ static llvm::Value *EmitX86BitTestIntrinsic(CodeGenFunction 
&CGF,
   llvm::IntegerType *IntType = llvm::IntegerType::get(
   CGF.getLLVMContext(),
   CGF.getContext().getTypeSize(E->getArg(1)->getType()));
-  llvm::Type *PtrType = llvm::PointerType::getUnqual(CGF.getLLVMContext());
   llvm::FunctionType *FTy =
-  llvm::FunctionType

[clang] Introduce paged vector (PR #66430)

2023-09-25 Thread Giulio Eulisse via cfe-commits

https://github.com/ktf updated https://github.com/llvm/llvm-project/pull/66430

>From 1512bc16040e1015b6f8ed2b51ed8efb7fd97b8e Mon Sep 17 00:00:00 2001
From: Giulio Eulisse <10544+...@users.noreply.github.com>
Date: Thu, 14 Sep 2023 21:58:21 +0200
Subject: [PATCH] Introduce PagedVector class

The goal of the class is to be an (almost) drop in replacement for
SmallVector and std::vector when those are presized and filled later,
as it happens in SourceManager and ASTReader.

By splitting the actual vector in pages of the same size and allocating
the pages only when they are needed, using this containers reduces the
memory usage by a factor 4 for the cases relevant to the ALICE
experiment ROOT / cling usage.
---
 clang/include/clang/Basic/SourceManager.h |   3 +-
 clang/include/clang/Serialization/ASTReader.h |   5 +-
 clang/lib/Basic/SourceManager.cpp |  10 +-
 clang/lib/Serialization/ASTReader.cpp |   5 +-
 llvm/docs/ProgrammersManual.rst   |  33 ++
 llvm/include/llvm/ADT/PagedVector.h   | 317 
 llvm/unittests/ADT/CMakeLists.txt |   1 +
 llvm/unittests/ADT/PagedVectorTest.cpp| 342 ++
 8 files changed, 706 insertions(+), 10 deletions(-)
 create mode 100644 llvm/include/llvm/ADT/PagedVector.h
 create mode 100644 llvm/unittests/ADT/PagedVectorTest.cpp

diff --git a/clang/include/clang/Basic/SourceManager.h 
b/clang/include/clang/Basic/SourceManager.h
index 2f846502d6f3327..e37caa2252532f9 100644
--- a/clang/include/clang/Basic/SourceManager.h
+++ b/clang/include/clang/Basic/SourceManager.h
@@ -43,6 +43,7 @@
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/DenseSet.h"
 #include "llvm/ADT/IntrusiveRefCntPtr.h"
+#include "llvm/ADT/PagedVector.h"
 #include "llvm/ADT/PointerIntPair.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
@@ -699,7 +700,7 @@ class SourceManager : public RefCountedBase {
   ///
   /// Negative FileIDs are indexes into this table. To get from ID to an index,
   /// use (-ID - 2).
-  SmallVector LoadedSLocEntryTable;
+  llvm::PagedVector LoadedSLocEntryTable;
 
   /// The starting offset of the next local SLocEntry.
   ///
diff --git a/clang/include/clang/Serialization/ASTReader.h 
b/clang/include/clang/Serialization/ASTReader.h
index dc1eb21c27801fe..65e19c6e44cf571 100644
--- a/clang/include/clang/Serialization/ASTReader.h
+++ b/clang/include/clang/Serialization/ASTReader.h
@@ -38,6 +38,7 @@
 #include "llvm/ADT/DenseSet.h"
 #include "llvm/ADT/IntrusiveRefCntPtr.h"
 #include "llvm/ADT/MapVector.h"
+#include "llvm/ADT/PagedVector.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SetVector.h"
 #include "llvm/ADT/SmallPtrSet.h"
@@ -487,7 +488,7 @@ class ASTReader
   ///
   /// When the pointer at index I is non-NULL, the type with
   /// ID = (I + 1) << FastQual::Width has already been loaded
-  std::vector TypesLoaded;
+  llvm::PagedVector TypesLoaded;
 
   using GlobalTypeMapType =
   ContinuousRangeMap;
@@ -501,7 +502,7 @@ class ASTReader
   ///
   /// When the pointer at index I is non-NULL, the declaration with ID
   /// = I + 1 has already been loaded.
-  std::vector DeclsLoaded;
+  llvm::PagedVector DeclsLoaded;
 
   using GlobalDeclMapType =
   ContinuousRangeMap;
diff --git a/clang/lib/Basic/SourceManager.cpp 
b/clang/lib/Basic/SourceManager.cpp
index 0521ac7b30339ab..7fa8b8096ac4931 100644
--- a/clang/lib/Basic/SourceManager.cpp
+++ b/clang/lib/Basic/SourceManager.cpp
@@ -2344,11 +2344,11 @@ SourceManager::MemoryBufferSizes 
SourceManager::getMemoryBufferSizes() const {
 }
 
 size_t SourceManager::getDataStructureSizes() const {
-  size_t size = llvm::capacity_in_bytes(MemBufferInfos)
-+ llvm::capacity_in_bytes(LocalSLocEntryTable)
-+ llvm::capacity_in_bytes(LoadedSLocEntryTable)
-+ llvm::capacity_in_bytes(SLocEntryLoaded)
-+ llvm::capacity_in_bytes(FileInfos);
+  size_t size = llvm::capacity_in_bytes(MemBufferInfos) +
+llvm::capacity_in_bytes(LocalSLocEntryTable) +
+llvm::capacity_in_bytes(LoadedSLocEntryTable) +
+llvm::capacity_in_bytes(SLocEntryLoaded) +
+llvm::capacity_in_bytes(FileInfos);
 
   if (OverriddenFilesInfo)
 size += llvm::capacity_in_bytes(OverriddenFilesInfo->OverriddenFiles);
diff --git a/clang/lib/Serialization/ASTReader.cpp 
b/clang/lib/Serialization/ASTReader.cpp
index 0952244d037a77c..badd54987af18dd 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -7944,9 +7944,10 @@ void ASTReader::PrintStats() {
   std::fprintf(stderr, "*** AST File Statistics:\n");
 
   unsigned NumTypesLoaded =
-  TypesLoaded.size() - llvm::count(TypesLoaded, QualType());
+  TypesLoaded.size() - llvm::count(TypesLoaded.materialised(), QualType());
   unsigned NumDeclsLoaded =
-  DeclsLoaded.size() - llvm::count(DeclsLoaded, (Decl *)nullptr);
+  DeclsLoaded.size() -
+  llvm::count(DeclsLoaded.materialised(), (

[clang] Introduce paged vector (PR #66430)

2023-09-25 Thread Giulio Eulisse via cfe-commits

ktf wrote:

I am afraid I will need a bit of the to fix the C2248 from Visual Studio. 

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


[clang] [clang][Interp] Implement compound assign operators on bitfields (PR #67306)

2023-09-25 Thread Timm Baeder via cfe-commits
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= 
Message-ID: 
In-Reply-To:


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

None

>From 2cd32e94dd4eb194fd70b481f50eeaa2b6f72b66 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Wed, 13 Sep 2023 14:11:00 +0200
Subject: [PATCH 1/3] [clang] Avoid evaluating the BitWidth expression over and
 over again

It's usually a ConstantExpr with a saved constant integer anyway, so we
can just return that.
---
 clang/lib/AST/Decl.cpp | 8 
 1 file changed, 8 insertions(+)

diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp
index 08ae2087cfe70eb..e283f921905b4eb 100644
--- a/clang/lib/AST/Decl.cpp
+++ b/clang/lib/AST/Decl.cpp
@@ -4471,6 +4471,14 @@ void 
FieldDecl::setLazyInClassInitializer(LazyDeclStmtPtr NewInit) {
 
 unsigned FieldDecl::getBitWidthValue(const ASTContext &Ctx) const {
   assert(isBitField() && "not a bitfield");
+
+  // Try to avoid evaluating the expression in the overwhelmingly
+  // common case that we have a ConstantExpr.
+  if (const auto *CE = dyn_cast(getBitWidth())) {
+assert(CE->hasAPValueResult());
+return CE->getResultAsAPSInt().getZExtValue();
+  }
+
   return getBitWidth()->EvaluateKnownConstInt(Ctx).getZExtValue();
 }
 

>From 7c502534c4062d6f2126b57d105cfde1b72f7b67 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Thu, 10 Aug 2023 09:19:05 +0200
Subject: [PATCH 2/3] [clang][Interp] Basic support for bit fields

Differential Revision: https://reviews.llvm.org/D155270
---
 clang/lib/AST/Interp/ByteCodeExprGen.cpp | 17 +++--
 clang/lib/AST/Interp/ByteCodeStmtGen.cpp |  9 -
 clang/lib/AST/Interp/Interp.h| 14 +++
 clang/lib/AST/Interp/Record.h|  1 +
 clang/test/AST/Interp/bitfields.cpp  | 47 
 5 files changed, 75 insertions(+), 13 deletions(-)
 create mode 100644 clang/test/AST/Interp/bitfields.cpp

diff --git a/clang/lib/AST/Interp/ByteCodeExprGen.cpp 
b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
index e813d4fa651ceaf..cb3cfd835ad01df 100644
--- a/clang/lib/AST/Interp/ByteCodeExprGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeExprGen.cpp
@@ -316,8 +316,10 @@ bool ByteCodeExprGen::VisitBinaryOperator(const 
BinaryOperator *BO) {
 return Discard(this->emitDiv(*T, BO));
   case BO_Assign:
 if (DiscardResult)
-  return this->emitStorePop(*T, BO);
-return this->emitStore(*T, BO);
+  return LHS->refersToBitField() ? this->emitStoreBitFieldPop(*T, BO)
+ : this->emitStorePop(*T, BO);
+return LHS->refersToBitField() ? this->emitStoreBitField(*T, BO)
+   : this->emitStore(*T, BO);
   case BO_And:
 return Discard(this->emitBitAnd(*T, BO));
   case BO_Or:
@@ -521,8 +523,15 @@ bool 
ByteCodeExprGen::visitInitList(ArrayRef Inits,
   const Record::Field *FieldToInit = R->getField(InitIndex);
   if (!this->visit(Init))
 return false;
-  if (!this->emitInitField(*T, FieldToInit->Offset, E))
-return false;
+
+  if (FieldToInit->isBitField()) {
+if (!this->emitInitBitField(*T, FieldToInit, E))
+  return false;
+  } else {
+if (!this->emitInitField(*T, FieldToInit->Offset, E))
+  return false;
+  }
+
   if (!this->emitPopPtr(E))
 return false;
   ++InitIndex;
diff --git a/clang/lib/AST/Interp/ByteCodeStmtGen.cpp 
b/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
index 15eae8e20b3a678..b57bf3476d931a9 100644
--- a/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
+++ b/clang/lib/AST/Interp/ByteCodeStmtGen.cpp
@@ -166,8 +166,13 @@ bool ByteCodeStmtGen::visitFunc(const 
FunctionDecl *F) {
   if (!this->visit(InitExpr))
 return false;
 
-  if (!this->emitInitThisField(*T, F->Offset, InitExpr))
-return false;
+  if (F->isBitField()) {
+if (!this->emitInitThisBitField(*T, F, InitExpr))
+  return false;
+  } else {
+if (!this->emitInitThisField(*T, F->Offset, InitExpr))
+  return false;
+  }
 } else {
   // Non-primitive case. Get a pointer to the field-to-initialize
   // on the stack and call visitInitialzer() for it.
diff --git a/clang/lib/AST/Interp/Interp.h b/clang/lib/AST/Interp/Interp.h
index 8453856e526a6b2..f9cfa3bd00bf67a 100644
--- a/clang/lib/AST/Interp/Interp.h
+++ b/clang/lib/AST/Interp/Interp.h
@@ -1037,6 +1037,7 @@ bool InitThisField(InterpState &S, CodePtr OpPC, uint32_t 
I) {
 
 template ::T>
 bool InitThisBitField(InterpState &S, CodePtr OpPC, const Record::Field *F) {
+  assert(F->isBitField());
   if (S.checkingPotentialConstantExpression())
 return false;
   const Pointer &This = S.Current->getThis();
@@ -1078,8 +1079,9 @@ bool InitField(InterpState &S, CodePtr OpPC, uint32_t I) {
 
 template ::T>
 bool InitBitField(InterpState &S, CodePtr OpPC, const Record::Field *F) {
+  assert(F->isBitF

[clang-tools-extra] AMDGPU: Don't COPY constants from VGPR to SGPR (PR #66882)

2023-09-25 Thread via cfe-commits

https://github.com/rovka updated https://github.com/llvm/llvm-project/pull/66882

>From c1016a45d9cf57def642d14ba256db10e767cf5f Mon Sep 17 00:00:00 2001
From: Diana Picus 
Date: Wed, 20 Sep 2023 10:19:46 +0200
Subject: [PATCH 1/2] Pre-commit testcases

---
 llvm/test/CodeGen/AMDGPU/fix-sgpr-copies.mir | 58 
 1 file changed, 58 insertions(+)

diff --git a/llvm/test/CodeGen/AMDGPU/fix-sgpr-copies.mir 
b/llvm/test/CodeGen/AMDGPU/fix-sgpr-copies.mir
index 1315c227ecde385..f733cb999d77cef 100644
--- a/llvm/test/CodeGen/AMDGPU/fix-sgpr-copies.mir
+++ b/llvm/test/CodeGen/AMDGPU/fix-sgpr-copies.mir
@@ -125,4 +125,62 @@ body:   |
   %2:sreg_32 = S_MOV_B32 1
   %3:sreg_32 = COPY %1:vgpr_32
   %4:sreg_32 = S_CSELECT_B32 killed %2:sreg_32, killed %3:sreg_32, implicit 
undef $scc
+...
+
+---
+# Test that the VGPR immediate is replaced with an SGPR one.
+# GCN-LABEL: name: reg_sequence_vgpr_immediate
+# GCN: [[A_SGPR:%[0-9]+]]:sreg_32 = IMPLICIT_DEF
+# GCN: [[VGPR_CONST:%[0-9]+]]:vgpr_32 = V_MOV_B32_e32 37
+# GCN: [[A_VGPR:%[0-9]+]]:vgpr_32 = COPY [[A_SGPR]]
+# GCN: {{%[0-9]+}}:vreg_64 = REG_SEQUENCE [[VGPR_CONST]], %subreg.sub0, killed 
[[A_VGPR]], %subreg.sub1
+name: reg_sequence_vgpr_immediate
+body: |
+  bb.0:
+%0:sreg_32 = IMPLICIT_DEF
+%1:vgpr_32 = V_MOV_B32_e32 37, implicit $exec
+%2:sreg_64 = REG_SEQUENCE %1:vgpr_32, %subreg.sub0, %0:sreg_32, 
%subreg.sub1
+
+%3:vgpr_32 = V_ADD_U32_e32 %1:vgpr_32, %1:vgpr_32, implicit $exec
+...
+
 ---
+# GCN-LABEL: name: insert_subreg_vgpr_immediate
+# GCN: [[V0:%[0-9]+]]:vgpr_32 = COPY $sgpr0
+# GCN: [[V2:%[0-9]+]]:vgpr_32 = COPY $sgpr0
+# GCN: [[DST:%[0-9]+]]:vreg_128 = REG_SEQUENCE [[V0]], %subreg.sub0, [[V2]], 
%subreg.sub2
+# GCN: [[VGPR_CONST:%[0-9]+]]:vgpr_32 = V_MOV_B32_e32 43
+# GCN: {{%[0-9]+}}:vreg_128 = INSERT_SUBREG [[DST]], [[VGPR_CONST]], 
%subreg.sub3
+name: insert_subreg_vgpr_immediate
+body: |
+  bb.0:
+%0:sgpr_128 = REG_SEQUENCE $sgpr0, %subreg.sub0, $sgpr0, %subreg.sub2
+%1:vgpr_32 = V_MOV_B32_e32 43, implicit $exec
+%2:sgpr_128 = INSERT_SUBREG %0, %1, %subreg.sub3
+...
+
+---
+# GCN-LABEL: name: phi_vgpr_immediate
+# GCN: bb.1:
+# GCN: [[VGPR:%[0-9]+]]:vgpr_32 = V_MOV_B32_e32 51
+# GCN: bb.2:
+# GCN: IMPLICIT_DEF
+# GCN: bb.3:
+# GCN: vgpr_32 = PHI [[VGPR]], %bb.1
+name: phi_vgpr_immediate
+tracksRegLiveness: true
+body:   |
+  bb.0:
+S_CBRANCH_SCC1 %bb.2, implicit undef $scc
+
+  bb.1:
+%0:vgpr_32 = V_MOV_B32_e32 51, implicit $exec
+S_BRANCH %bb.3
+
+  bb.2:
+%1:sreg_32 = IMPLICIT_DEF
+S_BRANCH %bb.3
+
+  bb.3:
+%2:sreg_32 = PHI %0:vgpr_32, %bb.1, %1:sreg_32, %bb.2
+...

>From 551374344a8c8487dac43c9194b223a5869222f2 Mon Sep 17 00:00:00 2001
From: Diana Picus 
Date: Wed, 20 Sep 2023 10:21:28 +0200
Subject: [PATCH 2/2] AMDGPU: Don't COPY constants from VGPR to SGPR

Teach the si-fix-sgpr-copies pass to deal with REG_SEQUENCE, PHI or
INSERT_SUBREG where the result is an SGPR, but some of the inputs are
constants materialized into VGPRs. This may happen in cases where for
instance several instructions use an immediate zero and SelectionDAG
chooses to put it in a VGPR to satisfy all of them. This however causes
the si-fix-sgpr-copies to try to switch the whole chain to VGPR and may
lead to illegal VGPR-to-SGPR copies. Rematerializing the constant into
an SGPR fixes the issue.
---
 llvm/lib/Target/AMDGPU/SIFixSGPRCopies.cpp   | 74 +---
 llvm/test/CodeGen/AMDGPU/fix-sgpr-copies.mir | 18 +++--
 2 files changed, 56 insertions(+), 36 deletions(-)

diff --git a/llvm/lib/Target/AMDGPU/SIFixSGPRCopies.cpp 
b/llvm/lib/Target/AMDGPU/SIFixSGPRCopies.cpp
index 2216acf128bfa56..60cd9d4c3c35a27 100644
--- a/llvm/lib/Target/AMDGPU/SIFixSGPRCopies.cpp
+++ b/llvm/lib/Target/AMDGPU/SIFixSGPRCopies.cpp
@@ -152,6 +152,13 @@ class SIFixSGPRCopies : public MachineFunctionPass {
 
   void processPHINode(MachineInstr &MI);
 
+  // Check if MO is an immediate materialized into a VGPR, and if so replace it
+  // with an SGPR immediate. The VGPR immediate is also deleted if it does not
+  // have any other uses.
+  bool tryMoveVGPRConstToSGPR(MachineOperand &MO, Register NewDst,
+  MachineBasicBlock *BlockToInsertTo,
+  MachineBasicBlock::iterator PointToInsertTo);
+
   StringRef getPassName() const override { return "SI Fix SGPR copies"; }
 
   void getAnalysisUsage(AnalysisUsage &AU) const override {
@@ -662,13 +669,17 @@ bool 
SIFixSGPRCopies::runOnMachineFunction(MachineFunction &MF) {
  : MBB;
   MachineBasicBlock::iterator PointToInsertCopy =
   MI.isPHI() ? BlockToInsertCopy->getFirstInstrTerminator() : 
I;
-  MachineInstr *NewCopy =
-  BuildMI(*BlockToInsertCopy, PointToInsertCopy,
-  PointToInsertCopy->getDebugLoc(),
-  TII->get(AMDGPU::COPY), NewDst)
- 

[clang] clang/OpenCL: set sqrt fp accuracy on call to Z4sqrt (PR #66651)

2023-09-25 Thread Romaric Jodin via cfe-commits


@@ -5612,6 +5612,10 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo 
&CallInfo,
   BundleList);
 EmitBlock(Cont);
   }
+  if (CI->getCalledFunction() && CI->getCalledFunction()->hasName() &&
+  CI->getCalledFunction()->getName().startswith("_Z4sqrt")) {

rjodinchr wrote:

Using a custom `ext_vector_type` in OpenCL feels like an undefined behaviour. I 
don't see anything about it in the specification.
Am I missing something?

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


[clang] [ASTMatchers] Fix classIsDerivedFrom for recusrive cases (PR #67307)

2023-09-25 Thread Ilya Biryukov via cfe-commits

https://github.com/ilya-biryukov created 
https://github.com/llvm/llvm-project/pull/67307

By ensuring the base is only visited once. This avoids infinite recursion and 
expontential running times in some corner cases.

See the added tests for examples.

Apart from the cases that caused infinite recursion and used to crash, this 
change is an NFC and results of the matchers are the same.

>From bd300e3bf41df7cc90e4d4acf5e46da9847be46a Mon Sep 17 00:00:00 2001
From: Ilya Biryukov 
Date: Mon, 25 Sep 2023 11:46:03 +0200
Subject: [PATCH] [ASTMatchers] Fix classIsDerivedFrom for recusrive cases

By ensuring the base is only visited once. This avoids infinite
recursion and expontential running times in some corner cases.

See the added tests for examples.

Apart from the cases that caused infinite recursion and used to crash,
this change is an NFC and results of the matchers are the same.
---
 clang/lib/ASTMatchers/ASTMatchFinder.cpp  | 24 ++-
 .../ASTMatchers/ASTMatchersNodeTest.cpp   | 68 +++
 2 files changed, 91 insertions(+), 1 deletion(-)

diff --git a/clang/lib/ASTMatchers/ASTMatchFinder.cpp 
b/clang/lib/ASTMatchers/ASTMatchFinder.cpp
index f9bd1354fa8dc44..0bac2ed63a927ef 100644
--- a/clang/lib/ASTMatchers/ASTMatchFinder.cpp
+++ b/clang/lib/ASTMatchers/ASTMatchFinder.cpp
@@ -18,8 +18,10 @@
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/AST/ASTConsumer.h"
 #include "clang/AST/ASTContext.h"
+#include "clang/AST/DeclCXX.h"
 #include "clang/AST/RecursiveASTVisitor.h"
 #include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/Support/PrettyStackTrace.h"
 #include "llvm/Support/Timer.h"
@@ -651,11 +653,20 @@ class MatchASTVisitor : public 
RecursiveASTVisitor,
   BoundNodesTreeBuilder *Builder,
   bool Directly) override;
 
+private:
+  bool
+  classIsDerivedFromImpl(const CXXRecordDecl *Declaration,
+ const Matcher &Base,
+ BoundNodesTreeBuilder *Builder, bool Directly,
+ llvm::SmallPtrSetImpl 
&Visited);
+
+public:
   bool objcClassIsDerivedFrom(const ObjCInterfaceDecl *Declaration,
   const Matcher &Base,
   BoundNodesTreeBuilder *Builder,
   bool Directly) override;
 
+public:
   // Implements ASTMatchFinder::matchesChildOf.
   bool matchesChildOf(const DynTypedNode &Node, ASTContext &Ctx,
   const DynTypedMatcher &Matcher,
@@ -1361,8 +1372,18 @@ bool MatchASTVisitor::classIsDerivedFrom(const 
CXXRecordDecl *Declaration,
  const Matcher &Base,
  BoundNodesTreeBuilder *Builder,
  bool Directly) {
+  llvm::SmallPtrSet Visited;
+  return classIsDerivedFromImpl(Declaration, Base, Builder, Directly, Visited);
+}
+
+bool MatchASTVisitor::classIsDerivedFromImpl(
+const CXXRecordDecl *Declaration, const Matcher &Base,
+BoundNodesTreeBuilder *Builder, bool Directly,
+llvm::SmallPtrSetImpl &Visited) {
   if (!Declaration->hasDefinition())
 return false;
+  if (!Visited.insert(Declaration).second)
+return false;
   for (const auto &It : Declaration->bases()) {
 const Type *TypeNode = It.getType().getTypePtr();
 
@@ -1384,7 +1405,8 @@ bool MatchASTVisitor::classIsDerivedFrom(const 
CXXRecordDecl *Declaration,
   *Builder = std::move(Result);
   return true;
 }
-if (!Directly && classIsDerivedFrom(ClassDecl, Base, Builder, Directly))
+if (!Directly &&
+classIsDerivedFromImpl(ClassDecl, Base, Builder, Directly, Visited))
   return true;
   }
   return false;
diff --git a/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp 
b/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
index 7a6d6ef0a95554b..0a08a8b4c491dca 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -2369,6 +2369,74 @@ TEST_P(ASTMatchersTest, 
LambdaCaptureTest_BindsToCaptureOfReferenceType) {
"}", matcher));
 }
 
+TEST_P(ASTMatchersTest, IsDerivedFromRecursion) {
+  if (!GetParam().isCXX11OrLater())
+return;
+
+  // Check we don't crash on cycles in the traversal and inheritance hierarchy.
+  // Clang will normally enforce there are no cycles, but matchers opted to
+  // traverse primary template for dependent specializations, spuriously
+  // creating the cycles.
+  DeclarationMatcher matcher = cxxRecordDecl(isDerivedFrom("X"));
+  EXPECT_TRUE(notMatches(R"cpp(
+  template  struct M; template  struct M {}; template  struct L : M {};
+  template 
+  struct M : L, M> {};
+  )cpp",
+ matcher));
+
+  // Check the running time is not exponential. The number of subojects to
+  // traverse grows as fibonacci numbers even though the

[clang] [ASTMatchers] Fix classIsDerivedFrom for recusrive cases (PR #67307)

2023-09-25 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-tidy


Changes

By ensuring the base is only visited once. This avoids infinite recursion and 
expontential running times in some corner cases.

See the added tests for examples.

Apart from the cases that caused infinite recursion and used to crash, this 
change is an NFC and results of the matchers are the same.

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


2 Files Affected:

- (modified) clang/lib/ASTMatchers/ASTMatchFinder.cpp (+23-1) 
- (modified) clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp (+68) 


``diff
diff --git a/clang/lib/ASTMatchers/ASTMatchFinder.cpp 
b/clang/lib/ASTMatchers/ASTMatchFinder.cpp
index f9bd1354fa8dc44..0bac2ed63a927ef 100644
--- a/clang/lib/ASTMatchers/ASTMatchFinder.cpp
+++ b/clang/lib/ASTMatchers/ASTMatchFinder.cpp
@@ -18,8 +18,10 @@
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/AST/ASTConsumer.h"
 #include "clang/AST/ASTContext.h"
+#include "clang/AST/DeclCXX.h"
 #include "clang/AST/RecursiveASTVisitor.h"
 #include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/Support/PrettyStackTrace.h"
 #include "llvm/Support/Timer.h"
@@ -651,11 +653,20 @@ class MatchASTVisitor : public 
RecursiveASTVisitor,
   BoundNodesTreeBuilder *Builder,
   bool Directly) override;
 
+private:
+  bool
+  classIsDerivedFromImpl(const CXXRecordDecl *Declaration,
+ const Matcher &Base,
+ BoundNodesTreeBuilder *Builder, bool Directly,
+ llvm::SmallPtrSetImpl 
&Visited);
+
+public:
   bool objcClassIsDerivedFrom(const ObjCInterfaceDecl *Declaration,
   const Matcher &Base,
   BoundNodesTreeBuilder *Builder,
   bool Directly) override;
 
+public:
   // Implements ASTMatchFinder::matchesChildOf.
   bool matchesChildOf(const DynTypedNode &Node, ASTContext &Ctx,
   const DynTypedMatcher &Matcher,
@@ -1361,8 +1372,18 @@ bool MatchASTVisitor::classIsDerivedFrom(const 
CXXRecordDecl *Declaration,
  const Matcher &Base,
  BoundNodesTreeBuilder *Builder,
  bool Directly) {
+  llvm::SmallPtrSet Visited;
+  return classIsDerivedFromImpl(Declaration, Base, Builder, Directly, Visited);
+}
+
+bool MatchASTVisitor::classIsDerivedFromImpl(
+const CXXRecordDecl *Declaration, const Matcher &Base,
+BoundNodesTreeBuilder *Builder, bool Directly,
+llvm::SmallPtrSetImpl &Visited) {
   if (!Declaration->hasDefinition())
 return false;
+  if (!Visited.insert(Declaration).second)
+return false;
   for (const auto &It : Declaration->bases()) {
 const Type *TypeNode = It.getType().getTypePtr();
 
@@ -1384,7 +1405,8 @@ bool MatchASTVisitor::classIsDerivedFrom(const 
CXXRecordDecl *Declaration,
   *Builder = std::move(Result);
   return true;
 }
-if (!Directly && classIsDerivedFrom(ClassDecl, Base, Builder, Directly))
+if (!Directly &&
+classIsDerivedFromImpl(ClassDecl, Base, Builder, Directly, Visited))
   return true;
   }
   return false;
diff --git a/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp 
b/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
index 7a6d6ef0a95554b..0a08a8b4c491dca 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -2369,6 +2369,74 @@ TEST_P(ASTMatchersTest, 
LambdaCaptureTest_BindsToCaptureOfReferenceType) {
"}", matcher));
 }
 
+TEST_P(ASTMatchersTest, IsDerivedFromRecursion) {
+  if (!GetParam().isCXX11OrLater())
+return;
+
+  // Check we don't crash on cycles in the traversal and inheritance hierarchy.
+  // Clang will normally enforce there are no cycles, but matchers opted to
+  // traverse primary template for dependent specializations, spuriously
+  // creating the cycles.
+  DeclarationMatcher matcher = cxxRecordDecl(isDerivedFrom("X"));
+  EXPECT_TRUE(notMatches(R"cpp(
+  template  struct M; template  struct M {}; template  struct L : M {};
+  template 
+  struct M : L, M> {};
+  )cpp",
+ matcher));
+
+  // Check the running time is not exponential. The number of subojects to
+  // traverse grows as fibonacci numbers even though the number of bases to
+  // traverse is quadratic.
+  // The test will hang if implementation of matchers traverses all subojects.
+  EXPECT_TRUE(notMatches(R"cpp(
+template  struct A0 {};
+template  struct A1 : A0 {};
+template  struct A2 : A1, A0 {};
+template  struct A3 : A2, A1 {};
+template  struct A4 : A3, A2 {};
+template  struct A5 : A4, A3 {};
+template  struct A6 : A5, A4 {};
+template  struct A7 : A6, A5 {};
+template  struct A8 :

[clang] [llvm][tblgen] Add `SourcePath` for `emitSourceFileHeader` (PR #65744)

2023-09-25 Thread Renato Golin via cfe-commits

rengolin wrote:

> Is this suggestion correct?

Doesn't look right to me. I seems it's suggesting 4 spaces tabs, which isn't 
what we normally use. Something wrong with the clang-format job, maybe?

@tru @tstellar 

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


[clang] [ASTMatchers] Fix classIsDerivedFrom for recusrive cases (PR #67307)

2023-09-25 Thread Sam McCall via cfe-commits

https://github.com/sam-mccall approved this pull request.


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


[clang] 3e97db8 - [PowerPC] Emit IR module flag for current float abi

2023-09-25 Thread Qiu Chaofan via cfe-commits

Author: Qiu Chaofan
Date: 2023-09-25T17:53:39+08:00
New Revision: 3e97db89ae8e5b4d7bb6c0bf52773c43c9e06c51

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

LOG: [PowerPC] Emit IR module flag for current float abi

This is part of the efforts adding .gnu_attribute support for PowerPC.
In Clang, an extra metadata field will be added as float-abi to show
current long double format. So backend can emit .gnu_attribute section
data from this metadata.

To avoid breaking existing behavior, the module metadata will only be
emitted when this module makes use of long double.

Reviewed By: nemanjai

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

Added: 
clang/test/CodeGen/ppc64-float-abi-attr.c

Modified: 
clang/lib/CodeGen/CodeGenTypes.cpp
clang/lib/CodeGen/CodeGenTypes.h
clang/lib/CodeGen/Targets/PPC.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CodeGenTypes.cpp 
b/clang/lib/CodeGen/CodeGenTypes.cpp
index 30021794a0bb3d3..29f4f51dc08b5ec 100644
--- a/clang/lib/CodeGen/CodeGenTypes.cpp
+++ b/clang/lib/CodeGen/CodeGenTypes.cpp
@@ -34,6 +34,7 @@ CodeGenTypes::CodeGenTypes(CodeGenModule &cgm)
 Target(cgm.getTarget()), TheCXXABI(cgm.getCXXABI()),
 TheABIInfo(cgm.getTargetCodeGenInfo().getABIInfo()) {
   SkippedLayout = false;
+  LongDoubleReferenced = false;
 }
 
 CodeGenTypes::~CodeGenTypes() {
@@ -406,10 +407,12 @@ llvm::Type *CodeGenTypes::ConvertType(QualType T) {
   Context.getLangOpts().NativeHalfType ||
   !Context.getTargetInfo().useFP16ConversionIntrinsics());
   break;
+case BuiltinType::LongDouble:
+  LongDoubleReferenced = true;
+  LLVM_FALLTHROUGH;
 case BuiltinType::BFloat16:
 case BuiltinType::Float:
 case BuiltinType::Double:
-case BuiltinType::LongDouble:
 case BuiltinType::Float128:
 case BuiltinType::Ibm128:
   ResultType = getTypeForFormat(getLLVMContext(),

diff  --git a/clang/lib/CodeGen/CodeGenTypes.h 
b/clang/lib/CodeGen/CodeGenTypes.h
index a0e846d9a7516cd..01c0c673795c0fa 100644
--- a/clang/lib/CodeGen/CodeGenTypes.h
+++ b/clang/lib/CodeGen/CodeGenTypes.h
@@ -84,6 +84,9 @@ class CodeGenTypes {
   /// a recursive struct conversion, set this to true.
   bool SkippedLayout;
 
+  /// True if any instance of long double types are used.
+  bool LongDoubleReferenced;
+
   /// This map keeps cache of llvm::Types and maps clang::Type to
   /// corresponding llvm::Type.
   llvm::DenseMap TypeCache;
@@ -289,6 +292,7 @@ class CodeGenTypes {
   /// zero-initialized (in the C++ sense) with an LLVM zeroinitializer.
   bool isZeroInitializable(const RecordDecl *RD);
 
+  bool isLongDoubleReferenced() const { return LongDoubleReferenced; }
   bool isRecordLayoutComplete(const Type *Ty) const;
   unsigned getTargetAddressSpace(QualType T) const;
 };

diff  --git a/clang/lib/CodeGen/Targets/PPC.cpp 
b/clang/lib/CodeGen/Targets/PPC.cpp
index 6f4c150ef3149e8..40e508c1772 100644
--- a/clang/lib/CodeGen/Targets/PPC.cpp
+++ b/clang/lib/CodeGen/Targets/PPC.cpp
@@ -620,6 +620,9 @@ class PPC64_SVR4_TargetCodeGenInfo : public 
TargetCodeGenInfo {
 
   bool initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF,
llvm::Value *Address) const override;
+  void emitTargetMetadata(CodeGen::CodeGenModule &CGM,
+  const llvm::MapVector
+  &MangledDeclNames) const override;
 };
 
 class PPC64TargetCodeGenInfo : public TargetCodeGenInfo {
@@ -940,6 +943,24 @@ PPC64_SVR4_TargetCodeGenInfo::initDwarfEHRegSizeTable(
  /*IsAIX*/ false);
 }
 
+void PPC64_SVR4_TargetCodeGenInfo::emitTargetMetadata(
+CodeGen::CodeGenModule &CGM,
+const llvm::MapVector &MangledDeclNames) const {
+  if (CGM.getTypes().isLongDoubleReferenced()) {
+llvm::LLVMContext &Ctx = CGM.getLLVMContext();
+const auto *flt = &CGM.getTarget().getLongDoubleFormat();
+if (flt == &llvm::APFloat::PPCDoubleDouble())
+  CGM.getModule().addModuleFlag(llvm::Module::Error, "float-abi",
+llvm::MDString::get(Ctx, "doubledouble"));
+else if (flt == &llvm::APFloat::IEEEquad())
+  CGM.getModule().addModuleFlag(llvm::Module::Error, "float-abi",
+llvm::MDString::get(Ctx, "ieeequad"));
+else if (flt == &llvm::APFloat::IEEEdouble())
+  CGM.getModule().addModuleFlag(llvm::Module::Error, "float-abi",
+llvm::MDString::get(Ctx, "ieeedouble"));
+  }
+}
+
 bool
 PPC64TargetCodeGenInfo::initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF,
 llvm::Value *Address) const {

diff  --git a/clang/test/CodeGen/ppc64-float-abi-attr.c 
b/clang/test/CodeGen/ppc64-float-

[PATCH] D116016: [Clang] [PowerPC] Emit module flag for current float abi

2023-09-25 Thread Qiu Chaofan via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rG3e97db89ae8e: [PowerPC] Emit IR module flag for current 
float abi (authored by qiucf).

Changed prior to commit:
  https://reviews.llvm.org/D116016?vs=530843&id=557298#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D116016/new/

https://reviews.llvm.org/D116016

Files:
  clang/lib/CodeGen/CodeGenTypes.cpp
  clang/lib/CodeGen/CodeGenTypes.h
  clang/lib/CodeGen/Targets/PPC.cpp
  clang/test/CodeGen/ppc64-float-abi-attr.c

Index: clang/test/CodeGen/ppc64-float-abi-attr.c
===
--- /dev/null
+++ clang/test/CodeGen/ppc64-float-abi-attr.c
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -triple powerpc64le-unknown-linux-gnu %s -emit-llvm -o - | FileCheck %s
+// RUN: %clang_cc1 -triple powerpc64le-unknown-linux-gnu %s -emit-llvm -mabi=ieeelongdouble -o - | FileCheck %s --check-prefix=IEEE
+// RUN: %clang_cc1 -triple powerpc64le-unknown-linux-gnu %s -emit-llvm -mlong-double-64 -o - | FileCheck %s --check-prefix=LDBL64
+// RUN: %clang_cc1 -triple powerpc64le-unknown-linux-gnu %s -emit-llvm -DNOLDBL -o - | FileCheck %s --check-prefix=NOLDBL
+
+#ifndef NOLDBL
+long double foo(long double a, long double b) {
+  return a + b;
+}
+#endif
+
+int bar() { return 1; }
+
+// CHECK: ![[#]] = !{i32 1, !"float-abi", !"doubledouble"}
+// IEEE: ![[#]] = !{i32 1, !"float-abi", !"ieeequad"}
+// LDBL64: ![[#]] = !{i32 1, !"float-abi", !"ieeedouble"}
+// NOLDBL-NOT: ![[#]] = !{i32 1, !"float-abi"
Index: clang/lib/CodeGen/Targets/PPC.cpp
===
--- clang/lib/CodeGen/Targets/PPC.cpp
+++ clang/lib/CodeGen/Targets/PPC.cpp
@@ -620,6 +620,9 @@
 
   bool initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF,
llvm::Value *Address) const override;
+  void emitTargetMetadata(CodeGen::CodeGenModule &CGM,
+  const llvm::MapVector
+  &MangledDeclNames) const override;
 };
 
 class PPC64TargetCodeGenInfo : public TargetCodeGenInfo {
@@ -940,6 +943,24 @@
  /*IsAIX*/ false);
 }
 
+void PPC64_SVR4_TargetCodeGenInfo::emitTargetMetadata(
+CodeGen::CodeGenModule &CGM,
+const llvm::MapVector &MangledDeclNames) const {
+  if (CGM.getTypes().isLongDoubleReferenced()) {
+llvm::LLVMContext &Ctx = CGM.getLLVMContext();
+const auto *flt = &CGM.getTarget().getLongDoubleFormat();
+if (flt == &llvm::APFloat::PPCDoubleDouble())
+  CGM.getModule().addModuleFlag(llvm::Module::Error, "float-abi",
+llvm::MDString::get(Ctx, "doubledouble"));
+else if (flt == &llvm::APFloat::IEEEquad())
+  CGM.getModule().addModuleFlag(llvm::Module::Error, "float-abi",
+llvm::MDString::get(Ctx, "ieeequad"));
+else if (flt == &llvm::APFloat::IEEEdouble())
+  CGM.getModule().addModuleFlag(llvm::Module::Error, "float-abi",
+llvm::MDString::get(Ctx, "ieeedouble"));
+  }
+}
+
 bool
 PPC64TargetCodeGenInfo::initDwarfEHRegSizeTable(CodeGen::CodeGenFunction &CGF,
 llvm::Value *Address) const {
Index: clang/lib/CodeGen/CodeGenTypes.h
===
--- clang/lib/CodeGen/CodeGenTypes.h
+++ clang/lib/CodeGen/CodeGenTypes.h
@@ -84,6 +84,9 @@
   /// a recursive struct conversion, set this to true.
   bool SkippedLayout;
 
+  /// True if any instance of long double types are used.
+  bool LongDoubleReferenced;
+
   /// This map keeps cache of llvm::Types and maps clang::Type to
   /// corresponding llvm::Type.
   llvm::DenseMap TypeCache;
@@ -289,6 +292,7 @@
   /// zero-initialized (in the C++ sense) with an LLVM zeroinitializer.
   bool isZeroInitializable(const RecordDecl *RD);
 
+  bool isLongDoubleReferenced() const { return LongDoubleReferenced; }
   bool isRecordLayoutComplete(const Type *Ty) const;
   unsigned getTargetAddressSpace(QualType T) const;
 };
Index: clang/lib/CodeGen/CodeGenTypes.cpp
===
--- clang/lib/CodeGen/CodeGenTypes.cpp
+++ clang/lib/CodeGen/CodeGenTypes.cpp
@@ -34,6 +34,7 @@
 Target(cgm.getTarget()), TheCXXABI(cgm.getCXXABI()),
 TheABIInfo(cgm.getTargetCodeGenInfo().getABIInfo()) {
   SkippedLayout = false;
+  LongDoubleReferenced = false;
 }
 
 CodeGenTypes::~CodeGenTypes() {
@@ -406,10 +407,12 @@
   Context.getLangOpts().NativeHalfType ||
   !Context.getTargetInfo().useFP16ConversionIntrinsics());
   break;
+case BuiltinType::LongDouble:
+  LongDoubleReferenced = true;
+  LLVM_FALLTHROUGH;
 case BuiltinType::BFloat16:
 case BuiltinType::Float:
 case BuiltinType::Double:
-case BuiltinType::LongDouble:
 case BuiltinType::Float128:
 ca

[clang] [ASTMatchers] Fix classIsDerivedFrom for recusrive cases (PR #67307)

2023-09-25 Thread Ilya Biryukov via cfe-commits

https://github.com/ilya-biryukov updated 
https://github.com/llvm/llvm-project/pull/67307

>From bd300e3bf41df7cc90e4d4acf5e46da9847be46a Mon Sep 17 00:00:00 2001
From: Ilya Biryukov 
Date: Mon, 25 Sep 2023 11:46:03 +0200
Subject: [PATCH 1/2] [ASTMatchers] Fix classIsDerivedFrom for recusrive cases

By ensuring the base is only visited once. This avoids infinite
recursion and expontential running times in some corner cases.

See the added tests for examples.

Apart from the cases that caused infinite recursion and used to crash,
this change is an NFC and results of the matchers are the same.
---
 clang/lib/ASTMatchers/ASTMatchFinder.cpp  | 24 ++-
 .../ASTMatchers/ASTMatchersNodeTest.cpp   | 68 +++
 2 files changed, 91 insertions(+), 1 deletion(-)

diff --git a/clang/lib/ASTMatchers/ASTMatchFinder.cpp 
b/clang/lib/ASTMatchers/ASTMatchFinder.cpp
index f9bd1354fa8dc44..0bac2ed63a927ef 100644
--- a/clang/lib/ASTMatchers/ASTMatchFinder.cpp
+++ b/clang/lib/ASTMatchers/ASTMatchFinder.cpp
@@ -18,8 +18,10 @@
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/AST/ASTConsumer.h"
 #include "clang/AST/ASTContext.h"
+#include "clang/AST/DeclCXX.h"
 #include "clang/AST/RecursiveASTVisitor.h"
 #include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/Support/PrettyStackTrace.h"
 #include "llvm/Support/Timer.h"
@@ -651,11 +653,20 @@ class MatchASTVisitor : public 
RecursiveASTVisitor,
   BoundNodesTreeBuilder *Builder,
   bool Directly) override;
 
+private:
+  bool
+  classIsDerivedFromImpl(const CXXRecordDecl *Declaration,
+ const Matcher &Base,
+ BoundNodesTreeBuilder *Builder, bool Directly,
+ llvm::SmallPtrSetImpl 
&Visited);
+
+public:
   bool objcClassIsDerivedFrom(const ObjCInterfaceDecl *Declaration,
   const Matcher &Base,
   BoundNodesTreeBuilder *Builder,
   bool Directly) override;
 
+public:
   // Implements ASTMatchFinder::matchesChildOf.
   bool matchesChildOf(const DynTypedNode &Node, ASTContext &Ctx,
   const DynTypedMatcher &Matcher,
@@ -1361,8 +1372,18 @@ bool MatchASTVisitor::classIsDerivedFrom(const 
CXXRecordDecl *Declaration,
  const Matcher &Base,
  BoundNodesTreeBuilder *Builder,
  bool Directly) {
+  llvm::SmallPtrSet Visited;
+  return classIsDerivedFromImpl(Declaration, Base, Builder, Directly, Visited);
+}
+
+bool MatchASTVisitor::classIsDerivedFromImpl(
+const CXXRecordDecl *Declaration, const Matcher &Base,
+BoundNodesTreeBuilder *Builder, bool Directly,
+llvm::SmallPtrSetImpl &Visited) {
   if (!Declaration->hasDefinition())
 return false;
+  if (!Visited.insert(Declaration).second)
+return false;
   for (const auto &It : Declaration->bases()) {
 const Type *TypeNode = It.getType().getTypePtr();
 
@@ -1384,7 +1405,8 @@ bool MatchASTVisitor::classIsDerivedFrom(const 
CXXRecordDecl *Declaration,
   *Builder = std::move(Result);
   return true;
 }
-if (!Directly && classIsDerivedFrom(ClassDecl, Base, Builder, Directly))
+if (!Directly &&
+classIsDerivedFromImpl(ClassDecl, Base, Builder, Directly, Visited))
   return true;
   }
   return false;
diff --git a/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp 
b/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
index 7a6d6ef0a95554b..0a08a8b4c491dca 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -2369,6 +2369,74 @@ TEST_P(ASTMatchersTest, 
LambdaCaptureTest_BindsToCaptureOfReferenceType) {
"}", matcher));
 }
 
+TEST_P(ASTMatchersTest, IsDerivedFromRecursion) {
+  if (!GetParam().isCXX11OrLater())
+return;
+
+  // Check we don't crash on cycles in the traversal and inheritance hierarchy.
+  // Clang will normally enforce there are no cycles, but matchers opted to
+  // traverse primary template for dependent specializations, spuriously
+  // creating the cycles.
+  DeclarationMatcher matcher = cxxRecordDecl(isDerivedFrom("X"));
+  EXPECT_TRUE(notMatches(R"cpp(
+  template  struct M; template  struct M {}; template  struct L : M {};
+  template 
+  struct M : L, M> {};
+  )cpp",
+ matcher));
+
+  // Check the running time is not exponential. The number of subojects to
+  // traverse grows as fibonacci numbers even though the number of bases to
+  // traverse is quadratic.
+  // The test will hang if implementation of matchers traverses all subojects.
+  EXPECT_TRUE(notMatches(R"cpp(
+template  struct A0 {};
+template  struct A1 : A0 {};
+template  struct A2 : A1, A0 {};
+template  struct A3 : A2, A1 

[clang] f5cb9cb - [ASTMatchers] Fix classIsDerivedFrom for recusrive cases (#67307)

2023-09-25 Thread via cfe-commits

Author: Ilya Biryukov
Date: 2023-09-25T12:10:29+02:00
New Revision: f5cb9cb59d7c9c6ac3d5c41c677f68c9b75d34a3

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

LOG: [ASTMatchers] Fix classIsDerivedFrom for recusrive cases (#67307)

By ensuring the base is only visited once. This avoids infinite
recursion and expontential running times in some corner cases.

See the added tests for examples.

Apart from the cases that caused infinite recursion and used to crash,
this change is an NFC and results of the matchers are the same.

Added: 


Modified: 
clang/lib/ASTMatchers/ASTMatchFinder.cpp
clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp

Removed: 




diff  --git a/clang/lib/ASTMatchers/ASTMatchFinder.cpp 
b/clang/lib/ASTMatchers/ASTMatchFinder.cpp
index f9bd1354fa8dc44..0bac2ed63a927ef 100644
--- a/clang/lib/ASTMatchers/ASTMatchFinder.cpp
+++ b/clang/lib/ASTMatchers/ASTMatchFinder.cpp
@@ -18,8 +18,10 @@
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/AST/ASTConsumer.h"
 #include "clang/AST/ASTContext.h"
+#include "clang/AST/DeclCXX.h"
 #include "clang/AST/RecursiveASTVisitor.h"
 #include "llvm/ADT/DenseMap.h"
+#include "llvm/ADT/SmallPtrSet.h"
 #include "llvm/ADT/StringMap.h"
 #include "llvm/Support/PrettyStackTrace.h"
 #include "llvm/Support/Timer.h"
@@ -651,11 +653,20 @@ class MatchASTVisitor : public 
RecursiveASTVisitor,
   BoundNodesTreeBuilder *Builder,
   bool Directly) override;
 
+private:
+  bool
+  classIsDerivedFromImpl(const CXXRecordDecl *Declaration,
+ const Matcher &Base,
+ BoundNodesTreeBuilder *Builder, bool Directly,
+ llvm::SmallPtrSetImpl 
&Visited);
+
+public:
   bool objcClassIsDerivedFrom(const ObjCInterfaceDecl *Declaration,
   const Matcher &Base,
   BoundNodesTreeBuilder *Builder,
   bool Directly) override;
 
+public:
   // Implements ASTMatchFinder::matchesChildOf.
   bool matchesChildOf(const DynTypedNode &Node, ASTContext &Ctx,
   const DynTypedMatcher &Matcher,
@@ -1361,8 +1372,18 @@ bool MatchASTVisitor::classIsDerivedFrom(const 
CXXRecordDecl *Declaration,
  const Matcher &Base,
  BoundNodesTreeBuilder *Builder,
  bool Directly) {
+  llvm::SmallPtrSet Visited;
+  return classIsDerivedFromImpl(Declaration, Base, Builder, Directly, Visited);
+}
+
+bool MatchASTVisitor::classIsDerivedFromImpl(
+const CXXRecordDecl *Declaration, const Matcher &Base,
+BoundNodesTreeBuilder *Builder, bool Directly,
+llvm::SmallPtrSetImpl &Visited) {
   if (!Declaration->hasDefinition())
 return false;
+  if (!Visited.insert(Declaration).second)
+return false;
   for (const auto &It : Declaration->bases()) {
 const Type *TypeNode = It.getType().getTypePtr();
 
@@ -1384,7 +1405,8 @@ bool MatchASTVisitor::classIsDerivedFrom(const 
CXXRecordDecl *Declaration,
   *Builder = std::move(Result);
   return true;
 }
-if (!Directly && classIsDerivedFrom(ClassDecl, Base, Builder, Directly))
+if (!Directly &&
+classIsDerivedFromImpl(ClassDecl, Base, Builder, Directly, Visited))
   return true;
   }
   return false;

diff  --git a/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp 
b/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
index 7a6d6ef0a95554b..8f0dd5602307c53 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
+++ b/clang/unittests/ASTMatchers/ASTMatchersNodeTest.cpp
@@ -2369,6 +2369,80 @@ TEST_P(ASTMatchersTest, 
LambdaCaptureTest_BindsToCaptureOfReferenceType) {
"}", matcher));
 }
 
+TEST_P(ASTMatchersTest, IsDerivedFromRecursion) {
+  if (!GetParam().isCXX11OrLater())
+return;
+
+  // Check we don't crash on cycles in the traversal and inheritance hierarchy.
+  // Clang will normally enforce there are no cycles, but matchers opted to
+  // traverse primary template for dependent specializations, spuriously
+  // creating the cycles.
+  DeclarationMatcher matcher = cxxRecordDecl(isDerivedFrom("X"));
+  EXPECT_TRUE(notMatches(R"cpp(
+  template 
+  struct M;
+
+  template 
+  struct M {};
+
+  template 
+  struct L : M {};
+
+  template 
+  struct M : L, M> {};
+  )cpp",
+ matcher));
+
+  // Check the running time is not exponential. The number of subojects to
+  // traverse grows as fibonacci numbers even though the number of bases to
+  // traverse is quadratic.
+  // The test will hang if implementation of matchers traverses all subojects.
+  EXPECT_TRUE(

[clang] [ASTMatchers] Fix classIsDerivedFrom for recusrive cases (PR #67307)

2023-09-25 Thread Ilya Biryukov via cfe-commits

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


[clang] [llvm][tblgen] Add `SourcePath` for `emitSourceFileHeader` (PR #65744)

2023-09-25 Thread Tobias Hieta via cfe-commits

tru wrote:

No I don't think it's job's fault. I ran clang-format on this file and it's not 
formatted at all, so I think when we ask it to just format a patch like we do 
in the job, it gets a bit confused and give you a bit of non-sense formatting. 
This is just a limitation of not running formatting on the whole file. 

Two solutions:
1) just ignore it, it looks fine in general.
2) Push a NFC commit that fixes the formatting of this file and then 
rebase/merge to get that commit in your branch and it should look fine.


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


[clang] [llvm][tblgen] Add `SourcePath` for `emitSourceFileHeader` (PR #65744)

2023-09-25 Thread Tobias Hieta via cfe-commits

tru wrote:

Looking at it - it seems like none of Tablegen is correctly clang-formatted. If 
that's not desired, maybe it should have a local .clang-format file to disable 
the formatting of these files.

Do we have a clang-tblgen maintainer? Couldn't find anything in the codeowners 
and git log history seems to be very split.

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


[clang] -fsanitize=function: fix MSVC hashing to sugared type (PR #66816)

2023-09-25 Thread Matheus Izvekov via cfe-commits

mizvekov wrote:

@efriedma-quic gentle ping :-)

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


[clang] [NVPTX] Add support for maxclusterrank in launch_bounds (PR #66496)

2023-09-25 Thread Jakub Chlanda via cfe-commits

https://github.com/jchlanda updated 
https://github.com/llvm/llvm-project/pull/66496

>From 9c8caed3c8def15ccdbfdf831f36d0befed1fc84 Mon Sep 17 00:00:00 2001
From: Jakub Chlanda 
Date: Fri, 15 Sep 2023 12:08:04 +0100
Subject: [PATCH 1/7] [NVPTX] Add support for maxclusterrank in launch_bounds

Since SM_90 CUDA supports specifying additional argument to the
launch_bounds attribute: maxBlocksPerCluster, to express the maximum
number of CTAs that can be part of the cluster. See:
https://docs.nvidia.com/cuda/parallel-thread-execution/index.html#cluster-dimension-directives-maxclusterrank
and
https://docs.nvidia.com/cuda/cuda-c-programming-guide/index.html#launch-bounds
for details.
---
 clang/include/clang/Basic/Attr.td |  3 +-
 .../clang/Basic/DiagnosticSemaKinds.td|  4 +
 clang/include/clang/Sema/Sema.h   |  5 +-
 clang/lib/CodeGen/Targets/NVPTX.cpp   | 12 ++-
 clang/lib/Parse/ParseOpenMP.cpp   |  3 +-
 clang/lib/Sema/SemaDeclAttr.cpp   | 46 +--
 .../lib/Sema/SemaTemplateInstantiateDecl.cpp  | 10 ++-
 clang/test/CodeGenCUDA/launch-bounds.cu   | 69 
 clang/test/SemaCUDA/launch_bounds.cu  |  4 +-
 clang/test/SemaCUDA/launch_bounds_sm_90.cu| 45 +++
 llvm/lib/Target/NVPTX/NVPTXAsmPrinter.cpp | 79 +--
 llvm/lib/Target/NVPTX/NVPTXUtilities.cpp  |  4 +
 llvm/lib/Target/NVPTX/NVPTXUtilities.h|  1 +
 13 files changed, 227 insertions(+), 58 deletions(-)
 create mode 100644 clang/test/SemaCUDA/launch_bounds_sm_90.cu

diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index c95db7e8049d47a..3c51261bd3eb081 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1267,7 +1267,8 @@ def CUDAInvalidTarget : InheritableAttr {
 
 def CUDALaunchBounds : InheritableAttr {
   let Spellings = [GNU<"launch_bounds">, Declspec<"__launch_bounds__">];
-  let Args = [ExprArgument<"MaxThreads">, ExprArgument<"MinBlocks", 1>];
+  let Args = [ExprArgument<"MaxThreads">, ExprArgument<"MinBlocks", 1>,
+  ExprArgument<"MaxBlocks", 1>];
   let LangOpts = [CUDA];
   let Subjects = SubjectList<[ObjCMethod, FunctionLike]>;
   // An AST node is created for this attribute, but is not used by other parts
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 0ac4df8edb242f6..088e3a45c7babba 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -11836,6 +11836,10 @@ def err_sycl_special_type_num_init_method : Error<
   "types with 'sycl_special_class' attribute must have one and only one 
'__init' "
   "method defined">;
 
+def warn_cuda_maxclusterrank_sm_90 : Warning<
+  "maxclusterrank requires sm_90 or higher, CUDA arch provided: %0, ignoring "
+  "%1 attribute">, InGroup;
+
 def err_bit_int_bad_size : Error<"%select{signed|unsigned}0 _BitInt must "
  "have a bit size of at least %select{2|1}0">;
 def err_bit_int_max_size : Error<"%select{signed|unsigned}0 _BitInt of bit "
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 47379e00a7445e3..dca7b66da3796d9 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -11051,12 +11051,13 @@ class Sema final {
   /// Create an CUDALaunchBoundsAttr attribute.
   CUDALaunchBoundsAttr *CreateLaunchBoundsAttr(const AttributeCommonInfo &CI,
Expr *MaxThreads,
-   Expr *MinBlocks);
+   Expr *MinBlocks,
+   Expr *MaxBlocks);
 
   /// AddLaunchBoundsAttr - Adds a launch_bounds attribute to a particular
   /// declaration.
   void AddLaunchBoundsAttr(Decl *D, const AttributeCommonInfo &CI,
-   Expr *MaxThreads, Expr *MinBlocks);
+   Expr *MaxThreads, Expr *MinBlocks, Expr *MaxBlocks);
 
   /// AddModeAttr - Adds a mode attribute to a particular declaration.
   void AddModeAttr(Decl *D, const AttributeCommonInfo &CI, IdentifierInfo 
*Name,
diff --git a/clang/lib/CodeGen/Targets/NVPTX.cpp 
b/clang/lib/CodeGen/Targets/NVPTX.cpp
index 0d4bbd795648008..64d019a10514d60 100644
--- a/clang/lib/CodeGen/Targets/NVPTX.cpp
+++ b/clang/lib/CodeGen/Targets/NVPTX.cpp
@@ -296,8 +296,8 @@ void CodeGenModule::handleCUDALaunchBoundsAttr(
 NVPTXTargetCodeGenInfo::addNVVMMetadata(F, "maxntidx",
 MaxThreads.getExtValue());
 
-  // min blocks is an optional argument for CUDALaunchBoundsAttr. If it was
-  // not specified in __launch_bounds__ or if the user specified a 0 value,
+  // min and max blocks is an optional argument for CUDALaunchBoundsAttr. If it
+  // was not specified in __launch_bounds__ or if the user specified

[clang] [NVPTX] Add support for maxclusterrank in launch_bounds (PR #66496)

2023-09-25 Thread Jakub Chlanda via cfe-commits


@@ -537,59 +537,46 @@ void NVPTXAsmPrinter::emitKernelFunctionDirectives(const 
Function &F,
raw_ostream &O) const {
   // If the NVVM IR has some of reqntid* specified, then output
   // the reqntid directive, and set the unspecified ones to 1.
-  // If none of reqntid* is specified, don't output reqntid directive.
-  unsigned reqntidx, reqntidy, reqntidz;
-  bool specified = false;
-  if (!getReqNTIDx(F, reqntidx))
-reqntidx = 1;
-  else
-specified = true;
-  if (!getReqNTIDy(F, reqntidy))
-reqntidy = 1;
-  else
-specified = true;
-  if (!getReqNTIDz(F, reqntidz))
-reqntidz = 1;
-  else
-specified = true;
-
-  if (specified)
-O << ".reqntid " << reqntidx << ", " << reqntidy << ", " << reqntidz
+  // If none of Reqntid* is specified, don't output reqntid directive.
+  unsigned Reqntidx, Reqntidy, Reqntidz;
+  Reqntidx = Reqntidy = Reqntidz = 1;
+  bool ReqSpecified = false;
+  ReqSpecified |= getReqNTIDx(F, Reqntidx);
+  ReqSpecified |= getReqNTIDy(F, Reqntidy);
+  ReqSpecified |= getReqNTIDz(F, Reqntidz);
+
+  if (ReqSpecified)
+O << ".reqntid " << Reqntidx << ", " << Reqntidy << ", " << Reqntidz
   << "\n";
 
   // If the NVVM IR has some of maxntid* specified, then output
   // the maxntid directive, and set the unspecified ones to 1.
   // If none of maxntid* is specified, don't output maxntid directive.
-  unsigned maxntidx, maxntidy, maxntidz;
-  specified = false;
-  if (!getMaxNTIDx(F, maxntidx))
-maxntidx = 1;
-  else
-specified = true;
-  if (!getMaxNTIDy(F, maxntidy))
-maxntidy = 1;
-  else
-specified = true;
-  if (!getMaxNTIDz(F, maxntidz))
-maxntidz = 1;
-  else
-specified = true;
-
-  if (specified)
-O << ".maxntid " << maxntidx << ", " << maxntidy << ", " << maxntidz
+  unsigned Maxntidx, Maxntidy, Maxntidz;
+  Maxntidx = Maxntidy = Maxntidz = 1;
+  bool MaxSpecified = false;
+  MaxSpecified |= getMaxNTIDx(F, Maxntidx);
+  MaxSpecified |= getMaxNTIDy(F, Maxntidy);
+  MaxSpecified |= getMaxNTIDz(F, Maxntidz);
+
+  if (MaxSpecified)
+O << ".maxntid " << Maxntidx << ", " << Maxntidy << ", " << Maxntidz
   << "\n";
 
-  unsigned mincta;
-  if (getMinCTASm(F, mincta))
-O << ".minnctapersm " << mincta << "\n";
+  unsigned Mincta = 0;
+  if (getMinCTASm(F, Mincta))
+O << ".minnctapersm " << Mincta << "\n";
 
-  unsigned maxnreg;
-  if (getMaxNReg(F, maxnreg))
-O << ".maxnreg " << maxnreg << "\n";
+  unsigned Maxnreg = 0;
+  if (getMaxNReg(F, Maxnreg))
+O << ".maxnreg " << Maxnreg << "\n";
+
+  unsigned Maxclusterrank = 0;

jchlanda wrote:

Sure, done in: 261840a8bc58258b0e6ce45dd72e7e918a77c692

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


[clang] [Driver] Support -fsanitize=cfi-icall on loongarch64 (PR #67310)

2023-09-25 Thread via cfe-commits

https://github.com/Ami-zhang created 
https://github.com/llvm/llvm-project/pull/67310

None

>From a8a8b30c472b88815e373132198ee97f3658869a Mon Sep 17 00:00:00 2001
From: zhanglimin 
Date: Thu, 31 Aug 2023 15:04:17 +0800
Subject: [PATCH] [Driver] Support -fsanitize=cfi-icall on loongarch64

---
 clang/lib/Driver/ToolChain.cpp | 3 ++-
 clang/test/Driver/fsanitize.c  | 1 +
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index 31245964c4baab3..ab19166f18c2dcf 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -1319,7 +1319,8 @@ SanitizerMask ToolChain::getSupportedSanitizers() const {
   if (getTriple().getArch() == llvm::Triple::x86 ||
   getTriple().getArch() == llvm::Triple::x86_64 ||
   getTriple().getArch() == llvm::Triple::arm || getTriple().isWasm() ||
-  getTriple().isAArch64() || getTriple().isRISCV())
+  getTriple().isAArch64() || getTriple().isRISCV() ||
+  getTriple().isLoongArch64())
 Res |= SanitizerKind::CFIICall;
   if (getTriple().getArch() == llvm::Triple::x86_64 ||
   getTriple().isAArch64(64) || getTriple().isRISCV())
diff --git a/clang/test/Driver/fsanitize.c b/clang/test/Driver/fsanitize.c
index 19e10f6043123fb..9eb800b0d9e2c7f 100644
--- a/clang/test/Driver/fsanitize.c
+++ b/clang/test/Driver/fsanitize.c
@@ -600,6 +600,7 @@
 // RUN: %clang --target=aarch64_be -fvisibility=hidden -fsanitize=cfi -flto 
-resource-dir=%S/Inputs/resource_dir -c %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-CFI
 // RUN: %clang --target=riscv32 -fvisibility=hidden -fsanitize=cfi -flto 
-resource-dir=%S/Inputs/resource_dir -c %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-CFI
 // RUN: %clang --target=riscv64 -fvisibility=hidden -fsanitize=cfi -flto 
-resource-dir=%S/Inputs/resource_dir -c %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-CFI
+// RUN: %clang --target=loongarch64 -fvisibility=hidden -fsanitize=cfi -flto 
-resource-dir=%S/Inputs/resource_dir -c %s -### 2>&1 | FileCheck %s 
--check-prefix=CHECK-CFI
 // CHECK-CFI: 
-emit-llvm-bc{{.*}}-fsanitize=cfi-derived-cast,cfi-icall,cfi-mfcall,cfi-unrelated-cast,cfi-nvcall,cfi-vcall
 // CHECK-CFI-NOMFCALL: 
-emit-llvm-bc{{.*}}-fsanitize=cfi-derived-cast,cfi-icall,cfi-unrelated-cast,cfi-nvcall,cfi-vcall
 // CHECK-CFI-DCAST: -emit-llvm-bc{{.*}}-fsanitize=cfi-derived-cast

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


[clang] [clang][dataflow] Remove buggy assertion. (PR #67311)

2023-09-25 Thread via cfe-commits

https://github.com/martinboehme created 
https://github.com/llvm/llvm-project/pull/67311

The assertion fails on the test TransferTest.EvaluateBlockWithUnreachablePreds
(which I think, ironically, was introuced in the same patch as the assertion).

This just wasn't obvious because the assertion is inside an `LLVM_DEBUG` block
and is thus only executed if the command-line flag `-debug` is passed. We don't
have any CI builds that do this, so it's almost guaranteed that assertions like
this will start failing over time (if they ever passed in the first place --
which I'm not sure about here).

It's not clear to me whether there's _some_ assertion we might be able to make
here -- I've looked at this for a while but haven't been able to come up with
anything obvious. For the time being, I think it's best to simply delete the
assertion.


>From f51c74eb8ec4f84f388dd25b8de724118a49f13c Mon Sep 17 00:00:00 2001
From: Martin Braenne 
Date: Mon, 25 Sep 2023 11:04:53 +
Subject: [PATCH] [clang][dataflow] Remove buggy assertion.

The assertion fails on the test TransferTest.EvaluateBlockWithUnreachablePreds
(which I think, ironically, was introuced in the same patch as the assertion).

This just wasn't obvious because the assertion is inside an `LLVM_DEBUG` block
and is thus only executed if the command-line flag `-debug` is passed. We don't
have any CI builds that do this, so it's almost guaranteed that assertions like
this will start failing over time (if they ever passed in the first place --
which I'm not sure about here).

It's not clear to me whether there's _some_ assertion we might be able to make
here -- I've looked at this for a while but haven't been able to come up with
anything obvious. For the time being, I think it's best to simply delete the
assertion.
---
 clang/lib/Analysis/FlowSensitive/Transfer.cpp | 14 +-
 1 file changed, 1 insertion(+), 13 deletions(-)

diff --git a/clang/lib/Analysis/FlowSensitive/Transfer.cpp 
b/clang/lib/Analysis/FlowSensitive/Transfer.cpp
index 2414a1cc026af5f..2e4fa1ae9600f29 100644
--- a/clang/lib/Analysis/FlowSensitive/Transfer.cpp
+++ b/clang/lib/Analysis/FlowSensitive/Transfer.cpp
@@ -43,20 +43,8 @@ const Environment *StmtToEnvMap::getEnvironment(const Stmt 
&S) const {
   if (!CFCtx.isBlockReachable(*BlockIt->getSecond()))
 return nullptr;
   const auto &State = BlockToState[BlockIt->getSecond()->getBlockID()];
-  if (!(State)) {
-LLVM_DEBUG({
-  // State can be null when this block is unreachable from the block that
-  // called this method.
-  bool hasUnreachableEdgeFromPred = false;
-  for (auto B : BlockIt->getSecond()->preds())
-if (!B) {
-  hasUnreachableEdgeFromPred = true;
-  break;
-}
-  assert(hasUnreachableEdgeFromPred);
-});
+  if (!(State))
 return nullptr;
-  }
   return &State->Env;
 }
 

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


[clang] [clang][dataflow] Remove buggy assertion. (PR #67311)

2023-09-25 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang


Changes

The assertion fails on the test TransferTest.EvaluateBlockWithUnreachablePreds
(which I think, ironically, was introuced in the same patch as the assertion).

This just wasn't obvious because the assertion is inside an `LLVM_DEBUG` block
and is thus only executed if the command-line flag `-debug` is passed. We don't
have any CI builds that do this, so it's almost guaranteed that assertions like
this will start failing over time (if they ever passed in the first place --
which I'm not sure about here).

It's not clear to me whether there's _some_ assertion we might be able to make
here -- I've looked at this for a while but haven't been able to come up with
anything obvious. For the time being, I think it's best to simply delete the
assertion.


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


1 Files Affected:

- (modified) clang/lib/Analysis/FlowSensitive/Transfer.cpp (+1-13) 


``diff
diff --git a/clang/lib/Analysis/FlowSensitive/Transfer.cpp 
b/clang/lib/Analysis/FlowSensitive/Transfer.cpp
index 2414a1cc026af5f..2e4fa1ae9600f29 100644
--- a/clang/lib/Analysis/FlowSensitive/Transfer.cpp
+++ b/clang/lib/Analysis/FlowSensitive/Transfer.cpp
@@ -43,20 +43,8 @@ const Environment *StmtToEnvMap::getEnvironment(const Stmt 
&S) const {
   if (!CFCtx.isBlockReachable(*BlockIt->getSecond()))
 return nullptr;
   const auto &State = BlockToState[BlockIt->getSecond()->getBlockID()];
-  if (!(State)) {
-LLVM_DEBUG({
-  // State can be null when this block is unreachable from the block that
-  // called this method.
-  bool hasUnreachableEdgeFromPred = false;
-  for (auto B : BlockIt->getSecond()->preds())
-if (!B) {
-  hasUnreachableEdgeFromPred = true;
-  break;
-}
-  assert(hasUnreachableEdgeFromPred);
-});
+  if (!(State))
 return nullptr;
-  }
   return &State->Env;
 }
 

``




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


[clang] AMDGPU: Duplicate instead of COPY constants from VGPR to SGPR (PR #66882)

2023-09-25 Thread via cfe-commits

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


[clang] [clang][dataflow] Avoid putting an assertion in an `LLVM_DEBUG` block. (PR #67313)

2023-09-25 Thread via cfe-commits

https://github.com/martinboehme created 
https://github.com/llvm/llvm-project/pull/67313

`LLVM_DEBUG` blocks are only run if the `-debug` command line flag is passed.
We don't do this in any of our CI builds, so the assertion has limited value and
it's likely it will start failing over time.


>From 88189183e3562ddc48239d213efffec791b413a2 Mon Sep 17 00:00:00 2001
From: Martin Braenne 
Date: Mon, 25 Sep 2023 11:16:54 +
Subject: [PATCH] [clang][dataflow] Avoid putting an assertion in an
 `LLVM_DEBUG` block.

`LLVM_DEBUG` blocks are only run if the `-debug` command line flag is passed.
We don't do this in any of our CI builds, so the assertion has limited value and
it's likely it will start failing over time.
---
 clang/lib/Analysis/FlowSensitive/Transfer.cpp | 28 +++
 1 file changed, 16 insertions(+), 12 deletions(-)

diff --git a/clang/lib/Analysis/FlowSensitive/Transfer.cpp 
b/clang/lib/Analysis/FlowSensitive/Transfer.cpp
index 2414a1cc026af5f..2ad3f9d7c94a80c 100644
--- a/clang/lib/Analysis/FlowSensitive/Transfer.cpp
+++ b/clang/lib/Analysis/FlowSensitive/Transfer.cpp
@@ -696,19 +696,23 @@ class TransferVisitor : public 
ConstStmtVisitor {
   FieldLocs.insert({Field, &Loc});
 }
 
-LLVM_DEBUG({
-  // Check that we satisfy the invariant that a `RecordStorageLoation`
-  // contains exactly the set of modeled fields for that type.
-  // `ModeledFields` includes fields from all the bases, but only the
-  // modeled ones. However, if a class type is initialized with an
-  // `InitListExpr`, all fields in the class, including those from base
-  // classes, are included in the set of modeled fields. The code above
-  // should therefore populate exactly the modeled fields.
-  auto ModeledFields = 
Env.getDataflowAnalysisContext().getModeledFields(Type);
-  assert(ModeledFields.size() == FieldLocs.size());
+// Check that we satisfy the invariant that a `RecordStorageLoation`
+// contains exactly the set of modeled fields for that type.
+// `ModeledFields` includes fields from all the bases, but only the
+// modeled ones. However, if a class type is initialized with an
+// `InitListExpr`, all fields in the class, including those from base
+// classes, are included in the set of modeled fields. The code above
+// should therefore populate exactly the modeled fields.
+assert([&]() {
+  auto ModeledFields =
+  Env.getDataflowAnalysisContext().getModeledFields(Type);
+  if (ModeledFields.size() != FieldLocs.size())
+return false;
   for ([[maybe_unused]] auto [Field, Loc] : FieldLocs)
-assert(ModeledFields.contains(cast_or_null(Field)));
-});
+if (!ModeledFields.contains(cast_or_null(Field)))
+  return false;
+  return true;
+}());
 
 auto &Loc =
 Env.getDataflowAnalysisContext().arena().create(

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


[clang] [clang][dataflow] Avoid putting an assertion in an `LLVM_DEBUG` block. (PR #67313)

2023-09-25 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-analysis


Changes

`LLVM_DEBUG` blocks are only run if the `-debug` command line flag is passed.
We don't do this in any of our CI builds, so the assertion has limited value and
it's likely it will start failing over time.


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


1 Files Affected:

- (modified) clang/lib/Analysis/FlowSensitive/Transfer.cpp (+16-12) 


``diff
diff --git a/clang/lib/Analysis/FlowSensitive/Transfer.cpp 
b/clang/lib/Analysis/FlowSensitive/Transfer.cpp
index 2414a1cc026af5f..2ad3f9d7c94a80c 100644
--- a/clang/lib/Analysis/FlowSensitive/Transfer.cpp
+++ b/clang/lib/Analysis/FlowSensitive/Transfer.cpp
@@ -696,19 +696,23 @@ class TransferVisitor : public 
ConstStmtVisitor {
   FieldLocs.insert({Field, &Loc});
 }
 
-LLVM_DEBUG({
-  // Check that we satisfy the invariant that a `RecordStorageLoation`
-  // contains exactly the set of modeled fields for that type.
-  // `ModeledFields` includes fields from all the bases, but only the
-  // modeled ones. However, if a class type is initialized with an
-  // `InitListExpr`, all fields in the class, including those from base
-  // classes, are included in the set of modeled fields. The code above
-  // should therefore populate exactly the modeled fields.
-  auto ModeledFields = 
Env.getDataflowAnalysisContext().getModeledFields(Type);
-  assert(ModeledFields.size() == FieldLocs.size());
+// Check that we satisfy the invariant that a `RecordStorageLoation`
+// contains exactly the set of modeled fields for that type.
+// `ModeledFields` includes fields from all the bases, but only the
+// modeled ones. However, if a class type is initialized with an
+// `InitListExpr`, all fields in the class, including those from base
+// classes, are included in the set of modeled fields. The code above
+// should therefore populate exactly the modeled fields.
+assert([&]() {
+  auto ModeledFields =
+  Env.getDataflowAnalysisContext().getModeledFields(Type);
+  if (ModeledFields.size() != FieldLocs.size())
+return false;
   for ([[maybe_unused]] auto [Field, Loc] : FieldLocs)
-assert(ModeledFields.contains(cast_or_null(Field)));
-});
+if (!ModeledFields.contains(cast_or_null(Field)))
+  return false;
+  return true;
+}());
 
 auto &Loc =
 Env.getDataflowAnalysisContext().arena().create(

``




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


[clang-tools-extra] [clang-tidy] add modernize-use-std-numbers (PR #66583)

2023-09-25 Thread via cfe-commits

https://github.com/5chmidti updated 
https://github.com/llvm/llvm-project/pull/66583

>From 8f5e9e6024b0db8f251625669adbc5d607da83cb Mon Sep 17 00:00:00 2001
From: Julian Schmidt <44101708+5chmi...@users.noreply.github.com>
Date: Sat, 16 Sep 2023 16:24:13 +0200
Subject: [PATCH 1/9] [clang-tidy] add modernize-use-std-numbers check

This check finds constants and function calls to math functions that can be 
replaced
with c++20's mathematical constants ('numbers' header) and offers fixit-hints.
Does not match the use of variables or macros with that value and instead, 
offers a replacement
at the definition of said variables and macros.
---
 .../clang-tidy/modernize/CMakeLists.txt   |   1 +
 .../modernize/ModernizeTidyModule.cpp |   3 +
 .../modernize/UseStdNumbersCheck.cpp  | 377 ++
 .../clang-tidy/modernize/UseStdNumbersCheck.h |  37 ++
 clang-tools-extra/docs/ReleaseNotes.rst   |   6 +
 .../docs/clang-tidy/checks/list.rst   |   3 +-
 .../checks/modernize/use-std-numbers.rst  |  25 ++
 .../checkers/modernize/use-std-numbers.cpp| 205 ++
 8 files changed, 656 insertions(+), 1 deletion(-)
 create mode 100644 
clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp
 create mode 100644 clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/modernize/use-std-numbers.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-numbers.cpp

diff --git a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
index 717c400c4790330..d82353d74fbd0d4 100644
--- a/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/modernize/CMakeLists.txt
@@ -16,6 +16,7 @@ add_clang_library(clangTidyModernizeModule
   MakeSharedCheck.cpp
   MakeSmartPtrCheck.cpp
   MakeUniqueCheck.cpp
+  UseStdNumbersCheck.cpp
   ModernizeTidyModule.cpp
   PassByValueCheck.cpp
   RawStringLiteralCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp 
b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
index 73751cf2705068d..73584e20166f66a 100644
--- a/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/ModernizeTidyModule.cpp
@@ -18,6 +18,7 @@
 #include "MacroToEnumCheck.h"
 #include "MakeSharedCheck.h"
 #include "MakeUniqueCheck.h"
+#include "UseStdNumbersCheck.h"
 #include "PassByValueCheck.h"
 #include "RawStringLiteralCheck.h"
 #include "RedundantVoidArgCheck.h"
@@ -65,6 +66,8 @@ class ModernizeModule : public ClangTidyModule {
 CheckFactories.registerCheck("modernize-macro-to-enum");
 CheckFactories.registerCheck("modernize-make-shared");
 CheckFactories.registerCheck("modernize-make-unique");
+CheckFactories.registerCheck(
+"modernize-use-std-numbers");
 CheckFactories.registerCheck("modernize-pass-by-value");
 CheckFactories.registerCheck("modernize-use-std-print");
 CheckFactories.registerCheck(
diff --git a/clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp
new file mode 100644
index 000..c23dc6671013bc3
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/modernize/UseStdNumbersCheck.cpp
@@ -0,0 +1,377 @@
+//===--- UseStdNumbersCheck.cpp - clang_tidy -===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX_License_Identifier: Apache_2.0 WITH LLVM_exception
+//
+//===--===//
+
+#include "UseStdNumbersCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Expr.h"
+#include "clang/AST/Stmt.h"
+#include "clang/AST/Type.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/ASTMatchers/ASTMatchersInternal.h"
+#include "clang/ASTMatchers/ASTMatchersMacros.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Basic/TokenKinds.h"
+#include "clang/Lex/PPCallbacks.h"
+#include "clang/Lex/Preprocessor.h"
+#include "clang/Lex/Token.h"
+#include "clang/Tooling/Transformer/RewriteRule.h"
+#include "clang/Tooling/Transformer/Stencil.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/MathExtras.h"
+#include 
+#include 
+
+namespace {
+using namespace clang::ast_matchers;
+using clang::ast_matchers::internal::Matcher;
+using clang::transformer::addInclude;
+using clang::transformer::applyFirst;
+using clang::transformer::ASTEdit;
+using clang::transformer::cat;
+using clang::transformer::changeTo;
+using clang::transformer::edit;
+using clang::transformer::EditGenerator;
+using clang::transformer::flattenVector;
+using clang::transformer::RewriteRuleWith;
+using llvm::StringRef;
+
+constexpr double Pi = 3.1415926535897932384

[clang] AMDGPU: Duplicate instead of COPY constants from VGPR to SGPR (PR #66882)

2023-09-25 Thread via cfe-commits

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


[clang] Introduce paged vector (PR #66430)

2023-09-25 Thread Giulio Eulisse via cfe-commits

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


[clang] AMDGPU: Duplicate instead of COPY constants from VGPR to SGPR (PR #66882)

2023-09-25 Thread Jan Patrick Lehr via cfe-commits

jplehr wrote:

It appears that this change made the AMDGPU OpenMP buildbot unhappy
https://lab.llvm.org/buildbot/#/builders/193/builds/39050

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


[clang] Introduce paged vector (PR #66430)

2023-09-25 Thread Giulio Eulisse via cfe-commits

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


[clang] Introduce paged vector (PR #66430)

2023-09-25 Thread Giulio Eulisse via cfe-commits


@@ -0,0 +1,322 @@
+//===- llvm/ADT/PagedVector.h - 'Lazyly allocated' vectors *- C++
+//-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// This file defines the PagedVector class.
+//
+//===--===//
+#ifndef LLVM_ADT_PAGEDVECTOR_H
+#define LLVM_ADT_PAGEDVECTOR_H
+
+#include "llvm/ADT/PointerIntPair.h"
+#include "llvm/Support/Allocator.h"
+#include 
+#include 
+#include 
+
+namespace llvm {
+// A vector that allocates memory in pages.
+// Order is kept, but memory is allocated only when one element of the page is
+// accessed. This introduces a level of indirection, but it is useful when you
+// have a sparsely initialised vector where the full size is allocated upfront
+// with the default constructor and elements are initialised later, on first
+// access.
+//
+// Notice that this does not have iterators, because if you
+// have iterators it probably means you are going to touch
+// all the memory in any case, so better use a std::vector in
+// the first place.
+//
+// Pages are allocated in SLAB_SIZE chunks, using the BumpPtrAllocator.
+template 
+class PagedVector {
+  static_assert(PAGE_SIZE > 0, "PAGE_SIZE must be greater than 0. Most likely "
+   "you want it to be greater than 16.");
+  // The actual number of element in the vector which can be accessed.
+  std::size_t Size = 0;
+
+  // The position of the initial element of the page in the Data vector.
+  // Pages are allocated contiguously in the Data vector.
+  mutable std::vector PageToDataIdx;
+  // Actual page data. All the page elements are added to this vector on the
+  // first access of any of the elements of the page. Elements default
+  // constructed and elements of the page are stored contiguously. The order of
+  // the elements however depends on the order of access of the pages.
+  PointerIntPair Allocator;
+
+  constexpr static uintptr_t InvalidPage = SIZE_MAX;
+
+public:
+  using value_type = T;
+
+  // Default constructor. We build our own allocator.
+  PagedVector() : Allocator(new BumpPtrAllocator, true) {}
+  PagedVector(BumpPtrAllocator *A) : Allocator(A, false) {}
+
+  ~PagedVector() {
+// If we own the allocator, delete it.
+if (Allocator.getInt() == true)
+  delete Allocator.getPointer();
+  }
+
+  // Lookup an element at position i.
+  // If the associated page is not filled, it will be filled with default
+  // constructed elements. If the associated page is filled, return the 
element.
+  T &operator[](std::size_t Index) const {
+assert(Index < Size);
+assert(Index / PAGE_SIZE < PageToDataIdx.size());
+uintptr_t &PagePtr = PageToDataIdx[Index / PAGE_SIZE];
+// If the page was not yet allocated, allocate it.
+if (PagePtr == InvalidPage) {
+  T *NewPagePtr = Allocator.getPointer()->template Allocate(PAGE_SIZE);
+  // We need to invoke the default constructor on all the elements of the
+  // page.
+  for (std::size_t I = 0; I < PAGE_SIZE; ++I)
+new (NewPagePtr + I) T();
+
+  PagePtr = reinterpret_cast(NewPagePtr);
+}
+// Dereference the element in the page.
+return *((Index % PAGE_SIZE) + reinterpret_cast(PagePtr));
+  }
+
+  // Return the capacity of the vector. I.e. the maximum size it can be 
expanded
+  // to with the resize method without allocating more pages.
+  [[nodiscard]] std::size_t capacity() const {
+return PageToDataIdx.size() * PAGE_SIZE;
+  }
+
+  // Return the size of the vector. I.e. the maximum index that can be
+  // accessed, i.e. the maximum value which was used as argument of the
+  // resize method.
+  [[nodiscard]] std::size_t size() const { return Size; }
+
+  // Expands the vector to the given NewSize number of elements.
+  // If the vector was smaller, allocates new pages as needed.
+  // It should be called only with NewSize >= Size.
+  void resize(std::size_t NewSize) {
+// Handle shrink case: delete the pages and update the size.
+if (NewSize < Size) {
+  std::size_t NewLastPage = (NewSize - 1) / PAGE_SIZE;
+  for (std::size_t I = NewLastPage + 1; I < PageToDataIdx.size(); ++I) {
+uintptr_t PagePtr = PageToDataIdx[I];
+if (PagePtr == InvalidPage)
+  continue;
+T *Page = reinterpret_cast(PagePtr);
+// We need to invoke the destructor on all the elements of the page.
+for (std::size_t J = 0; J < PAGE_SIZE; ++J)
+  Page[J].~T();
+Allocator.getPointer()->Deallocate(Page);
+  }
+  // Delete the extra ones in the new last page.
+  uintptr_t PagePtr = PageToDataIdx[NewLastPage];
+  if (PagePtr != InvalidPage) {
+T *Page = reinterpret_cast(PagePtr)

[clang] Introduce paged vector (PR #66430)

2023-09-25 Thread Giulio Eulisse via cfe-commits

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


[clang] [llvm][tblgen] Add `SourcePath` for `emitSourceFileHeader` (PR #65744)

2023-09-25 Thread via cfe-commits

cor3ntin wrote:

@tru I'd ask @AaronBallman. My vote would be to reformat.

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


[clang] [PowerPC] Support local-dynamic TLS relocation on AIX (PR #66316)

2023-09-25 Thread Felix via cfe-commits

orcguru wrote:

When a module contains three TLS LD variables

>From assembly file generated by "as -a64 -many -o"
```
02f8 (idx: 33) a[TC]:
 2f8: 00 00 00 00   
02f8:  R_TLS_LD (idx: 41) a[TL]
 2fc: 00 00 00 00   

0300 (idx: 35) _$TLSML[TC]:
 300: 00 00 00 00   
0300:  R_TLSML  (idx: 35) _$TLSML[TC]
 304: 00 00 00 00   

0308 (idx: 37) b[TC]:
 308: 00 00 00 00   
0308:  R_TLS_LD (idx: 43) b[TL]
 30c: 00 00 00 04   

0310 (idx: 39) c[TC]:
 310: 00 00 00 00   
0310:  R_TLS_LD (idx: 45) c[TL]
 314: 00 00 00 08   
```

Object mode output:
```
02f8 (idx: 31) a[TC]:
 2f8: 00 00 00 00   
02f8:  R_TLS_LD (idx: 39) a[TL]
 2fc: 00 00 00 00   

0300 (idx: 33) _$TLSML[TC]:
 300: 00 00 00 00   
0300:  R_TLSML  (idx: 33) _$TLSML[TC]
 304: 00 00 00 00   

0308 (idx: 35) b[TC]:
 308: 00 00 00 00   
0308:  R_TLS_LD (idx: 41) b[TL]
 30c: 00 00 00 00   

0310 (idx: 37) c[TC]:
 310: 00 00 00 00   
0310:  R_TLS_LD (idx: 43) c[TL]
 314: 00 00 00 00   
```

Obj mode had wrong offset.

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


[clang] b7ff032 - [Documentation] Replace recommonmark by myst-parser (#65664)

2023-09-25 Thread via cfe-commits

Author: cor3ntin
Date: 2023-09-25T14:02:39+02:00
New Revision: b7ff03206d668cd5a620a9d4e1b22ea112ed56e3

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

LOG: [Documentation] Replace recommonmark by myst-parser (#65664)

Recommonmark has been deprecated, then archived last year. This was
tracked by: https://github.com/llvm/llvm-iwg/issues/30

See https://github.com/readthedocs/recommonmark

This patch migrates all our doc to use myst

Additional details for bot maintainers: 
https://discourse.llvm.org/t/maintenance-required-on-sphinx-build-bots/73612

Added: 


Modified: 
.github/workflows/release-tasks.yml
clang/docs/conf.py
flang/docs/Aliasing.md
flang/docs/ArrayComposition.md
flang/docs/BijectiveInternalNameUniquing.md
flang/docs/C++17.md
flang/docs/C++style.md
flang/docs/Calls.md
flang/docs/Character.md
flang/docs/ComplexOperations.md
flang/docs/ControlFlowGraph.md
flang/docs/DesignGuideline.md
flang/docs/DoConcurrent.md
flang/docs/Extensions.md
flang/docs/FIRArrayOperations.md
flang/docs/FlangDriver.md
flang/docs/FortranFeatureHistory.md
flang/docs/FortranForCProgrammers.md
flang/docs/FortranIR.md
flang/docs/FortranLLVMTestSuite.md
flang/docs/GettingInvolved.md
flang/docs/GettingStarted.md
flang/docs/IORuntimeInternals.md
flang/docs/ImplementingASemanticCheck.md
flang/docs/IntrinsicTypes.md
flang/docs/Intrinsics.md
flang/docs/LabelResolution.md
flang/docs/ModFiles.md
flang/docs/OpenACC.md
flang/docs/OpenMP-semantics.md
flang/docs/Overview.md
flang/docs/ParserCombinators.md
flang/docs/Parsing.md
flang/docs/Preprocessing.md
flang/docs/RuntimeDescriptor.md
flang/docs/RuntimeTypeInfo.md
flang/docs/Semantics.md
flang/docs/conf.py
flang/docs/index.md
llvm/docs/GwpAsan.rst
llvm/docs/MarkdownQuickstartTemplate.md
llvm/docs/SphinxQuickstartTemplate.rst
llvm/docs/conf.py
llvm/utils/release/build-docs.sh

Removed: 




diff  --git a/.github/workflows/release-tasks.yml 
b/.github/workflows/release-tasks.yml
index 013714005d1124e..656b8c49c556173 100644
--- a/.github/workflows/release-tasks.yml
+++ b/.github/workflows/release-tasks.yml
@@ -24,6 +24,9 @@ jobs:
   release_version=$(echo "${{ github.ref_name }}" | sed 
's/llvmorg-//g')
   echo "release-version=$release_version" >> "$GITHUB_OUTPUT"
 
+  - name: Checkout LLVM
+uses: actions/checkout@v4
+
   - name: Install Dependencies
 run: |
   sudo apt-get update
@@ -31,14 +34,9 @@ jobs:
   doxygen \
   graphviz \
   python3-github \
-  python3-recommonmark \
-  python3-sphinx \
   ninja-build \
   texlive-font-utils
-  pip3 install --user sphinx-markdown-tables
-
-  - name: Checkout LLVM
-uses: actions/checkout@v4
+  pip3 install --user -r ./llvm/docs/requirements.txt
 
   - name: Create Release
 run: |

diff  --git a/clang/docs/conf.py b/clang/docs/conf.py
index de31a5dcd068eac..ca310026f53e2a9 100644
--- a/clang/docs/conf.py
+++ b/clang/docs/conf.py
@@ -32,26 +32,11 @@
 # Add any paths that contain templates here, relative to this directory.
 templates_path = ["_templates"]
 
-# The suffix of source filenames.
-source_suffix = {
-".rst": "restructuredtext",
-}
 
-try:
-import recommonmark
-except ImportError:
-# manpages do not use any .md sources
-if not tags.has("builder-man"):
-raise
-else:
-import sphinx
-
-if sphinx.version_info >= (3, 0):
-# This requires 0.5 or later.
-extensions.append("recommonmark")
-else:
-source_parsers = {".md": "recommonmark.parser.CommonMarkParser"}
-source_suffix[".md"] = "markdown"
+import sphinx
+
+if sphinx.version_info >= (3, 0):
+extensions.append("myst_parser")
 
 # The encoding of source files.
 # source_encoding = 'utf-8-sig'

diff  --git a/flang/docs/Aliasing.md b/flang/docs/Aliasing.md
index f2805c731477160..652b766541fd467 100644
--- a/flang/docs/Aliasing.md
+++ b/flang/docs/Aliasing.md
@@ -8,9 +8,10 @@
 
 # Aliasing in Fortran
 
-```eval_rst
-.. contents::
-   :local:
+```{contents}
+---
+local:
+---
 ```
 
 ## Introduction

diff  --git a/flang/docs/ArrayComposition.md b/flang/docs/ArrayComposition.md
index 9e61abe5670f370..8de1c760d281a04 100644
--- a/flang/docs/ArrayComposition.md
+++ b/flang/docs/ArrayComposition.md
@@ -8,9 +8,10 @@
 
 # Array Composition
 
-```eval_rst
-.. contents::
-   :local:
+```{contents}
+---
+local:
+---
 ```
 
 This note attempts to describe the motivation for and design of an

diff  --git a/flang/docs/BijectiveInternalNameUniquing.md 
b/flang/docs/Bijective

[clang] [Documentation] Replace recommonmark by myst-parser (PR #65664)

2023-09-25 Thread via cfe-commits

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


[clang] [Driver] Remove FreeBSD/riscv32 support (PR #67277)

2023-09-25 Thread Ed Maste via cfe-commits

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

Sure; we're generally moving away from supporting any 32-bit platforms so it is 
exceedingly unlikely that we would add riscv32 support.

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


[clang] Introduce paged vector (PR #66430)

2023-09-25 Thread Giulio Eulisse via cfe-commits

https://github.com/ktf updated https://github.com/llvm/llvm-project/pull/66430

>From 4b02b55cccd73b0fe3efea52054735fca6e6c159 Mon Sep 17 00:00:00 2001
From: Giulio Eulisse <10544+...@users.noreply.github.com>
Date: Thu, 14 Sep 2023 21:58:21 +0200
Subject: [PATCH] Introduce PagedVector class

The goal of the class is to be an (almost) drop in replacement for
SmallVector and std::vector when those are presized and filled later,
as it happens in SourceManager and ASTReader.

By splitting the actual vector in pages of the same size and allocating
the pages only when they are needed, using this containers reduces the
memory usage by a factor 4 for the cases relevant to the ALICE
experiment ROOT / cling usage.
---
 clang/include/clang/Basic/SourceManager.h |   3 +-
 clang/include/clang/Serialization/ASTReader.h |   5 +-
 clang/lib/Basic/SourceManager.cpp |  10 +-
 clang/lib/Serialization/ASTReader.cpp |   5 +-
 llvm/docs/ProgrammersManual.rst   |  33 ++
 llvm/include/llvm/ADT/PagedVector.h   | 323 +
 llvm/unittests/ADT/CMakeLists.txt |   1 +
 llvm/unittests/ADT/PagedVectorTest.cpp| 342 ++
 8 files changed, 712 insertions(+), 10 deletions(-)
 create mode 100644 llvm/include/llvm/ADT/PagedVector.h
 create mode 100644 llvm/unittests/ADT/PagedVectorTest.cpp

diff --git a/clang/include/clang/Basic/SourceManager.h 
b/clang/include/clang/Basic/SourceManager.h
index 2f846502d6f3327..e37caa2252532f9 100644
--- a/clang/include/clang/Basic/SourceManager.h
+++ b/clang/include/clang/Basic/SourceManager.h
@@ -43,6 +43,7 @@
 #include "llvm/ADT/DenseMap.h"
 #include "llvm/ADT/DenseSet.h"
 #include "llvm/ADT/IntrusiveRefCntPtr.h"
+#include "llvm/ADT/PagedVector.h"
 #include "llvm/ADT/PointerIntPair.h"
 #include "llvm/ADT/SmallVector.h"
 #include "llvm/ADT/StringRef.h"
@@ -699,7 +700,7 @@ class SourceManager : public RefCountedBase {
   ///
   /// Negative FileIDs are indexes into this table. To get from ID to an index,
   /// use (-ID - 2).
-  SmallVector LoadedSLocEntryTable;
+  llvm::PagedVector LoadedSLocEntryTable;
 
   /// The starting offset of the next local SLocEntry.
   ///
diff --git a/clang/include/clang/Serialization/ASTReader.h 
b/clang/include/clang/Serialization/ASTReader.h
index dc1eb21c27801fe..65e19c6e44cf571 100644
--- a/clang/include/clang/Serialization/ASTReader.h
+++ b/clang/include/clang/Serialization/ASTReader.h
@@ -38,6 +38,7 @@
 #include "llvm/ADT/DenseSet.h"
 #include "llvm/ADT/IntrusiveRefCntPtr.h"
 #include "llvm/ADT/MapVector.h"
+#include "llvm/ADT/PagedVector.h"
 #include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SetVector.h"
 #include "llvm/ADT/SmallPtrSet.h"
@@ -487,7 +488,7 @@ class ASTReader
   ///
   /// When the pointer at index I is non-NULL, the type with
   /// ID = (I + 1) << FastQual::Width has already been loaded
-  std::vector TypesLoaded;
+  llvm::PagedVector TypesLoaded;
 
   using GlobalTypeMapType =
   ContinuousRangeMap;
@@ -501,7 +502,7 @@ class ASTReader
   ///
   /// When the pointer at index I is non-NULL, the declaration with ID
   /// = I + 1 has already been loaded.
-  std::vector DeclsLoaded;
+  llvm::PagedVector DeclsLoaded;
 
   using GlobalDeclMapType =
   ContinuousRangeMap;
diff --git a/clang/lib/Basic/SourceManager.cpp 
b/clang/lib/Basic/SourceManager.cpp
index 0521ac7b30339ab..7fa8b8096ac4931 100644
--- a/clang/lib/Basic/SourceManager.cpp
+++ b/clang/lib/Basic/SourceManager.cpp
@@ -2344,11 +2344,11 @@ SourceManager::MemoryBufferSizes 
SourceManager::getMemoryBufferSizes() const {
 }
 
 size_t SourceManager::getDataStructureSizes() const {
-  size_t size = llvm::capacity_in_bytes(MemBufferInfos)
-+ llvm::capacity_in_bytes(LocalSLocEntryTable)
-+ llvm::capacity_in_bytes(LoadedSLocEntryTable)
-+ llvm::capacity_in_bytes(SLocEntryLoaded)
-+ llvm::capacity_in_bytes(FileInfos);
+  size_t size = llvm::capacity_in_bytes(MemBufferInfos) +
+llvm::capacity_in_bytes(LocalSLocEntryTable) +
+llvm::capacity_in_bytes(LoadedSLocEntryTable) +
+llvm::capacity_in_bytes(SLocEntryLoaded) +
+llvm::capacity_in_bytes(FileInfos);
 
   if (OverriddenFilesInfo)
 size += llvm::capacity_in_bytes(OverriddenFilesInfo->OverriddenFiles);
diff --git a/clang/lib/Serialization/ASTReader.cpp 
b/clang/lib/Serialization/ASTReader.cpp
index 0952244d037a77c..badd54987af18dd 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -7944,9 +7944,10 @@ void ASTReader::PrintStats() {
   std::fprintf(stderr, "*** AST File Statistics:\n");
 
   unsigned NumTypesLoaded =
-  TypesLoaded.size() - llvm::count(TypesLoaded, QualType());
+  TypesLoaded.size() - llvm::count(TypesLoaded.materialised(), QualType());
   unsigned NumDeclsLoaded =
-  DeclsLoaded.size() - llvm::count(DeclsLoaded, (Decl *)nullptr);
+  DeclsLoaded.size() -
+  llvm::count(DeclsLoaded.materialised(), 

[clang] [PowerPC] Support local-dynamic TLS relocation on AIX (PR #66316)

2023-09-25 Thread Felix via cfe-commits

orcguru wrote:

Missing an update in `recordRelocation()` similar as the patch: 
https://reviews.llvm.org/D155415.

Working on it now.

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


[clang] [clang-cl] Fix value of __FUNCTION__ and __FUNC__ in MSVC mode for c++. (PR #66120)

2023-09-25 Thread Zahira Ammarguellat via cfe-commits

zahiraam wrote:

> This implementation has bugs, see [#66114 
> (comment)](https://github.com/llvm/llvm-project/issues/66114#issuecomment-1732319259)

@RIscRIpt Thanks. Will look at them.

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


[PATCH] D155775: [HIP][Clang][Driver][RFC] Add driver support for C++ Parallel Algorithm Offload

2023-09-25 Thread Yaxun Liu via Phabricator via cfe-commits
yaxunl accepted this revision.
yaxunl added a comment.
This revision is now accepted and ready to land.

LGTM. Thanks


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D155775/new/

https://reviews.llvm.org/D155775

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


[clang] [Clang] Fix missing diagnostic for non-standard layout type in `offsetof` (PR #65246)

2023-09-25 Thread Louis Dionne via cfe-commits

ldionne wrote:

> Thank you for your review! Here are some comments and my thoughts.
> 
> > Note that you should probably rebase your patch onto main and force-push to 
> > update the PR
> 
> Does it mean that I can rebase and force-push since (it should be avoided in 
> normal case but) this is a special case?

That's what I usually do. Do we have any Github workflow documentation that 
mentions we shouldn't force-push to update PRs? If so, I am not aware of it.

> 
> > So... should we strive to eradicate this from libc++ in the first place, or 
> > should we just silence the warning. WDYT?
> 
> I think it's good to only silence the warning and (if necessary) leave some 
> TODO comments about the `offsetof` usage because it's undesirable for this 
> patch to be larger than it needs to be..

My question is about the desired end state of libc++, not whether that end 
state should be achieved in this specific patch or not.

> 
> > Also, given that it is conditionally supported in C++17, I assume this 
> > warning doesn't trigger at all in C++17 mode, right?
> 
> I believe the purpose of this warning is to tell you that your program works 
> now, but may not be compiled with another compiler. So the similar warning 
> should appear even in C++17 mode. I chedked and found that 
> `_FirstPaddingByte<>` is ~standard layout but non-POD~ both standard-layout 
> and POD (I checked them with `std::is_standard_layout` and `std::is_pod`). 
> Using `offsetof` with a standard-layout class is supported in C++17, so I 
> guess there is no warning

What `T` type did you use to check that `_FirstPaddingByte<>` was standard 
layout and POD? Certainly `_FirstPaddingByte<>` can't be standard layout if the 
`T` it holds is not standard layout?

@philnik777 do you have thoughts on this?

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


[clang] AMDGPU: Duplicate instead of COPY constants from VGPR to SGPR (PR #66882)

2023-09-25 Thread via cfe-commits

rovka wrote:

@jplehr Thanks for pointing that out. I tried reproducing the failure locally 
(Ubuntu 22.04 running on AMD hardware) but couldn't manage to run the tests for 
amdgcn-amd-amdhsa, although the AMDGPU target is in LLVM_TARGETS_TO_BUILD. I'm 
assuming this is because I'm missing some packages but I couldn't figure out 
which. Do I need to install a full ROCm for this to work? Alternatively, could 
you or someone else get me an IR reproducer from the buildbot or a similar 
machine? 

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


[clang-tools-extra] AMDGPU: Duplicate instead of COPY constants from VGPR to SGPR (PR #66882)

2023-09-25 Thread via cfe-commits

rovka wrote:

@jplehr Thanks for pointing that out. I tried reproducing the failure locally 
(Ubuntu 22.04 running on AMD hardware) but couldn't manage to run the tests for 
amdgcn-amd-amdhsa, although the AMDGPU target is in LLVM_TARGETS_TO_BUILD. I'm 
assuming this is because I'm missing some packages but I couldn't figure out 
which. Do I need to install a full ROCm for this to work? Alternatively, could 
you or someone else get me an IR reproducer from the buildbot or a similar 
machine? 

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


[clang] [llvm][tblgen] Add `SourcePath` for `emitSourceFileHeader` (PR #65744)

2023-09-25 Thread Renato Golin via cfe-commits

rengolin wrote:

> @tru I'd ask @AaronBallman. My vote would be to reformat.

Not as a requirement for this patch, I imagine?

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


[clang] [clang-analysis]Fix false positive in mutation check when using pointer to member function (PR #66846)

2023-09-25 Thread Congcong Cai via cfe-commits

https://github.com/HerrCai0907 updated 
https://github.com/llvm/llvm-project/pull/66846

>From 6d8e737ab1a883371a7491b676e1e202a087701f Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Tue, 19 Sep 2023 16:15:20 +0800
Subject: [PATCH 1/2] [clang-analysis]Fix false positive in mutation check when
 using pointer to member function

Fixes: #66204
---
 clang-tools-extra/docs/ReleaseNotes.rst   |  4 +++
 .../misc/const-correctness-values.cpp | 13 
 clang/docs/ReleaseNotes.rst   |  2 ++
 clang/lib/Analysis/ExprMutationAnalyzer.cpp   | 22 --
 .../Analysis/ExprMutationAnalyzerTest.cpp | 30 +++
 5 files changed, 68 insertions(+), 3 deletions(-)

diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index a2cde526a8c04d9..4370059653dfc09 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -222,6 +222,10 @@ Changes in existing checks
   ` check to provide fixes for
   ``inline`` namespaces in the same format as :program:`clang-format`.
 
+- Improved :doc:`misc-const-correctness
+  ` check to avoid false positive 
when
+  using pointer to member function.
+
 - Improved :doc:`misc-include-cleaner
   ` check by adding option
   `DeduplicateFindings` to output one finding per symbol occurrence.
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values.cpp
index 186e3cf5a179b24..cb6bfcc1dccba39 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values.cpp
@@ -976,3 +976,16 @@ void auto_usage_variants() {
   auto &auto_td1 = auto_td0;
   auto *auto_td2 = &auto_td0;
 }
+
+using PointerToMemberFunction = int (Value::*)();
+void member_pointer(Value &x, PointerToMemberFunction m) {
+  Value &member_pointer_tmp = x;
+  (member_pointer_tmp.*m)();
+}
+
+using PointerToConstMemberFunction = int (Value::*)() const;
+void member_pointer_const(Value &x, PointerToConstMemberFunction m) {
+  Value &member_pointer_tmp = x;
+  // CHECK-MESSAGES:[[@LINE-1]]:3: warning: variable 'member_pointer_tmp' of 
type 'Value &' can be declared 'const'
+  (member_pointer_tmp.*m)();
+}
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 5b2a6349a5b15bf..1594e4d012a4aff 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -384,6 +384,8 @@ Static Analyzer
   bitwise shift operators produce undefined behavior (because some operand is
   negative or too large).
 
+- Fix false positive in mutation check when using pointer to member function.
+
 .. _release-notes-sanitizers:
 
 Sanitizers
diff --git a/clang/lib/Analysis/ExprMutationAnalyzer.cpp 
b/clang/lib/Analysis/ExprMutationAnalyzer.cpp
index 90803830ff41949..fcd909be88c999b 100644
--- a/clang/lib/Analysis/ExprMutationAnalyzer.cpp
+++ b/clang/lib/Analysis/ExprMutationAnalyzer.cpp
@@ -100,6 +100,20 @@ AST_MATCHER(CXXTypeidExpr, isPotentiallyEvaluated) {
   return Node.isPotentiallyEvaluated();
 }
 
+AST_MATCHER(CXXMemberCallExpr, isConstCallee) {
+  const auto *CalleeDecl = Node.getCalleeDecl();
+  const auto *VD = dyn_cast_or_null(CalleeDecl);
+  if (!VD)
+return false;
+  const auto T = VD->getType().getCanonicalType();
+  const auto *MPT = dyn_cast(T);
+  const auto *FPT = MPT ? cast(MPT->getPointeeType())
+: dyn_cast(T);
+  if (!FPT)
+return false;
+  return FPT->isConst();
+}
+
 AST_MATCHER_P(GenericSelectionExpr, hasControllingExpr,
   ast_matchers::internal::Matcher, InnerMatcher) {
   if (Node.isTypePredicate())
@@ -274,8 +288,8 @@ const Stmt *ExprMutationAnalyzer::findDirectMutation(const 
Expr *Exp) {
   const auto NonConstMethod = cxxMethodDecl(unless(isConst()));
 
   const auto AsNonConstThis = expr(anyOf(
-  cxxMemberCallExpr(callee(NonConstMethod),
-on(canResolveToExpr(equalsNode(Exp,
+  cxxMemberCallExpr(on(canResolveToExpr(equalsNode(Exp))),
+unless(isConstCallee())),
   cxxOperatorCallExpr(callee(NonConstMethod),
   hasArgument(0, canResolveToExpr(equalsNode(Exp,
   // In case of a templated type, calling overloaded operators is not
@@ -391,7 +405,9 @@ const Stmt *ExprMutationAnalyzer::findMemberMutation(const 
Expr *Exp) {
   match(findAll(expr(anyOf(memberExpr(hasObjectExpression(
canResolveToExpr(equalsNode(Exp,
cxxDependentScopeMemberExpr(hasObjectExpression(
-   canResolveToExpr(equalsNode(Exp))
+   canResolveToExpr(equalsNode(Exp,
+   binaryOperator(allOf(hasOperatorName(".*"),
+hasLHS(equalsN

[clang-tools-extra] [clang-analysis]Fix false positive in mutation check when using pointer to member function (PR #66846)

2023-09-25 Thread Congcong Cai via cfe-commits

https://github.com/HerrCai0907 updated 
https://github.com/llvm/llvm-project/pull/66846

>From 6d8e737ab1a883371a7491b676e1e202a087701f Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Tue, 19 Sep 2023 16:15:20 +0800
Subject: [PATCH 1/2] [clang-analysis]Fix false positive in mutation check when
 using pointer to member function

Fixes: #66204
---
 clang-tools-extra/docs/ReleaseNotes.rst   |  4 +++
 .../misc/const-correctness-values.cpp | 13 
 clang/docs/ReleaseNotes.rst   |  2 ++
 clang/lib/Analysis/ExprMutationAnalyzer.cpp   | 22 --
 .../Analysis/ExprMutationAnalyzerTest.cpp | 30 +++
 5 files changed, 68 insertions(+), 3 deletions(-)

diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index a2cde526a8c04d9..4370059653dfc09 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -222,6 +222,10 @@ Changes in existing checks
   ` check to provide fixes for
   ``inline`` namespaces in the same format as :program:`clang-format`.
 
+- Improved :doc:`misc-const-correctness
+  ` check to avoid false positive 
when
+  using pointer to member function.
+
 - Improved :doc:`misc-include-cleaner
   ` check by adding option
   `DeduplicateFindings` to output one finding per symbol occurrence.
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values.cpp
index 186e3cf5a179b24..cb6bfcc1dccba39 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values.cpp
@@ -976,3 +976,16 @@ void auto_usage_variants() {
   auto &auto_td1 = auto_td0;
   auto *auto_td2 = &auto_td0;
 }
+
+using PointerToMemberFunction = int (Value::*)();
+void member_pointer(Value &x, PointerToMemberFunction m) {
+  Value &member_pointer_tmp = x;
+  (member_pointer_tmp.*m)();
+}
+
+using PointerToConstMemberFunction = int (Value::*)() const;
+void member_pointer_const(Value &x, PointerToConstMemberFunction m) {
+  Value &member_pointer_tmp = x;
+  // CHECK-MESSAGES:[[@LINE-1]]:3: warning: variable 'member_pointer_tmp' of 
type 'Value &' can be declared 'const'
+  (member_pointer_tmp.*m)();
+}
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 5b2a6349a5b15bf..1594e4d012a4aff 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -384,6 +384,8 @@ Static Analyzer
   bitwise shift operators produce undefined behavior (because some operand is
   negative or too large).
 
+- Fix false positive in mutation check when using pointer to member function.
+
 .. _release-notes-sanitizers:
 
 Sanitizers
diff --git a/clang/lib/Analysis/ExprMutationAnalyzer.cpp 
b/clang/lib/Analysis/ExprMutationAnalyzer.cpp
index 90803830ff41949..fcd909be88c999b 100644
--- a/clang/lib/Analysis/ExprMutationAnalyzer.cpp
+++ b/clang/lib/Analysis/ExprMutationAnalyzer.cpp
@@ -100,6 +100,20 @@ AST_MATCHER(CXXTypeidExpr, isPotentiallyEvaluated) {
   return Node.isPotentiallyEvaluated();
 }
 
+AST_MATCHER(CXXMemberCallExpr, isConstCallee) {
+  const auto *CalleeDecl = Node.getCalleeDecl();
+  const auto *VD = dyn_cast_or_null(CalleeDecl);
+  if (!VD)
+return false;
+  const auto T = VD->getType().getCanonicalType();
+  const auto *MPT = dyn_cast(T);
+  const auto *FPT = MPT ? cast(MPT->getPointeeType())
+: dyn_cast(T);
+  if (!FPT)
+return false;
+  return FPT->isConst();
+}
+
 AST_MATCHER_P(GenericSelectionExpr, hasControllingExpr,
   ast_matchers::internal::Matcher, InnerMatcher) {
   if (Node.isTypePredicate())
@@ -274,8 +288,8 @@ const Stmt *ExprMutationAnalyzer::findDirectMutation(const 
Expr *Exp) {
   const auto NonConstMethod = cxxMethodDecl(unless(isConst()));
 
   const auto AsNonConstThis = expr(anyOf(
-  cxxMemberCallExpr(callee(NonConstMethod),
-on(canResolveToExpr(equalsNode(Exp,
+  cxxMemberCallExpr(on(canResolveToExpr(equalsNode(Exp))),
+unless(isConstCallee())),
   cxxOperatorCallExpr(callee(NonConstMethod),
   hasArgument(0, canResolveToExpr(equalsNode(Exp,
   // In case of a templated type, calling overloaded operators is not
@@ -391,7 +405,9 @@ const Stmt *ExprMutationAnalyzer::findMemberMutation(const 
Expr *Exp) {
   match(findAll(expr(anyOf(memberExpr(hasObjectExpression(
canResolveToExpr(equalsNode(Exp,
cxxDependentScopeMemberExpr(hasObjectExpression(
-   canResolveToExpr(equalsNode(Exp))
+   canResolveToExpr(equalsNode(Exp,
+   binaryOperator(allOf(hasOperatorName(".*"),
+hasLHS(equalsN

[clang] [llvm][tblgen] Add `SourcePath` for `emitSourceFileHeader` (PR #65744)

2023-09-25 Thread Aaron Ballman via cfe-commits

AaronBallman wrote:

> > @tru I'd ask @AaronBallman. My vote would be to reformat.
> 
> Not as a requirement for this patch, I imagine?

If we wanted to reformat the file as an NFC commit (before or after this 
patch), that would be fine. But let's please not reformat as part of this patch 
(that makes code archeology much harder).

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


[clang] [llvm][tblgen] Add `SourcePath` for `emitSourceFileHeader` (PR #65744)

2023-09-25 Thread Aaron Ballman via cfe-commits

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

LGTM (fine to land without tests as it only adds comments to generated header 
files)

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


[clang] 247b7d0 - [cmake] Add LLVM_FORCE_VC_REVISION option (#67125)

2023-09-25 Thread via cfe-commits

Author: David Truby
Date: 2023-09-25T14:32:52+01:00
New Revision: 247b7d068497de085b7fd66c6531034afa9709f0

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

LOG: [cmake] Add LLVM_FORCE_VC_REVISION option (#67125)

This patch adds a LLVM_FORCE_VC_REVISION option to force a custom
VC revision to be included instead of trying to fetch one from a
git command. This is helpful in environments where git is not
available or is non-functional but the vc revision is available
through some other means.

Added: 


Modified: 
clang/lib/Basic/CMakeLists.txt
flang/lib/Common/CMakeLists.txt
lld/Common/CMakeLists.txt
lldb/source/Version/CMakeLists.txt
llvm/CMakeLists.txt
llvm/cmake/modules/GenerateVersionFromVCS.cmake
llvm/docs/CMake.rst
llvm/include/llvm/Support/CMakeLists.txt

Removed: 




diff  --git a/clang/lib/Basic/CMakeLists.txt b/clang/lib/Basic/CMakeLists.txt
index db59d7dd96da0a4..36ccf7d0809453e 100644
--- a/clang/lib/Basic/CMakeLists.txt
+++ b/clang/lib/Basic/CMakeLists.txt
@@ -39,6 +39,8 @@ add_custom_command(OUTPUT "${version_inc}"
"-DHEADER_FILE=${version_inc}"
"-DLLVM_VC_REPOSITORY=${llvm_vc_repository}"
"-DLLVM_VC_REVISION=${llvm_vc_revision}"
+   "-DLLVM_FORCE_VC_REVISION=${LLVM_FORCE_VC_REVISION}"
+   
"-DLLVM_FORCE_VC_REPOSITORY=${LLVM_FORCE_VC_REPOSITORY}"
-P "${generate_vcs_version_script}")
 
 # Mark the generated header as being generated.

diff  --git a/flang/lib/Common/CMakeLists.txt b/flang/lib/Common/CMakeLists.txt
index 81cee82e04b88ae..c6f818ad27cd19a 100644
--- a/flang/lib/Common/CMakeLists.txt
+++ b/flang/lib/Common/CMakeLists.txt
@@ -12,7 +12,7 @@ endif()
 if(flang_vc AND LLVM_APPEND_VC_REV)
   set(flang_source_dir ${FLANG_SOURCE_DIR})
 endif()
-
+ 
 # Create custom target to generate the VC revision include.
 add_custom_command(OUTPUT "${version_inc}"
   DEPENDS "${llvm_vc}" "${flang_vc}" "${generate_vcs_version_script}"
@@ -20,6 +20,8 @@ add_custom_command(OUTPUT "${version_inc}"
"-DLLVM_SOURCE_DIR=${llvm_source_dir}"
"-DFLANG_SOURCE_DIR=${flang_source_dir}"
"-DHEADER_FILE=${version_inc}"
+   "-DLLVM_FORCE_VC_REVISION=${LLVM_FORCE_VC_REVISION}"
+   
"-DLLVM_FORCE_VC_REPOSITORY=${LLVM_FORCE_VC_REPOSITORY}"
-P "${generate_vcs_version_script}")
 
 # Mark the generated header as being generated.

diff  --git a/lld/Common/CMakeLists.txt b/lld/Common/CMakeLists.txt
index c975da2a49b6bda..4f503d04f7844f7 100644
--- a/lld/Common/CMakeLists.txt
+++ b/lld/Common/CMakeLists.txt
@@ -13,6 +13,8 @@ add_custom_command(OUTPUT "${version_inc}"
   COMMAND ${CMAKE_COMMAND} "-DNAMES=LLD"
   "-DLLD_SOURCE_DIR=${lld_source_dir}"
   "-DHEADER_FILE=${version_inc}"
+  "-DLLVM_FORCE_VC_REVISION=${LLVM_FORCE_VC_REVISION}"
+  "-DLLVM_FORCE_VC_REPOSITORY=${LLVM_FORCE_VC_REPOSITORY}"
   -P "${generate_vcs_version_script}")
 
 # Mark the generated header as being generated.

diff  --git a/lldb/source/Version/CMakeLists.txt 
b/lldb/source/Version/CMakeLists.txt
index c1393b5dd6e6b62..90fe53d52cc5d05 100644
--- a/lldb/source/Version/CMakeLists.txt
+++ b/lldb/source/Version/CMakeLists.txt
@@ -17,6 +17,8 @@ add_custom_command(OUTPUT "${vcs_version_inc}"
   COMMAND ${CMAKE_COMMAND} "-DNAMES=LLDB"
"-DLLDB_SOURCE_DIR=${lldb_source_dir}"
"-DHEADER_FILE=${vcs_version_inc}"
+   "-DLLVM_FORCE_VC_REVISION=${LLVM_FORCE_VC_REVISION}"
+   
"-DLLVM_FORCE_VC_REPOSITORY=${LLVM_FORCE_VC_REPOSITORY}"
-P "${generate_vcs_version_script}")
 
 set_source_files_properties("${vcs_version_inc}"

diff  --git a/llvm/CMakeLists.txt b/llvm/CMakeLists.txt
index fa39c7554de1f61..5985256498dcbb2 100644
--- a/llvm/CMakeLists.txt
+++ b/llvm/CMakeLists.txt
@@ -325,6 +325,12 @@ include(VersionFromVCS)
 option(LLVM_APPEND_VC_REV
   "Embed the version control system revision in LLVM" ON)
 
+set(LLVM_FORCE_VC_REVISION
+  "" CACHE STRING "Force custom VC revision for LLVM_APPEND_VC_REV")
+
+set(LLVM_FORCE_VC_REPOSITORY
+  "" CACHE STRING "Force custom VC repository for LLVM_APPEND_VC_REV")
+
 option(LLVM_TOOL_LLVM_DRIVER_BUILD "Enables building the llvm multicall tool" 
OFF)
 
 set(PACKAGE_NAME LLVM)

diff  --git a/llvm/cmake/modules/GenerateVersionFromVCS.cmake 
b/llvm/cmake/modules/GenerateVersionFromVCS.cmake
index 9cd780e5aa162c0..1b3b2946e62b25c 100644
--- a/llvm/cmake/modules/GenerateVersionFromVCS.cmake
+++ b/llvm/cmake/modules/GenerateVersionFromVCS.cm

[clang] [cmake] Add LLVM_FORCE_VC_REVISION option (PR #67125)

2023-09-25 Thread David Truby via cfe-commits

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


[clang] [clang-analysis]Fix false positive in mutation check when using pointer to member function (PR #66846)

2023-09-25 Thread Congcong Cai via cfe-commits

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


[clang-tools-extra] [clang-analysis]Fix false positive in mutation check when using pointer to member function (PR #66846)

2023-09-25 Thread Congcong Cai via cfe-commits

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


[clang] [clang-analysis]Fix false positive in mutation check when using pointer to member function (PR #66846)

2023-09-25 Thread Congcong Cai via cfe-commits


@@ -274,8 +288,8 @@ const Stmt *ExprMutationAnalyzer::findDirectMutation(const 
Expr *Exp) {
   const auto NonConstMethod = cxxMethodDecl(unless(isConst()));
 
   const auto AsNonConstThis = expr(anyOf(
-  cxxMemberCallExpr(callee(NonConstMethod),
-on(canResolveToExpr(equalsNode(Exp,
+  cxxMemberCallExpr(on(canResolveToExpr(equalsNode(Exp))),
+unless(isConstCallee())),

HerrCai0907 wrote:

see this test case

```c++
buildASTFromCode("struct X {};"
 "using T = int (X::*)() const;"
 "void f(X &x, T m) { X &ref = x; (ref.*m)(); }");
```

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


[clang-tools-extra] [clang-analysis]Fix false positive in mutation check when using pointer to member function (PR #66846)

2023-09-25 Thread Congcong Cai via cfe-commits


@@ -274,8 +288,8 @@ const Stmt *ExprMutationAnalyzer::findDirectMutation(const 
Expr *Exp) {
   const auto NonConstMethod = cxxMethodDecl(unless(isConst()));
 
   const auto AsNonConstThis = expr(anyOf(
-  cxxMemberCallExpr(callee(NonConstMethod),
-on(canResolveToExpr(equalsNode(Exp,
+  cxxMemberCallExpr(on(canResolveToExpr(equalsNode(Exp))),
+unless(isConstCallee())),

HerrCai0907 wrote:

see this test case

```c++
buildASTFromCode("struct X {};"
 "using T = int (X::*)() const;"
 "void f(X &x, T m) { X &ref = x; (ref.*m)(); }");
```

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


[PATCH] D156711: [clang][ExprConstant] Fix assertion failure in constant expression folding

2023-09-25 Thread antoine moynault via Phabricator via cfe-commits
antmo abandoned this revision.
antmo added a comment.

yes indeed you fixed this @shafik. thanks for the update. abandoning this 
revision


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D156711/new/

https://reviews.llvm.org/D156711

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


[clang] c1300ef - [Driver] Remove FreeBSD/riscv32 support (#67277)

2023-09-25 Thread via cfe-commits

Author: Brad Smith
Date: 2023-09-25T09:43:10-04:00
New Revision: c1300efc78a17374065744c8985b4598fb8c3166

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

LOG: [Driver] Remove FreeBSD/riscv32 support (#67277)

FreeBSD does not support riscv32 and has no intention of doing so.

Added: 


Modified: 
clang/lib/Basic/Targets.cpp
clang/lib/Driver/ToolChains/FreeBSD.cpp
clang/test/Driver/freebsd.c
clang/test/Preprocessor/predefined-macros-no-warnings.c

Removed: 




diff  --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp
index 35d1d0d2c45c530..80822f65662850d 100644
--- a/clang/lib/Basic/Targets.cpp
+++ b/clang/lib/Basic/Targets.cpp
@@ -430,9 +430,6 @@ std::unique_ptr AllocateTarget(const 
llvm::Triple &Triple,
 
   case llvm::Triple::riscv32:
 switch (os) {
-case llvm::Triple::FreeBSD:
-  return std::make_unique>(Triple,
-Opts);
 case llvm::Triple::NetBSD:
   return std::make_unique>(Triple,
Opts);

diff  --git a/clang/lib/Driver/ToolChains/FreeBSD.cpp 
b/clang/lib/Driver/ToolChains/FreeBSD.cpp
index 4c46861bbbd74ef..67a8bb863b3b6b0 100644
--- a/clang/lib/Driver/ToolChains/FreeBSD.cpp
+++ b/clang/lib/Driver/ToolChains/FreeBSD.cpp
@@ -210,11 +210,6 @@ void freebsd::Linker::ConstructJob(Compilation &C, const 
JobAction &JA,
 else
   CmdArgs.push_back("elf64ltsmip_fbsd");
 break;
-  case llvm::Triple::riscv32:
-CmdArgs.push_back("-m");
-CmdArgs.push_back("elf32lriscv");
-CmdArgs.push_back("-X");
-break;
   case llvm::Triple::riscv64:
 CmdArgs.push_back("-m");
 CmdArgs.push_back("elf64lriscv");

diff  --git a/clang/test/Driver/freebsd.c b/clang/test/Driver/freebsd.c
index 8ac0cb011638a8a..afa0a17249851b3 100644
--- a/clang/test/Driver/freebsd.c
+++ b/clang/test/Driver/freebsd.c
@@ -73,9 +73,6 @@
 //
 // Check that RISC-V passes the correct linker emulation.
 //
-// RUN: %clang --target=riscv32-freebsd -### %s %s 2>&1 \
-// RUN:   | FileCheck --check-prefix=CHECK-RV32I-LD %s
-// CHECK-RV32I-LD: ld{{.*}}" {{.*}} "-m" "elf32lriscv"
 // RUN: %clang --target=riscv64-freebsd -### %s %s 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-RV64I-LD %s
 // CHECK-RV64I-LD: ld{{.*}}" {{.*}} "-m" "elf64lriscv"

diff  --git a/clang/test/Preprocessor/predefined-macros-no-warnings.c 
b/clang/test/Preprocessor/predefined-macros-no-warnings.c
index 56573af6fc7ba82..e0617f8de4da385 100644
--- a/clang/test/Preprocessor/predefined-macros-no-warnings.c
+++ b/clang/test/Preprocessor/predefined-macros-no-warnings.c
@@ -103,7 +103,6 @@
 // RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple amdgcn
 // RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple r600
 // RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple riscv32
-// RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple riscv32-freebsd
 // RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple riscv32-linux
 // RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple riscv64
 // RUN: %clang_cc1 %s -Eonly -Wsystem-headers -Werror -triple riscv64-freebsd



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


[clang] [Driver] Remove FreeBSD/riscv32 support (PR #67277)

2023-09-25 Thread Brad Smith via cfe-commits

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


[clang] [clang] Fix pretty-printing assume_aligned attributes (PR #67331)

2023-09-25 Thread Balazs Benics via cfe-commits

https://github.com/steakhal created 
https://github.com/llvm/llvm-project/pull/67331

Inside `writePrettyPrintFunction()`, we check if we need to emit the given 
argument:
```C++
if (!arg->isOptional() || arg->getIsOmitted() == "false") {
FoundNonOptArg = true;
continue;
}
```
For the `AssumeAligned` attribute, the second argument was optional, but the 
`getIsOmitted()` returned `false`, thus we treated this argument as 
**non-optional** in the end because of that disjunction.

It was because `getIsOmitted()` did not account for `Expr *` type, and returned 
`false` on the fallthrough branch.
The fix is easy and generic: just check if the type is a pointer.

Fixes #67156

>From b106eda609baf83c200cb1ac6a96e3b40ab0bfbe Mon Sep 17 00:00:00 2001
From: Balazs Benics 
Date: Mon, 25 Sep 2023 15:37:34 +0200
Subject: [PATCH] [clang] Fix pretty-printing assume_aligned attributes

Inside `writePrettyPrintFunction()`, we check if we need to emit the
given argument:
```C++
if (!arg->isOptional() || arg->getIsOmitted() == "false") {
FoundNonOptArg = true;
continue;
}
```
For the `AssumeAligned` attribute, the second argument was optional, but
the `getIsOmitted()` returned `false`, thus we treated this argument as
**non-optional** in the end because of that disjunction.

It was because `getIsOmitted()` did not account for `Expr *` type, and
returned `false` on the fallthrough branch.
The fix is easy and generic: just check if the type is a pointer.

Fixes #67156
---
 clang/test/AST/attr-print-emit.cpp| 6 ++
 clang/utils/TableGen/ClangAttrEmitter.cpp | 7 ---
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/clang/test/AST/attr-print-emit.cpp 
b/clang/test/AST/attr-print-emit.cpp
index cc7413baf10e87a..8c48eb92daba5ee 100644
--- a/clang/test/AST/attr-print-emit.cpp
+++ b/clang/test/AST/attr-print-emit.cpp
@@ -2,6 +2,12 @@
 // RUN: %clang -emit-ast -o %t.ast %s
 // RUN: %clang_cc1 %t.ast -ast-print | FileCheck %s
 
+// CHECK: void *aa() __attribute__((assume_aligned(64)));
+void *aa() __attribute__((assume_aligned(64)));
+
+// CHECK: void *aa2() __attribute__((assume_aligned(64, 8)));
+void *aa2() __attribute__((assume_aligned(64, 8)));
+
 // CHECK: void xla(int a) __attribute__((xray_log_args(1)));
 void xla(int a) __attribute__((xray_log_args(1)));
 
diff --git a/clang/utils/TableGen/ClangAttrEmitter.cpp 
b/clang/utils/TableGen/ClangAttrEmitter.cpp
index 7ea09058c3d39f2..56e87e5d05948a3 100644
--- a/clang/utils/TableGen/ClangAttrEmitter.cpp
+++ b/clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -320,10 +320,11 @@ namespace {
 }
 
 std::string getIsOmitted() const override {
-  if (type == "IdentifierInfo *")
-return "!get" + getUpperName().str() + "()";
-  if (type == "TypeSourceInfo *")
+  StringRef T = type;
+  if (T == "TypeSourceInfo *")
 return "!get" + getUpperName().str() + "Loc()";
+  if (T.ends_with(" *"))
+return "!get" + getUpperName().str() + "()";
   if (type == "ParamIdx")
 return "!get" + getUpperName().str() + "().isValid()";
   return "false";

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


[clang] [clang] Fix pretty-printing assume_aligned attributes (PR #67331)

2023-09-25 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang


Changes

Inside `writePrettyPrintFunction()`, we check if we need to emit the given 
argument:
```C++
if (!arg->isOptional() || arg->getIsOmitted() == "false") {
FoundNonOptArg = true;
continue;
}
```
For the `AssumeAligned` attribute, the second argument was optional, but the 
`getIsOmitted()` returned `false`, thus we treated this argument as 
**non-optional** in the end because of that disjunction.

It was because `getIsOmitted()` did not account for `Expr *` type, and returned 
`false` on the fallthrough branch.
The fix is easy and generic: just check if the type is a pointer.

Fixes #67156

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


2 Files Affected:

- (modified) clang/test/AST/attr-print-emit.cpp (+6) 
- (modified) clang/utils/TableGen/ClangAttrEmitter.cpp (+4-3) 


``diff
diff --git a/clang/test/AST/attr-print-emit.cpp 
b/clang/test/AST/attr-print-emit.cpp
index cc7413baf10e87a..8c48eb92daba5ee 100644
--- a/clang/test/AST/attr-print-emit.cpp
+++ b/clang/test/AST/attr-print-emit.cpp
@@ -2,6 +2,12 @@
 // RUN: %clang -emit-ast -o %t.ast %s
 // RUN: %clang_cc1 %t.ast -ast-print | FileCheck %s
 
+// CHECK: void *aa() __attribute__((assume_aligned(64)));
+void *aa() __attribute__((assume_aligned(64)));
+
+// CHECK: void *aa2() __attribute__((assume_aligned(64, 8)));
+void *aa2() __attribute__((assume_aligned(64, 8)));
+
 // CHECK: void xla(int a) __attribute__((xray_log_args(1)));
 void xla(int a) __attribute__((xray_log_args(1)));
 
diff --git a/clang/utils/TableGen/ClangAttrEmitter.cpp 
b/clang/utils/TableGen/ClangAttrEmitter.cpp
index 7ea09058c3d39f2..56e87e5d05948a3 100644
--- a/clang/utils/TableGen/ClangAttrEmitter.cpp
+++ b/clang/utils/TableGen/ClangAttrEmitter.cpp
@@ -320,10 +320,11 @@ namespace {
 }
 
 std::string getIsOmitted() const override {
-  if (type == "IdentifierInfo *")
-return "!get" + getUpperName().str() + "()";
-  if (type == "TypeSourceInfo *")
+  StringRef T = type;
+  if (T == "TypeSourceInfo *")
 return "!get" + getUpperName().str() + "Loc()";
+  if (T.ends_with(" *"))
+return "!get" + getUpperName().str() + "()";
   if (type == "ParamIdx")
 return "!get" + getUpperName().str() + "().isValid()";
   return "false";

``




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


[clang] [PowerPC] Support local-dynamic TLS relocation on AIX (PR #66316)

2023-09-25 Thread Felix via cfe-commits

orcguru wrote:

> Missing an update in `recordRelocation()` similar as the patch: 
> https://reviews.llvm.org/D155415.
> 
> Working on it now.

Done. Added one test case aix-tls-ld-xcoff-reloc-large.ll to track this kind of 
issue. If full set of test case is necessary, please let me know, and I will 
add the remaining ones (reloc-large32, reloc, reloc-32).

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


[clang] [flang][Driver] Support -rpath, -shared, and -static in the frontend (PR #66702)

2023-09-25 Thread Tarun Prabhu via cfe-commits

tarunprabhu wrote:

> I think Windows does not work likely because `ld` is absent in PATH. You need 
> `-Bxxx/bin` to specify a directory that contains `ld`, but I don't remember 
> whether `ld.exe` is needed instead.

I think what I saw on the buildkite was Link.exe, but I don't know if that is 
always the case.


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


[clang-tools-extra] AMDGPU: Duplicate instead of COPY constants from VGPR to SGPR (PR #66882)

2023-09-25 Thread Jan Patrick Lehr via cfe-commits

jplehr wrote:

Sure, I'll look into it later today and get back to you.

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


[clang-tools-extra] [clang-analysis]Fix false positive in mutation check when using pointer to member function (PR #66846)

2023-09-25 Thread Congcong Cai via cfe-commits

https://github.com/HerrCai0907 updated 
https://github.com/llvm/llvm-project/pull/66846

>From 6d8e737ab1a883371a7491b676e1e202a087701f Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Tue, 19 Sep 2023 16:15:20 +0800
Subject: [PATCH 1/4] [clang-analysis]Fix false positive in mutation check when
 using pointer to member function

Fixes: #66204
---
 clang-tools-extra/docs/ReleaseNotes.rst   |  4 +++
 .../misc/const-correctness-values.cpp | 13 
 clang/docs/ReleaseNotes.rst   |  2 ++
 clang/lib/Analysis/ExprMutationAnalyzer.cpp   | 22 --
 .../Analysis/ExprMutationAnalyzerTest.cpp | 30 +++
 5 files changed, 68 insertions(+), 3 deletions(-)

diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index a2cde526a8c04d9..4370059653dfc09 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -222,6 +222,10 @@ Changes in existing checks
   ` check to provide fixes for
   ``inline`` namespaces in the same format as :program:`clang-format`.
 
+- Improved :doc:`misc-const-correctness
+  ` check to avoid false positive 
when
+  using pointer to member function.
+
 - Improved :doc:`misc-include-cleaner
   ` check by adding option
   `DeduplicateFindings` to output one finding per symbol occurrence.
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values.cpp
index 186e3cf5a179b24..cb6bfcc1dccba39 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values.cpp
@@ -976,3 +976,16 @@ void auto_usage_variants() {
   auto &auto_td1 = auto_td0;
   auto *auto_td2 = &auto_td0;
 }
+
+using PointerToMemberFunction = int (Value::*)();
+void member_pointer(Value &x, PointerToMemberFunction m) {
+  Value &member_pointer_tmp = x;
+  (member_pointer_tmp.*m)();
+}
+
+using PointerToConstMemberFunction = int (Value::*)() const;
+void member_pointer_const(Value &x, PointerToConstMemberFunction m) {
+  Value &member_pointer_tmp = x;
+  // CHECK-MESSAGES:[[@LINE-1]]:3: warning: variable 'member_pointer_tmp' of 
type 'Value &' can be declared 'const'
+  (member_pointer_tmp.*m)();
+}
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 5b2a6349a5b15bf..1594e4d012a4aff 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -384,6 +384,8 @@ Static Analyzer
   bitwise shift operators produce undefined behavior (because some operand is
   negative or too large).
 
+- Fix false positive in mutation check when using pointer to member function.
+
 .. _release-notes-sanitizers:
 
 Sanitizers
diff --git a/clang/lib/Analysis/ExprMutationAnalyzer.cpp 
b/clang/lib/Analysis/ExprMutationAnalyzer.cpp
index 90803830ff41949..fcd909be88c999b 100644
--- a/clang/lib/Analysis/ExprMutationAnalyzer.cpp
+++ b/clang/lib/Analysis/ExprMutationAnalyzer.cpp
@@ -100,6 +100,20 @@ AST_MATCHER(CXXTypeidExpr, isPotentiallyEvaluated) {
   return Node.isPotentiallyEvaluated();
 }
 
+AST_MATCHER(CXXMemberCallExpr, isConstCallee) {
+  const auto *CalleeDecl = Node.getCalleeDecl();
+  const auto *VD = dyn_cast_or_null(CalleeDecl);
+  if (!VD)
+return false;
+  const auto T = VD->getType().getCanonicalType();
+  const auto *MPT = dyn_cast(T);
+  const auto *FPT = MPT ? cast(MPT->getPointeeType())
+: dyn_cast(T);
+  if (!FPT)
+return false;
+  return FPT->isConst();
+}
+
 AST_MATCHER_P(GenericSelectionExpr, hasControllingExpr,
   ast_matchers::internal::Matcher, InnerMatcher) {
   if (Node.isTypePredicate())
@@ -274,8 +288,8 @@ const Stmt *ExprMutationAnalyzer::findDirectMutation(const 
Expr *Exp) {
   const auto NonConstMethod = cxxMethodDecl(unless(isConst()));
 
   const auto AsNonConstThis = expr(anyOf(
-  cxxMemberCallExpr(callee(NonConstMethod),
-on(canResolveToExpr(equalsNode(Exp,
+  cxxMemberCallExpr(on(canResolveToExpr(equalsNode(Exp))),
+unless(isConstCallee())),
   cxxOperatorCallExpr(callee(NonConstMethod),
   hasArgument(0, canResolveToExpr(equalsNode(Exp,
   // In case of a templated type, calling overloaded operators is not
@@ -391,7 +405,9 @@ const Stmt *ExprMutationAnalyzer::findMemberMutation(const 
Expr *Exp) {
   match(findAll(expr(anyOf(memberExpr(hasObjectExpression(
canResolveToExpr(equalsNode(Exp,
cxxDependentScopeMemberExpr(hasObjectExpression(
-   canResolveToExpr(equalsNode(Exp))
+   canResolveToExpr(equalsNode(Exp,
+   binaryOperator(allOf(hasOperatorName(".*"),
+hasLHS(equalsN

  1   2   3   4   >