Don't stack-allocate an IntegerLiteral which can be referred to after the current method returns. PR11744, part 2.

llvm-svn: 148995
This commit is contained in:
Eli Friedman 2012-01-25 23:20:27 +00:00
parent 29f7dff581
commit 9562f39e2f
2 changed files with 16 additions and 3 deletions

View File

@ -8325,9 +8325,12 @@ TreeTransform<Derived>::RebuildArrayType(QualType ElementType,
break;
}
IntegerLiteral ArraySize(SemaRef.Context, *Size, SizeType,
/*FIXME*/BracketsRange.getBegin());
return SemaRef.BuildArrayType(ElementType, SizeMod, &ArraySize,
// Note that we can return a VariableArrayType here in the case where
// the element type was a dependent VariableArrayType.
IntegerLiteral *ArraySize
= IntegerLiteral::Create(SemaRef.Context, *Size, SizeType,
/*FIXME*/BracketsRange.getBegin());
return SemaRef.BuildArrayType(ElementType, SizeMod, ArraySize,
IndexTypeQuals, BracketsRange,
getDerived().getBaseEntity());
}

View File

@ -25,3 +25,13 @@ void f(int argc, const char* argv[]) {
// CHECK: call void @_ZN1XD1Ev
// CHECK: ret void
}
namespace PR11744 {
// Make sure this doesn't crash; there was a use-after-free issue
// for this testcase.
template<typename T> int f(int n) {
T arr[3][n];
return 3;
}
int test = f<int>(0);
}