diff options
author | David Blaikie <dblaikie@gmail.com> | 2013-02-18 22:06:02 +0000 |
---|---|---|
committer | David Blaikie <dblaikie@gmail.com> | 2013-02-18 22:06:02 +0000 |
commit | 39e6ab4be93d9c5e729a578ddd9d415cd2d49872 (patch) | |
tree | fc9c9aad9c0b7b392ff2b08bb1d5df59c8d6c048 /lib/Sema/SemaTemplateInstantiate.cpp | |
parent | 9ba7627d25a7555b1afff04f685d2f161974e682 (diff) |
Replace TypeLoc llvm::cast support to be well-defined.
The TypeLoc hierarchy used the llvm::cast machinery to perform undefined
behavior by casting pointers/references to TypeLoc objects to derived types
and then using the derived copy constructors (or even returning pointers to
derived types that actually point to the original TypeLoc object).
Some context is in this thread:
http://lists.cs.uiuc.edu/pipermail/llvmdev/2012-December/056804.html
Though it's spread over a few months which can be hard to read in the mail
archive.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@175462 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaTemplateInstantiate.cpp')
-rw-r--r-- | lib/Sema/SemaTemplateInstantiate.cpp | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/lib/Sema/SemaTemplateInstantiate.cpp b/lib/Sema/SemaTemplateInstantiate.cpp index 04aa79b5fc..7363bc0fd9 100644 --- a/lib/Sema/SemaTemplateInstantiate.cpp +++ b/lib/Sema/SemaTemplateInstantiate.cpp @@ -1566,10 +1566,10 @@ static bool NeedsInstantiationAsFunctionType(TypeSourceInfo *T) { return true; TypeLoc TL = T->getTypeLoc().IgnoreParens(); - if (!isa<FunctionProtoTypeLoc>(TL)) + if (!TL.getAs<FunctionProtoTypeLoc>()) return false; - FunctionProtoTypeLoc FP = cast<FunctionProtoTypeLoc>(TL); + FunctionProtoTypeLoc FP = TL.castAs<FunctionProtoTypeLoc>(); for (unsigned I = 0, E = FP.getNumArgs(); I != E; ++I) { ParmVarDecl *P = FP.getArg(I); @@ -1613,9 +1613,9 @@ TypeSourceInfo *Sema::SubstFunctionDeclType(TypeSourceInfo *T, TLB.reserve(TL.getFullDataSize()); QualType Result; - - if (FunctionProtoTypeLoc *Proto = dyn_cast<FunctionProtoTypeLoc>(&TL)) { - Result = Instantiator.TransformFunctionProtoType(TLB, *Proto, ThisContext, + + if (FunctionProtoTypeLoc Proto = TL.getAs<FunctionProtoTypeLoc>()) { + Result = Instantiator.TransformFunctionProtoType(TLB, Proto, ThisContext, ThisTypeQuals); } else { Result = Instantiator.TransformType(TLB, TL); @@ -1635,9 +1635,8 @@ ParmVarDecl *Sema::SubstParmVarDecl(ParmVarDecl *OldParm, TypeSourceInfo *NewDI = 0; TypeLoc OldTL = OldDI->getTypeLoc(); - if (isa<PackExpansionTypeLoc>(OldTL)) { - PackExpansionTypeLoc ExpansionTL = cast<PackExpansionTypeLoc>(OldTL); - + if (PackExpansionTypeLoc ExpansionTL = OldTL.getAs<PackExpansionTypeLoc>()) { + // We have a function parameter pack. Substitute into the pattern of the // expansion. NewDI = SubstType(ExpansionTL.getPatternLoc(), TemplateArgs, |