]> granicus.if.org Git - clang/commitdiff
remove some code where CGBuiltin folds constants, and use tryEvaluate to
authorChris Lattner <sabre@nondot.org>
Mon, 6 Oct 2008 06:09:18 +0000 (06:09 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 6 Oct 2008 06:09:18 +0000 (06:09 +0000)
do it instead.  We should still handle __builtin_nan etc, but don't yet.
This fixes incorrect evaluation of __builtin_constant_p, a FIXME.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@57156 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGBuiltin.cpp

index 1ced9869c1aa6f3a78ff7c811a8760e3419f9b5f..10b47f1a489cf707a94d96b0bd26a2397f459e46 100644 (file)
@@ -14,6 +14,7 @@
 #include "CodeGenFunction.h"
 #include "CodeGenModule.h"
 #include "clang/Basic/TargetInfo.h"
+#include "clang/AST/APValue.h"
 #include "clang/AST/ASTContext.h"
 #include "clang/AST/Decl.h"
 #include "clang/AST/TargetBuiltins.h"
@@ -39,6 +40,24 @@ RValue CodeGenFunction::EmitBuiltinExpr(unsigned BuiltinID, const CallExpr *E) {
   switch (BuiltinID) {
   default: break;  // Handle intrinsics and libm functions below.
       
+  case Builtin::BI__builtin_huge_val:
+  case Builtin::BI__builtin_huge_valf:
+  case Builtin::BI__builtin_huge_vall:
+  case Builtin::BI__builtin_inf:
+  case Builtin::BI__builtin_inff:
+  case Builtin::BI__builtin_infl:
+  case Builtin::BI__builtin_classify_type:
+  case Builtin::BI__builtin_constant_p: {
+    APValue Result;
+    bool IsCst = E->tryEvaluate(Result, CGM.getContext());
+    assert(IsCst && "These must all be constants!");
+    
+    if (Result.isInt())
+      return RValue::get(llvm::ConstantInt::get(Result.getInt()));
+    assert(Result.isFloat() && "Unsupported constant type");
+    return RValue::get(llvm::ConstantFP::get(Result.getFloat()));
+  }
+      
   case Builtin::BI__builtin___CFStringMakeConstantString: {
     const Expr *Arg = E->getArg(0);
     
@@ -87,18 +106,6 @@ RValue CodeGenFunction::EmitBuiltinExpr(unsigned BuiltinID, const CallExpr *E) {
     return RValue::get(Builder.CreateCall2(CGM.getIntrinsic(Intrinsic::vacopy), 
                                            DstPtr, SrcPtr));
   }
-  case Builtin::BI__builtin_classify_type: {
-    APSInt Result(32);
-    if (!E->isBuiltinClassifyType(Result))
-      assert(0 && "Expr not __builtin_classify_type!");
-    return RValue::get(ConstantInt::get(Result));
-  }
-  case Builtin::BI__builtin_constant_p: {
-    APSInt Result(32);
-    // FIXME: Analyze the parameter and check if it is a constant.
-    Result = 0;
-    return RValue::get(ConstantInt::get(Result));
-  }
   case Builtin::BI__builtin_abs: {
     Value *ArgValue = EmitScalarExpr(E->getArg(0));   
     
@@ -224,16 +231,6 @@ RValue CodeGenFunction::EmitBuiltinExpr(unsigned BuiltinID, const CallExpr *E) {
     return RValue::get(Builder.CreateCall(F));
   }
 
-  case Builtin::BI__builtin_huge_val:
-  case Builtin::BI__builtin_huge_valf:
-  case Builtin::BI__builtin_huge_vall:
-  case Builtin::BI__builtin_inf:
-  case Builtin::BI__builtin_inff:
-  case Builtin::BI__builtin_infl: {
-    const llvm::fltSemantics &Sem =
-      CGM.getContext().getFloatTypeSemantics(E->getType());
-    return RValue::get(ConstantFP::get(APFloat::getInf(Sem)));
-  }
   case Builtin::BI__builtin_nan:
   case Builtin::BI__builtin_nanf:
   case Builtin::BI__builtin_nanl: {