Skip to content

Commit 66e707e

Browse files
authored
[NFC] Remove getDefaultCallingConvention IsBuiltin (#145904)
ASTContext::getDefaultCallingConvention() was documented as returning "the default calling convention for the current target", but did not do this, and was never intended to do this, it has always been controlled by command-line options to deviate from the target default. This commit changes ASTContext::getDefaultCallingConvention() to reflect the fact that it returns the context's default calling convention, not the target's default calling convention. The IsBuiltin parameter, which was used to return the target's default calling convention rather than the context's, is removed in favor of getTargetInfo().getDefaultCallingConv() which is more explicit of the intent.
1 parent 3b41e4d commit 66e707e

File tree

6 files changed

+48
-46
lines changed

6 files changed

+48
-46
lines changed

clang/include/clang/AST/ASTContext.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2916,10 +2916,14 @@ class ASTContext : public RefCountedBase<ASTContext> {
29162916
NestedNameSpecifier *
29172917
getCanonicalNestedNameSpecifier(NestedNameSpecifier *NNS) const;
29182918

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

29242928
/// Retrieves the "canonical" template name that refers to a
29252929
/// given template.

clang/include/clang/Basic/TargetInfo.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1698,8 +1698,11 @@ class TargetInfo : public TransferrableTargetInfo,
16981698
/// Controls if __arithmetic_fence is supported in the targeted backend.
16991699
virtual bool checkArithmeticFenceSupported() const { return false; }
17001700

1701-
/// Gets the default calling convention for the given target and
1702-
/// declaration context.
1701+
/// Gets the default calling convention for the given target.
1702+
///
1703+
/// This function does not take into account any user options to override the
1704+
/// default calling convention. For that, see
1705+
/// ASTContext::getDefaultCallingConvention().
17031706
virtual CallingConv getDefaultCallingConv() const {
17041707
// Not all targets will specify an explicit calling convention that we can
17051708
// express. This will always do the right thing, even though it's not

clang/lib/AST/ASTContext.cpp

Lines changed: 31 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -12678,10 +12678,9 @@ QualType ASTContext::GetBuiltinType(unsigned Id,
1267812678

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

12681-
FunctionType::ExtInfo EI(getDefaultCallingConvention(
12682-
Variadic, /*IsCXXMethod=*/false, /*IsBuiltin=*/true));
12683-
if (BuiltinInfo.isNoReturn(Id)) EI = EI.withNoReturn(true);
12684-
12681+
FunctionType::ExtInfo EI(Target->getDefaultCallingConv());
12682+
if (BuiltinInfo.isNoReturn(Id))
12683+
EI = EI.withNoReturn(true);
1268512684

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

1306713066
CallingConv ASTContext::getDefaultCallingConvention(bool IsVariadic,
13068-
bool IsCXXMethod,
13069-
bool IsBuiltin) const {
13067+
bool IsCXXMethod) const {
1307013068
// Pass through to the C++ ABI object
1307113069
if (IsCXXMethod)
1307213070
return ABI->getDefaultMethodCallConv(IsVariadic);
1307313071

13074-
// Builtins ignore user-specified default calling convention and remain the
13075-
// Target's default calling convention.
13076-
if (!IsBuiltin) {
13077-
switch (LangOpts.getDefaultCallingConv()) {
13078-
case LangOptions::DCC_None:
13079-
break;
13080-
case LangOptions::DCC_CDecl:
13081-
return CC_C;
13082-
case LangOptions::DCC_FastCall:
13083-
if (getTargetInfo().hasFeature("sse2") && !IsVariadic)
13084-
return CC_X86FastCall;
13085-
break;
13086-
case LangOptions::DCC_StdCall:
13087-
if (!IsVariadic)
13088-
return CC_X86StdCall;
13089-
break;
13090-
case LangOptions::DCC_VectorCall:
13091-
// __vectorcall cannot be applied to variadic functions.
13092-
if (!IsVariadic)
13093-
return CC_X86VectorCall;
13094-
break;
13095-
case LangOptions::DCC_RegCall:
13096-
// __regcall cannot be applied to variadic functions.
13097-
if (!IsVariadic)
13098-
return CC_X86RegCall;
13099-
break;
13100-
case LangOptions::DCC_RtdCall:
13101-
if (!IsVariadic)
13102-
return CC_M68kRTD;
13103-
break;
13104-
}
13072+
switch (LangOpts.getDefaultCallingConv()) {
13073+
case LangOptions::DCC_None:
13074+
break;
13075+
case LangOptions::DCC_CDecl:
13076+
return CC_C;
13077+
case LangOptions::DCC_FastCall:
13078+
if (getTargetInfo().hasFeature("sse2") && !IsVariadic)
13079+
return CC_X86FastCall;
13080+
break;
13081+
case LangOptions::DCC_StdCall:
13082+
if (!IsVariadic)
13083+
return CC_X86StdCall;
13084+
break;
13085+
case LangOptions::DCC_VectorCall:
13086+
// __vectorcall cannot be applied to variadic functions.
13087+
if (!IsVariadic)
13088+
return CC_X86VectorCall;
13089+
break;
13090+
case LangOptions::DCC_RegCall:
13091+
// __regcall cannot be applied to variadic functions.
13092+
if (!IsVariadic)
13093+
return CC_X86RegCall;
13094+
break;
13095+
case LangOptions::DCC_RtdCall:
13096+
if (!IsVariadic)
13097+
return CC_M68kRTD;
13098+
break;
1310513099
}
1310613100
return Target->getDefaultCallingConv();
1310713101
}

clang/lib/Sema/SemaExprCXX.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3477,8 +3477,8 @@ void Sema::DeclareGlobalAllocationFunction(DeclarationName Name,
34773477
}
34783478
}
34793479

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

34833483
QualType BadAllocType;
34843484
bool HasBadAllocExceptionSpec = Name.isAnyOperatorNew();

clang/lib/Sema/SemaLookup.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "clang/AST/ExprCXX.h"
2323
#include "clang/Basic/Builtins.h"
2424
#include "clang/Basic/LangOptions.h"
25+
#include "clang/Basic/TargetInfo.h"
2526
#include "clang/Lex/HeaderSearch.h"
2627
#include "clang/Lex/ModuleLoader.h"
2728
#include "clang/Lex/Preprocessor.h"
@@ -777,7 +778,7 @@ static void GetOpenCLBuiltinFctOverloads(
777778
std::vector<QualType> &FunctionList, SmallVector<QualType, 1> &RetTypes,
778779
SmallVector<SmallVector<QualType, 1>, 5> &ArgTypes) {
779780
FunctionProtoType::ExtProtoInfo PI(
780-
Context.getDefaultCallingConvention(false, false, true));
781+
Context.getTargetInfo().getDefaultCallingConv());
781782
PI.Variadic = false;
782783

783784
// Do not attempt to create any FunctionTypes if there are no return types,

clang/lib/Sema/SemaRISCV.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ void RISCVIntrinsicManagerImpl::CreateRVVIntrinsicDecl(LookupResult &LR,
417417
ArgTypes.push_back(RVVType2Qual(Context, Sigs[i]));
418418

419419
FunctionProtoType::ExtProtoInfo PI(
420-
Context.getDefaultCallingConvention(false, false, true));
420+
Context.getTargetInfo().getDefaultCallingConv());
421421

422422
PI.Variadic = false;
423423

0 commit comments

Comments
 (0)