Windows SDK ヘッダーを解析するために Libtooling を使用していますが、慣例を呼び出す関数を取得する際に問題があります。libtooling は常に、Win32 API のデフォルトの呼び出し規約である呼び出し規約を__cdell
返しWINAPI
ます。__stdcall
入力例です
VOID
__stdcall
TestFunction (_In_ BOOLEAN is_valid);
これは私の関数ビジター関数ですRecursiveASTVisitor
virtual bool VisitFunctionDecl(clang::FunctionDecl *func)
{
// ...
if (m_AstContext->getSourceManager().isInMainFile(func->getLocation()))
{
if (func->hasAttrs())
{
auto stdcall = func->hasAttr<StdCallAttr>(); // always return False
}
const clang::FunctionProtoType * prototype = func->getType()->getAs<FunctionProtoType>();
if (prototype)
{
auto stdcall = prototype->hasAttr(attr::Kind::StdCall); // always return False
errs() << clang::FunctionType::getNameForCallConv(prototype->getCallConv()).str() << " "; // always return cdecl
}
func->dumpColor(); // But there is __attribute__((stdcall)) in dumped output!
}
// ...
}
そして最後にfunc->dumpColor();
for input example の出力!
^
FunctionDecl 0x218c95bb6f0 <C:\Program Files (x86)\Windows Kits\10\Include\10.0.17134.0\um\winnt.h:430:14, C:\ExampleInput.h:18:36> col:1 TestFunction 'void (BOOLEAN) __attribute__((stdcall))':'void (BOOLEAN)'
`-ParmVarDecl 0x218c95bb5c0 <col:20, col:28> col:28 is_valid 'BOOLEAN':'unsigned char'
互換性の理由から、このオプションの有無にかかわらず実行しましたが、違いはまったくありません:-(
-fms-compatibility
-fms-extensions
-fms-compatibility-version=19
何か案が?
アップデート
#Clang のデフォルトのコンパイル設定が原因で、問題が見つかりました。これは 64 ビット (64 ビット ツールチェーン) であり__stdcall
、64 ビット モードでは動作しません 32 ビット バージョン (または -m32 オプション) を使用すると、正しく動作します
64ビットモードでなぜそれが起こるのか考えていますか?