From eccce7e246a17e12a2afd6eabb9ac7c8d582db4e Mon Sep 17 00:00:00 2001 From: Argyrios Kyrtzidis Date: Tue, 3 May 2011 18:45:38 +0000 Subject: [PATCH] Fix a double free when parsing malformed code. Fixes rdar://9173693. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@130775 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Parse/ParseExprCXX.cpp | 7 +++++-- test/SemaTemplate/rdar9173693.cpp | 6 ++++++ 2 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 test/SemaTemplate/rdar9173693.cpp diff --git a/lib/Parse/ParseExprCXX.cpp b/lib/Parse/ParseExprCXX.cpp index 8bf6f63d3e..eb491ef2bb 100644 --- a/lib/Parse/ParseExprCXX.cpp +++ b/lib/Parse/ParseExprCXX.cpp @@ -280,8 +280,11 @@ bool Parser::ParseOptionalCXXScopeSpecifier(CXXScopeSpec &SS, : TemplateId->TemplateNameLoc; SS.SetInvalid(SourceRange(StartLoc, CCLoc)); } - - TemplateId->Destroy(); + + // If we are caching tokens we will process the TemplateId again, + // otherwise destroy it. + if (!PP.isBacktrackEnabled()) + TemplateId->Destroy(); continue; } diff --git a/test/SemaTemplate/rdar9173693.cpp b/test/SemaTemplate/rdar9173693.cpp new file mode 100644 index 0000000000..86b49545a3 --- /dev/null +++ b/test/SemaTemplate/rdar9173693.cpp @@ -0,0 +1,6 @@ +// RUN: %clang_cc1 -fsyntax-only -verify %s + +// +template< bool C > struct assert { }; +template< bool > struct assert_arg_pred_impl { }; // expected-note 3 {{declared here}} +template< typename Pred > assert assert_not_arg( void (*)(Pred), typename assert_arg_pred::type ); // expected-error 5 {{}}