platform/upstream/llvm.git
13 months ago[lldb] Take StringRef name in GetIndexOfChildMemberWithName (NFC)
Dave Lee [Sun, 28 May 2023 19:08:19 +0000 (12:08 -0700)]
[lldb] Take StringRef name in GetIndexOfChildMemberWithName (NFC)

Change the type of the `name` parameter from `char *` to `StringRef`.

Follow up to D151615.

Differential Revision: https://reviews.llvm.org/D151810

13 months ago[Fuchsia] Add llvm-debuginfod to toolchain
Daniel Thornburgh [Tue, 30 May 2023 21:20:46 +0000 (14:20 -0700)]
[Fuchsia] Add llvm-debuginfod to toolchain

13 months ago[RISCV] Lower extern_weak symbols using the GOT for the medany model
Jessica Clarke [Wed, 31 May 2023 17:30:36 +0000 (18:30 +0100)]
[RISCV] Lower extern_weak symbols using the GOT for the medany model

Such symbols may be undefined at link time and thus resolve to 0, which
may be further than 2GiB away from PC, causing the immediate to be out
of range for PC-relative addressing. Using the GOT avoids this, and is
the approach taken by AArch64.

Reviewed By: asb, MaskRay, arichardson

Differential Revision: https://reviews.llvm.org/D107280

13 months ago[RISCV] Add new lga pseudoinstruction
Jessica Clarke [Wed, 31 May 2023 17:30:27 +0000 (18:30 +0100)]
[RISCV] Add new lga pseudoinstruction

This mirrors lla and is always GOT-relative, allowing an explicit
request to use the GOT without having to expand the instruction. This
then means la is just defined in terms of lla and lga in the assembler,
based on whether PIC is enabled, and at the codegen level we replace la
entirely with lga since we only ever use la there when we want to load
from the GOT (and assert that to be the case).

See https://github.com/riscv-non-isa/riscv-asm-manual/issues/50

Reviewed By: asb, MaskRay

Differential Revision: https://reviews.llvm.org/D107278

13 months ago[RISCV] Add test showing the current extern_weak lowering
Jessica Clarke [Wed, 31 May 2023 17:30:19 +0000 (18:30 +0100)]
[RISCV] Add test showing the current extern_weak lowering

Reviewed By: asb, MaskRay

Differential Revision: https://reviews.llvm.org/D107279

13 months ago[mlir] Avoid folding `index.remu` and `index.rems` for 0 rhs
rikhuijzer [Wed, 31 May 2023 17:45:05 +0000 (10:45 -0700)]
[mlir] Avoid folding `index.remu` and `index.rems` for 0 rhs

As discussed in https://github.com/llvm/llvm-project/issues/59714#issuecomment-1369518768, the folder for the remainder operations should be resillient when the rhs is 0.
The file `IndexOps.cpp` was already checking for multiple divisions by zero, so I tried to stick to the code style from those checks.

Fixes #59714.

As a side note, is it correct that remainder operations are never optimized away? I would expect that the following code

```
func.func @remu_test() -> index {
  %c3 = index.constant 2
  %c0 = index.constant 1
  %0 = index.remu %c3, %c0
  return %0 : index
}
```
would be optimized to
```
func.func @remu_test() -> index {
  return index.constant 0 : index
}
```
when called with `mlir-opt --convert-scf-to-openmp temp.mlir`, but maybe I'm misunderstanding something.

Reviewed By: Mogball

Differential Revision: https://reviews.llvm.org/D151476

13 months ago[flang] CUDA Fortran - part 3/5: declarations checking
Peter Klausler [Sat, 6 May 2023 22:03:39 +0000 (15:03 -0700)]
[flang] CUDA Fortran - part 3/5: declarations checking

Implements checks for CUDA Fortran attributes on objects, types, and
subprograms.  Includes a couple downgrades of existing errors into
warnings that were exposed during testing.

Depends on https://reviews.llvm.org/D150159 &
https://reviews.llvm.org/D150161.

Differential Revision: https://reviews.llvm.org/D150162

13 months ago[ARM][AArch64] Add tests for shuffles load patterns. NFC
David Green [Wed, 31 May 2023 17:42:01 +0000 (18:42 +0100)]
[ARM][AArch64] Add tests for shuffles load patterns. NFC

See D151029

13 months ago[LoadStoreVectorizer] Fix index width != pointer width case
Krzysztof Drewniak [Tue, 30 May 2023 21:01:21 +0000 (21:01 +0000)]
[LoadStoreVectorizer] Fix index width != pointer width case

Fixes https://github.com/llvm/llvm-project/issues/62856

Reviewed By: jlebar

Differential Revision: https://reviews.llvm.org/D151754

13 months agoRevert "[ThinLTO] Disable partial sample profile scaling by default"
Teresa Johnson [Wed, 31 May 2023 16:09:27 +0000 (09:09 -0700)]
Revert "[ThinLTO] Disable partial sample profile scaling by default"

This reverts commit aae8524bcc26cf04729f2bbc02ecb54233a587e4, which was
found to cause a few unexpected benchmark performance differences that
need investigation.

13 months ago[flang] CUDA Fortran - part 2/5: symbols & scopes
Peter Klausler [Sat, 6 May 2023 22:03:39 +0000 (15:03 -0700)]
[flang] CUDA Fortran - part 2/5: symbols & scopes

Add representations of CUDA Fortran data and subprogram attributes
to the symbol table and scopes of semantics.  Set them in name
resolution, and emit them to module files.

Depends on https://reviews.llvm.org/D150159.

Differential Revision: https://reviews.llvm.org/D150161

13 months ago[RISCV][InsertVSETVLI] Relax tail policy more often for vmv.s.x
Luke Lau [Wed, 31 May 2023 17:04:25 +0000 (17:04 +0000)]
[RISCV][InsertVSETVLI] Relax tail policy more often for vmv.s.x

If a vm.s.x pseudo has an undef passthru operand, then we're free to use
whatever tail policy we want for VL > 1. We previously relaxed the tail
policy for this but only when we could also expand the SEW.
This patch changes it to relax the tail policy even if the SEW can't be
expanded and removes a few more toggles, as well as fully moving the
vmv.s.x logic into getDemanded.

13 months ago[RISCV][InsertVSETVLI] Avoid vmv.s.x SEW toggle if at start of block
Luke Lau [Wed, 31 May 2023 14:29:28 +0000 (14:29 +0000)]
[RISCV][InsertVSETVLI] Avoid vmv.s.x SEW toggle if at start of block

vmv.s.x/vfmv.s.f instructions that only write to the first destination
element can use any SEW greater than or equal to its original SEW,
provided that it's writing to an implicit_def operand where we can
clobber the other lanes.

We were already handling this in needVSETVLI, which meant that when
scanning the instructions from top to bottom we could detect this and
avoid the toggle:

vsetivli zero, 4, e64, mf2, ta, ma
li a0, 11
vsetivli zero, 1, e8, mf8, ta, ma
vmv.s.x v0, a0

->
vsetivli zero, 4, e64, mf2, ta, ma
li a0, 11
vmv.s.x v0, a0
The issue that this patch aims to solve is arises when the vmv.s.x is
the first vector instruction in the block and doesn't have any prior
predecessor info:

entry_bb:
li a0, 11
; No previous state here: forced to set VL/VTYPE
vsetivli zero, 1, e8, mf8, ta, ma
vmv.s.x v0, a0
vsetivli zero, 4, e16, mf2, ta, ma
vmerge.vvm v8, v9, v8, v0
doLocalPostpass can work backwards from bottom to top and work out if
an earlier vsetvli can be mutated to avoid a toggle. It uses
DemandedFields and getDemanded for this, which previously didn't take
into account the possibility of going to a larger SEW.

