Commit 4ba7f8d
committed
[cast-optimizer] Fix incorrect handling of returned pointers.
Put simply, the method Type::getAnyNominal() returns either a nominal type or a
nullptr. We are then casting it using dyn_cast to a ProtocolDecl. dyn_cast is
not allowed to handle nullptrs... hence the crash. The fix is to use the API
dyn_cast_or_null, the specific cast meant for this case!
In terms of how this effects the flow of the code in such a case, we will just
bail early if we have a non-nominal type today (which to me means at least
metatypes, which is this case).
I included a test case that we crash on without my change today and just do not
optimize.
rdar://87989767
(cherry picked from commit 52eb3b5)1 parent 7d9a1b6 commit 4ba7f8d
File tree
2 files changed
+23
-1
lines changed- lib/SILOptimizer/Utils
- test/SILOptimizer
2 files changed
+23
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1547 | 1547 | | |
1548 | 1548 | | |
1549 | 1549 | | |
1550 | | - | |
| 1550 | + | |
1551 | 1551 | | |
1552 | 1552 | | |
1553 | 1553 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
332 | 332 | | |
333 | 333 | | |
334 | 334 | | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
0 commit comments