Commit Graph

576 Commits

Author SHA1 Message Date
swift-ci
df75f6ee09 Merge remote-tracking branch 'origin/main' into rebranch 2023-01-25 22:33:52 -08:00
swift-ci
281088eb73 Merge pull request #63204 from meg-gupta/ptrauthcodegenpr
Initial support for ptrauth qualified function pointers in C
2023-01-25 22:19:34 -08:00
Meghana Gupta
901c279bea Add IRGen support for reads and writes to imported __ptrauth qualified field function pointers
Access to such pointers are protected by begin_access [signed]/end_access.
Generate code to auth/sign them before access.
2023-01-25 14:03:19 -08:00
swift-ci
5df3e6ca80 Merge remote-tracking branch 'origin/main' into rebranch 2023-01-11 01:56:51 -08:00
Konrad `ktoso` Malawski
54dec38a34 initial complete impl 2023-01-05 16:19:05 +09:00
swift-ci
328e716489 Merge remote-tracking branch 'origin/main' into rebranch 2022-12-12 07:33:19 -08:00
Nate Chandler
8d8577e5b0 [SIL] Removed Indirect_In_Constant convention.
It is no different from @in.

Continue parse @in_constant in textual and serialized SIL, but just as
an alias for @in.
2022-12-09 21:54:00 -08:00
swift-ci
6bb167f353 Merge remote-tracking branch 'origin/main' into rebranch 2022-11-14 23:34:22 -08:00
Erik Eckstein
190fea8acc IRGen: getPointerElementType -> getNonOpaquePointerElementType
`getPointerElementType` is deprecated in a newer LLVM.
2022-11-14 20:36:09 +01:00
Arnold Schwaighofer
d68dc2d06e IRGen: objc_direct method calls have a different convention
objc_direct methods no longer have the CMD argument.

rdar://102151993
2022-11-10 12:55:51 -08:00
Erik Eckstein
533fa45f79 IRgen: AllocAInst::getAlignment -> AllocaInst::getAlign 2022-11-04 20:44:19 +01:00
Arnold Schwaighofer
8e6e1588a3 IRGen: Fix the type of function pointers for signatures with opaque result types
The lower type of the definition might be an opaque type while a call to
the same function in the same resilience domain might look through to an
underlying type.

rdar://101780666
2022-11-01 15:44:57 -07:00
Arnold Schwaighofer
15015c078c Handle windows style async function pointers 2022-10-17 15:49:45 -07:00
Arnold Schwaighofer
2c09f54e09 Remove stray dump() calls 2022-10-17 14:41:37 -07:00
Arnold Schwaighofer
296c1e9fbd fix IRGenSILFunction::visitClassMethodInst 2022-10-05 09:23:53 -07:00
Arnold Schwaighofer
ab435a792f Fix FunctionPointer::getName when compiled with typed pointers 2022-10-05 09:22:08 -07:00
Arnold Schwaighofer
3115feae7e Track when we expect the signature to be used for the function type 2022-10-05 09:21:12 -07:00
Arnold Schwaighofer
fa70442b1e IRGen: Remove suspiciously looking (duplicate) logic
This should be computed by SignatureExpansion in a more correct way.
The code here seems suspiciously off in the case we have both a direct
return result and one indirect return result.
2022-10-03 15:27:17 -07:00
Arnold Schwaighofer
d810b0f7e4 IRGen: Pass the elementType of pointers through to operations
In preparation for moving to llvm's opaque pointer representation
replace getPointerElementType and CreateCall/CreateLoad/Store uses that
dependent on the address operand's pointer element type.

This means an `Address` carries the element type and we use
`FunctionPointer` in more places or read the function type off the
`llvm::Function`.
2022-10-03 15:27:12 -07:00
Alex Lorenz
e1989dd1f5 [interop][SwiftToCxx] verify that lowered function signature represented all LLVM IR params 2022-09-07 13:06:11 -07:00
Alex Lorenz
c351f3a550 [interop][SwiftToCxx] error result param should be handled by lowered function signature 2022-09-07 12:55:12 -07:00
Alex Lorenz
f4de75ae2c [interop][SwiftToCxx] 'self' param should be handled by type param visitor 2022-09-07 12:45:38 -07:00
Alex Lorenz
1696f94223 [interop][SwiftToCxx] reimplement function lowering to correctly distinguish between direct/indirect return values and parameters 2022-09-07 11:43:38 -07:00
Alex Lorenz
a5043c354d [interop][SwiftToCxx] add support for invoking methods in generic structs 2022-08-31 20:19:19 -07:00
Arnold Schwaighofer
f04a0c95ec IRGen: Only use clang type based task continuation function pointer
descriminator schema if descrimination is requested

