Skip to content

Commit 3623c1d

Browse files
committed
PrintAsClang: Apply review comments to check on should print of @cdecl
1 parent 1b0a3d2 commit 3623c1d

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

lib/PrintAsClang/DeclAndTypePrinter.cpp

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3006,14 +3006,22 @@ bool DeclAndTypePrinter::shouldInclude(const ValueDecl *VD) {
30063006
return false;
30073007
}
30083008

3009-
// In C output mode print only @cdecls and skip them in other modes.
3010-
bool isCDeclForC = false;
3011-
auto *FD = dyn_cast<AbstractFunctionDecl>(VD);
3012-
if (FD)
3013-
isCDeclForC = FD->getCDeclKind() == ForeignLanguage::C;
3014-
if (isCDeclForC != (outputLang == OutputLanguageMode::C))
3009+
// In C output mode print only the C variant `@cdecl` (no `@_cdecl`),
3010+
// while in other modes print only `@_cdecl`.
3011+
std::optional<ForeignLanguage> cdeclKind = std::nullopt;
3012+
if (auto *FD = dyn_cast<AbstractFunctionDecl>(VD))
3013+
cdeclKind = FD->getCDeclKind();
3014+
if (cdeclKind &&
3015+
(*cdeclKind == ForeignLanguage::C) !=
3016+
(outputLang == OutputLanguageMode::C))
30153017
return false;
30163018

3019+
// C output mode only accepts @cdecl functions.
3020+
if (outputLang == OutputLanguageMode::C &&
3021+
!cdeclKind) {
3022+
return false;
3023+
}
3024+
30173025
if (VD->getAttrs().hasAttribute<ImplementationOnlyAttr>())
30183026
return false;
30193027

0 commit comments

Comments
 (0)