Naked functions have no prolog, so it's not valid to emit prolog code to evaluate the variably-modified type. This fixes Issue 50541.
Details
Diff Detail
Event Timeline
Other than this 1 thing, LGTM. I DO find myself wondering how much of the CXXMethodDecl bit in the branch above is valid for 'naked' as well. If it ISN'T we might consider moving this loop AND that to EmitFunctionPrologue.
clang/lib/CodeGen/CodeGenFunction.cpp | ||
---|---|---|
1200 | Since you're touching it... this looks like a 'range-for' loop :D |
There's a different kind of bug there. MSVC disallows using the naked attribute on a member function. Clang doesn't enforce this: https://godbolt.org/z/6jKGbzYTq GCC has no such restriction, but GCC doesn't have many diagnostics in this area anyway. We may want to reconsider whether allowing the naked attribute on a non static member function is a good idea. We probably don't want to allow it in MS compatibility mode at the very least. But I think this can be a change for another day. WDYT?
clang/lib/CodeGen/CodeGenFunction.cpp | ||
---|---|---|
1200 | Sure, I can do that. |
Ah! I didn't know the bit about MSVC! I think that makes it even more interesting. From what I can tell however, GCC actually DOES 'do the right thing' with member functions, though the motivation for them is somewhat suspicious. I definitely agree we don't want to allow it in MS Compat mode (and agree that is a different patch). As for in GCC mode, a part of me wants to just DO it and see what the fallout is. The only value I can see for these as non-static member functions is in a template (or perhaps as a virtual function? *shudders*), and I don't see much overlap in the usage there.
clang/test/CodeGen/attr-naked.c | ||
---|---|---|
31 | so in the test, both 'entry' and '%0'/'%1' above are unstable names. You might want to replace both with wildcards. THOUGH, I see other parts of this test have the param names, so IDK? Either way, 'entry' isn't necessarily a stable label. |
I don't have very strong opinions on whether we restrict in non-Microsoft mode, but from what I can tell, the Itanium ABI does do some interesting things for some member functions (having to do with virtual table tables, also having to do with targets that mandate returning this, but otherwise don't seem to do any interesting things in the prolog. So it may be sensible to restrict some situations while still allowing it on member functions. I think for the moment, I'll just restrict on Microsoft mode under the assumption that Itanium is "okay enough" for the moment. But I'll do that in a follow-up patch.
clang/test/CodeGen/attr-naked.c | ||
---|---|---|
31 | Ah, good to know -- I'll correct that. |
Since you're touching it... this looks like a 'range-for' loop :D