From aa45ce114429f5bc340db01ba14168b79bcc60c9 Mon Sep 17 00:00:00 2001 From: Erich Keane Date: Mon, 10 Sep 2018 14:31:56 +0000 Subject: [PATCH] Prevent cpu-specific/cpu-dispatch from giong on a lambda. It is non-sensical to use cpu-specific/cpu-dispatch multiversioning on a lambda, so prevent it when trying to add the attribute. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@341833 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaDeclAttr.cpp | 8 ++++++++ test/SemaCXX/attr-cpuspecific.cpp | 3 +++ 2 files changed, 11 insertions(+) diff --git a/lib/Sema/SemaDeclAttr.cpp b/lib/Sema/SemaDeclAttr.cpp index 65c636b94e..db5df4db80 100644 --- a/lib/Sema/SemaDeclAttr.cpp +++ b/lib/Sema/SemaDeclAttr.cpp @@ -1842,6 +1842,14 @@ static void handleRestrictAttr(Sema &S, Decl *D, const ParsedAttr &AL) { static void handleCPUSpecificAttr(Sema &S, Decl *D, const ParsedAttr &AL) { FunctionDecl *FD = cast(D); + + if (const auto *MD = dyn_cast(D)) { + if (MD->getParent()->isLambda()) { + S.Diag(AL.getLoc(), diag::err_attribute_dll_lambda) << AL; + return; + } + } + if (!checkAttributeAtLeastNumArgs(S, AL, 1)) return; diff --git a/test/SemaCXX/attr-cpuspecific.cpp b/test/SemaCXX/attr-cpuspecific.cpp index a881b6c4e2..7ec8c6cd0c 100644 --- a/test/SemaCXX/attr-cpuspecific.cpp +++ b/test/SemaCXX/attr-cpuspecific.cpp @@ -109,3 +109,6 @@ int __attribute__((cpu_specific(sandybridge))) BadOutOfLine::foo(int) { return 1 // Ensure Cpp Spelling works. [[clang::cpu_specific(ivybridge,atom)]] int CppSpelling(){} + +// expected-error@+1 {{lambda cannot be declared 'cpu_dispatch'}} +auto x = []() __attribute__((cpu_dispatch(atom))) {}; -- 2.50.1