[Lldb-commits] [mlir] [compiler-rt] [libc] [clang] [flang] [llvm] [openmp] [lldb] [hwasan] Respect strip_path_prefix printing locals (PR #76132)

2023-12-21 Thread antoine moynault via lldb-commits

antmox wrote:

Hello, this patch broke several aarch64 bots:
https://lab.llvm.org/buildbot/#/builders/198/builds/7522
https://lab.llvm.org/buildbot/#/builders/176/builds/7521
https://lab.llvm.org/buildbot/#/builders/197/builds/11545
https://lab.llvm.org/buildbot/#/builders/184/builds/8762
https://lab.llvm.org/buildbot/#/builders/185/builds/5675
Could you please look at this ?



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


[Lldb-commits] [libc] [clang] [openmp] [flang] [libcxx] [llvm] [compiler-rt] [lldb] [mlir] [hwasan] Classify stack overflow, and use after scope (PR #76133)

2023-12-21 Thread Vitaly Buka via lldb-commits

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


[Lldb-commits] [libc] [clang] [openmp] [flang] [libcxx] [llvm] [compiler-rt] [lldb] [mlir] [hwasan] Classify stack overflow, and use after scope (PR #76133)

2023-12-21 Thread Florian Mayer via lldb-commits

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


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


[Lldb-commits] [mlir] [openmp] [libcxx] [compiler-rt] [llvm] [lldb] [libc] [clang] [flang] [hwasan] Classify stack overflow, and use after scope (PR #76133)

2023-12-21 Thread Vitaly Buka via lldb-commits

vitalybuka wrote:

> Remove this comment?
> 
> Line 780
> 
> ```
> // TODO(fmayer): figure out how to distinguish use-after-return and
> // stack-buffer-overflow.
> ```

done

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


[Lldb-commits] [mlir] [openmp] [libcxx] [compiler-rt] [llvm] [lldb] [libc] [clang] [flang] [hwasan] Classify stack overflow, and use after scope (PR #76133)

2023-12-21 Thread Vitaly Buka via lldb-commits

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

>From 89636904337efe75ef6e0743e4f098f0d5b5ab56 Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Wed, 20 Dec 2023 23:58:05 -0800
Subject: [PATCH 1/4] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20ch?=
 =?UTF-8?q?anges=20to=20main=20this=20commit=20is=20based=20on?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.4

[skip ci]
---
 compiler-rt/lib/hwasan/hwasan_report.cpp  | 26 ++-
 .../test/hwasan/TestCases/Linux/syscalls.cpp  |  2 +-
 .../hwasan/TestCases/heap-buffer-overflow.c   |  7 ++---
 3 files changed, 24 insertions(+), 11 deletions(-)

diff --git a/compiler-rt/lib/hwasan/hwasan_report.cpp 
b/compiler-rt/lib/hwasan/hwasan_report.cpp
index 5e8aa315801bcd..dc34cded48e12c 100644
--- a/compiler-rt/lib/hwasan/hwasan_report.cpp
+++ b/compiler-rt/lib/hwasan/hwasan_report.cpp
@@ -205,6 +205,7 @@ static void PrintStackAllocations(const 
StackAllocationsRingBuffer *sa,
   tag_t addr_tag, uptr untagged_addr) {
   uptr frames = Min((uptr)flags()->stack_history_size, sa->size());
   bool found_local = false;
+  InternalScopedString location;
   for (uptr i = 0; i < frames; i++) {
 const uptr *record_addr = &(*sa)[i];
 uptr record = *record_addr;
@@ -233,11 +234,16 @@ static void PrintStackAllocations(const 
StackAllocationsRingBuffer *sa,
 if (obj_offset >= local.size)
   continue;
 if (!found_local) {
-  Printf("Potentially referenced stack objects:\n");
+  Printf("\nPotentially referenced stack objects:\n");
   found_local = true;
 }
-Printf("  %s in %s %s:%d\n", local.name, local.function_name,
-   local.decl_file, local.decl_line);
+StackTracePrinter::GetOrInit()->RenderSourceLocation(
+, local.decl_file, local.decl_line, 0,
+common_flags()->symbolize_vs_style,
+common_flags()->strip_path_prefix);
+Printf("  %s in %s %s\n", local.name, local.function_name,
+   location.data());
+location.clear();
   }
   frame.Clear();
 }
@@ -363,7 +369,7 @@ static void PrintTagsAroundAddr(uptr addr, GetTag get_tag,
   InternalScopedString s;
   addr = MemToShadow(addr);
   s.AppendF(
-  "Memory tags around the buggy address (one tag corresponds to %zd "
+  "\nMemory tags around the buggy address (one tag corresponds to %zd "
   "bytes):\n",
   kShadowAlignment);
   PrintTagInfoAroundAddr(addr, kShadowLines, s,
@@ -648,19 +654,23 @@ void BaseReport::PrintHeapOrGlobalCandidate() const {
   if (candidate.heap.is_allocated) {
 uptr offset;
 const char *whence;
+const char *cause;
 if (candidate.heap.begin <= untagged_addr &&
 untagged_addr < candidate.heap.end) {
   offset = untagged_addr - candidate.heap.begin;
   whence = "inside";
+  cause = "heap-use-after-free";
 } else if (candidate.after) {
   offset = untagged_addr - candidate.heap.end;
   whence = "after";
+  cause = "heap-buffer-overflow";
 } else {
   offset = candidate.heap.begin - untagged_addr;
   whence = "before";
+  cause = "heap-buffer-underflow";
 }
 Printf("%s", d.Error());
-Printf("\nCause: heap-buffer-overflow\n");
+Printf("\nCause: %s\n", cause);
 Printf("%s", d.Default());
 Printf("%s", d.Location());
 Printf("%p is located %zd bytes %s a %zd-byte region [%p,%p)\n",
@@ -803,8 +813,10 @@ void BaseReport::PrintAddressDescription() const {
   }
 
   // Print the remaining threads, as an extra information, 1 line per thread.
-  if (flags()->print_live_threads_info)
+  if (flags()->print_live_threads_info) {
+Printf("\n");
 hwasanThreadList().VisitAllLiveThreads([&](Thread *t) { t->Announce(); });
+  }
 
   if (!num_descriptions_printed)
 // We exhausted our possibilities. Bail out.
@@ -1020,7 +1032,7 @@ void ReportTagMismatch(StackTrace *stack, uptr 
tagged_addr, uptr access_size,
 // See the frame breakdown defined in __hwasan_tag_mismatch (from
 // hwasan_tag_mismatch_{aarch64,riscv64}.S).
 void ReportRegisters(const uptr *frame, uptr pc) {
-  Printf("Registers where the failure occurred (pc %p):\n", pc);
+  Printf("\nRegisters where the failure occurred (pc %p):\n", pc);
 
   // We explicitly print a single line (4 registers/line) each iteration to
   // reduce the amount of logcat error messages printed. Each Printf() will
diff --git a/compiler-rt/test/hwasan/TestCases/Linux/syscalls.cpp 
b/compiler-rt/test/hwasan/TestCases/Linux/syscalls.cpp
index 154b6989899352..eee43f458fac10 100644
--- a/compiler-rt/test/hwasan/TestCases/Linux/syscalls.cpp
+++ b/compiler-rt/test/hwasan/TestCases/Linux/syscalls.cpp
@@ -26,7 +26,7 @@ int main(int argc, char *argv[]) {
 
   __sanitizer_syscall_pre_recvmsg(0, buf - 1, 0);
   // CHECK: HWAddressSanitizer: tag-mismatch on address 

[Lldb-commits] [mlir] [openmp] [libcxx] [compiler-rt] [llvm] [lldb] [libc] [clang] [flang] [hwasan] Classify stack overflow, and use after scope (PR #76133)

2023-12-21 Thread Vitaly Buka via lldb-commits

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

>From 89636904337efe75ef6e0743e4f098f0d5b5ab56 Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Wed, 20 Dec 2023 23:58:05 -0800
Subject: [PATCH 1/3] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20ch?=
 =?UTF-8?q?anges=20to=20main=20this=20commit=20is=20based=20on?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.4

[skip ci]
---
 compiler-rt/lib/hwasan/hwasan_report.cpp  | 26 ++-
 .../test/hwasan/TestCases/Linux/syscalls.cpp  |  2 +-
 .../hwasan/TestCases/heap-buffer-overflow.c   |  7 ++---
 3 files changed, 24 insertions(+), 11 deletions(-)

diff --git a/compiler-rt/lib/hwasan/hwasan_report.cpp 
b/compiler-rt/lib/hwasan/hwasan_report.cpp
index 5e8aa315801bcd..dc34cded48e12c 100644
--- a/compiler-rt/lib/hwasan/hwasan_report.cpp
+++ b/compiler-rt/lib/hwasan/hwasan_report.cpp
@@ -205,6 +205,7 @@ static void PrintStackAllocations(const 
StackAllocationsRingBuffer *sa,
   tag_t addr_tag, uptr untagged_addr) {
   uptr frames = Min((uptr)flags()->stack_history_size, sa->size());
   bool found_local = false;
+  InternalScopedString location;
   for (uptr i = 0; i < frames; i++) {
 const uptr *record_addr = &(*sa)[i];
 uptr record = *record_addr;
@@ -233,11 +234,16 @@ static void PrintStackAllocations(const 
StackAllocationsRingBuffer *sa,
 if (obj_offset >= local.size)
   continue;
 if (!found_local) {
-  Printf("Potentially referenced stack objects:\n");
+  Printf("\nPotentially referenced stack objects:\n");
   found_local = true;
 }
-Printf("  %s in %s %s:%d\n", local.name, local.function_name,
-   local.decl_file, local.decl_line);
+StackTracePrinter::GetOrInit()->RenderSourceLocation(
+, local.decl_file, local.decl_line, 0,
+common_flags()->symbolize_vs_style,
+common_flags()->strip_path_prefix);
+Printf("  %s in %s %s\n", local.name, local.function_name,
+   location.data());
+location.clear();
   }
   frame.Clear();
 }
@@ -363,7 +369,7 @@ static void PrintTagsAroundAddr(uptr addr, GetTag get_tag,
   InternalScopedString s;
   addr = MemToShadow(addr);
   s.AppendF(
-  "Memory tags around the buggy address (one tag corresponds to %zd "
+  "\nMemory tags around the buggy address (one tag corresponds to %zd "
   "bytes):\n",
   kShadowAlignment);
   PrintTagInfoAroundAddr(addr, kShadowLines, s,
@@ -648,19 +654,23 @@ void BaseReport::PrintHeapOrGlobalCandidate() const {
   if (candidate.heap.is_allocated) {
 uptr offset;
 const char *whence;
+const char *cause;
 if (candidate.heap.begin <= untagged_addr &&
 untagged_addr < candidate.heap.end) {
   offset = untagged_addr - candidate.heap.begin;
   whence = "inside";
+  cause = "heap-use-after-free";
 } else if (candidate.after) {
   offset = untagged_addr - candidate.heap.end;
   whence = "after";
+  cause = "heap-buffer-overflow";
 } else {
   offset = candidate.heap.begin - untagged_addr;
   whence = "before";
+  cause = "heap-buffer-underflow";
 }
 Printf("%s", d.Error());
-Printf("\nCause: heap-buffer-overflow\n");
+Printf("\nCause: %s\n", cause);
 Printf("%s", d.Default());
 Printf("%s", d.Location());
 Printf("%p is located %zd bytes %s a %zd-byte region [%p,%p)\n",
@@ -803,8 +813,10 @@ void BaseReport::PrintAddressDescription() const {
   }
 
   // Print the remaining threads, as an extra information, 1 line per thread.
-  if (flags()->print_live_threads_info)
+  if (flags()->print_live_threads_info) {
+Printf("\n");
 hwasanThreadList().VisitAllLiveThreads([&](Thread *t) { t->Announce(); });
+  }
 
   if (!num_descriptions_printed)
 // We exhausted our possibilities. Bail out.
@@ -1020,7 +1032,7 @@ void ReportTagMismatch(StackTrace *stack, uptr 
tagged_addr, uptr access_size,
 // See the frame breakdown defined in __hwasan_tag_mismatch (from
 // hwasan_tag_mismatch_{aarch64,riscv64}.S).
 void ReportRegisters(const uptr *frame, uptr pc) {
-  Printf("Registers where the failure occurred (pc %p):\n", pc);
+  Printf("\nRegisters where the failure occurred (pc %p):\n", pc);
 
   // We explicitly print a single line (4 registers/line) each iteration to
   // reduce the amount of logcat error messages printed. Each Printf() will
diff --git a/compiler-rt/test/hwasan/TestCases/Linux/syscalls.cpp 
b/compiler-rt/test/hwasan/TestCases/Linux/syscalls.cpp
index 154b6989899352..eee43f458fac10 100644
--- a/compiler-rt/test/hwasan/TestCases/Linux/syscalls.cpp
+++ b/compiler-rt/test/hwasan/TestCases/Linux/syscalls.cpp
@@ -26,7 +26,7 @@ int main(int argc, char *argv[]) {
 
   __sanitizer_syscall_pre_recvmsg(0, buf - 1, 0);
   // CHECK: HWAddressSanitizer: tag-mismatch on address 

[Lldb-commits] [llvm] [openmp] [libc] [compiler-rt] [lldb] [mlir] [flang] [libcxx] [clang] [hwasan] Classify stack overflow, and use after scope (PR #76133)

2023-12-21 Thread Florian Mayer via lldb-commits

https://github.com/fmayer commented:

Remove this comment?

Line 780

```
// TODO(fmayer): figure out how to distinguish use-after-return and
// stack-buffer-overflow.
```

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


[Lldb-commits] [llvm] [libc] [compiler-rt] [clang-tools-extra] [lldb] [flang] [libcxx] [clang] [RegAllocFast] Refactor dominates algorithm for large basic block (PR #72250)

2023-12-21 Thread via lldb-commits

https://github.com/HaohaiWen updated 
https://github.com/llvm/llvm-project/pull/72250

>From 581b28b6827855643bd5bdbca0cf9ccef0de2584 Mon Sep 17 00:00:00 2001
From: Haohai Wen 
Date: Tue, 14 Nov 2023 20:20:29 +0800
Subject: [PATCH 1/2] [RegAllocFast] Refactor dominates algorithm for large
 basic block

The original brute force dominates algorithm is O(n) complexity so it is
very slow for very large machine basic block which is very common with
O0. This patch added InstrPosIndexes to assign index for each
instruction and use it to determine dominance. The complexity is now
O(1).
---
 llvm/lib/CodeGen/RegAllocFast.cpp | 92 ++-
 1 file changed, 78 insertions(+), 14 deletions(-)

diff --git a/llvm/lib/CodeGen/RegAllocFast.cpp 
b/llvm/lib/CodeGen/RegAllocFast.cpp
index b216d729644626..acdc32f5902fa8 100644
--- a/llvm/lib/CodeGen/RegAllocFast.cpp
+++ b/llvm/lib/CodeGen/RegAllocFast.cpp
@@ -62,6 +62,71 @@ static RegisterRegAlloc fastRegAlloc("fast", "fast register 
allocator",
 
 namespace {
 
+/// Assign ascending index for instructions in machine basic block. The index
+/// can be used to determine dominance between instructions in same MBB.
+class InstrPosIndexes {
+public:
+  void init(const MachineBasicBlock ) {
+CurMBB = 
+Instr2PosIndex.clear();
+uint64_t LastIndex = 0;
+for (const MachineInstr  : MBB) {
+  LastIndex += InstrDist;
+  Instr2PosIndex[] = LastIndex;
+}
+  }
+
+  /// Set \p Index to index of \p MI. If \p MI is new inserted, it try to 
assign
+  /// index without affecting existing instruction's index. Return true if all
+  /// instructions index has been reassigned.
+  bool getIndex(const MachineInstr , uint64_t ) {
+assert(MI.getParent() == CurMBB && "MI is not in CurMBB");
+if (Instr2PosIndex.count()) {
+  Index = Instr2PosIndex[];
+  return false;
+}
+
+unsigned Distance = 1;
+MachineBasicBlock::const_iterator Start = MI.getIterator(),
+  End = std::next(Start);
+while (Start != CurMBB->begin() &&
+   !Instr2PosIndex.count(&*std::prev(Start))) {
+  --Start;
+  ++Distance;
+}
+while (End != CurMBB->end() && !Instr2PosIndex.count(&*(End))) {
+  ++End;
+  ++Distance;
+}
+
+uint64_t LastIndex =
+Start == CurMBB->begin() ? 0 : Instr2PosIndex.at(&*std::prev(Start));
+uint64_t Step = End == CurMBB->end()
+? static_cast(InstrDist)
+: (Instr2PosIndex.at(&*End) - LastIndex - 1) / 
Distance;
+
+// Reassign index for all instructions if number of new inserted
+// instructions exceed slot or all instructions are new.
+if (LLVM_UNLIKELY(!Step || (!LastIndex && Step == InstrDist))) {
+  init(*CurMBB);
+  Index = Instr2PosIndex.at();
+  return true;
+}
+
+for (auto I = Start; I != End; ++I) {
+  LastIndex += Step;
+  Instr2PosIndex[&*I] = LastIndex;
+}
+Index = Instr2PosIndex.at();
+return false;
+  }
+
+private:
+  enum { InstrDist = 1024 };
+  const MachineBasicBlock *CurMBB = nullptr;
+  DenseMap Instr2PosIndex;
+};
+
 class RegAllocFast : public MachineFunctionPass {
 public:
   static char ID;
@@ -153,6 +218,9 @@ class RegAllocFast : public MachineFunctionPass {
   // Register masks attached to the current instruction.
   SmallVector RegMasks;
 
+  // Assign index for each instruction to quickly determine dominance.
+  InstrPosIndexes PosIndexes;
+
   void setPhysRegState(MCPhysReg PhysReg, unsigned NewState);
   bool isPhysRegFree(MCPhysReg PhysReg) const;
 
@@ -339,18 +407,13 @@ int RegAllocFast::getStackSpaceFor(Register VirtReg) {
   return FrameIdx;
 }
 
-static bool dominates(MachineBasicBlock ,
-  MachineBasicBlock::const_iterator A,
-  MachineBasicBlock::const_iterator B) {
-  auto MBBEnd = MBB.end();
-  if (B == MBBEnd)
-return true;
-
-  MachineBasicBlock::const_iterator I = MBB.begin();
-  for (; &*I != A && &*I != B; ++I)
-;
-
-  return &*I == A;
+static bool dominates(InstrPosIndexes , const MachineInstr ,
+  const MachineInstr ) {
+  uint64_t IndexA, IndexB;
+  PosIndexes.getIndex(A, IndexA);
+  if (LLVM_UNLIKELY(PosIndexes.getIndex(B, IndexB)))
+PosIndexes.getIndex(A, IndexA);
+  return IndexA < IndexB;
 }
 
 /// Returns false if \p VirtReg is known to not live out of the current block.
@@ -371,7 +434,7 @@ bool RegAllocFast::mayLiveOut(Register VirtReg) {
 MayLiveAcrossBlocks.set(Register::virtReg2Index(VirtReg));
 return true;
   } else {
-if (!SelfLoopDef || dominates(*MBB, DefInst.getIterator(), 
SelfLoopDef))
+if (!SelfLoopDef || dominates(PosIndexes, DefInst, *SelfLoopDef))
   SelfLoopDef = 
   }
 }
@@ -396,7 +459,7 @@ bool RegAllocFast::mayLiveOut(Register VirtReg) {
   // Try to handle some simple cases to avoid spilling and reloading every
   // value inside a self looping 

[Lldb-commits] [llvm] [openmp] [libc] [compiler-rt] [lldb] [mlir] [flang] [libcxx] [clang] [hwasan] Classify stack overflow, and use after scope (PR #76133)

2023-12-21 Thread Florian Mayer via lldb-commits


@@ -221,29 +221,55 @@ static void PrintStackAllocations(const 
StackAllocationsRingBuffer *sa,
   for (LocalInfo  : frame.locals) {
 if (!local.has_frame_offset || !local.has_size || 
!local.has_tag_offset)
   continue;
+if (!(local.name && internal_strlen(local.name)) &&
+!(local.function_name && internal_strlen(local.name)) &&
+!(local.decl_file && internal_strlen(local.decl_file)))
+  continue;
 tag_t obj_tag = base_tag ^ local.tag_offset;
 if (obj_tag != addr_tag)
   continue;
-// Calculate the offset from the object address to the faulting
-// address. Because we only store bits 4-19 of FP (bits 0-3 are
-// guaranteed to be zero), the calculation is performed mod 2^20 and 
may
-// harmlessly underflow if the address mod 2^20 is below the object
-// address.
-uptr obj_offset =
-(untagged_addr - fp - local.frame_offset) & (kRecordFPModulus - 1);
-if (obj_offset >= local.size)
-  continue;
+uptr local_beg = (fp + local.frame_offset) |

fmayer wrote:

 I am confused by this. Could you add a comment as on the LHS? Why isn't the 
`local_beg` not just `fp + local.frame_offset`?

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


[Lldb-commits] [clang] [llvm] [libcxx] [lldb] [flang] [openmp] [mlir] [libc] [compiler-rt] [hwasan] Classify stack overflow, and use after scope (PR #76133)

2023-12-21 Thread Florian Mayer via lldb-commits


@@ -221,29 +221,55 @@ static void PrintStackAllocations(const 
StackAllocationsRingBuffer *sa,
   for (LocalInfo  : frame.locals) {
 if (!local.has_frame_offset || !local.has_size || 
!local.has_tag_offset)
   continue;
+if (!(local.name && internal_strlen(local.name)) &&
+!(local.function_name && internal_strlen(local.name)) &&
+!(local.decl_file && internal_strlen(local.decl_file)))
+  continue;
 tag_t obj_tag = base_tag ^ local.tag_offset;
 if (obj_tag != addr_tag)
   continue;
-// Calculate the offset from the object address to the faulting
-// address. Because we only store bits 4-19 of FP (bits 0-3 are
-// guaranteed to be zero), the calculation is performed mod 2^20 and 
may
-// harmlessly underflow if the address mod 2^20 is below the object
-// address.
-uptr obj_offset =
-(untagged_addr - fp - local.frame_offset) & (kRecordFPModulus - 1);
-if (obj_offset >= local.size)
-  continue;
+uptr local_beg = (fp + local.frame_offset) |
+ (untagged_addr & ~(uptr(kRecordFPModulus) - 1));
+uptr local_end = local_beg + local.size;
+
 if (!found_local) {
   Printf("\nPotentially referenced stack objects:\n");
   found_local = true;
 }
+
+uptr offset;
+const char *whence;
+const char *cause;
+if (local_beg <= untagged_addr && untagged_addr < local_end) {
+  offset = untagged_addr - local_beg;
+  whence = "inside";
+  cause = "use-after-scope";
+} else if (untagged_addr >= local_end) {
+  offset = untagged_addr - local_end;
+  whence = "after";
+  cause = "stack-buffer-overflow";
+} else {
+  offset = local_beg - untagged_addr;
+  whence = "before";
+  cause = "stack-buffer-overflow";
+}
+Decorator d;
+Printf("%s", d.Error());
+Printf("Cause: %s\n", cause);
+Printf("%s", d.Default());
+Printf("%s", d.Location());
+Printf("%p is located %zd bytes %s a %zd-byte region [%p,%p)\n",
+   untagged_addr, offset, whence, local_end - local_beg, local_beg,
+   local_end);
+Printf("%s", d.Allocation());
 StackTracePrinter::GetOrInit()->RenderSourceLocation(

fmayer wrote:

FYI the offline symbolizer has this output format

```
self.print('')
self.print('Potentially referenced stack object:')
self.print('  %d bytes inside a variable "%s" in stack frame of 
function "%s"' % (obj_offset, local[2], local[0]))
self.print('  at %s' % (local[1],))
```

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


[Lldb-commits] [llvm] [clang-tools-extra] [libcxx] [compiler-rt] [flang] [libc] [lldb] [clang] [RegAllocFast] Refactor dominates algorithm for large basic block (PR #72250)

2023-12-21 Thread via lldb-commits

https://github.com/HaohaiWen updated 
https://github.com/llvm/llvm-project/pull/72250

>From 581b28b6827855643bd5bdbca0cf9ccef0de2584 Mon Sep 17 00:00:00 2001
From: Haohai Wen 
Date: Tue, 14 Nov 2023 20:20:29 +0800
Subject: [PATCH 1/2] [RegAllocFast] Refactor dominates algorithm for large
 basic block

The original brute force dominates algorithm is O(n) complexity so it is
very slow for very large machine basic block which is very common with
O0. This patch added InstrPosIndexes to assign index for each
instruction and use it to determine dominance. The complexity is now
O(1).
---
 llvm/lib/CodeGen/RegAllocFast.cpp | 92 ++-
 1 file changed, 78 insertions(+), 14 deletions(-)

diff --git a/llvm/lib/CodeGen/RegAllocFast.cpp 
b/llvm/lib/CodeGen/RegAllocFast.cpp
index b216d729644626..acdc32f5902fa8 100644
--- a/llvm/lib/CodeGen/RegAllocFast.cpp
+++ b/llvm/lib/CodeGen/RegAllocFast.cpp
@@ -62,6 +62,71 @@ static RegisterRegAlloc fastRegAlloc("fast", "fast register 
allocator",
 
 namespace {
 
+/// Assign ascending index for instructions in machine basic block. The index
+/// can be used to determine dominance between instructions in same MBB.
+class InstrPosIndexes {
+public:
+  void init(const MachineBasicBlock ) {
+CurMBB = 
+Instr2PosIndex.clear();
+uint64_t LastIndex = 0;
+for (const MachineInstr  : MBB) {
+  LastIndex += InstrDist;
+  Instr2PosIndex[] = LastIndex;
+}
+  }
+
+  /// Set \p Index to index of \p MI. If \p MI is new inserted, it try to 
assign
+  /// index without affecting existing instruction's index. Return true if all
+  /// instructions index has been reassigned.
+  bool getIndex(const MachineInstr , uint64_t ) {
+assert(MI.getParent() == CurMBB && "MI is not in CurMBB");
+if (Instr2PosIndex.count()) {
+  Index = Instr2PosIndex[];
+  return false;
+}
+
+unsigned Distance = 1;
+MachineBasicBlock::const_iterator Start = MI.getIterator(),
+  End = std::next(Start);
+while (Start != CurMBB->begin() &&
+   !Instr2PosIndex.count(&*std::prev(Start))) {
+  --Start;
+  ++Distance;
+}
+while (End != CurMBB->end() && !Instr2PosIndex.count(&*(End))) {
+  ++End;
+  ++Distance;
+}
+
+uint64_t LastIndex =
+Start == CurMBB->begin() ? 0 : Instr2PosIndex.at(&*std::prev(Start));
+uint64_t Step = End == CurMBB->end()
+? static_cast(InstrDist)
+: (Instr2PosIndex.at(&*End) - LastIndex - 1) / 
Distance;
+
+// Reassign index for all instructions if number of new inserted
+// instructions exceed slot or all instructions are new.
+if (LLVM_UNLIKELY(!Step || (!LastIndex && Step == InstrDist))) {
+  init(*CurMBB);
+  Index = Instr2PosIndex.at();
+  return true;
+}
+
+for (auto I = Start; I != End; ++I) {
+  LastIndex += Step;
+  Instr2PosIndex[&*I] = LastIndex;
+}
+Index = Instr2PosIndex.at();
+return false;
+  }
+
+private:
+  enum { InstrDist = 1024 };
+  const MachineBasicBlock *CurMBB = nullptr;
+  DenseMap Instr2PosIndex;
+};
+
 class RegAllocFast : public MachineFunctionPass {
 public:
   static char ID;
@@ -153,6 +218,9 @@ class RegAllocFast : public MachineFunctionPass {
   // Register masks attached to the current instruction.
   SmallVector RegMasks;
 
+  // Assign index for each instruction to quickly determine dominance.
+  InstrPosIndexes PosIndexes;
+
   void setPhysRegState(MCPhysReg PhysReg, unsigned NewState);
   bool isPhysRegFree(MCPhysReg PhysReg) const;
 
@@ -339,18 +407,13 @@ int RegAllocFast::getStackSpaceFor(Register VirtReg) {
   return FrameIdx;
 }
 
-static bool dominates(MachineBasicBlock ,
-  MachineBasicBlock::const_iterator A,
-  MachineBasicBlock::const_iterator B) {
-  auto MBBEnd = MBB.end();
-  if (B == MBBEnd)
-return true;
-
-  MachineBasicBlock::const_iterator I = MBB.begin();
-  for (; &*I != A && &*I != B; ++I)
-;
-
-  return &*I == A;
+static bool dominates(InstrPosIndexes , const MachineInstr ,
+  const MachineInstr ) {
+  uint64_t IndexA, IndexB;
+  PosIndexes.getIndex(A, IndexA);
+  if (LLVM_UNLIKELY(PosIndexes.getIndex(B, IndexB)))
+PosIndexes.getIndex(A, IndexA);
+  return IndexA < IndexB;
 }
 
 /// Returns false if \p VirtReg is known to not live out of the current block.
@@ -371,7 +434,7 @@ bool RegAllocFast::mayLiveOut(Register VirtReg) {
 MayLiveAcrossBlocks.set(Register::virtReg2Index(VirtReg));
 return true;
   } else {
-if (!SelfLoopDef || dominates(*MBB, DefInst.getIterator(), 
SelfLoopDef))
+if (!SelfLoopDef || dominates(PosIndexes, DefInst, *SelfLoopDef))
   SelfLoopDef = 
   }
 }
@@ -396,7 +459,7 @@ bool RegAllocFast::mayLiveOut(Register VirtReg) {
   // Try to handle some simple cases to avoid spilling and reloading every
   // value inside a self looping 

[Lldb-commits] [flang] [clang] [mlir] [llvm] [libcxx] [compiler-rt] [libc] [lldb] [openmp] [hwasan] Classify stack overflow, and use after scope (PR #76133)

2023-12-21 Thread Vitaly Buka via lldb-commits


@@ -0,0 +1,25 @@
+// RUN: %clang_hwasan -g %s -o %t && not %run %t 2>&1 | FileCheck %s
+
+// Stack histories currently are not recorded on x86.
+// XFAIL: target=x86_64{{.*}}
+
+__attribute((noinline)) void buggy() {
+  char c[64];
+  char *volatile p = c;
+  p[-2] = 0;
+}
+
+int main() {
+  buggy();
+  // CHECK: WRITE of size 1 at
+  // CHECK: #0 {{.*}} in buggy{{.*}}stack-underflow.c:[[@LINE-6]]
+  // CHECK: Cause: stack tag-mismatch

vitalybuka wrote:

The first one is true, the second one is "Potentially"

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


[Lldb-commits] [flang] [clang] [mlir] [llvm] [libcxx] [compiler-rt] [libc] [lldb] [openmp] [hwasan] Classify stack overflow, and use after scope (PR #76133)

2023-12-21 Thread Vitaly Buka via lldb-commits


@@ -221,29 +221,55 @@ static void PrintStackAllocations(const 
StackAllocationsRingBuffer *sa,
   for (LocalInfo  : frame.locals) {
 if (!local.has_frame_offset || !local.has_size || 
!local.has_tag_offset)
   continue;
+if (!(local.name && internal_strlen(local.name)) &&
+!(local.function_name && internal_strlen(local.name)) &&
+!local.decl_file)

vitalybuka wrote:

will check

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


[Lldb-commits] [flang] [clang] [mlir] [llvm] [libcxx] [compiler-rt] [libc] [lldb] [openmp] [hwasan] Classify stack overflow, and use after scope (PR #76133)

2023-12-21 Thread Vitaly Buka via lldb-commits

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


[Lldb-commits] [compiler-rt] [flang] [llvm] [libc] [openmp] [clang] [lldb] [mlir] [hwasan] Respect strip_path_prefix printing locals (PR #76132)

2023-12-21 Thread Vitaly Buka via lldb-commits

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


[Lldb-commits] [compiler-rt] [flang] [llvm] [libc] [openmp] [clang] [lldb] [mlir] [hwasan] Respect strip_path_prefix printing locals (PR #76132)

2023-12-21 Thread Vitaly Buka via lldb-commits

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

>From 8c5b5de0d4fda16cfa1c8c4281601b61a9ca774d Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Wed, 20 Dec 2023 23:58:01 -0800
Subject: [PATCH 1/4] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20ch?=
 =?UTF-8?q?anges=20to=20main=20this=20commit=20is=20based=20on?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.4

[skip ci]
---
 compiler-rt/lib/hwasan/hwasan_report.cpp | 16 +++-
 .../test/hwasan/TestCases/Linux/syscalls.cpp |  2 +-
 .../test/hwasan/TestCases/heap-buffer-overflow.c |  7 ---
 3 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/compiler-rt/lib/hwasan/hwasan_report.cpp 
b/compiler-rt/lib/hwasan/hwasan_report.cpp
index 5e8aa315801bcd..71155c9814c186 100644
--- a/compiler-rt/lib/hwasan/hwasan_report.cpp
+++ b/compiler-rt/lib/hwasan/hwasan_report.cpp
@@ -233,7 +233,7 @@ static void PrintStackAllocations(const 
StackAllocationsRingBuffer *sa,
 if (obj_offset >= local.size)
   continue;
 if (!found_local) {
-  Printf("Potentially referenced stack objects:\n");
+  Printf("\nPotentially referenced stack objects:\n");
   found_local = true;
 }
 Printf("  %s in %s %s:%d\n", local.name, local.function_name,
@@ -363,7 +363,7 @@ static void PrintTagsAroundAddr(uptr addr, GetTag get_tag,
   InternalScopedString s;
   addr = MemToShadow(addr);
   s.AppendF(
-  "Memory tags around the buggy address (one tag corresponds to %zd "
+  "\nMemory tags around the buggy address (one tag corresponds to %zd "
   "bytes):\n",
   kShadowAlignment);
   PrintTagInfoAroundAddr(addr, kShadowLines, s,
@@ -648,19 +648,23 @@ void BaseReport::PrintHeapOrGlobalCandidate() const {
   if (candidate.heap.is_allocated) {
 uptr offset;
 const char *whence;
+const char *cause;
 if (candidate.heap.begin <= untagged_addr &&
 untagged_addr < candidate.heap.end) {
   offset = untagged_addr - candidate.heap.begin;
   whence = "inside";
+  cause = "heap-use-after-free";
 } else if (candidate.after) {
   offset = untagged_addr - candidate.heap.end;
   whence = "after";
+  cause = "heap-buffer-overflow";
 } else {
   offset = candidate.heap.begin - untagged_addr;
   whence = "before";
+  cause = "heap-buffer-underflow";
 }
 Printf("%s", d.Error());
-Printf("\nCause: heap-buffer-overflow\n");
+Printf("\nCause: %s\n", cause);
 Printf("%s", d.Default());
 Printf("%s", d.Location());
 Printf("%p is located %zd bytes %s a %zd-byte region [%p,%p)\n",
@@ -803,8 +807,10 @@ void BaseReport::PrintAddressDescription() const {
   }
 
   // Print the remaining threads, as an extra information, 1 line per thread.
-  if (flags()->print_live_threads_info)
+  if (flags()->print_live_threads_info) {
+Printf("\n");
 hwasanThreadList().VisitAllLiveThreads([&](Thread *t) { t->Announce(); });
+  }
 
   if (!num_descriptions_printed)
 // We exhausted our possibilities. Bail out.
@@ -1020,7 +1026,7 @@ void ReportTagMismatch(StackTrace *stack, uptr 
tagged_addr, uptr access_size,
 // See the frame breakdown defined in __hwasan_tag_mismatch (from
 // hwasan_tag_mismatch_{aarch64,riscv64}.S).
 void ReportRegisters(const uptr *frame, uptr pc) {
-  Printf("Registers where the failure occurred (pc %p):\n", pc);
+  Printf("\nRegisters where the failure occurred (pc %p):\n", pc);
 
   // We explicitly print a single line (4 registers/line) each iteration to
   // reduce the amount of logcat error messages printed. Each Printf() will
diff --git a/compiler-rt/test/hwasan/TestCases/Linux/syscalls.cpp 
b/compiler-rt/test/hwasan/TestCases/Linux/syscalls.cpp
index 154b6989899352..eee43f458fac10 100644
--- a/compiler-rt/test/hwasan/TestCases/Linux/syscalls.cpp
+++ b/compiler-rt/test/hwasan/TestCases/Linux/syscalls.cpp
@@ -26,7 +26,7 @@ int main(int argc, char *argv[]) {
 
   __sanitizer_syscall_pre_recvmsg(0, buf - 1, 0);
   // CHECK: HWAddressSanitizer: tag-mismatch on address [[PTR:0x[a-f0-9]+]]
-  // CHECK: Cause: heap-buffer-overflow
+  // CHECK: Cause: heap-buffer-underflow
   // CHECK: [[PTR]] is located 1 bytes before a 1000-byte region
 
   free(buf);
diff --git a/compiler-rt/test/hwasan/TestCases/heap-buffer-overflow.c 
b/compiler-rt/test/hwasan/TestCases/heap-buffer-overflow.c
index 4e6638be584b0d..c1c7d458b9424f 100644
--- a/compiler-rt/test/hwasan/TestCases/heap-buffer-overflow.c
+++ b/compiler-rt/test/hwasan/TestCases/heap-buffer-overflow.c
@@ -29,7 +29,8 @@ int main(int argc, char **argv) {
   if (size == 100) {
 fprintf(stderr, "is a large allocated heap chunk; size: 1003520 offset: 
%d\n",
 offset);
-fprintf(stderr, "Cause: heap-buffer-overflow\n");
+fprintf(stderr, "Cause: heap-buffer-%s\n",
+offset == -30 ? "underflow" : "overflow");
 

[Lldb-commits] [llvm] [lldb] [mlir] [libc] [compiler-rt] [flang] [clang] [openmp] [hwasan] Respect strip_path_prefix printing locals (PR #76132)

2023-12-21 Thread Florian Mayer via lldb-commits

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

Lgtm thanks

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


[Lldb-commits] [llvm] [lldb] [mlir] [libc] [compiler-rt] [flang] [clang] [openmp] [hwasan] Respect strip_path_prefix printing locals (PR #76132)

2023-12-21 Thread Vitaly Buka via lldb-commits

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

>From 8c5b5de0d4fda16cfa1c8c4281601b61a9ca774d Mon Sep 17 00:00:00 2001
From: Vitaly Buka 
Date: Wed, 20 Dec 2023 23:58:01 -0800
Subject: [PATCH 1/3] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20ch?=
 =?UTF-8?q?anges=20to=20main=20this=20commit=20is=20based=20on?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Created using spr 1.3.4

[skip ci]
---
 compiler-rt/lib/hwasan/hwasan_report.cpp | 16 +++-
 .../test/hwasan/TestCases/Linux/syscalls.cpp |  2 +-
 .../test/hwasan/TestCases/heap-buffer-overflow.c |  7 ---
 3 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/compiler-rt/lib/hwasan/hwasan_report.cpp 
b/compiler-rt/lib/hwasan/hwasan_report.cpp
index 5e8aa315801bcd..71155c9814c186 100644
--- a/compiler-rt/lib/hwasan/hwasan_report.cpp
+++ b/compiler-rt/lib/hwasan/hwasan_report.cpp
@@ -233,7 +233,7 @@ static void PrintStackAllocations(const 
StackAllocationsRingBuffer *sa,
 if (obj_offset >= local.size)
   continue;
 if (!found_local) {
-  Printf("Potentially referenced stack objects:\n");
+  Printf("\nPotentially referenced stack objects:\n");
   found_local = true;
 }
 Printf("  %s in %s %s:%d\n", local.name, local.function_name,
@@ -363,7 +363,7 @@ static void PrintTagsAroundAddr(uptr addr, GetTag get_tag,
   InternalScopedString s;
   addr = MemToShadow(addr);
   s.AppendF(
-  "Memory tags around the buggy address (one tag corresponds to %zd "
+  "\nMemory tags around the buggy address (one tag corresponds to %zd "
   "bytes):\n",
   kShadowAlignment);
   PrintTagInfoAroundAddr(addr, kShadowLines, s,
@@ -648,19 +648,23 @@ void BaseReport::PrintHeapOrGlobalCandidate() const {
   if (candidate.heap.is_allocated) {
 uptr offset;
 const char *whence;
+const char *cause;
 if (candidate.heap.begin <= untagged_addr &&
 untagged_addr < candidate.heap.end) {
   offset = untagged_addr - candidate.heap.begin;
   whence = "inside";
+  cause = "heap-use-after-free";
 } else if (candidate.after) {
   offset = untagged_addr - candidate.heap.end;
   whence = "after";
+  cause = "heap-buffer-overflow";
 } else {
   offset = candidate.heap.begin - untagged_addr;
   whence = "before";
+  cause = "heap-buffer-underflow";
 }
 Printf("%s", d.Error());
-Printf("\nCause: heap-buffer-overflow\n");
+Printf("\nCause: %s\n", cause);
 Printf("%s", d.Default());
 Printf("%s", d.Location());
 Printf("%p is located %zd bytes %s a %zd-byte region [%p,%p)\n",
@@ -803,8 +807,10 @@ void BaseReport::PrintAddressDescription() const {
   }
 
   // Print the remaining threads, as an extra information, 1 line per thread.
-  if (flags()->print_live_threads_info)
+  if (flags()->print_live_threads_info) {
+Printf("\n");
 hwasanThreadList().VisitAllLiveThreads([&](Thread *t) { t->Announce(); });
+  }
 
   if (!num_descriptions_printed)
 // We exhausted our possibilities. Bail out.
@@ -1020,7 +1026,7 @@ void ReportTagMismatch(StackTrace *stack, uptr 
tagged_addr, uptr access_size,
 // See the frame breakdown defined in __hwasan_tag_mismatch (from
 // hwasan_tag_mismatch_{aarch64,riscv64}.S).
 void ReportRegisters(const uptr *frame, uptr pc) {
-  Printf("Registers where the failure occurred (pc %p):\n", pc);
+  Printf("\nRegisters where the failure occurred (pc %p):\n", pc);
 
   // We explicitly print a single line (4 registers/line) each iteration to
   // reduce the amount of logcat error messages printed. Each Printf() will
diff --git a/compiler-rt/test/hwasan/TestCases/Linux/syscalls.cpp 
b/compiler-rt/test/hwasan/TestCases/Linux/syscalls.cpp
index 154b6989899352..eee43f458fac10 100644
--- a/compiler-rt/test/hwasan/TestCases/Linux/syscalls.cpp
+++ b/compiler-rt/test/hwasan/TestCases/Linux/syscalls.cpp
@@ -26,7 +26,7 @@ int main(int argc, char *argv[]) {
 
   __sanitizer_syscall_pre_recvmsg(0, buf - 1, 0);
   // CHECK: HWAddressSanitizer: tag-mismatch on address [[PTR:0x[a-f0-9]+]]
-  // CHECK: Cause: heap-buffer-overflow
+  // CHECK: Cause: heap-buffer-underflow
   // CHECK: [[PTR]] is located 1 bytes before a 1000-byte region
 
   free(buf);
diff --git a/compiler-rt/test/hwasan/TestCases/heap-buffer-overflow.c 
b/compiler-rt/test/hwasan/TestCases/heap-buffer-overflow.c
index 4e6638be584b0d..c1c7d458b9424f 100644
--- a/compiler-rt/test/hwasan/TestCases/heap-buffer-overflow.c
+++ b/compiler-rt/test/hwasan/TestCases/heap-buffer-overflow.c
@@ -29,7 +29,8 @@ int main(int argc, char **argv) {
   if (size == 100) {
 fprintf(stderr, "is a large allocated heap chunk; size: 1003520 offset: 
%d\n",
 offset);
-fprintf(stderr, "Cause: heap-buffer-overflow\n");
+fprintf(stderr, "Cause: heap-buffer-%s\n",
+offset == -30 ? "underflow" : "overflow");
 

[Lldb-commits] [llvm] [lldb] [mlir] [libc] [compiler-rt] [flang] [clang] [openmp] [hwasan] Respect strip_path_prefix printing locals (PR #76132)

2023-12-21 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 9d0e3a77eee290592620cf017c433bd7a751952d 
9e2f17c3a3624b8dbaff499612339210d66ff975 -- 
compiler-rt/test/hwasan/TestCases/strip_path_prefix.c 
compiler-rt/lib/hwasan/hwasan_report.cpp
``





View the diff from clang-format here.


``diff
diff --git a/compiler-rt/test/hwasan/TestCases/strip_path_prefix.c 
b/compiler-rt/test/hwasan/TestCases/strip_path_prefix.c
index 39ee7f562f..5f1c7ab663 100644
--- a/compiler-rt/test/hwasan/TestCases/strip_path_prefix.c
+++ b/compiler-rt/test/hwasan/TestCases/strip_path_prefix.c
@@ -9,7 +9,7 @@
 
 int t;
 
-__attribute__((noinline)) char* buggy() {
+__attribute__((noinline)) char *buggy() {
   char *volatile p;
   char zzz = {};
   char yyy = {};
@@ -18,7 +18,7 @@ __attribute__((noinline)) char* buggy() {
 }
 
 int main() {
-  char* p = buggy();
+  char *p = buggy();
   return *p;
   // CHECK: READ of size 1 at
   // CHECK: #0 {{.*}} in main strip_path_prefix.c:[[@LINE-2]]

``




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


[Lldb-commits] [llvm] [compiler-rt] [lldb] [mlir] [clang] [openmp] [flang] [libc] [hwasan] Respect strip_path_prefix printing locals (PR #76132)

2023-12-21 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 9d0e3a77eee290592620cf017c433bd7a751952d 
9e2f17c3a3624b8dbaff499612339210d66ff975 -- 
compiler-rt/test/hwasan/TestCases/strip_path_prefix.c 
compiler-rt/lib/hwasan/hwasan_report.cpp
``





View the diff from clang-format here.


``diff
diff --git a/compiler-rt/test/hwasan/TestCases/strip_path_prefix.c 
b/compiler-rt/test/hwasan/TestCases/strip_path_prefix.c
index 39ee7f562f..5f1c7ab663 100644
--- a/compiler-rt/test/hwasan/TestCases/strip_path_prefix.c
+++ b/compiler-rt/test/hwasan/TestCases/strip_path_prefix.c
@@ -9,7 +9,7 @@
 
 int t;
 
-__attribute__((noinline)) char* buggy() {
+__attribute__((noinline)) char *buggy() {
   char *volatile p;
   char zzz = {};
   char yyy = {};
@@ -18,7 +18,7 @@ __attribute__((noinline)) char* buggy() {
 }
 
 int main() {
-  char* p = buggy();
+  char *p = buggy();
   return *p;
   // CHECK: READ of size 1 at
   // CHECK: #0 {{.*}} in main strip_path_prefix.c:[[@LINE-2]]

``




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


[Lldb-commits] [llvm] [compiler-rt] [lldb] [mlir] [clang] [openmp] [flang] [libc] [hwasan] Respect strip_path_prefix printing locals (PR #76132)

2023-12-21 Thread Vitaly Buka via lldb-commits

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


[Lldb-commits] [lldb] [LLDB] Define _BSD_SOURCE globally, to get optreset available in mingw's getopt.h (PR #76137)

2023-12-21 Thread Martin Storsjö via lldb-commits

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


[Lldb-commits] [lldb] f70b229 - [LLDB] Define _BSD_SOURCE globally, to get optreset available in mingw's getopt.h (#76137)

2023-12-21 Thread via lldb-commits

Author: Martin Storsjö
Date: 2023-12-22T00:40:12+02:00
New Revision: f70b229e9643ddb895d491b62a5ec0655917f6f8

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

LOG: [LLDB] Define _BSD_SOURCE globally, to get optreset available in mingw's 
getopt.h (#76137)

We previously were defining _BSD_SOURCE right before including getopt.h.
However, on mingw-w64, getopt.h is also transitively included by
unistd.h, and unistd.h can be transitively included by many headers
(recently, by some libc++ headers).

Therefore, to be safe, we need to define _BSD_SOURCE before including
any header. Thus do this in CMake.

This fixes https://github.com/llvm/llvm-project/issues/76050.

Added: 


Modified: 
lldb/CMakeLists.txt
lldb/include/lldb/Host/HostGetOpt.h

Removed: 




diff  --git a/lldb/CMakeLists.txt b/lldb/CMakeLists.txt
index 4a53d7ef3d0da0..7844d93d78d29a 100644
--- a/lldb/CMakeLists.txt
+++ b/lldb/CMakeLists.txt
@@ -44,6 +44,10 @@ endif()
 
 if (WIN32)
   add_definitions(-D_ENABLE_EXTENDED_ALIGNED_STORAGE)
+  if (NOT MSVC)
+# _BSD_SOURCE is required for MinGW's getopt.h to define optreset
+add_definitions(-D_BSD_SOURCE)
+  endif()
 endif()
 
 if (LLDB_ENABLE_PYTHON)

diff  --git a/lldb/include/lldb/Host/HostGetOpt.h 
b/lldb/include/lldb/Host/HostGetOpt.h
index 746e03e1bd1ee2..52cfdf4dbb89c2 100644
--- a/lldb/include/lldb/Host/HostGetOpt.h
+++ b/lldb/include/lldb/Host/HostGetOpt.h
@@ -11,10 +11,6 @@
 
 #if !defined(_MSC_VER) && !defined(__NetBSD__)
 
-#ifdef _WIN32
-#define _BSD_SOURCE // Required so that getopt.h defines optreset
-#endif
-
 #include 
 #include 
 



___
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)

2023-12-21 Thread Felipe de Azevedo Piovezan via lldb-commits

https://github.com/felipepiovezan edited 
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] Remove redundant severity substring within a diagnostic message. (PR #76111)

2023-12-21 Thread Felipe de Azevedo Piovezan via lldb-commits


@@ -48,8 +48,17 @@ std::string DiagnosticManager::GetString(char separator) {
   std::string ret;
 
   for (const auto  : 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);

felipepiovezan wrote:

Oh, also `ret` breaks both promises: we modify it  a lot and we also extend its 
lifetime past the current function

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] Remove redundant severity substring within a diagnostic message. (PR #76111)

2023-12-21 Thread Felipe de Azevedo Piovezan via lldb-commits


@@ -48,8 +48,17 @@ std::string DiagnosticManager::GetString(char separator) {
   std::string ret;
 
   for (const auto  : 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);

felipepiovezan wrote:

> I thought StringRef was better for strings that get passed around and reused 
> and std::string is better for transient work, such as this.

> Is general, is there an advantage to using StringRef over std::string?


A StringRef is a _non-owning view_ into a string. When we see one of those, 
that means the author of the code is making a few promises:
1. They don't need to mutate the string
2. They don't need to extend its lifetime past "the current" context.

Conversely, when the author conjures a `std::string` out of `StringRef`, the 
author is saying that they intend to break one of those promises. Note that 
your code doesn't need to, with the exception `searchable_message`: we had to 
modify the string with "to_lower"!


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] Remove redundant severity substring within a diagnostic message. (PR #76111)

2023-12-21 Thread Pete Lawrence via lldb-commits


@@ -48,8 +48,17 @@ std::string DiagnosticManager::GetString(char separator) {
   std::string ret;
 
   for (const auto  : 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:

I don't know how hot it is either but, I do know `UserExpression.cpp` has 2 
call sites, which may be a popular path.

There's about 15 call sites from these files:
* `lldb/include/lldb/Expression/DiagnosticManager.h`
* `lldb/source/Breakpoint/BreakpointLocation.cpp`
* `lldb/source/Expression/DiagnosticManager.cpp`
* `lldb/source/Expression/UserExpression.cpp`
* `lldb/source/Expression/UtilityFunction.cpp`
* `lldb/source/Interpreter/CommandReturnObject.cpp`
* `lldb/source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp`
* `lldb/source/Plugins/Platform/POSIX/PlatformPOSIX.cpp`
* `lldb/source/Plugins/Platform/Windows/PlatformWindows.cpp`
* `lldb/source/Target/Target.cpp`
* `lldb/source/Utility/Status.cpp`

The one from `DiagnosticManager.h` is its `Dump()` method which itself has 7 
call sites.

I have a future PR that'll move this functionality into `class Status`, and 
whatever we decided to do here we can do there as well.

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] Define _BSD_SOURCE globally, to get optreset available in mingw's getopt.h (PR #76137)

2023-12-21 Thread Martin Storsjö via lldb-commits


@@ -44,6 +44,10 @@ endif()
 
 if (WIN32)
   add_definitions(-D_ENABLE_EXTENDED_ALIGNED_STORAGE)
+  if (NOT MSVC)

mstorsjo wrote:

This was never defined for clang-cl/MSVC builds before. Note that the existing 
define I'm removing is within this context:

```
#if !defined(_MSC_VER) && !defined(__NetBSD__)

#ifdef _WIN32
#define _BSD_SOURCE // Required so that getopt.h defines optreset
#endif
```
So we previously only defined `_BSD_SOURCE` on `defined(_WIN32) && 
!defined(_MSC_VER)`, i.e. `if (WIN32 AND NOT MSVC)` in cmake (even if the 
condition nesting is the other way around there).

https://github.com/llvm/llvm-project/pull/76137
___
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)

2023-12-21 Thread Pete Lawrence via lldb-commits


@@ -48,8 +48,17 @@ std::string DiagnosticManager::GetString(char separator) {
   std::string ret;
 
   for (const auto  : 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:

I thought `StringRef` was better for strings that get passed around and reused 
and `std::string` is better for transient work, such as this.

Is general, is there an advantage to using `StringRef` over `std::string`?

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] Make only one function that needs to be implemented when searching for types (PR #74786)

2023-12-21 Thread David Blaikie via lldb-commits

dwblaikie wrote:

FWIW, we're seeing this breaking a pretty printer in google - previously a 
lookup was able to find 
`absl::cord_internal::RefcountAndFlags::Flags::kNumFlags` ( 
https://github.com/abseil/abseil-cpp/blob/8184f16e898fcb13b310b40430e13ba40679cf0e/absl/strings/internal/cord_internal.h#L202
 ) (the name components are, in order: namespace, namespace, class, unscoped 
enumeration, enumerator)

The code we have (working via [gala](https://github.com/sivachandra/gala)) has 
been doing this query twice to workaround this bug: 
https://github.com/llvm/llvm-project/issues/53904 - but it looks like since 
this change, that workaround has even broken and the name is no longer found?

I don't have a fully isolated repro yet, but figured I'd start with raising the 
flag in case anyone recognizes this.

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


[Lldb-commits] [lldb] [LLDB] Fix write permission error in TestGlobalModuleCache.py (PR #76171)

2023-12-21 Thread via lldb-commits

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


[Lldb-commits] [lldb] 1830fad - [LLDB] Fix write permission error in TestGlobalModuleCache.py (#76171)

2023-12-21 Thread via lldb-commits

Author: cmtice
Date: 2023-12-21T12:05:36-08:00
New Revision: 1830fadb78be9993cfeeaa7fb6867c3df1a53a8b

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

LOG: [LLDB] Fix write permission error in TestGlobalModuleCache.py (#76171)

TestGlobalModuleCache.py, a recently added test, tries to update a
source file in the build directory, but it assumes the file is writable.
In our distributed build and test system, this is not always true, so
the test often fails with a write permissions error.

This change fixes that by setting the permissions on the file to be
writable before attempting to write to it.

Added: 


Modified: 
lldb/test/API/python_api/global_module_cache/TestGlobalModuleCache.py

Removed: 




diff  --git 
a/lldb/test/API/python_api/global_module_cache/TestGlobalModuleCache.py 
b/lldb/test/API/python_api/global_module_cache/TestGlobalModuleCache.py
index 6bb22c46efb443..5b6e9e8a588a39 100644
--- a/lldb/test/API/python_api/global_module_cache/TestGlobalModuleCache.py
+++ b/lldb/test/API/python_api/global_module_cache/TestGlobalModuleCache.py
@@ -26,6 +26,13 @@ def copy_to_main(self, src, dst):
 # a previous build, so sleep a bit here to ensure that the touch is 
later.
 time.sleep(2)
 try:
+# Make sure dst is writeable before trying to write to it.
+subprocess.run(
+["chmod", "777", dst],
+stdin=None,
+capture_output=False,
+encoding="utf-8",
+)
 shutil.copy(src, dst)
 except:
 self.fail(f"Could not copy {src} to {dst}")



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


[Lldb-commits] [lldb] [LLDB] Fix write permission error in TestGlobalModuleCache.py (PR #76171)

2023-12-21 Thread Alex Langford via lldb-commits

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


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


[Lldb-commits] [lldb] [libc] [llvm] [compiler-rt] [clang] [flang] [libcxx] [clang-tools-extra] [openmp] [lld] [mlir] [libunwind] [OpenMP] Improve omp offload profiler (PR #68016)

2023-12-21 Thread Johannes Doerfert via lldb-commits

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

LG. Please rebase and merge.

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


[Lldb-commits] [lldb] [LLDB] Fix write permission error in TestGlobalModuleCache.py (PR #76171)

2023-12-21 Thread Jordan Rupprecht via lldb-commits

rupprecht wrote:

IIUC, the issue is that even though we are working in the build directory, 
which is writeable, we are copying a file from the source tree, which may be 
readonly, and those readonly permission bits persist when they're copied to the 
build directory.

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


[Lldb-commits] [lldb] [LLDB] Fix write permission error in TestGlobalModuleCache.py (PR #76171)

2023-12-21 Thread via lldb-commits

https://github.com/cmtice updated 
https://github.com/llvm/llvm-project/pull/76171

>From 74ac76e175917e0354d998b3b3fdc2b30bf9251b Mon Sep 17 00:00:00 2001
From: Caroline Tice 
Date: Thu, 21 Dec 2023 09:10:35 -0800
Subject: [PATCH 1/4] [LLDB] Fix write permission error in
 TestGlobalModuleCache.py

TestGlobalModuleCache.py, a recently added test, tries to update
a source file in the build directory, but it assumes the file is
writable. In our distributed build and test system, this is not
always true, so the test often fails with a write permissions error.

This change fixes that by setting the permissions on the file to
be writable before attempting to write to it.
---
 .../python_api/global_module_cache/TestGlobalModuleCache.py| 3 +++
 1 file changed, 3 insertions(+)

diff --git 
a/lldb/test/API/python_api/global_module_cache/TestGlobalModuleCache.py 
b/lldb/test/API/python_api/global_module_cache/TestGlobalModuleCache.py
index 6bb22c46efb443..02b77310b0067b 100644
--- a/lldb/test/API/python_api/global_module_cache/TestGlobalModuleCache.py
+++ b/lldb/test/API/python_api/global_module_cache/TestGlobalModuleCache.py
@@ -26,6 +26,9 @@ def copy_to_main(self, src, dst):
 # a previous build, so sleep a bit here to ensure that the touch is 
later.
 time.sleep(2)
 try:
+# Make sure dst is writeable before trying to write to it.
+subprocess.run(['chmod', '777', dst], stdin=None,
+   capture_output=False, encoding='utf-8')
 shutil.copy(src, dst)
 except:
 self.fail(f"Could not copy {src} to {dst}")

>From 1261639e6faae4e719d6e96c732ee56a1d3589bc Mon Sep 17 00:00:00 2001
From: Caroline Tice 
Date: Thu, 21 Dec 2023 09:34:40 -0800
Subject: [PATCH 2/4] [LLDB] Fix write permission error in
 TestGlobalModuleCache.py

Fix python formatting.
---
 .../global_module_cache/TestGlobalModuleCache.py  | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git 
a/lldb/test/API/python_api/global_module_cache/TestGlobalModuleCache.py 
b/lldb/test/API/python_api/global_module_cache/TestGlobalModuleCache.py
index 02b77310b0067b..3dea682dc6bdf6 100644
--- a/lldb/test/API/python_api/global_module_cache/TestGlobalModuleCache.py
+++ b/lldb/test/API/python_api/global_module_cache/TestGlobalModuleCache.py
@@ -27,8 +27,12 @@ def copy_to_main(self, src, dst):
 time.sleep(2)
 try:
 # Make sure dst is writeable before trying to write to it.
-subprocess.run(['chmod', '777', dst], stdin=None,
-   capture_output=False, encoding='utf-8')
+subprocess.run(
+['chmod', '777', dst],
+stdin=None,
+capture_output=False,
+encoding='utf-8'
+)
 shutil.copy(src, dst)
 except:
 self.fail(f"Could not copy {src} to {dst}")

>From 9ecbc8a2870133ec7ace24de0ff95629bc23b870 Mon Sep 17 00:00:00 2001
From: Caroline Tice 
Date: Thu, 21 Dec 2023 09:42:31 -0800
Subject: [PATCH 3/4] [LLDB] Fix write permission error in
 TestGlobalModuleCache.py

Fix python format issues.
---
 .../python_api/global_module_cache/TestGlobalModuleCache.py   | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git 
a/lldb/test/API/python_api/global_module_cache/TestGlobalModuleCache.py 
b/lldb/test/API/python_api/global_module_cache/TestGlobalModuleCache.py
index 3dea682dc6bdf6..5be7e43abbd274 100644
--- a/lldb/test/API/python_api/global_module_cache/TestGlobalModuleCache.py
+++ b/lldb/test/API/python_api/global_module_cache/TestGlobalModuleCache.py
@@ -28,10 +28,10 @@ def copy_to_main(self, src, dst):
 try:
 # Make sure dst is writeable before trying to write to it.
 subprocess.run(
-['chmod', '777', dst],
+["chmod", "777", dst],
 stdin=None,
 capture_output=False,
-encoding='utf-8'
+encoding="utf-8"
 )
 shutil.copy(src, dst)
 except:

>From 4010e9fccb6b34ba549a405789333d7c5a9433ba Mon Sep 17 00:00:00 2001
From: Caroline Tice 
Date: Thu, 21 Dec 2023 09:51:40 -0800
Subject: [PATCH 4/4] [LLDB] Fix write permission error in
 TestGlobalModuleCache.p

Fix python format.
---
 .../API/python_api/global_module_cache/TestGlobalModuleCache.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git 
a/lldb/test/API/python_api/global_module_cache/TestGlobalModuleCache.py 
b/lldb/test/API/python_api/global_module_cache/TestGlobalModuleCache.py
index 5be7e43abbd274..5b6e9e8a588a39 100644
--- a/lldb/test/API/python_api/global_module_cache/TestGlobalModuleCache.py
+++ b/lldb/test/API/python_api/global_module_cache/TestGlobalModuleCache.py
@@ -31,7 +31,7 @@ def copy_to_main(self, src, dst):
 ["chmod", "777", dst],
 stdin=None,
 capture_output=False,
-

[Lldb-commits] [lldb] [LLDB] Fix write permission error in TestGlobalModuleCache.py (PR #76171)

2023-12-21 Thread via lldb-commits

https://github.com/cmtice updated 
https://github.com/llvm/llvm-project/pull/76171

>From 74ac76e175917e0354d998b3b3fdc2b30bf9251b Mon Sep 17 00:00:00 2001
From: Caroline Tice 
Date: Thu, 21 Dec 2023 09:10:35 -0800
Subject: [PATCH 1/3] [LLDB] Fix write permission error in
 TestGlobalModuleCache.py

TestGlobalModuleCache.py, a recently added test, tries to update
a source file in the build directory, but it assumes the file is
writable. In our distributed build and test system, this is not
always true, so the test often fails with a write permissions error.

This change fixes that by setting the permissions on the file to
be writable before attempting to write to it.
---
 .../python_api/global_module_cache/TestGlobalModuleCache.py| 3 +++
 1 file changed, 3 insertions(+)

diff --git 
a/lldb/test/API/python_api/global_module_cache/TestGlobalModuleCache.py 
b/lldb/test/API/python_api/global_module_cache/TestGlobalModuleCache.py
index 6bb22c46efb443..02b77310b0067b 100644
--- a/lldb/test/API/python_api/global_module_cache/TestGlobalModuleCache.py
+++ b/lldb/test/API/python_api/global_module_cache/TestGlobalModuleCache.py
@@ -26,6 +26,9 @@ def copy_to_main(self, src, dst):
 # a previous build, so sleep a bit here to ensure that the touch is 
later.
 time.sleep(2)
 try:
+# Make sure dst is writeable before trying to write to it.
+subprocess.run(['chmod', '777', dst], stdin=None,
+   capture_output=False, encoding='utf-8')
 shutil.copy(src, dst)
 except:
 self.fail(f"Could not copy {src} to {dst}")

>From 1261639e6faae4e719d6e96c732ee56a1d3589bc Mon Sep 17 00:00:00 2001
From: Caroline Tice 
Date: Thu, 21 Dec 2023 09:34:40 -0800
Subject: [PATCH 2/3] [LLDB] Fix write permission error in
 TestGlobalModuleCache.py

Fix python formatting.
---
 .../global_module_cache/TestGlobalModuleCache.py  | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git 
a/lldb/test/API/python_api/global_module_cache/TestGlobalModuleCache.py 
b/lldb/test/API/python_api/global_module_cache/TestGlobalModuleCache.py
index 02b77310b0067b..3dea682dc6bdf6 100644
--- a/lldb/test/API/python_api/global_module_cache/TestGlobalModuleCache.py
+++ b/lldb/test/API/python_api/global_module_cache/TestGlobalModuleCache.py
@@ -27,8 +27,12 @@ def copy_to_main(self, src, dst):
 time.sleep(2)
 try:
 # Make sure dst is writeable before trying to write to it.
-subprocess.run(['chmod', '777', dst], stdin=None,
-   capture_output=False, encoding='utf-8')
+subprocess.run(
+['chmod', '777', dst],
+stdin=None,
+capture_output=False,
+encoding='utf-8'
+)
 shutil.copy(src, dst)
 except:
 self.fail(f"Could not copy {src} to {dst}")

>From 9ecbc8a2870133ec7ace24de0ff95629bc23b870 Mon Sep 17 00:00:00 2001
From: Caroline Tice 
Date: Thu, 21 Dec 2023 09:42:31 -0800
Subject: [PATCH 3/3] [LLDB] Fix write permission error in
 TestGlobalModuleCache.py

Fix python format issues.
---
 .../python_api/global_module_cache/TestGlobalModuleCache.py   | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git 
a/lldb/test/API/python_api/global_module_cache/TestGlobalModuleCache.py 
b/lldb/test/API/python_api/global_module_cache/TestGlobalModuleCache.py
index 3dea682dc6bdf6..5be7e43abbd274 100644
--- a/lldb/test/API/python_api/global_module_cache/TestGlobalModuleCache.py
+++ b/lldb/test/API/python_api/global_module_cache/TestGlobalModuleCache.py
@@ -28,10 +28,10 @@ def copy_to_main(self, src, dst):
 try:
 # Make sure dst is writeable before trying to write to it.
 subprocess.run(
-['chmod', '777', dst],
+["chmod", "777", dst],
 stdin=None,
 capture_output=False,
-encoding='utf-8'
+encoding="utf-8"
 )
 shutil.copy(src, dst)
 except:

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


[Lldb-commits] [lldb] [LLDB] Fix write permission error in TestGlobalModuleCache.py (PR #76171)

2023-12-21 Thread via lldb-commits

https://github.com/cmtice updated 
https://github.com/llvm/llvm-project/pull/76171

>From 74ac76e175917e0354d998b3b3fdc2b30bf9251b Mon Sep 17 00:00:00 2001
From: Caroline Tice 
Date: Thu, 21 Dec 2023 09:10:35 -0800
Subject: [PATCH 1/2] [LLDB] Fix write permission error in
 TestGlobalModuleCache.py

TestGlobalModuleCache.py, a recently added test, tries to update
a source file in the build directory, but it assumes the file is
writable. In our distributed build and test system, this is not
always true, so the test often fails with a write permissions error.

This change fixes that by setting the permissions on the file to
be writable before attempting to write to it.
---
 .../python_api/global_module_cache/TestGlobalModuleCache.py| 3 +++
 1 file changed, 3 insertions(+)

diff --git 
a/lldb/test/API/python_api/global_module_cache/TestGlobalModuleCache.py 
b/lldb/test/API/python_api/global_module_cache/TestGlobalModuleCache.py
index 6bb22c46efb443..02b77310b0067b 100644
--- a/lldb/test/API/python_api/global_module_cache/TestGlobalModuleCache.py
+++ b/lldb/test/API/python_api/global_module_cache/TestGlobalModuleCache.py
@@ -26,6 +26,9 @@ def copy_to_main(self, src, dst):
 # a previous build, so sleep a bit here to ensure that the touch is 
later.
 time.sleep(2)
 try:
+# Make sure dst is writeable before trying to write to it.
+subprocess.run(['chmod', '777', dst], stdin=None,
+   capture_output=False, encoding='utf-8')
 shutil.copy(src, dst)
 except:
 self.fail(f"Could not copy {src} to {dst}")

>From 1261639e6faae4e719d6e96c732ee56a1d3589bc Mon Sep 17 00:00:00 2001
From: Caroline Tice 
Date: Thu, 21 Dec 2023 09:34:40 -0800
Subject: [PATCH 2/2] [LLDB] Fix write permission error in
 TestGlobalModuleCache.py

Fix python formatting.
---
 .../global_module_cache/TestGlobalModuleCache.py  | 8 ++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git 
a/lldb/test/API/python_api/global_module_cache/TestGlobalModuleCache.py 
b/lldb/test/API/python_api/global_module_cache/TestGlobalModuleCache.py
index 02b77310b0067b..3dea682dc6bdf6 100644
--- a/lldb/test/API/python_api/global_module_cache/TestGlobalModuleCache.py
+++ b/lldb/test/API/python_api/global_module_cache/TestGlobalModuleCache.py
@@ -27,8 +27,12 @@ def copy_to_main(self, src, dst):
 time.sleep(2)
 try:
 # Make sure dst is writeable before trying to write to it.
-subprocess.run(['chmod', '777', dst], stdin=None,
-   capture_output=False, encoding='utf-8')
+subprocess.run(
+['chmod', '777', dst],
+stdin=None,
+capture_output=False,
+encoding='utf-8'
+)
 shutil.copy(src, dst)
 except:
 self.fail(f"Could not copy {src} to {dst}")

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


[Lldb-commits] [lldb] [LLDB] Fix write permission error in TestGlobalModuleCache.py (PR #76171)

2023-12-21 Thread via lldb-commits

github-actions[bot] wrote:




:warning: Python code formatter, darker found issues in your code. :warning:



You can test this locally with the following command:


``bash
darker --check --diff -r 
11140cc238b8c4124e6f9efacb1601f81da096a0...74ac76e175917e0354d998b3b3fdc2b30bf9251b
 lldb/test/API/python_api/global_module_cache/TestGlobalModuleCache.py
``





View the diff from darker here.


``diff
--- TestGlobalModuleCache.py2023-12-21 17:10:35.00 +
+++ TestGlobalModuleCache.py2023-12-21 17:32:04.533392 +
@@ -25,12 +25,16 @@
 # We are relying on the source file being newer than the .o file from
 # a previous build, so sleep a bit here to ensure that the touch is 
later.
 time.sleep(2)
 try:
 # Make sure dst is writeable before trying to write to it.
-subprocess.run(['chmod', '777', dst], stdin=None,
-   capture_output=False, encoding='utf-8')
+subprocess.run(
+["chmod", "777", dst],
+stdin=None,
+capture_output=False,
+encoding="utf-8",
+)
 shutil.copy(src, dst)
 except:
 self.fail(f"Could not copy {src} to {dst}")
 Path(dst).touch()
 

``




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


[Lldb-commits] [lldb] [LLDB] Fix write permission error in TestGlobalModuleCache.py (PR #76171)

2023-12-21 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: None (cmtice)


Changes

TestGlobalModuleCache.py, a recently added test, tries to update a source file 
in the build directory, but it assumes the file is writable. In our distributed 
build and test system, this is not always true, so the test often fails with a 
write permissions error.

This change fixes that by setting the permissions on the file to be writable 
before attempting to write to it.

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


1 Files Affected:

- (modified) 
lldb/test/API/python_api/global_module_cache/TestGlobalModuleCache.py (+3) 


``diff
diff --git 
a/lldb/test/API/python_api/global_module_cache/TestGlobalModuleCache.py 
b/lldb/test/API/python_api/global_module_cache/TestGlobalModuleCache.py
index 6bb22c46efb443..02b77310b0067b 100644
--- a/lldb/test/API/python_api/global_module_cache/TestGlobalModuleCache.py
+++ b/lldb/test/API/python_api/global_module_cache/TestGlobalModuleCache.py
@@ -26,6 +26,9 @@ def copy_to_main(self, src, dst):
 # a previous build, so sleep a bit here to ensure that the touch is 
later.
 time.sleep(2)
 try:
+# Make sure dst is writeable before trying to write to it.
+subprocess.run(['chmod', '777', dst], stdin=None,
+   capture_output=False, encoding='utf-8')
 shutil.copy(src, dst)
 except:
 self.fail(f"Could not copy {src} to {dst}")

``




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


[Lldb-commits] [lldb] [LLDB] Fix write permission error in TestGlobalModuleCache.py (PR #76171)

2023-12-21 Thread via lldb-commits

https://github.com/cmtice created 
https://github.com/llvm/llvm-project/pull/76171

TestGlobalModuleCache.py, a recently added test, tries to update a source file 
in the build directory, but it assumes the file is writable. In our distributed 
build and test system, this is not always true, so the test often fails with a 
write permissions error.

This change fixes that by setting the permissions on the file to be writable 
before attempting to write to it.

>From 74ac76e175917e0354d998b3b3fdc2b30bf9251b Mon Sep 17 00:00:00 2001
From: Caroline Tice 
Date: Thu, 21 Dec 2023 09:10:35 -0800
Subject: [PATCH] [LLDB] Fix write permission error in TestGlobalModuleCache.py

TestGlobalModuleCache.py, a recently added test, tries to update
a source file in the build directory, but it assumes the file is
writable. In our distributed build and test system, this is not
always true, so the test often fails with a write permissions error.

This change fixes that by setting the permissions on the file to
be writable before attempting to write to it.
---
 .../python_api/global_module_cache/TestGlobalModuleCache.py| 3 +++
 1 file changed, 3 insertions(+)

diff --git 
a/lldb/test/API/python_api/global_module_cache/TestGlobalModuleCache.py 
b/lldb/test/API/python_api/global_module_cache/TestGlobalModuleCache.py
index 6bb22c46efb443..02b77310b0067b 100644
--- a/lldb/test/API/python_api/global_module_cache/TestGlobalModuleCache.py
+++ b/lldb/test/API/python_api/global_module_cache/TestGlobalModuleCache.py
@@ -26,6 +26,9 @@ def copy_to_main(self, src, dst):
 # a previous build, so sleep a bit here to ensure that the touch is 
later.
 time.sleep(2)
 try:
+# Make sure dst is writeable before trying to write to it.
+subprocess.run(['chmod', '777', dst], stdin=None,
+   capture_output=False, encoding='utf-8')
 shutil.copy(src, dst)
 except:
 self.fail(f"Could not copy {src} to {dst}")

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


[Lldb-commits] [clang-tools-extra] [openmp] [libcxx] [llvm] [mlir] [flang] [clang] [lldb] [compiler-rt] [libc] [OpenMP] atomic compare fail : Codegen support (PR #75709)

2023-12-21 Thread via lldb-commits

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

>From fe931d64741f427629407bca3e68a61bec6f2b67 Mon Sep 17 00:00:00 2001
From: Sunil Kuravinakop 
Date: Sat, 16 Dec 2023 11:43:35 -0600
Subject: [PATCH 1/3] Adding parameter to fail clause (i.e. memory order
 clause) for codegen.

  Changes to be committed:
modified:   clang/lib/CodeGen/CGStmtOpenMP.cpp
---
 clang/lib/CodeGen/CGStmtOpenMP.cpp | 51 +++---
 1 file changed, 47 insertions(+), 4 deletions(-)

diff --git a/clang/lib/CodeGen/CGStmtOpenMP.cpp 
b/clang/lib/CodeGen/CGStmtOpenMP.cpp
index 478d6dbf9ca81d..a502db7ac3a5e0 100644
--- a/clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ b/clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -6516,10 +6516,6 @@ static void emitOMPAtomicExpr(CodeGenFunction , 
OpenMPClauseKind Kind,
  IsPostfixUpdate, IsFailOnly, Loc);
 break;
   }
-  case OMPC_fail: {
-//TODO
-break;
-  }
   default:
 llvm_unreachable("Clause is not allowed in 'omp atomic'.");
   }
@@ -6527,6 +6523,8 @@ static void emitOMPAtomicExpr(CodeGenFunction , 
OpenMPClauseKind Kind,
 
 void CodeGenFunction::EmitOMPAtomicDirective(const OMPAtomicDirective ) {
   llvm::AtomicOrdering AO = llvm::AtomicOrdering::Monotonic;
+  // Fail Memory Clause Ordering.
+  llvm::AtomicOrdering FO = llvm::AtomicOrdering::Monotonic;
   bool MemOrderingSpecified = false;
   if (S.getSingleClause()) {
 AO = llvm::AtomicOrdering::SequentiallyConsistent;
@@ -6580,6 +6578,51 @@ void CodeGenFunction::EmitOMPAtomicDirective(const 
OMPAtomicDirective ) {
 }
   }
 
+  if (KindsEncountered.contains(OMPC_compare) &&
+  KindsEncountered.contains(OMPC_fail)) {
+Kind = OMPC_compare;
+const OMPFailClause *fC = S.getSingleClause();
+if (fC) {
+  OpenMPClauseKind fP = fC->getFailParameter();
+  if (fP == llvm::omp::OMPC_relaxed)
+FO = llvm::AtomicOrdering::Monotonic;
+  else if (fP == llvm::omp::OMPC_acquire)
+FO = llvm::AtomicOrdering::Acquire;
+  else if (fP == llvm::omp::OMPC_seq_cst)
+FO = llvm::AtomicOrdering::SequentiallyConsistent;
+}
+
+// Logic for 2 memory order clauses in the atomic directive.
+// e.g. #pragma omp atomic compare capture release fail(seq_cst)
+//  if(x > e) { x = j; } else { k = x; }
+// To provide the Memory Order clause in atomic directive
+// there are 2 instructions in LLVM IR atomicrmw & cmpxchgl.
+// 1) atomicrmw can use only 1 memory order clause and can contain the
+//operator in if condition.
+// 2) cmpxchgl can use 2 memory order clauses : Success memory order clause
+//& fail parameter memory clause. However, cmpxchgl uses only equality
+//operator.
+// We need to change atomicrmw to contain the fail parameter clause or add
+// a new instruction in LLVM IR. Changes in LLVM IR need to be done
+// seperately and at present we will use the logic of using the more strict
+// memory order clause of success or fail memory order clauses for the
+// atomicrmw. The following logic takes care of this change in the memory
+// order clause.
+if (AO == llvm::AtomicOrdering::Monotonic)
+  AO = FO;
+else if (FO == llvm::AtomicOrdering::Monotonic)
+  AO = AO;
+else if (AO == llvm::AtomicOrdering::SequentiallyConsistent ||
+ FO == llvm::AtomicOrdering::SequentiallyConsistent)
+  AO = llvm::AtomicOrdering::SequentiallyConsistent;
+else if (AO == llvm::AtomicOrdering::Acquire)
+  AO = llvm::AtomicOrdering::Acquire;
+else if (AO == llvm::AtomicOrdering::Release)
+  AO = llvm::AtomicOrdering::AcquireRelease;
+else if (AO == llvm::AtomicOrdering::AcquireRelease)
+  AO = llvm::AtomicOrdering::AcquireRelease;
+  }
+
   LexicalScope Scope(*this, S.getSourceRange());
   EmitStopPoint(S.getAssociatedStmt());
   emitOMPAtomicExpr(*this, Kind, AO, S.isPostfixUpdate(), S.getX(), S.getV(),

>From 9cc33631c89c4fd4dce8a274fed700febe5dfa90 Mon Sep 17 00:00:00 2001
From: Sunil Kuravinakop 
Date: Tue, 19 Dec 2023 23:49:03 -0600
Subject: [PATCH 2/3] 1) Since the{if(x == e) {x = v;} else {d = x;}}
 results in generation of cmpxchg in the LLVM IR, the memory order clause in
 "fail" clause is now being added.In case of other operators ">" & "<"
 e.g.dx = dx > de ? de : dx; result in atomicrmw in the LLVM IR.
 "atomicrmw" can have only one memory order clause. Currently, the memory
 order clause is ignored. 2) Test cases for codegen 3) In SemaOpenMP.cpp,
 addedEncounteredAtomicKinds.contains(OMPC_compare) instead of AtomicKind
 == OMPC_compare. This was to accomodate where AtomicKind is OMPC_capture.

  Changes to be committed:
modified:   clang/lib/CodeGen/CGStmtOpenMP.cpp
modified:   clang/lib/Sema/SemaOpenMP.cpp
modified:   clang/test/OpenMP/atomic_compare_codegen.cpp
modified:   llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h

[Lldb-commits] [lldb] [lldb] enhance colorize process for image lookup command (PR #76112)

2023-12-21 Thread David Spickett via lldb-commits
=?utf-8?q?José?= L. Junior ,
=?utf-8?q?José?= L. Junior ,
=?utf-8?q?José?= L. Junior 
Message-ID:
In-Reply-To: 


DavidSpickett wrote:

Drive by comments since I am low on time, also I will be away until early 
January from today.

A general comment, please keep each PR to one thing. So I'd say making the 
highlight stuff into a struct is one PR, then adding function highlighting is 
another. Makes it easier to understand for everyone involved.

On tests for function highlighting, assuming we know that 
`PutCStringHighlighted` works (which we do), we don't need to repeat single 
match, multiple match, end of string match, etc. for functions as well. Just 
check that the parts of the output for functions have some sort of highlight in 
them. Use the simplest query that will achieve that.

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


[Lldb-commits] [lldb] [lldb] enhance colorize process for image lookup command (PR #76112)

2023-12-21 Thread David Spickett via lldb-commits
=?utf-8?q?José?= L. Junior ,
=?utf-8?q?José?= L. Junior ,
=?utf-8?q?José?= L. Junior 
Message-ID:
In-Reply-To: 



@@ -72,23 +72,21 @@ size_t Stream::PutCString(llvm::StringRef str) {
   return bytes_written;
 }
 
-void Stream::PutCStringColorHighlighted(llvm::StringRef text,
-llvm::StringRef pattern,
-llvm::StringRef prefix,
-llvm::StringRef suffix) {
-  // Only apply color formatting when a pattern is present and both prefix and
-  // suffix are specified. In the absence of these conditions, output the text
-  // without color formatting.
-  if (pattern.empty() || (prefix.empty() && suffix.empty())) {
+void Stream::PutCStringColorHighlighted(
+llvm::StringRef text, std::optional pattern_info) {
+  // Only apply color formatting when the pattern information is specified.
+  // Otherwise, output the text without color formatting.
+  if (!pattern_info.has_value()) {
 PutCString(text);
 return;
   }
 
-  llvm::Regex reg_pattern(pattern);
+  llvm::Regex reg_pattern(pattern_info.value().pattern);

DavidSpickett wrote:

Which can be cleaner, is my point, `value()` vs. `->`.

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


[Lldb-commits] [lldb] [lldb] enhance colorize process for image lookup command (PR #76112)

2023-12-21 Thread David Spickett via lldb-commits
=?utf-8?q?José?= L. Junior ,
=?utf-8?q?José?= L. Junior ,
=?utf-8?q?José?= L. Junior 
Message-ID:
In-Reply-To: 



@@ -23,6 +23,16 @@
 
 namespace lldb_private {
 
+struct Information {

DavidSpickett wrote:

This should be within the Stream class.

Also the name is too generic, `HighlightSettings` maybe? Choosing a name is 
hard but something that says what the information is about.

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


[Lldb-commits] [lldb] [lldb] enhance colorize process for image lookup command (PR #76112)

2023-12-21 Thread David Spickett via lldb-commits
=?utf-8?q?José?= L. Junior ,
=?utf-8?q?José?= L. Junior ,
=?utf-8?q?José?= L. Junior 
Message-ID:
In-Reply-To: 



@@ -1609,6 +1612,11 @@ static uint32_t LookupSymbolInModule(CommandInterpreter 
,
   }
 
   if (num_matches > 0) {
+llvm::StringRef ansi_prefix =
+interpreter.GetDebugger().GetRegexMatchAnsiPrefix();
+llvm::StringRef ansi_suffix =
+interpreter.GetDebugger().GetRegexMatchAnsiSuffix();
+Information info(name, ansi_prefix, ansi_suffix);

DavidSpickett wrote:

Construct this closer to the place of use, also inline the `GetRegex...` calls 
into it like `info(...GetRegexMatch...())`.

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


[Lldb-commits] [lldb] [lldb] enhance colorize process for image lookup command (PR #76112)

2023-12-21 Thread David Spickett via lldb-commits
=?utf-8?q?José?= L. Junior ,
=?utf-8?q?José?= L. Junior ,
=?utf-8?q?José?= L. Junior 
Message-ID:
In-Reply-To: 



@@ -72,23 +72,21 @@ size_t Stream::PutCString(llvm::StringRef str) {
   return bytes_written;
 }
 
-void Stream::PutCStringColorHighlighted(llvm::StringRef text,
-llvm::StringRef pattern,
-llvm::StringRef prefix,
-llvm::StringRef suffix) {
-  // Only apply color formatting when a pattern is present and both prefix and
-  // suffix are specified. In the absence of these conditions, output the text
-  // without color formatting.
-  if (pattern.empty() || (prefix.empty() && suffix.empty())) {
+void Stream::PutCStringColorHighlighted(
+llvm::StringRef text, std::optional pattern_info) {
+  // Only apply color formatting when the pattern information is specified.
+  // Otherwise, output the text without color formatting.
+  if (!pattern_info.has_value()) {
 PutCString(text);
 return;
   }
 
-  llvm::Regex reg_pattern(pattern);
+  llvm::Regex reg_pattern(pattern_info.value().pattern);

DavidSpickett wrote:

This isn't wrong but you can instead do:
```
pattern_info->pattern
```
Pointer like operations on optionals accessed the contained value.

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


[Lldb-commits] [lldb] [lldb] enhance colorize process for image lookup command (PR #76112)

2023-12-21 Thread David Spickett via lldb-commits
=?utf-8?q?José?= L. Junior ,
=?utf-8?q?José?= L. Junior ,
=?utf-8?q?José?= L. Junior 
Message-ID:
In-Reply-To: 



@@ -262,14 +263,12 @@ void Symbol::GetDescription(Stream *s, 
lldb::DescriptionLevel level,
   }
   if (ConstString demangled = m_mangled.GetDemangledName()) {
 s->PutCString(", name=\"");
-s->PutCStringColorHighlighted(demangled.GetStringRef(), pattern,
-  ansi_prefix, ansi_suffix);
+s->PutCStringColorHighlighted(demangled.GetStringRef(), pattern_info);
 s->PutCString("\"");
   }
   if (ConstString mangled_name = m_mangled.GetMangledName()) {
 s->PutCString(", mangled=\"");
-s->PutCStringColorHighlighted(mangled_name.GetStringRef(), pattern,
-  ansi_prefix, ansi_suffix);
+s->PutCStringColorHighlighted(mangled_name.GetStringRef(), pattern_info);

DavidSpickett wrote:

The name `pattern_info` for a local variable is fine I think, the name of the 
type bothers me more.

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


[Lldb-commits] [lldb] [llvm] [mlir] [openmp] [libc] [flang] [clang] [AMDGPU] GFX12 global_atomic_ordered_add_b64 instruction and intrinsic (PR #76149)

2023-12-21 Thread Jay Foad via lldb-commits

https://github.com/jayfoad updated 
https://github.com/llvm/llvm-project/pull/76149

>From b14a554a15e4de88c9afc428f9c6898090e6eb23 Mon Sep 17 00:00:00 2001
From: Jay Foad 
Date: Thu, 21 Dec 2023 12:00:26 +
Subject: [PATCH] [AMDGPU] GFX12 global_atomic_ordered_add_b64 instruction and
 intrinsic

---
 llvm/include/llvm/IR/IntrinsicsAMDGPU.td  | 10 ++-
 llvm/lib/Target/AMDGPU/AMDGPUInstructions.td  |  1 +
 .../Target/AMDGPU/AMDGPURegisterBankInfo.cpp  |  1 +
 .../Target/AMDGPU/AMDGPUSearchableTables.td   |  1 +
 llvm/lib/Target/AMDGPU/FLATInstructions.td| 11 +++-
 llvm/lib/Target/AMDGPU/SIISelLowering.cpp |  1 +
 ...vm.amdgcn.global.atomic.ordered.add.b64.ll | 65 +++
 llvm/test/MC/AMDGPU/gfx11_unsupported.s   |  3 +
 llvm/test/MC/AMDGPU/gfx12_asm_vflat.s | 24 +++
 .../Disassembler/AMDGPU/gfx12_dasm_vflat.txt  | 12 
 10 files changed, 124 insertions(+), 5 deletions(-)
 create mode 100644 
llvm/test/CodeGen/AMDGPU/llvm.amdgcn.global.atomic.ordered.add.b64.ll

diff --git a/llvm/include/llvm/IR/IntrinsicsAMDGPU.td 
b/llvm/include/llvm/IR/IntrinsicsAMDGPU.td
index 51bd9b63c127ed..3985c8871e1615 100644
--- a/llvm/include/llvm/IR/IntrinsicsAMDGPU.td
+++ b/llvm/include/llvm/IR/IntrinsicsAMDGPU.td
@@ -10,6 +10,8 @@
 //
 
//===--===//
 
+def global_ptr_ty : LLVMQualPointerType<1>;
+
 class AMDGPUReadPreloadRegisterIntrinsic
   : DefaultAttrsIntrinsic<[llvm_i32_ty], [], [IntrNoMem, IntrSpeculatable]>;
 
@@ -2353,10 +2355,10 @@ def int_amdgcn_s_get_waveid_in_workgroup :
   Intrinsic<[llvm_i32_ty], [],
 [IntrNoMem, IntrHasSideEffects, IntrWillReturn, IntrNoCallback, 
IntrNoFree]>;
 
-class AMDGPUGlobalAtomicRtn : Intrinsic <
+class AMDGPUGlobalAtomicRtn : 
Intrinsic <
   [vt],
-  [llvm_anyptr_ty,// vaddr
-   vt],   // vdata(VGPR)
+  [pt,  // vaddr
+   vt], // vdata(VGPR)
   [IntrArgMemOnly, IntrWillReturn, NoCapture>, IntrNoCallback, 
IntrNoFree], "",
   [SDNPMemOperand]>;
 
@@ -2486,6 +2488,8 @@ def int_amdgcn_permlanex16_var : 
ClangBuiltin<"__builtin_amdgcn_permlanex16_var"
 [IntrNoMem, IntrConvergent, IntrWillReturn,
  ImmArg>, ImmArg>, IntrNoCallback, 
IntrNoFree]>;
 
+def int_amdgcn_global_atomic_ordered_add_b64 : 
AMDGPUGlobalAtomicRtn;
+
 def int_amdgcn_flat_atomic_fmin_num   : 
AMDGPUGlobalAtomicRtn;
 def int_amdgcn_flat_atomic_fmax_num   : 
AMDGPUGlobalAtomicRtn;
 def int_amdgcn_global_atomic_fmin_num : 
AMDGPUGlobalAtomicRtn;
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUInstructions.td 
b/llvm/lib/Target/AMDGPU/AMDGPUInstructions.td
index eaf72d7157ee2d..36e07d944c942c 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUInstructions.td
+++ b/llvm/lib/Target/AMDGPU/AMDGPUInstructions.td
@@ -642,6 +642,7 @@ defm int_amdgcn_global_atomic_fmax : noret_op;
 defm int_amdgcn_global_atomic_csub : noret_op;
 defm int_amdgcn_flat_atomic_fadd : local_addr_space_atomic_op;
 defm int_amdgcn_ds_fadd_v2bf16 : noret_op;
+defm int_amdgcn_global_atomic_ordered_add_b64 : noret_op;
 defm int_amdgcn_flat_atomic_fmin_num : noret_op;
 defm int_amdgcn_flat_atomic_fmax_num : noret_op;
 defm int_amdgcn_global_atomic_fmin_num : noret_op;
diff --git a/llvm/lib/Target/AMDGPU/AMDGPURegisterBankInfo.cpp 
b/llvm/lib/Target/AMDGPU/AMDGPURegisterBankInfo.cpp
index c9412f720c62ec..fba060464a6e74 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPURegisterBankInfo.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPURegisterBankInfo.cpp
@@ -4690,6 +4690,7 @@ AMDGPURegisterBankInfo::getInstrMapping(const 
MachineInstr ) const {
 case Intrinsic::amdgcn_flat_atomic_fmax_num:
 case Intrinsic::amdgcn_global_atomic_fadd_v2bf16:
 case Intrinsic::amdgcn_flat_atomic_fadd_v2bf16:
+case Intrinsic::amdgcn_global_atomic_ordered_add_b64:
   return getDefaultMappingAllVGPR(MI);
 case Intrinsic::amdgcn_ds_ordered_add:
 case Intrinsic::amdgcn_ds_ordered_swap:
diff --git a/llvm/lib/Target/AMDGPU/AMDGPUSearchableTables.td 
b/llvm/lib/Target/AMDGPU/AMDGPUSearchableTables.td
index beb670669581f1..4cc8871a00fe1f 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPUSearchableTables.td
+++ b/llvm/lib/Target/AMDGPU/AMDGPUSearchableTables.td
@@ -243,6 +243,7 @@ def : SourceOfDivergence;
 def : SourceOfDivergence;
 def : SourceOfDivergence;
 def : SourceOfDivergence;
+def : SourceOfDivergence;
 def : SourceOfDivergence;
 def : SourceOfDivergence;
 def : SourceOfDivergence;
diff --git a/llvm/lib/Target/AMDGPU/FLATInstructions.td 
b/llvm/lib/Target/AMDGPU/FLATInstructions.td
index 0dd2b3f5c2c912..615f8cd54d8f9c 100644
--- a/llvm/lib/Target/AMDGPU/FLATInstructions.td
+++ b/llvm/lib/Target/AMDGPU/FLATInstructions.td
@@ -926,9 +926,11 @@ defm GLOBAL_LOAD_LDS_USHORT : FLAT_Global_Load_LDS_Pseudo 
<"global_load_lds_usho
 defm GLOBAL_LOAD_LDS_SSHORT : FLAT_Global_Load_LDS_Pseudo 
<"global_load_lds_sshort">;
 defm GLOBAL_LOAD_LDS_DWORD  : FLAT_Global_Load_LDS_Pseudo 
<"global_load_lds_dword">;
 
-} // End is_flat_global = 1
-
+let 

[Lldb-commits] [lldb] [LLDB] Define _BSD_SOURCE globally, to get optreset available in mingw's getopt.h (PR #76137)

2023-12-21 Thread David Spickett via lldb-commits


@@ -44,6 +44,10 @@ endif()
 
 if (WIN32)
   add_definitions(-D_ENABLE_EXTENDED_ALIGNED_STORAGE)
+  if (NOT MSVC)

DavidSpickett wrote:

Defining `_BSD_SOURCE` is probably not changing anything on our existing 
clang-cl Windows on Arm build then. This will just remove a define we never 
needed there, as you said.

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


[Lldb-commits] [lldb] f54249e - [lldb][test] Link to PlatformWindows in thread tests

2023-12-21 Thread David Spickett via lldb-commits

Author: David Spickett
Date: 2023-12-21T14:07:27Z
New Revision: f54249e79a507f4bfeaa9ce3f693dbe01c9af915

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

LOG: [lldb][test] Link to PlatformWindows in thread tests

Clearly I need my eyes checked, it wasn't linking to a non-existent
library at all, I had the name wrong.

Added: 


Modified: 
lldb/unittests/Thread/CMakeLists.txt

Removed: 




diff  --git a/lldb/unittests/Thread/CMakeLists.txt 
b/lldb/unittests/Thread/CMakeLists.txt
index 2b771d3cd309f7..8fc44da6f5b395 100644
--- a/lldb/unittests/Thread/CMakeLists.txt
+++ b/lldb/unittests/Thread/CMakeLists.txt
@@ -1,4 +1,5 @@
 if (CMAKE_SYSTEM_NAME MATCHES "Windows")
+  list(APPEND LLDB_WINDOWS_LIBS lldbPluginPlatformWindows)
   list(APPEND LLDB_WINDOWS_LIBS lldbPluginProcessWindowsCommon)
 endif()
 



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


[Lldb-commits] [lldb] 55985db - [lldb][test] Remove non-existent Windows lib from thread tests

2023-12-21 Thread David Spickett via lldb-commits

Author: David Spickett
Date: 2023-12-21T14:05:08Z
New Revision: 55985db5fe82705234370848c47575db7a16437e

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

LOG: [lldb][test] Remove non-existent Windows lib from thread tests

I assumed since it was in the PR and seemed like a logical
library to have, it would exist, but only `...Common` exists.

Added: 


Modified: 
lldb/unittests/Thread/CMakeLists.txt

Removed: 




diff  --git a/lldb/unittests/Thread/CMakeLists.txt 
b/lldb/unittests/Thread/CMakeLists.txt
index a90643eb0c110e..2b771d3cd309f7 100644
--- a/lldb/unittests/Thread/CMakeLists.txt
+++ b/lldb/unittests/Thread/CMakeLists.txt
@@ -1,5 +1,4 @@
 if (CMAKE_SYSTEM_NAME MATCHES "Windows")
-  list(APPEND LLDB_WINDOWS_LIBS lldbPluginProcessWindows)
   list(APPEND LLDB_WINDOWS_LIBS lldbPluginProcessWindowsCommon)
 endif()
 



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


[Lldb-commits] [lldb] [LLDB] Define _BSD_SOURCE globally, to get optreset available in mingw's getopt.h (PR #76137)

2023-12-21 Thread Saleem Abdulrasool via lldb-commits


@@ -44,6 +44,10 @@ endif()
 
 if (WIN32)
   add_definitions(-D_ENABLE_EXTENDED_ALIGNED_STORAGE)
+  if (NOT MSVC)

compnerd wrote:

clang-cl should be detected as MSVC.  The define should be generally safe, but 
it is nice to be more precise and add it when needed.

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


[Lldb-commits] [clang] [compiler-rt] [clang-tools-extra] [mlir] [libunwind] [libcxxabi] [llvm] [lldb] [libcxx] [flang] [lld] [libc] [asan] Install `pthread_atfork` (PR #75290)

2023-12-21 Thread Rainer Orth via lldb-commits

rorth wrote:

> I'll give such a patch a try...

That would be something like
```
int internal_fork(void) {
  // Call syscall directly to avoid pthread_atfork handler processing.
  //
  // This is highly unportable on Solaris since syscalls are an implementation
  // detail subject to change.
  return syscall(SYS_forksys, 0, 0);
}
```
Unfortunately, this fails miserably: at least every asan test that invokes the 
`llvm-symbolizer` fails like
```
==4030==Launching Symbolizer process: /usr/bin/llvm-symbolizer --demangle 
--inlines --default-arch=i386 
==4031==Waiting on the process failed (errno 10).
==4031==WARNING: external symbolizer didn't start up correctly!
```
>From all I could learn from the OpenSolaris `libc` code 
>(`lib/libc/port/threads/scalls.c` (`forkx`), it seems that there happens so 
>much processing on `libc`-internal data structures that cannot simply be 
>skipped that there's no reasonable chance to run `fork` without the handlers.  
>Expecting to be able to seems to be hack that may work on some platforms, but 
>not on others.

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


[Lldb-commits] [lldb] [lldb] add support for thread names on Windows (PR #74731)

2023-12-21 Thread David Spickett via lldb-commits

DavidSpickett wrote:

Everything passed on Windows 
(https://lab.llvm.org/buildbot/#/builders/219/builds/7700) and the rest of the 
lldb specific bots are green. You may get a few more messages as other builders 
get to it (the Mac ones mainly), if it's a link error with 
`lldbPluginProcessWindowsCommon` then it's already been fixed and you can 
ignore it.

If you do miss a failure for a while, someone like me will deal with it or ping 
you about it here.

Thanks for the contribution!

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


[Lldb-commits] [lldb] [LLDB] Define _BSD_SOURCE globally, to get optreset available in mingw's getopt.h (PR #76137)

2023-12-21 Thread David Spickett via lldb-commits

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

LGTM, bot might fail but only one way to find out.

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


[Lldb-commits] [lldb] [LLDB] Define _BSD_SOURCE globally, to get optreset available in mingw's getopt.h (PR #76137)

2023-12-21 Thread David Spickett via lldb-commits


@@ -44,6 +44,10 @@ endif()
 
 if (WIN32)
   add_definitions(-D_ENABLE_EXTENDED_ALIGNED_STORAGE)
+  if (NOT MSVC)

DavidSpickett wrote:

Do we want this msvc check?

Our Windows on Arm buildbot is using clang-cl, not sure if it'll hit this path. 
No harm in landing this and finding out though.

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


[Lldb-commits] [lldb] [lldb] add support for thread names on Windows (PR #74731)

2023-12-21 Thread via lldb-commits

oltolm wrote:

Thank you David, I didn't see a button for merging the PR.

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


[Lldb-commits] [lldb] dddb9d1 - [lldb][test] Fix missing-braces warnings in unit tests

2023-12-21 Thread David Spickett via lldb-commits

Author: David Spickett
Date: 2023-12-21T13:36:04Z
New Revision: dddb9d1ee3e283133ce1abb50b7c7a3715317b9d

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

LOG: [lldb][test] Fix missing-braces warnings in unit tests

```
/home/worker/2.0.1/lldb-x86_64-debian/llvm-project/lldb/unittests/Utility/ChecksumTest.cpp:15:38:
 warning: suggest braces around initialization of subobject [-Wmissing-braces]
static llvm::MD5::MD5Result hash1 = {0, 1, 2,  3,  4,  5,  6,  7,
 ^~~~
 {
```
And others.

Added: 


Modified: 
lldb/unittests/Utility/ChecksumTest.cpp
lldb/unittests/Utility/FileSpecTest.cpp

Removed: 




diff  --git a/lldb/unittests/Utility/ChecksumTest.cpp 
b/lldb/unittests/Utility/ChecksumTest.cpp
index 7537d30b5ff5b8..a81aba2ee98ca1 100644
--- a/lldb/unittests/Utility/ChecksumTest.cpp
+++ b/lldb/unittests/Utility/ChecksumTest.cpp
@@ -12,14 +12,14 @@
 
 using namespace lldb_private;
 
-static llvm::MD5::MD5Result hash1 = {0, 1, 2,  3,  4,  5,  6,  7,
- 8, 9, 10, 11, 12, 13, 14, 15};
+static llvm::MD5::MD5Result hash1 = {
+{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}};
 
-static llvm::MD5::MD5Result hash2 = {0, 1, 2,  3,  4,  5,  6,  7,
- 8, 9, 10, 11, 12, 13, 14, 15};
+static llvm::MD5::MD5Result hash2 = {
+{0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}};
 
-static llvm::MD5::MD5Result hash3 = {8, 9, 10, 11, 12, 13, 14, 15,
- 0, 1, 2,  3,  4,  5,  6,  7};
+static llvm::MD5::MD5Result hash3 = {
+{8, 9, 10, 11, 12, 13, 14, 15, 0, 1, 2, 3, 4, 5, 6, 7}};
 
 TEST(ChecksumTest, TestConstructor) {
   Checksum checksum1;

diff  --git a/lldb/unittests/Utility/FileSpecTest.cpp 
b/lldb/unittests/Utility/FileSpecTest.cpp
index 565395a495be60..9faad10e47301a 100644
--- a/lldb/unittests/Utility/FileSpecTest.cpp
+++ b/lldb/unittests/Utility/FileSpecTest.cpp
@@ -536,7 +536,8 @@ TEST(FileSpecTest, TestGetComponents) {
 }
 
 TEST(FileSpecTest, TestChecksum) {
-  Checksum checksum({0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15});
+  Checksum checksum(llvm::MD5::MD5Result{
+  {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15}});
   FileSpec file_spec("/foo/bar", FileSpec::Style::posix, checksum);
   EXPECT_TRUE(static_cast(file_spec.GetChecksum()));
   EXPECT_EQ(file_spec.GetChecksum(), checksum);



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


[Lldb-commits] [lldb] [lldb] add support for thread names on Windows (PR #74731)

2023-12-21 Thread David Spickett via lldb-commits

DavidSpickett wrote:

You'll have email from at least one Linux builder. I believe I've fixed that 
link error with: 
https://github.com/llvm/llvm-project/commit/513c2151cd0cddd90af91a6614b15b74b538963e

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


[Lldb-commits] [lldb] 513c215 - [lldb][test] Only link Windows libraries on Windows

2023-12-21 Thread David Spickett via lldb-commits

Author: David Spickett
Date: 2023-12-21T13:11:34Z
New Revision: 513c2151cd0cddd90af91a6614b15b74b538963e

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

LOG: [lldb][test] Only link Windows libraries on Windows

ld.lld: error: unable to find library -llldbPluginProcessWindowsCommon

https://lab.llvm.org/buildbot/#/builders/96/builds/50407

Fixes 95e5839e06fdffd278499257c6e7679bba3d6868.

Added: 


Modified: 
lldb/unittests/Thread/CMakeLists.txt

Removed: 




diff  --git a/lldb/unittests/Thread/CMakeLists.txt 
b/lldb/unittests/Thread/CMakeLists.txt
index f6c8795f349a5e..a90643eb0c110e 100644
--- a/lldb/unittests/Thread/CMakeLists.txt
+++ b/lldb/unittests/Thread/CMakeLists.txt
@@ -1,3 +1,8 @@
+if (CMAKE_SYSTEM_NAME MATCHES "Windows")
+  list(APPEND LLDB_WINDOWS_LIBS lldbPluginProcessWindows)
+  list(APPEND LLDB_WINDOWS_LIBS lldbPluginProcessWindowsCommon)
+endif()
+
 add_lldb_unittest(ThreadTests
   ThreadTest.cpp
 
@@ -11,7 +16,6 @@ add_lldb_unittest(ThreadTests
   lldbInterpreter
   lldbBreakpoint
   lldbPluginPlatformLinux
-  lldbPluginPlatformWindows
-  lldbPluginProcessWindowsCommon
+  ${LLDB_WINDOWS_LIBS}
   )
 



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


[Lldb-commits] [libcxx] [llvm] [clang] [flang] [mlir] [lld] [clang-tools-extra] [libc] [lldb] [compiler-rt] Don't emit relax relocs like R_X86_64_REX_GOTPCRELX on X86 target for OPENMP internal vars.

2023-12-21 Thread via lldb-commits

https://github.com/UmeshKalappa0 updated 
https://github.com/llvm/llvm-project/pull/75564

>From 4125e4a709c594562fa6c52f045ba7442e3cb523 Mon Sep 17 00:00:00 2001
From: Umesh Kalappa 
Date: Fri, 15 Dec 2023 11:52:52 +0530
Subject: [PATCH 1/4] Problem :For Kernel Modules ,emitting the relocs like
 R_X86_64_REX_GOTPCRELX  for the OPENMP internal vars like
 https://godbolt.org/z/hhh7ozojz.

Solution : Mark the OpenMP internal variables with dso_local
conditionally for no-pic and no-pie ,then
a)reset the dso_local for thread_local and weak linkage vars.
---
 .../test/OpenMP/gomp_critical_dso_local_var.c | 23 +++
 1 file changed, 23 insertions(+)
 create mode 100644 clang/test/OpenMP/gomp_critical_dso_local_var.c

diff --git a/clang/test/OpenMP/gomp_critical_dso_local_var.c 
b/clang/test/OpenMP/gomp_critical_dso_local_var.c
new file mode 100644
index 00..915f6773bf67bf
--- /dev/null
+++ b/clang/test/OpenMP/gomp_critical_dso_local_var.c
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -fopenmp -x c -emit-llvm %s -o - | FileCheck %s 
--check-prefix=DSO_LOCAL
+
+// DSO_LOCAL-DAG: @.gomp_critical_user_.var = common dso_local global [8 x 
i32] zeroinitializer, align 8
+int omp_critical_test()
+{
+  int sum;
+  int known_sum;
+
+  sum=0;
+#pragma omp parallel
+  {
+int mysum=0;
+int i;
+#pragma omp for
+for (i = 0; i < 1000; i++)
+  mysum = mysum + i;
+#pragma omp critical
+sum = mysum +sum;
+  }
+  known_sum = 999 * 1000 / 2;
+  return (known_sum == sum);
+}
+

>From 842245de490ab15f8a901b94576ae4539c760e1e Mon Sep 17 00:00:00 2001
From: Umesh Kalappa 
Date: Fri, 15 Dec 2023 12:49:48 +0530
Subject: [PATCH 2/4] testcases are changed accordignly.

---
 clang/lib/CodeGen/CGOpenMPRuntime.cpp   | 2 ++
 clang/test/OpenMP/critical_codegen.cpp  | 6 +++---
 clang/test/OpenMP/critical_codegen_attr.cpp | 6 +++---
 clang/test/OpenMP/for_reduction_codegen.cpp | 8 
 clang/test/OpenMP/gomp_critical_dso_local_var.c | 1 -
 clang/test/OpenMP/simd_codegen.cpp  | 4 ++--
 llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp   | 8 
 7 files changed, 22 insertions(+), 13 deletions(-)

diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index 7f7e6f53066644..183c757d72b8a7 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -1793,6 +1793,8 @@ Address 
CGOpenMPRuntime::getAddrOfArtificialThreadPrivate(CodeGenFunction ,
   if (CGM.getLangOpts().OpenMP && CGM.getLangOpts().OpenMPUseTLS &&
   CGM.getTarget().isTLSSupported()) {
 GAddr->setThreadLocal(/*Val=*/true);
+/// reset the dso_local for thread_local.
+GAddr->setDSOLocal(/*Val=*/false);
 return Address(GAddr, GAddr->getValueType(),
CGM.getContext().getTypeAlignInChars(VarType));
   }
diff --git a/clang/test/OpenMP/critical_codegen.cpp 
b/clang/test/OpenMP/critical_codegen.cpp
index 24145d44d962e5..9a613161ac294a 100644
--- a/clang/test/OpenMP/critical_codegen.cpp
+++ b/clang/test/OpenMP/critical_codegen.cpp
@@ -16,9 +16,9 @@
 #define HEADER
 
 // ALL:   [[IDENT_T_TY:%.+]] = type { i32, i32, i32, i32, ptr }
-// ALL:   [[UNNAMED_LOCK:@.+]] = common global [8 x i32] zeroinitializer
-// ALL:   [[THE_NAME_LOCK:@.+]] = common global [8 x i32] zeroinitializer
-// ALL:   [[THE_NAME_LOCK1:@.+]] = common global [8 x i32] zeroinitializer
+// ALL:   [[UNNAMED_LOCK:@.+]] = common dso_local global [8 x i32] 
zeroinitializer
+// ALL:   [[THE_NAME_LOCK:@.+]] = common dso_local global [8 x i32] 
zeroinitializer
+// ALL:   [[THE_NAME_LOCK1:@.+]] = common dso_local global [8 x i32] 
zeroinitializer
 
 // ALL:   define {{.*}}void [[FOO:@.+]]()
 
diff --git a/clang/test/OpenMP/critical_codegen_attr.cpp 
b/clang/test/OpenMP/critical_codegen_attr.cpp
index 34d90a9e3a6e48..5f1a76e2ad0f1f 100644
--- a/clang/test/OpenMP/critical_codegen_attr.cpp
+++ b/clang/test/OpenMP/critical_codegen_attr.cpp
@@ -16,9 +16,9 @@
 #define HEADER
 
 // ALL:   [[IDENT_T_TY:%.+]] = type { i32, i32, i32, i32, ptr }
-// ALL:   [[UNNAMED_LOCK:@.+]] = common global [8 x i32] zeroinitializer
-// ALL:   [[THE_NAME_LOCK:@.+]] = common global [8 x i32] zeroinitializer
-// ALL:   [[THE_NAME_LOCK1:@.+]] = common global [8 x i32] zeroinitializer
+// ALL:   [[UNNAMED_LOCK:@.+]] = common dso_local global [8 x i32] 
zeroinitializer
+// ALL:   [[THE_NAME_LOCK:@.+]] = common dso_local global [8 x i32] 
zeroinitializer
+// ALL:   [[THE_NAME_LOCK1:@.+]] = common dso_local global [8 x i32] 
zeroinitializer
 
 // ALL:   define {{.*}}void [[FOO:@.+]]()
 
diff --git a/clang/test/OpenMP/for_reduction_codegen.cpp 
b/clang/test/OpenMP/for_reduction_codegen.cpp
index 893c606f8d7b9f..b128bd5d79c251 100644
--- a/clang/test/OpenMP/for_reduction_codegen.cpp
+++ b/clang/test/OpenMP/for_reduction_codegen.cpp
@@ -528,12 +528,12 @@ int main() {
 
 #endif
 //.
-// CHECK1: 

[Lldb-commits] [lldb] [lldb] add support for thread names on Windows (PR #74731)

2023-12-21 Thread David Spickett via lldb-commits

DavidSpickett wrote:

If you have permissions, once a PR is approved you can click "squash and merge" 
to land it. I've gone ahead and done that for you in this time.

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


[Lldb-commits] [lldb] [lldb] add support for thread names on Windows (PR #74731)

2023-12-21 Thread David Spickett via lldb-commits

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


[Lldb-commits] [lldb] 95e5839 - [lldb] add support for thread names on Windows (#74731)

2023-12-21 Thread via lldb-commits

Author: oltolm
Date: 2023-12-21T12:42:22Z
New Revision: 95e5839e06fdffd278499257c6e7679bba3d6868

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

LOG: [lldb] add support for thread names on Windows (#74731)

This PR adds support for thread names in lldb on Windows.

```
(lldb) thr list
Process 2960 stopped
  thread #53: tid = 0x03a0, 0x7ff84582db34 
ntdll.dll`NtWaitForMultipleObjects + 20
  thread #29: tid = 0x04ec, 0x7ff845830a14 
ntdll.dll`NtWaitForAlertByThreadId + 20, name = 'SPUW.6'
  thread #89: tid = 0x057c, 0x7ff845830a14 
ntdll.dll`NtWaitForAlertByThreadId + 20, name = 'PPU[0x119] physics[main]'
  thread #3: tid = 0x0648, 0x7ff843c2cafe 
combase.dll`InternalDoATClassCreate + 39518
  thread #93: tid = 0x0688, 0x7ff845830a14 
ntdll.dll`NtWaitForAlertByThreadId + 20, name = 'PPU[0x100501d] 
uMovie::StreamingThread'
  thread #1: tid = 0x087c, 0x7ff842e7a104 
win32u.dll`NtUserMsgWaitForMultipleObjectsEx + 20
  thread #96: tid = 0x0890, 0x7ff845830a14 
ntdll.dll`NtWaitForAlertByThreadId + 20, name = 'PPU[0x1002020] HLE Video 
Decoder'
<...>
```

Added: 


Modified: 
lldb/source/Plugins/Process/Windows/Common/TargetThreadWindows.cpp
lldb/source/Plugins/Process/Windows/Common/TargetThreadWindows.h
lldb/unittests/Thread/CMakeLists.txt
lldb/unittests/Thread/ThreadTest.cpp

Removed: 




diff  --git 
a/lldb/source/Plugins/Process/Windows/Common/TargetThreadWindows.cpp 
b/lldb/source/Plugins/Process/Windows/Common/TargetThreadWindows.cpp
index 37dc8f6d6d14a5..ad67e764fe10f2 100644
--- a/lldb/source/Plugins/Process/Windows/Common/TargetThreadWindows.cpp
+++ b/lldb/source/Plugins/Process/Windows/Common/TargetThreadWindows.cpp
@@ -7,18 +7,14 @@
 
//===--===//
 
 #include "lldb/Host/HostInfo.h"
-#include "lldb/Host/HostNativeThreadBase.h"
-#include "lldb/Host/windows/HostThreadWindows.h"
-#include "lldb/Host/windows/windows.h"
-#include "lldb/Target/RegisterContext.h"
 #include "lldb/Target/Unwind.h"
 #include "lldb/Utility/LLDBLog.h"
 #include "lldb/Utility/Log.h"
-#include "lldb/Utility/State.h"
 
 #include "ProcessWindows.h"
-#include "ProcessWindowsLog.h"
 #include "TargetThreadWindows.h"
+#include "lldb/Host/windows/HostThreadWindows.h"
+#include 
 
 #if defined(__x86_64__) || defined(_M_AMD64)
 #include "x64/RegisterContextWindows_x64.h"
@@ -33,6 +29,9 @@
 using namespace lldb;
 using namespace lldb_private;
 
+using GetThreadDescriptionFunctionPtr = HRESULT
+WINAPI (*)(HANDLE hThread, PWSTR *ppszThreadDescription);
+
 TargetThreadWindows::TargetThreadWindows(ProcessWindows ,
  const HostThread )
 : Thread(process, thread.GetNativeThread().GetThreadId()),
@@ -175,3 +174,29 @@ Status TargetThreadWindows::DoResume() {
 
   return Status();
 }
+
+const char *TargetThreadWindows::GetName() {
+  Log *log = GetLog(LLDBLog::Thread);
+  static GetThreadDescriptionFunctionPtr GetThreadDescription = []() {
+HMODULE hModule = ::LoadLibraryW(L"Kernel32.dll");
+return hModule ? reinterpret_cast(
+ ::GetProcAddress(hModule, "GetThreadDescription"))
+   : nullptr;
+  }();
+  LLDB_LOGF(log, "GetProcAddress: %p",
+reinterpret_cast(GetThreadDescription));
+  if (!GetThreadDescription)
+return m_name.c_str();
+  PWSTR pszThreadName;
+  if (SUCCEEDED(GetThreadDescription(
+  m_host_thread.GetNativeThread().GetSystemHandle(), ))) 
{
+LLDB_LOGF(log, "GetThreadDescription: %ls", pszThreadName);
+llvm::convertUTF16ToUTF8String(
+llvm::ArrayRef(reinterpret_cast(pszThreadName),
+   wcslen(pszThreadName) * sizeof(wchar_t)),
+m_name);
+::LocalFree(pszThreadName);
+  }
+
+  return m_name.c_str();
+}

diff  --git a/lldb/source/Plugins/Process/Windows/Common/TargetThreadWindows.h 
b/lldb/source/Plugins/Process/Windows/Common/TargetThreadWindows.h
index 2845847738f60d..07e1db464ad594 100644
--- a/lldb/source/Plugins/Process/Windows/Common/TargetThreadWindows.h
+++ b/lldb/source/Plugins/Process/Windows/Common/TargetThreadWindows.h
@@ -34,6 +34,7 @@ class TargetThreadWindows : public lldb_private::Thread {
   lldb::RegisterContextSP
   CreateRegisterContextForFrame(StackFrame *frame) override;
   bool CalculateStopInfo() override;
+  const char *GetName() override;
 
   Status DoResume();
 
@@ -42,6 +43,7 @@ class TargetThreadWindows : public lldb_private::Thread {
 private:
   lldb::RegisterContextSP m_thread_reg_ctx_sp;
   HostThread m_host_thread;
+  std::string m_name;
 };
 } // namespace lldb_private
 

diff  --git a/lldb/unittests/Thread/CMakeLists.txt 
b/lldb/unittests/Thread/CMakeLists.txt
index d6e365adac5dd7..f6c8795f349a5e 

[Lldb-commits] [lldb] [lldb] add support for thread names on Windows (PR #74731)

2023-12-21 Thread David Spickett via lldb-commits

https://github.com/DavidSpickett edited 
https://github.com/llvm/llvm-project/pull/74731
___
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)

2023-12-21 Thread Felipe de Azevedo Piovezan via lldb-commits

https://github.com/felipepiovezan commented:

I'll leave the approval to others, but I left a coding suggestion.

It would be a lot nicer if we could tell the producer of those messages to not 
include the severity, but I think this is way out of scope here. The 
"severity" inside the message is likely coming from a producer that is too far 
gone at this point.

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] Remove redundant severity substring within a diagnostic message. (PR #76111)

2023-12-21 Thread Felipe de Azevedo Piovezan via lldb-commits


@@ -48,8 +48,17 @@ std::string DiagnosticManager::GetString(char separator) {
   std::string ret;
 
   for (const auto  : 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);

felipepiovezan wrote:

I'm not sure how hot this code path is, but we are doing a bunch of unnecessary 
string copies in here (as we were before this PR as well...). For example, 
`message` and `severity` are both `StringRef`s that don't need to be converted 
into strings.

Suggestion:

```c++
std::string DiagnosticManager::GetString(char separator) {
  std::string ret;
  llvm::raw_string_ostream stream(ret);

  for (const auto  : Diagnostics()) {
llvm::StringRef severity = StringForSeverity(diagnostic->GetSeverity());
stream << severity;

llvm::StringRef message = diagnostic->GetMessage();
std::string searchable_message = message.lower();
auto severity_pos = message.find_first_of(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;
}
```

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] Remove redundant severity substring within a diagnostic message. (PR #76111)

2023-12-21 Thread Felipe de Azevedo Piovezan via lldb-commits

https://github.com/felipepiovezan edited 
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] [clang-tools-extra] [lldb] [compiler-rt] [llvm] [libcxx] [flang] [libc] [clang] [flang] FDATE extension implementation: get date and time in ctime format (PR #71222)

2023-12-21 Thread Yi Wu via lldb-commits

https://github.com/yi-wu-arm updated 
https://github.com/llvm/llvm-project/pull/71222

>From e0d99fb5baa4231ab351f7fd5abf0a1ffe589547 Mon Sep 17 00:00:00 2001
From: Yi Wu 
Date: Mon, 6 Nov 2023 19:55:06 +
Subject: [PATCH 01/14] FDATE extension implementation: get date and time in
 ctime format

reference to gfortran fdate https://gcc.gnu.org/onlinedocs/gfortran/FDATE.html
usage:
CHARACTER(32) :: time
CALL fdate(time)
WRITE(*,*) time
---
 flang/docs/Intrinsics.md |  2 +-
 flang/include/flang/Runtime/command.h|  5 +
 flang/include/flang/Runtime/extensions.h |  2 ++
 flang/runtime/command.cpp| 28 
 flang/runtime/extensions.cpp |  5 +
 flang/unittests/Runtime/CommandTest.cpp  | 14 
 6 files changed, 55 insertions(+), 1 deletion(-)

diff --git a/flang/docs/Intrinsics.md b/flang/docs/Intrinsics.md
index ab0a940e53e553..982be820816429 100644
--- a/flang/docs/Intrinsics.md
+++ b/flang/docs/Intrinsics.md
@@ -751,7 +751,7 @@ This phase currently supports all the intrinsic procedures 
listed above but the
 | Object characteristic inquiry functions | ALLOCATED, ASSOCIATED, 
EXTENDS_TYPE_OF, IS_CONTIGUOUS, PRESENT, RANK, SAME_TYPE, STORAGE_SIZE |
 | Type inquiry intrinsic functions | BIT_SIZE, DIGITS, EPSILON, HUGE, KIND, 
MAXEXPONENT, MINEXPONENT, NEW_LINE, PRECISION, RADIX, RANGE, TINY|
 | Non-standard intrinsic functions | AND, OR, XOR, SHIFT, ZEXT, IZEXT, COSD, 
SIND, TAND, ACOSD, ASIND, ATAND, ATAN2D, COMPL, EQV, NEQV, INT8, JINT, JNINT, 
KNINT, QCMPLX, DREAL, DFLOAT, QEXT, QFLOAT, QREAL, DNUM, NUM, JNUM, KNUM, QNUM, 
RNUM, RAN, RANF, ILEN, SIZEOF, MCLOCK, SECNDS, COTAN, IBCHNG, ISHA, ISHC, ISHL, 
IXOR, IARG, IARGC, NARGS, NUMARG, BADDRESS, IADDR, CACHESIZE, EOF, FP_CLASS, 
INT_PTR_KIND, ISNAN, MALLOC |
-| Intrinsic subroutines |MVBITS (elemental), CPU_TIME, DATE_AND_TIME, 
EVENT_QUERY, EXECUTE_COMMAND_LINE, GET_COMMAND, GET_COMMAND_ARGUMENT, 
GET_ENVIRONMENT_VARIABLE, MOVE_ALLOC, RANDOM_INIT, RANDOM_NUMBER, RANDOM_SEED, 
SYSTEM_CLOCK |
+| Intrinsic subroutines |MVBITS (elemental), CPU_TIME, DATE_AND_TIME, 
EVENT_QUERY, EXECUTE_COMMAND_LINE, FDATE, GET_COMMAND, GET_COMMAND_ARGUMENT, 
GET_ENVIRONMENT_VARIABLE, MOVE_ALLOC, RANDOM_INIT, RANDOM_NUMBER, RANDOM_SEED, 
SYSTEM_CLOCK |
 | Atomic intrinsic subroutines | ATOMIC_ADD |
 | Collective intrinsic subroutines | CO_REDUCE |
 
diff --git a/flang/include/flang/Runtime/command.h 
b/flang/include/flang/Runtime/command.h
index ec628939054547..07f6d8e169ead6 100644
--- a/flang/include/flang/Runtime/command.h
+++ b/flang/include/flang/Runtime/command.h
@@ -23,6 +23,11 @@ extern "C" {
 // integer kind.
 std::int32_t RTNAME(ArgumentCount)();
 
+// Try to get the the current date (same format as CTIME: convert to a string)
+// Return a STATUS as described in the standard.
+std::int32_t RTNAME(FDate)(
+const Descriptor *argument = nullptr, const Descriptor *errmsg = nullptr);
+
 // 16.9.82 GET_COMMAND
 // Try to get the value of the whole command. All of the parameters are
 // optional.
diff --git a/flang/include/flang/Runtime/extensions.h 
b/flang/include/flang/Runtime/extensions.h
index ad592814e5acb7..92b9907860121a 100644
--- a/flang/include/flang/Runtime/extensions.h
+++ b/flang/include/flang/Runtime/extensions.h
@@ -24,6 +24,8 @@ void FORTRAN_PROCEDURE_NAME(flush)(const int );
 // GNU Fortran 77 compatibility function IARGC.
 std::int32_t FORTRAN_PROCEDURE_NAME(iargc)();
 
+void FORTRAN_PROCEDURE_NAME(fdate)(std::int8_t *string, std::int64_t length);
+
 // GNU Fortran 77 compatibility subroutine GETARG(N, ARG).
 void FORTRAN_PROCEDURE_NAME(getarg)(
 std::int32_t , std::int8_t *arg, std::int64_t length);
diff --git a/flang/runtime/command.cpp b/flang/runtime/command.cpp
index b81a0791c5e571..da0803c39f49b6 100644
--- a/flang/runtime/command.cpp
+++ b/flang/runtime/command.cpp
@@ -14,6 +14,7 @@
 #include "flang/Runtime/descriptor.h"
 #include 
 #include 
+#include 
 
 namespace Fortran::runtime {
 std::int32_t RTNAME(ArgumentCount)() {
@@ -125,6 +126,33 @@ static bool FitsInDescriptor(
   kind, terminator, value);
 }
 
+void removeNewLine(char *str) {
+  char *newlinePos = strchr(str, '\n');
+  if (newlinePos != NULL) {
+*newlinePos = '\0'; // Replace with null terminator
+  }
+}
+
+std::int32_t RTNAME(FDate)(const Descriptor *value, const Descriptor *errmsg) {
+  FillWithSpaces(*value);
+
+  time_t current_time;
+  time(_time);
+
+  char *time_string = ctime(_time);
+  removeNewLine(time_string);
+  std::int64_t stringLen{StringLength(time_string)};
+  if (stringLen <= 0) {
+return ToErrmsg(errmsg, StatMissingArgument);
+  }
+
+  if (value) {
+return CopyToDescriptor(*value, time_string, stringLen, errmsg);
+  }
+
+  return StatOk;
+}
+
 std::int32_t RTNAME(GetCommandArgument)(std::int32_t n, const Descriptor 
*value,
 const Descriptor *length, const Descriptor *errmsg, const char *sourceFile,
 int line) {
diff --git 

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

2023-12-21 Thread Yi Wu via lldb-commits

https://github.com/yi-wu-arm updated 
https://github.com/llvm/llvm-project/pull/71222

>From e0d99fb5baa4231ab351f7fd5abf0a1ffe589547 Mon Sep 17 00:00:00 2001
From: Yi Wu 
Date: Mon, 6 Nov 2023 19:55:06 +
Subject: [PATCH 01/13] FDATE extension implementation: get date and time in
 ctime format

reference to gfortran fdate https://gcc.gnu.org/onlinedocs/gfortran/FDATE.html
usage:
CHARACTER(32) :: time
CALL fdate(time)
WRITE(*,*) time
---
 flang/docs/Intrinsics.md |  2 +-
 flang/include/flang/Runtime/command.h|  5 +
 flang/include/flang/Runtime/extensions.h |  2 ++
 flang/runtime/command.cpp| 28 
 flang/runtime/extensions.cpp |  5 +
 flang/unittests/Runtime/CommandTest.cpp  | 14 
 6 files changed, 55 insertions(+), 1 deletion(-)

diff --git a/flang/docs/Intrinsics.md b/flang/docs/Intrinsics.md
index ab0a940e53e553..982be820816429 100644
--- a/flang/docs/Intrinsics.md
+++ b/flang/docs/Intrinsics.md
@@ -751,7 +751,7 @@ This phase currently supports all the intrinsic procedures 
listed above but the
 | Object characteristic inquiry functions | ALLOCATED, ASSOCIATED, 
EXTENDS_TYPE_OF, IS_CONTIGUOUS, PRESENT, RANK, SAME_TYPE, STORAGE_SIZE |
 | Type inquiry intrinsic functions | BIT_SIZE, DIGITS, EPSILON, HUGE, KIND, 
MAXEXPONENT, MINEXPONENT, NEW_LINE, PRECISION, RADIX, RANGE, TINY|
 | Non-standard intrinsic functions | AND, OR, XOR, SHIFT, ZEXT, IZEXT, COSD, 
SIND, TAND, ACOSD, ASIND, ATAND, ATAN2D, COMPL, EQV, NEQV, INT8, JINT, JNINT, 
KNINT, QCMPLX, DREAL, DFLOAT, QEXT, QFLOAT, QREAL, DNUM, NUM, JNUM, KNUM, QNUM, 
RNUM, RAN, RANF, ILEN, SIZEOF, MCLOCK, SECNDS, COTAN, IBCHNG, ISHA, ISHC, ISHL, 
IXOR, IARG, IARGC, NARGS, NUMARG, BADDRESS, IADDR, CACHESIZE, EOF, FP_CLASS, 
INT_PTR_KIND, ISNAN, MALLOC |
-| Intrinsic subroutines |MVBITS (elemental), CPU_TIME, DATE_AND_TIME, 
EVENT_QUERY, EXECUTE_COMMAND_LINE, GET_COMMAND, GET_COMMAND_ARGUMENT, 
GET_ENVIRONMENT_VARIABLE, MOVE_ALLOC, RANDOM_INIT, RANDOM_NUMBER, RANDOM_SEED, 
SYSTEM_CLOCK |
+| Intrinsic subroutines |MVBITS (elemental), CPU_TIME, DATE_AND_TIME, 
EVENT_QUERY, EXECUTE_COMMAND_LINE, FDATE, GET_COMMAND, GET_COMMAND_ARGUMENT, 
GET_ENVIRONMENT_VARIABLE, MOVE_ALLOC, RANDOM_INIT, RANDOM_NUMBER, RANDOM_SEED, 
SYSTEM_CLOCK |
 | Atomic intrinsic subroutines | ATOMIC_ADD |
 | Collective intrinsic subroutines | CO_REDUCE |
 
diff --git a/flang/include/flang/Runtime/command.h 
b/flang/include/flang/Runtime/command.h
index ec628939054547..07f6d8e169ead6 100644
--- a/flang/include/flang/Runtime/command.h
+++ b/flang/include/flang/Runtime/command.h
@@ -23,6 +23,11 @@ extern "C" {
 // integer kind.
 std::int32_t RTNAME(ArgumentCount)();
 
+// Try to get the the current date (same format as CTIME: convert to a string)
+// Return a STATUS as described in the standard.
+std::int32_t RTNAME(FDate)(
+const Descriptor *argument = nullptr, const Descriptor *errmsg = nullptr);
+
 // 16.9.82 GET_COMMAND
 // Try to get the value of the whole command. All of the parameters are
 // optional.
diff --git a/flang/include/flang/Runtime/extensions.h 
b/flang/include/flang/Runtime/extensions.h
index ad592814e5acb7..92b9907860121a 100644
--- a/flang/include/flang/Runtime/extensions.h
+++ b/flang/include/flang/Runtime/extensions.h
@@ -24,6 +24,8 @@ void FORTRAN_PROCEDURE_NAME(flush)(const int );
 // GNU Fortran 77 compatibility function IARGC.
 std::int32_t FORTRAN_PROCEDURE_NAME(iargc)();
 
+void FORTRAN_PROCEDURE_NAME(fdate)(std::int8_t *string, std::int64_t length);
+
 // GNU Fortran 77 compatibility subroutine GETARG(N, ARG).
 void FORTRAN_PROCEDURE_NAME(getarg)(
 std::int32_t , std::int8_t *arg, std::int64_t length);
diff --git a/flang/runtime/command.cpp b/flang/runtime/command.cpp
index b81a0791c5e571..da0803c39f49b6 100644
--- a/flang/runtime/command.cpp
+++ b/flang/runtime/command.cpp
@@ -14,6 +14,7 @@
 #include "flang/Runtime/descriptor.h"
 #include 
 #include 
+#include 
 
 namespace Fortran::runtime {
 std::int32_t RTNAME(ArgumentCount)() {
@@ -125,6 +126,33 @@ static bool FitsInDescriptor(
   kind, terminator, value);
 }
 
+void removeNewLine(char *str) {
+  char *newlinePos = strchr(str, '\n');
+  if (newlinePos != NULL) {
+*newlinePos = '\0'; // Replace with null terminator
+  }
+}
+
+std::int32_t RTNAME(FDate)(const Descriptor *value, const Descriptor *errmsg) {
+  FillWithSpaces(*value);
+
+  time_t current_time;
+  time(_time);
+
+  char *time_string = ctime(_time);
+  removeNewLine(time_string);
+  std::int64_t stringLen{StringLength(time_string)};
+  if (stringLen <= 0) {
+return ToErrmsg(errmsg, StatMissingArgument);
+  }
+
+  if (value) {
+return CopyToDescriptor(*value, time_string, stringLen, errmsg);
+  }
+
+  return StatOk;
+}
+
 std::int32_t RTNAME(GetCommandArgument)(std::int32_t n, const Descriptor 
*value,
 const Descriptor *length, const Descriptor *errmsg, const char *sourceFile,
 int line) {
diff --git 

[Lldb-commits] [openmp] [clang-tools-extra] [libc] [compiler-rt] [clang] [flang] [mlir] [lldb] [libcxx] [llvm] [OpenMP] atomic compare fail : Codegen support (PR #75709)

2023-12-21 Thread via lldb-commits

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

>From fe931d64741f427629407bca3e68a61bec6f2b67 Mon Sep 17 00:00:00 2001
From: Sunil Kuravinakop 
Date: Sat, 16 Dec 2023 11:43:35 -0600
Subject: [PATCH 1/3] Adding parameter to fail clause (i.e. memory order
 clause) for codegen.

  Changes to be committed:
modified:   clang/lib/CodeGen/CGStmtOpenMP.cpp
---
 clang/lib/CodeGen/CGStmtOpenMP.cpp | 51 +++---
 1 file changed, 47 insertions(+), 4 deletions(-)

diff --git a/clang/lib/CodeGen/CGStmtOpenMP.cpp 
b/clang/lib/CodeGen/CGStmtOpenMP.cpp
index 478d6dbf9ca81d..a502db7ac3a5e0 100644
--- a/clang/lib/CodeGen/CGStmtOpenMP.cpp
+++ b/clang/lib/CodeGen/CGStmtOpenMP.cpp
@@ -6516,10 +6516,6 @@ static void emitOMPAtomicExpr(CodeGenFunction , 
OpenMPClauseKind Kind,
  IsPostfixUpdate, IsFailOnly, Loc);
 break;
   }
-  case OMPC_fail: {
-//TODO
-break;
-  }
   default:
 llvm_unreachable("Clause is not allowed in 'omp atomic'.");
   }
@@ -6527,6 +6523,8 @@ static void emitOMPAtomicExpr(CodeGenFunction , 
OpenMPClauseKind Kind,
 
 void CodeGenFunction::EmitOMPAtomicDirective(const OMPAtomicDirective ) {
   llvm::AtomicOrdering AO = llvm::AtomicOrdering::Monotonic;
+  // Fail Memory Clause Ordering.
+  llvm::AtomicOrdering FO = llvm::AtomicOrdering::Monotonic;
   bool MemOrderingSpecified = false;
   if (S.getSingleClause()) {
 AO = llvm::AtomicOrdering::SequentiallyConsistent;
@@ -6580,6 +6578,51 @@ void CodeGenFunction::EmitOMPAtomicDirective(const 
OMPAtomicDirective ) {
 }
   }
 
+  if (KindsEncountered.contains(OMPC_compare) &&
+  KindsEncountered.contains(OMPC_fail)) {
+Kind = OMPC_compare;
+const OMPFailClause *fC = S.getSingleClause();
+if (fC) {
+  OpenMPClauseKind fP = fC->getFailParameter();
+  if (fP == llvm::omp::OMPC_relaxed)
+FO = llvm::AtomicOrdering::Monotonic;
+  else if (fP == llvm::omp::OMPC_acquire)
+FO = llvm::AtomicOrdering::Acquire;
+  else if (fP == llvm::omp::OMPC_seq_cst)
+FO = llvm::AtomicOrdering::SequentiallyConsistent;
+}
+
+// Logic for 2 memory order clauses in the atomic directive.
+// e.g. #pragma omp atomic compare capture release fail(seq_cst)
+//  if(x > e) { x = j; } else { k = x; }
+// To provide the Memory Order clause in atomic directive
+// there are 2 instructions in LLVM IR atomicrmw & cmpxchgl.
+// 1) atomicrmw can use only 1 memory order clause and can contain the
+//operator in if condition.
+// 2) cmpxchgl can use 2 memory order clauses : Success memory order clause
+//& fail parameter memory clause. However, cmpxchgl uses only equality
+//operator.
+// We need to change atomicrmw to contain the fail parameter clause or add
+// a new instruction in LLVM IR. Changes in LLVM IR need to be done
+// seperately and at present we will use the logic of using the more strict
+// memory order clause of success or fail memory order clauses for the
+// atomicrmw. The following logic takes care of this change in the memory
+// order clause.
+if (AO == llvm::AtomicOrdering::Monotonic)
+  AO = FO;
+else if (FO == llvm::AtomicOrdering::Monotonic)
+  AO = AO;
+else if (AO == llvm::AtomicOrdering::SequentiallyConsistent ||
+ FO == llvm::AtomicOrdering::SequentiallyConsistent)
+  AO = llvm::AtomicOrdering::SequentiallyConsistent;
+else if (AO == llvm::AtomicOrdering::Acquire)
+  AO = llvm::AtomicOrdering::Acquire;
+else if (AO == llvm::AtomicOrdering::Release)
+  AO = llvm::AtomicOrdering::AcquireRelease;
+else if (AO == llvm::AtomicOrdering::AcquireRelease)
+  AO = llvm::AtomicOrdering::AcquireRelease;
+  }
+
   LexicalScope Scope(*this, S.getSourceRange());
   EmitStopPoint(S.getAssociatedStmt());
   emitOMPAtomicExpr(*this, Kind, AO, S.isPostfixUpdate(), S.getX(), S.getV(),

>From 9cc33631c89c4fd4dce8a274fed700febe5dfa90 Mon Sep 17 00:00:00 2001
From: Sunil Kuravinakop 
Date: Tue, 19 Dec 2023 23:49:03 -0600
Subject: [PATCH 2/3] 1) Since the{if(x == e) {x = v;} else {d = x;}}
 results in generation of cmpxchg in the LLVM IR, the memory order clause in
 "fail" clause is now being added.In case of other operators ">" & "<"
 e.g.dx = dx > de ? de : dx; result in atomicrmw in the LLVM IR.
 "atomicrmw" can have only one memory order clause. Currently, the memory
 order clause is ignored. 2) Test cases for codegen 3) In SemaOpenMP.cpp,
 addedEncounteredAtomicKinds.contains(OMPC_compare) instead of AtomicKind
 == OMPC_compare. This was to accomodate where AtomicKind is OMPC_capture.

  Changes to be committed:
modified:   clang/lib/CodeGen/CGStmtOpenMP.cpp
modified:   clang/lib/Sema/SemaOpenMP.cpp
modified:   clang/test/OpenMP/atomic_compare_codegen.cpp
modified:   llvm/include/llvm/Frontend/OpenMP/OMPIRBuilder.h

[Lldb-commits] [clang-tools-extra] [libc] [compiler-rt] [clang] [flang] [mlir] [lldb] [libcxx] [lld] [llvm] Don't emit relax relocs like R_X86_64_REX_GOTPCRELX on X86 target for OPENMP internal vars.

2023-12-21 Thread via lldb-commits

https://github.com/UmeshKalappa0 updated 
https://github.com/llvm/llvm-project/pull/75564

>From 4125e4a709c594562fa6c52f045ba7442e3cb523 Mon Sep 17 00:00:00 2001
From: Umesh Kalappa 
Date: Fri, 15 Dec 2023 11:52:52 +0530
Subject: [PATCH 1/4] Problem :For Kernel Modules ,emitting the relocs like
 R_X86_64_REX_GOTPCRELX  for the OPENMP internal vars like
 https://godbolt.org/z/hhh7ozojz.

Solution : Mark the OpenMP internal variables with dso_local
conditionally for no-pic and no-pie ,then
a)reset the dso_local for thread_local and weak linkage vars.
---
 .../test/OpenMP/gomp_critical_dso_local_var.c | 23 +++
 1 file changed, 23 insertions(+)
 create mode 100644 clang/test/OpenMP/gomp_critical_dso_local_var.c

diff --git a/clang/test/OpenMP/gomp_critical_dso_local_var.c 
b/clang/test/OpenMP/gomp_critical_dso_local_var.c
new file mode 100644
index 00..915f6773bf67bf
--- /dev/null
+++ b/clang/test/OpenMP/gomp_critical_dso_local_var.c
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -fopenmp -x c -emit-llvm %s -o - | FileCheck %s 
--check-prefix=DSO_LOCAL
+
+// DSO_LOCAL-DAG: @.gomp_critical_user_.var = common dso_local global [8 x 
i32] zeroinitializer, align 8
+int omp_critical_test()
+{
+  int sum;
+  int known_sum;
+
+  sum=0;
+#pragma omp parallel
+  {
+int mysum=0;
+int i;
+#pragma omp for
+for (i = 0; i < 1000; i++)
+  mysum = mysum + i;
+#pragma omp critical
+sum = mysum +sum;
+  }
+  known_sum = 999 * 1000 / 2;
+  return (known_sum == sum);
+}
+

>From 842245de490ab15f8a901b94576ae4539c760e1e Mon Sep 17 00:00:00 2001
From: Umesh Kalappa 
Date: Fri, 15 Dec 2023 12:49:48 +0530
Subject: [PATCH 2/4] testcases are changed accordignly.

---
 clang/lib/CodeGen/CGOpenMPRuntime.cpp   | 2 ++
 clang/test/OpenMP/critical_codegen.cpp  | 6 +++---
 clang/test/OpenMP/critical_codegen_attr.cpp | 6 +++---
 clang/test/OpenMP/for_reduction_codegen.cpp | 8 
 clang/test/OpenMP/gomp_critical_dso_local_var.c | 1 -
 clang/test/OpenMP/simd_codegen.cpp  | 4 ++--
 llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp   | 8 
 7 files changed, 22 insertions(+), 13 deletions(-)

diff --git a/clang/lib/CodeGen/CGOpenMPRuntime.cpp 
b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
index 7f7e6f53066644..183c757d72b8a7 100644
--- a/clang/lib/CodeGen/CGOpenMPRuntime.cpp
+++ b/clang/lib/CodeGen/CGOpenMPRuntime.cpp
@@ -1793,6 +1793,8 @@ Address 
CGOpenMPRuntime::getAddrOfArtificialThreadPrivate(CodeGenFunction ,
   if (CGM.getLangOpts().OpenMP && CGM.getLangOpts().OpenMPUseTLS &&
   CGM.getTarget().isTLSSupported()) {
 GAddr->setThreadLocal(/*Val=*/true);
+/// reset the dso_local for thread_local.
+GAddr->setDSOLocal(/*Val=*/false);
 return Address(GAddr, GAddr->getValueType(),
CGM.getContext().getTypeAlignInChars(VarType));
   }
diff --git a/clang/test/OpenMP/critical_codegen.cpp 
b/clang/test/OpenMP/critical_codegen.cpp
index 24145d44d962e5..9a613161ac294a 100644
--- a/clang/test/OpenMP/critical_codegen.cpp
+++ b/clang/test/OpenMP/critical_codegen.cpp
@@ -16,9 +16,9 @@
 #define HEADER
 
 // ALL:   [[IDENT_T_TY:%.+]] = type { i32, i32, i32, i32, ptr }
-// ALL:   [[UNNAMED_LOCK:@.+]] = common global [8 x i32] zeroinitializer
-// ALL:   [[THE_NAME_LOCK:@.+]] = common global [8 x i32] zeroinitializer
-// ALL:   [[THE_NAME_LOCK1:@.+]] = common global [8 x i32] zeroinitializer
+// ALL:   [[UNNAMED_LOCK:@.+]] = common dso_local global [8 x i32] 
zeroinitializer
+// ALL:   [[THE_NAME_LOCK:@.+]] = common dso_local global [8 x i32] 
zeroinitializer
+// ALL:   [[THE_NAME_LOCK1:@.+]] = common dso_local global [8 x i32] 
zeroinitializer
 
 // ALL:   define {{.*}}void [[FOO:@.+]]()
 
diff --git a/clang/test/OpenMP/critical_codegen_attr.cpp 
b/clang/test/OpenMP/critical_codegen_attr.cpp
index 34d90a9e3a6e48..5f1a76e2ad0f1f 100644
--- a/clang/test/OpenMP/critical_codegen_attr.cpp
+++ b/clang/test/OpenMP/critical_codegen_attr.cpp
@@ -16,9 +16,9 @@
 #define HEADER
 
 // ALL:   [[IDENT_T_TY:%.+]] = type { i32, i32, i32, i32, ptr }
-// ALL:   [[UNNAMED_LOCK:@.+]] = common global [8 x i32] zeroinitializer
-// ALL:   [[THE_NAME_LOCK:@.+]] = common global [8 x i32] zeroinitializer
-// ALL:   [[THE_NAME_LOCK1:@.+]] = common global [8 x i32] zeroinitializer
+// ALL:   [[UNNAMED_LOCK:@.+]] = common dso_local global [8 x i32] 
zeroinitializer
+// ALL:   [[THE_NAME_LOCK:@.+]] = common dso_local global [8 x i32] 
zeroinitializer
+// ALL:   [[THE_NAME_LOCK1:@.+]] = common dso_local global [8 x i32] 
zeroinitializer
 
 // ALL:   define {{.*}}void [[FOO:@.+]]()
 
diff --git a/clang/test/OpenMP/for_reduction_codegen.cpp 
b/clang/test/OpenMP/for_reduction_codegen.cpp
index 893c606f8d7b9f..b128bd5d79c251 100644
--- a/clang/test/OpenMP/for_reduction_codegen.cpp
+++ b/clang/test/OpenMP/for_reduction_codegen.cpp
@@ -528,12 +528,12 @@ int main() {
 
 #endif
 //.
-// CHECK1: 

[Lldb-commits] [lldb] [lldb] Add actionable feedback when overwriting a command fails (PR #76030)

2023-12-21 Thread Felipe de Azevedo Piovezan via lldb-commits

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


[Lldb-commits] [lldb] cf0be7b - [lldb] Add actionable feedback when overwriting a command fails (#76030)

2023-12-21 Thread via lldb-commits

Author: Felipe de Azevedo Piovezan
Date: 2023-12-21T09:04:24-03:00
New Revision: cf0be7b4920cec762639a1f39e8ccf1868e44c40

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

LOG: [lldb] Add actionable feedback when overwriting a command fails (#76030)

If adding a user commands fails because a command with the same name
already exists, we only say that "force replace is not set" without
telling the user _how_ to set it. There are two ways to do so; this
commit changes the error message to mention both.

Added: 


Modified: 
lldb/source/Interpreter/CommandInterpreter.cpp
lldb/test/API/commands/command/script/TestCommandScript.py

Removed: 




diff  --git a/lldb/source/Interpreter/CommandInterpreter.cpp 
b/lldb/source/Interpreter/CommandInterpreter.cpp
index e1275ce711fc17..00651df48b6224 100644
--- a/lldb/source/Interpreter/CommandInterpreter.cpp
+++ b/lldb/source/Interpreter/CommandInterpreter.cpp
@@ -1160,7 +1160,11 @@ Status 
CommandInterpreter::AddUserCommand(llvm::StringRef name,
 
   if (UserCommandExists(name)) {
 if (!can_replace) {
-  result.SetErrorString("user command exists and force replace not set");
+  result.SetErrorStringWithFormatv(
+  "user command \"{0}\" already exists and force replace was not set "
+  "by --overwrite or 'settings set interpreter.require-overwrite "
+  "false'",
+  name);
   return result;
 }
 if (cmd_sp->IsMultiwordObject()) {

diff  --git a/lldb/test/API/commands/command/script/TestCommandScript.py 
b/lldb/test/API/commands/command/script/TestCommandScript.py
index cac11834fa7364..850552032902fd 100644
--- a/lldb/test/API/commands/command/script/TestCommandScript.py
+++ b/lldb/test/API/commands/command/script/TestCommandScript.py
@@ -161,6 +161,19 @@ def cleanup():
 )
 self.expect("my_command", substrs=["a.out"])
 
+# Test that without --overwrite we are not allowed to redefine the 
command.
+self.expect(
+"command script add my_command --class welcome.TargetnameCommand",
+substrs=[
+(
+'user command "my_command" already exists and force 
replace was'
+" not set by --overwrite or 'settings set"
+" interpreter.require-overwrite false'"
+),
+],
+error=True,
+)
+
 self.runCmd("command script clear")
 
 self.expect(



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


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

2023-12-21 Thread Yi Wu via lldb-commits

https://github.com/yi-wu-arm updated 
https://github.com/llvm/llvm-project/pull/71222

>From e0d99fb5baa4231ab351f7fd5abf0a1ffe589547 Mon Sep 17 00:00:00 2001
From: Yi Wu 
Date: Mon, 6 Nov 2023 19:55:06 +
Subject: [PATCH 01/12] FDATE extension implementation: get date and time in
 ctime format

reference to gfortran fdate https://gcc.gnu.org/onlinedocs/gfortran/FDATE.html
usage:
CHARACTER(32) :: time
CALL fdate(time)
WRITE(*,*) time
---
 flang/docs/Intrinsics.md |  2 +-
 flang/include/flang/Runtime/command.h|  5 +
 flang/include/flang/Runtime/extensions.h |  2 ++
 flang/runtime/command.cpp| 28 
 flang/runtime/extensions.cpp |  5 +
 flang/unittests/Runtime/CommandTest.cpp  | 14 
 6 files changed, 55 insertions(+), 1 deletion(-)

diff --git a/flang/docs/Intrinsics.md b/flang/docs/Intrinsics.md
index ab0a940e53e553..982be820816429 100644
--- a/flang/docs/Intrinsics.md
+++ b/flang/docs/Intrinsics.md
@@ -751,7 +751,7 @@ This phase currently supports all the intrinsic procedures 
listed above but the
 | Object characteristic inquiry functions | ALLOCATED, ASSOCIATED, 
EXTENDS_TYPE_OF, IS_CONTIGUOUS, PRESENT, RANK, SAME_TYPE, STORAGE_SIZE |
 | Type inquiry intrinsic functions | BIT_SIZE, DIGITS, EPSILON, HUGE, KIND, 
MAXEXPONENT, MINEXPONENT, NEW_LINE, PRECISION, RADIX, RANGE, TINY|
 | Non-standard intrinsic functions | AND, OR, XOR, SHIFT, ZEXT, IZEXT, COSD, 
SIND, TAND, ACOSD, ASIND, ATAND, ATAN2D, COMPL, EQV, NEQV, INT8, JINT, JNINT, 
KNINT, QCMPLX, DREAL, DFLOAT, QEXT, QFLOAT, QREAL, DNUM, NUM, JNUM, KNUM, QNUM, 
RNUM, RAN, RANF, ILEN, SIZEOF, MCLOCK, SECNDS, COTAN, IBCHNG, ISHA, ISHC, ISHL, 
IXOR, IARG, IARGC, NARGS, NUMARG, BADDRESS, IADDR, CACHESIZE, EOF, FP_CLASS, 
INT_PTR_KIND, ISNAN, MALLOC |
-| Intrinsic subroutines |MVBITS (elemental), CPU_TIME, DATE_AND_TIME, 
EVENT_QUERY, EXECUTE_COMMAND_LINE, GET_COMMAND, GET_COMMAND_ARGUMENT, 
GET_ENVIRONMENT_VARIABLE, MOVE_ALLOC, RANDOM_INIT, RANDOM_NUMBER, RANDOM_SEED, 
SYSTEM_CLOCK |
+| Intrinsic subroutines |MVBITS (elemental), CPU_TIME, DATE_AND_TIME, 
EVENT_QUERY, EXECUTE_COMMAND_LINE, FDATE, GET_COMMAND, GET_COMMAND_ARGUMENT, 
GET_ENVIRONMENT_VARIABLE, MOVE_ALLOC, RANDOM_INIT, RANDOM_NUMBER, RANDOM_SEED, 
SYSTEM_CLOCK |
 | Atomic intrinsic subroutines | ATOMIC_ADD |
 | Collective intrinsic subroutines | CO_REDUCE |
 
diff --git a/flang/include/flang/Runtime/command.h 
b/flang/include/flang/Runtime/command.h
index ec628939054547..07f6d8e169ead6 100644
--- a/flang/include/flang/Runtime/command.h
+++ b/flang/include/flang/Runtime/command.h
@@ -23,6 +23,11 @@ extern "C" {
 // integer kind.
 std::int32_t RTNAME(ArgumentCount)();
 
+// Try to get the the current date (same format as CTIME: convert to a string)
+// Return a STATUS as described in the standard.
+std::int32_t RTNAME(FDate)(
+const Descriptor *argument = nullptr, const Descriptor *errmsg = nullptr);
+
 // 16.9.82 GET_COMMAND
 // Try to get the value of the whole command. All of the parameters are
 // optional.
diff --git a/flang/include/flang/Runtime/extensions.h 
b/flang/include/flang/Runtime/extensions.h
index ad592814e5acb7..92b9907860121a 100644
--- a/flang/include/flang/Runtime/extensions.h
+++ b/flang/include/flang/Runtime/extensions.h
@@ -24,6 +24,8 @@ void FORTRAN_PROCEDURE_NAME(flush)(const int );
 // GNU Fortran 77 compatibility function IARGC.
 std::int32_t FORTRAN_PROCEDURE_NAME(iargc)();
 
+void FORTRAN_PROCEDURE_NAME(fdate)(std::int8_t *string, std::int64_t length);
+
 // GNU Fortran 77 compatibility subroutine GETARG(N, ARG).
 void FORTRAN_PROCEDURE_NAME(getarg)(
 std::int32_t , std::int8_t *arg, std::int64_t length);
diff --git a/flang/runtime/command.cpp b/flang/runtime/command.cpp
index b81a0791c5e571..da0803c39f49b6 100644
--- a/flang/runtime/command.cpp
+++ b/flang/runtime/command.cpp
@@ -14,6 +14,7 @@
 #include "flang/Runtime/descriptor.h"
 #include 
 #include 
+#include 
 
 namespace Fortran::runtime {
 std::int32_t RTNAME(ArgumentCount)() {
@@ -125,6 +126,33 @@ static bool FitsInDescriptor(
   kind, terminator, value);
 }
 
+void removeNewLine(char *str) {
+  char *newlinePos = strchr(str, '\n');
+  if (newlinePos != NULL) {
+*newlinePos = '\0'; // Replace with null terminator
+  }
+}
+
+std::int32_t RTNAME(FDate)(const Descriptor *value, const Descriptor *errmsg) {
+  FillWithSpaces(*value);
+
+  time_t current_time;
+  time(_time);
+
+  char *time_string = ctime(_time);
+  removeNewLine(time_string);
+  std::int64_t stringLen{StringLength(time_string)};
+  if (stringLen <= 0) {
+return ToErrmsg(errmsg, StatMissingArgument);
+  }
+
+  if (value) {
+return CopyToDescriptor(*value, time_string, stringLen, errmsg);
+  }
+
+  return StatOk;
+}
+
 std::int32_t RTNAME(GetCommandArgument)(std::int32_t n, const Descriptor 
*value,
 const Descriptor *length, const Descriptor *errmsg, const char *sourceFile,
 int line) {
diff --git 

[Lldb-commits] [lldb] lldb: add support for thread names on Windows (PR #74731)

2023-12-21 Thread via lldb-commits

oltolm wrote:

What happens next with my PR?

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


[Lldb-commits] [lldb] [LLDB] Define _BSD_SOURCE globally, to get optreset available in mingw's getopt.h (PR #76137)

2023-12-21 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-lldb

Author: Martin Storsjö (mstorsjo)


Changes

We previously were defining _BSD_SOURCE right before including getopt.h. 
However, on mingw-w64, getopt.h is also transitively included by unistd.h, and 
unistd.h can be transitively included by many headers (recently, by some libc++ 
headers).

Therefore, to be safe, we need to define _BSD_SOURCE before including any 
header. Thus do this in CMake.

This fixes https://github.com/llvm/llvm-project/issues/76050.

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


2 Files Affected:

- (modified) lldb/CMakeLists.txt (+4) 
- (modified) lldb/include/lldb/Host/HostGetOpt.h (-4) 


``diff
diff --git a/lldb/CMakeLists.txt b/lldb/CMakeLists.txt
index 4a53d7ef3d0da0..7844d93d78d29a 100644
--- a/lldb/CMakeLists.txt
+++ b/lldb/CMakeLists.txt
@@ -44,6 +44,10 @@ endif()
 
 if (WIN32)
   add_definitions(-D_ENABLE_EXTENDED_ALIGNED_STORAGE)
+  if (NOT MSVC)
+# _BSD_SOURCE is required for MinGW's getopt.h to define optreset
+add_definitions(-D_BSD_SOURCE)
+  endif()
 endif()
 
 if (LLDB_ENABLE_PYTHON)
diff --git a/lldb/include/lldb/Host/HostGetOpt.h 
b/lldb/include/lldb/Host/HostGetOpt.h
index 746e03e1bd1ee2..52cfdf4dbb89c2 100644
--- a/lldb/include/lldb/Host/HostGetOpt.h
+++ b/lldb/include/lldb/Host/HostGetOpt.h
@@ -11,10 +11,6 @@
 
 #if !defined(_MSC_VER) && !defined(__NetBSD__)
 
-#ifdef _WIN32
-#define _BSD_SOURCE // Required so that getopt.h defines optreset
-#endif
-
 #include 
 #include 
 

``




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


[Lldb-commits] [lldb] [LLDB] Define _BSD_SOURCE globally, to get optreset available in mingw's getopt.h (PR #76137)

2023-12-21 Thread via lldb-commits

llvmbot wrote:




@llvm/pr-subscribers-platform-windows

Author: Martin Storsjö (mstorsjo)


Changes

We previously were defining _BSD_SOURCE right before including getopt.h. 
However, on mingw-w64, getopt.h is also transitively included by unistd.h, and 
unistd.h can be transitively included by many headers (recently, by some libc++ 
headers).

Therefore, to be safe, we need to define _BSD_SOURCE before including any 
header. Thus do this in CMake.

This fixes https://github.com/llvm/llvm-project/issues/76050.

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


2 Files Affected:

- (modified) lldb/CMakeLists.txt (+4) 
- (modified) lldb/include/lldb/Host/HostGetOpt.h (-4) 


``diff
diff --git a/lldb/CMakeLists.txt b/lldb/CMakeLists.txt
index 4a53d7ef3d0da0..7844d93d78d29a 100644
--- a/lldb/CMakeLists.txt
+++ b/lldb/CMakeLists.txt
@@ -44,6 +44,10 @@ endif()
 
 if (WIN32)
   add_definitions(-D_ENABLE_EXTENDED_ALIGNED_STORAGE)
+  if (NOT MSVC)
+# _BSD_SOURCE is required for MinGW's getopt.h to define optreset
+add_definitions(-D_BSD_SOURCE)
+  endif()
 endif()
 
 if (LLDB_ENABLE_PYTHON)
diff --git a/lldb/include/lldb/Host/HostGetOpt.h 
b/lldb/include/lldb/Host/HostGetOpt.h
index 746e03e1bd1ee2..52cfdf4dbb89c2 100644
--- a/lldb/include/lldb/Host/HostGetOpt.h
+++ b/lldb/include/lldb/Host/HostGetOpt.h
@@ -11,10 +11,6 @@
 
 #if !defined(_MSC_VER) && !defined(__NetBSD__)
 
-#ifdef _WIN32
-#define _BSD_SOURCE // Required so that getopt.h defines optreset
-#endif
-
 #include 
 #include 
 

``




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


[Lldb-commits] [lldb] [LLDB] Define _BSD_SOURCE globally, to get optreset available in mingw's getopt.h (PR #76137)

2023-12-21 Thread Martin Storsjö via lldb-commits

https://github.com/mstorsjo created 
https://github.com/llvm/llvm-project/pull/76137

We previously were defining _BSD_SOURCE right before including getopt.h. 
However, on mingw-w64, getopt.h is also transitively included by unistd.h, and 
unistd.h can be transitively included by many headers (recently, by some libc++ 
headers).

Therefore, to be safe, we need to define _BSD_SOURCE before including any 
header. Thus do this in CMake.

This fixes https://github.com/llvm/llvm-project/issues/76050.

From 69552a132c6ff99a2a1caf8cd0075f796174d95a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Martin=20Storsj=C3=B6?= 
Date: Thu, 21 Dec 2023 11:23:18 +0200
Subject: [PATCH] [LLDB] Define _BSD_SOURCE globally, to get optreset available
 in mingw's getopt.h

We previously were defining _BSD_SOURCE right before including
getopt.h. However, on mingw-w64, getopt.h is also transitively
included by unistd.h, and unistd.h can be transitively included
by many headers (recently, by some libc++ headers).

Therefore, to be safe, we need to define _BSD_SOURCE before
including any header. Thus do this in CMake.

This fixes https://github.com/llvm/llvm-project/issues/76050.
---
 lldb/CMakeLists.txt | 4 
 lldb/include/lldb/Host/HostGetOpt.h | 4 
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/lldb/CMakeLists.txt b/lldb/CMakeLists.txt
index 4a53d7ef3d0da0..7844d93d78d29a 100644
--- a/lldb/CMakeLists.txt
+++ b/lldb/CMakeLists.txt
@@ -44,6 +44,10 @@ endif()
 
 if (WIN32)
   add_definitions(-D_ENABLE_EXTENDED_ALIGNED_STORAGE)
+  if (NOT MSVC)
+# _BSD_SOURCE is required for MinGW's getopt.h to define optreset
+add_definitions(-D_BSD_SOURCE)
+  endif()
 endif()
 
 if (LLDB_ENABLE_PYTHON)
diff --git a/lldb/include/lldb/Host/HostGetOpt.h 
b/lldb/include/lldb/Host/HostGetOpt.h
index 746e03e1bd1ee2..52cfdf4dbb89c2 100644
--- a/lldb/include/lldb/Host/HostGetOpt.h
+++ b/lldb/include/lldb/Host/HostGetOpt.h
@@ -11,10 +11,6 @@
 
 #if !defined(_MSC_VER) && !defined(__NetBSD__)
 
-#ifdef _WIN32
-#define _BSD_SOURCE // Required so that getopt.h defines optreset
-#endif
-
 #include 
 #include 
 

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


[Lldb-commits] [lldb] [lldb] Fix MaxSummaryLength target property type (PR #72233)

2023-12-21 Thread Michael Buch via lldb-commits

Michael137 wrote:

@dancing-leaves are you still planning to add tests for this so we can land 
this? Would be great to get this in

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