]> granicus.if.org Git - clang/commitdiff
Prevent cpu-specific/cpu-dispatch from giong on a lambda.
authorErich Keane <erich.keane@intel.com>
Mon, 10 Sep 2018 14:31:56 +0000 (14:31 +0000)
committerErich Keane <erich.keane@intel.com>
Mon, 10 Sep 2018 14:31:56 +0000 (14:31 +0000)
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
test/SemaCXX/attr-cpuspecific.cpp

index 65c636b94ea61f63dce291c6502c625560541b27..db5df4db80222cd9fa966217f5b7d19d409d4950 100644 (file)
@@ -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<FunctionDecl>(D);
+
+  if (const auto *MD = dyn_cast<CXXMethodDecl>(D)) {
+    if (MD->getParent()->isLambda()) {
+      S.Diag(AL.getLoc(), diag::err_attribute_dll_lambda) << AL;
+      return;
+    }
+  }
+
   if (!checkAttributeAtLeastNumArgs(S, AL, 1))
     return;
 
index a881b6c4e2bae143279a64b71acba28816cf32c2..7ec8c6cd0ce2c8f1c7284759af8cf97eacdf7ee2 100644 (file)
@@ -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))) {};