aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/CodeGen/CodeGenFunction.cpp
diff options
context:
space:
mode:
authorAlex Richardson <alexrichardson@google.com>2022-11-20 11:38:16 +0000
committerAlex Richardson <alexrichardson@google.com>2022-12-07 18:29:18 +0000
commit9114ac67a986400155b8b82013d09a9e4f48e534 (patch)
tree86def644afc440ee7a8758ab2b814d8cb7c0411a /clang/lib/CodeGen/CodeGenFunction.cpp
parente114979dce339c43e8bcf2c13f6f17dbc310b269 (diff)
downloadllvm-9114ac67a986400155b8b82013d09a9e4f48e534.zip
llvm-9114ac67a986400155b8b82013d09a9e4f48e534.tar.gz
llvm-9114ac67a986400155b8b82013d09a9e4f48e534.tar.bz2
Overload all llvm.annotation intrinsics for globals argument
The global constant arguments could be in a different address space than the first argument, so we have to add another overloaded argument. This patch was originally made for CHERI LLVM (where globals can be in address space 200), but it also appears to be useful for in-tree targets as can be seen from the test diffs. Differential Revision: https://reviews.llvm.org/D138722
Diffstat (limited to 'clang/lib/CodeGen/CodeGenFunction.cpp')
-rw-r--r--clang/lib/CodeGen/CodeGenFunction.cpp17
1 files changed, 11 insertions, 6 deletions
diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp
index e589b6e..a84f129 100644
--- a/clang/lib/CodeGen/CodeGenFunction.cpp
+++ b/clang/lib/CodeGen/CodeGenFunction.cpp
@@ -2460,8 +2460,10 @@ llvm::Value *CodeGenFunction::EmitAnnotationCall(llvm::Function *AnnotationFn,
const AnnotateAttr *Attr) {
SmallVector<llvm::Value *, 5> Args = {
AnnotatedVal,
- Builder.CreateBitCast(CGM.EmitAnnotationString(AnnotationStr), Int8PtrTy),
- Builder.CreateBitCast(CGM.EmitAnnotationUnit(Location), Int8PtrTy),
+ Builder.CreateBitCast(CGM.EmitAnnotationString(AnnotationStr),
+ ConstGlobalsPtrTy),
+ Builder.CreateBitCast(CGM.EmitAnnotationUnit(Location),
+ ConstGlobalsPtrTy),
CGM.EmitAnnotationLineNo(Location),
};
if (Attr)
@@ -2473,9 +2475,12 @@ void CodeGenFunction::EmitVarAnnotations(const VarDecl *D, llvm::Value *V) {
assert(D->hasAttr<AnnotateAttr>() && "no annotate attribute");
// FIXME We create a new bitcast for every annotation because that's what
// llvm-gcc was doing.
+ unsigned AS = V->getType()->getPointerAddressSpace();
+ llvm::Type *I8PtrTy = Builder.getInt8PtrTy(AS);
for (const auto *I : D->specific_attrs<AnnotateAttr>())
- EmitAnnotationCall(CGM.getIntrinsic(llvm::Intrinsic::var_annotation),
- Builder.CreateBitCast(V, CGM.Int8PtrTy, V->getName()),
+ EmitAnnotationCall(CGM.getIntrinsic(llvm::Intrinsic::var_annotation,
+ {I8PtrTy, CGM.ConstGlobalsPtrTy}),
+ Builder.CreateBitCast(V, I8PtrTy, V->getName()),
I->getAnnotation(), D->getLocation(), I);
}
@@ -2488,8 +2493,8 @@ Address CodeGenFunction::EmitFieldAnnotations(const FieldDecl *D,
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);
+ llvm::Function *F = CGM.getIntrinsic(llvm::Intrinsic::ptr_annotation,
+ {IntrinTy, CGM.ConstGlobalsPtrTy});
for (const auto *I : D->specific_attrs<AnnotateAttr>()) {
// FIXME Always emit the cast inst so we can differentiate between