[PATCH] D138514: Sema: diagnose PMFs passed through registers to inline assembly
Saleem Abdulrasool via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Dec 2 14:58:32 PST 2022
compnerd updated this revision to Diff 479752.
compnerd marked an inline comment as done.
compnerd added a comment.
Address feedback from review
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D138514/new/
https://reviews.llvm.org/D138514
Files:
clang/include/clang/Basic/DiagnosticSemaKinds.td
clang/lib/Sema/SemaStmtAsm.cpp
clang/test/Sema/gnu-asm-pmf.cpp
Index: clang/test/Sema/gnu-asm-pmf.cpp
===================================================================
--- /dev/null
+++ clang/test/Sema/gnu-asm-pmf.cpp
@@ -0,0 +1,46 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-windows-msvc -std=c++2b -fsyntax-only %s -verify
+// RUN: %clang_cc1 -triple x86_64-unknown-windows-itanium -std=c++2b -fsyntax-only %s -verify
+
+struct S {
+ void operator()();
+};
+
+struct T {
+ virtual void operator()();
+};
+
+struct U {
+ static void operator()();
+};
+
+struct V: virtual T {
+ virtual void f();
+};
+
+struct W : virtual V {
+};
+
+struct X {
+ __UINTPTR_TYPE__ ptr;
+ __UINTPTR_TYPE__ adj;
+};
+
+auto L = [](){};
+
+void f() {
+ auto pmf = &S::operator();
+
+ __asm__ __volatile__ ("" : : "r"(&decltype(L)::operator()));
+ // expected-error at -1{{passing pointer-to-member through register constrained inline assembly parameter is not permitted}}
+ __asm__ __volatile__ ("" : : "r"(&S::operator()));
+ // expected-error at -1{{passing pointer-to-member through register constrained inline assembly parameter is not permitted}}
+ __asm__ __volatile__ ("" : : "r"(&T::operator()));
+ // expected-error at -1{{passing pointer-to-member through register constrained inline assembly parameter is not permitted}}
+ __asm__ __volatile__ ("" : : "r"(pmf));
+ // expected-error at -1{{passing pointer-to-member through register constrained inline assembly parameter is not permitted}}
+ __asm__ __volatile__ ("" : : "r"(&W::f));
+ // expected-error at -1{{passing pointer-to-member through register constrained inline assembly parameter is not permitted}}
+
+ __asm__ __volatile__ ("" : : "r"(X{0,0}));
+ __asm__ __volatile__ ("" : : "r"(&U::operator()));
+}
Index: clang/lib/Sema/SemaStmtAsm.cpp
===================================================================
--- clang/lib/Sema/SemaStmtAsm.cpp
+++ clang/lib/Sema/SemaStmtAsm.cpp
@@ -377,6 +377,11 @@
Expr *InputExpr = Exprs[i];
+ if (InputExpr->getType()->isMemberPointerType())
+ return StmtError(Diag(InputExpr->getBeginLoc(),
+ diag::err_asm_pmf_through_constraint_not_permitted)
+ << InputExpr->getSourceRange());
+
// Referring to parameters is not allowed in naked functions.
if (CheckNakedParmReference(InputExpr, *this))
return StmtError();
Index: clang/include/clang/Basic/DiagnosticSemaKinds.td
===================================================================
--- clang/include/clang/Basic/DiagnosticSemaKinds.td
+++ clang/include/clang/Basic/DiagnosticSemaKinds.td
@@ -8841,6 +8841,9 @@
// inline asm.
let CategoryName = "Inline Assembly Issue" in {
+ def err_asm_pmf_through_constraint_not_permitted
+ : Error<"passing pointer-to-member through register constrained inline "
+ "assembly parameter is not permitted">;
def err_asm_invalid_lvalue_in_output : Error<"invalid lvalue in asm output">;
def err_asm_invalid_output_constraint : Error<
"invalid output constraint '%0' in asm">;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D138514.479752.patch
Type: text/x-patch
Size: 3009 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221202/679bbe2d/attachment.bin>
More information about the cfe-commits
mailing list