[clang] [Clang][attr] Add 'cfi_salt' attribute (PR #141846)
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Tue Aug 5 08:33:41 PDT 2025
================
@@ -7941,6 +7942,32 @@ static bool handleFunctionTypeAttr(TypeProcessingState &state, ParsedAttr &attr,
return true;
}
+ if (attr.getKind() == ParsedAttr::AT_CFISalt) {
+ if (attr.getNumArgs() == 0)
+ return true;
+
+ // Delay if this is not a function type.
+ StringRef Argument;
+ if (!S.checkStringLiteralArgumentAttr(attr, 0, Argument))
+ return false;
+
+ // Delay if this is not a function type.
+ if (!unwrapped.isFunctionType())
+ return false;
+
+ const auto *FnTy = unwrapped.get()->getAs<FunctionProtoType>();
+ if (!FnTy)
----------------
AaronBallman wrote:
I think what's being asked for is a test case like:
```
// RUN: %clang_cc1 -std=c89 -fsyntax-only -fsanitize=kcfi -verify %s
// K&R C function without a prototype
void func() __attribute__((cfi_salt("pepper"))); // expected-error {{attribute only applies to function types with a prototype}}
void (*fp)() __attribute__((cfi_salt("pepper"))); // expected-error {{attribute only applies to function pointer types with a prototype}}
```
(or something along those lines). As it stands, it looks like this code will silently drop the attribute because `getAs` will return null and we'll early return here.
https://github.com/llvm/llvm-project/pull/141846
More information about the cfe-commits
mailing list