Commit Graph

12796 Commits

Author SHA1 Message Date
Augusto Noronha
ef5aae1fea Merge pull request #72445 from augusto2112/zero-unsub-types-main
[DebugInfo] Always emit unsubsituted generic types with size 0
2024-05-03 13:13:59 -07:00
swift-ci
d9561451b4 Merge remote-tracking branch 'origin/main' into rebranch 2024-05-02 22:54:11 -07:00
Dario Rexin
c1d732a9cb [IRGen] Fix alignment for imported C types in CVW
rdar://127279770

When an imported C type is over or under aligned, we did not use the alignment of the type, but computed the maximum alignment of its components, causing alignment issues in compact value witnesses.
2024-05-02 17:05:38 -07:00
swift-ci
e2ba5ea903 Merge remote-tracking branch 'origin/main' into rebranch 2024-05-02 12:54:35 -07:00
Emil Pedersen
bf58b030c5 Merge pull request #73387 from Snowy1803/allocbox-fix
[DebugInfo] Fix loss of variables at -Onone
2024-05-02 12:39:17 -07:00
Emil Pedersen
c02f663f93 [DebugInfo] Fix AllocStackHoisting losing debug info
AllocStackHoisting was losing debug info, including at -Onone.
When two alloc_stacks of the same type are merged, one of them
would lose their debug variable. It is now salvaged, with an added
debug_value.

