@@ -3402,6 +3402,9 @@ void IRGenDebugInfoImpl::emitVariableDeclaration(
3402
3402
if (!DInstLine || (ArgNo > 0 && VarInfo.Name == IGM.Context .Id_self .str ()))
3403
3403
Artificial = ArtificialValue;
3404
3404
3405
+ if (VarInfo.Name == " index" )
3406
+ llvm::errs ();
3407
+
3405
3408
llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
3406
3409
if (Artificial || DITy->isArtificial () || DITy == InternalType)
3407
3410
Flags |= llvm::DINode::FlagArtificial;
@@ -3458,10 +3461,10 @@ void IRGenDebugInfoImpl::emitVariableDeclaration(
3458
3461
3459
3462
auto appendDIExpression =
3460
3463
[&VarInfo, this ](llvm::DIExpression *DIExpr,
3461
- llvm::DIExpression::FragmentInfo PieceFragment)
3462
- -> llvm::DIExpression * {
3464
+ llvm::DIExpression::FragmentInfo PieceFragment,
3465
+ bool IsFirstAndOnlyPiece) -> llvm::DIExpression * {
3463
3466
if (!VarInfo.DIExpr ) {
3464
- if (!PieceFragment.SizeInBits )
3467
+ if (!PieceFragment.SizeInBits || IsFirstAndOnlyPiece )
3465
3468
return DIExpr;
3466
3469
3467
3470
return llvm::DIExpression::createFragmentExpression (
@@ -3478,7 +3481,7 @@ void IRGenDebugInfoImpl::emitVariableDeclaration(
3478
3481
DIExpr = llvm::DIExpression::append (DIExpr, Operands);
3479
3482
3480
3483
// Add the fragment of the SIL variable.
3481
- if (VarFragment.SizeInBits )
3484
+ if (VarFragment.SizeInBits && !IsFirstAndOnlyPiece )
3482
3485
DIExpr = llvm::DIExpression::createFragmentExpression (
3483
3486
DIExpr, VarFragment.OffsetInBits , VarFragment.SizeInBits )
3484
3487
.value_or (nullptr );
@@ -3528,8 +3531,14 @@ void IRGenDebugInfoImpl::emitVariableDeclaration(
3528
3531
Fragment.OffsetInBits = OffsetInBits;
3529
3532
Fragment.SizeInBits = SizeInBits;
3530
3533
}
3534
+ // LLVM complains if a single fragment covers the entire variable. This can
3535
+ // happen if, e.g., the optimizer takes the _value out of an Int
3536
+ // struct. Detect this case and don't emit a fragment.
3537
+ bool IsFirstAndOnlyPiece =
3538
+ !IsPiece && Fragment.OffsetInBits == 0 &&
3539
+ Fragment.SizeInBits == getSizeInBits (Var->getType ());
3531
3540
llvm::DIExpression *DIExpr = DBuilder.createExpression (Operands);
3532
- DIExpr = appendDIExpression (DIExpr, Fragment);
3541
+ DIExpr = appendDIExpression (DIExpr, Fragment, IsFirstAndOnlyPiece );
3533
3542
if (DIExpr)
3534
3543
emitDbgIntrinsic (
3535
3544
Builder, Piece, Var, DIExpr, DInstLine, DInstLoc.Column , Scope, DS,
@@ -3541,7 +3550,7 @@ void IRGenDebugInfoImpl::emitVariableDeclaration(
3541
3550
if (Storage.empty ()) {
3542
3551
llvm::DIExpression::FragmentInfo NoFragment = {0 , 0 };
3543
3552
if (auto *DIExpr =
3544
- appendDIExpression (DBuilder.createExpression (), NoFragment))
3553
+ appendDIExpression (DBuilder.createExpression (), NoFragment, false ))
3545
3554
emitDbgIntrinsic (Builder, llvm::ConstantInt::get (IGM.Int64Ty , 0 ), Var,
3546
3555
DIExpr, DInstLine, DInstLoc.Column , Scope, DS,
3547
3556
Indirection == CoroDirectValue ||
0 commit comments