Use RAII objects to ensure proper destruction of expression and statement AST nodes in the parser in most cases, even on error.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@60057 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Parse/ParsePragma.cpp b/lib/Parse/ParsePragma.cpp
index 17eba03..a6e2328 100644
--- a/lib/Parse/ParsePragma.cpp
+++ b/lib/Parse/ParsePragma.cpp
@@ -12,6 +12,7 @@
//===----------------------------------------------------------------------===//
#include "ParsePragma.h"
+#include "AstGuard.h"
#include "clang/Basic/Diagnostic.h"
#include "clang/Lex/Preprocessor.h"
#include "clang/Parse/Action.h"
@@ -35,12 +36,14 @@
Action::PragmaPackKind Kind = Action::PPK_Default;
IdentifierInfo *Name = 0;
Action::ExprResult Alignment;
+ ExprGuard AlignmentGuard(Actions);
SourceLocation LParenLoc = Tok.getLocation();
PP.Lex(Tok);
if (Tok.is(tok::numeric_constant)) {
Alignment = Actions.ActOnNumericConstant(Tok);
if (Alignment.isInvalid)
return;
+ AlignmentGuard.reset(Alignment);
PP.Lex(Tok);
} else if (Tok.is(tok::identifier)) {
@@ -66,6 +69,7 @@
Alignment = Actions.ActOnNumericConstant(Tok);
if (Alignment.isInvalid)
return;
+ AlignmentGuard.reset(Alignment);
PP.Lex(Tok);
} else if (Tok.is(tok::identifier)) {
@@ -83,6 +87,7 @@
Alignment = Actions.ActOnNumericConstant(Tok);
if (Alignment.isInvalid)
return;
+ AlignmentGuard.reset(Alignment);
PP.Lex(Tok);
}
@@ -100,7 +105,7 @@
}
SourceLocation RParenLoc = Tok.getLocation();
- Actions.ActOnPragmaPack(Kind, Name, Alignment.Val, PackLoc,
+ Actions.ActOnPragmaPack(Kind, Name, AlignmentGuard.take(), PackLoc,
LParenLoc, RParenLoc);
}