[clang] 60ee885 - [clang][asm goto][slh] Warn if asm goto + SLH
Zola Bridges via cfe-commits
cfe-commits at lists.llvm.org
Wed May 20 09:48:34 PDT 2020
Author: Zola Bridges
Date: 2020-05-20T09:46:18-07:00
New Revision: 60ee885990982197013c71ff965a81e938184fd2
URL: https://github.com/llvm/llvm-project/commit/60ee885990982197013c71ff965a81e938184fd2
DIFF: https://github.com/llvm/llvm-project/commit/60ee885990982197013c71ff965a81e938184fd2.diff
LOG: [clang][asm goto][slh] Warn if asm goto + SLH
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
Added:
clang/test/Parser/slh-asm-goto-no-warn.cpp
clang/test/Parser/slh-asm-goto.cpp
Modified:
clang/include/clang/Basic/DiagnosticCommonKinds.td
clang/lib/Parse/ParseStmtAsm.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/Basic/DiagnosticCommonKinds.td b/clang/include/clang/Basic/DiagnosticCommonKinds.td
index 73f55784234e..65e3755efd22 100644
--- a/clang/include/clang/Basic/DiagnosticCommonKinds.td
+++ b/clang/include/clang/Basic/DiagnosticCommonKinds.td
@@ -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
diff --git a/clang/lib/Parse/ParseStmtAsm.cpp b/clang/lib/Parse/ParseStmtAsm.cpp
index 262def2b38a1..0f21037b6100 100644
--- a/clang/lib/Parse/ParseStmtAsm.cpp
+++ b/clang/lib/Parse/ParseStmtAsm.cpp
@@ -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
index 000000000000..b8cfecbdb159
--- /dev/null
+++ b/clang/test/Parser/slh-asm-goto-no-warn.cpp
@@ -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
index 000000000000..7ae3cbdb13e6
--- /dev/null
+++ b/clang/test/Parser/slh-asm-goto.cpp
@@ -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}}
+}
More information about the cfe-commits
mailing list