Skip to content

Commit 6e5b235

Browse files
committed
[InstCombine] Do not introduce bitcasts for swifterror arguments.
The following constraints hold for swifterror values: A swifterror value (either the parameter or the alloca) can only be loaded and stored from, or used as a swifterror argument. This patch updates instcombine to not try to convert a bitcast of a function into a bitcast of a swifterror argument. Reviewed By: rjmccall Differential Revision: https://reviews.llvm.org/D90258
1 parent ffb36e4 commit 6e5b235

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4907,6 +4907,9 @@ bool InstCombiner::transformConstExprCastCall(CallBase &Call) {
49074907
if (Call.isInAllocaArgument(i))
49084908
return false; // Cannot transform to and from inalloca.
49094909

4910+
if (CallerPAL.hasParamAttribute(i, Attribute::SwiftError))
4911+
return false;
4912+
49104913
// If the parameter is passed as a byval argument, then we have to have a
49114914
// sized type and the sized type has to have the same size as the old type.
49124915
if (ParamTy != ActTy && CallerPAL.hasParamAttribute(i, Attribute::ByVal)) {
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2+
; RUN: opt -instcombine -S %s | FileCheck %s
3+
4+
; The swifterror value can only be loaded, stored or used as swifterror
5+
; argument. Make sure we do not try to turn the function bitcast into an
6+
; argument bitcast.
7+
define swiftcc void @spam(i32** swifterror %arg) {
8+
; CHECK-LABEL: @spam(
9+
; CHECK-NEXT: bb:
10+
; CHECK-NEXT: call swiftcc void bitcast (void (i64**)* @widget to void (i32**)*)(i32** swifterror [[ARG:%.*]])
11+
; CHECK-NEXT: ret void
12+
;
13+
bb:
14+
call swiftcc void bitcast (void (i64**)* @widget to void (i32**)*)(i32** swifterror %arg)
15+
ret void
16+
}
17+
18+
declare swiftcc void @widget(i64**)

0 commit comments

Comments
 (0)