summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--clang/include/clang/Basic/DiagnosticSemaKinds.td26
-rw-r--r--clang/lib/Sema/SemaChecking.cpp8
-rw-r--r--clang/lib/Sema/SemaDecl.cpp12
-rw-r--r--clang/lib/Sema/SemaExpr.cpp5
4 files changed, 19 insertions, 32 deletions
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index d0518b98570..058d8072038 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -4909,9 +4909,8 @@ def warn_floatingpoint_eq : Warning<
"comparing floating point with == or != is unsafe">,
InGroup<DiagGroup<"float-equal">>, DefaultIgnore;
-def warn_division_by_zero : Warning<"division by zero is undefined">,
- InGroup<DivZero>;
-def warn_remainder_by_zero : Warning<"remainder by zero is undefined">,
+def warn_remainder_division_by_zero : Warning<
+ "%select{remainder|division}0 by zero is undefined">,
InGroup<DivZero>;
def warn_shift_lhs_negative : Warning<"shifting a negative signed value is undefined">,
InGroup<DiagGroup<"shift-negative-value">>;
@@ -6677,10 +6676,8 @@ def err_anonymous_union_with_storage_spec : Error<
def err_anonymous_struct_not_member : Error<
"anonymous %select{structs|structs and classes}0 must be "
"%select{struct or union|class}0 members">;
-def err_anonymous_union_member_redecl : Error<
- "member of anonymous union redeclares %0">;
-def err_anonymous_struct_member_redecl : Error<
- "member of anonymous struct redeclares %0">;
+def err_anonymous_record_member_redecl : Error<
+ "member of anonymous %select{struct|union}0 redeclares %1">;
def err_anonymous_record_with_type : Error<
"types cannot be declared in an anonymous %select{struct|union}0">;
def ext_anonymous_record_with_type : Extension<
@@ -7033,17 +7030,12 @@ def warn_null_ret : Warning<
InGroup<NonNull>;
// CHECK: returning address/reference of stack memory
-def warn_ret_stack_addr : Warning<
- "address of stack memory associated with local variable %0 returned">,
- InGroup<ReturnStackAddress>;
-def warn_ret_stack_ref : Warning<
- "reference to stack memory associated with local variable %0 returned">,
- InGroup<ReturnStackAddress>;
-def warn_ret_local_temp_addr : Warning<
- "returning address of local temporary object">,
+def warn_ret_stack_addr_ref : Warning<
+ "%select{address of|reference to}0 stack memory associated with local "
+ "variable %1 returned">,
InGroup<ReturnStackAddress>;
-def warn_ret_local_temp_ref : Warning<
- "returning reference to local temporary object">,
+def warn_ret_local_temp_addr_ref : Warning<
+ "returning %select{address of|reference to}0 local temporary object">,
InGroup<ReturnStackAddress>;
def warn_ret_addr_label : Warning<
"returning address of label, which is local">,
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 24940167be2..9e53c478ef6 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -5646,17 +5646,15 @@ CheckReturnStackAddr(Sema &S, Expr *RetValExp, QualType lhsType,
}
if (DeclRefExpr *DR = dyn_cast<DeclRefExpr>(stackE)) { //address of local var.
- S.Diag(diagLoc, lhsType->isReferenceType() ? diag::warn_ret_stack_ref
- : diag::warn_ret_stack_addr)
+ S.Diag(diagLoc, diag::warn_ret_stack_addr_ref) << lhsType->isReferenceType()
<< DR->getDecl()->getDeclName() << diagRange;
} else if (isa<BlockExpr>(stackE)) { // local block.
S.Diag(diagLoc, diag::err_ret_local_block) << diagRange;
} else if (isa<AddrLabelExpr>(stackE)) { // address of label.
S.Diag(diagLoc, diag::warn_ret_addr_label) << diagRange;
} else { // local temporary.
- S.Diag(diagLoc, lhsType->isReferenceType() ? diag::warn_ret_local_temp_ref
- : diag::warn_ret_local_temp_addr)
- << diagRange;
+ S.Diag(diagLoc, diag::warn_ret_local_temp_addr_ref)
+ << lhsType->isReferenceType() << diagRange;
}
// Display the "trail" of reference variables that we followed until we
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 5215a7e0dc4..47851a18441 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -3913,7 +3913,7 @@ static bool CheckAnonMemberRedeclaration(Sema &SemaRef,
DeclContext *Owner,
DeclarationName Name,
SourceLocation NameLoc,
- unsigned diagnostic) {
+ bool IsUnion) {
LookupResult R(SemaRef, Name, NameLoc, Sema::LookupMemberName,
Sema::ForRedeclaration);
if (!SemaRef.LookupName(R, S)) return false;
@@ -3928,7 +3928,8 @@ static bool CheckAnonMemberRedeclaration(Sema &SemaRef,
if (!SemaRef.isDeclInScope(PrevDecl, Owner, S))
return false;
- SemaRef.Diag(NameLoc, diagnostic) << Name;
+ SemaRef.Diag(NameLoc, diag::err_anonymous_record_member_redecl)
+ << IsUnion << Name;
SemaRef.Diag(PrevDecl->getLocation(), diag::note_previous_declaration);
return true;
@@ -3956,10 +3957,6 @@ static bool InjectAnonymousStructOrUnionMembers(Sema &SemaRef, Scope *S,
AccessSpecifier AS,
SmallVectorImpl<NamedDecl *> &Chaining,
bool MSAnonStruct) {
- unsigned diagKind
- = AnonRecord->isUnion() ? diag::err_anonymous_union_member_redecl
- : diag::err_anonymous_struct_member_redecl;
-
bool Invalid = false;
// Look every FieldDecl and IndirectFieldDecl with a name.
@@ -3968,7 +3965,8 @@ static bool InjectAnonymousStructOrUnionMembers(Sema &SemaRef, Scope *S,
cast<NamedDecl>(D)->getDeclName()) {
ValueDecl *VD = cast<ValueDecl>(D);
if (CheckAnonMemberRedeclaration(SemaRef, S, Owner, VD->getDeclName(),
- VD->getLocation(), diagKind)) {
+ VD->getLocation(),
+ AnonRecord->isUnion())) {
// C++ [class.union]p2:
// The names of the members of an anonymous union shall be
// distinct from the names of any other entity in the
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 8cd26c64ef4..5efd30f6efe 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -7575,13 +7575,12 @@ static void DiagnoseBadDivideOrRemainderValues(Sema& S, ExprResult &LHS,
ExprResult &RHS,
SourceLocation Loc, bool IsDiv) {
// Check for division/remainder by zero.
- unsigned Diag = (IsDiv) ? diag::warn_division_by_zero :
- diag::warn_remainder_by_zero;
llvm::APSInt RHSValue;
if (!RHS.get()->isValueDependent() &&
RHS.get()->EvaluateAsInt(RHSValue, S.Context) && RHSValue == 0)
S.DiagRuntimeBehavior(Loc, RHS.get(),
- S.PDiag(Diag) << RHS.get()->getSourceRange());
+ S.PDiag(diag::warn_remainder_division_by_zero)
+ << IsDiv << RHS.get()->getSourceRange());
}
QualType Sema::CheckMultiplyDivideOperands(ExprResult &LHS, ExprResult &RHS,
OpenPOWER on IntegriCloud