Skip to content

Commit f244033

Browse files
committedOct 7, 2015
Fix crash in codegen on casting to bool &.
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*. Differential Revision: http://reviews.llvm.org/D13325 llvm-svn: 249534
1 parent 4d31a48 commit f244033

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed
 

Diff for: ‎clang/lib/CodeGen/CGExprScalar.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -1383,7 +1383,7 @@ Value *ScalarExprEmitter::VisitCastExpr(CastExpr *CE) {
13831383
case CK_LValueBitCast:
13841384
case CK_ObjCObjectLValueCast: {
13851385
Address Addr = EmitLValue(E).getAddress();
1386-
Addr = Builder.CreateElementBitCast(Addr, ConvertType(DestTy));
1386+
Addr = Builder.CreateElementBitCast(Addr, CGF.ConvertTypeForMem(DestTy));
13871387
LValue LV = CGF.MakeAddrLValue(Addr, DestTy);
13881388
return EmitLoadOfLValue(LV, CE->getExprLoc());
13891389
}

Diff for: ‎clang/test/CodeGenCXX/cast-to-ref-bool.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// RUN: %clang_cc1 -triple x86_64-apple-darwin -emit-llvm -o - %s | FileCheck %s
2+
3+
// CHECK-LABEL: main
4+
int main(int argc, char **argv) {
5+
// CHECK: load i8, i8* %
6+
// CHECK-NEXT: trunc i8 %{{.+}} to i1
7+
bool b = (bool &)argv[argc][1];
8+
return b;
9+
}

0 commit comments

Comments
 (0)
Please sign in to comment.