[clang] [Clang][attr] Add 'kcfi_salt' attribute (PR #141846)
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Thu Jul 24 08:16:01 PDT 2025
================
@@ -0,0 +1,38 @@
+// RUN: %clang_cc1 -fsyntax-only -fsanitize=kcfi -verify %s
+
+#define __cfi_salt(S) __attribute__((cfi_salt(S)))
+
+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
+
+#if 0
+// FIXME: These should fail.
+int b(void) __cfi_salt("salt 'n") __cfi_salt("pepper");
+bar_t bar_fn __cfi_salt("salt 'n");
+#endif
+
----------------
AaronBallman wrote:
A few more tests I'd like to see:
```
void func(int a) __cfi_salt("pepper");
void func(int a) { } // Okay, inherits the attribute from the declaration.
void blah() __attribute__((cfi_salt)); // Error, missing argument to the attribute
void blarg() __attribute__((cfi_salt(5))); // Error, argument to the attribute is not a string
void okay() [[clang::cfi_salt("test")]]; // Uses the [[]] syntax which appertains to the function type
void (*fp)() = okay; // Is this okay to drop the type attribute? Or is this an error?
```
https://github.com/llvm/llvm-project/pull/141846
More information about the cfe-commits
mailing list