This is an archive of the discontinued LLVM Phabricator instance.

[clang codegen] Fix ABI for HVA returns on AArch64 MSVC.
ClosedPublic

Authored by efriedma on Jun 16 2023, 4:13 PM.

Details

Summary

MSVC normally has a bunch of restrictions on returning values directly, which don't apply to passing values directly. (This roughly corresponds to the definition of a C++14 aggregate.) However, these restrictions don't apply to HVAs; make sure we check for that.

Fixes https://github.com/llvm/llvm-project/issues/62223

Diff Detail

Event Timeline

efriedma created this revision.Jun 16 2023, 4:13 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 16 2023, 4:13 PM
efriedma requested review of this revision.Jun 16 2023, 4:13 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 16 2023, 4:13 PM
efriedma updated this revision to Diff 532334.Jun 16 2023, 5:00 PM

Restrict to AArch64.

Actually, it seems like something sort of similar happens with x86 vectorcall. But I haven't tried to test all the permutations of that, so don't modify the behavior for now.

rnk added a comment.Jun 20 2023, 1:43 PM

Interesting. In Clang, we basically layer the C++ rules over the C rules: if C++ aspects of a class allow it to be passed directly transparently, then we defer down to the C rules, which deal with HVAs, structs, and things like that.

Restrict to AArch64.

Actually, it seems like something sort of similar happens with x86 vectorcall. But I haven't tried to test all the permutations of that, so don't modify the behavior for now.

Can you file an issue for that and cc me?

clang/test/CodeGenCXX/homogeneous-aggregates.cpp
294

Can you do the same test again with a non-vector field (double) for test coverage?

295

Did you mean to inherit from base here to make a two-element HVA?

Filed https://github.com/llvm/llvm-project/issues/63417 . (On a related note, I also filed https://github.com/llvm/llvm-project/issues/63360 for an issue I stumbled over involving deleted copy constructors.)

Interesting. In Clang, we basically layer the C++ rules over the C rules: if C++ aspects of a class allow it to be passed directly transparently, then we defer down to the C rules, which deal with HVAs, structs, and things like that.

Yes... clearly MSVC is doing something very different if they're getting results like this by accident.

efriedma updated this revision to Diff 533045.Jun 20 2023, 2:33 PM

Updated testcase.

efriedma updated this revision to Diff 533050.Jun 20 2023, 2:47 PM

Upload correct diff.

rnk accepted this revision.Jun 20 2023, 3:17 PM

lgtm

This revision is now accepted and ready to land.Jun 20 2023, 3:17 PM
rnk added a comment.Jun 20 2023, 3:19 PM

The other thing I'm getting at here is that our TargetInfo.cpp abstraction is pretty well built out, even if it's a huge mess. The C++ rules are generally platform neutral, and we don't usually have to resort to these kinds of triple checks, but sometimes it's the most straightforward approach.

This revision was landed with ongoing or failed builds.Jun 26 2023, 10:46 AM
This revision was automatically updated to reflect the committed changes.