[clang] [clang] Use TargetInfo to decide Mangling for C (PR #129920)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Mar 5 11:45:17 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Prabhuk (Prabhuk)
<details>
<summary>Changes</summary>
Instead of hardcoding the decision on what mangling scheme to use based
on targets, use TargetInfo to make the decision.
---
Full diff: https://github.com/llvm/llvm-project/pull/129920.diff
4 Files Affected:
- (modified) clang/include/clang/Basic/TargetInfo.h (+6)
- (modified) clang/lib/AST/Mangle.cpp (+1-1)
- (modified) clang/lib/Basic/Targets/OSTargets.h (+2)
- (modified) clang/lib/Sema/SemaExpr.cpp (+3-4)
``````````diff
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
``````````
</details>
https://github.com/llvm/llvm-project/pull/129920
More information about the cfe-commits
mailing list