OSDN Git Service

Add upport for bitcast in the C API echo test
authorAmaury Sechet <deadalnix@gmail.com>
Wed, 17 Feb 2016 23:55:59 +0000 (23:55 +0000)
committerAmaury Sechet <deadalnix@gmail.com>
Wed, 17 Feb 2016 23:55:59 +0000 (23:55 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@261177 91177308-0d34-0410-b5e6-96231b3b80d8

tools/llvm-c-test/echo.cpp

index 22cbcf1..2295301 100644 (file)
@@ -276,12 +276,24 @@ LLVMValueRef clone_constant(LLVMValueRef Cst, LLVMModuleRef M) {
   if (LLVMIsUndef(Cst))
     return LLVMGetUndef(TypeCloner(M).Clone(Cst));
 
+  // Try float literal
+  if (LLVMIsAConstantFP(Cst))
+    report_fatal_error("ConstantFP is not supported");
+
   // This kind of constant is not supported
   if (!LLVMIsAConstantExpr(Cst))
     report_fatal_error("Expected a constant expression");
 
   // At this point, it must be a constant expression
-  report_fatal_error("ConstantExpression are not supported");
+  LLVMOpcode Op = LLVMGetConstOpcode(Cst);
+  switch(Op) {
+    case LLVMBitCast:
+      return LLVMConstBitCast(clone_constant(LLVMGetOperand(Cst, 0), M),
+                              TypeCloner(M).Clone(Cst));
+    default:
+      fprintf(stderr, "%d is not a supported opcode\n", Op);
+      exit(-1);
+  }
 }
 
 struct FunCloner {
@@ -489,6 +501,11 @@ struct FunCloner {
           Dst = LLVMBuildGEP(Builder, Ptr, Idx.data(), NumIdx, Name);
         break;
       }
+      case LLVMBitCast: {
+        LLVMValueRef V = CloneValue(LLVMGetOperand(Src, 0));
+        Dst = LLVMBuildBitCast(Builder, V, CloneType(Src), Name);
+        break;
+      }
       case LLVMICmp: {
         LLVMIntPredicate Pred = LLVMGetICmpPredicate(Src);
         LLVMValueRef LHS = CloneValue(LLVMGetOperand(Src, 0));