[PATCH] D123235: [OpenMP] atomic compare fail : Parser & AST support

2023-11-08 Thread Qiu Chaofan via Phabricator via cfe-commits
qiucf added a comment.

Hi, it seems rG086b65340cca2648a2a91a0a47d28c7d9bafd1e5 
 causes 
build failure:

  llvm-project/clang/lib/Basic/OpenMPKinds.cpp:444:13: error: 97 enumeration 
values not handled in switch: 'OMPC_adjust_args', 'OMPC_affinity', 
'OMPC_align'... [-Werror,-Wswitch]
  switch (CK) {
  ^~
  1 error generated.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D123235/new/

https://reviews.llvm.org/D123235

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


[clang-tools-extra] [clangd][RFC] Add container field to remote index Refs grpc method (PR #71605)

2023-11-08 Thread Nathan Ridge via cfe-commits
HighCommander4 wrote:

This sounds like it might be the culprit behind 
https://github.com/clangd/clangd/issues/1358

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


[PATCH] D123235: [OpenMP] atomic compare fail : Parser & AST support

2023-11-08 Thread Sunil K via Phabricator via cfe-commits
koops added a comment.

Only on ppc64 this error is being seen because it is expecting a default in the 
switch statement:
OpenMPClauseKind CK = ...
switch(CK)

This is similar to what has been added in OMPClauseWithPreInit::get() {
switch(C->getClauseKind()) {
case ...

default:
}
I am about to make this change.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D123235/new/

https://reviews.llvm.org/D123235

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


[llvm] [clang] [AMDGPU] Emit a waitcnt instruction after each memory instruction (PR #68932)

2023-11-08 Thread Matt Arsenault via cfe-commits
https://github.com/arsenm requested changes to this pull request.


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


[clang] [llvm] [AMDGPU] Emit a waitcnt instruction after each memory instruction (PR #68932)

2023-11-08 Thread Matt Arsenault via cfe-commits
https://github.com/arsenm edited https://github.com/llvm/llvm-project/pull/68932
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [AMDGPU] Emit a waitcnt instruction after each memory instruction (PR #68932)

2023-11-08 Thread Matt Arsenault via cfe-commits

@@ -52,6 +52,11 @@ static cl::opt ForceEmitZeroFlag(
   cl::desc("Force all waitcnt instrs to be emitted as s_waitcnt vmcnt(0) 
expcnt(0) lgkmcnt(0)"),
   cl::init(false), cl::Hidden);
 
+static cl::opt
+PreciseMemOpFlag("amdgpu-precise-memory-op",
+ cl::desc("Emit s_waitcnt 0 after each memory operation"),
+ cl::init(false));
+

arsenm wrote:

I think this should be fused into an enum flag with the existing waitcnt flag.

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


[clang] [llvm] [AMDGPU] Emit a waitcnt instruction after each memory instruction (PR #68932)

2023-11-08 Thread Matt Arsenault via cfe-commits

@@ -1809,6 +1816,23 @@ bool SIInsertWaitcnts::shouldFlushVmCnt(MachineLoop *ML,
   return HasVMemLoad && UsesVgprLoadedOutside;
 }
 
+bool SIInsertWaitcnts::insertWaitcntAfterMemOp(MachineFunction &MF) {
+  bool Modified = false;
+
+  for (auto &MBB : MF) {

arsenm wrote:

Should try to integrate with the rest of the logic instead of adding a separate 
pass over the function 

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


[PATCH] D123235: [OpenMP] atomic compare fail : Parser & AST support

2023-11-08 Thread Sunil K via Phabricator via cfe-commits
koops updated this revision to Diff 558051.
koops added a comment.

To avoid build error in ppc64 adding a "default" to switch statement. This is 
similar to the way it is currently handled in

   OMPClauseWithPreInit::get() {
  switch(C->getClauseKind()) {
  case ...
  
  default:
  } 


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D123235/new/

https://reviews.llvm.org/D123235

Files:
  clang/lib/Basic/OpenMPKinds.cpp


Index: clang/lib/Basic/OpenMPKinds.cpp
===
--- clang/lib/Basic/OpenMPKinds.cpp
+++ clang/lib/Basic/OpenMPKinds.cpp
@@ -442,12 +442,13 @@
   case OMPC_fail: {
 OpenMPClauseKind CK = static_cast(Type);
 switch (CK) {
-case OMPC_unknown:
-  return "unknown";
 #define OPENMP_ATOMIC_FAIL_MODIFIER(Name)  
\
   case OMPC_##Name:
\
 return #Name;
 #include "clang/Basic/OpenMPKinds.def"
+case OMPC_unknown:
+default:
+  return "unknown";
 }
 llvm_unreachable("Invalid OpenMP 'fail' clause modifier");
   }


Index: clang/lib/Basic/OpenMPKinds.cpp
===
--- clang/lib/Basic/OpenMPKinds.cpp
+++ clang/lib/Basic/OpenMPKinds.cpp
@@ -442,12 +442,13 @@
   case OMPC_fail: {
 OpenMPClauseKind CK = static_cast(Type);
 switch (CK) {
-case OMPC_unknown:
-  return "unknown";
 #define OPENMP_ATOMIC_FAIL_MODIFIER(Name)  \
   case OMPC_##Name:\
 return #Name;
 #include "clang/Basic/OpenMPKinds.def"
+case OMPC_unknown:
+default:
+  return "unknown";
 }
 llvm_unreachable("Invalid OpenMP 'fail' clause modifier");
   }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Fixes compile error that double colon operator cannot resolve macro with parentheses. (PR #68618)

2023-11-08 Thread Phoebe Wang via cfe-commits
https://github.com/phoebewang approved this pull request.

LGTM.

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


[clang] c468e89 - [clang][Interp][NFC] Fix right shifting signed IntegralAP values

2023-11-08 Thread Timm Bäder via cfe-commits
Author: Timm Bäder
Date: 2023-11-08T09:33:37+01:00
New Revision: c468e8923cadfa4c181eaa8bdbcf8d95feb70132

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

LOG: [clang][Interp][NFC] Fix right shifting signed IntegralAP values

Added: 


Modified: 
clang/lib/AST/Interp/IntegralAP.h

Removed: 




diff  --git a/clang/lib/AST/Interp/IntegralAP.h 
b/clang/lib/AST/Interp/IntegralAP.h
index 1f535d420bcd54b..6d301bad784af47 100644
--- a/clang/lib/AST/Interp/IntegralAP.h
+++ b/clang/lib/AST/Interp/IntegralAP.h
@@ -248,7 +248,11 @@ template  class IntegralAP final {
 
   static void shiftRight(const IntegralAP A, const IntegralAP B,
  unsigned OpBits, IntegralAP *R) {
-*R = IntegralAP(A.V.ashr(B.V.getZExtValue()));
+unsigned ShiftAmount = B.V.getZExtValue();
+if constexpr (Signed)
+  *R = IntegralAP(A.V.ashr(ShiftAmount));
+else
+  *R = IntegralAP(A.V.lshr(ShiftAmount));
   }
 
 private:



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


[llvm] [clang] [InstCombine] Infer zext nneg flag (PR #71534)

2023-11-08 Thread Nikita Popov via cfe-commits
https://github.com/nikic closed https://github.com/llvm/llvm-project/pull/71534
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] 5918f62 - [InstCombine] Infer zext nneg flag (#71534)

2023-11-08 Thread via cfe-commits
Author: Nikita Popov
Date: 2023-11-08T09:34:40+01:00
New Revision: 5918f62301788b53e7d3a23f3203c483e9d4d791

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

LOG: [InstCombine] Infer zext nneg flag (#71534)

Use KnownBits to infer the nneg flag on zext instructions.

Currently we only set nneg when converting sext -> zext, but don't set
it when we have a zext in the first place. If we want to use it in
optimizations, we should make sure the flag inference is consistent.

Added: 


Modified: 
clang/test/Headers/wasm.c
llvm/lib/Transforms/InstCombine/InstCombineCasts.cpp
llvm/test/Transforms/InstCombine/2010-11-01-lshr-mask.ll
llvm/test/Transforms/InstCombine/X86/x86-vector-shifts-inseltpoison.ll
llvm/test/Transforms/InstCombine/X86/x86-vector-shifts.ll
llvm/test/Transforms/InstCombine/adjust-for-minmax.ll
llvm/test/Transforms/InstCombine/and-narrow.ll
llvm/test/Transforms/InstCombine/and-xor-or.ll
llvm/test/Transforms/InstCombine/and.ll
llvm/test/Transforms/InstCombine/assoc-cast-assoc.ll
llvm/test/Transforms/InstCombine/binop-cast.ll
llvm/test/Transforms/InstCombine/cast-mul-select.ll
llvm/test/Transforms/InstCombine/cast.ll
llvm/test/Transforms/InstCombine/ctpop.ll
llvm/test/Transforms/InstCombine/cttz.ll
llvm/test/Transforms/InstCombine/fmul.ll
llvm/test/Transforms/InstCombine/freeze.ll
llvm/test/Transforms/InstCombine/load-bitcast-select.ll
llvm/test/Transforms/InstCombine/lshr.ll
llvm/test/Transforms/InstCombine/minmax-fold.ll
llvm/test/Transforms/InstCombine/minmax-intrinsics.ll
llvm/test/Transforms/InstCombine/narrow-math.ll
llvm/test/Transforms/InstCombine/negated-bitmask.ll
llvm/test/Transforms/InstCombine/overflow-mul.ll
llvm/test/Transforms/InstCombine/reduction-add-sext-zext-i1.ll
llvm/test/Transforms/InstCombine/reduction-xor-sext-zext-i1.ll
llvm/test/Transforms/InstCombine/rem.ll
llvm/test/Transforms/InstCombine/select-bitext-bitwise-ops.ll
llvm/test/Transforms/InstCombine/select-bitext.ll
llvm/test/Transforms/InstCombine/select-cmp-cttz-ctlz.ll
llvm/test/Transforms/InstCombine/select-ctlz-to-cttz.ll
llvm/test/Transforms/InstCombine/select-obo-peo-ops.ll
llvm/test/Transforms/InstCombine/select-with-bitwise-ops.ll

llvm/test/Transforms/InstCombine/shift-amount-reassociation-in-bittest-with-truncation-shl.ll
llvm/test/Transforms/InstCombine/shift.ll
llvm/test/Transforms/InstCombine/trunc-inseltpoison.ll
llvm/test/Transforms/InstCombine/trunc.ll
llvm/test/Transforms/InstCombine/udiv-simplify.ll
llvm/test/Transforms/InstCombine/udivrem-change-width.ll
llvm/test/Transforms/InstCombine/vector-casts-inseltpoison.ll
llvm/test/Transforms/InstCombine/vector-casts.ll
llvm/test/Transforms/InstCombine/wcslen-1.ll
llvm/test/Transforms/InstCombine/wcslen-3.ll
llvm/test/Transforms/InstCombine/zeroext-and-reduce.ll
llvm/test/Transforms/InstCombine/zext-or-icmp.ll
llvm/test/Transforms/InstCombine/zext.ll
llvm/test/Transforms/LoopVectorize/ARM/mve-reductions.ll
llvm/test/Transforms/LoopVectorize/reduction-inloop.ll

Removed: 




diff  --git a/clang/test/Headers/wasm.c b/clang/test/Headers/wasm.c
index a755499c6c79775..9643cafc1ce6c31 100644
--- a/clang/test/Headers/wasm.c
+++ b/clang/test/Headers/wasm.c
@@ -2183,7 +2183,7 @@ uint32_t test_i64x2_bitmask(v128_t a) {
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:[[TMP0:%.*]] = bitcast <4 x i32> [[A:%.*]] to <2 x i64>
 // CHECK-NEXT:[[TMP1:%.*]] = and i32 [[B:%.*]], 63
-// CHECK-NEXT:[[REM_I:%.*]] = zext i32 [[TMP1]] to i64
+// CHECK-NEXT:[[REM_I:%.*]] = zext nneg i32 [[TMP1]] to i64
 // CHECK-NEXT:[[SPLAT_SPLATINSERT_I:%.*]] = insertelement <2 x i64> 
poison, i64 [[REM_I]], i64 0
 // CHECK-NEXT:[[SPLAT_SPLAT_I:%.*]] = shufflevector <2 x i64> 
[[SPLAT_SPLATINSERT_I]], <2 x i64> poison, <2 x i32> zeroinitializer
 // CHECK-NEXT:[[SHL_I:%.*]] = shl <2 x i64> [[TMP0]], [[SPLAT_SPLAT_I]]
@@ -2198,7 +2198,7 @@ v128_t test_i64x2_shl(v128_t a, uint32_t b) {
 // CHECK-NEXT:  entry:
 // CHECK-NEXT:[[TMP0:%.*]] = bitcast <4 x i32> [[A:%.*]] to <2 x i64>
 // CHECK-NEXT:[[TMP1:%.*]] = and i32 [[B:%.*]], 63
-// CHECK-NEXT:[[REM_I:%.*]] = zext i32 [[TMP1]] to i64
+// CHECK-NEXT:[[REM_I:%.*]] = zext nneg i32 [[TMP1]] to i64
 // CHECK-NEXT:[[SPLAT_SPLATINSERT_I:%.*]] = insertelement <2 x i64> 
poison, i64 [[REM_I]], i64 0
 // CHECK-NEXT:[[SPLAT_SPLAT_I:%.*]] = shufflevector <2 x i64> 
[[SPLAT_SPLATINSERT_I]], <2 x i64> poison, <2 x i32> zeroinitializer
 // CHECK-NEXT:[[SHR_I:%.*]] = ashr <2 x i64> [[TMP0]], [[SPLAT_SPLAT_I]]
@@ -2213,7 +2213,7 @@ v128_t test_i64x2_shr(v128_t a, uint32_t b) {
 // CHECK-NEXT:  entry:
 // C

[compiler-rt] [llvm] [clang] [Profile] Refactor profile correlation. (PR #70856)

2023-11-08 Thread Petr Hosek via cfe-commits
petrhosek wrote:

> > What I think would be a better design is to just omit the respective 
> > sections altogether when -debug-info-correlate/-profile-correlate= is 
> > enabled.
> 
> I don't understand how this solves the problem you described above. Can you 
> elaborate a bit more? We still need to decide if we need to omit data and 
> names sections at runtime right?

If you omit the data and names sections from the object files, then 
`__llvm_profile_end_data() - __llvm_profile_begin_data()` and 
`__llvm_profile_end_names() - __llvm_profile_begin_names()` are both `0` and 
there's no need for [special casing this in the 
runtime](https://github.com/llvm/llvm-project/blob/24b11ba24da3e65f718391ccc85d4d22a081e893/compiler-rt/lib/profile/InstrProfilingBuffer.c#L59).
 When linking together objects complied with different flags, sizes of those 
sections would correspond only to object files compiled without correlation. 
For example, if linking together `a.o` compiled with debug info correlation and 
`b.o` compiled without, the profile would only contain data and names from 
`b.o`.

This approach would require slightly more complex logic in the correlator. 
Currently, we either read the data and names from the profile or from DWARF 
(depending on the flag), there's no in-between state. With the approach I'm 
proposing, we would need to combine data from different sources: read the data 
and names in the profile and combine them with the data and names in the DWARF 
and/or the unstripped file.

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


[clang] [AMDGPU] const-fold imm operands of amdgcn_update_dpp intrinsic (PR #71139)

2023-11-08 Thread Pravin Jagtap via cfe-commits
https://github.com/pravinjagtap updated 
https://github.com/llvm/llvm-project/pull/71139

>From c28e9f9fb753e41bc539fa4c45bd7896d7c5d04d Mon Sep 17 00:00:00 2001
From: Pravin Jagtap 
Date: Fri, 3 Nov 2023 00:04:14 -0400
Subject: [PATCH 1/3] [AMDGPU] const-fold imm operands of amdgcn_update_dpp
 intrinsic

---
 clang/lib/CodeGen/CGBuiltin.cpp  | 16 +++-
 clang/test/CodeGenHIP/dpp-const-fold.hip | 48 
 2 files changed, 62 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/CodeGenHIP/dpp-const-fold.hip

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index e047d31c012116f..a4049cbc79d303d 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -17632,8 +17632,20 @@ Value *CodeGenFunction::EmitAMDGPUBuiltinExpr(unsigned 
BuiltinID,
   case AMDGPU::BI__builtin_amdgcn_mov_dpp:
   case AMDGPU::BI__builtin_amdgcn_update_dpp: {
 llvm::SmallVector Args;
-for (unsigned I = 0; I != E->getNumArgs(); ++I)
-  Args.push_back(EmitScalarExpr(E->getArg(I)));
+for (unsigned I = 0; I != E->getNumArgs(); ++I) {
+  llvm::Value *Arg = EmitScalarExpr(E->getArg(I));
+  // Except first two input operands, all other are imm operands for dpp
+  // intrinsic.
+  if (llvm::is_contained(std::initializer_list{2, 3, 4, 5}, I)) {
+// If this is required to be a constant, constant fold it so that we
+// know that the generated intrinsic gets a ConstantInt.
+std::optional Result =
+E->getArg(I)->getIntegerConstantExpr(getContext());
+assert(Result && "Expected argument to be a constant");
+Arg = llvm::ConstantInt::get(getLLVMContext(), *Result);
+  }
+  Args.push_back(Arg);
+}
 assert(Args.size() == 5 || Args.size() == 6);
 if (Args.size() == 5)
   Args.insert(Args.begin(), llvm::PoisonValue::get(Args[0]->getType()));
diff --git a/clang/test/CodeGenHIP/dpp-const-fold.hip 
b/clang/test/CodeGenHIP/dpp-const-fold.hip
new file mode 100644
index 000..1d1d135fb06239a
--- /dev/null
+++ b/clang/test/CodeGenHIP/dpp-const-fold.hip
@@ -0,0 +1,48 @@
+// REQUIRES: amdgpu-registered-target
+
+// RUN: %clang --offload-arch=gfx906 -S -o - -emit-llvm --cuda-device-only \
+// RUN:   %s | FileCheck %s
+
+constexpr static int OpCtrl()
+{
+return 15 + 1;
+}
+
+constexpr static int RowMask()
+{
+return 3 + 1;
+}
+
+constexpr static int BankMask()
+{
+return 2 + 1;
+}
+
+constexpr static bool BountCtrl()
+{
+return true & false;
+}
+
+// CHECK: call i32 @llvm.amdgcn.update.dpp.i32(i32 %1, i32 %2, i32 16, i32 0, 
i32 0, i1 false)
+__attribute__((global)) void test_update_dpp_const_fold_imm_operand_2(int* 
out, int a, int b)
+{
+  *out = __builtin_amdgcn_update_dpp(a, b, OpCtrl(), 0, 0, false);
+}
+
+// CHECK: call i32 @llvm.amdgcn.update.dpp.i32(i32 %1, i32 %2, i32 0, i32 4, 
i32 0, i1 false)
+__attribute__((global)) void test_update_dpp_const_fold_imm_operand_3(int* 
out, int a, int b)
+{
+  *out = __builtin_amdgcn_update_dpp(a, b, 0, RowMask(), 0, false);
+}
+
+// CHECK: call i32 @llvm.amdgcn.update.dpp.i32(i32 %1, i32 %2, i32 0, i32 0, 
i32 3, i1 false)
+__attribute__((global)) void test_update_dpp_const_fold_imm_operand_4(int* 
out, int a, int b)
+{
+  *out = __builtin_amdgcn_update_dpp(a, b, 0, 0, BankMask(), false);
+}
+
+// CHECK: call i32 @llvm.amdgcn.update.dpp.i32(i32 %1, i32 %2, i32 0, i32 0, 
i32 0, i1 false)
+__attribute__((global)) void test_update_dpp_const_fold_imm_operand_5(int* 
out, int a, int b)
+{
+  *out = __builtin_amdgcn_update_dpp(a, b, 0, 0, 0, BountCtrl());
+}

>From 5c88b0b48c449f7beff887036a3f41b8b50ec19a Mon Sep 17 00:00:00 2001
From: Pravin Jagtap 
Date: Fri, 3 Nov 2023 04:21:39 -0400
Subject: [PATCH 2/3] removed the hardcoded look up for imm arguments

---
 clang/lib/CodeGen/CGBuiltin.cpp | 15 +++
 1 file changed, 11 insertions(+), 4 deletions(-)

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index a4049cbc79d303d..b7d2fc738d067c2 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -17632,11 +17632,18 @@ Value 
*CodeGenFunction::EmitAMDGPUBuiltinExpr(unsigned BuiltinID,
   case AMDGPU::BI__builtin_amdgcn_mov_dpp:
   case AMDGPU::BI__builtin_amdgcn_update_dpp: {
 llvm::SmallVector Args;
+// Find out if any arguments are required to be integer constant
+// expressions.
+unsigned ICEArguments = 0;
+ASTContext::GetBuiltinTypeError Error;
+getContext().GetBuiltinType(BuiltinID, Error, &ICEArguments);
+assert(Error == ASTContext::GE_None && "Should not codegen an error");
 for (unsigned I = 0; I != E->getNumArgs(); ++I) {
-  llvm::Value *Arg = EmitScalarExpr(E->getArg(I));
-  // Except first two input operands, all other are imm operands for dpp
-  // intrinsic.
-  if (llvm::is_contained(std::initializer_list{2, 3, 4, 5}, I)) {
+  llvm::Value *Arg = nullptr;
+  // If t

[PATCH] D123235: [OpenMP] atomic compare fail : Parser & AST support

2023-11-08 Thread Mikael Holmén via Phabricator via cfe-commits
uabelho added a comment.

In D123235#4656427 , @koops wrote:

> To avoid build error in ppc64 adding a "default" to switch statement.

I don't think it has anything particular to do with ppc64.

I see the warning/error when i compile with clang 15 on a RHEL7 machine.

If you compile without -Werror you just get a warning.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D123235/new/

https://reviews.llvm.org/D123235

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


[clang] [C++20] [Modules] Introduce thin BMI (PR #71622)

2023-11-08 Thread via cfe-commits
tschuett wrote:

It could also be a `surface BMI` as it only describes the surface of the 
module, but it does not contain its content.

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


[clang-tools-extra] [clang-tidy] Improve performance-enum-size to exclude empty enums (PR #71640)

2023-11-08 Thread Piotr Zegar via cfe-commits
https://github.com/PiotrZSL created 
https://github.com/llvm/llvm-project/pull/71640

Enums without enumerators (empty) are now excluded from analysis as it's not 
possible to peroperly determinate new narrowed type, and such enums can be used 
in diffrent way, like as strong-types.

Closes #71544

>From eeacce5ffae9eca72484a7e51f9e55592fe4ca13 Mon Sep 17 00:00:00 2001
From: Piotr Zegar 
Date: Wed, 8 Nov 2023 09:02:54 +
Subject: [PATCH] [clang-tidy] Improve performance-enum-size to exclude empty
 enums

Enums without enumerators (empty) are now excluded
from analysis as it's not possible to peroperly determinate
new narrowed type, and such enums can be used in diffrent
way, like as strong-types.
---
 clang-tools-extra/clang-tidy/performance/EnumSizeCheck.cpp   | 5 +
 .../docs/clang-tidy/checks/performance/enum-size.rst | 2 ++
 .../test/clang-tidy/checkers/performance/enum-size.cpp   | 3 +++
 3 files changed, 10 insertions(+)

diff --git a/clang-tools-extra/clang-tidy/performance/EnumSizeCheck.cpp 
b/clang-tools-extra/clang-tidy/performance/EnumSizeCheck.cpp
index 0d44b8c7706c3c4..b1df9d74cf661ee 100644
--- a/clang-tools-extra/clang-tidy/performance/EnumSizeCheck.cpp
+++ b/clang-tools-extra/clang-tidy/performance/EnumSizeCheck.cpp
@@ -23,6 +23,10 @@ namespace clang::tidy::performance {
 
 namespace {
 
+AST_MATCHER(EnumDecl, hasEnumerators) {
+  return Node.enumerator_begin() != Node.enumerator_end();
+}
+
 const std::uint64_t Min8 =
 std::imaxabs(std::numeric_limits::min());
 const std::uint64_t Max8 = std::numeric_limits::max();
@@ -93,6 +97,7 @@ bool EnumSizeCheck::isLanguageVersionSupported(
 void EnumSizeCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(
   enumDecl(unless(isExpansionInSystemHeader()), isDefinition(),
+   hasEnumerators(),
unless(matchers::matchesAnyListedName(EnumIgnoreList)))
   .bind("e"),
   this);
diff --git a/clang-tools-extra/docs/clang-tidy/checks/performance/enum-size.rst 
b/clang-tools-extra/docs/clang-tidy/checks/performance/enum-size.rst
index 08054123366eee4..f72b8c7eabc2221 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/performance/enum-size.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/performance/enum-size.rst
@@ -58,6 +58,8 @@ terms of memory usage and cache performance. However, it's 
important to
 consider the trade-offs and potential impact on code readability and
 maintainability.
 
+Enums without enumerators (empty) are excluded from analysis.
+
 Requires C++11 or above.
 Does not provide auto-fixes.
 
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/performance/enum-size.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/performance/enum-size.cpp
index 37481a8141c5c45..782c12080f5180e 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/performance/enum-size.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/performance/enum-size.cpp
@@ -102,4 +102,7 @@ enum class IgnoredSecondEnum
 unused2 = 2
 };
 
+enum class EnumClassWithoutValues : int {};
+enum EnumWithoutValues {};
+
 }

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


[clang-tools-extra] [clang-tidy] Improve performance-enum-size to exclude empty enums (PR #71640)

2023-11-08 Thread via cfe-commits
llvmbot wrote:




@llvm/pr-subscribers-clang-tidy

Author: Piotr Zegar (PiotrZSL)


Changes

Enums without enumerators (empty) are now excluded from analysis as it's not 
possible to peroperly determinate new narrowed type, and such enums can be used 
in diffrent way, like as strong-types.

Closes #71544

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


3 Files Affected:

- (modified) clang-tools-extra/clang-tidy/performance/EnumSizeCheck.cpp (+5) 
- (modified) clang-tools-extra/docs/clang-tidy/checks/performance/enum-size.rst 
(+2) 
- (modified) 
clang-tools-extra/test/clang-tidy/checkers/performance/enum-size.cpp (+3) 


``diff
diff --git a/clang-tools-extra/clang-tidy/performance/EnumSizeCheck.cpp 
b/clang-tools-extra/clang-tidy/performance/EnumSizeCheck.cpp
index 0d44b8c7706c3c4..b1df9d74cf661ee 100644
--- a/clang-tools-extra/clang-tidy/performance/EnumSizeCheck.cpp
+++ b/clang-tools-extra/clang-tidy/performance/EnumSizeCheck.cpp
@@ -23,6 +23,10 @@ namespace clang::tidy::performance {
 
 namespace {
 
+AST_MATCHER(EnumDecl, hasEnumerators) {
+  return Node.enumerator_begin() != Node.enumerator_end();
+}
+
 const std::uint64_t Min8 =
 std::imaxabs(std::numeric_limits::min());
 const std::uint64_t Max8 = std::numeric_limits::max();
@@ -93,6 +97,7 @@ bool EnumSizeCheck::isLanguageVersionSupported(
 void EnumSizeCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(
   enumDecl(unless(isExpansionInSystemHeader()), isDefinition(),
+   hasEnumerators(),
unless(matchers::matchesAnyListedName(EnumIgnoreList)))
   .bind("e"),
   this);
diff --git a/clang-tools-extra/docs/clang-tidy/checks/performance/enum-size.rst 
b/clang-tools-extra/docs/clang-tidy/checks/performance/enum-size.rst
index 08054123366eee4..f72b8c7eabc2221 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/performance/enum-size.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/performance/enum-size.rst
@@ -58,6 +58,8 @@ terms of memory usage and cache performance. However, it's 
important to
 consider the trade-offs and potential impact on code readability and
 maintainability.
 
+Enums without enumerators (empty) are excluded from analysis.
+
 Requires C++11 or above.
 Does not provide auto-fixes.
 
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/performance/enum-size.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/performance/enum-size.cpp
index 37481a8141c5c45..782c12080f5180e 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/performance/enum-size.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/performance/enum-size.cpp
@@ -102,4 +102,7 @@ enum class IgnoredSecondEnum
 unused2 = 2
 };
 
+enum class EnumClassWithoutValues : int {};
+enum EnumWithoutValues {};
+
 }

``




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


[clang-tools-extra] [clang-tidy] Improve performance-enum-size to exclude empty enums (PR #71640)

2023-11-08 Thread Piotr Zegar via cfe-commits
PiotrZSL wrote:

No release notes entry, as this check were added in this release.

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


[PATCH] D123235: [OpenMP] atomic compare fail : Parser & AST support

2023-11-08 Thread Mikael Holmén via Phabricator via cfe-commits
uabelho added a comment.

Btw, a bit confusing (to me at least) to reopen this review since it's already 
landed.




Comment at: clang/lib/Basic/OpenMPKinds.cpp:450
+case OMPC_unknown:
+default:
+  return "unknown";

Adding "default:" here silences the warning.
But looks like @ABataev commented on something similar earlier and said that's 
not recommended?


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D123235/new/

https://reviews.llvm.org/D123235

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


[clang] [AMDGPU] const-fold imm operands of amdgcn_update_dpp intrinsic (PR #71139)

2023-11-08 Thread Matt Arsenault via cfe-commits
https://github.com/arsenm approved this pull request.

Could probably golf this down for more sharing with the default path but this 
is a start 

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


[clang-tools-extra] [clang-tidy] readability-identifier-naming: add support for concepts (PR #71586)

2023-11-08 Thread Piotr Zegar via cfe-commits
https://github.com/PiotrZSL requested changes to this pull request.

Update release notes, and update pull request description.
Except those two, looks fine for me.

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


[clang-tools-extra] [clang-tidy] Improve performance-enum-size to exclude empty enums (PR #71640)

2023-11-08 Thread Congcong Cai via cfe-commits
https://github.com/HerrCai0907 approved this pull request.

LGTM

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


[clang-tools-extra] [clang-tidy] Improve performance-enum-size to exclude empty enums (PR #71640)

2023-11-08 Thread Congcong Cai via cfe-commits
https://github.com/HerrCai0907 edited 
https://github.com/llvm/llvm-project/pull/71640
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Improve performance-enum-size to exclude empty enums (PR #71640)

2023-11-08 Thread Congcong Cai via cfe-commits

@@ -23,6 +23,10 @@ namespace clang::tidy::performance {
 
 namespace {
 
+AST_MATCHER(EnumDecl, hasEnumerators) {
+  return Node.enumerator_begin() != Node.enumerator_end();

HerrCai0907 wrote:

```suggestion
  return !Node.enumerators().empty();
```

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


[llvm] [clang] [llvm][ARM] Emit MVE .arch_extension after .fpu directive if it does not include MVE features (PR #71545)

2023-11-08 Thread via cfe-commits
https://github.com/simpal01 edited 
https://github.com/llvm/llvm-project/pull/71545
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Improve performance-enum-size to exclude empty enums (PR #71640)

2023-11-08 Thread Piotr Zegar via cfe-commits
https://github.com/PiotrZSL updated 
https://github.com/llvm/llvm-project/pull/71640

>From eeacce5ffae9eca72484a7e51f9e55592fe4ca13 Mon Sep 17 00:00:00 2001
From: Piotr Zegar 
Date: Wed, 8 Nov 2023 09:02:54 +
Subject: [PATCH 1/2] [clang-tidy] Improve performance-enum-size to exclude
 empty enums

Enums without enumerators (empty) are now excluded
from analysis as it's not possible to peroperly determinate
new narrowed type, and such enums can be used in diffrent
way, like as strong-types.
---
 clang-tools-extra/clang-tidy/performance/EnumSizeCheck.cpp   | 5 +
 .../docs/clang-tidy/checks/performance/enum-size.rst | 2 ++
 .../test/clang-tidy/checkers/performance/enum-size.cpp   | 3 +++
 3 files changed, 10 insertions(+)

diff --git a/clang-tools-extra/clang-tidy/performance/EnumSizeCheck.cpp 
b/clang-tools-extra/clang-tidy/performance/EnumSizeCheck.cpp
index 0d44b8c7706c3c4..b1df9d74cf661ee 100644
--- a/clang-tools-extra/clang-tidy/performance/EnumSizeCheck.cpp
+++ b/clang-tools-extra/clang-tidy/performance/EnumSizeCheck.cpp
@@ -23,6 +23,10 @@ namespace clang::tidy::performance {
 
 namespace {
 
+AST_MATCHER(EnumDecl, hasEnumerators) {
+  return Node.enumerator_begin() != Node.enumerator_end();
+}
+
 const std::uint64_t Min8 =
 std::imaxabs(std::numeric_limits::min());
 const std::uint64_t Max8 = std::numeric_limits::max();
@@ -93,6 +97,7 @@ bool EnumSizeCheck::isLanguageVersionSupported(
 void EnumSizeCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(
   enumDecl(unless(isExpansionInSystemHeader()), isDefinition(),
+   hasEnumerators(),
unless(matchers::matchesAnyListedName(EnumIgnoreList)))
   .bind("e"),
   this);
diff --git a/clang-tools-extra/docs/clang-tidy/checks/performance/enum-size.rst 
b/clang-tools-extra/docs/clang-tidy/checks/performance/enum-size.rst
index 08054123366eee4..f72b8c7eabc2221 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/performance/enum-size.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/performance/enum-size.rst
@@ -58,6 +58,8 @@ terms of memory usage and cache performance. However, it's 
important to
 consider the trade-offs and potential impact on code readability and
 maintainability.
 
+Enums without enumerators (empty) are excluded from analysis.
+
 Requires C++11 or above.
 Does not provide auto-fixes.
 
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/performance/enum-size.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/performance/enum-size.cpp
index 37481a8141c5c45..782c12080f5180e 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/performance/enum-size.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/performance/enum-size.cpp
@@ -102,4 +102,7 @@ enum class IgnoredSecondEnum
 unused2 = 2
 };
 
+enum class EnumClassWithoutValues : int {};
+enum EnumWithoutValues {};
+
 }

>From 5fca3fdf781dc849db770975b9f7017b091cd112 Mon Sep 17 00:00:00 2001
From: Piotr Zegar 
Date: Wed, 8 Nov 2023 10:32:51 +0100
Subject: [PATCH 2/2] Update
 clang-tools-extra/clang-tidy/performance/EnumSizeCheck.cpp

Use empty()

Co-authored-by: Congcong Cai 
---
 clang-tools-extra/clang-tidy/performance/EnumSizeCheck.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang-tools-extra/clang-tidy/performance/EnumSizeCheck.cpp 
b/clang-tools-extra/clang-tidy/performance/EnumSizeCheck.cpp
index b1df9d74cf661ee..182ed49426e5c29 100644
--- a/clang-tools-extra/clang-tidy/performance/EnumSizeCheck.cpp
+++ b/clang-tools-extra/clang-tidy/performance/EnumSizeCheck.cpp
@@ -24,7 +24,7 @@ namespace clang::tidy::performance {
 namespace {
 
 AST_MATCHER(EnumDecl, hasEnumerators) {
-  return Node.enumerator_begin() != Node.enumerator_end();
+  return !Node.enumerators().empty();
 }
 
 const std::uint64_t Min8 =

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


[clang] 32a3f2a - [AMDGPU] const-fold imm operands of amdgcn_update_dpp intrinsic (#71139)

2023-11-08 Thread via cfe-commits
Author: Pravin Jagtap
Date: 2023-11-08T15:09:10+05:30
New Revision: 32a3f2afe6ea7ffb02a6a188b123ded6f4c89f6c

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

LOG: [AMDGPU] const-fold imm operands of amdgcn_update_dpp intrinsic (#71139)

Operands of `__builtin_amdgcn_update_dpp` need to evaluate to constant
to match the intrinsic requirements.

Fixes: SWDEV-426822, SWDEV-431138
-

Authored-by: Pravin Jagtap 

Added: 
clang/test/CodeGenHIP/dpp-const-fold.hip

Modified: 
clang/lib/CodeGen/CGBuiltin.cpp
clang/lib/CodeGen/CodeGenFunction.h

Removed: 




diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 5ab81cc605819c3..e7e498e8a933131 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -5708,18 +5708,7 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
 llvm::FunctionType *FTy = F->getFunctionType();
 
 for (unsigned i = 0, e = E->getNumArgs(); i != e; ++i) {
-  Value *ArgValue;
-  // If this is a normal argument, just emit it as a scalar.
-  if ((ICEArguments & (1 << i)) == 0) {
-ArgValue = EmitScalarExpr(E->getArg(i));
-  } else {
-// If this is required to be a constant, constant fold it so that we
-// know that the generated intrinsic gets a ConstantInt.
-ArgValue = llvm::ConstantInt::get(
-getLLVMContext(),
-*E->getArg(i)->getIntegerConstantExpr(getContext()));
-  }
-
+  Value *ArgValue = EmitScalarOrConstFoldImmArg(ICEArguments, i, E);
   // If the intrinsic arg type is 
diff erent from the builtin arg type
   // we need to do a bit cast.
   llvm::Type *PTy = FTy->getParamType(i);
@@ -8599,15 +8588,7 @@ Value *CodeGenFunction::EmitARMBuiltinExpr(unsigned 
BuiltinID,
   }
 }
 
-if ((ICEArguments & (1 << i)) == 0) {
-  Ops.push_back(EmitScalarExpr(E->getArg(i)));
-} else {
-  // If this is required to be a constant, constant fold it so that we know
-  // that the generated intrinsic gets a ConstantInt.
-  Ops.push_back(llvm::ConstantInt::get(
-  getLLVMContext(),
-  *E->getArg(i)->getIntegerConstantExpr(getContext(;
-}
+Ops.push_back(EmitScalarOrConstFoldImmArg(ICEArguments, i, E));
   }
 
   switch (BuiltinID) {
@@ -11094,15 +11075,7 @@ Value 
*CodeGenFunction::EmitAArch64BuiltinExpr(unsigned BuiltinID,
 continue;
   }
 }
-if ((ICEArguments & (1 << i)) == 0) {
-  Ops.push_back(EmitScalarExpr(E->getArg(i)));
-} else {
-  // If this is required to be a constant, constant fold it so that we know
-  // that the generated intrinsic gets a ConstantInt.
-  Ops.push_back(llvm::ConstantInt::get(
-  getLLVMContext(),
-  *E->getArg(i)->getIntegerConstantExpr(getContext(;
-}
+Ops.push_back(EmitScalarOrConstFoldImmArg(ICEArguments, i, E));
   }
 
   auto SISDMap = ArrayRef(AArch64SISDIntrinsicMap);
@@ -13814,16 +13787,7 @@ Value *CodeGenFunction::EmitX86BuiltinExpr(unsigned 
BuiltinID,
   assert(Error == ASTContext::GE_None && "Should not codegen an error");
 
   for (unsigned i = 0, e = E->getNumArgs(); i != e; i++) {
-// If this is a normal argument, just emit it as a scalar.
-if ((ICEArguments & (1 << i)) == 0) {
-  Ops.push_back(EmitScalarExpr(E->getArg(i)));
-  continue;
-}
-
-// If this is required to be a constant, constant fold it so that we know
-// that the generated intrinsic gets a ConstantInt.
-Ops.push_back(llvm::ConstantInt::get(
-getLLVMContext(), 
*E->getArg(i)->getIntegerConstantExpr(getContext(;
+Ops.push_back(EmitScalarOrConstFoldImmArg(ICEArguments, i, E));
   }
 
   // These exist so that the builtin that takes an immediate can be bounds
@@ -17588,6 +17552,23 @@ void CodeGenFunction::ProcessOrderScopeAMDGCN(Value 
*Order, Value *Scope,
   SSID = getLLVMContext().getOrInsertSyncScopeID(scp);
 }
 
+llvm::Value *CodeGenFunction::EmitScalarOrConstFoldImmArg(unsigned 
ICEArguments,
+  unsigned Idx,
+  const CallExpr *E) {
+  llvm::Value *Arg = nullptr;
+  if ((ICEArguments & (1 << Idx)) == 0) {
+Arg = EmitScalarExpr(E->getArg(Idx));
+  } else {
+// If this is required to be a constant, constant fold it so that we
+// know that the generated intrinsic gets a ConstantInt.
+std::optional Result =
+E->getArg(Idx)->getIntegerConstantExpr(getContext());
+assert(Result && "Expected argument to be a constant");
+Arg = llvm::ConstantInt::get(getLLVMContext(), *Result);
+  }
+  return Arg;
+}
+
 Value *CodeGenFunction::EmitAMDGPUBuiltinExpr(unsigned Builti

[clang] [AMDGPU] const-fold imm operands of amdgcn_update_dpp intrinsic (PR #71139)

2023-11-08 Thread Pravin Jagtap via cfe-commits
https://github.com/pravinjagtap closed 
https://github.com/llvm/llvm-project/pull/71139
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] clang: Add pragma clang fp reciprocal (PR #68267)

2023-11-08 Thread Matt Arsenault via cfe-commits
https://github.com/arsenm edited https://github.com/llvm/llvm-project/pull/68267
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Improve performance-enum-size to exclude empty enums (PR #71640)

2023-11-08 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 8c014e5949fdbecc31a82138361f8cdf886768a9 
5fca3fdf781dc849db770975b9f7017b091cd112 -- 
clang-tools-extra/clang-tidy/performance/EnumSizeCheck.cpp 
clang-tools-extra/test/clang-tidy/checkers/performance/enum-size.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang-tools-extra/clang-tidy/performance/EnumSizeCheck.cpp 
b/clang-tools-extra/clang-tidy/performance/EnumSizeCheck.cpp
index 182ed49426e5..0f3e9d3ef759 100644
--- a/clang-tools-extra/clang-tidy/performance/EnumSizeCheck.cpp
+++ b/clang-tools-extra/clang-tidy/performance/EnumSizeCheck.cpp
@@ -23,9 +23,7 @@ namespace clang::tidy::performance {
 
 namespace {
 
-AST_MATCHER(EnumDecl, hasEnumerators) {
-  return !Node.enumerators().empty();
-}
+AST_MATCHER(EnumDecl, hasEnumerators) { return !Node.enumerators().empty(); }
 
 const std::uint64_t Min8 =
 std::imaxabs(std::numeric_limits::min());

``




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


[clang] [clang][Interp] Consider bit width in toAPSInt() (PR #71646)

2023-11-08 Thread Timm Baeder via cfe-commits
https://github.com/tbaederr created 
https://github.com/llvm/llvm-project/pull/71646

In `Interp.h`, when a add/sub/mul fails, we call this code and expect to get an 
`APSInt` back that can handle more than the current bitwidth of the type.

>From a5a7c82862990475630a21d6aabb319acc6a80b2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Wed, 8 Nov 2023 06:08:04 +0100
Subject: [PATCH] [clang][Interp] Consider bit width in toAPSInt()

---
 clang/lib/AST/Interp/IntegralAP.h | 10 +-
 clang/test/AST/Interp/intap.cpp   |  9 +++--
 2 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/clang/lib/AST/Interp/IntegralAP.h 
b/clang/lib/AST/Interp/IntegralAP.h
index 6d301bad784af47..a24e283cb2e7cda 100644
--- a/clang/lib/AST/Interp/IntegralAP.h
+++ b/clang/lib/AST/Interp/IntegralAP.h
@@ -119,7 +119,15 @@ template  class IntegralAP final {
 
   constexpr unsigned bitWidth() const { return V.getBitWidth(); }
 
-  APSInt toAPSInt(unsigned Bits = 0) const { return APSInt(V, Signed); }
+  APSInt toAPSInt(unsigned Bits = 0) const {
+if (Bits == 0)
+  Bits = bitWidth();
+
+if constexpr (Signed)
+  return APSInt(V.sext(Bits), !Signed);
+else
+  return APSInt(V.zext(Bits), !Signed);
+  }
   APValue toAPValue() const { return APValue(APSInt(V, Signed)); }
 
   bool isZero() const { return V.isZero(); }
diff --git a/clang/test/AST/Interp/intap.cpp b/clang/test/AST/Interp/intap.cpp
index 45961e6fc74b7a7..898d5795e1ffd5a 100644
--- a/clang/test/AST/Interp/intap.cpp
+++ b/clang/test/AST/Interp/intap.cpp
@@ -59,11 +59,16 @@ namespace i128 {
 
   static const __int128_t INT128_MAX = UINT128_MAX >> (__int128_t)1;
   static_assert(INT128_MAX != 0, "");
+  static_assert(INT128_MAX == 0, ""); // expected-error {{failed}} \
+  // expected-note {{evaluates to 
'170141183460469231731687303715884105727 == 0'}} \
+  // ref-error {{failed}} \
+  // ref-note {{evaluates to 
'170141183460469231731687303715884105727 == 0'}}
+
   static const __int128_t INT128_MIN = -INT128_MAX - 1;
   constexpr __int128 A = INT128_MAX + 1; // expected-error {{must be 
initialized by a constant expression}} \
- // expected-note {{outside the 
range}} \
+ // expected-note {{value 
170141183460469231731687303715884105728 is outside the range}} \
  // ref-error {{must be initialized by 
a constant expression}} \
- // ref-note {{outside the range}}
+ // ref-note {{value 
170141183460469231731687303715884105728 is outside the range}}
   constexpr int128_t Two = (int128_t)1 << 1ul;
   static_assert(Two == 2, "");
   static_assert(Two, "");

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


[clang] [clang][Interp] Consider bit width in toAPSInt() (PR #71646)

2023-11-08 Thread via cfe-commits
llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)


Changes

In `Interp.h`, when a add/sub/mul fails, we call this code and expect to get an 
`APSInt` back that can handle more than the current bitwidth of the type.

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


2 Files Affected:

- (modified) clang/lib/AST/Interp/IntegralAP.h (+9-1) 
- (modified) clang/test/AST/Interp/intap.cpp (+7-2) 


``diff
diff --git a/clang/lib/AST/Interp/IntegralAP.h 
b/clang/lib/AST/Interp/IntegralAP.h
index 6d301bad784af47..a24e283cb2e7cda 100644
--- a/clang/lib/AST/Interp/IntegralAP.h
+++ b/clang/lib/AST/Interp/IntegralAP.h
@@ -119,7 +119,15 @@ template  class IntegralAP final {
 
   constexpr unsigned bitWidth() const { return V.getBitWidth(); }
 
-  APSInt toAPSInt(unsigned Bits = 0) const { return APSInt(V, Signed); }
+  APSInt toAPSInt(unsigned Bits = 0) const {
+if (Bits == 0)
+  Bits = bitWidth();
+
+if constexpr (Signed)
+  return APSInt(V.sext(Bits), !Signed);
+else
+  return APSInt(V.zext(Bits), !Signed);
+  }
   APValue toAPValue() const { return APValue(APSInt(V, Signed)); }
 
   bool isZero() const { return V.isZero(); }
diff --git a/clang/test/AST/Interp/intap.cpp b/clang/test/AST/Interp/intap.cpp
index 45961e6fc74b7a7..898d5795e1ffd5a 100644
--- a/clang/test/AST/Interp/intap.cpp
+++ b/clang/test/AST/Interp/intap.cpp
@@ -59,11 +59,16 @@ namespace i128 {
 
   static const __int128_t INT128_MAX = UINT128_MAX >> (__int128_t)1;
   static_assert(INT128_MAX != 0, "");
+  static_assert(INT128_MAX == 0, ""); // expected-error {{failed}} \
+  // expected-note {{evaluates to 
'170141183460469231731687303715884105727 == 0'}} \
+  // ref-error {{failed}} \
+  // ref-note {{evaluates to 
'170141183460469231731687303715884105727 == 0'}}
+
   static const __int128_t INT128_MIN = -INT128_MAX - 1;
   constexpr __int128 A = INT128_MAX + 1; // expected-error {{must be 
initialized by a constant expression}} \
- // expected-note {{outside the 
range}} \
+ // expected-note {{value 
170141183460469231731687303715884105728 is outside the range}} \
  // ref-error {{must be initialized by 
a constant expression}} \
- // ref-note {{outside the range}}
+ // ref-note {{value 
170141183460469231731687303715884105728 is outside the range}}
   constexpr int128_t Two = (int128_t)1 << 1ul;
   static_assert(Two == 2, "");
   static_assert(Two, "");

``




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


[clang] [clang][Interp] Consider bit width in IntegralAP::toAPSInt() (PR #71646)

2023-11-08 Thread Timm Baeder via cfe-commits
https://github.com/tbaederr edited 
https://github.com/llvm/llvm-project/pull/71646
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] e6a94dc - [clang][Interp] Fix creating APSInt from IntegralAP (#71410)

2023-11-08 Thread via cfe-commits
Author: Timm Baeder
Date: 2023-11-08T10:48:07+01:00
New Revision: e6a94dca38d77db2678366c55bb7b72cfa312487

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

LOG: [clang][Interp] Fix creating APSInt from IntegralAP (#71410)

The boolean argument in the APSInt constructor is IsUnsigned, not
IsSigned.

Added: 


Modified: 
clang/lib/AST/Interp/IntegralAP.h
clang/test/AST/Interp/intap.cpp

Removed: 




diff  --git a/clang/lib/AST/Interp/IntegralAP.h 
b/clang/lib/AST/Interp/IntegralAP.h
index 6d301bad784af47..b674082d9ea5812 100644
--- a/clang/lib/AST/Interp/IntegralAP.h
+++ b/clang/lib/AST/Interp/IntegralAP.h
@@ -119,8 +119,8 @@ template  class IntegralAP final {
 
   constexpr unsigned bitWidth() const { return V.getBitWidth(); }
 
-  APSInt toAPSInt(unsigned Bits = 0) const { return APSInt(V, Signed); }
-  APValue toAPValue() const { return APValue(APSInt(V, Signed)); }
+  APSInt toAPSInt(unsigned Bits = 0) const { return APSInt(V, !Signed); }
+  APValue toAPValue() const { return APValue(APSInt(V, !Signed)); }
 
   bool isZero() const { return V.isZero(); }
   bool isPositive() const { return V.isNonNegative(); }

diff  --git a/clang/test/AST/Interp/intap.cpp b/clang/test/AST/Interp/intap.cpp
index 45961e6fc74b7a7..5f08b76a565c25a 100644
--- a/clang/test/AST/Interp/intap.cpp
+++ b/clang/test/AST/Interp/intap.cpp
@@ -56,6 +56,10 @@ namespace i128 {
 
   static const __uint128_t UINT128_MAX =__uint128_t(__int128_t(-1L));
   static_assert(UINT128_MAX == -1, "");
+  static_assert(UINT128_MAX == 1, ""); // expected-error {{static assertion 
failed}} \
+   // expected-note 
{{'340282366920938463463374607431768211455 == 1'}} \
+   // ref-error {{static assertion 
failed}} \
+   // ref-note 
{{'340282366920938463463374607431768211455 == 1'}}
 
   static const __int128_t INT128_MAX = UINT128_MAX >> (__int128_t)1;
   static_assert(INT128_MAX != 0, "");



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


[clang] [clang][Interp] Fix creating APSInt from IntegralAP (PR #71410)

2023-11-08 Thread Timm Baeder via cfe-commits
https://github.com/tbaederr closed 
https://github.com/llvm/llvm-project/pull/71410
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] Improve performance-enum-size to exclude empty enums (PR #71640)

2023-11-08 Thread Piotr Zegar via cfe-commits
https://github.com/PiotrZSL updated 
https://github.com/llvm/llvm-project/pull/71640

>From f74559586a11455e2b4c1f2c63076c5c441c527b Mon Sep 17 00:00:00 2001
From: Piotr Zegar 
Date: Wed, 8 Nov 2023 09:02:54 +
Subject: [PATCH] [clang-tidy] Improve performance-enum-size to exclude empty
 enums

Enums without enumerators (empty) are now excluded
from analysis as it's not possible to peroperly determinate
new narrowed type, and such enums can be used in diffrent
way, like as strong-types.
---
 clang-tools-extra/clang-tidy/performance/EnumSizeCheck.cpp | 3 +++
 .../docs/clang-tidy/checks/performance/enum-size.rst   | 2 ++
 .../test/clang-tidy/checkers/performance/enum-size.cpp | 3 +++
 3 files changed, 8 insertions(+)

diff --git a/clang-tools-extra/clang-tidy/performance/EnumSizeCheck.cpp 
b/clang-tools-extra/clang-tidy/performance/EnumSizeCheck.cpp
index 0d44b8c7706c3c4..0f3e9d3ef75917b 100644
--- a/clang-tools-extra/clang-tidy/performance/EnumSizeCheck.cpp
+++ b/clang-tools-extra/clang-tidy/performance/EnumSizeCheck.cpp
@@ -23,6 +23,8 @@ namespace clang::tidy::performance {
 
 namespace {
 
+AST_MATCHER(EnumDecl, hasEnumerators) { return !Node.enumerators().empty(); }
+
 const std::uint64_t Min8 =
 std::imaxabs(std::numeric_limits::min());
 const std::uint64_t Max8 = std::numeric_limits::max();
@@ -93,6 +95,7 @@ bool EnumSizeCheck::isLanguageVersionSupported(
 void EnumSizeCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(
   enumDecl(unless(isExpansionInSystemHeader()), isDefinition(),
+   hasEnumerators(),
unless(matchers::matchesAnyListedName(EnumIgnoreList)))
   .bind("e"),
   this);
diff --git a/clang-tools-extra/docs/clang-tidy/checks/performance/enum-size.rst 
b/clang-tools-extra/docs/clang-tidy/checks/performance/enum-size.rst
index 08054123366eee4..f72b8c7eabc2221 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/performance/enum-size.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/performance/enum-size.rst
@@ -58,6 +58,8 @@ terms of memory usage and cache performance. However, it's 
important to
 consider the trade-offs and potential impact on code readability and
 maintainability.
 
+Enums without enumerators (empty) are excluded from analysis.
+
 Requires C++11 or above.
 Does not provide auto-fixes.
 
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/performance/enum-size.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/performance/enum-size.cpp
index 37481a8141c5c45..782c12080f5180e 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/performance/enum-size.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/performance/enum-size.cpp
@@ -102,4 +102,7 @@ enum class IgnoredSecondEnum
 unused2 = 2
 };
 
+enum class EnumClassWithoutValues : int {};
+enum EnumWithoutValues {};
+
 }

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


[clang] [clang][dataflow] Fix buggy assertion: Compare an unqualified type to an unqualified type. (PR #71573)

2023-11-08 Thread via cfe-commits
https://github.com/martinboehme edited 
https://github.com/llvm/llvm-project/pull/71573
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][dataflow] Fix buggy assertion: Compare an unqualified type to an unqualified type. (PR #71573)

2023-11-08 Thread via cfe-commits
https://github.com/martinboehme edited 
https://github.com/llvm/llvm-project/pull/71573
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][dataflow] Fix buggy assertion: Compare an unqualified type to an unqualified type. (PR #71573)

2023-11-08 Thread via cfe-commits

@@ -3197,6 +3197,26 @@ TEST(TransferTest, 
AggregateInitialization_NotExplicitlyInitializedField) {
   });
 }
 
+TEST(TransferTest, AggregateInitializationFunctionPointer) {
+  // This is a crash repro.

martinboehme wrote:

```suggestion
  // This is a repro for an assertion failure.
```

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


[clang] [clang][dataflow] Fix buggy assertion: Compare an unqualified type to an unqualified type. (PR #71573)

2023-11-08 Thread via cfe-commits
https://github.com/martinboehme approved this pull request.


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


[clang] [clang][Interp] Implement IntegralAP subtraction (PR #71648)

2023-11-08 Thread Timm Baeder via cfe-commits
https://github.com/tbaederr created 
https://github.com/llvm/llvm-project/pull/71648

The tests currently fail because they need one of the other open `IntegralAP` 
PRs.

Will update this once they are pushed.

>From 068feee9c34a8fc22675d17e257f166235a8803e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Wed, 8 Nov 2023 06:49:41 +0100
Subject: [PATCH] [clang][Interp] Implement IntegralAP subtraction

---
 clang/lib/AST/Interp/IntegralAP.h | 34 +--
 clang/test/AST/Interp/intap.cpp   | 15 ++
 2 files changed, 29 insertions(+), 20 deletions(-)

diff --git a/clang/lib/AST/Interp/IntegralAP.h 
b/clang/lib/AST/Interp/IntegralAP.h
index 6d301bad784af47..9a9a886ede47216 100644
--- a/clang/lib/AST/Interp/IntegralAP.h
+++ b/clang/lib/AST/Interp/IntegralAP.h
@@ -183,12 +183,11 @@ template  class IntegralAP final {
   }
 
   static bool add(IntegralAP A, IntegralAP B, unsigned OpBits, IntegralAP *R) {
-return CheckAddUB(A, B, OpBits, R);
+return CheckAddSubUB(A, B, OpBits, R);
   }
 
   static bool sub(IntegralAP A, IntegralAP B, unsigned OpBits, IntegralAP *R) {
-/// FIXME: Gotta check if the result fits into OpBits bits.
-return CheckSubUB(A, B, R);
+return CheckAddSubUB(A, B, OpBits, R);
   }
 
   static bool mul(IntegralAP A, IntegralAP B, unsigned OpBits, IntegralAP *R) {
@@ -256,28 +255,23 @@ template  class IntegralAP final {
   }
 
 private:
-  static bool CheckAddUB(const IntegralAP &A, const IntegralAP &B,
- unsigned BitWidth, IntegralAP *R) {
-if (!A.isSigned()) {
-  R->V = A.V + B.V;
+  template  class Op>
+  static bool CheckAddSubUB(const IntegralAP &A, const IntegralAP &B,
+unsigned BitWidth, IntegralAP *R) {
+if constexpr (!Signed) {
+  auto UOp = Op();
+  R->V = UOp(A.V, B.V);
   return false;
 }
 
-const APSInt &LHS = APSInt(A.V, A.isSigned());
-const APSInt &RHS = APSInt(B.V, B.isSigned());
-
-APSInt Value(LHS.extend(BitWidth) + RHS.extend(BitWidth), false);
+auto SOp = Op();
+const APSInt &LHS = A.toAPSInt();
+const APSInt &RHS = B.toAPSInt();
+APSInt Value(SOp(LHS.extend(BitWidth), RHS.extend(BitWidth)), false);
 APSInt Result = Value.trunc(LHS.getBitWidth());
-if (Result.extend(BitWidth) != Value)
-  return true;
-
 R->V = Result;
-return false;
-  }
-  static bool CheckSubUB(const IntegralAP &A, const IntegralAP &B,
- IntegralAP *R) {
-R->V = A.V - B.V;
-return false; // Success!
+
+return Result.extend(BitWidth) != Value;
   }
 };
 
diff --git a/clang/test/AST/Interp/intap.cpp b/clang/test/AST/Interp/intap.cpp
index 45961e6fc74b7a7..a6f1fc4e38dfca6 100644
--- a/clang/test/AST/Interp/intap.cpp
+++ b/clang/test/AST/Interp/intap.cpp
@@ -11,7 +11,12 @@ constexpr _BitInt(2) B = A + 1;
 constexpr _BitInt(2) C = B + 1; // expected-warning {{from 2 to -2}} \
 // ref-warning {{from 2 to -2}}
 static_assert(C == -2, "");
+static_assert(C - B == A, ""); // expected-error {{not an integral constant 
expression}} \
+   // expected-note {{value -3 is outside the 
range of representable values}} \
+   // ref-error {{not an integral constant 
expression}} \
+   // ref-note {{value -3 is outside the range of 
representable values}}
 
+static_assert(B - 1 == 0, "");
 
 constexpr MaxBitInt A_ = 0;
 constexpr MaxBitInt B_ = A_ + 1;
@@ -121,6 +126,16 @@ namespace i128 {
// expected-warning {{implicit 
conversion of out of range value}} \
// expected-error {{must be 
initialized by a constant expression}} \
// expected-note {{is outside the 
range of representable values of type}}
+
+  constexpr uint128_t Zero = 0;
+  static_assert((Zero -1) == -1, "");
+  constexpr int128_t Five = 5;
+  static_assert(Five - Zero == Five, "");
+
+  constexpr int128_t Sub1 = INT128_MIN - 1; // expected-error {{must be 
initialized by a constant expression}} \
+// expected-note 
{{-170141183460469231731687303715884105729 is outside the range}} \
+// ref-error {{must be initialized 
by a constant expression}} \
+// ref-note 
{{-170141183460469231731687303715884105729 is outside the range}}
 }
 
 namespace AddSubOffset {

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


[clang] [clang][Interp] Implement IntegralAP subtraction (PR #71648)

2023-11-08 Thread via cfe-commits
llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)


Changes

The tests currently fail because they need one of the other open `IntegralAP` 
PRs.

Will update this once they are pushed.

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


2 Files Affected:

- (modified) clang/lib/AST/Interp/IntegralAP.h (+14-20) 
- (modified) clang/test/AST/Interp/intap.cpp (+15) 


``diff
diff --git a/clang/lib/AST/Interp/IntegralAP.h 
b/clang/lib/AST/Interp/IntegralAP.h
index 6d301bad784af47..9a9a886ede47216 100644
--- a/clang/lib/AST/Interp/IntegralAP.h
+++ b/clang/lib/AST/Interp/IntegralAP.h
@@ -183,12 +183,11 @@ template  class IntegralAP final {
   }
 
   static bool add(IntegralAP A, IntegralAP B, unsigned OpBits, IntegralAP *R) {
-return CheckAddUB(A, B, OpBits, R);
+return CheckAddSubUB(A, B, OpBits, R);
   }
 
   static bool sub(IntegralAP A, IntegralAP B, unsigned OpBits, IntegralAP *R) {
-/// FIXME: Gotta check if the result fits into OpBits bits.
-return CheckSubUB(A, B, R);
+return CheckAddSubUB(A, B, OpBits, R);
   }
 
   static bool mul(IntegralAP A, IntegralAP B, unsigned OpBits, IntegralAP *R) {
@@ -256,28 +255,23 @@ template  class IntegralAP final {
   }
 
 private:
-  static bool CheckAddUB(const IntegralAP &A, const IntegralAP &B,
- unsigned BitWidth, IntegralAP *R) {
-if (!A.isSigned()) {
-  R->V = A.V + B.V;
+  template  class Op>
+  static bool CheckAddSubUB(const IntegralAP &A, const IntegralAP &B,
+unsigned BitWidth, IntegralAP *R) {
+if constexpr (!Signed) {
+  auto UOp = Op();
+  R->V = UOp(A.V, B.V);
   return false;
 }
 
-const APSInt &LHS = APSInt(A.V, A.isSigned());
-const APSInt &RHS = APSInt(B.V, B.isSigned());
-
-APSInt Value(LHS.extend(BitWidth) + RHS.extend(BitWidth), false);
+auto SOp = Op();
+const APSInt &LHS = A.toAPSInt();
+const APSInt &RHS = B.toAPSInt();
+APSInt Value(SOp(LHS.extend(BitWidth), RHS.extend(BitWidth)), false);
 APSInt Result = Value.trunc(LHS.getBitWidth());
-if (Result.extend(BitWidth) != Value)
-  return true;
-
 R->V = Result;
-return false;
-  }
-  static bool CheckSubUB(const IntegralAP &A, const IntegralAP &B,
- IntegralAP *R) {
-R->V = A.V - B.V;
-return false; // Success!
+
+return Result.extend(BitWidth) != Value;
   }
 };
 
diff --git a/clang/test/AST/Interp/intap.cpp b/clang/test/AST/Interp/intap.cpp
index 45961e6fc74b7a7..a6f1fc4e38dfca6 100644
--- a/clang/test/AST/Interp/intap.cpp
+++ b/clang/test/AST/Interp/intap.cpp
@@ -11,7 +11,12 @@ constexpr _BitInt(2) B = A + 1;
 constexpr _BitInt(2) C = B + 1; // expected-warning {{from 2 to -2}} \
 // ref-warning {{from 2 to -2}}
 static_assert(C == -2, "");
+static_assert(C - B == A, ""); // expected-error {{not an integral constant 
expression}} \
+   // expected-note {{value -3 is outside the 
range of representable values}} \
+   // ref-error {{not an integral constant 
expression}} \
+   // ref-note {{value -3 is outside the range of 
representable values}}
 
+static_assert(B - 1 == 0, "");
 
 constexpr MaxBitInt A_ = 0;
 constexpr MaxBitInt B_ = A_ + 1;
@@ -121,6 +126,16 @@ namespace i128 {
// expected-warning {{implicit 
conversion of out of range value}} \
// expected-error {{must be 
initialized by a constant expression}} \
// expected-note {{is outside the 
range of representable values of type}}
+
+  constexpr uint128_t Zero = 0;
+  static_assert((Zero -1) == -1, "");
+  constexpr int128_t Five = 5;
+  static_assert(Five - Zero == Five, "");
+
+  constexpr int128_t Sub1 = INT128_MIN - 1; // expected-error {{must be 
initialized by a constant expression}} \
+// expected-note 
{{-170141183460469231731687303715884105729 is outside the range}} \
+// ref-error {{must be initialized 
by a constant expression}} \
+// ref-note 
{{-170141183460469231731687303715884105729 is outside the range}}
 }
 
 namespace AddSubOffset {

``




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


[clang] a141a9f - Revert "[OpenMP] atomic compare fail : Parser & AST support"

2023-11-08 Thread Mitch Phillips via cfe-commits
Author: Mitch Phillips
Date: 2023-11-08T11:20:17+01:00
New Revision: a141a9fa9706e939415a929a46b6f2f77cd56c55

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

LOG: Revert "[OpenMP] atomic compare fail : Parser & AST support"

This reverts commit 086b65340cca2648a2a91a0a47d28c7d9bafd1e5.

Reason: Broke under -Werror. More details in
https://reviews.llvm.org/D123235

Added: 


Modified: 
clang/include/clang/AST/OpenMPClause.h
clang/include/clang/AST/RecursiveASTVisitor.h
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/include/clang/Basic/OpenMPKinds.def
clang/include/clang/Sema/Sema.h
clang/lib/AST/OpenMPClause.cpp
clang/lib/AST/StmtProfile.cpp
clang/lib/Basic/OpenMPKinds.cpp
clang/lib/CodeGen/CGStmtOpenMP.cpp
clang/lib/Parse/ParseOpenMP.cpp
clang/lib/Sema/SemaOpenMP.cpp
clang/lib/Sema/TreeTransform.h
clang/lib/Serialization/ASTReader.cpp
clang/lib/Serialization/ASTWriter.cpp
clang/test/OpenMP/atomic_ast_print.cpp
clang/test/OpenMP/atomic_messages.cpp
clang/tools/libclang/CIndex.cpp
flang/lib/Semantics/check-omp-structure.cpp
llvm/include/llvm/Frontend/OpenMP/OMP.td

Removed: 




diff  --git a/clang/include/clang/AST/OpenMPClause.h 
b/clang/include/clang/AST/OpenMPClause.h
index f7ecffe6154af80..549f12e87df597a 100644
--- a/clang/include/clang/AST/OpenMPClause.h
+++ b/clang/include/clang/AST/OpenMPClause.h
@@ -2513,104 +2513,6 @@ class OMPRelaxedClause final : public OMPClause {
   }
 };
 
-/// This represents 'fail' clause in the '#pragma omp atomic'
-/// directive.
-///
-/// \code
-/// #pragma omp atomic compare fail
-/// \endcode
-/// In this example directive '#pragma omp atomic compare' has 'fail' clause.
-class OMPFailClause final : public OMPClause {
-
-  // FailParameter is a memory-order-clause. Storing the ClauseKind is
-  // sufficient for our purpose.
-  OpenMPClauseKind FailParameter = llvm::omp::Clause::OMPC_unknown;
-  SourceLocation FailParameterLoc;
-  SourceLocation LParenLoc;
-
-  friend class OMPClauseReader;
-
-  /// Sets the location of '(' in fail clause.
-  void setLParenLoc(SourceLocation Loc) {
-LParenLoc = Loc;
-  }
-
-  /// Sets the location of memoryOrder clause argument in fail clause.
-  void setFailParameterLoc(SourceLocation Loc) { FailParameterLoc = Loc; }
-
-  /// Sets the mem_order clause for 'atomic compare fail' directive.
-  void setFailParameter(OpenMPClauseKind FailParameter) {
-switch (FailParameter) {
-case llvm::omp::OMPC_acq_rel:
-case llvm::omp::OMPC_acquire:
-  this->FailParameter = llvm::omp::OMPC_acquire;
-  break;
-case llvm::omp::OMPC_relaxed:
-case llvm::omp::OMPC_release:
-  this->FailParameter = llvm::omp::OMPC_relaxed;
-  break;
-case llvm::omp::OMPC_seq_cst:
-  this->FailParameter = llvm::omp::OMPC_seq_cst;
-  break;
-default:
-  this->FailParameter = llvm::omp::OMPC_unknown;
-  break;
-}
-  }
-
-public:
-  /// Build 'fail' clause.
-  ///
-  /// \param StartLoc Starting location of the clause.
-  /// \param EndLoc Ending location of the clause.
-  OMPFailClause(SourceLocation StartLoc, SourceLocation EndLoc)
-  : OMPClause(llvm::omp::OMPC_fail, StartLoc, EndLoc) {}
-
-  OMPFailClause(OpenMPClauseKind FailParameter, SourceLocation 
FailParameterLoc,
-SourceLocation StartLoc, SourceLocation LParenLoc,
-SourceLocation EndLoc)
-  : OMPClause(llvm::omp::OMPC_fail, StartLoc, EndLoc),
-FailParameterLoc(FailParameterLoc), LParenLoc(LParenLoc) {
-
-setFailParameter(FailParameter);
-  }
-
-  /// Build an empty clause.
-  OMPFailClause()
-  : OMPClause(llvm::omp::OMPC_fail, SourceLocation(), SourceLocation()) {}
-
-  child_range children() {
-return child_range(child_iterator(), child_iterator());
-  }
-
-  const_child_range children() const {
-return const_child_range(const_child_iterator(), const_child_iterator());
-  }
-
-  child_range used_children() {
-return child_range(child_iterator(), child_iterator());
-  }
-  const_child_range used_children() const {
-return const_child_range(const_child_iterator(), const_child_iterator());
-  }
-
-  static bool classof(const OMPClause *T) {
-return T->getClauseKind() == llvm::omp::OMPC_fail;
-  }
-
-  /// Gets the location of '(' (for the parameter) in fail clause.
-  SourceLocation getLParenLoc() const {
-return LParenLoc;
-  }
-
-  /// Gets the location of Fail Parameter (type memory-order-clause) in
-  /// fail clause.
-  SourceLocation getFailParameterLoc() const { return FailParameterLoc; }
-
-  /// Gets the parameter (type memory-order-clause) in Fail clause.
-  OpenMPClauseKind getFailParameter() const { return FailParameter; }
-};
-
 /// This represents clau

[clang-tools-extra] 3716b5b - [clang-tidy] Improve performance-enum-size to exclude empty enums (#71640)

2023-11-08 Thread via cfe-commits
Author: Piotr Zegar
Date: 2023-11-08T11:22:31+01:00
New Revision: 3716b5b4bac6ab41291b6558ad0444cbcca04aa3

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

LOG: [clang-tidy] Improve performance-enum-size to exclude empty enums (#71640)

Enums without enumerators (empty) are now excluded from analysis as it's
not possible to peroperly determinate new narrowed type, and such enums
can be used in diffrent way, like as strong-types.

Closes #71544

Added: 


Modified: 
clang-tools-extra/clang-tidy/performance/EnumSizeCheck.cpp
clang-tools-extra/docs/clang-tidy/checks/performance/enum-size.rst
clang-tools-extra/test/clang-tidy/checkers/performance/enum-size.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/performance/EnumSizeCheck.cpp 
b/clang-tools-extra/clang-tidy/performance/EnumSizeCheck.cpp
index 0d44b8c7706c3c4..0f3e9d3ef75917b 100644
--- a/clang-tools-extra/clang-tidy/performance/EnumSizeCheck.cpp
+++ b/clang-tools-extra/clang-tidy/performance/EnumSizeCheck.cpp
@@ -23,6 +23,8 @@ namespace clang::tidy::performance {
 
 namespace {
 
+AST_MATCHER(EnumDecl, hasEnumerators) { return !Node.enumerators().empty(); }
+
 const std::uint64_t Min8 =
 std::imaxabs(std::numeric_limits::min());
 const std::uint64_t Max8 = std::numeric_limits::max();
@@ -93,6 +95,7 @@ bool EnumSizeCheck::isLanguageVersionSupported(
 void EnumSizeCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(
   enumDecl(unless(isExpansionInSystemHeader()), isDefinition(),
+   hasEnumerators(),
unless(matchers::matchesAnyListedName(EnumIgnoreList)))
   .bind("e"),
   this);

diff  --git 
a/clang-tools-extra/docs/clang-tidy/checks/performance/enum-size.rst 
b/clang-tools-extra/docs/clang-tidy/checks/performance/enum-size.rst
index 08054123366eee4..f72b8c7eabc2221 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/performance/enum-size.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/performance/enum-size.rst
@@ -58,6 +58,8 @@ terms of memory usage and cache performance. However, it's 
important to
 consider the trade-offs and potential impact on code readability and
 maintainability.
 
+Enums without enumerators (empty) are excluded from analysis.
+
 Requires C++11 or above.
 Does not provide auto-fixes.
 

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/performance/enum-size.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/performance/enum-size.cpp
index 37481a8141c5c45..782c12080f5180e 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/performance/enum-size.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/performance/enum-size.cpp
@@ -102,4 +102,7 @@ enum class IgnoredSecondEnum
 unused2 = 2
 };
 
+enum class EnumClassWithoutValues : int {};
+enum EnumWithoutValues {};
+
 }



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


[clang-tools-extra] [clang-tidy] Improve performance-enum-size to exclude empty enums (PR #71640)

2023-11-08 Thread Piotr Zegar via cfe-commits
https://github.com/PiotrZSL closed 
https://github.com/llvm/llvm-project/pull/71640
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [C++20] [Modules] Introduce thin BMI (PR #71622)

2023-11-08 Thread Chuanqi Xu via cfe-commits
ChuanqiXu9 wrote:

The term `sparse` makes me wondering its format is not efficiency.. And for the 
term `surface`, ..., it may beyond my knowledge,  I feel it is odd but I can't 
give a concrete reason.

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


[clang-tools-extra] 2626916 - [clangd] Allow hover over 128-bit variable without crashing (#71415)

2023-11-08 Thread via cfe-commits
Author: Björn Pettersson
Date: 2023-11-08T11:30:03+01:00
New Revision: 2626916c45f428226052f5e431e510743aba9e75

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

LOG: [clangd] Allow hover over 128-bit variable without crashing (#71415)

When hovering over variables larger than 64 bits, with more than 64
active bits, there were assertion failures since Hover is trying to
print the value as a 64-bit hex value.

There is already protection avoiding to call printHex if there is more
than 64 significant bits. And we already truncate and print negative
values using only 32 bits, when possible. So we can simply truncate
values with more than 64 bits to avoid the assert when using
getZExtValue. The result will be that for example a negative 128 bit
variable is printed using 64 bits, when possible.

There is still no support for printing more than 64 bits. That would
involve more changes since for example llvm::FormatterNumber is limited
to 64 bits.

Added: 


Modified: 
clang-tools-extra/clangd/Hover.cpp
clang-tools-extra/clangd/unittests/HoverTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/Hover.cpp 
b/clang-tools-extra/clangd/Hover.cpp
index 7f7b5513dff6fee..a868d3bb4e3fa1d 100644
--- a/clang-tools-extra/clangd/Hover.cpp
+++ b/clang-tools-extra/clangd/Hover.cpp
@@ -408,7 +408,9 @@ void fillFunctionTypeAndParams(HoverInfo &HI, const Decl *D,
 // -2=> 0xfffe
 // -2^32 => 0x
 static llvm::FormattedNumber printHex(const llvm::APSInt &V) {
-  uint64_t Bits = V.getZExtValue();
+  assert(V.getSignificantBits() <= 64 && "Can't print more than 64 bits.");
+  uint64_t Bits =
+  V.getBitWidth() > 64 ? V.trunc(64).getZExtValue() : V.getZExtValue();
   if (V.isNegative() && V.getSignificantBits() <= 32)
 return llvm::format_hex(uint32_t(Bits), 0);
   return llvm::format_hex(Bits, 0);

diff  --git a/clang-tools-extra/clangd/unittests/HoverTests.cpp 
b/clang-tools-extra/clangd/unittests/HoverTests.cpp
index 063a60db044060e..847f141f521caa0 100644
--- a/clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ b/clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -3349,6 +3349,17 @@ TEST(Hover, NoCrashAPInt64) {
   getHover(AST, T.point(), format::getLLVMStyle(), nullptr);
 }
 
+TEST(Hover, NoCrashInt128) {
+  Annotations T(R"cpp(
+constexpr __int128_t value = -4;
+void foo() { va^lue; }
+  )cpp");
+  auto AST = TestTU::withCode(T.code()).build();
+  auto H = getHover(AST, T.point(), format::getLLVMStyle(), nullptr);
+  ASSERT_TRUE(H);
+  EXPECT_EQ(H->Value, "-4 (0xfffc)");
+}
+
 TEST(Hover, DocsFromMostSpecial) {
   Annotations T(R"cpp(
   // doc1



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


[clang-tools-extra] [clangd] Allow hover over 128-bit variable without crashing (PR #71415)

2023-11-08 Thread Björn Pettersson via cfe-commits
https://github.com/bjope closed https://github.com/llvm/llvm-project/pull/71415
___
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 handling of functional cast in google-readability-casting (PR #71650)

2023-11-08 Thread Piotr Zegar via cfe-commits
https://github.com/PiotrZSL created 
https://github.com/llvm/llvm-project/pull/71650

Fix issue with constructor call being interpreted as functional cast and 
considered for a replacement
with static cast or being removed as redundant.

Closes #57959

>From b2da54fc89e99d3056ee80d47b8be2874916e02f Mon Sep 17 00:00:00 2001
From: Piotr Zegar 
Date: Wed, 8 Nov 2023 09:38:39 +
Subject: [PATCH 1/2] [clang-tidy] Fix handling of functional cast in
 google-readability-casting

Fix issue with constructor call being interpreted
as functional cast and considered for a replacement
with static cast or being removed as redundant.
---
 .../clang-tidy/google/AvoidCStyleCastsCheck.cpp | 13 -
 .../clang-tidy/google/AvoidCStyleCastsCheck.h   |  3 +++
 clang-tools-extra/docs/ReleaseNotes.rst |  4 
 .../checkers/google/readability-casting.cpp | 13 +++--
 4 files changed, 18 insertions(+), 15 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp 
b/clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp
index 714ac0ee54dafb3..3afb93ac7f7dd15 100644
--- a/clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp
@@ -18,19 +18,22 @@ namespace clang::tidy::google::readability {
 
 void AvoidCStyleCastsCheck::registerMatchers(
 ast_matchers::MatchFinder *Finder) {
+
   Finder->addMatcher(
   cStyleCastExpr(
   // Filter out (EnumType)IntegerLiteral construct, which is generated
   // for non-type template arguments of enum types.
   // FIXME: Remove this once this is fixed in the AST.
-  unless(hasParent(substNonTypeTemplateParmExpr())),
-  // Avoid matches in template instantiations.
-  unless(isInTemplateInstantiation()))
+  unless(hasParent(substNonTypeTemplateParmExpr(
   .bind("cast"),
   this);
+
   Finder->addMatcher(
-  cxxFunctionalCastExpr(unless(hasDescendant(cxxConstructExpr())),
-unless(hasDescendant(initListExpr(
+  cxxFunctionalCastExpr(
+  hasDestinationType(hasCanonicalType(anyOf(
+  builtinType(), references(qualType()), pointsTo(qualType(),
+  unless(
+  hasSourceExpression(anyOf(cxxConstructExpr(), initListExpr()
   .bind("cast"),
   this);
 }
diff --git a/clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.h 
b/clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.h
index 485640d230280ee..4267b896b6992c6 100644
--- a/clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.h
+++ b/clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.h
@@ -31,6 +31,9 @@ class AvoidCStyleCastsCheck : public ClangTidyCheck {
   : ClangTidyCheck(Name, Context) {}
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+  std::optional getCheckTraversalKind() const override {
+return TK_IgnoreUnlessSpelledInSource;
+  }
 };
 
 } // namespace clang::tidy::google::readability
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index fe8c7175d554c7b..f02f4bba8916bb6 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -290,6 +290,10 @@ Changes in existing checks
   to ignore unused parameters when they are marked as unused and parameters of
   deleted functions and constructors.
 
+- Improved :doc:`google-readability-casting
+  ` check to ignore constructor
+  calls disguised as functional casts.
+
 - Improved :doc:`llvm-namespace-comment
   ` check to provide fixes for
   ``inline`` namespaces in the same format as :program:`clang-format`.
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/google/readability-casting.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/google/readability-casting.cpp
index e25463cf451b741..da49c3943d73222 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/google/readability-casting.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/google/readability-casting.cpp
@@ -322,17 +322,10 @@ void conversions() {
 }
 
 template 
-T functional_cast_template_used_by_class(float i) {
+T functional_cast_template(float i) {
   return T(i);
 }
 
-template 
-T functional_cast_template_used_by_int(float i) {
-  return T(i);
-  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: C-style casts are discouraged; 
use static_cast
-  // CHECK-FIXES: return static_cast(i);
-}
-
 struct S2 {
   S2(float);
 };
@@ -356,8 +349,8 @@ void functional_casts() {
   auto s = S(str);
 
   // Functional casts in template functions
-  functional_cast_template_used_by_class(x);
-  functional_cast_template_used_by_int(x);
+  functional_cast_template(x);
+  functional_cast_template(x);
 
   // New expressions are not functional casts
   auto w = new int(x);

>From bdc890dad78c78703e52d82d5d

[clang-tools-extra] [clang-tidy] Fix handling of functional cast in google-readability-casting (PR #71650)

2023-11-08 Thread via cfe-commits
llvmbot wrote:




@llvm/pr-subscribers-clang-tidy

Author: Piotr Zegar (PiotrZSL)


Changes

Fix issue with constructor call being interpreted as functional cast and 
considered for a replacement
with static cast or being removed as redundant.

Closes #57959

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


4 Files Affected:

- (modified) clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp 
(+8-5) 
- (modified) clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.h (+3) 
- (modified) clang-tools-extra/docs/ReleaseNotes.rst (+4) 
- (modified) 
clang-tools-extra/test/clang-tidy/checkers/google/readability-casting.cpp 
(+5-10) 


``diff
diff --git a/clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp 
b/clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp
index 714ac0ee54dafb3..3afb93ac7f7dd15 100644
--- a/clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp
+++ b/clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.cpp
@@ -18,19 +18,22 @@ namespace clang::tidy::google::readability {
 
 void AvoidCStyleCastsCheck::registerMatchers(
 ast_matchers::MatchFinder *Finder) {
+
   Finder->addMatcher(
   cStyleCastExpr(
   // Filter out (EnumType)IntegerLiteral construct, which is generated
   // for non-type template arguments of enum types.
   // FIXME: Remove this once this is fixed in the AST.
-  unless(hasParent(substNonTypeTemplateParmExpr())),
-  // Avoid matches in template instantiations.
-  unless(isInTemplateInstantiation()))
+  unless(hasParent(substNonTypeTemplateParmExpr(
   .bind("cast"),
   this);
+
   Finder->addMatcher(
-  cxxFunctionalCastExpr(unless(hasDescendant(cxxConstructExpr())),
-unless(hasDescendant(initListExpr(
+  cxxFunctionalCastExpr(
+  hasDestinationType(hasCanonicalType(anyOf(
+  builtinType(), references(qualType()), pointsTo(qualType(),
+  unless(
+  hasSourceExpression(anyOf(cxxConstructExpr(), initListExpr()
   .bind("cast"),
   this);
 }
diff --git a/clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.h 
b/clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.h
index 485640d230280ee..4267b896b6992c6 100644
--- a/clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.h
+++ b/clang-tools-extra/clang-tidy/google/AvoidCStyleCastsCheck.h
@@ -31,6 +31,9 @@ class AvoidCStyleCastsCheck : public ClangTidyCheck {
   : ClangTidyCheck(Name, Context) {}
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
+  std::optional getCheckTraversalKind() const override {
+return TK_IgnoreUnlessSpelledInSource;
+  }
 };
 
 } // namespace clang::tidy::google::readability
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index fe8c7175d554c7b..f02f4bba8916bb6 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -290,6 +290,10 @@ Changes in existing checks
   to ignore unused parameters when they are marked as unused and parameters of
   deleted functions and constructors.
 
+- Improved :doc:`google-readability-casting
+  ` check to ignore constructor
+  calls disguised as functional casts.
+
 - Improved :doc:`llvm-namespace-comment
   ` check to provide fixes for
   ``inline`` namespaces in the same format as :program:`clang-format`.
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/google/readability-casting.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/google/readability-casting.cpp
index e25463cf451b741..fdc71167cd82b07 100644
--- a/clang-tools-extra/test/clang-tidy/checkers/google/readability-casting.cpp
+++ b/clang-tools-extra/test/clang-tidy/checkers/google/readability-casting.cpp
@@ -322,17 +322,10 @@ void conversions() {
 }
 
 template 
-T functional_cast_template_used_by_class(float i) {
+T functional_cast_template(float i) {
   return T(i);
 }
 
-template 
-T functional_cast_template_used_by_int(float i) {
-  return T(i);
-  // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: C-style casts are discouraged; 
use static_cast
-  // CHECK-FIXES: return static_cast(i);
-}
-
 struct S2 {
   S2(float);
 };
@@ -356,8 +349,8 @@ void functional_casts() {
   auto s = S(str);
 
   // Functional casts in template functions
-  functional_cast_template_used_by_class(x);
-  functional_cast_template_used_by_int(x);
+  functional_cast_template(x);
+  functional_cast_template(x);
 
   // New expressions are not functional casts
   auto w = new int(x);
@@ -366,4 +359,6 @@ void functional_casts() {
   S2 t = T(x); // OK, constructor call
   S2 u = U(x); // NOK, it's a reinterpret_cast in disguise
   // CHECK-MESSAGES: :[[@LINE-1]]:10: warning: C-style casts are discouraged; 
use static_cast/const_cast/reinterpret_cast
+
+  throw S2(5.0f);
 }

``

[clang] [clang][Diagnostics] Highlight code snippets (PR #66514)

2023-11-08 Thread Timm Baeder via cfe-commits
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= ,
Timm =?utf-8?q?Bäder?= 
Message-ID:
In-Reply-To: 


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

>From 001149c81ddeca2488597ebae3604efeaee1c490 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Fri, 15 Sep 2023 15:51:39 +0200
Subject: [PATCH 01/21] [clang][Diagnostics] Highlight code snippets

Add some primitive syntax highlighting to our code snippet output.
---
 .../clang/Frontend/CodeSnippetHighlighter.h   |  46 +++
 clang/include/clang/Frontend/TextDiagnostic.h |   2 +
 clang/lib/Frontend/CMakeLists.txt |   1 +
 clang/lib/Frontend/CodeSnippetHighlighter.cpp | 120 ++
 clang/lib/Frontend/TextDiagnostic.cpp |  26 
 5 files changed, 195 insertions(+)
 create mode 100644 clang/include/clang/Frontend/CodeSnippetHighlighter.h
 create mode 100644 clang/lib/Frontend/CodeSnippetHighlighter.cpp

diff --git a/clang/include/clang/Frontend/CodeSnippetHighlighter.h 
b/clang/include/clang/Frontend/CodeSnippetHighlighter.h
new file mode 100644
index 000..776954b59e2e1a8
--- /dev/null
+++ b/clang/include/clang/Frontend/CodeSnippetHighlighter.h
@@ -0,0 +1,46 @@
+//===--- CodeSnippetHighlighter.h - Code snippet highlighting ---*- C++ 
-*-===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#ifndef LLVM_CLANG_FRONTEND_CODESNIPPETHIGHLIGHTER_H
+#define LLVM_CLANG_FRONTEND_CODESNIPPETHIGHLIGHTER_H
+
+#include "clang/Basic/LangOptions.h"
+#include "llvm/ADT/SmallSet.h"
+#include "llvm/Support/raw_ostream.h"
+#include 
+
+namespace clang {
+
+struct StyleRange {
+  unsigned Start;
+  unsigned End;
+  const enum llvm::raw_ostream::Colors c;
+};
+
+class CodeSnippetHighlighter final {
+public:
+  CodeSnippetHighlighter() = default;
+
+  /// Produce StyleRanges for the given line.
+  /// The returned vector contains non-overlapping style ranges. They are 
sorted
+  /// from beginning of the line to the end.
+  std::vector highlightLine(llvm::StringRef SourceLine,
+const LangOptions &LangOpts);
+
+private:
+  bool Initialized = false;
+  /// Fills Keywords and Literals.
+  void ensureTokenData();
+
+  llvm::SmallSet Keywords;
+  llvm::SmallSet Literals;
+};
+
+} // namespace clang
+
+#endif
diff --git a/clang/include/clang/Frontend/TextDiagnostic.h 
b/clang/include/clang/Frontend/TextDiagnostic.h
index 7eb0ab0cdc9bca8..59fd4d4f9408d48 100644
--- a/clang/include/clang/Frontend/TextDiagnostic.h
+++ b/clang/include/clang/Frontend/TextDiagnostic.h
@@ -15,6 +15,7 @@
 #ifndef LLVM_CLANG_FRONTEND_TEXTDIAGNOSTIC_H
 #define LLVM_CLANG_FRONTEND_TEXTDIAGNOSTIC_H
 
+#include "clang/Frontend/CodeSnippetHighlighter.h"
 #include "clang/Frontend/DiagnosticRenderer.h"
 
 namespace clang {
@@ -33,6 +34,7 @@ namespace clang {
 /// printing coming out of libclang.
 class TextDiagnostic : public DiagnosticRenderer {
   raw_ostream &OS;
+  CodeSnippetHighlighter SnippetHighlighter;
 
 public:
   TextDiagnostic(raw_ostream &OS,
diff --git a/clang/lib/Frontend/CMakeLists.txt 
b/clang/lib/Frontend/CMakeLists.txt
index 1e5f0a859dfd568..f3547f771593093 100644
--- a/clang/lib/Frontend/CMakeLists.txt
+++ b/clang/lib/Frontend/CMakeLists.txt
@@ -42,6 +42,7 @@ add_clang_library(clangFrontend
   TextDiagnosticPrinter.cpp
   VerifyDiagnosticConsumer.cpp
   InterfaceStubFunctionsConsumer.cpp
+  CodeSnippetHighlighter.cpp
 
   DEPENDS
   ClangDriverOptions
diff --git a/clang/lib/Frontend/CodeSnippetHighlighter.cpp 
b/clang/lib/Frontend/CodeSnippetHighlighter.cpp
new file mode 100644
index 000..829a533ad2692e5
--- /dev/null
+++ b/clang/lib/Frontend/CodeSnippetHighlighter.cpp
@@ -0,0 +1,120 @@
+
+#include "clang/Frontend/CodeSnippetHighlighter.h"
+#include "clang/Basic/DiagnosticOptions.h"
+#include "clang/Basic/SourceManager.h"
+#include "clang/Lex/Lexer.h"
+#include "llvm/Support/raw_ostream.h"
+
+using namespace clang;
+
+void CodeSnippetHighlighter::ensureTokenData() {
+  if (Initialized)
+return;
+
+  // List of keywords, literals and types we want to highlight.
+  // These are best-effort, as is everything we do wrt. highlighting.
+  Keywords.insert("_Static_assert");
+  Keywords.insert("auto");
+  Keywords.insert("concept");
+  Keywords.insert("const");
+  Keywords.insert("consteva

[clang] [clang] Only build static analyzer sources if requested (PR #71653)

2023-11-08 Thread Timm Baeder via cfe-commits
https://github.com/tbaederr created 
https://github.com/llvm/llvm-project/pull/71653

There used to be a patch similar to this on Phabricator. I asked a long time 
ago if I can pick it up but the author told me they will work on it, which 
never happened.

IIRC there also was a problem with this simple patch since some other component 
depends on the static analyzer being built. Let's see what CI says.

>From aec458976c007f2666c2a1939bf8e48b1840a3fd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Wed, 8 Nov 2023 11:43:22 +0100
Subject: [PATCH] [clang] Only build static analyzer sources if requested

---
 clang/lib/CMakeLists.txt | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/clang/lib/CMakeLists.txt b/clang/lib/CMakeLists.txt
index 1526d65795f8adf..e897fbb16c60d78 100644
--- a/clang/lib/CMakeLists.txt
+++ b/clang/lib/CMakeLists.txt
@@ -23,7 +23,9 @@ add_subdirectory(Tooling)
 add_subdirectory(DirectoryWatcher)
 add_subdirectory(Index)
 add_subdirectory(IndexSerialization)
-add_subdirectory(StaticAnalyzer)
+if(CLANG_ENABLE_STATIC_ANALYZER)
+  add_subdirectory(StaticAnalyzer)
+endif()
 add_subdirectory(Format)
 if(CLANG_INCLUDE_TESTS)
   add_subdirectory(Testing)

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


[clang] [clang] Only build static analyzer sources if requested (PR #71653)

2023-11-08 Thread via cfe-commits
llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)


Changes

There used to be a patch similar to this on Phabricator. I asked a long time 
ago if I can pick it up but the author told me they will work on it, which 
never happened.

IIRC there also was a problem with this simple patch since some other component 
depends on the static analyzer being built. Let's see what CI says.

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


1 Files Affected:

- (modified) clang/lib/CMakeLists.txt (+3-1) 


``diff
diff --git a/clang/lib/CMakeLists.txt b/clang/lib/CMakeLists.txt
index 1526d65795f8adf..e897fbb16c60d78 100644
--- a/clang/lib/CMakeLists.txt
+++ b/clang/lib/CMakeLists.txt
@@ -23,7 +23,9 @@ add_subdirectory(Tooling)
 add_subdirectory(DirectoryWatcher)
 add_subdirectory(Index)
 add_subdirectory(IndexSerialization)
-add_subdirectory(StaticAnalyzer)
+if(CLANG_ENABLE_STATIC_ANALYZER)
+  add_subdirectory(StaticAnalyzer)
+endif()
 add_subdirectory(Format)
 if(CLANG_INCLUDE_TESTS)
   add_subdirectory(Testing)

``




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


[clang] [C++20] [Modules] Bring Decls Hash to BMI for C++20 Module units (PR #71627)

2023-11-08 Thread Chuanqi Xu via cfe-commits
https://github.com/ChuanqiXu9 edited 
https://github.com/llvm/llvm-project/pull/71627
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang][dataflow][NFC] Fix stale comments. (PR #71654)

2023-11-08 Thread via cfe-commits
https://github.com/martinboehme created 
https://github.com/llvm/llvm-project/pull/71654

None

>From 3e889b59ee171c1665b365a933ba3578c4135ed3 Mon Sep 17 00:00:00 2001
From: Martin Braenne 
Date: Wed, 8 Nov 2023 10:51:50 +
Subject: [PATCH] [clang][dataflow][NFC] Fix stale comments.

---
 clang/include/clang/Analysis/FlowSensitive/Arena.h | 8 
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/clang/include/clang/Analysis/FlowSensitive/Arena.h 
b/clang/include/clang/Analysis/FlowSensitive/Arena.h
index 4be308c43fb7675..394ce054e65f11c 100644
--- a/clang/include/clang/Analysis/FlowSensitive/Arena.h
+++ b/clang/include/clang/Analysis/FlowSensitive/Arena.h
@@ -29,8 +29,8 @@ class Arena {
   /// Creates a `T` (some subclass of `StorageLocation`), forwarding `args` to
   /// the constructor, and returns a reference to it.
   ///
-  /// The `DataflowAnalysisContext` takes ownership of the created object. The
-  /// object will be destroyed when the `DataflowAnalysisContext` is destroyed.
+  /// The `Arena` takes ownership of the created object. The object will be
+  /// destroyed when the `Arena` is destroyed.
   template 
   std::enable_if_t::value, T &>
   create(Args &&...args) {
@@ -45,8 +45,8 @@ class Arena {
   /// Creates a `T` (some subclass of `Value`), forwarding `args` to the
   /// constructor, and returns a reference to it.
   ///
-  /// The `DataflowAnalysisContext` takes ownership of the created object. The
-  /// object will be destroyed when the `DataflowAnalysisContext` is destroyed.
+  /// The `Arena` takes ownership of the created object. The object will be
+  /// destroyed when the `Arena` is destroyed.
   template 
   std::enable_if_t::value, T &>
   create(Args &&...args) {

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


[clang] [clang][dataflow][NFC] Fix stale comments. (PR #71654)

2023-11-08 Thread via cfe-commits
llvmbot wrote:




@llvm/pr-subscribers-clang-analysis

Author: None (martinboehme)


Changes



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


1 Files Affected:

- (modified) clang/include/clang/Analysis/FlowSensitive/Arena.h (+4-4) 


``diff
diff --git a/clang/include/clang/Analysis/FlowSensitive/Arena.h 
b/clang/include/clang/Analysis/FlowSensitive/Arena.h
index 4be308c43fb7675..394ce054e65f11c 100644
--- a/clang/include/clang/Analysis/FlowSensitive/Arena.h
+++ b/clang/include/clang/Analysis/FlowSensitive/Arena.h
@@ -29,8 +29,8 @@ class Arena {
   /// Creates a `T` (some subclass of `StorageLocation`), forwarding `args` to
   /// the constructor, and returns a reference to it.
   ///
-  /// The `DataflowAnalysisContext` takes ownership of the created object. The
-  /// object will be destroyed when the `DataflowAnalysisContext` is destroyed.
+  /// The `Arena` takes ownership of the created object. The object will be
+  /// destroyed when the `Arena` is destroyed.
   template 
   std::enable_if_t::value, T &>
   create(Args &&...args) {
@@ -45,8 +45,8 @@ class Arena {
   /// Creates a `T` (some subclass of `Value`), forwarding `args` to the
   /// constructor, and returns a reference to it.
   ///
-  /// The `DataflowAnalysisContext` takes ownership of the created object. The
-  /// object will be destroyed when the `DataflowAnalysisContext` is destroyed.
+  /// The `Arena` takes ownership of the created object. The object will be
+  /// destroyed when the `Arena` is destroyed.
   template 
   std::enable_if_t::value, T &>
   create(Args &&...args) {

``




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


[clang-tools-extra] [clang-tidy] readability-identifier-naming: add support for concepts (PR #71586)

2023-11-08 Thread via cfe-commits
https://github.com/nvartolomei updated 
https://github.com/llvm/llvm-project/pull/71586

>From 0dbdbc35e9dd3f28f8688d8ebf91f977fda98c79 Mon Sep 17 00:00:00 2001
From: Nicolae Vartolomei 
Date: Tue, 7 Nov 2023 20:25:43 +
Subject: [PATCH] [clang-tidy] readability-identifier-naming: add support for
 concepts

Added support for C++20 ``concept`` declarations.
---
 .../readability/IdentifierNamingCheck.cpp |  4 ++
 clang-tools-extra/docs/ReleaseNotes.rst   |  1 +
 .../checks/readability/identifier-naming.rst  | 41 +++
 .../readability/identifier-naming.cpp | 10 +
 4 files changed, 56 insertions(+)

diff --git a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
index 7539b3899682e13..066057fa7208d55 100644
--- a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
@@ -124,6 +124,7 @@ namespace readability {
 m(TypeAlias) \
 m(MacroDefinition) \
 m(ObjcIvar) \
+m(Concept) \
 
 enum StyleKind : int {
 #define ENUMERATE(v) SK_ ## v,
@@ -1391,6 +1392,9 @@ StyleKind IdentifierNamingCheck::findStyleKind(
 return SK_Invalid;
   }
 
+  if (isa(D) && NamingStyles[SK_Concept])
+return SK_Concept;
+
   return SK_Invalid;
 }
 
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index fe8c7175d554c7b..655b9a33c3b72af 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -399,6 +399,7 @@ Changes in existing checks
   ``Leading_upper_snake_case`` naming convention. The handling of ``typedef``
   has been enhanced, particularly within complex types like function pointers
   and cases where style checks were omitted when functions started with macros.
+  Added support for C++20 ``concept`` declarations.
 
 - Improved :doc:`readability-implicit-bool-conversion
   ` check to take
diff --git 
a/clang-tools-extra/docs/clang-tidy/checks/readability/identifier-naming.rst 
b/clang-tools-extra/docs/clang-tidy/checks/readability/identifier-naming.rst
index 608bc2acdc0d5e5..e36bbee394f17ae 100644
--- a/clang-tools-extra/docs/clang-tidy/checks/readability/identifier-naming.rst
+++ b/clang-tools-extra/docs/clang-tidy/checks/readability/identifier-naming.rst
@@ -46,6 +46,7 @@ The following options are described below:
  - :option:`ClassConstantCase`, :option:`ClassConstantPrefix`, 
:option:`ClassConstantSuffix`, :option:`ClassConstantIgnoredRegexp`, 
:option:`ClassConstantHungarianPrefix`
  - :option:`ClassMemberCase`, :option:`ClassMemberPrefix`, 
:option:`ClassMemberSuffix`, :option:`ClassMemberIgnoredRegexp`, 
:option:`ClassMemberHungarianPrefix`
  - :option:`ClassMethodCase`, :option:`ClassMethodPrefix`, 
:option:`ClassMethodSuffix`, :option:`ClassMethodIgnoredRegexp`
+ - :option:`ConceptCase`, :option:`ConceptPrefix`, :option:`ConceptSuffix`, 
:option:`ConceptIgnoredRegexp`
  - :option:`ConstantCase`, :option:`ConstantPrefix`, :option:`ConstantSuffix`, 
:option:`ConstantIgnoredRegexp`, :option:`ConstantHungarianPrefix`
  - :option:`ConstantMemberCase`, :option:`ConstantMemberPrefix`, 
:option:`ConstantMemberSuffix`, :option:`ConstantMemberIgnoredRegexp`, 
:option:`ConstantMemberHungarianPrefix`
  - :option:`ConstantParameterCase`, :option:`ConstantParameterPrefix`, 
:option:`ConstantParameterSuffix`, :option:`ConstantParameterIgnoredRegexp`, 
:option:`ConstantParameterHungarianPrefix`
@@ -410,6 +411,46 @@ After:
   int pre_class_member_post();
 };
 
+.. option:: ConceptCase
+
+When defined, the check will ensure concept names conform to the
+selected casing.
+
+.. option:: ConceptPrefix
+
+When defined, the check will ensure concept names will add the
+prefixed with the given value (regardless of casing).
+
+.. option:: ConceptIgnoredRegexp
+
+Identifier naming checks won't be enforced for concept names
+matching this regular expression.
+
+.. option:: ConceptSuffix
+
+When defined, the check will ensure concept names will add the
+suffix with the given value (regardless of casing).
+
+For example using values of:
+
+   - ConceptCase of ``CamelCase``
+   - ConceptPrefix of ``Pre``
+   - ConceptSuffix of ``Post``
+
+Identifies and/or transforms concept names as follows:
+
+Before:
+
+.. code-block:: c++
+
+template concept my_concept = requires (T t) { {t++}; };
+
+After:
+
+.. code-block:: c++
+
+template concept PreMyConceptPost = requires (T t) { {t++}; };
+
 .. option:: ConstantCase
 
 When defined, the check will ensure constant names conform to the
diff --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming.cpp 
b/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming.cpp
index 84bf7764583e801..e375aa098972bfe 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/readability/identifier-naming.cpp
+++ 
b/clang

[clang-tools-extra] [clang-tidy] readability-identifier-naming: add support for concepts (PR #71586)

2023-11-08 Thread via cfe-commits
https://github.com/nvartolomei edited 
https://github.com/llvm/llvm-project/pull/71586
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] readability-identifier-naming: add support for concepts (PR #71586)

2023-11-08 Thread via cfe-commits
nvartolomei wrote:

@PiotrZSL thank you for your time reviewing this change. I have updated the 
release notes and PR description. I'm new to this project and not familiar with 
its customs. Apologize for any mistakes.

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


[clang] 8d72079 - Fix MSVC "not all control paths return a value" warning. NFC.

2023-11-08 Thread Simon Pilgrim via cfe-commits
Author: Simon Pilgrim
Date: 2023-11-08T10:45:20Z
New Revision: 8d72079077f8b8bf4a8d7173edbb09be083d975b

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

LOG: Fix MSVC "not all control paths return a value" warning. NFC.

Added: 


Modified: 
clang/lib/Analysis/FlowSensitive/Value.cpp

Removed: 




diff  --git a/clang/lib/Analysis/FlowSensitive/Value.cpp 
b/clang/lib/Analysis/FlowSensitive/Value.cpp
index 80dde7c8d582358..349f873f1e6c4d9 100644
--- a/clang/lib/Analysis/FlowSensitive/Value.cpp
+++ b/clang/lib/Analysis/FlowSensitive/Value.cpp
@@ -47,6 +47,7 @@ raw_ostream &operator<<(raw_ostream &OS, const Value &Val) {
   case Value::Kind::FormulaBool:
 return OS << "FormulaBool(" << cast(Val).formula() << 
")";
   }
+  llvm_unreachable("Unknown clang::dataflow::Value::Kind enum");
 }
 
 } // namespace dataflow



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


[clang] [C++20] [Modules] Bring Decls Hash to BMI for C++20 Module units (PR #71627)

2023-11-08 Thread Chuanqi Xu via cfe-commits
https://github.com/ChuanqiXu9 edited 
https://github.com/llvm/llvm-project/pull/71627
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang-tidy] readability-identifier-naming: add support for concepts (PR #71586)

2023-11-08 Thread Piotr Zegar via cfe-commits
https://github.com/PiotrZSL approved this pull request.

LGTM

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


[clang] [C++20] [Modules] Bring Decls Hash to BMI for C++20 Module units (PR #71627)

2023-11-08 Thread Chuanqi Xu via cfe-commits
https://github.com/ChuanqiXu9 ready_for_review 
https://github.com/llvm/llvm-project/pull/71627
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D123235: [OpenMP] atomic compare fail : Parser & AST support

2023-11-08 Thread Sunil K via Phabricator via cfe-commits
koops added inline comments.



Comment at: clang/lib/Basic/OpenMPKinds.cpp:450
+case OMPC_unknown:
+default:
+  return "unknown";

uabelho wrote:
> Adding "default:" here silences the warning.
> But looks like @ABataev commented on something similar earlier and said 
> that's not recommended?
I agree but, I am 



Comment at: clang/lib/Basic/OpenMPKinds.cpp:450
+case OMPC_unknown:
+default:
+  return "unknown";

koops wrote:
> uabelho wrote:
> > Adding "default:" here silences the warning.
> > But looks like @ABataev commented on something similar earlier and said 
> > that's not recommended?
> I agree but, I am 
Alexey was referring to 

```the -Wswitch warning won’t fire when new elements are added to that 
enumeration. To help avoid adding these kinds of defaults, Clang has the 
warning -Wcovered-switch-default which is off by default but turned on when 
building LLVM with a version of Clang that supports the warning```

in the standards document. In this particular case this has been taken care of 
by using the macro 

```
#define OPENMP_ATOMIC_FAIL_MODIFIER(Name)
case OMPC_##Name:
```

which covers all cases added to the enum.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D123235/new/

https://reviews.llvm.org/D123235

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


[clang] [C++20] [Modules] Introduce thin BMI (PR #71622)

2023-11-08 Thread Chuanqi Xu via cfe-commits
ChuanqiXu9 wrote:

Let's discuss the higher level problems in 
https://discourse.llvm.org/t/rfc-c-20-modules-introduce-thin-bmi-and-decls-hash/74755

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


[clang] [C++20] [Modules] Bring Decls Hash to BMI for C++20 Module units (PR #71627)

2023-11-08 Thread Chuanqi Xu via cfe-commits
https://github.com/ChuanqiXu9 edited 
https://github.com/llvm/llvm-project/pull/71627
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clang] [llvm] [lldb] [flang] [IndVars] Add check of loop invariant for trunc instructions (PR #71072)

2023-11-08 Thread Markos Horro via cfe-commits
https://github.com/markoshorro closed 
https://github.com/llvm/llvm-project/pull/71072
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [C++20] [Modules] Bring Decls Hash to BMI for C++20 Module units (PR #71627)

2023-11-08 Thread Chuanqi Xu via cfe-commits
ChuanqiXu9 wrote:

Let's discuss the higher level problems in Let's discuss the higher level 
problems in 
https://discourse.llvm.org/t/rfc-c-20-modules-introduce-thin-bmi-and-decls-hash/74755.
 Especially this one is not good to review since we don't support stacked 
review now.

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


[clang] Fix lit test clang/test/CodeGenHIP/dpp-const-fold.hip. added (PR #71656)

2023-11-08 Thread Pravin Jagtap via cfe-commits
https://github.com/pravinjagtap created 
https://github.com/llvm/llvm-project/pull/71656

during #71139

-nogpulib was missing.

>From 5adcc2a60aeb2d648b90a9f87009a93dde60a64e Mon Sep 17 00:00:00 2001
From: Pravin Jagtap 
Date: Wed, 8 Nov 2023 06:17:38 -0500
Subject: [PATCH] Fix lit test clang/test/CodeGenHIP/dpp-const-fold.hip. added
 during #71139

-nogpulib was missing.
---
 clang/test/CodeGenHIP/dpp-const-fold.hip | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/test/CodeGenHIP/dpp-const-fold.hip 
b/clang/test/CodeGenHIP/dpp-const-fold.hip
index 1d1d135fb06239a..4e5f6eb13f1eefc 100644
--- a/clang/test/CodeGenHIP/dpp-const-fold.hip
+++ b/clang/test/CodeGenHIP/dpp-const-fold.hip
@@ -1,6 +1,6 @@
 // REQUIRES: amdgpu-registered-target
 
-// RUN: %clang --offload-arch=gfx906 -S -o - -emit-llvm --cuda-device-only \
+// RUN: %clang --offload-arch=gfx906 -S -o - -emit-llvm --cuda-device-only 
-nogpuinc -nogpulib \
 // RUN:   %s | FileCheck %s
 
 constexpr static int OpCtrl()

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


[clang] Fix lit test clang/test/CodeGenHIP/dpp-const-fold.hip. added (PR #71656)

2023-11-08 Thread via cfe-commits
llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Pravin Jagtap (pravinjagtap)


Changes

during #71139

-nogpulib was missing.

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


1 Files Affected:

- (modified) clang/test/CodeGenHIP/dpp-const-fold.hip (+1-1) 


``diff
diff --git a/clang/test/CodeGenHIP/dpp-const-fold.hip 
b/clang/test/CodeGenHIP/dpp-const-fold.hip
index 1d1d135fb06239a..4e5f6eb13f1eefc 100644
--- a/clang/test/CodeGenHIP/dpp-const-fold.hip
+++ b/clang/test/CodeGenHIP/dpp-const-fold.hip
@@ -1,6 +1,6 @@
 // REQUIRES: amdgpu-registered-target
 
-// RUN: %clang --offload-arch=gfx906 -S -o - -emit-llvm --cuda-device-only \
+// RUN: %clang --offload-arch=gfx906 -S -o - -emit-llvm --cuda-device-only 
-nogpuinc -nogpulib \
 // RUN:   %s | FileCheck %s
 
 constexpr static int OpCtrl()

``




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


[clang] Fix lit test clang/test/CodeGenHIP/dpp-const-fold.hip. added (PR #71656)

2023-11-08 Thread Vikram Hegde via cfe-commits
https://github.com/vikramRH approved this pull request.


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


[clang] [llvm] [Coroutines] Introduce [[clang::coro_only_destroy_when_complete]] (PR #71014)

2023-11-08 Thread Chuanqi Xu via cfe-commits

@@ -0,0 +1,59 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c++20 \
+// RUN: -disable-llvm-passes -emit-llvm %s -o - | FileCheck %s
+
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c++20 \
+// RUN: -O3 -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK-O
+
+#include "Inputs/coroutine.h"
+
+using namespace std;
+
+struct A;
+struct A_promise_type {
+  A get_return_object();
+  suspend_always initial_suspend();
+  suspend_always final_suspend() noexcept;
+  void return_value(int);
+  void unhandled_exception();
+
+  std::coroutine_handle<> handle;
+};
+
+struct Awaitable{
+  bool await_ready();
+  int await_resume();
+  template 
+  void await_suspend(F);
+};
+Awaitable something();
+
+struct dtor {
+dtor();
+~dtor();
+};
+
+struct [[clang::coro_only_destroy_when_complete]] A {

ChuanqiXu9 wrote:

> Since the attribute is on the return type, would that mean it would apply to 
> any coroutine returning the particular type?

Yes.

> Say user is using some library implementation (i.e. folly::coro::Task), they 
> would not be able to use the attribute because it would mark all the 
> coroutines this way.

Yes. My thought is that such attribute can only be applied if the programmers 
understand the behavior of the coroutines very well. So that the users of the 
attribute should be the library writers instead of end users.

And for `folly::coro::Task`, (I didn't check it actively), it can't use the 
attribute if I remember correctly since its framework supports cancelling, that 
said, a task can be cancelled before being complete.

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


[llvm] [clang] [Coroutines] Introduce [[clang::coro_only_destroy_when_complete]] (PR #71014)

2023-11-08 Thread Chuanqi Xu via cfe-commits

@@ -0,0 +1,59 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c++20 \
+// RUN: -disable-llvm-passes -emit-llvm %s -o - | FileCheck %s
+
+// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -std=c++20 \
+// RUN: -O3 -emit-llvm %s -o - | FileCheck %s --check-prefix=CHECK-O
+
+#include "Inputs/coroutine.h"
+
+using namespace std;
+
+struct A;
+struct A_promise_type {
+  A get_return_object();
+  suspend_always initial_suspend();
+  suspend_always final_suspend() noexcept;
+  void return_value(int);
+  void unhandled_exception();
+
+  std::coroutine_handle<> handle;
+};
+
+struct Awaitable{
+  bool await_ready();
+  int await_resume();
+  template 
+  void await_suspend(F);
+};
+Awaitable something();
+
+struct dtor {
+dtor();
+~dtor();
+};
+
+struct [[clang::coro_only_destroy_when_complete]] A {

ChuanqiXu9 wrote:

BTW, while it is technically possible to give finer grained marks, I don't 
think it is good. Since the behaviors of coroutines are controlled by the 
framework, in another word, the library writers. And it is not good for the end 
users to predict the behaviors.

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


[clang] [clang][Interp] Implement __builtin_parity (PR #71662)

2023-11-08 Thread Timm Baeder via cfe-commits
https://github.com/tbaederr created 
https://github.com/llvm/llvm-project/pull/71662

None

>From a4a04d1ef43a680d9ced9d1cdd7db05cbc567436 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Wed, 8 Nov 2023 12:28:52 +0100
Subject: [PATCH] [clang][Interp] Implement __builtin_parity

---
 clang/lib/AST/Interp/InterpBuiltin.cpp  | 16 
 clang/test/AST/Interp/builtin-functions.cpp | 17 -
 2 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/clang/lib/AST/Interp/InterpBuiltin.cpp 
b/clang/lib/AST/Interp/InterpBuiltin.cpp
index f26d298f5b60045..0536fe44b9dcb03 100644
--- a/clang/lib/AST/Interp/InterpBuiltin.cpp
+++ b/clang/lib/AST/Interp/InterpBuiltin.cpp
@@ -439,6 +439,15 @@ static bool interp__builtin_popcount(InterpState &S, 
CodePtr OpPC,
   return true;
 }
 
+static bool interp__builtin_parity(InterpState &S, CodePtr OpPC,
+   const InterpFrame *Frame,
+   const Function *Func, const CallExpr *Call) 
{
+  PrimType ArgT = *S.getContext().classify(Call->getArg(0)->getType());
+  APSInt Val = peekToAPSInt(S.Stk, ArgT);
+  pushInt(S, Val.popcount() % 2);
+  return true;
+}
+
 bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F,
   const CallExpr *Call) {
   InterpFrame *Frame = S.Current;
@@ -576,6 +585,13 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const 
Function *F,
   return retInt(S, OpPC, Dummy);
 break;
 
+  case Builtin::BI__builtin_parity:
+  case Builtin::BI__builtin_parityl:
+  case Builtin::BI__builtin_parityll:
+if (interp__builtin_parity(S, OpPC, Frame, F, Call))
+  return retInt(S, OpPC, Dummy);
+break;
+
   default:
 return false;
   }
diff --git a/clang/test/AST/Interp/builtin-functions.cpp 
b/clang/test/AST/Interp/builtin-functions.cpp
index a78a0fbdf11b1d7..14604a2b553f151 100644
--- a/clang/test/AST/Interp/builtin-functions.cpp
+++ b/clang/test/AST/Interp/builtin-functions.cpp
@@ -274,6 +274,7 @@ namespace SourceLocation {
   }
 }
 
+#define BITSIZE(x) (sizeof(x) * 8)
 namespace popcount {
   static_assert(__builtin_popcount(~0u) == __CHAR_BIT__ * sizeof(unsigned 
int), "");
   static_assert(__builtin_popcount(0) == 0, "");
@@ -283,7 +284,6 @@ namespace popcount {
   static_assert(__builtin_popcountll(0) == 0, "");
 
   /// From test/Sema/constant-builtins-2.c
-#define BITSIZE(x) (sizeof(x) * 8)
   char popcount1[__builtin_popcount(0) == 0 ? 1 : -1];
   char popcount2[__builtin_popcount(0xF0F0) == 8 ? 1 : -1];
   char popcount3[__builtin_popcount(~0) == BITSIZE(int) ? 1 : -1];
@@ -295,3 +295,18 @@ namespace popcount {
   char popcount9[__builtin_popcountll(0xF0F0LL) == 8 ? 1 : -1];
   char popcount10[__builtin_popcountll(~0LL) == BITSIZE(long long) ? 1 : -1];
 }
+
+namespace parity {
+  /// From test/Sema/constant-builtins-2.c
+  char parity1[__builtin_parity(0) == 0 ? 1 : -1];
+  char parity2[__builtin_parity(0xb821) == 0 ? 1 : -1];
+  char parity3[__builtin_parity(0xb822) == 0 ? 1 : -1];
+  char parity4[__builtin_parity(0xb823) == 1 ? 1 : -1];
+  char parity5[__builtin_parity(0xb824) == 0 ? 1 : -1];
+  char parity6[__builtin_parity(0xb825) == 1 ? 1 : -1];
+  char parity7[__builtin_parity(0xb826) == 1 ? 1 : -1];
+  char parity8[__builtin_parity(~0) == 0 ? 1 : -1];
+  char parity9[__builtin_parityl(1L << (BITSIZE(long) - 1)) == 1 ? 1 : -1];
+  char parity10[__builtin_parityll(1LL << (BITSIZE(long long) - 1)) == 1 ? 1 : 
-1];
+}
+

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


[clang] [clang][Interp] Implement __builtin_parity (PR #71662)

2023-11-08 Thread via cfe-commits
llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)


Changes



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


2 Files Affected:

- (modified) clang/lib/AST/Interp/InterpBuiltin.cpp (+16) 
- (modified) clang/test/AST/Interp/builtin-functions.cpp (+16-1) 


``diff
diff --git a/clang/lib/AST/Interp/InterpBuiltin.cpp 
b/clang/lib/AST/Interp/InterpBuiltin.cpp
index f26d298f5b60045..0536fe44b9dcb03 100644
--- a/clang/lib/AST/Interp/InterpBuiltin.cpp
+++ b/clang/lib/AST/Interp/InterpBuiltin.cpp
@@ -439,6 +439,15 @@ static bool interp__builtin_popcount(InterpState &S, 
CodePtr OpPC,
   return true;
 }
 
+static bool interp__builtin_parity(InterpState &S, CodePtr OpPC,
+   const InterpFrame *Frame,
+   const Function *Func, const CallExpr *Call) 
{
+  PrimType ArgT = *S.getContext().classify(Call->getArg(0)->getType());
+  APSInt Val = peekToAPSInt(S.Stk, ArgT);
+  pushInt(S, Val.popcount() % 2);
+  return true;
+}
+
 bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F,
   const CallExpr *Call) {
   InterpFrame *Frame = S.Current;
@@ -576,6 +585,13 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const 
Function *F,
   return retInt(S, OpPC, Dummy);
 break;
 
+  case Builtin::BI__builtin_parity:
+  case Builtin::BI__builtin_parityl:
+  case Builtin::BI__builtin_parityll:
+if (interp__builtin_parity(S, OpPC, Frame, F, Call))
+  return retInt(S, OpPC, Dummy);
+break;
+
   default:
 return false;
   }
diff --git a/clang/test/AST/Interp/builtin-functions.cpp 
b/clang/test/AST/Interp/builtin-functions.cpp
index a78a0fbdf11b1d7..14604a2b553f151 100644
--- a/clang/test/AST/Interp/builtin-functions.cpp
+++ b/clang/test/AST/Interp/builtin-functions.cpp
@@ -274,6 +274,7 @@ namespace SourceLocation {
   }
 }
 
+#define BITSIZE(x) (sizeof(x) * 8)
 namespace popcount {
   static_assert(__builtin_popcount(~0u) == __CHAR_BIT__ * sizeof(unsigned 
int), "");
   static_assert(__builtin_popcount(0) == 0, "");
@@ -283,7 +284,6 @@ namespace popcount {
   static_assert(__builtin_popcountll(0) == 0, "");
 
   /// From test/Sema/constant-builtins-2.c
-#define BITSIZE(x) (sizeof(x) * 8)
   char popcount1[__builtin_popcount(0) == 0 ? 1 : -1];
   char popcount2[__builtin_popcount(0xF0F0) == 8 ? 1 : -1];
   char popcount3[__builtin_popcount(~0) == BITSIZE(int) ? 1 : -1];
@@ -295,3 +295,18 @@ namespace popcount {
   char popcount9[__builtin_popcountll(0xF0F0LL) == 8 ? 1 : -1];
   char popcount10[__builtin_popcountll(~0LL) == BITSIZE(long long) ? 1 : -1];
 }
+
+namespace parity {
+  /// From test/Sema/constant-builtins-2.c
+  char parity1[__builtin_parity(0) == 0 ? 1 : -1];
+  char parity2[__builtin_parity(0xb821) == 0 ? 1 : -1];
+  char parity3[__builtin_parity(0xb822) == 0 ? 1 : -1];
+  char parity4[__builtin_parity(0xb823) == 1 ? 1 : -1];
+  char parity5[__builtin_parity(0xb824) == 0 ? 1 : -1];
+  char parity6[__builtin_parity(0xb825) == 1 ? 1 : -1];
+  char parity7[__builtin_parity(0xb826) == 1 ? 1 : -1];
+  char parity8[__builtin_parity(~0) == 0 ? 1 : -1];
+  char parity9[__builtin_parityl(1L << (BITSIZE(long) - 1)) == 1 ? 1 : -1];
+  char parity10[__builtin_parityll(1LL << (BITSIZE(long long) - 1)) == 1 ? 1 : 
-1];
+}
+

``




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


[clang-tools-extra] [clangd] Correctly identify the next token after the completion point (PR #69153)

2023-11-08 Thread Younan Zhang via cfe-commits
https://github.com/zyn0217 edited 
https://github.com/llvm/llvm-project/pull/69153
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clangd] Correctly identify the next token after the completion point (PR #69153)

2023-11-08 Thread Younan Zhang via cfe-commits
https://github.com/zyn0217 approved this pull request.

I'd like to approve the patch boldly since the findTokenAfterCompletionPoint is 
mostly duplicated from `Lexer::findNextToken` except for a difference that our 
version calls `Loc.getLocWithOffset(1)` rather than MeasureTokenLength() for 
the next token's location.

I have also tried another approach similar to Nathan's, in which I have 
constructed a lexer from the current location (i.e. the completion point) as 
well as the preprocessor. It looks as complicated as this way, and I don't 
think that is more optimal. (Or should I conclude that this is the best option?)

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


[clang-tools-extra] [clangd] Correctly identify the next token after the completion point (PR #69153)

2023-11-08 Thread Younan Zhang via cfe-commits

@@ -1491,6 +1491,46 @@ FuzzyFindRequest 
speculativeFuzzyFindRequestForCompletion(
   return CachedReq;
 }
 
+// This function is similar to Lexer::findNextToken(), but assumes
+// that the input SourceLocation is the completion point (which is
+// a case findNextToken() does not handle).
+std::optional
+findTokenAfterCompletionPoint(SourceLocation CompletionPoint,
+  const SourceManager &SM,
+  const LangOptions &LangOpts) {
+  SourceLocation Loc = CompletionPoint;

zyn0217 wrote:

I was about to comment that we should add an assertion here to reflect the 
contract. However, after going through the codes, it seems hard to tell the 
token kind under a source location without a lexer. :(

Also, do you think it's possible to make this function a static member of 
`Lexer` like `Lexer::findNextToken`? That way we might need a slight refactor 
to reuse some common logics.

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


[clang-tools-extra] [clangd] Correctly identify the next token after the completion point (PR #69153)

2023-11-08 Thread Younan Zhang via cfe-commits
https://github.com/zyn0217 edited 
https://github.com/llvm/llvm-project/pull/69153
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang-tools-extra] [clangd] Correctly identify the next token after the completion point (PR #69153)

2023-11-08 Thread Younan Zhang via cfe-commits
https://github.com/zyn0217 edited 
https://github.com/llvm/llvm-project/pull/69153
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [llvm] [Coroutines] Introduce [[clang::coro_only_destroy_when_complete]] (PR #71014)

2023-11-08 Thread Chuanqi Xu via cfe-commits
ChuanqiXu9 wrote:

> > > Presumably there should only be one spelling everywhere.
> > 
> > 
> > Done
> 
> Missed a few. ;-)

Sorry and thanks for the detailed comment!

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


[clang] [llvm] [Coroutines] Introduce [[clang::coro_only_destroy_when_complete]] (PR #71014)

2023-11-08 Thread Chuanqi Xu via cfe-commits
https://github.com/ChuanqiXu9 updated 
https://github.com/llvm/llvm-project/pull/71014

>From 4531d8b95ecaf08e672939a49fa18415851d136e Mon Sep 17 00:00:00 2001
From: Chuanqi Xu 
Date: Thu, 2 Nov 2023 11:11:59 +0800
Subject: [PATCH] [Coroutines] Introduce
 [[clang::coro_only_destroy_when_complete]]

Close https://github.com/llvm/llvm-project/issues/56980.

This patch tries to introduce a light-weight optimizer for coroutines
which are guaranteed to only be destroyed afer it reached the final
suspend.

The rationale behind the patch is simple. See the example:

```C++
A foo() {
  dtor d;
  co_await something();
  dtor d1;
  co_await something();
  dtor d2;
  co_return 43;
}
```

Generally the generated .destroy function may be:

```C++
void foo.destroy(foo.Frame *frame) {
  switch(frame->suspend_index()) {
case 1:
  frame->d.~dtor();
  break;
case 2:
  frame->d.~dtor();
  frame->d1.~dtor();
  break;
case 3:
  frame->d.~dtor();
  frame->d1.~dtor();
  frame->d2.~dtor();
  break;
default: // coroutine completed or haven't started
  break;
  }

  frame->promise.~promise_type();
  delete frame;
}
```

Since the compiler need to be ready for all the cases that the coroutine
may be destroyed in a valid state.

However, from the user's perspective, we can understand that certain
coroutine types may only be destroyed after it reached to the final
suspend point. And we need a method to teach the compiler about this.
Then this is the patch. After the compiler recognized that the
coroutines can only be destroyed after complete, it can optimize the
above example to:

```C++
void foo.destroy(foo.Frame *frame) {
  frame->promise.~promise_type();
  delete frame;
}
```

I spent a lot of time experimenting and experiencing this in the
downstream. The numbers are really good. In a real-world coroutine-heavy
workload, the size of the build dir (including .o files) reduces 14%. And
the size of final libraries (excluding the .o files) reduces 8% in Debug
mode and 1% in Release mode.
---
 clang/docs/ReleaseNotes.rst   |   3 +
 clang/include/clang/Basic/Attr.td |  12 ++
 clang/include/clang/Basic/AttrDocs.td |  66 +
 clang/lib/CodeGen/CGCoroutine.cpp |   4 +
 .../coro-only-destroy-when-complete.cpp   |  59 
 ...a-attribute-supported-attributes-list.test |   1 +
 llvm/docs/Coroutines.rst  |  11 ++
 llvm/include/llvm/Bitcode/LLVMBitCodes.h  |   1 +
 llvm/include/llvm/IR/Attributes.td|   3 +
 llvm/include/llvm/IR/Function.h   |   7 +
 llvm/lib/Bitcode/Reader/BitcodeReader.cpp |   2 +
 llvm/lib/Bitcode/Writer/BitcodeWriter.cpp |   2 +
 llvm/lib/Transforms/Coroutines/CoroSplit.cpp  |  21 ++-
 llvm/lib/Transforms/Utils/CodeExtractor.cpp   |   1 +
 .../coro-only-destroy-when-complete.ll| 137 ++
 15 files changed, 323 insertions(+), 7 deletions(-)
 create mode 100644 
clang/test/CodeGenCoroutines/coro-only-destroy-when-complete.cpp
 create mode 100644 
llvm/test/Transforms/Coroutines/coro-only-destroy-when-complete.ll

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 8bac599f88503af..7a131cb520aa600 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -296,6 +296,9 @@ Attribute Changes in Clang
   is ignored, changed from the former incorrect suggestion to move it past
   declaration specifiers. (`#58637 
`_)
 
+- Clang now introduced ``[[clang::coro_only_destroy_when_complete]]`` attribute
+  to reduce the size of the destroy functions for coroutines which are known to
+  be destroyed after having reached the final suspend point.
 
 Improvements to Clang's diagnostics
 ---
diff --git a/clang/include/clang/Basic/Attr.td 
b/clang/include/clang/Basic/Attr.td
index 60b54c155e5..31434565becaec6 100644
--- a/clang/include/clang/Basic/Attr.td
+++ b/clang/include/clang/Basic/Attr.td
@@ -1082,6 +1082,18 @@ def CFConsumed : InheritableParamAttr {
   let Documentation = [RetainBehaviorDocs];
 }
 
+
+// coro_only_destroy_when_complete indicates the coroutines whose return type
+// is marked by coro_only_destroy_when_complete can only be destroyed when the
+// coroutine completes. Then the space for the destroy functions can be saved.
+def CoroOnlyDestroyWhenComplete : InheritableAttr {
+  let Spellings = [Clang<"coro_only_destroy_when_complete">];
+  let Subjects = SubjectList<[CXXRecord]>;
+  let LangOpts = [CPlusPlus];
+  let Documentation = [CoroOnlyDestroyWhenCompleteDocs];
+  let SimpleHandler = 1;
+}
+
 // OSObject-based attributes.
 def OSConsumed : InheritableParamAttr {
   let Spellings = [Clang<"os_consumed">];
diff --git a/clang/include/clang/Basic/AttrDocs.td 
b/clang/include/clang/Basic/AttrDocs.td
index 05703df2129f612..fa6f6acd0c30e88 100644
--- a/clang/include/clang/Basic/AttrDocs.td
+++ b/clang/

[clang] [mlir] [llvm] [AArch64][SME] Remove immediate argument restriction for svldr and svstr (PR #68565)

2023-11-08 Thread Sam Tebbs via cfe-commits
https://github.com/SamTebbs33 updated 
https://github.com/llvm/llvm-project/pull/68565

>From de07976922782b9dcf5d13d44551b782dc8b3b94 Mon Sep 17 00:00:00 2001
From: Samuel Tebbs 
Date: Fri, 6 Oct 2023 17:09:36 +0100
Subject: [PATCH 01/10] [AArch64][SME] Remove immediate argument restriction
 for svldr and svstr

The svldr_vnum_za and svstr_vnum_za builtins/intrinsics currently
require that the vnum argument be an immediate, since the instructions
take an immediate vector number. However, we emit 0 as the immediate
for the instruction no matter what, and instead modify the base register.

This patch removes that restriction on the argument, so that the
argument can be a non-immediate. If an appropriate immediate was
passed to the builtin then CGBuiltin passes that directly to the LLVM
intrinsic, otherwise it modifies the base register as is existing
behaviour.
---
 clang/lib/CodeGen/CGBuiltin.cpp   | 45 
 .../aarch64-sme-intrinsics/acle_sme_ldr.c | 71 ---
 .../aarch64-sme-intrinsics/acle_sme_str.c | 51 -
 llvm/include/llvm/IR/IntrinsicsAArch64.td |  4 +-
 llvm/lib/Target/AArch64/SMEInstrFormats.td| 10 +--
 .../CostModel/ARM/unaligned_double_load.ll| 59 +++
 .../CodeGen/AArch64/sme-intrinsics-loads.ll   | 33 +++--
 7 files changed, 166 insertions(+), 107 deletions(-)
 create mode 100644 llvm/test/Analysis/CostModel/ARM/unaligned_double_load.ll

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index e1211bb8949b665..63508b40096141e 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -9712,6 +9712,11 @@ Value *CodeGenFunction::EmitSVEMaskedStore(const 
CallExpr *E,
   return Store;
 }
 
+Value *CodeGenFunction::EmitTileslice(Value *Offset, Value *Base) {
+  llvm::Value *CastOffset = Builder.CreateIntCast(Offset, Int64Ty, false);
+  return Builder.CreateAdd(Base, CastOffset, "tileslice");
+}
+
 Value *CodeGenFunction::EmitSMELd1St1(const SVETypeFlags &TypeFlags,
   SmallVectorImpl &Ops,
   unsigned IntID) {
@@ -9767,18 +9772,34 @@ Value *CodeGenFunction::EmitSMEZero(const SVETypeFlags 
&TypeFlags,
 Value *CodeGenFunction::EmitSMELdrStr(const SVETypeFlags &TypeFlags,
   SmallVectorImpl &Ops,
   unsigned IntID) {
-  if (Ops.size() == 3) {
-Function *Cntsb = CGM.getIntrinsic(Intrinsic::aarch64_sme_cntsb);
-llvm::Value *CntsbCall = Builder.CreateCall(Cntsb, {}, "svlb");
-
-llvm::Value *VecNum = Ops[2];
-llvm::Value *MulVL = Builder.CreateMul(CntsbCall, VecNum, "mulvl");
-
-Ops[1] = Builder.CreateGEP(Int8Ty, Ops[1], MulVL);
-Ops[0] = Builder.CreateAdd(
-Ops[0], Builder.CreateIntCast(VecNum, Int32Ty, true), "tileslice");
-Ops.erase(&Ops[2]);
-  }
+  if (Ops.size() == 2) {
+// Intrinsics without a vecnum also use this function, so just provide 0
+Ops.push_back(Ops[1]);
+Ops[1] = Builder.getInt32(0);
+  } else {
+int Imm = -1;
+if (ConstantInt* C = dyn_cast(Ops[2]))
+  if (C->getZExtValue() <= 15)
+  Imm = C->getZExtValue();
+
+if (Imm != -1) {
+  Ops[2] = Ops[1];
+  Ops[1] = Builder.getInt32(Imm);
+} else {
+  Function *Cntsb = CGM.getIntrinsic(Intrinsic::aarch64_sme_cntsb);
+  llvm::Value *CntsbCall = Builder.CreateCall(Cntsb, {}, "svlb");
+
+  llvm::Value *VecNum = Ops[2];
+  llvm::Value *MulVL = Builder.CreateMul(
+  CntsbCall,
+  VecNum,
+  "mulvl");
+
+  Ops[2] = Builder.CreateGEP(Int8Ty, Ops[1], MulVL);
+  Ops[1] = Builder.getInt32(0);
+  Ops[0] = Builder.CreateIntCast(EmitTileslice(Ops[0], VecNum), Int32Ty, 
false);
+}
+   }
   Function *F = CGM.getIntrinsic(IntID, {});
   return Builder.CreateCall(F, Ops);
 }
diff --git a/clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_ldr.c 
b/clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_ldr.c
index e85c47072f2df80..8e07cf1d11c19b2 100644
--- a/clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_ldr.c
+++ b/clang/test/CodeGen/aarch64-sme-intrinsics/acle_sme_ldr.c
@@ -6,57 +6,46 @@
 
 #include 
 
-// CHECK-C-LABEL: define dso_local void @test_svldr_vnum_za(
-// CHECK-C-SAME: i32 noundef [[SLICE_BASE:%.*]], ptr noundef [[PTR:%.*]]) 
local_unnamed_addr #[[ATTR0:[0-9]+]] {
-// CHECK-C-NEXT:  entry:
-// CHECK-C-NEXT:tail call void @llvm.aarch64.sme.ldr(i32 [[SLICE_BASE]], 
ptr [[PTR]])
-// CHECK-C-NEXT:ret void
-//
-// CHECK-CXX-LABEL: define dso_local void @_Z18test_svldr_vnum_zajPKv(
-// CHECK-CXX-SAME: i32 noundef [[SLICE_BASE:%.*]], ptr noundef [[PTR:%.*]]) 
local_unnamed_addr #[[ATTR0:[0-9]+]] {
-// CHECK-CXX-NEXT:  entry:
-// CHECK-CXX-NEXT:tail call void @llvm.aarch64.sme.ldr(i32 [[SLICE_BASE]], 
ptr [[PTR]])
-// CHECK-CXX-NEXT:ret void
+// CHECK-C-LABEL: @test_svldr_vnum_za(
+// CHECK-CXX-LABEL: @_Z18test_svldr_vnum_zaj

[clang] d1fb930 - Revert "[AMDGPU] const-fold imm operands of amdgcn_update_dpp intrinsic (#71139)"

2023-11-08 Thread Mitch Phillips via cfe-commits
Author: Mitch Phillips
Date: 2023-11-08T12:50:53+01:00
New Revision: d1fb9307951319eea3e869d78470341d603c8363

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

LOG: Revert "[AMDGPU] const-fold imm operands of amdgcn_update_dpp intrinsic 
(#71139)"

This reverts commit 32a3f2afe6ea7ffb02a6a188b123ded6f4c89f6c.

Reason: Broke the sanitizer buildbots. More details at
https://github.com/llvm/llvm-project/commit/32a3f2afe6ea7ffb02a6a188b123ded6f4c89f6c

Added: 


Modified: 
clang/lib/CodeGen/CGBuiltin.cpp
clang/lib/CodeGen/CodeGenFunction.h

Removed: 
clang/test/CodeGenHIP/dpp-const-fold.hip



diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index e7e498e8a933131..5ab81cc605819c3 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -5708,7 +5708,18 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
 llvm::FunctionType *FTy = F->getFunctionType();
 
 for (unsigned i = 0, e = E->getNumArgs(); i != e; ++i) {
-  Value *ArgValue = EmitScalarOrConstFoldImmArg(ICEArguments, i, E);
+  Value *ArgValue;
+  // If this is a normal argument, just emit it as a scalar.
+  if ((ICEArguments & (1 << i)) == 0) {
+ArgValue = EmitScalarExpr(E->getArg(i));
+  } else {
+// If this is required to be a constant, constant fold it so that we
+// know that the generated intrinsic gets a ConstantInt.
+ArgValue = llvm::ConstantInt::get(
+getLLVMContext(),
+*E->getArg(i)->getIntegerConstantExpr(getContext()));
+  }
+
   // If the intrinsic arg type is 
diff erent from the builtin arg type
   // we need to do a bit cast.
   llvm::Type *PTy = FTy->getParamType(i);
@@ -8588,7 +8599,15 @@ Value *CodeGenFunction::EmitARMBuiltinExpr(unsigned 
BuiltinID,
   }
 }
 
-Ops.push_back(EmitScalarOrConstFoldImmArg(ICEArguments, i, E));
+if ((ICEArguments & (1 << i)) == 0) {
+  Ops.push_back(EmitScalarExpr(E->getArg(i)));
+} else {
+  // If this is required to be a constant, constant fold it so that we know
+  // that the generated intrinsic gets a ConstantInt.
+  Ops.push_back(llvm::ConstantInt::get(
+  getLLVMContext(),
+  *E->getArg(i)->getIntegerConstantExpr(getContext(;
+}
   }
 
   switch (BuiltinID) {
@@ -11075,7 +11094,15 @@ Value 
*CodeGenFunction::EmitAArch64BuiltinExpr(unsigned BuiltinID,
 continue;
   }
 }
-Ops.push_back(EmitScalarOrConstFoldImmArg(ICEArguments, i, E));
+if ((ICEArguments & (1 << i)) == 0) {
+  Ops.push_back(EmitScalarExpr(E->getArg(i)));
+} else {
+  // If this is required to be a constant, constant fold it so that we know
+  // that the generated intrinsic gets a ConstantInt.
+  Ops.push_back(llvm::ConstantInt::get(
+  getLLVMContext(),
+  *E->getArg(i)->getIntegerConstantExpr(getContext(;
+}
   }
 
   auto SISDMap = ArrayRef(AArch64SISDIntrinsicMap);
@@ -13787,7 +13814,16 @@ Value *CodeGenFunction::EmitX86BuiltinExpr(unsigned 
BuiltinID,
   assert(Error == ASTContext::GE_None && "Should not codegen an error");
 
   for (unsigned i = 0, e = E->getNumArgs(); i != e; i++) {
-Ops.push_back(EmitScalarOrConstFoldImmArg(ICEArguments, i, E));
+// If this is a normal argument, just emit it as a scalar.
+if ((ICEArguments & (1 << i)) == 0) {
+  Ops.push_back(EmitScalarExpr(E->getArg(i)));
+  continue;
+}
+
+// If this is required to be a constant, constant fold it so that we know
+// that the generated intrinsic gets a ConstantInt.
+Ops.push_back(llvm::ConstantInt::get(
+getLLVMContext(), 
*E->getArg(i)->getIntegerConstantExpr(getContext(;
   }
 
   // These exist so that the builtin that takes an immediate can be bounds
@@ -17552,23 +17588,6 @@ void CodeGenFunction::ProcessOrderScopeAMDGCN(Value 
*Order, Value *Scope,
   SSID = getLLVMContext().getOrInsertSyncScopeID(scp);
 }
 
-llvm::Value *CodeGenFunction::EmitScalarOrConstFoldImmArg(unsigned 
ICEArguments,
-  unsigned Idx,
-  const CallExpr *E) {
-  llvm::Value *Arg = nullptr;
-  if ((ICEArguments & (1 << Idx)) == 0) {
-Arg = EmitScalarExpr(E->getArg(Idx));
-  } else {
-// If this is required to be a constant, constant fold it so that we
-// know that the generated intrinsic gets a ConstantInt.
-std::optional Result =
-E->getArg(Idx)->getIntegerConstantExpr(getContext());
-assert(Result && "Expected argument to be a constant");
-Arg = llvm::ConstantInt::get(getLLVMContext(), *Result);
-  }
-  return Arg;
-}
-
 Value *CodeGenFunction::EmitA

[clang-tools-extra] ee03dc1 - Revert "[clangd] Allow hover over 128-bit variable without crashing (#71415)"

2023-11-08 Thread Bjorn Pettersson via cfe-commits
Author: Bjorn Pettersson
Date: 2023-11-08T12:56:26+01:00
New Revision: ee03dc1836348420221f8830cae9868d3a51484c

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

LOG: Revert "[clangd] Allow hover over 128-bit variable without crashing 
(#71415)"

This reverts commit 2626916c45f428226052f5e431e510743aba9e75.

It failed on buildbots not supporting __int128_t.

Added: 


Modified: 
clang-tools-extra/clangd/Hover.cpp
clang-tools-extra/clangd/unittests/HoverTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/Hover.cpp 
b/clang-tools-extra/clangd/Hover.cpp
index a868d3bb4e3fa1d..7f7b5513dff6fee 100644
--- a/clang-tools-extra/clangd/Hover.cpp
+++ b/clang-tools-extra/clangd/Hover.cpp
@@ -408,9 +408,7 @@ void fillFunctionTypeAndParams(HoverInfo &HI, const Decl *D,
 // -2=> 0xfffe
 // -2^32 => 0x
 static llvm::FormattedNumber printHex(const llvm::APSInt &V) {
-  assert(V.getSignificantBits() <= 64 && "Can't print more than 64 bits.");
-  uint64_t Bits =
-  V.getBitWidth() > 64 ? V.trunc(64).getZExtValue() : V.getZExtValue();
+  uint64_t Bits = V.getZExtValue();
   if (V.isNegative() && V.getSignificantBits() <= 32)
 return llvm::format_hex(uint32_t(Bits), 0);
   return llvm::format_hex(Bits, 0);

diff  --git a/clang-tools-extra/clangd/unittests/HoverTests.cpp 
b/clang-tools-extra/clangd/unittests/HoverTests.cpp
index 847f141f521caa0..063a60db044060e 100644
--- a/clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ b/clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -3349,17 +3349,6 @@ TEST(Hover, NoCrashAPInt64) {
   getHover(AST, T.point(), format::getLLVMStyle(), nullptr);
 }
 
-TEST(Hover, NoCrashInt128) {
-  Annotations T(R"cpp(
-constexpr __int128_t value = -4;
-void foo() { va^lue; }
-  )cpp");
-  auto AST = TestTU::withCode(T.code()).build();
-  auto H = getHover(AST, T.point(), format::getLLVMStyle(), nullptr);
-  ASSERT_TRUE(H);
-  EXPECT_EQ(H->Value, "-4 (0xfffc)");
-}
-
 TEST(Hover, DocsFromMostSpecial) {
   Annotations T(R"cpp(
   // doc1



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


[llvm] [clang] [SystemZ] Add backchain target-feature (PR #71668)

2023-11-08 Thread Ilya Leoshkevich via cfe-commits
https://github.com/iii-i created https://github.com/llvm/llvm-project/pull/71668

GCC supports building individual functions with backchain using the 
__attribute__((target("backchain"))) syntax, and Clang should too.

Clang translates this into the "target-features"="+backchain" attribute, and 
the -mbackchain command-line option into the "backchain" attribute. The backend 
currently checks only the latter; furthermore, the backchain target feature is 
not defined.

Handle backchain like soft-float. Define a target feature, convert function 
attribute into it in getSubtargetImpl(), and check for target feature instead 
of function attribute everywhere. Add an end-to-end test to the Clang testsuite.

>From 20c1609d4bf38b811ced90b43153912a834ea7b0 Mon Sep 17 00:00:00 2001
From: Ilya Leoshkevich 
Date: Tue, 7 Nov 2023 17:18:03 +0100
Subject: [PATCH] [SystemZ] Add backchain target-feature

GCC supports building individual functions with backchain using the
__attribute__((target("backchain"))) syntax, and Clang should too.

Clang translates this into the "target-features"="+backchain"
attribute, and the -mbackchain command-line option into the "backchain"
attribute. The backend currently checks only the latter; furthermore,
the backchain target feature is not defined.

Handle backchain like soft-float. Define a target feature, convert
function attribute into it in getSubtargetImpl(), and check for target
feature instead of function attribute everywhere. Add an end-to-end
test to the Clang testsuite.
---
 clang/test/CodeGen/SystemZ/mbackchain-4.c | 11 ++
 llvm/lib/Target/SystemZ/SystemZFeatures.td|  5 +
 .../Target/SystemZ/SystemZFrameLowering.cpp   | 20 ++-
 .../Target/SystemZ/SystemZISelLowering.cpp|  8 
 .../Target/SystemZ/SystemZTargetMachine.cpp   |  8 +---
 5 files changed, 36 insertions(+), 16 deletions(-)
 create mode 100644 clang/test/CodeGen/SystemZ/mbackchain-4.c

diff --git a/clang/test/CodeGen/SystemZ/mbackchain-4.c 
b/clang/test/CodeGen/SystemZ/mbackchain-4.c
new file mode 100644
index 000..6e5f4fc5da40084
--- /dev/null
+++ b/clang/test/CodeGen/SystemZ/mbackchain-4.c
@@ -0,0 +1,11 @@
+// RUN: %clang --target=s390x-linux -O1 -S -o - %s | FileCheck %s
+
+__attribute__((target("backchain")))
+void *foo(void) {
+  return __builtin_return_address(1);
+}
+
+// CHECK-LABEL: foo:
+// CHECK: lg %r1, 0(%r15)
+// CHECK: lg %r2, 112(%r1)
+// CHECK: br %r14
diff --git a/llvm/lib/Target/SystemZ/SystemZFeatures.td 
b/llvm/lib/Target/SystemZ/SystemZFeatures.td
index 78b8394d6486522..fdd94206421a418 100644
--- a/llvm/lib/Target/SystemZ/SystemZFeatures.td
+++ b/llvm/lib/Target/SystemZ/SystemZFeatures.td
@@ -32,6 +32,11 @@ def FeatureSoftFloat : SystemZFeature<
   "Use software emulation for floating point"
 >;
 
+def FeatureBackChain : SystemZFeature<
+  "backchain", "BackChain", (all_of FeatureBackChain),
+  "Store the address of the caller's frame into the callee's stack frame"
+>;
+
 
//===--===//
 //
 // New features added in the Ninth Edition of the z/Architecture
diff --git a/llvm/lib/Target/SystemZ/SystemZFrameLowering.cpp 
b/llvm/lib/Target/SystemZ/SystemZFrameLowering.cpp
index bfd31709eb3e0bc..7522998fd06d8e5 100644
--- a/llvm/lib/Target/SystemZ/SystemZFrameLowering.cpp
+++ b/llvm/lib/Target/SystemZ/SystemZFrameLowering.cpp
@@ -443,7 +443,7 @@ void 
SystemZELFFrameLowering::processFunctionBeforeFrameFinalized(
   MachineFrameInfo &MFFrame = MF.getFrameInfo();
   SystemZMachineFunctionInfo *ZFI = MF.getInfo();
   MachineRegisterInfo *MRI = &MF.getRegInfo();
-  bool BackChain = MF.getFunction().hasFnAttribute("backchain");
+  bool BackChain = MF.getSubtarget().hasBackChain();
 
   if (!usePackedStack(MF) || BackChain)
 // Create the incoming register save area.
@@ -628,7 +628,7 @@ void SystemZELFFrameLowering::emitPrologue(MachineFunction 
&MF,
 .addImm(StackSize);
 }
 else {
-  bool StoreBackchain = MF.getFunction().hasFnAttribute("backchain");
+  bool StoreBackchain = MF.getSubtarget().hasBackChain();
   // If we need backchain, save current stack pointer.  R1 is free at
   // this point.
   if (StoreBackchain)
@@ -786,7 +786,7 @@ void SystemZELFFrameLowering::inlineStackProbe(
   .addMemOperand(MMO);
   };
 
-  bool StoreBackchain = MF.getFunction().hasFnAttribute("backchain");
+  bool StoreBackchain = MF.getSubtarget().hasBackChain();
   if (StoreBackchain)
 BuildMI(*MBB, MBBI, DL, ZII->get(SystemZ::LGR))
   .addReg(SystemZ::R1D, RegState::Define).addReg(SystemZ::R15D);
@@ -861,8 +861,9 @@ StackOffset SystemZELFFrameLowering::getFrameIndexReference(
 unsigned SystemZELFFrameLowering::getRegSpillOffset(MachineFunction &MF,
 Register Reg) const {
   bool IsVarArg = MF.getFunction().isVarArg();
-  bool BackChain = MF.getFunction().hasFnAttribute("backchain");
-  bool SoftFl

[llvm] [clang] [SystemZ] Add backchain target-feature (PR #71668)

2023-11-08 Thread via cfe-commits
llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Ilya Leoshkevich (iii-i)


Changes

GCC supports building individual functions with backchain using the 
__attribute__((target("backchain"))) syntax, and Clang should too.

Clang translates this into the "target-features"="+backchain" attribute, and 
the -mbackchain command-line option into the "backchain" attribute. The backend 
currently checks only the latter; furthermore, the backchain target feature is 
not defined.

Handle backchain like soft-float. Define a target feature, convert function 
attribute into it in getSubtargetImpl(), and check for target feature instead 
of function attribute everywhere. Add an end-to-end test to the Clang testsuite.

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


5 Files Affected:

- (added) clang/test/CodeGen/SystemZ/mbackchain-4.c (+11) 
- (modified) llvm/lib/Target/SystemZ/SystemZFeatures.td (+5) 
- (modified) llvm/lib/Target/SystemZ/SystemZFrameLowering.cpp (+11-9) 
- (modified) llvm/lib/Target/SystemZ/SystemZISelLowering.cpp (+4-4) 
- (modified) llvm/lib/Target/SystemZ/SystemZTargetMachine.cpp (+5-3) 


``diff
diff --git a/clang/test/CodeGen/SystemZ/mbackchain-4.c 
b/clang/test/CodeGen/SystemZ/mbackchain-4.c
new file mode 100644
index 000..6e5f4fc5da40084
--- /dev/null
+++ b/clang/test/CodeGen/SystemZ/mbackchain-4.c
@@ -0,0 +1,11 @@
+// RUN: %clang --target=s390x-linux -O1 -S -o - %s | FileCheck %s
+
+__attribute__((target("backchain")))
+void *foo(void) {
+  return __builtin_return_address(1);
+}
+
+// CHECK-LABEL: foo:
+// CHECK: lg %r1, 0(%r15)
+// CHECK: lg %r2, 112(%r1)
+// CHECK: br %r14
diff --git a/llvm/lib/Target/SystemZ/SystemZFeatures.td 
b/llvm/lib/Target/SystemZ/SystemZFeatures.td
index 78b8394d6486522..fdd94206421a418 100644
--- a/llvm/lib/Target/SystemZ/SystemZFeatures.td
+++ b/llvm/lib/Target/SystemZ/SystemZFeatures.td
@@ -32,6 +32,11 @@ def FeatureSoftFloat : SystemZFeature<
   "Use software emulation for floating point"
 >;
 
+def FeatureBackChain : SystemZFeature<
+  "backchain", "BackChain", (all_of FeatureBackChain),
+  "Store the address of the caller's frame into the callee's stack frame"
+>;
+
 
//===--===//
 //
 // New features added in the Ninth Edition of the z/Architecture
diff --git a/llvm/lib/Target/SystemZ/SystemZFrameLowering.cpp 
b/llvm/lib/Target/SystemZ/SystemZFrameLowering.cpp
index bfd31709eb3e0bc..7522998fd06d8e5 100644
--- a/llvm/lib/Target/SystemZ/SystemZFrameLowering.cpp
+++ b/llvm/lib/Target/SystemZ/SystemZFrameLowering.cpp
@@ -443,7 +443,7 @@ void 
SystemZELFFrameLowering::processFunctionBeforeFrameFinalized(
   MachineFrameInfo &MFFrame = MF.getFrameInfo();
   SystemZMachineFunctionInfo *ZFI = MF.getInfo();
   MachineRegisterInfo *MRI = &MF.getRegInfo();
-  bool BackChain = MF.getFunction().hasFnAttribute("backchain");
+  bool BackChain = MF.getSubtarget().hasBackChain();
 
   if (!usePackedStack(MF) || BackChain)
 // Create the incoming register save area.
@@ -628,7 +628,7 @@ void SystemZELFFrameLowering::emitPrologue(MachineFunction 
&MF,
 .addImm(StackSize);
 }
 else {
-  bool StoreBackchain = MF.getFunction().hasFnAttribute("backchain");
+  bool StoreBackchain = MF.getSubtarget().hasBackChain();
   // If we need backchain, save current stack pointer.  R1 is free at
   // this point.
   if (StoreBackchain)
@@ -786,7 +786,7 @@ void SystemZELFFrameLowering::inlineStackProbe(
   .addMemOperand(MMO);
   };
 
-  bool StoreBackchain = MF.getFunction().hasFnAttribute("backchain");
+  bool StoreBackchain = MF.getSubtarget().hasBackChain();
   if (StoreBackchain)
 BuildMI(*MBB, MBBI, DL, ZII->get(SystemZ::LGR))
   .addReg(SystemZ::R1D, RegState::Define).addReg(SystemZ::R15D);
@@ -861,8 +861,9 @@ StackOffset SystemZELFFrameLowering::getFrameIndexReference(
 unsigned SystemZELFFrameLowering::getRegSpillOffset(MachineFunction &MF,
 Register Reg) const {
   bool IsVarArg = MF.getFunction().isVarArg();
-  bool BackChain = MF.getFunction().hasFnAttribute("backchain");
-  bool SoftFloat = MF.getSubtarget().hasSoftFloat();
+  const SystemZSubtarget &Subtarget = MF.getSubtarget();
+  bool BackChain = Subtarget.hasBackChain();
+  bool SoftFloat = Subtarget.hasSoftFloat();
   unsigned Offset = RegSpillOffsets[Reg];
   if (usePackedStack(MF) && !(IsVarArg && !SoftFloat)) {
 if (SystemZ::GR64BitRegClass.contains(Reg))
@@ -890,8 +891,9 @@ int 
SystemZELFFrameLowering::getOrCreateFramePointerSaveIndex(
 
 bool SystemZELFFrameLowering::usePackedStack(MachineFunction &MF) const {
   bool HasPackedStackAttr = MF.getFunction().hasFnAttribute("packed-stack");
-  bool BackChain = MF.getFunction().hasFnAttribute("backchain");
-  bool SoftFloat = MF.getSubtarget().hasSoftFloat();
+  const SystemZSubtarget &Subtarget = MF.getSubtarget();
+  bool BackChain = Subtarget.hasBackChain

[clang] Revert "Revert "[AMDGPU] const-fold imm operands of (PR #71669)

2023-11-08 Thread Pravin Jagtap via cfe-commits
https://github.com/pravinjagtap created 
https://github.com/llvm/llvm-project/pull/71669

amdgcn_update_dpp intrinsic (#71139)""

This reverts commit d1fb9307951319eea3e869d78470341d603c8363 and fixes the lit 
test clang/test/CodeGenHIP/dpp-const-fold.hip

>From 63f870074df10d0e2624632ac2ab0cb0996b436c Mon Sep 17 00:00:00 2001
From: Pravin Jagtap 
Date: Wed, 8 Nov 2023 07:08:03 -0500
Subject: [PATCH] Revert "Revert "[AMDGPU] const-fold imm operands of
 amdgcn_update_dpp intrinsic (#71139)""

This reverts commit d1fb9307951319eea3e869d78470341d603c8363 and fixes
the lit test clang/test/CodeGenHIP/dpp-const-fold.hip
---
 clang/lib/CodeGen/CGBuiltin.cpp  | 84 +---
 clang/lib/CodeGen/CodeGenFunction.h  |  2 +
 clang/test/CodeGenHIP/dpp-const-fold.hip | 48 ++
 3 files changed, 81 insertions(+), 53 deletions(-)
 create mode 100644 clang/test/CodeGenHIP/dpp-const-fold.hip

diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 5ab81cc605819c3..e7e498e8a933131 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -5708,18 +5708,7 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
 llvm::FunctionType *FTy = F->getFunctionType();
 
 for (unsigned i = 0, e = E->getNumArgs(); i != e; ++i) {
-  Value *ArgValue;
-  // If this is a normal argument, just emit it as a scalar.
-  if ((ICEArguments & (1 << i)) == 0) {
-ArgValue = EmitScalarExpr(E->getArg(i));
-  } else {
-// If this is required to be a constant, constant fold it so that we
-// know that the generated intrinsic gets a ConstantInt.
-ArgValue = llvm::ConstantInt::get(
-getLLVMContext(),
-*E->getArg(i)->getIntegerConstantExpr(getContext()));
-  }
-
+  Value *ArgValue = EmitScalarOrConstFoldImmArg(ICEArguments, i, E);
   // If the intrinsic arg type is different from the builtin arg type
   // we need to do a bit cast.
   llvm::Type *PTy = FTy->getParamType(i);
@@ -8599,15 +8588,7 @@ Value *CodeGenFunction::EmitARMBuiltinExpr(unsigned 
BuiltinID,
   }
 }
 
-if ((ICEArguments & (1 << i)) == 0) {
-  Ops.push_back(EmitScalarExpr(E->getArg(i)));
-} else {
-  // If this is required to be a constant, constant fold it so that we know
-  // that the generated intrinsic gets a ConstantInt.
-  Ops.push_back(llvm::ConstantInt::get(
-  getLLVMContext(),
-  *E->getArg(i)->getIntegerConstantExpr(getContext(;
-}
+Ops.push_back(EmitScalarOrConstFoldImmArg(ICEArguments, i, E));
   }
 
   switch (BuiltinID) {
@@ -11094,15 +11075,7 @@ Value 
*CodeGenFunction::EmitAArch64BuiltinExpr(unsigned BuiltinID,
 continue;
   }
 }
-if ((ICEArguments & (1 << i)) == 0) {
-  Ops.push_back(EmitScalarExpr(E->getArg(i)));
-} else {
-  // If this is required to be a constant, constant fold it so that we know
-  // that the generated intrinsic gets a ConstantInt.
-  Ops.push_back(llvm::ConstantInt::get(
-  getLLVMContext(),
-  *E->getArg(i)->getIntegerConstantExpr(getContext(;
-}
+Ops.push_back(EmitScalarOrConstFoldImmArg(ICEArguments, i, E));
   }
 
   auto SISDMap = ArrayRef(AArch64SISDIntrinsicMap);
@@ -13814,16 +13787,7 @@ Value *CodeGenFunction::EmitX86BuiltinExpr(unsigned 
BuiltinID,
   assert(Error == ASTContext::GE_None && "Should not codegen an error");
 
   for (unsigned i = 0, e = E->getNumArgs(); i != e; i++) {
-// If this is a normal argument, just emit it as a scalar.
-if ((ICEArguments & (1 << i)) == 0) {
-  Ops.push_back(EmitScalarExpr(E->getArg(i)));
-  continue;
-}
-
-// If this is required to be a constant, constant fold it so that we know
-// that the generated intrinsic gets a ConstantInt.
-Ops.push_back(llvm::ConstantInt::get(
-getLLVMContext(), 
*E->getArg(i)->getIntegerConstantExpr(getContext(;
+Ops.push_back(EmitScalarOrConstFoldImmArg(ICEArguments, i, E));
   }
 
   // These exist so that the builtin that takes an immediate can be bounds
@@ -17588,6 +17552,23 @@ void CodeGenFunction::ProcessOrderScopeAMDGCN(Value 
*Order, Value *Scope,
   SSID = getLLVMContext().getOrInsertSyncScopeID(scp);
 }
 
+llvm::Value *CodeGenFunction::EmitScalarOrConstFoldImmArg(unsigned 
ICEArguments,
+  unsigned Idx,
+  const CallExpr *E) {
+  llvm::Value *Arg = nullptr;
+  if ((ICEArguments & (1 << Idx)) == 0) {
+Arg = EmitScalarExpr(E->getArg(Idx));
+  } else {
+// If this is required to be a constant, constant fold it so that we
+// know that the generated intrinsic gets a ConstantInt.
+std::optional Result =
+E->getArg(Idx)->getIntegerConstantExpr(getContext());
+assert(Result && "Expected argument to be a constant");
+Arg = llvm::ConstantInt::

[clang] Revert "Revert "[AMDGPU] const-fold imm operands of (PR #71669)

2023-11-08 Thread via cfe-commits
llvmbot wrote:



@llvm/pr-subscribers-clang-codegen

@llvm/pr-subscribers-clang

Author: Pravin Jagtap (pravinjagtap)


Changes

amdgcn_update_dpp intrinsic (#71139)""

This reverts commit d1fb9307951319eea3e869d78470341d603c8363 and fixes the lit 
test clang/test/CodeGenHIP/dpp-const-fold.hip

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


3 Files Affected:

- (modified) clang/lib/CodeGen/CGBuiltin.cpp (+31-53) 
- (modified) clang/lib/CodeGen/CodeGenFunction.h (+2) 
- (added) clang/test/CodeGenHIP/dpp-const-fold.hip (+48) 


``diff
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 5ab81cc605819c3..e7e498e8a933131 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -5708,18 +5708,7 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl 
GD, unsigned BuiltinID,
 llvm::FunctionType *FTy = F->getFunctionType();
 
 for (unsigned i = 0, e = E->getNumArgs(); i != e; ++i) {
-  Value *ArgValue;
-  // If this is a normal argument, just emit it as a scalar.
-  if ((ICEArguments & (1 << i)) == 0) {
-ArgValue = EmitScalarExpr(E->getArg(i));
-  } else {
-// If this is required to be a constant, constant fold it so that we
-// know that the generated intrinsic gets a ConstantInt.
-ArgValue = llvm::ConstantInt::get(
-getLLVMContext(),
-*E->getArg(i)->getIntegerConstantExpr(getContext()));
-  }
-
+  Value *ArgValue = EmitScalarOrConstFoldImmArg(ICEArguments, i, E);
   // If the intrinsic arg type is different from the builtin arg type
   // we need to do a bit cast.
   llvm::Type *PTy = FTy->getParamType(i);
@@ -8599,15 +8588,7 @@ Value *CodeGenFunction::EmitARMBuiltinExpr(unsigned 
BuiltinID,
   }
 }
 
-if ((ICEArguments & (1 << i)) == 0) {
-  Ops.push_back(EmitScalarExpr(E->getArg(i)));
-} else {
-  // If this is required to be a constant, constant fold it so that we know
-  // that the generated intrinsic gets a ConstantInt.
-  Ops.push_back(llvm::ConstantInt::get(
-  getLLVMContext(),
-  *E->getArg(i)->getIntegerConstantExpr(getContext(;
-}
+Ops.push_back(EmitScalarOrConstFoldImmArg(ICEArguments, i, E));
   }
 
   switch (BuiltinID) {
@@ -11094,15 +11075,7 @@ Value 
*CodeGenFunction::EmitAArch64BuiltinExpr(unsigned BuiltinID,
 continue;
   }
 }
-if ((ICEArguments & (1 << i)) == 0) {
-  Ops.push_back(EmitScalarExpr(E->getArg(i)));
-} else {
-  // If this is required to be a constant, constant fold it so that we know
-  // that the generated intrinsic gets a ConstantInt.
-  Ops.push_back(llvm::ConstantInt::get(
-  getLLVMContext(),
-  *E->getArg(i)->getIntegerConstantExpr(getContext(;
-}
+Ops.push_back(EmitScalarOrConstFoldImmArg(ICEArguments, i, E));
   }
 
   auto SISDMap = ArrayRef(AArch64SISDIntrinsicMap);
@@ -13814,16 +13787,7 @@ Value *CodeGenFunction::EmitX86BuiltinExpr(unsigned 
BuiltinID,
   assert(Error == ASTContext::GE_None && "Should not codegen an error");
 
   for (unsigned i = 0, e = E->getNumArgs(); i != e; i++) {
-// If this is a normal argument, just emit it as a scalar.
-if ((ICEArguments & (1 << i)) == 0) {
-  Ops.push_back(EmitScalarExpr(E->getArg(i)));
-  continue;
-}
-
-// If this is required to be a constant, constant fold it so that we know
-// that the generated intrinsic gets a ConstantInt.
-Ops.push_back(llvm::ConstantInt::get(
-getLLVMContext(), 
*E->getArg(i)->getIntegerConstantExpr(getContext(;
+Ops.push_back(EmitScalarOrConstFoldImmArg(ICEArguments, i, E));
   }
 
   // These exist so that the builtin that takes an immediate can be bounds
@@ -17588,6 +17552,23 @@ void CodeGenFunction::ProcessOrderScopeAMDGCN(Value 
*Order, Value *Scope,
   SSID = getLLVMContext().getOrInsertSyncScopeID(scp);
 }
 
+llvm::Value *CodeGenFunction::EmitScalarOrConstFoldImmArg(unsigned 
ICEArguments,
+  unsigned Idx,
+  const CallExpr *E) {
+  llvm::Value *Arg = nullptr;
+  if ((ICEArguments & (1 << Idx)) == 0) {
+Arg = EmitScalarExpr(E->getArg(Idx));
+  } else {
+// If this is required to be a constant, constant fold it so that we
+// know that the generated intrinsic gets a ConstantInt.
+std::optional Result =
+E->getArg(Idx)->getIntegerConstantExpr(getContext());
+assert(Result && "Expected argument to be a constant");
+Arg = llvm::ConstantInt::get(getLLVMContext(), *Result);
+  }
+  return Arg;
+}
+
 Value *CodeGenFunction::EmitAMDGPUBuiltinExpr(unsigned BuiltinID,
   const CallExpr *E) {
   llvm::AtomicOrdering AO = llvm::AtomicOrdering::SequentiallyConsistent;
@@ -17638,8 +17619,15 @@ Value *CodeGenFunction::EmitAMDGPUBuiltinExpr(unsigned 
Buil

[clang] Fix lit test clang/test/CodeGenHIP/dpp-const-fold.hip. added (PR #71656)

2023-11-08 Thread Pravin Jagtap via cfe-commits
https://github.com/pravinjagtap closed 
https://github.com/llvm/llvm-project/pull/71656
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang] Print static_assert values of arithmetic binary operators (PR #71671)

2023-11-08 Thread Timm Baeder via cfe-commits
https://github.com/tbaederr created 
https://github.com/llvm/llvm-project/pull/71671

These are actually quite useful to print.

>From 2b257a11a78db4769af6751dbc9bd2f37a2b4c71 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= 
Date: Wed, 8 Nov 2023 13:32:41 +0100
Subject: [PATCH] [clang] Print static_assert values of arithmetic binary
 operators

These are actually quite useful to print.
---
 clang/lib/Sema/SemaDeclCXX.cpp |  8 
 clang/test/SemaCXX/complex-folding.cpp | 27 +-
 clang/test/SemaCXX/static-assert.cpp   | 10 ++
 3 files changed, 32 insertions(+), 13 deletions(-)

diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 60786a880b9d3fd..b326d87a72c2815 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -17219,10 +17219,10 @@ static bool UsefulToPrintExpr(const Expr *E) {
   if (const auto *UnaryOp = dyn_cast(E))
 return UsefulToPrintExpr(UnaryOp->getSubExpr());
 
-  // Ignore nested binary operators. This could be a FIXME for improvements
-  // to the diagnostics in the future.
-  if (isa(E))
-return false;
+  // Only print nested arithmetic operators.
+  if (const auto *BO = dyn_cast(E))
+return (BO->isShiftOp() || BO->isAdditiveOp() || BO->isMultiplicativeOp() 
||
+BO->isBitwiseOp());
 
   return true;
 }
diff --git a/clang/test/SemaCXX/complex-folding.cpp 
b/clang/test/SemaCXX/complex-folding.cpp
index 8c56cf0e5d984b0..054f159e9ce0dd2 100644
--- a/clang/test/SemaCXX/complex-folding.cpp
+++ b/clang/test/SemaCXX/complex-folding.cpp
@@ -3,7 +3,8 @@
 // Test the constant folding of builtin complex numbers.
 
 static_assert((0.0 + 0.0j) == (0.0 + 0.0j));
-static_assert((0.0 + 0.0j) != (0.0 + 0.0j)); // expected-error {{static 
assertion}}
+static_assert((0.0 + 0.0j) != (0.0 + 0.0j)); // expected-error {{static 
assertion}} \
+ // expected-note {{evaluates to}}
 
 static_assert((0.0 + 0.0j) == 0.0);
 static_assert(0.0 == (0.0 + 0.0j));
@@ -14,21 +15,29 @@ static_assert(0.0 != 1.0j);
 
 // Walk around the complex plane stepping between angular differences and
 // equality.
-static_assert((1.0 + 0.0j) == (0.0 + 0.0j)); // expected-error {{static 
assertion}}
+static_assert((1.0 + 0.0j) == (0.0 + 0.0j)); // expected-error {{static 
assertion}} \
+ // expected-note {{evaluates to}}
 static_assert((1.0 + 0.0j) == (1.0 + 0.0j));
-static_assert((1.0 + 1.0j) == (1.0 + 0.0j)); // expected-error {{static 
assertion}}
+static_assert((1.0 + 1.0j) == (1.0 + 0.0j)); // expected-error {{static 
assertion}} \
+ // expected-note {{evaluates to}}
 static_assert((1.0 + 1.0j) == (1.0 + 1.0j));
-static_assert((0.0 + 1.0j) == (1.0 + 1.0j)); // expected-error {{static 
assertion}}
+static_assert((0.0 + 1.0j) == (1.0 + 1.0j)); // expected-error {{static 
assertion}} \
+ // expected-note {{evaluates to}}
 static_assert((0.0 + 1.0j) == (0.0 + 1.0j));
-static_assert((-1.0 + 1.0j) == (0.0 + 1.0j)); // expected-error {{static 
assertion}}
+static_assert((-1.0 + 1.0j) == (0.0 + 1.0j)); // expected-error {{static 
assertion}} \
+  // expected-note {{evaluates to}}
 static_assert((-1.0 + 1.0j) == (-1.0 + 1.0j));
-static_assert((-1.0 + 0.0j) == (-1.0 + 1.0j)); // expected-error {{static 
assertion}}
+static_assert((-1.0 + 0.0j) == (-1.0 + 1.0j)); // expected-error {{static 
assertion}} \
+   // expected-note {{evaluates 
to}}
 static_assert((-1.0 + 0.0j) == (-1.0 + 0.0j));
-static_assert((-1.0 - 1.0j) == (-1.0 + 0.0j)); // expected-error {{static 
assertion}}
+static_assert((-1.0 - 1.0j) == (-1.0 + 0.0j)); // expected-error {{static 
assertion}} \
+   // expected-note {{evaluates 
to}}
 static_assert((-1.0 - 1.0j) == (-1.0 - 1.0j));
-static_assert((0.0 - 1.0j) == (-1.0 - 1.0j)); // expected-error {{static 
assertion}}
+static_assert((0.0 - 1.0j) == (-1.0 - 1.0j)); // expected-error {{static 
assertion}} \
+  // expected-note {{evaluates to}}
 static_assert((0.0 - 1.0j) == (0.0 - 1.0j));
-static_assert((1.0 - 1.0j) == (0.0 - 1.0j)); // expected-error {{static 
assertion}}
+static_assert((1.0 - 1.0j) == (0.0 - 1.0j)); // expected-error {{static 
assertion}} \
+ // expected-note {{evaluates to}}
 static_assert((1.0 - 1.0j) == (1.0 - 1.0j));
 
 // Test basic mathematical folding of both complex and real operands.
diff --git a/clang/test/SemaCXX/static-assert.cpp 
b/clang/test/SemaCXX/static-assert.cpp
index 4200d821339edeb..6e1701602ae30cf 100644
--- a/clang/test/SemaCXX/static-assert.cpp
+++ b/clang/test/SemaCXX/static-assert.cpp
@@ -351,4 +351,14 @@ namespace Diagnostics {
 ""
   );
 
+  static_asser

[clang] [clang] Print static_assert values of arithmetic binary operators (PR #71671)

2023-11-08 Thread via cfe-commits
llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)


Changes

These are actually quite useful to print.

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


3 Files Affected:

- (modified) clang/lib/Sema/SemaDeclCXX.cpp (+4-4) 
- (modified) clang/test/SemaCXX/complex-folding.cpp (+18-9) 
- (modified) clang/test/SemaCXX/static-assert.cpp (+10) 


``diff
diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp
index 60786a880b9d3fd..b326d87a72c2815 100644
--- a/clang/lib/Sema/SemaDeclCXX.cpp
+++ b/clang/lib/Sema/SemaDeclCXX.cpp
@@ -17219,10 +17219,10 @@ static bool UsefulToPrintExpr(const Expr *E) {
   if (const auto *UnaryOp = dyn_cast(E))
 return UsefulToPrintExpr(UnaryOp->getSubExpr());
 
-  // Ignore nested binary operators. This could be a FIXME for improvements
-  // to the diagnostics in the future.
-  if (isa(E))
-return false;
+  // Only print nested arithmetic operators.
+  if (const auto *BO = dyn_cast(E))
+return (BO->isShiftOp() || BO->isAdditiveOp() || BO->isMultiplicativeOp() 
||
+BO->isBitwiseOp());
 
   return true;
 }
diff --git a/clang/test/SemaCXX/complex-folding.cpp 
b/clang/test/SemaCXX/complex-folding.cpp
index 8c56cf0e5d984b0..054f159e9ce0dd2 100644
--- a/clang/test/SemaCXX/complex-folding.cpp
+++ b/clang/test/SemaCXX/complex-folding.cpp
@@ -3,7 +3,8 @@
 // Test the constant folding of builtin complex numbers.
 
 static_assert((0.0 + 0.0j) == (0.0 + 0.0j));
-static_assert((0.0 + 0.0j) != (0.0 + 0.0j)); // expected-error {{static 
assertion}}
+static_assert((0.0 + 0.0j) != (0.0 + 0.0j)); // expected-error {{static 
assertion}} \
+ // expected-note {{evaluates to}}
 
 static_assert((0.0 + 0.0j) == 0.0);
 static_assert(0.0 == (0.0 + 0.0j));
@@ -14,21 +15,29 @@ static_assert(0.0 != 1.0j);
 
 // Walk around the complex plane stepping between angular differences and
 // equality.
-static_assert((1.0 + 0.0j) == (0.0 + 0.0j)); // expected-error {{static 
assertion}}
+static_assert((1.0 + 0.0j) == (0.0 + 0.0j)); // expected-error {{static 
assertion}} \
+ // expected-note {{evaluates to}}
 static_assert((1.0 + 0.0j) == (1.0 + 0.0j));
-static_assert((1.0 + 1.0j) == (1.0 + 0.0j)); // expected-error {{static 
assertion}}
+static_assert((1.0 + 1.0j) == (1.0 + 0.0j)); // expected-error {{static 
assertion}} \
+ // expected-note {{evaluates to}}
 static_assert((1.0 + 1.0j) == (1.0 + 1.0j));
-static_assert((0.0 + 1.0j) == (1.0 + 1.0j)); // expected-error {{static 
assertion}}
+static_assert((0.0 + 1.0j) == (1.0 + 1.0j)); // expected-error {{static 
assertion}} \
+ // expected-note {{evaluates to}}
 static_assert((0.0 + 1.0j) == (0.0 + 1.0j));
-static_assert((-1.0 + 1.0j) == (0.0 + 1.0j)); // expected-error {{static 
assertion}}
+static_assert((-1.0 + 1.0j) == (0.0 + 1.0j)); // expected-error {{static 
assertion}} \
+  // expected-note {{evaluates to}}
 static_assert((-1.0 + 1.0j) == (-1.0 + 1.0j));
-static_assert((-1.0 + 0.0j) == (-1.0 + 1.0j)); // expected-error {{static 
assertion}}
+static_assert((-1.0 + 0.0j) == (-1.0 + 1.0j)); // expected-error {{static 
assertion}} \
+   // expected-note {{evaluates 
to}}
 static_assert((-1.0 + 0.0j) == (-1.0 + 0.0j));
-static_assert((-1.0 - 1.0j) == (-1.0 + 0.0j)); // expected-error {{static 
assertion}}
+static_assert((-1.0 - 1.0j) == (-1.0 + 0.0j)); // expected-error {{static 
assertion}} \
+   // expected-note {{evaluates 
to}}
 static_assert((-1.0 - 1.0j) == (-1.0 - 1.0j));
-static_assert((0.0 - 1.0j) == (-1.0 - 1.0j)); // expected-error {{static 
assertion}}
+static_assert((0.0 - 1.0j) == (-1.0 - 1.0j)); // expected-error {{static 
assertion}} \
+  // expected-note {{evaluates to}}
 static_assert((0.0 - 1.0j) == (0.0 - 1.0j));
-static_assert((1.0 - 1.0j) == (0.0 - 1.0j)); // expected-error {{static 
assertion}}
+static_assert((1.0 - 1.0j) == (0.0 - 1.0j)); // expected-error {{static 
assertion}} \
+ // expected-note {{evaluates to}}
 static_assert((1.0 - 1.0j) == (1.0 - 1.0j));
 
 // Test basic mathematical folding of both complex and real operands.
diff --git a/clang/test/SemaCXX/static-assert.cpp 
b/clang/test/SemaCXX/static-assert.cpp
index 4200d821339edeb..6e1701602ae30cf 100644
--- a/clang/test/SemaCXX/static-assert.cpp
+++ b/clang/test/SemaCXX/static-assert.cpp
@@ -351,4 +351,14 @@ namespace Diagnostics {
 ""
   );
 
+  static_assert(1 + 1 != 2, ""); // expected-error {{failed}} \
+ // expected-note {{evaluates to '2 != 2'}}
+  static_assert(1 - 1 == 2, ""); // expected-error {{failed}} \
+ // expe

[clang] [clang-format] Remove special handling of comments after brace/paren (PR #71672)

2023-11-08 Thread Björn Schäpers via cfe-commits
https://github.com/HazardyKnusperkeks created 
https://github.com/llvm/llvm-project/pull/71672

Fixes http://llvm.org/PR55487

The code did not match the documentation about Cpp11BracedListStyle. Changed 
handling of comments after opening braces, which are supposedly function call 
like to behave exactly like their parenthesis counter part.

From 4548aa1186531fb93a623144278fe72896d47e89 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Sch=C3=A4pers?= 
Date: Wed, 8 Nov 2023 13:31:32 +0100
Subject: [PATCH] [clang-format] Remove special handling of comments after
 brace/paren

Fixes http://llvm.org/PR55487

The code did not match the documentation about Cpp11BracedListStyle.
Changed handling of comments after opening braces, which are supposedly
function call like to behave exactly like their parenthesis counter
part.
---
 clang/lib/Format/ContinuationIndenter.cpp |  4 ++-
 clang/lib/Format/TokenAnnotator.cpp   |  8 ++---
 clang/unittests/Format/FormatTest.cpp | 24 +++
 clang/unittests/Format/FormatTestComments.cpp | 29 +++
 4 files changed, 40 insertions(+), 25 deletions(-)

diff --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index 3a829cdedb77fc7..1d76dbe39b00eae 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -802,7 +802,9 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState 
&State, bool DryRun,
   Previous.isNot(TT_ObjCMethodExpr) && Previous.isNot(TT_RequiresClause) &&
   !(Current.MacroParent && Previous.MacroParent) &&
   (Current.isNot(TT_LineComment) ||
-   Previous.isOneOf(BK_BracedInit, TT_VerilogMultiLineListLParen))) {
+   (Previous.is(BK_BracedInit) &&
+(!Previous.Previous || Previous.Previous->isNot(tok::identifier))) ||
+   Previous.is(TT_VerilogMultiLineListLParen))) {
 CurrentState.Indent = State.Column + Spaces;
 CurrentState.IsAligned = true;
   }
diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 729e7e370bf62ea..9691d879735d3aa 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -3510,12 +3510,10 @@ void 
TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) const {
   while (Current) {
 const FormatToken *Prev = Current->Previous;
 if (Current->is(TT_LineComment)) {
-  if (Prev->is(BK_BracedInit) && Prev->opensScope()) {
+  /*if (Prev->is(BK_BracedInit) && Prev->opensScope()) {
 Current->SpacesRequiredBefore =
-(Style.Cpp11BracedListStyle && !Style.SpacesInParensOptions.Other)
-? 0
-: 1;
-  } else if (Prev->is(TT_VerilogMultiLineListLParen)) {
+Style.SpacesInParensOptions.Other ? 1 : 0;
+  } else */if (Prev->is(TT_VerilogMultiLineListLParen)) {
 Current->SpacesRequiredBefore = 0;
   } else {
 Current->SpacesRequiredBefore = Style.SpacesBeforeTrailingComments;
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 80903e7630c8073..e47c27c6b728c80 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -13500,20 +13500,18 @@ TEST_F(FormatTest, LayoutCxx11BraceInitializers) {
"CDDDP83848_RBR_REGISTER};",
NoBinPacking);
 
-  // FIXME: The alignment of these trailing comments might be bad. Then again,
-  // this might be utterly useless in real code.
   verifyFormat("Constructor::Constructor()\n"
-   ": some_value{ //\n"
-   " aaa, //\n"
-   " bbb} {}");
+   ": some_value{  //\n"
+   "  aaa, //\n"
+   "  bbb} {}");
 
   // In braced lists, the first comment is always assumed to belong to the
   // first element. Thus, it can be moved to the next or previous line as
   // appropriate.
-  verifyFormat("function({// First element:\n"
-   "  1,\n"
-   "  // Second element:\n"
-   "  2});",
+  verifyFormat("function({ // First element:\n"
+   "   1,\n"
+   "   // Second element:\n"
+   "   2});",
"function({\n"
"// First element:\n"
"1,\n"
@@ -13582,9 +13580,9 @@ TEST_F(FormatTest, LayoutCxx11BraceInitializers) {
   verifyFormat(
   "someFunction(OtherParam,\n"
   " BracedList{ // comment 1 (Forcing interesting break)\n"
-  " param1, param2,\n"
-  " // comment 2\n"
-  " param3, param4 });",
+  " param1, param2,\n"
+  " // comment 2\n"
+  " param3, param4 });

[clang] [clang-format] Remove special handling of comments after brace/paren (PR #71672)

2023-11-08 Thread via cfe-commits
llvmbot wrote:




@llvm/pr-subscribers-clang-format

Author: Björn Schäpers (HazardyKnusperkeks)


Changes

Fixes http://llvm.org/PR55487

The code did not match the documentation about Cpp11BracedListStyle. Changed 
handling of comments after opening braces, which are supposedly function call 
like to behave exactly like their parenthesis counter part.

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


4 Files Affected:

- (modified) clang/lib/Format/ContinuationIndenter.cpp (+3-1) 
- (modified) clang/lib/Format/TokenAnnotator.cpp (+3-5) 
- (modified) clang/unittests/Format/FormatTest.cpp (+11-13) 
- (modified) clang/unittests/Format/FormatTestComments.cpp (+23-6) 


``diff
diff --git a/clang/lib/Format/ContinuationIndenter.cpp 
b/clang/lib/Format/ContinuationIndenter.cpp
index 3a829cdedb77fc7..1d76dbe39b00eae 100644
--- a/clang/lib/Format/ContinuationIndenter.cpp
+++ b/clang/lib/Format/ContinuationIndenter.cpp
@@ -802,7 +802,9 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState 
&State, bool DryRun,
   Previous.isNot(TT_ObjCMethodExpr) && Previous.isNot(TT_RequiresClause) &&
   !(Current.MacroParent && Previous.MacroParent) &&
   (Current.isNot(TT_LineComment) ||
-   Previous.isOneOf(BK_BracedInit, TT_VerilogMultiLineListLParen))) {
+   (Previous.is(BK_BracedInit) &&
+(!Previous.Previous || Previous.Previous->isNot(tok::identifier))) ||
+   Previous.is(TT_VerilogMultiLineListLParen))) {
 CurrentState.Indent = State.Column + Spaces;
 CurrentState.IsAligned = true;
   }
diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 729e7e370bf62ea..9691d879735d3aa 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -3510,12 +3510,10 @@ void 
TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) const {
   while (Current) {
 const FormatToken *Prev = Current->Previous;
 if (Current->is(TT_LineComment)) {
-  if (Prev->is(BK_BracedInit) && Prev->opensScope()) {
+  /*if (Prev->is(BK_BracedInit) && Prev->opensScope()) {
 Current->SpacesRequiredBefore =
-(Style.Cpp11BracedListStyle && !Style.SpacesInParensOptions.Other)
-? 0
-: 1;
-  } else if (Prev->is(TT_VerilogMultiLineListLParen)) {
+Style.SpacesInParensOptions.Other ? 1 : 0;
+  } else */if (Prev->is(TT_VerilogMultiLineListLParen)) {
 Current->SpacesRequiredBefore = 0;
   } else {
 Current->SpacesRequiredBefore = Style.SpacesBeforeTrailingComments;
diff --git a/clang/unittests/Format/FormatTest.cpp 
b/clang/unittests/Format/FormatTest.cpp
index 80903e7630c8073..e47c27c6b728c80 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -13500,20 +13500,18 @@ TEST_F(FormatTest, LayoutCxx11BraceInitializers) {
"CDDDP83848_RBR_REGISTER};",
NoBinPacking);
 
-  // FIXME: The alignment of these trailing comments might be bad. Then again,
-  // this might be utterly useless in real code.
   verifyFormat("Constructor::Constructor()\n"
-   ": some_value{ //\n"
-   " aaa, //\n"
-   " bbb} {}");
+   ": some_value{  //\n"
+   "  aaa, //\n"
+   "  bbb} {}");
 
   // In braced lists, the first comment is always assumed to belong to the
   // first element. Thus, it can be moved to the next or previous line as
   // appropriate.
-  verifyFormat("function({// First element:\n"
-   "  1,\n"
-   "  // Second element:\n"
-   "  2});",
+  verifyFormat("function({ // First element:\n"
+   "   1,\n"
+   "   // Second element:\n"
+   "   2});",
"function({\n"
"// First element:\n"
"1,\n"
@@ -13582,9 +13580,9 @@ TEST_F(FormatTest, LayoutCxx11BraceInitializers) {
   verifyFormat(
   "someFunction(OtherParam,\n"
   " BracedList{ // comment 1 (Forcing interesting break)\n"
-  " param1, param2,\n"
-  " // comment 2\n"
-  " param3, param4 });",
+  " param1, param2,\n"
+  " // comment 2\n"
+  " param3, param4 });",
   ExtraSpaces);
   verifyFormat(
   "std::this_thread::sleep_for(\n"
@@ -13635,7 +13633,7 @@ TEST_F(FormatTest, LayoutCxx11BraceInitializers) {
   verifyFormat("vector< int > x{ 1, 2, 3, 4 };", SpaceBetweenBraces);
   verifyFormat("f( {}, { {}, {} }, MyMap[ { k, v } ] );", SpaceBetweenBraces);
   verifyFormat("vector< int > x{ // comment 1\n"
-   " 1, 2, 3, 4 };",
+   "1, 

[clang] [clang-format] Remove special handling of comments after brace/paren (PR #71672)

2023-11-08 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 b44399296a7fa4323ab32739df6dbcfc6068af8f 
4548aa1186531fb93a623144278fe72896d47e89 -- 
clang/lib/Format/ContinuationIndenter.cpp clang/lib/Format/TokenAnnotator.cpp 
clang/unittests/Format/FormatTest.cpp 
clang/unittests/Format/FormatTestComments.cpp
``





View the diff from clang-format here.


``diff
diff --git a/clang/lib/Format/TokenAnnotator.cpp 
b/clang/lib/Format/TokenAnnotator.cpp
index 9691d8797..eb8d31745 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -3513,7 +3513,8 @@ void 
TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) const {
   /*if (Prev->is(BK_BracedInit) && Prev->opensScope()) {
 Current->SpacesRequiredBefore =
 Style.SpacesInParensOptions.Other ? 1 : 0;
-  } else */if (Prev->is(TT_VerilogMultiLineListLParen)) {
+  } else */
+  if (Prev->is(TT_VerilogMultiLineListLParen)) {
 Current->SpacesRequiredBefore = 0;
   } else {
 Current->SpacesRequiredBefore = Style.SpacesBeforeTrailingComments;

``




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


[llvm] [flang] [clang] [libc] [libunwind] [clang-tools-extra] [compiler-rt] [libcxx] [lld] [lldb] Test pr (PR #71086)

2023-11-08 Thread Zahira Ammarguellat via cfe-commits
https://github.com/zahiraam closed 
https://github.com/llvm/llvm-project/pull/71086
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[llvm] [clang] [SystemZ] Add backchain target-feature (PR #71668)

2023-11-08 Thread Ulrich Weigand via cfe-commits
https://github.com/uweigand approved this pull request.

LGTM.   Thanks for taking care of this, Ilya!

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


[clang] 5e09c4e - [clang][NFC] Partially annotate `IdentifierInfo` with `preferred_type`

2023-11-08 Thread Vlad Serebrennikov via cfe-commits
Author: Vlad Serebrennikov
Date: 2023-11-08T15:44:46+03:00
New Revision: 5e09c4e6a865707ed26f9a893dbef8b499591459

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

LOG: [clang][NFC] Partially annotate `IdentifierInfo` with `preferred_type`

This patch leaves `ObjCOrBuiltinID` alone, because of performance concerns with 
potential refactoring that would enable correct types in debug info.

Added: 


Modified: 
clang/include/clang/Basic/IdentifierTable.h

Removed: 




diff  --git a/clang/include/clang/Basic/IdentifierTable.h 
b/clang/include/clang/Basic/IdentifierTable.h
index 2eafe5938406749..0898e7d39dd7dee 100644
--- a/clang/include/clang/Basic/IdentifierTable.h
+++ b/clang/include/clang/Basic/IdentifierTable.h
@@ -110,6 +110,7 @@ class alignas(IdentifierInfoAlignment) IdentifierInfo {
   friend class IdentifierTable;
 
   // Front-end token ID or tok::identifier.
+  LLVM_PREFERRED_TYPE(tok::TokenKind)
   unsigned TokenID : 9;
 
   // ObjC keyword ('protocol' in '@protocol') or builtin (__builtin_inf).
@@ -118,58 +119,75 @@ class alignas(IdentifierInfoAlignment) IdentifierInfo {
   unsigned ObjCOrBuiltinID : ObjCOrBuiltinIDBits;
 
   // True if there is a #define for this.
+  LLVM_PREFERRED_TYPE(bool)
   unsigned HasMacro : 1;
 
   // True if there was a #define for this.
+  LLVM_PREFERRED_TYPE(bool)
   unsigned HadMacro : 1;
 
   // True if the identifier is a language extension.
+  LLVM_PREFERRED_TYPE(bool)
   unsigned IsExtension : 1;
 
   // True if the identifier is a keyword in a newer or proposed Standard.
+  LLVM_PREFERRED_TYPE(bool)
   unsigned IsFutureCompatKeyword : 1;
 
   // True if the identifier is poisoned.
+  LLVM_PREFERRED_TYPE(bool)
   unsigned IsPoisoned : 1;
 
   // True if the identifier is a C++ operator keyword.
+  LLVM_PREFERRED_TYPE(bool)
   unsigned IsCPPOperatorKeyword : 1;
 
   // Internal bit set by the member function RecomputeNeedsHandleIdentifier.
   // See comment about RecomputeNeedsHandleIdentifier for more info.
+  LLVM_PREFERRED_TYPE(bool)
   unsigned NeedsHandleIdentifier : 1;
 
   // True if the identifier was loaded (at least partially) from an AST file.
+  LLVM_PREFERRED_TYPE(bool)
   unsigned IsFromAST : 1;
 
   // True if the identifier has changed from the definition
   // loaded from an AST file.
+  LLVM_PREFERRED_TYPE(bool)
   unsigned ChangedAfterLoad : 1;
 
   // True if the identifier's frontend information has changed from the
   // definition loaded from an AST file.
+  LLVM_PREFERRED_TYPE(bool)
   unsigned FEChangedAfterLoad : 1;
 
   // True if revertTokenIDToIdentifier was called.
+  LLVM_PREFERRED_TYPE(bool)
   unsigned RevertedTokenID : 1;
 
   // True if there may be additional information about
   // this identifier stored externally.
+  LLVM_PREFERRED_TYPE(bool)
   unsigned OutOfDate : 1;
 
   // True if this is the 'import' contextual keyword.
+  LLVM_PREFERRED_TYPE(bool)
   unsigned IsModulesImport : 1;
 
   // True if this is a mangled OpenMP variant name.
+  LLVM_PREFERRED_TYPE(bool)
   unsigned IsMangledOpenMPVariantName : 1;
 
   // True if this is a deprecated macro.
+  LLVM_PREFERRED_TYPE(bool)
   unsigned IsDeprecatedMacro : 1;
 
   // True if this macro is unsafe in headers.
+  LLVM_PREFERRED_TYPE(bool)
   unsigned IsRestrictExpansion : 1;
 
   // True if this macro is final.
+  LLVM_PREFERRED_TYPE(bool)
   unsigned IsFinal : 1;
 
   // 22 bits left in a 64-bit word.



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


[clang-tools-extra] d5cfdca - [clangd] Allow hover over 128-bit variable without crashing (#71415)

2023-11-08 Thread Bjorn Pettersson via cfe-commits
Author: Björn Pettersson
Date: 2023-11-08T14:13:11+01:00
New Revision: d5cfdcaacbd36d6c25011f03a4eb51137f7a804a

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

LOG: [clangd] Allow hover over 128-bit variable without crashing (#71415)

When hovering over variables larger than 64 bits, with more than 64
active bits, there were assertion failures since Hover is trying to
print the value as a 64-bit hex value.

There is already protection avoiding to call printHex if there is more
than 64 significant bits. And we already truncate and print negative
values using only 32 bits, when possible. So we can simply truncate
values with more than 64 bits to avoid the assert when using
getZExtValue. The result will be that for example a negative 128 bit
variable is printed using 64 bits, when possible.

There is still no support for printing more than 64 bits. That would
involve more changes since for example llvm::FormatterNumber is limited
to 64 bits.

This is a second attempt at landing this patch. Now with protection
to ensure we use a triple that supports __int128_t.

Added: 


Modified: 
clang-tools-extra/clangd/Hover.cpp
clang-tools-extra/clangd/unittests/HoverTests.cpp

Removed: 




diff  --git a/clang-tools-extra/clangd/Hover.cpp 
b/clang-tools-extra/clangd/Hover.cpp
index 7f7b5513dff6fee..a868d3bb4e3fa1d 100644
--- a/clang-tools-extra/clangd/Hover.cpp
+++ b/clang-tools-extra/clangd/Hover.cpp
@@ -408,7 +408,9 @@ void fillFunctionTypeAndParams(HoverInfo &HI, const Decl *D,
 // -2=> 0xfffe
 // -2^32 => 0x
 static llvm::FormattedNumber printHex(const llvm::APSInt &V) {
-  uint64_t Bits = V.getZExtValue();
+  assert(V.getSignificantBits() <= 64 && "Can't print more than 64 bits.");
+  uint64_t Bits =
+  V.getBitWidth() > 64 ? V.trunc(64).getZExtValue() : V.getZExtValue();
   if (V.isNegative() && V.getSignificantBits() <= 32)
 return llvm::format_hex(uint32_t(Bits), 0);
   return llvm::format_hex(Bits, 0);

diff  --git a/clang-tools-extra/clangd/unittests/HoverTests.cpp 
b/clang-tools-extra/clangd/unittests/HoverTests.cpp
index 063a60db044060e..35db757b9c15b5d 100644
--- a/clang-tools-extra/clangd/unittests/HoverTests.cpp
+++ b/clang-tools-extra/clangd/unittests/HoverTests.cpp
@@ -3349,6 +3349,20 @@ TEST(Hover, NoCrashAPInt64) {
   getHover(AST, T.point(), format::getLLVMStyle(), nullptr);
 }
 
+TEST(Hover, NoCrashInt128) {
+  Annotations T(R"cpp(
+constexpr __int128_t value = -4;
+void foo() { va^lue; }
+  )cpp");
+  auto TU = TestTU::withCode(T.code());
+  // Need a triple that support __int128_t.
+  TU.ExtraArgs.push_back("--target=x86_64-pc-linux-gnu");
+  auto AST = TU.build();
+  auto H = getHover(AST, T.point(), format::getLLVMStyle(), nullptr);
+  ASSERT_TRUE(H);
+  EXPECT_EQ(H->Value, "-4 (0xfffc)");
+}
+
 TEST(Hover, DocsFromMostSpecial) {
   Annotations T(R"cpp(
   // doc1



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


  1   2   3   4   5   >