[clang] [llvm] [SPIRV] GPU intrinsics (PR #131190)

2025-03-14 Thread Michal Paszkowski via cfe-commits

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


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


[clang] [llvm] [SPIRV] GPU intrinsics (PR #131190)

2025-03-14 Thread Michal Paszkowski via cfe-commits


@@ -0,0 +1,501 @@
+//===- LowerGPUIntrinsic.cpp 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+//
+// Lower the llvm.gpu intrinsics to target specific code sequences.
+// Can be called from clang if building for a specific GPU or from the backend
+// as part of a SPIRV lowering pipeline. Initial pass can lower to amdgcn or

michalpaszkowski wrote:

I don't understand how this pass fits into the SPIR-V lowering pipeline. Is 
this confusing [SPIR and 
SPIR-V](https://en.wikipedia.org/wiki/Standard_Portable_Intermediate_Representation)?
 SPIR being the format based on LLVM IR (although on an old version of LLVM 
3.4)? SPIR-V being a custom [Khronos-defined 
format](https://registry.khronos.org/SPIR-V/specs/unified1/SPIRV.html).

[While SPIR-V easily maps to LLVM 
IR](https://github.com/KhronosGroup/SPIRV-LLVM-Translator/blob/main/docs/SPIRVRepresentationInLLVM.rst),
 it is far from being a standardized mapping and the actual translation is 
usually handled by either 
[SPIRV-LLVM-Translator](https://github.com/KhronosGroup/SPIRV-LLVM-Translator) 
or the in-tree SPIR-V backend.

Could you please comment on how this pass and the changes would fit into the 
current SPIR-V code generation flow through the SPIR-V backend?

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


[clang] [llvm] [SPIRV] GPU intrinsics (PR #131190)

2025-03-14 Thread Michal Paszkowski via cfe-commits

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


[clang] [llvm] [RISCV] Add Zilsd and Zclsd Extensions (PR #131094)

2025-03-14 Thread via cfe-commits

https://github.com/dong-miao updated 
https://github.com/llvm/llvm-project/pull/131094

>From bcdf9641037507b855a20a8ba5d26b127dd248e8 Mon Sep 17 00:00:00 2001
From: dong-miao 
Date: Sat, 4 Jan 2025 17:53:58 +0800
Subject: [PATCH 01/23] Update RISCVSystemOperands.td

---
 llvm/lib/Target/RISCV/RISCVSystemOperands.td | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/llvm/lib/Target/RISCV/RISCVSystemOperands.td 
b/llvm/lib/Target/RISCV/RISCVSystemOperands.td
index 39853cf13a920..41b96e1497e70 100644
--- a/llvm/lib/Target/RISCV/RISCVSystemOperands.td
+++ b/llvm/lib/Target/RISCV/RISCVSystemOperands.td
@@ -158,6 +158,7 @@ def : SysReg<"hip", 0x644>;
 def : SysReg<"hvip", 0x645>;
 def : SysReg<"htinst", 0x64A>;
 def : SysReg<"hgeip", 0xE12>;
+def : SysReg<"hedelegh", 0x612>;
 
 
//===--===//
 // Hypervisor Configuration
@@ -239,6 +240,7 @@ def : SysReg<"mbadaddr", 0x343>;
 def : SysReg<"mip", 0x344>;
 def : SysReg<"mtinst", 0x34A>;
 def : SysReg<"mtval2", 0x34B>;
+def : SysReg<"medelegh", 0x312>;
 
 
//===--===//
 // Machine Configuration

>From 30e3fbe156581efe49a3c6def9dd444dc546f134 Mon Sep 17 00:00:00 2001
From: dong-miao 
Date: Sat, 4 Jan 2025 18:02:40 +0800
Subject: [PATCH 02/23] Update rv32-hypervisor-csr-names.s

---
 llvm/test/MC/RISCV/rv32-hypervisor-csr-names.s | 18 ++
 1 file changed, 18 insertions(+)

diff --git a/llvm/test/MC/RISCV/rv32-hypervisor-csr-names.s 
b/llvm/test/MC/RISCV/rv32-hypervisor-csr-names.s
index aadee4fb4f3ad..79d87b3f2471c 100644
--- a/llvm/test/MC/RISCV/rv32-hypervisor-csr-names.s
+++ b/llvm/test/MC/RISCV/rv32-hypervisor-csr-names.s
@@ -219,3 +219,21 @@ csrrs t2, 0x214, zero
 csrrs t1, vsiph, zero
 # uimm12
 csrrs t2, 0x254, zero
+
+##
+# Hypervisor Trap Setup
+##
+
+# hedelegh
+# name
+# CHECK-INST: csrrs t1, hedelegh, zero
+# CHECK-ENC: encoding: [0x73,0x23,0x20,0x61]
+# CHECK-INST-ALIAS: csrr t1, hedelegh
+# uimm12
+# CHECK-INST: csrrs t2, hedelegh, zero
+# CHECK-ENC: encoding: [0xf3,0x23,0x20,0x61]
+# CHECK-INST-ALIAS: csrr t2, hedelegh
+# name
+csrrs t1, hedelegh, zero
+# uimm12
+csrrs t2, 0x612, zero

>From e41e745626caf701b2a21eb2577ead05b922f590 Mon Sep 17 00:00:00 2001
From: dong-miao 
Date: Sat, 4 Jan 2025 18:05:04 +0800
Subject: [PATCH 03/23] Update rv32-machine-csr-names.s

---
 llvm/test/MC/RISCV/rv32-machine-csr-names.s | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/llvm/test/MC/RISCV/rv32-machine-csr-names.s 
b/llvm/test/MC/RISCV/rv32-machine-csr-names.s
index 3d527e382376e..9e929b7eddeed 100644
--- a/llvm/test/MC/RISCV/rv32-machine-csr-names.s
+++ b/llvm/test/MC/RISCV/rv32-machine-csr-names.s
@@ -22,6 +22,20 @@ csrrs t1, mstatush, zero
 # uimm12
 csrrs t2, 0x310, zero
 
+# medelegh
+# name
+# CHECK-INST: csrrs t1, medelegh, zero
+# CHECK-ENC: encoding: [0x73,0x23,0x20,0x31]
+# CHECK-INST-ALIAS: csrr t1, medelegh
+# uimm12
+# CHECK-INST: csrrs t2, medelegh, zero
+# CHECK-ENC: encoding: [0xf3,0x23,0x20,0x31]
+# CHECK-INST-ALIAS: csrr t2, medelegh
+# name
+csrrs t1, medelegh, zero
+# uimm12
+csrrs t2, 0x312, zero
+
 #
 # Machine Configuration
 #

>From ea2c1afaa0eede9cf9dfbf68d10fada108b0164b Mon Sep 17 00:00:00 2001
From: dong-miao 
Date: Sun, 5 Jan 2025 11:12:53 +0800
Subject: [PATCH 04/23] Update RISCVSystemOperands.td

---
 llvm/lib/Target/RISCV/RISCVSystemOperands.td | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/llvm/lib/Target/RISCV/RISCVSystemOperands.td 
b/llvm/lib/Target/RISCV/RISCVSystemOperands.td
index 41b96e1497e70..21f912bbc84d1 100644
--- a/llvm/lib/Target/RISCV/RISCVSystemOperands.td
+++ b/llvm/lib/Target/RISCV/RISCVSystemOperands.td
@@ -158,6 +158,7 @@ def : SysReg<"hip", 0x644>;
 def : SysReg<"hvip", 0x645>;
 def : SysReg<"htinst", 0x64A>;
 def : SysReg<"hgeip", 0xE12>;
+let isRV32Only = 1 in
 def : SysReg<"hedelegh", 0x612>;
 
 
//===--===//
@@ -240,6 +241,7 @@ def : SysReg<"mbadaddr", 0x343>;
 def : SysReg<"mip", 0x344>;
 def : SysReg<"mtinst", 0x34A>;
 def : SysReg<"mtval2", 0x34B>;
+let isRV32Only = 1 in
 def : SysReg<"medelegh", 0x312>;
 
 
//===--===//

>From 6b074f3d744bdfaf2f4de9fa49484b25f76df3d4 Mon Sep 17 00:00:00 2001
From: dong-miao 
Date: Sun, 5 Jan 2025 11:30:33 +0800
Subject: [PATCH 05/23] Update rv32-only-csr-names.s

---
 llvm/test/MC/RISCV/rv32-only-csr-names.s | 4 
 1 file changed, 4 insertions(+)

diff --git a/llvm/test/MC/RISCV/rv32-only-csr-names.s 
b/llvm/test/MC/RISCV/rv32-only-csr-names.s
index db88eacf9396b..1604469210193 100644
--- a/llvm/test/MC/RISCV/rv32-only-csr-names.s
+++ b/llvm/test/MC/RISCV/rv32-only-csr-names.s
@@ -41,12 +41,16 @@ csrrs t1, henvcfgh, zero # CHECK-NEED-RV32: :[[@LIN

[clang] [analyzer] Introduce per-entry-point statistics (PR #131175)

2025-03-14 Thread Arseniy Zaostrovnykh via cfe-commits

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


[clang] [C++20][Modules] Prevent premature calls to PassInterestingDeclsToConsumer() within FinishedDeserializing(). (PR #129982)

2025-03-14 Thread Michael Park via cfe-commits

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


[clang] [llvm] [RISCV] Add Zilsd and Zclsd Extensions (PR #131094)

2025-03-14 Thread via cfe-commits

https://github.com/dong-miao updated 
https://github.com/llvm/llvm-project/pull/131094

>From bcdf9641037507b855a20a8ba5d26b127dd248e8 Mon Sep 17 00:00:00 2001
From: dong-miao 
Date: Sat, 4 Jan 2025 17:53:58 +0800
Subject: [PATCH 01/24] Update RISCVSystemOperands.td

---
 llvm/lib/Target/RISCV/RISCVSystemOperands.td | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/llvm/lib/Target/RISCV/RISCVSystemOperands.td 
b/llvm/lib/Target/RISCV/RISCVSystemOperands.td
index 39853cf13a920..41b96e1497e70 100644
--- a/llvm/lib/Target/RISCV/RISCVSystemOperands.td
+++ b/llvm/lib/Target/RISCV/RISCVSystemOperands.td
@@ -158,6 +158,7 @@ def : SysReg<"hip", 0x644>;
 def : SysReg<"hvip", 0x645>;
 def : SysReg<"htinst", 0x64A>;
 def : SysReg<"hgeip", 0xE12>;
+def : SysReg<"hedelegh", 0x612>;
 
 
//===--===//
 // Hypervisor Configuration
@@ -239,6 +240,7 @@ def : SysReg<"mbadaddr", 0x343>;
 def : SysReg<"mip", 0x344>;
 def : SysReg<"mtinst", 0x34A>;
 def : SysReg<"mtval2", 0x34B>;
+def : SysReg<"medelegh", 0x312>;
 
 
//===--===//
 // Machine Configuration

>From 30e3fbe156581efe49a3c6def9dd444dc546f134 Mon Sep 17 00:00:00 2001
From: dong-miao 
Date: Sat, 4 Jan 2025 18:02:40 +0800
Subject: [PATCH 02/24] Update rv32-hypervisor-csr-names.s

---
 llvm/test/MC/RISCV/rv32-hypervisor-csr-names.s | 18 ++
 1 file changed, 18 insertions(+)

diff --git a/llvm/test/MC/RISCV/rv32-hypervisor-csr-names.s 
b/llvm/test/MC/RISCV/rv32-hypervisor-csr-names.s
index aadee4fb4f3ad..79d87b3f2471c 100644
--- a/llvm/test/MC/RISCV/rv32-hypervisor-csr-names.s
+++ b/llvm/test/MC/RISCV/rv32-hypervisor-csr-names.s
@@ -219,3 +219,21 @@ csrrs t2, 0x214, zero
 csrrs t1, vsiph, zero
 # uimm12
 csrrs t2, 0x254, zero
+
+##
+# Hypervisor Trap Setup
+##
+
+# hedelegh
+# name
+# CHECK-INST: csrrs t1, hedelegh, zero
+# CHECK-ENC: encoding: [0x73,0x23,0x20,0x61]
+# CHECK-INST-ALIAS: csrr t1, hedelegh
+# uimm12
+# CHECK-INST: csrrs t2, hedelegh, zero
+# CHECK-ENC: encoding: [0xf3,0x23,0x20,0x61]
+# CHECK-INST-ALIAS: csrr t2, hedelegh
+# name
+csrrs t1, hedelegh, zero
+# uimm12
+csrrs t2, 0x612, zero

>From e41e745626caf701b2a21eb2577ead05b922f590 Mon Sep 17 00:00:00 2001
From: dong-miao 
Date: Sat, 4 Jan 2025 18:05:04 +0800
Subject: [PATCH 03/24] Update rv32-machine-csr-names.s

---
 llvm/test/MC/RISCV/rv32-machine-csr-names.s | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/llvm/test/MC/RISCV/rv32-machine-csr-names.s 
b/llvm/test/MC/RISCV/rv32-machine-csr-names.s
index 3d527e382376e..9e929b7eddeed 100644
--- a/llvm/test/MC/RISCV/rv32-machine-csr-names.s
+++ b/llvm/test/MC/RISCV/rv32-machine-csr-names.s
@@ -22,6 +22,20 @@ csrrs t1, mstatush, zero
 # uimm12
 csrrs t2, 0x310, zero
 
+# medelegh
+# name
+# CHECK-INST: csrrs t1, medelegh, zero
+# CHECK-ENC: encoding: [0x73,0x23,0x20,0x31]
+# CHECK-INST-ALIAS: csrr t1, medelegh
+# uimm12
+# CHECK-INST: csrrs t2, medelegh, zero
+# CHECK-ENC: encoding: [0xf3,0x23,0x20,0x31]
+# CHECK-INST-ALIAS: csrr t2, medelegh
+# name
+csrrs t1, medelegh, zero
+# uimm12
+csrrs t2, 0x312, zero
+
 #
 # Machine Configuration
 #

>From ea2c1afaa0eede9cf9dfbf68d10fada108b0164b Mon Sep 17 00:00:00 2001
From: dong-miao 
Date: Sun, 5 Jan 2025 11:12:53 +0800
Subject: [PATCH 04/24] Update RISCVSystemOperands.td

---
 llvm/lib/Target/RISCV/RISCVSystemOperands.td | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/llvm/lib/Target/RISCV/RISCVSystemOperands.td 
b/llvm/lib/Target/RISCV/RISCVSystemOperands.td
index 41b96e1497e70..21f912bbc84d1 100644
--- a/llvm/lib/Target/RISCV/RISCVSystemOperands.td
+++ b/llvm/lib/Target/RISCV/RISCVSystemOperands.td
@@ -158,6 +158,7 @@ def : SysReg<"hip", 0x644>;
 def : SysReg<"hvip", 0x645>;
 def : SysReg<"htinst", 0x64A>;
 def : SysReg<"hgeip", 0xE12>;
+let isRV32Only = 1 in
 def : SysReg<"hedelegh", 0x612>;
 
 
//===--===//
@@ -240,6 +241,7 @@ def : SysReg<"mbadaddr", 0x343>;
 def : SysReg<"mip", 0x344>;
 def : SysReg<"mtinst", 0x34A>;
 def : SysReg<"mtval2", 0x34B>;
+let isRV32Only = 1 in
 def : SysReg<"medelegh", 0x312>;
 
 
//===--===//

>From 6b074f3d744bdfaf2f4de9fa49484b25f76df3d4 Mon Sep 17 00:00:00 2001
From: dong-miao 
Date: Sun, 5 Jan 2025 11:30:33 +0800
Subject: [PATCH 05/24] Update rv32-only-csr-names.s

---
 llvm/test/MC/RISCV/rv32-only-csr-names.s | 4 
 1 file changed, 4 insertions(+)

diff --git a/llvm/test/MC/RISCV/rv32-only-csr-names.s 
b/llvm/test/MC/RISCV/rv32-only-csr-names.s
index db88eacf9396b..1604469210193 100644
--- a/llvm/test/MC/RISCV/rv32-only-csr-names.s
+++ b/llvm/test/MC/RISCV/rv32-only-csr-names.s
@@ -41,12 +41,16 @@ csrrs t1, henvcfgh, zero # CHECK-NEED-RV32: :[[@LIN

[clang] [clang][DependencyScanning] Track modules that resolve from sysroot. (PR #130634)

2025-03-14 Thread Cyndy Ishida via cfe-commits


@@ -843,7 +864,7 @@ void ModuleDepCollectorPP::addModuleDep(
 !MDC.isPrebuiltModule(Import)) {

cyndyishida wrote:

In hindsight, I wish I made this a stacked diff against the real repo.

I have an implementation that addresses this in 
https://github.com/cyndyishida/llvm-project/commit/272b49206c51c4cc8879c2b539f199c5548fb47a
 I'd like to merge the current PR and then open a new PR against main for it. 
But I am open to other suggestions to make the review easier. 

That implementation adds some overhead for two reasons.
1. It deserializes out more content from prebuilt pcm files. 
2. When a module path is fully realized, it traverses down into the leaf 
dependency and updates whether they are in the sysroot. 

I measured this overhead on a large-ish objc project that uses pch's and toy 
examples against the macos sdk. I did not observe a noticeable difference.

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


[clang] [Clang] [Tests] Add some more tests around non-local/non-variable declarations in C for loops (PR #131199)

2025-03-14 Thread via cfe-commits

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


[clang] 20b7f59 - [Clang] [Tests] Add some more tests around non-local/non-variable declarations in C for loops (#131199)

2025-03-14 Thread via cfe-commits

Author: Sirraide
Date: 2025-03-14T14:09:26+01:00
New Revision: 20b7f5982622f1314129fbb9f3c520e789c69bb8

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

LOG: [Clang] [Tests] Add some more tests around non-local/non-variable 
declarations in C for loops (#131199)

As requested by @shafik in
https://github.com/llvm/llvm-project/pull/129737#discussion_r1984337334.
I also added a test for `thread_local` because why not.

Added: 


Modified: 
clang/test/Sema/for.c

Removed: 




diff  --git a/clang/test/Sema/for.c b/clang/test/Sema/for.c
index c21ef62247037..110f84ddda952 100644
--- a/clang/test/Sema/for.c
+++ b/clang/test/Sema/for.c
@@ -5,17 +5,19 @@
 void b1 (void) { for (void (*f) (void);;); }
 void b2 (void) { for (void f (void);;); }   /* c11-warning {{non-variable 
declaration in 'for' loop is a C23 extension}}
c23-warning {{non-variable 
declaration in 'for' loop is incompatible with C standards before C23}} */
-void b3 (void) { for (static int f;;); }/* c11-warning {{declaration of 
non-local variable in 'for' loop is a C23 extension}}
-   c23-warning {{declaration of 
non-local variable in 'for' loop is incompatible with C standards before C23}} 
*/
+void b3 (void) { for (static int f;f;); }/* c11-warning {{declaration of 
non-local variable in 'for' loop is a C23 extension}}
+c23-warning {{declaration of 
non-local variable in 'for' loop is incompatible with C standards before C23}} 
*/
 
 void b4 (void) { for (typedef int f;;); }   /* c11-warning {{non-variable 
declaration in 'for' loop is a C23 extension}}
c23-warning {{non-variable 
declaration in 'for' loop is incompatible with C standards before C23}} */
-void b5 (void) { for (struct { int i; } s;;); }
-void b6 (void) { for (enum { zero, ten = 10 } i;;); }
+void b5 (void) { for (struct { int i; } s;s.i;); }
+void b6 (void) { for (enum { zero, ten = 10 } i = ten;i;); }
 void b7 (void) { for (struct s { int i; };;); } /* c11-warning {{non-variable 
declaration in 'for' loop is a C23 extension}}
c23-warning {{non-variable 
declaration in 'for' loop is incompatible with C standards before C23}} */
-void b8 (void) { for (static struct { int i; } s;;); } /* c11-warning 
{{declaration of non-local variable in 'for' loop is a C23 extension}}
-  c23-warning 
{{declaration of non-local variable in 'for' loop is incompatible with C 
standards before C23}} */
-void b9 (void) { for (struct { int i; } (*s)(struct { int j; } o) = 0;;); }
+void b8 (void) { for (static struct { int i; } s;s.i;); } /* c11-warning 
{{declaration of non-local variable in 'for' loop is a C23 extension}}
+ c23-warning 
{{declaration of non-local variable in 'for' loop is incompatible with C 
standards before C23}} */
+void b9 (void) { for (struct { int i; } (*s)(struct { int j; } o) = 0;s;); }
 void b10(void) { for (typedef struct { int i; } (*s)(struct { int j; });;); } 
/* c11-warning {{non-variable declaration in 'for' loop is a C23 extension}}

  c23-warning {{non-variable declaration in 'for' loop is incompatible with C 
standards before C23}} */
+void b11 (void) { for (static _Thread_local struct { int i; } s;s.i;); } /* 
c11-warning {{declaration of non-local variable in 'for' loop is a C23 
extension}}
+
c23-warning {{declaration of non-local variable in 'for' loop is incompatible 
with C standards before C23}} */



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


[clang] [flang-rt] Pass the whole path of libflang_rt.runtime.a to linker on AIX (PR #131041)

2025-03-14 Thread Daniel Chen via cfe-commits

DanielCChen wrote:

I am working on a patch that re-uses `compilerRT` code as much as possible.

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


[clang] [clang] Add diagnostic for unresolved using declaration that shadows template parameters (PR #131328)

2025-03-14 Thread via cfe-commits

NewSigma wrote:

Hi @mizvekov. Can you help merge the PR? Thanks!

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


[clang-tools-extra] [clang-tidy] Add new check bugprone-capture-this-by-field (PR #130297)

2025-03-14 Thread Congcong Cai via cfe-commits

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

>From 8ef214f6c78d710dbd9c74b06c7c637baf93e527 Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Sat, 8 Mar 2025 00:03:39 +0800
Subject: [PATCH 1/9] [clang-tidy] Add new check bugprone-capture-this-by-field

---
 .../bugprone/BugproneTidyModule.cpp   |   3 +
 .../clang-tidy/bugprone/CMakeLists.txt|   1 +
 .../bugprone/CaptureThisByFieldCheck.cpp  |  99 +
 .../bugprone/CaptureThisByFieldCheck.h|  39 +
 clang-tools-extra/docs/ReleaseNotes.rst   |   6 +
 .../checks/bugprone/capture-this-by-field.rst |  28 
 .../docs/clang-tidy/checks/list.rst   |   1 +
 .../bugprone/capture-this-by-field.cpp| 133 ++
 8 files changed, 310 insertions(+)
 create mode 100644 
clang-tools-extra/clang-tidy/bugprone/CaptureThisByFieldCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/bugprone/CaptureThisByFieldCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/bugprone/capture-this-by-field.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/capture-this-by-field.cpp

diff --git a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp 
b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
index 0a3376949b6e5..ee9fa5ef06c7a 100644
--- a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
@@ -16,6 +16,7 @@
 #include "BitwisePointerCastCheck.h"
 #include "BoolPointerImplicitConversionCheck.h"
 #include "BranchCloneCheck.h"
+#include "CaptureThisByFieldCheck.h"
 #include "CastingThroughVoidCheck.h"
 #include "ChainedComparisonCheck.h"
 #include "ComparePointerToMemberVirtualFunctionCheck.h"
@@ -118,6 +119,8 @@ class BugproneModule : public ClangTidyModule {
 CheckFactories.registerCheck(
 "bugprone-bool-pointer-implicit-conversion");
 CheckFactories.registerCheck("bugprone-branch-clone");
+CheckFactories.registerCheck(
+"bugprone-capture-this-by-field");
 CheckFactories.registerCheck(
 "bugprone-casting-through-void");
 CheckFactories.registerCheck(
diff --git a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt 
b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
index dab139b77c770..4d1d50c4ea2a0 100644
--- a/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
+++ b/clang-tools-extra/clang-tidy/bugprone/CMakeLists.txt
@@ -12,6 +12,7 @@ add_clang_library(clangTidyBugproneModule STATIC
   BoolPointerImplicitConversionCheck.cpp
   BranchCloneCheck.cpp
   BugproneTidyModule.cpp
+  CaptureThisByFieldCheck.cpp
   CastingThroughVoidCheck.cpp
   ChainedComparisonCheck.cpp
   ComparePointerToMemberVirtualFunctionCheck.cpp
diff --git a/clang-tools-extra/clang-tidy/bugprone/CaptureThisByFieldCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/CaptureThisByFieldCheck.cpp
new file mode 100644
index 0..1f0f68acf335f
--- /dev/null
+++ b/clang-tools-extra/clang-tidy/bugprone/CaptureThisByFieldCheck.cpp
@@ -0,0 +1,99 @@
+//===--- CaptureThisByFieldCheck.cpp - clang-tidy 
-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "CaptureThisByFieldCheck.h"
+#include "clang/AST/DeclCXX.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/ASTMatchers/ASTMatchersMacros.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::bugprone {
+
+namespace {
+
+AST_MATCHER(CXXRecordDecl, correctHandleCaptureThisLambda) {
+  // unresolved
+  if (Node.needsOverloadResolutionForCopyConstructor() &&
+  Node.needsImplicitCopyConstructor())
+return false;
+  if (Node.needsOverloadResolutionForMoveConstructor() &&
+  Node.needsImplicitMoveConstructor())
+return false;
+  if (Node.needsOverloadResolutionForCopyAssignment() &&
+  Node.needsImplicitCopyAssignment())
+return false;
+  if (Node.needsOverloadResolutionForMoveAssignment() &&
+  Node.needsImplicitMoveAssignment())
+return false;
+  // default but not deleted
+  if (Node.hasSimpleCopyConstructor())
+return false;
+  if (Node.hasSimpleMoveConstructor())
+return false;
+  if (Node.hasSimpleCopyAssignment())
+return false;
+  if (Node.hasSimpleMoveAssignment())
+return false;
+
+  for (CXXConstructorDecl const *C : Node.ctors()) {
+if (C->isCopyOrMoveConstructor() && C->isDefaulted() && !C->isDeleted())
+  return false;
+  }
+  for (CXXMethodDecl const *M : Node.methods()) {
+if (M->isCopyAssignmentOperator() && M->isDefaulted() && !M->isDeleted())
+  return false;
+if (M->isMoveAssignmentOperator() && M->isDefaulted() && !M->isDel

[clang] [llvm] [analysis] Software Bill of Mitigations (PR #130103)

2025-03-14 Thread Matthew Levy via cfe-commits

matthewlevy97 wrote:

@efriedma-quic That is correct about this just tracking where mitigations are 
emitted. I believe the emissions points should largely correlate with where 
they would get instrumented, but if this analysis runs super late (after all 
optimizations, etc.) to determine exactly if/where mitigations actually get 
instrumented, it might become more of a binary analysis task and greatly 
increase complexity. I am open to suggestions on different approaches.

The use case isn't really to verify that mitigations are enabled, but provide a 
way of tracking incremental deployments of mitigations (e.g., large binary 
where a given mitigation being deployed causes to large of a regression so only 
certain sub-units have a given mitigation). I have a follow-up diff that 
outputs a summary instead of a per-function tracking to show overall coverage 
on mitigations in the binary which I assume will be the more used option.

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


[clang] [NFC][analyzer] Framework for multipart checkers (PR #130985)

2025-03-14 Thread Donát Nagy via cfe-commits

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


[clang] [NFC][analyzer] Framework for multipart checkers (PR #130985)

2025-03-14 Thread Donát Nagy via cfe-commits

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


[clang] [llvm] [analysis] Software Bill of Mitigations (PR #130103)

2025-03-14 Thread Matthew Levy via cfe-commits

https://github.com/matthewlevy97 updated 
https://github.com/llvm/llvm-project/pull/130103

>From fb04b7bf5f2b668bf354632fc53e7521f44880c9 Mon Sep 17 00:00:00 2001
From: Matt Levy 
Date: Wed, 5 Mar 2025 12:36:02 -0500
Subject: [PATCH 1/5] [clang][CodeGen] Software Bill of Mitigations Metadata

The goal of this stack is to create a high fidelity mapping of mitigations to 
their possible insertion points and their actual insertion points. This would 
let us track where we do and don't have mitigations rather than the current 
approach of tracking where we have the flag.

There are some challenges posed by this like:
- Some mitigations are not emitted by the compiler, but the preprocessor
- Some mitigations are lowered later during IR -> MIR (stack cookies)
---
 clang/include/clang/Basic/CodeGenOptions.def |  1 +
 clang/include/clang/Driver/Options.td|  6 ++
 clang/lib/CodeGen/CGBuiltin.cpp  | 10 +++
 clang/lib/CodeGen/CGClass.cpp|  3 +
 clang/lib/CodeGen/CGDecl.cpp |  4 +
 clang/lib/CodeGen/CGExpr.cpp |  5 ++
 clang/lib/CodeGen/CGExprCXX.cpp  |  6 ++
 clang/lib/CodeGen/CMakeLists.txt |  1 +
 clang/lib/CodeGen/CodeGenModule.cpp  | 22 +
 clang/lib/CodeGen/MitigationTagging.cpp  | 84 
 clang/lib/CodeGen/MitigationTagging.h| 45 +++
 clang/lib/Driver/ToolChains/Clang.cpp|  3 +
 12 files changed, 190 insertions(+)
 create mode 100644 clang/lib/CodeGen/MitigationTagging.cpp
 create mode 100644 clang/lib/CodeGen/MitigationTagging.h

diff --git a/clang/include/clang/Basic/CodeGenOptions.def 
b/clang/include/clang/Basic/CodeGenOptions.def
index a7f5f1abbb825..76a46ac3e592b 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -191,6 +191,7 @@ CODEGENOPT(NoTypeCheck   , 1, 0) ///< Set when 
-Wa,--no-type-check is enable
 CODEGENOPT(MisExpect , 1, 0) ///< Set when -Wmisexpect is enabled
 CODEGENOPT(EnableSegmentedStacks , 1, 0) ///< Set when -fsplit-stack is 
enabled.
 CODEGENOPT(StackClashProtector, 1, 0) ///< Set when -fstack-clash-protection 
is enabled.
+CODEGENOPT(MitigationAnalysis, 1, 0) ///< Set when -fmitigation-analysis is 
enabled.
 CODEGENOPT(NoImplicitFloat   , 1, 0) ///< Set when -mno-implicit-float is 
enabled.
 CODEGENOPT(NullPointerIsValid , 1, 0) ///< Assume Null pointer deference is 
defined.
 CODEGENOPT(OpenCLCorrectlyRoundedDivSqrt, 1, 0) ///< 
-cl-fp32-correctly-rounded-divide-sqrt
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index d0414aba35209..e50bb5c1c2cb4 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3891,6 +3891,12 @@ defm split_stack : BoolFOption<"split-stack",
   CodeGenOpts<"EnableSegmentedStacks">, DefaultFalse,
   NegFlag,
   PosFlag>;
+defm mitigation_analysis : BoolFOption<"mitigation-analysis",
+  CodeGenOpts<"MitigationAnalysis">, DefaultFalse,
+  PosFlag,
+  NegFlag,
+  BothFlags<[], [ClangOption], " mitigation analysis">>,
+  DocBrief<"Instrument mitigations (CFI, Stack Protectors, Auto-Var-Init, 
StackClashProtection) to analyze their coverage">;
 def fstack_protector_all : Flag<["-"], "fstack-protector-all">, Group,
   HelpText<"Enable stack protectors for all functions">;
 defm stack_clash_protection : BoolFOption<"stack-clash-protection",
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index ab8f19b25fa66..4e180bb1a87cf 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -21,6 +21,7 @@
 #include "CodeGenFunction.h"
 #include "CodeGenModule.h"
 #include "ConstantEmitter.h"
+#include "MitigationTagging.h"
 #include "PatternInit.h"
 #include "TargetInfo.h"
 #include "clang/AST/ASTContext.h"
@@ -83,6 +84,8 @@ static void initializeAlloca(CodeGenFunction &CGF, AllocaInst 
*AI, Value *Size,
   switch (CGF.getLangOpts().getTrivialAutoVarInit()) {
   case LangOptions::TrivialAutoVarInitKind::Uninitialized:
 // Nothing to initialize.
+AttachMitigationMetadataToFunction(CGF, MitigationKey::AUTO_VAR_INIT,
+   false);
 return;
   case LangOptions::TrivialAutoVarInitKind::Zero:
 Byte = CGF.Builder.getInt8(0x00);
@@ -94,6 +97,7 @@ static void initializeAlloca(CodeGenFunction &CGF, AllocaInst 
*AI, Value *Size,
 break;
   }
   }
+  AttachMitigationMetadataToFunction(CGF, MitigationKey::AUTO_VAR_INIT, true);
   if (CGF.CGM.stopAutoInit())
 return;
   auto *I = CGF.Builder.CreateMemSet(AI, Byte, Size, AlignmentInBytes);
@@ -4642,6 +4646,9 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
 AI->setAlignment(SuitableAlignmentInBytes);
 if (BuiltinID != Builtin::BI__builtin_alloca_uninitialized)
   initializeAlloca(*this, AI, Size, SuitableAlignmentInBytes);
+else
+  AttachMitigationMetadataToFunction(*t

[clang] Reapply "[Clang] Improve diagnostics for expansion length mismatch" (PR #121044)

2025-03-14 Thread Younan Zhang via cfe-commits


@@ -749,132 +759,124 @@ ExprResult Sema::CheckPackExpansion(Expr *Pattern, 
SourceLocation EllipsisLoc,
 PackExpansionExpr(Context.DependentTy, Pattern, EllipsisLoc, 
NumExpansions);
 }
 
+static bool IsUnexpandedPackExpansion(const TemplateArgument &TA) {
+  if (!TA.isPackExpansion())
+return false;
+
+  if (TA.getKind() == TemplateArgument::Type)
+return !TA.getAsType()->getAs()->getNumExpansions();
+
+  if (TA.getKind() == TemplateArgument::Expression)
+return !cast(TA.getAsExpr())->getNumExpansions();
+
+  return !TA.getNumTemplateExpansions();
+}
+
 bool Sema::CheckParameterPacksForExpansion(
 SourceLocation EllipsisLoc, SourceRange PatternRange,
 ArrayRef Unexpanded,
 const MultiLevelTemplateArgumentList &TemplateArgs, bool &ShouldExpand,
 bool &RetainExpansion, std::optional &NumExpansions) {
   ShouldExpand = true;
   RetainExpansion = false;
-  std::pair FirstPack;
-  bool HaveFirstPack = false;
-  std::optional NumPartialExpansions;
-  SourceLocation PartiallySubstitutedPackLoc;
-  typedef LocalInstantiationScope::DeclArgumentPack DeclArgumentPack;
+  std::pair FirstPack;
+  std::optional> PartialExpansion;
+  std::optional CurNumExpansions, CurMaximumOfLeastExpansions;
 
-  for (UnexpandedParameterPack ParmPack : Unexpanded) {
+  for (auto [P, Loc] : Unexpanded) {
 // Compute the depth and index for this parameter pack.
-unsigned Depth = 0, Index = 0;
-IdentifierInfo *Name;
-bool IsVarDeclPack = false;
-FunctionParmPackExpr *BindingPack = nullptr;
-
-if (const TemplateTypeParmType *TTP =
-ParmPack.first.dyn_cast()) {
-  Depth = TTP->getDepth();
-  Index = TTP->getIndex();
-  Name = TTP->getIdentifier();
-} else {
-  NamedDecl *ND = cast(ParmPack.first);
-  if (isa(ND))
-IsVarDeclPack = true;
-  else if (isa(ND)) {
+std::optional> Pos;
+unsigned NewPackSize, PendingPackExpansionSize = 0;
+const auto *ND = dyn_cast_if_present(P);
+if (ND) {
+  if (isa(ND)) {
+auto *DAP = dyn_cast(
+*CurrentInstantiationScope->findInstantiationOf(ND));
+if (!DAP) {
+  // We can't expand this function parameter pack, so we can't expand
+  // the pack expansion.
+  ShouldExpand = false;
+  continue;
+}
+NewPackSize = DAP->size();
+  } else if (isa(ND)) {
 // Find the instantiated BindingDecl and check it for a resolved pack.
-llvm::PointerUnion *Instantiation =
-CurrentInstantiationScope->findInstantiationOf(ND);
+llvm::PointerUnion
+*Instantiation = 
CurrentInstantiationScope->findInstantiationOf(ND);
 Decl *B = cast(*Instantiation);
 Expr *BindingExpr = cast(B)->getBinding();
-BindingPack = cast_if_present(BindingExpr);
+auto *BindingPack = cast_if_present(BindingExpr);
 if (!BindingPack) {
   ShouldExpand = false;
   continue;
 }
+NewPackSize = BindingPack->getNumExpansions();
   } else
-std::tie(Depth, Index) = getDepthAndIndex(ND);
-
-  Name = ND->getIdentifier();
+Pos = getDepthAndIndex(ND);
+} else if (const auto *TTP = dyn_cast(P)) {
+  Pos = {TTP->getDepth(), TTP->getIndex()};
+  ND = TTP->getDecl();
+  // FIXME: We either should have some fallback for canonical TTP, or
+  //never have canonical TTP here.
+} else if (const auto *STP =
+   dyn_cast(P)) {
+  NewPackSize = STP->getNumArgs();
+  PendingPackExpansionSize = llvm::count_if(
+  STP->getArgumentPack().getPackAsArray(), IsUnexpandedPackExpansion);
+  ND = STP->getReplacedParameter();
+} else {
+  const auto *SEP = cast(P);
+  NewPackSize = SEP->getArgumentPack().pack_size();
+  PendingPackExpansionSize = llvm::count_if(
+  SEP->getArgumentPack().getPackAsArray(), IsUnexpandedPackExpansion);
+  ND = SEP->getParameterPack();
 }
 
-// Determine the size of this argument pack.
-unsigned NewPackSize, PendingPackExpansionSize = 0;
-if (IsVarDeclPack) {
-  // Figure out whether we're instantiating to an argument pack or not.
-  llvm::PointerUnion *Instantiation =
-  CurrentInstantiationScope->findInstantiationOf(
-  cast(ParmPack.first));
-  if (isa(*Instantiation)) {
-// We could expand this function parameter pack.
-NewPackSize = cast(*Instantiation)->size();
-  } else {
-// We can't expand this function parameter pack, so we can't expand
-// the pack expansion.
-ShouldExpand = false;
-continue;
-  }
-} else if (BindingPack) {
-  NewPackSize = BindingPack->getNumExpansions();
-} else {
+if (Pos) {
   // If we don't have a template argument at this depth/index, then we
   // cannot expand the pack expansion. Make a note of this, but we still
   // want to check any parameter

[clang] [clang] Add diagnostic for unresolved using declaration that shadows template parameters (PR #131328)

2025-03-14 Thread Matheus Izvekov via cfe-commits

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

LGTM

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


[clang] [NFC][analyzer] Framework for multipart checkers (PR #130985)

2025-03-14 Thread Donát Nagy via cfe-commits

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


[clang] [NFC][analyzer] Framework for multipart checkers (PR #130985)

2025-03-14 Thread Donát Nagy via cfe-commits

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


[clang] [llvm] [ARM][Clang] Make `+nosimd` functional for AArch32 Targets (PR #130623)

2025-03-14 Thread David Green via cfe-commits

davemgreen wrote:

Sorry for the delay, my computer got very slow at building things. - What goes 
wrong if ARM::AEK_SIMD is removed from the CPU and architecture definitions? If 
it is needed then there are some other cpu's where it might need to be added 
too. But I'm not sure what needs it. (Target parsing gets quite complex and 
isn't nearly as well documented as it needs to be. We could do with something 
that explains how it is meant to work, at a high level so we can have a 
coherent design).

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


[clang] [clang-tools-extra] [clang][dataflow] For bugprone-unchecked-optional-access report range (PR #131055)

2025-03-14 Thread Jan Voung via cfe-commits

https://github.com/jvoung updated 
https://github.com/llvm/llvm-project/pull/131055

>From b93c10f029fb33e9f7261cbb174d097be4137006 Mon Sep 17 00:00:00 2001
From: Jan Voung 
Date: Thu, 13 Mar 2025 02:26:41 +
Subject: [PATCH 1/3] [clang][dataflow] For bugprone-unchecked-optional-access
 report range

Report the range in diagnostics, in addition to the location
in case the range helps disambiguate a little in chained `->` expressions.

b->a->f->x = 1;
^~~

instead of just:

b->a->f->x = 1;
^

As a followup we should probably also report the location/range
of an `->` if that operator is used. Like:

b->a->f->x = 1;
   ^~
---
 .../bugprone/UncheckedOptionalAccessCheck.cpp   | 17 ++---
 .../Models/UncheckedOptionalAccessModel.h   | 11 +--
 .../Models/UncheckedOptionalAccessModel.cpp | 14 +++---
 .../UncheckedOptionalAccessModelTest.cpp| 10 +-
 4 files changed, 31 insertions(+), 21 deletions(-)

diff --git 
a/clang-tools-extra/clang-tidy/bugprone/UncheckedOptionalAccessCheck.cpp 
b/clang-tools-extra/clang-tidy/bugprone/UncheckedOptionalAccessCheck.cpp
index 0a0e212f345ed..0b51d5677929c 100644
--- a/clang-tools-extra/clang-tidy/bugprone/UncheckedOptionalAccessCheck.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/UncheckedOptionalAccessCheck.cpp
@@ -19,6 +19,7 @@
 namespace clang::tidy::bugprone {
 using ast_matchers::MatchFinder;
 using dataflow::UncheckedOptionalAccessDiagnoser;
+using dataflow::UncheckedOptionalAccessDiagnostic;
 using dataflow::UncheckedOptionalAccessModel;
 
 static constexpr llvm::StringLiteral FuncID("fun");
@@ -52,14 +53,16 @@ void UncheckedOptionalAccessCheck::check(
   UncheckedOptionalAccessDiagnoser Diagnoser(ModelOptions);
   // FIXME: Allow user to set the (defaulted) SAT iterations max for
   // `diagnoseFunction` with config options.
-  if (llvm::Expected> Locs =
-  dataflow::diagnoseFunction(*FuncDecl, 
*Result.Context,
- Diagnoser))
-for (const SourceLocation &Loc : *Locs)
-  diag(Loc, "unchecked access to optional value");
+  if (llvm::Expected>
+  Diags = dataflow::diagnoseFunction(
+  *FuncDecl, *Result.Context, Diagnoser))
+for (const UncheckedOptionalAccessDiagnostic &Diag : *Diags) {
+  diag(Diag.Range.getBegin(), "unchecked access to optional value")
+  << Diag.Range;
+}
   else
-llvm::consumeError(Locs.takeError());
+llvm::consumeError(Diags.takeError());
 }
 
 } // namespace clang::tidy::bugprone
diff --git 
a/clang/include/clang/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.h
 
b/clang/include/clang/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.h
index fb11c2e230e32..696c9f4a6cf5c 100644
--- 
a/clang/include/clang/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.h
+++ 
b/clang/include/clang/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.h
@@ -20,6 +20,7 @@
 #include "clang/Analysis/FlowSensitive/CachedConstAccessorsLattice.h"
 #include "clang/Analysis/FlowSensitive/DataflowAnalysis.h"
 #include "clang/Analysis/FlowSensitive/DataflowEnvironment.h"
+#include "clang/Analysis/FlowSensitive/MatchSwitch.h"
 #include "clang/Analysis/FlowSensitive/NoopLattice.h"
 #include "clang/Basic/SourceLocation.h"
 #include "llvm/ADT/SmallVector.h"
@@ -71,12 +72,17 @@ class UncheckedOptionalAccessModel
   TransferMatchSwitch;
 };
 
+/// Diagnostic information for an unchecked optional access.
+struct UncheckedOptionalAccessDiagnostic {
+  CharSourceRange Range;
+};
+
 class UncheckedOptionalAccessDiagnoser {
 public:
   UncheckedOptionalAccessDiagnoser(
   UncheckedOptionalAccessModelOptions Options = {});
 
-  llvm::SmallVector
+  llvm::SmallVector
   operator()(const CFGElement &Elt, ASTContext &Ctx,
  const TransferStateForDiagnostics
  &State) {
@@ -84,7 +90,8 @@ class UncheckedOptionalAccessDiagnoser {
   }
 
 private:
-  CFGMatchSwitch>
+  CFGMatchSwitch>
   DiagnoseMatchSwitch;
 };
 
diff --git 
a/clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp 
b/clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
index c28424fac8fef..c1d7f6c015558 100644
--- a/clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
+++ b/clang/lib/Analysis/FlowSensitive/Models/UncheckedOptionalAccessModel.cpp
@@ -1120,8 +1120,8 @@ auto buildTransferMatchSwitch() {
   .Build();
 }
 
-llvm::SmallVector diagnoseUnwrapCall(const Expr *ObjectExpr,
- const Environment &Env) {
+llvm::SmallVector
+diagnoseUnwrapCall(const Expr *ObjectExpr, const Environment &Env) {
   if (auto *OptionalLoc = cast_or_null(
   getLocBehindPossiblePointer(*ObjectExpr, Env))) {
 auto *Prop = Env.getValue(locForHasValue(*OptionalLoc));
@@ -1132,9 +1132,8 @@ llvm::SmallVector 
diagnoseUnwrapCall(const Expr *ObjectExpr,
   }
 
   // Record that this unw

[clang] [clang-format] Add support for absl nullability macros (PR #130346)

2025-03-14 Thread Jan Voung via cfe-commits

jvoung wrote:

Thank you Owen for the review and helping merge, and thank you all for helping 
arrive at a solution! 

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


[clang] [NFC][PowerPC] cleaned dead code of PPC.cpp and PPC.h (PR #130994)

2025-03-14 Thread zhijian lin via cfe-commits

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


[clang-tools-extra] [clang-tidy] Add new check bugprone-capture-this-by-field (PR #130297)

2025-03-14 Thread Baranov Victor via cfe-commits


@@ -0,0 +1,36 @@
+.. title:: clang-tidy - bugprone-capturing-this-in-member-variable
+
+bugprone-capturing-this-in-member-variable
+==
+
+Finds lambda captures that capture the ``this`` pointer and store it as class
+members without handle the copy and move constructors and the assignments.
+
+Capture this in a lambda and store it as a class member is dangerous because 
the
+lambda can outlive the object it captures. Especially when the object is copied
+or moved, the captured ``this`` pointer will be implicitly propagated to the
+new object. Most of the time, people will believe that the captured ``this``
+pointer points to the new object, which will lead to bugs.
+
+.. code-block:: c++
+
+  struct C {
+C() : Captured([this]() -> C const * { return this; }) {}
+std::function Captured;
+  };
+
+  void foo() {
+C v1{};
+C v2 = v1; // v2.Captured capture v1's this pointer
+assert(v2.Captured() == v1.Captured()); // v2.Captured capture v1's this 
pointer
+assert(v2.Captured() == &v2); // assertion failed.
+  }
+
+Possible fixes include refactoring the function object into a class member
+method or passing the this pointer as a parameter.

vbvictor wrote:

```suggestion
method or passing the ``this`` pointer as a parameter.
```

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


[clang] [clang-tools-extra] [clang-tidy] Avoid processing declarations in system headers (PR #128150)

2025-03-14 Thread via cfe-commits

tonygould wrote:

This is huge. @carlosgalvezp thank you so much for all the hard work on the 
development and getting this merged. I love clang-tidy, but the build time has 
made it very difficult to use (and socialize) on large projects, especially for 
CICD.

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


[clang-tools-extra] [clang-tidy] Add an option to treat warnings as errors (PR #128221)

2025-03-14 Thread via cfe-commits

https://github.com/juru1234 updated 
https://github.com/llvm/llvm-project/pull/128221

>From 968350e01d4a0407d58b89c8859c3c6ec7f42f15 Mon Sep 17 00:00:00 2001
From: Julian Ruess 
Date: Fri, 21 Feb 2025 20:42:46 +0100
Subject: [PATCH] [clang-tidy] Add an option to treat warnings as errors

This patch allows to treat warnings as erros using clang-tidy-diff.

Co-authored-by: Piotr Zegar 
---
 clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py | 7 +++
 clang-tools-extra/docs/ReleaseNotes.rst  | 3 +++
 2 files changed, 10 insertions(+)

diff --git a/clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py 
b/clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
index 33de2077dfb1a..0f8ac7344aca3 100755
--- a/clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
+++ b/clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
@@ -259,6 +259,11 @@ def main():
 action="store_true",
 help="Only check files in the compilation database",
 )
+parser.add_argument(
+"-warnings-as-errors",
+help="Upgrades clang-tidy warnings to errors. Same format as 
'-checks'.",
+default="",
+)
 
 clang_tidy_args = []
 argv = sys.argv[1:]
@@ -374,6 +379,8 @@ def main():
 common_clang_tidy_args.append("-extra-arg-before=%s" % arg)
 for plugin in args.plugins:
 common_clang_tidy_args.append("-load=%s" % plugin)
+if args.warnings_as_errors:
+common_clang_tidy_args.append("-warnings-as-errors=" + 
args.warnings_as_errors)
 
 for name in lines_by_file:
 line_filter_json = json.dumps(
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 41ff1c1016f25..8d016307fba83 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -88,6 +88,9 @@ Improvements to clang-query
 Improvements to clang-tidy
 --
 
+- Improved :program:`clang-tidy-diff.py` script. Add the `-warnings-as-errors`
+  to treat warnings as errors.
+
 New checks
 ^^
 

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


[clang-tools-extra] [clang-tidy] Add new check bugprone-capture-this-by-field (PR #130297)

2025-03-14 Thread Baranov Victor via cfe-commits

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

LGTM, but please wait for others to review

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


[clang] [analyzer] Introduce per-entry-point statistics (PR #131175)

2025-03-14 Thread Donát Nagy via cfe-commits

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


[clang] [Clang] Rename SecondArgIsLastNamedArgument for clarity and consistency (PR #131346)

2025-03-14 Thread Imad Aldij via cfe-commits

https://github.com/imdj created https://github.com/llvm/llvm-project/pull/131346

Change the name of the control variable `SecondArgIsLastNamedArgument` to 
`SecondArgIsLastNonVariadicArgument`  for clarity and consistency.

Following feedback on earlier PR that was merged: 
- #131238

>From 3f4932668ba8b8f74136dc297f98f0f9494da90e Mon Sep 17 00:00:00 2001
From: Imad Aldij <69906094+i...@users.noreply.github.com>
Date: Fri, 14 Mar 2025 17:34:39 +0200
Subject: [PATCH] [Clang] Rename SecondArgIsLastNamedArgument for clarity

Update the variable and description to reflect its meaning and align with the 
corresponding warning diagnostic message
---
 clang/lib/Sema/SemaChecking.cpp | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index e99e30d75df94..c8e8cb6f4c150 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -4867,14 +4867,14 @@ bool Sema::BuiltinVAStart(unsigned BuiltinID, CallExpr 
*TheCall) {
   // current function or method. In C23 mode, if the second argument is an
   // integer constant expression with value 0, then we don't bother with this
   // check.
-  bool SecondArgIsLastNamedArgument = false;
+  bool SecondArgIsLastNonVariadicArgument = false;
   const Expr *Arg = TheCall->getArg(1)->IgnoreParenCasts();
   if (std::optional Val =
   TheCall->getArg(1)->getIntegerConstantExpr(Context);
   Val && LangOpts.C23 && *Val == 0)
 return false;
 
-  // These are valid if SecondArgIsLastNamedArgument is false after the next
+  // These are valid if SecondArgIsLastNonVariadicArgument is false after the 
next
   // block.
   QualType Type;
   SourceLocation ParamLoc;
@@ -4882,7 +4882,7 @@ bool Sema::BuiltinVAStart(unsigned BuiltinID, CallExpr 
*TheCall) {
 
   if (const DeclRefExpr *DR = dyn_cast(Arg)) {
 if (const ParmVarDecl *PV = dyn_cast(DR->getDecl())) {
-  SecondArgIsLastNamedArgument = PV == LastParam;
+  SecondArgIsLastNonVariadicArgument = PV == LastParam;
 
   Type = PV->getType();
   ParamLoc = PV->getLocation();
@@ -4891,7 +4891,7 @@ bool Sema::BuiltinVAStart(unsigned BuiltinID, CallExpr 
*TheCall) {
 }
   }
 
-  if (!SecondArgIsLastNamedArgument)
+  if (!SecondArgIsLastNonVariadicArgument)
 Diag(TheCall->getArg(1)->getBeginLoc(),
  diag::warn_second_arg_of_va_start_not_last_non_variadic_param);
   else if (IsCRegister || Type->isReferenceType() ||

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


[clang] [Clang] Rename SecondArgIsLastNamedArgument for clarity and consistency (PR #131346)

2025-03-14 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Imad Aldij (imdj)


Changes

Change the name of the control variable `SecondArgIsLastNamedArgument` to 
`SecondArgIsLastNonVariadicArgument`  for clarity and consistency.

Following feedback on earlier PR that was merged: 
- #131238

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


1 Files Affected:

- (modified) clang/lib/Sema/SemaChecking.cpp (+4-4) 


``diff
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index e99e30d75df94..c8e8cb6f4c150 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -4867,14 +4867,14 @@ bool Sema::BuiltinVAStart(unsigned BuiltinID, CallExpr 
*TheCall) {
   // current function or method. In C23 mode, if the second argument is an
   // integer constant expression with value 0, then we don't bother with this
   // check.
-  bool SecondArgIsLastNamedArgument = false;
+  bool SecondArgIsLastNonVariadicArgument = false;
   const Expr *Arg = TheCall->getArg(1)->IgnoreParenCasts();
   if (std::optional Val =
   TheCall->getArg(1)->getIntegerConstantExpr(Context);
   Val && LangOpts.C23 && *Val == 0)
 return false;
 
-  // These are valid if SecondArgIsLastNamedArgument is false after the next
+  // These are valid if SecondArgIsLastNonVariadicArgument is false after the 
next
   // block.
   QualType Type;
   SourceLocation ParamLoc;
@@ -4882,7 +4882,7 @@ bool Sema::BuiltinVAStart(unsigned BuiltinID, CallExpr 
*TheCall) {
 
   if (const DeclRefExpr *DR = dyn_cast(Arg)) {
 if (const ParmVarDecl *PV = dyn_cast(DR->getDecl())) {
-  SecondArgIsLastNamedArgument = PV == LastParam;
+  SecondArgIsLastNonVariadicArgument = PV == LastParam;
 
   Type = PV->getType();
   ParamLoc = PV->getLocation();
@@ -4891,7 +4891,7 @@ bool Sema::BuiltinVAStart(unsigned BuiltinID, CallExpr 
*TheCall) {
 }
   }
 
-  if (!SecondArgIsLastNamedArgument)
+  if (!SecondArgIsLastNonVariadicArgument)
 Diag(TheCall->getArg(1)->getBeginLoc(),
  diag::warn_second_arg_of_va_start_not_last_non_variadic_param);
   else if (IsCRegister || Type->isReferenceType() ||

``




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


[clang] [Clang] Rename SecondArgIsLastNamedArgument for clarity and consistency (PR #131346)

2025-03-14 Thread via cfe-commits

github-actions[bot] wrote:

⚠️ We detected that you are using a GitHub private e-mail address to contribute 
to the repo. Please turn off [Keep my email addresses 
private](https://github.com/settings/emails) setting in your account. See 
[LLVM 
Discourse](https://discourse.llvm.org/t/hidden-emails-on-github-should-we-do-something-about-it)
 for more information.

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


[clang] [Clang] Rename SecondArgIsLastNamedArgument for clarity and consistency (PR #131346)

2025-03-14 Thread Imad Aldij via cfe-commits

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


[clang] [NFC][analyzer] Framework for multipart checkers (PR #130985)

2025-03-14 Thread Donát Nagy via cfe-commits

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


[clang] Add diagnostic for unresolved using declaration that shadows template parameters (PR #131328)

2025-03-14 Thread via cfe-commits

https://github.com/NewSigma created 
https://github.com/llvm/llvm-project/pull/131328

Fix #129411 

>From df25106771358fd30eec246b7f1c35f4625f63f9 Mon Sep 17 00:00:00 2001
From: NewSigma 
Date: Fri, 14 Mar 2025 20:35:38 +0800
Subject: [PATCH] Fix #129411

---
 clang/docs/ReleaseNotes.rst | 1 +
 clang/lib/Sema/SemaDeclCXX.cpp  | 4 
 clang/test/Parser/cxx-template-decl.cpp | 8 
 3 files changed, 13 insertions(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 6456acfcc2ada..bf042c50e8b6d 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -310,6 +310,7 @@ Bug Fixes to C++ Support
 - Clang now correctly parses ``if constexpr`` expressions in immediate 
function context. (#GH123524)
 - Fixed an assertion failure affecting code that uses C++23 "deducing this". 
(#GH130272)
 - Clang now properly instantiates destructors for initialized members within 
non-delegating constructors. (#GH93251)
+- Correctly diagnoses if unresolved using declarations shadows template 
paramters (#GH129411)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 673f7eafca7fb..a02bd8335fa20 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -12895,6 +12895,10 @@ NamedDecl *Sema::BuildUsingDeclaration(
   SS, NameInfo, IdentLoc))
   return nullptr;
 
+if (Previous.isSingleResult() &&
+Previous.getFoundDecl()->isTemplateParameter())
+  DiagnoseTemplateParameterShadow(IdentLoc, Previous.getFoundDecl());
+
 if (HasTypenameKeyword) {
   // FIXME: not all declaration name kinds are legal here
   D = UnresolvedUsingTypenameDecl::Create(Context, CurContext,
diff --git a/clang/test/Parser/cxx-template-decl.cpp 
b/clang/test/Parser/cxx-template-decl.cpp
index 476341686a64b..a0460da7563ed 100644
--- a/clang/test/Parser/cxx-template-decl.cpp
+++ b/clang/test/Parser/cxx-template-decl.cpp
@@ -109,6 +109,14 @@ template class T> struct shadow8 { // 
expected-note{{template
   template class T> struct inner; // 
expected-error{{declaration of 'T' shadows template parameter}}
 };
 
+template
+class shadow9_;
+
+template // expected-note{{template parameter is declared here}}
+class shadow9 : public shadow9_ {
+  using typename shadow9_::T; // expected-error{{declaration of 'T' shadows 
template parameter}}
+};
+
 // Non-type template parameters in scope
 template
 void f(int& i) {

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


[clang-tools-extra] 1a68269 - [clang-tidy] support pointee mutation check in misc-const-correctness (#130494)

2025-03-14 Thread via cfe-commits

Author: Congcong Cai
Date: 2025-03-14T21:18:43+08:00
New Revision: 1a68269e280503650299805412fdbc52be25c6bb

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

LOG: [clang-tidy] support pointee mutation check in misc-const-correctness 
(#130494)

Co-authored-by: Baranov Victor 

Added: 

clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-pointer-as-pointers-values.cpp

clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-pointer-as-pointers.cpp

Modified: 
clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.h
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/docs/clang-tidy/checks/misc/const-correctness.rst

clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-allowed-types.cpp

clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-pointer-as-values.cpp

clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-transform-pointer-as-values.cpp

clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-transform-values.cpp

clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values-before-cxx23.cpp
clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-values.cpp

clang-tools-extra/test/clang-tidy/checkers/misc/const-correctness-wrong-config.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp 
b/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
index dbe59233df699..50e6722badf50 100644
--- a/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
+++ b/clang-tools-extra/clang-tidy/misc/ConstCorrectnessCheck.cpp
@@ -13,6 +13,7 @@
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
+#include 
 
 using namespace clang::ast_matchers;
 
@@ -37,36 +38,54 @@ AST_MATCHER(Type, isDependentType) { return 
Node.isDependentType(); }
 ConstCorrectnessCheck::ConstCorrectnessCheck(StringRef Name,
  ClangTidyContext *Context)
 : ClangTidyCheck(Name, Context),
-  AnalyzeValues(Options.get("AnalyzeValues", true)),
+  AnalyzePointers(Options.get("AnalyzePointers", true)),
   AnalyzeReferences(Options.get("AnalyzeReferences", true)),
+  AnalyzeValues(Options.get("AnalyzeValues", true)),
+
+  WarnPointersAsPointers(Options.get("WarnPointersAsPointers", true)),
   WarnPointersAsValues(Options.get("WarnPointersAsValues", false)),
-  TransformValues(Options.get("TransformValues", true)),
-  TransformReferences(Options.get("TransformReferences", true)),
+
+  TransformPointersAsPointers(
+  Options.get("TransformPointersAsPointers", true)),
   TransformPointersAsValues(
   Options.get("TransformPointersAsValues", false)),
+  TransformReferences(Options.get("TransformReferences", true)),
+  TransformValues(Options.get("TransformValues", true)),
+
   AllowedTypes(
   utils::options::parseStringList(Options.get("AllowedTypes", ""))) {
-  if (AnalyzeValues == false && AnalyzeReferences == false)
+  if (AnalyzeValues == false && AnalyzeReferences == false &&
+  AnalyzePointers == false)
 this->configurationDiag(
 "The check 'misc-const-correctness' will not "
-"perform any analysis because both 'AnalyzeValues' and "
-"'AnalyzeReferences' are false.");
+"perform any analysis because 'AnalyzeValues', "
+"'AnalyzeReferences' and 'AnalyzePointers' are false.");
 }
 
 void ConstCorrectnessCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
-  Options.store(Opts, "AnalyzeValues", AnalyzeValues);
+  Options.store(Opts, "AnalyzePointers", AnalyzePointers);
   Options.store(Opts, "AnalyzeReferences", AnalyzeReferences);
+  Options.store(Opts, "AnalyzeValues", AnalyzeValues);
+
+  Options.store(Opts, "WarnPointersAsPointers", WarnPointersAsPointers);
   Options.store(Opts, "WarnPointersAsValues", WarnPointersAsValues);
 
-  Options.store(Opts, "TransformValues", TransformValues);
-  Options.store(Opts, "TransformReferences", TransformReferences);
+  Options.store(Opts, "TransformPointersAsPointers",
+TransformPointersAsPointers);
   Options.store(Opts, "TransformPointersAsValues", TransformPointersAsValues);
+  Options.store(Opts, "TransformReferences", TransformReferences);
+  Options.store(Opts, "TransformValues", TransformValues);
+
   Options.store(Opts, "AllowedTypes",
 utils::options::serializeStringList(AllowedTypes));
 }
 
 void ConstCorrectnessCheck::registerMatchers(MatchFinder *Finder) {
-  const auto ConstType = hasType(isConstQualified());
+  const auto ConstType = hasTyp

[clang] [Clang] Remove use of 'temporary' toolchains for offload deduction (PR #131332)

2025-03-14 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-driver

Author: Joseph Huber (jhuber6)


Changes

Summary:
We neededa toolchain to get the GPU architectures when compiling with
OpenMP. This kind of breaks the toolchain model because these are cached
all over the place. Instead of making a new one, just create both of
them unconditionally. It's not like this is saving any work since we
still needed to create both toolchains in the earlier case.

Fixes: https://github.com/llvm/llvm-project/issues/131325


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


2 Files Affected:

- (modified) clang/lib/Driver/Driver.cpp (+8-16) 
- (modified) clang/test/Driver/offload-Xarch.c (-2) 


``diff
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index ba0a7c2180867..848b27012976d 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -1040,23 +1040,15 @@ void 
Driver::CreateOffloadingDeviceToolChains(Compilation &C,
   // We need to temporarily create these toolchains so that we can access
   // tools for inferring architectures.
   llvm::DenseSet Archs;
-  if (NVPTXTriple) {
-auto TempTC = std::make_unique(
-*this, *NVPTXTriple, *HostTC, C.getInputArgs());
-for (StringRef Arch : getOffloadArchs(
- C, C.getArgs(), Action::OFK_OpenMP, &*TempTC, true))
-  Archs.insert(Arch);
-  }
-  if (AMDTriple) {
-auto TempTC = std::make_unique(
-*this, *AMDTriple, *HostTC, C.getInputArgs());
-for (StringRef Arch : getOffloadArchs(
- C, C.getArgs(), Action::OFK_OpenMP, &*TempTC, true))
-  Archs.insert(Arch);
-  }
-  if (!AMDTriple && !NVPTXTriple) {
+  for (const std::optional &TT : {NVPTXTriple, AMDTriple}) {
+if (!TT)
+  continue;
+
+auto &TC =
+getOffloadToolChain(C.getInputArgs(), Action::OFK_OpenMP, *TT,
+C.getDefaultToolChain().getTriple());
 for (StringRef Arch :
- getOffloadArchs(C, C.getArgs(), Action::OFK_OpenMP, nullptr, 
true))
+ getOffloadArchs(C, C.getArgs(), Action::OFK_OpenMP, &TC, true))
   Archs.insert(Arch);
   }
 
diff --git a/clang/test/Driver/offload-Xarch.c 
b/clang/test/Driver/offload-Xarch.c
index 0f8f40a5cbd74..8856dac198465 100644
--- a/clang/test/Driver/offload-Xarch.c
+++ b/clang/test/Driver/offload-Xarch.c
@@ -1,5 +1,3 @@
-// UNSUPPORTED: target={{.*darwin.*}}
-
 // RUN: %clang --target=x86_64-unknown-linux-gnu -x cuda %s -Xarch_nvptx64 -O3 
-S -nogpulib -nogpuinc -### 2>&1 | FileCheck -check-prefix=O3ONCE %s
 // RUN: %clang -x cuda %s -Xarch_device -O3 -S -nogpulib -nogpuinc -### 2>&1 | 
FileCheck -check-prefix=O3ONCE %s
 // RUN: %clang -x hip %s -Xarch_amdgcn -O3 -S -nogpulib -nogpuinc -### 2>&1 | 
FileCheck -check-prefix=O3ONCE %s

``




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


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

2025-03-14 Thread Carlos Alberto Enciso via cfe-commits

CarlosAlbertoEnciso wrote:

> > To work out which class A this refers to would involve parsing the template 
> > parameter correctly and matching to the correct anonymous namespace. While 
> > this technically isn’t impossible
> 
> Are you sure about that? Anonymous types are confined to a single CU 
> statically, but their values can definitely leak out at runtime. So if I'm 
> stopped in a random CU and I see am object whose dynamic type is `(anonymous 
> namespace)::X`, I don't see how one could determine which type (out of 
> possibly many) is that vtable referring to.

@labath I will double check with our debugger team.

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


[clang-tools-extra] [clang-tidy] Add new check bugprone-capture-this-by-field (PR #130297)

2025-03-14 Thread Baranov Victor via cfe-commits


@@ -0,0 +1,36 @@
+.. title:: clang-tidy - bugprone-capturing-this-in-member-variable
+
+bugprone-capturing-this-in-member-variable
+==
+
+Finds lambda captures that capture the ``this`` pointer and store it as class
+members without handle the copy and move constructors and the assignments.
+
+Capture this in a lambda and store it as a class member is dangerous because 
the
+lambda can outlive the object it captures. Especially when the object is copied
+or moved, the captured ``this`` pointer will be implicitly propagated to the
+new object. Most of the time, people will believe that the captured ``this``
+pointer points to the new object, which will lead to bugs.
+
+.. code-block:: c++
+
+  struct C {
+C() : Captured([this]() -> C const * { return this; }) {}
+std::function Captured;
+  };
+
+  void foo() {
+C v1{};
+C v2 = v1; // v2.Captured capture v1's this pointer
+assert(v2.Captured() == v1.Captured()); // v2.Captured capture v1's this 
pointer

vbvictor wrote:

```suggestion
assert(v2.Captured() == v1.Captured()); // v2.Captured capture v1's 'this' 
pointer
```

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


[clang] Warn about virtual methods in `final` classes (PR #131188)

2025-03-14 Thread Devon Loehr via cfe-commits

https://github.com/DKLoehr updated 
https://github.com/llvm/llvm-project/pull/131188

>From fbd474fb5ae3adeaf1644a4d44e916e4d7c66395 Mon Sep 17 00:00:00 2001
From: Devon Loehr 
Date: Thu, 13 Mar 2025 17:34:27 +
Subject: [PATCH 1/5] Initial warning commit

---
 clang/include/clang/Basic/DiagnosticGroups.td |  2 ++
 .../clang/Basic/DiagnosticSemaKinds.td|  3 +++
 clang/lib/Sema/SemaDeclCXX.cpp|  5 
 .../SemaCXX/unnecessary-virtual-specifier.cpp | 27 +++
 4 files changed, 37 insertions(+)
 create mode 100644 clang/test/SemaCXX/unnecessary-virtual-specifier.cpp

diff --git a/clang/include/clang/Basic/DiagnosticGroups.td 
b/clang/include/clang/Basic/DiagnosticGroups.td
index fac80fb4009aa..65593ddcb8608 100644
--- a/clang/include/clang/Basic/DiagnosticGroups.td
+++ b/clang/include/clang/Basic/DiagnosticGroups.td
@@ -372,6 +372,8 @@ def CXX11WarnInconsistentOverrideMethod :
 def CXX11WarnSuggestOverrideDestructor : 
DiagGroup<"suggest-destructor-override">;
 def CXX11WarnSuggestOverride : DiagGroup<"suggest-override">;
 
+def WarnUnnecessaryVirtualSpecifier : 
DiagGroup<"unnecessary-virtual-specifier">;
+
 // Original name of this warning in Clang
 def : DiagGroup<"c++0x-narrowing", [CXX11Narrowing]>;
 
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 8e6e6e892cdd7..a87cf7e674b4c 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -2706,6 +2706,9 @@ def warn_final_dtor_non_final_class : Warning<
   InGroup;
 def note_final_dtor_non_final_class_silence : Note<
   "mark %0 as '%select{final|sealed}1' to silence this warning">;
+def warn_unnecessary_virtual_specifier : Warning<
+  "virtual method %0 is inside a 'final' class and can never be overridden">,
+  InGroup;
 
 // C++11 attributes
 def err_repeat_attribute : Error<"%0 attribute cannot be repeated">;
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index dd779ee377309..1b2e494956d4b 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -7193,10 +7193,15 @@ void Sema::CheckCompletedCXXClass(Scope *S, 
CXXRecordDecl *Record) {
 // class without overriding any.
 if (!M->isStatic())
   DiagnoseHiddenVirtualMethods(M);
+
 if (M->hasAttr())
   HasMethodWithOverrideControl = true;
 else if (M->size_overridden_methods() > 0)
   HasOverridingMethodWithoutOverrideControl = true;
+
+// See if a method is marked as virtual inside of a final class.
+if (M->isVirtualAsWritten() && Record->isEffectivelyFinal())
+  Diag(M->getLocation(), diag::warn_unnecessary_virtual_specifier) << 
M;
   }
 
   if (!isa(M))
diff --git a/clang/test/SemaCXX/unnecessary-virtual-specifier.cpp 
b/clang/test/SemaCXX/unnecessary-virtual-specifier.cpp
new file mode 100644
index 0..eb8397d9ade45
--- /dev/null
+++ b/clang/test/SemaCXX/unnecessary-virtual-specifier.cpp
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -Wunnecessary-virtual-specifier 
-Wsuggest-override %s
+
+struct Foo final {
+  Foo() = default;
+   virtual ~Foo() = default;  // expected-warning 
{{virtual method}}
+   virtual Foo& operator=(Foo& other) = default;  // expected-warning 
{{virtual method}}
+   virtual Foo& operator=(Foo&& other) = default; // expected-warning 
{{virtual method}}
+   void f();
+  virtual void f(int);   // expected-warning {{virtual 
method}}
+  int g(int x) { return x; };
+  virtual int g(bool);   // expected-warning {{virtual 
method}}
+  static int s();
+};
+
+struct BarBase {
+  virtual ~BarBase() = delete;
+   virtual void virt() {}
+   virtual int virt(int);
+  int nonvirt();
+};
+
+struct Bar final : BarBase {
+  ~Bar() override = delete;
+   void virt() override {};
+   virtual int virt(int) override;// expected-warning 
{{virtual method}}
+  int nonvirt();
+};

>From 4a16ef81a4882785708a4973f78586119235e8f5 Mon Sep 17 00:00:00 2001
From: Devon Loehr 
Date: Thu, 13 Mar 2025 17:59:39 +
Subject: [PATCH 2/5] Add documentation

---
 clang/docs/ReleaseNotes.rst   |  3 +++
 clang/include/clang/Basic/DiagnosticGroups.td | 11 ++-
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 8989124611e66..15858631c17b7 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -247,6 +247,9 @@ Improvements to Clang's diagnostics
 - The ``-Wsign-compare`` warning now treats expressions with bitwise not(~) 
and minus(-) as signed integers 
   except for the case where the operand is an unsigned integer
   and throws warning if they are compared with unsigned integers (##18878).
+- The ``-Wunnecessary-virtual-specifier`` warning has

[clang] [clang] Fix inaccurate wording of warn_second_arg_of_va_start_not_last_named_param (PR #131238)

2025-03-14 Thread Imad Aldij via cfe-commits


@@ -4893,7 +4893,7 @@ bool Sema::BuiltinVAStart(unsigned BuiltinID, CallExpr 
*TheCall) {
 
   if (!SecondArgIsLastNamedArgument)
 Diag(TheCall->getArg(1)->getBeginLoc(),
- diag::warn_second_arg_of_va_start_not_last_named_param);

imdj wrote:

What is the recommended action here? Is it worth it to open a new PR?

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


[clang] [clang] Avoid doing C++20 aggregate init during copy-initialization (PR #131320)

2025-03-14 Thread via cfe-commits

offsetof wrote:

> I don't think this resolves the original issue.
> Part of the problem is that we are missing a diagnostic saying the implicit 
> constructor is deleted (and why).

Fair enough; I linked that issue because the nonsensical diagnostic mentioned 
there ("no viable conversion from `S` to `int`") is a side-effect of the bug 
fixed by this PR. With the change applied, we get the usual "no matching 
constructor" with a list of candidates. But if we want something else, then the 
issue should remain open.


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


[clang] [clang] Fix inaccurate wording of warn_second_arg_of_va_start_not_last_named_param (PR #131238)

2025-03-14 Thread Erich Keane via cfe-commits


@@ -4893,7 +4893,7 @@ bool Sema::BuiltinVAStart(unsigned BuiltinID, CallExpr 
*TheCall) {
 
   if (!SecondArgIsLastNamedArgument)
 Diag(TheCall->getArg(1)->getBeginLoc(),
- diag::warn_second_arg_of_va_start_not_last_named_param);

erichkeane wrote:

If you'd like, a new PR would be greatly appreciated!

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


[clang] Warn about virtual methods in `final` classes (PR #131188)

2025-03-14 Thread Devon Loehr via cfe-commits


@@ -0,0 +1,28 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -Wunnecessary-virtual-specifier %s
+
+struct Foo final {
+  Foo() = default;
+  virtual ~Foo() = default;  // expected-warning {{virtual 
method}}
+  virtual Foo& operator=(Foo& other) = default;  // expected-warning {{virtual 
method}}
+  virtual Foo& operator=(Foo&& other) = default; // expected-warning {{virtual 
method}}
+  void f();
+  virtual void f(int);   // expected-warning {{virtual 
method}}
+  int g(int x) { return x; };
+  virtual int g(bool);   // expected-warning {{virtual 
method}}
+  static int s();
+};
+
+struct BarBase {
+  virtual ~BarBase() = delete;
+  virtual void virt() {}
+  virtual int virt(int);
+  int nonvirt();
+};
+
+struct Bar final : BarBase {
+  ~Bar() override = delete;
+  void virt() override {};
+  // `virtual ... override;` is a common pattern, so don't warn
+  virtual int virt(int) override;

DKLoehr wrote:

Yes, good catch.

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


[clang] Warn about virtual methods in `final` classes (PR #131188)

2025-03-14 Thread Devon Loehr via cfe-commits


@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -Wunnecessary-virtual-specifier %s
+
+struct Foo final {
+  Foo() = default;
+   virtual ~Foo() = default;  // expected-warning 
{{virtual method}}
+   virtual Foo& operator=(Foo& other) = default;  // expected-warning 
{{virtual method}}
+   virtual Foo& operator=(Foo&& other) = default; // expected-warning 
{{virtual method}}
+   void f();
+  virtual void f(int);   // expected-warning {{virtual 
method}}
+  int g(int x) { return x; };
+  virtual int g(bool);   // expected-warning {{virtual 
method}}
+  static int s();
+};
+
+struct BarBase {
+  virtual ~BarBase() = delete;
+   virtual void virt() {}
+   virtual int virt(int);
+  int nonvirt();
+};
+
+struct Bar final : BarBase {
+  ~Bar() override = delete;
+   void virt() override {};
+   virtual int virt(int) override;// expected-warning 
{{virtual method}}

DKLoehr wrote:

Alright, disabled for `virtual...override`.

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


[clang] [llvm] Reapply "[AArch64][SVE] Improve fixed-length addressing modes. (#130263)" (PR #130625)

2025-03-14 Thread Paul Walker via cfe-commits

https://github.com/paulwalker-arm approved this pull request.


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


[clang] [clang] Remove usage of llvm-spirv in clang LIT tests (PR #131158)

2025-03-14 Thread Nick Sarnie via cfe-commits

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


[clang] f2541ce - [clang] Remove usage of llvm-spirv in clang LIT tests (#131158)

2025-03-14 Thread via cfe-commits

Author: Nick Sarnie
Date: 2025-03-14T15:18:13Z
New Revision: f2541cee44edca653326895f51bea4561394d6c7

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

LOG: [clang] Remove usage of llvm-spirv in clang LIT tests (#131158)

We use the backend now, so remove the requirement from the only test
that actually executes the translator and remove the LIT requirement
variable.

Signed-off-by: Sarnie, Nick 

Added: 


Modified: 
clang/test/Tooling/clang-linker-wrapper-spirv-elf.cpp
clang/test/Tooling/lit.local.cfg

Removed: 




diff  --git a/clang/test/Tooling/clang-linker-wrapper-spirv-elf.cpp 
b/clang/test/Tooling/clang-linker-wrapper-spirv-elf.cpp
index 9b16727d74192..af98904677283 100644
--- a/clang/test/Tooling/clang-linker-wrapper-spirv-elf.cpp
+++ b/clang/test/Tooling/clang-linker-wrapper-spirv-elf.cpp
@@ -1,7 +1,7 @@
 // Verify the ELF packaging of OpenMP SPIR-V device images.
 // REQUIRES: system-linux
 // REQUIRES: spirv-tools
-// REQUIRES: llvm-spirv
+// REQUIRES: spirv-registered-target
 // RUN: mkdir -p %t_tmp
 // RUN: cd %t_tmp
 // RUN: %clangxx -fopenmp -fopenmp-targets=spirv64-intel -nogpulib -c -o 
%t_clang-linker-wrapper-spirv-elf.o %s

diff  --git a/clang/test/Tooling/lit.local.cfg 
b/clang/test/Tooling/lit.local.cfg
index 61f328c91e4d3..46d32e6ebf454 100644
--- a/clang/test/Tooling/lit.local.cfg
+++ b/clang/test/Tooling/lit.local.cfg
@@ -9,6 +9,3 @@ if config.spirv_tools_tests:
 config.substitutions.append(("spirv-val", 
os.path.join(config.llvm_tools_dir, "spirv-val")))
 config.substitutions.append(("spirv-as", 
os.path.join(config.llvm_tools_dir, "spirv-as")))
 config.substitutions.append(("spirv-link", 
os.path.join(config.llvm_tools_dir, "spirv-link")))
-
-if lit.util.which("llvm-spirv"):
-config.available_features.add("llvm-spirv")



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


[clang] [analyzer] Introduce per-entry-point statistics (PR #131175)

2025-03-14 Thread Donát Nagy via cfe-commits


@@ -0,0 +1,201 @@
+//===- EntryPointStats.cpp --===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//======//
+
+#include "clang/StaticAnalyzer/Core/PathSensitive/EntryPointStats.h"
+#include "clang/AST/DeclBase.h"
+#include "clang/Analysis/AnalysisDeclContext.h"
+#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/StringExtras.h"
+#include "llvm/ADT/StringRef.h"
+#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/ManagedStatic.h"
+#include "llvm/Support/raw_ostream.h"
+#include 
+
+using namespace clang;
+using namespace ento;
+
+namespace {
+struct Registry {
+  std::vector BoolStats;
+  std::vector CounterStats;
+  std::vector UnsignedMaxStats;
+  std::vector UnsignedStats;
+
+  bool IsLocked = false;
+
+  struct Snapshot {
+const Decl *EntryPoint;
+std::vector BoolStatValues;
+std::vector UnsignedStatValues;
+
+void dumpDynamicStatsAsCSV(llvm::raw_ostream &OS) const;
+  };
+
+  std::vector Snapshots;
+};
+} // namespace
+
+static llvm::ManagedStatic StatsRegistry;
+
+namespace {
+template  void enumerateStatVectors(const Callback &Fn) {
+  Fn(StatsRegistry->BoolStats);
+  Fn(StatsRegistry->CounterStats);
+  Fn(StatsRegistry->UnsignedMaxStats);
+  Fn(StatsRegistry->UnsignedStats);
+}
+} // namespace
+
+static void checkStatName(const EntryPointStat *M) {
+#ifdef NDEBUG
+  return;
+#endif // NDEBUG
+  constexpr std::array AllowedSpecialChars = {
+  '+', '-', '_', '=', ':', '(',  ')', '@', '!', '~',
+  '$', '%', '^', '&', '*', '\'', ';', '<', '>', '/'};
+  for (unsigned char C : M->name()) {
+if (!std::isalnum(C) && !llvm::is_contained(AllowedSpecialChars, C)) {
+  llvm::errs() << "Stat name \"" << M->name() << "\" contains character '"
+   << C << "' (" << static_cast(C)
+   << ") that is not allowed.";
+  assert(false && "The Stat name contains unallowed character");

NagyDonat wrote:

> `llvm_unreachable` should be avoided unless there are strong optimization 
> arguments.

Why? To me it seems to be much more natural than `assert(false && ...)` which 
is just a roundabout way of saying that "this is unreachable" / should not be 
reached.

I also feel that the `llvm::errs() <<` printout looks like printf-debugging 
command that was accidentally left in the final commit – reporting the details 
within the assertion-like call would be much better.

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


[clang-tools-extra] [clang-tidy] Add an option to treat warnings as errors (PR #128221)

2025-03-14 Thread via cfe-commits

https://github.com/juru1234 updated 
https://github.com/llvm/llvm-project/pull/128221

>From 44d2bc11ccb23ba84e5dbc86436b407b08b1f9c4 Mon Sep 17 00:00:00 2001
From: Julian Ruess 
Date: Fri, 21 Feb 2025 20:42:46 +0100
Subject: [PATCH 1/2] [clang-tidy] Add an option to treat warnings as errors

This patch allows to treat warnings as erros using clang-tidy-diff.
---
 clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py | 7 +++
 clang-tools-extra/docs/ReleaseNotes.rst  | 3 +++
 2 files changed, 10 insertions(+)

diff --git a/clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py 
b/clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
index 33de2077dfb1a..74321f2642ff2 100755
--- a/clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
+++ b/clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
@@ -259,6 +259,11 @@ def main():
 action="store_true",
 help="Only check files in the compilation database",
 )
+parser.add_argument(
+"-warnings-as-errors",
+help="Upgrades clang-tidy warnings to errors. Same format as 
'-checks'.",
+default="",
+)
 
 clang_tidy_args = []
 argv = sys.argv[1:]
@@ -374,6 +379,8 @@ def main():
 common_clang_tidy_args.append("-extra-arg-before=%s" % arg)
 for plugin in args.plugins:
 common_clang_tidy_args.append("-load=%s" % plugin)
+if args.warnings_as_errors != "":
+common_clang_tidy_args.append("-warnings-as-errors=" + 
args.warnings_as_errors)
 
 for name in lines_by_file:
 line_filter_json = json.dumps(
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 41ff1c1016f25..8d016307fba83 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -88,6 +88,9 @@ Improvements to clang-query
 Improvements to clang-tidy
 --
 
+- Improved :program:`clang-tidy-diff.py` script. Add the `-warnings-as-errors`
+  to treat warnings as errors.
+
 New checks
 ^^
 

>From d189c11f1368f68d21ae4ab777c423ca7d5ffe81 Mon Sep 17 00:00:00 2001
From: Julian Ruess 
Date: Fri, 14 Mar 2025 14:08:04 +0100
Subject: [PATCH 2/2] Update
 clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py

Co-authored-by: Piotr Zegar 
---
 clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py 
b/clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
index 74321f2642ff2..0f8ac7344aca3 100755
--- a/clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
+++ b/clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
@@ -379,7 +379,7 @@ def main():
 common_clang_tidy_args.append("-extra-arg-before=%s" % arg)
 for plugin in args.plugins:
 common_clang_tidy_args.append("-load=%s" % plugin)
-if args.warnings_as_errors != "":
+if args.warnings_as_errors:
 common_clang_tidy_args.append("-warnings-as-errors=" + 
args.warnings_as_errors)
 
 for name in lines_by_file:

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


[clang] [analyzer] Introduce per-entry-point statistics (PR #131175)

2025-03-14 Thread Balazs Benics via cfe-commits


@@ -0,0 +1,27 @@
+===
+Analysis Statistics
+===
+
+CSA enjoys two facilities to collect statistics: per translation unit and per 
entry point.
+We use llvm/ADT/Statistic.h for numbers describing the entire translation unit 
(TU).
+We use clang/StaticAnalyzer/Core/PathSensitive/EntryPointStats.h to collect 
data for each symbolic-execution entry point.
+
+In many cases, it makes sense to collect statistics on both translation-unit 
level and entry-point level. You can use the two macros defined in 
EntryPointStats.h for that:
+
+- ``STAT_COUNTER`` for additive statistics, for example, "the number of steps 
executed", "the number of functions inlined".
+- ``STAT_MAX`` for maximizing statistics, for example, "the maximum 
environment size", or "the longest execution path".
+
+If you want to define a statistic that makes sense only for the entire 
translation unit, for example, "the number of entry points", Statistic.h 
defines two macros: ``STATISTIC`` and ``ALLWAYS_ENABLED_STATISTIC``.
+You should prefer ``ALLWAYS_ENABLED_STATISTIC`` unless you have a good reason 
not to.
+``STATISTIC`` is controlled by ``LLVM_ENABLE_STATS`` / 
``LLVM_FORCE_ENABLE_STATS``.
+However, note that with ``LLVM_ENABLE_STATS`` disabled, only storage of the 
values is disabled, the computations producing those values still carry on 
unless you took an explicit precaution to make them conditional too.

steakhal wrote:

```suggestion
If you want to define a statistic that makes sense only for the entire 
translation unit, for example, "the number of entry points", Statistic.h 
defines two macros: ``STATISTIC`` and ``ALWAYS_ENABLED_STATISTIC``.
You should prefer ``ALWAYS_ENABLED_STATISTIC`` unless you have a good reason 
not to.
``STATISTIC`` is controlled by ``LLVM_ENABLE_STATS`` / 
``LLVM_FORCE_ENABLE_STATS``.
However, note that with ``LLVM_ENABLE_STATS`` disabled, only storage of the 
values is disabled, the computations producing those values still carry on 
unless you took an explicit precaution to make them conditional too.
```

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


[clang] [analyzer] Introduce per-entry-point statistics (PR #131175)

2025-03-14 Thread Balazs Benics via cfe-commits

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

I only found a couple of minor points. Otherwise looks good.

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


[clang] [analyzer] Introduce per-entry-point statistics (PR #131175)

2025-03-14 Thread Balazs Benics via cfe-commits


@@ -688,6 +695,36 @@ AnalysisConsumer::getModeForDecl(Decl *D, AnalysisMode 
Mode) {
   return Mode;
 }
 
+template 
+static clang::Decl *preferDefinitionImpl(clang::Decl *D) {
+  if (auto *X = dyn_cast(D))
+if (auto *Def = X->getDefinition())
+  return Def;
+  return D;
+}
+
+template <> clang::Decl *preferDefinitionImpl(clang::Decl *D) {
+  if (const auto *X = dyn_cast(D)) {
+for (auto *I : X->redecls())
+  if (I->hasBody())
+return I;
+  }
+  return D;
+}
+
+static Decl *getDefinitionOrCanonicalDecl(Decl *D) {
+  assert(D);
+  D = D->getCanonicalDecl();
+  D = preferDefinitionImpl(D);
+  D = preferDefinitionImpl(D);
+  D = preferDefinitionImpl(D);
+  D = preferDefinitionImpl(D);
+  assert(D);
+  return D;
+}
+

steakhal wrote:

```suggestion
```
I don't think this code is used upstream.

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


[clang] [llvm] [analysis] Software Bill of Mitigations (PR #130103)

2025-03-14 Thread Matthew Levy via cfe-commits

https://github.com/matthewlevy97 updated 
https://github.com/llvm/llvm-project/pull/130103

>From fb04b7bf5f2b668bf354632fc53e7521f44880c9 Mon Sep 17 00:00:00 2001
From: Matt Levy 
Date: Wed, 5 Mar 2025 12:36:02 -0500
Subject: [PATCH 1/6] [clang][CodeGen] Software Bill of Mitigations Metadata

The goal of this stack is to create a high fidelity mapping of mitigations to 
their possible insertion points and their actual insertion points. This would 
let us track where we do and don't have mitigations rather than the current 
approach of tracking where we have the flag.

There are some challenges posed by this like:
- Some mitigations are not emitted by the compiler, but the preprocessor
- Some mitigations are lowered later during IR -> MIR (stack cookies)
---
 clang/include/clang/Basic/CodeGenOptions.def |  1 +
 clang/include/clang/Driver/Options.td|  6 ++
 clang/lib/CodeGen/CGBuiltin.cpp  | 10 +++
 clang/lib/CodeGen/CGClass.cpp|  3 +
 clang/lib/CodeGen/CGDecl.cpp |  4 +
 clang/lib/CodeGen/CGExpr.cpp |  5 ++
 clang/lib/CodeGen/CGExprCXX.cpp  |  6 ++
 clang/lib/CodeGen/CMakeLists.txt |  1 +
 clang/lib/CodeGen/CodeGenModule.cpp  | 22 +
 clang/lib/CodeGen/MitigationTagging.cpp  | 84 
 clang/lib/CodeGen/MitigationTagging.h| 45 +++
 clang/lib/Driver/ToolChains/Clang.cpp|  3 +
 12 files changed, 190 insertions(+)
 create mode 100644 clang/lib/CodeGen/MitigationTagging.cpp
 create mode 100644 clang/lib/CodeGen/MitigationTagging.h

diff --git a/clang/include/clang/Basic/CodeGenOptions.def 
b/clang/include/clang/Basic/CodeGenOptions.def
index a7f5f1abbb825..76a46ac3e592b 100644
--- a/clang/include/clang/Basic/CodeGenOptions.def
+++ b/clang/include/clang/Basic/CodeGenOptions.def
@@ -191,6 +191,7 @@ CODEGENOPT(NoTypeCheck   , 1, 0) ///< Set when 
-Wa,--no-type-check is enable
 CODEGENOPT(MisExpect , 1, 0) ///< Set when -Wmisexpect is enabled
 CODEGENOPT(EnableSegmentedStacks , 1, 0) ///< Set when -fsplit-stack is 
enabled.
 CODEGENOPT(StackClashProtector, 1, 0) ///< Set when -fstack-clash-protection 
is enabled.
+CODEGENOPT(MitigationAnalysis, 1, 0) ///< Set when -fmitigation-analysis is 
enabled.
 CODEGENOPT(NoImplicitFloat   , 1, 0) ///< Set when -mno-implicit-float is 
enabled.
 CODEGENOPT(NullPointerIsValid , 1, 0) ///< Assume Null pointer deference is 
defined.
 CODEGENOPT(OpenCLCorrectlyRoundedDivSqrt, 1, 0) ///< 
-cl-fp32-correctly-rounded-divide-sqrt
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index d0414aba35209..e50bb5c1c2cb4 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -3891,6 +3891,12 @@ defm split_stack : BoolFOption<"split-stack",
   CodeGenOpts<"EnableSegmentedStacks">, DefaultFalse,
   NegFlag,
   PosFlag>;
+defm mitigation_analysis : BoolFOption<"mitigation-analysis",
+  CodeGenOpts<"MitigationAnalysis">, DefaultFalse,
+  PosFlag,
+  NegFlag,
+  BothFlags<[], [ClangOption], " mitigation analysis">>,
+  DocBrief<"Instrument mitigations (CFI, Stack Protectors, Auto-Var-Init, 
StackClashProtection) to analyze their coverage">;
 def fstack_protector_all : Flag<["-"], "fstack-protector-all">, Group,
   HelpText<"Enable stack protectors for all functions">;
 defm stack_clash_protection : BoolFOption<"stack-clash-protection",
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index ab8f19b25fa66..4e180bb1a87cf 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -21,6 +21,7 @@
 #include "CodeGenFunction.h"
 #include "CodeGenModule.h"
 #include "ConstantEmitter.h"
+#include "MitigationTagging.h"
 #include "PatternInit.h"
 #include "TargetInfo.h"
 #include "clang/AST/ASTContext.h"
@@ -83,6 +84,8 @@ static void initializeAlloca(CodeGenFunction &CGF, AllocaInst 
*AI, Value *Size,
   switch (CGF.getLangOpts().getTrivialAutoVarInit()) {
   case LangOptions::TrivialAutoVarInitKind::Uninitialized:
 // Nothing to initialize.
+AttachMitigationMetadataToFunction(CGF, MitigationKey::AUTO_VAR_INIT,
+   false);
 return;
   case LangOptions::TrivialAutoVarInitKind::Zero:
 Byte = CGF.Builder.getInt8(0x00);
@@ -94,6 +97,7 @@ static void initializeAlloca(CodeGenFunction &CGF, AllocaInst 
*AI, Value *Size,
 break;
   }
   }
+  AttachMitigationMetadataToFunction(CGF, MitigationKey::AUTO_VAR_INIT, true);
   if (CGF.CGM.stopAutoInit())
 return;
   auto *I = CGF.Builder.CreateMemSet(AI, Byte, Size, AlignmentInBytes);
@@ -4642,6 +4646,9 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
 AI->setAlignment(SuitableAlignmentInBytes);
 if (BuiltinID != Builtin::BI__builtin_alloca_uninitialized)
   initializeAlloca(*this, AI, Size, SuitableAlignmentInBytes);
+else
+  AttachMitigationMetadataToFunction(*t

[clang] [CIR] Upstream CastOp and scalar conversions (PR #130690)

2025-03-14 Thread Morris Hafner via cfe-commits


@@ -121,29 +364,173 @@ mlir::Value CIRGenFunction::emitScalarExpr(const Expr 
*e) {
   return ScalarExprEmitter(*this, builder).Visit(const_cast(e));
 }
 
+[[maybe_unused]] static bool MustVisitNullValue(const Expr *e) {
+  // If a null pointer expression's type is the C++0x nullptr_t, then
+  // it's not necessarily a simple constant and it must be evaluated
+  // for its potential side effects.
+  return e->getType()->isNullPtrType();
+}
+
 // Emit code for an explicit or implicit cast.  Implicit
 // casts have to handle a more broad range of conversions than explicit
 // casts, as they handle things like function to ptr-to-function decay
 // etc.
 mlir::Value ScalarExprEmitter::VisitCastExpr(CastExpr *ce) {
-  Expr *e = ce->getSubExpr();
+  Expr *subExpr = ce->getSubExpr();
   QualType destTy = ce->getType();
   CastKind kind = ce->getCastKind();
 
+  // These cases are generally not written to ignore the result of evaluating
+  // their sub-expressions, so we clear this now.
+  ignoreResultAssign = false;

mmha wrote:

Note that `ignoreResultAssign` is a member variable and retains its value while 
we visit the expression. We might get called recursively so we should keep this 
store.

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


[clang] [flang] [llvm] [NFC][AMDGPU] Replace more direct arch comparison with isAMDGCN() (PR #131379)

2025-03-14 Thread Shilei Tian via cfe-commits

shiltian wrote:

* **#131379** https://app.graphite.dev/github/pr/llvm/llvm-project/131379?utm_source=stack-comment-icon";
 target="_blank">https://static.graphite.dev/graphite-32x32-black.png"; alt="Graphite" 
width="10px" height="10px"/> 👈 https://app.graphite.dev/github/pr/llvm/llvm-project/131379?utm_source=stack-comment-view-in-graphite";
 target="_blank">(View in Graphite)
* `main`




This stack of pull requests is managed by https://graphite.dev?utm-source=stack-comment";>Graphite. Learn 
more about https://stacking.dev/?utm_source=stack-comment";>stacking.


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


[clang] [AMDGPU][clang] provide device implementation for __builtin_logb and … (PR #129347)

2025-03-14 Thread via cfe-commits

https://github.com/choikwa updated 
https://github.com/llvm/llvm-project/pull/129347

>From adfb9c08cf1d62cd2c6596520e65ef9f299d3cdc Mon Sep 17 00:00:00 2001
From: Kevin Choi 
Date: Fri, 28 Feb 2025 16:52:03 -0600
Subject: [PATCH] [AMDGPU][clang] provide device implementation for
 __builtin_logb and __builtin_scalbn

Clang generates library calls for __builtin_* functions which can be a problem 
for GPUs that cannot handle them.
This patch generates a device implementations for __builtin_logb and 
__builtin_scalbn.
---
 clang/lib/CodeGen/CGBuiltin.cpp   | 43 ++-
 clang/lib/CodeGen/CodeGenModule.h |  5 
 clang/test/CodeGenHIP/logb_scalbn.hip | 42 ++
 3 files changed, 89 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/CodeGenHIP/logb_scalbn.hip

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index a5ed2595bad4d..5957fec364ae4 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -6621,10 +6621,27 @@ RValue CodeGenFunction::EmitBuiltinExpr(const 
GlobalDecl GD, unsigned BuiltinID,
   }
   }
 
+  // These will be emitted as Intrinsic later.
+  auto NeedsDeviceOverloadToIntrin = [&](unsigned BuiltinID) {
+if (getTarget().getTriple().isAMDGCN()) {
+  switch (BuiltinID) {
+  default:
+return false;
+  case Builtin::BIlogb:
+  case Builtin::BI__builtin_logb:
+  case Builtin::BIscalbn:
+  case Builtin::BI__builtin_scalbn:
+return true;
+  }
+}
+return false;
+  };
+
   // If this is an alias for a lib function (e.g. __builtin_sin), emit
   // the call using the normal call path, but using the unmangled
   // version of the function name.
-  if (getContext().BuiltinInfo.isLibFunction(BuiltinID))
+  if (!NeedsDeviceOverloadToIntrin(BuiltinID) &&
+  getContext().BuiltinInfo.isLibFunction(BuiltinID))
 return emitLibraryCall(*this, FD, E,
CGM.getBuiltinLibFunction(FD, BuiltinID));
 
@@ -20910,6 +20927,30 @@ Value *CodeGenFunction::EmitAMDGPUBuiltinExpr(unsigned 
BuiltinID,
   case AMDGPU::BI__builtin_amdgcn_s_prefetch_data:
 return emitBuiltinWithOneOverloadedType<2>(
 *this, E, Intrinsic::amdgcn_s_prefetch_data);
+  case Builtin::BIlogb:
+  case Builtin::BI__builtin_logb: {
+auto Src0 = EmitScalarExpr(E->getArg(0));
+auto FrExpFunc = CGM.getIntrinsic(Intrinsic::amdgcn_frexp_exp,
+  {Builder.getInt32Ty(), Src0->getType()});
+auto FrExp = Builder.CreateCall(FrExpFunc, Src0);
+auto Add = Builder.CreateAdd(
+FrExp, ConstantInt::getSigned(FrExp->getType(), -1), "", false, true);
+auto SIToFP = Builder.CreateSIToFP(Add, Builder.getDoubleTy());
+auto Fabs = emitBuiltinWithOneOverloadedType<1>(*this, E, Intrinsic::fabs);
+auto FCmpONE = Builder.CreateFCmpONE(
+Fabs, ConstantFP::getInfinity(Builder.getDoubleTy()));
+auto Sel1 = Builder.CreateSelect(FCmpONE, SIToFP, Fabs);
+auto FCmpOEQ =
+Builder.CreateFCmpOEQ(Src0, 
ConstantFP::getZero(Builder.getDoubleTy()));
+auto Sel2 = Builder.CreateSelect(
+FCmpOEQ, ConstantFP::getInfinity(Builder.getDoubleTy(), /*Neg*/ true),
+Sel1);
+return Sel2;
+  }
+  case Builtin::BIscalbn:
+  case Builtin::BI__builtin_scalbn:
+return emitBinaryExpMaybeConstrainedFPBuiltin(
+*this, E, Intrinsic::ldexp, Intrinsic::experimental_constrained_ldexp);
   default:
 return nullptr;
   }
diff --git a/clang/lib/CodeGen/CodeGenModule.h 
b/clang/lib/CodeGen/CodeGenModule.h
index 6deb467b2cc9f..ae1441dc3d009 100644
--- a/clang/lib/CodeGen/CodeGenModule.h
+++ b/clang/lib/CodeGen/CodeGenModule.h
@@ -1231,6 +1231,11 @@ class CodeGenModule : public CodeGenTypeCache {
   llvm::FunctionType *FnType = nullptr, bool DontDefer = false,
   ForDefinition_t IsForDefinition = NotForDefinition);
 
+  /// Given a builtin id for a function, return a Function* for device
+  /// overload implementation.
+  llvm::Constant *getDeviceLibFunction(const FunctionDecl *FD,
+   unsigned BuiltinID);
+
   /// Given a builtin id for a function like "__builtin_fabsf", return a
   /// Function* for "fabsf".
   llvm::Constant *getBuiltinLibFunction(const FunctionDecl *FD,
diff --git a/clang/test/CodeGenHIP/logb_scalbn.hip 
b/clang/test/CodeGenHIP/logb_scalbn.hip
new file mode 100644
index 0..935941bb25939
--- /dev/null
+++ b/clang/test/CodeGenHIP/logb_scalbn.hip
@@ -0,0 +1,42 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 5
+// RUN: %clang --cuda-device-only -nogpuinc -nogpulib -emit-llvm -S -o - %s | 
FileCheck %s
+#include 
+#define __device__ __attribute__((device))
+
+// CHECK-LABEL: define hidden void @_Z9my_kernelv(
+// CHECK-SAME: ) #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  [[ENTRY:.*:]]
+// CHECK-NEXT:[[D1:%.*]] = alloca float, align 4, addrspace(5)
+// CHE

[clang] dccc0a8 - [NFC][AMDGPU] Replace more direct arch comparison with isAMDGCN() (#131379)

2025-03-14 Thread via cfe-commits

Author: Shilei Tian
Date: 2025-03-14T17:02:15-04:00
New Revision: dccc0a836c20914549fa375905615db49d2f813b

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

LOG: [NFC][AMDGPU] Replace more direct arch comparison with isAMDGCN() (#131379)

This is an extension of #131357. Hopefully this would be the last one.

Added: 


Modified: 
clang/include/clang/Driver/ToolChain.h
clang/lib/Basic/Targets/AMDGPU.h
clang/lib/Driver/Driver.cpp
clang/lib/Driver/ToolChains/HIPAMD.cpp
clang/lib/Frontend/CompilerInvocation.cpp
flang/lib/Frontend/CompilerInvocation.cpp
llvm/include/llvm/TargetParser/Triple.h
llvm/lib/Target/AMDGPU/AMDGPUISelDAGToDAG.cpp
llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp
llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp

Removed: 




diff  --git a/clang/include/clang/Driver/ToolChain.h 
b/clang/include/clang/Driver/ToolChain.h
index 7d1d8feebf35e..90004c64a694a 100644
--- a/clang/include/clang/Driver/ToolChain.h
+++ b/clang/include/clang/Driver/ToolChain.h
@@ -821,7 +821,7 @@ class ToolChain {
 return llvm::Triple("nvptx-nvidia-cuda");
   if (TT.getArch() == llvm::Triple::nvptx64)
 return llvm::Triple("nvptx64-nvidia-cuda");
-  if (TT.getArch() == llvm::Triple::amdgcn)
+  if (TT.isAMDGCN())
 return llvm::Triple("amdgcn-amd-amdhsa");
 }
 return TT;

diff  --git a/clang/lib/Basic/Targets/AMDGPU.h 
b/clang/lib/Basic/Targets/AMDGPU.h
index 3d6778fb5a76f..63b0d4b6e5fc0 100644
--- a/clang/lib/Basic/Targets/AMDGPU.h
+++ b/clang/lib/Basic/Targets/AMDGPU.h
@@ -52,7 +52,7 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : public 
TargetInfo {
   std::string TargetID;
 
   bool hasFP64() const {
-return getTriple().getArch() == llvm::Triple::amdgcn ||
+return getTriple().isAMDGCN() ||
!!(GPUFeatures & llvm::AMDGPU::FEATURE_FP64);
   }
 
@@ -62,12 +62,10 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : 
public TargetInfo {
   }
 
   /// Has fast fma f64
-  bool hasFastFMA() const {
-return getTriple().getArch() == llvm::Triple::amdgcn;
-  }
+  bool hasFastFMA() const { return getTriple().isAMDGCN(); }
 
   bool hasFMAF() const {
-return getTriple().getArch() == llvm::Triple::amdgcn ||
+return getTriple().isAMDGCN() ||
!!(GPUFeatures & llvm::AMDGPU::FEATURE_FMA);
   }
 
@@ -76,13 +74,11 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : 
public TargetInfo {
   }
 
   bool hasLDEXPF() const {
-return getTriple().getArch() == llvm::Triple::amdgcn ||
+return getTriple().isAMDGCN() ||
!!(GPUFeatures & llvm::AMDGPU::FEATURE_LDEXP);
   }
 
-  static bool isAMDGCN(const llvm::Triple &TT) {
-return TT.getArch() == llvm::Triple::amdgcn;
-  }
+  static bool isAMDGCN(const llvm::Triple &TT) { return TT.isAMDGCN(); }
 
   static bool isR600(const llvm::Triple &TT) {
 return TT.getArch() == llvm::Triple::r600;
@@ -125,7 +121,7 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : 
public TargetInfo {
   }
 
   uint64_t getMaxPointerWidth() const override {
-return getTriple().getArch() == llvm::Triple::amdgcn ? 64 : 32;
+return getTriple().isAMDGCN() ? 64 : 32;
   }
 
   bool hasBFloat16Type() const override { return isAMDGCN(getTriple()); }
@@ -269,7 +265,7 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : 
public TargetInfo {
   }
 
   bool isValidCPUName(StringRef Name) const override {
-if (getTriple().getArch() == llvm::Triple::amdgcn)
+if (getTriple().isAMDGCN())
   return llvm::AMDGPU::parseArchAMDGCN(Name) != llvm::AMDGPU::GK_NONE;
 return llvm::AMDGPU::parseArchR600(Name) != llvm::AMDGPU::GK_NONE;
   }
@@ -277,7 +273,7 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : 
public TargetInfo {
   void fillValidCPUList(SmallVectorImpl &Values) const override;
 
   bool setCPU(const std::string &Name) override {
-if (getTriple().getArch() == llvm::Triple::amdgcn) {
+if (getTriple().isAMDGCN()) {
   GPUKind = llvm::AMDGPU::parseArchAMDGCN(Name);
   GPUFeatures = llvm::AMDGPU::getArchAttrAMDGCN(GPUKind);
 } else {

diff  --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 848b27012976d..056bfcf1b739a 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -158,8 +158,7 @@ getHIPOffloadTargetTriple(const Driver &D, const ArgList 
&Args) {
   auto TT = getOffloadTargetTriple(D, Args);
   if (!TT)
 return std::nullopt;
-  if (TT->getArch() == llvm::Triple::amdgcn &&
-  TT->getVendor() == llvm::Triple::AMD &&
+  if (TT->isAMDGCN() && TT->getVendor() == llvm::Triple::AMD &&
   TT->getOS() == llvm::Triple::AMDHSA)
 return TT;
   if (TT->getArch() == llvm::Triple::spirv64)
@@ -3409,8 +3408,7 @@ class Offlo

[clang] [AMDGPU][clang] provide device implementation for __builtin_logb and … (PR #129347)

2025-03-14 Thread via cfe-commits

https://github.com/choikwa updated 
https://github.com/llvm/llvm-project/pull/129347

>From 635cbb75bb966088ffc4145dbc640ee1c9c1048f Mon Sep 17 00:00:00 2001
From: Kevin Choi 
Date: Fri, 28 Feb 2025 16:52:03 -0600
Subject: [PATCH] [AMDGPU][clang] provide device implementation for
 __builtin_logb and __builtin_scalbn

Clang generates library calls for __builtin_* functions which can be a problem 
for GPUs that cannot handle them.
This patch generates a device implementations for __builtin_logb and 
__builtin_scalbn.
---
 clang/lib/CodeGen/CGBuiltin.cpp   | 43 ++-
 clang/test/CodeGenHIP/logb_scalbn.hip | 32 
 2 files changed, 74 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/CodeGenHIP/logb_scalbn.hip

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index a5ed2595bad4d..e6596e56a1627 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -6621,10 +6621,27 @@ RValue CodeGenFunction::EmitBuiltinExpr(const 
GlobalDecl GD, unsigned BuiltinID,
   }
   }
 
+  // These will be emitted as Intrinsic later.
+  auto NeedsDeviceOverload = [&](unsigned BuiltinID) {
+if (getTarget().getTriple().isAMDGCN()) {
+  switch (BuiltinID) {
+  default:
+return false;
+  case Builtin::BIlogb:
+  case Builtin::BI__builtin_logb:
+  case Builtin::BIscalbn:
+  case Builtin::BI__builtin_scalbn:
+return true;
+  }
+}
+return false;
+  };
+
   // If this is an alias for a lib function (e.g. __builtin_sin), emit
   // the call using the normal call path, but using the unmangled
   // version of the function name.
-  if (getContext().BuiltinInfo.isLibFunction(BuiltinID))
+  if (!NeedsDeviceOverload(BuiltinID) &&
+  getContext().BuiltinInfo.isLibFunction(BuiltinID))
 return emitLibraryCall(*this, FD, E,
CGM.getBuiltinLibFunction(FD, BuiltinID));
 
@@ -20910,6 +20927,30 @@ Value *CodeGenFunction::EmitAMDGPUBuiltinExpr(unsigned 
BuiltinID,
   case AMDGPU::BI__builtin_amdgcn_s_prefetch_data:
 return emitBuiltinWithOneOverloadedType<2>(
 *this, E, Intrinsic::amdgcn_s_prefetch_data);
+  case Builtin::BIlogb:
+  case Builtin::BI__builtin_logb: {
+auto Src0 = EmitScalarExpr(E->getArg(0));
+auto FrExpFunc = CGM.getIntrinsic(Intrinsic::amdgcn_frexp_exp,
+  {Builder.getInt32Ty(), Src0->getType()});
+auto FrExp = Builder.CreateCall(FrExpFunc, Src0);
+auto Add = Builder.CreateAdd(
+FrExp, ConstantInt::getSigned(FrExp->getType(), -1), "", false, true);
+auto SIToFP = Builder.CreateSIToFP(Add, Builder.getDoubleTy());
+auto Fabs = emitBuiltinWithOneOverloadedType<1>(*this, E, Intrinsic::fabs);
+auto FCmpONE = Builder.CreateFCmpONE(
+Fabs, ConstantFP::getInfinity(Builder.getDoubleTy()));
+auto Sel1 = Builder.CreateSelect(FCmpONE, SIToFP, Fabs);
+auto FCmpOEQ =
+Builder.CreateFCmpOEQ(Src0, 
ConstantFP::getZero(Builder.getDoubleTy()));
+auto Sel2 = Builder.CreateSelect(
+FCmpOEQ, ConstantFP::getInfinity(Builder.getDoubleTy(), /*Neg*/ true),
+Sel1);
+return Sel2;
+  }
+  case Builtin::BIscalbn:
+  case Builtin::BI__builtin_scalbn:
+return emitBinaryExpMaybeConstrainedFPBuiltin(
+*this, E, Intrinsic::ldexp, Intrinsic::experimental_constrained_ldexp);
   default:
 return nullptr;
   }
diff --git a/clang/test/CodeGenHIP/logb_scalbn.hip 
b/clang/test/CodeGenHIP/logb_scalbn.hip
new file mode 100644
index 0..76e6ef16191d8
--- /dev/null
+++ b/clang/test/CodeGenHIP/logb_scalbn.hip
@@ -0,0 +1,32 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 5
+// RUN: %clang --cuda-device-only -nogpuinc -nogpulib -emit-llvm -S -o - %s | 
FileCheck %s
+#include 
+#define __device__ __attribute__((device))
+
+// CHECK-LABEL: define hidden void @_Z9my_kernelv(
+// CHECK-SAME: ) #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  [[ENTRY:.*:]]
+// CHECK-NEXT:[[D1:%.*]] = alloca float, align 4, addrspace(5)
+// CHECK-NEXT:[[D2:%.*]] = alloca float, align 4, addrspace(5)
+// CHECK-NEXT:[[D1_ASCAST:%.*]] = addrspacecast ptr addrspace(5) [[D1]] to 
ptr
+// CHECK-NEXT:[[D2_ASCAST:%.*]] = addrspacecast ptr addrspace(5) [[D2]] to 
ptr
+// CHECK-NEXT:[[TMP0:%.*]] = call i32 
@llvm.amdgcn.frexp.exp.i32.f64(double 1.60e+01)
+// CHECK-NEXT:[[TMP1:%.*]] = add nsw i32 [[TMP0]], -1
+// CHECK-NEXT:[[TMP2:%.*]] = sitofp i32 [[TMP1]] to double
+// CHECK-NEXT:[[TMP3:%.*]] = call contract double @llvm.fabs.f64(double 
1.60e+01)
+// CHECK-NEXT:[[TMP4:%.*]] = fcmp contract one double [[TMP3]], 
0x7FF0
+// CHECK-NEXT:[[TMP5:%.*]] = select contract i1 [[TMP4]], double [[TMP2]], 
double [[TMP3]]
+// CHECK-NEXT:[[TMP6:%.*]] = select contract i1 false, double 
0xFFF0, double [[TMP5]]
+// CHECK-NEXT:[[CONV:%.*]] = fptrunc contr

[clang] [CIR] Upstream CastOp and scalar conversions (PR #130690)

2025-03-14 Thread Andy Kaylor via cfe-commits


@@ -121,29 +364,173 @@ mlir::Value CIRGenFunction::emitScalarExpr(const Expr 
*e) {
   return ScalarExprEmitter(*this, builder).Visit(const_cast(e));
 }
 
+[[maybe_unused]] static bool MustVisitNullValue(const Expr *e) {
+  // If a null pointer expression's type is the C++0x nullptr_t, then
+  // it's not necessarily a simple constant and it must be evaluated
+  // for its potential side effects.
+  return e->getType()->isNullPtrType();
+}
+
 // Emit code for an explicit or implicit cast.  Implicit
 // casts have to handle a more broad range of conversions than explicit
 // casts, as they handle things like function to ptr-to-function decay
 // etc.
 mlir::Value ScalarExprEmitter::VisitCastExpr(CastExpr *ce) {
-  Expr *e = ce->getSubExpr();
+  Expr *subExpr = ce->getSubExpr();
   QualType destTy = ce->getType();
   CastKind kind = ce->getCastKind();
 
+  // These cases are generally not written to ignore the result of evaluating
+  // their sub-expressions, so we clear this now.
+  ignoreResultAssign = false;

andykaylor wrote:

The incubator does use the value returned by `TestAndClearIgnoreResultAssign()` 
in `VisitBinAssign()` and `emitCompoundAssign()` so we'll probably want to keep 
the call in those places, but I don't see any value in calling the function 
when we aren't using the value returned.

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


[clang-tools-extra] [clang-tidy] Add an option to treat warnings as errors (PR #128221)

2025-03-14 Thread Julian Ruess via cfe-commits

https://github.com/juru1234 updated 
https://github.com/llvm/llvm-project/pull/128221

>From f22a342243d3251e5a1e2ff31aa4e7c176846b5f Mon Sep 17 00:00:00 2001
From: Julian Ruess 
Date: Fri, 21 Feb 2025 20:42:46 +0100
Subject: [PATCH] [clang-tidy-diff.py] Add an option to treat warnings as
 errors

This patch allows to treat warnings as erros using clang-tidy-diff.py.

Co-authored-by: Piotr Zegar 
---
 clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py | 7 +++
 clang-tools-extra/docs/ReleaseNotes.rst  | 3 +++
 2 files changed, 10 insertions(+)

diff --git a/clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py 
b/clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
index 33de2077dfb1a..0f8ac7344aca3 100755
--- a/clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
+++ b/clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
@@ -259,6 +259,11 @@ def main():
 action="store_true",
 help="Only check files in the compilation database",
 )
+parser.add_argument(
+"-warnings-as-errors",
+help="Upgrades clang-tidy warnings to errors. Same format as 
'-checks'.",
+default="",
+)
 
 clang_tidy_args = []
 argv = sys.argv[1:]
@@ -374,6 +379,8 @@ def main():
 common_clang_tidy_args.append("-extra-arg-before=%s" % arg)
 for plugin in args.plugins:
 common_clang_tidy_args.append("-load=%s" % plugin)
+if args.warnings_as_errors:
+common_clang_tidy_args.append("-warnings-as-errors=" + 
args.warnings_as_errors)
 
 for name in lines_by_file:
 line_filter_json = json.dumps(
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index d621a9c6d840b..b2e17d4bb73d1 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -97,6 +97,9 @@ Improvements to clang-tidy
   Note: this may lead to false negatives; downstream users may need to adjust
   their checks to preserve existing behavior.
 
+- Improved :program:`clang-tidy-diff.py` script. Add the `-warnings-as-errors`
+  to treat warnings as errors.
+
 New checks
 ^^
 

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


[clang] Avoid Assertion Failure Using -fcs-profile-generate with distributed thin-lto (PR #129736)

2025-03-14 Thread Nuri Amari via cfe-commits

https://github.com/NuriAmari updated 
https://github.com/llvm/llvm-project/pull/129736

>From fc06ad49b1b166dd1ef09c8babe65c337487ee65 Mon Sep 17 00:00:00 2001
From: Nuri Amari 
Date: Mon, 3 Mar 2025 16:10:54 -0800
Subject: [PATCH 1/2] Move Clang distributd thin-lto codegen tests into their
 own directory

clang/test/CodeGen includes many tests, some of which pretain to
distributed thin-lto. While they have similar names, it is easier to
find them all in a common directory.
---
 .../backend-skip.ll}| 2 +-
 .../{thinlto-distributed.ll => distributed-thin-lto/basic.ll}   | 0
 .../cfi-devirt.ll}  | 2 +-
 .../{thinlto-distributed-cfi.ll => distributed-thin-lto/cfi.ll} | 2 +-
 .../newpm.ll}   | 0
 .../objc-contract-pass.ll}  | 0
 .../supports-hot-cold-new.ll}   | 0
 7 files changed, 3 insertions(+), 3 deletions(-)
 rename clang/test/CodeGen/{thinlto-distributed-backend-skip.ll => 
distributed-thin-lto/backend-skip.ll} (87%)
 rename clang/test/CodeGen/{thinlto-distributed.ll => 
distributed-thin-lto/basic.ll} (100%)
 rename clang/test/CodeGen/{thinlto-distributed-cfi-devirt.ll => 
distributed-thin-lto/cfi-devirt.ll} (97%)
 rename clang/test/CodeGen/{thinlto-distributed-cfi.ll => 
distributed-thin-lto/cfi.ll} (95%)
 rename clang/test/CodeGen/{thinlto-distributed-newpm.ll => 
distributed-thin-lto/newpm.ll} (100%)
 rename clang/test/CodeGen/{thinlto-distributed-objc-contract-pass.ll => 
distributed-thin-lto/objc-contract-pass.ll} (100%)
 rename clang/test/CodeGen/{thinlto-distributed-supports-hot-cold-new.ll => 
distributed-thin-lto/supports-hot-cold-new.ll} (100%)

diff --git a/clang/test/CodeGen/thinlto-distributed-backend-skip.ll 
b/clang/test/CodeGen/distributed-thin-lto/backend-skip.ll
similarity index 87%
rename from clang/test/CodeGen/thinlto-distributed-backend-skip.ll
rename to clang/test/CodeGen/distributed-thin-lto/backend-skip.ll
index d7b8225ee2693..62aa8aa8e7dc4 100644
--- a/clang/test/CodeGen/thinlto-distributed-backend-skip.ll
+++ b/clang/test/CodeGen/distributed-thin-lto/backend-skip.ll
@@ -6,7 +6,7 @@
 ; RUN: opt -thinlto-bc -o %t.o %s
 
 ; RUN: %clang_cc1 -triple x86_64-grtev4-linux-gnu \
-; RUN:   -fthinlto-index=%S/Inputs/thinlto-distributed-backend-skip.bc \
+; RUN:   -fthinlto-index=%S/../Inputs/thinlto-distributed-backend-skip.bc \
 ; RUN:   -emit-llvm -o - -x ir %t.o | FileCheck %s
 
 target datalayout = 
"e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
diff --git a/clang/test/CodeGen/thinlto-distributed.ll 
b/clang/test/CodeGen/distributed-thin-lto/basic.ll
similarity index 100%
rename from clang/test/CodeGen/thinlto-distributed.ll
rename to clang/test/CodeGen/distributed-thin-lto/basic.ll
diff --git a/clang/test/CodeGen/thinlto-distributed-cfi-devirt.ll 
b/clang/test/CodeGen/distributed-thin-lto/cfi-devirt.ll
similarity index 97%
rename from clang/test/CodeGen/thinlto-distributed-cfi-devirt.ll
rename to clang/test/CodeGen/distributed-thin-lto/cfi-devirt.ll
index acbcdcdb4fd02..a5792eee8abfb 100644
--- a/clang/test/CodeGen/thinlto-distributed-cfi-devirt.ll
+++ b/clang/test/CodeGen/distributed-thin-lto/cfi-devirt.ll
@@ -33,7 +33,7 @@
 ; RUN: llvm-dis %t.o.thinlto.bc -o - | FileCheck %s --check-prefix=CHECK-DIS
 ; Round trip it through llvm-as
 ; RUN: llvm-dis %t.o.thinlto.bc -o - | llvm-as -o - | llvm-dis -o - | 
FileCheck %s --check-prefix=CHECK-DIS
-; CHECK-DIS: ^0 = module: (path: 
"{{.*}}thinlto-distributed-cfi-devirt.ll.tmp.o", hash: ({{.*}}, {{.*}}, {{.*}}, 
{{.*}}, {{.*}}))
+; CHECK-DIS: ^0 = module: (path: "{{.*}}cfi-devirt.ll.tmp.o", hash: ({{.*}}, 
{{.*}}, {{.*}}, {{.*}}, {{.*}}))
 ; CHECK-DIS: ^1 = gv: (guid: 8346051122425466633, summaries: (function: 
(module: ^0, flags: (linkage: external, visibility: default, 
notEligibleToImport: 0, live: 1, dsoLocal: 0, canAutoHide: 0, importType: 
definition), insts: 18, funcFlags: (readNone: 0, readOnly: 0, noRecurse: 0, 
returnDoesNotAlias: 0, noInline: 0, alwaysInline: 0, noUnwind: 0, mayThrow: 0, 
hasUnknownCall: 1, mustBeUnreachable: 0), typeIdInfo: (typeTests: (^2), 
typeCheckedLoadVCalls: (vFuncId: (^2, offset: 8), vFuncId: (^2, offset: 0))
 ; CHECK-DIS: ^2 = typeid: (name: "_ZTS1A", summary: (typeTestRes: (kind: 
allOnes, sizeM1BitWidth: 7), wpdResolutions: ((offset: 0, wpdRes: (kind: 
branchFunnel)), (offset: 8, wpdRes: (kind: singleImpl, singleImplName: 
"_ZN1A1nEi") ; guid = 7004155349499253778
 
diff --git a/clang/test/CodeGen/thinlto-distributed-cfi.ll 
b/clang/test/CodeGen/distributed-thin-lto/cfi.ll
similarity index 95%
rename from clang/test/CodeGen/thinlto-distributed-cfi.ll
rename to clang/test/CodeGen/distributed-thin-lto/cfi.ll
index 6023ba8f32df9..696f2dc4ea634 100644
--- a/clang/test/CodeGen/thinlto-distributed-cfi.ll
+++ b/clang/test/CodeGen/distributed-thin-lto/cfi.ll
@@ -23,7 +23,7 @

[clang-tools-extra] [clangd] Use `SymbolName` to represent Objective-C selectors (PR #82061)

2025-03-14 Thread David Goldman via cfe-commits

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


[clang] [llvm] IR: Store the default subtarget info in named metadata instead of the context. (PR #98673)

2025-03-14 Thread Eli Friedman via cfe-commits

efriedma-quic wrote:

Sorry, I meant to get back to this sooner.

I'm not sure it makes sense to distinguish between "compile-time" and 
"link-time" in the sense this patch is doing: whether an instrumentation pass 
runs at compile-time or link-time is more a matter of what's convenient for a 
given compilation pipeline, not a fundamental semantic difference.  The 
fundamental difference is whether we know the caller: if we know the caller, we 
can just take the flags from the caller.  If we don't, we have to pick some 
"generic" flags that work for any possible caller.

If this means frontends have to do something more complicated to compute the 
right set of features, or we need to add new flags to clang, I think that's 
just the cost of doing things correctly.

Along those lines, I think we need some sort of merge rule.  Some attributes 
can be merged: for example, whether the target has an atomic add instruction, 
as opposed to generic ll/sc atomics.  Some attributes can't be merged, like 
whether a register is reserved: there can only be one correct answer.

Maybe the answer is just that we don't want a generic "target-features" list at 
all; we should just have individual module flags for each feature.  That way 
each attribute can specify its own merge rule.  We've already effectively 
started to do this with #83153: we have a bunch of attributes derived from 
module flags.

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


[clang] [CIR] Upstream initial support for unary op (PR #131369)

2025-03-14 Thread Erich Keane via cfe-commits

https://github.com/erichkeane commented:

I still have the open question on that comment I'd like an answer to, but 1 
suggestion here.  Else this LGTM.

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


[clang] [CIR] Upstream initial support for unary op (PR #131369)

2025-03-14 Thread Andy Kaylor via cfe-commits


@@ -568,6 +568,128 @@ mlir::LogicalResult 
CIRToLLVMGlobalOpLowering::matchAndRewrite(
   return mlir::success();
 }
 
+mlir::LogicalResult CIRToLLVMUnaryOpLowering::matchAndRewrite(
+cir::UnaryOp op, OpAdaptor adaptor,
+mlir::ConversionPatternRewriter &rewriter) const {
+  assert(op.getType() == op.getInput().getType() &&
+ "Unary operation's operand type and result type are different");
+  mlir::Type type = op.getType();
+  mlir::Type elementType = type;
+  bool isVector = false;
+  assert(!cir::MissingFeatures::vectorType());
+  mlir::Type llvmType = getTypeConverter()->convertType(type);
+  mlir::Location loc = op.getLoc();
+
+  auto createIntConstant = [&](int64_t value) -> mlir::Value {

andykaylor wrote:

The createDummyValue he added is in the CIR codegen, and it's doing something 
different. These do seem like utility functions that will probably be useful 
elsewhere though. Or maybe a wrapper function isn't even needed.

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


[clang] [CIR] Upstream CastOp and scalar conversions (PR #130690)

2025-03-14 Thread Morris Hafner via cfe-commits


@@ -0,0 +1,79 @@
+// RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-linux-gnu -fclangir 
-emit-cir %s -o %t.cir
+// RUN: FileCheck --input-file=%t.cir %s
+
+unsigned char cxxstaticcast_0(unsigned int x) {
+  return static_cast(x);
+}
+
+// CHECK: cir.func @cxxstaticcast_0
+// CHECK:%0 = cir.alloca !cir.int, !cir.ptr>, ["x", 
init] {alignment = 4 : i64}
+// CHECK:cir.store %arg0, %0 : !cir.int, !cir.ptr>
+// CHECK:%1 = cir.load %0 : !cir.ptr>, !cir.int
+// CHECK:%2 = cir.cast(integral, %1 : !cir.int), !cir.int
+// CHECK:cir.return %2 : !cir.int
+// CHECK:  }
+
+
+int cStyleCasts_0(unsigned x1, int x2, float x3, short x4, double x5) {
+// CHECK: cir.func @cStyleCasts_0
+
+  char a = (char)x1; // truncate
+  // CHECK: %{{[0-9]+}} = cir.cast(integral, %{{[0-9]+}} : !cir.int), 
!cir.int

mmha wrote:

I expanded the tests to include LLVM lowering where feasible. `int_to_bool` is 
implemented in CIR but not in the lowering (as that requires comparisons) so I 
`ifdef`ed those out for the LLVM checks.

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


[clang] [flang] [llvm] [NFC][AMDGPU] Replace more direct arch comparison with isAMDGCN() (PR #131379)

2025-03-14 Thread Shilei Tian via cfe-commits

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


[clang] [clang][DependencyScanning] Track modules that resolve from sysroot. (PR #130634)

2025-03-14 Thread Cyndy Ishida via cfe-commits


@@ -739,6 +748,12 @@ ModuleDepCollectorPP::handleTopLevelModule(const Module 
*M) {
   MDC.ScanInstance.getASTReader()->visitInputFileInfos(
   *MF, /*IncludeSystem=*/true,
   [&](const serialization::InputFileInfo &IFI, bool IsSystem) {
+if (MD.IsInSysroot) {
+  auto FullFilePath = ASTReader::ResolveImportedPath(
+  PathBuf, IFI.UnresolvedImportedFilename, MF->BaseDirectory);
+  MD.IsInSysroot = FullFilePath->starts_with(CurrSysroot);

cyndyishida wrote:

There's also a swift version that attempts to do the same. 
https://github.com/swiftlang/swift/blob/b4a2908fb5d7ae5b19d1f4a7f0ec9636f7c729c9/lib/Basic/StringExtras.cpp#L1459
It isolates & moves forward by separator, so I can try to apply this here (and 
double check it resolves the examples you point out).

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


[clang] [HLSL] Add support for SV_GroupIndex in SPIR-V (PR #130672)

2025-03-14 Thread Cassandra Beckley via cfe-commits

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


[clang] [CIR] Upstream initial support for unary op (PR #131369)

2025-03-14 Thread Erich Keane via cfe-commits

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


[clang] [clang][DependencyScanning] Track modules that resolve from sysroot. (PR #130634)

2025-03-14 Thread Ben Langmuir via cfe-commits


@@ -739,6 +748,12 @@ ModuleDepCollectorPP::handleTopLevelModule(const Module 
*M) {
   MDC.ScanInstance.getASTReader()->visitInputFileInfos(
   *MF, /*IncludeSystem=*/true,
   [&](const serialization::InputFileInfo &IFI, bool IsSystem) {
+if (MD.IsInSysroot) {
+  auto FullFilePath = ASTReader::ResolveImportedPath(
+  PathBuf, IFI.UnresolvedImportedFilename, MF->BaseDirectory);
+  MD.IsInSysroot = FullFilePath->starts_with(CurrSysroot);

benlangmuir wrote:

Do you mean `starts_with`? That one looks like it has the same issue 😬 In fact 
I see in the `replace_path_prefix` documentation it claims the following 
behaviour
```
/oldfoo, /old, /new => /oldfoo
```

but the unit test for this function actually has an equivalent case and the 
behaviour is different `/oldnew/foo, /old, /new => /newnew/foo` specifically 
because `starts_with` is wrong.

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


[clang] [CIR] Upstream initial support for unary op (PR #131369)

2025-03-14 Thread Andy Kaylor via cfe-commits

https://github.com/andykaylor updated 
https://github.com/llvm/llvm-project/pull/131369

>From d51bb762224f70b2b879198e2466ca0d258f9eae Mon Sep 17 00:00:00 2001
From: Andy Kaylor 
Date: Mon, 10 Mar 2025 15:07:50 -0700
Subject: [PATCH 1/2] [CIR] Upstream initial support for unary op

This adds support for the cir.unary operation.
---
 clang/include/clang/CIR/Dialect/IR/CIROps.td  |  49 +++
 clang/include/clang/CIR/MissingFeatures.h |   9 +
 clang/lib/CIR/CodeGen/CIRGenExpr.cpp  |  48 +++
 clang/lib/CIR/CodeGen/CIRGenExprScalar.cpp| 223 ++
 clang/lib/CIR/CodeGen/CIRGenFunction.cpp  |   2 +
 clang/lib/CIR/CodeGen/CIRGenFunction.h|   4 +
 clang/lib/CIR/CodeGen/CIRGenValue.h   |   1 +
 clang/lib/CIR/Dialect/IR/CIRDialect.cpp   |  41 ++
 .../CIR/Lowering/DirectToLLVM/LowerToLLVM.cpp | 125 +-
 .../CIR/Lowering/DirectToLLVM/LowerToLLVM.h   |  10 +
 clang/test/CIR/CodeGen/unary.cpp  | 392 ++
 11 files changed, 903 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/CIR/CodeGen/unary.cpp

diff --git a/clang/include/clang/CIR/Dialect/IR/CIROps.td 
b/clang/include/clang/CIR/Dialect/IR/CIROps.td
index 77c43e5ace64a..52c78ffe42647 100644
--- a/clang/include/clang/CIR/Dialect/IR/CIROps.td
+++ b/clang/include/clang/CIR/Dialect/IR/CIROps.td
@@ -468,6 +468,55 @@ def BrOp : CIR_Op<"br",
   }];
 }
 
+//===--===//
+// UnaryOp
+//===--===//
+
+def UnaryOpKind_Inc   : I32EnumAttrCase<"Inc",   1, "inc">;
+def UnaryOpKind_Dec   : I32EnumAttrCase<"Dec",   2, "dec">;
+def UnaryOpKind_Plus  : I32EnumAttrCase<"Plus",  3, "plus">;
+def UnaryOpKind_Minus : I32EnumAttrCase<"Minus", 4, "minus">;
+def UnaryOpKind_Not   : I32EnumAttrCase<"Not",   5, "not">;
+
+def UnaryOpKind : I32EnumAttr<
+"UnaryOpKind",
+"unary operation kind",
+[UnaryOpKind_Inc,
+ UnaryOpKind_Dec,
+ UnaryOpKind_Plus,
+ UnaryOpKind_Minus,
+ UnaryOpKind_Not,
+ ]> {
+  let cppNamespace = "::cir";
+}
+
+// FIXME: Pure won't work when we add overloading.
+def UnaryOp : CIR_Op<"unary", [Pure, SameOperandsAndResultType]> {
+  let summary = "Unary operations";
+  let description = [{
+`cir.unary` performs the unary operation according to
+the specified opcode kind: [inc, dec, plus, minus, not].
+
+It requires one input operand and has one result, both types
+should be the same.
+
+```mlir
+%7 = cir.unary(inc, %1) : i32 -> i32
+%8 = cir.unary(dec, %2) : i32 -> i32
+```
+  }];
+
+  let results = (outs CIR_AnyType:$result);
+  let arguments = (ins Arg:$kind, 
Arg:$input);
+
+  let assemblyFormat = [{
+  `(` $kind `,` $input `)` `:` type($input) `,` type($result) attr-dict
+  }];
+
+  let hasVerifier = 1;
+  let hasFolder = 1;
+}
+
 
//===--===//
 // GlobalOp
 
//===--===//
diff --git a/clang/include/clang/CIR/MissingFeatures.h 
b/clang/include/clang/CIR/MissingFeatures.h
index 6c3d74cf96c64..fcbb2ae3db6aa 100644
--- a/clang/include/clang/CIR/MissingFeatures.h
+++ b/clang/include/clang/CIR/MissingFeatures.h
@@ -72,6 +72,10 @@ struct MissingFeatures {
   static bool opFuncLinkage() { return false; }
   static bool opFuncVisibility() { return false; }
 
+  // Unary operator handling
+  static bool opUnarySignedOverflow() { return false; }
+  static bool opUnaryPromotionType() { return false; }
+
   // Misc
   static bool scalarConversionOpts() { return false; }
   static bool tryEmitAsConstant() { return false; }
@@ -86,6 +90,11 @@ struct MissingFeatures {
   static bool aggValueSlot() { return false; }
 
   static bool unsizedTypes() { return false; }
+  static bool sanitizers() { return false; }
+  static bool CGFPOptionsRAII() { return false; }
+
+  // Missing types
+  static bool vectorType() { return false; }
 };
 
 } // namespace cir
diff --git a/clang/lib/CIR/CodeGen/CIRGenExpr.cpp 
b/clang/lib/CIR/CodeGen/CIRGenExpr.cpp
index 5b81fe172e645..24c0c8a18efd8 100644
--- a/clang/lib/CIR/CodeGen/CIRGenExpr.cpp
+++ b/clang/lib/CIR/CodeGen/CIRGenExpr.cpp
@@ -165,6 +165,54 @@ LValue CIRGenFunction::emitDeclRefLValue(const DeclRefExpr 
*e) {
   return LValue();
 }
 
+LValue CIRGenFunction::emitUnaryOpLValue(const UnaryOperator *e) {
+  UnaryOperatorKind op = e->getOpcode();
+
+  // __extension__ doesn't affect lvalue-ness.
+  if (op == UO_Extension)
+return emitLValue(e->getSubExpr());
+
+  switch (op) {
+  case UO_Deref: {
+cgm.errorNYI(e->getSourceRange(), "UnaryOp dereference");
+return LValue();
+  }
+  case UO_Real:
+  case UO_Imag: {
+cgm.errorNYI(e->getSourceRange(), "UnaryOp real/imag");
+return LValue();
+  }
+  case UO_PreInc:
+  case UO_PreDec: {
+bool isInc = e->isIncrementOp();
+LValue lv = emitLValue(e->getSubExpr());
+
+   

[clang] [flang] [llvm] [NFC][AMDGPU] Replace more direct arch comparison with isAMDGCN() (PR #131379)

2025-03-14 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-backend-amdgpu

@llvm/pr-subscribers-flang-driver

Author: Shilei Tian (shiltian)


Changes

This is an extension of #131357. Hopefully this would be the last one.

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


10 Files Affected:

- (modified) clang/include/clang/Driver/ToolChain.h (+1-1) 
- (modified) clang/lib/Basic/Targets/AMDGPU.h (+8-10) 
- (modified) clang/lib/Driver/Driver.cpp (+2-3) 
- (modified) clang/lib/Driver/ToolChains/HIPAMD.cpp (+1-1) 
- (modified) clang/lib/Frontend/CompilerInvocation.cpp (+1-1) 
- (modified) flang/lib/Frontend/CompilerInvocation.cpp (+1-1) 
- (modified) llvm/include/llvm/TargetParser/Triple.h (+1-3) 
- (modified) llvm/lib/Target/AMDGPU/AMDGPUISelDAGToDAG.cpp (+1-2) 
- (modified) llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp (+3-3) 
- (modified) llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp (+1-1) 


``diff
diff --git a/clang/include/clang/Driver/ToolChain.h 
b/clang/include/clang/Driver/ToolChain.h
index 7d1d8feebf35e..90004c64a694a 100644
--- a/clang/include/clang/Driver/ToolChain.h
+++ b/clang/include/clang/Driver/ToolChain.h
@@ -821,7 +821,7 @@ class ToolChain {
 return llvm::Triple("nvptx-nvidia-cuda");
   if (TT.getArch() == llvm::Triple::nvptx64)
 return llvm::Triple("nvptx64-nvidia-cuda");
-  if (TT.getArch() == llvm::Triple::amdgcn)
+  if (TT.isAMDGCN())
 return llvm::Triple("amdgcn-amd-amdhsa");
 }
 return TT;
diff --git a/clang/lib/Basic/Targets/AMDGPU.h b/clang/lib/Basic/Targets/AMDGPU.h
index 3d6778fb5a76f..9bee541cfdd5f 100644
--- a/clang/lib/Basic/Targets/AMDGPU.h
+++ b/clang/lib/Basic/Targets/AMDGPU.h
@@ -52,7 +52,7 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : public 
TargetInfo {
   std::string TargetID;
 
   bool hasFP64() const {
-return getTriple().getArch() == llvm::Triple::amdgcn ||
+return getTriple().isAMDGCN() ||
!!(GPUFeatures & llvm::AMDGPU::FEATURE_FP64);
   }
 
@@ -63,11 +63,11 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : 
public TargetInfo {
 
   /// Has fast fma f64
   bool hasFastFMA() const {
-return getTriple().getArch() == llvm::Triple::amdgcn;
+return getTriple().isAMDGCN();
   }
 
   bool hasFMAF() const {
-return getTriple().getArch() == llvm::Triple::amdgcn ||
+return getTriple().isAMDGCN() ||
!!(GPUFeatures & llvm::AMDGPU::FEATURE_FMA);
   }
 
@@ -76,13 +76,11 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : 
public TargetInfo {
   }
 
   bool hasLDEXPF() const {
-return getTriple().getArch() == llvm::Triple::amdgcn ||
+return getTriple().isAMDGCN() ||
!!(GPUFeatures & llvm::AMDGPU::FEATURE_LDEXP);
   }
 
-  static bool isAMDGCN(const llvm::Triple &TT) {
-return TT.getArch() == llvm::Triple::amdgcn;
-  }
+  static bool isAMDGCN(const llvm::Triple &TT) { return TT.isAMDGCN(); }
 
   static bool isR600(const llvm::Triple &TT) {
 return TT.getArch() == llvm::Triple::r600;
@@ -125,7 +123,7 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : 
public TargetInfo {
   }
 
   uint64_t getMaxPointerWidth() const override {
-return getTriple().getArch() == llvm::Triple::amdgcn ? 64 : 32;
+return getTriple().isAMDGCN() ? 64 : 32;
   }
 
   bool hasBFloat16Type() const override { return isAMDGCN(getTriple()); }
@@ -269,7 +267,7 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : 
public TargetInfo {
   }
 
   bool isValidCPUName(StringRef Name) const override {
-if (getTriple().getArch() == llvm::Triple::amdgcn)
+if (getTriple().isAMDGCN())
   return llvm::AMDGPU::parseArchAMDGCN(Name) != llvm::AMDGPU::GK_NONE;
 return llvm::AMDGPU::parseArchR600(Name) != llvm::AMDGPU::GK_NONE;
   }
@@ -277,7 +275,7 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : 
public TargetInfo {
   void fillValidCPUList(SmallVectorImpl &Values) const override;
 
   bool setCPU(const std::string &Name) override {
-if (getTriple().getArch() == llvm::Triple::amdgcn) {
+if (getTriple().isAMDGCN()) {
   GPUKind = llvm::AMDGPU::parseArchAMDGCN(Name);
   GPUFeatures = llvm::AMDGPU::getArchAttrAMDGCN(GPUKind);
 } else {
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 848b27012976d..0ae61fdd0d328 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -158,8 +158,7 @@ getHIPOffloadTargetTriple(const Driver &D, const ArgList 
&Args) {
   auto TT = getOffloadTargetTriple(D, Args);
   if (!TT)
 return std::nullopt;
-  if (TT->getArch() == llvm::Triple::amdgcn &&
-  TT->getVendor() == llvm::Triple::AMD &&
+  if (TT->isAMDGCN() && TT->getVendor() == llvm::Triple::AMD &&
   TT->getOS() == llvm::Triple::AMDHSA)
 return TT;
   if (TT->getArch() == llvm::Triple::spirv64)
@@ -3410,7 +3409,7 @@ class OffloadingActionBuilder final {
   const ToolChain *HostTC = 
C.getSingleOffloadToolChain();
   assert(HostTC && "No toolchain

[clang] [flang] [llvm] [NFC][AMDGPU] Replace more direct arch comparison with isAMDGCN() (PR #131379)

2025-03-14 Thread Shilei Tian via cfe-commits

https://github.com/shiltian updated 
https://github.com/llvm/llvm-project/pull/131379

>From 59bc234d4a5c343e093417150688a3231a230961 Mon Sep 17 00:00:00 2001
From: Shilei Tian 
Date: Fri, 14 Mar 2025 15:06:30 -0400
Subject: [PATCH 1/2] [NFC][AMDGPU] Replace more direct arch comparison with
 isAMDGCN()

This is an extension of #131357. Hopefully this would be the last one.
---
 clang/include/clang/Driver/ToolChain.h |  2 +-
 clang/lib/Basic/Targets/AMDGPU.h   | 18 --
 clang/lib/Driver/Driver.cpp|  5 ++---
 clang/lib/Driver/ToolChains/HIPAMD.cpp |  2 +-
 clang/lib/Frontend/CompilerInvocation.cpp  |  2 +-
 flang/lib/Frontend/CompilerInvocation.cpp  |  2 +-
 llvm/include/llvm/TargetParser/Triple.h|  4 +---
 llvm/lib/Target/AMDGPU/AMDGPUISelDAGToDAG.cpp  |  3 +--
 .../AMDGPU/AsmParser/AMDGPUAsmParser.cpp   |  6 +++---
 .../lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp |  2 +-
 10 files changed, 20 insertions(+), 26 deletions(-)

diff --git a/clang/include/clang/Driver/ToolChain.h 
b/clang/include/clang/Driver/ToolChain.h
index 7d1d8feebf35e..90004c64a694a 100644
--- a/clang/include/clang/Driver/ToolChain.h
+++ b/clang/include/clang/Driver/ToolChain.h
@@ -821,7 +821,7 @@ class ToolChain {
 return llvm::Triple("nvptx-nvidia-cuda");
   if (TT.getArch() == llvm::Triple::nvptx64)
 return llvm::Triple("nvptx64-nvidia-cuda");
-  if (TT.getArch() == llvm::Triple::amdgcn)
+  if (TT.isAMDGCN())
 return llvm::Triple("amdgcn-amd-amdhsa");
 }
 return TT;
diff --git a/clang/lib/Basic/Targets/AMDGPU.h b/clang/lib/Basic/Targets/AMDGPU.h
index 3d6778fb5a76f..9bee541cfdd5f 100644
--- a/clang/lib/Basic/Targets/AMDGPU.h
+++ b/clang/lib/Basic/Targets/AMDGPU.h
@@ -52,7 +52,7 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : public 
TargetInfo {
   std::string TargetID;
 
   bool hasFP64() const {
-return getTriple().getArch() == llvm::Triple::amdgcn ||
+return getTriple().isAMDGCN() ||
!!(GPUFeatures & llvm::AMDGPU::FEATURE_FP64);
   }
 
@@ -63,11 +63,11 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : 
public TargetInfo {
 
   /// Has fast fma f64
   bool hasFastFMA() const {
-return getTriple().getArch() == llvm::Triple::amdgcn;
+return getTriple().isAMDGCN();
   }
 
   bool hasFMAF() const {
-return getTriple().getArch() == llvm::Triple::amdgcn ||
+return getTriple().isAMDGCN() ||
!!(GPUFeatures & llvm::AMDGPU::FEATURE_FMA);
   }
 
@@ -76,13 +76,11 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : 
public TargetInfo {
   }
 
   bool hasLDEXPF() const {
-return getTriple().getArch() == llvm::Triple::amdgcn ||
+return getTriple().isAMDGCN() ||
!!(GPUFeatures & llvm::AMDGPU::FEATURE_LDEXP);
   }
 
-  static bool isAMDGCN(const llvm::Triple &TT) {
-return TT.getArch() == llvm::Triple::amdgcn;
-  }
+  static bool isAMDGCN(const llvm::Triple &TT) { return TT.isAMDGCN(); }
 
   static bool isR600(const llvm::Triple &TT) {
 return TT.getArch() == llvm::Triple::r600;
@@ -125,7 +123,7 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : 
public TargetInfo {
   }
 
   uint64_t getMaxPointerWidth() const override {
-return getTriple().getArch() == llvm::Triple::amdgcn ? 64 : 32;
+return getTriple().isAMDGCN() ? 64 : 32;
   }
 
   bool hasBFloat16Type() const override { return isAMDGCN(getTriple()); }
@@ -269,7 +267,7 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : 
public TargetInfo {
   }
 
   bool isValidCPUName(StringRef Name) const override {
-if (getTriple().getArch() == llvm::Triple::amdgcn)
+if (getTriple().isAMDGCN())
   return llvm::AMDGPU::parseArchAMDGCN(Name) != llvm::AMDGPU::GK_NONE;
 return llvm::AMDGPU::parseArchR600(Name) != llvm::AMDGPU::GK_NONE;
   }
@@ -277,7 +275,7 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : 
public TargetInfo {
   void fillValidCPUList(SmallVectorImpl &Values) const override;
 
   bool setCPU(const std::string &Name) override {
-if (getTriple().getArch() == llvm::Triple::amdgcn) {
+if (getTriple().isAMDGCN()) {
   GPUKind = llvm::AMDGPU::parseArchAMDGCN(Name);
   GPUFeatures = llvm::AMDGPU::getArchAttrAMDGCN(GPUKind);
 } else {
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 848b27012976d..0ae61fdd0d328 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -158,8 +158,7 @@ getHIPOffloadTargetTriple(const Driver &D, const ArgList 
&Args) {
   auto TT = getOffloadTargetTriple(D, Args);
   if (!TT)
 return std::nullopt;
-  if (TT->getArch() == llvm::Triple::amdgcn &&
-  TT->getVendor() == llvm::Triple::AMD &&
+  if (TT->isAMDGCN() && TT->getVendor() == llvm::Triple::AMD &&
   TT->getOS() == llvm::Triple::AMDHSA)
 return TT;
   if (TT->getArch() == llvm::Triple::spirv64)
@@ -3410,7 +3409,7 @@ class OffloadingActionBuilder final {
   const To

[clang] Warn about virtual methods in `final` classes (PR #131188)

2025-03-14 Thread Hans Wennborg via cfe-commits


@@ -2706,6 +2706,9 @@ def warn_final_dtor_non_final_class : Warning<
   InGroup;
 def note_final_dtor_non_final_class_silence : Note<
   "mark %0 as '%select{final|sealed}1' to silence this warning">;
+def warn_unnecessary_virtual_specifier : Warning<
+  "virtual method %0 is inside a 'final' class and can never be overridden">,
+  InGroup, DefaultIgnore;

zmodem wrote:

Instead of DefaultIgnore, could we turn this on by default? I think it should 
be pretty high fidelity. Or at least we could put it in -Wall or -Wextra?

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


[clang] Warn about virtual methods in `final` classes (PR #131188)

2025-03-14 Thread Hans Wennborg via cfe-commits

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


[clang] [flang] [llvm] [NFC][AMDGPU] Replace more direct arch comparison with isAMDGCN() (PR #131379)

2025-03-14 Thread via cfe-commits

github-actions[bot] wrote:




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



You can test this locally with the following command:


``bash
git-clang-format --diff 7598ceaf51e0fa726bcd50a251f86435d871ee70 
59bc234d4a5c343e093417150688a3231a230961 --extensions h,cpp -- 
clang/include/clang/Driver/ToolChain.h clang/lib/Basic/Targets/AMDGPU.h 
clang/lib/Driver/Driver.cpp clang/lib/Driver/ToolChains/HIPAMD.cpp 
clang/lib/Frontend/CompilerInvocation.cpp 
flang/lib/Frontend/CompilerInvocation.cpp 
llvm/include/llvm/TargetParser/Triple.h 
llvm/lib/Target/AMDGPU/AMDGPUISelDAGToDAG.cpp 
llvm/lib/Target/AMDGPU/AsmParser/AMDGPUAsmParser.cpp 
llvm/lib/Target/AMDGPU/Utils/AMDGPUBaseInfo.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Basic/Targets/AMDGPU.h b/clang/lib/Basic/Targets/AMDGPU.h
index 9bee541cfd..63b0d4b6e5 100644
--- a/clang/lib/Basic/Targets/AMDGPU.h
+++ b/clang/lib/Basic/Targets/AMDGPU.h
@@ -62,9 +62,7 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUTargetInfo final : public 
TargetInfo {
   }
 
   /// Has fast fma f64
-  bool hasFastFMA() const {
-return getTriple().isAMDGCN();
-  }
+  bool hasFastFMA() const { return getTriple().isAMDGCN(); }
 
   bool hasFMAF() const {
 return getTriple().isAMDGCN() ||
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 0ae61fdd0d..056bfcf1b7 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -3408,8 +3408,7 @@ class OffloadingActionBuilder final {
 
   const ToolChain *HostTC = 
C.getSingleOffloadToolChain();
   assert(HostTC && "No toolchain for host compilation.");
-  if (HostTC->getTriple().isNVPTX() ||
-  HostTC->getTriple().isAMDGCN()) {
+  if (HostTC->getTriple().isNVPTX() || HostTC->getTriple().isAMDGCN()) {
 // We do not support targeting NVPTX/AMDGCN for host compilation. Throw
 // an error and abort pipeline construction early so we don't trip
 // asserts that assume device-side compilation.
diff --git a/clang/lib/Frontend/CompilerInvocation.cpp 
b/clang/lib/Frontend/CompilerInvocation.cpp
index 8c38acad0c..e708bee464 100644
--- a/clang/lib/Frontend/CompilerInvocation.cpp
+++ b/clang/lib/Frontend/CompilerInvocation.cpp
@@ -4322,8 +4322,7 @@ bool CompilerInvocation::ParseLangArgs(LangOptions &Opts, 
ArgList &Args,
 TT.getArch() == llvm::Triple::systemz ||
 TT.getArch() == llvm::Triple::loongarch64 ||
 TT.getArch() == llvm::Triple::nvptx ||
-TT.getArch() == llvm::Triple::nvptx64 ||
-TT.isAMDGCN() ||
+TT.getArch() == llvm::Triple::nvptx64 || TT.isAMDGCN() ||
 TT.getArch() == llvm::Triple::x86 ||
 TT.getArch() == llvm::Triple::x86_64))
 Diags.Report(diag::err_drv_invalid_omp_target) << A->getValue(i);
diff --git a/flang/lib/Frontend/CompilerInvocation.cpp 
b/flang/lib/Frontend/CompilerInvocation.cpp
index de8a3bfb8b..f433ec9966 100644
--- a/flang/lib/Frontend/CompilerInvocation.cpp
+++ b/flang/lib/Frontend/CompilerInvocation.cpp
@@ -1174,8 +1174,7 @@ static bool parseOpenMPArgs(CompilerInvocation &res, 
llvm::opt::ArgList &args,
   !(tt.getArch() == llvm::Triple::aarch64 || tt.isPPC() ||
 tt.getArch() == llvm::Triple::systemz ||
 tt.getArch() == llvm::Triple::nvptx ||
-tt.getArch() == llvm::Triple::nvptx64 ||
-tt.isAMDGCN() ||
+tt.getArch() == llvm::Triple::nvptx64 || tt.isAMDGCN() ||
 tt.getArch() == llvm::Triple::x86 ||
 tt.getArch() == llvm::Triple::x86_64))
 diags.Report(clang::diag::err_drv_invalid_omp_target)

``




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


[clang-tools-extra] [clang-tidy] Add an option to treat warnings as errors (PR #128221)

2025-03-14 Thread Julian Ruess via cfe-commits

https://github.com/juru1234 updated 
https://github.com/llvm/llvm-project/pull/128221

>From 534f33d19ce72b299789db9a2497ba2b6d5a9e47 Mon Sep 17 00:00:00 2001
From: Julian Ruess 
Date: Fri, 21 Feb 2025 20:42:46 +0100
Subject: [PATCH] [clang-tidy-diff.py] Add an option to treat warnings as
 errors

This patch allows to treat warnings as erros using clang-tidy-diff.py.

Co-authored-by: Piotr Zegar 
---
 clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py | 7 +++
 clang-tools-extra/docs/ReleaseNotes.rst  | 3 +++
 2 files changed, 10 insertions(+)

diff --git a/clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py 
b/clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
index 33de2077dfb1a..0f8ac7344aca3 100755
--- a/clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
+++ b/clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
@@ -259,6 +259,11 @@ def main():
 action="store_true",
 help="Only check files in the compilation database",
 )
+parser.add_argument(
+"-warnings-as-errors",
+help="Upgrades clang-tidy warnings to errors. Same format as 
'-checks'.",
+default="",
+)
 
 clang_tidy_args = []
 argv = sys.argv[1:]
@@ -374,6 +379,8 @@ def main():
 common_clang_tidy_args.append("-extra-arg-before=%s" % arg)
 for plugin in args.plugins:
 common_clang_tidy_args.append("-load=%s" % plugin)
+if args.warnings_as_errors:
+common_clang_tidy_args.append("-warnings-as-errors=" + 
args.warnings_as_errors)
 
 for name in lines_by_file:
 line_filter_json = json.dumps(
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index d621a9c6d840b..8e3bfa9e978d1 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -97,6 +97,9 @@ Improvements to clang-tidy
   Note: this may lead to false negatives; downstream users may need to adjust
   their checks to preserve existing behavior.
 
+- Improved :program:`clang-tidy-diff.py` script. Add the `-warnings-as-errors`
+  argument to treat warnings as errors.
+
 New checks
 ^^
 

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


[clang] [AMDGPU][clang] provide device implementation for __builtin_logb and … (PR #129347)

2025-03-14 Thread via cfe-commits

https://github.com/choikwa updated 
https://github.com/llvm/llvm-project/pull/129347

>From 2da966db9ae5837b6fca0a6afc84e4258756e0df Mon Sep 17 00:00:00 2001
From: Kevin Choi 
Date: Fri, 28 Feb 2025 16:52:03 -0600
Subject: [PATCH] [AMDGPU][clang] provide device implementation for
 __builtin_logb and __builtin_scalbn

Clang generates library calls for __builtin_* functions which can be a problem 
for GPUs that cannot handle them.
This patch generates a device implementations for __builtin_logb and 
__builtin_scalbn.
---
 clang/lib/CodeGen/CGBuiltin.cpp   | 43 ++-
 clang/lib/CodeGen/CodeGenModule.h |  5 
 clang/test/CodeGenHIP/logb_scalbn.hip | 40 +
 3 files changed, 87 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/CodeGenHIP/logb_scalbn.hip

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index a5ed2595bad4d..e6596e56a1627 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -6621,10 +6621,27 @@ RValue CodeGenFunction::EmitBuiltinExpr(const 
GlobalDecl GD, unsigned BuiltinID,
   }
   }
 
+  // These will be emitted as Intrinsic later.
+  auto NeedsDeviceOverload = [&](unsigned BuiltinID) {
+if (getTarget().getTriple().isAMDGCN()) {
+  switch (BuiltinID) {
+  default:
+return false;
+  case Builtin::BIlogb:
+  case Builtin::BI__builtin_logb:
+  case Builtin::BIscalbn:
+  case Builtin::BI__builtin_scalbn:
+return true;
+  }
+}
+return false;
+  };
+
   // If this is an alias for a lib function (e.g. __builtin_sin), emit
   // the call using the normal call path, but using the unmangled
   // version of the function name.
-  if (getContext().BuiltinInfo.isLibFunction(BuiltinID))
+  if (!NeedsDeviceOverload(BuiltinID) &&
+  getContext().BuiltinInfo.isLibFunction(BuiltinID))
 return emitLibraryCall(*this, FD, E,
CGM.getBuiltinLibFunction(FD, BuiltinID));
 
@@ -20910,6 +20927,30 @@ Value *CodeGenFunction::EmitAMDGPUBuiltinExpr(unsigned 
BuiltinID,
   case AMDGPU::BI__builtin_amdgcn_s_prefetch_data:
 return emitBuiltinWithOneOverloadedType<2>(
 *this, E, Intrinsic::amdgcn_s_prefetch_data);
+  case Builtin::BIlogb:
+  case Builtin::BI__builtin_logb: {
+auto Src0 = EmitScalarExpr(E->getArg(0));
+auto FrExpFunc = CGM.getIntrinsic(Intrinsic::amdgcn_frexp_exp,
+  {Builder.getInt32Ty(), Src0->getType()});
+auto FrExp = Builder.CreateCall(FrExpFunc, Src0);
+auto Add = Builder.CreateAdd(
+FrExp, ConstantInt::getSigned(FrExp->getType(), -1), "", false, true);
+auto SIToFP = Builder.CreateSIToFP(Add, Builder.getDoubleTy());
+auto Fabs = emitBuiltinWithOneOverloadedType<1>(*this, E, Intrinsic::fabs);
+auto FCmpONE = Builder.CreateFCmpONE(
+Fabs, ConstantFP::getInfinity(Builder.getDoubleTy()));
+auto Sel1 = Builder.CreateSelect(FCmpONE, SIToFP, Fabs);
+auto FCmpOEQ =
+Builder.CreateFCmpOEQ(Src0, 
ConstantFP::getZero(Builder.getDoubleTy()));
+auto Sel2 = Builder.CreateSelect(
+FCmpOEQ, ConstantFP::getInfinity(Builder.getDoubleTy(), /*Neg*/ true),
+Sel1);
+return Sel2;
+  }
+  case Builtin::BIscalbn:
+  case Builtin::BI__builtin_scalbn:
+return emitBinaryExpMaybeConstrainedFPBuiltin(
+*this, E, Intrinsic::ldexp, Intrinsic::experimental_constrained_ldexp);
   default:
 return nullptr;
   }
diff --git a/clang/lib/CodeGen/CodeGenModule.h 
b/clang/lib/CodeGen/CodeGenModule.h
index 6deb467b2cc9f..ae1441dc3d009 100644
--- a/clang/lib/CodeGen/CodeGenModule.h
+++ b/clang/lib/CodeGen/CodeGenModule.h
@@ -1231,6 +1231,11 @@ class CodeGenModule : public CodeGenTypeCache {
   llvm::FunctionType *FnType = nullptr, bool DontDefer = false,
   ForDefinition_t IsForDefinition = NotForDefinition);
 
+  /// Given a builtin id for a function, return a Function* for device
+  /// overload implementation.
+  llvm::Constant *getDeviceLibFunction(const FunctionDecl *FD,
+   unsigned BuiltinID);
+
   /// Given a builtin id for a function like "__builtin_fabsf", return a
   /// Function* for "fabsf".
   llvm::Constant *getBuiltinLibFunction(const FunctionDecl *FD,
diff --git a/clang/test/CodeGenHIP/logb_scalbn.hip 
b/clang/test/CodeGenHIP/logb_scalbn.hip
new file mode 100644
index 0..c72c5dd189fbf
--- /dev/null
+++ b/clang/test/CodeGenHIP/logb_scalbn.hip
@@ -0,0 +1,40 @@
+// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py 
UTC_ARGS: --version 5
+// RUN: %clang --cuda-device-only -nogpuinc -nogpulib -emit-llvm -S -o - %s | 
FileCheck %s
+#include 
+#define __device__ __attribute__((device))
+
+// CHECK-LABEL: define hidden void @_Z9my_kernelv(
+// CHECK-SAME: ) #[[ATTR0:[0-9]+]] {
+// CHECK-NEXT:  [[ENTRY:.*:]]
+// CHECK-NEXT:[[D1:%.*]] = alloca float, align 4, addrspace(5)
+// CHECK-NEXT:[[D2:

[clang] [C++20][Modules] Do not update the declaration generation number if the redeclaration chain completion was delayed. (PR #129982)

2025-03-14 Thread Michael Park via cfe-commits

https://github.com/mpark updated 
https://github.com/llvm/llvm-project/pull/129982

>From ebf6cd9c13ae6dbd9bfcece78491bdf01f0f170f Mon Sep 17 00:00:00 2001
From: Michael Park 
Date: Wed, 5 Mar 2025 18:46:10 -0800
Subject: [PATCH 1/3] [clang][modules] Add a unit test for the assertion
 failure in bootstrap build on OS X with XCode.

---
 clang/test/Modules/pr129982.cpp | 107 
 1 file changed, 107 insertions(+)
 create mode 100644 clang/test/Modules/pr129982.cpp

diff --git a/clang/test/Modules/pr129982.cpp b/clang/test/Modules/pr129982.cpp
new file mode 100644
index 0..b19cccfd07687
--- /dev/null
+++ b/clang/test/Modules/pr129982.cpp
@@ -0,0 +1,107 @@
+// If this test fails, it should be investigated under Debug builds.
+// Before the PR, this test was violating an assertion.
+
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+
+// RUN: %clang_cc1 -std=c++20 -emit-obj -fmodules \
+// RUN:  -fmodule-map-file=%t/module.modulemap \
+// RUN:  -fmodules-cache-path=%t %t/a.cpp
+
+//--- module.modulemap
+module ebo {
+  header "ebo.h"
+}
+
+module fwd {
+  header "fwd.h"
+}
+
+module s {
+  header "s.h"
+  export *
+}
+
+module mod {
+  header "a.h"
+  header "b.h"
+}
+
+//--- ebo.h
+#pragma once
+
+namespace N { inline namespace __1 {
+
+template 
+struct EBO : T {
+  EBO() = default;
+};
+
+}}
+
+//--- fwd.h
+#pragma once
+
+namespace N { inline namespace __1 {
+
+template 
+struct Empty;
+
+template 
+struct BS;
+
+using S = BS>;
+
+}}
+
+//--- s.h
+#pragma once
+
+#include "fwd.h"
+#include "ebo.h"
+
+namespace N { inline namespace __1 {
+
+template 
+struct Empty {};
+
+template 
+struct BS {
+EBO _;
+void f();
+};
+
+extern template void BS>::f();
+
+}}
+
+//--- b.h
+#pragma once
+
+#include "s.h"
+
+struct B {
+  void f() {
+N::S{}.f();
+  }
+};
+
+//--- a.h
+#pragma once
+
+#include "s.h"
+
+struct A {
+  void f(int) {}
+  void f(const N::S &) {}
+
+  void g();
+};
+
+//--- a.cpp
+#include "a.h"
+
+void A::g() { f(0); }
+
+// expected-no-diagnostics

>From 7bb10f498c55b8c1ec9e10bd5efad7a7ab90437f Mon Sep 17 00:00:00 2001
From: Michael Park 
Date: Fri, 7 Mar 2025 01:09:38 -0800
Subject: [PATCH 2/3] =?UTF-8?q?Reapply=20"[C++20][Modules][Serialization]?=
 =?UTF-8?q?=20Delay=20marking=20pending=20incompl=E2=80=A6=20(#127136)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This reverts commit 912b154f3a3f8c3cebf5cc5731fd8b0749762da5.
---
 clang/lib/Serialization/ASTReader.cpp | 25 ---
 clang/test/Modules/pr121245.cpp   | 93 +++
 2 files changed, 105 insertions(+), 13 deletions(-)
 create mode 100644 clang/test/Modules/pr121245.cpp

diff --git a/clang/lib/Serialization/ASTReader.cpp 
b/clang/lib/Serialization/ASTReader.cpp
index 8e9978829c512..41b6c2a4d64ab 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -10182,12 +10182,12 @@ void ASTReader::visitTopLevelModuleMaps(
 }
 
 void ASTReader::finishPendingActions() {
-  while (
-  !PendingIdentifierInfos.empty() || !PendingDeducedFunctionTypes.empty() 
||
-  !PendingDeducedVarTypes.empty() || !PendingIncompleteDeclChains.empty() 
||
-  !PendingDeclChains.empty() || !PendingMacroIDs.empty() ||
-  !PendingDeclContextInfos.empty() || !PendingUpdateRecords.empty() ||
-  !PendingObjCExtensionIvarRedeclarations.empty()) {
+  while (!PendingIdentifierInfos.empty() ||
+ !PendingDeducedFunctionTypes.empty() ||
+ !PendingDeducedVarTypes.empty() || !PendingDeclChains.empty() ||
+ !PendingMacroIDs.empty() || !PendingDeclContextInfos.empty() ||
+ !PendingUpdateRecords.empty() ||
+ !PendingObjCExtensionIvarRedeclarations.empty()) {
 // If any identifiers with corresponding top-level declarations have
 // been loaded, load those declarations now.
 using TopLevelDeclsMap =
@@ -10235,13 +10235,6 @@ void ASTReader::finishPendingActions() {
 }
 PendingDeducedVarTypes.clear();
 
-// For each decl chain that we wanted to complete while deserializing, mark
-// it as "still needs to be completed".
-for (unsigned I = 0; I != PendingIncompleteDeclChains.size(); ++I) {
-  markIncompleteDeclChain(PendingIncompleteDeclChains[I]);
-}
-PendingIncompleteDeclChains.clear();
-
 // Load pending declaration chains.
 for (unsigned I = 0; I != PendingDeclChains.size(); ++I)
   loadPendingDeclChain(PendingDeclChains[I].first,
@@ -10479,6 +10472,12 @@ void ASTReader::finishPendingActions() {
   for (auto *ND : PendingMergedDefinitionsToDeduplicate)
 getContext().deduplicateMergedDefinitonsFor(ND);
   PendingMergedDefinitionsToDeduplicate.clear();
+
+  // For each decl chain that we wanted to complete while deserializing, mark
+  // it as "still needs to be completed".
+  for (Decl *D : PendingIncompleteDeclChains)
+markIncompleteDeclChain(D);
+  PendingIncompleteDeclChains.clear();
 }

[clang] [C++20][Modules] Do not update the declaration generation number if the redeclaration chain completion was delayed. (PR #129982)

2025-03-14 Thread via cfe-commits

github-actions[bot] wrote:




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



You can test this locally with the following command:


``bash
git-clang-format --diff fbf0276b6a7a7a4508c373cf87fc349569652659 
fb2de5d3725588acace54cfa62785e480c2666e0 --extensions h,cpp -- 
clang/test/Modules/pr121245.cpp clang/test/Modules/pr129982.cpp 
clang/include/clang/Serialization/ASTReader.h 
clang/lib/Serialization/ASTReader.cpp clang/lib/Serialization/ASTReaderDecl.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Serialization/ASTReader.cpp 
b/clang/lib/Serialization/ASTReader.cpp
index e3a51151c2..9d7be97b2c 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -10820,7 +10820,8 @@ void ASTReader::FinishedDeserializing() {
 PendingDeducedTypeUpdates.clear();
 for (auto Update : DTUpdates) {
   ProcessingUpdatesRAIIObj ProcessingUpdates(*this);
-  // FIXME: If the return type is already deduced, check that it 
matches.
+  // FIXME: If the return type is already deduced, check that it
+  // matches.
   getContext().adjustDeducedFunctionResultType(Update.first,
Update.second);
 }

``




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


[clang] [C++20][Modules] Prevent premature call to PassInterestingDeclsToConsumer() within FinishedDeserializing(). (PR #129982)

2025-03-14 Thread Michael Park via cfe-commits

https://github.com/mpark updated 
https://github.com/llvm/llvm-project/pull/129982

>From ebf6cd9c13ae6dbd9bfcece78491bdf01f0f170f Mon Sep 17 00:00:00 2001
From: Michael Park 
Date: Wed, 5 Mar 2025 18:46:10 -0800
Subject: [PATCH 1/3] [clang][modules] Add a unit test for the assertion
 failure in bootstrap build on OS X with XCode.

---
 clang/test/Modules/pr129982.cpp | 107 
 1 file changed, 107 insertions(+)
 create mode 100644 clang/test/Modules/pr129982.cpp

diff --git a/clang/test/Modules/pr129982.cpp b/clang/test/Modules/pr129982.cpp
new file mode 100644
index 0..b19cccfd07687
--- /dev/null
+++ b/clang/test/Modules/pr129982.cpp
@@ -0,0 +1,107 @@
+// If this test fails, it should be investigated under Debug builds.
+// Before the PR, this test was violating an assertion.
+
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+
+// RUN: %clang_cc1 -std=c++20 -emit-obj -fmodules \
+// RUN:  -fmodule-map-file=%t/module.modulemap \
+// RUN:  -fmodules-cache-path=%t %t/a.cpp
+
+//--- module.modulemap
+module ebo {
+  header "ebo.h"
+}
+
+module fwd {
+  header "fwd.h"
+}
+
+module s {
+  header "s.h"
+  export *
+}
+
+module mod {
+  header "a.h"
+  header "b.h"
+}
+
+//--- ebo.h
+#pragma once
+
+namespace N { inline namespace __1 {
+
+template 
+struct EBO : T {
+  EBO() = default;
+};
+
+}}
+
+//--- fwd.h
+#pragma once
+
+namespace N { inline namespace __1 {
+
+template 
+struct Empty;
+
+template 
+struct BS;
+
+using S = BS>;
+
+}}
+
+//--- s.h
+#pragma once
+
+#include "fwd.h"
+#include "ebo.h"
+
+namespace N { inline namespace __1 {
+
+template 
+struct Empty {};
+
+template 
+struct BS {
+EBO _;
+void f();
+};
+
+extern template void BS>::f();
+
+}}
+
+//--- b.h
+#pragma once
+
+#include "s.h"
+
+struct B {
+  void f() {
+N::S{}.f();
+  }
+};
+
+//--- a.h
+#pragma once
+
+#include "s.h"
+
+struct A {
+  void f(int) {}
+  void f(const N::S &) {}
+
+  void g();
+};
+
+//--- a.cpp
+#include "a.h"
+
+void A::g() { f(0); }
+
+// expected-no-diagnostics

>From 7bb10f498c55b8c1ec9e10bd5efad7a7ab90437f Mon Sep 17 00:00:00 2001
From: Michael Park 
Date: Fri, 7 Mar 2025 01:09:38 -0800
Subject: [PATCH 2/3] =?UTF-8?q?Reapply=20"[C++20][Modules][Serialization]?=
 =?UTF-8?q?=20Delay=20marking=20pending=20incompl=E2=80=A6=20(#127136)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This reverts commit 912b154f3a3f8c3cebf5cc5731fd8b0749762da5.
---
 clang/lib/Serialization/ASTReader.cpp | 25 ---
 clang/test/Modules/pr121245.cpp   | 93 +++
 2 files changed, 105 insertions(+), 13 deletions(-)
 create mode 100644 clang/test/Modules/pr121245.cpp

diff --git a/clang/lib/Serialization/ASTReader.cpp 
b/clang/lib/Serialization/ASTReader.cpp
index 8e9978829c512..41b6c2a4d64ab 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -10182,12 +10182,12 @@ void ASTReader::visitTopLevelModuleMaps(
 }
 
 void ASTReader::finishPendingActions() {
-  while (
-  !PendingIdentifierInfos.empty() || !PendingDeducedFunctionTypes.empty() 
||
-  !PendingDeducedVarTypes.empty() || !PendingIncompleteDeclChains.empty() 
||
-  !PendingDeclChains.empty() || !PendingMacroIDs.empty() ||
-  !PendingDeclContextInfos.empty() || !PendingUpdateRecords.empty() ||
-  !PendingObjCExtensionIvarRedeclarations.empty()) {
+  while (!PendingIdentifierInfos.empty() ||
+ !PendingDeducedFunctionTypes.empty() ||
+ !PendingDeducedVarTypes.empty() || !PendingDeclChains.empty() ||
+ !PendingMacroIDs.empty() || !PendingDeclContextInfos.empty() ||
+ !PendingUpdateRecords.empty() ||
+ !PendingObjCExtensionIvarRedeclarations.empty()) {
 // If any identifiers with corresponding top-level declarations have
 // been loaded, load those declarations now.
 using TopLevelDeclsMap =
@@ -10235,13 +10235,6 @@ void ASTReader::finishPendingActions() {
 }
 PendingDeducedVarTypes.clear();
 
-// For each decl chain that we wanted to complete while deserializing, mark
-// it as "still needs to be completed".
-for (unsigned I = 0; I != PendingIncompleteDeclChains.size(); ++I) {
-  markIncompleteDeclChain(PendingIncompleteDeclChains[I]);
-}
-PendingIncompleteDeclChains.clear();
-
 // Load pending declaration chains.
 for (unsigned I = 0; I != PendingDeclChains.size(); ++I)
   loadPendingDeclChain(PendingDeclChains[I].first,
@@ -10479,6 +10472,12 @@ void ASTReader::finishPendingActions() {
   for (auto *ND : PendingMergedDefinitionsToDeduplicate)
 getContext().deduplicateMergedDefinitonsFor(ND);
   PendingMergedDefinitionsToDeduplicate.clear();
+
+  // For each decl chain that we wanted to complete while deserializing, mark
+  // it as "still needs to be completed".
+  for (Decl *D : PendingIncompleteDeclChains)
+markIncompleteDeclChain(D);
+  PendingIncompleteDeclChains.clear();
 }

[clang] [C++20][Modules] Prevent premature call to PassInterestingDeclsToConsumer() within FinishedDeserializing(). (PR #129982)

2025-03-14 Thread Michael Park via cfe-commits

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


[clang] Move const qualification of array to its elements (PR #131366)

2025-03-14 Thread Eli Friedman via cfe-commits

efriedma-quic wrote:

Non-canonical types, are, as the name suggests, non-canonical: they can have 
all kinds of type sugar, and type qualifiers at all levels.  Please don't try 
to change that; just fix getCommonSugaredType so it can tolerate a const 
qualifier in this position.

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


[clang] [C++20][Modules] Prevent premature call to PassInterestingDeclsToConsumer() within FinishedDeserializing(). (PR #129982)

2025-03-14 Thread Richard Smith via cfe-commits

https://github.com/zygoloid commented:

Thanks, the explanation and code change makes sense to me.

Should this bugfix have a release note?

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


[clang] cb64a36 - [HLSL] Make sure `isSigned` flag is set on target type for `TypedBuffer` resources with signed int vectors (#130223)

2025-03-14 Thread via cfe-commits

Author: Helena Kotas
Date: 2025-03-14T13:09:21-07:00
New Revision: cb64a363ca71033937108763b078906b86c7fb04

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

LOG: [HLSL] Make sure `isSigned` flag is set on target type for `TypedBuffer` 
resources with signed int vectors (#130223)

Fixes #130191

Added: 


Modified: 
clang/lib/CodeGen/Targets/DirectX.cpp
clang/test/CodeGenHLSL/builtins/RWBuffer-elementtype.hlsl

Removed: 




diff  --git a/clang/lib/CodeGen/Targets/DirectX.cpp 
b/clang/lib/CodeGen/Targets/DirectX.cpp
index 88a4b812db675..0c5fc6e0d9fb1 100644
--- a/clang/lib/CodeGen/Targets/DirectX.cpp
+++ b/clang/lib/CodeGen/Targets/DirectX.cpp
@@ -59,8 +59,14 @@ llvm::Type *DirectXTargetCodeGenInfo::getHLSLType(
 SmallVector Ints = {/*IsWriteable*/ ResAttrs.ResourceClass ==
  llvm::dxil::ResourceClass::UAV,
  /*IsROV*/ ResAttrs.IsROV};
-if (!ResAttrs.RawBuffer)
-  Ints.push_back(/*IsSigned*/ ContainedTy->isSignedIntegerType());
+if (!ResAttrs.RawBuffer) {
+  const clang::Type *ElemType = ContainedTy->getUnqualifiedDesugaredType();
+  if (ElemType->isVectorType())
+ElemType = cast(ElemType)
+   ->getElementType()
+   ->getUnqualifiedDesugaredType();
+  Ints.push_back(/*IsSigned*/ ElemType->isSignedIntegerType());
+}
 
 return llvm::TargetExtType::get(Ctx, TypeName, {ElemType}, Ints);
   }

diff  --git a/clang/test/CodeGenHLSL/builtins/RWBuffer-elementtype.hlsl 
b/clang/test/CodeGenHLSL/builtins/RWBuffer-elementtype.hlsl
index 11c77644a906d..0944ad59d5fb5 100644
--- a/clang/test/CodeGenHLSL/builtins/RWBuffer-elementtype.hlsl
+++ b/clang/test/CodeGenHLSL/builtins/RWBuffer-elementtype.hlsl
@@ -10,10 +10,11 @@
 // DXIL: %"class.hlsl::RWBuffer.5" = type { target("dx.TypedBuffer", half, 1, 
0, 0) }
 // DXIL: %"class.hlsl::RWBuffer.6" = type { target("dx.TypedBuffer", float, 1, 
0, 0) }
 // DXIL: %"class.hlsl::RWBuffer.7" = type { target("dx.TypedBuffer", double, 
1, 0, 0) }
-// DXIL: %"class.hlsl::RWBuffer.8" = type { target("dx.TypedBuffer", <4 x 
i16>, 1, 0, 0) }
+// DXIL: %"class.hlsl::RWBuffer.8" = type { target("dx.TypedBuffer", <4 x 
i16>, 1, 0, 1) }
 // DXIL: %"class.hlsl::RWBuffer.9" = type { target("dx.TypedBuffer", <3 x 
i32>, 1, 0, 0) }
 // DXIL: %"class.hlsl::RWBuffer.10" = type { target("dx.TypedBuffer", <2 x 
half>, 1, 0, 0) }
 // DXIL: %"class.hlsl::RWBuffer.11" = type { target("dx.TypedBuffer", <3 x 
float>, 1, 0, 0) }
+// DXIL: %"class.hlsl::RWBuffer.12" = type { target("dx.TypedBuffer", <4 x 
i32>, 1, 0, 1) }
 
 // SPIRV: %"class.hlsl::RWBuffer" = type { target("spirv.Image", i16, 5, 2, 0, 
0, 2, 0) }
 // SPIRV: %"class.hlsl::RWBuffer.0" = type { target("spirv.Image", i16, 5, 2, 
0, 0, 2, 0) }
@@ -28,8 +29,7 @@
 // SPIRV: %"class.hlsl::RWBuffer.9" = type { target("spirv.Image", i32, 5, 2, 
0, 0, 2, 0) }
 // SPIRV: %"class.hlsl::RWBuffer.10" = type { target("spirv.Image", half, 5, 
2, 0, 0, 2, 0) }
 // SPIRV: %"class.hlsl::RWBuffer.11" = type { target("spirv.Image", float, 5, 
2, 0, 0, 2, 0) }
-
-
+// SPIRV: %"class.hlsl::RWBuffer.12" = type { target("spirv.Image", i32, 5, 2, 
0, 0, 2, 0) }
 
 RWBuffer BufI16;
 RWBuffer BufU16;
@@ -44,6 +44,7 @@ RWBuffer< vector > BufI16x4;
 RWBuffer< vector > BufU32x3;
 RWBuffer BufF16x2;
 RWBuffer BufF32x3;
+RWBuffer BufI32x4;
 // TODO: RWBuffer BufSNormF16; -> 11
 // TODO: RWBuffer BufUNormF16; -> 12
 // TODO: RWBuffer BufSNormF32; -> 13



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


[clang] [Clang] Introduce FunctionParmPackDecl for expanded lambda captures (PR #107995)

2025-03-14 Thread via cfe-commits

cor3ntin wrote:

@zyn0217 are you still working on that?

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


[clang] [C++20][Modules] Prevent premature call to PassInterestingDeclsToConsumer() within FinishedDeserializing(). (PR #129982)

2025-03-14 Thread Michael Park via cfe-commits

https://github.com/mpark updated 
https://github.com/llvm/llvm-project/pull/129982

>From ebf6cd9c13ae6dbd9bfcece78491bdf01f0f170f Mon Sep 17 00:00:00 2001
From: Michael Park 
Date: Wed, 5 Mar 2025 18:46:10 -0800
Subject: [PATCH 1/3] [clang][modules] Add a unit test for the assertion
 failure in bootstrap build on OS X with XCode.

---
 clang/test/Modules/pr129982.cpp | 107 
 1 file changed, 107 insertions(+)
 create mode 100644 clang/test/Modules/pr129982.cpp

diff --git a/clang/test/Modules/pr129982.cpp b/clang/test/Modules/pr129982.cpp
new file mode 100644
index 0..b19cccfd07687
--- /dev/null
+++ b/clang/test/Modules/pr129982.cpp
@@ -0,0 +1,107 @@
+// If this test fails, it should be investigated under Debug builds.
+// Before the PR, this test was violating an assertion.
+
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+
+// RUN: %clang_cc1 -std=c++20 -emit-obj -fmodules \
+// RUN:  -fmodule-map-file=%t/module.modulemap \
+// RUN:  -fmodules-cache-path=%t %t/a.cpp
+
+//--- module.modulemap
+module ebo {
+  header "ebo.h"
+}
+
+module fwd {
+  header "fwd.h"
+}
+
+module s {
+  header "s.h"
+  export *
+}
+
+module mod {
+  header "a.h"
+  header "b.h"
+}
+
+//--- ebo.h
+#pragma once
+
+namespace N { inline namespace __1 {
+
+template 
+struct EBO : T {
+  EBO() = default;
+};
+
+}}
+
+//--- fwd.h
+#pragma once
+
+namespace N { inline namespace __1 {
+
+template 
+struct Empty;
+
+template 
+struct BS;
+
+using S = BS>;
+
+}}
+
+//--- s.h
+#pragma once
+
+#include "fwd.h"
+#include "ebo.h"
+
+namespace N { inline namespace __1 {
+
+template 
+struct Empty {};
+
+template 
+struct BS {
+EBO _;
+void f();
+};
+
+extern template void BS>::f();
+
+}}
+
+//--- b.h
+#pragma once
+
+#include "s.h"
+
+struct B {
+  void f() {
+N::S{}.f();
+  }
+};
+
+//--- a.h
+#pragma once
+
+#include "s.h"
+
+struct A {
+  void f(int) {}
+  void f(const N::S &) {}
+
+  void g();
+};
+
+//--- a.cpp
+#include "a.h"
+
+void A::g() { f(0); }
+
+// expected-no-diagnostics

>From 7bb10f498c55b8c1ec9e10bd5efad7a7ab90437f Mon Sep 17 00:00:00 2001
From: Michael Park 
Date: Fri, 7 Mar 2025 01:09:38 -0800
Subject: [PATCH 2/3] =?UTF-8?q?Reapply=20"[C++20][Modules][Serialization]?=
 =?UTF-8?q?=20Delay=20marking=20pending=20incompl=E2=80=A6=20(#127136)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This reverts commit 912b154f3a3f8c3cebf5cc5731fd8b0749762da5.
---
 clang/lib/Serialization/ASTReader.cpp | 25 ---
 clang/test/Modules/pr121245.cpp   | 93 +++
 2 files changed, 105 insertions(+), 13 deletions(-)
 create mode 100644 clang/test/Modules/pr121245.cpp

diff --git a/clang/lib/Serialization/ASTReader.cpp 
b/clang/lib/Serialization/ASTReader.cpp
index 8e9978829c512..41b6c2a4d64ab 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -10182,12 +10182,12 @@ void ASTReader::visitTopLevelModuleMaps(
 }
 
 void ASTReader::finishPendingActions() {
-  while (
-  !PendingIdentifierInfos.empty() || !PendingDeducedFunctionTypes.empty() 
||
-  !PendingDeducedVarTypes.empty() || !PendingIncompleteDeclChains.empty() 
||
-  !PendingDeclChains.empty() || !PendingMacroIDs.empty() ||
-  !PendingDeclContextInfos.empty() || !PendingUpdateRecords.empty() ||
-  !PendingObjCExtensionIvarRedeclarations.empty()) {
+  while (!PendingIdentifierInfos.empty() ||
+ !PendingDeducedFunctionTypes.empty() ||
+ !PendingDeducedVarTypes.empty() || !PendingDeclChains.empty() ||
+ !PendingMacroIDs.empty() || !PendingDeclContextInfos.empty() ||
+ !PendingUpdateRecords.empty() ||
+ !PendingObjCExtensionIvarRedeclarations.empty()) {
 // If any identifiers with corresponding top-level declarations have
 // been loaded, load those declarations now.
 using TopLevelDeclsMap =
@@ -10235,13 +10235,6 @@ void ASTReader::finishPendingActions() {
 }
 PendingDeducedVarTypes.clear();
 
-// For each decl chain that we wanted to complete while deserializing, mark
-// it as "still needs to be completed".
-for (unsigned I = 0; I != PendingIncompleteDeclChains.size(); ++I) {
-  markIncompleteDeclChain(PendingIncompleteDeclChains[I]);
-}
-PendingIncompleteDeclChains.clear();
-
 // Load pending declaration chains.
 for (unsigned I = 0; I != PendingDeclChains.size(); ++I)
   loadPendingDeclChain(PendingDeclChains[I].first,
@@ -10479,6 +10472,12 @@ void ASTReader::finishPendingActions() {
   for (auto *ND : PendingMergedDefinitionsToDeduplicate)
 getContext().deduplicateMergedDefinitonsFor(ND);
   PendingMergedDefinitionsToDeduplicate.clear();
+
+  // For each decl chain that we wanted to complete while deserializing, mark
+  // it as "still needs to be completed".
+  for (Decl *D : PendingIncompleteDeclChains)
+markIncompleteDeclChain(D);
+  PendingIncompleteDeclChains.clear();
 }

[clang] [C++20][Modules] Prevent premature call to PassInterestingDeclsToConsumer() within FinishedDeserializing(). (PR #129982)

2025-03-14 Thread Michael Park via cfe-commits

https://github.com/mpark updated 
https://github.com/llvm/llvm-project/pull/129982

>From ebf6cd9c13ae6dbd9bfcece78491bdf01f0f170f Mon Sep 17 00:00:00 2001
From: Michael Park 
Date: Wed, 5 Mar 2025 18:46:10 -0800
Subject: [PATCH 1/3] [clang][modules] Add a unit test for the assertion
 failure in bootstrap build on OS X with XCode.

---
 clang/test/Modules/pr129982.cpp | 107 
 1 file changed, 107 insertions(+)
 create mode 100644 clang/test/Modules/pr129982.cpp

diff --git a/clang/test/Modules/pr129982.cpp b/clang/test/Modules/pr129982.cpp
new file mode 100644
index 0..b19cccfd07687
--- /dev/null
+++ b/clang/test/Modules/pr129982.cpp
@@ -0,0 +1,107 @@
+// If this test fails, it should be investigated under Debug builds.
+// Before the PR, this test was violating an assertion.
+
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+
+// RUN: %clang_cc1 -std=c++20 -emit-obj -fmodules \
+// RUN:  -fmodule-map-file=%t/module.modulemap \
+// RUN:  -fmodules-cache-path=%t %t/a.cpp
+
+//--- module.modulemap
+module ebo {
+  header "ebo.h"
+}
+
+module fwd {
+  header "fwd.h"
+}
+
+module s {
+  header "s.h"
+  export *
+}
+
+module mod {
+  header "a.h"
+  header "b.h"
+}
+
+//--- ebo.h
+#pragma once
+
+namespace N { inline namespace __1 {
+
+template 
+struct EBO : T {
+  EBO() = default;
+};
+
+}}
+
+//--- fwd.h
+#pragma once
+
+namespace N { inline namespace __1 {
+
+template 
+struct Empty;
+
+template 
+struct BS;
+
+using S = BS>;
+
+}}
+
+//--- s.h
+#pragma once
+
+#include "fwd.h"
+#include "ebo.h"
+
+namespace N { inline namespace __1 {
+
+template 
+struct Empty {};
+
+template 
+struct BS {
+EBO _;
+void f();
+};
+
+extern template void BS>::f();
+
+}}
+
+//--- b.h
+#pragma once
+
+#include "s.h"
+
+struct B {
+  void f() {
+N::S{}.f();
+  }
+};
+
+//--- a.h
+#pragma once
+
+#include "s.h"
+
+struct A {
+  void f(int) {}
+  void f(const N::S &) {}
+
+  void g();
+};
+
+//--- a.cpp
+#include "a.h"
+
+void A::g() { f(0); }
+
+// expected-no-diagnostics

>From 7bb10f498c55b8c1ec9e10bd5efad7a7ab90437f Mon Sep 17 00:00:00 2001
From: Michael Park 
Date: Fri, 7 Mar 2025 01:09:38 -0800
Subject: [PATCH 2/3] =?UTF-8?q?Reapply=20"[C++20][Modules][Serialization]?=
 =?UTF-8?q?=20Delay=20marking=20pending=20incompl=E2=80=A6=20(#127136)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This reverts commit 912b154f3a3f8c3cebf5cc5731fd8b0749762da5.
---
 clang/lib/Serialization/ASTReader.cpp | 25 ---
 clang/test/Modules/pr121245.cpp   | 93 +++
 2 files changed, 105 insertions(+), 13 deletions(-)
 create mode 100644 clang/test/Modules/pr121245.cpp

diff --git a/clang/lib/Serialization/ASTReader.cpp 
b/clang/lib/Serialization/ASTReader.cpp
index 8e9978829c512..41b6c2a4d64ab 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -10182,12 +10182,12 @@ void ASTReader::visitTopLevelModuleMaps(
 }
 
 void ASTReader::finishPendingActions() {
-  while (
-  !PendingIdentifierInfos.empty() || !PendingDeducedFunctionTypes.empty() 
||
-  !PendingDeducedVarTypes.empty() || !PendingIncompleteDeclChains.empty() 
||
-  !PendingDeclChains.empty() || !PendingMacroIDs.empty() ||
-  !PendingDeclContextInfos.empty() || !PendingUpdateRecords.empty() ||
-  !PendingObjCExtensionIvarRedeclarations.empty()) {
+  while (!PendingIdentifierInfos.empty() ||
+ !PendingDeducedFunctionTypes.empty() ||
+ !PendingDeducedVarTypes.empty() || !PendingDeclChains.empty() ||
+ !PendingMacroIDs.empty() || !PendingDeclContextInfos.empty() ||
+ !PendingUpdateRecords.empty() ||
+ !PendingObjCExtensionIvarRedeclarations.empty()) {
 // If any identifiers with corresponding top-level declarations have
 // been loaded, load those declarations now.
 using TopLevelDeclsMap =
@@ -10235,13 +10235,6 @@ void ASTReader::finishPendingActions() {
 }
 PendingDeducedVarTypes.clear();
 
-// For each decl chain that we wanted to complete while deserializing, mark
-// it as "still needs to be completed".
-for (unsigned I = 0; I != PendingIncompleteDeclChains.size(); ++I) {
-  markIncompleteDeclChain(PendingIncompleteDeclChains[I]);
-}
-PendingIncompleteDeclChains.clear();
-
 // Load pending declaration chains.
 for (unsigned I = 0; I != PendingDeclChains.size(); ++I)
   loadPendingDeclChain(PendingDeclChains[I].first,
@@ -10479,6 +10472,12 @@ void ASTReader::finishPendingActions() {
   for (auto *ND : PendingMergedDefinitionsToDeduplicate)
 getContext().deduplicateMergedDefinitonsFor(ND);
   PendingMergedDefinitionsToDeduplicate.clear();
+
+  // For each decl chain that we wanted to complete while deserializing, mark
+  // it as "still needs to be completed".
+  for (Decl *D : PendingIncompleteDeclChains)
+markIncompleteDeclChain(D);
+  PendingIncompleteDeclChains.clear();
 }

[clang] [CIR] Don't generate ClangIR after an unrecoverable error occured (PR #130971)

2025-03-14 Thread Erich Keane via cfe-commits

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


[clang] Warn about virtual methods in `final` classes (PR #131188)

2025-03-14 Thread Hans Wennborg via cfe-commits


@@ -0,0 +1,29 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -Wunnecessary-virtual-specifier %s
+
+struct Foo final {
+  Foo() = default;
+  virtual ~Foo() = default;  // expected-warning {{virtual 
method}}
+  virtual Foo& operator=(Foo& other) = default;  // expected-warning {{virtual 
method}}
+  virtual Foo& operator=(Foo&& other) = default; // expected-warning {{virtual 
method}}
+  void f();
+  virtual void f(int);   // expected-warning {{virtual 
method}}
+  int g(int x) { return x; };
+  virtual int g(bool);   // expected-warning {{virtual 
method}}
+  static int s();
+};
+
+struct BarBase {
+  virtual ~BarBase() = delete;
+  virtual void virt() {}
+  virtual int virt(int);
+  int nonvirt();
+};
+
+struct Bar final : BarBase {
+  ~Bar() override = delete;
+  void virt() override {};
+  // `virtual ... override;` is a common pattern, so don't warn
+  virtual int virt(int) override;
+  virtual int virt(bool);// expected-warning {{virtual 
method}}
+  int nonvirt();
+};

zmodem wrote:

I'd also like to see the case of a function which does override something, but 
isn't marked with override. For example:

```
struct Base {
  virtual void foo();
};
struct Derived final : public Base {
  virtual void foo();
};
```

Should we warn here?

The `virtual` is unnecessary because it's already "inherited". But at least 
pre-c++11 writing out the `virtual` was common to signal to the reader that it 
was in fact a virtual function. On the other hand, pre-c++11 code wouldn't be 
able to use `final`.

We will already warn (`-Wsuggest-override`), maybe that's enough for that one?

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


[clang] 8f011e2 - [Sema] Avoid repeated hash lookups (NFC) (#131263)

2025-03-14 Thread via cfe-commits

Author: Kazu Hirata
Date: 2025-03-14T07:20:22-07:00
New Revision: 8f011e2c7f003f3e9823c057109d603ca698a4be

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

LOG: [Sema] Avoid repeated hash lookups (NFC) (#131263)

Added: 


Modified: 
clang/lib/Sema/SemaOpenMP.cpp

Removed: 




diff  --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index e2c1b2aa81ce5..890de834533a4 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -6836,22 +6836,21 @@ SemaOpenMP::DeclGroupPtrTy 
SemaOpenMP::ActOnOpenMPDeclareSimdDirective(
 ->getCanonicalDecl() == CanonPVD) {
   // OpenMP  [2.15.3.7, linear Clause, Restrictions]
   // A list-item cannot appear in more than one linear clause.
-  if (LinearArgs.count(CanonPVD) > 0) {
+  if (auto It = LinearArgs.find(CanonPVD); It != LinearArgs.end()) {
 Diag(E->getExprLoc(), diag::err_omp_wrong_dsa)
 << getOpenMPClauseName(OMPC_linear)
 << getOpenMPClauseName(OMPC_linear) << E->getSourceRange();
-Diag(LinearArgs[CanonPVD]->getExprLoc(),
- diag::note_omp_explicit_dsa)
+Diag(It->second->getExprLoc(), diag::note_omp_explicit_dsa)
 << getOpenMPClauseName(OMPC_linear);
 continue;
   }
   // Each argument can appear in at most one uniform or linear clause.
-  if (UniformedArgs.count(CanonPVD) > 0) {
+  if (auto It = UniformedArgs.find(CanonPVD);
+  It != UniformedArgs.end()) {
 Diag(E->getExprLoc(), diag::err_omp_wrong_dsa)
 << getOpenMPClauseName(OMPC_linear)
 << getOpenMPClauseName(OMPC_uniform) << E->getSourceRange();
-Diag(UniformedArgs[CanonPVD]->getExprLoc(),
- diag::note_omp_explicit_dsa)
+Diag(It->second->getExprLoc(), diag::note_omp_explicit_dsa)
 << getOpenMPClauseName(OMPC_uniform);
 continue;
   }



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


[clang] [flang] [llvm] [NFC][AMDGPU] Replace more direct arch comparison with isAMDGCN() (PR #131379)

2025-03-14 Thread Joseph Huber via cfe-commits

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

I wonder if we should just make all of these `isAMDGPU()` as well.

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


[clang] [clang][DependencyScanning] Track modules that resolve from sysroot. (PR #130634)

2025-03-14 Thread Michael Spencer via cfe-commits


@@ -843,7 +864,7 @@ void ModuleDepCollectorPP::addModuleDep(
 !MDC.isPrebuiltModule(Import)) {

Bigcheese wrote:

I think that's fine as long as the current patch says that pre built modules 
means it's not in sysroot, as I think that's a small addition and keeps it 
conservatively correct.

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


[clang] [CIR] Upstream initial support for unary op (PR #131369)

2025-03-14 Thread Andy Kaylor via cfe-commits


@@ -568,6 +568,128 @@ mlir::LogicalResult 
CIRToLLVMGlobalOpLowering::matchAndRewrite(
   return mlir::success();
 }
 
+mlir::LogicalResult CIRToLLVMUnaryOpLowering::matchAndRewrite(
+cir::UnaryOp op, OpAdaptor adaptor,
+mlir::ConversionPatternRewriter &rewriter) const {
+  assert(op.getType() == op.getInput().getType() &&
+ "Unary operation's operand type and result type are different");
+  mlir::Type type = op.getType();
+  mlir::Type elementType = type;
+  bool isVector = false;
+  assert(!cir::MissingFeatures::vectorType());
+  mlir::Type llvmType = getTypeConverter()->convertType(type);
+  mlir::Location loc = op.getLoc();
+
+  auto createIntConstant = [&](int64_t value) -> mlir::Value {

andykaylor wrote:

On second thought, after looking more at the incubator code, I'm not so sure 
this is worth having a wrapper. There are a lot of small variations that look 
the same but aren't. Even in this function in the incubator my change to use 
these lambdas isn't quite right for all cases. I'm going to put this back 
closer to the way it was in the incubator. It's very slightly longer, but 
probably less error prone.

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


[clang] [C++20][Modules] Prevent premature call to PassInterestingDeclsToConsumer() within FinishedDeserializing(). (PR #129982)

2025-03-14 Thread Michael Park via cfe-commits

https://github.com/mpark updated 
https://github.com/llvm/llvm-project/pull/129982

>From ebf6cd9c13ae6dbd9bfcece78491bdf01f0f170f Mon Sep 17 00:00:00 2001
From: Michael Park 
Date: Wed, 5 Mar 2025 18:46:10 -0800
Subject: [PATCH 1/3] [clang][modules] Add a unit test for the assertion
 failure in bootstrap build on OS X with XCode.

---
 clang/test/Modules/pr129982.cpp | 107 
 1 file changed, 107 insertions(+)
 create mode 100644 clang/test/Modules/pr129982.cpp

diff --git a/clang/test/Modules/pr129982.cpp b/clang/test/Modules/pr129982.cpp
new file mode 100644
index 0..b19cccfd07687
--- /dev/null
+++ b/clang/test/Modules/pr129982.cpp
@@ -0,0 +1,107 @@
+// If this test fails, it should be investigated under Debug builds.
+// Before the PR, this test was violating an assertion.
+
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+
+// RUN: %clang_cc1 -std=c++20 -emit-obj -fmodules \
+// RUN:  -fmodule-map-file=%t/module.modulemap \
+// RUN:  -fmodules-cache-path=%t %t/a.cpp
+
+//--- module.modulemap
+module ebo {
+  header "ebo.h"
+}
+
+module fwd {
+  header "fwd.h"
+}
+
+module s {
+  header "s.h"
+  export *
+}
+
+module mod {
+  header "a.h"
+  header "b.h"
+}
+
+//--- ebo.h
+#pragma once
+
+namespace N { inline namespace __1 {
+
+template 
+struct EBO : T {
+  EBO() = default;
+};
+
+}}
+
+//--- fwd.h
+#pragma once
+
+namespace N { inline namespace __1 {
+
+template 
+struct Empty;
+
+template 
+struct BS;
+
+using S = BS>;
+
+}}
+
+//--- s.h
+#pragma once
+
+#include "fwd.h"
+#include "ebo.h"
+
+namespace N { inline namespace __1 {
+
+template 
+struct Empty {};
+
+template 
+struct BS {
+EBO _;
+void f();
+};
+
+extern template void BS>::f();
+
+}}
+
+//--- b.h
+#pragma once
+
+#include "s.h"
+
+struct B {
+  void f() {
+N::S{}.f();
+  }
+};
+
+//--- a.h
+#pragma once
+
+#include "s.h"
+
+struct A {
+  void f(int) {}
+  void f(const N::S &) {}
+
+  void g();
+};
+
+//--- a.cpp
+#include "a.h"
+
+void A::g() { f(0); }
+
+// expected-no-diagnostics

>From 7bb10f498c55b8c1ec9e10bd5efad7a7ab90437f Mon Sep 17 00:00:00 2001
From: Michael Park 
Date: Fri, 7 Mar 2025 01:09:38 -0800
Subject: [PATCH 2/3] =?UTF-8?q?Reapply=20"[C++20][Modules][Serialization]?=
 =?UTF-8?q?=20Delay=20marking=20pending=20incompl=E2=80=A6=20(#127136)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This reverts commit 912b154f3a3f8c3cebf5cc5731fd8b0749762da5.
---
 clang/lib/Serialization/ASTReader.cpp | 25 ---
 clang/test/Modules/pr121245.cpp   | 93 +++
 2 files changed, 105 insertions(+), 13 deletions(-)
 create mode 100644 clang/test/Modules/pr121245.cpp

diff --git a/clang/lib/Serialization/ASTReader.cpp 
b/clang/lib/Serialization/ASTReader.cpp
index 8e9978829c512..41b6c2a4d64ab 100644
--- a/clang/lib/Serialization/ASTReader.cpp
+++ b/clang/lib/Serialization/ASTReader.cpp
@@ -10182,12 +10182,12 @@ void ASTReader::visitTopLevelModuleMaps(
 }
 
 void ASTReader::finishPendingActions() {
-  while (
-  !PendingIdentifierInfos.empty() || !PendingDeducedFunctionTypes.empty() 
||
-  !PendingDeducedVarTypes.empty() || !PendingIncompleteDeclChains.empty() 
||
-  !PendingDeclChains.empty() || !PendingMacroIDs.empty() ||
-  !PendingDeclContextInfos.empty() || !PendingUpdateRecords.empty() ||
-  !PendingObjCExtensionIvarRedeclarations.empty()) {
+  while (!PendingIdentifierInfos.empty() ||
+ !PendingDeducedFunctionTypes.empty() ||
+ !PendingDeducedVarTypes.empty() || !PendingDeclChains.empty() ||
+ !PendingMacroIDs.empty() || !PendingDeclContextInfos.empty() ||
+ !PendingUpdateRecords.empty() ||
+ !PendingObjCExtensionIvarRedeclarations.empty()) {
 // If any identifiers with corresponding top-level declarations have
 // been loaded, load those declarations now.
 using TopLevelDeclsMap =
@@ -10235,13 +10235,6 @@ void ASTReader::finishPendingActions() {
 }
 PendingDeducedVarTypes.clear();
 
-// For each decl chain that we wanted to complete while deserializing, mark
-// it as "still needs to be completed".
-for (unsigned I = 0; I != PendingIncompleteDeclChains.size(); ++I) {
-  markIncompleteDeclChain(PendingIncompleteDeclChains[I]);
-}
-PendingIncompleteDeclChains.clear();
-
 // Load pending declaration chains.
 for (unsigned I = 0; I != PendingDeclChains.size(); ++I)
   loadPendingDeclChain(PendingDeclChains[I].first,
@@ -10479,6 +10472,12 @@ void ASTReader::finishPendingActions() {
   for (auto *ND : PendingMergedDefinitionsToDeduplicate)
 getContext().deduplicateMergedDefinitonsFor(ND);
   PendingMergedDefinitionsToDeduplicate.clear();
+
+  // For each decl chain that we wanted to complete while deserializing, mark
+  // it as "still needs to be completed".
+  for (Decl *D : PendingIncompleteDeclChains)
+markIncompleteDeclChain(D);
+  PendingIncompleteDeclChains.clear();
 }

[clang] [C++20][Modules] Prevent premature call to PassInterestingDeclsToConsumer() within FinishedDeserializing(). (PR #129982)

2025-03-14 Thread Michael Park via cfe-commits

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


[clang-tools-extra] [clang-tidy] Add IgnoreMacros to readability-function-size (PR #131406)

2025-03-14 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL created 
https://github.com/llvm/llvm-project/pull/131406

Extend readability-function-size check by adding
IgnoreMacros option.

Fixes #112835

>From 95b3e21c8712d9489cdff8bc2ce78b447d894837 Mon Sep 17 00:00:00 2001
From: Piotr Zegar 
Date: Tue, 7 Jan 2025 16:21:12 +
Subject: [PATCH] [clang-tidy] Add IgnoreMacros to readability-function-size

Extend readability-function-size check by adding
IgnoreMacros option.

Fixes: #112835
---
 .../clang-tidy/readability/FunctionSizeCheck.cpp  | 15 +--
 .../clang-tidy/readability/FunctionSizeCheck.h|  2 ++
 clang-tools-extra/docs/ReleaseNotes.rst   |  4 
 .../checks/readability/function-size.rst  |  7 +++
 .../checkers/readability/function-size.cpp| 15 ++-
 5 files changed, 40 insertions(+), 3 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/readability/FunctionSizeCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/FunctionSizeCheck.cpp
index 3313bcb39b7f3..9535211413be6 100644
--- a/clang-tools-extra/clang-tidy/readability/FunctionSizeCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/FunctionSizeCheck.cpp
@@ -20,6 +20,8 @@ class FunctionASTVisitor : public 
RecursiveASTVisitor {
   using Base = RecursiveASTVisitor;
 
 public:
+  FunctionASTVisitor(bool IgnoreMacros) : IgnoreMacros(IgnoreMacros) {}
+
   bool VisitVarDecl(VarDecl *VD) {
 // Do not count function params.
 // Do not count decomposition declarations (C++17's structured bindings).
@@ -39,6 +41,9 @@ class FunctionASTVisitor : public 
RecursiveASTVisitor {
 if (!Node)
   return Base::TraverseStmt(Node);
 
+if (IgnoreMacros && Node->getBeginLoc().isMacroID())
+  return true;
+
 if (TrackedParent.back() && !isa(Node))
   ++Info.Statements;
 
@@ -120,6 +125,9 @@ class FunctionASTVisitor : public 
RecursiveASTVisitor {
   llvm::BitVector TrackedParent;
   unsigned StructNesting = 0;
   unsigned CurrentNestingLevel = 0;
+
+private:
+  const bool IgnoreMacros;
 };
 
 } // namespace
@@ -135,7 +143,9 @@ FunctionSizeCheck::FunctionSizeCheck(StringRef Name, 
ClangTidyContext *Context)
   NestingThreshold(
   Options.get("NestingThreshold", DefaultNestingThreshold)),
   VariableThreshold(
-  Options.get("VariableThreshold", DefaultVariableThreshold)) {}
+  Options.get("VariableThreshold", DefaultVariableThreshold)),
+  IgnoreMacros(
+  Options.getLocalOrGlobal("IgnoreMacros", DefaultIgnoreMacros)) {}
 
 void FunctionSizeCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
   Options.store(Opts, "LineThreshold", LineThreshold);
@@ -144,6 +154,7 @@ void 
FunctionSizeCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
   Options.store(Opts, "ParameterThreshold", ParameterThreshold);
   Options.store(Opts, "NestingThreshold", NestingThreshold);
   Options.store(Opts, "VariableThreshold", VariableThreshold);
+  Options.store(Opts, "IgnoreMacros", IgnoreMacros);
 }
 
 void FunctionSizeCheck::registerMatchers(MatchFinder *Finder) {
@@ -158,7 +169,7 @@ void FunctionSizeCheck::registerMatchers(MatchFinder 
*Finder) {
 void FunctionSizeCheck::check(const MatchFinder::MatchResult &Result) {
   const auto *Func = Result.Nodes.getNodeAs("func");
 
-  FunctionASTVisitor Visitor;
+  FunctionASTVisitor Visitor(IgnoreMacros);
   Visitor.Info.NestingThreshold = NestingThreshold.value_or(-1);
   Visitor.TraverseDecl(const_cast(Func));
   auto &FI = Visitor.Info;
diff --git a/clang-tools-extra/clang-tidy/readability/FunctionSizeCheck.h 
b/clang-tools-extra/clang-tidy/readability/FunctionSizeCheck.h
index 106c69ff07393..b36de68f9583c 100644
--- a/clang-tools-extra/clang-tidy/readability/FunctionSizeCheck.h
+++ b/clang-tools-extra/clang-tidy/readability/FunctionSizeCheck.h
@@ -47,6 +47,7 @@ class FunctionSizeCheck : public ClangTidyCheck {
   const std::optional ParameterThreshold;
   const std::optional NestingThreshold;
   const std::optional VariableThreshold;
+  const bool IgnoreMacros;
 
   static constexpr std::optional DefaultLineThreshold = std::nullopt;
   static constexpr std::optional DefaultStatementThreshold = 800U;
@@ -58,6 +59,7 @@ class FunctionSizeCheck : public ClangTidyCheck {
   std::nullopt;
   static constexpr std::optional DefaultVariableThreshold =
   std::nullopt;
+  static constexpr bool DefaultIgnoreMacros = false;
 };
 
 } // namespace clang::tidy::readability
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 0ad52f83fad85..6ae117ca57ed4 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -178,6 +178,10 @@ Changes in existing checks
   tolerating fix-it breaking compilation when functions is used as pointers
   to avoid matching usage of functions within the current compilation unit.
 
+- Improved :doc:`readability-function-size
+  ` check by adding the option
+  `IgnoreMacros` to allow ignoring code inside macros

  1   2   3   4   >