|
@@ -1066,6 +1066,7 @@ void CodeGenFunction::EmitAndRegisterVariableArrayDimensions(
|
|
|
// For each dimension stores its QualType and corresponding
|
|
|
// size-expression Value.
|
|
|
SmallVector<CodeGenFunction::VlaSizePair, 4> Dimensions;
|
|
|
+ SmallVector<IdentifierInfo *, 4> VLAExprNames;
|
|
|
|
|
|
// Break down the array into individual dimensions.
|
|
|
QualType Type1D = D.getType();
|
|
@@ -1074,8 +1075,14 @@ void CodeGenFunction::EmitAndRegisterVariableArrayDimensions(
|
|
|
if (auto *C = dyn_cast<llvm::ConstantInt>(VlaSize.NumElts))
|
|
|
Dimensions.emplace_back(C, Type1D.getUnqualifiedType());
|
|
|
else {
|
|
|
- auto SizeExprAddr = CreateDefaultAlignTempAlloca(
|
|
|
- VlaSize.NumElts->getType(), "__vla_expr");
|
|
|
+ // Generate a locally unique name for the size expression.
|
|
|
+ Twine Name = Twine("__vla_expr") + Twine(VLAExprCounter++);
|
|
|
+ SmallString<12> Buffer;
|
|
|
+ StringRef NameRef = Name.toStringRef(Buffer);
|
|
|
+ auto &Ident = getContext().Idents.getOwn(NameRef);
|
|
|
+ VLAExprNames.push_back(&Ident);
|
|
|
+ auto SizeExprAddr =
|
|
|
+ CreateDefaultAlignTempAlloca(VlaSize.NumElts->getType(), NameRef);
|
|
|
Builder.CreateStore(VlaSize.NumElts, SizeExprAddr);
|
|
|
Dimensions.emplace_back(SizeExprAddr.getPointer(),
|
|
|
Type1D.getUnqualifiedType());
|
|
@@ -1089,20 +1096,20 @@ void CodeGenFunction::EmitAndRegisterVariableArrayDimensions(
|
|
|
// Register each dimension's size-expression with a DILocalVariable,
|
|
|
// so that it can be used by CGDebugInfo when instantiating a DISubrange
|
|
|
// to describe this array.
|
|
|
+ unsigned NameIdx = 0;
|
|
|
for (auto &VlaSize : Dimensions) {
|
|
|
llvm::Metadata *MD;
|
|
|
if (auto *C = dyn_cast<llvm::ConstantInt>(VlaSize.NumElts))
|
|
|
MD = llvm::ConstantAsMetadata::get(C);
|
|
|
else {
|
|
|
// Create an artificial VarDecl to generate debug info for.
|
|
|
- IdentifierInfo &NameIdent = getContext().Idents.getOwn(
|
|
|
- cast<llvm::AllocaInst>(VlaSize.NumElts)->getName());
|
|
|
+ IdentifierInfo *NameIdent = VLAExprNames[NameIdx++];
|
|
|
auto VlaExprTy = VlaSize.NumElts->getType()->getPointerElementType();
|
|
|
auto QT = getContext().getIntTypeForBitwidth(
|
|
|
VlaExprTy->getScalarSizeInBits(), false);
|
|
|
auto *ArtificialDecl = VarDecl::Create(
|
|
|
getContext(), const_cast<DeclContext *>(D.getDeclContext()),
|
|
|
- D.getLocation(), D.getLocation(), &NameIdent, QT,
|
|
|
+ D.getLocation(), D.getLocation(), NameIdent, QT,
|
|
|
getContext().CreateTypeSourceInfo(QT), SC_Auto);
|
|
|
ArtificialDecl->setImplicit();
|
|
|
|