platform/upstream/llvm.git
11 months agoWork around two more instances of __noinline__ conflicts. (#66138)
Artem Belevich [Tue, 12 Sep 2023 20:35:07 +0000 (13:35 -0700)]
Work around two more instances of __noinline__ conflicts. (#66138)

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

(cherry picked from commit 588023ddafb4b0cd11914ab068c6d07187374d69)

11 months ago[lldb] Fix building LLDB standlone without framework
Alex Langford [Mon, 31 Jul 2023 23:30:17 +0000 (16:30 -0700)]
[lldb] Fix building LLDB standlone without framework

In a809720102fae8d1b5a7073f99f9dae9395c5f41 I refactored some logic to
deal with the clang resource directory in standalone LLDB builds.
However, this logic escaped me because it only runs when you do not
build LLDB.framework.

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

(cherry picked from commit 6888de118707e6392b46073fc35738804f9f1d80)

11 months ago[lldb][NFCI] Change logic to find clang resource dir in standalone builds
Alex Langford [Tue, 25 Jul 2023 22:38:04 +0000 (15:38 -0700)]
[lldb][NFCI] Change logic to find clang resource dir in standalone builds

As of 0beffb854209a41f31beb18f9631258349a99299 there is a CMake
function to actually calculate the relative path to the clang resource
directory. Currently we have some bespoke logic that looks in a few
places, but with this new function we should be able to eliminate some
complexity here.

Also, I moved the functionality from LLDBConfig to LLDBStandalone since
it is only used in standalone builds.

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

(cherry picked from commit a809720102fae8d1b5a7073f99f9dae9395c5f41)

11 months ago[XCOFF] Do not generate the special .ref for zero-length sections (#66805)
Wael Yehia [Thu, 28 Sep 2023 05:33:41 +0000 (01:33 -0400)]
[XCOFF] Do not generate the special .ref for zero-length sections (#66805)

Co-authored-by: Wael Yehia <wyehia@ca.ibm.com>
(cherry picked from commit da55b1b52fbce80093eee8dd4185df4861a44ba5)

11 months agoFix buildbot failure caused by D157623
duk [Thu, 10 Aug 2023 20:33:43 +0000 (16:33 -0400)]
Fix buildbot failure caused by D157623

GCC doesn't like the implicit conversion here.

(cherry picked from commit f11f90d5f4ebfab2b44bf3c98b2d2162acf81e2c)

11 months ago[lld][COFF] Remove incorrect flag from EHcont table
namazso [Thu, 10 Aug 2023 20:00:58 +0000 (16:00 -0400)]
[lld][COFF] Remove incorrect flag from EHcont table

Fixes EHCont implementation in LLD. Closes #64570

Reviewed By: rnk

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

(cherry picked from commit e335c78ec2848e24b10e32e015a84347c69c8130)

11 months agoworkflows/release-tasks: Setup FileCheck and not for release-lit (#66799)
Tulio Magno Quites Machado Filho [Mon, 25 Sep 2023 17:03:34 +0000 (14:03 -0300)]
workflows/release-tasks: Setup FileCheck and not for release-lit (#66799)

lit tests require commands FileCheck and not. They must be available in
the PATH.

This also guarantees that python3-psutil is installed in order to enable
more tests.

Fixes #64892.

(cherry picked from commit b2247f85dc4b187dd0ebc93059a0aa42f35dd64a)

11 months ago[StackColoring] Handle fixed object index
Nikita Popov [Fri, 22 Sep 2023 10:25:56 +0000 (12:25 +0200)]
[StackColoring] Handle fixed object index

This is a followup to #66988. The implementation there did not
account for the possibility of the catch object frame index
referrring to a fixed object, which is the case on win64.

(cherry picked from commit aa70f4d8cf8f09a2997773156289b16d6a16ec01)

11 months ago[StackColoring] Handle SEH catch object stack slots conservatively
Nikita Popov [Thu, 21 Sep 2023 07:13:27 +0000 (09:13 +0200)]
[StackColoring] Handle SEH catch object stack slots conservatively

The write to the SEH catch object happens before cleanuppads are
executed, while the first reference to the object will typically
be in a catchpad.

If we make use of first-use analysis, we may end up allocating
an alloca used inside the cleanuppad and the catch object at the
same stack offset, which would be incorrect.

https://reviews.llvm.org/D86673 was a previous attempt to fix it.
It used the heuristic "a slot loaded in a WinEH pad and never
written" to detect catch objects. However, because it checks
for more than one load (while probably more than zero was
intended), the fix does not actually work.

The general approach also seems dubious to me, so this patch
reverts that change entirely, and instead marks all catch object
slots as conservative (i.e. excluded from first-use analysis)
based on the WinEHFuncInfo. As far as I can tell we don't need
any heuristics here, we know exactly which slots are affected.

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

(cherry picked from commit b3cb4f069c2cb99bdae68d6906156af20e76314f)

11 months ago[X86] Add test for #66984 (NFC)
Nikita Popov [Thu, 21 Sep 2023 07:13:27 +0000 (09:13 +0200)]
[X86] Add test for #66984 (NFC)

(cherry picked from commit 8b4e29b35d21b079e8b30244cbbfc4d4bc4a29d4)

11 months ago[SimpleLoopUnswitch] Fix exponential unswitch
Nikita Popov [Wed, 20 Sep 2023 09:41:42 +0000 (11:41 +0200)]
[SimpleLoopUnswitch] Fix exponential unswitch

When unswitching via invariant condition injection, we currently
mark the condition in the old loop, so that it does not get
unswitched again. However, if there are multiple branches for
which conditions can be injected, then we can do that for both
the old and new loop. This means that the number of unswitches
increases exponentially.

Change the handling to be more similar to partial unswitching,
where we instead mark the whole loop, rather than a single
condition. This means that we will only generate a linear number
of loops.

TBH I think even that is still highly undesirable, and we should
probably be unswitching all candidates at the same time, so that
we end up with only two loops. But at least this mitigates the
worst case.

The test case is a reduced variant that generates 1700 lines of IR
without this patch and 290 with it.

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

(cherry picked from commit 8362cae71b80bc43c8c680cdfb13c495705a622f)

11 months ago[SimpleLoopUnswitch] Fix reversed branch during condition injection
Nikita Popov [Wed, 20 Sep 2023 08:46:25 +0000 (10:46 +0200)]
[SimpleLoopUnswitch] Fix reversed branch during condition injection

The in-loop successor is only on the left after a potential condition
inversion. As we re-use the old condition as-is, we should also
reuse the old successors as-is.

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

(cherry picked from commit afd7db48c55cb87566758e961f1ebac8af16b8bc)

11 months ago[clang] Include `expected-no-diagnostics` in newly-added test (NFC)
Antonio Frighetto [Thu, 14 Sep 2023 07:16:01 +0000 (09:16 +0200)]
[clang] Include `expected-no-diagnostics` in newly-added test (NFC)

(cherry picked from commit c990d9444350ef583c6d53e84d9c10cebbf65532)

11 months ago[clang] Bail out when handling union access with virtual inheritance
Antonio Frighetto [Wed, 13 Sep 2023 16:44:19 +0000 (18:44 +0200)]
[clang] Bail out when handling union access with virtual inheritance

An assertion issue that arose when handling union member access with
virtual base class has been addressed. As pointed out by @zygoloid,
there is no need for further derived-to-base analysis in this instance,
so we can bail out upon encountering a virtual base class. Minor
refinement on the function name as we might not be handling a union.

Reported-By: ormris
Fixes: https://github.com/llvm/llvm-project/issues/65982
(cherry picked from commit 660876a4019b81b5a7427a3dcec5ce8c39cd1ee0)

11 months ago[clang][Diagnostics] Fix wrong line number display (#65238)
Takuya Shimizu [Tue, 5 Sep 2023 03:12:42 +0000 (12:12 +0900)]
[clang][Diagnostics] Fix wrong line number display (#65238)

When the caret location is lower than the lowest source range, clang is
printing wrong line numbers. The first line number should consider caret
location line even when there are source ranges provided.

Current wrong line example: https://godbolt.org/z/aj4qEjzs4

(cherry picked from commit ef5217b3c0dcbb58927fe43400b6d1faa677bf98)

11 months agoRevert "[InlineCost] Check for conflicting target attributes early"
Kazu Hirata [Thu, 21 Sep 2023 17:29:46 +0000 (10:29 -0700)]
Revert "[InlineCost] Check for conflicting target attributes early"

This reverts commit d6f994acb3d545b80161e24ab742c9c69d4bbf33.

Several people have reported breakage resulting from this patch:

- https://github.com/llvm/llvm-project/issues/65152
- https://github.com/llvm/llvm-project/issues/65205

(cherry picked from commit b4301df61fc77a9d54ac236bc88742a731285f1c)

11 months ago[GVN] Also remove phi nodes from VN table (PR65447)
Nikita Popov [Fri, 15 Sep 2023 09:42:59 +0000 (11:42 +0200)]
[GVN] Also remove phi nodes from VN table (PR65447)

Followup to D158849: We also need to remove the phi node from the
VN table, which is not handled by removeInstruction().

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

(cherry picked from commit 18e77760ce5e42d9057f69c3e64a8300d01a48ac)

11 months ago[GVN] Invalidate MDA when deduplicating phi nodes
Nikita Popov [Thu, 17 Aug 2023 14:37:32 +0000 (16:37 +0200)]
[GVN] Invalidate MDA when deduplicating phi nodes

Duplicate phi nodes were being directly removed, without
invalidating MDA. This could result in a new phi node being
allocated at the same address, incorrectly reusing a cache entry.

Fix this by optionally allowing EliminateDuplicatePHINodes() to
collect phi nodes to remove into a vector, which allows GVN to
handle removal itself.

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

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

(cherry picked from commit 7c229f6e85478bb0626a5e598f47b7be94bb50b0)

11 months agoBump version to 17.0.2
Tobias Hieta [Mon, 25 Sep 2023 11:03:29 +0000 (13:03 +0200)]
Bump version to 17.0.2

11 months ago[SVE] Ensure SVE call operands passed via memory are correctly initialised. (#66070)
paulwalker-arm [Thu, 14 Sep 2023 11:58:58 +0000 (12:58 +0100)]
[SVE] Ensure SVE call operands passed via memory are correctly initialised. (#66070)

The stores created when passing operands via memory don't typically
maintain the chain, because they can be done in any order. Instead,
a new chain is created based on all collated stores. SVE parameters
passed via memory don't follow this idiom and try to maintain the
chain, which unfortunately can result in them being incorrectly
deadcoded when the chain is recreated.

This patch brings the SVE side in line with the non-SVE side to
ensure no stores become lost whilst also allowing greater flexibility
when ordering the stores.

11 months ago[SVE] Precommit test to show missing initialisation of call operand.
Paul Walker [Fri, 8 Sep 2023 16:14:58 +0000 (16:14 +0000)]
[SVE] Precommit test to show missing initialisation of call operand.

When calling func_f8_and_v0_passed_via_memory the memory used to
hold the first vector operand is allocated but not initialised.

11 months agoBump version to 17.0.1
Tobias Hieta [Tue, 19 Sep 2023 09:05:13 +0000 (11:05 +0200)]
Bump version to 17.0.1

11 months agoRemove RC suffix
Tobias Hieta [Tue, 19 Sep 2023 07:44:33 +0000 (09:44 +0200)]
Remove RC suffix

11 months agoRevert "[C++20] [Coroutines] Mark await_suspend as noinline if the awaiter is not...
Chuanqi Xu [Mon, 28 Aug 2023 05:32:27 +0000 (13:32 +0800)]
Revert "[C++20] [Coroutines] Mark await_suspend as noinline if the awaiter is not empty"

This reverts commit f05226d7e38c36efe029a0eb4201b0843f81b5e8.

11 months agoRevert "[NFC] [C++20] [Coroutines] Mention the side effect of a fix may bring regress...
Chuanqi Xu [Mon, 28 Aug 2023 05:32:23 +0000 (13:32 +0800)]
Revert "[NFC] [C++20] [Coroutines] Mention the side effect of a fix may bring regressions"

This reverts commit 6998ecd330f2b028bf4678edd4f53b5489c5e6df.

11 months ago[SimplifyCFG] handle monotonic wrapped case for D150943 (#65882)
Kohei Asano [Thu, 14 Sep 2023 12:26:11 +0000 (21:26 +0900)]
[SimplifyCFG] handle monotonic wrapped case for D150943 (#65882)

(cherry picked from commit fef82492209b24fd0b36a199657f3ed822e601a6)

11 months ago[lli] Make sure the exported __chkstk functions are included when exporting them
Martin Storsjö [Tue, 29 Aug 2023 08:31:53 +0000 (11:31 +0300)]
[lli] Make sure the exported __chkstk functions are included when exporting them

The trick we use (since cbc2a0623a39461b56bd9eeb308ca535f03793f8)
for exporting the __chkstk function (with various per-arch names)
that is defined in a different object file, relies on the function
already being linked in (by some function referencing it).

This function does end up referenced if there's a function that
allocates more than 4 KB on the stack. In most cases, it's referenced
somewhere, but in the case of builds with LLVM_LINK_LLVM_DYLIB
enabled (so most of the code resides in a separate libLLVM-<ver>.dll)
the only code in lli.exe is the lli tool specific code and the
mingw-w64 crt startup code. In the case of GCC based MinGW i386
builds with LLVM_LINK_LLVM_DYLIB, nothing else references it though.

Manually add a reference to the function to make sure it is linked
in (from libgcc or compiler-rt builtins) so that it can be exported.

This fixes one build issue encountered in
https://github.com/msys2/MINGW-packages/pull/18002.

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

(cherry picked from commit 4bba12f7226228221d1fa4bad7732e25647ecb87)

11 months ago[ARM] Change CRC predicate to just HasCRC
David Green [Fri, 8 Sep 2023 08:02:15 +0000 (09:02 +0100)]
[ARM] Change CRC predicate to just HasCRC

This removes the backend requirement for crc instructions on HasV8, relying on
just HasCRC instead. This should allow them to be selected with ArmV7 + crc,
making them more usable whilst hopefully not making them incorrectly generated
(they only come from intrinsics, and HasCRC usually requires HasV8). This is
how most other instructions are specified.

(cherry picked from commit a82c106e571c6991a95c38a936a466895122d713)

11 months ago[flang] Allow runtime build with AVOID_NATIVE_INT128_T=1
Peter Klausler [Thu, 6 Jul 2023 22:03:05 +0000 (15:03 -0700)]
[flang] Allow runtime build with AVOID_NATIVE_INT128_T=1

This patch enables the Fortran runtime support library to be
built without native 128-bit integer support in the C++ compiler.

Experimental: do not merge yet.

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

(cherry picked from commit 1c35c1a73907a95ce54b5a0edca513591e2bc069)

12 months ago[Clang] Fix JIT test on 32-bit systems
Sam James [Tue, 5 Sep 2023 15:02:04 +0000 (16:02 +0100)]
[Clang] Fix JIT test on 32-bit systems

As reported by mgorny at https://reviews.llvm.org/D159115#4638037, the
unsigned long long cast fails on 32-bit systems at least with GCC.

It looks like a pointer provenance/aliasing issue rather than a bug in GCC.

Acked by Vassil Vassilev on the original revision.

(cherry picked from commit 3403686b72507e3fdbcd69f21fb9235ffa0ca169)

12 months ago[builtins][AArch64] Implement _sync out-of-line atomics
Jessica Clarke [Mon, 4 Sep 2023 00:46:00 +0000 (01:46 +0100)]
[builtins][AArch64] Implement _sync out-of-line atomics

Whilst Clang does not use these, recent GCC does, and so on systems such
as FreeBSD that wish to use compiler-rt as the system runtime library
but also wish to support building programs with GCC these interfaces are
needed.

This is a light adaptation of the code committed to GCC by Sebastian Pop
<spop@amazon.com>, relicensed with permission for use in compiler-rt.

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

Reviewed By: sebpop, MaskRay

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

(cherry picked from commit 4bb2416d42eb593c44bbeb765e1b8641a58f853c)

12 months agoFix AIX OS requirements for ThinLTO to 7.2.5 SP7
Wael Yehia [Wed, 6 Sep 2023 14:17:45 +0000 (14:17 +0000)]
Fix AIX OS requirements for ThinLTO to 7.2.5 SP7

12 months ago[SCEV] Fix potentially empty set for unsigned ranges
Tejas Joshi [Mon, 4 Sep 2023 09:46:52 +0000 (10:46 +0100)]
[SCEV] Fix potentially empty set for unsigned ranges

The following commit enabled the analysis of ranges for heap allocations:
22ca38da25e19a7c5fcfeb3f22159aba92ec381e

The range turns out to be empty in cases such as the one in test (which
is [1,1)), leading to an assertion failure. This patch fixes for the
same case.

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

Reviewed By: fhahn

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

(cherry picked from commit 0609b65aaf03b083d282a4ffe8bf660351dac461)

12 months ago[CodeGen] Fix incorrect insertion point selection for reduction nodes in ComplexDeint...
Igor Kirillov [Wed, 30 Aug 2023 14:52:28 +0000 (14:52 +0000)]
[CodeGen] Fix incorrect insertion point selection for reduction nodes in ComplexDeinterleavingPass

When replacing ComplexDeinterleavingPass::ReductionOperation, we can do it
either from the Real or Imaginary part. The correct way is to take whichever
is later in the BasicBlock, but before the patch, we just always took the
Real part.

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

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

(cherry picked from commit e2cb07c322e85604dc48f9caec52b3570db0e1d8)

12 months ago[CodeGen][AArch64] Commit test for #65044
Danila Malyutin [Tue, 29 Aug 2023 15:05:01 +0000 (18:05 +0300)]
[CodeGen][AArch64] Commit test for #65044

(cherry picked from commit 2fce8f74b3c04bbf7e941cfed7604edae2b573b6)

12 months ago[libc++][hardening] Remove hardening from release notes, undeprecate safe mode
Konstantin Varlamov [Wed, 30 Aug 2023 06:29:33 +0000 (23:29 -0700)]
[libc++][hardening] Remove hardening from release notes, undeprecate safe mode

This patch effectively maintains the status quo, making sure that the
safe mode keeps working the same way as before. Hardening will target
the next major release, allowing it to go through RFC and for the
implementation to stabilize and mature.

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

12 months ago[LoopVectorize] Fix incorrect order of invariant stores when there are multiple reduc...
Igor Kirillov [Thu, 10 Aug 2023 15:38:27 +0000 (15:38 +0000)]
[LoopVectorize] Fix incorrect order of invariant stores when there are multiple reductions.

When a loop has multiple reductions, each with an intermediate invariant
store, the order in which those reductions are processed is not considered.
This can result in the invariant stores outside the loop not preserving the
original order.
This patch sorts VPReductionPHIRecipes by the order in which they have
stores in the original loop before running
`InnerLoopVectorizer::fixReduction` function, and it helps to maintain
the correct order of stores.

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

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

(cherry picked from commit ac65fb869977185b44757b94dc5130bd08c6f7e2)

12 months ago[LoopVectorize] Pre-commit tests for D157631
Igor Kirillov [Thu, 10 Aug 2023 15:35:39 +0000 (15:35 +0000)]
[LoopVectorize] Pre-commit tests for D157631

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

(cherry picked from commit 2df9ed11c51ebf6d19f7cb22c3794d1bd460ddf8)

12 months ago[RelNotes] Add more details on the removal of the legacy optimization pipeline
Arthur Eubanks [Wed, 6 Sep 2023 18:28:38 +0000 (11:28 -0700)]
[RelNotes] Add more details on the removal of the legacy optimization pipeline

12 months ago[mlir][nfc] Allow ops to have operands/attributes named `context`.
Christian Sigg [Wed, 30 Aug 2023 10:23:25 +0000 (12:23 +0200)]
[mlir][nfc] Allow ops to have operands/attributes named `context`.

This is probably a bad idea, but it's only become a problem with properties and is easy to fix.

Reviewed By: mehdi_amini

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

12 months ago[JumpThreading] Invalidate LVI after `combineMetadataForCSE`.
DianQK [Sun, 3 Sep 2023 04:23:33 +0000 (12:23 +0800)]
[JumpThreading] Invalidate LVI after `combineMetadataForCSE`.

(cherry picked from commit 7ded71b1e43fff0be3acb74038bfea87f38d5cfa)

12 months ago[JumpThreading][NFC] Pre-commit for invalid LVI.
DianQK [Sun, 3 Sep 2023 04:18:57 +0000 (12:18 +0800)]
[JumpThreading][NFC] Pre-commit for invalid LVI.

(cherry picked from commit 5855a4be9cbc3c4584d8a1632886c347044dfbef)

12 months agoRevert "[clang][Docs] Added release note for D142609"
Takuya Shimizu [Mon, 4 Sep 2023 02:19:46 +0000 (11:19 +0900)]
Revert "[clang][Docs] Added release note for D142609"

The associated commit was reverted and backported in a93ca35, so this
release note line should also be removed.

This reverts commit 061e855767dbe0821d81a8d47158f468dd00ae5f.

12 months ago[clang][clangd] Ensure the stack bottom before building AST
Younan Zhang [Mon, 28 Aug 2023 06:51:59 +0000 (14:51 +0800)]
[clang][clangd] Ensure the stack bottom before building AST

`clang::runWithSufficientStackSpace` requires the address of the
initial stack bottom to prevent potential stack overflows.

In addition, add a fallback to ASTFrontendAction in case any client
forgets to call it when not through CompilerInstance::ExecuteAction,
which is rare.

Fixes https://github.com/clangd/clangd/issues/1745.

Reviewed By: sammccall

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

(cherry picked from commit e257c0a9190637e44e292271103a13d70bec4b03)

12 months ago[clang] Construct ExprRequirement with SubstitutionDiagnostic on SubstFailure
Younan Zhang [Wed, 16 Aug 2023 07:33:58 +0000 (15:33 +0800)]
[clang] Construct ExprRequirement with SubstitutionDiagnostic on SubstFailure

We're expecting a SubstitutionDiagnostic in diagnoseUnsatisfiedRequirement
if the status of ExprRequirement is SubstFailure. Previously, the Requirement
was created with Expr on SubstFailure by mistake, which could lead to the
assertion failure in the subsequent diagnosis.

Fixes https://github.com/clangd/clangd/issues/1726
Fixes https://github.com/llvm/llvm-project/issues/64723
Fixes https://github.com/llvm/llvm-project/issues/64172

In addition, this patch also fixes an invalid test from D129499.

Reviewed By: erichkeane

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

12 months ago[NFC][Clang] Fix static analyzer concern about null value dereference
Elizabeth Andrews [Mon, 14 Aug 2023 19:01:14 +0000 (12:01 -0700)]
[NFC][Clang] Fix static analyzer concern about null value dereference

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

12 months ago[sanitizer] scanf interceptor: fix write size for %mc/%mC/%mS
Fangrui Song [Mon, 28 Aug 2023 05:19:31 +0000 (22:19 -0700)]
[sanitizer] scanf interceptor: fix write size for %mc/%mC/%mS

When the optional assignment-allocation character 'm' (Extension to the
ISO C standard) is present, we currently use internal_strlen(buf)+1 for
all of cCsS[ (D85350). Fix cCS to use the correct size.

Fix https://github.com/llvm/llvm-project/issues/61768

Reviewed By: #sanitizers, vitalybuka

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

(cherry picked from commit beeb37a8f3275281be305d2d1afe35ca053e21c0)

12 months ago[CodeGen] First check the kind and then the llvm::Function properties.
Vassil Vassilev [Fri, 1 Sep 2023 19:50:54 +0000 (19:50 +0000)]
[CodeGen] First check the kind and then the llvm::Function properties.

This patch fixes valgrind reports from downstream consumers about conditional
jump over uninitialised memory.

The original report:

```[ RUN      ] ScopeReflectionTest.IsComplete
==987150== Conditional jump or move depends on uninitialised value(s)
==987150==    at 0x1E1128F: clang::CodeGen::CodeGenModule::SetLLVMFunctionAttributesForDefinition(clang::Decl const*, llvm::Function*) (CodeGenModule.cpp:2391)
==987150==    by 0x1E4F181: clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) (CodeGenModule.cpp:5669)
==987150==    by 0x1E4A194: clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (CodeGenModule.cpp:3909)
==987150==    by 0x1E4A752: clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) (CodeGenModule.cpp:3649)
==987150==    by 0x1E532F5: clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) [clone .part.0] (CodeGenModule.cpp:6563)
==987150==    by 0x1B0BEDD: (anonymous namespace)::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) (ModuleBuilder.cpp:190)
==987150==    by 0x1AEA47B: clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef) (CodeGenAction.cpp:235)
==987150==    by 0x101B02F: clang::IncrementalASTConsumer::HandleTopLevelDecl(clang::DeclGroupRef) (IncrementalParser.cpp:52)
==987150==    by 0x101ED93: clang::IncrementalParser::ParseOrWrapTopLevelDecl() (IncrementalParser.cpp:276)
==987150==    by 0x101FBBC: clang::IncrementalParser::Parse(llvm::StringRef) (IncrementalParser.cpp:342)
==987150==    by 0x100E104: clang::Interpreter::Parse(llvm::StringRef) (Interpreter.cpp:360)
==987150==    by 0xE734C0: Cpp::Interpreter::Parse(llvm::StringRef) (CppInterOpInterpreter.h:172)
==987150==  Uninitialised value was created by a heap allocation
==987150==    at 0x844BE63: operator new(unsigned long) (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==987150==    by 0x1B0C882: StartModule (ModuleBuilder.cpp:139)
==987150==    by 0x1B0C882: clang::CodeGenerator::StartModule(llvm::StringRef, llvm::LLVMContext&) (ModuleBuilder.cpp:360)
==987150==    by 0x101C4AF: clang::IncrementalParser::GenModule() (IncrementalParser.cpp:372)
==987150==    by 0x101FC0E: clang::IncrementalParser::Parse(llvm::StringRef) (IncrementalParser.cpp:362)
==987150==    by 0x100E104: clang::Interpreter::Parse(llvm::StringRef) (Interpreter.cpp:360)
==987150==    by 0x100E243: clang::Interpreter::create(std::unique_ptr<clang::CompilerInstance, std::default_delete<clang::CompilerInstance> >) (Interpreter.cpp:279)
==987150==    by 0xF2131A: compat::createClangInterpreter(std::vector<char const*, std::allocator<char const*> >&) (Compatibility.h:123)
==987150==    by 0xF22AB9: Cpp::Interpreter::Interpreter(int, char const* const*, char const*, std::vector<std::shared_ptr<clang::ModuleFileExtension>, std::allocator<std::shared_ptr<clang::ModuleFileExtension> > > const&, void*, bool) (CppInterOpInterpreter.h:146)
==987150==    by 0xF1827A: CreateInterpreter (CppInterOp.cpp:2494)
==987150==    by 0xECFA0E: TestUtils::GetAllTopLevelDecls(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::vector<clang::Decl*, std::allocator<clang::Decl*> >&, bool) (Utils.cpp:23)
==987150==    by 0xE9CB85: ScopeReflectionTest_IsComplete_Test::TestBody() (ScopeReflectionTest.cpp:71)
==987150==    by 0xF0ED0C: void testing::internal::HandleExceptionsInMethodIfSupported<testing::Test, void>(testing::Test*, void (testing::Test::*)(), char const*) (in /home/vvassilev/workspace/builds/scratch/cppyy/InterOp/build-with-clang-repl-release/unittests/CppInterOp/CppInterOpTests)
==987150==
```

Differential revision: https://reviews.llvm.org/D159339

(cherry picked from commit 92246a9be0ba47788ada9621bef58ce7819be526)

12 months ago[Driver] Report warnings for unclaimed TargetSpecific options for assembler input
Fangrui Song [Fri, 1 Sep 2023 06:26:46 +0000 (23:26 -0700)]
[Driver] Report warnings for unclaimed TargetSpecific options for assembler input

This patch amends D151590 to not error for unlaimed TargetSpecific
options for `-x assembler` input files. This input type causes Driver to
construct tools::ClangAs (-fintegrated-as) or other assemblers (e.g.
tools::gnutools::Assembler) Their ConstructJobs methods, unlike
Clang::ConstructJobs, claim very few options. If an option is unclaimed,
it either leads to a -Wunused-command-line-argument warning or an error
(if `TargetSpecific` is set):
```
% clang '-###' --target=aarch64 -mbranch-protection=bti -c a.s
clang: error: unsupported option '-mbranch-protection=' for target 'aarch64'
```

It seems that downgrading the diagnostic to warning is most useful as
many users use CFLAGS even for `.s` files:
```
clang --target=aarch64 -mbranch-protection=bti -S a.c
clang --target=aarch64 -mbranch-protection=bti -c a.s
```

I decide not to suppress the warning so that
-Wunused-command-line-argument lovers still get a warning, and help
projects use proper ASFLAGS/CFLAGS/etc.

Note: `-mbranch-protection=bti a.S` currently has no warning as `-x assembler-with-cpp`
instructs clangDriver to select tools::Clang and claim most options.

Revert D159010 to demonstrate that we emit a warning for -mfpmath= for
`-x assembler` input.

Modify my AIX cleanup cd18efb61d759405956dbd30e4b5f2720d8e1783 to
add an err_drv_unsupported_opt_for_target.

Reviewed By: thesamesam

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

(cherry picked from commit e9d454d1c195958645fb0948f8b97262e7f8b33a)

12 months ago[AArch64] Fix arm neon vstx lane memVT size
hstk30 [Thu, 31 Aug 2023 16:54:57 +0000 (17:54 +0100)]
[AArch64] Fix arm neon vstx lane memVT size

StN lane memory size set too big lead to alias analysis goes wrong.

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

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

(cherry picked from commit db8f6c009e5a17d304be7404e50eb20b2dd0c75b)

12 months ago[llvm-windres] Implement the windres flag --use-temp-file
Martin Storsjö [Wed, 30 Aug 2023 20:29:15 +0000 (23:29 +0300)]
[llvm-windres] Implement the windres flag --use-temp-file

Whether a temp file or a pipe is used for preprocessing is an
internal detail, this flag has a notable effect on the preprocessing
in GNU windres. Without this flag, GNU windres passes command
arguments as-is to popen(), which means they get evaluated by a
shell without being re-escaped for this case. To mimic this,
llvm-windres has manually tried to unescape arguments.

When GNU windres is given the --use-temp-file flag, it uses a
different API for invoking the preprocessor, and this API takes care
of preserving special characters in the command line arguments.
For users of GNU windres, this means that by using --use-temp-file,
they don't need to do the (quite terrible) double escaping of
quotes/spaces etc.

The xz project uses the --use-temp-file flag when invoking
GNU windres, see
https://github.com/tukaani-project/xz/commit/6b117d3b1fe91eb26d533ab16a2e552f84148d47.
However as llvm-windres didn't implement this flag and just
assumed the GNU windres popen() behaviour, they had to use a
different codepath for llvm-windres.

That separate codepath for llvm-windres broke later when llvm-windres
got slightly more accurate unescaping of lone quotes in
0f4c6b120f21d582ab7c5c4f2b2a475086c34938 /
https://reviews.llvm.org/D146848 (fixing a discrepancy to GNU
windres as found in https://github.com/llvm/llvm-project/issues/57334),
and this was reported in
https://github.com/mstorsjo/llvm-mingw/issues/363.

Not touching the implementation of the --preprocessor option
with respect to the --use-temp-file flag; that option is doubly
tricky as GNU windres changed its behaviour in a backwards incompatible
way recently (and llvm-windres currently matches the old behaviour).
(See
https://sourceware.org/git/?p=binutils-gdb.git;a=commitdiff;h=21c33bcbe36377abf01614fb1b9be439a3b6de20,
https://sourceware.org/bugzilla/show_bug.cgi?id=27594 and
https://sourceware.org/git/?p=binutils-gdb.git;a=commitdiff;h=5edb8e3f5ad8d74a83fc0df7f6e4514eed0aa77f;hp=3abbafc2aacc6706fea3e3e326e2f08d107c3672
for the behaviour change.)

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

(cherry picked from commit 2bcc0fdc58a220cb9921b47ec8a32c85f2511a47)

12 months ago[Tooling/Inclusion] Add std::range symbols in the mapping.
Haojian Wu [Fri, 28 Jul 2023 15:58:15 +0000 (17:58 +0200)]
[Tooling/Inclusion] Add std::range symbols in the mapping.

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

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

(cherry picked from commit 171868dc2cd60c6e3eaeb3861b18ba0e22461291)

12 months ago[sanitizer][test] -std=c2x instead of -std=c23
Fangrui Song [Thu, 31 Aug 2023 16:31:25 +0000 (09:31 -0700)]
[sanitizer][test] -std=c2x instead of -std=c23

Adjust tests from dd230efe703f34678ce52280e50238abf908aaa1 to use
-std=c2x instead, as Clang in release/17.x doesn't support -std=c23.

12 months ago[Driver] Adjust -fsanitize=function & -mexecute-only interop after D158614
Fangrui Song [Wed, 30 Aug 2023 19:29:50 +0000 (19:29 +0000)]
[Driver] Adjust -fsanitize=function & -mexecute-only interop after D158614

clangDriver depends on clangBasic, so clangBasic should not depend on
clangDriver, even just its header. Also remove clangBasic's dependency
on LLVMOption.

The issue can be seen through the bazel commit
d26dd681f9726ed7d43d7c0bdd8ee3cb2db69a2b which is reverted now.

Add hasFlagNoClaim and use it as we don't want to suppress
-Wunused-command-line-argument for -mexecute-only just because
-fsanitize= is specified.

12 months ago[UBSan] Disable the function and kcfi sanitizers on an execute-only target.
Ying Yi [Tue, 29 Aug 2023 19:02:13 +0000 (20:02 +0100)]
[UBSan] Disable the function and kcfi sanitizers on an execute-only target.

An execute-only target disallows data access to code sections.
-fsanitize=function and -fsanitize=kcfi instrument indirect function
calls to load a type hash before the function label. This results in a
non-execute access to the code section and a runtime error.

To solve the issue, -fsanitize=function should not be included in any
check group (e.g. undefined) on an execute-only target. If a user passes
-fsanitize=undefined, there is no error and no warning. However, if the
user explicitly passes -fsanitize=function or -fsanitize=kcfi on an
execute-only target, an error will be emitted.

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

Reviewed By: MaskRay, probinson, simon_tatham

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

12 months ago[X86][BF16] Lower FP_ROUND for vector types under AVX512BF16
Phoebe Wang [Tue, 29 Aug 2023 01:31:00 +0000 (09:31 +0800)]
[X86][BF16] Lower FP_ROUND for vector types under AVX512BF16

Reviewed By: RKSimon

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

(cherry picked from commit b667e9c23d6d2f1c7371eb4a03b30de4a6f8b7b6)

12 months ago[X86][BF16] Add test coverage for AVX-NE-CONVERT
Phoebe Wang [Tue, 29 Aug 2023 00:59:24 +0000 (08:59 +0800)]
[X86][BF16] Add test coverage for AVX-NE-CONVERT

Split from D158952.

(cherry picked from commit 30ec9473c6685d64d5caa17e2a6e8f4ccf275159)

12 months ago[clangd] Respect IWYU keep pragma for standard headers.
Haojian Wu [Mon, 31 Jul 2023 07:20:55 +0000 (09:20 +0200)]
[clangd] Respect IWYU keep pragma for standard headers.

see the issue https://github.com/llvm/llvm-project/issues/64191

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

(cherry picked from commit dcb28244faa88cb566a852533790bcac75daaa0f)

12 months ago[RISCV] Prevent tryToFoldBNEOnCmpXchgResult from deleting AND if it has others users.
Craig Topper [Mon, 28 Aug 2023 17:11:12 +0000 (10:11 -0700)]
[RISCV] Prevent tryToFoldBNEOnCmpXchgResult from deleting AND if it has others users.

This disables the transform if the branch does not have the kill
flag set for the AND we want to delete.

Ideally we'd be able to share the AND with the AND we create in
the expansion, but that's a more complex transform. So this starts
with the simple approach to fix miscompile.

This should be backported to LLVM 17.

Fixes PR65025.ll

Reviewed By: asb

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

(cherry picked from commit ff6d33382faf3709fa270ae0abb8d165142df9ae)

12 months ago[PowerPC][lld] Account for additional X-Forms -> D-Form/DS-Forms load/stores when...
Amy Kwan [Wed, 30 Aug 2023 16:54:12 +0000 (11:54 -0500)]
[PowerPC][lld] Account for additional X-Forms -> D-Form/DS-Forms load/stores when relaxing initial-exec to local-exec

D153645 added additional X-Form load/stores that can be generated for TLS accesses.
However, these added instructions have not been accounted for in lld. As a result,
lld does not know how to handle them and cannot relax initial-exec to local-exec
when the initial-exec sequence contains these additional load/stores.

This patch aims to resolve https://github.com/llvm/llvm-project/issues/64424.

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

(cherry picked from commit 698b45aa902de4d30c798e8d6bd080c8e31bade8)

12 months ago[AArch64] Add Defs=[NZCV] to MTE loop pseudos.
Simon Tatham [Mon, 21 Aug 2023 07:43:21 +0000 (08:43 +0100)]
[AArch64] Add Defs=[NZCV] to MTE loop pseudos.

The `STGloop` family of pseudo-instructions all expand to a loop which
iterates over a region of memory setting all its MTE tags to a given
value. The loop writes to the flags in order to check termination. But
the unexpanded pseudo-instructions were not marked as modifying the
flags. Therefore it was possible for one to end up in a location where
the flags were live, and then the loop would corrupt them.

We spotted the effect of this in a libc++ test involving a lot of
complicated inlining, and haven't been able to construct a smaller
test case that demonstrates actual incorrect output code. So my test
here is just checking that `implicit-def $nzcv` shows up on the
pseudo-instructions as they're output from isel.

Reviewed By: DavidSpickett

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

(cherry picked from commit b09c575975b691e988a0f2e31d632c5f1038ab1d)

12 months ago[libc++][format] Fixes out of bounds access.
Mark de Wever [Sat, 26 Aug 2023 17:25:45 +0000 (19:25 +0200)]
[libc++][format] Fixes out of bounds access.

Fixes https://llvm.org/PR65011

Reviewed By: #libc, ldionne

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

(cherry picked from commit 8930d04d5580c6a2cf04545c87387cd150cd7b46)

12 months ago[lldb][windows] _wsopen_s does not accept bits other than `_S_IREAD | _S_IWRITE`
Yuxuan Shui [Wed, 30 Aug 2023 12:40:56 +0000 (15:40 +0300)]
[lldb][windows] _wsopen_s does not accept bits other than `_S_IREAD | _S_IWRITE`

When sending file from a Linux host to a Windows remote, Linux host will try to copy the source file's permission bits, which will contain `_S_I?GRP` and `_S_I?OTH` bits. Those bits are rejected by `_wsopen_s`, causing it to return EINVAL.

This patch masks out the rejected bits.

GitHub issue: #64313

Reviewed By: jasonmolenda, DavidSpickett

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

(cherry picked from commit 9a4b3fdb82327e808213070fd157be3c557b8b9d)

12 months ago[RISCV] Fix assertion failure when zcmp extension is enabled.
Garvit Gupta [Wed, 30 Aug 2023 05:05:44 +0000 (22:05 -0700)]
[RISCV] Fix assertion failure when zcmp extension is enabled.

Before accessing "getOpcode" thorugh machine instruction, check if the iterator
has reached the end of Machine basic block otherwise we will crash at the
assertion `!NodePtr->isKnownSentinel()`.

The above assertion is hit in "Prologue/Epilogue Insertion & Frame Finalization
pass".

Reviewed By: craig.topper, wangpc

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

(cherry picked from commit fdef7952cbc26fd31d0d92a4f14dde58bc461fe9)

12 months ago[mlir] Fix infinite recursion in alias initializer
Markus Böck [Sat, 26 Aug 2023 14:10:52 +0000 (16:10 +0200)]
[mlir] Fix infinite recursion in alias initializer

The alias initializer keeps a list of child indices around. When an alias is then marked as non-deferrable, all children are also marked non-deferrable.

This is currently done naively which leads to an infinite recursion if using mutable types or attributes containing a cycle.

This patch fixes this by adding an early return if the alias is already marked non-deferrable. Since this function is the only way to mark an alias as non-deferrable, it is guaranteed that if it is marked non-deferrable, all its children are as well, and it is not required to walk all the children.
This incidentally makes the non-deferrable marking also `O(n)` instead of `O(n^2)` (although not performance sensitive obviously).

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

12 months ago[mlir] Fix crash when adding nested dialect extensions
Matthias Springer [Sat, 26 Aug 2023 07:57:43 +0000 (09:57 +0200)]
[mlir] Fix crash when adding nested dialect extensions

A dialect extension can add additional dialect extensions in its `apply` function. This used to crash when the vector of `extensions` was internally reallocated while it is being iterated over.

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

12 months ago[mlir][math] Modify math.powf to handle negative bases.
Balaji V. Iyer [Fri, 25 Aug 2023 22:15:28 +0000 (15:15 -0700)]
[mlir][math] Modify math.powf to handle negative bases.

Powf expansion currently returns NaN when the base is negative.
This is because taking natural log of a negative number gives
NaN. This patch will square the base and half the exponent, thereby
getting around the negative base problem.

Reviewed By: rsuderman

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

12 months ago[mlir][memref] Fix crash in SubViewReturnTypeCanonicalizer
Matthias Springer [Fri, 25 Aug 2023 13:53:39 +0000 (15:53 +0200)]
[mlir][memref] Fix crash in SubViewReturnTypeCanonicalizer

`SubViewReturnTypeCanonicalizer` is used by `OpWithOffsetSizesAndStridesConstantArgumentFolder`, which folds constant SSA value (dynamic) sizes into static sizes. The previous implementation crashed when a dynamic size was folded into a static `1` dimension, which was then mistaken as a rank reduction.

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

12 months ago[PowerPC] Update V17.0.0 release notes
Lei Huang [Fri, 25 Aug 2023 16:29:41 +0000 (11:29 -0500)]
[PowerPC] Update V17.0.0 release notes

12 months ago[clang][test] Make check pattern shorter
Serge Pavlov [Wed, 30 Aug 2023 05:32:35 +0000 (12:32 +0700)]
[clang][test] Make check pattern shorter

A check pattern in clang/test/SemaCXX/template-64605.cpp contains template
specialization kind (the text "implicit_instantiation"). It does not need to
be checked and can be safely removed.

Presence of this text in the check pattern prevents from backporting some
commits to the release branch: https://github.com/llvm/llvm-project/issues/64605.
It has only recently been printed and the relevant commit is not present in
the release/17.x branch.

(cherry picked from commit 8859c644ede4898f90f77dcad2286de08a9ba62e)

12 months ago[clang] Run test for concrete target
Serge Pavlov [Mon, 21 Aug 2023 06:20:22 +0000 (13:20 +0700)]
[clang] Run test for concrete target

The test clang/test/SemaCXX/template-64605.cpp uses pragma FENV_ACCESS,
which is not supported on all targets. Restrict it to x86_64 only.

(cherry picked from commit 73e5a70e676850b79f196e01e2194a2485041584)

12 months ago[clang] Set FP options in Sema when instantiating CompoundStmt
Serge Pavlov [Mon, 21 Aug 2023 05:20:37 +0000 (12:20 +0700)]
[clang] Set FP options in Sema when instantiating CompoundStmt

When an expression is instantiated, TreeTransform skips ImplicitCastExpr
nodes, assuming they are recreated when the instantiated expression is
built. It breaks functions that use non-default floating-point options,
because they are kept in these ImplicitCastExprs. In this case the
recreated ImplicitCastExpr takes FP options from the current Sema state
and not from AST node.

To fix this issue the FP options in Sema object are set when a compound
statement is cloned in TreeTransform.

This change fixes https://github.com/llvm/llvm-project/issues/64605
([Regression 16 -> 17] Template instantiation ignores FENV_ACCESS being
ON for both definition and instantiation).

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

(cherry picked from commit 0baf85c331090fbe2d2b42214ed0664d55feb0b5)

12 months agoworkflows: Fix libclang-abi test after update to use download-artifac… (#64877)
Tom Stellard [Mon, 28 Aug 2023 16:38:27 +0000 (09:38 -0700)]
workflows: Fix libclang-abi test after update to use download-artifac… (#64877)

workflows: Fix libclang-abi test after update to use download-artifact v3

12 months agoSilently accept -Wgnu-empty-initializer
Aaron Ballman [Thu, 10 Aug 2023 11:22:45 +0000 (07:22 -0400)]
Silently accept -Wgnu-empty-initializer

https://github.com/llvm/llvm-project/commit/5d8aaad4452f60ba8902e921d9bed606713a8f26
removed the warning group as the functionality is no longer a GNU
extension. However, users have asked for the warning group to be
supported so that code transitioning from Clang 16 to Clang 17 has an
easier migration path when compiling with -Werror. This patch restores
the warning group, but as an ignored warning group because the
functionality is now always considered to be a C extension rather than
a GNU extension. This allows users to do:

  -Werror -pedantic -Wno-gnu-empty-intializer -Wno-c2x-extensions

to silence the diagnostics in both Clang 16 and Clang 17.

Fixes https://github.com/llvm/llvm-project/issues/64357
Differential Revision: https://reviews.llvm.org/D157503

(cherry picked from commit 151214b40d869455666ca76548a9e3ad639f79de)

12 months ago[CMake] Add a few more missing dependencies on ClangDriverOptions
Jon Roelofs [Tue, 15 Aug 2023 23:55:32 +0000 (16:55 -0700)]
[CMake] Add a few more missing dependencies on ClangDriverOptions

This often breaks modules-enabled bootstrap builds.

(cherry picked from commit 1e4d6122cda6529781ecf467c2ae84e5dd41acdf)

12 months ago[clang-format] Exclude kw_decltype in RemoveParentheses
Owen Pan [Thu, 17 Aug 2023 08:00:02 +0000 (01:00 -0700)]
[clang-format] Exclude kw_decltype in RemoveParentheses

From https://en.cppreference.com/w/cpp/language/decltype:
Note that if the name of an object is parenthesized, it is treated as an
ordinary lvalue expression, thus decltype(x) and decltype((x)) are often
different types.

Fixes #64786.

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

(cherry picked from commit e3a79503a30f8c9d8fba79f3e5427bb895f320cf)

12 months ago[RISCV] Don't relax policy to ta when vmerge's VL shrinks during folding
Luke Lau [Thu, 17 Aug 2023 09:49:49 +0000 (10:49 +0100)]
[RISCV] Don't relax policy to ta when vmerge's VL shrinks during folding

When folding a vmerge into its operands, if the resulting VL is smaller than
what the vmerge had originally then what was previously in its body then gets
moved to the tail. In that case, we can't relax the tail policy to agnostic
when the merge operand is undefined, since we need to preserve these elements
past the new VL.

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

Reviewed By: craig.topper, reames

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

(cherry picked from commit 007b41b3939832b6938bb1ba91e9febebf93d3b8)

12 months ago[RISCV] Add test case showing vmerge fold miscompile with tail policy
Luke Lau [Thu, 17 Aug 2023 09:36:12 +0000 (10:36 +0100)]
[RISCV] Add test case showing vmerge fold miscompile with tail policy

Reviewed By: reames

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

(cherry picked from commit 6e532f94eb0e2c9c93a3d75b4cf53bf12ab9f518)

12 months agoFunction multi-versioning: disable ifunc for ELF targets other than glibc/Android...
Fangrui Song [Mon, 14 Aug 2023 15:59:59 +0000 (08:59 -0700)]
Function multi-versioning: disable ifunc for ELF targets other than glibc/Android/FreeBSD

Generalize D127933 (Fuchsia special case) to other ELF targets. Ensure
that musl, NetBSD, OpenBSD, etc do not get ifunc codegen which is
unsupported in their rtld.

Link: https://discourse.llvm.org/t/does-ifunc-use-from-llvm-require-os-support/67628
Close: https://github.com/llvm/llvm-project/issues/64631
(cherry picked from commit 0c3a02b8c09bb408a74a638a263e51d67c92ca74)

12 months ago[msan] Fix compilation on non-glibc
Brooks Davis [Tue, 29 Aug 2023 04:22:29 +0000 (21:22 -0700)]
[msan] Fix compilation on non-glibc

SANITIZER_GLIBC is always defined so should be tested with an if not an
ifdef.

Fixes: ad7e2501000d

Reviewed By: MaskRay

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

(cherry picked from commit 692344d87357ded619d216b265a9375f4326d8fb)

12 months ago[compiler-rt] [test] Adjust an XFAIL for strtoll_strict.c for MinGW targets
Martin Storsjö [Mon, 28 Aug 2023 20:31:08 +0000 (20:31 +0000)]
[compiler-rt] [test] Adjust an XFAIL for strtoll_strict.c for MinGW targets

8033231240f223dc7c718d1d27ece2dbcc8057c6 made this test pass
in MinGW environments, even if it still is failing in MSVC
environments.

(cherry picked from commit 277fc9475fb89c0b80d4237dbc8d698a55203c0d)

12 months ago[sanitizer] Intercept glibc 2.38 __isoc23_* functions
Fangrui Song [Mon, 28 Aug 2023 07:49:49 +0000 (00:49 -0700)]
[sanitizer] Intercept glibc 2.38 __isoc23_* functions

`strtol("0b1", 0, 0)` can be (pre-C23) 0 or (C23) 1.
`sscanf("0b10", "%i", &x)` is similar. glibc 2.38 introduced
`__isoc23_strtol` and `__isoc23_scanf` family functions for binary
compatibility.

When `_ISOC2X_SOURCE` is defined (implied by `_GNU_SOURCE`) or
`__STDC_VERSION__ > 201710L`, `__GLIBC_USE_ISOC2X` is defined to 1 and
these `__isoc23_*` symbols are used.

Add `__isoc23_` versions for the following interceptors:

* sanitizer_common_interceptors.inc implements strtoimax/strtoumax.
  Remove incorrect FIXME about https://github.com/google/sanitizers/issues/321
* asan_interceptors.cpp implements just strtol and strtoll. The default
  `replace_str` mode checks `nptr` is readable and `endptr` is writable.
  atoi reuses the existing strtol interceptor.
* msan_interceptors.cpp implements strtol family functions and their
  `_l` versions. Tested by lib/msan/tests/msan_test.cpp
* sanitizer_common_interceptors.inc implements scanf family functions.

The strtol family functions are spreaded, which is not great, but the
patch (intended for release/17.x) does not attempt to address the issue.

Add symbols to lib/sanitizer_common/symbolizer/scripts/global_symbols.txt to
support both glibc pre-2.38 and 2.38.

When build bots migrate to glibc 2.38+, we will lose test coverage for
non-isoc23 versions since the existing C++ unittests imply `_GNU_SOURCE`.
Add test/sanitizer_common/TestCases/{strtol.c,scanf.c}.
They catch msan false positive in the absence of the interceptors.

Fix https://github.com/llvm/llvm-project/issues/64388
Fix https://github.com/llvm/llvm-project/issues/64946

Link: https://lists.gnu.org/archive/html/info-gnu/2023-07/msg00010.html
("The GNU C Library version 2.38 is now available")

Reviewed By: #sanitizers, vitalybuka, mgorny

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

(cherry picked from commit ad7e2501000da2494860f06a306dfe8c08cc07c3)

12 months ago[asan] Intercept atoll and strtoll on Windows
Fangrui Song [Sun, 27 Aug 2023 17:36:30 +0000 (10:36 -0700)]
[asan] Intercept atoll and strtoll on Windows

`_MSC_VER>=1800` (Visual Studio 2013) supports atoll/strtoll.
Remove the obsoleted workaround ASAN_INTERCEPT_ATOLL_AND_STRTOLL.

test/asan/TestCases/atoll_strict.c passes but
test/asan/TestCases/strtoll_strict.c doesn't.

(cherry picked from commit 8033231240f223dc7c718d1d27ece2dbcc8057c6)

12 months ago[clang] Update NumFunctionDeclBits for FunctionDeclBitfields
dingfei [Thu, 17 Aug 2023 05:44:05 +0000 (13:44 +0800)]
[clang] Update NumFunctionDeclBits for FunctionDeclBitfields

NumFunctionDeclBits is not updated when DeductionCandidateKind is
incremented.

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

Reviewed By: cor3ntin, balazske, aaron.ballman

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

(cherry picked from commit 91c4b5550ecfbb7afe7275c341b73a6d3a1bbd78)

12 months ago[clang-format] Fix braced initializer with templated base class
Galen Elias [Tue, 1 Aug 2023 20:42:04 +0000 (13:42 -0700)]
[clang-format] Fix braced initializer with templated base class

Fixes #64134.

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

(cherry picked from commit 400da115c58ae19445cfdc871a3f559f160fc5c6)

12 months ago[clang][ExprConstant] Fix crash on uninitialized base class subobject
Takuya Shimizu [Tue, 8 Aug 2023 12:10:25 +0000 (21:10 +0900)]
[clang][ExprConstant] Fix crash on uninitialized base class subobject

This patch fixes the reported regression caused by D146358 through adding notes about an uninitialized base class when we diagnose uninitialized constructor.

This also changes the wording from the old one in order to make it clear that the uninitialized subobject is a base class and its constructor is not called.
Wording changes:
BEFORE: `subobject of type 'Base' is not initialized`
AFTER: `constructor of base class 'Base' is not called`

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

Reviewed By: aaron.ballman
Differential Revision: https://reviews.llvm.org/D153969

12 months agoReland "[clang-repl] Adapt to the recent dylib-related changes in ORC."
Vassil Vassilev [Tue, 29 Aug 2023 19:38:34 +0000 (19:38 +0000)]
Reland "[clang-repl] Adapt to the recent dylib-related changes in ORC."

Original commit message:"

ORC splits into separate dylibs symbols coming from the process and symbols
materialized in the Jit. This patch adapts intent of the existing interface and
adds a regression test to make sure both Jit'd and compiled symbols can be found.

Differential revision: https://reviews.llvm.org/D159115
"

This patch disables the test statement on windows as it seems we might have a
bug in the way we model dllimports.

(cherry picked from commit 452cb7f20bc7b976eb6fec4ac9f2d902f4175c08)

12 months ago[X86][BF16] Lower FP_EXTEND for vector types under AVX512BF16
Phoebe Wang [Mon, 28 Aug 2023 01:46:35 +0000 (09:46 +0800)]
[X86][BF16] Lower FP_EXTEND for vector types under AVX512BF16

Fixes #64460

Reviewed By: RKSimon, skan

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

(cherry picked from commit 6688701497ea8e562b769bdb154a40f4a1099abb)

12 months ago[Tests][ConstraintElim] autogen newly-added case in large-constant-ints.ll (NFC)
Erik Desjardins [Fri, 25 Aug 2023 19:37:05 +0000 (15:37 -0400)]
[Tests][ConstraintElim] autogen newly-added case in large-constant-ints.ll (NFC)

I forgot to do this in 66ec5df3a7f33366455d50769e4e878544becea6 / https://reviews.llvm.org/D158810.

Since this is testing for an assertion failure, the test checks don't matter, but we might as well avoid unnecessary churn the next time someone modifies this test.

(cherry picked from commit df112cba034eefb86d0e92e18518f5e944d58c37)

12 months ago[ConstraintElim] fix crash with large constants in mul nsw
Erik Desjardins [Fri, 25 Aug 2023 03:46:16 +0000 (23:46 -0400)]
[ConstraintElim] fix crash with large constants in mul nsw

Another case of https://github.com/llvm/llvm-project/issues/55085.

The added test would trip an assertion due to calling `getSExtValue()` on a value that doesn't fit in int64_t.

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

(cherry picked from commit 66ec5df3a7f33366455d50769e4e878544becea6)

12 months ago[llvm-exegesis] Use mmap2 when mmap is unavailable to fix riscv32 build
Khem Raj [Fri, 25 Aug 2023 17:43:00 +0000 (10:43 -0700)]
[llvm-exegesis] Use mmap2 when mmap is unavailable to fix riscv32 build

Some 32-bit architectures don't have mmap and define mmap2 instead.
E.g. on riscv32 we may get

```
| /mnt/b/yoe/master/build/tmp/work-shared/llvm-project-source-17.0.0-r0/git/llvm/tools/llvm-exegesis/lib/X86/Target.cpp:1116:19: error: use of undeclared identifier 'SYS_mmap'
|  1116 |   generateSyscall(SYS_mmap, MmapCode);
|       |                   ^
| /mnt/b/yoe/master/build/tmp/work-shared/llvm-project-source-17.0.0-r0/git/llvm/tools/llvm-exegesis/lib/X86/Target.cpp:1134:19: error: use of undeclared identifier 'SYS_mmap'
|  1134 |   generateSyscall(SYS_mmap, GeneratedCode);                                                                                                                                       |       |                   ^
| 1 warning and 2 errors generated.
```

Co-Authored-By: Fangrui Song <i@maskray.me>
Differential Revision: https://reviews.llvm.org/D158375

(cherry picked from commit 01a92f06f23585f15b3e83b7c378d0df2d91e06b)

12 months agoFix up release note; NFC
Aaron Ballman [Tue, 29 Aug 2023 13:10:57 +0000 (09:10 -0400)]
Fix up release note; NFC

12 months ago[llvm-rc] Continue to use Argv[0] to resolve executable path
Amy Huang [Fri, 25 Aug 2023 22:12:56 +0000 (15:12 -0700)]
[llvm-rc] Continue to use Argv[0] to resolve executable path

In internal google builds, MainExecPath doesn't go to the directory with `clang`.
Fall back to using Argv0 if MainExecPath doesn't find any clangs.

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

(cherry picked from commit e4eb8d97e8afcb879dc5cd0da7a937dbb26fbf12)

12 months ago[Driver,X86] Ignore -mfpmath= for assembler input
Fangrui Song [Mon, 28 Aug 2023 20:37:33 +0000 (13:37 -0700)]
[Driver,X86] Ignore -mfpmath= for assembler input

Some options are only claimed in AddX86TargetArgs/etc (called by
Clang::RenderTargetOptions).
For assembler input, `Add*TargetArgs` is not called. If an option is
unclaimed, it either leads to a -Wunused-command-line-argument warning
or an error (if `TargetSpecific` is set)
```
// clang '-###' --target=x86_64 -mfpmath=sse -c a.s
clang: error: unsupported option '-mfpmath=sse' for target 'x86_64'
```

For -mfpmath=, it's actually claimed by RenderFloatingPointOptions,
which should be moved to AddARMTargetArgs/AddX86TargetArgs later
(non-AArch32-non-x86 targets give a frontend error).
This change is localized and similar to D153691, for release/17.x
backporting.

Fix https://github.com/llvm/llvm-project/issues/65023

Reviewed By: thesamesam

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

(cherry picked from commit 081afa3d04a4bc0d43c62b5b0e5a84f86a8a70ec)

12 months agoRevert "[clang] Set FP options in Sema when instantiating CompoundStmt"
Tobias Hieta [Mon, 28 Aug 2023 10:13:13 +0000 (12:13 +0200)]
Revert "[clang] Set FP options in Sema when instantiating CompoundStmt"

This reverts commit f1d5ea362577a8a1b5fafe775cf82a449daa3b07.

12 months agoRevert "[clang] Run test for concrete target"
Tobias Hieta [Mon, 28 Aug 2023 10:13:07 +0000 (12:13 +0200)]
Revert "[clang] Run test for concrete target"

This reverts commit e54f48384bb213f2c204c74d4e7e08a13904a9d6.

12 months ago[Driver] Add PIE support on Solaris
Rainer Orth [Fri, 18 Aug 2023 19:09:37 +0000 (21:09 +0200)]
[Driver] Add PIE support on Solaris

`clang` currently lacks PIE support on Solaris.  This patch fixes this,
also linking with `crtbeginS.o` and `crtendS.o` for `-pie` and `-shared`.

Tested on `amd64-pc-solaris2.11`, `sparcv9-sun-solaris2.11`, and
`x86_64-pc-linux-gnu`.

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

(cherry picked from commit 62945bb811169ffac7cf22c64b6dd3a3ad8d38f0)

12 months ago[libc++] Fix GNU/Hurd build
Samuel Thibault [Fri, 25 Aug 2023 17:53:20 +0000 (19:53 +0200)]
[libc++] Fix GNU/Hurd build

GNU/Hurd does have clock_gettime, it just doesn't define _POSIX_TIMERS because its support for timers is not complete.

Reviewed By: #libc, Mordante

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

(cherry picked from commit 1cfcc36812ff7857567f7c729c22ae0e2be0fb3a)

12 months ago[AArch64] Check opcode before trying to extract register from operand
David Tellenbach [Wed, 23 Aug 2023 21:46:31 +0000 (14:46 -0700)]
[AArch64] Check opcode before trying to extract register from operand

When matching FNEG patterns for the MachineCombiner we need to check for
opcodes first, before trying to extract a register from an operand.
Otherwise handling of instructions with non-register operands causes the
compiler to crash.

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

(cherry picked from commit 979e8ae4fce64546c65d24864eedd8165bc9787b)

12 months ago[PowerPC] Exclude frexp(long double) on linux
Lei Huang [Wed, 23 Aug 2023 20:45:39 +0000 (15:45 -0500)]
[PowerPC] Exclude frexp(long double) on linux

PowerPC on linux currently don't have support for lowering long double for
frexp().  Removing the tests until implementation is provided.

Reviewed By: #libc, amyk, Mordante

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

(cherry picked from commit 5adac8bebcf26841c1d87227c5043af83a9ef94b)