-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[clang] Use TargetInfo to decide Mangling for C #129920
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Instead of hardcoding the decision on what mangling scheme to use based on targets, use TargetInfo to make the decision.
@llvm/pr-subscribers-clang Author: Prabhuk (Prabhuk) ChangesInstead of hardcoding the decision on what mangling scheme to use based Full diff: https://github.com/llvm/llvm-project/pull/129920.diff 4 Files Affected:
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
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, I spent a while thinking if this was correct, and then convincing myself that we ignore the relevant calling conventions on the appropriate platforms (we ignore __fastcall
on x64 and ignore __vectorcall
on Win ARM).
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/190/builds/15781 Here is the relevant piece of the build log for the reference
|
Instead of hardcoding the decision on what mangling scheme to use based on targets, use TargetInfo to make the decision.
Instead of hardcoding the decision on what mangling scheme to use based
on targets, use TargetInfo to make the decision.