[clang] d238b60 - [Clang][DiagnosticSemaKinds] combine diagnostic texts
Nick Desaulniers via cfe-commits
cfe-commits at lists.llvm.org
Fri Aug 6 13:58:38 PDT 2021
Author: Nick Desaulniers
Date: 2021-08-06T13:58:21-07:00
New Revision: d238b60285820691b08bcca3ec510d13ea46a5ed
URL: https://github.com/llvm/llvm-project/commit/d238b60285820691b08bcca3ec510d13ea46a5ed
DIFF: https://github.com/llvm/llvm-project/commit/d238b60285820691b08bcca3ec510d13ea46a5ed.diff
LOG: [Clang][DiagnosticSemaKinds] combine diagnostic texts
The diagnostic texts for warning on attributes that don't appear on the
initial declaration is generally useful. We'd like to re-use it in
D106030, but first let's combine two that already are very similar so we
may re-use it a third time in that commit.
Also, fix a few places that were using notePreviousDefinition to point
to declarations, to instead use diag::note_previous_declaration.
Reviewed By: aaron.ballman
Differential Revision: https://reviews.llvm.org/D107613
Added:
Modified:
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaDecl.cpp
clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.noreturn/p1.cpp
clang/test/Sema/attr-weak.c
clang/test/Sema/internal_linkage.c
clang/test/SemaCXX/internal_linkage.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td
index 6cfb8b89eb90..bf857f58951b 100644
--- a/clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -5571,8 +5571,8 @@ def warn_undefined_inline : Warning<"inline function %q0 is not defined">,
def err_undefined_inline_var : Error<"inline variable %q0 is not defined">;
def note_used_here : Note<"used here">;
-def err_internal_linkage_redeclaration : Error<
- "'internal_linkage' attribute does not appear on the first declaration of %0">;
+def err_attribute_missing_on_first_decl : Error<
+ "%0 attribute does not appear on the first declaration">;
def warn_internal_linkage_local_storage : Warning<
"'internal_linkage' attribute on a non-static local variable is ignored">,
InGroup<IgnoredAttributes>;
@@ -9676,10 +9676,6 @@ def warn_falloff_noreturn_function : Warning<
InGroup<InvalidNoreturn>;
def err_noreturn_block_has_return_expr : Error<
"block declared 'noreturn' should not return">;
-def err_noreturn_missing_on_first_decl : Error<
- "function declared '[[noreturn]]' after its first declaration">;
-def note_noreturn_missing_first_decl : Note<
- "declaration missing '[[noreturn]]' attribute is here">;
def err_carries_dependency_missing_on_first_decl : Error<
"%select{function|parameter}0 declared '[[carries_dependency]]' "
"after its first declaration">;
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 3367f0f9744a..eba5141c24c9 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -3353,13 +3353,13 @@ bool Sema::MergeFunctionDecl(FunctionDecl *New, NamedDecl *&OldD,
}
}
- if (New->hasAttr<InternalLinkageAttr>() &&
- !Old->hasAttr<InternalLinkageAttr>()) {
- Diag(New->getLocation(), diag::err_internal_linkage_redeclaration)
- << New->getDeclName();
- notePreviousDefinition(Old, New->getLocation());
- New->dropAttr<InternalLinkageAttr>();
- }
+ if (const auto *ILA = New->getAttr<InternalLinkageAttr>())
+ if (!Old->hasAttr<InternalLinkageAttr>()) {
+ Diag(New->getLocation(), diag::err_attribute_missing_on_first_decl)
+ << ILA;
+ Diag(Old->getLocation(), diag::note_previous_declaration);
+ New->dropAttr<InternalLinkageAttr>();
+ }
if (CheckRedeclarationModuleOwnership(New, Old))
return true;
@@ -3678,12 +3678,12 @@ bool Sema::MergeFunctionDecl(FunctionDecl *New, NamedDecl *&OldD,
// The first declaration of a function shall specify the noreturn
// attribute if any declaration of that function specifies the noreturn
// attribute.
- const CXX11NoReturnAttr *NRA = New->getAttr<CXX11NoReturnAttr>();
- if (NRA && !Old->hasAttr<CXX11NoReturnAttr>()) {
- Diag(NRA->getLocation(), diag::err_noreturn_missing_on_first_decl);
- Diag(Old->getFirstDecl()->getLocation(),
- diag::note_noreturn_missing_first_decl);
- }
+ if (const auto *NRA = New->getAttr<CXX11NoReturnAttr>())
+ if (!Old->hasAttr<CXX11NoReturnAttr>()) {
+ Diag(NRA->getLocation(), diag::err_attribute_missing_on_first_decl)
+ << NRA;
+ Diag(Old->getLocation(), diag::note_previous_declaration);
+ }
// C++11 [dcl.attr.depend]p2:
// The first declaration of a function shall specify the
@@ -4161,18 +4161,18 @@ void Sema::MergeVarDecl(VarDecl *New, LookupResult &Previous) {
Old->getStorageClass() == SC_None &&
!Old->hasAttr<WeakImportAttr>()) {
Diag(New->getLocation(), diag::warn_weak_import) << New->getDeclName();
- notePreviousDefinition(Old, New->getLocation());
+ Diag(Old->getLocation(), diag::note_previous_declaration);
// Remove weak_import attribute on new declaration.
New->dropAttr<WeakImportAttr>();
}
- if (New->hasAttr<InternalLinkageAttr>() &&
- !Old->hasAttr<InternalLinkageAttr>()) {
- Diag(New->getLocation(), diag::err_internal_linkage_redeclaration)
- << New->getDeclName();
- notePreviousDefinition(Old, New->getLocation());
- New->dropAttr<InternalLinkageAttr>();
- }
+ if (const auto *ILA = New->getAttr<InternalLinkageAttr>())
+ if (!Old->hasAttr<InternalLinkageAttr>()) {
+ Diag(New->getLocation(), diag::err_attribute_missing_on_first_decl)
+ << ILA;
+ Diag(Old->getLocation(), diag::note_previous_declaration);
+ New->dropAttr<InternalLinkageAttr>();
+ }
// Merge the types.
VarDecl *MostRecent = Old->getMostRecentDecl();
diff --git a/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.noreturn/p1.cpp b/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.noreturn/p1.cpp
index 49c1106b51a5..56920ea8e8cf 100644
--- a/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.noreturn/p1.cpp
+++ b/clang/test/CXX/dcl.dcl/dcl.attr/dcl.attr.noreturn/p1.cpp
@@ -24,8 +24,8 @@ int d2 [[noreturn]]; // expected-error {{'noreturn' attribute only applies to fu
[[noreturn]] int e() { b2(); } // ok
-int f(); // expected-note {{declaration missing '[[noreturn]]' attribute is here}}
-[[noreturn]] int f(); // expected-error {{function declared '[[noreturn]]' after its first declaration}}
+int f(); // expected-note {{previous declaration is here}}
+[[noreturn]] int f(); // expected-error {{'noreturn' attribute does not appear on the first declaration}}
int f();
[[noreturn]] int g();
diff --git a/clang/test/Sema/attr-weak.c b/clang/test/Sema/attr-weak.c
index 6f0c3d5523b3..cd818b43a476 100644
--- a/clang/test/Sema/attr-weak.c
+++ b/clang/test/Sema/attr-weak.c
@@ -17,7 +17,7 @@ static int f() __attribute__((weak)); // expected-error {{weak declaration canno
static int x __attribute__((weak)); // expected-error {{weak declaration cannot have internal linkage}}
// rdar://9538608
-int C; // expected-note {{previous definition is here}}
+int C; // expected-note {{previous declaration is here}}
extern int C __attribute__((weak_import)); // expected-warning {{an already-declared variable is made a weak_import declaration}}
static int pr14946_x;
diff --git a/clang/test/Sema/internal_linkage.c b/clang/test/Sema/internal_linkage.c
index a6911f4baa7b..99db5db4c505 100644
--- a/clang/test/Sema/internal_linkage.c
+++ b/clang/test/Sema/internal_linkage.c
@@ -6,9 +6,9 @@ int var2 __attribute__((internal_linkage,common)); // expected-error{{'common' a
int var3 __attribute__((common,internal_linkage)); // expected-error{{'internal_linkage' and 'common' attributes are not compatible}} \
// expected-note{{conflicting attribute is here}}
-int var4 __attribute__((common)); // expected-note{{previous definition is here}} expected-note{{conflicting attribute is here}}
+int var4 __attribute__((common)); // expected-note{{previous declaration is here}} expected-note{{conflicting attribute is here}}
int var4 __attribute__((internal_linkage)); // expected-error{{'internal_linkage' and 'common' attributes are not compatible}} \
- // expected-error{{'internal_linkage' attribute does not appear on the first declaration of 'var4'}}
+ // expected-error{{'internal_linkage' attribute does not appear on the first declaration}}
int var5 __attribute__((internal_linkage)); // expected-note{{conflicting attribute is here}}
int var5 __attribute__((common)); // expected-error{{'common' and 'internal_linkage' attributes are not compatible}}
diff --git a/clang/test/SemaCXX/internal_linkage.cpp b/clang/test/SemaCXX/internal_linkage.cpp
index 921a90ab4a41..81ab01f603e4 100644
--- a/clang/test/SemaCXX/internal_linkage.cpp
+++ b/clang/test/SemaCXX/internal_linkage.cpp
@@ -10,8 +10,8 @@ class __attribute__((internal_linkage)) A {
void f1() __attribute__((internal_linkage));
void f2() __attribute__((internal_linkage)) {}
static void f3() __attribute__((internal_linkage)) {}
- void f4(); // expected-note{{previous definition is here}}
- static int zz; // expected-note{{previous definition is here}}
+ void f4(); // expected-note{{previous declaration is here}}
+ static int zz; // expected-note{{previous declaration is here}}
A() __attribute__((internal_linkage)) {}
~A() __attribute__((internal_linkage)) {}
A& operator=(const A&) __attribute__((internal_linkage)) { return *this; }
@@ -20,9 +20,9 @@ class __attribute__((internal_linkage)) A {
};
};
-__attribute__((internal_linkage)) void A::f4() {} // expected-error{{'internal_linkage' attribute does not appear on the first declaration of 'f4'}}
+__attribute__((internal_linkage)) void A::f4() {} // expected-error{{'internal_linkage' attribute does not appear on the first declaration}}
-__attribute__((internal_linkage)) int A::zz; // expected-error{{'internal_linkage' attribute does not appear on the first declaration of 'zz'}}
+__attribute__((internal_linkage)) int A::zz; // expected-error{{'internal_linkage' attribute does not appear on the first declaration}}
namespace Z __attribute__((internal_linkage)) { // expected-warning{{'internal_linkage' attribute only applies to}}
}
More information about the cfe-commits
mailing list