Skip to content

Commit 71097e9

Browse files
[ARM64EC] Add support for parsing __vectorcall (#87725)
MSVC doesn't support generating __vectorcall calls in Arm64EC mode, but it does treat it as a distinct type. The Microsoft STL depends on this functionality. (Not sure if this is intentional.) Add support for parsing the same way as MSVC, and add some checks to ensure we don't try to actually generate code. The error handling in CodeGen is ugly, but I can't think of a better way to do it.
1 parent 4c6ae8e commit 71097e9

File tree

4 files changed

+32
-1
lines changed

4 files changed

+32
-1
lines changed

clang/lib/Basic/Targets/AArch64.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1543,10 +1543,13 @@ WindowsARM64TargetInfo::getBuiltinVaListKind() const {
15431543
TargetInfo::CallingConvCheckResult
15441544
WindowsARM64TargetInfo::checkCallingConvention(CallingConv CC) const {
15451545
switch (CC) {
1546+
case CC_X86VectorCall:
1547+
if (getTriple().isWindowsArm64EC())
1548+
return CCCR_OK;
1549+
return CCCR_Ignore;
15461550
case CC_X86StdCall:
15471551
case CC_X86ThisCall:
15481552
case CC_X86FastCall:
1549-
case CC_X86VectorCall:
15501553
return CCCR_Ignore;
15511554
case CC_C:
15521555
case CC_OpenCLKernel:

clang/lib/CodeGen/CGCall.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5591,6 +5591,12 @@ RValue CodeGenFunction::EmitCall(const CGFunctionInfo &CallInfo,
55915591
/*AttrOnCallSite=*/true,
55925592
/*IsThunk=*/false);
55935593

5594+
if (CallingConv == llvm::CallingConv::X86_VectorCall &&
5595+
getTarget().getTriple().isWindowsArm64EC()) {
5596+
CGM.Error(Loc, "__vectorcall calling convention is not currently "
5597+
"supported");
5598+
}
5599+
55945600
if (const FunctionDecl *FD = dyn_cast_or_null<FunctionDecl>(CurFuncDecl)) {
55955601
if (FD->hasAttr<StrictFPAttr>())
55965602
// All calls within a strictfp function are marked strictfp

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2087,6 +2087,14 @@ void CodeGenModule::SetLLVMFunctionAttributes(GlobalDecl GD,
20872087
llvm::AttributeList PAL;
20882088
ConstructAttributeList(F->getName(), Info, GD, PAL, CallingConv,
20892089
/*AttrOnCallSite=*/false, IsThunk);
2090+
if (CallingConv == llvm::CallingConv::X86_VectorCall &&
2091+
getTarget().getTriple().isWindowsArm64EC()) {
2092+
SourceLocation Loc;
2093+
if (const Decl *D = GD.getDecl())
2094+
Loc = D->getLocation();
2095+
2096+
Error(Loc, "__vectorcall calling convention is not currently supported");
2097+
}
20902098
F->setAttributes(PAL);
20912099
F->setCallingConv(static_cast<llvm::CallingConv::ID>(CallingConv));
20922100
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// RUN: %clang_cc1 -triple arm64ec-windows-msvc -emit-llvm -o - %s -verify
2+
3+
// ARM64EC doesn't support generating __vectorcall calls... but __vectorcall
4+
// function types need to be distinct from __cdecl function types to support
5+
// compiling the STL. Make sure we only diagnose constructs that actually
6+
// require generating code.
7+
void __vectorcall f1();
8+
void f2(void __vectorcall p()) {}
9+
void f2(void p()) {}
10+
void __vectorcall (*f3)();
11+
void __vectorcall f4(); // expected-error {{__vectorcall}}
12+
void __vectorcall f5() { // expected-error {{__vectorcall}}
13+
f4(); // expected-error{{__vectorcall}}
14+
}

0 commit comments

Comments
 (0)