[clang] [clang] Alias iso9899:2024 to C23, update documentation (PR #138459)

2025-05-04 Thread Raul Tambre via cfe-commits

https://github.com/tambry created 
https://github.com/llvm/llvm-project/pull/138459

None

>From 4f4394ff468cb0b398df9e8dab7cf9d18b019c1a Mon Sep 17 00:00:00 2001
From: Raul Tambre 
Date: Sun, 4 May 2025 18:58:13 +0300
Subject: [PATCH] [clang] Alias iso9899:2024 to C23, update documentation

---
 clang/docs/CommandGuide/clang.rst   | 9 +
 clang/docs/ReleaseNotes.rst | 1 +
 clang/include/clang/Basic/LangStandards.def | 7 +++
 clang/test/Driver/unknown-std.c | 5 ++---
 4 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/clang/docs/CommandGuide/clang.rst 
b/clang/docs/CommandGuide/clang.rst
index 42aac7b25d93c..e3399d39bf00c 100644
--- a/clang/docs/CommandGuide/clang.rst
+++ b/clang/docs/CommandGuide/clang.rst
@@ -146,6 +146,15 @@ Language Selection and Mode Options
 
ISO C 2017 with GNU extensions
 
+  | ``c23``
+  | ``iso9899:2024``
+
+   ISO C 2023
+
+  | ``gnu23``
+
+   ISO C 2023 with GNU extensions
+
  The default C language standard is ``gnu17``, except on PS4, where it is
  ``gnu99``.
 
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 918ff952bb2c3..52ef686841c04 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -241,6 +241,7 @@ C2y Feature Support
 
 C23 Feature Support
 ^^^
+- Clang now accepts ``-std=iso9899:2024`` as an alias for C23.
 - Added ``__builtin_c23_va_start()`` for compatibility with GCC and to enable
   better diagnostic behavior for the ``va_start()`` macro in C23 and later.
   This also updates the definition of ``va_start()`` in  to use
diff --git a/clang/include/clang/Basic/LangStandards.def 
b/clang/include/clang/Basic/LangStandards.def
index 982a79873adb5..49cd9881829d4 100644
--- a/clang/include/clang/Basic/LangStandards.def
+++ b/clang/include/clang/Basic/LangStandards.def
@@ -89,15 +89,14 @@ LANGSTANDARD_ALIAS(gnu17, "gnu18")
 
 // C23 modes
 LANGSTANDARD(c23, "c23",
- C, "Working Draft for ISO C23",
+ C, "ISO C 2023",
  LineComment | C99 | C11 | C17 | C23 | Digraphs | HexFloat)
+LANGSTANDARD_ALIAS(c23, "iso9899:2024")
 LANGSTANDARD_ALIAS_DEPR(c23, "c2x")
 LANGSTANDARD(gnu23, "gnu23",
- C, "Working Draft for ISO C23 with GNU extensions",
+ C, "ISO C 2023 with GNU extensions",
  LineComment | C99 | C11 | C17 | C23 | Digraphs | GNUMode | 
HexFloat)
 LANGSTANDARD_ALIAS_DEPR(gnu23, "gnu2x")
-// FIXME: Add the alias for iso9899:202* once we know the year ISO publishes
-// the document (expected to be 2024).
 
 // C2y modes
 LANGSTANDARD(c2y, "c2y",
diff --git a/clang/test/Driver/unknown-std.c b/clang/test/Driver/unknown-std.c
index 332d587ddd4a1..539b04f69b9ae 100644
--- a/clang/test/Driver/unknown-std.c
+++ b/clang/test/Driver/unknown-std.c
@@ -15,11 +15,10 @@
 // CHECK-NEXT: note: use 'gnu11' for 'ISO C 2011 with GNU extensions' standard
 // CHECK-NEXT: note: use 'c17', 'iso9899:2017', 'c18', or 'iso9899:2018' for 
'ISO C 2017' standard
 // CHECK-NEXT: note: use 'gnu17' or 'gnu18' for 'ISO C 2017 with GNU 
extensions' standard
-// CHECK-NEXT: note: use 'c23' for 'Working Draft for ISO C23' standard
-// CHECK-NEXT: note: use 'gnu23' for 'Working Draft for ISO C23 with GNU 
extensions' standard
+// CHECK-NEXT: note: use 'c23' or 'iso9899:2024' for 'ISO C 2023' standard
+// CHECK-NEXT: note: use 'gnu23' for 'ISO C 2023 with GNU extensions' standard
 // CHECK-NEXT: note: use 'c2y' for 'Working Draft for ISO C2y' standard
 // CHECK-NEXT: note: use 'gnu2y' for 'Working Draft for ISO C2y with GNU 
extensions' standard
 
 // Make sure that no other output is present.
 // CHECK-NOT: {{^.+$}}
-

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


[clang] [clang] Alias iso9899:2024 to C23, update documentation (PR #138459)

2025-05-04 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Raul Tambre (tambry)


Changes



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


4 Files Affected:

- (modified) clang/docs/CommandGuide/clang.rst (+9) 
- (modified) clang/docs/ReleaseNotes.rst (+1) 
- (modified) clang/include/clang/Basic/LangStandards.def (+3-4) 
- (modified) clang/test/Driver/unknown-std.c (+2-3) 


``diff
diff --git a/clang/docs/CommandGuide/clang.rst 
b/clang/docs/CommandGuide/clang.rst
index 42aac7b25d93c..e3399d39bf00c 100644
--- a/clang/docs/CommandGuide/clang.rst
+++ b/clang/docs/CommandGuide/clang.rst
@@ -146,6 +146,15 @@ Language Selection and Mode Options
 
ISO C 2017 with GNU extensions
 
+  | ``c23``
+  | ``iso9899:2024``
+
+   ISO C 2023
+
+  | ``gnu23``
+
+   ISO C 2023 with GNU extensions
+
  The default C language standard is ``gnu17``, except on PS4, where it is
  ``gnu99``.
 
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 918ff952bb2c3..52ef686841c04 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -241,6 +241,7 @@ C2y Feature Support
 
 C23 Feature Support
 ^^^
+- Clang now accepts ``-std=iso9899:2024`` as an alias for C23.
 - Added ``__builtin_c23_va_start()`` for compatibility with GCC and to enable
   better diagnostic behavior for the ``va_start()`` macro in C23 and later.
   This also updates the definition of ``va_start()`` in  to use
diff --git a/clang/include/clang/Basic/LangStandards.def 
b/clang/include/clang/Basic/LangStandards.def
index 982a79873adb5..49cd9881829d4 100644
--- a/clang/include/clang/Basic/LangStandards.def
+++ b/clang/include/clang/Basic/LangStandards.def
@@ -89,15 +89,14 @@ LANGSTANDARD_ALIAS(gnu17, "gnu18")
 
 // C23 modes
 LANGSTANDARD(c23, "c23",
- C, "Working Draft for ISO C23",
+ C, "ISO C 2023",
  LineComment | C99 | C11 | C17 | C23 | Digraphs | HexFloat)
+LANGSTANDARD_ALIAS(c23, "iso9899:2024")
 LANGSTANDARD_ALIAS_DEPR(c23, "c2x")
 LANGSTANDARD(gnu23, "gnu23",
- C, "Working Draft for ISO C23 with GNU extensions",
+ C, "ISO C 2023 with GNU extensions",
  LineComment | C99 | C11 | C17 | C23 | Digraphs | GNUMode | 
HexFloat)
 LANGSTANDARD_ALIAS_DEPR(gnu23, "gnu2x")
-// FIXME: Add the alias for iso9899:202* once we know the year ISO publishes
-// the document (expected to be 2024).
 
 // C2y modes
 LANGSTANDARD(c2y, "c2y",
diff --git a/clang/test/Driver/unknown-std.c b/clang/test/Driver/unknown-std.c
index 332d587ddd4a1..539b04f69b9ae 100644
--- a/clang/test/Driver/unknown-std.c
+++ b/clang/test/Driver/unknown-std.c
@@ -15,11 +15,10 @@
 // CHECK-NEXT: note: use 'gnu11' for 'ISO C 2011 with GNU extensions' standard
 // CHECK-NEXT: note: use 'c17', 'iso9899:2017', 'c18', or 'iso9899:2018' for 
'ISO C 2017' standard
 // CHECK-NEXT: note: use 'gnu17' or 'gnu18' for 'ISO C 2017 with GNU 
extensions' standard
-// CHECK-NEXT: note: use 'c23' for 'Working Draft for ISO C23' standard
-// CHECK-NEXT: note: use 'gnu23' for 'Working Draft for ISO C23 with GNU 
extensions' standard
+// CHECK-NEXT: note: use 'c23' or 'iso9899:2024' for 'ISO C 2023' standard
+// CHECK-NEXT: note: use 'gnu23' for 'ISO C 2023 with GNU extensions' standard
 // CHECK-NEXT: note: use 'c2y' for 'Working Draft for ISO C2y' standard
 // CHECK-NEXT: note: use 'gnu2y' for 'Working Draft for ISO C2y with GNU 
extensions' standard
 
 // Make sure that no other output is present.
 // CHECK-NOT: {{^.+$}}
-

``




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


[clang] [clang] Add support for Debian 14 Forky and Debian 15 Duke (PR #138460)

2025-05-04 Thread Raul Tambre via cfe-commits

https://github.com/tambry created 
https://github.com/llvm/llvm-project/pull/138460

Futureproofs our single Debian-specific special case for roughly the next 6 
years.

See: https://lists.debian.org/debian-devel-announce/2025/01/msg4.html

>From 71ed6486e8036682bda9b0f6bd88277c7d927cb2 Mon Sep 17 00:00:00 2001
From: Raul Tambre 
Date: Sun, 4 May 2025 19:03:50 +0300
Subject: [PATCH] [clang] Add support for Debian 14 Forky and Debian 15 Duke

Futureproofs our single Debian-specific special case for roughly the next 6 
years.

See: https://lists.debian.org/debian-devel-announce/2025/01/msg4.html
---
 clang/include/clang/Driver/Distro.h | 4 +++-
 clang/lib/Driver/Distro.cpp | 6 ++
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/Driver/Distro.h 
b/clang/include/clang/Driver/Distro.h
index 9f27c2baaeb47..5c25592e68ade 100644
--- a/clang/include/clang/Driver/Distro.h
+++ b/clang/include/clang/Driver/Distro.h
@@ -39,6 +39,8 @@ class Distro {
 DebianBullseye,
 DebianBookworm,
 DebianTrixie,
+DebianForky,
+DebianDuke,
 Exherbo,
 RHEL5,
 RHEL6,
@@ -129,7 +131,7 @@ class Distro {
   bool IsOpenSUSE() const { return DistroVal == OpenSUSE; }
 
   bool IsDebian() const {
-return DistroVal >= DebianLenny && DistroVal <= DebianTrixie;
+return DistroVal >= DebianLenny && DistroVal <= DebianDuke;
   }
 
   bool IsUbuntu() const {
diff --git a/clang/lib/Driver/Distro.cpp b/clang/lib/Driver/Distro.cpp
index 82c627819d9fc..90e5a390be7eb 100644
--- a/clang/lib/Driver/Distro.cpp
+++ b/clang/lib/Driver/Distro.cpp
@@ -161,6 +161,10 @@ static Distro::DistroType 
DetectDistro(llvm::vfs::FileSystem &VFS) {
 return Distro::DebianBookworm;
   case 13:
 return Distro::DebianTrixie;
+  case 14:
+return Distro::DebianForky;
+  case 15:
+return Distro::DebianDuke;
   default:
 return Distro::UnknownDistro;
   }
@@ -174,6 +178,8 @@ static Distro::DistroType 
DetectDistro(llvm::vfs::FileSystem &VFS) {
 .Case("bullseye/sid", Distro::DebianBullseye)
 .Case("bookworm/sid", Distro::DebianBookworm)
 .Case("trixie/sid", Distro::DebianTrixie)
+.Case("forky/sid", Distro::DebianForky)
+.Case("duke/sid", Distro::DebianDuke)
 .Default(Distro::UnknownDistro);
   }
 

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


[clang] [clang] Add support for Debian 14 Forky and Debian 15 Duke (PR #138460)

2025-05-04 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Raul Tambre (tambry)


Changes

Futureproofs our single Debian-specific special case for roughly the next 6 
years.

See: https://lists.debian.org/debian-devel-announce/2025/01/msg4.html

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


2 Files Affected:

- (modified) clang/include/clang/Driver/Distro.h (+3-1) 
- (modified) clang/lib/Driver/Distro.cpp (+6) 


``diff
diff --git a/clang/include/clang/Driver/Distro.h 
b/clang/include/clang/Driver/Distro.h
index 9f27c2baaeb47..5c25592e68ade 100644
--- a/clang/include/clang/Driver/Distro.h
+++ b/clang/include/clang/Driver/Distro.h
@@ -39,6 +39,8 @@ class Distro {
 DebianBullseye,
 DebianBookworm,
 DebianTrixie,
+DebianForky,
+DebianDuke,
 Exherbo,
 RHEL5,
 RHEL6,
@@ -129,7 +131,7 @@ class Distro {
   bool IsOpenSUSE() const { return DistroVal == OpenSUSE; }
 
   bool IsDebian() const {
-return DistroVal >= DebianLenny && DistroVal <= DebianTrixie;
+return DistroVal >= DebianLenny && DistroVal <= DebianDuke;
   }
 
   bool IsUbuntu() const {
diff --git a/clang/lib/Driver/Distro.cpp b/clang/lib/Driver/Distro.cpp
index 82c627819d9fc..90e5a390be7eb 100644
--- a/clang/lib/Driver/Distro.cpp
+++ b/clang/lib/Driver/Distro.cpp
@@ -161,6 +161,10 @@ static Distro::DistroType 
DetectDistro(llvm::vfs::FileSystem &VFS) {
 return Distro::DebianBookworm;
   case 13:
 return Distro::DebianTrixie;
+  case 14:
+return Distro::DebianForky;
+  case 15:
+return Distro::DebianDuke;
   default:
 return Distro::UnknownDistro;
   }
@@ -174,6 +178,8 @@ static Distro::DistroType 
DetectDistro(llvm::vfs::FileSystem &VFS) {
 .Case("bullseye/sid", Distro::DebianBullseye)
 .Case("bookworm/sid", Distro::DebianBookworm)
 .Case("trixie/sid", Distro::DebianTrixie)
+.Case("forky/sid", Distro::DebianForky)
+.Case("duke/sid", Distro::DebianDuke)
 .Default(Distro::UnknownDistro);
   }
 

``




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


[clang] [clang][analyzer][NFC] Improve Clang Static Analyzer performance. (PR #138295)

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

steakhal wrote:

FYI, build bots suggests that this PR has build errors.

BTW, could you run this under perf stats to demonstrate the reduction of the 
cache-misses and page-faults? I'd suspect a measurable difference if these 
separate allocators really help.

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


[clang] [clang] Add support for Debian 14 Forky and Debian 15 Duke (PR #138460)

2025-05-04 Thread Raul Tambre via cfe-commits

tambry wrote:

I have commit access but I'll wait for CI so everything's per the book. 
:slightly_smiling_face: 

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


[clang] [clang][analyzer] Improve cache locality by using separate allocators (PR #138295)

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

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


[clang] [analyzer] Improve cache locality by using separate allocators (PR #138295)

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

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


[clang] Attribute support `[[clang::musttail]]` in `ExprConstant.cpp` (work in progress) (PR #138477)

2025-05-04 Thread Hana Dusíková via cfe-commits

https://github.com/hanickadot created 
https://github.com/llvm/llvm-project/pull/138477

This change makes `[[clang::musttail]]` work. Function calls marked with this 
attribute won't use system stack, but will loop after nearest function call. 
The attribute is already very strick, and checks all problematic cases 
(non-trivial destructors, referencing local variables).

This PR is work in progress.

From f084366a545f5e2c0ec54fa7cc4dd688950c13af Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Hana=20Dusi=CC=81kova=CC=81?= 
Date: Sun, 4 May 2025 23:27:09 +0200
Subject: [PATCH] [clang] Attribute support [[clang::musttail]] in
 ExprConstant.cpp allows guaranteed tail recursion.

---
 clang/lib/AST/ExprConstant.cpp | 260 +++--
 1 file changed, 219 insertions(+), 41 deletions(-)

diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index b79d8c197fe7d..9ef6b983d196a 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -735,6 +735,13 @@ namespace {
 ScopeKind Scope)
 : Value(Val, Scope), Base(Base), T(T) {}
 
+Cleanup(Cleanup &&Other) noexcept
+: Value{Other.Value}, Base{Other.Base}, T{Other.T} {
+  Other.Value = {};
+}
+
+Cleanup &operator=(Cleanup &&) = default;
+
 /// Determine whether this cleanup should be performed at the end of the
 /// given kind of scope.
 bool isDestroyedAtEndOf(ScopeKind K) const {
@@ -1006,6 +1013,24 @@ namespace {
   EM_IgnoreSideEffects,
 } EvalMode;
 
+/// Pointer to last tail recursion enabled return. Enforced with
+/// [[clang::musttail]]
+const ReturnStmt *TailRecursionReturnStmt = nullptr;
+
+struct DeferRecursionFunctionCall {
+  const CallExpr *E{nullptr};
+  const FunctionDecl *Definition{nullptr};
+  bool HasThis{false};
+  APValue ThisVal{}; // can't use LValue here :(
+  llvm::ArrayRef Args{};
+  CallRef Call{};
+  Stmt *Body{nullptr};
+  SmallVector CovariantAdjustmentPath{};
+  SmallVector ArgumentsStored{};
+};
+
+DeferRecursionFunctionCall DeferFunctionCall{};
+
 /// Are we checking whether the expression is a potential constant
 /// expression?
 bool checkingPotentialConstantExpression() const override  {
@@ -1124,6 +1149,21 @@ namespace {
   return Result;
 }
 
+void EnableTailRecursion(const ReturnStmt *ret) {
+  TailRecursionReturnStmt = ret;
+}
+
+void DisableTailRecursion() { TailRecursionReturnStmt = nullptr; }
+
+bool TailRecursionReady() const { return DeferFunctionCall.E != nullptr; }
+
+bool IsTailRecursion(const ReturnStmt *ret) {
+  if (TailRecursionReturnStmt != ret)
+return false;
+  TailRecursionReturnStmt = nullptr;
+  return true;
+}
+
 /// Get the allocated storage for the given parameter of the given call.
 APValue *getParamSlot(CallRef Call, const ParmVarDecl *PVD) {
   CallStackFrame *Frame = getCallFrameAndDepth(Call.CallIndex).first;
@@ -1439,6 +1479,12 @@ namespace {
   // instances of this class.
   Info.CurrentCall->popTempVersion();
 }
+
+friend void transferFromCallScope(ScopeRAII &,
+  llvm::SmallVectorImpl &);
+friend bool transferIntoCallScope(ScopeRAII &,
+  llvm::SmallVectorImpl &);
+
   private:
 static bool cleanup(EvalInfo &Info, bool RunDestructors,
 unsigned OldStackSize) {
@@ -1457,6 +1503,10 @@ namespace {
 }
   }
 
+  compact(Info, OldStackSize);
+  return Success;
+}
+static void compact(EvalInfo &Info, unsigned OldStackSize) {
   // Compact any retained cleanups.
   auto NewEnd = Info.CleanupStack.begin() + OldStackSize;
   if (Kind != ScopeKind::Block)
@@ -1465,12 +1515,47 @@ namespace {
   return C.isDestroyedAtEndOf(Kind);
 });
   Info.CleanupStack.erase(NewEnd, Info.CleanupStack.end());
-  return Success;
 }
   };
   typedef ScopeRAII BlockScopeRAII;
   typedef ScopeRAII FullExpressionRAII;
   typedef ScopeRAII CallScopeRAII;
+
+  static void transferFromCallScope(CallScopeRAII &Scope,
+llvm::SmallVectorImpl &Backup) {
+Backup.clear();
+
+auto CurrentVariables = MutableArrayRef(Scope.Info.CleanupStack)
+.slice(Scope.OldStackSize);
+
+// Transfer of cleanup informations of tail call outside of current scope.
+// These variables are going to be destroyed in current scope, which only
+// prepares the tail call, but is not doing it.
+Backup.clear();
+
+for (Cleanup &Lifetime : CurrentVariables) {
+  Backup.push_back(std::move(Lifetime));
+}
+
+// Remove lifetime management from this scope.
+Scope.compact(Scope.Info, Scope.OldStackSize);
+Scope.Info.CleanupStack.truncate(
+Scope.OldStackSize); // make sure this is ok
+assert(Scope

[clang] Attribute support `[[clang::musttail]]` in `ExprConstant.cpp` (work in progress) (PR #138477)

2025-05-04 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Hana Dusíková (hanickadot)


Changes

This change makes `[[clang::musttail]]` work. Function calls marked with this 
attribute won't use system stack, but will loop after nearest function call. 
The attribute is already very strick, and checks all problematic cases 
(non-trivial destructors, referencing local variables).

This PR is work in progress.

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


1 Files Affected:

- (modified) clang/lib/AST/ExprConstant.cpp (+219-41) 


``diff
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index b79d8c197fe7d..9ef6b983d196a 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -735,6 +735,13 @@ namespace {
 ScopeKind Scope)
 : Value(Val, Scope), Base(Base), T(T) {}
 
+Cleanup(Cleanup &&Other) noexcept
+: Value{Other.Value}, Base{Other.Base}, T{Other.T} {
+  Other.Value = {};
+}
+
+Cleanup &operator=(Cleanup &&) = default;
+
 /// Determine whether this cleanup should be performed at the end of the
 /// given kind of scope.
 bool isDestroyedAtEndOf(ScopeKind K) const {
@@ -1006,6 +1013,24 @@ namespace {
   EM_IgnoreSideEffects,
 } EvalMode;
 
+/// Pointer to last tail recursion enabled return. Enforced with
+/// [[clang::musttail]]
+const ReturnStmt *TailRecursionReturnStmt = nullptr;
+
+struct DeferRecursionFunctionCall {
+  const CallExpr *E{nullptr};
+  const FunctionDecl *Definition{nullptr};
+  bool HasThis{false};
+  APValue ThisVal{}; // can't use LValue here :(
+  llvm::ArrayRef Args{};
+  CallRef Call{};
+  Stmt *Body{nullptr};
+  SmallVector CovariantAdjustmentPath{};
+  SmallVector ArgumentsStored{};
+};
+
+DeferRecursionFunctionCall DeferFunctionCall{};
+
 /// Are we checking whether the expression is a potential constant
 /// expression?
 bool checkingPotentialConstantExpression() const override  {
@@ -1124,6 +1149,21 @@ namespace {
   return Result;
 }
 
+void EnableTailRecursion(const ReturnStmt *ret) {
+  TailRecursionReturnStmt = ret;
+}
+
+void DisableTailRecursion() { TailRecursionReturnStmt = nullptr; }
+
+bool TailRecursionReady() const { return DeferFunctionCall.E != nullptr; }
+
+bool IsTailRecursion(const ReturnStmt *ret) {
+  if (TailRecursionReturnStmt != ret)
+return false;
+  TailRecursionReturnStmt = nullptr;
+  return true;
+}
+
 /// Get the allocated storage for the given parameter of the given call.
 APValue *getParamSlot(CallRef Call, const ParmVarDecl *PVD) {
   CallStackFrame *Frame = getCallFrameAndDepth(Call.CallIndex).first;
@@ -1439,6 +1479,12 @@ namespace {
   // instances of this class.
   Info.CurrentCall->popTempVersion();
 }
+
+friend void transferFromCallScope(ScopeRAII &,
+  llvm::SmallVectorImpl &);
+friend bool transferIntoCallScope(ScopeRAII &,
+  llvm::SmallVectorImpl &);
+
   private:
 static bool cleanup(EvalInfo &Info, bool RunDestructors,
 unsigned OldStackSize) {
@@ -1457,6 +1503,10 @@ namespace {
 }
   }
 
+  compact(Info, OldStackSize);
+  return Success;
+}
+static void compact(EvalInfo &Info, unsigned OldStackSize) {
   // Compact any retained cleanups.
   auto NewEnd = Info.CleanupStack.begin() + OldStackSize;
   if (Kind != ScopeKind::Block)
@@ -1465,12 +1515,47 @@ namespace {
   return C.isDestroyedAtEndOf(Kind);
 });
   Info.CleanupStack.erase(NewEnd, Info.CleanupStack.end());
-  return Success;
 }
   };
   typedef ScopeRAII BlockScopeRAII;
   typedef ScopeRAII FullExpressionRAII;
   typedef ScopeRAII CallScopeRAII;
+
+  static void transferFromCallScope(CallScopeRAII &Scope,
+llvm::SmallVectorImpl &Backup) {
+Backup.clear();
+
+auto CurrentVariables = MutableArrayRef(Scope.Info.CleanupStack)
+.slice(Scope.OldStackSize);
+
+// Transfer of cleanup informations of tail call outside of current scope.
+// These variables are going to be destroyed in current scope, which only
+// prepares the tail call, but is not doing it.
+Backup.clear();
+
+for (Cleanup &Lifetime : CurrentVariables) {
+  Backup.push_back(std::move(Lifetime));
+}
+
+// Remove lifetime management from this scope.
+Scope.compact(Scope.Info, Scope.OldStackSize);
+Scope.Info.CleanupStack.truncate(
+Scope.OldStackSize); // make sure this is ok
+assert(Scope.Info.CleanupStack.size() == Scope.OldStackSize);
+  }
+
+  static bool transferIntoCallScope(CallScopeRAII &Scope,
+llvm::SmallVectorImpl &Backup) {
+if (!Scope.cleanup(Scope.Info, true, Scope.Old

[clang] [clang] Remove unused local variables (NFC) (PR #138468)

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

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`openmp-clang-x86_64-linux-debian` running on `gribozavr4` while building 
`clang` at step 6 "test-openmp".

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


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

```
Step 6 (test-openmp) failure: test (failure)
 TEST 'libomp :: tasking/issue-94260-2.c' FAILED 

Exit Code: -11

Command Output (stdout):
--
# RUN: at line 1
/b/1/openmp-clang-x86_64-linux-debian/llvm.build/./bin/clang -fopenmp   -I 
/b/1/openmp-clang-x86_64-linux-debian/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 -I /b/1/openmp-clang-x86_64-linux-debian/llvm.src/openmp/runtime/test -L 
/b/1/openmp-clang-x86_64-linux-debian/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
  -fno-omit-frame-pointer -I 
/b/1/openmp-clang-x86_64-linux-debian/llvm.src/openmp/runtime/test/ompt 
/b/1/openmp-clang-x86_64-linux-debian/llvm.src/openmp/runtime/test/tasking/issue-94260-2.c
 -o 
/b/1/openmp-clang-x86_64-linux-debian/llvm.build/runtimes/runtimes-bins/openmp/runtime/test/tasking/Output/issue-94260-2.c.tmp
 -lm -latomic && 
/b/1/openmp-clang-x86_64-linux-debian/llvm.build/runtimes/runtimes-bins/openmp/runtime/test/tasking/Output/issue-94260-2.c.tmp
# executed command: 
/b/1/openmp-clang-x86_64-linux-debian/llvm.build/./bin/clang -fopenmp -I 
/b/1/openmp-clang-x86_64-linux-debian/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 -I /b/1/openmp-clang-x86_64-linux-debian/llvm.src/openmp/runtime/test -L 
/b/1/openmp-clang-x86_64-linux-debian/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 -fno-omit-frame-pointer -I 
/b/1/openmp-clang-x86_64-linux-debian/llvm.src/openmp/runtime/test/ompt 
/b/1/openmp-clang-x86_64-linux-debian/llvm.src/openmp/runtime/test/tasking/issue-94260-2.c
 -o 
/b/1/openmp-clang-x86_64-linux-debian/llvm.build/runtimes/runtimes-bins/openmp/runtime/test/tasking/Output/issue-94260-2.c.tmp
 -lm -latomic
# executed command: 
/b/1/openmp-clang-x86_64-linux-debian/llvm.build/runtimes/runtimes-bins/openmp/runtime/test/tasking/Output/issue-94260-2.c.tmp
# note: command had no output on stdout or stderr
# error: command failed with exit status: -11

--




```



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


[clang] Attribute support `[[clang::musttail]]` in `ExprConstant.cpp` (work in progress) (PR #138477)

2025-05-04 Thread Hana Dusíková via cfe-commits

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


[clang] Attribute support `[[clang::musttail]]` in `ExprConstant.cpp` (work in progress) (PR #138477)

2025-05-04 Thread Hana Dusíková via cfe-commits

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


[clang] Attribute support `[[clang::musttail]]` in `ExprConstant.cpp` (work in progress) (PR #138477)

2025-05-04 Thread Hana Dusíková via cfe-commits

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


[clang] [llvm] [sancov] Introduce optional callback for stack-depth tracking (PR #138323)

2025-05-04 Thread Marco Elver via cfe-commits

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

This is also missing flag and IR tests.

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


[clang] [llvm] [sancov] Introduce optional callback for stack-depth tracking (PR #138323)

2025-05-04 Thread Marco Elver via cfe-commits


@@ -1078,22 +1092,44 @@ void 
ModuleSanitizerCoverage::InjectCoverageAtBlock(Function &F, BasicBlock &BB,
 Store->setNoSanitizeMetadata();
   }
   if (Options.StackDepth && IsEntryBB && !IsLeafFunc) {
-// Check stack depth.  If it's the deepest so far, record it.
 Module *M = F.getParent();
-auto FrameAddrPtr = IRB.CreateIntrinsic(
-Intrinsic::frameaddress,
-IRB.getPtrTy(M->getDataLayout().getAllocaAddrSpace()),
-{Constant::getNullValue(Int32Ty)});
-auto FrameAddrInt = IRB.CreatePtrToInt(FrameAddrPtr, IntptrTy);
-auto LowestStack = IRB.CreateLoad(IntptrTy, SanCovLowestStack);
-auto IsStackLower = IRB.CreateICmpULT(FrameAddrInt, LowestStack);
-auto ThenTerm = SplitBlockAndInsertIfThen(
-IsStackLower, &*IP, false,
-MDBuilder(IRB.getContext()).createUnlikelyBranchWeights());
-IRBuilder<> ThenIRB(ThenTerm);
-auto Store = ThenIRB.CreateStore(FrameAddrInt, SanCovLowestStack);
-LowestStack->setNoSanitizeMetadata();
-Store->setNoSanitizeMetadata();
+if (Options.StackDepthCallbackMin) {
+  // In callback mode, only add call when stack depth reaches minimum.
+  const DataLayout &DL = M->getDataLayout();
+  uint32_t EstimatedStackSize = 0;
+
+  // Make an estimate on the stack usage.
+  for (auto &I : F.getEntryBlock()) {
+if (auto *AI = dyn_cast(&I)) {
+  if (AI->isStaticAlloca()) {
+uint32_t TypeSize = DL.getTypeAllocSize(AI->getAllocatedType());
+EstimatedStackSize += TypeSize;
+  } else {
+// Over-estimate dynamic sizes.
+EstimatedStackSize += 4096;

melver wrote:

This just seems too arbitrary. Can we do something more reliable? Because if 
this is used beyond the kernel (where we shouldn't even have all that many VLAs 
or dynamic allocas left - right?), it's anyone's guess if 4K is even a generous 
over estimation.

I see several options:
- Make this a cl::opt and not a hard-coded constant. The default should be much 
larger (8 MiB?), so that even we can't accurately calculate stack size we 
always get a callback.
- Just give up if we found a dynamic alloca, and always do the callback.

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


[clang] [llvm] [sancov] Introduce optional callback for stack-depth tracking (PR #138323)

2025-05-04 Thread Marco Elver via cfe-commits


@@ -34,6 +34,7 @@ class SanitizerArgs {
   std::vector CoverageIgnorelistFiles;
   std::vector BinaryMetadataIgnorelistFiles;
   int CoverageFeatures = 0;
+  int StackDepthCallbackMin = 0;

melver wrote:

`CoverageStackDepthCallbackMin`

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


[clang] [llvm] [sancov] Introduce optional callback for stack-depth tracking (PR #138323)

2025-05-04 Thread Marco Elver via cfe-commits

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


[clang] Attribute support `[[clang::musttail]]` in `ExprConstant.cpp` (work in progress) (PR #138477)

2025-05-04 Thread Hana Dusíková via cfe-commits

hanickadot wrote:

```c++
constexpr int deep_test(int remaining) {
if (remaining == 0) {
return 42;
}
MUST_TAIL return deep_test(remaining - 1);
}

constexpr int result = deep_test(200'000);
```

With debug build of clang:
```sh
clang++ -std=c++26 -c deep.cpp -fconstexpr-depth=1 
-DMUST_TAIL="[[clang::musttail]]"

real0m7.227s
user0m7.199s
sys 0m0.019s
```

```sh
clang++ -std=c++26 -c deep.cpp -fconstexpr-depth=20 -DMUST_TAIL=

Segmentation fault: 11
```


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


[clang] [clang-format] Add SpaceAfterOperatorKeyword option (PR #137610)

2025-05-04 Thread Filip Milosevic via cfe-commits

MightyFilipns wrote:

> Please also update the release notes.

It should be good now

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


[clang] [Clang] raise extension warning for unknown namespaced attributes (PR #120925)

2025-05-04 Thread Oleksandr T. via cfe-commits

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


[clang] [clang] Warn about deprecated volatile-qualified return types (PR #137899)

2025-05-04 Thread via cfe-commits

https://github.com/halbi2 updated 
https://github.com/llvm/llvm-project/pull/137899

>From 238d73776c85ed22386ac494f275261638cd40d3 Mon Sep 17 00:00:00 2001
From: halbi2 
Date: Mon, 28 Apr 2025 20:07:43 -0400
Subject: [PATCH] [clang] Warn about deprecated volatile-qualified return types

The old codepath in GetFullTypeForDeclarator was under "if (not a class type)"
so that it failed to warn for class types. Move the diagnostic outside of the
"if" so that it warns in the proper situations.

Fixes #133380
---
 clang/docs/ReleaseNotes.rst  |  3 +++
 clang/lib/Sema/SemaType.cpp  | 10 +-
 clang/test/CXX/expr/expr.const/p2-0x.cpp |  2 +-
 clang/test/SemaCXX/deprecated.cpp|  7 +++
 4 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 3105d8b481560..d71556c351e85 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -420,6 +420,9 @@ Improvements to Clang's diagnostics
   the ``-Wc99-designator`` diagnostic group, as they also are about the
   behavior of the C99 feature as it was introduced into C++20. Fixes #GH47037
 
+- ``-Wvolatile`` now warns about volatile-qualified class return types
+  as well as volatile-qualified scalar return types. Fixes #GH133380
+
 Improvements to Clang's time-trace
 --
 
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 6e7ee8b5506ff..31bdc97d014d6 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -5056,13 +5056,13 @@ static TypeSourceInfo 
*GetFullTypeForDeclarator(TypeProcessingState &state,
   S.Diag(DeclType.Loc, diag::err_func_returning_qualified_void) << T;
 } else
   diagnoseRedundantReturnTypeQualifiers(S, T, D, chunkIndex);
-
-// C++2a [dcl.fct]p12:
-//   A volatile-qualified return type is deprecated
-if (T.isVolatileQualified() && S.getLangOpts().CPlusPlus20)
-  S.Diag(DeclType.Loc, diag::warn_deprecated_volatile_return) << T;
   }
 
+  // C++2a [dcl.fct]p12:
+  //   A volatile-qualified return type is deprecated
+  if (T.isVolatileQualified() && S.getLangOpts().CPlusPlus20)
+S.Diag(DeclType.Loc, diag::warn_deprecated_volatile_return) << T;
+
   // Objective-C ARC ownership qualifiers are ignored on the function
   // return type (by type canonicalization). Complain if this attribute
   // was written here.
diff --git a/clang/test/CXX/expr/expr.const/p2-0x.cpp 
b/clang/test/CXX/expr/expr.const/p2-0x.cpp
index df5ce108aca82..c6c3381be5523 100644
--- a/clang/test/CXX/expr/expr.const/p2-0x.cpp
+++ b/clang/test/CXX/expr/expr.const/p2-0x.cpp
@@ -356,7 +356,7 @@ namespace LValueToRValue {
   // - a non-volatile glvalue of literal type that refers to a non-volatile
   //   temporary object whose lifetime has not ended, initialized with a
   //   constant expression;
-  constexpr volatile S f() { return S(); }
+  constexpr volatile S f() { return S(); } // cxx20-warning 
{{volatile-qualified return type 'volatile S' is deprecated}}
   static_assert(f().i, ""); // expected-error {{constant expression}} 
expected-note {{read of volatile-qualified type}}
   static_assert(((volatile const S&&)(S)0).i, ""); // expected-error 
{{constant expression}} expected-note {{read of volatile-qualified type}}
 }
diff --git a/clang/test/SemaCXX/deprecated.cpp 
b/clang/test/SemaCXX/deprecated.cpp
index a24b40d8e622a..061fa8b54dff1 100644
--- a/clang/test/SemaCXX/deprecated.cpp
+++ b/clang/test/SemaCXX/deprecated.cpp
@@ -231,6 +231,13 @@ namespace DeprecatedVolatile {
 a = c = a;
 b += a;
   }
+
+  volatile struct amber jurassic();
+// cxx20-warning@-1 {{volatile-qualified return type 'volatile struct 
amber' is deprecated}}
+  void trex(volatile short left_arm, volatile struct amber right_arm);
+// cxx20-warning@-1 {{volatile-qualified parameter type 'volatile short' 
is deprecated}}
+// cxx20-warning@-1 {{volatile-qualified parameter type 'volatile struct 
amber' is deprecated}}
+  void fly(volatile struct pterosaur* pteranodon);
 }
 
 namespace ArithConv {

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


[clang] [clang] Warn about deprecated volatile-qualified return types (PR #137899)

2025-05-04 Thread via cfe-commits

halbi2 wrote:

@shafik I have changed the commit message, can you please look again?

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


[clang] [llvm] [sancov] Introduce optional callback for stack-depth tracking (PR #138323)

2025-05-04 Thread Kees Cook via cfe-commits

https://github.com/kees updated https://github.com/llvm/llvm-project/pull/138323

>From 729d249d3848c2e417174ed935bfefde5c048dc7 Mon Sep 17 00:00:00 2001
From: Kees Cook 
Date: Fri, 2 May 2025 10:51:02 -0700
Subject: [PATCH] [sancov] Introduce optional callback for stack-depth tracking

Normally -fsanitize-coverage=stack-depth inserts inline arithmetic to
update thread_local __sancov_lowest_stack. To support stack depth
tracking in the Linux kernel, which does not implement traditional
thread_local storage, provide the option to call a function instead.

This matches the existing "stackleak" implementation that is supported
in Linux via a GCC plugin. To make this coverage more performant, a
minimum estimated stack depth can be chosen to enable the callback mode,
skipping instrumentation of functions with smaller stacks.

With -fsanitize-coverage-stack-depth-callback-min set greater than 0,
the __sanitize_cov_stack_depth() callback will be injected when the
estimated stack depth is greater than or equal to the given minimum.
---
 clang/include/clang/Basic/CodeGenOptions.def  |   1 +
 clang/include/clang/Driver/Options.td |   7 +
 clang/include/clang/Driver/SanitizerArgs.h|   1 +
 clang/lib/CodeGen/BackendUtil.cpp |   1 +
 clang/lib/Driver/SanitizerArgs.cpp|  15 ++
 clang/test/Driver/fsanitize-coverage.c|  13 +
 .../llvm/Transforms/Utils/Instrumentation.h   |   1 +
 .../Instrumentation/SanitizerCoverage.cpp |  74 +++--
 .../SanitizerCoverage/stack-depth-callback.ll | 254 ++
 9 files changed, 352 insertions(+), 15 deletions(-)
 create mode 100644 
llvm/test/Instrumentation/SanitizerCoverage/stack-depth-callback.ll

diff --git a/clang/include/clang/Basic/CodeGenOptions.def 
b/clang/include/clang/Basic/CodeGenOptions.def
index 927972015c3dc..452b1e325afb2 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -305,6 +305,7 @@ CODEGENOPT(SanitizeCoveragePCTable, 1, 0) ///< Create a PC 
Table.
 CODEGENOPT(SanitizeCoverageControlFlow, 1, 0) ///< Collect control flow
 CODEGENOPT(SanitizeCoverageNoPrune, 1, 0) ///< Disable coverage pruning.
 CODEGENOPT(SanitizeCoverageStackDepth, 1, 0) ///< Enable max stack depth 
tracing
+VALUE_CODEGENOPT(SanitizeCoverageStackDepthCallbackMin , 32, 0) ///< Enable 
stack depth tracing callbacks.
 CODEGENOPT(SanitizeCoverageTraceLoads, 1, 0) ///< Enable tracing of loads.
 CODEGENOPT(SanitizeCoverageTraceStores, 1, 0) ///< Enable tracing of stores.
 CODEGENOPT(SanitizeBinaryMetadataCovered, 1, 0) ///< Emit PCs for covered 
functions.
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 561b0498c549c..251d20d0b1984 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2361,6 +2361,13 @@ def fsanitize_coverage_ignorelist : Joined<["-"], 
"fsanitize-coverage-ignorelist
 HelpText<"Disable sanitizer coverage instrumentation for modules and 
functions "
  "that match the provided special case list, even the allowed 
ones">,
 
MarshallingInfoStringVector>;
+def fsanitize_coverage_stack_depth_callback_min_EQ
+: Joined<["-"], "fsanitize-coverage-stack-depth-callback-min=">,
+  Group,
+  MetaVarName<"">,
+  HelpText<"Use callback for max stack depth tracing with minimum stack "
+   "depth M">,
+  MarshallingInfoInt>;
 def fexperimental_sanitize_metadata_EQ : CommaJoined<["-"], 
"fexperimental-sanitize-metadata=">,
   Group,
   HelpText<"Specify the type of metadata to emit for binary analysis 
sanitizers">;
diff --git a/clang/include/clang/Driver/SanitizerArgs.h 
b/clang/include/clang/Driver/SanitizerArgs.h
index 528e3b400f3dc..1213cd8dcd3b6 100644
--- a/clang/include/clang/Driver/SanitizerArgs.h
+++ b/clang/include/clang/Driver/SanitizerArgs.h
@@ -34,6 +34,7 @@ class SanitizerArgs {
   std::vector CoverageIgnorelistFiles;
   std::vector BinaryMetadataIgnorelistFiles;
   int CoverageFeatures = 0;
+  int StackDepthCallbackMin = 0;
   int BinaryMetadataFeatures = 0;
   int OverflowPatternExclusions = 0;
   int MsanTrackOrigins = 0;
diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index c9ceb49ce5ceb..42c59377688b2 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -255,6 +255,7 @@ getSancovOptsFromCGOpts(const CodeGenOptions &CGOpts) {
   Opts.InlineBoolFlag = CGOpts.SanitizeCoverageInlineBoolFlag;
   Opts.PCTable = CGOpts.SanitizeCoveragePCTable;
   Opts.StackDepth = CGOpts.SanitizeCoverageStackDepth;
+  Opts.StackDepthCallbackMin = CGOpts.SanitizeCoverageStackDepthCallbackMin;
   Opts.TraceLoads = CGOpts.SanitizeCoverageTraceLoads;
   Opts.TraceStores = CGOpts.SanitizeCoverageTraceStores;
   Opts.CollectControlFlow = CGOpts.SanitizeCoverageControlFlow;
diff --git a/clang/lib/Driver/SanitizerArgs.cpp 
b/clang/lib/Driver/SanitizerArgs.cpp
index ff08bffdbde1f..da4ea

[clang] aafbdde - [clang-linker-wrapper] Remove unused local variables (NFC) (#138480)

2025-05-04 Thread via cfe-commits

Author: Kazu Hirata
Date: 2025-05-04T20:36:07-07:00
New Revision: aafbddee808b8c81e2401ddcb6803f582ccb6892

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

LOG: [clang-linker-wrapper] Remove unused local variables (NFC) (#138480)

Added: 


Modified: 
clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp

Removed: 




diff  --git a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp 
b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
index bdeaa2031d184..63f6e641d8c9e 100644
--- a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -418,9 +418,6 @@ fatbinary(ArrayRef> 
InputFiles,
   if (!OffloadBundlerPath)
 return OffloadBundlerPath.takeError();
 
-  llvm::Triple Triple(
-  Args.getLastArgValue(OPT_host_triple_EQ, sys::getDefaultTargetTriple()));
-
   // Create a new file to write the linked device image to.
   auto TempFileOrErr =
   createOutputFile(sys::path::filename(ExecutableName), "hipfb");
@@ -758,7 +755,6 @@ bundleCuda(ArrayRef Images, const ArgList 
&Args) {
 InputFiles.emplace_back(std::make_pair(Image.Image->getBufferIdentifier(),
Image.StringData.lookup("arch")));
 
-  Triple TheTriple = Triple(Images.front().StringData.lookup("triple"));
   auto FileOrErr = nvptx::fatbinary(InputFiles, Args);
   if (!FileOrErr)
 return FileOrErr.takeError();
@@ -781,7 +777,6 @@ bundleHIP(ArrayRef Images, const ArgList 
&Args) {
 InputFiles.emplace_back(std::make_pair(Image.Image->getBufferIdentifier(),
Image.StringData.lookup("arch")));
 
-  Triple TheTriple = Triple(Images.front().StringData.lookup("triple"));
   auto FileOrErr = amdgcn::fatbinary(InputFiles, Args);
   if (!FileOrErr)
 return FileOrErr.takeError();



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


[clang] [clang-linker-wrapper] Remove unused local variables (NFC) (PR #138480)

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

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


[clang] [llvm] [sancov] Introduce optional callback for stack-depth tracking (PR #138323)

2025-05-04 Thread Kees Cook via cfe-commits

https://github.com/kees updated https://github.com/llvm/llvm-project/pull/138323

>From 027ff82e738f6bdf82f958a4774eb05d321b23ef Mon Sep 17 00:00:00 2001
From: Kees Cook 
Date: Fri, 2 May 2025 10:51:02 -0700
Subject: [PATCH] [sancov] Introduce optional callback for stack-depth tracking

Normally -fsanitize-coverage=stack-depth inserts inline arithmetic to
update thread_local __sancov_lowest_stack. To support stack depth
tracking in the Linux kernel, which does not implement traditional
thread_local storage, provide the option to call a function instead.

This matches the existing "stackleak" implementation that is supported
in Linux via a GCC plugin. To make this coverage more performant, a
minimum estimated stack depth can be chosen to enable the callback mode,
skipping instrumentation of functions with smaller stacks.

With -fsanitize-coverage-stack-depth-callback-min set greater than 0,
the __sanitize_cov_stack_depth() callback will be injected when the
estimated stack depth is greater than or equal to the given minimum.
---
 clang/include/clang/Basic/CodeGenOptions.def  |   1 +
 clang/include/clang/Driver/Options.td |   7 +
 clang/include/clang/Driver/SanitizerArgs.h|   1 +
 clang/lib/CodeGen/BackendUtil.cpp |   1 +
 clang/lib/Driver/SanitizerArgs.cpp|  16 ++
 clang/test/Driver/fsanitize-coverage.c|  13 +
 .../llvm/Transforms/Utils/Instrumentation.h   |   1 +
 .../Instrumentation/SanitizerCoverage.cpp |  74 +++--
 .../SanitizerCoverage/stack-depth-callback.ll | 254 ++
 9 files changed, 353 insertions(+), 15 deletions(-)
 create mode 100644 
llvm/test/Instrumentation/SanitizerCoverage/stack-depth-callback.ll

diff --git a/clang/include/clang/Basic/CodeGenOptions.def 
b/clang/include/clang/Basic/CodeGenOptions.def
index 927972015c3dc..452b1e325afb2 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -305,6 +305,7 @@ CODEGENOPT(SanitizeCoveragePCTable, 1, 0) ///< Create a PC 
Table.
 CODEGENOPT(SanitizeCoverageControlFlow, 1, 0) ///< Collect control flow
 CODEGENOPT(SanitizeCoverageNoPrune, 1, 0) ///< Disable coverage pruning.
 CODEGENOPT(SanitizeCoverageStackDepth, 1, 0) ///< Enable max stack depth 
tracing
+VALUE_CODEGENOPT(SanitizeCoverageStackDepthCallbackMin , 32, 0) ///< Enable 
stack depth tracing callbacks.
 CODEGENOPT(SanitizeCoverageTraceLoads, 1, 0) ///< Enable tracing of loads.
 CODEGENOPT(SanitizeCoverageTraceStores, 1, 0) ///< Enable tracing of stores.
 CODEGENOPT(SanitizeBinaryMetadataCovered, 1, 0) ///< Emit PCs for covered 
functions.
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 561b0498c549c..251d20d0b1984 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -2361,6 +2361,13 @@ def fsanitize_coverage_ignorelist : Joined<["-"], 
"fsanitize-coverage-ignorelist
 HelpText<"Disable sanitizer coverage instrumentation for modules and 
functions "
  "that match the provided special case list, even the allowed 
ones">,
 
MarshallingInfoStringVector>;
+def fsanitize_coverage_stack_depth_callback_min_EQ
+: Joined<["-"], "fsanitize-coverage-stack-depth-callback-min=">,
+  Group,
+  MetaVarName<"">,
+  HelpText<"Use callback for max stack depth tracing with minimum stack "
+   "depth M">,
+  MarshallingInfoInt>;
 def fexperimental_sanitize_metadata_EQ : CommaJoined<["-"], 
"fexperimental-sanitize-metadata=">,
   Group,
   HelpText<"Specify the type of metadata to emit for binary analysis 
sanitizers">;
diff --git a/clang/include/clang/Driver/SanitizerArgs.h 
b/clang/include/clang/Driver/SanitizerArgs.h
index 528e3b400f3dc..513339060f2b2 100644
--- a/clang/include/clang/Driver/SanitizerArgs.h
+++ b/clang/include/clang/Driver/SanitizerArgs.h
@@ -34,6 +34,7 @@ class SanitizerArgs {
   std::vector CoverageIgnorelistFiles;
   std::vector BinaryMetadataIgnorelistFiles;
   int CoverageFeatures = 0;
+  int CoverageStackDepthCallbackMin = 0;
   int BinaryMetadataFeatures = 0;
   int OverflowPatternExclusions = 0;
   int MsanTrackOrigins = 0;
diff --git a/clang/lib/CodeGen/BackendUtil.cpp 
b/clang/lib/CodeGen/BackendUtil.cpp
index c9ceb49ce5ceb..42c59377688b2 100644
--- a/clang/lib/CodeGen/BackendUtil.cpp
+++ b/clang/lib/CodeGen/BackendUtil.cpp
@@ -255,6 +255,7 @@ getSancovOptsFromCGOpts(const CodeGenOptions &CGOpts) {
   Opts.InlineBoolFlag = CGOpts.SanitizeCoverageInlineBoolFlag;
   Opts.PCTable = CGOpts.SanitizeCoveragePCTable;
   Opts.StackDepth = CGOpts.SanitizeCoverageStackDepth;
+  Opts.StackDepthCallbackMin = CGOpts.SanitizeCoverageStackDepthCallbackMin;
   Opts.TraceLoads = CGOpts.SanitizeCoverageTraceLoads;
   Opts.TraceStores = CGOpts.SanitizeCoverageTraceStores;
   Opts.CollectControlFlow = CGOpts.SanitizeCoverageControlFlow;
diff --git a/clang/lib/Driver/SanitizerArgs.cpp 
b/clang/lib/Driver/SanitizerArgs.cpp
index ff08bffdbde1

[clang] [llvm] [sancov] Introduce optional callback for stack-depth tracking (PR #138323)

2025-05-04 Thread Kees Cook via cfe-commits


@@ -34,6 +34,7 @@ class SanitizerArgs {
   std::vector CoverageIgnorelistFiles;
   std::vector BinaryMetadataIgnorelistFiles;
   int CoverageFeatures = 0;
+  int StackDepthCallbackMin = 0;

kees wrote:

Fixed.

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


[clang] [clang-linker-wrapper] Remove unused local variables (NFC) (PR #138480)

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

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `openmp-s390x-linux` 
running on `systemz-1` while building `clang` at step 6 "test-openmp".

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


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

```
Step 6 (test-openmp) failure: test (failure)
 TEST 'libomp :: tasking/issue-94260-2.c' FAILED 

Exit Code: -11

Command Output (stdout):
--
# RUN: at line 1
/home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/./bin/clang 
-fopenmp   -I 
/home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 -I 
/home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.src/openmp/runtime/test 
-L 
/home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
  -fno-omit-frame-pointer -mbackchain -I 
/home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.src/openmp/runtime/test/ompt
 
/home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.src/openmp/runtime/test/tasking/issue-94260-2.c
 -o 
/home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/runtimes/runtimes-bins/openmp/runtime/test/tasking/Output/issue-94260-2.c.tmp
 -lm -latomic && 
/home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/runtimes/runtimes-bins/openmp/runtime/test/tasking/Output/issue-94260-2.c.tmp
# executed command: 
/home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/./bin/clang 
-fopenmp -I 
/home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 -I 
/home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.src/openmp/runtime/test 
-L 
/home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/runtimes/runtimes-bins/openmp/runtime/src
 -fno-omit-frame-pointer -mbackchain -I 
/home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.src/openmp/runtime/test/ompt
 
/home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.src/openmp/runtime/test/tasking/issue-94260-2.c
 -o 
/home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/runtimes/runtimes-bins/openmp/runtime/test/tasking/Output/issue-94260-2.c.tmp
 -lm -latomic
# executed command: 
/home/uweigand/sandbox/buildbot/openmp-s390x-linux/llvm.build/runtimes/runtimes-bins/openmp/runtime/test/tasking/Output/issue-94260-2.c.tmp
# note: command had no output on stdout or stderr
# error: command failed with exit status: -11

--




```



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


[clang] [Clang][OpenCL][AMDGPU] OpenCL Kernel stubs should be assigned alwaysinline attribute (PR #137769)

2025-05-04 Thread Aniket Lal via cfe-commits

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

>From aa151fcda1cb73edc9564f6e2494699046254350 Mon Sep 17 00:00:00 2001
From: anikelal 
Date: Tue, 29 Apr 2025 13:59:48 +0530
Subject: [PATCH] add alwaysinline attribute to stubs

---
 clang/lib/CodeGen/CodeGenModule.cpp   | 16 +
 .../CodeGenOpenCL/amdgpu-enqueue-kernel.cl|  6 ++---
 .../test/CodeGenOpenCL/cl-uniform-wg-size.cl  |  4 
 .../CodeGenOpenCL/cl20-device-side-enqueue.cl | 24 +++
 clang/test/CodeGenOpenCL/convergent.cl|  9 +++
 .../enqueue-kernel-non-entry-block.cl | 11 ++---
 6 files changed, 35 insertions(+), 35 deletions(-)

diff --git a/clang/lib/CodeGen/CodeGenModule.cpp 
b/clang/lib/CodeGen/CodeGenModule.cpp
index e917f3c42da06..82982a0e8951c 100644
--- a/clang/lib/CodeGen/CodeGenModule.cpp
+++ b/clang/lib/CodeGen/CodeGenModule.cpp
@@ -6174,6 +6174,22 @@ void 
CodeGenModule::EmitGlobalFunctionDefinition(GlobalDecl GD,
   CodeGenFunction(*this).GenerateCode(GD, Fn, FI);
 
   setNonAliasAttributes(GD, Fn);
+
+  bool ShouldAddOptNone = !CodeGenOpts.DisableO0ImplyOptNone &&
+  (CodeGenOpts.OptimizationLevel == 0) &&
+  !D->hasAttr();
+
+  if (D->hasAttr()) {
+if (GD.getKernelReferenceKind() == KernelReferenceKind::Stub &&
+!D->hasAttr() &&
+!Fn->hasFnAttribute(llvm::Attribute::NoInline) &&
+!D->hasAttr() &&
+!Fn->hasFnAttribute(llvm::Attribute::OptimizeNone) &&
+!ShouldAddOptNone) {
+  Fn->addFnAttr(llvm::Attribute::AlwaysInline);
+}
+  }
+
   SetLLVMFunctionAttributesForDefinition(D, Fn);
 
   if (const ConstructorAttr *CA = D->getAttr())
diff --git a/clang/test/CodeGenOpenCL/amdgpu-enqueue-kernel.cl 
b/clang/test/CodeGenOpenCL/amdgpu-enqueue-kernel.cl
index 773daf53b2746..a0e11a1b5997e 100644
--- a/clang/test/CodeGenOpenCL/amdgpu-enqueue-kernel.cl
+++ b/clang/test/CodeGenOpenCL/amdgpu-enqueue-kernel.cl
@@ -492,7 +492,7 @@ kernel void test_target_features_kernel(global int *i) {
 // GFX900-NEXT:ret void
 //
 //
-// GFX900: Function Attrs: convergent norecurse nounwind
+// GFX900: Function Attrs: alwaysinline convergent norecurse nounwind
 // GFX900-LABEL: define dso_local void @__clang_ocl_kern_imp_test(
 // GFX900-SAME: ptr addrspace(1) noundef align 1 [[A:%.*]], i8 noundef signext 
[[B:%.*]], ptr addrspace(1) noundef align 8 [[C:%.*]], i64 noundef [[D:%.*]]) 
#[[ATTR3:[0-9]+]] !kernel_arg_addr_space [[META10]] !kernel_arg_access_qual 
[[META11]] !kernel_arg_type [[META12]] !kernel_arg_base_type [[META12]] 
!kernel_arg_type_qual [[META13]] {
 // GFX900-NEXT:  [[ENTRY:.*:]]
@@ -640,7 +640,7 @@ kernel void test_target_features_kernel(global int *i) {
 // GFX900-NEXT:ret void
 //
 //
-// GFX900: Function Attrs: convergent norecurse nounwind
+// GFX900: Function Attrs: alwaysinline convergent norecurse nounwind
 // GFX900-LABEL: define dso_local void 
@__clang_ocl_kern_imp_test_target_features_kernel(
 // GFX900-SAME: ptr addrspace(1) noundef align 4 [[I:%.*]]) #[[ATTR3]] 
!kernel_arg_addr_space [[META22]] !kernel_arg_access_qual [[META23]] 
!kernel_arg_type [[META24]] !kernel_arg_base_type [[META24]] 
!kernel_arg_type_qual [[META25]] {
 // GFX900-NEXT:  [[ENTRY:.*:]]
@@ -832,7 +832,7 @@ kernel void test_target_features_kernel(global int *i) {
 // GFX900: attributes #[[ATTR0:[0-9]+]] = { "objc_arc_inert" }
 // GFX900: attributes #[[ATTR1]] = { convergent norecurse nounwind 
"denormal-fp-math-f32"="preserve-sign,preserve-sign" "no-trapping-math"="true" 
"stack-protector-buffer-size"="8" "target-cpu"="gfx900" 
"target-features"="+16-bit-insts,+ci-insts,+dpp,+gfx8-insts,+gfx9-insts,+s-memrealtime,+s-memtime-inst,+wavefrontsize64,-sram-ecc"
 }
 // GFX900: attributes #[[ATTR2]] = { convergent norecurse nounwind 
"amdgpu-flat-work-group-size"="1,256" 
"denormal-fp-math-f32"="preserve-sign,preserve-sign" "no-trapping-math"="true" 
"stack-protector-buffer-size"="8" "target-cpu"="gfx900" 
"target-features"="+16-bit-insts,+ci-insts,+dpp,+gfx8-insts,+gfx9-insts,+s-memrealtime,+s-memtime-inst,+wavefrontsize64,-sram-ecc"
 "uniform-work-group-size"="false" }
-// GFX900: attributes #[[ATTR3]] = { convergent norecurse nounwind 
"amdgpu-flat-work-group-size"="1,256" 
"denormal-fp-math-f32"="preserve-sign,preserve-sign" "no-trapping-math"="true" 
"stack-protector-buffer-size"="8" "target-cpu"="gfx900" 
"target-features"="+16-bit-insts,+ci-insts,+dpp,+gfx8-insts,+gfx9-insts,+s-memrealtime,+s-memtime-inst,+wavefrontsize64,-sram-ecc"
 }
+// GFX900: attributes #[[ATTR3]] = { alwaysinline convergent norecurse 
nounwind "amdgpu-flat-work-group-size"="1,256" 
"denormal-fp-math-f32"="preserve-sign,preserve-sign" "no-trapping-math"="true" 
"stack-protector-buffer-size"="8" "target-cpu"="gfx900" 
"target-features"="+16-bit-insts,+ci-insts,+dpp,+gfx8-insts,+gfx9-insts,+s-memrealtime,+s-memtime-inst,+wavefrontsize64,-sram-ecc"
 }
 // GFX900: attributes #[[ATTR4:[0-

[clang] [llvm] [OpenMP] Remove 'libomptarget.devicertl.a' fatbinary and use static library (PR #126143)

2025-05-04 Thread Ye Luo via cfe-commits


@@ -142,99 +125,40 @@ function(compileDeviceRTLLibrary target_name 
target_triple)
 endif()
 set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES 
${outfile})
 
-list(APPEND bc_files ${outfile})
+list(APPEND obj_files ${CMAKE_CURRENT_BINARY_DIR}/${outfile})
   endforeach()
-
-  set(bclib_name "libomptarget-${target_name}.bc")
-
-  # Link to a bitcode library.
-  add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/linked_${bclib_name}
-  COMMAND ${LINK_TOOL}
--o ${CMAKE_CURRENT_BINARY_DIR}/linked_${bclib_name} ${bc_files}
-  DEPENDS ${bc_files}
-  COMMENT "Linking LLVM bitcode ${bclib_name}"
-  )
-
-  if(TARGET llvm-link)
-add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/linked_${bclib_name}
-  DEPENDS llvm-link
-  APPEND)
-  endif()
-
-  add_custom_command(OUTPUT 
${CMAKE_CURRENT_BINARY_DIR}/internalized_${bclib_name}
-  COMMAND ${OPT_TOOL} ${link_export_flag} 
${CMAKE_CURRENT_BINARY_DIR}/linked_${bclib_name}
-  -o ${CMAKE_CURRENT_BINARY_DIR}/internalized_${bclib_name}
-  DEPENDS ${source_directory}/exports 
${CMAKE_CURRENT_BINARY_DIR}/linked_${bclib_name}
-  COMMENT "Internalizing LLVM bitcode ${bclib_name}"
-  )
-  if(TARGET opt)
-add_custom_command(OUTPUT 
${CMAKE_CURRENT_BINARY_DIR}/internalized_${bclib_name}
-  DEPENDS opt
-  APPEND)
-  endif()
-
-  add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${bclib_name}
-  COMMAND ${OPT_TOOL} ${link_opt_flags} 
${CMAKE_CURRENT_BINARY_DIR}/internalized_${bclib_name}
-  -o ${CMAKE_CURRENT_BINARY_DIR}/${bclib_name}
-  DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/internalized_${bclib_name}
-  COMMENT "Optimizing LLVM bitcode ${bclib_name}"
-  )
-  if(TARGET opt)
-add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${bclib_name}
-  DEPENDS opt
-  APPEND)
-  endif()
-
-  set(bclib_target_name "omptarget-${target_name}-bc")
-  add_custom_target(${bclib_target_name} DEPENDS 
${CMAKE_CURRENT_BINARY_DIR}/${bclib_name})
-
-  # Copy library to destination.
-  add_custom_command(TARGET ${bclib_target_name} POST_BUILD
-COMMAND ${CMAKE_COMMAND} -E copy 
${CMAKE_CURRENT_BINARY_DIR}/${bclib_name}
-${LIBOMPTARGET_LIBRARY_DIR})
-  add_dependencies(omptarget.devicertl.${target_name} ${bclib_target_name})
-
-  set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES 
${bclib_name} ${LIBOMPTARGET_LIBRARY_DIR}/${bclib_name})
-
-  # Install bitcode library under the lib destination folder.
-  install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${bclib_name} DESTINATION 
"${OFFLOAD_INSTALL_LIBDIR}")
-
-  set(target_feature "")
-  if("${target_triple}" STREQUAL "nvptx64-nvidia-cuda")
-set(target_feature "feature=+ptx63")
-  endif()
-
-  # Package the bitcode in the bitcode and embed it in an ELF for the static 
library
-  add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/packaged_${bclib_name}
-  COMMAND ${PACKAGER_TOOL} -o 
${CMAKE_CURRENT_BINARY_DIR}/packaged_${bclib_name}
-
"--image=file=${CMAKE_CURRENT_BINARY_DIR}/${bclib_name},${target_feature},triple=${target_triple},arch=generic,kind=openmp"
-  DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/${bclib_name}
-  COMMENT "Packaging LLVM offloading binary ${bclib_name}.out"
-  )
-  if(TARGET clang-offload-packager)
-add_custom_command(OUTPUT 
${CMAKE_CURRENT_BINARY_DIR}/packaged_${bclib_name}
-  DEPENDS clang-offload-packager
-  APPEND)
-  endif()
-
-  set(output_name "${CMAKE_CURRENT_BINARY_DIR}/devicertl-${target_name}.o")
-  add_custom_command(OUTPUT ${output_name}
-COMMAND ${CLANG_TOOL} --std=c++17 -c -nostdlib
--Xclang 
-fembed-offload-object=${CMAKE_CURRENT_BINARY_DIR}/packaged_${bclib_name}
--o ${output_name}
-${source_directory}/Stub.cpp
-DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/packaged_${bclib_name} 
${source_directory}/Stub.cpp
-COMMENT "Embedding LLVM offloading binary in devicertl-${target_name}.o"
-VERBATIM
+  # Trick to combine these into a bitcode file via the linker's LTO pass. This
+  # is used to provide the legacy `libomptarget-.bc` files. Hack this
+  # through as an executable to get it to use the relocatable link.
+  add_executable(libomptarget-${target_name} ${obj_files})
+  set_target_properties(libomptarget-${target_name} PROPERTIES
+RUNTIME_OUTPUT_DIRECTORY ${LIBOMPTARGET_LLVM_LIBRARY_INTDIR}
+LINKER_LANGUAGE CXX
+BUILD_RPATH ""
+INSTALL_RPATH ""
+RUNTIME_OUTPUT_NAME libomptarget-${target_name}.bc)
+  target_compile_options(libomptarget-${target_name} PRIVATE 
"--target=${target_triple}")
+  target_link_options(libomptarget-${target_name} PRIVATE 
"--target=${target_triple}"
+  "-r" "-nostdlib" "-flto" "-Wl,--lto-emit-llvm")
+  install(TARGETS libomptarget-${target_name}
+  PERMISSIONS OWNER_WRITE OWNER_READ GROUP_READ WORLD_READ
+  DESTINATION ${OFFLOAD_INSTALL_LIBDIR})

[clang] [clang][ptrauth] Add support for querying the ptrauth schema of a type (PR #138482)

2025-05-04 Thread Oliver Hunt via cfe-commits

https://github.com/ojhunt created 
https://github.com/llvm/llvm-project/pull/138482

This adds a number of builtins to query the ptrauth schema of an arbitrary type 
in a way that can be fed into other ptrauth qualifiers.

>From e84310f8a57a3f9b75dfc7260137e984d7f55f87 Mon Sep 17 00:00:00 2001
From: Oliver Hunt 
Date: Sun, 4 May 2025 21:07:33 -0700
Subject: [PATCH] [clang][ptrauth] Add support for querying the ptrauth schema
 of a type

This adds a number of builtins to query the ptrauth schema of an arbitrary
type in a way that can be fed into other ptrauth qualifiers.
---
 clang/docs/PointerAuthentication.rst  |  18 +++
 clang/include/clang/AST/ASTContext.h  |  12 ++
 .../clang/Basic/DiagnosticSemaKinds.td|   2 +
 clang/include/clang/Basic/LangOptions.def |   1 +
 clang/include/clang/Basic/LangOptions.h   |  11 ++
 clang/include/clang/Basic/TokenKinds.def  |   5 +
 clang/include/clang/Parse/Parser.h|   2 +
 clang/lib/AST/ASTContext.cpp  |  60 ++
 clang/lib/AST/ExprConstant.cpp|  72 
 clang/lib/AST/ItaniumMangle.cpp   |   8 ++
 clang/lib/CodeGen/CGExprScalar.cpp|  10 ++
 clang/lib/Frontend/CompilerInvocation.cpp |   4 +-
 clang/lib/Parse/ParseExpr.cpp |  41 ++-
 clang/lib/Sema/SemaExpr.cpp   |  45 +++-
 clang/test/CodeGen/ptrauth-queries.c  |  44 
 clang/test/Sema/ptrauth-type-query.c  |  83 ++
 clang/test/SemaCXX/ptrauth-type-query.cpp | 105 ++
 17 files changed, 518 insertions(+), 5 deletions(-)
 create mode 100644 clang/test/CodeGen/ptrauth-queries.c
 create mode 100644 clang/test/Sema/ptrauth-type-query.c
 create mode 100644 clang/test/SemaCXX/ptrauth-type-query.cpp

diff --git a/clang/docs/PointerAuthentication.rst 
b/clang/docs/PointerAuthentication.rst
index 41818d43ac687..b7fcbf7a4 100644
--- a/clang/docs/PointerAuthentication.rst
+++ b/clang/docs/PointerAuthentication.rst
@@ -499,6 +499,24 @@ type.  Implementations are not required to make all bits 
of the result equally
 significant; in particular, some implementations are known to not leave
 meaningful data in the low bits.
 
+``__ptrauth type queries``
+^^
+
+There are a number of builtins that can be used to query the ptrauth qualifier
+parameters of a type, including those configured implicitly. These are:
+
+.. code-block:: c
+__builtin_ptrauth_has_authentication(type)
+__builtin_ptrauth_schema_key(type)
+__builtin_ptrauth_schema_is_address_discriminated(type)
+__builtin_ptrauth_schema_extra_discriminator(type)
+__builtin_ptrauth_schema_options(type)
+
+All these builtins are compile time constants. The schema queries are only 
valid
+on types that have some form of pointer authentication, including implicit
+authentication as is present of function pointers. Each schema query returns a
+value of the appropriate type for the relevant parameter to the __ptrauth
+qualifier.
 
 
 Alternative Implementations
diff --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index 50083b055199e..6e68ed238c01f 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -1344,6 +1344,11 @@ class ASTContext : public RefCountedBase {
   /// Return the "other" type-specific discriminator for the given type.
   uint16_t getPointerAuthTypeDiscriminator(QualType T);
 
+  /// Produces the canonical "options" string for the given 
PointerAuthQualifier
+  /// such that using it explicitly in a __ptrauth qualifier would result in as
+  /// identical configuration
+  std::string getPointerAuthOptionsString(const PointerAuthQualifier &PAQ);
+
   /// Apply Objective-C protocol qualifiers to the given type.
   /// \param allowOnPointerType specifies if we can apply protocol
   /// qualifiers on ObjCObjectPointerType. It can be set to true when
@@ -1682,6 +1687,13 @@ class ASTContext : public RefCountedBase {
 
   QualType adjustStringLiteralBaseType(QualType StrLTy) const;
 
+  /// Synthesizes a PointerAuthQualifier representing the actual authentication
+  /// policy for the given type. This may be either the schema specified
+  /// explicitly via the __ptrauth qualified in the source, or the implicit
+  /// schema associated with function pointers and similar.
+  std::optional
+  getExplicitOrImplicitPointerAuth(QualType T);
+
 private:
   /// Return a normal function type with a typed argument list.
   QualType getFunctionTypeInternal(QualType ResultTy, ArrayRef Args,
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index e5a7cdc14a737..e6111f1c91579 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -1039,6 +1039,8 @@ def err_ptrauth_address_discrimination_invalid : Error<
   "invalid address discrimination flag '%0'; '

[clang] [clang][ptrauth] Add support for querying the ptrauth schema of a type (PR #138482)

2025-05-04 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-codegen

Author: Oliver Hunt (ojhunt)


Changes

This adds a number of builtins to query the ptrauth schema of an arbitrary type 
in a way that can be fed into other ptrauth qualifiers.

---

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


17 Files Affected:

- (modified) clang/docs/PointerAuthentication.rst (+18) 
- (modified) clang/include/clang/AST/ASTContext.h (+12) 
- (modified) clang/include/clang/Basic/DiagnosticSemaKinds.td (+2) 
- (modified) clang/include/clang/Basic/LangOptions.def (+1) 
- (modified) clang/include/clang/Basic/LangOptions.h (+11) 
- (modified) clang/include/clang/Basic/TokenKinds.def (+5) 
- (modified) clang/include/clang/Parse/Parser.h (+2) 
- (modified) clang/lib/AST/ASTContext.cpp (+60) 
- (modified) clang/lib/AST/ExprConstant.cpp (+72) 
- (modified) clang/lib/AST/ItaniumMangle.cpp (+8) 
- (modified) clang/lib/CodeGen/CGExprScalar.cpp (+10) 
- (modified) clang/lib/Frontend/CompilerInvocation.cpp (+3-1) 
- (modified) clang/lib/Parse/ParseExpr.cpp (+39-2) 
- (modified) clang/lib/Sema/SemaExpr.cpp (+43-2) 
- (added) clang/test/CodeGen/ptrauth-queries.c (+44) 
- (added) clang/test/Sema/ptrauth-type-query.c (+83) 
- (added) clang/test/SemaCXX/ptrauth-type-query.cpp (+105) 


``diff
diff --git a/clang/docs/PointerAuthentication.rst 
b/clang/docs/PointerAuthentication.rst
index 41818d43ac687..b7fcbf7a4 100644
--- a/clang/docs/PointerAuthentication.rst
+++ b/clang/docs/PointerAuthentication.rst
@@ -499,6 +499,24 @@ type.  Implementations are not required to make all bits 
of the result equally
 significant; in particular, some implementations are known to not leave
 meaningful data in the low bits.
 
+``__ptrauth type queries``
+^^
+
+There are a number of builtins that can be used to query the ptrauth qualifier
+parameters of a type, including those configured implicitly. These are:
+
+.. code-block:: c
+__builtin_ptrauth_has_authentication(type)
+__builtin_ptrauth_schema_key(type)
+__builtin_ptrauth_schema_is_address_discriminated(type)
+__builtin_ptrauth_schema_extra_discriminator(type)
+__builtin_ptrauth_schema_options(type)
+
+All these builtins are compile time constants. The schema queries are only 
valid
+on types that have some form of pointer authentication, including implicit
+authentication as is present of function pointers. Each schema query returns a
+value of the appropriate type for the relevant parameter to the __ptrauth
+qualifier.
 
 
 Alternative Implementations
diff --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index 50083b055199e..6e68ed238c01f 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -1344,6 +1344,11 @@ class ASTContext : public RefCountedBase {
   /// Return the "other" type-specific discriminator for the given type.
   uint16_t getPointerAuthTypeDiscriminator(QualType T);
 
+  /// Produces the canonical "options" string for the given 
PointerAuthQualifier
+  /// such that using it explicitly in a __ptrauth qualifier would result in as
+  /// identical configuration
+  std::string getPointerAuthOptionsString(const PointerAuthQualifier &PAQ);
+
   /// Apply Objective-C protocol qualifiers to the given type.
   /// \param allowOnPointerType specifies if we can apply protocol
   /// qualifiers on ObjCObjectPointerType. It can be set to true when
@@ -1682,6 +1687,13 @@ class ASTContext : public RefCountedBase {
 
   QualType adjustStringLiteralBaseType(QualType StrLTy) const;
 
+  /// Synthesizes a PointerAuthQualifier representing the actual authentication
+  /// policy for the given type. This may be either the schema specified
+  /// explicitly via the __ptrauth qualified in the source, or the implicit
+  /// schema associated with function pointers and similar.
+  std::optional
+  getExplicitOrImplicitPointerAuth(QualType T);
+
 private:
   /// Return a normal function type with a typed argument list.
   QualType getFunctionTypeInternal(QualType ResultTy, ArrayRef Args,
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index e5a7cdc14a737..e6111f1c91579 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -1039,6 +1039,8 @@ def err_ptrauth_address_discrimination_invalid : Error<
   "invalid address discrimination flag '%0'; '__ptrauth' requires '0' or '1'">;
 def err_ptrauth_extra_discriminator_invalid : Error<
   "invalid extra discriminator flag '%0'; '__ptrauth' requires a value between 
'0' and '%1'">;
+def err_ptrauth_query_type_has_no_pointer_authentication
+: Error<"argument to %0 parameter is not an authenticated value">;
 
 /// main()
 // static main() is not an error in C, just in C++.
diff --git a/clang/include/clang/Basic/LangOptions.def 
b/clan

[clang] [clang][ptrauth] Add support for querying the ptrauth schema of a type (PR #138482)

2025-05-04 Thread Oliver Hunt via cfe-commits

ojhunt wrote:

Adding @cor3ntin and @AaronBallman in case they have a better idea for getting 
the function key to Sema than having it duplicated in langopts and codegen 
options

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


[clang] [clang][ptrauth] Add support for querying the ptrauth schema of a type (PR #138482)

2025-05-04 Thread Oliver Hunt via cfe-commits

ojhunt wrote:

Also the associated tests do not pass yet as they're blocked on 
https://github.com/llvm/llvm-project/pull/136828 and other ptrauth PRs

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


[clang] [llvm] [BasicAA] Do not decompose past casts with different index width (PR #119365)

2025-05-04 Thread via cfe-commits

liushuyu wrote:

Hi there,

It seems like after this pull request, the following C code will crash LLVM if 
LLVM assertion is enabled:

Godbolt link: https://godbolt.org/z/91bqnYsb4

```c
#include 
#include 

#if SIZE_MAX != UINT32_MAX
#error "This reproducer only works on 32-bit targets"
#endif

void repro(unsigned char** arg0) {
#pragma clang loop unroll(disable)
for (size_t i = 0; i != INT32_MAX / 2 + 1; i++) {
*arg0[i] = 0;
arg0[i] = 0;
}
}
```

Reduced LLVM IR that can trigger the issue: https://godbolt.org/z/aj364W849

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


[clang] [analyzer] Improve cache locality by using separate allocators (PR #138295)

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

steakhal wrote:

I had a look at the spreadsheet and the numbers for `linux-topro.c` looks 
really impressive.
However, in general, we need further investigation about why are we not getting 
faster e.g. in the `clang-MSP430ISelDAGToDAG.cpp` case. The direction seems 
right though.

(FYI it usually better to take the minimums of the different analysis attempts 
than the avg).

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


[clang] [clang][bytecode] Use bytecode interpreter in EvaluateCharRangeAsString (PR #138461)

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

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

>From 6cc6ff2f4c62e6d0a7b95338c461f8998a4a6bbc Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Sun, 4 May 2025 07:25:20 +0200
Subject: [PATCH] [clang][bytecode] Use bytecode interpreter in
 EvaluateCharRangeAsString

This was always using the ast walker.
---
 clang/lib/AST/ByteCode/Context.cpp | 79 ++
 clang/lib/AST/ByteCode/Context.h   |  9 +++
 clang/lib/AST/ByteCode/EvalEmitter.cpp | 22 ++
 clang/lib/AST/ByteCode/EvalEmitter.h   |  5 ++
 clang/lib/AST/ByteCode/EvaluationResult.h  |  6 +-
 clang/lib/AST/ByteCode/Pointer.h   |  7 ++
 clang/lib/AST/ExprConstant.cpp |  6 +-
 clang/test/SemaCXX/gnu-asm-constexpr.cpp   |  1 +
 clang/test/SemaCXX/static-assert-cxx26.cpp |  1 +
 9 files changed, 130 insertions(+), 6 deletions(-)

diff --git a/clang/lib/AST/ByteCode/Context.cpp 
b/clang/lib/AST/ByteCode/Context.cpp
index b35b30cc20d81..db9df7abf7a29 100644
--- a/clang/lib/AST/ByteCode/Context.cpp
+++ b/clang/lib/AST/ByteCode/Context.cpp
@@ -134,6 +134,85 @@ bool Context::evaluateAsInitializer(State &Parent, const 
VarDecl *VD,
   return true;
 }
 
+template 
+bool Context::evaluateStringRepr(State &Parent, const Expr *SizeExpr,
+ const Expr *PtrExpr, ResultT &Result) {
+  assert(Stk.empty());
+  Compiler C(*this, *P, Parent, Stk);
+
+  // Evaluate size value.
+  APValue SizeValue;
+  if (!evaluateAsRValue(Parent, SizeExpr, SizeValue))
+return false;
+
+  if (!SizeValue.isInt())
+return false;
+  uint64_t Size = SizeValue.getInt().getZExtValue();
+
+  auto PtrRes = C.interpretAsPointer(PtrExpr, [&](const Pointer &Ptr) {
+if (Size == 0) {
+  if constexpr (std::is_same_v)
+Result = APValue(APValue::UninitArray{}, 0, 0);
+  return true;
+}
+
+if (!Ptr.isLive() || !Ptr.getFieldDesc()->isPrimitiveArray())
+  return false;
+
+// Must be char.
+if (Ptr.getFieldDesc()->getElemSize() != 1 /*bytes*/)
+  return false;
+
+if (Size > Ptr.getNumElems()) {
+  Parent.FFDiag(SizeExpr, diag::note_constexpr_access_past_end) << AK_Read;
+  Size = Ptr.getNumElems();
+}
+
+if constexpr (std::is_same_v) {
+  QualType CharTy = PtrExpr->getType()->getPointeeType();
+  Result = APValue(APValue::UninitArray{}, Size, Size);
+  for (uint64_t I = 0; I != Size; ++I) {
+if (std::optional ElemVal =
+Ptr.atIndex(I).toRValue(*this, CharTy))
+  Result.getArrayInitializedElt(I) = *ElemVal;
+else
+  return false;
+  }
+} else {
+  assert((std::is_same_v));
+  if (Size < Result.max_size())
+Result.resize(Size);
+  Result.assign(reinterpret_cast(Ptr.getRawAddress()), Size);
+}
+
+return true;
+  });
+
+  if (PtrRes.isInvalid()) {
+C.cleanup();
+Stk.clear();
+return false;
+  }
+
+  return true;
+}
+
+bool Context::evaluateCharRange(State &Parent, const Expr *SizeExpr,
+const Expr *PtrExpr, APValue &Result) {
+  assert(SizeExpr);
+  assert(PtrExpr);
+
+  return evaluateStringRepr(Parent, SizeExpr, PtrExpr, Result);
+}
+
+bool Context::evaluateCharRange(State &Parent, const Expr *SizeExpr,
+const Expr *PtrExpr, std::string &Result) {
+  assert(SizeExpr);
+  assert(PtrExpr);
+
+  return evaluateStringRepr(Parent, SizeExpr, PtrExpr, Result);
+}
+
 const LangOptions &Context::getLangOpts() const { return Ctx.getLangOpts(); }
 
 std::optional Context::classify(QualType T) const {
diff --git a/clang/lib/AST/ByteCode/Context.h b/clang/lib/AST/ByteCode/Context.h
index 5a39f40ef3f11..33bc9fad883f8 100644
--- a/clang/lib/AST/ByteCode/Context.h
+++ b/clang/lib/AST/ByteCode/Context.h
@@ -59,6 +59,11 @@ class Context final {
   /// Evaluates a toplevel initializer.
   bool evaluateAsInitializer(State &Parent, const VarDecl *VD, APValue 
&Result);
 
+  bool evaluateCharRange(State &Parent, const Expr *SizeExpr,
+ const Expr *PtrExpr, APValue &Result);
+  bool evaluateCharRange(State &Parent, const Expr *SizeExpr,
+ const Expr *PtrExpr, std::string &Result);
+
   /// Returns the AST context.
   ASTContext &getASTContext() const { return Ctx; }
   /// Returns the language options.
@@ -122,6 +127,10 @@ class Context final {
   /// Runs a function.
   bool Run(State &Parent, const Function *Func);
 
+  template 
+  bool evaluateStringRepr(State &Parent, const Expr *SizeExpr,
+  const Expr *PtrExpr, ResultT &Result);
+
   /// Current compilation context.
   ASTContext &Ctx;
   /// Interpreter stack, shared across invocations.
diff --git a/clang/lib/AST/ByteCode/EvalEmitter.cpp 
b/clang/lib/AST/ByteCode/EvalEmitter.cpp
index 71d688498ffa5..37e8d3788a6fe 100644
--- a/clang/lib/AST/ByteCode/EvalEmitter.cpp
+++ b/clang/lib/AST/ByteCode/EvalEmitter.cpp
@@ -72,6 +

[clang] [clang] Remove unused local variables (NFC) (PR #138453)

2025-05-04 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang-modules

@llvm/pr-subscribers-clang-driver

Author: Kazu Hirata (kazutakahirata)


Changes



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


27 Files Affected:

- (modified) clang/lib/CodeGen/CGBuiltin.cpp (-1) 
- (modified) clang/lib/CodeGen/CGCUDANV.cpp (-1) 
- (modified) clang/lib/CodeGen/CGDeclCXX.cpp (-1) 
- (modified) clang/lib/CodeGen/CGExpr.cpp (-2) 
- (modified) clang/lib/CodeGen/CGExprAgg.cpp (-1) 
- (modified) clang/lib/CodeGen/CGHLSLRuntime.cpp (-1) 
- (modified) clang/lib/CodeGen/CGObjCGNU.cpp (-2) 
- (modified) clang/lib/CodeGen/CGStmtOpenMP.cpp (-1) 
- (modified) clang/lib/Driver/ToolChains/CommonArgs.cpp (-1) 
- (modified) clang/lib/Driver/ToolChains/HLSL.cpp (-1) 
- (modified) clang/lib/Driver/ToolChains/OHOS.cpp (-1) 
- (modified) clang/lib/Frontend/InitPreprocessor.cpp (-1) 
- (modified) clang/lib/Lex/PPDirectives.cpp (-1) 
- (modified) clang/lib/Parse/ParsePragma.cpp (-1) 
- (modified) clang/lib/Sema/SemaCodeComplete.cpp (-1) 
- (modified) clang/lib/Sema/SemaDeclAttr.cpp (-1) 
- (modified) clang/lib/Sema/SemaDeclObjC.cpp (-1) 
- (modified) clang/lib/Sema/SemaInit.cpp (-1) 
- (modified) clang/lib/Sema/SemaOpenMP.cpp (-5) 
- (modified) clang/lib/Serialization/ASTReader.cpp (-2) 
- (modified) clang/lib/Serialization/ASTWriter.cpp (-1) 
- (modified) clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp (-1) 
- (modified) clang/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp (-1) 
- (modified) clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp (-1) 
- (modified) clang/tools/libclang/CIndex.cpp (-1) 
- (modified) clang/unittests/StaticAnalyzer/CallDescriptionTest.cpp (-7) 
- (modified) clang/utils/TableGen/ClangAttrEmitter.cpp (-1) 


``diff
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 1e4e055e04afd..6235473d19a31 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -1949,7 +1949,6 @@ RValue CodeGenFunction::emitBuiltinOSLogFormat(const 
CallExpr &E) {
   analyze_os_log::OSLogBufferLayout Layout;
   analyze_os_log::computeOSLogBufferLayout(Ctx, &E, Layout);
   Address BufAddr = EmitPointerWithAlignment(E.getArg(0));
-  llvm::SmallVector RetainableOperands;
 
   // Ignore argument 1, the format string. It is not currently used.
   CallArgList Args;
diff --git a/clang/lib/CodeGen/CGCUDANV.cpp b/clang/lib/CodeGen/CGCUDANV.cpp
index 395263331d141..dd26be74e561b 100644
--- a/clang/lib/CodeGen/CGCUDANV.cpp
+++ b/clang/lib/CodeGen/CGCUDANV.cpp
@@ -1194,7 +1194,6 @@ void CGNVCUDARuntime::transformManagedVars() {
 // registered. The linker will provide a pointer to this section so we can
 // register the symbols with the linked device image.
 void CGNVCUDARuntime::createOffloadingEntries() {
-  SmallVector Out;
   llvm::object::OffloadKind Kind = CGM.getLangOpts().HIP
? llvm::object::OffloadKind::OFK_HIP
: llvm::object::OffloadKind::OFK_Cuda;
diff --git a/clang/lib/CodeGen/CGDeclCXX.cpp b/clang/lib/CodeGen/CGDeclCXX.cpp
index 8a214da6bf628..69d77f283db3b 100644
--- a/clang/lib/CodeGen/CGDeclCXX.cpp
+++ b/clang/lib/CodeGen/CGDeclCXX.cpp
@@ -748,7 +748,6 @@ void CodeGenModule::EmitCXXModuleInitFunc(Module *Primary) {
   // Add any initializers with specified priority; this uses the same  approach
   // as EmitCXXGlobalInitFunc().
   if (!PrioritizedCXXGlobalInits.empty()) {
-SmallVector LocalCXXGlobalInits;
 llvm::array_pod_sort(PrioritizedCXXGlobalInits.begin(),
  PrioritizedCXXGlobalInits.end());
 for (SmallVectorImpl::iterator
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index bba7d1e805f3f..2e01adc51fdf0 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -3955,8 +3955,6 @@ void CodeGenFunction::EmitCfiCheckFail() {
   {CFITCK_UnrelatedCast, SanitizerKind::SO_CFIUnrelatedCast},
   {CFITCK_ICall, SanitizerKind::SO_CFIICall}};
 
-  SmallVector, 5>
-  Checks;
   for (auto CheckKindOrdinalPair : CheckKinds) {
 int Kind = CheckKindOrdinalPair.first;
 SanitizerKind::SanitizerOrdinal Ordinal = CheckKindOrdinalPair.second;
diff --git a/clang/lib/CodeGen/CGExprAgg.cpp b/clang/lib/CodeGen/CGExprAgg.cpp
index 87b2a73fb0c03..7917cdb7e12b6 100644
--- a/clang/lib/CodeGen/CGExprAgg.cpp
+++ b/clang/lib/CodeGen/CGExprAgg.cpp
@@ -1814,7 +1814,6 @@ void AggExprEmitter::VisitCXXParenListOrInitListExpr(
 
   // We'll need to enter cleanup scopes in case any of the element
   // initializers throws an exception.
-  SmallVector cleanups;
   CodeGenFunction::CleanupDeactivationScope DeactivateCleanups(CGF);
 
   unsigned curInitIndex = 0;
diff --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp 
b/clang/lib/CodeGen/CGHLSLRuntime.cpp
index 6136417fcad60..f6608faaa7309 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.cpp
+++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp
@@ -446,7 +446,6 @@ s

[clang] [clang] Remove unused local variables (NFC) (PR #138453)

2025-05-04 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-codegen

Author: Kazu Hirata (kazutakahirata)


Changes



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


27 Files Affected:

- (modified) clang/lib/CodeGen/CGBuiltin.cpp (-1) 
- (modified) clang/lib/CodeGen/CGCUDANV.cpp (-1) 
- (modified) clang/lib/CodeGen/CGDeclCXX.cpp (-1) 
- (modified) clang/lib/CodeGen/CGExpr.cpp (-2) 
- (modified) clang/lib/CodeGen/CGExprAgg.cpp (-1) 
- (modified) clang/lib/CodeGen/CGHLSLRuntime.cpp (-1) 
- (modified) clang/lib/CodeGen/CGObjCGNU.cpp (-2) 
- (modified) clang/lib/CodeGen/CGStmtOpenMP.cpp (-1) 
- (modified) clang/lib/Driver/ToolChains/CommonArgs.cpp (-1) 
- (modified) clang/lib/Driver/ToolChains/HLSL.cpp (-1) 
- (modified) clang/lib/Driver/ToolChains/OHOS.cpp (-1) 
- (modified) clang/lib/Frontend/InitPreprocessor.cpp (-1) 
- (modified) clang/lib/Lex/PPDirectives.cpp (-1) 
- (modified) clang/lib/Parse/ParsePragma.cpp (-1) 
- (modified) clang/lib/Sema/SemaCodeComplete.cpp (-1) 
- (modified) clang/lib/Sema/SemaDeclAttr.cpp (-1) 
- (modified) clang/lib/Sema/SemaDeclObjC.cpp (-1) 
- (modified) clang/lib/Sema/SemaInit.cpp (-1) 
- (modified) clang/lib/Sema/SemaOpenMP.cpp (-5) 
- (modified) clang/lib/Serialization/ASTReader.cpp (-2) 
- (modified) clang/lib/Serialization/ASTWriter.cpp (-1) 
- (modified) clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp (-1) 
- (modified) clang/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp (-1) 
- (modified) clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp (-1) 
- (modified) clang/tools/libclang/CIndex.cpp (-1) 
- (modified) clang/unittests/StaticAnalyzer/CallDescriptionTest.cpp (-7) 
- (modified) clang/utils/TableGen/ClangAttrEmitter.cpp (-1) 


``diff
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 1e4e055e04afd..6235473d19a31 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -1949,7 +1949,6 @@ RValue CodeGenFunction::emitBuiltinOSLogFormat(const 
CallExpr &E) {
   analyze_os_log::OSLogBufferLayout Layout;
   analyze_os_log::computeOSLogBufferLayout(Ctx, &E, Layout);
   Address BufAddr = EmitPointerWithAlignment(E.getArg(0));
-  llvm::SmallVector RetainableOperands;
 
   // Ignore argument 1, the format string. It is not currently used.
   CallArgList Args;
diff --git a/clang/lib/CodeGen/CGCUDANV.cpp b/clang/lib/CodeGen/CGCUDANV.cpp
index 395263331d141..dd26be74e561b 100644
--- a/clang/lib/CodeGen/CGCUDANV.cpp
+++ b/clang/lib/CodeGen/CGCUDANV.cpp
@@ -1194,7 +1194,6 @@ void CGNVCUDARuntime::transformManagedVars() {
 // registered. The linker will provide a pointer to this section so we can
 // register the symbols with the linked device image.
 void CGNVCUDARuntime::createOffloadingEntries() {
-  SmallVector Out;
   llvm::object::OffloadKind Kind = CGM.getLangOpts().HIP
? llvm::object::OffloadKind::OFK_HIP
: llvm::object::OffloadKind::OFK_Cuda;
diff --git a/clang/lib/CodeGen/CGDeclCXX.cpp b/clang/lib/CodeGen/CGDeclCXX.cpp
index 8a214da6bf628..69d77f283db3b 100644
--- a/clang/lib/CodeGen/CGDeclCXX.cpp
+++ b/clang/lib/CodeGen/CGDeclCXX.cpp
@@ -748,7 +748,6 @@ void CodeGenModule::EmitCXXModuleInitFunc(Module *Primary) {
   // Add any initializers with specified priority; this uses the same  approach
   // as EmitCXXGlobalInitFunc().
   if (!PrioritizedCXXGlobalInits.empty()) {
-SmallVector LocalCXXGlobalInits;
 llvm::array_pod_sort(PrioritizedCXXGlobalInits.begin(),
  PrioritizedCXXGlobalInits.end());
 for (SmallVectorImpl::iterator
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index bba7d1e805f3f..2e01adc51fdf0 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -3955,8 +3955,6 @@ void CodeGenFunction::EmitCfiCheckFail() {
   {CFITCK_UnrelatedCast, SanitizerKind::SO_CFIUnrelatedCast},
   {CFITCK_ICall, SanitizerKind::SO_CFIICall}};
 
-  SmallVector, 5>
-  Checks;
   for (auto CheckKindOrdinalPair : CheckKinds) {
 int Kind = CheckKindOrdinalPair.first;
 SanitizerKind::SanitizerOrdinal Ordinal = CheckKindOrdinalPair.second;
diff --git a/clang/lib/CodeGen/CGExprAgg.cpp b/clang/lib/CodeGen/CGExprAgg.cpp
index 87b2a73fb0c03..7917cdb7e12b6 100644
--- a/clang/lib/CodeGen/CGExprAgg.cpp
+++ b/clang/lib/CodeGen/CGExprAgg.cpp
@@ -1814,7 +1814,6 @@ void AggExprEmitter::VisitCXXParenListOrInitListExpr(
 
   // We'll need to enter cleanup scopes in case any of the element
   // initializers throws an exception.
-  SmallVector cleanups;
   CodeGenFunction::CleanupDeactivationScope DeactivateCleanups(CGF);
 
   unsigned curInitIndex = 0;
diff --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp 
b/clang/lib/CodeGen/CGHLSLRuntime.cpp
index 6136417fcad60..f6608faaa7309 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.cpp
+++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp
@@ -446,7 +446,6 @@ static void gatherFunctions(SmallVe

[clang] [clang] Remove unused local variables (NFC) (PR #138453)

2025-05-04 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-hlsl

Author: Kazu Hirata (kazutakahirata)


Changes



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


27 Files Affected:

- (modified) clang/lib/CodeGen/CGBuiltin.cpp (-1) 
- (modified) clang/lib/CodeGen/CGCUDANV.cpp (-1) 
- (modified) clang/lib/CodeGen/CGDeclCXX.cpp (-1) 
- (modified) clang/lib/CodeGen/CGExpr.cpp (-2) 
- (modified) clang/lib/CodeGen/CGExprAgg.cpp (-1) 
- (modified) clang/lib/CodeGen/CGHLSLRuntime.cpp (-1) 
- (modified) clang/lib/CodeGen/CGObjCGNU.cpp (-2) 
- (modified) clang/lib/CodeGen/CGStmtOpenMP.cpp (-1) 
- (modified) clang/lib/Driver/ToolChains/CommonArgs.cpp (-1) 
- (modified) clang/lib/Driver/ToolChains/HLSL.cpp (-1) 
- (modified) clang/lib/Driver/ToolChains/OHOS.cpp (-1) 
- (modified) clang/lib/Frontend/InitPreprocessor.cpp (-1) 
- (modified) clang/lib/Lex/PPDirectives.cpp (-1) 
- (modified) clang/lib/Parse/ParsePragma.cpp (-1) 
- (modified) clang/lib/Sema/SemaCodeComplete.cpp (-1) 
- (modified) clang/lib/Sema/SemaDeclAttr.cpp (-1) 
- (modified) clang/lib/Sema/SemaDeclObjC.cpp (-1) 
- (modified) clang/lib/Sema/SemaInit.cpp (-1) 
- (modified) clang/lib/Sema/SemaOpenMP.cpp (-5) 
- (modified) clang/lib/Serialization/ASTReader.cpp (-2) 
- (modified) clang/lib/Serialization/ASTWriter.cpp (-1) 
- (modified) clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp (-1) 
- (modified) clang/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp (-1) 
- (modified) clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp (-1) 
- (modified) clang/tools/libclang/CIndex.cpp (-1) 
- (modified) clang/unittests/StaticAnalyzer/CallDescriptionTest.cpp (-7) 
- (modified) clang/utils/TableGen/ClangAttrEmitter.cpp (-1) 


``diff
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 1e4e055e04afd..6235473d19a31 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -1949,7 +1949,6 @@ RValue CodeGenFunction::emitBuiltinOSLogFormat(const 
CallExpr &E) {
   analyze_os_log::OSLogBufferLayout Layout;
   analyze_os_log::computeOSLogBufferLayout(Ctx, &E, Layout);
   Address BufAddr = EmitPointerWithAlignment(E.getArg(0));
-  llvm::SmallVector RetainableOperands;
 
   // Ignore argument 1, the format string. It is not currently used.
   CallArgList Args;
diff --git a/clang/lib/CodeGen/CGCUDANV.cpp b/clang/lib/CodeGen/CGCUDANV.cpp
index 395263331d141..dd26be74e561b 100644
--- a/clang/lib/CodeGen/CGCUDANV.cpp
+++ b/clang/lib/CodeGen/CGCUDANV.cpp
@@ -1194,7 +1194,6 @@ void CGNVCUDARuntime::transformManagedVars() {
 // registered. The linker will provide a pointer to this section so we can
 // register the symbols with the linked device image.
 void CGNVCUDARuntime::createOffloadingEntries() {
-  SmallVector Out;
   llvm::object::OffloadKind Kind = CGM.getLangOpts().HIP
? llvm::object::OffloadKind::OFK_HIP
: llvm::object::OffloadKind::OFK_Cuda;
diff --git a/clang/lib/CodeGen/CGDeclCXX.cpp b/clang/lib/CodeGen/CGDeclCXX.cpp
index 8a214da6bf628..69d77f283db3b 100644
--- a/clang/lib/CodeGen/CGDeclCXX.cpp
+++ b/clang/lib/CodeGen/CGDeclCXX.cpp
@@ -748,7 +748,6 @@ void CodeGenModule::EmitCXXModuleInitFunc(Module *Primary) {
   // Add any initializers with specified priority; this uses the same  approach
   // as EmitCXXGlobalInitFunc().
   if (!PrioritizedCXXGlobalInits.empty()) {
-SmallVector LocalCXXGlobalInits;
 llvm::array_pod_sort(PrioritizedCXXGlobalInits.begin(),
  PrioritizedCXXGlobalInits.end());
 for (SmallVectorImpl::iterator
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index bba7d1e805f3f..2e01adc51fdf0 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -3955,8 +3955,6 @@ void CodeGenFunction::EmitCfiCheckFail() {
   {CFITCK_UnrelatedCast, SanitizerKind::SO_CFIUnrelatedCast},
   {CFITCK_ICall, SanitizerKind::SO_CFIICall}};
 
-  SmallVector, 5>
-  Checks;
   for (auto CheckKindOrdinalPair : CheckKinds) {
 int Kind = CheckKindOrdinalPair.first;
 SanitizerKind::SanitizerOrdinal Ordinal = CheckKindOrdinalPair.second;
diff --git a/clang/lib/CodeGen/CGExprAgg.cpp b/clang/lib/CodeGen/CGExprAgg.cpp
index 87b2a73fb0c03..7917cdb7e12b6 100644
--- a/clang/lib/CodeGen/CGExprAgg.cpp
+++ b/clang/lib/CodeGen/CGExprAgg.cpp
@@ -1814,7 +1814,6 @@ void AggExprEmitter::VisitCXXParenListOrInitListExpr(
 
   // We'll need to enter cleanup scopes in case any of the element
   // initializers throws an exception.
-  SmallVector cleanups;
   CodeGenFunction::CleanupDeactivationScope DeactivateCleanups(CGF);
 
   unsigned curInitIndex = 0;
diff --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp 
b/clang/lib/CodeGen/CGHLSLRuntime.cpp
index 6136417fcad60..f6608faaa7309 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.cpp
+++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp
@@ -446,7 +446,6 @@ static void gatherFunctions(SmallVectorImpl 

[clang] [clang] Remove unused local variables (NFC) (PR #138453)

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

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

None

>From ae39ce905c81d94d2ca079bf1ebfd781a361bf57 Mon Sep 17 00:00:00 2001
From: Kazu Hirata 
Date: Sun, 4 May 2025 08:14:05 -0700
Subject: [PATCH] [clang] Remove unused local variables (NFC)

---
 clang/lib/CodeGen/CGBuiltin.cpp| 1 -
 clang/lib/CodeGen/CGCUDANV.cpp | 1 -
 clang/lib/CodeGen/CGDeclCXX.cpp| 1 -
 clang/lib/CodeGen/CGExpr.cpp   | 2 --
 clang/lib/CodeGen/CGExprAgg.cpp| 1 -
 clang/lib/CodeGen/CGHLSLRuntime.cpp| 1 -
 clang/lib/CodeGen/CGObjCGNU.cpp| 2 --
 clang/lib/CodeGen/CGStmtOpenMP.cpp | 1 -
 clang/lib/Driver/ToolChains/CommonArgs.cpp | 1 -
 clang/lib/Driver/ToolChains/HLSL.cpp   | 1 -
 clang/lib/Driver/ToolChains/OHOS.cpp   | 1 -
 clang/lib/Frontend/InitPreprocessor.cpp| 1 -
 clang/lib/Lex/PPDirectives.cpp | 1 -
 clang/lib/Parse/ParsePragma.cpp| 1 -
 clang/lib/Sema/SemaCodeComplete.cpp| 1 -
 clang/lib/Sema/SemaDeclAttr.cpp| 1 -
 clang/lib/Sema/SemaDeclObjC.cpp| 1 -
 clang/lib/Sema/SemaInit.cpp| 1 -
 clang/lib/Sema/SemaOpenMP.cpp  | 5 -
 clang/lib/Serialization/ASTReader.cpp  | 2 --
 clang/lib/Serialization/ASTWriter.cpp  | 1 -
 clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp  | 1 -
 clang/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp  | 1 -
 .../lib/Tooling/DependencyScanning/ModuleDepCollector.cpp  | 1 -
 clang/tools/libclang/CIndex.cpp| 1 -
 clang/unittests/StaticAnalyzer/CallDescriptionTest.cpp | 7 ---
 clang/utils/TableGen/ClangAttrEmitter.cpp  | 1 -
 27 files changed, 40 deletions(-)

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 1e4e055e04afd..6235473d19a31 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -1949,7 +1949,6 @@ RValue CodeGenFunction::emitBuiltinOSLogFormat(const 
CallExpr &E) {
   analyze_os_log::OSLogBufferLayout Layout;
   analyze_os_log::computeOSLogBufferLayout(Ctx, &E, Layout);
   Address BufAddr = EmitPointerWithAlignment(E.getArg(0));
-  llvm::SmallVector RetainableOperands;
 
   // Ignore argument 1, the format string. It is not currently used.
   CallArgList Args;
diff --git a/clang/lib/CodeGen/CGCUDANV.cpp b/clang/lib/CodeGen/CGCUDANV.cpp
index 395263331d141..dd26be74e561b 100644
--- a/clang/lib/CodeGen/CGCUDANV.cpp
+++ b/clang/lib/CodeGen/CGCUDANV.cpp
@@ -1194,7 +1194,6 @@ void CGNVCUDARuntime::transformManagedVars() {
 // registered. The linker will provide a pointer to this section so we can
 // register the symbols with the linked device image.
 void CGNVCUDARuntime::createOffloadingEntries() {
-  SmallVector Out;
   llvm::object::OffloadKind Kind = CGM.getLangOpts().HIP
? llvm::object::OffloadKind::OFK_HIP
: llvm::object::OffloadKind::OFK_Cuda;
diff --git a/clang/lib/CodeGen/CGDeclCXX.cpp b/clang/lib/CodeGen/CGDeclCXX.cpp
index 8a214da6bf628..69d77f283db3b 100644
--- a/clang/lib/CodeGen/CGDeclCXX.cpp
+++ b/clang/lib/CodeGen/CGDeclCXX.cpp
@@ -748,7 +748,6 @@ void CodeGenModule::EmitCXXModuleInitFunc(Module *Primary) {
   // Add any initializers with specified priority; this uses the same  approach
   // as EmitCXXGlobalInitFunc().
   if (!PrioritizedCXXGlobalInits.empty()) {
-SmallVector LocalCXXGlobalInits;
 llvm::array_pod_sort(PrioritizedCXXGlobalInits.begin(),
  PrioritizedCXXGlobalInits.end());
 for (SmallVectorImpl::iterator
diff --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index bba7d1e805f3f..2e01adc51fdf0 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -3955,8 +3955,6 @@ void CodeGenFunction::EmitCfiCheckFail() {
   {CFITCK_UnrelatedCast, SanitizerKind::SO_CFIUnrelatedCast},
   {CFITCK_ICall, SanitizerKind::SO_CFIICall}};
 
-  SmallVector, 5>
-  Checks;
   for (auto CheckKindOrdinalPair : CheckKinds) {
 int Kind = CheckKindOrdinalPair.first;
 SanitizerKind::SanitizerOrdinal Ordinal = CheckKindOrdinalPair.second;
diff --git a/clang/lib/CodeGen/CGExprAgg.cpp b/clang/lib/CodeGen/CGExprAgg.cpp
index 87b2a73fb0c03..7917cdb7e12b6 100644
--- a/clang/lib/CodeGen/CGExprAgg.cpp
+++ b/clang/lib/CodeGen/CGExprAgg.cpp
@@ -1814,7 +1814,6 @@ void AggExprEmitter::VisitCXXParenListOrInitListExpr(
 
   // We'll need to enter cleanup scopes in case any of the element
   // initializers throws an exception.
-  SmallVector c

[clang] f002f30 - [clang] Remove unused local variables (NFC) (#138453)

2025-05-04 Thread via cfe-commits

Author: Kazu Hirata
Date: 2025-05-04T10:51:40-07:00
New Revision: f002f300c5e1f9ce8adf00441b7e879fec36a071

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

LOG: [clang] Remove unused local variables (NFC) (#138453)

Added: 


Modified: 
clang/lib/CodeGen/CGBuiltin.cpp
clang/lib/CodeGen/CGCUDANV.cpp
clang/lib/CodeGen/CGDeclCXX.cpp
clang/lib/CodeGen/CGExpr.cpp
clang/lib/CodeGen/CGExprAgg.cpp
clang/lib/CodeGen/CGHLSLRuntime.cpp
clang/lib/CodeGen/CGObjCGNU.cpp
clang/lib/CodeGen/CGStmtOpenMP.cpp
clang/lib/Driver/ToolChains/CommonArgs.cpp
clang/lib/Driver/ToolChains/HLSL.cpp
clang/lib/Driver/ToolChains/OHOS.cpp
clang/lib/Frontend/InitPreprocessor.cpp
clang/lib/Lex/PPDirectives.cpp
clang/lib/Parse/ParsePragma.cpp
clang/lib/Sema/SemaCodeComplete.cpp
clang/lib/Sema/SemaDeclAttr.cpp
clang/lib/Sema/SemaDeclObjC.cpp
clang/lib/Sema/SemaInit.cpp
clang/lib/Sema/SemaOpenMP.cpp
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTWriter.cpp
clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
clang/lib/StaticAnalyzer/Checkers/LocalizationChecker.cpp
clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
clang/tools/libclang/CIndex.cpp
clang/unittests/StaticAnalyzer/CallDescriptionTest.cpp
clang/utils/TableGen/ClangAttrEmitter.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 1e4e055e04afd..6235473d19a31 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -1949,7 +1949,6 @@ RValue CodeGenFunction::emitBuiltinOSLogFormat(const 
CallExpr &E) {
   analyze_os_log::OSLogBufferLayout Layout;
   analyze_os_log::computeOSLogBufferLayout(Ctx, &E, Layout);
   Address BufAddr = EmitPointerWithAlignment(E.getArg(0));
-  llvm::SmallVector RetainableOperands;
 
   // Ignore argument 1, the format string. It is not currently used.
   CallArgList Args;

diff  --git a/clang/lib/CodeGen/CGCUDANV.cpp b/clang/lib/CodeGen/CGCUDANV.cpp
index 395263331d141..dd26be74e561b 100644
--- a/clang/lib/CodeGen/CGCUDANV.cpp
+++ b/clang/lib/CodeGen/CGCUDANV.cpp
@@ -1194,7 +1194,6 @@ void CGNVCUDARuntime::transformManagedVars() {
 // registered. The linker will provide a pointer to this section so we can
 // register the symbols with the linked device image.
 void CGNVCUDARuntime::createOffloadingEntries() {
-  SmallVector Out;
   llvm::object::OffloadKind Kind = CGM.getLangOpts().HIP
? llvm::object::OffloadKind::OFK_HIP
: llvm::object::OffloadKind::OFK_Cuda;

diff  --git a/clang/lib/CodeGen/CGDeclCXX.cpp b/clang/lib/CodeGen/CGDeclCXX.cpp
index 8a214da6bf628..69d77f283db3b 100644
--- a/clang/lib/CodeGen/CGDeclCXX.cpp
+++ b/clang/lib/CodeGen/CGDeclCXX.cpp
@@ -748,7 +748,6 @@ void CodeGenModule::EmitCXXModuleInitFunc(Module *Primary) {
   // Add any initializers with specified priority; this uses the same  approach
   // as EmitCXXGlobalInitFunc().
   if (!PrioritizedCXXGlobalInits.empty()) {
-SmallVector LocalCXXGlobalInits;
 llvm::array_pod_sort(PrioritizedCXXGlobalInits.begin(),
  PrioritizedCXXGlobalInits.end());
 for (SmallVectorImpl::iterator

diff  --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index bba7d1e805f3f..2e01adc51fdf0 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -3955,8 +3955,6 @@ void CodeGenFunction::EmitCfiCheckFail() {
   {CFITCK_UnrelatedCast, SanitizerKind::SO_CFIUnrelatedCast},
   {CFITCK_ICall, SanitizerKind::SO_CFIICall}};
 
-  SmallVector, 5>
-  Checks;
   for (auto CheckKindOrdinalPair : CheckKinds) {
 int Kind = CheckKindOrdinalPair.first;
 SanitizerKind::SanitizerOrdinal Ordinal = CheckKindOrdinalPair.second;

diff  --git a/clang/lib/CodeGen/CGExprAgg.cpp b/clang/lib/CodeGen/CGExprAgg.cpp
index 87b2a73fb0c03..7917cdb7e12b6 100644
--- a/clang/lib/CodeGen/CGExprAgg.cpp
+++ b/clang/lib/CodeGen/CGExprAgg.cpp
@@ -1814,7 +1814,6 @@ void AggExprEmitter::VisitCXXParenListOrInitListExpr(
 
   // We'll need to enter cleanup scopes in case any of the element
   // initializers throws an exception.
-  SmallVector cleanups;
   CodeGenFunction::CleanupDeactivationScope DeactivateCleanups(CGF);
 
   unsigned curInitIndex = 0;

diff  --git a/clang/lib/CodeGen/CGHLSLRuntime.cpp 
b/clang/lib/CodeGen/CGHLSLRuntime.cpp
index 6136417fcad60..f6608faaa7309 100644
--- a/clang/lib/CodeGen/CGHLSLRuntime.cpp
+++ b/clang/lib/CodeGen/CGHLSLRuntime.cpp
@@ -446,7 +446,6 @@ static void gatherFunctions(SmallVectorImpl 
&Fns, llvm::Module &M,
   // HLSL neither supports priorities or COMDat values, so we will check those
   // in an a

[clang] [clang] Remove unused local variables (NFC) (PR #138453)

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


@@ -361,15 +361,8 @@ TEST(CallDescription, AliasNames) {
   std::cont v;
   v.data();
 })code";
-  constexpr StringRef UseStructNameInSpelling = R"code(
-void foo() {
-  std::container v;
-  v.data();
-})code";
   const std::string UseAliasInSpellingCode =
   (Twine{AliasNamesCode} + UseAliasInSpelling).str();
-  const std::string UseStructNameInSpellingCode =
-  (Twine{AliasNamesCode} + UseStructNameInSpelling).str();

kazutakahirata wrote:

Thank you for the review!  `UseStructNameInSpellingCode` seems to have been 
dead ever since it was added in
5644d152578f4604f7dc8c908a0a3f91a726ad80, a patch of yours.


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


[clang] [clang] Remove unused local variables (NFC) (PR #138453)

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

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


[clang] [llvm] [sancov] Introduce optional callback for stack-depth tracking (PR #138323)

2025-05-04 Thread Kees Cook via cfe-commits


@@ -1078,22 +1092,44 @@ void 
ModuleSanitizerCoverage::InjectCoverageAtBlock(Function &F, BasicBlock &BB,
 Store->setNoSanitizeMetadata();
   }
   if (Options.StackDepth && IsEntryBB && !IsLeafFunc) {
-// Check stack depth.  If it's the deepest so far, record it.
 Module *M = F.getParent();
-auto FrameAddrPtr = IRB.CreateIntrinsic(
-Intrinsic::frameaddress,
-IRB.getPtrTy(M->getDataLayout().getAllocaAddrSpace()),
-{Constant::getNullValue(Int32Ty)});
-auto FrameAddrInt = IRB.CreatePtrToInt(FrameAddrPtr, IntptrTy);
-auto LowestStack = IRB.CreateLoad(IntptrTy, SanCovLowestStack);
-auto IsStackLower = IRB.CreateICmpULT(FrameAddrInt, LowestStack);
-auto ThenTerm = SplitBlockAndInsertIfThen(
-IsStackLower, &*IP, false,
-MDBuilder(IRB.getContext()).createUnlikelyBranchWeights());
-IRBuilder<> ThenIRB(ThenTerm);
-auto Store = ThenIRB.CreateStore(FrameAddrInt, SanCovLowestStack);
-LowestStack->setNoSanitizeMetadata();
-Store->setNoSanitizeMetadata();
+if (Options.StackDepthCallbackMin) {
+  // In callback mode, only add call when stack depth reaches minimum.
+  const DataLayout &DL = M->getDataLayout();
+  uint32_t EstimatedStackSize = 0;
+
+  // Make an estimate on the stack usage.
+  for (auto &I : F.getEntryBlock()) {
+if (auto *AI = dyn_cast(&I)) {
+  if (AI->isStaticAlloca()) {
+uint32_t TypeSize = DL.getTypeAllocSize(AI->getAllocatedType());
+EstimatedStackSize += TypeSize;
+  } else {
+// Over-estimate dynamic sizes.
+EstimatedStackSize += 4096;

kees wrote:

Yeah, that's a good point. And yes, we have no dynamic stack sizes in Linux 
anymore, so this "else" will never get run there. I think "always make the 
callback" is a good choice here.

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


[clang] [llvm] [sancov] Introduce optional callback for stack-depth tracking (PR #138323)

2025-05-04 Thread Kees Cook via cfe-commits

kees wrote:

> This is also missing flag and IR tests.

Oh, yes, I will add those. Thanks!

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


[libunwind] [libunwind] [SEH] Implement parsing of ARM pdata/xdata (PR #137950)

2025-05-04 Thread Jacek Caban via cfe-commits

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

LGTM

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


[libunwind] [libunwind] [SEH] Set NonVolatileRegisters before calling a personality function (PR #137951)

2025-05-04 Thread Jacek Caban via cfe-commits

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

Looks reasonable to me overall.

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


[libunwind] [libunwind] [SEH] Set NonVolatileRegisters before calling a personality function (PR #137951)

2025-05-04 Thread Jacek Caban via cfe-commits


@@ -212,6 +238,21 @@ __libunwind_seh_personality(int version, _Unwind_Action 
state,
   ms_exc.ExceptionInformation[2] = state;
   DISPATCHER_CONTEXT *disp_ctx =
   __unw_seh_get_disp_ctx((unw_cursor_t *)context);
+#if defined(__aarch64__)
+  LOCAL_DISPATCHER_CONTEXT_NONVOLREG_ARM64 nonvol;
+  memcpy(&nonvol.GpNvRegs, &disp_ctx->ContextRecord->X19,
+ sizeof(nonvol.GpNvRegs));
+  for (int i = 0; i < 8; i++)
+nonvol.FpNvRegs[i] = disp_ctx->ContextRecord->V[i + 8].D[0];
+  disp_ctx->NonVolatileRegisters = (PBYTE)&nonvol;

cjacek wrote:

You could avoid the cast by using `nonvol.Buffer` here.

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


[libunwind] [libunwind] [SEH] Set NonVolatileRegisters before calling a personality function (PR #137951)

2025-05-04 Thread Jacek Caban via cfe-commits

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


[clang] [Clang][Cygwin] attempt to fix building shared libclang. (PR #138351)

2025-05-04 Thread via cfe-commits

jeremyd2019 wrote:

Surprisingly, it looks like Cygwin (@tyan0) is working around the export limit 
on gcc by setting `-DCMAKE_SHARED_LINKER_FLAGS=-fvisibility=hidden`.  I was 
surprised that worked on gcc - maybe it can be generalized here instead of 
fighting to build only static with gcc to then use that clang to build dynamic 
libraries?

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


[clang-tools-extra] [clangd] Store documentation when indexing standard library (PR #133681)

2025-05-04 Thread Nathan Ridge via cfe-commits


@@ -158,6 +159,42 @@ TEST(StdLibTests, EndToEnd) {
   UnorderedElementsAre(StdlibSymbol("list"), StdlibSymbol("vector")));
 }
 
+TEST(StdLibTests, StdLibDocComments) {
+  Config Cfg;
+  Cfg.Index.StandardLibrary = true;
+  WithContextValue Enabled(Config::Key, std::move(Cfg));
+
+  MockFS FS;
+  FS.Files["stdlib/vector"] = R"cpp(
+namespace std {
+  struct vector {
+/**doc comment*/
+struct inner {};
+  };
+}
+  )cpp";
+  MockCompilationDatabase CDB;
+  CDB.ExtraClangFlags.push_back("-isystem" + testPath("stdlib"));
+  ClangdServer::Options Opts = ClangdServer::optsForTest();
+  Opts.BuildDynamicSymbolIndex = true; // also used for stdlib index
+  ClangdServer Server(CDB, FS, Opts);
+
+  // Open an empty file.  will not be part of the preamble index,
+  // but it will be part of the stdlib index.
+  Server.addDocument(testPath("foo.cc"), "");
+
+  // Wait for the stdlib index to be built.
+  ASSERT_TRUE(Server.blockUntilIdleForTest());
+
+  // Check that the index contains the doc comment.
+  FuzzyFindRequest Req;
+  Req.Query = "inner";
+  Req.Scopes = {"std::vector::"};
+  SymbolSlab Result = runFuzzyFind(*Server.getIndexForTest(), Req);

HighCommander4 wrote:

Done, thanks for the suggestion!

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


[clang-tools-extra] [clangd] Add CodePatterns config option under Completion (PR #137613)

2025-05-04 Thread via cfe-commits

Noustaa wrote:

There is 2 different features involved here.
1) The fact that if i type "inc" it will suggest me both includes snippets
Like the below image the ones tagged LSP on the right side
![image](https://github.com/user-attachments/assets/a21e1db2-f057-4460-921e-d62d25efb794)

2) The fact that if i type "#include https://github.com/llvm/llvm-project/pull/137613
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clangd] Store documentation when indexing standard library (PR #133681)

2025-05-04 Thread Nathan Ridge via cfe-commits

https://github.com/HighCommander4 updated 
https://github.com/llvm/llvm-project/pull/133681

>From ce15317543b135b7aa86d4987fb0c25abd597d56 Mon Sep 17 00:00:00 2001
From: Nathan Ridge 
Date: Mon, 31 Mar 2025 02:25:45 -0400
Subject: [PATCH] [clangd] Store documentation when indexing standard library

Fixes https://github.com/clangd/clangd/issues/2344
---
 clang-tools-extra/clangd/index/FileIndex.cpp  | 21 
 clang-tools-extra/clangd/index/FileIndex.h|  3 +-
 clang-tools-extra/clangd/index/StdLib.cpp | 37 +++---
 .../clangd/unittests/StdLibTests.cpp  | 48 +++
 clang-tools-extra/clangd/unittests/TestTU.cpp |  3 +-
 5 files changed, 81 insertions(+), 31 deletions(-)

diff --git a/clang-tools-extra/clangd/index/FileIndex.cpp 
b/clang-tools-extra/clangd/index/FileIndex.cpp
index aa573e312a756..de88edd0c7a0b 100644
--- a/clang-tools-extra/clangd/index/FileIndex.cpp
+++ b/clang-tools-extra/clangd/index/FileIndex.cpp
@@ -48,13 +48,12 @@ SlabTuple indexSymbols(ASTContext &AST, Preprocessor &PP,
const MainFileMacros *MacroRefsToIndex,
const include_cleaner::PragmaIncludes &PI,
bool IsIndexMainAST, llvm::StringRef Version,
-   bool CollectMainFileRefs) {
+   bool CollectMainFileRefs, SymbolOrigin Origin) {
   SymbolCollector::Options CollectorOpts;
   CollectorOpts.CollectIncludePath = true;
   CollectorOpts.PragmaIncludes = &PI;
   CollectorOpts.CountReferences = false;
-  CollectorOpts.Origin =
-  IsIndexMainAST ? SymbolOrigin::Open : SymbolOrigin::Preamble;
+  CollectorOpts.Origin = Origin;
   CollectorOpts.CollectMainFileRefs = CollectMainFileRefs;
   // We want stdlib implementation details in the index only if we've opened 
the
   // file in question. This does means xrefs won't work, though.
@@ -221,22 +220,24 @@ FileShardedIndex::getShard(llvm::StringRef Uri) const {
 }
 
 SlabTuple indexMainDecls(ParsedAST &AST) {
-  return indexSymbols(
-  AST.getASTContext(), AST.getPreprocessor(), AST.getLocalTopLevelDecls(),
-  &AST.getMacros(), AST.getPragmaIncludes(),
-  /*IsIndexMainAST=*/true, AST.version(), /*CollectMainFileRefs=*/true);
+  return indexSymbols(AST.getASTContext(), AST.getPreprocessor(),
+  AST.getLocalTopLevelDecls(), &AST.getMacros(),
+  AST.getPragmaIncludes(),
+  /*IsIndexMainAST=*/true, AST.version(),
+  /*CollectMainFileRefs=*/true, SymbolOrigin::Open);
 }
 
 SlabTuple indexHeaderSymbols(llvm::StringRef Version, ASTContext &AST,
  Preprocessor &PP,
- const include_cleaner::PragmaIncludes &PI) {
+ const include_cleaner::PragmaIncludes &PI,
+ SymbolOrigin Origin) {
   std::vector DeclsToIndex(
   AST.getTranslationUnitDecl()->decls().begin(),
   AST.getTranslationUnitDecl()->decls().end());
   return indexSymbols(AST, PP, DeclsToIndex,
   /*MainFileMacros=*/nullptr, PI,
   /*IsIndexMainAST=*/false, Version,
-  /*CollectMainFileRefs=*/false);
+  /*CollectMainFileRefs=*/false, Origin);
 }
 
 FileSymbols::FileSymbols(IndexContents IdxContents, bool SupportContainedRefs)
@@ -463,7 +464,7 @@ void FileIndex::updatePreamble(PathRef Path, 
llvm::StringRef Version,
const include_cleaner::PragmaIncludes &PI) {
   IndexFileIn IF;
   std::tie(IF.Symbols, std::ignore, IF.Relations) =
-  indexHeaderSymbols(Version, AST, PP, PI);
+  indexHeaderSymbols(Version, AST, PP, PI, SymbolOrigin::Preamble);
   updatePreamble(std::move(IF));
 }
 
diff --git a/clang-tools-extra/clangd/index/FileIndex.h 
b/clang-tools-extra/clangd/index/FileIndex.h
index 8e88dc9712996..86af5ee3723f6 100644
--- a/clang-tools-extra/clangd/index/FileIndex.h
+++ b/clang-tools-extra/clangd/index/FileIndex.h
@@ -164,7 +164,8 @@ SlabTuple indexMainDecls(ParsedAST &AST);
 /// included headers.
 SlabTuple indexHeaderSymbols(llvm::StringRef Version, ASTContext &AST,
  Preprocessor &PP,
- const include_cleaner::PragmaIncludes &PI);
+ const include_cleaner::PragmaIncludes &PI,
+ SymbolOrigin Origin);
 
 /// Takes slabs coming from a TU (multiple files) and shards them per
 /// declaration location.
diff --git a/clang-tools-extra/clangd/index/StdLib.cpp 
b/clang-tools-extra/clangd/index/StdLib.cpp
index d34838a45048d..483589365eace 100644
--- a/clang-tools-extra/clangd/index/StdLib.cpp
+++ b/clang-tools-extra/clangd/index/StdLib.cpp
@@ -15,12 +15,15 @@
 #include "Compiler.h"
 #include "Config.h"
 #include "SymbolCollector.h"
+#include "clang-include-cleaner/Record.h"
+#include "index/FileIndex.h"
 #include "index/IndexAction.h"
 #include "support/Logger.h"
 

[clang-tools-extra] [clangd] Add CodePatterns config option under Completion (PR #137613)

2025-05-04 Thread Nathan Ridge via cfe-commits

HighCommander4 wrote:

> There is 2 different features involved here.
> 
> [...]
>
> In the feature i'm trying to implement, number 1 should be OFF if 
> CodePatterns is set to None but number 2 should still be working.

That makes sense to me, as a user expectation.

The code I linked to in my previous comment is for (1). The completions for 
scenario (2) come from 
[here](https://searchfox.org/llvm/rev/1b60b83adad8c62140ce8cc092179ed06df7ff09/clang/lib/Sema/SemaCodeComplete.cpp#10355),
 but unfortunately that's also `RK_Pattern`.

> Are these 2 features (num 1 & 2) coupled or can they be managed separately as 
> the current state ?

It looks like we can achieve this by allowing `RK_Pattern` completions if 
`Context.getKind() == CodeCompletionContext::CCC_IncludedFile`.

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


[clang] [Clang] Add `noalias` to `this` pointer in C++ constructors (PR #136792)

2025-05-04 Thread Guy David via cfe-commits

guy-david wrote:

Comparison between latest Clang and GCC's output for a snippet out of a 
benchmark that could use this optimization: https://godbolt.org/z/35EEvcsPr.

I've ran llvm-test-suite ten times for the before and after, it executed 
correctly and expectedly saw no performance gains:
```
Tests: 3326
Metric: exec_time

   exec_time
l/r  lhsrhs diff
count  3326.003326.001554.00
mean   885.285851 885.132328 inf
std20163.199507   20160.504672  NaN 
min0.00   0.00  -1.00   
25%0.00   0.00  -0.004020   
50%0.00   0.00   0.00   
75%1.741165   1.840265   0.003943   
max802971.672414  802823.530425  inf
```

Also built a bootstrap build and confirmed that `ninja stage2-check-all` passes 
successfully, except for a few libcxx benchmarks that seem to fail regardless.

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


[clang] [FixIt] Improve Source Ranges and Fix-It Hints for Unused Lambda Captures #106445 (PR #117953)

2025-05-04 Thread via cfe-commits

https://github.com/charan-003 updated 
https://github.com/llvm/llvm-project/pull/117953

>From b886394f3aca3ea53f2c97d85a8e963d192c122f Mon Sep 17 00:00:00 2001
From: charan-003 <85248228+charan-...@users.noreply.github.com>
Date: Wed, 27 Nov 2024 18:43:38 -0700
Subject: [PATCH 01/36] Update SemaLambda.cpp

This patch refines how Clang handles source ranges for unused lambda captures. 
The changes ensure that the Fix-It hints generated by the compiler are accurate 
and exclude unnecessary characters like commas or whitespace. Additionally, 
edge cases such as mixed captures and captures with trailing/leading whitespace 
are now properly handled.
---
 clang/lib/Sema/SemaLambda.cpp | 13 ++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/clang/lib/Sema/SemaLambda.cpp b/clang/lib/Sema/SemaLambda.cpp
index a67c0b2b367d1..e7417d1a884dc 100644
--- a/clang/lib/Sema/SemaLambda.cpp
+++ b/clang/lib/Sema/SemaLambda.cpp
@@ -1164,8 +1164,11 @@ void 
Sema::ActOnLambdaExpressionAfterIntroducer(LambdaIntroducer &Intro,
   /*FunctionScopeIndexToStopAtPtr*/ nullptr,
   C->Kind == LCK_StarThis);
   if (!LSI->Captures.empty())
-LSI->ExplicitCaptureRanges[LSI->Captures.size() - 1] = 
C->ExplicitRange;
-  continue;
+  {
+  SourceRange TrimmedRange = Lexer::makeFileCharRange(
+  C->ExplicitRange, SM, LangOpts);
+  LSI->ExplicitCaptureRanges[LSI->Captures.size() - 1] = TrimmedRange;
+  }
 }
 
 assert(C->Id && "missing identifier for capture");
@@ -1329,7 +1332,11 @@ void 
Sema::ActOnLambdaExpressionAfterIntroducer(LambdaIntroducer &Intro,
   tryCaptureVariable(Var, C->Loc, Kind, EllipsisLoc);
 }
 if (!LSI->Captures.empty())
-  LSI->ExplicitCaptureRanges[LSI->Captures.size() - 1] = C->ExplicitRange;
+  {
+SourceRange TrimmedRange = Lexer::makeFileCharRange(
+C->ExplicitRange, SM, LangOpts);
+LSI->ExplicitCaptureRanges[LSI->Captures.size() - 1] = TrimmedRange;
+}
   }
   finishLambdaExplicitCaptures(LSI);
   LSI->ContainsUnexpandedParameterPack |= ContainsUnexpandedParameterPack;

>From ccb39521d4e246bb2b1fd2c9f3727d2332b9a6df Mon Sep 17 00:00:00 2001
From: charan-003 <85248228+charan-...@users.noreply.github.com>
Date: Wed, 27 Nov 2024 18:48:37 -0700
Subject: [PATCH 02/36] Update fixit-unused-lambda-capture.cpp

This patch extends the existing test coverage in 
fixit-unused-lambda-capture.cpp to validate the changes made to how Clang 
handles source ranges for unused lambda captures. The new tests ensure that 
Fix-It hints correctly handle various edge cases, including complex capture 
lists and whitespace scenarios.
---
 .../FixIt/fixit-unused-lambda-capture.cpp | 32 +++
 1 file changed, 32 insertions(+)

diff --git a/clang/test/FixIt/fixit-unused-lambda-capture.cpp 
b/clang/test/FixIt/fixit-unused-lambda-capture.cpp
index ce0c78d677099..ae43d4ebbdf82 100644
--- a/clang/test/FixIt/fixit-unused-lambda-capture.cpp
+++ b/clang/test/FixIt/fixit-unused-lambda-capture.cpp
@@ -66,6 +66,38 @@ void test() {
   // CHECK: [z = (n = i)] {};
   [j,z = (n = i)] {};
   // CHECK: [z = (n = i)] {};
+
+  // New Edge Cases
+
+  // Test 1: Leading and trailing whitespace
+  [i,j] { return i; };
+  // CHECK: [i] { return i; };
+  [i ,j] { return j; };
+  // CHECK: [j] { return j; };
+  [i  ,  j ,  k] { return j + k; };
+  // CHECK: [j,k] { return j + k; };
+
+  // Test 2: Single unused capture
+  [i] {};
+  // CHECK: [] {};
+  [&i] {};
+  // CHECK: [] {};
+
+  // Test 3: Multiple commas
+  [i,,j] { return j; };
+  // CHECK: [j] { return j; };
+  [,i,j,,k] { return k; };
+  // CHECK: [k] { return k; };
+
+  // Test 4: Mixed captures
+  [=, &i, j] { return i; };
+  // CHECK: [&i] { return i; };
+  [&, i] {};
+  // CHECK: [&] {};
+
+  // Test 5: Capture with comments
+  [/*capture*/ i, j] { return j; };
+  // CHECK: [/*capture*/ j] { return j; };
 }
 
 class ThisTest {

>From 6b5fff5d2f10e422f94939213d2302a87501a867 Mon Sep 17 00:00:00 2001
From: charan-003 <85248228+charan-...@users.noreply.github.com>
Date: Wed, 27 Nov 2024 21:52:22 -0700
Subject: [PATCH 03/36] Update SemaLambda.cpp

added #include "clang/Lex/Lexer.h"
---
 clang/lib/Sema/SemaLambda.cpp | 5 +
 1 file changed, 5 insertions(+)

diff --git a/clang/lib/Sema/SemaLambda.cpp b/clang/lib/Sema/SemaLambda.cpp
index e7417d1a884dc..82a0f926d6af7 100644
--- a/clang/lib/Sema/SemaLambda.cpp
+++ b/clang/lib/Sema/SemaLambda.cpp
@@ -26,6 +26,7 @@
 #include "clang/Sema/SemaOpenMP.h"
 #include "clang/Sema/Template.h"
 #include "llvm/ADT/STLExtras.h"
+#include "clang/Lex/Lexer.h"
 #include 
 using namespace clang;
 using namespace sema;
@@ -1165,6 +1166,8 @@ void 
Sema::ActOnLambdaExpressionAfterIntroducer(LambdaIntroducer &Intro,
   C->Kind == LCK_StarThis);
   if (!LSI->Captures.empty())
   {
+  SourceManager &SourceMgr = Context.getSourceManager(); 
+  cons

[clang] [clang-format] Add SpaceAfterOperatorKeyword option (PR #137610)

2025-05-04 Thread Filip Milosevic via cfe-commits

https://github.com/MightyFilipns updated 
https://github.com/llvm/llvm-project/pull/137610

>From dd0434829bebfa00493be35faa108b32efa62b03 Mon Sep 17 00:00:00 2001
From: MightyFilipns 
Date: Mon, 28 Apr 2025 11:54:20 +0200
Subject: [PATCH] clang-format: Add SpaceAfterOperatorKeyword option

---
 clang/docs/ClangFormatStyleOptions.rst | 10 ++
 clang/docs/ReleaseNotes.rst|  1 +
 clang/include/clang/Format/Format.h|  9 +
 clang/lib/Format/Format.cpp|  3 +++
 clang/lib/Format/TokenAnnotator.cpp|  2 +-
 clang/unittests/Format/ConfigParseTest.cpp |  1 +
 clang/unittests/Format/FormatTest.cpp  |  6 ++
 7 files changed, 31 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index b47291599649d..a4c381bf583b6 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -6127,6 +6127,16 @@ the configuration (without a prefix: ``Auto``).
  true:  false:
  ! someExpression();vs. !someExpression();
 
+.. _SpaceAfterOperatorKeyword:
+
+**SpaceAfterOperatorKeyword** (``Boolean``) :versionbadge:`clang-format 21` 
:ref:`¶ `
+  If ``true``, a space will be inserted after the ``operator`` keyword.
+
+  .. code-block:: c++
+
+ true:false:
+ bool operator ==(int a); vs. bool operator==(int a);
+
 .. _SpaceAfterTemplateKeyword:
 
 **SpaceAfterTemplateKeyword** (``Boolean``) :versionbadge:`clang-format 4` 
:ref:`¶ `
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 918ff952bb2c3..40239b50716b4 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -786,6 +786,7 @@ clang-format
 - Add ``EnumTrailingComma`` option for inserting/removing commas at the end of
   ``enum`` enumerator lists.
 - Add ``OneLineFormatOffRegex`` option for turning formatting off for one line.
+- Add ``SpaceAfterOperatorKeyword`` option.
 
 libclang
 
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 7fe41d800ccb3..b86c4bd00eb91 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -4484,6 +4484,14 @@ struct FormatStyle {
   /// \version 9
   bool SpaceAfterLogicalNot;
 
+  /// If ``true``, a space will be inserted after the ``operator`` keyword.
+  /// \code
+  ///true:false:
+  ///bool operator ==(int a); vs. bool operator==(int a);
+  /// \endcode
+  /// \version 21
+  bool SpaceAfterOperatorKeyword;
+
   /// If \c true, a space will be inserted after the ``template`` keyword.
   /// \code
   ///true:  false:
@@ -5454,6 +5462,7 @@ struct FormatStyle {
SortJavaStaticImport == R.SortJavaStaticImport &&
SpaceAfterCStyleCast == R.SpaceAfterCStyleCast &&
SpaceAfterLogicalNot == R.SpaceAfterLogicalNot &&
+   SpaceAfterOperatorKeyword == R.SpaceAfterOperatorKeyword &&
SpaceAfterTemplateKeyword == R.SpaceAfterTemplateKeyword &&
SpaceBeforeAssignmentOperators == R.SpaceBeforeAssignmentOperators 
&&
SpaceBeforeCaseColon == R.SpaceBeforeCaseColon &&
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 2f4b64ef4f5fe..20b5352b83a9e 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -1152,6 +1152,8 @@ template <> struct MappingTraits {
 IO.mapOptional("SortUsingDeclarations", Style.SortUsingDeclarations);
 IO.mapOptional("SpaceAfterCStyleCast", Style.SpaceAfterCStyleCast);
 IO.mapOptional("SpaceAfterLogicalNot", Style.SpaceAfterLogicalNot);
+IO.mapOptional("SpaceAfterOperatorKeyword",
+   Style.SpaceAfterOperatorKeyword);
 IO.mapOptional("SpaceAfterTemplateKeyword",
Style.SpaceAfterTemplateKeyword);
 IO.mapOptional("SpaceAroundPointerQualifiers",
@@ -1639,6 +1641,7 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind 
Language) {
   LLVMStyle.SortUsingDeclarations = FormatStyle::SUD_LexicographicNumeric;
   LLVMStyle.SpaceAfterCStyleCast = false;
   LLVMStyle.SpaceAfterLogicalNot = false;
+  LLVMStyle.SpaceAfterOperatorKeyword = false;
   LLVMStyle.SpaceAfterTemplateKeyword = true;
   LLVMStyle.SpaceAroundPointerQualifiers = FormatStyle::SAPQ_Default;
   LLVMStyle.SpaceBeforeAssignmentOperators = true;
diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index caf386cffd25b..50a22149f7bd9 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -5039,7 +5039,7 @@ bool TokenAnnotator::spaceRequiredBefore(const 
AnnotatedLine &Line,
 }
 
 if (Left.is(tok::kw_operator))
-  return Right.is(tok::coloncolon);
+  return Right.is(tok::coloncolon) || Style.SpaceAfterOperatorKeyword;
 if (Rig

[clang] 1812a43 - [clang] Remove unused local variables (NFC) (#138468)

2025-05-04 Thread via cfe-commits

Author: Kazu Hirata
Date: 2025-05-04T14:14:23-07:00
New Revision: 1812a43a22a82adccf46d6589b8460a3a7a2678e

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

LOG: [clang] Remove unused local variables (NFC) (#138468)

Added: 


Modified: 
clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h
clang/lib/Sema/SemaPPC.cpp
clang/lib/Sema/SemaTemplateDeduction.cpp
clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
clang/lib/StaticAnalyzer/Core/BugReporter.cpp
clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
clang/unittests/Tooling/CompilationDatabaseTest.cpp

Removed: 




diff  --git 
a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h
index e084a13995306..d4052ef90de6e 100644
--- 
a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h
+++ 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h
@@ -324,8 +324,6 @@ class SMTConstraintManager : public 
clang::ento::SimpleConstraintManager {
 
 // Construct the logical AND of all the constraints
 if (I != IE) {
-  std::vector ASTs;
-
   llvm::SMTExprRef Constraint = I++->second;
   while (I != IE) {
 Constraint = Solver->mkAnd(Constraint, I++->second);

diff  --git a/clang/lib/Sema/SemaPPC.cpp b/clang/lib/Sema/SemaPPC.cpp
index b6802d6890ed1..9b4d82745f881 100644
--- a/clang/lib/Sema/SemaPPC.cpp
+++ b/clang/lib/Sema/SemaPPC.cpp
@@ -98,7 +98,6 @@ bool SemaPPC::CheckPPCBuiltinFunctionCall(const TargetInfo 
&TI,
   CallExpr *TheCall) {
   ASTContext &Context = getASTContext();
   bool IsTarget64Bit = TI.getTypeWidth(TI.getIntPtrType()) == 64;
-  llvm::APSInt Result;
 
   if (isPPC_64Builtin(BuiltinID) && !IsTarget64Bit)
 return Diag(TheCall->getBeginLoc(), diag::err_64_bit_builtin_32_bit_tgt)

diff  --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 
b/clang/lib/Sema/SemaTemplateDeduction.cpp
index 0ecdbb3ffb89f..c9de36383d334 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -6605,8 +6605,6 @@ bool 
Sema::isTemplateTemplateParameterAtLeastAsSpecializedAs(
 llvm_unreachable("Unexpected Result");
   }
 
-  SmallVector DeducedArgs(Deduced.begin(), Deduced.end());
-
   TemplateDeductionResult TDK;
   runWithSufficientStackSpace(Info.getLocation(), [&] {
 TDK = ::FinishTemplateArgumentDeduction(

diff  --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
index 0f0184c472f36..4ddd11495f534 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
@@ -370,8 +370,6 @@ std::optional isUnsafePtr(const QualType T, bool 
IsArcEnabled) {
 std::optional isGetterOfSafePtr(const CXXMethodDecl *M) {
   assert(M);
 
-  std::optional RTC;
-
   if (isa(M)) {
 const CXXRecordDecl *calleeMethodsClass = M->getParent();
 auto className = safeGetName(calleeMethodsClass);

diff  --git a/clang/lib/StaticAnalyzer/Core/BugReporter.cpp 
b/clang/lib/StaticAnalyzer/Core/BugReporter.cpp
index f8db8d0bc8343..28b96f2717210 100644
--- a/clang/lib/StaticAnalyzer/Core/BugReporter.cpp
+++ b/clang/lib/StaticAnalyzer/Core/BugReporter.cpp
@@ -3377,8 +3377,6 @@ 
PathSensitiveBugReporter::generateDiagnosticForConsumerMap(
 BugReport *exampleReport,
 ArrayRef> consumers,
 ArrayRef bugReports) {
-  std::vector BasicBugReports;
-  std::vector PathSensitiveBugReports;
   if (isa(exampleReport))
 return BugReporter::generateDiagnosticForConsumerMap(exampleReport,
  consumers, 
bugReports);

diff  --git a/clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp 
b/clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
index 95d9df4100bfa..84a9c43d3572e 100644
--- a/clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
+++ b/clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
@@ -270,7 +270,7 @@ static bool isWithinConstantOverflowBounds(llvm::APSInt I) {
   assert(!AT.isUnsigned() &&
  "This only works with signed integers!");
 
-  llvm::APSInt Max = AT.getMaxValue() / AT.getValue(4), Min = -Max;
+  llvm::APSInt Max = AT.getMaxValue() / AT.getValue(4);
   return (I <= Max) && (I >= -Max);
 }
 

diff  --git a/clang/unittests/Tooling/CompilationDatabaseTest.cpp 
b/clang/unittests/Tooling/CompilationDatabaseTest.cpp
index 2032b13726c45..c1febaf40bf19 100644
--- a/clang/unittests/Tooling/CompilationDatabaseTest.cpp
+++ b/clang/unittests/Tooling/CompilationDatabaseTest.cpp
@@ -703,7 +703,6 @@ TEST(ParseFix

[clang] [clang] Remove unused local variables (NFC) (PR #138468)

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

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


[clang] [Clang] Add `noalias` to `this` pointer in C++ constructors (PR #136792)

2025-05-04 Thread Guy David via cfe-commits

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


[clang] [clang] Add support for Debian 14 Forky and Debian 15 Duke (PR #138460)

2025-05-04 Thread Sylvestre Ledru via cfe-commits

sylvestre wrote:

please let me know i should merge it


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


[clang] [clang] Add support for Debian 14 Forky and Debian 15 Duke (PR #138460)

2025-05-04 Thread Sylvestre Ledru via cfe-commits

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

excellent, thanks!



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


[clang] [clang] Remove unused local variables (NFC) (PR #138453)

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


@@ -361,15 +361,8 @@ TEST(CallDescription, AliasNames) {
   std::cont v;
   v.data();
 })code";
-  constexpr StringRef UseStructNameInSpelling = R"code(
-void foo() {
-  std::container v;
-  v.data();
-})code";
   const std::string UseAliasInSpellingCode =
   (Twine{AliasNamesCode} + UseAliasInSpelling).str();
-  const std::string UseStructNameInSpellingCode =
-  (Twine{AliasNamesCode} + UseStructNameInSpelling).str();

steakhal wrote:

This test code left me wondering if this is dead because it's intended to test 
something or dead because we moved the relevant parts to other tests thus 
become dead.
I think it's safe to remove these lines.

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


[clang] [clang] Remove unused local variables (NFC) (PR #138453)

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

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


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


[clang] [clang][bytecode] Use bytecode interpreter in EvaluateCharRangeAsString (PR #138461)

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

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

This was always using the ast walker.

>From 8d76bc91a3a443b6563cfe26f7558adf73d2f60c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Sun, 4 May 2025 07:25:20 +0200
Subject: [PATCH] [clang][bytecode] Use bytecode interpreter in
 EvaluateCharRangeAsString

This was always using the ast walker.
---
 clang/lib/AST/ByteCode/Context.cpp | 79 ++
 clang/lib/AST/ByteCode/Context.h   |  9 +++
 clang/lib/AST/ByteCode/EvalEmitter.cpp | 23 +++
 clang/lib/AST/ByteCode/EvalEmitter.h   |  6 ++
 clang/lib/AST/ByteCode/EvaluationResult.h  |  6 +-
 clang/lib/AST/ByteCode/Pointer.h   |  7 ++
 clang/lib/AST/ExprConstant.cpp |  7 +-
 clang/test/SemaCXX/gnu-asm-constexpr.cpp   |  1 +
 clang/test/SemaCXX/static-assert-cxx26.cpp |  1 +
 9 files changed, 133 insertions(+), 6 deletions(-)

diff --git a/clang/lib/AST/ByteCode/Context.cpp 
b/clang/lib/AST/ByteCode/Context.cpp
index b35b30cc20d81..db9df7abf7a29 100644
--- a/clang/lib/AST/ByteCode/Context.cpp
+++ b/clang/lib/AST/ByteCode/Context.cpp
@@ -134,6 +134,85 @@ bool Context::evaluateAsInitializer(State &Parent, const 
VarDecl *VD,
   return true;
 }
 
+template 
+bool Context::evaluateStringRepr(State &Parent, const Expr *SizeExpr,
+ const Expr *PtrExpr, ResultT &Result) {
+  assert(Stk.empty());
+  Compiler C(*this, *P, Parent, Stk);
+
+  // Evaluate size value.
+  APValue SizeValue;
+  if (!evaluateAsRValue(Parent, SizeExpr, SizeValue))
+return false;
+
+  if (!SizeValue.isInt())
+return false;
+  uint64_t Size = SizeValue.getInt().getZExtValue();
+
+  auto PtrRes = C.interpretAsPointer(PtrExpr, [&](const Pointer &Ptr) {
+if (Size == 0) {
+  if constexpr (std::is_same_v)
+Result = APValue(APValue::UninitArray{}, 0, 0);
+  return true;
+}
+
+if (!Ptr.isLive() || !Ptr.getFieldDesc()->isPrimitiveArray())
+  return false;
+
+// Must be char.
+if (Ptr.getFieldDesc()->getElemSize() != 1 /*bytes*/)
+  return false;
+
+if (Size > Ptr.getNumElems()) {
+  Parent.FFDiag(SizeExpr, diag::note_constexpr_access_past_end) << AK_Read;
+  Size = Ptr.getNumElems();
+}
+
+if constexpr (std::is_same_v) {
+  QualType CharTy = PtrExpr->getType()->getPointeeType();
+  Result = APValue(APValue::UninitArray{}, Size, Size);
+  for (uint64_t I = 0; I != Size; ++I) {
+if (std::optional ElemVal =
+Ptr.atIndex(I).toRValue(*this, CharTy))
+  Result.getArrayInitializedElt(I) = *ElemVal;
+else
+  return false;
+  }
+} else {
+  assert((std::is_same_v));
+  if (Size < Result.max_size())
+Result.resize(Size);
+  Result.assign(reinterpret_cast(Ptr.getRawAddress()), Size);
+}
+
+return true;
+  });
+
+  if (PtrRes.isInvalid()) {
+C.cleanup();
+Stk.clear();
+return false;
+  }
+
+  return true;
+}
+
+bool Context::evaluateCharRange(State &Parent, const Expr *SizeExpr,
+const Expr *PtrExpr, APValue &Result) {
+  assert(SizeExpr);
+  assert(PtrExpr);
+
+  return evaluateStringRepr(Parent, SizeExpr, PtrExpr, Result);
+}
+
+bool Context::evaluateCharRange(State &Parent, const Expr *SizeExpr,
+const Expr *PtrExpr, std::string &Result) {
+  assert(SizeExpr);
+  assert(PtrExpr);
+
+  return evaluateStringRepr(Parent, SizeExpr, PtrExpr, Result);
+}
+
 const LangOptions &Context::getLangOpts() const { return Ctx.getLangOpts(); }
 
 std::optional Context::classify(QualType T) const {
diff --git a/clang/lib/AST/ByteCode/Context.h b/clang/lib/AST/ByteCode/Context.h
index 5a39f40ef3f11..33bc9fad883f8 100644
--- a/clang/lib/AST/ByteCode/Context.h
+++ b/clang/lib/AST/ByteCode/Context.h
@@ -59,6 +59,11 @@ class Context final {
   /// Evaluates a toplevel initializer.
   bool evaluateAsInitializer(State &Parent, const VarDecl *VD, APValue 
&Result);
 
+  bool evaluateCharRange(State &Parent, const Expr *SizeExpr,
+ const Expr *PtrExpr, APValue &Result);
+  bool evaluateCharRange(State &Parent, const Expr *SizeExpr,
+ const Expr *PtrExpr, std::string &Result);
+
   /// Returns the AST context.
   ASTContext &getASTContext() const { return Ctx; }
   /// Returns the language options.
@@ -122,6 +127,10 @@ class Context final {
   /// Runs a function.
   bool Run(State &Parent, const Function *Func);
 
+  template 
+  bool evaluateStringRepr(State &Parent, const Expr *SizeExpr,
+  const Expr *PtrExpr, ResultT &Result);
+
   /// Current compilation context.
   ASTContext &Ctx;
   /// Interpreter stack, shared across invocations.
diff --git a/clang/lib/AST/ByteCode/EvalEmitter.cpp 
b/clang/lib/AST/ByteCode/EvalEmitter.cpp
index 71d688498ffa5..90aca568c9394 100644
--- a/clang/lib/AST/ByteCode/EvalEmitter.cpp
+++ b/clang/lib

[clang] [clang][bytecode] Use bytecode interpreter in EvaluateCharRangeAsString (PR #138461)

2025-05-04 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)


Changes

This was always using the ast walker.

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


9 Files Affected:

- (modified) clang/lib/AST/ByteCode/Context.cpp (+79) 
- (modified) clang/lib/AST/ByteCode/Context.h (+9) 
- (modified) clang/lib/AST/ByteCode/EvalEmitter.cpp (+23) 
- (modified) clang/lib/AST/ByteCode/EvalEmitter.h (+6) 
- (modified) clang/lib/AST/ByteCode/EvaluationResult.h (+1-5) 
- (modified) clang/lib/AST/ByteCode/Pointer.h (+7) 
- (modified) clang/lib/AST/ExprConstant.cpp (+6-1) 
- (modified) clang/test/SemaCXX/gnu-asm-constexpr.cpp (+1) 
- (modified) clang/test/SemaCXX/static-assert-cxx26.cpp (+1) 


``diff
diff --git a/clang/lib/AST/ByteCode/Context.cpp 
b/clang/lib/AST/ByteCode/Context.cpp
index b35b30cc20d81..db9df7abf7a29 100644
--- a/clang/lib/AST/ByteCode/Context.cpp
+++ b/clang/lib/AST/ByteCode/Context.cpp
@@ -134,6 +134,85 @@ bool Context::evaluateAsInitializer(State &Parent, const 
VarDecl *VD,
   return true;
 }
 
+template 
+bool Context::evaluateStringRepr(State &Parent, const Expr *SizeExpr,
+ const Expr *PtrExpr, ResultT &Result) {
+  assert(Stk.empty());
+  Compiler C(*this, *P, Parent, Stk);
+
+  // Evaluate size value.
+  APValue SizeValue;
+  if (!evaluateAsRValue(Parent, SizeExpr, SizeValue))
+return false;
+
+  if (!SizeValue.isInt())
+return false;
+  uint64_t Size = SizeValue.getInt().getZExtValue();
+
+  auto PtrRes = C.interpretAsPointer(PtrExpr, [&](const Pointer &Ptr) {
+if (Size == 0) {
+  if constexpr (std::is_same_v)
+Result = APValue(APValue::UninitArray{}, 0, 0);
+  return true;
+}
+
+if (!Ptr.isLive() || !Ptr.getFieldDesc()->isPrimitiveArray())
+  return false;
+
+// Must be char.
+if (Ptr.getFieldDesc()->getElemSize() != 1 /*bytes*/)
+  return false;
+
+if (Size > Ptr.getNumElems()) {
+  Parent.FFDiag(SizeExpr, diag::note_constexpr_access_past_end) << AK_Read;
+  Size = Ptr.getNumElems();
+}
+
+if constexpr (std::is_same_v) {
+  QualType CharTy = PtrExpr->getType()->getPointeeType();
+  Result = APValue(APValue::UninitArray{}, Size, Size);
+  for (uint64_t I = 0; I != Size; ++I) {
+if (std::optional ElemVal =
+Ptr.atIndex(I).toRValue(*this, CharTy))
+  Result.getArrayInitializedElt(I) = *ElemVal;
+else
+  return false;
+  }
+} else {
+  assert((std::is_same_v));
+  if (Size < Result.max_size())
+Result.resize(Size);
+  Result.assign(reinterpret_cast(Ptr.getRawAddress()), Size);
+}
+
+return true;
+  });
+
+  if (PtrRes.isInvalid()) {
+C.cleanup();
+Stk.clear();
+return false;
+  }
+
+  return true;
+}
+
+bool Context::evaluateCharRange(State &Parent, const Expr *SizeExpr,
+const Expr *PtrExpr, APValue &Result) {
+  assert(SizeExpr);
+  assert(PtrExpr);
+
+  return evaluateStringRepr(Parent, SizeExpr, PtrExpr, Result);
+}
+
+bool Context::evaluateCharRange(State &Parent, const Expr *SizeExpr,
+const Expr *PtrExpr, std::string &Result) {
+  assert(SizeExpr);
+  assert(PtrExpr);
+
+  return evaluateStringRepr(Parent, SizeExpr, PtrExpr, Result);
+}
+
 const LangOptions &Context::getLangOpts() const { return Ctx.getLangOpts(); }
 
 std::optional Context::classify(QualType T) const {
diff --git a/clang/lib/AST/ByteCode/Context.h b/clang/lib/AST/ByteCode/Context.h
index 5a39f40ef3f11..33bc9fad883f8 100644
--- a/clang/lib/AST/ByteCode/Context.h
+++ b/clang/lib/AST/ByteCode/Context.h
@@ -59,6 +59,11 @@ class Context final {
   /// Evaluates a toplevel initializer.
   bool evaluateAsInitializer(State &Parent, const VarDecl *VD, APValue 
&Result);
 
+  bool evaluateCharRange(State &Parent, const Expr *SizeExpr,
+ const Expr *PtrExpr, APValue &Result);
+  bool evaluateCharRange(State &Parent, const Expr *SizeExpr,
+ const Expr *PtrExpr, std::string &Result);
+
   /// Returns the AST context.
   ASTContext &getASTContext() const { return Ctx; }
   /// Returns the language options.
@@ -122,6 +127,10 @@ class Context final {
   /// Runs a function.
   bool Run(State &Parent, const Function *Func);
 
+  template 
+  bool evaluateStringRepr(State &Parent, const Expr *SizeExpr,
+  const Expr *PtrExpr, ResultT &Result);
+
   /// Current compilation context.
   ASTContext &Ctx;
   /// Interpreter stack, shared across invocations.
diff --git a/clang/lib/AST/ByteCode/EvalEmitter.cpp 
b/clang/lib/AST/ByteCode/EvalEmitter.cpp
index 71d688498ffa5..90aca568c9394 100644
--- a/clang/lib/AST/ByteCode/EvalEmitter.cpp
+++ b/clang/lib/AST/ByteCode/EvalEmitter.cpp
@@ -72,6 +72,25 @@ EvaluationResult EvalEmitter::interpretDecl(const VarDecl 
*VD,
   return std::move(this->EvalResult);
 }
 
+EvaluationResult EvalEmitter::interpretAsPoint

[clang] 4c587f5 - [clang] Use *(Set|Map)::contains (NFC) (#138464)

2025-05-04 Thread via cfe-commits

Author: Kazu Hirata
Date: 2025-05-04T11:56:31-07:00
New Revision: 4c587f549cbbea0ac1db2b983b8c5fb4fff82d72

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

LOG: [clang] Use *(Set|Map)::contains (NFC) (#138464)

Added: 


Modified: 
clang/lib/AST/DeclBase.cpp
clang/lib/Serialization/ASTReader.cpp
clang/tools/libclang/CXCursor.cpp
clang/utils/TableGen/ClangBuiltinTemplatesEmitter.cpp

Removed: 




diff  --git a/clang/lib/AST/DeclBase.cpp b/clang/lib/AST/DeclBase.cpp
index fead99c5f28a9..aea19c51401aa 100644
--- a/clang/lib/AST/DeclBase.cpp
+++ b/clang/lib/AST/DeclBase.cpp
@@ -2149,8 +2149,7 @@ void DeclContext::makeDeclVisibleInContextImpl(NamedDecl 
*D, bool Internal) {
   // have already checked the external source.
   if (!Internal)
 if (ExternalASTSource *Source = getParentASTContext().getExternalSource())
-  if (hasExternalVisibleStorage() &&
-  Map->find(D->getDeclName()) == Map->end())
+  if (hasExternalVisibleStorage() && !Map->contains(D->getDeclName()))
 Source->FindExternalVisibleDeclsByName(this, D->getDeclName(),
D->getDeclContext());
 

diff  --git a/clang/lib/Serialization/ASTReader.cpp 
b/clang/lib/Serialization/ASTReader.cpp
index 106a652049b07..e47bac0261356 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -8646,9 +8646,8 @@ ASTReader::getLoadedSpecializationsLookupTables(const 
Decl *D, bool IsPartial) {
 
 bool ASTReader::haveUnloadedSpecializations(const Decl *D) const {
   assert(D->isCanonicalDecl());
-  return (PartialSpecializationsLookups.find(D) !=
-  PartialSpecializationsLookups.end()) ||
- (SpecializationsLookups.find(D) != SpecializationsLookups.end());
+  return PartialSpecializationsLookups.contains(D) ||
+ SpecializationsLookups.contains(D);
 }
 
 /// Under non-PCH compilation the consumer receives the objc methods

diff  --git a/clang/tools/libclang/CXCursor.cpp 
b/clang/tools/libclang/CXCursor.cpp
index 1d15120106017..635d03a88d105 100644
--- a/clang/tools/libclang/CXCursor.cpp
+++ b/clang/tools/libclang/CXCursor.cpp
@@ -1638,7 +1638,7 @@ unsigned clang_CXCursorSet_contains(CXCursorSet set, 
CXCursor cursor) {
   CXCursorSet_Impl *setImpl = unpackCXCursorSet(set);
   if (!setImpl)
 return 0;
-  return setImpl->find(cursor) != setImpl->end();
+  return setImpl->contains(cursor);
 }
 
 unsigned clang_CXCursorSet_insert(CXCursorSet set, CXCursor cursor) {

diff  --git a/clang/utils/TableGen/ClangBuiltinTemplatesEmitter.cpp 
b/clang/utils/TableGen/ClangBuiltinTemplatesEmitter.cpp
index de79743a06e1f..e2eb65091bc5a 100644
--- a/clang/utils/TableGen/ClangBuiltinTemplatesEmitter.cpp
+++ b/clang/utils/TableGen/ClangBuiltinTemplatesEmitter.cpp
@@ -60,10 +60,8 @@ ParseTemplateParameterList(ParserState &PS,
 } else if (Arg->isSubClassOf("NTTP")) {
   auto Type = Arg->getValueAsString("TypeName");
 
-  if (TemplateNameToParmName.find(Type.str()) ==
-  TemplateNameToParmName.end()) {
+  if (!TemplateNameToParmName.contains(Type.str()))
 PrintFatalError("Unkown Type Name");
-  }
 
   auto TSIName = "TSI" + std::to_string(PS.UniqueCounter++);
   Code << " auto *" << TSIName << " = C.getTrivialTypeSourceInfo(QualType("



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


[clang] [clang] Use *(Set|Map)::contains (NFC) (PR #138464)

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

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


[clang] [clang][Driver][test] Fix Driver/solaris-ld.c on non-Unix hosts (PR #138466)

2025-05-04 Thread Rainer Orth via cfe-commits

https://github.com/rorth created 
https://github.com/llvm/llvm-project/pull/138466

`Clang :: Driver/solaris-ld.c` currently `FAIL`s on two non-Unix buildbots: 
[fuchsia-x86_64-linux](https://lab.llvm.org/buildbot/#/builders/11/builds/14369)
 and
[llvm-clang-win-x-aarch64](https://lab.llvm.org/buildbot/#/builders/193/builds/7452).

Judging from `linux-ld.c`, all subtests need `-rtlib=platform 
--unwindlib=platform` whenever host and target have different `rtlib` and 
`unwindlib` defaults, which is what this patch does for `solaris-ld.c`, too.

Tested on `amd64-pc-solaris2.11`, `sparcv9-sun-solaris2.11`, and 
`x86_64-pc-linux-gnu`.

>From 34c6251f497d21b49d525c69e83b180d7b577332 Mon Sep 17 00:00:00 2001
From: Rainer Orth 
Date: Sun, 4 May 2025 21:22:33 +0200
Subject: [PATCH] [clang][Driver][test] Fix Driver/solaris-ld.c on non-Unix
 hosts

`Clang :: Driver/solaris-ld.c` currently `FAIL`s on two non-Unix buildbots:
[fuchsia-x86_64-linux](https://lab.llvm.org/buildbot/#/builders/11/builds/14369)
and
[llvm-clang-win-x-aarch64](https://lab.llvm.org/buildbot/#/builders/193/builds/7452).

Judging from `linux-ld.c`, all subtests need `-rtlib=platform
--unwindlib=platform` whenever host and target have different `rtlib` and
`unwindlib` defaults, which is what this patch does for `solaris-ld.c`,
too.

Tested on `amd64-pc-solaris2.11`, `sparcv9-sun-solaris2.11`, and
`x86_64-pc-linux-gnu`.
---
 clang/test/Driver/solaris-ld.c | 36 +-
 1 file changed, 35 insertions(+), 1 deletion(-)

diff --git a/clang/test/Driver/solaris-ld.c b/clang/test/Driver/solaris-ld.c
index 9aa7ed760666d..5940ee2add769 100644
--- a/clang/test/Driver/solaris-ld.c
+++ b/clang/test/Driver/solaris-ld.c
@@ -3,9 +3,11 @@
 
 // Check sparc-sun-solaris2.11, 32bit
 // RUN: %clang -### %s --target=sparc-sun-solaris2.11 -fuse-ld= \
+// RUN: -rtlib=platform --unwindlib=platform \
 // RUN: --sysroot=%S/Inputs/solaris_sparc_tree 2>&1 \
 // RUN:   | FileCheck --check-prefixes=CHECK-LD-SPARC32,CHECK-LD %s
 // RUN: %clang -### %s --target=sparc-sun-solaris2.11 -fuse-ld=gld \
+// RUN: -rtlib=platform --unwindlib=platform \
 // RUN: --sysroot=%S/Inputs/solaris_sparc_tree 2>&1 \
 // RUN:   | FileCheck --check-prefixes=CHECK-LD-SPARC32,CHECK-GLD %s
 // CHECK-LD-SPARC32-NOT: warning:
@@ -29,6 +31,7 @@
 
 // Check sparc-sun-solaris2.11, 64bit
 // RUN: %clang -m64 -### %s 2>&1 --target=sparc-sun-solaris2.11 \
+// RUN: -rtlib=platform --unwindlib=platform \
 // RUN: --sysroot=%S/Inputs/solaris_sparc_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-LD-SPARC64 %s
 // CHECK-LD-SPARC64-NOT: warning:
@@ -50,6 +53,7 @@
 
 // Check i386-pc-solaris2.11, 32bit
 // RUN: %clang -### %s 2>&1 --target=i386-pc-solaris2.11 \
+// RUN: -rtlib=platform --unwindlib=platform \
 // RUN: --sysroot=%S/Inputs/solaris_x86_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-LD-X32 %s
 // CHECK-LD-X32-NOT: warning:
@@ -72,6 +76,7 @@
 // Check i386-pc-solaris2.11, 64bit
 // RUN: %clang -m64 -### %s 2>&1 \
 // RUN: --target=i386-pc-solaris2.11 \
+// RUN: -rtlib=platform --unwindlib=platform \
 // RUN: --sysroot=%S/Inputs/solaris_x86_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-LD-X64 %s
 // CHECK-LD-X64-NOT: warning:
@@ -94,6 +99,7 @@
 // Check the right -l flags are present with -shared
 // RUN: %clang -### %s -shared 2>&1 \
 // RUN: --target=sparc-sun-solaris2.11 \
+// RUN: -rtlib=platform --unwindlib=platform \
 // RUN: --sysroot=%S/Inputs/solaris_sparc_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-SPARC32-SHARED %s
 // CHECK-SPARC32-SHARED: "{{.*}}ld{{(.exe)?}}"
@@ -103,7 +109,7 @@
 
 /// Check that -static-libgcc is supported.
 // RUN: %clang -### %s --target=sparc-sun-solaris2.11 \
-// RUN: -static-libgcc \
+// RUN: -static-libgcc -rtlib=platform --unwindlib=platform \
 // RUN: --sysroot=%S/Inputs/solaris_sparc_tree 2>&1 \
 // RUN:   | FileCheck --check-prefixes=CHECK-STATIC-LIBGCC %s
 // CHECK-STATIC-LIBGCC-NOT: warning: argument unused during compilation: 
'-static-libgcc'
@@ -112,15 +118,19 @@
 
 // Check that libm is only linked with clang++.
 // RUN: %clang -### %s --target=sparc-sun-solaris2.11 \
+// RUN: -rtlib=platform --unwindlib=platform \
 // RUN: --sysroot=%S/Inputs/solaris_sparc_tree 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-NOLIBM %s
 // RUN: %clang -### %s -shared --target=sparc-sun-solaris2.11 \
+// RUN: -rtlib=platform --unwindlib=platform \
 // RUN: --sysroot=%S/Inputs/solaris_sparc_tree 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-NOLIBM %s
 // RUN: %clangxx -### %s --target=sparc-sun-solaris2.11 \
+// RUN: -rtlib=platform --unwindlib=platform \
 // RUN: --sysroot=%S/Inputs/solaris_sparc_tree 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-LIBM %s
 // RUN: %clangxx -### %s -shared --target=sparc-sun-solaris2.11 \
+// RUN: -rtlib=platform --unwindlib=platform \
 // RUN: --sysroot=%S/Inputs/solaris_sparc_tree 2>&1 \

[clang] [clang][Driver][test] Fix Driver/solaris-ld.c on non-Unix hosts (PR #138466)

2025-05-04 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Rainer Orth (rorth)


Changes

`Clang :: Driver/solaris-ld.c` currently `FAIL`s on two non-Unix buildbots: 
[fuchsia-x86_64-linux](https://lab.llvm.org/buildbot/#/builders/11/builds/14369)
 and
[llvm-clang-win-x-aarch64](https://lab.llvm.org/buildbot/#/builders/193/builds/7452).

Judging from `linux-ld.c`, all subtests need `-rtlib=platform 
--unwindlib=platform` whenever host and target have different `rtlib` and 
`unwindlib` defaults, which is what this patch does for `solaris-ld.c`, too.

Tested on `amd64-pc-solaris2.11`, `sparcv9-sun-solaris2.11`, and 
`x86_64-pc-linux-gnu`.

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


1 Files Affected:

- (modified) clang/test/Driver/solaris-ld.c (+35-1) 


``diff
diff --git a/clang/test/Driver/solaris-ld.c b/clang/test/Driver/solaris-ld.c
index 9aa7ed760666d..5940ee2add769 100644
--- a/clang/test/Driver/solaris-ld.c
+++ b/clang/test/Driver/solaris-ld.c
@@ -3,9 +3,11 @@
 
 // Check sparc-sun-solaris2.11, 32bit
 // RUN: %clang -### %s --target=sparc-sun-solaris2.11 -fuse-ld= \
+// RUN: -rtlib=platform --unwindlib=platform \
 // RUN: --sysroot=%S/Inputs/solaris_sparc_tree 2>&1 \
 // RUN:   | FileCheck --check-prefixes=CHECK-LD-SPARC32,CHECK-LD %s
 // RUN: %clang -### %s --target=sparc-sun-solaris2.11 -fuse-ld=gld \
+// RUN: -rtlib=platform --unwindlib=platform \
 // RUN: --sysroot=%S/Inputs/solaris_sparc_tree 2>&1 \
 // RUN:   | FileCheck --check-prefixes=CHECK-LD-SPARC32,CHECK-GLD %s
 // CHECK-LD-SPARC32-NOT: warning:
@@ -29,6 +31,7 @@
 
 // Check sparc-sun-solaris2.11, 64bit
 // RUN: %clang -m64 -### %s 2>&1 --target=sparc-sun-solaris2.11 \
+// RUN: -rtlib=platform --unwindlib=platform \
 // RUN: --sysroot=%S/Inputs/solaris_sparc_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-LD-SPARC64 %s
 // CHECK-LD-SPARC64-NOT: warning:
@@ -50,6 +53,7 @@
 
 // Check i386-pc-solaris2.11, 32bit
 // RUN: %clang -### %s 2>&1 --target=i386-pc-solaris2.11 \
+// RUN: -rtlib=platform --unwindlib=platform \
 // RUN: --sysroot=%S/Inputs/solaris_x86_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-LD-X32 %s
 // CHECK-LD-X32-NOT: warning:
@@ -72,6 +76,7 @@
 // Check i386-pc-solaris2.11, 64bit
 // RUN: %clang -m64 -### %s 2>&1 \
 // RUN: --target=i386-pc-solaris2.11 \
+// RUN: -rtlib=platform --unwindlib=platform \
 // RUN: --sysroot=%S/Inputs/solaris_x86_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-LD-X64 %s
 // CHECK-LD-X64-NOT: warning:
@@ -94,6 +99,7 @@
 // Check the right -l flags are present with -shared
 // RUN: %clang -### %s -shared 2>&1 \
 // RUN: --target=sparc-sun-solaris2.11 \
+// RUN: -rtlib=platform --unwindlib=platform \
 // RUN: --sysroot=%S/Inputs/solaris_sparc_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-SPARC32-SHARED %s
 // CHECK-SPARC32-SHARED: "{{.*}}ld{{(.exe)?}}"
@@ -103,7 +109,7 @@
 
 /// Check that -static-libgcc is supported.
 // RUN: %clang -### %s --target=sparc-sun-solaris2.11 \
-// RUN: -static-libgcc \
+// RUN: -static-libgcc -rtlib=platform --unwindlib=platform \
 // RUN: --sysroot=%S/Inputs/solaris_sparc_tree 2>&1 \
 // RUN:   | FileCheck --check-prefixes=CHECK-STATIC-LIBGCC %s
 // CHECK-STATIC-LIBGCC-NOT: warning: argument unused during compilation: 
'-static-libgcc'
@@ -112,15 +118,19 @@
 
 // Check that libm is only linked with clang++.
 // RUN: %clang -### %s --target=sparc-sun-solaris2.11 \
+// RUN: -rtlib=platform --unwindlib=platform \
 // RUN: --sysroot=%S/Inputs/solaris_sparc_tree 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-NOLIBM %s
 // RUN: %clang -### %s -shared --target=sparc-sun-solaris2.11 \
+// RUN: -rtlib=platform --unwindlib=platform \
 // RUN: --sysroot=%S/Inputs/solaris_sparc_tree 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-NOLIBM %s
 // RUN: %clangxx -### %s --target=sparc-sun-solaris2.11 \
+// RUN: -rtlib=platform --unwindlib=platform \
 // RUN: --sysroot=%S/Inputs/solaris_sparc_tree 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-LIBM %s
 // RUN: %clangxx -### %s -shared --target=sparc-sun-solaris2.11 \
+// RUN: -rtlib=platform --unwindlib=platform \
 // RUN: --sysroot=%S/Inputs/solaris_sparc_tree 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-LIBM %s
 // CHECK-LIBM: "-lm"
@@ -128,35 +138,45 @@
 
 // Check the right ld flags are present with -pie.
 // RUN: %clang --target=sparc-sun-solaris2.11 -### %s -pie -fuse-ld= \
+// RUN: -rtlib=platform --unwindlib=platform \
 // RUN: --sysroot=%S/Inputs/solaris_sparc_tree 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-PIE-LD %s
 // RUN: %clang --target=sparc-sun-solaris2.11 -### %s -pie -fuse-ld=gld \
+// RUN: -rtlib=platform --unwindlib=platform \
 // RUN: --sysroot=%S/Inputs/solaris_sparc_tree 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-PIE-GLD %s
 // RUN: %clang --target=sparc-sun-solaris2.11 -### %s -no-pie -fuse-ld= \
+// RUN: -rtlib=p

[clang] [clang-linker-wrapper] Remove unused local variables (NFC) (PR #138480)

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

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`sanitizer-x86_64-linux-android` running on `sanitizer-buildbot-android` while 
building `clang` at step 2 "annotate".

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


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

```
Step 2 (annotate) failure: 'python 
../sanitizer_buildbot/sanitizers/zorg/buildbot/builders/sanitizers/buildbot_selector.py'
 (failure)
...
[   OK ] AddressSanitizer.AtoiAndFriendsOOBTest (2240 ms)
[ RUN  ] AddressSanitizer.HasFeatureAddressSanitizerTest
[   OK ] AddressSanitizer.HasFeatureAddressSanitizerTest (0 ms)
[ RUN  ] AddressSanitizer.CallocReturnsZeroMem
[   OK ] AddressSanitizer.CallocReturnsZeroMem (9 ms)
[ DISABLED ] AddressSanitizer.DISABLED_TSDTest
[ RUN  ] AddressSanitizer.IgnoreTest
[   OK ] AddressSanitizer.IgnoreTest (0 ms)
[ RUN  ] AddressSanitizer.SignalTest
[   OK ] AddressSanitizer.SignalTest (220 ms)
[ RUN  ] AddressSanitizer.ReallocTest
[   OK ] AddressSanitizer.ReallocTest (36 ms)
[ RUN  ] AddressSanitizer.WrongFreeTest
[   OK ] AddressSanitizer.WrongFreeTest (119 ms)
[ RUN  ] AddressSanitizer.LongJmpTest
[   OK ] AddressSanitizer.LongJmpTest (0 ms)
[ RUN  ] AddressSanitizer.ThreadStackReuseTest
[   OK ] AddressSanitizer.ThreadStackReuseTest (8 ms)
[ DISABLED ] AddressSanitizer.DISABLED_MemIntrinsicUnalignedAccessTest
[ DISABLED ] AddressSanitizer.DISABLED_LargeFunctionSymbolizeTest
[ DISABLED ] AddressSanitizer.DISABLED_MallocFreeUnwindAndSymbolizeTest
[ RUN  ] AddressSanitizer.UseThenFreeThenUseTest
[   OK ] AddressSanitizer.UseThenFreeThenUseTest (116 ms)
[ RUN  ] AddressSanitizer.FileNameInGlobalReportTest
[   OK ] AddressSanitizer.FileNameInGlobalReportTest (132 ms)
[ DISABLED ] AddressSanitizer.DISABLED_StressStackReuseAndExceptionsTest
[ RUN  ] AddressSanitizer.MlockTest
[   OK ] AddressSanitizer.MlockTest (0 ms)
[ DISABLED ] AddressSanitizer.DISABLED_DemoThreadedTest
[ DISABLED ] AddressSanitizer.DISABLED_DemoStackTest
[ DISABLED ] AddressSanitizer.DISABLED_DemoThreadStackTest
[ DISABLED ] AddressSanitizer.DISABLED_DemoUAFLowIn
[ DISABLED ] AddressSanitizer.DISABLED_DemoUAFLowLeft
[ DISABLED ] AddressSanitizer.DISABLED_DemoUAFLowRight
[ DISABLED ] AddressSanitizer.DISABLED_DemoUAFHigh
[ DISABLED ] AddressSanitizer.DISABLED_DemoOOM
[ DISABLED ] AddressSanitizer.DISABLED_DemoDoubleFreeTest
[ DISABLED ] AddressSanitizer.DISABLED_DemoNullDerefTest
[ DISABLED ] AddressSanitizer.DISABLED_DemoFunctionStaticTest
[ DISABLED ] AddressSanitizer.DISABLED_DemoTooMuchMemoryTest
[ RUN  ] AddressSanitizer.LongDoubleNegativeTest
[   OK ] AddressSanitizer.LongDoubleNegativeTest (0 ms)
[--] 19 tests from AddressSanitizer (28059 ms total)

[--] Global test environment tear-down
[==] 22 tests from 2 test suites ran. (28085 ms total)
[  PASSED  ] 22 tests.

  YOU HAVE 1 DISABLED TEST

Step 34 (run instrumented asan tests 
[aarch64/bluejay-userdebug/TQ3A.230805.001]) failure: run instrumented asan 
tests [aarch64/bluejay-userdebug/TQ3A.230805.001] (failure)
...
[ RUN  ] AddressSanitizer.HasFeatureAddressSanitizerTest
[   OK ] AddressSanitizer.HasFeatureAddressSanitizerTest (0 ms)
[ RUN  ] AddressSanitizer.CallocReturnsZeroMem
[   OK ] AddressSanitizer.CallocReturnsZeroMem (9 ms)
[ DISABLED ] AddressSanitizer.DISABLED_TSDTest
[ RUN  ] AddressSanitizer.IgnoreTest
[   OK ] AddressSanitizer.IgnoreTest (0 ms)
[ RUN  ] AddressSanitizer.SignalTest
[   OK ] AddressSanitizer.SignalTest (220 ms)
[ RUN  ] AddressSanitizer.ReallocTest
[   OK ] AddressSanitizer.ReallocTest (36 ms)
[ RUN  ] AddressSanitizer.WrongFreeTest
[   OK ] AddressSanitizer.WrongFreeTest (119 ms)
[ RUN  ] AddressSanitizer.LongJmpTest
[   OK ] AddressSanitizer.LongJmpTest (0 ms)
[ RUN  ] AddressSanitizer.ThreadStackReuseTest
[   OK ] AddressSanitizer.ThreadStackReuseTest (8 ms)
[ DISABLED ] AddressSanitizer.DISABLED_MemIntrinsicUnalignedAccessTest
[ DISABLED ] AddressSanitizer.DISABLED_LargeFunctionSymbolizeTest
[ DISABLED ] AddressSanitizer.DISABLED_MallocFreeUnwindAndSymbolizeTest
[ RUN  ] AddressSanitizer.UseThenFreeThenUseTest
[   OK ] AddressSanitizer.UseThenFreeThenUseTest (116 ms)
[ RUN  ] AddressSanitizer.FileNameInGlobalReportTest
[   OK ] AddressSanitizer.FileNameInGlobalReportTest (132 ms)
[ DISABLED ] AddressSanitizer.DISABLED_StressStackReuseAndExceptionsTest
[ RUN  ] AddressSanitizer.MlockTest
[   OK ] AddressSanitizer.MlockTest (0 ms)
[ DISABLED ] AddressSanitizer.DISABLED_DemoThreadedTest
[ DISABLED ] AddressSanitizer.DISABLED_DemoStackTest
[ DISABLED ] AddressSanitizer.DISABLED_DemoThreadStackTest
[ DISABLED ] AddressSanitizer.DISABLED_DemoUAFLowIn
[ DISABLED ] AddressSanitizer.DISABLED_DemoUAFLowLeft
[ DISABLED ] AddressSanitizer.DISABLED_DemoUAFLowRight
[ DISABLED ] Addr

[clang] [Clang] Add `noalias` to `this` pointer in C++ constructors (PR #136792)

2025-05-04 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-hlsl

Author: Guy David (guy-david)


Changes

Note: the patch is probably amending the wrong piece of code, I've tried to add 
it to `buildThisParam` but hit an assertion because of a missing translation 
unit context.

Clang does not transform the following example into a 128-bit load and store:
```c++
class vector4f
{
private:
float _elements[4];
public:
explicit __attribute__((noinline)) vector4f(float const *src)
{
_elements[0] = src[0];
_elements[1] = src[1];
_elements[2] = src[2];
_elements[3] = src[3];
}
};
```
And instead generates 8 memory operations. That's because `src` might overlap 
with `_elements`. However, GCC is able to optimize it for constructors only.

According to the standard in 11.10.4.2 under [class.cdtor]:
> "During the construction of an object, if the value of the object or any 
of its subobjects is accessed through a glvalue that is not obtained, directly 
or indirectly, from the constructor’s this pointer, the value of the object or 
subobject thus obtained is unspecified."

which sounds like `restrict`.

Relevant GCC chain-mail: 
https://gcc.gnu.org/pipermail/gcc-patches/2018-May/498812.html.


---

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


132 Files Affected:

- (modified) clang/lib/CodeGen/CGCall.cpp (+7-2) 
- (modified) clang/test/CodeGen/attr-counted-by-pr88931.cpp (+1-1) 
- (modified) clang/test/CodeGen/attr-noundef.cpp (+152-151) 
- (modified) clang/test/CodeGen/paren-list-agg-init.cpp (+4-4) 
- (modified) clang/test/CodeGen/temporary-lifetime.cpp (+8-8) 
- (modified) clang/test/CodeGenCUDA/offload_via_llvm.cu (+5-5) 
- (modified) clang/test/CodeGenCUDA/record-layout.cu (+10-10) 
- (modified) clang/test/CodeGenCUDA/vtbl.cu (+1-1) 
- (modified) clang/test/CodeGenCXX/LoongArch/abi-lp64d-struct-inherit.cpp 
(+1-1) 
- (modified) clang/test/CodeGenCXX/aix-static-init-temp-spec-and-inline-var.cpp 
(+4-4) 
- (modified) clang/test/CodeGenCXX/amdgcn-automatic-variable.cpp (+1-1) 
- (modified) clang/test/CodeGenCXX/amdgcn-func-arg.cpp (+1-1) 
- (modified) clang/test/CodeGenCXX/atomicinit.cpp (+3-3) 
- (modified) clang/test/CodeGenCXX/bug135668.cpp (+1-1) 
- (modified) clang/test/CodeGenCXX/control-flow-in-stmt-expr.cpp (+2-2) 
- (modified) clang/test/CodeGenCXX/cxx2a-consteval.cpp (+1-1) 
- (modified) clang/test/CodeGenCXX/cxx2b-deducing-this.cpp (+1-1) 
- (modified) clang/test/CodeGenCXX/fcheck-new.cpp (+1-1) 
- (modified) clang/test/CodeGenCXX/for-range.cpp (+8-8) 
- (modified) clang/test/CodeGenCXX/gh62818.cpp (+1-1) 
- (modified) clang/test/CodeGenCXX/ibm128-declarations.cpp (+4-4) 
- (modified) clang/test/CodeGenCXX/init-invariant.cpp (+5-5) 
- (modified) clang/test/CodeGenCXX/matrix-casts.cpp (+2-2) 
- (modified) clang/test/CodeGenCXX/no-elide-constructors.cpp (+1-1) 
- (modified) clang/test/CodeGenCXX/nrvo.cpp (+137-137) 
- (modified) clang/test/CodeGenCXX/pr13396.cpp (+4-4) 
- (modified) clang/test/CodeGenCXX/ptrauth-qualifier-struct.cpp (+2-2) 
- (modified) clang/test/CodeGenCXX/trivial_abi_debuginfo.cpp (+1-1) 
- (modified) clang/test/CodeGenCXX/vtt-address-space.cpp (+12-12) 
- (modified) clang/test/CodeGenCoroutines/coro-suspend-cleanups.cpp (+1-1) 
- (modified) 
clang/test/CodeGenHLSL/builtins/ByteAddressBuffers-constructors.hlsl (+9-9) 
- (modified) clang/test/CodeGenHLSL/builtins/RWBuffer-constructor.hlsl (+9-9) 
- (modified) 
clang/test/CodeGenHLSL/builtins/StructuredBuffers-constructors.hlsl (+9-9) 
- (modified) clang/test/Headers/__clang_hip_cmath.hip (+4-4) 
- (modified) clang/test/OpenMP/amdgcn_sret_ctor.cpp (+3-5) 
- (modified) clang/test/OpenMP/amdgcn_target_global_constructor.cpp (+4-4) 
- (modified) clang/test/OpenMP/distribute_firstprivate_codegen.cpp (+36-36) 
- (modified) clang/test/OpenMP/distribute_lastprivate_codegen.cpp (+44-44) 
- (modified) clang/test/OpenMP/distribute_parallel_for_firstprivate_codegen.cpp 
(+36-36) 
- (modified) clang/test/OpenMP/distribute_parallel_for_lastprivate_codegen.cpp 
(+52-52) 
- (modified) clang/test/OpenMP/distribute_parallel_for_num_threads_codegen.cpp 
(+20-20) 
- (modified) clang/test/OpenMP/distribute_parallel_for_private_codegen.cpp 
(+52-52) 
- (modified) 
clang/test/OpenMP/distribute_parallel_for_simd_firstprivate_codegen.cpp 
(+259-259) 
- (modified) 
clang/test/OpenMP/distribute_parallel_for_simd_lastprivate_codegen.cpp 
(+244-244) 
- (modified) 
clang/test/OpenMP/distribute_parallel_for_simd_num_threads_codegen.cpp 
(+504-504) 
- (modified) clang/test/OpenMP/distribute_parallel_for_simd_private_codegen.cpp 
(+238-238) 
- (modified) clang/test/OpenMP/distribute_private_codegen.cpp (+44-44) 
- (modified) clang/test/OpenMP/distribute_simd_firstprivate_codegen.cpp 
(+168-168) 
- (modified) clang/test/OpenMP/distribute_simd_lastprivate_codegen.cpp 
(+176-176) 
- (modified) clang/test/OpenMP/distribute_simd_private_codegen.cpp (+190-190) 
- (modified

[clang] [clang][Driver][test] Fix Driver/solaris-ld.c on non-Unix hosts (PR #138466)

2025-05-04 Thread Fangrui Song via cfe-commits

MaskRay wrote:

It's not due to non-Unix hosts. It's likely due to these builds setting 
CLANG_DEFAULT_RTLIB and CLANG_DEFAULT_UNWINDLIB.

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


[clang] [clang-format] Don't annotate enum colon as InheritanceColon (PR #138440)

2025-05-04 Thread Björn Schäpers via cfe-commits


@@ -1423,7 +1423,7 @@ class AnnotatingParser {
 Tok->setType(TT_BitFieldColon);
   } else if (Contexts.size() == 1 &&
  !Line.First->isOneOf(tok::kw_enum, tok::kw_case,
-  tok::kw_default)) {
+  tok::kw_default, tok::kw_typedef)) {

HazardyKnusperkeks wrote:

Sadly `typedef class` is a thing too, this would break, wouldn't it?

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


[clang] [Driver] Use AddRunTimeLibs on Solaris (PR #137596)

2025-05-04 Thread Rainer Orth via cfe-commits

rorth wrote:

I've just created PR #138466 which hopefully fixes those failures.  Can anyone 
affected please give this a try?

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


[clang] [clang-format] Add SpaceAfterOperatorKeyword option (PR #137610)

2025-05-04 Thread Filip Milosevic via cfe-commits

https://github.com/MightyFilipns updated 
https://github.com/llvm/llvm-project/pull/137610

>From 2bbc9f699de5e73d899c5d58607ccfe36aa7a7d7 Mon Sep 17 00:00:00 2001
From: MightyFilipns 
Date: Mon, 28 Apr 2025 11:54:20 +0200
Subject: [PATCH] clang-format: Add SpaceAfterOperatorKeyword option

---
 clang/docs/ClangFormatStyleOptions.rst | 10 ++
 clang/docs/ReleaseNotes.rst|  1 +
 clang/include/clang/Format/Format.h|  9 +
 clang/lib/Format/Format.cpp|  3 +++
 clang/lib/Format/TokenAnnotator.cpp|  2 +-
 clang/unittests/Format/ConfigParseTest.cpp |  1 +
 clang/unittests/Format/FormatTest.cpp  |  6 ++
 7 files changed, 31 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index 3f8a5f49313b2..eb67166e822b9 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -6104,6 +6104,16 @@ the configuration (without a prefix: ``Auto``).
  true:  false:
  ! someExpression();vs. !someExpression();
 
+.. _SpaceAfterOperatorKeyword:
+
+**SpaceAfterOperatorKeyword** (``Boolean``) :versionbadge:`clang-format 22` 
:ref:`¶ `
+  If ``true``, a space will be inserted after the ``operator`` keyword.
+
+  .. code-block:: c++
+
+ true:false:
+ bool operator == (int a) vs. bool operator== (int a)
+
 .. _SpaceAfterTemplateKeyword:
 
 **SpaceAfterTemplateKeyword** (``Boolean``) :versionbadge:`clang-format 4` 
:ref:`¶ `
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 3105d8b481560..a058f9b1d1a87 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -695,6 +695,7 @@ clang-format
   top of the file.
 - Add ``EnumTrailingComma`` option for inserting/removing commas at the end of
   ``enum`` enumerator lists.
+- Add ``SpaceAfterOperatorKeyword`` option.
 
 libclang
 
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index f6ceef08b46da..c9557b0c6d65e 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -4463,6 +4463,14 @@ struct FormatStyle {
   /// \version 9
   bool SpaceAfterLogicalNot;
 
+  /// If ``true``, a space will be inserted after the ``operator`` keyword.
+  /// \code
+  ///true:false:
+  ///bool operator ==(int a); vs. bool operator==(int a);
+  /// \endcode
+  /// \version 21
+  bool SpaceAfterOperatorKeyword;
+
   /// If \c true, a space will be inserted after the ``template`` keyword.
   /// \code
   ///true:  false:
@@ -5432,6 +5440,7 @@ struct FormatStyle {
SortJavaStaticImport == R.SortJavaStaticImport &&
SpaceAfterCStyleCast == R.SpaceAfterCStyleCast &&
SpaceAfterLogicalNot == R.SpaceAfterLogicalNot &&
+   SpaceAfterOperatorKeyword == R.SpaceAfterOperatorKeyword &&
SpaceAfterTemplateKeyword == R.SpaceAfterTemplateKeyword &&
SpaceBeforeAssignmentOperators == R.SpaceBeforeAssignmentOperators 
&&
SpaceBeforeCaseColon == R.SpaceBeforeCaseColon &&
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 5a1c3f556b331..fdb26165beee0 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -1151,6 +1151,8 @@ template <> struct MappingTraits {
 IO.mapOptional("SortUsingDeclarations", Style.SortUsingDeclarations);
 IO.mapOptional("SpaceAfterCStyleCast", Style.SpaceAfterCStyleCast);
 IO.mapOptional("SpaceAfterLogicalNot", Style.SpaceAfterLogicalNot);
+IO.mapOptional("SpaceAfterOperatorKeyword",
+   Style.SpaceAfterOperatorKeyword);
 IO.mapOptional("SpaceAfterTemplateKeyword",
Style.SpaceAfterTemplateKeyword);
 IO.mapOptional("SpaceAroundPointerQualifiers",
@@ -1638,6 +1640,7 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind 
Language) {
   LLVMStyle.SortUsingDeclarations = FormatStyle::SUD_LexicographicNumeric;
   LLVMStyle.SpaceAfterCStyleCast = false;
   LLVMStyle.SpaceAfterLogicalNot = false;
+  LLVMStyle.SpaceAfterOperatorKeyword = false;
   LLVMStyle.SpaceAfterTemplateKeyword = true;
   LLVMStyle.SpaceAroundPointerQualifiers = FormatStyle::SAPQ_Default;
   LLVMStyle.SpaceBeforeAssignmentOperators = true;
diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index e56cc92987af7..1c7a0d92fefb3 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -5030,7 +5030,7 @@ bool TokenAnnotator::spaceRequiredBefore(const 
AnnotatedLine &Line,
 }
 
 if (Left.is(tok::kw_operator))
-  return Right.is(tok::coloncolon);
+  return Right.is(tok::coloncolon) || Style.SpaceAfterOperatorKeyword;
 if (Right.is(tok::l_brace) && Right.is(BK_BracedInit) &&
 !L

[clang] [clang][Driver][test] Fix Driver/solaris-ld.c on non-Unix hosts (PR #138466)

2025-05-04 Thread Fangrui Song via cfe-commits

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


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


[clang] [clang-format] Add SpaceAfterOperatorKeyword option (PR #137610)

2025-05-04 Thread Filip Milosevic via cfe-commits

https://github.com/MightyFilipns updated 
https://github.com/llvm/llvm-project/pull/137610

>From aabc71f63914ec58e312fc89f6102919333f0b7f Mon Sep 17 00:00:00 2001
From: MightyFilipns 
Date: Mon, 28 Apr 2025 11:54:20 +0200
Subject: [PATCH] clang-format: Add SpaceAfterOperatorKeyword option

# Conflicts:
#   clang/docs/ReleaseNotes.rst
---
 clang/docs/ClangFormatStyleOptions.rst |  10 ++
 clang/docs/ReleaseNotes.rst| 105 ++---
 clang/include/clang/Format/Format.h|   9 ++
 clang/lib/Format/Format.cpp|   3 +
 clang/lib/Format/TokenAnnotator.cpp|   2 +-
 clang/unittests/Format/ConfigParseTest.cpp |   1 +
 clang/unittests/Format/FormatTest.cpp  |   6 ++
 7 files changed, 38 insertions(+), 98 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index b47291599649d..b1d2e09ddaad1 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -6127,6 +6127,16 @@ the configuration (without a prefix: ``Auto``).
  true:  false:
  ! someExpression();vs. !someExpression();
 
+.. _SpaceAfterOperatorKeyword:
+
+**SpaceAfterOperatorKeyword** (``Boolean``) :versionbadge:`clang-format 22` 
:ref:`¶ `
+  If ``true``, a space will be inserted after the ``operator`` keyword.
+
+  .. code-block:: c++
+
+ true:false:
+ bool operator == (int a) vs. bool operator== (int a)
+
 .. _SpaceAfterTemplateKeyword:
 
 **SpaceAfterTemplateKeyword** (``Boolean``) :versionbadge:`clang-format 4` 
:ref:`¶ `
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 918ff952bb2c3..436d34dd5bb7d 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -134,8 +134,6 @@ Resolutions to C++ Defect Reports
 - Bumped the ``__cpp_constexpr`` feature-test macro to ``202002L`` in C++20 
mode as indicated in
   `P2493R0 `_.
 
-- Implemented `CWG3005 Function parameters should never be name-independent 
`_.
-
 C Language Changes
 --
 
@@ -143,75 +141,15 @@ C Language Changes
   function type in Microsoft compatibility mode. #GH124869
 - Clang now allows ``restrict`` qualifier for array types with pointer 
elements (#GH92847).
 - Clang now diagnoses ``const``-qualified object definitions without an
-  initializer. If the object is a variable or field which is zero-initialized,
-  it will be diagnosed under the new warning ``-Wdefault-const-init-var`` or
-  ``-Wdefault-const-init-field``, respectively. Similarly, if the variable or
-  field is not zero-initialized, it will be diagnosed under the new diagnostic
-  ``-Wdefault-const-init-var-unsafe`` or ``-Wdefault-const-init-field-unsafe``,
-  respectively. The unsafe diagnostic variants are grouped under a new
-  diagnostic ``-Wdefault-const-init-unsafe``, which itself is grouped under the
-  new diagnostic ``-Wdefault-const-init``. Finally, ``-Wdefault-const-init`` is
-  grouped under ``-Wc++-compat`` because these constructs are not compatible
-  with C++. #GH19297
+  initializer. If the object is zero-initialized, it will be diagnosed under
+  the new warning ``-Wdefault-const-init`` (which is grouped under
+  ``-Wc++-compat`` because this construct is not compatible with C++). If the
+  object is left uninitialized, it will be diagnosed unsed the new warning
+  ``-Wdefault-const-init-unsafe`` (which is grouped under
+  ``-Wdefault-const-init``). #GH19297
 - Added ``-Wimplicit-void-ptr-cast``, grouped under ``-Wc++-compat``, which
   diagnoses implicit conversion from ``void *`` to another pointer type as
   being incompatible with C++. (#GH17792)
-- Added ``-Wc++-keyword``, grouped under ``-Wc++-compat``, which diagnoses when
-  a C++ keyword is used as an identifier in C. (#GH21898)
-- Added ``-Wc++-hidden-decl``, grouped under ``-Wc++-compat``, which diagnoses
-  use of tag types which are visible in C but not visible in C++ due to scoping
-  rules. e.g.,
-
-  .. code-block:: c
-
-struct S {
-  struct T {
-int x;
-  } t;
-};
-struct T t; // Invalid C++, valid C, now diagnosed
-- Added ``-Wimplicit-int-enum-cast``, grouped under ``-Wc++-compat``, which
-  diagnoses implicit conversion from integer types to an enumeration type in C,
-  which is not compatible with C++. #GH37027
-- Split "implicit conversion from enum type to different enum type" diagnostic
-  from ``-Wenum-conversion`` into its own diagnostic group,
-  ``-Wimplicit-enum-enum-cast``, which is grouped under both
-  ``-Wenum-conversion`` and ``-Wimplicit-int-enum-cast``. This conversion is an
-  int-to-enum conversion because the enumeration on the right-hand side is
-  promoted to ``int`` before the assignment.
-- Added ``-Wtentative-definition-compat``, grouped under ``-Wc++-compat``,
-  which diagnoses tentative definitions in C with mul

[clang] [clang-format] Add SpaceAfterOperatorKeyword option (PR #137610)

2025-05-04 Thread Filip Milosevic via cfe-commits

https://github.com/MightyFilipns updated 
https://github.com/llvm/llvm-project/pull/137610

>From 601985f75cf961f585a3d232868eda3a400878fc Mon Sep 17 00:00:00 2001
From: MightyFilipns 
Date: Mon, 28 Apr 2025 11:54:20 +0200
Subject: [PATCH] clang-format: Add SpaceAfterOperatorKeyword option

---
 clang/docs/ClangFormatStyleOptions.rst | 10 ++
 clang/docs/ReleaseNotes.rst|  3 ++-
 clang/include/clang/Format/Format.h|  9 +
 clang/lib/Format/Format.cpp|  3 +++
 clang/lib/Format/TokenAnnotator.cpp|  2 +-
 clang/unittests/Format/ConfigParseTest.cpp |  1 +
 clang/unittests/Format/FormatTest.cpp  |  6 ++
 7 files changed, 32 insertions(+), 2 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index b47291599649d..b1d2e09ddaad1 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -6127,6 +6127,16 @@ the configuration (without a prefix: ``Auto``).
  true:  false:
  ! someExpression();vs. !someExpression();
 
+.. _SpaceAfterOperatorKeyword:
+
+**SpaceAfterOperatorKeyword** (``Boolean``) :versionbadge:`clang-format 22` 
:ref:`¶ `
+  If ``true``, a space will be inserted after the ``operator`` keyword.
+
+  .. code-block:: c++
+
+ true:false:
+ bool operator == (int a) vs. bool operator== (int a)
+
 .. _SpaceAfterTemplateKeyword:
 
 **SpaceAfterTemplateKeyword** (``Boolean``) :versionbadge:`clang-format 4` 
:ref:`¶ `
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 918ff952bb2c3..e08b52c355387 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -786,6 +786,7 @@ clang-format
 - Add ``EnumTrailingComma`` option for inserting/removing commas at the end of
   ``enum`` enumerator lists.
 - Add ``OneLineFormatOffRegex`` option for turning formatting off for one line.
+- Add ``SpaceAfterOperatorKeyword`` option.
 
 libclang
 
@@ -876,4 +877,4 @@ tree.
 
 If you have any questions or comments about Clang, please feel free to
 contact us on the `Discourse forums (Clang Frontend category)
-`_.
+`_.
\ No newline at end of file
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 7fe41d800ccb3..b86c4bd00eb91 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -4484,6 +4484,14 @@ struct FormatStyle {
   /// \version 9
   bool SpaceAfterLogicalNot;
 
+  /// If ``true``, a space will be inserted after the ``operator`` keyword.
+  /// \code
+  ///true:false:
+  ///bool operator ==(int a); vs. bool operator==(int a);
+  /// \endcode
+  /// \version 21
+  bool SpaceAfterOperatorKeyword;
+
   /// If \c true, a space will be inserted after the ``template`` keyword.
   /// \code
   ///true:  false:
@@ -5454,6 +5462,7 @@ struct FormatStyle {
SortJavaStaticImport == R.SortJavaStaticImport &&
SpaceAfterCStyleCast == R.SpaceAfterCStyleCast &&
SpaceAfterLogicalNot == R.SpaceAfterLogicalNot &&
+   SpaceAfterOperatorKeyword == R.SpaceAfterOperatorKeyword &&
SpaceAfterTemplateKeyword == R.SpaceAfterTemplateKeyword &&
SpaceBeforeAssignmentOperators == R.SpaceBeforeAssignmentOperators 
&&
SpaceBeforeCaseColon == R.SpaceBeforeCaseColon &&
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 2f4b64ef4f5fe..20b5352b83a9e 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -1152,6 +1152,8 @@ template <> struct MappingTraits {
 IO.mapOptional("SortUsingDeclarations", Style.SortUsingDeclarations);
 IO.mapOptional("SpaceAfterCStyleCast", Style.SpaceAfterCStyleCast);
 IO.mapOptional("SpaceAfterLogicalNot", Style.SpaceAfterLogicalNot);
+IO.mapOptional("SpaceAfterOperatorKeyword",
+   Style.SpaceAfterOperatorKeyword);
 IO.mapOptional("SpaceAfterTemplateKeyword",
Style.SpaceAfterTemplateKeyword);
 IO.mapOptional("SpaceAroundPointerQualifiers",
@@ -1639,6 +1641,7 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind 
Language) {
   LLVMStyle.SortUsingDeclarations = FormatStyle::SUD_LexicographicNumeric;
   LLVMStyle.SpaceAfterCStyleCast = false;
   LLVMStyle.SpaceAfterLogicalNot = false;
+  LLVMStyle.SpaceAfterOperatorKeyword = false;
   LLVMStyle.SpaceAfterTemplateKeyword = true;
   LLVMStyle.SpaceAroundPointerQualifiers = FormatStyle::SAPQ_Default;
   LLVMStyle.SpaceBeforeAssignmentOperators = true;
diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index caf386cffd25b..50a22149f7bd9 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/Toke

[clang] [clang][Driver][test] Fix Driver/solaris-ld.c on non-Unix hosts (PR #138466)

2025-05-04 Thread Rainer Orth via cfe-commits

rorth wrote:

> It's not due to non-Unix hosts. It's likely due to these builds setting 
> CLANG_DEFAULT_RTLIB and CLANG_DEFAULT_UNWINDLIB.

That occured to me shortly after I created the PR.  I'll fix the description 
accordingly.

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


[clang] 142f99a - [clang][Driver][test] Fix Driver/solaris-ld.c (#138466)

2025-05-04 Thread via cfe-commits

Author: Rainer Orth
Date: 2025-05-04T21:44:56+02:00
New Revision: 142f99ad645f9e77dd5adb470e41c55ce6d37b2b

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

LOG: [clang][Driver][test] Fix Driver/solaris-ld.c (#138466)

`Clang :: Driver/solaris-ld.c` currently `FAIL`s on two buildbots:
[fuchsia-x86_64-linux](https://lab.llvm.org/buildbot/#/builders/11/builds/14369)
and

[llvm-clang-win-x-aarch64](https://lab.llvm.org/buildbot/#/builders/193/builds/7452).

Judging from `linux-ld.c`, all subtests need `-rtlib=platform
--unwindlib=platform` whenever host and target have different `rtlib`
and `unwindlib` defaults, which is what this patch does for
`solaris-ld.c`, too.

Tested on `amd64-pc-solaris2.11`, `sparcv9-sun-solaris2.11`, and
`x86_64-pc-linux-gnu`.

Added: 


Modified: 
clang/test/Driver/solaris-ld.c

Removed: 




diff  --git a/clang/test/Driver/solaris-ld.c b/clang/test/Driver/solaris-ld.c
index 9aa7ed760666d..5940ee2add769 100644
--- a/clang/test/Driver/solaris-ld.c
+++ b/clang/test/Driver/solaris-ld.c
@@ -3,9 +3,11 @@
 
 // Check sparc-sun-solaris2.11, 32bit
 // RUN: %clang -### %s --target=sparc-sun-solaris2.11 -fuse-ld= \
+// RUN: -rtlib=platform --unwindlib=platform \
 // RUN: --sysroot=%S/Inputs/solaris_sparc_tree 2>&1 \
 // RUN:   | FileCheck --check-prefixes=CHECK-LD-SPARC32,CHECK-LD %s
 // RUN: %clang -### %s --target=sparc-sun-solaris2.11 -fuse-ld=gld \
+// RUN: -rtlib=platform --unwindlib=platform \
 // RUN: --sysroot=%S/Inputs/solaris_sparc_tree 2>&1 \
 // RUN:   | FileCheck --check-prefixes=CHECK-LD-SPARC32,CHECK-GLD %s
 // CHECK-LD-SPARC32-NOT: warning:
@@ -29,6 +31,7 @@
 
 // Check sparc-sun-solaris2.11, 64bit
 // RUN: %clang -m64 -### %s 2>&1 --target=sparc-sun-solaris2.11 \
+// RUN: -rtlib=platform --unwindlib=platform \
 // RUN: --sysroot=%S/Inputs/solaris_sparc_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-LD-SPARC64 %s
 // CHECK-LD-SPARC64-NOT: warning:
@@ -50,6 +53,7 @@
 
 // Check i386-pc-solaris2.11, 32bit
 // RUN: %clang -### %s 2>&1 --target=i386-pc-solaris2.11 \
+// RUN: -rtlib=platform --unwindlib=platform \
 // RUN: --sysroot=%S/Inputs/solaris_x86_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-LD-X32 %s
 // CHECK-LD-X32-NOT: warning:
@@ -72,6 +76,7 @@
 // Check i386-pc-solaris2.11, 64bit
 // RUN: %clang -m64 -### %s 2>&1 \
 // RUN: --target=i386-pc-solaris2.11 \
+// RUN: -rtlib=platform --unwindlib=platform \
 // RUN: --sysroot=%S/Inputs/solaris_x86_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-LD-X64 %s
 // CHECK-LD-X64-NOT: warning:
@@ -94,6 +99,7 @@
 // Check the right -l flags are present with -shared
 // RUN: %clang -### %s -shared 2>&1 \
 // RUN: --target=sparc-sun-solaris2.11 \
+// RUN: -rtlib=platform --unwindlib=platform \
 // RUN: --sysroot=%S/Inputs/solaris_sparc_tree \
 // RUN:   | FileCheck --check-prefix=CHECK-SPARC32-SHARED %s
 // CHECK-SPARC32-SHARED: "{{.*}}ld{{(.exe)?}}"
@@ -103,7 +109,7 @@
 
 /// Check that -static-libgcc is supported.
 // RUN: %clang -### %s --target=sparc-sun-solaris2.11 \
-// RUN: -static-libgcc \
+// RUN: -static-libgcc -rtlib=platform --unwindlib=platform \
 // RUN: --sysroot=%S/Inputs/solaris_sparc_tree 2>&1 \
 // RUN:   | FileCheck --check-prefixes=CHECK-STATIC-LIBGCC %s
 // CHECK-STATIC-LIBGCC-NOT: warning: argument unused during compilation: 
'-static-libgcc'
@@ -112,15 +118,19 @@
 
 // Check that libm is only linked with clang++.
 // RUN: %clang -### %s --target=sparc-sun-solaris2.11 \
+// RUN: -rtlib=platform --unwindlib=platform \
 // RUN: --sysroot=%S/Inputs/solaris_sparc_tree 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-NOLIBM %s
 // RUN: %clang -### %s -shared --target=sparc-sun-solaris2.11 \
+// RUN: -rtlib=platform --unwindlib=platform \
 // RUN: --sysroot=%S/Inputs/solaris_sparc_tree 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-NOLIBM %s
 // RUN: %clangxx -### %s --target=sparc-sun-solaris2.11 \
+// RUN: -rtlib=platform --unwindlib=platform \
 // RUN: --sysroot=%S/Inputs/solaris_sparc_tree 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-LIBM %s
 // RUN: %clangxx -### %s -shared --target=sparc-sun-solaris2.11 \
+// RUN: -rtlib=platform --unwindlib=platform \
 // RUN: --sysroot=%S/Inputs/solaris_sparc_tree 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-LIBM %s
 // CHECK-LIBM: "-lm"
@@ -128,35 +138,45 @@
 
 // Check the right ld flags are present with -pie.
 // RUN: %clang --target=sparc-sun-solaris2.11 -### %s -pie -fuse-ld= \
+// RUN: -rtlib=platform --unwindlib=platform \
 // RUN: --sysroot=%S/Inputs/solaris_sparc_tree 2>&1 \
 // RUN:   | FileCheck --check-prefix=CHECK-PIE-LD %s
 // RUN: %clang --target=sparc-sun-solaris2.11 -### %s -pie -fuse-ld=gld \
+/

[clang] [clang][Driver][test] Fix Driver/solaris-ld.c on non-Unix hosts (PR #138466)

2025-05-04 Thread Rainer Orth via cfe-commits

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


[clang] [clang-format] Add SpaceAfterOperatorKeyword option (PR #137610)

2025-05-04 Thread Filip Milosevic via cfe-commits

https://github.com/MightyFilipns updated 
https://github.com/llvm/llvm-project/pull/137610

>From d18481a5535c64267bd00c84252a81d9dc6baecd Mon Sep 17 00:00:00 2001
From: MightyFilipns 
Date: Mon, 28 Apr 2025 11:54:20 +0200
Subject: [PATCH] clang-format: Add SpaceAfterOperatorKeyword option

---
 clang/docs/ClangFormatStyleOptions.rst | 10 ++
 clang/docs/ReleaseNotes.rst|  3 ++-
 clang/include/clang/Format/Format.h|  9 +
 clang/lib/Format/Format.cpp|  3 +++
 clang/lib/Format/TokenAnnotator.cpp|  2 +-
 clang/unittests/Format/ConfigParseTest.cpp |  1 +
 clang/unittests/Format/FormatTest.cpp  |  6 ++
 7 files changed, 32 insertions(+), 2 deletions(-)

diff --git a/clang/docs/ClangFormatStyleOptions.rst 
b/clang/docs/ClangFormatStyleOptions.rst
index b47291599649d..b1d2e09ddaad1 100644
--- a/clang/docs/ClangFormatStyleOptions.rst
+++ b/clang/docs/ClangFormatStyleOptions.rst
@@ -6127,6 +6127,16 @@ the configuration (without a prefix: ``Auto``).
  true:  false:
  ! someExpression();vs. !someExpression();
 
+.. _SpaceAfterOperatorKeyword:
+
+**SpaceAfterOperatorKeyword** (``Boolean``) :versionbadge:`clang-format 22` 
:ref:`¶ `
+  If ``true``, a space will be inserted after the ``operator`` keyword.
+
+  .. code-block:: c++
+
+ true:false:
+ bool operator == (int a) vs. bool operator== (int a)
+
 .. _SpaceAfterTemplateKeyword:
 
 **SpaceAfterTemplateKeyword** (``Boolean``) :versionbadge:`clang-format 4` 
:ref:`¶ `
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 918ff952bb2c3..e08b52c355387 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -786,6 +786,7 @@ clang-format
 - Add ``EnumTrailingComma`` option for inserting/removing commas at the end of
   ``enum`` enumerator lists.
 - Add ``OneLineFormatOffRegex`` option for turning formatting off for one line.
+- Add ``SpaceAfterOperatorKeyword`` option.
 
 libclang
 
@@ -876,4 +877,4 @@ tree.
 
 If you have any questions or comments about Clang, please feel free to
 contact us on the `Discourse forums (Clang Frontend category)
-`_.
+`_.
\ No newline at end of file
diff --git a/clang/include/clang/Format/Format.h 
b/clang/include/clang/Format/Format.h
index 7fe41d800ccb3..b86c4bd00eb91 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -4484,6 +4484,14 @@ struct FormatStyle {
   /// \version 9
   bool SpaceAfterLogicalNot;
 
+  /// If ``true``, a space will be inserted after the ``operator`` keyword.
+  /// \code
+  ///true:false:
+  ///bool operator ==(int a); vs. bool operator==(int a);
+  /// \endcode
+  /// \version 21
+  bool SpaceAfterOperatorKeyword;
+
   /// If \c true, a space will be inserted after the ``template`` keyword.
   /// \code
   ///true:  false:
@@ -5454,6 +5462,7 @@ struct FormatStyle {
SortJavaStaticImport == R.SortJavaStaticImport &&
SpaceAfterCStyleCast == R.SpaceAfterCStyleCast &&
SpaceAfterLogicalNot == R.SpaceAfterLogicalNot &&
+   SpaceAfterOperatorKeyword == R.SpaceAfterOperatorKeyword &&
SpaceAfterTemplateKeyword == R.SpaceAfterTemplateKeyword &&
SpaceBeforeAssignmentOperators == R.SpaceBeforeAssignmentOperators 
&&
SpaceBeforeCaseColon == R.SpaceBeforeCaseColon &&
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index 2f4b64ef4f5fe..20b5352b83a9e 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -1152,6 +1152,8 @@ template <> struct MappingTraits {
 IO.mapOptional("SortUsingDeclarations", Style.SortUsingDeclarations);
 IO.mapOptional("SpaceAfterCStyleCast", Style.SpaceAfterCStyleCast);
 IO.mapOptional("SpaceAfterLogicalNot", Style.SpaceAfterLogicalNot);
+IO.mapOptional("SpaceAfterOperatorKeyword",
+   Style.SpaceAfterOperatorKeyword);
 IO.mapOptional("SpaceAfterTemplateKeyword",
Style.SpaceAfterTemplateKeyword);
 IO.mapOptional("SpaceAroundPointerQualifiers",
@@ -1639,6 +1641,7 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind 
Language) {
   LLVMStyle.SortUsingDeclarations = FormatStyle::SUD_LexicographicNumeric;
   LLVMStyle.SpaceAfterCStyleCast = false;
   LLVMStyle.SpaceAfterLogicalNot = false;
+  LLVMStyle.SpaceAfterOperatorKeyword = false;
   LLVMStyle.SpaceAfterTemplateKeyword = true;
   LLVMStyle.SpaceAroundPointerQualifiers = FormatStyle::SAPQ_Default;
   LLVMStyle.SpaceBeforeAssignmentOperators = true;
diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index caf386cffd25b..50a22149f7bd9 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/Toke

[clang] [clang] Use *(Set|Map)::contains (NFC) (PR #138464)

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

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


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


[clang] [clang] Add support for Debian 14 Forky and Debian 15 Duke (PR #138460)

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

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder 
`llvm-clang-x86_64-gcc-ubuntu` running on `sie-linux-worker3` while building 
`clang` at step 6 "test-build-unified-tree-check-all".

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


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

```
Step 6 (test-build-unified-tree-check-all) failure: test (failure)
...
PASS: lit :: allow-retries.py (89893 of 89902)
PASS: lit :: discovery.py (89894 of 89902)
PASS: lit :: shtest-external-shell-kill.py (89895 of 89902)
PASS: lit :: googletest-timeout.py (89896 of 89902)
PASS: lit :: selecting.py (89897 of 89902)
PASS: lit :: shtest-timeout.py (89898 of 89902)
PASS: lit :: max-time.py (89899 of 89902)
PASS: lit :: shtest-shell.py (89900 of 89902)
PASS: lit :: shtest-define.py (89901 of 89902)
TIMEOUT: AddressSanitizer-x86_64-linux-dynamic :: 
TestCases/asan_lsan_deadlock.cpp (89902 of 89902)
 TEST 'AddressSanitizer-x86_64-linux-dynamic :: 
TestCases/asan_lsan_deadlock.cpp' FAILED 
Exit Code: -9
Timeout: Reached timeout of 900 seconds

Command Output (stderr):
--
/home/buildbot/buildbot-root/llvm-clang-x86_64-gcc-ubuntu/build/./bin/clang  
--driver-mode=g++ -fsanitize=address -mno-omit-leaf-frame-pointer 
-fno-omit-frame-pointer -fno-optimize-sibling-calls -gline-tables-only  -m64  
-shared-libasan -O0 
/home/buildbot/buildbot-root/llvm-clang-x86_64-gcc-ubuntu/llvm-project/compiler-rt/test/asan/TestCases/asan_lsan_deadlock.cpp
 -o 
/home/buildbot/buildbot-root/llvm-clang-x86_64-gcc-ubuntu/build/runtimes/runtimes-bins/compiler-rt/test/asan/X86_64LinuxDynamicConfig/TestCases/Output/asan_lsan_deadlock.cpp.tmp
 # RUN: at line 4
+ /home/buildbot/buildbot-root/llvm-clang-x86_64-gcc-ubuntu/build/./bin/clang 
--driver-mode=g++ -fsanitize=address -mno-omit-leaf-frame-pointer 
-fno-omit-frame-pointer -fno-optimize-sibling-calls -gline-tables-only -m64 
-shared-libasan -O0 
/home/buildbot/buildbot-root/llvm-clang-x86_64-gcc-ubuntu/llvm-project/compiler-rt/test/asan/TestCases/asan_lsan_deadlock.cpp
 -o 
/home/buildbot/buildbot-root/llvm-clang-x86_64-gcc-ubuntu/build/runtimes/runtimes-bins/compiler-rt/test/asan/X86_64LinuxDynamicConfig/TestCases/Output/asan_lsan_deadlock.cpp.tmp
env ASAN_OPTIONS=detect_leaks=1 not  
/home/buildbot/buildbot-root/llvm-clang-x86_64-gcc-ubuntu/build/runtimes/runtimes-bins/compiler-rt/test/asan/X86_64LinuxDynamicConfig/TestCases/Output/asan_lsan_deadlock.cpp.tmp
 2>&1 | FileCheck 
/home/buildbot/buildbot-root/llvm-clang-x86_64-gcc-ubuntu/llvm-project/compiler-rt/test/asan/TestCases/asan_lsan_deadlock.cpp
 # RUN: at line 5
+ env ASAN_OPTIONS=detect_leaks=1 not 
/home/buildbot/buildbot-root/llvm-clang-x86_64-gcc-ubuntu/build/runtimes/runtimes-bins/compiler-rt/test/asan/X86_64LinuxDynamicConfig/TestCases/Output/asan_lsan_deadlock.cpp.tmp
+ FileCheck 
/home/buildbot/buildbot-root/llvm-clang-x86_64-gcc-ubuntu/llvm-project/compiler-rt/test/asan/TestCases/asan_lsan_deadlock.cpp

--



Timed Out Tests (1):
  AddressSanitizer-x86_64-linux-dynamic :: TestCases/asan_lsan_deadlock.cpp


Testing Time: 1169.99s

Total Discovered Tests: 124386
  Skipped  : 38 (0.03%)
  Unsupported  :   2646 (2.13%)
  Passed   : 121410 (97.61%)
  Expectedly Failed:291 (0.23%)
  Timed Out:  1 (0.00%)
FAILED: CMakeFiles/check-all 
/home/buildbot/buildbot-root/llvm-clang-x86_64-gcc-ubuntu/build/CMakeFiles/check-all
 
cd /home/buildbot/buildbot-root/llvm-clang-x86_64-gcc-ubuntu/build && 
/usr/bin/python3.8 
/home/buildbot/buildbot-root/llvm-clang-x86_64-gcc-ubuntu/build/./bin/llvm-lit 
--verbose --timeout=900 --param USE_Z3_SOLVER=0 
/home/buildbot/buildbot-root/llvm-clang-x86_64-gcc-ubuntu/build/utils/mlgo-utils
 
/home/buildbot/buildbot-root/llvm-clang-x86_64-gcc-ubuntu/build/projects/cross-project-tests
 /home/buildbot/buildbot-root/llvm-clang-x86_64-gcc-ubuntu/build/tools/lld/test 
/home/buildbot/buildbot-root/llvm-clang-x86_64-gcc-ubuntu/build/tools/clang/tools/extra/include-cleaner/test
 
/home/buildbot/buildbot-root/llvm-clang-x86_64-gcc-ubuntu/build/tools/clang/tools/extra/test
 
/home/buildbot/buildbot-root/llvm-clang-x86_64-gcc-ubuntu/build/tools/clang/test
 
@/home/buildbot/buildbot-root/llvm-clang-x86_64-gcc-ubuntu/build/runtimes/runtimes-bins/lit.tests
 /home/buildbot/buildbot-root/llvm-clang-x86_64-gcc-ubuntu/build/utils/lit 
/home/buildbot/buildbot-root/llvm-clang-x86_64-gcc-ubuntu/build/test
ninja: build stopped: subcommand failed.

```



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


[clang] [clang] Use *(Set|Map)::contains (NFC) (PR #138464)

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

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


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


[clang] [clang-linker-wrapper] Remove unused local variables (NFC) (PR #138480)

2025-05-04 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Kazu Hirata (kazutakahirata)


Changes



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


1 Files Affected:

- (modified) clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp (-5) 


``diff
diff --git a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp 
b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
index bdeaa2031d184..63f6e641d8c9e 100644
--- a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -418,9 +418,6 @@ fatbinary(ArrayRef> 
InputFiles,
   if (!OffloadBundlerPath)
 return OffloadBundlerPath.takeError();
 
-  llvm::Triple Triple(
-  Args.getLastArgValue(OPT_host_triple_EQ, sys::getDefaultTargetTriple()));
-
   // Create a new file to write the linked device image to.
   auto TempFileOrErr =
   createOutputFile(sys::path::filename(ExecutableName), "hipfb");
@@ -758,7 +755,6 @@ bundleCuda(ArrayRef Images, const ArgList 
&Args) {
 InputFiles.emplace_back(std::make_pair(Image.Image->getBufferIdentifier(),
Image.StringData.lookup("arch")));
 
-  Triple TheTriple = Triple(Images.front().StringData.lookup("triple"));
   auto FileOrErr = nvptx::fatbinary(InputFiles, Args);
   if (!FileOrErr)
 return FileOrErr.takeError();
@@ -781,7 +777,6 @@ bundleHIP(ArrayRef Images, const ArgList 
&Args) {
 InputFiles.emplace_back(std::make_pair(Image.Image->getBufferIdentifier(),
Image.StringData.lookup("arch")));
 
-  Triple TheTriple = Triple(Images.front().StringData.lookup("triple"));
   auto FileOrErr = amdgcn::fatbinary(InputFiles, Args);
   if (!FileOrErr)
 return FileOrErr.takeError();

``




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


[clang] [clang-linker-wrapper] Remove unused local variables (NFC) (PR #138480)

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

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


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


[clang] [clang-linker-wrapper] Remove unused local variables (NFC) (PR #138480)

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

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

None

>From fb19c7799d3ac769eb75d9fee0a3a8b7827d1908 Mon Sep 17 00:00:00 2001
From: Kazu Hirata 
Date: Sun, 4 May 2025 19:13:57 -0700
Subject: [PATCH] [clang-linker-wrapper] Remove unused local variables (NFC)

---
 clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp | 5 -
 1 file changed, 5 deletions(-)

diff --git a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp 
b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
index bdeaa2031d184..63f6e641d8c9e 100644
--- a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -418,9 +418,6 @@ fatbinary(ArrayRef> 
InputFiles,
   if (!OffloadBundlerPath)
 return OffloadBundlerPath.takeError();
 
-  llvm::Triple Triple(
-  Args.getLastArgValue(OPT_host_triple_EQ, sys::getDefaultTargetTriple()));
-
   // Create a new file to write the linked device image to.
   auto TempFileOrErr =
   createOutputFile(sys::path::filename(ExecutableName), "hipfb");
@@ -758,7 +755,6 @@ bundleCuda(ArrayRef Images, const ArgList 
&Args) {
 InputFiles.emplace_back(std::make_pair(Image.Image->getBufferIdentifier(),
Image.StringData.lookup("arch")));
 
-  Triple TheTriple = Triple(Images.front().StringData.lookup("triple"));
   auto FileOrErr = nvptx::fatbinary(InputFiles, Args);
   if (!FileOrErr)
 return FileOrErr.takeError();
@@ -781,7 +777,6 @@ bundleHIP(ArrayRef Images, const ArgList 
&Args) {
 InputFiles.emplace_back(std::make_pair(Image.Image->getBufferIdentifier(),
Image.StringData.lookup("arch")));
 
-  Triple TheTriple = Triple(Images.front().StringData.lookup("triple"));
   auto FileOrErr = amdgcn::fatbinary(InputFiles, Args);
   if (!FileOrErr)
 return FileOrErr.takeError();

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


[clang] [clang] Warn about deprecated volatile-qualified return types (PR #137899)

2025-05-04 Thread via cfe-commits


@@ -5056,13 +5056,13 @@ static TypeSourceInfo 
*GetFullTypeForDeclarator(TypeProcessingState &state,
   S.Diag(DeclType.Loc, diag::err_func_returning_qualified_void) << T;
 } else
   diagnoseRedundantReturnTypeQualifiers(S, T, D, chunkIndex);
-
-// C++2a [dcl.fct]p12:
-//   A volatile-qualified return type is deprecated
-if (T.isVolatileQualified() && S.getLangOpts().CPlusPlus20)
-  S.Diag(DeclType.Loc, diag::warn_deprecated_volatile_return) << T;
   }
 
+  // C++2a [dcl.fct]p12:
+  //   A volatile-qualified return type is deprecated
+  if (T.isVolatileQualified() && S.getLangOpts().CPlusPlus20)
+S.Diag(DeclType.Loc, diag::warn_deprecated_volatile_return) << T;

halbi2 wrote:

I understand that `CheckFunctionReturnType` is used when checking the type of a 
function like `using T = volatile int();` but this codepath here is used when 
checking a function declaration instead.

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


[clang] [clang] Warn about deprecated volatile-qualified return types (PR #137899)

2025-05-04 Thread via cfe-commits


@@ -231,6 +231,13 @@ namespace DeprecatedVolatile {
 a = c = a;
 b += a;
   }
+
+  volatile struct amber jurassic();

halbi2 wrote:

Lines 207-215 are that, are they not?

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


[clang] [clang-format] Add SpaceAfterOperatorKeyword option (PR #137610)

2025-05-04 Thread Filip Milosevic via cfe-commits


@@ -17630,6 +17630,10 @@ TEST_F(FormatTest, ConfigurableSpaceBeforeParens) {
   verifyFormat("int x = int (y);", SomeSpace2);
   verifyFormat("auto lambda = []() { return 0; };", SomeSpace2);
 
+  FormatStyle SpaceAfterOperatorKeyword = getLLVMStyle();
+  SpaceAfterOperatorKeyword.SpaceAfterOperatorKeyword = true;
+  verifyFormat("bool operator ++(int a)", SpaceAfterOperatorKeyword);

MightyFilipns wrote:

I have moved this into a separate TEST_F

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


[clang] [clang-format] Add SpaceAfterOperatorKeyword option (PR #137610)

2025-05-04 Thread Filip Milosevic via cfe-commits


@@ -17630,6 +17630,10 @@ TEST_F(FormatTest, ConfigurableSpaceBeforeParens) {
   verifyFormat("int x = int (y);", SomeSpace2);
   verifyFormat("auto lambda = []() { return 0; };", SomeSpace2);
 
+  FormatStyle SpaceAfterOperatorKeyword = getLLVMStyle();
+  SpaceAfterOperatorKeyword.SpaceAfterOperatorKeyword = true;
+  verifyFormat("bool operator ++(int a)", SpaceAfterOperatorKeyword);

MightyFilipns wrote:

Fixed

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


[clang] [clang-format] Add SpaceAfterOperatorKeyword option (PR #137610)

2025-05-04 Thread Filip Milosevic via cfe-commits


@@ -17630,6 +17630,10 @@ TEST_F(FormatTest, ConfigurableSpaceBeforeParens) {
   verifyFormat("int x = int (y);", SomeSpace2);
   verifyFormat("auto lambda = []() { return 0; };", SomeSpace2);
 
+  FormatStyle SpaceAfterOperatorKeyword = getLLVMStyle();

MightyFilipns wrote:

Fixed

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


[clang] [clang] Remove unused local variables (NFC) (PR #138468)

2025-05-04 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Kazu Hirata (kazutakahirata)


Changes



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


7 Files Affected:

- (modified) 
clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h 
(-2) 
- (modified) clang/lib/Sema/SemaPPC.cpp (-1) 
- (modified) clang/lib/Sema/SemaTemplateDeduction.cpp (-2) 
- (modified) clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp 
(-2) 
- (modified) clang/lib/StaticAnalyzer/Core/BugReporter.cpp (-2) 
- (modified) clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp (+1-1) 
- (modified) clang/unittests/Tooling/CompilationDatabaseTest.cpp (-1) 


``diff
diff --git 
a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h
index e084a13995306..d4052ef90de6e 100644
--- 
a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h
+++ 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h
@@ -324,8 +324,6 @@ class SMTConstraintManager : public 
clang::ento::SimpleConstraintManager {
 
 // Construct the logical AND of all the constraints
 if (I != IE) {
-  std::vector ASTs;
-
   llvm::SMTExprRef Constraint = I++->second;
   while (I != IE) {
 Constraint = Solver->mkAnd(Constraint, I++->second);
diff --git a/clang/lib/Sema/SemaPPC.cpp b/clang/lib/Sema/SemaPPC.cpp
index b6802d6890ed1..9b4d82745f881 100644
--- a/clang/lib/Sema/SemaPPC.cpp
+++ b/clang/lib/Sema/SemaPPC.cpp
@@ -98,7 +98,6 @@ bool SemaPPC::CheckPPCBuiltinFunctionCall(const TargetInfo 
&TI,
   CallExpr *TheCall) {
   ASTContext &Context = getASTContext();
   bool IsTarget64Bit = TI.getTypeWidth(TI.getIntPtrType()) == 64;
-  llvm::APSInt Result;
 
   if (isPPC_64Builtin(BuiltinID) && !IsTarget64Bit)
 return Diag(TheCall->getBeginLoc(), diag::err_64_bit_builtin_32_bit_tgt)
diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 
b/clang/lib/Sema/SemaTemplateDeduction.cpp
index 0ecdbb3ffb89f..c9de36383d334 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -6605,8 +6605,6 @@ bool 
Sema::isTemplateTemplateParameterAtLeastAsSpecializedAs(
 llvm_unreachable("Unexpected Result");
   }
 
-  SmallVector DeducedArgs(Deduced.begin(), Deduced.end());
-
   TemplateDeductionResult TDK;
   runWithSufficientStackSpace(Info.getLocation(), [&] {
 TDK = ::FinishTemplateArgumentDeduction(
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
index 0f0184c472f36..4ddd11495f534 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
@@ -370,8 +370,6 @@ std::optional isUnsafePtr(const QualType T, bool 
IsArcEnabled) {
 std::optional isGetterOfSafePtr(const CXXMethodDecl *M) {
   assert(M);
 
-  std::optional RTC;
-
   if (isa(M)) {
 const CXXRecordDecl *calleeMethodsClass = M->getParent();
 auto className = safeGetName(calleeMethodsClass);
diff --git a/clang/lib/StaticAnalyzer/Core/BugReporter.cpp 
b/clang/lib/StaticAnalyzer/Core/BugReporter.cpp
index f8db8d0bc8343..28b96f2717210 100644
--- a/clang/lib/StaticAnalyzer/Core/BugReporter.cpp
+++ b/clang/lib/StaticAnalyzer/Core/BugReporter.cpp
@@ -3377,8 +3377,6 @@ 
PathSensitiveBugReporter::generateDiagnosticForConsumerMap(
 BugReport *exampleReport,
 ArrayRef> consumers,
 ArrayRef bugReports) {
-  std::vector BasicBugReports;
-  std::vector PathSensitiveBugReports;
   if (isa(exampleReport))
 return BugReporter::generateDiagnosticForConsumerMap(exampleReport,
  consumers, 
bugReports);
diff --git a/clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp 
b/clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
index 95d9df4100bfa..84a9c43d3572e 100644
--- a/clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
+++ b/clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
@@ -270,7 +270,7 @@ static bool isWithinConstantOverflowBounds(llvm::APSInt I) {
   assert(!AT.isUnsigned() &&
  "This only works with signed integers!");
 
-  llvm::APSInt Max = AT.getMaxValue() / AT.getValue(4), Min = -Max;
+  llvm::APSInt Max = AT.getMaxValue() / AT.getValue(4);
   return (I <= Max) && (I >= -Max);
 }
 
diff --git a/clang/unittests/Tooling/CompilationDatabaseTest.cpp 
b/clang/unittests/Tooling/CompilationDatabaseTest.cpp
index 2032b13726c45..c1febaf40bf19 100644
--- a/clang/unittests/Tooling/CompilationDatabaseTest.cpp
+++ b/clang/unittests/Tooling/CompilationDatabaseTest.cpp
@@ -703,7 +703,6 @@ TEST(ParseFixedCompilationDatabase, HandlesArgv0) {
 Database->getCompileCommands("source");
   ASSERT_EQ(1ul, Result.size());
   ASSERT_EQ(".", Result[0].Directory);
-  std::vector Expecte

[clang] [clang] Remove unused local variables (NFC) (PR #138468)

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

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

None

>From 89189fd5a12716b35019271a7473887867b2c3e1 Mon Sep 17 00:00:00 2001
From: Kazu Hirata 
Date: Sun, 4 May 2025 13:03:48 -0700
Subject: [PATCH] [clang] Remove unused local variables (NFC)

---
 .../StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h| 2 --
 clang/lib/Sema/SemaPPC.cpp  | 1 -
 clang/lib/Sema/SemaTemplateDeduction.cpp| 2 --
 clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp  | 2 --
 clang/lib/StaticAnalyzer/Core/BugReporter.cpp   | 2 --
 clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp | 2 +-
 clang/unittests/Tooling/CompilationDatabaseTest.cpp | 1 -
 7 files changed, 1 insertion(+), 11 deletions(-)

diff --git 
a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h
index e084a13995306..d4052ef90de6e 100644
--- 
a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h
+++ 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h
@@ -324,8 +324,6 @@ class SMTConstraintManager : public 
clang::ento::SimpleConstraintManager {
 
 // Construct the logical AND of all the constraints
 if (I != IE) {
-  std::vector ASTs;
-
   llvm::SMTExprRef Constraint = I++->second;
   while (I != IE) {
 Constraint = Solver->mkAnd(Constraint, I++->second);
diff --git a/clang/lib/Sema/SemaPPC.cpp b/clang/lib/Sema/SemaPPC.cpp
index b6802d6890ed1..9b4d82745f881 100644
--- a/clang/lib/Sema/SemaPPC.cpp
+++ b/clang/lib/Sema/SemaPPC.cpp
@@ -98,7 +98,6 @@ bool SemaPPC::CheckPPCBuiltinFunctionCall(const TargetInfo 
&TI,
   CallExpr *TheCall) {
   ASTContext &Context = getASTContext();
   bool IsTarget64Bit = TI.getTypeWidth(TI.getIntPtrType()) == 64;
-  llvm::APSInt Result;
 
   if (isPPC_64Builtin(BuiltinID) && !IsTarget64Bit)
 return Diag(TheCall->getBeginLoc(), diag::err_64_bit_builtin_32_bit_tgt)
diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 
b/clang/lib/Sema/SemaTemplateDeduction.cpp
index 0ecdbb3ffb89f..c9de36383d334 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -6605,8 +6605,6 @@ bool 
Sema::isTemplateTemplateParameterAtLeastAsSpecializedAs(
 llvm_unreachable("Unexpected Result");
   }
 
-  SmallVector DeducedArgs(Deduced.begin(), Deduced.end());
-
   TemplateDeductionResult TDK;
   runWithSufficientStackSpace(Info.getLocation(), [&] {
 TDK = ::FinishTemplateArgumentDeduction(
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
index 0f0184c472f36..4ddd11495f534 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
@@ -370,8 +370,6 @@ std::optional isUnsafePtr(const QualType T, bool 
IsArcEnabled) {
 std::optional isGetterOfSafePtr(const CXXMethodDecl *M) {
   assert(M);
 
-  std::optional RTC;
-
   if (isa(M)) {
 const CXXRecordDecl *calleeMethodsClass = M->getParent();
 auto className = safeGetName(calleeMethodsClass);
diff --git a/clang/lib/StaticAnalyzer/Core/BugReporter.cpp 
b/clang/lib/StaticAnalyzer/Core/BugReporter.cpp
index f8db8d0bc8343..28b96f2717210 100644
--- a/clang/lib/StaticAnalyzer/Core/BugReporter.cpp
+++ b/clang/lib/StaticAnalyzer/Core/BugReporter.cpp
@@ -3377,8 +3377,6 @@ 
PathSensitiveBugReporter::generateDiagnosticForConsumerMap(
 BugReport *exampleReport,
 ArrayRef> consumers,
 ArrayRef bugReports) {
-  std::vector BasicBugReports;
-  std::vector PathSensitiveBugReports;
   if (isa(exampleReport))
 return BugReporter::generateDiagnosticForConsumerMap(exampleReport,
  consumers, 
bugReports);
diff --git a/clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp 
b/clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
index 95d9df4100bfa..84a9c43d3572e 100644
--- a/clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
+++ b/clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
@@ -270,7 +270,7 @@ static bool isWithinConstantOverflowBounds(llvm::APSInt I) {
   assert(!AT.isUnsigned() &&
  "This only works with signed integers!");
 
-  llvm::APSInt Max = AT.getMaxValue() / AT.getValue(4), Min = -Max;
+  llvm::APSInt Max = AT.getMaxValue() / AT.getValue(4);
   return (I <= Max) && (I >= -Max);
 }
 
diff --git a/clang/unittests/Tooling/CompilationDatabaseTest.cpp 
b/clang/unittests/Tooling/CompilationDatabaseTest.cpp
index 2032b13726c45..c1febaf40bf19 100644
--- a/clang/unittests/Tooling/CompilationDatabaseTest.cpp
+++ b/clang/unittests/Tooling/CompilationDatabaseTest.cpp
@@ -703,7 +703,6 @@ TEST(ParseFixedCompilationDatabase, HandlesArgv

[clang] [clang] Remove unused local variables (NFC) (PR #138468)

2025-05-04 Thread via cfe-commits

llvmbot wrote:




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

Author: Kazu Hirata (kazutakahirata)


Changes



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


7 Files Affected:

- (modified) 
clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h 
(-2) 
- (modified) clang/lib/Sema/SemaPPC.cpp (-1) 
- (modified) clang/lib/Sema/SemaTemplateDeduction.cpp (-2) 
- (modified) clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp 
(-2) 
- (modified) clang/lib/StaticAnalyzer/Core/BugReporter.cpp (-2) 
- (modified) clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp (+1-1) 
- (modified) clang/unittests/Tooling/CompilationDatabaseTest.cpp (-1) 


``diff
diff --git 
a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h
index e084a13995306..d4052ef90de6e 100644
--- 
a/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h
+++ 
b/clang/include/clang/StaticAnalyzer/Core/PathSensitive/SMTConstraintManager.h
@@ -324,8 +324,6 @@ class SMTConstraintManager : public 
clang::ento::SimpleConstraintManager {
 
 // Construct the logical AND of all the constraints
 if (I != IE) {
-  std::vector ASTs;
-
   llvm::SMTExprRef Constraint = I++->second;
   while (I != IE) {
 Constraint = Solver->mkAnd(Constraint, I++->second);
diff --git a/clang/lib/Sema/SemaPPC.cpp b/clang/lib/Sema/SemaPPC.cpp
index b6802d6890ed1..9b4d82745f881 100644
--- a/clang/lib/Sema/SemaPPC.cpp
+++ b/clang/lib/Sema/SemaPPC.cpp
@@ -98,7 +98,6 @@ bool SemaPPC::CheckPPCBuiltinFunctionCall(const TargetInfo 
&TI,
   CallExpr *TheCall) {
   ASTContext &Context = getASTContext();
   bool IsTarget64Bit = TI.getTypeWidth(TI.getIntPtrType()) == 64;
-  llvm::APSInt Result;
 
   if (isPPC_64Builtin(BuiltinID) && !IsTarget64Bit)
 return Diag(TheCall->getBeginLoc(), diag::err_64_bit_builtin_32_bit_tgt)
diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp 
b/clang/lib/Sema/SemaTemplateDeduction.cpp
index 0ecdbb3ffb89f..c9de36383d334 100644
--- a/clang/lib/Sema/SemaTemplateDeduction.cpp
+++ b/clang/lib/Sema/SemaTemplateDeduction.cpp
@@ -6605,8 +6605,6 @@ bool 
Sema::isTemplateTemplateParameterAtLeastAsSpecializedAs(
 llvm_unreachable("Unexpected Result");
   }
 
-  SmallVector DeducedArgs(Deduced.begin(), Deduced.end());
-
   TemplateDeductionResult TDK;
   runWithSufficientStackSpace(Info.getLocation(), [&] {
 TDK = ::FinishTemplateArgumentDeduction(
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
index 0f0184c472f36..4ddd11495f534 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
@@ -370,8 +370,6 @@ std::optional isUnsafePtr(const QualType T, bool 
IsArcEnabled) {
 std::optional isGetterOfSafePtr(const CXXMethodDecl *M) {
   assert(M);
 
-  std::optional RTC;
-
   if (isa(M)) {
 const CXXRecordDecl *calleeMethodsClass = M->getParent();
 auto className = safeGetName(calleeMethodsClass);
diff --git a/clang/lib/StaticAnalyzer/Core/BugReporter.cpp 
b/clang/lib/StaticAnalyzer/Core/BugReporter.cpp
index f8db8d0bc8343..28b96f2717210 100644
--- a/clang/lib/StaticAnalyzer/Core/BugReporter.cpp
+++ b/clang/lib/StaticAnalyzer/Core/BugReporter.cpp
@@ -3377,8 +3377,6 @@ 
PathSensitiveBugReporter::generateDiagnosticForConsumerMap(
 BugReport *exampleReport,
 ArrayRef> consumers,
 ArrayRef bugReports) {
-  std::vector BasicBugReports;
-  std::vector PathSensitiveBugReports;
   if (isa(exampleReport))
 return BugReporter::generateDiagnosticForConsumerMap(exampleReport,
  consumers, 
bugReports);
diff --git a/clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp 
b/clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
index 95d9df4100bfa..84a9c43d3572e 100644
--- a/clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
+++ b/clang/lib/StaticAnalyzer/Core/SimpleSValBuilder.cpp
@@ -270,7 +270,7 @@ static bool isWithinConstantOverflowBounds(llvm::APSInt I) {
   assert(!AT.isUnsigned() &&
  "This only works with signed integers!");
 
-  llvm::APSInt Max = AT.getMaxValue() / AT.getValue(4), Min = -Max;
+  llvm::APSInt Max = AT.getMaxValue() / AT.getValue(4);
   return (I <= Max) && (I >= -Max);
 }
 
diff --git a/clang/unittests/Tooling/CompilationDatabaseTest.cpp 
b/clang/unittests/Tooling/CompilationDatabaseTest.cpp
index 2032b13726c45..c1febaf40bf19 100644
--- a/clang/unittests/Tooling/CompilationDatabaseTest.cpp
+++ b/clang/unittests/Tooling/CompilationDatabaseTest.cpp
@@ -703,7 +703,6 @@ TEST(ParseFixedCompilationDatabase, HandlesArgv0) {
 Database->getCompileCommands("source");
   ASSERT_EQ(1ul, Result.size());
   ASSERT_EQ(".", Result[0].Directory);
-  s

[clang] [clang-format] Add SpaceAfterOperatorKeyword option (PR #137610)

2025-05-04 Thread Filip Milosevic via cfe-commits

https://github.com/MightyFilipns updated 
https://github.com/llvm/llvm-project/pull/137610



  



Rate limit · GitHub


  body {
background-color: #f6f8fa;
color: #24292e;
font-family: -apple-system,BlinkMacSystemFont,Segoe 
UI,Helvetica,Arial,sans-serif,Apple Color Emoji,Segoe UI Emoji,Segoe UI Symbol;
font-size: 14px;
line-height: 1.5;
margin: 0;
  }

  .container { margin: 50px auto; max-width: 600px; text-align: center; 
padding: 0 24px; }

  a { color: #0366d6; text-decoration: none; }
  a:hover { text-decoration: underline; }

  h1 { line-height: 60px; font-size: 48px; font-weight: 300; margin: 0px; 
text-shadow: 0 1px 0 #fff; }
  p { color: rgba(0, 0, 0, 0.5); margin: 20px 0 40px; }

  ul { list-style: none; margin: 25px 0; padding: 0; }
  li { display: table-cell; font-weight: bold; width: 1%; }

  .logo { display: inline-block; margin-top: 35px; }
  .logo-img-2x { display: none; }
  @media
  only screen and (-webkit-min-device-pixel-ratio: 2),
  only screen and (   min--moz-device-pixel-ratio: 2),
  only screen and ( -o-min-device-pixel-ratio: 2/1),
  only screen and (min-device-pixel-ratio: 2),
  only screen and (min-resolution: 192dpi),
  only screen and (min-resolution: 2dppx) {
.logo-img-1x { display: none; }
.logo-img-2x { display: inline-block; }
  }

  #suggestions {
margin-top: 35px;
color: #ccc;
  }
  #suggestions a {
color: #66;
font-weight: 200;
font-size: 14px;
margin: 0 10px;
  }


  
  



  Whoa there!
  You have exceeded a secondary rate limit.
Please wait a few minutes before you try again;
in some cases this may take up to an hour.
  
  
https://support.github.com/contact";>Contact Support —
https://githubstatus.com";>GitHub Status —
https://twitter.com/githubstatus";>@githubstatus
  

  

  

  

  

  


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


  1   2   >