[LLVMbugs] [Bug 7998] New: some (all?) intrinsics crashing when using float32 and cross-compiling from darwin -> mingw32

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Thu Aug 26 07:58:43 PDT 2010


http://llvm.org/bugs/show_bug.cgi?id=7998

           Summary: some (all?) intrinsics crashing when using float32 and
                    cross-compiling from darwin -> mingw32
           Product: libraries
           Version: 2.7
          Platform: PC
        OS/Version: Windows XP
            Status: NEW
          Severity: normal
          Priority: P
         Component: Core LLVM classes
        AssignedTo: unassignedbugs at nondot.org
        ReportedBy: harmonicholas at hotmail.com
                CC: llvmbugs at cs.uiuc.edu


Created an attachment (id=5415)
 --> (http://llvm.org/bugs/attachment.cgi?id=5415)
crash report in windows

Overview:
When cross-compiling from a macintosh platform targetting windows with mingw,
using the llvm intrinsics with the float32 type causes a crash during execution
of the JIT compiled function calling the intrinsic.

Steps to Reproduce:
1. have a working mingw crosscompiler. I used 
mingw-cross-env-2.15.tar.gz from
http://mingw-cross-env.nongnu.org/ which is very easy to install

2. be sure to have i686-pc-mingw32-gcc and  i686-pc-mingw32-g++ in the PATH

3. configure llvm-2.7 
./configure --build=i386-apple-darwin --host=i686-pc-mingw32
--target=i686-pc-mingw32 --enable-targets=x86 -enable-optimized=yes

4. build & install llvm

5.
compile file IntrinsicProblem.cpp (see below) using the mingw cross compiler.
It simply tries to evaluate sinf(pi/2) using the intrinsic
Makefile is trivially adapted from examples/HowToUseJIT


6. Execute IntrinsicProblem.exe in a Windows environment, an exception is
signalled

Actual Results:
the application crashed

Expected Results:
showing a result the result of sinf(pi/2), which is 1

Build Date & Platform: 
build platform:
Darwin xxxx.xxxx.fr 10.4.0 Darwin Kernel Version 10.4.0: Fri Apr 23 18:28:53
PDT 2010; root:xnu-1504.7.4~1/RELEASE_I386 i386
date 26 Aug 2010 on mac os 10.6.4
target platform:
Windows XP Professional 32 bits / Windows Version 5.1
(2600.xpsp_sp3.gdr.100427-1636 : Service Pack 3) running in VMWare Fusion


Additional Information:
intrinsic & double-float works OK
double-float and calling the function sin works aswell



cat  examples/IntrinsicProblem/IntrinsicProblem.cpp 
// if I use float and intrinsic, the I have a segmentation fault when
cross-compiled with build = darwin10 x86_64 and target = mingw32

#define USE_FLOAT 1
#define USE_INTRINSIC 1 

//===-- examples/IntrinsicProblem/IntrinsicProblem.cpp - An example use of the
JIT --===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
//  This small program provides an example of how to quickly build a small
//  module with two functions and execute it with the JIT.
//
// Goal:
//  The goal of this snippet is to create in the memory
//  the LLVM module consisting of a functions as follow: 
//
// int foo() {
//   return sin(pi/2);
// }
//
// then compile the module via JIT, then execute the `foo'
// function and return result to a driver, i.e. to a "host program".
//
// Some remarks and questions:
//
//===----------------------------------------------------------------------===//

#include "llvm/LLVMContext.h"
#include "llvm/Module.h"
#include "llvm/Constants.h"
#include "llvm/DerivedTypes.h"
#include "llvm/Instructions.h"
#include "llvm/ExecutionEngine/JIT.h"
#include "llvm/ExecutionEngine/Interpreter.h"
#include "llvm/ExecutionEngine/GenericValue.h"
#include "llvm/Target/TargetSelect.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Intrinsics.h"
using namespace llvm;


int main() {

  InitializeNativeTarget();

  LLVMContext Context;

#if USE_FLOAT
    const Type * type = Type::getFloatTy(Context);
#else
    const Type * type = Type::getDoubleTy(Context);
#endif

  // Create some module to put our function into it.
  Module *M = new Module("test", Context);

  // arguments.
  Function *FooF =
    cast<Function>(M->getOrInsertFunction("foo", type, (Type *)0));

  // Add a basic block to the FooF function.
  BasicBlock *BB = BasicBlock::Create(Context, "EntryBlock", FooF);

  // Get pointers to the constant `2'.
  Value *Arg = ConstantFP::get(type,M_PI/2.);

#if USE_INTRINSIC
    const Type *Tys[] = { type };
    Function *Sine = Intrinsic::getDeclaration(M, Intrinsic::sin,Tys, 1);    
#else
    std::vector<const Type*> arguments_types;
    FunctionType * FT;
    arguments_types.clear();
    arguments_types.push_back(type);
  FT = FunctionType::get(type,arguments_types, false);
    char function_name[16] = "sin";
    if( type == Type::getFloatTy(Context) )
    {
        strcat(function_name,"f");
    }
    Function * Sine = Function::Create(FT, Function::ExternalLinkage,
function_name, M);
#endif

    CallInst *CallRes = CallInst::Create(Sine, Arg, "rslt", BB);

  // Create the return instruction and add it to the basic block.
  ReturnInst::Create(Context, CallRes, BB);

  // Now we create the JIT.
  ExecutionEngine* EE = EngineBuilder(M).create();

  outs() << "We just constructed this LLVM module:\n\n" << *M;
  outs() << "\n\nRunning foo: ";
  outs().flush();

  // Call the `foo' function with no arguments:
  std::vector<GenericValue> noargs;
  GenericValue gv = EE->runFunction(FooF, noargs);

  // Import result of execution:
  outs() << "Result: " << (type == Type::getFloatTy(Context) ? gv.FloatVal :
gv.DoubleVal ) << "\n";
  EE->freeMachineCodeForFunction(FooF);
  delete EE;
  llvm_shutdown();
  return 0;
}
(o)

-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list