-
Notifications
You must be signed in to change notification settings - Fork 342
[BoundsSafety] Do not merge param/return types if there is no need to #10873
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: next
Are you sure you want to change the base?
Conversation
@swift-ci test llvm |
@@ -4101,12 +4101,33 @@ static bool mergeFunctionDeclBoundsAttributes(FunctionDecl *New, | |||
} | |||
return MergeTy; | |||
}; | |||
|
|||
auto hasBoundsAttributesAtAnyLevel = [](QualType Ty) -> bool { | |||
while (Ty->isPointerType()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't remember if void foo(int arr[__counted_by(len)], int len);
decays to a pointer type immediately, or if the function declaration has a parameter with type CountAttributedType(IncompleteArrayType)
. Could you check that this function handles this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it walk through pointers enclosed by "Atomic" types?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't remember if
void foo(int arr[__counted_by(len)], int len);
decays to a pointer type immediately, or if the function declaration has a parameter with typeCountAttributedType(IncompleteArrayType)
. Could you check that this function handles this?
Yes, it does decay before this code is invoked. I added a test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it walk through pointers enclosed by "Atomic" types?
It does not. It shouldn't change the behavior, since ASTContext::mergeBoundsSafetyPointerTypes
does not walk through _Atomic
types too:
QualType ASTContext::mergeBoundsSafetyPointerTypes(
QualType DstTy, QualType SrcTy,
std::function<QualType(QualType /* DstTy */, QualType /* SrcTy */,
QualType /* MergePointeeTy */,
QualType /* OrigDstTy */)> &MergeFunctor,
QualType OrigDstTy) {
if (!DstTy->isPointerType())
return DstTy;
If pointers don't have any interesting attributes, there is no need to attempt to merge the types, and we can keep the type unchanged. This will let us keep the sugars used in the new declaration. rdar://153579566
e6621b4
to
a6c3623
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
If pointers don't have any interesting attributes, there is no need to attempt to merge the types, and we can keep the type unchanged. This will let us keep the sugars used in the new declaration.
rdar://153579566