From 16fcf99610f36c7c11d20097c070a93b648e19c9 Mon Sep 17 00:00:00 2001 From: Erich Keane Date: Tue, 15 Jan 2019 17:51:09 +0000 Subject: [PATCH] Fix cpu-dispatch MV regression caused by r347812 r347812 permitted forward declarations for cpu-dispatch functions, which are occassionally useful as exposition in header files. However, this inadvertently permitted this function to become multiversioned after a usage. This patch ensures that the "CausesMV" checks are still run in the forward-declaration case. Change-Id: Icb6f975a2d068f088b89e3bbe26cf1d24f5a972c git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@351212 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaDecl.cpp | 3 ++- test/Sema/attr-cpuspecific.c | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index e853180d76..23c99d45a7 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -9816,7 +9816,8 @@ static bool CheckMultiVersionAdditionalDecl( return true; } - if (CheckMultiVersionAdditionalRules(S, OldFD, NewFD, false, NewMVType)) { + if (CheckMultiVersionAdditionalRules(S, OldFD, NewFD, + !OldFD->isMultiVersion(), NewMVType)) { NewFD->setInvalidDecl(); return true; } diff --git a/test/Sema/attr-cpuspecific.c b/test/Sema/attr-cpuspecific.c index d15a65ea1f..e87ad4de75 100644 --- a/test/Sema/attr-cpuspecific.c +++ b/test/Sema/attr-cpuspecific.c @@ -40,6 +40,14 @@ int __attribute__((cpu_dispatch(atom))) redecl2(void) { } int allow_fwd_decl(void); int __attribute__((cpu_dispatch(atom))) allow_fwd_decl(void) {} +int allow_fwd_decl2(void); +void use_fwd_decl(void) { + allow_fwd_decl2(); +} +// expected-error@+1 {{function declaration cannot become a multiversioned function after first usage}} +int __attribute__((cpu_dispatch(atom))) allow_fwd_decl2(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}} int redecl4(void); -- 2.40.0