Skip to content
Open
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
5 changes: 0 additions & 5 deletions clang/include/clang/Sema/Sema.h
Original file line number Diff line number Diff line change
Expand Up @@ -2685,11 +2685,6 @@ class Sema final : public SemaBase {
/// function without this attribute.
bool DiscardingCFIUncheckedCallee(QualType From, QualType To) const;

/// Returns true if `From` is a function or pointer to a function without the
/// `cfi_unchecked_callee` attribute but `To` is a function or pointer to
/// function with this attribute.
bool AddingCFIUncheckedCallee(QualType From, QualType To) const;

/// This function calls Action when it determines that E designates a
/// misaligned member due to the packed attribute. This is used to emit
/// local diagnostics like in reference binding.
Expand Down
30 changes: 5 additions & 25 deletions clang/lib/Sema/SemaChecking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12351,14 +12351,9 @@ static void DiagnoseMixedUnicodeImplicitConversion(Sema &S, const Type *Source,
}
}

enum CFIUncheckedCalleeChange {
None,
Adding,
Discarding,
};

static CFIUncheckedCalleeChange AdjustingCFIUncheckedCallee(QualType From,
QualType To) {
bool Sema::DiscardingCFIUncheckedCallee(QualType From, QualType To) const {
From = Context.getCanonicalType(From);
To = Context.getCanonicalType(To);
QualType MaybePointee = From->getPointeeType();
if (!MaybePointee.isNull() && MaybePointee->getAs<FunctionType>())
From = MaybePointee;
Expand All @@ -12370,25 +12365,10 @@ static CFIUncheckedCalleeChange AdjustingCFIUncheckedCallee(QualType From,
if (const auto *ToFn = To->getAs<FunctionType>()) {
if (FromFn->getCFIUncheckedCalleeAttr() &&
!ToFn->getCFIUncheckedCalleeAttr())
return Discarding;
if (!FromFn->getCFIUncheckedCalleeAttr() &&
ToFn->getCFIUncheckedCalleeAttr())
return Adding;
return true;
}
}
return None;
}

bool Sema::DiscardingCFIUncheckedCallee(QualType From, QualType To) const {
From = Context.getCanonicalType(From);
To = Context.getCanonicalType(To);
return ::AdjustingCFIUncheckedCallee(From, To) == Discarding;
}

bool Sema::AddingCFIUncheckedCallee(QualType From, QualType To) const {
From = Context.getCanonicalType(From);
To = Context.getCanonicalType(To);
return ::AdjustingCFIUncheckedCallee(From, To) == Adding;
return false;
}

void Sema::CheckImplicitConversion(Expr *E, QualType T, SourceLocation CC,
Expand Down
11 changes: 4 additions & 7 deletions clang/lib/Sema/SemaOverload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2532,15 +2532,12 @@ static bool IsStandardConversion(Sema &S, Expr* From, QualType ToType,

SCS.setToType(2, FromType);

// If we have not converted the argument type to the parameter type,
// this is a bad conversion sequence, unless we're resolving an overload in C.
//
// Permit conversions from a function without `cfi_unchecked_callee` to a
// function with `cfi_unchecked_callee`.
if (CanonFrom == CanonTo || S.AddingCFIUncheckedCallee(CanonFrom, CanonTo))
if (CanonFrom == CanonTo)
return true;

if ((S.getLangOpts().CPlusPlus || !InOverloadResolution))
// If we have not converted the argument type to the parameter type,
// this is a bad conversion sequence, unless we're resolving an overload in C.
if (S.getLangOpts().CPlusPlus || !InOverloadResolution)
return false;

ExprResult ER = ExprResult{From};
Expand Down
1 change: 1 addition & 0 deletions clang/test/Frontend/cfi-unchecked-callee-attribute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ void (*checked_ptr)(void) = unchecked; // expected-warning{{implicit conversion
void (CFI_UNCHECKED_CALLEE *unchecked_ptr)(void) = unchecked;
void (CFI_UNCHECKED_CALLEE *from_normal)(void) = checked;
void (CFI_UNCHECKED_CALLEE *c_no_function_decay)(void) = &unchecked;
void (CFI_UNCHECKED_CALLEE __attribute__((noreturn)) *other_conflict)(void) = &checked; // expected-error{{cannot initialize a variable of type 'void (*)() __attribute__((noreturn)) __attribute__((cfi_unchecked_callee))' with an rvalue of type 'void (*)()'}}
void (CFI_UNCHECKED_CALLEE *arr[10])(void);
void (*cfi_elem)(void) = arr[1]; // expected-warning{{implicit conversion from 'void (*)() __attribute__((cfi_unchecked_callee))' to 'void (*)()' discards 'cfi_unchecked_callee' attribute}}
void (CFI_UNCHECKED_CALLEE *cfi_unchecked_elem)(void) = arr[1];
Expand Down