[clang-tools-extra] r316246 - [clang-tidy] Don't error on MS-style inline assembly.

Zachary Turner via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 20 16:00:51 PDT 2017


Author: zturner
Date: Fri Oct 20 16:00:51 2017
New Revision: 316246

URL: http://llvm.org/viewvc/llvm-project?rev=316246&view=rev
Log:
[clang-tidy] Don't error on MS-style inline assembly.

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

Added:
    clang-tools-extra/trunk/test/clang-tidy/hicpp-no-assembler-msvc.cpp
Modified:
    clang-tools-extra/trunk/clang-tidy/CMakeLists.txt
    clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp
    clang-tools-extra/trunk/test/clang-tidy/hicpp-no-assembler.cpp

Modified: clang-tools-extra/trunk/clang-tidy/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/CMakeLists.txt?rev=316246&r1=316245&r2=316246&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/CMakeLists.txt (original)
+++ clang-tools-extra/trunk/clang-tidy/CMakeLists.txt Fri Oct 20 16:00:51 2017
@@ -1,4 +1,7 @@
 set(LLVM_LINK_COMPONENTS
+  AllTargetsAsmParsers
+  AllTargetsDescs
+  AllTargetsInfos
   Support
   )
 

Modified: clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp?rev=316246&r1=316245&r2=316246&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp Fri Oct 20 16:00:51 2017
@@ -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
 
   ProfileData Profile;
 
+  llvm::InitializeAllTargetInfos();
+  llvm::InitializeAllTargetMCs();
+  llvm::InitializeAllAsmParsers();
+
   ClangTidyContext Context(std::move(OwningOptionsProvider));
   runClangTidy(Context, OptionsParser.getCompilations(), PathList,
                EnableCheckProfile ? &Profile : nullptr);

Added: clang-tools-extra/trunk/test/clang-tidy/hicpp-no-assembler-msvc.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/hicpp-no-assembler-msvc.cpp?rev=316246&view=auto
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/hicpp-no-assembler-msvc.cpp (added)
+++ clang-tools-extra/trunk/test/clang-tidy/hicpp-no-assembler-msvc.cpp Fri Oct 20 16:00:51 2017
@@ -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]
+  }
+}

Modified: clang-tools-extra/trunk/test/clang-tidy/hicpp-no-assembler.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/hicpp-no-assembler.cpp?rev=316246&r1=316245&r2=316246&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/hicpp-no-assembler.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/hicpp-no-assembler.cpp Fri Oct 20 16:00:51 2017
@@ -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]
+  }
 }




More information about the cfe-commits mailing list