Introduce a new OpaquePtr<N> struct type, which is a simple POD wrapper for a
pointer. Its purpose in life is to be a glorified void*, but which does not
implicitly convert to void* or other OpaquePtr's with a different UID.
Introduce Action::DeclPtrTy which is a typedef for OpaquePtr<0>. Change the
entire parser/sema interface to use DeclPtrTy instead of DeclTy*. This
makes the C++ compiler enforce that these aren't convertible to other opaque
types.
We should also convert ExprTy, StmtTy, TypeTy, AttrTy, BaseTy, etc,
but I don't plan to do that in the short term.
The one outstanding known problem with this patch is that we lose the
bitmangling optimization where ActionResult<DeclPtrTy> doesn't know how to
bitmangle the success bit into the low bit of DeclPtrTy. I will rectify
this with a subsequent patch.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67952 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index 0a77c21..39d2a50 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -876,7 +876,7 @@
Scope *CheckS = S;
while (CheckS) {
if (CheckS->isWithinElse() &&
- CheckS->getControlParent()->isDeclScope(Var)) {
+ CheckS->getControlParent()->isDeclScope(DeclPtrTy::make(Var))) {
if (Var->getType()->isBooleanType())
ExprError(Diag(Loc, diag::warn_value_always_false)
<< Var->getDeclName());
@@ -1743,7 +1743,7 @@
Sema::ActOnMemberReferenceExpr(Scope *S, ExprArg Base, SourceLocation OpLoc,
tok::TokenKind OpKind, SourceLocation MemberLoc,
IdentifierInfo &Member,
- DeclTy *ObjCImpDecl) {
+ DeclPtrTy ObjCImpDecl) {
Expr *BaseExpr = static_cast<Expr *>(Base.release());
assert(BaseExpr && "no record expression");
@@ -1879,7 +1879,7 @@
// the context as argument to this routine. Ideally, this context need
// be passed down in the AST node and somehow calculated from the AST
// for a function decl.
- Decl *ImplDecl = static_cast<Decl *>(ObjCImpDecl);
+ Decl *ImplDecl = ObjCImpDecl.getAs<Decl>();
if (ObjCImplementationDecl *IMPD =
dyn_cast<ObjCImplementationDecl>(ImplDecl))
ClassOfMethodDecl = IMPD->getClassInterface();
@@ -4590,13 +4590,13 @@
// no arguments, not a function that takes a single void argument.
if (FTI.hasPrototype &&
FTI.NumArgs == 1 && !FTI.isVariadic && FTI.ArgInfo[0].Ident == 0 &&
- (!((ParmVarDecl *)FTI.ArgInfo[0].Param)->getType().getCVRQualifiers() &&
- ((ParmVarDecl *)FTI.ArgInfo[0].Param)->getType()->isVoidType())) {
+ (!FTI.ArgInfo[0].Param.getAs<ParmVarDecl>()->getType().getCVRQualifiers()&&
+ FTI.ArgInfo[0].Param.getAs<ParmVarDecl>()->getType()->isVoidType())) {
// empty arg list, don't push any params.
CurBlock->isVariadic = false;
} else if (FTI.hasPrototype) {
for (unsigned i = 0, e = FTI.NumArgs; i != e; ++i)
- CurBlock->Params.push_back((ParmVarDecl *)FTI.ArgInfo[i].Param);
+ CurBlock->Params.push_back(FTI.ArgInfo[i].Param.getAs<ParmVarDecl>());
CurBlock->isVariadic = FTI.isVariadic;
QualType T = GetTypeForDeclarator (ParamInfo, CurScope);