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

Bill Wendling via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 28 16:09:39 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
+
----------------
bwendling wrote:

> ```
> void func(int a) __cfi_salt("pepper");
> void func(int a) { } // Okay, inherits the attribute from the declaration.
> ```

This isn't allowed, because function types don't appear to work that way.

> ```
> 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
> ```

Okay.

> ```
> 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?
> ```

No, because it would lose the attribute.


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


More information about the cfe-commits mailing list