summaryrefslogtreecommitdiffstats
path: root/clang/lib
diff options
context:
space:
mode:
authorJustin Lebar <jlebar@google.com>2016-09-30 23:57:34 +0000
committerJustin Lebar <jlebar@google.com>2016-09-30 23:57:34 +0000
commite71b2fa4c9945bbcb00b9e9bf80c46fbe4068257 (patch)
tree1c079c110cbfe720f4fa1eab7749859d8e7900a7 /clang/lib
parent1041101953dae8ac0db2b65ca5f8bf537e436dad (diff)
downloadbcm5719-llvm-e71b2fa4c9945bbcb00b9e9bf80c46fbe4068257.tar.gz
bcm5719-llvm-e71b2fa4c9945bbcb00b9e9bf80c46fbe4068257.zip
[CUDA] Disallow __constant__ local variables.
Reviewers: tra, rnk Subscribers: cfe-commits Differential Revision: https://reviews.llvm.org/D25129 llvm-svn: 282986
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/Sema/SemaDeclAttr.cpp16
1 files changed, 14 insertions, 2 deletions
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index ff63d7b1ce6..21cace432c4 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -3696,6 +3696,19 @@ static void handleOptimizeNoneAttr(Sema &S, Decl *D,
D->addAttr(Optnone);
}
+static void handleConstantAttr(Sema &S, Decl *D, const AttributeList &Attr) {
+ if (checkAttrMutualExclusion<CUDASharedAttr>(S, D, Attr.getRange(),
+ Attr.getName()))
+ return;
+ auto *VD = cast<VarDecl>(D);
+ if (!VD->hasGlobalStorage()) {
+ S.Diag(Attr.getLoc(), diag::err_cuda_nonglobal_constant);
+ return;
+ }
+ D->addAttr(::new (S.Context) CUDAConstantAttr(
+ Attr.getRange(), S.Context, Attr.getAttributeSpellingListIndex()));
+}
+
static void handleSharedAttr(Sema &S, Decl *D, const AttributeList &Attr) {
if (checkAttrMutualExclusion<CUDAConstantAttr>(S, D, Attr.getRange(),
Attr.getName()))
@@ -5541,8 +5554,7 @@ static void ProcessDeclAttribute(Sema &S, Scope *scope, Decl *D,
handleCommonAttr(S, D, Attr);
break;
case AttributeList::AT_CUDAConstant:
- handleSimpleAttributeWithExclusions<CUDAConstantAttr, CUDASharedAttr>(S, D,
- Attr);
+ handleConstantAttr(S, D, Attr);
break;
case AttributeList::AT_PassObjectSize:
handlePassObjectSizeAttr(S, D, Attr);
OpenPOWER on IntegriCloud