This is an archive of the discontinued LLVM Phabricator instance.

[Clang][AArch64] Add diagnostic for calls from non-ZA to shared-ZA functions.
ClosedPublic

Authored by sdesmalen on Aug 7 2023, 3:33 AM.

Details

Summary

The caller is required to have ZA state if it wants to share it with a callee.

Diff Detail

Event Timeline

sdesmalen created this revision.Aug 7 2023, 3:33 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 7 2023, 3:33 AM
sdesmalen requested review of this revision.Aug 7 2023, 3:33 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 7 2023, 3:33 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
rsandifo-arm added inline comments.Aug 7 2023, 6:48 AM
clang/lib/Sema/SemaChecking.cpp
6823

Very minor, but it looked odd to me to have |= in this statement and = above.

clang/test/Sema/aarch64-sme-func-attrs.c
181

Would be good to have some tests for indirect function calls too (via function pointers), to make sure that the diagnostic still works when no decl is available.

I suppose this applies to D157269 too.

sdesmalen added inline comments.Aug 7 2023, 7:40 AM
clang/test/Sema/aarch64-sme-func-attrs.c
181

I'm not sure that's necessary because D127762 already added tests to ensure the attributes propagate on pointer types, which then sets the ExtProtoInfo for those values. This patch merely checks the SME attribute fields from ExtProtoInfo. i.e. there is already nothing depending on a declaration being available.

rsandifo-arm added inline comments.Aug 7 2023, 9:18 AM
clang/test/Sema/aarch64-sme-func-attrs.c
181

But Sema::checkCall does have some tests that depend on the decl rather than the type. So the purpose of the test wouldn't be “does the attribute stick when applied to indirect function types?” (which I agree is already covered), but “does the new code correctly process the attribute on the target of a function pointer type?”

sdesmalen updated this revision to Diff 547936.Aug 7 2023, 2:00 PM
sdesmalen marked an inline comment as done.
  • Replaced |= into normal assignment =
  • Added test for global initializer.
clang/test/Sema/aarch64-sme-func-attrs.c
181

The declaration is only relevant for the call-site, not the callee.

if (ExtInfo.AArch64SMEAttributes & FunctionType::SME_PStateZASharedMask) {

The above line checks __arm_shared_za attribute of the callee (could be a decl, or a function pointer, but in either case is a prototyped function with the propagated attributes)

if (auto *CallerFD = dyn_cast<FunctionDecl>(CurContext)) {

The above line checks if the call-site context is a FunctionDecl (or definition for that matter). If the call is not part of a declaration (e.g. it's part of some global initialiser), we know it cannot have any live ZA state (which I now realise is missing a test-case).

So I think that a test like this:

__arm_new_za void foo(void (*f)() __arm_shared_za) { f(); }

is not testing anything that isn't already tested. But perhaps I'm still misunderstanding your point. If so, could you give an example of a test you have in mind?

rsandifo-arm added inline comments.Aug 7 2023, 5:33 PM
clang/test/Sema/aarch64-sme-func-attrs.c
181

That's the kind of test I had in mind.

checkCall does have some conditions that are based on the callee decl rather than the callee type. That is, it does distinguish between direct calls and indirect calls. It would have been easy for the code to be in a block that was guarded with FDecl. Or it could be accidentally rearranged like that in future, especially if the function grows to have several more tests.

And yeah, I agree that the code as-written works, and so it doesn't fall into the trap that is being tested for. But that's true of most tests that get written for new features. :)

So a test for both the direct and indirect cases seemed worthwhile. If we were just going to have one, then I think testing the indirect case is more valuable than testing the direct case, since it's the type rather than the decl that matters.

I won't press the point further though. Feel free to skip the comment if you'd rather keep the tests as they are.

sdesmalen added inline comments.Aug 8 2023, 2:42 AM
clang/test/Sema/aarch64-sme-func-attrs.c
181

Thanks for elaborating, I was mostly trying to understand your reasoning for adding this test.

If we were just going to have one, then I think testing the indirect case is more valuable than testing the direct case, since it's the type rather than the decl that matters.

You're right that the tests should probably have used the indirect case from the start. I see your argument about the code possibly changing in the future. It seems unlikely that someone would add an extra FDecl guard above the block where I've added the code, but I see how that's not really the point. I guess there is little argument not to add another positive test-case to the patch, so I'll just do that.

sdesmalen updated this revision to Diff 548131.Aug 8 2023, 2:46 AM

Added test-cases for indirect calls

aaron.ballman accepted this revision.Aug 8 2023, 5:12 AM

LGTM aside from a nit.

clang/lib/Sema/SemaChecking.cpp
6819
This revision is now accepted and ready to land.Aug 8 2023, 5:12 AM
This revision was landed with ongoing or failed builds.Aug 9 2023, 5:38 AM
This revision was automatically updated to reflect the committed changes.
sdesmalen marked 4 inline comments as done.