Skip to content

Commit 0bf37a6

Browse files
committed
[NFC] Remove getDefaultCallingConvention IsBuiltin
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 a76448c commit 0bf37a6

File tree

5 files changed

+43
-44
lines changed

5 files changed

+43
-44
lines changed

clang/include/clang/AST/ASTContext.h

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

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

29222926
/// Retrieves the "canonical" template name that refers to a
29232927
/// given template.

clang/lib/AST/ASTContext.cpp

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

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

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

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

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

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

clang/lib/Sema/SemaExprCXX.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3467,8 +3467,8 @@ void Sema::DeclareGlobalAllocationFunction(DeclarationName Name,
34673467
}
34683468
}
34693469

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

34733473
QualType BadAllocType;
34743474
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)