[cfe-dev] Missing C99 function's __builtin_'s

Ruben Van Boxem vanboxem.ruben at gmail.com
Mon Jan 16 10:25:50 PST 2012


2012/1/16 Eli Friedman <eli.friedman at gmail.com>

> On Mon, Jan 16, 2012 at 8:24 AM, Ruben Van Boxem
> <vanboxem.ruben at gmail.com> wrote:
> > Hi,
> >
> > Is there a specific reason why Clang does not have
> > __builtin_labs
> > __builtin_llabs
>
> No, probably just nobody got around to adding them.
>

I had an attempt at adding the __builtin's mentioned above. I tested with
current trunk attached patch. It just adds the two builtin names and puts
it in the same codegen part as regular abs. I hope this is correct, I had a
quick check of llabs with -2^61 and printf using "%lld".

Thanks,

Ruben

PS: If patch is OK, please commit, I don't have commit rights.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20120116/325996e9/attachment.html>
-------------- next part --------------
Index: include/clang/Basic/Builtins.def
===================================================================
--- include/clang/Basic/Builtins.def	(revision 148240)
+++ include/clang/Basic/Builtins.def	(working copy)
@@ -108,6 +108,8 @@
 BUILTIN(__builtin_inf  , "d"   , "nc")
 BUILTIN(__builtin_inff , "f"   , "nc")
 BUILTIN(__builtin_infl , "Ld"  , "nc")
+BUILTIN(__builtin_labs , "LiLi"  , "Fnc")
+BUILTIN(__builtin_llabs, "LLiLLi", "Fnc")
 BUILTIN(__builtin_ldexp , "ddi"  , "Fnc")
 BUILTIN(__builtin_ldexpf, "ffi"  , "Fnc")
 BUILTIN(__builtin_ldexpl, "LdLdi", "Fnc")
Index: lib/CodeGen/CGBuiltin.cpp
===================================================================
--- lib/CodeGen/CGBuiltin.cpp	(revision 148240)
+++ lib/CodeGen/CGBuiltin.cpp	(working copy)
@@ -214,7 +214,9 @@
     return RValue::get(Builder.CreateCall2(CGM.getIntrinsic(Intrinsic::vacopy),
                                            DstPtr, SrcPtr));
   }
-  case Builtin::BI__builtin_abs: {
+  case Builtin::BI__builtin_abs: 
+  case Builtin::BI__builtin_labs:
+  case Builtin::BI__builtin_llabs: {
     Value *ArgValue = EmitScalarExpr(E->getArg(0));
 
     Value *NegOp = Builder.CreateNeg(ArgValue, "neg");


More information about the cfe-dev mailing list