Skip to content

Commit 0c6f471

Browse files
committed
[clang][Sema] close IsStandardConversion hole when adding cfi_unchecked_callee
Commit b194cf1 changed this function for the case where attribute cfi_unchecked_callee is added in a function conversion. But this introduces a hole (issue #162798), and it seems the change was unnecessary: the preceding TryFunctionConversion will already allow adding the cfi_unchecked_callee attribute, and will update FromType if it succeeds. So we revert the changes to IsStandardConversion. Fixes: #162798
1 parent be2c6c1 commit 0c6f471

File tree

2 files changed

+5
-7
lines changed

2 files changed

+5
-7
lines changed

clang/lib/Sema/SemaOverload.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2532,15 +2532,12 @@ static bool IsStandardConversion(Sema &S, Expr* From, QualType ToType,
25322532

25332533
SCS.setToType(2, FromType);
25342534

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

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

25462543
ExprResult ER = ExprResult{From};

clang/test/Frontend/cfi-unchecked-callee-attribute.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ void (*checked_ptr)(void) = unchecked; // expected-warning{{implicit conversion
99
void (CFI_UNCHECKED_CALLEE *unchecked_ptr)(void) = unchecked;
1010
void (CFI_UNCHECKED_CALLEE *from_normal)(void) = checked;
1111
void (CFI_UNCHECKED_CALLEE *c_no_function_decay)(void) = &unchecked;
12+
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 (*)()'}}
1213
void (CFI_UNCHECKED_CALLEE *arr[10])(void);
1314
void (*cfi_elem)(void) = arr[1]; // expected-warning{{implicit conversion from 'void (*)() __attribute__((cfi_unchecked_callee))' to 'void (*)()' discards 'cfi_unchecked_callee' attribute}}
1415
void (CFI_UNCHECKED_CALLEE *cfi_unchecked_elem)(void) = arr[1];

0 commit comments

Comments
 (0)