Author: Joshua Haberman Date: 2021-03-22T14:13:42-07:00 New Revision: c3134d7c44f1059889dfee698dff415f7c2e1620
URL: https://github.com/llvm/llvm-project/commit/c3134d7c44f1059889dfee698dff415f7c2e1620 DIFF: https://github.com/llvm/llvm-project/commit/c3134d7c44f1059889dfee698dff415f7c2e1620.diff LOG: [clang] Replaced some manual pointer tagging with llvm::PointerIntPair. There is no functional change here (hence no new tests). The only change is to replace a couple uintptr_t members with llvm::PointerIntPair<> to clean up the code, making it more readable and less error prone. This cleanup highlighted that the old code was effectively casting away const. This is fixed by changing some function signatures. Reviewed By: rsmith Differential Revision: https://reviews.llvm.org/D98889 Added: Modified: clang/include/clang/Sema/Initialization.h clang/include/clang/Sema/Sema.h clang/lib/Sema/SemaDeclCXX.cpp clang/lib/Sema/SemaInit.cpp Removed: ################################################################################ diff --git a/clang/include/clang/Sema/Initialization.h b/clang/include/clang/Sema/Initialization.h index dcdfa3c3cf64..a764a36d3312 100644 --- a/clang/include/clang/Sema/Initialization.h +++ b/clang/include/clang/Sema/Initialization.h @@ -187,8 +187,8 @@ class alignas(8) InitializedEntity { ObjCMethodDecl *MethodDecl; /// When Kind == EK_Parameter, the ParmVarDecl, with the - /// low bit indicating whether the parameter is "consumed". - uintptr_t Parameter; + /// integer indicating whether the parameter is "consumed". + llvm::PointerIntPair<ParmVarDecl *, 1> Parameter; /// When Kind == EK_Temporary or EK_CompoundLiteralInit, the type /// source information for the temporary. @@ -197,9 +197,9 @@ class alignas(8) InitializedEntity { struct LN LocAndNRVO; /// When Kind == EK_Base, the base specifier that provides the - /// base class. The lower bit specifies whether the base is an inherited + /// base class. The integer specifies whether the base is an inherited /// virtual base. - uintptr_t Base; + llvm::PointerIntPair<const CXXBaseSpecifier *, 1> Base; /// When Kind == EK_ArrayElement, EK_VectorElement, or /// EK_ComplexElement, the index of the array or vector element being @@ -252,15 +252,14 @@ class alignas(8) InitializedEntity { /// Create the initialization entity for a parameter. static InitializedEntity InitializeParameter(ASTContext &Context, - const ParmVarDecl *Parm) { + ParmVarDecl *Parm) { return InitializeParameter(Context, Parm, Parm->getType()); } /// Create the initialization entity for a parameter, but use /// another type. - static InitializedEntity InitializeParameter(ASTContext &Context, - const ParmVarDecl *Parm, - QualType Type) { + static InitializedEntity + InitializeParameter(ASTContext &Context, ParmVarDecl *Parm, QualType Type) { bool Consumed = (Context.getLangOpts().ObjCAutoRefCount && Parm->hasAttr<NSConsumedAttr>()); @@ -269,8 +268,7 @@ class alignas(8) InitializedEntity { Entity.Type = Context.getVariableArrayDecayedType(Type.getUnqualifiedType()); Entity.Parent = nullptr; - Entity.Parameter - = (static_cast<uintptr_t>(Consumed) | reinterpret_cast<uintptr_t>(Parm)); + Entity.Parameter = {Parm, Consumed}; return Entity; } @@ -283,7 +281,7 @@ class alignas(8) InitializedEntity { Entity.Kind = EK_Parameter; Entity.Type = Context.getVariableArrayDecayedType(Type); Entity.Parent = nullptr; - Entity.Parameter = (Consumed); + Entity.Parameter = {nullptr, Consumed}; return Entity; } @@ -466,19 +464,19 @@ class alignas(8) InitializedEntity { /// parameter. bool isParameterConsumed() const { assert(isParameterKind() && "Not a parameter"); - return (Parameter & 1); + return Parameter.getInt(); } /// Retrieve the base specifier. const CXXBaseSpecifier *getBaseSpecifier() const { assert(getKind() == EK_Base && "Not a base specifier"); - return reinterpret_cast<const CXXBaseSpecifier *>(Base & ~0x1); + return Base.getPointer(); } /// Return whether the base is an inherited virtual base. bool isInheritedVirtualBase() const { assert(getKind() == EK_Base && "Not a base specifier"); - return Base & 0x1; + return Base.getInt(); } /// Determine whether this is an array new with an unknown bound. diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index 650b2061e314..efabc78b45ba 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -2702,8 +2702,7 @@ class Sema final { void ActOnParamUnparsedDefaultArgument(Decl *param, SourceLocation EqualLoc, SourceLocation ArgLoc); void ActOnParamDefaultArgumentError(Decl *param, SourceLocation EqualLoc); - ExprResult ConvertParamDefaultArgument(const ParmVarDecl *Param, - Expr *DefaultArg, + ExprResult ConvertParamDefaultArgument(ParmVarDecl *Param, Expr *DefaultArg, SourceLocation EqualLoc); void SetParamDefaultArgument(ParmVarDecl *Param, Expr *DefaultArg, SourceLocation EqualLoc); diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index 10f61d8c649e..8470fad39854 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -254,8 +254,7 @@ void Sema::ImplicitExceptionSpecification::CalledStmt(Stmt *S) { ComputedEST = EST_None; } -ExprResult Sema::ConvertParamDefaultArgument(const ParmVarDecl *Param, - Expr *Arg, +ExprResult Sema::ConvertParamDefaultArgument(ParmVarDecl *Param, Expr *Arg, SourceLocation EqualLoc) { if (RequireCompleteType(Param->getLocation(), Param->getType(), diag::err_typecheck_decl_incomplete_type)) diff --git a/clang/lib/Sema/SemaInit.cpp b/clang/lib/Sema/SemaInit.cpp index faf71baf3d1d..ec7e4722ea4e 100644 --- a/clang/lib/Sema/SemaInit.cpp +++ b/clang/lib/Sema/SemaInit.cpp @@ -24,6 +24,7 @@ #include "clang/Sema/Lookup.h" #include "clang/Sema/SemaInternal.h" #include "llvm/ADT/APInt.h" +#include "llvm/ADT/PointerIntPair.h" #include "llvm/ADT/SmallString.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/raw_ostream.h" @@ -3281,10 +3282,7 @@ InitializedEntity::InitializeBase(ASTContext &Context, InitializedEntity Result; Result.Kind = EK_Base; Result.Parent = Parent; - Result.Base = reinterpret_cast<uintptr_t>(Base); - if (IsInheritedVirtualBase) - Result.Base |= 0x01; - + Result.Base = {Base, IsInheritedVirtualBase}; Result.Type = Base->getType(); return Result; } @@ -3293,7 +3291,7 @@ DeclarationName InitializedEntity::getName() const { switch (getKind()) { case EK_Parameter: case EK_Parameter_CF_Audited: { - ParmVarDecl *D = reinterpret_cast<ParmVarDecl*>(Parameter & ~0x1); + ParmVarDecl *D = Parameter.getPointer(); return (D ? D->getDeclName() : DeclarationName()); } @@ -3336,7 +3334,7 @@ ValueDecl *InitializedEntity::getDecl() const { case EK_Parameter: case EK_Parameter_CF_Audited: - return reinterpret_cast<ParmVarDecl*>(Parameter & ~0x1); + return Parameter.getPointer(); case EK_Result: case EK_StmtExprResult: _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits