summaryrefslogtreecommitdiffstats
path: root/clang/tools/libclang/CIndex.cpp
diff options
context:
space:
mode:
authorDavid Blaikie <dblaikie@gmail.com>2013-02-18 22:06:02 +0000
committerDavid Blaikie <dblaikie@gmail.com>2013-02-18 22:06:02 +0000
commit6adc78e0df73d1f7dca4f0a39fe1473b4c2bd346 (patch)
tree4e0f7c0b001d67a581b235b4f19314a314de48e4 /clang/tools/libclang/CIndex.cpp
parentf666b761bd0737c7e9dd39531f4145fc2a334066 (diff)
downloadbcm5719-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/tools/libclang/CIndex.cpp')
-rw-r--r--clang/tools/libclang/CIndex.cpp18
1 files changed, 9 insertions, 9 deletions
diff --git a/clang/tools/libclang/CIndex.cpp b/clang/tools/libclang/CIndex.cpp
index 1a19a004df5..e8e3f1d31e6 100644
--- a/clang/tools/libclang/CIndex.cpp
+++ b/clang/tools/libclang/CIndex.cpp
@@ -671,10 +671,10 @@ bool CursorVisitor::VisitClassTemplateSpecializationDecl(
// Visit the template arguments used in the specialization.
if (TypeSourceInfo *SpecType = D->getTypeAsWritten()) {
TypeLoc TL = SpecType->getTypeLoc();
- if (TemplateSpecializationTypeLoc *TSTLoc
- = dyn_cast<TemplateSpecializationTypeLoc>(&TL)) {
- for (unsigned I = 0, N = TSTLoc->getNumArgs(); I != N; ++I)
- if (VisitTemplateArgumentLoc(TSTLoc->getArgLoc(I)))
+ if (TemplateSpecializationTypeLoc TSTLoc =
+ TL.getAs<TemplateSpecializationTypeLoc>()) {
+ for (unsigned I = 0, N = TSTLoc.getNumArgs(); I != N; ++I)
+ if (VisitTemplateArgumentLoc(TSTLoc.getArgLoc(I)))
return true;
}
}
@@ -750,12 +750,12 @@ bool CursorVisitor::VisitFunctionDecl(FunctionDecl *ND) {
// Visit the function declaration's syntactic components in the order
// written. This requires a bit of work.
TypeLoc TL = TSInfo->getTypeLoc().IgnoreParens();
- FunctionTypeLoc *FTL = dyn_cast<FunctionTypeLoc>(&TL);
+ FunctionTypeLoc FTL = TL.getAs<FunctionTypeLoc>();
// If we have a function declared directly (without the use of a typedef),
// visit just the return type. Otherwise, just visit the function's type
// now.
- if ((FTL && !isa<CXXConversionDecl>(ND) && Visit(FTL->getResultLoc())) ||
+ if ((FTL && !isa<CXXConversionDecl>(ND) && Visit(FTL.getResultLoc())) ||
(!FTL && Visit(TL)))
return true;
@@ -771,7 +771,7 @@ bool CursorVisitor::VisitFunctionDecl(FunctionDecl *ND) {
// FIXME: Visit explicitly-specified template arguments!
// Visit the function parameters, if we have a function type.
- if (FTL && VisitFunctionTypeLoc(*FTL, true))
+ if (FTL && VisitFunctionTypeLoc(FTL, true))
return true;
// FIXME: Attributes?
@@ -2360,8 +2360,8 @@ bool CursorVisitor::RunVisitorWorkList(VisitorWorkList &WL) {
// Visit the whole type.
if (Visit(TL))
return true;
- } else if (isa<FunctionProtoTypeLoc>(TL)) {
- FunctionProtoTypeLoc Proto = cast<FunctionProtoTypeLoc>(TL);
+ } else if (FunctionProtoTypeLoc Proto =
+ TL.getAs<FunctionProtoTypeLoc>()) {
if (E->hasExplicitParameters()) {
// Visit parameters.
for (unsigned I = 0, N = Proto.getNumArgs(); I != N; ++I)
OpenPOWER on IntegriCloud