diff --git a/clang/lib/CodeGen/CGExprComplex.cpp b/clang/lib/CodeGen/CGExprComplex.cpp index f7a4e9e947127..4c527867bb9f3 100644 --- a/clang/lib/CodeGen/CGExprComplex.cpp +++ b/clang/lib/CodeGen/CGExprComplex.cpp @@ -431,8 +431,10 @@ ComplexPairTy ComplexExprEmitter::EmitComplexToComplexCast(ComplexPairTy Val, // C99 6.3.1.6: When a value of complex type is converted to another // complex type, both the real and imaginary parts follow the conversion // rules for the corresponding real types. - Val.first = CGF.EmitScalarConversion(Val.first, SrcType, DestType, Loc); - Val.second = CGF.EmitScalarConversion(Val.second, SrcType, DestType, Loc); + if (Val.first) + Val.first = CGF.EmitScalarConversion(Val.first, SrcType, DestType, Loc); + if (Val.second) + Val.second = CGF.EmitScalarConversion(Val.second, SrcType, DestType, Loc); return Val; } diff --git a/clang/test/CodeGen/complex-convert.c b/clang/test/CodeGen/complex-convert.c index 5d2e9d706bdc0..6d0291aa4274b 100644 --- a/clang/test/CodeGen/complex-convert.c +++ b/clang/test/CodeGen/complex-convert.c @@ -722,3 +722,8 @@ void foo(signed char sc, unsigned char uc, signed long long sll, // CHECK-NEXT: store i[[LLSIZE]] %[[VAR441]], i[[LLSIZE]]* %[[VAR443]] } +// This code used to cause a crash; test that it no longer does so. +_Complex int a; +void pr44624(void) { + (_Complex double) a; +}