From 65693873276757290e49f547cb7a6409b0f58c91 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. llvm-svn: 245616 --- .../lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp | 4 ++-- .../test/Analysis/delayed-template-parsing-crash.cpp | 11 +++++++++++ 2 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 clang/test/Analysis/delayed-template-parsing-crash.cpp diff --git a/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp b/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp index c957a654a84c..728287fbaa62 100644 --- a/clang/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp +++ b/clang/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/clang/test/Analysis/delayed-template-parsing-crash.cpp b/clang/test/Analysis/delayed-template-parsing-crash.cpp new file mode 100644 index 000000000000..94a143b0c066 --- /dev/null +++ b/clang/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); +}