Skip to content

Commit 5547919

Browse files
committed
Fix a crash when casting _Complex and ignoring the results.
Performing a cast where the result is ignored caused Clang to crash when performing codegen for the conversion: _Complex int a; void fn1() { (_Complex double) a; } This patch addresses the crash by not trying to emit the scalar conversions, causing it to be a noop. Fixes PR44624.
1 parent da6a896 commit 5547919

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

clang/lib/CodeGen/CGExprComplex.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -431,8 +431,10 @@ ComplexPairTy ComplexExprEmitter::EmitComplexToComplexCast(ComplexPairTy Val,
431431
// C99 6.3.1.6: When a value of complex type is converted to another
432432
// complex type, both the real and imaginary parts follow the conversion
433433
// rules for the corresponding real types.
434-
Val.first = CGF.EmitScalarConversion(Val.first, SrcType, DestType, Loc);
435-
Val.second = CGF.EmitScalarConversion(Val.second, SrcType, DestType, Loc);
434+
if (Val.first)
435+
Val.first = CGF.EmitScalarConversion(Val.first, SrcType, DestType, Loc);
436+
if (Val.second)
437+
Val.second = CGF.EmitScalarConversion(Val.second, SrcType, DestType, Loc);
436438
return Val;
437439
}
438440

clang/test/CodeGen/complex-convert.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,3 +722,8 @@ void foo(signed char sc, unsigned char uc, signed long long sll,
722722
// CHECK-NEXT: store i[[LLSIZE]] %[[VAR441]], i[[LLSIZE]]* %[[VAR443]]
723723
}
724724

725+
// This code used to cause a crash; test that it no longer does so.
726+
_Complex int a;
727+
void pr44624(void) {
728+
(_Complex double) a;
729+
}

0 commit comments

Comments
 (0)