r192832 - Emit a .ident saying that clang produced this file.

Rafael Espindola rafael.espindola at gmail.com
Wed Oct 16 12:28:50 PDT 2013


Author: rafael
Date: Wed Oct 16 14:28:50 2013
New Revision: 192832

URL: http://llvm.org/viewvc/llvm-project?rev=192832&view=rev
Log:
Emit a .ident saying that clang produced this file.

Patch by Katya Romanova.

Added:
    cfe/trunk/test/Driver/ident_md.c
Modified:
    cfe/trunk/lib/CodeGen/CodeGenModule.cpp
    cfe/trunk/lib/CodeGen/CodeGenModule.h
    cfe/trunk/test/CodeGenObjC/ivar-base-as-invariant-load.m

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.cpp?rev=192832&r1=192831&r2=192832&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.cpp Wed Oct 16 14:28:50 2013
@@ -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")) {

Modified: cfe/trunk/lib/CodeGen/CodeGenModule.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenModule.h?rev=192832&r1=192831&r2=192832&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenModule.h (original)
+++ cfe/trunk/lib/CodeGen/CodeGenModule.h Wed Oct 16 14:28:50 2013
@@ -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();

Modified: cfe/trunk/test/CodeGenObjC/ivar-base-as-invariant-load.m
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenObjC/ivar-base-as-invariant-load.m?rev=192832&r1=192831&r2=192832&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenObjC/ivar-base-as-invariant-load.m (original)
+++ cfe/trunk/test/CodeGenObjC/ivar-base-as-invariant-load.m Wed Oct 16 14:28:50 2013
@@ -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
 

Added: cfe/trunk/test/Driver/ident_md.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/ident_md.c?rev=192832&view=auto
==============================================================================
--- cfe/trunk/test/Driver/ident_md.c (added)
+++ cfe/trunk/test/Driver/ident_md.c Wed Oct 16 14:28:50 2013
@@ -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 !{{.*}}
+





More information about the cfe-commits mailing list