diff --git a/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp b/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp index ab05414519c..12bfb8e252c 100644 --- a/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp +++ b/lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp @@ -29,6 +29,7 @@ #include #include #include +#include using std::vector; using namespace llvm; @@ -200,6 +201,22 @@ GenericValue lle_X_pow(FunctionType *FT, const vector &Args) { return GV; } +// double sin(double) +GenericValue lle_X_sin(FunctionType *FT, const vector &Args) { + assert(Args.size() == 1); + GenericValue GV; + GV.DoubleVal = sin(Args[0].DoubleVal); + return GV; +} + +// double cos(double) +GenericValue lle_X_cos(FunctionType *FT, const vector &Args) { + assert(Args.size() == 1); + GenericValue GV; + GV.DoubleVal = cos(Args[0].DoubleVal); + return GV; +} + // double exp(double) GenericValue lle_X_exp(FunctionType *FT, const vector &Args) { assert(Args.size() == 1); @@ -705,6 +722,24 @@ GenericValue lle_X_fprintf(FunctionType *FT, const vector &Args) { return GV; } +// int __cxa_guard_acquire (__guard *g); +GenericValue lle_X___cxa_guard_acquire(FunctionType *FT, + const vector &Args) { + assert(Args.size() == 1); + GenericValue GV; + GV.IntVal = APInt(32, __cxxabiv1::__cxa_guard_acquire ( + (__cxxabiv1::__guard*)GVTOP(Args[0]))); + return GV; +} + +// void __cxa_guard_release (__guard *g); +GenericValue lle_X___cxa_guard_release(FunctionType *FT, + const vector &Args) { + assert(Args.size() == 1); + __cxxabiv1::__cxa_guard_release ((__cxxabiv1::__guard*)GVTOP(Args[0])); + return GenericValue(); +} + } // End extern "C" @@ -719,6 +754,8 @@ void Interpreter::initializeExternalFunctions() { FuncNames["lle_X_free"] = lle_X_free; FuncNames["lle_X_atoi"] = lle_X_atoi; FuncNames["lle_X_pow"] = lle_X_pow; + FuncNames["lle_X_sin"] = lle_X_sin; + FuncNames["lle_X_cos"] = lle_X_cos; FuncNames["lle_X_exp"] = lle_X_exp; FuncNames["lle_X_log"] = lle_X_log; FuncNames["lle_X_floor"] = lle_X_floor; @@ -759,5 +796,8 @@ void Interpreter::initializeExternalFunctions() { FuncNames["lle_X_ungetc"] = lle_X_ungetc; FuncNames["lle_X_fprintf"] = lle_X_fprintf; FuncNames["lle_X_freopen"] = lle_X_freopen; + + FuncNames["lle_X___cxa_guard_acquire"] = lle_X___cxa_guard_acquire; + FuncNames["lle_X____cxa_guard_release"] = lle_X___cxa_guard_release; } diff --git a/test/ExecutionEngine/2007-12-11-APIntExFuncCall.ll b/test/ExecutionEngine/2007-12-11-APIntExFuncCall.ll new file mode 100644 index 00000000000..e135a77ea3c --- /dev/null +++ b/test/ExecutionEngine/2007-12-11-APIntExFuncCall.ll @@ -0,0 +1,54 @@ +; RUN: llvm-as < %s -o - | lli -force-interpreter +; PR1629 + +; ModuleID = '' +target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32" +target triple = "i686-pc-linux-gnu" + %struct.X = type { i32 } +@_ZGVZ4mainE1a = internal global i64 0, align 8 ; [#uses=3] +@_ZZ4mainE1a = internal global %struct.X zeroinitializer ; <%struct.X*> [#uses=1] + +define i32 @main() nounwind { +entry: + %"alloca point" = bitcast i32 0 to i32 ; [#uses=0] + %tmp2 = call double @sin( double 1.999000e+00 ) nounwind readonly ; [#uses=1] + %tmp3 = call double @cos( double 1.990000e+00 ) nounwind readonly ; [#uses=1] + %tmp4 = add double %tmp2, %tmp3 ; [#uses=1] + %tmp5 = load i8* bitcast (i64* @_ZGVZ4mainE1a to i8*), align 1 ; [#uses=1] + %tmp6 = icmp eq i8 %tmp5, 0 ; [#uses=1] + %tmp67 = zext i1 %tmp6 to i8 ; [#uses=1] + %toBool = icmp ne i8 %tmp67, 0 ; [#uses=1] + br i1 %toBool, label %cond_true, label %cond_next14 + +cond_true: ; preds = %entry + %tmp8 = call i32 @__cxa_guard_acquire( i64* @_ZGVZ4mainE1a ) nounwind ; [#uses=1] + %tmp9 = icmp ne i32 %tmp8, 0 ; [#uses=1] + %tmp910 = zext i1 %tmp9 to i8 ; [#uses=1] + %toBool12 = icmp ne i8 %tmp910, 0 ; [#uses=1] + br i1 %toBool12, label %cond_true13, label %cond_next14 + +cond_true13: ; preds = %cond_true + call void @_ZN1XC1Ei( %struct.X* @_ZZ4mainE1a, i32 0 ) nounwind + call void @__cxa_guard_release( i64* @_ZGVZ4mainE1a ) nounwind + br label %cond_next14 + +cond_next14: ; preds = %cond_true13, %cond_true, %entry + %tmp1516 = fptosi double %tmp4 to i32 ; [#uses=1] + ret i32 %tmp1516 +} + +define linkonce void @_ZN1XC1Ei(%struct.X* %this, i32 %val) nounwind { +entry: + %"alloca point" = bitcast i32 0 to i32 ; [#uses=0] + %tmp1 = getelementptr %struct.X* %this, i32 0, i32 0 ; [#uses=1] + store i32 %val, i32* %tmp1, align 4 + ret void +} + +declare double @sin(double) nounwind readonly + +declare double @cos(double) nounwind readonly + +declare i32 @__cxa_guard_acquire(i64*) nounwind + +declare void @__cxa_guard_release(i64*) nounwind