From f21c081b78ec7a83a79137c65edd58874b262761 Mon Sep 17 00:00:00 2001 From: Nicolai Hähnle Date: Wed, 5 Jun 2019 21:35:30 +0200 Subject: CodeGen: Allow annotations on globals in non-zero address space Summary: Attribute annotations are recorded in a special global composite variable that points to annotation strings and the annotated objects. As a restriction of the LLVM IR type system, those pointers are all pointers to address space 0, so let's insert an addrspacecast when the annotated global is in a non-0 address space. Since this addrspacecast is only reachable from the global annotations object, this should allow us to represent annotations on all globals regardless of which addrspacecasts are usually legal for the target. Reviewers: rjmccall Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D71208 --- clang/lib/CodeGen/CodeGenModule.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'clang/lib/CodeGen/CodeGenModule.cpp') diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index d3d3df8c66b..3805eae17b3 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -2212,9 +2212,15 @@ llvm::Constant *CodeGenModule::EmitAnnotateAttr(llvm::GlobalValue *GV, *UnitGV = EmitAnnotationUnit(L), *LineNoCst = EmitAnnotationLineNo(L); + llvm::Constant *ASZeroGV = GV; + if (GV->getAddressSpace() != 0) { + ASZeroGV = llvm::ConstantExpr::getAddrSpaceCast( + GV, GV->getValueType()->getPointerTo(0)); + } + // Create the ConstantStruct for the global annotation. llvm::Constant *Fields[4] = { - llvm::ConstantExpr::getBitCast(GV, Int8PtrTy), + llvm::ConstantExpr::getBitCast(ASZeroGV, Int8PtrTy), llvm::ConstantExpr::getBitCast(AnnoGV, Int8PtrTy), llvm::ConstantExpr::getBitCast(UnitGV, Int8PtrTy), LineNoCst -- cgit v1.2.3