diff options
author | dim <dim@FreeBSD.org> | 2014-03-21 17:53:59 +0000 |
---|---|---|
committer | dim <dim@FreeBSD.org> | 2014-03-21 17:53:59 +0000 |
commit | 9cedb8bb69b89b0f0c529937247a6a80cabdbaec (patch) | |
tree | c978f0e9ec1ab92dc8123783f30b08a7fd1e2a39 /contrib/llvm/tools/clang/lib/Sema/SemaCast.cpp | |
parent | 03fdc2934eb61c44c049a02b02aa974cfdd8a0eb (diff) | |
download | FreeBSD-src-9cedb8bb69b89b0f0c529937247a6a80cabdbaec.zip FreeBSD-src-9cedb8bb69b89b0f0c529937247a6a80cabdbaec.tar.gz |
MFC 261991:
Upgrade our copy of llvm/clang to 3.4 release. This version supports
all of the features in the current working draft of the upcoming C++
standard, provisionally named C++1y.
The code generator's performance is greatly increased, and the loop
auto-vectorizer is now enabled at -Os and -O2 in addition to -O3. The
PowerPC backend has made several major improvements to code generation
quality and compile time, and the X86, SPARC, ARM32, Aarch64 and SystemZ
backends have all seen major feature work.
Release notes for llvm and clang can be found here:
<http://llvm.org/releases/3.4/docs/ReleaseNotes.html>
<http://llvm.org/releases/3.4/tools/clang/docs/ReleaseNotes.html>
MFC 262121 (by emaste):
Update lldb for clang/llvm 3.4 import
This commit largely restores the lldb source to the upstream r196259
snapshot with the addition of threaded inferior support and a few bug
fixes.
Specific upstream lldb revisions restored include:
SVN git
181387 779e6ac
181703 7bef4e2
182099 b31044e
182650 f2dcf35
182683 0d91b80
183862 15c1774
183929 99447a6
184177 0b2934b
184948 4dc3761
184954 007e7bc
186990 eebd175
Sponsored by: DARPA, AFRL
MFC 262186 (by emaste):
Fix mismerge in r262121
A break statement was lost in the merge. The error had no functional
impact, but restore it to reduce the diff against upstream.
MFC 262303:
Pull in r197521 from upstream clang trunk (by rdivacky):
Use the integrated assembler by default on FreeBSD/ppc and ppc64.
Requested by: jhibbits
MFC 262611:
Pull in r196874 from upstream llvm trunk:
Fix a crash that occurs when PWD is invalid.
MCJIT needs to be able to run in hostile environments, even when PWD
is invalid. There's no need to crash MCJIT in this case.
The obvious fix is to simply leave MCContext's CompilationDir empty
when PWD can't be determined. This way, MCJIT clients,
and other clients that link with LLVM don't need a valid working directory.
If we do want to guarantee valid CompilationDir, that should be done
only for clients of getCompilationDir(). This is as simple as checking
for an empty string.
The only current use of getCompilationDir is EmitGenDwarfInfo, which
won't conceivably run with an invalid working dir. However, in the
purely hypothetically and untestable case that this happens, the
AT_comp_dir will be omitted from the compilation_unit DIE.
This should help fix assertions occurring with ports-mgmt/tinderbox,
when it is using jails, and sometimes invalidates clang's current
working directory.
Reported by: decke
MFC 262809:
Pull in r203007 from upstream clang trunk:
Don't produce an alias between destructors with different calling conventions.
Fixes pr19007.
(Please note that is an LLVM PR identifier, not a FreeBSD one.)
This should fix Firefox and/or libxul crashes (due to problems with
regparm/stdcall calling conventions) on i386.
Reported by: multiple users on freebsd-current
PR: bin/187103
MFC 263048:
Repair recognition of "CC" as an alias for the C++ compiler, since it
was silently broken by upstream for a Windows-specific use-case.
Apparently some versions of CMake still rely on this archaic feature...
Reported by: rakuco
MFC 263049:
Garbage collect the old way of adding the libstdc++ include directories
in clang's InitHeaderSearch.cpp. This has been superseded by David
Chisnall's commit in r255321.
Moreover, if libc++ is used, the libstdc++ include directories should
not be in the search path at all. These directories are now only used
if you pass -stdlib=libstdc++.
Diffstat (limited to 'contrib/llvm/tools/clang/lib/Sema/SemaCast.cpp')
-rw-r--r-- | contrib/llvm/tools/clang/lib/Sema/SemaCast.cpp | 142 |
1 files changed, 105 insertions, 37 deletions
diff --git a/contrib/llvm/tools/clang/lib/Sema/SemaCast.cpp b/contrib/llvm/tools/clang/lib/Sema/SemaCast.cpp index eb11a57..ba00b71 100644 --- a/contrib/llvm/tools/clang/lib/Sema/SemaCast.cpp +++ b/contrib/llvm/tools/clang/lib/Sema/SemaCast.cpp @@ -200,8 +200,9 @@ static TryCastResult TryStaticCast(Sema &Self, ExprResult &SrcExpr, unsigned &msg, CastKind &Kind, CXXCastPath &BasePath, bool ListInitialization); -static TryCastResult TryConstCast(Sema &Self, Expr *SrcExpr, QualType DestType, - bool CStyle, unsigned &msg); +static TryCastResult TryConstCast(Sema &Self, ExprResult &SrcExpr, + QualType DestType, bool CStyle, + unsigned &msg); static TryCastResult TryReinterpretCast(Sema &Self, ExprResult &SrcExpr, QualType DestType, bool CStyle, const SourceRange &OpRange, @@ -242,7 +243,9 @@ Sema::BuildCXXNamedCast(SourceLocation OpLoc, tok::TokenKind Kind, // If the type is dependent, we won't do the semantic analysis now. // FIXME: should we check this in a more fine-grained manner? - bool TypeDependent = DestType->isDependentType() || Ex.get()->isTypeDependent(); + bool TypeDependent = DestType->isDependentType() || + Ex.get()->isTypeDependent() || + Ex.get()->isValueDependent(); CastOperation Op(*this, DestType, E); Op.OpRange = SourceRange(OpLoc, Parens.getEnd()); @@ -383,11 +386,6 @@ static bool tryDiagnoseOverloadedCast(Sema &S, CastType CT, static void diagnoseBadCast(Sema &S, unsigned msg, CastType castType, SourceRange opRange, Expr *src, QualType destType, bool listInitialization) { - if (src->getType() == S.Context.BoundMemberTy) { - (void) S.CheckPlaceholderExpr(src); // will always fail - return; - } - if (msg == diag::err_bad_cxx_cast_generic && tryDiagnoseOverloadedCast(S, castType, opRange, src, destType, listInitialization)) @@ -515,8 +513,8 @@ CastsAwayConstness(Sema &Self, QualType SrcType, QualType DestType, QualType SrcConstruct = Self.Context.VoidTy; QualType DestConstruct = Self.Context.VoidTy; ASTContext &Context = Self.Context; - for (SmallVector<Qualifiers, 8>::reverse_iterator i1 = cv1.rbegin(), - i2 = cv2.rbegin(); + for (SmallVectorImpl<Qualifiers>::reverse_iterator i1 = cv1.rbegin(), + i2 = cv2.rbegin(); i1 != cv1.rend(); ++i1, ++i2) { SrcConstruct = Context.getPointerType(Context.getQualifiedType(SrcConstruct, *i1)); @@ -558,6 +556,7 @@ void CastOperation::CheckDynamicCast() { } else { Self.Diag(OpRange.getBegin(), diag::err_bad_dynamic_cast_not_ref_or_ptr) << this->DestType << DestRange; + SrcExpr = ExprError(); return; } @@ -567,11 +566,14 @@ void CastOperation::CheckDynamicCast() { } else if (DestRecord) { if (Self.RequireCompleteType(OpRange.getBegin(), DestPointee, diag::err_bad_dynamic_cast_incomplete, - DestRange)) + DestRange)) { + SrcExpr = ExprError(); return; + } } else { Self.Diag(OpRange.getBegin(), diag::err_bad_dynamic_cast_not_class) << DestPointee.getUnqualifiedType() << DestRange; + SrcExpr = ExprError(); return; } @@ -587,6 +589,7 @@ void CastOperation::CheckDynamicCast() { } else { Self.Diag(OpRange.getBegin(), diag::err_bad_dynamic_cast_not_ptr) << OrigSrcType << SrcExpr.get()->getSourceRange(); + SrcExpr = ExprError(); return; } } else if (DestReference->isLValueReferenceType()) { @@ -603,11 +606,14 @@ void CastOperation::CheckDynamicCast() { if (SrcRecord) { if (Self.RequireCompleteType(OpRange.getBegin(), SrcPointee, diag::err_bad_dynamic_cast_incomplete, - SrcExpr.get())) + SrcExpr.get())) { + SrcExpr = ExprError(); return; + } } else { Self.Diag(OpRange.getBegin(), diag::err_bad_dynamic_cast_not_class) << SrcPointee.getUnqualifiedType() << SrcExpr.get()->getSourceRange(); + SrcExpr = ExprError(); return; } @@ -621,6 +627,7 @@ void CastOperation::CheckDynamicCast() { if (!DestPointee.isAtLeastAsQualifiedAs(SrcPointee)) { Self.Diag(OpRange.getBegin(), diag::err_bad_cxx_cast_qualifiers_away) << CT_Dynamic << OrigSrcType << this->DestType << OpRange; + SrcExpr = ExprError(); return; } @@ -636,8 +643,10 @@ void CastOperation::CheckDynamicCast() { if (DestRecord && Self.IsDerivedFrom(SrcPointee, DestPointee)) { if (Self.CheckDerivedToBaseConversion(SrcPointee, DestPointee, OpRange.getBegin(), OpRange, - &BasePath)) - return; + &BasePath)) { + SrcExpr = ExprError(); + return; + } Kind = CK_DerivedToBase; @@ -655,10 +664,20 @@ void CastOperation::CheckDynamicCast() { if (!cast<CXXRecordDecl>(SrcDecl)->isPolymorphic()) { Self.Diag(OpRange.getBegin(), diag::err_bad_dynamic_cast_not_polymorphic) << SrcPointee.getUnqualifiedType() << SrcExpr.get()->getSourceRange(); + SrcExpr = ExprError(); } Self.MarkVTableUsed(OpRange.getBegin(), cast<CXXRecordDecl>(SrcRecord->getDecl())); + // dynamic_cast is not available with -fno-rtti. + // As an exception, dynamic_cast to void* is available because it doesn't + // use RTTI. + if (!Self.getLangOpts().RTTI && !DestPointee->isVoidType()) { + Self.Diag(OpRange.getBegin(), diag::err_no_dynamic_cast_with_fno_rtti); + SrcExpr = ExprError(); + return; + } + // Done. Everything else is run-time checks. Kind = CK_Dynamic; } @@ -677,10 +696,12 @@ void CastOperation::CheckConstCast() { return; unsigned msg = diag::err_bad_cxx_cast_generic; - if (TryConstCast(Self, SrcExpr.get(), DestType, /*CStyle*/false, msg) != TC_Success - && msg != 0) + if (TryConstCast(Self, SrcExpr, DestType, /*CStyle*/false, msg) != TC_Success + && msg != 0) { Self.Diag(OpRange.getBegin(), msg) << CT_Const << SrcExpr.get()->getType() << DestType << OpRange; + SrcExpr = ExprError(); + } } /// Check that a reinterpret_cast\<DestType\>(SrcExpr) is not used as upcast @@ -758,6 +779,7 @@ static void DiagnoseReinterpretUpDownCast(Sema &Self, const Expr *SrcExpr, VirtualBase = VirtualBase && IsVirtual; } + (void) NonZeroOffset; // Silence set but not used warning. assert((VirtualBase || NonZeroOffset) && "Should have returned if has non-virtual base with zero offset"); @@ -768,10 +790,10 @@ static void DiagnoseReinterpretUpDownCast(Sema &Self, const Expr *SrcExpr, SourceLocation BeginLoc = OpRange.getBegin(); Self.Diag(BeginLoc, diag::warn_reinterpret_different_from_static) - << DerivedType << BaseType << !VirtualBase << ReinterpretKind + << DerivedType << BaseType << !VirtualBase << int(ReinterpretKind) << OpRange; Self.Diag(BeginLoc, diag::note_reinterpret_updowncast_use_static) - << ReinterpretKind + << int(ReinterpretKind) << FixItHint::CreateReplacement(BeginLoc, "static_cast"); } @@ -807,6 +829,7 @@ void CastOperation::CheckReinterpretCast() { diagnoseBadCast(Self, msg, CT_Reinterpret, OpRange, SrcExpr.get(), DestType, /*listInitialization=*/false); } + SrcExpr = ExprError(); } else if (tcr == TC_Success) { if (Self.getLangOpts().ObjCAutoRefCount) checkObjCARCConversion(Sema::CCK_OtherCast); @@ -868,6 +891,7 @@ void CastOperation::CheckStaticCast() { diagnoseBadCast(Self, msg, CT_Static, OpRange, SrcExpr.get(), DestType, /*listInitialization=*/false); } + SrcExpr = ExprError(); } else if (tcr == TC_Success) { if (Kind == CK_BitCast) checkCastAlign(); @@ -1447,12 +1471,26 @@ TryStaticImplicitCast(Sema &Self, ExprResult &SrcExpr, QualType DestType, /// TryConstCast - See if a const_cast from source to destination is allowed, /// and perform it if it is. -static TryCastResult TryConstCast(Sema &Self, Expr *SrcExpr, QualType DestType, - bool CStyle, unsigned &msg) { +static TryCastResult TryConstCast(Sema &Self, ExprResult &SrcExpr, + QualType DestType, bool CStyle, + unsigned &msg) { DestType = Self.Context.getCanonicalType(DestType); - QualType SrcType = SrcExpr->getType(); + QualType SrcType = SrcExpr.get()->getType(); + bool NeedToMaterializeTemporary = false; + if (const ReferenceType *DestTypeTmp =DestType->getAs<ReferenceType>()) { - if (isa<LValueReferenceType>(DestTypeTmp) && !SrcExpr->isLValue()) { + // C++11 5.2.11p4: + // if a pointer to T1 can be explicitly converted to the type "pointer to + // T2" using a const_cast, then the following conversions can also be + // made: + // -- an lvalue of type T1 can be explicitly converted to an lvalue of + // type T2 using the cast const_cast<T2&>; + // -- a glvalue of type T1 can be explicitly converted to an xvalue of + // type T2 using the cast const_cast<T2&&>; and + // -- if T1 is a class type, a prvalue of type T1 can be explicitly + // converted to an xvalue of type T2 using the cast const_cast<T2&&>. + + if (isa<LValueReferenceType>(DestTypeTmp) && !SrcExpr.get()->isLValue()) { // Cannot const_cast non-lvalue to lvalue reference type. But if this // is C-style, static_cast might find a way, so we simply suggest a // message and tell the parent to keep searching. @@ -1460,18 +1498,29 @@ static TryCastResult TryConstCast(Sema &Self, Expr *SrcExpr, QualType DestType, return TC_NotApplicable; } + if (isa<RValueReferenceType>(DestTypeTmp) && SrcExpr.get()->isRValue()) { + if (!SrcType->isRecordType()) { + // Cannot const_cast non-class prvalue to rvalue reference type. But if + // this is C-style, static_cast can do this. + msg = diag::err_bad_cxx_cast_rvalue; + return TC_NotApplicable; + } + + // Materialize the class prvalue so that the const_cast can bind a + // reference to it. + NeedToMaterializeTemporary = true; + } + // It's not completely clear under the standard whether we can // const_cast bit-field gl-values. Doing so would not be // intrinsically complicated, but for now, we say no for // consistency with other compilers and await the word of the // committee. - if (SrcExpr->refersToBitField()) { + if (SrcExpr.get()->refersToBitField()) { msg = diag::err_bad_cxx_cast_bitfield; return TC_NotApplicable; } - // C++ 5.2.11p4: An lvalue of type T1 can be [cast] to an lvalue of type T2 - // [...] if a pointer to T1 can be [cast] to the type pointer to T2. DestType = Self.Context.getPointerType(DestTypeTmp->getPointeeType()); SrcType = Self.Context.getPointerType(SrcType); } @@ -1525,6 +1574,13 @@ static TryCastResult TryConstCast(Sema &Self, Expr *SrcExpr, QualType DestType, if (SrcType != DestType) return TC_NotApplicable; + if (NeedToMaterializeTemporary) + // This is a const_cast from a class prvalue to an rvalue reference type. + // Materialize a temporary to store the result of the conversion. + SrcExpr = new (Self.Context) MaterializeTemporaryExpr( + SrcType, SrcExpr.take(), /*IsLValueReference*/ false, + /*ExtendingDecl*/ 0); + return TC_Success; } @@ -1614,8 +1670,18 @@ static void checkIntToPointerCast(bool CStyle, SourceLocation Loc, && !SrcType->isBooleanType() && !SrcType->isEnumeralType() && !SrcExpr->isIntegerConstantExpr(Self.Context) - && Self.Context.getTypeSize(DestType) > Self.Context.getTypeSize(SrcType)) - Self.Diag(Loc, diag::warn_int_to_pointer_cast) << SrcType << DestType; + && Self.Context.getTypeSize(DestType) > + Self.Context.getTypeSize(SrcType)) { + // Separate between casts to void* and non-void* pointers. + // Some APIs use (abuse) void* for something like a user context, + // and often that value is an integer even if it isn't a pointer itself. + // Having a separate warning flag allows users to control the warning + // for their workflow. + unsigned Diag = DestType->isVoidPointerType() ? + diag::warn_int_to_void_pointer_cast + : diag::warn_int_to_pointer_cast; + Self.Diag(Loc, Diag) << SrcType << DestType; + } } static TryCastResult TryReinterpretCast(Sema &Self, ExprResult &SrcExpr, @@ -1803,10 +1869,12 @@ static TryCastResult TryReinterpretCast(Sema &Self, ExprResult &SrcExpr, assert(srcIsPtr && "One type must be a pointer"); // C++ 5.2.10p4: A pointer can be explicitly converted to any integral // type large enough to hold it; except in Microsoft mode, where the - // integral type size doesn't matter. + // integral type size doesn't matter (except we don't allow bool). + bool MicrosoftException = Self.getLangOpts().MicrosoftExt && + !DestType->isBooleanType(); if ((Self.Context.getTypeSize(SrcType) > Self.Context.getTypeSize(DestType)) && - !Self.getLangOpts().MicrosoftExt) { + !MicrosoftException) { msg = diag::err_bad_reinterpret_cast_small_int; return TC_Failed; } @@ -1940,14 +2008,12 @@ void CastOperation::CheckCXXCStyleCast(bool FunctionalStyle, } SrcExpr = Self.IgnoredValueConversions(SrcExpr.take()); - if (SrcExpr.isInvalid()) - return; - return; } // If the type is dependent, we won't do any other semantic analysis now. - if (DestType->isDependentType() || SrcExpr.get()->isTypeDependent()) { + if (DestType->isDependentType() || SrcExpr.get()->isTypeDependent() || + SrcExpr.get()->isValueDependent()) { assert(Kind == CK_Dependent); return; } @@ -1980,8 +2046,10 @@ void CastOperation::CheckCXXCStyleCast(bool FunctionalStyle, // even if a cast resulting from that interpretation is ill-formed. // In plain language, this means trying a const_cast ... unsigned msg = diag::err_bad_cxx_cast_generic; - TryCastResult tcr = TryConstCast(Self, SrcExpr.get(), DestType, + TryCastResult tcr = TryConstCast(Self, SrcExpr, DestType, /*CStyle*/true, msg); + if (SrcExpr.isInvalid()) + return; if (tcr == TC_Success) Kind = CK_NoOp; @@ -2298,9 +2366,9 @@ ExprResult Sema::BuildCXXFunctionalCastExpr(TypeSourceInfo *CastTypeInfo, return ExprError(); if (CXXConstructExpr *ConstructExpr = dyn_cast<CXXConstructExpr>(Op.SrcExpr.get())) - ConstructExpr->setParenRange(SourceRange(LPLoc, RPLoc)); + ConstructExpr->setParenOrBraceRange(SourceRange(LPLoc, RPLoc)); return Op.complete(CXXFunctionalCastExpr::Create(Context, Op.ResultType, - Op.ValueKind, CastTypeInfo, Op.DestRange.getBegin(), - Op.Kind, Op.SrcExpr.take(), &Op.BasePath, RPLoc)); + Op.ValueKind, CastTypeInfo, Op.Kind, + Op.SrcExpr.take(), &Op.BasePath, LPLoc, RPLoc)); } |