This revision was automatically updated to reflect the committed changes. Closed by commit rG99b94f29ac5d: [analyzer] LoopUnrolling: fix crash when a parameter is a loop counter. (authored by dergachev.a).
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D80171/new/ https://reviews.llvm.org/D80171 Files: clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp clang/test/Analysis/loop-unrolling.cpp Index: clang/test/Analysis/loop-unrolling.cpp =================================================================== --- clang/test/Analysis/loop-unrolling.cpp +++ clang/test/Analysis/loop-unrolling.cpp @@ -499,3 +499,15 @@ clang_analyzer_numTimesReached(); // expected-warning {{6}} } } + +void parm_by_value_as_loop_counter(int i) { + for (i = 0; i < 10; ++i) { + clang_analyzer_numTimesReached(); // expected-warning {{10}} + } +} + +void parm_by_ref_as_loop_counter(int &i) { + for (i = 0; i < 10; ++i) { + clang_analyzer_numTimesReached(); // expected-warning {{4}} + } +} Index: clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp =================================================================== --- clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp +++ clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp @@ -164,6 +164,11 @@ if (VD->hasGlobalStorage()) return true; + const bool isParm = isa<ParmVarDecl>(VD); + // Reference parameters are assumed as escaped variables. + if (isParm && VD->getType()->isReferenceType()) + return true; + while (!N->pred_empty()) { // FIXME: getStmtForDiagnostics() does nasty things in order to provide // a valid statement for body farms, do we need this behavior here? @@ -193,6 +198,11 @@ N = N->getFirstPred(); } + + // Parameter declaration will not be found. + if (isParm) + return false; + llvm_unreachable("Reached root without finding the declaration of VD"); }
Index: clang/test/Analysis/loop-unrolling.cpp =================================================================== --- clang/test/Analysis/loop-unrolling.cpp +++ clang/test/Analysis/loop-unrolling.cpp @@ -499,3 +499,15 @@ clang_analyzer_numTimesReached(); // expected-warning {{6}} } } + +void parm_by_value_as_loop_counter(int i) { + for (i = 0; i < 10; ++i) { + clang_analyzer_numTimesReached(); // expected-warning {{10}} + } +} + +void parm_by_ref_as_loop_counter(int &i) { + for (i = 0; i < 10; ++i) { + clang_analyzer_numTimesReached(); // expected-warning {{4}} + } +} Index: clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp =================================================================== --- clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp +++ clang/lib/StaticAnalyzer/Core/LoopUnrolling.cpp @@ -164,6 +164,11 @@ if (VD->hasGlobalStorage()) return true; + const bool isParm = isa<ParmVarDecl>(VD); + // Reference parameters are assumed as escaped variables. + if (isParm && VD->getType()->isReferenceType()) + return true; + while (!N->pred_empty()) { // FIXME: getStmtForDiagnostics() does nasty things in order to provide // a valid statement for body farms, do we need this behavior here? @@ -193,6 +198,11 @@ N = N->getFirstPred(); } + + // Parameter declaration will not be found. + if (isParm) + return false; + llvm_unreachable("Reached root without finding the declaration of VD"); }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits