summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang/lib/CodeGen/CGExprScalar.cpp2
-rw-r--r--clang/test/CodeGenCXX/cast-to-ref-bool.cpp9
2 files changed, 10 insertions, 1 deletions
diff --git a/clang/lib/CodeGen/CGExprScalar.cpp b/clang/lib/CodeGen/CGExprScalar.cpp
index 44a8646c119..6a40e4ed86f 100644
--- a/clang/lib/CodeGen/CGExprScalar.cpp
+++ b/clang/lib/CodeGen/CGExprScalar.cpp
@@ -1383,7 +1383,7 @@ Value *ScalarExprEmitter::VisitCastExpr(CastExpr *CE) {
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());
}
diff --git a/clang/test/CodeGenCXX/cast-to-ref-bool.cpp b/clang/test/CodeGenCXX/cast-to-ref-bool.cpp
new file mode 100644
index 00000000000..10647205de3
--- /dev/null
+++ b/clang/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;
+}
OpenPOWER on IntegriCloud