[llvm] r201819 - Set the SuppressWarnings option on tool level and propagate to the library.

Eli Bendersky eliben at google.com
Thu Feb 20 14:19:25 PST 2014


Author: eliben
Date: Thu Feb 20 16:19:24 2014
New Revision: 201819

URL: http://llvm.org/viewvc/llvm-project?rev=201819&view=rev
Log:
Set the SuppressWarnings option on tool level and propagate to the library.

The SuppressWarnings flag, unfortunately, isn't very useful for custom tools
that want to use the LLVM module linker. So I'm changing it to a parameter of
the Linker, and the flag itself moves to the llvm-link tool.

For the time being as SuppressWarnings is pretty much the only "option" it
seems reasonable to propagate it to Linker objects. If we end up with more
options in the future, some sort of "struct collecting options" may be a
better idea.


Modified:
    llvm/trunk/include/llvm/Linker.h
    llvm/trunk/lib/Linker/LinkModules.cpp
    llvm/trunk/tools/llvm-link/llvm-link.cpp

Modified: llvm/trunk/include/llvm/Linker.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Linker.h?rev=201819&r1=201818&r2=201819&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Linker.h (original)
+++ llvm/trunk/include/llvm/Linker.h Thu Feb 20 16:19:24 2014
@@ -30,7 +30,7 @@ class Linker {
       PreserveSource = 1 // Preserve the source module.
     };
 
-    Linker(Module *M);
+    Linker(Module *M, bool SuppressWarnings=false);
     ~Linker();
 
     Module *getModule() const { return Composite; }
@@ -52,6 +52,8 @@ class Linker {
   private:
     Module *Composite;
     SmallPtrSet<StructType*, 32> IdentifiedStructTypes;
+
+    bool SuppressWarnings;
 };
 
 } // End llvm namespace

Modified: llvm/trunk/lib/Linker/LinkModules.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Linker/LinkModules.cpp?rev=201819&r1=201818&r2=201819&view=diff
==============================================================================
--- llvm/trunk/lib/Linker/LinkModules.cpp (original)
+++ llvm/trunk/lib/Linker/LinkModules.cpp Thu Feb 20 16:19:24 2014
@@ -27,10 +27,6 @@
 using namespace llvm;
 
 
-static cl::opt<bool>
-SuppressWarnings("suppress-warnings", cl::desc("Suppress all linking warnings"),
-                 cl::init(false));
-
 //===----------------------------------------------------------------------===//
 // TypeMap implementation.
 //===----------------------------------------------------------------------===//
@@ -408,15 +404,18 @@ namespace {
     
     // Vector of functions to lazily link in.
     std::vector<Function*> LazilyLinkFunctions;
+
+    bool SuppressWarnings;
     
   public:
     std::string ErrorMsg;
-    
-    ModuleLinker(Module *dstM, TypeSet &Set, Module *srcM, unsigned mode)
-      : DstM(dstM), SrcM(srcM), TypeMap(Set),
-        ValMaterializer(TypeMap, DstM, LazilyLinkFunctions),
-        Mode(mode) { }
-    
+
+    ModuleLinker(Module *dstM, TypeSet &Set, Module *srcM, unsigned mode,
+                 bool SuppressWarnings=false)
+        : DstM(dstM), SrcM(srcM), TypeMap(Set),
+          ValMaterializer(TypeMap, DstM, LazilyLinkFunctions), Mode(mode),
+          SuppressWarnings(SuppressWarnings) {}
+
     bool run();
     
   private:
@@ -1354,7 +1353,8 @@ bool ModuleLinker::run() {
   return false;
 }
 
-Linker::Linker(Module *M) : Composite(M) {
+Linker::Linker(Module *M, bool SuppressWarnings)
+    : Composite(M), SuppressWarnings(SuppressWarnings) {
   TypeFinder StructTypes;
   StructTypes.run(*M, true);
   IdentifiedStructTypes.insert(StructTypes.begin(), StructTypes.end());
@@ -1369,7 +1369,8 @@ void Linker::deleteModule() {
 }
 
 bool Linker::linkInModule(Module *Src, unsigned Mode, std::string *ErrorMsg) {
-  ModuleLinker TheLinker(Composite, IdentifiedStructTypes, Src, Mode);
+  ModuleLinker TheLinker(Composite, IdentifiedStructTypes, Src, Mode,
+                         SuppressWarnings);
   if (TheLinker.run()) {
     if (ErrorMsg)
       *ErrorMsg = TheLinker.ErrorMsg;

Modified: llvm/trunk/tools/llvm-link/llvm-link.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-link/llvm-link.cpp?rev=201819&r1=201818&r2=201819&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-link/llvm-link.cpp (original)
+++ llvm/trunk/tools/llvm-link/llvm-link.cpp Thu Feb 20 16:19:24 2014
@@ -50,6 +50,10 @@ Verbose("v", cl::desc("Print information
 static cl::opt<bool>
 DumpAsm("d", cl::desc("Print assembly as linked"), cl::Hidden);
 
+static cl::opt<bool>
+SuppressWarnings("suppress-warnings", cl::desc("Suppress all linking warnings"),
+                 cl::init(false));
+
 // LoadFile - Read the specified bitcode file in and return it.  This routine
 // searches the link path for the specified file to try to find it...
 //
@@ -86,7 +90,7 @@ int main(int argc, char **argv) {
     return 1;
   }
 
-  Linker L(Composite.get());
+  Linker L(Composite.get(), SuppressWarnings);
   for (unsigned i = BaseArg+1; i < InputFilenames.size(); ++i) {
     OwningPtr<Module> M(LoadFile(argv[0], InputFilenames[i], Context));
     if (M.get() == 0) {





More information about the llvm-commits mailing list