[OpenCL] Fix atomic Builtins check for address spaces of non-atomic pointer
If there are two pointers passed to an atomic Builtin,
Clang doesn't allow the second (non-atomic) one to be qualified
with an address space.
Remove this restriction by recording the address space of passed pointers
in atomics type diagnostics.
llvm-svn: 256243
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index d5c80c9..949e874 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -1801,8 +1801,17 @@
Ty = ByValType;
else if (Form == Arithmetic)
Ty = Context.getPointerDiffType();
- else
- Ty = Context.getPointerType(ValType.getUnqualifiedType());
+ else {
+ Expr *ValArg = TheCall->getArg(i);
+ unsigned AS = 0;
+ // Keep address space of non-atomic pointer type.
+ if (const PointerType *PtrTy =
+ ValArg->getType()->getAs<PointerType>()) {
+ AS = PtrTy->getPointeeType().getAddressSpace();
+ }
+ Ty = Context.getPointerType(
+ Context.getAddrSpaceQualType(ValType.getUnqualifiedType(), AS));
+ }
break;
case 2:
// The third argument to compare_exchange / GNU exchange is a