Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,9 @@ Removed Compiler Flags

Attribute Changes in Clang
--------------------------
- The definition of a function declaration with ``[[clang::cfi_unchecked_callee]]`` inherits this
attribute, allowing the attribute to only be attached to the declaration. Prior, this would be
treated as an error where the definition and declaration would have differing types.

Improvements to Clang's diagnostics
-----------------------------------
Expand Down
17 changes: 17 additions & 0 deletions clang/lib/Sema/SemaDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3877,6 +3877,23 @@ bool Sema::MergeFunctionDecl(FunctionDecl *New, NamedDecl *&OldD, Scope *S,
RequiresAdjustment = true;
}

// If the declaration is marked with cfi_unchecked_callee but the definition
// isn't, the definition is also cfi_unchecked_callee.
if (auto *FPT1 = OldType->getAs<FunctionProtoType>()) {
if (auto *FPT2 = NewType->getAs<FunctionProtoType>()) {
FunctionProtoType::ExtProtoInfo EPI1 = FPT1->getExtProtoInfo();
FunctionProtoType::ExtProtoInfo EPI2 = FPT2->getExtProtoInfo();

if (EPI1.CFIUncheckedCallee && !EPI2.CFIUncheckedCallee) {
EPI2.CFIUncheckedCallee = true;
NewQType = Context.getFunctionType(FPT2->getReturnType(),
FPT2->getParamTypes(), EPI2);
NewType = cast<FunctionType>(NewQType);
New->setType(NewQType);
}
}
}

// Merge regparm attribute.
if (OldTypeInfo.getHasRegParm() != NewTypeInfo.getHasRegParm() ||
OldTypeInfo.getRegParm() != NewTypeInfo.getRegParm()) {
Expand Down
9 changes: 9 additions & 0 deletions clang/test/AST/cfi-unchecked-callee.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// RUN: %clang_cc1 -ast-dump %s | FileCheck %s


// CHECK: FunctionDecl [[PTR:0x[a-z0-9]*]] {{.*}}func 'void () __attribute__((cfi_unchecked_callee))'
__attribute__((cfi_unchecked_callee))
void func(void);

// CHECK-NEXT: FunctionDecl {{0x[a-z0-9]*}} prev [[PTR]] {{.*}}func 'void () __attribute__((cfi_unchecked_callee))'
void func(void) {}
4 changes: 4 additions & 0 deletions clang/test/Frontend/cfi-unchecked-callee-attribute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,3 +233,7 @@ void lambdas() {
checked_func = checked_lambda;
};
}

CFI_UNCHECKED_CALLEE
void func(void);
void func(void) {} // No warning expected.