]> granicus.if.org Git - clang/commitdiff
Do not crash when static analysis encounters a FunctionDecl that has a delayed templa...
authorAaron Ballman <aaron@aaronballman.com>
Thu, 20 Aug 2015 21:27:35 +0000 (21:27 +0000)
committerAaron Ballman <aaron@aaronballman.com>
Thu, 20 Aug 2015 21:27:35 +0000 (21:27 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@245616 91177308-0d34-0410-b5e6-96231b3b80d8

lib/StaticAnalyzer/Frontend/AnalysisConsumer.cpp
test/Analysis/delayed-template-parsing-crash.cpp [new file with mode: 0644]

index c957a654a84c2a579128295113f8b1bb8ae39c94..728287fbaa625c3cef8732647315e581d2da7b6f 100644 (file)
@@ -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 (file)
index 0000000..94a143b
--- /dev/null
@@ -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);
+}