[clang] [LoongArch][Clang] Make the parameters and return value of {x,}vorn.v builti ns `unsigned char` vectors (PR #114514)

2024-11-04 Thread Xi Ruoyao via cfe-commits

https://github.com/xry111 updated 
https://github.com/llvm/llvm-project/pull/114514

>From bfd9e855bc1c91bee6c39e388f20be48db8dfd8f Mon Sep 17 00:00:00 2001
From: Xi Ruoyao 
Date: Fri, 1 Nov 2024 00:28:12 +0800
Subject: [PATCH] [LoongArch][Clang] Make the parameters and return value of
 {x,}vorn.v builtins `unsigned char` vectors

All other bitwise vector builtins use `unsigned char` vector operands,
so it does not make too much sense to use `signed char` for the orn
operation alone.

The same change has been also proposed for GCC:
https://gcc.gnu.org/pipermail/gcc-patches/2024-October/667065.html.
---
 clang/include/clang/Basic/BuiltinsLoongArchLASX.def | 2 +-
 clang/include/clang/Basic/BuiltinsLoongArchLSX.def  | 2 +-
 clang/lib/Headers/lasxintrin.h  | 2 +-
 clang/lib/Headers/lsxintrin.h   | 2 +-
 4 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/clang/include/clang/Basic/BuiltinsLoongArchLASX.def 
b/clang/include/clang/Basic/BuiltinsLoongArchLASX.def
index f644b820a61898..c4ea46a3bc5b51 100644
--- a/clang/include/clang/Basic/BuiltinsLoongArchLASX.def
+++ b/clang/include/clang/Basic/BuiltinsLoongArchLASX.def
@@ -371,7 +371,7 @@ TARGET_BUILTIN(__builtin_lasx_xvor_v, "V32UcV32UcV32Uc", 
"nc", "lasx")
 TARGET_BUILTIN(__builtin_lasx_xvxor_v, "V32UcV32UcV32Uc", "nc", "lasx")
 TARGET_BUILTIN(__builtin_lasx_xvnor_v, "V32UcV32UcV32Uc", "nc", "lasx")
 TARGET_BUILTIN(__builtin_lasx_xvandn_v, "V32UcV32UcV32Uc", "nc", "lasx")
-TARGET_BUILTIN(__builtin_lasx_xvorn_v, "V32ScV32ScV32Sc", "nc", "lasx")
+TARGET_BUILTIN(__builtin_lasx_xvorn_v, "V32UcV32UcV32Uc", "nc", "lasx")
 
 TARGET_BUILTIN(__builtin_lasx_xvandi_b, "V32UcV32UcIUi", "nc", "lasx")
 TARGET_BUILTIN(__builtin_lasx_xvori_b, "V32UcV32UcIUi", "nc", "lasx")
diff --git a/clang/include/clang/Basic/BuiltinsLoongArchLSX.def 
b/clang/include/clang/Basic/BuiltinsLoongArchLSX.def
index b3056971986d19..a823783af88c4f 100644
--- a/clang/include/clang/Basic/BuiltinsLoongArchLSX.def
+++ b/clang/include/clang/Basic/BuiltinsLoongArchLSX.def
@@ -355,7 +355,7 @@ TARGET_BUILTIN(__builtin_lsx_vor_v, "V16UcV16UcV16Uc", 
"nc", "lsx")
 TARGET_BUILTIN(__builtin_lsx_vxor_v, "V16UcV16UcV16Uc", "nc", "lsx")
 TARGET_BUILTIN(__builtin_lsx_vnor_v, "V16UcV16UcV16Uc", "nc", "lsx")
 TARGET_BUILTIN(__builtin_lsx_vandn_v, "V16UcV16UcV16Uc", "nc", "lsx")
-TARGET_BUILTIN(__builtin_lsx_vorn_v, "V16ScV16ScV16Sc", "nc", "lsx")
+TARGET_BUILTIN(__builtin_lsx_vorn_v, "V16UcV16UcV16Uc", "nc", "lsx")
 
 TARGET_BUILTIN(__builtin_lsx_vandi_b, "V16UcV16UcIUi", "nc", "lsx")
 TARGET_BUILTIN(__builtin_lsx_vori_b, "V16UcV16UcIUi", "nc", "lsx")
diff --git a/clang/lib/Headers/lasxintrin.h b/clang/lib/Headers/lasxintrin.h
index dafc2a2f3e6a70..c065ea92a2dd52 100644
--- a/clang/lib/Headers/lasxintrin.h
+++ b/clang/lib/Headers/lasxintrin.h
@@ -2585,7 +2585,7 @@ extern __inline
 extern __inline
 __attribute__((__gnu_inline__, __always_inline__, __artificial__)) __m256i
 __lasx_xvorn_v(__m256i _1, __m256i _2) {
-  return (__m256i)__builtin_lasx_xvorn_v((v32i8)_1, (v32i8)_2);
+  return (__m256i)__builtin_lasx_xvorn_v((v32u8)_1, (v32u8)_2);
 }
 
 #define __lasx_xvldi(/*i13*/ _1) ((__m256i)__builtin_lasx_xvldi((_1)))
diff --git a/clang/lib/Headers/lsxintrin.h b/clang/lib/Headers/lsxintrin.h
index f347955ce6fb51..f020b0c18f0d29 100644
--- a/clang/lib/Headers/lsxintrin.h
+++ b/clang/lib/Headers/lsxintrin.h
@@ -3425,7 +3425,7 @@ extern __inline
 extern __inline
 __attribute__((__gnu_inline__, __always_inline__, __artificial__)) __m128i
 __lsx_vorn_v(__m128i _1, __m128i _2) {
-  return (__m128i)__builtin_lsx_vorn_v((v16i8)_1, (v16i8)_2);
+  return (__m128i)__builtin_lsx_vorn_v((v16u8)_1, (v16u8)_2);
 }
 
 #define __lsx_vldi(/*i13*/ _1) ((__m128i)__builtin_lsx_vldi((_1)))

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


[clang] f96ea89 - [APINotes] Document immortal reference type annotation

2024-11-04 Thread via cfe-commits

Author: Egor Zhdan
Date: 2024-11-04T11:43:20Z
New Revision: f96ea8983b8edc941107c7df2e4f08b44a1663d0

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

LOG: [APINotes] Document immortal reference type annotation

API Notes allow annotating a C++ reference type with its retain/release
operations. These are honored by the Swift compiler when the type is
used from Swift. Apart from names of C++ functions that need to be
called to retain/release the object, API Notes also accept a value of
`immortal` which indicates that the object is to be considered alive for
the duration of the program.

Added: 


Modified: 
clang/docs/APINotes.rst

Removed: 




diff  --git a/clang/docs/APINotes.rst b/clang/docs/APINotes.rst
index dcefa6810dac67..d20c4f9b5ba843 100644
--- a/clang/docs/APINotes.rst
+++ b/clang/docs/APINotes.rst
@@ -169,6 +169,20 @@ declaration kind), all of which are optional:
   to ``SWIFT_RETURNS_INDEPENDENT_VALUE``) or ``computed_property`` (equivalent 
to
   ``SWIFT_COMPUTED_PROPERTY``).
 
+  ::
+
+Tags:
+- Name: OwnedStorage
+  SwiftImportAs: owned
+
+:SwiftRetainOp, SwiftReleaseOp:
+
+  Controls the lifetime operations of a class which uses custom reference
+  counting. The class must be annotated as a reference type using
+  ``SwiftImportAs: reference``. The values are either names of global 
functions,
+  each taking a single parameter of a pointer type, or ``immortal`` for a type
+  that is considered alive for the duration of the program.
+
   ::
 
 Tags:
@@ -176,6 +190,10 @@ declaration kind), all of which are optional:
   SwiftImportAs: reference
   SwiftReleaseOp: RCRelease
   SwiftRetainOp: RCRetain
+- Name: ImmortalSingleton
+  SwiftImportAs: reference
+  SwiftReleaseOp: immortal
+  SwiftRetainOp: immortal
 
 :SwiftCopyable:
 



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


