Index: include/clang/Basic/DiagnosticGroups.td =================================================================== --- include/clang/Basic/DiagnosticGroups.td +++ include/clang/Basic/DiagnosticGroups.td @@ -142,6 +142,7 @@ def : DiagGroup<"discard-qual">; def DivZero : DiagGroup<"division-by-zero">; def : DiagGroup<"div-by-zero", [DivZero]>; +def DivSizeofPtr : DiagGroup<"sizeof-pointer-div">; def DocumentationHTML : DiagGroup<"documentation-html">; def DocumentationUnknownCommand : DiagGroup<"documentation-unknown-command">; @@ -785,6 +786,7 @@ SelfMove, SizeofArrayArgument, SizeofArrayDecay, + DivSizeofPtr, StringPlusInt, Trigraphs, Uninitialized, Index: include/clang/Basic/DiagnosticSemaKinds.td =================================================================== --- include/clang/Basic/DiagnosticSemaKinds.td +++ include/clang/Basic/DiagnosticSemaKinds.td @@ -3291,6 +3291,10 @@ InGroup; def note_reference_is_return_value : Note<"%0 returns a reference">; +def warn_division_sizeof_ptr : Warning< + "division produces the incorrect number of array elements">, + InGroup; + def note_function_warning_silence : Note< "prefix with the address-of operator to silence this warning">; def note_function_to_function_call : Note< Index: lib/Sema/SemaExpr.cpp =================================================================== --- lib/Sema/SemaExpr.cpp +++ lib/Sema/SemaExpr.cpp @@ -115,7 +115,7 @@ return NoteDeletedInheritingConstructor(Ctor); Diag(Decl->getLocation(), diag::note_availability_specified_here) - << Decl << true; + << Decl << true; } /// Determine whether a FunctionDecl was ever declared with an @@ -170,9 +170,10 @@ if (!DowngradeWarning && UsedFn) DowngradeWarning = UsedFn->isInlined() || UsedFn->hasAttr(); - S.Diag(Loc, DowngradeWarning ? diag::ext_internal_in_extern_inline_quiet - : diag::ext_internal_in_extern_inline) - << /*IsVar=*/!UsedFn << D; + S.Diag(Loc, + DowngradeWarning ? diag::ext_internal_in_extern_inline_quiet + : diag::ext_internal_in_extern_inline) + << /*IsVar=*/!UsedFn << D; S.MaybeSuggestAddingStaticToDecl(Current); @@ -187,7 +188,7 @@ if (!hasAnyExplicitStorageClass(First)) { SourceLocation DeclBegin = First->getSourceRange().getBegin(); Diag(DeclBegin, diag::note_convert_inline_to_static) - << Cur << FixItHint::CreateInsertion(DeclBegin, "static "); + << Cur << FixItHint::CreateInsertion(DeclBegin, "static "); } } @@ -234,10 +235,10 @@ if (ParsingInitForAutoVars.count(D)) { if (isa(D)) { Diag(Loc, diag::err_binding_cannot_appear_in_own_initializer) - << D->getDeclName(); + << D->getDeclName(); } else { Diag(Loc, diag::err_auto_variable_cannot_appear_in_own_initializer) - << D->getDeclName() << cast(D)->getType(); + << D->getDeclName() << cast(D)->getType(); } return true; } @@ -273,12 +274,12 @@ cast(MD)->isDefaultConstructor()) || MD->isCopyAssignmentOperator() || MD->isMoveAssignmentOperator())) { Diag(Loc, diag::warn_cxx17_compat_lambda_def_ctor_assign) - << !isa(MD); + << !isa(MD); } } - auto getReferencedObjCProp = [](const NamedDecl *D) -> - const ObjCPropertyDecl * { + auto getReferencedObjCProp = + [](const NamedDecl *D) -> const ObjCPropertyDecl * { if (const auto *MD = dyn_cast(D)) return MD->findPropertyDecl(); return nullptr; @@ -287,7 +288,7 @@ if (diagnoseArgIndependentDiagnoseIfAttrs(ObjCPDecl, Loc)) return true; } else if (diagnoseArgIndependentDiagnoseIfAttrs(D, Loc)) { - return true; + return true; } // [OpenMP 4.0], 2.15 declare reduction Directive, Restrictions @@ -352,7 +353,8 @@ const FunctionType *fn = nullptr; if (const PointerType *ptr = type->getAs()) { fn = ptr->getPointeeType()->getAs(); - if (!fn) return; + if (!fn) + return; calleeType = CT_Function; } else if (const BlockPointerType *ptr = type->getAs()) { fn = ptr->getPointeeType()->castAs(); @@ -391,9 +393,12 @@ // Otherwise, find the sentinel expression. Expr *sentinelExpr = Args[Args.size() - numArgsAfterSentinel - 1]; - if (!sentinelExpr) return; - if (sentinelExpr->isValueDependent()) return; - if (Context.isSentinelNullExpr(sentinelExpr)) return; + if (!sentinelExpr) + return; + if (sentinelExpr->isValueDependent()) + return; + if (Context.isSentinelNullExpr(sentinelExpr)) + return; // Pick a reasonable string to insert. Optimistically use 'nil', 'nullptr', // or 'NULL' if those are actually defined in the context. Only use @@ -414,8 +419,8 @@ Diag(Loc, diag::warn_missing_sentinel) << int(calleeType); else Diag(MissingNilLoc, diag::warn_missing_sentinel) - << int(calleeType) - << FixItHint::CreateInsertion(MissingNilLoc, ", " + NullValue); + << int(calleeType) + << FixItHint::CreateInsertion(MissingNilLoc, ", " + NullValue); Diag(D->getLocation(), diag::note_sentinel_here) << int(calleeType); } @@ -432,7 +437,8 @@ // Handle any placeholder expressions which made it here. if (E->getType()->isPlaceholderType()) { ExprResult result = CheckPlaceholderExpr(E); - if (result.isInvalid()) return ExprError(); + if (result.isInvalid()) + return ExprError(); E = result.get(); } @@ -446,7 +452,8 @@ return ExprError(); E = ImpCastExprToType(E, Context.getPointerType(Ty), - CK_FunctionToPointerDecay).get(); + CK_FunctionToPointerDecay) + .get(); } else if (Ty->isArrayType()) { // In C90 mode, arrays only promote to pointers if the array expression is // an lvalue. The relevant legalese is C90 6.2.2.1p3: "an lvalue that has @@ -461,7 +468,8 @@ // if (getLangOpts().C99 || getLangOpts().CPlusPlus || E->isLValue()) E = ImpCastExprToType(E, Context.getArrayDecayedType(Ty), - CK_ArrayToPointerDecay).get(); + CK_ArrayToPointerDecay) + .get(); } return E; } @@ -474,20 +482,19 @@ // only handles the pattern "*null", which is a very syntactic check. if (UnaryOperator *UO = dyn_cast(E->IgnoreParenCasts())) if (UO->getOpcode() == UO_Deref && - UO->getSubExpr()->IgnoreParenCasts()-> - isNullPointerConstant(S.Context, Expr::NPC_ValueDependentIsNotNull) && + UO->getSubExpr()->IgnoreParenCasts()->isNullPointerConstant( + S.Context, Expr::NPC_ValueDependentIsNotNull) && !UO->getType().isVolatileQualified()) { - S.DiagRuntimeBehavior(UO->getOperatorLoc(), UO, - S.PDiag(diag::warn_indirection_through_null) - << UO->getSubExpr()->getSourceRange()); - S.DiagRuntimeBehavior(UO->getOperatorLoc(), UO, - S.PDiag(diag::note_indirection_through_null)); - } + S.DiagRuntimeBehavior(UO->getOperatorLoc(), UO, + S.PDiag(diag::warn_indirection_through_null) + << UO->getSubExpr()->getSourceRange()); + S.DiagRuntimeBehavior(UO->getOperatorLoc(), UO, + S.PDiag(diag::note_indirection_through_null)); + } } static void DiagnoseDirectIsaAccess(Sema &S, const ObjCIvarRefExpr *OIRE, - SourceLocation AssignLoc, - const Expr* RHS) { + SourceLocation AssignLoc, const Expr *RHS) { const ObjCIvarDecl *IV = OIRE->getDecl(); if (!IV) return; @@ -505,13 +512,12 @@ if (ObjCInterfaceDecl *IDecl = OTy->getInterface()) { ObjCInterfaceDecl *ClassDeclared = nullptr; ObjCIvarDecl *IV = IDecl->lookupInstanceVariable(Member, ClassDeclared); - if (!ClassDeclared->getSuperClass() - && (*ClassDeclared->ivar_begin()) == IV) { + if (!ClassDeclared->getSuperClass() && + (*ClassDeclared->ivar_begin()) == IV) { if (RHS) { - NamedDecl *ObjectSetClass = - S.LookupSingleName(S.TUScope, - &S.Context.Idents.get("object_setClass"), - SourceLocation(), S.LookupOrdinaryName); + NamedDecl *ObjectSetClass = S.LookupSingleName( + S.TUScope, &S.Context.Idents.get("object_setClass"), + SourceLocation(), S.LookupOrdinaryName); if (ObjectSetClass) { SourceLocation RHSLocEnd = S.getLocForEndOfToken(RHS->getEndLoc()); S.Diag(OIRE->getExprLoc(), diag::warn_objc_isa_assign) @@ -520,14 +526,12 @@ << FixItHint::CreateReplacement( SourceRange(OIRE->getOpLoc(), AssignLoc), ",") << FixItHint::CreateInsertion(RHSLocEnd, ")"); - } - else + } else S.Diag(OIRE->getLocation(), diag::warn_objc_isa_assign); } else { - NamedDecl *ObjectGetClass = - S.LookupSingleName(S.TUScope, - &S.Context.Idents.get("object_getClass"), - SourceLocation(), S.LookupOrdinaryName); + NamedDecl *ObjectGetClass = S.LookupSingleName( + S.TUScope, &S.Context.Idents.get("object_getClass"), + SourceLocation(), S.LookupOrdinaryName); if (ObjectGetClass) S.Diag(OIRE->getExprLoc(), diag::warn_objc_isa_use) << FixItHint::CreateInsertion(OIRE->getBeginLoc(), @@ -546,24 +550,24 @@ // Handle any placeholder expressions which made it here. if (E->getType()->isPlaceholderType()) { ExprResult result = CheckPlaceholderExpr(E); - if (result.isInvalid()) return ExprError(); + if (result.isInvalid()) + return ExprError(); E = result.get(); } // C++ [conv.lval]p1: // A glvalue of a non-function, non-array type T can be // converted to a prvalue. - if (!E->isGLValue()) return E; + if (!E->isGLValue()) + return E; QualType T = E->getType(); assert(!T.isNull() && "r-value conversion on typeless expression?"); // We don't want to throw lvalue-to-rvalue casts on top of // expressions of certain types in C++. - if (getLangOpts().CPlusPlus && - (E->getType() == Context.OverloadTy || - T->isDependentType() || - T->isRecordType())) + if (getLangOpts().CPlusPlus && (E->getType() == Context.OverloadTy || + T->isDependentType() || T->isRecordType())) return E; // The C standard is actually really unclear on this point, and @@ -577,16 +581,15 @@ // OpenCL usually rejects direct accesses to values of 'half' type. if (getLangOpts().OpenCL && !getOpenCLOptions().isEnabled("cl_khr_fp16") && T->isHalfType()) { - Diag(E->getExprLoc(), diag::err_opencl_half_load_store) - << 0 << T; + Diag(E->getExprLoc(), diag::err_opencl_half_load_store) << 0 << T; return ExprError(); } CheckForNullPointerDereference(*this, E); if (const ObjCIsaExpr *OISA = dyn_cast(E->IgnoreParenCasts())) { - NamedDecl *ObjectGetClass = LookupSingleName(TUScope, - &Context.Idents.get("object_getClass"), - SourceLocation(), LookupOrdinaryName); + NamedDecl *ObjectGetClass = + LookupSingleName(TUScope, &Context.Idents.get("object_getClass"), + SourceLocation(), LookupOrdinaryName); if (ObjectGetClass) Diag(E->getExprLoc(), diag::warn_objc_isa_use) << FixItHint::CreateInsertion(OISA->getBeginLoc(), "object_getClass(") @@ -594,10 +597,9 @@ SourceRange(OISA->getOpLoc(), OISA->getIsaMemberLoc()), ")"); else Diag(E->getExprLoc(), diag::warn_objc_isa_use); - } - else if (const ObjCIvarRefExpr *OIRE = - dyn_cast(E->IgnoreParenCasts())) - DiagnoseDirectIsaAccess(*this, OIRE, SourceLocation(), /* Expr*/nullptr); + } else if (const ObjCIvarRefExpr *OIRE = + dyn_cast(E->IgnoreParenCasts())) + DiagnoseDirectIsaAccess(*this, OIRE, SourceLocation(), /* Expr*/ nullptr); // C++ [conv.lval]p1: // [...] If T is a non-class type, the type of the prvalue is the @@ -618,7 +620,8 @@ UpdateMarkingForLValueToRValue(E); - // Loading a __weak object implicitly retains the value, so we need a cleanup to + // Loading a __weak object implicitly retains the value, so we need a cleanup + // to // balance that. if (E->getType().getObjCLifetime() == Qualifiers::OCL_Weak) Cleanup.setExprNeedsCleanups(true); @@ -657,7 +660,8 @@ // to function type. if (Ty->isFunctionType()) { Res = ImpCastExprToType(E, Context.getPointerType(Ty), - CK_FunctionToPointerDecay).get(); + CK_FunctionToPointerDecay) + .get(); if (Res.isInvalid()) return ExprError(); } @@ -737,11 +741,10 @@ const BuiltinType *BTy = Ty->getAs(); if (BTy && (BTy->getKind() == BuiltinType::Half || BTy->getKind() == BuiltinType::Float)) { - if (getLangOpts().OpenCL && - !getOpenCLOptions().isEnabled("cl_khr_fp64")) { - if (BTy->getKind() == BuiltinType::Half) { - E = ImpCastExprToType(E, Context.FloatTy, CK_FloatingCast).get(); - } + if (getLangOpts().OpenCL && !getOpenCLOptions().isEnabled("cl_khr_fp64")) { + if (BTy->getKind() == BuiltinType::Half) { + E = ImpCastExprToType(E, Context.FloatTy, CK_FloatingCast).get(); + } } else { E = ImpCastExprToType(E, Context.DoubleTy, CK_FloatingCast).get(); } @@ -760,8 +763,8 @@ // potentially potentially evaluated contexts. if (getLangOpts().CPlusPlus && E->isGLValue() && !isUnevaluatedContext()) { ExprResult Temp = PerformCopyInitialization( - InitializedEntity::InitializeTemporary(E->getType()), - E->getExprLoc(), E); + InitializedEntity::InitializeTemporary(E->getType()), E->getExprLoc(), + E); if (Temp.isInvalid()) return ExprError(); E = Temp.get(); @@ -879,7 +882,7 @@ (FDecl && FDecl->hasAttr()))) { E = stripARCUnbridgedCast(E); - // Otherwise, do normal placeholder checking. + // Otherwise, do normal placeholder checking. } else { ExprResult ExprRes = CheckPlaceholderExpr(E); if (ExprRes.isInvalid()) @@ -902,8 +905,8 @@ UnqualifiedId Name; Name.setIdentifier(PP.getIdentifierInfo("__builtin_trap"), E->getBeginLoc()); - ExprResult TrapFn = ActOnIdExpression(TUScope, SS, TemplateKWLoc, - Name, true, false); + ExprResult TrapFn = + ActOnIdExpression(TUScope, SS, TemplateKWLoc, Name, true, false); if (TrapFn.isInvalid()) return ExprError(); @@ -937,13 +940,15 @@ QualType IntTy, QualType ComplexTy, bool SkipCast) { - if (IntTy->isComplexType() || IntTy->isRealFloatingType()) return true; - if (SkipCast) return false; + if (IntTy->isComplexType() || IntTy->isRealFloatingType()) + return true; + if (SkipCast) + return false; if (IntTy->isIntegerType()) { QualType fpTy = cast(ComplexTy)->getElementType(); IntExpr = S.ImpCastExprToType(IntExpr.get(), fpTy, CK_IntegralToFloating); - IntExpr = S.ImpCastExprToType(IntExpr.get(), ComplexTy, - CK_FloatingRealToComplex); + IntExpr = + S.ImpCastExprToType(IntExpr.get(), ComplexTy, CK_FloatingRealToComplex); } else { assert(IntTy->isComplexIntegerType()); IntExpr = S.ImpCastExprToType(IntExpr.get(), ComplexTy, @@ -960,10 +965,10 @@ bool IsCompAssign) { // if we have an integer operand, the result is the complex type. if (!handleIntegerToComplexFloatConversion(S, RHS, LHS, RHSType, LHSType, - /*skipCast*/false)) + /*skipCast*/ false)) return LHSType; if (!handleIntegerToComplexFloatConversion(S, LHS, RHS, LHSType, RHSType, - /*skipCast*/IsCompAssign)) + /*skipCast*/ IsCompAssign)) return RHSType; // This handles complex/complex, complex/float, or float/complex. @@ -1017,8 +1022,8 @@ if (IntTy->isIntegerType()) { if (ConvertInt) // Convert intExpr to the lhs floating point type. - IntExpr = S.ImpCastExprToType(IntExpr.get(), FloatTy, - CK_IntegralToFloating); + IntExpr = + S.ImpCastExprToType(IntExpr.get(), FloatTy, CK_IntegralToFloating); return FloatTy; } @@ -1033,17 +1038,17 @@ // float -> _Complex float if (ConvertFloat) - FloatExpr = S.ImpCastExprToType(FloatExpr.get(), result, - CK_FloatingRealToComplex); + FloatExpr = + S.ImpCastExprToType(FloatExpr.get(), result, CK_FloatingRealToComplex); return result; } /// Handle arithmethic conversion with floating point types. Helper /// function of UsualArithmeticConversions() -static QualType handleFloatConversion(Sema &S, ExprResult &LHS, - ExprResult &RHS, QualType LHSType, - QualType RHSType, bool IsCompAssign) { +static QualType handleFloatConversion(Sema &S, ExprResult &LHS, ExprResult &RHS, + QualType LHSType, QualType RHSType, + bool IsCompAssign) { bool LHSFloat = LHSType->isRealFloatingType(); bool RHSFloat = RHSType->isRealFloatingType(); @@ -1069,11 +1074,11 @@ return handleIntToFloatConversion(S, LHS, RHS, LHSType, RHSType, /*convertFloat=*/!IsCompAssign, - /*convertInt=*/ true); + /*convertInt=*/true); } assert(RHSFloat); return handleIntToFloatConversion(S, RHS, LHS, RHSType, LHSType, - /*convertInt=*/ true, + /*convertInt=*/true, /*convertFloat=*/!IsCompAssign); } @@ -1095,10 +1100,8 @@ auto *LHSComplex = LHSType->getAs(); auto *RHSComplex = RHSType->getAs(); - QualType LHSElemType = LHSComplex ? - LHSComplex->getElementType() : LHSType; - QualType RHSElemType = RHSComplex ? - RHSComplex->getElementType() : RHSType; + QualType LHSElemType = LHSComplex ? LHSComplex->getElementType() : LHSType; + QualType RHSElemType = RHSComplex ? RHSComplex->getElementType() : RHSType; // No issue if the two types have the same representation if (&S.Context.getFloatTypeSemantics(LHSElemType) == @@ -1114,8 +1117,8 @@ // representation. We allow all conversions for all possible long double types // except PPC's double double. return Float128AndLongDouble && - (&S.Context.getFloatTypeSemantics(S.Context.LongDoubleTy) == - &llvm::APFloat::PPCDoubleDouble()); + (&S.Context.getFloatTypeSemantics(S.Context.LongDoubleTy) == + &llvm::APFloat::PPCDoubleDouble()); } typedef ExprResult PerformCastFn(Sema &S, Expr *operand, QualType toType); @@ -1176,7 +1179,7 @@ // on most 32-bit systems). Use the unsigned type corresponding // to the signed type. QualType result = - S.Context.getCorrespondingUnsignedType(LHSSigned ? LHSType : RHSType); + S.Context.getCorrespondingUnsignedType(LHSSigned ? LHSType : RHSType); RHS = (*doRHSCast)(S, RHS.get(), result); if (!IsCompAssign) LHS = (*doLHSCast)(S, LHS.get(), result); @@ -1197,8 +1200,8 @@ QualType LHSEltType = LHSComplexInt->getElementType(); QualType RHSEltType = RHSComplexInt->getElementType(); QualType ScalarType = - handleIntegerConversion - (S, LHS, RHS, LHSEltType, RHSEltType, IsCompAssign); + handleIntegerConversion( + S, LHS, RHS, LHSEltType, RHSEltType, IsCompAssign); return S.Context.getComplexType(ScalarType); } @@ -1206,11 +1209,10 @@ if (LHSComplexInt) { QualType LHSEltType = LHSComplexInt->getElementType(); QualType ScalarType = - handleIntegerConversion - (S, LHS, RHS, LHSEltType, RHSType, IsCompAssign); + handleIntegerConversion( + S, LHS, RHS, LHSEltType, RHSType, IsCompAssign); QualType ComplexType = S.Context.getComplexType(ScalarType); - RHS = S.ImpCastExprToType(RHS.get(), ComplexType, - CK_IntegralRealToComplex); + RHS = S.ImpCastExprToType(RHS.get(), ComplexType, CK_IntegralRealToComplex); return ComplexType; } @@ -1219,13 +1221,12 @@ QualType RHSEltType = RHSComplexInt->getElementType(); QualType ScalarType = - handleIntegerConversion - (S, LHS, RHS, LHSType, RHSEltType, IsCompAssign); + handleIntegerConversion( + S, LHS, RHS, LHSType, RHSEltType, IsCompAssign); QualType ComplexType = S.Context.getComplexType(ScalarType); if (!IsCompAssign) - LHS = S.ImpCastExprToType(LHS.get(), ComplexType, - CK_IntegralRealToComplex); + LHS = S.ImpCastExprToType(LHS.get(), ComplexType, CK_IntegralRealToComplex); return ComplexType; } @@ -1248,9 +1249,9 @@ // For conversion purposes, we ignore any qualifiers. // For example, "const float" and "float" are equivalent. QualType LHSType = - Context.getCanonicalType(LHS.get()->getType()).getUnqualifiedType(); + Context.getCanonicalType(LHS.get()->getType()).getUnqualifiedType(); QualType RHSType = - Context.getCanonicalType(RHS.get()->getType()).getUnqualifiedType(); + Context.getCanonicalType(RHS.get()->getType()).getUnqualifiedType(); // For conversion purposes, we ignore any atomic qualifier on the LHS. if (const AtomicType *AtomicLHS = LHSType->getAs()) @@ -1302,49 +1303,44 @@ IsCompAssign); // Finally, we have two differing integer types. - return handleIntegerConversion - (*this, LHS, RHS, LHSType, RHSType, IsCompAssign); + return handleIntegerConversion( + *this, LHS, RHS, LHSType, RHSType, IsCompAssign); } - //===----------------------------------------------------------------------===// // Semantic Analysis for various Expression Types //===----------------------------------------------------------------------===// - -ExprResult -Sema::ActOnGenericSelectionExpr(SourceLocation KeyLoc, - SourceLocation DefaultLoc, - SourceLocation RParenLoc, - Expr *ControllingExpr, - ArrayRef ArgTypes, - ArrayRef ArgExprs) { +ExprResult Sema::ActOnGenericSelectionExpr(SourceLocation KeyLoc, + SourceLocation DefaultLoc, + SourceLocation RParenLoc, + Expr *ControllingExpr, + ArrayRef ArgTypes, + ArrayRef ArgExprs) { unsigned NumAssocs = ArgTypes.size(); assert(NumAssocs == ArgExprs.size()); - TypeSourceInfo **Types = new TypeSourceInfo*[NumAssocs]; + TypeSourceInfo **Types = new TypeSourceInfo *[NumAssocs]; for (unsigned i = 0; i < NumAssocs; ++i) { if (ArgTypes[i]) - (void) GetTypeFromParser(ArgTypes[i], &Types[i]); + (void)GetTypeFromParser(ArgTypes[i], &Types[i]); else Types[i] = nullptr; } - ExprResult ER = CreateGenericSelectionExpr(KeyLoc, DefaultLoc, RParenLoc, - ControllingExpr, - llvm::makeArrayRef(Types, NumAssocs), - ArgExprs); - delete [] Types; + ExprResult ER = CreateGenericSelectionExpr( + KeyLoc, DefaultLoc, RParenLoc, ControllingExpr, + llvm::makeArrayRef(Types, NumAssocs), ArgExprs); + delete[] Types; return ER; } -ExprResult -Sema::CreateGenericSelectionExpr(SourceLocation KeyLoc, - SourceLocation DefaultLoc, - SourceLocation RParenLoc, - Expr *ControllingExpr, - ArrayRef Types, - ArrayRef Exprs) { +ExprResult Sema::CreateGenericSelectionExpr(SourceLocation KeyLoc, + SourceLocation DefaultLoc, + SourceLocation RParenLoc, + Expr *ControllingExpr, + ArrayRef Types, + ArrayRef Exprs) { unsigned NumAssocs = Types.size(); assert(NumAssocs == Exprs.size()); @@ -1368,8 +1364,8 @@ bool TypeErrorFound = false, IsResultDependent = ControllingExpr->isTypeDependent(), - ContainsUnexpandedParameterPack - = ControllingExpr->containsUnexpandedParameterPack(); + ContainsUnexpandedParameterPack = + ControllingExpr->containsUnexpandedParameterPack(); for (unsigned i = 0; i < NumAssocs; ++i) { if (Exprs[i]->containsUnexpandedParameterPack()) @@ -1394,26 +1390,23 @@ if (D != 0) { Diag(Types[i]->getTypeLoc().getBeginLoc(), D) - << Types[i]->getTypeLoc().getSourceRange() - << Types[i]->getType(); + << Types[i]->getTypeLoc().getSourceRange() << Types[i]->getType(); TypeErrorFound = true; } // C11 6.5.1.1p2 "No two generic associations in the same generic // selection shall specify compatible types." - for (unsigned j = i+1; j < NumAssocs; ++j) + for (unsigned j = i + 1; j < NumAssocs; ++j) if (Types[j] && !Types[j]->getType()->isDependentType() && Context.typesAreCompatible(Types[i]->getType(), Types[j]->getType())) { Diag(Types[j]->getTypeLoc().getBeginLoc(), diag::err_assoc_compatible_types) - << Types[j]->getTypeLoc().getSourceRange() - << Types[j]->getType() - << Types[i]->getType(); - Diag(Types[i]->getTypeLoc().getBeginLoc(), - diag::note_compat_assoc) - << Types[i]->getTypeLoc().getSourceRange() - << Types[i]->getType(); + << Types[j]->getTypeLoc().getSourceRange() + << Types[j]->getType() << Types[i]->getType(); + Diag(Types[i]->getTypeLoc().getBeginLoc(), diag::note_compat_assoc) + << Types[i]->getTypeLoc().getSourceRange() + << Types[i]->getType(); TypeErrorFound = true; } } @@ -1450,10 +1443,8 @@ << ControllingExpr->getSourceRange() << ControllingExpr->getType() << (unsigned)CompatIndices.size(); for (unsigned I : CompatIndices) { - Diag(Types[I]->getTypeLoc().getBeginLoc(), - diag::note_compat_assoc) - << Types[I]->getTypeLoc().getSourceRange() - << Types[I]->getType(); + Diag(Types[I]->getTypeLoc().getBeginLoc(), diag::note_compat_assoc) + << Types[I]->getTypeLoc().getSourceRange() << Types[I]->getType(); } return ExprError(); } @@ -1475,8 +1466,7 @@ // then the result expression of the generic selection is the expression // in that generic association. Otherwise, the result expression of the // generic selection is the expression in the default generic association." - unsigned ResultIndex = - CompatIndices.size() ? CompatIndices[0] : DefaultIndex; + unsigned ResultIndex = CompatIndices.size() ? CompatIndices[0] : DefaultIndex; return new (Context) GenericSelectionExpr( Context, KeyLoc, ControllingExpr, Types, Exprs, DefaultLoc, RParenLoc, @@ -1496,7 +1486,7 @@ static ExprResult BuildCookedLiteralOperatorCall(Sema &S, Scope *Scope, IdentifierInfo *UDSuffix, SourceLocation UDSuffixLoc, - ArrayRef Args, + ArrayRef Args, SourceLocation LitEndLoc) { assert(Args.size() <= 2 && "too many arguments for literal operator"); @@ -1508,7 +1498,7 @@ } DeclarationName OpName = - S.Context.DeclarationNames.getCXXLiteralOperatorName(UDSuffix); + S.Context.DeclarationNames.getCXXLiteralOperatorName(UDSuffix); DeclarationNameInfo OpNameInfo(OpName, UDSuffixLoc); OpNameInfo.setCXXLiteralOperatorNameLoc(UDSuffixLoc); @@ -1528,8 +1518,8 @@ /// multiple tokens. However, the common case is that StringToks points to one /// string. /// -ExprResult -Sema::ActOnStringLiteral(ArrayRef StringToks, Scope *UDLScope) { +ExprResult Sema::ActOnStringLiteral(ArrayRef StringToks, + Scope *UDLScope) { assert(!StringToks.empty() && "Must have at least one string!"); StringLiteralParser Literal(StringToks, PP); @@ -1574,18 +1564,17 @@ ArrayType::Normal, 0); // Pass &StringTokLocs[0], StringTokLocs.size() to factory! - StringLiteral *Lit = StringLiteral::Create(Context, Literal.GetString(), - Kind, Literal.Pascal, StrTy, - &StringTokLocs[0], - StringTokLocs.size()); + StringLiteral *Lit = + StringLiteral::Create(Context, Literal.GetString(), Kind, Literal.Pascal, + StrTy, &StringTokLocs[0], StringTokLocs.size()); if (Literal.getUDSuffix().empty()) return Lit; // We're building a user-defined literal. IdentifierInfo *UDSuffix = &Context.Idents.get(Literal.getUDSuffix()); SourceLocation UDSuffixLoc = - getUDSuffixLoc(*this, StringTokLocs[Literal.getUDSuffixToken()], - Literal.getUDSuffixOffset()); + getUDSuffixLoc(*this, StringTokLocs[Literal.getUDSuffixToken()], + Literal.getUDSuffixOffset()); // Make sure we're allowed user-defined literals here. if (!UDLScope) @@ -1596,13 +1585,11 @@ QualType SizeType = Context.getSizeType(); DeclarationName OpName = - Context.DeclarationNames.getCXXLiteralOperatorName(UDSuffix); + Context.DeclarationNames.getCXXLiteralOperatorName(UDSuffix); DeclarationNameInfo OpNameInfo(OpName, UDSuffixLoc); OpNameInfo.setCXXLiteralOperatorNameLoc(UDSuffixLoc); - QualType ArgTy[] = { - Context.getArrayDecayedType(StrTy), SizeType - }; + QualType ArgTy[] = {Context.getArrayDecayedType(StrTy), SizeType}; LookupResult R(*this, OpName, UDSuffixLoc, LookupOrdinaryName); switch (LookupLiteralOperator(UDLScope, R, ArgTy, @@ -1612,9 +1599,9 @@ case LOLR_Cooked: { llvm::APInt Len(Context.getIntWidth(SizeType), Literal.GetNumStringChars()); - IntegerLiteral *LenArg = IntegerLiteral::Create(Context, Len, SizeType, - StringTokLocs[0]); - Expr *Args[] = { Lit, LenArg }; + IntegerLiteral *LenArg = + IntegerLiteral::Create(Context, Len, SizeType, StringTokLocs[0]); + Expr *Args[] = {Lit, LenArg}; return BuildLiteralOperatorCall(R, OpNameInfo, Args, StringTokLocs.back()); } @@ -1627,7 +1614,8 @@ llvm::APSInt Value(CharBits, CharIsUnsigned); TemplateArgument TypeArg(CharTy); - TemplateArgumentLocInfo TypeArgInfo(Context.getTrivialTypeSourceInfo(CharTy)); + TemplateArgumentLocInfo TypeArgInfo( + Context.getTrivialTypeSourceInfo(CharTy)); ExplicitArgs.addArgument(TemplateArgumentLoc(TypeArg, TypeArgInfo)); for (unsigned I = 0, N = Lit->getLength(); I != N; ++I) { @@ -1649,10 +1637,8 @@ llvm_unreachable("unexpected literal operator lookup result"); } -ExprResult -Sema::BuildDeclRefExpr(ValueDecl *D, QualType Ty, ExprValueKind VK, - SourceLocation Loc, - const CXXScopeSpec *SS) { +ExprResult Sema::BuildDeclRefExpr(ValueDecl *D, QualType Ty, ExprValueKind VK, + SourceLocation Loc, const CXXScopeSpec *SS) { DeclarationNameInfo NameInfo(D->getDeclName(), Loc); return BuildDeclRefExpr(D, Ty, VK, NameInfo, SS); } @@ -1673,16 +1659,17 @@ VarTemplateSpecializationDecl *VarSpec = cast(D); - E = DeclRefExpr::Create(Context, SS ? SS->getWithLocInContext(Context) - : NestedNameSpecifierLoc(), - VarSpec->getTemplateKeywordLoc(), D, - RefersToCapturedVariable, NameInfo.getLoc(), Ty, VK, - FoundD, TemplateArgs); + E = DeclRefExpr::Create( + Context, + SS ? SS->getWithLocInContext(Context) : NestedNameSpecifierLoc(), + VarSpec->getTemplateKeywordLoc(), D, RefersToCapturedVariable, + NameInfo.getLoc(), Ty, VK, FoundD, TemplateArgs); } else { assert(!TemplateArgs && "No template arguments for non-variable" " template specialization references"); - E = DeclRefExpr::Create(Context, SS ? SS->getWithLocInContext(Context) - : NestedNameSpecifierLoc(), + E = DeclRefExpr::Create(Context, + SS ? SS->getWithLocInContext(Context) + : NestedNameSpecifierLoc(), SourceLocation(), D, RefersToCapturedVariable, NameInfo, Ty, VK, FoundD); } @@ -1722,11 +1709,10 @@ /// This actually loses a lot of source location information for /// non-standard name kinds; we should consider preserving that in /// some way. -void -Sema::DecomposeUnqualifiedId(const UnqualifiedId &Id, - TemplateArgumentListInfo &Buffer, - DeclarationNameInfo &NameInfo, - const TemplateArgumentListInfo *&TemplateArgs) { +void Sema::DecomposeUnqualifiedId( + const UnqualifiedId &Id, TemplateArgumentListInfo &Buffer, + DeclarationNameInfo &NameInfo, + const TemplateArgumentListInfo *&TemplateArgs) { if (Id.getKind() == UnqualifiedIdKind::IK_TemplateId) { Buffer.setLAngleLoc(Id.TemplateId->LAngleLoc); Buffer.setRAngleLoc(Id.TemplateId->RAngleLoc); @@ -1755,8 +1741,8 @@ // Emit a special diagnostic for failed member lookups. // FIXME: computing the declaration context might fail here (?) if (Ctx) - SemaRef.Diag(TypoLoc, diag::err_no_member) << Typo << Ctx - << SS.getRange(); + SemaRef.Diag(TypoLoc, diag::err_no_member) + << Typo << Ctx << SS.getRange(); else SemaRef.Diag(TypoLoc, DiagnosticID) << Typo; return; @@ -1772,20 +1758,20 @@ SemaRef.diagnoseTypo(TC, SemaRef.PDiag(DiagnosticSuggestID) << Typo, SemaRef.PDiag(NoteID)); else - SemaRef.diagnoseTypo(TC, SemaRef.PDiag(diag::err_no_member_suggest) - << Typo << Ctx << DroppedSpecifier - << SS.getRange(), + SemaRef.diagnoseTypo(TC, + SemaRef.PDiag(diag::err_no_member_suggest) + << Typo << Ctx << DroppedSpecifier + << SS.getRange(), SemaRef.PDiag(NoteID)); } /// Diagnose an empty lookup. /// /// \return false if new lookup candidates were found -bool -Sema::DiagnoseEmptyLookup(Scope *S, CXXScopeSpec &SS, LookupResult &R, - std::unique_ptr CCC, - TemplateArgumentListInfo *ExplicitTemplateArgs, - ArrayRef Args, TypoExpr **Out) { +bool Sema::DiagnoseEmptyLookup(Scope *S, CXXScopeSpec &SS, LookupResult &R, + std::unique_ptr CCC, + TemplateArgumentListInfo *ExplicitTemplateArgs, + ArrayRef Args, TypoExpr **Out) { DeclarationName Name = R.getLookupName(); unsigned diagnostic = diag::err_undeclared_var_use; @@ -1818,8 +1804,7 @@ CodeSynthesisContexts.back().Kind == CodeSynthesisContext::DefaultFunctionArgumentInstantiation; CXXMethodDecl *CurMethod = dyn_cast(CurContext); - bool isInstance = CurMethod && - CurMethod->isInstance() && + bool isInstance = CurMethod && CurMethod->isInstance() && DC == CurMethod->getParent() && !isDefaultArgument; // Give a code modification hint to insert 'this->'. @@ -1828,8 +1813,8 @@ if (getLangOpts().MSVCCompat) diagnostic = diag::ext_found_via_dependent_bases_lookup; if (isInstance) { - Diag(R.getNameLoc(), diagnostic) << Name - << FixItHint::CreateInsertion(R.getNameLoc(), "this->"); + Diag(R.getNameLoc(), diagnostic) + << Name << FixItHint::CreateInsertion(R.getNameLoc(), "this->"); CheckCXXThisCapture(R.getNameLoc()); } else { Diag(R.getNameLoc(), diagnostic) << Name; @@ -1899,15 +1884,14 @@ OverloadCandidateSet::CSK_Normal); OverloadCandidateSet::iterator Best; for (NamedDecl *CD : Corrected) { - if (FunctionTemplateDecl *FTD = - dyn_cast(CD)) - AddTemplateOverloadCandidate( - FTD, DeclAccessPair::make(FTD, AS_none), ExplicitTemplateArgs, - Args, OCS); + if (FunctionTemplateDecl *FTD = dyn_cast(CD)) + AddTemplateOverloadCandidate(FTD, + DeclAccessPair::make(FTD, AS_none), + ExplicitTemplateArgs, Args, OCS); else if (FunctionDecl *FD = dyn_cast(CD)) if (!ExplicitTemplateArgs || ExplicitTemplateArgs->size() == 0) - AddOverloadCandidate(FD, DeclAccessPair::make(FD, AS_none), - Args, OCS); + AddOverloadCandidate(FD, DeclAccessPair::make(FD, AS_none), Args, + OCS); } switch (OCS.BestViableFunction(*this, R.getNameLoc(), Best)) { case OR_Success: @@ -1928,8 +1912,8 @@ Record = Ty->getAsCXXRecordDecl(); } if (!Record) - Record = cast( - ND->getDeclContext()->getRedeclContext()); + Record = + cast(ND->getDeclContext()->getRedeclContext()); R.setNamingClass(Record); } @@ -1957,9 +1941,10 @@ diagnoseTypo(Corrected, PDiag(diagnostic_suggest) << Name, PDiag(NoteID), AcceptableWithRecovery); else - diagnoseTypo(Corrected, PDiag(diag::err_no_member_suggest) - << Name << computeDeclContext(SS, false) - << DroppedSpecifier << SS.getRange(), + diagnoseTypo(Corrected, + PDiag(diag::err_no_member_suggest) + << Name << computeDeclContext(SS, false) + << DroppedSpecifier << SS.getRange(), PDiag(NoteID), AcceptableWithRecovery); // Tell the callee whether to try to recover. @@ -1972,8 +1957,7 @@ // FIXME: computing the declaration context might fail here (?) if (!SS.isEmpty()) { Diag(R.getNameLoc(), diag::err_no_member) - << Name << computeDeclContext(SS, false) - << SS.getRange(); + << Name << computeDeclContext(SS, false) << SS.getRange(); return true; } @@ -2134,7 +2118,8 @@ // extension in C99, forbidden in C++). if (R.empty() && HasTrailingLParen && II && !getLangOpts().CPlusPlus) { NamedDecl *D = ImplicitlyDefineFunction(NameLoc, *II, S); - if (D) R.addDecl(D); + if (D) + R.addDecl(D); } // Determine whether this name might be a candidate for @@ -2182,13 +2167,14 @@ KeywordReplacement->startToken(); KeywordReplacement->setKind(II->getTokenID()); KeywordReplacement->setIdentifierInfo(II); - KeywordReplacement->setLocation(BestTC.getCorrectionRange().getBegin()); + KeywordReplacement->setLocation( + BestTC.getCorrectionRange().getBegin()); // Clean up the state associated with the TypoExpr, since it has // now been diagnosed (without a call to CorrectDelayedTyposInExpr). clearDelayedTypo(TE); // Signal that a correction to a keyword was performed by returning a // valid-but-null ExprResult. - return (Expr*)nullptr; + return (Expr *)nullptr; } State.Consumer->resetCorrectionStream(); } @@ -2255,8 +2241,8 @@ isa(R.getFoundDecl()); if (MightBeImplicitMember) - return BuildPossibleImplicitMemberExpr(SS, TemplateKWLoc, - R, TemplateArgs, S); + return BuildPossibleImplicitMemberExpr(SS, TemplateKWLoc, R, TemplateArgs, + S); } if (TemplateArgs || TemplateKWLoc.isValid()) { @@ -2303,7 +2289,7 @@ if (R.empty()) { Diag(NameInfo.getLoc(), diag::err_no_member) - << NameInfo.getName() << DC << SS.getRange(); + << NameInfo.getName() << DC << SS.getRange(); return ExprError(); } @@ -2362,9 +2348,9 @@ /// actually quite a lot of extra work involved. /// /// Returns a null sentinel to indicate trivial success. -ExprResult -Sema::LookupInObjCMethod(LookupResult &Lookup, Scope *S, - IdentifierInfo *II, bool AllowBuiltinCreation) { +ExprResult Sema::LookupInObjCMethod(LookupResult &Lookup, Scope *S, + IdentifierInfo *II, + bool AllowBuiltinCreation) { SourceLocation Loc = Lookup.getNameLoc(); ObjCMethodDecl *CurMethod = getCurMethodDecl(); @@ -2453,7 +2439,7 @@ if (getLangOpts().ObjCAutoRefCount) { if (CurContext->isClosure()) Diag(Loc, diag::warn_implicitly_retains_self) - << FixItHint::CreateInsertion(Loc, "self->"); + << FixItHint::CreateInsertion(Loc, "self->"); } return Result; @@ -2481,10 +2467,11 @@ if (unsigned BuiltinID = II->getBuiltinID()) { if (!(getLangOpts().CPlusPlus && Context.BuiltinInfo.isPredefinedLibFunction(BuiltinID))) { - NamedDecl *D = LazilyCreateBuiltin((IdentifierInfo *)II, BuiltinID, - S, Lookup.isForRedeclaration(), + NamedDecl *D = LazilyCreateBuiltin((IdentifierInfo *)II, BuiltinID, S, + Lookup.isForRedeclaration(), Lookup.getNameLoc()); - if (D) Lookup.addDecl(D); + if (D) + Lookup.addDecl(D); } } } @@ -2509,11 +2496,10 @@ /// * Finally we cast from the declaring class to the "true" /// declaring class of the member. This conversion does not /// obey access control. -ExprResult -Sema::PerformObjectMemberConversion(Expr *From, - NestedNameSpecifier *Qualifier, - NamedDecl *FoundDecl, - NamedDecl *Member) { +ExprResult Sema::PerformObjectMemberConversion(Expr *From, + NestedNameSpecifier *Qualifier, + NamedDecl *FoundDecl, + NamedDecl *Member) { CXXRecordDecl *RD = dyn_cast(Member->getDeclContext()); if (!RD) return From; @@ -2594,14 +2580,15 @@ // Otherwise build the appropriate casts. if (IsDerivedFrom(FromLoc, FromRecordType, QRecordType)) { CXXCastPath BasePath; - if (CheckDerivedToBaseConversion(FromRecordType, QRecordType, - FromLoc, FromRange, &BasePath)) + if (CheckDerivedToBaseConversion(FromRecordType, QRecordType, FromLoc, + FromRange, &BasePath)) return ExprError(); if (PointerConversions) QType = Context.getPointerType(QType); - From = ImpCastExprToType(From, QType, CK_UncheckedDerivedToBase, - VK, &BasePath).get(); + From = ImpCastExprToType(From, QType, CK_UncheckedDerivedToBase, VK, + &BasePath) + .get(); FromType = QType; FromRecordType = QRecordType; @@ -2623,22 +2610,23 @@ if (FoundDecl->getDeclContext() != Member->getDeclContext()) { assert(isa(FoundDecl)); QualType URecordType = Context.getTypeDeclType( - cast(FoundDecl->getDeclContext())); + cast(FoundDecl->getDeclContext())); // We only need to do this if the naming-class to declaring-class // conversion is non-trivial. if (!Context.hasSameUnqualifiedType(FromRecordType, URecordType)) { assert(IsDerivedFrom(FromLoc, FromRecordType, URecordType)); CXXCastPath BasePath; - if (CheckDerivedToBaseConversion(FromRecordType, URecordType, - FromLoc, FromRange, &BasePath)) + if (CheckDerivedToBaseConversion(FromRecordType, URecordType, FromLoc, + FromRange, &BasePath)) return ExprError(); QualType UType = URecordType; if (PointerConversions) UType = Context.getPointerType(UType); - From = ImpCastExprToType(From, UType, CK_UncheckedDerivedToBase, - VK, &BasePath).get(); + From = ImpCastExprToType(From, UType, CK_UncheckedDerivedToBase, VK, + &BasePath) + .get(); FromType = UType; FromRecordType = URecordType; } @@ -2649,13 +2637,12 @@ } CXXCastPath BasePath; - if (CheckDerivedToBaseConversion(FromRecordType, DestRecordType, - FromLoc, FromRange, &BasePath, - IgnoreAccess)) + if (CheckDerivedToBaseConversion(FromRecordType, DestRecordType, FromLoc, + FromRange, &BasePath, IgnoreAccess)) return ExprError(); - return ImpCastExprToType(From, DestType, CK_UncheckedDerivedToBase, - VK, &BasePath); + return ImpCastExprToType(From, DestType, CK_UncheckedDerivedToBase, VK, + &BasePath); } bool Sema::UseArgumentDependentLookup(const CXXScopeSpec &SS, @@ -2711,7 +2698,6 @@ return true; } - /// Diagnoses obvious problems with the use of the given declaration /// as an expression. This is only actually called for lookups that /// were not overloaded, and it doesn't promise that the declaration @@ -2771,19 +2757,16 @@ // we've picked a target. R.suppressDiagnostics(); - UnresolvedLookupExpr *ULE - = UnresolvedLookupExpr::Create(Context, R.getNamingClass(), - SS.getWithLocInContext(Context), - R.getLookupNameInfo(), - NeedsADL, R.isOverloadedResult(), - R.begin(), R.end()); + UnresolvedLookupExpr *ULE = UnresolvedLookupExpr::Create( + Context, R.getNamingClass(), SS.getWithLocInContext(Context), + R.getLookupNameInfo(), NeedsADL, R.isOverloadedResult(), R.begin(), + R.end()); return ULE; } -static void -diagnoseUncapturableValueReference(Sema &S, SourceLocation loc, - ValueDecl *var, DeclContext *DC); +static void diagnoseUncapturableValueReference(Sema &S, SourceLocation loc, + ValueDecl *var, DeclContext *DC); /// Complete semantic analysis for a reference to the given declaration. ExprResult Sema::BuildDeclarationNameExpr( @@ -2808,8 +2791,7 @@ // Make sure that we're referring to a value. ValueDecl *VD = dyn_cast(D); if (!VD) { - Diag(Loc, diag::err_ref_non_value) - << D << SS.getRange(); + Diag(Loc, diag::err_ref_non_value) << D << SS.getRange(); Diag(D->getLocation(), diag::note_declared_at); return ExprError(); } @@ -2848,11 +2830,10 @@ ExprValueKind valueKind = VK_RValue; switch (D->getKind()) { - // Ignore all the non-ValueDecl kinds. +// Ignore all the non-ValueDecl kinds. #define ABSTRACT_DECL(kind) #define VALUE(type, base) -#define DECL(type, base) \ - case Decl::type: +#define DECL(type, base) case Decl::type: #include "clang/AST/DeclNodes.inc" llvm_unreachable("invalid value decl kind"); @@ -2875,8 +2856,7 @@ // exist in the high-level semantics. case Decl::Field: case Decl::IndirectField: - assert(getLangOpts().CPlusPlus && - "building reference to field in C?"); + assert(getLangOpts().CPlusPlus && "building reference to field in C?"); // These can't have reference type in well-formed programs, but // for internal consistency we do this anyway. @@ -2906,8 +2886,7 @@ case Decl::Decomposition: case Decl::OMPCapturedExpr: // In C, "extern void blah;" is valid and is an r-value. - if (!getLangOpts().CPlusPlus && - !type.hasQualifiers() && + if (!getLangOpts().CPlusPlus && !type.hasQualifiers() && type->isVoidType()) { valueKind = VK_RValue; break; @@ -2996,8 +2975,8 @@ // If we're referring to a method with an __unknown_anytype // result type, make the entire expression __unknown_anytype. // This should only be possible with a type written directly. - if (const FunctionProtoType *proto - = dyn_cast(VD->getType())) + if (const FunctionProtoType *proto = + dyn_cast(VD->getType())) if (proto->getReturnType() == Context.UnknownAnyTy) { type = Context.UnknownAnyTy; valueKind = VK_RValue; @@ -3090,14 +3069,29 @@ PredefinedExpr::IdentType IT; switch (Kind) { - default: llvm_unreachable("Unknown simple primary expr!"); - case tok::kw___func__: IT = PredefinedExpr::Func; break; // [C99 6.4.2.2] - case tok::kw___FUNCTION__: IT = PredefinedExpr::Function; break; - case tok::kw___FUNCDNAME__: IT = PredefinedExpr::FuncDName; break; // [MS] - case tok::kw___FUNCSIG__: IT = PredefinedExpr::FuncSig; break; // [MS] - case tok::kw_L__FUNCTION__: IT = PredefinedExpr::LFunction; break; // [MS] - case tok::kw_L__FUNCSIG__: IT = PredefinedExpr::LFuncSig; break; // [MS] - case tok::kw___PRETTY_FUNCTION__: IT = PredefinedExpr::PrettyFunction; break; + default: + llvm_unreachable("Unknown simple primary expr!"); + case tok::kw___func__: + IT = PredefinedExpr::Func; + break; // [C99 6.4.2.2] + case tok::kw___FUNCTION__: + IT = PredefinedExpr::Function; + break; + case tok::kw___FUNCDNAME__: + IT = PredefinedExpr::FuncDName; + break; // [MS] + case tok::kw___FUNCSIG__: + IT = PredefinedExpr::FuncSig; + break; // [MS] + case tok::kw_L__FUNCTION__: + IT = PredefinedExpr::LFunction; + break; // [MS] + case tok::kw_L__FUNCSIG__: + IT = PredefinedExpr::LFuncSig; + break; // [MS] + case tok::kw___PRETTY_FUNCTION__: + IT = PredefinedExpr::PrettyFunction; + break; } return BuildPredefinedExpr(Loc, IT); @@ -3125,9 +3119,9 @@ else if (Literal.isUTF32()) Ty = Context.Char32Ty; // U'x' -> char32_t in C11 and C++11. else if (!getLangOpts().CPlusPlus || Literal.isMultiChar()) - Ty = Context.IntTy; // 'x' -> int in C, 'wxyz' -> int in C++. + Ty = Context.IntTy; // 'x' -> int in C, 'wxyz' -> int in C++. else - Ty = Context.CharTy; // 'x' -> char in C++ + Ty = Context.CharTy; // 'x' -> char in C++ CharacterLiteral::CharacterKind Kind = CharacterLiteral::Ascii; if (Literal.isWide()) @@ -3139,8 +3133,8 @@ else if (Literal.isUTF8()) Kind = CharacterLiteral::UTF8; - Expr *Lit = new (Context) CharacterLiteral(Literal.getValue(), Kind, Ty, - Tok.getLocation()); + Expr *Lit = new (Context) + CharacterLiteral(Literal.getValue(), Kind, Ty, Tok.getLocation()); if (Literal.getUDSuffix().empty()) return Lit; @@ -3148,7 +3142,7 @@ // We're building a user-defined literal. IdentifierInfo *UDSuffix = &Context.Idents.get(Literal.getUDSuffix()); SourceLocation UDSuffixLoc = - getUDSuffixLoc(*this, Tok.getLocation(), Literal.getUDSuffixOffset()); + getUDSuffixLoc(*this, Tok.getLocation(), Literal.getUDSuffixOffset()); // Make sure we're allowed user-defined literals here. if (!UDLScope) @@ -3189,9 +3183,7 @@ APFloat::getSmallest(Format).toString(buffer); } - S.Diag(Loc, diagnostic) - << Ty - << StringRef(buffer.data(), buffer.size()); + S.Diag(Loc, diagnostic) << Ty << StringRef(buffer.data(), buffer.size()); } bool isExact = (result == APFloat::opOK); @@ -3231,7 +3223,7 @@ // cannot have a trigraph, escaped newline, radix prefix, or suffix. if (Tok.getLength() == 1) { const char Val = PP.getSpellingOfSingleCharacterNumericConstant(Tok); - return ActOnIntegerConstant(Tok.getLocation(), Val-'0'); + return ActOnIntegerConstant(Tok.getLocation(), Val - '0'); } SmallString<128> SpellingBuffer; @@ -3255,7 +3247,7 @@ // We're building a user-defined literal. IdentifierInfo *UDSuffix = &Context.Idents.get(Literal.getUDSuffix()); SourceLocation UDSuffixLoc = - getUDSuffixLoc(*this, Tok.getLocation(), Literal.getUDSuffixOffset()); + getUDSuffixLoc(*this, Tok.getLocation(), Literal.getUDSuffixOffset()); // Make sure we're allowed user-defined literals here. if (!UDLScope) @@ -3275,7 +3267,7 @@ } DeclarationName OpName = - Context.DeclarationNames.getCXXLiteralOperatorName(UDSuffix); + Context.DeclarationNames.getCXXLiteralOperatorName(UDSuffix); DeclarationNameInfo OpNameInfo(OpName, UDSuffixLoc); OpNameInfo.setCXXLiteralOperatorNameLoc(UDSuffixLoc); @@ -3319,7 +3311,7 @@ llvm::APInt(32, Length + 1), ArrayType::Normal, 0); Expr *Lit = StringLiteral::Create( Context, StringRef(TokSpelling.data(), Length), StringLiteral::Ascii, - /*Pascal*/false, StrTy, &TokLoc, 1); + /*Pascal*/ false, StrTy, &TokLoc, 1); return BuildLiteralOperatorCall(R, OpNameInfo, Lit, TokLoc); } @@ -3369,7 +3361,8 @@ } } - if (Literal.isUnsigned) Ty = Context.getCorrespondingUnsignedType(Ty); + if (Literal.isUnsigned) + Ty = Context.getCorrespondingUnsignedType(Ty); bool isSigned = !Literal.isUnsigned; unsigned scale = Context.getFixedPointScale(Ty); @@ -3393,7 +3386,7 @@ Tok.getLocation(), scale); } else if (Literal.isFloatingLiteral()) { QualType Ty; - if (Literal.isHalf){ + if (Literal.isHalf) { if (getOpenCLOptions().isEnabled("cl_khr_fp16")) Ty = Context.HalfTy; else { @@ -3435,8 +3428,8 @@ if (!getLangOpts().C99 && Literal.isLongLong) { if (getLangOpts().CPlusPlus) Diag(Tok.getLocation(), - getLangOpts().CPlusPlus11 ? - diag::warn_cxx98_compat_longlong : diag::ext_cxx11_longlong); + getLangOpts().CPlusPlus11 ? diag::warn_cxx98_compat_longlong + : diag::ext_cxx11_longlong); else Diag(Tok.getLocation(), diag::ext_c99_longlong); } @@ -3482,7 +3475,7 @@ // Does it fit in a unsigned int? if (ResultVal.isIntN(IntSize)) { // Does it fit in a signed int? - if (!Literal.isUnsigned && ResultVal[IntSize-1] == 0) + if (!Literal.isUnsigned && ResultVal[IntSize - 1] == 0) Ty = Context.IntTy; else if (AllowUnsigned) Ty = Context.UnsignedIntTy; @@ -3497,7 +3490,7 @@ // Does it fit in a unsigned long? if (ResultVal.isIntN(LongSize)) { // Does it fit in a signed long? - if (!Literal.isUnsigned && ResultVal[LongSize-1] == 0) + if (!Literal.isUnsigned && ResultVal[LongSize - 1] == 0) Ty = Context.LongTy; else if (AllowUnsigned) Ty = Context.UnsignedLongTy; @@ -3530,8 +3523,9 @@ // Does it fit in a signed long long? // To be compatible with MSVC, hex integer literals ending with the // LL or i64 suffix are always signed in Microsoft mode. - if (!Literal.isUnsigned && (ResultVal[LongLongSize-1] == 0 || - (getLangOpts().MSVCCompat && Literal.isLongLong))) + if (!Literal.isUnsigned && + (ResultVal[LongLongSize - 1] == 0 || + (getLangOpts().MSVCCompat && Literal.isLongLong))) Ty = Context.LongLongTy; else if (AllowUnsigned) Ty = Context.UnsignedLongLongTy; @@ -3555,8 +3549,8 @@ // If this is an imaginary literal, create the ImaginaryLiteral wrapper. if (Literal.isImaginary) { - Res = new (Context) ImaginaryLiteral(Res, - Context.getComplexType(Res->getType())); + Res = new (Context) + ImaginaryLiteral(Res, Context.getComplexType(Res->getType())); Diag(Tok.getLocation(), diag::ext_imaginary_constant); } @@ -3576,8 +3570,7 @@ // Every built-in scalar type (OpenCL 1.1 6.1.1) is either an arithmetic // type (C99 6.2.5p18) or void. if (!(T->isArithmeticType() || T->isVoidType() || T->isVectorType())) { - S.Diag(Loc, diag::err_vecstep_non_scalar_vector_type) - << T << ArgRange; + S.Diag(Loc, diag::err_vecstep_non_scalar_vector_type) << T << ArgRange; return true; } @@ -3599,7 +3592,7 @@ (TraitKind == UETT_SizeOf || TraitKind == UETT_AlignOf)) { // sizeof(function)/alignof(function) is allowed as an extension. S.Diag(Loc, diag::ext_sizeof_alignof_function_type) - << TraitKind << ArgRange; + << TraitKind << ArgRange; return false; } @@ -3623,8 +3616,7 @@ // runtime doesn't allow it. if (!S.LangOpts.ObjCRuntime.allowsSizeofAlignof() && T->isObjCObjectType()) { S.Diag(Loc, diag::err_sizeof_nonfragile_interface) - << T << (TraitKind == UETT_SizeOf) - << ArgRange; + << T << (TraitKind == UETT_SizeOf) << ArgRange; return true; } @@ -3644,9 +3636,9 @@ if (!ICE || ICE->getCastKind() != CK_ArrayToPointerDecay) return; - S.Diag(Loc, diag::warn_sizeof_array_decay) << ICE->getSourceRange() - << ICE->getType() - << ICE->getSubExpr()->getType(); + S.Diag(Loc, diag::warn_sizeof_array_decay) + << ICE->getSourceRange() << ICE->getType() + << ICE->getSubExpr()->getType(); } /// Check the constraints on expression operands to unary type expression @@ -3692,7 +3684,7 @@ if (ExprTy->isFunctionType()) { Diag(E->getExprLoc(), diag::err_sizeof_alignof_function_type) - << ExprKind << E->getSourceRange(); + << ExprKind << E->getSourceRange(); return true; } @@ -3712,8 +3704,7 @@ QualType OType = PVD->getOriginalType(); QualType Type = PVD->getType(); if (Type->isPointerType() && OType->isArrayType()) { - Diag(E->getExprLoc(), diag::warn_sizeof_array_param) - << Type << OType; + Diag(E->getExprLoc(), diag::warn_sizeof_array_param) << Type << OType; Diag(PVD->getLocation(), diag::note_declared_at); } } @@ -3779,13 +3770,13 @@ return false; if (RequireCompleteType(OpLoc, ExprType, - diag::err_sizeof_alignof_incomplete_type, - ExprKind, ExprRange)) + diag::err_sizeof_alignof_incomplete_type, ExprKind, + ExprRange)) return true; if (ExprType->isFunctionType()) { Diag(OpLoc, diag::err_sizeof_alignof_function_type) - << ExprKind << ExprRange; + << ExprKind << ExprRange; return true; } @@ -3805,7 +3796,7 @@ if (E->getObjectKind() == OK_BitField) { S.Diag(E->getExprLoc(), diag::err_sizeof_alignof_typeof_bitfield) - << 1 << E->getSourceRange(); + << 1 << E->getSourceRange(); return true; } @@ -3838,7 +3829,7 @@ // definition if we can find a member of it. if (!FD->getParent()->isCompleteDefinition()) { S.Diag(E->getExprLoc(), diag::err_alignof_member_of_incomplete_type) - << E->getSourceRange(); + << E->getSourceRange(); return true; } @@ -3988,11 +3979,10 @@ } /// Build a sizeof or alignof expression given a type operand. -ExprResult -Sema::CreateUnaryExprOrTypeTraitExpr(TypeSourceInfo *TInfo, - SourceLocation OpLoc, - UnaryExprOrTypeTrait ExprKind, - SourceRange R) { +ExprResult Sema::CreateUnaryExprOrTypeTraitExpr(TypeSourceInfo *TInfo, + SourceLocation OpLoc, + UnaryExprOrTypeTrait ExprKind, + SourceRange R) { if (!TInfo) return ExprError(); @@ -4033,9 +4023,8 @@ /// Build a sizeof or alignof expression given an expression /// operand. -ExprResult -Sema::CreateUnaryExprOrTypeTraitExpr(Expr *E, SourceLocation OpLoc, - UnaryExprOrTypeTrait ExprKind) { +ExprResult Sema::CreateUnaryExprOrTypeTraitExpr(Expr *E, SourceLocation OpLoc, + UnaryExprOrTypeTrait ExprKind) { ExprResult PE = CheckPlaceholderExpr(E); if (PE.isInvalid()) return ExprError(); @@ -4051,9 +4040,9 @@ } else if (ExprKind == UETT_VecStep) { isInvalid = CheckVecStepExpr(E); } else if (ExprKind == UETT_OpenMPRequiredSimdAlign) { - Diag(E->getExprLoc(), diag::err_openmp_default_simd_align_expr); - isInvalid = true; - } else if (E->refersToBitField()) { // C99 6.5.3.4p1. + Diag(E->getExprLoc(), diag::err_openmp_default_simd_align_expr); + isInvalid = true; + } else if (E->refersToBitField()) { // C99 6.5.3.4p1. Diag(E->getExprLoc(), diag::err_sizeof_alignof_typeof_bitfield) << 0; isInvalid = true; } else { @@ -4065,7 +4054,8 @@ if (ExprKind == UETT_SizeOf && E->getType()->isVariableArrayType()) { PE = TransformToPotentiallyEvaluated(E); - if (PE.isInvalid()) return ExprError(); + if (PE.isInvalid()) + return ExprError(); E = PE.get(); } @@ -4077,16 +4067,17 @@ /// ActOnUnaryExprOrTypeTraitExpr - Handle @c sizeof(type) and @c sizeof @c /// expr and the same for @c alignof and @c __alignof /// Note that the ArgRange is invalid if isType is false. -ExprResult -Sema::ActOnUnaryExprOrTypeTraitExpr(SourceLocation OpLoc, - UnaryExprOrTypeTrait ExprKind, bool IsType, - void *TyOrEx, SourceRange ArgRange) { +ExprResult Sema::ActOnUnaryExprOrTypeTraitExpr(SourceLocation OpLoc, + UnaryExprOrTypeTrait ExprKind, + bool IsType, void *TyOrEx, + SourceRange ArgRange) { // If error parsing type, ignore. - if (!TyOrEx) return ExprError(); + if (!TyOrEx) + return ExprError(); if (IsType) { TypeSourceInfo *TInfo; - (void) GetTypeFromParser(ParsedType::getFromOpaquePtr(TyOrEx), &TInfo); + (void)GetTypeFromParser(ParsedType::getFromOpaquePtr(TyOrEx), &TInfo); return CreateUnaryExprOrTypeTraitExpr(TInfo, OpLoc, ExprKind, ArgRange); } @@ -4117,33 +4108,37 @@ // Test for placeholders. ExprResult PR = S.CheckPlaceholderExpr(V.get()); - if (PR.isInvalid()) return QualType(); + if (PR.isInvalid()) + return QualType(); if (PR.get() != V.get()) { V = PR; return CheckRealImagOperand(S, V, Loc, IsReal); } // Reject anything else. - S.Diag(Loc, diag::err_realimag_invalid_type) << V.get()->getType() - << (IsReal ? "__real" : "__imag"); + S.Diag(Loc, diag::err_realimag_invalid_type) + << V.get()->getType() << (IsReal ? "__real" : "__imag"); return QualType(); } - - -ExprResult -Sema::ActOnPostfixUnaryOp(Scope *S, SourceLocation OpLoc, - tok::TokenKind Kind, Expr *Input) { +ExprResult Sema::ActOnPostfixUnaryOp(Scope *S, SourceLocation OpLoc, + tok::TokenKind Kind, Expr *Input) { UnaryOperatorKind Opc; switch (Kind) { - default: llvm_unreachable("Unknown unary op!"); - case tok::plusplus: Opc = UO_PostInc; break; - case tok::minusminus: Opc = UO_PostDec; break; + default: + llvm_unreachable("Unknown unary op!"); + case tok::plusplus: + Opc = UO_PostInc; + break; + case tok::minusminus: + Opc = UO_PostDec; + break; } // Since this might is a postfix expression, get rid of ParenListExprs. ExprResult Result = MaybeConvertParenListExprToParenExpr(S, Input); - if (Result.isInvalid()) return ExprError(); + if (Result.isInvalid()) + return ExprError(); Input = Result.get(); return BuildUnaryOp(S, OpLoc, Opc, Input); @@ -4152,8 +4147,7 @@ /// Diagnose if arithmetic on the given ObjC pointer is illegal. /// /// \return true on error -static bool checkArithmeticOnObjCPointer(Sema &S, - SourceLocation opLoc, +static bool checkArithmeticOnObjCPointer(Sema &S, SourceLocation opLoc, Expr *op) { assert(op->getType()->isObjCObjectPointerType()); if (S.LangOpts.ObjCRuntime.allowsPointerArithmetic() && @@ -4161,8 +4155,8 @@ return false; S.Diag(opLoc, diag::err_arithmetic_nonfragile_interface) - << op->getType()->castAs()->getPointeeType() - << op->getSourceRange(); + << op->getType()->castAs()->getPointeeType() + << op->getSourceRange(); return true; } @@ -4173,9 +4167,9 @@ return isa(BaseNoParens); } -ExprResult -Sema::ActOnArraySubscriptExpr(Scope *S, Expr *base, SourceLocation lbLoc, - Expr *idx, SourceLocation rbLoc) { +ExprResult Sema::ActOnArraySubscriptExpr(Scope *S, Expr *base, + SourceLocation lbLoc, Expr *idx, + SourceLocation rbLoc) { if (base && !base->getType().isNull() && base->getType()->isSpecificPlaceholderType(BuiltinType::OMPArraySection)) return ActOnOMPArraySectionExpr(base, lbLoc, idx, SourceLocation(), @@ -4184,7 +4178,8 @@ // Since this might be a postfix expression, get rid of ParenListExprs. if (isa(base)) { ExprResult result = MaybeConvertParenListExprToParenExpr(S, base); - if (result.isInvalid()) return ExprError(); + if (result.isInvalid()) + return ExprError(); base = result.get(); } @@ -4205,7 +4200,8 @@ } if (idx->getType()->isNonOverloadPlaceholderType()) { ExprResult result = CheckPlaceholderExpr(idx); - if (result.isInvalid()) return ExprError(); + if (result.isInvalid()) + return ExprError(); idx = result.get(); } @@ -4352,7 +4348,8 @@ // OpenMP 4.5, [2.4 Array Sections] // The array section must be a subset of the original array. if (LowerBoundValue.isNegative()) { - Diag(LowerBound->getExprLoc(), diag::err_omp_section_not_subset_of_array) + Diag(LowerBound->getExprLoc(), + diag::err_omp_section_not_subset_of_array) << LowerBound->getSourceRange(); return ExprError(); } @@ -4394,9 +4391,9 @@ VK_LValue, OK_Ordinary, ColonLoc, RBLoc); } -ExprResult -Sema::CreateBuiltinArraySubscriptExpr(Expr *Base, SourceLocation LLoc, - Expr *Idx, SourceLocation RLoc) { +ExprResult Sema::CreateBuiltinArraySubscriptExpr(Expr *Base, + SourceLocation LLoc, Expr *Idx, + SourceLocation RLoc) { Expr *LHSExp = Base; Expr *RHSExp = Idx; @@ -4442,7 +4439,7 @@ IndexExpr = RHSExp; ResultType = PTy->getPointeeType(); } else if (const ObjCObjectPointerType *PTy = - LHSTy->getAs()) { + LHSTy->getAs()) { BaseExpr = LHSExp; IndexExpr = RHSExp; @@ -4454,23 +4451,23 @@ ResultType = PTy->getPointeeType(); } else if (const PointerType *PTy = RHSTy->getAs()) { - // Handle the uncommon case of "123[Ptr]". + // Handle the uncommon case of "123[Ptr]". BaseExpr = RHSExp; IndexExpr = LHSExp; ResultType = PTy->getPointeeType(); } else if (const ObjCObjectPointerType *PTy = - RHSTy->getAs()) { - // Handle the uncommon case of "123[Ptr]". + RHSTy->getAs()) { + // Handle the uncommon case of "123[Ptr]". BaseExpr = RHSExp; IndexExpr = LHSExp; ResultType = PTy->getPointeeType(); if (!LangOpts.isSubscriptPointerArithmetic()) { Diag(LLoc, diag::err_subscript_nonfragile_interface) - << ResultType << BaseExpr->getSourceRange(); + << ResultType << BaseExpr->getSourceRange(); return ExprError(); } } else if (const VectorType *VTy = LHSTy->getAs()) { - BaseExpr = LHSExp; // vectors: V[123] + BaseExpr = LHSExp; // vectors: V[123] IndexExpr = RHSExp; // We apply C++ DR1213 to vector subscripting too. if (getLangOpts().CPlusPlus11 && LHSExp->getValueKind() == VK_RValue) { @@ -4499,7 +4496,8 @@ Diag(LHSExp->getBeginLoc(), diag::ext_subscript_non_lvalue) << LHSExp->getSourceRange(); LHSExp = ImpCastExprToType(LHSExp, Context.getArrayDecayedType(LHSTy), - CK_ArrayToPointerDecay).get(); + CK_ArrayToPointerDecay) + .get(); LHSTy = LHSExp->getType(); BaseExpr = LHSExp; @@ -4510,7 +4508,8 @@ Diag(RHSExp->getBeginLoc(), diag::ext_subscript_non_lvalue) << RHSExp->getSourceRange(); RHSExp = ImpCastExprToType(RHSExp, Context.getArrayDecayedType(RHSTy), - CK_ArrayToPointerDecay).get(); + CK_ArrayToPointerDecay) + .get(); RHSTy = RHSExp->getType(); BaseExpr = RHSExp; @@ -4518,7 +4517,7 @@ ResultType = RHSTy->getAs()->getPointeeType(); } else { return ExprError(Diag(LLoc, diag::err_typecheck_subscript_value) - << LHSExp->getSourceRange() << RHSExp->getSourceRange()); + << LHSExp->getSourceRange() << RHSExp->getSourceRange()); } // C99 6.5.2.1p1 if (!IndexExpr->getType()->isIntegerType() && !IndexExpr->isTypeDependent()) @@ -4526,8 +4525,8 @@ << IndexExpr->getSourceRange()); if ((IndexExpr->getType()->isSpecificBuiltinType(BuiltinType::Char_S) || - IndexExpr->getType()->isSpecificBuiltinType(BuiltinType::Char_U)) - && !IndexExpr->isTypeDependent()) + IndexExpr->getType()->isSpecificBuiltinType(BuiltinType::Char_U)) && + !IndexExpr->isTypeDependent()) Diag(LLoc, diag::warn_subscript_is_char) << IndexExpr->getSourceRange(); // C99 6.5.2.1p1: "shall have type "pointer to *object* type". Similarly, @@ -4542,15 +4541,15 @@ if (ResultType->isVoidType() && !getLangOpts().CPlusPlus) { // GNU extension: subscripting on pointer to void - Diag(LLoc, diag::ext_gnu_subscript_void_type) - << BaseExpr->getSourceRange(); + Diag(LLoc, diag::ext_gnu_subscript_void_type) << BaseExpr->getSourceRange(); // C forbids expressions of unqualified void type from being l-values. // See IsCForbiddenLValueType. - if (!ResultType.hasQualifiers()) VK = VK_RValue; + if (!ResultType.hasQualifiers()) + VK = VK_RValue; } else if (!ResultType->isDependentType() && - RequireCompleteType(LLoc, ResultType, - diag::err_subscript_incomplete_type, BaseExpr)) + RequireCompleteType(LLoc, ResultType, + diag::err_subscript_incomplete_type, BaseExpr)) return ExprError(); assert(VK == VK_RValue || LangOpts.CPlusPlus || @@ -4563,9 +4562,8 @@ bool Sema::CheckCXXDefaultArgExpr(SourceLocation CallLoc, FunctionDecl *FD, ParmVarDecl *Param) { if (Param->hasUnparsedDefaultArg()) { - Diag(CallLoc, - diag::err_use_of_default_argument_to_function_declared_later) << - FD << cast(FD->getDeclContext())->getDeclName(); + Diag(CallLoc, diag::err_use_of_default_argument_to_function_declared_later) + << FD << cast(FD->getDeclContext())->getDeclName(); Diag(UnparsedDefaultArgLocs[Param], diag::note_default_argument_declared_here); return true; @@ -4594,8 +4592,8 @@ // // template // A Foo(int a = A::FooImpl()); - MultiLevelTemplateArgumentList MutiLevelArgList - = getTemplateInstantiationArgs(FD, nullptr, /*RelativeToPrimary=*/true); + MultiLevelTemplateArgumentList MutiLevelArgList = + getTemplateInstantiationArgs(FD, nullptr, /*RelativeToPrimary=*/true); InstantiatingTemplate Inst(*this, CallLoc, Param, MutiLevelArgList.getInnermost()); @@ -4616,14 +4614,14 @@ ContextRAII SavedContext(*this, FD); LocalInstantiationScope Local(*this); Result = SubstInitializer(UninstExpr, MutiLevelArgList, - /*DirectInit*/false); + /*DirectInit*/ false); } if (Result.isInvalid()) return true; // Check the expression as an initializer for the parameter. - InitializedEntity Entity - = InitializedEntity::InitializeParameter(Context, Param); + InitializedEntity Entity = + InitializedEntity::InitializeParameter(Context, Param); InitializationKind Kind = InitializationKind::CreateCopy( Param->getLocation(), /*FIXME:EqualLoc*/ UninstExpr->getBeginLoc()); @@ -4634,8 +4632,8 @@ if (Result.isInvalid()) return true; - Result = ActOnFinishFullExpr(Result.getAs(), - Param->getOuterLocStart()); + Result = + ActOnFinishFullExpr(Result.getAs(), Param->getOuterLocStart()); if (Result.isInvalid()) return true; @@ -4687,9 +4685,9 @@ return CXXDefaultArgExpr::Create(Context, CallLoc, Param); } -Sema::VariadicCallType -Sema::getVariadicCallType(FunctionDecl *FDecl, const FunctionProtoType *Proto, - Expr *Fn) { +Sema::VariadicCallType Sema::getVariadicCallType(FunctionDecl *FDecl, + const FunctionProtoType *Proto, + Expr *Fn) { if (Proto && Proto->isVariadic()) { if (dyn_cast_or_null(FDecl)) return VariadicConstructor; @@ -4773,13 +4771,12 @@ /// Fn is the function expression. For a C++ member function, this /// routine does not attempt to convert the object argument. Returns /// true if the call is ill-formed. -bool -Sema::ConvertArgumentsForCall(CallExpr *Call, Expr *Fn, - FunctionDecl *FDecl, - const FunctionProtoType *Proto, - ArrayRef Args, - SourceLocation RParenLoc, - bool IsExecConfig) { +bool Sema::ConvertArgumentsForCall(CallExpr *Call, Expr *Fn, + FunctionDecl *FDecl, + const FunctionProtoType *Proto, + ArrayRef Args, + SourceLocation RParenLoc, + bool IsExecConfig) { // Bail out early if calling a builtin with custom typechecking. if (FDecl) if (unsigned ID = FDecl->getBuiltinID()) @@ -4792,9 +4789,9 @@ bool Invalid = false; unsigned MinArgs = FDecl ? FDecl->getMinRequiredArguments() : NumParams; unsigned FnKind = Fn->getType()->isBlockPointerType() - ? 1 /* block */ - : (IsExecConfig ? 3 /* kernel function (exec config) */ - : 0 /* function */); + ? 1 /* block */ + : (IsExecConfig ? 3 /* kernel function (exec config) */ + : 0 /* function */); // If too few arguments are available (and we don't have default // arguments for the remaining parameters), don't make the call. @@ -4806,9 +4803,10 @@ MinArgs == NumParams && !Proto->isVariadic() ? diag::err_typecheck_call_too_few_args_suggest : diag::err_typecheck_call_too_few_args_at_least_suggest; - diagnoseTypo(TC, PDiag(diag_id) << FnKind << MinArgs - << static_cast(Args.size()) - << TC.getCorrectionRange()); + diagnoseTypo(TC, + PDiag(diag_id) << FnKind << MinArgs + << static_cast(Args.size()) + << TC.getCorrectionRange()); } else if (MinArgs == 1 && FDecl && FDecl->getParamDecl(0)->getDeclName()) Diag(RParenLoc, MinArgs == NumParams && !Proto->isVariadic() @@ -4816,9 +4814,10 @@ : diag::err_typecheck_call_too_few_args_at_least_one) << FnKind << FDecl->getParamDecl(0) << Fn->getSourceRange(); else - Diag(RParenLoc, MinArgs == NumParams && !Proto->isVariadic() - ? diag::err_typecheck_call_too_few_args - : diag::err_typecheck_call_too_few_args_at_least) + Diag(RParenLoc, + MinArgs == NumParams && !Proto->isVariadic() + ? diag::err_typecheck_call_too_few_args + : diag::err_typecheck_call_too_few_args_at_least) << FnKind << MinArgs << static_cast(Args.size()) << Fn->getSourceRange(); @@ -4841,9 +4840,10 @@ MinArgs == NumParams && !Proto->isVariadic() ? diag::err_typecheck_call_too_many_args_suggest : diag::err_typecheck_call_too_many_args_at_most_suggest; - diagnoseTypo(TC, PDiag(diag_id) << FnKind << NumParams - << static_cast(Args.size()) - << TC.getCorrectionRange()); + diagnoseTypo(TC, + PDiag(diag_id) << FnKind << NumParams + << static_cast(Args.size()) + << TC.getCorrectionRange()); } else if (NumParams == 1 && FDecl && FDecl->getParamDecl(0)->getDeclName()) Diag(Args[NumParams]->getBeginLoc(), @@ -4911,12 +4911,12 @@ // Strip the unbridged-cast placeholder expression off, if applicable. bool CFAudited = false; - if (Arg->getType() == Context.ARCUnbridgedCastTy && - FDecl && FDecl->hasAttr() && + if (Arg->getType() == Context.ARCUnbridgedCastTy && FDecl && + FDecl->hasAttr() && (!Param || !Param->hasAttr())) Arg = stripARCUnbridgedCast(Arg); - else if (getLangOpts().ObjCAutoRefCount && - FDecl && FDecl->hasAttr() && + else if (getLangOpts().ObjCAutoRefCount && FDecl && + FDecl->hasAttr() && (!Param || !Param->hasAttr())) CFAudited = true; @@ -4943,8 +4943,7 @@ } else { assert(Param && "can't use default arguments without a known callee"); - ExprResult ArgExpr = - BuildCXXDefaultArgExpr(CallLoc, FDecl, Param); + ExprResult ArgExpr = BuildCXXDefaultArgExpr(CallLoc, FDecl, Param); if (ArgExpr.isInvalid()) return true; @@ -4975,7 +4974,7 @@ AllArgs.push_back(arg.get()); } - // Otherwise do argument promotion, (C99 6.5.2.2p7). + // Otherwise do argument promotion, (C99 6.5.2.2p7). } else { for (Expr *A : Args.slice(ArgIx)) { ExprResult Arg = DefaultVariadicArgumentPromotion(A, CallType, FDecl); @@ -4997,7 +4996,7 @@ TL = DTL.getOriginalLoc(); if (ArrayTypeLoc ATL = TL.getAs()) S.Diag(PVD->getLocation(), diag::note_callee_static_array) - << ATL.getLocalSourceRange(); + << ATL.getLocalSourceRange(); } /// CheckStaticArrayArgument - If the given argument corresponds to a static @@ -5008,10 +5007,8 @@ /// array type derivation, then for each call to the function, the value of the /// corresponding actual argument shall provide access to the first element of /// an array with at least as many elements as specified by the size expression. -void -Sema::CheckStaticArrayArgument(SourceLocation CallLoc, - ParmVarDecl *Param, - const Expr *ArgExpr) { +void Sema::CheckStaticArrayArgument(SourceLocation CallLoc, ParmVarDecl *Param, + const Expr *ArgExpr) { // Static array parameters are not supported in C++. if (!Param || getLangOpts().CPlusPlus) return; @@ -5022,8 +5019,7 @@ if (!AT || AT->getSizeModifier() != ArrayType::Static) return; - if (ArgExpr->isNullPointerConstant(Context, - Expr::NPC_NeverValueDependent)) { + if (ArgExpr->isNullPointerConstant(Context, Expr::NPC_NeverValueDependent)) { Diag(CallLoc, diag::warn_null_arg) << ArgExpr->getSourceRange(); DiagnoseCalleeStaticArrayParam(*this, Param); return; @@ -5034,15 +5030,15 @@ return; const ConstantArrayType *ArgCAT = - Context.getAsConstantArrayType(ArgExpr->IgnoreParenImpCasts()->getType()); + Context.getAsConstantArrayType(ArgExpr->IgnoreParenImpCasts()->getType()); if (!ArgCAT) return; if (ArgCAT->getSize().ult(CAT->getSize())) { Diag(CallLoc, diag::warn_static_array_too_small) - << ArgExpr->getSourceRange() - << (unsigned) ArgCAT->getSize().getZExtValue() - << (unsigned) CAT->getSize().getZExtValue(); + << ArgExpr->getSourceRange() + << (unsigned)ArgCAT->getSize().getZExtValue() + << (unsigned)CAT->getSize().getZExtValue(); DiagnoseCalleeStaticArrayParam(*this, Param); } } @@ -5056,11 +5052,12 @@ static bool isPlaceholderToRemoveAsArg(QualType type) { // Placeholders are never sugared. const BuiltinType *placeholder = dyn_cast(type); - if (!placeholder) return false; + if (!placeholder) + return false; switch (placeholder->getKind()) { - // Ignore all the non-placeholder types. -#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ +// Ignore all the non-placeholder types. +#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ case BuiltinType::Id: #include "clang/Basic/OpenCLImageTypes.def" #define PLACEHOLDER_TYPE(ID, SINGLETON_ID) @@ -5092,7 +5089,6 @@ case BuiltinType::BuiltinFn: case BuiltinType::OMPArraySection: return true; - } llvm_unreachable("bad builtin type kind"); } @@ -5106,8 +5102,10 @@ for (size_t i = 0, e = args.size(); i != e; i++) { if (isPlaceholderToRemoveAsArg(args[i]->getType())) { ExprResult result = S.CheckPlaceholderExpr(args[i]); - if (result.isInvalid()) hasInvalid = true; - else args[i] = result.get(); + if (result.isInvalid()) + hasInvalid = true; + else + args[i] = result.get(); } else if (hasInvalid) { (void)S.CorrectDelayedTyposInExpr(args[i]); } @@ -5133,8 +5131,8 @@ QualType DeclType = FDecl->getType(); const FunctionProtoType *FT = dyn_cast(DeclType); - if (!Context.BuiltinInfo.hasPtrArgsOrResult(FDecl->getBuiltinID()) || - !FT || FT->isVariadic() || ArgExprs.size() != FT->getNumParams()) + if (!Context.BuiltinInfo.hasPtrArgsOrResult(FDecl->getBuiltinID()) || !FT || + FT->isVariadic() || ArgExprs.size() != FT->getNumParams()) return nullptr; bool NeedsNewDecl = false; @@ -5173,25 +5171,22 @@ return nullptr; FunctionProtoType::ExtProtoInfo EPI; - QualType OverloadTy = Context.getFunctionType(FT->getReturnType(), - OverloadParams, EPI); + QualType OverloadTy = + Context.getFunctionType(FT->getReturnType(), OverloadParams, EPI); DeclContext *Parent = Context.getTranslationUnitDecl(); - FunctionDecl *OverloadDecl = FunctionDecl::Create(Context, Parent, - FDecl->getLocation(), - FDecl->getLocation(), - FDecl->getIdentifier(), - OverloadTy, - /*TInfo=*/nullptr, - SC_Extern, false, - /*hasPrototype=*/true); - SmallVector Params; + FunctionDecl *OverloadDecl = FunctionDecl::Create( + Context, Parent, FDecl->getLocation(), FDecl->getLocation(), + FDecl->getIdentifier(), OverloadTy, + /*TInfo=*/nullptr, SC_Extern, false, + /*hasPrototype=*/true); + SmallVector Params; FT = cast(OverloadTy); for (unsigned i = 0, e = FT->getNumParams(); i != e; ++i) { QualType ParamType = FT->getParamType(i); ParmVarDecl *Parm = ParmVarDecl::Create(Context, OverloadDecl, SourceLocation(), - SourceLocation(), nullptr, ParamType, - /*TInfo=*/nullptr, SC_None, nullptr); + SourceLocation(), nullptr, ParamType, + /*TInfo=*/nullptr, SC_None, nullptr); Parm->setScopeInfo(0, i); Params.push_back(Parm); } @@ -5287,7 +5282,6 @@ if (!enclosingClassIsRelatedToClassInWhichMembersWereFound(UME, S)) return; - DeclContext *EnclosingFunctionCtx = S.CurContext->getParent()->getParent(); // If the enclosing function is not dependent, then this lambda is // capture ready, so if we can capture this, do so. @@ -5314,7 +5308,8 @@ Expr *ExecConfig, bool IsExecConfig) { // Since this might be a postfix expression, get rid of ParenListExprs. ExprResult Result = MaybeConvertParenListExprToParenExpr(Scope, Fn); - if (Result.isInvalid()) return ExprError(); + if (Result.isInvalid()) + return ExprError(); Fn = Result.get(); if (checkArgsForPlaceholders(*this, ArgExprs)) @@ -5336,7 +5331,8 @@ } if (Fn->getType() == Context.PseudoObjectTy) { ExprResult result = CheckPlaceholderExpr(Fn); - if (result.isInvalid()) return ExprError(); + if (result.isInvalid()) + return ExprError(); Fn = result.get(); } @@ -5365,7 +5361,8 @@ if (Fn->getType() == Context.UnknownAnyTy) { ExprResult result = rebuildUnknownAnyFunction(*this, Fn); - if (result.isInvalid()) return ExprError(); + if (result.isInvalid()) + return ExprError(); Fn = result.get(); } @@ -5397,7 +5394,8 @@ // If we're directly calling a function, get the appropriate declaration. if (Fn->getType() == Context.UnknownAnyTy) { ExprResult result = rebuildUnknownAnyFunction(*this, Fn); - if (result.isInvalid()) return ExprError(); + if (result.isInvalid()) + return ExprError(); Fn = result.get(); } @@ -5432,8 +5430,9 @@ NDecl = cast(NakedFn)->getMemberDecl(); if (FunctionDecl *FD = dyn_cast_or_null(NDecl)) { - if (CallingNDeclIndirectly && !checkAddressOfFunctionIsAvailable( - FD, /*Complain=*/true, Fn->getBeginLoc())) + if (CallingNDeclIndirectly && + !checkAddressOfFunctionIsAvailable(FD, /*Complain=*/true, + Fn->getBeginLoc())) return ExprError(); if (getLangOpts().OpenCL && checkOpenCLDisabledDecl(*FD, *Fn)) @@ -5458,11 +5457,9 @@ QualType DstTy = GetTypeFromParser(ParsedDestTy); QualType SrcTy = E->getType(); if (Context.getTypeSize(DstTy) != Context.getTypeSize(SrcTy)) - return ExprError(Diag(BuiltinLoc, - diag::err_invalid_astype_of_different_size) - << DstTy - << SrcTy - << E->getSourceRange()); + return ExprError( + Diag(BuiltinLoc, diag::err_invalid_astype_of_different_size) + << DstTy << SrcTy << E->getSourceRange()); return new (Context) AsTypeExpr(E, DstTy, VK, OK, BuiltinLoc, RParenLoc); } @@ -5485,12 +5482,11 @@ /// block-pointer type. /// /// \param NDecl the declaration being called, if available -ExprResult -Sema::BuildResolvedCallExpr(Expr *Fn, NamedDecl *NDecl, - SourceLocation LParenLoc, - ArrayRef Args, - SourceLocation RParenLoc, - Expr *Config, bool IsExecConfig) { +ExprResult Sema::BuildResolvedCallExpr(Expr *Fn, NamedDecl *NDecl, + SourceLocation LParenLoc, + ArrayRef Args, + SourceLocation RParenLoc, Expr *Config, + bool IsExecConfig) { FunctionDecl *FDecl = dyn_cast_or_null(NDecl); unsigned BuiltinID = (FDecl ? FDecl->getBuiltinID() : 0); @@ -5518,7 +5514,8 @@ if (BuiltinID && Fn->getType()->isSpecificBuiltinType(BuiltinType::BuiltinFn)) { Result = ImpCastExprToType(Fn, Context.getPointerType(FDecl->getType()), - CK_BuiltinFnToFnPtr).get(); + CK_BuiltinFnToFnPtr) + .get(); } else { Result = CallExprUnaryConversions(Fn); } @@ -5530,13 +5527,12 @@ // of arguments and function on error. CallExpr *TheCall; if (Config) - TheCall = new (Context) CUDAKernelCallExpr(Context, Fn, - cast(Config), Args, - Context.BoolTy, VK_RValue, - RParenLoc); + TheCall = new (Context) + CUDAKernelCallExpr(Context, Fn, cast(Config), Args, + Context.BoolTy, VK_RValue, RParenLoc); else - TheCall = new (Context) CallExpr(Context, Fn, Args, Context.BoolTy, - VK_RValue, RParenLoc); + TheCall = new (Context) + CallExpr(Context, Fn, Args, Context.BoolTy, VK_RValue, RParenLoc); if (!getLangOpts().CPlusPlus) { // C cannot always handle TypoExpr nodes in builtin calls and direct @@ -5544,9 +5540,11 @@ // dependent types properly, so make sure any TypoExprs have been // dealt with. ExprResult Result = CorrectDelayedTyposInExpr(TheCall); - if (!Result.isUsable()) return ExprError(); + if (!Result.isUsable()) + return ExprError(); TheCall = dyn_cast(Result.get()); - if (!TheCall) return Result; + if (!TheCall) + return Result; Args = llvm::makeArrayRef(TheCall->getArgs(), TheCall->getNumArgs()); } @@ -5554,7 +5552,7 @@ if (BuiltinID && Context.BuiltinInfo.hasCustomTypechecking(BuiltinID)) return CheckBuiltinFunctionCall(FDecl, BuiltinID, TheCall); - retry: +retry: const FunctionType *FuncT; if (const PointerType *PT = Fn->getType()->getAs()) { // C99 6.5.2.2p1 - "The expression that denotes the called function shall @@ -5562,40 +5560,42 @@ FuncT = PT->getPointeeType()->getAs(); if (!FuncT) return ExprError(Diag(LParenLoc, diag::err_typecheck_call_not_function) - << Fn->getType() << Fn->getSourceRange()); + << Fn->getType() << Fn->getSourceRange()); } else if (const BlockPointerType *BPT = - Fn->getType()->getAs()) { + Fn->getType()->getAs()) { FuncT = BPT->getPointeeType()->castAs(); } else { // Handle calls to expressions of unknown-any type. if (Fn->getType() == Context.UnknownAnyTy) { ExprResult rewrite = rebuildUnknownAnyFunction(*this, Fn); - if (rewrite.isInvalid()) return ExprError(); + if (rewrite.isInvalid()) + return ExprError(); Fn = rewrite.get(); TheCall->setCallee(Fn); goto retry; } return ExprError(Diag(LParenLoc, diag::err_typecheck_call_not_function) - << Fn->getType() << Fn->getSourceRange()); + << Fn->getType() << Fn->getSourceRange()); } if (getLangOpts().CUDA) { if (Config) { // CUDA: Kernel calls must be to global functions if (FDecl && !FDecl->hasAttr()) - return ExprError(Diag(LParenLoc,diag::err_kern_call_not_global_function) + return ExprError( + Diag(LParenLoc, diag::err_kern_call_not_global_function) << FDecl << Fn->getSourceRange()); // CUDA: Kernel function must have 'void' return type if (!FuncT->getReturnType()->isVoidType()) return ExprError(Diag(LParenLoc, diag::err_kern_type_not_void_return) - << Fn->getType() << Fn->getSourceRange()); + << Fn->getType() << Fn->getSourceRange()); } else { // CUDA: Calls to global functions must be configured if (FDecl && FDecl->hasAttr()) return ExprError(Diag(LParenLoc, diag::err_global_call_not_config) - << FDecl << Fn->getSourceRange()); + << FDecl << Fn->getSourceRange()); } } @@ -5622,9 +5622,11 @@ const FunctionDecl *Def = nullptr; if (FDecl->hasBody(Def) && Args.size() != Def->param_size()) { Proto = Def->getType()->getAs(); - if (!Proto || !(Proto->isVariadic() && Args.size() >= Def->param_size())) + if (!Proto || + !(Proto->isVariadic() && Args.size() >= Def->param_size())) Diag(RParenLoc, diag::warn_call_wrong_number_of_arguments) - << (Args.size() > Def->param_size()) << FDecl << Fn->getSourceRange(); + << (Args.size() > Def->param_size()) << FDecl + << Fn->getSourceRange(); } // If the function we're calling isn't a function prototype, but we have @@ -5667,7 +5669,7 @@ if (CXXMethodDecl *Method = dyn_cast_or_null(FDecl)) if (!Method->isStatic()) return ExprError(Diag(LParenLoc, diag::err_member_call_without_object) - << Fn->getSourceRange()); + << Fn->getSourceRange()); // Check for sentinels if (NDecl) @@ -5691,9 +5693,9 @@ return MaybeBindToTemporary(TheCall); } -ExprResult -Sema::ActOnCompoundLiteral(SourceLocation LParenLoc, ParsedType Ty, - SourceLocation RParenLoc, Expr *InitExpr) { +ExprResult Sema::ActOnCompoundLiteral(SourceLocation LParenLoc, ParsedType Ty, + SourceLocation RParenLoc, + Expr *InitExpr) { assert(Ty && "ActOnCompoundLiteral(): missing type"); assert(InitExpr && "ActOnCompoundLiteral(): missing expression"); @@ -5705,43 +5707,45 @@ return BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc, InitExpr); } -ExprResult -Sema::BuildCompoundLiteralExpr(SourceLocation LParenLoc, TypeSourceInfo *TInfo, - SourceLocation RParenLoc, Expr *LiteralExpr) { +ExprResult Sema::BuildCompoundLiteralExpr(SourceLocation LParenLoc, + TypeSourceInfo *TInfo, + SourceLocation RParenLoc, + Expr *LiteralExpr) { QualType literalType = TInfo->getType(); if (literalType->isArrayType()) { - if (RequireCompleteType(LParenLoc, Context.getBaseElementType(literalType), - diag::err_illegal_decl_array_incomplete_type, - SourceRange(LParenLoc, - LiteralExpr->getSourceRange().getEnd()))) + if (RequireCompleteType( + LParenLoc, Context.getBaseElementType(literalType), + diag::err_illegal_decl_array_incomplete_type, + SourceRange(LParenLoc, LiteralExpr->getSourceRange().getEnd()))) return ExprError(); if (literalType->isVariableArrayType()) - return ExprError(Diag(LParenLoc, diag::err_variable_object_no_init) - << SourceRange(LParenLoc, LiteralExpr->getSourceRange().getEnd())); + return ExprError( + Diag(LParenLoc, diag::err_variable_object_no_init) + << SourceRange(LParenLoc, LiteralExpr->getSourceRange().getEnd())); } else if (!literalType->isDependentType() && - RequireCompleteType(LParenLoc, literalType, - diag::err_typecheck_decl_incomplete_type, - SourceRange(LParenLoc, LiteralExpr->getSourceRange().getEnd()))) + RequireCompleteType( + LParenLoc, literalType, + diag::err_typecheck_decl_incomplete_type, + SourceRange(LParenLoc, + LiteralExpr->getSourceRange().getEnd()))) return ExprError(); - InitializedEntity Entity - = InitializedEntity::InitializeCompoundLiteralInit(TInfo); - InitializationKind Kind - = InitializationKind::CreateCStyleCast(LParenLoc, - SourceRange(LParenLoc, RParenLoc), - /*InitList=*/true); + InitializedEntity Entity = + InitializedEntity::InitializeCompoundLiteralInit(TInfo); + InitializationKind Kind = InitializationKind::CreateCStyleCast( + LParenLoc, SourceRange(LParenLoc, RParenLoc), + /*InitList=*/true); InitializationSequence InitSeq(*this, Entity, Kind, LiteralExpr); - ExprResult Result = InitSeq.Perform(*this, Entity, Kind, LiteralExpr, - &literalType); + ExprResult Result = + InitSeq.Perform(*this, Entity, Kind, LiteralExpr, &literalType); if (Result.isInvalid()) return ExprError(); LiteralExpr = Result.get(); bool isFileScope = !CurContext->isFunctionOrMethod(); if (isFileScope) { - if (!LiteralExpr->isTypeDependent() && - !LiteralExpr->isValueDependent() && + if (!LiteralExpr->isTypeDependent() && !LiteralExpr->isValueDependent() && !literalType->isDependentType()) // C99 6.5.2.5p3 if (CheckForConstantInitializer(LiteralExpr, literalType)) return ExprError(); @@ -5751,7 +5755,7 @@ // "If the compound literal occurs inside the body of a function, the // type name shall not be qualified by an address-space qualifier." Diag(LParenLoc, diag::err_compound_literal_with_address_space) - << SourceRange(LParenLoc, LiteralExpr->getSourceRange().getEnd()); + << SourceRange(LParenLoc, LiteralExpr->getSourceRange().getEnd()); return ExprError(); } @@ -5778,14 +5782,13 @@ ? VK_RValue : VK_LValue; - return MaybeBindToTemporary( - new (Context) CompoundLiteralExpr(LParenLoc, TInfo, literalType, - VK, LiteralExpr, isFileScope)); + return MaybeBindToTemporary(new (Context) CompoundLiteralExpr( + LParenLoc, TInfo, literalType, VK, LiteralExpr, isFileScope)); } -ExprResult -Sema::ActOnInitList(SourceLocation LBraceLoc, MultiExprArg InitArgList, - SourceLocation RBraceLoc) { +ExprResult Sema::ActOnInitList(SourceLocation LBraceLoc, + MultiExprArg InitArgList, + SourceLocation RBraceLoc) { // Immediately handle non-overload placeholders. Overloads can be // resolved contextually, but everything else here can't. for (unsigned I = 0, E = InitArgList.size(); I != E; ++I) { @@ -5794,7 +5797,8 @@ // Ignore failures; dropping the entire initializer list because // of one failure would be terrible for indexing/etc. - if (result.isInvalid()) continue; + if (result.isInvalid()) + continue; InitArgList[I] = result.get(); } @@ -5803,8 +5807,8 @@ // Semantic analysis for initializers is done by ActOnDeclarator() and // CheckInitializer() - it requires knowledge of the object being initialized. - InitListExpr *E = new (Context) InitListExpr(Context, LBraceLoc, InitArgList, - RBraceLoc); + InitListExpr *E = + new (Context) InitListExpr(Context, LBraceLoc, InitArgList, RBraceLoc); E->setType(Context.VoidTy); // FIXME: just a place holder for now. return E; } @@ -5815,7 +5819,8 @@ assert(E.get()->isRValue()); // Only do this in an r-value context. - if (!getLangOpts().ObjCAutoRefCount) return; + if (!getLangOpts().ObjCAutoRefCount) + return; E = ImplicitCastExpr::Create(Context, E.get()->getType(), CK_ARCExtendBlockObject, E.get(), @@ -5866,7 +5871,8 @@ } case Type::STK_BlockPointer: return (SrcKind == Type::STK_BlockPointer - ? CK_BitCast : CK_AnyPointerToBlockPointerCast); + ? CK_BitCast + : CK_AnyPointerToBlockPointerCast); case Type::STK_ObjCObjectPointer: if (SrcKind == Type::STK_ObjCObjectPointer) return CK_BitCast; @@ -5904,13 +5910,13 @@ return CK_IntegralToFloating; case Type::STK_IntegralComplex: Src = ImpCastExprToType(Src.get(), - DestTy->castAs()->getElementType(), - CK_IntegralCast); + DestTy->castAs()->getElementType(), + CK_IntegralCast); return CK_IntegralRealToComplex; case Type::STK_FloatingComplex: Src = ImpCastExprToType(Src.get(), - DestTy->castAs()->getElementType(), - CK_IntegralToFloating); + DestTy->castAs()->getElementType(), + CK_IntegralToFloating); return CK_FloatingRealToComplex; case Type::STK_MemberPointer: llvm_unreachable("member pointer type in C"); @@ -6018,7 +6024,8 @@ // We allow lax conversion to and from non-vector types, but only if // they're real types (i.e. non-complex, non-pointer scalar types). - if (!type->isRealType()) return false; + if (!type->isRealType()) + return false; len = 1; eltType = type; @@ -6040,13 +6047,17 @@ // depend on them). Most scalar OP ExtVector cases are handled by the // splat path anyway, which does what we want (convert, not bitcast). // What this rules out for ExtVectors is crazy things like char4*float. - if (srcTy->isScalarType() && destTy->isExtVectorType()) return false; - if (destTy->isScalarType() && srcTy->isExtVectorType()) return false; + if (srcTy->isScalarType() && destTy->isExtVectorType()) + return false; + if (destTy->isScalarType() && srcTy->isExtVectorType()) + return false; uint64_t srcLen, destLen; QualType srcEltTy, destEltTy; - if (!breakDownVectorType(srcTy, srcLen, srcEltTy)) return false; - if (!breakDownVectorType(destTy, destLen, destEltTy)) return false; + if (!breakDownVectorType(srcTy, srcLen, srcEltTy)) + return false; + if (!breakDownVectorType(destTy, destLen, destEltTy)) + return false; // ASTContext::getTypeSize will return the size rounded up to a // power of 2, so instead of using that, we need to use the raw @@ -6074,14 +6085,14 @@ if (Ty->isVectorType() || Ty->isIntegralType(Context)) { if (!areLaxCompatibleVectorTypes(Ty, VectorTy)) return Diag(R.getBegin(), - Ty->isVectorType() ? - diag::err_invalid_conversion_between_vectors : - diag::err_invalid_conversion_between_vector_and_integer) - << VectorTy << Ty << R; + Ty->isVectorType() + ? diag::err_invalid_conversion_between_vectors + : diag::err_invalid_conversion_between_vector_and_integer) + << VectorTy << Ty << R; } else return Diag(R.getBegin(), diag::err_invalid_conversion_between_vector_and_scalar) - << VectorTy << Ty << R; + << VectorTy << Ty << R; Kind = CK_BitCast; return false; @@ -6134,8 +6145,8 @@ if (!areLaxCompatibleVectorTypes(SrcTy, DestTy) || (getLangOpts().OpenCL && !Context.hasSameUnqualifiedType(DestTy, SrcTy))) { - Diag(R.getBegin(),diag::err_invalid_conversion_between_ext_vectors) - << DestTy << SrcTy << R; + Diag(R.getBegin(), diag::err_invalid_conversion_between_ext_vectors) + << DestTy << SrcTy << R; return ExprError(); } Kind = CK_BitCast; @@ -6148,16 +6159,15 @@ if (SrcTy->isPointerType()) return Diag(R.getBegin(), diag::err_invalid_conversion_between_vector_and_scalar) - << DestTy << SrcTy << R; + << DestTy << SrcTy << R; Kind = CK_VectorSplat; return prepareVectorSplat(DestTy, CastExpr); } -ExprResult -Sema::ActOnCastExpr(Scope *S, SourceLocation LParenLoc, - Declarator &D, ParsedType &Ty, - SourceLocation RParenLoc, Expr *CastExpr) { +ExprResult Sema::ActOnCastExpr(Scope *S, SourceLocation LParenLoc, + Declarator &D, ParsedType &Ty, + SourceLocation RParenLoc, Expr *CastExpr) { assert(!D.isInvalidType() && (CastExpr != nullptr) && "ActOnCastExpr(): missing type or expr"); @@ -6187,8 +6197,9 @@ // i.e. all the elements are integer constants. ParenExpr *PE = dyn_cast(CastExpr); ParenListExpr *PLE = dyn_cast(CastExpr); - if ((getLangOpts().AltiVec || getLangOpts().ZVector || getLangOpts().OpenCL) - && castType->isVectorType() && (PE || PLE)) { + if ((getLangOpts().AltiVec || getLangOpts().ZVector || + getLangOpts().OpenCL) && + castType->isVectorType() && (PE || PLE)) { if (PLE && PLE->getNumExprs() == 0) { Diag(PLE->getExprLoc(), diag::err_altivec_empty_initializer); return ExprError(); @@ -6197,8 +6208,7 @@ Expr *E = (PE ? PE->getSubExpr() : PLE->getExpr(0)); if (!E->getType()->isVectorType()) isVectorLiteral = true; - } - else + } else isVectorLiteral = true; } @@ -6212,7 +6222,8 @@ // sequence of BinOp comma operators. if (isa(CastExpr)) { ExprResult Result = MaybeConvertParenListExprToParenExpr(S, CastExpr); - if (Result.isInvalid()) return ExprError(); + if (Result.isInvalid()) + return ExprError(); CastExpr = Result.get(); } @@ -6275,44 +6286,39 @@ Literal = ImpCastExprToType(Literal.get(), ElemTy, PrepareScalarCast(Literal, ElemTy)); return BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc, Literal.get()); - } - else if (numExprs < numElems) { - Diag(E->getExprLoc(), - diag::err_incorrect_number_of_vector_initializers); + } else if (numExprs < numElems) { + Diag(E->getExprLoc(), diag::err_incorrect_number_of_vector_initializers); return ExprError(); - } - else + } else initExprs.append(exprs, exprs + numExprs); - } - else { + } else { // For OpenCL, when the number of initializers is a single value, // it will be replicated to all components of the vector. if (getLangOpts().OpenCL && - VTy->getVectorKind() == VectorType::GenericVector && - numExprs == 1) { - QualType ElemTy = Ty->getAs()->getElementType(); - ExprResult Literal = DefaultLvalueConversion(exprs[0]); - if (Literal.isInvalid()) - return ExprError(); - Literal = ImpCastExprToType(Literal.get(), ElemTy, - PrepareScalarCast(Literal, ElemTy)); - return BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc, Literal.get()); + VTy->getVectorKind() == VectorType::GenericVector && numExprs == 1) { + QualType ElemTy = Ty->getAs()->getElementType(); + ExprResult Literal = DefaultLvalueConversion(exprs[0]); + if (Literal.isInvalid()) + return ExprError(); + Literal = ImpCastExprToType(Literal.get(), ElemTy, + PrepareScalarCast(Literal, ElemTy)); + return BuildCStyleCastExpr(LParenLoc, TInfo, RParenLoc, Literal.get()); } initExprs.append(exprs, exprs + numExprs); } // FIXME: This means that pretty-printing the final AST will produce curly // braces instead of the original commas. - InitListExpr *initE = new (Context) InitListExpr(Context, LiteralLParenLoc, - initExprs, LiteralRParenLoc); + InitListExpr *initE = new (Context) + InitListExpr(Context, LiteralLParenLoc, initExprs, LiteralRParenLoc); initE->setType(Ty); return BuildCompoundLiteralExpr(LParenLoc, TInfo, RParenLoc, initE); } /// This is not an AltiVec-style cast or or C++ direct-initialization, so turn /// the ParenListExpr into a sequence of comma binary operators. -ExprResult -Sema::MaybeConvertParenListExprToParenExpr(Scope *S, Expr *OrigExpr) { +ExprResult Sema::MaybeConvertParenListExprToParenExpr(Scope *S, + Expr *OrigExpr) { ParenListExpr *E = dyn_cast(OrigExpr); if (!E) return OrigExpr; @@ -6320,16 +6326,16 @@ ExprResult Result(E->getExpr(0)); for (unsigned i = 1, e = E->getNumExprs(); i != e && !Result.isInvalid(); ++i) - Result = ActOnBinOp(S, E->getExprLoc(), tok::comma, Result.get(), - E->getExpr(i)); + Result = + ActOnBinOp(S, E->getExprLoc(), tok::comma, Result.get(), E->getExpr(i)); - if (Result.isInvalid()) return ExprError(); + if (Result.isInvalid()) + return ExprError(); return ActOnParenExpr(E->getLParenLoc(), E->getRParenLoc(), Result.get()); } -ExprResult Sema::ActOnParenListExpr(SourceLocation L, - SourceLocation R, +ExprResult Sema::ActOnParenListExpr(SourceLocation L, SourceLocation R, MultiExprArg Val) { Expr *expr = new (Context) ParenListExpr(Context, L, Val, R); return expr; @@ -6342,16 +6348,14 @@ SourceLocation QuestionLoc) { Expr *NullExpr = LHSExpr; Expr *NonPointerExpr = RHSExpr; - Expr::NullPointerConstantKind NullKind = - NullExpr->isNullPointerConstant(Context, - Expr::NPC_ValueDependentIsNotNull); + Expr::NullPointerConstantKind NullKind = NullExpr->isNullPointerConstant( + Context, Expr::NPC_ValueDependentIsNotNull); if (NullKind == Expr::NPCK_NotNull) { NullExpr = RHSExpr; NonPointerExpr = LHSExpr; - NullKind = - NullExpr->isNullPointerConstant(Context, - Expr::NPC_ValueDependentIsNotNull); + NullKind = NullExpr->isNullPointerConstant( + Context, Expr::NPC_ValueDependentIsNotNull); } if (NullKind == Expr::NPCK_NotNull) @@ -6383,33 +6387,34 @@ // OpenCL v1.1 s6.3.i says the condition cannot be a floating point type. if (S.getLangOpts().OpenCL && CondTy->isFloatingType()) { S.Diag(QuestionLoc, diag::err_typecheck_cond_expect_nonfloat) - << CondTy << Cond->getSourceRange(); + << CondTy << Cond->getSourceRange(); return true; } // C99 6.5.15p2 - if (CondTy->isScalarType()) return false; + if (CondTy->isScalarType()) + return false; S.Diag(QuestionLoc, diag::err_typecheck_cond_expect_scalar) - << CondTy << Cond->getSourceRange(); + << CondTy << Cond->getSourceRange(); return true; } /// Handle when one or both operands are void type. static QualType checkConditionalVoidType(Sema &S, ExprResult &LHS, ExprResult &RHS) { - Expr *LHSExpr = LHS.get(); - Expr *RHSExpr = RHS.get(); + Expr *LHSExpr = LHS.get(); + Expr *RHSExpr = RHS.get(); - if (!LHSExpr->getType()->isVoidType()) - S.Diag(RHSExpr->getBeginLoc(), diag::ext_typecheck_cond_one_void) - << RHSExpr->getSourceRange(); - if (!RHSExpr->getType()->isVoidType()) - S.Diag(LHSExpr->getBeginLoc(), diag::ext_typecheck_cond_one_void) - << LHSExpr->getSourceRange(); - LHS = S.ImpCastExprToType(LHS.get(), S.Context.VoidTy, CK_ToVoid); - RHS = S.ImpCastExprToType(RHS.get(), S.Context.VoidTy, CK_ToVoid); - return S.Context.VoidTy; + if (!LHSExpr->getType()->isVoidType()) + S.Diag(RHSExpr->getBeginLoc(), diag::ext_typecheck_cond_one_void) + << RHSExpr->getSourceRange(); + if (!RHSExpr->getType()->isVoidType()) + S.Diag(LHSExpr->getBeginLoc(), diag::ext_typecheck_cond_one_void) + << LHSExpr->getSourceRange(); + LHS = S.ImpCastExprToType(LHS.get(), S.Context.VoidTy, CK_ToVoid); + RHS = S.ImpCastExprToType(RHS.get(), S.Context.VoidTy, CK_ToVoid); + return S.Context.VoidTy; } /// Return false if the NullExpr can be promoted to PointerTy, @@ -6418,7 +6423,7 @@ QualType PointerTy) { if ((!PointerTy->isAnyPointerType() && !PointerTy->isBlockPointerType()) || !NullExpr.get()->isNullPointerConstant(S.Context, - Expr::NPC_ValueDependentIsNull)) + Expr::NPC_ValueDependentIsNull)) return true; NullExpr = S.ImpCastExprToType(NullExpr.get(), PointerTy, CK_NullToPointer); @@ -6480,7 +6485,8 @@ return QualType(); } - unsigned MergedCVRQual = lhQual.getCVRQualifiers() | rhQual.getCVRQualifiers(); + unsigned MergedCVRQual = + lhQual.getCVRQualifiers() | rhQual.getCVRQualifiers(); auto LHSCastKind = CK_BitCast, RHSCastKind = CK_BitCast; lhQual.removeCVRQualifiers(); rhQual.removeCVRQualifiers(); @@ -6571,8 +6577,8 @@ return destType; } S.Diag(Loc, diag::err_typecheck_cond_incompatible_operands) - << LHSTy << RHSTy << LHS.get()->getSourceRange() - << RHS.get()->getSourceRange(); + << LHSTy << RHSTy << LHS.get()->getSourceRange() + << RHS.get()->getSourceRange(); return QualType(); } @@ -6581,10 +6587,8 @@ } /// Return the resulting type when the operands are both pointers. -static QualType -checkConditionalObjectPointersCompatibility(Sema &S, ExprResult &LHS, - ExprResult &RHS, - SourceLocation Loc) { +static QualType checkConditionalObjectPointersCompatibility( + Sema &S, ExprResult &LHS, ExprResult &RHS, SourceLocation Loc) { // get the pointer types QualType LHSTy = LHS.get()->getType(); QualType RHSTy = RHS.get()->getType(); @@ -6596,8 +6600,8 @@ // ignore qualifiers on void (C99 6.5.15p3, clause 6) if (lhptee->isVoidType() && rhptee->isIncompleteOrObjectType()) { // Figure out necessary qualifiers (C99 6.5.15p6) - QualType destPointee - = S.Context.getQualifiedType(lhptee, rhptee.getQualifiers()); + QualType destPointee = + S.Context.getQualifiedType(lhptee, rhptee.getQualifiers()); QualType destType = S.Context.getPointerType(destPointee); // Add qualifiers if necessary. LHS = S.ImpCastExprToType(LHS.get(), destType, CK_NoOp); @@ -6606,8 +6610,8 @@ return destType; } if (rhptee->isVoidType() && lhptee->isIncompleteOrObjectType()) { - QualType destPointee - = S.Context.getQualifiedType(rhptee, lhptee.getQualifiers()); + QualType destPointee = + S.Context.getQualifiedType(rhptee, lhptee.getQualifiers()); QualType destType = S.Context.getPointerType(destPointee); // Add qualifiers if necessary. RHS = S.ImpCastExprToType(RHS.get(), destType, CK_NoOp); @@ -6622,7 +6626,7 @@ /// Return false if the first expression is not an integer and the second /// expression is not a pointer, true otherwise. static bool checkPointerIntegerMismatch(Sema &S, ExprResult &Int, - Expr* PointerExpr, SourceLocation Loc, + Expr *PointerExpr, SourceLocation Loc, bool IsIntFirstExpr) { if (!PointerExpr->getType()->isPointerType() || !Int.get()->getType()->isIntegerType()) @@ -6632,8 +6636,8 @@ Expr *Expr2 = IsIntFirstExpr ? PointerExpr : Int.get(); S.Diag(Loc, diag::ext_typecheck_cond_pointer_integer_mismatch) - << Expr1->getType() << Expr2->getType() - << Expr1->getSourceRange() << Expr2->getSourceRange(); + << Expr1->getType() << Expr2->getType() << Expr1->getSourceRange() + << Expr2->getSourceRange(); Int = S.ImpCastExprToType(Int.get(), PointerExpr->getType(), CK_IntegralToPointer); return true; @@ -6664,19 +6668,19 @@ // For conversion purposes, we ignore any qualifiers. // For example, "const float" and "float" are equivalent. QualType LHSType = - S.Context.getCanonicalType(LHS.get()->getType()).getUnqualifiedType(); + S.Context.getCanonicalType(LHS.get()->getType()).getUnqualifiedType(); QualType RHSType = - S.Context.getCanonicalType(RHS.get()->getType()).getUnqualifiedType(); + S.Context.getCanonicalType(RHS.get()->getType()).getUnqualifiedType(); if (!LHSType->isIntegerType() && !LHSType->isRealFloatingType()) { S.Diag(QuestionLoc, diag::err_typecheck_cond_expect_int_float) - << LHSType << LHS.get()->getSourceRange(); + << LHSType << LHS.get()->getSourceRange(); return QualType(); } if (!RHSType->isIntegerType() && !RHSType->isRealFloatingType()) { S.Diag(QuestionLoc, diag::err_typecheck_cond_expect_int_float) - << RHSType << RHS.get()->getSourceRange(); + << RHSType << RHS.get()->getSourceRange(); return QualType(); } @@ -6690,8 +6694,8 @@ /*IsCompAssign = */ false); // Finally, we have two differing integer types. - return handleIntegerConversion - (S, LHS, RHS, LHSType, RHSType, /*IsCompAssign = */ false); + return handleIntegerConversion( + S, LHS, RHS, LHSType, RHSType, /*IsCompAssign = */ false); } /// Convert scalar operands to a vector that matches the @@ -6705,11 +6709,12 @@ /// into a vector of that type where the length matches the condition /// vector type. s6.11.6 requires that the element types of the result /// and the condition must have the same number of bits. -static QualType -OpenCLConvertScalarsToVectors(Sema &S, ExprResult &LHS, ExprResult &RHS, - QualType CondTy, SourceLocation QuestionLoc) { +static QualType OpenCLConvertScalarsToVectors(Sema &S, ExprResult &LHS, + ExprResult &RHS, QualType CondTy, + SourceLocation QuestionLoc) { QualType ResTy = OpenCLArithmeticConversions(S, LHS, RHS, QuestionLoc); - if (ResTy.isNull()) return QualType(); + if (ResTy.isNull()) + return QualType(); const VectorType *CV = CondTy->getAs(); assert(CV); @@ -6719,8 +6724,8 @@ QualType VectorTy = S.Context.getExtVectorType(ResTy, NumElements); // Ensure that all types have the same number of bits - if (S.Context.getTypeSize(CV->getElementType()) - != S.Context.getTypeSize(ResTy)) { + if (S.Context.getTypeSize(CV->getElementType()) != + S.Context.getTypeSize(ResTy)) { // Since VectorTy is created internally, it does not pretty print // with an OpenCL name. Instead, we just print a description. std::string EleTyName = ResTy.getUnqualifiedType().getAsString(); @@ -6728,7 +6733,7 @@ llvm::raw_svector_ostream OS(Str); OS << "(vector of " << NumElements << " '" << EleTyName << "' values)"; S.Diag(QuestionLoc, diag::err_conditional_vector_element_size) - << CondTy << OS.str(); + << CondTy << OS.str(); return QualType(); } @@ -6747,10 +6752,11 @@ const VectorType *CondTy = Cond->getType()->getAs(); assert(CondTy); QualType EleTy = CondTy->getElementType(); - if (EleTy->isIntegerType()) return false; + if (EleTy->isIntegerType()) + return false; S.Diag(QuestionLoc, diag::err_typecheck_cond_expect_nonfloat) - << Cond->getType() << Cond->getSourceRange(); + << Cond->getType() << Cond->getSourceRange(); return true; } @@ -6768,7 +6774,7 @@ if (CV->getNumElements() != RV->getNumElements()) { S.Diag(QuestionLoc, diag::err_conditional_vector_size) - << CondTy << VecResTy; + << CondTy << VecResTy; return true; } @@ -6777,7 +6783,7 @@ if (S.Context.getTypeSize(CVE) != S.Context.getTypeSize(RVE)) { S.Diag(QuestionLoc, diag::err_conditional_vector_element_size) - << CondTy << VecResTy; + << CondTy << VecResTy; return true; } @@ -6787,10 +6793,9 @@ /// Return the resulting type for the conditional operator in /// OpenCL (aka "ternary selection operator", OpenCL v1.1 /// s6.3.i) when the condition is a vector type. -static QualType -OpenCLCheckVectorConditional(Sema &S, ExprResult &Cond, - ExprResult &LHS, ExprResult &RHS, - SourceLocation QuestionLoc) { +static QualType OpenCLCheckVectorConditional(Sema &S, ExprResult &Cond, + ExprResult &LHS, ExprResult &RHS, + SourceLocation QuestionLoc) { Cond = S.DefaultFunctionArrayLvalueConversion(Cond.get()); if (Cond.isInvalid()) return QualType(); @@ -6804,10 +6809,11 @@ if (LHS.get()->getType()->isVectorType() || RHS.get()->getType()->isVectorType()) { QualType VecResTy = S.CheckVectorOperands(LHS, RHS, QuestionLoc, - /*isCompAssign*/false, - /*AllowBothBool*/true, - /*AllowBoolConversions*/false); - if (VecResTy.isNull()) return QualType(); + /*isCompAssign*/ false, + /*AllowBothBool*/ true, + /*AllowBoolConversions*/ false); + if (VecResTy.isNull()) + return QualType(); // The result type must match the condition type as specified in // OpenCL v1.1 s6.11.6. if (checkVectorResult(S, CondTy, VecResTy, QuestionLoc)) @@ -6840,11 +6846,13 @@ SourceLocation QuestionLoc) { ExprResult LHSResult = CheckPlaceholderExpr(LHS.get()); - if (!LHSResult.isUsable()) return QualType(); + if (!LHSResult.isUsable()) + return QualType(); LHS = LHSResult; ExprResult RHSResult = CheckPlaceholderExpr(RHS.get()); - if (!RHSResult.isUsable()) return QualType(); + if (!RHSResult.isUsable()) + return QualType(); RHS = RHSResult; // C++ is sufficiently different to merit its own checker. @@ -6869,9 +6877,9 @@ // Now check the two expressions. if (LHS.get()->getType()->isVectorType() || RHS.get()->getType()->isVectorType()) - return CheckVectorOperands(LHS, RHS, QuestionLoc, /*isCompAssign*/false, - /*AllowBothBool*/true, - /*AllowBoolConversions*/false); + return CheckVectorOperands(LHS, RHS, QuestionLoc, /*isCompAssign*/ false, + /*AllowBothBool*/ true, + /*AllowBoolConversions*/ false); QualType ResTy = UsualArithmeticConversions(LHS, RHS); if (LHS.isInvalid() || RHS.isInvalid()) @@ -6883,9 +6891,9 @@ // Diagnose attempts to convert between __float128 and long double where // such conversions currently can't be handled. if (unsupportedTypeConversion(*this, LHSTy, RHSTy)) { - Diag(QuestionLoc, - diag::err_typecheck_cond_incompatible_operands) << LHSTy << RHSTy - << LHS.get()->getSourceRange() << RHS.get()->getSourceRange(); + Diag(QuestionLoc, diag::err_typecheck_cond_incompatible_operands) + << LHSTy << RHSTy << LHS.get()->getSourceRange() + << RHS.get()->getSourceRange(); return QualType(); } @@ -6907,7 +6915,7 @@ // If both operands are the same structure or union type, the result is that // type. - if (const RecordType *LHSRT = LHSTy->getAs()) { // C99 6.5.15p3 + if (const RecordType *LHSRT = LHSTy->getAs()) { // C99 6.5.15p3 if (const RecordType *RHSRT = RHSTy->getAs()) if (LHSRT->getDecl() == RHSRT->getDecl()) // "If both the operands have structure or union type, the result has @@ -6924,18 +6932,18 @@ // C99 6.5.15p6 - "if one operand is a null pointer constant, the result has // the type of the other operand." - if (!checkConditionalNullPointer(*this, RHS, LHSTy)) return LHSTy; - if (!checkConditionalNullPointer(*this, LHS, RHSTy)) return RHSTy; + if (!checkConditionalNullPointer(*this, RHS, LHSTy)) + return LHSTy; + if (!checkConditionalNullPointer(*this, LHS, RHSTy)) + return RHSTy; // All objective-c pointer type analysis is done here. - QualType compositeType = FindCompositeObjCPointerType(LHS, RHS, - QuestionLoc); + QualType compositeType = FindCompositeObjCPointerType(LHS, RHS, QuestionLoc); if (LHS.isInvalid() || RHS.isInvalid()) return QualType(); if (!compositeType.isNull()) return compositeType; - // Handle block pointer types. if (LHSTy->isBlockPointerType() || RHSTy->isBlockPointerType()) return checkConditionalBlockPointerCompatibility(*this, LHS, RHS, @@ -6949,10 +6957,10 @@ // GCC compatibility: soften pointer/integer mismatch. Note that // null pointers have been filtered out by this point. if (checkPointerIntegerMismatch(*this, LHS, RHS.get(), QuestionLoc, - /*isIntFirstExpr=*/true)) + /*isIntFirstExpr=*/true)) return RHSTy; if (checkPointerIntegerMismatch(*this, RHS, LHS.get(), QuestionLoc, - /*isIntFirstExpr=*/false)) + /*isIntFirstExpr=*/false)) return LHSTy; // Emit a better diagnostic if one of the expressions is a null pointer @@ -6963,8 +6971,8 @@ // Otherwise, the operands are not compatible. Diag(QuestionLoc, diag::err_typecheck_cond_incompatible_operands) - << LHSTy << RHSTy << LHS.get()->getSourceRange() - << RHS.get()->getSourceRange(); + << LHSTy << RHSTy << LHS.get()->getSourceRange() + << RHS.get()->getSourceRange(); return QualType(); } @@ -7017,8 +7025,10 @@ // Two identical object pointer types are always compatible. return LHSTy; } - const ObjCObjectPointerType *LHSOPT = LHSTy->castAs(); - const ObjCObjectPointerType *RHSOPT = RHSTy->castAs(); + const ObjCObjectPointerType *LHSOPT = + LHSTy->castAs(); + const ObjCObjectPointerType *RHSOPT = + RHSTy->castAs(); QualType compositeType = LHSTy; // If both operands are interfaces and either operand can be @@ -7034,8 +7044,8 @@ // FIXME: Consider unifying with 'areComparableObjCPointerTypes'. // It could return the composite type. - if (!(compositeType = - Context.areCommonBaseCompatible(LHSOPT, RHSOPT)).isNull()) { + if (!(compositeType = Context.areCommonBaseCompatible(LHSOPT, RHSOPT)) + .isNull()) { // Nothing more to do. } else if (Context.canAssignObjCInterfaces(LHSOPT, RHSOPT)) { compositeType = RHSOPT->isObjCBuiltinType() ? RHSTy : LHSTy; @@ -7053,8 +7063,8 @@ compositeType = Context.getObjCIdType(); } else { Diag(QuestionLoc, diag::ext_typecheck_cond_incompatible_operands) - << LHSTy << RHSTy - << LHS.get()->getSourceRange() << RHS.get()->getSourceRange(); + << LHSTy << RHSTy << LHS.get()->getSourceRange() + << RHS.get()->getSourceRange(); QualType incompatTy = Context.getObjCIdType(); LHS = ImpCastExprToType(LHS.get(), incompatTy, CK_BitCast); RHS = ImpCastExprToType(RHS.get(), incompatTy, CK_BitCast); @@ -7070,15 +7080,16 @@ if (getLangOpts().ObjCAutoRefCount) { // ARC forbids the implicit conversion of object pointers to 'void *', // so these types are not compatible. - Diag(QuestionLoc, diag::err_cond_voidptr_arc) << LHSTy << RHSTy - << LHS.get()->getSourceRange() << RHS.get()->getSourceRange(); + Diag(QuestionLoc, diag::err_cond_voidptr_arc) + << LHSTy << RHSTy << LHS.get()->getSourceRange() + << RHS.get()->getSourceRange(); LHS = RHS = true; return QualType(); } QualType lhptee = LHSTy->getAs()->getPointeeType(); QualType rhptee = RHSTy->getAs()->getPointeeType(); - QualType destPointee - = Context.getQualifiedType(lhptee, rhptee.getQualifiers()); + QualType destPointee = + Context.getQualifiedType(lhptee, rhptee.getQualifiers()); QualType destType = Context.getPointerType(destPointee); // Add qualifiers if necessary. LHS = ImpCastExprToType(LHS.get(), destType, CK_NoOp); @@ -7090,15 +7101,16 @@ if (getLangOpts().ObjCAutoRefCount) { // ARC forbids the implicit conversion of object pointers to 'void *', // so these types are not compatible. - Diag(QuestionLoc, diag::err_cond_voidptr_arc) << LHSTy << RHSTy - << LHS.get()->getSourceRange() << RHS.get()->getSourceRange(); + Diag(QuestionLoc, diag::err_cond_voidptr_arc) + << LHSTy << RHSTy << LHS.get()->getSourceRange() + << RHS.get()->getSourceRange(); LHS = RHS = true; return QualType(); } QualType lhptee = LHSTy->getAs()->getPointeeType(); QualType rhptee = RHSTy->getAs()->getPointeeType(); - QualType destPointee - = Context.getQualifiedType(rhptee, lhptee.getQualifiers()); + QualType destPointee = + Context.getQualifiedType(rhptee, lhptee.getQualifiers()); QualType destType = Context.getPointerType(destPointee); // Add qualifiers if necessary. RHS = ImpCastExprToType(RHS.get(), destType, CK_NoOp); @@ -7117,9 +7129,9 @@ SourceLocation EndLoc = Self.getLocForEndOfToken(ParenRange.getEnd()); if (ParenRange.getBegin().isFileID() && ParenRange.getEnd().isFileID() && EndLoc.isValid()) { - Self.Diag(Loc, Note) - << FixItHint::CreateInsertion(ParenRange.getBegin(), "(") - << FixItHint::CreateInsertion(EndLoc, ")"); + Self.Diag(Loc, Note) << FixItHint::CreateInsertion(ParenRange.getBegin(), + "(") + << FixItHint::CreateInsertion(EndLoc, ")"); } else { // We can't display the parentheses, so just show the bare note. Self.Diag(Loc, Note) << ParenRange; @@ -7164,8 +7176,8 @@ // Make sure this is really a binary operator that is safe to pass into // BinaryOperator::getOverloadedOpcode(), e.g. it's not a subscript op. OverloadedOperatorKind OO = Call->getOperator(); - if (OO < OO_Plus || OO > OO_Arrow || - OO == OO_PlusPlus || OO == OO_MinusMinus) + if (OO < OO_Plus || OO > OO_Arrow || OO == OO_PlusPlus || + OO == OO_MinusMinus) return false; BinaryOperatorKind OpKind = BinaryOperator::getOverloadedOpcode(OO); @@ -7203,10 +7215,8 @@ /// and binary operator are mixed in a way that suggests the programmer assumed /// the conditional operator has higher precedence, for example: /// "int x = a + someBinaryCondition ? 1 : 2". -static void DiagnoseConditionalPrecedence(Sema &Self, - SourceLocation OpLoc, - Expr *Condition, - Expr *LHSExpr, +static void DiagnoseConditionalPrecedence(Sema &Self, SourceLocation OpLoc, + Expr *Condition, Expr *LHSExpr, Expr *RHSExpr) { BinaryOperatorKind CondOpcode; Expr *CondRHS; @@ -7257,7 +7267,7 @@ MergedKind = NullabilityKind::NonNull; else MergedKind = RHSKind; - // Compute nullability of a normal conditional expression. + // Compute nullability of a normal conditional expression. } else { if (LHSKind == NullabilityKind::Nullable || RHSKind == NullabilityKind::Nullable) @@ -7286,9 +7296,8 @@ /// ActOnConditionalOp - Parse a ?: operation. Note that 'LHS' may be null /// in the case of a the GNU conditional expr extension. ExprResult Sema::ActOnConditionalOp(SourceLocation QuestionLoc, - SourceLocation ColonLoc, - Expr *CondExpr, Expr *LHSExpr, - Expr *RHSExpr) { + SourceLocation ColonLoc, Expr *CondExpr, + Expr *LHSExpr, Expr *RHSExpr) { if (!getLangOpts().CPlusPlus) { // C cannot handle TypoExpr nodes in the condition because it // doesn't handle dependent types properly, so make sure any TypoExprs have @@ -7324,18 +7333,17 @@ // as Objective-C++'s dictionary subscripting syntax. if (commonExpr->hasPlaceholderType()) { ExprResult result = CheckPlaceholderExpr(commonExpr); - if (!result.isUsable()) return ExprError(); + if (!result.isUsable()) + return ExprError(); commonExpr = result.get(); } // We usually want to apply unary conversions *before* saving, except // in the special case of a C++ l-value conditional. - if (!(getLangOpts().CPlusPlus - && !commonExpr->isTypeDependent() - && commonExpr->getValueKind() == RHSExpr->getValueKind() - && commonExpr->isGLValue() - && commonExpr->isOrdinaryOrBitFieldObject() - && RHSExpr->isOrdinaryOrBitFieldObject() - && Context.hasSameType(commonExpr->getType(), RHSExpr->getType()))) { + if (!(getLangOpts().CPlusPlus && !commonExpr->isTypeDependent() && + commonExpr->getValueKind() == RHSExpr->getValueKind() && + commonExpr->isGLValue() && commonExpr->isOrdinaryOrBitFieldObject() && + RHSExpr->isOrdinaryOrBitFieldObject() && + Context.hasSameType(commonExpr->getType(), RHSExpr->getType()))) { ExprResult commonRes = UsualUnaryConversions(commonExpr); if (commonRes.isInvalid()) return ExprError(); @@ -7352,11 +7360,9 @@ commonExpr = MatExpr.get(); } - opaqueValue = new (Context) OpaqueValueExpr(commonExpr->getExprLoc(), - commonExpr->getType(), - commonExpr->getValueKind(), - commonExpr->getObjectKind(), - commonExpr); + opaqueValue = new (Context) OpaqueValueExpr( + commonExpr->getExprLoc(), commonExpr->getType(), + commonExpr->getValueKind(), commonExpr->getObjectKind(), commonExpr); LHSExpr = CondExpr = opaqueValue; } @@ -7364,10 +7370,9 @@ ExprValueKind VK = VK_RValue; ExprObjectKind OK = OK_Ordinary; ExprResult Cond = CondExpr, LHS = LHSExpr, RHS = RHSExpr; - QualType result = CheckConditionalOperands(Cond, LHS, RHS, - VK, OK, QuestionLoc); - if (result.isNull() || Cond.isInvalid() || LHS.isInvalid() || - RHS.isInvalid()) + QualType result = + CheckConditionalOperands(Cond, LHS, RHS, VK, OK, QuestionLoc); + if (result.isNull() || Cond.isInvalid() || LHS.isInvalid() || RHS.isInvalid()) return ExprError(); DiagnoseConditionalPrecedence(*this, QuestionLoc, Cond.get(), LHS.get(), @@ -7375,8 +7380,8 @@ CheckBoolLikeConversion(Cond.get(), QuestionLoc); - result = computeConditionalNullability(result, commonExpr, LHSTy, RHSTy, - Context); + result = + computeConditionalNullability(result, commonExpr, LHSTy, RHSTy, Context); if (!commonExpr) return new (Context) @@ -7427,10 +7432,9 @@ // It's okay to add or remove GC or lifetime qualifiers when converting to // and from void*. - else if (lhq.withoutObjCGCAttr().withoutObjCLifetime() - .compatiblyIncludes( - rhq.withoutObjCGCAttr().withoutObjCLifetime()) - && (lhptee->isVoidType() || rhptee->isVoidType())) + else if (lhq.withoutObjCGCAttr().withoutObjCLifetime().compatiblyIncludes( + rhq.withoutObjCGCAttr().withoutObjCLifetime()) && + (lhptee->isVoidType() || rhptee->isVoidType())) ; // keep old // Treat lifetime mismatches as fatal. @@ -7439,7 +7443,8 @@ // For GCC/MS compatibility, other qualifier mismatches are treated // as still compatible in C. - else ConvTy = Sema::CompatiblePointerDiscardsQualifiers; + else + ConvTy = Sema::CompatiblePointerDiscardsQualifiers; } // C99 6.5.16.1p1 (constraint 4): If one operand is a pointer to an object or @@ -7602,9 +7607,9 @@ return Sema::IncompatiblePointer; } -Sema::AssignConvertType -Sema::CheckAssignmentConstraints(SourceLocation Loc, - QualType LHSType, QualType RHSType) { +Sema::AssignConvertType Sema::CheckAssignmentConstraints(SourceLocation Loc, + QualType LHSType, + QualType RHSType) { // Fake up an opaque expression. We don't actually care about what // cast operations are required, so if CheckAssignmentConstraints // adds casts to this they'll be wasted, but fortunately that doesn't @@ -7641,9 +7646,10 @@ /// C99 spec dictates. /// /// Sets 'Kind' for any result kind except Incompatible. -Sema::AssignConvertType -Sema::CheckAssignmentConstraints(QualType LHSType, ExprResult &RHS, - CastKind &Kind, bool ConvertRHS) { +Sema::AssignConvertType Sema::CheckAssignmentConstraints(QualType LHSType, + ExprResult &RHS, + CastKind &Kind, + bool ConvertRHS) { QualType RHSType = RHS.get()->getType(); QualType OrigLHSType = LHSType; @@ -7662,7 +7668,7 @@ // atomic qualification step. if (const AtomicType *AtomicTy = dyn_cast(LHSType)) { Sema::AssignConvertType result = - CheckAssignmentConstraints(AtomicTy->getValueType(), RHS, Kind); + CheckAssignmentConstraints(AtomicTy->getValueType(), RHS, Kind); if (result != Compatible) return result; if (Kind != CK_NoOp && ConvertRHS) @@ -7851,7 +7857,7 @@ if (RHSType->isObjCObjectPointerType()) { Kind = CK_BitCast; Sema::AssignConvertType result = - checkObjCPointerTypesForAssignment(*this, LHSType, RHSType); + checkObjCPointerTypesForAssignment(*this, LHSType, RHSType); if (getLangOpts().allowsNonTrivialObjCLifetimeQualifiers() && result == Compatible && !CheckObjCARCUnavailableWeakConversion(OrigLHSType, RHSType)) @@ -7955,8 +7961,8 @@ // Build an initializer list that designates the appropriate member // of the transparent union. Expr *E = EResult.get(); - InitListExpr *Initializer = new (C) InitListExpr(C, SourceLocation(), - E, SourceLocation()); + InitListExpr *Initializer = + new (C) InitListExpr(C, SourceLocation(), E, SourceLocation()); Initializer->setType(UnionType); Initializer->setInitializedFieldInUnion(Field); @@ -7996,16 +8002,14 @@ if (RHS.get()->isNullPointerConstant(Context, Expr::NPC_ValueDependentIsNull)) { - RHS = ImpCastExprToType(RHS.get(), it->getType(), - CK_NullToPointer); + RHS = ImpCastExprToType(RHS.get(), it->getType(), CK_NullToPointer); InitField = it; break; } } CastKind Kind; - if (CheckAssignmentConstraints(it->getType(), RHS, Kind) - == Compatible) { + if (CheckAssignmentConstraints(it->getType(), RHS, Kind) == Compatible) { RHS = ImpCastExprToType(RHS.get(), it->getType(), Kind); InitField = it; break; @@ -8021,8 +8025,7 @@ Sema::AssignConvertType Sema::CheckSingleAssignmentConstraints(QualType LHSType, ExprResult &CallerRHS, - bool Diagnose, - bool DiagnoseCFAudited, + bool Diagnose, bool DiagnoseCFAudited, bool ConvertRHS) { // We need to be able to tell the caller whether we diagnosed a problem, if // they ask us to issue diagnostics. @@ -8098,8 +8101,9 @@ } // OpenCL queue_t type assignment. - if (LHSType->isQueueT() && RHS.get()->isNullPointerConstant( - Context, Expr::NPC_ValueDependentIsNull)) { + if (LHSType->isQueueT() && + RHS.get()->isNullPointerConstant(Context, + Expr::NPC_ValueDependentIsNull)) { RHS = ImpCastExprToType(RHS.get(), LHSType, CK_NullToPointer); return Compatible; } @@ -8118,7 +8122,7 @@ } CastKind Kind; Sema::AssignConvertType result = - CheckAssignmentConstraints(LHSType, RHS, Kind, ConvertRHS); + CheckAssignmentConstraints(LHSType, RHS, Kind, ConvertRHS); // C99 6.5.16.1p2: The value of the right operand is converted to the // type of the assignment expression. @@ -8185,20 +8189,20 @@ OriginalOperand OrigLHS(LHS.get()), OrigRHS(RHS.get()); Diag(Loc, diag::err_typecheck_invalid_operands) - << OrigLHS.getType() << OrigRHS.getType() - << LHS.get()->getSourceRange() << RHS.get()->getSourceRange(); + << OrigLHS.getType() << OrigRHS.getType() << LHS.get()->getSourceRange() + << RHS.get()->getSourceRange(); // If a user-defined conversion was applied to either of the operands prior // to applying the built-in operator rules, tell the user about it. if (OrigLHS.Conversion) { Diag(OrigLHS.Conversion->getLocation(), diag::note_typecheck_invalid_operands_converted) - << 0 << LHS.get()->getType(); + << 0 << LHS.get()->getType(); } if (OrigRHS.Conversion) { Diag(OrigRHS.Conversion->getLocation(), diag::note_typecheck_invalid_operands_converted) - << 1 << RHS.get()->getType(); + << 1 << RHS.get()->getType(); } return QualType(); @@ -8244,18 +8248,17 @@ /// \param scalar - if non-null, actually perform the conversions /// \return true if the operation fails (but without diagnosing the failure) static bool tryVectorConvertAndSplat(Sema &S, ExprResult *scalar, - QualType scalarTy, - QualType vectorEltTy, - QualType vectorTy, - unsigned &DiagID) { + QualType scalarTy, QualType vectorEltTy, + QualType vectorTy, unsigned &DiagID) { // The conversion to apply to the scalar before splatting it, // if necessary. CastKind scalarCast = CK_NoOp; if (vectorEltTy->isIntegralType(S.Context)) { - if (S.getLangOpts().OpenCL && (scalarTy->isRealFloatingType() || - (scalarTy->isIntegerType() && - S.Context.getIntegerTypeOrder(vectorEltTy, scalarTy) < 0))) { + if (S.getLangOpts().OpenCL && + (scalarTy->isRealFloatingType() || + (scalarTy->isIntegerType() && + S.Context.getIntegerTypeOrder(vectorEltTy, scalarTy) < 0))) { DiagID = diag::err_opencl_scalar_type_rank_greater_than_vector_type; return true; } @@ -8270,8 +8273,7 @@ return true; } scalarCast = CK_FloatingCast; - } - else if (scalarTy->isIntegralType(S.Context)) + } else if (scalarTy->isIntegralType(S.Context)) scalarCast = CK_IntegralToFloating; else return true; @@ -8293,9 +8295,8 @@ static ExprResult convertVector(Expr *E, QualType ElementType, Sema &S) { const auto *VecTy = E->getType()->getAs(); assert(VecTy && "Expression E must be a vector"); - QualType NewVecTy = S.Context.getVectorType(ElementType, - VecTy->getNumElements(), - VecTy->getVectorKind()); + QualType NewVecTy = S.Context.getVectorType( + ElementType, VecTy->getNumElements(), VecTy->getVectorKind()); // Look through the implicit cast. Return the subexpression if its type is // NewVecTy. @@ -8487,9 +8488,9 @@ // AltiVec-style "vector bool op vector bool" combinations are allowed // for some operators but not others. - if (!AllowBothBool && - LHSVecType && LHSVecType->getVectorKind() == VectorType::AltiVecBool && - RHSVecType && RHSVecType->getVectorKind() == VectorType::AltiVecBool) + if (!AllowBothBool && LHSVecType && + LHSVecType->getVectorKind() == VectorType::AltiVecBool && RHSVecType && + RHSVecType->getVectorKind() == VectorType::AltiVecBool) return InvalidOperands(Loc, LHS, RHS); // If the vector types are identical, return. @@ -8572,11 +8573,11 @@ if (!IsCompAssign) { *OtherExpr = ImpCastExprToType(OtherExpr->get(), VecType, CK_BitCast); return VecType; - // In a compound assignment, lhs += rhs, 'lhs' is a lvalue src, forbidding - // any implicit cast. Here, the 'rhs' should be implicit casted to 'lhs' - // type. Note that this is already done by non-compound assignments in - // CheckAssignmentConstraints. If it's a scalar type, only bitcast for - // <1 x T> -> T. The result is also a vector type. + // In a compound assignment, lhs += rhs, 'lhs' is a lvalue src, forbidding + // any implicit cast. Here, the 'rhs' should be implicit casted to 'lhs' + // type. Note that this is already done by non-compound assignments in + // CheckAssignmentConstraints. If it's a scalar type, only bitcast for + // <1 x T> -> T. The result is also a vector type. } else if (OtherType->isExtVectorType() || OtherType->isVectorType() || (OtherType->isScalarType() && VT->getNumElements() == 1)) { ExprResult *RHSExpr = &RHS; @@ -8591,8 +8592,8 @@ if ((!RHSVecType && !RHSType->isRealType()) || (!LHSVecType && !LHSType->isRealType())) { Diag(Loc, diag::err_typecheck_vector_not_convertable_non_scalar) - << LHSType << RHSType - << LHS.get()->getSourceRange() << RHS.get()->getSourceRange(); + << LHSType << RHSType << LHS.get()->getSourceRange() + << RHS.get()->getSourceRange(); return QualType(); } @@ -8600,15 +8601,13 @@ // If the operands are of more than one vector type, then an error shall // occur. Implicit conversions between vector types are not permitted, per // section 6.2.1. - if (getLangOpts().OpenCL && - RHSVecType && isa(RHSVecType) && + if (getLangOpts().OpenCL && RHSVecType && isa(RHSVecType) && LHSVecType && isa(LHSVecType)) { - Diag(Loc, diag::err_opencl_implicit_vector_conversion) << LHSType - << RHSType; + Diag(Loc, diag::err_opencl_implicit_vector_conversion) + << LHSType << RHSType; return QualType(); } - // If there is a vector type that is not a ExtVector and a scalar, we reach // this point if scalar could not be converted to the vector's element type // without truncation. @@ -8617,17 +8616,15 @@ QualType Scalar = LHSVecType ? RHSType : LHSType; QualType Vector = LHSVecType ? LHSType : RHSType; unsigned ScalarOrVector = LHSVecType && RHSVecType ? 1 : 0; - Diag(Loc, - diag::err_typecheck_vector_not_convertable_implict_truncation) + Diag(Loc, diag::err_typecheck_vector_not_convertable_implict_truncation) << ScalarOrVector << Scalar << Vector; return QualType(); } // Otherwise, use the generic diagnostic. - Diag(Loc, DiagID) - << LHSType << RHSType - << LHS.get()->getSourceRange() << RHS.get()->getSourceRange(); + Diag(Loc, DiagID) << LHSType << RHSType << LHS.get()->getSourceRange() + << RHS.get()->getSourceRange(); return QualType(); } @@ -8666,11 +8663,44 @@ return; S.Diag(Loc, diag::warn_null_in_comparison_operation) - << LHSNull /* LHS is NULL */ << NonNullType - << LHS.get()->getSourceRange() << RHS.get()->getSourceRange(); + << LHSNull /* LHS is NULL */ << NonNullType << LHS.get()->getSourceRange() + << RHS.get()->getSourceRange(); } -static void DiagnoseBadDivideOrRemainderValues(Sema& S, ExprResult &LHS, +static void DiagnoseDivisionSizeofPointer(Sema &S, Expr *LHS, Expr *RHS, + SourceLocation Loc) { + UnaryExprOrTypeTraitExpr *LUE = + dyn_cast_or_null(LHS); + UnaryExprOrTypeTraitExpr *RUE = + dyn_cast_or_null(RHS); + + if (!LUE || !RUE) + return; + if (LUE->getKind() != UETT_SizeOf || LUE->isArgumentType() || + RUE->getKind() != UETT_SizeOf) + return; + + QualType LHSTy; + QualType RHSTy; + LHS = LUE->getArgumentExpr()->IgnoreParens(); + LHSTy = LHS->getType(); + + if (RUE->isArgumentType()) { + RHSTy = RUE->getArgumentType(); + } else { + RHS = RUE->getArgumentExpr()->IgnoreParens(); + RHSTy = RHS->getType(); + } + + if (!LHSTy->isPointerType() || RHSTy->isPointerType()) + return; + if (LHSTy->getPointeeType() != RHSTy) + return; + + S.Diag(Loc, diag::warn_division_sizeof_ptr) << LHS->getSourceRange(); +} + +static void DiagnoseBadDivideOrRemainderValues(Sema &S, ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, bool IsDiv) { // Check for division/remainder by zero. @@ -8679,7 +8709,7 @@ RHS.get()->EvaluateAsInt(RHSValue, S.Context) && RHSValue == 0) S.DiagRuntimeBehavior(Loc, RHS.get(), S.PDiag(diag::warn_remainder_division_by_zero) - << IsDiv << RHS.get()->getSourceRange()); + << IsDiv << RHS.get()->getSourceRange()); } QualType Sema::CheckMultiplyDivideOperands(ExprResult &LHS, ExprResult &RHS, @@ -8690,23 +8720,24 @@ if (LHS.get()->getType()->isVectorType() || RHS.get()->getType()->isVectorType()) return CheckVectorOperands(LHS, RHS, Loc, IsCompAssign, - /*AllowBothBool*/getLangOpts().AltiVec, - /*AllowBoolConversions*/false); + /*AllowBothBool*/ getLangOpts().AltiVec, + /*AllowBoolConversions*/ false); QualType compType = UsualArithmeticConversions(LHS, RHS, IsCompAssign); if (LHS.isInvalid() || RHS.isInvalid()) return QualType(); - if (compType.isNull() || !compType->isArithmeticType()) return InvalidOperands(Loc, LHS, RHS); - if (IsDiv) + if (IsDiv) { DiagnoseBadDivideOrRemainderValues(*this, LHS, RHS, Loc, IsDiv); + DiagnoseDivisionSizeofPointer(*this, LHS.get(), RHS.get(), Loc); + } return compType; } -QualType Sema::CheckRemainderOperands( - ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, bool IsCompAssign) { +QualType Sema::CheckRemainderOperands(ExprResult &LHS, ExprResult &RHS, + SourceLocation Loc, bool IsCompAssign) { checkArithmeticNull(*this, LHS, RHS, Loc, /*isCompare=*/false); if (LHS.get()->getType()->isVectorType() || @@ -8714,8 +8745,8 @@ if (LHS.get()->getType()->hasIntegerRepresentation() && RHS.get()->getType()->hasIntegerRepresentation()) return CheckVectorOperands(LHS, RHS, Loc, IsCompAssign, - /*AllowBothBool*/getLangOpts().AltiVec, - /*AllowBoolConversions*/false); + /*AllowBothBool*/ getLangOpts().AltiVec, + /*AllowBoolConversions*/ false); return InvalidOperands(Loc, LHS, RHS); } @@ -8732,20 +8763,20 @@ /// Diagnose invalid arithmetic on two void pointers. static void diagnoseArithmeticOnTwoVoidPointers(Sema &S, SourceLocation Loc, Expr *LHSExpr, Expr *RHSExpr) { - S.Diag(Loc, S.getLangOpts().CPlusPlus - ? diag::err_typecheck_pointer_arith_void_type - : diag::ext_gnu_void_ptr) - << 1 /* two pointers */ << LHSExpr->getSourceRange() - << RHSExpr->getSourceRange(); + S.Diag(Loc, + S.getLangOpts().CPlusPlus ? diag::err_typecheck_pointer_arith_void_type + : diag::ext_gnu_void_ptr) + << 1 /* two pointers */ << LHSExpr->getSourceRange() + << RHSExpr->getSourceRange(); } /// Diagnose invalid arithmetic on a void pointer. static void diagnoseArithmeticOnVoidPointer(Sema &S, SourceLocation Loc, Expr *Pointer) { - S.Diag(Loc, S.getLangOpts().CPlusPlus - ? diag::err_typecheck_pointer_arith_void_type - : diag::ext_gnu_void_ptr) - << 0 /* one pointer */ << Pointer->getSourceRange(); + S.Diag(Loc, + S.getLangOpts().CPlusPlus ? diag::err_typecheck_pointer_arith_void_type + : diag::ext_gnu_void_ptr) + << 0 /* one pointer */ << Pointer->getSourceRange(); } /// Diagnose invalid arithmetic on a null pointer. @@ -8756,11 +8787,10 @@ static void diagnoseArithmeticOnNullPointer(Sema &S, SourceLocation Loc, Expr *Pointer, bool IsGNUIdiom) { if (IsGNUIdiom) - S.Diag(Loc, diag::warn_gnu_null_ptr_arith) - << Pointer->getSourceRange(); + S.Diag(Loc, diag::warn_gnu_null_ptr_arith) << Pointer->getSourceRange(); else S.Diag(Loc, diag::warn_pointer_arith_null_ptr) - << S.getLangOpts().CPlusPlus << Pointer->getSourceRange(); + << S.getLangOpts().CPlusPlus << Pointer->getSourceRange(); } /// Diagnose invalid arithmetic on two function pointers. @@ -8768,27 +8798,29 @@ Expr *LHS, Expr *RHS) { assert(LHS->getType()->isAnyPointerType()); assert(RHS->getType()->isAnyPointerType()); - S.Diag(Loc, S.getLangOpts().CPlusPlus - ? diag::err_typecheck_pointer_arith_function_type - : diag::ext_gnu_ptr_func_arith) - << 1 /* two pointers */ << LHS->getType()->getPointeeType() - // We only show the second type if it differs from the first. - << (unsigned)!S.Context.hasSameUnqualifiedType(LHS->getType(), - RHS->getType()) - << RHS->getType()->getPointeeType() - << LHS->getSourceRange() << RHS->getSourceRange(); + S.Diag(Loc, + S.getLangOpts().CPlusPlus + ? diag::err_typecheck_pointer_arith_function_type + : diag::ext_gnu_ptr_func_arith) + << 1 /* two pointers */ << LHS->getType()->getPointeeType() + // We only show the second type if it differs from the first. + << (unsigned)!S.Context.hasSameUnqualifiedType(LHS->getType(), + RHS->getType()) + << RHS->getType()->getPointeeType() << LHS->getSourceRange() + << RHS->getSourceRange(); } /// Diagnose invalid arithmetic on a function pointer. static void diagnoseArithmeticOnFunctionPointer(Sema &S, SourceLocation Loc, Expr *Pointer) { assert(Pointer->getType()->isAnyPointerType()); - S.Diag(Loc, S.getLangOpts().CPlusPlus - ? diag::err_typecheck_pointer_arith_function_type - : diag::ext_gnu_ptr_func_arith) - << 0 /* one pointer */ << Pointer->getType()->getPointeeType() - << 0 /* one pointer, so only one type */ - << Pointer->getSourceRange(); + S.Diag(Loc, + S.getLangOpts().CPlusPlus + ? diag::err_typecheck_pointer_arith_function_type + : diag::ext_gnu_ptr_func_arith) + << 0 /* one pointer */ << Pointer->getType()->getPointeeType() + << 0 /* one pointer, so only one type */ + << Pointer->getSourceRange(); } /// Emit error if Operand is incomplete pointer type @@ -8821,7 +8853,8 @@ if (const AtomicType *ResAtomicType = ResType->getAs()) ResType = ResAtomicType->getValueType(); - if (!ResType->isAnyPointerType()) return true; + if (!ResType->isAnyPointerType()) + return true; QualType PointeeTy = ResType->getPointeeType(); if (PointeeTy->isVoidType()) { @@ -8833,7 +8866,8 @@ return !S.getLangOpts().CPlusPlus; } - if (checkArithmeticIncompletePointerType(S, Loc, Operand)) return false; + if (checkArithmeticIncompletePointerType(S, Loc, Operand)) + return false; return true; } @@ -8851,11 +8885,14 @@ Expr *LHSExpr, Expr *RHSExpr) { bool isLHSPointer = LHSExpr->getType()->isAnyPointerType(); bool isRHSPointer = RHSExpr->getType()->isAnyPointerType(); - if (!isLHSPointer && !isRHSPointer) return true; + if (!isLHSPointer && !isRHSPointer) + return true; QualType LHSPointeeTy, RHSPointeeTy; - if (isLHSPointer) LHSPointeeTy = LHSExpr->getType()->getPointeeType(); - if (isRHSPointer) RHSPointeeTy = RHSExpr->getType()->getPointeeType(); + if (isLHSPointer) + LHSPointeeTy = LHSExpr->getType()->getPointeeType(); + if (isRHSPointer) + RHSPointeeTy = RHSExpr->getType()->getPointeeType(); // if both are pointers check if operation is valid wrt address spaces if (S.getLangOpts().OpenCL && isLHSPointer && isRHSPointer) { @@ -8874,9 +8911,12 @@ bool isLHSVoidPtr = isLHSPointer && LHSPointeeTy->isVoidType(); bool isRHSVoidPtr = isRHSPointer && RHSPointeeTy->isVoidType(); if (isLHSVoidPtr || isRHSVoidPtr) { - if (!isRHSVoidPtr) diagnoseArithmeticOnVoidPointer(S, Loc, LHSExpr); - else if (!isLHSVoidPtr) diagnoseArithmeticOnVoidPointer(S, Loc, RHSExpr); - else diagnoseArithmeticOnTwoVoidPointers(S, Loc, LHSExpr, RHSExpr); + if (!isRHSVoidPtr) + diagnoseArithmeticOnVoidPointer(S, Loc, LHSExpr); + else if (!isLHSVoidPtr) + diagnoseArithmeticOnVoidPointer(S, Loc, RHSExpr); + else + diagnoseArithmeticOnTwoVoidPointers(S, Loc, LHSExpr, RHSExpr); return !S.getLangOpts().CPlusPlus; } @@ -8884,10 +8924,12 @@ bool isLHSFuncPtr = isLHSPointer && LHSPointeeTy->isFunctionType(); bool isRHSFuncPtr = isRHSPointer && RHSPointeeTy->isFunctionType(); if (isLHSFuncPtr || isRHSFuncPtr) { - if (!isRHSFuncPtr) diagnoseArithmeticOnFunctionPointer(S, Loc, LHSExpr); - else if (!isLHSFuncPtr) diagnoseArithmeticOnFunctionPointer(S, Loc, - RHSExpr); - else diagnoseArithmeticOnTwoFunctionPointers(S, Loc, LHSExpr, RHSExpr); + if (!isRHSFuncPtr) + diagnoseArithmeticOnFunctionPointer(S, Loc, LHSExpr); + else if (!isLHSFuncPtr) + diagnoseArithmeticOnFunctionPointer(S, Loc, RHSExpr); + else + diagnoseArithmeticOnTwoFunctionPointers(S, Loc, LHSExpr, RHSExpr); return !S.getLangOpts().CPlusPlus; } @@ -8904,15 +8946,15 @@ /// literal. static void diagnoseStringPlusInt(Sema &Self, SourceLocation OpLoc, Expr *LHSExpr, Expr *RHSExpr) { - StringLiteral* StrExpr = dyn_cast(LHSExpr->IgnoreImpCasts()); - Expr* IndexExpr = RHSExpr; + StringLiteral *StrExpr = dyn_cast(LHSExpr->IgnoreImpCasts()); + Expr *IndexExpr = RHSExpr; if (!StrExpr) { StrExpr = dyn_cast(RHSExpr->IgnoreImpCasts()); IndexExpr = LHSExpr; } - bool IsStringPlusInt = StrExpr && - IndexExpr->getType()->isIntegralOrUnscopedEnumerationType(); + bool IsStringPlusInt = + StrExpr && IndexExpr->getType()->isIntegralOrUnscopedEnumerationType(); if (!IsStringPlusInt || IndexExpr->isValueDependent()) return; @@ -8969,11 +9011,9 @@ SourceRange DiagRange(LHSExpr->getBeginLoc(), RHSExpr->getEndLoc()); const QualType CharType = CharExpr->getType(); - if (!CharType->isAnyCharacterType() && - CharType->isIntegerType() && + if (!CharType->isAnyCharacterType() && CharType->isIntegerType() && llvm::isUIntN(Ctx.getCharWidth(), CharExpr->getValue())) { - Self.Diag(OpLoc, diag::warn_string_plus_char) - << DiagRange << Ctx.CharTy; + Self.Diag(OpLoc, diag::warn_string_plus_char) << DiagRange << Ctx.CharTy; } else { Self.Diag(OpLoc, diag::warn_string_plus_char) << DiagRange << CharExpr->getType(); @@ -8997,23 +9037,24 @@ assert(LHSExpr->getType()->isAnyPointerType()); assert(RHSExpr->getType()->isAnyPointerType()); S.Diag(Loc, diag::err_typecheck_sub_ptr_compatible) - << LHSExpr->getType() << RHSExpr->getType() << LHSExpr->getSourceRange() - << RHSExpr->getSourceRange(); + << LHSExpr->getType() << RHSExpr->getType() << LHSExpr->getSourceRange() + << RHSExpr->getSourceRange(); } // C99 6.5.6 QualType Sema::CheckAdditionOperands(ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, BinaryOperatorKind Opc, - QualType* CompLHSTy) { + QualType *CompLHSTy) { checkArithmeticNull(*this, LHS, RHS, Loc, /*isCompare=*/false); if (LHS.get()->getType()->isVectorType() || RHS.get()->getType()->isVectorType()) { - QualType compType = CheckVectorOperands( - LHS, RHS, Loc, CompLHSTy, - /*AllowBothBool*/getLangOpts().AltiVec, - /*AllowBoolConversions*/getLangOpts().ZVector); - if (CompLHSTy) *CompLHSTy = compType; + QualType compType = + CheckVectorOperands(LHS, RHS, Loc, CompLHSTy, + /*AllowBothBool*/ getLangOpts().AltiVec, + /*AllowBoolConversions*/ getLangOpts().ZVector); + if (CompLHSTy) + *CompLHSTy = compType; return compType; } @@ -9029,7 +9070,8 @@ // handle the common case first (both operands are arithmetic). if (!compType.isNull() && compType->isArithmeticType()) { - if (CompLHSTy) *CompLHSTy = compType; + if (CompLHSTy) + *CompLHSTy = compType; return compType; } @@ -9097,16 +9139,17 @@ // C99 6.5.6 QualType Sema::CheckSubtractionOperands(ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, - QualType* CompLHSTy) { + QualType *CompLHSTy) { checkArithmeticNull(*this, LHS, RHS, Loc, /*isCompare=*/false); if (LHS.get()->getType()->isVectorType() || RHS.get()->getType()->isVectorType()) { - QualType compType = CheckVectorOperands( - LHS, RHS, Loc, CompLHSTy, - /*AllowBothBool*/getLangOpts().AltiVec, - /*AllowBoolConversions*/getLangOpts().ZVector); - if (CompLHSTy) *CompLHSTy = compType; + QualType compType = + CheckVectorOperands(LHS, RHS, Loc, CompLHSTy, + /*AllowBothBool*/ getLangOpts().AltiVec, + /*AllowBoolConversions*/ getLangOpts().ZVector); + if (CompLHSTy) + *CompLHSTy = compType; return compType; } @@ -9118,7 +9161,8 @@ // Handle the common case first (both operands are arithmetic). if (!compType.isNull() && compType->isArithmeticType()) { - if (CompLHSTy) *CompLHSTy = compType; + if (CompLHSTy) + *CompLHSTy = compType; return compType; } @@ -9136,8 +9180,8 @@ // Subtracting from a null pointer should produce a warning. // The last argument to the diagnose call says this doesn't match the // GNU int-to-pointer idiom. - if (LHS.get()->IgnoreParenCasts()->isNullPointerConstant(Context, - Expr::NPC_ValueDependentIsNotNull)) { + if (LHS.get()->IgnoreParenCasts()->isNullPointerConstant( + Context, Expr::NPC_ValueDependentIsNotNull)) { // In C++ adding zero to a null pointer is defined. llvm::APSInt KnownVal; if (!getLangOpts().CPlusPlus || @@ -9151,16 +9195,17 @@ return QualType(); // Check array bounds for pointer arithemtic - CheckArrayAccess(LHS.get(), RHS.get(), /*ArraySubscriptExpr*/nullptr, - /*AllowOnePastEnd*/true, /*IndexNegated*/true); + CheckArrayAccess(LHS.get(), RHS.get(), /*ArraySubscriptExpr*/ nullptr, + /*AllowOnePastEnd*/ true, /*IndexNegated*/ true); - if (CompLHSTy) *CompLHSTy = LHS.get()->getType(); + if (CompLHSTy) + *CompLHSTy = LHS.get()->getType(); return LHS.get()->getType(); } // Handle pointer-pointer subtractions. - if (const PointerType *RHSPTy - = RHS.get()->getType()->getAs()) { + if (const PointerType *RHSPTy = + RHS.get()->getType()->getAs()) { QualType rpointee = RHSPTy->getPointeeType(); if (getLangOpts().CPlusPlus) { @@ -9178,8 +9223,8 @@ } } - if (!checkArithmeticBinOpPointerOperands(*this, Loc, - LHS.get(), RHS.get())) + if (!checkArithmeticBinOpPointerOperands(*this, Loc, LHS.get(), + RHS.get())) return QualType(); // FIXME: Add warnings for nullptr - ptr. @@ -9190,13 +9235,14 @@ if (!rpointee->isVoidType() && !rpointee->isFunctionType()) { CharUnits ElementSize = Context.getTypeSizeInChars(rpointee); if (ElementSize.isZero()) { - Diag(Loc,diag::warn_sub_ptr_zero_size_types) - << rpointee.getUnqualifiedType() - << LHS.get()->getSourceRange() << RHS.get()->getSourceRange(); + Diag(Loc, diag::warn_sub_ptr_zero_size_types) + << rpointee.getUnqualifiedType() << LHS.get()->getSourceRange() + << RHS.get()->getSourceRange(); } } - if (CompLHSTy) *CompLHSTy = LHS.get()->getType(); + if (CompLHSTy) + *CompLHSTy = LHS.get()->getType(); return Context.getPointerDiffType(); } } @@ -9210,10 +9256,11 @@ return false; } -static void DiagnoseBadShiftValues(Sema& S, ExprResult &LHS, ExprResult &RHS, +static void DiagnoseBadShiftValues(Sema &S, ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, BinaryOperatorKind Opc, QualType LHSType) { - // OpenCL 6.3j: shift values are effectively % word size of LHS (more defined), + // OpenCL 6.3j: shift values are effectively % word size of LHS (more + // defined), // so skip remaining warnings as we don't want to modify values within Sema. if (S.getLangOpts().OpenCL) return; @@ -9227,7 +9274,7 @@ if (Right.isNegative()) { S.DiagRuntimeBehavior(Loc, RHS.get(), S.PDiag(diag::warn_shift_negative) - << RHS.get()->getSourceRange()); + << RHS.get()->getSourceRange()); return; } llvm::APInt LeftBits(Right.getBitWidth(), @@ -9235,7 +9282,7 @@ if (Right.uge(LeftBits)) { S.DiagRuntimeBehavior(Loc, RHS.get(), S.PDiag(diag::warn_shift_gt_typewidth) - << RHS.get()->getSourceRange()); + << RHS.get()->getSourceRange()); return; } if (Opc != BO_Shl) @@ -9256,12 +9303,12 @@ if (Left.isNegative() && !S.getLangOpts().isSignedOverflowDefined()) { S.DiagRuntimeBehavior(Loc, LHS.get(), S.PDiag(diag::warn_shift_lhs_negative) - << LHS.get()->getSourceRange()); + << LHS.get()->getSourceRange()); return; } llvm::APInt ResultBits = - static_cast(Right) + Left.getMinSignedBits(); + static_cast(Right) + Left.getMinSignedBits(); if (LeftBits.uge(ResultBits)) return; llvm::APSInt Result = Left.extend(ResultBits.getLimitedValue()); @@ -9278,15 +9325,15 @@ // turned off separately if needed. if (LeftBits == ResultBits - 1) { S.Diag(Loc, diag::warn_shift_result_sets_sign_bit) - << HexResult << LHSType - << LHS.get()->getSourceRange() << RHS.get()->getSourceRange(); + << HexResult << LHSType << LHS.get()->getSourceRange() + << RHS.get()->getSourceRange(); return; } S.Diag(Loc, diag::warn_shift_result_gt_typewidth) - << HexResult.str() << Result.getMinSignedBits() << LHSType - << Left.getBitWidth() << LHS.get()->getSourceRange() - << RHS.get()->getSourceRange(); + << HexResult.str() << Result.getMinSignedBits() << LHSType + << Left.getBitWidth() << LHS.get()->getSourceRange() + << RHS.get()->getSourceRange(); } /// Return the resulting type when a vector is shifted @@ -9297,18 +9344,20 @@ if ((S.LangOpts.OpenCL || S.LangOpts.ZVector) && !LHS.get()->getType()->isVectorType()) { S.Diag(Loc, diag::err_shift_rhs_only_vector) - << RHS.get()->getType() << LHS.get()->getType() - << LHS.get()->getSourceRange() << RHS.get()->getSourceRange(); + << RHS.get()->getType() << LHS.get()->getType() + << LHS.get()->getSourceRange() << RHS.get()->getSourceRange(); return QualType(); } if (!IsCompAssign) { LHS = S.UsualUnaryConversions(LHS.get()); - if (LHS.isInvalid()) return QualType(); + if (LHS.isInvalid()) + return QualType(); } RHS = S.UsualUnaryConversions(RHS.get()); - if (RHS.isInvalid()) return QualType(); + if (RHS.isInvalid()) + return QualType(); QualType LHSType = LHS.get()->getType(); // Note that LHS might be a scalar because the routine calls not only in @@ -9324,13 +9373,13 @@ // The operands need to be integers. if (!LHSEleType->isIntegerType()) { S.Diag(Loc, diag::err_typecheck_expect_int) - << LHS.get()->getType() << LHS.get()->getSourceRange(); + << LHS.get()->getType() << LHS.get()->getSourceRange(); return QualType(); } if (!RHSEleType->isIntegerType()) { S.Diag(Loc, diag::err_typecheck_expect_int) - << RHS.get()->getType() << RHS.get()->getSourceRange(); + << RHS.get()->getType() << RHS.get()->getSourceRange(); return QualType(); } @@ -9339,7 +9388,7 @@ if (IsCompAssign) return RHSType; if (LHSEleType != RHSEleType) { - LHS = S.ImpCastExprToType(LHS.get(),RHSEleType, CK_IntegralCast); + LHS = S.ImpCastExprToType(LHS.get(), RHSEleType, CK_IntegralCast); LHSEleType = RHSEleType; } QualType VecTy = @@ -9352,8 +9401,8 @@ // that the number of elements is the same as LHS... if (RHSVecTy->getNumElements() != LHSVecTy->getNumElements()) { S.Diag(Loc, diag::err_typecheck_vector_lengths_not_equal) - << LHS.get()->getType() << RHS.get()->getType() - << LHS.get()->getSourceRange() << RHS.get()->getSourceRange(); + << LHS.get()->getType() << RHS.get()->getType() + << LHS.get()->getSourceRange() << RHS.get()->getSourceRange(); return QualType(); } if (!S.LangOpts.OpenCL && !S.LangOpts.ZVector) { @@ -9369,7 +9418,7 @@ } else { // ...else expand RHS to match the number of elements in LHS. QualType VecTy = - S.Context.getExtVectorType(RHSEleType, LHSVecTy->getNumElements()); + S.Context.getExtVectorType(RHSEleType, LHSVecTy->getNumElements()); RHS = S.ImpCastExprToType(RHS.get(), VecTy, CK_VectorSplat); } @@ -9409,7 +9458,8 @@ if (LHS.isInvalid()) return QualType(); QualType LHSType = LHS.get()->getType(); - if (IsCompAssign) LHS = OldLHS; + if (IsCompAssign) + LHS = OldLHS; // The RHS is simpler. RHS = UsualUnaryConversions(RHS.get()); @@ -9424,8 +9474,7 @@ // C++0x: Don't allow scoped enums. FIXME: Use something better than // hasIntegerRepresentation() above instead of this. - if (isScopedEnumerationType(LHSType) || - isScopedEnumerationType(RHSType)) { + if (isScopedEnumerationType(LHSType) || isScopedEnumerationType(RHSType)) { return InvalidOperands(Loc, LHS, RHS); } // Sanity-check shift operands @@ -9460,18 +9509,19 @@ return; S.Diag(Loc, diag::warn_comparison_of_mixed_enum_types) - << LHSStrippedType << RHSStrippedType - << LHS->getSourceRange() << RHS->getSourceRange(); + << LHSStrippedType << RHSStrippedType << LHS->getSourceRange() + << RHS->getSourceRange(); } /// Diagnose bad pointer comparisons. static void diagnoseDistinctPointerComparison(Sema &S, SourceLocation Loc, ExprResult &LHS, ExprResult &RHS, bool IsError) { - S.Diag(Loc, IsError ? diag::err_typecheck_comparison_of_distinct_pointers - : diag::ext_typecheck_comparison_of_distinct_pointers) - << LHS.get()->getType() << RHS.get()->getType() - << LHS.get()->getSourceRange() << RHS.get()->getSourceRange(); + S.Diag(Loc, + IsError ? diag::err_typecheck_comparison_of_distinct_pointers + : diag::ext_typecheck_comparison_of_distinct_pointers) + << LHS.get()->getType() << RHS.get()->getType() + << LHS.get()->getSourceRange() << RHS.get()->getSourceRange(); } /// Returns false if the pointers are converted to a composite type, @@ -9496,7 +9546,7 @@ if (T.isNull()) { if ((LHSType->isPointerType() || LHSType->isMemberPointerType()) && (RHSType->isPointerType() || RHSType->isMemberPointerType())) - diagnoseDistinctPointerComparison(S, Loc, LHS, RHS, /*isError*/true); + diagnoseDistinctPointerComparison(S, Loc, LHS, RHS, /*isError*/ true); else S.InvalidOperands(Loc, LHS, RHS); return true; @@ -9511,10 +9561,11 @@ ExprResult &LHS, ExprResult &RHS, bool IsError) { - S.Diag(Loc, IsError ? diag::err_typecheck_comparison_of_fptr_to_void - : diag::ext_typecheck_comparison_of_fptr_to_void) - << LHS.get()->getType() << RHS.get()->getType() - << LHS.get()->getSourceRange() << RHS.get()->getSourceRange(); + S.Diag(Loc, + IsError ? diag::err_typecheck_comparison_of_fptr_to_void + : diag::ext_typecheck_comparison_of_fptr_to_void) + << LHS.get()->getType() << RHS.get()->getType() + << LHS.get()->getSourceRange() << RHS.get()->getSourceRange(); } static bool isObjCObjectLiteral(ExprResult &E) { @@ -9532,7 +9583,7 @@ static bool hasIsEqualMethod(Sema &S, const Expr *LHS, const Expr *RHS) { const ObjCObjectPointerType *Type = - LHS->getType()->getAs(); + LHS->getType()->getAs(); // If this is not actually an Objective-C object, bail out. if (!Type) @@ -9547,8 +9598,7 @@ // Try to find the -isEqual: method. Selector IsEqualSel = S.NSAPIObj->getIsEqualSelector(); - ObjCMethodDecl *Method = S.LookupMethodInObjectType(IsEqualSel, - InterfaceType, + ObjCMethodDecl *Method = S.LookupMethodInObjectType(IsEqualSel, InterfaceType, /*instance=*/true); if (!Method) { if (Type->isObjCIdType()) { @@ -9579,48 +9629,48 @@ Sema::ObjCLiteralKind Sema::CheckLiteralKind(Expr *FromE) { FromE = FromE->IgnoreParenImpCasts(); switch (FromE->getStmtClass()) { + default: + break; + case Stmt::ObjCStringLiteralClass: + // "string literal" + return LK_String; + case Stmt::ObjCArrayLiteralClass: + // "array literal" + return LK_Array; + case Stmt::ObjCDictionaryLiteralClass: + // "dictionary literal" + return LK_Dictionary; + case Stmt::BlockExprClass: + return LK_Block; + case Stmt::ObjCBoxedExprClass: { + Expr *Inner = cast(FromE)->getSubExpr()->IgnoreParens(); + switch (Inner->getStmtClass()) { + case Stmt::IntegerLiteralClass: + case Stmt::FloatingLiteralClass: + case Stmt::CharacterLiteralClass: + case Stmt::ObjCBoolLiteralExprClass: + case Stmt::CXXBoolLiteralExprClass: + // "numeric literal" + return LK_Numeric; + case Stmt::ImplicitCastExprClass: { + CastKind CK = cast(Inner)->getCastKind(); + // Boolean literals can be represented by implicit casts. + if (CK == CK_IntegralToBoolean || CK == CK_IntegralCast) + return LK_Numeric; + break; + } default: break; - case Stmt::ObjCStringLiteralClass: - // "string literal" - return LK_String; - case Stmt::ObjCArrayLiteralClass: - // "array literal" - return LK_Array; - case Stmt::ObjCDictionaryLiteralClass: - // "dictionary literal" - return LK_Dictionary; - case Stmt::BlockExprClass: - return LK_Block; - case Stmt::ObjCBoxedExprClass: { - Expr *Inner = cast(FromE)->getSubExpr()->IgnoreParens(); - switch (Inner->getStmtClass()) { - case Stmt::IntegerLiteralClass: - case Stmt::FloatingLiteralClass: - case Stmt::CharacterLiteralClass: - case Stmt::ObjCBoolLiteralExprClass: - case Stmt::CXXBoolLiteralExprClass: - // "numeric literal" - return LK_Numeric; - case Stmt::ImplicitCastExprClass: { - CastKind CK = cast(Inner)->getCastKind(); - // Boolean literals can be represented by implicit casts. - if (CK == CK_IntegralToBoolean || CK == CK_IntegralCast) - return LK_Numeric; - break; - } - default: - break; - } - return LK_Boxed; } + return LK_Boxed; } + } return LK_None; } static void diagnoseObjCLiteralComparison(Sema &S, SourceLocation Loc, ExprResult &LHS, ExprResult &RHS, - BinaryOperator::Opcode Opc){ + BinaryOperator::Opcode Opc) { Expr *Literal; Expr *Other; if (isObjCObjectLiteral(LHS)) { @@ -9648,22 +9698,22 @@ if (LiteralKind == Sema::LK_String) S.Diag(Loc, diag::warn_objc_string_literal_comparison) - << Literal->getSourceRange(); + << Literal->getSourceRange(); else S.Diag(Loc, diag::warn_objc_literal_comparison) - << LiteralKind << Literal->getSourceRange(); + << LiteralKind << Literal->getSourceRange(); if (BinaryOperator::isEqualityOp(Opc) && hasIsEqualMethod(S, LHS.get(), RHS.get())) { SourceLocation Start = LHS.get()->getBeginLoc(); SourceLocation End = S.getLocForEndOfToken(RHS.get()->getEndLoc()); CharSourceRange OpRange = - CharSourceRange::getCharRange(Loc, S.getLocForEndOfToken(Loc)); + CharSourceRange::getCharRange(Loc, S.getLocForEndOfToken(Loc)); S.Diag(Loc, diag::note_objc_literal_comparison_isequal) - << FixItHint::CreateInsertion(Start, Opc == BO_EQ ? "[" : "![") - << FixItHint::CreateReplacement(OpRange, " isEqual:") - << FixItHint::CreateInsertion(End, "]"); + << FixItHint::CreateInsertion(Start, Opc == BO_EQ ? "[" : "![") + << FixItHint::CreateReplacement(OpRange, " isEqual:") + << FixItHint::CreateInsertion(End, "]"); } } @@ -9673,14 +9723,17 @@ BinaryOperatorKind Opc) { // Check that left hand side is !something. UnaryOperator *UO = dyn_cast(LHS.get()->IgnoreImpCasts()); - if (!UO || UO->getOpcode() != UO_LNot) return; + if (!UO || UO->getOpcode() != UO_LNot) + return; // Only check if the right hand side is non-bool arithmetic type. - if (RHS.get()->isKnownToHaveBooleanValue()) return; + if (RHS.get()->isKnownToHaveBooleanValue()) + return; // Make sure that the something in !something is not bool. Expr *SubExpr = UO->getSubExpr()->IgnoreImpCasts(); - if (SubExpr->isKnownToHaveBooleanValue()) return; + if (SubExpr->isKnownToHaveBooleanValue()) + return; // Emit warning. bool IsBitwiseOp = Opc == BO_And || Opc == BO_Or || Opc == BO_Xor; @@ -9694,8 +9747,7 @@ if (FirstClose.isInvalid()) FirstOpen = SourceLocation(); S.Diag(UO->getOperatorLoc(), diag::note_logical_not_fix) - << IsBitwiseOp - << FixItHint::CreateInsertion(FirstOpen, "(") + << IsBitwiseOp << FixItHint::CreateInsertion(FirstOpen, "(") << FixItHint::CreateInsertion(FirstClose, ")"); // Second note suggests (!x) < y @@ -9760,10 +9812,14 @@ if (DL && DR && declaresSameEntity(DL, DR)) { StringRef Result; switch (Opc) { - case BO_EQ: case BO_LE: case BO_GE: + case BO_EQ: + case BO_LE: + case BO_GE: Result = "true"; break; - case BO_NE: case BO_LT: case BO_GT: + case BO_NE: + case BO_LT: + case BO_GT: Result = "false"; break; case BO_Cmp: @@ -9776,12 +9832,11 @@ S.PDiag(diag::warn_comparison_always) << 0 /*self-comparison*/ << !Result.empty() << Result); - } else if (DL && DR && - DL->getType()->isArrayType() && DR->getType()->isArrayType() && - !DL->isWeak() && !DR->isWeak()) { + } else if (DL && DR && DL->getType()->isArrayType() && + DR->getType()->isArrayType() && !DL->isWeak() && !DR->isWeak()) { // What is it always going to evaluate to? StringRef Result; - switch(Opc) { + switch (Opc) { case BO_EQ: // e.g. array1 == array2 Result = "false"; break; @@ -9814,8 +9869,8 @@ LiteralStringStripped = LHSStripped; } else if ((isa(RHSStripped) || isa(RHSStripped)) && - !LHSStripped->isNullPointerConstant(S.Context, - Expr::NPC_ValueDependentIsNull)) { + !LHSStripped->isNullPointerConstant( + S.Context, Expr::NPC_ValueDependentIsNull)) { LiteralString = RHS; LiteralStringStripped = RHSStripped; } @@ -9882,8 +9937,8 @@ PreNarrowingType, /*IgnoreFloatToIntegralConversion*/ true)) { case NK_Dependent_Narrowing: - // Implicit conversion to a narrower type, but the expression is - // value-dependent so we can't tell whether it's actually narrowing. + // Implicit conversion to a narrower type, but the expression is + // value-dependent so we can't tell whether it's actually narrowing. case NK_Not_Narrowing: return false; @@ -9896,8 +9951,8 @@ return true; case NK_Variable_Narrowing: - // Implicit conversion to a narrower type, and the value is not a constant - // expression. + // Implicit conversion to a narrower type, and the value is not a constant + // expression. case NK_Type_Narrowing: S.Diag(E->getBeginLoc(), diag::err_spaceship_argument_narrowing) << /*Constant*/ 0 << FromType << ToType; @@ -10118,7 +10173,6 @@ return InvalidOperands(Loc, LHS, RHS); }; - if (!IsRelational && LHSIsNull != RHSIsNull) { bool IsEquality = Opc == BO_EQ; if (RHSIsNull) @@ -10165,8 +10219,9 @@ // pointer type. if ((int)LHSType->isPointerType() + (int)RHSType->isPointerType() >= (IsRelational ? 2 : 1) && - (!LangOpts.ObjCAutoRefCount || !(LHSType->isObjCObjectPointerType() || - RHSType->isObjCObjectPointerType()))) { + (!LangOpts.ObjCAutoRefCount || + !(LHSType->isObjCObjectPointerType() || + RHSType->isObjCObjectPointerType()))) { if (convertPointersToCompositeType(*this, Loc, LHS, RHS)) return QualType(); return computeResultTy(); @@ -10176,9 +10231,9 @@ // All of the following pointer-related warnings are GCC extensions, except // when handling null pointer constants. QualType LCanPointeeTy = - LHSType->castAs()->getPointeeType().getCanonicalType(); + LHSType->castAs()->getPointeeType().getCanonicalType(); QualType RCanPointeeTy = - RHSType->castAs()->getPointeeType().getCanonicalType(); + RHSType->castAs()->getPointeeType().getCanonicalType(); // C99 6.5.9p2 and C99 6.5.8p2 if (Context.typesAreCompatible(LCanPointeeTy.getUnqualifiedType(), @@ -10186,25 +10241,28 @@ // Valid unless a relational comparison of function pointers if (IsRelational && LCanPointeeTy->isFunctionType()) { Diag(Loc, diag::ext_typecheck_ordered_comparison_of_function_pointers) - << LHSType << RHSType << LHS.get()->getSourceRange() - << RHS.get()->getSourceRange(); + << LHSType << RHSType << LHS.get()->getSourceRange() + << RHS.get()->getSourceRange(); } } else if (!IsRelational && (LCanPointeeTy->isVoidType() || RCanPointeeTy->isVoidType())) { // Valid unless comparison between non-null pointer and function pointer - if ((LCanPointeeTy->isFunctionType() || RCanPointeeTy->isFunctionType()) - && !LHSIsNull && !RHSIsNull) + if ((LCanPointeeTy->isFunctionType() || + RCanPointeeTy->isFunctionType()) && + !LHSIsNull && !RHSIsNull) diagnoseFunctionPointerToVoidComparison(*this, Loc, LHS, RHS, - /*isError*/false); + /*isError*/ false); } else { // Invalid - diagnoseDistinctPointerComparison(*this, Loc, LHS, RHS, /*isError*/false); + diagnoseDistinctPointerComparison(*this, Loc, LHS, RHS, + /*isError*/ false); } if (LCanPointeeTy != RCanPointeeTy) { // Treat NULL constant as a special case in OpenCL. if (getLangOpts().OpenCL && !LHSIsNull && !RHSIsNull) { const PointerType *LHSPtr = LHSType->getAs(); - if (!LHSPtr->isAddressSpaceOverlapping(*RHSType->getAs())) { + if (!LHSPtr->isAddressSpaceOverlapping( + *RHSType->getAs())) { Diag(Loc, diag::err_typecheck_op_on_nonoverlapping_address_space_pointers) << LHSType << RHSType << 0 /* comparison */ @@ -10213,8 +10271,8 @@ } LangAS AddrSpaceL = LCanPointeeTy.getAddressSpace(); LangAS AddrSpaceR = RCanPointeeTy.getAddressSpace(); - CastKind Kind = AddrSpaceL != AddrSpaceR ? CK_AddressSpaceConversion - : CK_BitCast; + CastKind Kind = + AddrSpaceL != AddrSpaceR ? CK_AddressSpaceConversion : CK_BitCast; if (LHSIsNull && !RHSIsNull) LHS = ImpCastExprToType(LHS.get(), RHSType, Kind); else @@ -10297,34 +10355,36 @@ if (!LHSIsNull && !RHSIsNull && !Context.typesAreCompatible(lpointee, rpointee)) { Diag(Loc, diag::err_typecheck_comparison_of_distinct_blocks) - << LHSType << RHSType << LHS.get()->getSourceRange() - << RHS.get()->getSourceRange(); + << LHSType << RHSType << LHS.get()->getSourceRange() + << RHS.get()->getSourceRange(); } RHS = ImpCastExprToType(RHS.get(), LHSType, CK_BitCast); return computeResultTy(); } // Allow block pointers to be compared with null pointer constants. - if (!IsRelational - && ((LHSType->isBlockPointerType() && RHSType->isPointerType()) - || (LHSType->isPointerType() && RHSType->isBlockPointerType()))) { + if (!IsRelational && + ((LHSType->isBlockPointerType() && RHSType->isPointerType()) || + (LHSType->isPointerType() && RHSType->isBlockPointerType()))) { if (!LHSIsNull && !RHSIsNull) { - if (!((RHSType->isPointerType() && RHSType->castAs() - ->getPointeeType()->isVoidType()) - || (LHSType->isPointerType() && LHSType->castAs() - ->getPointeeType()->isVoidType()))) + if (!((RHSType->isPointerType() && + RHSType->castAs()->getPointeeType()->isVoidType()) || + (LHSType->isPointerType() && + LHSType->castAs()->getPointeeType()->isVoidType()))) Diag(Loc, diag::err_typecheck_comparison_of_distinct_blocks) - << LHSType << RHSType << LHS.get()->getSourceRange() - << RHS.get()->getSourceRange(); + << LHSType << RHSType << LHS.get()->getSourceRange() + << RHS.get()->getSourceRange(); } if (LHSIsNull && !RHSIsNull) LHS = ImpCastExprToType(LHS.get(), RHSType, - RHSType->isPointerType() ? CK_BitCast - : CK_AnyPointerToBlockPointerCast); + RHSType->isPointerType() + ? CK_BitCast + : CK_AnyPointerToBlockPointerCast); else RHS = ImpCastExprToType(RHS.get(), LHSType, - LHSType->isPointerType() ? CK_BitCast - : CK_AnyPointerToBlockPointerCast); + LHSType->isPointerType() + ? CK_BitCast + : CK_AnyPointerToBlockPointerCast); return computeResultTy(); } @@ -10339,24 +10399,23 @@ if (!LPtrToVoid && !RPtrToVoid && !Context.typesAreCompatible(LHSType, RHSType)) { diagnoseDistinctPointerComparison(*this, Loc, LHS, RHS, - /*isError*/false); + /*isError*/ false); } if (LHSIsNull && !RHSIsNull) { Expr *E = LHS.get(); if (getLangOpts().ObjCAutoRefCount) CheckObjCConversion(SourceRange(), RHSType, E, CCK_ImplicitConversion); - LHS = ImpCastExprToType(E, RHSType, - RPT ? CK_BitCast :CK_CPointerToObjCPointerCast); - } - else { + LHS = ImpCastExprToType( + E, RHSType, RPT ? CK_BitCast : CK_CPointerToObjCPointerCast); + } else { Expr *E = RHS.get(); if (getLangOpts().ObjCAutoRefCount) CheckObjCConversion(SourceRange(), LHSType, E, CCK_ImplicitConversion, /*Diagnose=*/true, /*DiagnoseCFAudited=*/false, Opc); - RHS = ImpCastExprToType(E, LHSType, - LPT ? CK_BitCast :CK_CPointerToObjCPointerCast); + RHS = ImpCastExprToType( + E, LHSType, LPT ? CK_BitCast : CK_CPointerToObjCPointerCast); } return computeResultTy(); } @@ -10364,7 +10423,7 @@ RHSType->isObjCObjectPointerType()) { if (!Context.areComparableObjCPointerTypes(LHSType, RHSType)) diagnoseDistinctPointerComparison(*this, Loc, LHS, RHS, - /*isError*/false); + /*isError*/ false); if (isObjCObjectLiteral(LHS) || isObjCObjectLiteral(RHS)) diagnoseObjCLiteralComparison(*this, Loc, LHS, RHS, Opc); @@ -10400,8 +10459,9 @@ if (IsRelational) { isError = getLangOpts().CPlusPlus; DiagID = - isError ? diag::err_typecheck_ordered_comparison_of_pointer_and_zero - : diag::ext_typecheck_ordered_comparison_of_pointer_and_zero; + isError + ? diag::err_typecheck_ordered_comparison_of_pointer_and_zero + : diag::ext_typecheck_ordered_comparison_of_pointer_and_zero; } } else if (getLangOpts().CPlusPlus) { DiagID = diag::err_typecheck_comparison_of_pointer_integer; @@ -10412,30 +10472,31 @@ DiagID = diag::ext_typecheck_comparison_of_pointer_integer; if (DiagID) { - Diag(Loc, DiagID) - << LHSType << RHSType << LHS.get()->getSourceRange() - << RHS.get()->getSourceRange(); + Diag(Loc, DiagID) << LHSType << RHSType << LHS.get()->getSourceRange() + << RHS.get()->getSourceRange(); if (isError) return QualType(); } if (LHSType->isIntegerType()) LHS = ImpCastExprToType(LHS.get(), RHSType, - LHSIsNull ? CK_NullToPointer : CK_IntegralToPointer); + LHSIsNull ? CK_NullToPointer + : CK_IntegralToPointer); else RHS = ImpCastExprToType(RHS.get(), LHSType, - RHSIsNull ? CK_NullToPointer : CK_IntegralToPointer); + RHSIsNull ? CK_NullToPointer + : CK_IntegralToPointer); return computeResultTy(); } // Handle block pointers. - if (!IsRelational && RHSIsNull - && LHSType->isBlockPointerType() && RHSType->isIntegerType()) { + if (!IsRelational && RHSIsNull && LHSType->isBlockPointerType() && + RHSType->isIntegerType()) { RHS = ImpCastExprToType(RHS.get(), LHSType, CK_NullToPointer); return computeResultTy(); } - if (!IsRelational && LHSIsNull - && LHSType->isIntegerType() && RHSType->isBlockPointerType()) { + if (!IsRelational && LHSIsNull && LHSType->isIntegerType() && + RHSType->isBlockPointerType()) { LHS = ImpCastExprToType(LHS.get(), RHSType, CK_NullToPointer); return computeResultTy(); } @@ -10509,9 +10570,10 @@ BinaryOperatorKind Opc) { // Check to make sure we're operating on vectors of the same type and width, // Allowing one side to be a scalar of element type. - QualType vType = CheckVectorOperands(LHS, RHS, Loc, /*isCompAssign*/false, - /*AllowBothBool*/true, - /*AllowBoolConversions*/getLangOpts().ZVector); + QualType vType = + CheckVectorOperands(LHS, RHS, Loc, /*isCompAssign*/ false, + /*AllowBothBool*/ true, + /*AllowBoolConversions*/ getLangOpts().ZVector); if (vType.isNull()) return vType; @@ -10544,8 +10606,8 @@ // Ensure that either both operands are of the same vector type, or // one operand is of a vector type and the other is of its element type. QualType vType = CheckVectorOperands(LHS, RHS, Loc, false, - /*AllowBothBool*/true, - /*AllowBoolConversions*/false); + /*AllowBothBool*/ true, + /*AllowBoolConversions*/ false); if (vType.isNull()) return InvalidOperands(Loc, LHS, RHS); if (getLangOpts().OpenCL && getLangOpts().OpenCLVersion < 120 && @@ -10573,9 +10635,10 @@ RHS.get()->getType()->isVectorType()) { if (LHS.get()->getType()->hasIntegerRepresentation() && RHS.get()->getType()->hasIntegerRepresentation()) - return CheckVectorOperands(LHS, RHS, Loc, IsCompAssign, - /*AllowBothBool*/true, - /*AllowBoolConversions*/getLangOpts().ZVector); + return CheckVectorOperands( + LHS, RHS, Loc, IsCompAssign, + /*AllowBothBool*/ true, + /*AllowBoolConversions*/ getLangOpts().ZVector); return InvalidOperands(Loc, LHS, RHS); } @@ -10583,8 +10646,8 @@ diagnoseLogicalNotOnLHSofCheck(*this, LHS, RHS, Loc, Opc); ExprResult LHSResult = LHS, RHSResult = RHS; - QualType compType = UsualArithmeticConversions(LHSResult, RHSResult, - IsCompAssign); + QualType compType = + UsualArithmeticConversions(LHSResult, RHSResult, IsCompAssign); if (LHSResult.isInvalid() || RHSResult.isInvalid()) return QualType(); LHS = LHSResult.get(); @@ -10600,7 +10663,8 @@ SourceLocation Loc, BinaryOperatorKind Opc) { // Check vector operands differently. - if (LHS.get()->getType()->isVectorType() || RHS.get()->getType()->isVectorType()) + if (LHS.get()->getType()->isVectorType() || + RHS.get()->getType()->isVectorType()) return CheckVectorLogicalOperands(LHS, RHS, Loc); // Diagnose cases where the user write a logical and/or but probably meant a @@ -10621,14 +10685,13 @@ !RHS.get()->getExprLoc().isMacroID()) || (Result != 0 && Result != 1)) { Diag(Loc, diag::warn_logical_instead_of_bitwise) - << RHS.get()->getSourceRange() - << (Opc == BO_LAnd ? "&&" : "||"); + << RHS.get()->getSourceRange() << (Opc == BO_LAnd ? "&&" : "||"); // Suggest replacing the logical operator with the bitwise version Diag(Loc, diag::note_logical_instead_of_bitwise_change_operator) << (Opc == BO_LAnd ? "&" : "|") - << FixItHint::CreateReplacement(SourceRange( - Loc, getLocForEndOfToken(Loc)), - Opc == BO_LAnd ? "&" : "|"); + << FixItHint::CreateReplacement( + SourceRange(Loc, getLocForEndOfToken(Loc)), + Opc == BO_LAnd ? "&" : "|"); if (Opc == BO_LAnd) // Suggest replacing "Foo() && kNonZero" with "Foo()" Diag(Loc, diag::note_logical_instead_of_bitwise_remove_constant) @@ -10687,11 +10750,14 @@ static bool IsReadonlyMessage(Expr *E, Sema &S) { const MemberExpr *ME = dyn_cast(E); - if (!ME) return false; - if (!isa(ME->getMemberDecl())) return false; + if (!ME) + return false; + if (!isa(ME->getMemberDecl())) + return false; ObjCMessageExpr *Base = dyn_cast( ME->getBase()->IgnoreImplicit()->IgnoreParenImpCasts()); - if (!Base) return false; + if (!Base) + return false; return Base->getMethodDecl() != nullptr; } @@ -10705,13 +10771,17 @@ // Must be a reference to a declaration from an enclosing scope. DeclRefExpr *DRE = dyn_cast(E); - if (!DRE) return NCCK_None; - if (!DRE->refersToEnclosingVariableOrCapture()) return NCCK_None; + if (!DRE) + return NCCK_None; + if (!DRE->refersToEnclosingVariableOrCapture()) + return NCCK_None; // The declaration must be a variable which is not declared 'const'. VarDecl *var = dyn_cast(DRE->getDecl()); - if (!var) return NCCK_None; - if (var->getType().isConstQualified()) return NCCK_None; + if (!var) + return NCCK_None; + if (var->getType().isConstQualified()) + return NCCK_None; assert(var->hasLocalStorage() && "capture added 'const' to non-local?"); // Decide whether the first capture was for a block or a lambda. @@ -10750,7 +10820,7 @@ ConstMember, ConstMethod, NestedConstMember, - ConstUnknown, // Keep as last element + ConstUnknown, // Keep as last element }; /// Emit the "read-only variable not assignable" error and print notes to give @@ -10831,8 +10901,8 @@ const FunctionDecl *FD = CE->getDirectCallee(); if (FD && !IsTypeModifiable(FD->getReturnType(), IsDereference)) { if (!DiagnosticEmitted) { - S.Diag(Loc, diag::err_typecheck_assign_const) << ExprRange - << ConstFunction << FD; + S.Diag(Loc, diag::err_typecheck_assign_const) + << ExprRange << ConstFunction << FD; DiagnosticEmitted = true; } S.Diag(FD->getReturnTypeSourceRange().getBegin(), @@ -10858,8 +10928,8 @@ if (const CXXMethodDecl *MD = dyn_cast(DC)) { if (MD->isConst()) { if (!DiagnosticEmitted) { - S.Diag(Loc, diag::err_typecheck_assign_const) << ExprRange - << ConstMethod << MD; + S.Diag(Loc, diag::err_typecheck_assign_const) + << ExprRange << ConstMethod << MD; DiagnosticEmitted = true; } S.Diag(MD->getLocation(), diag::note_typecheck_assign_const) @@ -10876,11 +10946,7 @@ S.Diag(Loc, diag::err_typecheck_assign_const) << ExprRange << ConstUnknown; } -enum OriginalExprKind { - OEK_Variable, - OEK_Member, - OEK_LValue -}; +enum OriginalExprKind { OEK_Variable, OEK_Member, OEK_LValue }; static void DiagnoseRecursiveConstFields(Sema &S, const ValueDecl *VD, const RecordType *Ty, @@ -10895,21 +10961,20 @@ if (Field->getType().isConstQualified()) { if (!DiagnosticEmitted) { S.Diag(Loc, diag::err_typecheck_assign_const) - << Range << NestedConstMember << OEK << VD - << IsNested << Field; + << Range << NestedConstMember << OEK << VD << IsNested << Field; DiagnosticEmitted = true; } S.Diag(Field->getLocation(), diag::note_typecheck_assign_const) - << NestedConstMember << IsNested << Field - << Field->getType() << Field->getSourceRange(); + << NestedConstMember << IsNested << Field << Field->getType() + << Field->getSourceRange(); } } // Then, recurse. for (const FieldDecl *Field : Ty->getDecl()->fields()) { QualType FTy = Field->getType(); if (const RecordType *FieldRecTy = FTy->getAs()) - DiagnoseRecursiveConstFields(S, VD, FieldRecTy, Loc, Range, - OEK, DiagnosticEmitted, true); + DiagnoseRecursiveConstFields(S, VD, FieldRecTy, Loc, Range, OEK, + DiagnosticEmitted, true); } } @@ -10924,14 +10989,14 @@ bool DiagEmitted = false; if (const MemberExpr *ME = dyn_cast(E)) - DiagnoseRecursiveConstFields(S, ME->getMemberDecl(), RTy, Loc, - Range, OEK_Member, DiagEmitted); + DiagnoseRecursiveConstFields(S, ME->getMemberDecl(), RTy, Loc, Range, + OEK_Member, DiagEmitted); else if (const DeclRefExpr *DRE = dyn_cast(E)) - DiagnoseRecursiveConstFields(S, DRE->getDecl(), RTy, Loc, - Range, OEK_Variable, DiagEmitted); + DiagnoseRecursiveConstFields(S, DRE->getDecl(), RTy, Loc, Range, + OEK_Variable, DiagEmitted); else - DiagnoseRecursiveConstFields(S, nullptr, RTy, Loc, - Range, OEK_LValue, DiagEmitted); + DiagnoseRecursiveConstFields(S, nullptr, RTy, Loc, Range, OEK_LValue, + DiagEmitted); if (!DiagEmitted) DiagnoseConstAssignment(S, E, Loc); } @@ -10944,8 +11009,7 @@ S.CheckShadowingDeclModification(E, Loc); SourceLocation OrigLoc = Loc; - Expr::isModifiableLvalueResult IsLV = E->isModifiableLvalue(S.Context, - &Loc); + Expr::isModifiableLvalueResult IsLV = E->isModifiableLvalue(S.Context, &Loc); if (IsLV == Expr::MLV_ClassTemporary && IsReadonlyMessage(E, S)) IsLV = Expr::MLV_InvalidMessageExpression; if (IsLV == Expr::MLV_Valid) @@ -10982,8 +11046,8 @@ ObjCMethodDecl *method = S.getCurMethodDecl(); if (method && var == method->getSelfDecl()) DiagID = method->isClassMethod() - ? diag::err_typecheck_arc_assign_self_class_method - : diag::err_typecheck_arc_assign_self; + ? diag::err_typecheck_arc_assign_self_class_method + : diag::err_typecheck_arc_assign_self; // - fast enumeration variables else @@ -11035,8 +11099,9 @@ break; case Expr::MLV_IncompleteType: case Expr::MLV_IncompleteVoidType: - return S.RequireCompleteType(Loc, E->getType(), - diag::err_typecheck_incomplete_type_not_modifiable_lvalue, E); + return S.RequireCompleteType( + Loc, E->getType(), + diag::err_typecheck_incomplete_type_not_modifiable_lvalue, E); case Expr::MLV_DuplicateVectorComponents: DiagID = diag::err_typecheck_duplicate_vector_components_not_mlvalue; break; @@ -11061,8 +11126,7 @@ } static void CheckIdentityFieldAssignment(Expr *LHSExpr, Expr *RHSExpr, - SourceLocation Loc, - Sema &Sema) { + SourceLocation Loc, Sema &Sema) { if (Sema.inTemplateInstantiation()) return; if (Sema.isUnevaluatedContext()) @@ -11115,15 +11179,15 @@ return QualType(); QualType LHSType = LHSExpr->getType(); - QualType RHSType = CompoundType.isNull() ? RHS.get()->getType() : - CompoundType; + QualType RHSType = + CompoundType.isNull() ? RHS.get()->getType() : CompoundType; // OpenCL v1.2 s6.1.1.1 p2: // The half data type can only be used to declare a pointer to a buffer that // contains half values if (getLangOpts().OpenCL && !getOpenCLOptions().isEnabled("cl_khr_fp16") && - LHSType->isHalfType()) { - Diag(Loc, diag::err_opencl_half_load_store) << 1 - << LHSType.getUnqualifiedType(); + LHSType->isHalfType()) { + Diag(Loc, diag::err_opencl_half_load_store) + << 1 << LHSType.getUnqualifiedType(); return QualType(); } @@ -11145,10 +11209,8 @@ LHSType->isObjCObjectPointerType()))) ConvTy = Compatible; - if (ConvTy == Compatible && - LHSType->isObjCObjectType()) - Diag(Loc, diag::err_objc_object_assignment) - << LHSType; + if (ConvTy == Compatible && LHSType->isObjCObjectType()) + Diag(Loc, diag::err_objc_object_assignment) << LHSType; // If the RHS is a unary plus or minus, check to see if they = and + are // right next to each other. If so, the user may have typo'd "x =+ 4" @@ -11165,8 +11227,8 @@ Loc.getLocWithOffset(2) != UO->getSubExpr()->getBeginLoc() && UO->getSubExpr()->getBeginLoc().isFileID()) { Diag(Loc, diag::warn_not_compound_assign) - << (UO->getOpcode() == UO_Plus ? "+" : "-") - << SourceRange(UO->getOperatorLoc(), UO->getOperatorLoc()); + << (UO->getOpcode() == UO_Plus ? "+" : "-") + << SourceRange(UO->getOperatorLoc(), UO->getOperatorLoc()); } } @@ -11205,8 +11267,8 @@ ConvTy = CheckAssignmentConstraints(Loc, LHSType, RHSType); } - if (DiagnoseAssignmentResult(ConvTy, Loc, LHSType, RHSType, - RHS.get(), AA_Assigning)) + if (DiagnoseAssignmentResult(ConvTy, Loc, LHSType, RHSType, RHS.get(), + AA_Assigning)) return QualType(); CheckForNullPointerDereference(*this, LHSExpr); @@ -11218,8 +11280,7 @@ // is converted to the type of the assignment expression (above). // C++ 5.17p1: the type of the assignment expression is that of its left // operand. - return (getLangOpts().CPlusPlus - ? LHSType : LHSType.getUnqualifiedType()); + return (getLangOpts().CPlusPlus ? LHSType : LHSType.getUnqualifiedType()); } // Only ignore explicit casts to void. @@ -11323,8 +11384,8 @@ static QualType CheckIncrementDecrementOperand(Sema &S, Expr *Op, ExprValueKind &VK, ExprObjectKind &OK, - SourceLocation OpLoc, - bool IsInc, bool IsPrefix) { + SourceLocation OpLoc, bool IsInc, + bool IsPrefix) { if (Op->isTypeDependent()) return S.Context.DependentTy; @@ -11344,9 +11405,10 @@ return QualType(); } // Increment of bool sets it to true, but is deprecated. - S.Diag(OpLoc, S.getLangOpts().CPlusPlus17 ? diag::ext_increment_bool - : diag::warn_increment_bool) - << Op->getSourceRange(); + S.Diag(OpLoc, + S.getLangOpts().CPlusPlus17 ? diag::ext_increment_bool + : diag::warn_increment_bool) + << Op->getSourceRange(); } else if (S.getLangOpts().CPlusPlus && ResType->isEnumeralType()) { // Error on enum increments and decrements in C++ mode S.Diag(OpLoc, diag::err_increment_decrement_enum) << IsInc << ResType; @@ -11366,24 +11428,25 @@ } else if (ResType->isAnyComplexType()) { // C99 does not support ++/-- on complex types, we allow as an extension. S.Diag(OpLoc, diag::ext_integer_increment_complex) - << ResType << Op->getSourceRange(); + << ResType << Op->getSourceRange(); } else if (ResType->isPlaceholderType()) { ExprResult PR = S.CheckPlaceholderExpr(Op); - if (PR.isInvalid()) return QualType(); - return CheckIncrementDecrementOperand(S, PR.get(), VK, OK, OpLoc, - IsInc, IsPrefix); + if (PR.isInvalid()) + return QualType(); + return CheckIncrementDecrementOperand(S, PR.get(), VK, OK, OpLoc, IsInc, + IsPrefix); } else if (S.getLangOpts().AltiVec && ResType->isVectorType()) { // OK! ( C/C++ Language Extensions for CBEA(Version 2.6) 10.3 ) } else if (S.getLangOpts().ZVector && ResType->isVectorType() && (ResType->getAs()->getVectorKind() != VectorType::AltiVecBool)) { // The z vector extensions allow ++ and -- for non-bool vectors. - } else if(S.getLangOpts().OpenCL && ResType->isVectorType() && - ResType->getAs()->getElementType()->isIntegerType()) { + } else if (S.getLangOpts().OpenCL && ResType->isVectorType() && + ResType->getAs()->getElementType()->isIntegerType()) { // OpenCL V1.2 6.3 says dec/inc ops operate on integer vector types. } else { S.Diag(OpLoc, diag::err_typecheck_illegal_increment_decrement) - << ResType << int(IsInc) << Op->getSourceRange(); + << ResType << int(IsInc) << Op->getSourceRange(); return QualType(); } // At this point, we know we have a real, complex or pointer type. @@ -11403,7 +11466,6 @@ } } - /// getPrimaryDecl - Helper function for CheckAddressOfOperand(). /// This routine allows us to typecheck complex/recursive expressions /// where the declaration is needed for type checking. We only need to @@ -11431,8 +11493,8 @@ case Stmt::ArraySubscriptExprClass: { // FIXME: This code shouldn't be necessary! We should catch the implicit // promotion of register arrays earlier. - Expr* Base = cast(E)->getBase(); - if (ImplicitCastExpr* ICE = dyn_cast(Base)) { + Expr *Base = cast(E)->getBase(); + if (ImplicitCastExpr *ICE = dyn_cast(Base)) { if (ICE->getSubExpr()->getType()->isArrayType()) return getPrimaryDecl(ICE->getSubExpr()); } @@ -11441,7 +11503,7 @@ case Stmt::UnaryOperatorClass: { UnaryOperator *UO = cast(E); - switch(UO->getOpcode()) { + switch (UO->getOpcode()) { case UO_Real: case UO_Imag: case UO_Extension: @@ -11462,19 +11524,19 @@ } namespace { - enum { - AO_Bit_Field = 0, - AO_Vector_Element = 1, - AO_Property_Expansion = 2, - AO_Register_Variable = 3, - AO_No_Error = 4 - }; +enum { + AO_Bit_Field = 0, + AO_Vector_Element = 1, + AO_Property_Expansion = 2, + AO_Register_Variable = 3, + AO_No_Error = 4 +}; } /// Diagnose invalid operand for address of operations. /// /// \param Type The type of operand which cannot have its address taken. -static void diagnoseAddressOfInvalidType(Sema &S, SourceLocation Loc, - Expr *E, unsigned Type) { +static void diagnoseAddressOfInvalidType(Sema &S, SourceLocation Loc, Expr *E, + unsigned Type) { S.Diag(Loc, diag::err_typecheck_address_of) << Type << E->getSourceRange(); } @@ -11486,13 +11548,14 @@ /// In C++, the operand might be an overloaded function name, in which case /// we allow the '&' but retain the overloaded-function type. QualType Sema::CheckAddressOfOperand(ExprResult &OrigOp, SourceLocation OpLoc) { - if (const BuiltinType *PTy = OrigOp.get()->getType()->getAsPlaceholderType()){ + if (const BuiltinType *PTy = + OrigOp.get()->getType()->getAsPlaceholderType()) { if (PTy->getKind() == BuiltinType::Overload) { Expr *E = OrigOp.get()->IgnoreParens(); if (!isa(E)) { assert(cast(E)->getOpcode() == UO_AddrOf); Diag(OpLoc, diag::err_typecheck_invalid_lvalue_addrof_addrof_function) - << OrigOp.get()->getSourceRange(); + << OrigOp.get()->getSourceRange(); return QualType(); } @@ -11500,7 +11563,7 @@ if (isa(Ovl)) if (!ResolveSingleFunctionTemplateSpecialization(Ovl)) { Diag(OpLoc, diag::err_invalid_form_pointer_member_function) - << OrigOp.get()->getSourceRange(); + << OrigOp.get()->getSourceRange(); return QualType(); } @@ -11512,12 +11575,13 @@ if (PTy->getKind() == BuiltinType::BoundMember) { Diag(OpLoc, diag::err_invalid_form_pointer_member_function) - << OrigOp.get()->getSourceRange(); + << OrigOp.get()->getSourceRange(); return QualType(); } OrigOp = CheckPlaceholderExpr(OrigOp.get()); - if (OrigOp.isInvalid()) return QualType(); + if (OrigOp.isInvalid()) + return QualType(); } if (OrigOp.get()->isTypeDependent()) @@ -11534,7 +11598,7 @@ // depending on a vendor implementation. Thus preventing // taking an address of the capture to avoid invalid AS casts. if (LangOpts.OpenCL) { - auto* VarRef = dyn_cast(op); + auto *VarRef = dyn_cast(op); if (VarRef && VarRef->refersToEnclosingVariableOrCapture()) { Diag(op->getExprLoc(), diag::err_opencl_taking_address_capture); return QualType(); @@ -11543,7 +11607,7 @@ if (getLangOpts().C99) { // Implement C99-only parts of addressof rules. - if (UnaryOperator* uOp = dyn_cast(op)) { + if (UnaryOperator *uOp = dyn_cast(op)) { if (uOp->getOpcode() == UO_Deref) // Per C99 6.5.3.2, the address of a deref always returns a valid result // (assuming the deref expression is valid). @@ -11564,9 +11628,10 @@ if (lval == Expr::LV_ClassTemporary || lval == Expr::LV_ArrayTemporary) { bool sfinae = (bool)isSFINAEContext(); - Diag(OpLoc, isSFINAEContext() ? diag::err_typecheck_addrof_temporary - : diag::ext_typecheck_addrof_temporary) - << op->getType() << op->getSourceRange(); + Diag(OpLoc, + isSFINAEContext() ? diag::err_typecheck_addrof_temporary + : diag::ext_typecheck_addrof_temporary) + << op->getType() << op->getSourceRange(); if (sfinae) return QualType(); // Materialize the temporary as an lvalue so that we can take its address. @@ -11581,7 +11646,7 @@ // If the underlying expression isn't a decl ref, give up. if (!isa(op)) { Diag(OpLoc, diag::err_invalid_form_pointer_member_function) - << OrigOp.get()->getSourceRange(); + << OrigOp.get()->getSourceRange(); return QualType(); } DeclRefExpr *DRE = cast(op); @@ -11590,19 +11655,20 @@ // The id-expression was parenthesized. if (OrigOp.get() != DRE) { Diag(OpLoc, diag::err_parens_pointer_member_function) - << OrigOp.get()->getSourceRange(); + << OrigOp.get()->getSourceRange(); - // The method was named without a qualifier. + // The method was named without a qualifier. } else if (!DRE->getQualifier()) { if (MD->getParent()->getName().empty()) Diag(OpLoc, diag::err_unqualified_pointer_member_function) - << op->getSourceRange(); + << op->getSourceRange(); else { SmallString<32> Str; StringRef Qual = (MD->getParent()->getName() + "::").toStringRef(Str); Diag(OpLoc, diag::err_unqualified_pointer_member_function) - << op->getSourceRange() - << FixItHint::CreateInsertion(op->getSourceRange().getBegin(), Qual); + << op->getSourceRange() + << FixItHint::CreateInsertion(op->getSourceRange().getBegin(), + Qual); } } @@ -11625,7 +11691,7 @@ AddressOfError = AO_Property_Expansion; } else { Diag(OpLoc, diag::err_typecheck_invalid_lvalue_addrof) - << op->getType() << op->getSourceRange(); + << op->getType() << op->getSourceRange(); return QualType(); } } @@ -11641,8 +11707,7 @@ if (const VarDecl *vd = dyn_cast(dcl)) { // in C++ it is not error to take address of a register // variable (c++03 7.1.1P3) - if (vd->getStorageClass() == SC_Register && - !getLangOpts().CPlusPlus) { + if (vd->getStorageClass() == SC_Register && !getLangOpts().CPlusPlus) { AddressOfError = AO_Register_Variable; } } else if (isa(dcl)) { @@ -11659,7 +11724,7 @@ if (dcl->getType()->isReferenceType()) { Diag(OpLoc, diag::err_cannot_form_pointer_to_member_of_reference_type) - << dcl->getDeclName() << dcl->getType(); + << dcl->getDeclName() << dcl->getType(); return QualType(); } @@ -11711,7 +11776,7 @@ const ParmVarDecl *Param = dyn_cast(D); if (!Param) return; - if (const FunctionDecl* FD = dyn_cast(Param->getDeclContext())) + if (const FunctionDecl *FD = dyn_cast(Param->getDeclContext())) if (!FD->hasAttr() && !Param->hasAttr()) return; if (FunctionScopeInfo *FD = S.getCurFunction()) @@ -11734,27 +11799,26 @@ if (isa(Op)) { QualType OpOrigType = Op->IgnoreParenCasts()->getType(); - S.CheckCompatibleReinterpretCast(OpOrigType, OpTy, /*IsDereference*/true, + S.CheckCompatibleReinterpretCast(OpOrigType, OpTy, /*IsDereference*/ true, Op->getSourceRange()); } - if (const PointerType *PT = OpTy->getAs()) - { + if (const PointerType *PT = OpTy->getAs()) { Result = PT->getPointeeType(); - } - else if (const ObjCObjectPointerType *OPT = - OpTy->getAs()) + } else if (const ObjCObjectPointerType *OPT = + OpTy->getAs()) Result = OPT->getPointeeType(); else { ExprResult PR = S.CheckPlaceholderExpr(Op); - if (PR.isInvalid()) return QualType(); + if (PR.isInvalid()) + return QualType(); if (PR.get() != Op) return CheckIndirectionOperand(S, PR.get(), VK, OpLoc); } if (Result.isNull()) { S.Diag(OpLoc, diag::err_typecheck_indirection_requires_pointer) - << OpTy << Op->getSourceRange(); + << OpTy << Op->getSourceRange(); return QualType(); } @@ -11769,7 +11833,7 @@ // be a pointer to an object type, or a pointer to a function type if (S.getLangOpts().CPlusPlus && Result->isVoidType()) S.Diag(OpLoc, diag::ext_typecheck_indirection_through_void_pointer) - << OpTy << Op->getSourceRange(); + << OpTy << Op->getSourceRange(); // Dereferences are usually l-values... VK = VK_LValue; @@ -11784,60 +11848,150 @@ BinaryOperatorKind Sema::ConvertTokenKindToBinaryOpcode(tok::TokenKind Kind) { BinaryOperatorKind Opc; switch (Kind) { - default: llvm_unreachable("Unknown binop!"); - case tok::periodstar: Opc = BO_PtrMemD; break; - case tok::arrowstar: Opc = BO_PtrMemI; break; - case tok::star: Opc = BO_Mul; break; - case tok::slash: Opc = BO_Div; break; - case tok::percent: Opc = BO_Rem; break; - case tok::plus: Opc = BO_Add; break; - case tok::minus: Opc = BO_Sub; break; - case tok::lessless: Opc = BO_Shl; break; - case tok::greatergreater: Opc = BO_Shr; break; - case tok::lessequal: Opc = BO_LE; break; - case tok::less: Opc = BO_LT; break; - case tok::greaterequal: Opc = BO_GE; break; - case tok::greater: Opc = BO_GT; break; - case tok::exclaimequal: Opc = BO_NE; break; - case tok::equalequal: Opc = BO_EQ; break; - case tok::spaceship: Opc = BO_Cmp; break; - case tok::amp: Opc = BO_And; break; - case tok::caret: Opc = BO_Xor; break; - case tok::pipe: Opc = BO_Or; break; - case tok::ampamp: Opc = BO_LAnd; break; - case tok::pipepipe: Opc = BO_LOr; break; - case tok::equal: Opc = BO_Assign; break; - case tok::starequal: Opc = BO_MulAssign; break; - case tok::slashequal: Opc = BO_DivAssign; break; - case tok::percentequal: Opc = BO_RemAssign; break; - case tok::plusequal: Opc = BO_AddAssign; break; - case tok::minusequal: Opc = BO_SubAssign; break; - case tok::lesslessequal: Opc = BO_ShlAssign; break; - case tok::greatergreaterequal: Opc = BO_ShrAssign; break; - case tok::ampequal: Opc = BO_AndAssign; break; - case tok::caretequal: Opc = BO_XorAssign; break; - case tok::pipeequal: Opc = BO_OrAssign; break; - case tok::comma: Opc = BO_Comma; break; + default: + llvm_unreachable("Unknown binop!"); + case tok::periodstar: + Opc = BO_PtrMemD; + break; + case tok::arrowstar: + Opc = BO_PtrMemI; + break; + case tok::star: + Opc = BO_Mul; + break; + case tok::slash: + Opc = BO_Div; + break; + case tok::percent: + Opc = BO_Rem; + break; + case tok::plus: + Opc = BO_Add; + break; + case tok::minus: + Opc = BO_Sub; + break; + case tok::lessless: + Opc = BO_Shl; + break; + case tok::greatergreater: + Opc = BO_Shr; + break; + case tok::lessequal: + Opc = BO_LE; + break; + case tok::less: + Opc = BO_LT; + break; + case tok::greaterequal: + Opc = BO_GE; + break; + case tok::greater: + Opc = BO_GT; + break; + case tok::exclaimequal: + Opc = BO_NE; + break; + case tok::equalequal: + Opc = BO_EQ; + break; + case tok::spaceship: + Opc = BO_Cmp; + break; + case tok::amp: + Opc = BO_And; + break; + case tok::caret: + Opc = BO_Xor; + break; + case tok::pipe: + Opc = BO_Or; + break; + case tok::ampamp: + Opc = BO_LAnd; + break; + case tok::pipepipe: + Opc = BO_LOr; + break; + case tok::equal: + Opc = BO_Assign; + break; + case tok::starequal: + Opc = BO_MulAssign; + break; + case tok::slashequal: + Opc = BO_DivAssign; + break; + case tok::percentequal: + Opc = BO_RemAssign; + break; + case tok::plusequal: + Opc = BO_AddAssign; + break; + case tok::minusequal: + Opc = BO_SubAssign; + break; + case tok::lesslessequal: + Opc = BO_ShlAssign; + break; + case tok::greatergreaterequal: + Opc = BO_ShrAssign; + break; + case tok::ampequal: + Opc = BO_AndAssign; + break; + case tok::caretequal: + Opc = BO_XorAssign; + break; + case tok::pipeequal: + Opc = BO_OrAssign; + break; + case tok::comma: + Opc = BO_Comma; + break; } return Opc; } -static inline UnaryOperatorKind ConvertTokenKindToUnaryOpcode( - tok::TokenKind Kind) { +static inline UnaryOperatorKind +ConvertTokenKindToUnaryOpcode(tok::TokenKind Kind) { UnaryOperatorKind Opc; switch (Kind) { - default: llvm_unreachable("Unknown unary op!"); - case tok::plusplus: Opc = UO_PreInc; break; - case tok::minusminus: Opc = UO_PreDec; break; - case tok::amp: Opc = UO_AddrOf; break; - case tok::star: Opc = UO_Deref; break; - case tok::plus: Opc = UO_Plus; break; - case tok::minus: Opc = UO_Minus; break; - case tok::tilde: Opc = UO_Not; break; - case tok::exclaim: Opc = UO_LNot; break; - case tok::kw___real: Opc = UO_Real; break; - case tok::kw___imag: Opc = UO_Imag; break; - case tok::kw___extension__: Opc = UO_Extension; break; + default: + llvm_unreachable("Unknown unary op!"); + case tok::plusplus: + Opc = UO_PreInc; + break; + case tok::minusminus: + Opc = UO_PreDec; + break; + case tok::amp: + Opc = UO_AddrOf; + break; + case tok::star: + Opc = UO_Deref; + break; + case tok::plus: + Opc = UO_Plus; + break; + case tok::minus: + Opc = UO_Minus; + break; + case tok::tilde: + Opc = UO_Not; + break; + case tok::exclaim: + Opc = UO_LNot; + break; + case tok::kw___real: + Opc = UO_Real; + break; + case tok::kw___imag: + Opc = UO_Imag; + break; + case tok::kw___extension__: + Opc = UO_Extension; + break; } return Opc; } @@ -11856,14 +12010,13 @@ RHSExpr = RHSExpr->IgnoreParenImpCasts(); const DeclRefExpr *LHSDeclRef = dyn_cast(LHSExpr); const DeclRefExpr *RHSDeclRef = dyn_cast(RHSExpr); - if (!LHSDeclRef || !RHSDeclRef || - LHSDeclRef->getLocation().isMacroID() || + if (!LHSDeclRef || !RHSDeclRef || LHSDeclRef->getLocation().isMacroID() || RHSDeclRef->getLocation().isMacroID()) return; const ValueDecl *LHSDecl = - cast(LHSDeclRef->getDecl()->getCanonicalDecl()); + cast(LHSDeclRef->getDecl()->getCanonicalDecl()); const ValueDecl *RHSDecl = - cast(RHSDeclRef->getDecl()->getCanonicalDecl()); + cast(RHSDeclRef->getDecl()->getCanonicalDecl()); if (LHSDecl != RHSDecl) return; if (LHSDecl->getType().isVolatileQualified()) @@ -11872,8 +12025,9 @@ if (RefTy->getPointeeType().isVolatileQualified()) return; - S.Diag(OpLoc, IsBuiltin ? diag::warn_self_assignment_builtin - : diag::warn_self_assignment_overloaded) + S.Diag(OpLoc, + IsBuiltin ? diag::warn_self_assignment_builtin + : diag::warn_self_assignment_overloaded) << LHSDeclRef->getType() << LHSExpr->getSourceRange() << RHSExpr->getSourceRange(); } @@ -11892,8 +12046,7 @@ if (LHS->IgnoreParenCasts()->getType()->isObjCObjectPointerType()) { ObjCPointerExpr = LHS; OtherExpr = RHS; - } - else if (RHS->IgnoreParenCasts()->getType()->isObjCObjectPointerType()) { + } else if (RHS->IgnoreParenCasts()->getType()->isObjCObjectPointerType()) { ObjCPointerExpr = RHS; OtherExpr = LHS; } @@ -11916,8 +12069,7 @@ Diag = diag::warn_objc_pointer_masking_performSelector; } - S.Diag(OpLoc, Diag) - << ObjCPointerExpr->getSourceRange(); + S.Diag(OpLoc, Diag) << ObjCPointerExpr->getSourceRange(); } } @@ -11958,9 +12110,9 @@ BinOpResTy = S.GetSignedVectorType(BinOpResTy); if (IsCompAssign) - return new (Context) CompoundAssignOperator( - LHS.get(), RHS.get(), Opc, ResultTy, VK, OK, BinOpResTy, BinOpResTy, - OpLoc, FPFeatures); + return new (Context) + CompoundAssignOperator(LHS.get(), RHS.get(), Opc, ResultTy, VK, OK, + BinOpResTy, BinOpResTy, OpLoc, FPFeatures); LHS = convertVector(LHS.get(), Context.FloatTy, S); auto *BO = new (Context) BinaryOperator(LHS.get(), RHS.get(), Opc, BinOpResTy, @@ -12001,8 +12153,8 @@ /// operator @p Opc at location @c TokLoc. This routine only supports /// built-in operations; ActOnBinOp handles overloaded operators. ExprResult Sema::CreateBuiltinBinOp(SourceLocation OpLoc, - BinaryOperatorKind Opc, - Expr *LHSExpr, Expr *RHSExpr) { + BinaryOperatorKind Opc, Expr *LHSExpr, + Expr *RHSExpr) { if (getLangOpts().CPlusPlus11 && isa(RHSExpr)) { // The syntax only allows initializer lists on the RHS of assignment, // so we don't need to worry about accepting invalid code for @@ -12022,7 +12174,7 @@ } ExprResult LHS = LHSExpr, RHS = RHSExpr; - QualType ResultTy; // Result type of the binary operator. + QualType ResultTy; // Result type of the binary operator. // The following two variables are used for compound assignment operators QualType CompLHSTy; // Type of LHS after promotions for computation QualType CompResultTy; // Type of computation result @@ -12050,9 +12202,8 @@ // OpenCL special types - image, sampler, pipe, and blocks are to be used // only with a builtin functions and therefore should be disallowed here. - if (LHSTy->isImageType() || RHSTy->isImageType() || - LHSTy->isSamplerT() || RHSTy->isSamplerT() || - LHSTy->isPipeType() || RHSTy->isPipeType() || + if (LHSTy->isImageType() || RHSTy->isImageType() || LHSTy->isSamplerT() || + RHSTy->isSamplerT() || LHSTy->isPipeType() || RHSTy->isPipeType() || LHSTy->isBlockPointerType() || RHSTy->isBlockPointerType()) { ResultTy = InvalidOperands(OpLoc, LHS, RHS); return ExprError(); @@ -12075,14 +12226,14 @@ break; case BO_PtrMemD: case BO_PtrMemI: - ResultTy = CheckPointerToMemberOperands(LHS, RHS, VK, OpLoc, - Opc == BO_PtrMemI); + ResultTy = + CheckPointerToMemberOperands(LHS, RHS, VK, OpLoc, Opc == BO_PtrMemI); break; case BO_Mul: case BO_Div: ConvertHalfVec = true; - ResultTy = CheckMultiplyDivideOperands(LHS, RHS, OpLoc, false, - Opc == BO_Div); + ResultTy = + CheckMultiplyDivideOperands(LHS, RHS, OpLoc, false, Opc == BO_Div); break; case BO_Rem: ResultTy = CheckRemainderOperands(LHS, RHS, OpLoc); @@ -12131,8 +12282,8 @@ case BO_MulAssign: case BO_DivAssign: ConvertHalfVec = true; - CompResultTy = CheckMultiplyDivideOperands(LHS, RHS, OpLoc, true, - Opc == BO_DivAssign); + CompResultTy = + CheckMultiplyDivideOperands(LHS, RHS, OpLoc, true, Opc == BO_DivAssign); CompLHSTy = CompResultTy; if (!CompResultTy.isNull() && !LHS.isInvalid() && !RHS.isInvalid()) ResultTy = CheckAssignmentOperands(LHS.get(), RHS, OpLoc, CompResultTy); @@ -12188,19 +12339,20 @@ // this only when HalfArgsAndReturn is set (that is, when the target is arm or // arm64). assert(isVector(RHS.get()->getType(), Context.HalfTy) == - isVector(LHS.get()->getType(), Context.HalfTy) && + isVector(LHS.get()->getType(), Context.HalfTy) && "both sides are half vectors or neither sides are"); - ConvertHalfVec = needsConversionOfHalfVec(ConvertHalfVec, Context, - LHS.get()->getType()); + ConvertHalfVec = + needsConversionOfHalfVec(ConvertHalfVec, Context, LHS.get()->getType()); // Check for array bounds violations for both sides of the BinaryOperator CheckArrayAccess(LHS.get()); CheckArrayAccess(RHS.get()); - if (const ObjCIsaExpr *OISA = dyn_cast(LHS.get()->IgnoreParenCasts())) { - NamedDecl *ObjectSetClass = LookupSingleName(TUScope, - &Context.Idents.get("object_setClass"), - SourceLocation(), LookupOrdinaryName); + if (const ObjCIsaExpr *OISA = + dyn_cast(LHS.get()->IgnoreParenCasts())) { + NamedDecl *ObjectSetClass = + LookupSingleName(TUScope, &Context.Idents.get("object_setClass"), + SourceLocation(), LookupOrdinaryName); if (ObjectSetClass && isa(LHS.get())) { SourceLocation RHSLocEnd = getLocForEndOfToken(RHS.get()->getEndLoc()); Diag(LHS.get()->getExprLoc(), diag::warn_objc_isa_assign) @@ -12209,12 +12361,10 @@ << FixItHint::CreateReplacement(SourceRange(OISA->getOpLoc(), OpLoc), ",") << FixItHint::CreateInsertion(RHSLocEnd, ")"); - } - else + } else Diag(LHS.get()->getExprLoc(), diag::warn_objc_isa_assign); - } - else if (const ObjCIvarRefExpr *OIRE = - dyn_cast(LHS.get()->IgnoreParenCasts())) + } else if (const ObjCIvarRefExpr *OIRE = + dyn_cast(LHS.get()->IgnoreParenCasts())) DiagnoseDirectIsaAccess(*this, OIRE, OpLoc, RHS.get()); // Opc is not a compound assignment if CompResultTy is null. @@ -12227,8 +12377,8 @@ } // Handle compound assignments. - if (getLangOpts().CPlusPlus && LHS.get()->getObjectKind() != - OK_ObjCProperty) { + if (getLangOpts().CPlusPlus && + LHS.get()->getObjectKind() != OK_ObjCProperty) { VK = VK_LValue; OK = LHS.get()->getObjectKind(); } @@ -12237,9 +12387,9 @@ return convertHalfVecBinOp(*this, LHS, RHS, Opc, ResultTy, VK, OK, true, OpLoc, FPFeatures); - return new (Context) CompoundAssignOperator( - LHS.get(), RHS.get(), Opc, ResultTy, VK, OK, CompLHSTy, CompResultTy, - OpLoc, FPFeatures); + return new (Context) + CompoundAssignOperator(LHS.get(), RHS.get(), Opc, ResultTy, VK, OK, + CompLHSTy, CompResultTy, OpLoc, FPFeatures); } /// DiagnoseBitwisePrecedence - Emit a warning when bitwise and comparison @@ -12275,29 +12425,29 @@ : SourceRange(LHSExpr->getBeginLoc(), RHSBO->getLHS()->getEndLoc()); Self.Diag(OpLoc, diag::warn_precedence_bitwise_rel) - << DiagRange << BinaryOperator::getOpcodeStr(Opc) << OpStr; + << DiagRange << BinaryOperator::getOpcodeStr(Opc) << OpStr; SuggestParentheses(Self, OpLoc, - Self.PDiag(diag::note_precedence_silence) << OpStr, - (isLeftComp ? LHSExpr : RHSExpr)->getSourceRange()); + Self.PDiag(diag::note_precedence_silence) << OpStr, + (isLeftComp ? LHSExpr : RHSExpr)->getSourceRange()); SuggestParentheses(Self, OpLoc, - Self.PDiag(diag::note_precedence_bitwise_first) - << BinaryOperator::getOpcodeStr(Opc), - ParensRange); + Self.PDiag(diag::note_precedence_bitwise_first) + << BinaryOperator::getOpcodeStr(Opc), + ParensRange); } /// It accepts a '&&' expr that is inside a '||' one. /// Emit a diagnostic together with a fixit hint that wraps the '&&' expression /// in parentheses. -static void -EmitDiagnosticForLogicalAndInLogicalOr(Sema &Self, SourceLocation OpLoc, - BinaryOperator *Bop) { +static void EmitDiagnosticForLogicalAndInLogicalOr(Sema &Self, + SourceLocation OpLoc, + BinaryOperator *Bop) { assert(Bop->getOpcode() == BO_LAnd); Self.Diag(Bop->getOperatorLoc(), diag::warn_logical_and_in_logical_or) << Bop->getSourceRange() << OpLoc; SuggestParentheses(Self, Bop->getOperatorLoc(), - Self.PDiag(diag::note_precedence_silence) - << Bop->getOpcodeStr(), - Bop->getSourceRange()); + Self.PDiag(diag::note_precedence_silence) + << Bop->getOpcodeStr(), + Bop->getSourceRange()); } /// Returns true if the given expression can be evaluated as a constant @@ -12361,12 +12511,12 @@ if (BinaryOperator *Bop = dyn_cast(SubExpr)) { if (Bop->isBitwiseOp() && Bop->getOpcode() < Opc) { S.Diag(Bop->getOperatorLoc(), diag::warn_bitwise_op_in_bitwise_op) - << Bop->getOpcodeStr() << BinaryOperator::getOpcodeStr(Opc) - << Bop->getSourceRange() << OpLoc; + << Bop->getOpcodeStr() << BinaryOperator::getOpcodeStr(Opc) + << Bop->getSourceRange() << OpLoc; SuggestParentheses(S, Bop->getOperatorLoc(), - S.PDiag(diag::note_precedence_silence) - << Bop->getOpcodeStr(), - Bop->getSourceRange()); + S.PDiag(diag::note_precedence_silence) + << Bop->getOpcodeStr(), + Bop->getSourceRange()); } } } @@ -12379,14 +12529,14 @@ S.Diag(Bop->getOperatorLoc(), diag::warn_addition_in_bitshift) << Bop->getSourceRange() << OpLoc << Shift << Op; SuggestParentheses(S, Bop->getOperatorLoc(), - S.PDiag(diag::note_precedence_silence) << Op, - Bop->getSourceRange()); + S.PDiag(diag::note_precedence_silence) << Op, + Bop->getSourceRange()); } } } -static void DiagnoseShiftCompare(Sema &S, SourceLocation OpLoc, - Expr *LHSExpr, Expr *RHSExpr) { +static void DiagnoseShiftCompare(Sema &S, SourceLocation OpLoc, Expr *LHSExpr, + Expr *RHSExpr) { CXXOperatorCallExpr *OCE = dyn_cast(LHSExpr); if (!OCE) return; @@ -12415,27 +12565,28 @@ /// precedence. static void DiagnoseBinOpPrecedence(Sema &Self, BinaryOperatorKind Opc, SourceLocation OpLoc, Expr *LHSExpr, - Expr *RHSExpr){ + Expr *RHSExpr) { // Diagnose "arg1 'bitwise' arg2 'eq' arg3". if (BinaryOperator::isBitwiseOp(Opc)) DiagnoseBitwisePrecedence(Self, Opc, OpLoc, LHSExpr, RHSExpr); // Diagnose "arg1 & arg2 | arg3" if ((Opc == BO_Or || Opc == BO_Xor) && - !OpLoc.isMacroID()/* Don't warn in macros. */) { + !OpLoc.isMacroID() /* Don't warn in macros. */) { DiagnoseBitwiseOpInBitwiseOp(Self, Opc, OpLoc, LHSExpr); DiagnoseBitwiseOpInBitwiseOp(Self, Opc, OpLoc, RHSExpr); } // Warn about arg1 || arg2 && arg3, as GCC 4.3+ does. // We don't warn for 'assert(a || b && "bad")' since this is safe. - if (Opc == BO_LOr && !OpLoc.isMacroID()/* Don't warn in macros. */) { + if (Opc == BO_LOr && !OpLoc.isMacroID() /* Don't warn in macros. */) { DiagnoseLogicalAndInLogicalOrLHS(Self, OpLoc, LHSExpr, RHSExpr); DiagnoseLogicalAndInLogicalOrRHS(Self, OpLoc, LHSExpr, RHSExpr); } - if ((Opc == BO_Shl && LHSExpr->getType()->isIntegralType(Self.getASTContext())) - || Opc == BO_Shr) { + if ((Opc == BO_Shl && + LHSExpr->getType()->isIntegralType(Self.getASTContext())) || + Opc == BO_Shr) { StringRef Shift = BinaryOperator::getOpcodeStr(Opc); DiagnoseAdditionInShift(Self, OpLoc, LHSExpr, Shift); DiagnoseAdditionInShift(Self, OpLoc, RHSExpr, Shift); @@ -12449,8 +12600,7 @@ // Binary Operators. 'Tok' is the token for the operator. ExprResult Sema::ActOnBinOp(Scope *S, SourceLocation TokLoc, - tok::TokenKind Kind, - Expr *LHSExpr, Expr *RHSExpr) { + tok::TokenKind Kind, Expr *LHSExpr, Expr *RHSExpr) { BinaryOperatorKind Opc = ConvertTokenKindToBinaryOpcode(Kind); assert(LHSExpr && "ActOnBinOp(): missing left expression"); assert(RHSExpr && "ActOnBinOp(): missing right expression"); @@ -12463,8 +12613,8 @@ /// Build an overloaded binary operator expression in the given scope. static ExprResult BuildOverloadedBinOp(Sema &S, Scope *Sc, SourceLocation OpLoc, - BinaryOperatorKind Opc, - Expr *LHS, Expr *RHS) { + BinaryOperatorKind Opc, Expr *LHS, + Expr *RHS) { switch (Opc) { case BO_Assign: case BO_DivAssign: @@ -12485,11 +12635,10 @@ // scope and an argument-dependent lookup based on the types of // the arguments. UnresolvedSet<16> Functions; - OverloadedOperatorKind OverOp - = BinaryOperator::getOverloadedOperator(Opc); + OverloadedOperatorKind OverOp = BinaryOperator::getOverloadedOperator(Opc); if (Sc && OverOp != OO_None && OverOp != OO_Equal) - S.LookupOverloadedOperatorName(OverOp, Sc, LHS->getType(), - RHS->getType(), Functions); + S.LookupOverloadedOperatorName(OverOp, Sc, LHS->getType(), RHS->getType(), + Functions); // Build the (potentially-overloaded, potentially-dependent) // binary operation. @@ -12497,8 +12646,8 @@ } ExprResult Sema::BuildBinOp(Scope *S, SourceLocation OpLoc, - BinaryOperatorKind Opc, - Expr *LHSExpr, Expr *RHSExpr) { + BinaryOperatorKind Opc, Expr *LHSExpr, + Expr *RHSExpr) { ExprResult LHS, RHS; std::tie(LHS, RHS) = CorrectDelayedTyposInBinOp(*this, Opc, LHSExpr, RHSExpr); if (!LHS.isUsable() || !RHS.isUsable()) @@ -12527,7 +12676,8 @@ // that an overload set can be dependently-typed, but it never // instantiates to having an overloadable type. ExprResult resolvedRHS = CheckPlaceholderExpr(RHSExpr); - if (resolvedRHS.isInvalid()) return ExprError(); + if (resolvedRHS.isInvalid()) + return ExprError(); RHSExpr = resolvedRHS.get(); if (RHSExpr->isTypeDependent() || @@ -12552,13 +12702,14 @@ Diag(OE->getQualifier() ? OE->getQualifierLoc().getBeginLoc() : OE->getNameLoc(), diag::err_template_kw_missing) - << OE->getName().getAsString() << ""; + << OE->getName().getAsString() << ""; return ExprError(); } } ExprResult LHS = CheckPlaceholderExpr(LHSExpr); - if (LHS.isInvalid()) return ExprError(); + if (LHS.isInvalid()) + return ExprError(); LHSExpr = LHS.get(); } @@ -12581,7 +12732,8 @@ return BuildOverloadedBinOp(*this, S, OpLoc, Opc, LHSExpr, RHSExpr); ExprResult resolvedRHS = CheckPlaceholderExpr(RHSExpr); - if (!resolvedRHS.isUsable()) return ExprError(); + if (!resolvedRHS.isUsable()) + return ExprError(); RHSExpr = resolvedRHS.get(); } @@ -12613,8 +12765,7 @@ } ExprResult Sema::CreateBuiltinUnaryOp(SourceLocation OpLoc, - UnaryOperatorKind Opc, - Expr *InputExpr) { + UnaryOperatorKind Opc, Expr *InputExpr) { ExprResult Input = InputExpr; ExprValueKind VK = VK_RValue; ExprObjectKind OK = OK_Ordinary; @@ -12626,10 +12777,12 @@ QualType Ty = InputExpr->getType(); // The only legal unary operation for atomics is '&'. if ((Opc != UO_AddrOf && Ty->isAtomicType()) || - // OpenCL special types - image, sampler, pipe, and blocks are to be used - // only with a builtin functions and therefore should be disallowed here. - (Ty->isImageType() || Ty->isSamplerT() || Ty->isPipeType() - || Ty->isBlockPointerType())) { + // OpenCL special types - image, sampler, pipe, and blocks are to be + // used + // only with a builtin functions and therefore should be disallowed + // here. + (Ty->isImageType() || Ty->isSamplerT() || Ty->isPipeType() || + Ty->isBlockPointerType())) { return ExprError(Diag(OpLoc, diag::err_typecheck_unary_expr) << InputExpr->getType() << Input.get()->getSourceRange()); @@ -12640,12 +12793,10 @@ case UO_PreDec: case UO_PostInc: case UO_PostDec: - resultType = CheckIncrementDecrementOperand(*this, Input.get(), VK, OK, - OpLoc, - Opc == UO_PreInc || - Opc == UO_PostInc, - Opc == UO_PreInc || - Opc == UO_PreDec); + resultType = + CheckIncrementDecrementOperand(*this, Input.get(), VK, OK, OpLoc, + Opc == UO_PreInc || Opc == UO_PostInc, + Opc == UO_PreInc || Opc == UO_PreDec); CanOverflow = isOverflowingIntegerType(Context, resultType); break; case UO_AddrOf: @@ -12654,7 +12805,8 @@ break; case UO_Deref: { Input = DefaultFunctionArrayLvalueConversion(Input.get()); - if (Input.isInvalid()) return ExprError(); + if (Input.isInvalid()) + return ExprError(); resultType = CheckIndirectionOperand(*this, Input.get(), VK, OpLoc); break; } @@ -12663,7 +12815,8 @@ CanOverflow = Opc == UO_Minus && isOverflowingIntegerType(Context, Input.get()->getType()); Input = UsualUnaryConversions(Input.get()); - if (Input.isInvalid()) return ExprError(); + if (Input.isInvalid()) + return ExprError(); // Unary plus and minus require promoting an operand of half vector to a // float vector and truncating the result back to a half vector. For now, we // do this only when HalfArgsAndReturns is set (that is, when the target is @@ -12683,15 +12836,14 @@ // The z vector extensions don't allow + or - with bool vectors. (!Context.getLangOpts().ZVector || resultType->getAs()->getVectorKind() != - VectorType::AltiVecBool)) + VectorType::AltiVecBool)) break; else if (getLangOpts().CPlusPlus && // C++ [expr.unary.op]p6 - Opc == UO_Plus && - resultType->isPointerType()) + Opc == UO_Plus && resultType->isPointerType()) break; return ExprError(Diag(OpLoc, diag::err_typecheck_unary_expr) - << resultType << Input.get()->getSourceRange()); + << resultType << Input.get()->getSourceRange()); case UO_Not: // bitwise complement Input = UsualUnaryConversions(Input.get()); @@ -12714,7 +12866,7 @@ QualType T = resultType->getAs()->getElementType(); if (!T->isIntegerType()) return ExprError(Diag(OpLoc, diag::err_typecheck_unary_expr) - << resultType << Input.get()->getSourceRange()); + << resultType << Input.get()->getSourceRange()); } else { return ExprError(Diag(OpLoc, diag::err_typecheck_unary_expr) << resultType << Input.get()->getSourceRange()); @@ -12724,12 +12876,14 @@ case UO_LNot: // logical negation // Unlike +/-/~, integer promotions aren't done here (C99 6.5.3.3p5). Input = DefaultFunctionArrayLvalueConversion(Input.get()); - if (Input.isInvalid()) return ExprError(); + if (Input.isInvalid()) + return ExprError(); resultType = Input.get()->getType(); // Though we still have to promote half FP to float... if (resultType->isHalfType() && !Context.getLangOpts().NativeHalfType) { - Input = ImpCastExprToType(Input.get(), Context.FloatTy, CK_FloatingCast).get(); + Input = ImpCastExprToType(Input.get(), Context.FloatTy, CK_FloatingCast) + .get(); resultType = Context.FloatTy; } @@ -12767,7 +12921,7 @@ // FIXME: GCC's vector extension permits the usage of '!' with a vector // type in C++. We should allow that here too. return ExprError(Diag(OpLoc, diag::err_typecheck_unary_expr) - << resultType << Input.get()->getSourceRange()); + << resultType << Input.get()->getSourceRange()); } // LNot always has type int. C99 6.5.3.3p5. @@ -12779,7 +12933,8 @@ resultType = CheckRealImagOperand(*this, Input, OpLoc, Opc == UO_Real); // _Real maps ordinary l-values into ordinary l-values. _Imag maps ordinary // complex l-values to ordinary l-values and all other values to r-values. - if (Input.isInvalid()) return ExprError(); + if (Input.isInvalid()) + return ExprError(); if (Opc == UO_Real || Input.get()->getType()->isAnyComplexType()) { if (Input.get()->getValueKind() != VK_RValue && Input.get()->getObjectKind() == OK_Ordinary) @@ -12798,8 +12953,8 @@ // It's unnecessary to represent the pass-through operator co_await in the // AST; just return the input expression instead. assert(!Input.get()->getType()->isDependentType() && - "the co_await expression must be non-dependant before " - "building operator co_await"); + "the co_await expression must be non-dependant before " + "building operator co_await"); return Input; } if (resultType.isNull() || Input.isInvalid()) @@ -12876,15 +13031,15 @@ // & gets special logic for several kinds of placeholder. // The builtin code knows what to do. - if (Opc == UO_AddrOf && - (pty->getKind() == BuiltinType::Overload || - pty->getKind() == BuiltinType::UnknownAny || - pty->getKind() == BuiltinType::BoundMember)) + if (Opc == UO_AddrOf && (pty->getKind() == BuiltinType::Overload || + pty->getKind() == BuiltinType::UnknownAny || + pty->getKind() == BuiltinType::BoundMember)) return CreateBuiltinUnaryOp(OpLoc, Opc, Input); // Anything else needs to be handled now. ExprResult Result = CheckPlaceholderExpr(Input); - if (Result.isInvalid()) return ExprError(); + if (Result.isInvalid()) + return ExprError(); Input = Result.get(); } @@ -12908,8 +13063,8 @@ } // Unary Operators. 'Tok' is the token for the operator. -ExprResult Sema::ActOnUnaryOp(Scope *S, SourceLocation OpLoc, - tok::TokenKind Op, Expr *Input) { +ExprResult Sema::ActOnUnaryOp(Scope *S, SourceLocation OpLoc, tok::TokenKind Op, + Expr *Input) { return BuildUnaryOp(S, OpLoc, ConvertTokenKindToUnaryOpcode(Op), Input); } @@ -12930,7 +13085,8 @@ static Expr *maybeRebuildARCConsumingStmt(Stmt *Statement) { // Should always be wrapped with one of these. ExprWithCleanups *cleanups = dyn_cast(Statement); - if (!cleanups) return nullptr; + if (!cleanups) + return nullptr; ImplicitCastExpr *cast = dyn_cast(cleanups->getSubExpr()); if (!cast || cast->getCastKind() != CK_ARCConsumeObject) @@ -12957,9 +13113,8 @@ PopExpressionEvaluationContext(); } -ExprResult -Sema::ActOnStmtExpr(SourceLocation LPLoc, Stmt *SubStmt, - SourceLocation RPLoc) { // "({..})" +ExprResult Sema::ActOnStmtExpr(SourceLocation LPLoc, Stmt *SubStmt, + SourceLocation RPLoc) { // "({..})" assert(SubStmt && isa(SubStmt) && "Invalid action invocation!"); CompoundStmt *Compound = cast(SubStmt); @@ -13001,8 +13156,8 @@ // initialization will create a produce. In both cases the // result will be +1, and we'll need to balance that out with // a bind. - if (Expr *rebuiltLastStmt - = maybeRebuildARCConsumingStmt(LastExpr.get())) { + if (Expr *rebuiltLastStmt = + maybeRebuildARCConsumingStmt(LastExpr.get())) { LastExpr = rebuiltLastStmt; } else { LastExpr = PerformCopyInitialization( @@ -13044,32 +13199,32 @@ // a struct/union/class. if (!Dependent && !ArgTy->isRecordType()) return ExprError(Diag(BuiltinLoc, diag::err_offsetof_record_type) - << ArgTy << TypeRange); + << ArgTy << TypeRange); // Type must be complete per C99 7.17p3 because a declaring a variable // with an incomplete type would be ill-formed. - if (!Dependent - && RequireCompleteType(BuiltinLoc, ArgTy, - diag::err_offsetof_incomplete_type, TypeRange)) + if (!Dependent && + RequireCompleteType(BuiltinLoc, ArgTy, diag::err_offsetof_incomplete_type, + TypeRange)) return ExprError(); bool DidWarnAboutNonPOD = false; QualType CurrentType = ArgTy; SmallVector Comps; - SmallVector Exprs; + SmallVector Exprs; for (const OffsetOfComponent &OC : Components) { if (OC.isBrackets) { // Offset of an array sub-field. TODO: Should we allow vector elements? if (!CurrentType->isDependentType()) { const ArrayType *AT = Context.getAsArrayType(CurrentType); - if(!AT) + if (!AT) return ExprError(Diag(OC.LocEnd, diag::err_offsetof_array_type) << CurrentType); CurrentType = AT->getElementType(); } else CurrentType = Context.DependentTy; - ExprResult IdxRval = DefaultLvalueConversion(static_cast(OC.U.E)); + ExprResult IdxRval = DefaultLvalueConversion(static_cast(OC.U.E)); if (IdxRval.isInvalid()) return ExprError(); Expr *Idx = IdxRval.get(); @@ -13117,16 +13272,17 @@ // If type is not a standard-layout class (Clause 9), the results are // undefined. if (CXXRecordDecl *CRD = dyn_cast(RD)) { - bool IsSafe = LangOpts.CPlusPlus11? CRD->isStandardLayout() : CRD->isPOD(); - unsigned DiagID = - LangOpts.CPlusPlus11? diag::ext_offsetof_non_standardlayout_type + bool IsSafe = + LangOpts.CPlusPlus11 ? CRD->isStandardLayout() : CRD->isPOD(); + unsigned DiagID = LangOpts.CPlusPlus11 + ? diag::ext_offsetof_non_standardlayout_type : diag::ext_offsetof_non_pod_type; if (!IsSafe && !DidWarnAboutNonPOD && - DiagRuntimeBehavior(BuiltinLoc, nullptr, - PDiag(DiagID) - << SourceRange(Components[0].LocStart, OC.LocEnd) - << CurrentType)) + DiagRuntimeBehavior( + BuiltinLoc, nullptr, + PDiag(DiagID) << SourceRange(Components[0].LocStart, OC.LocEnd) + << CurrentType)) DidWarnAboutNonPOD = true; } @@ -13142,8 +13298,8 @@ if (!MemberDecl) return ExprError(Diag(BuiltinLoc, diag::err_no_member) - << OC.U.IdentInfo << RD << SourceRange(OC.LocStart, - OC.LocEnd)); + << OC.U.IdentInfo << RD + << SourceRange(OC.LocStart, OC.LocEnd)); // C99 7.17p3: // (If the specified member is a bit-field, the behavior is undefined.) @@ -13151,8 +13307,7 @@ // We diagnose this as an error. if (MemberDecl->isBitField()) { Diag(OC.LocEnd, diag::err_offsetof_bitfield) - << MemberDecl->getDeclName() - << SourceRange(BuiltinLoc, RParenLoc); + << MemberDecl->getDeclName() << SourceRange(BuiltinLoc, RParenLoc); Diag(MemberDecl->getLocation(), diag::note_bitfield_decl); return ExprError(); } @@ -13168,8 +13323,7 @@ Paths)) { if (Paths.getDetectedVirtual()) { Diag(OC.LocEnd, diag::err_offsetof_field_of_virtual_base) - << MemberDecl->getDeclName() - << SourceRange(BuiltinLoc, RParenLoc); + << MemberDecl->getDeclName() << SourceRange(BuiltinLoc, RParenLoc); return ExprError(); } @@ -13181,8 +13335,8 @@ if (IndirectMemberDecl) { for (auto *FI : IndirectMemberDecl->chain()) { assert(isa(FI)); - Comps.push_back(OffsetOfNode(OC.LocStart, - cast(FI), OC.LocEnd)); + Comps.push_back( + OffsetOfNode(OC.LocStart, cast(FI), OC.LocEnd)); } } else Comps.push_back(OffsetOfNode(OC.LocStart, MemberDecl, OC.LocEnd)); @@ -13194,8 +13348,7 @@ Comps, Exprs, RParenLoc); } -ExprResult Sema::ActOnBuiltinOffsetOf(Scope *S, - SourceLocation BuiltinLoc, +ExprResult Sema::ActOnBuiltinOffsetOf(Scope *S, SourceLocation BuiltinLoc, SourceLocation TypeLoc, ParsedType ParsedArgTy, ArrayRef Components, @@ -13212,9 +13365,7 @@ return BuildBuiltinOffsetOf(BuiltinLoc, ArgTInfo, Components, RParenLoc); } - -ExprResult Sema::ActOnChooseExpr(SourceLocation BuiltinLoc, - Expr *CondExpr, +ExprResult Sema::ActOnChooseExpr(SourceLocation BuiltinLoc, Expr *CondExpr, Expr *LHSExpr, Expr *RHSExpr, SourceLocation RPLoc) { assert((CondExpr && LHSExpr && RHSExpr) && "Missing type argument(s)"); @@ -13230,9 +13381,9 @@ } else { // The conditional expression is required to be a constant expression. llvm::APSInt condEval(32); - ExprResult CondICE - = VerifyIntegerConstantExpression(CondExpr, &condEval, - diag::err_typecheck_choose_expr_requires_constant, false); + ExprResult CondICE = VerifyIntegerConstantExpression( + CondExpr, &condEval, diag::err_typecheck_choose_expr_requires_constant, + false); if (CondICE.isInvalid()) return ExprError(); CondExpr = CondICE.get(); @@ -13262,9 +13413,8 @@ if (LangOpts.CPlusPlus) { Decl *ManglingContextDecl; - if (MangleNumberingContext *MCtx = - getCurrentMangleNumberContext(Block->getDeclContext(), - ManglingContextDecl)) { + if (MangleNumberingContext *MCtx = getCurrentMangleNumberContext( + Block->getDeclContext(), ManglingContextDecl)) { unsigned ManglingNumber = MCtx->getManglingNumber(Block); Block->setBlockMangling(ManglingNumber, ManglingContextDecl); } @@ -13340,7 +13490,7 @@ const FunctionType *Fn = T->getAs(); QualType RetTy = Fn->getReturnType(); bool isVariadic = - (isa(Fn) && cast(Fn)->isVariadic()); + (isa(Fn) && cast(Fn)->isVariadic()); CurBlock->TheDecl->setIsVariadic(isVariadic); @@ -13355,20 +13505,18 @@ } // Push block parameters from the declarator if we had them. - SmallVector Params; + SmallVector Params; if (ExplicitSignature) { for (unsigned I = 0, E = ExplicitSignature.getNumParams(); I != E; ++I) { ParmVarDecl *Param = ExplicitSignature.getParam(I); - if (Param->getIdentifier() == nullptr && - !Param->isImplicit() && - !Param->isInvalidDecl() && - !getLangOpts().CPlusPlus) + if (Param->getIdentifier() == nullptr && !Param->isImplicit() && + !Param->isInvalidDecl() && !getLangOpts().CPlusPlus) Diag(Param->getLocation(), diag::err_parameter_name_omitted); Params.push_back(Param); } - // Fake up parameter variables if we have a typedef, like - // ^ fntype { ... } + // Fake up parameter variables if we have a typedef, like + // ^ fntype { ... } } else if (const FunctionProtoType *Fn = T->getAs()) { for (const auto &I : Fn->param_types()) { ParmVarDecl *Param = BuildParmVarDeclForTypedef( @@ -13414,8 +13562,8 @@ /// ActOnBlockStmtExpr - This is called when the body of a block statement /// literal was successfully completed. ^(int x){...} -ExprResult Sema::ActOnBlockStmtExpr(SourceLocation CaretLoc, - Stmt *Body, Scope *CurScope) { +ExprResult Sema::ActOnBlockStmtExpr(SourceLocation CaretLoc, Stmt *Body, + Scope *CurScope) { // If blocks are disabled, emit an error. if (!LangOpts.Blocks) Diag(CaretLoc, diag::err_blocks_disable) << LangOpts.OpenCL; @@ -13458,7 +13606,8 @@ const FunctionType *FTy = BSI->FunctionType->getAs(); FunctionType::ExtInfo Ext = FTy->getExtInfo(); - if (NoReturn && !Ext.getNoReturn()) Ext = Ext.withNoReturn(true); + if (NoReturn && !Ext.getNoReturn()) + Ext = Ext.withNoReturn(true); // Turn protoless block types into nullary block types. if (isa(FTy)) { @@ -13466,13 +13615,13 @@ EPI.ExtInfo = Ext; BlockTy = Context.getFunctionType(RetTy, None, EPI); - // Otherwise, if we don't need to change anything about the function type, - // preserve its sugar structure. + // Otherwise, if we don't need to change anything about the function type, + // preserve its sugar structure. } else if (FTy->getReturnType() == RetTy && (!NoReturn || FTy->getNoReturnAttr())) { BlockTy = BSI->FunctionType; - // Otherwise, make the minimal modifications to the function type. + // Otherwise, make the minimal modifications to the function type. } else { const FunctionProtoType *FPT = cast(FTy); FunctionProtoType::ExtProtoInfo EPI = FPT->getExtProtoInfo(); @@ -13481,7 +13630,7 @@ BlockTy = Context.getFunctionType(RetTy, FPT->getParamTypes(), EPI); } - // If we don't have a function type, just build one from nothing. + // If we don't have a function type, just build one from nothing. } else { FunctionProtoType::ExtProtoInfo EPI; EPI.ExtInfo = FunctionType::ExtInfo().withNoReturn(NoReturn); @@ -13492,8 +13641,7 @@ BlockTy = Context.getBlockPointerType(BlockTy); // If needed, diagnose invalid gotos and switches in the block. - if (getCurFunction()->NeedsScopeChecking() && - !PP.isCodeCompletionEnabled()) + if (getCurFunction()->NeedsScopeChecking() && !PP.isCodeCompletionEnabled()) DiagnoseInvalidJumps(cast(Body)); BSI->TheDecl->setBody(cast(Body)); @@ -13543,9 +13691,8 @@ return BuildVAArgExpr(BuiltinLoc, E, TInfo, RPLoc); } -ExprResult Sema::BuildVAArgExpr(SourceLocation BuiltinLoc, - Expr *E, TypeSourceInfo *TInfo, - SourceLocation RPLoc) { +ExprResult Sema::BuildVAArgExpr(SourceLocation BuiltinLoc, Expr *E, + TypeSourceInfo *TInfo, SourceLocation RPLoc) { Expr *OrigExpr = E; bool IsMS = false; @@ -13562,7 +13709,8 @@ // as Microsoft ABI on an actual Microsoft platform, where // __builtin_ms_va_list and __builtin_va_list are the same.) if (!E->isTypeDependent() && Context.getTargetInfo().hasBuiltinMSVaList() && - Context.getTargetInfo().getBuiltinVaListKind() != TargetInfo::CharPtrBuiltinVaList) { + Context.getTargetInfo().getBuiltinVaListKind() != + TargetInfo::CharPtrBuiltinVaList) { QualType MSVaListType = Context.getBuiltinMSVaListType(); if (Context.hasSameType(MSVaListType, E->getType())) { if (CheckForModifiableLvalue(E, BuiltinLoc, *this)) @@ -13615,19 +13763,17 @@ TInfo->getTypeLoc())) return ExprError(); - if (RequireNonAbstractType(TInfo->getTypeLoc().getBeginLoc(), - TInfo->getType(), - diag::err_second_parameter_to_va_arg_abstract, - TInfo->getTypeLoc())) + if (RequireNonAbstractType( + TInfo->getTypeLoc().getBeginLoc(), TInfo->getType(), + diag::err_second_parameter_to_va_arg_abstract, TInfo->getTypeLoc())) return ExprError(); if (!TInfo->getType().isPODType(Context)) { Diag(TInfo->getTypeLoc().getBeginLoc(), TInfo->getType()->isObjCLifetimeType() - ? diag::warn_second_parameter_to_va_arg_ownership_qualified - : diag::warn_second_parameter_to_va_arg_not_pod) - << TInfo->getType() - << TInfo->getTypeLoc().getSourceRange(); + ? diag::warn_second_parameter_to_va_arg_ownership_qualified + : diag::warn_second_parameter_to_va_arg_not_pod) + << TInfo->getType() << TInfo->getTypeLoc().getSourceRange(); } // Check for va_arg where arguments of the given type will be promoted @@ -13641,11 +13787,11 @@ if (TInfo->getType()->isSpecificBuiltinType(BuiltinType::Float)) PromoteType = Context.DoubleTy; if (!PromoteType.isNull()) - DiagRuntimeBehavior(TInfo->getTypeLoc().getBeginLoc(), E, - PDiag(diag::warn_second_parameter_to_va_arg_never_compatible) - << TInfo->getType() - << PromoteType - << TInfo->getTypeLoc().getSourceRange()); + DiagRuntimeBehavior( + TInfo->getTypeLoc().getBeginLoc(), E, + PDiag(diag::warn_second_parameter_to_va_arg_never_compatible) + << TInfo->getType() << PromoteType + << TInfo->getTypeLoc().getSourceRange()); } QualType T = TInfo->getType().getNonLValueExprType(Context); @@ -13725,10 +13871,9 @@ } bool Sema::DiagnoseAssignmentResult(AssignConvertType ConvTy, - SourceLocation Loc, - QualType DstType, QualType SrcType, - Expr *SrcExpr, AssignmentAction Action, - bool *Complained) { + SourceLocation Loc, QualType DstType, + QualType SrcType, Expr *SrcExpr, + AssignmentAction Action, bool *Complained) { if (Complained) *Complained = false; @@ -13745,8 +13890,8 @@ switch (ConvTy) { case Compatible: - DiagnoseAssignmentEnum(DstType, SrcType, SrcExpr); - return false; + DiagnoseAssignmentEnum(DstType, SrcType, SrcExpr); + return false; case PointerToInt: DiagKind = diag::ext_typecheck_convert_pointer_int; @@ -13768,11 +13913,10 @@ DiagKind = diag::ext_typecheck_convert_incompatible_pointer; CheckInferredResultType = DstType->isObjCObjectPointerType() && - SrcType->isObjCObjectPointerType(); + SrcType->isObjCObjectPointerType(); if (Hint.isNull() && !CheckInferredResultType) { ConvHints.tryToFixConversion(SrcExpr, SrcType, DstType, *this); - } - else if (CheckInferredResultType) { + } else if (CheckInferredResultType) { SrcType = SrcType.getUnqualifiedType(); DstType = DstType.getUnqualifiedType(); } @@ -13786,7 +13930,8 @@ break; case IncompatiblePointerDiscardsQualifiers: { // Perform array-to-pointer decay if necessary. - if (SrcType->isArrayType()) SrcType = Context.getArrayDecayedType(SrcType); + if (SrcType->isArrayType()) + SrcType = Context.getArrayDecayedType(SrcType); Qualifiers lhq = SrcType->getPointeeType().getQualifiers(); Qualifiers rhq = DstType->getPointeeType().getQualifiers(); @@ -13829,24 +13974,23 @@ case IncompatibleObjCQualifiedId: { if (SrcType->isObjCQualifiedIdType()) { const ObjCObjectPointerType *srcOPT = - SrcType->getAs(); + SrcType->getAs(); for (auto *srcProto : srcOPT->quals()) { PDecl = srcProto; break; } if (const ObjCInterfaceType *IFaceT = - DstType->getAs()->getInterfaceType()) + DstType->getAs()->getInterfaceType()) IFace = IFaceT->getDecl(); - } - else if (DstType->isObjCQualifiedIdType()) { + } else if (DstType->isObjCQualifiedIdType()) { const ObjCObjectPointerType *dstOPT = - DstType->getAs(); + DstType->getAs(); for (auto *dstProto : dstOPT->quals()) { PDecl = dstProto; break; } if (const ObjCInterfaceType *IFaceT = - SrcType->getAs()->getInterfaceType()) + SrcType->getAs()->getInterfaceType()) IFace = IFaceT->getDecl(); } DiagKind = diag::warn_incompatible_qualified_id; @@ -13908,20 +14052,22 @@ } else { FDiag << Hint; } - if (MayHaveConvFixit) { FDiag << (unsigned) (ConvHints.Kind); } + if (MayHaveConvFixit) { + FDiag << (unsigned)(ConvHints.Kind); + } if (MayHaveFunctionDiff) HandleFunctionTypeMismatch(FDiag, SecondType, FirstType); Diag(Loc, FDiag); - if (DiagKind == diag::warn_incompatible_qualified_id && - PDecl && IFace && !IFace->hasDefinition()) - Diag(IFace->getLocation(), diag::note_incomplete_class_and_qualified_id) + if (DiagKind == diag::warn_incompatible_qualified_id && PDecl && IFace && + !IFace->hasDefinition()) + Diag(IFace->getLocation(), diag::note_incomplete_class_and_qualified_id) << IFace << PDecl; if (SecondType == Context.OverloadTy) - NoteAllOverloadCandidates(OverloadExpr::find(SrcExpr).Expression, - FirstType, /*TakingAddress=*/true); + NoteAllOverloadCandidates(OverloadExpr::find(SrcExpr).Expression, FirstType, + /*TakingAddress=*/true); if (CheckInferredResultType) EmitRelatedResultTypeNote(SrcExpr); @@ -13946,8 +14092,7 @@ return VerifyIntegerConstantExpression(E, Result, Diagnoser); } -ExprResult Sema::VerifyIntegerConstantExpression(Expr *E, - llvm::APSInt *Result, +ExprResult Sema::VerifyIntegerConstantExpression(Expr *E, llvm::APSInt *Result, unsigned DiagID, bool AllowFold) { class IDDiagnoser : public VerifyICEDiagnoser { @@ -13955,7 +14100,7 @@ public: IDDiagnoser(unsigned DiagID) - : VerifyICEDiagnoser(DiagID == 0), DiagID(DiagID) { } + : VerifyICEDiagnoser(DiagID == 0), DiagID(DiagID) {} void diagnoseNotICE(Sema &S, SourceLocation Loc, SourceRange SR) override { S.Diag(Loc, DiagID) << SR; @@ -13970,10 +14115,9 @@ S.Diag(Loc, diag::ext_expr_not_ice) << SR << S.LangOpts.CPlusPlus; } -ExprResult -Sema::VerifyIntegerConstantExpression(Expr *E, llvm::APSInt *Result, - VerifyICEDiagnoser &Diagnoser, - bool AllowFold) { +ExprResult Sema::VerifyIntegerConstantExpression(Expr *E, llvm::APSInt *Result, + VerifyICEDiagnoser &Diagnoser, + bool AllowFold) { SourceLocation DiagLoc = E->getBeginLoc(); if (getLangOpts().CPlusPlus11) { @@ -13986,49 +14130,51 @@ class CXX11ConvertDiagnoser : public ICEConvertDiagnoser { public: CXX11ConvertDiagnoser(bool Silent) - : ICEConvertDiagnoser(/*AllowScopedEnumerations*/false, - Silent, true) {} + : ICEConvertDiagnoser(/*AllowScopedEnumerations*/ false, Silent, + true) {} SemaDiagnosticBuilder diagnoseNotInt(Sema &S, SourceLocation Loc, QualType T) override { return S.Diag(Loc, diag::err_ice_not_integral) << T; } - SemaDiagnosticBuilder diagnoseIncomplete( - Sema &S, SourceLocation Loc, QualType T) override { + SemaDiagnosticBuilder diagnoseIncomplete(Sema &S, SourceLocation Loc, + QualType T) override { return S.Diag(Loc, diag::err_ice_incomplete_type) << T; } - SemaDiagnosticBuilder diagnoseExplicitConv( - Sema &S, SourceLocation Loc, QualType T, QualType ConvTy) override { + SemaDiagnosticBuilder diagnoseExplicitConv(Sema &S, SourceLocation Loc, + QualType T, + QualType ConvTy) override { return S.Diag(Loc, diag::err_ice_explicit_conversion) << T << ConvTy; } - SemaDiagnosticBuilder noteExplicitConv( - Sema &S, CXXConversionDecl *Conv, QualType ConvTy) override { + SemaDiagnosticBuilder noteExplicitConv(Sema &S, CXXConversionDecl *Conv, + QualType ConvTy) override { return S.Diag(Conv->getLocation(), diag::note_ice_conversion_here) - << ConvTy->isEnumeralType() << ConvTy; + << ConvTy->isEnumeralType() << ConvTy; } - SemaDiagnosticBuilder diagnoseAmbiguous( - Sema &S, SourceLocation Loc, QualType T) override { + SemaDiagnosticBuilder diagnoseAmbiguous(Sema &S, SourceLocation Loc, + QualType T) override { return S.Diag(Loc, diag::err_ice_ambiguous_conversion) << T; } - SemaDiagnosticBuilder noteAmbiguous( - Sema &S, CXXConversionDecl *Conv, QualType ConvTy) override { + SemaDiagnosticBuilder noteAmbiguous(Sema &S, CXXConversionDecl *Conv, + QualType ConvTy) override { return S.Diag(Conv->getLocation(), diag::note_ice_conversion_here) - << ConvTy->isEnumeralType() << ConvTy; + << ConvTy->isEnumeralType() << ConvTy; } - SemaDiagnosticBuilder diagnoseConversion( - Sema &S, SourceLocation Loc, QualType T, QualType ConvTy) override { + SemaDiagnosticBuilder diagnoseConversion(Sema &S, SourceLocation Loc, + QualType T, + QualType ConvTy) override { llvm_unreachable("conversion functions are permitted"); } } ConvertDiagnoser(Diagnoser.Suppress); - Converted = PerformContextualImplicitConversion(DiagLoc, E, - ConvertDiagnoser); + Converted = + PerformContextualImplicitConversion(DiagLoc, E, ConvertDiagnoser); if (Converted.isInvalid()) return Converted; E = Converted.get(); @@ -14070,8 +14216,8 @@ // If our only note is the usual "invalid subexpression" note, just point // the caret at its location rather than producing an essentially // redundant note. - if (Notes.size() == 1 && Notes[0].second.getDiagID() == - diag::note_invalid_subexpr_in_const_expr) { + if (Notes.size() == 1 && + Notes[0].second.getDiagID() == diag::note_invalid_subexpr_in_const_expr) { DiagLoc = Notes[0].first; Notes.clear(); } @@ -14096,69 +14242,67 @@ } namespace { - // Handle the case where we conclude a expression which we speculatively - // considered to be unevaluated is actually evaluated. - class TransformToPE : public TreeTransform { - typedef TreeTransform BaseTransform; +// Handle the case where we conclude a expression which we speculatively +// considered to be unevaluated is actually evaluated. +class TransformToPE : public TreeTransform { + typedef TreeTransform BaseTransform; - public: - TransformToPE(Sema &SemaRef) : BaseTransform(SemaRef) { } +public: + TransformToPE(Sema &SemaRef) : BaseTransform(SemaRef) {} - // Make sure we redo semantic analysis - bool AlwaysRebuild() { return true; } + // Make sure we redo semantic analysis + bool AlwaysRebuild() { return true; } - // Make sure we handle LabelStmts correctly. - // FIXME: This does the right thing, but maybe we need a more general - // fix to TreeTransform? - StmtResult TransformLabelStmt(LabelStmt *S) { - S->getDecl()->setStmt(nullptr); - return BaseTransform::TransformLabelStmt(S); - } + // Make sure we handle LabelStmts correctly. + // FIXME: This does the right thing, but maybe we need a more general + // fix to TreeTransform? + StmtResult TransformLabelStmt(LabelStmt *S) { + S->getDecl()->setStmt(nullptr); + return BaseTransform::TransformLabelStmt(S); + } - // We need to special-case DeclRefExprs referring to FieldDecls which - // are not part of a member pointer formation; normal TreeTransforming - // doesn't catch this case because of the way we represent them in the AST. - // FIXME: This is a bit ugly; is it really the best way to handle this - // case? - // - // Error on DeclRefExprs referring to FieldDecls. - ExprResult TransformDeclRefExpr(DeclRefExpr *E) { - if (isa(E->getDecl()) && - !SemaRef.isUnevaluatedContext()) - return SemaRef.Diag(E->getLocation(), - diag::err_invalid_non_static_member_use) - << E->getDecl() << E->getSourceRange(); + // We need to special-case DeclRefExprs referring to FieldDecls which + // are not part of a member pointer formation; normal TreeTransforming + // doesn't catch this case because of the way we represent them in the AST. + // FIXME: This is a bit ugly; is it really the best way to handle this + // case? + // + // Error on DeclRefExprs referring to FieldDecls. + ExprResult TransformDeclRefExpr(DeclRefExpr *E) { + if (isa(E->getDecl()) && !SemaRef.isUnevaluatedContext()) + return SemaRef.Diag(E->getLocation(), + diag::err_invalid_non_static_member_use) + << E->getDecl() << E->getSourceRange(); - return BaseTransform::TransformDeclRefExpr(E); - } + return BaseTransform::TransformDeclRefExpr(E); + } - // Exception: filter out member pointer formation - ExprResult TransformUnaryOperator(UnaryOperator *E) { - if (E->getOpcode() == UO_AddrOf && E->getType()->isMemberPointerType()) - return E; + // Exception: filter out member pointer formation + ExprResult TransformUnaryOperator(UnaryOperator *E) { + if (E->getOpcode() == UO_AddrOf && E->getType()->isMemberPointerType()) + return E; - return BaseTransform::TransformUnaryOperator(E); - } + return BaseTransform::TransformUnaryOperator(E); + } - ExprResult TransformLambdaExpr(LambdaExpr *E) { - // Lambdas never need to be transformed. - return E; - } - }; + ExprResult TransformLambdaExpr(LambdaExpr *E) { + // Lambdas never need to be transformed. + return E; + } +}; } ExprResult Sema::TransformToPotentiallyEvaluated(Expr *E) { assert(isUnevaluatedContext() && "Should only transform unevaluated expressions"); ExprEvalContexts.back().Context = - ExprEvalContexts[ExprEvalContexts.size()-2].Context; + ExprEvalContexts[ExprEvalContexts.size() - 2].Context; if (isUnevaluatedContext()) return E; return TransformToPE(*this).TransformExpr(E); } -void -Sema::PushExpressionEvaluationContext( +void Sema::PushExpressionEvaluationContext( ExpressionEvaluationContext NewContext, Decl *LambdaContextDecl, ExpressionEvaluationContextRecord::ExpressionKind ExprContext) { ExprEvalContexts.emplace_back(NewContext, ExprCleanupObjects.size(), Cleanup, @@ -14168,8 +14312,7 @@ std::swap(MaybeODRUseExprs, ExprEvalContexts.back().SavedMaybeODRUseExprs); } -void -Sema::PushExpressionEvaluationContext( +void Sema::PushExpressionEvaluationContext( ExpressionEvaluationContext NewContext, ReuseLambdaContextDecl_t, ExpressionEvaluationContextRecord::ExpressionKind ExprContext) { Decl *ClosureContextDecl = ExprEvalContexts.back().ManglingContextDecl; @@ -14177,12 +14320,13 @@ } void Sema::PopExpressionEvaluationContext() { - ExpressionEvaluationContextRecord& Rec = ExprEvalContexts.back(); + ExpressionEvaluationContextRecord &Rec = ExprEvalContexts.back(); unsigned NumTypos = Rec.NumTypos; if (!Rec.Lambdas.empty()) { using ExpressionKind = ExpressionEvaluationContextRecord::ExpressionKind; - if (Rec.ExprContext == ExpressionKind::EK_TemplateArgument || Rec.isUnevaluated() || + if (Rec.ExprContext == ExpressionKind::EK_TemplateArgument || + Rec.isUnevaluated() || (Rec.isConstantEvaluated() && !getLangOpts().CPlusPlus17)) { unsigned D; if (Rec.isUnevaluated()) { @@ -14225,7 +14369,7 @@ Cleanup = Rec.ParentCleanup; CleanupVarDeclMarking(); std::swap(MaybeODRUseExprs, Rec.SavedMaybeODRUseExprs); - // Otherwise, merge the contexts together. + // Otherwise, merge the contexts together. } else { Cleanup.mergeFrom(Rec.ParentCleanup); MaybeODRUseExprs.insert(Rec.SavedMaybeODRUseExprs.begin(), @@ -14243,9 +14387,9 @@ } void Sema::DiscardCleanupsInEvaluationContext() { - ExprCleanupObjects.erase( - ExprCleanupObjects.begin() + ExprEvalContexts.back().NumCleanupObjects, - ExprCleanupObjects.end()); + ExprCleanupObjects.erase(ExprCleanupObjects.begin() + + ExprEvalContexts.back().NumCleanupObjects, + ExprCleanupObjects.end()); Cleanup.reset(); MaybeODRUseExprs.clear(); } @@ -14261,23 +14405,23 @@ /// captured by C++'s idea of an "unevaluated context". static bool isEvaluatableContext(Sema &SemaRef) { switch (SemaRef.ExprEvalContexts.back().Context) { - case Sema::ExpressionEvaluationContext::Unevaluated: - case Sema::ExpressionEvaluationContext::UnevaluatedAbstract: - // Expressions in this context are never evaluated. - return false; + case Sema::ExpressionEvaluationContext::Unevaluated: + case Sema::ExpressionEvaluationContext::UnevaluatedAbstract: + // Expressions in this context are never evaluated. + return false; - case Sema::ExpressionEvaluationContext::UnevaluatedList: - case Sema::ExpressionEvaluationContext::ConstantEvaluated: - case Sema::ExpressionEvaluationContext::PotentiallyEvaluated: - case Sema::ExpressionEvaluationContext::DiscardedStatement: - // Expressions in this context could be evaluated. - return true; + case Sema::ExpressionEvaluationContext::UnevaluatedList: + case Sema::ExpressionEvaluationContext::ConstantEvaluated: + case Sema::ExpressionEvaluationContext::PotentiallyEvaluated: + case Sema::ExpressionEvaluationContext::DiscardedStatement: + // Expressions in this context could be evaluated. + return true; - case Sema::ExpressionEvaluationContext::PotentiallyEvaluatedIfUsed: - // Referenced declarations will only be used if the construct in the - // containing expression is used, at which point we'll be given another - // turn to mark them. - return false; + case Sema::ExpressionEvaluationContext::PotentiallyEvaluatedIfUsed: + // Referenced declarations will only be used if the construct in the + // containing expression is used, at which point we'll be given another + // turn to mark them. + return false; } llvm_unreachable("Invalid context"); } @@ -14291,18 +14435,18 @@ return false; switch (SemaRef.ExprEvalContexts.back().Context) { - case Sema::ExpressionEvaluationContext::Unevaluated: - case Sema::ExpressionEvaluationContext::UnevaluatedList: - case Sema::ExpressionEvaluationContext::UnevaluatedAbstract: - case Sema::ExpressionEvaluationContext::DiscardedStatement: - return false; + case Sema::ExpressionEvaluationContext::Unevaluated: + case Sema::ExpressionEvaluationContext::UnevaluatedList: + case Sema::ExpressionEvaluationContext::UnevaluatedAbstract: + case Sema::ExpressionEvaluationContext::DiscardedStatement: + return false; - case Sema::ExpressionEvaluationContext::ConstantEvaluated: - case Sema::ExpressionEvaluationContext::PotentiallyEvaluated: - return true; + case Sema::ExpressionEvaluationContext::ConstantEvaluated: + case Sema::ExpressionEvaluationContext::PotentiallyEvaluated: + return true; - case Sema::ExpressionEvaluationContext::PotentiallyEvaluatedIfUsed: - return false; + case Sema::ExpressionEvaluationContext::PotentiallyEvaluatedIfUsed: + return false; } llvm_unreachable("Invalid context"); } @@ -14422,7 +14566,8 @@ // Recursive functions should be marked when used from another function. // FIXME: Is this really right? - if (CurContext == Func) return; + if (CurContext == Func) + return; // Implicit instantiation of function templates and member functions of // class templates. @@ -14454,8 +14599,8 @@ InstantiateFunctionDefinition(PointOfInstantiation, Func); else { Func->setInstantiationIsPending(true); - PendingInstantiations.push_back(std::make_pair(Func, - PointOfInstantiation)); + PendingInstantiations.push_back( + std::make_pair(Func, PointOfInstantiation)); // Notify the consumer that a function was implicitly instantiated. Consumer.HandleCXXImplicitFunctionInstantiation(Func); } @@ -14468,14 +14613,14 @@ } } - if (!OdrUse) return; + if (!OdrUse) + return; // Keep track of used but undefined functions. if (!Func->isDefined()) { if (mightHaveNonExternalLinkage(Func)) UndefinedButUsed.insert(std::make_pair(Func->getCanonicalDecl(), Loc)); - else if (Func->getMostRecentDecl()->isInlined() && - !LangOpts.GNUInline && + else if (Func->getMostRecentDecl()->isInlined() && !LangOpts.GNUInline && !Func->getMostRecentDecl()->hasAttr()) UndefinedButUsed.insert(std::make_pair(Func->getCanonicalDecl(), Loc)); else if (isExternalWithNoLinkageType(Func)) @@ -14485,16 +14630,15 @@ Func->markUsed(Context); } -static void -diagnoseUncapturableValueReference(Sema &S, SourceLocation loc, - ValueDecl *var, DeclContext *DC) { +static void diagnoseUncapturableValueReference(Sema &S, SourceLocation loc, + ValueDecl *var, + DeclContext *DC) { DeclContext *VarDC = var->getDeclContext(); // If the parameter still belongs to the translation unit, then // we're actually just using one parameter in the declaration of // the next. - if (isa(var) && - isa(VarDC)) + if (isa(var) && isa(VarDC)) return; // For C code, don't diagnose about capture if we're not actually in code @@ -14519,20 +14663,19 @@ } S.Diag(loc, diag::err_reference_to_local_in_enclosing_context) - << var << ValueKind << ContextKind << VarDC; - S.Diag(var->getLocation(), diag::note_entity_declared_at) - << var; + << var << ValueKind << ContextKind << VarDC; + S.Diag(var->getLocation(), diag::note_entity_declared_at) << var; // FIXME: Add additional diagnostic info about class etc. which prevents // capture. } - -static bool isVariableAlreadyCapturedInScopeInfo(CapturingScopeInfo *CSI, VarDecl *Var, - bool &SubCapturesAreNested, - QualType &CaptureType, - QualType &DeclRefType) { - // Check whether we've already captured it. +static bool isVariableAlreadyCapturedInScopeInfo(CapturingScopeInfo *CSI, + VarDecl *Var, + bool &SubCapturesAreNested, + QualType &CaptureType, + QualType &DeclRefType) { + // Check whether we've already captured it. if (CSI->CaptureMap.count(Var)) { // If we found a capture, any subcaptures are nested. SubCapturesAreNested = true; @@ -14559,14 +14702,16 @@ // Only block literals, captured statements, and lambda expressions can // capture; other scopes don't work. -static DeclContext *getParentOfCapturingContextOrNull(DeclContext *DC, VarDecl *Var, - SourceLocation Loc, - const bool Diagnose, Sema &S) { +static DeclContext *getParentOfCapturingContextOrNull(DeclContext *DC, + VarDecl *Var, + SourceLocation Loc, + const bool Diagnose, + Sema &S) { if (isa(DC) || isa(DC) || isLambdaCallOperator(DC)) return getLambdaAwareParentOfDeclContext(DC); else if (Var->hasLocalStorage()) { if (Diagnose) - diagnoseUncapturableValueReference(S, Loc, Var, DC); + diagnoseUncapturableValueReference(S, Loc, Var, DC); } return nullptr; } @@ -14575,8 +14720,8 @@ // certain types of variables (unnamed, variably modified types etc.) // so check for eligibility. static bool isVariableCapturable(CapturingScopeInfo *CSI, VarDecl *Var, - SourceLocation Loc, - const bool Diagnose, Sema &S) { + SourceLocation Loc, const bool Diagnose, + Sema &S) { bool IsBlock = isa(CSI); bool IsLambda = isa(CSI); @@ -14598,7 +14743,7 @@ if (Diagnose) { S.Diag(Loc, diag::err_ref_vm_type); S.Diag(Var->getLocation(), diag::note_previous_decl) - << Var->getDeclName(); + << Var->getDeclName(); } return false; } @@ -14611,9 +14756,9 @@ S.Diag(Loc, diag::err_ref_flexarray_type); else S.Diag(Loc, diag::err_lambda_capture_flexarray_type) + << Var->getDeclName(); + S.Diag(Var->getLocation(), diag::note_previous_decl) << Var->getDeclName(); - S.Diag(Var->getLocation(), diag::note_previous_decl) - << Var->getDeclName(); } return false; } @@ -14624,9 +14769,9 @@ if (HasBlocksAttr && (IsLambda || isa(CSI))) { if (Diagnose) { S.Diag(Loc, diag::err_capture_block_variable) - << Var->getDeclName() << !IsLambda; + << Var->getDeclName() << !IsLambda; S.Diag(Var->getLocation(), diag::note_previous_decl) - << Var->getDeclName(); + << Var->getDeclName(); } return false; } @@ -14643,12 +14788,9 @@ // Returns true if the capture by block was successful. static bool captureInBlock(BlockScopeInfo *BSI, VarDecl *Var, - SourceLocation Loc, - const bool BuildAndDiagnose, - QualType &CaptureType, - QualType &DeclRefType, - const bool Nested, - Sema &S) { + SourceLocation Loc, const bool BuildAndDiagnose, + QualType &CaptureType, QualType &DeclRefType, + const bool Nested, Sema &S) { Expr *CopyExpr = nullptr; bool ByRef = false; @@ -14659,7 +14801,7 @@ if (BuildAndDiagnose) { S.Diag(Loc, diag::err_ref_array_type); S.Diag(Var->getLocation(), diag::note_previous_decl) - << Var->getDeclName(); + << Var->getDeclName(); } return false; } @@ -14667,10 +14809,9 @@ // Forbid the block-capture of autoreleasing variables. if (CaptureType.getObjCLifetime() == Qualifiers::OCL_Autoreleasing) { if (BuildAndDiagnose) { - S.Diag(Loc, diag::err_arc_autoreleasing_capture) - << /*block*/ 0; + S.Diag(Loc, diag::err_arc_autoreleasing_capture) << /*block*/ 0; S.Diag(Var->getLocation(), diag::note_previous_decl) - << Var->getDeclName(); + << Var->getDeclName(); } return false; } @@ -14735,22 +14876,21 @@ // According to the blocks spec, the capture of a variable from // the stack requires a const copy constructor. This is not true // of the copy/move done to move a __block variable to the heap. - Expr *DeclRef = new (S.Context) DeclRefExpr(Var, Nested, - DeclRefType.withConst(), - VK_LValue, Loc); + Expr *DeclRef = new (S.Context) + DeclRefExpr(Var, Nested, DeclRefType.withConst(), VK_LValue, Loc); - ExprResult Result - = S.PerformCopyInitialization( - InitializedEntity::InitializeBlock(Var->getLocation(), - CaptureType, false), - Loc, DeclRef); + ExprResult Result = S.PerformCopyInitialization( + InitializedEntity::InitializeBlock(Var->getLocation(), CaptureType, + false), + Loc, DeclRef); // Build a full-expression copy expression if initialization // succeeded and used a non-trivial constructor. Recover from // errors by pretending that the copy isn't necessary. if (!Result.isInvalid() && - !cast(Result.get())->getConstructor() - ->isTrivial()) { + !cast(Result.get()) + ->getConstructor() + ->isTrivial()) { Result = S.MaybeCreateExprWithCleanups(Result); CopyExpr = Result.get(); } @@ -14760,23 +14900,18 @@ // Actually capture the variable. if (BuildAndDiagnose) - BSI->addCapture(Var, HasBlocksAttr, ByRef, Nested, Loc, - SourceLocation(), CaptureType, CopyExpr); + BSI->addCapture(Var, HasBlocksAttr, ByRef, Nested, Loc, SourceLocation(), + CaptureType, CopyExpr); return true; - } - /// Capture the given variable in the captured region. -static bool captureInCapturedRegion(CapturedRegionScopeInfo *RSI, - VarDecl *Var, - SourceLocation Loc, - const bool BuildAndDiagnose, - QualType &CaptureType, - QualType &DeclRefType, - const bool RefersToCapturedVariable, - Sema &S) { +static bool +captureInCapturedRegion(CapturedRegionScopeInfo *RSI, VarDecl *Var, + SourceLocation Loc, const bool BuildAndDiagnose, + QualType &CaptureType, QualType &DeclRefType, + const bool RefersToCapturedVariable, Sema &S) { // By default, capture variables by reference. bool ByRef = true; // Using an LValue reference type is consistent with Lambdas (see below). @@ -14803,8 +14938,8 @@ // evaluation will be needed. RecordDecl *RD = RSI->TheRecordDecl; - FieldDecl *Field - = FieldDecl::Create(S.Context, RD, Loc, Loc, nullptr, CaptureType, + FieldDecl *Field = + FieldDecl::Create(S.Context, RD, Loc, Loc, nullptr, CaptureType, S.Context.getTrivialTypeSourceInfo(CaptureType, Loc), nullptr, false, ICIS_NoInit); Field->setImplicit(true); @@ -14813,18 +14948,17 @@ if (S.getLangOpts().OpenMP && RSI->CapRegionKind == CR_OpenMP) S.setOpenMPCaptureKind(Field, Var, RSI->OpenMPLevel); - CopyExpr = new (S.Context) DeclRefExpr(Var, RefersToCapturedVariable, - DeclRefType, VK_LValue, Loc); + CopyExpr = new (S.Context) + DeclRefExpr(Var, RefersToCapturedVariable, DeclRefType, VK_LValue, Loc); Var->setReferenced(true); Var->markUsed(S.Context); } // Actually capture the variable. if (BuildAndDiagnose) - RSI->addCapture(Var, /*isBlock*/false, ByRef, RefersToCapturedVariable, Loc, - SourceLocation(), CaptureType, CopyExpr); + RSI->addCapture(Var, /*isBlock*/ false, ByRef, RefersToCapturedVariable, + Loc, SourceLocation(), CaptureType, CopyExpr); - return true; } @@ -14837,8 +14971,8 @@ CXXRecordDecl *Lambda = LSI->Lambda; // Build the non-static data member. - FieldDecl *Field - = FieldDecl::Create(S.Context, Lambda, Loc, Loc, nullptr, FieldType, + FieldDecl *Field = + FieldDecl::Create(S.Context, Lambda, Loc, Loc, nullptr, FieldType, S.Context.getTrivialTypeSourceInfo(FieldType, Loc), nullptr, false, ICIS_NoInit); Field->setImplicit(true); @@ -14847,16 +14981,12 @@ } /// Capture the given variable in the lambda. -static bool captureInLambda(LambdaScopeInfo *LSI, - VarDecl *Var, - SourceLocation Loc, - const bool BuildAndDiagnose, - QualType &CaptureType, - QualType &DeclRefType, +static bool captureInLambda(LambdaScopeInfo *LSI, VarDecl *Var, + SourceLocation Loc, const bool BuildAndDiagnose, + QualType &CaptureType, QualType &DeclRefType, const bool RefersToCapturedVariable, const Sema::TryCaptureKind Kind, - SourceLocation EllipsisLoc, - const bool IsTopScope, + SourceLocation EllipsisLoc, const bool IsTopScope, Sema &S) { // Determine whether we are capturing by reference or by value. @@ -14893,7 +15023,7 @@ // captured entity is a reference to a function, the // corresponding data member is also a reference to a // function. - end note ] - if (const ReferenceType *RefType = CaptureType->getAs()){ + if (const ReferenceType *RefType = CaptureType->getAs()) { if (!RefType->getPointeeType()->isFunctionType()) CaptureType = RefType->getPointeeType(); } @@ -14903,7 +15033,7 @@ if (BuildAndDiagnose) { S.Diag(Loc, diag::err_arc_autoreleasing_capture) << /*lambda*/ 1; S.Diag(Var->getLocation(), diag::note_previous_decl) - << Var->getDeclName(); + << Var->getDeclName(); } return false; } @@ -14961,7 +15091,8 @@ DeclContext *DC = CurContext; const unsigned MaxFunctionScopesIndex = FunctionScopeIndexToStopAt - ? *FunctionScopeIndexToStopAt : FunctionScopes.size() - 1; + ? *FunctionScopeIndexToStopAt + : FunctionScopes.size() - 1; // We need to sync up the Declaration Context with the // FunctionScopeIndexToStopAt if (FunctionScopeIndexToStopAt) { @@ -14972,10 +15103,10 @@ } } - // If the variable is declared in the current context, there is no need to // capture it. - if (VarDC == DC) return true; + if (VarDC == DC) + return true; // Capture global variables if it is required to use private copy of this // variable. @@ -15000,10 +15131,8 @@ do { // Only block literals, captured statements, and lambda expressions can // capture; other scopes don't work. - DeclContext *ParentDC = getParentOfCapturingContextOrNull(DC, Var, - ExprLoc, - BuildAndDiagnose, - *this); + DeclContext *ParentDC = getParentOfCapturingContextOrNull( + DC, Var, ExprLoc, BuildAndDiagnose, *this); // We need to check for the parent *first* because, if we *have* // private-captured a global variable, we need to recursively capture it in // intermediate blocks, lambdas, etc. @@ -15015,10 +15144,9 @@ return true; } - FunctionScopeInfo *FSI = FunctionScopes[FunctionScopesIndex]; + FunctionScopeInfo *FSI = FunctionScopes[FunctionScopesIndex]; CapturingScopeInfo *CSI = cast(FSI); - // Check whether we've already captured it. if (isVariableAlreadyCapturedInScopeInfo(CSI, Var, Nested, CaptureType, DeclRefType)) { @@ -15035,18 +15163,19 @@ if (LSI->ImpCaptureStyle == CapturingScopeInfo::ImpCap_None) { Diag(ExprLoc, diag::err_lambda_impcap) << Var->getDeclName(); Diag(Var->getLocation(), diag::note_previous_decl) - << Var->getDeclName(); + << Var->getDeclName(); Diag(LSI->Lambda->getBeginLoc(), diag::note_lambda_decl); } else diagnoseUncapturableValueReference(*this, ExprLoc, Var, DC); } return true; } - // Certain capturing entities (lambdas, blocks etc.) are not allowed to capture + // Certain capturing entities (lambdas, blocks etc.) are not allowed to + // capture // certain types of variables (unnamed, variably modified types etc.) // so check for eligibility. if (!isVariableCapturable(CSI, Var, ExprLoc, BuildAndDiagnose, *this)) - return true; + return true; // Try to capture variable-length arrays types. if (Var->getType()->isVariablyModifiedType()) { @@ -15088,7 +15217,7 @@ if (BuildAndDiagnose) { Diag(ExprLoc, diag::err_lambda_impcap) << Var->getDeclName(); Diag(Var->getLocation(), diag::note_previous_decl) - << Var->getDeclName(); + << Var->getDeclName(); if (cast(CSI)->Lambda) Diag(cast(CSI)->Lambda->getBeginLoc(), diag::note_lambda_decl); @@ -15117,28 +15246,26 @@ // requirements, and adding captures if requested. // If the variable had already been captured previously, we start capturing // at the lambda nested within that one. - for (unsigned I = ++FunctionScopesIndex, N = MaxFunctionScopesIndex + 1; I != N; - ++I) { + for (unsigned I = ++FunctionScopesIndex, N = MaxFunctionScopesIndex + 1; + I != N; ++I) { CapturingScopeInfo *CSI = cast(FunctionScopes[I]); if (BlockScopeInfo *BSI = dyn_cast(CSI)) { - if (!captureInBlock(BSI, Var, ExprLoc, - BuildAndDiagnose, CaptureType, + if (!captureInBlock(BSI, Var, ExprLoc, BuildAndDiagnose, CaptureType, DeclRefType, Nested, *this)) return true; Nested = true; - } else if (CapturedRegionScopeInfo *RSI = dyn_cast(CSI)) { - if (!captureInCapturedRegion(RSI, Var, ExprLoc, - BuildAndDiagnose, CaptureType, - DeclRefType, Nested, *this)) + } else if (CapturedRegionScopeInfo *RSI = + dyn_cast(CSI)) { + if (!captureInCapturedRegion(RSI, Var, ExprLoc, BuildAndDiagnose, + CaptureType, DeclRefType, Nested, *this)) return true; Nested = true; } else { LambdaScopeInfo *LSI = cast(CSI); - if (!captureInLambda(LSI, Var, ExprLoc, - BuildAndDiagnose, CaptureType, + if (!captureInLambda(LSI, Var, ExprLoc, BuildAndDiagnose, CaptureType, DeclRefType, Nested, Kind, EllipsisLoc, - /*IsTopScope*/I == N - 1, *this)) + /*IsTopScope*/ I == N - 1, *this)) return true; Nested = true; } @@ -15151,8 +15278,8 @@ QualType CaptureType; QualType DeclRefType; return tryCaptureVariable(Var, Loc, Kind, EllipsisLoc, - /*BuildAndDiagnose=*/true, CaptureType, - DeclRefType, nullptr); + /*BuildAndDiagnose=*/true, CaptureType, DeclRefType, + nullptr); } bool Sema::NeedToCaptureVariable(VarDecl *Var, SourceLocation Loc) { @@ -15169,21 +15296,20 @@ // Determine whether we can capture this variable. if (tryCaptureVariable(Var, Loc, TryCapture_Implicit, SourceLocation(), - /*BuildAndDiagnose=*/false, CaptureType, - DeclRefType, nullptr)) + /*BuildAndDiagnose=*/false, CaptureType, DeclRefType, + nullptr)) return QualType(); return DeclRefType; } - - // If either the type of the variable or the initializer is dependent, // return false. Otherwise, determine whether the variable is a constant // expression. Use this if you need to know if a variable that might or // might not be dependent is truly a constant expression. -static inline bool IsVariableNonDependentAndAConstantExpression(VarDecl *Var, - ASTContext &Context) { +static inline bool +IsVariableNonDependentAndAConstantExpression(VarDecl *Var, + ASTContext &Context) { if (Var->getType()->isDependentType()) return false; @@ -15198,7 +15324,6 @@ return IsVariableAConstantExpression(Var, Context); } - void Sema::UpdateMarkingForLValueToRValue(Expr *E) { // Per C++11 [basic.def.odr], a variable is odr-used "unless it is // an object that satisfies the requirements for appearing in a @@ -15259,7 +15384,6 @@ MaybeODRUseExprs.clear(); } - static void DoMarkVarDeclReferenced(Sema &SemaRef, SourceLocation Loc, VarDecl *Var, Expr *E) { assert((!E || isa(E) || isa(E)) && @@ -15308,9 +15432,10 @@ bool InstantiationDependent = false; bool IsNonDependent = - VarSpec ? !TemplateSpecializationType::anyDependentTemplateArguments( - VarSpec->getTemplateArgsInfo(), InstantiationDependent) - : true; + VarSpec + ? !TemplateSpecializationType::anyDependentTemplateArguments( + VarSpec->getTemplateArgsInfo(), InstantiationDependent) + : true; // Do not instantiate specializations that are still type-dependent. if (IsNonDependent) { @@ -15325,8 +15450,8 @@ // and "implicit instantiation of definition requested", so we have // no direct way to avoid enqueueing the pending instantiation // multiple times. - SemaRef.PendingInstantiations - .push_back(std::make_pair(Var, PointOfInstantiation)); + SemaRef.PendingInstantiations.push_back( + std::make_pair(Var, PointOfInstantiation)); } } } @@ -15350,7 +15475,7 @@ } else if (OdrUseContext) { MarkVarDeclODRUsed(Var, Loc, SemaRef, /*MaxFunctionScopeIndex ptr*/ nullptr); - } else if (isOdrUseContext(SemaRef, /*SkipDependentUses*/false)) { + } else if (isOdrUseContext(SemaRef, /*SkipDependentUses*/ false)) { // If this is a dependent context, we don't need to mark variables as // odr-used, but we may still need to track them for lambda capture. // FIXME: Do we also need to do this inside dependent typeid expressions @@ -15387,8 +15512,8 @@ DoMarkVarDeclReferenced(*this, Loc, Var, nullptr); } -static void MarkExprReferenced(Sema &SemaRef, SourceLocation Loc, - Decl *D, Expr *E, bool MightBeOdrUse) { +static void MarkExprReferenced(Sema &SemaRef, SourceLocation Loc, Decl *D, + Expr *E, bool MightBeOdrUse) { if (SemaRef.isInOpenMPDeclareTargetContext()) SemaRef.checkDeclIsAllowedInOpenMPTarget(E, D); @@ -15408,8 +15533,8 @@ if (!MD) return; // Only attempt to devirtualize if this is truly a virtual call. - bool IsVirtualCall = MD->isVirtual() && - ME->performsVirtualDispatch(SemaRef.getLangOpts()); + bool IsVirtualCall = + MD->isVirtual() && ME->performsVirtualDispatch(SemaRef.getLangOpts()); if (!IsVirtualCall) return; @@ -15473,24 +15598,24 @@ } namespace { - // Mark all of the declarations used by a type as referenced. - // FIXME: Not fully implemented yet! We need to have a better understanding - // of when we're entering a context we should not recurse into. - // FIXME: This is and EvaluatedExprMarker are more-or-less equivalent to - // TreeTransforms rebuilding the type in a new context. Rather than - // duplicating the TreeTransform logic, we should consider reusing it here. - // Currently that causes problems when rebuilding LambdaExprs. - class MarkReferencedDecls : public RecursiveASTVisitor { - Sema &S; - SourceLocation Loc; +// Mark all of the declarations used by a type as referenced. +// FIXME: Not fully implemented yet! We need to have a better understanding +// of when we're entering a context we should not recurse into. +// FIXME: This is and EvaluatedExprMarker are more-or-less equivalent to +// TreeTransforms rebuilding the type in a new context. Rather than +// duplicating the TreeTransform logic, we should consider reusing it here. +// Currently that causes problems when rebuilding LambdaExprs. +class MarkReferencedDecls : public RecursiveASTVisitor { + Sema &S; + SourceLocation Loc; - public: - typedef RecursiveASTVisitor Inherited; +public: + typedef RecursiveASTVisitor Inherited; - MarkReferencedDecls(Sema &S, SourceLocation Loc) : S(S), Loc(Loc) { } + MarkReferencedDecls(Sema &S, SourceLocation Loc) : S(S), Loc(Loc) {} - bool TraverseTemplateArgument(const TemplateArgument &Arg); - }; + bool TraverseTemplateArgument(const TemplateArgument &Arg); +}; } bool MarkReferencedDecls::TraverseTemplateArgument( @@ -15516,77 +15641,75 @@ } namespace { - /// Helper class that marks all of the declarations referenced by - /// potentially-evaluated subexpressions as "referenced". - class EvaluatedExprMarker : public EvaluatedExprVisitor { - Sema &S; - bool SkipLocalVariables; +/// Helper class that marks all of the declarations referenced by +/// potentially-evaluated subexpressions as "referenced". +class EvaluatedExprMarker : public EvaluatedExprVisitor { + Sema &S; + bool SkipLocalVariables; - public: - typedef EvaluatedExprVisitor Inherited; +public: + typedef EvaluatedExprVisitor Inherited; - EvaluatedExprMarker(Sema &S, bool SkipLocalVariables) - : Inherited(S.Context), S(S), SkipLocalVariables(SkipLocalVariables) { } + EvaluatedExprMarker(Sema &S, bool SkipLocalVariables) + : Inherited(S.Context), S(S), SkipLocalVariables(SkipLocalVariables) {} - void VisitDeclRefExpr(DeclRefExpr *E) { - // If we were asked not to visit local variables, don't. - if (SkipLocalVariables) { - if (VarDecl *VD = dyn_cast(E->getDecl())) - if (VD->hasLocalStorage()) - return; - } - - S.MarkDeclRefReferenced(E); + void VisitDeclRefExpr(DeclRefExpr *E) { + // If we were asked not to visit local variables, don't. + if (SkipLocalVariables) { + if (VarDecl *VD = dyn_cast(E->getDecl())) + if (VD->hasLocalStorage()) + return; } - void VisitMemberExpr(MemberExpr *E) { - S.MarkMemberReferenced(E); - Inherited::VisitMemberExpr(E); - } + S.MarkDeclRefReferenced(E); + } - void VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { - S.MarkFunctionReferenced( - E->getBeginLoc(), - const_cast(E->getTemporary()->getDestructor())); - Visit(E->getSubExpr()); - } + void VisitMemberExpr(MemberExpr *E) { + S.MarkMemberReferenced(E); + Inherited::VisitMemberExpr(E); + } - void VisitCXXNewExpr(CXXNewExpr *E) { - if (E->getOperatorNew()) - S.MarkFunctionReferenced(E->getBeginLoc(), E->getOperatorNew()); - if (E->getOperatorDelete()) - S.MarkFunctionReferenced(E->getBeginLoc(), E->getOperatorDelete()); - Inherited::VisitCXXNewExpr(E); - } + void VisitCXXBindTemporaryExpr(CXXBindTemporaryExpr *E) { + S.MarkFunctionReferenced( + E->getBeginLoc(), + const_cast(E->getTemporary()->getDestructor())); + Visit(E->getSubExpr()); + } - void VisitCXXDeleteExpr(CXXDeleteExpr *E) { - if (E->getOperatorDelete()) - S.MarkFunctionReferenced(E->getBeginLoc(), E->getOperatorDelete()); - QualType Destroyed = S.Context.getBaseElementType(E->getDestroyedType()); - if (const RecordType *DestroyedRec = Destroyed->getAs()) { - CXXRecordDecl *Record = cast(DestroyedRec->getDecl()); - S.MarkFunctionReferenced(E->getBeginLoc(), S.LookupDestructor(Record)); - } + void VisitCXXNewExpr(CXXNewExpr *E) { + if (E->getOperatorNew()) + S.MarkFunctionReferenced(E->getBeginLoc(), E->getOperatorNew()); + if (E->getOperatorDelete()) + S.MarkFunctionReferenced(E->getBeginLoc(), E->getOperatorDelete()); + Inherited::VisitCXXNewExpr(E); + } - Inherited::VisitCXXDeleteExpr(E); + void VisitCXXDeleteExpr(CXXDeleteExpr *E) { + if (E->getOperatorDelete()) + S.MarkFunctionReferenced(E->getBeginLoc(), E->getOperatorDelete()); + QualType Destroyed = S.Context.getBaseElementType(E->getDestroyedType()); + if (const RecordType *DestroyedRec = Destroyed->getAs()) { + CXXRecordDecl *Record = cast(DestroyedRec->getDecl()); + S.MarkFunctionReferenced(E->getBeginLoc(), S.LookupDestructor(Record)); } - void VisitCXXConstructExpr(CXXConstructExpr *E) { - S.MarkFunctionReferenced(E->getBeginLoc(), E->getConstructor()); - Inherited::VisitCXXConstructExpr(E); - } + Inherited::VisitCXXDeleteExpr(E); + } - void VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) { - Visit(E->getExpr()); - } + void VisitCXXConstructExpr(CXXConstructExpr *E) { + S.MarkFunctionReferenced(E->getBeginLoc(), E->getConstructor()); + Inherited::VisitCXXConstructExpr(E); + } - void VisitImplicitCastExpr(ImplicitCastExpr *E) { - Inherited::VisitImplicitCastExpr(E); + void VisitCXXDefaultArgExpr(CXXDefaultArgExpr *E) { Visit(E->getExpr()); } - if (E->getCastKind() == CK_LValueToRValue) - S.UpdateMarkingForLValueToRValue(E->getSubExpr()); - } - }; + void VisitImplicitCastExpr(ImplicitCastExpr *E) { + Inherited::VisitImplicitCastExpr(E); + + if (E->getCastKind() == CK_LValueToRValue) + S.UpdateMarkingForLValueToRValue(E->getSubExpr()); + } +}; } /// Mark any declarations that appear within this expression or any @@ -15594,8 +15717,7 @@ /// /// \param SkipLocalVariables If true, don't mark local variables as /// 'referenced'. -void Sema::MarkDeclarationsReferencedInExpr(Expr *E, - bool SkipLocalVariables) { +void Sema::MarkDeclarationsReferencedInExpr(Expr *E, bool SkipLocalVariables) { EvaluatedExprMarker(*this, SkipLocalVariables).Visit(E); } @@ -15632,8 +15754,8 @@ case ExpressionEvaluationContext::PotentiallyEvaluated: case ExpressionEvaluationContext::PotentiallyEvaluatedIfUsed: if (Statement && getCurFunctionOrMethodDecl()) { - FunctionScopes.back()->PossiblyUnreachableDiags. - push_back(sema::PossiblyUnreachableDiag(PD, Loc, Statement)); + FunctionScopes.back()->PossiblyUnreachableDiags.push_back( + sema::PossiblyUnreachableDiag(PD, Loc, Statement)); return true; } @@ -15677,17 +15799,17 @@ public: CallReturnIncompleteDiagnoser(FunctionDecl *FD, CallExpr *CE) - : FD(FD), CE(CE) { } + : FD(FD), CE(CE) {} void diagnose(Sema &S, SourceLocation Loc, QualType T) override { if (!FD) { S.Diag(Loc, diag::err_call_incomplete_return) - << T << CE->getSourceRange(); + << T << CE->getSourceRange(); return; } S.Diag(Loc, diag::err_call_function_incomplete_return) - << CE->getSourceRange() << FD->getDeclName() << T; + << CE->getSourceRange() << FD->getDeclName() << T; S.Diag(FD->getLocation(), diag::note_entity_declared_at) << FD->getDeclName(); } @@ -15714,8 +15836,8 @@ IsOrAssign = Op->getOpcode() == BO_OrAssign; // Greylist some idioms by putting them into a warning subcategory. - if (ObjCMessageExpr *ME - = dyn_cast(Op->getRHS()->IgnoreParenCasts())) { + if (ObjCMessageExpr *ME = + dyn_cast(Op->getRHS()->IgnoreParenCasts())) { Selector Sel = ME->getSelector(); // self = [ init...] @@ -15746,15 +15868,15 @@ SourceLocation Open = E->getBeginLoc(); SourceLocation Close = getLocForEndOfToken(E->getSourceRange().getEnd()); Diag(Loc, diag::note_condition_assign_silence) - << FixItHint::CreateInsertion(Open, "(") - << FixItHint::CreateInsertion(Close, ")"); + << FixItHint::CreateInsertion(Open, "(") + << FixItHint::CreateInsertion(Close, ")"); if (IsOrAssign) Diag(Loc, diag::note_condition_or_assign_to_comparison) - << FixItHint::CreateReplacement(Loc, "!="); + << FixItHint::CreateReplacement(Loc, "!="); else Diag(Loc, diag::note_condition_assign_to_comparison) - << FixItHint::CreateReplacement(Loc, "=="); + << FixItHint::CreateReplacement(Loc, "=="); } /// Redundant parentheses over an equality comparison can indicate @@ -15772,17 +15894,17 @@ if (BinaryOperator *opE = dyn_cast(E)) if (opE->getOpcode() == BO_EQ && - opE->getLHS()->IgnoreParenImpCasts()->isModifiableLvalue(Context) - == Expr::MLV_Valid) { + opE->getLHS()->IgnoreParenImpCasts()->isModifiableLvalue(Context) == + Expr::MLV_Valid) { SourceLocation Loc = opE->getOperatorLoc(); Diag(Loc, diag::warn_equality_with_extra_parens) << E->getSourceRange(); SourceRange ParenERange = ParenE->getSourceRange(); Diag(Loc, diag::note_equality_comparison_silence) - << FixItHint::CreateRemoval(ParenERange.getBegin()) - << FixItHint::CreateRemoval(ParenERange.getEnd()); + << FixItHint::CreateRemoval(ParenERange.getBegin()) + << FixItHint::CreateRemoval(ParenERange.getEnd()); Diag(Loc, diag::note_equality_comparison_to_assign) - << FixItHint::CreateReplacement(Loc, "="); + << FixItHint::CreateReplacement(Loc, "="); } } @@ -15793,7 +15915,8 @@ DiagnoseEqualityWithExtraParens(parenE); ExprResult result = CheckPlaceholderExpr(E); - if (result.isInvalid()) return ExprError(); + if (result.isInvalid()) + return ExprError(); E = result.get(); if (!E->isTypeDependent()) { @@ -15808,7 +15931,7 @@ QualType T = E->getType(); if (!T->isScalarType()) { // C99 6.8.4.1p1 Diag(Loc, diag::err_typecheck_statement_requires_scalar) - << T << E->getSourceRange(); + << T << E->getSourceRange(); return ExprError(); } CheckBoolLikeConversion(E, Loc); @@ -15850,190 +15973,182 @@ } namespace { - /// A visitor for rebuilding a call to an __unknown_any expression - /// to have an appropriate type. - struct RebuildUnknownAnyFunction +/// A visitor for rebuilding a call to an __unknown_any expression +/// to have an appropriate type. +struct RebuildUnknownAnyFunction : StmtVisitor { - Sema &S; + Sema &S; - RebuildUnknownAnyFunction(Sema &S) : S(S) {} + RebuildUnknownAnyFunction(Sema &S) : S(S) {} - ExprResult VisitStmt(Stmt *S) { - llvm_unreachable("unexpected statement!"); - } + ExprResult VisitStmt(Stmt *S) { llvm_unreachable("unexpected statement!"); } - ExprResult VisitExpr(Expr *E) { - S.Diag(E->getExprLoc(), diag::err_unsupported_unknown_any_call) + ExprResult VisitExpr(Expr *E) { + S.Diag(E->getExprLoc(), diag::err_unsupported_unknown_any_call) << E->getSourceRange(); + return ExprError(); + } + + /// Rebuild an expression which simply semantically wraps another + /// expression which it shares the type and value kind of. + template ExprResult rebuildSugarExpr(T *E) { + ExprResult SubResult = Visit(E->getSubExpr()); + if (SubResult.isInvalid()) return ExprError(); - } - /// Rebuild an expression which simply semantically wraps another - /// expression which it shares the type and value kind of. - template ExprResult rebuildSugarExpr(T *E) { - ExprResult SubResult = Visit(E->getSubExpr()); - if (SubResult.isInvalid()) return ExprError(); + Expr *SubExpr = SubResult.get(); + E->setSubExpr(SubExpr); + E->setType(SubExpr->getType()); + E->setValueKind(SubExpr->getValueKind()); + assert(E->getObjectKind() == OK_Ordinary); + return E; + } - Expr *SubExpr = SubResult.get(); - E->setSubExpr(SubExpr); - E->setType(SubExpr->getType()); - E->setValueKind(SubExpr->getValueKind()); - assert(E->getObjectKind() == OK_Ordinary); - return E; - } + ExprResult VisitParenExpr(ParenExpr *E) { return rebuildSugarExpr(E); } - ExprResult VisitParenExpr(ParenExpr *E) { - return rebuildSugarExpr(E); - } + ExprResult VisitUnaryExtension(UnaryOperator *E) { + return rebuildSugarExpr(E); + } - ExprResult VisitUnaryExtension(UnaryOperator *E) { - return rebuildSugarExpr(E); - } + ExprResult VisitUnaryAddrOf(UnaryOperator *E) { + ExprResult SubResult = Visit(E->getSubExpr()); + if (SubResult.isInvalid()) + return ExprError(); - ExprResult VisitUnaryAddrOf(UnaryOperator *E) { - ExprResult SubResult = Visit(E->getSubExpr()); - if (SubResult.isInvalid()) return ExprError(); + Expr *SubExpr = SubResult.get(); + E->setSubExpr(SubExpr); + E->setType(S.Context.getPointerType(SubExpr->getType())); + assert(E->getValueKind() == VK_RValue); + assert(E->getObjectKind() == OK_Ordinary); + return E; + } - Expr *SubExpr = SubResult.get(); - E->setSubExpr(SubExpr); - E->setType(S.Context.getPointerType(SubExpr->getType())); - assert(E->getValueKind() == VK_RValue); - assert(E->getObjectKind() == OK_Ordinary); - return E; - } + ExprResult resolveDecl(Expr *E, ValueDecl *VD) { + if (!isa(VD)) + return VisitExpr(E); - ExprResult resolveDecl(Expr *E, ValueDecl *VD) { - if (!isa(VD)) return VisitExpr(E); + E->setType(VD->getType()); - E->setType(VD->getType()); + assert(E->getValueKind() == VK_RValue); + if (S.getLangOpts().CPlusPlus && + !(isa(VD) && cast(VD)->isInstance())) + E->setValueKind(VK_LValue); - assert(E->getValueKind() == VK_RValue); - if (S.getLangOpts().CPlusPlus && - !(isa(VD) && - cast(VD)->isInstance())) - E->setValueKind(VK_LValue); + return E; + } - return E; - } + ExprResult VisitMemberExpr(MemberExpr *E) { + return resolveDecl(E, E->getMemberDecl()); + } - ExprResult VisitMemberExpr(MemberExpr *E) { - return resolveDecl(E, E->getMemberDecl()); - } - - ExprResult VisitDeclRefExpr(DeclRefExpr *E) { - return resolveDecl(E, E->getDecl()); - } - }; + ExprResult VisitDeclRefExpr(DeclRefExpr *E) { + return resolveDecl(E, E->getDecl()); + } +}; } /// Given a function expression of unknown-any type, try to rebuild it /// to have a function type. static ExprResult rebuildUnknownAnyFunction(Sema &S, Expr *FunctionExpr) { ExprResult Result = RebuildUnknownAnyFunction(S).Visit(FunctionExpr); - if (Result.isInvalid()) return ExprError(); + if (Result.isInvalid()) + return ExprError(); return S.DefaultFunctionArrayConversion(Result.get()); } namespace { - /// A visitor for rebuilding an expression of type __unknown_anytype - /// into one which resolves the type directly on the referring - /// expression. Strict preservation of the original source - /// structure is not a goal. - struct RebuildUnknownAnyExpr - : StmtVisitor { +/// A visitor for rebuilding an expression of type __unknown_anytype +/// into one which resolves the type directly on the referring +/// expression. Strict preservation of the original source +/// structure is not a goal. +struct RebuildUnknownAnyExpr : StmtVisitor { - Sema &S; + Sema &S; - /// The current destination type. - QualType DestType; + /// The current destination type. + QualType DestType; - RebuildUnknownAnyExpr(Sema &S, QualType CastType) + RebuildUnknownAnyExpr(Sema &S, QualType CastType) : S(S), DestType(CastType) {} - ExprResult VisitStmt(Stmt *S) { - llvm_unreachable("unexpected statement!"); - } + ExprResult VisitStmt(Stmt *S) { llvm_unreachable("unexpected statement!"); } - ExprResult VisitExpr(Expr *E) { - S.Diag(E->getExprLoc(), diag::err_unsupported_unknown_any_expr) + ExprResult VisitExpr(Expr *E) { + S.Diag(E->getExprLoc(), diag::err_unsupported_unknown_any_expr) << E->getSourceRange(); - return ExprError(); - } + return ExprError(); + } - ExprResult VisitCallExpr(CallExpr *E); - ExprResult VisitObjCMessageExpr(ObjCMessageExpr *E); + ExprResult VisitCallExpr(CallExpr *E); + ExprResult VisitObjCMessageExpr(ObjCMessageExpr *E); - /// Rebuild an expression which simply semantically wraps another - /// expression which it shares the type and value kind of. - template ExprResult rebuildSugarExpr(T *E) { - ExprResult SubResult = Visit(E->getSubExpr()); - if (SubResult.isInvalid()) return ExprError(); - Expr *SubExpr = SubResult.get(); - E->setSubExpr(SubExpr); - E->setType(SubExpr->getType()); - E->setValueKind(SubExpr->getValueKind()); - assert(E->getObjectKind() == OK_Ordinary); - return E; - } + /// Rebuild an expression which simply semantically wraps another + /// expression which it shares the type and value kind of. + template ExprResult rebuildSugarExpr(T *E) { + ExprResult SubResult = Visit(E->getSubExpr()); + if (SubResult.isInvalid()) + return ExprError(); + Expr *SubExpr = SubResult.get(); + E->setSubExpr(SubExpr); + E->setType(SubExpr->getType()); + E->setValueKind(SubExpr->getValueKind()); + assert(E->getObjectKind() == OK_Ordinary); + return E; + } - ExprResult VisitParenExpr(ParenExpr *E) { - return rebuildSugarExpr(E); - } + ExprResult VisitParenExpr(ParenExpr *E) { return rebuildSugarExpr(E); } - ExprResult VisitUnaryExtension(UnaryOperator *E) { - return rebuildSugarExpr(E); - } + ExprResult VisitUnaryExtension(UnaryOperator *E) { + return rebuildSugarExpr(E); + } - ExprResult VisitUnaryAddrOf(UnaryOperator *E) { - const PointerType *Ptr = DestType->getAs(); - if (!Ptr) { - S.Diag(E->getOperatorLoc(), diag::err_unknown_any_addrof) + ExprResult VisitUnaryAddrOf(UnaryOperator *E) { + const PointerType *Ptr = DestType->getAs(); + if (!Ptr) { + S.Diag(E->getOperatorLoc(), diag::err_unknown_any_addrof) << E->getSourceRange(); - return ExprError(); - } + return ExprError(); + } - if (isa(E->getSubExpr())) { - S.Diag(E->getOperatorLoc(), diag::err_unknown_any_addrof_call) + if (isa(E->getSubExpr())) { + S.Diag(E->getOperatorLoc(), diag::err_unknown_any_addrof_call) << E->getSourceRange(); - return ExprError(); - } + return ExprError(); + } - assert(E->getValueKind() == VK_RValue); - assert(E->getObjectKind() == OK_Ordinary); - E->setType(DestType); + assert(E->getValueKind() == VK_RValue); + assert(E->getObjectKind() == OK_Ordinary); + E->setType(DestType); - // Build the sub-expression as if it were an object of the pointee type. - DestType = Ptr->getPointeeType(); - ExprResult SubResult = Visit(E->getSubExpr()); - if (SubResult.isInvalid()) return ExprError(); - E->setSubExpr(SubResult.get()); - return E; - } + // Build the sub-expression as if it were an object of the pointee type. + DestType = Ptr->getPointeeType(); + ExprResult SubResult = Visit(E->getSubExpr()); + if (SubResult.isInvalid()) + return ExprError(); + E->setSubExpr(SubResult.get()); + return E; + } - ExprResult VisitImplicitCastExpr(ImplicitCastExpr *E); + ExprResult VisitImplicitCastExpr(ImplicitCastExpr *E); - ExprResult resolveDecl(Expr *E, ValueDecl *VD); + ExprResult resolveDecl(Expr *E, ValueDecl *VD); - ExprResult VisitMemberExpr(MemberExpr *E) { - return resolveDecl(E, E->getMemberDecl()); - } + ExprResult VisitMemberExpr(MemberExpr *E) { + return resolveDecl(E, E->getMemberDecl()); + } - ExprResult VisitDeclRefExpr(DeclRefExpr *E) { - return resolveDecl(E, E->getDecl()); - } - }; + ExprResult VisitDeclRefExpr(DeclRefExpr *E) { + return resolveDecl(E, E->getDecl()); + } +}; } /// Rebuilds a call expression which yielded __unknown_anytype. ExprResult RebuildUnknownAnyExpr::VisitCallExpr(CallExpr *E) { Expr *CalleeExpr = E->getCallee(); - enum FnKind { - FK_MemberFunction, - FK_FunctionPointer, - FK_BlockPointer - }; + enum FnKind { FK_MemberFunction, FK_FunctionPointer, FK_BlockPointer }; FnKind Kind; QualType CalleeType = CalleeExpr->getType(); @@ -16056,8 +16171,7 @@ if (Kind == FK_BlockPointer) diagID = diag::err_block_returning_array_function; - S.Diag(E->getExprLoc(), diagID) - << DestType->isFunctionType() << DestType; + S.Diag(E->getExprLoc(), diagID) << DestType->isFunctionType() << DestType; return ExprError(); } @@ -16107,8 +16221,7 @@ DestType = S.Context.getFunctionType(DestType, ParamTypes, Proto->getExtProtoInfo()); } else { - DestType = S.Context.getFunctionNoProtoType(DestType, - FnType->getExtInfo()); + DestType = S.Context.getFunctionNoProtoType(DestType, FnType->getExtInfo()); } // Rebuild the appropriate pointer-to-function type. @@ -16128,7 +16241,8 @@ // Finally, we can recurse. ExprResult CalleeResult = Visit(CalleeExpr); - if (!CalleeResult.isUsable()) return ExprError(); + if (!CalleeResult.isUsable()) + return ExprError(); E->setCallee(CalleeResult.get()); // Bind a temporary if necessary. @@ -16139,7 +16253,7 @@ // Verify that this is a legal result type of a call. if (DestType->isArrayType() || DestType->isFunctionType()) { S.Diag(E->getExprLoc(), diag::err_func_returning_array_function) - << DestType->isFunctionType() << DestType; + << DestType->isFunctionType() << DestType; return ExprError(); } @@ -16168,7 +16282,8 @@ DestType = DestType->castAs()->getPointeeType(); ExprResult Result = Visit(E->getSubExpr()); - if (!Result.isUsable()) return ExprError(); + if (!Result.isUsable()) + return ExprError(); E->setSubExpr(Result.get()); return E; @@ -16184,7 +16299,8 @@ DestType = S.Context.getLValueReferenceType(DestType); ExprResult Result = Visit(E->getSubExpr()); - if (!Result.isUsable()) return ExprError(); + if (!Result.isUsable()) + return ExprError(); E->setSubExpr(Result.get()); return E; @@ -16204,14 +16320,15 @@ if (const PointerType *Ptr = Type->getAs()) { DestType = Ptr->getPointeeType(); ExprResult Result = resolveDecl(E, VD); - if (Result.isInvalid()) return ExprError(); - return S.ImpCastExprToType(Result.get(), Type, - CK_FunctionToPointerDecay, VK_RValue); + if (Result.isInvalid()) + return ExprError(); + return S.ImpCastExprToType(Result.get(), Type, CK_FunctionToPointerDecay, + VK_RValue); } if (!Type->isFunctionType()) { S.Diag(E->getExprLoc(), diag::err_unknown_any_function) - << VD << E->getSourceRange(); + << VD << E->getSourceRange(); return ExprError(); } if (const FunctionProtoType *FT = Type->getAs()) { @@ -16220,25 +16337,24 @@ // type. See the lengthy commentary in that routine. QualType FDT = FD->getType(); const FunctionType *FnType = FDT->castAs(); - const FunctionProtoType *Proto = dyn_cast_or_null(FnType); + const FunctionProtoType *Proto = + dyn_cast_or_null(FnType); DeclRefExpr *DRE = dyn_cast(E); - if (DRE && Proto && Proto->getParamTypes().empty() && Proto->isVariadic()) { + if (DRE && Proto && Proto->getParamTypes().empty() && + Proto->isVariadic()) { SourceLocation Loc = FD->getLocation(); - FunctionDecl *NewFD = FunctionDecl::Create(FD->getASTContext(), - FD->getDeclContext(), - Loc, Loc, FD->getNameInfo().getName(), - DestType, FD->getTypeSourceInfo(), - SC_None, false/*isInlineSpecified*/, - FD->hasPrototype(), - false/*isConstexprSpecified*/); + FunctionDecl *NewFD = FunctionDecl::Create( + FD->getASTContext(), FD->getDeclContext(), Loc, Loc, + FD->getNameInfo().getName(), DestType, FD->getTypeSourceInfo(), + SC_None, false /*isInlineSpecified*/, FD->hasPrototype(), + false /*isConstexprSpecified*/); if (FD->getQualifier()) NewFD->setQualifierInfo(FD->getQualifierLoc()); - SmallVector Params; + SmallVector Params; for (const auto &AI : FT->param_types()) { - ParmVarDecl *Param = - S.BuildParmVarDeclForTypedef(FD, Loc, AI); + ParmVarDecl *Param = S.BuildParmVarDeclForTypedef(FD, Loc, AI); Param->setScopeInfo(0, Params.size()); Params.push_back(Param); } @@ -16258,20 +16374,20 @@ if (!S.getLangOpts().CPlusPlus) ValueKind = VK_RValue; - // - variables + // - variables } else if (isa(VD)) { if (const ReferenceType *RefTy = Type->getAs()) { Type = RefTy->getPointeeType(); } else if (Type->isFunctionType()) { S.Diag(E->getExprLoc(), diag::err_unknown_any_var_function_type) - << VD << E->getSourceRange(); + << VD << E->getSourceRange(); return ExprError(); } - // - nothing else + // - nothing else } else { S.Diag(E->getExprLoc(), diag::err_unsupported_unknown_any_decl) - << VD << E->getSourceRange(); + << VD << E->getSourceRange(); return ExprError(); } @@ -16296,7 +16412,8 @@ // Rewrite the casted expression from scratch. ExprResult result = RebuildUnknownAnyExpr(*this, CastType).Visit(CastExpr); - if (!result.isUsable()) return ExprError(); + if (!result.isUsable()) + return ExprError(); CastExpr = result.get(); VK = CastExpr->getValueKind(); @@ -16309,14 +16426,15 @@ return RebuildUnknownAnyExpr(*this, ToType).Visit(E); } -ExprResult Sema::checkUnknownAnyArg(SourceLocation callLoc, - Expr *arg, QualType ¶mType) { +ExprResult Sema::checkUnknownAnyArg(SourceLocation callLoc, Expr *arg, + QualType ¶mType) { // If the syntactic form of the argument is not an explicit cast of // any sort, just do default argument promotion. ExplicitCastExpr *castArg = dyn_cast(arg->IgnoreParens()); if (!castArg) { ExprResult result = DefaultArgumentPromotion(arg); - if (result.isInvalid()) return ExprError(); + if (result.isInvalid()) + return ExprError(); paramType = result.get()->getType(); return result; } @@ -16327,8 +16445,8 @@ // Copy-initialize a parameter of that type. InitializedEntity entity = - InitializedEntity::InitializeParameter(Context, paramType, - /*consumed*/ false); + InitializedEntity::InitializeParameter(Context, paramType, + /*consumed*/ false); return PerformCopyInitialization(entity, callLoc, arg); } @@ -16359,13 +16477,13 @@ d = msg->getMethodDecl(); if (!d) { S.Diag(loc, diag::err_uncasted_send_to_unknown_any_method) - << static_cast(msg->isClassMessage()) << msg->getSelector() - << orig->getSourceRange(); + << static_cast(msg->isClassMessage()) << msg->getSelector() + << orig->getSourceRange(); return ExprError(); } } else { S.Diag(E->getExprLoc(), diag::err_unsupported_unknown_any_expr) - << E->getSourceRange(); + << E->getSourceRange(); return ExprError(); } @@ -16383,12 +16501,14 @@ // doesn't handle dependent types properly, so make sure any TypoExprs have // been dealt with before checking the operands. ExprResult Result = CorrectDelayedTyposInExpr(E); - if (!Result.isUsable()) return ExprError(); + if (!Result.isUsable()) + return ExprError(); E = Result.get(); } const BuiltinType *placeholderType = E->getType()->getAsPlaceholderType(); - if (!placeholderType) return E; + if (!placeholderType) + return E; switch (placeholderType->getKind()) { @@ -16452,7 +16572,8 @@ auto *FD = cast(DRE->getDecl()); if (FD->getBuiltinID() == Builtin::BI__noop) { E = ImpCastExprToType(E, Context.getPointerType(FD->getType()), - CK_BuiltinFnToFnPtr).get(); + CK_BuiltinFnToFnPtr) + .get(); return new (Context) CallExpr(Context, E, None, Context.IntTy, VK_RValue, SourceLocation()); } @@ -16467,8 +16588,8 @@ Diag(E->getBeginLoc(), diag::err_omp_array_section_use); return ExprError(); - // Everything else should be impossible. -#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ +// Everything else should be impossible. +#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ case BuiltinType::Id: #include "clang/Basic/OpenCLImageTypes.def" #define BUILTIN_TYPE(Id, SingletonId) case BuiltinType::Id: @@ -16489,8 +16610,8 @@ } /// ActOnObjCBoolLiteral - Parse {__objc_yes,__objc_no} literals. -ExprResult -Sema::ActOnObjCBoolLiteral(SourceLocation OpLoc, tok::TokenKind Kind) { +ExprResult Sema::ActOnObjCBoolLiteral(SourceLocation OpLoc, + tok::TokenKind Kind) { assert((Kind == tok::kw___objc_yes || Kind == tok::kw___objc_no) && "Unknown Objective-C Boolean value!"); QualType BoolT = Context.ObjCBuiltinBoolTy; Index: test/Sema/div-sizeof-ptr.c =================================================================== --- test/Sema/div-sizeof-ptr.c +++ test/Sema/div-sizeof-ptr.c @@ -0,0 +1,12 @@ +// RUN: %clang_cc1 %s -verify -Wsizeof-pointer-div -fsyntax-only + +void test(int *p, int **q) { + int a = sizeof(p) / sizeof(*p); // expected-warning {{division produces the incorrect number of array elements}} + int b = sizeof p / sizeof *p; // expected-warning {{division produces the incorrect number of array elements}} + int c = sizeof(*q) / sizeof(**q); // expected-warning {{division produces the incorrect number of array elements}} + int d = sizeof(p) / sizeof(int); // expected-warning {{division produces the incorrect number of array elements}} + + int e = sizeof(int *) / sizeof(int); + int f = sizeof(p) / sizeof(p); + int g = sizeof(*q) / sizeof(q); +}