rdar://99142574
2022-08-25 10:22:11 -07:00
Arnold Schwaighofer
a0ef942e19 IRGen: Use the clang type descriminator for TaskContinuationFunction*
rdar://98992498
2022-08-24 10:52:13 -07:00
swift-ci
37dacefe15 Merge remote-tracking branch 'origin/main' into rebranch 2022-07-29 00:33:45 -07:00
Alex Lorenz
32723f7e67 [interop][SwiftToCxx] initial generic function support: pass generic parameters
Only primitive types are supported at the moment from C++ as the type traits aren't emitted for all types yet
2022-07-28 22:52:21 +01:00
Ben Barham
b8aae6ecf1 [rebranch] Fix compile error caused by new AttrBuilder API
`AttrBuilder` now requires a `LLVMContext &` to be passed in, fix up the
use added in `main`.
2022-07-05 12:29:08 -07:00
swift-ci
5c8f1fcb12 Merge remote-tracking branch 'origin/main' into rebranch 2022-07-02 17:03:37 -07:00
Egor Zhdan
0e31acb18c [IRGen] Emit missing sret for function arguments
If the IR representation of a C++ function takes an `SRet` parameter instead of a return value, Swift needs to wrap the corresponding argument with `sret(...)` on call site.

This fixes SILOptimizer crashes on arm64.

