[clang] [llvm] [BPF] Add load-acquire and store-release instructions under -mcpu=v4 (PR #108636)

2024-10-24 Thread via cfe-commits


@@ -48,6 +48,13 @@ def BPF_END  : BPFArithOp<0xd>;
 def BPF_XCHG: BPFArithOp<0xe>;
 def BPF_CMPXCHG : BPFArithOp<0xf>;
 
+class BPFAtomicLoadStoreOp val> {
+  bits<4> Value = val;
+}
+
+def BPF_LOAD_ACQ : BPFAtomicLoadStoreOp<0x1>;
+def BPF_STORE_REL : BPFAtomicLoadStoreOp<0xb>;

yonghong-song wrote:

I may miss some context. Any particular reason to pick 0xb here for imm field?

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


[clang] Emit constrained atan2 intrinsic for clang builtin (PR #113636)

2024-10-24 Thread Tex Riddell via cfe-commits

https://github.com/tex3d created 
https://github.com/llvm/llvm-project/pull/113636

This change is part of this proposal: 
https://discourse.llvm.org/t/rfc-all-the-math-intrinsics/78294

- `Builtins.td` - Add f16 support for libm atan2 builtin
- `CGBuiltin.cpp` - Emit constraint atan2 intrinsic for clang builtin

Part of Implement the atan2 HLSL Function 
https://github.com/llvm/llvm-project/issues/70096.

>From 0c9dfb67a7371b9c4087d7b54e6f93e780038117 Mon Sep 17 00:00:00 2001
From: Tex Riddell 
Date: Tue, 15 Oct 2024 16:18:44 -0700
Subject: [PATCH 1/2] Emit constrained atan2 intrinsic for clang builtin

This change is part of this proposal: 
https://discourse.llvm.org/t/rfc-all-the-math-intrinsics/78294

- `Builtins.td` - Add f16 support for libm atan2 builtin
- `CGBuiltin.cpp` - Emit constraint atan2 intrinsic for clang builtin

Part of Implement the atan2 HLSL Function #70096.
---
 clang/include/clang/Basic/Builtins.td |  6 +++---
 clang/lib/CodeGen/CGBuiltin.cpp   | 11 ++
 clang/test/CodeGen/X86/math-builtins.c| 14 ++---
 .../test/CodeGen/constrained-math-builtins.c  |  7 +++
 clang/test/CodeGen/libcalls.c |  7 +++
 clang/test/CodeGen/math-libcalls.c| 20 +--
 .../test/CodeGenCXX/builtin-calling-conv.cpp  | 10 +-
 clang/test/CodeGenOpenCL/builtins-f16.cl  |  3 +++
 8 files changed, 49 insertions(+), 29 deletions(-)

diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index 90475a361bb8f8..0d77f4105bb757 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -227,10 +227,10 @@ def FminimumNumF16F128 : Builtin, F16F128MathTemplate {
   let Prototype = "T(T, T)";
 }
 
-def Atan2F128 : Builtin {
-  let Spellings = ["__builtin_atan2f128"];
+def Atan2F16F128 : Builtin, F16F128MathTemplate {
+  let Spellings = ["__builtin_atan2"];
   let Attributes = [FunctionWithBuiltinPrefix, NoThrow, 
ConstIgnoringErrnoAndExceptions];
-  let Prototype = "__float128(__float128, __float128)";
+  let Prototype = "T(T, T)";
 }
 
 def CopysignF16 : Builtin {
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index e2d03eff8ab4a0..0bec8f32552110 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -2724,6 +2724,17 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
   return RValue::get(emitUnaryMaybeConstrainedFPBuiltin(
   *this, E, Intrinsic::atan, 
Intrinsic::experimental_constrained_atan));
 
+case Builtin::BIatan2:
+case Builtin::BIatan2f:
+case Builtin::BIatan2l:
+case Builtin::BI__builtin_atan2:
+case Builtin::BI__builtin_atan2f:
+case Builtin::BI__builtin_atan2f16:
+case Builtin::BI__builtin_atan2l:
+case Builtin::BI__builtin_atan2f128:
+  return RValue::get(emitBinaryMaybeConstrainedFPBuiltin(
+  *this, E, Intrinsic::atan2, 
Intrinsic::experimental_constrained_atan2));
+
 case Builtin::BIceil:
 case Builtin::BIceilf:
 case Builtin::BIceill:
diff --git a/clang/test/CodeGen/X86/math-builtins.c 
b/clang/test/CodeGen/X86/math-builtins.c
index 48465df21cca19..bf107437fc63a3 100644
--- a/clang/test/CodeGen/X86/math-builtins.c
+++ b/clang/test/CodeGen/X86/math-builtins.c
@@ -45,10 +45,10 @@ void foo(double *d, float f, float *fp, long double *l, int 
*i, const char *c) {
 
   __builtin_atan2(f,f);__builtin_atan2f(f,f) ;  __builtin_atan2l(f, f); 
__builtin_atan2f128(f,f);
 
-// NO__ERRNO: declare double @atan2(double noundef, double noundef) 
[[READNONE:#[0-9]+]]
-// NO__ERRNO: declare float @atan2f(float noundef, float noundef) [[READNONE]]
-// NO__ERRNO: declare x86_fp80 @atan2l(x86_fp80 noundef, x86_fp80 noundef) 
[[READNONE]]
-// NO__ERRNO: declare fp128 @atan2f128(fp128 noundef, fp128 noundef) 
[[READNONE]]
+// NO__ERRNO: declare double @llvm.atan2.f64(double, double) 
[[READNONE_INTRINSIC:#[0-9]+]]
+// NO__ERRNO: declare float @llvm.atan2.f32(float, float) 
[[READNONE_INTRINSIC]]
+// NO__ERRNO: declare x86_fp80 @llvm.atan2.f80(x86_fp80, x86_fp80) 
[[READNONE_INTRINSIC]]
+// NO__ERRNO: declare fp128 @llvm.atan2.f128(fp128, fp128) 
[[READNONE_INTRINSIC]]
 // HAS_ERRNO: declare double @atan2(double noundef, double noundef) 
[[NOT_READNONE]]
 // HAS_ERRNO: declare float @atan2f(float noundef, float noundef) 
[[NOT_READNONE]]
 // HAS_ERRNO: declare x86_fp80 @atan2l(x86_fp80 noundef, x86_fp80 noundef) 
[[NOT_READNONE]]
@@ -56,7 +56,7 @@ void foo(double *d, float f, float *fp, long double *l, int 
*i, const char *c) {
 
   __builtin_copysign(f,f); __builtin_copysignf(f,f); __builtin_copysignl(f,f); 
__builtin_copysignf128(f,f);
 
-// NO__ERRNO: declare double @llvm.copysign.f64(double, double) 
[[READNONE_INTRINSIC:#[0-9]+]]
+// NO__ERRNO: declare double @llvm.copysign.f64(double, double) 
[[READNONE_INTRINSIC]]
 // NO__ERRNO: declare float @llvm.copysign.f32(float, float) 
[[R

[clang] Emit constrained atan2 intrinsic for clang builtin (PR #113636)

2024-10-24 Thread Tex Riddell via cfe-commits

https://github.com/tex3d updated 
https://github.com/llvm/llvm-project/pull/113636

>From 0c9dfb67a7371b9c4087d7b54e6f93e780038117 Mon Sep 17 00:00:00 2001
From: Tex Riddell 
Date: Tue, 15 Oct 2024 16:18:44 -0700
Subject: [PATCH 1/3] Emit constrained atan2 intrinsic for clang builtin

This change is part of this proposal: 
https://discourse.llvm.org/t/rfc-all-the-math-intrinsics/78294

- `Builtins.td` - Add f16 support for libm atan2 builtin
- `CGBuiltin.cpp` - Emit constraint atan2 intrinsic for clang builtin

Part of Implement the atan2 HLSL Function #70096.
---
 clang/include/clang/Basic/Builtins.td |  6 +++---
 clang/lib/CodeGen/CGBuiltin.cpp   | 11 ++
 clang/test/CodeGen/X86/math-builtins.c| 14 ++---
 .../test/CodeGen/constrained-math-builtins.c  |  7 +++
 clang/test/CodeGen/libcalls.c |  7 +++
 clang/test/CodeGen/math-libcalls.c| 20 +--
 .../test/CodeGenCXX/builtin-calling-conv.cpp  | 10 +-
 clang/test/CodeGenOpenCL/builtins-f16.cl  |  3 +++
 8 files changed, 49 insertions(+), 29 deletions(-)

diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index 90475a361bb8f8..0d77f4105bb757 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -227,10 +227,10 @@ def FminimumNumF16F128 : Builtin, F16F128MathTemplate {
   let Prototype = "T(T, T)";
 }
 
-def Atan2F128 : Builtin {
-  let Spellings = ["__builtin_atan2f128"];
+def Atan2F16F128 : Builtin, F16F128MathTemplate {
+  let Spellings = ["__builtin_atan2"];
   let Attributes = [FunctionWithBuiltinPrefix, NoThrow, 
ConstIgnoringErrnoAndExceptions];
-  let Prototype = "__float128(__float128, __float128)";
+  let Prototype = "T(T, T)";
 }
 
 def CopysignF16 : Builtin {
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index e2d03eff8ab4a0..0bec8f32552110 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -2724,6 +2724,17 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
   return RValue::get(emitUnaryMaybeConstrainedFPBuiltin(
   *this, E, Intrinsic::atan, 
Intrinsic::experimental_constrained_atan));
 
+case Builtin::BIatan2:
+case Builtin::BIatan2f:
+case Builtin::BIatan2l:
+case Builtin::BI__builtin_atan2:
+case Builtin::BI__builtin_atan2f:
+case Builtin::BI__builtin_atan2f16:
+case Builtin::BI__builtin_atan2l:
+case Builtin::BI__builtin_atan2f128:
+  return RValue::get(emitBinaryMaybeConstrainedFPBuiltin(
+  *this, E, Intrinsic::atan2, 
Intrinsic::experimental_constrained_atan2));
+
 case Builtin::BIceil:
 case Builtin::BIceilf:
 case Builtin::BIceill:
diff --git a/clang/test/CodeGen/X86/math-builtins.c 
b/clang/test/CodeGen/X86/math-builtins.c
index 48465df21cca19..bf107437fc63a3 100644
--- a/clang/test/CodeGen/X86/math-builtins.c
+++ b/clang/test/CodeGen/X86/math-builtins.c
@@ -45,10 +45,10 @@ void foo(double *d, float f, float *fp, long double *l, int 
*i, const char *c) {
 
   __builtin_atan2(f,f);__builtin_atan2f(f,f) ;  __builtin_atan2l(f, f); 
__builtin_atan2f128(f,f);
 
-// NO__ERRNO: declare double @atan2(double noundef, double noundef) 
[[READNONE:#[0-9]+]]
-// NO__ERRNO: declare float @atan2f(float noundef, float noundef) [[READNONE]]
-// NO__ERRNO: declare x86_fp80 @atan2l(x86_fp80 noundef, x86_fp80 noundef) 
[[READNONE]]
-// NO__ERRNO: declare fp128 @atan2f128(fp128 noundef, fp128 noundef) 
[[READNONE]]
+// NO__ERRNO: declare double @llvm.atan2.f64(double, double) 
[[READNONE_INTRINSIC:#[0-9]+]]
+// NO__ERRNO: declare float @llvm.atan2.f32(float, float) 
[[READNONE_INTRINSIC]]
+// NO__ERRNO: declare x86_fp80 @llvm.atan2.f80(x86_fp80, x86_fp80) 
[[READNONE_INTRINSIC]]
+// NO__ERRNO: declare fp128 @llvm.atan2.f128(fp128, fp128) 
[[READNONE_INTRINSIC]]
 // HAS_ERRNO: declare double @atan2(double noundef, double noundef) 
[[NOT_READNONE]]
 // HAS_ERRNO: declare float @atan2f(float noundef, float noundef) 
[[NOT_READNONE]]
 // HAS_ERRNO: declare x86_fp80 @atan2l(x86_fp80 noundef, x86_fp80 noundef) 
[[NOT_READNONE]]
@@ -56,7 +56,7 @@ void foo(double *d, float f, float *fp, long double *l, int 
*i, const char *c) {
 
   __builtin_copysign(f,f); __builtin_copysignf(f,f); __builtin_copysignl(f,f); 
__builtin_copysignf128(f,f);
 
-// NO__ERRNO: declare double @llvm.copysign.f64(double, double) 
[[READNONE_INTRINSIC:#[0-9]+]]
+// NO__ERRNO: declare double @llvm.copysign.f64(double, double) 
[[READNONE_INTRINSIC]]
 // NO__ERRNO: declare float @llvm.copysign.f32(float, float) 
[[READNONE_INTRINSIC]]
 // NO__ERRNO: declare x86_fp80 @llvm.copysign.f80(x86_fp80, x86_fp80) 
[[READNONE_INTRINSIC]]
 // NO__ERRNO: declare fp128 @llvm.copysign.f128(fp128, fp128) 
[[READNONE_INTRINSIC]]
@@ -179,7 +179,7 @@ void foo(double *d, float f, float *fp, long double *l, int 
*i, const char *c) {
 
   __builtin_acosh(f

[clang] [llvm] [BPF] Add load-acquire and store-release instructions under -mcpu=v4 (PR #108636)

2024-10-24 Thread via cfe-commits

yonghong-song wrote:

@peilin-ye Thanks for trying getExtendForAtomicOps(). I just did some 
experiments and indeed looks like backend has to pick one default extend, sign, 
unsigned, or any. My previous suggestion to match atomic_load_zext_{8,16} and 
atomic_load_sext_{8,16} separately won't work.

So your change looks good. Once you get some kernel work in reasonable shape, 
this patch can land. Thanks!

https://github.com/llvm/llvm-project/pull/108636
___
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-tidy] Create bugprone-incorrect-enable-shared-from-this check (PR #102299)

2024-10-24 Thread via cfe-commits

MichelleCDjunaidi wrote:

...oops, I don't think that was supposed to happen.

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


[clang] Emit constrained atan2 intrinsic for clang builtin (PR #113636)

2024-10-24 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-backend-x86

Author: Tex Riddell (tex3d)


Changes

This change is part of this proposal: 
https://discourse.llvm.org/t/rfc-all-the-math-intrinsics/78294

- `Builtins.td` - Add f16 support for libm atan2 builtin
- `CGBuiltin.cpp` - Emit constraint atan2 intrinsic for clang builtin

Part of Implement the atan2 HLSL Function 
https://github.com/llvm/llvm-project/issues/70096.

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


8 Files Affected:

- (modified) clang/include/clang/Basic/Builtins.td (+3-3) 
- (modified) clang/lib/CodeGen/CGBuiltin.cpp (+11) 
- (modified) clang/test/CodeGen/X86/math-builtins.c (+7-7) 
- (modified) clang/test/CodeGen/constrained-math-builtins.c (+7) 
- (modified) clang/test/CodeGen/libcalls.c (+3-4) 
- (modified) clang/test/CodeGen/math-libcalls.c (+10-10) 
- (modified) clang/test/CodeGenCXX/builtin-calling-conv.cpp (+8-8) 
- (modified) clang/test/CodeGenOpenCL/builtins-f16.cl (+3) 


``diff
diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index 90475a361bb8f8..0d77f4105bb757 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -227,10 +227,10 @@ def FminimumNumF16F128 : Builtin, F16F128MathTemplate {
   let Prototype = "T(T, T)";
 }
 
-def Atan2F128 : Builtin {
-  let Spellings = ["__builtin_atan2f128"];
+def Atan2F16F128 : Builtin, F16F128MathTemplate {
+  let Spellings = ["__builtin_atan2"];
   let Attributes = [FunctionWithBuiltinPrefix, NoThrow, 
ConstIgnoringErrnoAndExceptions];
-  let Prototype = "__float128(__float128, __float128)";
+  let Prototype = "T(T, T)";
 }
 
 def CopysignF16 : Builtin {
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index e2d03eff8ab4a0..0bec8f32552110 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -2724,6 +2724,17 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
   return RValue::get(emitUnaryMaybeConstrainedFPBuiltin(
   *this, E, Intrinsic::atan, 
Intrinsic::experimental_constrained_atan));
 
+case Builtin::BIatan2:
+case Builtin::BIatan2f:
+case Builtin::BIatan2l:
+case Builtin::BI__builtin_atan2:
+case Builtin::BI__builtin_atan2f:
+case Builtin::BI__builtin_atan2f16:
+case Builtin::BI__builtin_atan2l:
+case Builtin::BI__builtin_atan2f128:
+  return RValue::get(emitBinaryMaybeConstrainedFPBuiltin(
+  *this, E, Intrinsic::atan2, 
Intrinsic::experimental_constrained_atan2));
+
 case Builtin::BIceil:
 case Builtin::BIceilf:
 case Builtin::BIceill:
diff --git a/clang/test/CodeGen/X86/math-builtins.c 
b/clang/test/CodeGen/X86/math-builtins.c
index 48465df21cca19..bf107437fc63a3 100644
--- a/clang/test/CodeGen/X86/math-builtins.c
+++ b/clang/test/CodeGen/X86/math-builtins.c
@@ -45,10 +45,10 @@ void foo(double *d, float f, float *fp, long double *l, int 
*i, const char *c) {
 
   __builtin_atan2(f,f);__builtin_atan2f(f,f) ;  __builtin_atan2l(f, f); 
__builtin_atan2f128(f,f);
 
-// NO__ERRNO: declare double @atan2(double noundef, double noundef) 
[[READNONE:#[0-9]+]]
-// NO__ERRNO: declare float @atan2f(float noundef, float noundef) [[READNONE]]
-// NO__ERRNO: declare x86_fp80 @atan2l(x86_fp80 noundef, x86_fp80 noundef) 
[[READNONE]]
-// NO__ERRNO: declare fp128 @atan2f128(fp128 noundef, fp128 noundef) 
[[READNONE]]
+// NO__ERRNO: declare double @llvm.atan2.f64(double, double) 
[[READNONE_INTRINSIC:#[0-9]+]]
+// NO__ERRNO: declare float @llvm.atan2.f32(float, float) 
[[READNONE_INTRINSIC]]
+// NO__ERRNO: declare x86_fp80 @llvm.atan2.f80(x86_fp80, x86_fp80) 
[[READNONE_INTRINSIC]]
+// NO__ERRNO: declare fp128 @llvm.atan2.f128(fp128, fp128) 
[[READNONE_INTRINSIC]]
 // HAS_ERRNO: declare double @atan2(double noundef, double noundef) 
[[NOT_READNONE]]
 // HAS_ERRNO: declare float @atan2f(float noundef, float noundef) 
[[NOT_READNONE]]
 // HAS_ERRNO: declare x86_fp80 @atan2l(x86_fp80 noundef, x86_fp80 noundef) 
[[NOT_READNONE]]
@@ -56,7 +56,7 @@ void foo(double *d, float f, float *fp, long double *l, int 
*i, const char *c) {
 
   __builtin_copysign(f,f); __builtin_copysignf(f,f); __builtin_copysignl(f,f); 
__builtin_copysignf128(f,f);
 
-// NO__ERRNO: declare double @llvm.copysign.f64(double, double) 
[[READNONE_INTRINSIC:#[0-9]+]]
+// NO__ERRNO: declare double @llvm.copysign.f64(double, double) 
[[READNONE_INTRINSIC]]
 // NO__ERRNO: declare float @llvm.copysign.f32(float, float) 
[[READNONE_INTRINSIC]]
 // NO__ERRNO: declare x86_fp80 @llvm.copysign.f80(x86_fp80, x86_fp80) 
[[READNONE_INTRINSIC]]
 // NO__ERRNO: declare fp128 @llvm.copysign.f128(fp128, fp128) 
[[READNONE_INTRINSIC]]
@@ -179,7 +179,7 @@ void foo(double *d, float f, float *fp, long double *l, int 
*i, const char *c) {
 
   __builtin_acosh(f);  __builtin_acoshf(f); __builtin_acoshl(f);  
__builtin_acoshf128(f);
 
-// NO__ERRNO: declare double @acosh(doubl

[clang] 8aa69a0 - [clang][dataflow] Disambiguate a ref to "internal" in CachedConstAccessorsLattice (#113601)

2024-10-24 Thread via cfe-commits

Author: Jan Voung
Date: 2024-10-24T15:23:40-04:00
New Revision: 8aa69a0d02e99e50db0242f75a192b1c2d826528

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

LOG: [clang][dataflow] Disambiguate a ref to "internal" in 
CachedConstAccessorsLattice (#113601)

Disambiguate to fix a build error (e.g., on windows with clang-cl)

Added: 


Modified: 
clang/include/clang/Analysis/FlowSensitive/CachedConstAccessorsLattice.h

Removed: 




diff  --git 
a/clang/include/clang/Analysis/FlowSensitive/CachedConstAccessorsLattice.h 
b/clang/include/clang/Analysis/FlowSensitive/CachedConstAccessorsLattice.h
index 3402d105746e88..48c5287367739a 100644
--- a/clang/include/clang/Analysis/FlowSensitive/CachedConstAccessorsLattice.h
+++ b/clang/include/clang/Analysis/FlowSensitive/CachedConstAccessorsLattice.h
@@ -154,11 +154,12 @@ LatticeEffect CachedConstAccessorsLattice::join(
   // are non-identical but equivalent. This is likely to be sufficient in
   // practice, and it reduces implementation complexity considerably.
 
-  ConstMethodReturnValues = internal::joinConstMethodMap(
-  ConstMethodReturnValues, Other.ConstMethodReturnValues, Effect);
+  ConstMethodReturnValues =
+  clang::dataflow::internal::joinConstMethodMap(
+  ConstMethodReturnValues, Other.ConstMethodReturnValues, Effect);
 
   ConstMethodReturnStorageLocations =
-  internal::joinConstMethodMap(
+  clang::dataflow::internal::joinConstMethodMap(
   ConstMethodReturnStorageLocations,
   Other.ConstMethodReturnStorageLocations, Effect);
 



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


[clang] [llvm] Adding splitdouble HLSL function (PR #109331)

2024-10-24 Thread Tex Riddell via cfe-commits

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


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


[clang] [llvm] [BPF] Add load-acquire and store-release instructions under -mcpu=v4 (PR #108636)

2024-10-24 Thread via cfe-commits


@@ -67,6 +67,8 @@ void BPFTargetInfo::getTargetDefines(const LangOptions &Opts,
 Builder.defineMacro("__BPF_FEATURE_SDIV_SMOD");
 Builder.defineMacro("__BPF_FEATURE_GOTOL");
 Builder.defineMacro("__BPF_FEATURE_ST");
+Builder.defineMacro("__BPF_FEATURE_LOAD_ACQUIRE");
+Builder.defineMacro("__BPF_FEATURE_STORE_RELEASE");

yonghong-song wrote:

I think load_acquire and store_release can be just ONE feature as 
load_acquire/store_release often pair with each other. But I don't have a good 
name for that. If no good name, your above two features are fine to me too.

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


[clang-tools-extra] [clang-tidy] Create bugprone-incorrect-enable-shared-from-this check (PR #102299)

2024-10-24 Thread via cfe-commits

MichelleCDjunaidi wrote:

For context: force-push is to undo merge-squash. Didn't know that pinged 
everyone else, real sorry!

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


[clang-tools-extra] [clang-tidy] fix false positive for implicit conversion of comparison result in C23 (PR #113639)

2024-10-24 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-tidy

Author: Congcong Cai (HerrCai0907)


Changes

Fixed #111013
bool will be builtin type in C23 but comparison result in C is still int.
It is no need to change this kind of implicit cast to explicit cast.


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


3 Files Affected:

- (modified) 
clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp (+7) 
- (modified) clang-tools-extra/docs/ReleaseNotes.rst (+2-1) 
- (modified) 
clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion.c
 (+9) 


``diff
diff --git 
a/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
index 968a4a55a6d798..06415c1346a4f0 100644
--- a/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
@@ -26,6 +26,8 @@ AST_MATCHER(Stmt, isMacroExpansion) {
   return SM.isMacroBodyExpansion(Loc) || SM.isMacroArgExpansion(Loc);
 }
 
+AST_MATCHER(Stmt, isC23) { return Finder->getASTContext().getLangOpts().C23; }
+
 bool isNULLMacroExpansion(const Stmt *Statement, ASTContext &Context) {
   SourceManager &SM = Context.getSourceManager();
   const LangOptions &LO = Context.getLangOpts();
@@ -298,6 +300,11 @@ void 
ImplicitBoolConversionCheck::registerMatchers(MatchFinder *Finder) {
  hasCastKind(CK_FloatingToBoolean),
  hasCastKind(CK_PointerToBoolean),
  hasCastKind(CK_MemberPointerToBoolean)),
+   // Exclude cases of C23 comparison result.
+   unless(allOf(
+   isC23(),
+   hasSourceExpression(binaryOperator(hasAnyOperatorName(
+   ">", ">=", "==", "!=", "<", "<="),
// Exclude case of using if or while statements with 
variable
// declaration, e.g.:
//   if (int var = functionCall()) {}
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index a9b1ab367f538a..e42082806fd308 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -244,7 +244,8 @@ Changes in existing checks
 - Improved :doc:`readability-implicit-bool-conversion
   ` check
   by adding the option `UseUpperCaseLiteralSuffix` to select the
-  case of the literal suffix in fixes.
+  case of the literal suffix in fixes and fixing false positive for implicit
+  conversion of comparison result in C23.
 
 - Improved :doc:`readability-redundant-smartptr-get
   ` check to
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion.c
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion.c
index f3dc32c10d640a..0b231d10adf8fc 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion.c
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion.c
@@ -304,6 +304,15 @@ void 
implicitConversionToBoolFromUnaryMinusAndZeroLiterals() {
   // CHECK-FIXES: functionTakingBool((-0.0) != 0.0);
 }
 
+void ignoreImplicitCastToBoolForComparisonResult() {
+  bool boolFromComparison0 = 1 != 0;
+  bool boolFromComparison1 = 1 == 0;
+  bool boolFromComparison2 = 1 > 0;
+  bool boolFromComparison3 = 1 >= 0;
+  bool boolFromComparison4 = 1 < 0;
+  bool boolFromComparison5 = 1 <= 0;
+}
+
 void ignoreExplicitCastsToBool() {
   int integer = 10;
   bool boolComingFromInt = (bool)integer;

``




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


[clang] [clang-format] Print the names of unfound files in error messages (PR #113640)

2024-10-24 Thread Owen Pan via cfe-commits

https://github.com/owenca created 
https://github.com/llvm/llvm-project/pull/113640

Fixes #113631.

>From 274b7cbdd8989c9f34c3df4041fa9098857bcc89 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Thu, 24 Oct 2024 20:05:52 -0700
Subject: [PATCH] [clang-format] Print the names of unfound files in error
 messages

Fixes #113631.
---
 clang/test/Format/error-unfound-files.cpp | 7 +++
 clang/tools/clang-format/ClangFormat.cpp  | 2 +-
 2 files changed, 8 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/Format/error-unfound-files.cpp

diff --git a/clang/test/Format/error-unfound-files.cpp 
b/clang/test/Format/error-unfound-files.cpp
new file mode 100644
index 00..3923c8d097443c
--- /dev/null
+++ b/clang/test/Format/error-unfound-files.cpp
@@ -0,0 +1,7 @@
+// RUN: rm -f a.c b.c
+
+// RUN: not clang-format a.c b.c 2>&1 | FileCheck %s
+// CHECK: a.c:
+// CHECK-NEXT: b.c:
+
+// rm -f a.c b.c
diff --git a/clang/tools/clang-format/ClangFormat.cpp 
b/clang/tools/clang-format/ClangFormat.cpp
index 96fb85e99bf5f0..7c54462b3795dd 100644
--- a/clang/tools/clang-format/ClangFormat.cpp
+++ b/clang/tools/clang-format/ClangFormat.cpp
@@ -419,7 +419,7 @@ static bool format(StringRef FileName, bool 
ErrorOnIncompleteFormat = false) {
   ? MemoryBuffer::getFileAsStream(FileName)
   : MemoryBuffer::getFileOrSTDIN(FileName, /*IsText=*/true);
   if (std::error_code EC = CodeOrErr.getError()) {
-errs() << EC.message() << "\n";
+errs() << FileName << ": " << EC.message() << "\n";
 return true;
   }
   std::unique_ptr Code = std::move(CodeOrErr.get());

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


[clang-tools-extra] [clang-tidy] fix false positive for implicit conversion of comparison result in C23 (PR #113639)

2024-10-24 Thread via cfe-commits

llvmbot wrote:




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

Author: Congcong Cai (HerrCai0907)


Changes

Fixed #111013
bool will be builtin type in C23 but comparison result in C is still int.
It is no need to change this kind of implicit cast to explicit cast.


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


3 Files Affected:

- (modified) 
clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp (+7) 
- (modified) clang-tools-extra/docs/ReleaseNotes.rst (+2-1) 
- (modified) 
clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion.c
 (+9) 


``diff
diff --git 
a/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
index 968a4a55a6d798..06415c1346a4f0 100644
--- a/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
@@ -26,6 +26,8 @@ AST_MATCHER(Stmt, isMacroExpansion) {
   return SM.isMacroBodyExpansion(Loc) || SM.isMacroArgExpansion(Loc);
 }
 
+AST_MATCHER(Stmt, isC23) { return Finder->getASTContext().getLangOpts().C23; }
+
 bool isNULLMacroExpansion(const Stmt *Statement, ASTContext &Context) {
   SourceManager &SM = Context.getSourceManager();
   const LangOptions &LO = Context.getLangOpts();
@@ -298,6 +300,11 @@ void 
ImplicitBoolConversionCheck::registerMatchers(MatchFinder *Finder) {
  hasCastKind(CK_FloatingToBoolean),
  hasCastKind(CK_PointerToBoolean),
  hasCastKind(CK_MemberPointerToBoolean)),
+   // Exclude cases of C23 comparison result.
+   unless(allOf(
+   isC23(),
+   hasSourceExpression(binaryOperator(hasAnyOperatorName(
+   ">", ">=", "==", "!=", "<", "<="),
// Exclude case of using if or while statements with 
variable
// declaration, e.g.:
//   if (int var = functionCall()) {}
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index a9b1ab367f538a..e42082806fd308 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -244,7 +244,8 @@ Changes in existing checks
 - Improved :doc:`readability-implicit-bool-conversion
   ` check
   by adding the option `UseUpperCaseLiteralSuffix` to select the
-  case of the literal suffix in fixes.
+  case of the literal suffix in fixes and fixing false positive for implicit
+  conversion of comparison result in C23.
 
 - Improved :doc:`readability-redundant-smartptr-get
   ` check to
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion.c
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion.c
index f3dc32c10d640a..0b231d10adf8fc 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion.c
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion.c
@@ -304,6 +304,15 @@ void 
implicitConversionToBoolFromUnaryMinusAndZeroLiterals() {
   // CHECK-FIXES: functionTakingBool((-0.0) != 0.0);
 }
 
+void ignoreImplicitCastToBoolForComparisonResult() {
+  bool boolFromComparison0 = 1 != 0;
+  bool boolFromComparison1 = 1 == 0;
+  bool boolFromComparison2 = 1 > 0;
+  bool boolFromComparison3 = 1 >= 0;
+  bool boolFromComparison4 = 1 < 0;
+  bool boolFromComparison5 = 1 <= 0;
+}
+
 void ignoreExplicitCastsToBool() {
   int integer = 10;
   bool boolComingFromInt = (bool)integer;

``




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


[clang-tools-extra] [clang-tidy] fix false positive for implicit conversion of comparison result in C23 (PR #113639)

2024-10-24 Thread Congcong Cai via cfe-commits

https://github.com/HerrCai0907 created 
https://github.com/llvm/llvm-project/pull/113639

Fixed #111013
bool will be builtin type in C23 but comparison result in C is still int.
It is no need to change this kind of implicit cast to explicit cast.


>From 53ff1325281e37b164abc8705f2d75d7caeec3a4 Mon Sep 17 00:00:00 2001
From: Congcong Cai 
Date: Fri, 25 Oct 2024 11:07:14 +0800
Subject: [PATCH] [clang-tidy] fix false positive for implicit conversion of
 comparison result in C23

Fixed #111013
bool will be builtin type in C23 but comparison result in C is still int.
It is no need to change this kind of implicit cast to explicit cast.
---
 .../readability/ImplicitBoolConversionCheck.cpp  | 7 +++
 clang-tools-extra/docs/ReleaseNotes.rst  | 3 ++-
 .../checkers/readability/implicit-bool-conversion.c  | 9 +
 3 files changed, 18 insertions(+), 1 deletion(-)

diff --git 
a/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
index 968a4a55a6d798..06415c1346a4f0 100644
--- a/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/ImplicitBoolConversionCheck.cpp
@@ -26,6 +26,8 @@ AST_MATCHER(Stmt, isMacroExpansion) {
   return SM.isMacroBodyExpansion(Loc) || SM.isMacroArgExpansion(Loc);
 }
 
+AST_MATCHER(Stmt, isC23) { return Finder->getASTContext().getLangOpts().C23; }
+
 bool isNULLMacroExpansion(const Stmt *Statement, ASTContext &Context) {
   SourceManager &SM = Context.getSourceManager();
   const LangOptions &LO = Context.getLangOpts();
@@ -298,6 +300,11 @@ void 
ImplicitBoolConversionCheck::registerMatchers(MatchFinder *Finder) {
  hasCastKind(CK_FloatingToBoolean),
  hasCastKind(CK_PointerToBoolean),
  hasCastKind(CK_MemberPointerToBoolean)),
+   // Exclude cases of C23 comparison result.
+   unless(allOf(
+   isC23(),
+   hasSourceExpression(binaryOperator(hasAnyOperatorName(
+   ">", ">=", "==", "!=", "<", "<="),
// Exclude case of using if or while statements with 
variable
// declaration, e.g.:
//   if (int var = functionCall()) {}
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index a9b1ab367f538a..e42082806fd308 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -244,7 +244,8 @@ Changes in existing checks
 - Improved :doc:`readability-implicit-bool-conversion
   ` check
   by adding the option `UseUpperCaseLiteralSuffix` to select the
-  case of the literal suffix in fixes.
+  case of the literal suffix in fixes and fixing false positive for implicit
+  conversion of comparison result in C23.
 
 - Improved :doc:`readability-redundant-smartptr-get
   ` check to
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion.c
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion.c
index f3dc32c10d640a..0b231d10adf8fc 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion.c
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/implicit-bool-conversion.c
@@ -304,6 +304,15 @@ void 
implicitConversionToBoolFromUnaryMinusAndZeroLiterals() {
   // CHECK-FIXES: functionTakingBool((-0.0) != 0.0);
 }
 
+void ignoreImplicitCastToBoolForComparisonResult() {
+  bool boolFromComparison0 = 1 != 0;
+  bool boolFromComparison1 = 1 == 0;
+  bool boolFromComparison2 = 1 > 0;
+  bool boolFromComparison3 = 1 >= 0;
+  bool boolFromComparison4 = 1 < 0;
+  bool boolFromComparison5 = 1 <= 0;
+}
+
 void ignoreExplicitCastsToBool() {
   int integer = 10;
   bool boolComingFromInt = (bool)integer;

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


[clang] [clang-format] Print the names of unfound files in error messages (PR #113640)

2024-10-24 Thread Owen Pan via cfe-commits

https://github.com/owenca updated 
https://github.com/llvm/llvm-project/pull/113640

>From 274b7cbdd8989c9f34c3df4041fa9098857bcc89 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Thu, 24 Oct 2024 20:05:52 -0700
Subject: [PATCH 1/2] [clang-format] Print the names of unfound files in error
 messages

Fixes #113631.
---
 clang/test/Format/error-unfound-files.cpp | 7 +++
 clang/tools/clang-format/ClangFormat.cpp  | 2 +-
 2 files changed, 8 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/Format/error-unfound-files.cpp

diff --git a/clang/test/Format/error-unfound-files.cpp 
b/clang/test/Format/error-unfound-files.cpp
new file mode 100644
index 00..3923c8d097443c
--- /dev/null
+++ b/clang/test/Format/error-unfound-files.cpp
@@ -0,0 +1,7 @@
+// RUN: rm -f a.c b.c
+
+// RUN: not clang-format a.c b.c 2>&1 | FileCheck %s
+// CHECK: a.c:
+// CHECK-NEXT: b.c:
+
+// rm -f a.c b.c
diff --git a/clang/tools/clang-format/ClangFormat.cpp 
b/clang/tools/clang-format/ClangFormat.cpp
index 96fb85e99bf5f0..7c54462b3795dd 100644
--- a/clang/tools/clang-format/ClangFormat.cpp
+++ b/clang/tools/clang-format/ClangFormat.cpp
@@ -419,7 +419,7 @@ static bool format(StringRef FileName, bool 
ErrorOnIncompleteFormat = false) {
   ? MemoryBuffer::getFileAsStream(FileName)
   : MemoryBuffer::getFileOrSTDIN(FileName, /*IsText=*/true);
   if (std::error_code EC = CodeOrErr.getError()) {
-errs() << EC.message() << "\n";
+errs() << FileName << ": " << EC.message() << "\n";
 return true;
   }
   std::unique_ptr Code = std::move(CodeOrErr.get());

>From 0a92c3df1497baf40b6ceb293d91a8eb26b1f753 Mon Sep 17 00:00:00 2001
From: Owen Pan 
Date: Thu, 24 Oct 2024 20:14:28 -0700
Subject: [PATCH 2/2] Update error-unfound-files.cpp

---
 clang/test/Format/error-unfound-files.cpp | 2 --
 1 file changed, 2 deletions(-)

diff --git a/clang/test/Format/error-unfound-files.cpp 
b/clang/test/Format/error-unfound-files.cpp
index 3923c8d097443c..1cc57ed064fb42 100644
--- a/clang/test/Format/error-unfound-files.cpp
+++ b/clang/test/Format/error-unfound-files.cpp
@@ -3,5 +3,3 @@
 // RUN: not clang-format a.c b.c 2>&1 | FileCheck %s
 // CHECK: a.c:
 // CHECK-NEXT: b.c:
-
-// rm -f a.c b.c

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


[clang] [llvm] [DXIL][SPIRV] Lower WaveActiveCountBits intrinsic (PR #113382)

2024-10-24 Thread Greg Roth via cfe-commits


@@ -1762,6 +1765,36 @@ bool SPIRVInstructionSelector::selectSign(Register 
ResVReg,
   return Result;
 }
 
+bool SPIRVInstructionSelector::selectWaveActiveCountBits(
+Register ResVReg, const SPIRVType *ResType, MachineInstr &I) const {
+  assert(I.getNumOperands() == 3);
+  assert(I.getOperand(2).isReg());
+  MachineBasicBlock &BB = *I.getParent();
+
+  Register BallotReg = MRI->createVirtualRegister(&SPIRV::IDRegClass);
+  SPIRVType *IntTy = GR.getOrCreateSPIRVIntegerType(32, I, TII);
+  SPIRVType *BallotType = GR.getOrCreateSPIRVVectorType(IntTy, 4, I, TII);
+
+  bool Result =
+  BuildMI(BB, I, I.getDebugLoc(), TII.get(SPIRV::OpGroupNonUniformBallot))
+  .addDef(BallotReg)
+  .addUse(GR.getSPIRVTypeID(BallotType))
+  .addUse(GR.getOrCreateConstInt(SPIRV::Scope::Subgroup, I, IntTy, 
TII))
+  .addUse(I.getOperand(2).getReg());

pow2clk wrote:

You're missing a `constrainAllUses` call on the end here. `AddUse` returns a 
reference to `MachineInstrBuilder`, which I'm not really sure how gets 
converted to a bool, but I don't want to rely on it. 

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


[clang] [clang-format] Print the names of unfound files in error messages (PR #113640)

2024-10-24 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-format

Author: Owen Pan (owenca)


Changes

Fixes #113631.

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


2 Files Affected:

- (added) clang/test/Format/error-unfound-files.cpp (+7) 
- (modified) clang/tools/clang-format/ClangFormat.cpp (+1-1) 


``diff
diff --git a/clang/test/Format/error-unfound-files.cpp 
b/clang/test/Format/error-unfound-files.cpp
new file mode 100644
index 00..3923c8d097443c
--- /dev/null
+++ b/clang/test/Format/error-unfound-files.cpp
@@ -0,0 +1,7 @@
+// RUN: rm -f a.c b.c
+
+// RUN: not clang-format a.c b.c 2>&1 | FileCheck %s
+// CHECK: a.c:
+// CHECK-NEXT: b.c:
+
+// rm -f a.c b.c
diff --git a/clang/tools/clang-format/ClangFormat.cpp 
b/clang/tools/clang-format/ClangFormat.cpp
index 96fb85e99bf5f0..7c54462b3795dd 100644
--- a/clang/tools/clang-format/ClangFormat.cpp
+++ b/clang/tools/clang-format/ClangFormat.cpp
@@ -419,7 +419,7 @@ static bool format(StringRef FileName, bool 
ErrorOnIncompleteFormat = false) {
   ? MemoryBuffer::getFileAsStream(FileName)
   : MemoryBuffer::getFileOrSTDIN(FileName, /*IsText=*/true);
   if (std::error_code EC = CodeOrErr.getError()) {
-errs() << EC.message() << "\n";
+errs() << FileName << ": " << EC.message() << "\n";
 return true;
   }
   std::unique_ptr Code = std::move(CodeOrErr.get());

``




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


[clang] [flang] [flang] Add UNSIGNED (PR #113504)

2024-10-24 Thread Peter Klausler via cfe-commits


@@ -0,0 +1,116 @@
+
+
+# Fortran Extensions supported by Flang
+
+```{contents}
+---
+local:
+---
+```
+
+For better compatibility with GNU Fortran and Sun Fortran,
+this compiler supports an option (`-funsigned`) that enables
+the `UNSIGNED` data type, constants, intrinsic functions,
+its use with intrinsic operations and `SELECT CASE`, and C
+language interoperability.
+
+## `UNSIGNED` type
+
+`UNSIGNED` is a numeric type with the same kinds as `INTEGER`.
+It may appear as a type-spec in any context, including
+a type declaration statement, a type-decl in an array
+constructor or `ALLOCATE` statement, `IMPLICIT`, or a
+function statement's prefix.
+
+`UNSIGNED` constants are nonempty strings of decimal digits
+followed by the letter `U` and optionally a kind suffix with
+an underscore.
+
+## `UNSIGNED` operations
+
+`UNSIGNED` operands are accepted for unary negation (`-`),
+the basic four binary arithmetic intrinsic operations `+`, `-`, `*`, and `/`,
+and for numeric relational operators.
+The power operator `**` does not accept `UNSIGNED` operands.
+
+Mixed operations with other types are not allowed.
+Mixed operations with one `UNSIGNED` operand and one BOZ literal
+constant operand are allowed.
+When the operands' kinds differ, the smaller operand is zero-extended
+to the size of the larger.
+
+The arithmetic operations `u+v`, `-u`, `u-v`, and `u*v` are implemented
+modulo `MAX(HUGE(u),HUGE(v))+1`;
+informally speaking, they always truncate their results, or are
+guaranteed to "wrap".
+
+## `UNSIGNED` intrinsic functions
+
+`UNSIGNED` operands are accepted as operands to,
+or may be returned as results from,
+several intrinsic procedures.
+
+Bitwise operations:
+* `NOT`
+* `IAND`, `IOR`, `IEOR`, `IBCLR`, `IBSET`, `IBITS`, `MERGE_BITS`
+* `BTEST`
+* `ISHFT`, `ISHFTC`
+* `SHIFTA`, `SHIFTL`, `SHIFTR`
+* `TRANSFER`
+* `MVBITS`
+
+The existing unsigned comparisons `BLT`, `BLE`, `BGE`, and `BGT`.
+
+The inquiries `BIT_SIZE`, `DIGITS`, `HUGE`, and `RANGE`.
+
+Homogeneous `MAX` and `MIN`.

klausler wrote:

It means that `MAX` and `MIN` should support `UNSIGNED` arguments, but only 
when all of the arguments are `UNSIGNED`.  Mixed arguments with `UNSIGNED` 
combined with `REAL` or other types should not work.

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


[clang] [llvm] [LoongArch] Support LoongArch-specific amswap[_db].{b/h} and amadd[_db].{b/h} instructions (PR #113255)

2024-10-24 Thread Lu Weining via cfe-commits

SixWeining wrote:

> Just a heads up, I think this broke documentation builds. After bisecting it 
> points to this commit.

Thanks. Fixed by #113632.

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


[clang] [HLSL] Add Append/ConsumeStructuredBuffer definitions to HLSLExternalSemaSource (PR #113643)

2024-10-24 Thread Helena Kotas via cfe-commits

https://github.com/hekota updated 
https://github.com/llvm/llvm-project/pull/113643

>From 497d0f2c2d0c84603f3b3434aaee0e23722cd701 Mon Sep 17 00:00:00 2001
From: Helena Kotas 
Date: Thu, 24 Oct 2024 20:32:28 -0700
Subject: [PATCH 1/2] [HLSL] Add AppendStructuredBuffer and
 ConsumeStructuredBuffer to HLSLExternalSemaSource

Add separate tests for the AST shape and element types. Add 
constructor/handle.fromBinding test case to shared test file.
These buffers do not have any subscript operators. Append and Consume methods 
will be added later in llvm/llvm-project#112968.

Fixes #112777
---
 clang/lib/Sema/HLSLExternalSemaSource.cpp | 22 
 .../AST/HLSL/AppendStructuredBuffer-AST.hlsl  | 50 +
 .../AST/HLSL/ConsumeStructuredBuffer-AST.hlsl | 51 ++
 .../AppendStructuredBuffer-elementtype.hlsl   | 53 +++
 .../ConsumeStructuredBuffer-elementtype.hlsl  | 53 +++
 .../StructuredBuffers-constructors.hlsl   | 23 +++-
 6 files changed, 250 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/AST/HLSL/AppendStructuredBuffer-AST.hlsl
 create mode 100644 clang/test/AST/HLSL/ConsumeStructuredBuffer-AST.hlsl
 create mode 100644 
clang/test/CodeGenHLSL/builtins/AppendStructuredBuffer-elementtype.hlsl
 create mode 100644 
clang/test/CodeGenHLSL/builtins/ConsumeStructuredBuffer-elementtype.hlsl

diff --git a/clang/lib/Sema/HLSLExternalSemaSource.cpp 
b/clang/lib/Sema/HLSLExternalSemaSource.cpp
index ce8564429b3802..22ca9f72d40a30 100644
--- a/clang/lib/Sema/HLSLExternalSemaSource.cpp
+++ b/clang/lib/Sema/HLSLExternalSemaSource.cpp
@@ -530,6 +530,28 @@ void 
HLSLExternalSemaSource::defineHLSLTypesWithForwardDeclarations() {
 .addArraySubscriptOperators()
 .completeDefinition();
   });
+
+  Decl =
+  BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace, "AppendStructuredBuffer")
+  .addSimpleTemplateParams(*SemaPtr, {"element_type"})
+  .Record;
+  onCompletion(Decl, [this](CXXRecordDecl *Decl) {
+setupBufferType(Decl, *SemaPtr, ResourceClass::UAV,
+ResourceKind::TypedBuffer, /*IsROV=*/false,
+/*RawBuffer=*/true)
+.completeDefinition();
+  });
+
+  Decl =
+  BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace, 
"ConsumeStructuredBuffer")
+  .addSimpleTemplateParams(*SemaPtr, {"element_type"})
+  .Record;
+  onCompletion(Decl, [this](CXXRecordDecl *Decl) {
+setupBufferType(Decl, *SemaPtr, ResourceClass::UAV,
+ResourceKind::TypedBuffer, /*IsROV=*/false,
+/*RawBuffer=*/true)
+.completeDefinition();
+  });
 }
 
 void HLSLExternalSemaSource::onCompletion(CXXRecordDecl *Record,
diff --git a/clang/test/AST/HLSL/AppendStructuredBuffer-AST.hlsl 
b/clang/test/AST/HLSL/AppendStructuredBuffer-AST.hlsl
new file mode 100644
index 00..6fc88cec72e3e9
--- /dev/null
+++ b/clang/test/AST/HLSL/AppendStructuredBuffer-AST.hlsl
@@ -0,0 +1,50 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-library -x hlsl -ast-dump 
-DEMPTY %s | FileCheck -check-prefix=EMPTY %s
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-library -x hlsl -ast-dump %s 
| FileCheck %s
+
+
+// This test tests two different AST generations. The "EMPTY" test mode 
verifies
+// the AST generated by forward declaration of the HLSL types which happens on
+// initializing the HLSL external AST with an AST Context.
+
+// The non-empty mode has a use that requires the AppendStructuredBuffer type 
be complete,
+// which results in the AST being populated by the external AST source. That
+// case covers the full implementation of the template declaration and the
+// instantiated specialization.
+
+// EMPTY: ClassTemplateDecl 0x{{[0-9A-Fa-f]+}} <>  
implicit AppendStructuredBuffer
+// EMPTY-NEXT: TemplateTypeParmDecl 0x{{[0-9A-Fa-f]+}} <> 
 class depth 0 index 0 element_type
+// EMPTY-NEXT: CXXRecordDecl 0x{{[0-9A-Fa-f]+}} <>  implicit  class AppendStructuredBuffer
+// EMPTY-NEXT: FinalAttr 0x{{[0-9A-Fa-f]+}} <> Implicit final
+
+// There should be no more occurrances of AppendStructuredBuffer
+// EMPTY-NOT: {{[^[:alnum:]]}}AppendStructuredBuffer
+
+#ifndef EMPTY
+
+AppendStructuredBuffer Buffer;
+
+#endif
+
+// CHECK: ClassTemplateDecl 0x{{[0-9A-Fa-f]+}} <>  
implicit AppendStructuredBuffer
+// CHECK-NEXT: TemplateTypeParmDecl 0x{{[0-9A-Fa-f]+}} <> 
 class depth 0 index 0 element_type
+// CHECK-NEXT: CXXRecordDecl 0x{{[0-9A-Fa-f]+}} <>  implicit class AppendStructuredBuffer definition
+
+// CHECK: FinalAttr 0x{{[0-9A-Fa-f]+}} <> Implicit final
+// CHECK-NEXT: FieldDecl 0x{{[0-9A-Fa-f]+}} <>  
implicit h '__hlsl_resource_t
+// CHECK-SAME{LITERAL}: [[hlsl::resource_class(UAV)]]
+// CHECK-SAME{LITERAL}: [[hlsl::raw_buffer]]
+// CHECK-SAME{LITERAL}: [[hlsl::contained_type(element_type)]]
+// CHECK-NEXT: HLSLResourceAttr 0x{{[0-9A-Fa-f]+}} <> Implicit 
TypedBuffer
+
+// CHECK-NOT: CXXMethodDecl 0x{{[0-9A-Fa-f]+}} <>  
operator[] 'element_type

[clang] [analyzer] Fix a crash from element region construction during `ArrayInitLoopExpr` analysis (PR #113570)

2024-10-24 Thread Balazs Benics via cfe-commits


@@ -513,70 +513,25 @@ ProgramStateRef 
ExprEngine::updateObjectsUnderConstruction(
 static ProgramStateRef
 bindRequiredArrayElementToEnvironment(ProgramStateRef State,
   const ArrayInitLoopExpr *AILE,
-  const LocationContext *LCtx, SVal Idx) {
-  // The ctor in this case is guaranteed to be a copy ctor, otherwise we hit a
-  // compile time error.
-  //
-  //  -ArrayInitLoopExpr<-- we're here
-  //   |-OpaqueValueExpr
-  //   | `-DeclRefExpr  <-- match this
-  //   `-CXXConstructExpr
-  // `-ImplicitCastExpr
-  //   `-ArraySubscriptExpr
-  // |-ImplicitCastExpr
-  // | `-OpaqueValueExpr
-  // |   `-DeclRefExpr
-  // `-ArrayInitIndexExpr
-  //
-  // The resulting expression might look like the one below in an implicit
-  // copy/move ctor.
-  //
-  //   ArrayInitLoopExpr<-- we're here
-  //   |-OpaqueValueExpr
-  //   | `-MemberExpr   <-- match this
-  //   |  (`-CXXStaticCastExpr) <-- move ctor only
-  //   | `-DeclRefExpr
-  //   `-CXXConstructExpr
-  // `-ArraySubscriptExpr
-  //   |-ImplicitCastExpr
-  //   | `-OpaqueValueExpr
-  //   |   `-MemberExpr
-  //   | `-DeclRefExpr
-  //   `-ArrayInitIndexExpr
-  //
-  // The resulting expression for a multidimensional array.
-  // ArrayInitLoopExpr  <-- we're here
-  // |-OpaqueValueExpr
-  // | `-DeclRefExpr<-- match this
-  // `-ArrayInitLoopExpr
-  //   |-OpaqueValueExpr
-  //   | `-ArraySubscriptExpr
-  //   |   |-ImplicitCastExpr
-  //   |   | `-OpaqueValueExpr
-  //   |   |   `-DeclRefExpr
-  //   |   `-ArrayInitIndexExpr
-  //   `-CXXConstructExpr <-- extract this
-  // ` ...
-
-  const auto *OVESrc = AILE->getCommonExpr()->getSourceExpr();
+  const LocationContext *LCtx, NonLoc Idx) 
{
+  SValBuilder &SVB = State->getStateManager().getSValBuilder();
+  MemRegionManager &MRMgr = SVB.getRegionManager();
+  ASTContext &Ctx = SVB.getContext();
 
   // HACK: There is no way we can put the index of the array element into the
   // CFG unless we unroll the loop, so we manually select and bind the required
   // parameter to the environment.
-  const auto *CE =
+  const Expr *SourceArray = AILE->getCommonExpr()->getSourceExpr();
+  const auto *Ctor =
   cast(extractElementInitializerFromNestedAILE(AILE));
 
-  SVal Base = UnknownVal();
-  if (const auto *ME = dyn_cast(OVESrc))
-Base = State->getSVal(ME, LCtx);
-  else if (const auto *DRE = dyn_cast(OVESrc))
-Base = State->getLValue(cast(DRE->getDecl()), LCtx);
-  else
-llvm_unreachable("ArrayInitLoopExpr contains unexpected source 
expression");
-
-  SVal NthElem = State->getLValue(CE->getType(), Idx, Base);
+  const SubRegion *SourceArrayRegion =

steakhal wrote:

Use const auto here as the type is already spelled in the statement.

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


[clang] [analyzer] Fix a crash from element region construction during `ArrayInitLoopExpr` analysis (PR #113570)

2024-10-24 Thread Balazs Benics via cfe-commits


@@ -330,3 +330,47 @@ void no_crash() {
 }
 
 } // namespace crash
+
+namespace array_subscript_initializer {

steakhal wrote:

Could you please put these braces on the same line of the namespace/struct 
declarations? That way its slightly more compact.

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


[clang] [analyzer] Fix a crash from element region construction during `ArrayInitLoopExpr` analysis (PR #113570)

2024-10-24 Thread Balazs Benics via cfe-commits

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


[clang] [compiler-rt] [flang] [libc] [llvm] [clang-tidy] Create bugprone-incorrect-enable-shared-from-this check (PR #102299)

2024-10-24 Thread via cfe-commits

MichelleCDjunaidi wrote:

that's strange, I invoked git rebase with origin/main though. but will redo.

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


[clang] [clang-format] add MaxSingleLinesInBracedList style option (PR #112482)

2024-10-24 Thread Owen Pan via cfe-commits

owenca wrote:

> There will be bugs if/when people use this option with small values for the 
> limit, as it will interact weirdly with both the braced list initializer 
> formatting rules, and also with the `AvoidBinPacking` logic of the 
> continuation indenter.

Can you give some examples?



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


[clang] [LoongArch] fix description of clang option -m[no-]lam-bh (PR #113632)

2024-10-24 Thread Lu Weining via cfe-commits

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


[clang-tools-extra] [clang-tidy] Create bugprone-incorrect-enable-shared-from-this check (PR #102299)

2024-10-24 Thread via cfe-commits

MichelleCDjunaidi wrote:

@EugeneZelenko thanks for the pointers; didn't realize git fetch did not update 
local main. does this look fine now?

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


[clang] [LoongArch] fix description of clang option -m[no-]lam-bh (PR #113632)

2024-10-24 Thread LLVM Continuous Integration via cfe-commits

llvm-ci wrote:

LLVM Buildbot has detected a new failure on builder `lldb-aarch64-ubuntu` 
running on `linaro-lldb-aarch64-ubuntu` while building `clang` at step 6 "test".

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


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

```
Step 6 (test) failure: build (failure)
...
PASS: lldb-unit :: ValueObject/./LLDBValueObjectTests/1/3 (2033 of 2042)
PASS: lldb-unit :: Utility/./UtilityTests/7/8 (2034 of 2042)
PASS: lldb-unit :: ValueObject/./LLDBValueObjectTests/2/3 (2035 of 2042)
PASS: lldb-unit :: tools/lldb-server/tests/./LLDBServerTests/1/2 (2036 of 2042)
PASS: lldb-unit :: tools/lldb-server/tests/./LLDBServerTests/0/2 (2037 of 2042)
PASS: lldb-unit :: Host/./HostTests/11/12 (2038 of 2042)
PASS: lldb-unit :: Target/./TargetTests/11/14 (2039 of 2042)
PASS: lldb-unit :: Host/./HostTests/3/12 (2040 of 2042)
PASS: lldb-unit :: Process/gdb-remote/./ProcessGdbRemoteTests/8/9 (2041 of 2042)
UNRESOLVED: lldb-api :: tools/lldb-server/TestLldbGdbServer.py (2042 of 2042)
 TEST 'lldb-api :: tools/lldb-server/TestLldbGdbServer.py' 
FAILED 
Script:
--
/usr/bin/python3.10 
/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/llvm-project/lldb/test/API/dotest.py
 -u CXXFLAGS -u CFLAGS --env 
LLVM_LIBS_DIR=/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/./lib --env 
LLVM_INCLUDE_DIR=/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/include 
--env LLVM_TOOLS_DIR=/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/./bin 
--arch aarch64 --build-dir 
/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/lldb-test-build.noindex 
--lldb-module-cache-dir 
/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/lldb-test-build.noindex/module-cache-lldb/lldb-api
 --clang-module-cache-dir 
/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/lldb-test-build.noindex/module-cache-clang/lldb-api
 --executable /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/./bin/lldb 
--compiler /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/./bin/clang 
--dsymutil /home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/./bin/dsymutil 
--make /usr/bin/make --llvm-tools-dir 
/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/./bin --lldb-obj-root 
/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/tools/lldb --lldb-libs-dir 
/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/./lib 
/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/llvm-project/lldb/test/API/tools/lldb-server
 -p TestLldbGdbServer.py
--
Exit Code: 1

Command Output (stdout):
--
lldb version 20.0.0git (https://github.com/llvm/llvm-project.git revision 
ce858e2127beb7e8f5780996d5a87994fbad39d4)
  clang revision ce858e2127beb7e8f5780996d5a87994fbad39d4
  llvm revision ce858e2127beb7e8f5780996d5a87994fbad39d4
Skipping the following test categories: ['libc++', 'dsym', 'gmodules', 
'debugserver', 'objc']

--
Command Output (stderr):
--
UNSUPPORTED: LLDB 
(/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/bin/clang-aarch64) :: 
test_Hc_then_Csignal_signals_correct_thread_launch_debugserver 
(TestLldbGdbServer.LldbGdbServerTestCase) (test case does not fall in any 
category of interest for this run) 
PASS: LLDB 
(/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/bin/clang-aarch64) :: 
test_Hc_then_Csignal_signals_correct_thread_launch_llgs 
(TestLldbGdbServer.LldbGdbServerTestCase)
PASS: LLDB 
(/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/bin/clang-aarch64) :: 
test_Hg_fails_on_another_pid_llgs (TestLldbGdbServer.LldbGdbServerTestCase)
PASS: LLDB 
(/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/bin/clang-aarch64) :: 
test_Hg_fails_on_minus_one_pid_llgs (TestLldbGdbServer.LldbGdbServerTestCase)
PASS: LLDB 
(/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/bin/clang-aarch64) :: 
test_Hg_fails_on_zero_pid_llgs (TestLldbGdbServer.LldbGdbServerTestCase)
UNSUPPORTED: LLDB 
(/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/bin/clang-aarch64) :: 
test_Hg_switches_to_3_threads_launch_debugserver 
(TestLldbGdbServer.LldbGdbServerTestCase) (test case does not fall in any 
category of interest for this run) 
PASS: LLDB 
(/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/bin/clang-aarch64) :: 
test_Hg_switches_to_3_threads_launch_llgs 
(TestLldbGdbServer.LldbGdbServerTestCase)
UNSUPPORTED: LLDB 
(/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/bin/clang-aarch64) :: 
test_P_and_p_thread_suffix_work_debugserver 
(TestLldbGdbServer.LldbGdbServerTestCase) (test case does not fall in any 
category of interest for this run) 
PASS: LLDB 
(/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/bin/clang-aarch64) :: 
test_P_and_p_thread_suffix_work_llgs (TestLldbGdbServer.LldbGdbServerTestCase)
UNSUPPORTED: LLDB 
(/home/tcwg-buildbot/worker/lldb-aarch64-ubuntu/build/bin/clang-aarch64) :: 
test_P_writes_all_gpr_registers_debugserver 
(TestLldbGdbServer.LldbGdbServerTestCase) (test case does not fall in any 
category of interest for this r

[clang] Emit constrained atan2 intrinsic for clang builtin (PR #113636)

2024-10-24 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 c03d09ce3eed336fea4d9283232383f6d4d4057d 
b5a4c777280873e9827bb812b95cad32fbf6b7f4 --extensions cpp,c -- 
clang/lib/CodeGen/CGBuiltin.cpp clang/test/CodeGen/X86/math-builtins.c 
clang/test/CodeGen/constrained-math-builtins.c clang/test/CodeGen/libcalls.c 
clang/test/CodeGen/math-libcalls.c 
clang/test/CodeGenCXX/builtin-calling-conv.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 0bec8f3255..c420b473b1 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -2733,7 +2733,8 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
 case Builtin::BI__builtin_atan2l:
 case Builtin::BI__builtin_atan2f128:
   return RValue::get(emitBinaryMaybeConstrainedFPBuiltin(
-  *this, E, Intrinsic::atan2, 
Intrinsic::experimental_constrained_atan2));
+  *this, E, Intrinsic::atan2,
+  Intrinsic::experimental_constrained_atan2));
 
 case Builtin::BIceil:
 case Builtin::BIceilf:

``




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


[clang] [WebKit Checkers] Allow a guardian CheckedPtr/CheckedRef (PR #110222)

2024-10-24 Thread Rashmi Mudduluru via cfe-commits


@@ -56,7 +60,8 @@ bool tryToFindPtrOrigin(
   if (StopAtFirstRefCountedObj) {
 if (auto *ConversionFunc =
 dyn_cast_or_null(cast->getConversionFunction())) 
{
-  if (isCtorOfRefCounted(ConversionFunc))
+  if (isCtorOfRefCounted(ConversionFunc) ||
+  isCtorOfCheckedPtr(ConversionFunc))

t-rasmud wrote:

Could this also be refactored into a function (say `isSafeCtor`) like 
`isSafePtr`?

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


[clang-tools-extra] [clang-tidy] Create bugprone-incorrect-enable-shared-from-this check (PR #102299)

2024-10-24 Thread via cfe-commits

EugeneZelenko wrote:

As far as I see from branch's history, it's still outdated `main` (as of 
September 9).

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


[clang] [HLSL] Add RasterizerOrderedStructuredBuffer definition to HLSLExternalSemaSource (PR #113648)

2024-10-24 Thread Helena Kotas via cfe-commits

https://github.com/hekota created 
https://github.com/llvm/llvm-project/pull/113648

Adds `RasterizerOrderedStructuredBuffer` definition to HLSLExternalSemaSource. 
Adds separate tests for the AST shape and element types. Adds 
constructor/handle.fromBinding and subscript test cases to shared test file for 
structured buffers. Additional methods will be added later.

Fixes #112776

>From b8a47223444e72f2a6759178de15f6d1a13dff99 Mon Sep 17 00:00:00 2001
From: Helena Kotas 
Date: Thu, 24 Oct 2024 21:22:32 -0700
Subject: [PATCH] [HLSL] Add RasterizerOrderedStructuredBuffer definition to
 HLSLExternalSemaSource

Adds RasterizerOrderedStructuredBuffer definition to HLSLExternalSemaSource. 
Adds separate tests for the AST shape and element types. Adds 
constructor/handle.fromBinding and subscript test cases to shared test file for 
structured buffers.
Additional methods will be added later.

Fixes #112776
---
 clang/lib/Sema/HLSLExternalSemaSource.cpp | 12 
 ...RasterizerOrderedStructuredBuffer-AST.hlsl | 66 +
 ...erOrderedStructuredBuffer-elementtype.hlsl | 70 +++
 .../StructuredBuffers-constructors.hlsl   |  9 +++
 .../StructuredBuffers-subscripts.hlsl |  6 +-
 5 files changed, 161 insertions(+), 2 deletions(-)
 create mode 100644 
clang/test/AST/HLSL/RasterizerOrderedStructuredBuffer-AST.hlsl
 create mode 100644 
clang/test/CodeGenHLSL/builtins/RasterizerOrderedStructuredBuffer-elementtype.hlsl

diff --git a/clang/lib/Sema/HLSLExternalSemaSource.cpp 
b/clang/lib/Sema/HLSLExternalSemaSource.cpp
index ce8564429b3802..f3a0ff5dd852be 100644
--- a/clang/lib/Sema/HLSLExternalSemaSource.cpp
+++ b/clang/lib/Sema/HLSLExternalSemaSource.cpp
@@ -530,6 +530,18 @@ void 
HLSLExternalSemaSource::defineHLSLTypesWithForwardDeclarations() {
 .addArraySubscriptOperators()
 .completeDefinition();
   });
+
+  Decl = BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace,
+"RasterizerOrderedStructuredBuffer")
+ .addSimpleTemplateParams(*SemaPtr, {"element_type"})
+ .Record;
+  onCompletion(Decl, [this](CXXRecordDecl *Decl) {
+setupBufferType(Decl, *SemaPtr, ResourceClass::UAV,
+ResourceKind::TypedBuffer, /*IsROV=*/true,
+/*RawBuffer=*/true)
+.addArraySubscriptOperators()
+.completeDefinition();
+  });
 }
 
 void HLSLExternalSemaSource::onCompletion(CXXRecordDecl *Record,
diff --git a/clang/test/AST/HLSL/RasterizerOrderedStructuredBuffer-AST.hlsl 
b/clang/test/AST/HLSL/RasterizerOrderedStructuredBuffer-AST.hlsl
new file mode 100644
index 00..f334e1bb6db3fc
--- /dev/null
+++ b/clang/test/AST/HLSL/RasterizerOrderedStructuredBuffer-AST.hlsl
@@ -0,0 +1,66 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-library -x hlsl -ast-dump 
-DEMPTY %s | FileCheck -check-prefix=EMPTY %s
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-library -x hlsl -ast-dump %s 
| FileCheck %s
+
+
+// This test tests two different AST generations. The "EMPTY" test mode 
verifies
+// the AST generated by forward declaration of the HLSL types which happens on
+// initializing the HLSL external AST with an AST Context.
+
+// The non-empty mode has a use that requires the 
RasterizerOrderedStructuredBuffer type be complete,
+// which results in the AST being populated by the external AST source. That
+// case covers the full implementation of the template declaration and the
+// instantiated specialization.
+
+// EMPTY: ClassTemplateDecl 0x{{[0-9A-Fa-f]+}} <>  
implicit RasterizerOrderedStructuredBuffer
+// EMPTY-NEXT: TemplateTypeParmDecl 0x{{[0-9A-Fa-f]+}} <> 
 class depth 0 index 0 element_type
+// EMPTY-NEXT: CXXRecordDecl 0x{{[0-9A-Fa-f]+}} <>  implicit  class 
RasterizerOrderedStructuredBuffer
+// EMPTY-NEXT: FinalAttr 0x{{[0-9A-Fa-f]+}} <> Implicit final
+
+// There should be no more occurrences of RasterizerOrderedStructuredBuffer
+// EMPTY-NOT: {{[^[:alnum:]]}}RasterizerOrderedStructuredBuffer
+
+#ifndef EMPTY
+
+RasterizerOrderedStructuredBuffer Buffer;
+
+#endif
+
+// CHECK: ClassTemplateDecl 0x{{[0-9A-Fa-f]+}} <>  
implicit RasterizerOrderedStructuredBuffer
+// CHECK-NEXT: TemplateTypeParmDecl 0x{{[0-9A-Fa-f]+}} <> 
 class depth 0 index 0 element_type
+// CHECK-NEXT: CXXRecordDecl 0x{{[0-9A-Fa-f]+}} <>  implicit class RasterizerOrderedStructuredBuffer definition
+
+// CHECK: FinalAttr 0x{{[0-9A-Fa-f]+}} <> Implicit final
+// CHECK-NEXT: FieldDecl 0x{{[0-9A-Fa-f]+}} <>  
implicit h '__hlsl_resource_t
+// CHECK-SAME{LITERAL}: [[hlsl::resource_class(UAV)]]
+// CHECK-SAME{LITERAL}: [[hlsl::is_rov]]
+// CHECK-SAME{LITERAL}: [[hlsl::raw_buffer]]
+// CHECK-SAME{LITERAL}: [[hlsl::contained_type(element_type)]]
+// CHECK-NEXT: HLSLResourceAttr 0x{{[0-9A-Fa-f]+}} <> Implicit 
TypedBuffer
+
+// CHECK: CXXMethodDecl 0x{{[0-9A-Fa-f]+}} <>  
operator[] 'element_type &const (unsigned int) const'
+// CHECK-NEXT: ParmVarDecl 0x{{[0-9A-Fa-f]+}} <>  
Idx 'unsigned int'
+// CHECK-N

[clang] [llvm] [BPF] Add load-acquire and store-release instructions under -mcpu=v4 (PR #108636)

2024-10-24 Thread Peilin Ye via cfe-commits


@@ -48,6 +48,13 @@ def BPF_END  : BPFArithOp<0xd>;
 def BPF_XCHG: BPFArithOp<0xe>;
 def BPF_CMPXCHG : BPFArithOp<0xf>;
 
+class BPFAtomicLoadStoreOp val> {
+  bits<4> Value = val;
+}
+
+def BPF_LOAD_ACQ : BPFAtomicLoadStoreOp<0x1>;
+def BPF_STORE_REL : BPFAtomicLoadStoreOp<0xb>;

peilin-ye wrote:

@yonghong-song, my thinking was:

Right now for `BPF_ATOMIC` insns, we use a subset of `BPFArithOp<>` in `imm`:
```
def BPF_ADD  : BPFArithOp<0x0>;
def BPF_OR   : BPFArithOp<0x4>;
def BPF_AND  : BPFArithOp<0x5>;
def BPF_XOR  : BPFArithOp<0xa>;
def BPF_XCHG: BPFArithOp<0xe>;
def BPF_CMPXCHG : BPFArithOp<0xf>;
```
Will we ever want to support other `BPFArithOp<>` ops in `BPF_ATOMIC` ?  Like, 
`0x1` is `BPF_SUB`, but it looks like currently atomic SUB is implemented using 
NEG + ADD:
```
// atomic_load_sub can be represented as a neg followed
// by an atomic_load_add.
```
So I thought, "OK, if we don't need to reserve `0x1` for `BPF_SUB`, then I can 
use it".  Similarly, `0xb` is `BPF_MOV` (moving value between registers), and I 
think it's safe to say we'll never need it for `BPF_ATOMIC`.

But `0x2` is `BPF_MUL`; will we ever support atomic multiplication? :-)
- - -
Am I overthinking this?  Should I simply use `0x1` and `0x2` ?

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


[clang] [WebKit Checkers] Allow a guardian CheckedPtr/CheckedRef (PR #110222)

2024-10-24 Thread Ryosuke Niwa via cfe-commits


@@ -63,18 +63,29 @@ std::optional isUncounted(const clang::CXXRecordDecl* 
Class);
 /// class, false if not, std::nullopt if inconclusive.
 std::optional isUncountedPtr(const clang::QualType T);
 
-/// \returns true if Name is a RefPtr, Ref, or its variant, false if not.
-bool isRefType(const std::string &Name);
+/// \returns true if \p T is a RefPtr, Ref, CheckedPtr, CheckedRef, or its
+/// variant, false if not.
+bool isSafePtrType(const clang::QualType T);
 
 /// \returns true if \p F creates ref-countable object from uncounted 
parameter,
 /// false if not.
 bool isCtorOfRefCounted(const clang::FunctionDecl *F);
 
+/// \returns true if \p F creates ref-countable object from uncounted 
parameter,
+/// false if not.
+bool isCtorOfCheckedPtr(const clang::FunctionDecl *F);
+
+/// \returns true if \p Name is RefPtr, Ref, or its variant, false if not.
+bool isRefType(const std::string &Name);
+
+/// \returns true if \p Name is CheckedRef or CheckedPtr, false if not.
+bool isCheckedPtr(const std::string &Name);
+
 /// \returns true if \p T is RefPtr, Ref, or its variant, false if not.
 bool isRefType(const clang::QualType T);

rniwa wrote:

Apparently this was a dead code. Just deleted this declaration.

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


[clang] [llvm] [RISCV] Mark pointer masking extensions as non-experimental (PR #113618)

2024-10-24 Thread Pengcheng Wang via cfe-commits

https://github.com/wangpc-pp approved this pull request.

LGTM.

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


[clang] [llvm] [RISCV] Mark pointer masking extensions as non-experimental (PR #113618)

2024-10-24 Thread Pengcheng Wang via cfe-commits


@@ -26,5 +26,5 @@ entry:
 ; Function Attrs: nocallback nofree nosync nounwind willreturn memory(read)
 declare  @llvm.masked.gather.nxv4i32.nxv4p0(, i32 immarg, , ) #1
 
-attributes #0 = { 
"target-features"="+64bit,+d,+f,+relax,+v,+xsifivecdiscarddlone,+zicsr,+zve32f,+zve32x,+zve64d,+zve64f,+zve64x,+zvl128b,+zvl32b,+zvl64b,-a,-b,-c,-e,-experimental-smctr,-experimental-smmpm,-experimental-smnpm,-experimental-ssctr,-experimental-ssnpm,-experimental-sspm,-experimental-supm,-experimental-zacas,-experimental-zalasr,-experimental-zicfilp,-experimental-zicfiss,-experimental-zvbc32e,-experimental-zvkgs,-h,-m,-shcounterenw,-shgatpa,-shtvala,-shvsatpa,-shvstvala,-shvstvecd,-smaia,-smcdeleg,-smcsrind,-smepmp,-smstateen,-ssaia,-ssccfg,-ssccptr,-sscofpmf,-sscounterenw,-sscsrind,-ssqosid,-ssstateen,-ssstrict,-sstc,-sstvala,-sstvecd,-ssu64xl,-svade,-svadu,-svbare,-svinval,-svnapot,-svpbmt,-xcvalu,-xcvbi,-xcvbitmanip,-xcvelw,-xcvmac,-xcvmem,-xcvsimd,-xsfcease,-xsfvcp,-xsfvfnrclipxfqf,-xsfvfwmaccqqq,-xsfvqmaccdod,-xsfvqmaccqoq,-xsifivecflushdlone,-xtheadba,-xtheadbb,-xtheadbs,-xtheadcmo,-xtheadcondmov,-xtheadfmemidx,-xtheadmac,-xtheadmemidx,-xtheadmempair,-xtheadsync,-xtheadvdot,-xventanacondops,-xwchc,-za128rs,-za64rs,-zaamo,-zabha,-zalrsc,-zama16b,-zawrs,-zba,-zbb,-zbc,-zbkb,-zbkc,-zbkx,-zbs,-zca,-zcb,-zcd,-zce,-zcf,-zcmop,-zcmp,-zcmt,-zdinx,-zfa,-zfbfmin,-zfh,-zfhmin,-zfinx,-zhinx,-zhinxmin,-zic64b,-zicbom,-zicbop,-zicboz,-ziccamoa,-ziccif,-zicclsm,-ziccrse,-zicntr,-zicond,-zifencei,-zihintntl,-zihintpause,-zihpm,-zimop,-zk,-zkn,-zknd,-zkne,-zknh,-zkr,-zks,-zksed,-zksh,-zkt,-zmmul,-ztso,-zvbb,-zvbc,-zvfbfmin,-zvfbfwma,-zvfh,-zvfhmin,-zvkb,-zvkg,-zvkn,-zvknc,-zvkned,-zvkng,-zvknha,-zvknhb,-zvks,-zvksc,-zvksed,-zvksg,-zvksh,-zvkt,-zvl1024b,-zvl16384b,-zvl2048b,-zvl256b,-zvl32768b,-zvl4096b,-zvl512b,-zvl65536b,-zvl8192b"
 }
+attributes #0 = { 
"target-features"="+64bit,+d,+f,+relax,+v,+xsifivecdiscarddlone,+zicsr,+zve32f,+zve32x,+zve64d,+zve64f,+zve64x,+zvl128b,+zvl32b,+zvl64b,-a,-b,-c,-e,-experimental-smctr,-smmpm,-smnpm,-experimental-ssctr,-ssnpm,-sspm,-supm,-experimental-zacas,-experimental-zalasr,-experimental-zicfilp,-experimental-zicfiss,-experimental-zvbc32e,-experimental-zvkgs,-h,-m,-shcounterenw,-shgatpa,-shtvala,-shvsatpa,-shvstvala,-shvstvecd,-smaia,-smcdeleg,-smcsrind,-smepmp,-smstateen,-ssaia,-ssccfg,-ssccptr,-sscofpmf,-sscounterenw,-sscsrind,-ssqosid,-ssstateen,-ssstrict,-sstc,-sstvala,-sstvecd,-ssu64xl,-svade,-svadu,-svbare,-svinval,-svnapot,-svpbmt,-xcvalu,-xcvbi,-xcvbitmanip,-xcvelw,-xcvmac,-xcvmem,-xcvsimd,-xsfcease,-xsfvcp,-xsfvfnrclipxfqf,-xsfvfwmaccqqq,-xsfvqmaccdod,-xsfvqmaccqoq,-xsifivecflushdlone,-xtheadba,-xtheadbb,-xtheadbs,-xtheadcmo,-xtheadcondmov,-xtheadfmemidx,-xtheadmac,-xtheadmemidx,-xtheadmempair,-xtheadsync,-xtheadvdot,-xventanacondops,-xwchc,-za128rs,-za64rs,-zaamo,-zabha,-zalrsc,-zama16b,-zawrs,-zba,-zbb,-zbc,-zbkb,-zbkc,-zbkx,-zbs,-zca,-zcb,-zcd,-zce,-zcf,-zcmop,-zcmp,-zcmt,-zdinx,-zfa,-zfbfmin,-zfh,-zfhmin,-zfinx,-zhinx,-zhinxmin,-zic64b,-zicbom,-zicbop,-zicboz,-ziccamoa,-ziccif,-zicclsm,-ziccrse,-zicntr,-zicond,-zifencei,-zihintntl,-zihintpause,-zihpm,-zimop,-zk,-zkn,-zknd,-zkne,-zknh,-zkr,-zks,-zksed,-zksh,-zkt,-zmmul,-ztso,-zvbb,-zvbc,-zvfbfmin,-zvfbfwma,-zvfh,-zvfhmin,-zvkb,-zvkg,-zvkn,-zvknc,-zvkned,-zvkng,-zvknha,-zvknhb,-zvks,-zvksc,-zvksed,-zvksg,-zvksh,-zvkt,-zvl1024b,-zvl16384b,-zvl2048b,-zvl256b,-zvl32768b,-zvl4096b,-zvl512b,-zvl65536b,-zvl8192b"
 }

wangpc-pp wrote:

Comment that is not for this patch: 
Why do we need this attribute list? We should use `-mattr` instead. cc @lukel97 

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


[clang] [llvm] [RISCV] Mark pointer masking extensions as non-experimental (PR #113618)

2024-10-24 Thread Pengcheng Wang via cfe-commits

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


[clang] [HLSL] Add RasterizerOrderedStructuredBuffer definition to HLSLExternalSemaSource (PR #113648)

2024-10-24 Thread Helena Kotas via cfe-commits

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


[clang] [HLSL] Add Append/ConsumeStructuredBuffer definitions to HLSLExternalSemaSource (PR #113643)

2024-10-24 Thread Helena Kotas via cfe-commits

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


[clang] [HLSL] Add RasterizerOrderedStructuredBuffer definition to HLSLExternalSemaSource (PR #113648)

2024-10-24 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Helena Kotas (hekota)


Changes

Adds `RasterizerOrderedStructuredBuffer` definition to HLSLExternalSemaSource. 
Adds separate tests for the AST shape and element types. Adds 
constructor/handle.fromBinding and subscript test cases to shared test file for 
structured buffers. Additional methods will be added later.

Fixes #112776

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


5 Files Affected:

- (modified) clang/lib/Sema/HLSLExternalSemaSource.cpp (+12) 
- (added) clang/test/AST/HLSL/RasterizerOrderedStructuredBuffer-AST.hlsl (+66) 
- (added) 
clang/test/CodeGenHLSL/builtins/RasterizerOrderedStructuredBuffer-elementtype.hlsl
 (+70) 
- (modified) 
clang/test/CodeGenHLSL/builtins/StructuredBuffers-constructors.hlsl (+9) 
- (modified) clang/test/CodeGenHLSL/builtins/StructuredBuffers-subscripts.hlsl 
(+4-2) 


``diff
diff --git a/clang/lib/Sema/HLSLExternalSemaSource.cpp 
b/clang/lib/Sema/HLSLExternalSemaSource.cpp
index ce8564429b3802..f3a0ff5dd852be 100644
--- a/clang/lib/Sema/HLSLExternalSemaSource.cpp
+++ b/clang/lib/Sema/HLSLExternalSemaSource.cpp
@@ -530,6 +530,18 @@ void 
HLSLExternalSemaSource::defineHLSLTypesWithForwardDeclarations() {
 .addArraySubscriptOperators()
 .completeDefinition();
   });
+
+  Decl = BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace,
+"RasterizerOrderedStructuredBuffer")
+ .addSimpleTemplateParams(*SemaPtr, {"element_type"})
+ .Record;
+  onCompletion(Decl, [this](CXXRecordDecl *Decl) {
+setupBufferType(Decl, *SemaPtr, ResourceClass::UAV,
+ResourceKind::TypedBuffer, /*IsROV=*/true,
+/*RawBuffer=*/true)
+.addArraySubscriptOperators()
+.completeDefinition();
+  });
 }
 
 void HLSLExternalSemaSource::onCompletion(CXXRecordDecl *Record,
diff --git a/clang/test/AST/HLSL/RasterizerOrderedStructuredBuffer-AST.hlsl 
b/clang/test/AST/HLSL/RasterizerOrderedStructuredBuffer-AST.hlsl
new file mode 100644
index 00..f334e1bb6db3fc
--- /dev/null
+++ b/clang/test/AST/HLSL/RasterizerOrderedStructuredBuffer-AST.hlsl
@@ -0,0 +1,66 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-library -x hlsl -ast-dump 
-DEMPTY %s | FileCheck -check-prefix=EMPTY %s
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-library -x hlsl -ast-dump %s 
| FileCheck %s
+
+
+// This test tests two different AST generations. The "EMPTY" test mode 
verifies
+// the AST generated by forward declaration of the HLSL types which happens on
+// initializing the HLSL external AST with an AST Context.
+
+// The non-empty mode has a use that requires the 
RasterizerOrderedStructuredBuffer type be complete,
+// which results in the AST being populated by the external AST source. That
+// case covers the full implementation of the template declaration and the
+// instantiated specialization.
+
+// EMPTY: ClassTemplateDecl 0x{{[0-9A-Fa-f]+}} <>  
implicit RasterizerOrderedStructuredBuffer
+// EMPTY-NEXT: TemplateTypeParmDecl 0x{{[0-9A-Fa-f]+}} <> 
 class depth 0 index 0 element_type
+// EMPTY-NEXT: CXXRecordDecl 0x{{[0-9A-Fa-f]+}} <>  implicit  class 
RasterizerOrderedStructuredBuffer
+// EMPTY-NEXT: FinalAttr 0x{{[0-9A-Fa-f]+}} <> Implicit final
+
+// There should be no more occurrences of RasterizerOrderedStructuredBuffer
+// EMPTY-NOT: {{[^[:alnum:]]}}RasterizerOrderedStructuredBuffer
+
+#ifndef EMPTY
+
+RasterizerOrderedStructuredBuffer Buffer;
+
+#endif
+
+// CHECK: ClassTemplateDecl 0x{{[0-9A-Fa-f]+}} <>  
implicit RasterizerOrderedStructuredBuffer
+// CHECK-NEXT: TemplateTypeParmDecl 0x{{[0-9A-Fa-f]+}} <> 
 class depth 0 index 0 element_type
+// CHECK-NEXT: CXXRecordDecl 0x{{[0-9A-Fa-f]+}} <>  implicit class RasterizerOrderedStructuredBuffer definition
+
+// CHECK: FinalAttr 0x{{[0-9A-Fa-f]+}} <> Implicit final
+// CHECK-NEXT: FieldDecl 0x{{[0-9A-Fa-f]+}} <>  
implicit h '__hlsl_resource_t
+// CHECK-SAME{LITERAL}: [[hlsl::resource_class(UAV)]]
+// CHECK-SAME{LITERAL}: [[hlsl::is_rov]]
+// CHECK-SAME{LITERAL}: [[hlsl::raw_buffer]]
+// CHECK-SAME{LITERAL}: [[hlsl::contained_type(element_type)]]
+// CHECK-NEXT: HLSLResourceAttr 0x{{[0-9A-Fa-f]+}} <> Implicit 
TypedBuffer
+
+// CHECK: CXXMethodDecl 0x{{[0-9A-Fa-f]+}} <>  
operator[] 'element_type &const (unsigned int) const'
+// CHECK-NEXT: ParmVarDecl 0x{{[0-9A-Fa-f]+}} <>  
Idx 'unsigned int'
+// CHECK-NEXT: CompoundStmt 0x{{[0-9A-Fa-f]+}} <>
+// CHECK-NEXT: ReturnStmt 0x{{[0-9A-Fa-f]+}} <>
+// CHECK-NEXT: MemberExpr 0x{{[0-9A-Fa-f]+}} <> 'element_type' 
lvalue .e 0x{{[0-9A-Fa-f]+}}
+// CHECK-NEXT: CXXThisExpr 0x{{[0-9A-Fa-f]+}} <> 'const 
RasterizerOrderedStructuredBuffer' lvalue implicit this
+// CHECK-NEXT: AlwaysInlineAttr 0x{{[0-9A-Fa-f]+}} <> Implicit 
always_inline
+
+// CHECK-NEXT: CXXMethodDecl 0x{{[0-9A-Fa-f]+}} <>  operator[] 'element_type &(unsigned int)'
+// CHECK-NEXT: ParmVarDecl 0x{{[0-9A-Fa-f]+}} <>  
Idx 'unsigned int'
+// CHECK

[clang] [HLSL] Add Append/ConsumeStructuredBuffer definitions to HLSLExternalSemaSource (PR #113643)

2024-10-24 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-hlsl

Author: Helena Kotas (hekota)


Changes

Adds `AppendStructuredBuffer` and `ConsumeStructuredBuffer` definition to 
HLSLExternalSemaSource. Adds separate tests for the AST shape and element 
types, and adds constructor/handle.fromBinding test case to shared test file 
for structured buffers.

These buffers do not have any subscript operators. Append and Consume methods 
will be added later in llvm/llvm-project#112968.

Fixes #112777

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


6 Files Affected:

- (modified) clang/lib/Sema/HLSLExternalSemaSource.cpp (+22) 
- (added) clang/test/AST/HLSL/AppendStructuredBuffer-AST.hlsl (+50) 
- (added) clang/test/AST/HLSL/ConsumeStructuredBuffer-AST.hlsl (+51) 
- (added) 
clang/test/CodeGenHLSL/builtins/AppendStructuredBuffer-elementtype.hlsl (+53) 
- (added) 
clang/test/CodeGenHLSL/builtins/ConsumeStructuredBuffer-elementtype.hlsl (+53) 
- (modified) 
clang/test/CodeGenHLSL/builtins/StructuredBuffers-constructors.hlsl (+21-2) 


``diff
diff --git a/clang/lib/Sema/HLSLExternalSemaSource.cpp 
b/clang/lib/Sema/HLSLExternalSemaSource.cpp
index ce8564429b3802..22ca9f72d40a30 100644
--- a/clang/lib/Sema/HLSLExternalSemaSource.cpp
+++ b/clang/lib/Sema/HLSLExternalSemaSource.cpp
@@ -530,6 +530,28 @@ void 
HLSLExternalSemaSource::defineHLSLTypesWithForwardDeclarations() {
 .addArraySubscriptOperators()
 .completeDefinition();
   });
+
+  Decl =
+  BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace, "AppendStructuredBuffer")
+  .addSimpleTemplateParams(*SemaPtr, {"element_type"})
+  .Record;
+  onCompletion(Decl, [this](CXXRecordDecl *Decl) {
+setupBufferType(Decl, *SemaPtr, ResourceClass::UAV,
+ResourceKind::TypedBuffer, /*IsROV=*/false,
+/*RawBuffer=*/true)
+.completeDefinition();
+  });
+
+  Decl =
+  BuiltinTypeDeclBuilder(*SemaPtr, HLSLNamespace, 
"ConsumeStructuredBuffer")
+  .addSimpleTemplateParams(*SemaPtr, {"element_type"})
+  .Record;
+  onCompletion(Decl, [this](CXXRecordDecl *Decl) {
+setupBufferType(Decl, *SemaPtr, ResourceClass::UAV,
+ResourceKind::TypedBuffer, /*IsROV=*/false,
+/*RawBuffer=*/true)
+.completeDefinition();
+  });
 }
 
 void HLSLExternalSemaSource::onCompletion(CXXRecordDecl *Record,
diff --git a/clang/test/AST/HLSL/AppendStructuredBuffer-AST.hlsl 
b/clang/test/AST/HLSL/AppendStructuredBuffer-AST.hlsl
new file mode 100644
index 00..2ede9dfacae7c9
--- /dev/null
+++ b/clang/test/AST/HLSL/AppendStructuredBuffer-AST.hlsl
@@ -0,0 +1,50 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-library -x hlsl -ast-dump 
-DEMPTY %s | FileCheck -check-prefix=EMPTY %s
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-library -x hlsl -ast-dump %s 
| FileCheck %s
+
+
+// This test tests two different AST generations. The "EMPTY" test mode 
verifies
+// the AST generated by forward declaration of the HLSL types which happens on
+// initializing the HLSL external AST with an AST Context.
+
+// The non-empty mode has a use that requires the AppendStructuredBuffer type 
be complete,
+// which results in the AST being populated by the external AST source. That
+// case covers the full implementation of the template declaration and the
+// instantiated specialization.
+
+// EMPTY: ClassTemplateDecl 0x{{[0-9A-Fa-f]+}} <>  
implicit AppendStructuredBuffer
+// EMPTY-NEXT: TemplateTypeParmDecl 0x{{[0-9A-Fa-f]+}} <> 
 class depth 0 index 0 element_type
+// EMPTY-NEXT: CXXRecordDecl 0x{{[0-9A-Fa-f]+}} <>  implicit  class AppendStructuredBuffer
+// EMPTY-NEXT: FinalAttr 0x{{[0-9A-Fa-f]+}} <> Implicit final
+
+// There should be no more occurrences of AppendStructuredBuffer
+// EMPTY-NOT: {{[^[:alnum:]]}}AppendStructuredBuffer
+
+#ifndef EMPTY
+
+AppendStructuredBuffer Buffer;
+
+#endif
+
+// CHECK: ClassTemplateDecl 0x{{[0-9A-Fa-f]+}} <>  
implicit AppendStructuredBuffer
+// CHECK-NEXT: TemplateTypeParmDecl 0x{{[0-9A-Fa-f]+}} <> 
 class depth 0 index 0 element_type
+// CHECK-NEXT: CXXRecordDecl 0x{{[0-9A-Fa-f]+}} <>  implicit class AppendStructuredBuffer definition
+
+// CHECK: FinalAttr 0x{{[0-9A-Fa-f]+}} <> Implicit final
+// CHECK-NEXT: FieldDecl 0x{{[0-9A-Fa-f]+}} <>  
implicit h '__hlsl_resource_t
+// CHECK-SAME{LITERAL}: [[hlsl::resource_class(UAV)]]
+// CHECK-SAME{LITERAL}: [[hlsl::raw_buffer]]
+// CHECK-SAME{LITERAL}: [[hlsl::contained_type(element_type)]]
+// CHECK-NEXT: HLSLResourceAttr 0x{{[0-9A-Fa-f]+}} <> Implicit 
TypedBuffer
+
+// CHECK-NOT: CXXMethodDecl 0x{{[0-9A-Fa-f]+}} <>  
operator[] 'element_type &const (unsigned int) const'
+// CHECK-NOT: CXXMethodDecl 0x{{[0-9A-Fa-f]+}} <>  
operator[] 'element_type &(unsigned int)'
+
+// CHECK: ClassTemplateSpecializationDecl 0x{{[0-9A-Fa-f]+}} <> 
 class AppendStructuredBuffer definition
+// CHECK: TemplateArgument type 'int'
+// CHECK-NEXT: BuiltinType 0x{{[0-9A-Fa-f]+}} 'int

[clang] [HLSL][NFC] Cleanup - removed unused includes and param, fix typos (PR #113649)

2024-10-24 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-hlsl

Author: Helena Kotas (hekota)


Changes



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


4 Files Affected:

- (modified) clang/lib/Sema/HLSLExternalSemaSource.cpp (+2-13) 
- (modified) clang/test/AST/HLSL/RWBuffer-AST.hlsl (+1-1) 
- (modified) clang/test/AST/HLSL/RWStructuredBuffer-AST.hlsl (+1-1) 
- (modified) clang/test/AST/HLSL/StructuredBuffer-AST.hlsl (+1-1) 


``diff
diff --git a/clang/lib/Sema/HLSLExternalSemaSource.cpp 
b/clang/lib/Sema/HLSLExternalSemaSource.cpp
index ce8564429b3802..a8365448de7246 100644
--- a/clang/lib/Sema/HLSLExternalSemaSource.cpp
+++ b/clang/lib/Sema/HLSLExternalSemaSource.cpp
@@ -14,8 +14,6 @@
 #include "clang/AST/Attr.h"
 #include "clang/AST/DeclCXX.h"
 #include "clang/AST/Type.h"
-#include "clang/Basic/AttrKinds.h"
-#include "clang/Basic/HLSLRuntime.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Sema/Lookup.h"
 #include "clang/Sema/Sema.h"
@@ -164,16 +162,7 @@ struct BuiltinTypeDeclBuilder {
VD, false, NameInfo, Ty, VK_PRValue);
   }
 
-  static Expr *emitResourceClassExpr(ASTContext &AST, ResourceClass RC) {
-return IntegerLiteral::Create(
-AST,
-llvm::APInt(AST.getIntWidth(AST.UnsignedCharTy),
-static_cast(RC)),
-AST.UnsignedCharTy, SourceLocation());
-  }
-
-  BuiltinTypeDeclBuilder &addDefaultHandleConstructor(Sema &S,
-  ResourceClass RC) {
+  BuiltinTypeDeclBuilder &addDefaultHandleConstructor(Sema &S) {
 if (Record->isCompleteDefinition())
   return *this;
 ASTContext &AST = Record->getASTContext();
@@ -480,7 +469,7 @@ static BuiltinTypeDeclBuilder setupBufferType(CXXRecordDecl 
*Decl, Sema &S,
   bool IsROV, bool RawBuffer) {
   return BuiltinTypeDeclBuilder(Decl)
   .addHandleMember(S, RC, RK, IsROV, RawBuffer)
-  .addDefaultHandleConstructor(S, RC);
+  .addDefaultHandleConstructor(S);
 }
 
 void HLSLExternalSemaSource::defineHLSLTypesWithForwardDeclarations() {
diff --git a/clang/test/AST/HLSL/RWBuffer-AST.hlsl 
b/clang/test/AST/HLSL/RWBuffer-AST.hlsl
index e6ce73dbd962f7..ebddd72ddb1e0e 100644
--- a/clang/test/AST/HLSL/RWBuffer-AST.hlsl
+++ b/clang/test/AST/HLSL/RWBuffer-AST.hlsl
@@ -15,7 +15,7 @@
 // EMPTY-NEXT: CXXRecordDecl 0x{{[0-9A-Fa-f]+}} <>  implicit  class RWBuffer
 // EMPTY-NEXT: FinalAttr 0x{{[0-9A-Fa-f]+}} <> Implicit final
 
-// There should be no more occurrances of RWBuffer
+// There should be no more occurrences of RWBuffer
 // EMPTY-NOT: RWBuffer
 
 #ifndef EMPTY
diff --git a/clang/test/AST/HLSL/RWStructuredBuffer-AST.hlsl 
b/clang/test/AST/HLSL/RWStructuredBuffer-AST.hlsl
index f95d74b30acded..4104250225aec3 100644
--- a/clang/test/AST/HLSL/RWStructuredBuffer-AST.hlsl
+++ b/clang/test/AST/HLSL/RWStructuredBuffer-AST.hlsl
@@ -16,7 +16,7 @@
 // EMPTY-NEXT: CXXRecordDecl 0x{{[0-9A-Fa-f]+}} <>  implicit  class RWStructuredBuffer
 // EMPTY-NEXT: FinalAttr 0x{{[0-9A-Fa-f]+}} <> Implicit final
 
-// There should be no more occurrances of RWStructuredBuffer
+// There should be no more occurrences of RWStructuredBuffer
 // EMPTY-NOT: {{[^[:alnum:]]}}RWStructuredBuffer
 
 #ifndef EMPTY
diff --git a/clang/test/AST/HLSL/StructuredBuffer-AST.hlsl 
b/clang/test/AST/HLSL/StructuredBuffer-AST.hlsl
index 6c39be8ba519f9..42a7d1b5617397 100644
--- a/clang/test/AST/HLSL/StructuredBuffer-AST.hlsl
+++ b/clang/test/AST/HLSL/StructuredBuffer-AST.hlsl
@@ -16,7 +16,7 @@
 // EMPTY-NEXT: CXXRecordDecl 0x{{[0-9A-Fa-f]+}} <>  implicit  class StructuredBuffer
 // EMPTY-NEXT: FinalAttr 0x{{[0-9A-Fa-f]+}} <> Implicit final
 
-// There should be no more occurrances of StructuredBuffer
+// There should be no more occurrences of StructuredBuffer
 // EMPTY-NOT: {{[^[:alnum:]]}}StructuredBuffer
 
 #ifndef EMPTY

``




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


[clang] [HLSL][NFC] Cleanup - removed unused includes and param, fix typos (PR #113649)

2024-10-24 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Helena Kotas (hekota)


Changes



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


4 Files Affected:

- (modified) clang/lib/Sema/HLSLExternalSemaSource.cpp (+2-13) 
- (modified) clang/test/AST/HLSL/RWBuffer-AST.hlsl (+1-1) 
- (modified) clang/test/AST/HLSL/RWStructuredBuffer-AST.hlsl (+1-1) 
- (modified) clang/test/AST/HLSL/StructuredBuffer-AST.hlsl (+1-1) 


``diff
diff --git a/clang/lib/Sema/HLSLExternalSemaSource.cpp 
b/clang/lib/Sema/HLSLExternalSemaSource.cpp
index ce8564429b3802..a8365448de7246 100644
--- a/clang/lib/Sema/HLSLExternalSemaSource.cpp
+++ b/clang/lib/Sema/HLSLExternalSemaSource.cpp
@@ -14,8 +14,6 @@
 #include "clang/AST/Attr.h"
 #include "clang/AST/DeclCXX.h"
 #include "clang/AST/Type.h"
-#include "clang/Basic/AttrKinds.h"
-#include "clang/Basic/HLSLRuntime.h"
 #include "clang/Basic/SourceLocation.h"
 #include "clang/Sema/Lookup.h"
 #include "clang/Sema/Sema.h"
@@ -164,16 +162,7 @@ struct BuiltinTypeDeclBuilder {
VD, false, NameInfo, Ty, VK_PRValue);
   }
 
-  static Expr *emitResourceClassExpr(ASTContext &AST, ResourceClass RC) {
-return IntegerLiteral::Create(
-AST,
-llvm::APInt(AST.getIntWidth(AST.UnsignedCharTy),
-static_cast(RC)),
-AST.UnsignedCharTy, SourceLocation());
-  }
-
-  BuiltinTypeDeclBuilder &addDefaultHandleConstructor(Sema &S,
-  ResourceClass RC) {
+  BuiltinTypeDeclBuilder &addDefaultHandleConstructor(Sema &S) {
 if (Record->isCompleteDefinition())
   return *this;
 ASTContext &AST = Record->getASTContext();
@@ -480,7 +469,7 @@ static BuiltinTypeDeclBuilder setupBufferType(CXXRecordDecl 
*Decl, Sema &S,
   bool IsROV, bool RawBuffer) {
   return BuiltinTypeDeclBuilder(Decl)
   .addHandleMember(S, RC, RK, IsROV, RawBuffer)
-  .addDefaultHandleConstructor(S, RC);
+  .addDefaultHandleConstructor(S);
 }
 
 void HLSLExternalSemaSource::defineHLSLTypesWithForwardDeclarations() {
diff --git a/clang/test/AST/HLSL/RWBuffer-AST.hlsl 
b/clang/test/AST/HLSL/RWBuffer-AST.hlsl
index e6ce73dbd962f7..ebddd72ddb1e0e 100644
--- a/clang/test/AST/HLSL/RWBuffer-AST.hlsl
+++ b/clang/test/AST/HLSL/RWBuffer-AST.hlsl
@@ -15,7 +15,7 @@
 // EMPTY-NEXT: CXXRecordDecl 0x{{[0-9A-Fa-f]+}} <>  implicit  class RWBuffer
 // EMPTY-NEXT: FinalAttr 0x{{[0-9A-Fa-f]+}} <> Implicit final
 
-// There should be no more occurrances of RWBuffer
+// There should be no more occurrences of RWBuffer
 // EMPTY-NOT: RWBuffer
 
 #ifndef EMPTY
diff --git a/clang/test/AST/HLSL/RWStructuredBuffer-AST.hlsl 
b/clang/test/AST/HLSL/RWStructuredBuffer-AST.hlsl
index f95d74b30acded..4104250225aec3 100644
--- a/clang/test/AST/HLSL/RWStructuredBuffer-AST.hlsl
+++ b/clang/test/AST/HLSL/RWStructuredBuffer-AST.hlsl
@@ -16,7 +16,7 @@
 // EMPTY-NEXT: CXXRecordDecl 0x{{[0-9A-Fa-f]+}} <>  implicit  class RWStructuredBuffer
 // EMPTY-NEXT: FinalAttr 0x{{[0-9A-Fa-f]+}} <> Implicit final
 
-// There should be no more occurrances of RWStructuredBuffer
+// There should be no more occurrences of RWStructuredBuffer
 // EMPTY-NOT: {{[^[:alnum:]]}}RWStructuredBuffer
 
 #ifndef EMPTY
diff --git a/clang/test/AST/HLSL/StructuredBuffer-AST.hlsl 
b/clang/test/AST/HLSL/StructuredBuffer-AST.hlsl
index 6c39be8ba519f9..42a7d1b5617397 100644
--- a/clang/test/AST/HLSL/StructuredBuffer-AST.hlsl
+++ b/clang/test/AST/HLSL/StructuredBuffer-AST.hlsl
@@ -16,7 +16,7 @@
 // EMPTY-NEXT: CXXRecordDecl 0x{{[0-9A-Fa-f]+}} <>  implicit  class StructuredBuffer
 // EMPTY-NEXT: FinalAttr 0x{{[0-9A-Fa-f]+}} <> Implicit final
 
-// There should be no more occurrances of StructuredBuffer
+// There should be no more occurrences of StructuredBuffer
 // EMPTY-NOT: {{[^[:alnum:]]}}StructuredBuffer
 
 #ifndef EMPTY

``




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


[clang] [llvm] [RISCV] Add Supm extension to RVA23 profiles (PR #113619)

2024-10-24 Thread Pengcheng Wang via cfe-commits

https://github.com/wangpc-pp approved this pull request.

LGTM.
(And it's time to mask RV[A|B|M]23 as non-experimental now?)

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


[clang] [HLSL][NFC] Cleanup - removed unused includes and param, fix typos (PR #113649)

2024-10-24 Thread Helena Kotas via cfe-commits

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


[clang] [llvm] [RISCV] Add Supm extension to RVA23 profiles (PR #113619)

2024-10-24 Thread Pengcheng Wang via cfe-commits

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


[clang] [clang-format] clang-format-ignore: Add support for double asterisk patterns (PR #110560)

2024-10-24 Thread Owen Pan via cfe-commits


@@ -164,6 +164,40 @@ TEST_F(MatchFilePathTest, Path) {
   EXPECT_FALSE(match("foo\\", R"(foo*\)"));
 }
 
+TEST_F(MatchFilePathTest, DoubleAsterisk) {
+  EXPECT_TRUE(match("a/b/c/d.cpp", "**b**"));
+  EXPECT_TRUE(match("a/b/c/d.cpp", "**/b/**"));
+  EXPECT_TRUE(match("a/b/c/d_e.cpp", "**d_*"));
+  EXPECT_TRUE(match("a/b/c/d_e.cpp", "**/d_*"));
+  EXPECT_TRUE(match("a/b/c/d_e.cpp", "**d_**"));
+  EXPECT_TRUE(match("a/b/c/d_e.cpp", "**/d_**"));
+
+  EXPECT_TRUE(match("a/b/c/d_e.cpp", "**/b/c/**"));
+
+  EXPECT_TRUE(match("a/b/c/d_e.cpp", "a/**/b/c/d_e.cpp"));
+  EXPECT_TRUE(match("a/b/c/d_e.cpp", "a/**/c/d_e.cpp"));
+  EXPECT_TRUE(match("a/b/c/d_e.cpp", "a/**/b/**/d_e.cpp"));
+  EXPECT_TRUE(match("a/b/c/d_e.cpp", "**/b/**/d_e.cpp"));
+  EXPECT_TRUE(match("a/b/c/d_e.cpp", "a/**/**/b/**"));
+
+  EXPECT_FALSE(match("a/b/c/d_e.cpp", "**/d"));
+  EXPECT_FALSE(match("a/b/c/d_e.cpp", "**/b/d"));
+  EXPECT_FALSE(match("a/b/c/d_e.cpp", "**/b/d/**"));
+  EXPECT_FALSE(match("a/b/c/d_e.cpp", "**/b/c/"));
+
+  // Multiple consecutive asterisks are treated as **
+  EXPECT_TRUE(match("a/b/c/d.cpp", "***b"));
+  EXPECT_TRUE(match("a/b/c/d.cpp", "/b/***"));
+  EXPECT_TRUE(match("a/b/c/d_e.cpp", "***d_**"));
+  EXPECT_TRUE(match("a/b/c/d_e.cpp", "/d_*"));
+  EXPECT_TRUE(match("a/b/c/d_e.cpp", "***/b/c/*"));
+
+  EXPECT_FALSE(match("a/b/c/d_e.cpp", "*/d"));
+  EXPECT_FALSE(match("a/b/c/d_e.cpp", "***/b/d"));
+  EXPECT_FALSE(match("a/b/c/d_e.cpp", "*/b/d/***"));
+  EXPECT_FALSE(match("a/b/c/d_e.cpp", "***/b/c"));

owenca wrote:

> > if we are doing this an saying "Its like .gitignore" should we support
> 
> I am only indicating that the `**` glob pattern is implemented in .gitignore, 
> and we follow the same rules they do for this specific pattern.

When I added .clang-format-ignore, I chose a POSIX glob-like model and 
intentionally stayed clear of the .gitignore model, which is, IMO, confusing 
and overcomplicated. I prefer to not add `**` now to partially match .gitignore 
unless there's a good reason and strong demand for it. There's also a 
possibility of regression as `**` is currently matched the same way as a single 
`*`.

> I think the current implementation only considers one pattern in the file at 
> a time, in isolation of all other lines in the .clang-format-ignore file.

Yes, the current behavior is to check the patterns in the .clang-format-ignore 
file one pattern at a time until a match is found.

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


[clang] [Driver] Use != instead of compare to compare strings (NFC) (PR #113651)

2024-10-24 Thread Fangrui Song via cfe-commits

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


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


[clang] [WebKit Checkers] Allow a guardian CheckedPtr/CheckedRef (PR #110222)

2024-10-24 Thread Rashmi Mudduluru via cfe-commits


@@ -63,18 +63,29 @@ std::optional isUncounted(const clang::CXXRecordDecl* 
Class);
 /// class, false if not, std::nullopt if inconclusive.
 std::optional isUncountedPtr(const clang::QualType T);
 
-/// \returns true if Name is a RefPtr, Ref, or its variant, false if not.
-bool isRefType(const std::string &Name);
+/// \returns true if \p T is a RefPtr, Ref, CheckedPtr, CheckedRef, or its
+/// variant, false if not.
+bool isSafePtrType(const clang::QualType T);
 
 /// \returns true if \p F creates ref-countable object from uncounted 
parameter,
 /// false if not.
 bool isCtorOfRefCounted(const clang::FunctionDecl *F);
 
+/// \returns true if \p F creates ref-countable object from uncounted 
parameter,
+/// false if not.
+bool isCtorOfCheckedPtr(const clang::FunctionDecl *F);
+
+/// \returns true if \p Name is RefPtr, Ref, or its variant, false if not.
+bool isRefType(const std::string &Name);
+
+/// \returns true if \p Name is CheckedRef or CheckedPtr, false if not.
+bool isCheckedPtr(const std::string &Name);
+
 /// \returns true if \p T is RefPtr, Ref, or its variant, false if not.
 bool isRefType(const clang::QualType T);

t-rasmud wrote:

This is more of a question for me to understand: Is there a reason this 
overload of `isRefType` isn't modified to check for `CheckedPtr`, `CheckedRef`?

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


[libcxx] [libcxxabi] [libunwind] [llvm] Revert "[runtimes] Probe for -nostdlib++ and -nostdinc++ with the C compiler" (PR #113653)

2024-10-24 Thread Martin Storsjö via cfe-commits

mstorsjo wrote:

Sure, if this is the one that is breaking things. Thanks for looking into it, 
and sorry for the breakage!

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


[clang] [llvm] [AMDGPU] Infer amdgpu-no-flat-scratch-init attribute in AMDGPUAttributor (PR #94647)

2024-10-24 Thread Jun Wang via cfe-commits


@@ -683,6 +706,59 @@ struct AAAMDAttributesFunction : public AAAMDAttributes {
 return !A.checkForAllCallLikeInstructions(DoesNotRetrieve, *this,
   UsedAssumedInformation);
   }
+
+  // Returns true if FlatScratchInit is needed, i.e., no-flat-scratch-init is
+  // not to be set.
+  bool needFlatScratchInit(Attributor &A) {
+assert(isAssumed(FLAT_SCRATCH_INIT)); // only called if the bit is still 
set
+
+// This is called on each callee; false means callee shouldn't have
+// no-flat-scratch-init.
+auto CheckForNoFlatScratchInit = [&](Instruction &I) {
+  const auto &CB = cast(I);
+  const Function *Callee = CB.getCalledFunction();
+
+  // Callee == 0 for inline asm or indirect call with known callees.
+  // In the latter case, updateImpl() already checked the callees and we
+  // know their FLAT_SCRATCH_INIT bit is set.
+  // If function has indirect call with unknown callees, the bit is
+  // already removed in updateImpl() and execution won't reach here.
+  if (!Callee)
+return true;
+
+  return Callee->getIntrinsicID() !=
+ Intrinsic::amdgcn_addrspacecast_nonnull;
+};
+
+bool UsedAssumedInformation = false;
+// If any callee is false (i.e. need FlatScratchInit),
+// checkForAllCallLikeInstructions returns false, in which case this
+// function returns true.
+return !A.checkForAllCallLikeInstructions(CheckForNoFlatScratchInit, *this,
+  UsedAssumedInformation);
+  }
+
+  bool constHasASCast(const Constant *C,
+  SmallPtrSetImpl &Visited) {
+if (!Visited.insert(C).second)
+  return false;
+
+if (const auto *CE = dyn_cast(C))
+  if (CE->getOpcode() == Instruction::AddrSpaceCast &&
+  CE->getOperand(0)->getType()->getPointerAddressSpace() ==
+  AMDGPUAS::PRIVATE_ADDRESS)
+return true;
+
+for (const Use &U : C->operands()) {
+  const auto *OpC = dyn_cast(U);
+  if (!OpC || !Visited.insert(OpC).second)
+continue;
+
+  if (constHasASCast(OpC, Visited))
+return true;
+}
+return false;
+  }

jwanggit86 wrote:

Found `getConstantAccess()`, which might be what you were referring to. I'm 
looking into it.

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


[libcxx] [libcxxabi] [libunwind] [llvm] [runtimes] Probe for -nostdlib++ and -nostdinc++ with the C compiler (PR #108357)

2024-10-24 Thread Martin Storsjö via cfe-commits

mstorsjo wrote:

> Actually this PR is the case of 
> https://lab.llvm.org/buildbot/#/builders/164/builds/3908, not #113491

Sorry about that.

Are you able to dig up any of the cmake configure logs from these builds, so 
that we can figure out how this ends up breaking things? Because as in most of 
these cases, the visible output in the buildbot logs mostly say that some 
configure checks end up going the wrong way, but we can't really see why.

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


[clang] [analyzer] Untangle subcheckers of CStringChecker (PR #113312)

2024-10-24 Thread Balazs Benics via cfe-commits


@@ -579,8 +579,14 @@ ProgramStateRef 
CStringChecker::CheckLocation(CheckerContext &C,
 // These checks are either enabled by the CString out-of-bounds checker
 // explicitly or implicitly by the Malloc checker.
 // In the latter case we only do modeling but do not emit warning.
-if (!Filter.CheckCStringOutOfBounds)
-  return nullptr;
+// FIXME: We detected a fatal error here, we should stop analysis even if 
we
+// chose not to emit a report here. However, as long as our out-of-bounds
+// checker is in alpha, lets just pretend nothing happened.
+if (!Filter.CheckCStringOutOfBounds) {
+  //C.addSink();

steakhal wrote:

Commented out code is a code smell. Use the comment "We should not sink 
execution here."

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


[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2024-10-24 Thread Dan Liew via cfe-commits


@@ -186,4 +218,370 @@ bool Sema::CheckCountedByAttrOnField(FieldDecl *FD, Expr 
*E, bool CountInBytes,
   return false;
 }
 
+SourceRange Sema::BoundsSafetySourceRangeFor(const CountAttributedType *CATy) {
+  // Note: This implementation relies on `CountAttributedType` being unique.
+  // E.g.:
+  //
+  // struct Foo {
+  //   int count;
+  //   char* __counted_by(count) buffer;
+  //   char* __counted_by(count) buffer2;
+  // };
+  //
+  // The types of `buffer` and `buffer2` are unique. The types being
+  // unique means the SourceLocation of the `counted_by` expression can be used
+  // to find where the attribute was written.
+
+  auto Fallback = CATy->getCountExpr()->getSourceRange();

delcypher wrote:

This method's implementation has been completely changed so this isn't relevant 
anymore.

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


[clang] [llvm] [DXIL][SPIRV] Lower WaveActiveCountBits intrinsic (PR #113382)

2024-10-24 Thread Greg Roth via cfe-commits


@@ -1762,6 +1765,36 @@ bool SPIRVInstructionSelector::selectSign(Register 
ResVReg,
   return Result;
 }
 
+bool SPIRVInstructionSelector::selectWaveActiveCountBits(
+Register ResVReg, const SPIRVType *ResType, MachineInstr &I) const {
+  assert(I.getNumOperands() == 3);
+  assert(I.getOperand(2).isReg());
+  MachineBasicBlock &BB = *I.getParent();
+
+  Register BallotReg = MRI->createVirtualRegister(&SPIRV::IDRegClass);
+  SPIRVType *IntTy = GR.getOrCreateSPIRVIntegerType(32, I, TII);
+  SPIRVType *BallotType = GR.getOrCreateSPIRVVectorType(IntTy, 4, I, TII);
+
+  bool Result =
+  BuildMI(BB, I, I.getDebugLoc(), TII.get(SPIRV::OpGroupNonUniformBallot))
+  .addDef(BallotReg)
+  .addUse(GR.getSPIRVTypeID(BallotType))
+  .addUse(GR.getOrCreateConstInt(SPIRV::Scope::Subgroup, I, IntTy, 
TII))
+  .addUse(I.getOperand(2).getReg());
+
+  Result |=
+  BuildMI(BB, I, I.getDebugLoc(),
+  TII.get(SPIRV::OpGroupNonUniformBallotBitCount))
+  .addDef(ResVReg)
+  .addUse(GR.getSPIRVTypeID(ResType))
+  .addUse(GR.getOrCreateConstInt(SPIRV::Scope::Subgroup, I, IntTy, 
TII))
+  .addImm(0)

pow2clk wrote:

Do I understand that you'll do this before submitting this PR?

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


[clang] Fix amdgpu-arch for dll name on Windows (PR #101350)

2024-10-24 Thread Yaxun Liu via cfe-commits

yxsamliu wrote:

ping

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


[clang] [Driver] Use != instead of compare to compare strings (NFC) (PR #113651)

2024-10-24 Thread Kazu Hirata via cfe-commits

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

None

>From 0e6ea5f32dc77ba2c81f45d6530e301da85e6e91 Mon Sep 17 00:00:00 2001
From: Kazu Hirata 
Date: Thu, 24 Oct 2024 15:59:14 -0700
Subject: [PATCH] [Driver] Use != instead of compare to compare strings (NFC)

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

diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 06c44a660e98fb..04b3832327a99c 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -2838,7 +2838,7 @@ static std::string 
ComplexArithmeticStr(LangOptions::ComplexRangeKind Range) {
 
 static void EmitComplexRangeDiag(const Driver &D, std::string str1,
  std::string str2) {
-  if ((str1.compare(str2) != 0) && !str2.empty() && !str1.empty()) {
+  if (str1 != str2 && !str2.empty() && !str1.empty()) {
 D.Diag(clang::diag::warn_drv_overriding_option) << str1 << str2;
   }
 }
@@ -2996,8 +2996,8 @@ static void RenderFloatingPointOptions(const ToolChain 
&TC, const Driver &D,
 EmitComplexRangeDiag(D, RenderComplexRangeOption(Range),
  "-fno-cx-limited-range");
   } else {
-if (GccRangeComplexOption.compare("-fcx-limited-range") != 0 &&
-GccRangeComplexOption.compare("-fno-cx-fortran-rules") != 0)
+if (GccRangeComplexOption != "-fcx-limited-range" &&
+GccRangeComplexOption != "-fno-cx-fortran-rules")
   EmitComplexRangeDiag(D, GccRangeComplexOption,
"-fno-cx-limited-range");
   }
@@ -3042,8 +3042,8 @@ static void RenderFloatingPointOptions(const ToolChain 
&TC, const Driver &D,
 break;
   }
   if (!GccRangeComplexOption.empty()) {
-if (GccRangeComplexOption.compare("-fcx-limited-range") != 0) {
-  if (GccRangeComplexOption.compare("-fcx-fortran-rules") != 0) {
+if (GccRangeComplexOption != "-fcx-limited-range") {
+  if (GccRangeComplexOption != "-fcx-fortran-rules") {
 if (RangeVal != LangOptions::ComplexRangeKind::CX_Improved)
   EmitComplexRangeDiag(D, GccRangeComplexOption,
ComplexArithmeticStr(RangeVal));

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


[libcxx] [libcxxabi] [libunwind] [llvm] [runtimes] Probe for -nostdlib++ and -nostdinc++ with the C compiler (PR #108357)

2024-10-24 Thread Vitaly Buka via cfe-commits

vitalybuka wrote:

Actually this PR is the case of 
https://lab.llvm.org/buildbot/#/builders/164/builds/3908, not 
https://github.com/llvm/llvm-project/pull/113491

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


[clang] [WebKit Checkers] Make TrivialFunctionAnalysis recognize std::array::operator[] as trivial (PR #113377)

2024-10-24 Thread Ryosuke Niwa via cfe-commits


@@ -452,6 +454,10 @@ class RefCounted {
   unsigned nonTrivial23() { return DerivedNumber("123").value(); }
   SomeType nonTrivial24() { return SomeType("123"); }
 
+  void call_libcpp_verbose_abort() {
+  __libcpp_verbose_abort("%s", "aborting");

rniwa wrote:

Nit: This indentation seems wrong?

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


[clang] [Driver] Use != instead of compare to compare strings (NFC) (PR #113651)

2024-10-24 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang-driver

Author: Kazu Hirata (kazutakahirata)


Changes



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


1 Files Affected:

- (modified) clang/lib/Driver/ToolChains/Clang.cpp (+5-5) 


``diff
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp 
b/clang/lib/Driver/ToolChains/Clang.cpp
index 06c44a660e98fb..04b3832327a99c 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -2838,7 +2838,7 @@ static std::string 
ComplexArithmeticStr(LangOptions::ComplexRangeKind Range) {
 
 static void EmitComplexRangeDiag(const Driver &D, std::string str1,
  std::string str2) {
-  if ((str1.compare(str2) != 0) && !str2.empty() && !str1.empty()) {
+  if (str1 != str2 && !str2.empty() && !str1.empty()) {
 D.Diag(clang::diag::warn_drv_overriding_option) << str1 << str2;
   }
 }
@@ -2996,8 +2996,8 @@ static void RenderFloatingPointOptions(const ToolChain 
&TC, const Driver &D,
 EmitComplexRangeDiag(D, RenderComplexRangeOption(Range),
  "-fno-cx-limited-range");
   } else {
-if (GccRangeComplexOption.compare("-fcx-limited-range") != 0 &&
-GccRangeComplexOption.compare("-fno-cx-fortran-rules") != 0)
+if (GccRangeComplexOption != "-fcx-limited-range" &&
+GccRangeComplexOption != "-fno-cx-fortran-rules")
   EmitComplexRangeDiag(D, GccRangeComplexOption,
"-fno-cx-limited-range");
   }
@@ -3042,8 +3042,8 @@ static void RenderFloatingPointOptions(const ToolChain 
&TC, const Driver &D,
 break;
   }
   if (!GccRangeComplexOption.empty()) {
-if (GccRangeComplexOption.compare("-fcx-limited-range") != 0) {
-  if (GccRangeComplexOption.compare("-fcx-fortran-rules") != 0) {
+if (GccRangeComplexOption != "-fcx-limited-range") {
+  if (GccRangeComplexOption != "-fcx-fortran-rules") {
 if (RangeVal != LangOptions::ComplexRangeKind::CX_Improved)
   EmitComplexRangeDiag(D, GccRangeComplexOption,
ComplexArithmeticStr(RangeVal));

``




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


[clang] [analyzer] Fix a crash from element region construction during `ArrayInitLoopExpr` analysis (PR #113570)

2024-10-24 Thread Balazs Benics via cfe-commits

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

Could you please add `no-crash` comment in the test code where we would have 
crashed?

Other than this, this looks good to me.
Thabks for the prompt fix!

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


[libcxx] [libcxxabi] [libunwind] [llvm] Revert "[runtimes] Probe for -nostdlib++ and -nostdinc++ with the C compiler" (PR #113653)

2024-10-24 Thread Vitaly Buka via cfe-commits

https://github.com/vitalybuka created 
https://github.com/llvm/llvm-project/pull/113653

Reverts llvm/llvm-project#108357

Breaks  https://lab.llvm.org/buildbot/#/builders/164/builds/3908 and similar 
bots

>From bcc6c988acdd2e6fba38f373abc3e090b3b70581 Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Thu, 24 Oct 2024 22:44:56 -0700
Subject: [PATCH] =?UTF-8?q?Revert=20"[runtimes]=20Probe=20for=20-nostdlib+?=
 =?UTF-8?q?+=20and=20-nostdinc++=20with=20the=20C=20compiler=20=E2=80=A6"?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This reverts commit 75d0281bc81f0040c24d15bdf9c5cc46e9237224.
---
 libcxx/cmake/config-ix.cmake| 12 
 libcxxabi/cmake/config-ix.cmake | 12 
 libcxxabi/src/CMakeLists.txt|  4 ++--
 libunwind/cmake/config-ix.cmake | 12 
 libunwind/src/CMakeLists.txt|  2 +-
 runtimes/CMakeLists.txt | 12 
 6 files changed, 19 insertions(+), 35 deletions(-)

diff --git a/libcxx/cmake/config-ix.cmake b/libcxx/cmake/config-ix.cmake
index 192bad7a7a7fc6..270d80575adcfd 100644
--- a/libcxx/cmake/config-ix.cmake
+++ b/libcxx/cmake/config-ix.cmake
@@ -38,13 +38,9 @@ check_cxx_compiler_flag(-nolibc CXX_SUPPORTS_NOLIBC_FLAG)
 # required during compilation (which has the -nostdlib++ or -nodefaultlibs). 
libc is
 # required for the link to go through. We remove sanitizers from the
 # configuration checks to avoid spurious link errors.
-#
-# Adding flags to CMAKE_REQUIRED_FLAGS will include the flags both when testing
-# compilation of C and C++. Therefore test to make sure that the flags are
-# supported by the C compiler driver, before deciding to include them.
 
-check_c_compiler_flag(-nostdlib++ C_SUPPORTS_NOSTDLIBXX_FLAG)
-if (C_SUPPORTS_NOSTDLIBXX_FLAG)
+check_cxx_compiler_flag(-nostdlib++ CXX_SUPPORTS_NOSTDLIBXX_FLAG)
+if (CXX_SUPPORTS_NOSTDLIBXX_FLAG)
   set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nostdlib++")
 else()
   check_c_compiler_flag(-nodefaultlibs C_SUPPORTS_NODEFAULTLIBS_FLAG)
@@ -55,7 +51,7 @@ endif()
 
 # Only link against compiler-rt manually if we use -nodefaultlibs, since
 # otherwise the compiler will do the right thing on its own.
-if (NOT C_SUPPORTS_NOSTDLIBXX_FLAG AND C_SUPPORTS_NODEFAULTLIBS_FLAG)
+if (NOT CXX_SUPPORTS_NOSTDLIBXX_FLAG AND C_SUPPORTS_NODEFAULTLIBS_FLAG)
   if (LIBCXX_USE_COMPILER_RT)
 include(HandleCompilerRT)
 find_compiler_rt_library(builtins LIBCXX_BUILTINS_LIBRARY
@@ -85,7 +81,7 @@ if (NOT C_SUPPORTS_NOSTDLIBXX_FLAG AND 
C_SUPPORTS_NODEFAULTLIBS_FLAG)
   endif()
 endif()
 
-if (C_SUPPORTS_NOSTDLIBXX_FLAG OR C_SUPPORTS_NODEFAULTLIBS_FLAG)
+if (CXX_SUPPORTS_NOSTDLIBXX_FLAG OR C_SUPPORTS_NODEFAULTLIBS_FLAG)
   if (CMAKE_C_FLAGS MATCHES -fsanitize OR CMAKE_CXX_FLAGS MATCHES -fsanitize)
 set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -fno-sanitize=all")
   endif ()
diff --git a/libcxxabi/cmake/config-ix.cmake b/libcxxabi/cmake/config-ix.cmake
index ab74ad79a654af..10f2087c68c5e7 100644
--- a/libcxxabi/cmake/config-ix.cmake
+++ b/libcxxabi/cmake/config-ix.cmake
@@ -22,13 +22,9 @@ endif ()
 # required during compilation (which has the -nodefaultlibs). libc is
 # required for the link to go through. We remove sanitizers from the
 # configuration checks to avoid spurious link errors.
-#
-# Adding flags to CMAKE_REQUIRED_FLAGS will include the flags both when testing
-# compilation of C and C++. Therefore test to make sure that the flags are
-# supported by the C compiler driver, before deciding to include them.
 
-check_c_compiler_flag(-nostdlib++ C_SUPPORTS_NOSTDLIBXX_FLAG)
-if (C_SUPPORTS_NOSTDLIBXX_FLAG)
+check_cxx_compiler_flag(-nostdlib++ CXX_SUPPORTS_NOSTDLIBXX_FLAG)
+if (CXX_SUPPORTS_NOSTDLIBXX_FLAG)
   set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nostdlib++")
 else()
   check_c_compiler_flag(-nodefaultlibs C_SUPPORTS_NODEFAULTLIBS_FLAG)
@@ -39,7 +35,7 @@ endif()
 
 # Only link against compiler-rt manually if we use -nodefaultlibs, since
 # otherwise the compiler will do the right thing on its own.
-if (NOT C_SUPPORTS_NOSTDLIBXX_FLAG AND C_SUPPORTS_NODEFAULTLIBS_FLAG)
+if (NOT CXX_SUPPORTS_NOSTDLIBXX_FLAG AND C_SUPPORTS_NODEFAULTLIBS_FLAG)
   if (LIBCXXABI_HAS_C_LIB)
 list(APPEND CMAKE_REQUIRED_LIBRARIES c)
   endif ()
@@ -75,7 +71,7 @@ if (NOT C_SUPPORTS_NOSTDLIBXX_FLAG AND 
C_SUPPORTS_NODEFAULTLIBS_FLAG)
   endif()
 endif()
 
-if (C_SUPPORTS_NOSTDLIBXX_FLAG OR C_SUPPORTS_NODEFAULTLIBS_FLAG)
+if (CXX_SUPPORTS_NOSTDLIBXX_FLAG OR C_SUPPORTS_NODEFAULTLIBS_FLAG)
   if (CMAKE_C_FLAGS MATCHES -fsanitize OR CMAKE_CXX_FLAGS MATCHES -fsanitize)
 set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -fno-sanitize=all")
   endif ()
diff --git a/libcxxabi/src/CMakeLists.txt b/libcxxabi/src/CMakeLists.txt
index af8071cbdc8537..84fe2784bec5ca 100644
--- a/libcxxabi/src/CMakeLists.txt
+++ b/libcxxabi/src/CMakeLists.txt
@@ -91,7 +91,7 @@ if (ANDROID AND ANDROID_PLATFORM_LEVEL LESS 21)
 endif()
 
 # Setup flags.
-if (C_SUPPORTS_NOSTDLIBXX_F

[libcxx] [libcxxabi] [libunwind] [llvm] Revert "[runtimes] Probe for -nostdlib++ and -nostdinc++ with the C compiler" (PR #113653)

2024-10-24 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-libunwind

Author: Vitaly Buka (vitalybuka)


Changes

Reverts llvm/llvm-project#108357

Breaks  https://lab.llvm.org/buildbot/#/builders/164/builds/3908 and similar 
bots

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


6 Files Affected:

- (modified) libcxx/cmake/config-ix.cmake (+4-8) 
- (modified) libcxxabi/cmake/config-ix.cmake (+4-8) 
- (modified) libcxxabi/src/CMakeLists.txt (+2-2) 
- (modified) libunwind/cmake/config-ix.cmake (+4-8) 
- (modified) libunwind/src/CMakeLists.txt (+1-1) 
- (modified) runtimes/CMakeLists.txt (+4-8) 


``diff
diff --git a/libcxx/cmake/config-ix.cmake b/libcxx/cmake/config-ix.cmake
index 192bad7a7a7fc6e..270d80575adcfd4 100644
--- a/libcxx/cmake/config-ix.cmake
+++ b/libcxx/cmake/config-ix.cmake
@@ -38,13 +38,9 @@ check_cxx_compiler_flag(-nolibc CXX_SUPPORTS_NOLIBC_FLAG)
 # required during compilation (which has the -nostdlib++ or -nodefaultlibs). 
libc is
 # required for the link to go through. We remove sanitizers from the
 # configuration checks to avoid spurious link errors.
-#
-# Adding flags to CMAKE_REQUIRED_FLAGS will include the flags both when testing
-# compilation of C and C++. Therefore test to make sure that the flags are
-# supported by the C compiler driver, before deciding to include them.
 
-check_c_compiler_flag(-nostdlib++ C_SUPPORTS_NOSTDLIBXX_FLAG)
-if (C_SUPPORTS_NOSTDLIBXX_FLAG)
+check_cxx_compiler_flag(-nostdlib++ CXX_SUPPORTS_NOSTDLIBXX_FLAG)
+if (CXX_SUPPORTS_NOSTDLIBXX_FLAG)
   set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nostdlib++")
 else()
   check_c_compiler_flag(-nodefaultlibs C_SUPPORTS_NODEFAULTLIBS_FLAG)
@@ -55,7 +51,7 @@ endif()
 
 # Only link against compiler-rt manually if we use -nodefaultlibs, since
 # otherwise the compiler will do the right thing on its own.
-if (NOT C_SUPPORTS_NOSTDLIBXX_FLAG AND C_SUPPORTS_NODEFAULTLIBS_FLAG)
+if (NOT CXX_SUPPORTS_NOSTDLIBXX_FLAG AND C_SUPPORTS_NODEFAULTLIBS_FLAG)
   if (LIBCXX_USE_COMPILER_RT)
 include(HandleCompilerRT)
 find_compiler_rt_library(builtins LIBCXX_BUILTINS_LIBRARY
@@ -85,7 +81,7 @@ if (NOT C_SUPPORTS_NOSTDLIBXX_FLAG AND 
C_SUPPORTS_NODEFAULTLIBS_FLAG)
   endif()
 endif()
 
-if (C_SUPPORTS_NOSTDLIBXX_FLAG OR C_SUPPORTS_NODEFAULTLIBS_FLAG)
+if (CXX_SUPPORTS_NOSTDLIBXX_FLAG OR C_SUPPORTS_NODEFAULTLIBS_FLAG)
   if (CMAKE_C_FLAGS MATCHES -fsanitize OR CMAKE_CXX_FLAGS MATCHES -fsanitize)
 set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -fno-sanitize=all")
   endif ()
diff --git a/libcxxabi/cmake/config-ix.cmake b/libcxxabi/cmake/config-ix.cmake
index ab74ad79a654afa..10f2087c68c5e79 100644
--- a/libcxxabi/cmake/config-ix.cmake
+++ b/libcxxabi/cmake/config-ix.cmake
@@ -22,13 +22,9 @@ endif ()
 # required during compilation (which has the -nodefaultlibs). libc is
 # required for the link to go through. We remove sanitizers from the
 # configuration checks to avoid spurious link errors.
-#
-# Adding flags to CMAKE_REQUIRED_FLAGS will include the flags both when testing
-# compilation of C and C++. Therefore test to make sure that the flags are
-# supported by the C compiler driver, before deciding to include them.
 
-check_c_compiler_flag(-nostdlib++ C_SUPPORTS_NOSTDLIBXX_FLAG)
-if (C_SUPPORTS_NOSTDLIBXX_FLAG)
+check_cxx_compiler_flag(-nostdlib++ CXX_SUPPORTS_NOSTDLIBXX_FLAG)
+if (CXX_SUPPORTS_NOSTDLIBXX_FLAG)
   set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -nostdlib++")
 else()
   check_c_compiler_flag(-nodefaultlibs C_SUPPORTS_NODEFAULTLIBS_FLAG)
@@ -39,7 +35,7 @@ endif()
 
 # Only link against compiler-rt manually if we use -nodefaultlibs, since
 # otherwise the compiler will do the right thing on its own.
-if (NOT C_SUPPORTS_NOSTDLIBXX_FLAG AND C_SUPPORTS_NODEFAULTLIBS_FLAG)
+if (NOT CXX_SUPPORTS_NOSTDLIBXX_FLAG AND C_SUPPORTS_NODEFAULTLIBS_FLAG)
   if (LIBCXXABI_HAS_C_LIB)
 list(APPEND CMAKE_REQUIRED_LIBRARIES c)
   endif ()
@@ -75,7 +71,7 @@ if (NOT C_SUPPORTS_NOSTDLIBXX_FLAG AND 
C_SUPPORTS_NODEFAULTLIBS_FLAG)
   endif()
 endif()
 
-if (C_SUPPORTS_NOSTDLIBXX_FLAG OR C_SUPPORTS_NODEFAULTLIBS_FLAG)
+if (CXX_SUPPORTS_NOSTDLIBXX_FLAG OR C_SUPPORTS_NODEFAULTLIBS_FLAG)
   if (CMAKE_C_FLAGS MATCHES -fsanitize OR CMAKE_CXX_FLAGS MATCHES -fsanitize)
 set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -fno-sanitize=all")
   endif ()
diff --git a/libcxxabi/src/CMakeLists.txt b/libcxxabi/src/CMakeLists.txt
index af8071cbdc85371..84fe2784bec5ca8 100644
--- a/libcxxabi/src/CMakeLists.txt
+++ b/libcxxabi/src/CMakeLists.txt
@@ -91,7 +91,7 @@ if (ANDROID AND ANDROID_PLATFORM_LEVEL LESS 21)
 endif()
 
 # Setup flags.
-if (C_SUPPORTS_NOSTDLIBXX_FLAG)
+if (CXX_SUPPORTS_NOSTDLIBXX_FLAG)
   add_link_flags_if_supported(-nostdlib++)
 else()
   add_link_flags_if_supported(-nodefaultlibs)
@@ -167,7 +167,7 @@ if (LIBCXXABI_USE_LLVM_UNWINDER)
   endif()
 endif()
 target_link_libraries(cxxabi_shared_objects PRIVATE cxx-headers 
${LIBCXXABI_LIBRARIES})
-if (NOT C_SUPPORTS_NOSTDLIBXX_FLAG)
+if (NOT CXX_SUPPORTS

[clang-tools-extra] [clang-tidy] Create bugprone-incorrect-enable-shared-from-this check (PR #102299)

2024-10-24 Thread via cfe-commits

MichelleCDjunaidi wrote:

Main history should be resolved now.

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


[libcxx] [libcxxabi] [libunwind] [llvm] Revert "[runtimes] Probe for -nostdlib++ and -nostdinc++ with the C compiler" (PR #113653)

2024-10-24 Thread Fangrui Song via cfe-commits

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


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


[clang] [llvm] [AMDGPU] Add a type for the named barrier (PR #113614)

2024-10-24 Thread Gang Chen via cfe-commits

https://github.com/cmc-rep updated 
https://github.com/llvm/llvm-project/pull/113614

>From 166a4aec8a8ee813be0ee3045563cd45efd944c0 Mon Sep 17 00:00:00 2001
From: gangc 
Date: Thu, 24 Oct 2024 11:18:22 -0700
Subject: [PATCH 1/3] [AMDGPU] Add a type for the named barrier

---
 clang/include/clang/Basic/AMDGPUTypes.def |  8 
 .../include/clang/Serialization/ASTBitCodes.h |  2 +-
 clang/lib/CodeGen/CGDebugInfo.cpp |  7 
 clang/lib/CodeGen/CodeGenTypes.cpp|  4 ++
 clang/test/AST/ast-dump-amdgpu-types.c| 13 --
 .../CodeGen/amdgpu-barrier-type-debug-info.c  |  8 
 .../CodeGenCXX/amdgpu-barrier-typeinfo.cpp| 10 +
 clang/test/CodeGenHIP/amdgpu-barrier-type.hip | 42 +++
 clang/test/SemaCXX/amdgpu-barrier.cpp | 17 
 clang/test/SemaHIP/amdgpu-barrier.hip | 20 +
 clang/test/SemaOpenCL/amdgpu-barrier.cl   | 12 ++
 clang/test/SemaOpenMP/amdgpu-barrier.cpp  | 17 
 llvm/lib/IR/Type.cpp  |  8 
 13 files changed, 163 insertions(+), 5 deletions(-)
 create mode 100644 clang/test/CodeGen/amdgpu-barrier-type-debug-info.c
 create mode 100644 clang/test/CodeGenCXX/amdgpu-barrier-typeinfo.cpp
 create mode 100644 clang/test/CodeGenHIP/amdgpu-barrier-type.hip
 create mode 100644 clang/test/SemaCXX/amdgpu-barrier.cpp
 create mode 100644 clang/test/SemaHIP/amdgpu-barrier.hip
 create mode 100644 clang/test/SemaOpenCL/amdgpu-barrier.cl
 create mode 100644 clang/test/SemaOpenMP/amdgpu-barrier.cpp

diff --git a/clang/include/clang/Basic/AMDGPUTypes.def 
b/clang/include/clang/Basic/AMDGPUTypes.def
index e47e544fdc82c1..6b98e311b4cf55 100644
--- a/clang/include/clang/Basic/AMDGPUTypes.def
+++ b/clang/include/clang/Basic/AMDGPUTypes.def
@@ -15,7 +15,15 @@
   AMDGPU_TYPE(Name, Id, SingletonId, Width, Align)
 #endif
 
+#ifndef AMDGPU_NAMED_BARRIER_TYPE
+#define AMDGPU_NAMED_BARRIER_TYPE(Name, Id, SingletonId, Width, Align, Scope) \
+  AMDGPU_TYPE(Name, Id, SingletonId, Width, Align)
+#endif
+
 AMDGPU_OPAQUE_PTR_TYPE("__amdgpu_buffer_rsrc_t", AMDGPUBufferRsrc, 
AMDGPUBufferRsrcTy, 128, 128, 8)
 
+AMDGPU_NAMED_BARRIER_TYPE("__amdgpu_named_workgroup_barrier_t", 
AMDGPUNamedWorkgroupBarrier, AMDGPUNamedWorkgroupBarrierTy, 128, 32, 0)
+
 #undef AMDGPU_TYPE
 #undef AMDGPU_OPAQUE_PTR_TYPE
+#undef AMDGPU_NAMED_BARRIER_TYPE
\ No newline at end of file
diff --git a/clang/include/clang/Serialization/ASTBitCodes.h 
b/clang/include/clang/Serialization/ASTBitCodes.h
index 13173dc96e71ae..99232fd2135790 100644
--- a/clang/include/clang/Serialization/ASTBitCodes.h
+++ b/clang/include/clang/Serialization/ASTBitCodes.h
@@ -1149,7 +1149,7 @@ enum PredefinedTypeIDs {
 ///
 /// Type IDs for non-predefined types will start at
 /// NUM_PREDEF_TYPE_IDs.
-const unsigned NUM_PREDEF_TYPE_IDS = 511;
+const unsigned NUM_PREDEF_TYPE_IDS = 512;
 
 // Ensure we do not overrun the predefined types we reserved
 // in the enum PredefinedTypeIDs above.
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp 
b/clang/lib/CodeGen/CGDebugInfo.cpp
index 27bbbfc6f531a1..3f9e14a52fc801 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -909,6 +909,13 @@ llvm::DIType *CGDebugInfo::CreateType(const BuiltinType 
*BT) {
  TheCU, TheCU->getFile(), 0);  
\
 return SingletonId;
\
   }
+#define AMDGPU_NAMED_BARRIER_TYPE(Name, Id, SingletonId, Width, Align, Scope)  
\
+  case BuiltinType::Id: {  
 \
+if (!SingletonId)  
\
+  SingletonId =
\
+  DBuilder.createBasicType(Name, Width, llvm::dwarf::DW_ATE_unsigned); 
\
+return SingletonId;
+  }
 #include "clang/Basic/AMDGPUTypes.def"
   case BuiltinType::UChar:
   case BuiltinType::Char_U:
diff --git a/clang/lib/CodeGen/CodeGenTypes.cpp 
b/clang/lib/CodeGen/CodeGenTypes.cpp
index f87184fc77832c..09191a4901f493 100644
--- a/clang/lib/CodeGen/CodeGenTypes.cpp
+++ b/clang/lib/CodeGen/CodeGenTypes.cpp
@@ -564,6 +564,10 @@ llvm::Type *CodeGenTypes::ConvertType(QualType T) {
 #define AMDGPU_OPAQUE_PTR_TYPE(Name, Id, SingletonId, Width, Align, AS)
\
   case BuiltinType::Id:
\
 return llvm::PointerType::get(getLLVMContext(), AS);
+#define AMDGPU_NAMED_BARRIER_TYPE(Name, Id, SingletonId, Width, Align, Scope)  
\
+  case BuiltinType::Id:
\
+return llvm::TargetExtType::get(getLLVMContext(), "amdgcn.named.barrier",  
\
+{}, {Scope});
 #include "clang/Basic/AMDGPUTypes.def"
 #define HLSL_INTANGIBLE_TYPE(Name, Id, SingletonId) case BuiltinType::Id:
 #include "clang/Basic/HLSLIntangibleTypes.def"
diff --git a/clang/test/AST/ast

[clang] [llvm] [HLSL][SPIRV] Added clamp intrinsic (PR #113394)

2024-10-24 Thread Adam Yang via cfe-commits

https://github.com/adam-yang updated 
https://github.com/llvm/llvm-project/pull/113394

>From 8cf5032a5580b97c4c4965e577374f627fbe0643 Mon Sep 17 00:00:00 2001
From: Adam Yang <31109344+adam-y...@users.noreply.github.com>
Date: Mon, 14 Oct 2024 16:35:45 -0700
Subject: [PATCH 1/5] Added the intrinsics and modified the clang test

---
 clang/lib/CodeGen/CGBuiltin.cpp   |  25 ++-
 clang/test/CodeGenHLSL/builtins/clamp.hlsl| 174 +-
 llvm/include/llvm/IR/IntrinsicsSPIRV.td   |   3 +
 .../Target/SPIRV/SPIRVInstructionSelector.cpp |   6 +
 4 files changed, 122 insertions(+), 86 deletions(-)

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 1ad950798c2118..1087537ae4ee29 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -18665,10 +18665,27 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned 
BuiltinID,
 if (auto *VecTy = Ty->getAs())
   Ty = VecTy->getElementType();
 IsUnsigned = Ty->isUnsignedIntegerType();
-return Builder.CreateIntrinsic(
-/*ReturnType=*/OpX->getType(),
-IsUnsigned ? Intrinsic::dx_uclamp : Intrinsic::dx_clamp,
-ArrayRef{OpX, OpMin, OpMax}, nullptr, "dx.clamp");
+switch (CGM.getTarget().getTriple().getArch()) {
+case llvm::Triple::dxil: {
+  return Builder.CreateIntrinsic(
+  /*ReturnType=*/OpX->getType(),
+  IsUnsigned ? Intrinsic::dx_uclamp : Intrinsic::dx_clamp,
+  ArrayRef{OpX, OpMin, OpMax}, nullptr, "dx.clamp");
+} break;
+case llvm::Triple::spirv: {
+  Intrinsic::ID Intr = Intrinsic::spv_sclamp;
+  if (Ty->isFloatingType()) {
+Intr = Intrinsic::spv_fclamp;
+  } else if (IsUnsigned) {
+Intr = Intrinsic::spv_uclamp;
+  }
+  return Builder.CreateIntrinsic(OpX->getType(), Intr,
+ ArrayRef{OpX, OpMin, OpMax},
+ nullptr, "spv.clamp");
+} break;
+default:
+  llvm_unreachable("Intrinsic clamp not supported by target architecture");
+}
   }
   case Builtin::BI__builtin_hlsl_cross: {
 Value *Op0 = EmitScalarExpr(E->getArg(0));
diff --git a/clang/test/CodeGenHLSL/builtins/clamp.hlsl 
b/clang/test/CodeGenHLSL/builtins/clamp.hlsl
index af8f6b9733a071..806e786ae70931 100644
--- a/clang/test/CodeGenHLSL/builtins/clamp.hlsl
+++ b/clang/test/CodeGenHLSL/builtins/clamp.hlsl
@@ -1,133 +1,143 @@
 // RUN: %clang_cc1 -finclude-default-header -triple 
dxil-pc-shadermodel6.3-library %s \
 // RUN:  -fnative-half-type -emit-llvm -disable-llvm-passes -o - | \
-// RUN:  FileCheck %s --check-prefixes=CHECK,NATIVE_HALF
+// RUN:  FileCheck %s --check-prefixes=CHECK,NATIVE_HALF \
+// RUN:  -DSCLAMP="dx.clamp" -DUCLAMP="dx.uclamp" -DFCLAMP="dx.clamp" 
-DFNATTR="noundef"
 // RUN: %clang_cc1 -finclude-default-header -triple 
dxil-pc-shadermodel6.3-library %s \
 // RUN:  -emit-llvm -disable-llvm-passes -o - | \
-// RUN:  FileCheck %s --check-prefixes=CHECK,NO_HALF
+// RUN:  FileCheck %s --check-prefixes=CHECK,NO_HALF \
+// RUN:  -DSCLAMP="dx.clamp" -DUCLAMP="dx.uclamp" -DFCLAMP="dx.clamp" 
-DFNATTR="noundef"
+// RUN: %clang_cc1 -finclude-default-header -triple 
spirv-unknown-vulkan-compute %s \
+// RUN:  -fnative-half-type -emit-llvm -disable-llvm-passes -o - | \
+// RUN:  FileCheck %s --check-prefixes=CHECK,NATIVE_HALF \
+// RUN:  -DSCLAMP="spv.sclamp" -DUCLAMP="spv.uclamp" -DFCLAMP="spv.fclamp" 
-DFNATTR="spir_func noundef"
+// RUN: %clang_cc1 -finclude-default-header -triple 
spirv-unknown-vulkan-compute %s \
+// RUN:  -emit-llvm -disable-llvm-passes -o - | \
+// RUN:  FileCheck %s --check-prefixes=CHECK,NO_HALF \
+// RUN:  -DSCLAMP="spv.sclamp" -DUCLAMP="spv.uclamp" -DFCLAMP="spv.fclamp" 
-DFNATTR="spir_func noundef"
 
 #ifdef __HLSL_ENABLE_16_BIT
-// NATIVE_HALF-LABEL: define noundef i16 @_Z16test_clamp_short
-// NATIVE_HALF: call i16 @llvm.dx.clamp.i16(
+// NATIVE_HALF: define [[FNATTR]] i16 @_Z16test_clamp_short
+// NATIVE_HALF: call i16 @llvm.[[SCLAMP]].i16(
 int16_t test_clamp_short(int16_t p0, int16_t p1) { return clamp(p0, p1,p1); }
-// NATIVE_HALF-LABEL: define noundef <2 x i16> @_Z17test_clamp_short2
-// NATIVE_HALF: call <2 x i16> @llvm.dx.clamp.v2i16(
+// NATIVE_HALF: define [[FNATTR]] <2 x i16> @_Z17test_clamp_short2
+// NATIVE_HALF: call <2 x i16> @llvm.[[SCLAMP]].v2i16(
 int16_t2 test_clamp_short2(int16_t2 p0, int16_t2 p1) { return clamp(p0, 
p1,p1); }
-// NATIVE_HALF-LABEL: define noundef <3 x i16> @_Z17test_clamp_short3
-// NATIVE_HALF: call <3 x i16> @llvm.dx.clamp.v3i16
+// NATIVE_HALF: define [[FNATTR]] <3 x i16> @_Z17test_clamp_short3
+// NATIVE_HALF: call <3 x i16> @llvm.[[SCLAMP]].v3i16
 int16_t3 test_clamp_short3(int16_t3 p0, int16_t3 p1) { return clamp(p0, 
p1,p1); }
-// NATIVE_HALF-LABEL: define noundef <4 x i16> @_Z17test_clamp_short4
-// NATIVE_HALF: call <4 x i16> @llvm.dx.clamp.v4i16
+// NATIVE_HALF: define [[FNATTR]] <4 x i16> @_Z17test_clamp_short4
+// NATIVE_HALF: call <

[clang] [clang-linker-wrapper] Add error handling for missing linker path (PR #113613)

2024-10-24 Thread Arvind Sudarsanam via cfe-commits

asudarsa wrote:

@jhuber6 

Can you please take a look and comment if this change looks ok.

Thanks

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


[clang] [clang-tools-extra] RFC: [clang-tidy] [analyzer] Move nondeterministic pointer usage check to tidy (PR #110471)

2024-10-24 Thread via cfe-commits

https://github.com/vabridgers updated 
https://github.com/llvm/llvm-project/pull/110471

>From 5be6cce0cd2cbc41f92b1f67516e38c30c1aa4ed Mon Sep 17 00:00:00 2001
From: Vince Bridgers 
Date: Thu, 26 Sep 2024 16:24:59 +0200
Subject: [PATCH] [clang-tidy] [analyzer] Move nondeterministic pointer usage
 check to tidy

This change moves the alpha.nondeterministic.PointerSorting and
alpha.nondeterministic.PointerIteration static analyzer checkers to
a single clang-tidy check. Those checkers were implemented as clang-tidy
checks wrapped in the static analyzer framework. The documentation was
updated to describe what the checks can and cannot do, and testing
was completed on a broad set of open source projects.
---
 .../bugprone/BugproneTidyModule.cpp   |   3 +
 .../clang-tidy/bugprone/CMakeLists.txt|   1 +
 ...eterministicPointerIterationOrderCheck.cpp |  85 ++
 ...ndeterministicPointerIterationOrderCheck.h |  37 +
 clang-tools-extra/docs/ReleaseNotes.rst   |   6 +
 ...ndeterministic-pointer-iteration-order.rst |  35 
 .../docs/clang-tidy/checks/list.rst   |   1 +
 .../system-header-simulator/sim_algorithm |  31 
 .../system-header-simulator/sim_c++config.h   |  11 ++
 .../sim_initializer_list  |  39 +
 .../system-header-simulator/sim_iterator_base |  22 +++
 .../Inputs/system-header-simulator/sim_map|  34 
 .../Inputs/system-header-simulator/sim_set|  44 +
 .../system-header-simulator/sim_stl_pair  |  32 
 .../system-header-simulator/sim_type_traits   |  19 +++
 .../system-header-simulator/sim_unordered_map |  33 
 .../system-header-simulator/sim_unordered_set |  35 
 .../Inputs/system-header-simulator/sim_vector | 150 ++
 ...ndeterministic-pointer-iteration-order.cpp |  84 ++
 clang/docs/ReleaseNotes.rst   |   6 +
 clang/docs/analyzer/checkers.rst  |  31 
 .../clang/StaticAnalyzer/Checkers/Checkers.td |  18 ---
 .../StaticAnalyzer/Checkers/CMakeLists.txt|   2 -
 .../Checkers/PointerIterationChecker.cpp  | 101 
 .../Checkers/PointerSortingChecker.cpp| 115 --
 clang/test/Analysis/ptr-iter.cpp  |  28 
 clang/test/Analysis/ptr-sort.cpp  |  36 -
 27 files changed, 708 insertions(+), 331 deletions(-)
 create mode 100644 
clang-tools-extra/clang-tidy/bugprone/NondeterministicPointerIterationOrderCheck.cpp
 create mode 100644 
clang-tools-extra/clang-tidy/bugprone/NondeterministicPointerIterationOrderCheck.h
 create mode 100644 
clang-tools-extra/docs/clang-tidy/checks/bugprone/nondeterministic-pointer-iteration-order.rst
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/Inputs/system-header-simulator/sim_algorithm
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/Inputs/system-header-simulator/sim_c++config.h
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/Inputs/system-header-simulator/sim_initializer_list
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/Inputs/system-header-simulator/sim_iterator_base
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/Inputs/system-header-simulator/sim_map
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/Inputs/system-header-simulator/sim_set
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/Inputs/system-header-simulator/sim_stl_pair
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/Inputs/system-header-simulator/sim_type_traits
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/Inputs/system-header-simulator/sim_unordered_map
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/Inputs/system-header-simulator/sim_unordered_set
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/Inputs/system-header-simulator/sim_vector
 create mode 100644 
clang-tools-extra/test/clang-tidy/checkers/bugprone/nondeterministic-pointer-iteration-order.cpp
 delete mode 100644 
clang/lib/StaticAnalyzer/Checkers/PointerIterationChecker.cpp
 delete mode 100644 clang/lib/StaticAnalyzer/Checkers/PointerSortingChecker.cpp
 delete mode 100644 clang/test/Analysis/ptr-iter.cpp
 delete mode 100644 clang/test/Analysis/ptr-sort.cpp

diff --git a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp 
b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
index 9120c4b6c0d9ae..33ac65e715ce81 100644
--- a/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
+++ b/clang-tools-extra/clang-tidy/bugprone/BugproneTidyModule.cpp
@@ -49,6 +49,7 @@
 #include "MultipleStatementMacroCheck.h"
 #include "NoEscapeCheck.h"
 #include "NonZeroEnumToBoolConversionCheck.h"
+#include "NondeterministicPointerIterationOrderCheck.h"
 #include "NotNullTerminatedResultCheck.h"
 #include "OptionalValueConversionCheck.h"
 #include "ParentVirtual

[clang] [clang-tools-extra] RFC: [clang-tidy] [analyzer] Move nondeterministic pointer usage check to tidy (PR #110471)

2024-10-24 Thread via cfe-commits


@@ -49,6 +49,7 @@
 #include "MultipleStatementMacroCheck.h"
 #include "NoEscapeCheck.h"
 #include "NonZeroEnumToBoolConversionCheck.h"

vabridgers wrote:

I checked the order, clang-format did not complain. Z comes before d (case 
matters it seems). So this begets

 50 #include "NoEscapeCheck.h"
 51 #include "NonZeroEnumToBoolConversionCheck.h"
 52 #include "NondeterministicPointerIterationOrderCheck.h"
 53 #include "NotNullTerminatedResultCheck.h"

Am I missing something?

Thanks!

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


[clang] Remove Linux search paths on Windows (PR #113628)

2024-10-24 Thread David Salinas via cfe-commits

https://github.com/david-salinas created 
https://github.com/llvm/llvm-project/pull/113628

Change-Id: Ia0b44eb1069fa631a6d5156cf5881c978e23b62d

>From 2bcd8608ca1e00893692f1d1f8b1734204abbd15 Mon Sep 17 00:00:00 2001
From: David Salinas 
Date: Tue, 22 Oct 2024 18:58:47 +
Subject: [PATCH] Remove Linux search paths on Windows

Change-Id: Ia0b44eb1069fa631a6d5156cf5881c978e23b62d
---
 clang/lib/Driver/Driver.cpp  |  6 ++--
 clang/lib/Driver/ToolChains/AMDGPU.cpp   | 34 ++--
 clang/lib/Driver/ToolChains/AMDGPU.h |  2 +-
 clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp |  2 +-
 clang/lib/Driver/ToolChains/HIPAMD.cpp   |  9 +-
 clang/lib/Driver/ToolChains/MSVC.cpp |  5 +++
 clang/lib/Driver/ToolChains/ROCm.h   | 12 +++
 clang/test/Driver/rocm-detect-linux.hip  |  9 ++
 clang/test/Driver/rocm-detect-windows.hip|  9 ++
 9 files changed, 72 insertions(+), 16 deletions(-)
 create mode 100644 clang/test/Driver/rocm-detect-linux.hip
 create mode 100644 clang/test/Driver/rocm-detect-windows.hip

diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 9878a9dad78d40..2be0d04d1c5ddf 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -6440,7 +6440,7 @@ const ToolChain &Driver::getToolChain(const ArgList &Args,
   TC = std::make_unique(*this, Target, Args);
   break;
 case llvm::Triple::AMDHSA:
-  TC = std::make_unique(*this, Target, Args);
+  TC = std::make_unique(*this, Target, Args, 
Target.isWindowsMSVCEnvironment());
   break;
 case llvm::Triple::AMDPAL:
 case llvm::Triple::Mesa3D:
@@ -6582,8 +6582,8 @@ const ToolChain &Driver::getOffloadingDeviceToolChain(
 TC = std::make_unique(*this, Target,
HostTC, Args);
   else if (Target.getArch() == llvm::Triple::spirv64 &&
-   Target.getVendor() == llvm::Triple::UnknownVendor &&
-   Target.getOS() == llvm::Triple::UnknownOS)
+ Target.getVendor() == llvm::Triple::UnknownVendor &&
+ Target.getOS() == llvm::Triple::UnknownOS)
 TC = std::make_unique(*this, Target,
HostTC, Args);
   break;
diff --git a/clang/lib/Driver/ToolChains/AMDGPU.cpp 
b/clang/lib/Driver/ToolChains/AMDGPU.cpp
index 2c85d21ebd738c..c6ff2717d9853b 100644
--- a/clang/lib/Driver/ToolChains/AMDGPU.cpp
+++ b/clang/lib/Driver/ToolChains/AMDGPU.cpp
@@ -306,15 +306,18 @@ RocmInstallationDetector::getInstallationPathCandidates() 
{
   LatestVer = Ver;
 }
   }
+
+ if (!isHostWindows()) {
   if (!LatestROCm.empty())
 ROCmSearchDirs.emplace_back(D.SysRoot + "/opt/" + LatestROCm,
 /*StrictChecking=*/true);
 
-  ROCmSearchDirs.emplace_back(D.SysRoot + "/usr/local",
-  /*StrictChecking=*/true);
-  ROCmSearchDirs.emplace_back(D.SysRoot + "/usr",
-  /*StrictChecking=*/true);
-
+ROCmSearchDirs.emplace_back(D.SysRoot + "/usr/local",
+/*StrictChecking=*/true);
+ROCmSearchDirs.emplace_back(D.SysRoot + "/usr",
+/*StrictChecking=*/true);
+ }
+  
   DoPrintROCmSearchDirs();
   return ROCmSearchDirs;
 }
@@ -376,10 +379,15 @@ RocmInstallationDetector::RocmInstallationDetector(
   .str();
   }
 
-  if (DetectHIPRuntime)
-detectHIPRuntime();
-  if (DetectDeviceLib)
-detectDeviceLibrary();
+  // Windows needs to exclude linux style paths from the list of paths to 
search,
+  // so delay these detection functions until after the constructor
+  if (!isHostWindows() && !HostTriple.isWindowsMSVCEnvironment()) {
+if (DetectHIPRuntime)
+  detectHIPRuntime();
+if (DetectDeviceLib)
+  detectDeviceLibrary();
+}
+
 }
 
 void RocmInstallationDetector::detectDeviceLibrary() {
@@ -835,8 +843,11 @@ bool AMDGPUToolChain::isWave64(const llvm::opt::ArgList 
&DriverArgs,
 
 /// ROCM Toolchain
 ROCMToolChain::ROCMToolChain(const Driver &D, const llvm::Triple &Triple,
- const ArgList &Args)
+ const ArgList &Args, bool isHostTCMSVC)
 : AMDGPUToolChain(D, Triple, Args) {
+  RocmInstallation->setHostWindows(isHostTCMSVC);
+  if (isHostTCMSVC) 
+RocmInstallation->init(true, false);
   RocmInstallation->detectDeviceLibrary();
 }
 
@@ -1048,6 +1059,9 @@ ROCMToolChain::getCommonDeviceLibNames(const 
llvm::opt::ArgList &DriverArgs,
   options::OPT_fno_hip_fp32_correctly_rounded_divide_sqrt, true);
   bool Wave64 = isWave64(DriverArgs, Kind);
 
+  /* SALINASif (getTriple().isWindowsMSVCEnvironment())
+RocmInstallation->init(true,true); */
+
   return RocmInstallation->getCommonBitcodeLibs(
   DriverArgs, LibDeviceFile, Wave64, DAZ, FiniteOnly, UnsafeMathOpt,
   FastRelaxedMath, CorrectSqrt, ABIVer, isOpe

[clang] Remove Linux search paths on Windows (PR #113628)

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


[clang] [clang-tools-extra] RFC: [clang-tidy] [analyzer] Move nondeterministic pointer usage check to tidy (PR #110471)

2024-10-24 Thread via cfe-commits


@@ -49,6 +49,7 @@
 #include "MultipleStatementMacroCheck.h"
 #include "NoEscapeCheck.h"
 #include "NonZeroEnumToBoolConversionCheck.h"

EugeneZelenko wrote:

My mistake. Sorry for noise.

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


[clang] Remove Linux search paths on Windows (PR #113628)

2024-10-24 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 7b9f988a535c3549b71025e951e3a36a2bf0fa03 
2bcd8608ca1e00893692f1d1f8b1734204abbd15 --extensions cpp,h -- 
clang/lib/Driver/Driver.cpp clang/lib/Driver/ToolChains/AMDGPU.cpp 
clang/lib/Driver/ToolChains/AMDGPU.h 
clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp 
clang/lib/Driver/ToolChains/HIPAMD.cpp clang/lib/Driver/ToolChains/MSVC.cpp 
clang/lib/Driver/ToolChains/ROCm.h
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index 2be0d04d1c..b652988157 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -6440,7 +6440,8 @@ const ToolChain &Driver::getToolChain(const ArgList &Args,
   TC = std::make_unique(*this, Target, Args);
   break;
 case llvm::Triple::AMDHSA:
-  TC = std::make_unique(*this, Target, Args, 
Target.isWindowsMSVCEnvironment());
+  TC = std::make_unique(
+  *this, Target, Args, Target.isWindowsMSVCEnvironment());
   break;
 case llvm::Triple::AMDPAL:
 case llvm::Triple::Mesa3D:
@@ -6582,8 +6583,8 @@ const ToolChain &Driver::getOffloadingDeviceToolChain(
 TC = std::make_unique(*this, Target,
HostTC, Args);
   else if (Target.getArch() == llvm::Triple::spirv64 &&
- Target.getVendor() == llvm::Triple::UnknownVendor &&
- Target.getOS() == llvm::Triple::UnknownOS)
+   Target.getVendor() == llvm::Triple::UnknownVendor &&
+   Target.getOS() == llvm::Triple::UnknownOS)
 TC = std::make_unique(*this, Target,
HostTC, Args);
   break;
diff --git a/clang/lib/Driver/ToolChains/AMDGPU.cpp 
b/clang/lib/Driver/ToolChains/AMDGPU.cpp
index c6ff2717d9..c7520b0a58 100644
--- a/clang/lib/Driver/ToolChains/AMDGPU.cpp
+++ b/clang/lib/Driver/ToolChains/AMDGPU.cpp
@@ -307,17 +307,17 @@ RocmInstallationDetector::getInstallationPathCandidates() 
{
 }
   }
 
- if (!isHostWindows()) {
-  if (!LatestROCm.empty())
-ROCmSearchDirs.emplace_back(D.SysRoot + "/opt/" + LatestROCm,
-/*StrictChecking=*/true);
+  if (!isHostWindows()) {
+if (!LatestROCm.empty())
+  ROCmSearchDirs.emplace_back(D.SysRoot + "/opt/" + LatestROCm,
+  /*StrictChecking=*/true);
 
 ROCmSearchDirs.emplace_back(D.SysRoot + "/usr/local",
 /*StrictChecking=*/true);
 ROCmSearchDirs.emplace_back(D.SysRoot + "/usr",
 /*StrictChecking=*/true);
- }
-  
+  }
+
   DoPrintROCmSearchDirs();
   return ROCmSearchDirs;
 }
@@ -379,15 +379,14 @@ RocmInstallationDetector::RocmInstallationDetector(
   .str();
   }
 
-  // Windows needs to exclude linux style paths from the list of paths to 
search,
-  // so delay these detection functions until after the constructor
+  // Windows needs to exclude linux style paths from the list of paths to
+  // search, so delay these detection functions until after the constructor
   if (!isHostWindows() && !HostTriple.isWindowsMSVCEnvironment()) {
 if (DetectHIPRuntime)
   detectHIPRuntime();
 if (DetectDeviceLib)
   detectDeviceLibrary();
-}
-
+  }
 }
 
 void RocmInstallationDetector::detectDeviceLibrary() {
@@ -846,7 +845,7 @@ ROCMToolChain::ROCMToolChain(const Driver &D, const 
llvm::Triple &Triple,
  const ArgList &Args, bool isHostTCMSVC)
 : AMDGPUToolChain(D, Triple, Args) {
   RocmInstallation->setHostWindows(isHostTCMSVC);
-  if (isHostTCMSVC) 
+  if (isHostTCMSVC)
 RocmInstallation->init(true, false);
   RocmInstallation->detectDeviceLibrary();
 }
diff --git a/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp 
b/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
index 892db0dbc7..11a5c22e18 100644
--- a/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
+++ b/clang/lib/Driver/ToolChains/AMDGPUOpenMP.cpp
@@ -33,7 +33,9 @@ AMDGPUOpenMPToolChain::AMDGPUOpenMPToolChain(const Driver &D,
  const llvm::Triple &Triple,
  const ToolChain &HostTC,
  const ArgList &Args)
-: ROCMToolChain(D, Triple, Args, 
HostTC.getTriple().isWindowsMSVCEnvironment()), HostTC(HostTC) {
+: ROCMToolChain(D, Triple, Args,
+HostTC.getTriple().isWindowsMSVCEnvironment()),
+  HostTC(HostTC) {
   // Lookup binaries into the driver directory, this is used to
   // discover the 'amdgpu-arch' executable.
   getProgramPaths().push_back(getDriver().Dir);
diff --git a/clang/lib/Driver/ToolChains/HIPAMD.cpp 
b/clang/lib/Driver/ToolChains/HIPAMD.cp

[clang] c4248fa - [X86] Support MOVRS and AVX10.2 instructions. (#113274)

2024-10-24 Thread via cfe-commits

Author: Freddy Ye
Date: 2024-10-25T09:00:19+08:00
New Revision: c4248fa3edd3e2e18219b4fb46561ca1bfd65728

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

LOG: [X86] Support MOVRS and AVX10.2 instructions. (#113274)

Ref.: https://cdrdv2.intel.com/v1/dl/getContent/671368

Added: 
clang/lib/Headers/movrs_avx10_2_512intrin.h
clang/lib/Headers/movrs_avx10_2intrin.h
clang/test/CodeGen/X86/movrs-avx10.2-512-builtins-error-32.c
clang/test/CodeGen/X86/movrs-avx10.2-512-builtins.c
clang/test/CodeGen/X86/movrs-avx10.2-builtins-error-32.c
clang/test/CodeGen/X86/movrs-avx10.2-builtins.c
llvm/test/CodeGen/X86/movrs-avx10.2-512-intrinsics.ll
llvm/test/CodeGen/X86/movrs-avx10.2-intrinsics.ll
llvm/test/MC/Disassembler/X86/movrs-avx10-64.txt
llvm/test/MC/X86/movrs-avx10-att-64.s
llvm/test/MC/X86/movrs-avx10-intel-64.s

Modified: 
clang/docs/ReleaseNotes.rst
clang/include/clang/Basic/BuiltinsX86_64.def
clang/include/clang/Driver/Options.td
clang/lib/Basic/Targets/X86.cpp
clang/lib/Basic/Targets/X86.h
clang/lib/Headers/CMakeLists.txt
clang/lib/Headers/immintrin.h
clang/test/CodeGen/target-builtin-noerror.c
clang/test/Driver/x86-target-features.c
clang/test/Preprocessor/x86_target_features.c
compiler-rt/lib/builtins/cpu_model/x86.c
llvm/docs/ReleaseNotes.md
llvm/include/llvm/IR/IntrinsicsX86.td
llvm/include/llvm/TargetParser/X86TargetParser.def
llvm/lib/Target/X86/X86.td
llvm/lib/Target/X86/X86InstrAVX10.td
llvm/lib/Target/X86/X86InstrPredicates.td
llvm/lib/TargetParser/Host.cpp
llvm/lib/TargetParser/X86TargetParser.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 46021c9c17feac..d7b47cd2e2ee26 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -624,6 +624,9 @@ X86 Support
 
 - All intrinsics in tbmintrin.h can now be used in constant expressions.
 
+- Supported intrinsics for ``MOVRS AND AVX10.2``.
+  * Supported intrinsics of ``_mm(256|512)_(mask(z))_loadrs_epi(8|16|32|64)``.
+
 Arm and AArch64 Support
 ^^^
 

diff  --git a/clang/include/clang/Basic/BuiltinsX86_64.def 
b/clang/include/clang/Basic/BuiltinsX86_64.def
index 2c591edb2835cd..e1e613560167ac 100644
--- a/clang/include/clang/Basic/BuiltinsX86_64.def
+++ b/clang/include/clang/Basic/BuiltinsX86_64.def
@@ -161,6 +161,20 @@ TARGET_BUILTIN(__builtin_ia32_aand64, "vv*SOi", "n", 
"raoint")
 TARGET_BUILTIN(__builtin_ia32_aor64, "vv*SOi", "n", "raoint")
 TARGET_BUILTIN(__builtin_ia32_axor64, "vv*SOi", "n", "raoint")
 
+// MOVRS and AVX10.2
+TARGET_BUILTIN(__builtin_ia32_vmovrsb128, "V16cV16cC*", "nV:128:", 
"movrs,avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vmovrsb256, "V32cV32cC*", "nV:256:", 
"movrs,avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vmovrsb512, "V64cV64cC*", "nV:512:", 
"movrs,avx10.2-512")
+TARGET_BUILTIN(__builtin_ia32_vmovrsd128, "V4iV4iC*", "nV:128:", 
"movrs,avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vmovrsd256, "V8iV8iC*", "nV:256:", 
"movrs,avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vmovrsd512, "V16iV16iC*", "nV:512:", 
"movrs,avx10.2-512")
+TARGET_BUILTIN(__builtin_ia32_vmovrsq128, "V2OiV2OiC*", "nV:128:", 
"movrs,avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vmovrsq256, "V4OiV4OiC*", "nV:256:", 
"movrs,avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vmovrsq512, "V8OiV8OiC*", "nV:512:", 
"movrs,avx10.2-512")
+TARGET_BUILTIN(__builtin_ia32_vmovrsw128, "V8sV8sC*", "nV:128:", 
"movrs,avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vmovrsw256, "V16sV16sC*", "nV:256:", 
"movrs,avx10.2-256")
+TARGET_BUILTIN(__builtin_ia32_vmovrsw512, "V32sV32sC*", "nV:512:", 
"movrs,avx10.2-512")
+
 #undef BUILTIN
 #undef TARGET_BUILTIN
 #undef TARGET_HEADER_BUILTIN

diff  --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 2ddb2f5312148e..62603969eaf8c3 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -6424,6 +6424,8 @@ def mmovdiri : Flag<["-"], "mmovdiri">, 
Group;
 def mno_movdiri : Flag<["-"], "mno-movdiri">, Group;
 def mmovdir64b : Flag<["-"], "mmovdir64b">, Group;
 def mno_movdir64b : Flag<["-"], "mno-movdir64b">, Group;
+def mmovrs : Flag<["-"], "mmovrs">, Group;
+def mno_movrs : Flag<["-"], "mno-movrs">, Group;
 def mmwaitx : Flag<["-"], "mmwaitx">, Group;
 def mno_mwaitx : Flag<["-"], "mno-mwaitx">, Group;
 def mpku : Flag<["-"], "mpku">, Group;

diff  --git a/clang/lib/Basic/Targets/X86.cpp b/clang/lib/Basic/Targets/X86.cpp
index 5448bd841959f4..d067ec218b5270 100644
--- a/clang/lib/Basic/Targets/X86.cpp
+++ b/clang/lib/Basic/Targets/X86.cpp
@@ -348,6 +348,8 @@ bool 
X86TargetInfo::handleTargetFeatures(std::vector &Features,
   HasSM4 = true

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

2024-10-24 Thread Finn Plummer via cfe-commits

https://github.com/inbelic edited 
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] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2024-10-24 Thread via cfe-commits


@@ -0,0 +1,584 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fexperimental-late-parse-attributes -fsyntax-only -verify 
%s
+
+#define __counted_by(f)  __attribute__((counted_by(f)))
+
+// 
=
+// # Struct incomplete type with attribute in the decl position
+// 
=
+
+// Note: This could be considered misleading. The typedef isn't actually on 
this
+// line. Also note the discrepancy in diagnostic count (27 vs 51) is due to
+// the pointer arithmetic on incomplete pointee type diagnostic always using
+// diagnostic text that refers to the underlying forward decl, even when the
+// typedef is used.
+// expected-note@+1 27{{forward declaration of 'Incomplete_t' (aka 'struct 
IncompleteTy')}}
+struct IncompleteTy; // expected-note 51{{forward declaration of 'struct 
IncompleteTy'}}
+
+typedef struct IncompleteTy Incomplete_t; 
+
+struct CBBufDeclPos {
+  int count;
+  struct IncompleteTy* buf __counted_by(count); // OK expected-note 
27{{__counted_by attribute is here}}
+  Incomplete_t* buf_typedef __counted_by(count); // OK expected-note 
27{{__counted_by attribute is here}}
+};
+
+void consume_struct_IncompleteTy(struct IncompleteTy* buf);
+
+int idx(void);
+
+
+
+void test_CBBufDeclPos(struct CBBufDeclPos* ptr) {
+  // 
===
+  // ## Local variable initialization
+  // 
===
+  struct CBBufDeclPos explicit_desig_init = {
+.count = 0,
+// expected-error@+1{{cannot initialize 'CBBufDeclPos::buf' that has type 
'struct IncompleteTy * __counted_by(count)' (aka 'struct IncompleteTy *') 
because the pointee type 'struct IncompleteTy' is incomplete and the 
'__counted_by' attribute requires the pointee type be complete when 
initializing; consider providing a complete definition for 'struct 
IncompleteTy' or using the '__sized_by' attribute}}
+.buf = 0x0,
+// expected-error@+1{{cannot initialize 'CBBufDeclPos::buf_typedef' that 
has type 'Incomplete_t * __counted_by(count)' (aka 'struct IncompleteTy *') 
because the pointee type 'Incomplete_t' (aka 'struct IncompleteTy') is 
incomplete and the '__counted_by' attribute requires the pointee type be 
complete when initializing; consider providing a complete definition for 
'Incomplete_t' or using the '__sized_by' attribute}}
+.buf_typedef = 0x0
+  };
+  // Variable is not currently marked as invalid so uses of the variable allows
+  // diagnostics to fire.
+  // expected-error@+1{{cannot assign to 'CBBufDeclPos::buf' that has type 
'struct IncompleteTy * __counted_by(count)' (aka 'struct IncompleteTy *') 
because the pointee type 'struct IncompleteTy' is incomplete and the 
'__counted_by' attribute requires the pointee type be complete when assigning; 
consider providing a complete definition for 'struct IncompleteTy' or using the 
'__sized_by' attribute}}
+  explicit_desig_init.buf = 0x0;
+  // expected-error@+1{{cannot assign to 'CBBufDeclPos::buf_typedef' that has 
type 'Incomplete_t * __counted_by(count)' (aka 'struct IncompleteTy *') because 
the pointee type 'Incomplete_t' (aka 'struct IncompleteTy') is incomplete and 
the '__counted_by' attribute requires the pointee type be complete when 
assigning; consider providing a complete definition for 'Incomplete_t' or using 
the '__sized_by' attribute}}
+  explicit_desig_init.buf_typedef = 0x0;
+  // expected-error@+1{{cannot use 'explicit_desig_init.buf' with type 'struct 
IncompleteTy * __counted_by(count)' (aka 'struct IncompleteTy *') because the 
pointee type 'struct IncompleteTy' is incomplete and the '__counted_by' 
attribute requires the pointee type be complete in this context; consider 
providing a complete definition for 'struct IncompleteTy' or using the 
'__sized_by' attribute}}
+  void *tmp = explicit_desig_init.buf;
+  // expected-error@+1{{cannot use 'explicit_desig_init.buf_typedef' with type 
'Incomplete_t * __counted_by(count)' (aka 'struct IncompleteTy *') because the 
pointee type 'Incomplete_t' (aka 'struct IncompleteTy') is incomplete and the 
'__counted_by' attribute requires the pointee type be complete in this context; 
consider providing a complete definition for 'Incomplete_t' or using the 
'__sized_by' attribute}}
+  void *tmp2 = explicit_desig_init.buf_typedef;
+
+  struct CBBufDeclPos partial_explicit_desig_init = {
+.count = 0,
+// .buf and .buf_typedef are implicit zero initialized
+// expected-error@+2{{cannot implicitly initialize 'CBBufDeclPos::buf' 
that has type 'struct IncompleteTy * __counted_by(count)' (aka 'struct 
IncompleteTy *') because the pointee type 'struct IncompleteTy' is incomplete 
and the '__counted_by' attribute requires the pointee type be complete when 
initializing; consider providing a complete defin

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2024-10-24 Thread via cfe-commits


@@ -186,4 +218,216 @@ bool Sema::CheckCountedByAttrOnField(FieldDecl *FD, Expr 
*E, bool CountInBytes,
   return false;
 }
 
+SourceRange Sema::BoundsSafetySourceRangeFor(const CountAttributedType *CATy) {
+  // This is an approximation that's not quite right. This points to the
+  // the expression inside the attribute rather than the attribute itself.
+  //
+  // TODO: Implement logic to find the relevant TypeLoc for the attribute and
+  // get the SourceRange from that (#113582).
+  return CATy->getCountExpr()->getSourceRange();
+}
+
+static void EmitIncompleteCountedByPointeeNotes(Sema &S,
+const CountAttributedType 
*CATy,
+NamedDecl *IncompleteTyDecl,
+bool NoteAttrLocation = true) {
+  assert(IncompleteTyDecl == nullptr || isa(IncompleteTyDecl));
+
+  if (NoteAttrLocation) {
+// Note where the attribute is declared
+auto AttrSrcRange = S.BoundsSafetySourceRangeFor(CATy);
+S.Diag(AttrSrcRange.getBegin(), diag::note_named_attribute)
+<< CATy->getAttributeName(/*WithMacroPrefix=*/true) << AttrSrcRange;
+  }
+
+  if (!IncompleteTyDecl)
+return;
+
+  // If there's an associated forward declaration display it to emphasize
+  // why the type is incomplete (all we have is a forward declaration).
+
+  // Note the `IncompleteTyDecl` type is the underlying type which might not
+  // be the same as `CATy->getPointeeType()` which could be a typedef.
+  //
+  // The diagnostic printed will be at the location of the underlying type but
+  // the diagnostic text will print the type of `CATy->getPointeeType()` which
+  // could be a typedef name rather than the underlying type. This is ok
+  // though because the diagnostic will print the underlying type name too.
+  // E.g:
+  //
+  // `forward declaration of 'Incomplete_Struct_t'
+  //  (aka 'struct IncompleteStructTy')`
+  //
+  // If this ends up being confusing we could emit a second diagnostic (one
+  // explaining where the typedef is) but that seems overly verbose.
+
+  S.Diag(IncompleteTyDecl->getBeginLoc(), diag::note_forward_declaration)
+  << CATy->getPointeeType();
+}
+
+static bool
+HasCountedByAttrOnIncompletePointee(QualType Ty, NamedDecl **ND,
+const CountAttributedType **CATyOut,
+QualType *PointeeTyOut) {
+  auto *CATy = Ty->getAs();
+  if (!CATy)
+return false;
+
+  // Incomplete pointee type is only a problem for
+  // counted_by/counted_by_or_null
+  if (CATy->isCountInBytes())
+return false;
+
+  auto PointeeTy = CATy->getPointeeType();
+  if (PointeeTy.isNull())
+return false; // Reachable?
+
+  if (!PointeeTy->isIncompleteType(ND))
+return false;
+
+  if (CATyOut)
+*CATyOut = CATy;
+  if (PointeeTyOut)
+*PointeeTyOut = PointeeTy;
+  return true;
+}
+
+/// Perform Checks for assigning to a `__counted_by` or
+/// `__counted_by_or_null` pointer type \param LHSTy where the pointee type
+/// is incomplete which is invalid.
+///
+/// \param S The Sema instance.
+/// \param LHSTy The type being assigned to. Checks will only be performed if
+///  the type is a `counted_by` or `counted_by_or_null ` pointer.
+/// \param RHSExpr The expression being assigned from.
+/// \param Action The type assignment being performed
+/// \param Loc The SourceLocation to use for error diagnostics
+/// \param ComputeAssignee If provided this function will be called before
+///emitting a diagnostic. The function should return the name of
+///entity being assigned to or an empty string if this cannot be
+///determined.
+///
+/// \returns True iff no diagnostic where emitted, false otherwise.
+static bool CheckAssignmentToCountAttrPtrWithIncompletePointeeTy(
+Sema &S, QualType LHSTy, Expr *RHSExpr, AssignmentAction Action,
+SourceLocation Loc, llvm::function_ref ComputeAssignee) {
+  NamedDecl *IncompleteTyDecl = nullptr;
+  const CountAttributedType *CATy = nullptr;
+  QualType PointeeTy;
+  if (!HasCountedByAttrOnIncompletePointee(LHSTy, &IncompleteTyDecl, &CATy,
+   &PointeeTy))
+return true;
+  assert(CATy && !CATy->isCountInBytes() && !PointeeTy.isNull());
+
+  // It's not expected that the diagnostic be emitted in these cases.
+  // It's not necessarily a problem but we should catch when this starts
+  // to happen.
+  assert(Action != AssignmentAction::Converting &&
+ Action != AssignmentAction::Sending &&
+ Action != AssignmentAction::Casting &&
+ Action != AssignmentAction::Passing_CFAudited);
+
+  // By having users provide a function we only pay the cost of allocation the
+  // string and computing when a diagnostic is emitted.
+  std::string Assignee = ComputeAssignee ? ComputeAssignee() : "";
+  {
+auto D = S.Diag(Loc, diag::err_counted_by_on_incomplete_type_on_ass

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2024-10-24 Thread via cfe-commits


@@ -186,4 +218,216 @@ bool Sema::CheckCountedByAttrOnField(FieldDecl *FD, Expr 
*E, bool CountInBytes,
   return false;
 }
 
+SourceRange Sema::BoundsSafetySourceRangeFor(const CountAttributedType *CATy) {
+  // This is an approximation that's not quite right. This points to the
+  // the expression inside the attribute rather than the attribute itself.
+  //
+  // TODO: Implement logic to find the relevant TypeLoc for the attribute and
+  // get the SourceRange from that (#113582).
+  return CATy->getCountExpr()->getSourceRange();
+}
+
+static void EmitIncompleteCountedByPointeeNotes(Sema &S,
+const CountAttributedType 
*CATy,
+NamedDecl *IncompleteTyDecl,
+bool NoteAttrLocation = true) {
+  assert(IncompleteTyDecl == nullptr || isa(IncompleteTyDecl));
+
+  if (NoteAttrLocation) {
+// Note where the attribute is declared
+auto AttrSrcRange = S.BoundsSafetySourceRangeFor(CATy);
+S.Diag(AttrSrcRange.getBegin(), diag::note_named_attribute)
+<< CATy->getAttributeName(/*WithMacroPrefix=*/true) << AttrSrcRange;
+  }
+
+  if (!IncompleteTyDecl)
+return;
+
+  // If there's an associated forward declaration display it to emphasize
+  // why the type is incomplete (all we have is a forward declaration).
+
+  // Note the `IncompleteTyDecl` type is the underlying type which might not
+  // be the same as `CATy->getPointeeType()` which could be a typedef.
+  //
+  // The diagnostic printed will be at the location of the underlying type but
+  // the diagnostic text will print the type of `CATy->getPointeeType()` which
+  // could be a typedef name rather than the underlying type. This is ok
+  // though because the diagnostic will print the underlying type name too.
+  // E.g:
+  //
+  // `forward declaration of 'Incomplete_Struct_t'
+  //  (aka 'struct IncompleteStructTy')`
+  //
+  // If this ends up being confusing we could emit a second diagnostic (one
+  // explaining where the typedef is) but that seems overly verbose.
+
+  S.Diag(IncompleteTyDecl->getBeginLoc(), diag::note_forward_declaration)
+  << CATy->getPointeeType();
+}
+
+static bool
+HasCountedByAttrOnIncompletePointee(QualType Ty, NamedDecl **ND,
+const CountAttributedType **CATyOut,
+QualType *PointeeTyOut) {

Sirraide wrote:

We could change this to return a tuple instead of taking three out-parameters. 
All but the last `return` here could just be `return {}`, and we could 
destructure the return value at the call site (and check if the pointee type is 
non-null to see if it succeeded), which imo is a bit more ergonomic.

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


[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2024-10-24 Thread via cfe-commits


@@ -186,4 +218,370 @@ bool Sema::CheckCountedByAttrOnField(FieldDecl *FD, Expr 
*E, bool CountInBytes,
   return false;
 }
 
+SourceRange Sema::BoundsSafetySourceRangeFor(const CountAttributedType *CATy) {

Sirraide wrote:

> [#108631](https://github.com/llvm/llvm-project/pull/108631) seems to have 
> similar issues with wanting to access `AttributedTypeLoc` when all they have 
> is `AttributedType`. We might need to improve the infrastructure for 
> accessing `TypeLoc`s in a more ergonomic fashion.

Yeah, ideally, the attribute should really be moved from `AttributedTypeLoc` 
into `AttributedType` (Aaron and I had a discussion about this a few months 
back); this isn’t the first time we’ve run into problems because of that, but 
unfortunately, that wouldn’t even fix this because `CountAttributedType` is not 
an `AttributedType` (on that note, we have a lot of types that basically just 
implement an attribute; I wonder if there’d be a way to merge some of them and 
use just `AttributedType` instead once it actually stores the attribute, but 
that’s a different matter altogether ;Þ)

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


[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2024-10-24 Thread via cfe-commits


@@ -186,4 +218,216 @@ bool Sema::CheckCountedByAttrOnField(FieldDecl *FD, Expr 
*E, bool CountInBytes,
   return false;
 }
 
+SourceRange Sema::BoundsSafetySourceRangeFor(const CountAttributedType *CATy) {
+  // This is an approximation that's not quite right. This points to the
+  // the expression inside the attribute rather than the attribute itself.
+  //
+  // TODO: Implement logic to find the relevant TypeLoc for the attribute and
+  // get the SourceRange from that (#113582).
+  return CATy->getCountExpr()->getSourceRange();
+}
+
+static void EmitIncompleteCountedByPointeeNotes(Sema &S,
+const CountAttributedType 
*CATy,
+NamedDecl *IncompleteTyDecl,
+bool NoteAttrLocation = true) {
+  assert(IncompleteTyDecl == nullptr || isa(IncompleteTyDecl));
+
+  if (NoteAttrLocation) {
+// Note where the attribute is declared
+auto AttrSrcRange = S.BoundsSafetySourceRangeFor(CATy);
+S.Diag(AttrSrcRange.getBegin(), diag::note_named_attribute)
+<< CATy->getAttributeName(/*WithMacroPrefix=*/true) << AttrSrcRange;
+  }
+
+  if (!IncompleteTyDecl)
+return;
+
+  // If there's an associated forward declaration display it to emphasize
+  // why the type is incomplete (all we have is a forward declaration).
+
+  // Note the `IncompleteTyDecl` type is the underlying type which might not
+  // be the same as `CATy->getPointeeType()` which could be a typedef.
+  //
+  // The diagnostic printed will be at the location of the underlying type but
+  // the diagnostic text will print the type of `CATy->getPointeeType()` which
+  // could be a typedef name rather than the underlying type. This is ok
+  // though because the diagnostic will print the underlying type name too.
+  // E.g:
+  //
+  // `forward declaration of 'Incomplete_Struct_t'
+  //  (aka 'struct IncompleteStructTy')`
+  //
+  // If this ends up being confusing we could emit a second diagnostic (one
+  // explaining where the typedef is) but that seems overly verbose.
+
+  S.Diag(IncompleteTyDecl->getBeginLoc(), diag::note_forward_declaration)
+  << CATy->getPointeeType();
+}
+
+static bool
+HasCountedByAttrOnIncompletePointee(QualType Ty, NamedDecl **ND,
+const CountAttributedType **CATyOut,
+QualType *PointeeTyOut) {
+  auto *CATy = Ty->getAs();
+  if (!CATy)
+return false;
+
+  // Incomplete pointee type is only a problem for
+  // counted_by/counted_by_or_null
+  if (CATy->isCountInBytes())
+return false;
+
+  auto PointeeTy = CATy->getPointeeType();
+  if (PointeeTy.isNull())
+return false; // Reachable?
+
+  if (!PointeeTy->isIncompleteType(ND))
+return false;
+
+  if (CATyOut)
+*CATyOut = CATy;
+  if (PointeeTyOut)
+*PointeeTyOut = PointeeTy;
+  return true;
+}
+
+/// Perform Checks for assigning to a `__counted_by` or
+/// `__counted_by_or_null` pointer type \param LHSTy where the pointee type
+/// is incomplete which is invalid.
+///
+/// \param S The Sema instance.
+/// \param LHSTy The type being assigned to. Checks will only be performed if
+///  the type is a `counted_by` or `counted_by_or_null ` pointer.
+/// \param RHSExpr The expression being assigned from.
+/// \param Action The type assignment being performed
+/// \param Loc The SourceLocation to use for error diagnostics
+/// \param ComputeAssignee If provided this function will be called before
+///emitting a diagnostic. The function should return the name of
+///entity being assigned to or an empty string if this cannot be
+///determined.
+///
+/// \returns True iff no diagnostic where emitted, false otherwise.
+static bool CheckAssignmentToCountAttrPtrWithIncompletePointeeTy(
+Sema &S, QualType LHSTy, Expr *RHSExpr, AssignmentAction Action,
+SourceLocation Loc, llvm::function_ref ComputeAssignee) {

Sirraide wrote:

Instead of the `ComputeAssignee` parameter being a function, can’t we just pass 
a `DeclarationName` to this function instead? All the uses I saw at least end 
up passing in the name of some declaration—or are there cases where we 
need/want to pass in some other string?

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


[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2024-10-24 Thread via cfe-commits


@@ -0,0 +1,584 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fexperimental-late-parse-attributes -fsyntax-only -verify 
%s
+
+#define __counted_by(f)  __attribute__((counted_by(f)))
+
+// 
=
+// # Struct incomplete type with attribute in the decl position
+// 
=
+
+// Note: This could be considered misleading. The typedef isn't actually on 
this
+// line. Also note the discrepancy in diagnostic count (27 vs 51) is due to
+// the pointer arithmetic on incomplete pointee type diagnostic always using
+// diagnostic text that refers to the underlying forward decl, even when the
+// typedef is used.
+// expected-note@+1 27{{forward declaration of 'Incomplete_t' (aka 'struct 
IncompleteTy')}}
+struct IncompleteTy; // expected-note 51{{forward declaration of 'struct 
IncompleteTy'}}
+
+typedef struct IncompleteTy Incomplete_t; 
+
+struct CBBufDeclPos {
+  int count;
+  struct IncompleteTy* buf __counted_by(count); // OK expected-note 
27{{__counted_by attribute is here}}
+  Incomplete_t* buf_typedef __counted_by(count); // OK expected-note 
27{{__counted_by attribute is here}}
+};
+
+void consume_struct_IncompleteTy(struct IncompleteTy* buf);
+
+int idx(void);
+
+
+
+void test_CBBufDeclPos(struct CBBufDeclPos* ptr) {
+  // 
===
+  // ## Local variable initialization
+  // 
===
+  struct CBBufDeclPos explicit_desig_init = {
+.count = 0,
+// expected-error@+1{{cannot initialize 'CBBufDeclPos::buf' that has type 
'struct IncompleteTy * __counted_by(count)' (aka 'struct IncompleteTy *') 
because the pointee type 'struct IncompleteTy' is incomplete and the 
'__counted_by' attribute requires the pointee type be complete when 
initializing; consider providing a complete definition for 'struct 
IncompleteTy' or using the '__sized_by' attribute}}
+.buf = 0x0,
+// expected-error@+1{{cannot initialize 'CBBufDeclPos::buf_typedef' that 
has type 'Incomplete_t * __counted_by(count)' (aka 'struct IncompleteTy *') 
because the pointee type 'Incomplete_t' (aka 'struct IncompleteTy') is 
incomplete and the '__counted_by' attribute requires the pointee type be 
complete when initializing; consider providing a complete definition for 
'Incomplete_t' or using the '__sized_by' attribute}}
+.buf_typedef = 0x0
+  };
+  // Variable is not currently marked as invalid so uses of the variable allows
+  // diagnostics to fire.
+  // expected-error@+1{{cannot assign to 'CBBufDeclPos::buf' that has type 
'struct IncompleteTy * __counted_by(count)' (aka 'struct IncompleteTy *') 
because the pointee type 'struct IncompleteTy' is incomplete and the 
'__counted_by' attribute requires the pointee type be complete when assigning; 
consider providing a complete definition for 'struct IncompleteTy' or using the 
'__sized_by' attribute}}
+  explicit_desig_init.buf = 0x0;
+  // expected-error@+1{{cannot assign to 'CBBufDeclPos::buf_typedef' that has 
type 'Incomplete_t * __counted_by(count)' (aka 'struct IncompleteTy *') because 
the pointee type 'Incomplete_t' (aka 'struct IncompleteTy') is incomplete and 
the '__counted_by' attribute requires the pointee type be complete when 
assigning; consider providing a complete definition for 'Incomplete_t' or using 
the '__sized_by' attribute}}
+  explicit_desig_init.buf_typedef = 0x0;
+  // expected-error@+1{{cannot use 'explicit_desig_init.buf' with type 'struct 
IncompleteTy * __counted_by(count)' (aka 'struct IncompleteTy *') because the 
pointee type 'struct IncompleteTy' is incomplete and the '__counted_by' 
attribute requires the pointee type be complete in this context; consider 
providing a complete definition for 'struct IncompleteTy' or using the 
'__sized_by' attribute}}
+  void *tmp = explicit_desig_init.buf;
+  // expected-error@+1{{cannot use 'explicit_desig_init.buf_typedef' with type 
'Incomplete_t * __counted_by(count)' (aka 'struct IncompleteTy *') because the 
pointee type 'Incomplete_t' (aka 'struct IncompleteTy') is incomplete and the 
'__counted_by' attribute requires the pointee type be complete in this context; 
consider providing a complete definition for 'Incomplete_t' or using the 
'__sized_by' attribute}}
+  void *tmp2 = explicit_desig_init.buf_typedef;
+
+  struct CBBufDeclPos partial_explicit_desig_init = {
+.count = 0,
+// .buf and .buf_typedef are implicit zero initialized
+// expected-error@+2{{cannot implicitly initialize 'CBBufDeclPos::buf' 
that has type 'struct IncompleteTy * __counted_by(count)' (aka 'struct 
IncompleteTy *') because the pointee type 'struct IncompleteTy' is incomplete 
and the '__counted_by' attribute requires the pointee type be complete when 
initializing; consider providing a complete defin

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2024-10-24 Thread via cfe-commits


@@ -186,4 +218,216 @@ bool Sema::CheckCountedByAttrOnField(FieldDecl *FD, Expr 
*E, bool CountInBytes,
   return false;
 }
 
+SourceRange Sema::BoundsSafetySourceRangeFor(const CountAttributedType *CATy) {
+  // This is an approximation that's not quite right. This points to the
+  // the expression inside the attribute rather than the attribute itself.
+  //
+  // TODO: Implement logic to find the relevant TypeLoc for the attribute and
+  // get the SourceRange from that (#113582).
+  return CATy->getCountExpr()->getSourceRange();
+}
+
+static void EmitIncompleteCountedByPointeeNotes(Sema &S,
+const CountAttributedType 
*CATy,
+NamedDecl *IncompleteTyDecl,
+bool NoteAttrLocation = true) {
+  assert(IncompleteTyDecl == nullptr || isa(IncompleteTyDecl));
+
+  if (NoteAttrLocation) {
+// Note where the attribute is declared
+auto AttrSrcRange = S.BoundsSafetySourceRangeFor(CATy);
+S.Diag(AttrSrcRange.getBegin(), diag::note_named_attribute)
+<< CATy->getAttributeName(/*WithMacroPrefix=*/true) << AttrSrcRange;
+  }
+
+  if (!IncompleteTyDecl)
+return;
+
+  // If there's an associated forward declaration display it to emphasize
+  // why the type is incomplete (all we have is a forward declaration).
+
+  // Note the `IncompleteTyDecl` type is the underlying type which might not
+  // be the same as `CATy->getPointeeType()` which could be a typedef.
+  //
+  // The diagnostic printed will be at the location of the underlying type but
+  // the diagnostic text will print the type of `CATy->getPointeeType()` which
+  // could be a typedef name rather than the underlying type. This is ok
+  // though because the diagnostic will print the underlying type name too.
+  // E.g:
+  //
+  // `forward declaration of 'Incomplete_Struct_t'
+  //  (aka 'struct IncompleteStructTy')`
+  //
+  // If this ends up being confusing we could emit a second diagnostic (one
+  // explaining where the typedef is) but that seems overly verbose.
+
+  S.Diag(IncompleteTyDecl->getBeginLoc(), diag::note_forward_declaration)
+  << CATy->getPointeeType();
+}
+
+static bool
+HasCountedByAttrOnIncompletePointee(QualType Ty, NamedDecl **ND,
+const CountAttributedType **CATyOut,
+QualType *PointeeTyOut) {
+  auto *CATy = Ty->getAs();
+  if (!CATy)
+return false;
+
+  // Incomplete pointee type is only a problem for
+  // counted_by/counted_by_or_null
+  if (CATy->isCountInBytes())
+return false;
+
+  auto PointeeTy = CATy->getPointeeType();
+  if (PointeeTy.isNull())
+return false; // Reachable?
+
+  if (!PointeeTy->isIncompleteType(ND))
+return false;
+
+  if (CATyOut)
+*CATyOut = CATy;
+  if (PointeeTyOut)
+*PointeeTyOut = PointeeTy;
+  return true;
+}
+
+/// Perform Checks for assigning to a `__counted_by` or
+/// `__counted_by_or_null` pointer type \param LHSTy where the pointee type
+/// is incomplete which is invalid.
+///
+/// \param S The Sema instance.
+/// \param LHSTy The type being assigned to. Checks will only be performed if
+///  the type is a `counted_by` or `counted_by_or_null ` pointer.
+/// \param RHSExpr The expression being assigned from.
+/// \param Action The type assignment being performed
+/// \param Loc The SourceLocation to use for error diagnostics
+/// \param ComputeAssignee If provided this function will be called before
+///emitting a diagnostic. The function should return the name of
+///entity being assigned to or an empty string if this cannot be
+///determined.
+///
+/// \returns True iff no diagnostic where emitted, false otherwise.
+static bool CheckAssignmentToCountAttrPtrWithIncompletePointeeTy(
+Sema &S, QualType LHSTy, Expr *RHSExpr, AssignmentAction Action,
+SourceLocation Loc, llvm::function_ref ComputeAssignee) {
+  NamedDecl *IncompleteTyDecl = nullptr;
+  const CountAttributedType *CATy = nullptr;
+  QualType PointeeTy;
+  if (!HasCountedByAttrOnIncompletePointee(LHSTy, &IncompleteTyDecl, &CATy,
+   &PointeeTy))
+return true;
+  assert(CATy && !CATy->isCountInBytes() && !PointeeTy.isNull());
+
+  // It's not expected that the diagnostic be emitted in these cases.
+  // It's not necessarily a problem but we should catch when this starts
+  // to happen.
+  assert(Action != AssignmentAction::Converting &&
+ Action != AssignmentAction::Sending &&
+ Action != AssignmentAction::Casting &&
+ Action != AssignmentAction::Passing_CFAudited);
+
+  // By having users provide a function we only pay the cost of allocation the
+  // string and computing when a diagnostic is emitted.
+  std::string Assignee = ComputeAssignee ? ComputeAssignee() : "";
+  {
+auto D = S.Diag(Loc, diag::err_counted_by_on_incomplete_type_on_ass

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2024-10-24 Thread via cfe-commits


@@ -186,4 +218,370 @@ bool Sema::CheckCountedByAttrOnField(FieldDecl *FD, Expr 
*E, bool CountInBytes,
   return false;
 }
 
+SourceRange Sema::BoundsSafetySourceRangeFor(const CountAttributedType *CATy) {

Sirraide wrote:

I think this function can just be inlined at this point

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


[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2024-10-24 Thread via cfe-commits


@@ -186,4 +218,216 @@ bool Sema::CheckCountedByAttrOnField(FieldDecl *FD, Expr 
*E, bool CountInBytes,
   return false;
 }
 
+SourceRange Sema::BoundsSafetySourceRangeFor(const CountAttributedType *CATy) {
+  // This is an approximation that's not quite right. This points to the
+  // the expression inside the attribute rather than the attribute itself.
+  //
+  // TODO: Implement logic to find the relevant TypeLoc for the attribute and
+  // get the SourceRange from that (#113582).
+  return CATy->getCountExpr()->getSourceRange();
+}
+
+static void EmitIncompleteCountedByPointeeNotes(Sema &S,
+const CountAttributedType 
*CATy,
+NamedDecl *IncompleteTyDecl,
+bool NoteAttrLocation = true) {
+  assert(IncompleteTyDecl == nullptr || isa(IncompleteTyDecl));
+
+  if (NoteAttrLocation) {
+// Note where the attribute is declared
+auto AttrSrcRange = S.BoundsSafetySourceRangeFor(CATy);
+S.Diag(AttrSrcRange.getBegin(), diag::note_named_attribute)
+<< CATy->getAttributeName(/*WithMacroPrefix=*/true) << AttrSrcRange;
+  }
+
+  if (!IncompleteTyDecl)
+return;
+
+  // If there's an associated forward declaration display it to emphasize
+  // why the type is incomplete (all we have is a forward declaration).
+
+  // Note the `IncompleteTyDecl` type is the underlying type which might not
+  // be the same as `CATy->getPointeeType()` which could be a typedef.
+  //
+  // The diagnostic printed will be at the location of the underlying type but
+  // the diagnostic text will print the type of `CATy->getPointeeType()` which
+  // could be a typedef name rather than the underlying type. This is ok
+  // though because the diagnostic will print the underlying type name too.
+  // E.g:
+  //
+  // `forward declaration of 'Incomplete_Struct_t'
+  //  (aka 'struct IncompleteStructTy')`
+  //
+  // If this ends up being confusing we could emit a second diagnostic (one
+  // explaining where the typedef is) but that seems overly verbose.
+
+  S.Diag(IncompleteTyDecl->getBeginLoc(), diag::note_forward_declaration)
+  << CATy->getPointeeType();
+}
+
+static bool
+HasCountedByAttrOnIncompletePointee(QualType Ty, NamedDecl **ND,
+const CountAttributedType **CATyOut,
+QualType *PointeeTyOut) {
+  auto *CATy = Ty->getAs();
+  if (!CATy)
+return false;
+
+  // Incomplete pointee type is only a problem for
+  // counted_by/counted_by_or_null
+  if (CATy->isCountInBytes())
+return false;
+
+  auto PointeeTy = CATy->getPointeeType();
+  if (PointeeTy.isNull())
+return false; // Reachable?
+
+  if (!PointeeTy->isIncompleteType(ND))
+return false;
+
+  if (CATyOut)
+*CATyOut = CATy;
+  if (PointeeTyOut)
+*PointeeTyOut = PointeeTy;
+  return true;
+}
+
+/// Perform Checks for assigning to a `__counted_by` or
+/// `__counted_by_or_null` pointer type \param LHSTy where the pointee type
+/// is incomplete which is invalid.
+///
+/// \param S The Sema instance.
+/// \param LHSTy The type being assigned to. Checks will only be performed if
+///  the type is a `counted_by` or `counted_by_or_null ` pointer.
+/// \param RHSExpr The expression being assigned from.
+/// \param Action The type assignment being performed
+/// \param Loc The SourceLocation to use for error diagnostics
+/// \param ComputeAssignee If provided this function will be called before
+///emitting a diagnostic. The function should return the name of
+///entity being assigned to or an empty string if this cannot be
+///determined.
+///
+/// \returns True iff no diagnostic where emitted, false otherwise.
+static bool CheckAssignmentToCountAttrPtrWithIncompletePointeeTy(
+Sema &S, QualType LHSTy, Expr *RHSExpr, AssignmentAction Action,
+SourceLocation Loc, llvm::function_ref ComputeAssignee) {
+  NamedDecl *IncompleteTyDecl = nullptr;
+  const CountAttributedType *CATy = nullptr;
+  QualType PointeeTy;
+  if (!HasCountedByAttrOnIncompletePointee(LHSTy, &IncompleteTyDecl, &CATy,
+   &PointeeTy))
+return true;
+  assert(CATy && !CATy->isCountInBytes() && !PointeeTy.isNull());
+
+  // It's not expected that the diagnostic be emitted in these cases.
+  // It's not necessarily a problem but we should catch when this starts
+  // to happen.
+  assert(Action != AssignmentAction::Converting &&
+ Action != AssignmentAction::Sending &&
+ Action != AssignmentAction::Casting &&
+ Action != AssignmentAction::Passing_CFAudited);
+
+  // By having users provide a function we only pay the cost of allocation the
+  // string and computing when a diagnostic is emitted.
+  std::string Assignee = ComputeAssignee ? ComputeAssignee() : "";
+  {
+auto D = S.Diag(Loc, diag::err_counted_by_on_incomplete_type_on_ass

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2024-10-24 Thread via cfe-commits


@@ -186,4 +218,216 @@ bool Sema::CheckCountedByAttrOnField(FieldDecl *FD, Expr 
*E, bool CountInBytes,
   return false;
 }
 
+SourceRange Sema::BoundsSafetySourceRangeFor(const CountAttributedType *CATy) {
+  // This is an approximation that's not quite right. This points to the
+  // the expression inside the attribute rather than the attribute itself.
+  //
+  // TODO: Implement logic to find the relevant TypeLoc for the attribute and
+  // get the SourceRange from that (#113582).
+  return CATy->getCountExpr()->getSourceRange();
+}
+
+static void EmitIncompleteCountedByPointeeNotes(Sema &S,
+const CountAttributedType 
*CATy,
+NamedDecl *IncompleteTyDecl,
+bool NoteAttrLocation = true) {
+  assert(IncompleteTyDecl == nullptr || isa(IncompleteTyDecl));
+
+  if (NoteAttrLocation) {
+// Note where the attribute is declared
+auto AttrSrcRange = S.BoundsSafetySourceRangeFor(CATy);
+S.Diag(AttrSrcRange.getBegin(), diag::note_named_attribute)
+<< CATy->getAttributeName(/*WithMacroPrefix=*/true) << AttrSrcRange;
+  }
+
+  if (!IncompleteTyDecl)
+return;
+
+  // If there's an associated forward declaration display it to emphasize
+  // why the type is incomplete (all we have is a forward declaration).
+
+  // Note the `IncompleteTyDecl` type is the underlying type which might not
+  // be the same as `CATy->getPointeeType()` which could be a typedef.
+  //
+  // The diagnostic printed will be at the location of the underlying type but
+  // the diagnostic text will print the type of `CATy->getPointeeType()` which
+  // could be a typedef name rather than the underlying type. This is ok
+  // though because the diagnostic will print the underlying type name too.
+  // E.g:
+  //
+  // `forward declaration of 'Incomplete_Struct_t'
+  //  (aka 'struct IncompleteStructTy')`
+  //
+  // If this ends up being confusing we could emit a second diagnostic (one
+  // explaining where the typedef is) but that seems overly verbose.
+
+  S.Diag(IncompleteTyDecl->getBeginLoc(), diag::note_forward_declaration)
+  << CATy->getPointeeType();
+}
+
+static bool
+HasCountedByAttrOnIncompletePointee(QualType Ty, NamedDecl **ND,
+const CountAttributedType **CATyOut,
+QualType *PointeeTyOut) {
+  auto *CATy = Ty->getAs();
+  if (!CATy)
+return false;
+
+  // Incomplete pointee type is only a problem for
+  // counted_by/counted_by_or_null
+  if (CATy->isCountInBytes())
+return false;
+
+  auto PointeeTy = CATy->getPointeeType();
+  if (PointeeTy.isNull())
+return false; // Reachable?
+
+  if (!PointeeTy->isIncompleteType(ND))
+return false;
+
+  if (CATyOut)
+*CATyOut = CATy;
+  if (PointeeTyOut)
+*PointeeTyOut = PointeeTy;
+  return true;
+}
+
+/// Perform Checks for assigning to a `__counted_by` or
+/// `__counted_by_or_null` pointer type \param LHSTy where the pointee type
+/// is incomplete which is invalid.
+///
+/// \param S The Sema instance.
+/// \param LHSTy The type being assigned to. Checks will only be performed if
+///  the type is a `counted_by` or `counted_by_or_null ` pointer.
+/// \param RHSExpr The expression being assigned from.
+/// \param Action The type assignment being performed
+/// \param Loc The SourceLocation to use for error diagnostics
+/// \param ComputeAssignee If provided this function will be called before
+///emitting a diagnostic. The function should return the name of
+///entity being assigned to or an empty string if this cannot be
+///determined.
+///
+/// \returns True iff no diagnostic where emitted, false otherwise.
+static bool CheckAssignmentToCountAttrPtrWithIncompletePointeeTy(
+Sema &S, QualType LHSTy, Expr *RHSExpr, AssignmentAction Action,
+SourceLocation Loc, llvm::function_ref ComputeAssignee) {
+  NamedDecl *IncompleteTyDecl = nullptr;
+  const CountAttributedType *CATy = nullptr;
+  QualType PointeeTy;
+  if (!HasCountedByAttrOnIncompletePointee(LHSTy, &IncompleteTyDecl, &CATy,
+   &PointeeTy))
+return true;
+  assert(CATy && !CATy->isCountInBytes() && !PointeeTy.isNull());
+
+  // It's not expected that the diagnostic be emitted in these cases.
+  // It's not necessarily a problem but we should catch when this starts
+  // to happen.

Sirraide wrote:

This comment on an assertion is a bit confusing to me: ‘it’s not necessarily a 
problem, but we should catch it if it does happen’? That to me at least 
implicates that it is in fact a problem if this happens, otherwise, why bother 
catching it?

Should this maybe be a `TODO` or `FIXME` comment instead?

https://github.com/llvm/llvm-project/pull/106321
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
htt

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2024-10-24 Thread via cfe-commits


@@ -186,4 +218,216 @@ bool Sema::CheckCountedByAttrOnField(FieldDecl *FD, Expr 
*E, bool CountInBytes,
   return false;
 }
 
+SourceRange Sema::BoundsSafetySourceRangeFor(const CountAttributedType *CATy) {
+  // This is an approximation that's not quite right. This points to the
+  // the expression inside the attribute rather than the attribute itself.
+  //
+  // TODO: Implement logic to find the relevant TypeLoc for the attribute and
+  // get the SourceRange from that (#113582).
+  return CATy->getCountExpr()->getSourceRange();
+}
+
+static void EmitIncompleteCountedByPointeeNotes(Sema &S,
+const CountAttributedType 
*CATy,
+NamedDecl *IncompleteTyDecl,
+bool NoteAttrLocation = true) {
+  assert(IncompleteTyDecl == nullptr || isa(IncompleteTyDecl));
+
+  if (NoteAttrLocation) {
+// Note where the attribute is declared
+auto AttrSrcRange = S.BoundsSafetySourceRangeFor(CATy);
+S.Diag(AttrSrcRange.getBegin(), diag::note_named_attribute)
+<< CATy->getAttributeName(/*WithMacroPrefix=*/true) << AttrSrcRange;
+  }
+
+  if (!IncompleteTyDecl)
+return;
+
+  // If there's an associated forward declaration display it to emphasize
+  // why the type is incomplete (all we have is a forward declaration).
+
+  // Note the `IncompleteTyDecl` type is the underlying type which might not
+  // be the same as `CATy->getPointeeType()` which could be a typedef.
+  //
+  // The diagnostic printed will be at the location of the underlying type but
+  // the diagnostic text will print the type of `CATy->getPointeeType()` which
+  // could be a typedef name rather than the underlying type. This is ok
+  // though because the diagnostic will print the underlying type name too.
+  // E.g:
+  //
+  // `forward declaration of 'Incomplete_Struct_t'
+  //  (aka 'struct IncompleteStructTy')`
+  //
+  // If this ends up being confusing we could emit a second diagnostic (one
+  // explaining where the typedef is) but that seems overly verbose.
+
+  S.Diag(IncompleteTyDecl->getBeginLoc(), diag::note_forward_declaration)
+  << CATy->getPointeeType();
+}
+
+static bool
+HasCountedByAttrOnIncompletePointee(QualType Ty, NamedDecl **ND,
+const CountAttributedType **CATyOut,
+QualType *PointeeTyOut) {
+  auto *CATy = Ty->getAs();
+  if (!CATy)
+return false;
+
+  // Incomplete pointee type is only a problem for
+  // counted_by/counted_by_or_null
+  if (CATy->isCountInBytes())
+return false;
+
+  auto PointeeTy = CATy->getPointeeType();
+  if (PointeeTy.isNull())
+return false; // Reachable?
+
+  if (!PointeeTy->isIncompleteType(ND))
+return false;
+
+  if (CATyOut)
+*CATyOut = CATy;
+  if (PointeeTyOut)
+*PointeeTyOut = PointeeTy;
+  return true;
+}
+
+/// Perform Checks for assigning to a `__counted_by` or
+/// `__counted_by_or_null` pointer type \param LHSTy where the pointee type
+/// is incomplete which is invalid.
+///
+/// \param S The Sema instance.
+/// \param LHSTy The type being assigned to. Checks will only be performed if
+///  the type is a `counted_by` or `counted_by_or_null ` pointer.
+/// \param RHSExpr The expression being assigned from.
+/// \param Action The type assignment being performed
+/// \param Loc The SourceLocation to use for error diagnostics
+/// \param ComputeAssignee If provided this function will be called before
+///emitting a diagnostic. The function should return the name of
+///entity being assigned to or an empty string if this cannot be
+///determined.
+///
+/// \returns True iff no diagnostic where emitted, false otherwise.
+static bool CheckAssignmentToCountAttrPtrWithIncompletePointeeTy(
+Sema &S, QualType LHSTy, Expr *RHSExpr, AssignmentAction Action,
+SourceLocation Loc, llvm::function_ref ComputeAssignee) {
+  NamedDecl *IncompleteTyDecl = nullptr;
+  const CountAttributedType *CATy = nullptr;
+  QualType PointeeTy;
+  if (!HasCountedByAttrOnIncompletePointee(LHSTy, &IncompleteTyDecl, &CATy,
+   &PointeeTy))
+return true;
+  assert(CATy && !CATy->isCountInBytes() && !PointeeTy.isNull());
+
+  // It's not expected that the diagnostic be emitted in these cases.
+  // It's not necessarily a problem but we should catch when this starts
+  // to happen.
+  assert(Action != AssignmentAction::Converting &&
+ Action != AssignmentAction::Sending &&
+ Action != AssignmentAction::Casting &&
+ Action != AssignmentAction::Passing_CFAudited);
+
+  // By having users provide a function we only pay the cost of allocation the
+  // string and computing when a diagnostic is emitted.
+  std::string Assignee = ComputeAssignee ? ComputeAssignee() : "";
+  {
+auto D = S.Diag(Loc, diag::err_counted_by_on_incomplete_type_on_ass

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2024-10-24 Thread via cfe-commits


@@ -2440,6 +2440,26 @@ class alignas(TypeAlignment) Type : public 
ExtQualsTypeCommonBase {
 return !isFunctionType();
   }
 
+  /// \returns True if the type is incomplete and it is also a type that
+  /// cannot be completed by a later type definition.
+  ///
+  /// E.g. For `void` this is true but for `struct ForwardDecl;` this is false
+  /// because a definition for `ForwardDecl` could be provided later on in the
+  /// translation unit.
+  ///
+  /// Note even for types that this function returns true for it is still
+  /// possible for the declarations that contain this type to later have a
+  /// complete type in a translation unit. E.g.:
+  ///
+  /// \code{.c}
+  /// // This decl has type 'char[]' which is incomplete and cannot be later
+  /// // completed by another by another type declaration.
+  /// extern char foo[];
+  /// // This decl how has complete type 'char[5]'.
+  /// char foo[5]; // foo has a complete type
+  /// \endcode
+  bool isIncompletableIncompleteType() const;

Sirraide wrote:

That’s probably fine then, but the name should probably be changed because 
`isIncompletableIncompleteType()` gives me a bit of a headache, maybe something 
like `isAlwaysIncompleteType()` would be better? Or maybe you can think of a 
better name; I’m not that good at naming things...

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


[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2024-10-24 Thread via cfe-commits


@@ -0,0 +1,584 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+// RUN: %clang_cc1 -fexperimental-late-parse-attributes -fsyntax-only -verify 
%s
+
+#define __counted_by(f)  __attribute__((counted_by(f)))
+
+// 
=
+// # Struct incomplete type with attribute in the decl position
+// 
=
+
+// Note: This could be considered misleading. The typedef isn't actually on 
this
+// line. Also note the discrepancy in diagnostic count (27 vs 51) is due to
+// the pointer arithmetic on incomplete pointee type diagnostic always using
+// diagnostic text that refers to the underlying forward decl, even when the
+// typedef is used.
+// expected-note@+1 27{{forward declaration of 'Incomplete_t' (aka 'struct 
IncompleteTy')}}
+struct IncompleteTy; // expected-note 51{{forward declaration of 'struct 
IncompleteTy'}}
+
+typedef struct IncompleteTy Incomplete_t; 
+
+struct CBBufDeclPos {
+  int count;
+  struct IncompleteTy* buf __counted_by(count); // OK expected-note 
27{{__counted_by attribute is here}}
+  Incomplete_t* buf_typedef __counted_by(count); // OK expected-note 
27{{__counted_by attribute is here}}
+};
+
+void consume_struct_IncompleteTy(struct IncompleteTy* buf);
+
+int idx(void);
+
+
+
+void test_CBBufDeclPos(struct CBBufDeclPos* ptr) {
+  // 
===
+  // ## Local variable initialization
+  // 
===
+  struct CBBufDeclPos explicit_desig_init = {
+.count = 0,
+// expected-error@+1{{cannot initialize 'CBBufDeclPos::buf' that has type 
'struct IncompleteTy * __counted_by(count)' (aka 'struct IncompleteTy *') 
because the pointee type 'struct IncompleteTy' is incomplete and the 
'__counted_by' attribute requires the pointee type be complete when 
initializing; consider providing a complete definition for 'struct 
IncompleteTy' or using the '__sized_by' attribute}}
+.buf = 0x0,
+// expected-error@+1{{cannot initialize 'CBBufDeclPos::buf_typedef' that 
has type 'Incomplete_t * __counted_by(count)' (aka 'struct IncompleteTy *') 
because the pointee type 'Incomplete_t' (aka 'struct IncompleteTy') is 
incomplete and the '__counted_by' attribute requires the pointee type be 
complete when initializing; consider providing a complete definition for 
'Incomplete_t' or using the '__sized_by' attribute}}
+.buf_typedef = 0x0
+  };
+  // Variable is not currently marked as invalid so uses of the variable allows
+  // diagnostics to fire.
+  // expected-error@+1{{cannot assign to 'CBBufDeclPos::buf' that has type 
'struct IncompleteTy * __counted_by(count)' (aka 'struct IncompleteTy *') 
because the pointee type 'struct IncompleteTy' is incomplete and the 
'__counted_by' attribute requires the pointee type be complete when assigning; 
consider providing a complete definition for 'struct IncompleteTy' or using the 
'__sized_by' attribute}}
+  explicit_desig_init.buf = 0x0;
+  // expected-error@+1{{cannot assign to 'CBBufDeclPos::buf_typedef' that has 
type 'Incomplete_t * __counted_by(count)' (aka 'struct IncompleteTy *') because 
the pointee type 'Incomplete_t' (aka 'struct IncompleteTy') is incomplete and 
the '__counted_by' attribute requires the pointee type be complete when 
assigning; consider providing a complete definition for 'Incomplete_t' or using 
the '__sized_by' attribute}}
+  explicit_desig_init.buf_typedef = 0x0;
+  // expected-error@+1{{cannot use 'explicit_desig_init.buf' with type 'struct 
IncompleteTy * __counted_by(count)' (aka 'struct IncompleteTy *') because the 
pointee type 'struct IncompleteTy' is incomplete and the '__counted_by' 
attribute requires the pointee type be complete in this context; consider 
providing a complete definition for 'struct IncompleteTy' or using the 
'__sized_by' attribute}}
+  void *tmp = explicit_desig_init.buf;
+  // expected-error@+1{{cannot use 'explicit_desig_init.buf_typedef' with type 
'Incomplete_t * __counted_by(count)' (aka 'struct IncompleteTy *') because the 
pointee type 'Incomplete_t' (aka 'struct IncompleteTy') is incomplete and the 
'__counted_by' attribute requires the pointee type be complete in this context; 
consider providing a complete definition for 'Incomplete_t' or using the 
'__sized_by' attribute}}

Sirraide wrote:

That is... a long diagnostic. I do think the explanation has value because this 
is probably not obvious to users not familiar w/ this attribute (which is 
probably most users), but it’s also nice to be able to get a general idea of 
what is wrong just from a shorter message.

Maybe we could make the main error something like ‘Access to bounds-checked 
field has incomplete type’, and then move the rest of the explanation into a 
note (we could merge this note with the one that points to the `__coun

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2024-10-24 Thread via cfe-commits


@@ -8207,6 +8207,14 @@ ExprResult InitializationSequence::Perform(Sema &S,
 Kind.getRange().getEnd());
   } else {
 CurInit = new (S.Context) ImplicitValueInitExpr(Step->Type);
+// Note the return value isn't used to return early
+// to preserve the AST as best as possible even though an error
+// might have occurred. For struct initialization it also allows
+// all field assignments to be checked rather than bailing on the
+// first error.

Sirraide wrote:

I still think the comment is superfluous. This pattern of potentially 
diagnosing something, but not returning `ExprError()`/`true`/whatever so we can 
still construct a somewhat valid AST is fairly common in Sema, so I don’t think 
every (or any) call to this function in this fashion really needs to be 
commented (and the same applies to the call in 
`InitializationSequence::Perform()`).

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


[clang] [clang-format] Add an option to control indentation of `export { ... }` (PR #110381)

2024-10-24 Thread via cfe-commits


@@ -26588,10 +26613,7 @@ TEST_F(FormatTest, Cpp20ModulesSupport) {
"  int foo;\n"
"};",
Style);
-  verifyFormat("export {\n"
-   "  int foo;\n"
-   "};",
-   Style);
+  verifyFormat("export { int foo; };", Style);

Sirraide wrote:

Makes sense; I’ll hopefully have time to look into this next week because I’ve 
been a bit busy recently.

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


[clang] [clang-repl] Fix undefined lld::wasm::link symbol while building clangInterpreter for wasm (PR #113446)

2024-10-24 Thread Vassil Vassilev via cfe-commits

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

Unfortunately this feature is only tested externally... LGTM!

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


[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2024-10-24 Thread via cfe-commits

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


[clang] [clang-repl] Fix undefined lld::wasm::link symbol while building clangInterpreter for wasm (PR #113446)

2024-10-24 Thread via cfe-commits

github-actions[bot] wrote:



@anutosh491 Congratulations on having your first Pull Request (PR) merged into 
the LLVM Project!

Your changes will be combined with recent changes from other authors, then 
tested by our [build bots](https://lab.llvm.org/buildbot/). If there is a 
problem with a build, you may receive a report in an email or a comment on this 
PR.

Please check whether problems have been caused by your change specifically, as 
the builds can include changes from many authors. It is not uncommon for your 
change to be included in a build that fails due to someone else's changes, or 
infrastructure issues.

How to do this, and the rest of the post-merge process, is covered in detail 
[here](https://llvm.org/docs/MyFirstTypoFix.html#myfirsttypofix-issues-after-landing-your-pr).

If your change does cause a problem, it may be reverted, or you can revert it 
yourself. This is a normal part of [LLVM 
development](https://llvm.org/docs/DeveloperPolicy.html#patch-reversion-policy).
 You can fix your changes and open a new PR to merge them again.

If you don't get any reports, no action is required from you. Your changes are 
working as expected, well done!


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


[clang] 075581f - [clang-repl] Fix undefined lld::wasm::link symbol while building clangInterpreter for wasm (#113446)

2024-10-24 Thread via cfe-commits

Author: Anutosh Bhat
Date: 2024-10-25T09:09:14+03:00
New Revision: 075581f34035c01659cc883d0d69336c279ef0d5

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

LOG: [clang-repl] Fix undefined lld::wasm::link symbol while building 
clangInterpreter for wasm (#113446)

While building llvm (clang, lld) for wasm using emscripten (recipe
hosted on emscripten-forge
https://github.com/emscripten-forge/recipes/tree/main/recipes/recipes_emscripten/llvm)
I ended up with this error
```
 │ │ wasm-ld: error: ../../../../lib/libclangInterpreter.a(Wasm.cpp.o): 
undefined symbol: lld::wasm::link(llvm::ArrayRef, 
llvm::raw_ostream&, llvm:
 │ │ :raw_ostream&, bool, bool)
 ```
 This is due to the link function here 
 
https://github.com/llvm/llvm-project/blob/a4819bd46d8baebc3aaa8b38f78065de33593199/clang/lib/Interpreter/Wasm.cpp#L25-L30
 
 This was added through this PR 
(https://github.com/llvm/llvm-project/pull/86402) as an attempt to support 
running clang-repl and executing C++ code interactively inside a Javascript 
engine using WebAssembly when built with Emscripten.
 
 The definition for link is present in lldwasm and when building for the 
emscripten platform we should be linking against it.

Added: 


Modified: 
clang/lib/Interpreter/CMakeLists.txt

Removed: 




diff  --git a/clang/lib/Interpreter/CMakeLists.txt 
b/clang/lib/Interpreter/CMakeLists.txt
index 2cc7c59b61d318..d5ffe78251d253 100644
--- a/clang/lib/Interpreter/CMakeLists.txt
+++ b/clang/lib/Interpreter/CMakeLists.txt
@@ -14,6 +14,7 @@ set(LLVM_LINK_COMPONENTS
 
 if (EMSCRIPTEN AND "lld" IN_LIST LLVM_ENABLE_PROJECTS)
   set(WASM_SRC Wasm.cpp)
+  set(WASM_LINK lldWasm)
 endif()
 
 add_clang_library(clangInterpreter
@@ -44,6 +45,7 @@ add_clang_library(clangInterpreter
   clangParse
   clangSema
   clangSerialization
+  ${WASM_LINK}
   )
 
 if ((MINGW OR CYGWIN) AND BUILD_SHARED_LIBS)



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


[clang] [llvm] [HLSL][SPIRV] Added clamp intrinsic (PR #113394)

2024-10-24 Thread Adam Yang via cfe-commits


@@ -0,0 +1,130 @@
+; RUN: llc  -verify-machineinstrs -O0 -mtriple=spirv-unknown-unknown %s -o - | 
FileCheck %s
+; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv-unknown-unknown %s -o - 
-filetype=obj | spirv-val %}

adam-yang wrote:

I'm just following what was done in DX; there's clamp and clamp-vec.

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


[clang] [llvm] [ci] New script to generate test reports as Buildkite Annotations (PR #113447)

2024-10-24 Thread Aiden Grossman via cfe-commits

boomanaiden154 wrote:

> I'd rather not do that. Commenting on the PR should be done very rarely, 
> especially for CI failures, since it clutters the PR and Github already has a 
> builtin system for presenting CI failures.

I think this is something that needs to be discussed further when we actually 
get there. Comments I think can still be useful in certain circumstances, but 
definitely agree that adding a comment for every push would clutter things, but 
that's definitely not the only way to do things.

> Overall, I'm fine with this patch, however I wonder how much effort it is 
> worth putting into the BuildKite infrastructure given that we plan on moving 
> as much as possible to Github Actions. 

The script is already written and works, and there still isn't a concrete 
timeline for when we are going to move things over to Github actions. This 
solves a valid complaint I hear somewhat often. For libc++ at least, there are 
definitely platforms that will not be able to move over to Github precommit 
where something like this might still be useful from what I understand.

> With Github actions, the .ci/generate-buildkite-pipeline-premerge script 
> would probably go away entirely in favour of individual workflows or 
> something along those lines, and then the issue of figuring out what failed 
> would probably be a non-issue. I am especially unsure about adding 
> functionality to fundamental utilities like Lit in that context: if we e.g. 
> end up not needing to output test results in individual files a few 
> weeks/months from now, then there may not be any users of 
> --use-unique-output-file-name anymore and then we'll have increased the 
> complexity of Lit for a temporary benefit.

Do we make any guarantees about supporting lit flags in the future? It's mostly 
an internal tool, and I would personally be in support of removing flags that 
are no longer used in tree, unless there are some extremely compelling 
downstream use cases and there is an appropriate maintenance story.

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


[clang] [llvm] [RISCV] Add Supm extension to RVA23 profiles (PR #113619)

2024-10-24 Thread Alex Bradbury via cfe-commits

https://github.com/asb created https://github.com/llvm/llvm-project/pull/113619

This is mandatory for both RVA23U64 and RVA23S64 in the ratified version of the 
specification
.

>From 32239ed67654c71f04dd66ccd602e8d9641330ae Mon Sep 17 00:00:00 2001
From: Alex Bradbury 
Date: Thu, 24 Oct 2024 13:43:22 -0700
Subject: [PATCH 1/2] [RISCV] Mark pointer masking extensions as
 non-experimental

These extensions were ratified very recently.


I've ensured we have definitions for all extensions in the document
.
There are no additional CSRs.
---
 .../Driver/print-supported-extensions-riscv.c | 10 +-
 clang/test/Driver/riscv-profiles.c|  2 +-
 .../test/Preprocessor/riscv-target-features.c | 16 +++
 llvm/docs/RISCVUsage.rst  |  8 +---
 llvm/docs/ReleaseNotes.md |  2 ++
 llvm/lib/Target/RISCV/RISCVFeatures.td| 20 +--
 llvm/test/CodeGen/RISCV/attributes.ll | 20 +--
 llvm/test/CodeGen/RISCV/rvv/pr107950.ll   |  2 +-
 .../TargetParser/RISCVISAInfoTest.cpp | 10 +-
 9 files changed, 47 insertions(+), 43 deletions(-)

diff --git a/clang/test/Driver/print-supported-extensions-riscv.c 
b/clang/test/Driver/print-supported-extensions-riscv.c
index a39c1ab36b1db0..7b5c7c7961974d 100644
--- a/clang/test/Driver/print-supported-extensions-riscv.c
+++ b/clang/test/Driver/print-supported-extensions-riscv.c
@@ -120,6 +120,8 @@
 // CHECK-NEXT: smcdeleg 1.0   'Smcdeleg' (Counter 
Delegation Machine Level)
 // CHECK-NEXT: smcsrind 1.0   'Smcsrind' (Indirect CSR 
Access Machine Level)
 // CHECK-NEXT: smepmp   1.0   'Smepmp' (Enhanced Physical 
Memory Protection)
+// CHECK-NEXT: smmpm1.0   'Smmpm' (Machine-level 
Pointer Masking for M-mode)
+// CHECK-NEXT: smnpm1.0   'Smnpm' (Machine-level 
Pointer Masking for next lower privilege mode)
 // CHECK-NEXT: smstateen1.0   'Smstateen' (Machine-mode 
view of the state-enable extension)
 // CHECK-NEXT: ssaia1.0   'Ssaia' (Advanced Interrupt 
Architecture Supervisor Level)
 // CHECK-NEXT: ssccfg   1.0   'Ssccfg' (Counter 
Configuration Supervisor Level)
@@ -127,6 +129,8 @@
 // CHECK-NEXT: sscofpmf 1.0   'Sscofpmf' (Count Overflow 
and Mode-Based Filtering)
 // CHECK-NEXT: sscounterenw 1.0   'Sscounterenw' (Support 
writeable scounteren enable bit for any hpmcounter that is not read-only zero)
 // CHECK-NEXT: sscsrind 1.0   'Sscsrind' (Indirect CSR 
Access Supervisor Level)
+// CHECK-NEXT: ssnpm1.0   'Ssnpm' (Supervisor-level 
Pointer Masking for next lower privilege mode)
+// CHECK-NEXT: sspm 1.0   'Sspm' (Indicates 
Supervisor-mode Pointer Masking)
 // CHECK-NEXT: ssqosid  1.0   'Ssqosid' 
(Quality-of-Service (QoS) Identifiers)
 // CHECK-NEXT: ssstateen1.0   'Ssstateen' (Supervisor-mode 
view of the state-enable extension)
 // CHECK-NEXT: ssstrict 1.0   'Ssstrict' (No 
non-conforming extensions are present)
@@ -134,6 +138,7 @@
 // CHECK-NEXT: sstvala  1.0   'Sstvala' (stval provides 
all needed values)
 // CHECK-NEXT: sstvecd  1.0   'Sstvecd' (stvec supports 
Direct mode)
 // CHECK-NEXT: ssu64xl  1.0   'Ssu64xl' (UXLEN=64 
supported)
+// CHECK-NEXT: supm 1.0   'Supm' (Indicates User-mode 
Pointer Masking)
 // CHECK-NEXT: svade1.0   'Svade' (Raise exceptions on 
improper A/D bits)
 // CHECK-NEXT: svadu1.0   'Svadu' (Hardware A/D 
updates)
 // CHECK-NEXT: svbare   1.0   'Svbare' $(satp mode Bare 
supported)
@@ -176,12 +181,7 @@
 // CHECK-NEXT: zvbc32e  0.7   'Zvbc32e' (Vector Carryless 
Multiplication with 32-bits elements)
 // CHECK-NEXT: zvkgs0.7   'Zvkgs' (Vector-Scalar GCM 
instructions for Cryptography)
 // CHECK-NEXT: smctr1.0   'Smctr' (Control Transfer 
Records Machine Level)
-// CHECK-NEXT: smmpm1.0   'Smmpm' (Machine-level 
Pointer Masking for M-mode)
-// CHECK-NEXT: smnpm1.0   'Smnpm' (Machine-level 
Pointer Masking for next lower privilege mode)
 // CHECK-NEXT: ssctr1.0   'Ssctr' (Control Transfer 
Records Supervisor Level)
-// CHECK-NEXT: ssnpm1.0   'Ssnpm' (Supervisor-level 
Pointer Masking for next lower privilege mode)
-// CHECK-NEXT: sspm 

[clang] [BoundsSafety][Sema] Allow counted_by and counted_by_or_null on pointers where the pointee type is incomplete but potentially completable (PR #106321)

2024-10-24 Thread Dan Liew via cfe-commits


@@ -186,4 +218,370 @@ bool Sema::CheckCountedByAttrOnField(FieldDecl *FD, Expr 
*E, bool CountInBytes,
   return false;
 }
 
+SourceRange Sema::BoundsSafetySourceRangeFor(const CountAttributedType *CATy) {

delcypher wrote:

I've dropped the hacky implementation in favor of just using the SourceRange 
attached to the count expression. I've filed #113582 to track resolving this 
properly.

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


[clang] [llvm] [HLSL][SPIRV] Added clamp intrinsic (PR #113394)

2024-10-24 Thread Adam Yang via cfe-commits

https://github.com/adam-yang updated 
https://github.com/llvm/llvm-project/pull/113394

>From 8cf5032a5580b97c4c4965e577374f627fbe0643 Mon Sep 17 00:00:00 2001
From: Adam Yang <31109344+adam-y...@users.noreply.github.com>
Date: Mon, 14 Oct 2024 16:35:45 -0700
Subject: [PATCH 1/6] Added the intrinsics and modified the clang test

---
 clang/lib/CodeGen/CGBuiltin.cpp   |  25 ++-
 clang/test/CodeGenHLSL/builtins/clamp.hlsl| 174 +-
 llvm/include/llvm/IR/IntrinsicsSPIRV.td   |   3 +
 .../Target/SPIRV/SPIRVInstructionSelector.cpp |   6 +
 4 files changed, 122 insertions(+), 86 deletions(-)

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 1ad950798c2118..1087537ae4ee29 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -18665,10 +18665,27 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned 
BuiltinID,
 if (auto *VecTy = Ty->getAs())
   Ty = VecTy->getElementType();
 IsUnsigned = Ty->isUnsignedIntegerType();
-return Builder.CreateIntrinsic(
-/*ReturnType=*/OpX->getType(),
-IsUnsigned ? Intrinsic::dx_uclamp : Intrinsic::dx_clamp,
-ArrayRef{OpX, OpMin, OpMax}, nullptr, "dx.clamp");
+switch (CGM.getTarget().getTriple().getArch()) {
+case llvm::Triple::dxil: {
+  return Builder.CreateIntrinsic(
+  /*ReturnType=*/OpX->getType(),
+  IsUnsigned ? Intrinsic::dx_uclamp : Intrinsic::dx_clamp,
+  ArrayRef{OpX, OpMin, OpMax}, nullptr, "dx.clamp");
+} break;
+case llvm::Triple::spirv: {
+  Intrinsic::ID Intr = Intrinsic::spv_sclamp;
+  if (Ty->isFloatingType()) {
+Intr = Intrinsic::spv_fclamp;
+  } else if (IsUnsigned) {
+Intr = Intrinsic::spv_uclamp;
+  }
+  return Builder.CreateIntrinsic(OpX->getType(), Intr,
+ ArrayRef{OpX, OpMin, OpMax},
+ nullptr, "spv.clamp");
+} break;
+default:
+  llvm_unreachable("Intrinsic clamp not supported by target architecture");
+}
   }
   case Builtin::BI__builtin_hlsl_cross: {
 Value *Op0 = EmitScalarExpr(E->getArg(0));
diff --git a/clang/test/CodeGenHLSL/builtins/clamp.hlsl 
b/clang/test/CodeGenHLSL/builtins/clamp.hlsl
index af8f6b9733a071..806e786ae70931 100644
--- a/clang/test/CodeGenHLSL/builtins/clamp.hlsl
+++ b/clang/test/CodeGenHLSL/builtins/clamp.hlsl
@@ -1,133 +1,143 @@
 // RUN: %clang_cc1 -finclude-default-header -triple 
dxil-pc-shadermodel6.3-library %s \
 // RUN:  -fnative-half-type -emit-llvm -disable-llvm-passes -o - | \
-// RUN:  FileCheck %s --check-prefixes=CHECK,NATIVE_HALF
+// RUN:  FileCheck %s --check-prefixes=CHECK,NATIVE_HALF \
+// RUN:  -DSCLAMP="dx.clamp" -DUCLAMP="dx.uclamp" -DFCLAMP="dx.clamp" 
-DFNATTR="noundef"
 // RUN: %clang_cc1 -finclude-default-header -triple 
dxil-pc-shadermodel6.3-library %s \
 // RUN:  -emit-llvm -disable-llvm-passes -o - | \
-// RUN:  FileCheck %s --check-prefixes=CHECK,NO_HALF
+// RUN:  FileCheck %s --check-prefixes=CHECK,NO_HALF \
+// RUN:  -DSCLAMP="dx.clamp" -DUCLAMP="dx.uclamp" -DFCLAMP="dx.clamp" 
-DFNATTR="noundef"
+// RUN: %clang_cc1 -finclude-default-header -triple 
spirv-unknown-vulkan-compute %s \
+// RUN:  -fnative-half-type -emit-llvm -disable-llvm-passes -o - | \
+// RUN:  FileCheck %s --check-prefixes=CHECK,NATIVE_HALF \
+// RUN:  -DSCLAMP="spv.sclamp" -DUCLAMP="spv.uclamp" -DFCLAMP="spv.fclamp" 
-DFNATTR="spir_func noundef"
+// RUN: %clang_cc1 -finclude-default-header -triple 
spirv-unknown-vulkan-compute %s \
+// RUN:  -emit-llvm -disable-llvm-passes -o - | \
+// RUN:  FileCheck %s --check-prefixes=CHECK,NO_HALF \
+// RUN:  -DSCLAMP="spv.sclamp" -DUCLAMP="spv.uclamp" -DFCLAMP="spv.fclamp" 
-DFNATTR="spir_func noundef"
 
 #ifdef __HLSL_ENABLE_16_BIT
-// NATIVE_HALF-LABEL: define noundef i16 @_Z16test_clamp_short
-// NATIVE_HALF: call i16 @llvm.dx.clamp.i16(
+// NATIVE_HALF: define [[FNATTR]] i16 @_Z16test_clamp_short
+// NATIVE_HALF: call i16 @llvm.[[SCLAMP]].i16(
 int16_t test_clamp_short(int16_t p0, int16_t p1) { return clamp(p0, p1,p1); }
-// NATIVE_HALF-LABEL: define noundef <2 x i16> @_Z17test_clamp_short2
-// NATIVE_HALF: call <2 x i16> @llvm.dx.clamp.v2i16(
+// NATIVE_HALF: define [[FNATTR]] <2 x i16> @_Z17test_clamp_short2
+// NATIVE_HALF: call <2 x i16> @llvm.[[SCLAMP]].v2i16(
 int16_t2 test_clamp_short2(int16_t2 p0, int16_t2 p1) { return clamp(p0, 
p1,p1); }
-// NATIVE_HALF-LABEL: define noundef <3 x i16> @_Z17test_clamp_short3
-// NATIVE_HALF: call <3 x i16> @llvm.dx.clamp.v3i16
+// NATIVE_HALF: define [[FNATTR]] <3 x i16> @_Z17test_clamp_short3
+// NATIVE_HALF: call <3 x i16> @llvm.[[SCLAMP]].v3i16
 int16_t3 test_clamp_short3(int16_t3 p0, int16_t3 p1) { return clamp(p0, 
p1,p1); }
-// NATIVE_HALF-LABEL: define noundef <4 x i16> @_Z17test_clamp_short4
-// NATIVE_HALF: call <4 x i16> @llvm.dx.clamp.v4i16
+// NATIVE_HALF: define [[FNATTR]] <4 x i16> @_Z17test_clamp_short4
+// NATIVE_HALF: call <

  1   2   3   4   5   >