platform/upstream/llvm.git
2 years ago[gn build] Port 2c3bbac0c715
LLVM GN Syncbot [Thu, 23 Jun 2022 11:53:18 +0000 (11:53 +0000)]
[gn build] Port 2c3bbac0c715

2 years ago[libc++] Implement ranges::move{, _backward}
Nikolas Klauser [Thu, 23 Jun 2022 10:23:41 +0000 (12:23 +0200)]
[libc++] Implement ranges::move{, _backward}

This patch also adds a new optimization to `std::move`. It unwraps three `reverse_iterator`s if the wrapped iterator is a `contiguous_iterator` and the iterated type is trivially_movable. This allows us to simplify `ranges::move_backward` to a forward to `std::move` without any pessimization.

Reviewed By: var-const, #libc

Spies: libcxx-commits, mgorny

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

2 years ago[flang] Lowering passing variables to OPTIONAL VALUE
Valentin Clement [Thu, 23 Jun 2022 11:43:38 +0000 (13:43 +0200)]
[flang] Lowering passing variables to OPTIONAL VALUE

The case where the dummy argument is OPTIONAL was missing in the
handling of VALUE numerical and logical dummies (passBy::BaseAddressValueAttribute).
This caused segfaults while unconditionally copying actual arguments that were legally
absent at runtime.

Takes this bug as an opportunity to share the code that lowers arguments
that must be passed by BaseAddress, BaseAddressValueAttribute, BoxChar,
and CharBoxValueAttribute.
It has to deal with the exact same issues (being able to make contiguous
copies of the actual argument, potentially conditionally at runtime,
and potentially requiring a copy-back).
The VALUE case is the same as the non value case, except there is never
a copy-back and there is always a copy-in for variables. This two
differences are easily controlled by a byValue flag.

This as the benefit of implementing CHARACTER, VALUE for free that was
previously a hard TODO.

This patch is part of the upstreaming effort from fir-dev branch.

Reviewed By: kiranchandramohan

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

Co-authored-by: Jean Perier <jperier@nvidia.com>
2 years ago[VPlan] Update unit test after 569d84fe99e63.
Florian Hahn [Thu, 23 Jun 2022 11:44:41 +0000 (13:44 +0200)]
[VPlan] Update unit test after 569d84fe99e63.

2 years ago[tbaa] Handle base classes in struct tbaa
Bruno De Fraine [Thu, 23 Jun 2022 11:25:05 +0000 (13:25 +0200)]
[tbaa] Handle base classes in struct tbaa

This is a fix for the miscompilation reported in https://github.com/llvm/llvm-project/issues/55384

Not adding a new test case since existing test cases already cover base classes (including new-struct-path tbaa).

Reviewed By: jeroen.dobbelaere

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

2 years ago[VPlan] Remove dead recipes across whole plan.
Florian Hahn [Thu, 23 Jun 2022 11:36:02 +0000 (13:36 +0200)]
[VPlan] Remove dead recipes across whole plan.

This extends removeDeadRecipe to remove recipes across the whole plan.

Reviewed By: Ayal

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

2 years ago[docs] Document and publish LLVM community calendar
Kristof Beyls [Wed, 15 Jun 2022 13:09:03 +0000 (15:09 +0200)]
[docs] Document and publish LLVM community calendar

Let's introduce and publish an LLVM community calendar.

The idea is that organizers of events such as online sync-ups or office hours
invite calendar@llvm.org to the event they're creating. That way, the calendar
publicly visible at
https://calendar.google.com/calendar/u/0/embed?src=calendar@llvm.org will show
the event.

The hope is that having a single calendar showing all LLVM events makes it
easier for both new comers and experienced people to discover events they're
interested in.

This patch partially implements https://github.com/llvm/llvm-project/issues/55426

We could also give pointers to the calendar in a few other places, e.g. from
the main LLVM page, but let's introduce the incrementally.

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

2 years agoFix sphinx build for clang-tools-extra
Aaron Ballman [Thu, 23 Jun 2022 11:22:00 +0000 (07:22 -0400)]
Fix sphinx build for clang-tools-extra

I think it doesn't like the non-ASCII characters in the block, so using
a text block to disable syntax highlighting.

This should fix:
https://lab.llvm.org/buildbot/#/builders/115/builds/29888

2 years ago[Flang] Call the CSE pass in the pass pipeline
Kiran Chandramohan [Thu, 23 Jun 2022 10:55:30 +0000 (10:55 +0000)]
[Flang] Call the CSE pass in the pass pipeline

During the upstreaming process, it was decided to move contents
of the FIR CSE pass to the MLIR pass. Most of the FIR CSE changes
that are used are already moved to the MLIR pass. This patch calls
the MLIR CSE pass in places where the FIR CSE pass is called in the
pass pipeline.

Note: This is part of upstreaming from the fir-dev branch of
https://github.com/flang-compiler/f18-llvm-project.

Reviewed By: awarzynski, clementval

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

Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
Co-authored-by: Valentin Clement <clementval@gmail.com>
Co-authored-by: Andrzej Warzynski <andrzej.warzynski@arm.com>
2 years ago[Clang] Don't test register allocation
Nikita Popov [Thu, 23 Jun 2022 10:44:46 +0000 (12:44 +0200)]
[Clang] Don't test register allocation

This test was broken by 719658d078c4093d1ee716fb65ae94673df7b22b.

How did an assembly test get into clang/test?

2 years agoRevert "[LLDB] Handle DIE with DW_AT_low_pc and empty ranges"
David Spickett [Thu, 23 Jun 2022 10:33:05 +0000 (10:33 +0000)]
Revert "[LLDB] Handle DIE with DW_AT_low_pc and empty ranges"

This reverts commit 1beededc0e7d86d09cee972f0b9f0030a139cab4.

Due to failures on the Arm/AArch64 build bots:
https://lab.llvm.org/buildbot/#/builders/96/builds/25032

2 years ago[X86] Update some AMX tests to use opaque pointers (NFC)
Nikita Popov [Thu, 23 Jun 2022 10:18:28 +0000 (12:18 +0200)]
[X86] Update some AMX tests to use opaque pointers (NFC)

This only touches IR tests (or tests without codegen changes).

2 years ago[AMDGPU][MC][GFX11] Correct disassembly of VOP3.DPP8 opcodes
Dmitry Preobrazhensky [Thu, 23 Jun 2022 10:07:45 +0000 (13:07 +0300)]
[AMDGPU][MC][GFX11] Correct disassembly of VOP3.DPP8 opcodes

