ABataev created this revision. ABataev added a reviewer: rjmccall. ABataev added a subscriber: cfe-commits.
Currently codegen crashes trying to emit casting to `bool &`. It happens because `bool` type is converted to `i1` and later then lvalue for reference is converted to `i1*`. But when codegen tries to load this lvalue it crashes trying to load value from this `i1*`. http://reviews.llvm.org/D13325 Files: lib/CodeGen/CGExprScalar.cpp test/CodeGenCXX/cast-to-ref-bool.cpp Index: lib/CodeGen/CGExprScalar.cpp =================================================================== --- lib/CodeGen/CGExprScalar.cpp +++ lib/CodeGen/CGExprScalar.cpp @@ -1369,7 +1369,7 @@ case CK_LValueBitCast: case CK_ObjCObjectLValueCast: { Address Addr = EmitLValue(E).getAddress(); - Addr = Builder.CreateElementBitCast(Addr, ConvertType(DestTy)); + Addr = Builder.CreateElementBitCast(Addr, CGF.ConvertTypeForMem(DestTy)); LValue LV = CGF.MakeAddrLValue(Addr, DestTy); return EmitLoadOfLValue(LV, CE->getExprLoc()); } Index: test/CodeGenCXX/cast-to-ref-bool.cpp =================================================================== --- test/CodeGenCXX/cast-to-ref-bool.cpp +++ test/CodeGenCXX/cast-to-ref-bool.cpp @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin -emit-llvm -o - %s | FileCheck %s + +// CHECK-LABEL: main +int main(int argc, char **argv) { + // CHECK: load i8, i8* % + // CHECK-NEXT: trunc i8 %{{.+}} to i1 + bool b = (bool &)argv[argc][1]; + return b; +}
Index: lib/CodeGen/CGExprScalar.cpp =================================================================== --- lib/CodeGen/CGExprScalar.cpp +++ lib/CodeGen/CGExprScalar.cpp @@ -1369,7 +1369,7 @@ case CK_LValueBitCast: case CK_ObjCObjectLValueCast: { Address Addr = EmitLValue(E).getAddress(); - Addr = Builder.CreateElementBitCast(Addr, ConvertType(DestTy)); + Addr = Builder.CreateElementBitCast(Addr, CGF.ConvertTypeForMem(DestTy)); LValue LV = CGF.MakeAddrLValue(Addr, DestTy); return EmitLoadOfLValue(LV, CE->getExprLoc()); } Index: test/CodeGenCXX/cast-to-ref-bool.cpp =================================================================== --- test/CodeGenCXX/cast-to-ref-bool.cpp +++ test/CodeGenCXX/cast-to-ref-bool.cpp @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 -triple x86_64-apple-darwin -emit-llvm -o - %s | FileCheck %s + +// CHECK-LABEL: main +int main(int argc, char **argv) { + // CHECK: load i8, i8* % + // CHECK-NEXT: trunc i8 %{{.+}} to i1 + bool b = (bool &)argv[argc][1]; + return b; +}
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits