diff options
| author | Joey Gouly <joey.gouly@arm.com> | 2013-06-06 13:48:00 +0000 |
|---|---|---|
| committer | Joey Gouly <joey.gouly@arm.com> | 2013-06-06 13:48:00 +0000 |
| commit | 1ba2733e2cde7dbfa78f1a276a01b12760de2e28 (patch) | |
| tree | b22d268ba829908cf0d8046a377ccf0e5c9b3cdf /clang/lib | |
| parent | 5fe8a4f88fca4631ce04c28352c814292cdfb7f2 (diff) | |
| download | bcm5719-llvm-1ba2733e2cde7dbfa78f1a276a01b12760de2e28.tar.gz bcm5719-llvm-1ba2733e2cde7dbfa78f1a276a01b12760de2e28.zip | |
Fix a crash with -Wassign-enum, where we didn't adjust the APInt type of the
constant. Also fix some spelling mistakes and formatting issues.
Reviewed by Richard Smith over IRC.
Fixes PR15069.
llvm-svn: 183409
Diffstat (limited to 'clang/lib')
| -rw-r--r-- | clang/lib/Sema/SemaStmt.cpp | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp index a6b98a2f6a7..7c2ee9dbe77 100644 --- a/clang/lib/Sema/SemaStmt.cpp +++ b/clang/lib/Sema/SemaStmt.cpp @@ -1120,9 +1120,9 @@ Sema::ActOnFinishSwitchStmt(SourceLocation SwitchLoc, Stmt *Switch, void Sema::DiagnoseAssignmentEnum(QualType DstType, QualType SrcType, Expr *SrcExpr) { - unsigned DIAG = diag::warn_not_in_enum_assignement; - if (Diags.getDiagnosticLevel(DIAG, SrcExpr->getExprLoc()) - == DiagnosticsEngine::Ignored) + if (Diags.getDiagnosticLevel(diag::warn_not_in_enum_assignment, + SrcExpr->getExprLoc()) == + DiagnosticsEngine::Ignored) return; if (const EnumType *ET = DstType->getAs<EnumType>()) @@ -1131,13 +1131,14 @@ Sema::DiagnoseAssignmentEnum(QualType DstType, QualType SrcType, if (!SrcExpr->isTypeDependent() && !SrcExpr->isValueDependent() && SrcExpr->isIntegerConstantExpr(Context)) { // Get the bitwidth of the enum value before promotions. - unsigned DstWith = Context.getIntWidth(DstType); + unsigned DstWidth = Context.getIntWidth(DstType); bool DstIsSigned = DstType->isSignedIntegerOrEnumerationType(); llvm::APSInt RhsVal = SrcExpr->EvaluateKnownConstInt(Context); + AdjustAPSInt(RhsVal, DstWidth, DstIsSigned); const EnumDecl *ED = ET->getDecl(); - typedef SmallVector<std::pair<llvm::APSInt, EnumConstantDecl*>, 64> - EnumValsTy; + typedef SmallVector<std::pair<llvm::APSInt, EnumConstantDecl *>, 64> + EnumValsTy; EnumValsTy EnumVals; // Gather all enum values, set their type and sort them, @@ -1145,21 +1146,21 @@ Sema::DiagnoseAssignmentEnum(QualType DstType, QualType SrcType, for (EnumDecl::enumerator_iterator EDI = ED->enumerator_begin(); EDI != ED->enumerator_end(); ++EDI) { llvm::APSInt Val = EDI->getInitVal(); - AdjustAPSInt(Val, DstWith, DstIsSigned); + AdjustAPSInt(Val, DstWidth, DstIsSigned); EnumVals.push_back(std::make_pair(Val, *EDI)); } if (EnumVals.empty()) return; std::stable_sort(EnumVals.begin(), EnumVals.end(), CmpEnumVals); EnumValsTy::iterator EIend = - std::unique(EnumVals.begin(), EnumVals.end(), EqEnumVals); + std::unique(EnumVals.begin(), EnumVals.end(), EqEnumVals); - // See which case values aren't in enum. + // See which values aren't in the enum. EnumValsTy::const_iterator EI = EnumVals.begin(); while (EI != EIend && EI->first < RhsVal) EI++; if (EI == EIend || EI->first != RhsVal) { - Diag(SrcExpr->getExprLoc(), diag::warn_not_in_enum_assignement) + Diag(SrcExpr->getExprLoc(), diag::warn_not_in_enum_assignment) << DstType; } } |

