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 | 6adc78e0df73d1f7dca4f0a39fe1473b4c2bd346 (patch) | |
tree | 4e0f7c0b001d67a581b235b4f19314a314de48e4 /clang/lib/ARCMigrate/TransGCAttrs.cpp | |
parent | f666b761bd0737c7e9dd39531f4145fc2a334066 (diff) | |
download | bcm5719-llvm-6adc78e0df73d1f7dca4f0a39fe1473b4c2bd346.tar.gz bcm5719-llvm-6adc78e0df73d1f7dca4f0a39fe1473b4c2bd346.zip |
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.
llvm-svn: 175462
Diffstat (limited to 'clang/lib/ARCMigrate/TransGCAttrs.cpp')
-rw-r--r-- | clang/lib/ARCMigrate/TransGCAttrs.cpp | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/clang/lib/ARCMigrate/TransGCAttrs.cpp b/clang/lib/ARCMigrate/TransGCAttrs.cpp index eec7306ba74..d8be1ae746a 100644 --- a/clang/lib/ARCMigrate/TransGCAttrs.cpp +++ b/clang/lib/ARCMigrate/TransGCAttrs.cpp @@ -63,19 +63,18 @@ public: return; TypeLoc TL = TInfo->getTypeLoc(); while (TL) { - if (const QualifiedTypeLoc *QL = dyn_cast<QualifiedTypeLoc>(&TL)) { - TL = QL->getUnqualifiedLoc(); - } else if (const AttributedTypeLoc * - Attr = dyn_cast<AttributedTypeLoc>(&TL)) { - if (handleAttr(*Attr, D)) + if (QualifiedTypeLoc QL = TL.getAs<QualifiedTypeLoc>()) { + TL = QL.getUnqualifiedLoc(); + } else if (AttributedTypeLoc Attr = TL.getAs<AttributedTypeLoc>()) { + if (handleAttr(Attr, D)) break; - TL = Attr->getModifiedLoc(); - } else if (const ArrayTypeLoc *Arr = dyn_cast<ArrayTypeLoc>(&TL)) { - TL = Arr->getElementLoc(); - } else if (const PointerTypeLoc *PT = dyn_cast<PointerTypeLoc>(&TL)) { - TL = PT->getPointeeLoc(); - } else if (const ReferenceTypeLoc *RT = dyn_cast<ReferenceTypeLoc>(&TL)) - TL = RT->getPointeeLoc(); + TL = Attr.getModifiedLoc(); + } else if (ArrayTypeLoc Arr = TL.getAs<ArrayTypeLoc>()) { + TL = Arr.getElementLoc(); + } else if (PointerTypeLoc PT = TL.getAs<PointerTypeLoc>()) { + TL = PT.getPointeeLoc(); + } else if (ReferenceTypeLoc RT = TL.getAs<ReferenceTypeLoc>()) + TL = RT.getPointeeLoc(); else break; } @@ -249,8 +248,9 @@ static void checkAllAtProps(MigrationContext &MigrateCtx, if (!TInfo) return; TypeLoc TL = TInfo->getTypeLoc(); - if (AttributedTypeLoc *ATL = dyn_cast<AttributedTypeLoc>(&TL)) { - ATLs.push_back(std::make_pair(*ATL, PD)); + if (AttributedTypeLoc ATL = + TL.getAs<AttributedTypeLoc>()) { + ATLs.push_back(std::make_pair(ATL, PD)); if (TInfo->getType().getObjCLifetime() == Qualifiers::OCL_Weak) { hasWeak = true; } else if (TInfo->getType().getObjCLifetime() == Qualifiers::OCL_Strong) |