Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,7 @@ Crash and bug fixes
- Fixed a crash in the static analyzer that when the expression in an
``[[assume(expr)]]`` attribute was enclosed in parentheses. (#GH151529)
- Fixed a crash when parsing ``#embed`` parameters with unmatched closing brackets. (#GH152829)
- Fixed a crash when compiling ``__real__`` or ``__imag__`` unary operator on scalar value with type promotion. (#GH160583)

Improvements
^^^^^^^^^^^^
Expand Down
31 changes: 18 additions & 13 deletions clang/lib/CodeGen/CGExprScalar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3672,17 +3672,19 @@ Value *ScalarExprEmitter::VisitReal(const UnaryOperator *E,
// If it's an l-value, load through the appropriate subobject l-value.
// Note that we have to ask E because Op might be an l-value that
// this won't work for, e.g. an Obj-C property.
if (E->isGLValue()) {
if (E->isGLValue()) {
if (!PromotionType.isNull()) {
CodeGenFunction::ComplexPairTy result = CGF.EmitComplexExpr(
Op, /*IgnoreReal*/ IgnoreResultAssign, /*IgnoreImag*/ true);
if (result.first)
result.first = CGF.EmitPromotedValue(result, PromotionType).first;
return result.first;
} else {
return CGF.EmitLoadOfLValue(CGF.EmitLValue(E), E->getExprLoc())
.getScalarVal();
PromotionType = PromotionType->isAnyComplexType()
? PromotionType
: CGF.getContext().getComplexType(PromotionType);
return result.first ? CGF.EmitPromotedValue(result, PromotionType).first
: result.first;
}

return CGF.EmitLoadOfLValue(CGF.EmitLValue(E), E->getExprLoc())
.getScalarVal();
}
// Otherwise, calculate and project.
return CGF.EmitComplexExpr(Op, false, true).first;
Expand Down Expand Up @@ -3715,13 +3717,16 @@ Value *ScalarExprEmitter::VisitImag(const UnaryOperator *E,
if (!PromotionType.isNull()) {
CodeGenFunction::ComplexPairTy result = CGF.EmitComplexExpr(
Op, /*IgnoreReal*/ true, /*IgnoreImag*/ IgnoreResultAssign);
if (result.second)
result.second = CGF.EmitPromotedValue(result, PromotionType).second;
return result.second;
} else {
return CGF.EmitLoadOfLValue(CGF.EmitLValue(E), E->getExprLoc())
.getScalarVal();
PromotionType = PromotionType->isAnyComplexType()
? PromotionType
: CGF.getContext().getComplexType(PromotionType);
return result.second
? CGF.EmitPromotedValue(result, PromotionType).second
: result.second;
}

return CGF.EmitLoadOfLValue(CGF.EmitLValue(E), E->getExprLoc())
.getScalarVal();
}
// Otherwise, calculate and project.
return CGF.EmitComplexExpr(Op, true, false).second;
Expand Down
9 changes: 9 additions & 0 deletions clang/test/CodeGen/complex.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,12 @@ void t92(void) {
(0 ? (_Complex double) 2.0f : 2.0f);
}

void real_on_scalar_with_type_promotion() {
_Float16 _Complex a;
_Float16 b = __real__(__real__ a);
}

void imag_on_scalar_with_type_promotion() {
_Float16 _Complex a;
_Float16 b = __real__(__imag__ a);
}