Index: lib/CodeGen/CGExpr.cpp =================================================================== --- lib/CodeGen/CGExpr.cpp +++ lib/CodeGen/CGExpr.cpp @@ -96,10 +96,12 @@ } QualType BoolTy = getContext().BoolTy; + SourceLocation Loc = E->getExprLoc(); if (!E->getType()->isAnyComplexType()) - return EmitScalarConversion(EmitScalarExpr(E), E->getType(), BoolTy); + return EmitScalarConversion(EmitScalarExpr(E), E->getType(), BoolTy, Loc); - return EmitComplexToScalarConversion(EmitComplexExpr(E), E->getType(),BoolTy); + return EmitComplexToScalarConversion(EmitComplexExpr(E), E->getType(), BoolTy, + Loc); } /// EmitIgnoredExpr - Emit code to compute the specified expression, Index: lib/CodeGen/CGExprComplex.cpp =================================================================== --- lib/CodeGen/CGExprComplex.cpp +++ lib/CodeGen/CGExprComplex.cpp @@ -85,10 +85,10 @@ /// Emit a cast from complex value Val to DestType. ComplexPairTy EmitComplexToComplexCast(ComplexPairTy Val, QualType SrcType, - QualType DestType); + QualType DestType, SourceLocation Loc); /// Emit a cast from scalar value Val to DestType. ComplexPairTy EmitScalarToComplexCast(llvm::Value *Val, QualType SrcType, - QualType DestType); + QualType DestType, SourceLocation Loc); //===--------------------------------------------------------------------===// // Visitor Methods @@ -394,7 +394,8 @@ /// Emit a cast from complex value Val to DestType. ComplexPairTy ComplexExprEmitter::EmitComplexToComplexCast(ComplexPairTy Val, QualType SrcType, - QualType DestType) { + QualType DestType, + SourceLocation Loc) { // Get the src/dest element type. SrcType = SrcType->castAs()->getElementType(); DestType = DestType->castAs()->getElementType(); @@ -402,17 +403,18 @@ // 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); - Val.second = CGF.EmitScalarConversion(Val.second, SrcType, DestType); + Val.first = CGF.EmitScalarConversion(Val.first, SrcType, DestType, Loc); + Val.second = CGF.EmitScalarConversion(Val.second, SrcType, DestType, Loc); return Val; } ComplexPairTy ComplexExprEmitter::EmitScalarToComplexCast(llvm::Value *Val, QualType SrcType, - QualType DestType) { + QualType DestType, + SourceLocation Loc) { // Convert the input element to the element type of the complex. DestType = DestType->castAs()->getElementType(); - Val = CGF.EmitScalarConversion(Val, SrcType, DestType); + Val = CGF.EmitScalarConversion(Val, SrcType, DestType, Loc); // Return (realval, 0). return ComplexPairTy(Val, llvm::Constant::getNullValue(Val->getType())); @@ -488,14 +490,15 @@ case CK_FloatingRealToComplex: case CK_IntegralRealToComplex: - return EmitScalarToComplexCast(CGF.EmitScalarExpr(Op), - Op->getType(), DestTy); + return EmitScalarToComplexCast(CGF.EmitScalarExpr(Op), Op->getType(), + DestTy, Op->getExprLoc()); case CK_FloatingComplexCast: case CK_FloatingComplexToIntegralComplex: case CK_IntegralComplexCast: case CK_IntegralComplexToFloatingComplex: - return EmitComplexToComplexCast(Visit(Op), Op->getType(), DestTy); + return EmitComplexToComplexCast(Visit(Op), Op->getType(), DestTy, + Op->getExprLoc()); } llvm_unreachable("unknown cast resulting in complex value"); @@ -846,19 +849,20 @@ LValue LHS = CGF.EmitLValue(E->getLHS()); // Load from the l-value and convert it. + SourceLocation Loc = E->getExprLoc(); if (LHSTy->isAnyComplexType()) { - ComplexPairTy LHSVal = EmitLoadOfLValue(LHS, E->getExprLoc()); - OpInfo.LHS = EmitComplexToComplexCast(LHSVal, LHSTy, OpInfo.Ty); + ComplexPairTy LHSVal = EmitLoadOfLValue(LHS, Loc); + OpInfo.LHS = EmitComplexToComplexCast(LHSVal, LHSTy, OpInfo.Ty, Loc); } else { - llvm::Value *LHSVal = CGF.EmitLoadOfScalar(LHS, E->getExprLoc()); + llvm::Value *LHSVal = CGF.EmitLoadOfScalar(LHS, Loc); // For floating point real operands we can directly pass the scalar form // to the binary operator emission and potentially get more efficient code. if (LHSTy->isRealFloatingType()) { if (!CGF.getContext().hasSameUnqualifiedType(ComplexElementTy, LHSTy)) - LHSVal = CGF.EmitScalarConversion(LHSVal, LHSTy, ComplexElementTy); + LHSVal = CGF.EmitScalarConversion(LHSVal, LHSTy, ComplexElementTy, Loc); OpInfo.LHS = ComplexPairTy(LHSVal, nullptr); } else { - OpInfo.LHS = EmitScalarToComplexCast(LHSVal, LHSTy, OpInfo.Ty); + OpInfo.LHS = EmitScalarToComplexCast(LHSVal, LHSTy, OpInfo.Ty, Loc); } } @@ -867,12 +871,13 @@ // Truncate the result and store it into the LHS lvalue. if (LHSTy->isAnyComplexType()) { - ComplexPairTy ResVal = EmitComplexToComplexCast(Result, OpInfo.Ty, LHSTy); + ComplexPairTy ResVal = + EmitComplexToComplexCast(Result, OpInfo.Ty, LHSTy, Loc); EmitStoreOfComplex(ResVal, LHS, /*isInit*/ false); Val = RValue::getComplex(ResVal); } else { llvm::Value *ResVal = - CGF.EmitComplexToScalarConversion(Result, OpInfo.Ty, LHSTy); + CGF.EmitComplexToScalarConversion(Result, OpInfo.Ty, LHSTy, Loc); CGF.EmitStoreOfScalar(ResVal, LHS, /*isInit*/ false); Val = RValue::get(ResVal); } Index: lib/CodeGen/CGExprScalar.cpp =================================================================== --- lib/CodeGen/CGExprScalar.cpp +++ lib/CodeGen/CGExprScalar.cpp @@ -143,17 +143,19 @@ /// Emit a check that a conversion to or from a floating-point type does not /// overflow. void EmitFloatConversionCheck(Value *OrigSrc, QualType OrigSrcType, - Value *Src, QualType SrcType, - QualType DstType, llvm::Type *DstTy); + Value *Src, QualType SrcType, QualType DstType, + llvm::Type *DstTy, SourceLocation Loc); /// Emit a conversion from the specified type to the specified destination /// type, both of which are LLVM scalar types. - Value *EmitScalarConversion(Value *Src, QualType SrcTy, QualType DstTy); + Value *EmitScalarConversion(Value *Src, QualType SrcTy, QualType DstTy, + SourceLocation Loc); /// Emit a conversion from the specified complex type to the specified /// destination type, where the destination type is an LLVM scalar type. Value *EmitComplexToScalarConversion(CodeGenFunction::ComplexPairTy Src, - QualType SrcTy, QualType DstTy); + QualType SrcTy, QualType DstTy, + SourceLocation Loc); /// EmitNullValue - Emit a value that corresponds to null for the given type. Value *EmitNullValue(QualType Ty); @@ -593,11 +595,9 @@ return EmitPointerToBoolConversion(Src); } -void ScalarExprEmitter::EmitFloatConversionCheck(Value *OrigSrc, - QualType OrigSrcType, - Value *Src, QualType SrcType, - QualType DstType, - llvm::Type *DstTy) { +void ScalarExprEmitter::EmitFloatConversionCheck( + Value *OrigSrc, QualType OrigSrcType, Value *Src, QualType SrcType, + QualType DstType, llvm::Type *DstTy, SourceLocation Loc) { CodeGenFunction::SanitizerScope SanScope(&CGF); using llvm::APFloat; using llvm::APSInt; @@ -721,11 +721,9 @@ } } - // FIXME: Provide a SourceLocation. - llvm::Constant *StaticArgs[] = { - CGF.EmitCheckTypeDescriptor(OrigSrcType), - CGF.EmitCheckTypeDescriptor(DstType) - }; + llvm::Constant *StaticArgs[] = {CGF.EmitCheckSourceLocation(Loc), + CGF.EmitCheckTypeDescriptor(OrigSrcType), + CGF.EmitCheckTypeDescriptor(DstType)}; CGF.EmitCheck(std::make_pair(Check, SanitizerKind::FloatCastOverflow), "float_cast_overflow", StaticArgs, OrigSrc); } @@ -733,7 +731,8 @@ /// Emit a conversion from the specified type to the specified destination type, /// both of which are LLVM scalar types. Value *ScalarExprEmitter::EmitScalarConversion(Value *Src, QualType SrcType, - QualType DstType) { + QualType DstType, + SourceLocation Loc) { SrcType = CGF.getContext().getCanonicalType(SrcType); DstType = CGF.getContext().getCanonicalType(DstType); if (SrcType == DstType) return Src; @@ -808,7 +807,7 @@ if (DstType->isExtVectorType() && !SrcType->isVectorType()) { // Cast the scalar to element type QualType EltTy = DstType->getAs()->getElementType(); - llvm::Value *Elt = EmitScalarConversion(Src, SrcType, EltTy); + llvm::Value *Elt = EmitScalarConversion(Src, SrcType, EltTy, Loc); // Splat the element across to all elements unsigned NumElements = cast(DstTy)->getNumElements(); @@ -828,8 +827,8 @@ // or the destination type is a floating-point type. if (CGF.SanOpts.has(SanitizerKind::FloatCastOverflow) && (OrigSrcType->isFloatingType() || DstType->isFloatingType())) - EmitFloatConversionCheck(OrigSrc, OrigSrcType, Src, SrcType, DstType, - DstTy); + EmitFloatConversionCheck(OrigSrc, OrigSrcType, Src, SrcType, DstType, DstTy, + Loc); // Cast to half through float if half isn't a native type. if (DstType->isHalfType() && !CGF.getContext().getLangOpts().NativeHalfType) { @@ -885,17 +884,17 @@ /// Emit a conversion from the specified complex type to the specified /// destination type, where the destination type is an LLVM scalar type. -Value *ScalarExprEmitter:: -EmitComplexToScalarConversion(CodeGenFunction::ComplexPairTy Src, - QualType SrcTy, QualType DstTy) { +Value *ScalarExprEmitter::EmitComplexToScalarConversion( + CodeGenFunction::ComplexPairTy Src, QualType SrcTy, QualType DstTy, + SourceLocation Loc) { // Get the source element type. SrcTy = SrcTy->castAs()->getElementType(); // Handle conversions to bool first, they are special: comparisons against 0. if (DstTy->isBooleanType()) { // Complex != 0 -> (Real != 0) | (Imag != 0) - Src.first = EmitScalarConversion(Src.first, SrcTy, DstTy); - Src.second = EmitScalarConversion(Src.second, SrcTy, DstTy); + Src.first = EmitScalarConversion(Src.first, SrcTy, DstTy, Loc); + Src.second = EmitScalarConversion(Src.second, SrcTy, DstTy, Loc); return Builder.CreateOr(Src.first, Src.second, "tobool"); } @@ -903,7 +902,7 @@ // the imaginary part of the complex value is discarded and the value of the // real part is converted according to the conversion rules for the // corresponding real type. - return EmitScalarConversion(Src.first, SrcTy, DstTy); + return EmitScalarConversion(Src.first, SrcTy, DstTy, Loc); } Value *ScalarExprEmitter::EmitNullValue(QualType Ty) { @@ -1559,7 +1558,8 @@ llvm::Type *DstTy = ConvertType(DestTy); Value *Elt = Visit(const_cast(E)); Elt = EmitScalarConversion(Elt, E->getType(), - DestTy->getAs()->getElementType()); + DestTy->getAs()->getElementType(), + CE->getExprLoc()); // Splat the element across to all elements unsigned NumElements = cast(DstTy)->getNumElements(); @@ -1570,7 +1570,8 @@ case CK_IntegralToFloating: case CK_FloatingToIntegral: case CK_FloatingCast: - return EmitScalarConversion(Visit(E), E->getType(), DestTy); + return EmitScalarConversion(Visit(E), E->getType(), DestTy, + CE->getExprLoc()); case CK_IntegralToBoolean: return EmitIntToBoolConversion(Visit(E)); case CK_PointerToBoolean: @@ -1592,7 +1593,8 @@ CodeGenFunction::ComplexPairTy V = CGF.EmitComplexExpr(E); // TODO: kill this function off, inline appropriate case here - return EmitComplexToScalarConversion(V, E->getType(), DestTy); + return EmitComplexToScalarConversion(V, E->getType(), DestTy, + CE->getExprLoc()); } case CK_ZeroToOCLEvent: { @@ -2168,8 +2170,10 @@ llvm_unreachable("Invalid compound assignment type"); } if (aop != llvm::AtomicRMWInst::BAD_BINOP) { - llvm::Value *amt = CGF.EmitToMemory(EmitScalarConversion(OpInfo.RHS, - E->getRHS()->getType(), LHSTy), LHSTy); + llvm::Value *amt = CGF.EmitToMemory( + EmitScalarConversion(OpInfo.RHS, E->getRHS()->getType(), LHSTy, + E->getExprLoc()), + LHSTy); Builder.CreateAtomicRMW(aop, LHSLV.getAddress(), amt, llvm::SequentiallyConsistent); return LHSLV; @@ -2190,14 +2194,16 @@ else OpInfo.LHS = EmitLoadOfLValue(LHSLV, E->getExprLoc()); - OpInfo.LHS = EmitScalarConversion(OpInfo.LHS, LHSTy, - E->getComputationLHSType()); + SourceLocation Loc = E->getExprLoc(); + OpInfo.LHS = + EmitScalarConversion(OpInfo.LHS, LHSTy, E->getComputationLHSType(), Loc); // Expand the binary operator. Result = (this->*Func)(OpInfo); // Convert the result back to the LHS type. - Result = EmitScalarConversion(Result, E->getComputationResultType(), LHSTy); + Result = + EmitScalarConversion(Result, E->getComputationResultType(), LHSTy, Loc); if (atomicPHI) { llvm::BasicBlock *opBB = Builder.GetInsertBlock(); @@ -2921,7 +2927,8 @@ Value *CR6Param = Builder.getInt32(CR6); llvm::Function *F = CGF.CGM.getIntrinsic(ID); Result = Builder.CreateCall(F, {CR6Param, FirstVecArg, SecondVecArg}); - return EmitScalarConversion(Result, CGF.getContext().BoolTy, E->getType()); + return EmitScalarConversion(Result, CGF.getContext().BoolTy, E->getType(), + E->getExprLoc()); } if (LHS->getType()->isFPOrFPVectorTy()) { @@ -2990,7 +2997,8 @@ } } - return EmitScalarConversion(Result, CGF.getContext().BoolTy, E->getType()); + return EmitScalarConversion(Result, CGF.getContext().BoolTy, E->getType(), + E->getExprLoc()); } Value *ScalarExprEmitter::VisitBinAssign(const BinaryOperator *E) { @@ -3472,21 +3480,23 @@ /// Emit a conversion from the specified type to the specified destination type, /// both of which are LLVM scalar types. Value *CodeGenFunction::EmitScalarConversion(Value *Src, QualType SrcTy, - QualType DstTy) { + QualType DstTy, + SourceLocation Loc) { assert(hasScalarEvaluationKind(SrcTy) && hasScalarEvaluationKind(DstTy) && "Invalid scalar expression to emit"); - return ScalarExprEmitter(*this).EmitScalarConversion(Src, SrcTy, DstTy); + return ScalarExprEmitter(*this).EmitScalarConversion(Src, SrcTy, DstTy, Loc); } /// Emit a conversion from the specified complex type to the specified /// destination type, where the destination type is an LLVM scalar type. Value *CodeGenFunction::EmitComplexToScalarConversion(ComplexPairTy Src, QualType SrcTy, - QualType DstTy) { + QualType DstTy, + SourceLocation Loc) { assert(SrcTy->isAnyComplexType() && hasScalarEvaluationKind(DstTy) && "Invalid complex -> scalar conversion"); - return ScalarExprEmitter(*this).EmitComplexToScalarConversion(Src, SrcTy, - DstTy); + return ScalarExprEmitter(*this) + .EmitComplexToScalarConversion(Src, SrcTy, DstTy, Loc); } Index: lib/CodeGen/CGOpenMPRuntime.cpp =================================================================== --- lib/CodeGen/CGOpenMPRuntime.cpp +++ lib/CodeGen/CGOpenMPRuntime.cpp @@ -1284,12 +1284,12 @@ } static void emitIfStmt(CodeGenFunction &CGF, llvm::Value *IfCond, - OpenMPDirectiveKind Kind, + OpenMPDirectiveKind Kind, SourceLocation Loc, const RegionCodeGenTy &BodyOpGen) { llvm::Value *CallBool = CGF.EmitScalarConversion( IfCond, CGF.getContext().getIntTypeForBitwidth(/*DestWidth=*/32, /*Signed=*/true), - CGF.getContext().BoolTy); + CGF.getContext().BoolTy, Loc); auto *ThenBlock = CGF.createBasicBlock("omp_if.then"); auto *ContBlock = CGF.createBasicBlock("omp_if.end"); @@ -1315,13 +1315,14 @@ CGF.EmitRuntimeCall(createRuntimeFunction(OMPRTL__kmpc_master), Args); typedef CallEndCleanup::value> MasterCallEndCleanup; - emitIfStmt(CGF, IsMaster, OMPD_master, [&](CodeGenFunction &CGF) -> void { - CodeGenFunction::RunCleanupsScope Scope(CGF); - CGF.EHStack.pushCleanup( - NormalAndEHCleanup, createRuntimeFunction(OMPRTL__kmpc_end_master), - llvm::makeArrayRef(Args)); - MasterOpGen(CGF); - }); + emitIfStmt( + CGF, IsMaster, OMPD_master, Loc, [&](CodeGenFunction &CGF) -> void { + CodeGenFunction::RunCleanupsScope Scope(CGF); + CGF.EHStack.pushCleanup( + NormalAndEHCleanup, createRuntimeFunction(OMPRTL__kmpc_end_master), + llvm::makeArrayRef(Args)); + MasterOpGen(CGF); + }); } void CGOpenMPRuntime::emitTaskyieldCall(CodeGenFunction &CGF, @@ -1444,18 +1445,19 @@ CGF.EmitRuntimeCall(createRuntimeFunction(OMPRTL__kmpc_single), Args); typedef CallEndCleanup::value> SingleCallEndCleanup; - emitIfStmt(CGF, IsSingle, OMPD_single, [&](CodeGenFunction &CGF) -> void { - CodeGenFunction::RunCleanupsScope Scope(CGF); - CGF.EHStack.pushCleanup( - NormalAndEHCleanup, createRuntimeFunction(OMPRTL__kmpc_end_single), - llvm::makeArrayRef(Args)); - SingleOpGen(CGF); - if (DidIt) { - // did_it = 1; - CGF.Builder.CreateAlignedStore(CGF.Builder.getInt32(1), DidIt, - DidIt->getAlignment()); - } - }); + emitIfStmt( + CGF, IsSingle, OMPD_single, Loc, [&](CodeGenFunction &CGF) -> void { + CodeGenFunction::RunCleanupsScope Scope(CGF); + CGF.EHStack.pushCleanup( + NormalAndEHCleanup, createRuntimeFunction(OMPRTL__kmpc_end_single), + llvm::makeArrayRef(Args)); + SingleOpGen(CGF); + if (DidIt) { + // did_it = 1; + CGF.Builder.CreateAlignedStore(CGF.Builder.getInt32(1), DidIt, + DidIt->getAlignment()); + } + }); // call __kmpc_copyprivate(ident_t *, gtid, , , // , did_it); if (DidIt) { @@ -1719,7 +1721,7 @@ CGF.EmitRuntimeCall(createDispatchNextFunction(IVSize, IVSigned), Args); return CGF.EmitScalarConversion( Call, CGF.getContext().getIntTypeForBitwidth(32, /* Signed */ true), - CGF.getContext().BoolTy); + CGF.getContext().BoolTy, Loc); } void CGOpenMPRuntime::emitNumThreadsClause(CodeGenFunction &CGF, Index: lib/CodeGen/CGStmtOpenMP.cpp =================================================================== --- lib/CodeGen/CGStmtOpenMP.cpp +++ lib/CodeGen/CGStmtOpenMP.cpp @@ -1056,7 +1056,8 @@ if (!C->getHelperChunkSize() || !OuterRegion) { Chunk = CGF.EmitScalarExpr(Ch); Chunk = CGF.EmitScalarConversion(Chunk, Ch->getType(), - S.getIterationVariable()->getType()); + S.getIterationVariable()->getType(), + S.getLocStart()); } } } @@ -1673,27 +1674,29 @@ } static llvm::Value *convertToScalarValue(CodeGenFunction &CGF, RValue Val, - QualType SrcType, QualType DestType) { + QualType SrcType, QualType DestType, + SourceLocation Loc) { assert(CGF.hasScalarEvaluationKind(DestType) && "DestType must have scalar evaluation kind."); assert(!Val.isAggregate() && "Must be a scalar or complex."); return Val.isScalar() - ? CGF.EmitScalarConversion(Val.getScalarVal(), SrcType, DestType) + ? CGF.EmitScalarConversion(Val.getScalarVal(), SrcType, DestType, + Loc) : CGF.EmitComplexToScalarConversion(Val.getComplexVal(), SrcType, - DestType); + DestType, Loc); } static CodeGenFunction::ComplexPairTy convertToComplexValue(CodeGenFunction &CGF, RValue Val, QualType SrcType, - QualType DestType) { + QualType DestType, SourceLocation Loc) { assert(CGF.getEvaluationKind(DestType) == TEK_Complex && "DestType must have complex evaluation kind."); CodeGenFunction::ComplexPairTy ComplexVal; if (Val.isScalar()) { // Convert the input element to the element type of the complex. auto DestElementType = DestType->castAs()->getElementType(); - auto ScalarVal = - CGF.EmitScalarConversion(Val.getScalarVal(), SrcType, DestElementType); + auto ScalarVal = CGF.EmitScalarConversion(Val.getScalarVal(), SrcType, + DestElementType, Loc); ComplexVal = CodeGenFunction::ComplexPairTy( ScalarVal, llvm::Constant::getNullValue(ScalarVal->getType())); } else { @@ -1701,9 +1704,9 @@ auto SrcElementType = SrcType->castAs()->getElementType(); auto DestElementType = DestType->castAs()->getElementType(); ComplexVal.first = CGF.EmitScalarConversion( - Val.getComplexVal().first, SrcElementType, DestElementType); + Val.getComplexVal().first, SrcElementType, DestElementType, Loc); ComplexVal.second = CGF.EmitScalarConversion( - Val.getComplexVal().second, SrcElementType, DestElementType); + Val.getComplexVal().second, SrcElementType, DestElementType, Loc); } return ComplexVal; } @@ -1720,16 +1723,16 @@ } static void emitSimpleStore(CodeGenFunction &CGF, LValue LVal, RValue RVal, - QualType RValTy) { + QualType RValTy, SourceLocation Loc) { switch (CGF.getEvaluationKind(LVal.getType())) { case TEK_Scalar: - CGF.EmitStoreThroughLValue( - RValue::get(convertToScalarValue(CGF, RVal, RValTy, LVal.getType())), - LVal); + CGF.EmitStoreThroughLValue(RValue::get(convertToScalarValue( + CGF, RVal, RValTy, LVal.getType(), Loc)), + LVal); break; case TEK_Complex: CGF.EmitStoreOfComplex( - convertToComplexValue(CGF, RVal, RValTy, LVal.getType()), LVal, + convertToComplexValue(CGF, RVal, RValTy, LVal.getType(), Loc), LVal, /*isInit=*/false); break; case TEK_Aggregate: @@ -1757,7 +1760,7 @@ // list. if (IsSeqCst) CGF.CGM.getOpenMPRuntime().emitFlush(CGF, llvm::None, Loc); - emitSimpleStore(CGF,VLValue, Res, X->getType().getNonReferenceType()); + emitSimpleStore(CGF, VLValue, Res, X->getType().getNonReferenceType(), Loc); } static void EmitOMPAtomicWriteExpr(CodeGenFunction &CGF, bool IsSeqCst, @@ -1928,12 +1931,14 @@ } static RValue convertToType(CodeGenFunction &CGF, RValue Value, - QualType SourceType, QualType ResType) { + QualType SourceType, QualType ResType, + SourceLocation Loc) { switch (CGF.getEvaluationKind(ResType)) { case TEK_Scalar: - return RValue::get(convertToScalarValue(CGF, Value, SourceType, ResType)); + return RValue::get( + convertToScalarValue(CGF, Value, SourceType, ResType, Loc)); case TEK_Complex: { - auto Res = convertToComplexValue(CGF, Value, SourceType, ResType); + auto Res = convertToComplexValue(CGF, Value, SourceType, ResType, Loc); return RValue::getComplex(Res.first, Res.second); } case TEK_Aggregate: @@ -1998,7 +2003,7 @@ // 'x' is simply rewritten with some 'expr'. NewVValType = X->getType().getNonReferenceType(); ExprRValue = convertToType(CGF, ExprRValue, E->getType(), - X->getType().getNonReferenceType()); + X->getType().getNonReferenceType(), Loc); auto &&Gen = [&CGF, &NewVVal, ExprRValue](RValue XRValue) -> RValue { NewVVal = XRValue; return ExprRValue; @@ -2013,7 +2018,7 @@ } } // Emit post-update store to 'v' of old/new 'x' value. - emitSimpleStore(CGF, VLValue, NewVVal, NewVValType); + emitSimpleStore(CGF, VLValue, NewVVal, NewVValType, Loc); // OpenMP, 2.12.6, atomic Construct // Any atomic construct with a seq_cst clause forces the atomically // performed operation to include an implicit flush operation without a Index: lib/CodeGen/CodeGenFunction.h =================================================================== --- lib/CodeGen/CodeGenFunction.h +++ lib/CodeGen/CodeGenFunction.h @@ -2710,13 +2710,13 @@ /// Emit a conversion from the specified type to the specified destination /// type, both of which are LLVM scalar types. llvm::Value *EmitScalarConversion(llvm::Value *Src, QualType SrcTy, - QualType DstTy); + QualType DstTy, SourceLocation Loc); /// Emit a conversion from the specified complex type to the specified /// destination type, where the destination type is an LLVM scalar type. llvm::Value *EmitComplexToScalarConversion(ComplexPairTy Src, QualType SrcTy, - QualType DstTy); - + QualType DstTy, + SourceLocation Loc); /// EmitAggExpr - Emit the computation of the specified expression /// of aggregate type. The result is computed into the given slot, Index: test/CodeGen/catch-undef-behavior.c =================================================================== --- test/CodeGen/catch-undef-behavior.c +++ test/CodeGen/catch-undef-behavior.c @@ -19,6 +19,17 @@ // CHECK-UBSAN: @[[LINE_700:.*]] = {{.*}}, i32 700, i32 14 {{.*}} @[[STRUCT_S]], i64 4, i8 3 } // CHECK-UBSAN: @[[LINE_800:.*]] = {{.*}}, i32 800, i32 12 {{.*}} @{{.*}} } // CHECK-UBSAN: @[[LINE_900:.*]] = {{.*}}, i32 900, i32 11 {{.*}} @{{.*}} } +// CHECK-UBSAN: @[[LINE_1000:.*]] = {{.*}}, i32 1000, i32 10 {{.*}} @{{.*}} } +// CHECK-UBSAN: @[[FP16:.*]] = private unnamed_addr constant { i16, i16, [9 x i8] } { i16 1, i16 16, [9 x i8] c"'__fp16'\00" } +// CHECK-UBSAN: @[[LINE_1100:.*]] = {{.*}}, i32 1100, i32 8 {{.*}} @{{.*}} } +// CHECK-UBSAN: @[[LINE_1200:.*]] = {{.*}}, i32 1200, i32 10 {{.*}} @{{.*}} } +// CHECK-UBSAN: @[[LINE_1300:.*]] = {{.*}}, i32 1300, i32 10 {{.*}} @{{.*}} } +// CHECK-UBSAN: @[[LINE_1400:.*]] = {{.*}}, i32 1400, i32 10 {{.*}} @{{.*}} } +// Make sure we check the fp16 type_mismatch data so we can easily match the signed char float_cast_overflow +// CHECK-UBSAN: @[[LINE_1500:.*]] = {{.*}}, i32 1500, i32 10 {{.*}} @[[FP16]], {{.*}} } +// CHECK-UBSAN: @[[SCHAR:.*]] = private unnamed_addr constant { i16, i16, [14 x i8] } { i16 0, i16 7, [14 x i8] c"'signed char'\00" } +// CHECK-UBSAN: @[[LINE_1500:.*]] = {{.*}}, i32 1500, i32 10 {{.*}} @[[FP16]], {{.*}} } +// CHECK-UBSAN: @[[LINE_1600:.*]] = {{.*}}, i32 1600, i32 10 {{.*}} @{{.*}} } // CHECK-NULL: @[[LINE_100:.*]] = private unnamed_addr global {{.*}}, i32 100, i32 5 {{.*}} @@ -209,10 +220,11 @@ // CHECK-COMMON: %[[INBOUNDS:.*]] = icmp ule i128 %{{.*}}, -20282409603651670423947251286016 // CHECK-COMMON-NEXT: br i1 %[[INBOUNDS]] - // CHECK-UBSAN: call void @__ubsan_handle_float_cast_overflow( + // CHECK-UBSAN: call void @__ubsan_handle_float_cast_overflow(i8* bitcast ({{.*}} @[[LINE_1000]] to i8*), // CHECK-TRAP: call void @llvm.trap() [[NR_NUW]] // CHECK-TRAP-NEXT: unreachable +#line 1000 return n; } @@ -223,10 +235,11 @@ // CHECK-COMMON: %[[INBOUNDS:.*]] = and i1 %[[GE]], %[[LE]] // CHECK-COMMON-NEXT: br i1 %[[INBOUNDS]] - // CHECK-UBSAN: call void @__ubsan_handle_float_cast_overflow( + // CHECK-UBSAN: call void @__ubsan_handle_float_cast_overflow(i8* bitcast ({{.*}} @[[LINE_1100]] to i8*), // CHECK-TRAP: call void @llvm.trap() [[NR_NUW]] // CHECK-TRAP-NEXT: unreachable +#line 1100 *p = n; } @@ -239,10 +252,11 @@ // CHECK-UBSAN: %[[CAST:.*]] = bitcast float %[[F]] to i32 // CHECK-UBSAN: %[[ARG:.*]] = zext i32 %[[CAST]] to i64 - // CHECK-UBSAN: call void @__ubsan_handle_float_cast_overflow({{.*}}, i64 %[[ARG]] + // CHECK-UBSAN: call void @__ubsan_handle_float_cast_overflow(i8* bitcast ({{.*}} @[[LINE_1200]] to i8*), i64 %[[ARG]] // CHECK-TRAP: call void @llvm.trap() [[NR_NUW]] // CHECK-TRAP-NEXT: unreachable +#line 1200 return f; } @@ -257,10 +271,11 @@ // CHECK-UBSAN: store x86_fp80 %[[F]], x86_fp80* %[[ALLOCA:.*]], !nosanitize // CHECK-UBSAN: %[[ARG:.*]] = ptrtoint x86_fp80* %[[ALLOCA]] to i64 - // CHECK-UBSAN: call void @__ubsan_handle_float_cast_overflow({{.*}}, i64 %[[ARG]] + // CHECK-UBSAN: call void @__ubsan_handle_float_cast_overflow(i8* bitcast ({{.*}} @[[LINE_1300]] to i8*), i64 %[[ARG]] // CHECK-TRAP: call void @llvm.trap() [[NR_NUW]] // CHECK-TRAP-NEXT: unreachable +#line 1300 return ld; } @@ -271,10 +286,11 @@ // CHECK-COMMON: %[[INBOUNDS:.*]] = and i1 %[[GE]], %[[LE]] // CHECK-COMMON-NEXT: br i1 %[[INBOUNDS]] - // CHECK-UBSAN: call void @__ubsan_handle_float_cast_overflow( + // CHECK-UBSAN: call void @__ubsan_handle_float_cast_overflow(i8* bitcast ({{.*}} @[[LINE_1400]] to i8*), // CHECK-TRAP: call void @llvm.trap() [[NR_NUW]] // CHECK-TRAP-NEXT: unreachable +#line 1400 return f; } @@ -285,10 +301,11 @@ // CHECK-COMMON: %[[INBOUNDS:.*]] = and i1 %[[GE]], %[[LE]] // CHECK-COMMON-NEXT: br i1 %[[INBOUNDS]] - // CHECK-UBSAN: call void @__ubsan_handle_float_cast_overflow( + // CHECK-UBSAN: call void @__ubsan_handle_float_cast_overflow(i8* bitcast ({{.*}} @[[LINE_1500]] to i8*), // CHECK-TRAP: call void @llvm.trap() [[NR_NUW]] // CHECK-TRAP-NEXT: unreachable +#line 1500 return *p; } @@ -301,10 +318,11 @@ // CHECK-COMMON: %[[INBOUNDS:.*]] = xor i1 %[[OUTOFBOUNDS]], true // CHECK-COMMON-NEXT: br i1 %[[INBOUNDS]] - // CHECK-UBSAN: call void @__ubsan_handle_float_cast_overflow( + // CHECK-UBSAN: call void @__ubsan_handle_float_cast_overflow(i8* bitcast ({{.*}} @[[LINE_1600]] to i8*), // CHECK-TRAP: call void @llvm.trap() [[NR_NUW]] // CHECK-TRAP-NEXT: unreachable +#line 1600 return f; }