Skip to content

Commit c4168be

Browse files
committed
[embedded] Add an embedded test for -enable-import-ptrauth-field-function-pointers, fix deserialization
1 parent bc4ab29 commit c4168be

File tree

3 files changed

+77
-3
lines changed

3 files changed

+77
-3
lines changed

lib/Serialization/DeserializeSIL.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2368,7 +2368,7 @@ bool SILDeserializer::readSILInstruction(SILFunction *Fn,
23682368
SILValue op = getLocalValue(
23692369
ValID, getSILType(MF->getType(TyID), (SILValueCategory)TyCategory, Fn));
23702370
auto accessKind = SILAccessKind(Attr & 0x3);
2371-
auto enforcement = SILAccessEnforcement((Attr >> 2) & 0x3);
2371+
auto enforcement = SILAccessEnforcement((Attr >> 2) & 0x07);
23722372
bool noNestedConflict = (Attr >> 4) & 0x01;
23732373
bool fromBuiltin = (Attr >> 5) & 0x01;
23742374
ResultInst = Builder.createBeginAccess(Loc, op, accessKind, enforcement,
@@ -2410,7 +2410,7 @@ bool SILDeserializer::readSILInstruction(SILFunction *Fn,
24102410
getLocalValue(ValID2, getSILType(MF->getType(TyID2),
24112411
(SILValueCategory)TyCategory2, Fn));
24122412
auto accessKind = SILAccessKind(Attr & 0x3);
2413-
auto enforcement = SILAccessEnforcement((Attr >> 2) & 0x03);
2413+
auto enforcement = SILAccessEnforcement((Attr >> 2) & 0x07);
24142414
bool noNestedConflict = (Attr >> 4) & 0x01;
24152415
bool fromBuiltin = (Attr >> 5) & 0x01;
24162416
ResultInst = Builder.createBeginUnpairedAccess(
@@ -2422,7 +2422,7 @@ bool SILDeserializer::readSILInstruction(SILFunction *Fn,
24222422
SILValue op = getLocalValue(
24232423
ValID, getSILType(MF->getType(TyID), (SILValueCategory)TyCategory, Fn));
24242424
bool aborted = Attr & 0x1;
2425-
auto enforcement = SILAccessEnforcement((Attr >> 1) & 0x03);
2425+
auto enforcement = SILAccessEnforcement((Attr >> 1) & 0x07);
24262426
bool fromBuiltin = (Attr >> 3) & 0x01;
24272427
ResultInst = Builder.createEndUnpairedAccess(Loc, op, enforcement, aborted,
24282428
fromBuiltin);

test/embedded/ptrauth-fieldptr1.swift

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %{python} %utils/split_file.py -o %t %s
3+
4+
// RUN: %target-swift-frontend -enable-import-ptrauth-field-function-pointers -O -emit-ir %t/Main.swift -enable-experimental-feature Embedded -import-objc-header %t/header.h | %FileCheck %s
5+
6+
// REQUIRES: swift_in_compiler
7+
// REQUIRES: VENDOR=apple
8+
// REQUIRES: OS=macosx
9+
// REQUIRES: CPU=arm64e
10+
11+
// BEGIN header.h
12+
13+
struct MyStruct {
14+
void (*fptr1)(void);
15+
void (*__ptrauth(0, 0, 0x4242) fptr2)(void);
16+
};
17+
18+
// BEGIN Main.swift
19+
20+
public func test1(x: UnsafePointer<MyStruct>) {
21+
x.pointee.fptr1()
22+
}
23+
24+
public func test2(x: UnsafePointer<MyStruct>) {
25+
x.pointee.fptr2()
26+
}
27+
28+
// CHECK: define {{.*}}@"$s4Main5test11xySPySo8MyStructVG_tF"
29+
// CHECK: call {{.*}}[ "ptrauth"(i32 0, i64 0) ]
30+
// CHECK: define {{.*}}@"$s4Main5test21xySPySo8MyStructVG_tF"
31+
// CHECK: call {{.*}}[ "ptrauth"(i32 0, i64 16962) ]

test/embedded/ptrauth-fieldptr2.swift

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %{python} %utils/split_file.py -o %t %s
3+
4+
// RUN: %target-swift-frontend -enable-import-ptrauth-field-function-pointers -O -emit-module -o %t/Module.swiftmodule %t/Module.swift -enable-experimental-feature Embedded -import-objc-header %t/header.h
5+
6+
// RUN: %target-swift-frontend -enable-import-ptrauth-field-function-pointers -O -emit-ir %t/Main.swift -I%t -enable-experimental-feature Embedded -import-objc-header %t/header.h
7+
8+
// REQUIRES: swift_in_compiler
9+
// REQUIRES: VENDOR=apple
10+
// REQUIRES: OS=macosx
11+
// REQUIRES: CPU=arm64e
12+
13+
// BEGIN header.h
14+
15+
#pragma once
16+
struct MyStruct {
17+
void (*fptr1)(void);
18+
void (*__ptrauth(0, 0, 0x4242) fptr2)(void);
19+
};
20+
21+
// BEGIN Module.swift
22+
23+
public func test1(x: UnsafePointer<MyStruct>) {
24+
x.pointee.fptr1()
25+
}
26+
27+
public func test2(x: UnsafePointer<MyStruct>) {
28+
x.pointee.fptr2()
29+
}
30+
31+
// BEGIN Main.swift
32+
33+
import Module
34+
35+
public func mainfunc(x: UnsafePointer<MyStruct>) {
36+
test1(x: x)
37+
test2(x: x)
38+
}
39+
40+
// CHECK: define {{.*}}@"$s4Main5test11xySPySo8MyStructVG_tF"
41+
// CHECK: call {{.*}}[ "ptrauth"(i32 0, i64 0) ]
42+
// CHECK: define {{.*}}@"$s4Main5test21xySPySo8MyStructVG_tF"
43+
// CHECK: call {{.*}}[ "ptrauth"(i32 0, i64 16962) ]

0 commit comments

Comments
 (0)