summaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/CGExprScalar.cpp
diff options
context:
space:
mode:
authorAmr Hesham <amr96@programmer.net>2025-09-26 18:19:21 +0200
committerGitHub <noreply@github.com>2025-09-26 18:19:21 +0200
commit3aaa58fd903b26831f986140acbfdac4e07d4f12 (patch)
tree1f85fa2bb15f4a212a554b1c3d94f6f17f90c214 /clang/lib/CodeGen/CGExprScalar.cpp
parent7d2f6fd177fcf79564e68c9999a38b5af9982cbb (diff)
[Clang] Fix Codegen UO real/imag crash on scalar with type promotion (#160609)
Fixing codegen crash when compiling real/imag unary operators on scalar with type promotion Ref: #160583
Diffstat (limited to 'clang/lib/CodeGen/CGExprScalar.cpp')
-rw-r--r--clang/lib/CodeGen/CGExprScalar.cpp31
1 files changed, 18 insertions, 13 deletions
diff --git a/clang/lib/CodeGen/CGExprScalar.cpp b/clang/lib/CodeGen/CGExprScalar.cpp
index 4fa25c5d6666..f319b176513f 100644
--- a/clang/lib/CodeGen/CGExprScalar.cpp
+++ b/clang/lib/CodeGen/CGExprScalar.cpp
@@ -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;
@@ -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;