diff --git a/clang/include/clang/Basic/DiagnosticCommonKinds.td b/clang/include/clang/Basic/DiagnosticCommonKinds.td --- a/clang/include/clang/Basic/DiagnosticCommonKinds.td +++ b/clang/include/clang/Basic/DiagnosticCommonKinds.td @@ -243,6 +243,9 @@ def warn_stack_clash_protection_inline_asm : Warning< "Unable to protect inline asm that clobbers stack pointer against stack clash">, InGroup>; + + def warn_slh_does_not_support_asm_goto : Warning< + "Speculative load hardening does not protect functions with asm goto">, InGroup>; } // Sema && Serialization diff --git a/clang/lib/Parse/ParseStmtAsm.cpp b/clang/lib/Parse/ParseStmtAsm.cpp --- a/clang/lib/Parse/ParseStmtAsm.cpp +++ b/clang/lib/Parse/ParseStmtAsm.cpp @@ -729,6 +729,9 @@ 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/asm-goto-slh.cpp b/clang/test/Parser/asm-goto-slh.cpp new file mode 100644 --- /dev/null +++ b/clang/test/Parser/asm-goto-slh.cpp @@ -0,0 +1,5 @@ +// RUN: %clang_cc1 %s -mspeculative-load-hardening -triple x86_64-pc-linux-gnu -emit-llvm -S + +void f() { + __asm goto("movl %ecx, %edx"); // expected-warning {{Speculative load hardening does not protect functions with asm goto}} +}