[clang] [KeyInstr][Clang] Static variable init atom (PR #134636)

2025-05-22 Thread Orlando Cazalet-Hyams via cfe-commits

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


[clang] [llvm] [Clang][LoongArch] Add inline asm support for the `q` constraint (PR #141037)

2025-05-22 Thread WÁNG Xuěruì via cfe-commits

https://github.com/xen0n commented:

LGTM, thanks!

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


[clang] [llvm] [clang][DebugInfo] Add symbol for debugger with VTable information. (PR #130255)

2025-05-22 Thread Carlos Alberto Enciso via cfe-commits

CarlosAlbertoEnciso wrote:

> Could you remove the LLVM tests? They don't add coverage since tnhis isn't an 
> LLVM feature - as far as LLVM is concerned, this is another static member 
> variable like any other.

Removed all the LLVM tests.

> 
> Why do some of the test cases use distinct input files/headers? I'd have 
> thought these could all be written as standalone files with classes all 
> written in a single file? (easier to read the test case in isolation, no 
> implication that the header-ness matters (like this shouldn't be behaving 
> differently because some content exists in a header V not, right?))

Moved all the code into a single file. The performed checks are the same.
Uploaded updated patch.



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


[clang] [Clang] Optimize some `getBeginLoc` implementations (PR #141058)

2025-05-22 Thread via cfe-commits

https://github.com/cor3ntin updated 
https://github.com/llvm/llvm-project/pull/141058

>From 381c2219e346acfbf5b61e93fcc3233af6b7c3a7 Mon Sep 17 00:00:00 2001
From: Corentin Jabot 
Date: Wed, 21 May 2025 23:09:00 +0200
Subject: [PATCH 1/9] try optimize

---
 clang/lib/AST/Expr.cpp | 11 ++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index fe874ccd7b60f..1906e46042cad 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -1544,7 +1544,16 @@ unsigned CallExpr::offsetToTrailingObjects(StmtClass SC) 
{
 }
 
 Decl *Expr::getReferencedDeclOfCallee() {
-  Expr *CEE = IgnoreParenImpCasts();
+
+  // Optimize for the common case first
+  // (simple function or member function call)
+  // then try more exotic possibilities
+  Expr *CEE = IgnoreImpCasts();
+  if (auto *DRE = dyn_cast(CEE))
+return DRE->getDecl();
+
+  if (auto *ME = dyn_cast(CEE))
+return ME->getMemberDecl();
 
   while (auto *NTTP = dyn_cast(CEE))
 CEE = NTTP->getReplacement()->IgnoreParenImpCasts();

>From 16077ed74794645452434c9ec761d642789e09ac Mon Sep 17 00:00:00 2001
From: Corentin Jabot 
Date: Thu, 22 May 2025 00:28:05 +0200
Subject: [PATCH 2/9] remove call to getCalleeDecl

---
 clang/include/clang/AST/Expr.h|  5 +
 clang/include/clang/AST/Stmt.h|  5 +++--
 clang/lib/AST/Expr.cpp| 21 ++---
 clang/lib/Sema/SemaOpenCL.cpp |  2 +-
 clang/lib/Sema/SemaOverload.cpp   |  2 ++
 clang/lib/Serialization/ASTReaderStmt.cpp |  2 ++
 clang/lib/Serialization/ASTWriterStmt.cpp |  2 ++
 7 files changed, 25 insertions(+), 14 deletions(-)

diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index e9c3c16c87598..a8bfae2e7efda 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -3028,6 +3028,9 @@ class CallExpr : public Expr {
 
   bool hasStoredFPFeatures() const { return CallExprBits.HasFPFeatures; }
 
+  bool usesMemberSyntax() const { return 
CallExprBits.ExplicitObjectMemFunUsingMemberSyntax; }
+  void setUsesMemberSyntax(bool V = true) { 
CallExprBits.ExplicitObjectMemFunUsingMemberSyntax = V; }
+
   bool isCoroElideSafe() const { return CallExprBits.IsCoroElideSafe; }
   void setCoroElideSafe(bool V = true) { CallExprBits.IsCoroElideSafe = V; }
 
@@ -3220,6 +3223,8 @@ class CallExpr : public Expr {
   }
 };
 
+static_assert(sizeof(CallExpr) == 24);
+
 /// MemberExpr - [C99 6.5.2.3] Structure and Union Members.  X->F and X.F.
 ///
 class MemberExpr final
diff --git a/clang/include/clang/AST/Stmt.h b/clang/include/clang/AST/Stmt.h
index 336eb6d3df7e1..b3ad285ca73fd 100644
--- a/clang/include/clang/AST/Stmt.h
+++ b/clang/include/clang/AST/Stmt.h
@@ -563,10 +563,11 @@ class alignas(void *) Stmt {
 unsigned HasFPFeatures : 1;
 
 /// True if the call expression is a must-elide call to a coroutine.
+LLVM_PREFERRED_TYPE(bool)
 unsigned IsCoroElideSafe : 1;
 
-/// Padding used to align OffsetToTrailingObjects to a byte multiple.
-unsigned : 24 - 4 - NumExprBits;
+LLVM_PREFERRED_TYPE(bool)
+unsigned ExplicitObjectMemFunUsingMemberSyntax : 1;
 
 /// The offset in bytes from the this pointer to the start of the
 /// trailing objects belonging to CallExpr. Intentionally byte sized
diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index 1906e46042cad..e6ccd0904eefd 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -1484,6 +1484,8 @@ CallExpr::CallExpr(StmtClass SC, Expr *Fn, ArrayRef PreArgs,
 
   CallExprBits.HasFPFeatures = FPFeatures.requiresTrailingStorage();
   CallExprBits.IsCoroElideSafe = false;
+  CallExprBits.ExplicitObjectMemFunUsingMemberSyntax = false;
+
   if (hasStoredFPFeatures())
 setStoredFPFeatures(FPFeatures);
 }
@@ -1549,12 +1551,15 @@ Decl *Expr::getReferencedDeclOfCallee() {
   // (simple function or member function call)
   // then try more exotic possibilities
   Expr *CEE = IgnoreImpCasts();
+
   if (auto *DRE = dyn_cast(CEE))
 return DRE->getDecl();
 
   if (auto *ME = dyn_cast(CEE))
 return ME->getMemberDecl();
 
+  CEE = CEE->IgnoreParens();
+
   while (auto *NTTP = dyn_cast(CEE))
 CEE = NTTP->getReplacement()->IgnoreParenImpCasts();
 
@@ -1658,20 +1663,14 @@ SourceLocation CallExpr::getBeginLoc() const {
   // begin location should come from the first argument.
   // This does not apply to dependent calls, which are modelled with `o.f`
   // being the callee.
-  if (!isTypeDependent()) {
-if (const auto *Method =
-dyn_cast_if_present(getCalleeDecl());
-Method && Method->isExplicitObjectMemberFunction()) {
-  if (auto FirstArgLoc = getArg(0)->getBeginLoc(); FirstArgLoc.isValid()) {
-return FirstArgLoc;
-  }
+  // Because this check is expennsive, we cache the result.
+  if (usesMemberSyntax()) {
+if (auto FirstArgLoc = getArg(0)->getBeginLoc(); FirstArgLoc.isValid()) {
+  

[clang] [Clang] Optimize some `getBeginLoc` implementations (PR #141058)

2025-05-22 Thread Aaron Ballman via cfe-commits


@@ -2901,34 +2907,44 @@ class CallExpr : public Expr {
   //
   // * An optional of type FPOptionsOverride.
   //
-  // Note that we store the offset in bytes from the this pointer to the start
-  // of the trailing objects. It would be perfectly possible to compute it
-  // based on the dynamic kind of the CallExpr. However 1.) we have plenty of
-  // space in the bit-fields of Stmt. 2.) It was benchmarked to be faster to
-  // compute this once and then load the offset from the bit-fields of Stmt,
-  // instead of re-computing the offset each time the trailing objects are
-  // accessed.
+  // CallExpr subclasses are asssumed to be 32 bytes or less, and CallExpr
+  // itself is 24 bytes. To avoid having to recompute or store the offset of 
the
+  // trailing objects, we put it at 32 bytes (such that it is suitable for all
+  // subclasses) We use the 8 bytes gap left for instances of CallExpr to store
+  // the begin and end source locations. Caching the begin source location in
+  // particular as a significant impact on perf as getBeginLoc is assumed to be
+  // cheap.
+  // The layourt is as follow:
+  // CallExpr | Begin | End | Trailing Objects
+  // CXXMemberCallExpr | Trailing Objects
+  // A bit in CallExprBitfields indicates if source locations are presents.
 
+protected:
+  static constexpr unsigned offsetToTrailingObjects = 32;

AaronBallman wrote:

```suggestion
  static constexpr unsigned OffsetToTrailingObjects = 32;
```

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


[clang] [Clang] Optimize some `getBeginLoc` implementations (PR #141058)

2025-05-22 Thread Aaron Ballman via cfe-commits


@@ -1510,41 +1519,41 @@ CallExpr *CallExpr::Create(const ASTContext &Ctx, Expr 
*Fn,
   unsigned NumArgs = std::max(Args.size(), MinNumArgs);
   unsigned SizeOfTrailingObjects = CallExpr::sizeOfTrailingObjects(
   /*NumPreArgs=*/0, NumArgs, FPFeatures.requiresTrailingStorage());
-  void *Mem =
-  Ctx.Allocate(sizeof(CallExpr) + SizeOfTrailingObjects, 
alignof(CallExpr));
-  return new (Mem) CallExpr(CallExprClass, Fn, /*PreArgs=*/{}, Args, Ty, VK,
-RParenLoc, FPFeatures, MinNumArgs, UsesADL);
+  void *Mem = Ctx.Allocate(
+  sizeToAllocateForCallExprSubclass(SizeOfTrailingObjects),
+  alignof(CallExpr));
+  CallExpr *E =
+  new (Mem) CallExpr(CallExprClass, Fn, /*PreArgs=*/{}, Args, Ty, VK,
+ RParenLoc, FPFeatures, MinNumArgs, UsesADL);
+  E->updateTrailingSourceLocs();
+  return E;
 }
 
 CallExpr *CallExpr::CreateEmpty(const ASTContext &Ctx, unsigned NumArgs,
 bool HasFPFeatures, EmptyShell Empty) {
   unsigned SizeOfTrailingObjects =
   CallExpr::sizeOfTrailingObjects(/*NumPreArgs=*/0, NumArgs, 
HasFPFeatures);
-  void *Mem =
-  Ctx.Allocate(sizeof(CallExpr) + SizeOfTrailingObjects, 
alignof(CallExpr));
+  void *Mem = Ctx.Allocate(
+  sizeToAllocateForCallExprSubclass(SizeOfTrailingObjects),
+  alignof(CallExpr));
   return new (Mem)
   CallExpr(CallExprClass, /*NumPreArgs=*/0, NumArgs, HasFPFeatures, Empty);
 }
 
-unsigned CallExpr::offsetToTrailingObjects(StmtClass SC) {
-  switch (SC) {
-  case CallExprClass:
-return sizeof(CallExpr);
-  case CXXOperatorCallExprClass:
-return sizeof(CXXOperatorCallExpr);
-  case CXXMemberCallExprClass:
-return sizeof(CXXMemberCallExpr);
-  case UserDefinedLiteralClass:
-return sizeof(UserDefinedLiteral);
-  case CUDAKernelCallExprClass:
-return sizeof(CUDAKernelCallExpr);
-  default:
-llvm_unreachable("unexpected class deriving from CallExpr!");
-  }
-}
-
 Decl *Expr::getReferencedDeclOfCallee() {
-  Expr *CEE = IgnoreParenImpCasts();
+
+  // Optimize for the common case first
+  // (simple function or member function call)
+  // then try more exotic possibilities
+  Expr *CEE = IgnoreImpCasts();
+
+  if (auto *DRE = dyn_cast(CEE))
+return DRE->getDecl();
+
+  if (auto *ME = dyn_cast(CEE))
+return ME->getMemberDecl();
+
+  CEE = CEE->IgnoreParens();

AaronBallman wrote:

Warning bells going off!

>From `IgnoreParenImpCasts()`:
```
  /// Skip past any parentheses and implicit casts which might surround this
  /// expression until reaching a fixed point.
  /// FIXME: IgnoreParenImpCasts really ought to be equivalent to
  /// IgnoreParens() + IgnoreImpCasts() until reaching a fixed point. However
  /// this is currently not the case. Instead IgnoreParenImpCasts() skips:
```
Are we subtly changing behavior here?

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


[clang] [Clang] Optimize some `getBeginLoc` implementations (PR #141058)

2025-05-22 Thread Aaron Ballman via cfe-commits


@@ -1510,41 +1519,41 @@ CallExpr *CallExpr::Create(const ASTContext &Ctx, Expr 
*Fn,
   unsigned NumArgs = std::max(Args.size(), MinNumArgs);
   unsigned SizeOfTrailingObjects = CallExpr::sizeOfTrailingObjects(
   /*NumPreArgs=*/0, NumArgs, FPFeatures.requiresTrailingStorage());
-  void *Mem =
-  Ctx.Allocate(sizeof(CallExpr) + SizeOfTrailingObjects, 
alignof(CallExpr));
-  return new (Mem) CallExpr(CallExprClass, Fn, /*PreArgs=*/{}, Args, Ty, VK,
-RParenLoc, FPFeatures, MinNumArgs, UsesADL);
+  void *Mem = Ctx.Allocate(
+  sizeToAllocateForCallExprSubclass(SizeOfTrailingObjects),
+  alignof(CallExpr));
+  CallExpr *E =
+  new (Mem) CallExpr(CallExprClass, Fn, /*PreArgs=*/{}, Args, Ty, VK,
+ RParenLoc, FPFeatures, MinNumArgs, UsesADL);
+  E->updateTrailingSourceLocs();
+  return E;
 }
 
 CallExpr *CallExpr::CreateEmpty(const ASTContext &Ctx, unsigned NumArgs,
 bool HasFPFeatures, EmptyShell Empty) {
   unsigned SizeOfTrailingObjects =
   CallExpr::sizeOfTrailingObjects(/*NumPreArgs=*/0, NumArgs, 
HasFPFeatures);
-  void *Mem =
-  Ctx.Allocate(sizeof(CallExpr) + SizeOfTrailingObjects, 
alignof(CallExpr));
+  void *Mem = Ctx.Allocate(
+  sizeToAllocateForCallExprSubclass(SizeOfTrailingObjects),
+  alignof(CallExpr));
   return new (Mem)
   CallExpr(CallExprClass, /*NumPreArgs=*/0, NumArgs, HasFPFeatures, Empty);
 }
 
-unsigned CallExpr::offsetToTrailingObjects(StmtClass SC) {
-  switch (SC) {
-  case CallExprClass:
-return sizeof(CallExpr);
-  case CXXOperatorCallExprClass:
-return sizeof(CXXOperatorCallExpr);
-  case CXXMemberCallExprClass:
-return sizeof(CXXMemberCallExpr);
-  case UserDefinedLiteralClass:
-return sizeof(UserDefinedLiteral);
-  case CUDAKernelCallExprClass:
-return sizeof(CUDAKernelCallExpr);
-  default:
-llvm_unreachable("unexpected class deriving from CallExpr!");
-  }
-}
-
 Decl *Expr::getReferencedDeclOfCallee() {
-  Expr *CEE = IgnoreParenImpCasts();
+
+  // Optimize for the common case first
+  // (simple function or member function call)
+  // then try more exotic possibilities

AaronBallman wrote:

```suggestion
  // then try more exotic possibilities.
```

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


[clang] [Clang] Optimize some `getBeginLoc` implementations (PR #141058)

2025-05-22 Thread Aaron Ballman via cfe-commits


@@ -3187,9 +3216,59 @@ class CallExpr : public Expr {
   SourceLocation getRParenLoc() const { return RParenLoc; }
   void setRParenLoc(SourceLocation L) { RParenLoc = L; }
 
-  SourceLocation getBeginLoc() const LLVM_READONLY;
-  SourceLocation getEndLoc() const LLVM_READONLY;
+  template  SourceLocation getTrailingSourceLoc() const {
+static_assert(N <= 1);
+assert(CallExprBits.HasTrailingSourceLocs && "No trailing source loc");
+static_assert(sizeof(CallExpr) <=
+  offsetToTrailingObjects + 2 * sizeof(SourceLocation));
+return *reinterpret_cast(
+reinterpret_cast(this) + sizeof(CallExpr) +
+sizeof(SourceLocation) * N);
+  }
+
+  SourceLocation getBeginLoc() const {
+if (CallExprBits.HasTrailingSourceLocs)
+  return getTrailingSourceLoc<0>();
+
+if (usesMemberSyntax()) {
+  if (auto FirstArgLoc = getArg(0)->getBeginLoc(); FirstArgLoc.isValid()) {
+return FirstArgLoc;
+  }
+}
+return getCallee()->getBeginLoc();
+  }
+
+  SourceLocation getEndLoc() const {
+if (CallExprBits.HasTrailingSourceLocs)
+  return getTrailingSourceLoc<0>();
+
+SourceLocation end = getRParenLoc();

AaronBallman wrote:

```suggestion
SourceLocation End = getRParenLoc();
```

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


[clang] [Clang] Optimize some `getBeginLoc` implementations (PR #141058)

2025-05-22 Thread Aaron Ballman via cfe-commits


@@ -2901,34 +2907,44 @@ class CallExpr : public Expr {
   //
   // * An optional of type FPOptionsOverride.
   //
-  // Note that we store the offset in bytes from the this pointer to the start
-  // of the trailing objects. It would be perfectly possible to compute it
-  // based on the dynamic kind of the CallExpr. However 1.) we have plenty of
-  // space in the bit-fields of Stmt. 2.) It was benchmarked to be faster to
-  // compute this once and then load the offset from the bit-fields of Stmt,
-  // instead of re-computing the offset each time the trailing objects are
-  // accessed.
+  // CallExpr subclasses are asssumed to be 32 bytes or less, and CallExpr
+  // itself is 24 bytes. To avoid having to recompute or store the offset of 
the
+  // trailing objects, we put it at 32 bytes (such that it is suitable for all
+  // subclasses) We use the 8 bytes gap left for instances of CallExpr to store

AaronBallman wrote:

This works today, but we keep talking about moving to 64-bit source locations 
(and that's getting more important thanks to modules), what's the idea for in 
that situation? Grow the size of `CallExpr`?

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


[clang] [Clang] Optimize some `getBeginLoc` implementations (PR #141058)

2025-05-22 Thread Aaron Ballman via cfe-commits

https://github.com/AaronBallman commented:

Thank you for working on this!

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


[clang] [Clang] Optimize some `getBeginLoc` implementations (PR #141058)

2025-05-22 Thread Aaron Ballman via cfe-commits


@@ -3187,9 +3216,59 @@ class CallExpr : public Expr {
   SourceLocation getRParenLoc() const { return RParenLoc; }
   void setRParenLoc(SourceLocation L) { RParenLoc = L; }
 
-  SourceLocation getBeginLoc() const LLVM_READONLY;
-  SourceLocation getEndLoc() const LLVM_READONLY;
+  template  SourceLocation getTrailingSourceLoc() const {
+static_assert(N <= 1);
+assert(CallExprBits.HasTrailingSourceLocs && "No trailing source loc");
+static_assert(sizeof(CallExpr) <=
+  offsetToTrailingObjects + 2 * sizeof(SourceLocation));
+return *reinterpret_cast(
+reinterpret_cast(this) + sizeof(CallExpr) +
+sizeof(SourceLocation) * N);
+  }
+
+  SourceLocation getBeginLoc() const {
+if (CallExprBits.HasTrailingSourceLocs)
+  return getTrailingSourceLoc<0>();
+
+if (usesMemberSyntax()) {
+  if (auto FirstArgLoc = getArg(0)->getBeginLoc(); FirstArgLoc.isValid()) {
+return FirstArgLoc;
+  }
+}
+return getCallee()->getBeginLoc();
+  }
+
+  SourceLocation getEndLoc() const {
+if (CallExprBits.HasTrailingSourceLocs)
+  return getTrailingSourceLoc<0>();
+
+SourceLocation end = getRParenLoc();
+if (end.isInvalid() && getNumArgs() > 0 && getArg(getNumArgs() - 1))
+  end = getArg(getNumArgs() - 1)->getEndLoc();
+return end;
+  }
+
+private:
+  bool hasTrailingSourceLoc() const {
+return CallExprBits.HasTrailingSourceLocs;
+  }
 
+  void updateTrailingSourceLocs() {
+assert(!CallExprBits.HasTrailingSourceLocs &&
+   "Trailing source loc already set?");
+assert(getStmtClass() == CallExprClass &&
+   "Calling setTrailingSourceLocs on a subclass of CallExpr");
+static_assert(sizeof(CallExpr) <=
+  offsetToTrailingObjects + 2 * sizeof(SourceLocation));
+
+SourceLocation *Locs = reinterpret_cast(
+reinterpret_cast(this) + sizeof(CallExpr));

AaronBallman wrote:

`reinterpret_cast(this + 1)` ?

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


[clang] [llvm] [Clang][LoongArch] Add inline asm support for the `q` constraint (PR #141037)

2025-05-22 Thread via cfe-commits

github-actions[bot] wrote:




:warning: undef deprecator found issues in your code. :warning:



You can test this locally with the following command:


``bash
git diff -U0 --pickaxe-regex -S 
'([^a-zA-Z0-9#_-]undef[^a-zA-Z0-9_-]|UndefValue::get)' 'HEAD~1' HEAD 
llvm/test/CodeGen/LoongArch/inline-asm-constraint-q.ll 
clang/lib/Basic/Targets/LoongArch.cpp 
clang/test/CodeGen/LoongArch/inline-asm-constraints.c 
llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
``




The following files introduce new uses of undef:
 - llvm/test/CodeGen/LoongArch/inline-asm-constraint-q.ll

[Undef](https://llvm.org/docs/LangRef.html#undefined-values) is now deprecated 
and should only be used in the rare cases where no replacement is possible. For 
example, a load of uninitialized memory yields `undef`. You should use `poison` 
values for placeholders instead.

In tests, avoid using `undef` and having tests that trigger undefined behavior. 
If you need an operand with some unimportant value, you can add a new argument 
to the function and use that instead.

For example, this is considered a bad practice:
```llvm
define void @fn() {
  ...
  br i1 undef, ...
}
```

Please use the following instead:
```llvm
define void @fn(i1 %cond) {
  ...
  br i1 %cond, ...
}
```

Please refer to the [Undefined Behavior 
Manual](https://llvm.org/docs/UndefinedBehavior.html) for more information.



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


[clang] [clang][bytecode] Fix self-init diagnostics in C++23 (PR #141044)

2025-05-22 Thread Timm Baeder via cfe-commits

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


[clang] d45f1d0 - [clang][bytecode] Fix self-init diagnostics in C++23 (#141044)

2025-05-22 Thread via cfe-commits

Author: Timm Baeder
Date: 2025-05-22T14:26:52+02:00
New Revision: d45f1d08272ead39700d54dc800ce78d97170bde

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

LOG: [clang][bytecode] Fix self-init diagnostics in C++23 (#141044)

Added: 


Modified: 
clang/lib/AST/ByteCode/Interp.cpp
clang/test/AST/ByteCode/cxx23.cpp

Removed: 




diff  --git a/clang/lib/AST/ByteCode/Interp.cpp 
b/clang/lib/AST/ByteCode/Interp.cpp
index b3ac84ce9278f..7cc0d2a526480 100644
--- a/clang/lib/AST/ByteCode/Interp.cpp
+++ b/clang/lib/AST/ByteCode/Interp.cpp
@@ -670,7 +670,8 @@ bool CheckInitialized(InterpState &S, CodePtr OpPC, const 
Pointer &Ptr,
   if (const auto *VD = Ptr.getDeclDesc()->asVarDecl();
   VD && (VD->isConstexpr() || VD->hasGlobalStorage())) {
 
-if (!S.getLangOpts().CPlusPlus23 && VD == S.EvaluatingDecl) {
+if (VD == S.EvaluatingDecl &&
+!(S.getLangOpts().CPlusPlus23 && VD->getType()->isReferenceType())) {
   if (!S.getLangOpts().CPlusPlus14 &&
   !VD->getType().isConstant(S.getASTContext())) {
 // Diagnose as non-const read.

diff  --git a/clang/test/AST/ByteCode/cxx23.cpp 
b/clang/test/AST/ByteCode/cxx23.cpp
index ce18a9d473302..417d35dbca946 100644
--- a/clang/test/AST/ByteCode/cxx23.cpp
+++ b/clang/test/AST/ByteCode/cxx23.cpp
@@ -73,6 +73,12 @@ constexpr int k(int n) {
 }
 constexpr int k0 = k(0);
 
+#if __cplusplus >= 202302L
+constexpr int &b = b; // all-error {{must be initialized by a constant 
expression}} \
+  // all-note {{initializer of 'b' is not a constant 
expression}} \
+  // all-note {{declared here}}
+#endif
+
 namespace StaticLambdas {
   constexpr auto static_capture_constexpr() {
 char n = 'n';



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


[clang] [C2y] Add stdcountof.h (PR #140890)

2025-05-22 Thread Aaron Ballman via cfe-commits

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

>From 10cb78bd9f361dd442c40702dad3c7809f466615 Mon Sep 17 00:00:00 2001
From: Aaron Ballman 
Date: Wed, 21 May 2025 08:59:47 -0400
Subject: [PATCH 1/3] [C2y] Add stdcountof.h

WG14 N3469 changed _Lengthof to _Countof but it also introduced the
 header to expose a macro with a non-ugly identifier.
GCC vends this header as part of the compiler implementation, so Clang
should do the same.
---
 clang/docs/ReleaseNotes.rst|  4 +++-
 clang/lib/Headers/stdcountof.h | 15 +++
 clang/test/C/C2y/n3469.c   | 13 +++--
 3 files changed, 29 insertions(+), 3 deletions(-)
 create mode 100644 clang/lib/Headers/stdcountof.h

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index b466f3758e0b6..7b2777f711b8d 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -249,7 +249,9 @@ C2y Feature Support
   a conforming extension in earlier C language modes, but not in C++ language
   modes (``std::extent`` and ``std::size`` already provide the same
   functionality but with more granularity). The feature can be tested via
-  ``__has_feature(c_countof)`` or ``__has_extension(c_countof)``.
+  ``__has_feature(c_countof)`` or ``__has_extension(c_countof)``. This also
+  adds the  header file which exposes the ``countof`` macro
+  which expands to ``_Countof``.
 
 C23 Feature Support
 ^^^
diff --git a/clang/lib/Headers/stdcountof.h b/clang/lib/Headers/stdcountof.h
new file mode 100644
index 0..5714e6d6ff860
--- /dev/null
+++ b/clang/lib/Headers/stdcountof.h
@@ -0,0 +1,15 @@
+/*=== stdcountof.h - Standard header for countof ---===
+ *
+ * Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+ * See https://llvm.org/LICENSE.txt for license information.
+ * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+ *
+ *===---===
+ */
+
+#ifndef __STDCOUNTOF_H
+#define __STDCOUNTOF_H
+
+#define countof _Countof
+
+#endif /* __STDCOUNTOF_H */
diff --git a/clang/test/C/C2y/n3469.c b/clang/test/C/C2y/n3469.c
index 3d9ac8e6411e9..4660596614075 100644
--- a/clang/test/C/C2y/n3469.c
+++ b/clang/test/C/C2y/n3469.c
@@ -1,9 +1,9 @@
-// RUN: %clang_cc1 -fsyntax-only -std=c2y -verify %s
+// RUN: %clang_cc1 -fsyntax-only -std=c2y -verify -ffreestanding %s
 
 /* WG14 N3469: Clang 21
  * The Big Array Size Survey
  *
- * This renames _Lengthof to _Countof.
+ * This renames _Lengthof to _Countof and introduces the stdcountof.h header.
  */
 
 void test() {
@@ -12,3 +12,12 @@ void test() {
expected-error {{expected expression}}
 }
 
+#ifdef countof
+#error "why is countof defined as a macro?"
+#endif
+
+#include 
+
+#ifndef countof
+#error "why is countof not defined as a macro?"
+#endif

>From 7d94ea7a3d0b663ffca61f89bca2ca56ef585f7d Mon Sep 17 00:00:00 2001
From: Aaron Ballman 
Date: Wed, 21 May 2025 09:33:56 -0400
Subject: [PATCH 2/3] Update other places where the builtin header needs to be
 mentioned

---
 clang/lib/Headers/CMakeLists.txt | 1 +
 clang/lib/Headers/module.modulemap   | 5 +
 clang/lib/Lex/ModuleMap.cpp  | 1 +
 clang/lib/Lex/PPDirectives.cpp   | 4 ++--
 clang/lib/Tooling/Inclusions/Stdlib/CSymbolMap.inc   | 1 +
 .../Modules/Inputs/builtin-headers/system-modules.modulemap  | 5 +
 6 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Headers/CMakeLists.txt b/clang/lib/Headers/CMakeLists.txt
index 449feb012481f..013bd13d1d276 100644
--- a/clang/lib/Headers/CMakeLists.txt
+++ b/clang/lib/Headers/CMakeLists.txt
@@ -18,6 +18,7 @@ set(core_files
   __stdarg_va_list.h
   stdatomic.h
   stdbool.h
+  stdcountof.h
   stdckdint.h
   stddef.h
   __stddef_header_macro.h
diff --git a/clang/lib/Headers/module.modulemap 
b/clang/lib/Headers/module.modulemap
index dcaf09e8f2c55..35897a3ed0e79 100644
--- a/clang/lib/Headers/module.modulemap
+++ b/clang/lib/Headers/module.modulemap
@@ -231,6 +231,11 @@ module _Builtin_stdbool [system] {
   export *
 }
 
+module _Builtin_stdcountof [system] {
+  header "stdcountof.h"
+  export *
+}
+
 module _Builtin_stddef [system] {
   textual header "stddef.h"
 
diff --git a/clang/lib/Lex/ModuleMap.cpp b/clang/lib/Lex/ModuleMap.cpp
index 4175959d8f55b..be9cab8afb9b3 100644
--- a/clang/lib/Lex/ModuleMap.cpp
+++ b/clang/lib/Lex/ModuleMap.cpp
@@ -260,6 +260,7 @@ static bool isBuiltinHeaderName(StringRef FileName) {
.Case("stdarg.h", true)
.Case("stdatomic.h", true)
.Case("stdbool.h", true)
+   .Case("stdcountof.h", true)
.Case("stddef.h", true)
.Case("stdint.h", true)
.Case("tgmath.h", true)
diff --git a/clang/lib/Lex/PPDirectives.cpp b/clang/lib/Lex/PPDirective

[clang] [C2y] Add stdcountof.h (PR #140890)

2025-05-22 Thread Aaron Ballman via cfe-commits


@@ -49,6 +49,11 @@ module cstd [system] [no_undeclared_includes] {
 export *
   }
 
+  module stdcountof {
+header "stdcountof.h"
+export *
+  }
+

AaronBallman wrote:

Good catch! I've updated that test as well.

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


[clang] [clang][CodeGen] Fix crash on non-natural type in CheckAtomicAlignment (PR #141053)

2025-05-22 Thread Pierre van Houtryve via cfe-commits


@@ -0,0 +1,45 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 5
+// RUN: %clang_cc1 -O0 -cl-std=CL2.0 -triple amdgcn-amd-amdhsa -target-cpu 
gfx942 \
+// RUN:   %s -emit-llvm -o - | FileCheck %s
+
+// REQUIRES: amdgpu-registered-target

Pierre-vh wrote:

Is it only required if we run the passes?

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


[clang] [llvm] [AMDGPU][Clang] Allow amdgpu-waves-per-eu attribute to lower target occupancy range (PR #138284)

2025-05-22 Thread Lucas Ramirez via cfe-commits


@@ -279,7 +268,7 @@ define amdgpu_kernel void @kernel_3_6() #12 {
 ; 3,6 -> 6,9
 define internal void @refine_upper_func_3_6() #13 {
 ; CHECK-LABEL: define internal void @refine_upper_func_3_6
-; CHECK-SAME: () #[[ATTR9]] {
+; CHECK-SAME: () #[[ATTR14:[0-9]+]] {

lucas-rami wrote:

This is the last "real" change in the file. The waves/EU range for this 
function goes from [4,10] to [3,6]. All attribute changes below are just 
renames.

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


[clang] [Clang] Optimize some `getBeginLoc` implementations (PR #141058)

2025-05-22 Thread via cfe-commits

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


[clang] [Clang] Optimize some `getBeginLoc` implementations (PR #141058)

2025-05-22 Thread Timm Baeder via cfe-commits


@@ -2901,34 +2907,43 @@ class CallExpr : public Expr {
   //
   // * An optional of type FPOptionsOverride.
   //
-  // Note that we store the offset in bytes from the this pointer to the start
-  // of the trailing objects. It would be perfectly possible to compute it
-  // based on the dynamic kind of the CallExpr. However 1.) we have plenty of
-  // space in the bit-fields of Stmt. 2.) It was benchmarked to be faster to
-  // compute this once and then load the offset from the bit-fields of Stmt,
-  // instead of re-computing the offset each time the trailing objects are
-  // accessed.
+  // CallExpr subclasses are asssumed to be 32 bytes or less, and CallExpr
+  // itself is 24 bytes. To avoid having to recompute or store the offset of 
the
+  // trailing objects, we put it at 32 bytes (such that it is suitable for all
+  // subclasses) We use the 8 bytes gap left for instances of CallExpr to store
+  // the begin source location, which has a significant impact on perf as
+  // getBeginLoc is assumed to be cheap.
+  // The layourt is as follow:
+  // CallExpr | Begin | 4 bytes left | Trailing Objects
+  // CXXMemberCallExpr | Trailing Objects
+  // A bit in CallExprBitfields indicates if source locations are presents.

tbaederr wrote:

```suggestion
  // A bit in CallExprBitfields indicates if source locations are present.
```

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


[clang] [Clang] Optimize some `getBeginLoc` implementations (PR #141058)

2025-05-22 Thread via cfe-commits


@@ -1510,41 +1519,41 @@ CallExpr *CallExpr::Create(const ASTContext &Ctx, Expr 
*Fn,
   unsigned NumArgs = std::max(Args.size(), MinNumArgs);
   unsigned SizeOfTrailingObjects = CallExpr::sizeOfTrailingObjects(
   /*NumPreArgs=*/0, NumArgs, FPFeatures.requiresTrailingStorage());
-  void *Mem =
-  Ctx.Allocate(sizeof(CallExpr) + SizeOfTrailingObjects, 
alignof(CallExpr));
-  return new (Mem) CallExpr(CallExprClass, Fn, /*PreArgs=*/{}, Args, Ty, VK,
-RParenLoc, FPFeatures, MinNumArgs, UsesADL);
+  void *Mem = Ctx.Allocate(
+  sizeToAllocateForCallExprSubclass(SizeOfTrailingObjects),
+  alignof(CallExpr));
+  CallExpr *E =
+  new (Mem) CallExpr(CallExprClass, Fn, /*PreArgs=*/{}, Args, Ty, VK,
+ RParenLoc, FPFeatures, MinNumArgs, UsesADL);
+  E->updateTrailingSourceLocs();
+  return E;
 }
 
 CallExpr *CallExpr::CreateEmpty(const ASTContext &Ctx, unsigned NumArgs,
 bool HasFPFeatures, EmptyShell Empty) {
   unsigned SizeOfTrailingObjects =
   CallExpr::sizeOfTrailingObjects(/*NumPreArgs=*/0, NumArgs, 
HasFPFeatures);
-  void *Mem =
-  Ctx.Allocate(sizeof(CallExpr) + SizeOfTrailingObjects, 
alignof(CallExpr));
+  void *Mem = Ctx.Allocate(
+  sizeToAllocateForCallExprSubclass(SizeOfTrailingObjects),
+  alignof(CallExpr));
   return new (Mem)
   CallExpr(CallExprClass, /*NumPreArgs=*/0, NumArgs, HasFPFeatures, Empty);
 }
 
-unsigned CallExpr::offsetToTrailingObjects(StmtClass SC) {
-  switch (SC) {
-  case CallExprClass:
-return sizeof(CallExpr);
-  case CXXOperatorCallExprClass:
-return sizeof(CXXOperatorCallExpr);
-  case CXXMemberCallExprClass:
-return sizeof(CXXMemberCallExpr);
-  case UserDefinedLiteralClass:
-return sizeof(UserDefinedLiteral);
-  case CUDAKernelCallExprClass:
-return sizeof(CUDAKernelCallExpr);
-  default:
-llvm_unreachable("unexpected class deriving from CallExpr!");
-  }
-}
-
 Decl *Expr::getReferencedDeclOfCallee() {
-  Expr *CEE = IgnoreParenImpCasts();
+
+  // Optimize for the common case first
+  // (simple function or member function call)
+  // then try more exotic possibilities
+  Expr *CEE = IgnoreImpCasts();
+
+  if (auto *DRE = dyn_cast(CEE))
+return DRE->getDecl();
+
+  if (auto *ME = dyn_cast(CEE))
+return ME->getMemberDecl();
+
+  CEE = CEE->IgnoreParens();

cor3ntin wrote:

Not in so far as the tests pass (we already handle 
SubstNonTypeTemplateParmExpr, and MaterializeTemporaryExpr is a prvalue), so... 
it should be fine. If not, we will add more tests!

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


[clang] [C2y] Add stdcountof.h (PR #140890)

2025-05-22 Thread via cfe-commits


@@ -389,6 +389,7 @@ SYMBOL(cosh, None, )
 SYMBOL(coshf, None, )
 SYMBOL(coshl, None, )
 SYMBOL(cosl, None, )
+SYMBOL(countof, None, )

cor3ntin wrote:

That file is code-generated, right?

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


[clang] [libTooling] Fix `constructExprArgs` for direct-init and implicit construction (PR #139990)

2025-05-22 Thread Yitzhak Mandelbaum via cfe-commits

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

Nice!

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


[clang] [Clang] Optimize some `getBeginLoc` implementations (PR #141058)

2025-05-22 Thread via cfe-commits


@@ -1638,43 +1647,6 @@ CallExpr::getUnusedResultAttr(const ASTContext &Ctx) 
const {
   return {nullptr, nullptr};
 }
 
-SourceLocation CallExpr::getBeginLoc() const {
-  if (const auto *OCE = dyn_cast(this))
-return OCE->getBeginLoc();
-
-  // A non-dependent call to a member function with an explicit object 
parameter
-  // is modelled with the object expression being the first argument, e.g. in
-  // `o.f(x)`, the callee will be just `f`, and `o` will be the first argument.
-  // Since the first argument is written before the callee, the expression's
-  // begin location should come from the first argument.
-  // This does not apply to dependent calls, which are modelled with `o.f`
-  // being the callee.
-  if (!isTypeDependent()) {
-if (const auto *Method =
-dyn_cast_if_present(getCalleeDecl());
-Method && Method->isExplicitObjectMemberFunction()) {
-  if (auto FirstArgLoc = getArg(0)->getBeginLoc(); FirstArgLoc.isValid()) {
-return FirstArgLoc;
-  }
-}
-  }
-
-  SourceLocation begin = getCallee()->getBeginLoc();
-  if (begin.isInvalid() && getNumArgs() > 0 && getArg(0))
-begin = getArg(0)->getBeginLoc();
-  return begin;
-}
-
-SourceLocation CallExpr::getEndLoc() const {
-  if (const auto *OCE = dyn_cast(this))
-return OCE->getEndLoc();
-
-  SourceLocation end = getRParenLoc();
-  if (end.isInvalid() && getNumArgs() > 0 && getArg(getNumArgs() - 1))
-end = getArg(getNumArgs() - 1)->getEndLoc();

cor3ntin wrote:

No test broke, no. Afaict, getExprLoc calls the implementation in 
CXXOperatorCallExpr

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


[clang] [llvm] [llvm][DebugInfo][clang] Finalize all declaration subprograms in DIBuilder::finalize() (PR #139914)

2025-05-22 Thread Vladislav Dzhidzhoev via cfe-commits

dzhidzhoev wrote:

> I suppose what this is encoding is a (subtle?) assumption about how 
> definition-subprograms are modelled: they're created once and are immutable. 
> Wheras declaration-functions can be forwarded declared and then have extra 
> information added to them when a definition is emitted.

It is possible.

By the way, I've noticed that (declaration) SPs created with the 
`DIBuilder::CreateMethod` call in `CGDebugInfo::CreateCXXMemberFunction` are 
not finalized anywhere in clang (at least it's true for `get_a`/`get_b` in 
`clang/test/CodeGenCXX/debug-info-local-types.cpp` from 
https://github.com/llvm/llvm-project/pull/119001). I think clang expected 
DIBuilder to finalize everything before https://reviews.llvm.org/D33704, where 
it turned out that clang needed some subprograms to be finalized before the 
finalization of the whole CGDebugInfo instance. It seems to me that manual 
finalizeSubprogram() calls were added sporadically, not followed by 
declaration-vs-definition logic.

> If there's no performance cost as a result of this patch, then it seems fine 
> to go in to me.

Performance cost in terms of compilation time?

> but is there a functional reason in a later patch that makes it necessary?

I've touched it briefly here 
https://github.com/llvm/llvm-project/pull/119001#discussion_r2089196943. I've 
noticed that the mentioned PR doesn't call `finalizeSubprogram()` for the 
created declaration SP. With the call added, the test output changes: 
declaration DISubprograms have their DICompositeTypes in the `retainedNodes` 
field.
We can't just add `finalizeSubprogram` right after `CreateSubprogram()`, as we 
return from the function before the local types are created. And we can't 
attach a declaration subprogram to the corresponding Clang AST declaration, as 
it may not exist.
We could start tracking these declarations in CGDebugInfo class, but I'm 
curious why not to do that on DIBuilder's level globally :) 

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


[clang] [clang-format] Add AlignAfterOpenBracketOptions (PR #108332)

2025-05-22 Thread Gedare Bloom via cfe-commits


@@ -3373,6 +3409,51 @@ the configuration (without a prefix: ``Auto``).
 
 
 
+.. _BreakBeforeCloseBracketIf:
+
+**BreakBeforeCloseBracketIf** (``Boolean``) :versionbadge:`clang-format 21` 
:ref:`¶ `
+  Force break before the right parenthesis of an if control statement
+  when the expression exceeds the column limit. The break before the
+  closing parenthesis is only made if there is a break after the opening
+  parenthesis.
+
+  .. code-block:: c++
+
+true: false:
+if constexpr (  vs.   if constexpr (a ||

gedare wrote:

Yes, `BreakAfterCloseBracket` will only work if there is a break after the 
opening bracket. This is a holdover from how `AlwaysBreak` and `BlockIndent` 
alignment options work.

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


[clang] b048f3f - [clang] Use llvm::is_contained (NFC) (#140985)

2025-05-22 Thread via cfe-commits

Author: Kazu Hirata
Date: 2025-05-22T07:25:02-07:00
New Revision: b048f3f8d7a6ff178dafa82e47f275c95258

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

LOG: [clang] Use llvm::is_contained (NFC) (#140985)

Added: 


Modified: 
clang/include/clang/Sema/Sema.h
clang/lib/Interpreter/Interpreter.cpp
clang/unittests/ASTMatchers/ASTMatchersTest.h
clang/unittests/Tooling/ToolingTest.cpp

Removed: 




diff  --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 4733ed2ee9452..fe93df94438cb 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -14629,8 +14629,8 @@ class Sema final : public SemaBase {
   bool SatisfactionStackContains(const NamedDecl *D,
  const llvm::FoldingSetNodeID &ID) const {
 const NamedDecl *Can = cast(D->getCanonicalDecl());
-return llvm::find(SatisfactionStack, SatisfactionStackEntryTy{Can, ID}) !=
-   SatisfactionStack.end();
+return llvm::is_contained(SatisfactionStack,
+  SatisfactionStackEntryTy{Can, ID});
   }
 
   using SatisfactionStackEntryTy =

diff  --git a/clang/lib/Interpreter/Interpreter.cpp 
b/clang/lib/Interpreter/Interpreter.cpp
index c04b2099a4b9a..4b407a0172adb 100644
--- a/clang/lib/Interpreter/Interpreter.cpp
+++ b/clang/lib/Interpreter/Interpreter.cpp
@@ -654,14 +654,13 @@ void Interpreter::ResetExecutor() { IncrExecutor.reset(); 
}
 
 llvm::Error Interpreter::Execute(PartialTranslationUnit &T) {
   assert(T.TheModule);
-  LLVM_DEBUG(llvm::dbgs()
- << "execute-ptu "
- << ((std::find(PTUs.begin(), PTUs.end(), T) != PTUs.end())
- ? std::distance(PTUs.begin(),
- std::find(PTUs.begin(), PTUs.end(), T))
- : -1)
- << ": [TU=" << T.TUPart << ", M=" << T.TheModule.get() << " ("
- << T.TheModule->getName() << ")]\n");
+  LLVM_DEBUG(
+  llvm::dbgs() << "execute-ptu "
+   << (llvm::is_contained(PTUs, T)
+   ? std::distance(PTUs.begin(), llvm::find(PTUs, T))
+   : -1)
+   << ": [TU=" << T.TUPart << ", M=" << T.TheModule.get()
+   << " (" << T.TheModule->getName() << ")]\n");
   if (!IncrExecutor) {
 auto Err = CreateExecutor();
 if (Err)

diff  --git a/clang/unittests/ASTMatchers/ASTMatchersTest.h 
b/clang/unittests/ASTMatchers/ASTMatchersTest.h
index 6eea39ae787fa..c1d4daea2c9f1 100644
--- a/clang/unittests/ASTMatchers/ASTMatchersTest.h
+++ b/clang/unittests/ASTMatchers/ASTMatchersTest.h
@@ -110,7 +110,7 @@ testing::AssertionResult matchesConditionally(
   // Append additional arguments at the end to allow overriding the default
   // choices that we made above.
   llvm::copy(CompileArgs, std::back_inserter(Args));
-  if (llvm::find(Args, "-target") == Args.end()) {
+  if (!llvm::is_contained(Args, "-target")) {
 // Use an unknown-unknown triple so we don't instantiate the full system
 // toolchain.  On Linux, instantiating the toolchain involves stat'ing
 // large portions of /usr/lib, and this slows down not only this test, but

diff  --git a/clang/unittests/Tooling/ToolingTest.cpp 
b/clang/unittests/Tooling/ToolingTest.cpp
index 8cdfffb54390e..cfa021a5ef137 100644
--- a/clang/unittests/Tooling/ToolingTest.cpp
+++ b/clang/unittests/Tooling/ToolingTest.cpp
@@ -793,7 +793,7 @@ TEST(ClangToolTest, StripDependencyFileAdjuster) {
   Tool.run(Action.get());
 
   auto HasFlag = [&FinalArgs](const std::string &Flag) {
-return llvm::find(FinalArgs, Flag) != FinalArgs.end();
+return llvm::is_contained(FinalArgs, Flag);
   };
   EXPECT_FALSE(HasFlag("-MD"));
   EXPECT_FALSE(HasFlag("-MMD"));
@@ -825,7 +825,7 @@ TEST(ClangToolTest, 
StripDependencyFileAdjusterShowIncludes) {
   Tool.run(Action.get());
 
   auto HasFlag = [&FinalArgs](const std::string &Flag) {
-return llvm::find(FinalArgs, Flag) != FinalArgs.end();
+return llvm::is_contained(FinalArgs, Flag);
   };
   EXPECT_FALSE(HasFlag("/showIncludes"));
   EXPECT_FALSE(HasFlag("/showIncludes:user"));
@@ -858,7 +858,7 @@ TEST(ClangToolTest, StripDependencyFileAdjusterMsvc) {
   Tool.run(Action.get());
 
   auto HasFlag = [&FinalArgs](const std::string &Flag) {
-return llvm::find(FinalArgs, Flag) != FinalArgs.end();
+return llvm::is_contained(FinalArgs, Flag);
   };
   EXPECT_TRUE(HasFlag("-MD"));
   EXPECT_TRUE(HasFlag("-MDd"));
@@ -891,7 +891,7 @@ TEST(ClangToolTest, StripPluginsAdjuster) {
   Tool.run(Action.get());
 
   auto HasFlag = [&FinalArgs](const std::string &Flag) {
-return llvm::find(FinalArgs, Flag) != FinalArgs.end();
+return llvm::is_contained(FinalArgs, Flag);
   };
   EX

[clang] [clang] Use llvm::is_contained (NFC) (PR #140985)

2025-05-22 Thread Kazu Hirata via cfe-commits

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


[clang] [ASTMatchers] Fix matching `CXXOperatorCallExpr` of `->` (PR #139994)

2025-05-22 Thread Yitzhak Mandelbaum via cfe-commits

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


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


[clang] [llvm] [AMDGPU][clang][CodeGen][opt] Add late-resolved feature identifying predicates (PR #134016)

2025-05-22 Thread Alex Voicu via cfe-commits


@@ -13338,4 +13338,23 @@ def err_acc_device_type_multiple_archs
 // AMDGCN builtins diagnostics
 def err_amdgcn_load_lds_size_invalid_value : Error<"invalid size value">;
 def note_amdgcn_load_lds_size_valid_value : Note<"size must be %select{1, 2, 
or 4|1, 2, 4, 12 or 16}0">;
+def err_amdgcn_processor_is_arg_not_literal
+: Error<"the argument to __builtin_amdgcn_processor_is must be a string "
+"literal">;
+def err_amdgcn_processor_is_arg_invalid_value
+: Error<"the argument to __builtin_amdgcn_processor_is must be a valid "
+"AMDGCN processor identifier; '%0' is not valid">;

AlexVlx wrote:

Yes, this is an excellent idea, thank you for it. Done.

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


[clang] [clang][SPIR-V] Fix OpenCL addrspace mapping when using non-zero default AS (PR #137187)

2025-05-22 Thread Nick Sarnie via cfe-commits

sarnex wrote:

@yingcong-wu Hi, I'm not totally sure what you mean, did this change break 
something for you or did it fix something? Feel free to email me internally as 
well. Thanks

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


[clang] [llvm] [openmp] [clang][OpenMP] New OpenMP 6.0 threadset clause (PR #135807)

2025-05-22 Thread via cfe-commits

https://github.com/Ritanya-B-Bharadwaj updated 
https://github.com/llvm/llvm-project/pull/135807

>From 9c56e59ba9984c14c15a8d5a95a02e7192a64e8f Mon Sep 17 00:00:00 2001
From: Ritanya B Bharadwaj 
Date: Sun, 6 Apr 2025 09:33:06 -0500
Subject: [PATCH 1/4] [OpenMP] Parsing Support of ThreadSets in Task

---
 clang/include/clang/AST/OpenMPClause.h| 80 +++
 clang/include/clang/AST/RecursiveASTVisitor.h |  6 ++
 clang/include/clang/Basic/OpenMPKinds.def |  8 +-
 clang/include/clang/Basic/OpenMPKinds.h   |  7 ++
 clang/include/clang/Sema/SemaOpenMP.h |  6 ++
 clang/lib/AST/OpenMPClause.cpp|  7 ++
 clang/lib/AST/StmtProfile.cpp |  2 +
 clang/lib/Basic/OpenMPKinds.cpp   |  9 +++
 clang/lib/Parse/ParseOpenMP.cpp   |  1 +
 clang/lib/Sema/SemaOpenMP.cpp | 21 +
 clang/lib/Sema/TreeTransform.h|  7 ++
 clang/lib/Serialization/ASTReader.cpp | 11 +++
 clang/lib/Serialization/ASTWriter.cpp |  6 ++
 clang/tools/libclang/CIndex.cpp   |  2 +
 llvm/include/llvm/Frontend/OpenMP/OMP.td  |  4 +
 15 files changed, 176 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/AST/OpenMPClause.h 
b/clang/include/clang/AST/OpenMPClause.h
index 572e62249b46f..81420384f885c 100644
--- a/clang/include/clang/AST/OpenMPClause.h
+++ b/clang/include/clang/AST/OpenMPClause.h
@@ -1332,6 +1332,86 @@ class OMPDefaultClause : public OMPClause {
   }
 };
 
+/// This represents 'threadset' clause in the '#pragma omp ...' directive.
+///
+/// \code
+/// #pragma omp parallel threadset(shared)
+/// \endcode
+/// In this example directive '#pragma omp parallel' has simple 'threadset'
+/// clause with kind 'shared'.
+class OMPThreadsetClause : public OMPClause {
+  friend class OMPClauseReader;
+
+  /// Location of '('.
+  SourceLocation LParenLoc;
+
+  /// A kind of the 'threadset' clause.
+  OpenMPThreadsetKind Kind = OMPC_THREADSET_unknown;
+
+  /// Start location of the kind in source code.
+  SourceLocation KindLoc;
+
+  /// Set kind of the clauses.
+  ///
+  /// \param K Argument of clause.
+  void setThreadsetKind(OpenMPThreadsetKind K) { Kind = K; }
+
+  /// Set argument location.
+  ///
+  /// \param KLoc Argument location.
+  void setThreadsetKindLoc(SourceLocation KLoc) { KindLoc = KLoc; }
+
+public:
+  /// Build 'threadset' clause with argument \a A ('none' or 'shared').
+  ///
+  /// \param A Argument of the clause ('none' or 'shared').
+  /// \param ALoc Starting location of the argument.
+  /// \param StartLoc Starting location of the clause.
+  /// \param LParenLoc Location of '('.
+  /// \param EndLoc Ending location of the clause.
+  OMPThreadsetClause(OpenMPThreadsetKind A, SourceLocation ALoc,
+ SourceLocation StartLoc, SourceLocation LParenLoc,
+ SourceLocation EndLoc)
+  : OMPClause(llvm::omp::OMPC_threadset, StartLoc, EndLoc),
+LParenLoc(LParenLoc), Kind(A), KindLoc(ALoc) {}
+
+  /// Build an empty clause.
+  OMPThreadsetClause()
+  : OMPClause(llvm::omp::OMPC_threadset, SourceLocation(),
+  SourceLocation()) {}
+
+  /// Sets the location of '('.
+  void setLParenLoc(SourceLocation Loc) { LParenLoc = Loc; }
+
+  /// Returns the location of '('.
+  SourceLocation getLParenLoc() const { return LParenLoc; }
+
+  /// Returns kind of the clause.
+  OpenMPThreadsetKind getThreadsetKind() const { return Kind; }
+
+  /// Returns location of clause kind.
+  SourceLocation getThreadsetKindLoc() const { return KindLoc; }
+
+  child_range children() {
+return child_range(child_iterator(), child_iterator());
+  }
+
+  const_child_range children() const {
+return const_child_range(const_child_iterator(), const_child_iterator());
+  }
+
+  child_range used_children() {
+return child_range(child_iterator(), child_iterator());
+  }
+  const_child_range used_children() const {
+return const_child_range(const_child_iterator(), const_child_iterator());
+  }
+
+  static bool classof(const OMPClause *T) {
+return T->getClauseKind() == llvm::omp::OMPC_threadset;
+  }
+};
+
 /// This represents 'proc_bind' clause in the '#pragma omp ...'
 /// directive.
 ///
diff --git a/clang/include/clang/AST/RecursiveASTVisitor.h 
b/clang/include/clang/AST/RecursiveASTVisitor.h
index 0530996ed20d3..d86c7d4577ac6 100644
--- a/clang/include/clang/AST/RecursiveASTVisitor.h
+++ b/clang/include/clang/AST/RecursiveASTVisitor.h
@@ -3410,6 +3410,12 @@ bool 
RecursiveASTVisitor::VisitOMPDefaultClause(OMPDefaultClause *) {
   return true;
 }
 
+template 
+bool RecursiveASTVisitor::VisitOMPThreadsetClause(
+OMPThreadsetClause *) {
+  return true;
+}
+
 template 
 bool RecursiveASTVisitor::VisitOMPProcBindClause(OMPProcBindClause *) 
{
   return true;
diff --git a/clang/include/clang/Basic/OpenMPKinds.def 
b/clang/include/clang/Basic/OpenMPKinds.def
index b0de65df7e397..5b8889b8f7a34 100644
--- a/clang/include/clang/B

[clang] [XRay] Fix argument parsing with offloading (#140748) (PR #141043)

2025-05-22 Thread Joseph Huber via cfe-commits

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

We'll now be creating the XRayArgs class when we do this every time, but I 
don't think it's expensive enough or done enough times to be an issue. Thanks.

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


[clang] [clang][CodeGen] Fix crash on non-natural type in CheckAtomicAlignment (PR #141053)

2025-05-22 Thread Matt Arsenault via cfe-commits


@@ -0,0 +1,45 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 5
+// RUN: %clang_cc1 -O0 -cl-std=CL2.0 -triple amdgcn-amd-amdhsa -target-cpu 
gfx942 \
+// RUN:   %s -emit-llvm -o - | FileCheck %s
+
+// REQUIRES: amdgpu-registered-target

arsenm wrote:

but I guess we have this on most of the tests, so might as well keep it 

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


[clang] [Clang] Optimize some `getBeginLoc` implementations (PR #141058)

2025-05-22 Thread via cfe-commits

cor3ntin wrote:

https://llvm-compile-time-tracker.com/compare.php?from=f4cebe5d73c24ab53917bd58aedc9db892a164ae&to=99d11a55c0222e8ed64aa35a068a3f08673baaba&stat=instructions%3Au

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


[clang] [KeyInstr][Clang] Agg init atom (PR #134635)

2025-05-22 Thread Orlando Cazalet-Hyams via cfe-commits

https://github.com/OCHyams updated 
https://github.com/llvm/llvm-project/pull/134635

>From c4029c3503f565ab6c2faa9cdec129c79133ff4f Mon Sep 17 00:00:00 2001
From: Orlando Cazalet-Hyams 
Date: Tue, 1 Apr 2025 15:40:58 +0100
Subject: [PATCH 1/7] [KeyInstr][Clang] Agg init atom

This patch is part of a stack that teaches Clang to generate Key Instructions
metadata for C and C++.

The Key Instructions project is introduced, including a "quick summary" section
at the top which adds context for this PR, here:
https://discourse.llvm.org/t/rfc-improving-is-stmt-placement-for-better-interactive-debugging/82668

The feature is only functional in LLVM if LLVM is built with CMake flag
LLVM_EXPERIMENTAL_KEY_INSTRUCTIONs. Eventually that flag will be removed.

The Clang-side work is demoed here:
https://github.com/llvm/llvm-project/pull/130943
---
 clang/lib/CodeGen/CGDecl.cpp  |  2 ++
 .../DebugInfo/KeyInstructions/init-agg.cpp| 22 +++
 2 files changed, 24 insertions(+)
 create mode 100644 clang/test/DebugInfo/KeyInstructions/init-agg.cpp

diff --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp
index d02f2ad09d2f1..8d43d531f6043 100644
--- a/clang/lib/CodeGen/CGDecl.cpp
+++ b/clang/lib/CodeGen/CGDecl.cpp
@@ -1270,6 +1270,8 @@ void CodeGenFunction::emitStoresForConstant(const VarDecl 
&D, Address Loc,
createUnnamedGlobalForMemcpyFrom(
CGM, D, Builder, constant, Loc.getAlignment()),
SizeVal, isVolatile);
+  addInstToCurrentSourceAtom(I, nullptr);
+
   if (IsAutoInit)
 I->addAnnotationMetadata("auto-init");
 }
diff --git a/clang/test/DebugInfo/KeyInstructions/init-agg.cpp 
b/clang/test/DebugInfo/KeyInstructions/init-agg.cpp
new file mode 100644
index 0..b96256b532f3e
--- /dev/null
+++ b/clang/test/DebugInfo/KeyInstructions/init-agg.cpp
@@ -0,0 +1,22 @@
+
+// RUN: %clang -gkey-instructions %s -gmlt -S -emit-llvm -o - \
+// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not 
atomRank
+
+// The implicit-check-not is important; we don't want the GEPs created for the
+// store locations to be included in the atom group.
+
+int g;
+void a() {
+// CHECK: _Z1av()
+// CHECK: call void @llvm.memcpy{{.*}}, !dbg [[G1R1:!.*]]
+int A[] = { 1, 2, 3 };
+// CHECK: store i32 1, ptr %{{.*}}, !dbg [[G2R1:!.*]]
+// CHECK: store i32 2, ptr %{{.*}}, !dbg [[G2R1]]
+// CHECK: %0 = load i32, ptr @g{{.*}}, !dbg [[G2R2:!.*]]
+// CHECK: store i32 %0, ptr %{{.*}}, !dbg [[G2R1]]
+int B[] = { 1, 2, g };
+}
+
+// CHECK: [[G1R1]] = !DILocation({{.*}}, atomGroup: 1, atomRank: 1)
+// CHECK: [[G2R1]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 1)
+// CHECK: [[G2R2]] = !DILocation({{.*}}, atomGroup: 2, atomRank: 2)

>From d946e31203b07c88d1ade65677a3b2d87adf533e Mon Sep 17 00:00:00 2001
From: Orlando Cazalet-Hyams 
Date: Tue, 1 Apr 2025 16:45:47 +0100
Subject: [PATCH 2/7] shouldUseBZeroPlusStoresToInitialize

---
 clang/lib/CodeGen/CGDecl.cpp  |  3 +++
 clang/test/DebugInfo/KeyInstructions/init-agg.cpp | 12 +++-
 2 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp
index 8d43d531f6043..bb13c31f8f5e4 100644
--- a/clang/lib/CodeGen/CGDecl.cpp
+++ b/clang/lib/CodeGen/CGDecl.cpp
@@ -945,6 +945,7 @@ void 
CodeGenFunction::emitStoresForInitAfterBZero(llvm::Constant *Init,
   isa(Init) || isa(Init) ||
   isa(Init)) {
 auto *I = Builder.CreateStore(Init, Loc, isVolatile);
+addInstToCurrentSourceAtom(I, nullptr);
 if (IsAutoInit)
   I->addAnnotationMetadata("auto-init");
 return;
@@ -1200,6 +1201,8 @@ void CodeGenFunction::emitStoresForConstant(const VarDecl 
&D, Address Loc,
   if (shouldUseBZeroPlusStoresToInitialize(constant, ConstantSize)) {
 auto *I = Builder.CreateMemSet(Loc, llvm::ConstantInt::get(CGM.Int8Ty, 0),
SizeVal, isVolatile);
+addInstToCurrentSourceAtom(I, nullptr);
+
 if (IsAutoInit)
   I->addAnnotationMetadata("auto-init");
 
diff --git a/clang/test/DebugInfo/KeyInstructions/init-agg.cpp 
b/clang/test/DebugInfo/KeyInstructions/init-agg.cpp
index b96256b532f3e..854af3237ed98 100644
--- a/clang/test/DebugInfo/KeyInstructions/init-agg.cpp
+++ b/clang/test/DebugInfo/KeyInstructions/init-agg.cpp
@@ -1,22 +1,32 @@
 
-// RUN: %clang -gkey-instructions %s -gmlt -S -emit-llvm -o - \
+// RUN: %clang -gkey-instructions %s -gmlt -gno-column-info -S -emit-llvm -o - 
\
 // RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not 
atomRank
 
 // The implicit-check-not is important; we don't want the GEPs created for the
 // store locations to be included in the atom group.
 
 int g;
+char gc;
 void a() {
 // CHECK: _Z1av()
 // CHECK: call void @llvm.memcpy{{.*}}, !dbg [[G1R1:!.*]]
 int A[] = { 1, 2, 3 };
+
 // CHECK: store i32 1, ptr %{{.*}}, !dbg [[G2R1:!.*]]
 // CHECK: store i32 2, p

[clang] [clang][CodeGen] Fix crash on non-natural type in CheckAtomicAlignment (PR #141053)

2025-05-22 Thread Pierre van Houtryve via cfe-commits

https://github.com/Pierre-vh updated 
https://github.com/llvm/llvm-project/pull/141053

>From 68db9fad42369be31d935257a2d80962a4018892 Mon Sep 17 00:00:00 2001
From: pvanhout 
Date: Thu, 22 May 2025 14:13:54 +0200
Subject: [PATCH 1/3] [clang][CodeGen] Fix crash on non-natural type in
 CheckAtomicAlignment

In some specific scenarios, `Ptr.getElementType()` won't be a primitive
type or a vector of primitive types, and thus `getScalarSizeInBits()` returns
zero.

Use the datalayout to get the proper size of the type instead of making an 
implicit
assumption that the type is a simple primitive type.

Solves SWDEV-534184
---
 clang/lib/CodeGen/CGBuiltin.cpp   |  3 +-
 .../CodeGenOpenCL/check-atomic-alignment.cl   | 45 +++
 2 files changed, 47 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/CodeGenOpenCL/check-atomic-alignment.cl

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 04a0d9ba2bbce..749f716acfbe8 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -274,9 +274,10 @@ Value *EmitFromInt(CodeGenFunction &CGF, llvm::Value *V,
 Address CheckAtomicAlignment(CodeGenFunction &CGF, const CallExpr *E) {
   ASTContext &Ctx = CGF.getContext();
   Address Ptr = CGF.EmitPointerWithAlignment(E->getArg(0));
+  const llvm::DataLayout &DL = CGF.CGM.getDataLayout();
   unsigned Bytes = Ptr.getElementType()->isPointerTy()
? Ctx.getTypeSizeInChars(Ctx.VoidPtrTy).getQuantity()
-   : Ptr.getElementType()->getScalarSizeInBits() / 8;
+   : DL.getTypeSizeInBits(Ptr.getElementType()) / 8;
   unsigned Align = Ptr.getAlignment().getQuantity();
   if (Align % Bytes != 0) {
 DiagnosticsEngine &Diags = CGF.CGM.getDiags();
diff --git a/clang/test/CodeGenOpenCL/check-atomic-alignment.cl 
b/clang/test/CodeGenOpenCL/check-atomic-alignment.cl
new file mode 100644
index 0..6aa4bc26633f8
--- /dev/null
+++ b/clang/test/CodeGenOpenCL/check-atomic-alignment.cl
@@ -0,0 +1,45 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 5
+// RUN: %clang_cc1 -O0 -cl-std=CL2.0 -triple amdgcn-amd-amdhsa -target-cpu 
gfx942 \
+// RUN:   %s -emit-llvm -o - | FileCheck %s
+
+// REQUIRES: amdgpu-registered-target
+
+// `Ptr.getElementType()` in `CheckAtomicAlignment` returns
+//  %struct.__half2 = type { %union.anon }
+// Check we do not crash when handling that.
+
+typedef half  __attribute__((ext_vector_type(2))) half2;
+typedef short  __attribute__((ext_vector_type(2))) short2;
+
+struct __half2 {
+union {
+struct {
+half x;
+half y;
+};
+half2 data;
+};
+};
+
+// CHECK-LABEL: define dso_local <2 x half> @test_flat_add_2f16(
+// CHECK-SAME: ptr noundef [[ADDR:%.*]], <2 x half> noundef [[VAL:%.*]]) 
#[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  [[ENTRY:.*:]]
+// CHECK-NEXT:[[RETVAL:%.*]] = alloca <2 x half>, align 4, addrspace(5)
+// CHECK-NEXT:[[ADDR_ADDR:%.*]] = alloca ptr, align 8, addrspace(5)
+// CHECK-NEXT:[[VAL_ADDR:%.*]] = alloca <2 x half>, align 4, addrspace(5)
+// CHECK-NEXT:[[RETVAL_ASCAST:%.*]] = addrspacecast ptr addrspace(5) 
[[RETVAL]] to ptr
+// CHECK-NEXT:[[ADDR_ADDR_ASCAST:%.*]] = addrspacecast ptr addrspace(5) 
[[ADDR_ADDR]] to ptr
+// CHECK-NEXT:[[VAL_ADDR_ASCAST:%.*]] = addrspacecast ptr addrspace(5) 
[[VAL_ADDR]] to ptr
+// CHECK-NEXT:store ptr [[ADDR]], ptr [[ADDR_ADDR_ASCAST]], align 8
+// CHECK-NEXT:store <2 x half> [[VAL]], ptr [[VAL_ADDR_ASCAST]], align 4
+// CHECK-NEXT:[[TMP0:%.*]] = load ptr, ptr [[ADDR_ADDR_ASCAST]], align 8
+// CHECK-NEXT:[[TMP1:%.*]] = load <2 x half>, ptr [[VAL_ADDR_ASCAST]], 
align 4
+// CHECK-NEXT:[[TMP2:%.*]] = atomicrmw fadd ptr [[TMP0]], <2 x half> 
[[TMP1]] syncscope("agent") monotonic, align 4, !amdgpu.no.fine.grained.memory 
[[META4:![0-9]+]]
+// CHECK-NEXT:ret <2 x half> [[TMP2]]
+//
+half2 test_flat_add_2f16(__generic short2 *addr, half2 val) {
+  return __builtin_amdgcn_flat_atomic_fadd_v2f16((struct __half2*)addr, val);
+}
+//.
+// CHECK: [[META4]] = !{}
+//.

>From 11ddc4d93d36d1605390f9b4ffcf3233c342c90c Mon Sep 17 00:00:00 2001
From: pvanhout 
Date: Thu, 22 May 2025 14:46:37 +0200
Subject: [PATCH 2/3] comments

---
 clang/lib/CodeGen/CGBuiltin.cpp   |  2 +-
 .../CodeGenOpenCL/check-atomic-alignment.cl   | 26 +++
 2 files changed, 11 insertions(+), 17 deletions(-)

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 749f716acfbe8..809ffe549be88 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -277,7 +277,7 @@ Address CheckAtomicAlignment(CodeGenFunction &CGF, const 
CallExpr *E) {
   const llvm::DataLayout &DL = CGF.CGM.getDataLayout();
   unsigned Bytes = Ptr.getElementType()->isPointerTy()
? Ctx.getTypeSizeInChars(Ctx.VoidPtrTy).getQuantit

[clang] [clang][CodeGen] Fix crash on non-natural type in CheckAtomicAlignment (PR #141053)

2025-05-22 Thread Pierre van Houtryve via cfe-commits

https://github.com/Pierre-vh updated 
https://github.com/llvm/llvm-project/pull/141053

>From 68db9fad42369be31d935257a2d80962a4018892 Mon Sep 17 00:00:00 2001
From: pvanhout 
Date: Thu, 22 May 2025 14:13:54 +0200
Subject: [PATCH 1/2] [clang][CodeGen] Fix crash on non-natural type in
 CheckAtomicAlignment

In some specific scenarios, `Ptr.getElementType()` won't be a primitive
type or a vector of primitive types, and thus `getScalarSizeInBits()` returns
zero.

Use the datalayout to get the proper size of the type instead of making an 
implicit
assumption that the type is a simple primitive type.

Solves SWDEV-534184
---
 clang/lib/CodeGen/CGBuiltin.cpp   |  3 +-
 .../CodeGenOpenCL/check-atomic-alignment.cl   | 45 +++
 2 files changed, 47 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/CodeGenOpenCL/check-atomic-alignment.cl

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 04a0d9ba2bbce..749f716acfbe8 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -274,9 +274,10 @@ Value *EmitFromInt(CodeGenFunction &CGF, llvm::Value *V,
 Address CheckAtomicAlignment(CodeGenFunction &CGF, const CallExpr *E) {
   ASTContext &Ctx = CGF.getContext();
   Address Ptr = CGF.EmitPointerWithAlignment(E->getArg(0));
+  const llvm::DataLayout &DL = CGF.CGM.getDataLayout();
   unsigned Bytes = Ptr.getElementType()->isPointerTy()
? Ctx.getTypeSizeInChars(Ctx.VoidPtrTy).getQuantity()
-   : Ptr.getElementType()->getScalarSizeInBits() / 8;
+   : DL.getTypeSizeInBits(Ptr.getElementType()) / 8;
   unsigned Align = Ptr.getAlignment().getQuantity();
   if (Align % Bytes != 0) {
 DiagnosticsEngine &Diags = CGF.CGM.getDiags();
diff --git a/clang/test/CodeGenOpenCL/check-atomic-alignment.cl 
b/clang/test/CodeGenOpenCL/check-atomic-alignment.cl
new file mode 100644
index 0..6aa4bc26633f8
--- /dev/null
+++ b/clang/test/CodeGenOpenCL/check-atomic-alignment.cl
@@ -0,0 +1,45 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 5
+// RUN: %clang_cc1 -O0 -cl-std=CL2.0 -triple amdgcn-amd-amdhsa -target-cpu 
gfx942 \
+// RUN:   %s -emit-llvm -o - | FileCheck %s
+
+// REQUIRES: amdgpu-registered-target
+
+// `Ptr.getElementType()` in `CheckAtomicAlignment` returns
+//  %struct.__half2 = type { %union.anon }
+// Check we do not crash when handling that.
+
+typedef half  __attribute__((ext_vector_type(2))) half2;
+typedef short  __attribute__((ext_vector_type(2))) short2;
+
+struct __half2 {
+union {
+struct {
+half x;
+half y;
+};
+half2 data;
+};
+};
+
+// CHECK-LABEL: define dso_local <2 x half> @test_flat_add_2f16(
+// CHECK-SAME: ptr noundef [[ADDR:%.*]], <2 x half> noundef [[VAL:%.*]]) 
#[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  [[ENTRY:.*:]]
+// CHECK-NEXT:[[RETVAL:%.*]] = alloca <2 x half>, align 4, addrspace(5)
+// CHECK-NEXT:[[ADDR_ADDR:%.*]] = alloca ptr, align 8, addrspace(5)
+// CHECK-NEXT:[[VAL_ADDR:%.*]] = alloca <2 x half>, align 4, addrspace(5)
+// CHECK-NEXT:[[RETVAL_ASCAST:%.*]] = addrspacecast ptr addrspace(5) 
[[RETVAL]] to ptr
+// CHECK-NEXT:[[ADDR_ADDR_ASCAST:%.*]] = addrspacecast ptr addrspace(5) 
[[ADDR_ADDR]] to ptr
+// CHECK-NEXT:[[VAL_ADDR_ASCAST:%.*]] = addrspacecast ptr addrspace(5) 
[[VAL_ADDR]] to ptr
+// CHECK-NEXT:store ptr [[ADDR]], ptr [[ADDR_ADDR_ASCAST]], align 8
+// CHECK-NEXT:store <2 x half> [[VAL]], ptr [[VAL_ADDR_ASCAST]], align 4
+// CHECK-NEXT:[[TMP0:%.*]] = load ptr, ptr [[ADDR_ADDR_ASCAST]], align 8
+// CHECK-NEXT:[[TMP1:%.*]] = load <2 x half>, ptr [[VAL_ADDR_ASCAST]], 
align 4
+// CHECK-NEXT:[[TMP2:%.*]] = atomicrmw fadd ptr [[TMP0]], <2 x half> 
[[TMP1]] syncscope("agent") monotonic, align 4, !amdgpu.no.fine.grained.memory 
[[META4:![0-9]+]]
+// CHECK-NEXT:ret <2 x half> [[TMP2]]
+//
+half2 test_flat_add_2f16(__generic short2 *addr, half2 val) {
+  return __builtin_amdgcn_flat_atomic_fadd_v2f16((struct __half2*)addr, val);
+}
+//.
+// CHECK: [[META4]] = !{}
+//.

>From 11ddc4d93d36d1605390f9b4ffcf3233c342c90c Mon Sep 17 00:00:00 2001
From: pvanhout 
Date: Thu, 22 May 2025 14:46:37 +0200
Subject: [PATCH 2/2] comments

---
 clang/lib/CodeGen/CGBuiltin.cpp   |  2 +-
 .../CodeGenOpenCL/check-atomic-alignment.cl   | 26 +++
 2 files changed, 11 insertions(+), 17 deletions(-)

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 749f716acfbe8..809ffe549be88 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -277,7 +277,7 @@ Address CheckAtomicAlignment(CodeGenFunction &CGF, const 
CallExpr *E) {
   const llvm::DataLayout &DL = CGF.CGM.getDataLayout();
   unsigned Bytes = Ptr.getElementType()->isPointerTy()
? Ctx.getTypeSizeInChars(Ctx.VoidPtrTy).getQuantit

[clang] [llvm] [Clang][LoongArch] Add inline asm support for the `q` constraint (PR #141037)

2025-05-22 Thread via cfe-commits

https://github.com/heiher updated 
https://github.com/llvm/llvm-project/pull/141037

>From 1148711cdfdd5a58960564790509559fa86e2649 Mon Sep 17 00:00:00 2001
From: WANG Rui 
Date: Thu, 22 May 2025 09:59:53 +0800
Subject: [PATCH 1/4] [Clang][LoongArch] Add inline asm support for the `q`
 constraint

This patch adds support for the `q` constraint:
a general-purpose register except for $r0 and $r1 (for the csrxchg
instruction)

Link: https://gcc.gnu.org/pipermail/gcc-patches/2025-May/684339.html
---
 clang/lib/Basic/Targets/LoongArch.cpp|  5 +
 .../test/CodeGen/LoongArch/inline-asm-constraints.c  |  6 ++
 llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp  |  5 +
 llvm/test/CodeGen/LoongArch/inline-asm-constraint.ll | 12 
 4 files changed, 28 insertions(+)

diff --git a/clang/lib/Basic/Targets/LoongArch.cpp 
b/clang/lib/Basic/Targets/LoongArch.cpp
index ca742797d7a3b..f4bcb54bd470d 100644
--- a/clang/lib/Basic/Targets/LoongArch.cpp
+++ b/clang/lib/Basic/Targets/LoongArch.cpp
@@ -139,6 +139,11 @@ bool LoongArchTargetInfo::validateAsmConstraint(
 // A signed 16-bit constant.
 Info.setRequiresImmediate(-32768, 32767);
 return true;
+  case 'q':
+// A general-purpose register except for $r0 and $r1 (for the csrxchg
+// instruction)
+Info.setAllowsRegister();
+return true;
   case 'I':
 // A signed 12-bit constant (for arithmetic instructions).
 Info.setRequiresImmediate(-2048, 2047);
diff --git a/clang/test/CodeGen/LoongArch/inline-asm-constraints.c 
b/clang/test/CodeGen/LoongArch/inline-asm-constraints.c
index b19494284bd99..ded21206d63bf 100644
--- a/clang/test/CodeGen/LoongArch/inline-asm-constraints.c
+++ b/clang/test/CodeGen/LoongArch/inline-asm-constraints.c
@@ -35,6 +35,12 @@ void test_m(int *p) {
   asm volatile("" :: "m"(*(p+4)));
 }
 
+void test_q(void) {
+// CHECK-LABEL: define{{.*}} void @test_q()
+// CHECK: call void asm sideeffect "", "q"(i32 0)
+  asm volatile ("" :: "q"(0));
+}
+
 void test_I(void) {
 // CHECK-LABEL: define{{.*}} void @test_I()
 // CHECK: call void asm sideeffect "", "I"(i32 2047)
diff --git a/llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp 
b/llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
index 9774683e16291..50ec0b2e3ca78 100644
--- a/llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
+++ b/llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
@@ -7276,6 +7276,8 @@ LoongArchTargetLowering::getConstraintType(StringRef 
Constraint) const {
   // 'm':  A memory operand whose address is formed by a base register and
   //   offset that is suitable for use in instructions with the same
   //   addressing mode as st.w and ld.w.
+  // 'q':  A general-purpose register except for $r0 and $r1 (for the csrxchg
+  //   instruction)
   // 'I':  A signed 12-bit constant (for arithmetic instructions).
   // 'J':  Integer zero.
   // 'K':  An unsigned 12-bit constant (for logic instructions).
@@ -7289,6 +7291,7 @@ LoongArchTargetLowering::getConstraintType(StringRef 
Constraint) const {
 default:
   break;
 case 'f':
+case 'q':
   return C_RegisterClass;
 case 'l':
 case 'I':
@@ -7328,6 +7331,8 @@ LoongArchTargetLowering::getRegForInlineAsmConstraint(
   if (VT.isVector())
 break;
   return std::make_pair(0U, &LoongArch::GPRRegClass);
+case 'q':
+  return std::make_pair(0U, &LoongArch::GPRNoR0R1RegClass);
 case 'f':
   if (Subtarget.hasBasicF() && VT == MVT::f32)
 return std::make_pair(0U, &LoongArch::FPR32RegClass);
diff --git a/llvm/test/CodeGen/LoongArch/inline-asm-constraint.ll 
b/llvm/test/CodeGen/LoongArch/inline-asm-constraint.ll
index 4bcc88be97396..73d240b99b0bc 100644
--- a/llvm/test/CodeGen/LoongArch/inline-asm-constraint.ll
+++ b/llvm/test/CodeGen/LoongArch/inline-asm-constraint.ll
@@ -17,6 +17,18 @@ define i32 @constraint_r(i32 %a, i32 %b) nounwind {
   ret i32 %1
 }
 
+define i32 @constraint_q(i32 %a) nounwind {
+; CHECK-LABEL: constraint_q:
+; CHECK:   # %bb.0:
+; CHECK-NEXT:move $a1, $zero
+; CHECK-NEXT:#APP
+; CHECK-NEXT:csrxchg $a0, $a1, 0
+; CHECK-NEXT:#NO_APP
+; CHECK-NEXT:ret
+  %1 = tail call i32 asm "csrxchg $0, $1, $2", "=r,q,i,0"(i32 0, i32 0, i32 %a)
+  ret i32 %1
+}
+
 define i32 @constraint_i(i32 %a) nounwind {
 ; CHECK-LABEL: constraint_i:
 ; CHECK:   # %bb.0:

>From 5c7090293bb9ace8f1d81c1b8e8d9f04b6f42682 Mon Sep 17 00:00:00 2001
From: WANG Rui 
Date: Thu, 22 May 2025 19:21:20 +0800
Subject: [PATCH 2/4] Address xen0n's comments

---
 .../LoongArch/inline-asm-constraint-q.ll  | 20 +++
 .../LoongArch/inline-asm-constraint.ll| 12 ---
 2 files changed, 20 insertions(+), 12 deletions(-)
 create mode 100644 llvm/test/CodeGen/LoongArch/inline-asm-constraint-q.ll

diff --git a/llvm/test/CodeGen/LoongArch/inline-asm-constraint-q.ll 
b/llvm/test/CodeGen/LoongArch/inline-asm-constraint-q.ll
new file mode 100644
index 0..f22fecdd16829
--- 

[clang] [llvm] [Clang][LoongArch] Add inline asm support for the `q` constraint (PR #141037)

2025-05-22 Thread via cfe-commits

https://github.com/heiher updated 
https://github.com/llvm/llvm-project/pull/141037

>From 1148711cdfdd5a58960564790509559fa86e2649 Mon Sep 17 00:00:00 2001
From: WANG Rui 
Date: Thu, 22 May 2025 09:59:53 +0800
Subject: [PATCH 1/5] [Clang][LoongArch] Add inline asm support for the `q`
 constraint

This patch adds support for the `q` constraint:
a general-purpose register except for $r0 and $r1 (for the csrxchg
instruction)

Link: https://gcc.gnu.org/pipermail/gcc-patches/2025-May/684339.html
---
 clang/lib/Basic/Targets/LoongArch.cpp|  5 +
 .../test/CodeGen/LoongArch/inline-asm-constraints.c  |  6 ++
 llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp  |  5 +
 llvm/test/CodeGen/LoongArch/inline-asm-constraint.ll | 12 
 4 files changed, 28 insertions(+)

diff --git a/clang/lib/Basic/Targets/LoongArch.cpp 
b/clang/lib/Basic/Targets/LoongArch.cpp
index ca742797d7a3b..f4bcb54bd470d 100644
--- a/clang/lib/Basic/Targets/LoongArch.cpp
+++ b/clang/lib/Basic/Targets/LoongArch.cpp
@@ -139,6 +139,11 @@ bool LoongArchTargetInfo::validateAsmConstraint(
 // A signed 16-bit constant.
 Info.setRequiresImmediate(-32768, 32767);
 return true;
+  case 'q':
+// A general-purpose register except for $r0 and $r1 (for the csrxchg
+// instruction)
+Info.setAllowsRegister();
+return true;
   case 'I':
 // A signed 12-bit constant (for arithmetic instructions).
 Info.setRequiresImmediate(-2048, 2047);
diff --git a/clang/test/CodeGen/LoongArch/inline-asm-constraints.c 
b/clang/test/CodeGen/LoongArch/inline-asm-constraints.c
index b19494284bd99..ded21206d63bf 100644
--- a/clang/test/CodeGen/LoongArch/inline-asm-constraints.c
+++ b/clang/test/CodeGen/LoongArch/inline-asm-constraints.c
@@ -35,6 +35,12 @@ void test_m(int *p) {
   asm volatile("" :: "m"(*(p+4)));
 }
 
+void test_q(void) {
+// CHECK-LABEL: define{{.*}} void @test_q()
+// CHECK: call void asm sideeffect "", "q"(i32 0)
+  asm volatile ("" :: "q"(0));
+}
+
 void test_I(void) {
 // CHECK-LABEL: define{{.*}} void @test_I()
 // CHECK: call void asm sideeffect "", "I"(i32 2047)
diff --git a/llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp 
b/llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
index 9774683e16291..50ec0b2e3ca78 100644
--- a/llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
+++ b/llvm/lib/Target/LoongArch/LoongArchISelLowering.cpp
@@ -7276,6 +7276,8 @@ LoongArchTargetLowering::getConstraintType(StringRef 
Constraint) const {
   // 'm':  A memory operand whose address is formed by a base register and
   //   offset that is suitable for use in instructions with the same
   //   addressing mode as st.w and ld.w.
+  // 'q':  A general-purpose register except for $r0 and $r1 (for the csrxchg
+  //   instruction)
   // 'I':  A signed 12-bit constant (for arithmetic instructions).
   // 'J':  Integer zero.
   // 'K':  An unsigned 12-bit constant (for logic instructions).
@@ -7289,6 +7291,7 @@ LoongArchTargetLowering::getConstraintType(StringRef 
Constraint) const {
 default:
   break;
 case 'f':
+case 'q':
   return C_RegisterClass;
 case 'l':
 case 'I':
@@ -7328,6 +7331,8 @@ LoongArchTargetLowering::getRegForInlineAsmConstraint(
   if (VT.isVector())
 break;
   return std::make_pair(0U, &LoongArch::GPRRegClass);
+case 'q':
+  return std::make_pair(0U, &LoongArch::GPRNoR0R1RegClass);
 case 'f':
   if (Subtarget.hasBasicF() && VT == MVT::f32)
 return std::make_pair(0U, &LoongArch::FPR32RegClass);
diff --git a/llvm/test/CodeGen/LoongArch/inline-asm-constraint.ll 
b/llvm/test/CodeGen/LoongArch/inline-asm-constraint.ll
index 4bcc88be97396..73d240b99b0bc 100644
--- a/llvm/test/CodeGen/LoongArch/inline-asm-constraint.ll
+++ b/llvm/test/CodeGen/LoongArch/inline-asm-constraint.ll
@@ -17,6 +17,18 @@ define i32 @constraint_r(i32 %a, i32 %b) nounwind {
   ret i32 %1
 }
 
+define i32 @constraint_q(i32 %a) nounwind {
+; CHECK-LABEL: constraint_q:
+; CHECK:   # %bb.0:
+; CHECK-NEXT:move $a1, $zero
+; CHECK-NEXT:#APP
+; CHECK-NEXT:csrxchg $a0, $a1, 0
+; CHECK-NEXT:#NO_APP
+; CHECK-NEXT:ret
+  %1 = tail call i32 asm "csrxchg $0, $1, $2", "=r,q,i,0"(i32 0, i32 0, i32 %a)
+  ret i32 %1
+}
+
 define i32 @constraint_i(i32 %a) nounwind {
 ; CHECK-LABEL: constraint_i:
 ; CHECK:   # %bb.0:

>From 5c7090293bb9ace8f1d81c1b8e8d9f04b6f42682 Mon Sep 17 00:00:00 2001
From: WANG Rui 
Date: Thu, 22 May 2025 19:21:20 +0800
Subject: [PATCH 2/5] Address xen0n's comments

---
 .../LoongArch/inline-asm-constraint-q.ll  | 20 +++
 .../LoongArch/inline-asm-constraint.ll| 12 ---
 2 files changed, 20 insertions(+), 12 deletions(-)
 create mode 100644 llvm/test/CodeGen/LoongArch/inline-asm-constraint-q.ll

diff --git a/llvm/test/CodeGen/LoongArch/inline-asm-constraint-q.ll 
b/llvm/test/CodeGen/LoongArch/inline-asm-constraint-q.ll
new file mode 100644
index 0..f22fecdd16829
--- 

[clang] [Sema] Warn about omitting deprecated enumerator in switch (PR #138562)

2025-05-22 Thread Hans Wennborg via cfe-commits

https://github.com/zmodem updated 
https://github.com/llvm/llvm-project/pull/138562

>From e221ba3b0f7b08bcfc56bf75f7505265c332637d Mon Sep 17 00:00:00 2001
From: Hans Wennborg 
Date: Mon, 5 May 2025 20:24:15 +0200
Subject: [PATCH 1/9] [Sema] Warn about omitting deprecated enumerator in
 switch

This undoes part of 3e4e3b17c14c15c23c0ed18ca9165b42b1b13ae3 which
added the "Omitting a deprecated constant is ok; it should never
materialize." logic.

That seems wrong: deprecated means the enumerator is likely to be
removed in future versions, not that it canot materialize.
---
 clang/lib/Sema/SemaStmt.cpp   | 6 +-
 clang/test/Sema/switch-availability.c | 2 +-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index e8c1f8490342a..990d2fadaf5aa 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -1667,8 +1667,12 @@ Sema::ActOnFinishSwitchStmt(SourceLocation SwitchLoc, 
Stmt *Switch,
 // Don't warn about omitted unavailable EnumConstantDecls.
 switch (EI->second->getAvailability()) {
 case AR_Deprecated:
-  // Omitting a deprecated constant is ok; it should never materialize.
+  // Deprecated enumerators still need to be handled: they may be
+  // deprecated, but can still occur.
+  break;
+
 case AR_Unavailable:
+  // Omitting an unavailable enumerator is ok; it should never occur.
   continue;
 
 case AR_NotYetIntroduced:
diff --git a/clang/test/Sema/switch-availability.c 
b/clang/test/Sema/switch-availability.c
index 888edddac463d..b4f8726addc0b 100644
--- a/clang/test/Sema/switch-availability.c
+++ b/clang/test/Sema/switch-availability.c
@@ -15,7 +15,7 @@ enum SwitchTwo {
 };
 
 void testSwitchTwo(enum SwitchTwo st) {
-  switch (st) {} // expected-warning{{enumeration values 'Vim' and 'Emacs' not 
handled in switch}}
+  switch (st) {} // expected-warning{{enumeration values 'Ed', 'Vim' and 
'Emacs' not handled in switch}}
 }
 
 enum SwitchThree {

>From 6bc923d27d77009b37de12c9e33d2e83835d6a4d Mon Sep 17 00:00:00 2001
From: Hans Wennborg 
Date: Tue, 6 May 2025 09:31:50 +0200
Subject: [PATCH 2/9] check for -Wreturn-type

---
 clang/test/Sema/switch-availability.c | 15 ++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/clang/test/Sema/switch-availability.c 
b/clang/test/Sema/switch-availability.c
index b4f8726addc0b..137cdc976ec2d 100644
--- a/clang/test/Sema/switch-availability.c
+++ b/clang/test/Sema/switch-availability.c
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -verify -Wswitch -triple x86_64-apple-macosx10.12 %s
+// RUN: %clang_cc1 -verify -Wswitch -Wreturn-type -triple 
x86_64-apple-macosx10.12 %s
 
 enum SwitchOne {
   Unavail __attribute__((availability(macos, unavailable))),
@@ -25,3 +25,16 @@ enum SwitchThree {
 void testSwitchThree(enum SwitchThree st) {
   switch (st) {} // expected-warning{{enumeration value 'New' not handled in 
switch}}
 }
+
+enum SwitchFour {
+  Red,
+  Green,
+  Blue [[deprecated]]
+};
+
+int testSwitchFour(enum SwitchFour e) {
+  switch (e) { // expected-warning{{enumeration value 'Blue' not handled in 
switch}}
+  case Red:   return 1;
+  case Green: return 2;
+  }
+} // expected-warning{{non-void function does not return a value in all 
control paths}}

>From 432ab6cb5bc2fe11a575146e53af1083a96c8405 Mon Sep 17 00:00:00 2001
From: Hans Wennborg 
Date: Tue, 6 May 2025 16:30:25 +0200
Subject: [PATCH 3/9] don't forget the oxford comma

---
 clang/test/Sema/switch-availability.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/test/Sema/switch-availability.c 
b/clang/test/Sema/switch-availability.c
index 137cdc976ec2d..fc44375fc83a0 100644
--- a/clang/test/Sema/switch-availability.c
+++ b/clang/test/Sema/switch-availability.c
@@ -15,7 +15,7 @@ enum SwitchTwo {
 };
 
 void testSwitchTwo(enum SwitchTwo st) {
-  switch (st) {} // expected-warning{{enumeration values 'Ed', 'Vim' and 
'Emacs' not handled in switch}}
+  switch (st) {} // expected-warning{{enumeration values 'Ed', 'Vim', and 
'Emacs' not handled in switch}}
 }
 
 enum SwitchThree {

>From 6530e7faae5be297bdfcaae7baee44b7321eb3c4 Mon Sep 17 00:00:00 2001
From: Hans Wennborg 
Date: Thu, 15 May 2025 12:56:05 +0200
Subject: [PATCH 4/9] suppress 'deprecated' warning in case expressions

---
 clang/include/clang/Sema/Sema.h  | 3 +++
 clang/lib/Parse/ParseExpr.cpp| 3 +++
 clang/lib/Sema/SemaAvailability.cpp  | 5 +
 clang/lib/Sema/SemaStmt.cpp  | 4 ++--
 clang/test/Sema/switch-availability.c| 8 
 clang/test/SemaObjC/unguarded-availability.m | 6 +++---
 6 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 19343eb0af092..bb69930446177 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -6767,6 +6767,9 @

[clang] 229aa66 - [KeyInstr][Clang] Agg init atom (#134635)

2025-05-22 Thread via cfe-commits

Author: Orlando Cazalet-Hyams
Date: 2025-05-22T13:49:15+01:00
New Revision: 229aa6627a63012ac5e0b3587c87e94c2b5ad36f

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

LOG: [KeyInstr][Clang] Agg init atom (#134635)

Covers aggregate initialisation and -ftrivial-auto-var-init=pattern.

This patch is part of a stack that teaches Clang to generate Key Instructions
metadata for C and C++.

RFC:
https://discourse.llvm.org/t/rfc-improving-is-stmt-placement-for-better-interactive-debugging/82668

The feature is only functional in LLVM if LLVM is built with CMake flag
LLVM_EXPERIMENTAL_KEY_INSTRUCTIONs. Eventually that flag will be removed.

Added: 
clang/test/DebugInfo/KeyInstructions/init-agg.cpp

Modified: 
clang/lib/CodeGen/CGDecl.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp
index d02f2ad09d2f1..18135384021e8 100644
--- a/clang/lib/CodeGen/CGDecl.cpp
+++ b/clang/lib/CodeGen/CGDecl.cpp
@@ -945,6 +945,7 @@ void 
CodeGenFunction::emitStoresForInitAfterBZero(llvm::Constant *Init,
   isa(Init) || isa(Init) ||
   isa(Init)) {
 auto *I = Builder.CreateStore(Init, Loc, isVolatile);
+addInstToCurrentSourceAtom(I, nullptr);
 if (IsAutoInit)
   I->addAnnotationMetadata("auto-init");
 return;
@@ -1188,6 +1189,7 @@ void CodeGenFunction::emitStoresForConstant(const VarDecl 
&D, Address Loc,
   Ty->isPtrOrPtrVectorTy() || Ty->isFPOrFPVectorTy();
   if (canDoSingleStore) {
 auto *I = Builder.CreateStore(constant, Loc, isVolatile);
+addInstToCurrentSourceAtom(I, nullptr);
 if (IsAutoInit)
   I->addAnnotationMetadata("auto-init");
 return;
@@ -1200,6 +1202,8 @@ void CodeGenFunction::emitStoresForConstant(const VarDecl 
&D, Address Loc,
   if (shouldUseBZeroPlusStoresToInitialize(constant, ConstantSize)) {
 auto *I = Builder.CreateMemSet(Loc, llvm::ConstantInt::get(CGM.Int8Ty, 0),
SizeVal, isVolatile);
+addInstToCurrentSourceAtom(I, nullptr);
+
 if (IsAutoInit)
   I->addAnnotationMetadata("auto-init");
 
@@ -1224,6 +1228,7 @@ void CodeGenFunction::emitStoresForConstant(const VarDecl 
&D, Address Loc,
 }
 auto *I = Builder.CreateMemSet(
 Loc, llvm::ConstantInt::get(CGM.Int8Ty, Value), SizeVal, isVolatile);
+addInstToCurrentSourceAtom(I, nullptr);
 if (IsAutoInit)
   I->addAnnotationMetadata("auto-init");
 return;
@@ -1270,6 +1275,8 @@ void CodeGenFunction::emitStoresForConstant(const VarDecl 
&D, Address Loc,
createUnnamedGlobalForMemcpyFrom(
CGM, D, Builder, constant, Loc.getAlignment()),
SizeVal, isVolatile);
+  addInstToCurrentSourceAtom(I, nullptr);
+
   if (IsAutoInit)
 I->addAnnotationMetadata("auto-init");
 }

diff  --git a/clang/test/DebugInfo/KeyInstructions/init-agg.cpp 
b/clang/test/DebugInfo/KeyInstructions/init-agg.cpp
new file mode 100644
index 0..5446aae155d63
--- /dev/null
+++ b/clang/test/DebugInfo/KeyInstructions/init-agg.cpp
@@ -0,0 +1,48 @@
+
+// RUN: %clang_cc1 -gkey-instructions %s -debug-info-kind=line-tables-only 
-gno-column-info -emit-llvm -o - -ftrivial-auto-var-init=pattern \
+// RUN: | FileCheck %s --implicit-check-not atomGroup --implicit-check-not 
atomRank
+
+// The implicit-check-not is important; we don't want the GEPs created for the
+// store locations to be included in the atom group.
+
+int g;
+void a() {
+// CHECK: _Z1av()
+// CHECK: call void @llvm.memcpy{{.*}}%A, {{.*}}@__const._Z1av.A{{.*}}, !dbg 
[[G1R1:!.*]]
+int A[] = { 1, 2, 3 };
+
+// CHECK:  call void @llvm.memcpy{{.*}}%B, {{.*}}@__const._Z1av.B{{.*}}, 
!dbg [[G2R1:!.*]]
+// CHECK-NEXT: store i32 1, ptr %B{{.*}}, !dbg [[G2R1:!.*]]
+// CHECK-NEXT: %arrayinit.element = getelementptr {{.*}}, ptr %B, i64 1, !dbg 
[[B_LINE:!.*]]
+// CHECK-NEXT: store i32 2, ptr %arrayinit.element{{.*}}, !dbg [[G2R1]]
+// CHECK-NEXT: %arrayinit.element1 = getelementptr {{.*}}, ptr %B, i64 2, !dbg 
[[B_LINE]]
+// CHECK-NEXT: %0 = load i32, ptr @g{{.*}}, !dbg [[G2R2:!.*]]
+// CHECK-NEXT: store i32 %0, ptr %arrayinit.element1{{.*}}, !dbg [[G2R1]]
+int B[] = { 1, 2, g };
+
+// CHECK:  call void @llvm.memset{{.*}}%big{{.*}} !dbg [[G3R1:!.*]]
+// CHECK-NEXT: %1 = getelementptr {{.*}}, ptr %big, i32 0, i32 0, !dbg 
[[big_LINE:!.*]]
+// CHECK-NEXT: store i8 97, ptr %1{{.*}}, !dbg [[G3R1]]
+// CHECK-NEXT: %2 = getelementptr {{.*}}, ptr %big, i32 0, i32 1, !dbg 
[[big_LINE]]
+// CHECK-NEXT: store i8 98, ptr %2{{.*}}, !dbg [[G3R1]]
+// CHECK-NEXT: %3 = getelementptr {{.*}}, ptr %big, i32 0, i32 2, !dbg 
[[big_LINE]]
+// CHECK-NEXT: store i8 99, ptr %3{{.*}}, !dbg [[G3R1]]
+// CHECK-NEXT: %4 = getelementptr {{.*}}, ptr %b

[clang] [clang][CodeGen] Fix crash on non-natural type in CheckAtomicAlignment (PR #141053)

2025-05-22 Thread Matt Arsenault via cfe-commits


@@ -1,8 +1,6 @@
 // NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 5
-// RUN: %clang_cc1 -O0 -cl-std=CL2.0 -triple amdgcn-amd-amdhsa -target-cpu 
gfx942 \
-// RUN:   %s -emit-llvm -o - | FileCheck %s
-
-// REQUIRES: amdgpu-registered-target
+// RUN: %clang_cc1 -O0 -cl-std=CL1.2 -triple amdgcn-amd-amdhsa -target-cpu 
gfx942 \

arsenm wrote:

I just realized you are testing with the flat atomic, so maybe this should stay 
as 2.0. I'm surprised it actually worked without flat address space 

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


[clang] [KeyInstr][Clang] Agg init atom (PR #134635)

2025-05-22 Thread Orlando Cazalet-Hyams via cfe-commits

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


[clang] [Clang] Optimize some `getBeginLoc` implementations (PR #141058)

2025-05-22 Thread via cfe-commits


@@ -2901,34 +2907,44 @@ class CallExpr : public Expr {
   //
   // * An optional of type FPOptionsOverride.
   //
-  // Note that we store the offset in bytes from the this pointer to the start
-  // of the trailing objects. It would be perfectly possible to compute it
-  // based on the dynamic kind of the CallExpr. However 1.) we have plenty of
-  // space in the bit-fields of Stmt. 2.) It was benchmarked to be faster to
-  // compute this once and then load the offset from the bit-fields of Stmt,
-  // instead of re-computing the offset each time the trailing objects are
-  // accessed.
+  // CallExpr subclasses are asssumed to be 32 bytes or less, and CallExpr
+  // itself is 24 bytes. To avoid having to recompute or store the offset of 
the
+  // trailing objects, we put it at 32 bytes (such that it is suitable for all
+  // subclasses) We use the 8 bytes gap left for instances of CallExpr to store

cor3ntin wrote:

We have 4 bytes left now. But yeah, ff we need more space, we would need a 
different strategy

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


[clang] [Clang] Allow parsing arbitrary order of attributes for declarations (PR #133107)

2025-05-22 Thread Aaron Ballman via cfe-commits

AaronBallman wrote:

> > I think we need to understand what we want before we can make decisions on 
> > what needs changing, though. Are there invariants we want to introduce, 
> > like the source range for the AST node should encompass the source 
> > locations tracked within the AST node? Or are we fine with the AST node 
> > tracking source locations which exist outside of the source range for the 
> > node itself? How do we want users of the AST to understand what the source 
> > range represents?
> 
> I think semantically connecting all the requirements of source tools to AST 
> nodes is difficult.
> 
> > I am currently leaning towards the idea that the source range for an AST 
> > node should be the union of the ranges tracked by the node and its children.
> 
> I think this makes sense and sounds principled on paper, but achieving that 
> isn't feasible without breaking users every time we take a step towards it.

Agreed, but any changes to source location fidelity will break users unless 
it's exposing a new source location we didn't previously expose. Tooling gets 
ABI stability guarantees, it does not get behavioral stability guarantees; we 
still need to be able to evolve the compiler as languages and the state of the 
art move forward.

> > Someday, if we start tracking source locations for the storage class 
> > specifiers, the range may expand to include those.
> 
> I think that would be a breaking change for downstream consumers once again. 
> People will rely on those changes not being part of the outer decls, and when 
> we expand them, we'll regress those (e.g. tools that just rewrite types, will 
> start dropping storage specifiers all of a sudden).
> 
> I really don't know the answer here, and the more I think the harder it 
> feels. 

Same!

> Even if we didn't have this "incremental issues result in regressions for the 
> users" issue, as you've also pointed out, I don't think modelling AST nodes 
> as "properly nested" works for C++ :/ Ignoring macros, pragmas, comments; 
> declarator syntax itself means type and name of a declaration might be 
> nested, instead of being siblings.

Yeah, that's a fair point.

> So I'd probably just keep the source range definition for composite 
> definitions as-is today, claim them deprecated and just provide "self" 
> locations for ast nodes, possibly making it multiple locations to model any 
> discontinuities. e.g. a `VarDecl` would only point to its `name`. you'd need 
> to drill down into specific parts of it if your tool is interested in the 
> rest. This sounds like a much simpler contract, and can be incrementally 
> implemented as well. Moreover it will be stable, no matter what changes we 
> make to AST, as long as an AST node is there, source location associated with 
> it will stay there.

I think this may be the most principled way forward, but there are some moving 
parts.

This means we need to track a lot more source locations in the AST, which comes 
with overhead. We don't know the impacts of that increased overhead, some of it 
may be too painful for us to want to bear.

Once we've started tracking enough source location information for an AST node 
that we no longer need to track the range, we can deprecate the internal range 
API (since we now have something else we can switch to).

Once we've replaced all the range uses with the source location uses, we can 
get rid of the range API for that node.

But this leaves the question about what to do for tooling. We have 
`clang_getCursorExtent()` (and others) as exposed APIs. We promise people ABI 
stability, so deprecating an API in libclang is kind of an academic exercise 
because we can't remove the interface. So do we mark it as deprecated and 
update the comments to explain it no longer returns a range, just a single 
location? Or do we try to put range logic into libclang to try to keep some of 
the cursors limping along with the previous behavior? Something else?

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


[clang] [clang][CodeGen] Fix crash on non-natural type in CheckAtomicAlignment (PR #141053)

2025-05-22 Thread Matt Arsenault via cfe-commits

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

Doesn't seem right that this is looking to the IR for the size instead of 
directly at the source type 

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


[clang] [clang-tools-extra] [clang][dataflow] Add bugprone-dataflow-dead-code check (PR #139068)

2025-05-22 Thread via cfe-commits

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


[clang] [Clang] Optimize some `getBeginLoc` implementations (PR #141058)

2025-05-22 Thread Erich Keane via cfe-commits


@@ -3187,9 +3215,48 @@ class CallExpr : public Expr {
   SourceLocation getRParenLoc() const { return RParenLoc; }
   void setRParenLoc(SourceLocation L) { RParenLoc = L; }
 
-  SourceLocation getBeginLoc() const LLVM_READONLY;
-  SourceLocation getEndLoc() const LLVM_READONLY;
+  SourceLocation getBeginLoc() const {
+if (CallExprBits.HasTrailingSourceLoc) {
+assert(CallExprBits.HasTrailingSourceLoc && "No trailing source loc");
+static_assert(sizeof(CallExpr) <=
+  offsetToTrailingObjects + sizeof(SourceLocation));
+return *reinterpret_cast(
+reinterpret_cast(this) + sizeof(CallExpr));
+}
+
+if (usesMemberSyntax()) {

erichkeane wrote:

no curleys on single liners?

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


[clang] [Clang] Optimize some `getBeginLoc` implementations (PR #141058)

2025-05-22 Thread via cfe-commits

https://github.com/cor3ntin updated 
https://github.com/llvm/llvm-project/pull/141058

>From 381c2219e346acfbf5b61e93fcc3233af6b7c3a7 Mon Sep 17 00:00:00 2001
From: Corentin Jabot 
Date: Wed, 21 May 2025 23:09:00 +0200
Subject: [PATCH 01/10] try optimize

---
 clang/lib/AST/Expr.cpp | 11 ++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index fe874ccd7b60f..1906e46042cad 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -1544,7 +1544,16 @@ unsigned CallExpr::offsetToTrailingObjects(StmtClass SC) 
{
 }
 
 Decl *Expr::getReferencedDeclOfCallee() {
-  Expr *CEE = IgnoreParenImpCasts();
+
+  // Optimize for the common case first
+  // (simple function or member function call)
+  // then try more exotic possibilities
+  Expr *CEE = IgnoreImpCasts();
+  if (auto *DRE = dyn_cast(CEE))
+return DRE->getDecl();
+
+  if (auto *ME = dyn_cast(CEE))
+return ME->getMemberDecl();
 
   while (auto *NTTP = dyn_cast(CEE))
 CEE = NTTP->getReplacement()->IgnoreParenImpCasts();

>From 16077ed74794645452434c9ec761d642789e09ac Mon Sep 17 00:00:00 2001
From: Corentin Jabot 
Date: Thu, 22 May 2025 00:28:05 +0200
Subject: [PATCH 02/10] remove call to getCalleeDecl

---
 clang/include/clang/AST/Expr.h|  5 +
 clang/include/clang/AST/Stmt.h|  5 +++--
 clang/lib/AST/Expr.cpp| 21 ++---
 clang/lib/Sema/SemaOpenCL.cpp |  2 +-
 clang/lib/Sema/SemaOverload.cpp   |  2 ++
 clang/lib/Serialization/ASTReaderStmt.cpp |  2 ++
 clang/lib/Serialization/ASTWriterStmt.cpp |  2 ++
 7 files changed, 25 insertions(+), 14 deletions(-)

diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index e9c3c16c87598..a8bfae2e7efda 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -3028,6 +3028,9 @@ class CallExpr : public Expr {
 
   bool hasStoredFPFeatures() const { return CallExprBits.HasFPFeatures; }
 
+  bool usesMemberSyntax() const { return 
CallExprBits.ExplicitObjectMemFunUsingMemberSyntax; }
+  void setUsesMemberSyntax(bool V = true) { 
CallExprBits.ExplicitObjectMemFunUsingMemberSyntax = V; }
+
   bool isCoroElideSafe() const { return CallExprBits.IsCoroElideSafe; }
   void setCoroElideSafe(bool V = true) { CallExprBits.IsCoroElideSafe = V; }
 
@@ -3220,6 +3223,8 @@ class CallExpr : public Expr {
   }
 };
 
+static_assert(sizeof(CallExpr) == 24);
+
 /// MemberExpr - [C99 6.5.2.3] Structure and Union Members.  X->F and X.F.
 ///
 class MemberExpr final
diff --git a/clang/include/clang/AST/Stmt.h b/clang/include/clang/AST/Stmt.h
index 336eb6d3df7e1..b3ad285ca73fd 100644
--- a/clang/include/clang/AST/Stmt.h
+++ b/clang/include/clang/AST/Stmt.h
@@ -563,10 +563,11 @@ class alignas(void *) Stmt {
 unsigned HasFPFeatures : 1;
 
 /// True if the call expression is a must-elide call to a coroutine.
+LLVM_PREFERRED_TYPE(bool)
 unsigned IsCoroElideSafe : 1;
 
-/// Padding used to align OffsetToTrailingObjects to a byte multiple.
-unsigned : 24 - 4 - NumExprBits;
+LLVM_PREFERRED_TYPE(bool)
+unsigned ExplicitObjectMemFunUsingMemberSyntax : 1;
 
 /// The offset in bytes from the this pointer to the start of the
 /// trailing objects belonging to CallExpr. Intentionally byte sized
diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index 1906e46042cad..e6ccd0904eefd 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -1484,6 +1484,8 @@ CallExpr::CallExpr(StmtClass SC, Expr *Fn, ArrayRef PreArgs,
 
   CallExprBits.HasFPFeatures = FPFeatures.requiresTrailingStorage();
   CallExprBits.IsCoroElideSafe = false;
+  CallExprBits.ExplicitObjectMemFunUsingMemberSyntax = false;
+
   if (hasStoredFPFeatures())
 setStoredFPFeatures(FPFeatures);
 }
@@ -1549,12 +1551,15 @@ Decl *Expr::getReferencedDeclOfCallee() {
   // (simple function or member function call)
   // then try more exotic possibilities
   Expr *CEE = IgnoreImpCasts();
+
   if (auto *DRE = dyn_cast(CEE))
 return DRE->getDecl();
 
   if (auto *ME = dyn_cast(CEE))
 return ME->getMemberDecl();
 
+  CEE = CEE->IgnoreParens();
+
   while (auto *NTTP = dyn_cast(CEE))
 CEE = NTTP->getReplacement()->IgnoreParenImpCasts();
 
@@ -1658,20 +1663,14 @@ SourceLocation CallExpr::getBeginLoc() const {
   // begin location should come from the first argument.
   // This does not apply to dependent calls, which are modelled with `o.f`
   // being the callee.
-  if (!isTypeDependent()) {
-if (const auto *Method =
-dyn_cast_if_present(getCalleeDecl());
-Method && Method->isExplicitObjectMemberFunction()) {
-  if (auto FirstArgLoc = getArg(0)->getBeginLoc(); FirstArgLoc.isValid()) {
-return FirstArgLoc;
-  }
+  // Because this check is expennsive, we cache the result.
+  if (usesMemberSyntax()) {
+if (auto FirstArgLoc = getArg(0)->getBeginLoc(); FirstArgLoc.isValid()) {
+  

[clang] [llvm] Add macro to suppress -Wunnecessary-virtual-specifier (PR #139614)

2025-05-22 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`clang-s390x-linux-multistage` running on `systemz-1` while building 
`clang,llvm` at step 4 "build stage 1".

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


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

```
Step 4 (build stage 1) failure: 'ninja -j4' (failure)
[1/6104] Building CXX object 
lib/Demangle/CMakeFiles/LLVMDemangle.dir/Demangle.cpp.o
[2/6104] Building CXX object 
lib/Demangle/CMakeFiles/LLVMDemangle.dir/DLangDemangle.cpp.o
[3/6104] Building CXX object 
lib/Support/CMakeFiles/LLVMSupport.dir/ABIBreak.cpp.o
[4/6104] Building CXX object 
lib/Demangle/CMakeFiles/LLVMDemangle.dir/RustDemangle.cpp.o
[5/6104] Building CXX object 
lib/Demangle/CMakeFiles/LLVMDemangle.dir/MicrosoftDemangleNodes.cpp.o
[6/6104] Building CXX object 
lib/Support/CMakeFiles/LLVMSupport.dir/AMDGPUMetadata.cpp.o
FAILED: lib/Support/CMakeFiles/LLVMSupport.dir/AMDGPUMetadata.cpp.o 
CCACHE_CPP2=yes CCACHE_HASHDIR=yes CCACHE_SLOPPINESS=pch_defines,time_macros 
/usr/bin/ccache /usr/bin/c++ -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GLIBCXX_ASSERTIONS 
-D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS 
-D__STDC_LIMIT_MACROS 
-I/home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/stage1/lib/Support
 
-I/home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/llvm/lib/Support
 -I/home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/stage1/include 
-I/home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/llvm/include
 -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden 
-Werror=date-time -Wall -Wextra -Wno-unused-parameter -Wwrite-strings 
-Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long 
-Wimplicit-fallthrough -Wno-uninitialized -Wno-nonnull -Wno-class-memaccess 
-Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type 
-Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment 
-Wno-misleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color 
-ffunction-sections -fdata-sections -O3 -DNDEBUG -UNDEBUG -std=c++17  
-fno-exceptions -funwind-tables -fno-rtti -MD -MT 
lib/Support/CMakeFiles/LLVMSupport.dir/AMDGPUMetadata.cpp.o -MF 
lib/Support/CMakeFiles/LLVMSupport.dir/AMDGPUMetadata.cpp.o.d -o 
lib/Support/CMakeFiles/LLVMSupport.dir/AMDGPUMetadata.cpp.o -c 
/home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/llvm/lib/Support/AMDGPUMetadata.cpp
In file included from 
/home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/llvm/include/llvm/ADT/STLFunctionalExtras.h:19,
 from 
/home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/llvm/include/llvm/ADT/StringRef.h:13,
 from 
/home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/llvm/include/llvm/Support/AMDGPUMetadata.h:18,
 from 
/home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/llvm/lib/Support/AMDGPUMetadata.cpp:15:
/home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/llvm/include/llvm/Support/Compiler.h:719:40:
 error: missing binary operator before token "("
  719 | #if defined(__clang__) && 
__has_warning("-Wunnecessary-virtual-specifier")
  |^
[7/6104] Building CXX object 
lib/Demangle/CMakeFiles/LLVMDemangle.dir/MicrosoftDemangle.cpp.o
[8/6104] Building CXX object 
lib/Support/CMakeFiles/LLVMSupport.dir/APFixedPoint.cpp.o
FAILED: lib/Support/CMakeFiles/LLVMSupport.dir/APFixedPoint.cpp.o 
CCACHE_CPP2=yes CCACHE_HASHDIR=yes CCACHE_SLOPPINESS=pch_defines,time_macros 
/usr/bin/ccache /usr/bin/c++ -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GLIBCXX_ASSERTIONS 
-D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS 
-D__STDC_LIMIT_MACROS 
-I/home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/stage1/lib/Support
 
-I/home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/llvm/lib/Support
 -I/home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/stage1/include 
-I/home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/llvm/include
 -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden 
-Werror=date-time -Wall -Wextra -Wno-unused-parameter -Wwrite-strings 
-Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long 
-Wimplicit-fallthrough -Wno-uninitialized -Wno-nonnull -Wno-class-memaccess 
-Wno-redundant-move -Wno-pessimizing-move -Wno-noexcept-type 
-Wdelete-non-virtual-dtor -Wsuggest-override -Wno-comment 
-Wno-misleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color 
-ffunction-sections -fdata-sections -O3 -DNDEBUG -UNDEBUG -std=c++17  
-fno-exceptions -funwind-tables -fno-rtti -MD -MT 
lib/Support/CMakeFiles/LLVMSupport.dir/APFixedPoint.cpp.o -MF 
lib/Support/CMakeFiles/LLVMSupport.dir/APFixedPoint.cpp.o.d -o 
lib/Support/CMakeFiles/LLVMSupport.dir/APFixedPoint.cpp.o -c 
/home/uweigand/sandbox/buildbot/clang-s390x-linux-multistage/llvm/llvm/lib/Support/APFixedPoi

[clang] [clang-format] Add AlignAfterOpenBracketOptions (PR #108332)

2025-05-22 Thread Gedare Bloom via cfe-commits

https://github.com/gedare updated 
https://github.com/llvm/llvm-project/pull/108332

>From 5972376f719665225b04bf121cda6c769e3392d9 Mon Sep 17 00:00:00 2001
From: Gedare Bloom 
Date: Thu, 20 Jun 2024 17:35:39 -0600
Subject: [PATCH 1/9] Format: add AlignAfterControlStatement

Introduce new style option to allow overriding the breaking after the
opening parenthesis for control statements (if/for/while/switch).

Fixes #67738.
Fixes #79176.
Fixes #80123.
---
 clang/include/clang/Format/Format.h|  17 ++
 clang/lib/Format/ContinuationIndenter.cpp  |  69 +++--
 clang/lib/Format/Format.cpp|  13 +
 clang/lib/Format/TokenAnnotator.cpp|   8 +-
 clang/unittests/Format/ConfigParseTest.cpp |   8 +
 clang/unittests/Format/FormatTest.cpp  | 298 +
 6 files changed, 391 insertions(+), 22 deletions(-)

diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 3ac4318824ac0..2b2bcb6764e9b 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -62,6 +62,22 @@ struct FormatStyle {
   /// \version 3.3
   int AccessModifierOffset;
 
+  /// Different styles for breaking the parenthesis after a control statement
+  /// (``if/switch/while/for ...``).
+  /// \version 21
+  enum BreakAfterControlStatementStyle : int8_t {
+/// Use the default behavior.
+BACSS_Default,
+/// Force break after the left parenthesis of a control statement only
+/// when the expression exceeds the column limit, and align on the
+/// ``ContinuationIndentWidth``.
+BACSS_MultiLine,
+/// Do not force a break after the control statment.
+BACSS_No,
+  };
+
+  BreakAfterControlStatementStyle AlignAfterControlStatement;
+
   /// Different styles for aligning after open brackets.
   enum BracketAlignmentStyle : int8_t {
 /// Align parameters on the open bracket, e.g.:
@@ -5305,6 +5321,7 @@ struct FormatStyle {
 
   bool operator==(const FormatStyle &R) const {
 return AccessModifierOffset == R.AccessModifierOffset &&
+   AlignAfterControlStatement == R.AlignAfterControlStatement &&
AlignAfterOpenBracket == R.AlignAfterOpenBracket &&
AlignArrayOfStructures == R.AlignArrayOfStructures &&
AlignConsecutiveAssignments == R.AlignConsecutiveAssignments &&
diff --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index 4e4e48f90a89f..f91da11cd2f44 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -814,6 +814,11 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState 
&State, bool DryRun,
   // parenthesis by disallowing any further line breaks if there is no line
   // break after the opening parenthesis. Don't break if it doesn't conserve
   // columns.
+  auto IsOtherConditional = [&](const FormatToken &Tok) {
+return Tok.isOneOf(tok::kw_for, tok::kw_while, tok::kw_switch) ||
+   (Style.isJavaScript() && Tok.is(Keywords.kw_await) && Tok.Previous 
&&
+Tok.Previous->is(tok::kw_for));
+  };
   auto IsOpeningBracket = [&](const FormatToken &Tok) {
 auto IsStartOfBracedList = [&]() {
   return Tok.is(tok::l_brace) && Tok.isNot(BK_Block) &&
@@ -825,26 +830,36 @@ void 
ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun,
 }
 if (!Tok.Previous)
   return true;
-if (Tok.Previous->isIf())
-  return Style.AlignAfterOpenBracket == FormatStyle::BAS_AlwaysBreak;
-return !Tok.Previous->isOneOf(TT_CastRParen, tok::kw_for, tok::kw_while,
-  tok::kw_switch) &&
-   !(Style.isJavaScript() && Tok.Previous->is(Keywords.kw_await));
+if (Tok.Previous->isIf()) {
+  /* For backward compatibility, use AlignAfterOpenBracket
+   * in case AlignAfterControlStatement is not initialized */
+  return Style.AlignAfterControlStatement == FormatStyle::BACSS_MultiLine 
||
+ (Style.AlignAfterControlStatement == FormatStyle::BACSS_Default &&
+  Style.AlignAfterOpenBracket == FormatStyle::BAS_AlwaysBreak);
+}
+if (IsOtherConditional(*Tok.Previous))
+  return Style.AlignAfterControlStatement == FormatStyle::BACSS_MultiLine;
+if (Style.AlignAfterOpenBracket == FormatStyle::BAS_AlwaysBreak ||
+Style.AlignAfterOpenBracket == FormatStyle::BAS_BlockIndent) {
+  return !Tok.Previous->is(TT_CastRParen) &&
+ !(Style.isJavaScript() && Tok.is(Keywords.kw_await));
+}
+return false;
   };
   auto IsFunctionCallParen = [](const FormatToken &Tok) {
 return Tok.is(tok::l_paren) && Tok.ParameterCount > 0 && Tok.Previous &&
Tok.Previous->is(tok::identifier);
   };
-  auto IsInTemplateString = [this](const FormatToken &Tok) {
+  auto IsInTemplateString = [this](const FormatToken &Tok, bool NestBlocks) {
 if (!Style.isJavaScript())
   return false;
 for (const auto *Prev = &Tok; Prev; Pre

[clang] [Clang] Optimize some `getBeginLoc` implementations (PR #141058)

2025-05-22 Thread via cfe-commits


@@ -3028,6 +3043,19 @@ class CallExpr : public Expr {
 
   bool hasStoredFPFeatures() const { return CallExprBits.HasFPFeatures; }
 
+  bool usesMemberSyntax() const {
+return CallExprBits.ExplicitObjectMemFunUsingMemberSyntax;
+  }
+  void setUsesMemberSyntax(bool V = true) {
+CallExprBits.ExplicitObjectMemFunUsingMemberSyntax = V;
+// Because the source location may be different for explicit
+// member, we reset the cached values.
+if (CallExprBits.HasTrailingSourceLoc) {
+  CallExprBits.HasTrailingSourceLoc = false;
+  updateTrailingSourceLoc();

cor3ntin wrote:

I have not benchmarked - it avoids a branch in getBeginLoc (we would have to 
check that we _can_ cache, as subclasses can't)

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


[clang] [Clang] Optimize some `getBeginLoc` implementations (PR #141058)

2025-05-22 Thread Younan Zhang via cfe-commits


@@ -563,17 +563,21 @@ class alignas(void *) Stmt {
 unsigned HasFPFeatures : 1;
 
 /// True if the call expression is a must-elide call to a coroutine.
+LLVM_PREFERRED_TYPE(bool)
 unsigned IsCoroElideSafe : 1;
 
-/// Padding used to align OffsetToTrailingObjects to a byte multiple.
-unsigned : 24 - 4 - NumExprBits;
+/// Tracks When CallExpr is used to represent an explicit object

zyn0217 wrote:

```suggestion
/// Tracks when CallExpr is used to represent an explicit object
```

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


[clang] [Clang] Optimize some `getBeginLoc` implementations (PR #141058)

2025-05-22 Thread Younan Zhang via cfe-commits


@@ -1638,43 +1647,6 @@ CallExpr::getUnusedResultAttr(const ASTContext &Ctx) 
const {
   return {nullptr, nullptr};
 }
 
-SourceLocation CallExpr::getBeginLoc() const {
-  if (const auto *OCE = dyn_cast(this))
-return OCE->getBeginLoc();
-
-  // A non-dependent call to a member function with an explicit object 
parameter
-  // is modelled with the object expression being the first argument, e.g. in
-  // `o.f(x)`, the callee will be just `f`, and `o` will be the first argument.
-  // Since the first argument is written before the callee, the expression's
-  // begin location should come from the first argument.
-  // This does not apply to dependent calls, which are modelled with `o.f`
-  // being the callee.
-  if (!isTypeDependent()) {
-if (const auto *Method =
-dyn_cast_if_present(getCalleeDecl());
-Method && Method->isExplicitObjectMemberFunction()) {
-  if (auto FirstArgLoc = getArg(0)->getBeginLoc(); FirstArgLoc.isValid()) {
-return FirstArgLoc;
-  }
-}
-  }
-
-  SourceLocation begin = getCallee()->getBeginLoc();
-  if (begin.isInvalid() && getNumArgs() > 0 && getArg(0))
-begin = getArg(0)->getBeginLoc();
-  return begin;
-}
-
-SourceLocation CallExpr::getEndLoc() const {
-  if (const auto *OCE = dyn_cast(this))
-return OCE->getEndLoc();
-
-  SourceLocation end = getRParenLoc();
-  if (end.isInvalid() && getNumArgs() > 0 && getArg(getNumArgs() - 1))
-end = getArg(getNumArgs() - 1)->getEndLoc();

zyn0217 wrote:

Are they never exercised? And where do we handle CXXOperatorCallExpr now?

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


[clang] [Clang] Optimize some `getBeginLoc` implementations (PR #141058)

2025-05-22 Thread Erich Keane via cfe-commits


@@ -3028,6 +3043,19 @@ class CallExpr : public Expr {
 
   bool hasStoredFPFeatures() const { return CallExprBits.HasFPFeatures; }
 
+  bool usesMemberSyntax() const {
+return CallExprBits.ExplicitObjectMemFunUsingMemberSyntax;
+  }
+  void setUsesMemberSyntax(bool V = true) {
+CallExprBits.ExplicitObjectMemFunUsingMemberSyntax = V;
+// Because the source location may be different for explicit
+// member, we reset the cached values.
+if (CallExprBits.HasTrailingSourceLoc) {
+  CallExprBits.HasTrailingSourceLoc = false;
+  updateTrailingSourceLoc();

erichkeane wrote:

Oh, hrmph... My mental benchmark is whether every callexpr gets its `BeginLoc` 
queried at least 1x.  My hope/intuition is that we wouldn't call it very often 
unless doing some sort of ast-dump/etc, but the benchmarks obviously show my 
intuition to be wrong.  So this NOT being a use-initiated cache is perhaps the 
right answer.  So, I think I'm talking myself out of this suggestion :)

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


[clang] [Clang] Optimize some `getBeginLoc` implementations (PR #141058)

2025-05-22 Thread Younan Zhang via cfe-commits


@@ -296,14 +298,18 @@ class NestedNameSpecifierLoc {
   /// Retrieve the location of the beginning of this
   /// nested-name-specifier.
   SourceLocation getBeginLoc() const {
-return getSourceRange().getBegin();
+if (!Qualifier)
+  return SourceLocation();
+
+NestedNameSpecifierLoc First = *this;
+while (NestedNameSpecifierLoc Prefix = First.getPrefix())
+  First = Prefix;
+return First.getLocalSourceRange().getBegin();

zyn0217 wrote:

I didn't see the differences of changes on these functions... Are they related?

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


[clang] [Clang] Optimize some `getBeginLoc` implementations (PR #141058)

2025-05-22 Thread Younan Zhang via cfe-commits


@@ -542,7 +542,8 @@ bool SemaOpenCL::checkBuiltinToAddr(unsigned BuiltinID, 
CallExpr *Call) {
   auto RT = Call->getArg(0)->getType();
   if (!RT->isPointerType() ||
   RT->getPointeeType().getAddressSpace() == LangAS::opencl_constant) {
-Diag(Call->getBeginLoc(), diag::err_opencl_builtin_to_addr_invalid_arg)
+Diag(Call->getArg(0)->getBeginLoc(),

zyn0217 wrote:

Why Call->getBeginLoc() no longer works?

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


[clang] [clang-format] Add AlignAfterOpenBracketOptions (PR #108332)

2025-05-22 Thread Gedare Bloom via cfe-commits


@@ -3373,6 +3409,51 @@ the configuration (without a prefix: ``Auto``).
 
 
 
+.. _BreakBeforeCloseBracketIf:
+
+**BreakBeforeCloseBracketIf** (``Boolean``) :versionbadge:`clang-format 21` 
:ref:`¶ `
+  Force break before the right parenthesis of an if control statement
+  when the expression exceeds the column limit. The break before the
+  closing parenthesis is only made if there is a break after the opening
+  parenthesis.
+
+  .. code-block:: c++
+
+true: false:
+if constexpr (  vs.   if constexpr (a ||

gedare wrote:

I probably need to fix the `false` case though, as disabling the option will 
not affect the break after the opener.

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


[clang] [clang][analyzer] Refine modeling of 'getcwd' in StdCLibraryFunctions checker (PR #141076)

2025-05-22 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-static-analyzer-1

Author: Balázs Kéri (balazske)


Changes

Add extra branches for the case when the buffer argument is NULL.

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


2 Files Affected:

- (modified) clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp 
(+10-4) 
- (modified) clang/test/Analysis/errno-stdlibraryfunctions.c (+14-1) 


``diff
diff --git a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
index 3c6c3123f5cdd..6dae817fe89b5 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -2651,16 +2651,22 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
 addToFunctionSummaryMap(
 "getcwd", Signature(ArgTypes{CharPtrTy, SizeTy}, RetType{CharPtrTy}),
 Summary(NoEvalCall)
-.Case({ArgumentCondition(1, WithinRange, Range(1, SizeMax)),
+.Case({NotNull(0),
+   ArgumentCondition(1, WithinRange, Range(1, SizeMax)),
ReturnValueCondition(BO_EQ, ArgNo(0))},
   ErrnoMustNotBeChecked, GenericSuccessMsg)
-.Case({ArgumentCondition(1, WithinRange, SingleValue(0)),
+.Case({NotNull(0),
+   ArgumentCondition(1, WithinRange, SingleValue(0)),
IsNull(Ret)},
   ErrnoNEZeroIrrelevant, "Assuming that argument 'size' is 0")
-.Case({ArgumentCondition(1, WithinRange, Range(1, SizeMax)),
+.Case({NotNull(0),
+   ArgumentCondition(1, WithinRange, Range(1, SizeMax)),
IsNull(Ret)},
   ErrnoNEZeroIrrelevant, GenericFailureMsg)
-.ArgConstraint(NotNull(ArgNo(0)))
+.Case({IsNull(0), NotNull(Ret)}, ErrnoMustNotBeChecked,
+  GenericSuccessMsg)
+.Case({IsNull(0), IsNull(Ret)}, ErrnoNEZeroIrrelevant,
+  GenericFailureMsg)
 .ArgConstraint(
 BufferSize(/*Buffer*/ ArgNo(0), /*BufSize*/ ArgNo(1)))
 .ArgConstraint(
diff --git a/clang/test/Analysis/errno-stdlibraryfunctions.c 
b/clang/test/Analysis/errno-stdlibraryfunctions.c
index 657aa37a42670..72d167f68a1f4 100644
--- a/clang/test/Analysis/errno-stdlibraryfunctions.c
+++ b/clang/test/Analysis/errno-stdlibraryfunctions.c
@@ -99,7 +99,9 @@ void errno_mkdtemp3(CHAR_PTR template) {
   }
 }
 
-void errno_getcwd(char *Buf, size_t Sz) {
+void errno_getcwd_buf_nonnull(char *Buf, size_t Sz) {
+  if (Buf == NULL)
+return;
   char *Path = getcwd(Buf, Sz);
   if (Sz == 0) {
 clang_analyzer_eval(errno != 0);   // expected-warning{{TRUE}}
@@ -114,6 +116,17 @@ void errno_getcwd(char *Buf, size_t Sz) {
   }
 }
 
+void errno_getcwd_buf_null() {
+  // POSIX does not mention this case but many implementations (Linux, 
FreeBSD) work this way.
+  char *Path = getcwd(NULL, 1);
+  if (Path == NULL) {
+clang_analyzer_eval(errno != 0);   // expected-warning{{TRUE}}
+if (errno) {}  // no warning
+  } else {
+if (errno) {}  // expected-warning{{An undefined value 
may be read from 'errno'}}
+  }
+}
+
 void errno_execv(char *Path, char * Argv[]) {
   int Ret = execv(Path, Argv);
   clang_analyzer_eval(Ret == -1);  // expected-warning{{TRUE}}

``




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


[clang] [flang] [lld] [lldb] [llvm] [mlir] [polly] [CMake] respect LLVMConfig.cmake's LLVM_DEFINITIONS in standalone builds (PR #138587)

2025-05-22 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `clang-ppc64-aix` running 
on `aix-ppc64` while building `bolt,clang,flang,lld,lldb,mlir,polly` at step 6 
"test-build-unified-tree-check-all".

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


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

```
Step 6 (test-build-unified-tree-check-all) failure: test (failure)
 TEST 'lit :: timeout-hang.py' FAILED 
Exit Code: 1

Command Output (stdout):
--
# RUN: at line 13
not env -u FILECHECK_OPTS 
"/home/llvm/llvm-external-buildbots/workers/env/bin/python3.11" 
/home/llvm/llvm-external-buildbots/workers/aix-ppc64/clang-ppc64-aix/llvm-project/llvm/utils/lit/lit.py
 -j1 --order=lexical Inputs/timeout-hang/run-nonexistent.txt  --timeout=1 
--param external=0 | 
"/home/llvm/llvm-external-buildbots/workers/env/bin/python3.11" 
/home/llvm/llvm-external-buildbots/workers/aix-ppc64/clang-ppc64-aix/build/utils/lit/tests/timeout-hang.py
 1
# executed command: not env -u FILECHECK_OPTS 
/home/llvm/llvm-external-buildbots/workers/env/bin/python3.11 
/home/llvm/llvm-external-buildbots/workers/aix-ppc64/clang-ppc64-aix/llvm-project/llvm/utils/lit/lit.py
 -j1 --order=lexical Inputs/timeout-hang/run-nonexistent.txt --timeout=1 
--param external=0
# .---command stderr
# | lit.py: 
/home/llvm/llvm-external-buildbots/workers/aix-ppc64/clang-ppc64-aix/llvm-project/llvm/utils/lit/lit/main.py:72:
 note: The test suite configuration requested an individual test timeout of 0 
seconds but a timeout of 1 seconds was requested on the command line. Forcing 
timeout to be 1 seconds.
# `-
# executed command: 
/home/llvm/llvm-external-buildbots/workers/env/bin/python3.11 
/home/llvm/llvm-external-buildbots/workers/aix-ppc64/clang-ppc64-aix/build/utils/lit/tests/timeout-hang.py
 1
# .---command stdout
# | Testing took as long or longer than timeout
# `-
# error: command failed with exit status: 1

--




```



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


[clang] [Preprocessor] Do not expand macros if the input is already preprocessed (PR #137665)

2025-05-22 Thread Juan Manuel Martinez Caamaño via cfe-commits

https://github.com/jmmartinez updated 
https://github.com/llvm/llvm-project/pull/137665

From 72bc06251047bb92a5bc6a068670b047c078a3c3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Juan=20Manuel=20Martinez=20Caama=C3=B1o?= 
Date: Mon, 28 Apr 2025 17:05:46 +0200
Subject: [PATCH 1/4] Pre-commit test: [Preprocessor] Do not expand macros if
 the input is already preprocessed

---
 clang/test/Preprocessor/preprocess-cpp-output.c | 9 +
 1 file changed, 9 insertions(+)
 create mode 100644 clang/test/Preprocessor/preprocess-cpp-output.c

diff --git a/clang/test/Preprocessor/preprocess-cpp-output.c 
b/clang/test/Preprocessor/preprocess-cpp-output.c
new file mode 100644
index 0..59ff057e9b871
--- /dev/null
+++ b/clang/test/Preprocessor/preprocess-cpp-output.c
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -E -x c %s | FileCheck %s --check-prefixes=EXPANDED
+// RUN: %clang_cc1 -E -x cpp-output %s | FileCheck %s --check-prefixes=EXPANDED
+
+// EXPANDED: void __attribute__((__attribute__((always_inline foo()
+
+#define always_inline __attribute__((always_inline))
+void __attribute__((always_inline)) foo() {
+return 4;
+}

From d6ca7b96d410348ace49cfea5666d83ecc9ca98a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Juan=20Manuel=20Martinez=20Caama=C3=B1o?= 
Date: Tue, 13 May 2025 15:03:46 +0200
Subject: [PATCH 2/4] [Modules] initializers.cpp test fix

The module contents should not contain preprocessor directives. The
contents should be already preprocessed.

Duplicate the modules instead to propose 2 versions: one with the
namespace ns and one without.
---
 clang/test/Modules/initializers.cpp | 59 +++--
 1 file changed, 55 insertions(+), 4 deletions(-)

diff --git a/clang/test/Modules/initializers.cpp 
b/clang/test/Modules/initializers.cpp
index dcd9b08ec6f7a..e1f826fbc09f3 100644
--- a/clang/test/Modules/initializers.cpp
+++ b/clang/test/Modules/initializers.cpp
@@ -48,6 +48,7 @@
 // instantiation for v in one of the two headers, because we will only
 // parse one of the two get() functions.
 
+#ifdef NS
 #pragma clang module build m
 module m {
   module a {
@@ -60,9 +61,7 @@ module m {
 #pragma clang module begin m.a
 inline int non_trivial() { return 3; }
 
-#ifdef NS
 namespace ns {
-#endif
 
 int a = non_trivial();
 inline int b = non_trivial();
@@ -102,12 +101,64 @@ inline void use(bool b, ...) {
   X::e, X::f, X::g, X::h);
 }
 
-#ifdef NS
 }
-#endif
 
 #pragma clang module end
 #pragma clang module endbuild
+#else
+#pragma clang module build m
+module m {
+  module a {
+header "foo.h" { size 123 mtime 456789 }
+  }
+  module b {}
+}
+
+#pragma clang module contents
+#pragma clang module begin m.a
+inline int non_trivial() { return 3; }
+
+int a = non_trivial();
+inline int b = non_trivial();
+thread_local int c = non_trivial();
+inline thread_local int d = non_trivial();
+
+template int e = non_trivial();
+template inline int f = non_trivial();
+template thread_local int g = non_trivial();
+template inline thread_local int h = non_trivial();
+
+inline int unused = 123; // should not be emitted
+
+template struct X {
+  static int a;
+  static inline int b = non_trivial();
+  static thread_local int c;
+  static inline thread_local int d = non_trivial();
+
+  template static int e;
+  template static inline int f = non_trivial();
+  template static thread_local int g;
+  template static inline thread_local int h = non_trivial();
+
+  static inline int unused = 123; // should not be emitted
+};
+
+template int X::a = non_trivial();
+template thread_local int X::c = non_trivial();
+template template int X::e = non_trivial();
+template template thread_local int X::g = 
non_trivial();
+
+inline void use(bool b, ...) {
+  if (b) return;
+  use(true, e, f, g, h,
+  X::a, X::b, X::c, X::d,
+  X::e, X::f, X::g, X::h);
+}
+
+#pragma clang module end
+#pragma clang module endbuild
+#endif
 
 #if IMPORT == 1
 // Import the module and the m.a submodule; runs the ordered initializers and

From 09c37acc1466a4680de0bcbedff7c0012d3e8969 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Juan=20Manuel=20Martinez=20Caama=C3=B1o?= 
Date: Tue, 22 Apr 2025 18:40:37 +0200
Subject: [PATCH 3/4] [Preprocessor] Do not expand macros if the input is
 already preprocessed

---
 clang/include/clang/Lex/Preprocessor.h  | 5 +
 clang/lib/Frontend/InitPreprocessor.cpp | 7 +++
 clang/test/Preprocessor/preprocess-cpp-output.c | 3 ++-
 3 files changed, 14 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Lex/Preprocessor.h 
b/clang/include/clang/Lex/Preprocessor.h
index f2dfd3a349b8b..63774e48a468b 100644
--- a/clang/include/clang/Lex/Preprocessor.h
+++ b/clang/include/clang/Lex/Preprocessor.h
@@ -1831,6 +1831,11 @@ class Preprocessor {
 MacroExpansionInDirectivesOverride = true;
   }
 
+  void SetDisableMacroExpansion() {
+DisableMacroExpansion = true;
+MacroExpansionInDirectivesOverride = false;
+  }
+
   /// Peeks ahead N tokens and returns that token without co

[clang] [Preprocessor] Do not expand macros if the input is already preprocessed (PR #137665)

2025-05-22 Thread Juan Manuel Martinez Caamaño via cfe-commits


@@ -1558,6 +1558,13 @@ void clang::InitializePreprocessor(Preprocessor &PP,
const PCHContainerReader &PCHContainerRdr,
const FrontendOptions &FEOpts,
const CodeGenOptions &CodeGenOpts) {
+
+  if (all_of(FEOpts.Inputs,
+ [](const FrontendInputFile &FI) { return FI.isPreprocessed(); })) 
{
+PP.SetDisableMacroExpansion();
+return;
+  }

jmmartinez wrote:

You're right, it makes more sense there. I've updated it to match.

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


[clang] [lld] [llvm] [mlir] [LLVM][Windows] Elide `PrettyStackTrace` output for usage errors (PR #140956)

2025-05-22 Thread via cfe-commits

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


[clang] [clang][CodeGen] Fix crash on non-natural type in CheckAtomicAlignment (PR #141053)

2025-05-22 Thread Matt Arsenault via cfe-commits


@@ -274,9 +274,10 @@ Value *EmitFromInt(CodeGenFunction &CGF, llvm::Value *V,
 Address CheckAtomicAlignment(CodeGenFunction &CGF, const CallExpr *E) {
   ASTContext &Ctx = CGF.getContext();
   Address Ptr = CGF.EmitPointerWithAlignment(E->getArg(0));
+  const llvm::DataLayout &DL = CGF.CGM.getDataLayout();
   unsigned Bytes = Ptr.getElementType()->isPointerTy()
? Ctx.getTypeSizeInChars(Ctx.VoidPtrTy).getQuantity()
-   : Ptr.getElementType()->getScalarSizeInBits() / 8;
+   : DL.getTypeSizeInBits(Ptr.getElementType()) / 8;

arsenm wrote:

```suggestion
   : DL.getTypeStoreSize(Ptr.getElementType());
```

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


[clang] [clang][CodeGen] Fix crash on non-natural type in CheckAtomicAlignment (PR #141053)

2025-05-22 Thread Matt Arsenault via cfe-commits


@@ -0,0 +1,45 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 5
+// RUN: %clang_cc1 -O0 -cl-std=CL2.0 -triple amdgcn-amd-amdhsa -target-cpu 
gfx942 \
+// RUN:   %s -emit-llvm -o - | FileCheck %s
+
+// REQUIRES: amdgpu-registered-target

arsenm wrote:

It shouldn't actually 

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


[clang] [clang][CodeGen] Fix crash on non-natural type in CheckAtomicAlignment (PR #141053)

2025-05-22 Thread Matt Arsenault via cfe-commits


@@ -0,0 +1,45 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 5
+// RUN: %clang_cc1 -O0 -cl-std=CL2.0 -triple amdgcn-amd-amdhsa -target-cpu 
gfx942 \

arsenm wrote:

-disable-llvm-passes, and can you use -cl-std=CL1.2

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


[clang] clang-format: Add IncludeSortKey option (PR #137840)

2025-05-22 Thread Daan De Meyer via cfe-commits


@@ -1647,7 +1647,7 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind 
Language) {
   LLVMStyle.SeparateDefinitionBlocks = FormatStyle::SDS_Leave;
   LLVMStyle.ShortNamespaceLines = 1;
   LLVMStyle.SkipMacroDefinitionBody = false;
-  LLVMStyle.SortIncludes = {/*Enabled=*/true, /*IgnoreCase=*/false};
+  LLVMStyle.SortIncludes = {/*Enabled=*/true, /*IgnoreCase=*/false, 
/*IgnoreExtension=*/false};

DaanDeMeyer wrote:

I'm very confused now what the suggestion is that I should apply here to make 
everyone happy

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


[clang] [clang][CodeGen] Fix crash on non-natural type in CheckAtomicAlignment (PR #141053)

2025-05-22 Thread Pierre van Houtryve via cfe-commits

https://github.com/Pierre-vh updated 
https://github.com/llvm/llvm-project/pull/141053

>From 68db9fad42369be31d935257a2d80962a4018892 Mon Sep 17 00:00:00 2001
From: pvanhout 
Date: Thu, 22 May 2025 14:13:54 +0200
Subject: [PATCH 1/4] [clang][CodeGen] Fix crash on non-natural type in
 CheckAtomicAlignment

In some specific scenarios, `Ptr.getElementType()` won't be a primitive
type or a vector of primitive types, and thus `getScalarSizeInBits()` returns
zero.

Use the datalayout to get the proper size of the type instead of making an 
implicit
assumption that the type is a simple primitive type.

Solves SWDEV-534184
---
 clang/lib/CodeGen/CGBuiltin.cpp   |  3 +-
 .../CodeGenOpenCL/check-atomic-alignment.cl   | 45 +++
 2 files changed, 47 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/CodeGenOpenCL/check-atomic-alignment.cl

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 04a0d9ba2bbce..749f716acfbe8 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -274,9 +274,10 @@ Value *EmitFromInt(CodeGenFunction &CGF, llvm::Value *V,
 Address CheckAtomicAlignment(CodeGenFunction &CGF, const CallExpr *E) {
   ASTContext &Ctx = CGF.getContext();
   Address Ptr = CGF.EmitPointerWithAlignment(E->getArg(0));
+  const llvm::DataLayout &DL = CGF.CGM.getDataLayout();
   unsigned Bytes = Ptr.getElementType()->isPointerTy()
? Ctx.getTypeSizeInChars(Ctx.VoidPtrTy).getQuantity()
-   : Ptr.getElementType()->getScalarSizeInBits() / 8;
+   : DL.getTypeSizeInBits(Ptr.getElementType()) / 8;
   unsigned Align = Ptr.getAlignment().getQuantity();
   if (Align % Bytes != 0) {
 DiagnosticsEngine &Diags = CGF.CGM.getDiags();
diff --git a/clang/test/CodeGenOpenCL/check-atomic-alignment.cl 
b/clang/test/CodeGenOpenCL/check-atomic-alignment.cl
new file mode 100644
index 0..6aa4bc26633f8
--- /dev/null
+++ b/clang/test/CodeGenOpenCL/check-atomic-alignment.cl
@@ -0,0 +1,45 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 5
+// RUN: %clang_cc1 -O0 -cl-std=CL2.0 -triple amdgcn-amd-amdhsa -target-cpu 
gfx942 \
+// RUN:   %s -emit-llvm -o - | FileCheck %s
+
+// REQUIRES: amdgpu-registered-target
+
+// `Ptr.getElementType()` in `CheckAtomicAlignment` returns
+//  %struct.__half2 = type { %union.anon }
+// Check we do not crash when handling that.
+
+typedef half  __attribute__((ext_vector_type(2))) half2;
+typedef short  __attribute__((ext_vector_type(2))) short2;
+
+struct __half2 {
+union {
+struct {
+half x;
+half y;
+};
+half2 data;
+};
+};
+
+// CHECK-LABEL: define dso_local <2 x half> @test_flat_add_2f16(
+// CHECK-SAME: ptr noundef [[ADDR:%.*]], <2 x half> noundef [[VAL:%.*]]) 
#[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  [[ENTRY:.*:]]
+// CHECK-NEXT:[[RETVAL:%.*]] = alloca <2 x half>, align 4, addrspace(5)
+// CHECK-NEXT:[[ADDR_ADDR:%.*]] = alloca ptr, align 8, addrspace(5)
+// CHECK-NEXT:[[VAL_ADDR:%.*]] = alloca <2 x half>, align 4, addrspace(5)
+// CHECK-NEXT:[[RETVAL_ASCAST:%.*]] = addrspacecast ptr addrspace(5) 
[[RETVAL]] to ptr
+// CHECK-NEXT:[[ADDR_ADDR_ASCAST:%.*]] = addrspacecast ptr addrspace(5) 
[[ADDR_ADDR]] to ptr
+// CHECK-NEXT:[[VAL_ADDR_ASCAST:%.*]] = addrspacecast ptr addrspace(5) 
[[VAL_ADDR]] to ptr
+// CHECK-NEXT:store ptr [[ADDR]], ptr [[ADDR_ADDR_ASCAST]], align 8
+// CHECK-NEXT:store <2 x half> [[VAL]], ptr [[VAL_ADDR_ASCAST]], align 4
+// CHECK-NEXT:[[TMP0:%.*]] = load ptr, ptr [[ADDR_ADDR_ASCAST]], align 8
+// CHECK-NEXT:[[TMP1:%.*]] = load <2 x half>, ptr [[VAL_ADDR_ASCAST]], 
align 4
+// CHECK-NEXT:[[TMP2:%.*]] = atomicrmw fadd ptr [[TMP0]], <2 x half> 
[[TMP1]] syncscope("agent") monotonic, align 4, !amdgpu.no.fine.grained.memory 
[[META4:![0-9]+]]
+// CHECK-NEXT:ret <2 x half> [[TMP2]]
+//
+half2 test_flat_add_2f16(__generic short2 *addr, half2 val) {
+  return __builtin_amdgcn_flat_atomic_fadd_v2f16((struct __half2*)addr, val);
+}
+//.
+// CHECK: [[META4]] = !{}
+//.

>From 11ddc4d93d36d1605390f9b4ffcf3233c342c90c Mon Sep 17 00:00:00 2001
From: pvanhout 
Date: Thu, 22 May 2025 14:46:37 +0200
Subject: [PATCH 2/4] comments

---
 clang/lib/CodeGen/CGBuiltin.cpp   |  2 +-
 .../CodeGenOpenCL/check-atomic-alignment.cl   | 26 +++
 2 files changed, 11 insertions(+), 17 deletions(-)

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 749f716acfbe8..809ffe549be88 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -277,7 +277,7 @@ Address CheckAtomicAlignment(CodeGenFunction &CGF, const 
CallExpr *E) {
   const llvm::DataLayout &DL = CGF.CGM.getDataLayout();
   unsigned Bytes = Ptr.getElementType()->isPointerTy()
? Ctx.getTypeSizeInChars(Ctx.VoidPtrTy).getQuantit

[clang] [Clang] Optimize some `getBeginLoc` implementations (PR #141058)

2025-05-22 Thread Aaron Ballman via cfe-commits

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


[clang] clang_EvalResult_getAsCXString impl (PR #134551)

2025-05-22 Thread via cfe-commits

cor3ntin wrote:

@AaronBallman I missed most of the discussion here, but the underlying object 
is an array.  Trying to find the null terminator once the pointer has decayed 
is asking for trouble. Is there a way to evaluate as an array? If not, that 
might be a better direction. That would be less awkward to use (and in that 
case the array would contain the whole string, including embedded and terminal 
nulls)

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


[clang] [Clang] Optimize some `getBeginLoc` implementations (PR #141058)

2025-05-22 Thread via cfe-commits

https://github.com/cor3ntin created 
https://github.com/llvm/llvm-project/pull/141058

The bulk of the changes are in `CallExpr`

We cache Begin/End source locs in the trailing objects, in the space left by 
making the offset to the trailing objects static.
We also set a flag to indicate that we are calling an explicit object member 
function, further reducing the cost of getBeginLoc.

Fixes #140876 

>From 381c2219e346acfbf5b61e93fcc3233af6b7c3a7 Mon Sep 17 00:00:00 2001
From: Corentin Jabot 
Date: Wed, 21 May 2025 23:09:00 +0200
Subject: [PATCH 1/8] try optimize

---
 clang/lib/AST/Expr.cpp | 11 ++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index fe874ccd7b60f..1906e46042cad 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -1544,7 +1544,16 @@ unsigned CallExpr::offsetToTrailingObjects(StmtClass SC) 
{
 }
 
 Decl *Expr::getReferencedDeclOfCallee() {
-  Expr *CEE = IgnoreParenImpCasts();
+
+  // Optimize for the common case first
+  // (simple function or member function call)
+  // then try more exotic possibilities
+  Expr *CEE = IgnoreImpCasts();
+  if (auto *DRE = dyn_cast(CEE))
+return DRE->getDecl();
+
+  if (auto *ME = dyn_cast(CEE))
+return ME->getMemberDecl();
 
   while (auto *NTTP = dyn_cast(CEE))
 CEE = NTTP->getReplacement()->IgnoreParenImpCasts();

>From 16077ed74794645452434c9ec761d642789e09ac Mon Sep 17 00:00:00 2001
From: Corentin Jabot 
Date: Thu, 22 May 2025 00:28:05 +0200
Subject: [PATCH 2/8] remove call to getCalleeDecl

---
 clang/include/clang/AST/Expr.h|  5 +
 clang/include/clang/AST/Stmt.h|  5 +++--
 clang/lib/AST/Expr.cpp| 21 ++---
 clang/lib/Sema/SemaOpenCL.cpp |  2 +-
 clang/lib/Sema/SemaOverload.cpp   |  2 ++
 clang/lib/Serialization/ASTReaderStmt.cpp |  2 ++
 clang/lib/Serialization/ASTWriterStmt.cpp |  2 ++
 7 files changed, 25 insertions(+), 14 deletions(-)

diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index e9c3c16c87598..a8bfae2e7efda 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -3028,6 +3028,9 @@ class CallExpr : public Expr {
 
   bool hasStoredFPFeatures() const { return CallExprBits.HasFPFeatures; }
 
+  bool usesMemberSyntax() const { return 
CallExprBits.ExplicitObjectMemFunUsingMemberSyntax; }
+  void setUsesMemberSyntax(bool V = true) { 
CallExprBits.ExplicitObjectMemFunUsingMemberSyntax = V; }
+
   bool isCoroElideSafe() const { return CallExprBits.IsCoroElideSafe; }
   void setCoroElideSafe(bool V = true) { CallExprBits.IsCoroElideSafe = V; }
 
@@ -3220,6 +3223,8 @@ class CallExpr : public Expr {
   }
 };
 
+static_assert(sizeof(CallExpr) == 24);
+
 /// MemberExpr - [C99 6.5.2.3] Structure and Union Members.  X->F and X.F.
 ///
 class MemberExpr final
diff --git a/clang/include/clang/AST/Stmt.h b/clang/include/clang/AST/Stmt.h
index 336eb6d3df7e1..b3ad285ca73fd 100644
--- a/clang/include/clang/AST/Stmt.h
+++ b/clang/include/clang/AST/Stmt.h
@@ -563,10 +563,11 @@ class alignas(void *) Stmt {
 unsigned HasFPFeatures : 1;
 
 /// True if the call expression is a must-elide call to a coroutine.
+LLVM_PREFERRED_TYPE(bool)
 unsigned IsCoroElideSafe : 1;
 
-/// Padding used to align OffsetToTrailingObjects to a byte multiple.
-unsigned : 24 - 4 - NumExprBits;
+LLVM_PREFERRED_TYPE(bool)
+unsigned ExplicitObjectMemFunUsingMemberSyntax : 1;
 
 /// The offset in bytes from the this pointer to the start of the
 /// trailing objects belonging to CallExpr. Intentionally byte sized
diff --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index 1906e46042cad..e6ccd0904eefd 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -1484,6 +1484,8 @@ CallExpr::CallExpr(StmtClass SC, Expr *Fn, ArrayRef PreArgs,
 
   CallExprBits.HasFPFeatures = FPFeatures.requiresTrailingStorage();
   CallExprBits.IsCoroElideSafe = false;
+  CallExprBits.ExplicitObjectMemFunUsingMemberSyntax = false;
+
   if (hasStoredFPFeatures())
 setStoredFPFeatures(FPFeatures);
 }
@@ -1549,12 +1551,15 @@ Decl *Expr::getReferencedDeclOfCallee() {
   // (simple function or member function call)
   // then try more exotic possibilities
   Expr *CEE = IgnoreImpCasts();
+
   if (auto *DRE = dyn_cast(CEE))
 return DRE->getDecl();
 
   if (auto *ME = dyn_cast(CEE))
 return ME->getMemberDecl();
 
+  CEE = CEE->IgnoreParens();
+
   while (auto *NTTP = dyn_cast(CEE))
 CEE = NTTP->getReplacement()->IgnoreParenImpCasts();
 
@@ -1658,20 +1663,14 @@ SourceLocation CallExpr::getBeginLoc() const {
   // begin location should come from the first argument.
   // This does not apply to dependent calls, which are modelled with `o.f`
   // being the callee.
-  if (!isTypeDependent()) {
-if (const auto *Method =
-dyn_cast_if_present(getCalleeDecl());
-Method && Method->isExplicitObj

[clang] [Clang] Optimize some `getBeginLoc` implementations (PR #141058)

2025-05-22 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang-modules

@llvm/pr-subscribers-clang

Author: cor3ntin (cor3ntin)


Changes

The bulk of the changes are in `CallExpr`

We cache Begin/End source locs in the trailing objects, in the space left by 
making the offset to the trailing objects static.
We also set a flag to indicate that we are calling an explicit object member 
function, further reducing the cost of getBeginLoc.

Fixes #140876 

---

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


10 Files Affected:

- (modified) clang/include/clang/AST/Expr.h (+98-19) 
- (modified) clang/include/clang/AST/NestedNameSpecifier.h (+11-5) 
- (modified) clang/include/clang/AST/Stmt.h (+11-7) 
- (modified) clang/lib/AST/Expr.cpp (+48-76) 
- (modified) clang/lib/AST/ExprCXX.cpp (+28-14) 
- (modified) clang/lib/AST/NestedNameSpecifier.cpp (-12) 
- (modified) clang/lib/Sema/SemaOpenCL.cpp (+2-1) 
- (modified) clang/lib/Sema/SemaOverload.cpp (+2) 
- (modified) clang/lib/Serialization/ASTReaderStmt.cpp (+5) 
- (modified) clang/lib/Serialization/ASTWriterStmt.cpp (+2) 


``diff
diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index e9c3c16c87598..2a1b5a838d794 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -1344,7 +1344,13 @@ class DeclRefExpr final
 
   SourceLocation getLocation() const { return DeclRefExprBits.Loc; }
   void setLocation(SourceLocation L) { DeclRefExprBits.Loc = L; }
-  SourceLocation getBeginLoc() const LLVM_READONLY;
+
+  SourceLocation getBeginLoc() const {
+if (hasQualifier())
+  return getQualifierLoc().getBeginLoc();
+return DeclRefExprBits.Loc;
+  }
+
   SourceLocation getEndLoc() const LLVM_READONLY;
 
   /// Determine whether this declaration reference was preceded by a
@@ -2901,34 +2907,44 @@ class CallExpr : public Expr {
   //
   // * An optional of type FPOptionsOverride.
   //
-  // Note that we store the offset in bytes from the this pointer to the start
-  // of the trailing objects. It would be perfectly possible to compute it
-  // based on the dynamic kind of the CallExpr. However 1.) we have plenty of
-  // space in the bit-fields of Stmt. 2.) It was benchmarked to be faster to
-  // compute this once and then load the offset from the bit-fields of Stmt,
-  // instead of re-computing the offset each time the trailing objects are
-  // accessed.
+  // CallExpr subclasses are asssumed to be 32 bytes or less, and CallExpr
+  // itself is 24 bytes. To avoid having to recompute or store the offset of 
the
+  // trailing objects, we put it at 32 bytes (such that it is suitable for all
+  // subclasses) We use the 8 bytes gap left for instances of CallExpr to store
+  // the begin and end source locations. Caching the begin source location in
+  // particular as a significant impact on perf as getBeginLoc is assumed to be
+  // cheap.
+  // The layourt is as follow:
+  // CallExpr | Begin | End | Trailing Objects
+  // CXXMemberCallExpr | Trailing Objects
+  // A bit in CallExprBitfields indicates if source locations are presents.
 
+protected:
+  static constexpr unsigned offsetToTrailingObjects = 32;
+  template 
+  static constexpr unsigned
+  sizeToAllocateForCallExprSubclass(unsigned SizeOfTrailingObjects) {
+static_assert(sizeof(T) <= CallExpr::offsetToTrailingObjects);
+return SizeOfTrailingObjects + CallExpr::offsetToTrailingObjects;
+  }
+
+private:
   /// Return a pointer to the start of the trailing array of "Stmt *".
   Stmt **getTrailingStmts() {
 return reinterpret_cast(reinterpret_cast(this) +
- CallExprBits.OffsetToTrailingObjects);
+ offsetToTrailingObjects);
   }
   Stmt *const *getTrailingStmts() const {
 return const_cast(this)->getTrailingStmts();
   }
 
-  /// Map a statement class to the appropriate offset in bytes from the
-  /// this pointer to the trailing objects.
-  static unsigned offsetToTrailingObjects(StmtClass SC);
-
   unsigned getSizeOfTrailingStmts() const {
 return (1 + getNumPreArgs() + getNumArgs()) * sizeof(Stmt *);
   }
 
   size_t getOffsetOfTrailingFPFeatures() const {
 assert(hasStoredFPFeatures());
-return CallExprBits.OffsetToTrailingObjects + getSizeOfTrailingStmts();
+return offsetToTrailingObjects + getSizeOfTrailingStmts();
   }
 
 public:
@@ -2975,14 +2991,14 @@ class CallExpr : public Expr {
   FPOptionsOverride *getTrailingFPFeatures() {
 assert(hasStoredFPFeatures());
 return reinterpret_cast(
-reinterpret_cast(this) + CallExprBits.OffsetToTrailingObjects +
+reinterpret_cast(this) + offsetToTrailingObjects +
 getSizeOfTrailingStmts());
   }
   const FPOptionsOverride *getTrailingFPFeatures() const {
 assert(hasStoredFPFeatures());
 return reinterpret_cast(
-reinterpret_cast(this) +
-CallExprBits.OffsetToTrailingObjects + getSizeOf

[clang] [XRay] Fix argument parsing with offloading (#140748) (PR #141043)

2025-05-22 Thread Sebastian Kreutzer via cfe-commits

sebastiankreutzer wrote:

Pinging potential reviewers: @jhuber6 @MaskRay 

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


[clang] clang_EvalResult_getAsCXString impl (PR #134551)

2025-05-22 Thread Aaron Ballman via cfe-commits

AaronBallman wrote:

> We could keep `CXString` as it was before, but `const void *data` could 
> actually point to a dynamically allocated struct that has roughly this 
> definition:
> 
> ```c
> struct Data  {
> size_t length;
> char data[1];
> };
> ```
> 
> This wouldn't change the current API, and it would still be only one 
> allocation. What do you think?

It means all such string accesses would require two indirections to get to the 
string data, but that may be acceptable overhead (we probably should measure 
though, given how much string processing happens in tooling). I also wonder if 
we want to be slightly less memory efficient and add a `version` field in case 
we need to make changes again in the future (the only revision I can think of 
right now has to do with encodings, but we always use a single charset 
internally (UTF-8) so I don't know that we'd ever start returning multiple 
different encodings within the same program such that we'd need to track it on 
the string).

CC @cor3ntin who thinks about strings more than most folks do, so he may have 
opinions or ideas

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


[clang] [Clang] Optimize some `getBeginLoc` implementations (PR #141058)

2025-05-22 Thread Aaron Ballman via cfe-commits

AaronBallman wrote:

> https://llvm-compile-time-tracker.com/compare.php?from=f4cebe5d73c24ab53917bd58aedc9db892a164ae&to=99d11a55c0222e8ed64aa35a068a3f08673baaba&stat=instructions%3Au

There is so much green!

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


[clang] [llvm] Revert "[lit][clang] Avoid realpath on Windows due to MAX_PATH limitations" (PR #139739)

2025-05-22 Thread Tristan Labelle via cfe-commits

tristanlabelle wrote:

Hi @michael-jabbour-sonarsource , thanks for the ping!

I agree with your views on how canonicalization should be defined and work in 
theory, but I am concerned about reconciliating it with the reality that:

1. Code pervasively access files through canonicalized paths rather than using 
canonicalized paths only for identity comparisons. The two usages are often 
conflated and can't be teased apart easily.
2. Hitting the Windows `MAX_PATH` limitation is a showstopper (broken builds or 
tests)

I don't think higher-level workarounds are possible (in APIs or in tests) 
because there is information loss once the lower levels have performed 
canonicalization, and lower levels can perform file accesses on paths that they 
have canonicalized.

I wish I had more alternatives to offer :/

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


[clang] [llvm] [AMDGPU][Clang] Allow amdgpu-waves-per-eu attribute to lower target occupancy range (PR #138284)

2025-05-22 Thread Lucas Ramirez via cfe-commits

https://github.com/lucas-rami updated 
https://github.com/llvm/llvm-project/pull/138284

>From 9906334cbabf160221dea11aa93e2cf7a154e6da Mon Sep 17 00:00:00 2001
From: Lucas Ramirez 
Date: Thu, 22 May 2025 13:26:57 +
Subject: [PATCH] Rebase on main (integrate changes from 1b34722)

---
 clang/lib/CodeGen/Targets/AMDGPU.cpp  | 27 -
 clang/lib/Sema/SemaAMDGPU.cpp |  5 --
 clang/test/SemaOpenCL/amdgpu-attrs.cl |  1 -
 llvm/lib/IR/Verifier.cpp  | 23 
 llvm/lib/Target/AMDGPU/AMDGPUAttributor.cpp   |  4 ++
 llvm/lib/Target/AMDGPU/AMDGPUSubtarget.cpp| 46 ---
 llvm/lib/Target/AMDGPU/AMDGPUSubtarget.h  |  4 +-
 .../AMDGPU/attr-amdgpu-waves-per-eu.ll| 12 
 ...-work-group-size-overrides-waves-per-eu.ll |  4 +-
 ...ine-scheduler-sink-trivial-remats-attr.mir | 12 ++--
 .../CodeGen/AMDGPU/propagate-waves-per-eu.ll  | 56 ---
 .../Verifier/AMDGPU/amdgpu-waves-per-eu.ll| 40 +
 12 files changed, 153 insertions(+), 81 deletions(-)
 create mode 100644 llvm/test/Verifier/AMDGPU/amdgpu-waves-per-eu.ll

diff --git a/clang/lib/CodeGen/Targets/AMDGPU.cpp 
b/clang/lib/CodeGen/Targets/AMDGPU.cpp
index c8921c434db47..8072d4f363feb 100644
--- a/clang/lib/CodeGen/Targets/AMDGPU.cpp
+++ b/clang/lib/CodeGen/Targets/AMDGPU.cpp
@@ -743,20 +743,21 @@ void CodeGenModule::handleAMDGPUWavesPerEUAttr(
 llvm::Function *F, const AMDGPUWavesPerEUAttr *Attr) {
   unsigned Min =
   Attr->getMin()->EvaluateKnownConstInt(getContext()).getExtValue();
-  unsigned Max =
-  Attr->getMax()
-  ? Attr->getMax()->EvaluateKnownConstInt(getContext()).getExtValue()
-  : 0;
 
-  if (Min != 0) {
-assert((Max == 0 || Min <= Max) && "Min must be less than or equal Max");
-
-std::string AttrVal = llvm::utostr(Min);
-if (Max != 0)
-  AttrVal = AttrVal + "," + llvm::utostr(Max);
-F->addFnAttr("amdgpu-waves-per-eu", AttrVal);
-  } else
-assert(Max == 0 && "Max must be zero");
+  if (Attr->getMax()) {
+unsigned Max =
+Attr->getMax()->EvaluateKnownConstInt(getContext()).getExtValue();
+assert(Min == 0 || (Min != 0 && Max != 0) &&
+   "Min must be non-zero when Max is non-zero");
+assert(Min <= Max && "Min must be less than or equal to Max");
+// Do not add the attribute if min,max=0,0.
+if (Min != 0) {
+  std::string AttrVal = llvm::utostr(Min) + "," + llvm::utostr(Max);
+  F->addFnAttr("amdgpu-waves-per-eu", AttrVal);
+}
+  } else if (Min != 0) {
+F->addFnAttr("amdgpu-waves-per-eu", llvm::utostr(Min));
+  }
 }
 
 std::unique_ptr
diff --git a/clang/lib/Sema/SemaAMDGPU.cpp b/clang/lib/Sema/SemaAMDGPU.cpp
index e6414a623b929..9ae3ec1289def 100644
--- a/clang/lib/Sema/SemaAMDGPU.cpp
+++ b/clang/lib/Sema/SemaAMDGPU.cpp
@@ -244,11 +244,6 @@ static bool checkAMDGPUWavesPerEUArguments(Sema &S, Expr 
*MinExpr,
   if (MaxExpr && !S.checkUInt32Argument(Attr, MaxExpr, Max, 1))
 return true;
 
-  if (Min == 0 && Max != 0) {
-S.Diag(Attr.getLocation(), diag::err_attribute_argument_invalid)
-<< &Attr << 0;
-return true;
-  }
   if (Max != 0 && Min > Max) {
 S.Diag(Attr.getLocation(), diag::err_attribute_argument_invalid)
 << &Attr << 1;
diff --git a/clang/test/SemaOpenCL/amdgpu-attrs.cl 
b/clang/test/SemaOpenCL/amdgpu-attrs.cl
index 89ba3f86803c5..b9b44dff4d4a9 100644
--- a/clang/test/SemaOpenCL/amdgpu-attrs.cl
+++ b/clang/test/SemaOpenCL/amdgpu-attrs.cl
@@ -46,7 +46,6 @@ __attribute__((amdgpu_num_sgpr(4294967296))) kernel void 
kernel_num_sgpr_L() {}
 __attribute__((amdgpu_num_vgpr(4294967296))) kernel void kernel_num_vgpr_L() 
{} // expected-error {{integer constant expression evaluates to value 
4294967296 that cannot be represented in a 32-bit unsigned integer type}}
 
 __attribute__((amdgpu_flat_work_group_size(0, 64))) kernel void 
kernel_flat_work_group_size_0_64() {} // expected-error 
{{'amdgpu_flat_work_group_size' attribute argument is invalid: max must be 0 
since min is 0}}
-__attribute__((amdgpu_waves_per_eu(0, 4))) kernel void 
kernel_waves_per_eu_0_4() {} // expected-error {{'amdgpu_waves_per_eu' 
attribute argument is invalid: max must be 0 since min is 0}}
 
 __attribute__((amdgpu_flat_work_group_size(64, 32))) kernel void 
kernel_flat_work_group_size_64_32() {} // expected-error 
{{'amdgpu_flat_work_group_size' attribute argument is invalid: min must not be 
greater than max}}
 __attribute__((amdgpu_waves_per_eu(4, 2))) kernel void 
kernel_waves_per_eu_4_2() {} // expected-error {{'amdgpu_waves_per_eu' 
attribute argument is invalid: min must not be greater than max}}
diff --git a/llvm/lib/IR/Verifier.cpp b/llvm/lib/IR/Verifier.cpp
index 73b4274a41ee6..402af44e38cbf 100644
--- a/llvm/lib/IR/Verifier.cpp
+++ b/llvm/lib/IR/Verifier.cpp
@@ -2473,6 +2473,29 @@ void Verifier::verifyFunctionAttrs(FunctionType *FT, 
AttributeList Attrs,
   CheckFailed("invalid value for 'denormal-fp-math

[clang] [Clang] Optimize some `getBeginLoc` implementations (PR #141058)

2025-05-22 Thread Erich Keane via cfe-commits


@@ -1510,41 +1519,41 @@ CallExpr *CallExpr::Create(const ASTContext &Ctx, Expr 
*Fn,
   unsigned NumArgs = std::max(Args.size(), MinNumArgs);
   unsigned SizeOfTrailingObjects = CallExpr::sizeOfTrailingObjects(
   /*NumPreArgs=*/0, NumArgs, FPFeatures.requiresTrailingStorage());
-  void *Mem =
-  Ctx.Allocate(sizeof(CallExpr) + SizeOfTrailingObjects, 
alignof(CallExpr));
-  return new (Mem) CallExpr(CallExprClass, Fn, /*PreArgs=*/{}, Args, Ty, VK,
-RParenLoc, FPFeatures, MinNumArgs, UsesADL);
+  void *Mem = Ctx.Allocate(
+  sizeToAllocateForCallExprSubclass(SizeOfTrailingObjects),
+  alignof(CallExpr));
+  CallExpr *E =
+  new (Mem) CallExpr(CallExprClass, Fn, /*PreArgs=*/{}, Args, Ty, VK,
+ RParenLoc, FPFeatures, MinNumArgs, UsesADL);
+  E->updateTrailingSourceLoc();
+  return E;
 }
 
 CallExpr *CallExpr::CreateEmpty(const ASTContext &Ctx, unsigned NumArgs,
 bool HasFPFeatures, EmptyShell Empty) {
   unsigned SizeOfTrailingObjects =
   CallExpr::sizeOfTrailingObjects(/*NumPreArgs=*/0, NumArgs, 
HasFPFeatures);
-  void *Mem =
-  Ctx.Allocate(sizeof(CallExpr) + SizeOfTrailingObjects, 
alignof(CallExpr));
+  void *Mem = Ctx.Allocate(
+  sizeToAllocateForCallExprSubclass(SizeOfTrailingObjects),
+  alignof(CallExpr));
   return new (Mem)
   CallExpr(CallExprClass, /*NumPreArgs=*/0, NumArgs, HasFPFeatures, Empty);
 }
 
-unsigned CallExpr::offsetToTrailingObjects(StmtClass SC) {
-  switch (SC) {
-  case CallExprClass:
-return sizeof(CallExpr);
-  case CXXOperatorCallExprClass:
-return sizeof(CXXOperatorCallExpr);
-  case CXXMemberCallExprClass:
-return sizeof(CXXMemberCallExpr);
-  case UserDefinedLiteralClass:
-return sizeof(UserDefinedLiteral);
-  case CUDAKernelCallExprClass:
-return sizeof(CUDAKernelCallExpr);
-  default:
-llvm_unreachable("unexpected class deriving from CallExpr!");
-  }
-}
-
 Decl *Expr::getReferencedDeclOfCallee() {
-  Expr *CEE = IgnoreParenImpCasts();
+
+  // Optimize for the common case first
+  // (simple function or member function call)
+  // then try more exotic possibilities
+  Expr *CEE = IgnoreImpCasts();
+
+  if (auto *DRE = dyn_cast(CEE))

erichkeane wrote:

I find myself wondering if this function would benefit SEVERELY from a 
`llvm::typeSwitch`.  

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


[clang] [Clang] Optimize some `getBeginLoc` implementations (PR #141058)

2025-05-22 Thread Erich Keane via cfe-commits


@@ -3187,9 +3215,48 @@ class CallExpr : public Expr {
   SourceLocation getRParenLoc() const { return RParenLoc; }
   void setRParenLoc(SourceLocation L) { RParenLoc = L; }
 
-  SourceLocation getBeginLoc() const LLVM_READONLY;
-  SourceLocation getEndLoc() const LLVM_READONLY;
+  SourceLocation getBeginLoc() const {
+if (CallExprBits.HasTrailingSourceLoc) {
+assert(CallExprBits.HasTrailingSourceLoc && "No trailing source loc");

erichkeane wrote:

What is the point of this assert?  Right after you just did the same thing in 
the 'if' above?

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


[clang] [Clang] Optimize some `getBeginLoc` implementations (PR #141058)

2025-05-22 Thread Erich Keane via cfe-commits


@@ -3028,6 +3043,19 @@ class CallExpr : public Expr {
 
   bool hasStoredFPFeatures() const { return CallExprBits.HasFPFeatures; }
 
+  bool usesMemberSyntax() const {
+return CallExprBits.ExplicitObjectMemFunUsingMemberSyntax;
+  }
+  void setUsesMemberSyntax(bool V = true) {
+CallExprBits.ExplicitObjectMemFunUsingMemberSyntax = V;
+// Because the source location may be different for explicit
+// member, we reset the cached values.
+if (CallExprBits.HasTrailingSourceLoc) {
+  CallExprBits.HasTrailingSourceLoc = false;
+  updateTrailingSourceLoc();

erichkeane wrote:

Since this is a 'cache' sorta thing... why do we update it right away?  Could 
we instead just wait until the first caller?

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


[clang] [Clang] Optimize some `getBeginLoc` implementations (PR #141058)

2025-05-22 Thread Erich Keane via cfe-commits


@@ -1510,41 +1519,41 @@ CallExpr *CallExpr::Create(const ASTContext &Ctx, Expr 
*Fn,
   unsigned NumArgs = std::max(Args.size(), MinNumArgs);
   unsigned SizeOfTrailingObjects = CallExpr::sizeOfTrailingObjects(
   /*NumPreArgs=*/0, NumArgs, FPFeatures.requiresTrailingStorage());
-  void *Mem =
-  Ctx.Allocate(sizeof(CallExpr) + SizeOfTrailingObjects, 
alignof(CallExpr));
-  return new (Mem) CallExpr(CallExprClass, Fn, /*PreArgs=*/{}, Args, Ty, VK,
-RParenLoc, FPFeatures, MinNumArgs, UsesADL);
+  void *Mem = Ctx.Allocate(
+  sizeToAllocateForCallExprSubclass(SizeOfTrailingObjects),
+  alignof(CallExpr));
+  CallExpr *E =
+  new (Mem) CallExpr(CallExprClass, Fn, /*PreArgs=*/{}, Args, Ty, VK,
+ RParenLoc, FPFeatures, MinNumArgs, UsesADL);
+  E->updateTrailingSourceLoc();

erichkeane wrote:

Same concern here.  We're doing an immediate update, but I wonder if there is 
value to delaying this call until we are in a 'getBeginLoc`.

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


[clang] clang_EvalResult_getAsCXString impl (PR #134551)

2025-05-22 Thread Damian Andrei via cfe-commits

xTachyon wrote:

> It means all such string accesses would require two indirections to get to 
> the string data

I don't think that's true. Getting the pointer would be `ptr+sizeof(size_t)`.

> I also wonder if we want to be slightly less memory efficient and add a 
> version field in case we need to make changes again in the future

Where would this go? The `Data` structure would be private API, not exposed, so 
it shouldn't matter when we change it.

I don't understand very well the last messages of you and 
[cor3ntin](https://github.com/cor3ntin), sorry.

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


[clang] [clang][CodeGen] Fix crash on non-natural type in CheckAtomicAlignment (PR #141053)

2025-05-22 Thread Pierre van Houtryve via cfe-commits

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


[clang] [clang][analyzer] Refine modeling of 'getcwd' in StdCLibraryFunctions checker (PR #141076)

2025-05-22 Thread Balázs Kéri via cfe-commits

https://github.com/balazske created 
https://github.com/llvm/llvm-project/pull/141076

Add extra branches for the case when the buffer argument is NULL.

From a82a775585ea473d6c29457b260848436071d0ff Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bal=C3=A1zs=20K=C3=A9ri?= 
Date: Thu, 22 May 2025 16:41:46 +0200
Subject: [PATCH] [clang][analyzer] Refine modeling of 'getcwd' in
 StdCLibraryFunctions checker

Add extra branches for the case when the buffer argument is NULL.
---
 .../Checkers/StdLibraryFunctionsChecker.cpp   | 14 ++
 clang/test/Analysis/errno-stdlibraryfunctions.c   | 15 ++-
 2 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
index 3c6c3123f5cdd..6dae817fe89b5 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -2651,16 +2651,22 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
 addToFunctionSummaryMap(
 "getcwd", Signature(ArgTypes{CharPtrTy, SizeTy}, RetType{CharPtrTy}),
 Summary(NoEvalCall)
-.Case({ArgumentCondition(1, WithinRange, Range(1, SizeMax)),
+.Case({NotNull(0),
+   ArgumentCondition(1, WithinRange, Range(1, SizeMax)),
ReturnValueCondition(BO_EQ, ArgNo(0))},
   ErrnoMustNotBeChecked, GenericSuccessMsg)
-.Case({ArgumentCondition(1, WithinRange, SingleValue(0)),
+.Case({NotNull(0),
+   ArgumentCondition(1, WithinRange, SingleValue(0)),
IsNull(Ret)},
   ErrnoNEZeroIrrelevant, "Assuming that argument 'size' is 0")
-.Case({ArgumentCondition(1, WithinRange, Range(1, SizeMax)),
+.Case({NotNull(0),
+   ArgumentCondition(1, WithinRange, Range(1, SizeMax)),
IsNull(Ret)},
   ErrnoNEZeroIrrelevant, GenericFailureMsg)
-.ArgConstraint(NotNull(ArgNo(0)))
+.Case({IsNull(0), NotNull(Ret)}, ErrnoMustNotBeChecked,
+  GenericSuccessMsg)
+.Case({IsNull(0), IsNull(Ret)}, ErrnoNEZeroIrrelevant,
+  GenericFailureMsg)
 .ArgConstraint(
 BufferSize(/*Buffer*/ ArgNo(0), /*BufSize*/ ArgNo(1)))
 .ArgConstraint(
diff --git a/clang/test/Analysis/errno-stdlibraryfunctions.c 
b/clang/test/Analysis/errno-stdlibraryfunctions.c
index 657aa37a42670..72d167f68a1f4 100644
--- a/clang/test/Analysis/errno-stdlibraryfunctions.c
+++ b/clang/test/Analysis/errno-stdlibraryfunctions.c
@@ -99,7 +99,9 @@ void errno_mkdtemp3(CHAR_PTR template) {
   }
 }
 
-void errno_getcwd(char *Buf, size_t Sz) {
+void errno_getcwd_buf_nonnull(char *Buf, size_t Sz) {
+  if (Buf == NULL)
+return;
   char *Path = getcwd(Buf, Sz);
   if (Sz == 0) {
 clang_analyzer_eval(errno != 0);   // expected-warning{{TRUE}}
@@ -114,6 +116,17 @@ void errno_getcwd(char *Buf, size_t Sz) {
   }
 }
 
+void errno_getcwd_buf_null() {
+  // POSIX does not mention this case but many implementations (Linux, 
FreeBSD) work this way.
+  char *Path = getcwd(NULL, 1);
+  if (Path == NULL) {
+clang_analyzer_eval(errno != 0);   // expected-warning{{TRUE}}
+if (errno) {}  // no warning
+  } else {
+if (errno) {}  // expected-warning{{An undefined value 
may be read from 'errno'}}
+  }
+}
+
 void errno_execv(char *Path, char * Argv[]) {
   int Ret = execv(Path, Argv);
   clang_analyzer_eval(Ret == -1);  // expected-warning{{TRUE}}

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


[clang] [clang][analyzer] Refine modeling of 'getcwd' in StdCLibraryFunctions checker (PR #141076)

2025-05-22 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Balázs Kéri (balazske)


Changes

Add extra branches for the case when the buffer argument is NULL.

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


2 Files Affected:

- (modified) clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp 
(+10-4) 
- (modified) clang/test/Analysis/errno-stdlibraryfunctions.c (+14-1) 


``diff
diff --git a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
index 3c6c3123f5cdd..6dae817fe89b5 100644
--- a/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/StdLibraryFunctionsChecker.cpp
@@ -2651,16 +2651,22 @@ void StdLibraryFunctionsChecker::initFunctionSummaries(
 addToFunctionSummaryMap(
 "getcwd", Signature(ArgTypes{CharPtrTy, SizeTy}, RetType{CharPtrTy}),
 Summary(NoEvalCall)
-.Case({ArgumentCondition(1, WithinRange, Range(1, SizeMax)),
+.Case({NotNull(0),
+   ArgumentCondition(1, WithinRange, Range(1, SizeMax)),
ReturnValueCondition(BO_EQ, ArgNo(0))},
   ErrnoMustNotBeChecked, GenericSuccessMsg)
-.Case({ArgumentCondition(1, WithinRange, SingleValue(0)),
+.Case({NotNull(0),
+   ArgumentCondition(1, WithinRange, SingleValue(0)),
IsNull(Ret)},
   ErrnoNEZeroIrrelevant, "Assuming that argument 'size' is 0")
-.Case({ArgumentCondition(1, WithinRange, Range(1, SizeMax)),
+.Case({NotNull(0),
+   ArgumentCondition(1, WithinRange, Range(1, SizeMax)),
IsNull(Ret)},
   ErrnoNEZeroIrrelevant, GenericFailureMsg)
-.ArgConstraint(NotNull(ArgNo(0)))
+.Case({IsNull(0), NotNull(Ret)}, ErrnoMustNotBeChecked,
+  GenericSuccessMsg)
+.Case({IsNull(0), IsNull(Ret)}, ErrnoNEZeroIrrelevant,
+  GenericFailureMsg)
 .ArgConstraint(
 BufferSize(/*Buffer*/ ArgNo(0), /*BufSize*/ ArgNo(1)))
 .ArgConstraint(
diff --git a/clang/test/Analysis/errno-stdlibraryfunctions.c 
b/clang/test/Analysis/errno-stdlibraryfunctions.c
index 657aa37a42670..72d167f68a1f4 100644
--- a/clang/test/Analysis/errno-stdlibraryfunctions.c
+++ b/clang/test/Analysis/errno-stdlibraryfunctions.c
@@ -99,7 +99,9 @@ void errno_mkdtemp3(CHAR_PTR template) {
   }
 }
 
-void errno_getcwd(char *Buf, size_t Sz) {
+void errno_getcwd_buf_nonnull(char *Buf, size_t Sz) {
+  if (Buf == NULL)
+return;
   char *Path = getcwd(Buf, Sz);
   if (Sz == 0) {
 clang_analyzer_eval(errno != 0);   // expected-warning{{TRUE}}
@@ -114,6 +116,17 @@ void errno_getcwd(char *Buf, size_t Sz) {
   }
 }
 
+void errno_getcwd_buf_null() {
+  // POSIX does not mention this case but many implementations (Linux, 
FreeBSD) work this way.
+  char *Path = getcwd(NULL, 1);
+  if (Path == NULL) {
+clang_analyzer_eval(errno != 0);   // expected-warning{{TRUE}}
+if (errno) {}  // no warning
+  } else {
+if (errno) {}  // expected-warning{{An undefined value 
may be read from 'errno'}}
+  }
+}
+
 void errno_execv(char *Path, char * Argv[]) {
   int Ret = execv(Path, Argv);
   clang_analyzer_eval(Ret == -1);  // expected-warning{{TRUE}}

``




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


[clang] [llvm] [mlir] [AMDGPU] Add a new amdgcn.load.to.lds intrinsic (PR #137425)

2025-05-22 Thread Jon Chesterfield via cfe-commits

JonChesterfield wrote:

I think we could do with an additional overload here.

Currently a bunch of code (notably CK but probably elsewhere) uses the v4i32 
version of the LDS intrinsics. I think this patch lets one use the addrspace(7) 
pointer of 128 bits alternative. So callers could transform the v4i32 into an 
addrspace(7) and then call this.

It's not very clear from the backend docs how this stuff is supposed to be 
wired up by the user. Possibly bitcast from the 4i32 into an addrspace(8) 
annotated i128, and then addrspacecast to 7 to provide an extra 32 bits of 
zero, and then onward to this builtin? Whatever the proper sequence might be, 
adding an overload which takes a v4i32 and does the conversion is likely to 
improve adoption for the new builtin.

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


[clang] [Clang] Move opt level in clang toolchain to clang::ConstructJob start (PR #141036)

2025-05-22 Thread Omar Ahmed via cfe-commits

https://github.com/omarahmed updated 
https://github.com/llvm/llvm-project/pull/141036

>From 0eb754713a8c2994144417f9d5ce12cbfefe19d0 Mon Sep 17 00:00:00 2001
From: omarahmed 
Date: Thu, 22 May 2025 11:19:53 +0100
Subject: [PATCH] [Clang] Move opt level in clang toolchain to beginning

---
 clang/lib/Driver/ToolChains/Clang.cpp | 30 +--
 clang/test/Driver/Ofast.c | 10 -
 clang/test/Driver/cl-options.c| 12 +--
 clang/test/Driver/clang-translation.c |  2 +-
 clang/test/Driver/offload-Xarch.c |  4 ++--
 5 files changed, 24 insertions(+), 34 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 355a48be9f493..30ecbf865d261 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -5202,6 +5202,16 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
 }
   }
 
+  // Optimization level for CodeGen.
+  if (const Arg *A = Args.getLastArg(options::OPT_O_Group)) {
+if (A->getOption().matches(options::OPT_O4)) {
+  CmdArgs.push_back("-O3");
+  D.Diag(diag::warn_O4_is_O3);
+} else {
+  A->render(Args, CmdArgs);
+}
+  }
+
   // Unconditionally claim the printf option now to avoid unused diagnostic.
   if (const Arg *PF = Args.getLastArg(options::OPT_mprintf_kind_EQ))
 PF->claim();
@@ -5573,16 +5583,6 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
   break;
 }
 
-// Optimization level for CodeGen.
-if (const Arg *A = Args.getLastArg(options::OPT_O_Group)) {
-  if (A->getOption().matches(options::OPT_O4)) {
-CmdArgs.push_back("-O3");
-D.Diag(diag::warn_O4_is_O3);
-  } else {
-A->render(Args, CmdArgs);
-  }
-}
-
 // Input/Output file.
 if (Output.getType() == types::TY_Dependencies) {
   // Handled with other dependency code.
@@ -6463,16 +6463,6 @@ void Clang::ConstructJob(Compilation &C, const JobAction 
&JA,
   // preprocessed inputs and configure concludes that -fPIC is not supported.
   Args.ClaimAllArgs(options::OPT_D);
 
-  // Manually translate -O4 to -O3; let clang reject others.
-  if (Arg *A = Args.getLastArg(options::OPT_O_Group)) {
-if (A->getOption().matches(options::OPT_O4)) {
-  CmdArgs.push_back("-O3");
-  D.Diag(diag::warn_O4_is_O3);
-} else {
-  A->render(Args, CmdArgs);
-}
-  }
-
   // Warn about ignored options to clang.
   for (const Arg *A :
Args.filtered(options::OPT_clang_ignored_gcc_optimization_f_Group)) {
diff --git a/clang/test/Driver/Ofast.c b/clang/test/Driver/Ofast.c
index b5189e951cc68..612478cc89558 100644
--- a/clang/test/Driver/Ofast.c
+++ b/clang/test/Driver/Ofast.c
@@ -12,36 +12,36 @@
 
 // CHECK-OFAST: use '-O3 -ffast-math' for the same behavior, or '-O3' to 
enable only conforming optimizations
 // CHECK-OFAST: -cc1
+// CHECK-OFAST: -Ofast
 // CHECK-OFAST-NOT: -relaxed-aliasing
 // CHECK-OFAST: -ffast-math
-// CHECK-OFAST: -Ofast
 // CHECK-OFAST: -vectorize-loops
 
 // Lack of warning about '-Ofast' deprecation is checked via -Werror
 // CHECK-OFAST-O2: -cc1
+// CHECK-OFAST-O2-NOT: -Ofast
 // CHECK-OFAST-O2-ALIASING-NOT: -relaxed-aliasing
 // CHECK-OFAST-O2-ALIASING-MSVC: -relaxed-aliasing
 // CHECK-OFAST-O2-NOT: -ffast-math
-// CHECK-OFAST-O2-NOT: -Ofast
 // CHECK-OFAST-O2: -vectorize-loops
 
 // CHECK-OFAST-NO-FAST-MATH: use '-O3 -ffast-math' for the same behavior, or 
'-O3' to enable only conforming optimizations
 // CHECK-OFAST-NO-FAST-MATH: -cc1
+// CHECK-OFAST-NO-FAST-MATH: -Ofast
 // CHECK-OFAST-NO-FAST-MATH-NOT: -relaxed-aliasing
 // CHECK-OFAST-NO-FAST-MATH-NOT: -ffast-math
-// CHECK-OFAST-NO-FAST-MATH: -Ofast
 // CHECK-OFAST-NO-FAST-MATH: -vectorize-loops
 
 // CHECK-OFAST-NO-STRICT-ALIASING: use '-O3 -ffast-math' for the same 
behavior, or '-O3' to enable only conforming optimizations
 // CHECK-OFAST-NO-STRICT-ALIASING: -cc1
+// CHECK-OFAST-NO-STRICT-ALIASING: -Ofast
 // CHECK-OFAST-NO-STRICT-ALIASING: -relaxed-aliasing
 // CHECK-OFAST-NO-STRICT-ALIASING: -ffast-math
-// CHECK-OFAST-NO-STRICT-ALIASING: -Ofast
 // CHECK-OFAST-NO-STRICT-ALIASING: -vectorize-loops
 
 // CHECK-OFAST-NO-VECTORIZE: use '-O3 -ffast-math' for the same behavior, or 
'-O3' to enable only conforming optimizations
 // CHECK-OFAST-NO-VECTORIZE: -cc1
+// CHECK-OFAST-NO-VECTORIZE: -Ofast
 // CHECK-OFAST-NO-VECTORIZE-NOT: -relaxed-aliasing
 // CHECK-OFAST-NO-VECTORIZE: -ffast-math
-// CHECK-OFAST-NO-VECTORIZE: -Ofast
 // CHECK-OFAST-NO-VECTORIZE-NOT: -vectorize-loops
diff --git a/clang/test/Driver/cl-options.c b/clang/test/Driver/cl-options.c
index c32b6a7f68c8c..0535285862b9f 100644
--- a/clang/test/Driver/cl-options.c
+++ b/clang/test/Driver/cl-options.c
@@ -185,30 +185,30 @@
 
 // RUN: %clang_cl /Os --target=i686-pc-windows-msvc -### -- %s 2>&1 | 
FileCheck -check-prefix=Os %s
 // RUN: %clang_cl /Os --target=x86_64-pc-windows-msvc -### -- %s 2>&1 | 
FileCheck -check-prefix=

[clang] [lld] [llvm] [mlir] [LLVM][Windows] Elide `PrettyStackTrace` output for usage errors (PR #140956)

2025-05-22 Thread via cfe-commits

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


[clang] [llvm] [Clang][LoongArch] Add inline asm support for the `q` constraint (PR #141037)

2025-05-22 Thread via cfe-commits

heiher wrote:

cc @xry111 @xen0n 

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


[clang] [clang] Move opt level in clang toolchain to clang::ConstructJob start (PR #141036)

2025-05-22 Thread Omar Ahmed via cfe-commits

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


[clang] [lld] [llvm] [mlir] [LLVM][Windows] Elide `PrettyStackTrace` output for usage errors (PR #140956)

2025-05-22 Thread via cfe-commits

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


[clang] clang_EvalResult_getAsCXString impl (PR #134551)

2025-05-22 Thread Damian Andrei via cfe-commits

xTachyon wrote:

That's pretty much what I was thinking of in terms of implementation.

> and we'd need the versioning information if we had Clang N tracking length + 
> contents and Clang N + 1 was tracking length + contents + encoding because 
> the newer Clang would be casting to a pointer of the wrong type if it was 
> given a CXString from the older Clang.
>
> But now that I think about it, this still runs into ABI issues like the 
> original solution. Newer Clang would produce a private_flags value that older 
> Clang couldn't handle gracefully.

Does libclang support having different versions of it at the same time loaded 
in a process? Otherwise I don't see how the outside world would be able to tell 
or care what `data` and `private_flags` mean.

In my suggestion, `StringWithLength` would only have a definition inside 
`CXString.cpp`; I don't want to make it part of the public API. I believe this 
would mean that this can be changed at any point for any reason.

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


[clang] Fixed issue #128882: don't warn if 1st argument to 'getcwd' is NULL (PR #135720)

2025-05-22 Thread Balázs Kéri via cfe-commits


@@ -105,9 +105,6 @@ void errno_getcwd(char *Buf, size_t Sz) {
 clang_analyzer_eval(errno != 0);   // expected-warning{{TRUE}}
 clang_analyzer_eval(Path == NULL); // expected-warning{{TRUE}}
 if (errno) {}  // no warning
-  } else if (Path == NULL) {
-clang_analyzer_eval(errno != 0);   // expected-warning{{TRUE}}
-if (errno) {}  // no warning

balazske wrote:

For me it was more easy to create a new PR #141076. The code change is almost 
the same just added the new cases for NULL `Buf` argument. (Improvements are 
still possible like add the fact that a `malloc`-like allocation happens in 
this case (with initialized content).)

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


[clang] [clang][analyzer] Refine modeling of 'getcwd' in StdCLibraryFunctions checker (PR #141076)

2025-05-22 Thread Balazs Benics via cfe-commits

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


[clang] Fixed issue #128882: don't warn if 1st argument to 'getcwd' is NULL (PR #135720)

2025-05-22 Thread Balazs Benics via cfe-commits

steakhal wrote:

Superseded by #141076

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


[clang] Fixed issue #128882: don't warn if 1st argument to 'getcwd' is NULL (PR #135720)

2025-05-22 Thread Balazs Benics via cfe-commits

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


[clang] Fixed issue #128882: don't warn if 1st argument to 'getcwd' is NULL (PR #135720)

2025-05-22 Thread Balazs Benics via cfe-commits


@@ -105,9 +105,6 @@ void errno_getcwd(char *Buf, size_t Sz) {
 clang_analyzer_eval(errno != 0);   // expected-warning{{TRUE}}
 clang_analyzer_eval(Path == NULL); // expected-warning{{TRUE}}
 if (errno) {}  // no warning
-  } else if (Path == NULL) {
-clang_analyzer_eval(errno != 0);   // expected-warning{{TRUE}}
-if (errno) {}  // no warning

steakhal wrote:

Thank you. I'm resolving this conversation.

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


[clang] [llvm] [mlir] [AMDGPU] Add a new amdgcn.load.to.lds intrinsic (PR #137425)

2025-05-22 Thread Krzysztof Drewniak via cfe-commits

krzysz00 wrote:

@JonChesterfield This builtin, semantically, cannot accommodate the v4i32 usage

When you have a v4i32, you need to also specify, as an additional argument, the 
`voffset` that gets used to index into that v4i32. This builtin doesn't have 
room for that, because it takes either a global pointer (which doesn't have a 
notion of the offset) or a buffer fat pointer (which has the offset stored in 
the low bits of the pointer and is, in some sense, a v5i32)

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


[clang] [Clang] Add missing macro undefs in AttributeSpellingList emitter (PR #141090)

2025-05-22 Thread Aaron Ballman via cfe-commits

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

LGTM!

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


  1   2   3   4   5   >