500354 Commits

Author SHA1 Message Date
Endre Fülöp
46b3145b7c
[clang][analyzer][NFC] Add test for a limitation of alpha.unix.BlockInCriticalSection checker (#93799)
Updated the documentation in `checkers.rst` to include an example of how
`trylock` function is handled.
Added a new test for a scenario where `pthread_mutex_trylock` is used,
demonstrating the current limitation.
2024-05-31 12:51:14 +02:00
Endre Fülöp
196dca7561
[clang][analyzer][NFC] Improve docs of alpha.unix.BlockInCriticalSection (#93812)
- Enhanced descriptions for blocking and critical section functions
- Added an additional code sample highlighting interleaved C and C++
style mutexes
2024-05-31 12:50:04 +02:00
Henry Linjamäki
a65771fce4
[SPIR-V] Prefer llvm-spirv-<LLVM_VERSION_MAJOR> tool (#77897)
Prefer using `llvm-spirv-<LLVM_VERSION_MAJOR>` tool (i.e.
`llvm-spirv-18`) over plain `llvm-spirv`. If the versioned tool is not
found in PATH, fall back to use the plain `llvm-spirv`.

An issue with the using `llvm-spirv` is that the one found in PATH might
be compiled against older LLVM version which could lead to crashes or
obscure bugs. For example, `llvm-spirv` distributed by Ubuntu links
against different LLVM version depending on the Ubuntu release (LLVM-10
in 20.04LTS, LLVM-13 in 22.04LTS).
2024-05-31 12:21:21 +02:00
Tom Eccles
c8fad4fb88
[flang][OpenMP][NFC] Reduce OMPMarkDeclareTarget boilerplate (#93797)
The pass constructor can be generated automatically by tablegen.

This pass does not need adapting to work with non-function top level
operations because it operates specifically on call operations inside of
an OpenMP declare target function.
2024-05-31 11:13:54 +01:00
Sergey Kachkov
60a890d855 [LoopPeel] Add pre-commit test for min/max intrinsics 2024-05-31 13:06:08 +03:00
Nikita Popov
de32a3df35 [Clang] Regenerate test checks (NFC)
To minimize diffs in an upcoming change.
2024-05-31 11:18:17 +02:00
Stanislav Mekhanoshin
2766a66fa7
[AMDGPU] Remove FlatVariant argument from isLegalFlatAddressingMode. NFC. (#93938)
This argument is easily deduced from AS argument.
2024-05-31 01:58:12 -07:00
Guillaume Chatelet
48ba7da9c8
[libc][NFC] Allow compilation of memcpy with -m32 (#93790)
Needed to support i386 (#93709).
2024-05-31 10:48:38 +02:00
Jay Foad
b1be480b03 [DAGCombiner] Move CanReassociate down to first use. NFC. 2024-05-31 09:44:47 +01:00
Nikita Popov
51e459a561 Revert "[ConstantFold] Remove non-trivial gep-of-gep fold (#93823)"
This reverts commit e1cc9e4eaddcc295b4e775512e33b947b1514c17.

This causes some non-trivial text size increases in unoptimized
builds for Bullet. Revert while I investigate.
2024-05-31 10:37:32 +02:00
Théo Degioanni
b86a9c5bf2
[mlir][irdl] Lookup symbols near dialects instead of locally (#92819)
Because symbols cannot refer to operations outside of their symbol
tables, it was impossible to refer to operations outside of the dialect
currently being defined. This PR modifies the lookup logic to happen
relative to the symbol table containing the dialect-defining operations.
This is a bit of hack but should unblock the situation here.
2024-05-31 09:15:50 +01:00
Yvan Roux
ae86278090
[Nomination] Add ST representative to Security group (#93176)
I'd like to nominate myself to join the LLVM Security group as a
representative of ST. I work in ST's compiler team contributing to
upstream (LLVM and GNU) and several downstream toolchains. We believe
that it is important for us to be part of this group to address or
report any potential security issues the LLVM project or our toolchains
may encounter.
2024-05-31 10:13:26 +02:00
Sander de Smalen
f484c79e7a
[AArch64] Avoid NEON ctpop in Streaming-SVE mode (#93826)
The NEON ctpop instruction is also used for scalars.
2024-05-31 09:01:17 +01:00
Matheus Izvekov
be566d2eac
[clang] AST Visitor: skip empty qualifiers in QualifiedTemplateName (#93926) 2024-05-31 04:31:31 -03:00
Nikita Popov
e1cc9e4ead
[ConstantFold] Remove non-trivial gep-of-gep fold (#93823)
This fold is subtly incorrect, because DL-unaware constant folding does
not know the correct index type to use, and just performs the addition
in the type that happens to already be there. This is incorrect, since
sext(X)+sext(Y) is generally not the same as sext(X+Y). See the
`@constexpr_gep_of_gep_with_narrow_type()` for a miscompile with the
current implementation.

One could try to restrict the fold to cases where no overflow occurs,
but I'm not bothering with that here, because the DL-aware constant
folding will take care of this anyway. I've only kept the
straightforward zero-index case, where we just concatenate two GEPs.
2024-05-31 09:25:38 +02:00
Nikita Popov
63dc31b68b Reapply [IR] Avoid creating icmp/fcmp constant expressions (#92885)
Reapply after https://github.com/llvm/llvm-project/pull/93548,
which should address the lldb failure on macos.

-----

Do not create icmp/fcmp constant expressions in IRBuilder etc anymore,
i.e. treat them as "undesirable". This is in preparation for removing
them entirely.

Part of:
https://discourse.llvm.org/t/rfc-remove-most-constant-expressions/63179
2024-05-31 08:55:59 +02:00
Fabian Ritter
0821b7937c
[AMDGPU] Copy Defs and Uses from Pseudo to Real Instructions (#93004)
Currently, the tablegen files that generate the instruction definitions
in lib/Target/AMDGPU/AMDGPUGenInstrInfo.inc often only include implicit
operands for the architecture-independent pseudo instructions, but not
for the corresponding real instructions. The missing implicit operands
(most prominently: the EXEC mask) do not affect code generation, since
that operates on pseudo instructions, but they are problematic when
working with real instructions, e.g., as a decoding result from the MC
layer.

This patch copies the implicit Defs and Uses from pseudo instructions to
the corresponding real instructions, so that implicit operands are also
defined for real instructions.

Addresses issue #89830.
2024-05-31 08:40:54 +02:00
jeanPerier
5228c2cbd6
[flang][FIR] add fir.is_assumed_size operation (#93853)
Assumed-rank fir.box/class may describe assumed-size array. This case
needs special handling in SELECT RANK. It is not possible to generate
FIR code to detect that a fir.box is an assumed-size (the way to detect
that is to check that upper dimension extent is -1 in the descriptor).

Instead of emitting a runtime call directly in lowering, add an
operation that can later be lowered to a runtime call or inline code
when the descriptor layout is known.
2024-05-31 08:38:40 +02:00
jeanPerier
f49d26bc77
[flang][runtime] add IsAssumedSize API (#93857)
Needed for SELECT RANK implementation. I want to stay away from
generating the `rank > 0 && ...` logic in FIR codegen for now.
2024-05-31 08:37:23 +02:00
Cyndy Ishida
4985f25ffc
[IR] Fix IWYU violation (#93918)
GEPNoWrapFlags.h calls `assert` creating a undeclared identifier error
when running an Apple-stage2 build with LLVM_ENABLE_MODULES enabled.

resolves: rdar://129031201
2024-05-30 23:19:46 -07:00
Nikita Popov
71ccd0d8cc
[IRInterpreter] Return zero address for missing weak function (#93548)
If a weak function is missing, still return it's address (zero) rather
than failing interpretation. Otherwise we have a mismatch between
Interpret() and CanInterpret() resulting in failures that would not
occur with JIT execution.

Alternatively, we could try to look for weak symbols in CanInterpret()
and generally reject them there.

This is the root cause for the issue exposed by
https://github.com/llvm/llvm-project/pull/92885. Previously, the case
affected by that always fell back to JIT because an icmp constant
expression was used, which is not supported by the interpreter. Now a
normal icmp instruction is used, which is supported. However, we fail to
interpret due to incorrect handling of weak function addresses.
2024-05-31 08:18:35 +02:00
Malay Sanghi
089dfeee8a
[X86] Add support for MS inp functions. (#93804)
support _inp, _inpw, _inpd.
These functions were removed from the Windows runtime library, but aare
still supported for kernel mode development.
2024-05-31 14:11:33 +08:00
Zixu Wang
1fa073ab89
[MachO] Stop parsing past end of rebase/bind table (#93897)
`MachORebaseEntry::moveNext()` and `MachOBindEntry::moveNext()` assume
that the rebase/bind table ends with `{REBASE|BIND}_OPCODE_DONE` or an
actual rebase/bind. However a valid rebase/bind table might also end
with other effectively no-op opcodes, which caused the parser to move
past the end and go into the next table, resulting in corrupted entries
or infinite loops.
2024-05-30 23:08:01 -07:00
Owen Pan
c5fdb5c34e
[clang-format] Insert a space between a keyword and a literal (#93632)
Fixes #93603.
2024-05-30 22:13:00 -07:00
Florian Hahn
461cc8612f
[LAA] Add test where stride is also used for BTC.
Add missing test coverage for follow-up to
https://github.com/llvm/llvm-project/pull/93499.
2024-05-30 21:05:31 -07:00
Jianjian Guan
db6de1a20f
[DAGCombiner][VP] Add DAGCombine for VP_MUL (#80105)
Use visitMUL to combine VP_MUL, share most logic of MUL with VP_MUL.

Migrate from https://reviews.llvm.org/D121187
2024-05-31 10:17:11 +08:00
gulfemsavrun
aa98c75da4
Revert "[clang][AST] fix ast-print of extern <lang> with >=2 declarators" (#93912)
Reverts llvm/llvm-project#93131 because it broke some lldb tests on the
Fuchsia Clang toolchain builders.

https://ci.chromium.org/ui/p/fuchsia/builders/toolchain.ci/clang-linux-x64/b8746482644341901905/infra
2024-05-30 18:51:52 -07:00
Amir Ayupov
e9954ec087 [BOLT] Detect .warm split functions as cold fragments (#93759)
CDSplit splits functions up to three ways: main fragment with no suffix,
and fragments with .cold and .warm suffixes.

Add .warm suffix to the regex used to recognize split fragments.

Test Plan: updated register-fragments-bolt-symbols.s
2024-05-30 17:48:12 -07:00
Florian Hahn
f38d84ce32
[VPlan] Use ir-bb prefix for VPIRBasicBlock.
Follow-up to adjust the names and tests after
https://github.com/llvm/llvm-project/pull/93398.
2024-05-30 17:43:40 -07:00
Akira Hatanaka
e1c3e16d24
[clang] Fix a crash when a variable is captured by a block nested inside a lambda (#93749)
`Eval->Value.get` returns a null pointer when the variable doesn't have
an initializer. Use `cast_if_present` instead of `cast`.

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

rdar://128482541
2024-05-30 16:52:37 -07:00
Aaron Siddhartha Mondal
852aaf5407
Reapply "[Support] Remove terminfo dependency (#92865)" (#93889)
This reverts commit fe82a3da36196157c0caa1ef2505186782f750d1.

This broke LLDB on MacOS due to a missing symbol during linking.

The fix has been applied in c6c08eee37bada190bd1aa4593c88a5e2c8cdaac.

Original commit message:

The terminfo dependency introduces a significant nonhermeticity into the
build. It doesn't respect `--no-undefined-version` meaning that it's not
a dependency that can be built with Clang 17+. This forces maintainers
of source-based distributions to implement patches or ignore linker
errors.

Remove it to reduce the closure size and improve portability of
LLVM-based tools. Users can still use command line arguments to toggle
color support expliticly.

Fixes #75490
Closes #53294 #23355
2024-05-31 01:29:00 +02:00
Jorge Gorbe Moya
d4ff9615a1 Add missing #include for ObjCMethodDecl.
DeclBase.h only contains a forward declaration of ObjCMethodDecl, and
when building clang/Sema/Attr.h with header modules this causes a build
failure because `llvm::isa<ObjCMethodDecl>` requires the full type.
2024-05-30 15:42:57 -07:00
S. Bharadwaj Yadavalli
235ddbd138
[DirectX] [Docs] Add DXILOpTableGenDesign.rst to toctree of DirectXUsage. (#93864)
Fix doc build failure.
2024-05-30 18:42:15 -04:00
David Blaikie
d9fbccf9a9 Fix test on MacOS where -fstandalone-debug is the default
This test is meant to check the behavior when -fno-standalone-debug is
active - it doesn't care whether it's explicit or implicit, so let's
make it explicit so it applies equally to MacOS and other platforms.
2024-05-30 22:33:54 +00:00
Matt Arsenault
419d363385
AMDGPU: Add kernarg input attributes to preloaded kernarg test (#93669)
Explicitly mark the unused implicit arguments in the test, since this
should be sensitive to the number of free user SGPRs.

This is in preparation for #83131.
2024-05-30 23:50:24 +02:00
Sterling Augustine
fc2b15987b Send output to a temp file, even in the error case
Prior to this, the test tries to write to the source directory,
which prevents it from working when the source is on a read-only
file systems.
2024-05-30 21:44:06 +00:00
shaw young
629b6f4eb1
[BOLT][NFC] Extend updateLayoutIndices (#93861)
Make FunctionLayout::updateLayoutIndices const and add an overloaded
function that updates LayoutIndices given an Order parameter.
2024-05-30 14:35:29 -07:00
Kazu Hirata
90acfbf90d
[memprof] Use linear IDs for Frames and call stacks (#93740)
With this patch, we stop using on-disk hash tables for Frames and call
stacks.  Instead, we'll write out all the Frames as a flat array while
maintaining mappings from FrameIds to the indexes into the array.
Then we serialize call stacks in terms of those indexes.

Likewise, we'll write out all the call stacks as another flat array
while maintaining mappings from CallStackIds to the indexes into the
call stack array.  One minor difference from Frames is that the
indexes into the call stack array are not contiguous because call
stacks are variable-length objects.

Then we serialize IndexedMemProfRecords in terms of the indexes
into the call stack array.

Now, we describe each call stack with 32-bit indexes into the Frame
array (as opposed to the 64-bit FrameIds in Version 2).  The use of
the smaller type cuts down the profile file size by about 40% relative
to Version 2.  The departure from the on-disk hash tables contributes
a little bit to the savings, too.

For now, IndexedMemProfRecords refer to call stacks with 64-bit
indexes into the call stack array.  As a follow-up, I'll change that
to uint32_t, including necessary updates to RecordWriterTrait.
2024-05-30 14:28:22 -07:00
Fangrui Song
d5f077cf52 [ELF] Simplify assignOffsets. NFC 2024-05-30 14:27:47 -07:00
Stanislav Mekhanoshin
215f92b979
[AMDGPU] Fix crash in the SILoadStoreOptimizer (#93862)
It does not properly handle situation when address calculation uses
V_ADDC_U32 0, 0, carry-in (i.e. with both src0 and src1 immediates).
2024-05-30 14:27:33 -07:00
Fangrui Song
c4dad9a6b6 [DirectX] Fix BitcodeWriter ctor after #92983 2024-05-30 14:22:50 -07:00
Fangrui Song
f795853d1f raw_ostream: Fix a comment in llvm::errs
https://reviews.llvm.org/D81156 tied errs() to outs().
030897523d43e3296f69d25a71a140d9e5793c6a removed the tie, but did not
update the comment.
2024-05-30 14:16:28 -07:00
Keith Smiley
031f08c0a5
[bazel] Port #93567 (#93877) 2024-05-30 13:52:25 -07:00
Miro Bucko
493eefc93f
[lldb][test] Fix failing test TestAddressRange.py (#93871)
Test llvm-project/lldb/test/API/python_api/address_range/TestAddressRange.py is failing on Windows due adding a carriage return character at the end of line. Original PR is #93836.
2024-05-30 13:44:51 -07:00
Fangrui Song
167cad531d [ELF] Improve ADDR tests
Merge some test files.
The "undefined section" error (`checkIfExists`) was previously untested.
2024-05-30 13:43:15 -07:00
Craig Topper
8247068b70
[RISCV] Support (truncate (smin (smax X, C1), C2)) for vnclipu in combineTruncToVnclip. (#93756)
If the smax removed all negative numbers, then we can treat the smin
like a umin.

If the smin and smax are in the other order we can swap them and use a
vnclipu as long as the smax constant is smaller than the smin constant.

This is based on similar code from X86's detectUSatPattern.
2024-05-30 15:41:07 -05:00
David Blaikie
6e975ecf5c Reapply "[DebugInfo] Add flag to only emit referenced member functions" (#93767)
This reverts commit 02c6845c762dfd0a19d4a2f997990e160f392dae,
reapplying bfabc958c7c0d7ddc15f23383d9da836e8c6093f.

The patch was reverted due to the test failing on MacOS and Windows
where type units aren't supported. This is addressed by limiting type
unit flag/test coverage to Linux.

Complete C++ type information can be quite expensive - and there's
limited value in representing every member function, even those that
can't be called (we don't do similarly for every non-member function
anyway). So add a flag to opt out of this behavior for experimenting
with this more terse behavior.

I think Sony already does this by default, so perhaps with a change to
the defaults, Sony can migrate to this rather than a downstream patch.

This breaks current debuggers in some expected ways - but those
breakages are visible without this feature too. Consider member function
template instantiations - they can't be consistently enumerated in every
translation unit:

a.h:
```
struct t1 {
  template <int i>
  static int f1() {
    return i;
  }
};
namespace ns {
template <int i>
int f1() {
  return i;
}
}  // namespace ns
```
a.cpp:
```
void f1() {
  t1::f1<0>();
  ns::f1<0>();
}
```
b.cpp:
```
void f1();
int main() {
  f1();
  t1::f1<1>();
  ns::f1<1>();
}
```
```
(gdb) p ns::f1<0>()
$1 = 0
(gdb) p ns::f1<1>()
$2 = 1
(gdb) p t1::f1<0>()
Couldn't find method t1::f1<0>
(gdb) p t1::f1<1>()
$3 = 1
(gdb) s
f1 () at a.cpp:3
3         t1::f1<0>();
(gdb) p t1::f1<0>()
$4 = 0
(gdb) p t1::f1<1>()
Couldn't find method t1::f1<1>
(gdb)
```

(other similar non-canonical features are implicit special members
(copy/move ctor/assignment operator, default ctor) and nested types (eg:
pimpl idiom, where the nested type is declared-but-not-defined in one
TU, and defined in another TU))

lldb can't parse the template expressions above, so I'm not sure how to
test it there, but I'd guess it has similar problems. (

https://stackoverflow.com/questions/64602475/how-to-print-value-returned-by-template-member-function-in-gdb-lldb-debugging
so... I guess that's just totally not supported in lldb, how
unfortunate. And implicit special members are instantiated implicitly by
lldb, so missing those doesn't tickle the same issue)

Some very rudimentary numbers for a clang debug build:
.debug_info section size:
-g: 476MiB
-g -fdebug-types-section: 357MiB
-g -gomit-unreferenced-members: 340MiB

Though it also means a major reduction in .debug_str size,
-fdebug-types-section doesn't reduce string usage (so the first two
examples have the same .debug_str size, 247MiB), down to 175MiB.

So for total clang binary size (I don't have a quick "debug section size
reduction" on-hand): 1.45 (no type units) GiB -> 1.34 -> 1.22, so it
saves about 120MiB of binary size.

Original Differential Revision: https://reviews.llvm.org/D152017
2024-05-30 20:36:47 +00:00
Keith Smiley
d471860f2d
[bazel] Port #92983 (#93874) 2024-05-30 13:35:03 -07:00
Nick Desaulniers (paternity leave)
6f576d957e
[libc] android atest compat (#93852)
These changes slighly modify the output of the unittests so that they better
match GTest, so that utilities that parse the expected output from GTest (such
as Android's unit test harness) can read the output from our unit tests.

This allows our unit tests to be run on Android devices.

Add very primitive command line parsing to:
- support --gtest_color=no to disable printing terminal colors.
- recognize --gtest_print_time and print the test time in milliseconds.
  - most of our unit tests run on the order of microseconds, so its useful to
    preserve the existing behavior.  But upsteram GTest ONLY prints time tests
    in milliseconds, and Android's atest expects to be able to parse exactly
    that. Atest always passes --gtest_print_time. The word `took` is removed as
    that also differs from upstream GTest, tripping up parsers.
- ignore other --gtest_* flags

Do so so that atest can parse the output correctly.

Print the test number count before
each run, so that atest can parse this value correctly.

Link: https://android-review.googlesource.com/c/platform/external/llvm-libc/+/3107252
Link: https://google.github.io/googletest/advanced.html#colored-terminal-output
Link: https://google.github.io/googletest/advanced.html#suppressing-the-elapsed-time
2024-05-30 13:28:11 -07:00
Adrian Prantl
22ada554d5
[dsymutil] Also detect external downloadable toolchains (#93872)
and reject them when copying Swift interface files, since they can live
outside of DEVELOPER_DIR.
2024-05-30 13:20:57 -07:00