Skip to content

Commit 029ee8e

Browse files
committed
Add tests for a salt that's empty.
1 parent 44c179d commit 029ee8e

File tree

1 file changed

+21
-3
lines changed

1 file changed

+21
-3
lines changed

clang/test/CodeGen/cfi-salt.c

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,16 @@
1111
#endif
1212

1313
#ifdef ORIG_ATTR_SYN
14-
#define __cfi_salt __attribute__((cfi_salt("pepper")))
14+
#define __cfi_salt __attribute__((cfi_salt("pepper")))
15+
#define __cfi_salt_empty __attribute__((cfi_salt("")))
1516
#else
16-
#define __cfi_salt [[clang::cfi_salt("pepper")]]
17+
#define __cfi_salt [[clang::cfi_salt("pepper")]]
18+
#define __cfi_salt_empty [[clang::cfi_salt("")]]
1719
#endif
1820

1921
typedef int (*fn_t)(void);
2022
typedef int (* __cfi_salt fn_salt_t)(void);
23+
typedef int (* __cfi_salt_empty fn_salt_empty_t)(void);
2124

2225
typedef unsigned int (*ufn_t)(void);
2326
typedef unsigned int (* __cfi_salt ufn_salt_t)(void);
@@ -49,9 +52,13 @@ static int f5_salt(void) __cfi_salt;
4952
extern int f6(void);
5053
extern int f6_salt(void) __cfi_salt;
5154

55+
int f8(void);
56+
int f8_salt_empty(void) __cfi_salt_empty;
57+
5258
struct cfi_struct {
5359
fn_t __cfi_salt fptr;
5460
fn_salt_t td_fptr;
61+
fn_salt_empty_t td_empty_fptr;
5562
};
5663

5764
int f7_salt(struct cfi_struct *ptr);
@@ -75,6 +82,7 @@ int __call(fn_t f) {
7582
int call(fn_t f) { return f(); }
7683
int call_salt(fn_t __cfi_salt f) { return f(); }
7784
int call_salt_ty(fn_salt_t f) { return f(); }
85+
int call_salt_empty_ty(fn_salt_empty_t f) { return f(); }
7886

7987
// CHECK-LABEL: @ucall
8088
// CHECK: call{{.*}} i32 %{{.}}(){{.*}} [ "kcfi"(i32 [[#%d,LOW_SODIUM_UHASH:]]) ]
@@ -113,7 +121,10 @@ int test1(struct cfi_struct *ptr) {
113121
f6_salt() +
114122

115123
f7_salt(ptr) +
116-
f7_typedef_salt(ptr);
124+
f7_typedef_salt(ptr) +
125+
126+
f8() +
127+
f8_salt_empty();
117128
}
118129

119130
// CHECK-LABEL: define dso_local{{.*}} i32 @f1(){{.*}} !kcfi_type
@@ -160,6 +171,13 @@ static int f5_salt(void) __cfi_salt { return 2; }
160171
int f7_salt(struct cfi_struct *ptr) { return ptr->fptr(); }
161172
int f7_typedef_salt(struct cfi_struct *ptr) { return ptr->td_fptr(); }
162173

174+
// CHECK-LABEL: define dso_local{{.*}} i32 @f8(){{.*}} !kcfi_type
175+
// CHECK-SAME: ![[#LOW_SODIUM_TYPE:]]
176+
// CHECK-LABEL: define dso_local{{.*}} i32 @f8_salt_empty(){{.*}} !kcfi_type
177+
// CHECK-SAME: ![[#LOW_SODIUM_TYPE:]]
178+
int f8(void) { return 0; }
179+
int f8_salt_empty(void) __cfi_salt_empty { return 0; }
180+
163181
// CHECK: ![[#]] = !{i32 4, !"kcfi", i32 1}
164182
// OFFSET: ![[#]] = !{i32 4, !"kcfi-offset", i32 3}
165183
//

0 commit comments

Comments
 (0)