summaryrefslogtreecommitdiffstats
path: root/clang/lib
diff options
context:
space:
mode:
authorMichael Liao <michael.hliao@gmail.com>2019-12-02 13:13:52 -0500
committerMichael Liao <michael.hliao@gmail.com>2019-12-04 09:37:50 -0500
commitfa9dd410a9a9aa65ce6731cbe1ee12c5941eb3e8 (patch)
treee1cd16217eef256328f2b80d7d4bc3779c4d7b54 /clang/lib
parentd3f62ceac0ce5d35f888c5a2de9c4a41780c8040 (diff)
downloadbcm5719-llvm-fa9dd410a9a9aa65ce6731cbe1ee12c5941eb3e8.tar.gz
bcm5719-llvm-fa9dd410a9a9aa65ce6731cbe1ee12c5941eb3e8.zip
[opencl] Fix address space deduction on array variables.
Summary: - The deduced address space needs applying to its element type as well. Reviewers: Anastasia Subscribers: yaxunl, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D70981
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/Sema/SemaDecl.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index d3503727310..660be458a69 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -6128,7 +6128,26 @@ void Sema::deduceOpenCLAddressSpace(ValueDecl *Decl) {
if ((getLangOpts().OpenCLCPlusPlus || getLangOpts().OpenCLVersion >= 200) &&
Var->hasGlobalStorage())
ImplAS = LangAS::opencl_global;
+ // If the original type from a decayed type is an array type and that array
+ // type has no address space yet, deduce it now.
+ if (auto DT = dyn_cast<DecayedType>(Type)) {
+ auto OrigTy = DT->getOriginalType();
+ if (!OrigTy.getQualifiers().hasAddressSpace() && OrigTy->isArrayType()) {
+ // Add the address space to the original array type and then propagate
+ // that to the element type through `getAsArrayType`.
+ OrigTy = Context.getAddrSpaceQualType(OrigTy, ImplAS);
+ OrigTy = QualType(Context.getAsArrayType(OrigTy), 0);
+ // Re-generate the decayed type.
+ Type = Context.getDecayedType(OrigTy);
+ }
+ }
Type = Context.getAddrSpaceQualType(Type, ImplAS);
+ // Apply any qualifiers (including address space) from the array type to
+ // the element type. This implements C99 6.7.3p8: "If the specification of
+ // an array type includes any type qualifiers, the element type is so
+ // qualified, not the array type."
+ if (Type->isArrayType())
+ Type = QualType(Context.getAsArrayType(Type), 0);
Decl->setType(Type);
}
}
OpenPOWER on IntegriCloud