[PATCH] D73545: Fix a crash when casting _Complex and ignoring the results

2020-01-28 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman closed this revision.
aaron.ballman added a comment.

Committed in 554791928088d6139e0fb3480d79cd76ea59198f 



CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D73545/new/

https://reviews.llvm.org/D73545



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D73545: Fix a crash when casting _Complex and ignoring the results

2020-01-28 Thread John McCall via Phabricator via cfe-commits
rjmccall accepted this revision.
rjmccall added a comment.
This revision is now accepted and ready to land.

LGTM


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D73545/new/

https://reviews.llvm.org/D73545



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D73545: Fix a crash when casting _Complex and ignoring the results

2020-01-28 Thread Aaron Ballman via Phabricator via cfe-commits
aaron.ballman created this revision.
aaron.ballman added reviewers: rjmccall, jyknight, lebedev.ri.

Performing a cast where the result is ignored causes 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.


https://reviews.llvm.org/D73545

Files:
  clang/lib/CodeGen/CGExprComplex.cpp
  clang/test/CodeGen/complex-convert.c


Index: clang/test/CodeGen/complex-convert.c
===
--- clang/test/CodeGen/complex-convert.c
+++ clang/test/CodeGen/complex-convert.c
@@ -722,3 +722,8 @@
   // 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;
+}
Index: clang/lib/CodeGen/CGExprComplex.cpp
===
--- clang/lib/CodeGen/CGExprComplex.cpp
+++ clang/lib/CodeGen/CGExprComplex.cpp
@@ -431,8 +431,10 @@
   // 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;
 }
 


Index: clang/test/CodeGen/complex-convert.c
===
--- clang/test/CodeGen/complex-convert.c
+++ clang/test/CodeGen/complex-convert.c
@@ -722,3 +722,8 @@
   // 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;
+}
Index: clang/lib/CodeGen/CGExprComplex.cpp
===
--- clang/lib/CodeGen/CGExprComplex.cpp
+++ clang/lib/CodeGen/CGExprComplex.cpp
@@ -431,8 +431,10 @@
   // 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;
 }
 
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits