diff options
Diffstat (limited to 'clang/lib/CodeGen')
-rw-r--r-- | clang/lib/CodeGen/CodeGenModule.cpp | 17 | ||||
-rw-r--r-- | clang/lib/CodeGen/CodeGenModule.h | 3 |
2 files changed, 20 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/CodeGenModule.cpp b/clang/lib/CodeGen/CodeGenModule.cpp index cb34fb5a731..a5a51b19c79 100644 --- a/clang/lib/CodeGen/CodeGenModule.cpp +++ b/clang/lib/CodeGen/CodeGenModule.cpp @@ -44,6 +44,7 @@ CodeGenModule::~CodeGenModule() { if (ObjCInitFunction) AddGlobalCtor(ObjCInitFunction); EmitGlobalCtors(); + EmitAnnotations(); delete Runtime; } @@ -123,6 +124,22 @@ void CodeGenModule::EmitGlobalCtors() { +void CodeGenModule::EmitAnnotations() { + if (Annotations.empty()) + return; + + // Create a new global variable for the ConstantStruct in the Module. + llvm::Constant *Array = + llvm::ConstantArray::get(llvm::ArrayType::get(Annotations[0]->getType(), + Annotations.size()), + Annotations); + llvm::GlobalValue *gv = + new llvm::GlobalVariable(Array->getType(), false, + llvm::GlobalValue::AppendingLinkage, Array, + "llvm.global.annotations", &TheModule); + gv->setSection("llvm.metadata"); +} + /// ReplaceMapValuesWith - This is a really slow and bad function that /// searches for any entries in GlobalDeclMap that point to OldVal, changing /// them to point to NewVal. This is badbadbad, FIXME! diff --git a/clang/lib/CodeGen/CodeGenModule.h b/clang/lib/CodeGen/CodeGenModule.h index 3fcb56e3c4f..e192e9913ee 100644 --- a/clang/lib/CodeGen/CodeGenModule.h +++ b/clang/lib/CodeGen/CodeGenModule.h @@ -59,6 +59,7 @@ class CodeGenModule { llvm::Function *MemSetFn; llvm::DenseMap<const Decl*, llvm::Constant*> GlobalDeclMap; std::vector<llvm::Constant*> GlobalCtors; + std::vector<llvm::Constant*> Annotations; llvm::StringMap<llvm::Constant*> CFConstantStringMap; llvm::StringMap<llvm::Constant*> ConstantStringMap; @@ -99,6 +100,8 @@ public: void AddGlobalCtor(llvm::Function * Ctor); void EmitGlobalCtors(void); + void AddAnnotation(llvm::Constant *C) { Annotations.push_back(C); } + void EmitAnnotations(void); void EmitObjCMethod(const ObjCMethodDecl *OMD); void EmitFunction(const FunctionDecl *FD); |