7199 Commits

Author SHA1 Message Date
Austin
c7bacc9f26
[llvm] using wrapper llvm::sort(nfc) (#151000)
using wrapper llvm::sort(nfc)
2025-08-04 09:27:01 +08:00
David Majnemer
9fdb5e1fef [APFloat] Properly implement next for DoubleAPFloat
Rather than converting to the legacy 106-bit format, perform next() on the
low APFloat. Of course, we need to renormalize the two APFloats if
either of the two constraints are violated:
1. abs(low) <= ulp(high)/2
2. high = rtne(high + low)

Should renormalization be needed, it will increment the high component
and set low to the smallest value which obeys these rules.
2025-08-01 12:34:33 -07:00
Martin Storsjö
1c60b7da4f
[Support] [Windows] Conditionally compile the SetThreadInformation calls (#151388)
The declarations for this API are missing in older mingw-w64 headers
(versions before v12). This API is also hidden if building with MS
WinSDK if targeting versions before Windows 10.

Check whether THREAD_POWER_THROTTLING_CURRENT_VERSION is defined before
using this API; this constant is a #define in both WinSDK and mingw-w64.
2025-07-31 21:54:09 +03:00
Daniel Paoliello
4adce336f4
[win][arm64ec] Fixes to unblock building LLVM and Clang as Arm64EC (#150068)
These changes allow LLVM and Clang to be built with Clang targeting
Arm64EC using the MSVC linker.

Built with these options:
```
-DLLVM_ENABLE_PROJECTS="clang"
-DLLVM_HOST_TRIPLE=arm64ec-pc-windows-msvc
-DCMAKE_C_COMPILER=clang-cl.exe
-DCMAKE_C_COMPILER_TARGET=arm64ec-pc-windows-msvc
-DCMAKE_CXX_COMPILER=clang-cl.exe
-DCMAKE_CXX_COMPILER_TARGET=arm64ec-pc-windows-msvc
-DCMAKE_LINKER_TYPE=MSVC
```
2025-07-31 09:30:05 -07:00
James Y Knight
9ddbb478ce
NFC: Clean up construction of IntrusiveRefCntPtr from raw pointers for llvm::vfs::FileSystem. (#151407)
This switches to `makeIntrusiveRefCnt<FileSystem>` where creating a new
object, and to passing/returning by `IntrusiveRefCntPtr<FileSystem>`
instead of `FileSystem*` or `FileSystem&`, when dealing with existing
objects.

Part of cleanup #151026.
2025-07-31 09:57:13 -04:00
Tim Blechmann
860b1e68ea
Windows: use EcoQoS for ThreadPriority::Background (#148797)
The SetThreadInformation API allows threads to be scheduled on the most
efficient cores on the most efficient frequency.
Using this API for ThreadPriority::Background should make clangd-based
IDEs a little less CPU hungry.

---------

Co-authored-by: Alexandre Ganea <aganea@havenstudios.com>
2025-07-29 11:24:06 -04:00
Kazu Hirata
5e150bb781
[Support] Remove an unnecessary cast (NFC) (#151083)
NumRead is already of ssize_t.
2025-07-29 08:19:01 -07:00
Mehdi Amini
9c82f87aec
Introduce a "log level" support for DEBUG_TYPE (#150855)
This allows to set an optional integer level for a given debug type. The
string format is `type[:level]`, and the integer is interpreted as such:

- if not provided: all debugging for this debug type is enabled.
- if >0: all debug that is < to the level is enabled.
- if 0: same as for >0 but also does not disable the other debug-types,
it acts as a negative filter.

The LDBG() macro is updated to accept an optional log level to
illustrate the feature. Here is the expected behavior:

LDBG() << "A"; // Identical to LDBG(1) << "A";
LDBG(2) << "B";

With `--debug-only=some_type`: we'll see A and B in the output.  
With `--debug-only=some_type:1`: we'll see A but not B in the output. 
With `--debug-only=some_type:2`: we'll see A and B in the output. (same
with any level above 2)
With `--debug-only=some_type:0`: we'll see neither A nor B in the
output, but we'll see any other logging for other debug types.
2025-07-28 18:10:36 +02:00
Aaron Ballman
479ae4aa8f
Revert "fix: replace report_fatal_error with Diags and exit" (#150662)
Reverts llvm/llvm-project#147959
2025-07-25 13:24:00 -04:00
woruyu
9d3dd8efe0
fix: replace report_fatal_error with Diags and exit (#147959)
report_fatal_error is not a good way to report diagnostics to the users, so this switches to using actual diagnostic reporting mechanisms instead.

Fixes #147187
2025-07-25 10:20:30 -04:00
Andrew Rogers
04892228b1
[llvm] get cl::opt instantiations working with MSVC DLL build (#147810)
## Purpose

This patch is one in a series of code-mods that annotate LLVM’s public
interface for export. This patch annotates the `llvm:🆑:opt` explicit
template instantiations for export with `LLVM_TEMPLATE_ABI` and
`LLVM_EXPORT_TEMPLATE`. This annotation currently has no meaningful
impact on the LLVM build; however, it is a prerequisite to support an
LLVM Windows DLL (shared library) build.

## Background

This effort is tracked in #109483. Additional context is provided in
[this
discourse](https://discourse.llvm.org/t/psa-annotating-llvm-public-interface/85307),
and documentation for `LLVM_ABI` and related annotations is found in the
LLVM repo
[here](https://github.com/llvm/llvm-project/blob/main/llvm/docs/InterfaceExportAnnotations.rst).

Annotating the `llvm:🆑:opt` template instances for DLL export was not
straight-forward like other explicit template instances that have
already been annotated. Annotating them as documented
[here](https://github.com/llvm/llvm-project/blob/main/llvm/docs/InterfaceExportAnnotations.rst#templates)
results in link errors when building a Windows DLL using MSVC.

## Overview 
There are two specific issues that appear when exporting the
`llvm:🆑:opt` templates and compiling a Windows DLL with MSVC:
1. We cannot export `opt<std::string>`. This is because MSVC exports all
ancestor classes when exporting an instantiated template class. Since
one of `opt`'s ancestor classes is its type argument (via
`opt_storage`), it is an ancestor of `std::string`. Therefore, if we
export `opt<std::string>` from the LLVM DLL, MSVC forces
`std::basic_string` to also be exported. This leads to duplicate symbol
errors and generally seems like a bad idea. Compiling with `clang-cl`
does not exhibit this behavior.
2. The `opt` template instances other than `opt<bool>` get optimized out
because they are not referenced in the TU (`opt<bool>` actually is). It
is unclear exactly why MSVC optimizes these template instances away, but
`clang-cl` does not. Adding explicit references to the instantiated
`opt` template classes' vtables via implicit virtual destructor forces
MSVC to export them.

## Validation
Windows with MSVC
Windows with Clang
2025-07-24 11:03:58 -07:00
Mark Murray
d52675e0a7
[lld][AArch64][Build Attributes] Add support for AArch64 Build Attributes (#147970)
This patch enables lld to read AArch64 Build Attributes and convert them
into GNU Properties.

Changes:
    - Parses AArch64 Build Attributes from input object files.
    - Converts known attributes into corresponding GNU Properties.
    - Merges attributes when linking multiple objects.

Spec reference:
    https://github.com/ARM-software/abi-aa/pull/230/files#r1030

Co-authored-by: Sivan Shani <sivan.shani@arm.com>

---------

Co-authored-by: Sivan Shani <sivan.shani@arm.com>
2025-07-24 10:38:36 +01:00
Guy David
802ea0eb78
[Support] System include SipHash.h (#149499)
A regular include may not search the system include path.
2025-07-19 15:00:21 +03:00
Matt Arsenault
2f38ced51b
StringMap: Remove redundant member init in constructor (#149491)
These are already zeroinitialized in the field definitions.
2025-07-19 09:15:48 +09:00
Tomohiro Kashiwada
8de61eb01c
[Support/BLAKE3] quick fix for Cygwin build (#148635)
BLAKE3 1.8.2 ( imported in d2ad63a193216d008c8161879a59c5f42e0125cc )
fails to build for the Cygwin target.

see: https://github.com/BLAKE3-team/BLAKE3/issues/494

As a temporary workaround, add `&& !defined(__CYGWIN__)` to BLAKE3
locally.

resolves https://github.com/llvm/llvm-project/issues/148365
2025-07-18 00:16:08 +03:00
Nikita Popov
1754a7d573
[Support][BLAKE3] Restore static on blake3_hash4_neon (#149046)
This was dropped in #147948 and causes symbol conflicts if libblake3 is
also linked.
2025-07-16 17:49:19 +02:00
Marina Taylor
dd3d26bc89
Revert "[Support] Error if SocketPath is too long" (#149096)
Reverts llvm/llvm-project#148903 due to bot failure
https://lab.llvm.org/buildbot/#/builders/187/builds/8162
2025-07-16 16:48:59 +01:00
Marina Taylor
73630d5e20
[Support] Error if SocketPath is too long (#148903)
If the path is longer than sockaddr_un's buffer, it will be truncated,
at which point it may become indistinguishable from similar truncated
paths. This will cause `bind` to fail with an "Address already in use"
error. There is some existing code that checks `fs::exists` to catch
these errors, but since `fs::exists` compares the full un-truncated
paths, a too-long path will prevent those checks from working.

rdar://154397133
2025-07-16 12:15:23 +01:00
Jordan Rupprecht
60579ec305
[Support][BLAKE3] Prefix more blake3 methods (#149007)
Added by #147948, blake3_xof_many and blake3_compress_subtree_wide cause
conflicts when linking llvm and blake3 statically into the same binary.
Similar to #148607.
2025-07-16 11:31:48 +02:00
Dmitry Vasilyev
efa94cf703
[Support/rpmalloc] Updated fake atomics with Interlocked functions (#148303)
Most atomic functions used Interlocked functions in case of MSVC (since MSVC does not do C11 yet).
But few load/store functions are dummy.
Use Interlocked functions for these atomics to ensure they are thread-safe.

This PR fixes #146205.

LLVM is on VS 2019 version 16.7 currently and eventually we require VS 2022 if we wanted to use stdatomics in rpmalloc, etc. In the meanwhile, we use the Interlocked intrinsics when building with MSVC.
2025-07-15 22:42:27 +04:00
Nikita Popov
4b52d221a0
[Support][BLAKE3] Prefix blake3_xof_many_avx512 (#148607)
This symbol was introduced in #147948, but not prefixed, resulting in
conflicts if libblake3 and LLVM are both linked statically into the same
binary.
2025-07-14 14:32:47 -07:00
Dmitry Vasilyev
d2ad63a193
[Support/BLAKE3] Make g_cpu_features thread safe (#147948)
`g_cpu_features` can be updated multiple times by `get_cpu_features()`,
which reports a thread sanitizer error when used with multiple lld
threads.

This PR updates BLAKE3 to v1.8.2.
2025-07-12 11:02:56 +04:00
Rahul Joshi
d8a2141ff9
[NFC][LLVM][ADT] Simplify StringRef case insensitive compare (#147994)
Change `ascii_strncasecmp` to use a range for loop and use StringRef
parameters.
2025-07-10 13:08:19 -07:00
Peter Collingbourne
7f3afab918
Extract SipHash implementation into a header.
This is so that we'll be able to use it in compiler-rt as well.
Dependencies on LLVM Support were removed from the header by restoring
code from the original SipHash implementation.

Reviewers: kuhar, dwblaikie, ahmedbougacha

Reviewed By: dwblaikie

Pull Request: https://github.com/llvm/llvm-project/pull/134197
2025-07-09 16:07:16 -07:00
Alex Langford
9337594e33
[Support] Don't re-raise signals sent from kernel (#145759)
When an llvm tool crashes (e.g. from a segmentation fault),
SignalHandler will re-raise the signal. The effect is that crash reports
now contain SignalHandler in the stack trace. The crash reports are
still useful, but the presence of SignalHandler can confuse tooling and
automation that deduplicate or analyze crash reports.

rdar://150464802
2025-07-09 14:53:15 -07:00
Matthias Braun
bdc0119e1b
ErrorHandling: Check for EINTR and partial writes (#147595)
Calls to the posix `write` function can return -1 and set errno to
`EINTR` or perform partial writes when interrupted by signals. In those
cases applications are supposed to just try again. See for example the
documentation in glibc:
https://sourceware.org/glibc/manual/latest/html_node/I_002fO-Primitives.html#index-write

This fixes the uses in `ErrorHandling.cpp` to retry as needed.
2025-07-09 11:19:21 -07:00
Kazu Hirata
75b989ec73
[Support] Remove an unnecessary cast (NFC) (#147548)
I is already of int64_t.
2025-07-08 12:47:23 -07:00
Pavel Labath
0a60c4ca22
[Support] Add signed operations to DataExtractor (#147261)
This is motivated by the [SFrame format](https://discourse.llvm.org/t/rfc-adding-sframe-support-to-llvm/86900),
which contains several signed fields.

Having explicit signed operations makes the parsing code read better and
avoids potential surprises if e.g. a "signed" uint8_t value is converted
ta greater width.
2025-07-08 08:47:04 +02:00
Kazu Hirata
ea88634764
[Support] Remove an unnecessary cast (NFC) (#146810)
We don't need to cast std::string to std::string.
2025-07-03 12:02:26 -07:00
vabridgers
c71bbd50a1
[analyzer] Correct Z3 test cases, fix exposed crashes (#146597)
PR145731 corrected the analyzer test runner to consider use of z3 when
used by testcases, which exposed problems in test cases PR37855.c and
crashes in z3-crosscheck.c This change fixes those crashes and
re-enables the test cases that were "XFAIL"'d out.

Co-authored-by: einvbri <vince.a.bridgers@ericsson.com>
2025-07-03 09:08:00 -05:00
Abhina Sree
a4d517dc38
[SystemZ][z/OS] Fix error about const char in Text Encoding (#146727)
This patch fixes the following error:
```
llvm/lib/Support/TextEncoding.cpp:274:11: error: cannot initialize a variable of type 'char *' with an rvalue of type 'const char *'
  274 |     char *Input = InputLength ? const_cast<char *>(Source.data()) : "";
      |           ^       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
```
2025-07-02 13:45:52 -04:00
Stephen Tozer
35626e97d8
[DLCov] Origin-Tracking: Enable collecting and symbolizing stack traces (#143591)
This patch is part of a series that adds origin-tracking to the debugify
source location coverage checks, allowing us to report symbolized stack
traces of the point where missing source locations appear.

This patch adds a pair of new functions in `signals.h` that can be used
to collect and symbolize stack traces respectively. This has major
implementation overlap with the existing stack trace
collection/symbolizing methods, but the existing functions are
specialized for dumping a stack trace to stderr when LLVM crashes, while
these new functions are meant to be called repeatedly during the
execution of the program, and therefore we need a separate set of
functions.
2025-07-02 12:01:17 +01:00
Martin Storsjö
163871c2d2
[Support] Remove workarounds for building with mingw.org toolchains (#145683)
Assume that mingw builds are made with mingw-w64 headers.

The old mingw.org distribution isn't even accessible at the moment, and
their project hosting site (osdn.net) seems to have been down for a
couple of years, and their old project hosting (at sourceforge.net)
hasn't been updated since 2018.
2025-06-26 13:23:42 +03:00
Tomohiro Kashiwada
bd96918f01
[LLVM][Support][Cygwin] Add threading support for Cygwin host (#145314)
Cygwin environment has pthread functionality but LLVM integration
doesn't care it nor provide fallback.
Using Linux integration for Cygwin works fine.
2025-06-24 17:18:28 +03:00
Martin Storsjö
7a4b392559
[Support] Remove an outdated MinGW workaround (#145294)
mingw-w64 has had the _HEAPOK define since the initial commits in 2007;
unclear when/where it was added for mingw.org headers, but it does seem
to exist there as well (at least in versions from 2011).

This workaround stems from 53fbecce6e8b7d1f024e3dc6df4160fe9a577ff1 from
2004 - it is no longer relevant today.
2025-06-24 17:13:44 +03:00
Andrew Rogers
a88e655809
[llvm] build Blake3 source with LLVM_EXPORTS defined (#144753)
## Purpose
This patch ensures that the BLAKE3 implementation in the LLVM Support
library exports its public interface with `__declspec(dllexport)` when
building LLVM as a Windows DLL.

## Background
The effort to support building LLVM as a Windows DLL is tracked in
#109483. Additional context is provided in [this
discourse](https://discourse.llvm.org/t/psa-annotating-llvm-public-interface/85307).

## Overview
Replicate [this
logic](https://github.com/llvm/llvm-project/blob/main/llvm/cmake/modules/AddLLVM.cmake#L662-L664)
from `llvm_add_library()` for the `LLVMSupportBlake3` target. Without
this change, the `llvm_blake_` functions will only be annotated with
`__declspec(dllimport)` when building LLVM as a Windows DLL which leads
to inconsistent DLL linkage warnings from MSVC and `clang-cl`.
2025-06-18 13:08:05 -07:00
Sirraide
9ae4d2e013
[LLVM] [Support] Disable ioctl() terminal size check on Solaris (#144600)
#143514 broke the `clang-solaris11-sparcv9` bot; from what I can tell
that’s Solaris and according to `SolarisTargetInfo::getOSDefines`, the
macro `__sun__` should be defined on Solaris, so check for that and
don’t try to query the terminal size if it is defined.

Not sure this is the best solution but hopefully it fixes the bot.
2025-06-17 22:44:02 +02:00
Sirraide
b4e39e4ff9
[LLVM] [Support] Query the terminal width using ioctl() (#143514)
On unix systems, we were trying to determine the terminal width using
the `COULMNS` environment variable. Unfortunately, `COLUMNS` is not 
exported by all shells and thus not available on some systems.

We were previously using `ioctl()` for this; fall back to doing so if `COLUMNS`
does not exist or does not store a positive integer.

This essentially reverts a3eb3d3d92d037fe3c9deaad87f6fc42fe9ea766 and
parts of https://reviews.llvm.org/D61326.

For more information, see #139499.

Fixes #139499.
2025-06-17 15:03:37 +02:00
Abhina Sree
be9994b092
[SystemZ][z/OS] Refactor AutoConvert more (#143955)
This patch removes the C++
disablezOSAutoConversion,enablezOSAutoConversion declarations and also
updates Path.inc to use the common function.
2025-06-13 07:00:36 -04:00
Abhina Sree
22fd11fe66
[SystemZ][z/OS] Refactor AutoConvert.h to remove large MVS guard (#143174)
This AutoConvert.h header frequently gets mislabeled as an unused
include because it is guarded by MVS internally and every usage is also
guarded. This refactors the change to remove this guard and instead make
these functions a noop on other non-z/OS platforms.
2025-06-11 15:26:49 -04:00
jeremyd2019
d659364295
[Support][Cygwin] Fix handling of Process symbol lookup. (#143072)
In Unix/DynamicLibrary.inc, it was already known that Cygwin required
use of `RTLD_DEFAULT` as the `Handle` parameter to `DLSym` to search all
modules for a symbol. Unfortunately, RTLD_DEFAULT is defined as NULL, so
the existing checks of the `Process` handle meant `DLSym` would never be
called on Cygwin. Use the existing `&Invalid` sentinel instead of
`nullptr` for the `Process` handle.
2025-06-09 22:19:37 +03:00
Kazu Hirata
477f9f6d92
[llvm] Call hash_combine_range with ranges (NFC) (#143225)
We can now invoke hash_combine_range with a range.
2025-06-06 22:55:19 -07:00
Florian Mayer
44a6a44573
[NFC] [DebugCounter] warn if --debug-counter is unused in NDEBUG (#143057)
Co-authored-by: Nikita Popov <npopov@redhat.com>
2025-06-06 10:54:07 -07:00
Abhina Sreeskantharajan
6a4b89055b [SystemZ][z/OS] add back headers needed for strnlen, autoconversion 2025-06-06 09:45:06 -04:00
Christian Ulmann
052d5889f8
[Support] Properly zero initialize CPU set when querying affinity (#142924)
This commit resolves a potential issue of working with uninitialized
memory when querying the CPU's affinity. The man page of
`sched_getaffinity` does not guarantee that the memory will be fully
overwritten, so this change should ensure that issues are avoided.
2025-06-06 11:24:46 +02:00
Kazu Hirata
25642eaa1d [Support] Restore a couple of includes
A build failure has been reported at:

https://github.com/llvm/llvm-project/pull/142733#issuecomment-2942753737
2025-06-04 22:06:45 -07:00
Kazu Hirata
228f66807d
[llvm] Remove unused includes (NFC) (#142733)
These are identified by misc-include-cleaner.  I've filtered out those
that break builds.  Also, I'm staying away from llvm-config.h,
config.h, and Compiler.h, which likely cause platform- or
compiler-specific build failures.
2025-06-04 12:30:52 -07:00
Paul Kirth
8e77263ad0
[llvm][mustache] Fix UB in ASTNode::render() (#142249)
The current implementation set a reference to a nullptr, leading to all
kinds of problems. Instead, we can check the various uses to ensure we
don't deref invalid memory, and improve the logic for how contexts are
passed to children, since that was also subtly wrong in some cases.
2025-06-04 09:46:14 -07:00
Hemang Gadhavi
41841e625d
[lldb][llvm][AIX] Added support for getProcFile with TID (#142586)
This PR is in reference to porting LLDB on AIX.
Link to discussions on llvm discourse and github:

1. https://discourse.llvm.org/t/port-lldb-to-ibm-aix/80640
2. https://github.com/llvm/llvm-project/issues/101657
The complete changes for porting are present in this draft PR:
https://github.com/llvm/llvm-project/pull/102601

- Added changes to getProcFile() with threadID, including testcase for
AIX.
- Added support for AIX to get_threadid() from llvm.
2025-06-04 14:44:57 +05:30
Qinkun Bao
81bde1040c
[NFCI] Change SpecialCaseList::inSectionBlame to return pair<uint, uint> (FileIdx, LineNo). (#141540)
Accoring to the discussion in https://github.com/llvm/llvm-project/pull/140529, we need to SSCL can be created from multiple ignore list files, so we can repeat-fsanitize-ignorelist=. The change is necessary to achieve the feature described in https://github.com/llvm/llvm-project/issues/139128.
2025-05-28 00:18:37 -04:00