[clang] fix incorrect assumption about function type 's ExtInfo#157925
Merged
[clang] fix incorrect assumption about function type 's ExtInfo#157925
Conversation
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.
Member
|
@llvm/pr-subscribers-clang Author: Matheus Izvekov (mizvekov) ChangesThis 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. Full diff: https://github.com/llvm/llvm-project/pull/157925.diff 3 Files Affected:
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
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.