A previous patch consolidated the vmv.s.x logic from needVSETVLI logic
into getDemanded, and this patch removes the gate around it so that
doLocalPostpass can now delete vsetvlis like in the scenario below:

entry_bb:
li a0, 11
; Previous vsetivli mutated: second one deleted
vsetivli zero, 4, e16, mf2, ta, ma
vmv.s.x v0, a0
vmerge.vvm v8, v9, v8, v0

Differential Revision: https://reviews.llvm.org/D151561

13 months ago[RISCV][InsertVSETVLI] Move vmv.s.x SEW check into getDemandedBits. NFC
Luke Lau [Fri, 26 May 2023 12:58:04 +0000 (12:58 +0000)]
[RISCV][InsertVSETVLI] Move vmv.s.x SEW check into getDemandedBits. NFC

This patch restructures the logic that checks if vmv.s.x's SEW can be
expanded into getDemandedBits, so that it can be shared by both the
top-to-bottom and bottom-to-top passes.

It adds a third option for SEW in DemandedFields, that's weaker than
demanded but stronger than not demanded, that states that it the new SEW
must be greater than or equal to the current SEW.

Note that we now need to take care of the order of operands in
areCompatibleVTYPEs as the relation is no longer commutative.

A later patch will remove the gating on the bottom-to-top pass
(dolocalPostpass) and another one will relax the demands on the tail
policy further.

13 months ago[NFC][CLANG] Fix nullptr dereference issue in SetValueDataBasedOnQualType()
Manna, Soumi [Wed, 31 May 2023 17:11:14 +0000 (10:11 -0700)]
[NFC][CLANG] Fix nullptr dereference issue in SetValueDataBasedOnQualType()

This patch uses castAs instead of getAs which will assert if the type doesn't match in SetValueDataBasedOnQualType(clang::Value &, unsigned long long).

Reviewed By: erichkeane

Differential Revision: https://reviews.llvm.org/D151770

13 months agoRevert "[RISCV] Add Zvfhmin extension for clang."
Craig Topper [Wed, 31 May 2023 17:02:12 +0000 (10:02 -0700)]
Revert "[RISCV] Add Zvfhmin extension for clang."

This reverts commit 35a0079238ce9fc36cdc8c6a2895eb5538bf7b4a.

The backend support is not present yet. The intrinsics will crash
the compiler if compiled to assembly or binary.

13 months agoRevert "[RISCV][InsertVSETVLI] Avoid vmv.s.x SEW toggle if at start of block"
Luke Lau [Wed, 31 May 2023 17:14:55 +0000 (18:14 +0100)]
Revert "[RISCV][InsertVSETVLI] Avoid vmv.s.x SEW toggle if at start of block"

This reverts commit 0ba41dd3806e658e67acb63353fd5540f2bf333c.

13 months ago[RISCV][InsertVSETVLI] Avoid vmv.s.x SEW toggle if at start of block
Luke Lau [Wed, 31 May 2023 17:04:25 +0000 (17:04 +0000)]
[RISCV][InsertVSETVLI] Avoid vmv.s.x SEW toggle if at start of block

vmv.s.x and friends that only write to the first destination element can
use any SEW greater than or equal to its original SEW, provided that
it's writing to an implicit_def operand where we can clobber the other
lanes.

We were already handling this in needVSETVLI, which meant that when
scanning the instructions from top to bottom we could detect this and
avoid the toggle:

```
vsetivli zero, 4, e64, mf2, ta, ma
li a0, 11
vsetivli zero, 1, e8, mf8, ta, ma
vmv.s.x v0, a0

->
vsetivli zero, 4, e64, mf2, ta, ma
li a0, 11
vmv.s.x v0, a0

```
The issue that this patch aims to solve is whenever vmv.s.x arises when
the first vector instruction in the block and doesn't have any prior
predecessor info:

```
entry_bb:
li a0, 11
; No previous state here: forced to set VL/VTYPE
vsetivli zero, 1, e8, mf8, ta, ma
vmv.s.x v0, a0
vsetivli zero, 4, e16, mf2, ta, ma
vmerge.vvm v8, v9, v8, v0
```

doLocalPostpass can work backwards from bottom to top and work out if
an earlier vsetvli can be mutated to avoid a toggle. It uses
DemandedFields and getDemanded for this, which previously didn't take
into account the possibility of going to a larger SEW.

This patch adds a third option for SEW in DemandedFields, that's weaker
than demanded but stronger than not demanded, that states that it the
new SEW must be greater than or equal to the current SEW.

We can then use this option to move that vmv.s.x specific logic from
needVSETVLI into getDemanded, making it available for both phase 2 and
3, i.e. we can now mutate the earlier vsetivli going from bottom to top:

```
entry_bb:
li a0, 11
; Previous vsetivli mutated: second one deleted
vsetivli zero, 4, e16, mf2, ta, ma
vmv.s.x v0, a0
vmerge.vvm v8, v9, v8, v0
```

Reviewed By: reames

Differential Revision: https://reviews.llvm.org/D151561

13 months ago[NFC][CLANG] Fix nullptr dereference issue in HandleRISCVRVVVectorBitsTypeAttr()
Manna, Soumi [Wed, 31 May 2023 16:54:51 +0000 (09:54 -0700)]
[NFC][CLANG] Fix nullptr dereference issue in HandleRISCVRVVVectorBitsTypeAttr()

This patch uses castAs instead of getAs which will assert if the type doesn't match in HandleRISCVRVVVectorBitsTypeAttr(clang::QualType &, clang::ParsedAttr &, clang::Sema &)

Reviewed By: erichkeane

Differential Revision: https://reviews.llvm.org/D151769

13 months ago[Demangle] fix deref of std::string_view::end()
Nick Desaulniers [Wed, 31 May 2023 16:44:13 +0000 (09:44 -0700)]
[Demangle] fix deref of std::string_view::end()

In D148546, I replaced much of the use of llvm::StringView w/
std::string_view.  There's one important semantic difference between the
two:

In most STL containers, end() returns an iterator that refers to one
past the end of the container. But llvm::StringView::end() refers to the
last element.

Expressions such as `&*my_std_string_view.end()` produce the failed
assertion:

  include/c++/v1/__iterator/bounded_iter.h:93: assertion
  __in_bounds(__current_) failed: __bounded_iter::operator*: Attempt to
  dereference an out-of-range iterator

This was caught when copying the recent downstream changes back upstream
in D148566, and is reproducible via:

  $ libcxx/utils/ci/run-buildbot generic-debug-mode

when compiled with clang and clang++. The correct way to get the same
value as before without dereferencing invalid iterators is to prefer
`&*my_std_string_view.rbegin() + 1`.

Fix this downstream so that I might copy it back upstream in D148566.

The other instance of `&*my_std_string_view.end()` that I introduced in
D148546 has been fixed already in D149061.

Reviewed By: ashay-github

Differential Revision: https://reviews.llvm.org/D151760

13 months ago[flang] CUDA Fortran - part 1/5: parsing
Peter Klausler [Sat, 6 May 2023 22:03:39 +0000 (15:03 -0700)]
[flang] CUDA Fortran - part 1/5: parsing

Begin upstreaming of CUDA Fortran support in LLVM Flang.

This first patch implements parsing for CUDA Fortran syntax,
including:
 - a new LanguageFeature enum value for CUDA Fortran
 - driver change to enable that feature for *.cuf and *.CUF source files
 - parse tree representation of CUDA Fortran syntax
 - dumping and unparsing of the parse tree
 - the actual parsers for CUDA Fortran syntax
 - prescanning support for !@CUF and !$CUF
 - basic sanity testing via unparsing and parse tree dumps

