https://github.com/mizvekov created 
https://github.com/llvm/llvm-project/pull/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 https://github.com/llvm/llvm-project/pull/147835, 
but that PR adds another way to reproduce it.

>From 489383e2a500812894f0714cbcb30d8d3289147d Mon Sep 17 00:00:00 2001
From: Matheus Izvekov <mizve...@gmail.com>
Date: Wed, 10 Sep 2025 15:26:53 -0300
Subject: [PATCH] [clang] fix incorrect assumption about function type 's
 ExtInfo

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 https://github.com/llvm/llvm-project/pull/147835,
but that PR adds another way to reproduce it.
---
 clang/docs/ReleaseNotes.rst               |  3 +++
 clang/lib/AST/ASTContext.cpp              |  6 +++++-
 clang/test/SemaCXX/sugar-common-types.cpp | 24 +++++++++++++++++++++++
 3 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index a20b1ab298f9c..c0e3fafc379c6 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -350,6 +350,9 @@ Bug Fixes to C++ Support
   authentication enabled. (#GH152601)
 - Fix the check for narrowing int-to-float conversions, so that they are 
detected in
   cases where converting the float back to an integer is undefined behaviour 
(#GH157067).
+- Fix a crash when applying binary or ternary operators to two same function 
types with different spellings,
+  where at least one of the function parameters has an attribute which affects
+  the function type.
 - Fix an assertion failure when a ``constexpr`` variable is only referenced 
through
   ``__builtin_addressof``, and related issues with builtin arguments. 
(#GH154034)
 
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index c04de4e132739..ed4c6b0e38be3 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -14195,7 +14195,11 @@ static QualType getCommonNonSugarTypeNode(const 
ASTContext &Ctx, const Type *X,
     FunctionProtoType::ExtProtoInfo EPIX = FX->getExtProtoInfo(),
                                     EPIY = FY->getExtProtoInfo();
     assert(EPIX.ExtInfo == EPIY.ExtInfo);
-    assert(EPIX.ExtParameterInfos == EPIY.ExtParameterInfos);
+    assert(!EPIX.ExtParameterInfos == !EPIY.ExtParameterInfos);
+    assert(!EPIX.ExtParameterInfos ||
+           llvm::equal(
+               llvm::ArrayRef(EPIX.ExtParameterInfos, FX->getNumParams()),
+               llvm::ArrayRef(EPIY.ExtParameterInfos, FY->getNumParams())));
     assert(EPIX.RefQualifier == EPIY.RefQualifier);
     assert(EPIX.TypeQuals == EPIY.TypeQuals);
     assert(EPIX.Variadic == EPIY.Variadic);
diff --git a/clang/test/SemaCXX/sugar-common-types.cpp 
b/clang/test/SemaCXX/sugar-common-types.cpp
index dd5fc4a654795..4db0d2ac2f2ae 100644
--- a/clang/test/SemaCXX/sugar-common-types.cpp
+++ b/clang/test/SemaCXX/sugar-common-types.cpp
@@ -203,3 +203,27 @@ namespace member_pointers {
   N t3 = 0 ? &W1::a : &W2::b;
   // expected-error@-1 {{rvalue of type 'B1 member_pointers::W<void>::*'}}
 } // namespace member_pointers
+
+namespace FunctionTypeExtInfo {
+  namespace RecordType {
+    class A;
+    void (*x)(__attribute__((swift_async_context)) A *);
+
+    class A;
+    void (*y)(__attribute__((swift_async_context)) A *);
+
+    N t1 = 0 ? x : y;
+    // expected-error@-1 {{lvalue of type 'void 
(*)(__attribute__((swift_async_context)) A *)'}}
+  } // namespace RecordType
+  namespace TypedefType {
+    class A;
+    using B = A;
+    void (*x)(__attribute__((swift_async_context)) B *);
+
+    using B = A;
+    void (*y)(__attribute__((swift_async_context)) B *);
+
+    N t1 = 0 ? x : y;
+    // expected-error@-1 {{lvalue of type 'void 
(*)(__attribute__((swift_async_context)) B *)'}}
+  } // namespace TypedefType
+} // namespace FunctionTypeExtInfo

_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to