Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Run clang-format
  • Loading branch information
Endilll committed May 18, 2024
commit 55757c3bf14e774e8d7ed0c2931daa4e97604e2a
3 changes: 1 addition & 2 deletions clang/include/clang/Sema/SemaAccess.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,7 @@ class SemaAccess : public SemaBase {
SourceLocation Loc,
const PartialDiagnostic &Diag);
bool isMemberAccessibleForDeletion(CXXRecordDecl *NamingClass,
DeclAccessPair Found,
QualType ObjectType);
DeclAccessPair Found, QualType ObjectType);

void HandleDependentAccessCheck(
const DependentDiagnostic &DD,
Expand Down
198 changes: 100 additions & 98 deletions clang/lib/Sema/SemaAccess.cpp

Large diffs are not rendered by default.

18 changes: 8 additions & 10 deletions clang/lib/Sema/SemaCast.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1736,13 +1736,12 @@ TryStaticDowncast(Sema &Self, CanQualType SrcType, CanQualType DestType,
}

if (!CStyle) {
switch (Self.Access().CheckBaseClassAccess(OpRange.getBegin(),
SrcType, DestType,
Paths.front(),
diag::err_downcast_from_inaccessible_base)) {
switch (Self.Access().CheckBaseClassAccess(
OpRange.getBegin(), SrcType, DestType, Paths.front(),
diag::err_downcast_from_inaccessible_base)) {
case SemaAccess::AR_accessible:
case SemaAccess::AR_delayed: // be optimistic
case SemaAccess::AR_dependent: // be optimistic
case SemaAccess::AR_delayed: // be optimistic
case SemaAccess::AR_dependent: // be optimistic
break;

case SemaAccess::AR_inaccessible:
Expand Down Expand Up @@ -1835,10 +1834,9 @@ TryStaticMemberPointerUpcast(Sema &Self, ExprResult &SrcExpr, QualType SrcType,
}

if (!CStyle) {
switch (Self.Access().CheckBaseClassAccess(OpRange.getBegin(),
DestClass, SrcClass,
Paths.front(),
diag::err_upcast_to_inaccessible_base)) {
switch (Self.Access().CheckBaseClassAccess(
OpRange.getBegin(), DestClass, SrcClass, Paths.front(),
diag::err_upcast_to_inaccessible_base)) {
case SemaAccess::AR_accessible:
case SemaAccess::AR_delayed:
case SemaAccess::AR_dependent:
Expand Down
3 changes: 2 additions & 1 deletion clang/lib/Sema/SemaCodeComplete.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1779,7 +1779,8 @@ class CodeCompletionDeclConsumer : public VisibleDeclConsumer {
NamingClass = nullptr;
BaseType = QualType();
}
return Results.getSema().Access().IsSimplyAccessible(ND, NamingClass, BaseType);
return Results.getSema().Access().IsSimplyAccessible(ND, NamingClass,
BaseType);
}
};
} // namespace
Expand Down
29 changes: 15 additions & 14 deletions clang/lib/Sema/SemaDeclCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1419,7 +1419,8 @@ static DeclAccessPair findDecomposableBaseClass(Sema &S, SourceLocation Loc,

// ... [accessible, implied by other rules] base class of E.
S.Access().CheckBaseClassAccess(Loc, BaseType, S.Context.getRecordType(RD),
*BestPath, diag::err_decomp_decl_inaccessible_base);
*BestPath,
diag::err_decomp_decl_inaccessible_base);
AS = BestPath->Access;

ClassWithFields = BaseType->getAsCXXRecordDecl();
Expand Down Expand Up @@ -3167,8 +3168,8 @@ Sema::CheckDerivedToBaseConversion(QualType Derived, QualType Base,
if (Path) {
if (!IgnoreAccess) {
// Check that the base class can be accessed.
switch (
Access().CheckBaseClassAccess(Loc, Base, Derived, *Path, InaccessibleBaseID)) {
switch (Access().CheckBaseClassAccess(Loc, Base, Derived, *Path,
InaccessibleBaseID)) {
case SemaAccess::AR_inaccessible:
return true;
case SemaAccess::AR_accessible:
Expand Down Expand Up @@ -5906,9 +5907,8 @@ Sema::MarkBaseAndMemberDestructorsReferenced(SourceLocation Location,
if (!Dtor)
continue;
Access().CheckDestructorAccess(Field->getLocation(), Dtor,
PDiag(diag::err_access_dtor_field)
<< Field->getDeclName()
<< FieldType);
PDiag(diag::err_access_dtor_field)
<< Field->getDeclName() << FieldType);

MarkFunctionReferenced(Location, Dtor);
DiagnoseUseOfDecl(Dtor, Location);
Expand Down Expand Up @@ -5956,9 +5956,10 @@ Sema::MarkBaseAndMemberDestructorsReferenced(SourceLocation Location,

// FIXME: caret should be on the start of the class name
Access().CheckDestructorAccess(Base.getBeginLoc(), Dtor,
PDiag(diag::err_access_dtor_base)
<< Base.getType() << Base.getSourceRange(),
Context.getTypeDeclType(ClassDecl));
PDiag(diag::err_access_dtor_base)
<< Base.getType()
<< Base.getSourceRange(),
Context.getTypeDeclType(ClassDecl));

MarkFunctionReferenced(Location, Dtor);
DiagnoseUseOfDecl(Dtor, Location);
Expand Down Expand Up @@ -5996,8 +5997,7 @@ void Sema::MarkVirtualBaseDestructorsReferenced(
ClassDecl->getLocation(), Dtor,
PDiag(diag::err_access_dtor_vbase)
<< Context.getTypeDeclType(ClassDecl) << VBase.getType(),
Context.getTypeDeclType(ClassDecl)) ==
SemaAccess::AR_accessible) {
Context.getTypeDeclType(ClassDecl)) == SemaAccess::AR_accessible) {
CheckDerivedToBaseConversion(
Context.getTypeDeclType(ClassDecl), VBase.getType(),
diag::err_access_dtor_vbase, 0, ClassDecl->getLocation(),
Expand Down Expand Up @@ -16236,8 +16236,8 @@ void Sema::FinalizeVarWithDestructor(VarDecl *VD, const RecordType *Record) {
if (!VD->getType()->isArrayType()) {
MarkFunctionReferenced(VD->getLocation(), Destructor);
Access().CheckDestructorAccess(VD->getLocation(), Destructor,
PDiag(diag::err_access_dtor_var)
<< VD->getDeclName() << VD->getType());
PDiag(diag::err_access_dtor_var)
<< VD->getDeclName() << VD->getType());
DiagnoseUseOfDecl(Destructor, VD->getLocation());
}

Expand Down Expand Up @@ -18101,7 +18101,8 @@ NamedDecl *Sema::ActOnFriendFunctionDecl(Scope *S, Declarator &D,
if (ND->isInvalidDecl()) {
FrD->setInvalidDecl();
} else {
if (DC->isRecord()) Access().CheckFriendAccess(ND);
if (DC->isRecord())
Access().CheckFriendAccess(ND);

FunctionDecl *FD;
if (FunctionTemplateDecl *FTD = dyn_cast<FunctionTemplateDecl>(ND))
Expand Down
18 changes: 10 additions & 8 deletions clang/lib/Sema/SemaExceptionSpec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
//
//===----------------------------------------------------------------------===//

#include "clang/Sema/SemaInternal.h"
#include "clang/AST/ASTMutationListener.h"
#include "clang/AST/CXXInheritance.h"
#include "clang/AST/Expr.h"
Expand All @@ -20,6 +19,7 @@
#include "clang/Basic/Diagnostic.h"
#include "clang/Basic/SourceManager.h"
#include "clang/Sema/SemaAccess.h"
#include "clang/Sema/SemaInternal.h"
#include "llvm/ADT/SmallPtrSet.h"
#include "llvm/ADT/SmallString.h"
#include <optional>
Expand Down Expand Up @@ -753,13 +753,15 @@ bool Sema::handlerCanCatch(QualType HandlerType, QualType ExceptionType) {
return false;

// Do this check from a context without privileges.
switch (Access().CheckBaseClassAccess(SourceLocation(), HandlerType, ExceptionType,
Paths.front(),
/*Diagnostic*/ 0,
/*ForceCheck*/ true,
/*ForceUnprivileged*/ true)) {
case SemaAccess::AR_accessible: return true;
case SemaAccess::AR_inaccessible: return false;
switch (Access().CheckBaseClassAccess(SourceLocation(), HandlerType,
ExceptionType, Paths.front(),
/*Diagnostic*/ 0,
/*ForceCheck*/ true,
/*ForceUnprivileged*/ true)) {
case SemaAccess::AR_accessible:
return true;
case SemaAccess::AR_inaccessible:
return false;
case SemaAccess::AR_dependent:
llvm_unreachable("access check dependent for unprivileged context");
case SemaAccess::AR_delayed:
Expand Down
36 changes: 21 additions & 15 deletions clang/lib/Sema/SemaExprCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1046,7 +1046,8 @@ bool Sema::CheckCXXThrowOperand(SourceLocation ThrowLoc,
if (CXXDestructorDecl *Destructor = LookupDestructor(RD)) {
MarkFunctionReferenced(E->getExprLoc(), Destructor);
Access().CheckDestructorAccess(E->getExprLoc(), Destructor,
PDiag(diag::err_access_dtor_exception) << Ty);
PDiag(diag::err_access_dtor_exception)
<< Ty);
if (DiagnoseUseOfDecl(Destructor, E->getExprLoc()))
return true;
}
Expand Down Expand Up @@ -2616,8 +2617,9 @@ static bool resolveAllocationOverload(
case OR_Success: {
// Got one!
FunctionDecl *FnDecl = Best->Function;
if (S.Access().CheckAllocationAccess(R.getNameLoc(), Range, R.getNamingClass(),
Best->FoundDecl) == SemaAccess::AR_inaccessible)
if (S.Access().CheckAllocationAccess(R.getNameLoc(), Range,
R.getNamingClass(), Best->FoundDecl) ==
SemaAccess::AR_inaccessible)
return true;

Operator = FnDecl;
Expand Down Expand Up @@ -3023,8 +3025,8 @@ bool Sema::FindAllocationFunctions(SourceLocation StartLoc, SourceRange Range,
}
}

Access().CheckAllocationAccess(StartLoc, Range, FoundDelete.getNamingClass(),
Matches[0].first);
Access().CheckAllocationAccess(
StartLoc, Range, FoundDelete.getNamingClass(), Matches[0].first);
} else if (!Matches.empty()) {
// We found multiple suitable operators. Per [expr.new]p20, that means we
// call no 'operator delete' function, but we should at least warn the user.
Expand Down Expand Up @@ -3382,8 +3384,9 @@ bool Sema::FindDeallocationFunction(SourceLocation StartLoc, CXXRecordDecl *RD,
return true;
}

if (Access().CheckAllocationAccess(StartLoc, SourceRange(), Found.getNamingClass(),
Matches[0].Found, Diagnose) == SemaAccess::AR_inaccessible)
if (Access().CheckAllocationAccess(StartLoc, SourceRange(),
Found.getNamingClass(), Matches[0].Found,
Diagnose) == SemaAccess::AR_inaccessible)
return true;

return false;
Expand Down Expand Up @@ -3869,7 +3872,8 @@ Sema::ActOnCXXDelete(SourceLocation StartLoc, bool UseGlobal,
if (PointeeRD) {
if (CXXDestructorDecl *Dtor = LookupDestructor(PointeeRD)) {
Access().CheckDestructorAccess(Ex.get()->getExprLoc(), Dtor,
PDiag(diag::err_access_dtor) << PointeeElem);
PDiag(diag::err_access_dtor)
<< PointeeElem);
IsVirtualDelete = Dtor->isVirtual();
}
}
Expand Down Expand Up @@ -4217,8 +4221,9 @@ static ExprResult BuildCXXCastArgument(Sema &S,
ConstructorArgs))
return ExprError();

S.Access().CheckConstructorAccess(CastLoc, Constructor, FoundDecl,
InitializedEntity::InitializeTemporary(Ty));
S.Access().CheckConstructorAccess(
CastLoc, Constructor, FoundDecl,
InitializedEntity::InitializeTemporary(Ty));
if (S.DiagnoseUseOfDecl(Method, CastLoc))
return ExprError();

Expand All @@ -4236,7 +4241,8 @@ static ExprResult BuildCXXCastArgument(Sema &S,
case CK_UserDefinedConversion: {
assert(!From->getType()->isPointerType() && "Arg can't have pointer type!");

S.Access().CheckMemberOperatorAccess(CastLoc, From, /*arg*/ nullptr, FoundDecl);
S.Access().CheckMemberOperatorAccess(CastLoc, From, /*arg*/ nullptr,
FoundDecl);
if (S.DiagnoseUseOfDecl(Method, CastLoc))
return ExprError();

Expand Down Expand Up @@ -7648,8 +7654,8 @@ ExprResult Sema::MaybeBindToTemporary(Expr *E) {
if (Destructor) {
MarkFunctionReferenced(E->getExprLoc(), Destructor);
Access().CheckDestructorAccess(E->getExprLoc(), Destructor,
PDiag(diag::err_access_dtor_temp)
<< E->getType());
PDiag(diag::err_access_dtor_temp)
<< E->getType());
if (DiagnoseUseOfDecl(Destructor, E->getExprLoc()))
return ExprError();

Expand Down Expand Up @@ -7819,8 +7825,8 @@ ExprResult Sema::ActOnDecltypeExpression(Expr *E) {

MarkFunctionReferenced(Bind->getExprLoc(), Destructor);
Access().CheckDestructorAccess(Bind->getExprLoc(), Destructor,
PDiag(diag::err_access_dtor_temp)
<< Bind->getType());
PDiag(diag::err_access_dtor_temp)
<< Bind->getType());
if (DiagnoseUseOfDecl(Destructor, Bind->getExprLoc()))
return ExprError();

Expand Down
32 changes: 18 additions & 14 deletions clang/lib/Sema/SemaInit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1932,9 +1932,9 @@ static bool checkDestructorReference(QualType ElementType, SourceLocation Loc,
return false;

CXXDestructorDecl *Destructor = SemaRef.LookupDestructor(CXXRD);
SemaRef.Access().CheckDestructorAccess(Loc, Destructor,
SemaRef.PDiag(diag::err_access_dtor_temp)
<< ElementType);
SemaRef.Access().CheckDestructorAccess(
Loc, Destructor,
SemaRef.PDiag(diag::err_access_dtor_temp) << ElementType);
SemaRef.MarkFunctionReferenced(Loc, Destructor);
return SemaRef.DiagnoseUseOfDecl(Destructor, Loc);
}
Expand Down Expand Up @@ -6860,7 +6860,7 @@ static ExprResult CopyObject(Sema &S,
CurInit.get(); // Ownership transferred into MultiExprArg, below.

S.Access().CheckConstructorAccess(Loc, Constructor, Best->FoundDecl, Entity,
IsExtraneousCopy);
IsExtraneousCopy);

if (IsExtraneousCopy) {
// If this is a totally extraneous copy for C++03 reference
Expand Down Expand Up @@ -6970,8 +6970,9 @@ static void CheckCXX98CompatAccessibleCopy(Sema &S,

switch (OR) {
case OR_Success:
S.Access().CheckConstructorAccess(Loc, cast<CXXConstructorDecl>(Best->Function),
Best->FoundDecl, Entity, Diag);
S.Access().CheckConstructorAccess(Loc,
cast<CXXConstructorDecl>(Best->Function),
Best->FoundDecl, Entity, Diag);
// FIXME: Check default arguments as far as that's possible.
break;

Expand Down Expand Up @@ -7173,7 +7174,8 @@ PerformConstructorInitialization(Sema &S,
return ExprError();

// Only check access if all of that succeeded.
S.Access().CheckConstructorAccess(Loc, Constructor, Step.Function.FoundDecl, Entity);
S.Access().CheckConstructorAccess(Loc, Constructor, Step.Function.FoundDecl,
Entity);
if (S.DiagnoseUseOfDecl(Step.Function.FoundDecl, Loc))
return ExprError();

Expand Down Expand Up @@ -8824,7 +8826,8 @@ ExprResult InitializationSequence::Perform(Sema &S,
case SK_ResolveAddressOfOverloadedFunction:
// Overload resolution determined which function invoke; update the
// initializer to reflect that choice.
S.Access().CheckAddressOfMemberAccess(CurInit.get(), Step->Function.FoundDecl);
S.Access().CheckAddressOfMemberAccess(CurInit.get(),
Step->Function.FoundDecl);
if (S.DiagnoseUseOfDecl(Step->Function.FoundDecl, Kind.getLocation()))
return ExprError();
CurInit = S.FixOverloadedFunctionReference(CurInit,
Expand Down Expand Up @@ -8969,8 +8972,8 @@ ExprResult InitializationSequence::Perform(Sema &S,
if (CurInit.isInvalid())
return ExprError();

S.Access().CheckConstructorAccess(Kind.getLocation(), Constructor, FoundFn,
Entity);
S.Access().CheckConstructorAccess(Kind.getLocation(), Constructor,
FoundFn, Entity);
if (S.DiagnoseUseOfDecl(FoundFn, Kind.getLocation()))
return ExprError();

Expand All @@ -8979,8 +8982,8 @@ ExprResult InitializationSequence::Perform(Sema &S,
} else {
// Build a call to the conversion function.
CXXConversionDecl *Conversion = cast<CXXConversionDecl>(Fn);
S.Access().CheckMemberOperatorAccess(Kind.getLocation(), CurInit.get(), nullptr,
FoundFn);
S.Access().CheckMemberOperatorAccess(Kind.getLocation(), CurInit.get(),
nullptr, FoundFn);
if (S.DiagnoseUseOfDecl(FoundFn, Kind.getLocation()))
return ExprError();

Expand Down Expand Up @@ -9013,8 +9016,9 @@ ExprResult InitializationSequence::Perform(Sema &S,
if (const RecordType *Record = T->getAs<RecordType>()) {
CXXDestructorDecl *Destructor
= S.LookupDestructor(cast<CXXRecordDecl>(Record->getDecl()));
S.Access().CheckDestructorAccess(CurInit.get()->getBeginLoc(), Destructor,
S.PDiag(diag::err_access_dtor_temp) << T);
S.Access().CheckDestructorAccess(
CurInit.get()->getBeginLoc(), Destructor,
S.PDiag(diag::err_access_dtor_temp) << T);
S.MarkFunctionReferenced(CurInit.get()->getBeginLoc(), Destructor);
if (S.DiagnoseUseOfDecl(Destructor, CurInit.get()->getBeginLoc()))
return ExprError();
Expand Down
8 changes: 4 additions & 4 deletions clang/lib/Sema/SemaLookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4885,10 +4885,10 @@ void TypoCorrectionConsumer::performQualifiedLookups() {
}
for (LookupResult::iterator TRD = Result.begin(), TRDEnd = Result.end();
TRD != TRDEnd; ++TRD) {
if (SemaRef.Access().CheckMemberAccess(TC.getCorrectionRange().getBegin(),
NSType ? NSType->getAsCXXRecordDecl()
: nullptr,
TRD.getPair()) == SemaAccess::AR_accessible)
if (SemaRef.Access().CheckMemberAccess(
TC.getCorrectionRange().getBegin(),
NSType ? NSType->getAsCXXRecordDecl() : nullptr,
TRD.getPair()) == SemaAccess::AR_accessible)
TC.addCorrectionDecl(*TRD);
}
if (TC.isResolved()) {
Expand Down
Loading