summaryrefslogtreecommitdiffstats
path: root/clang/lib
diff options
context:
space:
mode:
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/Sema/SemaCUDA.cpp20
-rw-r--r--clang/lib/Sema/SemaType.cpp4
2 files changed, 24 insertions, 0 deletions
diff --git a/clang/lib/Sema/SemaCUDA.cpp b/clang/lib/Sema/SemaCUDA.cpp
index b1939a17157..c75bdc7f59a 100644
--- a/clang/lib/Sema/SemaCUDA.cpp
+++ b/clang/lib/Sema/SemaCUDA.cpp
@@ -539,3 +539,23 @@ bool Sema::CheckCUDAExceptionExpr(SourceLocation Loc, StringRef ExprTy) {
}
return true;
}
+
+bool Sema::CheckCUDAVLA(SourceLocation Loc) {
+ assert(getLangOpts().CUDA && "Should only be called during CUDA compilation");
+ FunctionDecl *CurFn = dyn_cast<FunctionDecl>(CurContext);
+ if (!CurFn)
+ return true;
+ CUDAFunctionTarget Target = IdentifyCUDATarget(CurFn);
+ if (Target == CFT_Global || Target == CFT_Device) {
+ Diag(Loc, diag::err_cuda_vla) << Target;
+ return false;
+ }
+ if (Target == CFT_HostDevice && getLangOpts().CUDAIsDevice) {
+ PartialDiagnostic ErrPD{PartialDiagnostic::NullDiagnostic()};
+ ErrPD.Reset(diag::err_cuda_vla);
+ ErrPD << Target;
+ CurFn->addDeferredDiag({Loc, std::move(ErrPD)});
+ return false;
+ }
+ return true;
+}
diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 1619483f082..dd833d72217 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -2241,6 +2241,10 @@ QualType Sema::BuildArrayType(QualType T, ArrayType::ArraySizeModifier ASM,
Diag(Loc, diag::err_opencl_vla);
return QualType();
}
+ // CUDA device code doesn't support VLAs.
+ if (getLangOpts().CUDA && T->isVariableArrayType() && !CheckCUDAVLA(Loc))
+ return QualType();
+
// If this is not C99, extwarn about VLA's and C99 array size modifiers.
if (!getLangOpts().C99) {
if (T->isVariableArrayType()) {
OpenPOWER on IntegriCloud