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.
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);
 
_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to