Commit Graph

155 Commits

Author SHA1 Message Date
Allan Shortlidge
030a3da88c AST: Fix AvailabilityContext::forDeclSignature().
It had a bug that would cause it to return incorrect results for some decls
with invalid source locations. Since not all declarations introduce a new
`DeclContext`, it's not sufficient to walk the decl context hiearchy when
computing availability for a decl.
2025-07-21 17:00:35 -07:00
Eric Miotto
00334acf37 Disable tests that require arm64e slices for iOS sanitizers
We started building iOS sanitizers when switching to
`LLVM_ENABLE_RUNTIMES` to build compiler-rt, and turns out they
currently provide only the arm64 slice.

Addresses rdar://151782340
2025-05-22 14:40:07 -07:00
Kavon Farvardin
b1db0126c7 Workaround lack of new swift-driver on Windows. 2024-12-13 14:44:39 -08:00
Kavon Farvardin
5cbe247404 Update test to cover use of flags from new driver 2024-12-12 17:42:42 -08:00
Erik Eckstein
7cceaff5f3 SIL: don't print operand types in textual SIL
Type annotations for instruction operands are omitted, e.g.

```
  %3 = struct $S(%1, %2)
```

Operand types are redundant anyway and were only used for sanity checking in the SIL parser.

But: operand types _are_ printed if the definition of the operand value was not printed yet.
This happens:

* if the block with the definition appears after the block where the operand's instruction is located

* if a block or instruction is printed in isolation, e.g. in a debugger

The old behavior can be restored with `-Xllvm -sil-print-types`.
This option is added to many existing test files which check for operand types in their check-lines.
2024-11-21 18:49:52 +01:00
Allan Shortlidge
a4057551ad SILGen: Avoid attempting to profile any ClangImporter synthesized function.
ClangImporter synthesized declarations inherently do not have user written
code. Unfortunately, despite that they are not always marked implicit as they
should be. This was causing a crash when attempting to generate profile
coverage maps for synthesized constructors for imported structs.

I tried marking the constructors implicit, but that had too many knock-on
effects in tests. This more targeted fix unblocks compatibility suite testing
without trying to grapple with the implications of that more fundamental fix.

Resolves rdar://139486938.
2024-11-11 16:28:02 -08:00
Kavon Farvardin
2b01714fba PGO: new -profile-sample-use= frontend flag
This is meant to match clang's `-fprofile-sample-use=` and accepts a
file with the same format.

rdar://135443278
2024-11-01 11:59:54 -07:00
Kuba Mracek
8620a99b18 [embedded] Add QEMU-based testing configs for ARM and AVR for runtime testing 2024-10-25 14:52:49 -07:00
Hamish Knight
3325296401 [test] Enable some profiler tests on non-macOS 2024-08-04 10:45:29 +01:00
Hamish Knight
7e15c95a28 [test] Update a couple of Profiler tests for rebranch
On rebranch, in optimized IR, we can print the constant range
of expected return values, ignore it in the match.
2024-07-22 20:23:05 +01:00
Hamish Knight
251182cf52 [test] Generalize runtime library searching
Allow detecting the compiler runtime libraries for
non-Darwin platforms, allowing us to test that
programs relying on these libraries link successfully.
2024-07-15 15:22:46 +01:00
Hamish Knight
df4d28fd43 [Driver] Pass -lld-allow-duplicate-weak for coverage on Windows
And add an integration test for both the legacy
and new driver.

rdar://129337999
2024-07-12 16:01:05 +01:00
Hamish Knight
6c930f7aaa [Coverage] Also walk MacroExpansionDecls
Make sure we walk macro expansion decls to handle
cases where e.g a binding introduces control flow.
This should be a pretty uncommon case since bindings
introduced by macros aren't actually usable when
expanded in local contexts, but handle it all the
same.
2024-06-03 12:14:56 +01:00
Hamish Knight
95cbced7a0 [Coverage] Avoid profiling functions with body macros
These replace the body of the function, and as such
shouldn't be profiled.
2024-06-03 12:14:56 +01:00
Hamish Knight
98f0200f64 [Coverage] Avoid recording regions from macro expansions
Ignore any regions recorded while inside a macro
expansion, but account for any control flow that
may have happened such that the exit count is
correctly adjusted. This allows e.g throwing function
calls to behave correctly within the expansion.

