Skip to content

[SR-14814] Incorrect parsing on 'forwarding' directive in SIL #57162

@swift-ci

Description

@swift-ci
Previous ID SR-14814
Radar None
Original Reporter myhsu (JIRA User)
Type Bug
Status Resolved
Resolution Done
Environment

Swift HEAD: 544c796
Arch: x86_64
OS: Mac OSX 11.4
Xcode version: 12.5.1

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee myhsu (JIRA)
Priority Medium

md5: 1b0272376fcf532d415620f8b212588a

Issue Description:

With this input code:

struct Point {
    var x: Int
    var y: Int
}

func foo(p: Point) -> Int {
    p.x + p.y
}

If we try to attach debug info onto its corresponding SIL code using the following command:

swiftc -emit-sil -Xllvm -sil-print-debuginfo simple.swift -o simple.sil

And try to parse the generated SIL code with `sil-opt`:

sil-opt -O simple.sil

It will give us the following error:

./simple.sil:21:45: error: expected 'forwarding' in SIL instruction
  %3 = struct $Int32 (%2 : $Builtin.Int32), scope 1 // user: %4
                                            ^
...
./simple.sil:66:18: error: expected 'forwarding' in SIL instruction
  %6 = tuple (), loc "simple.swift":2:9, scope 4  // user: %7
                 ^
./simple.sil:81:46: error: expected 'forwarding' in SIL instruction
  %2 = struct_extract %0 : $Point, #Point.y, scope 5 // user: %3
                                             ^
...

Take `struct_extract` instruction as an example: The SIL parser always expects a "forwarding" identifier if there is a comma follows after the operands. However, in this case we have debug info directive follows after the comma – which is totally legit – so the parser bails out.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itself

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions