From a7bcab75d22d26a4f2d89eb4540a27758a8ecb85 Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Fri, 9 May 2014 17:08:01 +0000 Subject: ThreadSafetyAnalysis: Don't crash when trying to analyze objc methods. The thread safety analysis isn't very useful in ObjC (you can't annotate ObjC classes or methods) but we can still analyze the actual code and show violations in usage of C/C++ functions. Fixes PR19541, which does not use thread safety attributes but crashes with -Weverything. llvm-svn: 208436 --- clang/lib/Analysis/ThreadSafetyCommon.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'clang/lib/Analysis') diff --git a/clang/lib/Analysis/ThreadSafetyCommon.cpp b/clang/lib/Analysis/ThreadSafetyCommon.cpp index 0a6efebd311..fb96834b3e7 100644 --- a/clang/lib/Analysis/ThreadSafetyCommon.cpp +++ b/clang/lib/Analysis/ThreadSafetyCommon.cpp @@ -14,6 +14,7 @@ #include "clang/Analysis/Analyses/ThreadSafetyCommon.h" #include "clang/AST/Attr.h" #include "clang/AST/DeclCXX.h" +#include "clang/AST/DeclObjC.h" #include "clang/AST/ExprCXX.h" #include "clang/AST/StmtCXX.h" #include "clang/Analysis/Analyses/PostOrderCFGView.h" @@ -634,8 +635,7 @@ void SExprBuilder::mergePhiNodesBackEdge(const CFGBlock *Blk) { } } - -void SExprBuilder::enterCFG(CFG *Cfg, const FunctionDecl *FD, +void SExprBuilder::enterCFG(CFG *Cfg, const NamedDecl *D, const CFGBlock *First) { // Perform initial setup operations. unsigned NBlocks = Cfg->getNumBlockIDs(); @@ -649,10 +649,12 @@ void SExprBuilder::enterCFG(CFG *Cfg, const FunctionDecl *FD, auto *BB = new (Arena) til::BasicBlock(Arena, 0, B->size()); BlockMap[B->getBlockID()] = BB; } - CallCtx.reset(new SExprBuilder::CallingContext(FD)); + CallCtx.reset(new SExprBuilder::CallingContext(D)); CurrentBB = lookupBlock(&Cfg->getEntry()); - for (auto *Pm : FD->parameters()) { + auto Parms = isa(D) ? cast(D)->parameters() + : cast(D)->parameters(); + for (auto *Pm : Parms) { QualType T = Pm->getType(); if (!T.isTrivialType(Pm->getASTContext())) continue; -- cgit v1.2.3