[clang] [clang codegen] Emit int TBAA metadata on more FP math libcalls (PR #100302)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 23 22:14:06 PDT 2024
https://github.com/vfdff created https://github.com/llvm/llvm-project/pull/100302
Follow PR96025, except expf, more FP math libcalls in libm should also be supported.
Fix https://github.com/llvm/llvm-project/issues/86635
>From c750234674531788ee26958954a5f9a6b59ea866 Mon Sep 17 00:00:00 2001
From: zhongyunde 00443407 <zhongyunde at huawei.com>
Date: Tue, 23 Jul 2024 23:10:42 -0400
Subject: [PATCH] [clang codegen] Emit int TBAA metadata on more FP math
libcalls
Follow PR96025, except expf, more FP math libcalls in libm
should also be supported.
Fix https://github.com/llvm/llvm-project/issues/86635
---
clang/lib/CodeGen/CGBuiltin.cpp | 15 +++++++--------
1 file changed, 7 insertions(+), 8 deletions(-)
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index a0d03b87ccdc9..a9696ebe61e3a 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -692,23 +692,22 @@ static RValue emitLibraryCall(CodeGenFunction &CGF, const FunctionDecl *FD,
RValue Call =
CGF.EmitCall(E->getCallee()->getType(), callee, E, ReturnValueSlot());
- // Check the supported intrinsic.
+ ASTContext &Context = CGF.getContext();
if (unsigned BuiltinID = FD->getBuiltinID()) {
auto IsErrnoIntrinsic = [&]() -> unsigned {
- switch (BuiltinID) {
- case Builtin::BIexpf:
- case Builtin::BI__builtin_expf:
- case Builtin::BI__builtin_expf128:
+ // Check whether a FP math builtin function, such as BI__builtin_expf
+ QualType ResultTy = FD->getReturnType();
+ bool IsMathLibCall =
+ Context.BuiltinInfo.isLibFunction(BuiltinID) ||
+ Context.BuiltinInfo.isPredefinedLibFunction(BuiltinID);
+ if (IsMathLibCall && CGF.ConvertType(ResultTy)->isFloatingPointTy())
return true;
- }
- // TODO: support more FP math libcalls
return false;
}();
// Restrict to target with errno, for example, MacOS doesn't set errno.
if (IsErrnoIntrinsic && CGF.CGM.getLangOpts().MathErrno &&
!CGF.Builder.getIsFPConstrained()) {
- ASTContext &Context = CGF.getContext();
// Emit "int" TBAA metadata on FP math libcalls.
clang::QualType IntTy = Context.IntTy;
TBAAAccessInfo TBAAInfo = CGF.CGM.getTBAAAccessInfo(IntTy);
More information about the cfe-commits
mailing list