From: Rafael Espindola Date: Wed, 16 Oct 2013 19:28:50 +0000 (+0000) Subject: Emit a .ident saying that clang produced this file. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9686f1234e1b9a44270452477e6690ccadcd204a;p=clang Emit a .ident saying that clang produced this file. Patch by Katya Romanova. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@192832 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp index 17bca0a6f3..7682efc752 100644 --- a/lib/CodeGen/CodeGenModule.cpp +++ b/lib/CodeGen/CodeGenModule.cpp @@ -35,6 +35,7 @@ #include "clang/Basic/Module.h" #include "clang/Basic/SourceManager.h" #include "clang/Basic/TargetInfo.h" +#include "clang/Basic/Version.h" #include "clang/Frontend/CodeGenOptions.h" #include "llvm/ADT/APSInt.h" #include "llvm/ADT/Triple.h" @@ -204,6 +205,8 @@ void CodeGenModule::Release() { if (DebugInfo) DebugInfo->finalize(); + + EmitVersionIdentMetadata(); } void CodeGenModule::UpdateCompletedType(const TagDecl *TD) { @@ -3034,6 +3037,18 @@ void CodeGenFunction::EmitDeclMetadata() { } } +void CodeGenModule::EmitVersionIdentMetadata() { + llvm::NamedMDNode *IdentMetadata = + TheModule.getOrInsertNamedMetadata("llvm.ident"); + std::string Version = getClangFullVersion(); + llvm::LLVMContext &Ctx = TheModule.getContext(); + + llvm::Value *IdentNode[] = { + llvm::MDString::get(Ctx, Version) + }; + IdentMetadata->addOperand(llvm::MDNode::get(Ctx, IdentNode)); +} + void CodeGenModule::EmitCoverageFile() { if (!getCodeGenOpts().CoverageFile.empty()) { if (llvm::NamedMDNode *CUNode = TheModule.getNamedMetadata("llvm.dbg.cu")) { diff --git a/lib/CodeGen/CodeGenModule.h b/lib/CodeGen/CodeGenModule.h index 1f49802e3e..066009ca7d 100644 --- a/lib/CodeGen/CodeGenModule.h +++ b/lib/CodeGen/CodeGenModule.h @@ -1094,6 +1094,9 @@ private: void EmitDeclMetadata(); + /// \brief Emit the Clang version as llvm.ident metadata. + void EmitVersionIdentMetadata(); + /// EmitCoverageFile - Emit the llvm.gcov metadata used to tell LLVM where /// to emit the .gcno and .gcda files in a way that persists in .bc files. void EmitCoverageFile(); diff --git a/test/CodeGenObjC/ivar-base-as-invariant-load.m b/test/CodeGenObjC/ivar-base-as-invariant-load.m index 8b660cf483..19dc6587f5 100644 --- a/test/CodeGenObjC/ivar-base-as-invariant-load.m +++ b/test/CodeGenObjC/ivar-base-as-invariant-load.m @@ -23,7 +23,7 @@ @end -// CHECK: [[T1:%.*]] = load i64* @"OBJC_IVAR_$_A._flags", !invariant.load !4 -// CHECK: [[T2:%.*]] = load i64* @"OBJC_IVAR_$_A._flags", !invariant.load !4 -// CHECK: [[T3:%.*]] = load i64* @"OBJC_IVAR_$_A._flags", !invariant.load !4 +// CHECK: [[T1:%.*]] = load i64* @"OBJC_IVAR_$_A._flags", !invariant.load !5 +// CHECK: [[T2:%.*]] = load i64* @"OBJC_IVAR_$_A._flags", !invariant.load !5 +// CHECK: [[T3:%.*]] = load i64* @"OBJC_IVAR_$_A._flags", !invariant.load !5 diff --git a/test/Driver/ident_md.c b/test/Driver/ident_md.c new file mode 100644 index 0000000000..d7da31707f --- /dev/null +++ b/test/Driver/ident_md.c @@ -0,0 +1,6 @@ +// RUN: %clang %s -emit-llvm -S -o - | FileCheck %s +// Verify that clang version appears in the llvm.ident metadata. + +// CHECK: !llvm.ident = !{!0} +// CHECK: !0 = metadata !{metadata !{{.*}} +