[Lldb-commits] [lldb] [Clang] Fix crash when ill-formed code is treated as a deduction guide (PR #67373)

2023-09-30 Thread via lldb-commits

https://github.com/cor3ntin edited 
https://github.com/llvm/llvm-project/pull/67373
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [Support] Add KnownBits::computeForSubBorrow (PR #67788)

2023-09-30 Thread Christian Kissig via lldb-commits

https://github.com/christiankissig updated 
https://github.com/llvm/llvm-project/pull/67788

>From 5d86936c3a48c613460983c980271fcab8128b75 Mon Sep 17 00:00:00 2001
From: Christian Kissig 
Date: Tue, 26 Sep 2023 12:18:59 +
Subject: [PATCH 1/5] [Support] Add KnownBits::computeForSubBorrow

* Implements computeForSubBorrow as alias for computeforAddCarry. Borrow
  is expected to be 1-bit wide.
* Adds exhaustive unit test.
---
 llvm/include/llvm/Support/KnownBits.h|  4 +++
 llvm/lib/Support/KnownBits.cpp   | 12 +
 llvm/unittests/Support/KnownBitsTest.cpp | 31 
 3 files changed, 47 insertions(+)

diff --git a/llvm/include/llvm/Support/KnownBits.h 
b/llvm/include/llvm/Support/KnownBits.h
index 8462aa11202d5d7..711ca8c12129a1b 100644
--- a/llvm/include/llvm/Support/KnownBits.h
+++ b/llvm/include/llvm/Support/KnownBits.h
@@ -332,6 +332,10 @@ struct KnownBits {
   static KnownBits computeForAddSub(bool Add, bool NSW, const KnownBits &LHS,
 KnownBits RHS);
 
+  /// Compute known bits results from subtracting RHS from LHS.
+  static KnownBits computeForSubBorrow(const KnownBits &LHS, KnownBits RHS,
+   const KnownBits &Borrow);
+
   /// Compute knownbits resulting from llvm.sadd.sat(LHS, RHS)
   static KnownBits sadd_sat(const KnownBits &LHS, const KnownBits &RHS);
 
diff --git a/llvm/lib/Support/KnownBits.cpp b/llvm/lib/Support/KnownBits.cpp
index 097c22d33dd12ba..99ac50a34666fce 100644
--- a/llvm/lib/Support/KnownBits.cpp
+++ b/llvm/lib/Support/KnownBits.cpp
@@ -85,6 +85,18 @@ KnownBits KnownBits::computeForAddSub(bool Add, bool NSW,
   return KnownOut;
 }
 
+KnownBits KnownBits::computeForSubBorrow(const KnownBits &LHS, KnownBits RHS,
+ const KnownBits &Borrow) {
+  assert(Borrow.getBitWidth() == 1 && "Borrow must be 1-bit");
+
+  // LHS - RHS = LHS + ~RHS + 1
+  // Carry 1 - Borrow in ::computeForAddCarry
+  std::swap(RHS.Zero, RHS.One);
+  return ::computeForAddCarry(LHS, RHS,
+  /*CarryZero*/ Borrow.One.getBoolValue(),
+  /*CarryOne*/ Borrow.Zero.getBoolValue());
+}
+
 KnownBits KnownBits::sextInReg(unsigned SrcBitWidth) const {
   unsigned BitWidth = getBitWidth();
   assert(0 < SrcBitWidth && SrcBitWidth <= BitWidth &&
diff --git a/llvm/unittests/Support/KnownBitsTest.cpp 
b/llvm/unittests/Support/KnownBitsTest.cpp
index 9d184beea3ba9e9..5597d69ab248d23 100644
--- a/llvm/unittests/Support/KnownBitsTest.cpp
+++ b/llvm/unittests/Support/KnownBitsTest.cpp
@@ -213,6 +213,37 @@ TEST(KnownBitsTest, AddSubExhaustive) {
   TestAddSubExhaustive(false);
 }
 
+TEST(KnownBitsTest, SubBorrowExhaustive) {
+  unsigned Bits = 4;
+  ForeachKnownBits(Bits, [&](const KnownBits &Known1) {
+ForeachKnownBits(Bits, [&](const KnownBits &Known2) {
+  ForeachKnownBits(1, [&](const KnownBits &KnownBorrow) {
+// Explicitly compute known bits of the addition by trying all
+// possibilities.
+KnownBits Known(Bits);
+Known.Zero.setAllBits();
+Known.One.setAllBits();
+ForeachNumInKnownBits(Known1, [&](const APInt &N1) {
+  ForeachNumInKnownBits(Known2, [&](const APInt &N2) {
+ForeachNumInKnownBits(KnownBorrow, [&](const APInt &Borrow) {
+  APInt Sub = N1 - N2;
+  if (Borrow.getBoolValue())
+--Sub;
+
+  Known.One &= Sub;
+  Known.Zero &= ~Sub;
+});
+  });
+});
+
+KnownBits KnownComputed =
+KnownBits::computeForSubBorrow(Known1, Known2, KnownBorrow);
+EXPECT_EQ(Known, KnownComputed);
+  });
+});
+  });
+}
+
 TEST(KnownBitsTest, BinaryExhaustive) {
   testBinaryOpExhaustive(
   [](const KnownBits &Known1, const KnownBits &Known2) {

>From f84c882cf429df238054d88ee07e41a08ae3fd6c Mon Sep 17 00:00:00 2001
From: Christian Kissig 
Date: Tue, 26 Sep 2023 18:02:49 +
Subject: [PATCH 2/5] [CodeGen] Implement USUBC, USUBO_CARRY, and SSUBO_CARRY
 with KnownBits::computeForSubBorrow

---
 .../lib/CodeGen/SelectionDAG/SelectionDAG.cpp | 12 ++
 .../CodeGen/AArch64SelectionDAGTest.cpp   | 24 +++
 2 files changed, 32 insertions(+), 4 deletions(-)

diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp 
b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index cd21af770e1a4d9..ab3e9b4bdc67402 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -3732,14 +3732,18 @@ KnownBits SelectionDAG::computeKnownBits(SDValue Op, 
const APInt &DemandedElts,
 assert(Op.getResNo() == 0 &&
"We only compute knownbits for the difference here.");
 
-// TODO: Compute influence of the carry operand.
+// With UADDO_CARRY and SSUBO_CARRY a borrow bit may be added in.
+KnownBits Borrow(1);
 if (Opcode == ISD::USUBO_CARRY || Opcode == ISD:

[Lldb-commits] [lldb] [Clang] Fix crash when ill-formed code is treated as a deduction guide (PR #67373)

2023-09-30 Thread Shafik Yaghmour via lldb-commits

https://github.com/shafik updated 
https://github.com/llvm/llvm-project/pull/67373

>From beab5db738483795ecb0bace2842acdbb1c9869a Mon Sep 17 00:00:00 2001
From: Shafik Yaghmour 
Date: Mon, 25 Sep 2023 13:56:43 -0700
Subject: [PATCH 1/2] [Clang] Fix crash when ill-formed code is treated as a
 deduction guide

In some cases where ill-formed code could be interpreted as a deduction guide
we can crash because we reach an unreachable path. This fixes this issue by
introducing a diagnostic instead.

Fixes: https://github.com/llvm/llvm-project/issues/65522
---
 clang/include/clang/Basic/DiagnosticSemaKinds.td |  2 ++
 clang/lib/Sema/SemaTemplateInstantiate.cpp   |  4 +++-
 clang/test/SemaCXX/gh65522.cpp   | 11 +++
 3 files changed, 16 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/SemaCXX/gh65522.cpp

diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td 
b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index f4eb02fd9570c2f..c3c1810fd7934a2 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -5414,6 +5414,8 @@ def note_constraint_normalization_here : Note<
 def note_parameter_mapping_substitution_here : Note<
   "while substituting into concept arguments here; substitution failures not "
   "allowed in concept arguments">;
+def note_building_deduction_guide_here : Note<
+  "while building implicit deduction guide first needed here">;
 def note_lambda_substitution_here : Note<
   "while substituting into a lambda expression here">;
 def note_instantiation_contexts_suppressed : Note<
diff --git a/clang/lib/Sema/SemaTemplateInstantiate.cpp 
b/clang/lib/Sema/SemaTemplateInstantiate.cpp
index 00a36696cf90450..1ed3df5a011bcb6 100644
--- a/clang/lib/Sema/SemaTemplateInstantiate.cpp
+++ b/clang/lib/Sema/SemaTemplateInstantiate.cpp
@@ -1075,7 +1075,9 @@ void Sema::PrintInstantiationStack() {
   << Active->InstantiationRange;
   break;
 case CodeSynthesisContext::BuildingDeductionGuides:
-  llvm_unreachable("unexpected deduction guide in instantiation stack");
+  Diags.Report(Active->PointOfInstantiation,
+   diag::note_building_deduction_guide_here);
+  break;
 }
   }
 }
diff --git a/clang/test/SemaCXX/gh65522.cpp b/clang/test/SemaCXX/gh65522.cpp
new file mode 100644
index 000..2d6331b0372a31d
--- /dev/null
+++ b/clang/test/SemaCXX/gh65522.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -std=c++20 -Wc++17-compat -verify -Wno-unused %s
+
+class X {};
+
+template
+class B3 { // expected-note {{candidate template ignored: could not match 
'B3' against 'int'}}
+  template B3(T); // expected-warning 2{{non-type template parameter of 
type 'X' is incompatible with C++ standards before C++20}} \
+   // expected-note {{candidate template ignored: couldn't 
infer template argument 'x'}}
+};
+B3 b3 = 0; // expected-error {{no viable constructor or deduction guide for 
deduction of template arguments of 'B3'}} \
+   // expected-note {{while building implicit deduction guide first 
needed here}}