rdar://129081384
2024-06-03 12:14:56 +01:00
Hamish Knight
c3b055a9a8 [Profiler] Improve if statement coverage
Fix counters for regions following `else if`s, fix
the counters for `else if` conditions, and fix
handling of `break` statements. Also while here,
clean up the handling of branch exit regions such
that we don't generate multiple overlapping
regions for each branch, but a single region at
the end of the entire `if` statement that accounts
for all exiting control flow.

rdar://104078910
rdar://104079242
2023-12-04 11:09:01 +00:00
Hamish Knight
556c503685 Merge pull request #70119 from hamishknight/add-test
[test] Add an additional coverage test
2023-11-30 18:22:15 +00:00
Hamish Knight
25e6e96016 [Profiler] Avoid crashing on redundant break in repeat-while
Treat subtracting zero as a no-op, avoiding the
assertion guarding against creating negative
counters.
2023-11-30 13:23:26 +00:00
Hamish Knight
b66665f6d8 [test] Add an additional coverage test 2023-11-30 12:37:08 +00:00
Hamish Knight
322ce4e3f4 [Profiler] Fix handling of property wrapper backing inits
Previously we were walking into the
PropertyWrapperValuePlaceholderExpr when generating
coverage for a property wrapper backing initializer.
This meant that we were duplicating the coverage of
the initializer expression, and it could cause
crashes if a refined counter was introduced within
the top-most expression region, such as with a
throwing expression in a `try!`.

rdar://118939162
2023-11-29 22:58:29 +00:00
Hamish Knight
b430a025ea Merge pull request #69986 from hamishknight/try-try-again 2023-11-27 20:18:53 +00:00
Hamish Knight
ff1c42aabd [Profiler] Fix throwing expressions in if conditions
Previously we would ignore the effect that an if
statement or ternary's condition exit counter might
have on its branches, as we assumed a condition
can't do any control flow. However, in the case
where the condition throws an error, we need to
account for the error branch.
2023-11-21 15:02:56 +00:00
Hamish Knight
59275b20b1 [Profiler] Correctly handle try? expressions
Ensure that `try?` expressions appropriately
scope the regions generated by child
error-throwing expressions, such that the
non-error branch does not extend beyond the region
of the `try?`.
2023-11-21 15:02:56 +00:00
Hamish Knight
e8d3d1aef3 [Profiler] Fix ternary error handling coverage
Previously the branches of a ternary would cut off
the coverage after a throwing expression, since
they have their own region, and we pop child
regions when leaving. Update the logic to use the
existing counter adjustment logic when we leave
the scope, ensuring that we push a new counter to
reflect the exit count of the scope.
2023-11-21 15:02:56 +00:00
Hamish Knight
0f1f950039 [test] Add test case for rdar://118185163 2023-11-17 01:16:20 +00:00
Hamish Knight
ff145a261b [test] Couple of coverage test tweaks 2023-11-17 01:16:20 +00:00
Hamish Knight
d9f3047871 [Profiler] Fix DoCatchStmt coverage handling
The logic here previously worked by computing the
exit count by taking the parent count and
subtracting any control flow that jumped out of the
clauses. With `try` handling fixed, this no longer
works correctly, since a `try` shouldn't be
subtracted if the error is caught be one of the
catches, as that's not actually leaving the
statement. We could write the logic to determine
where a `try` is jumping to, but the logic here is
already pretty brittle, relying on being sprinkled
in various different places.

