This revision was automatically updated to reflect the committed changes. Closed by commit rG29353e69d25c: [analyzer] LoopWidening: fix crash by avoiding aliased references invalidation (authored by AbbasSabra, committed by vsavchenko).
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D80669/new/ https://reviews.llvm.org/D80669 Files: clang/lib/StaticAnalyzer/Core/LoopWidening.cpp clang/test/Analysis/loop-widening-preserve-reference-type.cpp Index: clang/test/Analysis/loop-widening-preserve-reference-type.cpp =================================================================== --- clang/test/Analysis/loop-widening-preserve-reference-type.cpp +++ clang/test/Analysis/loop-widening-preserve-reference-type.cpp @@ -12,3 +12,11 @@ for (int i = 0; i < 10; ++i) { } clang_analyzer_eval(&x != 0); // expected-warning{{TRUE}} } // expected-warning@-1{{reference cannot be bound to dereferenced null pointer in well-defined C++ code; comparison may be assumed to always evaluate to true}} + +using AR = const A &; +void invalid_type_alias_region_access() { + AR x = B(); + for (int i = 0; i < 10; ++i) { + } + clang_analyzer_eval(&x != 0); // expected-warning{{TRUE}} +} // expected-warning@-1{{reference cannot be bound to dereferenced null pointer in well-defined C++ code; comparison may be assumed to always evaluate to true}} Index: clang/lib/StaticAnalyzer/Core/LoopWidening.cpp =================================================================== --- clang/lib/StaticAnalyzer/Core/LoopWidening.cpp +++ clang/lib/StaticAnalyzer/Core/LoopWidening.cpp @@ -67,8 +67,10 @@ } // References should not be invalidated. - auto Matches = match(findAll(stmt(hasDescendant(varDecl(hasType(referenceType())).bind(MatchRef)))), - *LCtx->getDecl()->getBody(), ASTCtx); + auto Matches = match( + findAll(stmt(hasDescendant( + varDecl(hasType(hasCanonicalType(referenceType()))).bind(MatchRef)))), + *LCtx->getDecl()->getBody(), ASTCtx); for (BoundNodes Match : Matches) { const VarDecl *VD = Match.getNodeAs<VarDecl>(MatchRef); assert(VD);
Index: clang/test/Analysis/loop-widening-preserve-reference-type.cpp =================================================================== --- clang/test/Analysis/loop-widening-preserve-reference-type.cpp +++ clang/test/Analysis/loop-widening-preserve-reference-type.cpp @@ -12,3 +12,11 @@ for (int i = 0; i < 10; ++i) { } clang_analyzer_eval(&x != 0); // expected-warning{{TRUE}} } // expected-warning@-1{{reference cannot be bound to dereferenced null pointer in well-defined C++ code; comparison may be assumed to always evaluate to true}} + +using AR = const A &; +void invalid_type_alias_region_access() { + AR x = B(); + for (int i = 0; i < 10; ++i) { + } + clang_analyzer_eval(&x != 0); // expected-warning{{TRUE}} +} // expected-warning@-1{{reference cannot be bound to dereferenced null pointer in well-defined C++ code; comparison may be assumed to always evaluate to true}} Index: clang/lib/StaticAnalyzer/Core/LoopWidening.cpp =================================================================== --- clang/lib/StaticAnalyzer/Core/LoopWidening.cpp +++ clang/lib/StaticAnalyzer/Core/LoopWidening.cpp @@ -67,8 +67,10 @@ } // References should not be invalidated. - auto Matches = match(findAll(stmt(hasDescendant(varDecl(hasType(referenceType())).bind(MatchRef)))), - *LCtx->getDecl()->getBody(), ASTCtx); + auto Matches = match( + findAll(stmt(hasDescendant( + varDecl(hasType(hasCanonicalType(referenceType()))).bind(MatchRef)))), + *LCtx->getDecl()->getBody(), ASTCtx); for (BoundNodes Match : Matches) { const VarDecl *VD = Match.getNodeAs<VarDecl>(MatchRef); assert(VD);
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits