]> granicus.if.org Git - clang/commitdiff
Handle emitting __builtin_huge_valf as a constant expr.
authorAnders Carlsson <andersca@mac.com>
Mon, 25 Aug 2008 03:27:15 +0000 (03:27 +0000)
committerAnders Carlsson <andersca@mac.com>
Mon, 25 Aug 2008 03:27:15 +0000 (03:27 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@55299 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/Expr.cpp
lib/CodeGen/CGExprConstant.cpp

index 5107a5643c9bc6c1d8b606a42c501d7cf2122684..a7e49d0efcd5af111b5f62f9d2ecff951e255d77 100644 (file)
@@ -161,7 +161,8 @@ bool CallExpr::isBuiltinConstantExpr() const {
 
   // We have a builtin that is a constant expression
   return builtinID == Builtin::BI__builtin___CFStringMakeConstantString ||
-         builtinID == Builtin::BI__builtin_classify_type;
+         builtinID == Builtin::BI__builtin_classify_type ||
+         builtinID == Builtin::BI__builtin_huge_valf;
 }
 
 bool CallExpr::isBuiltinClassifyType(llvm::APSInt &Result) const {
index 9f94d4244f07883e44fdf1c7f2aa832ddf06078e..e0c39c9cbac6885f0f640ce11898e5c69cf898c7 100644 (file)
@@ -606,6 +606,20 @@ public:
 
     return Visit(E->getRHS());
   }
+
+  llvm::Constant *VisitCallExpr(const CallExpr *E) {
+    if (const ImplicitCastExpr *IcExpr = 
+        dyn_cast<const ImplicitCastExpr>(E->getCallee()))
+      if (const DeclRefExpr *DRExpr = 
+          dyn_cast<const DeclRefExpr>(IcExpr->getSubExpr()))
+        if (const FunctionDecl *FDecl = 
+            dyn_cast<const FunctionDecl>(DRExpr->getDecl()))
+          if (unsigned builtinID = FDecl->getIdentifier()->getBuiltinID())
+            return EmitBuiltinExpr(builtinID, E);
+
+    CGM.ErrorUnsupported(E, "constant call expression");
+    return llvm::Constant::getNullValue(ConvertType(E->getType()));
+  }
     
   // Utility methods
   const llvm::Type *ConvertType(QualType T) {
@@ -805,6 +819,20 @@ public:
     return llvm::UndefValue::get(Ty);
   }
 
+  llvm::Constant *EmitBuiltinExpr(unsigned BuiltinID, const CallExpr *E)
+  {
+    switch (BuiltinID) {
+    default:
+      CGM.ErrorUnsupported(E, "constant builtin function");
+      return 0;
+    case Builtin::BI__builtin_huge_valf: {
+      const llvm::fltSemantics &Sem =
+      CGM.getContext().getFloatTypeSemantics(E->getType());
+      return llvm::ConstantFP::get(llvm::APFloat::getInf(Sem));
+    }        
+    }
+  }
+    
 };
   
 }  // end anonymous namespace.