For now, let's take the more straightforward
approach and handle do-catches the same way we
handle switches, we initialize the exit counter to
0, and add on each exit count of each branch. This
lets us re-use the existing CaseStmt handling
logic. This doesn't necessarily produce the most
optimal counter expressions, but I want to replace
this all with a SILOptimizer pass anyway, which
will be able to much more easily compute optimal
counter expressions.

rdar://100470244
2023-11-16 17:28:57 +00:00
Hamish Knight
49ad980b86 [Profiler] Map regions for error-throwing AST nodes
Map a counter for the error branch of a given
potentially-throwing expression, and subtract it
from the following region count.

rdar://34244637
2023-11-16 17:28:57 +00:00
Hamish Knight
4e48db550b [Profiler] Improve region termination
We can terminate all the regions up to the last
AST node in the stack, since regions without AST
nodes are refinements of the region with the AST
node, and should be terminated the same. This
avoids leaving some regions that extend past e.g
the `return` of a function.

The region in the test case that changes here is:

```
[[@LINE+9]]:28 -> [[@LINE+12]]:4 : (0 - 1)
```

this was extending past the return. Now it is:

```
[[@LINE]]:6    -> [[@LINE+4]]:11 : (0 - 1)
```

Apologies, I also refactored the test case at the
same time which makes the difference harder to see,
but the main point is that this region now terminates
at the return, the same as the others.
2023-11-16 17:28:57 +00:00
Hamish Knight
bb48233695 [Profiler] Avoid recording empty regions
These are redundant.
2023-11-16 17:28:57 +00:00
Hamish Knight
509a78102b [test] Rename a test file
And rename the functions in it
2023-11-16 17:28:57 +00:00
Hamish Knight
5aab237468 [Profiler] Emit skipped regions for inactive #if branches
For any `#if` blocks in the function we're emitting,
emit skipped ranges for the inactive clauses, including
the syntax for the `#if` itself, since that should
not be considered executable code.

rdar://116860865
2023-11-14 20:41:35 +00:00
Doug Gregor
07d887111d Generalize test 2023-11-09 14:31:57 -08:00
Doug Gregor
4f773c2250 [SILGen] Ensure that we have a scope for error conversions in reabstraction thunks 2023-11-09 11:13:38 -08:00
Doug Gregor
d031296c50 Update test 2023-11-08 13:17:38 -08:00
Augusto Noronha
1c4b67afd1 Adapt tests to changes to keep functions for debugger on Onone
Now that we keep many more functions on unoptimized builds, many tests
need to be changed to either:
- Account for function that wasn't being emitted before to being emitted
  now.
- Account for functions that previously were being emitted lazily to
  being emitted eagerly now.
2023-10-06 11:08:10 -07:00
Mustafa Uzun
49fe1b870b fix: init_accessor_initializes_attribute_on_other_declaration error message typo 2023-08-18 14:36:57 +03:00
Nate Chandler
e5d87f75a8 [SIL] Add source formal type to checked_cast_br.
It is necessary for opaque values where for casts that will newly start
out as checked_cast_brs and be lowered to checked_cast_addr_brs, since
the latter has the source formal type, IRGen relies on being able to
access it, and there's no way in general to obtain the source formal
type from the source lowered type.
2023-07-27 15:04:15 -07:00
Doug Gregor
bf097b5bd7 [Macros] Update test case to properly use named(init). 2023-07-18 07:35:39 -07:00
Hamish Knight
9dc2d04352 [test] A couple of minor changes 2023-05-22 17:54:18 +01:00
Hamish Knight
b55f97250d [IRGen] Update coverage mapping for version 6
The coverage format version we use is automatically
set to whatever the latest version LLVM has. This
resulting in us outputting version 6 as our
format without having made the changes necessary
to reflect the new format. Update the emission
logic to take account for [the new changes in
version 6][1] (we need to include the current
working directory as the first element of the list
of files we output). Additionally, add a
`static_assert` so we don't get caught out by
version bumps in the future. Note we can't pin our
version, as it must stay in sync with the version
Clang is using.

