Skip to content

Commit 514523b

Browse files
committed
fixup! Reject function protos that have different cfi_salt values.
1 parent 44950cc commit 514523b

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

clang/lib/Sema/SemaType.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7943,6 +7943,10 @@ static bool handleFunctionTypeAttr(TypeProcessingState &state, ParsedAttr &attr,
79437943
}
79447944

79457945
if (attr.getKind() == ParsedAttr::AT_CFISalt) {
7946+
if (attr.getNumArgs() == 0)
7947+
return true;
7948+
7949+
// Delay if this is not a function type.
79467950
StringRef Argument;
79477951
if (!S.checkStringLiteralArgumentAttr(attr, 0, Argument))
79487952
return false;
@@ -7952,6 +7956,9 @@ static bool handleFunctionTypeAttr(TypeProcessingState &state, ParsedAttr &attr,
79527956
return false;
79537957

79547958
const auto *FnTy = unwrapped.get()->getAs<FunctionProtoType>();
7959+
if (!FnTy)
7960+
return true;
7961+
79557962
FunctionProtoType::ExtProtoInfo EPI = FnTy->getExtProtoInfo();
79567963
EPI.ExtraAttributeInfo.CFISalt = Argument;
79577964

clang/test/Sema/attr-cfi-salt.c

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,20 @@
22

33
#define __cfi_salt(S) __attribute__((cfi_salt(S)))
44

5+
int bad1() __cfi_salt();
6+
// expected-error@-1{{'cfi_salt' attribute takes one argument}}
7+
int bad2() __cfi_salt(42);
8+
// expected-error@-1{{expected string literal as argument of 'cfi_salt' attribute}}
9+
510
int foo(int a, int b) __cfi_salt("pepper"); // ok
611
int foo(int a, int b) __cfi_salt("pepper"); // ok
712

813
typedef int (*bar_t)(void) __cfi_salt("pepper"); // ok
914
typedef int (*bar_t)(void) __cfi_salt("pepper"); // ok
1015

11-
#if 0
12-
// FIXME: These should fail.
13-
int b(void) __cfi_salt("salt 'n") __cfi_salt("pepper");
14-
bar_t bar_fn __cfi_salt("salt 'n");
15-
#endif
16+
// FIXME: Should we allow this?
17+
// int b(void) __cfi_salt("salt 'n") __cfi_salt("pepper");
18+
// bar_t bar_fn __cfi_salt("salt 'n");
1619

1720
int baz __cfi_salt("salt");
1821
// expected-warning@-1{{'cfi_salt' only applies to function types}}
@@ -36,3 +39,12 @@ typedef int (*quux_t)(void) __cfi_salt("salt 'n");
3639
// expected-note@-1{{previous definition is here}}
3740
typedef int (*quux_t)(void) __cfi_salt("pepper");
3841
// expected-error@-1{{typedef redefinition with different type}}
42+
43+
void func(int a) __cfi_salt("pepper");
44+
// expected-note@-1{{previous declaration is here}}
45+
void func(int a) { }
46+
// expected-error@-1{{conflicting types for 'func'}}
47+
48+
void func2(int) [[clang::cfi_salt("test")]];
49+
void func2(int a) { }
50+
void (*fp)(int) = func2;

0 commit comments

Comments
 (0)