[PATCH] D17981: [clang-tidy] Fix clang-tidy to support parsing of assembly statements.

Etienne Bergeron via cfe-commits cfe-commits at lists.llvm.org
Tue Mar 8 21:15:31 PST 2016


etienneb created this revision.
etienneb added reviewers: alexfh, rnk.
etienneb added a subscriber: cfe-commits.


Summary:
Clang-tidy fails when parsing MSVC inline assembly statements. The native target and asm parser aren't initialized.

The following patch is fixing the issue by using the same code than clang-check.
The tool clang-check has the following code in main to initialize the required components.

  // Initialize targets for clang module support.
  llvm::InitializeAllTargets();
  llvm::InitializeAllTargetMCs();
  llvm::InitializeAllAsmPrinters();
  llvm::InitializeAllAsmParsers();

Apparently, it is sufficient to initialize the native target and the asm parser.
see:
https://code.google.com/p/chromium/codesearch#chromium/src/tools/clang/rewrite_scoped_refptr/RewriteScopedRefptr.cpp&l=262

  llvm::InitializeNativeTarget();
  llvm::InitializeNativeTargetAsmParser();

http://reviews.llvm.org/D17981

Files:
  CMakeLists.txt
  ClangTidyMain.cpp

Index: CMakeLists.txt
===================================================================
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -1,4 +1,5 @@
 set(LLVM_LINK_COMPONENTS
+  ${LLVM_TARGETS_TO_BUILD}
   support
   )
 
Index: ClangTidyMain.cpp
===================================================================
--- ClangTidyMain.cpp
+++ ClangTidyMain.cpp
@@ -18,6 +18,8 @@
 #include "../ClangTidy.h"
 #include "clang/Tooling/CommonOptionsParser.h"
 #include "llvm/Support/Process.h"
+#include "llvm/Support/Signals.h"
+#include "llvm/Support/TargetSelect.h"
 
 using namespace clang::ast_matchers;
 using namespace clang::driver;
@@ -296,6 +298,14 @@
 }
 
 static int clangTidyMain(int argc, const char **argv) {
+  llvm::sys::PrintStackTraceOnErrorSignal();
+
+  // Initialize targets for clang module support.
+  llvm::InitializeAllTargets();
+  llvm::InitializeAllTargetMCs();
+  llvm::InitializeAllAsmPrinters();
+  llvm::InitializeAllAsmParsers();
+
   CommonOptionsParser OptionsParser(argc, argv, ClangTidyCategory,
                                     cl::ZeroOrMore);
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D17981.50103.patch
Type: text/x-patch
Size: 1104 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160309/6abb589d/attachment-0001.bin>


More information about the cfe-commits mailing list