Files
swift-mirror/test/IRGen/Inputs/sensitive_c_functions.c
Erik Eckstein 1b1d5ed020 IRGen: support the @sensitive attribute
Call `swift_clearSensitive` after destroying or taking "sensitive" struct types.

Also, support calling C-functions with "sensitive" parameters or return values. In SIL, sensitive types are address-only and so are sensitive parameters/return values.
Though, (small) sensitive C-structs are passed directly to/from C-functions. We need re-abstract such parameter and return values for C-functions.
2024-04-09 12:01:11 +02:00

48 lines
953 B
C

#include "sensitive.h"
#include <stdio.h>
struct SmallCStruct getSmallStruct(int x) {
printf("x = %d\n", x);
struct SmallCStruct s;
s.a = 0xdeadbeaf;
s.b = 0xdeadbeaf;
s.c = 0xdeadbeaf;
return s;
}
struct LargeCStruct getLargeStruct(int x) {
printf("x = %d\n", x);
struct LargeCStruct s;
s.a = 0xdeadbeaf;
s.b = 0xdeadbeaf;
s.c = 0xdeadbeaf;
s.d = 0xdeadbeaf;
s.e = 0xdeadbeaf;
s.f = 0xdeadbeaf;
s.g = 0xdeadbeaf;
return s;
}
void printSmallStruct(int x, struct SmallCStruct s, int y) {
printf("x = %d, y = %d\n", x, y);
printf("s = (%u, %u, %u)\n", s.a, s.b, s.c);
}
struct SmallCStruct forwardSmallStruct(struct SmallCStruct s) {
return s;
}
void printLargeStruct(int x, struct LargeCStruct s, int y) {
printf("x = %d, y = %d\n", x, y);
printf("s = (%u, %u, %u, %u, %u, %u, %u)\n", s.a, s.b, s.c, s.e, s.e, s.f, s.g);
}
struct LargeCStruct forwardLargeStruct(struct LargeCStruct s) {
return s;
}