... along with any minimized changes elsewhere to make these
work, mostly no-op cases in common::visitors instances in
semantics and lowering to allow them to compile in the face
of new types in variant<> instances in the parse tree.

Because CUDA Fortran allows the kernel launch chevron syntax
("call foo<<<blocks, threads>>>()") only on CALL statements and
not on function references, the parse tree nodes for CallStmt,
FunctionReference, and their shared Call were rearranged a bit;
this caused a fair amount of one-line changes in many files.

More patches will follow that implement CUDA Fortran in the symbol
table and name resolution, and then semantic checking.

Differential Revision: https://reviews.llvm.org/D150159

13 months agoFix -u option in dsymutil, to not emit an extra DW_LNE_set_address if the original...
Shubham Sandeep Rastogi [Fri, 26 May 2023 19:05:09 +0000 (12:05 -0700)]
Fix -u option in dsymutil, to not emit an extra DW_LNE_set_address if the original line table was empty

With dsymutil's -u option, only the accelerator tables should be
updated, but with https://reviews.llvm.org/D150554 the -u option will
still re-generate the line table. If the line table was empty, that is,
it was a dummy line table, with no entries in it, dsymutil will always
generate a line table with a DW_LNE_end_sequence, a funky side effect of
this is that when the line table is re-generated, it will always emit a
DW_LNE_set_address first, which will change the line table total size.
This patch addresses this by making sure that if all the line table has
in it is a DW_LNE_end_sequence, it is the same as a dummy entry.

Differential Revision: https://reviews.llvm.org/D151579

13 months ago[gn build] Port 8e728adcfedd
LLVM GN Syncbot [Wed, 31 May 2023 16:33:01 +0000 (16:33 +0000)]
[gn build] Port 8e728adcfedd

13 months ago[MLIR][Linalg] (NFC) Improve RUN command in `generalize-pad-tensor.mlir`
Lorenzo Chelini [Wed, 31 May 2023 15:34:13 +0000 (17:34 +0200)]
[MLIR][Linalg] (NFC) Improve RUN command in `generalize-pad-tensor.mlir`

There is no need to specify any `check-prefix` here.

13 months agoworkflows/release-tasks: Upload lit releases to pypi
Tom Stellard [Wed, 31 May 2023 16:13:04 +0000 (09:13 -0700)]
workflows/release-tasks: Upload lit releases to pypi

Reviewed By: thieta, kwk

Differential Revision: https://reviews.llvm.org/D146491

13 months ago[flang] Fix interpretations of x87 80-bit Inf/NaN
Peter Klausler [Fri, 26 May 2023 15:50:35 +0000 (08:50 -0700)]
[flang] Fix interpretations of x87 80-bit Inf/NaN

Current implementations of x87 80-bit extended precision floating
point interpret 7FFF8000000000000000 as +Inf, not a Nan.  The explicit
MSB in the significand must be set for an infinity.

Differential Revision: https://reviews.llvm.org/D151739

13 months agoclang/openmp: Fix alignment for ThreadID Address variables
Tom Stellard [Wed, 31 May 2023 16:11:07 +0000 (09:11 -0700)]
clang/openmp: Fix alignment for ThreadID Address variables

There are places in the runtime, like __kmp_init_indirect_csptr, which
assume these pointers are aligned to sizeof(void*), so make sure we emit
them with the correct alignment.

Fixes #62668

Reviewed By: jlpeyton

Differential Revision: https://reviews.llvm.org/D150723

13 months ago[compiler-rt][CMake] Properly set COMPILER_RT_HAS_LLD
Arthur Eubanks [Thu, 23 Feb 2023 19:21:33 +0000 (11:21 -0800)]
[compiler-rt][CMake] Properly set COMPILER_RT_HAS_LLD

LLVM_TOOL_LLD_BUILD is a relic of the pre-monorepo times. This causes us to never set COMPILER_RT_HAS_LLD.

Instead, set it from the runtimes build if lld is being built and lld is used as the compiler-rt linker.

Reviewed By: MaskRay

Differential Revision: https://reviews.llvm.org/D144660

13 months ago[flang] Detect output field width overflow for Inf/NaN
Peter Klausler [Thu, 25 May 2023 23:23:22 +0000 (16:23 -0700)]
[flang] Detect output field width overflow for Inf/NaN

The output editing code paths for F and E/D output that handle
IEEE-754 infinities and NaNs fail to check for overflow of the
output field, which should cause the field to be filled with
asterisks instead.  Catch these cases.

Differential Revision: https://reviews.llvm.org/D151738

13 months ago[Sema] Remove unused function getFloat128Identifier
Kazu Hirata [Wed, 31 May 2023 15:59:35 +0000 (08:59 -0700)]
[Sema] Remove unused function getFloat128Identifier

The last use was removed by:

  commit bb1ea2d6139a72340b426e114510c46d938645a6
  Author: Nemanja Ivanovic <nemanja.i.ibm@gmail.com>
  Date:   Mon May 9 08:52:33 2016 +0000

Differential Revision: https://reviews.llvm.org/D151608

13 months agoRevert "[compiler-rt] Avoid memintrinsic calls inserted by the compiler"
Marco Elver [Wed, 31 May 2023 15:57:07 +0000 (17:57 +0200)]
Revert "[compiler-rt] Avoid memintrinsic calls inserted by the compiler"

This reverts commit 4369de7af46605522bf7dbe3bc31d00b0eb4bee6.

Fails on Mac OS with "sanitizer_libc.cpp:109:5: error: aliases are not
supported on darwin".

13 months ago[Clang][SVE2.1] Add clang support for builtins using svcount_t
Caroline Concatto [Wed, 31 May 2023 14:12:08 +0000 (14:12 +0000)]
[Clang][SVE2.1] Add clang support for builtins  using svcount_t

In this patch it is used for the prototype:
  * svptrue_c8 (and _c16/_c32/_c64)

 As described in: https://github.com/ARM-software/acle/pull/257

Patch by: Sander de Smalen <sander.desmalen@arm.com>

Reviewed By: sdesmalen, david-arm

Differential Revision: https://reviews.llvm.org/D150953

13 months ago[flang] Don't fold SIZE()/SHAPE() into expression referencing optional dummy arguments
Peter Klausler [Thu, 25 May 2023 23:01:52 +0000 (16:01 -0700)]
[flang] Don't fold SIZE()/SHAPE() into expression referencing optional dummy arguments

When computing the shape of an expression at compilation time as part of
folding an intrinsic function like SIZE(), don't create an expression that
increases a dependence on the presence of an optional dummy argument.

Differential Revision: https://reviews.llvm.org/D151737

13 months ago[KnownBits] Also test 1-bit values in exhaustive tests (NFC)
Nikita Popov [Wed, 31 May 2023 08:10:47 +0000 (10:10 +0200)]
[KnownBits] Also test 1-bit values in exhaustive tests (NFC)

Similar to what we do with ConstantRanges, also test 1-bit values
in exhaustive tests, as these often expose special conditions.
This would have exposed the assertion failure fixed in D151788
earlier.

13 months ago[RISCV] Fix an unused variable warning
Kazu Hirata [Wed, 31 May 2023 15:45:29 +0000 (08:45 -0700)]
[RISCV] Fix an unused variable warning

 llvm-project/llvm/lib/Target/RISCV/RISCVISelLowering.cpp:3793:7:
 error: unused variable 'XLenVT' [-Werror,-Wunused-variable]

13 months ago[X86] X86FixupVectorConstantsPass - use VBROADCASTSS/VBROADCASTSD for integer vector...
Simon Pilgrim [Wed, 31 May 2023 14:33:44 +0000 (15:33 +0100)]
[X86] X86FixupVectorConstantsPass - use VBROADCASTSS/VBROADCASTSD for integer vector loads on AVX1-only targets

