[clang] [Clang][CodeGen] Automatically resolve MSVC _hypotf and dllimport for… (PR #207135)
Eli Friedman via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 7 00:55:02 PDT 2026
================
@@ -247,10 +247,35 @@ llvm::Constant *CodeGenModule::getBuiltinLibFunction(const FunctionDecl *FD,
Name = Context.BuiltinInfo.getName(BuiltinID).substr(10);
}
+ // If no standard library declaration was found in the AST (freestanding
+ // code calling builtins directly without headers), perform automatic
+ // resolution of MSVC CRT symbol names and DLL import attributes.
+ bool IsNoHeader = (D == GlobalDecl(FD));
+ if (IsNoHeader && getTriple().isWindowsMSVCEnvironment() &&
+ Name == "hypotf") {
+ // Map C99 float math functions to their MSVC CRT prefixed names on Windows.
+ // (Only hypotf needs mapping as it is not exported without prefix in UCRT
+ // on both x86 and x64).
+ Name = "_hypotf";
----------------
efriedma-quic wrote:
What choice do we have? We can reject __builtin_hypotf on Windows, we can require the user to include math.h and redirect the builtin there, we can hardcode this mapping somewhere, or we can synthesize our own implementation. All of those options have downsides...
https://github.com/llvm/llvm-project/pull/207135
More information about the cfe-commits
mailing list