r183886 - Fix part of PR12457. Patch by Justin Bogner!

Richard Smith richard-llvm at metafoo.co.uk
Wed Jun 12 22:04:17 PDT 2013


Author: rsmith
Date: Thu Jun 13 00:04:16 2013
New Revision: 183886

URL: http://llvm.org/viewvc/llvm-project?rev=183886&view=rev
Log:
Fix part of PR12457. Patch by Justin Bogner!

Modified:
    cfe/trunk/lib/AST/ExprConstant.cpp
    cfe/trunk/test/Sema/constant-builtins-2.c

Modified: cfe/trunk/lib/AST/ExprConstant.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ExprConstant.cpp?rev=183886&r1=183885&r2=183886&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ExprConstant.cpp (original)
+++ cfe/trunk/lib/AST/ExprConstant.cpp Thu Jun 13 00:04:16 2013
@@ -5691,6 +5691,40 @@ bool IntExprEvaluator::VisitCallExpr(con
     return Success(Val.byteSwap(), E);
   }
 
+  case Builtin::BI__builtin_clz:
+  case Builtin::BI__builtin_clzl:
+  case Builtin::BI__builtin_clzll: {
+    APSInt Val;
+    if (!EvaluateInteger(E->getArg(0), Val, Info))
+      return false;
+    if (!Val)
+      return Error(E);
+
+    return Success(Val.countLeadingZeros(), E);
+  }
+
+  case Builtin::BI__builtin_ctz:
+  case Builtin::BI__builtin_ctzl:
+  case Builtin::BI__builtin_ctzll: {
+    APSInt Val;
+    if (!EvaluateInteger(E->getArg(0), Val, Info))
+      return false;
+    if (!Val)
+      return Error(E);
+
+    return Success(Val.countTrailingZeros(), E);
+  }
+
+  case Builtin::BI__builtin_popcount:
+  case Builtin::BI__builtin_popcountl:
+  case Builtin::BI__builtin_popcountll: {
+    APSInt Val;
+    if (!EvaluateInteger(E->getArg(0), Val, Info))
+      return false;
+
+    return Success(Val.countPopulation(), 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=183886&r1=183885&r2=183886&view=diff
==============================================================================
--- cfe/trunk/test/Sema/constant-builtins-2.c (original)
+++ cfe/trunk/test/Sema/constant-builtins-2.c Thu Jun 13 00:04:16 2013
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1 -fsyntax-only %s
+// RUN: %clang_cc1 -fsyntax-only -verify %s
 
 // Math stuff
 
@@ -41,6 +41,33 @@ long double  g18 = __builtin_copysignl(1
 //float        g20 = __builtin_powif(2.0f, 4);
 //long double  g21 = __builtin_powil(2.0L, 4);
 
+#define BITSIZE(x) (sizeof(x) * 8)
+char g22[__builtin_clz(1) == BITSIZE(int) - 1 ? 1 : -1];
+char g23[__builtin_clz(7) == BITSIZE(int) - 3 ? 1 : -1];
+char g24[__builtin_clz(1 << (BITSIZE(int) - 1)) == 0 ? 1 : -1];
+int g25 = __builtin_clz(0); // expected-error {{not a compile-time constant}}
+char g26[__builtin_clzl(0xFL) == BITSIZE(long) - 4 ? 1 : -1];
+char g27[__builtin_clzll(0xFFLL) == BITSIZE(long long) - 8 ? 1 : -1];
+
+char g28[__builtin_ctz(1) == 0 ? 1 : -1];
+char g29[__builtin_ctz(8) == 3 ? 1 : -1];
+char g30[__builtin_ctz(1 << (BITSIZE(int) - 1)) == BITSIZE(int) - 1 ? 1 : -1];
+int g31 = __builtin_ctz(0); // expected-error {{not a compile-time constant}}
+char g32[__builtin_ctzl(0x10L) == 4 ? 1 : -1];
+char g33[__builtin_ctzll(0x100LL) == 8 ? 1 : -1];
+
+char g34[__builtin_popcount(0) == 0 ? 1 : -1];
+char g35[__builtin_popcount(0xF0F0) == 8 ? 1 : -1];
+char g36[__builtin_popcount(~0) == BITSIZE(int) ? 1 : -1];
+char g37[__builtin_popcount(~0L) == BITSIZE(int) ? 1 : -1];
+char g38[__builtin_popcountl(0L) == 0 ? 1 : -1];
+char g39[__builtin_popcountl(0xF0F0L) == 8 ? 1 : -1];
+char g40[__builtin_popcountl(~0L) == BITSIZE(long) ? 1 : -1];
+char g41[__builtin_popcountll(0LL) == 0 ? 1 : -1];
+char g42[__builtin_popcountll(0xF0F0LL) == 8 ? 1 : -1];
+char g43[__builtin_popcountll(~0LL) == BITSIZE(long long) ? 1 : -1];
+#undef BITSIZE
+
 // GCC misc stuff
 
 extern int f();





More information about the cfe-commits mailing list