The OpenCL specification states that images are allocated
from the global address space (6.5.1 of the OpenCL 1.2 specification).
This makes clang construct the image arguments in the global address
space and generate the argument metadata with the correct address space
descriptor.
Patch by Pedro Ferreira!
llvm-svn: 198868
diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp
index c1e522d..564ea11 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -383,7 +383,12 @@
if (pointeeTy.isVolatileQualified())
typeQuals += typeQuals.empty() ? "volatile" : " volatile";
} else {
- addressQuals.push_back(Builder.getInt32(0));
+ uint32_t AddrSpc = 0;
+ if (ty->isImageType())
+ AddrSpc =
+ CGM.getContext().getTargetAddressSpace(LangAS::opencl_global);
+
+ addressQuals.push_back(Builder.getInt32(AddrSpc));
// Get argument type name.
std::string typeName = ty.getUnqualifiedType().getAsString();