Fix bug #56163.
Add W32/W64 tests for all VOP3.DPP opcodes.

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

2 years ago[analyzer] Structured binding to arrays
isuckatcs [Wed, 8 Jun 2022 21:23:07 +0000 (23:23 +0200)]
[analyzer] Structured binding to arrays

Introducing structured binding to data members and more.
To handle binding to arrays, ArrayInitLoopExpr is also
evaluated, which enables the analyzer to store information
in two more cases. These are:
  - when a lambda-expression captures an array by value
  - in the implicit copy/move constructor for a class
    with an array member

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

2 years ago[IR] Export ConstantFold.h header (NFC)
Nikita Popov [Mon, 20 Jun 2022 15:38:04 +0000 (17:38 +0200)]
[IR] Export ConstantFold.h header (NFC)

This is in preparation for https://discourse.llvm.org/t/rfc-remove-most-constant-expressions/63179.
As part of that change, we'll want to invoke some of these constant
folding APIs explicitly, as it won't happen as part of
ConstantExpr::getXYZ() anymore.

Ideally, we'd merge these with the DL-aware constant folding APIs
and only call those, but this is not easily possible for some
current usages (most important IRBuilder, which uses DL-independent
constant folding by default, and some major layering changes would
be needed to change that).

This is basically a reboot of D115035 with different motivation.

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

2 years ago[clang][analyzer] Fix StdLibraryFunctionsChecker 'mkdir' return value.
Balázs Kéri [Thu, 23 Jun 2022 08:24:45 +0000 (10:24 +0200)]
[clang][analyzer] Fix StdLibraryFunctionsChecker 'mkdir' return value.

The functions 'mkdir', 'mknod', 'mkdirat', 'mknodat' return 0 on success
and -1 on failure. The checker modeled these functions with a >= 0
return value on success which is changed to 0 only. This fix makes
ErrnoChecker work better for these functions.

Reviewed By: steakhal

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

2 years ago[LoongArch] Combine ((x & shifted_mask) >> shamt) to bstrpick.{w/d}
Weining Lu [Thu, 23 Jun 2022 09:07:42 +0000 (17:07 +0800)]
[LoongArch] Combine ((x & shifted_mask) >> shamt) to bstrpick.{w/d}

This is an improvement to LoongArch codegen. In D127206 we combined
((x >> shamt) & shifted_mask) to bstrpick and here we do a similar
combination when certain conditions are met.

Thanks to @xen0n for reminding me.

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

2 years ago[ConstraintElimination] Transfer info from SGT to unsigned system.
Florian Hahn [Thu, 23 Jun 2022 09:04:51 +0000 (11:04 +0200)]
[ConstraintElimination] Transfer info from SGT to unsigned system.

If A >s B then A >=u 0, if B >=s -1.

https://alive2.llvm.org/ce/z/cncGKi

2 years ago[mlir] Add an additional check to vectorizeStaticLinalgOpPrecondition.
Adrian Kuegel [Wed, 22 Jun 2022 11:50:30 +0000 (13:50 +0200)]
[mlir] Add an additional check to vectorizeStaticLinalgOpPrecondition.

We need to make sure that the types used in the body are valid element types
for VectorType.

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

2 years ago[fastalloc] Support allocating specific register class in fastalloc
Luo, Yuanke [Thu, 23 Jun 2022 01:18:47 +0000 (09:18 +0800)]
[fastalloc] Support allocating specific register class in fastalloc

The base RA support infrastructure that only allow a specific register
class be allocated in RA pss. Since greedy RA, basic RA derived from
base RA, they all allow allocating specific register class. Fast RA
doesn't support allocating register for specific register class. This
patch is to enable ShouldAllocateClass in fast RA, so that it can
support allocating register for specific register class.

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

2 years agoRevert D115462 "[SLP]Improve shuffles cost estimation where possible."
Fangrui Song [Thu, 23 Jun 2022 06:16:31 +0000 (23:16 -0700)]
Revert D115462 "[SLP]Improve shuffles cost estimation where possible."

This reverts commit cac60940b771a0685d058a5b471c84cea05fdc46.

Caused -Os -fsanitize=memory -march=haswell miscompile to pytorch/cpuinfo.
See my latest comment (may update) on D115462.

2 years agoRevert "[SLP]Fix a crash when insert subvector is out of range."
Fangrui Song [Thu, 23 Jun 2022 05:31:01 +0000 (22:31 -0700)]
Revert "[SLP]Fix a crash when insert subvector is out of range."

This reverts commit f1ee2738b3d70fea803ac1f3401c2fc9f61e514a.

Revert due to the revert of a dependent commit `[SLP]Improve shuffles cost estimation where possible.`

2 years ago[RISCV] Refactor code to remove some small wrapper methods and merge two functions...
Craig Topper [Thu, 23 Jun 2022 06:04:30 +0000 (23:04 -0700)]
[RISCV] Refactor code to remove some small wrapper methods and merge two functions together. NFC

2 years agoRevert "[SelectionDAG][DAGCombiner] Reuse exist node by reassociate"
chenglin.bi [Thu, 23 Jun 2022 05:21:51 +0000 (13:21 +0800)]
Revert "[SelectionDAG][DAGCombiner] Reuse exist node by reassociate"

This reverts commit 6c951c5ee6d0b848877cb8ac7a9cb2a9ef9ebbb5.

2 years ago[RS4GC] Handle freeze case for vector
Serguei Katkov [Tue, 21 Jun 2022 08:57:44 +0000 (15:57 +0700)]
[RS4GC] Handle freeze case for vector

Finding BDV for vector value does not handle freeze instruction.
Adding its handling as it is done for scalar case.

Reviewed By: apilipenko
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D128254