>From 32d948f9cd73ef7fc7e6900ac4ccdb204ffd3298 Mon Sep 17 00:00:00 2001
From: Shafik Yaghmour 
Date: Sat, 30 Sep 2023 15:08:04 -0700
Subject: [PATCH 2/2] Fix release note

---
 clang/docs/ReleaseNotes.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 58753884ec0cc2e..79c495d072b2dd3 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -377,7 +377,7 @@ Bug Fixes to C++ Support
 
 - Fix crash where ill-formed code was being treated as a deduction guide and
   we now produce a diagnostic. Fixes:
-  (`65522 `_)
+  (`#65522 `_)
 
 Bug Fixes to AST Handling
 ^

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


[Lldb-commits] [lldb] dc1a2cb - [lldb][windows] Cover more symbols in LLDB_EXPORT_ALL_SYMBOLS

2023-09-30 Thread River Riddle via lldb-commits

Author: River Riddle
Date: 2023-09-30T16:06:19-07:00
New Revision: dc1a2cb9718966e9050e32962dc86377088f2d7e

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

LOG: [lldb][windows] Cover more symbols in LLDB_EXPORT_ALL_SYMBOLS

Followup to #67628 that relaxes the symbol regex a bit to cover more
lldb_private symbols.

Added: 


Modified: 
lldb/scripts/msvc_extract_private_symbols.py

Removed: 




diff  --git a/lldb/scripts/msvc_extract_private_symbols.py 
b/lldb/scripts/msvc_extract_private_symbols.py
index 05e8b0e2095ca33..b741310d717c23c 100644
--- a/lldb/scripts/msvc_extract_private_symbols.py
+++ b/lldb/scripts/msvc_extract_private_symbols.py
@@ -18,7 +18,7 @@ def extract_symbols(nm_path: str, lib: str):
 library to extract from."""
 
 # Matches mangled symbols containing 'lldb_private'.
-lldb_sym_re = r"0* [BT] (?P[?]+[^?].*lldb_private.*)"
+lldb_sym_re = r"[0-9a-zA-Z]* [BT] (?P[?]+[^?].*lldb_private.*)"
 
 # '-g' means we only get global symbols.
 # '-p' do not waste time sorting the symbols.



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