Skip to content

[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

Merged
merged 1 commit into from
Mar 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions clang/include/clang/Basic/TargetInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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).
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/AST/Mangle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) &&
Expand Down
2 changes: 2 additions & 0 deletions clang/lib/Basic/Targets/OSTargets.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
};

Expand All @@ -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;
}
};

Expand Down
7 changes: 3 additions & 4 deletions clang/lib/Sema/SemaExpr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down