Matches behaviour in lowerBuildVectorAsBroadcast

13 months ago[libc++]{CI] Bumps clang-tidy version used.
Mark de Wever [Sun, 28 May 2023 12:23:12 +0000 (14:23 +0200)]
[libc++]{CI] Bumps clang-tidy version used.

The CI can no longer run with clang-tidy 16 increment it to version 17.
Whether permanently moving to the latest development version is being
discussed on Discourse.

Depends on D149455

Reviewed By: #libc, ldionne

Differential Revision: https://reviews.llvm.org/D151628

13 months ago[libc++][test] Prefers the newer clang-tidy version.
Mark de Wever [Fri, 28 Apr 2023 15:38:47 +0000 (17:38 +0200)]
[libc++][test] Prefers the newer clang-tidy version.

Module require Clang 17, since Clang 16 requires the magic # __FILE__
line. Therefore, if available, use clang-tidy 17 too. This change should
be reverted after LLVM 17 is released.

Reviewed By: #libc, ldionne

Differential Revision: https://reviews.llvm.org/D149455

13 months ago[libc++] Gives ignore external linkage.
Mark de Wever [Thu, 25 May 2023 19:59:25 +0000 (21:59 +0200)]
[libc++] Gives ignore external linkage.

A slightly different fix is in D144994.

Reviewed By: #libc, ldionne

Differential Revision: https://reviews.llvm.org/D151490

13 months ago[libc++] Fixes use-after move diagnostic.
Mark de Wever [Tue, 23 May 2023 15:14:20 +0000 (17:14 +0200)]
[libc++] Fixes use-after move diagnostic.

The diagnostic is issued by clang-tidy 17.

This just suppressed the diagnostic. The move operations are non-standard extensions and the class itself is deprecated.

Reviewed By: #libc, ldionne

Differential Revision: https://reviews.llvm.org/D151223

13 months ago[lldb] Override GetVariable in ValueObjectSynthetic (NFC)
Dave Lee [Sat, 20 May 2023 17:05:44 +0000 (10:05 -0700)]
[lldb] Override GetVariable in ValueObjectSynthetic (NFC)

Make `GetVariable` a passthrough function the the underlying value object in `ValueObjectSynthetic`.

Differential Revision: https://reviews.llvm.org/D151384

13 months ago[APInt] Support zero-width extract in extractBitsAsZExtValue()
Nikita Popov [Wed, 31 May 2023 08:16:16 +0000 (10:16 +0200)]
[APInt] Support zero-width extract in extractBitsAsZExtValue()

D111241 added support for extractBits() with zero width. Extend this
to extractBitsAsZExtValue() as well for consistency (in which case
it will always return zero).

Differential Revision: https://reviews.llvm.org/D151788

13 months ago[gn] port 4369de7af466
Nico Weber [Wed, 31 May 2023 15:12:32 +0000 (11:12 -0400)]
[gn] port 4369de7af466

13 months ago[lldb] Take StringRef name in GetChildMemberWithName (NFC)
Dave Lee [Sat, 27 May 2023 04:19:10 +0000 (21:19 -0700)]
[lldb] Take StringRef name in GetChildMemberWithName (NFC)

`GetChildMemberWithName` does not need a `ConstString`. This change makes the function
take a `StringRef` instead, which alleviates the need for callers to construct a
`ConstString`. I don't expect this change to improve performance, only ergonomics.

This is in support of Alex's effort to replace `ConstString` where appropriate.

There are related `ValueObject` functions that can also be changed, if this is accepted.

Differential Revision: https://reviews.llvm.org/D151615

13 months ago[Flang] Move several definitions to IntrinsicCall header for code cleanliness and...
Paul Scoropan [Tue, 30 May 2023 15:07:44 +0000 (15:07 +0000)]
[Flang] Move several definitions to IntrinsicCall header for code cleanliness and reusability

In the future we intend to add support for many PowerPC-specific intrinsics that ideally will exist in a separate new PPCIntrinsicCall file. But first we need to move definitions to the IntrinsicCall header file to increase code cleanliness and readability and to make code reusable for when we add PPCIntrinsicCall.

Reviewed By: vzakhari

Differential Revision: https://reviews.llvm.org/D151715

13 months ago[LV] Use SCEV for uniformity analysis across VF
Florian Hahn [Wed, 31 May 2023 15:00:57 +0000 (16:00 +0100)]
[LV] Use SCEV for uniformity analysis across VF

This patch uses SCEV to check if a value is uniform across a given VF.

The basic idea is to construct SCEVs where the AddRecs of the loop are
adjusted to reflect the version in the vectorized loop (Step multiplied
by VF). We construct a SCEV for the value of the vector lane 0
(offset 0) compare it to the expressions for lanes 1 to the last vector
lane (VF - 1). If they are equal, consider the expression uniform.

While re-writing expressions, we also need to catch expressions we
cannot determine uniformity (e.g. SCEVUnknown).

Reviewed By: Ayal

Differential Revision: https://reviews.llvm.org/D148841

13 months ago[compiler-rt] Avoid memintrinsic calls inserted by the compiler
Marco Elver [Tue, 30 May 2023 09:59:22 +0000 (11:59 +0200)]
[compiler-rt] Avoid memintrinsic calls inserted by the compiler

D135716 introduced -ftrivial-auto-var-init=pattern where supported.
Unfortunately this introduces unwanted memset() for large stack arrays,
as shown by the new tests added for asan and msan (tsan already had this
test).

In general, the problem of compiler-inserted memintrinsic calls
(memset/memcpy/memmove) is not new to compiler-rt, and has been a
problem before.

To avoid introducing unwanted memintrinsic calls, we redefine
memintrinsics as __sanitizer_internal_mem* at the assembly level for
most source files automatically (where sanitizer_common_internal_defs.h
is included).

In few cases, redefining a symbol in this way causes issues for
interceptors, namely the memintrinsic interceptor themselves. For such
source files we have to selectively disable the redefinition.

Other alternatives have been considered, but simply do not work well in
the context of compiler-rt:

1. Linker --wrap:  this does not work because --wrap only
   applies to the final link, and would not apply when building
   sanitizer static libraries.

2. Changing references to memset() via objcopy:  this may work,
   but due to the complexities of the build system, introducing
   such a post-processing step for the right object files (in
   particular object files defining memset cannot be touched)
   seems infeasible.

The chosen solution works well (as shown by the tests). Other libraries
have chosen the same solution where nothing else works (see e.g. glibc's
"symbol-hacks.h").

v2:
- Fix ubsan_minimal build where compiler decides to insert
  memset/memcpy: ubsan_minimal has work without RTSanitizerCommonLibc,
  therefore do not redefine the builtins.
- Fix definition of internal_mem* functions with compilers that want the
  aliased function to already be defined before.
- Fix definition of __sanitizer_internal_mem* functions with compilers
  more pedantic about attribute placement around extern "C".

Reviewed By: vitalybuka, dvyukov

Differential Revision: https://reviews.llvm.org/D151152

13 months ago[TableGen] Add !getdagarg and !getdagname
Michael Liao [Fri, 26 May 2023 16:58:12 +0000 (12:58 -0400)]
[TableGen] Add !getdagarg and !getdagname

- This patch proposes to add `!getdagarg` and `!getdagname` bang
  operators as the inverse operation of `!dag`. They allow us to examine
  arguments of a given dag.

Reviewed By: simon_tatham

Differential Revision: https://reviews.llvm.org/D151602

13 months ago[RISCV] Use v(f)slide1down for shuffle+insert idiom
Philip Reames [Wed, 31 May 2023 14:48:17 +0000 (07:48 -0700)]
[RISCV] Use v(f)slide1down for shuffle+insert idiom

