Index: lib/CodeGen/CGExprScalar.cpp =================================================================== --- lib/CodeGen/CGExprScalar.cpp +++ lib/CodeGen/CGExprScalar.cpp @@ -2712,8 +2712,10 @@ // LLVM requires the LHS and RHS to be the same type: promote or truncate the // RHS to the same size as the LHS. Value *RHS = Ops.RHS; - if (Ops.LHS->getType() != RHS->getType()) - RHS = Builder.CreateIntCast(RHS, Ops.LHS->getType(), false, "sh_prom"); + if (Ops.LHS->getType() != RHS->getType()) { + bool isSigned = dyn_cast(Ops.E)->getRHS()->getType().getTypePtr()->isSignedIntegerType(); + RHS = Builder.CreateIntCast(RHS, Ops.LHS->getType(), isSigned, "sh_prom"); + } bool SanitizeBase = CGF.SanOpts.has(SanitizerKind::ShiftBase) && Ops.Ty->hasSignedIntegerRepresentation(); Index: test/CodeGenOpenCL/opencl_rhs_signed.cl =================================================================== --- test/CodeGenOpenCL/opencl_rhs_signed.cl +++ test/CodeGenOpenCL/opencl_rhs_signed.cl @@ -0,0 +1,7 @@ +// RUN: %clang_cc1 %s -emit-llvm -o - -O0 +// XFAIL: * + +void foo() +{ + int x[(long long)8L<< (short)-5]; +}