[cfe-commits] [PATCH] Allow __builtin_bswap32/64 in constant expressions like gcc

Tijl Coosemans tijl at coosemans.org
Wed Sep 26 12:14:32 PDT 2012


Hi,

The attached patch makes __builtin_bswap32 and __builtin_bswap64
usable in constant expressions like gcc.

This is my first look at clang code so perhaps review it more
thoroughly than usual.
-------------- next part --------------
Index: lib/AST/ExprConstant.cpp
===================================================================
--- lib/AST/ExprConstant.cpp	(revision 164714)
+++ lib/AST/ExprConstant.cpp	(working copy)
@@ -4296,6 +4296,15 @@ bool IntExprEvaluator::VisitCallExpr(const CallExp
     return Error(E);
   }
 
+  case Builtin::BI__builtin_bswap32:
+  case Builtin::BI__builtin_bswap64: {
+    APSInt Val;
+    if (!EvaluateInteger(E->getArg(0), Val, Info))
+      return false;
+
+    return Success(Val.byteSwap(), E);
+  }
+
   case Builtin::BI__builtin_classify_type:
     return Success(EvaluateBuiltinClassifyType(E), E);
 


More information about the cfe-commits mailing list