[cfe-commits] r164841 - in /cfe/trunk: lib/AST/ExprConstant.cpp test/Sema/constant-builtins-2.c test/Sema/constant-builtins.c
Richard Smith
richard-llvm at metafoo.co.uk
Fri Sep 28 13:20:53 PDT 2012
Author: rsmith
Date: Fri Sep 28 15:20:52 2012
New Revision: 164841
URL: http://llvm.org/viewvc/llvm-project?rev=164841&view=rev
Log:
Allow __builtin_bswap32/64 in constant expressions, like gcc does. Patch by Tijl Coosemans!
Modified:
cfe/trunk/lib/AST/ExprConstant.cpp
cfe/trunk/test/Sema/constant-builtins-2.c
cfe/trunk/test/Sema/constant-builtins.c
Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=164841&r1=164840&r2=164841&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Fri Sep 28 15:20:52 2012
@@ -4296,6 +4296,15 @@
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);
Modified: cfe/trunk/test/Sema/constant-builtins-2.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/constant-builtins-2.c?rev=164841&r1=164840&r2=164841&view=diff
==============================================================================
--- cfe/trunk/test/Sema/constant-builtins-2.c (original)
+++ cfe/trunk/test/Sema/constant-builtins-2.c Fri Sep 28 15:20:52 2012
@@ -48,6 +48,8 @@
int h0 = __builtin_types_compatible_p(int, float);
//int h1 = __builtin_choose_expr(1, 10, f());
//int h2 = __builtin_expect(0, 0);
+int h3 = __builtin_bswap32(0x1234) == 0x34120000 ? 1 : f();
+int h4 = __builtin_bswap64(0x1234) == 0x3412000000000000 ? 1 : f();
extern long int bi0;
extern __typeof__(__builtin_expect(0, 0)) bi0;
Modified: cfe/trunk/test/Sema/constant-builtins.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/constant-builtins.c?rev=164841&r1=164840&r2=164841&view=diff
==============================================================================
--- cfe/trunk/test/Sema/constant-builtins.c (original)
+++ cfe/trunk/test/Sema/constant-builtins.c Fri Sep 28 15:20:52 2012
@@ -16,6 +16,8 @@
int h0 = __builtin_types_compatible_p(int,float);
//int h1 = __builtin_choose_expr(1, 10, f());
//int h2 = __builtin_expect(0, 0);
+int h3 = __builtin_bswap32(0x1234) == 0x34120000 ? 1 : f();
+int h4 = __builtin_bswap64(0x1234) == 0x3412000000000000 ? 1 : f();
short somefunc();
More information about the cfe-commits
mailing list