]> granicus.if.org Git - clang/commitdiff
Process attributes 'ifunc' and 'alias' when checking for redefinition
authorSerge Pavlov <sepavloff@gmail.com>
Sat, 18 Feb 2017 06:04:15 +0000 (06:04 +0000)
committerSerge Pavlov <sepavloff@gmail.com>
Sat, 18 Feb 2017 06:04:15 +0000 (06:04 +0000)
These attributes effectively turn a non-defining declaration into a
definition, so the case when the declaration already has a body must
be diagnosed properly.

Differential Revision: https://reviews.llvm.org/D30032

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@295541 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDecl.cpp
test/Sema/alias-redefinition.c
test/Sema/attr-ifunc.c

index e96860a294ea12c354d0324ba6c034f6ebf40573..54d8c27af36999fc62ec2c6ffd8d8fadf631561b 100644 (file)
@@ -11786,6 +11786,18 @@ Decl *Sema::ActOnStartOfFunctionDef(Scope *FnBodyScope, Decl *D,
   else
     FD = cast<FunctionDecl>(D);
 
+  // Check for defining attributes before the check for redefinition.
+  if (const auto *Attr = FD->getAttr<AliasAttr>()) {
+    Diag(Attr->getLocation(), diag::err_alias_is_definition) << FD << 0;
+    FD->dropAttr<AliasAttr>();
+    FD->setInvalidDecl();
+  }
+  if (const auto *Attr = FD->getAttr<IFuncAttr>()) {
+    Diag(Attr->getLocation(), diag::err_alias_is_definition) << FD << 1;
+    FD->dropAttr<IFuncAttr>();
+    FD->setInvalidDecl();
+  }
+
   // See if this is a redefinition.
   if (!FD->isLateTemplateParsed()) {
     CheckForFunctionRedefinition(FD, nullptr, SkipBody);
index 91f4b2714cd0364549a091ece6351b0b1035e205..a4c06eebf499b33dc70f6a5a90af7405357d37e5 100644 (file)
@@ -19,9 +19,8 @@ void f4() {}
 void fun4(void) __attribute((alias("f4")));
 void fun4(void);
 
-// FIXME: We should produce a special case error for this.
 void f5() {}
-void __attribute((alias("f5"))) fun5(void) {} // expected-error {{redefinition of 'fun5'}} // expected-note {{previous definition}}
+void __attribute((alias("f5"))) fun5(void) {} // expected-error {{definition 'fun5' cannot also be an alias}}
 
 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}}
index d177b7168488f28732088a2c69721fdf3169d749..8f9c22f849272620195a4a98a3c490311317dee8 100644 (file)
@@ -39,5 +39,9 @@ void f1() __attribute__((ifunc("f1_ifunc")));
 //expected-error@-1 {{definition with same mangled name as another definition}}
 void* f1_ifunc() { return 0; }
 
+void* f6_ifunc(int i);
+void __attribute__((ifunc("f6_ifunc"))) f6() {}
+//expected-error@-1 {{definition 'f6' cannot also be an ifunc}}
+
 #endif
 #endif