-
Notifications
You must be signed in to change notification settings - Fork 341
[BoundsSafety] Do not check for bounds-attributed output arguments in dependent contexts #9733
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ | |
#include "clang/AST/Decl.h" | ||
#include "clang/AST/DeclObjC.h" | ||
#include "clang/AST/DeclTemplate.h" | ||
#include "clang/AST/DependenceFlags.h" | ||
#include "clang/AST/DynamicRecursiveASTVisitor.h" | ||
#include "clang/AST/EvaluatedExprVisitor.h" | ||
#include "clang/AST/Expr.h" | ||
|
@@ -8332,7 +8333,7 @@ static bool checkDynamicCountPointerAsParameter(Sema &S, FunctionDecl *FDecl, | |
if (!ArgInfo.isCountInParamOrCountPointer() && !ArgInfo.isCountInRet() && | ||
!ParmInfo.isCountInParamOrCountPointer() && !ParmInfo.isCountInRet()) | ||
continue; | ||
assert(!ActualArgExp->isValueDependent()); | ||
|
||
// Disable these checks for attribute-only mode because we don't want | ||
// non-type-incompatibility errors in that mode. | ||
if (!S.getLangOpts().isBoundsSafetyAttributeOnlyMode() && | ||
|
@@ -8903,7 +8904,10 @@ 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)) | ||
|
||
// For C++, we don't want to check for any dependent constructs. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Maybe instead of casting enum to bool, we could be explicit There was a problem hiding this comment. Choose a reason for hiding this commentThe 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." |
||
if (TheCall->getDependence() == ExprDependence::None && | ||
!checkDynamicCountPointerAsParameter(*this, FDecl, TheCall)) | ||
return ExprError(); | ||
if (getLangOpts().BoundsSafety) | ||
if (!checkDynamicRangePointerAsParameter(*this, FDecl, TheCall)) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,12 +11,15 @@ class MyClass { | |
namespace value_dependent_assertion_violation { | ||
// Running attribute-only mode on the C++ code below crashes | ||
// previously. | ||
void g(unsigned); | ||
void g(int * __counted_by(n) * p, size_t n); | ||
|
||
template<typename T> | ||
struct S { | ||
void f(T p) { | ||
g(sizeof(p)); | ||
g(nullptr, sizeof(p)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
} | ||
}; | ||
|
||
// expected-error@-4{{incompatible dynamic count pointer argument to parameter of type 'int * __counted_by(n)*' (aka 'int **')}} | ||
template struct S<int>; // expected-note{{in instantiation of member function 'value_dependent_assertion_violation::S<int>::f' requested here}} | ||
} |
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.
Is is it still necessary to remove this, despite checking
!TheCall->getDependence()
before callingcheckDynamicCountPointerAsParameter
? Or is this something else?Uh oh!
There was an error while loading. Please reload this page.
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.
!TheCall->getDependence()
implies no argumentisValueDependent()
. 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