def Alias : Attr {
let Spellings = [GCC<"alias">];
let Args = [StringArgument<"Aliasee">];
+ let Subjects = SubjectList<[Function, GlobalVar], ErrorDiag,
+ "ExpectedFunctionGlobalVarMethodOrProperty">;
let Documentation = [Undocumented];
}
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_tentative_after_alias :
- Error<"tentative definition of %0 after alias definition">;
+def err_alias_is_definition :
+ Error<"definition %0 cannot also be an alias">;
def err_definition_of_implicitly_declared_member : Error<
"definition of implicitly declared %select{default constructor|copy "
"constructor|move constructor|copy assignment operator|move assignment "
const Attr *NewAttribute = NewAttributes[I];
if (isa<AliasAttr>(NewAttribute)) {
- if (FunctionDecl *FD = dyn_cast<FunctionDecl>(New))
- S.CheckForFunctionRedefinition(FD, cast<FunctionDecl>(Def));
- else {
- VarDecl *VD = cast<VarDecl>(New);
- unsigned Diag = cast<VarDecl>(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();
- }
+ FunctionDecl *FD = cast<FunctionDecl>(New);
+ S.CheckForFunctionRedefinition(FD, cast<FunctionDecl>(Def));
++I;
continue;
}
if (ND.isExternallyVisible()) {
S.Diag(Attr->getLocation(), diag::err_attribute_weakref_not_static);
ND.dropAttr<WeakRefAttr>();
+ ND.dropAttr<AliasAttr>();
+ }
+ }
+
+ if (auto *VD = dyn_cast<VarDecl>(&ND)) {
+ if (VD->hasInit()) {
+ if (const auto *Attr = VD->getAttr<AliasAttr>()) {
+ assert(VD->isThisDeclarationADefinition() &&
+ !VD->isExternallyVisible() && "Broken AliasAttr handled late!");
+ S.Diag(Attr->getLocation(), diag::err_alias_is_definition) << VD;
+ VD->dropAttr<AliasAttr>();
+ }
}
}
}
}
- if (!VD->isInvalidDecl() &&
- VD->isThisDeclarationADefinition() == VarDecl::TentativeDefinition) {
- if (const VarDecl *Def = VD->getDefinition()) {
- if (Def->hasAttr<AliasAttr>()) {
- Diag(VD->getLocation(), diag::err_tentative_after_alias)
- << VD->getDeclName();
- Diag(Def->getLocation(), diag::note_previous_definition);
- VD->setInvalidDecl();
- }
- }
- }
-
const DeclContext *DC = VD->getDeclContext();
// If there's a #pragma GCC visibility in scope, and this isn't a class
// member, set the visibility of this variable.
return;
}
+ // Aliases should be on declarations, not definitions.
+ if (const auto *FD = dyn_cast<FunctionDecl>(D)) {
+ if (FD->isThisDeclarationADefinition()) {
+ S.Diag(Attr.getLoc(), diag::err_alias_is_definition) << FD;
+ return;
+ }
+ } else {
+ const auto *VD = cast<VarDecl>(D);
+ if (VD->isThisDeclarationADefinition() && VD->isExternallyVisible()) {
+ S.Diag(Attr.getLoc(), diag::err_alias_is_definition) << VD;
+ return;
+ }
+ }
+
// FIXME: check if target symbol exists in current file
D->addAttr(::new (S.Context) AliasAttr(Attr.getRange(), S.Context, Str,
// CHECK: FunctionDecl{{.*}}TestInt
// CHECK-NEXT: ConstructorAttr{{.*}} 123
-int TestString __attribute__((alias("alias1")));
+static int TestString __attribute__((alias("alias1")));
// CHECK: VarDecl{{.*}}TestString
// CHECK-NEXT: AliasAttr{{.*}} "alias1"
void f5() {}
void __attribute((alias("f5"))) fun5(void) {} // expected-error {{redefinition of 'fun5'}} // expected-note {{previous definition}}
-int v1;
-int var1 __attribute((alias("v1"))); // expected-note {{previous definition}}
-int var1 __attribute((alias("v1"))); // expected-error {{redefinition of 'var1'}}
-
-int v2;
-int var2 = 2; // expected-note {{previous definition}}
-int var2 __attribute((alias("v2"))); // expected-error {{redefinition of 'var2'}}
-
-int v3;
-int var3 __attribute((alias("v3"))); // expected-note {{previous definition}}
-int var3 = 2; // expected-error {{redefinition of 'var3'}}
-
-int v4;
-int var4; // expected-note {{previous definition}}
-int var4 __attribute((alias("v4"))); // expected-error {{alias definition of 'var4' after tentative definition}}
-
-int v5;
-int var5 __attribute((alias("v5"))); // expected-note {{previous definition}}
-int var5; // expected-error {{tentative definition of 'var5' after alias definition}}
+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}}