From 6b90356ab455baca180c74ee67282fd40bf2780c Mon Sep 17 00:00:00 2001 From: David Majnemer Date: Mon, 19 Jan 2015 10:21:22 +0000 Subject: [PATCH] Add back a check removed in r226436 It shouldn't have been removed, the code which replaced it didn't cover this case. llvm-svn: 226442 --- clang/include/clang/Basic/DiagnosticSemaKinds.td | 2 ++ clang/lib/Sema/SemaDecl.cpp | 14 ++++++++++++-- clang/test/Sema/alias-redefinition.c | 3 +++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index 5509b03..3e41564a 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/include/clang/Basic/DiagnosticSemaKinds.td @@ -3902,6 +3902,8 @@ def warn_missing_variable_declarations : Warning< def err_static_data_member_reinitialization : Error<"static data member %0 already has an initializer">; def err_redefinition : Error<"redefinition of %0">; +def err_alias_after_tentative : + Error<"alias definition of %0 after tentative definition">; def err_alias_is_definition : Error<"definition %0 cannot also be an alias">; def err_definition_of_implicitly_declared_member : Error< diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index da59fb5..9eb5993 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -2219,8 +2219,18 @@ static void checkNewAttributesAfterDef(Sema &S, Decl *New, const Decl *Old) { const Attr *NewAttribute = NewAttributes[I]; if (isa(NewAttribute)) { - FunctionDecl *FD = cast(New); - S.CheckForFunctionRedefinition(FD, cast(Def)); + if (FunctionDecl *FD = dyn_cast(New)) + S.CheckForFunctionRedefinition(FD, cast(Def)); + else { + VarDecl *VD = cast(New); + unsigned Diag = cast(Def)->isThisDeclarationADefinition() == + VarDecl::TentativeDefinition + ? diag::err_alias_after_tentative + : diag::err_redefinition; + S.Diag(VD->getLocation(), Diag) << VD->getDeclName(); + S.Diag(Def->getLocation(), diag::note_previous_definition); + VD->setInvalidDecl(); + } ++I; continue; } diff --git a/clang/test/Sema/alias-redefinition.c b/clang/test/Sema/alias-redefinition.c index 9f9930d..c1562c7 100644 --- a/clang/test/Sema/alias-redefinition.c +++ b/clang/test/Sema/alias-redefinition.c @@ -25,3 +25,6 @@ void __attribute((alias("f5"))) fun5(void) {} // expected-error {{redefinition o int var1 __attribute((alias("v1"))); // expected-error {{definition 'var1' cannot also be an alias}} static int var2 __attribute((alias("v2"))) = 2; // expected-error {{definition 'var2' cannot also be an alias}} + +extern int var3 __attribute__((alias("C"))); // expected-note{{previous definition is here}} +int var3 = 3; // expected-error{{redefinition of 'var3'}} -- 2.7.4