[clang] [clang] Use TargetInfo to decide Mangling for C (PR #129920)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Mar 5 11:44:39 PST 2025
https://github.com/Prabhuk created https://github.com/llvm/llvm-project/pull/129920
Instead of hardcoding the decision on what mangling scheme to use based
on targets, use TargetInfo to make the decision.
>From 50204fcef930b215c9494b92b8c54a19d3821d5b Mon Sep 17 00:00:00 2001
From: prabhukr <prabhukr at google.com>
Date: Wed, 5 Mar 2025 19:40:31 +0000
Subject: [PATCH] [clang] Use TargetInfo to decide Mangling for C
Instead of hardcoding the decision on what mangling scheme to use based
on targets, use TargetInfo to make the decision.
---
clang/include/clang/Basic/TargetInfo.h | 6 ++++++
clang/lib/AST/Mangle.cpp | 2 +-
clang/lib/Basic/Targets/OSTargets.h | 2 ++
clang/lib/Sema/SemaExpr.cpp | 7 +++----
4 files changed, 12 insertions(+), 5 deletions(-)
diff --git a/clang/include/clang/Basic/TargetInfo.h b/clang/include/clang/Basic/TargetInfo.h
index 291cf26cb2e78..d136b459e9cd4 100644
--- a/clang/include/clang/Basic/TargetInfo.h
+++ b/clang/include/clang/Basic/TargetInfo.h
@@ -253,6 +253,7 @@ class TargetInfo : public TransferrableTargetInfo,
const char *MCountName;
unsigned char RegParmMax, SSERegParmMax;
TargetCXXABI TheCXXABI;
+ bool UseMicrosoftManglingForC = false;
const LangASMap *AddrSpaceMap;
mutable StringRef PlatformName;
@@ -1344,6 +1345,11 @@ class TargetInfo : public TransferrableTargetInfo,
return TheCXXABI;
}
+ /// Should the Microsoft mangling scheme be used for C Calling Convention.
+ bool shouldUseMicrosoftCCforMangling() const {
+ return UseMicrosoftManglingForC;
+ }
+
/// Target the specified CPU.
///
/// \return False on error (invalid CPU name).
diff --git a/clang/lib/AST/Mangle.cpp b/clang/lib/AST/Mangle.cpp
index 15be9c62bf888..4c4f2038c51e6 100644
--- a/clang/lib/AST/Mangle.cpp
+++ b/clang/lib/AST/Mangle.cpp
@@ -74,7 +74,7 @@ static CCMangling getCallingConvMangling(const ASTContext &Context,
if (FD->isMain() && FD->getNumParams() == 2)
return CCM_WasmMainArgcArgv;
- if (!Triple.isOSWindows() || !Triple.isX86())
+ if (!TI.shouldUseMicrosoftCCforMangling())
return CCM_Other;
if (Context.getLangOpts().CPlusPlus && !isExternC(ND) &&
diff --git a/clang/lib/Basic/Targets/OSTargets.h b/clang/lib/Basic/Targets/OSTargets.h
index 991efd2bde01f..a88c851797aab 100644
--- a/clang/lib/Basic/Targets/OSTargets.h
+++ b/clang/lib/Basic/Targets/OSTargets.h
@@ -817,6 +817,7 @@ class LLVM_LIBRARY_VISIBILITY UEFITargetInfo : public OSTargetInfo<Target> {
: OSTargetInfo<Target>(Triple, Opts) {
this->WCharType = TargetInfo::UnsignedShort;
this->WIntType = TargetInfo::UnsignedShort;
+ this->UseMicrosoftManglingForC = true;
}
};
@@ -837,6 +838,7 @@ class LLVM_LIBRARY_VISIBILITY WindowsTargetInfo : public OSTargetInfo<Target> {
: OSTargetInfo<Target>(Triple, Opts) {
this->WCharType = TargetInfo::UnsignedShort;
this->WIntType = TargetInfo::UnsignedShort;
+ this->UseMicrosoftManglingForC = true;
}
};
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 1738663327453..c2f297886a38b 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -17978,10 +17978,9 @@ static bool isPotentiallyConstantEvaluatedContext(Sema &SemaRef) {
/// Return true if this function has a calling convention that requires mangling
/// in the size of the parameter pack.
static bool funcHasParameterSizeMangling(Sema &S, FunctionDecl *FD) {
- // These manglings don't do anything on non-Windows or non-x86 platforms, so
- // we don't need parameter type sizes.
- const llvm::Triple &TT = S.Context.getTargetInfo().getTriple();
- if (!TT.isOSWindows() || !TT.isX86())
+ // These manglings are only applicable for targets whcih use Microsoft
+ // mangling scheme for C.
+ if (!S.Context.getTargetInfo().shouldUseMicrosoftCCforMangling())
return false;
// If this is C++ and this isn't an extern "C" function, parameters do not
More information about the cfe-commits
mailing list