Skip to content

[NFC] Remove getDefaultCallingConvention IsBuiltin #145904

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions clang/include/clang/AST/ASTContext.h
Original file line number Diff line number Diff line change
Expand Up @@ -2914,10 +2914,14 @@ class ASTContext : public RefCountedBase<ASTContext> {
NestedNameSpecifier *
getCanonicalNestedNameSpecifier(NestedNameSpecifier *NNS) const;

/// Retrieves the default calling convention for the current target.
/// Retrieves the default calling convention for the current context.
///
/// The context's default calling convention may differ from the current
/// target's default calling convention if the -fdefault-calling-conv option
/// is used; to get the target's default calling convention, e.g. for built-in
/// functions, call getTargetInfo().getDefaultCallingConv() instead.
CallingConv getDefaultCallingConvention(bool IsVariadic,
bool IsCXXMethod,
bool IsBuiltin = false) const;
bool IsCXXMethod) const;

/// Retrieves the "canonical" template name that refers to a
/// given template.
Expand Down
68 changes: 31 additions & 37 deletions clang/lib/AST/ASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12677,10 +12677,9 @@ QualType ASTContext::GetBuiltinType(unsigned Id,

bool Variadic = (TypeStr[0] == '.');

FunctionType::ExtInfo EI(getDefaultCallingConvention(
Variadic, /*IsCXXMethod=*/false, /*IsBuiltin=*/true));
if (BuiltinInfo.isNoReturn(Id)) EI = EI.withNoReturn(true);

FunctionType::ExtInfo EI(Target->getDefaultCallingConv());
if (BuiltinInfo.isNoReturn(Id))
EI = EI.withNoReturn(true);

// We really shouldn't be making a no-proto type here.
if (ArgTypes.empty() && Variadic && !getLangOpts().requiresStrictPrototypes())
Expand Down Expand Up @@ -13064,43 +13063,38 @@ void ASTContext::forEachMultiversionedFunctionVersion(
}

CallingConv ASTContext::getDefaultCallingConvention(bool IsVariadic,
bool IsCXXMethod,
bool IsBuiltin) const {
bool IsCXXMethod) const {
// Pass through to the C++ ABI object
if (IsCXXMethod)
return ABI->getDefaultMethodCallConv(IsVariadic);

// Builtins ignore user-specified default calling convention and remain the
// Target's default calling convention.
if (!IsBuiltin) {
switch (LangOpts.getDefaultCallingConv()) {
case LangOptions::DCC_None:
break;
case LangOptions::DCC_CDecl:
return CC_C;
case LangOptions::DCC_FastCall:
if (getTargetInfo().hasFeature("sse2") && !IsVariadic)
return CC_X86FastCall;
break;
case LangOptions::DCC_StdCall:
if (!IsVariadic)
return CC_X86StdCall;
break;
case LangOptions::DCC_VectorCall:
// __vectorcall cannot be applied to variadic functions.
if (!IsVariadic)
return CC_X86VectorCall;
break;
case LangOptions::DCC_RegCall:
// __regcall cannot be applied to variadic functions.
if (!IsVariadic)
return CC_X86RegCall;
break;
case LangOptions::DCC_RtdCall:
if (!IsVariadic)
return CC_M68kRTD;
break;
}
switch (LangOpts.getDefaultCallingConv()) {
case LangOptions::DCC_None:
break;
case LangOptions::DCC_CDecl:
return CC_C;
case LangOptions::DCC_FastCall:
if (getTargetInfo().hasFeature("sse2") && !IsVariadic)
return CC_X86FastCall;
break;
case LangOptions::DCC_StdCall:
if (!IsVariadic)
return CC_X86StdCall;
break;
case LangOptions::DCC_VectorCall:
// __vectorcall cannot be applied to variadic functions.
if (!IsVariadic)
return CC_X86VectorCall;
break;
case LangOptions::DCC_RegCall:
// __regcall cannot be applied to variadic functions.
if (!IsVariadic)
return CC_X86RegCall;
break;
case LangOptions::DCC_RtdCall:
if (!IsVariadic)
return CC_M68kRTD;
break;
}
return Target->getDefaultCallingConv();
}
Expand Down
4 changes: 2 additions & 2 deletions clang/lib/Sema/SemaExprCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3467,8 +3467,8 @@ void Sema::DeclareGlobalAllocationFunction(DeclarationName Name,
}
}

FunctionProtoType::ExtProtoInfo EPI(Context.getDefaultCallingConvention(
/*IsVariadic=*/false, /*IsCXXMethod=*/false, /*IsBuiltin=*/true));
FunctionProtoType::ExtProtoInfo EPI(
Context.getTargetInfo().getDefaultCallingConv());

QualType BadAllocType;
bool HasBadAllocExceptionSpec = Name.isAnyOperatorNew();
Expand Down
3 changes: 2 additions & 1 deletion clang/lib/Sema/SemaLookup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "clang/AST/ExprCXX.h"
#include "clang/Basic/Builtins.h"
#include "clang/Basic/LangOptions.h"
#include "clang/Basic/TargetInfo.h"
#include "clang/Lex/HeaderSearch.h"
#include "clang/Lex/ModuleLoader.h"
#include "clang/Lex/Preprocessor.h"
Expand Down Expand Up @@ -777,7 +778,7 @@ static void GetOpenCLBuiltinFctOverloads(
std::vector<QualType> &FunctionList, SmallVector<QualType, 1> &RetTypes,
SmallVector<SmallVector<QualType, 1>, 5> &ArgTypes) {
FunctionProtoType::ExtProtoInfo PI(
Context.getDefaultCallingConvention(false, false, true));
Context.getTargetInfo().getDefaultCallingConv());
PI.Variadic = false;

// Do not attempt to create any FunctionTypes if there are no return types,
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/Sema/SemaRISCV.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ void RISCVIntrinsicManagerImpl::CreateRVVIntrinsicDecl(LookupResult &LR,
ArgTypes.push_back(RVVType2Qual(Context, Sigs[i]));

FunctionProtoType::ExtProtoInfo PI(
Context.getDefaultCallingConvention(false, false, true));
Context.getTargetInfo().getDefaultCallingConv());

PI.Variadic = false;

Expand Down