[clang] Add -mno-unaligned-access and -mbig-endian to ARM and AArch64 multilib flags (PR #114782)

2024-11-04 Thread via cfe-commits

https://github.com/simpal01 created 
https://github.com/llvm/llvm-project/pull/114782

This adds the -mno-unaligned-access and -mbig-endian command line options to 
the set of flags used by the multilib selection for ARM and AArch64 targets.

>From 4a06df9bec87882964e0892b50dd9a81d5e1e6ac Mon Sep 17 00:00:00 2001
From: Simi Pallipurath 
Date: Mon, 4 Nov 2024 12:02:29 +
Subject: [PATCH] Add -mno-unaligned-access and -mbig-endian to ARM and AArch64
 multilib flags.

---
 clang/lib/Driver/ToolChain.cpp| 25 +++
 .../test/Driver/print-multi-selection-flags.c |  8 ++
 2 files changed, 33 insertions(+)

diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index bdf3da0c96adca..dec9af62ad79e4 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -230,6 +230,18 @@ static void getAArch64MultilibFlags(const Driver &D,
 Result.push_back(BranchProtectionArg->getAsString(Args));
   }
 
+  const Arg *StrictAlignArg =
+  Args.getLastArgNoClaim(options::OPT_mstrict_align, 
options::OPT_mno_unaligned_access);
+  if (StrictAlignArg) {
+Result.push_back(StrictAlignArg->getAsString(Args));
+  }
+
+  const Arg *BigEndian =
+  Args.getLastArgNoClaim(options::OPT_mbig_endian);
+  if (BigEndian) {
+Result.push_back(BigEndian->getAsString(Args));
+  }
+
   const Arg *ABIArg = Args.getLastArgNoClaim(options::OPT_mabi_EQ);
   if (ABIArg) {
 Result.push_back(ABIArg->getAsString(Args));
@@ -287,6 +299,19 @@ static void getARMMultilibFlags(const Driver &D,
   if (BranchProtectionArg) {
 Result.push_back(BranchProtectionArg->getAsString(Args));
   }
+
+  const Arg *StrictAlignArg =
+  Args.getLastArgNoClaim(options::OPT_mstrict_align, options::
+OPT_mno_unaligned_access);
+  if (StrictAlignArg) {
+Result.push_back(StrictAlignArg->getAsString(Args));
+  }
+
+  const Arg *BigEndian =
+  Args.getLastArgNoClaim(options::OPT_mbig_endian);
+  if (BigEndian) {
+Result.push_back(BigEndian->getAsString(Args));
+  }
 }
 
 static void getRISCVMultilibFlags(const Driver &D, const llvm::Triple &Triple,
diff --git a/clang/test/Driver/print-multi-selection-flags.c 
b/clang/test/Driver/print-multi-selection-flags.c
index 4bb62665ad8981..5bf6dca5096a73 100644
--- a/clang/test/Driver/print-multi-selection-flags.c
+++ b/clang/test/Driver/print-multi-selection-flags.c
@@ -68,6 +68,14 @@
 // RUN: %clang -multi-lib-config=%S/Inputs/multilib/empty.yaml 
-print-multi-flags-experimental --target=aarch64-none-elf 
-mbranch-protection=standard | FileCheck --check-prefix=CHECK-BRANCH-PROTECTION 
%s
 // CHECK-BRANCH-PROTECTION: -mbranch-protection=standard
 
+// RUN: %clang -multi-lib-config=%S/Inputs/multilib/empty.yaml 
-print-multi-flags-experimental --target=arm-none-eabi -mno-unaligned-access | 
FileCheck --check-prefix=CHECK-NO-UNALIGNED-ACCESS %s
+// RUN: %clang -multi-lib-config=%S/Inputs/multilib/empty.yaml 
-print-multi-flags-experimental --target=aarch64-none-elf -mno-unaligned-access 
| FileCheck --check-prefix=CHECK-NO-UNALIGNED-ACCESS %s
+// CHECK-NO-UNALIGNED-ACCESS: -mno-unaligned-access
+
+// RUN: %clang -multi-lib-config=%S/Inputs/multilib/empty.yaml 
-print-multi-flags-experimental --target=arm-none-eabi -mbig-endian | FileCheck 
--check-prefix=CHECK-BIG-ENDIAN %s
+// RUN: %clang -multi-lib-config=%S/Inputs/multilib/empty.yaml 
-print-multi-flags-experimental --target=aarch64-none-elf -mbig-endian | 
FileCheck --check-prefix=CHECK-BIG-ENDIAN %s
+// CHECK-BIG-ENDIAN: -mbig-endian
+
 // RUN: %clang -multi-lib-config=%S/Inputs/multilib/empty.yaml 
-print-multi-flags-experimental --target=riscv32-none-elf -march=rv32g | 
FileCheck --check-prefix=CHECK-RV32 %s
 // CHECK-RV32: --target=riscv32-unknown-none-elf
 // CHECK-RV32: -mabi=ilp32d

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


[clang] Add -mno-unaligned-access and -mbig-endian to ARM and AArch64 multilib flags (PR #114782)

2024-11-04 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-driver

Author: None (simpal01)


Changes

This adds the -mno-unaligned-access and -mbig-endian command line options to 
the set of flags used by the multilib selection for ARM and AArch64 targets.

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


2 Files Affected:

- (modified) clang/lib/Driver/ToolChain.cpp (+25) 
- (modified) clang/test/Driver/print-multi-selection-flags.c (+8) 


``diff
diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index bdf3da0c96adca..dec9af62ad79e4 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -230,6 +230,18 @@ static void getAArch64MultilibFlags(const Driver &D,
 Result.push_back(BranchProtectionArg->getAsString(Args));
   }
 
+  const Arg *StrictAlignArg =
+  Args.getLastArgNoClaim(options::OPT_mstrict_align, 
options::OPT_mno_unaligned_access);
+  if (StrictAlignArg) {
+Result.push_back(StrictAlignArg->getAsString(Args));
+  }
+
+  const Arg *BigEndian =
+  Args.getLastArgNoClaim(options::OPT_mbig_endian);
+  if (BigEndian) {
+Result.push_back(BigEndian->getAsString(Args));
+  }
+
   const Arg *ABIArg = Args.getLastArgNoClaim(options::OPT_mabi_EQ);
   if (ABIArg) {
 Result.push_back(ABIArg->getAsString(Args));
@@ -287,6 +299,19 @@ static void getARMMultilibFlags(const Driver &D,
   if (BranchProtectionArg) {
 Result.push_back(BranchProtectionArg->getAsString(Args));
   }
+
+  const Arg *StrictAlignArg =
+  Args.getLastArgNoClaim(options::OPT_mstrict_align, options::
+OPT_mno_unaligned_access);
+  if (StrictAlignArg) {
+Result.push_back(StrictAlignArg->getAsString(Args));
+  }
+
+  const Arg *BigEndian =
+  Args.getLastArgNoClaim(options::OPT_mbig_endian);
+  if (BigEndian) {
+Result.push_back(BigEndian->getAsString(Args));
+  }
 }
 
 static void getRISCVMultilibFlags(const Driver &D, const llvm::Triple &Triple,
diff --git a/clang/test/Driver/print-multi-selection-flags.c 
b/clang/test/Driver/print-multi-selection-flags.c
index 4bb62665ad8981..5bf6dca5096a73 100644
--- a/clang/test/Driver/print-multi-selection-flags.c
+++ b/clang/test/Driver/print-multi-selection-flags.c
@@ -68,6 +68,14 @@
 // RUN: %clang -multi-lib-config=%S/Inputs/multilib/empty.yaml 
-print-multi-flags-experimental --target=aarch64-none-elf 
-mbranch-protection=standard | FileCheck --check-prefix=CHECK-BRANCH-PROTECTION 
%s
 // CHECK-BRANCH-PROTECTION: -mbranch-protection=standard
 
+// RUN: %clang -multi-lib-config=%S/Inputs/multilib/empty.yaml 
-print-multi-flags-experimental --target=arm-none-eabi -mno-unaligned-access | 
FileCheck --check-prefix=CHECK-NO-UNALIGNED-ACCESS %s
+// RUN: %clang -multi-lib-config=%S/Inputs/multilib/empty.yaml 
-print-multi-flags-experimental --target=aarch64-none-elf -mno-unaligned-access 
| FileCheck --check-prefix=CHECK-NO-UNALIGNED-ACCESS %s
+// CHECK-NO-UNALIGNED-ACCESS: -mno-unaligned-access
+
+// RUN: %clang -multi-lib-config=%S/Inputs/multilib/empty.yaml 
-print-multi-flags-experimental --target=arm-none-eabi -mbig-endian | FileCheck 
--check-prefix=CHECK-BIG-ENDIAN %s
+// RUN: %clang -multi-lib-config=%S/Inputs/multilib/empty.yaml 
-print-multi-flags-experimental --target=aarch64-none-elf -mbig-endian | 
FileCheck --check-prefix=CHECK-BIG-ENDIAN %s
+// CHECK-BIG-ENDIAN: -mbig-endian
+
 // RUN: %clang -multi-lib-config=%S/Inputs/multilib/empty.yaml 
-print-multi-flags-experimental --target=riscv32-none-elf -march=rv32g | 
FileCheck --check-prefix=CHECK-RV32 %s
 // CHECK-RV32: --target=riscv32-unknown-none-elf
 // CHECK-RV32: -mabi=ilp32d

``




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


[clang] Add Shafik and hstk30 as maintainers for issue triage (PR #114781)

2024-11-04 Thread Aaron Ballman via cfe-commits

https://github.com/AaronBallman created 
https://github.com/llvm/llvm-project/pull/114781

Both volunteered for this role. Shafik has been actively performing these 
duties for a while and hstk30 is interested in volunteering in this space to 
help out.

>From fa37c54674c365449a53cef74fb2f800d3f11d59 Mon Sep 17 00:00:00 2001
From: Aaron Ballman 
Date: Mon, 4 Nov 2024 07:14:03 -0500
Subject: [PATCH] Add Shafik and hstk30 as maintainers for issue triage

Both volunteered for this role. Shafik has been actively performing
these duties for a while and hstk30 is interested in volunteering in
this space to help out.
---
 clang/Maintainers.rst | 9 +
 1 file changed, 9 insertions(+)

diff --git a/clang/Maintainers.rst b/clang/Maintainers.rst
index 896b463d882d08..694ebc691107cb 100644
--- a/clang/Maintainers.rst
+++ b/clang/Maintainers.rst
@@ -295,6 +295,15 @@ SYCL conformance
 | alexey.bader\@intel.com (email), bader (Phabricator), bader (GitHub)
 
 
+Issue Triage
+
+| Shafik Yaghmour
+| shafik.yaghmour\@intel.com (email), shafik (GitHub), shafik.yaghmour 
(Discord), shafik (Discourse)
+
+| hstk30
+| hanwei62\@huawei.com (email), hstk30-hw (GitHub), hstk30(Discord), hstk30 
(Discourse)
+
+
 Inactive Maintainers
 
 The following people have graciously spent time performing maintainership

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


[clang] Add Shafik and hstk30 as maintainers for issue triage (PR #114781)

2024-11-04 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Aaron Ballman (AaronBallman)


Changes

Both volunteered for this role. Shafik has been actively performing these 
duties for a while and hstk30 is interested in volunteering in this space to 
help out.

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


1 Files Affected:

- (modified) clang/Maintainers.rst (+9) 


``diff
diff --git a/clang/Maintainers.rst b/clang/Maintainers.rst
index 896b463d882d08..694ebc691107cb 100644
--- a/clang/Maintainers.rst
+++ b/clang/Maintainers.rst
@@ -295,6 +295,15 @@ SYCL conformance
 | alexey.bader\@intel.com (email), bader (Phabricator), bader (GitHub)
 
 
+Issue Triage
+
+| Shafik Yaghmour
+| shafik.yaghmour\@intel.com (email), shafik (GitHub), shafik.yaghmour 
(Discord), shafik (Discourse)
+
+| hstk30
+| hanwei62\@huawei.com (email), hstk30-hw (GitHub), hstk30(Discord), hstk30 
(Discourse)
+
+
 Inactive Maintainers
 
 The following people have graciously spent time performing maintainership

``




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


[clang] Add Shafik and hstk30 as maintainers for issue triage (PR #114781)

2024-11-04 Thread Vlad Serebrennikov via cfe-commits

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


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


[clang] Add -mno-unaligned-access and -mbig-endian to ARM and AArch64 multilib flags (PR #114782)

2024-11-04 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 af6ebb70d22ed75d4472a6069ba3a0890e0d3a00 
4a06df9bec87882964e0892b50dd9a81d5e1e6ac --extensions c,cpp -- 
clang/lib/Driver/ToolChain.cpp clang/test/Driver/print-multi-selection-flags.c
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index dec9af62ad..652aa96860 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -230,14 +230,13 @@ static void getAArch64MultilibFlags(const Driver &D,
 Result.push_back(BranchProtectionArg->getAsString(Args));
   }
 
-  const Arg *StrictAlignArg =
-  Args.getLastArgNoClaim(options::OPT_mstrict_align, 
options::OPT_mno_unaligned_access);
+  const Arg *StrictAlignArg = Args.getLastArgNoClaim(
+  options::OPT_mstrict_align, options::OPT_mno_unaligned_access);
   if (StrictAlignArg) {
 Result.push_back(StrictAlignArg->getAsString(Args));
   }
 
-  const Arg *BigEndian =
-  Args.getLastArgNoClaim(options::OPT_mbig_endian);
+  const Arg *BigEndian = Args.getLastArgNoClaim(options::OPT_mbig_endian);
   if (BigEndian) {
 Result.push_back(BigEndian->getAsString(Args));
   }
@@ -300,15 +299,13 @@ static void getARMMultilibFlags(const Driver &D,
 Result.push_back(BranchProtectionArg->getAsString(Args));
   }
 
-  const Arg *StrictAlignArg =
-  Args.getLastArgNoClaim(options::OPT_mstrict_align, options::
-OPT_mno_unaligned_access);
+  const Arg *StrictAlignArg = Args.getLastArgNoClaim(
+  options::OPT_mstrict_align, options::OPT_mno_unaligned_access);
   if (StrictAlignArg) {
 Result.push_back(StrictAlignArg->getAsString(Args));
   }
 
-  const Arg *BigEndian =
-  Args.getLastArgNoClaim(options::OPT_mbig_endian);
+  const Arg *BigEndian = Args.getLastArgNoClaim(options::OPT_mbig_endian);
   if (BigEndian) {
 Result.push_back(BigEndian->getAsString(Args));
   }

``




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


[clang] [flang] [llvm] Enable seq_cst Clause for flush Directive in OpenMP (PR #114072)

2024-11-04 Thread via cfe-commits

https://github.com/ShashwathiNavada updated 
https://github.com/llvm/llvm-project/pull/114072

>From 4b49b221a67bd77db98ca765610f7c1ace0772a0 Mon Sep 17 00:00:00 2001
From: Shashwathi N 
Date: Tue, 29 Oct 2024 09:16:04 -0500
Subject: [PATCH] Added support for seq_cst clause for flush directive

---
 clang/include/clang/AST/OpenMPClause.h|  4 ++--
 .../clang/Basic/DiagnosticSemaKinds.td|  2 +-
 clang/lib/Sema/SemaOpenMP.cpp |  3 ++-
 clang/test/OpenMP/flush_ast_print.cpp | 18 +++--
 clang/test/OpenMP/flush_codegen.cpp   | 20 ++-
 clang/test/OpenMP/flush_messages.cpp  |  6 ++
 .../Semantics/OpenMP/clause-validity01.f90|  3 +--
 flang/test/Semantics/OpenMP/flush02.f90   |  4 +---
 llvm/include/llvm/Frontend/OpenMP/OMP.td  |  1 +
 9 files changed, 33 insertions(+), 28 deletions(-)

diff --git a/clang/include/clang/AST/OpenMPClause.h 
b/clang/include/clang/AST/OpenMPClause.h
index 9cf46f73f6e46d..8a1f16f96ddc27 100644
--- a/clang/include/clang/AST/OpenMPClause.h
+++ b/clang/include/clang/AST/OpenMPClause.h
@@ -2645,8 +2645,8 @@ class OMPCompareClause final : public OMPClause {
   }
 };
 
-/// This represents 'seq_cst' clause in the '#pragma omp atomic'
-/// directive.
+/// This represents 'seq_cst' clause in the '#pragma omp atomic|flush'
+/// directives.
 ///
 /// \code
 /// #pragma omp atomic seq_cst
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 34ff49d7238a7f..6ce969988491c1 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -11360,7 +11360,7 @@ def err_omp_atomic_weak_no_equality : Error<"expected 
'==' operator for 'weak' c
 def err_omp_atomic_several_clauses : Error<
   "directive '#pragma omp atomic' cannot contain more than one 'read', 
'write', 'update', 'capture', or 'compare' clause">;
 def err_omp_several_mem_order_clauses : Error<
-  "directive '#pragma omp %0' cannot contain more than one %select{'seq_cst', 
'relaxed', |}1'acq_rel', 'acquire' or 'release' clause">;
+  "directive '#pragma omp %0' cannot contain more than one 'seq_cst',%select{ 
'relaxed',|}1 'acq_rel', 'acquire' or 'release' clause">;
 def err_omp_atomic_incompatible_mem_order_clause : Error<
   "directive '#pragma omp atomic%select{ %0|}1' cannot be used with '%2' 
clause">;
 def note_omp_previous_mem_order_clause : Note<
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 79e1536288e602..d794d572d07ead 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -11105,7 +11105,8 @@ StmtResult 
SemaOpenMP::ActOnOpenMPFlushDirective(ArrayRef Clauses,
   for (const OMPClause *C : Clauses) {
 if (C->getClauseKind() == OMPC_acq_rel ||
 C->getClauseKind() == OMPC_acquire ||
-C->getClauseKind() == OMPC_release) {
+C->getClauseKind() == OMPC_release ||
+C->getClauseKind() == OMPC_seq_cst /*OpenMP 5.1*/) {
   if (MemOrderKind != OMPC_unknown) {
 Diag(C->getBeginLoc(), diag::err_omp_several_mem_order_clauses)
 << getOpenMPDirectiveName(OMPD_flush) << 1
diff --git a/clang/test/OpenMP/flush_ast_print.cpp 
b/clang/test/OpenMP/flush_ast_print.cpp
index 9578ada020227a..768282422032fd 100644
--- a/clang/test/OpenMP/flush_ast_print.cpp
+++ b/clang/test/OpenMP/flush_ast_print.cpp
@@ -1,10 +1,10 @@
-// RUN: %clang_cc1 -verify -fopenmp -ast-print %s | FileCheck %s
-// RUN: %clang_cc1 -fopenmp -x c++ -std=c++11 -emit-pch -o %t %s
-// RUN: %clang_cc1 -fopenmp -std=c++11 -include-pch %t -verify %s -ast-print | 
FileCheck %s
+// RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=51 -ast-print %s | 
FileCheck %s
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=51 -x c++ -std=c++11 -emit-pch -o 
%t %s
+// RUN: %clang_cc1 -fopenmp -fopenmp-version=51 -std=c++11 -include-pch %t  
-verify %s -ast-print | FileCheck %s
 
-// RUN: %clang_cc1 -verify -fopenmp-simd -ast-print %s | FileCheck %s
-// RUN: %clang_cc1 -fopenmp-simd -x c++ -std=c++11 -emit-pch -o %t %s
-// RUN: %clang_cc1 -fopenmp-simd -std=c++11 -include-pch %t -verify %s 
-ast-print | FileCheck %s
+// RUN: %clang_cc1 -verify -fopenmp-simd -fopenmp-version=51 -ast-print %s | 
FileCheck %s
+// RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=51 -x c++ -std=c++11 
-emit-pch -o %t %s
+// RUN: %clang_cc1 -fopenmp-simd -fopenmp-version=51 -std=c++11 -include-pch 
%t -verify %s -ast-print | FileCheck %s
 // expected-no-diagnostics
 
 #ifndef HEADER
@@ -19,6 +19,7 @@ T tmain(T argc) {
 #pragma omp flush acq_rel
 #pragma omp flush acquire
 #pragma omp flush release
+#pragma omp flush seq_cst
 #pragma omp flush(a)
   return a + argc;
 }
@@ -27,18 +28,21 @@ T tmain(T argc) {
 // CHECK-NEXT: #pragma omp flush acq_rel{{$}}
 // CHECK-NEXT: #pragma omp flush acquire{{$}}
 // CHECK-NEXT: #pragma omp flush release{{$}}
+// CHECK-NEXT: #pragma omp flush seq_cst{{$}}
 // CHECK

[clang] [Clang] Document some of the implementation-defined keywords (PR #84591)

2024-11-04 Thread Aaron Ballman via cfe-commits


@@ -433,6 +433,117 @@ __datasizeof
 ``__datasizeof`` behaves like ``sizeof``, except that it returns the size of 
the
 type ignoring tail padding.
 
+_BitInt, _ExtInt
+
+
+Clang supports the C23 ``_BitInt(N)`` feature as an extension in older C modes
+and in C++. This type was previously implemented in Clang with the same
+semantics, but spelled ``_ExtInt(N)``. This spelling has been deprecated in
+favor of the standard type.
+
+Note: the ABI for ``_BitInt(N)`` is still in the process of being stabilized,
+so this type should not yet be used in interfaces that require ABI stability.
+
+C keywords supported in all language modes
+--
+
+Clang supports ``_Alignas``, ``_Alignof``, ``_Atomic``, ``_Complex``,
+``_Generic``, ``_Imaginary``, ``_Noreturn``, ``_Static_assert``,
+``_Thread_local``, ``_Float16``, ``_Decimal32``, ``_Decimal64`` and
+``_Decimal128`` in all language modes with the C semantics.
+
+__alignof, __alignof__
+--
+
+``__alignof`` and ``__alignof__`` return, in contrast to ``_Alignof`` and
+``alignof``, the preferred alignment of a type. This may be larger than the
+required alignment for improved performance.
+
+__extension__
+-
+
+``__extension__`` suppressed extension diagnostics in the statement it is
+prepended to.
+
+__auto_type
+---
+
+``__auto_type`` behaves the same as C++11s ``auto`` but is available in all
+language modes.
+
+__imag, __imag__
+
+
+``__imag`` and ``__imag__`` can be used to get the imaginary part of a complex
+value.
+
+__real, __real__
+
+
+``__real`` and ``__real__`` can be used to get the real part of a complex 
value.
+
+__asm, __asm__
+--
+
+``__asm`` and ``__asm__`` are alternate spellings for ``asm``, but available in
+all language modes.
+
+__complex, __complex__
+--
+
+``__complex`` and ``__complex__`` are alternate spellings for ``_Complex``.
+
+__const, __const__
+--
+
+``__const`` and ``__const__`` are alternate spellings for ``const``.
+
+__decltype
+--
+
+``__decltype`` is an alternate spelling for ``decltype``, but is also available
+in C++ modes before C++11.
+
+__inline, __inline__
+
+
+``__inline`` and ``__inline__`` are alternate spellings for ``inline``, but are
+available in all language modes.
+
+__nullptr
+-
+
+``__nullptr`` is an alternate spelling for ``nullptr``, but is also available 
in
+C++ modes before C++11.

AaronBallman wrote:

Should note that this is currently only available in C++ modes, not C modes, 
despite C23 adding support for `nullptr`. I think this may be an oversight in 
C; perhaps worth filing a `good first issue` for it.

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


[clang] [Clang] Document some of the implementation-defined keywords (PR #84591)

2024-11-04 Thread Aaron Ballman via cfe-commits

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


[clang] [Clang] Document some of the implementation-defined keywords (PR #84591)

2024-11-04 Thread Aaron Ballman via cfe-commits


@@ -433,6 +433,117 @@ __datasizeof
 ``__datasizeof`` behaves like ``sizeof``, except that it returns the size of 
the
 type ignoring tail padding.
 
+_BitInt, _ExtInt
+
+
+Clang supports the C23 ``_BitInt(N)`` feature as an extension in older C modes
+and in C++. This type was previously implemented in Clang with the same
+semantics, but spelled ``_ExtInt(N)``. This spelling has been deprecated in
+favor of the standard type.
+
+Note: the ABI for ``_BitInt(N)`` is still in the process of being stabilized,
+so this type should not yet be used in interfaces that require ABI stability.
+
+C keywords supported in all language modes
+--
+
+Clang supports ``_Alignas``, ``_Alignof``, ``_Atomic``, ``_Complex``,
+``_Generic``, ``_Imaginary``, ``_Noreturn``, ``_Static_assert``,
+``_Thread_local``, ``_Float16``, ``_Decimal32``, ``_Decimal64`` and
+``_Decimal128`` in all language modes with the C semantics.
+
+__alignof, __alignof__
+--
+
+``__alignof`` and ``__alignof__`` return, in contrast to ``_Alignof`` and
+``alignof``, the preferred alignment of a type. This may be larger than the
+required alignment for improved performance.
+
+__extension__
+-
+
+``__extension__`` suppressed extension diagnostics in the statement it is

AaronBallman wrote:

```suggestion
``__extension__`` suppresses extension diagnostics in the statement it is
```

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


[clang] [Clang] Document some of the implementation-defined keywords (PR #84591)

2024-11-04 Thread Aaron Ballman via cfe-commits


@@ -433,6 +433,117 @@ __datasizeof
 ``__datasizeof`` behaves like ``sizeof``, except that it returns the size of 
the
 type ignoring tail padding.
 
+_BitInt, _ExtInt
+
+
+Clang supports the C23 ``_BitInt(N)`` feature as an extension in older C modes
+and in C++. This type was previously implemented in Clang with the same
+semantics, but spelled ``_ExtInt(N)``. This spelling has been deprecated in
+favor of the standard type.
+
+Note: the ABI for ``_BitInt(N)`` is still in the process of being stabilized,
+so this type should not yet be used in interfaces that require ABI stability.
+
+C keywords supported in all language modes
+--
+
+Clang supports ``_Alignas``, ``_Alignof``, ``_Atomic``, ``_Complex``,
+``_Generic``, ``_Imaginary``, ``_Noreturn``, ``_Static_assert``,
+``_Thread_local``, ``_Float16``, ``_Decimal32``, ``_Decimal64`` and
+``_Decimal128`` in all language modes with the C semantics.
+
+__alignof, __alignof__
+--
+
+``__alignof`` and ``__alignof__`` return, in contrast to ``_Alignof`` and
+``alignof``, the preferred alignment of a type. This may be larger than the
+required alignment for improved performance.
+
+__extension__
+-
+
+``__extension__`` suppressed extension diagnostics in the statement it is
+prepended to.
+
+__auto_type
+---
+
+``__auto_type`` behaves the same as C++11s ``auto`` but is available in all
+language modes.
+
+__imag, __imag__
+
+
+``__imag`` and ``__imag__`` can be used to get the imaginary part of a complex
+value.
+
+__real, __real__
+
+
+``__real`` and ``__real__`` can be used to get the real part of a complex 
value.
+
+__asm, __asm__
+--
+
+``__asm`` and ``__asm__`` are alternate spellings for ``asm``, but available in
+all language modes.
+
+__complex, __complex__
+--
+
+``__complex`` and ``__complex__`` are alternate spellings for ``_Complex``.
+
+__const, __const__
+--
+
+``__const`` and ``__const__`` are alternate spellings for ``const``.
+
+__decltype
+--
+
+``__decltype`` is an alternate spelling for ``decltype``, but is also available
+in C++ modes before C++11.
+
+__inline, __inline__
+
+
+``__inline`` and ``__inline__`` are alternate spellings for ``inline``, but are
+available in all language modes.
+
+__nullptr
+-
+
+``__nullptr`` is an alternate spelling for ``nullptr``, but is also available 
in
+C++ modes before C++11.
+
+__restrict, __restrict__
+
+
+``__restrict`` and ``__restrict__`` are alternate spellings for ``restrict``,
+but are available in all language modes.
+
+__signed, __signed__
+
+
+``__signed`` and ``__signed__`` are alternate spellings for ``signed``.
+
+__typeof, __typeof__
+
+
+``__typeof`` and ``__typeof__`` are alternate spellings for ``typeof``, but are
+available in all langauge modes.
+
+__volatile, __volatile__

AaronBallman wrote:

Stick this with `const`?

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


[clang] [Clang] Document some of the implementation-defined keywords (PR #84591)

2024-11-04 Thread Aaron Ballman via cfe-commits


@@ -433,6 +433,117 @@ __datasizeof
 ``__datasizeof`` behaves like ``sizeof``, except that it returns the size of 
the
 type ignoring tail padding.
 
+_BitInt, _ExtInt
+
+
+Clang supports the C23 ``_BitInt(N)`` feature as an extension in older C modes
+and in C++. This type was previously implemented in Clang with the same
+semantics, but spelled ``_ExtInt(N)``. This spelling has been deprecated in
+favor of the standard type.
+
+Note: the ABI for ``_BitInt(N)`` is still in the process of being stabilized,
+so this type should not yet be used in interfaces that require ABI stability.
+
+C keywords supported in all language modes
+--
+
+Clang supports ``_Alignas``, ``_Alignof``, ``_Atomic``, ``_Complex``,
+``_Generic``, ``_Imaginary``, ``_Noreturn``, ``_Static_assert``,
+``_Thread_local``, ``_Float16``, ``_Decimal32``, ``_Decimal64`` and
+``_Decimal128`` in all language modes with the C semantics.
+
+__alignof, __alignof__
+--
+
+``__alignof`` and ``__alignof__`` return, in contrast to ``_Alignof`` and
+``alignof``, the preferred alignment of a type. This may be larger than the
+required alignment for improved performance.
+
+__extension__
+-
+
+``__extension__`` suppressed extension diagnostics in the statement it is
+prepended to.
+
+__auto_type
+---
+
+``__auto_type`` behaves the same as C++11s ``auto`` but is available in all
+language modes.
+
+__imag, __imag__
+
+
+``__imag`` and ``__imag__`` can be used to get the imaginary part of a complex
+value.
+
+__real, __real__
+
+
+``__real`` and ``__real__`` can be used to get the real part of a complex 
value.
+
+__asm, __asm__
+--
+
+``__asm`` and ``__asm__`` are alternate spellings for ``asm``, but available in
+all language modes.
+
+__complex, __complex__
+--
+
+``__complex`` and ``__complex__`` are alternate spellings for ``_Complex``.
+
+__const, __const__
+--
+
+``__const`` and ``__const__`` are alternate spellings for ``const``.
+
+__decltype
+--
+
+``__decltype`` is an alternate spelling for ``decltype``, but is also available
+in C++ modes before C++11.
+
+__inline, __inline__
+
+
+``__inline`` and ``__inline__`` are alternate spellings for ``inline``, but are
+available in all language modes.
+
+__nullptr
+-
+
+``__nullptr`` is an alternate spelling for ``nullptr``, but is also available 
in
+C++ modes before C++11.
+
+__restrict, __restrict__

AaronBallman wrote:

Stick this with `const`?

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


[clang] [Clang] Document some of the implementation-defined keywords (PR #84591)

2024-11-04 Thread Aaron Ballman via cfe-commits


@@ -433,6 +433,117 @@ __datasizeof
 ``__datasizeof`` behaves like ``sizeof``, except that it returns the size of 
the
 type ignoring tail padding.
 
+_BitInt, _ExtInt
+
+
+Clang supports the C23 ``_BitInt(N)`` feature as an extension in older C modes
+and in C++. This type was previously implemented in Clang with the same
+semantics, but spelled ``_ExtInt(N)``. This spelling has been deprecated in
+favor of the standard type.
+
+Note: the ABI for ``_BitInt(N)`` is still in the process of being stabilized,
+so this type should not yet be used in interfaces that require ABI stability.
+
+C keywords supported in all language modes
+--
+
+Clang supports ``_Alignas``, ``_Alignof``, ``_Atomic``, ``_Complex``,
+``_Generic``, ``_Imaginary``, ``_Noreturn``, ``_Static_assert``,
+``_Thread_local``, ``_Float16``, ``_Decimal32``, ``_Decimal64`` and
+``_Decimal128`` in all language modes with the C semantics.
+
+__alignof, __alignof__
+--
+
+``__alignof`` and ``__alignof__`` return, in contrast to ``_Alignof`` and
+``alignof``, the preferred alignment of a type. This may be larger than the
+required alignment for improved performance.
+
+__extension__
+-
+
+``__extension__`` suppressed extension diagnostics in the statement it is
+prepended to.
+
+__auto_type
+---
+
+``__auto_type`` behaves the same as C++11s ``auto`` but is available in all
+language modes.
+
+__imag, __imag__
+
+
+``__imag`` and ``__imag__`` can be used to get the imaginary part of a complex
+value.
+
+__real, __real__
+
+
+``__real`` and ``__real__`` can be used to get the real part of a complex 
value.
+
+__asm, __asm__
+--
+
+``__asm`` and ``__asm__`` are alternate spellings for ``asm``, but available in
+all language modes.
+
+__complex, __complex__
+--
+
+``__complex`` and ``__complex__`` are alternate spellings for ``_Complex``.
+
+__const, __const__
+--
+
+``__const`` and ``__const__`` are alternate spellings for ``const``.

AaronBallman wrote:

It might make sense to document all the cvr qualifiers together in one section?

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


[clang] [Clang] Document some of the implementation-defined keywords (PR #84591)

2024-11-04 Thread Aaron Ballman via cfe-commits


@@ -433,6 +433,117 @@ __datasizeof
 ``__datasizeof`` behaves like ``sizeof``, except that it returns the size of 
the
 type ignoring tail padding.
 
+_BitInt, _ExtInt
+
+
+Clang supports the C23 ``_BitInt(N)`` feature as an extension in older C modes
+and in C++. This type was previously implemented in Clang with the same
+semantics, but spelled ``_ExtInt(N)``. This spelling has been deprecated in
+favor of the standard type.
+
+Note: the ABI for ``_BitInt(N)`` is still in the process of being stabilized,
+so this type should not yet be used in interfaces that require ABI stability.
+
+C keywords supported in all language modes
+--
+
+Clang supports ``_Alignas``, ``_Alignof``, ``_Atomic``, ``_Complex``,
+``_Generic``, ``_Imaginary``, ``_Noreturn``, ``_Static_assert``,
+``_Thread_local``, ``_Float16``, ``_Decimal32``, ``_Decimal64`` and
+``_Decimal128`` in all language modes with the C semantics.
+
+__alignof, __alignof__
+--
+
+``__alignof`` and ``__alignof__`` return, in contrast to ``_Alignof`` and
+``alignof``, the preferred alignment of a type. This may be larger than the
+required alignment for improved performance.
+
+__extension__
+-
+
+``__extension__`` suppressed extension diagnostics in the statement it is
+prepended to.
+
+__auto_type
+---
+
+``__auto_type`` behaves the same as C++11s ``auto`` but is available in all

AaronBallman wrote:

```suggestion
``__auto_type`` behaves the same as ``auto`` in C++11 and C23 but is available 
in all
```

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


[clang] [Clang] Document some of the implementation-defined keywords (PR #84591)

2024-11-04 Thread Aaron Ballman via cfe-commits


@@ -433,6 +433,117 @@ __datasizeof
 ``__datasizeof`` behaves like ``sizeof``, except that it returns the size of 
the
 type ignoring tail padding.
 
+_BitInt, _ExtInt
+
+
+Clang supports the C23 ``_BitInt(N)`` feature as an extension in older C modes
+and in C++. This type was previously implemented in Clang with the same
+semantics, but spelled ``_ExtInt(N)``. This spelling has been deprecated in
+favor of the standard type.
+
+Note: the ABI for ``_BitInt(N)`` is still in the process of being stabilized,
+so this type should not yet be used in interfaces that require ABI stability.
+
+C keywords supported in all language modes
+--
+
+Clang supports ``_Alignas``, ``_Alignof``, ``_Atomic``, ``_Complex``,
+``_Generic``, ``_Imaginary``, ``_Noreturn``, ``_Static_assert``,
+``_Thread_local``, ``_Float16``, ``_Decimal32``, ``_Decimal64`` and
+``_Decimal128`` in all language modes with the C semantics.
+
+__alignof, __alignof__
+--
+
+``__alignof`` and ``__alignof__`` return, in contrast to ``_Alignof`` and
+``alignof``, the preferred alignment of a type. This may be larger than the
+required alignment for improved performance.
+
+__extension__
+-
+
+``__extension__`` suppressed extension diagnostics in the statement it is
+prepended to.
+
+__auto_type
+---
+
+``__auto_type`` behaves the same as C++11s ``auto`` but is available in all
+language modes.
+
+__imag, __imag__
+
+
+``__imag`` and ``__imag__`` can be used to get the imaginary part of a complex
+value.
+
+__real, __real__
+
+
+``__real`` and ``__real__`` can be used to get the real part of a complex 
value.
+
+__asm, __asm__
+--
+
+``__asm`` and ``__asm__`` are alternate spellings for ``asm``, but available in
+all language modes.
+
+__complex, __complex__
+--
+
+``__complex`` and ``__complex__`` are alternate spellings for ``_Complex``.
+
+__const, __const__
+--
+
+``__const`` and ``__const__`` are alternate spellings for ``const``.
+
+__decltype
+--
+
+``__decltype`` is an alternate spelling for ``decltype``, but is also available
+in C++ modes before C++11.
+
+__inline, __inline__
+
+
+``__inline`` and ``__inline__`` are alternate spellings for ``inline``, but are
+available in all language modes.
+
+__nullptr
+-
+
+``__nullptr`` is an alternate spelling for ``nullptr``, but is also available 
in
+C++ modes before C++11.
+
+__restrict, __restrict__
+
+
+``__restrict`` and ``__restrict__`` are alternate spellings for ``restrict``,
+but are available in all language modes.
+
+__signed, __signed__
+
+
+``__signed`` and ``__signed__`` are alternate spellings for ``signed``.
+
+__typeof, __typeof__
+
+
+``__typeof`` and ``__typeof__`` are alternate spellings for ``typeof``, but are
+available in all langauge modes.
+
+__volatile, __volatile__
+
+
+``__volatile`` and ``__volatile__`` are alternate spellings for ``volatile``.
+
+__char16_t, __char32_t
+--
+
+``__char16_t`` and ``__char32_t`` are alternate spellings for ``char16_t`` and

AaronBallman wrote:

Should mention that these are C++-only and that `__char8_t` is not supported (I 
wonder why that is?)

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


[clang] [Clang] Document some of the implementation-defined keywords (PR #84591)

2024-11-04 Thread Aaron Ballman via cfe-commits


@@ -433,6 +433,117 @@ __datasizeof
 ``__datasizeof`` behaves like ``sizeof``, except that it returns the size of 
the
 type ignoring tail padding.
 
+_BitInt, _ExtInt
+
+
+Clang supports the C23 ``_BitInt(N)`` feature as an extension in older C modes
+and in C++. This type was previously implemented in Clang with the same
+semantics, but spelled ``_ExtInt(N)``. This spelling has been deprecated in
+favor of the standard type.
+
+Note: the ABI for ``_BitInt(N)`` is still in the process of being stabilized,
+so this type should not yet be used in interfaces that require ABI stability.
+
+C keywords supported in all language modes
+--
+
+Clang supports ``_Alignas``, ``_Alignof``, ``_Atomic``, ``_Complex``,
+``_Generic``, ``_Imaginary``, ``_Noreturn``, ``_Static_assert``,
+``_Thread_local``, ``_Float16``, ``_Decimal32``, ``_Decimal64`` and
+``_Decimal128`` in all language modes with the C semantics.
+
+__alignof, __alignof__
+--
+
+``__alignof`` and ``__alignof__`` return, in contrast to ``_Alignof`` and
+``alignof``, the preferred alignment of a type. This may be larger than the
+required alignment for improved performance.
+
+__extension__
+-
+
+``__extension__`` suppressed extension diagnostics in the statement it is
+prepended to.
+
+__auto_type
+---
+
+``__auto_type`` behaves the same as C++11s ``auto`` but is available in all
+language modes.
+
+__imag, __imag__
+
+
+``__imag`` and ``__imag__`` can be used to get the imaginary part of a complex
+value.
+
+__real, __real__
+
+
+``__real`` and ``__real__`` can be used to get the real part of a complex 
value.
+
+__asm, __asm__
+--
+
+``__asm`` and ``__asm__`` are alternate spellings for ``asm``, but available in
+all language modes.
+
+__complex, __complex__
+--
+
+``__complex`` and ``__complex__`` are alternate spellings for ``_Complex``.
+
+__const, __const__
+--
+
+``__const`` and ``__const__`` are alternate spellings for ``const``.
+
+__decltype
+--
+
+``__decltype`` is an alternate spelling for ``decltype``, but is also available
+in C++ modes before C++11.
+
+__inline, __inline__
+
+
+``__inline`` and ``__inline__`` are alternate spellings for ``inline``, but are
+available in all language modes.
+
+__nullptr
+-
+
+``__nullptr`` is an alternate spelling for ``nullptr``, but is also available 
in
+C++ modes before C++11.
+
+__restrict, __restrict__
+
+
+``__restrict`` and ``__restrict__`` are alternate spellings for ``restrict``,
+but are available in all language modes.
+
+__signed, __signed__
+
+
+``__signed`` and ``__signed__`` are alternate spellings for ``signed``.
+
+__typeof, __typeof__
+
+
+``__typeof`` and ``__typeof__`` are alternate spellings for ``typeof``, but are

AaronBallman wrote:

Should mention `typeof` in C23 and that all three of these get you the type 
information with qualifiers still attached.

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


[clang] [Clang] Document some of the implementation-defined keywords (PR #84591)

2024-11-04 Thread Aaron Ballman via cfe-commits


@@ -433,6 +433,117 @@ __datasizeof
 ``__datasizeof`` behaves like ``sizeof``, except that it returns the size of 
the
 type ignoring tail padding.
 
+_BitInt, _ExtInt
+
+
+Clang supports the C23 ``_BitInt(N)`` feature as an extension in older C modes
+and in C++. This type was previously implemented in Clang with the same
+semantics, but spelled ``_ExtInt(N)``. This spelling has been deprecated in
+favor of the standard type.
+
+Note: the ABI for ``_BitInt(N)`` is still in the process of being stabilized,
+so this type should not yet be used in interfaces that require ABI stability.
+
+C keywords supported in all language modes
+--
+
+Clang supports ``_Alignas``, ``_Alignof``, ``_Atomic``, ``_Complex``,
+``_Generic``, ``_Imaginary``, ``_Noreturn``, ``_Static_assert``,
+``_Thread_local``, ``_Float16``, ``_Decimal32``, ``_Decimal64`` and
+``_Decimal128`` in all language modes with the C semantics.
+
+__alignof, __alignof__
+--
+
+``__alignof`` and ``__alignof__`` return, in contrast to ``_Alignof`` and
+``alignof``, the preferred alignment of a type. This may be larger than the
+required alignment for improved performance.
+
+__extension__
+-
+
+``__extension__`` suppressed extension diagnostics in the statement it is
+prepended to.
+
+__auto_type
+---
+
+``__auto_type`` behaves the same as C++11s ``auto`` but is available in all
+language modes.
+
+__imag, __imag__
+
+
+``__imag`` and ``__imag__`` can be used to get the imaginary part of a complex
+value.
+
+__real, __real__
+
+
+``__real`` and ``__real__`` can be used to get the real part of a complex 
value.
+
+__asm, __asm__
+--
+
+``__asm`` and ``__asm__`` are alternate spellings for ``asm``, but available in
+all language modes.
+
+__complex, __complex__
+--
+
+``__complex`` and ``__complex__`` are alternate spellings for ``_Complex``.
+
+__const, __const__
+--
+
+``__const`` and ``__const__`` are alternate spellings for ``const``.
+
+__decltype
+--
+
+``__decltype`` is an alternate spelling for ``decltype``, but is also available
+in C++ modes before C++11.
+
+__inline, __inline__
+
+
+``__inline`` and ``__inline__`` are alternate spellings for ``inline``, but are
+available in all language modes.
+
+__nullptr
+-
+
+``__nullptr`` is an alternate spelling for ``nullptr``, but is also available 
in
+C++ modes before C++11.
+
+__restrict, __restrict__
+
+
+``__restrict`` and ``__restrict__`` are alternate spellings for ``restrict``,
+but are available in all language modes.
+
+__signed, __signed__

AaronBallman wrote:

Should probably mention that we do not support `__unsigned__`, which certainly 
surprised me (neither does GCC)

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


[clang] [Clang] Document some of the implementation-defined keywords (PR #84591)

2024-11-04 Thread Aaron Ballman via cfe-commits


@@ -433,6 +433,117 @@ __datasizeof
 ``__datasizeof`` behaves like ``sizeof``, except that it returns the size of 
the
 type ignoring tail padding.
 
+_BitInt, _ExtInt
+
+
+Clang supports the C23 ``_BitInt(N)`` feature as an extension in older C modes
+and in C++. This type was previously implemented in Clang with the same
+semantics, but spelled ``_ExtInt(N)``. This spelling has been deprecated in
+favor of the standard type.
+
+Note: the ABI for ``_BitInt(N)`` is still in the process of being stabilized,
+so this type should not yet be used in interfaces that require ABI stability.
+
+C keywords supported in all language modes
+--
+
+Clang supports ``_Alignas``, ``_Alignof``, ``_Atomic``, ``_Complex``,
+``_Generic``, ``_Imaginary``, ``_Noreturn``, ``_Static_assert``,
+``_Thread_local``, ``_Float16``, ``_Decimal32``, ``_Decimal64`` and
+``_Decimal128`` in all language modes with the C semantics.

AaronBallman wrote:

The `_Decimal` variants are not supported yet: https://godbolt.org/z/noMe3KndK

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


[clang] [Clang] Document some of the implementation-defined keywords (PR #84591)

2024-11-04 Thread Aaron Ballman via cfe-commits

https://github.com/AaronBallman commented:

Thank you for working on this!

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


[clang] [compiler-rt] [libcxx] [llvm] [libc++] Replace LIBCXX_ENABLE_STATIC_ABI_LIBRARY & friends by a new LIBCXX_CXX_ABI choice (PR #112978)

2024-11-04 Thread Nikita Popov via cfe-commits

nikic wrote:

Looking at our current cmake config, we're using:
```
-DLIBCXX_STATICALLY_LINK_ABI_IN_STATIC_LIBRARY=ON \
-DLIBCXX_ENABLE_ABI_LINKER_SCRIPT=ON \
```
Do I understand correctly that the new replacement for that would be?
```
-DLIBCXX_ABILIB_FOR_SHARED="shared-libcxxabi" \
-DLIBCXX_ABILIB_FOR_STATIC="merged-libcxxabi" \
-DLIBCXX_ENABLE_ABI_LINKER_SCRIPT=ON \
```
And those LIBCXX_ABILIB options are also the defaults, if I'm reading the docs 
right.

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


[clang] [ASTWriter] Detect more non-affecting FileIDs to reduce source location duplication (PR #112015)

2024-11-04 Thread Ilya Biryukov via cfe-commits

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


[clang] [ASTWriter] Detect more non-affecting FileIDs to reduce source location duplication (PR #112015)

2024-11-04 Thread Ilya Biryukov via cfe-commits

ilya-biryukov wrote:

> Did you mean _"mark it as affecting"_ / _"not mark it as **non**-affecting"_ 
> instead of _"**not** mark it as affecting"_?

Yes, sorry, that was a mistake on my part.

> Can you expand on that? Why doesn't it work properly if you stop writing 
> those input files as well?

Because `ClangScanDeps` relies on the information from those `InputFIle` to 
determine which module map files the code depends on, the relevant code is 
here: 
https://github.com/llvm/llvm-project/blob/a15bf88d532ad2e81d7c54c480707f6c7d8bbeab/clang/lib/Tooling/DependencyScanning/ModuleDepCollector.cpp#L599

If we stop producing those input files, it should not affect the compiler in 
any way, but clang-scan-deps will be broken (some tests will fail, including 
the ones that check the final commands can compile the underlying modules)

> This is unexpected and I think it breaks the correctness of clang-scan-deps. 
> I think we might need to take your patch a bit further and make it so that 
> `ASTWriter::WriteInputFiles()` doesn't care whether the SLocEntry associated 
> with the file through `Module::DefinitionLoc` is loaded or local.

Hm, that would actually make the final outputs much more predictable, so I like 
this approach. Let me try to prototype it and get back to you.
The only downside is more `InputFile` entries being reported, but I bet they 
are a very small fraction of the serialized AST, so it should not really 
matter. 

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


[clang] [SYCL] change sycl version accrodnig to standard (PR #114790)

2024-11-04 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/114790
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [SYCL] change sycl version accrodnig to standard (PR #114790)

2024-11-04 Thread via cfe-commits

https://github.com/dklochkov-emb created 
https://github.com/llvm/llvm-project/pull/114790

Version of SYCL was changed according to the latest agreement:
The lower 2 digits are not formally specified, but we plan to use these to 
identify the month in which we submit the specification for ratification, which 
is similar to the C++ macro __cplusplus.

Since the SYCL 2020 specification was submitted for ratification in December of 
2020, the macro's value is now 202012 for SYCL 2020.
see PR for details 
https://github.com/KhronosGroup/SYCL-Docs/pull/634

>From 962fcac610226d5bbd0ed84d7c3dc111d1bafa4f Mon Sep 17 00:00:00 2001
From: "Klochkov, Denis" 
Date: Mon, 4 Nov 2024 04:58:30 -0800
Subject: [PATCH] [SYCL] change sycl version accrodnig to standard

---
 clang/lib/Frontend/InitPreprocessor.cpp | 2 +-
 clang/test/Preprocessor/sycl-macro.cpp  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Frontend/InitPreprocessor.cpp 
b/clang/lib/Frontend/InitPreprocessor.cpp
index 9a0fdb175ff29e..e9c7dc338380fd 100644
--- a/clang/lib/Frontend/InitPreprocessor.cpp
+++ b/clang/lib/Frontend/InitPreprocessor.cpp
@@ -587,7 +587,7 @@ static void InitializeStandardPredefinedMacros(const 
TargetInfo &TI,
 if (LangOpts.getSYCLVersion() == LangOptions::SYCL_2017)
   Builder.defineMacro("CL_SYCL_LANGUAGE_VERSION", "121");
 else if (LangOpts.getSYCLVersion() == LangOptions::SYCL_2020)
-  Builder.defineMacro("SYCL_LANGUAGE_VERSION", "202001");
+  Builder.defineMacro("SYCL_LANGUAGE_VERSION", "202012");
   }
 
   // Not "standard" per se, but available even with the -undef flag.
diff --git a/clang/test/Preprocessor/sycl-macro.cpp 
b/clang/test/Preprocessor/sycl-macro.cpp
index eecddaa09d1c33..a509086f99e413 100644
--- a/clang/test/Preprocessor/sycl-macro.cpp
+++ b/clang/test/Preprocessor/sycl-macro.cpp
@@ -10,5 +10,5 @@
 // CHECK-NOT:#define __SYCL_DEVICE_ONLY__ 1
 // CHECK-NOT:#define CL_SYCL_LANGUAGE_VERSION 121
 // CHECK-SYCL-STD:#define CL_SYCL_LANGUAGE_VERSION 121
-// CHECK-SYCL-STD-2020:#define SYCL_LANGUAGE_VERSION 202001
+// CHECK-SYCL-STD-2020:#define SYCL_LANGUAGE_VERSION 202012
 // CHECK-SYCL:#define __SYCL_DEVICE_ONLY__ 1

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


[clang] [SYCL] change sycl version accrodnig to standard (PR #114790)

2024-11-04 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (dklochkov-emb)


Changes

Version of SYCL was changed according to the latest agreement:
The lower 2 digits are not formally specified, but we plan to use these to 
identify the month in which we submit the specification for ratification, which 
is similar to the C++ macro __cplusplus.

Since the SYCL 2020 specification was submitted for ratification in December of 
2020, the macro's value is now 202012 for SYCL 2020.
see PR for details 
https://github.com/KhronosGroup/SYCL-Docs/pull/634

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


2 Files Affected:

- (modified) clang/lib/Frontend/InitPreprocessor.cpp (+1-1) 
- (modified) clang/test/Preprocessor/sycl-macro.cpp (+1-1) 


``diff
diff --git a/clang/lib/Frontend/InitPreprocessor.cpp 
b/clang/lib/Frontend/InitPreprocessor.cpp
index 9a0fdb175ff29e..e9c7dc338380fd 100644
--- a/clang/lib/Frontend/InitPreprocessor.cpp
+++ b/clang/lib/Frontend/InitPreprocessor.cpp
@@ -587,7 +587,7 @@ static void InitializeStandardPredefinedMacros(const 
TargetInfo &TI,
 if (LangOpts.getSYCLVersion() == LangOptions::SYCL_2017)
   Builder.defineMacro("CL_SYCL_LANGUAGE_VERSION", "121");
 else if (LangOpts.getSYCLVersion() == LangOptions::SYCL_2020)
-  Builder.defineMacro("SYCL_LANGUAGE_VERSION", "202001");
+  Builder.defineMacro("SYCL_LANGUAGE_VERSION", "202012");
   }
 
   // Not "standard" per se, but available even with the -undef flag.
diff --git a/clang/test/Preprocessor/sycl-macro.cpp 
b/clang/test/Preprocessor/sycl-macro.cpp
index eecddaa09d1c33..a509086f99e413 100644
--- a/clang/test/Preprocessor/sycl-macro.cpp
+++ b/clang/test/Preprocessor/sycl-macro.cpp
@@ -10,5 +10,5 @@
 // CHECK-NOT:#define __SYCL_DEVICE_ONLY__ 1
 // CHECK-NOT:#define CL_SYCL_LANGUAGE_VERSION 121
 // CHECK-SYCL-STD:#define CL_SYCL_LANGUAGE_VERSION 121
-// CHECK-SYCL-STD-2020:#define SYCL_LANGUAGE_VERSION 202001
+// CHECK-SYCL-STD-2020:#define SYCL_LANGUAGE_VERSION 202012
 // CHECK-SYCL:#define __SYCL_DEVICE_ONLY__ 1

``




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


[clang] [llvm] [opt][AMDGPU] Add pass to handle AMDGCN pseudo-intrinsics, start with `llvm.amdgcn.wavefrontsize` (PR #114481)

2024-11-04 Thread Alex Voicu via cfe-commits

https://github.com/AlexVlx updated 
https://github.com/llvm/llvm-project/pull/114481

>From 3ba88ce598aaab269169f0a5db5981c9a9ac8603 Mon Sep 17 00:00:00 2001
From: Alex Voicu 
Date: Thu, 31 Oct 2024 22:38:36 +
Subject: [PATCH 1/4] Add pass to handle AMDGCN pseudo-intrinsics (abstract
 placeholders for target specific info), and add handling for
 `llvm.amdgcn.wavefrontsize`.

---
 clang/test/CodeGenOpenCL/builtins-amdgcn.cl   |  5 +-
 llvm/lib/Target/AMDGPU/AMDGPU.h   |  9 ++
 .../AMDGPU/AMDGPUExpandPseudoIntrinsics.cpp   | 49 +
 llvm/lib/Target/AMDGPU/AMDGPUPassRegistry.def |  2 +
 .../lib/Target/AMDGPU/AMDGPUTargetMachine.cpp |  3 +-
 llvm/lib/Target/AMDGPU/CMakeLists.txt |  1 +
 .../AMDGPU/llvm.amdgcn.wavefrontsize.ll   | 99 ++-
 7 files changed, 139 insertions(+), 29 deletions(-)
 create mode 100644 llvm/lib/Target/AMDGPU/AMDGPUExpandPseudoIntrinsics.cpp

diff --git a/clang/test/CodeGenOpenCL/builtins-amdgcn.cl 
b/clang/test/CodeGenOpenCL/builtins-amdgcn.cl
index bf5f2971cf118c..de6a06dad6a08d 100644
--- a/clang/test/CodeGenOpenCL/builtins-amdgcn.cl
+++ b/clang/test/CodeGenOpenCL/builtins-amdgcn.cl
@@ -1,6 +1,6 @@
 // REQUIRES: amdgpu-registered-target
 // RUN: %clang_cc1 -cl-std=CL2.0 -triple amdgcn-unknown-unknown -target-cpu 
tahiti -emit-llvm -o - %s | FileCheck -enable-var-scope 
--check-prefixes=CHECK-AMDGCN,CHECK %s
-// RUN: %clang_cc1 -cl-std=CL2.0 -triple spirv64-amd-amdhsa -emit-llvm -o - %s 
| FileCheck -enable-var-scope --check-prefix=CHECK %s
+// RUN: %clang_cc1 -cl-std=CL2.0 -triple spirv64-amd-amdhsa -emit-llvm -o - %s 
| FileCheck -enable-var-scope --check-prefixes=CHECK,CHECK-SPIRV %s
 
 
 #pragma OPENCL EXTENSION cl_khr_fp64 : enable
@@ -866,7 +866,8 @@ void test_atomic_inc_dec(__attribute__((address_space(3))) 
uint *lptr, __attribu
 // CHECK-LABEL test_wavefrontsize(
 unsigned test_wavefrontsize() {
 
-  // CHECK: {{.*}}call{{.*}} i32 @llvm.amdgcn.wavefrontsize()
+  // CHECK-AMDGCN: ret i32 {{[0-9]+}}
+  // CHECK-SPIRV: {{.*}}call{{.*}} i32 @llvm.amdgcn.wavefrontsize()
   return __builtin_amdgcn_wavefrontsize();
 }
 
diff --git a/llvm/lib/Target/AMDGPU/AMDGPU.h b/llvm/lib/Target/AMDGPU/AMDGPU.h
index 95d0ad0f9dc96a..17d3e6ab7c65ab 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPU.h
+++ b/llvm/lib/Target/AMDGPU/AMDGPU.h
@@ -345,6 +345,15 @@ extern char &AMDGPUPrintfRuntimeBindingID;
 void initializeAMDGPUResourceUsageAnalysisPass(PassRegistry &);
 extern char &AMDGPUResourceUsageAnalysisID;
 
+struct AMDGPUExpandPseudoIntrinsicsPass
+: PassInfoMixin {
+  const AMDGPUTargetMachine &TM;
+  AMDGPUExpandPseudoIntrinsicsPass(const AMDGPUTargetMachine &ATM) : TM(ATM) {}
+  PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
+
+  static bool isRequired() { return true; }
+};
+
 struct AMDGPUPrintfRuntimeBindingPass
 : PassInfoMixin {
   PreservedAnalyses run(Module &M, ModuleAnalysisManager &AM);
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUExpandPseudoIntrinsics.cpp 
b/llvm/lib/Target/AMDGPU/AMDGPUExpandPseudoIntrinsics.cpp
new file mode 100644
index 00..faa23bb8550dbc
--- /dev/null
+++ b/llvm/lib/Target/AMDGPU/AMDGPUExpandPseudoIntrinsics.cpp
@@ -0,0 +1,49 @@
+//===- AMDGPUExpandPseudoIntrinsics.cpp - Pseudo Intrinsic Expander Pass 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+// This file implements a pass that deals with expanding AMDGCN generic pseudo-
+// intrinsics into target specific quantities / sequences. In this context, a
+// pseudo-intrinsic is an AMDGCN intrinsic that does not directly map to a
+// specific instruction, but rather is intended as a mechanism for abstractly
+// conveying target specific info to a HLL / the FE, without concretely
+// impacting the AST. An example of such an intrinsic is amdgcn.wavefrontsize.
+// This pass should run as early as possible / immediately after Clang CodeGen,
+// so that the optimisation pipeline and the BE operate with concrete target
+// data.
+//===--===//
+
+#include "AMDGPU.h"
+#include "AMDGPUTargetMachine.h"
+#include "GCNSubtarget.h"
+
+#include "llvm/IR/Constants.h"
+#include "llvm/IR/Function.h"
+#include "llvm/IR/Module.h"
+#include "llvm/Pass.h"
+
+using namespace llvm;
+
+static inline PreservedAnalyses expandWaveSizeIntrinsic(const GCNSubtarget &ST,
+Function *WaveSize) {
+  if (WaveSize->hasZeroLiveUses())
+return PreservedAnalyses::all();
+
+  for (auto &&U : WaveSize->users())
+U->replaceAllUsesWith(ConstantInt::get(WaveSize->getReturnType(),
+   ST.getWavefrontSize()));
+
+  return PreservedAnalyses::none();
+}
+
+Preserved

[clang-tools-extra] [clangd] [Modules] Support Reusable Modules Builder (PR #106683)

2024-11-04 Thread kadir çetinkaya via cfe-commits


@@ -316,36 +294,205 @@ llvm::Error buildModuleFile(llvm::StringRef ModuleName,
   if (Clang->getDiagnostics().hasErrorOccurred())
 return llvm::createStringError("Compilation failed");
 
-  BuiltModuleFiles.addModuleFile(ModuleName, Inputs.CompileCommand.Output);
-  return llvm::Error::success();
+  return ModuleFile{ModuleName, Inputs.CompileCommand.Output};
+}
+
+bool ReusablePrerequisiteModules::canReuse(
+const CompilerInvocation &CI,
+llvm::IntrusiveRefCntPtr VFS) const {
+  if (RequiredModules.empty())
+return true;
+
+  SmallVector BMIPaths;
+  for (auto &MF : RequiredModules)
+BMIPaths.push_back(MF->getModuleFilePath());
+  return IsModuleFilesUpToDate(BMIPaths, *this, VFS);
+}
+
+class ModuleFileCache {
+public:
+  ModuleFileCache(const GlobalCompilationDatabase &CDB) : CDB(CDB) {}
+
+  llvm::Error
+  getOrBuildModuleFile(StringRef ModuleName, const ThreadsafeFS &TFS,
+   ProjectModules &MDB,
+   ReusablePrerequisiteModules &RequiredModules);
+  const GlobalCompilationDatabase &getCDB() const { return CDB; }
+
+  std::shared_ptr
+  getValidModuleFile(StringRef ModuleName, ProjectModules &MDB,
+ const ThreadsafeFS &TFS,
+ PrerequisiteModules &BuiltModuleFiles);
+
+  void add(StringRef ModuleName, std::shared_ptr ModuleFile) {
+std::lock_guard _(ModuleFilesMutex);
+
+ModuleFiles.insert_or_assign(ModuleName, ModuleFile);
+  }
+
+private:
+  const GlobalCompilationDatabase &CDB;
+
+  llvm::StringMap> ModuleFiles;
+  // Mutex to guard accesses to ModuleFiles.
+  std::mutex ModuleFilesMutex;
+};
+
+/// Collect the directly and indirectly required module names for \param
+/// ModuleName. The \param ModuleName is guaranteed to be the first element in
+/// \param ModuleNames.
+void getAllRequiredModules(ProjectModules &MDB, StringRef ModuleName,
+   llvm::SmallVector &ModuleNames) {
+  std::queue Worklist;
+  llvm::StringSet<> ModuleNamesSet;
+  Worklist.push(ModuleName);
+
+  while (!Worklist.empty()) {
+StringRef CurrentModule = Worklist.front();
+Worklist.pop();
+
+if (!ModuleNamesSet.insert(CurrentModule).second)
+  continue;
+
+ModuleNames.push_back(CurrentModule);
+
+for (StringRef RequiredModuleName :
+ MDB.getRequiredModules(MDB.getSourceForModuleName(CurrentModule)))
+  if (!ModuleNamesSet.contains(RequiredModuleName))
+Worklist.push(RequiredModuleName);
+  }
+}
+
+std::shared_ptr
+ModuleFileCache::getValidModuleFile(StringRef ModuleName, ProjectModules &MDB,
+const ThreadsafeFS &TFS,
+PrerequisiteModules &BuiltModuleFiles) {
+  {
+std::lock_guard _(ModuleFilesMutex);
+
+if (ModuleFiles.find(ModuleName) == ModuleFiles.end())

kadircet wrote:

prefer `.count`

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


[clang-tools-extra] [clangd] [Modules] Support Reusable Modules Builder (PR #106683)

2024-11-04 Thread kadir çetinkaya via cfe-commits


@@ -316,36 +294,205 @@ llvm::Error buildModuleFile(llvm::StringRef ModuleName,
   if (Clang->getDiagnostics().hasErrorOccurred())
 return llvm::createStringError("Compilation failed");
 
-  BuiltModuleFiles.addModuleFile(ModuleName, Inputs.CompileCommand.Output);
-  return llvm::Error::success();
+  return ModuleFile{ModuleName, Inputs.CompileCommand.Output};
+}
+
+bool ReusablePrerequisiteModules::canReuse(
+const CompilerInvocation &CI,
+llvm::IntrusiveRefCntPtr VFS) const {
+  if (RequiredModules.empty())
+return true;
+
+  SmallVector BMIPaths;
+  for (auto &MF : RequiredModules)
+BMIPaths.push_back(MF->getModuleFilePath());
+  return IsModuleFilesUpToDate(BMIPaths, *this, VFS);
+}
+
+class ModuleFileCache {
+public:
+  ModuleFileCache(const GlobalCompilationDatabase &CDB) : CDB(CDB) {}
+
+  llvm::Error
+  getOrBuildModuleFile(StringRef ModuleName, const ThreadsafeFS &TFS,
+   ProjectModules &MDB,
+   ReusablePrerequisiteModules &RequiredModules);
+  const GlobalCompilationDatabase &getCDB() const { return CDB; }
+
+  std::shared_ptr
+  getValidModuleFile(StringRef ModuleName, ProjectModules &MDB,
+ const ThreadsafeFS &TFS,
+ PrerequisiteModules &BuiltModuleFiles);
+
+  void add(StringRef ModuleName, std::shared_ptr ModuleFile) {
+std::lock_guard _(ModuleFilesMutex);
+
+ModuleFiles.insert_or_assign(ModuleName, ModuleFile);
+  }
+
+private:
+  const GlobalCompilationDatabase &CDB;
+
+  llvm::StringMap> ModuleFiles;
+  // Mutex to guard accesses to ModuleFiles.
+  std::mutex ModuleFilesMutex;
+};
+
+/// Collect the directly and indirectly required module names for \param
+/// ModuleName. The \param ModuleName is guaranteed to be the first element in
+/// \param ModuleNames.
+void getAllRequiredModules(ProjectModules &MDB, StringRef ModuleName,
+   llvm::SmallVector &ModuleNames) {
+  std::queue Worklist;
+  llvm::StringSet<> ModuleNamesSet;
+  Worklist.push(ModuleName);
+
+  while (!Worklist.empty()) {
+StringRef CurrentModule = Worklist.front();
+Worklist.pop();
+
+if (!ModuleNamesSet.insert(CurrentModule).second)
+  continue;
+
+ModuleNames.push_back(CurrentModule);
+
+for (StringRef RequiredModuleName :
+ MDB.getRequiredModules(MDB.getSourceForModuleName(CurrentModule)))
+  if (!ModuleNamesSet.contains(RequiredModuleName))

kadircet wrote:

let's perform the `insert` here and check if it succeeded to prevent extra loops

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


[clang-tools-extra] [clangd] [Modules] Support Reusable Modules Builder (PR #106683)

2024-11-04 Thread kadir çetinkaya via cfe-commits


@@ -316,36 +294,205 @@ llvm::Error buildModuleFile(llvm::StringRef ModuleName,
   if (Clang->getDiagnostics().hasErrorOccurred())
 return llvm::createStringError("Compilation failed");
 
-  BuiltModuleFiles.addModuleFile(ModuleName, Inputs.CompileCommand.Output);
-  return llvm::Error::success();
+  return ModuleFile{ModuleName, Inputs.CompileCommand.Output};
+}
+
+bool ReusablePrerequisiteModules::canReuse(
+const CompilerInvocation &CI,
+llvm::IntrusiveRefCntPtr VFS) const {
+  if (RequiredModules.empty())
+return true;
+
+  SmallVector BMIPaths;
+  for (auto &MF : RequiredModules)
+BMIPaths.push_back(MF->getModuleFilePath());
+  return IsModuleFilesUpToDate(BMIPaths, *this, VFS);
+}
+
+class ModuleFileCache {
+public:
+  ModuleFileCache(const GlobalCompilationDatabase &CDB) : CDB(CDB) {}
+
+  llvm::Error
+  getOrBuildModuleFile(StringRef ModuleName, const ThreadsafeFS &TFS,
+   ProjectModules &MDB,
+   ReusablePrerequisiteModules &RequiredModules);
+  const GlobalCompilationDatabase &getCDB() const { return CDB; }
+
+  std::shared_ptr
+  getValidModuleFile(StringRef ModuleName, ProjectModules &MDB,
+ const ThreadsafeFS &TFS,
+ PrerequisiteModules &BuiltModuleFiles);
+
+  void add(StringRef ModuleName, std::shared_ptr ModuleFile) {
+std::lock_guard _(ModuleFilesMutex);
+
+ModuleFiles.insert_or_assign(ModuleName, ModuleFile);
+  }
+
+private:
+  const GlobalCompilationDatabase &CDB;
+
+  llvm::StringMap> ModuleFiles;
+  // Mutex to guard accesses to ModuleFiles.
+  std::mutex ModuleFilesMutex;
+};
+
+/// Collect the directly and indirectly required module names for \param
+/// ModuleName. The \param ModuleName is guaranteed to be the first element in
+/// \param ModuleNames.
+void getAllRequiredModules(ProjectModules &MDB, StringRef ModuleName,
+   llvm::SmallVector &ModuleNames) {
+  std::queue Worklist;
+  llvm::StringSet<> ModuleNamesSet;
+  Worklist.push(ModuleName);
+
+  while (!Worklist.empty()) {
+StringRef CurrentModule = Worklist.front();
+Worklist.pop();
+
+if (!ModuleNamesSet.insert(CurrentModule).second)
+  continue;
+
+ModuleNames.push_back(CurrentModule);
+
+for (StringRef RequiredModuleName :
+ MDB.getRequiredModules(MDB.getSourceForModuleName(CurrentModule)))
+  if (!ModuleNamesSet.contains(RequiredModuleName))
+Worklist.push(RequiredModuleName);
+  }
+}
+
+std::shared_ptr
+ModuleFileCache::getValidModuleFile(StringRef ModuleName, ProjectModules &MDB,
+const ThreadsafeFS &TFS,
+PrerequisiteModules &BuiltModuleFiles) {
+  {
+std::lock_guard _(ModuleFilesMutex);
+
+if (ModuleFiles.find(ModuleName) == ModuleFiles.end())
+  return nullptr;
+  }
+
+  llvm::SmallVector ModuleNames;
+  getAllRequiredModules(MDB, ModuleName, ModuleNames);
+
+  llvm::SmallVector> RequiredModuleFiles;
+
+  {
+std::lock_guard _(ModuleFilesMutex);
+
+for (StringRef ModuleName : ModuleNames) {
+  auto Iter = ModuleFiles.find(ModuleName);
+  if (Iter == ModuleFiles.end())
+return nullptr;
+
+  RequiredModuleFiles.push_back(Iter->second);
+}
+  }
+
+  if (RequiredModuleFiles.empty())
+return nullptr;
+
+  if (llvm::all_of(RequiredModuleFiles, [&](auto MF) {

kadircet wrote:

use `any_of` and invert the `IsModuleFileUpToDate` check to bail out early here.

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


[clang-tools-extra] [clangd] [Modules] Support Reusable Modules Builder (PR #106683)

2024-11-04 Thread kadir çetinkaya via cfe-commits


@@ -316,36 +294,205 @@ llvm::Error buildModuleFile(llvm::StringRef ModuleName,
   if (Clang->getDiagnostics().hasErrorOccurred())
 return llvm::createStringError("Compilation failed");
 
-  BuiltModuleFiles.addModuleFile(ModuleName, Inputs.CompileCommand.Output);
-  return llvm::Error::success();
+  return ModuleFile{ModuleName, Inputs.CompileCommand.Output};
+}
+
+bool ReusablePrerequisiteModules::canReuse(
+const CompilerInvocation &CI,
+llvm::IntrusiveRefCntPtr VFS) const {
+  if (RequiredModules.empty())
+return true;
+
+  SmallVector BMIPaths;
+  for (auto &MF : RequiredModules)
+BMIPaths.push_back(MF->getModuleFilePath());
+  return IsModuleFilesUpToDate(BMIPaths, *this, VFS);
+}
+
+class ModuleFileCache {
+public:
+  ModuleFileCache(const GlobalCompilationDatabase &CDB) : CDB(CDB) {}
+
+  llvm::Error
+  getOrBuildModuleFile(StringRef ModuleName, const ThreadsafeFS &TFS,
+   ProjectModules &MDB,
+   ReusablePrerequisiteModules &RequiredModules);
+  const GlobalCompilationDatabase &getCDB() const { return CDB; }
+
+  std::shared_ptr
+  getValidModuleFile(StringRef ModuleName, ProjectModules &MDB,
+ const ThreadsafeFS &TFS,
+ PrerequisiteModules &BuiltModuleFiles);
+
+  void add(StringRef ModuleName, std::shared_ptr ModuleFile) {
+std::lock_guard _(ModuleFilesMutex);
+
+ModuleFiles.insert_or_assign(ModuleName, ModuleFile);
+  }
+
+private:
+  const GlobalCompilationDatabase &CDB;
+
+  llvm::StringMap> ModuleFiles;
+  // Mutex to guard accesses to ModuleFiles.
+  std::mutex ModuleFilesMutex;
+};
+
+/// Collect the directly and indirectly required module names for \param
+/// ModuleName. The \param ModuleName is guaranteed to be the first element in
+/// \param ModuleNames.
+void getAllRequiredModules(ProjectModules &MDB, StringRef ModuleName,
+   llvm::SmallVector &ModuleNames) {
+  std::queue Worklist;
+  llvm::StringSet<> ModuleNamesSet;
+  Worklist.push(ModuleName);
+
+  while (!Worklist.empty()) {
+StringRef CurrentModule = Worklist.front();
+Worklist.pop();
+
+if (!ModuleNamesSet.insert(CurrentModule).second)
+  continue;
+
+ModuleNames.push_back(CurrentModule);
+
+for (StringRef RequiredModuleName :
+ MDB.getRequiredModules(MDB.getSourceForModuleName(CurrentModule)))
+  if (!ModuleNamesSet.contains(RequiredModuleName))
+Worklist.push(RequiredModuleName);
+  }
+}
+
+std::shared_ptr
+ModuleFileCache::getValidModuleFile(StringRef ModuleName, ProjectModules &MDB,
+const ThreadsafeFS &TFS,
+PrerequisiteModules &BuiltModuleFiles) {
+  {
+std::lock_guard _(ModuleFilesMutex);
+
+if (ModuleFiles.find(ModuleName) == ModuleFiles.end())
+  return nullptr;
+  }
+
+  llvm::SmallVector ModuleNames;
+  getAllRequiredModules(MDB, ModuleName, ModuleNames);
+
+  llvm::SmallVector> RequiredModuleFiles;
+
+  {
+std::lock_guard _(ModuleFilesMutex);
+
+for (StringRef ModuleName : ModuleNames) {
+  auto Iter = ModuleFiles.find(ModuleName);
+  if (Iter == ModuleFiles.end())
+return nullptr;
+
+  RequiredModuleFiles.push_back(Iter->second);
+}
+  }
+
+  if (RequiredModuleFiles.empty())
+return nullptr;

kadircet wrote:

we already returned nullptr if we're missing **any** module-files in the loop 
above

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


[clang-tools-extra] [clangd] [Modules] Support Reusable Modules Builder (PR #106683)

2024-11-04 Thread kadir çetinkaya via cfe-commits

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


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


[clang-tools-extra] [clangd] [Modules] Support Reusable Modules Builder (PR #106683)

2024-11-04 Thread kadir çetinkaya via cfe-commits


@@ -316,36 +294,205 @@ llvm::Error buildModuleFile(llvm::StringRef ModuleName,
   if (Clang->getDiagnostics().hasErrorOccurred())
 return llvm::createStringError("Compilation failed");
 
-  BuiltModuleFiles.addModuleFile(ModuleName, Inputs.CompileCommand.Output);
-  return llvm::Error::success();
+  return ModuleFile{ModuleName, Inputs.CompileCommand.Output};
+}
+
+bool ReusablePrerequisiteModules::canReuse(
+const CompilerInvocation &CI,
+llvm::IntrusiveRefCntPtr VFS) const {
+  if (RequiredModules.empty())
+return true;
+
+  SmallVector BMIPaths;
+  for (auto &MF : RequiredModules)
+BMIPaths.push_back(MF->getModuleFilePath());
+  return IsModuleFilesUpToDate(BMIPaths, *this, VFS);
+}
+
+class ModuleFileCache {
+public:
+  ModuleFileCache(const GlobalCompilationDatabase &CDB) : CDB(CDB) {}
+
+  llvm::Error
+  getOrBuildModuleFile(StringRef ModuleName, const ThreadsafeFS &TFS,
+   ProjectModules &MDB,
+   ReusablePrerequisiteModules &RequiredModules);
+  const GlobalCompilationDatabase &getCDB() const { return CDB; }
+
+  std::shared_ptr
+  getValidModuleFile(StringRef ModuleName, ProjectModules &MDB,
+ const ThreadsafeFS &TFS,
+ PrerequisiteModules &BuiltModuleFiles);
+
+  void add(StringRef ModuleName, std::shared_ptr ModuleFile) {
+std::lock_guard _(ModuleFilesMutex);
+
+ModuleFiles.insert_or_assign(ModuleName, ModuleFile);
+  }
+
+private:
+  const GlobalCompilationDatabase &CDB;
+
+  llvm::StringMap> ModuleFiles;
+  // Mutex to guard accesses to ModuleFiles.
+  std::mutex ModuleFilesMutex;
+};
+
+/// Collect the directly and indirectly required module names for \param
+/// ModuleName. The \param ModuleName is guaranteed to be the first element in
+/// \param ModuleNames.
+void getAllRequiredModules(ProjectModules &MDB, StringRef ModuleName,

kadircet wrote:

can you just return `std::vector` instead of taking an out parameter 
here?

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


[clang-tools-extra] [clangd] [Modules] Support Reusable Modules Builder (PR #106683)

2024-11-04 Thread kadir çetinkaya via cfe-commits


@@ -316,36 +294,205 @@ llvm::Error buildModuleFile(llvm::StringRef ModuleName,
   if (Clang->getDiagnostics().hasErrorOccurred())
 return llvm::createStringError("Compilation failed");
 
-  BuiltModuleFiles.addModuleFile(ModuleName, Inputs.CompileCommand.Output);
-  return llvm::Error::success();
+  return ModuleFile{ModuleName, Inputs.CompileCommand.Output};
+}
+
+bool ReusablePrerequisiteModules::canReuse(
+const CompilerInvocation &CI,
+llvm::IntrusiveRefCntPtr VFS) const {
+  if (RequiredModules.empty())
+return true;
+
+  SmallVector BMIPaths;
+  for (auto &MF : RequiredModules)
+BMIPaths.push_back(MF->getModuleFilePath());
+  return IsModuleFilesUpToDate(BMIPaths, *this, VFS);
+}
+
+class ModuleFileCache {
+public:
+  ModuleFileCache(const GlobalCompilationDatabase &CDB) : CDB(CDB) {}
+
+  llvm::Error
+  getOrBuildModuleFile(StringRef ModuleName, const ThreadsafeFS &TFS,
+   ProjectModules &MDB,
+   ReusablePrerequisiteModules &RequiredModules);
+  const GlobalCompilationDatabase &getCDB() const { return CDB; }
+
+  std::shared_ptr
+  getValidModuleFile(StringRef ModuleName, ProjectModules &MDB,
+ const ThreadsafeFS &TFS,
+ PrerequisiteModules &BuiltModuleFiles);
+
+  void add(StringRef ModuleName, std::shared_ptr ModuleFile) {
+std::lock_guard _(ModuleFilesMutex);
+
+ModuleFiles.insert_or_assign(ModuleName, ModuleFile);
+  }
+
+private:
+  const GlobalCompilationDatabase &CDB;
+
+  llvm::StringMap> ModuleFiles;
+  // Mutex to guard accesses to ModuleFiles.
+  std::mutex ModuleFilesMutex;
+};
+
+/// Collect the directly and indirectly required module names for \param
+/// ModuleName. The \param ModuleName is guaranteed to be the first element in
+/// \param ModuleNames.
+void getAllRequiredModules(ProjectModules &MDB, StringRef ModuleName,
+   llvm::SmallVector &ModuleNames) {
+  std::queue Worklist;
+  llvm::StringSet<> ModuleNamesSet;
+  Worklist.push(ModuleName);
+
+  while (!Worklist.empty()) {
+StringRef CurrentModule = Worklist.front();
+Worklist.pop();
+
+if (!ModuleNamesSet.insert(CurrentModule).second)
+  continue;
+
+ModuleNames.push_back(CurrentModule);
+
+for (StringRef RequiredModuleName :
+ MDB.getRequiredModules(MDB.getSourceForModuleName(CurrentModule)))
+  if (!ModuleNamesSet.contains(RequiredModuleName))
+Worklist.push(RequiredModuleName);
+  }
+}
+
+std::shared_ptr
+ModuleFileCache::getValidModuleFile(StringRef ModuleName, ProjectModules &MDB,
+const ThreadsafeFS &TFS,
+PrerequisiteModules &BuiltModuleFiles) {
+  {
+std::lock_guard _(ModuleFilesMutex);

kadircet wrote:

call it `Lock` (same below)

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


[clang-tools-extra] [clangd] [Modules] Support Reusable Modules Builder (PR #106683)

2024-11-04 Thread kadir çetinkaya via cfe-commits


@@ -228,54 +223,30 @@ class StandalonePrerequisiteModules : public 
PrerequisiteModules {
 return BuiltModuleNames.contains(ModuleName);
   }
 
-  void addModuleFile(llvm::StringRef ModuleName,
- llvm::StringRef ModuleFilePath) {
-RequiredModules.emplace_back(ModuleName, ModuleFilePath);
-BuiltModuleNames.insert(ModuleName);
+  void addModuleFile(std::shared_ptr BMI) {
+BuiltModuleNames.insert(BMI->ModuleName);
+RequiredModules.emplace_back(std::move(BMI));
   }
 
 private:
-  llvm::SmallVector RequiredModules;
+  mutable llvm::SmallVector, 8> RequiredModules;

kadircet wrote:

> I add the data members of ModuleFile  to be private and we can only access 
> them by the getters. I think this has the same effect.

i don't think it has the same affect. It makes sure code today is adhering to 
those standards because you and me have context and very careful about the 
interaction. Tomorrow someone might end up mutating ModuleFiles because the 
interfaces in builder didn't enforce that and they didn't pay as much attention 
to subtle shared ownership model.

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


[clang-tools-extra] [clangd] [Modules] Support Reusable Modules Builder (PR #106683)

2024-11-04 Thread kadir çetinkaya via cfe-commits


@@ -316,36 +287,169 @@ llvm::Error buildModuleFile(llvm::StringRef ModuleName,
   if (Clang->getDiagnostics().hasErrorOccurred())
 return llvm::createStringError("Compilation failed");
 
-  BuiltModuleFiles.addModuleFile(ModuleName, Inputs.CompileCommand.Output);
-  return llvm::Error::success();
+  return ModuleFile{ModuleName, Inputs.CompileCommand.Output};
+}
+
+bool ReusablePrerequisiteModules::canReuse(
+const CompilerInvocation &CI,
+llvm::IntrusiveRefCntPtr VFS) const {
+  if (RequiredModules.empty())
+return true;
+
+  SmallVector BMIPaths;
+  for (auto &MF : RequiredModules)
+BMIPaths.push_back(MF->ModuleFilePath);
+  return IsModuleFilesUpToDate(BMIPaths, *this, VFS);
 }
 } // namespace
 
+class ModulesBuilder::ModuleFileCache {
+public:
+  ModuleFileCache(const GlobalCompilationDatabase &CDB) : CDB(CDB) {}
+
+  llvm::Error
+  getOrBuildModuleFile(StringRef ModuleName, const ThreadsafeFS &TFS,
+   ProjectModules &MDB,
+   ReusablePrerequisiteModules &RequiredModules);
+  const GlobalCompilationDatabase &getCDB() const { return CDB; }
+
+private:
+  std::shared_ptr
+  getValidModuleFile(StringRef ModuleName, ProjectModules &MDB,
+ const ThreadsafeFS &TFS,
+ PrerequisiteModules &BuiltModuleFiles);
+
+  /// This should only be called by getValidModuleFile. This is unlocked 
version
+  /// of getValidModuleFile. The function is extracted to avoid dead locks when
+  /// recursing.
+  std::shared_ptr
+  isValidModuleFileUnlocked(StringRef ModuleName, ProjectModules &MDB,
+const ThreadsafeFS &TFS,
+PrerequisiteModules &BuiltModuleFiles);
+
+  const GlobalCompilationDatabase &CDB;
+
+  llvm::StringMap> ModuleFiles;

kadircet wrote:

> The cache should be an owner. Otherwise, if we close all tabs and we open a 
> tab again, we may have to build the same module file that could be in the 
> cache.

Yes, and I think that's WAI. That's what clangd has today with preambles, if 
you close a file and re-open it, you'll pay for the warm up cost.

This ensures we can keep a long editing session going on. We ensure we're 
clearing up the resources as people close their files. Doing it differently 
here will imply clangd can no longer be used in workflows that open tons of 
files while navigating the codebase. As nothing will clear up the dependent 
modules built in the meanwhile.

We're still going to provide better performance here, compared to preambles. As 
we'll re-use any "core" modules that we keep in the cache.

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


[clang-tools-extra] [clangd] [Modules] Support Reusable Modules Builder (PR #106683)

2024-11-04 Thread kadir çetinkaya via cfe-commits


@@ -316,36 +287,169 @@ llvm::Error buildModuleFile(llvm::StringRef ModuleName,
   if (Clang->getDiagnostics().hasErrorOccurred())
 return llvm::createStringError("Compilation failed");
 
-  BuiltModuleFiles.addModuleFile(ModuleName, Inputs.CompileCommand.Output);
-  return llvm::Error::success();
+  return ModuleFile{ModuleName, Inputs.CompileCommand.Output};
+}
+
+bool ReusablePrerequisiteModules::canReuse(
+const CompilerInvocation &CI,
+llvm::IntrusiveRefCntPtr VFS) const {
+  if (RequiredModules.empty())
+return true;
+
+  SmallVector BMIPaths;
+  for (auto &MF : RequiredModules)
+BMIPaths.push_back(MF->ModuleFilePath);
+  return IsModuleFilesUpToDate(BMIPaths, *this, VFS);
 }
 } // namespace
 
+class ModulesBuilder::ModuleFileCache {
+public:
+  ModuleFileCache(const GlobalCompilationDatabase &CDB) : CDB(CDB) {}
+
+  llvm::Error
+  getOrBuildModuleFile(StringRef ModuleName, const ThreadsafeFS &TFS,
+   ProjectModules &MDB,
+   ReusablePrerequisiteModules &RequiredModules);
+  const GlobalCompilationDatabase &getCDB() const { return CDB; }
+
+private:
+  std::shared_ptr
+  getValidModuleFile(StringRef ModuleName, ProjectModules &MDB,
+ const ThreadsafeFS &TFS,
+ PrerequisiteModules &BuiltModuleFiles);
+
+  /// This should only be called by getValidModuleFile. This is unlocked 
version
+  /// of getValidModuleFile. The function is extracted to avoid dead locks when
+  /// recursing.
+  std::shared_ptr
+  isValidModuleFileUnlocked(StringRef ModuleName, ProjectModules &MDB,
+const ThreadsafeFS &TFS,
+PrerequisiteModules &BuiltModuleFiles);
+
+  const GlobalCompilationDatabase &CDB;
+
+  llvm::StringMap> ModuleFiles;
+  // Mutex to guard accesses to ModuleFiles.
+  std::mutex ModuleFilesMutex;
+};
+
+std::shared_ptr
+ModulesBuilder::ModuleFileCache::isValidModuleFileUnlocked(
+StringRef ModuleName, ProjectModules &MDB, const ThreadsafeFS &TFS,
+PrerequisiteModules &BuiltModuleFiles) {
+  auto Iter = ModuleFiles.find(ModuleName);
+  if (Iter != ModuleFiles.end()) {
+if (!IsModuleFileUpToDate(Iter->second->ModuleFilePath, BuiltModuleFiles,
+  TFS.view(std::nullopt))) {
+  log("Found not-up-date module file {0} for module {1} in cache",
+  Iter->second->ModuleFilePath, ModuleName);
+  ModuleFiles.erase(Iter);
+  return nullptr;
+}
+
+if (llvm::any_of(
+MDB.getRequiredModules(MDB.getSourceForModuleName(ModuleName)),
+[&MDB, &TFS, &BuiltModuleFiles, this](auto &&RequiredModuleName) {
+  return !isValidModuleFileUnlocked(RequiredModuleName, MDB, TFS,
+BuiltModuleFiles);
+})) {
+  ModuleFiles.erase(Iter);
+  return nullptr;
+}
+
+return Iter->second;
+  }
+
+  log("Don't find {0} in cache", ModuleName);
+
+  return nullptr;
+}
+
+std::shared_ptr 
ModulesBuilder::ModuleFileCache::getValidModuleFile(
+StringRef ModuleName, ProjectModules &MDB, const ThreadsafeFS &TFS,
+PrerequisiteModules &BuiltModuleFiles) {
+  std::lock_guard _(ModuleFilesMutex);
+
+  return isValidModuleFileUnlocked(ModuleName, MDB, TFS, BuiltModuleFiles);
+}
+
+llvm::Error ModulesBuilder::ModuleFileCache::getOrBuildModuleFile(

kadircet wrote:

i think we achieved the bit around cache just being a cache, but understanding 
of building a module is still split across two places. as `ModulesBuilderImpl` 
needs to know details of `buildModuleFile` (as it ensures to call this function 
only after all the dependent modules are traversed and build), and 
`buildModuleFile` knows the other bit around invoking a compilation and 
trusting it will only be called after all the dependencies are build.

Can we make sure all of this logic is contained in one place instead?

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


[clang-tools-extra] Enforce SL.con.3: Add check to replace operator[] with at() [Cont.] (PR #95220)

2024-11-04 Thread via cfe-commits
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= 
Message-ID:
In-Reply-To: 


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


[clang-tools-extra] [clangd] Fix use-after-free issues in TidyProvider.cpp (PR #114808)

2024-11-04 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang-tools-extra

@llvm/pr-subscribers-clangd

Author: Haojian Wu (hokein)


Changes



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


1 Files Affected:

- (modified) clang-tools-extra/clangd/TidyProvider.cpp (+12-7) 


``diff
diff --git a/clang-tools-extra/clangd/TidyProvider.cpp 
b/clang-tools-extra/clangd/TidyProvider.cpp
index a87238e0c0938c..f35cf9f0ab999d 100644
--- a/clang-tools-extra/clangd/TidyProvider.cpp
+++ b/clang-tools-extra/clangd/TidyProvider.cpp
@@ -46,7 +46,7 @@ class DotClangTidyCache : private FileCache {
 [this](std::optional Data) {
   Value.reset();
   if (Data && !Data->empty()) {
-tidy::DiagCallback Diagnostics = [](const llvm::SMDiagnostic &D) {
+auto Diagnostics = [](const llvm::SMDiagnostic &D) {
   switch (D.getKind()) {
   case llvm::SourceMgr::DK_Error:
 elog("tidy-config error at {0}:{1}:{2}: {3}", D.getFilename(),
@@ -159,12 +159,15 @@ TidyProviderRef provideEnvironment() {
 return Ret;
   }();
 
-  if (User)
-return
-[](tidy::ClangTidyOptions &Opts, llvm::StringRef) { Opts.User = User; 
};
+  if (User) {
+static const auto Provider = [](tidy::ClangTidyOptions &Opts, 
llvm::StringRef) { Opts.User = User; };
+return Provider;
+  }
   // FIXME: Once function_ref and unique_function operator= operators handle
   // null values, this can return null.
-  return [](tidy::ClangTidyOptions &, llvm::StringRef) {};
+  static const auto EmptyProvider = [](tidy::ClangTidyOptions &,
+   llvm::StringRef) {};
+  return EmptyProvider;
 }
 
 TidyProviderRef provideDefaultChecks() {
@@ -178,10 +181,11 @@ TidyProviderRef provideDefaultChecks() {
   "bugprone-suspicious-missing-comma", "bugprone-unused-raii",
   "bugprone-unused-return-value", "misc-unused-using-decls",
   "misc-unused-alias-decls", "misc-definitions-in-headers");
-  return [](tidy::ClangTidyOptions &Opts, llvm::StringRef) {
+  static auto Provider =  [](tidy::ClangTidyOptions &Opts, llvm::StringRef) {
 if (!Opts.Checks || Opts.Checks->empty())
   Opts.Checks = DefaultChecks;
   };
+  return Provider;
 }
 
 TidyProvider addTidyChecks(llvm::StringRef Checks,
@@ -252,7 +256,7 @@ TidyProvider 
disableUnusableChecks(llvm::ArrayRef ExtraBadChecks) {
 }
 
 TidyProviderRef provideClangdConfig() {
-  return [](tidy::ClangTidyOptions &Opts, llvm::StringRef) {
+  static const auto Provider = [](tidy::ClangTidyOptions &Opts, 
llvm::StringRef) {
 const auto &CurTidyConfig = Config::current().Diagnostics.ClangTidy;
 if (!CurTidyConfig.Checks.empty())
   mergeCheckList(Opts.Checks, CurTidyConfig.Checks);
@@ -262,6 +266,7 @@ TidyProviderRef provideClangdConfig() {
  
tidy::ClangTidyOptions::ClangTidyValue(
  CheckOption.getValue(), 1U));
   };
+  return Provider;
 }
 
 TidyProvider provideClangTidyFiles(ThreadsafeFS &TFS) {

``




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


[clang-tools-extra] [clang-query] add basic profiling on matching each ASTs (PR #114806)

2024-11-04 Thread Ding Fei via cfe-commits

https://github.com/danix800 updated 
https://github.com/llvm/llvm-project/pull/114806

>From dfd42c06d94f859ec78ec1e5c3386c0e4016386f Mon Sep 17 00:00:00 2001
From: dingfei 
Date: Mon, 4 Nov 2024 22:37:51 +0800
Subject: [PATCH 1/3] [clang-query] add basic profiling on matching each ASTs

Sample output:

$ cat test.cql
set enable-profile true
m binaryOperator(isExpansionInMainFile())

$ cat test.c
int test(int i, int j) {
  return i + j;
}

$ clang-query --track-memory -f test.cql test.c --

Match #1:

{{.*}}/test.c:2:10: note: "root" binds here
2 |   return i + j;
  |  ^
1 match.
===-===
 clang-query matcher profiling
===-===
  Total Execution Time: 0. seconds (0. wall clock)

   ---User Time---   --System Time--   --User+System--   ---Wall Time---  
---Mem---  --- Name ---
   0. (100.0%)   0. (100.0%)   0. (100.0%)   0. (100.0%)
224  {{.*}}/test.c
   0. (100.0%)   0. (100.0%)   0. (100.0%)   0. (100.0%)
224  Total
---
 clang-tools-extra/clang-query/CMakeLists.txt  |  1 +
 clang-tools-extra/clang-query/Query.cpp   | 26 --
 clang-tools-extra/clang-query/QueryParser.cpp |  5 +++
 .../clang-query/QueryProfile.cpp  | 24 +
 clang-tools-extra/clang-query/QueryProfile.h  | 35 +++
 clang-tools-extra/clang-query/QuerySession.h  |  3 +-
 6 files changed, 90 insertions(+), 4 deletions(-)
 create mode 100644 clang-tools-extra/clang-query/QueryProfile.cpp
 create mode 100644 clang-tools-extra/clang-query/QueryProfile.h

diff --git a/clang-tools-extra/clang-query/CMakeLists.txt 
b/clang-tools-extra/clang-query/CMakeLists.txt
index b168a3a8581567..84a1ad6fa33582 100644
--- a/clang-tools-extra/clang-query/CMakeLists.txt
+++ b/clang-tools-extra/clang-query/CMakeLists.txt
@@ -7,6 +7,7 @@ set(LLVM_LINK_COMPONENTS
 add_clang_library(clangQuery STATIC
   Query.cpp
   QueryParser.cpp
+  QueryProfile.cpp
 
   DEPENDS
   omp_gen
diff --git a/clang-tools-extra/clang-query/Query.cpp 
b/clang-tools-extra/clang-query/Query.cpp
index 282d136aff721a..5b628de3c4deeb 100644
--- a/clang-tools-extra/clang-query/Query.cpp
+++ b/clang-tools-extra/clang-query/Query.cpp
@@ -8,6 +8,7 @@
 
 #include "Query.h"
 #include "QueryParser.h"
+#include "QueryProfile.h"
 #include "QuerySession.h"
 #include "clang/AST/ASTDumper.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
@@ -44,6 +45,8 @@ bool HelpQuery::run(llvm::raw_ostream &OS, QuerySession &QS) 
const {
 "  set bind-root (true|false)"
 "Set whether to bind the root matcher to \"root\".\n"
 "  set print-matcher (true|false)"
+"  set enable-profile (true|false)"
+"Set whether to enable matcher profiling,\n"
 "Set whether to print the current matcher,\n"
 "  set traversal   "
 "Set traversal kind of clang-query session. Available kinds are:\n"
@@ -82,10 +85,13 @@ namespace {
 
 struct CollectBoundNodes : MatchFinder::MatchCallback {
   std::vector &Bindings;
-  CollectBoundNodes(std::vector &Bindings) : Bindings(Bindings) {}
+  StringRef Unit;
+  CollectBoundNodes(std::vector &Bindings, StringRef Unit)
+  : Bindings(Bindings), Unit(Unit) {}
   void run(const MatchFinder::MatchResult &Result) override {
 Bindings.push_back(Result.Nodes);
   }
+  StringRef getID() const override { return Unit; }
 };
 
 } // namespace
@@ -93,8 +99,19 @@ struct CollectBoundNodes : MatchFinder::MatchCallback {
 bool MatchQuery::run(llvm::raw_ostream &OS, QuerySession &QS) const {
   unsigned MatchCount = 0;
 
+  std::optional Profiling;
+  if (QS.EnableProfile)
+Profiling = QueryProfile();
+
   for (auto &AST : QS.ASTs) {
-MatchFinder Finder;
+ast_matchers::MatchFinder::MatchFinderOptions FinderOptions;
+std::optional> Records;
+if (QS.EnableProfile) {
+  Records.emplace();
+  FinderOptions.CheckProfiling.emplace(*Records);
+}
+
+MatchFinder Finder(FinderOptions);
 std::vector Matches;
 DynTypedMatcher MaybeBoundMatcher = Matcher;
 if (QS.BindRoot) {
@@ -102,7 +119,8 @@ bool MatchQuery::run(llvm::raw_ostream &OS, QuerySession 
&QS) const {
   if (M)
 MaybeBoundMatcher = *M;
 }
-CollectBoundNodes Collect(Matches);
+StringRef OrigSrcName = AST->getOriginalSourceFileName();
+CollectBoundNodes Collect(Matches, OrigSrcName);
 if (!Finder.addDynamicMatcher(MaybeBoundMatcher, &Collect)) {
   OS << "Not a valid top-level matcher.\n";
   return false;
@@ -111,6 +129,8 @@ bool MatchQuery::run(llvm::raw_ostream &OS, QuerySession 
&QS) const {
 ASTContext &Ctx = AST->getASTContext();
 Ctx.getParentMapContext().setTraversalKind(QS.TK);
 Finder.matchAST(Ctx);
+if (QS.EnableProfile)
+  Profiling->Records[OrigSrcName] += (*Records)[Orig

[clang-tools-extra] [clangd] Fix use-after-free issues in TidyProvider.cpp (PR #114808)

2024-11-04 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 0653698d8637b8d565cbf59de591e2d8c61c20cc 
38c41b134b7092d880ba349bcca1a7bb6887d1dc --extensions cpp -- 
clang-tools-extra/clangd/TidyProvider.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang-tools-extra/clangd/TidyProvider.cpp 
b/clang-tools-extra/clangd/TidyProvider.cpp
index f35cf9f0ab..f94e095492 100644
--- a/clang-tools-extra/clangd/TidyProvider.cpp
+++ b/clang-tools-extra/clangd/TidyProvider.cpp
@@ -160,7 +160,8 @@ TidyProviderRef provideEnvironment() {
   }();
 
   if (User) {
-static const auto Provider = [](tidy::ClangTidyOptions &Opts, 
llvm::StringRef) { Opts.User = User; };
+static const auto Provider = [](tidy::ClangTidyOptions &Opts,
+llvm::StringRef) { Opts.User = User; };
 return Provider;
   }
   // FIXME: Once function_ref and unique_function operator= operators handle
@@ -181,7 +182,7 @@ TidyProviderRef provideDefaultChecks() {
   "bugprone-suspicious-missing-comma", "bugprone-unused-raii",
   "bugprone-unused-return-value", "misc-unused-using-decls",
   "misc-unused-alias-decls", "misc-definitions-in-headers");
-  static auto Provider =  [](tidy::ClangTidyOptions &Opts, llvm::StringRef) {
+  static auto Provider = [](tidy::ClangTidyOptions &Opts, llvm::StringRef) {
 if (!Opts.Checks || Opts.Checks->empty())
   Opts.Checks = DefaultChecks;
   };
@@ -256,7 +257,8 @@ TidyProvider 
disableUnusableChecks(llvm::ArrayRef ExtraBadChecks) {
 }
 
 TidyProviderRef provideClangdConfig() {
-  static const auto Provider = [](tidy::ClangTidyOptions &Opts, 
llvm::StringRef) {
+  static const auto Provider = [](tidy::ClangTidyOptions &Opts,
+  llvm::StringRef) {
 const auto &CurTidyConfig = Config::current().Diagnostics.ClangTidy;
 if (!CurTidyConfig.Checks.empty())
   mergeCheckList(Opts.Checks, CurTidyConfig.Checks);

``




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


[clang-tools-extra] [clang-query] add basic profiling on matching each ASTs (PR #114806)

2024-11-04 Thread Ding Fei via cfe-commits

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


[clang-tools-extra] Enforce SL.con.3: Add check to replace operator[] with at() [Cont.] (PR #95220)

2024-11-04 Thread via cfe-commits
=��___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] Enforce SL.con.3: Add check to replace operator[] with at() [Cont.] (PR #95220)

2024-11-04 Thread via cfe-commits
Paul =?utf-8?q?Heidekr=C3=BCger?= ,
Paul =?utf-8?q?Heidekr=C3=BCger?= ,
Paul =?utf-8?q?Heidekr=C3=BCger?= ,
Paul =?utf-8?q?Heidekr=C3=BCger?= ,
Paul =?utf-8?q?Heidekr=C3=BCger?= ,
Paul =?utf-8?q?Heidekr=C3=BCger?= ,
Paul =?utf-8?q?Heidekr=C3=BCger?= ,
Paul =?utf-8?q?Heidekr=C3=BCger?= ,
Paul =?utf-8?q?Heidekr=C3=BCger?= ,
Paul =?utf-8?q?Heidekr=C3=BCger?= ,
Paul =?utf-8?q?Heidekr=C3=BCger?= ,
Paul =?utf-8?q?Heidekr=C3=BCger?= ,
Paul =?utf-8?q?Heidekr=C3=BCger?= ,
Paul =?utf-8?q?Heidekr=C3=BCger?= ,
Paul =?utf-8?q?Heidekr=C3=BCger?= ,
Paul =?utf-8?q?Heidekr=C3=BCger?= ,
Paul =?utf-8?q?Heidekr=C3=BCger?= ,
Paul =?utf-8?q?Heidekr=C3=BCger?= ,
Paul =?utf-8?q?Heidekr=C3=BCger?= ,
Paul =?utf-8?q?Heidekr=C3=BCger?= ,
Paul =?utf-8?q?Heidekr=C3=BCger?= ,
Paul =?utf-8?q?Heidekr=C3=BCger?= ,
Paul =?utf-8?q?Heidekr=C3=BCger?= ,
Paul =?utf-8?q?Heidekr=C3=BCger?= ,
Paul =?utf-8?q?Heidekr=C3=BCger?= ,
Paul =?utf-8?q?Heidekr=C3=BCger?= ,
Paul =?utf-8?q?Heidekr=C3=BCger?= ,
Paul =?utf-8?q?Heidekr=C3=BCger?= ,
Paul =?utf-8?q?Heidekr=C3=BCger?= ,
Paul =?utf-8?q?Heidekr=C3=BCger?= ,
Paul =?utf-8?q?Heidekr=C3=BCger?= ,
Paul =?utf-8?q?Heidekr=C3=BCger?= ,
Paul =?utf-8?q?Heidekr=C3=BCger?= ,
Paul =?utf-8?q?Heidekr=C3=BCger?= ,
Paul =?utf-8?q?Heidekr=C3=BCger?= ,
Paul =?utf-8?q?Heidekr=C3=BCger?= ,
Paul =?utf-8?q?Heidekr=C3=BCger?= ,
Paul =?utf-8?q?Heidekr=C3=BCger?= ,
Paul =?utf-8?q?Heidekr=C3=BCger?= ,
Paul =?utf-8?q?Heidekr=C3=BCger?= ,
Paul =?utf-8?q?Heidekr=C3=BCger?= ,
Paul =?utf-8?q?Heidekr=C3=BCger?= ,
Paul =?utf-8?q?Heidekr=C3=BCger?= ,
Paul =?utf-8?q?Heidekr=C3=BCger?= ,
Paul =?utf-8?q?Heidekr=C3=BCger?= ,
Paul =?utf-8?q?Heidekr=C3=BCger?= 
Message-ID:
In-Reply-To: 


https://github.com/EugeneZelenko commented:

Please rebase from `main`.

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


[clang-tools-extra] Enforce SL.con.3: Add check to replace operator[] with at() [Cont.] (PR #95220)

2024-11-04 Thread via cfe-commits
=��___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] Enforce SL.con.3: Add check to replace operator[] with at() [Cont.] (PR #95220)

2024-11-04 Thread via cfe-commits
=��___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-query] add basic profiling on matching each ASTs (PR #114806)

2024-11-04 Thread Ding Fei via cfe-commits

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


[clang-tools-extra] [clangd] Fix use-after-free issues in TidyProvider.cpp (PR #114808)

2024-11-04 Thread Haojian Wu via cfe-commits

https://github.com/hokein created 
https://github.com/llvm/llvm-project/pull/114808

None

>From 38c41b134b7092d880ba349bcca1a7bb6887d1dc Mon Sep 17 00:00:00 2001
From: Haojian Wu 
Date: Mon, 4 Nov 2024 16:03:27 +0100
Subject: [PATCH] [clangd] Fix use-after-free issues in TidyProvider.cpp

---
 clang-tools-extra/clangd/TidyProvider.cpp | 19 ---
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/clang-tools-extra/clangd/TidyProvider.cpp 
b/clang-tools-extra/clangd/TidyProvider.cpp
index a87238e0c0938c..f35cf9f0ab999d 100644
--- a/clang-tools-extra/clangd/TidyProvider.cpp
+++ b/clang-tools-extra/clangd/TidyProvider.cpp
@@ -46,7 +46,7 @@ class DotClangTidyCache : private FileCache {
 [this](std::optional Data) {
   Value.reset();
   if (Data && !Data->empty()) {
-tidy::DiagCallback Diagnostics = [](const llvm::SMDiagnostic &D) {
+auto Diagnostics = [](const llvm::SMDiagnostic &D) {
   switch (D.getKind()) {
   case llvm::SourceMgr::DK_Error:
 elog("tidy-config error at {0}:{1}:{2}: {3}", D.getFilename(),
@@ -159,12 +159,15 @@ TidyProviderRef provideEnvironment() {
 return Ret;
   }();
 
-  if (User)
-return
-[](tidy::ClangTidyOptions &Opts, llvm::StringRef) { Opts.User = User; 
};
+  if (User) {
+static const auto Provider = [](tidy::ClangTidyOptions &Opts, 
llvm::StringRef) { Opts.User = User; };
+return Provider;
+  }
   // FIXME: Once function_ref and unique_function operator= operators handle
   // null values, this can return null.
-  return [](tidy::ClangTidyOptions &, llvm::StringRef) {};
+  static const auto EmptyProvider = [](tidy::ClangTidyOptions &,
+   llvm::StringRef) {};
+  return EmptyProvider;
 }
 
 TidyProviderRef provideDefaultChecks() {
@@ -178,10 +181,11 @@ TidyProviderRef provideDefaultChecks() {
   "bugprone-suspicious-missing-comma", "bugprone-unused-raii",
   "bugprone-unused-return-value", "misc-unused-using-decls",
   "misc-unused-alias-decls", "misc-definitions-in-headers");
-  return [](tidy::ClangTidyOptions &Opts, llvm::StringRef) {
+  static auto Provider =  [](tidy::ClangTidyOptions &Opts, llvm::StringRef) {
 if (!Opts.Checks || Opts.Checks->empty())
   Opts.Checks = DefaultChecks;
   };
+  return Provider;
 }
 
 TidyProvider addTidyChecks(llvm::StringRef Checks,
@@ -252,7 +256,7 @@ TidyProvider 
disableUnusableChecks(llvm::ArrayRef ExtraBadChecks) {
 }
 
 TidyProviderRef provideClangdConfig() {
-  return [](tidy::ClangTidyOptions &Opts, llvm::StringRef) {
+  static const auto Provider = [](tidy::ClangTidyOptions &Opts, 
llvm::StringRef) {
 const auto &CurTidyConfig = Config::current().Diagnostics.ClangTidy;
 if (!CurTidyConfig.Checks.empty())
   mergeCheckList(Opts.Checks, CurTidyConfig.Checks);
@@ -262,6 +266,7 @@ TidyProviderRef provideClangdConfig() {
  
tidy::ClangTidyOptions::ClangTidyValue(
  CheckOption.getValue(), 1U));
   };
+  return Provider;
 }
 
 TidyProvider provideClangTidyFiles(ThreadsafeFS &TFS) {

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


[clang-tools-extra] Enforce SL.con.3: Add check to replace operator[] with at() [Cont.] (PR #95220)

2024-11-04 Thread via cfe-commits
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= ,
Paul =?utf-8?q?Heidekrüger?= 
Message-ID:
In-Reply-To: 



@@ -101,6 +101,13 @@ Improvements to clang-tidy
 New checks
 ^^
 
+- New :doc:`cppcoreguidelines-pro-bounds-avoid-unchecked-container-accesses
+  
`
+  check.
+
+  Flags calls to operator[] in STL containers and suggests replacing it with

EugeneZelenko wrote:

```suggestion
  Flags calls to ``operator[]`` in STL containers and suggests replacing it with
```

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


[clang] [llvm] [HLSL][SPIRV][DXIL] Implement `dot4add_i8packed` intrinsic (PR #113623)

2024-11-04 Thread Steven Perron via cfe-commits

https://github.com/s-perron approved this pull request.

LGTM. I just want someone on the OpenCL side to make sure they are okay with 
the changes for OpenCL.

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


[clang-tools-extra] [clang-query] add basic profiling on matching each ASTs (PR #114806)

2024-11-04 Thread Ding Fei via cfe-commits

https://github.com/danix800 updated 
https://github.com/llvm/llvm-project/pull/114806

>From dfd42c06d94f859ec78ec1e5c3386c0e4016386f Mon Sep 17 00:00:00 2001
From: dingfei 
Date: Mon, 4 Nov 2024 22:37:51 +0800
Subject: [PATCH 1/2] [clang-query] add basic profiling on matching each ASTs

Sample output:

$ cat test.cql
set enable-profile true
m binaryOperator(isExpansionInMainFile())

$ cat test.c
int test(int i, int j) {
  return i + j;
}

$ clang-query --track-memory -f test.cql test.c --

Match #1:

{{.*}}/test.c:2:10: note: "root" binds here
2 |   return i + j;
  |  ^
1 match.
===-===
 clang-query matcher profiling
===-===
  Total Execution Time: 0. seconds (0. wall clock)

   ---User Time---   --System Time--   --User+System--   ---Wall Time---  
---Mem---  --- Name ---
   0. (100.0%)   0. (100.0%)   0. (100.0%)   0. (100.0%)
224  {{.*}}/test.c
   0. (100.0%)   0. (100.0%)   0. (100.0%)   0. (100.0%)
224  Total
---
 clang-tools-extra/clang-query/CMakeLists.txt  |  1 +
 clang-tools-extra/clang-query/Query.cpp   | 26 --
 clang-tools-extra/clang-query/QueryParser.cpp |  5 +++
 .../clang-query/QueryProfile.cpp  | 24 +
 clang-tools-extra/clang-query/QueryProfile.h  | 35 +++
 clang-tools-extra/clang-query/QuerySession.h  |  3 +-
 6 files changed, 90 insertions(+), 4 deletions(-)
 create mode 100644 clang-tools-extra/clang-query/QueryProfile.cpp
 create mode 100644 clang-tools-extra/clang-query/QueryProfile.h

diff --git a/clang-tools-extra/clang-query/CMakeLists.txt 
b/clang-tools-extra/clang-query/CMakeLists.txt
index b168a3a8581567..84a1ad6fa33582 100644
--- a/clang-tools-extra/clang-query/CMakeLists.txt
+++ b/clang-tools-extra/clang-query/CMakeLists.txt
@@ -7,6 +7,7 @@ set(LLVM_LINK_COMPONENTS
 add_clang_library(clangQuery STATIC
   Query.cpp
   QueryParser.cpp
+  QueryProfile.cpp
 
   DEPENDS
   omp_gen
diff --git a/clang-tools-extra/clang-query/Query.cpp 
b/clang-tools-extra/clang-query/Query.cpp
index 282d136aff721a..5b628de3c4deeb 100644
--- a/clang-tools-extra/clang-query/Query.cpp
+++ b/clang-tools-extra/clang-query/Query.cpp
@@ -8,6 +8,7 @@
 
 #include "Query.h"
 #include "QueryParser.h"
+#include "QueryProfile.h"
 #include "QuerySession.h"
 #include "clang/AST/ASTDumper.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
@@ -44,6 +45,8 @@ bool HelpQuery::run(llvm::raw_ostream &OS, QuerySession &QS) 
const {
 "  set bind-root (true|false)"
 "Set whether to bind the root matcher to \"root\".\n"
 "  set print-matcher (true|false)"
+"  set enable-profile (true|false)"
+"Set whether to enable matcher profiling,\n"
 "Set whether to print the current matcher,\n"
 "  set traversal   "
 "Set traversal kind of clang-query session. Available kinds are:\n"
@@ -82,10 +85,13 @@ namespace {
 
 struct CollectBoundNodes : MatchFinder::MatchCallback {
   std::vector &Bindings;
-  CollectBoundNodes(std::vector &Bindings) : Bindings(Bindings) {}
+  StringRef Unit;
+  CollectBoundNodes(std::vector &Bindings, StringRef Unit)
+  : Bindings(Bindings), Unit(Unit) {}
   void run(const MatchFinder::MatchResult &Result) override {
 Bindings.push_back(Result.Nodes);
   }
+  StringRef getID() const override { return Unit; }
 };
 
 } // namespace
@@ -93,8 +99,19 @@ struct CollectBoundNodes : MatchFinder::MatchCallback {
 bool MatchQuery::run(llvm::raw_ostream &OS, QuerySession &QS) const {
   unsigned MatchCount = 0;
 
+  std::optional Profiling;
+  if (QS.EnableProfile)
+Profiling = QueryProfile();
+
   for (auto &AST : QS.ASTs) {
-MatchFinder Finder;
+ast_matchers::MatchFinder::MatchFinderOptions FinderOptions;
+std::optional> Records;
+if (QS.EnableProfile) {
+  Records.emplace();
+  FinderOptions.CheckProfiling.emplace(*Records);
+}
+
+MatchFinder Finder(FinderOptions);
 std::vector Matches;
 DynTypedMatcher MaybeBoundMatcher = Matcher;
 if (QS.BindRoot) {
@@ -102,7 +119,8 @@ bool MatchQuery::run(llvm::raw_ostream &OS, QuerySession 
&QS) const {
   if (M)
 MaybeBoundMatcher = *M;
 }
-CollectBoundNodes Collect(Matches);
+StringRef OrigSrcName = AST->getOriginalSourceFileName();
+CollectBoundNodes Collect(Matches, OrigSrcName);
 if (!Finder.addDynamicMatcher(MaybeBoundMatcher, &Collect)) {
   OS << "Not a valid top-level matcher.\n";
   return false;
@@ -111,6 +129,8 @@ bool MatchQuery::run(llvm::raw_ostream &OS, QuerySession 
&QS) const {
 ASTContext &Ctx = AST->getASTContext();
 Ctx.getParentMapContext().setTraversalKind(QS.TK);
 Finder.matchAST(Ctx);
+if (QS.EnableProfile)
+  Profiling->Records[OrigSrcName] += (*Records)[Orig

[clang] [NFC][Clang][AArch64]Refactor implementation of Neon vectors MFloat8… (PR #114804)

2024-11-04 Thread Jonathan Thackray via cfe-commits

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

LGTM

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


[clang-tools-extra] [clangd] fix extract-to-function for overloaded operators (PR #81640)

2024-11-04 Thread Nathan Ridge via cfe-commits


@@ -104,9 +104,12 @@ bool isRootStmt(const Node *N) {
   // Root statement cannot be partially selected.
   if (N->Selected == SelectionTree::Partial)
 return false;
-  // Only DeclStmt can be an unselected RootStmt since VarDecls claim the 
entire
-  // selection range in selectionTree.
-  if (N->Selected == SelectionTree::Unselected && !N->ASTNode.get())
+  // A DeclStmt can be an unselected RootStmt since VarDecls claim the entire
+  // selection range in selectionTree. Additionally, a CXXOperatorCallExpr of a
+  // binary operation can be unselected because it's children claim the entire
+  // selection range in the selection tree (e.g. <<).
+  if (N->Selected == SelectionTree::Unselected && !N->ASTNode.get() 
&&

HighCommander4 wrote:

Do we need to make a corresponding change 
[here](https://searchfox.org/llvm/rev/30213e99b86a078c9d472264c7edeea9aa638dd4/clang-tools-extra/clangd/refactor/tweaks/ExtractFunction.cpp#141-146)?
 The comment suggests that it's special-casing `DeclStmt` for the same reason 
as this code.

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


[clang-tools-extra] [clangd] fix extract-to-function for overloaded operators (PR #81640)

2024-11-04 Thread Nathan Ridge via cfe-commits


@@ -190,6 +190,14 @@ F (extracted();)
 }]]
   )cpp";
   EXPECT_EQ(apply(CompoundFailInput), "unavailable");
+
+  ExtraArgs.push_back("-std=c++14");
+  // FIXME: Expressions are currently not extracted
+  EXPECT_EQ(apply(R"cpp(
+void sink(int);
+void call() { sink([[1+1]]); }

HighCommander4 wrote:

I was thinking more specifically about entire expression-statements, e.g. 
`[[stream << 42;]]`.

Extraction of arbitrary subexpressions would be nice as well, but likely more 
involved; there is a work in progress [here](https://reviews.llvm.org/D140619).

(We can keep this test case too.)

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


[clang-tools-extra] [clangd] fix extract-to-function for overloaded operators (PR #81640)

2024-11-04 Thread Nathan Ridge via cfe-commits

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


[clang-tools-extra] Extend bugprone-use-after-move check to handle std::optional::reset() and std::any::reset() (PR #114255)

2024-11-04 Thread via cfe-commits

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


[clang-tools-extra] Extend bugprone-use-after-move check to handle std::optional::reset() and std::any::reset() (PR #114255)

2024-11-04 Thread via cfe-commits


@@ -279,7 +281,7 @@ void UseAfterMoveFinder::getDeclRefs(
 if (DeclRef && BlockMap->blockContainingStmt(DeclRef) == Block) {
   // Ignore uses of a standard smart pointer that don't dereference the
   // pointer.
-  if (Operator || !isStandardSmartPointer(DeclRef->getDecl())) {
+  if (Operator || !isStandardResettableOwner(DeclRef->getDecl())) {

higher-performance wrote:

> `has_value` together with `value`

Ahh I see. I was thinking of them separately, but I guess I can see that if 
`has_value` returns true then the next action will be `value` which probably 
shouldn't be relied on, so you could say `has_value` shouldn't be relied on 
either.

> I would've said that this PR should be blocked until the above is handled 
> correctly, but actually, the PR as is, is removing some false-positives by 
> considering the calls to `reset` as resetting the state. So there are no real 
> negatives attached to this PR, that weren't there before, it's only improving 
> the state. The changes outlined above make some negatives positives, which 
> could be done in a follow-up (+issue in case you do not end up implementing 
> it) (in one go would be nicer, of course).

Ah okay. Could we move forward with this PR then? I'll make an issue for this, 
but I'm not sure when I'll find the time to work on that, and I don't want to 
block this on that change.

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


[clang-tools-extra] Extend bugprone-use-after-move check to handle std::optional::reset() and std::any::reset() (PR #114255)

2024-11-04 Thread via cfe-commits


@@ -279,7 +281,7 @@ void UseAfterMoveFinder::getDeclRefs(
 if (DeclRef && BlockMap->blockContainingStmt(DeclRef) == Block) {
   // Ignore uses of a standard smart pointer that don't dereference the
   // pointer.
-  if (Operator || !isStandardSmartPointer(DeclRef->getDecl())) {
+  if (Operator || !isStandardResettableOwner(DeclRef->getDecl())) {

higher-performance wrote:

But just to double check -- are you sure this doesn't actually negatively 
impact `std::optional`? I'm having a hard time verifying this by just reading 
the code.

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


[clang] Add -mno-unaligned-access and -mbig-endian to ARM and AArch64 multilib flags (PR #114782)

2024-11-04 Thread via cfe-commits

https://github.com/simpal01 updated 
https://github.com/llvm/llvm-project/pull/114782

>From 4a06df9bec87882964e0892b50dd9a81d5e1e6ac Mon Sep 17 00:00:00 2001
From: Simi Pallipurath 
Date: Mon, 4 Nov 2024 12:02:29 +
Subject: [PATCH 1/2] Add -mno-unaligned-access and -mbig-endian to ARM and
 AArch64 multilib flags.

---
 clang/lib/Driver/ToolChain.cpp| 25 +++
 .../test/Driver/print-multi-selection-flags.c |  8 ++
 2 files changed, 33 insertions(+)

diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index bdf3da0c96adca..dec9af62ad79e4 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -230,6 +230,18 @@ static void getAArch64MultilibFlags(const Driver &D,
 Result.push_back(BranchProtectionArg->getAsString(Args));
   }
 
+  const Arg *StrictAlignArg =
+  Args.getLastArgNoClaim(options::OPT_mstrict_align, 
options::OPT_mno_unaligned_access);
+  if (StrictAlignArg) {
+Result.push_back(StrictAlignArg->getAsString(Args));
+  }
+
+  const Arg *BigEndian =
+  Args.getLastArgNoClaim(options::OPT_mbig_endian);
+  if (BigEndian) {
+Result.push_back(BigEndian->getAsString(Args));
+  }
+
   const Arg *ABIArg = Args.getLastArgNoClaim(options::OPT_mabi_EQ);
   if (ABIArg) {
 Result.push_back(ABIArg->getAsString(Args));
@@ -287,6 +299,19 @@ static void getARMMultilibFlags(const Driver &D,
   if (BranchProtectionArg) {
 Result.push_back(BranchProtectionArg->getAsString(Args));
   }
+
+  const Arg *StrictAlignArg =
+  Args.getLastArgNoClaim(options::OPT_mstrict_align, options::
+OPT_mno_unaligned_access);
+  if (StrictAlignArg) {
+Result.push_back(StrictAlignArg->getAsString(Args));
+  }
+
+  const Arg *BigEndian =
+  Args.getLastArgNoClaim(options::OPT_mbig_endian);
+  if (BigEndian) {
+Result.push_back(BigEndian->getAsString(Args));
+  }
 }
 
 static void getRISCVMultilibFlags(const Driver &D, const llvm::Triple &Triple,
diff --git a/clang/test/Driver/print-multi-selection-flags.c 
b/clang/test/Driver/print-multi-selection-flags.c
index 4bb62665ad8981..5bf6dca5096a73 100644
--- a/clang/test/Driver/print-multi-selection-flags.c
+++ b/clang/test/Driver/print-multi-selection-flags.c
@@ -68,6 +68,14 @@
 // RUN: %clang -multi-lib-config=%S/Inputs/multilib/empty.yaml 
-print-multi-flags-experimental --target=aarch64-none-elf 
-mbranch-protection=standard | FileCheck --check-prefix=CHECK-BRANCH-PROTECTION 
%s
 // CHECK-BRANCH-PROTECTION: -mbranch-protection=standard
 
+// RUN: %clang -multi-lib-config=%S/Inputs/multilib/empty.yaml 
-print-multi-flags-experimental --target=arm-none-eabi -mno-unaligned-access | 
FileCheck --check-prefix=CHECK-NO-UNALIGNED-ACCESS %s
+// RUN: %clang -multi-lib-config=%S/Inputs/multilib/empty.yaml 
-print-multi-flags-experimental --target=aarch64-none-elf -mno-unaligned-access 
| FileCheck --check-prefix=CHECK-NO-UNALIGNED-ACCESS %s
+// CHECK-NO-UNALIGNED-ACCESS: -mno-unaligned-access
+
+// RUN: %clang -multi-lib-config=%S/Inputs/multilib/empty.yaml 
-print-multi-flags-experimental --target=arm-none-eabi -mbig-endian | FileCheck 
--check-prefix=CHECK-BIG-ENDIAN %s
+// RUN: %clang -multi-lib-config=%S/Inputs/multilib/empty.yaml 
-print-multi-flags-experimental --target=aarch64-none-elf -mbig-endian | 
FileCheck --check-prefix=CHECK-BIG-ENDIAN %s
+// CHECK-BIG-ENDIAN: -mbig-endian
+
 // RUN: %clang -multi-lib-config=%S/Inputs/multilib/empty.yaml 
-print-multi-flags-experimental --target=riscv32-none-elf -march=rv32g | 
FileCheck --check-prefix=CHECK-RV32 %s
 // CHECK-RV32: --target=riscv32-unknown-none-elf
 // CHECK-RV32: -mabi=ilp32d

>From 5a315d558bda884f1203b8bc5a0dd45c558f45e6 Mon Sep 17 00:00:00 2001
From: Simi Pallipurath 
Date: Mon, 4 Nov 2024 15:20:28 +
Subject: [PATCH 2/2] fixup! Fix the clang code format issue

---
 clang/lib/Driver/ToolChain.cpp | 15 ++-
 1 file changed, 6 insertions(+), 9 deletions(-)

diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index dec9af62ad79e4..652aa9686054c8 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -230,14 +230,13 @@ static void getAArch64MultilibFlags(const Driver &D,
 Result.push_back(BranchProtectionArg->getAsString(Args));
   }
 
-  const Arg *StrictAlignArg =
-  Args.getLastArgNoClaim(options::OPT_mstrict_align, 
options::OPT_mno_unaligned_access);
+  const Arg *StrictAlignArg = Args.getLastArgNoClaim(
+  options::OPT_mstrict_align, options::OPT_mno_unaligned_access);
   if (StrictAlignArg) {
 Result.push_back(StrictAlignArg->getAsString(Args));
   }
 
-  const Arg *BigEndian =
-  Args.getLastArgNoClaim(options::OPT_mbig_endian);
+  const Arg *BigEndian = Args.getLastArgNoClaim(options::OPT_mbig_endian);
   if (BigEndian) {
 Result.push_back(BigEndian->getAsString(Args));
   }
@@ -300,15 +299,13 @@ static void getARMMultilibFlags(const Driver &D,
 Result.push_back(BranchProtectionArg->getAsString(Args))

[clang] Add -mno-unaligned-access and -mbig-endian to ARM and AArch64 multilib flags (PR #114782)

2024-11-04 Thread Lucas Duarte Prates via cfe-commits


@@ -230,6 +230,17 @@ static void getAArch64MultilibFlags(const Driver &D,
 Result.push_back(BranchProtectionArg->getAsString(Args));
   }
 
+  const Arg *StrictAlignArg = Args.getLastArgNoClaim(
+  options::OPT_mstrict_align, options::OPT_mno_unaligned_access);
+  if (StrictAlignArg) {
+Result.push_back(StrictAlignArg->getAsString(Args));
+  }
+
+  const Arg *BigEndian = Args.getLastArgNoClaim(options::OPT_mbig_endian);

pratlucas wrote:

I believe the same logic applies for `-mbig-endian` vs `-mlittle-endian`, where 
the last option provided takes effect over others. 

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


[clang] Add -mno-unaligned-access and -mbig-endian to ARM and AArch64 multilib flags (PR #114782)

2024-11-04 Thread Lucas Duarte Prates via cfe-commits


@@ -287,6 +298,17 @@ static void getARMMultilibFlags(const Driver &D,
   if (BranchProtectionArg) {
 Result.push_back(BranchProtectionArg->getAsString(Args));
   }
+
+  const Arg *StrictAlignArg = Args.getLastArgNoClaim(
+  options::OPT_mstrict_align, options::OPT_mno_unaligned_access);

pratlucas wrote:

Ditto.

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


[clang] Add -mno-unaligned-access and -mbig-endian to ARM and AArch64 multilib flags (PR #114782)

2024-11-04 Thread Lucas Duarte Prates via cfe-commits


@@ -287,6 +298,17 @@ static void getARMMultilibFlags(const Driver &D,
   if (BranchProtectionArg) {
 Result.push_back(BranchProtectionArg->getAsString(Args));
   }
+
+  const Arg *StrictAlignArg = Args.getLastArgNoClaim(
+  options::OPT_mstrict_align, options::OPT_mno_unaligned_access);
+  if (StrictAlignArg) {
+Result.push_back(StrictAlignArg->getAsString(Args));
+  }
+
+  const Arg *BigEndian = Args.getLastArgNoClaim(options::OPT_mbig_endian);

pratlucas wrote:

Ditto.

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


[clang] Add -mno-unaligned-access and -mbig-endian to ARM and AArch64 multilib flags (PR #114782)

2024-11-04 Thread Lucas Duarte Prates via cfe-commits


@@ -230,6 +230,17 @@ static void getAArch64MultilibFlags(const Driver &D,
 Result.push_back(BranchProtectionArg->getAsString(Args));
   }
 
+  const Arg *StrictAlignArg = Args.getLastArgNoClaim(
+  options::OPT_mstrict_align, options::OPT_mno_unaligned_access);
+  if (StrictAlignArg) {

pratlucas wrote:

I think the presence of `-munaligned-access` or `-mno-strict-align` also needs 
to be considered here.

Looking at `clang/lib/Driver/Toolchains/Arch/AArch64.cpp`, it looks like the 
last of these options is the one which takes effect:
```
  if (Arg *A = Args.getLastArg(
  options::OPT_mstrict_align, options::OPT_mno_strict_align,
  options::OPT_mno_unaligned_access, options::OPT_munaligned_access)) {
if (A->getOption().matches(options::OPT_mstrict_align) ||
A->getOption().matches(options::OPT_mno_unaligned_access))
  Features.push_back("+strict-align");
```
I'd recommend using the same logic here.

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


[clang-tools-extra] [clangd] Fix use-after-free issues in TidyProvider.cpp (PR #114808)

2024-11-04 Thread kadir çetinkaya via cfe-commits

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

can we instead change the function return types to be `TidyProvider` ? unless 
there's something we get by making these static lambdas (which isn't obvious to 
me).

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


[clang] [Clang] eliminate shadowing warnings for parameters using deducing this (PR #114813)

2024-11-04 Thread Oleksandr T. via cfe-commits

https://github.com/a-tarasyuk created 
https://github.com/llvm/llvm-project/pull/114813

Fixes #95707

>From 91ff2b4226110ea35c78f0f1b6ff89b4bec2c788 Mon Sep 17 00:00:00 2001
From: Oleksandr T 
Date: Mon, 4 Nov 2024 17:38:46 +0200
Subject: [PATCH] [Clang] eliminate shadowing warnings for parameters using
 deducing this

---
 clang/docs/ReleaseNotes.rst  |  2 ++
 clang/lib/Sema/SemaDecl.cpp  |  7 +--
 clang/test/SemaCXX/cxx2b-warn-shadow.cpp | 10 ++
 3 files changed, 17 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/SemaCXX/cxx2b-warn-shadow.cpp

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 1372e49dfac03c..af8288ee8a8296 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -464,6 +464,8 @@ Improvements to Clang's diagnostics
 
 - Clang now diagnoses ``[[deprecated]]`` attribute usage on local variables 
(#GH90073).
 
+- Clang now omits shadowing warnings for parameter names using deducing this 
(#GH95707).
+
 Improvements to Clang's time-trace
 --
 
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 1aa3e8edfe1b13..38b07b15eb3eb2 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -8236,11 +8236,14 @@ void Sema::CheckShadow(NamedDecl *D, NamedDecl 
*ShadowedDecl,
   DeclContext *NewDC = D->getDeclContext();
 
   if (FieldDecl *FD = dyn_cast(ShadowedDecl)) {
-// Fields are not shadowed by variables in C++ static methods.
-if (CXXMethodDecl *MD = dyn_cast(NewDC))
+if (CXXMethodDecl *MD = dyn_cast(NewDC)) {
+  // Fields are not shadowed by variables in C++ static methods.
   if (MD->isStatic())
 return;
 
+  if (!MD->getParent()->isLambda() && MD->isExplicitObjectMemberFunction())
+return;
+}
 // Fields shadowed by constructor parameters are a special case. Usually
 // the constructor initializes the field with the parameter.
 if (isa(NewDC))
diff --git a/clang/test/SemaCXX/cxx2b-warn-shadow.cpp 
b/clang/test/SemaCXX/cxx2b-warn-shadow.cpp
new file mode 100644
index 00..0cf47f3848979c
--- /dev/null
+++ b/clang/test/SemaCXX/cxx2b-warn-shadow.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -verify -fsyntax-only -std=c++2b -Wshadow-all %s
+
+namespace GH95707 {
+struct Foo {
+  int a; // expected-note {{previous declaration is here}}
+
+  void f1(this auto &self, int a) { self.a = a; }
+  void f2(int a) { } // expected-warning {{declaration shadows a field of 
'GH95707::Foo'}}
+};
+} // namespace GH95707

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


[clang] [lld] [llvm] [mlir] [llvm-project] Fix typo "propogate" (PR #114795)

2024-11-04 Thread Jay Foad via cfe-commits

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


[clang] [Clang] eliminate shadowing warnings for parameters using deducing this (PR #114813)

2024-11-04 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Oleksandr T. (a-tarasyuk)


Changes

Fixes #95707

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


3 Files Affected:

- (modified) clang/docs/ReleaseNotes.rst (+2) 
- (modified) clang/lib/Sema/SemaDecl.cpp (+5-2) 
- (added) clang/test/SemaCXX/cxx2b-warn-shadow.cpp (+10) 


``diff
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 1372e49dfac03c..af8288ee8a8296 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -464,6 +464,8 @@ Improvements to Clang's diagnostics
 
 - Clang now diagnoses ``[[deprecated]]`` attribute usage on local variables 
(#GH90073).
 
+- Clang now omits shadowing warnings for parameter names using deducing this 
(#GH95707).
+
 Improvements to Clang's time-trace
 --
 
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 1aa3e8edfe1b13..38b07b15eb3eb2 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -8236,11 +8236,14 @@ void Sema::CheckShadow(NamedDecl *D, NamedDecl 
*ShadowedDecl,
   DeclContext *NewDC = D->getDeclContext();
 
   if (FieldDecl *FD = dyn_cast(ShadowedDecl)) {
-// Fields are not shadowed by variables in C++ static methods.
-if (CXXMethodDecl *MD = dyn_cast(NewDC))
+if (CXXMethodDecl *MD = dyn_cast(NewDC)) {
+  // Fields are not shadowed by variables in C++ static methods.
   if (MD->isStatic())
 return;
 
+  if (!MD->getParent()->isLambda() && MD->isExplicitObjectMemberFunction())
+return;
+}
 // Fields shadowed by constructor parameters are a special case. Usually
 // the constructor initializes the field with the parameter.
 if (isa(NewDC))
diff --git a/clang/test/SemaCXX/cxx2b-warn-shadow.cpp 
b/clang/test/SemaCXX/cxx2b-warn-shadow.cpp
new file mode 100644
index 00..0cf47f3848979c
--- /dev/null
+++ b/clang/test/SemaCXX/cxx2b-warn-shadow.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang_cc1 -verify -fsyntax-only -std=c++2b -Wshadow-all %s
+
+namespace GH95707 {
+struct Foo {
+  int a; // expected-note {{previous declaration is here}}
+
+  void f1(this auto &self, int a) { self.a = a; }
+  void f2(int a) { } // expected-warning {{declaration shadows a field of 
'GH95707::Foo'}}
+};
+} // namespace GH95707

``




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


[clang] [Multilib] Custom flags YAML parsing (PR #110657)

2024-11-04 Thread Victor Campos via cfe-commits


@@ -101,6 +101,25 @@ class Multilib {
 
 raw_ostream &operator<<(raw_ostream &OS, const Multilib &M);
 
+namespace custom_flag {
+struct CustomFlagDeclaration;

vhscampos wrote:

Fixed

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


[clang] [Multilib] Custom flags YAML parsing (PR #110657)

2024-11-04 Thread Victor Campos via cfe-commits


@@ -101,6 +101,25 @@ class Multilib {
 
 raw_ostream &operator<<(raw_ostream &OS, const Multilib &M);
 
+namespace custom_flag {
+struct CustomFlagDeclaration;
+using CustomFlagDeclarationPtr = std::shared_ptr;
+
+struct CustomFlagValueDetail {
+  std::string Name;
+  std::optional> ExtraBuildArgs;
+  CustomFlagDeclarationPtr Decl;
+};
+
+struct CustomFlagDeclaration {
+  std::string Name;
+  SmallVector ValueList;
+  size_t DefaultValueIdx = ~0UL;

vhscampos wrote:

Fixed

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


[clang] [SYCL] The sycl_kernel_entry_point attribute. (PR #111389)

2024-11-04 Thread Tom Honermann via cfe-commits

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

>From 3c4a2b8a52d3f1c730df88a308dece21a67834ef Mon Sep 17 00:00:00 2001
From: Tom Honermann 
Date: Fri, 4 Oct 2024 11:10:32 -0700
Subject: [PATCH 1/9] [SYCL] The sycl_kernel_entry_point attribute.

The `sycl_kernel_entry_point` attribute is used to declare a function that
defines a pattern for an offload kernel to be emitted. The attribute requires
a single type argument that specifies the type used as a SYCL kernel name as
described in section 5.2, "Naming of kernels", of the SYCL 2020 specification.

Properties of the offload kernel are collected when a function declared with
the `sycl_kernel_entry_point` attribute is parsed or instantiated. These
properties, such as the kernel name type, are stored in the AST context where
they are (or will be) used for diagnostic purposes and to facilitate reflection
to a SYCL run-time library. These properties are not serialized with the AST
but are recreated upon deserialization.

The `sycl_kernel_entry_point` attribute is intended to replace the existing
`sycl_kernel` attribute which is intended to be deprecated in a future change
and removed following an appropriate deprecation period. The new attribute
differs in that it is enabled for both SYCL host and device compilation, may
be used with non-template functions, explicitly indicates the type used as
the kernel name type, and will impact AST generation.

This change adds the basic infrastructure for the new attribute. Future
changes will add diagnostics and new AST support that will be used to drive
generation of the corresponding offload kernel.
---
 clang/include/clang/AST/ASTContext.h  |  12 ++
 clang/include/clang/AST/SYCLKernelInfo.h  |  47 ++
 clang/include/clang/Basic/Attr.td |  16 +-
 clang/include/clang/Basic/AttrDocs.td |  58 +++
 clang/include/clang/Sema/SemaSYCL.h   |   1 +
 clang/lib/AST/ASTContext.cpp  |  25 +++
 clang/lib/Sema/SemaDecl.cpp   |   4 +
 clang/lib/Sema/SemaDeclAttr.cpp   |   3 +
 clang/lib/Sema/SemaSYCL.cpp   |   9 ++
 clang/lib/Serialization/ASTReaderDecl.cpp |   9 ++
 .../ast-dump-sycl-kernel-entry-point.cpp  | 144 ++
 ...a-attribute-supported-attributes-list.test |   1 +
 .../sycl-kernel-entry-point-attr-grammar.cpp  | 137 +
 .../sycl-kernel-entry-point-attr-ignored.cpp  |  17 +++
 14 files changed, 480 insertions(+), 3 deletions(-)
 create mode 100644 clang/include/clang/AST/SYCLKernelInfo.h
 create mode 100644 clang/test/ASTSYCL/ast-dump-sycl-kernel-entry-point.cpp
 create mode 100644 clang/test/SemaSYCL/sycl-kernel-entry-point-attr-grammar.cpp
 create mode 100644 clang/test/SemaSYCL/sycl-kernel-entry-point-attr-ignored.cpp

diff --git a/clang/include/clang/AST/ASTContext.h 
b/clang/include/clang/AST/ASTContext.h
index b65a1f7dff5bc1..e68f0a4da57b16 100644
--- a/clang/include/clang/AST/ASTContext.h
+++ b/clang/include/clang/AST/ASTContext.h
@@ -23,6 +23,7 @@
 #include "clang/AST/ExternalASTSource.h"
 #include "clang/AST/PrettyPrinter.h"
 #include "clang/AST/RawCommentList.h"
+#include "clang/AST/SYCLKernelInfo.h"
 #include "clang/AST/TemplateName.h"
 #include "clang/Basic/LLVM.h"
 #include "clang/Basic/PartialDiagnostic.h"
@@ -1222,6 +1223,11 @@ class ASTContext : public RefCountedBase {
   /// in device compilation.
   llvm::DenseSet CUDAImplicitHostDeviceFunUsedByDevice;
 
+  /// Map of SYCL kernels indexed by the unique type used to name the kernel.
+  /// Entries are not serialized but are recreated on deserialization of a
+  /// sycl_kernel_entry_point attributed function declaration.
+  llvm::DenseMap SYCLKernels;
+
   /// For capturing lambdas with an explicit object parameter whose type is
   /// derived from the lambda type, we need to perform derived-to-base
   /// conversion so we can access the captures; the cast paths for that
@@ -3301,6 +3307,12 @@ class ASTContext : public RefCountedBase {
   void getFunctionFeatureMap(llvm::StringMap &FeatureMap,
  GlobalDecl GD) const;
 
+  /// Generates and stores SYCL kernel metadata for the provided
+  /// SYCL kernel entry point function. The provided function must have
+  /// an attached sycl_kernel_entry_point attribute that specifies a unique
+  /// type for the name of a SYCL kernel.
+  void registerSYCLEntryPointFunction(FunctionDecl *FD);
+
   
//======//
   //Statistics
   
//======//
diff --git a/clang/include/clang/AST/SYCLKernelInfo.h 
b/clang/include/clang/AST/SYCLKernelInfo.h
new file mode 100644
index 00..79a83330f1d23b
--- /dev/null
+++ b/clang/include/clang/AST/SYCLKernelInfo.h
@@ -0,0 +1,47 @@
+//===--- SYCLKernelInfo.h --- Information about SYCL kernels 
--===//
+//
+// P

[clang] [SYCL] The sycl_kernel_entry_point attribute. (PR #111389)

2024-11-04 Thread Tom Honermann via cfe-commits


@@ -14296,6 +14296,34 @@ void 
ASTContext::getFunctionFeatureMap(llvm::StringMap &FeatureMap,
   }
 }
 
+static SYCLKernelInfo BuildSYCLKernelInfo(CanQualType KernelNameType,
+  const FunctionDecl *FD) {
+  return {KernelNameType, FD};
+}
+
+void ASTContext::registerSYCLEntryPointFunction(FunctionDecl *FD) {
+  // If the function declaration to register is invalid or dependent, the
+  // registration attempt is ignored.
+  if (FD->isInvalidDecl() || FD->isTemplated())
+return;
+
+  const auto *SKEPAttr = FD->getAttr();
+  assert(SKEPAttr && "Missing sycl_kernel_entry_point attribute");
+
+  // Be tolerant of multiple registration attempts so long as each attempt
+  // is for the same entity. Callers are obligated to detect and diagnose
+  // conflicting kernel names prior to calling this function.
+  CanQualType KernelNameType = getCanonicalType(SKEPAttr->getKernelName());
+  auto IT = SYCLKernels.find(KernelNameType);
+  if (IT != SYCLKernels.end()) {
+assert(declaresSameEntity(FD, IT->second.getKernelEntryPointDecl()) &&

tahonermann wrote:

Good suggestion. Done.

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


[clang-tools-extra] Extend bugprone-use-after-move check to handle std::optional::reset() and std::any::reset() (PR #114255)

2024-11-04 Thread via cfe-commits

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


[clang] [HLSL][SPIRV] Add HLSL type translation for spirv. (PR #114273)

2024-11-04 Thread Steven Perron via cfe-commits

https://github.com/s-perron updated 
https://github.com/llvm/llvm-project/pull/114273

>From 215a3427acd5f5ab5fc5fb889a235c3ac7abcdfb Mon Sep 17 00:00:00 2001
From: Steven Perron 
Date: Tue, 1 Oct 2024 09:56:20 -0400
Subject: [PATCH 1/5] [HLSL][SPIRV] Add HLSL type translation for spirv.

This commit partially implements SPIRTargetCodeGenInfo::getHLSLType. It
can now generate the spirv type for the following HLSL types:

1. RWBuffer
2. Buffer
3. Sampler

# Conflicts:
#   clang/test/CodeGenHLSL/builtins/RWBuffer-elementtype.hlsl
---
 clang/lib/CodeGen/Targets/SPIR.cpp| 81 +++
 .../builtins/RWBuffer-elementtype.hlsl| 45 +++
 2 files changed, 112 insertions(+), 14 deletions(-)

diff --git a/clang/lib/CodeGen/Targets/SPIR.cpp 
b/clang/lib/CodeGen/Targets/SPIR.cpp
index 7dd5c518e7149a..e6921d65084701 100644
--- a/clang/lib/CodeGen/Targets/SPIR.cpp
+++ b/clang/lib/CodeGen/Targets/SPIR.cpp
@@ -52,6 +52,10 @@ class CommonSPIRTargetCodeGenInfo : public TargetCodeGenInfo 
{
 
   unsigned getOpenCLKernelCallingConv() const override;
   llvm::Type *getOpenCLType(CodeGenModule &CGM, const Type *T) const override;
+  llvm::Type *getHLSLType(CodeGenModule &CGM, const Type *Ty) const override;
+  llvm::Type *getSPIRVImageTypeFromHLSLResource(
+  const HLSLAttributedResourceType::Attributes &attributes,
+  llvm::Type *ElementType, llvm::LLVMContext &Ctx) const;
 };
 class SPIRVTargetCodeGenInfo : public CommonSPIRTargetCodeGenInfo {
 public:
@@ -323,6 +327,83 @@ llvm::Type 
*CommonSPIRTargetCodeGenInfo::getOpenCLType(CodeGenModule &CGM,
   return nullptr;
 }
 
+llvm::Type *CommonSPIRTargetCodeGenInfo::getHLSLType(CodeGenModule &CGM,
+ const Type *Ty) const {
+  auto *ResType = dyn_cast(Ty);
+  if (!ResType)
+return nullptr;
+
+  llvm::LLVMContext &Ctx = CGM.getLLVMContext();
+  const HLSLAttributedResourceType::Attributes &ResAttrs = ResType->getAttrs();
+  switch (ResAttrs.ResourceClass) {
+  case llvm::dxil::ResourceClass::UAV:
+  case llvm::dxil::ResourceClass::SRV: {
+// TypedBuffer and RawBuffer both need element type
+QualType ContainedTy = ResType->getContainedType();
+if (ContainedTy.isNull())
+  return nullptr;
+
+assert(!ResAttrs.RawBuffer &&
+   "Raw buffers handles are not implemented for SPIR-V yet");
+assert(!ResAttrs.IsROV &&
+   "Rasterizer order views not implemented for SPIR-V yet");
+
+// convert element type
+llvm::Type *ElemType = CGM.getTypes().ConvertType(ContainedTy);
+return getSPIRVImageTypeFromHLSLResource(ResAttrs, ElemType, Ctx);
+  }
+  case llvm::dxil::ResourceClass::CBuffer:
+llvm_unreachable("CBuffer handles are not implemented for SPIR-V yet");
+break;
+  case llvm::dxil::ResourceClass::Sampler:
+return llvm::TargetExtType::get(Ctx, "spirv.Sampler");
+  }
+  return nullptr;
+}
+
+llvm::Type *CommonSPIRTargetCodeGenInfo::getSPIRVImageTypeFromHLSLResource(
+const HLSLAttributedResourceType::Attributes &attributes,
+llvm::Type *ElementType, llvm::LLVMContext &Ctx) const {
+
+  if (ElementType->isVectorTy()) {
+ElementType = ElementType->getScalarType();
+  }
+
+  if (!ElementType->isIntegerTy() && !ElementType->isFloatingPointTy()) {
+// TODO: Should there be an error message?
+ElementType->dump();
+assert(false && "Bad element type");
+return nullptr;
+  }
+
+  // For HLSL types, the depth is always 2.
+  SmallVector IntParams = {0, 2, 0, 0, 1, 0};
+
+  // Dim
+  // For now we assume everything is a buffer.
+  IntParams[0] = 5;
+
+  // Depth
+  // HLSL does not indicate if it is a depth texture or not, so we use unknown.
+  IntParams[1] = 2;
+
+  // Arrayed
+  IntParams[2] = 0;
+
+  // MS
+  IntParams[3] = 0;
+
+  // Sampled
+  IntParams[4] =
+  attributes.ResourceClass == llvm::dxil::ResourceClass::UAV ? 2 : 1;
+
+  // Image format.
+  // Setting to unknown for now.
+  IntParams[5] = 0;
+
+  return llvm::TargetExtType::get(Ctx, "spirv.Image", {ElementType}, 
IntParams);
+}
+
 std::unique_ptr
 CodeGen::createCommonSPIRTargetCodeGenInfo(CodeGenModule &CGM) {
   return std::make_unique(CGM.getTypes());
diff --git a/clang/test/CodeGenHLSL/builtins/RWBuffer-elementtype.hlsl 
b/clang/test/CodeGenHLSL/builtins/RWBuffer-elementtype.hlsl
index 16120a44a9e4d2..d737d76a9d8d97 100644
--- a/clang/test/CodeGenHLSL/builtins/RWBuffer-elementtype.hlsl
+++ b/clang/test/CodeGenHLSL/builtins/RWBuffer-elementtype.hlsl
@@ -1,22 +1,39 @@
-// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.2-compute 
-finclude-default-header -fnative-half-type -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.2-compute 
-finclude-default-header -fnative-half-type -emit-llvm -o - %s | FileCheck %s 
-check-prefixes=DXIL
+// RUN: %clang_cc1 -triple spirv-pc-vulkan-compute -finclude-default-header 
-fnative-half-type -emit-llvm -o - %s | FileCheck %s -check-prefixes=SPIRV
 
 // NOTE: The type name nu

[clang] [C++20][Modules] Load function body from the module that gives canonical decl (PR #111992)

2024-11-04 Thread Ilya Biryukov via cfe-commits

ilya-biryukov wrote:

> @ilya-biryukov could you please take a look?

Sorry for the late reply, was on vacation. I'll ask @alexfh to run this through 
our release testing and report if there are any bugs left.

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


[clang-tools-extra] [clangd] Check for editsNearCursor client capability under experimental capabilities (PR #114699)

2024-11-04 Thread Haojian Wu via cfe-commits

https://github.com/hokein commented:

(No action required) – we have other extensions in clangd e.g. 
`references.container` `offsetEncoding`. Do we plan to do the same thing for 
them?

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


[clang] f855975 - [llvm-project] Fix typo "propogate" (#114795)

2024-11-04 Thread via cfe-commits

Author: Jay Foad
Date: 2024-11-04T15:33:19Z
New Revision: f8559751fc2b15b45ac417be9abe865085af45ad

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

LOG: [llvm-project] Fix typo "propogate" (#114795)

Added: 


Modified: 
clang/test/Analysis/malloc.c
lld/test/Unit/lit.cfg.py
llvm/docs/HistoricalNotes/2001-05-18-ExceptionHandling.txt
llvm/docs/HistoricalNotes/2002-05-12-InstListChange.txt
llvm/lib/Transforms/IPO/AttributorAttributes.cpp
llvm/lib/Transforms/IPO/IROutliner.cpp
llvm/test/CodeGen/AArch64/i128-fast-isel-fallback.ll
llvm/test/CodeGen/AMDGPU/waitcnt-loop-single-basic-block.mir
llvm/test/DebugInfo/MIR/X86/livedebugvalues_basic_diamond.mir
llvm/test/DebugInfo/MIR/X86/livedebugvalues_basic_diamond_match_clobber.mir
llvm/test/DebugInfo/MIR/X86/livedebugvalues_basic_diamond_match_move.mir
llvm/test/DebugInfo/MIR/X86/livedebugvalues_loop_within_loop_outer_moved.mir
llvm/test/Transforms/IROutliner/included-phi-nodes-end.ll
llvm/test/Transforms/IROutliner/region-inputs-in-phi-nodes.ll
llvm/test/Transforms/InstSimplify/ConstProp/2002-03-11-ConstPropCrash.ll

llvm/test/Transforms/InstSimplify/ConstProp/2002-05-03-DivideByZeroException.ll
llvm/test/Transforms/LoopSimplifyCFG/constant-fold-branch.ll
llvm/test/Unit/lit.cfg.py
llvm/utils/TableGen/jupyter/tablegen_kernel/kernel.py
mlir/lib/Dialect/Tosa/Transforms/TosaInferShapes.cpp
mlir/test/Dialect/Linalg/canonicalize.mlir
mlir/test/Dialect/Tensor/canonicalize.mlir

Removed: 




diff  --git a/clang/test/Analysis/malloc.c b/clang/test/Analysis/malloc.c
index 57f8561a74da66..f2f8975b5f0e21 100644
--- a/clang/test/Analysis/malloc.c
+++ b/clang/test/Analysis/malloc.c
@@ -1829,7 +1829,7 @@ void testConstEscapeThroughAnotherField(void) {
 } // no-warning
 
 // PR15623
-int testNoCheckerDataPropogationFromLogicalOpOperandToOpResult(void) {
+int testNoCheckerDataPropagationFromLogicalOpOperandToOpResult(void) {
char *param = malloc(10);
char *value = malloc(10);
int ok = (param && value);

diff  --git a/lld/test/Unit/lit.cfg.py b/lld/test/Unit/lit.cfg.py
index ffbbddeeed5ec9..1cf890a05cb28c 100644
--- a/lld/test/Unit/lit.cfg.py
+++ b/lld/test/Unit/lit.cfg.py
@@ -38,7 +38,7 @@
 config.environment["PATH"] = os.path.pathsep.join((
 config.shlibdir, config.environment["PATH"]))
 
-# Win32 may use %SYSTEMDRIVE% during file system shell operations, so 
propogate.
+# Win32 may use %SYSTEMDRIVE% during file system shell operations, so 
propagate.
 if sys.platform == "win32" and "SYSTEMDRIVE" in os.environ:
 config.environment["SYSTEMDRIVE"] = os.environ["SYSTEMDRIVE"]
 

diff  --git a/llvm/docs/HistoricalNotes/2001-05-18-ExceptionHandling.txt 
b/llvm/docs/HistoricalNotes/2001-05-18-ExceptionHandling.txt
index b546301d35a404..04b40acd0f8305 100644
--- a/llvm/docs/HistoricalNotes/2001-05-18-ExceptionHandling.txt
+++ b/llvm/docs/HistoricalNotes/2001-05-18-ExceptionHandling.txt
@@ -70,7 +70,7 @@ void TestFunction(...) {
 // execution continues after the try block: the exception is consumed
   } catch (double) {
 ...double stuff...
-   throw;// Exception is propogated
+   throw;// Exception is propagated
   }
 }
 
@@ -83,14 +83,14 @@ Func:
   %b = alloca B   // minor detail for this example
   B::B(%b)
 
-  call foo() with fooCleanup // An exception in foo is propogated to fooCleanup
-  call bar() with barCleanup // An exception in bar is propogated to barCleanup
+  call foo() with fooCleanup // An exception in foo is propagated to fooCleanup
+  call bar() with barCleanup // An exception in bar is propagated to barCleanup
 
   %c = alloca C
   C::C(c)
   %d = alloca D
   D::D(d)
-  call baz() with bazCleanup // An exception in baz is propogated to bazCleanup
+  call baz() with bazCleanup // An exception in baz is propagated to bazCleanup
   d->~D();
 EndTry:   // This label corresponds to the end of the try block
   c->~C()   // These could also throw, these are also ignored

diff  --git a/llvm/docs/HistoricalNotes/2002-05-12-InstListChange.txt 
b/llvm/docs/HistoricalNotes/2002-05-12-InstListChange.txt
index 638682b49fda0b..79629077619644 100644
--- a/llvm/docs/HistoricalNotes/2002-05-12-InstListChange.txt
+++ b/llvm/docs/HistoricalNotes/2002-05-12-InstListChange.txt
@@ -18,7 +18,7 @@ linear search of the basic block the instruction is contained 
in... just
 to insert an instruction before another instruction, or to delete an 
 instruction!  This complicates algorithms that should be very simple (like 
 simple constant propagation), because they aren't actually sparse anymore,
-they have to traverse basic blocks to remove constant propogated 
+they have to traverse basic blocks to remov

[clang] [clang-tools-extra] [llvm] [clang] Introduce diagnostics suppression mappings (PR #112517)

2024-11-04 Thread kadir çetinkaya via cfe-commits


@@ -599,6 +600,19 @@ DiagnosticIDs::getDiagnosticSeverity(unsigned DiagID, 
SourceLocation Loc,
   SM.isInSystemMacro(Loc))
 return diag::Severity::Ignored;
 
+  // Apply suppression mappings if severity wasn't explicitly mapped with a
+  // clang-diagnostics pragma to ensure pragmas always take precedence over

kadircet wrote:

pragma takes precedence and we don't suppress via the mappings. do you think 
the comment needs rewording?

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


[clang] [clang-tools-extra] [llvm] [clang] Introduce diagnostics suppression mappings (PR #112517)

2024-11-04 Thread kadir çetinkaya via cfe-commits


@@ -122,7 +122,6 @@ class SpecialCaseList {
 // Returns zero if no match is found.
 unsigned match(StringRef Query) const;
 
-  private:
 StringMap> Globs;

kadircet wrote:

thanks, and I'd like to address these in a follow-up refactoring, sent out 
https://discourse.llvm.org/t/refactoring-llvm-specialcaselist/82931 to see what 
people think about this.

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


[clang] [clang-tools-extra] [llvm] [clang] Introduce diagnostics suppression mappings (PR #112517)

2024-11-04 Thread kadir çetinkaya via cfe-commits


@@ -70,6 +76,16 @@ void clang::ProcessWarningOptions(DiagnosticsEngine &Diags,
   else
 Diags.setExtensionHandlingBehavior(diag::Severity::Ignored);
 
+  if (!Opts.DiagnosticSuppressionMappingsFile.empty()) {
+if (auto Buf =

kadircet wrote:

sure, i think it's a little bit unfortunate to spend so much effort in a 
variable that's scoped to 2 lines.

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


[clang] [clang-tools-extra] [llvm] [clang] Introduce diagnostics suppression mappings (PR #112517)

2024-11-04 Thread kadir çetinkaya via cfe-commits


@@ -167,4 +176,159 @@ TEST(DiagnosticTest, storedDiagEmptyWarning) {
   // Make sure an empty warning can round-trip with \c StoredDiagnostic.
   Diags.Report(CaptureConsumer.StoredDiags.front());
 }
+
+class SuppressionMappingTest : public testing::Test {

kadircet wrote:

yes, see 
https://github.com/llvm/llvm-project/pull/112517/files#diff-a8d03c054381627f238bdb8f7914daa4abebdae705d313dda026ce36eca0fe2fR327-R332

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


[clang] [clang-tools-extra] [llvm] [clang] Introduce diagnostics suppression mappings (PR #112517)

2024-11-04 Thread kadir çetinkaya via cfe-commits


@@ -477,6 +485,100 @@ void DiagnosticsEngine::setSeverityForAll(diag::Flavor 
Flavor,
   setSeverity(Diag, Map, Loc);
 }
 
+namespace {
+class WarningsSpecialCaseList : public llvm::SpecialCaseList {

kadircet wrote:

also see https://discourse.llvm.org/t/refactoring-llvm-specialcaselist/82931

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


[clang] [clang-tools-extra] [llvm] [clang] Introduce diagnostics suppression mappings (PR #112517)

2024-11-04 Thread kadir çetinkaya via cfe-commits




kadircet wrote:

this is already tested in 
https://github.com/llvm/llvm-project/pull/112517/files#diff-a8d03c054381627f238bdb8f7914daa4abebdae705d313dda026ce36eca0fe2fR327-R332

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


[clang] [clang-tools-extra] [llvm] [clang] Introduce diagnostics suppression mappings (PR #112517)

2024-11-04 Thread kadir çetinkaya via cfe-commits


@@ -477,6 +486,109 @@ void DiagnosticsEngine::setSeverityForAll(diag::Flavor 
Flavor,
   setSeverity(Diag, Map, Loc);
 }
 
+namespace {
+class WarningsSpecialCaseList : public llvm::SpecialCaseList {
+public:
+  static std::unique_ptr
+  create(const llvm::MemoryBuffer &MB, std::string &Err) {
+auto SCL = std::make_unique();
+if (!SCL->createInternal(&MB, Err))
+  return nullptr;
+return SCL;
+  }
+
+  // Section names refer to diagnostic groups, which cover multiple individual
+  // diagnostics. Expand diagnostic groups here to individual diagnostics.
+  // A diagnostic can have multiple diagnostic groups associated with it, we 
let
+  // the last section take precedence in such cases.
+  void processSections(DiagnosticsEngine &Diags) {
+// Drop the default section introduced by special case list, we only 
support
+// exact diagnostic group names.
+Sections.erase("*");
+// Make sure we iterate sections by their line numbers.
+std::vector *>>
+LineAndSectionEntry;
+LineAndSectionEntry.reserve(Sections.size());
+for (const auto &Entry : Sections) {
+  LineAndSectionEntry.emplace_back(
+  Entry.second.SectionMatcher->Globs.at(Entry.first()).second, &Entry);
+}
+llvm::sort(LineAndSectionEntry);
+static constexpr auto kFlavor = clang::diag::Flavor::WarningOrError;
+for (const auto &[_, SectionEntry] : LineAndSectionEntry) {
+  SmallVector GroupDiags;
+  llvm::StringRef DiagGroup = SectionEntry->getKey();
+  if (Diags.getDiagnosticIDs()->getDiagnosticsInGroup(kFlavor, DiagGroup,
+  GroupDiags)) {
+StringRef Suggestion =
+DiagnosticIDs::getNearestOption(kFlavor, DiagGroup);
+Diags.Report(diag::warn_unknown_diag_option)
+<< static_cast(kFlavor) << DiagGroup
+<< !Suggestion.empty() << Suggestion;
+continue;
+  }
+  for (diag::kind D : GroupDiags)
+DiagToSection[D] = &SectionEntry->getValue();
+}
+  }
+
+  bool isDiagSuppressed(diag::kind DiagId, llvm::StringRef FilePath) const {
+auto Section = DiagToSection.find(DiagId);
+if (Section == DiagToSection.end())
+  return false;
+auto &DiagEntries = Section->second->Entries;
+auto SrcEntries = DiagEntries.find("src");
+if (SrcEntries == DiagEntries.end())
+  return false;
+return globsMatches(SrcEntries->second, FilePath);
+  }
+
+private:
+  // Find the longest glob pattern that matches FilePath amongst
+  // CategoriesToMatchers, return true iff the match exists and belongs to a
+  // positive category.
+  bool globsMatches(llvm::StringMap CategoriesToMatchers,
+llvm::StringRef FilePath) const {
+llvm::StringRef LongestMatch;
+bool LongestIsPositive = false;
+for (const auto &[Category, Matcher] : CategoriesToMatchers) {
+  bool IsPositive = Category != "emit";
+  for (const auto &[Pattern, Glob] : Matcher.Globs) {

kadircet wrote:

> RE: "rest of the speical-case-list actually match entries in line order", 

sorry I think I was confused while writing this one. I was trying to say, rest 
of the SpecialCaseList users can observe which line matched first. Hence 
performing a re-ordering of patterns would result in behavioral changes for 
these users (I can't say if it'll be a regression or not, as I don't fully 
understand their use cases).

> do you mean that the behavior here is significantly different. Would this be 
> confusing?

not sure what you mean here exactly. overall we don't have a different matching 
behavior in a "user-visible" manner. implementation-wise it's slightly 
different than other sanitizer-list matching, as we keep searching for longest 
matching glob, rather than stopping at first match. it's documented as such and 
I think is intuitive for users (that the most specific entry takes precedence).

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


[clang] [clang] SemaFunctionEffects: When verifying a function, ignore any trailing 'requires' clause. (PR #114266)

2024-11-04 Thread Doug Wyatt via cfe-commits


@@ -985,6 +986,9 @@ class Analyzer {
   if (auto *Dtor = dyn_cast(CurrentCaller.CDecl))
 followDestructor(dyn_cast(Dtor->getParent()), Dtor);
 
+  if (auto *FD = dyn_cast(CurrentCaller.CDecl))
+TrailingRequiresClause = FD->getTrailingRequiresClause();

dougsonos wrote:

Looking at an AST dump from:

```c++
template 
struct integral_constant {
  static constexpr const _Tp value = __v;
  typedef _Tp value_type;
  typedef integral_constant type;
  constexpr operator value_type() const noexcept { return value; }
  constexpr value_type operator()() const noexcept { return value; }
};

template 
constexpr const _Tp integral_constant<_Tp, __v>::value;

typedef integral_constant true_type;
typedef integral_constant false_type;

template 
struct is_default_constructible : public integral_constant {};

template 
inline constexpr bool is_default_constructible_v = __is_constructible(_Tp);

template 
void f()
requires is_default_constructible_v
{
auto g = [](int x) requires is_default_constructible_v {

};
}
```

There are separate `UnresolvedLookupExpr`'s attached to the `FunctionDecl` for 
`f` and to the lambda-generated class's `operator()` and `CXXConversionDecl`.

I found `getTrailingReturnClause()` being used by 
`RecursiveASTVisitor::TraverseFunctionHelper()`.

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


[clang] [Clang] update reasoned delete diagnostic kind to use Extension, making it pedantic only (PR #114713)

2024-11-04 Thread Oleksandr T. via cfe-commits

a-tarasyuk wrote:

> I think we should make these changes to all backported features.

@zwuis @AaronBallman is it okay to handle that in a separate issue/PR?



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


[clang] [Multilib] Custom flags YAML parsing (PR #110657)

2024-11-04 Thread Victor Campos via cfe-commits


@@ -259,11 +266,69 @@ template <> struct 
llvm::yaml::MappingTraits {
   }
 };
 
+template <>
+struct llvm::yaml::MappingContextTraits> {
+  static void mapping(llvm::yaml::IO &io, custom_flag::CustomFlagValueDetail 
&V,
+  llvm::SmallSet &) {
+io.mapRequired("Name", V.Name);
+io.mapOptional("ExtraBuildArgs", V.ExtraBuildArgs);
+  }
+  static std::string validate(IO &io, custom_flag::CustomFlagValueDetail &V,
+  llvm::SmallSet &NameSet) {
+if (V.Name.empty())
+  return "custom flag value requires a name";
+if (!NameSet.insert(V.Name).second)
+  return "duplicate custom flag value name: \"" + V.Name + "\"";
+return {};
+  }
+};
+
+template <>
+struct llvm::yaml::MappingContextTraits> {
+  static void mapping(llvm::yaml::IO &io,
+  custom_flag::CustomFlagDeclarationPtr &V,
+  llvm::SmallSet &NameSet) {
+assert(!V);
+V = std::make_shared();
+io.mapRequired("Name", V->Name);
+io.mapRequired("Values", V->ValueList, NameSet);
+std::string DefaultValueName;
+io.mapRequired("Default", DefaultValueName);
+
+for (auto [Idx, Value] : llvm::enumerate(V->ValueList)) {
+  Value.Decl = V;
+  if (Value.Name == DefaultValueName) {
+assert(V->DefaultValueIdx == ~0UL);
+V->DefaultValueIdx = Idx;
+  }
+}
+  }
+  static std::string validate(IO &io, custom_flag::CustomFlagDeclarationPtr &V,
+  llvm::SmallSet &) {
+if (V->Name.empty())
+  return "custom flag requires a name";
+if (V->ValueList.empty())
+  return "custom flag must have at least one value";
+if (V->DefaultValueIdx >= V->ValueList.size())
+  return "custom flag must have a default value";
+if (llvm::any_of(V->ValueList, [&V](const auto &Value) {
+  return !Value.Decl || Value.Decl != V;
+}))
+  return "custom flag value missing reference to its custom flag "
+ "declaration";

vhscampos wrote:

Fixed

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


[clang] [llvm] [TLI] Add support for reallocarray (PR #114818)

2024-11-04 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-llvm-analysis

@llvm/pr-subscribers-llvm-transforms

Author: None (serge-sans-paille)


Changes

reallocarray is available in glibc since 2.29 under _DEFAULT_SOURCE and under 
_GNU_SOURCE before, let's model it appropriately.

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


7 Files Affected:

- (modified) clang/include/clang/Basic/Builtins.td (+6) 
- (modified) clang/test/Sema/builtins-gnu-mode.c (+1) 
- (modified) llvm/include/llvm/Analysis/TargetLibraryInfo.def (+5) 
- (modified) llvm/lib/Analysis/TargetLibraryInfo.cpp (+1) 
- (modified) llvm/lib/Transforms/Utils/BuildLibCalls.cpp (+15) 
- (modified) llvm/test/tools/llvm-tli-checker/ps4-tli-check.yaml (+2-2) 
- (modified) llvm/unittests/Analysis/TargetLibraryInfoTest.cpp (+1) 


``diff
diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index 9bd67e0cefebc3..546442f843a6b3 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -3224,6 +3224,12 @@ def AllocA : GNULibBuiltin<"stdlib.h"> {
   let AddBuiltinPrefixedAlias = 1;
 }
 
+def ReallocArray : GNULibBuiltin<"stdlib.h"> {
+  let Spellings = ["reallocarray"];
+  let Prototype = "void*(void*, size_t, size_t)";
+}
+
+
 // POSIX malloc.h
 
 def MemAlign : GNULibBuiltin<"malloc.h"> {
diff --git a/clang/test/Sema/builtins-gnu-mode.c 
b/clang/test/Sema/builtins-gnu-mode.c
index d93b6fdef027b6..f85a1e5793a703 100644
--- a/clang/test/Sema/builtins-gnu-mode.c
+++ b/clang/test/Sema/builtins-gnu-mode.c
@@ -8,6 +8,7 @@ int stpncpy;
 int strdup;
 int strndup;
 int index;
+int reallocarray;
 int rindex;
 int bzero;
 int strcasecmp;
diff --git a/llvm/include/llvm/Analysis/TargetLibraryInfo.def 
b/llvm/include/llvm/Analysis/TargetLibraryInfo.def
index fd53a26ef8fc11..db566b8ee610e5 100644
--- a/llvm/include/llvm/Analysis/TargetLibraryInfo.def
+++ b/llvm/include/llvm/Analysis/TargetLibraryInfo.def
@@ -2077,6 +2077,11 @@ TLI_DEFINE_ENUM_INTERNAL(reallocf)
 TLI_DEFINE_STRING_INTERNAL("reallocf")
 TLI_DEFINE_SIG_INTERNAL(Ptr, Ptr, SizeT)
 
+/// void *reallocarray(void *ptr, size_t nmemb, size_t size);
+TLI_DEFINE_ENUM_INTERNAL(reallocarray)
+TLI_DEFINE_STRING_INTERNAL("reallocarray")
+TLI_DEFINE_SIG_INTERNAL(Ptr, Ptr, SizeT, SizeT)
+
 /// char *realpath(const char *file_name, char *resolved_name);
 TLI_DEFINE_ENUM_INTERNAL(realpath)
 TLI_DEFINE_STRING_INTERNAL("realpath")
diff --git a/llvm/lib/Analysis/TargetLibraryInfo.cpp 
b/llvm/lib/Analysis/TargetLibraryInfo.cpp
index 7f0b98ab3c1514..e4b1dbfc3e7231 100644
--- a/llvm/lib/Analysis/TargetLibraryInfo.cpp
+++ b/llvm/lib/Analysis/TargetLibraryInfo.cpp
@@ -852,6 +852,7 @@ static void initializeLibCalls(TargetLibraryInfoImpl &TLI, 
const Triple &T,
 TLI.setUnavailable(LibFunc_memrchr);
 TLI.setUnavailable(LibFunc_ntohl);
 TLI.setUnavailable(LibFunc_ntohs);
+TLI.setUnavailable(LibFunc_reallocarray);
 TLI.setUnavailable(LibFunc_reallocf);
 TLI.setUnavailable(LibFunc_roundeven);
 TLI.setUnavailable(LibFunc_roundevenf);
diff --git a/llvm/lib/Transforms/Utils/BuildLibCalls.cpp 
b/llvm/lib/Transforms/Utils/BuildLibCalls.cpp
index e039457f313b29..8887f2d7792fee 100644
--- a/llvm/lib/Transforms/Utils/BuildLibCalls.cpp
+++ b/llvm/lib/Transforms/Utils/BuildLibCalls.cpp
@@ -577,6 +577,21 @@ bool llvm::inferNonMandatoryLibFuncAttrs(Function &F,
 Changed |= setDoesNotCapture(F, 0);
 Changed |= setArgNoUndef(F, 1);
 break;
+  case LibFunc_reallocarray:
+Changed |= setAllocFamily(F, "malloc");
+Changed |= setAllocKind(F, AllocFnKind::Realloc);
+Changed |= setAllocatedPointerParam(F, 0);
+Changed |= setAllocSize(F, 1, std::nullopt);
+Changed |= setAllocSize(F, 2, std::nullopt);
+Changed |= setOnlyAccessesInaccessibleMemOrArgMem(F);
+Changed |= setRetNoUndef(F);
+Changed |= setDoesNotThrow(F);
+Changed |= setRetDoesNotAlias(F);
+Changed |= setWillReturn(F);
+Changed |= setDoesNotCapture(F, 0);
+Changed |= setArgNoUndef(F, 1);
+Changed |= setArgNoUndef(F, 2);
+break;
   case LibFunc_read:
 // May throw; "read" is a valid pthread cancellation point.
 Changed |= setRetAndArgsNoUndef(F);
diff --git a/llvm/test/tools/llvm-tli-checker/ps4-tli-check.yaml 
b/llvm/test/tools/llvm-tli-checker/ps4-tli-check.yaml
index 6702725e4fc8a4..2d23b15d74b17d 100644
--- a/llvm/test/tools/llvm-tli-checker/ps4-tli-check.yaml
+++ b/llvm/test/tools/llvm-tli-checker/ps4-tli-check.yaml
@@ -54,10 +54,10 @@
 ## the exact count first; the two directives should add up to that.
 ## Yes, this means additions to TLI will fail this test, but the argument
 ## to -COUNT can't be an expression.
-# AVAIL: TLI knows 522 symbols, 289 available
+# AVAIL: TLI knows 523 symbols, 289 available
 # AVAIL-COUNT-289: {{^}} available
 # AVAIL-NOT:   {{^}} available
-# UNAVAIL-COUNT-233: not available
+# UNAVAIL-COUNT-234: not available
 # UNAVAIL-NOT:   not available
 
 ## This is a

[clang] [clang] Fix the post-filtering heuristic for GSLPointer. (PR #114044)

2024-11-04 Thread Haojian Wu via cfe-commits

https://github.com/hokein updated 
https://github.com/llvm/llvm-project/pull/114044

>From 3cb4219e3f09c8a21ce49af7dbafee39eb3d46c6 Mon Sep 17 00:00:00 2001
From: Haojian Wu 
Date: Fri, 1 Nov 2024 16:51:03 +0100
Subject: [PATCH 1/2] [clang] Fix the post-filtering heuristics for GSLPointer
 case.

---
 clang/docs/ReleaseNotes.rst   |   2 +
 clang/lib/Sema/CheckExprLifetime.cpp  | 113 ++
 .../Sema/warn-lifetime-analysis-nocfg.cpp |  48 +++-
 3 files changed, 139 insertions(+), 24 deletions(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index dc45202f6b2e86..0576dc1b4bc6a3 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -464,6 +464,8 @@ Improvements to Clang's diagnostics
 
 - Clang now diagnoses ``[[deprecated]]`` attribute usage on local variables 
(#GH90073).
 
+- Fix false positives when `[[gsl::Owner/Pointer]]` and 
`[[clang::lifetimebound]]` are used together.
+
 Improvements to Clang's time-trace
 --
 
diff --git a/clang/lib/Sema/CheckExprLifetime.cpp 
b/clang/lib/Sema/CheckExprLifetime.cpp
index a1a402b4a2b530..d1e8cc9f9b075c 100644
--- a/clang/lib/Sema/CheckExprLifetime.cpp
+++ b/clang/lib/Sema/CheckExprLifetime.cpp
@@ -1093,6 +1093,87 @@ static bool pathOnlyHandlesGslPointer(const 
IndirectLocalPath &Path) {
   }
   return false;
 }
+// Result of analyzing the Path for GSLPointer.
+enum AnalysisResult {
+  // Path does not correspond to a GSLPointer.
+  NotGSLPointer,
+
+  // A relevant case was identified.
+  Report,
+  // Stop the entire traversal.
+  Abandon,
+  // Skip this step and continue traversing inner AST nodes.
+  Skip,
+};
+// Analyze cases where a GSLPointer is initialized or assigned from a
+// temporary owner object.
+static AnalysisResult analyzePathForGSLPointer(const IndirectLocalPath &Path,
+   Local L) {
+  if (!pathOnlyHandlesGslPointer(Path))
+return NotGSLPointer;
+
+  // At this point, Path represents a series of operations involving a
+  // GSLPointer, either in the process of initialization or assignment.
+
+  // Note: A LifetimeBoundCall can appear interleaved in this sequence.
+  // For example:
+  //const std::string& Ref(const std::string& a [[clang::lifetimebound]]);
+  //string_view abc = Ref(std::string());
+  // The "Path" is [GSLPointerInit, LifetimeboundCall], where "L" is the
+  // temporary "std::string()" object. We need to check if the function with 
the
+  // lifetimebound attribute returns a "owner" type.
+  if (Path.back().Kind == IndirectLocalPathEntry::LifetimeBoundCall) {
+// The lifetimebound applies to the implicit object parameter of a method.
+if (const auto *Method = llvm::dyn_cast(Path.back().D)) {
+  if (Method->getReturnType()->isReferenceType() &&
+  isRecordWithAttr(
+  Method->getReturnType()->getPointeeType()))
+return Report;
+  return Abandon;
+}
+// The lifetimebound applies to a function parameter.
+const auto *PD = llvm::dyn_cast(Path.back().D);
+if (const auto *FD = llvm::dyn_cast(PD->getDeclContext())) {
+  if (isa(FD)) {
+// Constructor case: the parameter is annotated with lifetimebound
+//   e.g., GSLPointer(const S& s [[clang::lifetimebound]])
+// We still respect this case even the type S is not an owner.
+return Report;
+  }
+  // For regular functions, check if the return type has an Owner 
attribute.
+  //   e.g., const GSLOwner& func(const Foo& foo [[clang::lifetimebound]])
+  if (FD->getReturnType()->isReferenceType() &&
+  isRecordWithAttr(FD->getReturnType()->getPointeeType()))
+return Report;
+}
+return Abandon;
+  }
+
+  if (isa(L)) {
+// We do not want to follow the references when returning a pointer
+// originating from a local owner to avoid the following false positive:
+//   int &p = *localUniquePtr;
+//   someContainer.add(std::move(localUniquePtr));
+//   return p;
+if (!pathContainsInit(Path) && isRecordWithAttr(L->getType()))
+  return Report;
+return Abandon;
+  }
+
+  // The GSLPointer is from a temporary object.
+  auto *MTE = dyn_cast(L);
+
+  bool IsGslPtrValueFromGslTempOwner =
+  MTE && !MTE->getExtendingDecl() &&
+  isRecordWithAttr(MTE->getType());
+  // Skipping a chain of initializing gsl::Pointer annotated objects.
+  // We are looking only for the final source to find out if it was
+  // a local or temporary owner or the address of a local
+  // variable/param.
+  if (!IsGslPtrValueFromGslTempOwner)
+return Skip;
+  return Report;
+}
 
 static bool isAssignmentOperatorLifetimeBound(CXXMethodDecl *CMD) {
   if (!CMD)
@@ -1131,27 +1212,17 @@ static void checkExprLifetimeImpl(Sema &SemaRef,
 
 auto *MTE = dyn_cast(L);
 
-bool IsGslPtrValueFromGslTempOwner = false;
-if (pathOnlyHandlesGslPointer(Path)) {
-  if (isa(L))

[clang] [clang-tools-extra] [analyzer] Remove alpha.core.IdenticalExpr Checker (PR #114715)

2024-11-04 Thread Donát Nagy via cfe-commits

NagyDonat wrote:

> I did take the cases one by one from identical-expressions.cpp to the tidy 
> checks and noticed one pattern. It looks to me like identical expressions 
> utilizing floats were excluded in the tidy checks but found in the static 
> analysis check. Do you want to retain that through improvements in 
> misc-redundant-expression, or leave that marked as FIXME? I'm happy to take a 
> look at an improvement like that.

If it's not too difficult, then please improve the tidy checks to cover 
everything that was covered by the static analyzer checker that we want to 
remove. (Obviously this doesn't have a major practical importance as I assume 
that practically nobody used this alpha checker, but it's still nice to say 
that we preserve every feature.)

_(Disclaimer: if you think that the analyzer-only features happen to be buggy 
and/or completely useless, then don't port them.)_

If the changes are complex and you want to create several separate commits, 
then I think the natural commit order would be (1) adding the new features in 
tidy and then (2) removing the analyzer checker in a follow-up commit. However, 
I'd guess that it's reasonable to do these all in a single commit.

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


[clang] [clang] Fix the post-filtering heuristic for GSLPointer. (PR #114044)

2024-11-04 Thread Haojian Wu via cfe-commits


@@ -1093,6 +1093,87 @@ static bool pathOnlyHandlesGslPointer(const 
IndirectLocalPath &Path) {
   }
   return false;
 }
+// Result of analyzing the Path for GSLPointer.
+enum AnalysisResult {
+  // Path does not correspond to a GSLPointer.
+  NotGSLPointer,
+
+  // A relevant case was identified.
+  Report,
+  // Stop the entire traversal.
+  Abandon,
+  // Skip this step and continue traversing inner AST nodes.
+  Skip,
+};
+// Analyze cases where a GSLPointer is initialized or assigned from a
+// temporary owner object.
+static AnalysisResult analyzePathForGSLPointer(const IndirectLocalPath &Path,
+   Local L) {
+  if (!pathOnlyHandlesGslPointer(Path))
+return NotGSLPointer;
+
+  // At this point, Path represents a series of operations involving a
+  // GSLPointer, either in the process of initialization or assignment.
+
+  // Note: A LifetimeBoundCall can appear interleaved in this sequence.
+  // For example:
+  //const std::string& Ref(const std::string& a [[clang::lifetimebound]]);
+  //string_view abc = Ref(std::string());
+  // The "Path" is [GSLPointerInit, LifetimeboundCall], where "L" is the
+  // temporary "std::string()" object. We need to check if the function with 
the
+  // lifetimebound attribute returns a "owner" type.
+  if (Path.back().Kind == IndirectLocalPathEntry::LifetimeBoundCall) {
+// The lifetimebound applies to the implicit object parameter of a method.
+if (const auto *Method = llvm::dyn_cast(Path.back().D)) {
+  if (Method->getReturnType()->isReferenceType() &&

hokein wrote:

Addressed. The new revision reuses more code and is shorter, but I'm not sure 
the rewrite would make the code harder to follow. 

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


[clang] [clang] SemaFunctionEffects: When verifying a function, ignore any trailing 'requires' clause. (PR #114266)

2024-11-04 Thread Doug Wyatt via cfe-commits

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


[clang] [clang] Fix the post-filtering heuristic for GSLPointer. (PR #114044)

2024-11-04 Thread Haojian Wu via cfe-commits


@@ -1093,6 +1093,87 @@ static bool pathOnlyHandlesGslPointer(const 
IndirectLocalPath &Path) {
   }
   return false;
 }
+// Result of analyzing the Path for GSLPointer.
+enum AnalysisResult {

hokein wrote:

We don’t have a strict policy on using enum class vs enum, it's typically left 
to the author's judgment.

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


[clang] [clang] Fix the post-filtering heuristic for GSLPointer. (PR #114044)

2024-11-04 Thread Haojian Wu via cfe-commits


@@ -1093,6 +1093,87 @@ static bool pathOnlyHandlesGslPointer(const 
IndirectLocalPath &Path) {
   }
   return false;
 }
+// Result of analyzing the Path for GSLPointer.

hokein wrote:

It is intended. I think these three `pathOnlyHandlesGslPointer`, 
`AnalysisResult` and `analyzePathForGSLPointer` belong to a group, they all are 
used to implement the filter heuristic. (we can even inline the 
`pathOnlyHandlesGslPointer` in the `analyzePathForGSLPointer`).

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


[clang] [clang] Fix the post-filtering heuristic for GSLPointer. (PR #114044)

2024-11-04 Thread Haojian Wu via cfe-commits


@@ -793,3 +794,44 @@ void test13() {
 }
 
 } // namespace GH100526
+
+namespace LifetimeboundInterleave {
+
+const std::string& Ref(const std::string& abc [[clang::lifetimebound]]);
+std::string_view test1() {
+  std::string_view t1 = Ref(std::string()); // expected-warning {{object 
backing}}
+  t1 = Ref(std::string()); // expected-warning {{object backing}}
+  return Ref(std::string()); // expected-warning {{returning address}}
+}
+
+template 
+struct Foo {
+  const T& get() const [[clang::lifetimebound]];
+  const T& getNoLB() const;
+};
+std::string_view test2(Foo r1, Foo r2) {
+  std::string_view t1 = Foo().get(); // expected-warning {{object 
backing}}
+  t1 = Foo().get(); // expected-warning {{object backing}}
+  return r1.get(); // expected-warning {{address of stack}}
+  
+  std::string_view t2 = Foo().get();
+  t2 = Foo().get();
+  return r2.get();
+
+  // no warning on no-LB-annotated method.
+  std::string_view t3 = Foo().getNoLB(); 
+  t3 = Foo().getNoLB(); 
+  return r1.getNoLB(); 
+}
+
+struct Bar {};
+struct [[gsl::Pointer]] Pointer {
+  Pointer(const Bar & bar [[clang::lifetimebound]]);
+};
+Pointer test3(Bar bar) {
+  Pointer p = Pointer(Bar()); // expected-warning {{temporary}}
+  p = Pointer(Bar()); // expected-warning {{object backing}}

hokein wrote:

This was a false negative before, this patch also fixes it.

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


[clang] 3268d51 - [clang][bytecode][NFC] Fix a possible build warning (#114800)

2024-11-04 Thread via cfe-commits

Author: Timm Baeder
Date: 2024-11-04T16:58:44+01:00
New Revision: 3268d51a5c81be705a97216bf061fab9bb195ebe

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

LOG: [clang][bytecode][NFC] Fix a possible build warning (#114800)

InterpBuiltinBitCast.cpp:95:3: warning: non-void function does not
return a value in all control paths [-Wreturn-type]
   95 |   }
  |   ^
1 warning generated.

Added: 


Modified: 
clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp

Removed: 




diff  --git a/clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp 
b/clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp
index e458613bc1d08d..27b20e258d94f4 100644
--- a/clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp
+++ b/clang/lib/AST/ByteCode/InterpBuiltinBitCast.cpp
@@ -88,9 +88,8 @@ struct BitcastBuffer {
   const std::byte *data() const { return Data.data(); }
 
   std::byte *getBytes(unsigned BitOffset) const {
-if (BitOffset % 8 == 0)
-  return const_cast(data() + (BitOffset / 8));
-assert(false && "hmm, how to best handle this?");
+assert(BitOffset % 8 == 0);
+return const_cast(data() + (BitOffset / 8));
   }
 
   bool allInitialized() const {



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


[clang] [clang] SemaFunctionEffects: When verifying a function, ignore any trailing 'requires' clause. (PR #114266)

2024-11-04 Thread Doug Wyatt via cfe-commits

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


[clang] [llvm] [TLI] Add support for reallocarray (PR #114818)

2024-11-04 Thread via cfe-commits

https://github.com/serge-sans-paille created 
https://github.com/llvm/llvm-project/pull/114818

reallocarray is available in glibc since 2.29 under _DEFAULT_SOURCE and under 
_GNU_SOURCE before, let's model it appropriately.

>From c46cdf6b3debe50fc0611c93ec3a1de33d4f472b Mon Sep 17 00:00:00 2001
From: serge-sans-paille 
Date: Mon, 4 Nov 2024 16:50:45 +0100
Subject: [PATCH] [TLI] Add support for reallocarray

reallocarray is available in glibc since 2.29 under _DEFAULT_SOURCE and
under _GNU_SOURCE before, let's model it appropriately.
---
 clang/include/clang/Basic/Builtins.td |  6 ++
 clang/test/Sema/builtins-gnu-mode.c   |  1 +
 llvm/include/llvm/Analysis/TargetLibraryInfo.def  |  5 +
 llvm/lib/Analysis/TargetLibraryInfo.cpp   |  1 +
 llvm/lib/Transforms/Utils/BuildLibCalls.cpp   | 15 +++
 .../tools/llvm-tli-checker/ps4-tli-check.yaml |  4 ++--
 llvm/unittests/Analysis/TargetLibraryInfoTest.cpp |  1 +
 7 files changed, 31 insertions(+), 2 deletions(-)

diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index 9bd67e0cefebc3..546442f843a6b3 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -3224,6 +3224,12 @@ def AllocA : GNULibBuiltin<"stdlib.h"> {
   let AddBuiltinPrefixedAlias = 1;
 }
 
+def ReallocArray : GNULibBuiltin<"stdlib.h"> {
+  let Spellings = ["reallocarray"];
+  let Prototype = "void*(void*, size_t, size_t)";
+}
+
+
 // POSIX malloc.h
 
 def MemAlign : GNULibBuiltin<"malloc.h"> {
diff --git a/clang/test/Sema/builtins-gnu-mode.c 
b/clang/test/Sema/builtins-gnu-mode.c
index d93b6fdef027b6..f85a1e5793a703 100644
--- a/clang/test/Sema/builtins-gnu-mode.c
+++ b/clang/test/Sema/builtins-gnu-mode.c
@@ -8,6 +8,7 @@ int stpncpy;
 int strdup;
 int strndup;
 int index;
+int reallocarray;
 int rindex;
 int bzero;
 int strcasecmp;
diff --git a/llvm/include/llvm/Analysis/TargetLibraryInfo.def 
b/llvm/include/llvm/Analysis/TargetLibraryInfo.def
index fd53a26ef8fc11..db566b8ee610e5 100644
--- a/llvm/include/llvm/Analysis/TargetLibraryInfo.def
+++ b/llvm/include/llvm/Analysis/TargetLibraryInfo.def
@@ -2077,6 +2077,11 @@ TLI_DEFINE_ENUM_INTERNAL(reallocf)
 TLI_DEFINE_STRING_INTERNAL("reallocf")
 TLI_DEFINE_SIG_INTERNAL(Ptr, Ptr, SizeT)
 
+/// void *reallocarray(void *ptr, size_t nmemb, size_t size);
+TLI_DEFINE_ENUM_INTERNAL(reallocarray)
+TLI_DEFINE_STRING_INTERNAL("reallocarray")
+TLI_DEFINE_SIG_INTERNAL(Ptr, Ptr, SizeT, SizeT)
+
 /// char *realpath(const char *file_name, char *resolved_name);
 TLI_DEFINE_ENUM_INTERNAL(realpath)
 TLI_DEFINE_STRING_INTERNAL("realpath")
diff --git a/llvm/lib/Analysis/TargetLibraryInfo.cpp 
b/llvm/lib/Analysis/TargetLibraryInfo.cpp
index 7f0b98ab3c1514..e4b1dbfc3e7231 100644
--- a/llvm/lib/Analysis/TargetLibraryInfo.cpp
+++ b/llvm/lib/Analysis/TargetLibraryInfo.cpp
@@ -852,6 +852,7 @@ static void initializeLibCalls(TargetLibraryInfoImpl &TLI, 
const Triple &T,
 TLI.setUnavailable(LibFunc_memrchr);
 TLI.setUnavailable(LibFunc_ntohl);
 TLI.setUnavailable(LibFunc_ntohs);
+TLI.setUnavailable(LibFunc_reallocarray);
 TLI.setUnavailable(LibFunc_reallocf);
 TLI.setUnavailable(LibFunc_roundeven);
 TLI.setUnavailable(LibFunc_roundevenf);
diff --git a/llvm/lib/Transforms/Utils/BuildLibCalls.cpp 
b/llvm/lib/Transforms/Utils/BuildLibCalls.cpp
index e039457f313b29..8887f2d7792fee 100644
--- a/llvm/lib/Transforms/Utils/BuildLibCalls.cpp
+++ b/llvm/lib/Transforms/Utils/BuildLibCalls.cpp
@@ -577,6 +577,21 @@ bool llvm::inferNonMandatoryLibFuncAttrs(Function &F,
 Changed |= setDoesNotCapture(F, 0);
 Changed |= setArgNoUndef(F, 1);
 break;
+  case LibFunc_reallocarray:
+Changed |= setAllocFamily(F, "malloc");
+Changed |= setAllocKind(F, AllocFnKind::Realloc);
+Changed |= setAllocatedPointerParam(F, 0);
+Changed |= setAllocSize(F, 1, std::nullopt);
+Changed |= setAllocSize(F, 2, std::nullopt);
+Changed |= setOnlyAccessesInaccessibleMemOrArgMem(F);
+Changed |= setRetNoUndef(F);
+Changed |= setDoesNotThrow(F);
+Changed |= setRetDoesNotAlias(F);
+Changed |= setWillReturn(F);
+Changed |= setDoesNotCapture(F, 0);
+Changed |= setArgNoUndef(F, 1);
+Changed |= setArgNoUndef(F, 2);
+break;
   case LibFunc_read:
 // May throw; "read" is a valid pthread cancellation point.
 Changed |= setRetAndArgsNoUndef(F);
diff --git a/llvm/test/tools/llvm-tli-checker/ps4-tli-check.yaml 
b/llvm/test/tools/llvm-tli-checker/ps4-tli-check.yaml
index 6702725e4fc8a4..2d23b15d74b17d 100644
--- a/llvm/test/tools/llvm-tli-checker/ps4-tli-check.yaml
+++ b/llvm/test/tools/llvm-tli-checker/ps4-tli-check.yaml
@@ -54,10 +54,10 @@
 ## the exact count first; the two directives should add up to that.
 ## Yes, this means additions to TLI will fail this test, but the argument
 ## to -COUNT can't be an expression.
-# AVAIL: TLI knows 522 symbols, 289 available
+# AVAIL: TLI knows 523 symbols

[clang] [clang] SemaFunctionEffects: When verifying a function, ignore any trailing 'requires' clause. (PR #114266)

2024-11-04 Thread Doug Wyatt via cfe-commits


@@ -985,6 +986,9 @@ class Analyzer {
   if (auto *Dtor = dyn_cast(CurrentCaller.CDecl))
 followDestructor(dyn_cast(Dtor->getParent()), Dtor);
 
+  if (auto *FD = dyn_cast(CurrentCaller.CDecl))
+TrailingRequiresClause = FD->getTrailingRequiresClause();

dougsonos wrote:

That's a good question. This is sufficient/correct for a couple of reasons:

- This whole `RecursiveASTVisitor` subclass is called for one 
function/lambda/block at a time, and this (new) member `TrailingRequiresClause` 
is being set for that "top-level" function only.
- Lambdas and blocks have overridden `Traverse` methods in order to skip their 
bodies -- which also mean we don't care about, and don't visit, their 
`requires` clauses.

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


[clang] [compiler-rt] [libcxx] [llvm] [libc++] Replace LIBCXX_ENABLE_STATIC_ABI_LIBRARY & friends by a new LIBCXX_CXX_ABI choice (PR #112978)

2024-11-04 Thread Louis Dionne via cfe-commits

ldionne wrote:

> Looking at our current cmake config, we're using:
> 
> ```
> -DLIBCXX_STATICALLY_LINK_ABI_IN_STATIC_LIBRARY=ON \
> -DLIBCXX_ENABLE_ABI_LINKER_SCRIPT=ON \
> ```
> 
> Do I understand correctly that the new replacement for that would be?
> 
> ```
> -DLIBCXX_ABILIB_FOR_SHARED="shared-libcxxabi" \
> -DLIBCXX_ABILIB_FOR_STATIC="merged-libcxxabi" \
> -DLIBCXX_ENABLE_ABI_LINKER_SCRIPT=ON \
> ```

Yes, that is correct. This patch should be changing your CMake config as well, 
unless that config is not visible in the monorepo (or if I missed it).

> 
> And those LIBCXX_ABILIB options are also the defaults, if I'm reading the 
> docs right.

Not quite. `LIBCXX_ABILIB_FOR_SHARED="shared-libcxxabi"` is the default for the 
shared library. However for the static library, the default is 
`LIBCXX_ABILIB_FOR_STATIC="static-libcxxabi"`. That might not be the most 
useful default (`merged-libcxxabi` would be more useful IMO), but it's the 
status quo and this patch doesn't change that.

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


  1   2   3   4   5   6   >