[clang][asm goto][slh] Warn if asm goto + SLH
authorZola Bridges <zbrid@google.com>
Mon, 11 May 2020 20:23:54 +0000 (13:23 -0700)
committerZola Bridges <zbrid@google.com>
Wed, 20 May 2020 16:46:18 +0000 (09:46 -0700)
Summary:
Asm goto is not supported by SLH. Warn if an instance of asm goto is detected
while SLH is enabled.

Test included.

Reviewed By: jyu2

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

clang/include/clang/Basic/DiagnosticCommonKinds.td
clang/lib/Parse/ParseStmtAsm.cpp
clang/test/Parser/slh-asm-goto-no-warn.cpp [new file with mode: 0644]
clang/test/Parser/slh-asm-goto.cpp [new file with mode: 0644]

index 73f5578..65e3755 100644 (file)
@@ -246,6 +246,11 @@ let CategoryName = "Inline Assembly Issue" in {
   def warn_stack_clash_protection_inline_asm : Warning<
     "Unable to protect inline asm that clobbers stack pointer against stack clash">,
     InGroup<DiagGroup<"stack-protector">>;
+
+  def warn_slh_does_not_support_asm_goto
+      : Warning<"Speculative load hardening does not protect functions with "
+                "asm goto">,
+        InGroup<DiagGroup<"slh-asm-goto">>;
 }
 
 // Sema && Serialization
index 262def2..0f21037 100644 (file)
@@ -729,6 +729,9 @@ StmtResult Parser::ParseAsmStatement(bool &msAsm) {
   if (parseGNUAsmQualifierListOpt(GAQ))
     return StmtError();
 
+  if (GAQ.isGoto() && getLangOpts().SpeculativeLoadHardening)
+    Diag(Loc, diag::warn_slh_does_not_support_asm_goto);
+
   BalancedDelimiterTracker T(*this, tok::l_paren);
   T.consumeOpen();
 
diff --git a/clang/test/Parser/slh-asm-goto-no-warn.cpp b/clang/test/Parser/slh-asm-goto-no-warn.cpp
new file mode 100644 (file)
index 0000000..b8cfecb
--- /dev/null
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -Wno-slh-asm-goto -mspeculative-load-hardening -fsyntax-only -verify %s
+
+void f() {
+  __asm goto("movl %ecx, %edx"); // expected-no-diagnostics
+}
diff --git a/clang/test/Parser/slh-asm-goto.cpp b/clang/test/Parser/slh-asm-goto.cpp
new file mode 100644 (file)
index 0000000..7ae3cbd
--- /dev/null
@@ -0,0 +1,5 @@
+// RUN: %clang_cc1 -mspeculative-load-hardening -fsyntax-only -verify %s
+
+void f() {
+  __asm goto("movl %ecx, %edx"); // expected-warning {{Speculative load hardening does not protect functions with asm goto}}
+}