r245616 - Do not crash when static analysis encounters a FunctionDecl that has a delayed template parse of its body.

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 20 14:27:36 PDT 2015


Author: aaronballman
Date: Thu Aug 20 16:27:35 2015
New Revision: 245616

URL: http://llvm.org/viewvc/llvm-project?rev=245616&view=rev
Log:
Do not crash when static analysis encounters a FunctionDecl that has a delayed template parse of its body.

Added:
    cfe/trunk/test/Analysis/delayed-template-parsing-crash.cpp
Modified:
    cfe/trunk/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp

Modified: cfe/trunk/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp?rev=245616&r1=245615&r2=245616&view=diff
==============================================================================
--- cfe/trunk/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp (original)
+++ cfe/trunk/lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp Thu Aug 20 16:27:35 2015
@@ -588,8 +588,8 @@ AnalysisConsumer::getModeForDecl(Decl *D
   // - 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)) {

Added: cfe/trunk/test/Analysis/delayed-template-parsing-crash.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Analysis/delayed-template-parsing-crash.cpp?rev=245616&view=auto
==============================================================================
--- cfe/trunk/test/Analysis/delayed-template-parsing-crash.cpp (added)
+++ cfe/trunk/test/Analysis/delayed-template-parsing-crash.cpp Thu Aug 20 16:27:35 2015
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -analyze -analyzer-checker=core -std=c++11 -fdelayed-template-parsing -verify %s
+// expected-no-diagnostics
+
+template <class T> struct remove_reference      {typedef T type;};
+template <class T> struct remove_reference<T&>  {typedef T type;};
+template <class T> struct remove_reference<T&&> {typedef T type;};
+
+template <typename T>
+typename remove_reference<T>::type&& move(T&& arg) { // this used to crash
+  return static_cast<typename remove_reference<T>::type&&>(arg);
+}




More information about the cfe-commits mailing list