2 years ago[flang] Fixes several bugs relating to initialization expressions. An (#1493)
Valentin Clement [Thu, 23 Jun 2022 04:54:03 +0000 (06:54 +0200)]
[flang] Fixes several bugs relating to initialization expressions. An (#1493)

Fixes several bugs relating to initialization expressions. An
initialization expression has no access to dynamic resources like the
stack or the heap. It must reduce to a relocatable expression that the
loader can complete at runtime.

Adds regression test.

This patch is part of the upstreaming effort from fir-dev branch.

Reviewed By: PeteSteinfeld

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

Co-authored-by: Jean Perier <jperier@nvidia.com>
Co-authored-by: Eric Schweitz <eschweitz@nvidia.com>
2 years ago[GlobalISel][TableGen] Qualify calls to llvm::format that have ::std:: types as param...
Charlie Barto [Thu, 23 Jun 2022 04:34:19 +0000 (21:34 -0700)]
[GlobalISel][TableGen] Qualify calls to llvm::format that have ::std:: types as parameters

... to avoid ambiguity in overload resolution when ADL finds `std::format`.

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

2 years ago[TableGen] Add new operator !exists
wangpc [Thu, 23 Jun 2022 03:11:09 +0000 (11:11 +0800)]
[TableGen] Add new operator !exists

We can cast a string to a record via !cast, but we have no mechanism
to check if it is valid and TableGen will raise an error if failed to
cast. Besides, we have no semantic null in TableGen (we have `?` but
different backends handle uninitialized value differently), so operator
like `dyn_cast<>` is hard to implement.

In this patch, we add a new operator `!exists<T>(s)` to check whether
a record with type `T` and name `s` exists. Self-references are allowed
just like `!cast`.

By doing these, we can write code like:
```
class dyn_cast_to_record<string name> {
  R value = !if(!exists<R>(name), !cast<R>(name), default_value);
}
defvar v = dyn_cast_to_record<"R0">.value; // R0 or default_value.
```

Reviewed By: tra, nhaehnle

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

2 years ago[gn build] Port 2962f9df7ca3
LLVM GN Syncbot [Thu, 23 Jun 2022 02:41:57 +0000 (02:41 +0000)]
[gn build] Port 2962f9df7ca3

2 years agostop llvm-reduce from introducing undefs
John Regehr [Tue, 21 Jun 2022 23:30:52 +0000 (17:30 -0600)]
stop llvm-reduce from introducing undefs

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

2 years ago[mlir][linalg] move isElementwise() to Linalg/Utils (NFC)
Okwan Kwon [Wed, 22 Jun 2022 22:59:53 +0000 (15:59 -0700)]
[mlir][linalg] move isElementwise() to Linalg/Utils (NFC)

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

2 years ago[ASan][Darwin] XFAIL test; atos does not show line numbers for globals
Julian Lettner [Thu, 23 Jun 2022 01:19:31 +0000 (18:19 -0700)]
[ASan][Darwin] XFAIL test; atos does not show line numbers for globals

atos currently doesn't show source line numbers for global variables, so
global-location.cpp is failing after we switched from ASan-specific
metadata to normal symbolication.

See:
https://reviews.llvm.org/D127552

2 years agoAMDGPU: Add missing implicit uses in tests
Matt Arsenault [Fri, 17 Jun 2022 22:24:28 +0000 (18:24 -0400)]
AMDGPU: Add missing implicit uses in tests

These tests were deleting the copy instruction, defeating
the purpose of having it.

2 years agoAMDGPU: Fix invalid liveness after si-optimize-exec-masking-pre-ra
Matt Arsenault [Fri, 10 Jun 2022 19:07:39 +0000 (15:07 -0400)]
AMDGPU: Fix invalid liveness after si-optimize-exec-masking-pre-ra

This was leaving behind a use at the deleted instruction which the
verifier would fail during allocation.

2 years agoInlineSpiller: Don't fold spills into undef reads
Matt Arsenault [Wed, 15 Jun 2022 21:04:05 +0000 (17:04 -0400)]
InlineSpiller: Don't fold spills into undef reads

This was producing a load into a dead register which was a verifier
error.

2 years ago[OpenMP] Add handling cases when filter(tid) appears with default(none)
Fazlay Rabbi [Thu, 23 Jun 2022 00:10:31 +0000 (17:10 -0700)]
[OpenMP] Add handling cases when filter(tid) appears with default(none)

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

2 years ago[SampleProfile][Inline] Annotate sample profile inline remarks with link phase (preli...
Mingming Liu [Wed, 1 Jun 2022 22:21:59 +0000 (15:21 -0700)]
[SampleProfile][Inline] Annotate sample profile inline remarks with link phase (prelink/postlink) information.

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

2 years ago[SVE] Make ISD::SPLAT_VECTOR a legal operation.
Paul Walker [Thu, 24 Feb 2022 18:40:23 +0000 (18:40 +0000)]
[SVE] Make ISD::SPLAT_VECTOR a legal operation.

The implication of this patch being AArch64ISD::DUP no longer
supports scalable vectors.

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

2 years ago[mlir][vulkan-runner] fix VK_ERROR_INCOMPATIBLE_DRIVER error
jackalcooper [Tue, 21 Jun 2022 16:28:36 +0000 (12:28 -0400)]
[mlir][vulkan-runner] fix VK_ERROR_INCOMPATIBLE_DRIVER error

On macOS, Vulkan is emulated by MoltenVK. Some extra flags are
required for "building robust and portable Vulkan based
applications that are good citizens in the Vulkan ecosystem".

More information:
https://vulkan.lunarg.com/doc/sdk/1.3.216.0/mac/getting_started.html

Reviewed By: antiagainst

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

2 years ago[libc++] Implement P0154R1 (Hardware inference size)
Nikolas Klauser [Wed, 22 Jun 2022 19:10:57 +0000 (21:10 +0200)]
[libc++] Implement P0154R1 (Hardware inference size)

`__GCC_CONSTRUCTIVE_SIZE` and `__GCC_DESTRUCTIVE_SIZE` are available since GCC 12. I'm assuming clang will also implement these for compatability with libstdc++.

Reviewed By: ldionne, #libc

Spies: h-vetinari, libcxx-commits, arichardson

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

2 years ago[libc++] Simplify the visibility attributes
Nikolas Klauser [Wed, 22 Jun 2022 09:14:04 +0000 (11:14 +0200)]
[libc++] Simplify the visibility attributes

Reviewed By: ldionne, #libc

Spies: libcxx-commits

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

2 years ago[ELF][test] Clean up thinlto*
Fangrui Song [Wed, 22 Jun 2022 23:19:17 +0000 (16:19 -0700)]
[ELF][test] Clean up thinlto*

2 years ago[MTE] [HWASan] Use LoopInfo for reachability queries.
Florian Mayer [Wed, 15 Jun 2022 22:31:05 +0000 (15:31 -0700)]
[MTE] [HWASan] Use LoopInfo for reachability queries.

The reachability queries default to "reachable" after exploring too many
basic blocks. LoopInfo helps it skip over the whole loop.

Reviewed By: eugenis

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

2 years ago[lldb/Fuzzer] Add command interpreter fuzzer for LLDB
Chelsea Cassanova [Tue, 21 Jun 2022 18:11:27 +0000 (14:11 -0400)]
[lldb/Fuzzer] Add command interpreter fuzzer for LLDB

This adds a command interpreter fuzzer to LLDB's fuzzing library.
The input data from the fuzzer is used as input for the command
interpreter.
Input data for the fuzzer is guided by a dictionary of keywords used in
LLDB, such as "breakpoint", "target" and others.

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

2 years agoFix a misspell. NFC
Adrian Tong [Wed, 22 Jun 2022 21:22:45 +0000 (21:22 +0000)]
Fix a misspell. NFC

2 years ago[StructurizeCFG] Improve basic block ordering
Brendon Cahoon [Wed, 6 Apr 2022 14:05:56 +0000 (09:05 -0500)]
[StructurizeCFG] Improve basic block ordering

StructurizeCFG linearizes the successors of branching basic block
by adding Flow blocks to record the true/false path for branches
and back edges. This patch reduces the number of Phi values needed
to capture the control flow path by improving the basic block
ordering.

Previously, StructurizeCFG adds loop exit blocks outside of the
loop. StructurizeCFG sets a boolean value to indicate the path
taken, and all exit block live values extend to after the loop.
For loops with a large number of exits blocks, this creates a
huge number of values that are maintained, which increases
compilation time and register pressure. This is problem
especially with ASAN, which adds early exits to blocks with
unreachable instructions for each instrumented check in the loop.

In specific cases, this patch reduces the number of values needed
after the loop by moving the exit block into the loop. This is
done for blocks that have a single predecessor and single successor
by moving the block to appear just after the predecessor.

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

2 years ago[lldb] Fix off-by-one error in the AppleObjCRuntimeV2 utility function
Jonas Devlieghere [Wed, 22 Jun 2022 20:46:00 +0000 (13:46 -0700)]
[lldb] Fix off-by-one error in the AppleObjCRuntimeV2 utility function

Fix an off-by-one error in the utility function used to extract the
dynamic class info. This resulted in a buffer overflow in the inferior
which interrupted our utility function.

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

2 years ago[lldb] Return the correct utility function in AppleObjCRuntimeV2
Jonas Devlieghere [Wed, 22 Jun 2022 20:39:56 +0000 (13:39 -0700)]
[lldb] Return the correct utility function in AppleObjCRuntimeV2

A copy/paste error in GetClassInfoUtilityFunction resulted in the wrong
utility function being returned: copyRealizedClassList instead of
getRealizedClassList_trylock.

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

2 years ago[UnifyLoopExits] Reduce number of guard blocks
Brendon Cahoon [Wed, 6 Apr 2022 01:53:46 +0000 (20:53 -0500)]
[UnifyLoopExits] Reduce number of guard blocks

UnifyLoopExits creates a single exit, a control flow hub, for
loops with multiple exits. There is an input to the block for
each loop exiting block and an output from the block for each
loop exit block. Multiple checks, or guard blocks, are needed
to branch to the correct exit block.

For large loops with lots of exit blocks, all the extra guard
blocks cause problems for StructurizeCFG and subsequent passes.
This patch reduces the number of guard blocks needed when the
exit blocks branch to a common block (e.g., an unreachable
block). The guard blocks are reduced by changing the inputs
and outputs of the control flow hub. The inputs are the exit
blocks and the outputs are the common block.

Reducing the guard blocks enables StructurizeCFG to reorder the
basic blocks in the CFG to reduce the values that exit a loop
with multiple exits. This reduces the compile-time of
StructurizeCFG and also reduces register pressure.

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

2 years agoRevert "[Attributor] Ensure to use the proper liveness AA"
Evgenii Stepanov [Wed, 22 Jun 2022 18:19:56 +0000 (11:19 -0700)]
Revert "[Attributor] Ensure to use the proper liveness AA"

Reason: memory leaks

This reverts commit 083010312aa4a0ba0cd5299bd3b039af8fb6d58f.

2 years ago[clang-tidy][docs] Fix a couple of missed cases from 6e566bc5523
Nathan James [Wed, 22 Jun 2022 20:37:16 +0000 (21:37 +0100)]
[clang-tidy][docs] Fix a couple of missed cases from 6e566bc5523

A few of the checks had documentation URLs that weren't updated in the aforementioned commit.

2 years ago[flang] Capture result interface of functions called in internal procedures
Valentin Clement [Wed, 22 Jun 2022 20:32:21 +0000 (22:32 +0200)]
[flang] Capture result interface of functions called in internal procedures

Character and array results are allocated on the caller side. This
require evaluating the result interface on the call site. When calling
such functions inside an internal procedure, it is possible that the
interface is defined in the host, in which case the lengths/bounds of
the function results must be captured so that they are available in
the internal function to emit the call.

To handle this case, extend the PFT symbol visit to visit the bounds and length
parameters of functions called in the internal procedure parse tree.

This patch is part of the upstreaming effort from fir-dev branch.

Reviewed By: klausler

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

Co-authored-by: Jean Perier <jperier@nvidia.com>
2 years ago[clang-tidy][docs] Reorganise release notes
Nathan James [Wed, 22 Jun 2022 20:21:24 +0000 (21:21 +0100)]
[clang-tidy][docs] Reorganise release notes

2 years agoFix a bug with "process continue -b" when no breakpoints are
Jim Ingham [Wed, 22 Jun 2022 19:16:24 +0000 (12:16 -0700)]
Fix a bug with "process continue -b" when no breakpoints are
passed.  I was passing the empty list of breakponts to the
VerifyBreakpointList routine, but that treats empty as "choose
the default breakpoint" which we don't want here.

2 years ago[mlir][Linalg] SplitReduction implementation without tensor::ExpandShapeOp
Nicolas Vasilache [Tue, 21 Jun 2022 12:11:29 +0000 (05:11 -0700)]
[mlir][Linalg] SplitReduction implementation without tensor::ExpandShapeOp

This revision proposes a different implementation of the SplitReductoin transformation that does
not rely on tensor::ExpandShapeOp.

Previously, a dimension `[k]` would be split into `[k][kk]` via an ExpandShapeOp.
Instead, this revision proposes to rewrite `[k]` into `[factor * k + kk]`.

There are different tradeoffs involved  but the proposed implementation is more general because
the affine rewrite is well-defined. In particular, it works naturally with `?` parallel dimensions and
non-trivial indexing maps.

A further rewrite of `[factor * k + kk]` + ExpandShapeOp is possible as a followup.

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

2 years agoRename GCCBuiltin into ClangBuiltin
Guillaume Gomez [Wed, 22 Jun 2022 18:48:31 +0000 (19:48 +0100)]
Rename GCCBuiltin into ClangBuiltin

This patch is needed because developers expect "GCCBuiltin" items to be the GCC intrinsics equivalent and not the Clang internals.

Reviewed By: #libc_abi, RKSimon, xbolva00

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

2 years ago[flang] Remove some auto
Valentin Clement [Wed, 22 Jun 2022 18:47:48 +0000 (20:47 +0200)]
[flang] Remove some auto

This patch replaces some `auto` with proper type. This was done in fir-dev
but not upstreamed yet.

This patch is part of the upstreaming effort from fir-dev branch.

Reviewed By: klausler

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

2 years ago[flang] Handle BINC(C) variables and add TODO for corner cases
Valentin Clement [Wed, 22 Jun 2022 18:46:30 +0000 (20:46 +0200)]
[flang] Handle BINC(C) variables and add TODO for corner cases

- BIND(C) was ignored in lowering for objects (it can be used on
module and common blocks): use the bind name as the fir.global name.

- When an procedure is declared BIND(C) indirectly via an interface,
  it should have a BIND(C) name. This was not the case because
  GetBindName()/bindingName() return nothing in this case: detect this
  case in mangler.cpp and use the symbol name.

Add TODOs for corner cases:

- BIND(C) module variables may be initialized on the C side. This does
  not fit well with the current linkage strategy. Add a TODO until this
  is revisited.

- BIND(C) internal procedures should not have a binding label (see
  Fortran 2018 section 18.10.2 point 2), yet we currently lower them as
  if they were BIND(C) external procedure.
  I think this and the indirect interface case should really be
  handled by symbol.GetBindName instead of adding more logic in
  lowering to deal with this case: add a TODO.

This patch is part of the upstreaming effort from fir-dev branch.

Reviewed By: klausler

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

Co-authored-by: Jean Perier <jperier@nvidia.com>
2 years ago[libc++] Clarify std::function release note
Joe Loser [Wed, 22 Jun 2022 17:25:43 +0000 (11:25 -0600)]
[libc++] Clarify std::function release note

Replace "This option it" with "This option" to make the sentence read a bit
clearer.

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

2 years ago[MTE] [HWASan] Support diamond lifetimes.
Florian Mayer [Tue, 14 Jun 2022 22:41:27 +0000 (15:41 -0700)]
[MTE] [HWASan] Support diamond lifetimes.

We were overly conservative and required a ret statement to be dominated
completely be a single lifetime.end marker. This is quite restrictive
and leads to two problems:

* limits coverage of use-after-scope, as we degenerate to
  use-after-return;
* increases stack usage in programs, as we have to remove all lifetime
  markers if we degenerate to use-after-return, which prevents
  reuse of stack slots by the stack coloring algorithm.

Reviewed By: eugenis

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

2 years ago[trace] Add an option to dump instructions in json and to a file
Walter Erquinigo [Sat, 18 Jun 2022 22:44:37 +0000 (15:44 -0700)]
[trace] Add an option to dump instructions in json and to a file

In order to provide simple scripting support on top of instruction traces, a simple solution is to enhance the `dump instructions` command and allow printing in json and directly to a file. The format is verbose and not space efficient, but it's not supposed to be used for really large traces, in which case the TraceCursor API is the way to go.

- add a -j option for printing the dump in json
- add a -J option for pretty printing the json output
- add a -F option for specifying an output file
- add a -a option for dumping all the instructions available starting at the initial point configured with the other flags
- add tests for all cases
- refactored the instruction dumper and abstracted the actual "printing" logic. There are two writer implementations: CLI and JSON. This made the dumper itself much more readable and maintanable

sample output:

```
(lldb) thread trace dump instructions  -t -a --id 100 -J
[
  {
    "id": 100,
    "tsc": "43591204528448966"
    "loadAddress": "0x407a91",
    "module": "a.out",
    "symbol": "void std::deque<Foo, std::allocator<Foo>>::_M_push_back_aux<Foo>(Foo&&)",
    "mnemonic": "movq",
    "source": "/usr/include/c++/8/bits/deque.tcc",
    "line": 492,
    "column": 30
  },
  ...
```

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

2 years ago[clang-tidy] Organize test files into subdirectories by module (NFC)
Richard [Fri, 17 Jun 2022 01:02:47 +0000 (19:02 -0600)]
[clang-tidy] Organize test files into subdirectories by module (NFC)

Eliminate clutter by reorganizing the Lit test files for clang-tidy:
- Move checkers/<module>-* to checkers/<module>/*.
- Move module specific inputs from Inputs to <module>/Inputs.  Remove
  any module prefix from the file or subdirectory name as they are no
  longer needed.
- Introduce a Lit substitution %clang_tidy_headers for the system
  headers in checkers/Inputs/Headers and use this throughout.  This
  avoids referencing system headers through a relative path to the
  parent directory and makes it clear that these fake system headers are
  shared among all modules.
- Update add_new_check.py to follow the above conventions when creating
  the boiler plate test files for a new check.
- Update Contributing.rst to describe per-module Inputs directory and
  fix link to test source code.

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

2 years ago[LLDB] Handle DIE with DW_AT_low_pc and empty ranges
Alexander Yermolovich [Wed, 22 Jun 2022 17:52:19 +0000 (10:52 -0700)]
[LLDB] Handle DIE with DW_AT_low_pc and empty ranges

The case comes out of how BOLT handles transformation of
DW_AT_low_pc/DW_AT_high_pc into DW_AT_low_pc/DW_AT_high_pc
with latter being 0.

Reviewed By: clayborg

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

2 years ago[NFC] [HWASan] Remove indirection for getting analyses.
Florian Mayer [Wed, 15 Jun 2022 22:54:12 +0000 (15:54 -0700)]
[NFC] [HWASan] Remove indirection for getting analyses.

This was necessary for code reuse between the old and new passmanager.
With the old pass-manager gone, this is no longer necessary.

Reviewed By: eugenis, myhsu

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

2 years ago[Support/BLAKE3] Fix error in prior commit, apply `-mavx512vl` for `blake3_avx512_x86...
Argyrios Kyrtzidis [Wed, 22 Jun 2022 17:49:31 +0000 (10:49 -0700)]
[Support/BLAKE3] Fix error in prior commit, apply `-mavx512vl` for `blake3_avx512_x86-64_unix.S` when including it

2 years ago[lldb] Second attempt at fixing command-target-create-resolve-exe.test on the buildbot
Alvin Wong [Wed, 22 Jun 2022 17:48:01 +0000 (20:48 +0300)]
[lldb] Second attempt at fixing command-target-create-resolve-exe.test on the buildbot

2 years ago[libc++][NFC] Merges unused functions in callers.
Mark de Wever [Tue, 14 Jun 2022 15:47:51 +0000 (17:47 +0200)]
[libc++][NFC] Merges unused functions in callers.

This is a follow up based on a request of @jloser in D127594.

As drive-by qualified the function calls in the <bit> header.

Reviewed By: #libc, EricWF

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

2 years ago[LinkerWrapper][NFC] Change interface to use a StringRef to TempFiles
Joseph Huber [Wed, 22 Jun 2022 15:17:14 +0000 (11:17 -0400)]
[LinkerWrapper][NFC] Change interface to use a StringRef to TempFiles

Summary:
Currently we use temporary files to write the intermediate results to.
However, these are stored as regular strings and we do a few unnecessary
copies and conversions of them. This patch simply replaces these strings
with a reference to the filename stored in the list of temporary files.
The temporary files will stay alive during the whole linking phase and
have stable pointers, so we should be able to cheaply pass references to
them rather than copying them every time.

2 years ago[Support] Change TrackingStatistic and NoopStatistic to use uint64_t instead of unsigned.
Mingming Liu [Fri, 17 Jun 2022 15:49:04 +0000 (08:49 -0700)]
[Support] Change TrackingStatistic and NoopStatistic to use uint64_t instead of unsigned.

Binary size of `clang` is trivial; namely, numerical value doesn't
change when measured in MiB, and `.data` section increases from 139Ki to
173 Ki.

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

2 years ago[MLIR] Fix top-level comment (NFC)
lorenzo chelini [Wed, 22 Jun 2022 17:04:40 +0000 (19:04 +0200)]
[MLIR] Fix top-level comment (NFC)

2 years ago[Symbolize] Parse multi-line markup elements.
Daniel Thornburgh [Fri, 29 Apr 2022 19:09:19 +0000 (19:09 +0000)]
[Symbolize] Parse multi-line markup elements.

This allows registering certain tags as possibly beginning multi-line
elements in the symbolizer markup parser. The parser is kept agnostic to
how lines are delimited; it reports the entire contents, including line
endings, once the end of element marker is reached.

Reviewed By: peter.smith

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

2 years agoAdd a "-b" option to "process continue" to run to a set of breakpoints,
Jim Ingham [Wed, 8 Jun 2022 01:03:23 +0000 (18:03 -0700)]
Add a "-b" option to "process continue" to run to a set of breakpoints,
temporarily ignoring the others.

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

2 years ago[iwyu] Handle regressions in libLLVM header include
serge-sans-paille [Wed, 22 Jun 2022 14:20:21 +0000 (16:20 +0200)]
[iwyu] Handle regressions in libLLVM header include

Running iwyu-diff on LLVM codebase since fb67d683db46dfd88da09d99 detected a few
regressions, fixing them.

The impact on preprocessed output is negligible: -4k lines.

2 years ago[clang-tidy] Fix documentation (NFC)
Richard [Wed, 22 Jun 2022 16:46:27 +0000 (10:46 -0600)]
[clang-tidy] Fix documentation (NFC)

The documentation files were reorganized into subdirectories, but a new
check was added concurrently and wasn't rebased correctly before
submitting.  Sort the new clang-tidy checks by check name and fix the
indentation of bugprone-unchecked-optional-access.

2 years ago[libc++] Reduces std::to_chars instantiations.
Mark de Wever [Mon, 20 Jun 2022 16:28:34 +0000 (18:28 +0200)]
[libc++] Reduces std::to_chars instantiations.

Instead of instantiating all functions called by std::to_chars for the
integral types only instantiate them for 32 and 64 bit integral types.
This results in a smaller binary when using different types.

In an example using the types: signed char, short, int, long, long long,
unsigned char, unsigned short, unsigned int, unsigned long, and
unsigned long long this saved 2792 bytes of code size. For libc++.so.1
is saves 688 bytes of code size (64-bit Linux).

This was discovered while investigating a solution for #52709.

Reviewed By: #libc, ldionne

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

2 years ago[mlir][sparse] fix typo in CHECK test
Aart Bik [Tue, 21 Jun 2022 23:03:25 +0000 (16:03 -0700)]
[mlir][sparse] fix typo in CHECK test

Thanks Peiming for reporting!

Reviewed By: Peiming

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

2 years ago[mlir][sparse] accept sparse reshape (expand/collapse)
Aart Bik [Tue, 21 Jun 2022 23:47:44 +0000 (16:47 -0700)]
[mlir][sparse] accept sparse reshape (expand/collapse)

This revision makes sure we accept sparse tensors as arguments
of the expand/collapse reshaping operations in the tensor dialect.
Note that the actual lowering to runnable IR is still TBD.

Reviewed By: springerm

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

2 years ago[MLIR][Presburger] introduce SlowMPInt, an auto-resizing APInt for fully correct...
Arjun P [Wed, 22 Jun 2022 16:29:46 +0000 (18:29 +0200)]
[MLIR][Presburger] introduce SlowMPInt, an auto-resizing APInt for fully correct signed integer computations

The Presburger library currently uses int64_t throughout for its integers.
This runs the risk of silently producing incorrect results when overflows occur.
Fixing this issue requires some sort of multiprecision integer
that transparently supports aribtrary arithmetic computations.

The class SlowMPInt provides this functionality, and is intended to be used
as the slow path fallback for a more optimized upcoming class, MPInt, that optimizes
for the Presburger library's workloads.

Reviewed By: ftynse

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

2 years ago[LSR] Don't allow zero quotient as scale ref. PR56160
Max Kazantsev [Wed, 22 Jun 2022 13:48:47 +0000 (20:48 +0700)]
[LSR] Don't allow zero quotient as scale ref. PR56160

Scale reg should never be zero, so when the quotient is zero, we
cannot assign it there. Limit this transform to avoid this situation.

Differential Revision: https://reviews.llvm.org/D128339
Reviewed By: eopXD

2 years ago[RISCV] Add RISCVISD opcodes for the rest of get*Addr.
Craig Topper [Wed, 22 Jun 2022 16:00:15 +0000 (09:00 -0700)]
[RISCV] Add RISCVISD opcodes for the rest of get*Addr.

This adds RISCVISD opccodes for LA, LA_TLS_IE, and LA_TLS_GD to
remove creation of MachineSDNodes form get*Addr. This makes the
code consistent with the previous patches that added RISCVISD::HI,
ADD_LO, LLA, and TPREL_ADD.

Reviewed By: asb

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

2 years ago[libc++][CI] Use GCC 12 labels.
Mark de Wever [Wed, 22 Jun 2022 16:11:19 +0000 (18:11 +0200)]
[libc++][CI] Use GCC 12 labels.

2 years ago[DirectX] Support opaque ptr for ValueAsMetadata in DXILBitcodeWriter
Xiang Li [Tue, 14 Jun 2022 00:15:56 +0000 (17:15 -0700)]
[DirectX] Support opaque ptr for ValueAsMetadata in DXILBitcodeWriter

When writeValueAsMetadata for GlobalVariable and Function, write TypedPointerType for ValueType and FunctionType.

Reviewed By: bogner

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

2 years ago[flang] Add semantic check for C1520
Peixin Qiao [Wed, 22 Jun 2022 16:04:24 +0000 (00:04 +0800)]
[flang] Add semantic check for C1520

As Fortran 2018 C1520, if proc-language-binding-spec with NAME= is
specified, then proc-decl-list shall contain exactly one proc-decl,
which shall neither have the POINTER attribute nor be a dummy procedure.
Add this check.

Reviewed By: klausler

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

2 years ago[flang][Driver] Refine _when_ driver diagnostics are formatted
Peixin Qiao [Wed, 22 Jun 2022 15:56:34 +0000 (23:56 +0800)]
[flang][Driver] Refine _when_ driver diagnostics are formatted

This patch refines //when// driver diagnostics are formatted so that
`flang-new` and `flang-new -fc1` behave consistently with `clang` and
`clang -cc1`, respectively. This change only applies to driver diagnostics.
Scanning, parsing and semantic diagnostics are separate and not covered here.

**NEW BEHAVIOUR**
To illustrate the new behaviour, consider the following input file:
```! file.f90
program m
  integer :: i = k
end
```
In the following invocations, "error: Semantic errors in file.f90" _will be_
formatted:
```
$ flang-new file.f90
error: Semantic errors in file.f90
./file.f90:2:18: error: Must be a constant value
    integer :: i = k
$ flang-new -fc1 -fcolor-diagnostics file.f90
error: Semantic errors in file.f90
./file.f90:2:18: error: Must be a constant value
    integer :: i = k
```

However, in the following invocations, "error: Semantic errors in file.f90"
_will not be_ formatted:
```
$ flang-new -fno-color-diagnostics file.f90
error: Semantic errors in file.f90
./file.f90:2:18: error: Must be a constant value
    integer :: i = k
$ flang-new -fc1 file.f90
error: Semantic errors in file.f90
./file.f90:2:18: error: Must be a constant value
    integer :: i = k
```

Before this change, none of the above would be formatted. Note also that the
default behaviour in `flang-new` is different to `flang-new -fc1` (this is
consistent with Clang).

**NOTES ON IMPLEMENTATION**
Note that the diagnostic options are parsed in `createAndPopulateDiagOpt`s in
driver.cpp. That's where the driver's `DiagnosticEngine` options are set. Like
most command-line compiler driver options, these flags are "claimed" in
Flang.cpp (i.e.  when creating a frontend driver invocation) by calling
`getLastArg` rather than in driver.cpp.

In Clang's Options.td, `defm color_diagnostics` is replaced with two separate
definitions: `def fcolor_diagnostics` and def fno_color_diagnostics`. That's
because originally `color_diagnostics` derived from `OptInCC1FFlag`, which is a
multiclass for opt-in options in CC1. In order to preserve the current
behaviour in `clang -cc1` (i.e. to keep `-fno-color-diagnostics` unavailable in
`clang -cc1`) and to implement similar behaviour in `flang-new -fc1`, we can't
re-use `OptInCC1FFlag`.

Formatting is only available in consoles that support it and will normally mean that
the message is printed in bold + color.

Co-authored-by: Andrzej Warzynski <andrzej.warzynski@arm.com>
Reviewed By: rovka

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

2 years ago[NFC][flang] Add the test case for D125371
Peixin Qiao [Wed, 22 Jun 2022 15:53:38 +0000 (23:53 +0800)]
[NFC][flang] Add the test case for D125371

This adds the test case with portability warning preparing for D125804,
which supports checking for portability warnings in test_errors.py.

Reviewed By: ekieri

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

2 years ago[lldb] Tentative attempt to fix command-target-create-resolve-exe.test on buildbot
Martin Storsjö [Wed, 22 Jun 2022 15:48:04 +0000 (18:48 +0300)]
[lldb] Tentative attempt to fix command-target-create-resolve-exe.test on buildbot

This test does succeed in my local test environment though, but
fails on the buildbot.

2 years ago[OpenMP][libomp] Hold old __kmp_threads arrays until library shutdown
Jonathan Peyton [Thu, 5 May 2022 14:15:41 +0000 (09:15 -0500)]
[OpenMP][libomp] Hold old __kmp_threads arrays until library shutdown

When many nested teams are formed, __kmp_threads may be reallocated
to accommodate new threads. This reallocation causes a data
race when another existing team's thread simultaneously references
__kmp_threads. This patch keeps the old thread arrays around until library
shutdown so these lingering references can complete without issue and
access to __kmp_threads remains a simple array reference.

Fixes: https://github.com/llvm/llvm-project/issues/54708
Differential Revision: https://reviews.llvm.org/D125013

2 years ago[X86PreAMXConfig] Use IRBuilder to insert instructions (NFC)
Nikita Popov [Wed, 22 Jun 2022 15:25:35 +0000 (17:25 +0200)]
[X86PreAMXConfig] Use IRBuilder to insert instructions (NFC)

Use an IRBuilder to insert instructions in preWriteTileCfg().
While here, also remove some unnecessary bool return values.

There are some test changes because the IRBuilder folds
"trunc i16 8 to i8" to "i8 8", and that has knock-on effects on
instruction naming.

I ran into this when converting tests to opaque pointers and
noticed that this pass introduces unnecessary "bitcast ptr to ptr"
instructions.

2 years ago[libc++] Fixes GCC-12 build.
Mark de Wever [Wed, 22 Jun 2022 15:26:17 +0000 (17:26 +0200)]
[libc++] Fixes GCC-12 build.

2 years ago[X86] Regenerate test checks (NFC)
Nikita Popov [Wed, 22 Jun 2022 15:00:10 +0000 (17:00 +0200)]
[X86] Regenerate test checks (NFC)

This runs the test through -instnamer and generates test checks
using update_test_checks.py. (The previous comment indicated that
update_llc_test_checks.py was used, but I rather doubt that.)

This relies on the non-determinism fix from
fbb72530fe80a95678a7d643d7a3f5ee8d693c93,
the previous check lines have apparently been written to accomodate
that non-determinism.

2 years ago[X86PreAMXConfig] Use MapVector to fix non-determinism
Nikita Popov [Wed, 22 Jun 2022 14:56:43 +0000 (16:56 +0200)]
[X86PreAMXConfig] Use MapVector to fix non-determinism

We generate code by iterating over this map, so make sure that the
order is deterministic.

2 years agoRevert "[NFC] Remove dead code"
Guillaume Chatelet [Wed, 22 Jun 2022 14:55:47 +0000 (14:55 +0000)]
Revert "[NFC] Remove dead code"

This reverts commit 8ba2cbff70f2c49a8926451c59cc260d67b706cf.

2 years ago[X86] Name instructions in test (NFC)
Nikita Popov [Wed, 22 Jun 2022 14:43:21 +0000 (16:43 +0200)]
[X86] Name instructions in test (NFC)

Run the test through -instnamer, to make it easier to modify.

2 years ago[gn build] Port c3574ef739fb slightly better
Nico Weber [Wed, 22 Jun 2022 14:44:07 +0000 (10:44 -0400)]
[gn build] Port c3574ef739fb slightly better

The name of the host binary changed from make_confusable_table to
make-confusable-table, so match that.

2 years agoReland "[gn build] (manually) port b94db7ed7eaf (Confusables.inc)"
Nico Weber [Fri, 3 Jun 2022 11:49:28 +0000 (07:49 -0400)]
Reland "[gn build] (manually) port b94db7ed7eaf (Confusables.inc)"

b94db7ed7eaf relanded in c3574ef739fb.

This relands commit 180bae08a04d4dc, rebased across the new version of
commit c3574ef739fb, and rebased across 10f7255d32b690.

2 years ago[clang-tidy] Confusable identifiers detection
serge-sans-paille [Fri, 15 Oct 2021 13:20:22 +0000 (15:20 +0200)]
[clang-tidy] Confusable identifiers detection

Detect identifiers that are confusable using a variant of Unicode definition

        http://www.unicode.org/reports/tr39/#Confusable_Detection

and have conflicting scopes.

This a recommit (with portability and feature fixes) of b94db7ed7eaf4a3b21f600653a09c55cab77b79f

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

2 years ago[lldb] Add setting to override PE/COFF ABI by module name
Alvin Wong [Wed, 22 Jun 2022 13:16:04 +0000 (16:16 +0300)]
[lldb] Add setting to override PE/COFF ABI by module name

The setting `plugin.object-file.pe-coff.module-abi` is a string-to-enum
map that allows specifying an ABI to a module name. For example:

    ucrtbase.dll=msvc
    libstdc++-6.dll=gnu

This allows for debugging a process which mixes both modules built using
the MSVC ABI and modules built using the MinGW ABI.

Depends on D127048

Reviewed By: DavidSpickett

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

2 years ago[lldb][windows] Fix crash on getting nested exception
Alvin Wong [Wed, 22 Jun 2022 13:15:34 +0000 (16:15 +0300)]
[lldb][windows] Fix crash on getting nested exception

LLDB tries to follow `EXCEPTION_RECORD::ExceptionRecord` to follow the
nested exception chain. In practice this code just causes Access
Violation whenever there is a nested exception. Since there does not
appear to be any code in LLDB that is actually using the nested
exceptions, this change just removes the crashing code and adds a
comment for future reference.

Fixes https://github.com/mstorsjo/llvm-mingw/issues/292

Reviewed By: DavidSpickett

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

2 years ago[lldb] Resolve exe location for `target create`
Alvin Wong [Wed, 22 Jun 2022 13:13:57 +0000 (16:13 +0300)]
[lldb] Resolve exe location for `target create`

This fixes an issue that, when you start lldb or use `target create`
with a program name which is on $PATH, or not specify the .exe suffix of
a program in the working directory on Windows, you get a confusing
error, for example:

    (lldb) target create notepad
    error: 'C:\WINDOWS\SYSTEM32\notepad.exe' doesn't contain any 'host'
    platform architectures: i686, x86_64, i386, i386

Fixes https://github.com/mstorsjo/llvm-mingw/issues/265

Reviewed By: DavidSpickett

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

2 years ago[lldb] Fix reading i686-windows executables with GNU environment
Martin Storsjö [Tue, 21 Jun 2022 12:31:32 +0000 (15:31 +0300)]
[lldb] Fix reading i686-windows executables with GNU environment

25c8a061c5739677d2fc0af29a8cc9520207b923 / D127048 added an option
for setting the ABI to GNU.

When an object file is loaded, there's only minimal verification
done for the architecture spec set for it, if the object file only
provides one.

However, for i386 object files, the PECOFF object file plugin
provides two architectures, i386-pc-windows and i686-pc-windows.
This picks a totally different codepath in
TargetList::CreateTargetInternal, where it's treated as a fat
binary. This goes through more verifications to see if the
architectures provided by the object file matches what the
platform plugin supports.

The PlatformWindows() constructor explicitly adds the
"i386-pc-windows" and "i686-pc-windows" architectures (even when
running on other architectures), which allows this "fat binary
verification" to succeed for the i386 object files that provide
two architectures.

However, after that commit, if the object file is advertised with
the different environment (either when lldb is built in a mingw
environment, or if that setting is set), the fat binary validation
won't accept the file any longer.

Update ArchSpec::IsEqualTo with more logic for the Windows use
cases; mismatching vendors is not an issue (they don't have any
practical effect on Windows), and GNU and MSVC environments are
compatible to the point that PlatformWindows can handle object
files for both environments/ABIs.

As a separate path forward, one could also consider to stop returning
two architecture specs from ObjectFilePECOFF::GetModuleSpecifications
for i386 files.

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