12

On "Compiling swift files" step while archiving, it said that a particular file had this error:

PHI node has multiple entries for the same basic block with different incoming values!
  %31 = phi i64 [ 3, %385 ], [ %386, %385 ], [ 1, %29 ], !dbg !1370
label %385
i64 3
  %386 = phi i64 [ %23, %27 ], !dbg !1433
LLVM ERROR: Broken function found, compilation aborted!

After commenting the file's code for a while I found out that the following lines of code were the issue:

var normalizedStrikes = max(1, strikes)
normalizedStrikes = min(normalizedStrikes, 3)

After trying out a lot of things I discovered that I couldn't use max() and then min(), here is what solved the issue for me:

var normalizedStrikes = strikes
if (normalizedStrikes <= 0) {
    normalizedStrikes = 1
}
normalizedStrikes = min(normalizedStrikes, 3)

Another very nice thing I've found is that if I change the condition to "< 1", it throws the same error. Good stuff.

var normalizedStrikes = strikes
if (normalizedStrikes < 1) {
    normalizedStrikes = 1
}
normalizedStrikes = min(normalizedStrikes, 3)

My question is: why that happened?

Btw I'm using Xcode Version 6.1.1 (6A2008a)

Rafael Garcia
  • 361
  • 3
  • 14
  • That's a pretty cool bug. I duplicated it on my dev environment. The swift compiler is still fairly new, and is loaded with bugs. It will improve with time. – HalR Feb 14 '15 at 15:02
  • Nice spot with this, I was getting a similar error: `PHI node has multiple entries for the same basic block with different incoming values!` `%12 = phi double [ %9, %8 ], [ 1.000000e+00, %8 ], [ 0.000000e+00, %7 ], [ 1.000000e+00, %7 ], !dbg !254` `label %8` `double 1.000000e+00` `%9 = phi double [ %5, %entry ], !dbg !252` `LLVM ERROR: Broken function found, compilation aborted!` And thanks to your post I found the problem was with: `progress = min(1, max(0, progress))` Also I only notice the error occurred while build the Release config which was running Optimisations... Cheers again! – Rich Feb 23 '15 at 20:18
  • Did you file a bug about this? – Matteo Piombo Mar 31 '15 at 14:11
  • Nope, my bad, I was lazy about it, @MatteoPiombo. If you could that, that'd be awesome! :) – Rafael Garcia Mar 31 '15 at 17:44

1 Answers1

1

This is resolved as of Xcode 6.3 (6D570).

Aaron Brager
  • 65,323
  • 19
  • 161
  • 287