cil-project / cil

C Intermediate Language
Other
348 stars 86 forks source link

Support for gcc's __builtin_bswap32 #9

Closed stephenrkell closed 10 years ago

stephenrkell commented 10 years ago

gcc 4.3 added a new intrinsic, __builtin_bswap32. Currently CIL doesn't know about this builtin, so will emit a (wrongly-typed) prototype for it, causing undefined references in the output object file. The following patch fixes the problem for me.

diff --git a/src/cil.ml b/src/cil.ml
index 1c737e8..343216f 100644
--- a/src/cil.ml
+++ b/src/cil.ml
@@ -2835,6 +2835,7 @@ let initGccBuiltins () : unit =
   (* See if we have builtin_va_list *)
   let hasbva = !M.theMachine.M.__builtin_va_list in
   let ulongLongType = TInt(IULongLong, []) in
+  let uIntType = TInt(IUInt, []) in
   let floatType = TFloat(FFloat, []) in
   let longDoubleType = TFloat (FLongDouble, []) in
   let voidConstPtrType = TPtr(TVoid [Attr ("const", [])], []) in
@@ -2878,6 +2879,8 @@ let initGccBuiltins () : unit =
   H.add h "__builtin_atan2l" (longDoubleType, [ longDoubleType; 
                                                 longDoubleType ], false);

+  H.add h "__builtin_bswap32" (uIntType, [ uIntType ], false);
+
   H.add h "__builtin_ceil" (doubleType, [ doubleType ], false);
   H.add h "__builtin_ceilf" (floatType, [ floatType ], false);
   H.add h "__builtin_ceill" (longDoubleType, [ longDoubleType ], false);
kerneis commented 10 years ago

Which version of CIL are you using? This has been fixed almost two years ago: 28f312243c978e129943bff044729e88dbd8b2b5

stephenrkell commented 10 years ago

Ah, oops. Turns out I had [pulled but] not rebased/upated since 1.4.