forked from OSchip/llvm-project
Remove creation of out-of-bounds value of enumeration type (resulting in UB).
Also remove unnecessary initialization of out-parameters with this value, so that MSan is able to catch errors appropriately. llvm-svn: 320212
This commit is contained in:
parent
a5370fb82c
commit
354abec3e6
|
@ -2742,7 +2742,6 @@ protected:
|
|||
ty->containsUnexpandedParameterPack()) ||
|
||||
(op && op->containsUnexpandedParameterPack()))),
|
||||
Op(op) {
|
||||
assert(kind != CK_Invalid && "creating cast with invalid cast kind");
|
||||
CastExprBits.Kind = kind;
|
||||
setBasePathSize(BasePathSize);
|
||||
assert(CastConsistency());
|
||||
|
|
|
@ -23,8 +23,6 @@ enum CastKind {
|
|||
#include "clang/AST/OperationKinds.def"
|
||||
};
|
||||
|
||||
static const CastKind CK_Invalid = static_cast<CastKind>(-1);
|
||||
|
||||
enum BinaryOperatorKind {
|
||||
#define BINARY_OPERATION(Name, Spelling) BO_##Name,
|
||||
#include "clang/AST/OperationKinds.def"
|
||||
|
|
|
@ -122,21 +122,20 @@ template <> struct ArgTypeTraits<unsigned> {
|
|||
|
||||
template <> struct ArgTypeTraits<attr::Kind> {
|
||||
private:
|
||||
static attr::Kind getAttrKind(llvm::StringRef AttrKind) {
|
||||
return llvm::StringSwitch<attr::Kind>(AttrKind)
|
||||
static Optional<attr::Kind> getAttrKind(llvm::StringRef AttrKind) {
|
||||
return llvm::StringSwitch<Optional<attr::Kind>>(AttrKind)
|
||||
#define ATTR(X) .Case("attr::" #X, attr:: X)
|
||||
#include "clang/Basic/AttrList.inc"
|
||||
.Default(attr::Kind(-1));
|
||||
.Default(llvm::None);
|
||||
}
|
||||
|
||||
public:
|
||||
static bool is(const VariantValue &Value) {
|
||||
return Value.isString() &&
|
||||
getAttrKind(Value.getString()) != attr::Kind(-1);
|
||||
return Value.isString() && getAttrKind(Value.getString());
|
||||
}
|
||||
|
||||
static attr::Kind get(const VariantValue &Value) {
|
||||
return getAttrKind(Value.getString());
|
||||
return *getAttrKind(Value.getString());
|
||||
}
|
||||
|
||||
static ArgKind getKind() {
|
||||
|
@ -146,21 +145,20 @@ public:
|
|||
|
||||
template <> struct ArgTypeTraits<CastKind> {
|
||||
private:
|
||||
static CastKind getCastKind(llvm::StringRef AttrKind) {
|
||||
return llvm::StringSwitch<CastKind>(AttrKind)
|
||||
static Optional<CastKind> getCastKind(llvm::StringRef AttrKind) {
|
||||
return llvm::StringSwitch<Optional<CastKind>>(AttrKind)
|
||||
#define CAST_OPERATION(Name) .Case( #Name, CK_##Name)
|
||||
#include "clang/AST/OperationKinds.def"
|
||||
.Default(CK_Invalid);
|
||||
.Default(llvm::None);
|
||||
}
|
||||
|
||||
public:
|
||||
static bool is(const VariantValue &Value) {
|
||||
return Value.isString() &&
|
||||
getCastKind(Value.getString()) != CK_Invalid;
|
||||
return Value.isString() && getCastKind(Value.getString());
|
||||
}
|
||||
|
||||
static CastKind get(const VariantValue &Value) {
|
||||
return getCastKind(Value.getString());
|
||||
return *getCastKind(Value.getString());
|
||||
}
|
||||
|
||||
static ArgKind getKind() {
|
||||
|
|
|
@ -529,7 +529,7 @@ CastKind Sema::ScalarTypeToBooleanCastKind(QualType ScalarTy) {
|
|||
case Type::STK_IntegralComplex: return CK_IntegralComplexToBoolean;
|
||||
case Type::STK_FloatingComplex: return CK_FloatingComplexToBoolean;
|
||||
}
|
||||
return CK_Invalid;
|
||||
llvm_unreachable("unknown scalar type kind");
|
||||
}
|
||||
|
||||
/// \brief Used to prune the decls of Sema's UnusedFileScopedDecls vector.
|
||||
|
|
|
@ -7511,7 +7511,7 @@ Sema::CheckAssignmentConstraints(SourceLocation Loc,
|
|||
// usually happen on valid code.
|
||||
OpaqueValueExpr RHSExpr(Loc, RHSType, VK_RValue);
|
||||
ExprResult RHSPtr = &RHSExpr;
|
||||
CastKind K = CK_Invalid;
|
||||
CastKind K;
|
||||
|
||||
return CheckAssignmentConstraints(LHSType, RHSPtr, K, /*ConvertRHS=*/false);
|
||||
}
|
||||
|
@ -7903,7 +7903,7 @@ Sema::CheckTransparentUnionArgumentConstraints(QualType ArgType,
|
|||
}
|
||||
}
|
||||
|
||||
CastKind Kind = CK_Invalid;
|
||||
CastKind Kind;
|
||||
if (CheckAssignmentConstraints(it->getType(), RHS, Kind)
|
||||
== Compatible) {
|
||||
RHS = ImpCastExprToType(RHS.get(), it->getType(), Kind);
|
||||
|
@ -8019,7 +8019,7 @@ Sema::CheckSingleAssignmentConstraints(QualType LHSType, ExprResult &CallerRHS,
|
|||
}
|
||||
}
|
||||
|
||||
CastKind Kind = CK_Invalid;
|
||||
CastKind Kind;
|
||||
Sema::AssignConvertType result =
|
||||
CheckAssignmentConstraints(LHSType, RHS, Kind, ConvertRHS);
|
||||
|
||||
|
@ -8114,7 +8114,7 @@ static bool tryVectorConvertAndSplat(Sema &S, ExprResult *scalar,
|
|||
unsigned &DiagID) {
|
||||
// The conversion to apply to the scalar before splatting it,
|
||||
// if necessary.
|
||||
CastKind scalarCast = CK_Invalid;
|
||||
CastKind scalarCast = CK_NoOp;
|
||||
|
||||
if (vectorEltTy->isIntegralType(S.Context)) {
|
||||
if (S.getLangOpts().OpenCL && (scalarTy->isRealFloatingType() ||
|
||||
|
@ -8145,7 +8145,7 @@ static bool tryVectorConvertAndSplat(Sema &S, ExprResult *scalar,
|
|||
|
||||
// Adjust scalar if desired.
|
||||
if (scalar) {
|
||||
if (scalarCast != CK_Invalid)
|
||||
if (scalarCast != CK_NoOp)
|
||||
*scalar = S.ImpCastExprToType(scalar->get(), vectorEltTy, scalarCast);
|
||||
*scalar = S.ImpCastExprToType(scalar->get(), vectorTy, CK_VectorSplat);
|
||||
}
|
||||
|
|
|
@ -3840,7 +3840,7 @@ Sema::PerformImplicitConversion(Expr *From, QualType ToType,
|
|||
<< From->getSourceRange();
|
||||
}
|
||||
|
||||
CastKind Kind = CK_Invalid;
|
||||
CastKind Kind;
|
||||
CXXCastPath BasePath;
|
||||
if (CheckPointerConversion(From, ToType, Kind, BasePath, CStyle))
|
||||
return ExprError();
|
||||
|
@ -3860,7 +3860,7 @@ Sema::PerformImplicitConversion(Expr *From, QualType ToType,
|
|||
}
|
||||
|
||||
case ICK_Pointer_Member: {
|
||||
CastKind Kind = CK_Invalid;
|
||||
CastKind Kind;
|
||||
CXXCastPath BasePath;
|
||||
if (CheckMemberPointerConversion(From, ToType, Kind, BasePath, CStyle))
|
||||
return ExprError();
|
||||
|
|
Loading…
Reference in New Issue