aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/CodeGenFunction.cpp
diff options
context:
space:
mode:
authorErich Keane <erich.keane@intel.com>2021-08-31 09:50:01 -0700
committerErich Keane <erich.keane@intel.com>2021-09-01 06:12:24 -0700
commit42ae7eb581ff6abf77524f4c9e4333262c95aa4b (patch)
tree390e0ec1eaba3dfbb33983fbdc06e79251dbecec /clang/lib/CodeGen/CodeGenFunction.cpp
parent9b6c8132d3785269512803ff51cb421f8d8bcf0e (diff)
downloadllvm-42ae7eb581ff6abf77524f4c9e4333262c95aa4b.zip
llvm-42ae7eb581ff6abf77524f4c9e4333262c95aa4b.tar.gz
llvm-42ae7eb581ff6abf77524f4c9e4333262c95aa4b.tar.bz2
Ensure field-annotations on pointers properly match the AS of the field.
Discovered in SYCL, the field annotations were always cast to an i8*, which is an invalid bitcast for a pointer type with an address space. This patch makes sure that we create an intrinsic that takes a pointer to the correct address-space and properly do our casts. Differential Revision: https://reviews.llvm.org/D109003
Diffstat (limited to 'clang/lib/CodeGen/CodeGenFunction.cpp')
-rw-r--r--clang/lib/CodeGen/CodeGenFunction.cpp12
1 files changed, 8 insertions, 4 deletions
diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp
index a3c3480..5f63461a 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -2405,15 +2405,19 @@ Address CodeGenFunction::EmitFieldAnnotations(const FieldDecl *D,
assert(D->hasAttr<AnnotateAttr>() && "no annotate attribute");
llvm::Value *V = Addr.getPointer();
llvm::Type *VTy = V->getType();
- llvm::Function *F = CGM.getIntrinsic(llvm::Intrinsic::ptr_annotation,
- CGM.Int8PtrTy);
+ auto *PTy = dyn_cast<llvm::PointerType>(VTy);
+ unsigned AS = PTy ? PTy->getAddressSpace() : 0;
+ llvm::PointerType *IntrinTy =
+ llvm::PointerType::getWithSamePointeeType(CGM.Int8PtrTy, AS);
+ llvm::Function *F =
+ CGM.getIntrinsic(llvm::Intrinsic::ptr_annotation, IntrinTy);
for (const auto *I : D->specific_attrs<AnnotateAttr>()) {
// FIXME Always emit the cast inst so we can differentiate between
// annotation on the first field of a struct and annotation on the struct
// itself.
- if (VTy != CGM.Int8PtrTy)
- V = Builder.CreateBitCast(V, CGM.Int8PtrTy);
+ if (VTy != IntrinTy)
+ V = Builder.CreateBitCast(V, IntrinTy);
V = EmitAnnotationCall(F, V, I->getAnnotation(), D->getLocation(), I);
V = Builder.CreateBitCast(V, VTy);
}