rdar://92963081
2022-07-01 17:49:33 +01:00
swift-ci
6efe43cbce Merge remote-tracking branch 'origin/main' into rebranch 2022-06-27 10:13:55 -07:00
zoecarver
f86f9b7035 [cxx-interop] Record extra layer of indirection when calulating clang type from SILType. 2022-06-24 16:05:41 -07:00
zoecarver
dd7f49dd3b [cxx-interop] Use call, not function type for attributes.
Otherwise, attrs on the return (pass by val) will get applied to the call, which will trigger a verifier error.
2022-06-24 10:38:40 -07:00
swift-ci
26cf6542ba Merge remote-tracking branch 'origin/main' into rebranch 2022-05-28 07:14:52 -07:00
Max Desiatov
950792a260 IRGen: fix swifterror attribute mismatch for WebAssembly 2022-05-28 17:31:44 +09:00
Ben Barham
caa5003c7c [next] Pass LLVM context to AttrBuilder constructor
The `AttrBuilder` API was changed in llvm/llvm-project
d2cc6c2d0c2f8a6e272110416a3fd579ed5a3ac1 to now take a `LLVMContext &`
as part of its constructor. Update uses to pass one in.
2022-05-05 16:25:10 -07:00
Ben Barham
06a864cb31 [next] Rename BitInt to ExtInt
This was renamed in llvm/llvm-project
6c75ab5f66b403f7ca67e86aeed3a58abe10570b.
2022-05-05 16:25:10 -07:00
Ben Barham
04035b43b7 [next] Temporarily use getPointerElementType
`PointerType::getElementType` has been removed entirely as part of the
opaque pointers migration. Update to `getPointerElementType` for now
until we've also migrated.
2022-05-05 16:25:10 -07:00
Josh Soref
9fa14ca215 Spelling irgen (#42470)
* spelling: abstractable

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: across

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: clazz

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: command

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: components

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: current

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: declared

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: discrimination

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: entities

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: except

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: existential

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: generic

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: initialization

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: initialize

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: inserted

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: instantiate

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: instantiation

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: interfere

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: interferes

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: intrinsic

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: metadata

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: might

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: multiple

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: necessary

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: objective

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: occurrences

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: outlined

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: parameters

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: payload

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: rearchitecting

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: replaceable

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: reverse

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: rewritable

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: shareably

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: specializations

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: speedup

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: template

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: that

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: the

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: transferred

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: uninitialized

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

* spelling: witness

Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>

Co-authored-by: Josh Soref <jsoref@users.noreply.github.com>
2022-04-21 14:02:03 -07:00
Nate Chandler
d70d3919a6 [IRGen] Mark inout ptrs noalias.
Thanks to exclusivity checking, inout arguments can be marked noalias.
In the fullness of time, this should be applied in general.

As an incremental step towards marking all such arguments noalias, start
by marking inout arguments of pointer type noalias.  Take this
conservative step rather than always applying the attribute to ward
against issues with LLVM's alias analysis.

rdar://76540030
2022-04-20 16:58:08 -07:00
Joe Groff
15c21920a1 Merge pull request #42101 from jckarter/async-let-reabstraction
SILGen: Emit async let entry points at correct abstraction level.
2022-03-31 10:07:01 -07:00
Joe Groff
d451203b7f SILGen: Emit async let entry points at correct abstraction level.
Avoid a reabstraction thunk every time an async let entry point is emitted,
by setting the context abstraction level while we emit the implicit closure.
Adjust some surrounding logic that breaks when we do this:

- When lowering a non-throwing function type against a throwing abstraction
  pattern, include the error type in the lowered substituted type. Async
  throwing and nonthrowing functions would require another thunk to convert
  away the throwingness of the async context, which would defeat the purpose.
- Adjust the code in IRGen that pads the initial context size for `async let`
  entry points so that it works when the entry point has not yet emitted, by
  marking the async function pointer to be padded later if it isn't defined
  yet.
2022-03-30 14:51:46 -07:00
Yuta Saito
43a25e89b7 [Wasm][IRGen] Add initial support for absolute function pointer
On some Harvard architectures like WebAssembly that allow sliding code
and data address space offsets independently, it's impossible to make
direct relative reference to code from data because the relative offset
between them is not representable.
Use absolute function references instead of relative ones on such targets.
2022-03-30 08:12:23 +00:00
Joe Groff
6f68eae7ba IRGen: Artificially pad async let entry point contexts.
We fixed a bug in the concurrency runtime (rdar://problem/90357994) that would
lead to memory corruption when a new `async let` child task tried to use the
last 16 bytes of the preallocated slab from its parent to seed its own task
allocator. To work around this bug in older OSes that shipped with the bug,
artificially pad the async coroutine context size for any async functions
used as an `async let` entry point, which will prevent the runtime from
going down the path of trying to use the preallocated storage at all.
rdar://90506708
2022-03-25 16:06:00 -07:00
Ehud Adler
0056129d57 [cxx-interop] std::string::push_back is broken (#41240)
* [cxx-interop] fix  std::string::push_back by fixing mapping between clang/swift self/this type for cxx methods

* cleanup

* Fix unit test

* XFail test: operators/member-inline on linux-android

* add `C++` in expandExternalSignatureTypes comment

* Fix rebase

* Fix mapping issue in externalizeArguments

* Improve cxx_interop_ir test regex
2022-03-08 13:09:38 -05:00
Ben Langmuir
779bdf0bf3 Merge pull request #41550 from benlangmuir/make-next-less-sad
Pre-fix some build failures that we'll see with newer llvm
2022-03-02 09:23:07 -08:00
John McCall
aca744b211 Remove the Flags field from AsyncContext.
Generated code has never actually initialized this field, so we
might as well remove it.  Doing so mostly doesn't impact the ABI
since we don't store anything for arguments or results in the
context as part of the normal call sequence.  We do need to adjust
some of the hard-coded contexts, however, such as continuation
contexts and the statically-sized context for special runtime
async functions.
2022-02-25 16:57:49 -05:00
Ben Langmuir
35478637d3 Migrate from SmallVector.set_size to resize_for_overwrite
In the "next" branch, set_size has been made protected. Instead, users
can use resize_for_overwrite, optionally followed by truncate, to
handle the same use cases more safely.
2022-02-24 13:54:22 -08:00
John McCall
58fe89f359 [NFC] Split up the "special convention" for runtime async functions
The special convention currently means three things:

1. There is no async FP symbol for the function.  Calls should go directly
to the function symbol, and an async context of fixed static size should be
allocated.  This is mandatory for calling runtime-provided async functions.

2. The callee context should be allocated but not initialized.  The main
context pointer passed should be the caller's context, and the continuation
function pointer and callee context should be passed as separate arguments.
The function will resume the continuation function pointer with the caller's
context.  This is a micro-optimization appropriate for functions that are
expected to frequently return immediately; other functions shouldn't bother.

3. Generic arguments should be suppressed.  This is a microoptimization for
certain specific runtime functions where we happen to know that the runtime
already stores the appropriate information internally.  Other functions
probably don't want this.

Obviously, these different treatments should be split into different
predicates so that functions can opt in to different subsets of them.

I've also set the code up so that runtime functions can more easily
request a specific static async context size.  Previously, it was a
confusingly embedded assumption that the static context size was always
exactly two pointers more than the header.
2022-02-15 04:12:05 -05:00