[Lldb-commits] [lld] [llvm] [compiler-rt] [libc] [clang] [flang] [libunwind] [clang-tools-extra] [libcxx] [lldb] [GVN] Disable GVN PRE on target hasBranchDivergence (PR #77069)

2024-01-08 Thread via lldb-commits

https://github.com/fengfeng09 updated 
https://github.com/llvm/llvm-project/pull/77069

>From 17a9072758d9f443d0f7bca8862fec5a793c3dba Mon Sep 17 00:00:00 2001
From: "feng.feng" 
Date: Mon, 11 Dec 2023 15:14:32 +0800
Subject: [PATCH] [GVN] Disable GVN PRE on target hasBranchDivergence

Signed-off-by: feng.feng 
---
 llvm/lib/Transforms/Scalar/GVN.cpp | 5 +
 1 file changed, 5 insertions(+)

diff --git a/llvm/lib/Transforms/Scalar/GVN.cpp 
b/llvm/lib/Transforms/Scalar/GVN.cpp
index e36578f3de7ac4..777dec04faf9f6 100644
--- a/llvm/lib/Transforms/Scalar/GVN.cpp
+++ b/llvm/lib/Transforms/Scalar/GVN.cpp
@@ -41,6 +41,7 @@
 #include "llvm/Analysis/OptimizationRemarkEmitter.h"
 #include "llvm/Analysis/PHITransAddr.h"
 #include "llvm/Analysis/TargetLibraryInfo.h"
+#include "llvm/Analysis/TargetTransformInfo.h"
 #include "llvm/Analysis/ValueTracking.h"
 #include "llvm/IR/Attributes.h"
 #include "llvm/IR/BasicBlock.h"
@@ -750,6 +751,10 @@ bool GVNPass::isMemDepEnabled() const {
 }
 
 PreservedAnalyses GVNPass::run(Function &F, FunctionAnalysisManager &AM) {
+  // Disable PRE on GPU.
+  auto &TTI = AM.getResult(F);
+  if (TTI.hasBranchDivergence())
+GVNEnablePRE = false;
   // FIXME: The order of evaluation of these 'getResult' calls is very
   // significant! Re-ordering these variables will cause GVN when run alone to
   // be less effective! We should fix memdep and basic-aa to not exhibit this

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


[Lldb-commits] [lldb] [lldb][DWARFASTParserClang] GetClangDeclForDIE: don't create VarDecl for static data members (PR #77155)

2024-01-08 Thread Michael Buch via lldb-commits


@@ -0,0 +1,23 @@
+# UNSUPPORTED: system-darwin, system-windows
+
+# In DWARFv5, C++ static data members are represented
+# as DW_TAG_variable. We make sure LLDB's expression
+# evaluator doesn't crash when trying to parse such
+# a DW_TAG_variable DIE, whose parent DIE is only
+# a forward declaration.
+
+# RUN: %clangxx_host %S/Inputs/dwo-static-data-member.cpp \
+# RUN:   -g -gdwarf-5 -gsplit-dwarf -o %t
+# RUN: %lldb %t -s %s -o exit 2>&1 | FileCheck %s
+
+breakpoint set -n main
+process launch
+
+# CHECK: Process {{.*}} stopped
+
+# There is no definition for NoCtor anywhere
+# in the debug-info, so LLDB can't evaluate
+# this expression.
+expression NoCtor::i
+# CHECK-LABEL: expression NoCtor::i
+# CHECK:   use of undeclared identifier 'NoCtor'

Michael137 wrote:

Agreed, I'll rephrase the comment

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


[Lldb-commits] [compiler-rt] [libc] [lldb] [clang] [llvm] [flang] [libcxx] [clang-tools-extra] [flang] FDATE extension implementation: get date and time in ctime format (PR #71222)

2024-01-08 Thread Yi Wu via lldb-commits

yi-wu-arm wrote:

Hi @jeanPerier I have made some changes, mainly on test cases and use `char *` 
instead of `std::int_8t` for arg input. Saw your activity on GitHub, could you 
review the changes? Thanks in advance!

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


[Lldb-commits] [lldb] [lldb][DWARFASTParserClang] GetClangDeclForDIE: don't create VarDecl for static data members (PR #77155)

2024-01-08 Thread Michael Buch via lldb-commits


@@ -0,0 +1,23 @@
+# UNSUPPORTED: system-darwin, system-windows

Michael137 wrote:

As @dwblaikie points out, we need a process to run the expression. But if we 
specify `-flimit-debug-info` I can repro the crash on Darwin too, so we can 
remove `UNSUPPORTED` here and get the coverage that way.

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


[Lldb-commits] [lldb] Add support for inline DWARF source files. (PR #75880)

2024-01-08 Thread David Spickett via lldb-commits

DavidSpickett wrote:

This is failing on Windows: 
https://lab.llvm.org/buildbot/#/builders/219/builds/7982

Any obvious reason that this would be happening? I do see the DWARF in the 
binary:
```
0x0078: DW_TAG_compile_unit
  DW_AT_producer("clang version 18.0.0git 
(g...@github.com:llvm/llvm-project.git 
29ee66f4a0967e43a035f147c960743c7b640f2f)")
  DW_AT_language(DW_LANG_C11)
  DW_AT_name("/INLINE/inlined.c")
  DW_AT_LLVM_sysroot("/")
  DW_AT_str_offsets_base(0x0034)
  DW_AT_stmt_list   (0x007a)
  DW_AT_comp_dir("/Volumes/Data/llvm-project")
  DW_AT_low_pc  (0x000140001034)
  DW_AT_high_pc (0x000140001044)
  DW_AT_addr_base   (0x0020)

0x0090:   DW_TAG_subprogram
DW_AT_low_pc(0x000140001034)
DW_AT_high_pc   (0x000140001044)
DW_AT_frame_base(DW_OP_reg31 WSP)
DW_AT_name  ("f")
DW_AT_decl_file (0x01)
DW_AT_decl_line (2)
DW_AT_external  (true)

0x009b:   NULL
```
Maybe it is path style, but at least at a glance, the code is handling that.

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


[Lldb-commits] [libc] [libcxx] [compiler-rt] [llvm] [lld] [clang] [clang-tools-extra] [lldb] [mlir] [MLIR][LLVM] Add Continuous Loop Peeling transform to SCF (PR #71555)

2024-01-08 Thread via lldb-commits

https://github.com/muneebkhan85 updated 
https://github.com/llvm/llvm-project/pull/71555

>From 7bb2f9793b2a2cccbaa401f6e2ac850b587f2b59 Mon Sep 17 00:00:00 2001
From: Muneeb Khan 
Date: Tue, 7 Nov 2023 23:52:17 +0800
Subject: [PATCH 01/11] [MLIR][LLVM] Add Continuous Loop Peeling transform to
 SCF

This patch adds continuous loop peeling to scf loop transforms
in the MLIR backend. This transforms the target loop into a
chain of loops, with step sizes that are powers of two and
decrease exponetially across subsequent loops. Originally
authored by Litu Zhou litu.z...@huawei.com.
---
 .../SCF/TransformOps/SCFTransformOps.td   |  36 +
 .../SCF/TransformOps/SCFTransformOps.cpp  | 147 ++
 .../Dialect/SCF/loop-continuous-peel.mlir |  98 
 3 files changed, 281 insertions(+)
 create mode 100644 mlir/test/Dialect/SCF/loop-continuous-peel.mlir

diff --git a/mlir/include/mlir/Dialect/SCF/TransformOps/SCFTransformOps.td 
b/mlir/include/mlir/Dialect/SCF/TransformOps/SCFTransformOps.td
index 14df7e23a430fb..e3d79a7f0ae40f 100644
--- a/mlir/include/mlir/Dialect/SCF/TransformOps/SCFTransformOps.td
+++ b/mlir/include/mlir/Dialect/SCF/TransformOps/SCFTransformOps.td
@@ -147,6 +147,42 @@ def LoopPeelOp : Op {
+  let description = [{
+Transforms the loop into a chain of loops, with step sizes that are
+powers of two and decrease exponetially across subsequent loops.
+The transform is similar to loop.peel in the effect that it creates a loop
+with a step (that is power of 2) to divide the range evenly, with the
+difference that the remaining iterations are spread across similar loops
+with exponentially decreasing step sizes, with the last loop with step size
+of 2^0 = 1.
+
+ Return modes
+
+This operation consumes the `target` handles and produces the
+continuously-peeled loop.
+  }];
+
+  let arguments =
+  (ins TransformHandleTypeInterface:$target,
+   DefaultValuedAttr:$single_iter_opt);
+  // TODO: Return both the peeled loop and the remainder loop.
+  let results = (outs TransformHandleTypeInterface:$transformed);
+
+  let assemblyFormat =
+"$target attr-dict `:` functional-type(operands, results)";
+
+  let extraClassDeclaration = [{
+::mlir::DiagnosedSilenceableFailure applyToOne(
+::mlir::transform::TransformRewriter &rewriter,
+::mlir::Operation *target,
+::mlir::transform::ApplyToEachResultList &results,
+::mlir::transform::TransformState &state);
+  }];
+}
+
 def LoopPipelineOp : Op {
diff --git a/mlir/lib/Dialect/SCF/TransformOps/SCFTransformOps.cpp 
b/mlir/lib/Dialect/SCF/TransformOps/SCFTransformOps.cpp
index 62370604142cd5..dcba6a8b406b21 100644
--- a/mlir/lib/Dialect/SCF/TransformOps/SCFTransformOps.cpp
+++ b/mlir/lib/Dialect/SCF/TransformOps/SCFTransformOps.cpp
@@ -206,6 +206,153 @@ 
transform::LoopPeelOp::applyToOne(transform::TransformRewriter &rewriter,
   return DiagnosedSilenceableFailure::success();
 }
 
+//===-===//
+// LoopContinuousPeelOp
+//===-===//
+
+static LogicalResult splitLoopHelper(RewriterBase &b, scf::ForOp &forOp,
+ scf::ForOp &partialIteration,
+ Value &splitBound) {
+  RewriterBase::InsertionGuard guard(b);
+  auto lbInt = getConstantIntValue(forOp.getLowerBound());
+  auto ubInt = getConstantIntValue(forOp.getUpperBound());
+  auto stepInt = getConstantIntValue(forOp.getStep());
+
+  // No specialization necessary if step already divides upper bound evenly.
+  if (lbInt && ubInt && stepInt && (*ubInt - *lbInt) % *stepInt == 0)
+return failure();
+  // No specialization necessary if step size is 1.
+  if (stepInt == static_cast(1))
+return failure();
+
+  // Create ForOp for partial iteration.
+  b.setInsertionPointAfter(forOp);
+  partialIteration = cast(b.clone(*forOp.getOperation()));
+  partialIteration.getLowerBoundMutable().assign(splitBound);
+  forOp.replaceAllUsesWith(partialIteration->getResults());
+  partialIteration.getInitArgsMutable().assign(forOp->getResults());
+
+  // Set new upper loop bound.
+  b.updateRootInPlace(
+  forOp, [&]() { forOp.getUpperBoundMutable().assign(splitBound); });
+
+  return success();
+}
+
+static scf::IfOp convertSingleIterFor(RewriterBase &b, scf::ForOp &forOp) {
+  Location loc = forOp->getLoc();
+  IRMapping mapping;
+  mapping.map(forOp.getInductionVar(), forOp.getLowerBound());
+  for (auto [arg, operand] :
+   llvm::zip(forOp.getRegionIterArgs(), forOp.getInitsMutable())) {
+mapping.map(arg, operand.get());
+  }
+  b.setInsertionPoint(forOp);
+  auto cond =
+  b.create(loc, arith::CmpIPredicate::slt,
+  forOp.getLowerBound(), forOp.getUpperBound());
+  auto ifOp = b.create(loc, forOp->getResultTypes(), cond, true);
+  // then branch
+  b.setIns

[Lldb-commits] [lldb] 8b49ed8 - [lldb][test] Skip DWARF inline source file test on Windows

2024-01-08 Thread David Spickett via lldb-commits

Author: David Spickett
Date: 2024-01-08T12:11:52Z
New Revision: 8b49ed8ba1ba5ecd35bd1efa4be5a0f56b0135b8

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

LOG: [lldb][test] Skip DWARF inline source file test on Windows

This was added by 917b404e2ccdcc31d2d64971ad094b80967a240b
and fails for unknown reasons.

Added: 


Modified: 
lldb/test/API/functionalities/inline-sourcefile/TestInlineSourceFiles.py

Removed: 




diff  --git 
a/lldb/test/API/functionalities/inline-sourcefile/TestInlineSourceFiles.py 
b/lldb/test/API/functionalities/inline-sourcefile/TestInlineSourceFiles.py
index 20ed0ce00661f0..ad10a63e601329 100644
--- a/lldb/test/API/functionalities/inline-sourcefile/TestInlineSourceFiles.py
+++ b/lldb/test/API/functionalities/inline-sourcefile/TestInlineSourceFiles.py
@@ -8,6 +8,8 @@
 class InlineSourceFilesTestCase(TestBase):
 @skipIf(compiler="gcc")
 @skipIf(compiler="clang", compiler_version=["<", "18.0"])
+# Fails on Windows for unknown reasons.
+@skipIfWindows
 def test(self):
 """Test DWARF inline source files."""
 self.build()



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


[Lldb-commits] [lldb] [lldb][DWARFASTParserClang] GetClangDeclForDIE: don't create VarDecl for static data members (PR #77155)

2024-01-08 Thread Michael Buch via lldb-commits

https://github.com/Michael137 updated 
https://github.com/llvm/llvm-project/pull/77155

>From cf109ab8ed2a6c3e139c168375649ab4651c4ec4 Mon Sep 17 00:00:00 2001
From: Michael Buch 
Date: Fri, 5 Jan 2024 12:45:46 +
Subject: [PATCH 1/2] [lldb][DWARFASTParserClang] GetClangDeclForDIE: don't
 create VarDecl for static data members

With DWARFv5, C++ static data members are represented as
`DW_TAG_variable`s (see `faa3a5ea9ae481da757dab1c95c589e2d5645982`).

In GetClangDeclForDIE, when trying to parse the `DW_AT_specification`
that the CU-level DW_TAG_variable points to, we would try to
`CreateVariableDeclaration`, because the static member is a `DW_TAG_variable`
too. Whereas previously it was a no-op (for `DW_TAG_member`s).

Adding `VarDecls` to RecordDecls for static data members should always be
done in `CreateStaticMemberVariable`. The test-case is an exapmle where
we would crash if we tried to create a `VarDecl` from within
`GetClangDeclForDIE` for a static data member.

This patch simply checks whether the `DW_TAG_variable` being parsed is
a static data member, and if so, trivially return from
`GetClangDeclForDIE` (as we previously did for `DW_TAG_member`s).
---
 .../SymbolFile/DWARF/DWARFASTParserClang.cpp  | 21 -
 .../DWARF/Inputs/dwo-static-data-member.cpp   |  8 +++
 .../DWARF/dwo-static-data-member-access.test  | 23 +++
 3 files changed, 51 insertions(+), 1 deletion(-)
 create mode 100644 
lldb/test/Shell/SymbolFile/DWARF/Inputs/dwo-static-data-member.cpp
 create mode 100644 
lldb/test/Shell/SymbolFile/DWARF/dwo-static-data-member-access.test

diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
index 3e08f2550081f2..771d33bf8ff7ae 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -142,6 +142,18 @@ static bool ShouldIgnoreArtificialField(llvm::StringRef 
FieldName) {
  || FieldName.starts_with("_vptr.");
 }
 
+/// Returns true for C++ constructs represented by clang::CXXRecordDecl
+static bool TagIsRecordType(dw_tag_t tag) {
+  switch (tag) {
+  case DW_TAG_class_type:
+  case DW_TAG_structure_type:
+  case DW_TAG_union_type:
+return true;
+  default:
+return false;
+  }
+}
+
 TypeSP DWARFASTParserClang::ParseTypeFromClangModule(const SymbolContext &sc,
  const DWARFDIE &die,
  Log *log) {
@@ -3293,12 +3305,19 @@ clang::Decl 
*DWARFASTParserClang::GetClangDeclForDIE(const DWARFDIE &die) {
 return nullptr;
 
   switch (die.Tag()) {
-  case DW_TAG_variable:
   case DW_TAG_constant:
   case DW_TAG_formal_parameter:
   case DW_TAG_imported_declaration:
   case DW_TAG_imported_module:
 break;
+  case DW_TAG_variable:
+// This means 'die' is a C++ static data member.
+// We don't want to create decls for such members
+// here.
+if (auto parent = die.GetParent();
+parent.IsValid() && TagIsRecordType(parent.Tag()))
+  return nullptr;
+break;
   default:
 return nullptr;
   }
diff --git a/lldb/test/Shell/SymbolFile/DWARF/Inputs/dwo-static-data-member.cpp 
b/lldb/test/Shell/SymbolFile/DWARF/Inputs/dwo-static-data-member.cpp
new file mode 100644
index 00..fa7c3500df0f9d
--- /dev/null
+++ b/lldb/test/Shell/SymbolFile/DWARF/Inputs/dwo-static-data-member.cpp
@@ -0,0 +1,8 @@
+struct NoCtor {
+  NoCtor();
+  static int i;
+};
+
+int NoCtor::i = 15;
+
+int main() { return NoCtor::i; }
diff --git 
a/lldb/test/Shell/SymbolFile/DWARF/dwo-static-data-member-access.test 
b/lldb/test/Shell/SymbolFile/DWARF/dwo-static-data-member-access.test
new file mode 100644
index 00..da5a862c35568f
--- /dev/null
+++ b/lldb/test/Shell/SymbolFile/DWARF/dwo-static-data-member-access.test
@@ -0,0 +1,23 @@
+# UNSUPPORTED: system-darwin, system-windows
+
+# In DWARFv5, C++ static data members are represented
+# as DW_TAG_variable. We make sure LLDB's expression
+# evaluator doesn't crash when trying to parse such
+# a DW_TAG_variable DIE, whose parent DIE is only
+# a forward declaration.
+
+# RUN: %clangxx_host %S/Inputs/dwo-static-data-member.cpp \
+# RUN:   -g -gdwarf-5 -gsplit-dwarf -o %t
+# RUN: %lldb %t -s %s -o exit 2>&1 | FileCheck %s
+
+breakpoint set -n main
+process launch
+
+# CHECK: Process {{.*}} stopped
+
+# There is no definition for NoCtor anywhere
+# in the debug-info, so LLDB can't evaluate
+# this expression.
+expression NoCtor::i
+# CHECK-LABEL: expression NoCtor::i
+# CHECK:   use of undeclared identifier 'NoCtor'

>From d368ce332c3466f017658102728f8e1ca1305d30 Mon Sep 17 00:00:00 2001
From: Michael Buch 
Date: Mon, 8 Jan 2024 12:12:06 +
Subject: [PATCH 2/2] fixup! rephrase test comment and enable test on other
 platforms

---
 .../DWARF/dwo-static-data-member-access.test| 13 +++--
 1 file changed,

[Lldb-commits] [lldb] Add support for inline DWARF source files. (PR #75880)

2024-01-08 Thread David Spickett via lldb-commits

DavidSpickett wrote:

Skipped for now 
https://github.com/llvm/llvm-project/commit/8b49ed8ba1ba5ecd35bd1efa4be5a0f56b0135b8

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


[Lldb-commits] [lldb] ba4cf31 - [lldb][test] Skip part of nested expressions test on Windows

2024-01-08 Thread David Spickett via lldb-commits

Author: David Spickett
Date: 2024-01-08T12:17:16Z
New Revision: ba4cf31facdaf9bb9943c057d325ff0968331e9a

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

LOG: [lldb][test] Skip part of nested expressions test on Windows

This was added by e42edb5547618c172abe25914000bb61f5278c4c and
has been failing: https://lab.llvm.org/buildbot/#/builders/219/builds/8012

Added: 


Modified: 
lldb/test/API/commands/expression/nested/TestNestedExpressions.py

Removed: 




diff  --git a/lldb/test/API/commands/expression/nested/TestNestedExpressions.py 
b/lldb/test/API/commands/expression/nested/TestNestedExpressions.py
index 7f194e921e5628..6a97d4f34e6792 100644
--- a/lldb/test/API/commands/expression/nested/TestNestedExpressions.py
+++ b/lldb/test/API/commands/expression/nested/TestNestedExpressions.py
@@ -33,6 +33,8 @@ def test_struct_in_nested_structs(self):
 self.expect_expr("sizeof(A::B::C)", result_value="1")
 self.expect_expr("sizeof(A::B)", result_value="2")
 
+# Fails on Windows for unknown reasons.
+@skipIfWindows
 def test_static_in_nested_structs(self):
 """
 Test expressions that references a static variable in nested 
structs.



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


[Lldb-commits] [lldb] [lldb] Fix expressions that involve nested structs/classes/unions. (PR #77029)

2024-01-08 Thread David Spickett via lldb-commits

DavidSpickett wrote:

One of the new tests fails on Windows:
```
FAIL: test_static_in_nested_structs_dwarf 
(TestNestedExpressions.NestedExpressions)

--

Traceback (most recent call last):

  File 
"C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\llvm-project\lldb\packages\Python\lldbsuite\test\lldbtest.py",
 line 1696, in test_method

return attrvalue(self)

   ^^^

  File 
"C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\llvm-project\lldb\test\API\commands\expression\nested\TestNestedExpressions.py",
 line 44, in test_static_in_nested_structs

self.expect_expr("A::B::C::enum_static",

  File 
"C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\llvm-project\lldb\packages\Python\lldbsuite\test\lldbtest.py",
 line 2508, in expect_expr

value_check.check_value(self, eval_result, str(eval_result))

  File 
"C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\llvm-project\lldb\packages\Python\lldbsuite\test\lldbtest.py",
 line 300, in check_value

test_base.assertSuccess(val.GetError())

  File 
"C:\Users\tcwg\llvm-worker\lldb-aarch64-windows\llvm-project\lldb\packages\Python\lldbsuite\test\lldbtest.py",
 line 2543, in assertSuccess

self.fail(self._formatMessage(msg, "'{}' is not success".format(error)))

AssertionError: 'error: Couldn't look up symbols:

  A::B::C::enum_static

' is not success
```
But given the other issues we've had lately, it's not surprising.

I've skipped it for now - 
https://github.com/llvm/llvm-project/commit/ba4cf31facdaf9bb9943c057d325ff0968331e9a.

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


[Lldb-commits] [lldb] [lldb] DWARFDIE: Follow DW_AT_specification when computing CompilerCo… (PR #77157)

2024-01-08 Thread Michael Buch via lldb-commits


@@ -2574,11 +2574,12 @@ void SymbolFileDWARF::FindFunctions(const 
Module::LookupInfo &lookup_info,
 
   Module::LookupInfo no_tp_lookup_info(lookup_info);
   no_tp_lookup_info.SetLookupName(ConstString(name_no_template_params));
-  m_index->GetFunctions(no_tp_lookup_info, *this, parent_decl_ctx, 
[&](DWARFDIE die) {
-if (resolved_dies.insert(die.GetDIE()).second)
-  ResolveFunction(die, include_inlines, sc_list);
-return true;
-  });
+  m_index->GetFunctions(no_tp_lookup_info, *this, parent_decl_ctx,

Michael137 wrote:

Seems to be just a formatting change?

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


[Lldb-commits] [lldb] [lldb] DWARFDIE: Follow DW_AT_specification when computing CompilerCo… (PR #77157)

2024-01-08 Thread Michael Buch via lldb-commits


@@ -375,16 +375,21 @@ std::vector DWARFDIE::GetDeclContextDIEs() 
const {
 
 std::vector DWARFDIE::GetDeclContext() const {
   std::vector context;
-  const dw_tag_t tag = Tag();
-  if (tag == DW_TAG_compile_unit || tag == DW_TAG_partial_unit)
-return context;
   DWARFDIE parent = GetParent();
-  if (parent)
+  if (parent) {
+const dw_tag_t parent_tag = parent.Tag();
+if (parent_tag == DW_TAG_compile_unit || parent_tag == DW_TAG_partial_unit)

Michael137 wrote:

Could specifications also appear not at CU-level?

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


[Lldb-commits] [lldb] [lldb] DWARFDIE: Follow DW_AT_specification when computing CompilerCo… (PR #77157)

2024-01-08 Thread Michael Buch via lldb-commits


@@ -404,7 +409,7 @@ std::vector 
DWARFDIE::GetDeclContext() const {
 push_ctx(CompilerContextKind::Enum, GetName());
 break;
   case DW_TAG_subprogram:
-push_ctx(CompilerContextKind::Function, GetPubname());
+push_ctx(CompilerContextKind::Function, GetName());

Michael137 wrote:

What's the impact of this change? Looks like previously if a 
`DW_TAG_subprogram` had a linkage name, we'd put that into the 
`CompilerContext`? Is that not necessary anymore?

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


[Lldb-commits] [lldb] [lldb][NFCI] Change return type of BreakpointIDList::GetBreakpointIDAtIndex (PR #77166)

2024-01-08 Thread Felipe de Azevedo Piovezan via lldb-commits

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

Nice catch!

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


[Lldb-commits] [lldb] [lldb][NFCI] Remove BreakpointIDList::InsertStringArray (PR #77161)

2024-01-08 Thread Felipe de Azevedo Piovezan via lldb-commits

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

LGTM!

I see that we still have `FindAndReplaceIDRanges` referencing 
CommandReturnObject; out of curiosity, have you had a chance to look into 
removing that one (if it makes sense)? I see that `CommandReturnObject` is 
neither `#include`ed nor forward declared in the header, so the code is very 
much relying on others files to do either of those.

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


[Lldb-commits] [lldb] [lldb] DWARFDIE: Follow DW_AT_specification when computing CompilerCo… (PR #77157)

2024-01-08 Thread Felipe de Azevedo Piovezan via lldb-commits

https://github.com/felipepiovezan commented:

Btw this reminds me a lot of accelerator tables & finding the parents of 
functions there.
Because the declaration is never placed in the accelerator table (and the 
declaration is what has the scope), we are never able to find the parent of 
functions with the accelerator tables.

We might be able to do a similar trick there as to what you are doing here

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


[Lldb-commits] [lldb] [lldb] DWARFDIE: Follow DW_AT_specification when computing CompilerCo… (PR #77157)

2024-01-08 Thread Felipe de Azevedo Piovezan via lldb-commits


@@ -855,6 +855,23 @@ void Module::FindFunctions(ConstString name,
   }
 }
 
+void Module::FindFunctions(llvm::ArrayRef compiler_ctx,
+   FunctionNameType name_type_mask,
+   const ModuleFunctionSearchOptions &options,
+   SymbolContextList &sc_list) {
+  if (compiler_ctx.empty() ||
+  compiler_ctx.back().kind != CompilerContextKind::Function)
+return;
+  ConstString name = compiler_ctx.back().name;
+  CompilerDeclContext dc;

felipepiovezan wrote:

We can express that this a virtually useless variable by inlining the ctor into 
the `FindFunctions` call. 
The way this is written now, readers are led to believe the variable is either 
used later, or that `dc` is updated by `FindFunctions`; neither are true.

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


[Lldb-commits] [lldb] [lldb] DWARFDIE: Follow DW_AT_specification when computing CompilerCo… (PR #77157)

2024-01-08 Thread Felipe de Azevedo Piovezan via lldb-commits


@@ -855,6 +855,23 @@ void Module::FindFunctions(ConstString name,
   }
 }
 
+void Module::FindFunctions(llvm::ArrayRef compiler_ctx,
+   FunctionNameType name_type_mask,
+   const ModuleFunctionSearchOptions &options,
+   SymbolContextList &sc_list) {
+  if (compiler_ctx.empty() ||
+  compiler_ctx.back().kind != CompilerContextKind::Function)
+return;
+  ConstString name = compiler_ctx.back().name;
+  CompilerDeclContext dc;
+  SymbolContextList unfiltered;
+  FindFunctions(name, dc,name_type_mask, options, unfiltered);
+  // Filter by context.
+  for (auto sc : unfiltered)

felipepiovezan wrote:

We're making copies of a pretty big class (two shared pointers, 5 pointers, one 
LineEntry):

```
const auto &sc
```

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


[Lldb-commits] [lldb] [lldb] DWARFDIE: Follow DW_AT_specification when computing CompilerCo… (PR #77157)

2024-01-08 Thread Felipe de Azevedo Piovezan via lldb-commits

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


[Lldb-commits] [lldb] [lldb] DWARFDIE: Follow DW_AT_specification when computing CompilerCo… (PR #77157)

2024-01-08 Thread Felipe de Azevedo Piovezan via lldb-commits


@@ -375,16 +375,21 @@ std::vector DWARFDIE::GetDeclContextDIEs() 
const {
 
 std::vector DWARFDIE::GetDeclContext() const {
   std::vector context;
-  const dw_tag_t tag = Tag();
-  if (tag == DW_TAG_compile_unit || tag == DW_TAG_partial_unit)
-return context;
   DWARFDIE parent = GetParent();
-  if (parent)
+  if (parent) {
+const dw_tag_t parent_tag = parent.Tag();
+if (parent_tag == DW_TAG_compile_unit || parent_tag == DW_TAG_partial_unit)
+  // Handle top-level DIEs by following the specification if any.
+  if (DWARFDIE spec = GetReferencedDIE(DW_AT_specification))
+if (spec != *this)

felipepiovezan wrote:

Nit, If you feel so inclined:

```
if (DWARFDIE spec = GetReferencedDIE(DW_AT_specification);
 spec && spec != *this)
```

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


[Lldb-commits] [lldb] [lldb] DWARFDIE: Follow DW_AT_specification when computing CompilerCo… (PR #77157)

2024-01-08 Thread Felipe de Azevedo Piovezan via lldb-commits


@@ -855,6 +855,23 @@ void Module::FindFunctions(ConstString name,
   }
 }
 
+void Module::FindFunctions(llvm::ArrayRef compiler_ctx,
+   FunctionNameType name_type_mask,
+   const ModuleFunctionSearchOptions &options,
+   SymbolContextList &sc_list) {
+  if (compiler_ctx.empty() ||
+  compiler_ctx.back().kind != CompilerContextKind::Function)
+return;
+  ConstString name = compiler_ctx.back().name;
+  CompilerDeclContext dc;
+  SymbolContextList unfiltered;
+  FindFunctions(name, dc,name_type_mask, options, unfiltered);

felipepiovezan wrote:

`FindFunctions(name, dc,name_type_mask`

This is probably not clang-formatted

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


[Lldb-commits] [lldb] [lldb] DWARFDIE: Follow DW_AT_specification when computing CompilerCo… (PR #77157)

2024-01-08 Thread Felipe de Azevedo Piovezan via lldb-commits


@@ -404,7 +409,7 @@ std::vector 
DWARFDIE::GetDeclContext() const {
 push_ctx(CompilerContextKind::Enum, GetName());
 break;
   case DW_TAG_subprogram:
-push_ctx(CompilerContextKind::Function, GetPubname());
+push_ctx(CompilerContextKind::Function, GetName());

felipepiovezan wrote:

IIRC the linkage name / pubname each go into one of dwarf 
declaration/definition (I forget which one goes where), and thus we have this 
change?

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


[Lldb-commits] [lldb] 2bf01d7 - [lldb][DWARFASTParserClang] GetClangDeclForDIE: don't create VarDecl for static data members (#77155)

2024-01-08 Thread via lldb-commits

Author: Michael Buch
Date: 2024-01-08T14:10:02Z
New Revision: 2bf01d73f6ebca11f36c17a65b7a86109d44681e

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

LOG: [lldb][DWARFASTParserClang] GetClangDeclForDIE: don't create VarDecl for 
static data members (#77155)

With DWARFv5, C++ static data members are represented as
`DW_TAG_variable`s (see `faa3a5ea9ae481da757dab1c95c589e2d5645982`).

In GetClangDeclForDIE, when trying to parse the `DW_AT_specification`
that a static data member's CU-level `DW_TAG_variable` points to, we
would try to `CreateVariableDeclaration`. Whereas previously it was a
no-op (for `DW_TAG_member`s). However, adding `VarDecls` to RecordDecls
for static data members should always be done in
`CreateStaticMemberVariable`. The test-case is an exapmle where we would
crash if we tried to create a `VarDecl` from within `GetClangDeclForDIE`
for a static data member.

This patch simply checks whether the `DW_TAG_variable` being parsed is a
static data member, and if so, trivially returns from
`GetClangDeclForDIE` (as we previously did for `DW_TAG_member`s).

Added: 
lldb/test/Shell/SymbolFile/DWARF/Inputs/dwo-static-data-member.cpp
lldb/test/Shell/SymbolFile/DWARF/dwo-static-data-member-access.test

Modified: 
lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp

Removed: 




diff  --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
index 009722b85aa186..54d06b1115a229 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFASTParserClang.cpp
@@ -142,6 +142,18 @@ static bool ShouldIgnoreArtificialField(llvm::StringRef 
FieldName) {
  || FieldName.starts_with("_vptr.");
 }
 
+/// Returns true for C++ constructs represented by clang::CXXRecordDecl
+static bool TagIsRecordType(dw_tag_t tag) {
+  switch (tag) {
+  case DW_TAG_class_type:
+  case DW_TAG_structure_type:
+  case DW_TAG_union_type:
+return true;
+  default:
+return false;
+  }
+}
+
 TypeSP DWARFASTParserClang::ParseTypeFromClangModule(const SymbolContext &sc,
  const DWARFDIE &die,
  Log *log) {
@@ -3304,12 +3316,19 @@ clang::Decl 
*DWARFASTParserClang::GetClangDeclForDIE(const DWARFDIE &die) {
 return nullptr;
 
   switch (die.Tag()) {
-  case DW_TAG_variable:
   case DW_TAG_constant:
   case DW_TAG_formal_parameter:
   case DW_TAG_imported_declaration:
   case DW_TAG_imported_module:
 break;
+  case DW_TAG_variable:
+// This means 'die' is a C++ static data member.
+// We don't want to create decls for such members
+// here.
+if (auto parent = die.GetParent();
+parent.IsValid() && TagIsRecordType(parent.Tag()))
+  return nullptr;
+break;
   default:
 return nullptr;
   }

diff  --git 
a/lldb/test/Shell/SymbolFile/DWARF/Inputs/dwo-static-data-member.cpp 
b/lldb/test/Shell/SymbolFile/DWARF/Inputs/dwo-static-data-member.cpp
new file mode 100644
index 00..fa7c3500df0f9d
--- /dev/null
+++ b/lldb/test/Shell/SymbolFile/DWARF/Inputs/dwo-static-data-member.cpp
@@ -0,0 +1,8 @@
+struct NoCtor {
+  NoCtor();
+  static int i;
+};
+
+int NoCtor::i = 15;
+
+int main() { return NoCtor::i; }

diff  --git 
a/lldb/test/Shell/SymbolFile/DWARF/dwo-static-data-member-access.test 
b/lldb/test/Shell/SymbolFile/DWARF/dwo-static-data-member-access.test
new file mode 100644
index 00..6e4deae7b9a0d7
--- /dev/null
+++ b/lldb/test/Shell/SymbolFile/DWARF/dwo-static-data-member-access.test
@@ -0,0 +1,24 @@
+# In DWARFv5, C++ static data members are represented
+# as DW_TAG_variable. We make sure LLDB's expression
+# evaluator doesn't crash when trying to parse such
+# a DW_TAG_variable DIE, whose parent DIE is only
+# a forward declaration.
+
+# RUN: %clangxx_host %S/Inputs/dwo-static-data-member.cpp \
+# RUN:   -g -gdwarf-5 -gsplit-dwarf -flimit-debug-info -o %t
+# RUN: %lldb %t -s %s -o exit 2>&1 | FileCheck %s
+
+breakpoint set -n main
+process launch
+
+# CHECK: Process {{.*}} stopped
+
+# FIXME: The expression evaluator tries to attach
+# the static member's VarDecl to the NoCtor RecordDecl
+# before passing the AST to clang; this requires the
+# RecordDecl to be a full definition. But the debug-info
+# only contains forward declaration for NoCtor. So
+# LLDB fails to evaluate the expression.
+expression NoCtor::i
+# CHECK-LABEL: expression NoCtor::i
+# CHECK:   use of undeclared identifier 'NoCtor'



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


[Lldb-commits] [lldb] [lldb][DWARFASTParserClang] GetClangDeclForDIE: don't create VarDecl for static data members (PR #77155)

2024-01-08 Thread Michael Buch via lldb-commits

https://github.com/Michael137 closed 
https://github.com/llvm/llvm-project/pull/77155
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] b4ee7d6 - [lldb][DWARFIndex][nfc] Factor out fully qualified name query (#76977)

2024-01-08 Thread via lldb-commits

Author: Felipe de Azevedo Piovezan
Date: 2024-01-08T11:16:22-03:00
New Revision: b4ee7d6119f97931d9f38ac8c6bc7409eed87aab

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

LOG: [lldb][DWARFIndex][nfc] Factor out fully qualified name query (#76977)

This moves the functionally of finding a DIE based on a fully qualified
name from SymbolFileDWARF into DWARFIndex itself, so that
specializations of DWARFIndex can implement faster versions of this
query.

Added: 


Modified: 
lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.cpp
lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.h
lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp

Removed: 




diff  --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.cpp
index b1c323b101cef3..20c07a94b50769 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.cpp
@@ -7,6 +7,8 @@
 
//===--===//
 
 #include "Plugins/SymbolFile/DWARF/DWARFIndex.h"
+#include "DWARFDebugInfoEntry.h"
+#include "DWARFDeclContext.h"
 #include "Plugins/Language/ObjC/ObjCLanguage.h"
 #include "Plugins/SymbolFile/DWARF/DWARFDIE.h"
 #include "Plugins/SymbolFile/DWARF/SymbolFileDWARF.h"
@@ -112,3 +114,21 @@ void DWARFIndex::ReportInvalidDIERef(DIERef ref, 
llvm::StringRef name) const {
   "bad die {0:x16} for '{1}')\n",
   ref.die_offset(), name.str().c_str());
 }
+
+void DWARFIndex::GetFullyQualifiedType(
+const DWARFDeclContext &context,
+llvm::function_ref callback) {
+  GetTypes(context, [&](DWARFDIE die) {
+return GetFullyQualifiedTypeImpl(context, die, callback);
+  });
+}
+
+bool DWARFIndex::GetFullyQualifiedTypeImpl(
+const DWARFDeclContext &context, DWARFDIE die,
+llvm::function_ref callback) {
+  DWARFDeclContext dwarf_decl_ctx =
+  die.GetDIE()->GetDWARFDeclContext(die.GetCU());
+  if (dwarf_decl_ctx == context)
+return callback(die);
+  return true;
+}

diff  --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.h 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.h
index 9aadeddbb21753..0551b07100a96b 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.h
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFIndex.h
@@ -53,6 +53,14 @@ class DWARFIndex {
 llvm::function_ref callback) = 0;
   virtual void GetTypes(const DWARFDeclContext &context,
 llvm::function_ref callback) = 0;
+
+  /// Finds all DIEs whose fully qualified name matches `context`. A base
+  /// implementation is provided, and it uses the entire CU to check the DIE
+  /// parent hierarchy. Specializations should override this if they are able
+  /// to provide a faster implementation.
+  virtual void
+  GetFullyQualifiedType(const DWARFDeclContext &context,
+llvm::function_ref callback);
   virtual void
   GetNamespaces(ConstString name,
 llvm::function_ref callback) = 0;
@@ -102,6 +110,12 @@ class DWARFIndex {
   }
 
   void ReportInvalidDIERef(DIERef ref, llvm::StringRef name) const;
+
+  /// Implementation of `GetFullyQualifiedType` to check a single entry,
+  /// shareable with derived classes.
+  bool
+  GetFullyQualifiedTypeImpl(const DWARFDeclContext &context, DWARFDIE die,
+llvm::function_ref callback);
 };
 } // namespace dwarf
 } // namespace lldb_private::plugin

diff  --git a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
index 447930ffe07b3f..737da7798b82b9 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/SymbolFileDWARF.cpp
@@ -3138,7 +3138,7 @@ 
SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(const DWARFDIE &die) {
 }
 
 const DWARFDeclContext die_dwarf_decl_ctx = GetDWARFDeclContext(die);
-m_index->GetTypes(die_dwarf_decl_ctx, [&](DWARFDIE type_die) {
+m_index->GetFullyQualifiedType(die_dwarf_decl_ctx, [&](DWARFDIE type_die) {
   // Make sure type_die's language matches the type system we are
   // looking for. We don't want to find a "Foo" type from Java if we
   // are looking for a "Foo" type for C, C++, ObjC, or ObjC++.
@@ -3165,9 +3165,8 @@ 
SymbolFileDWARF::FindDefinitionTypeForDWARFDeclContext(const DWARFDIE &die) {
 return true;
   }
 
-  DWARFDeclContext type_dwarf_decl_ctx = GetDWARFDeclContext(type_die);
-
   if (log) {
+DWARFDeclContext type_dwarf_decl_ctx = GetDWARFDeclContext(type_die);
 GetObjectFile()->GetModule()->LogMessage(
 log,
 "SymbolFileDWARF::"
@@ -3177,10 +3176,6 @@ 
SymbolFileDWAR

[Lldb-commits] [lldb] [lldb][DWARFIndex][nfc] Factor out fully qualified name query (PR #76977)

2024-01-08 Thread Felipe de Azevedo Piovezan via lldb-commits

https://github.com/felipepiovezan closed 
https://github.com/llvm/llvm-project/pull/76977
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [clang-tools-extra] [libc] [mlir] [clang] [lld] [lldb] [compiler-rt] [libcxx] [llvm] [MLIR][LLVM] Add Continuous Loop Peeling transform to SCF (PR #71555)

2024-01-08 Thread Matthias Springer via lldb-commits


@@ -105,6 +106,167 @@ static void specializeForLoopForUnrolling(ForOp op) {
   op.erase();
 }
 
+/// Create a new for loop for the remaining iterations (partiaIteration)
+/// after a for loop has been peeled. This is followed by correcting the
+/// loop bounds for both loops given the index (splitBound) where the
+/// iteration space is to be split up.
+static LogicalResult splitLoopHelper(RewriterBase &b, scf::ForOp forOp,
+ scf::ForOp &partialIteration,
+ Value &splitBound) {
+  RewriterBase::InsertionGuard guard(b);
+  auto lbInt = getConstantIntValue(forOp.getLowerBound());
+  auto ubInt = getConstantIntValue(forOp.getUpperBound());
+  auto stepInt = getConstantIntValue(forOp.getStep());
+
+  // No specialization necessary if step already divides upper bound evenly.
+  if (lbInt && ubInt && stepInt && (*ubInt - *lbInt) % *stepInt == 0)
+return failure();
+  // No specialization necessary if step size is 1.
+  if (stepInt == static_cast(1))
+return failure();
+
+  // Create ForOp for partial iteration.
+  b.setInsertionPointAfter(forOp);
+  partialIteration = cast(b.clone(*forOp.getOperation()));
+  partialIteration.getLowerBoundMutable().assign(splitBound);
+  forOp.replaceAllUsesWith(partialIteration->getResults());
+  partialIteration.getInitArgsMutable().assign(forOp->getResults());
+
+  // Set new upper loop bound.
+  b.updateRootInPlace(
+  forOp, [&]() { forOp.getUpperBoundMutable().assign(splitBound); });
+
+  return success();
+}
+
+/// Convert single-iteration for loop to if-else block.
+static scf::IfOp convertSingleIterFor(RewriterBase &b, scf::ForOp &forOp) {
+  Location loc = forOp->getLoc();
+  IRMapping mapping;
+  mapping.map(forOp.getInductionVar(), forOp.getLowerBound());
+  for (auto [arg, operand] :
+   llvm::zip_equal(forOp.getRegionIterArgs(), forOp.getInitsMutable())) {
+mapping.map(arg, operand.get());
+  }
+  b.setInsertionPoint(forOp);
+  auto cond =
+  b.create(loc, arith::CmpIPredicate::slt,
+  forOp.getLowerBound(), forOp.getUpperBound());
+  auto ifOp = b.create(loc, forOp->getResultTypes(), cond, true);

matthias-springer wrote:

`/*withElseRegion=*/true`

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


[Lldb-commits] [libcxx] [mlir] [lldb] [llvm] [compiler-rt] [clang] [libc] [clang-tools-extra] [lld] [MLIR][LLVM] Add Continuous Loop Peeling transform to SCF (PR #71555)

2024-01-08 Thread Matthias Springer via lldb-commits


@@ -105,6 +106,167 @@ static void specializeForLoopForUnrolling(ForOp op) {
   op.erase();
 }
 
+/// Create a new for loop for the remaining iterations (partiaIteration)
+/// after a for loop has been peeled. This is followed by correcting the
+/// loop bounds for both loops given the index (splitBound) where the
+/// iteration space is to be split up.
+static LogicalResult splitLoopHelper(RewriterBase &b, scf::ForOp forOp,
+ scf::ForOp &partialIteration,
+ Value &splitBound) {

matthias-springer wrote:

Do not pass `splitBound` as reference. Otherwise it looks like a return value.

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


[Lldb-commits] [mlir] [llvm] [libc] [libcxx] [clang-tools-extra] [clang] [compiler-rt] [lldb] [lld] [MLIR][LLVM] Add Continuous Loop Peeling transform to SCF (PR #71555)

2024-01-08 Thread Matthias Springer via lldb-commits


@@ -0,0 +1,46 @@
+// RUN: mlir-opt %s 
-scf-for-loop-continuous-peeling=convert-single-iter-loops-to-if=true 
-split-input-file | FileCheck %s
+
+#map = affine_map<(d0, d1)[s0] -> (s0, d0 - d1)>
+func.func @foo(%ub: index) -> index {
+  %c0 = arith.constant 0 : index
+  %step = arith.constant 8 : index
+  %0 = scf.for %iv = %c0 to %ub step %step iter_args(%arg = %c0) -> (index) {
+%1 = affine.min #map(%ub, %iv)[%step]
+%2 = index.add %1, %arg
+scf.yield %2 : index
+  }
+  return %0 : index
+}
+
+// CHECK: #[[MAP:.*]] = affine_map<()[s0, s1, s2] -> (s1 - s1 mod s2)>
+// CHECK: func.func @foo(%[[UB:.*]]: index) -> index {
+// CHECK: %[[STEP8:.*]] = arith.constant 8 : index
+// CHECK: %[[STEP4:.*]] = arith.constant 4 : index
+// CHECK: %[[STEP2:.*]] = arith.constant 2 : index
+// CHECK: %[[STEP1:.*]] = arith.constant 1 : index
+// CHECK: %[[LB:.*]] = arith.constant 0 : index
+// CHECK: %[[I0:.*]] = affine.apply #[[MAP]]()[%[[LB]], %[[UB]], %[[STEP8]]]
+// CHECK: %[[I1:.*]] = scf.for %{{.*}} = %[[LB]] to %[[I0]] step %[[STEP8]] 
iter_args(%[[ALB:.*]] = %[[LB]]) -> (index) {
+// CHECK: %[[SUM:.*]] = index.add %[[ALB]], %[[STEP8]]
+// CHECK: scf.yield %[[SUM]] : index
+// CHECK: %[[I2:.*]] = affine.apply #[[MAP]]()[%[[I0]], %[[UB]], %[[STEP4]]]

matthias-springer wrote:

Please indent for better readability.


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


[Lldb-commits] [mlir] [clang-tools-extra] [libcxx] [lld] [libc] [clang] [lldb] [llvm] [compiler-rt] [MLIR][LLVM] Add Continuous Loop Peeling transform to SCF (PR #71555)

2024-01-08 Thread Matthias Springer via lldb-commits


@@ -105,6 +106,167 @@ static void specializeForLoopForUnrolling(ForOp op) {
   op.erase();
 }
 
+/// Create a new for loop for the remaining iterations (partiaIteration)
+/// after a for loop has been peeled. This is followed by correcting the
+/// loop bounds for both loops given the index (splitBound) where the
+/// iteration space is to be split up.
+static LogicalResult splitLoopHelper(RewriterBase &b, scf::ForOp forOp,
+ scf::ForOp &partialIteration,
+ Value &splitBound) {
+  RewriterBase::InsertionGuard guard(b);
+  auto lbInt = getConstantIntValue(forOp.getLowerBound());
+  auto ubInt = getConstantIntValue(forOp.getUpperBound());
+  auto stepInt = getConstantIntValue(forOp.getStep());
+
+  // No specialization necessary if step already divides upper bound evenly.
+  if (lbInt && ubInt && stepInt && (*ubInt - *lbInt) % *stepInt == 0)
+return failure();
+  // No specialization necessary if step size is 1.
+  if (stepInt == static_cast(1))
+return failure();
+
+  // Create ForOp for partial iteration.
+  b.setInsertionPointAfter(forOp);
+  partialIteration = cast(b.clone(*forOp.getOperation()));
+  partialIteration.getLowerBoundMutable().assign(splitBound);
+  forOp.replaceAllUsesWith(partialIteration->getResults());
+  partialIteration.getInitArgsMutable().assign(forOp->getResults());
+
+  // Set new upper loop bound.
+  b.updateRootInPlace(
+  forOp, [&]() { forOp.getUpperBoundMutable().assign(splitBound); });
+
+  return success();
+}
+
+/// Convert single-iteration for loop to if-else block.
+static scf::IfOp convertSingleIterFor(RewriterBase &b, scf::ForOp &forOp) {
+  Location loc = forOp->getLoc();
+  IRMapping mapping;
+  mapping.map(forOp.getInductionVar(), forOp.getLowerBound());
+  for (auto [arg, operand] :
+   llvm::zip_equal(forOp.getRegionIterArgs(), forOp.getInitsMutable())) {
+mapping.map(arg, operand.get());
+  }
+  b.setInsertionPoint(forOp);
+  auto cond =
+  b.create(loc, arith::CmpIPredicate::slt,
+  forOp.getLowerBound(), forOp.getUpperBound());
+  auto ifOp = b.create(loc, forOp->getResultTypes(), cond, true);
+  // then branch
+  SmallVector bbArgReplacements;
+  bbArgReplacements.push_back(forOp.getLowerBound());
+  llvm::append_range(bbArgReplacements, forOp.getInitArgs());
+
+  b.inlineBlockBefore(forOp.getBody(), ifOp.thenBlock(),
+  ifOp.thenBlock()->begin(), bbArgReplacements);
+  // else branch
+  b.setInsertionPointToStart(ifOp.elseBlock());
+  if (!forOp->getResultTypes().empty()) {
+b.create(loc, forOp.getInits());
+  }
+  b.replaceOp(forOp, ifOp->getResults());
+  return ifOp;
+}
+
+/// Rewrite a for loop with bounds/step that potentially do not divide the
+/// iteration space evenly into a chain of for loops where the step is a
+/// power of 2 and decreases exponentially across subsequent loops. Helps
+/// divide the iteration space across all resulting peeled loops evenly.
+///
+/// Optionally, convert all single iteration for loops to if-else
+/// blocks when convert_single_iter_loops_to_if attribute is set to true or
+/// alternatively with the convert-single-iter-loops-to-if option for the
+/// scf-for-loop-continuous-peeling pass.
+static LogicalResult continuousPeelForLoop(RewriterBase &b, ForOp forOp,
+   ForOp &partialIteration,
+   bool convertSingleIterLoopsToIf) {
+
+  scf::ForOp currentLoop;
+  auto lbInt = getConstantIntValue(forOp.getLowerBound());
+  auto stepInt = getConstantIntValue(forOp.getStep());
+
+  // Step size must be a known positive constant greater than 1.
+  if (!stepInt || stepInt <= static_cast(1))
+return failure();
+
+  Value initialUb = forOp.getUpperBound();
+  Value initialStep = forOp.getStep();
+  uint64_t loopStep = *stepInt;
+  currentLoop = forOp;
+  AffineExpr sym0, sym1, sym2;
+  bindSymbols(b.getContext(), sym0, sym1, sym2);
+  AffineMap defaultSplitMap =
+  AffineMap::get(0, 3, {sym1 - ((sym1 - sym0) % sym2)});
+  AffineMap powerSplitMap = AffineMap::get(0, 3, {sym1 - (sym1 % sym2)});
+  bool usePowerSplit = (lbInt.has_value()) &&
+   (*lbInt % *stepInt == static_cast(0)) &&
+   (loopStep == llvm::bit_floor(loopStep));
+  AffineMap splitMap = usePowerSplit ? powerSplitMap : defaultSplitMap;
+  SmallVector loops;
+  while (loopStep) {
+b.setInsertionPoint(currentLoop);
+auto constStepOp =
+b.create(currentLoop.getLoc(), loopStep);
+b.updateRootInPlace(currentLoop, [&]() {
+  currentLoop.getStepMutable().assign(constStepOp);
+});
+b.setInsertionPoint(currentLoop);
+Value splitBound = b.createOrFold(
+currentLoop.getLoc(), splitMap,
+ValueRange{currentLoop.getLowerBound(), currentLoop.getUpperBound(),
+   currentLoop.getStep()});
+LogicalResult status =
+spl

[Lldb-commits] [llvm] [libc] [lldb] [mlir] [libcxx] [clang] [clang-tools-extra] [compiler-rt] [lld] [MLIR][LLVM] Add Continuous Loop Peeling transform to SCF (PR #71555)

2024-01-08 Thread Matthias Springer via lldb-commits


@@ -105,6 +106,167 @@ static void specializeForLoopForUnrolling(ForOp op) {
   op.erase();
 }
 
+/// Create a new for loop for the remaining iterations (partiaIteration)
+/// after a for loop has been peeled. This is followed by correcting the
+/// loop bounds for both loops given the index (splitBound) where the
+/// iteration space is to be split up.

matthias-springer wrote:

Explain the meaning of the return value.

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


[Lldb-commits] [mlir] [libc] [clang-tools-extra] [libcxx] [clang] [llvm] [lld] [compiler-rt] [lldb] [MLIR][LLVM] Add Continuous Loop Peeling transform to SCF (PR #71555)

2024-01-08 Thread Matthias Springer via lldb-commits


@@ -105,6 +106,167 @@ static void specializeForLoopForUnrolling(ForOp op) {
   op.erase();
 }
 
+/// Create a new for loop for the remaining iterations (partiaIteration)
+/// after a for loop has been peeled. This is followed by correcting the
+/// loop bounds for both loops given the index (splitBound) where the
+/// iteration space is to be split up.
+static LogicalResult splitLoopHelper(RewriterBase &b, scf::ForOp forOp,
+ scf::ForOp &partialIteration,
+ Value &splitBound) {
+  RewriterBase::InsertionGuard guard(b);
+  auto lbInt = getConstantIntValue(forOp.getLowerBound());
+  auto ubInt = getConstantIntValue(forOp.getUpperBound());
+  auto stepInt = getConstantIntValue(forOp.getStep());
+
+  // No specialization necessary if step already divides upper bound evenly.
+  if (lbInt && ubInt && stepInt && (*ubInt - *lbInt) % *stepInt == 0)
+return failure();
+  // No specialization necessary if step size is 1.
+  if (stepInt == static_cast(1))
+return failure();
+
+  // Create ForOp for partial iteration.
+  b.setInsertionPointAfter(forOp);
+  partialIteration = cast(b.clone(*forOp.getOperation()));
+  partialIteration.getLowerBoundMutable().assign(splitBound);
+  forOp.replaceAllUsesWith(partialIteration->getResults());
+  partialIteration.getInitArgsMutable().assign(forOp->getResults());
+
+  // Set new upper loop bound.
+  b.updateRootInPlace(
+  forOp, [&]() { forOp.getUpperBoundMutable().assign(splitBound); });
+
+  return success();
+}
+
+/// Convert single-iteration for loop to if-else block.
+static scf::IfOp convertSingleIterFor(RewriterBase &b, scf::ForOp &forOp) {
+  Location loc = forOp->getLoc();
+  IRMapping mapping;
+  mapping.map(forOp.getInductionVar(), forOp.getLowerBound());
+  for (auto [arg, operand] :
+   llvm::zip_equal(forOp.getRegionIterArgs(), forOp.getInitsMutable())) {
+mapping.map(arg, operand.get());
+  }
+  b.setInsertionPoint(forOp);
+  auto cond =
+  b.create(loc, arith::CmpIPredicate::slt,
+  forOp.getLowerBound(), forOp.getUpperBound());
+  auto ifOp = b.create(loc, forOp->getResultTypes(), cond, true);
+  // then branch
+  SmallVector bbArgReplacements;
+  bbArgReplacements.push_back(forOp.getLowerBound());
+  llvm::append_range(bbArgReplacements, forOp.getInitArgs());
+
+  b.inlineBlockBefore(forOp.getBody(), ifOp.thenBlock(),
+  ifOp.thenBlock()->begin(), bbArgReplacements);
+  // else branch
+  b.setInsertionPointToStart(ifOp.elseBlock());
+  if (!forOp->getResultTypes().empty()) {
+b.create(loc, forOp.getInits());
+  }
+  b.replaceOp(forOp, ifOp->getResults());
+  return ifOp;
+}
+
+/// Rewrite a for loop with bounds/step that potentially do not divide the
+/// iteration space evenly into a chain of for loops where the step is a
+/// power of 2 and decreases exponentially across subsequent loops. Helps
+/// divide the iteration space across all resulting peeled loops evenly.
+///
+/// Optionally, convert all single iteration for loops to if-else
+/// blocks when convert_single_iter_loops_to_if attribute is set to true or
+/// alternatively with the convert-single-iter-loops-to-if option for the
+/// scf-for-loop-continuous-peeling pass.
+static LogicalResult continuousPeelForLoop(RewriterBase &b, ForOp forOp,
+   ForOp &partialIteration,
+   bool convertSingleIterLoopsToIf) {
+
+  scf::ForOp currentLoop;
+  auto lbInt = getConstantIntValue(forOp.getLowerBound());
+  auto stepInt = getConstantIntValue(forOp.getStep());
+
+  // Step size must be a known positive constant greater than 1.
+  if (!stepInt || stepInt <= static_cast(1))
+return failure();
+
+  Value initialUb = forOp.getUpperBound();
+  Value initialStep = forOp.getStep();
+  uint64_t loopStep = *stepInt;
+  currentLoop = forOp;
+  AffineExpr sym0, sym1, sym2;
+  bindSymbols(b.getContext(), sym0, sym1, sym2);
+  AffineMap defaultSplitMap =

matthias-springer wrote:

Add comment to explain why you have `defaultSplitMap` and `powerSplitMap`.

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


[Lldb-commits] [clang] [lld] [compiler-rt] [lldb] [libcxx] [clang-tools-extra] [mlir] [libc] [llvm] [MLIR][LLVM] Add Continuous Loop Peeling transform to SCF (PR #71555)

2024-01-08 Thread Matthias Springer via lldb-commits


@@ -0,0 +1,46 @@
+// RUN: mlir-opt %s 
-scf-for-loop-continuous-peeling=convert-single-iter-loops-to-if=true 
-split-input-file | FileCheck %s
+
+#map = affine_map<(d0, d1)[s0] -> (s0, d0 - d1)>
+func.func @foo(%ub: index) -> index {
+  %c0 = arith.constant 0 : index
+  %step = arith.constant 8 : index
+  %0 = scf.for %iv = %c0 to %ub step %step iter_args(%arg = %c0) -> (index) {

matthias-springer wrote:

Add another test case so that both `usePowerSplit = false` and `usePowerSplit = 
true` is exercised.

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


[Lldb-commits] [mlir] [clang-tools-extra] [lld] [lldb] [clang] [libcxx] [llvm] [compiler-rt] [libc] [MLIR][LLVM] Add Continuous Loop Peeling transform to SCF (PR #71555)

2024-01-08 Thread Matthias Springer via lldb-commits


@@ -189,16 +188,17 @@ LogicalResult 
scf::canonicalizeMinMaxOpInLoop(RewriterBase &rewriter,
 /// * Inside the peeled loop: min(step, ub - iv) == step
 /// * Inside the partial iteration: min(step, ub - iv) == ub - iv
 ///
-/// Returns `success` if the given operation was replaced by a new operation;
+/// Returns the new Affine op if the operation was replaced by a new operation;

matthias-springer wrote:

`new AffineApplyOp`

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


[Lldb-commits] [libcxx] [libc] [lldb] [clang-tools-extra] [llvm] [mlir] [compiler-rt] [lld] [clang] [MLIR][LLVM] Add Continuous Loop Peeling transform to SCF (PR #71555)

2024-01-08 Thread Matthias Springer via lldb-commits


@@ -105,6 +106,167 @@ static void specializeForLoopForUnrolling(ForOp op) {
   op.erase();
 }
 
+/// Create a new for loop for the remaining iterations (partiaIteration)
+/// after a for loop has been peeled. This is followed by correcting the
+/// loop bounds for both loops given the index (splitBound) where the
+/// iteration space is to be split up.
+static LogicalResult splitLoopHelper(RewriterBase &b, scf::ForOp forOp,
+ scf::ForOp &partialIteration,
+ Value &splitBound) {
+  RewriterBase::InsertionGuard guard(b);
+  auto lbInt = getConstantIntValue(forOp.getLowerBound());
+  auto ubInt = getConstantIntValue(forOp.getUpperBound());
+  auto stepInt = getConstantIntValue(forOp.getStep());
+
+  // No specialization necessary if step already divides upper bound evenly.
+  if (lbInt && ubInt && stepInt && (*ubInt - *lbInt) % *stepInt == 0)
+return failure();
+  // No specialization necessary if step size is 1.
+  if (stepInt == static_cast(1))
+return failure();
+
+  // Create ForOp for partial iteration.
+  b.setInsertionPointAfter(forOp);
+  partialIteration = cast(b.clone(*forOp.getOperation()));
+  partialIteration.getLowerBoundMutable().assign(splitBound);
+  forOp.replaceAllUsesWith(partialIteration->getResults());
+  partialIteration.getInitArgsMutable().assign(forOp->getResults());
+
+  // Set new upper loop bound.
+  b.updateRootInPlace(
+  forOp, [&]() { forOp.getUpperBoundMutable().assign(splitBound); });
+
+  return success();
+}
+
+/// Convert single-iteration for loop to if-else block.
+static scf::IfOp convertSingleIterFor(RewriterBase &b, scf::ForOp &forOp) {
+  Location loc = forOp->getLoc();
+  IRMapping mapping;
+  mapping.map(forOp.getInductionVar(), forOp.getLowerBound());
+  for (auto [arg, operand] :
+   llvm::zip_equal(forOp.getRegionIterArgs(), forOp.getInitsMutable())) {
+mapping.map(arg, operand.get());
+  }
+  b.setInsertionPoint(forOp);
+  auto cond =
+  b.create(loc, arith::CmpIPredicate::slt,
+  forOp.getLowerBound(), forOp.getUpperBound());
+  auto ifOp = b.create(loc, forOp->getResultTypes(), cond, true);
+  // then branch
+  SmallVector bbArgReplacements;
+  bbArgReplacements.push_back(forOp.getLowerBound());
+  llvm::append_range(bbArgReplacements, forOp.getInitArgs());
+
+  b.inlineBlockBefore(forOp.getBody(), ifOp.thenBlock(),
+  ifOp.thenBlock()->begin(), bbArgReplacements);
+  // else branch
+  b.setInsertionPointToStart(ifOp.elseBlock());
+  if (!forOp->getResultTypes().empty()) {
+b.create(loc, forOp.getInits());
+  }
+  b.replaceOp(forOp, ifOp->getResults());
+  return ifOp;
+}
+
+/// Rewrite a for loop with bounds/step that potentially do not divide the
+/// iteration space evenly into a chain of for loops where the step is a
+/// power of 2 and decreases exponentially across subsequent loops. Helps
+/// divide the iteration space across all resulting peeled loops evenly.
+///
+/// Optionally, convert all single iteration for loops to if-else
+/// blocks when convert_single_iter_loops_to_if attribute is set to true or
+/// alternatively with the convert-single-iter-loops-to-if option for the
+/// scf-for-loop-continuous-peeling pass.
+static LogicalResult continuousPeelForLoop(RewriterBase &b, ForOp forOp,
+   ForOp &partialIteration,
+   bool convertSingleIterLoopsToIf) {
+
+  scf::ForOp currentLoop;
+  auto lbInt = getConstantIntValue(forOp.getLowerBound());
+  auto stepInt = getConstantIntValue(forOp.getStep());
+
+  // Step size must be a known positive constant greater than 1.
+  if (!stepInt || stepInt <= static_cast(1))
+return failure();
+
+  Value initialUb = forOp.getUpperBound();
+  Value initialStep = forOp.getStep();
+  uint64_t loopStep = *stepInt;
+  currentLoop = forOp;
+  AffineExpr sym0, sym1, sym2;
+  bindSymbols(b.getContext(), sym0, sym1, sym2);
+  AffineMap defaultSplitMap =
+  AffineMap::get(0, 3, {sym1 - ((sym1 - sym0) % sym2)});
+  AffineMap powerSplitMap = AffineMap::get(0, 3, {sym1 - (sym1 % sym2)});
+  bool usePowerSplit = (lbInt.has_value()) &&
+   (*lbInt % *stepInt == static_cast(0)) &&
+   (loopStep == llvm::bit_floor(loopStep));
+  AffineMap splitMap = usePowerSplit ? powerSplitMap : defaultSplitMap;
+  SmallVector loops;
+  while (loopStep) {
+b.setInsertionPoint(currentLoop);
+auto constStepOp =
+b.create(currentLoop.getLoc(), loopStep);
+b.updateRootInPlace(currentLoop, [&]() {
+  currentLoop.getStepMutable().assign(constStepOp);
+});
+b.setInsertionPoint(currentLoop);
+Value splitBound = b.createOrFold(
+currentLoop.getLoc(), splitMap,
+ValueRange{currentLoop.getLowerBound(), currentLoop.getUpperBound(),
+   currentLoop.getStep()});
+LogicalResult status =
+spl

[Lldb-commits] [clang-tools-extra] [lldb] [libcxx] [libc] [compiler-rt] [clang] [llvm] [mlir] [lld] [MLIR][LLVM] Add Continuous Loop Peeling transform to SCF (PR #71555)

2024-01-08 Thread Matthias Springer via lldb-commits


@@ -105,6 +106,167 @@ static void specializeForLoopForUnrolling(ForOp op) {
   op.erase();
 }
 
+/// Create a new for loop for the remaining iterations (partiaIteration)
+/// after a for loop has been peeled. This is followed by correcting the
+/// loop bounds for both loops given the index (splitBound) where the
+/// iteration space is to be split up.
+static LogicalResult splitLoopHelper(RewriterBase &b, scf::ForOp forOp,
+ scf::ForOp &partialIteration,
+ Value &splitBound) {
+  RewriterBase::InsertionGuard guard(b);
+  auto lbInt = getConstantIntValue(forOp.getLowerBound());
+  auto ubInt = getConstantIntValue(forOp.getUpperBound());
+  auto stepInt = getConstantIntValue(forOp.getStep());
+
+  // No specialization necessary if step already divides upper bound evenly.
+  if (lbInt && ubInt && stepInt && (*ubInt - *lbInt) % *stepInt == 0)
+return failure();
+  // No specialization necessary if step size is 1.
+  if (stepInt == static_cast(1))
+return failure();
+
+  // Create ForOp for partial iteration.
+  b.setInsertionPointAfter(forOp);
+  partialIteration = cast(b.clone(*forOp.getOperation()));
+  partialIteration.getLowerBoundMutable().assign(splitBound);
+  forOp.replaceAllUsesWith(partialIteration->getResults());
+  partialIteration.getInitArgsMutable().assign(forOp->getResults());
+
+  // Set new upper loop bound.
+  b.updateRootInPlace(
+  forOp, [&]() { forOp.getUpperBoundMutable().assign(splitBound); });
+
+  return success();
+}
+
+/// Convert single-iteration for loop to if-else block.
+static scf::IfOp convertSingleIterFor(RewriterBase &b, scf::ForOp &forOp) {
+  Location loc = forOp->getLoc();
+  IRMapping mapping;

matthias-springer wrote:

`mapping` is not used, can be deleted.

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


[Lldb-commits] [lldb] [clang-tools-extra] [compiler-rt] [mlir] [libcxx] [clang] [libc] [lld] [llvm] [MLIR][LLVM] Add Continuous Loop Peeling transform to SCF (PR #71555)

2024-01-08 Thread Matthias Springer via lldb-commits


@@ -105,6 +106,167 @@ static void specializeForLoopForUnrolling(ForOp op) {
   op.erase();
 }
 
+/// Create a new for loop for the remaining iterations (partiaIteration)

matthias-springer wrote:

typo: partiaIteration

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


[Lldb-commits] [llvm] [lld] [lldb] [mlir] [clang] [libc] [clang-tools-extra] [compiler-rt] [libcxx] [MLIR][LLVM] Add Continuous Loop Peeling transform to SCF (PR #71555)

2024-01-08 Thread Matthias Springer via lldb-commits


@@ -105,6 +106,167 @@ static void specializeForLoopForUnrolling(ForOp op) {
   op.erase();
 }
 
+/// Create a new for loop for the remaining iterations (partiaIteration)
+/// after a for loop has been peeled. This is followed by correcting the
+/// loop bounds for both loops given the index (splitBound) where the
+/// iteration space is to be split up.
+static LogicalResult splitLoopHelper(RewriterBase &b, scf::ForOp forOp,
+ scf::ForOp &partialIteration,
+ Value &splitBound) {
+  RewriterBase::InsertionGuard guard(b);
+  auto lbInt = getConstantIntValue(forOp.getLowerBound());
+  auto ubInt = getConstantIntValue(forOp.getUpperBound());
+  auto stepInt = getConstantIntValue(forOp.getStep());
+
+  // No specialization necessary if step already divides upper bound evenly.
+  if (lbInt && ubInt && stepInt && (*ubInt - *lbInt) % *stepInt == 0)
+return failure();
+  // No specialization necessary if step size is 1.
+  if (stepInt == static_cast(1))
+return failure();
+
+  // Create ForOp for partial iteration.
+  b.setInsertionPointAfter(forOp);
+  partialIteration = cast(b.clone(*forOp.getOperation()));
+  partialIteration.getLowerBoundMutable().assign(splitBound);
+  forOp.replaceAllUsesWith(partialIteration->getResults());
+  partialIteration.getInitArgsMutable().assign(forOp->getResults());
+
+  // Set new upper loop bound.
+  b.updateRootInPlace(
+  forOp, [&]() { forOp.getUpperBoundMutable().assign(splitBound); });
+
+  return success();
+}
+
+/// Convert single-iteration for loop to if-else block.
+static scf::IfOp convertSingleIterFor(RewriterBase &b, scf::ForOp &forOp) {
+  Location loc = forOp->getLoc();
+  IRMapping mapping;
+  mapping.map(forOp.getInductionVar(), forOp.getLowerBound());
+  for (auto [arg, operand] :
+   llvm::zip_equal(forOp.getRegionIterArgs(), forOp.getInitsMutable())) {
+mapping.map(arg, operand.get());
+  }
+  b.setInsertionPoint(forOp);
+  auto cond =
+  b.create(loc, arith::CmpIPredicate::slt,
+  forOp.getLowerBound(), forOp.getUpperBound());
+  auto ifOp = b.create(loc, forOp->getResultTypes(), cond, true);
+  // then branch
+  SmallVector bbArgReplacements;
+  bbArgReplacements.push_back(forOp.getLowerBound());
+  llvm::append_range(bbArgReplacements, forOp.getInitArgs());
+
+  b.inlineBlockBefore(forOp.getBody(), ifOp.thenBlock(),
+  ifOp.thenBlock()->begin(), bbArgReplacements);
+  // else branch
+  b.setInsertionPointToStart(ifOp.elseBlock());
+  if (!forOp->getResultTypes().empty()) {
+b.create(loc, forOp.getInits());
+  }
+  b.replaceOp(forOp, ifOp->getResults());
+  return ifOp;
+}
+
+/// Rewrite a for loop with bounds/step that potentially do not divide the
+/// iteration space evenly into a chain of for loops where the step is a
+/// power of 2 and decreases exponentially across subsequent loops. Helps
+/// divide the iteration space across all resulting peeled loops evenly.
+///
+/// Optionally, convert all single iteration for loops to if-else
+/// blocks when convert_single_iter_loops_to_if attribute is set to true or
+/// alternatively with the convert-single-iter-loops-to-if option for the
+/// scf-for-loop-continuous-peeling pass.
+static LogicalResult continuousPeelForLoop(RewriterBase &b, ForOp forOp,
+   ForOp &partialIteration,
+   bool convertSingleIterLoopsToIf) {
+
+  scf::ForOp currentLoop;
+  auto lbInt = getConstantIntValue(forOp.getLowerBound());
+  auto stepInt = getConstantIntValue(forOp.getStep());
+
+  // Step size must be a known positive constant greater than 1.
+  if (!stepInt || stepInt <= static_cast(1))
+return failure();
+
+  Value initialUb = forOp.getUpperBound();
+  Value initialStep = forOp.getStep();
+  uint64_t loopStep = *stepInt;
+  currentLoop = forOp;
+  AffineExpr sym0, sym1, sym2;
+  bindSymbols(b.getContext(), sym0, sym1, sym2);
+  AffineMap defaultSplitMap =
+  AffineMap::get(0, 3, {sym1 - ((sym1 - sym0) % sym2)});
+  AffineMap powerSplitMap = AffineMap::get(0, 3, {sym1 - (sym1 % sym2)});
+  bool usePowerSplit = (lbInt.has_value()) &&
+   (*lbInt % *stepInt == static_cast(0)) &&
+   (loopStep == llvm::bit_floor(loopStep));
+  AffineMap splitMap = usePowerSplit ? powerSplitMap : defaultSplitMap;
+  SmallVector loops;
+  while (loopStep) {
+b.setInsertionPoint(currentLoop);
+auto constStepOp =
+b.create(currentLoop.getLoc(), loopStep);
+b.updateRootInPlace(currentLoop, [&]() {
+  currentLoop.getStepMutable().assign(constStepOp);
+});
+b.setInsertionPoint(currentLoop);
+Value splitBound = b.createOrFold(
+currentLoop.getLoc(), splitMap,
+ValueRange{currentLoop.getLowerBound(), currentLoop.getUpperBound(),
+   currentLoop.getStep()});
+LogicalResult status =
+spl

[Lldb-commits] [lldb] [lldb] Fix Intel PT plugin compile errors (PR #77252)

2024-01-08 Thread Nicholas Mosier via lldb-commits


@@ -276,6 +276,10 @@ class DecodedThread : public 
std::enable_shared_from_this {
 
 /// The string message of this item if it's an error
 std::string error;
+
+TraceItemStorage() {}
+~TraceItemStorage() {}

nmosier wrote:

`TraceItemStorage()` can't be defaulted because the union member `std::string 
error` has a non-trivial default constructor (quoted from 
[here](https://en.cppreference.com/w/cpp/language/union)):
> If a union contains a non-static data member with a non-trivial default 
> constructor, the default constructor of the union is deleted by default 
> unless a variant member of the union has a default member initializer.

`~TraceItemStorage()` can't be defaulted because the union member `std::string 
error` has a non-trivial destructor (quoted from 
[here](https://en.cppreference.com/w/cpp/language/union)):
> If a union contains a non-static data member with a non-trivial special 
> member function (copy/move constructor, copy/move assignment, or destructor), 
> that function is deleted by default in the union and needs to be defined 
> explicitly by the programmer.


Anyways, if I try to default them, I get these compile errors:
```
In file included from 
/usr/include/x86_64-linux-gnu/c++/11/bits/c++allocator.h:33,
 from /usr/include/c++/11/bits/allocator.h:46,
 from /usr/include/c++/11/unordered_map:40,
 from 
/afs/cs.stanford.edu/u/nmosier/llvm/bugfix-lldb-intelpt/lldb/include/lldb/Target/Trace.h:13,
 from 
/afs/cs.stanford.edu/u/nmosier/llvm/bugfix-lldb-intelpt/lldb/source/Plugins/Trace/intel-pt/DecodedThread.h:13,
 from 
/afs/cs.stanford.edu/u/nmosier/llvm/bugfix-lldb-intelpt/lldb/source/Plugins/Trace/intel-pt/DecodedThread.cpp:9:
/usr/include/c++/11/ext/new_allocator.h: In instantiation of ‘void 
__gnu_cxx::new_allocator<_Tp>::construct(_Up*, _Args&& ...) [with _Up = 
lldb_private::trace_intel_pt::DecodedThread::TraceItemStorage; _Args = {}; _Tp 
= lldb_private::trace_intel_pt::DecodedThread::TraceItemStorage]’:
/usr/include/c++/11/bits/alloc_traits.h:516:17:   required from ‘static void 
std::allocator_traits 
>::construct(std::allocator_traits >::allocator_type&, 
_Up*, _Args&& ...) [with _Up = 
lldb_private::trace_intel_pt::DecodedThread::TraceItemStorage; _Args = {}; _Tp 
= lldb_private::trace_intel_pt::DecodedThread::TraceItemStorage; 
std::allocator_traits >::allocator_type = 
std::allocator]’
/usr/include/c++/11/bits/vector.tcc:115:30:   required from ‘std::vector<_Tp, 
_Alloc>::reference std::vector<_Tp, _Alloc>::emplace_back(_Args&& ...) [with 
_Args = {}; _Tp = 
lldb_private::trace_intel_pt::DecodedThread::TraceItemStorage; _Alloc = 
std::allocator; 
std::vector<_Tp, _Alloc>::reference = 
lldb_private::trace_intel_pt::DecodedThread::TraceItemStorage&]’
/afs/cs.stanford.edu/u/nmosier/llvm/bugfix-lldb-intelpt/lldb/source/Plugins/Trace/intel-pt/DecodedThread.cpp:110:27:
   required from here
/usr/include/c++/11/ext/new_allocator.h:162:11: error: use of deleted function 
‘lldb_private::trace_intel_pt::DecodedThread::TraceItemStorage::TraceItemStorage()’
  162 | { ::new((void *)__p) _Up(std::forward<_Args>(__args)...); }
  |   ^~
In file included from 
/afs/cs.stanford.edu/u/nmosier/llvm/bugfix-lldb-intelpt/lldb/source/Plugins/Trace/intel-pt/DecodedThread.cpp:9:
/afs/cs.stanford.edu/u/nmosier/llvm/bugfix-lldb-intelpt/lldb/source/Plugins/Trace/intel-pt/DecodedThread.h:280:5:
 note: 
‘lldb_private::trace_intel_pt::DecodedThread::TraceItemStorage::TraceItemStorage()’
 is implicitly deleted because the default definition would be ill-formed:
  280 | TraceItemStorage() = default;
  | ^~~~
/afs/cs.stanford.edu/u/nmosier/llvm/bugfix-lldb-intelpt/lldb/source/Plugins/Trace/intel-pt/DecodedThread.h:278:17:
 error: union member 
‘lldb_private::trace_intel_pt::DecodedThread::TraceItemStorage::error’ with 
non-trivial ‘std::__cxx11::basic_string<_CharT, _Traits, 
_Alloc>::basic_string() [with _CharT = char; _Traits = std::char_traits; 
_Alloc = std::allocator]’
  278 | std::string error;
  | ^
```
and
```
In file included from /usr/include/c++/11/optional:44,
 from 
/afs/cs.stanford.edu/u/nmosier/llvm/bugfix-lldb-intelpt/lldb/include/lldb/Target/Trace.h:12,
 from 
/afs/cs.stanford.edu/u/nmosier/llvm/bugfix-lldb-intelpt/lldb/source/Plugins/Trace/intel-pt/DecodedThread.h:13,
 from 
/afs/cs.stanford.edu/u/nmosier/llvm/bugfix-lldb-intelpt/lldb/source/Plugins/Trace/intel-pt/DecodedThread.cpp:9:
/usr/include/c++/11/bits/stl_construct.h: In instantiation of ‘void 
std::_Destroy(_ForwardIterator, _ForwardIterator) [with _ForwardIterator = 
lldb_private::trace_intel_pt::DecodedThread::TraceItemStorage*]’:
/usr/include/c++/11/bits/alloc_traits.h:848:15:   required from ‘void 
std::_Destroy(_ForwardIterator,

[Lldb-commits] [lldb] [lldb] Fix Intel PT plugin compile errors (PR #77252)

2024-01-08 Thread Nicholas Mosier via lldb-commits


@@ -85,6 +85,11 @@ double DecodedThread::NanosecondsRange::GetInterpolatedTime(
   return interpolate(next_range->nanos);
 }
 
+DecodedThread::TraceItemStorage::TraceItemStorage(
+const TraceItemStorage &other) {
+  std::memcpy(this, &other, sizeof *this);

nmosier wrote:

`DecodedThread` does know which member is being used (it uses `enum 
TraceItemKind` to tag the union); however, it stores the tag separately in 
`DecodedThread::m_item_kinds` for space/alignment reasons.
I added this copy constructor for use by `std::vector 
DecodedThread::m_trace_data`; without it, it raises a compile error because it 
doesn't know how to copy/move `TraceItemStorage` elements when resizing the 
vector. This means that we can't add a second TraceItemKind argument to the 
copy constructor, because std::vector won't know how to use 
that.

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


[Lldb-commits] [lldb] [lldb] Fix Intel PT plugin compile errors (PR #77252)

2024-01-08 Thread Nicholas Mosier via lldb-commits

https://github.com/nmosier updated 
https://github.com/llvm/llvm-project/pull/77252

>From c99dbd7f915ab996a68c4d9eb0cee2edb3b33b84 Mon Sep 17 00:00:00 2001
From: Nicholas Mosier 
Date: Sun, 7 Jan 2024 20:06:55 +
Subject: [PATCH] [lldb] Fix Intel PT plugin compile errors

Fix #77251.
---
 .../Trace/intel-pt/CommandObjectTraceStartIntelPT.cpp   | 4 +---
 lldb/source/Plugins/Trace/intel-pt/DecodedThread.cpp| 5 +
 lldb/source/Plugins/Trace/intel-pt/DecodedThread.h  | 4 
 lldb/source/Plugins/Trace/intel-pt/LibiptDecoder.cpp| 4 ++--
 lldb/source/Plugins/Trace/intel-pt/TraceCursorIntelPT.cpp   | 4 ++--
 .../Plugins/Trace/intel-pt/TraceIntelPTBundleLoader.cpp | 6 +++---
 6 files changed, 17 insertions(+), 10 deletions(-)

diff --git 
a/lldb/source/Plugins/Trace/intel-pt/CommandObjectTraceStartIntelPT.cpp 
b/lldb/source/Plugins/Trace/intel-pt/CommandObjectTraceStartIntelPT.cpp
index d4f7dc354e9fed..44224229e625bf 100644
--- a/lldb/source/Plugins/Trace/intel-pt/CommandObjectTraceStartIntelPT.cpp
+++ b/lldb/source/Plugins/Trace/intel-pt/CommandObjectTraceStartIntelPT.cpp
@@ -158,7 +158,7 @@ 
CommandObjectProcessTraceStartIntelPT::CommandOptions::GetDefinitions() {
   return llvm::ArrayRef(g_process_trace_start_intel_pt_options);
 }
 
-bool CommandObjectProcessTraceStartIntelPT::DoExecute(
+void CommandObjectProcessTraceStartIntelPT::DoExecute(
 Args &command, CommandReturnObject &result) {
   if (Error err = m_trace.Start(
   m_options.m_ipt_trace_size, m_options.m_process_buffer_size_limit,
@@ -167,8 +167,6 @@ bool CommandObjectProcessTraceStartIntelPT::DoExecute(
 result.SetError(Status(std::move(err)));
   else
 result.SetStatus(eReturnStatusSuccessFinishResult);
-
-  return result.Succeeded();
 }
 
 std::optional
diff --git a/lldb/source/Plugins/Trace/intel-pt/DecodedThread.cpp 
b/lldb/source/Plugins/Trace/intel-pt/DecodedThread.cpp
index 17f8f51bdf0e0d..145e0386f6a023 100644
--- a/lldb/source/Plugins/Trace/intel-pt/DecodedThread.cpp
+++ b/lldb/source/Plugins/Trace/intel-pt/DecodedThread.cpp
@@ -85,6 +85,11 @@ double DecodedThread::NanosecondsRange::GetInterpolatedTime(
   return interpolate(next_range->nanos);
 }
 
+DecodedThread::TraceItemStorage::TraceItemStorage(
+const TraceItemStorage &other) {
+  std::memcpy(this, &other, sizeof *this);
+}
+
 uint64_t DecodedThread::GetItemsCount() const { return m_item_kinds.size(); }
 
 lldb::addr_t
diff --git a/lldb/source/Plugins/Trace/intel-pt/DecodedThread.h 
b/lldb/source/Plugins/Trace/intel-pt/DecodedThread.h
index 5745cdb67ab68f..88bf748d186a36 100644
--- a/lldb/source/Plugins/Trace/intel-pt/DecodedThread.h
+++ b/lldb/source/Plugins/Trace/intel-pt/DecodedThread.h
@@ -276,6 +276,10 @@ class DecodedThread : public 
std::enable_shared_from_this {
 
 /// The string message of this item if it's an error
 std::string error;
+
+TraceItemStorage() {}
+~TraceItemStorage() {}
+TraceItemStorage(const TraceItemStorage &other);
   };
 
   /// Create a new trace item.
diff --git a/lldb/source/Plugins/Trace/intel-pt/LibiptDecoder.cpp 
b/lldb/source/Plugins/Trace/intel-pt/LibiptDecoder.cpp
index cdf81954eee902..f8241ef6a79329 100644
--- a/lldb/source/Plugins/Trace/intel-pt/LibiptDecoder.cpp
+++ b/lldb/source/Plugins/Trace/intel-pt/LibiptDecoder.cpp
@@ -572,7 +572,7 @@ Error 
lldb_private::trace_intel_pt::DecodeSingleTraceForThread(
 Expected decoder = PSBBlockDecoder::Create(
 trace_intel_pt, block, buffer.slice(block.psb_offset, block.size),
 *decoded_thread.GetThread()->GetProcess(),
-i + 1 < blocks->size() ? blocks->at(i + 1).starting_ip : None,
+i + 1 < blocks->size() ? blocks->at(i + 1).starting_ip : std::nullopt,
 decoded_thread, std::nullopt);
 if (!decoder)
   return decoder.takeError();
@@ -640,7 +640,7 @@ Error 
lldb_private::trace_intel_pt::DecodeSystemWideTraceForThread(
   *decoded_thread.GetThread()->GetProcess(),
   j + 1 < execution.psb_blocks.size()
   ? execution.psb_blocks[j + 1].starting_ip
-  : None,
+  : std::nullopt,
   decoded_thread, execution.thread_execution.GetEndTSC());
   if (!decoder)
 return decoder.takeError();
diff --git a/lldb/source/Plugins/Trace/intel-pt/TraceCursorIntelPT.cpp 
b/lldb/source/Plugins/Trace/intel-pt/TraceCursorIntelPT.cpp
index 66d342196cf10d..dda6cd74343f0f 100644
--- a/lldb/source/Plugins/Trace/intel-pt/TraceCursorIntelPT.cpp
+++ b/lldb/source/Plugins/Trace/intel-pt/TraceCursorIntelPT.cpp
@@ -35,7 +35,7 @@ void TraceCursorIntelPT::Next() {
 void TraceCursorIntelPT::ClearTimingRangesIfInvalid() {
   if (m_tsc_range_calculated) {
 if (!m_tsc_range || m_pos < 0 || !m_tsc_range->InRange(m_pos)) {
-  m_tsc_range = None;
+  m_tsc_range = std::nullopt;
   m_tsc_range_calculated = false;
 }
   }
@@ -43,7 +43,7 @@ void TraceCursorIntelPT::ClearTimingRangesIfInvalid() {
   if (m_nanoseconds_range_calculated

[Lldb-commits] [lldb] [lldb] Fix Intel PT plugin compile errors (PR #77252)

2024-01-08 Thread Walter Erquinigo via lldb-commits


@@ -103,12 +103,10 @@ TraceIntelPTBundleLoader::CreateEmptyProcess(lldb::pid_t 
pid,
   ParsedProcess parsed_process;
   parsed_process.target_sp = target_sp;
 
-  // This should instead try to directly create an instance of ProcessTrace.
-  // ProcessSP process_sp = target_sp->CreateProcess(
-  ///*listener*/ nullptr, "trace",
-  ///*crash_file*/ nullptr,
-  ///*can_connect*/ false);
-
+  ProcessSP process_sp = target_sp->CreateProcess(
+  /*listener*/ nullptr, "trace",
+  /*crash_file*/ nullptr,
+  /*can_connect*/ false);

walter-erquinigo wrote:

Actually, if you could just do

```
ProcessTrace::CreateInstance(target_sp, /*listener*/ nullptr, /*crash_file*/ 
nullptr, /*can_connect*/ false);
```

Then we could consider this part of the code as fixed. You also need to make 
that `ProcessTrace::CreateInstance` function `public` instead of `private`.

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


[Lldb-commits] [lldb] [lldb] Fix Intel PT plugin compile errors (PR #77252)

2024-01-08 Thread Nicholas Mosier via lldb-commits


@@ -103,12 +103,10 @@ TraceIntelPTBundleLoader::CreateEmptyProcess(lldb::pid_t 
pid,
   ParsedProcess parsed_process;
   parsed_process.target_sp = target_sp;
 
-  // This should instead try to directly create an instance of ProcessTrace.
-  // ProcessSP process_sp = target_sp->CreateProcess(
-  ///*listener*/ nullptr, "trace",
-  ///*crash_file*/ nullptr,
-  ///*can_connect*/ false);
-
+  ProcessSP process_sp = target_sp->CreateProcess(
+  /*listener*/ nullptr, "trace",
+  /*crash_file*/ nullptr,
+  /*can_connect*/ false);

nmosier wrote:

I double-checked, and looks like commit 555a71be457fo3 commented out these four 
lines. Here's the commit message:
```
commit 555a71be457f351411b89c6a6a66aeecf7ca5291
Author: Walter Erquinigo 
Date:   Mon Nov 6 19:45:52 2023 -0500

[LLDB] Don't forcefully initialize the process trace plugin (#71455)

This was causing some process to wrongfully be handled by ProcessTrace.

The only place this was being used is in the intel pt plugin, but it
doesn't even build anymore, so I'm sure no one is using it.
```
I think the commit author meant to comment out the following line, 
`process_sp->SetID(static_cast(pid));`; however, they didn't catch 
the compile error because apparently the Intel PT plugin wasn't compiling back 
then anyway.

I updated my patch to keep those four lines plus the following two commented 
out. I verified that LLDB's Intel PT plugin still works just fine.

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


[Lldb-commits] [lldb] [lldb] Fix Intel PT plugin compile errors (PR #77252)

2024-01-08 Thread Walter Erquinigo via lldb-commits


@@ -85,6 +85,11 @@ double DecodedThread::NanosecondsRange::GetInterpolatedTime(
   return interpolate(next_range->nanos);
 }
 
+DecodedThread::TraceItemStorage::TraceItemStorage(
+const TraceItemStorage &other) {
+  std::memcpy(this, &other, sizeof *this);

walter-erquinigo wrote:

I think that the copies might cause unnecessary slowdowns because traces can 
contain tens of millions of items. What about using a deque instead of a 
vector? Then you don't need resizes anymore.

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


[Lldb-commits] [lldb] [lldb] Fix Intel PT plugin compile errors (PR #77252)

2024-01-08 Thread Walter Erquinigo via lldb-commits


@@ -108,8 +108,8 @@ TraceIntelPTBundleLoader::CreateEmptyProcess(lldb::pid_t 
pid,
   ///*listener*/ nullptr, "trace",
   ///*crash_file*/ nullptr,
   ///*can_connect*/ false);
-
-  process_sp->SetID(static_cast(pid));
+  //
+  // process_sp->SetID(static_cast(pid));

walter-erquinigo wrote:

do you need to do this? Otherwise all processes loaded from JSON will appear 
with an invalid PID.

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


[Lldb-commits] [clang-tools-extra] [libcxxabi] [flang] [lldb] [mlir] [llvm] [openmp] [compiler-rt] [libcxx] [clang] [libc] [OpenMP] Patch for Support to loop bind clause : Checking Parent Region (PR #

2024-01-08 Thread via lldb-commits

https://github.com/SunilKuravinakop updated 
https://github.com/llvm/llvm-project/pull/76938

>From 1dcd4703002acdde370a285089008e409043717b Mon Sep 17 00:00:00 2001
From: Sunil Kuravinakop 
Date: Thu, 4 Jan 2024 04:08:28 -0600
Subject: [PATCH 1/3] Changes uploaded to the phabricator on Dec 16th are lost
 because the phabricator is down. Hence re-uploading it to the github.com.

  Changes to be committed:
modified:   clang/include/clang/Sema/Sema.h
modified:   clang/lib/Sema/SemaOpenMP.cpp
modified:   clang/test/OpenMP/generic_loop_ast_print.cpp
modified:   clang/test/OpenMP/loop_bind_messages.cpp
modified:   clang/test/PCH/pragma-loop.cpp
---
 clang/include/clang/Sema/Sema.h  |   8 +-
 clang/lib/Sema/SemaOpenMP.cpp|  62 ---
 clang/test/OpenMP/generic_loop_ast_print.cpp |   4 +-
 clang/test/OpenMP/loop_bind_messages.cpp | 180 +--
 clang/test/PCH/pragma-loop.cpp   |   8 +-
 5 files changed, 226 insertions(+), 36 deletions(-)

diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 5e3b57ea33220b..3d8d94d200ac58 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -11335,6 +11335,7 @@ class Sema final {
   /// on the parameter of the bind clause. In the methods for the
   /// mapped directives, check the parameters of the lastprivate clause.
   bool checkLastPrivateForMappedDirectives(ArrayRef Clauses);
+
   /// Depending on the bind clause of OMPD_loop map the directive to new
   /// directives.
   ///1) loop bind(parallel) --> OMPD_for
@@ -11344,9 +11345,12 @@ class Sema final {
   /// rigorous semantic checking in the new mapped directives.
   bool mapLoopConstruct(llvm::SmallVector &ClausesWithoutBind,
 ArrayRef Clauses,
-OpenMPBindClauseKind BindKind,
+OpenMPBindClauseKind &BindKind,
 OpenMPDirectiveKind &Kind,
-OpenMPDirectiveKind &PrevMappedDirective);
+OpenMPDirectiveKind &PrevMappedDirective,
+SourceLocation StartLoc, SourceLocation EndLoc,
+const DeclarationNameInfo &DirName,
+OpenMPDirectiveKind CancelRegion);
 
 public:
   /// The declarator \p D defines a function in the scope \p S which is nested
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index f34d2959dc6191..6e060e5b8ee268 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -5072,6 +5072,18 @@ static bool checkNestingOfRegions(Sema &SemaRef, const 
DSAStackTy *Stack,
 CurrentRegion != OMPD_cancellation_point &&
 CurrentRegion != OMPD_cancel && CurrentRegion != OMPD_scan)
   return false;
+// Checks needed for mapping "loop" construct. Please check 
mapLoopConstruct
+// for a detailed explanation
+if (SemaRef.LangOpts.OpenMP >= 50 && CurrentRegion == OMPD_loop &&
+((BindKind == OMPC_BIND_parallel) || (BindKind == OMPC_BIND_teams)) &&
+(isOpenMPWorksharingDirective(ParentRegion) ||
+ ParentRegion == OMPD_loop)) {
+  int ErrorMsgNumber = (BindKind == OMPC_BIND_parallel) ? 1 : 4;
+  SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region)
+  << true << getOpenMPDirectiveName(ParentRegion) << ErrorMsgNumber
+  << getOpenMPDirectiveName(CurrentRegion);
+  return true;
+}
 if (CurrentRegion == OMPD_cancellation_point ||
 CurrentRegion == OMPD_cancel) {
   // OpenMP [2.16, Nesting of Regions]
@@ -6124,35 +6136,36 @@ processImplicitMapsWithDefaultMappers(Sema &S, 
DSAStackTy *Stack,
 
 bool Sema::mapLoopConstruct(llvm::SmallVector &ClausesWithoutBind,
 ArrayRef Clauses,
-OpenMPBindClauseKind BindKind,
+OpenMPBindClauseKind &BindKind,
 OpenMPDirectiveKind &Kind,
-OpenMPDirectiveKind &PrevMappedDirective) {
+OpenMPDirectiveKind &PrevMappedDirective,
+SourceLocation StartLoc, SourceLocation EndLoc,
+const DeclarationNameInfo &DirName,
+OpenMPDirectiveKind CancelRegion) {
 
   bool UseClausesWithoutBind = false;
 
   // Restricting to "#pragma omp loop bind"
   if (getLangOpts().OpenMP >= 50 && Kind == OMPD_loop) {
+
+const OpenMPDirectiveKind ParentDirective = DSAStack->getParentDirective();
+
 if (BindKind == OMPC_BIND_unknown) {
   // Setting the enclosing teams or parallel construct for the loop
   // directive without bind clause.
   BindKind = OMPC_BIND_thread; // Default bind(thread) if binding is 
unknown
 
-  const OpenMPDirectiveKind ParentDirective =
-  DSAStack->getParentDirective();
   if (ParentDirective == OMPD_unkno

[Lldb-commits] [lldb] [lldb] Fix Intel PT plugin compile errors (PR #77252)

2024-01-08 Thread Nicholas Mosier via lldb-commits

https://github.com/nmosier updated 
https://github.com/llvm/llvm-project/pull/77252

>From a4876e327f4e248ab4a48538f64507f60023d9d2 Mon Sep 17 00:00:00 2001
From: Nicholas Mosier 
Date: Sun, 7 Jan 2024 20:06:55 +
Subject: [PATCH] [lldb] Fix Intel PT plugin compile errors

Fix #77251.
---
 lldb/include/lldb/Target/ProcessTrace.h |  2 +-
 .../intel-pt/CommandObjectTraceStartIntelPT.cpp |  4 +---
 lldb/source/Plugins/Trace/intel-pt/DecodedThread.h  |  7 +--
 .../source/Plugins/Trace/intel-pt/LibiptDecoder.cpp |  4 ++--
 .../Plugins/Trace/intel-pt/TraceCursorIntelPT.cpp   |  4 ++--
 .../Trace/intel-pt/TraceIntelPTBundleLoader.cpp | 13 ++---
 6 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/lldb/include/lldb/Target/ProcessTrace.h 
b/lldb/include/lldb/Target/ProcessTrace.h
index 037dea232cc024..201754e975e4fb 100644
--- a/lldb/include/lldb/Target/ProcessTrace.h
+++ b/lldb/include/lldb/Target/ProcessTrace.h
@@ -71,7 +71,7 @@ class ProcessTrace : public PostMortemProcess {
   bool DoUpdateThreadList(ThreadList &old_thread_list,
   ThreadList &new_thread_list) override;
 
-private:
+public:
   static lldb::ProcessSP CreateInstance(lldb::TargetSP target_sp,
 lldb::ListenerSP listener_sp,
 const FileSpec *crash_file_path,
diff --git 
a/lldb/source/Plugins/Trace/intel-pt/CommandObjectTraceStartIntelPT.cpp 
b/lldb/source/Plugins/Trace/intel-pt/CommandObjectTraceStartIntelPT.cpp
index d4f7dc354e9fed..44224229e625bf 100644
--- a/lldb/source/Plugins/Trace/intel-pt/CommandObjectTraceStartIntelPT.cpp
+++ b/lldb/source/Plugins/Trace/intel-pt/CommandObjectTraceStartIntelPT.cpp
@@ -158,7 +158,7 @@ 
CommandObjectProcessTraceStartIntelPT::CommandOptions::GetDefinitions() {
   return llvm::ArrayRef(g_process_trace_start_intel_pt_options);
 }
 
-bool CommandObjectProcessTraceStartIntelPT::DoExecute(
+void CommandObjectProcessTraceStartIntelPT::DoExecute(
 Args &command, CommandReturnObject &result) {
   if (Error err = m_trace.Start(
   m_options.m_ipt_trace_size, m_options.m_process_buffer_size_limit,
@@ -167,8 +167,6 @@ bool CommandObjectProcessTraceStartIntelPT::DoExecute(
 result.SetError(Status(std::move(err)));
   else
 result.SetStatus(eReturnStatusSuccessFinishResult);
-
-  return result.Succeeded();
 }
 
 std::optional
diff --git a/lldb/source/Plugins/Trace/intel-pt/DecodedThread.h 
b/lldb/source/Plugins/Trace/intel-pt/DecodedThread.h
index 5745cdb67ab68f..ba66a09d3e762e 100644
--- a/lldb/source/Plugins/Trace/intel-pt/DecodedThread.h
+++ b/lldb/source/Plugins/Trace/intel-pt/DecodedThread.h
@@ -276,6 +276,9 @@ class DecodedThread : public 
std::enable_shared_from_this {
 
 /// The string message of this item if it's an error
 std::string error;
+
+TraceItemStorage() {}
+~TraceItemStorage() {}
   };
 
   /// Create a new trace item.
@@ -285,10 +288,10 @@ class DecodedThread : public 
std::enable_shared_from_this {
   DecodedThread::TraceItemStorage &CreateNewTraceItem(lldb::TraceItemKind 
kind);
 
   /// Most of the trace data is stored here.
-  std::vector m_item_data;
+  std::deque m_item_data;
   /// The TraceItemKind for each trace item encoded as uint8_t. We don't 
include
   /// it in TraceItemStorage to avoid padding.
-  std::vector m_item_kinds;
+  std::deque m_item_kinds;
 
   /// This map contains the TSCs of the decoded trace items. It maps
   /// `item index -> TSC`, where `item index` is the first index
diff --git a/lldb/source/Plugins/Trace/intel-pt/LibiptDecoder.cpp 
b/lldb/source/Plugins/Trace/intel-pt/LibiptDecoder.cpp
index cdf81954eee902..f8241ef6a79329 100644
--- a/lldb/source/Plugins/Trace/intel-pt/LibiptDecoder.cpp
+++ b/lldb/source/Plugins/Trace/intel-pt/LibiptDecoder.cpp
@@ -572,7 +572,7 @@ Error 
lldb_private::trace_intel_pt::DecodeSingleTraceForThread(
 Expected decoder = PSBBlockDecoder::Create(
 trace_intel_pt, block, buffer.slice(block.psb_offset, block.size),
 *decoded_thread.GetThread()->GetProcess(),
-i + 1 < blocks->size() ? blocks->at(i + 1).starting_ip : None,
+i + 1 < blocks->size() ? blocks->at(i + 1).starting_ip : std::nullopt,
 decoded_thread, std::nullopt);
 if (!decoder)
   return decoder.takeError();
@@ -640,7 +640,7 @@ Error 
lldb_private::trace_intel_pt::DecodeSystemWideTraceForThread(
   *decoded_thread.GetThread()->GetProcess(),
   j + 1 < execution.psb_blocks.size()
   ? execution.psb_blocks[j + 1].starting_ip
-  : None,
+  : std::nullopt,
   decoded_thread, execution.thread_execution.GetEndTSC());
   if (!decoder)
 return decoder.takeError();
diff --git a/lldb/source/Plugins/Trace/intel-pt/TraceCursorIntelPT.cpp 
b/lldb/source/Plugins/Trace/intel-pt/TraceCursorIntelPT.cpp
index 66d342196cf10d..dda6cd74343f0f 100644
--- a/lldb/source/Plugins/Trace/intel-pt/TraceCurso

[Lldb-commits] [lldb] [lldb] Fix Intel PT plugin compile errors (PR #77252)

2024-01-08 Thread Nicholas Mosier via lldb-commits

https://github.com/nmosier updated 
https://github.com/llvm/llvm-project/pull/77252

>From ffe2dff5783e57dfbc40b1840a784a28ea18ef26 Mon Sep 17 00:00:00 2001
From: Nicholas Mosier 
Date: Sun, 7 Jan 2024 20:06:55 +
Subject: [PATCH] [lldb] Fix Intel PT plugin compile errors

Fix #77251.
---
 lldb/include/lldb/Target/ProcessTrace.h |  2 +-
 .../intel-pt/CommandObjectTraceStartIntelPT.cpp |  4 +---
 lldb/source/Plugins/Trace/intel-pt/DecodedThread.h  |  9 ++---
 .../source/Plugins/Trace/intel-pt/LibiptDecoder.cpp |  4 ++--
 .../Plugins/Trace/intel-pt/TraceCursorIntelPT.cpp   |  4 ++--
 .../Trace/intel-pt/TraceIntelPTBundleLoader.cpp | 13 ++---
 6 files changed, 18 insertions(+), 18 deletions(-)

diff --git a/lldb/include/lldb/Target/ProcessTrace.h 
b/lldb/include/lldb/Target/ProcessTrace.h
index 037dea232cc024..201754e975e4fb 100644
--- a/lldb/include/lldb/Target/ProcessTrace.h
+++ b/lldb/include/lldb/Target/ProcessTrace.h
@@ -71,7 +71,7 @@ class ProcessTrace : public PostMortemProcess {
   bool DoUpdateThreadList(ThreadList &old_thread_list,
   ThreadList &new_thread_list) override;
 
-private:
+public:
   static lldb::ProcessSP CreateInstance(lldb::TargetSP target_sp,
 lldb::ListenerSP listener_sp,
 const FileSpec *crash_file_path,
diff --git 
a/lldb/source/Plugins/Trace/intel-pt/CommandObjectTraceStartIntelPT.cpp 
b/lldb/source/Plugins/Trace/intel-pt/CommandObjectTraceStartIntelPT.cpp
index d4f7dc354e9fed..44224229e625bf 100644
--- a/lldb/source/Plugins/Trace/intel-pt/CommandObjectTraceStartIntelPT.cpp
+++ b/lldb/source/Plugins/Trace/intel-pt/CommandObjectTraceStartIntelPT.cpp
@@ -158,7 +158,7 @@ 
CommandObjectProcessTraceStartIntelPT::CommandOptions::GetDefinitions() {
   return llvm::ArrayRef(g_process_trace_start_intel_pt_options);
 }
 
-bool CommandObjectProcessTraceStartIntelPT::DoExecute(
+void CommandObjectProcessTraceStartIntelPT::DoExecute(
 Args &command, CommandReturnObject &result) {
   if (Error err = m_trace.Start(
   m_options.m_ipt_trace_size, m_options.m_process_buffer_size_limit,
@@ -167,8 +167,6 @@ bool CommandObjectProcessTraceStartIntelPT::DoExecute(
 result.SetError(Status(std::move(err)));
   else
 result.SetStatus(eReturnStatusSuccessFinishResult);
-
-  return result.Succeeded();
 }
 
 std::optional
diff --git a/lldb/source/Plugins/Trace/intel-pt/DecodedThread.h 
b/lldb/source/Plugins/Trace/intel-pt/DecodedThread.h
index 5745cdb67ab68f..0f2c6e56bd541e 100644
--- a/lldb/source/Plugins/Trace/intel-pt/DecodedThread.h
+++ b/lldb/source/Plugins/Trace/intel-pt/DecodedThread.h
@@ -14,9 +14,9 @@
 #include "lldb/Utility/TraceIntelPTGDBRemotePackets.h"
 #include "llvm/Support/Errc.h"
 #include "llvm/Support/Error.h"
+#include 
 #include 
 #include 
-#include 
 
 namespace lldb_private {
 namespace trace_intel_pt {
@@ -276,6 +276,9 @@ class DecodedThread : public 
std::enable_shared_from_this {
 
 /// The string message of this item if it's an error
 std::string error;
+
+TraceItemStorage() {}
+~TraceItemStorage() {}
   };
 
   /// Create a new trace item.
@@ -285,10 +288,10 @@ class DecodedThread : public 
std::enable_shared_from_this {
   DecodedThread::TraceItemStorage &CreateNewTraceItem(lldb::TraceItemKind 
kind);
 
   /// Most of the trace data is stored here.
-  std::vector m_item_data;
+  std::deque m_item_data;
   /// The TraceItemKind for each trace item encoded as uint8_t. We don't 
include
   /// it in TraceItemStorage to avoid padding.
-  std::vector m_item_kinds;
+  std::deque m_item_kinds;
 
   /// This map contains the TSCs of the decoded trace items. It maps
   /// `item index -> TSC`, where `item index` is the first index
diff --git a/lldb/source/Plugins/Trace/intel-pt/LibiptDecoder.cpp 
b/lldb/source/Plugins/Trace/intel-pt/LibiptDecoder.cpp
index cdf81954eee902..f8241ef6a79329 100644
--- a/lldb/source/Plugins/Trace/intel-pt/LibiptDecoder.cpp
+++ b/lldb/source/Plugins/Trace/intel-pt/LibiptDecoder.cpp
@@ -572,7 +572,7 @@ Error 
lldb_private::trace_intel_pt::DecodeSingleTraceForThread(
 Expected decoder = PSBBlockDecoder::Create(
 trace_intel_pt, block, buffer.slice(block.psb_offset, block.size),
 *decoded_thread.GetThread()->GetProcess(),
-i + 1 < blocks->size() ? blocks->at(i + 1).starting_ip : None,
+i + 1 < blocks->size() ? blocks->at(i + 1).starting_ip : std::nullopt,
 decoded_thread, std::nullopt);
 if (!decoder)
   return decoder.takeError();
@@ -640,7 +640,7 @@ Error 
lldb_private::trace_intel_pt::DecodeSystemWideTraceForThread(
   *decoded_thread.GetThread()->GetProcess(),
   j + 1 < execution.psb_blocks.size()
   ? execution.psb_blocks[j + 1].starting_ip
-  : None,
+  : std::nullopt,
   decoded_thread, execution.thread_execution.GetEndTSC());
   if (!decoder)
 return decoder

[Lldb-commits] [lldb] [lldb] Fix Intel PT plugin compile errors (PR #77252)

2024-01-08 Thread Nicholas Mosier via lldb-commits


@@ -85,6 +85,11 @@ double DecodedThread::NanosecondsRange::GetInterpolatedTime(
   return interpolate(next_range->nanos);
 }
 
+DecodedThread::TraceItemStorage::TraceItemStorage(
+const TraceItemStorage &other) {
+  std::memcpy(this, &other, sizeof *this);

nmosier wrote:

Thanks for the  suggestion, I changed `DecodedThread::m_item_{kinds,data}` to 
`std::deque`s and removed the `TraceItemStorage`'s copy constructor.

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


[Lldb-commits] [lldb] [lldb] Fix Intel PT plugin compile errors (PR #77252)

2024-01-08 Thread Nicholas Mosier via lldb-commits


@@ -103,12 +103,10 @@ TraceIntelPTBundleLoader::CreateEmptyProcess(lldb::pid_t 
pid,
   ParsedProcess parsed_process;
   parsed_process.target_sp = target_sp;
 
-  // This should instead try to directly create an instance of ProcessTrace.
-  // ProcessSP process_sp = target_sp->CreateProcess(
-  ///*listener*/ nullptr, "trace",
-  ///*crash_file*/ nullptr,
-  ///*can_connect*/ false);
-
+  ProcessSP process_sp = target_sp->CreateProcess(
+  /*listener*/ nullptr, "trace",
+  /*crash_file*/ nullptr,
+  /*can_connect*/ false);

nmosier wrote:

@walter-erquinigo Thanks for the suggestion! I implemented that change.

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


[Lldb-commits] [lldb] [lldb] Fix Intel PT plugin compile errors (PR #77252)

2024-01-08 Thread Nicholas Mosier via lldb-commits


@@ -108,8 +108,8 @@ TraceIntelPTBundleLoader::CreateEmptyProcess(lldb::pid_t 
pid,
   ///*listener*/ nullptr, "trace",
   ///*crash_file*/ nullptr,
   ///*can_connect*/ false);
-
-  process_sp->SetID(static_cast(pid));
+  //
+  // process_sp->SetID(static_cast(pid));

nmosier wrote:

I reverted this, given your suggestion in the other thread.

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


[Lldb-commits] [lldb] [lldb] Fix Intel PT plugin compile errors (PR #77252)

2024-01-08 Thread Walter Erquinigo via lldb-commits

https://github.com/walter-erquinigo commented:

These changes lgtm at this point. Btw, how are you testing them?

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


[Lldb-commits] [lldb] [lldb] Fix Intel PT plugin compile errors (PR #77252)

2024-01-08 Thread Nicholas Mosier via lldb-commits

nmosier wrote:

> Btw, how are you testing them?

Not very rigorously, ha. Just something like
```
b main
r
process trace start
c
thread trace dump instructions
```
I was using a version with my original fixes to debug other code that was 
crashing, and it worked fine for that.

Are there existing tests I should be using? 

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


[Lldb-commits] [libcxxabi] [libc] [flang] [llvm] [lldb] [mlir] [compiler-rt] [clang-tools-extra] [libcxx] [openmp] [clang] [OpenMP] Patch for Support to loop bind clause : Checking Parent Region (PR #

2024-01-08 Thread Alexey Bataev via lldb-commits


@@ -6124,35 +6136,39 @@ processImplicitMapsWithDefaultMappers(Sema &S, 
DSAStackTy *Stack,
 
 bool Sema::mapLoopConstruct(llvm::SmallVector &ClausesWithoutBind,
 ArrayRef Clauses,
-OpenMPBindClauseKind BindKind,
+OpenMPBindClauseKind &BindKind,
 OpenMPDirectiveKind &Kind,
-OpenMPDirectiveKind &PrevMappedDirective) {
+OpenMPDirectiveKind &PrevMappedDirective,
+SourceLocation StartLoc, SourceLocation EndLoc,
+const DeclarationNameInfo &DirName,
+OpenMPDirectiveKind CancelRegion) {
 
   bool UseClausesWithoutBind = false;
 
   // Restricting to "#pragma omp loop bind"
   if (getLangOpts().OpenMP >= 50 && Kind == OMPD_loop) {
+
+const OpenMPDirectiveKind ParentDirective = DSAStack->getParentDirective();
+
 if (BindKind == OMPC_BIND_unknown) {
   // Setting the enclosing teams or parallel construct for the loop
   // directive without bind clause.
   BindKind = OMPC_BIND_thread; // Default bind(thread) if binding is 
unknown
 
-  const OpenMPDirectiveKind ParentDirective =
-  DSAStack->getParentDirective();
   if (ParentDirective == OMPD_unknown) {
 Diag(DSAStack->getDefaultDSALocation(),
  diag::err_omp_bind_required_on_loop);
   } else if (ParentDirective == OMPD_parallel ||
- ParentDirective == OMPD_target_parallel) {
+ ParentDirective == OMPD_target_parallel)
 BindKind = OMPC_BIND_parallel;
-  } else if (ParentDirective == OMPD_teams ||
- ParentDirective == OMPD_target_teams) {
-BindKind = OMPC_BIND_teams;
-  }
+} else if (ParentDirective == OMPD_teams ||
+   ParentDirective == OMPD_target_teams) {
+  BindKind = OMPC_BIND_teams;

alexey-bataev wrote:

Please restore original code here

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


[Lldb-commits] [libunwind] [llvm] [libcxx] [lld] [lldb] [flang] [libc] [clang] [compiler-rt] [clang-tools-extra] [libc++][test] try to directly create socket file in /tmp when filepath is too long (PR

2024-01-08 Thread Mark de Wever via lldb-commits

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

Thanks! LGTM!

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


[Lldb-commits] [clang] [lld] [compiler-rt] [flang] [llvm] [libcxx] [lldb] [libunwind] [libc] [clang-tools-extra] [libc++][test] try to directly create socket file in /tmp when filepath is too long (PR

2024-01-08 Thread Mark de Wever via lldb-commits

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


[Lldb-commits] [clang-tools-extra] [libcxx] [clang] [lldb] [compiler-rt] [lld] [llvm] [libunwind] [libc] [flang] [libc++][test] try to directly create socket file in /tmp when filepath is too long (PR

2024-01-08 Thread Mark de Wever via lldb-commits


@@ -320,16 +320,26 @@ struct scoped_test_env
   // allow tests to call this unguarded.
 #if !defined(__FreeBSD__) && !defined(__APPLE__) && !defined(_WIN32)
 std::string create_socket(std::string file) {
-file = sanitize_path(std::move(file));
-
-::sockaddr_un address;
-address.sun_family = AF_UNIX;
-assert(file.size() <= sizeof(address.sun_path));
-::strncpy(address.sun_path, file.c_str(), sizeof(address.sun_path));
-int fd = ::socket(AF_UNIX, SOCK_STREAM, 0);
-::bind(fd, reinterpret_cast<::sockaddr*>(&address), sizeof(address));
-return file;
+  file = sanitize_path(std::move(file));
+
+  ::sockaddr_un address;
+  address.sun_family = AF_UNIX;
+
+// If file.size() is too big, try to create a file directly inside
+// /tmp to make sure file path is short enough.
+// Android platform warns about tmpnam, since the problem does not appear
+// on Android, let's not apply it for Android.

mordante wrote:

Not too happy about this, but since we assert afterwards it will fail the test. 
If that happens we can investigate.

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


[Lldb-commits] [lldb] [lldb] Fix Intel PT plugin compile errors (PR #77252)

2024-01-08 Thread Walter Erquinigo via lldb-commits

walter-erquinigo wrote:

`third-party/llvm-project/lldb/test/API/commands/trace` has a set of pythong 
tests.

You should be able to run them with

```
build lldb-dotest
lldb-dotest -p TestTrace
```

Also, the CMake variable `LLDB_INCLUDE_TESTS` must be enabled (e.g. `ON`) in 
order to build `lldb-dotest`

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


[Lldb-commits] [clang] [libcxx] [lld] [lldb] [compiler-rt] [clang-tools-extra] [openmp] [mlir] [llvm] [flang] [clang] Add `intrin0.h` header to mimic `intrin0.h` used by MSVC STL for clang-cl (PR #757

2024-01-08 Thread Aaron Ballman via lldb-commits

AaronBallman wrote:

> If we land this as-is, it'll tank build time on Windows.

I would like some measurements so we can compare build times on Windows.

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


[Lldb-commits] [lldb] [lldb][[DWARFDeclContext] Add function to extract qualified names as vector (PR #77349)

2024-01-08 Thread Felipe de Azevedo Piovezan via lldb-commits

https://github.com/felipepiovezan created 
https://github.com/llvm/llvm-project/pull/77349

This functionality will support the efforts to implement the IDX_Parent 
attribute of accelerator table entries, and it will allow us to more easily 
compare each of the names in a DIE parent chain hierarchy.

>From 1b444a334fdfd5c88e263e9804cffbd7574a670b Mon Sep 17 00:00:00 2001
From: Felipe de Azevedo Piovezan 
Date: Mon, 11 Dec 2023 12:42:40 -0300
Subject: [PATCH] [lldb][[DWARFDeclContext] Add function to extract qualified
 names as vector

This functionality will support the efforts to implement the IDX_Parent
attribute of accelerator table entries, and it will allow us to more easily
compare each of the names in a DIE parent chain hierarchy.
---
 .../SymbolFile/DWARF/DWARFDeclContext.cpp |   6 +
 .../SymbolFile/DWARF/DWARFDeclContext.h   |   5 +
 .../SymbolFile/DWARF/DWARFDIETest.cpp | 109 ++
 3 files changed, 120 insertions(+)

diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDeclContext.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDeclContext.cpp
index 44421c0eda3eec..3cdb47d50bbfc0 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDeclContext.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDeclContext.cpp
@@ -55,6 +55,12 @@ const char *DWARFDeclContext::GetQualifiedName() const {
   return m_qualified_name.c_str();
 }
 
+llvm::SmallVector
+DWARFDeclContext::GetQualifiedNameAsVector() const {
+  return llvm::to_vector_of(
+  llvm::map_range(m_entries, GetName));
+}
+
 bool DWARFDeclContext::operator==(const DWARFDeclContext &rhs) const {
   if (m_entries.size() != rhs.m_entries.size())
 return false;
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDeclContext.h 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDeclContext.h
index a20a862d340296..40ebb72c91d8f0 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDeclContext.h
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDeclContext.h
@@ -68,6 +68,11 @@ class DWARFDeclContext {
 
   const char *GetQualifiedName() const;
 
+  /// Returns a vector of string, one string per entry in the fully qualified
+  /// name. For example, for the name `A::B::C`, this methods returns `{"A",
+  /// "B", "C"}`
+  llvm::SmallVector GetQualifiedNameAsVector() const;
+
   // Same as GetQualifiedName, but the life time of the returned string will
   // be that of the LLDB session.
   ConstString GetQualifiedNameAsConstString() const {
diff --git a/lldb/unittests/SymbolFile/DWARF/DWARFDIETest.cpp 
b/lldb/unittests/SymbolFile/DWARF/DWARFDIETest.cpp
index 8497855b2f3db5..5672270ee31f89 100644
--- a/lldb/unittests/SymbolFile/DWARF/DWARFDIETest.cpp
+++ b/lldb/unittests/SymbolFile/DWARF/DWARFDIETest.cpp
@@ -7,8 +7,10 @@
 
//===--===//
 
 #include "Plugins/SymbolFile/DWARF/DWARFDIE.h"
+#include "Plugins/SymbolFile/DWARF/DWARFDeclContext.h"
 #include "TestingSupport/Symbol/YAMLModuleTester.h"
 #include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/StringRef.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 
@@ -104,3 +106,110 @@ TEST(DWARFDIETest, ChildIteration) {
   DWARFDIE no_children_die(unit, die_child0);
   EXPECT_TRUE(no_children_die.children().empty());
 }
+
+TEST(DWARFDIETest, DeclContext) {
+  const char *yamldata = R"(
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS64
+  Data:ELFDATA2LSB
+  Type:ET_EXEC
+  Machine: EM_386
+DWARF:
+  debug_str:
+- 'mynamespace'
+- 'mystruct'
+- 'mytype'
+  debug_abbrev:
+- Table:
+- Code:0x0001
+  Tag: DW_TAG_compile_unit
+  Children:DW_CHILDREN_yes
+  Attributes:
+- Attribute:   DW_AT_language
+  Form:DW_FORM_data2
+- Code:0x0002
+  Tag: DW_TAG_structure_type
+  Children:DW_CHILDREN_yes
+  Attributes:
+- Attribute:   DW_AT_name
+  Form:DW_FORM_strp
+- Code:0x0003
+  Tag: DW_TAG_base_type
+  Children:DW_CHILDREN_no
+  Attributes:
+- Attribute:   DW_AT_name
+  Form:DW_FORM_strp
+- Code:0x0004
+  Tag: DW_TAG_namespace
+  Children:DW_CHILDREN_yes
+  Attributes:
+- Attribute:   DW_AT_name
+  Form:DW_FORM_strp
+  debug_info:
+- Version: 4
+  AddrSize:8
+  Entries:
+- AbbrCode:0x0001 # compile_unit
+  Values:
+- Value:   0x000C
+- AbbrCode:0x0004 # namespace
+  Values:
+- Value:   0x # DW_ATE_strp
+- AbbrCode:0x0002 # structure_type
+  Values:
+- Value:   0x000c 

[Lldb-commits] [lldb] [lldb][[DWARFDeclContext] Add function to extract qualified names as vector (PR #77349)

2024-01-08 Thread Felipe de Azevedo Piovezan via lldb-commits

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


[Lldb-commits] [lldb] [lldb][[DWARFDeclContext] Add function to extract qualified names as vector (PR #77349)

2024-01-08 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Felipe de Azevedo Piovezan (felipepiovezan)


Changes

This functionality will support the efforts to implement the IDX_Parent 
attribute of accelerator table entries, and it will allow us to more easily 
compare each of the names in a DIE parent chain hierarchy.

https://discourse.llvm.org/t/rfc-improve-dwarf-5-debug-names-type-lookup-parsing-speed/74151/45

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


3 Files Affected:

- (modified) lldb/source/Plugins/SymbolFile/DWARF/DWARFDeclContext.cpp (+6) 
- (modified) lldb/source/Plugins/SymbolFile/DWARF/DWARFDeclContext.h (+5) 
- (modified) lldb/unittests/SymbolFile/DWARF/DWARFDIETest.cpp (+109) 


``diff
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDeclContext.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDeclContext.cpp
index 44421c0eda3eec..3cdb47d50bbfc0 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDeclContext.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDeclContext.cpp
@@ -55,6 +55,12 @@ const char *DWARFDeclContext::GetQualifiedName() const {
   return m_qualified_name.c_str();
 }
 
+llvm::SmallVector
+DWARFDeclContext::GetQualifiedNameAsVector() const {
+  return llvm::to_vector_of(
+  llvm::map_range(m_entries, GetName));
+}
+
 bool DWARFDeclContext::operator==(const DWARFDeclContext &rhs) const {
   if (m_entries.size() != rhs.m_entries.size())
 return false;
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDeclContext.h 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDeclContext.h
index a20a862d340296..40ebb72c91d8f0 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDeclContext.h
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDeclContext.h
@@ -68,6 +68,11 @@ class DWARFDeclContext {
 
   const char *GetQualifiedName() const;
 
+  /// Returns a vector of string, one string per entry in the fully qualified
+  /// name. For example, for the name `A::B::C`, this methods returns `{"A",
+  /// "B", "C"}`
+  llvm::SmallVector GetQualifiedNameAsVector() const;
+
   // Same as GetQualifiedName, but the life time of the returned string will
   // be that of the LLDB session.
   ConstString GetQualifiedNameAsConstString() const {
diff --git a/lldb/unittests/SymbolFile/DWARF/DWARFDIETest.cpp 
b/lldb/unittests/SymbolFile/DWARF/DWARFDIETest.cpp
index 8497855b2f3db5..5672270ee31f89 100644
--- a/lldb/unittests/SymbolFile/DWARF/DWARFDIETest.cpp
+++ b/lldb/unittests/SymbolFile/DWARF/DWARFDIETest.cpp
@@ -7,8 +7,10 @@
 
//===--===//
 
 #include "Plugins/SymbolFile/DWARF/DWARFDIE.h"
+#include "Plugins/SymbolFile/DWARF/DWARFDeclContext.h"
 #include "TestingSupport/Symbol/YAMLModuleTester.h"
 #include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/StringRef.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 
@@ -104,3 +106,110 @@ TEST(DWARFDIETest, ChildIteration) {
   DWARFDIE no_children_die(unit, die_child0);
   EXPECT_TRUE(no_children_die.children().empty());
 }
+
+TEST(DWARFDIETest, DeclContext) {
+  const char *yamldata = R"(
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS64
+  Data:ELFDATA2LSB
+  Type:ET_EXEC
+  Machine: EM_386
+DWARF:
+  debug_str:
+- 'mynamespace'
+- 'mystruct'
+- 'mytype'
+  debug_abbrev:
+- Table:
+- Code:0x0001
+  Tag: DW_TAG_compile_unit
+  Children:DW_CHILDREN_yes
+  Attributes:
+- Attribute:   DW_AT_language
+  Form:DW_FORM_data2
+- Code:0x0002
+  Tag: DW_TAG_structure_type
+  Children:DW_CHILDREN_yes
+  Attributes:
+- Attribute:   DW_AT_name
+  Form:DW_FORM_strp
+- Code:0x0003
+  Tag: DW_TAG_base_type
+  Children:DW_CHILDREN_no
+  Attributes:
+- Attribute:   DW_AT_name
+  Form:DW_FORM_strp
+- Code:0x0004
+  Tag: DW_TAG_namespace
+  Children:DW_CHILDREN_yes
+  Attributes:
+- Attribute:   DW_AT_name
+  Form:DW_FORM_strp
+  debug_info:
+- Version: 4
+  AddrSize:8
+  Entries:
+- AbbrCode:0x0001 # compile_unit
+  Values:
+- Value:   0x000C
+- AbbrCode:0x0004 # namespace
+  Values:
+- Value:   0x # DW_ATE_strp
+- AbbrCode:0x0002 # structure_type
+  Values:
+- Value:   0x000c # DW_ATE_strp
+- AbbrCode:0x0003 # base_type
+  Values:
+- Value:   0x0015 # DW_ATE_strp
+- AbbrCode:0x
+)";
+
+  YAMLModuleTester t(yamldata);

[Lldb-commits] [lldb] [lldb][[DWARFDeclContext] Add function to extract qualified names as vector (PR #77349)

2024-01-08 Thread Felipe de Azevedo Piovezan via lldb-commits


@@ -68,6 +68,11 @@ class DWARFDeclContext {
 
   const char *GetQualifiedName() const;
 
+  /// Returns a vector of string, one string per entry in the fully qualified
+  /// name. For example, for the name `A::B::C`, this methods returns `{"A",
+  /// "B", "C"}`
+  llvm::SmallVector GetQualifiedNameAsVector() const;

felipepiovezan wrote:

Oops, this comment is wrong: the order of the strings is reversed here.

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


[Lldb-commits] [lldb] [lldb][[DWARFDeclContext] Add function to extract qualified names as vector (PR #77349)

2024-01-08 Thread Felipe de Azevedo Piovezan via lldb-commits

https://github.com/felipepiovezan updated 
https://github.com/llvm/llvm-project/pull/77349

>From 1b444a334fdfd5c88e263e9804cffbd7574a670b Mon Sep 17 00:00:00 2001
From: Felipe de Azevedo Piovezan 
Date: Mon, 11 Dec 2023 12:42:40 -0300
Subject: [PATCH 1/2] [lldb][[DWARFDeclContext] Add function to extract
 qualified names as vector

This functionality will support the efforts to implement the IDX_Parent
attribute of accelerator table entries, and it will allow us to more easily
compare each of the names in a DIE parent chain hierarchy.
---
 .../SymbolFile/DWARF/DWARFDeclContext.cpp |   6 +
 .../SymbolFile/DWARF/DWARFDeclContext.h   |   5 +
 .../SymbolFile/DWARF/DWARFDIETest.cpp | 109 ++
 3 files changed, 120 insertions(+)

diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDeclContext.cpp 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDeclContext.cpp
index 44421c0eda3eec..3cdb47d50bbfc0 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDeclContext.cpp
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDeclContext.cpp
@@ -55,6 +55,12 @@ const char *DWARFDeclContext::GetQualifiedName() const {
   return m_qualified_name.c_str();
 }
 
+llvm::SmallVector
+DWARFDeclContext::GetQualifiedNameAsVector() const {
+  return llvm::to_vector_of(
+  llvm::map_range(m_entries, GetName));
+}
+
 bool DWARFDeclContext::operator==(const DWARFDeclContext &rhs) const {
   if (m_entries.size() != rhs.m_entries.size())
 return false;
diff --git a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDeclContext.h 
b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDeclContext.h
index a20a862d340296..40ebb72c91d8f0 100644
--- a/lldb/source/Plugins/SymbolFile/DWARF/DWARFDeclContext.h
+++ b/lldb/source/Plugins/SymbolFile/DWARF/DWARFDeclContext.h
@@ -68,6 +68,11 @@ class DWARFDeclContext {
 
   const char *GetQualifiedName() const;
 
+  /// Returns a vector of string, one string per entry in the fully qualified
+  /// name. For example, for the name `A::B::C`, this methods returns `{"A",
+  /// "B", "C"}`
+  llvm::SmallVector GetQualifiedNameAsVector() const;
+
   // Same as GetQualifiedName, but the life time of the returned string will
   // be that of the LLDB session.
   ConstString GetQualifiedNameAsConstString() const {
diff --git a/lldb/unittests/SymbolFile/DWARF/DWARFDIETest.cpp 
b/lldb/unittests/SymbolFile/DWARF/DWARFDIETest.cpp
index 8497855b2f3db5..5672270ee31f89 100644
--- a/lldb/unittests/SymbolFile/DWARF/DWARFDIETest.cpp
+++ b/lldb/unittests/SymbolFile/DWARF/DWARFDIETest.cpp
@@ -7,8 +7,10 @@
 
//===--===//
 
 #include "Plugins/SymbolFile/DWARF/DWARFDIE.h"
+#include "Plugins/SymbolFile/DWARF/DWARFDeclContext.h"
 #include "TestingSupport/Symbol/YAMLModuleTester.h"
 #include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/StringRef.h"
 #include "gmock/gmock.h"
 #include "gtest/gtest.h"
 
@@ -104,3 +106,110 @@ TEST(DWARFDIETest, ChildIteration) {
   DWARFDIE no_children_die(unit, die_child0);
   EXPECT_TRUE(no_children_die.children().empty());
 }
+
+TEST(DWARFDIETest, DeclContext) {
+  const char *yamldata = R"(
+--- !ELF
+FileHeader:
+  Class:   ELFCLASS64
+  Data:ELFDATA2LSB
+  Type:ET_EXEC
+  Machine: EM_386
+DWARF:
+  debug_str:
+- 'mynamespace'
+- 'mystruct'
+- 'mytype'
+  debug_abbrev:
+- Table:
+- Code:0x0001
+  Tag: DW_TAG_compile_unit
+  Children:DW_CHILDREN_yes
+  Attributes:
+- Attribute:   DW_AT_language
+  Form:DW_FORM_data2
+- Code:0x0002
+  Tag: DW_TAG_structure_type
+  Children:DW_CHILDREN_yes
+  Attributes:
+- Attribute:   DW_AT_name
+  Form:DW_FORM_strp
+- Code:0x0003
+  Tag: DW_TAG_base_type
+  Children:DW_CHILDREN_no
+  Attributes:
+- Attribute:   DW_AT_name
+  Form:DW_FORM_strp
+- Code:0x0004
+  Tag: DW_TAG_namespace
+  Children:DW_CHILDREN_yes
+  Attributes:
+- Attribute:   DW_AT_name
+  Form:DW_FORM_strp
+  debug_info:
+- Version: 4
+  AddrSize:8
+  Entries:
+- AbbrCode:0x0001 # compile_unit
+  Values:
+- Value:   0x000C
+- AbbrCode:0x0004 # namespace
+  Values:
+- Value:   0x # DW_ATE_strp
+- AbbrCode:0x0002 # structure_type
+  Values:
+- Value:   0x000c # DW_ATE_strp
+- AbbrCode:0x0003 # base_type
+  Values:
+- Value:   0x0015 # DW_ATE_strp
+- AbbrCode:0x
+)";
+
+  YAMLModu

[Lldb-commits] [lldb] [lldb][NFCI] Remove BreakpointIDList::InsertStringArray (PR #77161)

2024-01-08 Thread Alex Langford via lldb-commits

bulbazord wrote:

> LGTM!
> 
> I see that we still have `FindAndReplaceIDRanges` referencing 
> CommandReturnObject; out of curiosity, have you had a chance to look into 
> removing that one (if it makes sense)? I see that `CommandReturnObject` is 
> neither `#include`ed nor forward declared in the header, so the code is very 
> much relying on others files to do either of those.

Yes, I planned on doing that in a follow-up. :)

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


[Lldb-commits] [lldb] [lldb][NFCI] Change return type of BreakpointIDList::GetBreakpointIDAtIndex (PR #77166)

2024-01-08 Thread Alex Langford via lldb-commits


@@ -20,17 +20,15 @@ using namespace lldb_private;
 
 // class BreakpointIDList
 
-BreakpointIDList::BreakpointIDList()
-: m_invalid_id(LLDB_INVALID_BREAK_ID, LLDB_INVALID_BREAK_ID) {}
+BreakpointIDList::BreakpointIDList() : m_breakpoint_ids() {}
 
 BreakpointIDList::~BreakpointIDList() = default;
 
 size_t BreakpointIDList::GetSize() const { return m_breakpoint_ids.size(); }
 
-const BreakpointID &
-BreakpointIDList::GetBreakpointIDAtIndex(size_t index) const {
+BreakpointID BreakpointIDList::GetBreakpointIDAtIndex(size_t index) const {
   return ((index < m_breakpoint_ids.size()) ? m_breakpoint_ids[index]
-: m_invalid_id);
+: BreakpointID());

bulbazord wrote:

The default constructor for `BreakpointID` sets the breakpoint id and location 
id to invalid values.

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


[Lldb-commits] [lldb] 07d6fbf - [lldb][NFCI] Remove BreakpointIDList::InsertStringArray (#77161)

2024-01-08 Thread via lldb-commits

Author: Alex Langford
Date: 2024-01-08T10:51:00-08:00
New Revision: 07d6fbf8d80083470b4371f2ddabd656a9c317e6

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

LOG: [lldb][NFCI] Remove BreakpointIDList::InsertStringArray (#77161)

This abstraction is leaky and BreakpointIDList does not need to know
about CommandReturnObject.
Additionally, setting the CommandReturnObject inout param to a success
state does very little. The function returns immediately if the input
ArrayRef is empty, and reading
CommandObjectMultiwordBreakpoint::VerifyIDs more closely, the input is
always empty if the previous call to
BreakpointIDList::FindAndReplaceIDRanges failed. If the call was
successful, then the CommandReturnObject is already in a success state.

I have opted to remove the function altogether and inline the
functionality where it was used.

Added: 


Modified: 
lldb/include/lldb/Breakpoint/BreakpointIDList.h
lldb/source/Breakpoint/BreakpointIDList.cpp
lldb/source/Commands/CommandObjectBreakpoint.cpp

Removed: 




diff  --git a/lldb/include/lldb/Breakpoint/BreakpointIDList.h 
b/lldb/include/lldb/Breakpoint/BreakpointIDList.h
index 924cb1f26b8b8a..161d1a2d314ead 100644
--- a/lldb/include/lldb/Breakpoint/BreakpointIDList.h
+++ b/lldb/include/lldb/Breakpoint/BreakpointIDList.h
@@ -48,9 +48,6 @@ class BreakpointIDList {
 
   bool FindBreakpointID(const char *bp_id, size_t *position) const;
 
-  void InsertStringArray(llvm::ArrayRef string_array,
- CommandReturnObject &result);
-
   // Returns a pair consisting of the beginning and end of a breakpoint
   // ID range expression.  If the input string is not a valid specification,
   // returns an empty pair.

diff  --git a/lldb/source/Breakpoint/BreakpointIDList.cpp 
b/lldb/source/Breakpoint/BreakpointIDList.cpp
index dd16d3b6388c46..c4fdbc370b223d 100644
--- a/lldb/source/Breakpoint/BreakpointIDList.cpp
+++ b/lldb/source/Breakpoint/BreakpointIDList.cpp
@@ -82,19 +82,6 @@ bool BreakpointIDList::FindBreakpointID(const char 
*bp_id_str,
   return FindBreakpointID(*bp_id, position);
 }
 
-void BreakpointIDList::InsertStringArray(
-llvm::ArrayRef string_array, CommandReturnObject &result) {
-  if(string_array.empty())
-return;
-
-  for (const char *str : string_array) {
-auto bp_id = BreakpointID::ParseCanonicalReference(str);
-if (bp_id)
-  m_breakpoint_ids.push_back(*bp_id);
-  }
-  result.SetStatus(eReturnStatusSuccessFinishNoResult);
-}
-
 //  This function takes OLD_ARGS, which is usually the result of breaking the
 //  command string arguments into
 //  an array of space-separated strings, and searches through the arguments for

diff  --git a/lldb/source/Commands/CommandObjectBreakpoint.cpp 
b/lldb/source/Commands/CommandObjectBreakpoint.cpp
index 63492590d32d66..f9ba68eda3ff1f 100644
--- a/lldb/source/Commands/CommandObjectBreakpoint.cpp
+++ b/lldb/source/Commands/CommandObjectBreakpoint.cpp
@@ -2494,7 +2494,9 @@ void CommandObjectMultiwordBreakpoint::VerifyIDs(
   // NOW, convert the list of breakpoint id strings in TEMP_ARGS into an actual
   // BreakpointIDList:
 
-  valid_ids->InsertStringArray(temp_args.GetArgumentArrayRef(), result);
+  for (llvm::StringRef temp_arg : temp_args.GetArgumentArrayRef())
+if (auto bp_id = BreakpointID::ParseCanonicalReference(temp_arg))
+  valid_ids->AddBreakpointID(*bp_id);
 
   // At this point,  all of the breakpoint ids that the user passed in have
   // been converted to breakpoint IDs and put into valid_ids.



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


[Lldb-commits] [lldb] [lldb][NFCI] Remove BreakpointIDList::InsertStringArray (PR #77161)

2024-01-08 Thread Alex Langford via lldb-commits

https://github.com/bulbazord closed 
https://github.com/llvm/llvm-project/pull/77161
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] 5cbf74b - [lldb][NFCI] Change return type of BreakpointIDList::GetBreakpointIDAtIndex (#77166)

2024-01-08 Thread via lldb-commits

Author: Alex Langford
Date: 2024-01-08T10:52:00-08:00
New Revision: 5cbf74b012c10e9cc841a27cd5d7335e556f47dd

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

LOG: [lldb][NFCI] Change return type of 
BreakpointIDList::GetBreakpointIDAtIndex (#77166)

There are 2 motivations here:
1.) There is no need to hand out constant references to BreakpointIDs,
they are only 8 bytes big. In addition, every use of this method already
  makes a copy anyway.
2.) Each BreakpointIDList held onto an invalid BreakpointID specifically
to
  prevent lifetime issues. Returning a value means you can return an
  invalid BreakpointID instead of needing to allocate storage for an
  invalid BreakpointID.

Added: 


Modified: 
lldb/include/lldb/Breakpoint/BreakpointIDList.h
lldb/source/Breakpoint/BreakpointIDList.cpp

Removed: 




diff  --git a/lldb/include/lldb/Breakpoint/BreakpointIDList.h 
b/lldb/include/lldb/Breakpoint/BreakpointIDList.h
index 161d1a2d314ead..6910024695d898 100644
--- a/lldb/include/lldb/Breakpoint/BreakpointIDList.h
+++ b/lldb/include/lldb/Breakpoint/BreakpointIDList.h
@@ -33,7 +33,7 @@ class BreakpointIDList {
 
   size_t GetSize() const;
 
-  const BreakpointID &GetBreakpointIDAtIndex(size_t index) const;
+  BreakpointID GetBreakpointIDAtIndex(size_t index) const;
 
   bool RemoveBreakpointIDAtIndex(size_t index);
 
@@ -63,7 +63,6 @@ class BreakpointIDList {
 
 private:
   BreakpointIDArray m_breakpoint_ids;
-  BreakpointID m_invalid_id;
 
   BreakpointIDList(const BreakpointIDList &) = delete;
   const BreakpointIDList &operator=(const BreakpointIDList &) = delete;

diff  --git a/lldb/source/Breakpoint/BreakpointIDList.cpp 
b/lldb/source/Breakpoint/BreakpointIDList.cpp
index c4fdbc370b223d..05c461827cadd8 100644
--- a/lldb/source/Breakpoint/BreakpointIDList.cpp
+++ b/lldb/source/Breakpoint/BreakpointIDList.cpp
@@ -20,17 +20,15 @@ using namespace lldb_private;
 
 // class BreakpointIDList
 
-BreakpointIDList::BreakpointIDList()
-: m_invalid_id(LLDB_INVALID_BREAK_ID, LLDB_INVALID_BREAK_ID) {}
+BreakpointIDList::BreakpointIDList() : m_breakpoint_ids() {}
 
 BreakpointIDList::~BreakpointIDList() = default;
 
 size_t BreakpointIDList::GetSize() const { return m_breakpoint_ids.size(); }
 
-const BreakpointID &
-BreakpointIDList::GetBreakpointIDAtIndex(size_t index) const {
+BreakpointID BreakpointIDList::GetBreakpointIDAtIndex(size_t index) const {
   return ((index < m_breakpoint_ids.size()) ? m_breakpoint_ids[index]
-: m_invalid_id);
+: BreakpointID());
 }
 
 bool BreakpointIDList::RemoveBreakpointIDAtIndex(size_t index) {



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


[Lldb-commits] [lldb] [lldb][NFCI] Change return type of BreakpointIDList::GetBreakpointIDAtIndex (PR #77166)

2024-01-08 Thread Alex Langford via lldb-commits

https://github.com/bulbazord closed 
https://github.com/llvm/llvm-project/pull/77166
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [clang] [compiler-rt] [libcxx] [polly] [llvm] [flang] [libcxxabi] [mlir] [lldb] [openmp] [libc] [clang-tools-extra] [OpenMP] Patch for Support to loop bind clause : Checking Parent Regi

2024-01-08 Thread via lldb-commits

https://github.com/SunilKuravinakop updated 
https://github.com/llvm/llvm-project/pull/76938

>From 1dcd4703002acdde370a285089008e409043717b Mon Sep 17 00:00:00 2001
From: Sunil Kuravinakop 
Date: Thu, 4 Jan 2024 04:08:28 -0600
Subject: [PATCH 1/4] Changes uploaded to the phabricator on Dec 16th are lost
 because the phabricator is down. Hence re-uploading it to the github.com.

  Changes to be committed:
modified:   clang/include/clang/Sema/Sema.h
modified:   clang/lib/Sema/SemaOpenMP.cpp
modified:   clang/test/OpenMP/generic_loop_ast_print.cpp
modified:   clang/test/OpenMP/loop_bind_messages.cpp
modified:   clang/test/PCH/pragma-loop.cpp
---
 clang/include/clang/Sema/Sema.h  |   8 +-
 clang/lib/Sema/SemaOpenMP.cpp|  62 ---
 clang/test/OpenMP/generic_loop_ast_print.cpp |   4 +-
 clang/test/OpenMP/loop_bind_messages.cpp | 180 +--
 clang/test/PCH/pragma-loop.cpp   |   8 +-
 5 files changed, 226 insertions(+), 36 deletions(-)

diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 5e3b57ea33220b..3d8d94d200ac58 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -11335,6 +11335,7 @@ class Sema final {
   /// on the parameter of the bind clause. In the methods for the
   /// mapped directives, check the parameters of the lastprivate clause.
   bool checkLastPrivateForMappedDirectives(ArrayRef Clauses);
+
   /// Depending on the bind clause of OMPD_loop map the directive to new
   /// directives.
   ///1) loop bind(parallel) --> OMPD_for
@@ -11344,9 +11345,12 @@ class Sema final {
   /// rigorous semantic checking in the new mapped directives.
   bool mapLoopConstruct(llvm::SmallVector &ClausesWithoutBind,
 ArrayRef Clauses,
-OpenMPBindClauseKind BindKind,
+OpenMPBindClauseKind &BindKind,
 OpenMPDirectiveKind &Kind,
-OpenMPDirectiveKind &PrevMappedDirective);
+OpenMPDirectiveKind &PrevMappedDirective,
+SourceLocation StartLoc, SourceLocation EndLoc,
+const DeclarationNameInfo &DirName,
+OpenMPDirectiveKind CancelRegion);
 
 public:
   /// The declarator \p D defines a function in the scope \p S which is nested
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index f34d2959dc6191..6e060e5b8ee268 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -5072,6 +5072,18 @@ static bool checkNestingOfRegions(Sema &SemaRef, const 
DSAStackTy *Stack,
 CurrentRegion != OMPD_cancellation_point &&
 CurrentRegion != OMPD_cancel && CurrentRegion != OMPD_scan)
   return false;
+// Checks needed for mapping "loop" construct. Please check 
mapLoopConstruct
+// for a detailed explanation
+if (SemaRef.LangOpts.OpenMP >= 50 && CurrentRegion == OMPD_loop &&
+((BindKind == OMPC_BIND_parallel) || (BindKind == OMPC_BIND_teams)) &&
+(isOpenMPWorksharingDirective(ParentRegion) ||
+ ParentRegion == OMPD_loop)) {
+  int ErrorMsgNumber = (BindKind == OMPC_BIND_parallel) ? 1 : 4;
+  SemaRef.Diag(StartLoc, diag::err_omp_prohibited_region)
+  << true << getOpenMPDirectiveName(ParentRegion) << ErrorMsgNumber
+  << getOpenMPDirectiveName(CurrentRegion);
+  return true;
+}
 if (CurrentRegion == OMPD_cancellation_point ||
 CurrentRegion == OMPD_cancel) {
   // OpenMP [2.16, Nesting of Regions]
@@ -6124,35 +6136,36 @@ processImplicitMapsWithDefaultMappers(Sema &S, 
DSAStackTy *Stack,
 
 bool Sema::mapLoopConstruct(llvm::SmallVector &ClausesWithoutBind,
 ArrayRef Clauses,
-OpenMPBindClauseKind BindKind,
+OpenMPBindClauseKind &BindKind,
 OpenMPDirectiveKind &Kind,
-OpenMPDirectiveKind &PrevMappedDirective) {
+OpenMPDirectiveKind &PrevMappedDirective,
+SourceLocation StartLoc, SourceLocation EndLoc,
+const DeclarationNameInfo &DirName,
+OpenMPDirectiveKind CancelRegion) {
 
   bool UseClausesWithoutBind = false;
 
   // Restricting to "#pragma omp loop bind"
   if (getLangOpts().OpenMP >= 50 && Kind == OMPD_loop) {
+
+const OpenMPDirectiveKind ParentDirective = DSAStack->getParentDirective();
+
 if (BindKind == OMPC_BIND_unknown) {
   // Setting the enclosing teams or parallel construct for the loop
   // directive without bind clause.
   BindKind = OMPC_BIND_thread; // Default bind(thread) if binding is 
unknown
 
-  const OpenMPDirectiveKind ParentDirective =
-  DSAStack->getParentDirective();
   if (ParentDirective == OMPD_unkno

[Lldb-commits] [libc] [clang-tools-extra] [openmp] [flang] [compiler-rt] [polly] [llvm] [libcxxabi] [mlir] [clang] [lldb] [libcxx] [OpenMP] Patch for Support to loop bind clause : Checking Parent Regi

2024-01-08 Thread Alexey Bataev via lldb-commits

https://github.com/alexey-bataev approved this pull request.

LG

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


[Lldb-commits] [lldb] [lldb][libc++] Adds some C++20 calendar data formatters. (PR #76983)

2024-01-08 Thread Alex Langford via lldb-commits

https://github.com/bulbazord commented:

I don't have a lot of knowledge about the C++20 calendar types, but the LLDB 
implementation looks ok to me.

What do you think @Michael137?

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


[Lldb-commits] [lldb] [lldb][libc++] Adds some C++20 calendar data formatters. (PR #76983)

2024-01-08 Thread Michael Buch via lldb-commits


@@ -1084,3 +1084,43 @@ bool 
lldb_private::formatters::LibcxxWStringViewSummaryProvider(
   return ::LibcxxWStringSummaryProvider(valobj, stream, summary_options,
 dataobj, size);
 }
+
+bool lldb_private::formatters::LibcxxChronoMonthSummaryProvider(
+ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
+  // These are the names used in the C++20 ostream operator. Since LLVM uses
+  // C++17 it's not possible to use the ostream operator directly.
+  static const std::array months = {
+  "January", "February", "March", "April",   "May",  "June",
+  "July","August",   "September", "October", "November", "December"};
+
+  unsigned month = 
valobj.GetChildMemberWithName("__m_")->GetValueAsUnsigned(0);

Michael137 wrote:

```suggestion
  const unsigned month = 
valobj.GetChildMemberWithName("__m_")->GetValueAsUnsigned(0);
```

Also we should probably check that `GetChildMemberWithName` returns a valid 
pointer

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


[Lldb-commits] [lldb] [lldb][libc++] Adds some C++20 calendar data formatters. (PR #76983)

2024-01-08 Thread Michael Buch via lldb-commits

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

(sorry had the review comments pending but didn't click the `Submit review` 
button)

LGTM

Just left some minor comments



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


[Lldb-commits] [lldb] [lldb][libc++] Adds some C++20 calendar data formatters. (PR #76983)

2024-01-08 Thread Michael Buch via lldb-commits


@@ -1084,3 +1084,43 @@ bool 
lldb_private::formatters::LibcxxWStringViewSummaryProvider(
   return ::LibcxxWStringSummaryProvider(valobj, stream, summary_options,
 dataobj, size);
 }
+
+bool lldb_private::formatters::LibcxxChronoMonthSummaryProvider(
+ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
+  // These are the names used in the C++20 ostream operator. Since LLVM uses
+  // C++17 it's not possible to use the ostream operator directly.

Michael137 wrote:

Should we FIXME this?

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


[Lldb-commits] [lldb] [lldb][libc++] Adds some C++20 calendar data formatters. (PR #76983)

2024-01-08 Thread Michael Buch via lldb-commits


@@ -1084,3 +1084,43 @@ bool 
lldb_private::formatters::LibcxxWStringViewSummaryProvider(
   return ::LibcxxWStringSummaryProvider(valobj, stream, summary_options,
 dataobj, size);
 }
+
+bool lldb_private::formatters::LibcxxChronoMonthSummaryProvider(
+ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
+  // These are the names used in the C++20 ostream operator. Since LLVM uses
+  // C++17 it's not possible to use the ostream operator directly.
+  static const std::array months = {
+  "January", "February", "March", "April",   "May",  "June",
+  "July","August",   "September", "October", "November", "December"};
+
+  unsigned month = 
valobj.GetChildMemberWithName("__m_")->GetValueAsUnsigned(0);
+  if (month >= 1 && month <= 12)
+stream << "month=" << months[month - 1];
+  else
+stream.Printf("month=%u", month);
+
+  return true;
+}
+
+bool lldb_private::formatters::LibcxxChronoYearMonthDaySummaryProvider(
+ValueObject &valobj, Stream &stream, const TypeSummaryOptions &options) {
+
+  stream << "date=";
+  int year = valobj.GetChildMemberWithName("__y_")
+ ->GetChildMemberWithName("__y_")
+ ->GetValueAsSigned(0);
+  if (year < 0) {
+stream << '-';
+year = -year;
+  }
+
+  unsigned month = valobj.GetChildMemberWithName("__m_")

Michael137 wrote:

```suggestion
  const unsigned month = valobj.GetChildMemberWithName("__m_")
```

nullptr check question from above also applies here

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


[Lldb-commits] [lldb] [lldb][libc++] Adds some C++20 calendar data formatters. (PR #76983)

2024-01-08 Thread Michael Buch via lldb-commits

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


[Lldb-commits] [libcxx] [flang] [lldb] [lld] [clang] [libc] [clang-tools-extra] [compiler-rt] [llvm] [msan] Unwind stack before fatal reports (PR #77168)

2024-01-08 Thread Vitaly Buka via lldb-commits

https://github.com/vitalybuka updated 
https://github.com/llvm/llvm-project/pull/77168

>From d4953b7a14dfb1d351b543e2546d710ae30173ed Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Fri, 5 Jan 2024 18:42:43 -0800
Subject: [PATCH 1/2] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20in?=
 =?UTF-8?q?itial=20version?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.4
---
 compiler-rt/lib/msan/msan.h   |  3 ++
 compiler-rt/lib/msan/msan_allocator.cpp   | 29 ---
 compiler-rt/lib/msan/msan_new_delete.cpp  | 26 ++---
 .../TestCases/max_allocation_size.cpp | 10 ++-
 4 files changed, 47 insertions(+), 21 deletions(-)

diff --git a/compiler-rt/lib/msan/msan.h b/compiler-rt/lib/msan/msan.h
index 25fa2212bdadd3..b717161577a1db 100644
--- a/compiler-rt/lib/msan/msan.h
+++ b/compiler-rt/lib/msan/msan.h
@@ -321,6 +321,9 @@ const int STACK_TRACE_TAG_VPTR = STACK_TRACE_TAG_FIELDS + 1;
 stack.Unwind(pc, bp, nullptr, common_flags()->fast_unwind_on_fatal); \
   }
 
+#define GET_FATAL_STACK_TRACE \
+  GET_FATAL_STACK_TRACE_PC_BP(StackTrace::GetCurrentPc(), GET_CURRENT_FRAME())
+
 class ScopedThreadLocalStateBackup {
  public:
   ScopedThreadLocalStateBackup() { Backup(); }
diff --git a/compiler-rt/lib/msan/msan_allocator.cpp 
b/compiler-rt/lib/msan/msan_allocator.cpp
index 72a7f980d39fb0..f71f59cedf820e 100644
--- a/compiler-rt/lib/msan/msan_allocator.cpp
+++ b/compiler-rt/lib/msan/msan_allocator.cpp
@@ -180,17 +180,19 @@ void MsanThreadLocalMallocStorage::CommitBack() {
 
 static void *MsanAllocate(StackTrace *stack, uptr size, uptr alignment,
   bool zeroise) {
-  if (size > max_malloc_size) {
+  if (UNLIKELY(size > max_malloc_size)) {
 if (AllocatorMayReturnNull()) {
   Report("WARNING: MemorySanitizer failed to allocate 0x%zx bytes\n", 
size);
   return nullptr;
 }
-ReportAllocationSizeTooBig(size, max_malloc_size, stack);
+GET_FATAL_STACK_TRACE;
+ReportAllocationSizeTooBig(size, max_malloc_size, &stack);
   }
   if (UNLIKELY(IsRssLimitExceeded())) {
 if (AllocatorMayReturnNull())
   return nullptr;
-ReportRssLimitExceeded(stack);
+GET_FATAL_STACK_TRACE;
+ReportRssLimitExceeded(&stack);
   }
   MsanThread *t = GetCurrentThread();
   void *allocated;
@@ -206,7 +208,8 @@ static void *MsanAllocate(StackTrace *stack, uptr size, 
uptr alignment,
 SetAllocatorOutOfMemory();
 if (AllocatorMayReturnNull())
   return nullptr;
-ReportOutOfMemory(size, stack);
+GET_FATAL_STACK_TRACE;
+ReportOutOfMemory(size, &stack);
   }
   Metadata *meta =
   reinterpret_cast(allocator.GetMetaData(allocated));
@@ -288,7 +291,8 @@ static void *MsanCalloc(StackTrace *stack, uptr nmemb, uptr 
size) {
   if (UNLIKELY(CheckForCallocOverflow(size, nmemb))) {
 if (AllocatorMayReturnNull())
   return nullptr;
-ReportCallocOverflow(nmemb, size, stack);
+GET_FATAL_STACK_TRACE;
+ReportCallocOverflow(nmemb, size, &stack);
   }
   return MsanAllocate(stack, nmemb * size, sizeof(u64), true);
 }
@@ -343,7 +347,8 @@ void *msan_reallocarray(void *ptr, uptr nmemb, uptr size, 
StackTrace *stack) {
 errno = errno_ENOMEM;
 if (AllocatorMayReturnNull())
   return nullptr;
-ReportReallocArrayOverflow(nmemb, size, stack);
+GET_FATAL_STACK_TRACE;
+ReportReallocArrayOverflow(nmemb, size, &stack);
   }
   return msan_realloc(ptr, nmemb * size, stack);
 }
@@ -358,7 +363,8 @@ void *msan_pvalloc(uptr size, StackTrace *stack) {
 errno = errno_ENOMEM;
 if (AllocatorMayReturnNull())
   return nullptr;
-ReportPvallocOverflow(size, stack);
+GET_FATAL_STACK_TRACE;
+ReportPvallocOverflow(size, &stack);
   }
   // pvalloc(0) should allocate one page.
   size = size ? RoundUpTo(size, PageSize) : PageSize;
@@ -370,7 +376,8 @@ void *msan_aligned_alloc(uptr alignment, uptr size, 
StackTrace *stack) {
 errno = errno_EINVAL;
 if (AllocatorMayReturnNull())
   return nullptr;
-ReportInvalidAlignedAllocAlignment(size, alignment, stack);
+GET_FATAL_STACK_TRACE;
+ReportInvalidAlignedAllocAlignment(size, alignment, &stack);
   }
   return SetErrnoOnNull(MsanAllocate(stack, size, alignment, false));
 }
@@ -380,7 +387,8 @@ void *msan_memalign(uptr alignment, uptr size, StackTrace 
*stack) {
 errno = errno_EINVAL;
 if (AllocatorMayReturnNull())
   return nullptr;
-ReportInvalidAllocationAlignment(alignment, stack);
+GET_FATAL_STACK_TRACE;
+ReportInvalidAllocationAlignment(alignment, &stack);
   }
   return SetErrnoOnNull(MsanAllocate(stack, size, alignment, false));
 }
@@ -390,7 +398,8 @@ int msan_posix_memalign(void **memptr, uptr alignment, uptr 
size,
   if (UNLIKELY(!CheckPosixMemalignAlignment(alignment))) {
 if (AllocatorMayReturnNull())
   return errno_EINVAL;
-ReportInvalidPosixMemalignAlignment(alignment, stack);
+GET_FATAL_STA

[Lldb-commits] [llvm] [clang-tools-extra] [lldb] [clang] [lldb][test] Apply @expectedFailureAll/@skipIf early for debug_info tests (PR #73067)

2024-01-08 Thread Jonas Devlieghere via lldb-commits

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


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


[Lldb-commits] [lldb] [lldb] Change interface of StructuredData::Array::GetItemAtIndexAsInteger (PR #71993)

2024-01-08 Thread Jonas Devlieghere via lldb-commits

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

LGTM

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


[Lldb-commits] [lldb] [lldb] Deprecate SBBreakpoint::AddName in favor of AddNameWithErrorHandling (PR #71228)

2024-01-08 Thread Jonas Devlieghere via lldb-commits

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


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


[Lldb-commits] [lld] [mlir] [lldb] [openmp] [clang] [flang] [compiler-rt] [libc] [libcxx] [polly] [llvm] [WebAssembly] Correctly consider signext/zext arg flags at function declaration (PR #77281)

2024-01-08 Thread Juneyoung Lee via lldb-commits

https://github.com/aqjune updated 
https://github.com/llvm/llvm-project/pull/77281

>From 1bbfe05bc50e1fbdb207f21a178b6fc7ab24e8cf Mon Sep 17 00:00:00 2001
From: Juneyoung Lee 
Date: Mon, 8 Jan 2024 02:01:41 -0600
Subject: [PATCH] [WebAssembly] Correctly consider signext/zext arg flags at
 function declaration

---
 .../WebAssembly/WebAssemblyFastISel.cpp   |   6 +-
 .../WebAssembly/signext-zeroext-callsite.ll   | 125 ++
 2 files changed, 129 insertions(+), 2 deletions(-)
 create mode 100644 llvm/test/CodeGen/WebAssembly/signext-zeroext-callsite.ll

diff --git a/llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp 
b/llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp
index 15dc44a0439573..80159974ecd691 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyFastISel.cpp
@@ -839,9 +839,11 @@ bool WebAssemblyFastISel::selectCall(const Instruction *I) 
{
 
 unsigned Reg;
 
-if (Attrs.hasParamAttr(I, Attribute::SExt))
+if (Attrs.hasParamAttr(I, Attribute::SExt) ||
+(IsDirect && Func->hasParamAttribute(I, Attribute::SExt)))
   Reg = getRegForSignedValue(V);
-else if (Attrs.hasParamAttr(I, Attribute::ZExt))
+else if (Attrs.hasParamAttr(I, Attribute::ZExt) ||
+ (IsDirect && Func->hasParamAttribute(I, Attribute::ZExt)))
   Reg = getRegForUnsignedValue(V);
 else
   Reg = getRegForValue(V);
diff --git a/llvm/test/CodeGen/WebAssembly/signext-zeroext-callsite.ll 
b/llvm/test/CodeGen/WebAssembly/signext-zeroext-callsite.ll
new file mode 100644
index 00..02ca578716dc98
--- /dev/null
+++ b/llvm/test/CodeGen/WebAssembly/signext-zeroext-callsite.ll
@@ -0,0 +1,125 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
+; RUN: llc < %s -O0 | FileCheck %s
+
+target triple = "wasm32-unknown-unknown"
+
+
+declare i32 @foo(i1 signext noundef, i32 noundef)
+
+; callsite_signext and callsite_nosignext must emit equivalent codes
+
+define i32 @callsite_nosignext() {
+; CHECK-LABEL: callsite_nosignext:
+; CHECK: .functype callsite_nosignext () -> (i32)
+; CHECK-NEXT:.local i32, i32, i32, i32, i32, i32
+; CHECK-NEXT:  # %bb.0: # %start
+; CHECK-NEXT:i32.const 1
+; CHECK-NEXT:local.set 0
+; CHECK-NEXT:i32.const 0
+; CHECK-NEXT:local.set 1
+; CHECK-NEXT:i32.const 31
+; CHECK-NEXT:local.set 2
+; CHECK-NEXT:local.get 0
+; CHECK-NEXT:local.get 2
+; CHECK-NEXT:i32.shl
+; CHECK-NEXT:local.set 3
+; CHECK-NEXT:local.get 3
+; CHECK-NEXT:local.get 2
+; CHECK-NEXT:i32.shr_s
+; CHECK-NEXT:local.set 4
+; CHECK-NEXT:local.get 4
+; CHECK-NEXT:local.get 1
+; CHECK-NEXT:call foo
+; CHECK-NEXT:local.set 5
+; CHECK-NEXT:local.get 5
+; CHECK-NEXT:return
+start:
+  %0 = call i32 @foo(i1 1, i32 0)
+  ret i32 %0
+}
+
+define i32 @callsite_signext() {
+; CHECK-LABEL: callsite_signext:
+; CHECK: .functype callsite_signext () -> (i32)
+; CHECK-NEXT:.local i32, i32, i32, i32, i32, i32
+; CHECK-NEXT:  # %bb.0: # %start
+; CHECK-NEXT:i32.const 1
+; CHECK-NEXT:local.set 0
+; CHECK-NEXT:i32.const 0
+; CHECK-NEXT:local.set 1
+; CHECK-NEXT:i32.const 31
+; CHECK-NEXT:local.set 2
+; CHECK-NEXT:local.get 0
+; CHECK-NEXT:local.get 2
+; CHECK-NEXT:i32.shl
+; CHECK-NEXT:local.set 3
+; CHECK-NEXT:local.get 3
+; CHECK-NEXT:local.get 2
+; CHECK-NEXT:i32.shr_s
+; CHECK-NEXT:local.set 4
+; CHECK-NEXT:local.get 4
+; CHECK-NEXT:local.get 1
+; CHECK-NEXT:call foo
+; CHECK-NEXT:local.set 5
+; CHECK-NEXT:local.get 5
+; CHECK-NEXT:return
+start:
+  %0 = call i32 @foo(i1 signext 1, i32 0)
+  ret i32 %0
+}
+
+declare i32 @foo2(i1 zeroext noundef, i32 noundef)
+
+; callsite_zeroext and callsite_nozeroext must emit equivalent codes
+
+define i32 @callsite_nozeroext() {
+; CHECK-LABEL: callsite_nozeroext:
+; CHECK: .functype callsite_nozeroext () -> (i32)
+; CHECK-NEXT:.local i32, i32, i32, i32, i32
+; CHECK-NEXT:  # %bb.0: # %start
+; CHECK-NEXT:i32.const 1
+; CHECK-NEXT:local.set 0
+; CHECK-NEXT:i32.const 0
+; CHECK-NEXT:local.set 1
+; CHECK-NEXT:i32.const 1
+; CHECK-NEXT:local.set 2
+; CHECK-NEXT:local.get 0
+; CHECK-NEXT:local.get 2
+; CHECK-NEXT:i32.and
+; CHECK-NEXT:local.set 3
+; CHECK-NEXT:local.get 3
+; CHECK-NEXT:local.get 1
+; CHECK-NEXT:call foo2
+; CHECK-NEXT:local.set 4
+; CHECK-NEXT:local.get 4
+; CHECK-NEXT:return
+start:
+  %0 = call i32 @foo2(i1 1, i32 0)
+  ret i32 %0
+}
+
+define i32 @callsite_zeroext() {
+; CHECK-LABEL: callsite_zeroext:
+; CHECK: .functype callsite_zeroext () -> (i32)
+; CHECK-NEXT:.local i32, i32, i32, i32, i32
+; CHECK-NEXT:  # %bb.0: # %start
+; CHECK-NEXT:i32.const 1
+; CHECK-NEXT:local.set 0
+; CHECK-NEXT:i32.const 0
+; CHECK-NEXT:local.set 1
+; CHECK-NEXT:i32.const 1
+; CHECK-NEXT:local

[Lldb-commits] [lldb] [lldb] Fix Intel PT plugin compile errors (PR #77252)

2024-01-08 Thread Nicholas Mosier via lldb-commits

nmosier wrote:

At least one test fails: `./bin/lldb -o 'trace load -v 
/llvm/lldb/test/API/commands/trace/intelpt-trace/trace_2threads.json'` crashes 
with an assertion failure on TraceIntelPTBundleLoader.cpp:127 (`*process_sp` is 
a null pointer dereference).

Do you know why `process_sp` would be null in this case? I added some extra 
assertions and it looks like `target_sp->m_process_sp` is null after the call 
to `ProcessTrace::CreateInstance` on line 111.



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


[Lldb-commits] [lldb] [lldb] Remove redundant severity substring within a diagnostic message. (PR #76111)

2024-01-08 Thread Pete Lawrence via lldb-commits

https://github.com/PortalPete updated 
https://github.com/llvm/llvm-project/pull/76111

>From d10ce06475f52ec918aab96f7b1f85ee414d2d2f Mon Sep 17 00:00:00 2001
From: Pete Lawrence 
Date: Tue, 19 Dec 2023 19:25:36 -1000
Subject: [PATCH] [lldb] Remove redundant severity substring within a
 diagnostic message.

For example, the following message has the severity string "error: " twice.
> "error: :3:1: error: cannot find 'bogus' in scope

This method already appends the severity string in the beginning, but with this 
fix, it also removes a secondary instance, if applicable.

Note that this change only removes the *first* redundant substring. I 
considered putting the removal logic in a loop, but I decided that if something 
is generating more than one redundant severity substring, then that's a problem 
the message's source should probably fix.

rdar://114203423
---
 lldb/source/Expression/DiagnosticManager.cpp  | 15 ---
 .../TestModulesCompileError.py|  2 +-
 2 files changed, 13 insertions(+), 4 deletions(-)

diff --git a/lldb/source/Expression/DiagnosticManager.cpp 
b/lldb/source/Expression/DiagnosticManager.cpp
index 08977066e3330a..9a1100df78db2b 100644
--- a/lldb/source/Expression/DiagnosticManager.cpp
+++ b/lldb/source/Expression/DiagnosticManager.cpp
@@ -46,11 +46,20 @@ static const char *StringForSeverity(DiagnosticSeverity 
severity) {
 
 std::string DiagnosticManager::GetString(char separator) {
   std::string ret;
+  llvm::raw_string_ostream stream(ret);
 
   for (const auto &diagnostic : Diagnostics()) {
-ret.append(StringForSeverity(diagnostic->GetSeverity()));
-ret.append(std::string(diagnostic->GetMessage()));
-ret.push_back(separator);
+llvm::StringRef severity = StringForSeverity(diagnostic->GetSeverity());
+stream << severity;
+
+llvm::StringRef message = diagnostic->GetMessage();
+std::string searchable_message = message.lower();
+auto severity_pos = message.find(severity);
+stream << message.take_front(severity_pos);
+
+if (severity_pos != llvm::StringRef::npos)
+  stream << message.drop_front(severity_pos + severity.size());
+stream << separator;
   }
 
   return ret;
diff --git 
a/lldb/test/API/lang/objc/modules-compile-error/TestModulesCompileError.py 
b/lldb/test/API/lang/objc/modules-compile-error/TestModulesCompileError.py
index 36e302be2525b5..620b6e44fc852a 100644
--- a/lldb/test/API/lang/objc/modules-compile-error/TestModulesCompileError.py
+++ b/lldb/test/API/lang/objc/modules-compile-error/TestModulesCompileError.py
@@ -21,7 +21,7 @@ def test(self):
 "expr @import LLDBTestModule",
 error=True,
 substrs=[
-"module.h:4:1: error: use of undeclared identifier 
'syntax_error_for_lldb_to_find'",
+"module.h:4:1: use of undeclared identifier 
'syntax_error_for_lldb_to_find'",
 "syntax_error_for_lldb_to_find // comment that tests source 
printing",
 "could not build module 'LLDBTestModule'",
 ],

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


[Lldb-commits] [lldb] [lldb] Remove redundant severity substring within a diagnostic message. (PR #76111)

2024-01-08 Thread Pete Lawrence via lldb-commits


@@ -48,8 +48,17 @@ std::string DiagnosticManager::GetString(char separator) {
   std::string ret;
 
   for (const auto &diagnostic : Diagnostics()) {
-ret.append(StringForSeverity(diagnostic->GetSeverity()));
-ret.append(std::string(diagnostic->GetMessage()));
+std::string message(diagnostic->GetMessage());
+std::string searchable_message(diagnostic->GetMessage().lower());
+std::string severity(StringForSeverity(diagnostic->GetSeverity()));
+
+// Erase the (first) redundant severity string in the message.
+size_t position = searchable_message.find(severity);
+if (position != std::string::npos)
+  message.erase(position, severity.length());
+
+ret.append(severity);
+ret.append(message);

PortalPete wrote:

 Ok, you're suggestion is up @felipepiovezan.
Thanks again! 🙂

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


[Lldb-commits] [lldb] [lldb] All ValueObjectSP instances are now valid (non-null) but have an error state (In-progress | Take 2) (PR #77375)

2024-01-08 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Pete Lawrence (PortalPete)


Changes

> **Note**
> I originally proposed this change with [PR 
74912](https://github.com/llvm/llvm-project/pull/74912) before renaming the 
branch.

### Purpose
For now, we'd like to get people's thought's on the goal, design, and scope of 
this PR by reviewing these preliminary changes.

I recommend focussing (or starting) on these files:
* `ValueObject.h`
* `ValueObject.cpp`


### Goal
Every `ValueObjectSP` will have an actual value and will never be equal to 
`nullptr`.


### Design
To force each `ValueObjectSP` to contain _something_, we're considering 
changing the type from a typedef…
```cpp
typedef std::shared_ptr ValueObjectSP;

```

to this subclass:
```cpp
class ValueObjectSP : public std::shared_ptr {
  ValueObjectSP() = delete;
  operator bool() = delete;

public:
  ValueObjectSP(std::shared_ptr 
&&pointer)
  : std::shared_ptr(std::move(pointer)) {
assert(pointer);
  }
};
```

This class removes the default constructor to force each `ValueObjectSP` to 
point to a real `ValueObject` instance. It also removes `operator bool()` 
because no instance will ever equal `nullptr`. 


### Change Patterns
The bulk of the changes into one of these two camps:
1. For methods that have a `Status &error` parameter **and** return an 
`ValueObjectSP`, the return value *becomes* the container for the error state, 
which eliminate the need for a parameter.
* This means that callers of these methods need to check the return value's 
error state.
  * `return_value->GetError.Success()`
  * `return_value->GetError.Fail()`

2. For all other methods that return a `ValueObjectSP` but don't have a `Status 
&` parameter, they now return `std::optional`.
* This changes a fair amount of code in these ways:
  * Code which had been using the `std::shared_ptr` Boolean operator now uses 
the `std::optional` Boolean operator.
  * Nearby code has to call the optional's `value()` method to get the shared 
pointer inside.
  * Methods with lines that return `ValueObjectSP()` now return `{}`, which 
creates an optional with nothing in it.

Again, I recommend focussing (or starting) on these files:
* `ValueObject.h`
* `ValueObject.cpp`


### Remaining work
This is very much a work-in-progress for a proof of concept, which means:
* It doesn't compile (yet)
* So far I've modified 53 files
* I estimate another 100-250 more files need to change based on the ninja build 
progress indicator.

The remaining changes will just be more of the same but now's a good time to 
take a look at this sample to get a sense of the magnitude and trajectory of 
the remaining changes.

---

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


53 Files Affected:

- (modified) lldb/include/lldb/Breakpoint/Watchpoint.h (+2-2) 
- (modified) lldb/include/lldb/Core/ValueObject.h (+38-28) 
- (modified) lldb/include/lldb/Core/ValueObjectConstResult.h (+4-4) 
- (modified) lldb/include/lldb/Core/ValueObjectConstResultCast.h (+3-3) 
- (modified) lldb/include/lldb/Core/ValueObjectConstResultChild.h (+3-3) 
- (modified) lldb/include/lldb/Core/ValueObjectConstResultImpl.h (+4-4) 
- (modified) lldb/include/lldb/Core/ValueObjectList.h (+10-7) 
- (modified) lldb/include/lldb/Core/ValueObjectRegister.h (+2-2) 
- (modified) lldb/include/lldb/Core/ValueObjectSyntheticFilter.h (+5-5) 
- (modified) lldb/include/lldb/Core/ValueObjectUpdater.h (+3-3) 
- (modified) lldb/include/lldb/DataFormatters/TypeSynthetic.h (+12-10) 
- (modified) lldb/include/lldb/DataFormatters/ValueObjectPrinter.h (+2-1) 
- (modified) lldb/include/lldb/DataFormatters/VectorIterator.h (+1-1) 
- (modified) lldb/include/lldb/Expression/ExpressionVariable.h (+37-16) 
- (modified) lldb/include/lldb/Expression/UserExpression.h (+1-1) 
- (modified) lldb/include/lldb/Interpreter/ScriptInterpreter.h (+4-4) 
- (modified) lldb/include/lldb/Target/LanguageRuntime.h (+3-3) 
- (modified) lldb/include/lldb/Target/StackFrame.h (+6-6) 
- (modified) lldb/include/lldb/Target/StackFrameRecognizer.h (+1-3) 
- (modified) lldb/include/lldb/Target/Target.h (+1-1) 
- (modified) lldb/include/lldb/Target/Thread.h (+2-2) 
- (modified) lldb/include/lldb/Target/ThreadPlan.h (+2-2) 
- (modified) lldb/include/lldb/Target/ThreadPlanCallFunction.h (+1-1) 
- (modified) lldb/include/lldb/lldb-forward.h (+12-1) 
- (modified) lldb/source/Breakpoint/BreakpointLocation.cpp (+2-4) 
- (modified) lldb/source/Breakpoint/Watchpoint.cpp (+13-9) 
- (modified) lldb/source/Commands/CommandObjectDWIMPrint.cpp (+12-11) 
- (modified) lldb/source/Commands/CommandObjectExpression.cpp (+14-11) 
- (modified) lldb/source/Commands/CommandObjectFrame.cpp (+19-17) 
- (modified) lldb/source/Commands/CommandObjectMemory.cpp (+9-16) 
- (modified) lldb/source/Commands/CommandObjectTarget.cp

[Lldb-commits] [lldb] [lldb] All ValueObjectSP instances are now valid (non-null) but have an error state (In-progress | Take 2) (PR #77375)

2024-01-08 Thread via lldb-commits

github-actions[bot] wrote:




:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:



You can test this locally with the following command:


``bash
git-clang-format --diff 07d6fbf8d80083470b4371f2ddabd656a9c317e6 
c416cad26ed3e84918f639cc5a408682afff451f -- 
lldb/include/lldb/Breakpoint/Watchpoint.h lldb/include/lldb/Core/ValueObject.h 
lldb/include/lldb/Core/ValueObjectConstResult.h 
lldb/include/lldb/Core/ValueObjectConstResultCast.h 
lldb/include/lldb/Core/ValueObjectConstResultChild.h 
lldb/include/lldb/Core/ValueObjectConstResultImpl.h 
lldb/include/lldb/Core/ValueObjectList.h 
lldb/include/lldb/Core/ValueObjectRegister.h 
lldb/include/lldb/Core/ValueObjectSyntheticFilter.h 
lldb/include/lldb/Core/ValueObjectUpdater.h 
lldb/include/lldb/DataFormatters/TypeSynthetic.h 
lldb/include/lldb/DataFormatters/ValueObjectPrinter.h 
lldb/include/lldb/DataFormatters/VectorIterator.h 
lldb/include/lldb/Expression/ExpressionVariable.h 
lldb/include/lldb/Expression/UserExpression.h 
lldb/include/lldb/Interpreter/ScriptInterpreter.h 
lldb/include/lldb/Target/LanguageRuntime.h 
lldb/include/lldb/Target/StackFrame.h 
lldb/include/lldb/Target/StackFrameRecognizer.h 
lldb/include/lldb/Target/Target.h lldb/include/lldb/Target/Thread.h 
lldb/include/lldb/Target/ThreadPlan.h 
lldb/include/lldb/Target/ThreadPlanCallFunction.h 
lldb/include/lldb/lldb-forward.h lldb/source/Breakpoint/BreakpointLocation.cpp 
lldb/source/Breakpoint/Watchpoint.cpp 
lldb/source/Commands/CommandObjectDWIMPrint.cpp 
lldb/source/Commands/CommandObjectExpression.cpp 
lldb/source/Commands/CommandObjectFrame.cpp 
lldb/source/Commands/CommandObjectMemory.cpp 
lldb/source/Commands/CommandObjectTarget.cpp 
lldb/source/Commands/CommandObjectThread.cpp 
lldb/source/Commands/CommandObjectType.cpp 
lldb/source/Commands/CommandObjectWatchpoint.cpp 
lldb/source/Core/FormatEntity.cpp lldb/source/Core/IOHandlerCursesGUI.cpp 
lldb/source/Core/ValueObject.cpp lldb/source/Core/ValueObjectConstResult.cpp 
lldb/source/Core/ValueObjectConstResultCast.cpp 
lldb/source/Core/ValueObjectConstResultChild.cpp 
lldb/source/Core/ValueObjectConstResultImpl.cpp 
lldb/source/Core/ValueObjectList.cpp lldb/source/Core/ValueObjectRegister.cpp 
lldb/source/Core/ValueObjectSyntheticFilter.cpp 
lldb/source/Core/ValueObjectUpdater.cpp 
lldb/source/DataFormatters/FormatManager.cpp 
lldb/source/DataFormatters/TypeSynthetic.cpp 
lldb/source/DataFormatters/ValueObjectPrinter.cpp 
lldb/source/DataFormatters/VectorType.cpp 
lldb/source/Expression/ExpressionVariable.cpp lldb/source/Target/StackFrame.cpp 
lldb/source/Target/Target.cpp lldb/source/Target/Thread.cpp
``





View the diff from clang-format here.


``diff
diff --git a/lldb/include/lldb/Core/ValueObject.h 
b/lldb/include/lldb/Core/ValueObject.h
index 0f1b8c98ae..cd80f8e428 100644
--- a/lldb/include/lldb/Core/ValueObject.h
+++ b/lldb/include/lldb/Core/ValueObject.h
@@ -468,7 +468,6 @@ public:
   virtual std::optional
   GetChildAtIndex(size_t idx, bool can_create = true);
 
-
   virtual lldb::ValueObjectSP GetChildMemberWithName(llvm::StringRef name,
  bool can_create = true);
   /// The method always creates missing children in the path, if necessary.

``




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


[Lldb-commits] [lldb] [lldb] Fix Intel PT plugin compile errors (PR #77252)

2024-01-08 Thread Walter Erquinigo via lldb-commits

walter-erquinigo wrote:

> At least one test fails: `./bin/lldb -o 'trace load -v 
> /llvm/lldb/test/API/commands/trace/intelpt-trace/trace_2threads.json'` 
> crashes with an assertion failure on TraceIntelPTBundleLoader.cpp:127 
> (`*process_sp` is a null pointer dereference).
> 
> Do you know why `process_sp` would be null in this case? I added some extra 
> assertions and it looks like `target_sp->m_process_sp` is null after the call 
> to `ProcessTrace::CreateInstance` on line 111.

It seems that the issue is that we still need to make `Target::m_process_sp` 
point to the newly created process...

So, let's give something else a try:

Return that code to its original form

```
ProcessSP process_sp = target_sp->CreateProcess(
/*listener*/ nullptr, "trace",
/*crash_file*/ nullptr,
/*can_connect*/ false);
```

If that passes the test, then there's nothing else to do and we are good to go.
If that doesn't work, then we need to additional add the line 
`LLDB_PLUGIN_DEFINE(ProcessTrace)` before any function declaration in the 
ProcessTrace.cpp file. That `LLDB_PLUGIN_DEFINE` define will register the 
ProcessTrace process plugin with that "trace", which will be searchable by 
`target_sp->CreateProcess`, who is looking for a trace process called "trace".

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


[Lldb-commits] [lldb] 09e32ab - [lldb] Deprecate SBBreakpoint::AddName in favor of AddNameWithErrorHandling (#71228)

2024-01-08 Thread via lldb-commits

Author: Alex Langford
Date: 2024-01-08T13:30:24-08:00
New Revision: 09e32ab75076a1f2270d37343922c86c12bdd047

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

LOG: [lldb] Deprecate SBBreakpoint::AddName in favor of 
AddNameWithErrorHandling (#71228)

AddName gives no feedback other than if it succeeded whereas
AddNameWithErrorHandling gives you back an SBError object. I would like
to mark AddName as deprecated and direct folks to use
AddNameWithErorrHandling instead.

-

Co-authored-by: Med Ismail Bennani 

Added: 


Modified: 
lldb/include/lldb/API/SBBreakpoint.h

Removed: 




diff  --git a/lldb/include/lldb/API/SBBreakpoint.h 
b/lldb/include/lldb/API/SBBreakpoint.h
index 0bb7c31d74f21f..e08df3b6d5ab07 100644
--- a/lldb/include/lldb/API/SBBreakpoint.h
+++ b/lldb/include/lldb/API/SBBreakpoint.h
@@ -112,6 +112,8 @@ class LLDB_API SBBreakpoint {
 
   SBError SetScriptCallbackBody(const char *script_body_text);
 
+  LLDB_DEPRECATED_FIXME("Doesn't provide error handling",
+"AddNameWithErrorHandling")
   bool AddName(const char *new_name);
 
   SBError AddNameWithErrorHandling(const char *new_name);



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


[Lldb-commits] [lldb] [lldb] Deprecate SBBreakpoint::AddName in favor of AddNameWithErrorHandling (PR #71228)

2024-01-08 Thread Alex Langford via lldb-commits

https://github.com/bulbazord closed 
https://github.com/llvm/llvm-project/pull/71228
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] 16b8a0d - [lldb] Change interface of StructuredData::Array::GetItemAtIndexAsInteger (#71993)

2024-01-08 Thread via lldb-commits

Author: Alex Langford
Date: 2024-01-08T13:31:03-08:00
New Revision: 16b8a0dc6885dea0882887a6e642a504fd1e193c

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

LOG: [lldb] Change interface of StructuredData::Array::GetItemAtIndexAsInteger 
(#71993)

This is a follow-up to (#71613) and (#71961).

Added: 


Modified: 
lldb/include/lldb/Utility/StructuredData.h
lldb/source/Breakpoint/BreakpointResolverName.cpp

lldb/source/Plugins/InstrumentationRuntime/TSan/InstrumentationRuntimeTSan.cpp
lldb/source/Target/DynamicRegisterInfo.cpp

Removed: 




diff  --git a/lldb/include/lldb/Utility/StructuredData.h 
b/lldb/include/lldb/Utility/StructuredData.h
index e7ee12868512f4..5e63ef92fac3ec 100644
--- a/lldb/include/lldb/Utility/StructuredData.h
+++ b/lldb/include/lldb/Utility/StructuredData.h
@@ -221,31 +221,17 @@ class StructuredData {
 }
 
 template 
-bool GetItemAtIndexAsInteger(size_t idx, IntType &result) const {
-  ObjectSP value_sp = GetItemAtIndex(idx);
-  if (value_sp.get()) {
+std::optional GetItemAtIndexAsInteger(size_t idx) const {
+  if (auto item_sp = GetItemAtIndex(idx)) {
 if constexpr (std::numeric_limits::is_signed) {
-  if (auto signed_value = value_sp->GetAsSignedInteger()) {
-result = static_cast(signed_value->GetValue());
-return true;
-  }
+  if (auto *signed_value = item_sp->GetAsSignedInteger())
+return static_cast(signed_value->GetValue());
 } else {
-  if (auto unsigned_value = value_sp->GetAsUnsignedInteger()) {
-result = static_cast(unsigned_value->GetValue());
-return true;
-  }
+  if (auto *unsigned_value = item_sp->GetAsUnsignedInteger())
+return static_cast(unsigned_value->GetValue());
 }
   }
-  return false;
-}
-
-template 
-bool GetItemAtIndexAsInteger(size_t idx, IntType &result,
- IntType default_val) const {
-  bool success = GetItemAtIndexAsInteger(idx, result);
-  if (!success)
-result = default_val;
-  return success;
+  return {};
 }
 
 std::optional GetItemAtIndexAsString(size_t idx) const {

diff  --git a/lldb/source/Breakpoint/BreakpointResolverName.cpp 
b/lldb/source/Breakpoint/BreakpointResolverName.cpp
index 82eef43ad6cfd2..aa86d2a26d1100 100644
--- a/lldb/source/Breakpoint/BreakpointResolverName.cpp
+++ b/lldb/source/Breakpoint/BreakpointResolverName.cpp
@@ -161,14 +161,14 @@ BreakpointResolverSP 
BreakpointResolverName::CreateFromStructuredData(
 error.SetErrorString("BRN::CFSD: name entry is not a string.");
 return nullptr;
   }
-  std::underlying_type::type fnt;
-  success = names_mask_array->GetItemAtIndexAsInteger(i, fnt);
-  if (!success) {
+  auto maybe_fnt = names_mask_array->GetItemAtIndexAsInteger<
+  std::underlying_type::type>(i);
+  if (!maybe_fnt) {
 error.SetErrorString("BRN::CFSD: name mask entry is not an integer.");
 return nullptr;
   }
   names.push_back(std::string(*maybe_name));
-  name_masks.push_back(static_cast(fnt));
+  name_masks.push_back(static_cast(*maybe_fnt));
 }
 
 std::shared_ptr resolver_sp =

diff  --git 
a/lldb/source/Plugins/InstrumentationRuntime/TSan/InstrumentationRuntimeTSan.cpp
 
b/lldb/source/Plugins/InstrumentationRuntime/TSan/InstrumentationRuntimeTSan.cpp
index 2a35256a6fb0bf..72293c5331f40d 100644
--- 
a/lldb/source/Plugins/InstrumentationRuntime/TSan/InstrumentationRuntimeTSan.cpp
+++ 
b/lldb/source/Plugins/InstrumentationRuntime/TSan/InstrumentationRuntimeTSan.cpp
@@ -592,9 +592,10 @@ addr_t 
InstrumentationRuntimeTSan::GetFirstNonInternalFramePc(
 if (skip_one_frame && i == 0)
   continue;
 
-addr_t addr;
-if (!trace_array->GetItemAtIndexAsInteger(i, addr))
+auto maybe_addr = trace_array->GetItemAtIndexAsInteger(i);
+if (!maybe_addr)
   continue;
+addr_t addr = *maybe_addr;
 
 lldb_private::Address so_addr;
 if (!process_sp->GetTarget().GetSectionLoadList().ResolveLoadAddress(

diff  --git a/lldb/source/Target/DynamicRegisterInfo.cpp 
b/lldb/source/Target/DynamicRegisterInfo.cpp
index 7469c1d4259afc..1a817449fa9589 100644
--- a/lldb/source/Target/DynamicRegisterInfo.cpp
+++ b/lldb/source/Target/DynamicRegisterInfo.cpp
@@ -349,10 +349,8 @@ DynamicRegisterInfo::SetRegisterInfo(const 
StructuredData::Dictionary &dict,
   const size_t num_regs = invalidate_reg_list->GetSize();
   if (num_regs > 0) {
 for (uint32_t idx = 0; idx < num_regs; ++idx) {
-  uint64_t invalidate_reg_num;
-  std::optional maybe_invalidate_reg_name =
-  invalidate_reg_list->GetItemAtIndex

[Lldb-commits] [lldb] [lldb] Change interface of StructuredData::Array::GetItemAtIndexAsInteger (PR #71993)

2024-01-08 Thread Alex Langford via lldb-commits

https://github.com/bulbazord closed 
https://github.com/llvm/llvm-project/pull/71993
___
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits


[Lldb-commits] [lldb] [lldb] Fix Intel PT plugin compile errors (PR #77252)

2024-01-08 Thread Nicholas Mosier via lldb-commits

nmosier wrote:

Thanks for the suggestions. Unfortunately, it's still crashing, now on the line
```c
process_sp->SetID(static_cast(pid));
```
because the prior call to `CreateProcess` on line 107 returned null.

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


[Lldb-commits] [lldb] [lldb] Add color support to StreamString (PR #77380)

2024-01-08 Thread Pete Lawrence via lldb-commits

https://github.com/PortalPete created 
https://github.com/llvm/llvm-project/pull/77380

This change just adds a `bool colors` parameter to the `StreamString` class's 
constructor, which it passes up to its superclass’s constructor.

rdar://120671168

>From 6ee5afb1a5f0f5e2070bfb0fb70f4a51bcd6ef9f Mon Sep 17 00:00:00 2001
From: Pete Lawrence 
Date: Fri, 5 Jan 2024 20:02:46 -1000
Subject: [PATCH] [lldb] Add color support to StreamString
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

This change just adds a `bool colors` parameter to the `StreamString` class's 
constructor, which it passes up to its superclass’s constructor.

rdar://120671168
---
 lldb/include/lldb/Utility/StreamString.h | 2 +-
 lldb/source/Utility/StreamString.cpp | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/lldb/include/lldb/Utility/StreamString.h 
b/lldb/include/lldb/Utility/StreamString.h
index 4c568acdcc6f60..3d675caf8f3f43 100644
--- a/lldb/include/lldb/Utility/StreamString.h
+++ b/lldb/include/lldb/Utility/StreamString.h
@@ -22,7 +22,7 @@ namespace lldb_private {
 
 class StreamString : public Stream {
 public:
-  StreamString();
+  StreamString(bool colors = false);
 
   StreamString(uint32_t flags, uint32_t addr_size, lldb::ByteOrder byte_order);
 
diff --git a/lldb/source/Utility/StreamString.cpp 
b/lldb/source/Utility/StreamString.cpp
index 745a85b7576520..0d35ccbdbbd0f5 100644
--- a/lldb/source/Utility/StreamString.cpp
+++ b/lldb/source/Utility/StreamString.cpp
@@ -11,7 +11,7 @@
 using namespace lldb;
 using namespace lldb_private;
 
-StreamString::StreamString() : Stream(0, 4, eByteOrderBig) {}
+StreamString::StreamString(bool colors) : Stream(0, 4, eByteOrderBig, colors) 
{}
 
 StreamString::StreamString(uint32_t flags, uint32_t addr_size,
ByteOrder byte_order)

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


[Lldb-commits] [lldb] [lldb] Add color support to StreamString (PR #77380)

2024-01-08 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Pete Lawrence (PortalPete)


Changes

This change just adds a `bool colors` parameter to the `StreamString` class's 
constructor, which it passes up to its superclass’s constructor.

rdar://120671168

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


2 Files Affected:

- (modified) lldb/include/lldb/Utility/StreamString.h (+1-1) 
- (modified) lldb/source/Utility/StreamString.cpp (+1-1) 


``diff
diff --git a/lldb/include/lldb/Utility/StreamString.h 
b/lldb/include/lldb/Utility/StreamString.h
index 4c568acdcc6f60..3d675caf8f3f43 100644
--- a/lldb/include/lldb/Utility/StreamString.h
+++ b/lldb/include/lldb/Utility/StreamString.h
@@ -22,7 +22,7 @@ namespace lldb_private {
 
 class StreamString : public Stream {
 public:
-  StreamString();
+  StreamString(bool colors = false);
 
   StreamString(uint32_t flags, uint32_t addr_size, lldb::ByteOrder byte_order);
 
diff --git a/lldb/source/Utility/StreamString.cpp 
b/lldb/source/Utility/StreamString.cpp
index 745a85b7576520..0d35ccbdbbd0f5 100644
--- a/lldb/source/Utility/StreamString.cpp
+++ b/lldb/source/Utility/StreamString.cpp
@@ -11,7 +11,7 @@
 using namespace lldb;
 using namespace lldb_private;
 
-StreamString::StreamString() : Stream(0, 4, eByteOrderBig) {}
+StreamString::StreamString(bool colors) : Stream(0, 4, eByteOrderBig, colors) 
{}
 
 StreamString::StreamString(uint32_t flags, uint32_t addr_size,
ByteOrder byte_order)

``




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


[Lldb-commits] [lldb] [lldb] Fix Intel PT plugin compile errors (PR #77252)

2024-01-08 Thread Walter Erquinigo via lldb-commits

walter-erquinigo wrote:

> because the prior call to `CreateProcess` on line 107 returned null.

If that call returned null, that means that CreateProcess wasn't able to find 
the "trace" process plugin. Another thing to add, which should definitely work, 
is to invoke

```
ProcessTrace::Initialize();
```
right before `CreateProcess`. That should definitely work

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


[Lldb-commits] [lldb] [libcxxabi] [libunwind] [flang] [lld] [clang] [compiler-rt] [libc] [libcxx] [mlir] [polly] [llvm] [clang-tools-extra] Make clang report invalid target versions. (PR #75373)

2024-01-08 Thread via lldb-commits

https://github.com/ZijunZhaoCCK updated 
https://github.com/llvm/llvm-project/pull/75373

>From 74f256d8a77ee2ba8e0d5bbb6519aa2729cf94d5 Mon Sep 17 00:00:00 2001
From: zijunzhao 
Date: Wed, 13 Dec 2023 20:07:45 +
Subject: [PATCH 01/13] Make clang report garbage target versions.

Clang always silently ignores garbage target versions and this makes
debug harder. So clang will report when target versions are invalid.
---
 llvm/lib/TargetParser/Triple.cpp | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/TargetParser/Triple.cpp b/llvm/lib/TargetParser/Triple.cpp
index c5e9ad43d22588..335253194d1cf8 100644
--- a/llvm/lib/TargetParser/Triple.cpp
+++ b/llvm/lib/TargetParser/Triple.cpp
@@ -11,6 +11,7 @@
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/raw_ostream.h"
 #include "llvm/Support/SwapByteOrder.h"
 #include "llvm/Support/VersionTuple.h"
 #include "llvm/TargetParser/ARMTargetParser.h"
@@ -1199,7 +1200,11 @@ StringRef Triple::getOSAndEnvironmentName() const {
 
 static VersionTuple parseVersionFromName(StringRef Name) {
   VersionTuple Version;
-  Version.tryParse(Name);
+  if (Version.tryParse(Name)) {
+errs() << "The input is "<< Name << " and it is invalid. Should pass an "<<
+"integer or integer combination! e.g. 2, 9.5 or 3.4.5\n";
+exit(1);
+  }
   return Version.withoutBuild();
 }
 

>From 0d159b2a9b76e233e020ac0aef15b49b03f4d86c Mon Sep 17 00:00:00 2001
From: zijunzhao 
Date: Wed, 13 Dec 2023 20:23:54 +
Subject: [PATCH 02/13] rephrase

---
 llvm/lib/TargetParser/Triple.cpp | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/llvm/lib/TargetParser/Triple.cpp b/llvm/lib/TargetParser/Triple.cpp
index 335253194d1cf8..713ca447403d50 100644
--- a/llvm/lib/TargetParser/Triple.cpp
+++ b/llvm/lib/TargetParser/Triple.cpp
@@ -1201,8 +1201,7 @@ StringRef Triple::getOSAndEnvironmentName() const {
 static VersionTuple parseVersionFromName(StringRef Name) {
   VersionTuple Version;
   if (Version.tryParse(Name)) {
-errs() << "The input is "<< Name << " and it is invalid. Should pass an "<<
-"integer or integer combination! e.g. 2, 9.5 or 3.4.5\n";
+errs() << "version "<< Name << " is invalid\n";
 exit(1);
   }
   return Version.withoutBuild();

>From b2dda9ce95804783c59aa1ca4e81a7941aae805d Mon Sep 17 00:00:00 2001
From: zijunzhao 
Date: Wed, 13 Dec 2023 20:07:45 +
Subject: [PATCH 03/13] Make clang report garbage target versions.

Clang always silently ignores garbage target versions and this makes
debug harder. So clang will report when target versions are invalid.
---
 clang/lib/Basic/Targets/OSTargets.h | 5 +
 llvm/include/llvm/TargetParser/Triple.h | 4 
 llvm/lib/TargetParser/Triple.cpp| 8 
 3 files changed, 17 insertions(+)

diff --git a/clang/lib/Basic/Targets/OSTargets.h 
b/clang/lib/Basic/Targets/OSTargets.h
index 342af4bbc42b7b..bc28066019971c 100644
--- a/clang/lib/Basic/Targets/OSTargets.h
+++ b/clang/lib/Basic/Targets/OSTargets.h
@@ -323,6 +323,11 @@ class LLVM_LIBRARY_VISIBILITY LinuxTargetInfo : public 
OSTargetInfo {
 // This historical but ambiguous name for the minSdkVersion macro. Keep
 // defined for compatibility.
 Builder.defineMacro("__ANDROID_API__", "__ANDROID_MIN_SDK_VERSION__");
+  } else {
+llvm::errs() << "version "<< Triple.getVersionName() <<
+" in triple " << Triple.getArchName() << "-" << Triple.getVendorName()
+<< "-" << Triple.getOSAndEnvironmentName() << " is invalid\n";
+exit(1);
   }
 } else {
 Builder.defineMacro("__gnu_linux__");
diff --git a/llvm/include/llvm/TargetParser/Triple.h 
b/llvm/include/llvm/TargetParser/Triple.h
index 47904621c0967f..05df1c489ad06e 100644
--- a/llvm/include/llvm/TargetParser/Triple.h
+++ b/llvm/include/llvm/TargetParser/Triple.h
@@ -434,6 +434,10 @@ class Triple {
   /// string (separated by a '-' if the environment component is present).
   StringRef getOSAndEnvironmentName() const;
 
+  /// Get the version component of the environment component as a single
+  /// string (the version after the environment).
+  StringRef getVersionName() const;
+
   /// @}
   /// @name Convenience Predicates
   /// @{
diff --git a/llvm/lib/TargetParser/Triple.cpp b/llvm/lib/TargetParser/Triple.cpp
index 49bc24ffbfae6c..db4ba7100781bc 100644
--- a/llvm/lib/TargetParser/Triple.cpp
+++ b/llvm/lib/TargetParser/Triple.cpp
@@ -1199,6 +1199,14 @@ StringRef Triple::getOSAndEnvironmentName() const {
   return Tmp.split('-').second;  // Strip second component
 }
 
+StringRef Triple::getVersionName() const {
+  StringRef VersionName = getEnvironmentName();
+  StringRef EnvironmentTypeName = getEnvironmentTypeName(getEnvironment());
+  if (VersionName.startswith(EnvironmentTypeName))
+return VersionName.substr(EnvironmentTypeName.size());
+  return VersionName;
+}
+
 static 

[Lldb-commits] [llvm] [compiler-rt] [mlir] [libcxx] [clang] [lldb] [libunwind] [clang-tools-extra] [polly] [libc] [flang] [lld] [libcxxabi] Make clang report invalid target versions. (PR #75373)

2024-01-08 Thread via lldb-commits

https://github.com/ZijunZhaoCCK updated 
https://github.com/llvm/llvm-project/pull/75373

>From 74f256d8a77ee2ba8e0d5bbb6519aa2729cf94d5 Mon Sep 17 00:00:00 2001
From: zijunzhao 
Date: Wed, 13 Dec 2023 20:07:45 +
Subject: [PATCH 01/14] Make clang report garbage target versions.

Clang always silently ignores garbage target versions and this makes
debug harder. So clang will report when target versions are invalid.
---
 llvm/lib/TargetParser/Triple.cpp | 7 ++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/TargetParser/Triple.cpp b/llvm/lib/TargetParser/Triple.cpp
index c5e9ad43d22588..335253194d1cf8 100644
--- a/llvm/lib/TargetParser/Triple.cpp
+++ b/llvm/lib/TargetParser/Triple.cpp
@@ -11,6 +11,7 @@
 #include "llvm/ADT/StringExtras.h"
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/raw_ostream.h"
 #include "llvm/Support/SwapByteOrder.h"
 #include "llvm/Support/VersionTuple.h"
 #include "llvm/TargetParser/ARMTargetParser.h"
@@ -1199,7 +1200,11 @@ StringRef Triple::getOSAndEnvironmentName() const {
 
 static VersionTuple parseVersionFromName(StringRef Name) {
   VersionTuple Version;
-  Version.tryParse(Name);
+  if (Version.tryParse(Name)) {
+errs() << "The input is "<< Name << " and it is invalid. Should pass an "<<
+"integer or integer combination! e.g. 2, 9.5 or 3.4.5\n";
+exit(1);
+  }
   return Version.withoutBuild();
 }
 

>From 0d159b2a9b76e233e020ac0aef15b49b03f4d86c Mon Sep 17 00:00:00 2001
From: zijunzhao 
Date: Wed, 13 Dec 2023 20:23:54 +
Subject: [PATCH 02/14] rephrase

---
 llvm/lib/TargetParser/Triple.cpp | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/llvm/lib/TargetParser/Triple.cpp b/llvm/lib/TargetParser/Triple.cpp
index 335253194d1cf8..713ca447403d50 100644
--- a/llvm/lib/TargetParser/Triple.cpp
+++ b/llvm/lib/TargetParser/Triple.cpp
@@ -1201,8 +1201,7 @@ StringRef Triple::getOSAndEnvironmentName() const {
 static VersionTuple parseVersionFromName(StringRef Name) {
   VersionTuple Version;
   if (Version.tryParse(Name)) {
-errs() << "The input is "<< Name << " and it is invalid. Should pass an "<<
-"integer or integer combination! e.g. 2, 9.5 or 3.4.5\n";
+errs() << "version "<< Name << " is invalid\n";
 exit(1);
   }
   return Version.withoutBuild();

>From b2dda9ce95804783c59aa1ca4e81a7941aae805d Mon Sep 17 00:00:00 2001
From: zijunzhao 
Date: Wed, 13 Dec 2023 20:07:45 +
Subject: [PATCH 03/14] Make clang report garbage target versions.

Clang always silently ignores garbage target versions and this makes
debug harder. So clang will report when target versions are invalid.
---
 clang/lib/Basic/Targets/OSTargets.h | 5 +
 llvm/include/llvm/TargetParser/Triple.h | 4 
 llvm/lib/TargetParser/Triple.cpp| 8 
 3 files changed, 17 insertions(+)

diff --git a/clang/lib/Basic/Targets/OSTargets.h 
b/clang/lib/Basic/Targets/OSTargets.h
index 342af4bbc42b7b..bc28066019971c 100644
--- a/clang/lib/Basic/Targets/OSTargets.h
+++ b/clang/lib/Basic/Targets/OSTargets.h
@@ -323,6 +323,11 @@ class LLVM_LIBRARY_VISIBILITY LinuxTargetInfo : public 
OSTargetInfo {
 // This historical but ambiguous name for the minSdkVersion macro. Keep
 // defined for compatibility.
 Builder.defineMacro("__ANDROID_API__", "__ANDROID_MIN_SDK_VERSION__");
+  } else {
+llvm::errs() << "version "<< Triple.getVersionName() <<
+" in triple " << Triple.getArchName() << "-" << Triple.getVendorName()
+<< "-" << Triple.getOSAndEnvironmentName() << " is invalid\n";
+exit(1);
   }
 } else {
 Builder.defineMacro("__gnu_linux__");
diff --git a/llvm/include/llvm/TargetParser/Triple.h 
b/llvm/include/llvm/TargetParser/Triple.h
index 47904621c0967f..05df1c489ad06e 100644
--- a/llvm/include/llvm/TargetParser/Triple.h
+++ b/llvm/include/llvm/TargetParser/Triple.h
@@ -434,6 +434,10 @@ class Triple {
   /// string (separated by a '-' if the environment component is present).
   StringRef getOSAndEnvironmentName() const;
 
+  /// Get the version component of the environment component as a single
+  /// string (the version after the environment).
+  StringRef getVersionName() const;
+
   /// @}
   /// @name Convenience Predicates
   /// @{
diff --git a/llvm/lib/TargetParser/Triple.cpp b/llvm/lib/TargetParser/Triple.cpp
index 49bc24ffbfae6c..db4ba7100781bc 100644
--- a/llvm/lib/TargetParser/Triple.cpp
+++ b/llvm/lib/TargetParser/Triple.cpp
@@ -1199,6 +1199,14 @@ StringRef Triple::getOSAndEnvironmentName() const {
   return Tmp.split('-').second;  // Strip second component
 }
 
+StringRef Triple::getVersionName() const {
+  StringRef VersionName = getEnvironmentName();
+  StringRef EnvironmentTypeName = getEnvironmentTypeName(getEnvironment());
+  if (VersionName.startswith(EnvironmentTypeName))
+return VersionName.substr(EnvironmentTypeName.size());
+  return VersionName;
+}
+
 static 

  1   2   >