[1]: https://llvm.org/docs/CoverageMappingFormat.html#llvm-ir-representation
2023-05-20 00:32:21 +01:00
Hamish Knight
a3848c62d5 [Profiler] Don't profile generated buffers
We may want to revisit this in the future, but for
now let's avoid profiling code in generated
buffers. To make this work we'll need to come up
with a scheme for writing out the generated buffers
such that tools like `llvm-cov` can reference them.

rdar://109562235
2023-05-20 00:32:20 +01:00
Meghana Gupta
e5eeb261d1 Fix SILInliner to create move_value in OSSA only 2023-02-26 08:47:15 -08:00
Hamish Knight
a40f1abaff Introduce if/switch expressions
Introduce SingleValueStmtExpr, which allows the
embedding of a statement in an expression context.
This then allows us to parse and type-check `if`
and `switch` statements as expressions, gated
behind the `IfSwitchExpression` experimental
feature for now. In the future,
SingleValueStmtExpr could also be used for e.g
`do` expressions.

For now, only single expression branches are
supported for producing a value from an
`if`/`switch` expression, and each branch is
type-checked independently. A multi-statement
branch may only appear if it ends with a `throw`,
and it may not `break`, `continue`, or `return`.

The placement of `if`/`switch` expressions is also
currently limited by a syntactic use diagnostic.
Currently they're only allowed in bindings,
assignments, throws, and returns. But this could
be lifted in the future if desired.
2023-02-01 15:30:18 +00:00
Hamish Knight
6d3545f4d5 [IRGen] Don't emit multiple copies of coverage maps
Iterating over the IRGenModules and emitting every
SILCoverageMap in the SILModule meant that we
were emitting N copies of the coverage maps for
parallel IRGen, where N is the number of output
object files.

This has always been wrong, but was previously
saved by the fact that we would drop the coverage
map on the floor if we didn't have the name data
available. This would only be the case for the
IRGenModule that had the emitted entity to
profile, in addition to any IRGenModules that
had inlined the body of a profiled enitity. As
such, this prevented the duplication from being
too egregious. However with the recent change to
emit unused name data in the case where we don't
already have name data available, we're now fully
duplicating every coverage mapping, and emitting a
ton of redundant name data.

Fix things such that we only emit coverage mapping
records for the IRGenModule that corresponds to
the entity being profiled.

rdar://102905496
2022-12-06 14:28:35 +00:00
Hamish Knight
663c0b2f82 [Profiler] Fix over-eager assert
We may have a skipped function body when walking
over a SourceFile to profile top-level code,
adjust the assertion so we ignore cases that we
don't want to profile anyway.

rdar://102405053
2022-11-16 16:05:08 +00:00
Hamish Knight
350e28b4b7 [Profiler] Rework profiling of top-level code
Instead of creating and destroying a SILProfiler
per TopLevelCodeDecl, setup a single profiler
for the top-level entry point function, and visit
all the TopLevelCodeDecls when mapping regions.
2022-10-14 17:45:14 +01:00
Hamish Knight
d0ffd29860 [test] Fix test name 2022-10-14 17:45:11 +01:00
Hamish Knight
5a8c14d583 [Profiler] Fix up a couple uses of emitProfilerIncrement
Remove a case where we know we don't have a
profiler, and avoid incrementing for a distributed
factory method. Otherwise such cases could pass
a null ASTNode, which will become an assertion
failure in a future commit.

While we're here, let's standardize on emitting
the profiler increment for function entry after
the prolog, as if there's e.g an unreachable
parameter, the increment can be safely elided
anyway.
2022-10-13 19:42:36 +01:00
Hamish Knight
bd18c37b82 [Profiler] Adopt SILDeclRef::hasUserWrittenCode
This replaces some of the existing checks, and
ensures that we don't emit coverage maps for
property wrapper backing initializers that don't
contain user code.

rdar://99931619
2022-09-29 10:08:15 +01:00