Skip to content

Commit 06e43bd

Browse files
committed
Change number of arguments check. Add test for it. And move the diagnostic messages to the same line.
1 parent 029ee8e commit 06e43bd

File tree

2 files changed

+21
-38
lines changed

2 files changed

+21
-38
lines changed

clang/lib/Sema/SemaType.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7943,10 +7943,9 @@ static bool handleFunctionTypeAttr(TypeProcessingState &state, ParsedAttr &attr,
79437943
}
79447944

79457945
if (attr.getKind() == ParsedAttr::AT_CFISalt) {
7946-
if (attr.getNumArgs() == 0)
7946+
if (attr.getNumArgs() != 1)
79477947
return true;
79487948

7949-
// Delay if this is not a function type.
79507949
StringRef Argument;
79517950
if (!S.checkStringLiteralArgumentAttr(attr, 0, Argument))
79527951
return false;

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

Lines changed: 20 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
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}}
5+
int bad1() __cfi_salt(); // expected-error{{'cfi_salt' attribute takes one argument}}
6+
int bad2() __cfi_salt(42); // expected-error{{expected string literal as argument of 'cfi_salt' attribute}}
7+
int bad3() __attribute__((cfi_salt("a", "b", "c"))); // expected-error{{'cfi_salt' attribute takes one argument}}
8+
99

1010
int foo(int a, int b) __cfi_salt("pepper"); // ok
1111
int foo(int a, int b) __cfi_salt("pepper"); // ok
@@ -17,51 +17,35 @@ typedef int (*bar_t)(void) __cfi_salt("pepper"); // ok
1717
// int b(void) __cfi_salt("salt 'n") __cfi_salt("pepper");
1818
// bar_t bar_fn __cfi_salt("salt 'n");
1919

20-
int baz __cfi_salt("salt");
21-
// expected-warning@-1{{'cfi_salt' only applies to function types}}
20+
int baz __cfi_salt("salt"); // expected-warning{{'cfi_salt' only applies to function types}}
2221

23-
int baz_fn(int a, int b) __cfi_salt("salt 'n");
24-
// expected-note@-1{{previous declaration is here}}
25-
int baz_fn(int a, int b) __cfi_salt("pepper");
26-
// expected-error@-1{{conflicting types for 'baz_fn'}}
22+
int baz_fn(int a, int b) __cfi_salt("salt 'n"); // expected-note{{previous declaration is here}}
23+
int baz_fn(int a, int b) __cfi_salt("pepper"); // expected-error{{conflicting types for 'baz_fn'}}
2724

28-
int mux_fn(int a, int b) __cfi_salt("salt 'n");
29-
// expected-note@-1{{previous declaration is here}}
30-
int mux_fn(int a, int b) __cfi_salt("pepper") {
31-
// expected-error@-1{{conflicting types for 'mux_fn'}}
25+
int mux_fn(int a, int b) __cfi_salt("salt 'n"); // expected-note{{previous declaration is here}}
26+
int mux_fn(int a, int b) __cfi_salt("pepper") { // expected-error{{conflicting types for 'mux_fn'}}
3227
return a * b;
3328
}
3429

35-
typedef int qux_t __cfi_salt("salt");
36-
// expected-warning@-1{{'cfi_salt' only applies to function types}}
30+
typedef int qux_t __cfi_salt("salt"); // expected-warning{{'cfi_salt' only applies to function types}}
3731

38-
typedef int (*quux_t)(void) __cfi_salt("salt 'n");
39-
// expected-note@-1{{previous definition is here}}
40-
typedef int (*quux_t)(void) __cfi_salt("pepper");
41-
// expected-error@-1{{typedef redefinition with different type}}
32+
typedef int (*quux_t)(void) __cfi_salt("salt 'n"); // expected-note{{previous definition is here}}
33+
typedef int (*quux_t)(void) __cfi_salt("pepper"); // expected-error{{typedef redefinition with different type}}
4234

43-
void func1(int a) __cfi_salt("pepper");
44-
// expected-note@-1{{previous declaration is here}}
45-
void func1(int a) { }
46-
// expected-error@-1{{conflicting types for 'func1'}}
47-
void (*fp1)(int) = func1;
48-
// expected-error@-1{{incompatible function pointer types initializing 'void (*)(int)' with an expression of type 'void (int)'}}
35+
void func1(int a) __cfi_salt("pepper"); // expected-note{{previous declaration is here}}
36+
void func1(int a) { } // expected-error{{conflicting types for 'func1'}}
37+
void (*fp1)(int) = func1; // expected-error{{incompatible function pointer types initializing 'void (*)(int)' with an expression of type 'void (int)'}}
4938

50-
void func2(int) [[clang::cfi_salt("test")]];
51-
// expected-note@-1{{previous declaration is here}}
52-
void func2(int a) { }
53-
// expected-error@-1{{conflicting types for 'func2'}}
54-
void (*fp2)(int) = func2;
55-
// expected-error@-1{{incompatible function pointer types initializing 'void (*)(int)' with an expression of type 'void (int)'}}
39+
void func2(int) [[clang::cfi_salt("test")]]; // expected-note{{previous declaration is here}}
40+
void func2(int a) { } // expected-error{{conflicting types for 'func2'}}
41+
void (*fp2)(int) = func2; // expected-error{{incompatible function pointer types initializing 'void (*)(int)' with an expression of type 'void (int)'}}
5642

5743
void func3(int) __cfi_salt("pepper"); // ok
5844
void func3(int a) __cfi_salt("pepper") { } // ok
5945
void (* __cfi_salt("pepper") fp3)(int) = func3; // ok
60-
void (*fp3_noattr)(int) = func3;
61-
// expected-error@-1{{incompatible function pointer types initializing 'void (*)(int)' with an expression of type 'void (int)'}}
46+
void (*fp3_noattr)(int) = func3; // expected-error{{incompatible function pointer types initializing 'void (*)(int)' with an expression of type 'void (int)'}}
6247

6348
void func4(int) [[clang::cfi_salt("test")]]; // ok
6449
void func4(int a) [[clang::cfi_salt("test")]] { } // ok
6550
void (* [[clang::cfi_salt("test")]] fp4)(int) = func4; // ok
66-
void (*fp4_noattr)(int) = func4;
67-
// expected-error@-1{{incompatible function pointer types initializing 'void (*)(int)' with an expression of type 'void (int)'}}
51+
void (*fp4_noattr)(int) = func4; // expected-error{{incompatible function pointer types initializing 'void (*)(int)' with an expression of type 'void (int)'}}

0 commit comments

Comments
 (0)