Skip to content

Commit 45ca613

Browse files
authored
[clang] Use TargetInfo to decide Mangling for C (#129920)
Instead of hardcoding the decision on what mangling scheme to use based on targets, use TargetInfo to make the decision.
1 parent c28c508 commit 45ca613

File tree

4 files changed

+12
-5
lines changed

4 files changed

+12
-5
lines changed

clang/include/clang/Basic/TargetInfo.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ class TargetInfo : public TransferrableTargetInfo,
253253
const char *MCountName;
254254
unsigned char RegParmMax, SSERegParmMax;
255255
TargetCXXABI TheCXXABI;
256+
bool UseMicrosoftManglingForC = false;
256257
const LangASMap *AddrSpaceMap;
257258

258259
mutable StringRef PlatformName;
@@ -1344,6 +1345,11 @@ class TargetInfo : public TransferrableTargetInfo,
13441345
return TheCXXABI;
13451346
}
13461347

1348+
/// Should the Microsoft mangling scheme be used for C Calling Convention.
1349+
bool shouldUseMicrosoftCCforMangling() const {
1350+
return UseMicrosoftManglingForC;
1351+
}
1352+
13471353
/// Target the specified CPU.
13481354
///
13491355
/// \return False on error (invalid CPU name).

clang/lib/AST/Mangle.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ static CCMangling getCallingConvMangling(const ASTContext &Context,
7474
if (FD->isMain() && FD->getNumParams() == 2)
7575
return CCM_WasmMainArgcArgv;
7676

77-
if (!Triple.isOSWindows() || !Triple.isX86())
77+
if (!TI.shouldUseMicrosoftCCforMangling())
7878
return CCM_Other;
7979

8080
if (Context.getLangOpts().CPlusPlus && !isExternC(ND) &&

clang/lib/Basic/Targets/OSTargets.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -817,6 +817,7 @@ class LLVM_LIBRARY_VISIBILITY UEFITargetInfo : public OSTargetInfo<Target> {
817817
: OSTargetInfo<Target>(Triple, Opts) {
818818
this->WCharType = TargetInfo::UnsignedShort;
819819
this->WIntType = TargetInfo::UnsignedShort;
820+
this->UseMicrosoftManglingForC = true;
820821
}
821822
};
822823

@@ -837,6 +838,7 @@ class LLVM_LIBRARY_VISIBILITY WindowsTargetInfo : public OSTargetInfo<Target> {
837838
: OSTargetInfo<Target>(Triple, Opts) {
838839
this->WCharType = TargetInfo::UnsignedShort;
839840
this->WIntType = TargetInfo::UnsignedShort;
841+
this->UseMicrosoftManglingForC = true;
840842
}
841843
};
842844

clang/lib/Sema/SemaExpr.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17978,10 +17978,9 @@ static bool isPotentiallyConstantEvaluatedContext(Sema &SemaRef) {
1797817978
/// Return true if this function has a calling convention that requires mangling
1797917979
/// in the size of the parameter pack.
1798017980
static bool funcHasParameterSizeMangling(Sema &S, FunctionDecl *FD) {
17981-
// These manglings don't do anything on non-Windows or non-x86 platforms, so
17982-
// we don't need parameter type sizes.
17983-
const llvm::Triple &TT = S.Context.getTargetInfo().getTriple();
17984-
if (!TT.isOSWindows() || !TT.isX86())
17981+
// These manglings are only applicable for targets whcih use Microsoft
17982+
// mangling scheme for C.
17983+
if (!S.Context.getTargetInfo().shouldUseMicrosoftCCforMangling())
1798517984
return false;
1798617985

1798717986
// If this is C++ and this isn't an extern "C" function, parameters do not

0 commit comments

Comments
 (0)