diff options
author | Benjamin Kramer <benny.kra@googlemail.com> | 2012-06-07 15:09:51 +0000 |
---|---|---|
committer | Benjamin Kramer <benny.kra@googlemail.com> | 2012-06-07 15:09:51 +0000 |
commit | 855243789cb44799c03f4c7216d3d6308805f549 (patch) | |
tree | ddfaf2e09c5404dd1a1caa9447984cdc7382dd97 /lib/Sema/SemaTemplate.cpp | |
parent | 575b66a8e07984ff21c1d3ed0da704043b9390bd (diff) |
Plug a long standing memory leak in TemplateArgument.
The integral APSInt value is now stored in a decomposed form and the backing
store for large values is allocated via the ASTContext. This way its not
leaked as TemplateArguments are never destructed when they are allocated in
the ASTContext. Since the integral data is immutable it is now shared between
instances, making copying TemplateArguments a trivial operation.
Currently getting the integral data out of a TemplateArgument requires creating
a new APSInt object. This is cheap when the value is small but can be expensive
if it's not. If this turns out to be an issue a more efficient accessor could
be added.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@158150 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaTemplate.cpp')
-rw-r--r-- | lib/Sema/SemaTemplate.cpp | 11 |
1 files changed, 6 insertions, 5 deletions
diff --git a/lib/Sema/SemaTemplate.cpp b/lib/Sema/SemaTemplate.cpp index 002b0b174e..dccb4b6a61 100644 --- a/lib/Sema/SemaTemplate.cpp +++ b/lib/Sema/SemaTemplate.cpp @@ -4125,7 +4125,8 @@ ExprResult Sema::CheckTemplateArgument(NonTypeTemplateParmDecl *Param, IntegerType = Enum->getDecl()->getIntegerType(); Value = Value.extOrTrunc(Context.getTypeSize(IntegerType)); - Converted = TemplateArgument(Value, Context.getCanonicalType(ParamType)); + Converted = TemplateArgument(Context, Value, + Context.getCanonicalType(ParamType)); return ArgResult; } @@ -4251,7 +4252,7 @@ ExprResult Sema::CheckTemplateArgument(NonTypeTemplateParmDecl *Param, } } - Converted = TemplateArgument(Value, + Converted = TemplateArgument(Context, Value, ParamType->isEnumeralType() ? Context.getCanonicalType(ParamType) : IntegerType); @@ -4569,13 +4570,13 @@ Sema::BuildExpressionFromIntegralTemplateArgument(const TemplateArgument &Arg, Kind = CharacterLiteral::Ascii; return Owned(new (Context) CharacterLiteral( - Arg.getAsIntegral()->getZExtValue(), + Arg.getAsIntegral().getZExtValue(), Kind, T, Loc)); } if (T->isBooleanType()) return Owned(new (Context) CXXBoolLiteralExpr( - Arg.getAsIntegral()->getBoolValue(), + Arg.getAsIntegral().getBoolValue(), T, Loc)); if (T->isNullPtrType()) @@ -4590,7 +4591,7 @@ Sema::BuildExpressionFromIntegralTemplateArgument(const TemplateArgument &Arg, else BT = T; - Expr *E = IntegerLiteral::Create(Context, *Arg.getAsIntegral(), BT, Loc); + Expr *E = IntegerLiteral::Create(Context, Arg.getAsIntegral(), BT, Loc); if (T->isEnumeralType()) { // FIXME: This is a hack. We need a better way to handle substituted // non-type template parameters. |