[PATCH] D138514: Sema: diagnose PMFs passed through registers to inline assembly

Reid Kleckner via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 22 16:07:01 PST 2022


rnk added inline comments.


================
Comment at: clang/lib/Sema/SemaStmtAsm.cpp:381
+    if (!Context.getTargetInfo().getCXXABI().isMicrosoft())
+      if (const auto *UO = dyn_cast<UnaryOperator>(InputExpr))
+        if (UO->getOpcode() == UO_AddrOf)
----------------
This is too narrow, there are lots of other ways to do this:
```
struct Foo { void method(); };
void f() {
  auto pmf = &Foo::method;
  asm volatile ("" : : "r"(pmf));
}
```

I think it makes sense to check for:
* An expression with a member pointer type
* Where the size of the type is larger than the size of a pointer, or word, or whatever proxy we normally use for the size of a general purpose register

In the Microsoft ABI, member function pointers are only sometimes pointer-sized. If the class uses the multiple inheritance model, it will be bigger and include the this-adjuster field. See the inheritance keyword docs to learn more:
https://learn.microsoft.com/en-us/cpp/cpp/inheritance-keywords?view=msvc-170

This also handles large pointers to data members in the MS ABI, which also has a wacky aggregate representation.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D138514/new/

https://reviews.llvm.org/D138514



More information about the cfe-commits mailing list