Skip to content
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

[BoundsSafety] Do not check for bounds-attributed output arguments in dependent contexts #9733

Merged
merged 1 commit into from
Dec 19, 2024

Conversation

ziqingluo-90
Copy link

@ziqingluo-90 ziqingluo-90 commented Dec 12, 2024

The bounds-attribute-only mode may be applied to C++ programs, where attributed functions/fields can be used in dependent contexts such as a template. We DO NOT want the type check at those places. Their instantiations will still be checked.

Note: bounds-attributed output arguments are the only ones being type checked in the attribute-only mode.

(rdar://140895392)
(rdar://141708643) // <- feel like better have a new radar for this issue

@ziqingluo-90
Copy link
Author

@swift-ci test

1 similar comment
@ziqingluo-90
Copy link
Author

@swift-ci test


template<typename T>
struct S {
void f(T p) {
g(sizeof(p));
g(nullptr, sizeof(p));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we certain this still exercises the same path as caused the crash previously, or should we keep the old function and add another?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The old one was testing for no type checking in a dependent context, if there is no bounds attribute. Now we are testing that the same path will not be reached under a stronger condition, i.e., no type checking in a dependent context.

So the new test is stronger and covers the old one after the change of this PR.

@@ -8332,7 +8332,7 @@ static bool checkDynamicCountPointerAsParameter(Sema &S, FunctionDecl *FDecl,
if (!ArgInfo.isCountInParamOrCountPointer() && !ArgInfo.isCountInRet() &&
!ParmInfo.isCountInParamOrCountPointer() && !ParmInfo.isCountInRet())
continue;
assert(!ActualArgExp->isValueDependent());

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is is it still necessary to remove this, despite checking !TheCall->getDependence() before calling checkDynamicCountPointerAsParameter? Or is this something else?

Copy link
Author

@ziqingluo-90 ziqingluo-90 Dec 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

!TheCall->getDependence() implies no argument isValueDependent(). So I think that assertion becomes unreachable.

This is where I got the sense that Call->getDependence() includes dependence info of its arguments:
https://github.com/llvm/llvm-project/blob/2916352936097a35cdcaaf38a9097465adbf8cf5/clang/lib/AST/ComputeDependence.cpp#L642C1-L654C2

if (!checkDynamicCountPointerAsParameter(*this, FDecl, TheCall))
if (!TheCall // Attr-only mode may be applied to C++ but we
->getDependence() // don't want to check for any dependent
// constructs

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Maybe instead of casting enum to bool, we could be explicit TheCall->getDependence() == ExprDependence::None? We could also move the comment before if.

@ziqingluo-90
Copy link
Author

@swift-ci test

@@ -8903,7 +8904,11 @@ ExprResult Sema::BuildResolvedCallExpr(Expr *Fn, NamedDecl *NDecl,
if (getLangOpts().BoundsSafetyAttributes && FDecl) {
// FIXME: We need to support function pointers and blocks that don't have
// function decl.
if (!checkDynamicCountPointerAsParameter(*this, FDecl, TheCall))

// Attr-only mode may be applied to C++ but we don't want to check for any
Copy link

@rapidsna rapidsna Dec 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: "For C++, we don't want to check for any dependent constructs."

…dent contexts

The bounds-attribute-only mode may be applied to C++ programs, where
attributed functions/fields may be used in dependent contexts such as
a template.  DO NOT type check at those places.  Their instantiations
will still be checked.

(rdar://141708643)
@ziqingluo-90 ziqingluo-90 merged commit d4329b6 into swiftlang:next Dec 19, 2024
@ziqingluo-90 ziqingluo-90 deleted the eng/PR-140895392-2 branch December 19, 2024 23:08
ziqingluo-90 added a commit to ziqingluo-90/apple-llvm-project that referenced this pull request Dec 19, 2024
…dent contexts (swiftlang#9733)

The bounds-attribute-only mode may be applied to C++ programs, where
attributed functions/fields may be used in dependent contexts such as
a template.  DO NOT type check at those places.  Their instantiations
will still be checked.

(rdar://141708643)

(cherry picked from commit d4329b6)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants