Skip to content

[SR-13449] Wrong method call when binary is built with optimizations #55891

@lxbndr

Description

@lxbndr
Previous ID SR-13449
Radar rdar://problem/68170038
Original Reporter @lxbndr
Type Bug
Status Closed
Resolution Done
Environment

Swift version 5.3-dev (LLVM 36f7fac60d2e676, Swift a5ca83a8b2d499f)
Target: x86_64-unknown-windows-msvc

Additional Detail from JIRA
Votes 1
Component/s Compiler
Labels Bug, OptimizedOnly, Optimizer
Assignee None
Priority Medium

md5: 205e769ae641e22368ccb8ccbb625245

blocks:

Issue Description:

Under specific conditions binary built with optimizations would call wrong method inside a class. This is the reason why network requests are not working in swift-corelibs-foundation at the moment.

Sample code have to be split in two sources, otherwise the issue is not reproduced.

// Grandchild.swift
class Grandchild: Child {}
// main.swift
class Root {}
class Child: Root {
  func doSomething() {
    print("-- \(type(of: self)) - \(#function) - will call doHomework()")
    doHomework()
    print("-- \(type(of: self)) - \(#function) - did call doHomework()")
  }   
  private func eatPopcorn() {
    print("-- \(type(of: self)) - \(#function)")
  }
  func playGames() {
    print("-- \(type(of: self)) - \(#function) - SHOULD NOT HAPPEN")
    eatPopcorn()
  }
  func doHomework() {
    print("-- \(type(of: self)) - \(#function)")
  }
}

Grandchild().doSomething()

Expected output:

-- Grandchild - doSomething() - will call doHomework()
-- Grandchild - doHomework()
-- Grandchild - doSomething() - did call doHomework()

Actual output:

-- Grandchild - doSomething() - will call doHomework()
-- Grandchild - playGames() - SHOULD NOT HAPPEN
-- Grandchild - eatPopcorn()
-- Grandchild - doSomething() - did call doHomework()

Metadata

Metadata

Assignees

No one assigned

    Labels

    SILOptimizerArea → compiler: SIL optimization passesbugA deviation from expected or documented behavior. Also: expected but undesirable behavior.compilerThe Swift compiler itselfoptimized onlyFlag: An issue whose reproduction requires optimized compilation

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions