[clang] [clang-format] add option to control bin-packing keyworded parameters (PR #131605)

2025-03-27 Thread Björn Schäpers via cfe-commits

HazardyKnusperkeks wrote:

Please recheck all your added comments, if the wording is still the best one, 
after renaming the option.

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


[clang] [AMDGPU][True16][Driver] support true16 target feature in clang driver (PR #133298)

2025-03-27 Thread Brox Chen via cfe-commits

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


[clang] [AMDGPU][True16][Clang] support true16 target feature in clang driver (PR #133298)

2025-03-27 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang-driver

@llvm/pr-subscribers-backend-amdgpu

Author: Brox Chen (broxigarchen)


Changes

Add a true16 clang option to turn on true16 mode(by default off) in GFX11Plus 
amdgpu. 

This allows to turn on true16 and enable testing for this feature. This patch 
be removed after we validated true16 feature and set it to be the default mode.

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


3 Files Affected:

- (modified) clang/include/clang/Driver/Options.td (+3) 
- (modified) clang/lib/Driver/ToolChains/AMDGPU.cpp (+4) 
- (modified) clang/test/Driver/amdgpu-features.c (+5) 


``diff
diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index a7fcb160d3867..68179d7835440 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5182,6 +5182,9 @@ defm wavefrontsize64 : SimpleMFlag<"wavefrontsize64",
 defm amdgpu_precise_memory_op
 : SimpleMFlag<"amdgpu-precise-memory-op", "Enable", "Disable",
   " precise memory mode (AMDGPU only)">;
+defm real_true16: SimpleMFlag<"real-true16",
+  "enable real-true16 in GFX11Plus", "enable real-true16 mode",
+  " real-true16 mode (AMDGPU only)">;
 
 def munsafe_fp_atomics : Flag<["-"], "munsafe-fp-atomics">,
   Visibility<[ClangOption, CC1Option]>, Alias;
diff --git a/clang/lib/Driver/ToolChains/AMDGPU.cpp 
b/clang/lib/Driver/ToolChains/AMDGPU.cpp
index 1c5bb08568801..ce0cba5aa536a 100644
--- a/clang/lib/Driver/ToolChains/AMDGPU.cpp
+++ b/clang/lib/Driver/ToolChains/AMDGPU.cpp
@@ -707,6 +707,10 @@ void amdgpu::getAMDGPUTargetFeatures(const Driver &D,
options::OPT_mno_amdgpu_precise_memory_op, false))
 Features.push_back("+precise-memory");
 
+  if (Args.hasFlag(options::OPT_mreal_true16, options::OPT_mno_real_true16,
+   false))
+Features.push_back("+real-true16");
+
   handleTargetFeaturesGroup(D, Triple, Args, Features,
 options::OPT_m_amdgpu_Features_Group);
 }
diff --git a/clang/test/Driver/amdgpu-features.c 
b/clang/test/Driver/amdgpu-features.c
index 864744db203e9..f46f0251cadfc 100644
--- a/clang/test/Driver/amdgpu-features.c
+++ b/clang/test/Driver/amdgpu-features.c
@@ -38,3 +38,8 @@
 
 // RUN: %clang -### -target amdgcn -mcpu=gfx1010 -mno-amdgpu-precise-memory-op 
%s 2>&1 | FileCheck --check-prefix=NO-PREC-MEM %s
 // NO-PREC-MEM-NOT: {{".*precise-memory"}}
+
+// RUN: %clang -### -target amdgcn -mcpu=gfx1100 -mreal-true16 %s 2>&1 | 
FileCheck --check-prefix=REAL16 %s
+// RUN: %clang -### -target amdgcn -mcpu=gfx1100 -mno-real-true16 %s 2>&1 | 
FileCheck --check-prefix=NO-REAL16 %s
+// REAL16: "-target-feature" "+real-true16"
+// NO-REAL16-NOT: {{".*real-true16"}}

``




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


[clang] [AMDGPU][True16][Clang] support true16 target feature in clang driver (PR #133298)

2025-03-27 Thread Brox Chen via cfe-commits

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


[clang] [AMDGPU][True16][Clang] support true16 target feature in clang driver (PR #133298)

2025-03-27 Thread Brox Chen via cfe-commits

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


[clang] [AMDGPU][True16][Clang] support true16 target feature in clang driver (PR #133298)

2025-03-27 Thread Brox Chen via cfe-commits

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


[clang] [AMDGPU][True16][Clang] support true16 target feature in clang driver (PR #133298)

2025-03-27 Thread Brox Chen via cfe-commits

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


[clang] Fix complex long double division with -mno-x87. (PR #133152)

2025-03-27 Thread Joshua Cranmer via cfe-commits


@@ -0,0 +1,49 @@
+// RUN %clang_cc1 %s -O0 -emit-llvm -triple x86_64-unknown-unknown \
+// RUN -verify -complex-range=promoted -o - | FileCheck %s
+
+// RUN %clang_cc1 %s -O0 -emit-llvm -triple x86_64-unknown-unknown \
+// RUN -verify=nopromotion -complex-range=promoted -target-feature -x87 -o - | 
FileCheck %s --check-prefix=X87

jcranmer-intel wrote:

I'd rename the check prefix label here to "NOX87" to make it a little more 
clear what's actually being tested.

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


[clang] [clang-format] add option to control bin-packing keyworded parameters (PR #131605)

2025-03-27 Thread Björn Schäpers via cfe-commits


@@ -3146,6 +3146,45 @@ struct FormatStyle {
   /// \version 16
   IntegerLiteralSeparatorStyle IntegerLiteralSeparator;
 
+  /// Function-like declaration with keyworded parameters.
+  /// Lists possible keywords for a named macro-like function
+  struct KeywordedFunctionLikeMacro {
+std::string Name;
+std::vector Keywords;
+
+bool operator==(const KeywordedFunctionLikeMacro &Other) const {
+  return Name == Other.Name && Keywords == Other.Keywords;
+}
+  };
+
+  /// Allows to format function-like macros with keyworded parameters according
+  /// to the BinPackParameters setting, treating keywords as parameter
+  /// sepratators.
+  ///
+  /// Q_PROPERTY is an example of such a macro:
+  /// \code
+  ///   Q_PROPERTY(int name READ name WRITE setName NOTIFY nameChanged)
+  /// \endcode
+  ///
+  /// With ``BinPackParameters``  set to ``OnePerLine`` (or
+  /// ``AlwaysOnePerLine``) and
+  /// \code{.yaml}
+  ///   FunctionDeclarationsWithKeywords:
+  ///   - Name: "Q_PROPERTY"
+  /// Keywords: ['READ', 'WRITE', 'MEMBER', 'RESET', 'NOTIFY']
+  /// \endcode
+  ///
+  /// the line above will be split on these keywords:
+  /// \code
+  ///   Q_PROPERTY(
+  ///   int name
+  ///   READ name
+  ///   WRITE setName
+  ///   NOTIFY nameChanged)
+  /// \endcode
+  /// \version 21
+  std::vector KeywordedFunctionLikeMacros;

HazardyKnusperkeks wrote:

K comes after J, please resort here and following.

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


[clang] [clang-format] add option to control bin-packing keyworded parameters (PR #131605)

2025-03-27 Thread Björn Schäpers via cfe-commits


@@ -29102,6 +29102,65 @@ TEST_F(FormatTest, BreakBeforeClassName) {
"ArenaSafeUniquePtr {};");
 }
 
+TEST_F(FormatTest, FunctionDeclarationWithKeywords) {

HazardyKnusperkeks wrote:

The test name should be changed, I'd refer directly to the option.

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


[clang] [clang-format] add option to control bin-packing keyworded parameters (PR #131605)

2025-03-27 Thread Björn Schäpers via cfe-commits


@@ -3146,6 +3146,45 @@ struct FormatStyle {
   /// \version 16
   IntegerLiteralSeparatorStyle IntegerLiteralSeparator;
 
+  /// Function-like declaration with keyworded parameters.
+  /// Lists possible keywords for a named macro-like function

HazardyKnusperkeks wrote:

```suggestion
  /// Lists possible keywords for a named macro-like function.
```

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


[clang] [llvm] Enable unnecessary-virtual-specifier by default (PR #133265)

2025-03-27 Thread via cfe-commits

Sirraide wrote:

> Ah, missed that, sorry. It seems there hasn't been a release since the 
> warning was added, and the existing release note seems to still apply:

Ah, I thought it was an older warning. In that case we don’t need a release note

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


[clang] Update OpenMPSupport.rst (PR #133138)

2025-03-27 Thread via cfe-commits

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


[clang-tools-extra] [llvm] [clang-doc] Adds a mustache backend (PR #133161)

2025-03-27 Thread Paul Kirth via cfe-commits


@@ -0,0 +1,75 @@
+//===-- FileHelpersClangDoc.cpp - File Helpers ---*- 
C++-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+#include "FileHelpersClangDoc.h"
+#include "llvm/Support/FileSystem.h"
+#include "llvm/Support/Path.h"
+
+namespace clang {
+namespace doc {
+
+llvm::Error
+copyFile(llvm::StringRef FilePath, llvm::StringRef OutDirectory) {
+  llvm::SmallString<128> PathWrite;
+  llvm::sys::path::native(OutDirectory, PathWrite);
+  llvm::sys::path::append(PathWrite, llvm::sys::path::filename(FilePath));
+  llvm::SmallString<128> PathRead;
+  llvm::sys::path::native(FilePath, PathRead);
+  std::error_code OK;
+  std::error_code FileErr = llvm::sys::fs::copy_file(PathRead, PathWrite);
+  if (FileErr != OK) {
+return llvm::createStringError(llvm::inconvertibleErrorCode(),
+   "error creating file " +
+   llvm::sys::path::filename(FilePath) +
+   ": " + FileErr.message() + "\n");
+  }
+  return llvm::Error::success();
+}
+
+
+llvm::SmallString<128> computeRelativePath(llvm::StringRef Destination,
+  llvm::StringRef Origin) {

ilovepi wrote:

Maybe we should drop this in favor of `std::filesystem::relative()`?

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


[clang] Add more tests for _Countof (PR #133333)

2025-03-27 Thread Alejandro Colomar via cfe-commits

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


[clang] [AMDGPU][True16][Driver] support true16 feature option in clang driver (PR #133298)

2025-03-27 Thread Brox Chen via cfe-commits

https://github.com/broxigarchen updated 
https://github.com/llvm/llvm-project/pull/133298

>From bd6300963b53ad8c5a4037e89e041fe1adfd3fe6 Mon Sep 17 00:00:00 2001
From: guochen2 
Date: Thu, 27 Mar 2025 14:41:40 -0400
Subject: [PATCH] add true16 feature in clang driver

---
 clang/include/clang/Driver/Options.td  | 3 +++
 clang/lib/Driver/ToolChains/AMDGPU.cpp | 4 
 clang/test/Driver/amdgpu-features.c| 5 +
 3 files changed, 12 insertions(+)

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index a7fcb160d3867..68179d7835440 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -5182,6 +5182,9 @@ defm wavefrontsize64 : SimpleMFlag<"wavefrontsize64",
 defm amdgpu_precise_memory_op
 : SimpleMFlag<"amdgpu-precise-memory-op", "Enable", "Disable",
   " precise memory mode (AMDGPU only)">;
+defm real_true16: SimpleMFlag<"real-true16",
+  "enable real-true16 in GFX11Plus", "enable real-true16 mode",
+  " real-true16 mode (AMDGPU only)">;
 
 def munsafe_fp_atomics : Flag<["-"], "munsafe-fp-atomics">,
   Visibility<[ClangOption, CC1Option]>, Alias;
diff --git a/clang/lib/Driver/ToolChains/AMDGPU.cpp 
b/clang/lib/Driver/ToolChains/AMDGPU.cpp
index 1c5bb08568801..ce0cba5aa536a 100644
--- a/clang/lib/Driver/ToolChains/AMDGPU.cpp
+++ b/clang/lib/Driver/ToolChains/AMDGPU.cpp
@@ -707,6 +707,10 @@ void amdgpu::getAMDGPUTargetFeatures(const Driver &D,
options::OPT_mno_amdgpu_precise_memory_op, false))
 Features.push_back("+precise-memory");
 
+  if (Args.hasFlag(options::OPT_mreal_true16, options::OPT_mno_real_true16,
+   false))
+Features.push_back("+real-true16");
+
   handleTargetFeaturesGroup(D, Triple, Args, Features,
 options::OPT_m_amdgpu_Features_Group);
 }
diff --git a/clang/test/Driver/amdgpu-features.c 
b/clang/test/Driver/amdgpu-features.c
index 864744db203e9..f46f0251cadfc 100644
--- a/clang/test/Driver/amdgpu-features.c
+++ b/clang/test/Driver/amdgpu-features.c
@@ -38,3 +38,8 @@
 
 // RUN: %clang -### -target amdgcn -mcpu=gfx1010 -mno-amdgpu-precise-memory-op 
%s 2>&1 | FileCheck --check-prefix=NO-PREC-MEM %s
 // NO-PREC-MEM-NOT: {{".*precise-memory"}}
+
+// RUN: %clang -### -target amdgcn -mcpu=gfx1100 -mreal-true16 %s 2>&1 | 
FileCheck --check-prefix=REAL16 %s
+// RUN: %clang -### -target amdgcn -mcpu=gfx1100 -mno-real-true16 %s 2>&1 | 
FileCheck --check-prefix=NO-REAL16 %s
+// REAL16: "-target-feature" "+real-true16"
+// NO-REAL16-NOT: {{".*real-true16"}}

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


[clang] [llvm] [RISCV] Remove experimental from Sdext and Sdtrig which are ratified. (PR #132529)

2025-03-27 Thread Craig Topper via cfe-commits

https://github.com/topperc updated 
https://github.com/llvm/llvm-project/pull/132529

>From 3b30343a99ecb7095adb734be2e3e71a67a597ac Mon Sep 17 00:00:00 2001
From: Craig Topper 
Date: Fri, 21 Mar 2025 23:35:56 -0700
Subject: [PATCH 1/2] [RISCV] Remove experimental from Sdext and Sdtrig which
 are ratified.

They were ratified in February 2025.
---
 llvm/lib/Target/RISCV/RISCVFeatures.td   | 4 ++--
 llvm/test/CodeGen/RISCV/attributes.ll| 4 ++--
 llvm/test/CodeGen/RISCV/features-info.ll | 4 ++--
 llvm/unittests/TargetParser/RISCVISAInfoTest.cpp | 4 ++--
 4 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/llvm/lib/Target/RISCV/RISCVFeatures.td 
b/llvm/lib/Target/RISCV/RISCVFeatures.td
index c1223beb304ad..d7edf94565ff4 100644
--- a/llvm/lib/Target/RISCV/RISCVFeatures.td
+++ b/llvm/lib/Target/RISCV/RISCVFeatures.td
@@ -869,9 +869,9 @@ def HasStdExtH : Predicate<"Subtarget->hasStdExtH()">,
 
 // Supervisor extensions
 
-def FeatureStdExtSdext : RISCVExperimentalExtension<1, 0, "External debugger">;
+def FeatureStdExtSdext : RISCVExtension<1, 0, "External debugger">;
 
-def FeatureStdExtSdtrig : RISCVExperimentalExtension<1, 0, "Debugger 
triggers">;
+def FeatureStdExtSdtrig : RISCVExtension<1, 0, "Debugger triggers">;
 
 def FeatureStdExtShgatpa
 : RISCVExtension<1, 0,
diff --git a/llvm/test/CodeGen/RISCV/attributes.ll 
b/llvm/test/CodeGen/RISCV/attributes.ll
index cc2ce1a572d9a..ea8f35957c046 100644
--- a/llvm/test/CodeGen/RISCV/attributes.ll
+++ b/llvm/test/CodeGen/RISCV/attributes.ll
@@ -311,8 +311,8 @@
 ; RUN: llc -mtriple=riscv64 -mattr=+supm %s -o - | FileCheck 
--check-prefix=RV64SUPM %s
 ; RUN: llc -mtriple=riscv64 -mattr=+experimental-smctr  %s -o - | FileCheck 
--check-prefix=RV64SMCTR %s
 ; RUN: llc -mtriple=riscv64 -mattr=+experimental-ssctr  %s -o - | FileCheck 
--check-prefix=RV64SSCTR %s
-; RUN: llc -mtriple=riscv64 -mattr=+experimental-sdext  %s -o - | FileCheck 
--check-prefix=RV64SDEXT %s
-; RUN: llc -mtriple=riscv64 -mattr=+experimental-sdtrig  %s -o - | FileCheck 
--check-prefix=RV64SDTRIG %s
+; RUN: llc -mtriple=riscv64 -mattr=+sdext  %s -o - | FileCheck 
--check-prefix=RV64SDEXT %s
+; RUN: llc -mtriple=riscv64 -mattr=+sdtrig  %s -o - | FileCheck 
--check-prefix=RV64SDTRIG %s
 ; RUN: llc -mtriple=riscv64 -mattr=+experimental-xqccmp %s -o - | FileCheck 
--check-prefix=RV64XQCCMP %s
 
 
diff --git a/llvm/test/CodeGen/RISCV/features-info.ll 
b/llvm/test/CodeGen/RISCV/features-info.ll
index ff29777a3ec37..60c29622b520a 100644
--- a/llvm/test/CodeGen/RISCV/features-info.ll
+++ b/llvm/test/CodeGen/RISCV/features-info.ll
@@ -15,8 +15,6 @@
 ; CHECK:   e- 'E' (Embedded Instruction Set 
with 16 GPRs).
 ; CHECK:   experimental - Experimental intrinsics.
 ; CHECK:   experimental-rvm23u32- RISC-V experimental-rvm23u32 
profile.
-; CHECK:   experimental-sdext   - 'Sdext' (External debugger).
-; CHECK:   experimental-sdtrig  - 'Sdtrig' (Debugger triggers).
 ; CHECK:   experimental-smctr   - 'Smctr' (Control Transfer 
Records Machine Level).
 ; CHECK:   experimental-ssctr   - 'Ssctr' (Control Transfer 
Records Supervisor Level).
 ; CHECK:   experimental-svukte  - 'Svukte' (Address-Independent 
Latency of User-Mode Faults to Supervisor Addresses).
@@ -96,6 +94,8 @@
 ; CHECK:   rvi20u32 - RISC-V rvi20u32 profile.
 ; CHECK:   rvi20u64 - RISC-V rvi20u64 profile.
 ; CHECK:   save-restore - Enable save/restore..
+; CHECK:   sdext- 'Sdext' (External debugger).
+; CHECK:   sdtrig   - 'Sdtrig' (Debugger triggers).
 ; CHECK:   sha  - 'Sha' (Augmented Hypervisor).
 ; CHECK:   shcounterenw - 'Shcounterenw' (Support 
writeable hcounteren enable bit for any hpmcounter that is not read-only zero).
 ; CHECK:   shgatpa  - 'Shgatpa' (SvNNx4 mode supported 
for all modes supported by satp, as well as Bare).
diff --git a/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp 
b/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp
index 16876ebcf9f83..f916f06827e03 100644
--- a/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp
+++ b/llvm/unittests/TargetParser/RISCVISAInfoTest.cpp
@@ -1058,6 +1058,8 @@ R"(All available -march extensions for RISC-V
 zvl8192b 1.0
 zhinx1.0
 zhinxmin 1.0
+sdext1.0
+sdtrig   1.0
 sha  1.0
 shcounterenw 1.0
 shgatpa  1.0
@@ -1137,8 +1139,6 @@ Experimental extensions
 zvbc32e  0.7
 zvkgs0.7
 zvqdotq  0.0
-sdext1.0
-sdtrig   1.0
 smctr1.0
 ssctr1.0
 svukte   0.3

>From 8cefd3b15efa4

[clang] Add more tests for _Countof (PR #133333)

2025-03-27 Thread Alejandro Colomar via cfe-commits

https://github.com/alejandro-colomar created 
https://github.com/llvm/llvm-project/pull/13

Cc: @AaronBallman 

I haven't yet tried to run these tests.  I've pasted and adapted them from the 
ones I wrote for my own implementation.

>From c9ce60fef4e3af6faaea2a7e7f41b3866856d237 Mon Sep 17 00:00:00 2001
From: Alejandro Colomar 
Date: Thu, 27 Mar 2025 23:51:18 +0100
Subject: [PATCH] Add more tests for _Countof

Signed-off-by: Alejandro Colomar 
---
 clang/test/C/C2y/n3369.c | 45 +++-
 1 file changed, 44 insertions(+), 1 deletion(-)

diff --git a/clang/test/C/C2y/n3369.c b/clang/test/C/C2y/n3369.c
index 389828b52b6a2..5f7792962ad21 100644
--- a/clang/test/C/C2y/n3369.c
+++ b/clang/test/C/C2y/n3369.c
@@ -18,6 +18,8 @@
 #endif
 
 int global_array[12];
+int global_multi_array[12][34];
+int global_num;
 
 void test_parsing_failures() {
   (void)_Countof; // expected-error {{expected expression}}
@@ -36,6 +38,12 @@ void test_semantic_failures() {
 expected-note {{forward declaration of 'struct 
S'}}
   struct T { int x; };
   (void)_Countof(struct T);  // expected-error {{'_Countof' requires an 
argument of array type; 'struct T' invalid}}
+  struct U { int x[3]; };
+  (void)_Countof(struct U);  // expected-error {{'_Countof' requires an 
argument of array type; 'struct U' invalid}}
+  int a[3];
+  (void)_Countof(&a);  // expected-error {{'_Countof' requires an argument of 
array type; 'int (*)[3]' invalid}}
+  int *p;
+  (void)_Countof(p);  // expected-error {{'_Countof' requires an argument of 
array type; 'int *' invalid}}
 }
 
 void test_constant_expression_behavior(int n) {
@@ -81,6 +89,22 @@ void test_with_function_param(int array[12], int 
(*array_ptr)[12], int static_ar
   (void)_Countof(static_array); // expected-error {{'_Countof' requires an 
argument of array type; 'int *' invalid}}
 }
 
+void test_func_fix_fix(int i, char (*a)[3][5], int (*x)[_Countof(*a)]);
+void test_func_fix_var(int i, char (*a)[3][i], int (*x)[_Countof(*a)]);
+void test_func_fix_uns(int i, char (*a)[3][*], int (*x)[_Countof(*a)]);
+
+void test_funcs() {
+  int i3[3];
+  int i5[5];
+  char c35[3][5];
+  test_func_fix_fix(5, &c35, &i3);
+  test_func_fix_fix(5, &c35, &i5); // expected-error 
{{incompatible-pointer-types}}
+  test_func_fix_var(5, &c35, &i3);
+  test_func_fix_var(5, &c35, &i5); // expected-error 
{{incompatible-pointer-types}}
+  test_func_fix_uns(5, &c35, &i3);
+  test_func_fix_uns(5, &c35, &i5); // expected-error 
{{incompatible-pointer-types}}
+}
+
 void test_multidimensional_arrays() {
   int array[12][7];
   static_assert(_Countof(array) == 12);
@@ -102,6 +126,11 @@ void test_unspecified_array_length() {
   static_assert(_Countof(**x) == 3);
 }
 
+void test_completed_array() {
+  int a[] = {1, 2, errno};
+  static_assert(_Countof(a) == 3);
+}
+
 // Test that the return type of _Countof is what you'd expect (size_t).
 void test_return_type() {
   static_assert(_Generic(typeof(_Countof global_array), typeof(sizeof(0)) : 1, 
default : 0));
@@ -121,10 +150,14 @@ void test_typedefs() {
   static_assert(_Countof(*x) == 12);
 }
 
-void test_zero_size_arrays() {
+void test_zero_size_arrays(int n) {
   int array[0]; // expected-warning {{zero size arrays are an extension}}
   static_assert(_Countof(array) == 0);
   static_assert(_Countof(int[0]) == 0); // expected-warning {{zero size arrays 
are an extension}}
+  int multi_array[0][n]; // expected-warning {{zero size arrays are an 
extension}}
+  static_assert(_Countof(multi_array) == 0);
+  int another_one[0][3]; // expected-warning {{zero size arrays are an 
extension}}
+  static_assert(_Countof(another_one) == 0);
 }
 
 void test_struct_members() {
@@ -144,3 +177,13 @@ void test_compound_literals() {
   static_assert(_Countof((int[2]){}) == 2);
   static_assert(_Countof((int[]){1, 2, 3, 4}) == 4);   
 }
+
+static int test_f1();
+static int test_f2();  // expected-warning {{never defined}}
+
+void test_symbols() {
+  int a[global_num][global_num];
+
+  static_assert(_Countof(global_multi_array[test_f1()]) == 34);
+  (void)_Countof(a[test_f2()]);
+}

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


[clang] Add more tests for _Countof (PR #133333)

2025-03-27 Thread via cfe-commits

github-actions[bot] wrote:



Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this 
page.

If this is not working for you, it is probably because you do not have write 
permissions for the repository. In which case you can instead tag reviewers by 
name in a comment by using `@` followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a 
review by "ping"ing the PR by adding a comment “Ping”. The common courtesy 
"ping" rate is once a week. Please remember that you are asking for valuable 
time from other developers.

If you have further questions, they may be answered by the [LLVM GitHub User 
Guide](https://llvm.org/docs/GitHub.html).

You can also ask questions in a comment on this PR, on the [LLVM 
Discord](https://discord.com/invite/xS7Z362) or on the 
[forums](https://discourse.llvm.org/).

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


[clang] [WebKit Checkers] Recognize Objective-C and CF pointer conversion functions. (PR #132784)

2025-03-27 Thread Ryosuke Niwa via cfe-commits

rniwa wrote:

Thanks for the review!

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


[clang] [SYCL] Basic code generation for SYCL kernel caller offload entry point functions. (PR #133030)

2025-03-27 Thread Tom Honermann via cfe-commits

https://github.com/tahonermann updated 
https://github.com/llvm/llvm-project/pull/133030

>From 2c99027df798c04d252ff8f66853888db89356f1 Mon Sep 17 00:00:00 2001
From: Elizabeth Andrews 
Date: Tue, 25 Mar 2025 09:31:11 -0700
Subject: [PATCH 1/2] [SYCL] Basic code generation for SYCL kernel caller
 offload entry point functions.

A function declared with the `sycl_kernel_entry_point` attribute, sometimes
called a SYCL kernel entry point function, specifies a pattern from which the
parameters and body of an offload entry point function, sometimes called a
SYCL kernel caller function, are derived.

SYCL kernel caller functions are emitted during SYCL device compilation.
Their parameters and body are derived from the `SYCLKernelCallStmt` statement
and `OutlinedFunctionDecl` declaration associated with their corresponding
SYCL kernel entry point function. A distinct SYCL kernel caller function is
generated for each SYCL kernel entry point function defined as a non-inline
function or ODR-used in the translation unit.

The name of each SYCL kernel caller function is parameterized by the SYCL
kernel name type specified by the `sycl_kernel_entry_point` attribute attached
to the corresponding SYCL kernel entry point function. For the moment, the
Itanium ABI mangled name for typeinfo data (`_ZTS`) is used to name
these functions; a future change will switch to a more appropriate naming
scheme.

The calling convention used for a SYCL kernel caller function is target
dependent. Support for AMDGCN, NVPTX, and SPIR targets is currently provided.
These functions are required to observe the language restrictions for SYCL
devices as specified by the SYCL 2020 specification; this includes a forward
progress guarantee and prohibits recursion.

Only SYCL kernel caller functions, functions declared as `SYCL_EXTERNAL`, and
functions directly or indirectly referenced from those functions should be
emitted during device compilation. Pruning of other declarations has not yet
been implemented.

Co-authored-by: Tom Honermann 
---
 clang/include/clang/AST/SYCLKernelInfo.h  |   8 +-
 clang/lib/AST/ASTContext.cpp  |  44 -
 clang/lib/CodeGen/CGCall.cpp  |  10 +
 clang/lib/CodeGen/CMakeLists.txt  |   1 +
 clang/lib/CodeGen/CodeGenModule.cpp   |  25 +++
 clang/lib/CodeGen/CodeGenModule.h |   5 +
 clang/lib/CodeGen/CodeGenSYCL.cpp |  73 
 clang/lib/CodeGen/CodeGenTypes.h  |   6 +
 clang/lib/CodeGen/Targets/NVPTX.cpp   |   4 +
 .../CodeGenSYCL/kernel-caller-entry-point.cpp | 177 ++
 10 files changed, 347 insertions(+), 6 deletions(-)
 create mode 100644 clang/lib/CodeGen/CodeGenSYCL.cpp
 create mode 100644 clang/test/CodeGenSYCL/kernel-caller-entry-point.cpp

diff --git a/clang/include/clang/AST/SYCLKernelInfo.h 
b/clang/include/clang/AST/SYCLKernelInfo.h
index 4a4827e601053..3825af86c14e3 100644
--- a/clang/include/clang/AST/SYCLKernelInfo.h
+++ b/clang/include/clang/AST/SYCLKernelInfo.h
@@ -22,9 +22,10 @@ namespace clang {
 class SYCLKernelInfo {
 public:
   SYCLKernelInfo(CanQualType KernelNameType,
- const FunctionDecl *KernelEntryPointDecl)
+ const FunctionDecl *KernelEntryPointDecl,
+ const std::string &KernelName)
   : KernelNameType(KernelNameType),
-KernelEntryPointDecl(KernelEntryPointDecl) {}
+KernelEntryPointDecl(KernelEntryPointDecl), KernelName(KernelName) {}
 
   CanQualType getKernelNameType() const { return KernelNameType; }
 
@@ -32,9 +33,12 @@ class SYCLKernelInfo {
 return KernelEntryPointDecl;
   }
 
+  const std::string &GetKernelName() const { return KernelName; }
+
 private:
   CanQualType KernelNameType;
   const FunctionDecl *KernelEntryPointDecl;
+  std::string KernelName;
 };
 
 } // namespace clang
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index c9d1bea4c623a..0945eeea4d0f7 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -12816,6 +12816,15 @@ bool ASTContext::DeclMustBeEmitted(const Decl *D) {
 if (!FD->doesThisDeclarationHaveABody())
   return FD->doesDeclarationForceExternallyVisibleDefinition();
 
+// Function definitions with the sycl_kernel_entry_point attribute are
+// required during device compilation so that SYCL kernel caller offload
+// entry points are emitted.
+if (LangOpts.SYCLIsDevice && FD->hasAttr())
+  return true;
+
+// FIXME: Functions declared with SYCL_EXTERNAL are required during
+// FIXME: device compilation.
+
 // Constructors and destructors are required.
 if (FD->hasAttr() || FD->hasAttr())
   return true;
@@ -14794,9 +14803,36 @@ void 
ASTContext::getFunctionFeatureMap(llvm::StringMap &FeatureMap,
   }
 }
 
-static SYCLKernelInfo BuildSYCLKernelInfo(CanQualType KernelNameType,
+static SYCLKernelInfo BuildSYCLKernelInfo(ASTContext &Context,
+   

[clang] Add more tests for _Countof (PR #133333)

2025-03-27 Thread Alejandro Colomar via cfe-commits

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


[clang] [HIP] use offload wrapper for non-device-only non-rdc (PR #132869)

2025-03-27 Thread Yaxun Liu via cfe-commits

https://github.com/yxsamliu updated 
https://github.com/llvm/llvm-project/pull/132869

>From a7b74b80018d15a3c2c30bbc363b73e691ece269 Mon Sep 17 00:00:00 2001
From: "Yaxun (Sam) Liu" 
Date: Fri, 21 Mar 2025 14:16:44 -0400
Subject: [PATCH] [HIP] use offload wrapper for non-device-only non-rdc

Currently HIP still uses offload bundler for non-rdc mode for
the new offload driver.

This patch switches to use offload wrapper for non-device-only
non-rdc mode when new offload driver is enabled.

This makes the rdc and non-rdc compilation more consistent
and speeds up compilation since the offload wrapper supports
parallel compilation for different GPU arch's.

It is implemented by adding a linker wrapper action for
each assemble action of input file. Linker wrapper action
differentiates this special type of work vs normal
linker wrapper work by the fle type. This type of work
results in object instead of image. The linker wrapper
adds "-r" for it and only includes the object file
as input, not the host libraries.

For device-only non-RDC mode, the new driver keeps the
original behavior.
---
 clang/lib/CodeGen/CGCUDANV.cpp |  3 +-
 clang/lib/Driver/Driver.cpp| 59 +++-
 clang/lib/Driver/ToolChains/Clang.cpp  | 19 +++--
 clang/test/Driver/hip-binding.hip  |  6 +-
 clang/test/Driver/hip-phases.hip   | 51 --
 clang/test/Driver/hip-toolchain-no-rdc.hip | 81 +-
 6 files changed, 142 insertions(+), 77 deletions(-)

diff --git a/clang/lib/CodeGen/CGCUDANV.cpp b/clang/lib/CodeGen/CGCUDANV.cpp
index 5445a9278596d..395263331d141 100644
--- a/clang/lib/CodeGen/CGCUDANV.cpp
+++ b/clang/lib/CodeGen/CGCUDANV.cpp
@@ -1281,7 +1281,8 @@ llvm::Function *CGNVCUDARuntime::finalizeModule() {
 return nullptr;
   }
   if (CGM.getLangOpts().OffloadViaLLVM ||
-  (CGM.getLangOpts().OffloadingNewDriver && RelocatableDeviceCode))
+  (CGM.getLangOpts().OffloadingNewDriver &&
+   (CGM.getLangOpts().HIP || RelocatableDeviceCode)))
 createOffloadingEntries();
   else
 return makeModuleCtorFunction();
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 07e36ea2efba4..90d8e823d1d02 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -4405,6 +4405,10 @@ void Driver::BuildActions(Compilation &C, DerivedArgList 
&Args,
options::OPT_no_offload_new_driver,
C.isOffloadingHostKind(Action::OFK_Cuda));
 
+  bool HIPNoRDC =
+  C.isOffloadingHostKind(Action::OFK_HIP) &&
+  !Args.hasFlag(options::OPT_fgpu_rdc, options::OPT_fno_gpu_rdc, false);
+
   // Builder to be used to build offloading actions.
   std::unique_ptr OffloadBuilder =
   !UseNewOffloadingDriver
@@ -4538,7 +4542,7 @@ void Driver::BuildActions(Compilation &C, DerivedArgList 
&Args,
 // Check if this Linker Job should emit a static library.
 if (ShouldEmitStaticLibrary(Args)) {
   LA = C.MakeAction(LinkerInputs, types::TY_Image);
-} else if (UseNewOffloadingDriver ||
+} else if ((UseNewOffloadingDriver && !HIPNoRDC) ||
Args.hasArg(options::OPT_offload_link)) {
   LA = C.MakeAction(LinkerInputs, types::TY_Image);
   LA->propagateHostOffloadInfo(C.getActiveOffloadKinds(),
@@ -4849,10 +4853,28 @@ Action *Driver::BuildOffloadingActions(Compilation &C,
const InputTy &Input, StringRef CUID,
Action *HostAction) const {
   // Don't build offloading actions if explicitly disabled or we do not have a
-  // valid source input and compile action to embed it in. If preprocessing 
only
-  // ignore embedding.
-  if (offloadHostOnly() || !types::isSrcFile(Input.first) ||
-  !(isa(HostAction) ||
+  // valid source input.
+  if (offloadHostOnly() || !types::isSrcFile(Input.first))
+return HostAction;
+
+  bool HIPNoRDC =
+  C.isOffloadingHostKind(Action::OFK_HIP) &&
+  !Args.hasFlag(options::OPT_fgpu_rdc, options::OPT_fno_gpu_rdc, false);
+
+  // For HIP non-rdc non-device-only compilation, create a linker wrapper
+  // action for each host object to link, bundle and wrap device files in
+  // it.
+  if (isa(HostAction) && HIPNoRDC && !offloadDeviceOnly()) {
+ActionList AL{HostAction};
+HostAction = C.MakeAction(AL, types::TY_Object);
+HostAction->propagateHostOffloadInfo(C.getActiveOffloadKinds(),
+ /*BoundArch=*/nullptr);
+return HostAction;
+  }
+
+  // Don't build offloading actions if we do not have a compile action. If
+  // preprocessing only ignore embedding.
+  if (!(isa(HostAction) ||
 getFinalPhase(Args) == phases::Preprocess))
 return HostAction;
 
@@ -4948,12 +4970,12 @@ Action *Driver::BuildOffloadingActions(Compilation &C,
   }
 }
 
-// Compiling HIP in non-RDC mode requires linking each action individually.
+// Compiling HIP in device-only non-RDC mode requires l

[clang] [llvm] [clang][CodeGen] Generate follow-up metadata for loops in correct format (PR #131985)

2025-03-27 Thread Ryotaro Kasuga via cfe-commits

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


[clang] [clang] Fix static_cast bypassing access control (PR #132285)

2025-03-27 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (offsetof)


Changes

Fix access and ambiguity checks not being performed when converting to an 
rvalue reference to a base class type with `static_cast`.

Fixes #121429

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


3 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+1) 
- (modified) clang/lib/Sema/SemaCast.cpp (+11-13) 
- (modified) clang/test/CXX/expr/expr.post/expr.static.cast/p3-0x.cpp (+64-1) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 159991e8db981..18dcedad810ae 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -357,6 +357,7 @@ Bug Fixes to C++ Support
 - Fixed a Clang regression in C++20 mode where unresolved dependent call 
expressions were created inside non-dependent contexts (#GH122892)
 - Clang now emits the ``-Wunused-variable`` warning when some structured 
bindings are unused
   and the ``[[maybe_unused]]`` attribute is not applied. (#GH125810)
+- Fixed ``static_cast`` not performing access or ambiguity checks when 
converting to an rvalue reference to a base class. (#GH121429)
 
 Bug Fixes to AST Handling
 ^
diff --git a/clang/lib/Sema/SemaCast.cpp b/clang/lib/Sema/SemaCast.cpp
index 718f6bec34910..7d64b4e954e4a 100644
--- a/clang/lib/Sema/SemaCast.cpp
+++ b/clang/lib/Sema/SemaCast.cpp
@@ -221,7 +221,7 @@ static void DiagnoseCastQual(Sema &Self, const ExprResult 
&SrcExpr,
 // %2: Destination Type
 static TryCastResult TryLValueToRValueCast(Sema &Self, Expr *SrcExpr,
QualType DestType, bool CStyle,
-   CastKind &Kind,
+   SourceRange OpRange, CastKind &Kind,
CXXCastPath &BasePath,
unsigned &msg);
 static TryCastResult TryStaticReferenceDowncast(Sema &Self, Expr *SrcExpr,
@@ -1357,8 +1357,8 @@ static TryCastResult TryStaticCast(Sema &Self, ExprResult 
&SrcExpr,
   // C++11 [expr.static.cast]p3:
   //   A glvalue of type "cv1 T1" can be cast to type "rvalue reference to cv2
   //   T2" if "cv2 T2" is reference-compatible with "cv1 T1".
-  tcr = TryLValueToRValueCast(Self, SrcExpr.get(), DestType, CStyle, Kind,
-  BasePath, msg);
+  tcr = TryLValueToRValueCast(Self, SrcExpr.get(), DestType, CStyle, OpRange,
+  Kind, BasePath, msg);
   if (tcr != TC_NotApplicable)
 return tcr;
 
@@ -1534,8 +1534,8 @@ static TryCastResult TryStaticCast(Sema &Self, ExprResult 
&SrcExpr,
 /// Tests whether a conversion according to N2844 is valid.
 TryCastResult TryLValueToRValueCast(Sema &Self, Expr *SrcExpr,
 QualType DestType, bool CStyle,
-CastKind &Kind, CXXCastPath &BasePath,
-unsigned &msg) {
+SourceRange OpRange, CastKind &Kind,
+CXXCastPath &BasePath, unsigned &msg) {
   // C++11 [expr.static.cast]p3:
   //   A glvalue of type "cv1 T1" can be cast to type "rvalue reference to
   //   cv2 T2" if "cv2 T2" is reference-compatible with "cv1 T1".
@@ -1548,7 +1548,6 @@ TryCastResult TryLValueToRValueCast(Sema &Self, Expr 
*SrcExpr,
 
   // Because we try the reference downcast before this function, from now on
   // this is the only cast possibility, so we issue an error if we fail now.
-  // FIXME: Should allow casting away constness if CStyle.
   QualType FromType = SrcExpr->getType();
   QualType ToType = R->getPointeeType();
   if (CStyle) {
@@ -1572,13 +1571,12 @@ TryCastResult TryLValueToRValueCast(Sema &Self, Expr 
*SrcExpr,
 
   if (RefConv & Sema::ReferenceConversions::DerivedToBase) {
 Kind = CK_DerivedToBase;
-CXXBasePaths Paths(/*FindAmbiguities=*/true, /*RecordPaths=*/true,
-   /*DetectVirtual=*/true);
-if (!Self.IsDerivedFrom(SrcExpr->getBeginLoc(), SrcExpr->getType(),
-R->getPointeeType(), Paths))
-  return TC_NotApplicable;
-
-Self.BuildBasePathArray(Paths, BasePath);
+if (Self.CheckDerivedToBaseConversion(FromType, ToType,
+  SrcExpr->getBeginLoc(), OpRange,
+  &BasePath, CStyle)) {
+  msg = 0;
+  return TC_Failed;
+}
   } else
 Kind = CK_NoOp;
 
diff --git a/clang/test/CXX/expr/expr.post/expr.static.cast/p3-0x.cpp 
b/clang/test/CXX/expr/expr.post/expr.static.cast/p3-0x.cpp
index 830ccda245baa..0f6968f00f8c1 100644
--- a/clang/test/CXX/expr/expr.post/expr.static.cast/p3-0x.cpp
+++ b/clang/test/CXX/expr/expr.post/expr.static.cast/p3-0x.cpp
@@ -1,5 +1,4 @@
 // RUN: %clang_cc1 -std=c++11 -fsyntax-only -verify %s
-// expected-no-diagnostics
 
 // A glvalue of type "cv1 T1" can be cast to type 

[clang-tools-extra] [clang-tidy] add new check: modernize-use-scoped-lock (PR #126434)

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


@@ -0,0 +1,342 @@
+//===--- UseScopedLockCheck.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 "UseScopedLockCheck.h"
+#include "clang/AST/ASTContext.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/Stmt.h"
+#include "clang/AST/Type.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/Basic/SourceLocation.h"
+#include "clang/Lex/Lexer.h"
+#include "llvm/ADT/SmallVector.h"
+#include "llvm/ADT/Twine.h"
+#include 
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::modernize {
+
+namespace {
+
+bool isLockGuard(const QualType &Type) {
+  if (const auto *Record = Type->getAs())
+if (const RecordDecl *Decl = Record->getDecl())
+  return Decl->getName() == "lock_guard" && Decl->isInStdNamespace();

vbvictor wrote:

added `assert` for `isIdentifier`

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


[clang] [llvm] Optimize Module Dependency Handling for Efficient Memory Usage (PR #132294)

2025-03-27 Thread Ayush Pareek via cfe-commits

https://github.com/ayushpareek2003 updated 
https://github.com/llvm/llvm-project/pull/132294

>From 53a31ec6ed3d9ace8e7d822c2b2de4f6f58ece8d Mon Sep 17 00:00:00 2001
From: Ayush Pareek 
Date: Fri, 21 Mar 2025 03:44:05 +0530
Subject: [PATCH 1/4] Optimize Module Dependency Handling for Efficient Memory
 Usage

-Optimized addModuleFiles functions for both CompilerInvocation and 
CowCompilerInvocation to reduce redundant function calls and improve efficiency

-Introduced memory preallocation using reserve() when eager load is enabled to 
reduce reallocation overhead

-Used try_emplace() instead of insert() for PrebuiltModuleFiles to avoid 
unnecessary overwrites
---
 .../DependencyScanning/ModuleDepCollector.cpp | 61 ---
 1 file changed, 39 insertions(+), 22 deletions(-)

diff --git a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp 
b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
index d715ef874e002..e172285c4b32d 100644
--- a/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
+++ b/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp
@@ -393,41 +393,58 @@ void ModuleDepCollector::addModuleMapFiles(
 CompilerInvocation &CI, ArrayRef ClangModuleDeps) const {
   if (Service.shouldEagerLoadModules())
 return; // Only pcm is needed for eager load.
-
+  
+  // Preallocate memory to avoid multiple allocations
+  CI.getFrontendOpts().ModuleMapFiles.reserve(
+  CI.getFrontendOpts().ModuleMapFiles.size() + ClangModuleDeps.size());
   for (const ModuleID &MID : ClangModuleDeps) {
-ModuleDeps *MD = ModuleDepsByID.lookup(MID);
-assert(MD && "Inconsistent dependency info");
-CI.getFrontendOpts().ModuleMapFiles.push_back(MD->ClangModuleMapFile);
+if (ModuleDeps *MD = ModuleDepsByID.lookup(MID)) { // Single lookup
+  assert(MD && "Inconsistent dependency info");
+  CI.getFrontendOpts().ModuleMapFiles.emplace_back(MD->ClangModuleMapFile);
+}
   }
 }
 
 void ModuleDepCollector::addModuleFiles(
 CompilerInvocation &CI, ArrayRef ClangModuleDeps) const {
+  
+// Preallocate memory if eager load is enabled
+  if (Service.shouldEagerLoadModules()) {
+CI.getFrontendOpts().ModuleFiles.reserve(
+CI.getFrontendOpts().ModuleFiles.size() + ClangModuleDeps.size());
+  }
   for (const ModuleID &MID : ClangModuleDeps) {
-ModuleDeps *MD = ModuleDepsByID.lookup(MID);
-std::string PCMPath =
-Controller.lookupModuleOutput(*MD, ModuleOutputKind::ModuleFile);
-
-if (Service.shouldEagerLoadModules())
-  CI.getFrontendOpts().ModuleFiles.push_back(std::move(PCMPath));
-else
-  CI.getHeaderSearchOpts().PrebuiltModuleFiles.insert(
-  {MID.ModuleName, std::move(PCMPath)});
+if (ModuleDeps *MD = ModuleDepsByID.lookup(MID)) {  
+  std::string PCMPath =
+  Controller.lookupModuleOutput(*MD, ModuleOutputKind::ModuleFile);
+  if (Service.shouldEagerLoadModules()) {
+CI.getFrontendOpts().ModuleFiles.emplace_back(std::move(PCMPath));
+  } else {
+CI.getHeaderSearchOpts().PrebuiltModuleFiles.try_emplace(
+MID.ModuleName, std::move(PCMPath));
+  }
+}
   }
 }
 
 void ModuleDepCollector::addModuleFiles(
 CowCompilerInvocation &CI, ArrayRef ClangModuleDeps) const {
+// Preallocation
+  if (Service.shouldEagerLoadModules()) {
+CI.getMutFrontendOpts().ModuleFiles.reserve(
+CI.getMutFrontendOpts().ModuleFiles.size() + ClangModuleDeps.size());
+  }
   for (const ModuleID &MID : ClangModuleDeps) {
-ModuleDeps *MD = ModuleDepsByID.lookup(MID);
-std::string PCMPath =
-Controller.lookupModuleOutput(*MD, ModuleOutputKind::ModuleFile);
-
-if (Service.shouldEagerLoadModules())
-  CI.getMutFrontendOpts().ModuleFiles.push_back(std::move(PCMPath));
-else
-  CI.getMutHeaderSearchOpts().PrebuiltModuleFiles.insert(
-  {MID.ModuleName, std::move(PCMPath)});
+if (ModuleDeps *MD = ModuleDepsByID.lookup(MID)) {  
+  std::string PCMPath =
+  Controller.lookupModuleOutput(*MD, ModuleOutputKind::ModuleFile);
+  if (Service.shouldEagerLoadModules()) {
+CI.getMutFrontendOpts().ModuleFiles.emplace_back(std::move(PCMPath));
+  } else {
+CI.getMutHeaderSearchOpts().PrebuiltModuleFiles.try_emplace(
+MID.ModuleName, std::move(PCMPath));
+  }
+}
   }
 }
 

>From 153cc53186c60454154e205e48249177b1695eff Mon Sep 17 00:00:00 2001
From: Ayush Pareek 
Date: Mon, 24 Mar 2025 03:02:03 +0530
Subject: [PATCH 2/4] Update README.md

---
 bolt/README.md | 1 +
 1 file changed, 1 insertion(+)

diff --git a/bolt/README.md b/bolt/README.md
index fe54bd82a356a..44ef33bcebeb0 100644
--- a/bolt/README.md
+++ b/bolt/README.md
@@ -7,6 +7,7 @@ An overview of the ideas implemented in BOLT along with a 
discussion of its
 potential and current results is available in
 [CGO'19 
paper](https://research.fb.com/publications/bolt-a-practical-binary-optimizer-for-data-centers-and-beyond/).
 

[clang-tools-extra] [llvm] [clang-doc] Adds a mustache backend (PR #133161)

2025-03-27 Thread Paul Kirth via cfe-commits


@@ -32,6 +33,183 @@ populateParentNamespaces(llvm::SmallVector 
&Namespaces,
 
 static void populateMemberTypeInfo(MemberTypeInfo &I, const FieldDecl *D);
 
+void getTemplateParameters(const TemplateParameterList *TemplateParams, 
+   llvm::raw_ostream &Stream) {
+  Stream << "template <";
+  
+  for (unsigned i = 0; i < TemplateParams->size(); ++i) {
+if (i > 0) {
+  Stream << ", ";
+}
+
+const NamedDecl *Param = TemplateParams->getParam(i);
+if (const auto *TTP = llvm::dyn_cast(Param)) {
+  if (TTP->wasDeclaredWithTypename()) {
+Stream << "typename";
+  } else {
+Stream << "class";
+  }
+  if (TTP->isParameterPack()) {
+Stream << "...";
+  }
+  Stream << " " << TTP->getNameAsString();
+} else if (const auto *NTTP = 
llvm::dyn_cast(Param)) {
+  NTTP->getType().print(Stream, NTTP->getASTContext().getPrintingPolicy());
+  if (NTTP->isParameterPack()) {
+Stream << "...";
+  }
+  Stream << " " << NTTP->getNameAsString();
+} else if (const auto *TTPD = 
llvm::dyn_cast(Param)) {
+  Stream << "template <";
+  getTemplateParameters(TTPD->getTemplateParameters(), Stream);
+  Stream << "> class " << TTPD->getNameAsString();
+}
+  }
+
+  Stream << "> ";
+}
+
+// Extract the full function prototype from a FunctionDecl including 
+// Full Decl
+llvm::SmallString<256> getFunctionPrototype(const FunctionDecl *FuncDecl) {

ilovepi wrote:

How much does this output differ from `PrintName()` or 
`getNameForDiagnostic()`? I'm wondering if we need a custom thing here since we 
have the FunctionDecl.

https://clang.llvm.org/doxygen/classclang_1_1FunctionDecl.html#af40656355e6d13ca9d7de07340b1b46c

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


[clang-tools-extra] [llvm] [clang-doc] Adds a mustache backend (PR #133161)

2025-03-27 Thread Paul Kirth via cfe-commits


@@ -455,8 +473,9 @@ struct EnumValueInfo {
   // Stores the user-supplied initialization expression for this enumeration
   // constant. This will be empty for implicit enumeration values.
   SmallString<16> ValueExpr;
-
-  std::vector Description; /// Comment description of this field.
+  
+  /// Comment description of this field.
+  std::vector Description; 

ilovepi wrote:

Lets try to keep cleanups like this in their own PRs. The same goes for any 
other changes that can be done  independently of adding Mustache support.

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


[clang] [NFC] Fix warning: variable II set but not used (PR #133307)

2025-03-27 Thread via cfe-commits

https://github.com/hiraditya created 
https://github.com/llvm/llvm-project/pull/133307

```
llvm-project/clang/lib/Sema/SemaExprCXX.cpp:63:29: warning: variable 'II' set 
but not used [-Wunused-but-set-variable]
   63 |   if (const IdentifierInfo *II = NNS->getAsIdentifier())
  | ^
```

>From fc11d3de940c57bb6aaf1592993c921a4c1038ee Mon Sep 17 00:00:00 2001
From: AdityaK 
Date: Thu, 27 Mar 2025 19:55:41 +
Subject: [PATCH] [NFC] Fix warning: variable II set but not used

llvm-project/clang/lib/Sema/SemaExprCXX.cpp:63:29: warning: variable 'II' set 
but not used [-Wunused-but-set-variable]
   63 |   if (const IdentifierInfo *II = NNS->getAsIdentifier())
  | ^
---
 clang/lib/Sema/SemaExprCXX.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index b2310628adc64..a96c024694c59 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -60,9 +60,10 @@ ParsedType Sema::getInheritingConstructorName(CXXScopeSpec 
&SS,
   SourceLocation NameLoc,
   const IdentifierInfo &Name) {
   NestedNameSpecifier *NNS = SS.getScopeRep();
+#ifndef NDEBUG
   if (const IdentifierInfo *II = NNS->getAsIdentifier())
 assert(II == &Name && "not a constructor name");
-
+#endif
   QualType Type(NNS->translateToType(Context), 0);
   // This reference to the type is located entirely at the location of the
   // final identifier in the qualified-id.

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


[clang] [llvm] [mlir] [MLIR][OpenMP] Add codegen for teams reductions (PR #133310)

2025-03-27 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-mlir-openmp

Author: Jan Leyonberg (jsjodin)


Changes

This patch adds the lowering of teams reductions from the omp dialect to 
LLVM-IR. Some minor cleanup was done in clang to remove an unused parameter. 

---

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


11 Files Affected:

- (modified) clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp (+1-2) 
- (modified) llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h (+4-4) 
- (modified) llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp (+135-56) 
- (modified) 
mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp (+185-23) 
- (modified) mlir/test/Target/LLVMIR/omptarget-parallel-wsloop.mlir (+1-1) 
- (modified) mlir/test/Target/LLVMIR/omptarget-wsloop-collapsed.mlir (+1-1) 
- (modified) mlir/test/Target/LLVMIR/omptarget-wsloop.mlir (+2-2) 
- (added) mlir/test/Target/LLVMIR/openmp-teams-reduction.mlir (+71) 
- (modified) mlir/test/Target/LLVMIR/openmp-todo.mlir (-28) 
- (added) offload/test/offloading/fortran/basic-target-parallel-reduction.f90 
(+27) 
- (added) 
offload/test/offloading/fortran/basic-target-teams-parallel-reduction.f90 (+27) 


``diff
diff --git a/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
index feb2448297542..d30bef9e7f0ba 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
@@ -1659,7 +1659,6 @@ void CGOpenMPRuntimeGPU::emitReduction(
 return;
 
   bool ParallelReduction = isOpenMPParallelDirective(Options.ReductionKind);
-  bool DistributeReduction = 
isOpenMPDistributeDirective(Options.ReductionKind);
   bool TeamsReduction = isOpenMPTeamsDirective(Options.ReductionKind);
 
   ASTContext &C = CGM.getContext();
@@ -1756,7 +1755,7 @@ void CGOpenMPRuntimeGPU::emitReduction(
   llvm::OpenMPIRBuilder::InsertPointTy AfterIP =
   cantFail(OMPBuilder.createReductionsGPU(
   OmpLoc, AllocaIP, CodeGenIP, ReductionInfos, false, TeamsReduction,
-  DistributeReduction, 
llvm::OpenMPIRBuilder::ReductionGenCBKind::Clang,
+  llvm::OpenMPIRBuilder::ReductionGenCBKind::Clang,
   CGF.getTarget().getGridValue(),
   C.getLangOpts().OpenMPCUDAReductionBufNum, RTLoc));
   CGF.Builder.restoreIP(AfterIP);
diff --git a/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h 
b/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
index 28909cef4748d..a3a266e3f0a98 100644
--- a/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
+++ b/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
@@ -1905,8 +1905,6 @@ class OpenMPIRBuilder {
   ///   nowait.
   /// \param IsTeamsReduction   Optional flag set if it is a teams
   ///   reduction.
-  /// \param HasDistribute  Optional flag set if it is a
-  ///   distribute reduction.
   /// \param GridValue  Optional GPU grid value.
   /// \param ReductionBufNumOptional OpenMPCUDAReductionBufNumValue to be
   /// used for teams reduction.
@@ -1915,7 +1913,6 @@ class OpenMPIRBuilder {
   const LocationDescription &Loc, InsertPointTy AllocaIP,
   InsertPointTy CodeGenIP, ArrayRef ReductionInfos,
   bool IsNoWait = false, bool IsTeamsReduction = false,
-  bool HasDistribute = false,
   ReductionGenCBKind ReductionGenCBKind = ReductionGenCBKind::MLIR,
   std::optional GridValue = {}, unsigned ReductionBufNum = 1024,
   Value *SrcLocInfo = nullptr);
@@ -1987,7 +1984,8 @@ class OpenMPIRBuilder {
 InsertPointTy AllocaIP,
 ArrayRef ReductionInfos,
 ArrayRef IsByRef,
-bool IsNoWait = false);
+bool IsNoWait = false,
+bool IsTeamsReduction = false);
 
   ///}
 
@@ -2271,6 +2269,8 @@ class OpenMPIRBuilder {
 int32_t MinTeams = 1;
 SmallVector MaxThreads = {-1};
 int32_t MinThreads = 1;
+int32_t ReductionDataSize = 0;
+int32_t ReductionBufferLength = 0;
   };
 
   /// Container to pass LLVM IR runtime values or constants related to the
diff --git a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp 
b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
index 2e5ce5308eea5..b5e55dbccf464 100644
--- a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -3495,9 +3495,9 @@ 
checkReductionInfos(ArrayRef ReductionInfos,
 OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::createReductionsGPU(
 const LocationDescription &Loc, InsertPointTy AllocaIP,
 InsertPointTy CodeGenIP, ArrayRef ReductionInfos,
-bool IsNoWait, bool IsTeamsReduction, bool HasDistribute,
-ReductionGenCBKind ReductionGenCBKind, std::optional GridValue,
-unsigned ReductionBufNum, Value *SrcLocInfo) {
+bool IsNoWait, bool IsTeamsRed

[clang] [llvm] [mlir] [MLIR][OpenMP] Add codegen for teams reductions (PR #133310)

2025-03-27 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Jan Leyonberg (jsjodin)


Changes

This patch adds the lowering of teams reductions from the omp dialect to 
LLVM-IR. Some minor cleanup was done in clang to remove an unused parameter. 

---

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


11 Files Affected:

- (modified) clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp (+1-2) 
- (modified) llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h (+4-4) 
- (modified) llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp (+135-56) 
- (modified) 
mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp (+185-23) 
- (modified) mlir/test/Target/LLVMIR/omptarget-parallel-wsloop.mlir (+1-1) 
- (modified) mlir/test/Target/LLVMIR/omptarget-wsloop-collapsed.mlir (+1-1) 
- (modified) mlir/test/Target/LLVMIR/omptarget-wsloop.mlir (+2-2) 
- (added) mlir/test/Target/LLVMIR/openmp-teams-reduction.mlir (+71) 
- (modified) mlir/test/Target/LLVMIR/openmp-todo.mlir (-28) 
- (added) offload/test/offloading/fortran/basic-target-parallel-reduction.f90 
(+27) 
- (added) 
offload/test/offloading/fortran/basic-target-teams-parallel-reduction.f90 (+27) 


``diff
diff --git a/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
index feb2448297542..d30bef9e7f0ba 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
@@ -1659,7 +1659,6 @@ void CGOpenMPRuntimeGPU::emitReduction(
 return;
 
   bool ParallelReduction = isOpenMPParallelDirective(Options.ReductionKind);
-  bool DistributeReduction = 
isOpenMPDistributeDirective(Options.ReductionKind);
   bool TeamsReduction = isOpenMPTeamsDirective(Options.ReductionKind);
 
   ASTContext &C = CGM.getContext();
@@ -1756,7 +1755,7 @@ void CGOpenMPRuntimeGPU::emitReduction(
   llvm::OpenMPIRBuilder::InsertPointTy AfterIP =
   cantFail(OMPBuilder.createReductionsGPU(
   OmpLoc, AllocaIP, CodeGenIP, ReductionInfos, false, TeamsReduction,
-  DistributeReduction, 
llvm::OpenMPIRBuilder::ReductionGenCBKind::Clang,
+  llvm::OpenMPIRBuilder::ReductionGenCBKind::Clang,
   CGF.getTarget().getGridValue(),
   C.getLangOpts().OpenMPCUDAReductionBufNum, RTLoc));
   CGF.Builder.restoreIP(AfterIP);
diff --git a/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h 
b/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
index 28909cef4748d..a3a266e3f0a98 100644
--- a/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
+++ b/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
@@ -1905,8 +1905,6 @@ class OpenMPIRBuilder {
   ///   nowait.
   /// \param IsTeamsReduction   Optional flag set if it is a teams
   ///   reduction.
-  /// \param HasDistribute  Optional flag set if it is a
-  ///   distribute reduction.
   /// \param GridValue  Optional GPU grid value.
   /// \param ReductionBufNumOptional OpenMPCUDAReductionBufNumValue to be
   /// used for teams reduction.
@@ -1915,7 +1913,6 @@ class OpenMPIRBuilder {
   const LocationDescription &Loc, InsertPointTy AllocaIP,
   InsertPointTy CodeGenIP, ArrayRef ReductionInfos,
   bool IsNoWait = false, bool IsTeamsReduction = false,
-  bool HasDistribute = false,
   ReductionGenCBKind ReductionGenCBKind = ReductionGenCBKind::MLIR,
   std::optional GridValue = {}, unsigned ReductionBufNum = 1024,
   Value *SrcLocInfo = nullptr);
@@ -1987,7 +1984,8 @@ class OpenMPIRBuilder {
 InsertPointTy AllocaIP,
 ArrayRef ReductionInfos,
 ArrayRef IsByRef,
-bool IsNoWait = false);
+bool IsNoWait = false,
+bool IsTeamsReduction = false);
 
   ///}
 
@@ -2271,6 +2269,8 @@ class OpenMPIRBuilder {
 int32_t MinTeams = 1;
 SmallVector MaxThreads = {-1};
 int32_t MinThreads = 1;
+int32_t ReductionDataSize = 0;
+int32_t ReductionBufferLength = 0;
   };
 
   /// Container to pass LLVM IR runtime values or constants related to the
diff --git a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp 
b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
index 2e5ce5308eea5..b5e55dbccf464 100644
--- a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -3495,9 +3495,9 @@ 
checkReductionInfos(ArrayRef ReductionInfos,
 OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::createReductionsGPU(
 const LocationDescription &Loc, InsertPointTy AllocaIP,
 InsertPointTy CodeGenIP, ArrayRef ReductionInfos,
-bool IsNoWait, bool IsTeamsReduction, bool HasDistribute,
-ReductionGenCBKind ReductionGenCBKind, std::optional GridValue,
-unsigned ReductionBufNum, Value *SrcLocInfo) {
+bool IsNoWait, bool IsTeamsReduction

[clang] [llvm] [mlir] [MLIR][OpenMP] Add codegen for teams reductions (PR #133310)

2025-03-27 Thread Jan Leyonberg via cfe-commits

https://github.com/jsjodin created 
https://github.com/llvm/llvm-project/pull/133310

This patch adds the lowering of teams reductions from the omp dialect to 
LLVM-IR. Some minor cleanup was done in clang to remove an unused parameter. 

>From 50fefbb31f4de7352c241c48fe5382785daaef21 Mon Sep 17 00:00:00 2001
From: Jan Leyonberg 
Date: Sun, 23 Mar 2025 09:56:51 -0400
Subject: [PATCH 1/8] Initial modifications to support reductions in flang.

---
 clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp  |  3 +-
 .../llvm/Frontend/OpenMP/OMPIRBuilder.h   |  3 --
 llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp | 30 +++
 3 files changed, 26 insertions(+), 10 deletions(-)

diff --git a/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
index feb2448297542..d30bef9e7f0ba 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
@@ -1659,7 +1659,6 @@ void CGOpenMPRuntimeGPU::emitReduction(
 return;
 
   bool ParallelReduction = isOpenMPParallelDirective(Options.ReductionKind);
-  bool DistributeReduction = 
isOpenMPDistributeDirective(Options.ReductionKind);
   bool TeamsReduction = isOpenMPTeamsDirective(Options.ReductionKind);
 
   ASTContext &C = CGM.getContext();
@@ -1756,7 +1755,7 @@ void CGOpenMPRuntimeGPU::emitReduction(
   llvm::OpenMPIRBuilder::InsertPointTy AfterIP =
   cantFail(OMPBuilder.createReductionsGPU(
   OmpLoc, AllocaIP, CodeGenIP, ReductionInfos, false, TeamsReduction,
-  DistributeReduction, 
llvm::OpenMPIRBuilder::ReductionGenCBKind::Clang,
+  llvm::OpenMPIRBuilder::ReductionGenCBKind::Clang,
   CGF.getTarget().getGridValue(),
   C.getLangOpts().OpenMPCUDAReductionBufNum, RTLoc));
   CGF.Builder.restoreIP(AfterIP);
diff --git a/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h 
b/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
index 28909cef4748d..9b67d0c050e46 100644
--- a/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
+++ b/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
@@ -1905,8 +1905,6 @@ class OpenMPIRBuilder {
   ///   nowait.
   /// \param IsTeamsReduction   Optional flag set if it is a teams
   ///   reduction.
-  /// \param HasDistribute  Optional flag set if it is a
-  ///   distribute reduction.
   /// \param GridValue  Optional GPU grid value.
   /// \param ReductionBufNumOptional OpenMPCUDAReductionBufNumValue to be
   /// used for teams reduction.
@@ -1915,7 +1913,6 @@ class OpenMPIRBuilder {
   const LocationDescription &Loc, InsertPointTy AllocaIP,
   InsertPointTy CodeGenIP, ArrayRef ReductionInfos,
   bool IsNoWait = false, bool IsTeamsReduction = false,
-  bool HasDistribute = false,
   ReductionGenCBKind ReductionGenCBKind = ReductionGenCBKind::MLIR,
   std::optional GridValue = {}, unsigned ReductionBufNum = 1024,
   Value *SrcLocInfo = nullptr);
diff --git a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp 
b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
index 2e5ce5308eea5..0001626086d7c 100644
--- a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -3495,9 +3495,9 @@ 
checkReductionInfos(ArrayRef ReductionInfos,
 OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::createReductionsGPU(
 const LocationDescription &Loc, InsertPointTy AllocaIP,
 InsertPointTy CodeGenIP, ArrayRef ReductionInfos,
-bool IsNoWait, bool IsTeamsReduction, bool HasDistribute,
-ReductionGenCBKind ReductionGenCBKind, std::optional GridValue,
-unsigned ReductionBufNum, Value *SrcLocInfo) {
+bool IsNoWait, bool IsTeamsReduction, ReductionGenCBKind 
ReductionGenCBKind,
+std::optional GridValue, unsigned ReductionBufNum,
+Value *SrcLocInfo) {
   if (!updateToLocation(Loc))
 return InsertPointTy();
   Builder.restoreIP(CodeGenIP);
@@ -3514,6 +3514,16 @@ OpenMPIRBuilder::InsertPointOrErrorTy 
OpenMPIRBuilder::createReductionsGPU(
   if (ReductionInfos.size() == 0)
 return Builder.saveIP();
 
+  BasicBlock *ContinuationBlock = nullptr;
+  if (ReductionGenCBKind != ReductionGenCBKind::Clang) {
+// Copied code from createReductions
+BasicBlock *InsertBlock = Loc.IP.getBlock();
+ContinuationBlock =
+InsertBlock->splitBasicBlock(Loc.IP.getPoint(), "reduce.finalize");
+InsertBlock->getTerminator()->eraseFromParent();
+Builder.SetInsertPoint(InsertBlock, InsertBlock->end());
+  }
+
   Function *CurFunc = Builder.GetInsertBlock()->getParent();
   AttributeList FuncAttrs;
   AttrBuilder AttrBldr(Ctx);
@@ -3669,11 +3679,21 @@ OpenMPIRBuilder::InsertPointOrErrorTy 
OpenMPIRBuilder::createReductionsGPU(
ReductionFunc;
   });
 } else {
-  assert(false && "Unhandled ReductionGenCBKind");
+  Value *LHSValue = Builder.CreateLoad(RI.ElementType, LHS, "final.lhs");
+  Value *RHSValue = Builder.CreateLoad(RI.ElementType, RHS, "final.r

[clang] [llvm] [mlir] [MLIR][OpenMP] Add codegen for teams reductions (PR #133310)

2025-03-27 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang-codegen

@llvm/pr-subscribers-mlir-llvm

Author: Jan Leyonberg (jsjodin)


Changes

This patch adds the lowering of teams reductions from the omp dialect to 
LLVM-IR. Some minor cleanup was done in clang to remove an unused parameter. 

---

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


11 Files Affected:

- (modified) clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp (+1-2) 
- (modified) llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h (+4-4) 
- (modified) llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp (+135-56) 
- (modified) 
mlir/lib/Target/LLVMIR/Dialect/OpenMP/OpenMPToLLVMIRTranslation.cpp (+185-23) 
- (modified) mlir/test/Target/LLVMIR/omptarget-parallel-wsloop.mlir (+1-1) 
- (modified) mlir/test/Target/LLVMIR/omptarget-wsloop-collapsed.mlir (+1-1) 
- (modified) mlir/test/Target/LLVMIR/omptarget-wsloop.mlir (+2-2) 
- (added) mlir/test/Target/LLVMIR/openmp-teams-reduction.mlir (+71) 
- (modified) mlir/test/Target/LLVMIR/openmp-todo.mlir (-28) 
- (added) offload/test/offloading/fortran/basic-target-parallel-reduction.f90 
(+27) 
- (added) 
offload/test/offloading/fortran/basic-target-teams-parallel-reduction.f90 (+27) 


``diff
diff --git a/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
index feb2448297542..d30bef9e7f0ba 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
@@ -1659,7 +1659,6 @@ void CGOpenMPRuntimeGPU::emitReduction(
 return;
 
   bool ParallelReduction = isOpenMPParallelDirective(Options.ReductionKind);
-  bool DistributeReduction = 
isOpenMPDistributeDirective(Options.ReductionKind);
   bool TeamsReduction = isOpenMPTeamsDirective(Options.ReductionKind);
 
   ASTContext &C = CGM.getContext();
@@ -1756,7 +1755,7 @@ void CGOpenMPRuntimeGPU::emitReduction(
   llvm::OpenMPIRBuilder::InsertPointTy AfterIP =
   cantFail(OMPBuilder.createReductionsGPU(
   OmpLoc, AllocaIP, CodeGenIP, ReductionInfos, false, TeamsReduction,
-  DistributeReduction, 
llvm::OpenMPIRBuilder::ReductionGenCBKind::Clang,
+  llvm::OpenMPIRBuilder::ReductionGenCBKind::Clang,
   CGF.getTarget().getGridValue(),
   C.getLangOpts().OpenMPCUDAReductionBufNum, RTLoc));
   CGF.Builder.restoreIP(AfterIP);
diff --git a/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h 
b/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
index 28909cef4748d..a3a266e3f0a98 100644
--- a/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
+++ b/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
@@ -1905,8 +1905,6 @@ class OpenMPIRBuilder {
   ///   nowait.
   /// \param IsTeamsReduction   Optional flag set if it is a teams
   ///   reduction.
-  /// \param HasDistribute  Optional flag set if it is a
-  ///   distribute reduction.
   /// \param GridValue  Optional GPU grid value.
   /// \param ReductionBufNumOptional OpenMPCUDAReductionBufNumValue to be
   /// used for teams reduction.
@@ -1915,7 +1913,6 @@ class OpenMPIRBuilder {
   const LocationDescription &Loc, InsertPointTy AllocaIP,
   InsertPointTy CodeGenIP, ArrayRef ReductionInfos,
   bool IsNoWait = false, bool IsTeamsReduction = false,
-  bool HasDistribute = false,
   ReductionGenCBKind ReductionGenCBKind = ReductionGenCBKind::MLIR,
   std::optional GridValue = {}, unsigned ReductionBufNum = 1024,
   Value *SrcLocInfo = nullptr);
@@ -1987,7 +1984,8 @@ class OpenMPIRBuilder {
 InsertPointTy AllocaIP,
 ArrayRef ReductionInfos,
 ArrayRef IsByRef,
-bool IsNoWait = false);
+bool IsNoWait = false,
+bool IsTeamsReduction = false);
 
   ///}
 
@@ -2271,6 +2269,8 @@ class OpenMPIRBuilder {
 int32_t MinTeams = 1;
 SmallVector MaxThreads = {-1};
 int32_t MinThreads = 1;
+int32_t ReductionDataSize = 0;
+int32_t ReductionBufferLength = 0;
   };
 
   /// Container to pass LLVM IR runtime values or constants related to the
diff --git a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp 
b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
index 2e5ce5308eea5..b5e55dbccf464 100644
--- a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -3495,9 +3495,9 @@ 
checkReductionInfos(ArrayRef ReductionInfos,
 OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::createReductionsGPU(
 const LocationDescription &Loc, InsertPointTy AllocaIP,
 InsertPointTy CodeGenIP, ArrayRef ReductionInfos,
-bool IsNoWait, bool IsTeamsReduction, bool HasDistribute,
-ReductionGenCBKind ReductionGenCBKind, std::optional GridValue,
-unsigned ReductionBufNum, Value *SrcLocInfo) {
+ 

[clang] [llvm] [mlir] [MLIR][OpenMP] Add codegen for teams reductions (PR #133310)

2025-03-27 Thread Jan Leyonberg via cfe-commits

https://github.com/jsjodin updated 
https://github.com/llvm/llvm-project/pull/133310

>From 50fefbb31f4de7352c241c48fe5382785daaef21 Mon Sep 17 00:00:00 2001
From: Jan Leyonberg 
Date: Sun, 23 Mar 2025 09:56:51 -0400
Subject: [PATCH 1/9] Initial modifications to support reductions in flang.

---
 clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp  |  3 +-
 .../llvm/Frontend/OpenMP/OMPIRBuilder.h   |  3 --
 llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp | 30 +++
 3 files changed, 26 insertions(+), 10 deletions(-)

diff --git a/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
index feb2448297542..d30bef9e7f0ba 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntimeGPU.cpp
@@ -1659,7 +1659,6 @@ void CGOpenMPRuntimeGPU::emitReduction(
 return;
 
   bool ParallelReduction = isOpenMPParallelDirective(Options.ReductionKind);
-  bool DistributeReduction = 
isOpenMPDistributeDirective(Options.ReductionKind);
   bool TeamsReduction = isOpenMPTeamsDirective(Options.ReductionKind);
 
   ASTContext &C = CGM.getContext();
@@ -1756,7 +1755,7 @@ void CGOpenMPRuntimeGPU::emitReduction(
   llvm::OpenMPIRBuilder::InsertPointTy AfterIP =
   cantFail(OMPBuilder.createReductionsGPU(
   OmpLoc, AllocaIP, CodeGenIP, ReductionInfos, false, TeamsReduction,
-  DistributeReduction, 
llvm::OpenMPIRBuilder::ReductionGenCBKind::Clang,
+  llvm::OpenMPIRBuilder::ReductionGenCBKind::Clang,
   CGF.getTarget().getGridValue(),
   C.getLangOpts().OpenMPCUDAReductionBufNum, RTLoc));
   CGF.Builder.restoreIP(AfterIP);
diff --git a/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h 
b/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
index 28909cef4748d..9b67d0c050e46 100644
--- a/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
+++ b/llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h
@@ -1905,8 +1905,6 @@ class OpenMPIRBuilder {
   ///   nowait.
   /// \param IsTeamsReduction   Optional flag set if it is a teams
   ///   reduction.
-  /// \param HasDistribute  Optional flag set if it is a
-  ///   distribute reduction.
   /// \param GridValue  Optional GPU grid value.
   /// \param ReductionBufNumOptional OpenMPCUDAReductionBufNumValue to be
   /// used for teams reduction.
@@ -1915,7 +1913,6 @@ class OpenMPIRBuilder {
   const LocationDescription &Loc, InsertPointTy AllocaIP,
   InsertPointTy CodeGenIP, ArrayRef ReductionInfos,
   bool IsNoWait = false, bool IsTeamsReduction = false,
-  bool HasDistribute = false,
   ReductionGenCBKind ReductionGenCBKind = ReductionGenCBKind::MLIR,
   std::optional GridValue = {}, unsigned ReductionBufNum = 1024,
   Value *SrcLocInfo = nullptr);
diff --git a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp 
b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
index 2e5ce5308eea5..0001626086d7c 100644
--- a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -3495,9 +3495,9 @@ 
checkReductionInfos(ArrayRef ReductionInfos,
 OpenMPIRBuilder::InsertPointOrErrorTy OpenMPIRBuilder::createReductionsGPU(
 const LocationDescription &Loc, InsertPointTy AllocaIP,
 InsertPointTy CodeGenIP, ArrayRef ReductionInfos,
-bool IsNoWait, bool IsTeamsReduction, bool HasDistribute,
-ReductionGenCBKind ReductionGenCBKind, std::optional GridValue,
-unsigned ReductionBufNum, Value *SrcLocInfo) {
+bool IsNoWait, bool IsTeamsReduction, ReductionGenCBKind 
ReductionGenCBKind,
+std::optional GridValue, unsigned ReductionBufNum,
+Value *SrcLocInfo) {
   if (!updateToLocation(Loc))
 return InsertPointTy();
   Builder.restoreIP(CodeGenIP);
@@ -3514,6 +3514,16 @@ OpenMPIRBuilder::InsertPointOrErrorTy 
OpenMPIRBuilder::createReductionsGPU(
   if (ReductionInfos.size() == 0)
 return Builder.saveIP();
 
+  BasicBlock *ContinuationBlock = nullptr;
+  if (ReductionGenCBKind != ReductionGenCBKind::Clang) {
+// Copied code from createReductions
+BasicBlock *InsertBlock = Loc.IP.getBlock();
+ContinuationBlock =
+InsertBlock->splitBasicBlock(Loc.IP.getPoint(), "reduce.finalize");
+InsertBlock->getTerminator()->eraseFromParent();
+Builder.SetInsertPoint(InsertBlock, InsertBlock->end());
+  }
+
   Function *CurFunc = Builder.GetInsertBlock()->getParent();
   AttributeList FuncAttrs;
   AttrBuilder AttrBldr(Ctx);
@@ -3669,11 +3679,21 @@ OpenMPIRBuilder::InsertPointOrErrorTy 
OpenMPIRBuilder::createReductionsGPU(
ReductionFunc;
   });
 } else {
-  assert(false && "Unhandled ReductionGenCBKind");
+  Value *LHSValue = Builder.CreateLoad(RI.ElementType, LHS, "final.lhs");
+  Value *RHSValue = Builder.CreateLoad(RI.ElementType, RHS, "final.rhs");
+  Value *Reduced;
+  InsertPointOrErrorTy AfterIP =
+  RI.ReductionGen(Builder.saveIP(), RHSValue, LHSValue, Reduced);
+  if (

[clang] [llvm] [HLSL][RootSignature] Implement parsing of a DescriptorTable with empty clauses (PR #133302)

2025-03-27 Thread via cfe-commits


@@ -0,0 +1,188 @@
+#include "clang/Parse/ParseHLSLRootSignature.h"
+
+#include "llvm/Support/raw_ostream.h"
+
+using namespace llvm::hlsl::rootsig;
+
+namespace clang {
+namespace hlsl {
+
+static std::string FormatTokenKinds(ArrayRef Kinds) {
+  std::string TokenString;
+  llvm::raw_string_ostream Out(TokenString);
+  bool First = true;
+  for (auto Kind : Kinds) {
+if (!First)
+  Out << ", ";
+switch (Kind) {
+#define TOK(X, SPELLING)   
\
+  case TokenKind::X:   
\
+Out << SPELLING;   
\
+break;
+#include "clang/Lex/HLSLRootSignatureTokenKinds.def"
+}
+First = false;
+  }
+
+  return TokenString;
+}
+
+// Parser Definitions
+
+RootSignatureParser::RootSignatureParser(SmallVector &Elements,
+ RootSignatureLexer &Lexer,
+ Preprocessor &PP)
+: Elements(Elements), Lexer(Lexer), PP(PP), CurToken(SourceLocation()) {}
+
+bool RootSignatureParser::Parse() {
+  // Iterate as many RootElements as possible
+  while (TryConsumeExpectedToken(TokenKind::kw_DescriptorTable)) {
+bool Error = false;
+// Dispatch onto parser method.
+// We guard against the unreachable here as we just ensured that CurToken
+// will be one of the kinds in the while condition
+switch (CurToken.Kind) {
+case TokenKind::kw_DescriptorTable:
+  Error = ParseDescriptorTable();
+  break;
+default:
+  llvm_unreachable("Switch for consumed token was not provided");
+}
+
+if (Error)
+  return true;
+
+if (!TryConsumeExpectedToken(TokenKind::pu_comma))
+  break;
+  }
+
+  return ConsumeExpectedToken(TokenKind::end_of_stream, diag::err_expected);
+}
+
+bool RootSignatureParser::ParseDescriptorTable() {
+  assert(CurToken.Kind == TokenKind::kw_DescriptorTable &&
+ "Expects to only be invoked starting at given keyword");
+
+  DescriptorTable Table;
+
+  if (ConsumeExpectedToken(TokenKind::pu_l_paren, diag::err_expected_after,
+   CurToken.Kind))
+return true;
+
+  // Iterate as many Clauses as possible
+  while (TryConsumeExpectedToken({TokenKind::kw_CBV, TokenKind::kw_SRV,

joaosaffran wrote:

nit: I imagine the above loop would be something like this, once you add more 
Root Elements?

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


[clang] [llvm] [HLSL][RootSignature] Implement parsing of a DescriptorTable with empty clauses (PR #133302)

2025-03-27 Thread via cfe-commits


@@ -0,0 +1,44 @@
+//===- HLSLRootSignature.h - HLSL Root Signature helper objects 
---===//
+//
+// 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
+//
+//===--===//
+///
+/// \file This file contains helper objects for working with HLSL Root
+/// Signatures.
+///
+//===--===//
+
+#ifndef LLVM_FRONTEND_HLSL_HLSLROOTSIGNATURE_H
+#define LLVM_FRONTEND_HLSL_HLSLROOTSIGNATURE_H
+
+#include "llvm/Support/DXILABI.h"
+#include 
+
+namespace llvm {
+namespace hlsl {
+namespace rootsig {
+
+// Definitions of the in-memory data layout structures
+
+// Models the end of a descriptor table and stores its visibility
+struct DescriptorTable {
+  uint32_t NumClauses = 0; // The number of clauses in the table
+};
+
+// Models DTClause : CBV | SRV | UAV | Sampler, by collecting like parameters
+using ClauseType = llvm::dxil::ResourceClass;
+struct DescriptorTableClause {
+  ClauseType Type;
+};
+
+// Models RootElement : DescriptorTable | DescriptorTableClause
+using RootElement = std::variant;

joaosaffran wrote:

I feel like the `DescriptorTableClause` should be a member of `DescriptorTable` 
and not a RootElement, since those are connected in the metadata 
representation, it should be easier that way, IMHO.

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


[clang] [AMDGPU][True16][Driver] support true16 target feature in clang driver (PR #133298)

2025-03-27 Thread Brox Chen via cfe-commits

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


[clang-tools-extra] [llvm] [clang-doc] Adds a mustache backend (PR #133161)

2025-03-27 Thread Paul Kirth via cfe-commits

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


[clang-tools-extra] [llvm] [clang-doc] Adds a mustache backend (PR #133161)

2025-03-27 Thread Paul Kirth via cfe-commits


@@ -359,6 +371,9 @@ struct FunctionInfo : public SymbolInfo {
   // Full qualified name of this function, including namespaces and template
   // specializations.
   SmallString<16> FullName;
+  
+  // Function Prototype
+  SmallString<256> ProtoType;

ilovepi wrote:

why 256? you realize that allocates a 256 byte buffer in this struct, right? Do 
we expect to use many of them? Do you have a feeling for the typical size of 
the Prototype? like what's the median size in say LLVM? what about 90th 
percentile? I have a feeling there is a better default that won't use so much 
space.

Also, I have a felling the layout will be kind of odd right now. You can try 
adding -Wpadding to the clang-doc build to see if there's a better layout for 
these internal types.

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


[clang-tools-extra] [llvm] [clang-doc] Adds a mustache backend (PR #133161)

2025-03-27 Thread Paul Kirth via cfe-commits


@@ -379,7 +394,7 @@ struct RecordInfo : public SymbolInfo {
   // Full qualified name of this record, including namespaces and template
   // specializations.
   SmallString<16> FullName;
-
+  

ilovepi wrote:

nit: empty space. the newline is fine though.

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


[clang-tools-extra] [llvm] [clang-doc] Adds a mustache backend (PR #133161)

2025-03-27 Thread Paul Kirth via cfe-commits


@@ -0,0 +1,523 @@
+//===-- HTMLMustacheGenerator.cpp - HTML Mustache Generator -*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+#include "Generators.h"
+#include "Representation.h"
+#include "FileHelpersClangDoc.h"
+#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/Mustache.h"
+
+using namespace llvm;
+using namespace llvm::json;
+using namespace llvm::mustache;
+
+namespace clang {
+namespace doc {
+
+
+class MustacheHTMLGenerator : public Generator {
+public:
+  static const char *Format;
+  llvm::Error generateDocs(StringRef RootDir,
+   llvm::StringMap> Infos,
+   const ClangDocContext &CDCtx) override;
+  llvm::Error createResources(ClangDocContext &CDCtx) override;
+  llvm::Error generateDocForInfo(Info *I, llvm::raw_ostream &OS,
+ const ClangDocContext &CDCtx) override;
+  
+};
+
+class MustacheTemplateFile : public Template {
+public:
+  static ErrorOr> createMustacheFile
+  (StringRef FileName) {
+ErrorOr> BufferOrError =
+MemoryBuffer::getFile(FileName);
+
+if (auto EC = BufferOrError.getError()) {
+  return EC;
+}
+std::unique_ptr Buffer = 
std::move(BufferOrError.get());
+llvm::StringRef FileContent = Buffer->getBuffer();
+return std::make_unique(FileContent);
+  }
+  
+  Error registerPartialFile(StringRef Name, StringRef FileName) {
+ErrorOr> BufferOrError =
+MemoryBuffer::getFile(FileName);
+if (auto EC = BufferOrError.getError())
+  return llvm::createFileError("cannot open file", EC);
+std::unique_ptr Buffer = 
std::move(BufferOrError.get());
+llvm::StringRef FileContent = Buffer->getBuffer();
+registerPartial(Name, FileContent);
+return llvm::Error::success();
+  }
+
+  MustacheTemplateFile(StringRef TemplateStr) : Template(TemplateStr) {}
+};
+
+static std::unique_ptr NamespaceTemplate = nullptr;
+
+static std::unique_ptr RecordTemplate = nullptr;
+
+
+llvm::Error setupTemplate(
+std::unique_ptr &Template,
+StringRef TemplatePath,
+std::vector> Partials) {
+  auto T = MustacheTemplateFile::createMustacheFile(TemplatePath);
+  if (auto EC = T.getError())
+return llvm::createFileError("cannot open file", EC);
+  Template = std::move(T.get());
+  for (const auto &P : Partials) {
+auto Err = Template->registerPartialFile(P.first, P.second);
+if (Err)
+  return Err;
+  }
+  return llvm::Error::success();
+}
+
+llvm::Error 
+setupTemplateFiles(const clang::doc::ClangDocContext &CDCtx) {
+  auto NamespaceFilePath = 
CDCtx.MustacheTemplates.lookup("namespace-template");
+  auto ClassFilePath = CDCtx.MustacheTemplates.lookup("class-template");
+  auto CommentFilePath = CDCtx.MustacheTemplates.lookup("comments-template");
+  auto FunctionFilePath = CDCtx.MustacheTemplates.lookup("function-template");
+  auto EnumFilePath = CDCtx.MustacheTemplates.lookup("enum-template");
+  std::vector> Partials = {
+  {"Comments", CommentFilePath},
+  {"FunctionPartial", FunctionFilePath},
+  {"EnumPartial", EnumFilePath}
+  };
+  
+  auto Err = setupTemplate(NamespaceTemplate, NamespaceFilePath, Partials);
+  if (Err)
+return Err;
+  
+  Err = setupTemplate(RecordTemplate, ClassFilePath, Partials);
+  
+  if (Err)
+return Err;
+  
+  return llvm::Error::success();
+}
+
+
+llvm::Error 
+MustacheHTMLGenerator::generateDocs(llvm::StringRef RootDir, 
+
llvm::StringMap> Infos, 
+const clang::doc::ClangDocContext &CDCtx) {
+  if (auto Err = setupTemplateFiles(CDCtx))
+return Err;
+  // Track which directories we already tried to create.
+  llvm::StringSet<> CreatedDirs;
+  // Collect all output by file name and create the necessary directories.
+  llvm::StringMap> FileToInfos;
+  for (const auto &Group : Infos) {
+doc::Info *Info = Group.getValue().get();
+
+llvm::SmallString<128> Path;
+llvm::sys::path::native(RootDir, Path);
+llvm::sys::path::append(Path, Info->getRelativeFilePath(""));
+if (!CreatedDirs.contains(Path)) {
+  if (std::error_code Err = llvm::sys::fs::create_directories(Path);
+  Err != std::error_code())
+return llvm::createStringError(Err, "Failed to create directory '%s'.",
+   Path.c_str());
+  CreatedDirs.insert(Path);
+}
+
+llvm::sys::path::append(Path, Info->getFileBaseName() + ".html");
+FileToInfos[Path].push_back(Info);
+  }
+  
+  for (const auto &Group : FileToInfos) {
+std::error_code FileErr;
+llvm::raw_fd_ostream InfoOS(Group.getKey(), FileErr,
+llvm::sys::fs::OF_None);
+if (Fi

[clang-tools-extra] [llvm] [clang-doc] Adds a mustache backend (PR #133161)

2025-03-27 Thread Paul Kirth via cfe-commits


@@ -32,6 +33,183 @@ populateParentNamespaces(llvm::SmallVector 
&Namespaces,
 
 static void populateMemberTypeInfo(MemberTypeInfo &I, const FieldDecl *D);
 
+void getTemplateParameters(const TemplateParameterList *TemplateParams, 
+   llvm::raw_ostream &Stream) {
+  Stream << "template <";
+  
+  for (unsigned i = 0; i < TemplateParams->size(); ++i) {
+if (i > 0) {
+  Stream << ", ";
+}
+
+const NamedDecl *Param = TemplateParams->getParam(i);
+if (const auto *TTP = llvm::dyn_cast(Param)) {
+  if (TTP->wasDeclaredWithTypename()) {
+Stream << "typename";
+  } else {
+Stream << "class";
+  }
+  if (TTP->isParameterPack()) {
+Stream << "...";
+  }
+  Stream << " " << TTP->getNameAsString();
+} else if (const auto *NTTP = 
llvm::dyn_cast(Param)) {
+  NTTP->getType().print(Stream, NTTP->getASTContext().getPrintingPolicy());
+  if (NTTP->isParameterPack()) {
+Stream << "...";
+  }
+  Stream << " " << NTTP->getNameAsString();
+} else if (const auto *TTPD = 
llvm::dyn_cast(Param)) {
+  Stream << "template <";
+  getTemplateParameters(TTPD->getTemplateParameters(), Stream);
+  Stream << "> class " << TTPD->getNameAsString();
+}
+  }
+
+  Stream << "> ";
+}
+
+// Extract the full function prototype from a FunctionDecl including 
+// Full Decl
+llvm::SmallString<256> getFunctionPrototype(const FunctionDecl *FuncDecl) {
+  llvm::SmallString<256> Result; 
+  llvm::raw_svector_ostream Stream(Result);
+  const ASTContext& Ctx = FuncDecl->getASTContext();
+  const auto *Method = llvm::dyn_cast(FuncDecl);
+  // If it's a templated function, handle the template parameters
+  if (const auto *TmplDecl = FuncDecl->getDescribedTemplate()) {
+getTemplateParameters(TmplDecl->getTemplateParameters(), Stream);
+  }
+  // If it's a virtual method
+  if (Method) {
+if (Method->isVirtual())
+{
+  Stream << "virtual ";
+}
+  }
+  // Print return type
+  FuncDecl->getReturnType().print(Stream, Ctx.getPrintingPolicy());
+
+  // Print function name
+  Stream << " " << FuncDecl->getNameAsString() << "(";
+
+  // Print parameter list with types, names, and default values
+  for (unsigned I = 0; I < FuncDecl->getNumParams(); ++I) {
+if (I > 0) {
+  Stream << ", ";
+}
+const ParmVarDecl *ParamDecl = FuncDecl->getParamDecl(I);
+QualType ParamType = ParamDecl->getType();
+ParamType.print(Stream, Ctx.getPrintingPolicy());
+
+// Print parameter name if it has one
+if (!ParamDecl->getName().empty()) {
+  Stream << " " << ParamDecl->getNameAsString();
+}
+
+// Print default argument if it exists
+if (ParamDecl->hasDefaultArg()) {
+  const Expr *DefaultArg = ParamDecl->getDefaultArg();
+  if (DefaultArg) {
+Stream << " = ";
+DefaultArg->printPretty(Stream, nullptr, Ctx.getPrintingPolicy());
+  }

ilovepi wrote:

DefaultArg only gets used in the conditional. you can use

```
if(const Expr* DefaultArg = ...){ ... }
```

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


[clang-tools-extra] [llvm] [clang-doc] Adds a mustache backend (PR #133161)

2025-03-27 Thread Paul Kirth via cfe-commits

https://github.com/ilovepi commented:

I know you're planing to split this up, but here's some preliminary feedback.

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


[clang-tools-extra] [llvm] [clang-doc] Adds a mustache backend (PR #133161)

2025-03-27 Thread Paul Kirth via cfe-commits


@@ -152,7 +153,9 @@ struct ScopeChildren {
 
 // A base struct for TypeInfos
 struct TypeInfo {
+  

ilovepi wrote:

unnecessary

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


[clang] [HIP] use offload wrapper for non-device-only non-rdc (PR #132869)

2025-03-27 Thread Yaxun Liu via cfe-commits

https://github.com/yxsamliu updated 
https://github.com/llvm/llvm-project/pull/132869

>From 987007b668991ab8027a569f2aaafb5237dfc194 Mon Sep 17 00:00:00 2001
From: "Yaxun (Sam) Liu" 
Date: Fri, 21 Mar 2025 14:16:44 -0400
Subject: [PATCH] [HIP] use offload wrapper for non-device-only non-rdc

Currently HIP still uses offload bundler for non-rdc mode for
the new offload driver.

This patch switches to use offload wrapper for non-device-only
non-rdc mode when new offload driver is enabled.

This makes the rdc and non-rdc compilation more consistent
and speeds up compilation since the offload wrapper supports
parallel compilation for different GPU arch's.

It is implemented by adding a linker wrapper action for
each assemble action of input file. Linker wrapper action
differentiates this special type of work vs normal
linker wrapper work by the fle type. This type of work
results in object instead of image. The linker wrapper
adds "-r" for it and only includes the object file
as input, not the host libraries.

For device-only non-RDC mode, the new driver keeps the
original behavior.
---
 clang/lib/CodeGen/CGCUDANV.cpp |  3 +-
 clang/lib/Driver/Driver.cpp| 60 +++-
 clang/lib/Driver/ToolChains/Clang.cpp  | 19 +++--
 clang/test/Driver/hip-binding.hip  |  6 +-
 clang/test/Driver/hip-phases.hip   | 51 --
 clang/test/Driver/hip-toolchain-no-rdc.hip | 81 +-
 6 files changed, 143 insertions(+), 77 deletions(-)

diff --git a/clang/lib/CodeGen/CGCUDANV.cpp b/clang/lib/CodeGen/CGCUDANV.cpp
index 5445a9278596d..395263331d141 100644
--- a/clang/lib/CodeGen/CGCUDANV.cpp
+++ b/clang/lib/CodeGen/CGCUDANV.cpp
@@ -1281,7 +1281,8 @@ llvm::Function *CGNVCUDARuntime::finalizeModule() {
 return nullptr;
   }
   if (CGM.getLangOpts().OffloadViaLLVM ||
-  (CGM.getLangOpts().OffloadingNewDriver && RelocatableDeviceCode))
+  (CGM.getLangOpts().OffloadingNewDriver &&
+   (CGM.getLangOpts().HIP || RelocatableDeviceCode)))
 createOffloadingEntries();
   else
 return makeModuleCtorFunction();
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 07e36ea2efba4..dd4ad2d644378 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -4405,6 +4405,10 @@ void Driver::BuildActions(Compilation &C, DerivedArgList 
&Args,
options::OPT_no_offload_new_driver,
C.isOffloadingHostKind(Action::OFK_Cuda));
 
+  bool HIPNoRDC =
+  C.isOffloadingHostKind(Action::OFK_HIP) &&
+  !Args.hasFlag(options::OPT_fgpu_rdc, options::OPT_fno_gpu_rdc, false);
+
   // Builder to be used to build offloading actions.
   std::unique_ptr OffloadBuilder =
   !UseNewOffloadingDriver
@@ -4538,7 +4542,7 @@ void Driver::BuildActions(Compilation &C, DerivedArgList 
&Args,
 // Check if this Linker Job should emit a static library.
 if (ShouldEmitStaticLibrary(Args)) {
   LA = C.MakeAction(LinkerInputs, types::TY_Image);
-} else if (UseNewOffloadingDriver ||
+} else if ((UseNewOffloadingDriver && !HIPNoRDC) ||
Args.hasArg(options::OPT_offload_link)) {
   LA = C.MakeAction(LinkerInputs, types::TY_Image);
   LA->propagateHostOffloadInfo(C.getActiveOffloadKinds(),
@@ -4849,10 +4853,28 @@ Action *Driver::BuildOffloadingActions(Compilation &C,
const InputTy &Input, StringRef CUID,
Action *HostAction) const {
   // Don't build offloading actions if explicitly disabled or we do not have a
-  // valid source input and compile action to embed it in. If preprocessing 
only
-  // ignore embedding.
-  if (offloadHostOnly() || !types::isSrcFile(Input.first) ||
-  !(isa(HostAction) ||
+  // valid source input.
+  if (offloadHostOnly() || !types::isSrcFile(Input.first))
+return HostAction;
+
+  bool HIPNoRDC =
+  C.isOffloadingHostKind(Action::OFK_HIP) &&
+  !Args.hasFlag(options::OPT_fgpu_rdc, options::OPT_fno_gpu_rdc, false);
+
+  // For HIP non-rdc non-device-only compilation, create a linker wrapper
+  // action for each host object to link, bundle and wrap device files in
+  // it.
+  if (isa(HostAction) && HIPNoRDC && !offloadDeviceOnly()) {
+ActionList AL{HostAction};
+HostAction = C.MakeAction(AL, types::TY_Object);
+HostAction->propagateHostOffloadInfo(C.getActiveOffloadKinds(),
+ /*BoundArch=*/nullptr);
+return HostAction;
+  }
+
+  // Don't build offloading actions if we do not have a compile action. If
+  // preprocessing only ignore embedding.
+  if (!(isa(HostAction) ||
 getFinalPhase(Args) == phases::Preprocess))
 return HostAction;
 
@@ -4948,12 +4970,13 @@ Action *Driver::BuildOffloadingActions(Compilation &C,
   }
 }
 
-// Compiling HIP in non-RDC mode requires linking each action individually.
+// Compiling HIP in device-only non-RDC mode requires l

[clang-tools-extra] [llvm] [clang-doc] Adds a mustache backend (PR #133161)

2025-03-27 Thread Paul Kirth via cfe-commits


@@ -521,8 +540,9 @@ struct ClangDocContext {
   // Path of CSS stylesheets that will be copied to OutDirectory and used to
   // style all HTML files.
   std::vector UserStylesheets;
-  // JavaScript files that will be imported in all HTML files.

ilovepi wrote:

Is this no longer true? there should probably sill be a comment here.

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


[clang-tools-extra] [llvm] [clang-doc] Adds a mustache backend (PR #133161)

2025-03-27 Thread Paul Kirth via cfe-commits


@@ -412,12 +427,15 @@ struct TypedefInfo : public SymbolInfo {
   void merge(TypedefInfo &&I);
 
   TypeInfo Underlying;
-
-  // Inidicates if this is a new C++ "using"-style typedef:
+  // Underlying type declaration
+  SmallString<16> TypeDeclaration;
+  // Indicates if this is a new C++ "using"-style typedef:

ilovepi wrote:

Let's use consistent spacing. If you find the file is already inconsistent, 
then lets make a PR to fix that first.

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


[clang] [AMDGPU][True16][Clang] support true16 target feature in clang driver (PR #133298)

2025-03-27 Thread Brox Chen via cfe-commits

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


[clang-tools-extra] [llvm] [clang-doc] Adds a mustache backend (PR #133161)

2025-03-27 Thread Paul Kirth via cfe-commits


@@ -32,6 +33,183 @@ populateParentNamespaces(llvm::SmallVector 
&Namespaces,
 
 static void populateMemberTypeInfo(MemberTypeInfo &I, const FieldDecl *D);
 
+void getTemplateParameters(const TemplateParameterList *TemplateParams, 
+   llvm::raw_ostream &Stream) {
+  Stream << "template <";
+  
+  for (unsigned i = 0; i < TemplateParams->size(); ++i) {
+if (i > 0) {
+  Stream << ", ";
+}
+
+const NamedDecl *Param = TemplateParams->getParam(i);
+if (const auto *TTP = llvm::dyn_cast(Param)) {
+  if (TTP->wasDeclaredWithTypename()) {
+Stream << "typename";
+  } else {
+Stream << "class";
+  }
+  if (TTP->isParameterPack()) {
+Stream << "...";
+  }
+  Stream << " " << TTP->getNameAsString();
+} else if (const auto *NTTP = 
llvm::dyn_cast(Param)) {
+  NTTP->getType().print(Stream, NTTP->getASTContext().getPrintingPolicy());
+  if (NTTP->isParameterPack()) {
+Stream << "...";
+  }
+  Stream << " " << NTTP->getNameAsString();
+} else if (const auto *TTPD = 
llvm::dyn_cast(Param)) {
+  Stream << "template <";
+  getTemplateParameters(TTPD->getTemplateParameters(), Stream);
+  Stream << "> class " << TTPD->getNameAsString();
+}
+  }
+
+  Stream << "> ";
+}
+
+// Extract the full function prototype from a FunctionDecl including 
+// Full Decl
+llvm::SmallString<256> getFunctionPrototype(const FunctionDecl *FuncDecl) {
+  llvm::SmallString<256> Result; 
+  llvm::raw_svector_ostream Stream(Result);
+  const ASTContext& Ctx = FuncDecl->getASTContext();
+  const auto *Method = llvm::dyn_cast(FuncDecl);
+  // If it's a templated function, handle the template parameters
+  if (const auto *TmplDecl = FuncDecl->getDescribedTemplate()) {
+getTemplateParameters(TmplDecl->getTemplateParameters(), Stream);
+  }
+  // If it's a virtual method
+  if (Method) {
+if (Method->isVirtual())
+{
+  Stream << "virtual ";
+}
+  }

ilovepi wrote:

```suggestion
  if (Method && Method->isVirtual()){
  Stream << "virtual ";
  }
```

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


[clang-tools-extra] [llvm] [clang-doc] Adds a mustache backend (PR #133161)

2025-03-27 Thread Paul Kirth via cfe-commits


@@ -0,0 +1,26 @@
+//===-- FileHelpersClangDoc.h --- File Helpers ---*- 
C++-*-===//

ilovepi wrote:

probably putting this in `clang-doc/support/File.h` is a bit more typical. At 
the least the file shouldn't have helper in the name, and probably doesn't need 
ClangDoc in it either.

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


[clang] [HIP] use offload wrapper for non-device-only non-rdc (PR #132869)

2025-03-27 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 8244f8210f2e62f68429a0daf104fd483ada45ab 
987007b668991ab8027a569f2aaafb5237dfc194 --extensions cpp -- 
clang/lib/CodeGen/CGCUDANV.cpp clang/lib/Driver/Driver.cpp 
clang/lib/Driver/ToolChains/Clang.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index dd4ad2d644..90d8e823d1 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -4975,8 +4975,7 @@ Action *Driver::BuildOffloadingActions(Compilation &C,
 for (Action *&A : DeviceActions) {
   if ((A->getType() != types::TY_Object &&
A->getType() != types::TY_LTO_BC) ||
-  !HIPNoRDC ||
-  !offloadDeviceOnly())
+  !HIPNoRDC || !offloadDeviceOnly())
 continue;
   ActionList LinkerInput = {A};
   A = C.MakeAction(LinkerInput, types::TY_Image);

``




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


[clang] [Clang][CodeGen] Do not set inbounds flag for struct GEP with null base pointers (PR #130734)

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


@@ -64,21 +64,27 @@ class CGBuilderTy : public CGBuilderBaseTy {
   Address createConstGEP2_32(Address Addr, unsigned Idx0, unsigned Idx1,
  const llvm::Twine &Name) {
 const llvm::DataLayout &DL = BB->getDataLayout();
-llvm::GetElementPtrInst *GEP;
+llvm::Value *V;
 if (IsInBounds)
-  GEP = cast(CreateConstInBoundsGEP2_32(
-  Addr.getElementType(), emitRawPointerFromAddress(Addr), Idx0, Idx1,
-  Name));
+  V = CreateConstInBoundsGEP2_32(Addr.getElementType(),
+ emitRawPointerFromAddress(Addr), Idx0,
+ Idx1, Name);
 else
-  GEP = cast(CreateConstGEP2_32(
-  Addr.getElementType(), emitRawPointerFromAddress(Addr), Idx0, Idx1,
-  Name));
+  V = CreateConstGEP2_32(Addr.getElementType(),
+ emitRawPointerFromAddress(Addr), Idx0, Idx1, 
Name);
 llvm::APInt Offset(
 DL.getIndexSizeInBits(Addr.getType()->getPointerAddressSpace()), 0,
 /*isSigned=*/true);
-if (!GEP->accumulateConstantOffset(DL, Offset))
-  llvm_unreachable("offset of GEP with constants is always computable");
-return Address(GEP, GEP->getResultElementType(),
+llvm::Type *ElementTy = nullptr;
+if (auto *GEP = dyn_cast(V)) {
+  if (!GEP->accumulateConstantOffset(DL, Offset))
+llvm_unreachable("offset of GEP with constants is always computable");

efriedma-quic wrote:

If constant-folding is triggering, I don't think the "accumulateConstantOffset" 
is guaranteed to succeed?  GEP is not necessarily the one we just created; it 
could be some existing GEP, or created by folding together two GEPs.

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


[clang] [Clang,debuginfo] added vtt parameter in destructor DISubroutineType (PR #130674)

2025-03-27 Thread Reid Kleckner via cfe-commits
Markus =?utf-8?q?Gschoßmann?= ,
Markus =?utf-8?q?Gschoßmann?= 
Message-ID:
In-Reply-To: 



@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -triple x86_64-none-linux-gnu -emit-llvm 
-debug-info-kind=limited %s -o - | FileCheck %s

rnk wrote:

Please add a test for the MSVC ABI, since I don't think it has VTT parameters, 
and I'm not sure the code you added does the right thing.

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


[clang] [WebKit Checkers] Recognize Objective-C and CF pointer conversion functions. (PR #132784)

2025-03-27 Thread Ryosuke Niwa via cfe-commits

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


[clang] Fix the assertion failure in Analysis/Checkers/WebKit/forward-decl-checker.mm after https://github.com/llvm/llvm-project/pull/132784. (PR #133341)

2025-03-27 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Ryosuke Niwa (rniwa)


Changes



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


1 Files Affected:

- (modified) clang/lib/StaticAnalyzer/Checkers/WebKit/ForwardDeclChecker.cpp 
(+2-1) 


``diff
diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/ForwardDeclChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/ForwardDeclChecker.cpp
index 291eb140d3202..a524593b0119b 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/ForwardDeclChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/ForwardDeclChecker.cpp
@@ -231,7 +231,8 @@ class ForwardDeclChecker : public 
Checker> {
 if (BR->getSourceManager().isInSystemHeader(E->getExprLoc()))
   return;
 
-if (auto *Receiver = E->getInstanceReceiver()->IgnoreParenCasts()) {
+if (auto *Receiver = E->getInstanceReceiver()) {
+  Receiver = Receiver->IgnoreParenCasts();
   if (isUnknownType(E->getReceiverType()))
 reportUnknownRecieverType(Receiver, DeclWithIssue);
 }

``




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


[clang] [WebKit Checkers] Recognize Objective-C and CF pointer conversion functions. (PR #132784)

2025-03-27 Thread Ryosuke Niwa via cfe-commits

rniwa wrote:

Oops, fixing this in https://github.com/llvm/llvm-project/pull/133341.

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


[clang] Fix the assertion failure in Analysis/Checkers/WebKit/forward-decl-checker.mm after https://github.com/llvm/llvm-project/pull/132784. (PR #133341)

2025-03-27 Thread Ryosuke Niwa via cfe-commits

https://github.com/rniwa created 
https://github.com/llvm/llvm-project/pull/133341

None

>From 13115c0d14953c01dba10c4fbb38e149acce6c34 Mon Sep 17 00:00:00 2001
From: Ryosuke Niwa 
Date: Thu, 27 Mar 2025 16:24:23 -0700
Subject: [PATCH] Fix the assertion failure in
 Analysis/Checkers/WebKit/forward-decl-checker.mm after
 https://github.com/llvm/llvm-project/pull/132784.

---
 .../lib/StaticAnalyzer/Checkers/WebKit/ForwardDeclChecker.cpp  | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/ForwardDeclChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/ForwardDeclChecker.cpp
index 291eb140d3202..a524593b0119b 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/ForwardDeclChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/ForwardDeclChecker.cpp
@@ -231,7 +231,8 @@ class ForwardDeclChecker : public 
Checker> {
 if (BR->getSourceManager().isInSystemHeader(E->getExprLoc()))
   return;
 
-if (auto *Receiver = E->getInstanceReceiver()->IgnoreParenCasts()) {
+if (auto *Receiver = E->getInstanceReceiver()) {
+  Receiver = Receiver->IgnoreParenCasts();
   if (isUnknownType(E->getReceiverType()))
 reportUnknownRecieverType(Receiver, DeclWithIssue);
 }

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


[clang] [clang] fix structural comparison dependent class member pointer (PR #133343)

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

https://github.com/mizvekov created 
https://github.com/llvm/llvm-project/pull/133343

Fixes a regression introduced in 
https://github.com/llvm/llvm-project/pull/130537 and reported here 
https://github.com/llvm/llvm-project/issues/133144

This fixes a crash in ASTStructuralEquivalence where the non-null precondition 
for IsStructurallyEquivalent would be violated, when comparing member pointers 
with a dependent class.

This also drive-by fixes the ast node traverser for member pointers so it 
doesn't traverse into the qualifier in case it's not a type, or the class 
declaration in case there is none.

This avoids printing of `<<>>` on the text node dumper, which is 
redundant.

No release notes since the regression was never released.

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

>From b679b6ef64e682808e7751eeba694e7a2f3e00f8 Mon Sep 17 00:00:00 2001
From: Matheus Izvekov 
Date: Thu, 27 Mar 2025 20:09:07 -0300
Subject: [PATCH] [clang] fix structural comparison dependent class member
 pointer

Fixes a regression introduced in 
https://github.com/llvm/llvm-project/pull/130537
and reported here https://github.com/llvm/llvm-project/issues/133144

This fixes a crash in ASTStructuralEquivalence where
the non-null precondition for IsStructurallyEquivalent
would be violated, when comparing member pointers with a dependent
class.

This also drive-by fixes the ast node traverser for member pointers
so it doesn't traverse into the qualifier in case it's not a type,
or the class declaration in case there is none.

This avoids printing of `<<>>` on the text node dumper,
which is redundant.

No release notes since the regression was never released.

Fixes https://github.com/llvm/llvm-project/issues/133144
---
 clang/include/clang/AST/ASTNodeTraverser.h|   9 +-
 clang/lib/AST/ASTStructuralEquivalence.cpp|   8 +-
 ...dump-template-json-win32-mangler-crash.cpp |   3 -
 clang/test/AST/ast-dump-templates.cpp | 375 +-
 clang/test/AST/ast-dump-types-json.cpp| 304 --
 5 files changed, 381 insertions(+), 318 deletions(-)

diff --git a/clang/include/clang/AST/ASTNodeTraverser.h 
b/clang/include/clang/AST/ASTNodeTraverser.h
index f557555e96e59..83a6b77704f34 100644
--- a/clang/include/clang/AST/ASTNodeTraverser.h
+++ b/clang/include/clang/AST/ASTNodeTraverser.h
@@ -394,8 +394,13 @@ class ASTNodeTraverser
   }
   void VisitMemberPointerType(const MemberPointerType *T) {
 // FIXME: Provide a NestedNameSpecifier visitor.
-Visit(T->getQualifier()->getAsType());
-Visit(T->getMostRecentCXXRecordDecl());
+NestedNameSpecifier *Qualifier = T->getQualifier();
+if (NestedNameSpecifier::SpecifierKind K = Qualifier->getKind();
+K == NestedNameSpecifier::TypeSpec ||
+K == NestedNameSpecifier::TypeSpecWithTemplate)
+  Visit(Qualifier->getAsType());
+if (T->isSugared())
+  Visit(T->getMostRecentCXXRecordDecl()->getTypeForDecl());
 Visit(T->getPointeeType());
   }
   void VisitArrayType(const ArrayType *T) { Visit(T->getElementType()); }
diff --git a/clang/lib/AST/ASTStructuralEquivalence.cpp 
b/clang/lib/AST/ASTStructuralEquivalence.cpp
index 2c2c8fd677500..a4349bdaaf682 100644
--- a/clang/lib/AST/ASTStructuralEquivalence.cpp
+++ b/clang/lib/AST/ASTStructuralEquivalence.cpp
@@ -897,9 +897,11 @@ static bool 
IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
 if (!IsStructurallyEquivalent(Context, MemPtr1->getQualifier(),
   MemPtr2->getQualifier()))
   return false;
-if (!IsStructurallyEquivalent(Context,
-  MemPtr1->getMostRecentCXXRecordDecl(),
-  MemPtr2->getMostRecentCXXRecordDecl()))
+CXXRecordDecl *D1 = MemPtr1->getMostRecentCXXRecordDecl(),
+  *D2 = MemPtr2->getMostRecentCXXRecordDecl();
+if (D1 == D2)
+  break;
+if (!D1 || !D2 || !IsStructurallyEquivalent(Context, D1, D2))
   return false;
 break;
   }
diff --git a/clang/test/AST/ast-dump-template-json-win32-mangler-crash.cpp 
b/clang/test/AST/ast-dump-template-json-win32-mangler-crash.cpp
index 9f0d3efb6277e..b80c1e1d77140 100644
--- a/clang/test/AST/ast-dump-template-json-win32-mangler-crash.cpp
+++ b/clang/test/AST/ast-dump-template-json-win32-mangler-crash.cpp
@@ -2452,9 +2452,6 @@ int main()
 // CHECK-NEXT:  }
 // CHECK-NEXT: },
 // CHECK-NEXT: {
-// CHECK-NEXT:  "id": "0x0"
-// CHECK-NEXT: },
-// CHECK-NEXT: {
 // CHECK-NEXT:  "id": "0x{{.*}}",
 // CHECK-NEXT:  "kind": "TemplateTypeParmType",
 // CHECK-NEXT:  "type": {
diff --git a/clang/test/AST/ast-dump-templates.cpp 
b/clang/test/AST/ast-dump-templates.cpp
index 0e0fa73871bb7..79572f5103bde 100644
--- a/clang/test/AST/ast-dump-templates.cpp
+++ b/clang/test/AST/ast-dump-templates.cpp
@@ -154,10 +154,30 @@ namespace TestMemberPointerPartialSpec {
 // DUMP-NEXT:  |-TemplateArgument ty

[clang] [clang] fix structural comparison for dependent class member pointer (PR #133343)

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

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


[clang] [clang] fix structural comparison for dependent class member pointer (PR #133343)

2025-03-27 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Matheus Izvekov (mizvekov)


Changes

Fixes a regression introduced in 
https://github.com/llvm/llvm-project/pull/130537 and reported here 
https://github.com/llvm/llvm-project/issues/133144

This fixes a crash in ASTStructuralEquivalence where the non-null precondition 
for IsStructurallyEquivalent would be violated, when comparing member pointers 
with a dependent class.

This also drive-by fixes the ast node traverser for member pointers so it 
doesn't traverse into the qualifier in case it's not a type, or the class 
declaration in case there is none.

This avoids printing of `<<>>` on the text node dumper, 
which is redundant.

No release notes since the regression was never released.

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

---

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


5 Files Affected:

- (modified) clang/include/clang/AST/ASTNodeTraverser.h (+7-2) 
- (modified) clang/lib/AST/ASTStructuralEquivalence.cpp (+5-3) 
- (modified) clang/test/AST/ast-dump-template-json-win32-mangler-crash.cpp (-3) 
- (modified) clang/test/AST/ast-dump-templates.cpp (+369-6) 
- (modified) clang/test/AST/ast-dump-types-json.cpp (-304) 


``diff
diff --git a/clang/include/clang/AST/ASTNodeTraverser.h 
b/clang/include/clang/AST/ASTNodeTraverser.h
index f557555e96e59..83a6b77704f34 100644
--- a/clang/include/clang/AST/ASTNodeTraverser.h
+++ b/clang/include/clang/AST/ASTNodeTraverser.h
@@ -394,8 +394,13 @@ class ASTNodeTraverser
   }
   void VisitMemberPointerType(const MemberPointerType *T) {
 // FIXME: Provide a NestedNameSpecifier visitor.
-Visit(T->getQualifier()->getAsType());
-Visit(T->getMostRecentCXXRecordDecl());
+NestedNameSpecifier *Qualifier = T->getQualifier();
+if (NestedNameSpecifier::SpecifierKind K = Qualifier->getKind();
+K == NestedNameSpecifier::TypeSpec ||
+K == NestedNameSpecifier::TypeSpecWithTemplate)
+  Visit(Qualifier->getAsType());
+if (T->isSugared())
+  Visit(T->getMostRecentCXXRecordDecl()->getTypeForDecl());
 Visit(T->getPointeeType());
   }
   void VisitArrayType(const ArrayType *T) { Visit(T->getElementType()); }
diff --git a/clang/lib/AST/ASTStructuralEquivalence.cpp 
b/clang/lib/AST/ASTStructuralEquivalence.cpp
index 2c2c8fd677500..a4349bdaaf682 100644
--- a/clang/lib/AST/ASTStructuralEquivalence.cpp
+++ b/clang/lib/AST/ASTStructuralEquivalence.cpp
@@ -897,9 +897,11 @@ static bool 
IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
 if (!IsStructurallyEquivalent(Context, MemPtr1->getQualifier(),
   MemPtr2->getQualifier()))
   return false;
-if (!IsStructurallyEquivalent(Context,
-  MemPtr1->getMostRecentCXXRecordDecl(),
-  MemPtr2->getMostRecentCXXRecordDecl()))
+CXXRecordDecl *D1 = MemPtr1->getMostRecentCXXRecordDecl(),
+  *D2 = MemPtr2->getMostRecentCXXRecordDecl();
+if (D1 == D2)
+  break;
+if (!D1 || !D2 || !IsStructurallyEquivalent(Context, D1, D2))
   return false;
 break;
   }
diff --git a/clang/test/AST/ast-dump-template-json-win32-mangler-crash.cpp 
b/clang/test/AST/ast-dump-template-json-win32-mangler-crash.cpp
index 9f0d3efb6277e..b80c1e1d77140 100644
--- a/clang/test/AST/ast-dump-template-json-win32-mangler-crash.cpp
+++ b/clang/test/AST/ast-dump-template-json-win32-mangler-crash.cpp
@@ -2452,9 +2452,6 @@ int main()
 // CHECK-NEXT:  }
 // CHECK-NEXT: },
 // CHECK-NEXT: {
-// CHECK-NEXT:  "id": "0x0"
-// CHECK-NEXT: },
-// CHECK-NEXT: {
 // CHECK-NEXT:  "id": "0x{{.*}}",
 // CHECK-NEXT:  "kind": "TemplateTypeParmType",
 // CHECK-NEXT:  "type": {
diff --git a/clang/test/AST/ast-dump-templates.cpp 
b/clang/test/AST/ast-dump-templates.cpp
index 0e0fa73871bb7..79572f5103bde 100644
--- a/clang/test/AST/ast-dump-templates.cpp
+++ b/clang/test/AST/ast-dump-templates.cpp
@@ -154,10 +154,30 @@ namespace TestMemberPointerPartialSpec {
 // DUMP-NEXT:  |-TemplateArgument type 'type-parameter-0-0 
type-parameter-0-1::*'
 // DUMP-NEXT:  | `-MemberPointerType {{.+}} 'type-parameter-0-0 
type-parameter-0-1::*' dependent
 // DUMP-NEXT:  |   |-TemplateTypeParmType {{.+}} 'type-parameter-0-1' 
dependent depth 0 index 1
-// DUMP-NEXT:  |   |-<<>>
 // DUMP-NEXT:  |   `-TemplateTypeParmType {{.+}} 'type-parameter-0-0' 
dependent depth 0 index 0
 } // namespace TestMemberPointerPartialSpec
 
+namespace TestDependentMemberPointer {
+  template  struct A {
+using X = int U::*;
+using Y = int U::test::*;
+using Z = int U::template V::*;
+  };
+// DUMP-LABEL: NamespaceDecl {{.+}} TestDependentMemberPointer{{$}}
+// DUMP:   |-TypeAliasDecl {{.+}} X 'int U::*'{{$}}
+// DUMP-NEXT:  | `-MemberPointerType {{.+}} 'int U::*' dependent
+// DUMP-NEXT:  |   |

[clang] [AMDGPU] Remove detection of hip runtime for Spack (PR #133263)

2025-03-27 Thread Harmen Stoppels via cfe-commits

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


[clang] [flang] [libcxx] [llvm] [llvm-reduce]: print short form, actionable names in the log (PR #132813)

2025-03-27 Thread Matt Arsenault via cfe-commits


@@ -164,24 +152,25 @@ static void runDeltaPassName(TestRunner &Tester, 
StringRef PassName) {
 
 void llvm::printDeltaPasses(raw_ostream &OS) {
   OS << "Delta passes (pass to `--delta-passes=` as a comma separated 
list):\n";
-#define DELTA_PASS(NAME, FUNC) OS << "  " << NAME << "\n";
   OS << " IR:\n";
-  DELTA_PASSES;
+  for (const DeltaPass &Pass : IR_Passes) {
+OS << "  " << Pass.Name  << "\n";
+  }
   OS << " MIR:\n";
-  DELTA_PASSES_MIR;
-#undef DELTA_PASS
+  for (const DeltaPass &Pass : MIR_Passes) {
+OS << "  " << Pass.Name  << "\n";

arsenm wrote:

```suggestion
OS << "  " << Pass.Name  << '\n';
```

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


[clang] [flang] [libcxx] [llvm] [llvm-reduce]: print short form, actionable names in the log (PR #132813)

2025-03-27 Thread Matt Arsenault via cfe-commits


@@ -832,11 +832,10 @@ std::unique_ptr ASTUnit::LoadFromASTFile(
   AST->ModCache = createCrossProcessModuleCache();
   AST->HSOpts = HSOpts ? HSOpts : std::make_shared();
   AST->HSOpts->ModuleFormat = 
std::string(PCHContainerRdr.getFormats().front());
-  AST->HeaderInfo.reset(new HeaderSearch(AST->getHeaderSearchOpts(),
- AST->getSourceManager(),
- AST->getDiagnostics(),
- AST->getLangOpts(),
- /*Target=*/nullptr));
+  AST->HeaderInfo.reset(
+  new HeaderSearch(AST->getHeaderSearchOpts(), AST->getSourceManager(),
+   AST->getDiagnostics(), AST->getLangOpts(),
+   /*Target=*/nullptr));

arsenm wrote:

Seems to have pulled in a lot of unrelated changes 

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


[clang] [flang] [libcxx] [llvm] [llvm-reduce]: print short form, actionable names in the log (PR #132813)

2025-03-27 Thread Matt Arsenault via cfe-commits


@@ -71,91 +73,77 @@ static cl::list
  "default, run all delta passes."),
 cl::cat(LLVMReduceOptions), cl::CommaSeparated);
 
-#define DELTA_PASSES   
\
-  do { 
\
-DELTA_PASS("strip-debug-info", stripDebugInfoDeltaPass)
\
-DELTA_PASS("functions", reduceFunctionsDeltaPass)  
\
-DELTA_PASS("function-bodies", reduceFunctionBodiesDeltaPass)   
\
-DELTA_PASS("special-globals", reduceSpecialGlobalsDeltaPass)   
\
-DELTA_PASS("aliases", reduceAliasesDeltaPass)  
\
-DELTA_PASS("ifuncs", reduceIFuncsDeltaPass)
\
-DELTA_PASS("simplify-conditionals-true", reduceConditionalsTrueDeltaPass)  
\
-DELTA_PASS("simplify-conditionals-false",  
\
-   reduceConditionalsFalseDeltaPass)   
\
-DELTA_PASS("invokes", reduceInvokesDeltaPass)  
\
-DELTA_PASS("unreachable-basic-blocks", 
\
-   reduceUnreachableBasicBlocksDeltaPass)  
\
-DELTA_PASS("basic-blocks", reduceBasicBlocksDeltaPass) 
\
-DELTA_PASS("simplify-cfg", reduceUsingSimplifyCFGDeltaPass)
\
-DELTA_PASS("function-data", reduceFunctionDataDeltaPass)   
\
-DELTA_PASS("global-values", reduceGlobalValuesDeltaPass)   
\
-DELTA_PASS("global-objects", reduceGlobalObjectsDeltaPass) 
\
-DELTA_PASS("global-initializers", reduceGlobalsInitializersDeltaPass)  
\
-DELTA_PASS("global-variables", reduceGlobalsDeltaPass) 
\
-DELTA_PASS("di-metadata", reduceDIMetadataDeltaPass)   
\
-DELTA_PASS("dbg-records", reduceDbgRecordDeltaPass)
\
-DELTA_PASS("distinct-metadata", reduceDistinctMetadataDeltaPass)   
\
-DELTA_PASS("metadata", reduceMetadataDeltaPass)
\
-DELTA_PASS("named-metadata", reduceNamedMetadataDeltaPass) 
\
-DELTA_PASS("arguments", reduceArgumentsDeltaPass)  
\
-DELTA_PASS("instructions", reduceInstructionsDeltaPass)
\
-DELTA_PASS("simplify-instructions", simplifyInstructionsDeltaPass) 
\
-DELTA_PASS("ir-passes", runIRPassesDeltaPass)  
\
-DELTA_PASS("operands-zero", reduceOperandsZeroDeltaPass)   
\
-DELTA_PASS("operands-one", reduceOperandsOneDeltaPass) 
\
-DELTA_PASS("operands-nan", reduceOperandsNaNDeltaPass) 
\
-DELTA_PASS("operands-to-args", reduceOperandsToArgsDeltaPass)  
\
-DELTA_PASS("operands-skip", reduceOperandsSkipDeltaPass)   
\
-DELTA_PASS("operand-bundles", reduceOperandBundesDeltaPass)
\
-DELTA_PASS("attributes", reduceAttributesDeltaPass)
\
-DELTA_PASS("module-data", reduceModuleDataDeltaPass)   
\
-DELTA_PASS("opcodes", reduceOpcodesDeltaPass)  
\
-DELTA_PASS("volatile", reduceVolatileInstructionsDeltaPass)
\
-DELTA_PASS("atomic-ordering", reduceAtomicOrderingDeltaPass)   
\
-DELTA_PASS("syncscopes", reduceAtomicSyncScopesDeltaPass)  
\
-DELTA_PASS("instruction-flags", reduceInstructionFlagsDeltaPass)   
\
-  } while (false)
-
-#define DELTA_PASSES_MIR   
\
-  do { 
\
-DELTA_PASS("instructions", reduceInstructionsMIRDeltaPass) 
\
-DELTA_PASS("ir-instruction-references",
\
-   reduceIRInstructionReferencesDeltaPass) 
\
-DELTA_PASS("ir-block-references", reduceIRBlockReferencesDeltaPass)
\
-DELTA_PASS("ir-function-references", reduceIRFunctionReferencesDeltaPass)  
\
-DELTA_PASS("instruction-flags", reduceInstructionFlagsMIRDeltaPass)
\
-DELTA_PASS("register-uses", reduceRegisterUsesMIRDeltaPass)
\
-DELTA_PASS("register-defs", reduceRegisterDefsMIRDeltaPass)
\
-DELTA_PASS("register-hints", reduceVirtualRegisterHintsDeltaPass)  
\
-DELTA_PASS("register-masks", reduceRegisterMasksMIRDeltaPass)  
\
-  } while (false)
+// Generate two separate Pass lists: IR_Passes and MIR_Passes
+static const DeltaPass IR_Passes[] = {
+  #undef DELTA_PASS_IR 
+  #undef DELTA_PASS_MIR 
+  #define DELTA_PASS_IR(NAME, FUNC, DESC) {NAME,

[clang] [flang] [libcxx] [llvm] [llvm-reduce]: print short form, actionable names in the log (PR #132813)

2025-03-27 Thread Matt Arsenault via cfe-commits


@@ -71,91 +73,77 @@ static cl::list
  "default, run all delta passes."),
 cl::cat(LLVMReduceOptions), cl::CommaSeparated);
 
-#define DELTA_PASSES   
\
-  do { 
\
-DELTA_PASS("strip-debug-info", stripDebugInfoDeltaPass)
\
-DELTA_PASS("functions", reduceFunctionsDeltaPass)  
\
-DELTA_PASS("function-bodies", reduceFunctionBodiesDeltaPass)   
\
-DELTA_PASS("special-globals", reduceSpecialGlobalsDeltaPass)   
\
-DELTA_PASS("aliases", reduceAliasesDeltaPass)  
\
-DELTA_PASS("ifuncs", reduceIFuncsDeltaPass)
\
-DELTA_PASS("simplify-conditionals-true", reduceConditionalsTrueDeltaPass)  
\
-DELTA_PASS("simplify-conditionals-false",  
\
-   reduceConditionalsFalseDeltaPass)   
\
-DELTA_PASS("invokes", reduceInvokesDeltaPass)  
\
-DELTA_PASS("unreachable-basic-blocks", 
\
-   reduceUnreachableBasicBlocksDeltaPass)  
\
-DELTA_PASS("basic-blocks", reduceBasicBlocksDeltaPass) 
\
-DELTA_PASS("simplify-cfg", reduceUsingSimplifyCFGDeltaPass)
\
-DELTA_PASS("function-data", reduceFunctionDataDeltaPass)   
\
-DELTA_PASS("global-values", reduceGlobalValuesDeltaPass)   
\
-DELTA_PASS("global-objects", reduceGlobalObjectsDeltaPass) 
\
-DELTA_PASS("global-initializers", reduceGlobalsInitializersDeltaPass)  
\
-DELTA_PASS("global-variables", reduceGlobalsDeltaPass) 
\
-DELTA_PASS("di-metadata", reduceDIMetadataDeltaPass)   
\
-DELTA_PASS("dbg-records", reduceDbgRecordDeltaPass)
\
-DELTA_PASS("distinct-metadata", reduceDistinctMetadataDeltaPass)   
\
-DELTA_PASS("metadata", reduceMetadataDeltaPass)
\
-DELTA_PASS("named-metadata", reduceNamedMetadataDeltaPass) 
\
-DELTA_PASS("arguments", reduceArgumentsDeltaPass)  
\
-DELTA_PASS("instructions", reduceInstructionsDeltaPass)
\
-DELTA_PASS("simplify-instructions", simplifyInstructionsDeltaPass) 
\
-DELTA_PASS("ir-passes", runIRPassesDeltaPass)  
\
-DELTA_PASS("operands-zero", reduceOperandsZeroDeltaPass)   
\
-DELTA_PASS("operands-one", reduceOperandsOneDeltaPass) 
\
-DELTA_PASS("operands-nan", reduceOperandsNaNDeltaPass) 
\
-DELTA_PASS("operands-to-args", reduceOperandsToArgsDeltaPass)  
\
-DELTA_PASS("operands-skip", reduceOperandsSkipDeltaPass)   
\
-DELTA_PASS("operand-bundles", reduceOperandBundesDeltaPass)
\
-DELTA_PASS("attributes", reduceAttributesDeltaPass)
\
-DELTA_PASS("module-data", reduceModuleDataDeltaPass)   
\
-DELTA_PASS("opcodes", reduceOpcodesDeltaPass)  
\
-DELTA_PASS("volatile", reduceVolatileInstructionsDeltaPass)
\
-DELTA_PASS("atomic-ordering", reduceAtomicOrderingDeltaPass)   
\
-DELTA_PASS("syncscopes", reduceAtomicSyncScopesDeltaPass)  
\
-DELTA_PASS("instruction-flags", reduceInstructionFlagsDeltaPass)   
\
-  } while (false)
-
-#define DELTA_PASSES_MIR   
\
-  do { 
\
-DELTA_PASS("instructions", reduceInstructionsMIRDeltaPass) 
\
-DELTA_PASS("ir-instruction-references",
\
-   reduceIRInstructionReferencesDeltaPass) 
\
-DELTA_PASS("ir-block-references", reduceIRBlockReferencesDeltaPass)
\
-DELTA_PASS("ir-function-references", reduceIRFunctionReferencesDeltaPass)  
\
-DELTA_PASS("instruction-flags", reduceInstructionFlagsMIRDeltaPass)
\
-DELTA_PASS("register-uses", reduceRegisterUsesMIRDeltaPass)
\
-DELTA_PASS("register-defs", reduceRegisterDefsMIRDeltaPass)
\
-DELTA_PASS("register-hints", reduceVirtualRegisterHintsDeltaPass)  
\
-DELTA_PASS("register-masks", reduceRegisterMasksMIRDeltaPass)  
\
-  } while (false)
+// Generate two separate Pass lists: IR_Passes and MIR_Passes
+static const DeltaPass IR_Passes[] = {
+  #undef DELTA_PASS_IR 
+  #undef DELTA_PASS_MIR 
+  #define DELTA_PASS_IR(NAME, FUNC, DESC) {NAME,

[clang] [flang] [libcxx] [llvm] [llvm-reduce]: print short form, actionable names in the log (PR #132813)

2025-03-27 Thread Matt Arsenault via cfe-commits


@@ -71,91 +73,77 @@ static cl::list
  "default, run all delta passes."),
 cl::cat(LLVMReduceOptions), cl::CommaSeparated);
 
-#define DELTA_PASSES   
\
-  do { 
\
-DELTA_PASS("strip-debug-info", stripDebugInfoDeltaPass)
\
-DELTA_PASS("functions", reduceFunctionsDeltaPass)  
\
-DELTA_PASS("function-bodies", reduceFunctionBodiesDeltaPass)   
\
-DELTA_PASS("special-globals", reduceSpecialGlobalsDeltaPass)   
\
-DELTA_PASS("aliases", reduceAliasesDeltaPass)  
\
-DELTA_PASS("ifuncs", reduceIFuncsDeltaPass)
\
-DELTA_PASS("simplify-conditionals-true", reduceConditionalsTrueDeltaPass)  
\
-DELTA_PASS("simplify-conditionals-false",  
\
-   reduceConditionalsFalseDeltaPass)   
\
-DELTA_PASS("invokes", reduceInvokesDeltaPass)  
\
-DELTA_PASS("unreachable-basic-blocks", 
\
-   reduceUnreachableBasicBlocksDeltaPass)  
\
-DELTA_PASS("basic-blocks", reduceBasicBlocksDeltaPass) 
\
-DELTA_PASS("simplify-cfg", reduceUsingSimplifyCFGDeltaPass)
\
-DELTA_PASS("function-data", reduceFunctionDataDeltaPass)   
\
-DELTA_PASS("global-values", reduceGlobalValuesDeltaPass)   
\
-DELTA_PASS("global-objects", reduceGlobalObjectsDeltaPass) 
\
-DELTA_PASS("global-initializers", reduceGlobalsInitializersDeltaPass)  
\
-DELTA_PASS("global-variables", reduceGlobalsDeltaPass) 
\
-DELTA_PASS("di-metadata", reduceDIMetadataDeltaPass)   
\
-DELTA_PASS("dbg-records", reduceDbgRecordDeltaPass)
\
-DELTA_PASS("distinct-metadata", reduceDistinctMetadataDeltaPass)   
\
-DELTA_PASS("metadata", reduceMetadataDeltaPass)
\
-DELTA_PASS("named-metadata", reduceNamedMetadataDeltaPass) 
\
-DELTA_PASS("arguments", reduceArgumentsDeltaPass)  
\
-DELTA_PASS("instructions", reduceInstructionsDeltaPass)
\
-DELTA_PASS("simplify-instructions", simplifyInstructionsDeltaPass) 
\
-DELTA_PASS("ir-passes", runIRPassesDeltaPass)  
\
-DELTA_PASS("operands-zero", reduceOperandsZeroDeltaPass)   
\
-DELTA_PASS("operands-one", reduceOperandsOneDeltaPass) 
\
-DELTA_PASS("operands-nan", reduceOperandsNaNDeltaPass) 
\
-DELTA_PASS("operands-to-args", reduceOperandsToArgsDeltaPass)  
\
-DELTA_PASS("operands-skip", reduceOperandsSkipDeltaPass)   
\
-DELTA_PASS("operand-bundles", reduceOperandBundesDeltaPass)
\
-DELTA_PASS("attributes", reduceAttributesDeltaPass)
\
-DELTA_PASS("module-data", reduceModuleDataDeltaPass)   
\
-DELTA_PASS("opcodes", reduceOpcodesDeltaPass)  
\
-DELTA_PASS("volatile", reduceVolatileInstructionsDeltaPass)
\
-DELTA_PASS("atomic-ordering", reduceAtomicOrderingDeltaPass)   
\
-DELTA_PASS("syncscopes", reduceAtomicSyncScopesDeltaPass)  
\
-DELTA_PASS("instruction-flags", reduceInstructionFlagsDeltaPass)   
\
-  } while (false)
-
-#define DELTA_PASSES_MIR   
\
-  do { 
\
-DELTA_PASS("instructions", reduceInstructionsMIRDeltaPass) 
\
-DELTA_PASS("ir-instruction-references",
\
-   reduceIRInstructionReferencesDeltaPass) 
\
-DELTA_PASS("ir-block-references", reduceIRBlockReferencesDeltaPass)
\
-DELTA_PASS("ir-function-references", reduceIRFunctionReferencesDeltaPass)  
\
-DELTA_PASS("instruction-flags", reduceInstructionFlagsMIRDeltaPass)
\
-DELTA_PASS("register-uses", reduceRegisterUsesMIRDeltaPass)
\
-DELTA_PASS("register-defs", reduceRegisterDefsMIRDeltaPass)
\
-DELTA_PASS("register-hints", reduceVirtualRegisterHintsDeltaPass)  
\
-DELTA_PASS("register-masks", reduceRegisterMasksMIRDeltaPass)  
\
-  } while (false)
+// Generate two separate Pass lists: IR_Passes and MIR_Passes
+static const DeltaPass IR_Passes[] = {
+  #undef DELTA_PASS_IR 
+  #undef DELTA_PASS_MIR 
+  #define DELTA_PASS_IR(NAME, FUNC, DESC) {NAME,

[clang] [flang] [libcxx] [llvm] [llvm-reduce]: print short form, actionable names in the log (PR #132813)

2025-03-27 Thread Matt Arsenault via cfe-commits


@@ -0,0 +1,25 @@
+//===--- DeltaPass.h - Delta Pass Structure *- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+
+
+#ifndef LLVM_TOOLS_LLVM_REDUCE_DELTAPASS_H
+#define LLVM_TOOLS_LLVM_REDUCE_DELTAPASS_H
+
+#include "TestRunner.h"
+
+namespace llvm {
+struct DeltaPass {
+  StringRef Name;   // e.g., "strip-debug-info"
+  void (*Func)(TestRunner &, StringRef); // function pointer, 
e.g.,stripDebugInfoDeltaPass

arsenm wrote:

Can you use function_ref here?

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


[clang] [flang] [libcxx] [llvm] [llvm-reduce]: print short form, actionable names in the log (PR #132813)

2025-03-27 Thread Matt Arsenault via cfe-commits


@@ -0,0 +1,25 @@
+//===--- DeltaPass.h - Delta Pass Structure *- C++ -*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+
+
+#ifndef LLVM_TOOLS_LLVM_REDUCE_DELTAPASS_H
+#define LLVM_TOOLS_LLVM_REDUCE_DELTAPASS_H
+
+#include "TestRunner.h"
+
+namespace llvm {
+struct DeltaPass {
+  StringRef Name;   // e.g., "strip-debug-info"
+  void (*Func)(TestRunner &, StringRef); // function pointer, 
e.g.,stripDebugInfoDeltaPass
+  StringRef Desc;   // e.g., "Stripping Debug Info"
+};
+} // namespace llvm
+
+
+#endif

arsenm wrote:

```suggestion
#endif

```

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


[clang] [CIR] Upstream CmpOp (PR #133159)

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

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


[clang-tools-extra] clangd: Add a build option to disable building dexp (PR #133124)

2025-03-27 Thread Yoann Congal via cfe-commits

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


[clang] [NFC][clang] Split clang/lib/CodeGen/CGBuiltin.cpp into target-specific files (PR #132252)

2025-03-27 Thread Farzon Lotfi via cfe-commits

farzonl wrote:

> > Would it be ok if we prefixed all of these files in `TargetBuiltins` with 
> > CG? #133199
> > Building using AppleClang seems to be upset that a cpp file with this name 
> > already exists. I'm assuming its talking about all the files in 
> > `clang/lib/Basic/Targets/`. For example there is now a 
> > `clang/lib/Basic/Targets/AMDGPU.cpp` and 
> > `clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp`.
> 
> We currently have four, so I'm unsure why one more makes a difference. I 
> guess because they go in the same library component or something?
> 
> ```
> clang/lib/Basic/Targets/AMDGPU.cpp
> clang/lib/CodeGen/TargetBuiltins/AMDGPU.cpp
> clang/lib/CodeGen/Targets/AMDGPU.cpp
> clang/lib/Driver/ToolChains/AMDGPU.cpp
> ```

I don't know what libtool is doing here to give you a confident answer.

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


[clang] [CIR] Upstream CmpOp (PR #133159)

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


@@ -710,6 +710,89 @@ class ScalarExprEmitter : public 
StmtVisitor {
   HANDLEBINOP(Xor)
   HANDLEBINOP(Or)
 #undef HANDLEBINOP
+
+  mlir::Value emitCmp(const BinaryOperator *e) {
+mlir::Value result;
+QualType lhsTy = e->getLHS()->getType();
+QualType rhsTy = e->getRHS()->getType();
+
+auto clangCmpToCIRCmp =
+[](clang::BinaryOperatorKind clangCmp) -> cir::CmpOpKind {
+  switch (clangCmp) {
+  case BO_LT:
+return cir::CmpOpKind::lt;
+  case BO_GT:
+return cir::CmpOpKind::gt;
+  case BO_LE:
+return cir::CmpOpKind::le;
+  case BO_GE:
+return cir::CmpOpKind::ge;
+  case BO_EQ:
+return cir::CmpOpKind::eq;
+  case BO_NE:
+return cir::CmpOpKind::ne;
+  default:
+llvm_unreachable("unsupported comparison kind");
+  }
+};
+
+if (lhsTy->getAs()) {
+  assert(e->getOpcode() == BO_EQ || e->getOpcode() == BO_NE);
+  mlir::Value lhs = cgf.emitScalarExpr(e->getLHS());
+  mlir::Value rhs = cgf.emitScalarExpr(e->getRHS());
+  cir::CmpOpKind kind = clangCmpToCIRCmp(e->getOpcode());
+  result =
+  builder.createCompare(cgf.getLoc(e->getExprLoc()), kind, lhs, rhs);
+} else if (!lhsTy->isAnyComplexType() && !rhsTy->isAnyComplexType()) {
+  BinOpInfo boInfo = emitBinOps(e);
+  mlir::Value lhs = boInfo.lhs;
+  mlir::Value rhs = boInfo.rhs;
+
+  if (lhsTy->isVectorType()) {
+assert(!cir::MissingFeatures::vectorType());
+cgf.cgm.errorNYI(boInfo.loc, "vector comparisons");
+result = builder.getBool(false, cgf.getLoc(boInfo.loc));
+  } else if (boInfo.isFixedPointOp()) {
+assert(!cir::MissingFeatures::fixedPointType());
+cgf.cgm.errorNYI(boInfo.loc, "fixed point comparisons");
+result = builder.getBool(false, cgf.getLoc(boInfo.loc));
+  } else if (lhsTy->hasSignedIntegerRepresentation()) {

mmha wrote:

I think it's better to remove that branch altogether and let the `else` deal 
with it.

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


[clang] [AMDGPU] Remove detection of hip runtime for Spack (PR #133263)

2025-03-27 Thread Matt Arsenault via cfe-commits

arsenm wrote:

I'm going to wager that we can't just rip this out without the world exploding, 
and these issues need to be addressed and not just drop the whole thing.

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


[clang] [Clang] Improve subsumption. (PR #132849)

2025-03-27 Thread via cfe-commits


@@ -170,102 +132,112 @@ struct alignas(ConstraintAlignment) 
FoldExpandedConstraint {
  const Expr *Pattern)
   : Kind(K), Constraint(std::move(C)), Pattern(Pattern) {};
 
-  template 
-  bool subsumes(const FoldExpandedConstraint &Other,
-const AtomicSubsumptionEvaluator &E) const;
-
   static bool AreCompatibleForSubsumption(const FoldExpandedConstraint &A,
   const FoldExpandedConstraint &B);
+
+  llvm::FoldingSetNodeID ProfileForSubsumption() const;

cor3ntin wrote:

This was just a (poorly named) attempt to produce a cache key for atomic 
constraint generically (we do it in two places but both places do it 
differently) - i just forgot to cleanup after myself

> Actually, should we be adding some time trace report support to this so users 
> can track how much time is spent on subsumption in their headers?

Completely unrelated but it might be a good in a follow up. But what we should 
profile there is more "how much time is spent finding the most constraint 
candidate"

 

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


[clang] [C23] Implement WG14 N3037 (PR #132939)

2025-03-27 Thread James Y Knight via cfe-commits


@@ -450,6 +453,116 @@ class StmtComparer {
 };
 } // namespace
 
+static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context,
+ const Attr *Attr1, const Attr *Attr2) {
+  // Two attributes are structurally equivalent if they are the same kind
+  // of attribute, spelled with the same spelling kind, and have the same
+  // arguments. This means that [[noreturn]] and __attribute__((noreturn)) are
+  // not structurally equivalent, nor are [[nodiscard("foo")]] and
+  // [[nodiscard("bar")]].
+  if (Attr1->getKind() != Attr2->getKind())
+return false;
+
+  if (Attr1->getSyntax() != Attr2->getSyntax())
+return false;
+
+  if (Attr1->getSpellingListIndex() != Attr2->getSpellingListIndex())
+return false;
+
+  auto GetAttrName = [](const Attr *A) {
+if (const IdentifierInfo *II = A->getAttrName())
+  return II->getName();
+return StringRef{};
+  };
+
+  if (GetAttrName(Attr1) != GetAttrName(Attr2))
+return false;
+
+  // FIXME: check the attribute arguments. Attr does not track the arguments on
+  // the base class, which makes this awkward. We may want to tablegen a
+  // comparison function for attributes? In the meantime, we're doing this the
+  // cheap way by pretty printing the attributes and checking they produce

jyknight wrote:

> safe by default (require attributes to be the same) or we can be unsafe by 
> default (ignore attributes).

If we treat two types as incompatible when they ought to be compatible, it 
potentially could result in silent miscompilation of a valid program, since 
loading from memory requires that you use a type compatible with the type which 
was used to store. OTOH, if we treat two types as being compatible when they 
should be incompatible, the result is that we may incorrectly accept some 
invalid programs which we could've rejected. The latter is _not useful_ towards 
the goal of assisting the developer in writing correct code, but not unsafe on 
its own. 

Though...I suppose getting it wrong here may not be able to actually cause 
miscompilation for Clang, since we emit TBAA metadata using a different (and 
weaker) concept of type-compatibility anyhow.

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


[clang] [llvm] Enable unnecessary-virtual-specifier by default (PR #133265)

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

DKLoehr wrote:

Ah, missed that, sorry. It seems there hasn't been a release since the warning 
was added, and the existing release note seems to still apply: 
https://github.com/llvm/llvm-project/blob/8bdcd0a96e65557c8c3bf506d186c49002db6463/clang/docs/ReleaseNotes.rst?plain=1#L291

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


[clang] [llvm] [HLSL][RootSignature] Implement parsing of a DescriptorTable with empty clauses (PR #133302)

2025-03-27 Thread Finn Plummer via cfe-commits

https://github.com/inbelic created 
https://github.com/llvm/llvm-project/pull/133302

- defines the Parser class and an initial set of helper methods to
support consuming tokens. functionality is demonstrated through a simple
empty descriptor table test case
- defines an initial in-memory representation of a DescriptorTable
- implements a test harness that will be used to validate the correct
diagnostics are generated. it will construct a dummy pre-processor with
diagnostics consumer to do so

>From a2d3cb70f683d61ce5478cd583af5fa4a91fddab Mon Sep 17 00:00:00 2001
From: Finn Plummer 
Date: Fri, 14 Feb 2025 19:44:36 +
Subject: [PATCH 1/6] [NFC][HLSL][RootSignature] add spelling of tokens to
 tokenkind.def

---
 .../clang/Lex/HLSLRootSignatureTokenKinds.def | 22 +--
 .../include/clang/Lex/LexHLSLRootSignature.h  |  2 +-
 .../Lex/LexHLSLRootSignatureTest.cpp  |  2 +-
 3 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/clang/include/clang/Lex/HLSLRootSignatureTokenKinds.def 
b/clang/include/clang/Lex/HLSLRootSignatureTokenKinds.def
index e6df763920430..697c6abc54efa 100644
--- a/clang/include/clang/Lex/HLSLRootSignatureTokenKinds.def
+++ b/clang/include/clang/Lex/HLSLRootSignatureTokenKinds.def
@@ -14,16 +14,16 @@
 
//===--===//
 
 #ifndef TOK
-#define TOK(X)
+#define TOK(X, SPELLING)
 #endif
 #ifndef PUNCTUATOR
-#define PUNCTUATOR(X,Y) TOK(pu_ ## X)
+#define PUNCTUATOR(X,Y) TOK(pu_ ## X, Y)
 #endif
 #ifndef KEYWORD
-#define KEYWORD(X) TOK(kw_ ## X)
+#define KEYWORD(X) TOK(kw_ ## X, #X)
 #endif
 #ifndef ENUM
-#define ENUM(NAME, LIT) TOK(en_ ## NAME)
+#define ENUM(NAME, LIT) TOK(en_ ## NAME, LIT)
 #endif
 
 // Defines the various types of enum
@@ -49,15 +49,15 @@
 #endif
 
 // General Tokens:
-TOK(invalid)
-TOK(end_of_stream)
-TOK(int_literal)
+TOK(invalid, "invalid identifier")
+TOK(end_of_stream, "end of stream")
+TOK(int_literal, "integer literal")
 
 // Register Tokens:
-TOK(bReg)
-TOK(tReg)
-TOK(uReg)
-TOK(sReg)
+TOK(bReg, "b register")
+TOK(tReg, "t register")
+TOK(uReg, "u register")
+TOK(sReg, "s register")
 
 // Punctuators:
 PUNCTUATOR(l_paren, '(')
diff --git a/clang/include/clang/Lex/LexHLSLRootSignature.h 
b/clang/include/clang/Lex/LexHLSLRootSignature.h
index 21c44e0351d9e..b82237411b2ab 100644
--- a/clang/include/clang/Lex/LexHLSLRootSignature.h
+++ b/clang/include/clang/Lex/LexHLSLRootSignature.h
@@ -24,7 +24,7 @@ namespace hlsl {
 
 struct RootSignatureToken {
   enum Kind {
-#define TOK(X) X,
+#define TOK(X, SPELLING) X,
 #include "clang/Lex/HLSLRootSignatureTokenKinds.def"
   };
 
diff --git a/clang/unittests/Lex/LexHLSLRootSignatureTest.cpp 
b/clang/unittests/Lex/LexHLSLRootSignatureTest.cpp
index 0576f08c4c276..1e014f6c41c57 100644
--- a/clang/unittests/Lex/LexHLSLRootSignatureTest.cpp
+++ b/clang/unittests/Lex/LexHLSLRootSignatureTest.cpp
@@ -113,7 +113,7 @@ TEST_F(LexHLSLRootSignatureTest, ValidLexAllTokensTest) {
 
   SmallVector Tokens;
   SmallVector Expected = {
-#define TOK(NAME) hlsl::TokenKind::NAME,
+#define TOK(NAME, SPELLING) hlsl::TokenKind::NAME,
 #include "clang/Lex/HLSLRootSignatureTokenKinds.def"
   };
 

>From 0fdb4e7ddd3b7bc0e8b9ac35c87a154c01611b4a Mon Sep 17 00:00:00 2001
From: Finn Plummer 
Date: Wed, 26 Mar 2025 19:10:15 +
Subject: [PATCH 2/6] [HLSL][RootSignature] Implement parsing of an empty
 DescriptorTable

- defines the Parser class and an initial set of helper methods to
support consuming tokens. functionality is demonstrated through a simple
empty descriptor table test case
- defines an initial in-memory representation of a DescriptorTable
- implements a test harness that will be used to validate the correct
diagnostics are generated. it will construct a dummy pre-processor with
diagnostics consumer to do so
---
 .../clang/Parse/ParseHLSLRootSignature.h  |  84 +++
 clang/lib/Parse/CMakeLists.txt|   1 +
 clang/lib/Parse/ParseHLSLRootSignature.cpp| 135 +++
 clang/unittests/CMakeLists.txt|   1 +
 clang/unittests/Parse/CMakeLists.txt  |  23 ++
 .../Parse/ParseHLSLRootSignatureTest.cpp  | 217 ++
 .../llvm/Frontend/HLSL/HLSLRootSignature.h|  37 +++
 7 files changed, 498 insertions(+)
 create mode 100644 clang/include/clang/Parse/ParseHLSLRootSignature.h
 create mode 100644 clang/lib/Parse/ParseHLSLRootSignature.cpp
 create mode 100644 clang/unittests/Parse/CMakeLists.txt
 create mode 100644 clang/unittests/Parse/ParseHLSLRootSignatureTest.cpp
 create mode 100644 llvm/include/llvm/Frontend/HLSL/HLSLRootSignature.h

diff --git a/clang/include/clang/Parse/ParseHLSLRootSignature.h 
b/clang/include/clang/Parse/ParseHLSLRootSignature.h
new file mode 100644
index 0..95243747fbd6b
--- /dev/null
+++ b/clang/include/clang/Parse/ParseHLSLRootSignature.h
@@ -0,0 +1,84 @@
+//===--- ParseHLSLRootSignature.h ---*- C++ 
-*-===//
+//
+// Part of th

[clang-tools-extra] [clang-tidy] do not diagnose array types within implicit instantiations of a template (PR #132924)

2025-03-27 Thread St. Muench via cfe-commits


@@ -92,3 +92,162 @@ const char name[] = "Some string";
 
 void takeCharArray(const char name[]);
 // CHECK-MESSAGES: :[[@LINE-1]]:26: warning: do not declare C-style arrays, 
use 'std::array' or 'std::vector' instead [modernize-avoid-c-arrays]
+
+namespace std {
+  template
+  struct is_same { constexpr static bool value{false}; };
+
+  template
+  struct is_same { constexpr static bool value{true}; };
+
+  template
+  constexpr bool is_same_v = is_same::value;
+
+  template struct remove_const { typedef T type; };
+  template struct remove_const { typedef T type; };
+
+  template
+  using remove_const_t = typename remove_const::type;
+
+  template struct enable_if {};
+  template struct enable_if { typedef T type; };
+
+  template< bool B, class T = void >
+  using enable_if_t = typename enable_if::type;
+}
+
+// below, no array type findings are expected within the template parameter 
declarations since no array type gets written explicitly
+template ,
+  bool = std::is_same::value,
+  bool = std::is_same_v, int>,
+  bool = std::is_same, int>::value,
+  bool = std::is_same_v::type, int>,
+  bool = std::is_same::type, int>::value,
+  std::enable_if_t, int>) && 
not(std::is_same_v::type, char>), bool> = true,
+  typename std::enable_if, 
int>) && not(std::is_same_v::type, char>), 
bool>::type = true,
+  typename = 
std::enable_if_t, int>) && 
not(std::is_same_v::type, char>)>,
+  typename = typename std::remove_const::type,
+  typename = std::remove_const_t>
+class MyClassTemplate {
+ public:
+  // here, plenty of array type findings are expected for below template 
parameter declarations since array types get written explicitly
+  template ,
+// CHECK-MESSAGES: :[[@LINE-1]]:38: warning: do not declare 
C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
+bool = std::is_same::value,
+// CHECK-MESSAGES: :[[@LINE-1]]:36: warning: do not declare 
C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
+std::enable_if_t, 
int[]>) && not(std::is_same_v::type, char[10]>), 
bool> = true,
+// CHECK-MESSAGES: :[[@LINE-1]]:73: warning: do not declare 
C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
+// CHECK-MESSAGES: :[[@LINE-2]]:140: warning: do not declare 
C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
+typename = typename std::remove_const::type,
+// CHECK-MESSAGES: :[[@LINE-1]]:51: warning: do not declare 
C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
+typename = std::remove_const_t>
+// CHECK-MESSAGES: :[[@LINE-1]]:44: warning: do not declare 
C-style arrays, use 'std::array' instead [modernize-avoid-c-arrays]
+class MyInnerClassTemplate {
+ public:
+  MyInnerClassTemplate(const U&) {}
+ private:
+  U field[3];
+  // CHECK-MESSAGES: :[[@LINE-1]]:7: warning: do not declare C-style 
arrays, use 'std::array' instead [modernize-avoid-c-arrays]
+};
+
+MyClassTemplate(const T&) {}
+
+ private:
+T field[7];
+// CHECK-MESSAGES: :[[@LINE-1]]:5: warning: do not declare C-style arrays, 
use 'std::array' instead [modernize-avoid-c-arrays]
+};
+
+// an explicit instantiation
+template
+class MyClassTemplate;
+// CHECK-MESSAGES: :[[@LINE-1]]:23: warning: do not declare C-style arrays, 
use 'std::array' instead [modernize-avoid-c-arrays]
+
+using MyArrayType = int[3];
+// CHECK-MESSAGES: :[[@LINE-1]]:21: warning: do not declare C-style arrays, 
use 'std::array' instead [modernize-avoid-c-arrays]
+
+// another explicit instantiation
+template
+class MyClassTemplate;
+
+// below, no array type findings are expected within the template parameter 
declarations since no array type gets written explicitly
+template ,
+  bool = std::is_same::value,
+  bool = std::is_same_v, int>,
+  bool = std::is_same, int>::value,
+  bool = std::is_same_v::type, int>,
+  bool = std::is_same::type, int>::value,
+  std::enable_if_t, int>) && 
not(std::is_same_v::type, char>), bool> = true,
+  typename std::enable_if, 
int>) && not(std::is_same_v::type, char>), 
bool>::type = true,
+  typename = 
std::enable_if_t, int>) && 
not(std::is_same_v::type, char>)>,
+  typename = typename std::remove_const::type,
+  typename = std::remove_const_t>
+void func(const T& param) {
+  int array1[1];
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not declare C-style arrays, 
use 'std::array' instead [modernize-avoid-c-arrays]
+
+  T array2[2];
+  // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not declare C-style arrays, 
use 'std::array' instead [modernize-avoid-c-arrays]
+
+  T value;
+}
+
+// here, plenty of array type findings are expected for below template 
parameter declarations since array types get written explicitly
+template ,
+ 

[clang] Ubsan: warn on -fsanitize-trap=undefined ignored when passed on its own (PR #132319)

2025-03-27 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: clf (clingfei)


Changes

As @delcypher proposed, when the -fsanitize-trap=undefined flag is 
passed on its own the compiler silently ignores it. Currently Clang requires 
that the -fsanitize= flag is also passed. 
This PR warn about this behavior.


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


1 Files Affected:

- (modified) clang/lib/Driver/SanitizerArgs.cpp (+3-1) 


``diff
diff --git a/clang/lib/Driver/SanitizerArgs.cpp 
b/clang/lib/Driver/SanitizerArgs.cpp
index 6e75001585c61..62d93954751f1 100644
--- a/clang/lib/Driver/SanitizerArgs.cpp
+++ b/clang/lib/Driver/SanitizerArgs.cpp
@@ -728,7 +728,9 @@ SanitizerArgs::SanitizerArgs(const ToolChain &TC,
   RecoverableKinds |= AlwaysRecoverable;
   RecoverableKinds &= ~Unrecoverable;
   RecoverableKinds &= Kinds;
-
+  if ((TrappingKinds & SanitizerKind::Undefined) &&
+  !(Kinds & SanitizerKind::Undefined))
+llvm::errs() << "Warning: -fsanitize-trap=undefined ignored\n";
   TrappingKinds &= Kinds;
   RecoverableKinds &= ~TrappingKinds;
 

``




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


[clang] [HIP] use offload wrapper for non-device-only non-rdc (PR #132869)

2025-03-27 Thread Yaxun Liu via cfe-commits


@@ -9348,11 +9348,22 @@ void LinkerWrapper::ConstructJob(Compilation &C, const 
JobAction &JA,
   // Add the linker arguments to be forwarded by the wrapper.
   CmdArgs.push_back(Args.MakeArgString(Twine("--linker-path=") +
LinkCommand->getExecutable()));
-  for (const char *LinkArg : LinkCommand->getArguments())
-CmdArgs.push_back(LinkArg);
 
-  addOffloadCompressArgs(Args, CmdArgs);
+  // We use action type to differentiate two use cases of the linker wrapper.
+  // TY_Image for normal linker wrapper work.
+  // TY_Object for HIP fno-gpu-rdc embedding device binary in a relocatable
+  // object.
+  assert(JA.getType() == types::TY_Object || JA.getType() == types::TY_Image);
+  if (JA.getType() == types::TY_Object) {
+CmdArgs.append({"-o", Output.getFilename()});
+for (auto Input : Inputs)

yxsamliu wrote:

That would include all the arguments from the command line and the generated 
arguments include the system libraries, whereas we only want to link the 
wrapper object to the original host object through "-r". It is simpler to 
create the command line options from scratch and cherry-pick any relevant 
options from Args if necessary. So far it is working.

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


[clang] [Clang] Handle `-flto-partitions` generically and forward it properly (PR #133283)

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

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


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


[clang] [MS][clang] Add support for vector deleting destructors (PR #126240)

2025-03-27 Thread Mariya Podchishchaeva via cfe-commits

Fznamznon wrote:

Removing `static ` from `newUnicodeStringArray` also makes the crash go away...

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


[clang] [llvm] [HLSL][RootSignature] Implement parsing of a DescriptorTable with empty clauses (PR #133302)

2025-03-27 Thread Finn Plummer via cfe-commits

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


[clang] [llvm] [clang][CodeGen] Generate follow-up metadata for loops in correct format (PR #131985)

2025-03-27 Thread Ryotaro Kasuga via cfe-commits


@@ -44,23 +44,19 @@ MDNode *LoopInfo::createPipeliningMetadata(const 
LoopAttributes &Attrs,
   else if (Attrs.PipelineInitiationInterval != 0)
 Enabled = true;
 
+  SmallVector Args;
+  Args.append(LoopProperties.begin(), LoopProperties.end());
+
   if (Enabled != true) {
-SmallVector NewLoopProperties;
 if (Enabled == false) {
-  NewLoopProperties.append(LoopProperties.begin(), LoopProperties.end());

kasuga-fj wrote:

> In principle, LoopVectorize should know that if the original loop had a 
> progress guarantee, then the vectorized loop will as well, so it should add 
> `llvm.loop.must_progress` no matter what.

I think this is completely correct. What I didn't understand is, why the 
followup metadata of `LOOP_6` (`FOLLOW_VECTOR_6`) didn't have 
`llvm.mustprogress` before this patch, but now it (`FOLLOWUP_VECTOR_3`) does.  
I investigated a little deeper and found the cause; `FOLLOWUP_VECTOR_6` 
actually had `mustprogress` (?!). That is, the test passed for both of the 
following directives.

```
// Original.
// CHECK: ![[AFTER_VECTOR_6]] = distinct !{![[AFTER_VECTOR_6]], 
![[ISVECTORIZED:.*]], ![[UNROLL_8:.*]]}

// This was also fine.
// CHECK: ![[AFTER_VECTOR_6]] = distinct !{![[AFTER_VECTOR_6]], [[MP]], 
![[ISVECTORIZED:.*]], ![[UNROLL_8:.*]]}
```

Maybe FileCheck has a problem?

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


[clang] [llvm] [clang][CodeGen] Generate follow-up metadata for loops in correct format (PR #131985)

2025-03-27 Thread Ryotaro Kasuga via cfe-commits


@@ -44,23 +44,19 @@ MDNode *LoopInfo::createPipeliningMetadata(const 
LoopAttributes &Attrs,
   else if (Attrs.PipelineInitiationInterval != 0)
 Enabled = true;
 
+  SmallVector Args;
+  Args.append(LoopProperties.begin(), LoopProperties.end());
+
   if (Enabled != true) {
-SmallVector NewLoopProperties;
 if (Enabled == false) {
-  NewLoopProperties.append(LoopProperties.begin(), LoopProperties.end());

kasuga-fj wrote:

The same thing seems to happen elsewhere, e.g. `LOOP_6` actually has 
`vectorize.enable` but is not included in the CHECK directive.

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


[clang] [Clang] Link libgcc_s.1.dylib when building for macOS 10.5 and older (PR #124651)

2025-03-27 Thread via cfe-commits

Un1q32 wrote:

Accidentally pushed a commit that was supposed to be for another pr to this 
branch, the PR has nothing to do with ARM

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


[clang] Add more tests for _Countof (PR #133333)

2025-03-27 Thread A. Jiang via cfe-commits


@@ -81,6 +89,22 @@ void test_with_function_param(int array[12], int 
(*array_ptr)[12], int static_ar
   (void)_Countof(static_array); // expected-error {{'_Countof' requires an 
argument of array type; 'int *' invalid}}
 }
 
+void test_func_fix_fix(int i, char (*a)[3][5], int (*x)[_Countof(*a)]);
+void test_func_fix_var(int i, char (*a)[3][i], int (*x)[_Countof(*a)]);
+void test_func_fix_uns(int i, char (*a)[3][*], int (*x)[_Countof(*a)]);

frederick-vs-ja wrote:

Oh, I forgot that trailing return type is not yet supported in C.

Perhaps we can do this:
```c
void test_func_fix_fix(int i, char (*a)[3][5], int (*x)[_Countof(*a)], 
char(*)[_Generic(x, int(*)[3] : 1)]);
```

Which effectively asserts that `typeof(x)` is `int(*)[3]`.

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


[libclc] [libclc] Pass -fapprox-func when compiling 'native' builtins (PR #133119)

2025-03-27 Thread Matt Arsenault via cfe-commits

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


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


[clang] [llvm] [Clang] Link libgcc_s.1.dylib when building for macOS 10.5 and older (PR #124651)

2025-03-27 Thread via cfe-commits

https://github.com/Un1q32 updated 
https://github.com/llvm/llvm-project/pull/124651

>From d4e97c4113086c3d2dfa3bf6e9ecfee377f8c4b6 Mon Sep 17 00:00:00 2001
From: Un1q32 
Date: Mon, 27 Jan 2025 18:00:34 -0500
Subject: [PATCH 1/4] [Clang] Link libgcc_s.1.dylib when building for macOS
 10.5 and older

---
 clang/lib/Driver/ToolChains/Darwin.cpp | 9 +
 clang/test/Driver/darwin-ld.c  | 7 ++-
 2 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp 
b/clang/lib/Driver/ToolChains/Darwin.cpp
index 55c55bad73934..67f27a599b4c3 100644
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
@@ -1645,12 +1645,13 @@ void DarwinClang::AddLinkRuntimeLibArgs(const ArgList 
&Args,
 CmdArgs.push_back("-lSystem");
 
   // Select the dynamic runtime library and the target specific static library.
-  if (isTargetIOSBased()) {
+  if (isTargetIOSBased() || isTargetMacOSBased()) {
 // If we are compiling as iOS / simulator, don't attempt to link 
libgcc_s.1,
 // it never went into the SDK.
-// Linking against libgcc_s.1 isn't needed for iOS 5.0+
-if (isIPhoneOSVersionLT(5, 0) && !isTargetIOSSimulator() &&
-getTriple().getArch() != llvm::Triple::aarch64)
+// Linking against libgcc_s.1 isn't needed for iOS 5.0+ or macOS 10.6+
+if ((isIPhoneOSVersionLT(5, 0) && !isTargetIOSSimulator() &&
+ getTriple().getArch() != llvm::Triple::aarch64) ||
+isMacosxVersionLT(10, 6))
   CmdArgs.push_back("-lgcc_s.1");
   }
   AddLinkRuntimeLib(Args, CmdArgs, "builtins");
diff --git a/clang/test/Driver/darwin-ld.c b/clang/test/Driver/darwin-ld.c
index f0ca411430cc7..5b10daaf007a2 100644
--- a/clang/test/Driver/darwin-ld.c
+++ b/clang/test/Driver/darwin-ld.c
@@ -240,6 +240,11 @@
 // RUN: FileCheck -check-prefix=LINK_NO_IOS_ARM64_LIBGCC_S %s < %t.log
 // LINK_NO_IOS_ARM64_LIBGCC_S-NOT: lgcc_s.1
 
+// Check that clang links with libgcc_s.1 for macOS 10.5 and earlier
+// RUN: %clang -target x86_64-apple-macos10.5 -mmacosx-version-min=10.5 -### 
%t.o 2> %t.log
+// RUN: FileCheck -check-prefix=LINK_OSX_LIBGCC_S %s < %t.log
+// LINK_OSX_LIBGCC_S: lgcc_s.1
+
 // RUN: %clang -target x86_64-apple-darwin12 -rdynamic -### %t.o \
 // RUN:   -fuse-ld= -mlinker-version=100 2> %t.log
 // RUN: FileCheck -check-prefix=LINK_NO_EXPORT_DYNAMIC %s < %t.log
@@ -385,4 +390,4 @@
 // RUN:   %clang -target armv7em-apple-darwin -mno-outline -### %t.o 2> %t.log
 // RUN: FileCheck -check-prefix=ARMV7EM-MNO_OUTLINE %s < %t.log
 // ARMV7EM-MNO_OUTLINE: {{ld(.exe)?"}}
-// ARMV7EM-MNO_OUTLINE-SAME: "-mllvm" "-enable-machine-outliner=never" 
"-mllvm" "-enable-linkonceodr-outlining"
\ No newline at end of file
+// ARMV7EM-MNO_OUTLINE-SAME: "-mllvm" "-enable-machine-outliner=never" 
"-mllvm" "-enable-linkonceodr-outlining"

>From 4407312c3b8f2edfd9279183a9d4fae316639469 Mon Sep 17 00:00:00 2001
From: Un1q32 
Date: Mon, 27 Jan 2025 18:59:53 -0500
Subject: [PATCH 2/4] fix

---
 clang/lib/Driver/ToolChains/Darwin.cpp | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp 
b/clang/lib/Driver/ToolChains/Darwin.cpp
index 67f27a599b4c3..82f7d4597d0c7 100644
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
@@ -1645,15 +1645,15 @@ void DarwinClang::AddLinkRuntimeLibArgs(const ArgList 
&Args,
 CmdArgs.push_back("-lSystem");
 
   // Select the dynamic runtime library and the target specific static library.
-  if (isTargetIOSBased() || isTargetMacOSBased()) {
+  if (isTargetIOSBased()) {
 // If we are compiling as iOS / simulator, don't attempt to link 
libgcc_s.1,
 // it never went into the SDK.
 // Linking against libgcc_s.1 isn't needed for iOS 5.0+ or macOS 10.6+
-if ((isIPhoneOSVersionLT(5, 0) && !isTargetIOSSimulator() &&
- getTriple().getArch() != llvm::Triple::aarch64) ||
-isMacosxVersionLT(10, 6))
+if (isIPhoneOSVersionLT(5, 0) && !isTargetIOSSimulator() &&
+getTriple().getArch() != llvm::Triple::aarch64)
   CmdArgs.push_back("-lgcc_s.1");
-  }
+  } else if (isTargetMacOSBased() && isMacosxVersionLT(10, 6))
+CmdArgs.push_back("-lgcc_s.1");
   AddLinkRuntimeLib(Args, CmdArgs, "builtins");
 }
 

>From 31bdca90a631f744f86fa3e25e1a178455901503 Mon Sep 17 00:00:00 2001
From: Un1q32 
Date: Mon, 17 Mar 2025 18:44:08 -0400
Subject: [PATCH 3/4] tidy this up a bit, also don't link libgcc_s on arm64
 ever

---
 clang/lib/Driver/ToolChains/Darwin.cpp | 16 
 clang/test/Driver/darwin-ld.c  |  8 ++--
 2 files changed, 14 insertions(+), 10 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp 
b/clang/lib/Driver/ToolChains/Darwin.cpp
index 757ba50e4c865..acc0f9ca59316 100644
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
@@ -1642,14 +1642,14 @@ void DarwinClang::AddLinkRuntimeLibArgs(const ArgList 
&Args,
 C

[clang] [Clang] Link libgcc_s.1.dylib when building for macOS 10.5 and older (PR #124651)

2025-03-27 Thread via cfe-commits

https://github.com/Un1q32 updated 
https://github.com/llvm/llvm-project/pull/124651

>From d4e97c4113086c3d2dfa3bf6e9ecfee377f8c4b6 Mon Sep 17 00:00:00 2001
From: Un1q32 
Date: Mon, 27 Jan 2025 18:00:34 -0500
Subject: [PATCH 1/3] [Clang] Link libgcc_s.1.dylib when building for macOS
 10.5 and older

---
 clang/lib/Driver/ToolChains/Darwin.cpp | 9 +
 clang/test/Driver/darwin-ld.c  | 7 ++-
 2 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp 
b/clang/lib/Driver/ToolChains/Darwin.cpp
index 55c55bad73934..67f27a599b4c3 100644
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
@@ -1645,12 +1645,13 @@ void DarwinClang::AddLinkRuntimeLibArgs(const ArgList 
&Args,
 CmdArgs.push_back("-lSystem");
 
   // Select the dynamic runtime library and the target specific static library.
-  if (isTargetIOSBased()) {
+  if (isTargetIOSBased() || isTargetMacOSBased()) {
 // If we are compiling as iOS / simulator, don't attempt to link 
libgcc_s.1,
 // it never went into the SDK.
-// Linking against libgcc_s.1 isn't needed for iOS 5.0+
-if (isIPhoneOSVersionLT(5, 0) && !isTargetIOSSimulator() &&
-getTriple().getArch() != llvm::Triple::aarch64)
+// Linking against libgcc_s.1 isn't needed for iOS 5.0+ or macOS 10.6+
+if ((isIPhoneOSVersionLT(5, 0) && !isTargetIOSSimulator() &&
+ getTriple().getArch() != llvm::Triple::aarch64) ||
+isMacosxVersionLT(10, 6))
   CmdArgs.push_back("-lgcc_s.1");
   }
   AddLinkRuntimeLib(Args, CmdArgs, "builtins");
diff --git a/clang/test/Driver/darwin-ld.c b/clang/test/Driver/darwin-ld.c
index f0ca411430cc7..5b10daaf007a2 100644
--- a/clang/test/Driver/darwin-ld.c
+++ b/clang/test/Driver/darwin-ld.c
@@ -240,6 +240,11 @@
 // RUN: FileCheck -check-prefix=LINK_NO_IOS_ARM64_LIBGCC_S %s < %t.log
 // LINK_NO_IOS_ARM64_LIBGCC_S-NOT: lgcc_s.1
 
+// Check that clang links with libgcc_s.1 for macOS 10.5 and earlier
+// RUN: %clang -target x86_64-apple-macos10.5 -mmacosx-version-min=10.5 -### 
%t.o 2> %t.log
+// RUN: FileCheck -check-prefix=LINK_OSX_LIBGCC_S %s < %t.log
+// LINK_OSX_LIBGCC_S: lgcc_s.1
+
 // RUN: %clang -target x86_64-apple-darwin12 -rdynamic -### %t.o \
 // RUN:   -fuse-ld= -mlinker-version=100 2> %t.log
 // RUN: FileCheck -check-prefix=LINK_NO_EXPORT_DYNAMIC %s < %t.log
@@ -385,4 +390,4 @@
 // RUN:   %clang -target armv7em-apple-darwin -mno-outline -### %t.o 2> %t.log
 // RUN: FileCheck -check-prefix=ARMV7EM-MNO_OUTLINE %s < %t.log
 // ARMV7EM-MNO_OUTLINE: {{ld(.exe)?"}}
-// ARMV7EM-MNO_OUTLINE-SAME: "-mllvm" "-enable-machine-outliner=never" 
"-mllvm" "-enable-linkonceodr-outlining"
\ No newline at end of file
+// ARMV7EM-MNO_OUTLINE-SAME: "-mllvm" "-enable-machine-outliner=never" 
"-mllvm" "-enable-linkonceodr-outlining"

>From 4407312c3b8f2edfd9279183a9d4fae316639469 Mon Sep 17 00:00:00 2001
From: Un1q32 
Date: Mon, 27 Jan 2025 18:59:53 -0500
Subject: [PATCH 2/3] fix

---
 clang/lib/Driver/ToolChains/Darwin.cpp | 10 +-
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp 
b/clang/lib/Driver/ToolChains/Darwin.cpp
index 67f27a599b4c3..82f7d4597d0c7 100644
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
@@ -1645,15 +1645,15 @@ void DarwinClang::AddLinkRuntimeLibArgs(const ArgList 
&Args,
 CmdArgs.push_back("-lSystem");
 
   // Select the dynamic runtime library and the target specific static library.
-  if (isTargetIOSBased() || isTargetMacOSBased()) {
+  if (isTargetIOSBased()) {
 // If we are compiling as iOS / simulator, don't attempt to link 
libgcc_s.1,
 // it never went into the SDK.
 // Linking against libgcc_s.1 isn't needed for iOS 5.0+ or macOS 10.6+
-if ((isIPhoneOSVersionLT(5, 0) && !isTargetIOSSimulator() &&
- getTriple().getArch() != llvm::Triple::aarch64) ||
-isMacosxVersionLT(10, 6))
+if (isIPhoneOSVersionLT(5, 0) && !isTargetIOSSimulator() &&
+getTriple().getArch() != llvm::Triple::aarch64)
   CmdArgs.push_back("-lgcc_s.1");
-  }
+  } else if (isTargetMacOSBased() && isMacosxVersionLT(10, 6))
+CmdArgs.push_back("-lgcc_s.1");
   AddLinkRuntimeLib(Args, CmdArgs, "builtins");
 }
 

>From 31bdca90a631f744f86fa3e25e1a178455901503 Mon Sep 17 00:00:00 2001
From: Un1q32 
Date: Mon, 17 Mar 2025 18:44:08 -0400
Subject: [PATCH 3/3] tidy this up a bit, also don't link libgcc_s on arm64
 ever

---
 clang/lib/Driver/ToolChains/Darwin.cpp | 16 
 clang/test/Driver/darwin-ld.c  |  8 ++--
 2 files changed, 14 insertions(+), 10 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp 
b/clang/lib/Driver/ToolChains/Darwin.cpp
index 757ba50e4c865..acc0f9ca59316 100644
--- a/clang/lib/Driver/ToolChains/Darwin.cpp
+++ b/clang/lib/Driver/ToolChains/Darwin.cpp
@@ -1642,14 +1642,14 @@ void DarwinClang::AddLinkRuntimeLibArgs(const ArgList 
&Args,
 C

[clang-tools-extra] [clang-doc] [feat] add --repository-line-prefix argument (PR #131280)

2025-03-27 Thread Mohamed Emad via cfe-commits

https://github.com/hulxv updated 
https://github.com/llvm/llvm-project/pull/131280

>From bf9bd4156cb7f652c9cf0477f537e5c58b470448 Mon Sep 17 00:00:00 2001
From: hulxv 
Date: Fri, 14 Mar 2025 07:39:15 +0200
Subject: [PATCH 01/16] [clang-doc] [feat] add `--repository-line-prefix`
 argument (fix #59814)

---
 clang-tools-extra/clang-doc/HTMLGenerator.cpp | 66 ---
 clang-tools-extra/clang-doc/MDGenerator.cpp   |  7 +-
 .../clang-doc/Representation.cpp  |  4 ++
 clang-tools-extra/clang-doc/Representation.h  |  5 +-
 .../clang-doc/tool/ClangDocMain.cpp   | 13 ++--
 5 files changed, 64 insertions(+), 31 deletions(-)

diff --git a/clang-tools-extra/clang-doc/HTMLGenerator.cpp 
b/clang-tools-extra/clang-doc/HTMLGenerator.cpp
index 18a0de826630c..967275f93193b 100644
--- a/clang-tools-extra/clang-doc/HTMLGenerator.cpp
+++ b/clang-tools-extra/clang-doc/HTMLGenerator.cpp
@@ -491,9 +491,9 @@ genReferencesBlock(const std::vector &References,
   return Out;
 }
 
-static std::unique_ptr
-writeFileDefinition(const Location &L,
-std::optional RepositoryUrl = std::nullopt) {
+static std::unique_ptr writeFileDefinition(
+const Location &L, std::optional RepositoryUrl = std::nullopt,
+std::optional RepositoryLinePrefix = std::nullopt) {
   if (!L.IsFileInRootDir && !RepositoryUrl)
 return std::make_unique(
 HTMLTag::TAG_P, "Defined at line " + std::to_string(L.LineNumber) +
@@ -514,17 +514,21 @@ writeFileDefinition(const Location &L,
   Node->Children.emplace_back(std::make_unique("Defined at line "));
   auto LocNumberNode =
   std::make_unique(HTMLTag::TAG_A, std::to_string(L.LineNumber));
-  // The links to a specific line in the source code use the github /
-  // googlesource notation so it won't work for all hosting pages.
-  // FIXME: we probably should have a configuration setting for line number
-  // rendering in the HTML. For example, GitHub uses #L22, while googlesource
-  // uses #22 for line numbers.
-  LocNumberNode->Attributes.emplace_back(
-  "href", (FileURL + "#" + std::to_string(L.LineNumber)).str());
+
+  std::string LineAnchor = "#";
+
+  if (RepositoryLinePrefix)
+LineAnchor += RepositoryLinePrefix.value().str();
+
+  LineAnchor += std::to_string(L.LineNumber);
+
+  LocNumberNode->Attributes.emplace_back("href", (FileURL + LineAnchor).str());
   Node->Children.emplace_back(std::move(LocNumberNode));
   Node->Children.emplace_back(std::make_unique(" of file "));
+
   auto LocFileNode = std::make_unique(
   HTMLTag::TAG_A, llvm::sys::path::filename(FileURL));
+
   LocFileNode->Attributes.emplace_back("href", std::string(FileURL));
   Node->Children.emplace_back(std::move(LocFileNode));
   return Node;
@@ -750,11 +754,15 @@ genHTML(const EnumInfo &I, const ClangDocContext &CDCtx) {
   Out.emplace_back(std::move(Table));
 
   if (I.DefLoc) {
-if (!CDCtx.RepositoryUrl)
-  Out.emplace_back(writeFileDefinition(*I.DefLoc));
-else
-  Out.emplace_back(
-  writeFileDefinition(*I.DefLoc, StringRef{*CDCtx.RepositoryUrl}));
+std::optional RepoUrl;
+std::optional RepoLinePrefix;
+
+if (CDCtx.RepositoryUrl)
+  RepoUrl = StringRef{*CDCtx.RepositoryUrl};
+if (CDCtx.RepositoryLinePrefix)
+  RepoLinePrefix = StringRef{*CDCtx.RepositoryLinePrefix};
+
+Out.emplace_back(writeFileDefinition(*I.DefLoc, RepoUrl, RepoLinePrefix));
   }
 
   std::string Description;
@@ -799,11 +807,15 @@ genHTML(const FunctionInfo &I, const ClangDocContext 
&CDCtx,
   FunctionHeader->Children.emplace_back(std::make_unique(")"));
 
   if (I.DefLoc) {
-if (!CDCtx.RepositoryUrl)
-  Out.emplace_back(writeFileDefinition(*I.DefLoc));
-else
-  Out.emplace_back(writeFileDefinition(
-  *I.DefLoc, StringRef{*CDCtx.RepositoryUrl}));
+std::optional RepoUrl;
+std::optional RepoLinePrefix;
+
+if (CDCtx.RepositoryUrl)
+  RepoUrl = StringRef{*CDCtx.RepositoryUrl};
+if (CDCtx.RepositoryLinePrefix)
+  RepoLinePrefix = StringRef{*CDCtx.RepositoryLinePrefix};
+
+Out.emplace_back(writeFileDefinition(*I.DefLoc, RepoUrl, RepoLinePrefix));
   }
 
   std::string Description;
@@ -866,11 +878,15 @@ genHTML(const RecordInfo &I, Index &InfoIndex, const 
ClangDocContext &CDCtx,
   Out.emplace_back(std::make_unique(HTMLTag::TAG_H1, InfoTitle));
 
   if (I.DefLoc) {
-if (!CDCtx.RepositoryUrl)
-  Out.emplace_back(writeFileDefinition(*I.DefLoc));
-else
-  Out.emplace_back(writeFileDefinition(
-  *I.DefLoc, StringRef{*CDCtx.RepositoryUrl}));
+std::optional RepoUrl;
+std::optional RepoLinePrefix;
+
+if (CDCtx.RepositoryUrl)
+  RepoUrl = StringRef{*CDCtx.RepositoryUrl};
+if (CDCtx.RepositoryLinePrefix)
+  RepoLinePrefix = StringRef{*CDCtx.RepositoryLinePrefix};
+
+Out.emplace_back(writeFileDefinition(*I.DefLoc, RepoUrl, RepoLinePrefix));
   }
 
   std::string Description;
diff --git a/clang-tools-extra/clang-doc/MDGenerator.cpp 
b/clang-too

[clang] [flang] [libcxx] [llvm] [llvm-reduce]: print short form, actionable names in the log (PR #132813)

2025-03-27 Thread Matt Arsenault via cfe-commits


@@ -17,8 +17,8 @@
 #include "Delta.h"
 
 namespace llvm {
-void reduceAliasesDeltaPass(TestRunner &Test);
-void reduceIFuncsDeltaPass(TestRunner &Test);
+void reduceAliasesDeltaPass(TestRunner &Test, StringRef PassMessage);

arsenm wrote:

Returning the function_ref is an unnecessary indirection. The entry point 
signatures should just change to void(Oracle &, ReducerWorkitem&). The table 
can directly refer to those 

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


[clang] [NFC] [dataflow] generalize smart pointer caching (PR #133350)

2025-03-27 Thread Florian Mayer via cfe-commits

https://github.com/fmayer updated 
https://github.com/llvm/llvm-project/pull/133350

>From 8ece858e76fad0962b2567f03bf80bcaf2828348 Mon Sep 17 00:00:00 2001
From: Florian Mayer 
Date: Thu, 27 Mar 2025 18:25:23 -0700
Subject: [PATCH 1/4] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20in?=
 =?UTF-8?q?itial=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.4
---
 .../SmartPointerAccessorCaching.h |   6 +-
 .../SmartPointerAccessorCaching.cpp   | 125 ++
 .../SmartPointerAccessorCachingTest.cpp   |  40 ++
 3 files changed, 114 insertions(+), 57 deletions(-)

diff --git 
a/clang/include/clang/Analysis/FlowSensitive/SmartPointerAccessorCaching.h 
b/clang/include/clang/Analysis/FlowSensitive/SmartPointerAccessorCaching.h
index b4291347e0969..e55b83aa845d4 100644
--- a/clang/include/clang/Analysis/FlowSensitive/SmartPointerAccessorCaching.h
+++ b/clang/include/clang/Analysis/FlowSensitive/SmartPointerAccessorCaching.h
@@ -62,8 +62,10 @@ ast_matchers::StatementMatcher isPointerLikeOperatorStar();
 ast_matchers::StatementMatcher isSmartPointerLikeOperatorStar();
 ast_matchers::StatementMatcher isPointerLikeOperatorArrow();
 ast_matchers::StatementMatcher isSmartPointerLikeOperatorArrow();
-ast_matchers::StatementMatcher isSmartPointerLikeValueMethodCall();
-ast_matchers::StatementMatcher isSmartPointerLikeGetMethodCall();
+ast_matchers::StatementMatcher
+isSmartPointerLikeValueMethodCall(clang::StringRef MethodName = "value");
+ast_matchers::StatementMatcher
+isSmartPointerLikeGetMethodCall(clang::StringRef MethodName = "get");
 
 // Common transfer functions.
 
diff --git a/clang/lib/Analysis/FlowSensitive/SmartPointerAccessorCaching.cpp 
b/clang/lib/Analysis/FlowSensitive/SmartPointerAccessorCaching.cpp
index 0860cc1dbaf8e..638f5211152b2 100644
--- a/clang/lib/Analysis/FlowSensitive/SmartPointerAccessorCaching.cpp
+++ b/clang/lib/Analysis/FlowSensitive/SmartPointerAccessorCaching.cpp
@@ -2,6 +2,7 @@
 
 #include "clang/AST/CanonicalType.h"
 #include "clang/AST/DeclCXX.h"
+#include "clang/AST/Type.h"
 #include "clang/ASTMatchers/ASTMatchers.h"
 #include "clang/ASTMatchers/ASTMatchersMacros.h"
 #include "clang/Basic/OperatorKinds.h"
@@ -23,8 +24,7 @@ using ast_matchers::pointerType;
 using ast_matchers::referenceType;
 using ast_matchers::returns;
 
-bool hasSmartPointerClassShape(const CXXRecordDecl &RD, bool &HasGet,
-   bool &HasValue) {
+CanQualType pointerLikeReturnType(const CXXRecordDecl &RD) {
   // We may want to cache this search, but in current profiles it hasn't shown
   // up as a hot spot (possibly because there aren't many hits, relatively).
   bool HasArrow = false;
@@ -55,38 +55,47 @@ bool hasSmartPointerClassShape(const CXXRecordDecl &RD, 
bool &HasGet,
   .getUnqualifiedType();
   }
   break;
-case OO_None: {
-  IdentifierInfo *II = MD->getIdentifier();
-  if (II == nullptr)
-continue;
-  if (II->isStr("get")) {
-if (MD->getReturnType()->isPointerType()) {
-  HasGet = true;
-  GetReturnType = MD->getReturnType()
-  ->getPointeeType()
-  ->getCanonicalTypeUnqualified()
-  .getUnqualifiedType();
-}
-  } else if (II->isStr("value")) {
-if (MD->getReturnType()->isReferenceType()) {
-  HasValue = true;
-  ValueReturnType = MD->getReturnType()
-.getNonReferenceType()
-->getCanonicalTypeUnqualified()
-.getUnqualifiedType();
-}
-  }
-} break;
 default:
   break;
 }
   }
+  if (HasStar && HasArrow && StarReturnType == ArrowReturnType)
+return StarReturnType;
 
-  if (!HasStar || !HasArrow || StarReturnType != ArrowReturnType)
-return false;
-  HasGet = HasGet && (GetReturnType == StarReturnType);
-  HasValue = HasValue && (ValueReturnType == StarReturnType);
-  return true;
+  return {};
+}
+CanQualType getLikeReturnType(QualType RT) {
+  if (!RT.isNull() && RT->isPointerType()) {
+return RT->getPointeeType()
+->getCanonicalTypeUnqualified()
+.getUnqualifiedType();
+  }
+  return {};
+}
+
+CanQualType valueLikeReturnType(QualType RT) {
+  if (!RT.isNull() && RT->isReferenceType()) {
+return RT.getNonReferenceType()
+->getCanonicalTypeUnqualified()
+.getUnqualifiedType();
+  }
+  return {};
+}
+
+QualType findReturnType(const CXXRecordDecl &RD, StringRef MethodName) {
+  for (const auto *MD : RD.methods()) {
+// We only consider methods that are const and have zero parameters.
+// It may be that there is a non-const overload for the method, but
+// there should at least be a const overload as well.
+if (!MD->isConst() || MD->getNumParams() != 0 ||
+MD->getOverloadedOp

[clang] cb80b26 - [clang] Use *Set::insert_range (NFC) (#133357)

2025-03-27 Thread via cfe-commits

Author: Kazu Hirata
Date: 2025-03-27T20:14:25-07:00
New Revision: cb80b26e3731e7b10ff516d66761a3cfbc55bd20

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

LOG: [clang] Use *Set::insert_range (NFC) (#133357)

We can use *Set::insert_range to collapse:

  for (auto Elem : Range)
Set.insert(E);

down to:

  Set.insert_range(Range);

In some cases, we can further fold that into the set declaration.

Added: 


Modified: 
clang/lib/Analysis/FlowSensitive/ASTOps.cpp
clang/lib/Basic/TargetID.cpp
clang/lib/CodeGen/CGDeclCXX.cpp
clang/lib/Sema/SemaChecking.cpp
clang/lib/Sema/SemaObjCProperty.cpp
clang/utils/TableGen/ClangOpenCLBuiltinEmitter.cpp

Removed: 




diff  --git a/clang/lib/Analysis/FlowSensitive/ASTOps.cpp 
b/clang/lib/Analysis/FlowSensitive/ASTOps.cpp
index 9a46e79cf4a67..431b1f2038357 100644
--- a/clang/lib/Analysis/FlowSensitive/ASTOps.cpp
+++ b/clang/lib/Analysis/FlowSensitive/ASTOps.cpp
@@ -64,8 +64,7 @@ static void getFieldsFromClassHierarchy(QualType Type, 
FieldSet &Fields) {
   !Type->isRecordType())
 return;
 
-  for (const FieldDecl *Field : Type->getAsRecordDecl()->fields())
-Fields.insert(Field);
+  Fields.insert_range(Type->getAsRecordDecl()->fields());
   if (auto *CXXRecord = Type->getAsCXXRecordDecl())
 for (const CXXBaseSpecifier &Base : CXXRecord->bases())
   getFieldsFromClassHierarchy(Base.getType(), Fields);
@@ -260,15 +259,13 @@ class ReferencedDeclsVisitor : public AnalysisASTVisitor {
 
   bool VisitInitListExpr(InitListExpr *InitList) override {
 if (InitList->getType()->isRecordType())
-  for (const auto *FD : getFieldsForInitListExpr(InitList))
-Referenced.Fields.insert(FD);
+  Referenced.Fields.insert_range(getFieldsForInitListExpr(InitList));
 return true;
   }
 
   bool VisitCXXParenListInitExpr(CXXParenListInitExpr *ParenInitList) override 
{
 if (ParenInitList->getType()->isRecordType())
-  for (const auto *FD : getFieldsForInitListExpr(ParenInitList))
-Referenced.Fields.insert(FD);
+  Referenced.Fields.insert_range(getFieldsForInitListExpr(ParenInitList));
 return true;
   }
 

diff  --git a/clang/lib/Basic/TargetID.cpp b/clang/lib/Basic/TargetID.cpp
index b42d1f07013c2..2a2f23409e896 100644
--- a/clang/lib/Basic/TargetID.cpp
+++ b/clang/lib/Basic/TargetID.cpp
@@ -113,9 +113,8 @@ parseTargetID(const llvm::Triple &T, llvm::StringRef 
TargetID,
   if (Processor.empty())
 return std::nullopt;
 
-  llvm::SmallSet AllFeatures;
-  for (auto &&F : getAllPossibleTargetIDFeatures(T, Processor))
-AllFeatures.insert(F);
+  llvm::SmallSet AllFeatures(
+  llvm::from_range, getAllPossibleTargetIDFeatures(T, Processor));
 
   for (auto &&F : *FeatureMap)
 if (!AllFeatures.count(F.first()))

diff  --git a/clang/lib/CodeGen/CGDeclCXX.cpp b/clang/lib/CodeGen/CGDeclCXX.cpp
index 1ad34ae61f96a..a01fa157c2b26 100644
--- a/clang/lib/CodeGen/CGDeclCXX.cpp
+++ b/clang/lib/CodeGen/CGDeclCXX.cpp
@@ -703,8 +703,7 @@ void CodeGenModule::EmitCXXModuleInitFunc(Module *Primary) {
   for (auto I : Primary->Exports)
 AllImports.insert(I.getPointer());
   // Ones that we only import.
-  for (Module *M : Primary->Imports)
-AllImports.insert(M);
+  AllImports.insert_range(Primary->Imports);
   // Ones that we import in the global module fragment or the private module
   // fragment.
   for (Module *SubM : Primary->submodules()) {
@@ -714,8 +713,7 @@ void CodeGenModule::EmitCXXModuleInitFunc(Module *Primary) {
 assert(SubM->Exports.empty() &&
"The global mdoule fragments and the private module fragments are "
"not allowed to export import modules.");
-for (Module *M : SubM->Imports)
-  AllImports.insert(M);
+AllImports.insert_range(SubM->Imports);
   }
 
   SmallVector ModuleInits;

diff  --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 12a8894cc7f47..5a4fa97366809 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -14731,9 +14731,8 @@ static bool isLayoutCompatibleStruct(const ASTContext 
&C, const RecordDecl *RD1,
 /// (C++11 [class.mem] p18)
 static bool isLayoutCompatibleUnion(const ASTContext &C, const RecordDecl *RD1,
 const RecordDecl *RD2) {
-  llvm::SmallPtrSet UnmatchedFields;
-  for (auto *Field2 : RD2->fields())
-UnmatchedFields.insert(Field2);
+  llvm::SmallPtrSet UnmatchedFields(llvm::from_range,
+  RD2->fields());
 
   for (auto *Field1 : RD1->fields()) {
 auto I = UnmatchedFields.begin();

diff  --git a/clang/lib/Sema/SemaObjCProperty.cpp 
b/clang/lib/Sema/SemaObjCProperty.cpp
index 93a17e8459811..6db2c246de791 100644
--- a/clang/lib/Sema/SemaObj

[clang] [llvm] [HLSL] Implement dot2add intrinsic (PR #131237)

2025-03-27 Thread Farzon Lotfi via cfe-commits

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


[clang-tools-extra] [clang-doc] [feat] add --repository-line-prefix argument (PR #131280)

2025-03-27 Thread Paul Kirth via cfe-commits


@@ -516,15 +518,16 @@ writeFileDefinition(const Location &L,
   std::make_unique(HTMLTag::TAG_A, std::to_string(L.LineNumber));
   // The links to a specific line in the source code use the github /
   // googlesource notation so it won't work for all hosting pages.
-  // FIXME: we probably should have a configuration setting for line number
-  // rendering in the HTML. For example, GitHub uses #L22, while googlesource
-  // uses #22 for line numbers.
-  LocNumberNode->Attributes.emplace_back(
-  "href", (FileURL + "#" + std::to_string(L.LineNumber)).str());
+  std::string LineAnchor =
+  formatv("#{0}{1}", RepositoryLinePrefix, L.LineNumber);

ilovepi wrote:

Why use an `std::string` here and then concatenate below? wouldn't it be easier 
to simply use `formatv` for the whole thing below?

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


[clang] [HLSL] Finish exposing half types and intrinsics always (PR #132804)

2025-03-27 Thread Sarah Spall via cfe-commits

https://github.com/spall created 
https://github.com/llvm/llvm-project/pull/132804

Finish the work of #81782 
Closes #132793 

>From 140b17c6972ac7f867dc342f29121d71e079c9db Mon Sep 17 00:00:00 2001
From: Sarah Spall 
Date: Mon, 24 Mar 2025 11:38:21 -0700
Subject: [PATCH] half overloads are defined all the time

---
 .../lib/Headers/hlsl/hlsl_alias_intrinsics.h  | 48 ---
 1 file changed, 32 insertions(+), 16 deletions(-)

diff --git a/clang/lib/Headers/hlsl/hlsl_alias_intrinsics.h 
b/clang/lib/Headers/hlsl/hlsl_alias_intrinsics.h
index 585e905c7bf5d..d1e23007f92ff 100644
--- a/clang/lib/Headers/hlsl/hlsl_alias_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_alias_intrinsics.h
@@ -134,16 +134,18 @@ double4 abs(double4);
 /// \brief Returns the arccosine of the input value, \a Val.
 /// \param Val The input value.
 
-#ifdef __HLSL_ENABLE_16_BIT
+_HLSL_AVAILABILITY(shadermodel, 6.2)
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_acos)
 half acos(half);
+_HLSL_AVAILABILITY(shadermodel, 6.2)
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_acos)
 half2 acos(half2);
+_HLSL_AVAILABILITY(shadermodel, 6.2)
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_acos)
 half3 acos(half3);
+_HLSL_AVAILABILITY(shadermodel, 6.2)
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_acos)
 half4 acos(half4);
-#endif
 
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_acos)
 float acos(float);
@@ -447,16 +449,18 @@ double4 asdouble(uint4, uint4);
 /// \brief Returns the arcsine of the input value, \a Val.
 /// \param Val The input value.
 
-#ifdef __HLSL_ENABLE_16_BIT
+_HLSL_AVAILABILITY(shadermodel, 6.2)
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_asin)
 half asin(half);
+_HLSL_AVAILABILITY(shadermodel, 6.2)
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_asin)
 half2 asin(half2);
+_HLSL_AVAILABILITY(shadermodel, 6.2)
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_asin)
 half3 asin(half3);
+_HLSL_AVAILABILITY(shadermodel, 6.2)
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_asin)
 half4 asin(half4);
-#endif
 
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_asin)
 float asin(float);
@@ -475,16 +479,18 @@ float4 asin(float4);
 /// \brief Returns the arctangent of the input value, \a Val.
 /// \param Val The input value.
 
-#ifdef __HLSL_ENABLE_16_BIT
+_HLSL_AVAILABILITY(shadermodel, 6.2)
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_atan)
 half atan(half);
+_HLSL_AVAILABILITY(shadermodel, 6.2)
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_atan)
 half2 atan(half2);
+_HLSL_AVAILABILITY(shadermodel, 6.2)
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_atan)
 half3 atan(half3);
+_HLSL_AVAILABILITY(shadermodel, 6.2)
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_atan)
 half4 atan(half4);
-#endif
 
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_atan)
 float atan(float);
@@ -505,16 +511,18 @@ float4 atan(float4);
 /// \param y The y-coordinate.
 /// \param x The x-coordinate.
 
-#ifdef __HLSL_ENABLE_16_BIT
+_HLSL_AVAILABILITY(shadermodel, 6.2)
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_atan2)
 half atan2(half y, half x);
+_HLSL_AVAILABILITY(shadermodel, 6.2)
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_atan2)
 half2 atan2(half2 y, half2 x);
+_HLSL_AVAILABILITY(shadermodel, 6.2)
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_atan2)
 half3 atan2(half3 y, half3 x);
+_HLSL_AVAILABILITY(shadermodel, 6.2)
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_atan2)
 half4 atan2(half4 y, half4 x);
-#endif
 
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_atan2)
 float atan2(float y, float x);
@@ -721,16 +729,18 @@ float4 cos(float4);
 /// \brief Returns the hyperbolic cosine of the input value, \a Val.
 /// \param Val The input value.
 
-#ifdef __HLSL_ENABLE_16_BIT
+_HLSL_AVAILABILITY(shadermodel, 6.2)
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_cosh)
 half cosh(half);
+_HLSL_AVAILABILITY(shadermodel, 6.2)
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_cosh)
 half2 cosh(half2);
+_HLSL_AVAILABILITY(shadermodel, 6.2)
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_cosh)
 half3 cosh(half3);
+_HLSL_AVAILABILITY(shadermodel, 6.2)
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_cosh)
 half4 cosh(half4);
-#endif
 
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_cosh)
 float cosh(float);
@@ -2124,16 +2134,18 @@ float4 sin(float4);
 /// \brief Returns the hyperbolic sine of the input value, \a Val.
 /// \param Val The input value.
 
-#ifdef __HLSL_ENABLE_16_BIT
+_HLSL_AVAILABILITY(shadermodel, 6.2)
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_sinh)
 half sinh(half);
+_HLSL_AVAILABILITY(shadermodel, 6.2)
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_sinh)
 half2 sinh(half2);
+_HLSL_AVAILABILITY(shadermodel, 6.2)
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_sinh)
 half3 sinh(half3);
+_HLSL_AVAILABILITY(shadermodel, 6.2)
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_sinh)
 half4 sinh(half4);
-#endif
 
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_sinh)
 float sinh(float);
@@ -2215,16 +2227,18 @@ float4 step(float4, float4);
 /// \brief Returns the tangent of the input value, \a Val.
 /// \param Val The input value.
 
-#ifdef __HLSL_ENABLE_16_BIT
+_HLSL_AVAILABILIT

[clang] [clang] fix structural comparison for dependent class member pointer (PR #133343)

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

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

Honestly I have no idea what's going wrong here. But please go on to get rid of 
these bugs. Thanks!

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


[clang] [Clang] Check PP presence when printing stats (PR #131608)

2025-03-27 Thread Qiu Chaofan via cfe-commits

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


  1   2   3   4   5   >