[PATCH] D99517: Implemented [[clang::musttail]] attribute for guaranteed tail calls.

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat Apr 3 09:36:04 PDT 2021


aaron.ballman added inline comments.


================
Comment at: clang/include/clang/Basic/AttrDocs.td:458
+same number of arguments as the caller. The types of the return value and all
+arguments must be similar, including the implicit "this" argument, if any.
+Any variables in scope, including all arguments to the function and the
----------------
It'd be nice if we could nail down "similar" somewhat. I don't know if `int` and `short` are similar (due to promotions) or `const int` and `int` are similar, etc.


================
Comment at: clang/include/clang/Basic/AttrDocs.td:461-462
+return value must be trivially destructible. The calling convention of the
+caller and callee must match, and they must not have old style K&R C function
+declarations.
+  }];
----------------
Not only is this not usable with K&R C declarations, but it's also not usable with `...` variadic functions either, right?


================
Comment at: clang/lib/Sema/SemaStmt.cpp:561-568
+  for (const auto *A : Attrs) {
+    if (A->getKind() == attr::MustTail) {
+      if (!checkMustTailAttr(SubStmt, *A)) {
+        return SubStmt;
+      }
+      setFunctionHasMustTail();
+    }
----------------
haberman wrote:
> aaron.ballman wrote:
> > This functionality belongs in SemaStmtAttr.cpp, I think.
> That is where I had originally put it, but that didn't work for templates. The semantic checks can only be performed at instantiation time. `ActOnAttributedStmt` seems to be the right hook point where I can evaluate the semantic checks for both template and non-template functions (with template functions getting checked at instantiation time).
I disagree that `ActOnAttributedStmt()` is the correct place for this checking -- template checking should occur when the template is instantiated, same as happens for declaration attributes. I'd like to see this functionality moved to SemaStmtAttr.cpp. Keeping the attribute logic together and following the same patterns is what allows us to tablegenerate more of the attribute logic. Statement attributes are just starting to get more such automation.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D99517



More information about the cfe-commits mailing list