[PATCH] Constant expression evaluation support for __builtin_isinf
Karthik Bhat
kv.bhat at samsung.com
Mon Oct 14 23:40:23 PDT 2013
Implemented comments from Richard and moved the test case to constant-builtins-2.c.
Can someone commit this for me if this looks good?
Thanks!
Hi rsmith, eli.friedman,
http://llvm-reviews.chandlerc.com/D1794
CHANGE SINCE LAST DIFF
http://llvm-reviews.chandlerc.com/D1794?vs=4615&id=4911#toc
Files:
lib/AST/ExprConstant.cpp
test/Sema/constant-builtins-2.c
Index: lib/AST/ExprConstant.cpp
===================================================================
--- lib/AST/ExprConstant.cpp
+++ lib/AST/ExprConstant.cpp
@@ -5985,6 +5985,30 @@
Success(Val.isInfinity() ? (Val.isNegative() ? -1 : 1) : 0, E);
}
+ case Builtin::BI__builtin_isinf: {
+ APFloat Val(0.0);
+ return EvaluateFloat(E->getArg(0), Val, Info) &&
+ Success(Val.isInfinity() ? 1 : 0, E);
+ }
+
+ case Builtin::BI__builtin_isfinite: {
+ APFloat Val(0.0);
+ return EvaluateFloat(E->getArg(0), Val, Info) &&
+ Success(Val.isFinite() ? 1 : 0, E);
+ }
+
+ case Builtin::BI__builtin_isnan: {
+ APFloat Val(0.0);
+ return EvaluateFloat(E->getArg(0), Val, Info) &&
+ Success(Val.isNaN() ? 1 : 0, E);
+ }
+
+ case Builtin::BI__builtin_isnormal: {
+ APFloat Val(0.0);
+ return EvaluateFloat(E->getArg(0), Val, Info) &&
+ Success(Val.isNormal() ? 1 : 0, E);
+ }
+
case Builtin::BI__builtin_parity:
case Builtin::BI__builtin_parityl:
case Builtin::BI__builtin_parityll: {
Index: test/Sema/constant-builtins-2.c
===================================================================
--- test/Sema/constant-builtins-2.c
+++ test/Sema/constant-builtins-2.c
@@ -121,3 +121,63 @@
// Strings
int array1[__builtin_strlen("ab\0cd")];
int array2[(sizeof(array1)/sizeof(int)) == 2? 1 : -1];
+
+
+// Builtin constant evaluation-
+// __builtin_isinf
+void test_builtin_isinf() {
+
+ const long double num1 = __builtin_isinf(1.l);
+ char l1[num1 == 0 ? 1 : -1];
+ const double num2 = __builtin_isinf(1.);
+ char l2[num2 == 0 ? 1 : -1];
+ const double num3 = __builtin_isinf(1.f);
+ char l3[num3 == 0 ? 1 : -1];
+ const float num4 = __builtin_isinf(__builtin_inf());
+ char l4[num4 == 1 ? 1 : -1];
+}
+
+// __builtin_isfinite
+void test_builtin_isfinite() {
+
+ const long double num1 = __builtin_isfinite(1.l);
+ char l1[num1 == 1 ? 1 : -1];
+ const double num2 = __builtin_isfinite(1.);
+ char l2[num2 == 1 ? 1 : -1];
+ const double num3 = __builtin_isfinite(1.f);
+ char l3[num3 == 1 ? 1 : -1];
+ const float num4 = __builtin_isfinite(__builtin_inf());
+ char l4[num4 == 0 ? 1 : -1];
+}
+
+// __builtin_isnan
+void test_builtin_isnan() {
+
+ const long double num1 = __builtin_isnan(1.l);
+ char l1[num1 == 0 ? 1 : -1];
+ const double num2 = __builtin_isnan(1.);
+ char l2[num2 == 0 ? 1 : -1];
+ const double num3 = __builtin_isnan(1.f);
+ char l3[num3 == 0 ? 1 : -1];
+ const float num4 = __builtin_isnan(__builtin_inf());
+ char l4[num4 == 0 ? 1 : -1];
+ const float num5 = __builtin_isnan(__builtin_nan(""));
+ char l5[num5 == 1 ? 1 : -1];
+}
+
+// __builtin_isnormal
+void test_builtin_isnormal() {
+
+ const long double num1 = __builtin_isnormal(1.l);
+ char l1[num1 == 1 ? 1 : -1];
+ const double num2 = __builtin_isnormal(1.);
+ char l2[num2 == 1 ? 1 : -1];
+ const double num3 = __builtin_isnormal(1.f);
+ char l3[num3 == 1 ? 1 : -1];
+ const float num4 = __builtin_isnormal(__builtin_inf());
+ char l4[num4 == 0 ? 1 : -1];
+ const float num5 = __builtin_isnormal(__builtin_nan(""));
+ char l5[num5 == 0 ? 1 : -1];
+ const float num6 = __builtin_isnormal(0.);
+ char l6[num6 == 0 ? 1 : -1];
+}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1794.3.patch
Type: text/x-patch
Size: 3223 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20131014/2bc89a0b/attachment.bin>
More information about the cfe-commits
mailing list