Skip to content

Commit 28f769f

Browse files
author
git apple-llvm automerger
committed
Merge commit '3aaa58fd903b' from llvm.org/main into next
2 parents ca9a148 + 3aaa58f commit 28f769f

File tree

3 files changed

+500
-14
lines changed

3 files changed

+500
-14
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -566,6 +566,7 @@ Crash and bug fixes
566566
- Fixed a crash in the static analyzer that when the expression in an
567567
``[[assume(expr)]]`` attribute was enclosed in parentheses. (#GH151529)
568568
- Fixed a crash when parsing ``#embed`` parameters with unmatched closing brackets. (#GH152829)
569+
- Fixed a crash when compiling ``__real__`` or ``__imag__`` unary operator on scalar value with type promotion. (#GH160583)
569570

570571
Improvements
571572
^^^^^^^^^^^^

clang/lib/CodeGen/CGExprScalar.cpp

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3832,17 +3832,19 @@ Value *ScalarExprEmitter::VisitReal(const UnaryOperator *E,
38323832
// If it's an l-value, load through the appropriate subobject l-value.
38333833
// Note that we have to ask E because Op might be an l-value that
38343834
// this won't work for, e.g. an Obj-C property.
3835-
if (E->isGLValue()) {
3835+
if (E->isGLValue()) {
38363836
if (!PromotionType.isNull()) {
38373837
CodeGenFunction::ComplexPairTy result = CGF.EmitComplexExpr(
38383838
Op, /*IgnoreReal*/ IgnoreResultAssign, /*IgnoreImag*/ true);
3839-
if (result.first)
3840-
result.first = CGF.EmitPromotedValue(result, PromotionType).first;
3841-
return result.first;
3842-
} else {
3843-
return CGF.EmitLoadOfLValue(CGF.EmitLValue(E), E->getExprLoc())
3844-
.getScalarVal();
3839+
PromotionType = PromotionType->isAnyComplexType()
3840+
? PromotionType
3841+
: CGF.getContext().getComplexType(PromotionType);
3842+
return result.first ? CGF.EmitPromotedValue(result, PromotionType).first
3843+
: result.first;
38453844
}
3845+
3846+
return CGF.EmitLoadOfLValue(CGF.EmitLValue(E), E->getExprLoc())
3847+
.getScalarVal();
38463848
}
38473849
// Otherwise, calculate and project.
38483850
return CGF.EmitComplexExpr(Op, false, true).first;
@@ -3875,13 +3877,16 @@ Value *ScalarExprEmitter::VisitImag(const UnaryOperator *E,
38753877
if (!PromotionType.isNull()) {
38763878
CodeGenFunction::ComplexPairTy result = CGF.EmitComplexExpr(
38773879
Op, /*IgnoreReal*/ true, /*IgnoreImag*/ IgnoreResultAssign);
3878-
if (result.second)
3879-
result.second = CGF.EmitPromotedValue(result, PromotionType).second;
3880-
return result.second;
3881-
} else {
3882-
return CGF.EmitLoadOfLValue(CGF.EmitLValue(E), E->getExprLoc())
3883-
.getScalarVal();
3880+
PromotionType = PromotionType->isAnyComplexType()
3881+
? PromotionType
3882+
: CGF.getContext().getComplexType(PromotionType);
3883+
return result.second
3884+
? CGF.EmitPromotedValue(result, PromotionType).second
3885+
: result.second;
38843886
}
3887+
3888+
return CGF.EmitLoadOfLValue(CGF.EmitLValue(E), E->getExprLoc())
3889+
.getScalarVal();
38853890
}
38863891
// Otherwise, calculate and project.
38873892
return CGF.EmitComplexExpr(Op, true, false).second;

0 commit comments

Comments
 (0)