Skip to content

Commit 6a581f7

Browse files
authored
[clang] fix incorrect assumption about function type 's ExtInfo (#157925)
This fixes an assumption that the ExtInfo for two same function types would have referential equality. This should compare these ExtInfos by value instead. The bug is pre-existing to #147835, but that PR adds another way to reproduce it.
1 parent 9e778f6 commit 6a581f7

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,9 @@ Bug Fixes to C++ Support
350350
authentication enabled. (#GH152601)
351351
- Fix the check for narrowing int-to-float conversions, so that they are detected in
352352
cases where converting the float back to an integer is undefined behaviour (#GH157067).
353+
- Fix a crash when applying binary or ternary operators to two same function types with different spellings,
354+
where at least one of the function parameters has an attribute which affects
355+
the function type.
353356
- Fix an assertion failure when a ``constexpr`` variable is only referenced through
354357
``__builtin_addressof``, and related issues with builtin arguments. (#GH154034)
355358

clang/lib/AST/ASTContext.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14195,7 +14195,11 @@ static QualType getCommonNonSugarTypeNode(const ASTContext &Ctx, const Type *X,
1419514195
FunctionProtoType::ExtProtoInfo EPIX = FX->getExtProtoInfo(),
1419614196
EPIY = FY->getExtProtoInfo();
1419714197
assert(EPIX.ExtInfo == EPIY.ExtInfo);
14198-
assert(EPIX.ExtParameterInfos == EPIY.ExtParameterInfos);
14198+
assert(!EPIX.ExtParameterInfos == !EPIY.ExtParameterInfos);
14199+
assert(!EPIX.ExtParameterInfos ||
14200+
llvm::equal(
14201+
llvm::ArrayRef(EPIX.ExtParameterInfos, FX->getNumParams()),
14202+
llvm::ArrayRef(EPIY.ExtParameterInfos, FY->getNumParams())));
1419914203
assert(EPIX.RefQualifier == EPIY.RefQualifier);
1420014204
assert(EPIX.TypeQuals == EPIY.TypeQuals);
1420114205
assert(EPIX.Variadic == EPIY.Variadic);

clang/test/SemaCXX/sugar-common-types.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,3 +203,27 @@ namespace member_pointers {
203203
N t3 = 0 ? &W1::a : &W2::b;
204204
// expected-error@-1 {{rvalue of type 'B1 member_pointers::W<void>::*'}}
205205
} // namespace member_pointers
206+
207+
namespace FunctionTypeExtInfo {
208+
namespace RecordType {
209+
class A;
210+
void (*x)(__attribute__((swift_async_context)) A *);
211+
212+
class A;
213+
void (*y)(__attribute__((swift_async_context)) A *);
214+
215+
N t1 = 0 ? x : y;
216+
// expected-error@-1 {{lvalue of type 'void (*)(__attribute__((swift_async_context)) A *)'}}
217+
} // namespace RecordType
218+
namespace TypedefType {
219+
class A;
220+
using B = A;
221+
void (*x)(__attribute__((swift_async_context)) B *);
222+
223+
using B = A;
224+
void (*y)(__attribute__((swift_async_context)) B *);
225+
226+
N t1 = 0 ? x : y;
227+
// expected-error@-1 {{lvalue of type 'void (*)(__attribute__((swift_async_context)) B *)'}}
228+
} // namespace TypedefType
229+
} // namespace FunctionTypeExtInfo

0 commit comments

Comments
 (0)