[PATCH] D63533: [analyzer] Fix clang-tidy crash on GCCAsmStmt

Nathan Huckleberry via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jun 18 17:07:27 PDT 2019


Nathan-Huckleberry created this revision.
Herald added subscribers: cfe-commits, Charusso, dkrupp, donat.nagy, Szelethus, mikhail.ramalho, a.sidorin, szepet, baloghadamsoftware, xazax.hun.
Herald added a project: clang.

Added entry in switch statement to recognize GCCAsmStmt
as a possible block terminator.

Handling to build CFG using GCCAsmStmt was already implemented.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D63533

Files:
  clang-tools-extra/test/clang-tidy/asm-goto.cpp
  clang/lib/StaticAnalyzer/Core/CoreEngine.cpp


Index: clang/lib/StaticAnalyzer/Core/CoreEngine.cpp
===================================================================
--- clang/lib/StaticAnalyzer/Core/CoreEngine.cpp
+++ clang/lib/StaticAnalyzer/Core/CoreEngine.cpp
@@ -396,6 +396,9 @@
       case Stmt::WhileStmtClass:
         HandleBranch(cast<WhileStmt>(Term)->getCond(), Term, B, Pred);
         return;
+
+      case Stmt::GCCAsmStmtClass:
+        return;
     }
   }
 
Index: clang-tools-extra/test/clang-tidy/asm-goto.cpp
===================================================================
--- /dev/null
+++ clang-tools-extra/test/clang-tidy/asm-goto.cpp
@@ -0,0 +1,29 @@
+// REQUIRES: static-analyzer
+// RUN: clang-tidy %s -checks='bugprone-use-after-move' -- | FileCheck %s
+#include <string>
+#include <utility>
+int main() {
+    struct S {
+      std::string str;
+      int i;
+    };
+
+    S s = { "Hello, world!\n", 42 };
+    S s_other = std::move(s);
+    asm goto( "xor %0, %0\n je %l[label1]\n jl %l[label2]" : /* no outputs */ : /* inputs */ : /* clobbers */ : label1, label2 /* any labels used */ );
+    return 0;
+
+    label1:
+    // CHECK: warning: 's' used after it was moved [bugprone-use-after-move]
+    s.str = "ABC";
+    s.i = 99;
+    return 2;
+
+    label2:
+    // There should be a warning here, but UseAfterMoveCheck only reports one
+    // warning per std::move
+    s.str = "DEF";
+    s.i = 100;
+    return 0;
+}
+


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D63533.205478.patch
Type: text/x-patch
Size: 1415 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190619/5360638d/attachment.bin>


More information about the cfe-commits mailing list