Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-452] Recursive function without base case returns garbage value when compiled with -O #43069

Closed
swift-ci opened this issue Jan 3, 2016 · 3 comments · Fixed by #59535
Closed
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself optimized only Flag: An issue whose reproduction requires optimized compilation

Comments

@swift-ci
Copy link
Contributor

swift-ci commented Jan 3, 2016

Previous ID SR-452
Radar None
Original Reporter loic (JIRA User)
Type Bug
Environment

Swift 2.2-dev (December 31)
OS X El Capitan

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

md5: 546cfc45f510272795c24cb4aa0daa3d

Issue Description:

This code will crash (segfault) when compiled with -Onone, but returns garbage when compiled with -O.

func rec(x: Int) -> Int {
    return rec(x)
}
print(rec(0))

I think it should always crash.

@swift-ci
Copy link
Contributor Author

Comment by Nadav Rotem (JIRA)

It looks like _TF4main3recFSiSi is compiled into: return undef.

@swift-ci
Copy link
Contributor Author

Comment by Nadav Rotem (JIRA)

The SIL looks okay. It looks like LLVM is optimizing _TF4main3recFSiSi into "return undef".

// main.rec (Swift.Int) -> Swift.Int
sil hidden @_TF4main3recFSiSi : $@convention(thin) (Int) -> Int {
bb0(%0 : $Int):
debug_value %0 : $Int // let x // id: %1
// function_ref main.rec (Swift.Int) -> Swift.Int
%2 = function_ref @_TF4main3recFSiSi : $@convention(thin) (Int) -> Int // user: %3
%3 = apply %2(%0) : $@convention(thin) (Int) -> Int // user: %4
return %3 : $Int // id: %4
}

define hidden i64 @_TF4main3recFSiSi(i64) #1 {
entry:
ret i64 undef
}

@Dante-Broggi
Copy link
Contributor

Has this been resolved? If so, it should be closed.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
AnthonyLatsis added a commit to AnthonyLatsis/swift that referenced this issue Jun 22, 2022
AnthonyLatsis added a commit to AnthonyLatsis/swift that referenced this issue Jun 22, 2022
AnthonyLatsis added a commit to AnthonyLatsis/swift that referenced this issue Jun 23, 2022
AnthonyLatsis added a commit to AnthonyLatsis/swift that referenced this issue Jun 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself optimized only Flag: An issue whose reproduction requires optimized compilation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants