Skip to content

Commit ecce6ac

Browse files
authored
Merge pull request swiftlang#76046 from kubamracek/fix-optimize-assert-config
Fix flipped 0/1 values in SimplifyBuiltin.optimizeAssertConfig
2 parents 3a570e0 + 4b16479 commit ecce6ac

File tree

3 files changed

+35
-18
lines changed

3 files changed

+35
-18
lines changed

SwiftCompilerSources/Sources/Optimizer/InstructionSimplification/SimplifyBuiltin.swift

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -150,19 +150,20 @@ private extension BuiltinInst {
150150
}
151151

152152
func optimizeAssertConfig(_ context: SimplifyContext) {
153-
let literal: IntegerLiteralInst
154-
switch context.options.assertConfiguration {
155-
case .enabled:
156-
let builder = Builder(before: self, context)
157-
literal = builder.createIntegerLiteral(1, type: type)
158-
case .disabled:
153+
// The values for the assert_configuration call are:
154+
// 0: Debug
155+
// 1: Release
156+
// 2: Fast / Unchecked
157+
let config = context.options.assertConfiguration
158+
switch config {
159+
case .debug, .release, .unchecked:
159160
let builder = Builder(before: self, context)
160-
literal = builder.createIntegerLiteral(0, type: type)
161-
default:
161+
let literal = builder.createIntegerLiteral(config.integerValue, type: type)
162+
uses.replaceAll(with: literal, context)
163+
context.erase(instruction: self)
164+
case .unknown:
162165
return
163166
}
164-
uses.replaceAll(with: literal, context)
165-
context.erase(instruction: self)
166167
}
167168

168169
func optimizeTargetTypeConst(_ context: SimplifyContext) {

SwiftCompilerSources/Sources/Optimizer/PassManager/Options.swift

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,31 @@ struct Options {
3636
_bridged.hasFeature(feature)
3737
}
3838

39+
// The values for the assert_configuration call are:
40+
// 0: Debug
41+
// 1: Release
42+
// 2: Fast / Unchecked
3943
enum AssertConfiguration {
40-
case enabled
41-
case disabled
44+
case debug
45+
case release
46+
case unchecked
4247
case unknown
48+
49+
var integerValue: Int {
50+
switch self {
51+
case .debug: return 0
52+
case .release: return 1
53+
case .unchecked: return 2
54+
case .unknown: fatalError()
55+
}
56+
}
4357
}
4458

4559
var assertConfiguration: AssertConfiguration {
4660
switch _bridged.getAssertConfiguration() {
47-
case .Debug: return .enabled
48-
case .Release, .Unchecked: return .disabled
61+
case .Debug: return .debug
62+
case .Release: return .release
63+
case .Unchecked: return .unchecked
4964
default: return .unknown
5065
}
5166
}

test/SILOptimizer/simplify_builtin.sil

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// RUN: %target-sil-opt -enable-sil-verify-all %s -onone-simplification -simplify-instruction=builtin | %FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-EARLY
22
// RUN: %target-sil-opt -enable-sil-verify-all %s -late-onone-simplification -simplify-instruction=builtin | %FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-LATE
3-
// RUN: %target-sil-opt -enable-sil-verify-all %s -assert-conf-id=1 -onone-simplification -simplify-instruction=builtin | %FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-NOASSERTS
4-
// RUN: %target-sil-opt -enable-sil-verify-all %s -assert-conf-id=2 -onone-simplification -simplify-instruction=builtin | %FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-NOASSERTS
3+
// RUN: %target-sil-opt -enable-sil-verify-all %s -assert-conf-id=1 -onone-simplification -simplify-instruction=builtin | %FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-NOASSERTS1
4+
// RUN: %target-sil-opt -enable-sil-verify-all %s -assert-conf-id=2 -onone-simplification -simplify-instruction=builtin | %FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-NOASSERTS2
55

66
// REQUIRES: swift_in_compiler
77

@@ -417,8 +417,9 @@ bb0:
417417

418418
// CHECK-LABEL: sil @remove_assert_configuration
419419
// CHECK-NOT: builtin "assert_configuration"
420-
// CHECK-EARLY: [[L:%.*]] = integer_literal $Builtin.Int8, 1
421-
// CHECK-NOASSERTS: [[L:%.*]] = integer_literal $Builtin.Int8, 0
420+
// CHECK-EARLY: [[L:%.*]] = integer_literal $Builtin.Int8, 0
421+
// CHECK-NOASSERTS1: [[L:%.*]] = integer_literal $Builtin.Int8, 1
422+
// CHECK-NOASSERTS2: [[L:%.*]] = integer_literal $Builtin.Int8, 2
422423
// CHECK: [[R:%.*]] = struct $Int8 ([[L]] : $Builtin.Int8)
423424
// CHECK: return [[R]]
424425
// CHECK: } // end sil function 'remove_assert_configuration'

0 commit comments

Comments
 (0)