This is a follow up to D151468 which added the vslide1down case as a sub-case of vslide1down matching. This generalizes that code into generic mask matching - specifically to point out the sub-vector insert restriction in the original patch. Since the matching logic is basically the same, go ahead and support vslide1up at the same time.

Differential Revision: https://reviews.llvm.org/D151742

13 months ago[InstCombine] Name instructions in test (NFC)
Nikita Popov [Wed, 31 May 2023 14:39:41 +0000 (16:39 +0200)]
[InstCombine] Name instructions in test (NFC)

13 months ago[Analysis] Remove unused class LegacyAARGetter
Kazu Hirata [Wed, 31 May 2023 14:30:14 +0000 (07:30 -0700)]
[Analysis] Remove unused class LegacyAARGetter

The last use was removed by:

  commit fa6ea7a419f37befbed04368bcb8af4c718facbb
  Author: Arthur Eubanks <aeubanks@google.com>
  Date:   Mon Mar 20 11:18:35 2023 -0700

Once we remove it, createLegacyPMAAResults and createLegacyPMAAResults
become unused, so this patch removes them as well.

Differential Revision: https://reviews.llvm.org/D151787

13 months ago[ELF][RISCV] --wrap=foo: Correctly update st_value(foo)
Fangrui Song [Wed, 31 May 2023 14:19:44 +0000 (07:19 -0700)]
[ELF][RISCV] --wrap=foo: Correctly update st_value(foo)

With --wrap=foo, we may have `d->file != file` for a defined symbol `foo`.
For the object file defining `foo`, its symbol table may not contain
`foo` after `redirectSymbols` changed the `foo` entry to `__wrap_foo` (see D50569).

Therefore, skipping `foo` with the condition `if (!d || d->file != file)` may
cause `__wrap_foo` not to be updated. See `ab.o w.o --wrap=foo` in the new test
(originally reported by D150220).

We could adjust the condition to `if (!d)`, but that would leave many `anchors`
entries if a symbol is referenced by many files. Switch to iterating over
`symtab` instead.

Note: D149735 (actually not NFC) allowed duplicate `anchors` entries and fixed
`a.o bw.o --wrap=foo`.

Reviewed By: jobnoorman

Differential Revision: https://reviews.llvm.org/D151768

13 months ago[flang] use greedy mlir driver for stack arrays pass
Tom Eccles [Wed, 17 May 2023 16:07:41 +0000 (16:07 +0000)]
[flang] use greedy mlir driver for stack arrays pass

In upstream mlir, the dialect conversion infrastructure is used for
lowering from one dialect to another: the passes are of the form
XToYPass. Whereas, transformations within the same dialect tend to use
applyPatternsAndFoldGreedily.

In this case, the full complexity of applyPatternsAndFoldGreedily isn't
needed so we can get away with the simpler applyOpPatternsAndFold.

This change was suggested by @jeanPerier

The old differential revision for this patch was
https://reviews.llvm.org/D150853

Re-applying here fixing the issue which led to the patch being reverted. The
issue was from erasing uses of the allocation operation while still iterating
over those uses (leading to a use-after-free). I have added a regression
test which catches this bug for -fsanitize=address builds, but it is
hard to reliably cause a crash from the use-after-free in normal builds.

Differential Revision: https://reviews.llvm.org/D151728

13 months ago[Headers][doc] Fix typo in avx2intrin.h doc
Paul Robinson [Wed, 31 May 2023 13:43:27 +0000 (06:43 -0700)]
[Headers][doc] Fix typo in avx2intrin.h doc

13 months ago[MLIR] Remove dependency on omp dialect in LLVM dialect.
Jan Sjodin [Tue, 30 May 2023 19:28:12 +0000 (14:28 -0500)]
[MLIR] Remove dependency on omp dialect in LLVM dialect.

This fixes a buildbot failure where the dependency on the omp dialect
in the LLVM dialect caused error. Instead of accessing the interface
defined in the omp dialect we directly access the attributes
instead. To make this work the IsDeviceAttr is removed and replaced
with a BoolAttr instead.

Reviewed By: kiranchandramohan

Differential Revision: https://reviews.llvm.org/D151745

13 months ago[Headers][doc] Add shuffle-like intrinsic descriptions to avx2intrin.h
Paul Robinson [Tue, 30 May 2023 20:30:12 +0000 (13:30 -0700)]
[Headers][doc] Add shuffle-like intrinsic descriptions to avx2intrin.h

Differential Revision: https://reviews.llvm.org/D151749

13 months ago[Test] Move LoopStrengthReduce/pr62563.ll to X86 specific test folder (NFC)
Dmitry Makogon [Wed, 31 May 2023 13:23:19 +0000 (20:23 +0700)]
[Test] Move LoopStrengthReduce/pr62563.ll to X86 specific test folder (NFC)

The test case is X86 specific. Should unblock buildbots after 253e3e2.

13 months ago[ConstraintElim] Move logic to remove stack entry to helper (NFC).
Florian Hahn [Wed, 31 May 2023 13:22:44 +0000 (14:22 +0100)]
[ConstraintElim] Move logic to remove stack entry to helper (NFC).

Preparation for follow-up patch that uses the logic in a separate place.

13 months ago[AA] Fix comparison of AliasResults (PR63019)
Nikita Popov [Wed, 31 May 2023 12:53:44 +0000 (14:53 +0200)]
[AA] Fix comparison of AliasResults (PR63019)

Comparison between two AliasResults implicitly decayed to comparison
of AliasResult::Kind. As a result, MergeAliasResults() ended up
considering two PartialAlias results with different offsets as
equivalent.

Fix this by adding an operator== implementation. To stay
compatible with extensive use of comparisons between AliasResult
and AliasResult::Kind, add an overload for that as well, which
will ignore the offset. In the future, it would probably be a
good idea to remove these implicit decays to AliasResult::Kind
and add dedicated methods to check for specific AliasResult kinds.

Fixes https://github.com/llvm/llvm-project/issues/63019.

13 months ago[GVN] Add test for PR63019 (NFC)
Nikita Popov [Wed, 31 May 2023 12:55:11 +0000 (14:55 +0200)]
[GVN] Add test for PR63019 (NFC)

13 months agoImplement BufferOverlap check for sprint/snprintf
Arnaud Bienner [Wed, 31 May 2023 08:54:27 +0000 (10:54 +0200)]
Implement BufferOverlap check for sprint/snprintf

Differential Revision: https://reviews.llvm.org/D150430

13 months ago[gn build] Port 26bda9e95a9d
LLVM GN Syncbot [Wed, 31 May 2023 12:30:10 +0000 (12:30 +0000)]
[gn build] Port 26bda9e95a9d

13 months ago[GlobalIsel][X86] Legalize G_CTLZ and G_CTPOP for 32-bit
Thorsten Schütt [Thu, 25 May 2023 15:47:00 +0000 (17:47 +0200)]
[GlobalIsel][X86] Legalize G_CTLZ and G_CTPOP for 32-bit

Note that 32-bit support is very limited

Reviewed By: RKSimon

Differential Revision: https://reviews.llvm.org/D151459

13 months ago[gn] port 301eb6b68f3 (AttrTokenKinds.inc)
Nico Weber [Wed, 31 May 2023 12:17:44 +0000 (08:17 -0400)]
[gn] port 301eb6b68f3 (AttrTokenKinds.inc)

13 months ago[mlir] Avoid tensor canonicalizer crash on negative dimensions
rikhuijzer [Wed, 31 May 2023 12:13:08 +0000 (14:13 +0200)]
[mlir] Avoid tensor canonicalizer crash on negative dimensions

Fixes #59703.

Reviewed By: ftynse

Differential Revision: https://reviews.llvm.org/D151611

13 months ago[libc][NFC] Fixing various typos
Guillaume Chatelet [Wed, 31 May 2023 12:06:45 +0000 (12:06 +0000)]
[libc][NFC] Fixing various typos

13 months ago[X86] Replace X32 test check prefix with X86
Simon Pilgrim [Wed, 31 May 2023 12:01:27 +0000 (13:01 +0100)]
[X86] Replace X32 test check prefix with X86

We try to only use X32 for gnux32 triple test cases

13 months ago[X86] Replace X32 test check prefixes with X86
Simon Pilgrim [Wed, 31 May 2023 12:00:23 +0000 (13:00 +0100)]
[X86] Replace X32 test check prefixes with X86

We try to only use X32 for gnux32 triple test cases

13 months ago[mlir][bazel] Disable Transform/test-repro-dump.mlir test in bazel build.
Benjamin Chetioui [Wed, 31 May 2023 11:50:48 +0000 (11:50 +0000)]
[mlir][bazel] Disable Transform/test-repro-dump.mlir test in bazel build.

13 months ago[Test] Add test showing miscompilation in LoopStrengthReduce on min/max expressions...
Dmitry Makogon [Wed, 31 May 2023 11:42:21 +0000 (18:42 +0700)]
[Test] Add test showing miscompilation in LoopStrengthReduce on min/max expressions (NFC)

This is a test case from https://github.com/llvm/llvm-project/issues/62563.

13 months ago[X86] printConstant - fix asm comment issue when broadcasting from a wider constant...
Simon Pilgrim [Wed, 31 May 2023 11:28:17 +0000 (12:28 +0100)]
[X86] printConstant - fix asm comment issue when broadcasting from a wider constant pool entry

In cases where a broadcast op is loading from a constant entry wider than the broadcast element, we were incorrectly printing the entire entry and not just the lower bits referenced by the broadcast.

13 months ago[X86] getTargetConstantBitsFromNode - ensure we truncate broadcasts from wider constants.
Simon Pilgrim [Wed, 31 May 2023 10:41:20 +0000 (11:41 +0100)]
[X86] getTargetConstantBitsFromNode - ensure we truncate broadcasts from wider constants.

We might be broadcasting the lower portion of a wider constant pool entry, ensure we truncate the full width of the constant back to the broadcast width.

