diff options
author | Erich Keane <erich.keane@intel.com> | 2018-11-28 21:54:04 +0000 |
---|---|---|
committer | Erich Keane <erich.keane@intel.com> | 2018-11-28 21:54:04 +0000 |
commit | a3e7a167c499bfe35628676137637c5265bb06aa (patch) | |
tree | 70cc06298f7a2187aa9516fd270e72f1a946f81e | |
parent | c9f2473b4306117a409bc3167f0988681ecb518f (diff) | |
download | bcm5719-llvm-a3e7a167c499bfe35628676137637c5265bb06aa.tar.gz bcm5719-llvm-a3e7a167c499bfe35628676137637c5265bb06aa.zip |
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
llvm-svn: 347812
-rw-r--r-- | clang/lib/Sema/SemaDecl.cpp | 17 | ||||
-rw-r--r-- | clang/test/CodeGen/attr-cpuspecific.c | 5 | ||||
-rw-r--r-- | clang/test/Sema/attr-cpuspecific.c | 6 |
3 files changed, 15 insertions, 13 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 8ccd9ae322b..5b2d2899f81 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -9822,6 +9822,15 @@ static bool CheckMultiVersionAdditionalDecl( 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(Sema &S, FunctionDecl *NewFD, 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 diff --git a/clang/test/CodeGen/attr-cpuspecific.c b/clang/test/CodeGen/attr-cpuspecific.c index 57a0ebebf25..d6c99648cb7 100644 --- a/clang/test/CodeGen/attr-cpuspecific.c +++ b/clang/test/CodeGen/attr-cpuspecific.c @@ -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() diff --git a/clang/test/Sema/attr-cpuspecific.c b/clang/test/Sema/attr-cpuspecific.c index 91063c1c5b8..4d21a8c894d 100644 --- a/clang/test/Sema/attr-cpuspecific.c +++ b/clang/test/Sema/attr-cpuspecific.c @@ -37,10 +37,8 @@ int __attribute__((cpu_dispatch(atom))) redecl2(void) { } // expected-note@-2 {{previous definition is here}} int __attribute__((cpu_dispatch(atom))) redecl2(void) { } -int redecl3(void); -// expected-error@-1 {{function declaration is missing 'cpu_specific' or 'cpu_dispatch' attribute in a multiversioned function}} -// expected-note@+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@+1 {{function declaration is missing 'cpu_specific' or 'cpu_dispatch' attribute in a multiversioned function}} |