r347812 - Allow cpu-dispatch forward declarations.
Erich Keane via cfe-commits
cfe-commits at lists.llvm.org
Wed Nov 28 13:54:04 PST 2018
Author: erichkeane
Date: Wed Nov 28 13:54:04 2018
New Revision: 347812
URL: http://llvm.org/viewvc/llvm-project?rev=347812&view=rev
Log:
Allow cpu-dispatch forward declarations.
As a followup to r347805, allow forward declarations of cpu-dispatch and
cpu-specific for the same reasons.
Change-Id: Ic1bde9be369b1f8f1d47d58e6fbdc2f9dfcdd785
Modified:
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/test/CodeGen/attr-cpuspecific.c
cfe/trunk/test/Sema/attr-cpuspecific.c
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=347812&r1=347811&r2=347812&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Wed Nov 28 13:54:04 2018
@@ -9822,6 +9822,15 @@ static bool CheckMultiVersionAdditionalD
return true;
}
+ // Permit forward declarations in the case where these two are compatible.
+ if (!OldFD->isMultiVersion()) {
+ OldFD->setIsMultiVersion();
+ NewFD->setIsMultiVersion();
+ Redeclaration = true;
+ OldDecl = OldFD;
+ return false;
+ }
+
NewFD->setIsMultiVersion();
Redeclaration = false;
MergeTypeWithPrevious = false;
@@ -9896,14 +9905,6 @@ static bool CheckMultiVersionFunction(Se
return CheckTargetCausesMultiVersioning(S, OldFD, NewFD, NewTA,
Redeclaration, OldDecl,
MergeTypeWithPrevious, Previous);
- // Previous declarations lack CPUDispatch/CPUSpecific.
- if (!OldFD->isMultiVersion()) {
- S.Diag(OldFD->getLocation(), diag::err_multiversion_required_in_redecl)
- << 1;
- S.Diag(NewFD->getLocation(), diag::note_multiversioning_caused_here);
- NewFD->setInvalidDecl();
- return true;
- }
// At this point, we have a multiversion function decl (in OldFD) AND an
// appropriate attribute in the current function decl. Resolve that these are
Modified: cfe/trunk/test/CodeGen/attr-cpuspecific.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/attr-cpuspecific.c?rev=347812&r1=347811&r2=347812&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/attr-cpuspecific.c (original)
+++ cfe/trunk/test/CodeGen/attr-cpuspecific.c Wed Nov 28 13:54:04 2018
@@ -23,7 +23,10 @@ void NotCalled(void){}
// LINUX: define void @NotCalled.S() #[[S]]
// WINDOWS: define dso_local void @NotCalled.S() #[[S:[0-9]+]]
-// Done before any of the implementations.
+// Done before any of the implementations. Also has an undecorated forward
+// declaration.
+void TwoVersions(void);
+
ATTR(cpu_dispatch(ivybridge, knl))
void TwoVersions(void);
// LINUX: define void ()* @TwoVersions.resolver()
Modified: cfe/trunk/test/Sema/attr-cpuspecific.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/attr-cpuspecific.c?rev=347812&r1=347811&r2=347812&view=diff
==============================================================================
--- cfe/trunk/test/Sema/attr-cpuspecific.c (original)
+++ cfe/trunk/test/Sema/attr-cpuspecific.c Wed Nov 28 13:54:04 2018
@@ -37,10 +37,8 @@ int __attribute__((cpu_dispatch(atom)))
// expected-note at -2 {{previous definition is here}}
int __attribute__((cpu_dispatch(atom))) redecl2(void) { }
-int redecl3(void);
-// expected-error at -1 {{function declaration is missing 'cpu_specific' or 'cpu_dispatch' attribute in a multiversioned function}}
-// expected-note at +1 {{function multiversioning caused by this declaration}}
-int __attribute__((cpu_dispatch(atom))) redecl3(void) {}
+int allow_fwd_decl(void);
+int __attribute__((cpu_dispatch(atom))) allow_fwd_decl(void) {}
int __attribute__((cpu_specific(atom))) redecl4(void);
// expected-error at +1 {{function declaration is missing 'cpu_specific' or 'cpu_dispatch' attribute in a multiversioned function}}
More information about the cfe-commits
mailing list