(This also exposes an issue with how asm comments print these constants - I'll address that in a followup).

Fixes #63030

13 months ago[X86] Replace X32 test check prefixes with X86
Simon Pilgrim [Wed, 31 May 2023 09:56:41 +0000 (10:56 +0100)]
[X86] Replace X32 test check prefixes with X86

We try to only use X32 for gnux32 triple test cases

13 months agoRevert "[clang][Interp] Optionally cast comparison result to non-bool"
Timm Bäder [Wed, 31 May 2023 11:07:19 +0000 (13:07 +0200)]
Revert "[clang][Interp] Optionally cast comparison result to non-bool"

This reverts commit 81522a012accfcc6bbf4dfa21a793aea6e4e532a.

Looks like we're not ready for this yet:
https://lab.llvm.org/buildbot/#/builders/139/builds/41797

13 months ago[clang][Interp] Optionally cast comparison result to non-bool
Timm Bäder [Tue, 2 May 2023 11:35:00 +0000 (13:35 +0200)]
[clang][Interp] Optionally cast comparison result to non-bool

Our comparison opcodes always produce a Boolean value and push it on the
stack. However, the result of such a comparison in C is int, so the
later code expects an integer value on the stack.

Work around this problem by casting the boolean value to int in those
cases. This is not ideal for C however. The comparison is usually
wrapped in a IntegerToBool cast anyway.

Differential Revision: https://reviews.llvm.org/D149645

13 months ago[bazel] Port for 301eb6b68f30074ee3a90e2dfbd11dfd87076323
Haojian Wu [Wed, 31 May 2023 10:49:21 +0000 (12:49 +0200)]
[bazel] Port for 301eb6b68f30074ee3a90e2dfbd11dfd87076323

13 months ago[clang][Interp] Add missing static_assert messages
Timm Bäder [Wed, 31 May 2023 10:27:58 +0000 (12:27 +0200)]
[clang][Interp] Add missing static_assert messages

13 months agoReapply [SelectionDAG] Handle NSW for ADD/SUB in computeKnownBits()
Dhruv Chawla [Wed, 17 May 2023 13:12:11 +0000 (15:12 +0200)]
Reapply [SelectionDAG] Handle NSW for ADD/SUB in computeKnownBits()

This exposed a miscompile due to incorrect flag preservation in
integer type legalization, which has been fixed in D151472.

-----

This patch is a continuation of D150110. It separates the cases for
ADD and SUB into their own cases so that computeForAddSub can be
directly called and the NSW flag passed. This allows better
optimization when the NSW flag is enabled, and allows fixing up the
TODO that was there previously in SimplifyDemandedBits.

Differential Revision: https://reviews.llvm.org/D150769

13 months agoRevert "[compiler-rt] Avoid memintrinsic calls inserted by the compiler"
Marco Elver [Wed, 31 May 2023 10:16:58 +0000 (12:16 +0200)]
Revert "[compiler-rt] Avoid memintrinsic calls inserted by the compiler"

This reverts commit e614d5667f6c6fc6c645587cb9aee1a058285454.

Build bot failures:

| FAILED: lib/clang/17/lib/linux/libclang_rt.ubsan_minimal-i386.so
| : && /usr/bin/clang++ -fPIC -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -Wall -Wno-unused-parameter -O3 -DNDEBUG  -Wl,-z,defs -Wl,-z,nodelete   -m32 -nodefaultlibs -Wl,-z,text -nostdlib++ -shared -Wl,-soname,libclang_rt.ubsan_minimal-i386.so -o lib/clang/17/lib/linux/libclang_rt.ubsan_minimal-i386.so projects/compiler-rt/lib/ubsan_minimal/CMakeFiles/RTUbsan_minimal.i386.dir/ubsan_minimal_handlers.cpp.o  -lgcc_s  -lc && :
| /usr/bin/ld: projects/compiler-rt/lib/ubsan_minimal/CMakeFiles/RTUbsan_minimal.i386.dir/ubsan_minimal_handlers.cpp.o: in function `__ubsan_handle_type_mismatch_minimal':
| /b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm-project/compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cpp:120: undefined reference to `__sanitizer_internal_memcpy'
| /usr/bin/ld: projects/compiler-rt/lib/ubsan_minimal/CMakeFiles/RTUbsan_minimal.i386.dir/ubsan_minimal_handlers.cpp.o: in function `__ubsan_handle_type_mismatch_minimal_abort':
| /b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm-project/compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cpp:120: undefined reference to `__sanitizer_internal_memcpy'
| /usr/bin/ld: projects/compiler-rt/lib/ubsan_minimal/CMakeFiles/RTUbsan_minimal.i386.dir/ubsan_minimal_handlers.cpp.o: in function `__ubsan_handle_alignment_assumption_minimal':
| /b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm-project/compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cpp:121: undefined reference to `__sanitizer_internal_memcpy'
| /usr/bin/ld: projects/compiler-rt/lib/ubsan_minimal/CMakeFiles/RTUbsan_minimal.i386.dir/ubsan_minimal_handlers.cpp.o: in function `__ubsan_handle_alignment_assumption_minimal_abort':
| /b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm-project/compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cpp:121: undefined reference to `__sanitizer_internal_memcpy'
| /usr/bin/ld: projects/compiler-rt/lib/ubsan_minimal/CMakeFiles/RTUbsan_minimal.i386.dir/ubsan_minimal_handlers.cpp.o: in function `__ubsan_handle_add_overflow_minimal':
| /b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm-project/compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cpp:122: undefined reference to `__sanitizer_internal_memcpy'
| /usr/bin/ld: projects/compiler-rt/lib/ubsan_minimal/CMakeFiles/RTUbsan_minimal.i386.dir/ubsan_minimal_handlers.cpp.o:/b/sanitizer-x86_64-linux-bootstrap-msan/build/llvm-project/compiler-rt/lib/ubsan_minimal/ubsan_minimal_handlers.cpp:122: more undefined references to `__sanitizer_internal_memcpy' follow

Link: https://lab.llvm.org/buildbot#builders/74/builds/19569
13 months ago[Assignment Tracking] Ignore stores to a negative offset from an alloca
OCHyams [Thu, 25 May 2023 09:48:22 +0000 (10:48 +0100)]
[Assignment Tracking] Ignore stores to a negative offset from an alloca

Fixes crash reported in llvm.org/PR62838.

Reviewed By: jryans

Differential Revision: https://reviews.llvm.org/D151326

13 months ago[clang][Interp] Track frame depth
Timm Bäder [Mon, 17 Apr 2023 13:23:37 +0000 (15:23 +0200)]
[clang][Interp] Track frame depth

Save the depth of each InterpFrame and bail out if we're too deep.

Differential Revision: https://reviews.llvm.org/D148614

13 months ago[gn] Port e614d5667f6c
Nico Weber [Wed, 31 May 2023 10:07:38 +0000 (06:07 -0400)]
[gn] Port e614d5667f6c

13 months ago[compiler-rt] Avoid memintrinsic calls inserted by the compiler
Marco Elver [Tue, 30 May 2023 09:59:22 +0000 (11:59 +0200)]
[compiler-rt] Avoid memintrinsic calls inserted by the compiler

D135716 introduced -ftrivial-auto-var-init=pattern where supported.
Unfortunately this introduces unwanted memset() for large stack arrays,
as shown by the new tests added for asan and msan (tsan already had this
test).

In general, the problem of compiler-inserted memintrinsic calls
(memset/memcpy/memmove) is not new to compiler-rt, and has been a
problem before.

To avoid introducing unwanted memintrinsic calls, we redefine
memintrinsics as __sanitizer_internal_mem* at the assembly level for
most source files automatically (where sanitizer_common_internal_defs.h
is included).

In few cases, redefining a symbol in this way causes issues for
interceptors, namely the memintrinsic interceptor themselves. For such
source files we have to selectively disable the redefinition.

Other alternatives have been considered, but simply do not work well in
the context of compiler-rt:

1. Linker --wrap:  this does not work because --wrap only
   applies to the final link, and would not apply when building
   sanitizer static libraries.

2. Changing references to memset() via objcopy:  this may work,
   but due to the complexities of the build system, introducing
   such a post-processing step for the right object files (in
   particular object files defining memset cannot be touched)
   seems infeasible.

The chosen solution works well (as shown by the tests). Other libraries
have chosen the same solution where nothing else works (see e.g. glibc's
"symbol-hacks.h").

Reviewed By: vitalybuka, dvyukov

Differential Revision: https://reviews.llvm.org/D151152

13 months ago[clang] Add Parse and Sema support for RegularKeyword attributes
Richard Sandiford [Tue, 4 Apr 2023 13:05:13 +0000 (14:05 +0100)]
[clang] Add Parse and Sema support for RegularKeyword attributes

This patch adds the Parse and Sema support for RegularKeyword attributes,
following on from a previous patch that added Attr.td support.

The patch is quite large.  However, nothing outside the tests is
specific to the first RegularKeyword attribute (__arm_streaming).
The patch should therefore be a one-off, up-front cost.  Other
attributes just need an entry in Attr.td and the usual Sema support.

The approach taken in the patch is that the keywords can be used with
any language version.  If standard attributes were added in language
version Y, the keyword rules for version X<Y are the same as they were
for version Y (to the extent possible).  Any extensions beyond Y are
handled in the same way for both keywords and attributes.  This ensures
that existing C++11 successors like C++17 are not treated differently
from versions that have yet to be defined.

Some notes on the implementation:

* The patch emits errors rather than warnings for diagnostics that
relate to keywords.

* Where possible, the patch drops “attribute” from diagnostics
relating to keywords.

* One exception to the previous point is that warnings about C++
extensions do still mention attributes.  The use there seemed OK
since the diagnostics are noting a change in the production rules.

* If a diagnostic string needs to be different for keywords and
attributes, the patch standardizes on passing the attribute/
name/token followed by 0 for attributes and 1 for keywords.

* Although the patch updates warn_attribute_wrong_decl_type_str,
warn_attribute_wrong_decl_type, and warn_attribute_wrong_decl_type,
only the error forms of these strings are used for keywords.

* I couldn't trigger the warnings in checkUnusedDeclAttributes,
even for existing attributes.  An assert on the warnings caused
no failures in the testsuite.  I think in practice all standard
attributes would be diagnosed before this.

* The patch drops a call to standardAttributesAllowed in
ParseFunctionDeclarator.  This is because MaybeParseCXX11Attributes
checks the same thing itself, where appropriate.

* The new tests are based on c2x-attributes.c and
cxx0x-attributes.cpp.  The C++ test also incorporates a version of
cxx11-base-spec-attributes.cpp.  The FIXMEs are carried across from
the originals.

Differential Revision: https://reviews.llvm.org/D148702

13 months ago[clang] Add support for “regular” keyword attributes
Richard Sandiford [Wed, 19 Apr 2023 10:03:42 +0000 (11:03 +0100)]
[clang] Add support for “regular” keyword attributes

Platform-specific language extensions often want to provide a way of
indicating that certain functions should be called in a different way,
compiled in a different way, or otherwise treated differently from a
“normal” function.  Honoring these indications is often required for
correctness, rather being than an optimization/QoI thing.

If a function declaration has a property P that matters for correctness,
it will be ODR-incompatible with a function that does not have property P.
If a function type has a property P that affects the calling convention,
it will not be two-way compatible with a function type that does not
have property P.  These properties therefore affect language semantics.
That in turn means that they cannot be treated as standard [[]]
attributes.

Until now, many of these properties have been specified using GNU-style
attributes instead.  GNU attributes have traditionally been more lax
than standard attributes, with many of them having semantic meaning.
Examples include calling conventions and the vector_size attribute.

However, there is a big drawback to using GNU attributes for semantic
information: compilers that don't understand the attributes will
(by default) emit a warning rather than an error.  They will go on to
compile the code as though the attributes weren't present, which will
inevitably lead to wrong code in most cases.  For users who live
dangerously and disable the warning, this wrong code could even be
generated silently.

A more robust approach would be to specify the properties using
keywords, which older compilers would then reject.  Some vendor-specific
extensions have already taken this approach.  But traditionally, each
such keyword has been treated as a language extension in its own right.
This has three major drawbacks:

(1) The parsing rules need to be kept up-to-date as the language evolves.

(2) There are often corner cases that similar extensions handle differently.

(3) Each extension requires more custom code than a standard attribute.

The underlying problem for all three is that, unlike for true attributes,
there is no established template that extensions can reuse.  The purpose
of this patch series is to try to provide such a template.

One option would have been to pick an existing keyword and do whatever
that keyword does.  The problem with that is that most keywords only
apply to specific kinds of types, kinds of decls, etc., and so the
parsing rules are (for good reason) not generally applicable to all
types and decls.

Really, the “only” thing wrong with using standard attributes is that
standard attributes cannot affect semantics.  In all other respects
they provide exactly what we need: a well-defined grammar that evolves
with the language, clear rules about what an attribute appertains to,
and so on.

This series therefore adds keyword “attributes” that can appear
exactly where a standard attribute can appear and that appertain
to exactly what a standard attribute would appertain to.  The link is
mechanical and no opt-outs or variations are allowed.  This should
make the keywords predictable for programmers who are already
familiar with standard attributes.

This does mean that these keywords will be accepted for parsing purposes
in many more places than necessary.  Inappropriate uses will then be
diagnosed during semantic analysis.  However, the compiler would need
to reject the keywords in those positions whatever happens, and treating
them as ostensible attributes shouldn't be any worse than the alternative.
In some cases it might even be better.  For example, SME's
__arm_streaming attribute would make conceptual sense as a statement
attribute, so someone who takes a “try-it-and-see” approach might write:

  __arm_streaming { …block-of-code…; }

In fact, we did consider supporting this originally.  The reason for
rejecting it was that it was too difficult to implement, rather than
because it didn't make conceptual sense.

One slight disadvantage of the keyword-based approach is that it isn't
possible to use #pragma clang attribute with the keywords.  Perhaps we
could add support for that in future, if it turns out to be useful.

For want of a better term, I've called the new attributes "regular"
keyword attributes (in the sense that their parsing is regular wrt
standard attributes), as opposed to "custom" keyword attributes that
have their own parsing rules.

This patch adds the Attr.td support for regular keyword attributes.
Adding an attribute with a RegularKeyword spelling causes tablegen
to define the associated tokens and to record that attributes created
with that syntax are regular keyword attributes rather than custom
keyword attributes.

A follow-on patch contains the main Parse and Sema support,
which is enabled automatically by the Attr.td definition.

Other notes:

* The series does not allow regular keyword attributes to take
arguments, but this could be added in future.

* I wondered about trying to use tablegen for
TypePrinter::printAttributedAfter too, but decided against it.
RegularKeyword is really a spelling-level classification rather
than an attribute-level classification, and in general, an attribute
could have both GNU and RegularKeyword spellings.  In contrast,
printAttributedAfter is only given the attribute kind and the type
that results from applying the attribute.  AFAIK, it doesn't have
access to the original attribute spelling.  This means that some
attribute-specific or type-specific knowledge might be needed
to print the attribute in the best way.

* Generating the tokens automatically from Attr.td means that
pseudo's libgrammar does now depend on tablegen.

* The patch uses the SME __arm_streaming attribute as an example
for testing purposes.  The attribute does not do anything at this
stage.  Later SME-specific patches will add proper semantics for it,
and add other SME-related keyword attributes.

Differential Revision: https://reviews.llvm.org/D148700

13 months ago[clang] Mark keywords that have their own parsing rules
Richard Sandiford [Tue, 4 Apr 2023 08:13:04 +0000 (09:13 +0100)]
[clang] Mark keywords that have their own parsing rules

This patch retroactively classifies all existing keyword attributes
as “custom” keyword attributes, in the sense that the keywords have
their own custom parsing rules.  A follow-on patch will add an
alternative type of keyword.

No functional change intended.

Differential Revision: https://reviews.llvm.org/D148699

13 months ago[clang][Interp] Fix diagnosing uninitialized ctor record arrays
Timm Bäder [Sun, 5 Feb 2023 10:03:48 +0000 (11:03 +0100)]
[clang][Interp] Fix diagnosing uninitialized ctor record arrays

Differential Revision: https://reviews.llvm.org/D143334

13 months agoFix link in transform example README.md
Oleksandr "Alex" Zinenko [Wed, 31 May 2023 09:39:26 +0000 (11:39 +0200)]
Fix link in transform example README.md

13 months ago[LangRef] fix the function result attributes location explanation and examples (NFC)
khei4 [Wed, 31 May 2023 03:26:11 +0000 (12:26 +0900)]
[LangRef] fix the function result attributes location explanation and examples (NFC)
Differential Revision: https://reviews.llvm.org/D151772

13 months ago[IndVars] Check expansion safety in makeIVComparisonInvariant() (PR62992)
Nikita Popov [Wed, 31 May 2023 09:18:53 +0000 (11:18 +0200)]
[IndVars] Check expansion safety in makeIVComparisonInvariant() (PR62992)

Make sure the invariant expressions are safe to expand. In
particular, we should not speculative a trapping division into
the preheader.

Fixes https://github.com/llvm/llvm-project/issues/62992.

13 months ago[mlir] drop debug tags after TransformInterpreterPassBase
Alex Zinenko [Wed, 31 May 2023 08:45:05 +0000 (08:45 +0000)]
[mlir] drop debug tags after TransformInterpreterPassBase

The pass attaches attributes to operations for repro generation
purposes, but never removes them. This is not desirable when the pass
actually succeeds.

Reviewed By: nicolasvasilache

Differential Revision: https://reviews.llvm.org/D151791

13 months ago[mlir] fix documentation includes
Alex Zinenko [Wed, 31 May 2023 08:58:16 +0000 (08:58 +0000)]
[mlir] fix documentation includes

13 months ago[clang][Diagnostics][NFC] Move variable decl into if statement
Timm Bäder [Wed, 24 May 2023 15:27:08 +0000 (17:27 +0200)]
[clang][Diagnostics][NFC] Move variable decl into if statement

13 months ago[MemoryBuiltins] Handle phi nodes without operands (PR63013)
Nikita Popov [Wed, 31 May 2023 08:44:56 +0000 (10:44 +0200)]
[MemoryBuiltins] Handle phi nodes without operands (PR63013)

Conservatively return unknown in this degenerate case. This is
hard to hit in practice, because such phis are usually optimized
away before they reach a getObjectSize() call.

Fixes https://github.com/llvm/llvm-project/issues/63013.

13 months ago[clang][Diagnostics][NFC] Move Buf{Start,End} out of the loop
Timm Bäder [Wed, 24 May 2023 06:16:04 +0000 (08:16 +0200)]
[clang][Diagnostics][NFC] Move Buf{Start,End} out of the loop

They don't change inside the loop.

13 months ago[clang][Diagnostics][NFC] Remove unnecessary StringRef
Timm Bäder [Wed, 24 May 2023 07:03:26 +0000 (09:03 +0200)]
[clang][Diagnostics][NFC] Remove unnecessary StringRef

Seems unnecessary to create a StringRef here just so we can drop the
trailing null bytes. We can do that with the std::string we
create anyway.

Differential Revision: https://reviews.llvm.org/D151300

13 months ago[clang][Diagnostics] Print empty lines in multiline snippets
Timm Bäder [Wed, 24 May 2023 06:45:31 +0000 (08:45 +0200)]
[clang][Diagnostics] Print empty lines in multiline snippets

We should preserve empty lines in output snippets.

Differential Revision: https://reviews.llvm.org/D151301

13 months ago[clang][Diagnostics][NFC] Don't create oversized CaretLine
Timm Bäder [Wed, 24 May 2023 04:44:35 +0000 (06:44 +0200)]
[clang][Diagnostics][NFC] Don't create oversized CaretLine

Instead of creating a CaretLine the size of the SourceLine, just leave
it empty at first, let HighlightRange resize it to fit all the ~, then
resize it to fit the ^. Then we can save ourselves the work to remove
the trailing whitespace again.

Differential Revision: https://reviews.llvm.org/D151286

13 months ago[mlir][bazel] Follow-up fix for ce954e1cda5c9b55325903d51285cd742152a0c3.
Benjamin Chetioui [Wed, 31 May 2023 08:19:26 +0000 (08:19 +0000)]
[mlir][bazel] Follow-up fix for ce954e1cda5c9b55325903d51285cd742152a0c3.

13 months ago[mlir] small cleanup of transform dialect docs
Alex Zinenko [Wed, 31 May 2023 08:19:09 +0000 (08:19 +0000)]
[mlir] small cleanup of transform dialect docs