Please use GitHub pull requests for new patches. Avoid migrating existing patches. Phabricator shutdown timeline
Changeset View
Changeset View
Standalone View
Standalone View
lib/Sema/SemaCast.cpp
Show First 20 Lines • Show All 250 Lines • ▼ Show 20 Lines | Sema::BuildCXXNamedCast(SourceLocation OpLoc, tok::TokenKind Kind, | ||||
switch (Kind) { | switch (Kind) { | ||||
default: llvm_unreachable("Unknown C++ cast!"); | default: llvm_unreachable("Unknown C++ cast!"); | ||||
case tok::kw_const_cast: | case tok::kw_const_cast: | ||||
if (!TypeDependent) { | if (!TypeDependent) { | ||||
Op.CheckConstCast(); | Op.CheckConstCast(); | ||||
if (Op.SrcExpr.isInvalid()) | if (Op.SrcExpr.isInvalid()) | ||||
return ExprError(); | return ExprError(); | ||||
DiscardMisalignedMemberAddress(DestType.getTypePtr(), E); | |||||
} | } | ||||
rsmith: More generally, I think we should discard it if the destination of the cast is a suitably… | |||||
return Op.complete(CXXConstCastExpr::Create(Context, Op.ResultType, | return Op.complete(CXXConstCastExpr::Create(Context, Op.ResultType, | ||||
Op.ValueKind, Op.SrcExpr.get(), DestTInfo, | Op.ValueKind, Op.SrcExpr.get(), DestTInfo, | ||||
OpLoc, Parens.getEnd(), | OpLoc, Parens.getEnd(), | ||||
AngleBrackets)); | AngleBrackets)); | ||||
case tok::kw_dynamic_cast: { | case tok::kw_dynamic_cast: { | ||||
if (!TypeDependent) { | if (!TypeDependent) { | ||||
Op.CheckDynamicCast(); | Op.CheckDynamicCast(); | ||||
if (Op.SrcExpr.isInvalid()) | if (Op.SrcExpr.isInvalid()) | ||||
return ExprError(); | return ExprError(); | ||||
} | } | ||||
return Op.complete(CXXDynamicCastExpr::Create(Context, Op.ResultType, | return Op.complete(CXXDynamicCastExpr::Create(Context, Op.ResultType, | ||||
Op.ValueKind, Op.Kind, Op.SrcExpr.get(), | Op.ValueKind, Op.Kind, Op.SrcExpr.get(), | ||||
&Op.BasePath, DestTInfo, | &Op.BasePath, DestTInfo, | ||||
OpLoc, Parens.getEnd(), | OpLoc, Parens.getEnd(), | ||||
AngleBrackets)); | AngleBrackets)); | ||||
} | } | ||||
case tok::kw_reinterpret_cast: { | case tok::kw_reinterpret_cast: { | ||||
if (!TypeDependent) { | if (!TypeDependent) { | ||||
Op.CheckReinterpretCast(); | Op.CheckReinterpretCast(); | ||||
if (Op.SrcExpr.isInvalid()) | if (Op.SrcExpr.isInvalid()) | ||||
return ExprError(); | return ExprError(); | ||||
DiscardMisalignedMemberAddress(DestType.getTypePtr(), E); | |||||
} | } | ||||
return Op.complete(CXXReinterpretCastExpr::Create(Context, Op.ResultType, | return Op.complete(CXXReinterpretCastExpr::Create(Context, Op.ResultType, | ||||
Op.ValueKind, Op.Kind, Op.SrcExpr.get(), | Op.ValueKind, Op.Kind, Op.SrcExpr.get(), | ||||
nullptr, DestTInfo, OpLoc, | nullptr, DestTInfo, OpLoc, | ||||
Parens.getEnd(), | Parens.getEnd(), | ||||
AngleBrackets)); | AngleBrackets)); | ||||
} | } | ||||
case tok::kw_static_cast: { | case tok::kw_static_cast: { | ||||
if (!TypeDependent) { | if (!TypeDependent) { | ||||
Op.CheckStaticCast(); | Op.CheckStaticCast(); | ||||
if (Op.SrcExpr.isInvalid()) | if (Op.SrcExpr.isInvalid()) | ||||
return ExprError(); | return ExprError(); | ||||
DiscardMisalignedMemberAddress(DestType.getTypePtr(), E); | |||||
} | } | ||||
return Op.complete(CXXStaticCastExpr::Create(Context, Op.ResultType, | return Op.complete(CXXStaticCastExpr::Create(Context, Op.ResultType, | ||||
Op.ValueKind, Op.Kind, Op.SrcExpr.get(), | Op.ValueKind, Op.Kind, Op.SrcExpr.get(), | ||||
&Op.BasePath, DestTInfo, | &Op.BasePath, DestTInfo, | ||||
OpLoc, Parens.getEnd(), | OpLoc, Parens.getEnd(), | ||||
AngleBrackets)); | AngleBrackets)); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 2,340 Lines • Show Last 20 Lines |
More generally, I think we should discard it if the destination of the cast is a suitably-aligned pointer type. (For instance, casting to char* should be OK, and casting an attribute((packed,aligned(2))) to a 2-byte-aligned pointer type should be OK.)