From 6adc78e0df73d1f7dca4f0a39fe1473b4c2bd346 Mon Sep 17 00:00:00 2001 From: David Blaikie Date: Mon, 18 Feb 2013 22:06:02 +0000 Subject: 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 --- clang/lib/ARCMigrate/TransGCAttrs.cpp | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'clang/lib/ARCMigrate/TransGCAttrs.cpp') 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(&TL)) { - TL = QL->getUnqualifiedLoc(); - } else if (const AttributedTypeLoc * - Attr = dyn_cast(&TL)) { - if (handleAttr(*Attr, D)) + if (QualifiedTypeLoc QL = TL.getAs()) { + TL = QL.getUnqualifiedLoc(); + } else if (AttributedTypeLoc Attr = TL.getAs()) { + if (handleAttr(Attr, D)) break; - TL = Attr->getModifiedLoc(); - } else if (const ArrayTypeLoc *Arr = dyn_cast(&TL)) { - TL = Arr->getElementLoc(); - } else if (const PointerTypeLoc *PT = dyn_cast(&TL)) { - TL = PT->getPointeeLoc(); - } else if (const ReferenceTypeLoc *RT = dyn_cast(&TL)) - TL = RT->getPointeeLoc(); + TL = Attr.getModifiedLoc(); + } else if (ArrayTypeLoc Arr = TL.getAs()) { + TL = Arr.getElementLoc(); + } else if (PointerTypeLoc PT = TL.getAs()) { + TL = PT.getPointeeLoc(); + } else if (ReferenceTypeLoc RT = TL.getAs()) + 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(&TL)) { - ATLs.push_back(std::make_pair(*ATL, PD)); + if (AttributedTypeLoc ATL = + TL.getAs()) { + 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) -- cgit v1.2.3