This case was previously only handled for noncopyable types, it is
now done in all cases.
2024-05-01 18:44:57 -07:00
Emil Pedersen
644509ea1c [DebugInfo] Fix LoadableByAddress losing debug info
LoadableByAddress was losing debug info, including at -Onone.
When converting a load-store pair to a copy_addr, the debug info
attached to the load was not salvaged.
Additionally, the wrong scope was being attached to other debug
values.
2024-05-01 18:44:33 -07:00
Becca Royal-Gordon
c3225b066e [NFC] Merge two category name accessors 2024-05-01 12:18:19 -07:00
swift-ci
7af405827e Merge remote-tracking branch 'origin/main' into rebranch 2024-05-01 08:16:56 -07:00
Alejandro Alonso
d380bf9ae3 Merge pull request #73277 from Azoy/fix-conditional-invertible
[IRGen] Fix misalignment of conditional invertible requirement counts
2024-05-01 08:10:46 -07:00
swift-ci
0d3ed3d63c Merge remote-tracking branch 'origin/main' into rebranch 2024-05-01 06:53:59 -07:00
Cyndy Ishida
84d36181a7 [TBDGen] Track unavailable declarations against the active platform for (#73284)
api generation

This resolves the bug where apijson files recorded declarations as
unavailable purely because it was unavailable on a unrelated platforms.

Resolves: rdar://113552185
2024-05-01 06:50:30 -07:00
swift-ci
480a3378d9 Merge remote-tracking branch 'origin/main' into rebranch 2024-04-30 20:54:40 -07:00
Becca Royal-Gordon
981233ad37 Merge pull request #73128 from beccadax/objcimpl-resilient
Handle resilient stored properties in objcImpl
2024-04-30 20:50:33 -07:00
Becca Royal-Gordon
f94ed6d606 Hide objcImpl resilience support behind feature
Resilence support will require changes to the Objective-C runtime to expand support for metadata initialization functions. Add a separate experimental feature flag to help with staging that support in, and modify diagnostics to not suggest increasing the minimum deployment target for now.
2024-04-30 12:03:46 -07:00
Becca Royal-Gordon
1dceb24802 Diagnose resilient properties in objcImpl
…when the deployment target is not high enough to support them.
2024-04-30 12:03:46 -07:00
Becca Royal-Gordon
d1f14e5814 Eliminate objcImpl field offset vectors
We really don’t need ‘em; we can just adjust the direct field offsets.

The runtime entry point currently uses a weird little hack that we will refactor away shortly.
2024-04-30 12:03:46 -07:00
Becca Royal-Gordon
427386feea Support resilient stored properties in objcImpl
When an @objc @implementation class requires the use of `ClassMetadataStrategy::Update` because some of its stored properties do not have fixed sizes, we adjust the direct field offsets during class realization by emitting a custom metadata update function which calls a new entry point in the Swift runtime. That entry point adjusts field offsets like `swift_updateClassMetadata2()`, but it only assumes that the class has Objective-C metadata, not Swift metadata.

This commit introduces an alternative mechanism which does the same thing without using any Swift-only metadata. It’s a rough implementation with important limitations:

• We’re currently using the field offset vector, which means that field offsets are being emitted into @objc @implementation classes; these will be removed.
• The new Swift runtime entry point duplicates a lot of `swift_updateClassMetadata2()`’s implementation; it will be refactored into something much smaller and more compact.
• Availability bounds for this feature have not yet been implemented.

Future commits in this PR will correct these issues.
2024-04-30 12:03:44 -07:00
swift-ci
a51df69c93 Merge remote-tracking branch 'origin/main' into rebranch 2024-04-29 10:34:28 -07:00
Emil Pedersen
ce68d74025 Merge pull request #73276 from Snowy1803/doc-and-fixes
[DebugInfo] Improve documentation & Fix discovered bugs
2024-04-29 10:22:46 -07:00
Alastair Houghton
a363719434 [IRGen] Set TargetOpts.UseInitArray in getIRTargetOptions().
IRGen sets up the `llvm::TargetOptions` by itself, rather than copying
them from the Clang instance (it has to do this, at present, because
Clang doesn't provide a way to get it to initialise one).

Unfortunately, it didn't set `UseInitArray`, which when linking with
GNU `ld` or `gold` is *fine* because those linkers automatically
convert `.ctors` and `.dtors` sections into `.init_array` and
`.fini_array` respectively.  *However*, `lld` does *not* do this
conversion, so when using `lld`, if the compiler generates a
constructor or destructor function, it won't be called(!)

The fix is to set `UseInitArray` properly; I chose to copy the setting
from Clang, just in case Clang knows of a reason why it shouldn't be
`true`.

rdar://123504095
2024-04-29 10:48:22 +01:00
Alastair Houghton
0a5653dbaf [IRGen] When creating a module object, mark __Swift_AST as used.
Without doing this, `__Swift_AST` gets stripped from the output.
We also need to call `IGM.finalize()` before `::performLLVM()` in the
`createSwiftModuleObjectFile()` function, so that we update the
section to mark it as retained.

rdar://123504095
2024-04-29 10:48:22 +01:00
Alastair Houghton
3c029ebd3f [IRGen] Use llvm.used on ELF instead of llvm.compiler.used.
We changed to `llvm.compiler.used` because of the behaviour of `gold`,
which refuses to coalesce sections that have different `SHF_GNU_RETAIN`
flags, which causes problems with metadata.

Originally I thought we were going to have to generate two sections
with distinct names and have the runtime look for both of them, but
it turns out that the runtime only wants to see sections that have
`SHF_GNU_RETAIN` in any case.  It's really the reflection code that
is interested in being able to see non-retained sections.  The upshot
is that we don't need to use `llvm.compiler.used`; it's just fine if
we have duplicate sections, as long as the reflection code looks for
them when it's inspecting an ELF image.

This also means we no longer need to pass `-z nostart-stop-gc` to the
linker if we're using `lld`.

rdar://123504095
2024-04-29 10:48:22 +01:00
Emil Pedersen
84dae7c37a [DebugInfo] Add support for constant debug values 2024-04-26 16:31:16 -07:00
Emil Pedersen
8ad3066011 [DebugInfo] Fix implicit deref on arithmetic expressions 2024-04-26 16:31:16 -07:00
Emil Pedersen
c2c16f53dd [DebugInfo] Fix undef debug values being removed 2024-04-26 16:31:16 -07:00
swift-ci
3c8a651a0d Merge remote-tracking branch 'origin/main' into rebranch 2024-04-26 04:54:47 -07:00
Arnold Schwaighofer
1846159657 Merge pull request #73270 from aschwaighofer/large_types_reg2mem_yield_begin_apply
LargeTypesReg2Mem: Fix yield and begin_apply instructions
2024-04-26 04:35:38 -07:00
Arnold Schwaighofer
f544aac75b Merge pull request #73269 from aschwaighofer/irgen_fix_large_c_argument_peephole
IRGen: Fix the load to indirect argument peephole
2024-04-26 04:34:55 -07:00
swift-ci
cf41bf0df7 Merge remote-tracking branch 'origin/main' into rebranch 2024-04-25 20:14:13 -07:00
Dario Rexin
09cd036d15 [IRGen] Fix size computation for imported C types in type layouts (#73271)
rdar://126954341

C types don't have separate size and stride, but in type layouts we always computed the size as if they did. This could cause wrong offsets in compact value witnesses
2024-04-25 19:58:14 -07:00
Alejandro Alonso
0e673f70a4 Fix misalignment of conditional invertible requirement counts 2024-04-25 17:58:13 -07:00
swift-ci
3ea8b187bb Merge remote-tracking branch 'origin/main' into rebranch 2024-04-25 16:54:34 -07:00
Emil Pedersen
a31d15c438 Merge pull request #72964 from Snowy1803/mem2reg-salvage-store
[DebugInfo] Salvage all stores
2024-04-25 16:52:37 -07:00
Arnold Schwaighofer
ff4682941a LargeTypesReg2Mem: Fix yield and begin_apply instructions
Speculative fix for #swift/issues/72911
2024-04-25 16:51:33 -07:00
swift-ci
4acc79a89a Merge remote-tracking branch 'origin/main' into rebranch 2024-04-25 16:34:45 -07:00
Joe Groff
2f954ef5d7 Merge pull request #73259 from jckarter/external-key-path-generic-environment-binding
IRGen: Fix key path generic environment marshalling for external property descriptors.
2024-04-25 16:24:42 -07:00
Arnold Schwaighofer
6794012ea1 IRGen: Fix the load to indirect argument peephole
When the source of the load is a projection we have to bail because the
code later can't handle it.
2024-04-25 15:41:51 -07:00
Ben Barham
445ee1ec14 Manually merge rebranch into main
Conflicts:
  - `lib/ClangImporter/ImportDecl.cpp` as `isPure` is now
    `isPureVirtual`
2024-04-25 13:48:57 -07:00
Joe Groff
02e1f2ea15 IRGen: Fix key path generic environment marshalling for external property descriptors.
The layout of a computed key path component carries an argument buffer for captures, which has
the following layout:

```
---
captured values (subscript indices)
---
generic arguments
---
```

When we reference an externally-defined public property or subscript from a key path, and the
external declaration has a property descriptor, then the generic arguments for the external
declaration get appended to the end of this buffer, giving:

```
---
captured values (subscript indices)
---
generic arguments
---
external property's generic arguments
---
```

The convention for key path accessors to bind their generic environment is thus to unpack them
from the end of the argument buffer, so that the external keypath's accessors can find the
arguments to bind the external generic environment while still allowing the enclosing key path
to save the original captured generic environment (which may be necessary to capture the
appropriate conditional and/or retroactive `Equatable` and `Hashable` conformances for
subscript indices).

However, our code generation for binding the generic arguments out of the argument buffer
contained a flawed optimization: for a property, we know there are never any captured values,
so I had assumed that the generic parameters could always be bound from the beginning of the
argument buffer, assuming that the generic parameters make up the totality of the buffer. This
falls over for external property descriptor references when the key path itself captures a
generic environment, since the external property's expected generic environment appears after
the key path's original generic environment. We can fix this by removing the conditional
entirely, and always adjusting the offset we load the generic environment from to look at the
end of the buffer. Fixes rdar://125886333.
2024-04-25 10:36:13 -07:00
Emil Pedersen
584d1db307 [IRGen] [DebugInfo] Ignore autogenerated flag for variables 2024-04-24 18:25:43 -07:00
nate-chandler
c1ecef79dc Merge pull request #73191 from nate-chandler/rdar125265980
[IRGen] Deadends don't need dealloc_pack_metadata.
2024-04-24 16:17:08 -07:00
Becca Royal-Gordon
9e83099279 [NFC] Refactor objcImpl matadata layout logic
Rather than having individual methods return without doing anything, arrange for ClassMetadataVisitor to never call them in the first place. This makes it so ClassMetadataScanner also knows which fields are omitted and it can compute offsets correctly.

The old logic is still present for field offsets to make this change NFC.
2024-04-24 11:39:24 -07:00
Nate Chandler
da38fb51fb [IRGen] Deadends don't need dealloc_pack_metadata.
There is a debug-build-only verification that is done for
alloc_pack_metadata instructions that checks that there exist paired
dealloc_pack_metadata instructions which will be keyed off of to clean
up the on-stack variadic metadata packs corresponding to (the
instruction after) the alloc_pack_metadata.

StackNesting omits the deallocation instruction (as does
PackMetadataMarkerInserter) if it would be created in a dead end block.
If all blocks in the dominance frontier of the alloc_pack_metadata
instruction are dead-end blocks, then the verification will incorrectly
fail.  It should not fail because it is not necessary to clean up the
on-stack pack metadata (or any other stack allocations) in such a case.

If all such blocks are dead-end blocks, however, the
alloc_pack_metadata's block itself is a dead-end block as well.  So
during the verification, check whether the alloc_pack_metadata occurs in
a dead-end block and do not fail verification if it does.

rdar://125265980
2024-04-24 07:24:20 -07:00
swift-ci
e79876e812 Merge remote-tracking branch 'origin/main' into rebranch 2024-04-19 18:01:11 -07:00
Kuba Mracek
89849b786e [embedded] Fix array processing stride/size bug in init/assign, too 2024-04-19 10:34:58 -07:00
Kuba Mracek
7d5acd3ac9 [embedded] Fix miscompile in IRGen in offset computation of Builtin.destroyArray 2024-04-18 21:19:03 -07:00
Nate Chandler
c43f87101f Merge branch 'main' into rebranch
Conflicts:
      lib/Basic/Platform.cpp

```
diff --git a/lib/Basic/Platform.cpp b/lib/Basic/Platform.cpp
index 240edfa144a..1797c87635f 100644
--- a/lib/Basic/Platform.cpp
+++ b/lib/Basic/Platform.cpp
@@ -200,10 +200,7 @@ StringRef swift::getPlatformNameForTriple(const llvm::Triple &triple) {
   case llvm::Triple::CUDA:
   case llvm::Triple::DragonFly:
   case llvm::Triple::DriverKit:
-<<<<<<< HEAD
   case llvm::Triple::ELFIAMCU:
-=======
->>>>>>> main
   case llvm::Triple::Emscripten:
   case llvm::Triple::Fuchsia:
   case llvm::Triple::HermitCore:
```
2024-04-17 13:32:48 -07:00
Augusto Noronha
bc4eeb861c Merge pull request #72963 from augusto2112/declaration-by-rep
[DebugInfo] Emit declaration by checking both type and SIL func repr
2024-04-17 10:19:20 -07:00
Egor Zhdan
cfe27287da Merge pull request #72903 from apple/egorzhdan/zero-init
[cxx-interop] Zero-initialize C++ structs when calling their default constructors
2024-04-17 13:39:21 +01:00