Hi,

I have a patch that fixes the parsing of command line options for LLVM optimizer plugins. Before this patch, the command line options were parsed before the plugin was loaded. Consequently the options could not be recognized.

OK to commit?

Cheers
Tobi
>From 6b597f8979a3338c3b94a7142756cfea05e0f600 Mon Sep 17 00:00:00 2001
From: Tobias Grosser <[email protected]>
Date: Fri, 7 Oct 2011 22:49:22 +0100
Subject: [PATCH] Parse LLVM command line arguments after plugins have been loaded

This fixes a crash due to command line options, that are not available
before the loading of plugins finished.
---
 lib/FrontendTool/ExecuteCompilerInvocation.cpp |   21 +++++++++++----------
 1 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/lib/FrontendTool/ExecuteCompilerInvocation.cpp b/lib/FrontendTool/ExecuteCompilerInvocation.cpp
index 1b808c1..c9af3cc 100644
--- a/lib/FrontendTool/ExecuteCompilerInvocation.cpp
+++ b/lib/FrontendTool/ExecuteCompilerInvocation.cpp
@@ -133,9 +133,20 @@ bool clang::ExecuteCompilerInvocation(CompilerInstance *Clang) {
     return 0;
   }
 
+  // Load any requested plugins.
+  for (unsigned i = 0,
+         e = Clang->getFrontendOpts().Plugins.size(); i != e; ++i) {
+    const std::string &Path = Clang->getFrontendOpts().Plugins[i];
+    std::string Error;
+    if (llvm::sys::DynamicLibrary::LoadLibraryPermanently(Path.c_str(), &Error))
+      Clang->getDiagnostics().Report(diag::err_fe_unable_to_load_plugin)
+        << Path << Error;
+  }
+
   // Honor -mllvm.
   //
   // FIXME: Remove this, one day.
+  // This should happen AFTER plugins have been loaded!
   if (!Clang->getFrontendOpts().LLVMArgs.empty()) {
     unsigned NumArgs = Clang->getFrontendOpts().LLVMArgs.size();
     const char **Args = new const char*[NumArgs + 2];
@@ -146,16 +157,6 @@ bool clang::ExecuteCompilerInvocation(CompilerInstance *Clang) {
     llvm::cl::ParseCommandLineOptions(NumArgs + 1, const_cast<char **>(Args));
   }
 
-  // Load any requested plugins.
-  for (unsigned i = 0,
-         e = Clang->getFrontendOpts().Plugins.size(); i != e; ++i) {
-    const std::string &Path = Clang->getFrontendOpts().Plugins[i];
-    std::string Error;
-    if (llvm::sys::DynamicLibrary::LoadLibraryPermanently(Path.c_str(), &Error))
-      Clang->getDiagnostics().Report(diag::err_fe_unable_to_load_plugin)
-        << Path << Error;
-  }
-
   // Honor -analyzer-checker-help.
   // This should happen AFTER plugins have been loaded!
   if (Clang->getAnalyzerOpts().ShowCheckerHelp) {
-- 
1.7.4.1

_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to