[clang-tidy] Don't error on MS-style inline assembly.
authorZachary Turner <zturner@google.com>
Fri, 20 Oct 2017 23:00:51 +0000 (23:00 +0000)
committerZachary Turner <zturner@google.com>
Fri, 20 Oct 2017 23:00:51 +0000 (23:00 +0000)
To get MS-style inline assembly, we need to link in the various
backends.  Some other clang tools already do this, and this issue
has been raised with clang-tidy several times, indicating there
is sufficient desire to make this work.

Differential Revision: https://reviews.llvm.org/D38549

llvm-svn: 316246

clang-tools-extra/clang-tidy/CMakeLists.txt
clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
clang-tools-extra/test/clang-tidy/hicpp-no-assembler-msvc.cpp [new file with mode: 0644]
clang-tools-extra/test/clang-tidy/hicpp-no-assembler.cpp

index 9d6fc7f..7efc63b 100644 (file)
@@ -1,4 +1,7 @@
 set(LLVM_LINK_COMPONENTS
+  AllTargetsAsmParsers
+  AllTargetsDescs
+  AllTargetsInfos
   Support
   )
 
index a57fde8..79c0d0b 100644 (file)
@@ -18,6 +18,7 @@
 #include "../ClangTidy.h"
 #include "clang/Tooling/CommonOptionsParser.h"
 #include "llvm/Support/Process.h"
+#include "llvm/Support/TargetSelect.h"
 
 using namespace clang::ast_matchers;
 using namespace clang::driver;
@@ -403,6 +404,10 @@ static int clangTidyMain(int argc, const char **argv) {
 
   ProfileData Profile;
 
+  llvm::InitializeAllTargetInfos();
+  llvm::InitializeAllTargetMCs();
+  llvm::InitializeAllAsmParsers();
+
   ClangTidyContext Context(std::move(OwningOptionsProvider));
   runClangTidy(Context, OptionsParser.getCompilations(), PathList,
                EnableCheckProfile ? &Profile : nullptr);
diff --git a/clang-tools-extra/test/clang-tidy/hicpp-no-assembler-msvc.cpp b/clang-tools-extra/test/clang-tidy/hicpp-no-assembler-msvc.cpp
new file mode 100644 (file)
index 0000000..f89e92b
--- /dev/null
@@ -0,0 +1,9 @@
+// REQUIRES: system-windows
+// RUN: %check_clang_tidy %s hicpp-no-assembler %t
+
+void f() {
+  _asm {
+    mov al, 2;
+    // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: do not use inline assembler in safety-critical code [hicpp-no-assembler]
+  }
+}
index d08ea74..9017331 100644 (file)
@@ -9,4 +9,9 @@ static int s asm("spam");
 void f() {
   __asm("mov al, 2");
   // CHECK-MESSAGES: :[[@LINE-1]]:3: warning: do not use inline assembler in safety-critical code [hicpp-no-assembler]
+
+  _asm {
+    mov al, 2;
+    // CHECK-MESSAGES: :[[@LINE-2]]:3: warning: do not use inline assembler in safety-critical code [hicpp-no-assembler]
+  }
 }