[clang-tools-extra] r246655 - Fix loop-convert crash.
Angel Garcia Gomez via cfe-commits
cfe-commits at lists.llvm.org
Wed Sep 2 07:25:08 PDT 2015
Author: angelgarcia
Date: Wed Sep 2 09:25:08 2015
New Revision: 246655
URL: http://llvm.org/viewvc/llvm-project?rev=246655&view=rev
Log:
Fix loop-convert crash.
Summary: loop-convert no longer crashes when calling a member function using a member pointer which is a member of another record.
Reviewers: alexfh, klimek
Subscribers: cfe-commits, klimek
Differential Revision: http://reviews.llvm.org/D12555
Modified:
clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertUtils.cpp
clang-tools-extra/trunk/test/clang-tidy/modernize-loop-convert-basic.cpp
Modified: clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertUtils.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertUtils.cpp?rev=246655&r1=246654&r2=246655&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertUtils.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/modernize/LoopConvertUtils.cpp Wed Sep 2 09:25:08 2015
@@ -370,7 +370,10 @@ static bool isAliasDecl(const Decl *TheD
case Stmt::CXXMemberCallExprClass: {
const auto *MemCall = cast<CXXMemberCallExpr>(Init);
- if (MemCall->getMethodDecl()->getName() == "at") {
+ // This check is needed because getMethodDecl can return nullptr if the
+ // callee is a member function pointer.
+ if (MemCall->getMethodDecl() &&
+ MemCall->getMethodDecl()->getName() == "at") {
assert(MemCall->getNumArgs() == 1);
return isIndexInSubscriptExpr(MemCall->getArg(0), IndexVar);
}
Modified: clang-tools-extra/trunk/test/clang-tidy/modernize-loop-convert-basic.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/modernize-loop-convert-basic.cpp?rev=246655&r1=246654&r2=246655&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/modernize-loop-convert-basic.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/modernize-loop-convert-basic.cpp Wed Sep 2 09:25:08 2015
@@ -156,6 +156,17 @@ void memberFunctionPointer() {
// CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use range-based for loop instead
// CHECK-FIXES: for (auto & elem : mfpArr)
// CHECK-FIXES-NEXT: (v.*elem)();
+
+ struct Foo {
+ int (Val::*f)();
+ } foo[N];
+
+ for (int i = 0; i < N; ++i)
+ int r = (v.*(foo[i].f))();
+ // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: use range-based for loop instead
+ // CHECK-FIXES: for (auto & elem : foo)
+ // CHECK-FIXES-NEXT: int r = (v.*(elem.f))();
+
}
} // namespace Array
More information about the cfe-commits
mailing list