[clang] [Clang][attr] Add 'cfi_salt' attribute (PR #141846)

Erich Keane via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 4 06:42:21 PDT 2025


================
@@ -0,0 +1,67 @@
+// RUN: %clang_cc1 -fsyntax-only -fsanitize=kcfi -verify %s
+
+#define __cfi_salt(S) __attribute__((cfi_salt(S)))
+
+int bad1() __cfi_salt();
+    // expected-error at -1{{'cfi_salt' attribute takes one argument}}
+int bad2() __cfi_salt(42);
+    // expected-error at -1{{expected string literal as argument of 'cfi_salt' attribute}}
+
+int foo(int a, int b) __cfi_salt("pepper"); // ok
+int foo(int a, int b) __cfi_salt("pepper"); // ok
+
+typedef int (*bar_t)(void) __cfi_salt("pepper"); // ok
+typedef int (*bar_t)(void) __cfi_salt("pepper"); // ok
+
+// FIXME: Should we allow this?
+// int b(void) __cfi_salt("salt 'n") __cfi_salt("pepper");
+// bar_t bar_fn __cfi_salt("salt 'n");
+
+int baz __cfi_salt("salt");
+    // expected-warning at -1{{'cfi_salt' only applies to function types}}
+
+int baz_fn(int a, int b) __cfi_salt("salt 'n");
+    // expected-note at -1{{previous declaration is here}}
----------------
erichkeane wrote:

I have a VERY strong preference for putting the 'note' immediately after the 'error' textually and doing whatever it takes to get the '@' to work right (I typically suggest our bookmark feature, but with these that is obviously not necessary).

For example, while reading this test, it took me an unfortunate amount of time to figure out which error this went with.

https://github.com/llvm/llvm-project/pull/141846


More information about the cfe-commits mailing list