From bd05286670dd657cbdfb2708ca32922b557066cd Mon Sep 17 00:00:00 2001 From: Aaron Ballman Date: Thu, 20 Aug 2015 21:27:35 +0000 Subject: [PATCH] Do not crash when static analysis encounters a FunctionDecl that has a delayed template parse of its body. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@245616 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp | 4 ++-- test/Analysis/delayed-template-parsing-crash.cpp | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 test/Analysis/delayed-template-parsing-crash.cpp diff --git a/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp b/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp index c957a654a8..728287fbaa 100644 --- a/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp +++ b/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp @@ -588,8 +588,8 @@ AnalysisConsumer::getModeForDecl(Decl *D, AnalysisMode Mode) { // - Header files: run non-path-sensitive checks only. // - System headers: don't run any checks. SourceManager &SM = Ctx->getSourceManager(); - SourceLocation SL = D->hasBody() ? D->getBody()->getLocStart() - : D->getLocation(); + const Stmt *Body = D->getBody(); + SourceLocation SL = Body ? Body->getLocStart() : D->getLocation(); SL = SM.getExpansionLoc(SL); if (!Opts->AnalyzeAll && !SM.isWrittenInMainFile(SL)) { diff --git a/test/Analysis/delayed-template-parsing-crash.cpp b/test/Analysis/delayed-template-parsing-crash.cpp new file mode 100644 index 0000000000..94a143b0c0 --- /dev/null +++ b/test/Analysis/delayed-template-parsing-crash.cpp @@ -0,0 +1,11 @@ +// RUN: %clang_cc1 -analyze -analyzer-checker=core -std=c++11 -fdelayed-template-parsing -verify %s +// expected-no-diagnostics + +template struct remove_reference {typedef T type;}; +template struct remove_reference {typedef T type;}; +template struct remove_reference {typedef T type;}; + +template +typename remove_reference::type&& move(T&& arg) { // this used to crash + return static_cast::type&&>(arg); +} -- 2.40.0