From: Nico Weber Date: Sat, 21 Mar 2015 17:37:46 +0000 (+0000) Subject: Dedent code for -Wdynamic-class-memaccess warning. No behavior change. X-Git-Tag: llvmorg-3.7.0-rc1~8651 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c44b35e3be15ac952bffeac491aff4b7e483a6b2;p=platform%2Fupstream%2Fllvm.git Dedent code for -Wdynamic-class-memaccess warning. No behavior change. The diff looks intimidating, but this just moves the -Wdynamic-class-memaccess code out a scope, protected by a if (PointeeTy == QualType()) continue; check so that it still only runs when it should. llvm-svn: 232899 --- diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index d73d33d..d684928 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -4650,7 +4650,7 @@ static const CXXRecordDecl *getContainedDynamicClass(QualType T, /// \brief If E is a sizeof expression, returns its argument expression, /// otherwise returns NULL. -static const Expr *getSizeOfExprArg(const Expr* E) { +static const Expr *getSizeOfExprArg(const Expr *E) { if (const UnaryExprOrTypeTraitExpr *SizeOf = dyn_cast(E)) if (SizeOf->getKind() == clang::UETT_SizeOf && !SizeOf->isArgumentType()) @@ -4660,7 +4660,7 @@ static const Expr *getSizeOfExprArg(const Expr* E) { } /// \brief If E is a sizeof expression, returns its argument type. -static QualType getSizeOfArgType(const Expr* E) { +static QualType getSizeOfArgType(const Expr *E) { if (const UnaryExprOrTypeTraitExpr *SizeOf = dyn_cast(E)) if (SizeOf->getKind() == clang::UETT_SizeOf) @@ -4706,8 +4706,9 @@ void Sema::CheckMemaccessArguments(const CallExpr *Call, SourceRange ArgRange = Call->getArg(ArgIdx)->getSourceRange(); QualType DestTy = Dest->getType(); + QualType PointeeTy; if (const PointerType *DestPtrTy = DestTy->getAs()) { - QualType PointeeTy = DestPtrTy->getPointeeType(); + PointeeTy = DestPtrTy->getPointeeType(); // Never warn about void type pointers. This can be used to suppress // false positives. @@ -4787,47 +4788,51 @@ void Sema::CheckMemaccessArguments(const CallExpr *Call, break; } } + } - // Always complain about dynamic classes. - bool IsContained; - if (const CXXRecordDecl *ContainedRD = - getContainedDynamicClass(PointeeTy, IsContained)) { - - unsigned OperationType = 0; - // "overwritten" if we're warning about the destination for any call - // but memcmp; otherwise a verb appropriate to the call. - if (ArgIdx != 0 || BId == Builtin::BImemcmp) { - if (BId == Builtin::BImemcpy) - OperationType = 1; - else if(BId == Builtin::BImemmove) - OperationType = 2; - else if (BId == Builtin::BImemcmp) - OperationType = 3; - } - - DiagRuntimeBehavior( - Dest->getExprLoc(), Dest, - PDiag(diag::warn_dyn_class_memaccess) - << (BId == Builtin::BImemcmp ? ArgIdx + 2 : ArgIdx) - << FnName << IsContained << ContainedRD << OperationType - << Call->getCallee()->getSourceRange()); - } else if (PointeeTy.hasNonTrivialObjCLifetime() && - BId != Builtin::BImemset) - DiagRuntimeBehavior( - Dest->getExprLoc(), Dest, - PDiag(diag::warn_arc_object_memaccess) - << ArgIdx << FnName << PointeeTy - << Call->getCallee()->getSourceRange()); - else - continue; + if (PointeeTy == QualType()) + continue; + // Always complain about dynamic classes. + bool IsContained; + if (const CXXRecordDecl *ContainedRD = + getContainedDynamicClass(PointeeTy, IsContained)) { + + unsigned OperationType = 0; + // "overwritten" if we're warning about the destination for any call + // but memcmp; otherwise a verb appropriate to the call. + if (ArgIdx != 0 || BId == Builtin::BImemcmp) { + if (BId == Builtin::BImemcpy) + OperationType = 1; + else if(BId == Builtin::BImemmove) + OperationType = 2; + else if (BId == Builtin::BImemcmp) + OperationType = 3; + } + DiagRuntimeBehavior( Dest->getExprLoc(), Dest, - PDiag(diag::note_bad_memaccess_silence) - << FixItHint::CreateInsertion(ArgRange.getBegin(), "(void*)")); - break; - } + PDiag(diag::warn_dyn_class_memaccess) + << (BId == Builtin::BImemcmp ? ArgIdx + 2 : ArgIdx) + << FnName << IsContained << ContainedRD << OperationType + << Call->getCallee()->getSourceRange()); + } else if (PointeeTy.hasNonTrivialObjCLifetime() && + BId != Builtin::BImemset) + DiagRuntimeBehavior( + Dest->getExprLoc(), Dest, + PDiag(diag::warn_arc_object_memaccess) + << ArgIdx << FnName << PointeeTy + << Call->getCallee()->getSourceRange()); + else + continue; + + DiagRuntimeBehavior( + Dest->getExprLoc(), Dest, + PDiag(diag::note_bad_memaccess_silence) + << FixItHint::CreateInsertion(ArgRange.getBegin(), "(void*)")); + break; } + } // A little helper routine: ignore addition and subtraction of integer literals.