[Clang-Tidy] Improve `bugprone-implicit-widening-of-multiplication-result`. (#214501)
Implicit integer promotions make it a bit difficult to deduce the
correct type in the following expression:
```
std::uint64_t calc_array_size(std::uint16_t width, std::uint16_t height) {
return width * height;
}
```
Originally, Clang-Tidy suggested to use the following code:
```
return static_cast<long long>(width) * height;
```
It is fully correct according to the C++ rules, but it makes it a bit
harder to reason for people. This change adds a more readable "FixIt"
taking into account the source type and avoid intermediate
representations.
Co-authored-by: Dmitrii Kuragin <dkuragin at adobe.com>
[clang][OffloadBundler] Fix uninitialized iterator in BinaryFileHandler (#219346)
This patch initializes NextBundleInfo at the top of ReadHeader to
prevent an uninitialized iterator comparison.
ReadHeader has several early return points where it exits without
reading any bundles. Upon an early return, NextBundleInfo never reaches
the assignment at the bottom of ReadHeader:
NextBundleInfo = BundlesInfo.begin();
leaving NextBundleInfo default-constructed. A subsequent call to
ReadBundleStart then attempts an invalid iterator comparison:
if (NextBundleInfo == BundlesInfo.end())
where NextBundleInfo is still default-constructed.
This bug was discovered with tightened epoch checks in
[2 lines not shown]
[flang][OpenMP] Support omx/ompx extension sentinels (#218475)
This adds support for the OpenMP 5.2 extension sentinels: !$omx, c$omx,
*$omx in fixed form and !$ompx in free form. Known directives after
these sentinels are handled just like !$omp, and unknown ones are
ignored with a warning so code using vendor extensions stays portable.
Added lit tests covering fixed form, free form, and the
ignore-with-warning behavior.
Assisted-by: Claude Opus 4.6
---------
Co-authored-by: Chandra Ghale <ghale at pe34genoa.hpc.amslabs.hpecorp.net>
Co-authored-by: Krzysztof Parzyszek <Krzysztof.Parzyszek at amd.com>
[ScalarizeMaskedMemIntrin][ProfCheck] Correctly annotate branch weights (part 2) (#219286)
https://github.com/llvm/llvm-project/pull/218753 broke LLVM CI because
it added a new test in `ScalarizeMaskedMemIntrin` that was not opted out
of during profcheck. Profcheck failed because this pass creates new
branches that did not attach branch weight metadata. We don't have any
information on the distribution of masks at runtime, so we have to mark
branch weights as explicitly unknown.
This basically extends https://github.com/llvm/llvm-project/pull/181568,
Aiden am I missing something for why you didn't add the branch weight
metadata for all branch creation before?
Tested the `ScalarizeMaskedMemIntrin` tests with profcheck locally and
they all pass.
[ADT] Remove unused IDHash parameter from Equals (NFC) (#219313)
This patch removes the unused IDHash parameter from several functions.
Now that FoldingSetTrait<SDVTListNode>::Equals no longer checks IDHash,
no implementation of Equals uses this parameter.
Assisted-by: Antigravity
[VPlan] Append recipes created via builder to worklist
The previous PR appended the top most created recipe to the worklist, and this PR extends it to any other nested recipes that were created, similar to InstCombine.
This removes the header mask in a good few more places on RISC-V as measured on SPEC CPU 2017, e.g. for the following loop:
```c
long f(const int *p, const int *q, long n) {
long a = 0, b = 0;
for (long i = 0;; i++) {
if (p[i] && q[i]) { a += i; b += i; }
if (i + 1 == n) break;
}
return a + b;
}
```
Before:
[49 lines not shown]
[VPlan] Process simplifyRecipes in a worklist
This brings simplifyRecipes further in line with InstCombine, and asides from unlocking more simplifications it also helps avoid spurious test churn whenever passes are moved around simplifyRecipes.
For now just push the new recipe onto the worklist, not its users.
This uses a post order traversal so we maintain the same simplification order as before.
I've gone through and checked every simplification we do is a canonicalisation that converges, and I checked on llvm-test-suite + SPEC CPU 2017 in various configurations that we don't hit any cycles.
[flang] Speed up large CHARACTER DATA initializers (#218813)
[flang] Speed up large CHARACTER DATA initializers
Repeated CHARACTER(KIND=1) array constants were lowered as one
fir.insert_value per element. Converting those chains to LLVM IR is
quadratic and can make compilation take tens of minutes.
Lower consecutive equal KIND=1 character elements with
fir.insert_on_range
and emit full-range initializers as a single flattened [N x i8] LLVM
global
string, keeping Fortran blank padding.
A 160000-element character DATA statement now compiles in well under a
second and before was more than 10 minutes.
[AST] Make err_struct_too_large check target-aware (#218749)
ASTContext::getASTRecordLayout used a fixed 1ULL << 60 threshold for
err_struct_too_large, regardless of the target's size_t width.
Scale the threshold to the target's size_t width instead, so it is below
(1 << 32) on 32-bit architectures. Diagnosing the overflow in Sema
avoids the crash in codegen.
rdar://183351516
[libc] Add stubs for POSIX netdb.h and getaddrinfo (#219337)
* Add the `<netdb.h>` POSIX header and declare `struct addrinfo` and
`freeaddrinfo` and `getaddrinfo` methods
as defined in
https://pubs.opengroup.org/onlinepubs/9799919799/functions/getaddrinfo.html
;
* Provide Linux-specific definitions for `EAI_` macro family;
* Add header/entrypoints to the list of "experimental" (i.e. WIP)
entrypoints on Linux systems;
* Create the proxy header harness for types / Linux-specific macro.
* Provide stub implementations - no-op `freeaddrinfo` and `getaddrinfo`
that returns `EAI_SYSTEM` and sets errno to `ENOSYS`. Validate this
behavior in unit tests.
Assisted by automated tooling, human-reviewed
[clang][modules] Introduce a flag to keep redundant module lookups on relocation checks (#219107)
cf8597bd3b87 introduced relocation checks for dependency scans but also
disabled it when the modules were built in the same build session for
implicit module builds.
It turns out downstream projects (using implicit modules) can depend on
the relocation check calling `lookupModule` for order-dependent module
resolution to hide poorly modularized dependencies within the same build
session, since that call loads discovered modules during search.
Introduce `-fmodules-force-redundant-lookup` as an escape hatch to
maintain preexisting redundant lookup for those projects while keeping
the fast path the default for dependency scans.
[libc++][FTM] Updated FTMs from C++29 (#218241)
... and a few missing ones from previous standard versions.
---------
Co-authored-by: Hristo Hristov <zingam at outlook.com>
Co-authored-by: A. Jiang <de34 at live.cn>
[WebAssembly] Avoid scanning unrelated debug values (NFCI) (#218378)
RegStackify looks for debug values when moving an instruction.
But when a debug use comes before the definition, it may collect values
for a lot of unrelated variables until the end of the block.
Stop early once all relevant values have been found instead.