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-attr output arguments in dependent contexts #9767

Open
wants to merge 1 commit into
base: stable/20240723
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions clang/lib/Sema/SemaExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "clang/AST/CXXInheritance.h"
#include "clang/AST/DeclObjC.h"
#include "clang/AST/DeclTemplate.h"
#include "clang/AST/DependenceFlags.h"
#include "clang/AST/EvaluatedExprVisitor.h"
#include "clang/AST/Expr.h"
#include "clang/AST/ExprCXX.h"
Expand Down Expand Up @@ -8251,7 +8252,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() &&
Expand Down Expand Up @@ -8822,7 +8823,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.
if (TheCall->getDependence() == ExprDependence::None &&
!checkDynamicCountPointerAsParameter(*this, FDecl, TheCall))
return ExprError();
if (getLangOpts().BoundsSafety)
if (!checkDynamicRangePointerAsParameter(*this, FDecl, TheCall))
Expand Down Expand Up @@ -26016,4 +26020,4 @@ ExprResult Sema::ActOnUnsafeTerminatedByFromIndexable(
PointerToTerminatorExpr, BuiltinLoc,
RParenLoc);
}
/* TO_UPSTREAM(BoundsSafety) OFF*/
/* TO_UPSTREAM(BoundsSafety) OFF*/
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
};

// 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}}
}