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

2024-02-14 Thread Jun Wang via cfe-commits

https://github.com/jwanggit86 updated 
https://github.com/llvm/llvm-project/pull/79236

>From 9c40b1151b0673430ff53eb121784724a5b090e5 Mon Sep 17 00:00:00 2001
From: Jun Wang 
Date: Tue, 23 Jan 2024 19:19:00 -0600
Subject: [PATCH 1/4] [AMDGPU] Emit a waitcnt instruction after each memory
 instruction

This patch introduces a new command-line option for clang, namely,
amdgpu-precise-mem-op. When this option is specified, a waitcnt instruction
is generated after each memory load/store instruction. The counter values are
always 0, but which counters are involved depends on the memory instruction.
---
 clang/include/clang/Driver/Options.td |   4 +
 clang/test/Driver/amdgpu-features.c   |   6 +
 llvm/lib/Target/AMDGPU/AMDGPU.td  |   4 +
 llvm/lib/Target/AMDGPU/GCNSubtarget.h |   3 +
 llvm/lib/Target/AMDGPU/SIMemoryLegalizer.cpp  |  79 +++
 .../CodeGen/AMDGPU/insert_waitcnt_for_all.ll  | 199 ++
 6 files changed, 295 insertions(+)
 create mode 100644 llvm/test/CodeGen/AMDGPU/insert_waitcnt_for_all.ll

diff --git a/clang/include/clang/Driver/Options.td 
b/clang/include/clang/Driver/Options.td
index 7f4fa33748faca..d570786534b361 100644
--- a/clang/include/clang/Driver/Options.td
+++ b/clang/include/clang/Driver/Options.td
@@ -4796,6 +4796,10 @@ defm tgsplit : SimpleMFlag<"tgsplit", "Enable", 
"Disable",
 defm wavefrontsize64 : SimpleMFlag<"wavefrontsize64",
   "Specify wavefront size 64", "Specify wavefront size 32",
   " mode (AMDGPU only)">;
+defm amdgpu_precise_memory_op
+: SimpleMFlag<"amdgpu-precise-memory-op", "Enable", "Disable",
+  " precise memory mode (AMDGPU only)",
+  m_amdgpu_Features_Group>;
 
 defm unsafe_fp_atomics : BoolOption<"m", "unsafe-fp-atomics",
   TargetOpts<"AllowAMDGPUUnsafeFPAtomics">, DefaultFalse,
diff --git a/clang/test/Driver/amdgpu-features.c 
b/clang/test/Driver/amdgpu-features.c
index a516bc6b7ff200..57d31ccedd8783 100644
--- a/clang/test/Driver/amdgpu-features.c
+++ b/clang/test/Driver/amdgpu-features.c
@@ -32,3 +32,9 @@
 
 // RUN: %clang -### -target amdgcn -mcpu=gfx1010 -mno-cumode %s 2>&1 | 
FileCheck --check-prefix=NO-CUMODE %s
 // NO-CUMODE: "-target-feature" "-cumode"
+
+// RUN: %clang -### -target amdgcn -mcpu=gfx1010 -mamdgpu-precise-memory-op %s 
2>&1 | FileCheck --check-prefix=PREC-MEM %s
+// PREC-MEM: "-target-feature" "+amdgpu-precise-memory-op"
+
+// RUN: %clang -### -target amdgcn -mcpu=gfx1010 -mno-amdgpu-precise-memory-op 
%s 2>&1 | FileCheck --check-prefix=NO-PREC-MEM %s
+// NO-PREC-MEM: "-target-feature" "-amdgpu-precise-memory-op"
diff --git a/llvm/lib/Target/AMDGPU/AMDGPU.td b/llvm/lib/Target/AMDGPU/AMDGPU.td
index cb29d5d9475981..c39cc947702359 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPU.td
+++ b/llvm/lib/Target/AMDGPU/AMDGPU.td
@@ -167,6 +167,10 @@ def FeatureCuMode : SubtargetFeature<"cumode",
   "Enable CU wavefront execution mode"
 >;
 
+def FeaturePreciseMemory
+: SubtargetFeature<"amdgpu-precise-memory-op", "EnablePreciseMemory",
+   "true", "Enable precise memory mode">;
+
 def FeatureSGPRInitBug : SubtargetFeature<"sgpr-init-bug",
   "SGPRInitBug",
   "true",
diff --git a/llvm/lib/Target/AMDGPU/GCNSubtarget.h 
b/llvm/lib/Target/AMDGPU/GCNSubtarget.h
index 8019b98b1c68d6..b69df21f785985 100644
--- a/llvm/lib/Target/AMDGPU/GCNSubtarget.h
+++ b/llvm/lib/Target/AMDGPU/GCNSubtarget.h
@@ -87,6 +87,7 @@ class GCNSubtarget final : public AMDGPUGenSubtargetInfo,
   bool EnableTgSplit = false;
   bool EnableCuMode = false;
   bool TrapHandler = false;
+  bool EnablePreciseMemory = false;
 
   // Used as options.
   bool EnableLoadStoreOpt = false;
@@ -592,6 +593,8 @@ class GCNSubtarget final : public AMDGPUGenSubtargetInfo,
 return EnableCuMode;
   }
 
+  bool isPreciseMemoryEnabled() const { return EnablePreciseMemory; }
+
   bool hasFlatAddressSpace() const {
 return FlatAddressSpace;
   }
diff --git a/llvm/lib/Target/AMDGPU/SIMemoryLegalizer.cpp 
b/llvm/lib/Target/AMDGPU/SIMemoryLegalizer.cpp
index 84b9330ef9633e..93cdceb37bd501 100644
--- a/llvm/lib/Target/AMDGPU/SIMemoryLegalizer.cpp
+++ b/llvm/lib/Target/AMDGPU/SIMemoryLegalizer.cpp
@@ -17,6 +17,7 @@
 #include "AMDGPUMachineModuleInfo.h"
 #include "GCNSubtarget.h"
 #include "MCTargetDesc/AMDGPUMCTargetDesc.h"
+#include "Utils/AMDGPUBaseInfo.h"
 #include "llvm/ADT/BitmaskEnum.h"
 #include "llvm/CodeGen/MachineBasicBlock.h"
 #include "llvm/CodeGen/MachineFunctionPass.h"
@@ -24,6 +25,8 @@
 #include "llvm/Support/AtomicOrdering.h"
 #include "llvm/TargetParser/TargetParser.h"
 
+#include 
+
 using namespace llvm;
 using namespace llvm::AMDGPU;
 
@@ -641,6 +644,9 @@ class SIMemoryLegalizer final : public MachineFunctionPass {
   bool expandAtomicCmpxchgOrRmw(const SIMemOpInfo ,
 MachineBasicBlock::iterator );
 
+  bool GFX9InsertWaitcntForPreciseMem(MachineFunction );
+  bool GFX10And11InsertWaitcntForPreciseMem(MachineFunction );
+
 public:
   static char 

[clang] [HLSL] Expose `half` types and intrinsics always (PR #81782)

2024-02-14 Thread Joshua Batista via cfe-commits

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


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


[clang] [compiler-rt] [llvm] [IRPGO][ValueProfile] Instrument virtual table address that could be used to do virtual table address comparision for indirect-call-promotion. (PR #66825)

2024-02-14 Thread Mingming Liu via cfe-commits

minglotus-6 wrote:

I have been putting this on hold to coordinate with some tooling change (which 
likely become behind schedule).

At this point, both code reviews and testing the (pending) changes in would be 
much more time efficient if this initial change could get in sooner. 

Now with stacked reviews possible in llvm main branch, I'm planning to split 
the profile format change into https://github.com/llvm/llvm-project/pull/81691 
first to mitigate the risk of repeated roll backs that comes with a PR with 2k 
lines. After the profile format change is in llvm main branch, will run 'git 
merge main' to update this PR.

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


[clang] [compiler-rt] [llvm] [IRPGO][ValueProfile] Instrument virtual table address that could be used to do virtual table address comparision for indirect-call-promotion. (PR #66825)

2024-02-14 Thread Mingming Liu via cfe-commits

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


[clang] [clang] Allow builtin addc/subc to be constant evaluated (PR #81656)

2024-02-14 Thread Bryce Wilson via cfe-commits

Bryce-MW wrote:

I swear I had meant to add tests! I did see a place that looks good to add them 
before so I've done that. Which allowed me to find out that I had not done my 
implementation correctly so I fixed that up.

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


[clang] [clang] Allow builtin addc/subc to be constant evaluated (PR #81656)

2024-02-14 Thread Bryce Wilson via cfe-commits

https://github.com/Bryce-MW updated 
https://github.com/llvm/llvm-project/pull/81656

>From 9bea6282aae73372a80aa3d0532ae0532b4ca948 Mon Sep 17 00:00:00 2001
From: Bryce Wilson 
Date: Fri, 9 Feb 2024 16:56:57 -0600
Subject: [PATCH 1/2] [clang] Allow builtin addc/subc to be constant evaluated

---
 clang/docs/LanguageExtensions.rst | 10 ++
 clang/include/clang/Basic/Builtins.td |  4 +--
 clang/lib/AST/ExprConstant.cpp| 50 +++
 3 files changed, 62 insertions(+), 2 deletions(-)

diff --git a/clang/docs/LanguageExtensions.rst 
b/clang/docs/LanguageExtensions.rst
index e91156837290f7..e8557a22662c07 100644
--- a/clang/docs/LanguageExtensions.rst
+++ b/clang/docs/LanguageExtensions.rst
@@ -5241,6 +5241,11 @@ Intrinsics Support within Constant Expressions
 
 The following builtin intrinsics can be used in constant expressions:
 
+* ``__builtin_addcb``
+* ``__builtin_addcs``
+* ``__builtin_addc``
+* ``__builtin_addcl``
+* ``__builtin_addcll``
 * ``__builtin_bitreverse8``
 * ``__builtin_bitreverse16``
 * ``__builtin_bitreverse32``
@@ -5287,6 +5292,11 @@ The following builtin intrinsics can be used in constant 
expressions:
 * ``__builtin_rotateright16``
 * ``__builtin_rotateright32``
 * ``__builtin_rotateright64``
+* ``__builtin_subcb``
+* ``__builtin_subcs``
+* ``__builtin_subc``
+* ``__builtin_subcl``
+* ``__builtin_subcll``
 
 The following x86-specific intrinsics can be used in constant expressions:
 
diff --git a/clang/include/clang/Basic/Builtins.td 
b/clang/include/clang/Basic/Builtins.td
index 31a2bdeb2d3e5e..59dc0e20393b5f 100644
--- a/clang/include/clang/Basic/Builtins.td
+++ b/clang/include/clang/Basic/Builtins.td
@@ -4061,14 +4061,14 @@ class MPATemplate : Template<
 
 def Addc : Builtin, MPATemplate {
   let Spellings = ["__builtin_addc"];
-  let Attributes = [NoThrow];
+  let Attributes = [NoThrow, Constexpr];
   // FIXME: Why are these argumentes marked const?
   let Prototype = "T(T const, T const, T const, T*)";
 }
 
 def Subc : Builtin, MPATemplate {
   let Spellings = ["__builtin_subc"];
-  let Attributes = [NoThrow];
+  let Attributes = [NoThrow, Constexpr];
   // FIXME: Why are these argumentes marked const?
   let Prototype = "T(T const, T const, T const, T*)";
 }
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 089bc2094567f7..42e134e70c6e8e 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -12691,6 +12691,56 @@ bool IntExprEvaluator::VisitBuiltinCallExpr(const 
CallExpr *E,
 return BuiltinOp == Builtin::BI__atomic_always_lock_free ?
 Success(0, E) : Error(E);
   }
+  case Builtin::BI__builtin_addcb:
+  case Builtin::BI__builtin_addcs:
+  case Builtin::BI__builtin_addc:
+  case Builtin::BI__builtin_addcl:
+  case Builtin::BI__builtin_addcll:
+  case Builtin::BI__builtin_subcb:
+  case Builtin::BI__builtin_subcs:
+  case Builtin::BI__builtin_subc:
+  case Builtin::BI__builtin_subcl:
+  case Builtin::BI__builtin_subcll: {
+LValue CarryOutLValue;
+APSInt LHS, RHS, CarryIn, Result;
+QualType ResultType = E->getArg(0)->getType();
+if (!EvaluateInteger(E->getArg(0), LHS, Info) ||
+!EvaluateInteger(E->getArg(1), RHS, Info) ||
+!EvaluateInteger(E->getArg(2), CarryIn, Info) ||
+!EvaluatePointer(E->getArg(3), CarryOutLValue, Info))
+  return false;
+
+bool FirstOverflowed = false;
+bool SecondOverflowed = false;
+switch (BuiltinOp) {
+default:
+  llvm_unreachable("Invalid value for BuiltinOp");
+case Builtin::BI__builtin_addcb:
+case Builtin::BI__builtin_addcs:
+case Builtin::BI__builtin_addc:
+case Builtin::BI__builtin_addcl:
+case Builtin::BI__builtin_addcll:
+  Result =
+  LHS.uadd_ov(RHS, FirstOverflowed).uadd_ov(CarryIn, SecondOverflowed);
+  break;
+case Builtin::BI__builtin_subcb:
+case Builtin::BI__builtin_subcs:
+case Builtin::BI__builtin_subc:
+case Builtin::BI__builtin_subcl:
+case Builtin::BI__builtin_subcll:
+  Result =
+  LHS.usub_ov(RHS, FirstOverflowed).usub_ov(CarryIn, SecondOverflowed);
+  break;
+}
+
+// It is possible for both overflows to happen but CGBuiltin uses an OR so
+// this is consistent
+APSInt API{(uint32_t)(FirstOverflowed | SecondOverflowed)};
+APValue APV{API};
+if (!handleAssignment(Info, E, CarryOutLValue, ResultType, APV))
+  return false;
+return Success(Result, E);
+  }
   case Builtin::BI__builtin_add_overflow:
   case Builtin::BI__builtin_sub_overflow:
   case Builtin::BI__builtin_mul_overflow:

>From 52ad49ce3eef5a98b779c13277af6f430a9b2a4a Mon Sep 17 00:00:00 2001
From: Bryce Wilson 
Date: Wed, 14 Feb 2024 16:52:09 -0600
Subject: [PATCH 2/2] Add tests and fix discovered bugs

---
 clang/lib/AST/ExprConstant.cpp   |  9 +++--
 clang/test/SemaCXX/builtins-overflow.cpp | 49 
 2 files changed, 55 insertions(+), 3 deletions(-)

diff --git 

[clang] [-Wunsafe-buffer-usage] Add fixits for array to pointer assignment (PR #81343)

2024-02-14 Thread via cfe-commits

https://github.com/jkorous-apple updated 
https://github.com/llvm/llvm-project/pull/81343

>From dfc9d95c185f5228f5c9680a19aa396d20e33d19 Mon Sep 17 00:00:00 2001
From: Jan Korous 
Date: Thu, 25 Jan 2024 13:52:12 -0800
Subject: [PATCH 01/11] [-Wunsafe-buffer-usage] Emit fixits for arguments of
 function pointers calls

Currently we ignore calls on function pointers (unlike direct calls of
functions and class methods). This patch adds support for function pointers as
well.

The change is to simply replace use of forEachArgumentWithParam matcher in UPC
gadget with forEachArgumentWithParamType.

from the documentation of forEachArgumentWithParamType:
/// Matches all arguments and their respective types for a \c CallExpr or
/// \c CXXConstructExpr. It is very similar to \c forEachArgumentWithParam but
/// it works on calls through function pointers as well.

Currently the matcher also uses hasPointerType() which checks that the
canonical type of an argument is pointer and won't match on arrays decayed to
pointer. Replacing hasPointerType() with isAnyPointerType() which allows
implicit casts allows for the arrays to be matched as well and this way we get
fixits for array arguments to function pointer calls too.
---
 clang/lib/Analysis/UnsafeBufferUsage.cpp |  4 ++--
 ...fer-usage-fixits-pointer-arg-to-func-ptr-call.cpp | 12 
 2 files changed, 14 insertions(+), 2 deletions(-)
 create mode 100644 
clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-pointer-arg-to-func-ptr-call.cpp

diff --git a/clang/lib/Analysis/UnsafeBufferUsage.cpp 
b/clang/lib/Analysis/UnsafeBufferUsage.cpp
index d00c598c4b9de3..c5a87f14bc8880 100644
--- a/clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ b/clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -282,8 +282,8 @@ isInUnspecifiedPointerContext(internal::Matcher 
InnerMatcher) {
   //(i.e., computing the distance between two pointers); or ...
 
   auto CallArgMatcher =
-  callExpr(forEachArgumentWithParam(InnerMatcher,
-  hasPointerType() /* array also decays to pointer type*/),
+  callExpr(forEachArgumentWithParamType(InnerMatcher,
+  isAnyPointer() /* array also decays to pointer type*/),
   unless(callee(functionDecl(hasAttr(attr::UnsafeBufferUsage);
 
   auto CastOperandMatcher =
diff --git 
a/clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-pointer-arg-to-func-ptr-call.cpp
 
b/clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-pointer-arg-to-func-ptr-call.cpp
new file mode 100644
index 00..ae761e46a98191
--- /dev/null
+++ 
b/clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-pointer-arg-to-func-ptr-call.cpp
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -std=c++20 -Wunsafe-buffer-usage \
+// RUN:-fsafe-buffer-usage-suggestions \
+// RUN:-fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
+
+void unsafe_array_func_ptr_call(void (*fn_ptr)(int *param)) {
+  int p[32];
+  // CHECK-DAG: 
fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:12}:"std::array p"
+
+  int tmp = p[5];
+  fn_ptr(p);
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:11}:".data()"
+}

>From 44dab965c459f2cd6084ea332f4a6756f57254e0 Mon Sep 17 00:00:00 2001
From: Jan Korous 
Date: Thu, 1 Feb 2024 14:44:01 -0800
Subject: [PATCH 02/11] [-Wunsafe-buffer-usage][NFC] Add tests for function
 pointer call fixits

---
 ...ge-fixits-pointer-arg-to-func-ptr-call.cpp | 38 ++-
 1 file changed, 37 insertions(+), 1 deletion(-)

diff --git 
a/clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-pointer-arg-to-func-ptr-call.cpp
 
b/clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-pointer-arg-to-func-ptr-call.cpp
index ae761e46a98191..0459d6549fd86f 100644
--- 
a/clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-pointer-arg-to-func-ptr-call.cpp
+++ 
b/clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-pointer-arg-to-func-ptr-call.cpp
@@ -6,7 +6,43 @@ void unsafe_array_func_ptr_call(void (*fn_ptr)(int *param)) {
   int p[32];
   // CHECK-DAG: 
fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:12}:"std::array p"
 
-  int tmp = p[5];
+  p[5] = 10;
   fn_ptr(p);
   // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:11}:".data()"
 }
+
+void unsafe_ptr_func_ptr_call(void (*fn_ptr)(int *param)) {
+  int *p;
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:9}:"std::span 
p"
+
+  p[5] = 10;
+  fn_ptr(p);
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:11}:".data()"
+}
+
+void addr_of_unsafe_ptr_func_ptr_call(void (*fn_ptr)(int *param)) {
+  int *p;
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:9}:"std::span 
p"
+
+  p[5] = 10;
+  fn_ptr([0]);
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-1]]:10-[[@LINE-1]]:15}:"p.data()"
+}
+
+void addr_of_unsafe_ptr_w_offset_func_ptr_call(void (*fn_ptr)(int *param)) {
+  int *p;
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:9}:"std::span 
p"
+
+  p[5] = 10;
+  fn_ptr([3]);
+  // CHECK-DAG: 

[clang] [-Wunsafe-buffer-usage] Add fixits for array to pointer assignment (PR #81343)

2024-02-14 Thread via cfe-commits

https://github.com/jkorous-apple updated 
https://github.com/llvm/llvm-project/pull/81343

>From dfc9d95c185f5228f5c9680a19aa396d20e33d19 Mon Sep 17 00:00:00 2001
From: Jan Korous 
Date: Thu, 25 Jan 2024 13:52:12 -0800
Subject: [PATCH 01/10] [-Wunsafe-buffer-usage] Emit fixits for arguments of
 function pointers calls

Currently we ignore calls on function pointers (unlike direct calls of
functions and class methods). This patch adds support for function pointers as
well.

The change is to simply replace use of forEachArgumentWithParam matcher in UPC
gadget with forEachArgumentWithParamType.

from the documentation of forEachArgumentWithParamType:
/// Matches all arguments and their respective types for a \c CallExpr or
/// \c CXXConstructExpr. It is very similar to \c forEachArgumentWithParam but
/// it works on calls through function pointers as well.

Currently the matcher also uses hasPointerType() which checks that the
canonical type of an argument is pointer and won't match on arrays decayed to
pointer. Replacing hasPointerType() with isAnyPointerType() which allows
implicit casts allows for the arrays to be matched as well and this way we get
fixits for array arguments to function pointer calls too.
---
 clang/lib/Analysis/UnsafeBufferUsage.cpp |  4 ++--
 ...fer-usage-fixits-pointer-arg-to-func-ptr-call.cpp | 12 
 2 files changed, 14 insertions(+), 2 deletions(-)
 create mode 100644 
clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-pointer-arg-to-func-ptr-call.cpp

diff --git a/clang/lib/Analysis/UnsafeBufferUsage.cpp 
b/clang/lib/Analysis/UnsafeBufferUsage.cpp
index d00c598c4b9de3..c5a87f14bc8880 100644
--- a/clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ b/clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -282,8 +282,8 @@ isInUnspecifiedPointerContext(internal::Matcher 
InnerMatcher) {
   //(i.e., computing the distance between two pointers); or ...
 
   auto CallArgMatcher =
-  callExpr(forEachArgumentWithParam(InnerMatcher,
-  hasPointerType() /* array also decays to pointer type*/),
+  callExpr(forEachArgumentWithParamType(InnerMatcher,
+  isAnyPointer() /* array also decays to pointer type*/),
   unless(callee(functionDecl(hasAttr(attr::UnsafeBufferUsage);
 
   auto CastOperandMatcher =
diff --git 
a/clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-pointer-arg-to-func-ptr-call.cpp
 
b/clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-pointer-arg-to-func-ptr-call.cpp
new file mode 100644
index 00..ae761e46a98191
--- /dev/null
+++ 
b/clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-pointer-arg-to-func-ptr-call.cpp
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -std=c++20 -Wunsafe-buffer-usage \
+// RUN:-fsafe-buffer-usage-suggestions \
+// RUN:-fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
+
+void unsafe_array_func_ptr_call(void (*fn_ptr)(int *param)) {
+  int p[32];
+  // CHECK-DAG: 
fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:12}:"std::array p"
+
+  int tmp = p[5];
+  fn_ptr(p);
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:11}:".data()"
+}

>From 44dab965c459f2cd6084ea332f4a6756f57254e0 Mon Sep 17 00:00:00 2001
From: Jan Korous 
Date: Thu, 1 Feb 2024 14:44:01 -0800
Subject: [PATCH 02/10] [-Wunsafe-buffer-usage][NFC] Add tests for function
 pointer call fixits

---
 ...ge-fixits-pointer-arg-to-func-ptr-call.cpp | 38 ++-
 1 file changed, 37 insertions(+), 1 deletion(-)

diff --git 
a/clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-pointer-arg-to-func-ptr-call.cpp
 
b/clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-pointer-arg-to-func-ptr-call.cpp
index ae761e46a98191..0459d6549fd86f 100644
--- 
a/clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-pointer-arg-to-func-ptr-call.cpp
+++ 
b/clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-pointer-arg-to-func-ptr-call.cpp
@@ -6,7 +6,43 @@ void unsafe_array_func_ptr_call(void (*fn_ptr)(int *param)) {
   int p[32];
   // CHECK-DAG: 
fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:12}:"std::array p"
 
-  int tmp = p[5];
+  p[5] = 10;
   fn_ptr(p);
   // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:11}:".data()"
 }
+
+void unsafe_ptr_func_ptr_call(void (*fn_ptr)(int *param)) {
+  int *p;
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:9}:"std::span 
p"
+
+  p[5] = 10;
+  fn_ptr(p);
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:11}:".data()"
+}
+
+void addr_of_unsafe_ptr_func_ptr_call(void (*fn_ptr)(int *param)) {
+  int *p;
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:9}:"std::span 
p"
+
+  p[5] = 10;
+  fn_ptr([0]);
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-1]]:10-[[@LINE-1]]:15}:"p.data()"
+}
+
+void addr_of_unsafe_ptr_w_offset_func_ptr_call(void (*fn_ptr)(int *param)) {
+  int *p;
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:9}:"std::span 
p"
+
+  p[5] = 10;
+  fn_ptr([3]);
+  // CHECK-DAG: 

[clang] [-Wunsafe-buffer-usage] Add fixits for array to pointer assignment (PR #81343)

2024-02-14 Thread via cfe-commits

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


[clang] [compiler-rt] [llvm] [IRPGO][ValueProfile] Instrument virtual table address that could be used to do virtual table address comparision for indirect-call-promotion. (PR #66825)

2024-02-14 Thread Mingming Liu via cfe-commits

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


[clang] Detect a return value of Ref & RefPtr (PR #81580)

2024-02-14 Thread Artem Dergachev via cfe-commits

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


[clang] 7249692 - [analyzer] Detect a return value of Ref & RefPtr (#81580)

2024-02-14 Thread via cfe-commits

Author: Ryosuke Niwa
Date: 2024-02-14T14:47:40-08:00
New Revision: 7249692bd24afc81fbbaa24240e3c9bba046f854

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

LOG: [analyzer] Detect a return value of Ref & RefPtr (#81580)

This PR makes the checker not emit warning when a function is called
with a return value of another function when the return value is of type
Ref or RefPtr.

Added: 
clang/test/Analysis/Checkers/WebKit/call-args-protected-return-value.cpp

Modified: 
clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h

Removed: 




diff  --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
index 4526fac64735bf..b76c0551c77bb0 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/ASTUtils.cpp
@@ -19,6 +19,10 @@ namespace clang {
 std::pair
 tryToFindPtrOrigin(const Expr *E, bool StopAtFirstRefCountedObj) {
   while (E) {
+if (auto *tempExpr = dyn_cast(E)) {
+  E = tempExpr->getSubExpr();
+  continue;
+}
 if (auto *cast = dyn_cast(E)) {
   if (StopAtFirstRefCountedObj) {
 if (auto *ConversionFunc =
@@ -62,6 +66,8 @@ tryToFindPtrOrigin(const Expr *E, bool 
StopAtFirstRefCountedObj) {
   E = call->getArg(0);
   continue;
 }
+if (isReturnValueRefCounted(callee))
+  return {E, true};
 
 if (isPtrConversion(callee)) {
   E = call->getArg(0);

diff  --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
index 08ba553d16ed14..907244013d0871 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
@@ -119,6 +119,26 @@ bool isCtorOfRefCounted(const clang::FunctionDecl *F) {
  || FunctionName == "Identifier";
 }
 
+bool isReturnValueRefCounted(const clang::FunctionDecl *F) {
+  assert(F);
+  QualType type = F->getReturnType();
+  while (!type.isNull()) {
+if (auto *elaboratedT = type->getAs()) {
+  type = elaboratedT->desugar();
+  continue;
+}
+if (auto *specialT = type->getAs()) {
+  if (auto *decl = specialT->getTemplateName().getAsTemplateDecl()) {
+auto name = decl->getNameAsString();
+return name == "Ref" || name == "RefPtr";
+  }
+  return false;
+}
+return false;
+  }
+  return false;
+}
+
 std::optional isUncounted(const CXXRecordDecl* Class)
 {
   // Keep isRefCounted first as it's cheaper.

diff  --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h
index 45b21cc0918443..c2c5b74442ba43 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.h
@@ -50,6 +50,9 @@ std::optional isUncountedPtr(const clang::Type* T);
 /// false if not.
 bool isCtorOfRefCounted(const clang::FunctionDecl *F);
 
+/// \returns true if \p F returns a ref-counted object, false if not.
+bool isReturnValueRefCounted(const clang::FunctionDecl *F);
+
 /// \returns true if \p M is getter of a ref-counted class, false if not.
 std::optional isGetterOfRefCounted(const clang::CXXMethodDecl* Method);
 

diff  --git 
a/clang/test/Analysis/Checkers/WebKit/call-args-protected-return-value.cpp 
b/clang/test/Analysis/Checkers/WebKit/call-args-protected-return-value.cpp
new file mode 100644
index 00..1c4b3df211b1e3
--- /dev/null
+++ b/clang/test/Analysis/Checkers/WebKit/call-args-protected-return-value.cpp
@@ -0,0 +1,23 @@
+// RUN: %clang_analyze_cc1 
-analyzer-checker=alpha.webkit.UncountedCallArgsChecker -verify %s
+// expected-no-diagnostics
+
+#include "mock-types.h"
+
+class RefCounted {
+public:
+  void ref();
+  void deref();
+};
+
+class Object {
+public:
+  void someFunction(RefCounted&);
+};
+
+RefPtr object();
+RefPtr protectedTargetObject();
+
+void testFunction() {
+  if (RefPtr obj = object())
+obj->someFunction(*protectedTargetObject());
+}



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


[clang] Detect a return value of Ref & RefPtr (PR #81580)

2024-02-14 Thread Artem Dergachev via cfe-commits

haoNoQ wrote:

Ok this needs a rebase after the other two PRs landed.

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


[clang] [alpha.webkit.UncountedCallArgsChecker] Add a few more safe functions to call. (PR #81532)

2024-02-14 Thread Artem Dergachev via cfe-commits

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


[clang] cbdc760 - [analyzer] Add a few more safe functions to call. (#81532)

2024-02-14 Thread via cfe-commits

Author: Ryosuke Niwa
Date: 2024-02-14T14:45:29-08:00
New Revision: cbdc7605edca26ff75a28f080089a835ed9dba92

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

LOG: [analyzer] Add a few more safe functions to call. (#81532)

Added checkedDowncast, uncheckedDowncast, & toString as safe functions
to call in alpha.webkit.UncountedCallArgsChecker.

Added: 
clang/test/Analysis/Checkers/WebKit/call-args-safe-functions.cpp

Modified: 
clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp

Removed: 
clang/test/Analysis/Checkers/WebKit/call-args-dynamic-downcast.cpp



diff  --git a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
index 96784d42d09fa4..08ba553d16ed14 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/PtrTypesSemantics.cpp
@@ -194,8 +194,9 @@ bool isPtrConversion(const FunctionDecl *F) {
   // FIXME: check # of params == 1
   const auto FunctionName = safeGetName(F);
   if (FunctionName == "getPtr" || FunctionName == "WeakPtr" ||
-  FunctionName == "dynamicDowncast"
-  || FunctionName == "downcast" || FunctionName == "bitwise_cast")
+  FunctionName == "dynamicDowncast" || FunctionName == "downcast" ||
+  FunctionName == "checkedDowncast" ||
+  FunctionName == "uncheckedDowncast" || FunctionName == "bitwise_cast")
 return true;
 
   return false;

diff  --git 
a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp
index c84e1f9c244a88..e2e1add31c9b17 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp
@@ -174,13 +174,14 @@ class UncountedCallArgsChecker
 
 auto name = safeGetName(Callee);
 if (name == "adoptRef" || name == "getPtr" || name == "WeakPtr" ||
-name == "dynamicDowncast" || name == "downcast" || name == 
"bitwise_cast" ||
-name == "is" || name == "equal" || name == "hash" ||
-name == "isType"
+name == "dynamicDowncast" || name == "downcast" ||
+name == "checkedDowncast" || name == "uncheckedDowncast" ||
+name == "bitwise_cast" || name == "is" || name == "equal" ||
+name == "hash" || name == "isType" ||
 // FIXME: Most/all of these should be implemented via attributes.
-|| name == "equalIgnoringASCIICase" ||
+name == "equalIgnoringASCIICase" ||
 name == "equalIgnoringASCIICaseCommon" ||
-name == "equalIgnoringNullity")
+name == "equalIgnoringNullity" || name == "toString")
   return true;
 
 return false;

diff  --git 
a/clang/test/Analysis/Checkers/WebKit/call-args-dynamic-downcast.cpp 
b/clang/test/Analysis/Checkers/WebKit/call-args-safe-functions.cpp
similarity index 55%
rename from clang/test/Analysis/Checkers/WebKit/call-args-dynamic-downcast.cpp
rename to clang/test/Analysis/Checkers/WebKit/call-args-safe-functions.cpp
index 28156623d9a0fd..a87446564870cd 100644
--- a/clang/test/Analysis/Checkers/WebKit/call-args-dynamic-downcast.cpp
+++ b/clang/test/Analysis/Checkers/WebKit/call-args-safe-functions.cpp
@@ -23,13 +23,34 @@ class OtherObject {
 Derived* obj();
 };
 
+class String {
+};
+
 template
 inline Target* dynamicDowncast(Source* source)
 {
 return static_cast(source);
 }
 
+template
+inline Target* checkedDowncast(Source* source)
+{
+return static_cast(source);
+}
+
+template
+inline Target* uncheckedDowncast(Source* source)
+{
+return static_cast(source);
+}
+
+template
+String toString(const Types&... values);
+
 void foo(OtherObject* other)
 {
 dynamicDowncast(other->obj());
+checkedDowncast(other->obj());
+uncheckedDowncast(other->obj());
+toString(other->obj());
 }



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


[clang] [compiler-rt] [llvm] [InstrProf] Single byte counters in coverage (PR #75425)

2024-02-14 Thread Ellis Hoag via cfe-commits


@@ -821,15 +822,23 @@ void InstrProfRecord::merge(InstrProfRecord , 
uint64_t Weight,
 
   for (size_t I = 0, E = Other.Counts.size(); I < E; ++I) {
 bool Overflowed;
-uint64_t Value =
-SaturatingMultiplyAdd(Other.Counts[I], Weight, Counts[I], );
-if (Value > getInstrMaxCountValue()) {
-  Value = getInstrMaxCountValue();
-  Overflowed = true;
+uint64_t Value;
+// When a profile has single byte coverage, use || to merge counters.
+if (HasSingleByteCoverage)
+  Value = Other.Counts[I] || Counts[I];

ellishg wrote:

I'm actually surprised this doesn't break any tests. If not, then I might need 
to add some more.

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


[clang] [alpha.webkit.UncountedCallArgsChecker] Check the safety of the object argument in a member function call. (PR #81400)

2024-02-14 Thread Artem Dergachev via cfe-commits

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


[clang] 3a49dfb - [analyzer] Check the safety of the object argument in a member function call. (#81400)

2024-02-14 Thread via cfe-commits

Author: Ryosuke Niwa
Date: 2024-02-14T14:44:51-08:00
New Revision: 3a49dfb28fed8f784484ce2ce6d687550f27ad59

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

LOG: [analyzer] Check the safety of the object argument in a member function 
call. (#81400)

This PR makes alpha.webkit.UncountedCallArgsChecker eplicitly check the
safety of the object argument in a member function call. It also removes
the exemption of local variables from this checker so that each local
variable's safety is checked if it's used in a function call instead of
relying on the local variable checker to find those since local variable
checker currently has exemption for "for" and "if" statements.

Added: 
clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp

Modified: 
clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp

Removed: 




diff  --git 
a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp 
b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp
index f4e6191cf05a3c..c84e1f9c244a88 100644
--- a/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/WebKit/UncountedCallArgsChecker.cpp
@@ -70,6 +70,15 @@ class UncountedCallArgsChecker
   // or std::function call operator).
   unsigned ArgIdx = isa(CE) && 
isa_and_nonnull(F);
 
+  if (auto *MemberCallExpr = dyn_cast(CE)) {
+auto *E = MemberCallExpr->getImplicitObjectArgument();
+QualType ArgType = MemberCallExpr->getObjectType();
+std::optional IsUncounted =
+isUncounted(ArgType->getAsCXXRecordDecl());
+if (IsUncounted && *IsUncounted && !isPtrOriginSafe(E))
+  reportBugOnThis(E);
+  }
+
   for (auto P = F->param_begin();
// FIXME: Also check variadic function parameters.
// FIXME: Also check default function arguments. Probably a 
diff erent
@@ -94,25 +103,7 @@ class UncountedCallArgsChecker
 if (auto *defaultArg = dyn_cast(Arg))
   Arg = defaultArg->getExpr();
 
-std::pair ArgOrigin =
-tryToFindPtrOrigin(Arg, true);
-
-// Temporary ref-counted object created as part of the call argument
-// would outlive the call.
-if (ArgOrigin.second)
-  continue;
-
-if (isa(ArgOrigin.first)) {
-  // foo(nullptr)
-  continue;
-}
-if (isa(ArgOrigin.first)) {
-  // FIXME: Check the value.
-  // foo(NULL)
-  continue;
-}
-
-if (isASafeCallArg(ArgOrigin.first))
+if (isPtrOriginSafe(Arg))
   continue;
 
 reportBug(Arg, *P);
@@ -120,6 +111,28 @@ class UncountedCallArgsChecker
 }
   }
 
+  bool isPtrOriginSafe(const Expr *Arg) const {
+std::pair ArgOrigin =
+tryToFindPtrOrigin(Arg, true);
+
+// Temporary ref-counted object created as part of the call argument
+// would outlive the call.
+if (ArgOrigin.second)
+  return true;
+
+if (isa(ArgOrigin.first)) {
+  // foo(nullptr)
+  return true;
+}
+if (isa(ArgOrigin.first)) {
+  // FIXME: Check the value.
+  // foo(NULL)
+  return true;
+}
+
+return isASafeCallArg(ArgOrigin.first);
+  }
+
   bool shouldSkipCall(const CallExpr *CE) const {
 if (CE->getNumArgs() == 0)
   return false;
@@ -196,6 +209,19 @@ class UncountedCallArgsChecker
 Report->addRange(CallArg->getSourceRange());
 BR->emitReport(std::move(Report));
   }
+
+  void reportBugOnThis(const Expr *CallArg) const {
+assert(CallArg);
+
+const SourceLocation SrcLocToReport = CallArg->getSourceRange().getBegin();
+
+PathDiagnosticLocation BSLoc(SrcLocToReport, BR->getSourceManager());
+auto Report = std::make_unique(
+Bug, "Call argument for 'this' parameter is uncounted and unsafe.",
+BSLoc);
+Report->addRange(CallArg->getSourceRange());
+BR->emitReport(std::move(Report));
+  }
 };
 } // namespace
 

diff  --git a/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp 
b/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp
new file mode 100644
index 00..e5e39e3faac714
--- /dev/null
+++ b/clang/test/Analysis/Checkers/WebKit/uncounted-obj-arg.cpp
@@ -0,0 +1,18 @@
+// RUN: %clang_analyze_cc1 
-analyzer-checker=alpha.webkit.UncountedCallArgsChecker -verify %s
+
+#include "mock-types.h"
+
+class RefCounted {
+public:
+  void ref() const;
+  void deref() const;
+  void someFunction();
+};
+
+RefCounted* refCountedObj();
+
+void test()
+{
+  refCountedObj()->someFunction();
+  // expected-warning@-1{{Call argument for 'this' parameter is uncounted and 
unsafe}}
+}



___
cfe-commits mailing list

[clang] [compiler-rt] [Sanitizer] add signed-integer-wrap sanitizer (PR #80089)

2024-02-14 Thread Kees Cook via cfe-commits

kees wrote:

> > > > > Why not just enforce -fsanitize=signed-integer-overflow with -fwrapv? 
> > > > > I suspect it's just overlook, and not intentional behavior.
> > > > 
> > > > 
> > > > +1
> > > > We should consider this direction
> > > 
> > > 
> > > The UB-vs-non-UB seemed to be a really specific goal in the existing 
> > > code. i.e. that the sanitizer was disabled didn't look like an accident. 
> > > For people using this to find _only_ UB, this would be a behavioral 
> > > change, so to me it seems like a separate name makes the most sense. 
> > > Anyone wanting wrap-around checking can use -wrap, and anyone wanting UB 
> > > checking can use -overflow.
> > 
> > 
> > Isn't this still UB even with -fwrapv? UB is a language feature, not 
> > compiler.
> 
> `-fwrapv` is essentially a language dialect that defines the behavior of 
> integer wraparound. It is no longer UB in compilations using that mode.

Right. `-fwrapv` defines the signed integer overflow resolution strategy. 
Without `-fwrapv` it is undefined (default language feature). With `-fwrapv` it 
is defined as 2s-complement wrap-around (and is well defined, like unsigned 
integer overflow).

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


[clang] [-Wunsafe-buffer-usage] Fixits for unsafe arguments of function pointer calls (PR #80358)

2024-02-14 Thread Artem Dergachev via cfe-commits

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


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


[clang] [-Wunsafe-buffer-usage] Fixits for unsafe arguments of function pointer calls (PR #80358)

2024-02-14 Thread Artem Dergachev via cfe-commits


@@ -282,8 +282,8 @@ isInUnspecifiedPointerContext(internal::Matcher 
InnerMatcher) {
   //(i.e., computing the distance between two pointers); or ...
 
   auto CallArgMatcher =
-  callExpr(forEachArgumentWithParam(InnerMatcher,
-  hasPointerType() /* array also decays to pointer type*/),
+  callExpr(forEachArgumentWithParamType(InnerMatcher,
+  isAnyPointer() /* array also decays to pointer type*/),

haoNoQ wrote:

Hmm looks like parameter types are always canonical. Probably because we need 
them to be the same for overloading purposes even if they're typedef'ed 
differently. The new code appears to be entirely equivalent to 
`hasCanonicalType(pointerType())` or just `pointerType()`.

Side note, `isAnyPointer()` only adds ObjC pointer types to the mix. We don't 
really care about ObjC pointers because you can't do pointer arithmetic on 
them. So might as well use `pointerType()`.

> Handling or not handling typedefs is the responsibility of `fixVariable` 
> function and perhaps individual FixableGadgets' `getFixits()` method.

In many cases you need to actively skip typedefs in order to get the gadget to 
match at all. But it looks like, indeed, it doesn't matter in this case.

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


[clang] [compiler-rt] [llvm] [InstrProf] Single byte counters in coverage (PR #75425)

2024-02-14 Thread Ellis Hoag via cfe-commits


@@ -821,15 +822,23 @@ void InstrProfRecord::merge(InstrProfRecord , 
uint64_t Weight,
 
   for (size_t I = 0, E = Other.Counts.size(); I < E; ++I) {
 bool Overflowed;
-uint64_t Value =
-SaturatingMultiplyAdd(Other.Counts[I], Weight, Counts[I], );
-if (Value > getInstrMaxCountValue()) {
-  Value = getInstrMaxCountValue();
-  Overflowed = true;
+uint64_t Value;
+// When a profile has single byte coverage, use || to merge counters.
+if (HasSingleByteCoverage)
+  Value = Other.Counts[I] || Counts[I];

ellishg wrote:

Yes, we actually do use block coverage to collect many raw profiles and 
aggregate them into an indexed profile. Since the counts can be larger than 
one, it helps differentiate between some hot and cold blocks during 
optimization.

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


[clang] [compiler-rt] [Sanitizer] add signed-integer-wrap sanitizer (PR #80089)

2024-02-14 Thread John McCall via cfe-commits

rjmccall wrote:

> > > > Why not just enforce -fsanitize=signed-integer-overflow with -fwrapv? I 
> > > > suspect it's just overlook, and not intentional behavior.
> > > 
> > > 
> > > +1
> > > We should consider this direction
> > 
> > 
> > The UB-vs-non-UB seemed to be a really specific goal in the existing code. 
> > i.e. that the sanitizer was disabled didn't look like an accident. For 
> > people using this to find _only_ UB, this would be a behavioral change, so 
> > to me it seems like a separate name makes the most sense. Anyone wanting 
> > wrap-around checking can use -wrap, and anyone wanting UB checking can use 
> > -overflow.
> 
> Isn't this still UB even with -fwrapv? UB is a language feature, not compiler.

`-fwrapv` is essentially a language dialect that defines the behavior of 
integer wraparound.  It is no longer UB in compilations using that mode.

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


[clang] [-Wunsafe-buffer-usage] Ignore constant safe indices in array subscripts (PR #80504)

2024-02-14 Thread via cfe-commits

https://github.com/jkorous-apple updated 
https://github.com/llvm/llvm-project/pull/80504

>From dfc9d95c185f5228f5c9680a19aa396d20e33d19 Mon Sep 17 00:00:00 2001
From: Jan Korous 
Date: Thu, 25 Jan 2024 13:52:12 -0800
Subject: [PATCH 1/7] [-Wunsafe-buffer-usage] Emit fixits for arguments of
 function pointers calls

Currently we ignore calls on function pointers (unlike direct calls of
functions and class methods). This patch adds support for function pointers as
well.

The change is to simply replace use of forEachArgumentWithParam matcher in UPC
gadget with forEachArgumentWithParamType.

from the documentation of forEachArgumentWithParamType:
/// Matches all arguments and their respective types for a \c CallExpr or
/// \c CXXConstructExpr. It is very similar to \c forEachArgumentWithParam but
/// it works on calls through function pointers as well.

Currently the matcher also uses hasPointerType() which checks that the
canonical type of an argument is pointer and won't match on arrays decayed to
pointer. Replacing hasPointerType() with isAnyPointerType() which allows
implicit casts allows for the arrays to be matched as well and this way we get
fixits for array arguments to function pointer calls too.
---
 clang/lib/Analysis/UnsafeBufferUsage.cpp |  4 ++--
 ...fer-usage-fixits-pointer-arg-to-func-ptr-call.cpp | 12 
 2 files changed, 14 insertions(+), 2 deletions(-)
 create mode 100644 
clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-pointer-arg-to-func-ptr-call.cpp

diff --git a/clang/lib/Analysis/UnsafeBufferUsage.cpp 
b/clang/lib/Analysis/UnsafeBufferUsage.cpp
index d00c598c4b9de3..c5a87f14bc8880 100644
--- a/clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ b/clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -282,8 +282,8 @@ isInUnspecifiedPointerContext(internal::Matcher 
InnerMatcher) {
   //(i.e., computing the distance between two pointers); or ...
 
   auto CallArgMatcher =
-  callExpr(forEachArgumentWithParam(InnerMatcher,
-  hasPointerType() /* array also decays to pointer type*/),
+  callExpr(forEachArgumentWithParamType(InnerMatcher,
+  isAnyPointer() /* array also decays to pointer type*/),
   unless(callee(functionDecl(hasAttr(attr::UnsafeBufferUsage);
 
   auto CastOperandMatcher =
diff --git 
a/clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-pointer-arg-to-func-ptr-call.cpp
 
b/clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-pointer-arg-to-func-ptr-call.cpp
new file mode 100644
index 00..ae761e46a98191
--- /dev/null
+++ 
b/clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-pointer-arg-to-func-ptr-call.cpp
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -std=c++20 -Wunsafe-buffer-usage \
+// RUN:-fsafe-buffer-usage-suggestions \
+// RUN:-fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
+
+void unsafe_array_func_ptr_call(void (*fn_ptr)(int *param)) {
+  int p[32];
+  // CHECK-DAG: 
fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:12}:"std::array p"
+
+  int tmp = p[5];
+  fn_ptr(p);
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:11}:".data()"
+}

>From 44dab965c459f2cd6084ea332f4a6756f57254e0 Mon Sep 17 00:00:00 2001
From: Jan Korous 
Date: Thu, 1 Feb 2024 14:44:01 -0800
Subject: [PATCH 2/7] [-Wunsafe-buffer-usage][NFC] Add tests for function
 pointer call fixits

---
 ...ge-fixits-pointer-arg-to-func-ptr-call.cpp | 38 ++-
 1 file changed, 37 insertions(+), 1 deletion(-)

diff --git 
a/clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-pointer-arg-to-func-ptr-call.cpp
 
b/clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-pointer-arg-to-func-ptr-call.cpp
index ae761e46a98191..0459d6549fd86f 100644
--- 
a/clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-pointer-arg-to-func-ptr-call.cpp
+++ 
b/clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-pointer-arg-to-func-ptr-call.cpp
@@ -6,7 +6,43 @@ void unsafe_array_func_ptr_call(void (*fn_ptr)(int *param)) {
   int p[32];
   // CHECK-DAG: 
fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:12}:"std::array p"
 
-  int tmp = p[5];
+  p[5] = 10;
   fn_ptr(p);
   // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:11}:".data()"
 }
+
+void unsafe_ptr_func_ptr_call(void (*fn_ptr)(int *param)) {
+  int *p;
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:9}:"std::span 
p"
+
+  p[5] = 10;
+  fn_ptr(p);
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:11}:".data()"
+}
+
+void addr_of_unsafe_ptr_func_ptr_call(void (*fn_ptr)(int *param)) {
+  int *p;
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:9}:"std::span 
p"
+
+  p[5] = 10;
+  fn_ptr([0]);
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-1]]:10-[[@LINE-1]]:15}:"p.data()"
+}
+
+void addr_of_unsafe_ptr_w_offset_func_ptr_call(void (*fn_ptr)(int *param)) {
+  int *p;
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:9}:"std::span 
p"
+
+  p[5] = 10;
+  fn_ptr([3]);
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-1]]:10-[[@LINE-1]]:15}:"()[3]"

[clang] [-Wunsafe-buffer-usage] Ignore constant safe indices in array subscripts (PR #80504)

2024-02-14 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-clang-analysis

@llvm/pr-subscribers-clang

Author: None (jkorous-apple)


Changes

depends on
https://github.com/llvm/llvm-project/pull/80358

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


5 Files Affected:

- (modified) clang/lib/Analysis/UnsafeBufferUsage.cpp (+46-11) 
- (modified) clang/test/SemaCXX/warn-unsafe-buffer-usage-array.cpp (+17-1) 
- (modified) 
clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-pointer-access.cpp (+4-4) 
- (added) 
clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-pointer-arg-to-func-ptr-call.cpp
 (+49) 
- (modified) clang/test/SemaCXX/warn-unsafe-buffer-usage.cpp (+27-26) 


``diff
diff --git a/clang/lib/Analysis/UnsafeBufferUsage.cpp 
b/clang/lib/Analysis/UnsafeBufferUsage.cpp
index d00c598c4b9de3..aa3240a86e562b 100644
--- a/clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ b/clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -281,10 +281,13 @@ isInUnspecifiedPointerContext(internal::Matcher 
InnerMatcher) {
   // 4. the operand of a pointer subtraction operation
   //(i.e., computing the distance between two pointers); or ...
 
-  auto CallArgMatcher =
-  callExpr(forEachArgumentWithParam(InnerMatcher,
-  hasPointerType() /* array also decays to pointer type*/),
-  unless(callee(functionDecl(hasAttr(attr::UnsafeBufferUsage);
+  // clang-format off
+  auto CallArgMatcher = callExpr(
+forEachArgumentWithParamType(
+  InnerMatcher, 
+  isAnyPointer() /* array also decays to pointer type*/),
+unless(callee(
+  functionDecl(hasAttr(attr::UnsafeBufferUsage);
 
   auto CastOperandMatcher =
   castExpr(anyOf(hasCastKind(CastKind::CK_PointerToIntegral),
@@ -306,6 +309,7 @@ isInUnspecifiedPointerContext(internal::Matcher 
InnerMatcher) {
   hasRHS(hasPointerType())),
 eachOf(hasLHS(InnerMatcher),
hasRHS(InnerMatcher)));
+  // clang-format on
 
   return stmt(anyOf(CallArgMatcher, CastOperandMatcher, CompOperandMatcher,
PtrSubtractionMatcher));
@@ -402,6 +406,37 @@ AST_MATCHER(CXXConstructExpr, isSafeSpanTwoParamConstruct) 
{
   }
   return false;
 }
+
+AST_MATCHER(ArraySubscriptExpr, isSafeArraySubscript) {
+  // FIXME: Proper solution:
+  //  - refactor Sema::CheckArrayAccess
+  //- split safe/OOB/unknown decision logic from diagnostics emitting code
+  //-  e. g. "Try harder to find a NamedDecl to point at in the note." 
already duplicated
+  //  - call both from Sema and from here
+
+  const DeclRefExpr * BaseDRE = 
dyn_cast_or_null(Node.getBase()->IgnoreParenImpCasts());
+  if (!BaseDRE)
+return false;
+  if (!BaseDRE->getDecl())
+return false;
+  auto BaseVarDeclTy = BaseDRE->getDecl()->getType();
+  if (!BaseVarDeclTy->isConstantArrayType())
+return false;
+  const auto * CATy = dyn_cast_or_null(BaseVarDeclTy);
+  if (!CATy)
+return false;
+  const APInt ArrSize = CATy->getSize();
+
+  if (const auto * IdxLit = dyn_cast(Node.getIdx())) {
+const APInt ArrIdx = IdxLit->getValue();
+// FIXME: ArrIdx.isNegative() we could immediately emit an error as that's 
a bug
+if (ArrIdx.isNonNegative() && ArrIdx.getLimitedValue() < 
ArrSize.getLimitedValue())
+  return true;
+  }
+
+  return false;
+}
+
 } // namespace clang::ast_matchers
 
 namespace {
@@ -594,16 +629,16 @@ class ArraySubscriptGadget : public WarningGadget {
   }
 
   static Matcher matcher() {
-// FIXME: What if the index is integer literal 0? Should this be
-// a safe gadget in this case?
-  // clang-format off
+// clang-format off
   return stmt(arraySubscriptExpr(
 hasBase(ignoringParenImpCasts(
   anyOf(hasPointerType(), hasArrayType(,
-unless(hasIndex(
-anyOf(integerLiteral(equals(0)), arrayInitIndexExpr())
- )))
-.bind(ArraySubscrTag));
+unless(anyOf(
+  isSafeArraySubscript(),
+  hasIndex(
+  anyOf(integerLiteral(equals(0)), arrayInitIndexExpr())
+  )
+))).bind(ArraySubscrTag));
 // clang-format on
   }
 
diff --git a/clang/test/SemaCXX/warn-unsafe-buffer-usage-array.cpp 
b/clang/test/SemaCXX/warn-unsafe-buffer-usage-array.cpp
index 90c11b1be95c25..4804223e8be058 100644
--- a/clang/test/SemaCXX/warn-unsafe-buffer-usage-array.cpp
+++ b/clang/test/SemaCXX/warn-unsafe-buffer-usage-array.cpp
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -std=c++20 -Wno-all -Wunsafe-buffer-usage \
+// RUN: %clang_cc1 -std=c++20 -Wno-everything -Wunsafe-buffer-usage \
 // RUN:-fsafe-buffer-usage-suggestions \
 // RUN:-verify %s
 
@@ -22,3 +22,19 @@ struct Foo {
 void foo2(Foo& f, unsigned idx) {
   f.member_buffer[idx] = 0; // expected-warning{{unsafe buffer access}}
 }
+
+void constant_idx_safe(unsigned idx) {
+  int buffer[10];
+  buffer[9] = 0;
+}
+
+void constant_idx_safe0(unsigned idx) {

[clang] [-Wunsafe-buffer-usage] Ignore constant safe indices in array subscripts (PR #80504)

2024-02-14 Thread via cfe-commits

https://github.com/jkorous-apple updated 
https://github.com/llvm/llvm-project/pull/80504

>From dfc9d95c185f5228f5c9680a19aa396d20e33d19 Mon Sep 17 00:00:00 2001
From: Jan Korous 
Date: Thu, 25 Jan 2024 13:52:12 -0800
Subject: [PATCH 1/6] [-Wunsafe-buffer-usage] Emit fixits for arguments of
 function pointers calls

Currently we ignore calls on function pointers (unlike direct calls of
functions and class methods). This patch adds support for function pointers as
well.

The change is to simply replace use of forEachArgumentWithParam matcher in UPC
gadget with forEachArgumentWithParamType.

from the documentation of forEachArgumentWithParamType:
/// Matches all arguments and their respective types for a \c CallExpr or
/// \c CXXConstructExpr. It is very similar to \c forEachArgumentWithParam but
/// it works on calls through function pointers as well.

Currently the matcher also uses hasPointerType() which checks that the
canonical type of an argument is pointer and won't match on arrays decayed to
pointer. Replacing hasPointerType() with isAnyPointerType() which allows
implicit casts allows for the arrays to be matched as well and this way we get
fixits for array arguments to function pointer calls too.
---
 clang/lib/Analysis/UnsafeBufferUsage.cpp |  4 ++--
 ...fer-usage-fixits-pointer-arg-to-func-ptr-call.cpp | 12 
 2 files changed, 14 insertions(+), 2 deletions(-)
 create mode 100644 
clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-pointer-arg-to-func-ptr-call.cpp

diff --git a/clang/lib/Analysis/UnsafeBufferUsage.cpp 
b/clang/lib/Analysis/UnsafeBufferUsage.cpp
index d00c598c4b9de3..c5a87f14bc8880 100644
--- a/clang/lib/Analysis/UnsafeBufferUsage.cpp
+++ b/clang/lib/Analysis/UnsafeBufferUsage.cpp
@@ -282,8 +282,8 @@ isInUnspecifiedPointerContext(internal::Matcher 
InnerMatcher) {
   //(i.e., computing the distance between two pointers); or ...
 
   auto CallArgMatcher =
-  callExpr(forEachArgumentWithParam(InnerMatcher,
-  hasPointerType() /* array also decays to pointer type*/),
+  callExpr(forEachArgumentWithParamType(InnerMatcher,
+  isAnyPointer() /* array also decays to pointer type*/),
   unless(callee(functionDecl(hasAttr(attr::UnsafeBufferUsage);
 
   auto CastOperandMatcher =
diff --git 
a/clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-pointer-arg-to-func-ptr-call.cpp
 
b/clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-pointer-arg-to-func-ptr-call.cpp
new file mode 100644
index 00..ae761e46a98191
--- /dev/null
+++ 
b/clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-pointer-arg-to-func-ptr-call.cpp
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -std=c++20 -Wunsafe-buffer-usage \
+// RUN:-fsafe-buffer-usage-suggestions \
+// RUN:-fdiagnostics-parseable-fixits %s 2>&1 | FileCheck %s
+
+void unsafe_array_func_ptr_call(void (*fn_ptr)(int *param)) {
+  int p[32];
+  // CHECK-DAG: 
fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:12}:"std::array p"
+
+  int tmp = p[5];
+  fn_ptr(p);
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:11}:".data()"
+}

>From 44dab965c459f2cd6084ea332f4a6756f57254e0 Mon Sep 17 00:00:00 2001
From: Jan Korous 
Date: Thu, 1 Feb 2024 14:44:01 -0800
Subject: [PATCH 2/6] [-Wunsafe-buffer-usage][NFC] Add tests for function
 pointer call fixits

---
 ...ge-fixits-pointer-arg-to-func-ptr-call.cpp | 38 ++-
 1 file changed, 37 insertions(+), 1 deletion(-)

diff --git 
a/clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-pointer-arg-to-func-ptr-call.cpp
 
b/clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-pointer-arg-to-func-ptr-call.cpp
index ae761e46a98191..0459d6549fd86f 100644
--- 
a/clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-pointer-arg-to-func-ptr-call.cpp
+++ 
b/clang/test/SemaCXX/warn-unsafe-buffer-usage-fixits-pointer-arg-to-func-ptr-call.cpp
@@ -6,7 +6,43 @@ void unsafe_array_func_ptr_call(void (*fn_ptr)(int *param)) {
   int p[32];
   // CHECK-DAG: 
fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:12}:"std::array p"
 
-  int tmp = p[5];
+  p[5] = 10;
   fn_ptr(p);
   // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:11}:".data()"
 }
+
+void unsafe_ptr_func_ptr_call(void (*fn_ptr)(int *param)) {
+  int *p;
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:9}:"std::span 
p"
+
+  p[5] = 10;
+  fn_ptr(p);
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-1]]:11-[[@LINE-1]]:11}:".data()"
+}
+
+void addr_of_unsafe_ptr_func_ptr_call(void (*fn_ptr)(int *param)) {
+  int *p;
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:9}:"std::span 
p"
+
+  p[5] = 10;
+  fn_ptr([0]);
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-1]]:10-[[@LINE-1]]:15}:"p.data()"
+}
+
+void addr_of_unsafe_ptr_w_offset_func_ptr_call(void (*fn_ptr)(int *param)) {
+  int *p;
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-1]]:3-[[@LINE-1]]:9}:"std::span 
p"
+
+  p[5] = 10;
+  fn_ptr([3]);
+  // CHECK-DAG: fix-it:"{{.*}}":{[[@LINE-1]]:10-[[@LINE-1]]:15}:"()[3]"

[clang] [clang][OpenACC] Fix copy-paste name in ParsingOpenACCDirectiveRAII (PR #81796)

2024-02-14 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: None (FruitClover)


Changes



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


1 Files Affected:

- (modified) clang/include/clang/Parse/RAIIObjectsForParser.h (+1-1) 


``diff
diff --git a/clang/include/clang/Parse/RAIIObjectsForParser.h 
b/clang/include/clang/Parse/RAIIObjectsForParser.h
index e1626a7870bb7a..f4fa518ef27d01 100644
--- a/clang/include/clang/Parse/RAIIObjectsForParser.h
+++ b/clang/include/clang/Parse/RAIIObjectsForParser.h
@@ -323,7 +323,7 @@ namespace clang {
 
 /// This can be used to restore the state early, before the dtor
 /// is run.
-void restore() { P.OpenMPDirectiveParsing = OldVal; }
+void restore() { P.OpenACCDirectiveParsing = OldVal; }
 
 ~ParsingOpenACCDirectiveRAII() { restore(); }
   };

``




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


[clang] [clang][OpenACC] Fix copy-paste name in ParsingOpenACCDirectiveRAII (PR #81796)

2024-02-14 Thread via cfe-commits

https://github.com/FruitClover created 
https://github.com/llvm/llvm-project/pull/81796

None

>From e7b232ea0228a267bf92ec0bbd61b61eac9cb579 Mon Sep 17 00:00:00 2001
From: Mike Kashkarov 
Date: Thu, 8 Feb 2024 19:27:29 +0300
Subject: [PATCH] [clang][OpenACC] Fix copy-paste name in
 ParsingOpenACCDirectiveRAII

---
 clang/include/clang/Parse/RAIIObjectsForParser.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/include/clang/Parse/RAIIObjectsForParser.h 
b/clang/include/clang/Parse/RAIIObjectsForParser.h
index e1626a7870bb7a..f4fa518ef27d01 100644
--- a/clang/include/clang/Parse/RAIIObjectsForParser.h
+++ b/clang/include/clang/Parse/RAIIObjectsForParser.h
@@ -323,7 +323,7 @@ namespace clang {
 
 /// This can be used to restore the state early, before the dtor
 /// is run.
-void restore() { P.OpenMPDirectiveParsing = OldVal; }
+void restore() { P.OpenACCDirectiveParsing = OldVal; }
 
 ~ParsingOpenACCDirectiveRAII() { restore(); }
   };

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


[clang] ad49657 - [clang] Add fixed point precision macros (#81207)

2024-02-14 Thread via cfe-commits

Author: PiJoules
Date: 2024-02-14T14:11:56-08:00
New Revision: ad49657a424db5e5979236ef5a474e93d827ab2c

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

LOG: [clang] Add fixed point precision macros (#81207)

This defines the builtin macros specified in `7.18a.3 Precision macros`
of ISO/IEC TR 18037:2008. These are the `__*__` versions of them and the
formal definitions in stdfix.h can use them.

Added: 
clang/test/Preprocessor/fixed-point.c
clang/test/Preprocessor/no-fixed-point.c

Modified: 
clang/docs/ReleaseNotes.rst
clang/lib/Frontend/InitPreprocessor.cpp
llvm/include/llvm/ADT/APFixedPoint.h
llvm/lib/Support/APFixedPoint.cpp

Removed: 




diff  --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 6cf48d63dd512e..a745f20199ceba 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -305,6 +305,12 @@ DWARF Support in Clang
 Floating Point Support in Clang
 ---
 
+Fixed Point Support in Clang
+
+
+- Support fixed point precision macros according to ``7.18a.3`` of
+  `ISO/IEC TR 18037:2008 
`_.
+
 AST Matchers
 
 

diff  --git a/clang/lib/Frontend/InitPreprocessor.cpp 
b/clang/lib/Frontend/InitPreprocessor.cpp
index 877e205e2e9bfa..1b250cda42a4dd 100644
--- a/clang/lib/Frontend/InitPreprocessor.cpp
+++ b/clang/lib/Frontend/InitPreprocessor.cpp
@@ -768,6 +768,60 @@ void InitializeOpenCLFeatureTestMacros(const TargetInfo 
,
   Builder.defineMacro("__opencl_c_int64");
 }
 
+llvm::SmallString<32> ConstructFixedPointLiteral(llvm::APFixedPoint Val,
+ llvm::StringRef Suffix) {
+  if (Val.isSigned() && Val == llvm::APFixedPoint::getMin(Val.getSemantics())) 
{
+// When representing the min value of a signed fixed point type in source
+// code, we cannot simply write `-`. For example, the min
+// value of a `short _Fract` cannot be written as `-1.0hr`. This is because
+// the parser will read this (and really any negative numerical literal) as
+// a UnaryOperator that owns a FixedPointLiteral with a positive value
+// rather than just a FixedPointLiteral with a negative value. Compiling
+// `-1.0hr` results in an overflow to the maximal value of that fixed point
+// type. The correct way to represent a signed min value is to instead 
split
+// it into two halves, like `(-0.5hr-0.5hr)` which is what the standard
+// defines SFRACT_MIN as.
+llvm::SmallString<32> Literal;
+Literal.push_back('(');
+llvm::SmallString<32> HalfStr =
+ConstructFixedPointLiteral(Val.shr(1), Suffix);
+Literal += HalfStr;
+Literal += HalfStr;
+Literal.push_back(')');
+return Literal;
+  }
+
+  llvm::SmallString<32> Str(Val.toString());
+  Str += Suffix;
+  return Str;
+}
+
+void DefineFixedPointMacros(const TargetInfo , MacroBuilder ,
+llvm::StringRef TypeName, llvm::StringRef Suffix,
+unsigned Width, unsigned Scale, bool Signed) {
+  // Saturation doesn't affect the size or scale of a fixed point type, so we
+  // don't need it here.
+  llvm::FixedPointSemantics FXSema(
+  Width, Scale, Signed, /*IsSaturated=*/false,
+  !Signed && TI.doUnsignedFixedPointTypesHavePadding());
+  llvm::SmallString<32> MacroPrefix("__");
+  MacroPrefix += TypeName;
+  Builder.defineMacro(MacroPrefix + "_EPSILON__",
+  ConstructFixedPointLiteral(
+  llvm::APFixedPoint::getEpsilon(FXSema), Suffix));
+  Builder.defineMacro(MacroPrefix + "_FBIT__", Twine(Scale));
+  Builder.defineMacro(
+  MacroPrefix + "_MAX__",
+  ConstructFixedPointLiteral(llvm::APFixedPoint::getMax(FXSema), Suffix));
+
+  // ISO/IEC TR 18037:2008 doesn't specify MIN macros for unsigned types since
+  // they're all just zero.
+  if (Signed)
+Builder.defineMacro(
+MacroPrefix + "_MIN__",
+ConstructFixedPointLiteral(llvm::APFixedPoint::getMin(FXSema), 
Suffix));
+}
+
 static void InitializePredefinedMacros(const TargetInfo ,
const LangOptions ,
const FrontendOptions ,
@@ -1097,6 +1151,47 @@ static void InitializePredefinedMacros(const TargetInfo 
,
  TI.getTypeWidth(TI.getIntMaxType()) &&
  "uintmax_t and intmax_t have 
diff erent widths?");
 
+  if (LangOpts.FixedPoint) {
+// Each unsigned type has the same width as their signed type.
+DefineFixedPointMacros(TI, Builder, "SFRACT", "HR", 
TI.getShortFractWidth(),
+   TI.getShortFractScale(), /*Signed=*/true);
+

[clang] [llvm] [clang] Add fixed point precision macros (PR #81207)

2024-02-14 Thread via cfe-commits

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


[clang] [alpha.webkit.UncountedCallArgsChecker] Add a few more safe functions to call. (PR #81532)

2024-02-14 Thread Artem Dergachev via cfe-commits

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


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


[clang] [llvm] [clang] Add fixed point precision macros (PR #81207)

2024-02-14 Thread via cfe-commits

https://github.com/PiJoules updated 
https://github.com/llvm/llvm-project/pull/81207

>From 58a33e3792d2447cf99ac9959c80333299a9a2dc Mon Sep 17 00:00:00 2001
From: Leonard Chan 
Date: Thu, 8 Feb 2024 16:12:35 -0800
Subject: [PATCH] [clang] Add fixed point precision macros

This defines the builtin macros specified in `7.18a.3 Precision macros`
of ISO/IEC TR 18037:2008. These are the `__*__` versions of them and the formal
definitions in stdfix.h can use them.
---
 clang/docs/ReleaseNotes.rst  |  6 ++
 clang/lib/Frontend/InitPreprocessor.cpp  | 95 
 clang/test/Preprocessor/fixed-point.c| 67 +
 clang/test/Preprocessor/no-fixed-point.c |  7 ++
 llvm/include/llvm/ADT/APFixedPoint.h |  1 +
 llvm/lib/Support/APFixedPoint.cpp|  6 ++
 6 files changed, 182 insertions(+)
 create mode 100644 clang/test/Preprocessor/fixed-point.c
 create mode 100644 clang/test/Preprocessor/no-fixed-point.c

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index e12a802e2e9ede..5c77b605d462a8 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -297,6 +297,12 @@ DWARF Support in Clang
 Floating Point Support in Clang
 ---
 
+Fixed Point Support in Clang
+
+
+- Support fixed point precision macros according to ``7.18a.3`` of
+  `ISO/IEC TR 18037:2008 
`_.
+
 AST Matchers
 
 
diff --git a/clang/lib/Frontend/InitPreprocessor.cpp 
b/clang/lib/Frontend/InitPreprocessor.cpp
index 877e205e2e9bfa..1b250cda42a4dd 100644
--- a/clang/lib/Frontend/InitPreprocessor.cpp
+++ b/clang/lib/Frontend/InitPreprocessor.cpp
@@ -768,6 +768,60 @@ void InitializeOpenCLFeatureTestMacros(const TargetInfo 
,
   Builder.defineMacro("__opencl_c_int64");
 }
 
+llvm::SmallString<32> ConstructFixedPointLiteral(llvm::APFixedPoint Val,
+ llvm::StringRef Suffix) {
+  if (Val.isSigned() && Val == llvm::APFixedPoint::getMin(Val.getSemantics())) 
{
+// When representing the min value of a signed fixed point type in source
+// code, we cannot simply write `-`. For example, the min
+// value of a `short _Fract` cannot be written as `-1.0hr`. This is because
+// the parser will read this (and really any negative numerical literal) as
+// a UnaryOperator that owns a FixedPointLiteral with a positive value
+// rather than just a FixedPointLiteral with a negative value. Compiling
+// `-1.0hr` results in an overflow to the maximal value of that fixed point
+// type. The correct way to represent a signed min value is to instead 
split
+// it into two halves, like `(-0.5hr-0.5hr)` which is what the standard
+// defines SFRACT_MIN as.
+llvm::SmallString<32> Literal;
+Literal.push_back('(');
+llvm::SmallString<32> HalfStr =
+ConstructFixedPointLiteral(Val.shr(1), Suffix);
+Literal += HalfStr;
+Literal += HalfStr;
+Literal.push_back(')');
+return Literal;
+  }
+
+  llvm::SmallString<32> Str(Val.toString());
+  Str += Suffix;
+  return Str;
+}
+
+void DefineFixedPointMacros(const TargetInfo , MacroBuilder ,
+llvm::StringRef TypeName, llvm::StringRef Suffix,
+unsigned Width, unsigned Scale, bool Signed) {
+  // Saturation doesn't affect the size or scale of a fixed point type, so we
+  // don't need it here.
+  llvm::FixedPointSemantics FXSema(
+  Width, Scale, Signed, /*IsSaturated=*/false,
+  !Signed && TI.doUnsignedFixedPointTypesHavePadding());
+  llvm::SmallString<32> MacroPrefix("__");
+  MacroPrefix += TypeName;
+  Builder.defineMacro(MacroPrefix + "_EPSILON__",
+  ConstructFixedPointLiteral(
+  llvm::APFixedPoint::getEpsilon(FXSema), Suffix));
+  Builder.defineMacro(MacroPrefix + "_FBIT__", Twine(Scale));
+  Builder.defineMacro(
+  MacroPrefix + "_MAX__",
+  ConstructFixedPointLiteral(llvm::APFixedPoint::getMax(FXSema), Suffix));
+
+  // ISO/IEC TR 18037:2008 doesn't specify MIN macros for unsigned types since
+  // they're all just zero.
+  if (Signed)
+Builder.defineMacro(
+MacroPrefix + "_MIN__",
+ConstructFixedPointLiteral(llvm::APFixedPoint::getMin(FXSema), 
Suffix));
+}
+
 static void InitializePredefinedMacros(const TargetInfo ,
const LangOptions ,
const FrontendOptions ,
@@ -1097,6 +1151,47 @@ static void InitializePredefinedMacros(const TargetInfo 
,
  TI.getTypeWidth(TI.getIntMaxType()) &&
  "uintmax_t and intmax_t have different widths?");
 
+  if (LangOpts.FixedPoint) {
+// Each unsigned type has the same width as their signed type.
+DefineFixedPointMacros(TI, Builder, "SFRACT", "HR", 
TI.getShortFractWidth(),
+ 

[clang] [HLSL] Vector standard conversions (PR #71098)

2024-02-14 Thread Chris B via cfe-commits


@@ -6432,7 +6432,7 @@ void InitializationSequence::InitializeFrom(Sema ,
   // For HLSL ext vector types we allow list initialization behavior for C++
   // constructor syntax. This is accomplished by converting initialization
   // arguments an InitListExpr late.
-  if (S.getLangOpts().HLSL && DestType->isExtVectorType() &&
+  if (S.getLangOpts().HLSL && Args.size() > 1 && DestType->isExtVectorType() &&

llvm-beanz wrote:

This is subtle but there are tests that cover this. The tests introduced here 
cover the `Args.size() == 1` case. Take this example:
```c++
void Fn(double2 D);
void Call(float2 F) {
  Fn(F);
}
```
In the call to `Fn` the argument becomes an implicit initialization list 
expression with one argument (fun right). In that case we rely on HLSL's 
standard conversion sequences to convert the first argument to the target type.

In other cases that we cover in the vector-constructors.hlsl test, we 
initialize vectors with initializer lists that are more than one argument like:

```c++
float2 f = float2(1, 2);
```

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


[clang] [clang-tools-extra] [clang-tidy] Add new check `modernize-use-designated-initializers` (PR #80541)

2024-02-14 Thread Piotr Zegar via cfe-commits
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= 
Message-ID:
In-Reply-To: 



@@ -0,0 +1,132 @@
+//===--- UseDesignatedInitializersCheck.cpp - clang-tidy 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "UseDesignatedInitializersCheck.h"
+#include "clang/AST/APValue.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/Expr.h"
+#include "clang/AST/Stmt.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/ASTMatchers/ASTMatchersMacros.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Lex/Lexer.h"
+#include "clang/Tooling/DesignatedInitializers.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::modernize {
+
+static constexpr char IgnoreSingleElementAggregatesName[] =
+"IgnoreSingleElementAggregates";
+static constexpr bool IgnoreSingleElementAggregatesDefault = true;
+
+static constexpr char RestrictToPODTypesName[] = "RestrictToPODTypes";
+static constexpr bool RestrictToPODTypesDefault = false;
+
+static constexpr char IgnoreMacrosName[] = "IgnoreMacros";
+static constexpr bool IgnoreMacrosDefault = true;
+
+namespace {
+
+AST_MATCHER(CXXRecordDecl, isAggregate) { return Node.isAggregate(); }
+
+AST_MATCHER(CXXRecordDecl, isPOD) { return Node.isPOD(); }
+
+AST_MATCHER(InitListExpr, isFullyDesignated) {
+  if (const InitListExpr *SyntacticForm =
+  Node.isSyntacticForm() ?  : Node.getSyntacticForm()) {
+return llvm::all_of(SyntacticForm->children(), [](auto *InitExpr) {
+  return isa(InitExpr);
+});
+  }
+  return true;
+}
+
+AST_MATCHER(InitListExpr, hasSingleElement) { return Node.getNumInits() == 1; }
+
+} // namespace
+
+UseDesignatedInitializersCheck::UseDesignatedInitializersCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context), IgnoreSingleElementAggregates(Options.get(
+ IgnoreSingleElementAggregatesName,
+ 
IgnoreSingleElementAggregatesDefault)),
+  RestrictToPODTypes(
+  Options.get(RestrictToPODTypesName, RestrictToPODTypesDefault)),
+  IgnoreMacros(Options.get(IgnoreMacrosName, IgnoreMacrosDefault)) {}
+
+void UseDesignatedInitializersCheck::registerMatchers(MatchFinder *Finder) {
+  const auto HasBaseWithFields =
+  hasAnyBase(hasType(cxxRecordDecl(has(fieldDecl();
+  Finder->addMatcher(
+  initListExpr(
+  hasType(cxxRecordDecl(RestrictToPODTypes ? isPOD() : isAggregate(),
+unless(HasBaseWithFields))
+  .bind("type")),
+  unless(IgnoreSingleElementAggregates ? hasSingleElement()
+   : unless(anything())),
+  unless(isFullyDesignated()))
+  .bind("init"),
+  this);
+}
+
+static bool isFullyUndesignated(const InitListExpr *SyntacticInitList) {
+  return std::all_of(

PiotrZSL wrote:

`llvm::all_of(*SyntacticInitList, [](auto *InitExpr) { return 
!isa(InitExpr); });`

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


[clang] [clang-tools-extra] [clang-tidy] Add new check `modernize-use-designated-initializers` (PR #80541)

2024-02-14 Thread Piotr Zegar via cfe-commits
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= 
Message-ID:
In-Reply-To: 



@@ -0,0 +1,132 @@
+//===--- UseDesignatedInitializersCheck.cpp - clang-tidy 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "UseDesignatedInitializersCheck.h"
+#include "clang/AST/APValue.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/Expr.h"
+#include "clang/AST/Stmt.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/ASTMatchers/ASTMatchersMacros.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Lex/Lexer.h"
+#include "clang/Tooling/DesignatedInitializers.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::modernize {
+
+static constexpr char IgnoreSingleElementAggregatesName[] =
+"IgnoreSingleElementAggregates";
+static constexpr bool IgnoreSingleElementAggregatesDefault = true;
+
+static constexpr char RestrictToPODTypesName[] = "RestrictToPODTypes";
+static constexpr bool RestrictToPODTypesDefault = false;
+
+static constexpr char IgnoreMacrosName[] = "IgnoreMacros";
+static constexpr bool IgnoreMacrosDefault = true;
+
+namespace {
+
+AST_MATCHER(CXXRecordDecl, isAggregate) { return Node.isAggregate(); }
+
+AST_MATCHER(CXXRecordDecl, isPOD) { return Node.isPOD(); }
+
+AST_MATCHER(InitListExpr, isFullyDesignated) {
+  if (const InitListExpr *SyntacticForm =
+  Node.isSyntacticForm() ?  : Node.getSyntacticForm()) {
+return llvm::all_of(SyntacticForm->children(), [](auto *InitExpr) {
+  return isa(InitExpr);
+});
+  }
+  return true;
+}
+
+AST_MATCHER(InitListExpr, hasSingleElement) { return Node.getNumInits() == 1; }
+
+} // namespace
+
+UseDesignatedInitializersCheck::UseDesignatedInitializersCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context), IgnoreSingleElementAggregates(Options.get(
+ IgnoreSingleElementAggregatesName,
+ 
IgnoreSingleElementAggregatesDefault)),
+  RestrictToPODTypes(
+  Options.get(RestrictToPODTypesName, RestrictToPODTypesDefault)),
+  IgnoreMacros(Options.get(IgnoreMacrosName, IgnoreMacrosDefault)) {}
+
+void UseDesignatedInitializersCheck::registerMatchers(MatchFinder *Finder) {
+  const auto HasBaseWithFields =
+  hasAnyBase(hasType(cxxRecordDecl(has(fieldDecl();
+  Finder->addMatcher(
+  initListExpr(
+  hasType(cxxRecordDecl(RestrictToPODTypes ? isPOD() : isAggregate(),
+unless(HasBaseWithFields))
+  .bind("type")),
+  unless(IgnoreSingleElementAggregates ? hasSingleElement()
+   : unless(anything())),
+  unless(isFullyDesignated()))
+  .bind("init"),
+  this);
+}
+
+static bool isFullyUndesignated(const InitListExpr *SyntacticInitList) {
+  return std::all_of(
+  SyntacticInitList->begin(), SyntacticInitList->end(),
+  [](auto *InitExpr) { return !isa(InitExpr); });
+}
+
+void UseDesignatedInitializersCheck::check(
+const MatchFinder::MatchResult ) {
+  const auto *InitList = Result.Nodes.getNodeAs("init");
+  const auto *Type = Result.Nodes.getNodeAs("type");
+  if (!Type || !InitList)
+return;
+  if (const auto *SyntacticInitList = InitList->getSyntacticForm()) {

PiotrZSL wrote:

consider some early exist like:
```
const auto *SyntacticInitList = InitList->getSyntacticForm();
if (!SyntacticInitList) return;
```

to reduce if nesting

https://github.com/llvm/llvm-project/pull/80541
___

[clang] [clang-tools-extra] [clang-tidy] Add new check `modernize-use-designated-initializers` (PR #80541)

2024-02-14 Thread Piotr Zegar via cfe-commits
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= 
Message-ID:
In-Reply-To: 



@@ -0,0 +1,132 @@
+//===--- UseDesignatedInitializersCheck.cpp - clang-tidy 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "UseDesignatedInitializersCheck.h"
+#include "clang/AST/APValue.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/Expr.h"
+#include "clang/AST/Stmt.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/ASTMatchers/ASTMatchersMacros.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Lex/Lexer.h"
+#include "clang/Tooling/DesignatedInitializers.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::modernize {
+
+static constexpr char IgnoreSingleElementAggregatesName[] =
+"IgnoreSingleElementAggregates";
+static constexpr bool IgnoreSingleElementAggregatesDefault = true;
+
+static constexpr char RestrictToPODTypesName[] = "RestrictToPODTypes";
+static constexpr bool RestrictToPODTypesDefault = false;
+
+static constexpr char IgnoreMacrosName[] = "IgnoreMacros";
+static constexpr bool IgnoreMacrosDefault = true;
+
+namespace {
+
+AST_MATCHER(CXXRecordDecl, isAggregate) { return Node.isAggregate(); }
+
+AST_MATCHER(CXXRecordDecl, isPOD) { return Node.isPOD(); }
+
+AST_MATCHER(InitListExpr, isFullyDesignated) {
+  if (const InitListExpr *SyntacticForm =
+  Node.isSyntacticForm() ?  : Node.getSyntacticForm()) {
+return llvm::all_of(SyntacticForm->children(), [](auto *InitExpr) {
+  return isa(InitExpr);
+});
+  }
+  return true;
+}
+
+AST_MATCHER(InitListExpr, hasSingleElement) { return Node.getNumInits() == 1; }
+
+} // namespace
+
+UseDesignatedInitializersCheck::UseDesignatedInitializersCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context), IgnoreSingleElementAggregates(Options.get(
+ IgnoreSingleElementAggregatesName,
+ 
IgnoreSingleElementAggregatesDefault)),
+  RestrictToPODTypes(
+  Options.get(RestrictToPODTypesName, RestrictToPODTypesDefault)),
+  IgnoreMacros(Options.get(IgnoreMacrosName, IgnoreMacrosDefault)) {}

PiotrZSL wrote:

use getLocalOrGlobal for IgnoreMacros, like other checks

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


[clang] [clang-tools-extra] [clang-tidy] Add new check `modernize-use-designated-initializers` (PR #80541)

2024-02-14 Thread Piotr Zegar via cfe-commits
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= 
Message-ID:
In-Reply-To: 



@@ -0,0 +1,132 @@
+//===--- UseDesignatedInitializersCheck.cpp - clang-tidy 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "UseDesignatedInitializersCheck.h"
+#include "clang/AST/APValue.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/Expr.h"
+#include "clang/AST/Stmt.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/ASTMatchers/ASTMatchersMacros.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Lex/Lexer.h"
+#include "clang/Tooling/DesignatedInitializers.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::modernize {
+
+static constexpr char IgnoreSingleElementAggregatesName[] =
+"IgnoreSingleElementAggregates";
+static constexpr bool IgnoreSingleElementAggregatesDefault = true;
+
+static constexpr char RestrictToPODTypesName[] = "RestrictToPODTypes";
+static constexpr bool RestrictToPODTypesDefault = false;
+
+static constexpr char IgnoreMacrosName[] = "IgnoreMacros";
+static constexpr bool IgnoreMacrosDefault = true;
+
+namespace {
+
+AST_MATCHER(CXXRecordDecl, isAggregate) { return Node.isAggregate(); }
+
+AST_MATCHER(CXXRecordDecl, isPOD) { return Node.isPOD(); }
+
+AST_MATCHER(InitListExpr, isFullyDesignated) {
+  if (const InitListExpr *SyntacticForm =
+  Node.isSyntacticForm() ?  : Node.getSyntacticForm()) {
+return llvm::all_of(SyntacticForm->children(), [](auto *InitExpr) {
+  return isa(InitExpr);
+});
+  }
+  return true;
+}
+
+AST_MATCHER(InitListExpr, hasSingleElement) { return Node.getNumInits() == 1; }
+
+} // namespace
+
+UseDesignatedInitializersCheck::UseDesignatedInitializersCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context), IgnoreSingleElementAggregates(Options.get(
+ IgnoreSingleElementAggregatesName,
+ 
IgnoreSingleElementAggregatesDefault)),
+  RestrictToPODTypes(
+  Options.get(RestrictToPODTypesName, RestrictToPODTypesDefault)),
+  IgnoreMacros(Options.get(IgnoreMacrosName, IgnoreMacrosDefault)) {}
+
+void UseDesignatedInitializersCheck::registerMatchers(MatchFinder *Finder) {
+  const auto HasBaseWithFields =
+  hasAnyBase(hasType(cxxRecordDecl(has(fieldDecl();
+  Finder->addMatcher(
+  initListExpr(
+  hasType(cxxRecordDecl(RestrictToPODTypes ? isPOD() : isAggregate(),
+unless(HasBaseWithFields))
+  .bind("type")),
+  unless(IgnoreSingleElementAggregates ? hasSingleElement()
+   : unless(anything())),
+  unless(isFullyDesignated()))
+  .bind("init"),
+  this);
+}
+
+static bool isFullyUndesignated(const InitListExpr *SyntacticInitList) {
+  return std::all_of(
+  SyntacticInitList->begin(), SyntacticInitList->end(),
+  [](auto *InitExpr) { return !isa(InitExpr); });
+}
+
+void UseDesignatedInitializersCheck::check(
+const MatchFinder::MatchResult ) {
+  const auto *InitList = Result.Nodes.getNodeAs("init");
+  const auto *Type = Result.Nodes.getNodeAs("type");
+  if (!Type || !InitList)
+return;
+  if (const auto *SyntacticInitList = InitList->getSyntacticForm()) {
+const llvm::DenseMap Designators =
+clang::tooling::getUnwrittenDesignators(SyntacticInitList);
+if (isFullyUndesignated(SyntacticInitList)) {
+  if (IgnoreMacros && InitList->getBeginLoc().isMacroID()) {
+return;
+  }
+  DiagnosticBuilder Diag =
+  

[clang] [clang-tools-extra] [clang-tidy] Add new check `modernize-use-designated-initializers` (PR #80541)

2024-02-14 Thread Piotr Zegar via cfe-commits
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= 
Message-ID:
In-Reply-To: 



@@ -0,0 +1,127 @@
+//===--- UseDesignatedInitializersCheck.cpp - clang-tidy 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "UseDesignatedInitializersCheck.h"
+#include "clang/AST/APValue.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/Expr.h"
+#include "clang/AST/Stmt.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/ASTMatchers/ASTMatchersMacros.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Lex/Lexer.h"
+#include "clang/Tooling/DesignatedInitializers.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::modernize {
+
+static const char *IgnoreSingleElementAggregatesName =
+"IgnoreSingleElementAggregates";
+static const bool IgnoreSingleElementAggregatesDefault = true;
+
+static const char *RestrictToPODTypesName = "RestrictToPODTypes";
+static const bool RestrictToPODTypesDefault = false;
+
+UseDesignatedInitializersCheck::UseDesignatedInitializersCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context), IgnoreSingleElementAggregates(Options.get(
+ IgnoreSingleElementAggregatesName,
+ 
IgnoreSingleElementAggregatesDefault)),
+  RestrictToPODTypes(
+  Options.get(RestrictToPODTypesName, RestrictToPODTypesDefault)) {}
+
+namespace {
+
+AST_MATCHER(CXXRecordDecl, isAggregate) { return Node.isAggregate(); }
+
+AST_MATCHER(CXXRecordDecl, isPOD) { return Node.isPOD(); }
+
+AST_MATCHER(InitListExpr, isFullyDesignated) {
+  const InitListExpr *SyntacticForm =
+  Node.isSyntacticForm() ?  : Node.getSyntacticForm();
+  return std::all_of(
+  SyntacticForm->begin(), SyntacticForm->end(),
+  [](auto *InitExpr) { return isa(InitExpr); });
+}
+
+AST_MATCHER(InitListExpr, hasSingleElement) { return Node.getNumInits() == 1; }
+
+AST_MATCHER_FUNCTION(::internal::Matcher, hasBaseWithFields) {
+  return hasAnyBase(hasType(cxxRecordDecl(has(fieldDecl();
+}
+
+AST_MATCHER(FieldDecl, isAnonymousDecl) {
+  if (const auto *Record =
+  Node.getType().getCanonicalType()->getAsRecordDecl()) {
+return Record->isAnonymousStructOrUnion() || !Record->getIdentifier();
+  }
+  return false;
+}
+
+} // namespace
+
+void UseDesignatedInitializersCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  initListExpr(
+  hasType(cxxRecordDecl(RestrictToPODTypes ? isPOD() : isAggregate(),
+unless(hasBaseWithFields()),
+unless(has(fieldDecl(isAnonymousDecl()
+  .bind("type")),
+  unless(IgnoreSingleElementAggregates ? hasSingleElement()

PiotrZSL wrote:

`initListExpr(IgnoreSingleElementAggregates ? hasSingleElement() : anything())` 
or
`IgnoreSingleElementAggregates ? initListExpr(hasSingleElement()) : 
initListExpr()` 
you can also use local variable

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


[clang] [clang-tools-extra] [clang-tidy] Add new check `modernize-use-designated-initializers` (PR #80541)

2024-02-14 Thread Piotr Zegar via cfe-commits
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= 
Message-ID:
In-Reply-To: 



@@ -0,0 +1,132 @@
+//===--- UseDesignatedInitializersCheck.cpp - clang-tidy 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "UseDesignatedInitializersCheck.h"
+#include "clang/AST/APValue.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/Expr.h"
+#include "clang/AST/Stmt.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/ASTMatchers/ASTMatchersMacros.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Lex/Lexer.h"
+#include "clang/Tooling/DesignatedInitializers.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::modernize {
+
+static constexpr char IgnoreSingleElementAggregatesName[] =
+"IgnoreSingleElementAggregates";
+static constexpr bool IgnoreSingleElementAggregatesDefault = true;
+
+static constexpr char RestrictToPODTypesName[] = "RestrictToPODTypes";
+static constexpr bool RestrictToPODTypesDefault = false;
+
+static constexpr char IgnoreMacrosName[] = "IgnoreMacros";
+static constexpr bool IgnoreMacrosDefault = true;
+
+namespace {
+
+AST_MATCHER(CXXRecordDecl, isAggregate) { return Node.isAggregate(); }
+
+AST_MATCHER(CXXRecordDecl, isPOD) { return Node.isPOD(); }
+
+AST_MATCHER(InitListExpr, isFullyDesignated) {
+  if (const InitListExpr *SyntacticForm =
+  Node.isSyntacticForm() ?  : Node.getSyntacticForm()) {
+return llvm::all_of(SyntacticForm->children(), [](auto *InitExpr) {
+  return isa(InitExpr);
+});
+  }
+  return true;
+}
+
+AST_MATCHER(InitListExpr, hasSingleElement) { return Node.getNumInits() == 1; }
+
+} // namespace
+
+UseDesignatedInitializersCheck::UseDesignatedInitializersCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context), IgnoreSingleElementAggregates(Options.get(
+ IgnoreSingleElementAggregatesName,
+ 
IgnoreSingleElementAggregatesDefault)),
+  RestrictToPODTypes(
+  Options.get(RestrictToPODTypesName, RestrictToPODTypesDefault)),
+  IgnoreMacros(Options.get(IgnoreMacrosName, IgnoreMacrosDefault)) {}
+
+void UseDesignatedInitializersCheck::registerMatchers(MatchFinder *Finder) {
+  const auto HasBaseWithFields =
+  hasAnyBase(hasType(cxxRecordDecl(has(fieldDecl();
+  Finder->addMatcher(
+  initListExpr(
+  hasType(cxxRecordDecl(RestrictToPODTypes ? isPOD() : isAggregate(),
+unless(HasBaseWithFields))
+  .bind("type")),
+  unless(IgnoreSingleElementAggregates ? hasSingleElement()
+   : unless(anything())),
+  unless(isFullyDesignated()))
+  .bind("init"),
+  this);
+}
+
+static bool isFullyUndesignated(const InitListExpr *SyntacticInitList) {
+  return std::all_of(
+  SyntacticInitList->begin(), SyntacticInitList->end(),
+  [](auto *InitExpr) { return !isa(InitExpr); });
+}
+
+void UseDesignatedInitializersCheck::check(
+const MatchFinder::MatchResult ) {
+  const auto *InitList = Result.Nodes.getNodeAs("init");
+  const auto *Type = Result.Nodes.getNodeAs("type");
+  if (!Type || !InitList)
+return;
+  if (const auto *SyntacticInitList = InitList->getSyntacticForm()) {
+const llvm::DenseMap Designators =
+clang::tooling::getUnwrittenDesignators(SyntacticInitList);
+if (isFullyUndesignated(SyntacticInitList)) {
+  if (IgnoreMacros && InitList->getBeginLoc().isMacroID()) {
+return;
+  }
+  DiagnosticBuilder Diag =
+  

[clang] [clang-tools-extra] [clang-tidy] Add new check `modernize-use-designated-initializers` (PR #80541)

2024-02-14 Thread Piotr Zegar via cfe-commits
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= 
Message-ID:
In-Reply-To: 



@@ -0,0 +1,132 @@
+//===--- UseDesignatedInitializersCheck.cpp - clang-tidy 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "UseDesignatedInitializersCheck.h"
+#include "clang/AST/APValue.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/Expr.h"
+#include "clang/AST/Stmt.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/ASTMatchers/ASTMatchersMacros.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Lex/Lexer.h"
+#include "clang/Tooling/DesignatedInitializers.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::modernize {
+
+static constexpr char IgnoreSingleElementAggregatesName[] =
+"IgnoreSingleElementAggregates";
+static constexpr bool IgnoreSingleElementAggregatesDefault = true;
+
+static constexpr char RestrictToPODTypesName[] = "RestrictToPODTypes";
+static constexpr bool RestrictToPODTypesDefault = false;
+
+static constexpr char IgnoreMacrosName[] = "IgnoreMacros";
+static constexpr bool IgnoreMacrosDefault = true;
+
+namespace {
+
+AST_MATCHER(CXXRecordDecl, isAggregate) { return Node.isAggregate(); }
+
+AST_MATCHER(CXXRecordDecl, isPOD) { return Node.isPOD(); }
+
+AST_MATCHER(InitListExpr, isFullyDesignated) {
+  if (const InitListExpr *SyntacticForm =
+  Node.isSyntacticForm() ?  : Node.getSyntacticForm()) {
+return llvm::all_of(SyntacticForm->children(), [](auto *InitExpr) {
+  return isa(InitExpr);
+});
+  }
+  return true;
+}
+
+AST_MATCHER(InitListExpr, hasSingleElement) { return Node.getNumInits() == 1; }
+
+} // namespace
+
+UseDesignatedInitializersCheck::UseDesignatedInitializersCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context), IgnoreSingleElementAggregates(Options.get(
+ IgnoreSingleElementAggregatesName,
+ 
IgnoreSingleElementAggregatesDefault)),
+  RestrictToPODTypes(
+  Options.get(RestrictToPODTypesName, RestrictToPODTypesDefault)),
+  IgnoreMacros(Options.get(IgnoreMacrosName, IgnoreMacrosDefault)) {}
+
+void UseDesignatedInitializersCheck::registerMatchers(MatchFinder *Finder) {
+  const auto HasBaseWithFields =
+  hasAnyBase(hasType(cxxRecordDecl(has(fieldDecl();
+  Finder->addMatcher(
+  initListExpr(
+  hasType(cxxRecordDecl(RestrictToPODTypes ? isPOD() : isAggregate(),
+unless(HasBaseWithFields))
+  .bind("type")),
+  unless(IgnoreSingleElementAggregates ? hasSingleElement()
+   : unless(anything())),
+  unless(isFullyDesignated()))
+  .bind("init"),
+  this);
+}
+
+static bool isFullyUndesignated(const InitListExpr *SyntacticInitList) {
+  return std::all_of(
+  SyntacticInitList->begin(), SyntacticInitList->end(),
+  [](auto *InitExpr) { return !isa(InitExpr); });
+}
+
+void UseDesignatedInitializersCheck::check(
+const MatchFinder::MatchResult ) {
+  const auto *InitList = Result.Nodes.getNodeAs("init");
+  const auto *Type = Result.Nodes.getNodeAs("type");
+  if (!Type || !InitList)
+return;
+  if (const auto *SyntacticInitList = InitList->getSyntacticForm()) {
+const llvm::DenseMap Designators =
+clang::tooling::getUnwrittenDesignators(SyntacticInitList);

PiotrZSL wrote:

verify that size of Designators is in sync with SyntacticInitList, at least 
size, to avoid crashes later.


[clang] [clang-tools-extra] [clang-tidy] Add new check `modernize-use-designated-initializers` (PR #80541)

2024-02-14 Thread Piotr Zegar via cfe-commits
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= 
Message-ID:
In-Reply-To: 



@@ -0,0 +1,132 @@
+//===--- UseDesignatedInitializersCheck.cpp - clang-tidy 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "UseDesignatedInitializersCheck.h"
+#include "clang/AST/APValue.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/Expr.h"
+#include "clang/AST/Stmt.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/ASTMatchers/ASTMatchersMacros.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Lex/Lexer.h"
+#include "clang/Tooling/DesignatedInitializers.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::modernize {
+
+static constexpr char IgnoreSingleElementAggregatesName[] =
+"IgnoreSingleElementAggregates";
+static constexpr bool IgnoreSingleElementAggregatesDefault = true;
+
+static constexpr char RestrictToPODTypesName[] = "RestrictToPODTypes";
+static constexpr bool RestrictToPODTypesDefault = false;
+
+static constexpr char IgnoreMacrosName[] = "IgnoreMacros";
+static constexpr bool IgnoreMacrosDefault = true;
+
+namespace {
+
+AST_MATCHER(CXXRecordDecl, isAggregate) { return Node.isAggregate(); }
+
+AST_MATCHER(CXXRecordDecl, isPOD) { return Node.isPOD(); }
+
+AST_MATCHER(InitListExpr, isFullyDesignated) {
+  if (const InitListExpr *SyntacticForm =
+  Node.isSyntacticForm() ?  : Node.getSyntacticForm()) {
+return llvm::all_of(SyntacticForm->children(), [](auto *InitExpr) {
+  return isa(InitExpr);
+});
+  }
+  return true;
+}
+
+AST_MATCHER(InitListExpr, hasSingleElement) { return Node.getNumInits() == 1; }
+
+} // namespace
+
+UseDesignatedInitializersCheck::UseDesignatedInitializersCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context), IgnoreSingleElementAggregates(Options.get(
+ IgnoreSingleElementAggregatesName,
+ 
IgnoreSingleElementAggregatesDefault)),
+  RestrictToPODTypes(
+  Options.get(RestrictToPODTypesName, RestrictToPODTypesDefault)),
+  IgnoreMacros(Options.get(IgnoreMacrosName, IgnoreMacrosDefault)) {}
+
+void UseDesignatedInitializersCheck::registerMatchers(MatchFinder *Finder) {
+  const auto HasBaseWithFields =
+  hasAnyBase(hasType(cxxRecordDecl(has(fieldDecl();
+  Finder->addMatcher(
+  initListExpr(
+  hasType(cxxRecordDecl(RestrictToPODTypes ? isPOD() : isAggregate(),
+unless(HasBaseWithFields))
+  .bind("type")),
+  unless(IgnoreSingleElementAggregates ? hasSingleElement()
+   : unless(anything())),
+  unless(isFullyDesignated()))
+  .bind("init"),
+  this);
+}
+
+static bool isFullyUndesignated(const InitListExpr *SyntacticInitList) {
+  return std::all_of(
+  SyntacticInitList->begin(), SyntacticInitList->end(),
+  [](auto *InitExpr) { return !isa(InitExpr); });
+}
+
+void UseDesignatedInitializersCheck::check(
+const MatchFinder::MatchResult ) {
+  const auto *InitList = Result.Nodes.getNodeAs("init");
+  const auto *Type = Result.Nodes.getNodeAs("type");
+  if (!Type || !InitList)
+return;
+  if (const auto *SyntacticInitList = InitList->getSyntacticForm()) {
+const llvm::DenseMap Designators =
+clang::tooling::getUnwrittenDesignators(SyntacticInitList);

PiotrZSL wrote:

call to getUnwrittenDesignators can be heavy, llvm::DenseMap isn't cheap to 
create.
Delay call to this function as long as possible.
Maybe consider 

[clang] [clang-tools-extra] [clang-tidy] Add new check `modernize-use-designated-initializers` (PR #80541)

2024-02-14 Thread Piotr Zegar via cfe-commits
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= ,
Danny =?utf-8?q?M=C3=B6sch?= 
Message-ID:
In-Reply-To: 


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

Overall looking fine.
Diagnostic could be still improved.

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


[clang] [clang-tools-extra] [clang-tidy] Add new check `modernize-use-designated-initializers` (PR #80541)

2024-02-14 Thread Piotr Zegar via cfe-commits
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= 
Message-ID:
In-Reply-To: 


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


[clang] [clang-tools-extra] [clang-tidy] Add new check `modernize-use-designated-initializers` (PR #80541)

2024-02-14 Thread Danny Mösch via cfe-commits


@@ -0,0 +1,127 @@
+//===--- UseDesignatedInitializersCheck.cpp - clang-tidy 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "UseDesignatedInitializersCheck.h"
+#include "clang/AST/APValue.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/Expr.h"
+#include "clang/AST/Stmt.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/ASTMatchers/ASTMatchersMacros.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Lex/Lexer.h"
+#include "clang/Tooling/DesignatedInitializers.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::modernize {
+
+static const char *IgnoreSingleElementAggregatesName =
+"IgnoreSingleElementAggregates";
+static const bool IgnoreSingleElementAggregatesDefault = true;
+
+static const char *RestrictToPODTypesName = "RestrictToPODTypes";
+static const bool RestrictToPODTypesDefault = false;
+
+UseDesignatedInitializersCheck::UseDesignatedInitializersCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context), IgnoreSingleElementAggregates(Options.get(
+ IgnoreSingleElementAggregatesName,
+ 
IgnoreSingleElementAggregatesDefault)),
+  RestrictToPODTypes(
+  Options.get(RestrictToPODTypesName, RestrictToPODTypesDefault)) {}
+
+namespace {
+
+AST_MATCHER(CXXRecordDecl, isAggregate) { return Node.isAggregate(); }
+
+AST_MATCHER(CXXRecordDecl, isPOD) { return Node.isPOD(); }
+
+AST_MATCHER(InitListExpr, isFullyDesignated) {
+  const InitListExpr *SyntacticForm =
+  Node.isSyntacticForm() ?  : Node.getSyntacticForm();
+  return std::all_of(
+  SyntacticForm->begin(), SyntacticForm->end(),
+  [](auto *InitExpr) { return isa(InitExpr); });
+}
+
+AST_MATCHER(InitListExpr, hasSingleElement) { return Node.getNumInits() == 1; }
+
+AST_MATCHER_FUNCTION(::internal::Matcher, hasBaseWithFields) {
+  return hasAnyBase(hasType(cxxRecordDecl(has(fieldDecl();
+}
+
+AST_MATCHER(FieldDecl, isAnonymousDecl) {
+  if (const auto *Record =
+  Node.getType().getCanonicalType()->getAsRecordDecl()) {
+return Record->isAnonymousStructOrUnion() || !Record->getIdentifier();
+  }
+  return false;
+}
+
+} // namespace
+
+void UseDesignatedInitializersCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  initListExpr(
+  hasType(cxxRecordDecl(RestrictToPODTypes ? isPOD() : isAggregate(),

SimplyDanny wrote:

So effectively

```c++
cxxRecordDecl(
RestrictToPODTypes ? isPOD() : isAggregate(),
...
)
```

would become:

```c++
cxxRecordDecl(
isAggregate(),
RestrictToPODTypes ? isPOD() : anything(),
...
)
```

Doesn't look like a huge difference.

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


[clang-tools-extra] [llvm] Add bazel support for clangd as a library. (PR #81556)

2024-02-14 Thread via cfe-commits

josh11b wrote:

I've made my email address public, as requested.

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


[clang] [clang-tools-extra] [clang-tidy] Add new check `modernize-use-designated-initializers` (PR #80541)

2024-02-14 Thread Piotr Zegar via cfe-commits
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= 
Message-ID:
In-Reply-To: 



@@ -0,0 +1,127 @@
+//===--- UseDesignatedInitializersCheck.cpp - clang-tidy 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "UseDesignatedInitializersCheck.h"
+#include "clang/AST/APValue.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/Expr.h"
+#include "clang/AST/Stmt.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/ASTMatchers/ASTMatchersMacros.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Lex/Lexer.h"
+#include "clang/Tooling/DesignatedInitializers.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::modernize {
+
+static const char *IgnoreSingleElementAggregatesName =
+"IgnoreSingleElementAggregates";
+static const bool IgnoreSingleElementAggregatesDefault = true;
+
+static const char *RestrictToPODTypesName = "RestrictToPODTypes";
+static const bool RestrictToPODTypesDefault = false;
+
+UseDesignatedInitializersCheck::UseDesignatedInitializersCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context), IgnoreSingleElementAggregates(Options.get(
+ IgnoreSingleElementAggregatesName,
+ 
IgnoreSingleElementAggregatesDefault)),
+  RestrictToPODTypes(
+  Options.get(RestrictToPODTypesName, RestrictToPODTypesDefault)) {}
+
+namespace {
+
+AST_MATCHER(CXXRecordDecl, isAggregate) { return Node.isAggregate(); }
+
+AST_MATCHER(CXXRecordDecl, isPOD) { return Node.isPOD(); }
+
+AST_MATCHER(InitListExpr, isFullyDesignated) {
+  const InitListExpr *SyntacticForm =
+  Node.isSyntacticForm() ?  : Node.getSyntacticForm();
+  return std::all_of(
+  SyntacticForm->begin(), SyntacticForm->end(),
+  [](auto *InitExpr) { return isa(InitExpr); });
+}
+
+AST_MATCHER(InitListExpr, hasSingleElement) { return Node.getNumInits() == 1; }
+
+AST_MATCHER_FUNCTION(::internal::Matcher, hasBaseWithFields) {
+  return hasAnyBase(hasType(cxxRecordDecl(has(fieldDecl();
+}
+
+AST_MATCHER(FieldDecl, isAnonymousDecl) {
+  if (const auto *Record =
+  Node.getType().getCanonicalType()->getAsRecordDecl()) {
+return Record->isAnonymousStructOrUnion() || !Record->getIdentifier();
+  }
+  return false;
+}
+
+} // namespace
+
+void UseDesignatedInitializersCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  initListExpr(
+  hasType(cxxRecordDecl(RestrictToPODTypes ? isPOD() : isAggregate(),

PiotrZSL wrote:

cxxRecordDecl(RestrictToPODTypes ? isPOD() : anything()))

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


[clang] [clang-tools-extra] [clang-tidy] Add new check `modernize-use-designated-initializers` (PR #80541)

2024-02-14 Thread Julian Schmidt via cfe-commits
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= 
Message-ID:
In-Reply-To: 


5chmidti wrote:

You can stream the `InitExpr->getSourceRange()` into the diagnostics, which 
would highlight the specific expression that needs a designated initializer.
E.g.:
```
use-designated-initializers.cpp.tmp.cpp:33:17: warning: use designated init 
expression [modernize-use-designated-initializers]
   33 | S2 s25 = {.i=1, 200};
  | ^~~
  | .j=
```
instead of 
```
use-designated-initializers.cpp.tmp.cpp:33:17: warning: use designated init 
expression [modernize-use-designated-initializers]
   33 | S2 s25 = {.i=1, 200};
  | ^
  | .j=
```

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


[clang] [clang-tools-extra] [clang-tidy] Add new check `modernize-use-designated-initializers` (PR #80541)

2024-02-14 Thread Danny Mösch via cfe-commits


@@ -0,0 +1,130 @@
+// RUN: %check_clang_tidy -std=c++17 %s modernize-use-designated-initializers 
%t
+// RUN: %check_clang_tidy -check-suffixes=,SINGLE-ELEMENT -std=c++17 %s 
modernize-use-designated-initializers %t \
+// RUN: -- -config="{CheckOptions: [{key: 
modernize-use-designated-initializers.IgnoreSingleElementAggregates, value: 
false}]}" \
+// RUN: --
+// RUN: %check_clang_tidy -check-suffixes=POD -std=c++17 %s 
modernize-use-designated-initializers %t \
+// RUN: -- -config="{CheckOptions: [{key: 
modernize-use-designated-initializers.RestrictToPODTypes, value: true}]}" \
+// RUN: --
+
+struct S1 {};
+

SimplyDanny wrote:

Added option with two tests. It's very strict though. As soon as an element in 
a list stems from a macro, it will be ignored. Not sure how to check whether a 
macro describes a whole expression or list element, because these cases would 
be fine, e.g.

```c++
#define A (3+2)
#define B .j=1

S s {A, B};
```

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


[clang-tools-extra] [include-cleaner] don't consider the associated header unused (PR #67228)

2024-02-14 Thread Vadim D. via cfe-commits


@@ -227,6 +230,7 @@ class PragmaIncludes::RecordPragma : public PPCallbacks, 
public CommentHandler {
   IncludedHeader = *File;
 checkForExport(HashFID, HashLine, std::move(IncludedHeader), File);

vvd170501 wrote:

`std::move` should be removed, because `IncludedHeader` is now also used for 
`checkForDeducedAssociated`.

Current implementation of `clang::include_cleaner::Header` is trivially 
movable, so `IncludedHeader` is unchanged, but it's safer to not rely on this 
fact.

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


[clang] [clang] Allow builtin addc/subc to be constant evaluated (PR #81656)

2024-02-14 Thread Thorsten Schütt via cfe-commits

tschuett wrote:

The bigger issue is that it needs a test. Unfortunately, I am less familiar 
with the Clang test infrastructure.

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


[clang] [compiler-rt] [Sanitizer] add signed-integer-wrap sanitizer (PR #80089)

2024-02-14 Thread Vitaly Buka via cfe-commits

vitalybuka wrote:

> `signed-integer-overflow`

Or maybe I am missing the bigger picture? Is there a plan fix 
signed-integer-overflow for -fwrapv as well?


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


[clang] [llvm] [transforms] Inline simple variadic functions (PR #81058)

2024-02-14 Thread Eli Friedman via cfe-commits

efriedma-quic wrote:

> > I don't really like the whole "sufficiently simple function" thing. It 
> > seems fragile. You should be able to just take a arbitrary internal varargs 
> > function, rewrite its signature to take a va_list argument, rewrite calls 
> > to va_start to make a copy of that va_list, and rewrite the callers to 
> > construct that va_list. If that function turns out to be inlinable, great; 
> > if not, you haven't really lost anything.
> 
> Yes, you can and I do. That's patch 2 of the series, numbered 1. in the list 
> in the commit message (for this is 0)

Not sure if this means isFunctionInlinable will go away in the followup patch, 
or if you plan to rewrite functions in a way that satisfies 
isFunctionInlinable.  I think the end state should be that all functions go 
down the same codepath, not conditionally do something different based on 
whether they're "simple".  I guess I don't have a strong preference for how you 
get there, though.

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


[clang] [compiler-rt] [Sanitizer] add signed-integer-wrap sanitizer (PR #80089)

2024-02-14 Thread Vitaly Buka via cfe-commits

vitalybuka wrote:

> > > Why not just enforce -fsanitize=signed-integer-overflow with -fwrapv? I 
> > > suspect it's just overlook, and not intentional behavior.
> > 
> > 
> > +1
> > We should consider this direction
> 
> The UB-vs-non-UB seemed to be a really specific goal in the existing code. 
> i.e. that the sanitizer was disabled didn't look like an accident. For people 
> using this to find _only_ UB, this would be a behavioral change, so to me it 
> seems like a separate name makes the most sense. Anyone wanting wrap-around 
> checking can use -wrap, and anyone wanting UB checking can use -overflow.

Isn't this still UB even with -fwrapv? UB is a language feature, not compiler.

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


[clang] [llvm] [AIX] support builtin_cpu_is() for aix (PR #80069)

2024-02-14 Thread Lei Huang via cfe-commits

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


[clang] [llvm] [AIX] support builtin_cpu_is() for aix (PR #80069)

2024-02-14 Thread Amy Kwan via cfe-commits


@@ -126,4 +126,53 @@ PPC_LNX_CPU("power10",47)
 #undef PPC_LNX_DEFINE_OFFSETS
 #undef PPC_LNX_FEATURE
 #undef PPC_LNX_CPU
+
+// Definition of the following values are found in the AIX header file: 
.
+#ifndef AIX_POWERPC_SYS_CONF
+#define AIX_POWERPC_SYS_CONF
+  #define AIX_SYSCON_IMPL_IDX 1
+  #define AIX_PPC7_VALUE 0x8000
+  #define AIX_PPC8_VALUE 0x0001
+  #define AIX_PPC9_VALUE 0x0002
+  #define AIX_PPC10_VALUE 0x0004
+
+  #define AIX_BUILTIN_PPC_TRUE 1
+  #define AIX_BUILTIN_PPC_FALSE 0
+  #define SYS_CONF 2

amy-kwan wrote:

```suggestion
  #define USE_SYS_CONF 2
```
Might be more clear this way.

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


[clang] [llvm] [AIX] support builtin_cpu_is() for aix (PR #80069)

2024-02-14 Thread Amy Kwan via cfe-commits


@@ -904,8 +904,18 @@ bool PPCTargetInfo::validateCpuSupports(StringRef 
FeatureStr) const {
 }
 
 bool PPCTargetInfo::validateCpuIs(StringRef CPUName) const {
+  llvm::Triple Triple = getTriple();

amy-kwan wrote:

Check clang-format for indentation.

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


[clang] [llvm] [AIX] support builtin_cpu_is() for aix (PR #80069)

2024-02-14 Thread Amy Kwan via cfe-commits


@@ -126,4 +126,53 @@ PPC_LNX_CPU("power10",47)
 #undef PPC_LNX_DEFINE_OFFSETS
 #undef PPC_LNX_FEATURE
 #undef PPC_LNX_CPU
+
+// Definition of the following values are found in the AIX header file: 
.
+#ifndef AIX_POWERPC_SYS_CONF
+#define AIX_POWERPC_SYS_CONF
+  #define AIX_SYSCON_IMPL_IDX 1
+  #define AIX_PPC7_VALUE 0x8000
+  #define AIX_PPC8_VALUE 0x0001
+  #define AIX_PPC9_VALUE 0x0002
+  #define AIX_PPC10_VALUE 0x0004
+
+  #define AIX_BUILTIN_PPC_TRUE 1
+  #define AIX_BUILTIN_PPC_FALSE 0
+  #define SYS_CONF 2
+
+  #define COMP_EQ  0
+
+#endif
+
+// When the value of SUPPORT_MAGIC is SYS_CONF, the return value depends on 
the 
+// _system_configuration[INDEX] COMPARE_OP VALUE.
+#ifndef PPC_AIX_CPU
+  #define PPC_AIX_CPU(NAME, SUPPORT_MAGIC, INDEX, COMPARE_OP, VALUE)
+#endif
+
+// __builtin_cpu_is() is supported only on Power7 and up.
+PPC_AIX_CPU("power4",AIX_BUILTIN_PPC_FALSE,0,0,0)
+PPC_AIX_CPU("ppc970",AIX_BUILTIN_PPC_FALSE,0,0,0)
+PPC_AIX_CPU("power5",AIX_BUILTIN_PPC_FALSE,0,0,0)
+PPC_AIX_CPU("power5+",AIX_BUILTIN_PPC_FALSE,0,0,0)
+PPC_AIX_CPU("power6",AIX_BUILTIN_PPC_FALSE,0,0,0)
+PPC_AIX_CPU("ppc-cell-be",AIX_BUILTIN_PPC_FALSE,0,0,0)
+PPC_AIX_CPU("power6x",AIX_BUILTIN_PPC_FALSE,0,0,0)
+PPC_AIX_CPU("power7",SYS_CONF,AIX_SYSCON_IMPL_IDX,COMP_EQ,AIX_PPC7_VALUE)
+PPC_AIX_CPU("ppca2",AIX_BUILTIN_PPC_FALSE,0,0,0)
+PPC_AIX_CPU("ppc405",AIX_BUILTIN_PPC_FALSE,0,0,0)
+PPC_AIX_CPU("ppc440",AIX_BUILTIN_PPC_FALSE,0,0,0)
+PPC_AIX_CPU("ppc464",AIX_BUILTIN_PPC_FALSE,0,0,0)
+PPC_AIX_CPU("ppc476",AIX_BUILTIN_PPC_FALSE,0,0,0)
+PPC_AIX_CPU("power8",SYS_CONF,AIX_SYSCON_IMPL_IDX,COMP_EQ,AIX_PPC8_VALUE)
+PPC_AIX_CPU("power9",SYS_CONF,AIX_SYSCON_IMPL_IDX,COMP_EQ,AIX_PPC9_VALUE)
+PPC_AIX_CPU("power10",SYS_CONF,AIX_SYSCON_IMPL_IDX,COMP_EQ,AIX_PPC10_VALUE)
+#undef PPC_AIX_CPU
+
+#ifndef PPC_SYSTEMCONFIG_TYPE

amy-kwan wrote:

Add a comment as to what `PPC_SYSTEMCONFIG_TYPE` is for. 

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


[clang] [llvm] [AIX] support builtin_cpu_is() for aix (PR #80069)

2024-02-14 Thread Amy Kwan via cfe-commits


@@ -126,4 +126,53 @@ PPC_LNX_CPU("power10",47)
 #undef PPC_LNX_DEFINE_OFFSETS
 #undef PPC_LNX_FEATURE
 #undef PPC_LNX_CPU
+
+// Definition of the following values are found in the AIX header file: 
.
+#ifndef AIX_POWERPC_SYS_CONF
+#define AIX_POWERPC_SYS_CONF
+  #define AIX_SYSCON_IMPL_IDX 1
+  #define AIX_PPC7_VALUE 0x8000
+  #define AIX_PPC8_VALUE 0x0001
+  #define AIX_PPC9_VALUE 0x0002
+  #define AIX_PPC10_VALUE 0x0004
+
+  #define AIX_BUILTIN_PPC_TRUE 1
+  #define AIX_BUILTIN_PPC_FALSE 0
+  #define SYS_CONF 2
+
+  #define COMP_EQ  0
+
+#endif
+
+// When the value of SUPPORT_MAGIC is SYS_CONF, the return value depends on 
the 
+// _system_configuration[INDEX] COMPARE_OP VALUE.

amy-kwan wrote:

This comment may not make sense here. However, if we do put a comment here, 
this comment should be clarified, since the comment should describe the intent 
behind the code.

- We should change the `COMPARE_OP` to be more explicit to show the possible 
comparison operations.
- We should not be using `_system_configuration[INDEX]`, since this doesn't 
seem to be described in this change.
- Where is SUPPORT_MAGIC defined?


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


[clang] [llvm] [AIX] support builtin_cpu_is() for aix (PR #80069)

2024-02-14 Thread Amy Kwan via cfe-commits


@@ -126,4 +126,53 @@ PPC_LNX_CPU("power10",47)
 #undef PPC_LNX_DEFINE_OFFSETS
 #undef PPC_LNX_FEATURE
 #undef PPC_LNX_CPU
+
+// Definition of the following values are found in the AIX header file: 
.
+#ifndef AIX_POWERPC_SYS_CONF
+#define AIX_POWERPC_SYS_CONF
+  #define AIX_SYSCON_IMPL_IDX 1
+  #define AIX_PPC7_VALUE 0x8000
+  #define AIX_PPC8_VALUE 0x0001
+  #define AIX_PPC9_VALUE 0x0002
+  #define AIX_PPC10_VALUE 0x0004
+
+  #define AIX_BUILTIN_PPC_TRUE 1
+  #define AIX_BUILTIN_PPC_FALSE 0
+  #define SYS_CONF 2
+
+  #define COMP_EQ  0
+
+#endif
+
+// When the value of SUPPORT_MAGIC is SYS_CONF, the return value depends on 
the 
+// _system_configuration[INDEX] COMPARE_OP VALUE.
+#ifndef PPC_AIX_CPU
+  #define PPC_AIX_CPU(NAME, SUPPORT_MAGIC, INDEX, COMPARE_OP, VALUE)

amy-kwan wrote:

Change we update this to the following, since it may be more clear?
```
#define PPC_AIX_CPU(NAME, SUPPORT_METHOD, SYS_CFG_INDEX, COMPARE_OP, 
SYS_CFG_VALUE)
```

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


[clang] [llvm] [AIX] support builtin_cpu_is() for aix (PR #80069)

2024-02-14 Thread Amy Kwan via cfe-commits


@@ -16542,12 +16542,64 @@ Value *CodeGenFunction::EmitPPCBuiltinExpr(unsigned 
BuiltinID,
 
   Intrinsic::ID ID = Intrinsic::not_intrinsic;
 
+  // The lambda function converts builtin_cpu_is function into directly
+  // returning false or true, or it gets and checks the information from the
+  // kernel variable _system_configuration for AIX OS.
+
+#include "llvm/TargetParser/PPCTargetParser.def"
+  auto ConvBuiltinCpu = [&](unsigned SupportMagic, unsigned FieldIdx,
+unsigned CompOp, unsigned OpValue) -> Value * {
+if (SupportMagic == AIX_BUILTIN_PPC_FALSE)
+  return llvm::ConstantInt::getFalse(ConvertType(E->getType()));
+
+if (SupportMagic == AIX_BUILTIN_PPC_TRUE)
+  return llvm::ConstantInt::getTrue(ConvertType(E->getType()));
+
+assert(SupportMagic <= SYS_CONF && "Invalid value for SupportMagic.");
+llvm::Type *STy = llvm::StructType::get(PPC_SYSTEMCONFIG_TYPE);
+
+llvm::Constant *SysConf =
+CGM.CreateRuntimeVariable(STy, "_system_configuration");
+
+// Grab the appropriate field from _system_configuration.
+llvm::Value *Idxs[] = {ConstantInt::get(Int32Ty, 0),
+   ConstantInt::get(Int32Ty, FieldIdx)};
+
+llvm::Value *FieldValue = Builder.CreateGEP(STy, SysConf, Idxs);
+FieldValue = Builder.CreateAlignedLoad(Int32Ty, FieldValue,
+   CharUnits::fromQuantity(4));
+
+assert((CompOp == COMP_EQ) && "Only equal comparisons are supported!");
+
+assert(FieldValue->getType()->isIntegerTy(32) &&
+   "Only supports 32-bit integer in the GetOpRes.");
+
+return Builder.CreateICmp(ICmpInst::ICMP_EQ, FieldValue,
+  ConstantInt::get(Int32Ty, OpValue));
+  };
+
   switch (BuiltinID) {
   default: return nullptr;
 
   case Builtin::BI__builtin_cpu_is: {
 const Expr *CPUExpr = E->getArg(0)->IgnoreParenCasts();
 StringRef CPUStr = cast(CPUExpr)->getString();
+llvm::Triple Triple = getTarget().getTriple();
+
+if (Triple.isOSAIX()) {
+  unsigned IsCpuSupport, FieldIdx, CompareOp, CpuIdValue;
+  typedef std::tuple CPUType;
+  std::tie(IsCpuSupport, FieldIdx, CompareOp, CpuIdValue) =
+  static_cast(StringSwitch(CPUStr)
+#define PPC_AIX_CPU(NAME, SUPPORT_MAGIC, INDEX, COMPARE_OP, VALUE) 
\
+  .Case(NAME, {SUPPORT_MAGIC, INDEX, COMPARE_OP, VALUE})
+#include "llvm/TargetParser/PPCTargetParser.def"
+  );
+  return ConvBuiltinCpu(IsCpuSupport, FieldIdx, CompareOp, CpuIdValue);
+}
+
+assert(Triple.isOSLinux() && "Triple for AIX OS has already been checked; "
+ "it must be Linux OS here.");

amy-kwan wrote:

Comment should be updated to something like:
```
__builtin_cpu_is() is only supported for AIX and Linux.
```
For here and on line 915 on `PPC.cpp`.


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


[clang] [llvm] [AIX] support builtin_cpu_is() for aix (PR #80069)

2024-02-14 Thread Amy Kwan via cfe-commits


@@ -126,4 +126,53 @@ PPC_LNX_CPU("power10",47)
 #undef PPC_LNX_DEFINE_OFFSETS
 #undef PPC_LNX_FEATURE
 #undef PPC_LNX_CPU
+
+// Definition of the following values are found in the AIX header file: 
.
+#ifndef AIX_POWERPC_SYS_CONF
+#define AIX_POWERPC_SYS_CONF

amy-kwan wrote:

Can we be consistent for the indenting here?

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


[clang] [llvm] [AIX] support builtin_cpu_is() for aix (PR #80069)

2024-02-14 Thread Amy Kwan via cfe-commits


@@ -126,4 +126,53 @@ PPC_LNX_CPU("power10",47)
 #undef PPC_LNX_DEFINE_OFFSETS
 #undef PPC_LNX_FEATURE
 #undef PPC_LNX_CPU
+
+// Definition of the following values are found in the AIX header file: 
.
+#ifndef AIX_POWERPC_SYS_CONF
+#define AIX_POWERPC_SYS_CONF
+  #define AIX_SYSCON_IMPL_IDX 1
+  #define AIX_PPC7_VALUE 0x8000
+  #define AIX_PPC8_VALUE 0x0001
+  #define AIX_PPC9_VALUE 0x0002
+  #define AIX_PPC10_VALUE 0x0004
+
+  #define AIX_BUILTIN_PPC_TRUE 1
+  #define AIX_BUILTIN_PPC_FALSE 0
+  #define SYS_CONF 2
+
+  #define COMP_EQ  0
+
+#endif
+
+// When the value of SUPPORT_MAGIC is SYS_CONF, the return value depends on 
the 
+// _system_configuration[INDEX] COMPARE_OP VALUE.
+#ifndef PPC_AIX_CPU
+  #define PPC_AIX_CPU(NAME, SUPPORT_MAGIC, INDEX, COMPARE_OP, VALUE)
+#endif
+
+// __builtin_cpu_is() is supported only on Power7 and up.
+PPC_AIX_CPU("power4",AIX_BUILTIN_PPC_FALSE,0,0,0)
+PPC_AIX_CPU("ppc970",AIX_BUILTIN_PPC_FALSE,0,0,0)
+PPC_AIX_CPU("power5",AIX_BUILTIN_PPC_FALSE,0,0,0)
+PPC_AIX_CPU("power5+",AIX_BUILTIN_PPC_FALSE,0,0,0)
+PPC_AIX_CPU("power6",AIX_BUILTIN_PPC_FALSE,0,0,0)
+PPC_AIX_CPU("ppc-cell-be",AIX_BUILTIN_PPC_FALSE,0,0,0)
+PPC_AIX_CPU("power6x",AIX_BUILTIN_PPC_FALSE,0,0,0)
+PPC_AIX_CPU("power7",SYS_CONF,AIX_SYSCON_IMPL_IDX,COMP_EQ,AIX_PPC7_VALUE)

amy-kwan wrote:

Can we move this above 167?

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


[clang] [llvm] [AIX] support builtin_cpu_is() for aix (PR #80069)

2024-02-14 Thread Amy Kwan via cfe-commits


@@ -362,8 +362,16 @@ class LLVM_LIBRARY_VISIBILITY PPCTargetInfo : public 
TargetInfo {
 
   // We support __builtin_cpu_supports/__builtin_cpu_is on targets that
   // have Glibc since it is Glibc that provides the HWCAP[2] in the auxv.
+  static constexpr int MINIMUM_AIX_OS_MAJOR = 7;
+  static constexpr int MINIMUM_AIX_OS_MINOR = 2;
   bool supportsCpuSupports() const override { return getTriple().isOSGlibc(); }
-  bool supportsCpuIs() const override { return getTriple().isOSGlibc(); }
+  bool supportsCpuIs() const override {
+llvm::Triple Triple = getTriple();
+// AIX 7.2 is the minimum requirement to support __builtin_cpu_is().
+return Triple.isOSGlibc() ||

amy-kwan wrote:

Check clang-format for indentation.

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


[clang] [llvm] [AIX] support builtin_cpu_is() for aix (PR #80069)

2024-02-14 Thread Amy Kwan via cfe-commits


@@ -126,4 +126,53 @@ PPC_LNX_CPU("power10",47)
 #undef PPC_LNX_DEFINE_OFFSETS
 #undef PPC_LNX_FEATURE
 #undef PPC_LNX_CPU
+
+// Definition of the following values are found in the AIX header file: 
.
+#ifndef AIX_POWERPC_SYS_CONF
+#define AIX_POWERPC_SYS_CONF
+  #define AIX_SYSCON_IMPL_IDX 1
+  #define AIX_PPC7_VALUE 0x8000
+  #define AIX_PPC8_VALUE 0x0001
+  #define AIX_PPC9_VALUE 0x0002
+  #define AIX_PPC10_VALUE 0x0004
+
+  #define AIX_BUILTIN_PPC_TRUE 1

amy-kwan wrote:

Add a comment to describe these are possible values for `SUPPORT_MAGIC`.

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


[clang] [llvm] [AIX] support builtin_cpu_is() for aix (PR #80069)

2024-02-14 Thread Amy Kwan via cfe-commits

https://github.com/amy-kwan commented:

Group review comments.

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


[clang] [llvm] [AIX] support builtin_cpu_is() for aix (PR #80069)

2024-02-14 Thread Amy Kwan via cfe-commits

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


[clang] [compiler-rt] [Sanitizer] add signed-integer-wrap sanitizer (PR #80089)

2024-02-14 Thread Kees Cook via cfe-commits

kees wrote:

> > Why not just enforce -fsanitize=signed-integer-overflow with -fwrapv? I 
> > suspect it's just overlook, and not intentional behavior.
> 
> +1
> 
> We should consider this direction

The UB-vs-non-UB seemed to be a really specific goal in the existing code. i.e. 
that the sanitizer was disabled didn't look like an accident. For people using 
this to find _only_ UB, this would be a behavioral change, so to me it seems 
like a separate name makes the most sense. Anyone wanting wrap-around checking 
can use -wrap, and anyone wanting UB checking can use -overflow.

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


[clang] [HLSL] Vector standard conversions (PR #71098)

2024-02-14 Thread Justin Bogner via cfe-commits


@@ -113,30 +115,12 @@ float2 HowManyFloats(float V) {
 // up nicely too.
 
 // CHECK-LABEL: AllRighty
-// CHECK: [[XTmp:%.*]] = alloca <1 x double>, align 8
-// CHECK: [[YTmp:%.*]] = alloca <1 x double>, align 8
-// CHECK: [[ZTmp:%.*]] = alloca <1 x double>, align 8
-
-// CHECK: store <1 x double> , ptr [[XTmp]], align 8
-// CHECK: [[XVec:%.*]] = load <1 x double>, ptr [[XTmp]], align 8
-// CHECK: [[XVec3:%.*]] = shufflevector <1 x double> [[XVec]], <1 x double> 
poison, <3 x i32> zeroinitializer
-// CHECK: [[XVal:%.*]] = extractelement <3 x double> [[XVec3]], i32 0
-// CHECK: [[XValF:%.*]] = fptrunc double [[XVal]] to float
-// CHECK: [[Vec3F1:%.*]] = insertelement <3 x float> poison, float [[XValF]], 
i32 0
-
-// CHECK: store <1 x double> , ptr [[YTmp]], align 8
-// CHECK: [[YVec:%.*]] = load <1 x double>, ptr [[YTmp]], align 8
-// CHECK: [[YVec3:%.*]] = shufflevector <1 x double> [[YVec]], <1 x double> 
poison, <3 x i32> zeroinitializer
-// CHECK: [[YVal:%.*]] = extractelement <3 x double> [[YVec3]], i32 1
-// CHECK: [[YValF:%.*]] = fptrunc double [[YVal]] to float
-// CHECK: [[Vec3F2:%.*]] = insertelement <3 x float> [[Vec3F1]], float 
[[YValF]], i32 1
-
-// CHECK: store <1 x double> , ptr [[ZTmp]], align 8
-// CHECK: [[ZVec:%.*]] = load <1 x double>, ptr [[ZTmp]], align 8
-// CHECK: [[ZVec3:%.*]] = shufflevector <1 x double> [[ZVec]], <1 x double> 
poison, <3 x i32> zeroinitializer
-// CHECK: [[ZVal:%.*]] = extractelement <3 x double> [[ZVec3]], i32 2
-// CHECK: [[ZValF:%.*]] = fptrunc double [[ZVal]] to float
-// CHECK: [[Vec3F3:%.*]] = insertelement <3 x float> [[Vec3F2]], float 
[[ZValF]], i32 2
+// CHECK: [[Tmp:%.*]] = alloca <1 x double>, align 8
+// CHECK: store <1 x double> , ptr [[Tmp]], align 8
+// CHECK: [[vec1:%.*]] = load <1 x double>, ptr [[Tmp]], align 8
+// CHECK: [[vec3:%.*]] = shufflevector <1 x double> [[vec1]], <1 x double> 
poison, <3 x i32> zeroinitializer
+// CHECK: [[vec3f:%.*]] = fptrunc <3 x double> [[vec3]] to <3 x float>
+// ret <3 x float> [[vec3f]]
 
 // ret <3 x float> [[Vec3F3]]

bogner wrote:

Why isn't the `ret` line a check? Also there seem to be two of them now.

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


[clang] [HLSL] Vector standard conversions (PR #71098)

2024-02-14 Thread Justin Bogner via cfe-commits


@@ -4772,6 +4788,76 @@ Sema::PerformImplicitConversion(Expr *From, QualType 
ToType,
 llvm_unreachable("Improper second standard conversion");
   }
 
+  if (SCS.Element != ICK_Identity) {
+// If SCS.Element is not ICK_Identity the To and From types must be HLSL
+// vectors or matrices. HLSL matrices aren't yet supported so this code 
only
+// handles vectors for now.

bogner wrote:

The comment about matrices should probably be a `TODO:`, and it might even be 
worth a separate assert that says "not implemented yet" for clarity

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


[clang] [HLSL] Vector standard conversions (PR #71098)

2024-02-14 Thread Justin Bogner via cfe-commits


@@ -6432,7 +6432,7 @@ void InitializationSequence::InitializeFrom(Sema ,
   // For HLSL ext vector types we allow list initialization behavior for C++
   // constructor syntax. This is accomplished by converting initialization
   // arguments an InitListExpr late.
-  if (S.getLangOpts().HLSL && DestType->isExtVectorType() &&
+  if (S.getLangOpts().HLSL && Args.size() > 1 && DestType->isExtVectorType() &&

bogner wrote:

This sort of looks like a separate bug fix. In any case I don't see a test for 
it (though maybe I missed it)

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


[clang] [HLSL] Vector standard conversions (PR #71098)

2024-02-14 Thread Justin Bogner via cfe-commits


@@ -4772,6 +4788,76 @@ Sema::PerformImplicitConversion(Expr *From, QualType 
ToType,
 llvm_unreachable("Improper second standard conversion");
   }
 
+  if (SCS.Element != ICK_Identity) {
+// If SCS.Element is not ICK_Identity the To and From types must be HLSL
+// vectors or matrices. HLSL matrices aren't yet supported so this code 
only
+// handles vectors for now.
+
+assert(From->getType()->isVectorType() && ToType->isVectorType() &&
+   "Element conversion is only supported for vector types.");
+assert(From->getType()->getAs()->getNumElements() ==
+   ToType->getAs()->getNumElements() &&
+   "Element conversion is only supported for vectors with the same "
+   "element counts.");
+QualType FromElTy = From->getType()->getAs()->getElementType();
+unsigned NumElts = ToType->getAs()->getNumElements();
+switch (SCS.Element) {
+case ICK_Identity:
+  // Nothing to do.
+  break;

bogner wrote:

`SCS.Element == ICK_Identity` is unreachable - we checked above

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


[clang] [HLSL] Vector standard conversions (PR #71098)

2024-02-14 Thread Justin Bogner via cfe-commits


@@ -123,84 +123,83 @@ CompareDerivedToBaseConversions(Sema , SourceLocation 
Loc,
 /// GetConversionRank - Retrieve the implicit conversion rank
 /// corresponding to the given implicit conversion kind.
 ImplicitConversionRank clang::GetConversionRank(ImplicitConversionKind Kind) {
-  static const ImplicitConversionRank
-Rank[] = {
-ICR_Exact_Match,
-ICR_Exact_Match,
-ICR_Exact_Match,
-ICR_Exact_Match,
-ICR_Exact_Match,
-ICR_Exact_Match,
-ICR_Promotion,
-ICR_Promotion,
-ICR_Promotion,
-ICR_Conversion,
-ICR_Conversion,
-ICR_Conversion,
-ICR_Conversion,
-ICR_Conversion,
-ICR_Conversion,
-ICR_Conversion,
-ICR_Conversion,
-ICR_Conversion,
-ICR_Conversion,
-ICR_Conversion,
-ICR_Conversion,
-ICR_OCL_Scalar_Widening,
-ICR_Complex_Real_Conversion,
-ICR_Conversion,
-ICR_Conversion,
-ICR_Writeback_Conversion,
-ICR_Exact_Match, // NOTE(gbiv): This may not be completely right --
- // it was omitted by the patch that added
- // ICK_Zero_Event_Conversion
-ICR_Exact_Match, // NOTE(ctopper): This may not be completely right --
- // it was omitted by the patch that added
- // ICK_Zero_Queue_Conversion
-ICR_C_Conversion,
-ICR_C_Conversion_Extension,
-ICR_Conversion,
+  static const ImplicitConversionRank Rank[] = {
+  ICR_Exact_Match,
+  ICR_Exact_Match,
+  ICR_Exact_Match,
+  ICR_Exact_Match,
+  ICR_Exact_Match,
+  ICR_Exact_Match,
+  ICR_Promotion,
+  ICR_Promotion,
+  ICR_Promotion,
+  ICR_Conversion,
+  ICR_Conversion,
+  ICR_Conversion,
+  ICR_Conversion,
+  ICR_Conversion,
+  ICR_Conversion,
+  ICR_Conversion,
+  ICR_Conversion,
+  ICR_Conversion,
+  ICR_Conversion,
+  ICR_Conversion,
+  ICR_Conversion,
+  ICR_OCL_Scalar_Widening,
+  ICR_Complex_Real_Conversion,
+  ICR_Conversion,
+  ICR_Conversion,
+  ICR_Writeback_Conversion,
+  ICR_Exact_Match, // NOTE(gbiv): This may not be completely right --
+   // it was omitted by the patch that added
+   // ICK_Zero_Event_Conversion
+  ICR_Exact_Match, // NOTE(ctopper): This may not be completely right --
+   // it was omitted by the patch that added
+   // ICK_Zero_Queue_Conversion
+  ICR_C_Conversion,
+  ICR_C_Conversion_Extension,
+  ICR_Conversion,
+  ICR_Conversion,

bogner wrote:

Might be nice to commit the clang-format changes in this file separately.

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


[clang] [HLSL] Vector standard conversions (PR #71098)

2024-02-14 Thread Justin Bogner via cfe-commits

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

Looks good barring a few minor comments

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


[clang] [HLSL] Vector standard conversions (PR #71098)

2024-02-14 Thread Justin Bogner via cfe-commits

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


[clang] [compiler-rt] [Sanitizer] add signed-integer-wrap sanitizer (PR #80089)

2024-02-14 Thread Fangrui Song via cfe-commits

MaskRay wrote:

> Why not just enforce -fsanitize=signed-integer-overflow with -fwrapv? I 
> suspect it's just overlook, and not intentional behavior.

+1

We should consider this direction 

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


[clang-tools-extra] [clangd] Clean formatting modernize-use-override (PR #81435)

2024-02-14 Thread via cfe-commits

github-actions[bot] wrote:



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

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

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

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

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

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


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


[clang-tools-extra] [clangd] Clean formatting modernize-use-override (PR #81435)

2024-02-14 Thread Piotr Zegar via cfe-commits

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


[clang-tools-extra] 5992b32 - [clangd] Clean formatting modernize-use-override (#81435)

2024-02-14 Thread via cfe-commits

Author: Kevin Joseph
Date: 2024-02-14T20:59:21+01:00
New Revision: 5992b3272b29e071f6f5a4807a4e0c23e88c310d

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

LOG: [clangd] Clean formatting modernize-use-override (#81435)

When applying the recommended fix for the
"modernize-use-override" clang-tidy diagnostic
there was a stray whitespace. This PR fixes that.
Resolves https://github.com/clangd/clangd/issues/1704

Added: 


Modified: 
clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp
clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
clang-tools-extra/docs/ReleaseNotes.rst
clang-tools-extra/test/clang-tidy/checkers/modernize/use-override.cpp

Removed: 




diff  --git a/clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp
index e348968b325a5a..fd5bd9f0b181b1 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp
@@ -7,6 +7,7 @@
 
//===--===//
 
 #include "UseOverrideCheck.h"
+#include "../utils/LexerUtils.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/Lex/Lexer.h"
@@ -228,9 +229,14 @@ void UseOverrideCheck::check(const 
MatchFinder::MatchResult ) {
   if (HasVirtual) {
 for (Token Tok : Tokens) {
   if (Tok.is(tok::kw_virtual)) {
-Diag << FixItHint::CreateRemoval(CharSourceRange::getTokenRange(
-Tok.getLocation(), Tok.getLocation()));
-break;
+std::optional NextToken =
+utils::lexer::findNextTokenIncludingComments(
+Tok.getEndLoc(), Sources, getLangOpts());
+if (NextToken.has_value()) {
+  Diag << FixItHint::CreateRemoval(CharSourceRange::getCharRange(
+  Tok.getLocation(), NextToken->getLocation()));
+  break;
+}
   }
 }
   }

diff  --git a/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp 
b/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
index f302dcf5f09db0..4839879e1b78c8 100644
--- a/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
+++ b/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
@@ -898,6 +898,46 @@ TEST(DiagnosticTest, ClangTidySelfContainedDiags) {
 withFix(equalToFix(ExpectedDFix));
 }
 
+TEST(DiagnosticTest, ClangTidySelfContainedDiagsFormatting) {
+  Annotations Main(R"cpp(
+class Interface {
+public:
+  virtual void Reset1() = 0;
+  virtual void Reset2() = 0;
+};
+class A : public Interface {
+  // This will be marked by clangd to use override instead of virtual
+  $virtual1[[virtual]]void $Reset1[[Reset1]]()$override1[[]];
+  $virtual2[[virtual  ]]/**/void $Reset2[[Reset2]]()$override2[[]];
+};
+  )cpp");
+  TestTU TU = TestTU::withCode(Main.code());
+  TU.ClangTidyProvider =
+  addTidyChecks("cppcoreguidelines-explicit-virtual-functions,");
+  clangd::Fix const ExpectedFix1{
+  "prefer using 'override' or (rarely) 'final' "
+  "instead of 'virtual'",
+  {TextEdit{Main.range("override1"), " override"},
+   TextEdit{Main.range("virtual1"), ""}}};
+  clangd::Fix const ExpectedFix2{
+  "prefer using 'override' or (rarely) 'final' "
+  "instead of 'virtual'",
+  {TextEdit{Main.range("override2"), " override"},
+   TextEdit{Main.range("virtual2"), ""}}};
+  // Note that in the Fix we expect the "virtual" keyword and the following
+  // whitespace to be deleted
+  EXPECT_THAT(TU.build().getDiagnostics(),
+  ifTidyChecks(UnorderedElementsAre(
+  AllOf(Diag(Main.range("Reset1"),
+ "prefer using 'override' or (rarely) 'final' "
+ "instead of 'virtual'"),
+withFix(equalToFix(ExpectedFix1))),
+  AllOf(Diag(Main.range("Reset2"),
+ "prefer using 'override' or (rarely) 'final' "
+ "instead of 'virtual'"),
+withFix(equalToFix(ExpectedFix2));
+}
+
 TEST(DiagnosticsTest, Preprocessor) {
   // This looks like a preamble, but there's an #else in the middle!
   // Check that:

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 2f874d17da430d..a1b95d2a2020fe 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -164,6 +164,10 @@ Changes in existing checks
   `AllowStringArrays` option, enabling the exclusion of array types with 
deduced
   length initialized from string literals.
 
+- Improved :doc:`modernize-use-override
+  ` 

[clang] [clang-format] Support of TableGen basic format restrictions. (PR #81611)

2024-02-14 Thread Björn Schäpers via cfe-commits


@@ -55,5 +59,271 @@ TEST_F(FormatTestTableGen, NoSpacesInSquareBracketLists) {
   verifyFormat("def flag : Flag<[\"-\", \"--\"], \"foo\">;");
 }
 
+TEST_F(FormatTestTableGen, LiteralsAndIdentifiers) {
+  verifyFormat("def LiteralAndIdentifiers {\n"
+   "  let someInteger = -42;\n"
+   "  let 0startID = $TokVarName;\n"
+   "  let 0xstartInteger = 0x42;\n"
+   "  let someIdentifier = $TokVarName;\n"
+   "}\n");
+}
+
+TEST_F(FormatTestTableGen, BangOperators) {
+  verifyFormat("def BangOperators {\n"
+   "  let IfOpe = !if(\n"
+   "  !not(!and(!gt(!add(1, 2), !sub(3, 4)), !isa($x))),\n"
+   "  !foldl(0, !listconcat(!range(5, 6), !range(7, 8)),\n"
+   " total, rec, !add(total, rec.Number)),\n"
+   "  !tail(!range(9, 10)));\n"
+   "  let ForeachOpe = !foreach(\n"
+   "  arg, arglist,\n"
+   "  !if(!isa(arg.Type),\n"
+   "  !add(!cast(arg).Number, x), arg));\n"
+   "  let CondOpe1 = !cond(!eq(size, 1): 1,\n"
+   "   !eq(size, 2): 1,\n"
+   "   !eq(size, 4): 1,\n"
+   "   !eq(size, 8): 1,\n"
+   "   !eq(size, 16): 1,\n"
+   "   true: 0);\n"
+   "  let CondOpe2 = !cond(!lt(x, 0): \"negativenegative\",\n"
+   "   !eq(x, 0): \"zerozero\",\n"
+   "   true: \"positivepositive\");\n"
+   "  let CondOpe2WithComment = !cond(!lt(x, 0):  // negative\n"
+   "  \"negativenegative\",\n"
+   "  !eq(x, 0):  // zero\n"
+   "  \"zerozero\",\n"
+   "  true:  // default\n"
+   "  \"positivepositive\");\n"
+   "}\n");
+}
+
+TEST_F(FormatTestTableGen, Include) {
+  verifyFormat("include \"test/IncludeFile.h\"\n");
+}
+
+TEST_F(FormatTestTableGen, Types) {
+  verifyFormat("def Types : list, bits<3>, list> {}\n");
+}
+
+TEST_F(FormatTestTableGen, SimpleValue1_SingleLiterals) {
+  verifyFormat("def SimpleValue {\n"
+   "  let Integer = 42;\n"
+   "  let String = \"some string\";\n"
+   "}\n");
+}
+
+TEST_F(FormatTestTableGen, SimpleValue1_MultilineString) {
+  // test::messUp does not understand multiline TableGen code-literals.
+  // We have to give the result and the strings to format manually.
+  std::string DefWithCode =

HazardyKnusperkeks wrote:

```suggestion
  StringRef DefWithCode =
```
No need to allocate.

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


[clang] bad error message on incorrect string literal #18079 (PR #81670)

2024-02-14 Thread via cfe-commits


@@ -2270,9 +2270,11 @@ bool Lexer::LexRawStringLiteral(Token , const 
char *CurPtr,
   const char *PrefixEnd = [PrefixLen];
   if (PrefixLen == 16) {
 Diag(PrefixEnd, diag::err_raw_delim_too_long);
-  } else {
+  } else if (*PrefixEnd != '\n') {

akshaykumars614 wrote:

Great! Thanks, I will flip the conditions. and update the testcases.

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


[clang] bad error message on incorrect string literal #18079 (PR #81670)

2024-02-14 Thread Jon Roelofs via cfe-commits


@@ -2270,9 +2270,11 @@ bool Lexer::LexRawStringLiteral(Token , const 
char *CurPtr,
   const char *PrefixEnd = [PrefixLen];
   if (PrefixLen == 16) {
 Diag(PrefixEnd, diag::err_raw_delim_too_long);
-  } else {
+  } else if (*PrefixEnd != '\n') {

jroelofs wrote:

couple of examples: https://clang.godbolt.org/z/161bn5d6s

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


[clang] bad error message on incorrect string literal #18079 (PR #81670)

2024-02-14 Thread via cfe-commits

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


[clang] bad error message on incorrect string literal #18079 (PR #81670)

2024-02-14 Thread via cfe-commits


@@ -2270,9 +2270,11 @@ bool Lexer::LexRawStringLiteral(Token , const 
char *CurPtr,
   const char *PrefixEnd = [PrefixLen];
   if (PrefixLen == 16) {
 Diag(PrefixEnd, diag::err_raw_delim_too_long);
-  } else {
+  } else if (*PrefixEnd != '\n') {

akshaykumars614 wrote:

ummm... still the file will end with \n right?


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


[clang-tools-extra] [clangd] Clean formatting modernize-use-override (PR #81435)

2024-02-14 Thread Piotr Zegar via cfe-commits

https://github.com/PiotrZSL updated 
https://github.com/llvm/llvm-project/pull/81435

>From db2c4ee74ffb0592ec7f3fd5557dbb5399ef998d Mon Sep 17 00:00:00 2001
From: Kevin Joseph 
Date: Sun, 11 Feb 2024 13:39:51 -0800
Subject: [PATCH 1/3] [clangd] Clean formatting modernize-use-override

When applying the recommended fix for the
"modernize-use-override" clang-tidy diagnostic
there was a stray whitespace.

This commit fixes: https://github.com/clangd/clangd/issues/1704
---
 .../clang-tidy/modernize/UseOverrideCheck.cpp |  4 +--
 .../clangd/unittests/DiagnosticsTests.cpp | 28 +++
 2 files changed, 30 insertions(+), 2 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp
index e348968b325a5a..4db32b02ee5a0c 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp
@@ -228,8 +228,8 @@ void UseOverrideCheck::check(const MatchFinder::MatchResult 
) {
   if (HasVirtual) {
 for (Token Tok : Tokens) {
   if (Tok.is(tok::kw_virtual)) {
-Diag << FixItHint::CreateRemoval(CharSourceRange::getTokenRange(
-Tok.getLocation(), Tok.getLocation()));
+Diag << FixItHint::CreateRemoval(CharSourceRange::getCharRange(
+Tok.getLocation(), Tok.getEndLoc().getLocWithOffset(1)));
 break;
   }
 }
diff --git a/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp 
b/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
index f302dcf5f09db0..76874ac9a2a4e7 100644
--- a/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
+++ b/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
@@ -898,6 +898,34 @@ TEST(DiagnosticTest, ClangTidySelfContainedDiags) {
 withFix(equalToFix(ExpectedDFix));
 }
 
+TEST(DiagnosticTest, ClangTidySelfContainedDiagsFormatting) {
+  Annotations Main(R"cpp(
+class Interface {
+public:
+  virtual void Reset() = 0;
+};
+class A : public Interface {
+  // This will be marked by clangd to use override instead of virtual
+  $virtual[[virtual ]] void $Reset[[Reset]]()$override[[]];
+};
+  )cpp");
+  TestTU TU = TestTU::withCode(Main.code());
+  TU.ClangTidyProvider =
+  addTidyChecks("cppcoreguidelines-explicit-virtual-functions,");
+  clangd::Fix const ExpectedFix{"prefer using 'override' or (rarely) 'final' "
+"instead of 'virtual'",
+{TextEdit{Main.range("override"), " override"},
+ TextEdit{Main.range("virtual"), ""}}};
+  // Note that in the Fix we expect the "virtual" keyword and the following
+  // whitespace to be deleted
+  EXPECT_THAT(TU.build().getDiagnostics(),
+  ifTidyChecks(UnorderedElementsAre(
+  AllOf(Diag(Main.range("Reset"),
+ "prefer using 'override' or (rarely) 'final' "
+ "instead of 'virtual'"),
+withFix(equalToFix(ExpectedFix));
+}
+
 TEST(DiagnosticsTest, Preprocessor) {
   // This looks like a preamble, but there's an #else in the middle!
   // Check that:

>From 7b868a4ede5f49f2c4471b85ac389b36aaf1c6e1 Mon Sep 17 00:00:00 2001
From: Kevin Joseph 
Date: Sun, 11 Feb 2024 19:35:29 -0800
Subject: [PATCH 2/3] fixup! [clangd] Clean formatting modernize-use-override

---
 .../clang-tidy/modernize/UseOverrideCheck.cpp | 12 ++--
 .../clangd/unittests/DiagnosticsTests.cpp | 28 +--
 clang-tools-extra/docs/ReleaseNotes.rst   |  4 +++
 .../checkers/modernize/use-override.cpp   |  5 
 4 files changed, 38 insertions(+), 11 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp 
b/clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp
index 4db32b02ee5a0c..fd5bd9f0b181b1 100644
--- a/clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp
+++ b/clang-tools-extra/clang-tidy/modernize/UseOverrideCheck.cpp
@@ -7,6 +7,7 @@
 
//===--===//
 
 #include "UseOverrideCheck.h"
+#include "../utils/LexerUtils.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/ASTMatchers/ASTMatchFinder.h"
 #include "clang/Lex/Lexer.h"
@@ -228,9 +229,14 @@ void UseOverrideCheck::check(const 
MatchFinder::MatchResult ) {
   if (HasVirtual) {
 for (Token Tok : Tokens) {
   if (Tok.is(tok::kw_virtual)) {
-Diag << FixItHint::CreateRemoval(CharSourceRange::getCharRange(
-Tok.getLocation(), Tok.getEndLoc().getLocWithOffset(1)));
-break;
+std::optional NextToken =
+utils::lexer::findNextTokenIncludingComments(
+Tok.getEndLoc(), Sources, getLangOpts());
+if (NextToken.has_value()) {
+  Diag << FixItHint::CreateRemoval(CharSourceRange::getCharRange(
+  Tok.getLocation(), 

[clang] [HLSL] Expose `half` types and intrinsics always (PR #81782)

2024-02-14 Thread via cfe-commits

llvmbot wrote:




@llvm/pr-subscribers-clang

Author: Chris B (llvm-beanz)


Changes

We previously made an implmenetation error when adding `half` overloads for 
HLSL library functionalitly. The `half` type is always defined in HLSL and 
`half` intrinsics should not be conditionally included.

When native 16-bit types are disabled `half` is a unique 32-bit float type with 
lesser promotion rank than `float`.

Fixes #81049

---

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


15 Files Affected:

- (modified) clang/lib/Headers/hlsl/hlsl_basic_types.h (-2) 
- (modified) clang/lib/Headers/hlsl/hlsl_intrinsics.h (+59-72) 
- (modified) clang/test/CodeGenHLSL/builtins/abs.hlsl (+4-1) 
- (modified) clang/test/CodeGenHLSL/builtins/ceil.hlsl (+1-1) 
- (modified) clang/test/CodeGenHLSL/builtins/cos.hlsl (+1-1) 
- (modified) clang/test/CodeGenHLSL/builtins/floor.hlsl (+1-1) 
- (modified) clang/test/CodeGenHLSL/builtins/log.hlsl (+1-1) 
- (modified) clang/test/CodeGenHLSL/builtins/log10.hlsl (+1-1) 
- (modified) clang/test/CodeGenHLSL/builtins/log2.hlsl (+1-1) 
- (modified) clang/test/CodeGenHLSL/builtins/max.hlsl (+1-17) 
- (modified) clang/test/CodeGenHLSL/builtins/min.hlsl (+1-17) 
- (modified) clang/test/CodeGenHLSL/builtins/pow.hlsl (+1-1) 
- (modified) clang/test/CodeGenHLSL/builtins/reversebits.hlsl (+1-1) 
- (modified) clang/test/CodeGenHLSL/builtins/sin.hlsl (+1-1) 
- (modified) clang/test/CodeGenHLSL/builtins/trunc.hlsl (+1-1) 


``diff
diff --git a/clang/lib/Headers/hlsl/hlsl_basic_types.h 
b/clang/lib/Headers/hlsl/hlsl_basic_types.h
index e96fa90b1ce469..3d0d296aadca3a 100644
--- a/clang/lib/Headers/hlsl/hlsl_basic_types.h
+++ b/clang/lib/Headers/hlsl/hlsl_basic_types.h
@@ -56,11 +56,9 @@ typedef vector uint64_t2;
 typedef vector uint64_t3;
 typedef vector uint64_t4;
 
-#ifdef __HLSL_ENABLE_16_BIT
 typedef vector half2;
 typedef vector half3;
 typedef vector half4;
-#endif
 
 typedef vector float2;
 typedef vector float3;
diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h 
b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index a8b36d29c78607..f87ac977997962 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -21,6 +21,13 @@ namespace hlsl {
 #define _HLSL_AVAILABILITY(environment, version)   
\
   __attribute__((availability(environment, introduced = version)))
 
+#ifdef __HLSL_ENABLE_16_BIT
+#define _HLSL_16BIT_AVAILABILITY(environment, version) 
\
+  __attribute__((availability(environment, introduced = version)))
+#else
+#define _HLSL_16BIT_AVAILABILITY(environment, version)
+#endif
+
 
//===--===//
 // abs builtins
 
//===--===//
@@ -42,20 +49,20 @@ int16_t3 abs(int16_t3);
 _HLSL_AVAILABILITY(shadermodel, 6.2)
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_abs)
 int16_t4 abs(int16_t4);
+#endif
 
-_HLSL_AVAILABILITY(shadermodel, 6.2)
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_abs)
 half abs(half);
-_HLSL_AVAILABILITY(shadermodel, 6.2)
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_abs)
 half2 abs(half2);
-_HLSL_AVAILABILITY(shadermodel, 6.2)
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_abs)
 half3 abs(half3);
-_HLSL_AVAILABILITY(shadermodel, 6.2)
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_abs)
 half4 abs(half4);
-#endif
 
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_abs)
 int abs(int);
@@ -102,20 +109,18 @@ double4 abs(double4);
 /// the input value, \a Val.
 /// \param Val The input value.
 
-#ifdef __HLSL_ENABLE_16_BIT
-_HLSL_AVAILABILITY(shadermodel, 6.2)
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_ceil)
 half ceil(half);
-_HLSL_AVAILABILITY(shadermodel, 6.2)
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_ceil)
 half2 ceil(half2);
-_HLSL_AVAILABILITY(shadermodel, 6.2)
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_ceil)
 half3 ceil(half3);
-_HLSL_AVAILABILITY(shadermodel, 6.2)
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_ceil)
 half4 ceil(half4);
-#endif
 
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_ceil)
 float ceil(float);
@@ -143,20 +148,18 @@ double4 ceil(double4);
 /// \brief Returns the cosine of the input value, \a Val.
 /// \param Val The input value.
 
-#ifdef __HLSL_ENABLE_16_BIT
-_HLSL_AVAILABILITY(shadermodel, 6.2)
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_cos)
 half cos(half);
-_HLSL_AVAILABILITY(shadermodel, 6.2)
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_cos)
 

[clang] [HLSL] Expose `half` types and intrinsics always (PR #81782)

2024-02-14 Thread via cfe-commits

llvmbot wrote:



@llvm/pr-subscribers-hlsl

@llvm/pr-subscribers-backend-x86

Author: Chris B (llvm-beanz)


Changes

We previously made an implmenetation error when adding `half` overloads for 
HLSL library functionalitly. The `half` type is always defined in HLSL and 
`half` intrinsics should not be conditionally included.

When native 16-bit types are disabled `half` is a unique 32-bit float type with 
lesser promotion rank than `float`.

Fixes #81049

---

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


15 Files Affected:

- (modified) clang/lib/Headers/hlsl/hlsl_basic_types.h (-2) 
- (modified) clang/lib/Headers/hlsl/hlsl_intrinsics.h (+59-72) 
- (modified) clang/test/CodeGenHLSL/builtins/abs.hlsl (+4-1) 
- (modified) clang/test/CodeGenHLSL/builtins/ceil.hlsl (+1-1) 
- (modified) clang/test/CodeGenHLSL/builtins/cos.hlsl (+1-1) 
- (modified) clang/test/CodeGenHLSL/builtins/floor.hlsl (+1-1) 
- (modified) clang/test/CodeGenHLSL/builtins/log.hlsl (+1-1) 
- (modified) clang/test/CodeGenHLSL/builtins/log10.hlsl (+1-1) 
- (modified) clang/test/CodeGenHLSL/builtins/log2.hlsl (+1-1) 
- (modified) clang/test/CodeGenHLSL/builtins/max.hlsl (+1-17) 
- (modified) clang/test/CodeGenHLSL/builtins/min.hlsl (+1-17) 
- (modified) clang/test/CodeGenHLSL/builtins/pow.hlsl (+1-1) 
- (modified) clang/test/CodeGenHLSL/builtins/reversebits.hlsl (+1-1) 
- (modified) clang/test/CodeGenHLSL/builtins/sin.hlsl (+1-1) 
- (modified) clang/test/CodeGenHLSL/builtins/trunc.hlsl (+1-1) 


``diff
diff --git a/clang/lib/Headers/hlsl/hlsl_basic_types.h 
b/clang/lib/Headers/hlsl/hlsl_basic_types.h
index e96fa90b1ce469..3d0d296aadca3a 100644
--- a/clang/lib/Headers/hlsl/hlsl_basic_types.h
+++ b/clang/lib/Headers/hlsl/hlsl_basic_types.h
@@ -56,11 +56,9 @@ typedef vector uint64_t2;
 typedef vector uint64_t3;
 typedef vector uint64_t4;
 
-#ifdef __HLSL_ENABLE_16_BIT
 typedef vector half2;
 typedef vector half3;
 typedef vector half4;
-#endif
 
 typedef vector float2;
 typedef vector float3;
diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h 
b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index a8b36d29c78607..f87ac977997962 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -21,6 +21,13 @@ namespace hlsl {
 #define _HLSL_AVAILABILITY(environment, version)   
\
   __attribute__((availability(environment, introduced = version)))
 
+#ifdef __HLSL_ENABLE_16_BIT
+#define _HLSL_16BIT_AVAILABILITY(environment, version) 
\
+  __attribute__((availability(environment, introduced = version)))
+#else
+#define _HLSL_16BIT_AVAILABILITY(environment, version)
+#endif
+
 
//===--===//
 // abs builtins
 
//===--===//
@@ -42,20 +49,20 @@ int16_t3 abs(int16_t3);
 _HLSL_AVAILABILITY(shadermodel, 6.2)
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_abs)
 int16_t4 abs(int16_t4);
+#endif
 
-_HLSL_AVAILABILITY(shadermodel, 6.2)
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_abs)
 half abs(half);
-_HLSL_AVAILABILITY(shadermodel, 6.2)
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_abs)
 half2 abs(half2);
-_HLSL_AVAILABILITY(shadermodel, 6.2)
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_abs)
 half3 abs(half3);
-_HLSL_AVAILABILITY(shadermodel, 6.2)
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_abs)
 half4 abs(half4);
-#endif
 
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_abs)
 int abs(int);
@@ -102,20 +109,18 @@ double4 abs(double4);
 /// the input value, \a Val.
 /// \param Val The input value.
 
-#ifdef __HLSL_ENABLE_16_BIT
-_HLSL_AVAILABILITY(shadermodel, 6.2)
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_ceil)
 half ceil(half);
-_HLSL_AVAILABILITY(shadermodel, 6.2)
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_ceil)
 half2 ceil(half2);
-_HLSL_AVAILABILITY(shadermodel, 6.2)
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_ceil)
 half3 ceil(half3);
-_HLSL_AVAILABILITY(shadermodel, 6.2)
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_ceil)
 half4 ceil(half4);
-#endif
 
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_ceil)
 float ceil(float);
@@ -143,20 +148,18 @@ double4 ceil(double4);
 /// \brief Returns the cosine of the input value, \a Val.
 /// \param Val The input value.
 
-#ifdef __HLSL_ENABLE_16_BIT
-_HLSL_AVAILABILITY(shadermodel, 6.2)
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_cos)
 half cos(half);
-_HLSL_AVAILABILITY(shadermodel, 6.2)
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
 

[clang-tools-extra] [clang-tidy] Removed redundant-inline-specifier warning on static data members (PR #81423)

2024-02-14 Thread Piotr Zegar via cfe-commits
=?utf-8?q?Félix-Antoine?= Constantin
Message-ID:
In-Reply-To: 


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


[clang-tools-extra] 9b80ab4 - [clang-tidy] Removed redundant-inline-specifier warning on static data members (#81423)

2024-02-14 Thread via cfe-commits

Author: Félix-Antoine Constantin
Date: 2024-02-14T20:30:21+01:00
New Revision: 9b80ab4332bbe336ab8b9f2082eadf6b8d223150

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

LOG: [clang-tidy] Removed redundant-inline-specifier warning on static data 
members (#81423)

Updated the check to ignore point static data members with in class
initializer since removing the inline specifier would generate a
compilation error

Fixes #80684

Added: 


Modified: 
clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.cpp
clang-tools-extra/docs/ReleaseNotes.rst

clang-tools-extra/test/clang-tidy/checkers/readability/redundant-inline-specifier.cpp

Removed: 




diff  --git 
a/clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.cpp 
b/clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.cpp
index 0e8d17d4442478..1693e5c5e9cd45 100644
--- a/clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/RedundantInlineSpecifierCheck.cpp
@@ -88,10 +88,14 @@ void 
RedundantInlineSpecifierCheck::registerMatchers(MatchFinder *Finder) {
 this);
 
   if (getLangOpts().CPlusPlus17) {
+const auto IsPartOfRecordDecl = hasAncestor(recordDecl());
 Finder->addMatcher(
-varDecl(isInlineSpecified(),
-anyOf(isInternalLinkage(StrictMode),
-  allOf(isConstexpr(), hasAncestor(recordDecl()
+varDecl(
+isInlineSpecified(),
+anyOf(allOf(isInternalLinkage(StrictMode),
+unless(allOf(hasInitializer(expr()), 
IsPartOfRecordDecl,
+ isStaticStorageClass(,
+  allOf(isConstexpr(), IsPartOfRecordDecl)))
 .bind("var_decl"),
 this);
   }

diff  --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index f2fba9aa1450d6..2f874d17da430d 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -164,6 +164,10 @@ Changes in existing checks
   `AllowStringArrays` option, enabling the exclusion of array types with 
deduced
   length initialized from string literals.
 
+- Improved :doc:`readability-redundant-inline-specifier
+  ` check to properly
+  emit warnings for static data member with an in-class initializer.
+
 Removed checks
 ^^
 

diff  --git 
a/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-inline-specifier.cpp
 
b/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-inline-specifier.cpp
index cdd98d8fdc20f5..14f9e88f7e7218 100644
--- 
a/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-inline-specifier.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/checkers/readability/redundant-inline-specifier.cpp
@@ -135,3 +135,17 @@ INLINE_MACRO()
 
 #define INLINE_KW inline
 INLINE_KW void fn10() { }
+
+namespace {
+class A
+{
+public:
+  static inline float test = 3.0F;
+  static inline double test2 = 3.0;
+  static inline int test3 = 3;
+
+  static inline float test4;
+  // CHECK-MESSAGES-STRICT: :[[@LINE-1]]:10: warning: variable 'test4' has 
inline specifier but is implicitly inlined 
[readability-redundant-inline-specifier]
+  // CHECK-FIXES-STRICT: static float test4;
+};
+}



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


[clang] [HLSL] Expose `half` types and intrinsics always (PR #81782)

2024-02-14 Thread Chris B via cfe-commits

https://github.com/llvm-beanz created 
https://github.com/llvm/llvm-project/pull/81782

We previously made an implmenetation error when adding `half` overloads for 
HLSL library functionalitly. The `half` type is always defined in HLSL and 
`half` intrinsics should not be conditionally included.

When native 16-bit types are disabled `half` is a unique 32-bit float type with 
lesser promotion rank than `float`.

Fixes #81049

>From e68a1db0ef525e63db30b77d03ac3708210f7ee8 Mon Sep 17 00:00:00 2001
From: Chris Bieneman 
Date: Wed, 14 Feb 2024 13:25:45 -0600
Subject: [PATCH] [HLSL] Expose `half` types and intrinsics always

We previously made an implmenetation error when adding `half` overloads
for HLSL library functionalitly. The `half` type is always defined in
HLSL and `half` intrinsics should not be conditionally included.

When native 16-bit types are disabled `half` is a unique 32-bit float
type with lesser promotion rank than `float`.

Fixes #81049
---
 clang/lib/Headers/hlsl/hlsl_basic_types.h |   2 -
 clang/lib/Headers/hlsl/hlsl_intrinsics.h  | 131 --
 clang/test/CodeGenHLSL/builtins/abs.hlsl  |   5 +-
 clang/test/CodeGenHLSL/builtins/ceil.hlsl |   2 +-
 clang/test/CodeGenHLSL/builtins/cos.hlsl  |   2 +-
 clang/test/CodeGenHLSL/builtins/floor.hlsl|   2 +-
 clang/test/CodeGenHLSL/builtins/log.hlsl  |   2 +-
 clang/test/CodeGenHLSL/builtins/log10.hlsl|   2 +-
 clang/test/CodeGenHLSL/builtins/log2.hlsl |   2 +-
 clang/test/CodeGenHLSL/builtins/max.hlsl  |  18 +--
 clang/test/CodeGenHLSL/builtins/min.hlsl  |  18 +--
 clang/test/CodeGenHLSL/builtins/pow.hlsl  |   2 +-
 .../CodeGenHLSL/builtins/reversebits.hlsl |   2 +-
 clang/test/CodeGenHLSL/builtins/sin.hlsl  |   2 +-
 clang/test/CodeGenHLSL/builtins/trunc.hlsl|   2 +-
 15 files changed, 75 insertions(+), 119 deletions(-)

diff --git a/clang/lib/Headers/hlsl/hlsl_basic_types.h 
b/clang/lib/Headers/hlsl/hlsl_basic_types.h
index e96fa90b1ce469..3d0d296aadca3a 100644
--- a/clang/lib/Headers/hlsl/hlsl_basic_types.h
+++ b/clang/lib/Headers/hlsl/hlsl_basic_types.h
@@ -56,11 +56,9 @@ typedef vector uint64_t2;
 typedef vector uint64_t3;
 typedef vector uint64_t4;
 
-#ifdef __HLSL_ENABLE_16_BIT
 typedef vector half2;
 typedef vector half3;
 typedef vector half4;
-#endif
 
 typedef vector float2;
 typedef vector float3;
diff --git a/clang/lib/Headers/hlsl/hlsl_intrinsics.h 
b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
index a8b36d29c78607..f87ac977997962 100644
--- a/clang/lib/Headers/hlsl/hlsl_intrinsics.h
+++ b/clang/lib/Headers/hlsl/hlsl_intrinsics.h
@@ -21,6 +21,13 @@ namespace hlsl {
 #define _HLSL_AVAILABILITY(environment, version)   
\
   __attribute__((availability(environment, introduced = version)))
 
+#ifdef __HLSL_ENABLE_16_BIT
+#define _HLSL_16BIT_AVAILABILITY(environment, version) 
\
+  __attribute__((availability(environment, introduced = version)))
+#else
+#define _HLSL_16BIT_AVAILABILITY(environment, version)
+#endif
+
 
//===--===//
 // abs builtins
 
//===--===//
@@ -42,20 +49,20 @@ int16_t3 abs(int16_t3);
 _HLSL_AVAILABILITY(shadermodel, 6.2)
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_abs)
 int16_t4 abs(int16_t4);
+#endif
 
-_HLSL_AVAILABILITY(shadermodel, 6.2)
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_abs)
 half abs(half);
-_HLSL_AVAILABILITY(shadermodel, 6.2)
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_abs)
 half2 abs(half2);
-_HLSL_AVAILABILITY(shadermodel, 6.2)
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_abs)
 half3 abs(half3);
-_HLSL_AVAILABILITY(shadermodel, 6.2)
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_abs)
 half4 abs(half4);
-#endif
 
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_abs)
 int abs(int);
@@ -102,20 +109,18 @@ double4 abs(double4);
 /// the input value, \a Val.
 /// \param Val The input value.
 
-#ifdef __HLSL_ENABLE_16_BIT
-_HLSL_AVAILABILITY(shadermodel, 6.2)
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_ceil)
 half ceil(half);
-_HLSL_AVAILABILITY(shadermodel, 6.2)
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_ceil)
 half2 ceil(half2);
-_HLSL_AVAILABILITY(shadermodel, 6.2)
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_ceil)
 half3 ceil(half3);
-_HLSL_AVAILABILITY(shadermodel, 6.2)
+_HLSL_16BIT_AVAILABILITY(shadermodel, 6.2)
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_ceil)
 half4 ceil(half4);
-#endif
 
 _HLSL_BUILTIN_ALIAS(__builtin_elementwise_ceil)
 float ceil(float);
@@ -143,20 +148,18 @@ double4 ceil(double4);
 /// \brief Returns the cosine of the input value, \a Val.
 

[clang] bad error message on incorrect string literal #18079 (PR #81670)

2024-02-14 Thread Jon Roelofs via cfe-commits


@@ -2270,9 +2270,11 @@ bool Lexer::LexRawStringLiteral(Token , const 
char *CurPtr,
   const char *PrefixEnd = [PrefixLen];
   if (PrefixLen == 16) {
 Diag(PrefixEnd, diag::err_raw_delim_too_long);
-  } else {
+  } else if (*PrefixEnd != '\n') {

jroelofs wrote:

hmmm. what happens if the line ends with `\r\n`?

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


[clang] bad error message on incorrect string literal #18079 (PR #81670)

2024-02-14 Thread via cfe-commits

https://github.com/akshaykumars614 updated 
https://github.com/llvm/llvm-project/pull/81670

>From c2f716ee5f787ec3df63511fd5f565a3deee4d6e Mon Sep 17 00:00:00 2001
From: akshaykumars614 
Date: Tue, 13 Feb 2024 16:29:51 -0500
Subject: [PATCH 1/5] issue: #18079 (bad errwqor message on incorrect string
 literal)

Fixed the error message for incorrect string literal
---
 clang/include/clang/Basic/DiagnosticLexKinds.td | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/include/clang/Basic/DiagnosticLexKinds.td 
b/clang/include/clang/Basic/DiagnosticLexKinds.td
index 75ca2fa16d3485..c5a2096d02b39d 100644
--- a/clang/include/clang/Basic/DiagnosticLexKinds.td
+++ b/clang/include/clang/Basic/DiagnosticLexKinds.td
@@ -100,7 +100,7 @@ def err_raw_delim_too_long : Error<
   "raw string delimiter longer than 16 characters"
   "; use PREFIX( )PREFIX to delimit raw string">;
 def err_invalid_char_raw_delim : Error<
-  "invalid character '%0' character in raw string delimiter"
+  "invalid newline character in raw string delimiter"
   "; use PREFIX( )PREFIX to delimit raw string">;
 def err_unterminated_raw_string : Error<
   "raw string missing terminating delimiter )%0\"">;

>From ac8b99309b07b6c7114dfbf784a46d2fb5d9dcc4 Mon Sep 17 00:00:00 2001
From: akshaykumars614 
Date: Wed, 14 Feb 2024 14:04:52 -0500
Subject: [PATCH 2/5] bad error message on incorrect string literal #18079

Introduced new error code for \n delimiter in raw string delimiter. Added 
testcase to test the same.
---
 clang/include/clang/Basic/DiagnosticLexKinds.td | 3 +++
 clang/lib/Lex/Lexer.cpp | 6 --
 clang/test/Lexer/raw-string-dlim-newline.cpp| 5 +
 3 files changed, 12 insertions(+), 2 deletions(-)
 create mode 100644 clang/test/Lexer/raw-string-dlim-newline.cpp

diff --git a/clang/include/clang/Basic/DiagnosticLexKinds.td 
b/clang/include/clang/Basic/DiagnosticLexKinds.td
index c5a2096d02b39d..0bc684a9db5793 100644
--- a/clang/include/clang/Basic/DiagnosticLexKinds.td
+++ b/clang/include/clang/Basic/DiagnosticLexKinds.td
@@ -102,6 +102,9 @@ def err_raw_delim_too_long : Error<
 def err_invalid_char_raw_delim : Error<
   "invalid newline character in raw string delimiter"
   "; use PREFIX( )PREFIX to delimit raw string">;
+def err_invalid_nexline_raw_delim : Error<
+  "invalid newline character in raw string delimiter"
+  "; use PREFIX( )PREFIX to delimit raw string">;
 def err_unterminated_raw_string : Error<
   "raw string missing terminating delimiter )%0\"">;
 def warn_cxx98_compat_raw_string_literal : Warning<
diff --git a/clang/lib/Lex/Lexer.cpp b/clang/lib/Lex/Lexer.cpp
index d927f28b47c270..95f39df7a4628a 100644
--- a/clang/lib/Lex/Lexer.cpp
+++ b/clang/lib/Lex/Lexer.cpp
@@ -2270,10 +2270,12 @@ bool Lexer::LexRawStringLiteral(Token , const 
char *CurPtr,
   const char *PrefixEnd = [PrefixLen];
   if (PrefixLen == 16) {
 Diag(PrefixEnd, diag::err_raw_delim_too_long);
-  } else {
+  } else if (*PrefixEnd != '\n') {
 Diag(PrefixEnd, diag::err_invalid_char_raw_delim)
   << StringRef(PrefixEnd, 1);
-  }
+  } else {
+Diag(PrefixEnd, diag::err_invalid_nexline_raw_delim);
+   }
 }
 
 // Search for the next '"' in hopes of salvaging the lexer. Unfortunately,
diff --git a/clang/test/Lexer/raw-string-dlim-newline.cpp 
b/clang/test/Lexer/raw-string-dlim-newline.cpp
new file mode 100644
index 00..36939ed864ecae
--- /dev/null
+++ b/clang/test/Lexer/raw-string-dlim-newline.cpp
@@ -0,0 +1,5 @@
+// RUN: not  %clang_cc1 -E %s 2>&1 | grep 'error: invalid newline character in 
raw string delimiter; use PREFIX( )PREFIX to delimit raw string'
+
+// Introduced new error code err_invalid_nexline_raw_delim for code which has 
\n as delimiter.
+char const* str1 = R"
+";

>From f8ede1571c5678aa6cdbce7cc0d5b30f191b4e92 Mon Sep 17 00:00:00 2001
From: akshaykumars614 <88362922+akshaykumars...@users.noreply.github.com>
Date: Wed, 14 Feb 2024 14:15:34 -0500
Subject: [PATCH 3/5] Update clang/include/clang/Basic/DiagnosticLexKinds.td

Co-authored-by: Jon Roelofs 
---
 clang/include/clang/Basic/DiagnosticLexKinds.td | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/include/clang/Basic/DiagnosticLexKinds.td 
b/clang/include/clang/Basic/DiagnosticLexKinds.td
index 0bc684a9db5793..1db34adf6bee61 100644
--- a/clang/include/clang/Basic/DiagnosticLexKinds.td
+++ b/clang/include/clang/Basic/DiagnosticLexKinds.td
@@ -102,7 +102,7 @@ def err_raw_delim_too_long : Error<
 def err_invalid_char_raw_delim : Error<
   "invalid newline character in raw string delimiter"
   "; use PREFIX( )PREFIX to delimit raw string">;
-def err_invalid_nexline_raw_delim : Error<
+def err_invalid_newline_raw_delim : Error<
   "invalid newline character in raw string delimiter"
   "; use PREFIX( )PREFIX to delimit raw string">;
 def err_unterminated_raw_string : Error<

>From baa768ebc8f5a5359a8921c110a39d3ff8739747 Mon Sep 17 00:00:00 2001
From: 

[clang] [clang-tools-extra] [clang-tidy] Add new check `modernize-use-designated-initializers` (PR #80541)

2024-02-14 Thread Piotr Zegar via cfe-commits
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= ,
Danny =?utf-8?q?Mösch?= 
Message-ID:
In-Reply-To: 



@@ -0,0 +1,127 @@
+//===--- UseDesignatedInitializersCheck.cpp - clang-tidy 
--===//
+//
+// Part of the LLVM Project, under the Apache License v2.0 with LLVM 
Exceptions.
+// See https://llvm.org/LICENSE.txt for license information.
+// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
+//
+//===--===//
+
+#include "UseDesignatedInitializersCheck.h"
+#include "clang/AST/APValue.h"
+#include "clang/AST/Decl.h"
+#include "clang/AST/Expr.h"
+#include "clang/AST/Stmt.h"
+#include "clang/ASTMatchers/ASTMatchFinder.h"
+#include "clang/ASTMatchers/ASTMatchers.h"
+#include "clang/ASTMatchers/ASTMatchersMacros.h"
+#include "clang/Basic/Diagnostic.h"
+#include "clang/Lex/Lexer.h"
+#include "clang/Tooling/DesignatedInitializers.h"
+
+using namespace clang::ast_matchers;
+
+namespace clang::tidy::modernize {
+
+static const char *IgnoreSingleElementAggregatesName =
+"IgnoreSingleElementAggregates";
+static const bool IgnoreSingleElementAggregatesDefault = true;
+
+static const char *RestrictToPODTypesName = "RestrictToPODTypes";
+static const bool RestrictToPODTypesDefault = false;
+
+UseDesignatedInitializersCheck::UseDesignatedInitializersCheck(
+StringRef Name, ClangTidyContext *Context)
+: ClangTidyCheck(Name, Context), IgnoreSingleElementAggregates(Options.get(
+ IgnoreSingleElementAggregatesName,
+ 
IgnoreSingleElementAggregatesDefault)),
+  RestrictToPODTypes(
+  Options.get(RestrictToPODTypesName, RestrictToPODTypesDefault)) {}
+
+namespace {
+
+AST_MATCHER(CXXRecordDecl, isAggregate) { return Node.isAggregate(); }
+
+AST_MATCHER(CXXRecordDecl, isPOD) { return Node.isPOD(); }
+
+AST_MATCHER(InitListExpr, isFullyDesignated) {
+  const InitListExpr *SyntacticForm =
+  Node.isSyntacticForm() ?  : Node.getSyntacticForm();
+  return std::all_of(
+  SyntacticForm->begin(), SyntacticForm->end(),
+  [](auto *InitExpr) { return isa(InitExpr); });
+}
+
+AST_MATCHER(InitListExpr, hasSingleElement) { return Node.getNumInits() == 1; }
+
+AST_MATCHER_FUNCTION(::internal::Matcher, hasBaseWithFields) {
+  return hasAnyBase(hasType(cxxRecordDecl(has(fieldDecl();
+}
+
+AST_MATCHER(FieldDecl, isAnonymousDecl) {
+  if (const auto *Record =
+  Node.getType().getCanonicalType()->getAsRecordDecl()) {
+return Record->isAnonymousStructOrUnion() || !Record->getIdentifier();
+  }
+  return false;
+}
+
+} // namespace
+
+void UseDesignatedInitializersCheck::registerMatchers(MatchFinder *Finder) {
+  Finder->addMatcher(
+  initListExpr(
+  hasType(cxxRecordDecl(RestrictToPODTypes ? isPOD() : isAggregate(),
+unless(hasBaseWithFields()),
+unless(has(fieldDecl(isAnonymousDecl()
+  .bind("type")),
+  unless(IgnoreSingleElementAggregates ? hasSingleElement()
+   : unless(anything())),
+  unless(isFullyDesignated()))
+  .bind("init"),
+  this);
+}
+
+static bool isFullyUndesignated(const InitListExpr *SyntacticInitList) {
+  return std::all_of(
+  SyntacticInitList->begin(), SyntacticInitList->end(),
+  [](auto *InitExpr) { return !isa(InitExpr); });
+}
+
+void UseDesignatedInitializersCheck::check(
+const MatchFinder::MatchResult ) {
+  const auto *InitList = Result.Nodes.getNodeAs("init");
+  const auto *Type = Result.Nodes.getNodeAs("type");
+  if (!Type || !InitList)
+return;
+  if (const auto *SyntacticInitList = InitList->getSyntacticForm()) {
+const llvm::DenseMap Designators =
+clang::tooling::getUnwrittenDesignators(SyntacticInitList);
+if (isFullyUndesignated(SyntacticInitList)) {
+  DiagnosticBuilder Diag =
+  diag(InitList->getLBraceLoc(), "use designated initializer list");
+  for (const Stmt *InitExpr : *SyntacticInitList) {
+Diag << FixItHint::CreateInsertion(
+InitExpr->getBeginLoc(),
+Designators.at(InitExpr->getBeginLoc()) + "=");
+  }
+} else {
+  for (const auto *InitExpr : 

[clang] bad error message on incorrect string literal #18079 (PR #81670)

2024-02-14 Thread via cfe-commits


@@ -2270,9 +2270,11 @@ bool Lexer::LexRawStringLiteral(Token , const 
char *CurPtr,
   const char *PrefixEnd = [PrefixLen];
   if (PrefixLen == 16) {
 Diag(PrefixEnd, diag::err_raw_delim_too_long);
-  } else {
+  } else if (*PrefixEnd != '\n') {

akshaykumars614 wrote:

I implemented it in that way initially, but the PrefixLen variable is assigned 
with the last token of the translation file (which is usually \n) when it could 
not find '(' token. So, I couldn't find the practical scenario where the 
*PrefixEnd will be other than \n. Hence I flipped the cases.
Can you suggest any scenarios if you can remember on top of your head?

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


[clang] [clang][CodeGen] Add missing error check (PR #81777)

2024-02-14 Thread Jacob Lambert via cfe-commits

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


[clang] 7d28f19 - [clang][CodeGen] Add missing error check (#81777)

2024-02-14 Thread via cfe-commits

Author: Jacob Lambert
Date: 2024-02-14T11:25:58-08:00
New Revision: 7d28f19f68c82b65cf1180b170f33d6f82422d64

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

LOG: [clang][CodeGen] Add missing error check (#81777)

Add missing error check. This resolves "error: variable 'Err' set but
not used" warnings

Added: 


Modified: 
clang/lib/CodeGen/CodeGenAction.cpp

Removed: 




diff  --git a/clang/lib/CodeGen/CodeGenAction.cpp 
b/clang/lib/CodeGen/CodeGenAction.cpp
index ab08a875e7e9c1..bb9aaba025fa59 100644
--- a/clang/lib/CodeGen/CodeGenAction.cpp
+++ b/clang/lib/CodeGen/CodeGenAction.cpp
@@ -291,6 +291,9 @@ bool BackendConsumer::LinkInModules(llvm::Module *M, bool 
ShouldLinkFiles) {
   });
 } else
   Err = Linker::linkModules(*M, std::move(LM.Module), LM.LinkFlags);
+
+if (Err)
+  return true;
   }
 
   LinkModules.clear();



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


[clang] [llvm] [AIX] support builtin_cpu_is() for aix (PR #80069)

2024-02-14 Thread Lei Huang via cfe-commits


@@ -10347,6 +10347,8 @@ def err_x86_builtin_tile_arg_duplicate : Error<
 
 def err_builtin_target_unsupported : Error<
   "builtin is not supported on this target">;
+def err_builtin_aix_os_unsupported : Error<
+  "this builtin is available only on AIX 7.2 and later operating systems">;

lei137 wrote:

but line 10349 starts with "builtin is ..." better to be consistent no?

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


[clang] [clang][CodeGen] Add missing error check (PR #81777)

2024-02-14 Thread Jon Roelofs via cfe-commits

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

LGTM

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


[clang] bad error message on incorrect string literal #18079 (PR #81670)

2024-02-14 Thread Jon Roelofs via cfe-commits


@@ -100,7 +100,10 @@ def err_raw_delim_too_long : Error<
   "raw string delimiter longer than 16 characters"
   "; use PREFIX( )PREFIX to delimit raw string">;
 def err_invalid_char_raw_delim : Error<
-  "invalid character '%0' character in raw string delimiter"
+  "invalid newline character in raw string delimiter"

jroelofs wrote:

```suggestion
  "invalid character '%0' in raw string delimiter"
```

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


[clang] bad error message on incorrect string literal #18079 (PR #81670)

2024-02-14 Thread Jon Roelofs via cfe-commits


@@ -2270,9 +2270,11 @@ bool Lexer::LexRawStringLiteral(Token , const 
char *CurPtr,
   const char *PrefixEnd = [PrefixLen];
   if (PrefixLen == 16) {
 Diag(PrefixEnd, diag::err_raw_delim_too_long);
-  } else {
+  } else if (*PrefixEnd != '\n') {

jroelofs wrote:

Might make more sense to flip the condition, and swap the else-if/else cases.

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


[clang] [Clang] Unify interface for accessing template arguments as written for class/variable template specializations (PR #81642)

2024-02-14 Thread Krystian Stasiowski via cfe-commits


@@ -6316,6 +6310,15 @@ TEST(HasAnyTemplateArgumentLoc, 
BindsToSpecializationWithDoubleArgument) {
   hasTypeLoc(loc(asString("double")));
 }
 
+TEST(HasAnyTemplateArgumentLoc, BindsToExplicitSpecializationWithIntArgument) {
+  EXPECT_TRUE(
+  matches("template class A {}; template<> class A {};",
+  classTemplateSpecializationDecl(
+  hasName("A"), hasAnyTemplateArgument(templateArgument(
+refersToType(asString("int")));
+}
+
+#if 0

sdkrystian wrote:

Oh, hah. I was checking whether we could still match class template 
specializations based on template arguments. The commented out tests should be 
replaced with equivalents written using the above syntax (where it makes sense).

So to answer your question, it's from local testing :)

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


<    1   2   3   4   >