I encountered a problem when attempting to create a call to function malloc. Below is the code that I use to allocate memory to a pointer
Type* tp = argument->getType();
AllocaInst* arg_alloc = builder.CreateAlloca(tp);
if(tp->isPointerTy()){
if(!tp->getContainedType(0)->isPointerTy()){
Value *alloc_size = ConstantInt::get(Type::getInt64Ty(getGlobalContext()),
dl->getTypeAllocSize(tp->getPointerElementType()), false);
CallInst::CreateMalloc(arg_alloc, tp, tp->getPointerElementType(), alloc_size);
}
}
But I got an error:
llvm-3.4/include/llvm/Support/Casting.h:239: typename
llvm::cast_retty<X, Y*>::ret_type llvm::cast(Y*) [with X =
llvm::IntegerType; Y = llvm::Type; typename llvm::cast_retty<X,
Y*>::ret_type = llvm::IntegerType*]: Assertion `isa<X>(Val) &&
"cast<Ty>() argument of incompatible type!"' failed.
0 libLLVM-3.4.so 0x00007f01246a4035 llvm::sys::PrintStackTrace(_IO_FILE*) + 37
1 libLLVM-3.4.so 0x00007f01246a3fb3
2 libpthread.so.0 0x00007f012392d340
3 libc.so.6 0x00007f0122a0cbb9 gsignal + 57
4 libc.so.6 0x00007f0122a0ffc8 abort + 328
5 libc.so.6 0x00007f0122a05a76
6 libc.so.6 0x00007f0122a05b22
7 libLLVM-3.4.so 0x00007f01240a85bc llvm::ConstantInt::get(llvm::Type*, unsigned long, bool) + 140
8 libLLVM-3.4.so 0x00007f012413ce0e
9 libLLVM-3.4.so 0x00007f012413d6bb llvm::CallInst::CreateMalloc(llvm::Instruction*, llvm::Type*, llvm::Type*, llvm::Value*, llvm::Value*, llvm::Function*, llvm::Twine const&) + 43
I just want to do a simple thing: suppose there is a variable p, if p is
a pointer then allocate memory to p. Any hint to get around of this error?
If Ty is the Type of the allocation:
Type* ITy = Type::getInt32Ty(Context);
Constant* AllocSize = ConstantExpr::getSizeOf(Ty);
AllocSize = ConstantExpr::getTruncOrBitCast(AllocSize, ITy);
Instruction* Malloc = CallInst::CreateMalloc(Builder->GetInsertBlock(),
ITy, Ty, AllocSize,
nullptr, nullptr, "");
is roughly what you want.
Related
When I am trying to run the following code
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
vector<vector<int>> v(n, vector<int>(2));
cout<<2<<"\n";
return 0;
}
using the command g++ file.cpp then it is giving the following error
0 0x1022a41a0 __assert_rtn + 140
1 0x10212ba8c mach_o::relocatable::Parser<arm64>::parse(mach_o::relocatable::ParserOptions const&) + 4536
2 0x1020fdd38 mach_o::relocatable::Parser<arm64>::parse(unsigned char const*, unsigned long long, char const*, long, ld::File::Ordinal, mach_o::relocatable::ParserOptions const&) + 148
3 0x1021664ac ld::tool::InputFiles::makeFile(Options::FileInfo const&, bool) + 1468
4 0x102169360 ___ZN2ld4tool10InputFilesC2ER7Options_block_invoke + 56
5 0x1c17b41f4 _dispatch_client_callout2 + 20
6 0x1c17c8f8c _dispatch_apply_invoke_and_wait + 224
7 0x1c17c826c _dispatch_apply_with_attr_f + 1152
8 0x1c17c847c dispatch_apply + 108
9 0x1021691f4 ld::tool::InputFiles::InputFiles(Options&) + 616
10 0x1020eb6c0 main + 552
A linker snapshot was created at:
/tmp/a.out-2022-09-19-011653.ld-snapshot
ld: Assertion failed: (_file->_atomsArrayCount == computedAtomCount && "more atoms allocated than expected"), function parse, file macho_relocatable_file.cpp, line 2061.
collect2: error: ld returned 1 exit status
I'm trying to follow this tutorial on how to implement a solver, but I'm having troubles setting up the case.
The original case can be found here. At first, when running blockMesh my version of OpenFOAM didn't recognize #eval() in blockMeshDict, so I changed it for #calc:
/*---------------------------------------------------------------------------*\
| ========= | |
| \\ / F ield | OpenFOAM: The Open Source CFD Toolbox |
| \\ / O peration | Version: 1.5 |
| \\ / A nd | Web: http://www.openfoam.org |
| \\/ M anipulation | |
\*---------------------------------------------------------------------------*/
FoamFile
{
version 2.0;
format ascii;
class dictionary;
object blockMeshDict;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
scale 1e-4;
mergeType points; //Or: blockMesh -merge-points
wedgeAngle 2.5;
rodRadius 9.9;
airRadius 999;
tanAlpha #calc"tan(0.5*degToRad($wedgeAngle))";
posRodZ #calc"$rodRadius*$tanAlpha";
negRodZ #calc"-$posRodZ";
posAirZ #calc"$airRadius*$tanAlpha";
negAirZ #calc"-$posAirZ";
vertices
(
(0 0 0) // vertex #0
(100 0 0) // vertex #1
(100 $rodRadius $posRodZ) // vertex #2
(0 $rodRadius $posRodZ) // vertex #3
(0 $rodRadius $negRodZ) // vertex #4
(100 $rodRadius $negRodZ) // vertex #5
(0 $airRadius $posAirZ) // vertex #6
(100 $airRadius $posAirZ) // vertex #7
(100 $airRadius $negAirZ) // vertex #8
(0 $airRadius $negAirZ) // vertex #9
);
blocks
(
hex (0 1 5 4 0 1 2 3) (30 6 1) simpleGrading (1 1 1) // block #0
hex (4 5 8 9 3 2 7 6) (30 599 1) simpleGrading (1 1 1) // block #1
);
edges
(
);
boundary
(
leftWall
{
type patch;
faces
(
(3 4 0 0)
);
}
rightWall
{
type patch;
faces
(
(1 5 2 1)
);
}
atmosphereTop
{
type patch;
faces
(
(9 6 7 8)
);
}
atmosphereRight
{
type patch;
faces
(
(3 6 9 4)
);
}
atmosphereLeft
{
type patch;
faces
(
(5 8 7 2)
);
}
axis
{
type empty;
faces
(
(0 1 1 0)
);
}
rodBack
{
type wedge;
faces
(
(0 4 5 1)
);
}
rodFront
{
type wedge;
faces
(
(0 1 2 3)
);
}
airBack
{
type wedge;
faces
(
(4 9 8 5)
);
}
airFront
{
type wedge;
faces
(
(3 2 7 6)
);
}
);
mergePatchPairs
(
);
// ************************************************************************* //
And now, when running blockMesh, I get the following errors:
/*---------------------------------------------------------------------------*\
========= |
\\ / F ield | OpenFOAM: The Open Source CFD Toolbox
\\ / O peration | Website: https://openfoam.org
\\ / A nd | Version: 9
\\/ M anipulation |
\*---------------------------------------------------------------------------*/
Build : 9-c8374a4890ad
Exec : blockMesh
Date : Dec 16 2021
Time : 12:59:36
Host : "endeavouros"
PID : 346839
I/O : uncollated
Case : /home/ariedinger/uni/gimap/openfoam/03emf/01huang/0rodFoam/rodFoamCase
nProcs : 1
sigFpe : Enabling floating point exception trapping (FOAM_SIGFPE).
fileModificationChecking : Monitoring run-time modified files using timeStampMaster (fileModificationSkew 10)
allowSystemOperations : Allowing user-supplied system call operations
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Create time
Reading "blockMeshDict"
Creating block mesh from
"system/blockMeshDict"
Using #calcEntry at line 26 in file "/home/ariedinger/uni/gimap/openfoam/03emf/01huang/0rodFoam/rodFoamCase/system/blockMeshDict"
Using #codeStream with "/home/ariedinger/uni/gimap/openfoam/03emf/01huang/0rodFoam/rodFoamCase/dynamicCode/platforms/linux64GccDPInt32Opt/lib/libcodeStream_28b21b5898ba159392899d5ac4d05a7158e0c6d6.so"
Creating new library in "dynamicCode/_28b21b5898ba159392899d5ac4d05a7158e0c6d6/platforms/linux64GccDPInt32Opt/lib/libcodeStream_28b21b5898ba159392899d5ac4d05a7158e0c6d6.so"
"/opt/OpenFOAM/OpenFOAM-9/etc/codeTemplates/dynamicCode/codeStreamTemplate.C" "/home/ariedinger/uni/gimap/openfoam/03emf/01huang/0rodFoam/rodFoamCase/dynamicCode/_28b21b5898ba159392899d5ac4d05a7158e0c6d6/codeStreamTemplate.C"
Invoking "wmake -s libso /home/ariedinger/uni/gimap/openfoam/03emf/01huang/0rodFoam/rodFoamCase/dynamicCode/_28b21b5898ba159392899d5ac4d05a7158e0c6d6"
wmake libso /home/ariedinger/uni/gimap/openfoam/03emf/01huang/0rodFoam/rodFoamCase/dynamicCode/_28b21b5898ba159392899d5ac4d05a7158e0c6d6
ln: ./lnInclude
wmkdep: codeStreamTemplate.C
Ctoo: codeStreamTemplate.C
ld: /home/ariedinger/uni/gimap/openfoam/03emf/01huang/0rodFoam/rodFoamCase/dynamicCode/_28b21b5898ba159392899d5ac4d05a7158e0c6d6/../platforms/linux64GccDPInt32Opt/lib/libcodeStream_28b21b5898ba159392899d5ac4d05a7158e0c6d6.so
codeStream : dictionary:"/home/ariedinger/uni/gimap/openfoam/03emf/01huang/0rodFoam/rodFoamCase/system/blockMeshDict" master-only-reading:1
Opening cached dictionary:"/home/ariedinger/uni/gimap/openfoam/03emf/01huang/0rodFoam/rodFoamCase/dynamicCode/platforms/linux64GccDPInt32Opt/lib/libcodeStream_28b21b5898ba159392899d5ac4d05a7158e0c6d6.so"
codeStream : dictionary:"/home/ariedinger/uni/gimap/openfoam/03emf/01huang/0rodFoam/rodFoamCase/system/blockMeshDict" master-only-reading:1
Using #calcEntry at line 27 in file "/home/ariedinger/uni/gimap/openfoam/03emf/01huang/0rodFoam/rodFoamCase/system/blockMeshDict"
Using #codeStream with "/home/ariedinger/uni/gimap/openfoam/03emf/01huang/0rodFoam/rodFoamCase/dynamicCode/platforms/linux64GccDPInt32Opt/lib/libcodeStream_efc80fd5ffbc4db1928cd9ff3362f686671433be.so"
Creating new library in "dynamicCode/_efc80fd5ffbc4db1928cd9ff3362f686671433be/platforms/linux64GccDPInt32Opt/lib/libcodeStream_efc80fd5ffbc4db1928cd9ff3362f686671433be.so"
"/opt/OpenFOAM/OpenFOAM-9/etc/codeTemplates/dynamicCode/codeStreamTemplate.C" "/home/ariedinger/uni/gimap/openfoam/03emf/01huang/0rodFoam/rodFoamCase/dynamicCode/_efc80fd5ffbc4db1928cd9ff3362f686671433be/codeStreamTemplate.C"
Invoking "wmake -s libso /home/ariedinger/uni/gimap/openfoam/03emf/01huang/0rodFoam/rodFoamCase/dynamicCode/_efc80fd5ffbc4db1928cd9ff3362f686671433be"
wmake libso /home/ariedinger/uni/gimap/openfoam/03emf/01huang/0rodFoam/rodFoamCase/dynamicCode/_efc80fd5ffbc4db1928cd9ff3362f686671433be
ln: ./lnInclude
wmkdep: codeStreamTemplate.C
Ctoo: codeStreamTemplate.C
ld: /home/ariedinger/uni/gimap/openfoam/03emf/01huang/0rodFoam/rodFoamCase/dynamicCode/_efc80fd5ffbc4db1928cd9ff3362f686671433be/../platforms/linux64GccDPInt32Opt/lib/libcodeStream_efc80fd5ffbc4db1928cd9ff3362f686671433be.so
codeStream : dictionary:"/home/ariedinger/uni/gimap/openfoam/03emf/01huang/0rodFoam/rodFoamCase/system/blockMeshDict" master-only-reading:1
Opening cached dictionary:"/home/ariedinger/uni/gimap/openfoam/03emf/01huang/0rodFoam/rodFoamCase/dynamicCode/platforms/linux64GccDPInt32Opt/lib/libcodeStream_efc80fd5ffbc4db1928cd9ff3362f686671433be.so"
codeStream : dictionary:"/home/ariedinger/uni/gimap/openfoam/03emf/01huang/0rodFoam/rodFoamCase/system/blockMeshDict" master-only-reading:1
Using #calcEntry at line 28 in file "/home/ariedinger/uni/gimap/openfoam/03emf/01huang/0rodFoam/rodFoamCase/system/blockMeshDict"
Using #codeStream with "/home/ariedinger/uni/gimap/openfoam/03emf/01huang/0rodFoam/rodFoamCase/dynamicCode/platforms/linux64GccDPInt32Opt/lib/libcodeStream_dc962d55c61555e401d9aa57fd57792f105fea79.so"
Creating new library in "dynamicCode/_dc962d55c61555e401d9aa57fd57792f105fea79/platforms/linux64GccDPInt32Opt/lib/libcodeStream_dc962d55c61555e401d9aa57fd57792f105fea79.so"
"/opt/OpenFOAM/OpenFOAM-9/etc/codeTemplates/dynamicCode/codeStreamTemplate.C" "/home/ariedinger/uni/gimap/openfoam/03emf/01huang/0rodFoam/rodFoamCase/dynamicCode/_dc962d55c61555e401d9aa57fd57792f105fea79/codeStreamTemplate.C"
Invoking "wmake -s libso /home/ariedinger/uni/gimap/openfoam/03emf/01huang/0rodFoam/rodFoamCase/dynamicCode/_dc962d55c61555e401d9aa57fd57792f105fea79"
wmake libso /home/ariedinger/uni/gimap/openfoam/03emf/01huang/0rodFoam/rodFoamCase/dynamicCode/_dc962d55c61555e401d9aa57fd57792f105fea79
ln: ./lnInclude
wmkdep: codeStreamTemplate.C
Ctoo: codeStreamTemplate.C
ld: /home/ariedinger/uni/gimap/openfoam/03emf/01huang/0rodFoam/rodFoamCase/dynamicCode/_dc962d55c61555e401d9aa57fd57792f105fea79/../platforms/linux64GccDPInt32Opt/lib/libcodeStream_dc962d55c61555e401d9aa57fd57792f105fea79.so
codeStream : dictionary:"/home/ariedinger/uni/gimap/openfoam/03emf/01huang/0rodFoam/rodFoamCase/system/blockMeshDict" master-only-reading:1
Opening cached dictionary:"/home/ariedinger/uni/gimap/openfoam/03emf/01huang/0rodFoam/rodFoamCase/dynamicCode/platforms/linux64GccDPInt32Opt/lib/libcodeStream_dc962d55c61555e401d9aa57fd57792f105fea79.so"
codeStream : dictionary:"/home/ariedinger/uni/gimap/openfoam/03emf/01huang/0rodFoam/rodFoamCase/system/blockMeshDict" master-only-reading:1
Using #calcEntry at line 29 in file "/home/ariedinger/uni/gimap/openfoam/03emf/01huang/0rodFoam/rodFoamCase/system/blockMeshDict"
Using #codeStream with "/home/ariedinger/uni/gimap/openfoam/03emf/01huang/0rodFoam/rodFoamCase/dynamicCode/platforms/linux64GccDPInt32Opt/lib/libcodeStream_4510c2296fa7a962a6a70dda03e9219ebc01dac4.so"
Creating new library in "dynamicCode/_4510c2296fa7a962a6a70dda03e9219ebc01dac4/platforms/linux64GccDPInt32Opt/lib/libcodeStream_4510c2296fa7a962a6a70dda03e9219ebc01dac4.so"
"/opt/OpenFOAM/OpenFOAM-9/etc/codeTemplates/dynamicCode/codeStreamTemplate.C" "/home/ariedinger/uni/gimap/openfoam/03emf/01huang/0rodFoam/rodFoamCase/dynamicCode/_4510c2296fa7a962a6a70dda03e9219ebc01dac4/codeStreamTemplate.C"
Invoking "wmake -s libso /home/ariedinger/uni/gimap/openfoam/03emf/01huang/0rodFoam/rodFoamCase/dynamicCode/_4510c2296fa7a962a6a70dda03e9219ebc01dac4"
wmake libso /home/ariedinger/uni/gimap/openfoam/03emf/01huang/0rodFoam/rodFoamCase/dynamicCode/_4510c2296fa7a962a6a70dda03e9219ebc01dac4
ln: ./lnInclude
wmkdep: codeStreamTemplate.C
Ctoo: codeStreamTemplate.C
ld: /home/ariedinger/uni/gimap/openfoam/03emf/01huang/0rodFoam/rodFoamCase/dynamicCode/_4510c2296fa7a962a6a70dda03e9219ebc01dac4/../platforms/linux64GccDPInt32Opt/lib/libcodeStream_4510c2296fa7a962a6a70dda03e9219ebc01dac4.so
codeStream : dictionary:"/home/ariedinger/uni/gimap/openfoam/03emf/01huang/0rodFoam/rodFoamCase/system/blockMeshDict" master-only-reading:1
Opening cached dictionary:"/home/ariedinger/uni/gimap/openfoam/03emf/01huang/0rodFoam/rodFoamCase/dynamicCode/platforms/linux64GccDPInt32Opt/lib/libcodeStream_4510c2296fa7a962a6a70dda03e9219ebc01dac4.so"
codeStream : dictionary:"/home/ariedinger/uni/gimap/openfoam/03emf/01huang/0rodFoam/rodFoamCase/system/blockMeshDict" master-only-reading:1
Using #calcEntry at line 30 in file "/home/ariedinger/uni/gimap/openfoam/03emf/01huang/0rodFoam/rodFoamCase/system/blockMeshDict"
Using #codeStream with "/home/ariedinger/uni/gimap/openfoam/03emf/01huang/0rodFoam/rodFoamCase/dynamicCode/platforms/linux64GccDPInt32Opt/lib/libcodeStream_0af64279ad3a68c6091e4927dfe1317848075c64.so"
Creating new library in "dynamicCode/_0af64279ad3a68c6091e4927dfe1317848075c64/platforms/linux64GccDPInt32Opt/lib/libcodeStream_0af64279ad3a68c6091e4927dfe1317848075c64.so"
"/opt/OpenFOAM/OpenFOAM-9/etc/codeTemplates/dynamicCode/codeStreamTemplate.C" "/home/ariedinger/uni/gimap/openfoam/03emf/01huang/0rodFoam/rodFoamCase/dynamicCode/_0af64279ad3a68c6091e4927dfe1317848075c64/codeStreamTemplate.C"
Invoking "wmake -s libso /home/ariedinger/uni/gimap/openfoam/03emf/01huang/0rodFoam/rodFoamCase/dynamicCode/_0af64279ad3a68c6091e4927dfe1317848075c64"
wmake libso /home/ariedinger/uni/gimap/openfoam/03emf/01huang/0rodFoam/rodFoamCase/dynamicCode/_0af64279ad3a68c6091e4927dfe1317848075c64
ln: ./lnInclude
wmkdep: codeStreamTemplate.C
Ctoo: codeStreamTemplate.C
ld: /home/ariedinger/uni/gimap/openfoam/03emf/01huang/0rodFoam/rodFoamCase/dynamicCode/_0af64279ad3a68c6091e4927dfe1317848075c64/../platforms/linux64GccDPInt32Opt/lib/libcodeStream_0af64279ad3a68c6091e4927dfe1317848075c64.so
codeStream : dictionary:"/home/ariedinger/uni/gimap/openfoam/03emf/01huang/0rodFoam/rodFoamCase/system/blockMeshDict" master-only-reading:1
Opening cached dictionary:"/home/ariedinger/uni/gimap/openfoam/03emf/01huang/0rodFoam/rodFoamCase/dynamicCode/platforms/linux64GccDPInt32Opt/lib/libcodeStream_0af64279ad3a68c6091e4927dfe1317848075c64.so"
codeStream : dictionary:"/home/ariedinger/uni/gimap/openfoam/03emf/01huang/0rodFoam/rodFoamCase/system/blockMeshDict" master-only-reading:1
Creating block edges
No non-planar block faces defined
Creating topology blocks
#0 Foam::error::printStack(Foam::Ostream&) at ??:?
#1 Foam::sigFpe::sigHandler(int) at ??:?
#2 ? in "/usr/lib/libc.so.6"
#3 Foam::face::centre(Foam::Field<Foam::Vector<double> > const&) const at ??:?
#4 Foam::blockDescriptor::check(Foam::Istream const&) at ??:?
#5 Foam::blockDescriptor::blockDescriptor(Foam::dictionary const&, int, Foam::Field<Foam::Vector<double> > const&, Foam::PtrList<Foam::blockEdge> const&, Foam::PtrList<Foam::blockFace> const&, Foam::Istream&) at ??:?
#6 Foam::block::block(Foam::dictionary const&, int, Foam::Field<Foam::Vector<double> > const&, Foam::PtrList<Foam::blockEdge> const&, Foam::PtrList<Foam::blockFace> const&, Foam::Istream&) at ??:?
#7 Foam::block::New(Foam::dictionary const&, int, Foam::Field<Foam::Vector<double> > const&, Foam::PtrList<Foam::blockEdge> const&, Foam::PtrList<Foam::blockFace> const&, Foam::Istream&) at ??:?
#8 void Foam::PtrList<Foam::block>::read<Foam::block::iNew>(Foam::Istream&, Foam::block::iNew const&) at ??:?
#9 Foam::blockMesh::createTopology(Foam::IOdictionary const&, Foam::word const&) at ??:?
#10 Foam::blockMesh::blockMesh(Foam::IOdictionary const&, Foam::word const&) at ??:?
#11 ? in "/opt/OpenFOAM/OpenFOAM-9/platforms/linux64GccDPInt32Opt/bin/blockMesh"
#12 __libc_start_main in "/usr/lib/libc.so.6"
#13 ? in "/opt/OpenFOAM/OpenFOAM-9/platforms/linux64GccDPInt32Opt/bin/blockMesh"
fish: Job 2, 'blockMesh' terminated by signal SIGFPE (Floating point exception)
So, I'm a bit at lost on where to look and I'd appreciate some tips to try and solve the error.
Besides changing #eval() for #calc in blockMeshDict, everything else is pretty much the same as in the original case but here are the rest of my files.
The given case appears to be built for OpenFOAM v2, and I'm trying to run it on OpenFOAM v9 (installed from the package openfoam-org from the AUR). So, maybe that would be a problem? Nonetheless, in the course the case was given in 2020 (look at Implement electromagnetic solver Case: rodFoamCase.tgz in Proceedings 2020).
Thanks in advance.
It would be worthwhile to test with "openfoam-com" as well to see if there is a difference there. Can either use an AUR recipe or (probably faster) test with a docker instance and openfom.com
https://develop.openfoam.com/Development/openfoam/-/wikis/precompiled/docker
void print(char *s) {
printf("%s\n", s);
}
I want to insert a call to the function above in an llvm pass. Here's my llvm pass code
Function *printFunc = M.getFunction("print");
if (printFunc) {
IRBuilder<> B(BB);
errs() << "print function: " << printFunc << "\n";
Value *v = B.CreateGlobalString("hi", "str");
ArrayRef<Value *> args(v);
Instruction *newInst = CallInst::Create(printFunc, args, "");
BB->getInstList().insert(I->getNextNode(), newInst);
}
Got the following error message:
opt: /workspace/LLVM_package/src/lib/IR/Instructions.cpp:279: void llvm::CallInst::init(llvm::Value*, llvm::ArrayRef<llvm::Value*>, const llvm::Twine&): Assertion `(i >= FTy->getNumParams() || FTy->getParamType(i) == Args[i]->getType()) && "Calling a function with a bad signature!"' failed.
0 opt 0x0000560a880abc62 llvm::sys::PrintStackTrace(_IO_FILE*) + 50
1 opt 0x0000560a880ab43c
2 libpthread.so.0 0x00007f8bd59d6800
3 libc.so.6 0x00007f8bd5476ce5 gsignal + 325
4 libc.so.6 0x00007f8bd5460857 abort + 299
5 libc.so.6 0x00007f8bd5460727
6 libc.so.6 0x00007f8bd546f426
7 opt 0x0000560a880177c1 llvm::CallInst::init(llvm::Value*, llvm::ArrayRef<llvm::Value*>, llvm::Twine const&) + 465
8 MyLLVMPass.so 0x00007f8bd5431377
9 opt 0x0000560a88036636 llvm::legacy::PassManagerImpl::run(llvm::Module&) + 822
10 opt 0x0000560a8724d072 main + 2626
11 libc.so.6 0x00007f8bd5462023 __libc_start_main + 243
12 opt 0x0000560a87267afe _start + 46
Stack dump:
0. Program arguments: opt -S -analyze -load ./build/Release+Asserts/lib/MyLLVMPass.so -MyLLVMPass
1. Running pass 'MyLLVMPass' on module '<stdin>'.
run_myllvmpass.sh: line 11: 60257 Aborted (core dumped) opt -S -analyze -load ./build/Release+Asserts/lib/MyLLVMPass.so -MyLLVMPass < ${var1} > ${var2}
Can anyone point out what I did wrong?
Your print function expects a pointer of type i8* but B.CreateGlobalString("hi", "str"); returns a pointer to an array of type i8. Use B.CreateGlobalStringPtr("hi", "str"); instead.
I am getting this error
> clang -std=c99 -c derivative.c -o derivative.a
fatal error: error in backend: Cannot select: intrinsic %llvm.spu.si.sf
when I try to compile this simple C program with Clang
#include <stdio.h>
#include <math.h>
int N = 100;
double H = 0.001;
double PI = 3.14159265;
void derive(double* input, long elements, double* output) {
for (int i = 1; i < elements - 1; i++) {
output[i - 1] = (input[i + 1] - input[i - 1])/ (2 * H);
}
}
int main() {
double f[N];
double f_prime[N - 2];
for (int i = 0; i < N; i++) {
f[i] = sin(i * 2 * PI / (double)N);
}
derive(f, N, f_prime);
for (int i = 0; i < N - 2; i++) {
printf("%f %f\n", i * 2 * PI / (double)N, f_prime[i]);
}
}
I already searched the Internet, but was not (yet) able to find a solution.
When I compile to Bitcode, it compiles but the execution dumps core.
> clang -emit-llvm -c derivative.c -o derivative.bc
> lli derivative.bc
lli: BitcodeReader.cpp:283: llvm::Value* llvm::BitcodeReaderValueList::getValueFwdRef(unsigned int, llvm::Type*): Assertion `(Ty == 0 || Ty == V->getType()) && "Type mismatch in value table!"' failed.
0 lli 0x0000000000c6fb02
1 lli 0x0000000000c6ff93
2 libpthread.so.0 0x00007f304d7dbbd0
3 libc.so.6 0x00007f304ca19037 gsignal + 55
4 libc.so.6 0x00007f304ca1c698 abort + 328
5 libc.so.6 0x00007f304ca11e03
6 libc.so.6 0x00007f304ca11eb2
7 lli 0x000000000052eeb0 llvm::BitcodeReaderValueList::getConstantFwdRef(unsigned int, llvm::Type*) + 0
8 lli 0x0000000000538943 llvm::BitcodeReader::ParseFunctionBody(llvm::Function*) + 10275
9 lli 0x000000000053acb1 llvm::BitcodeReader::Materialize(llvm::GlobalValue*, std::string*) + 241
10 lli 0x0000000000535195 llvm::BitcodeReader::MaterializeModule(llvm::Module*, std::string*) + 85
11 lli 0x0000000000c0a82f llvm::Module::MaterializeAllPermanently(std::string*) + 31
12 lli 0x00000000005360fc llvm::ParseBitcodeFile(llvm::MemoryBuffer*, llvm::LLVMContext&, std::string*) + 44
13 lli 0x00000000004f70b7
14 lli 0x00000000004e74f3 main + 339
15 libc.so.6 0x00007f304ca03ea5 __libc_start_main + 245
16 lli 0x00000000004f0f41
Stack dump:
0. Program arguments: lli derivative.bc
Aborted (core dumped)
Trying llvm-dis on the bc-file yields an almost identical core dump.
EDIT:
I tried to find the minimal failing example, and it seems, the problem is defining the array size via the constant.
this fails:
int main() {
int N = 100;
double f[N];
}
this works:
int main() {
double f[100];
}
EDIT2:
Changing int N = 100 to const int N = 100 makes the program compile with Clang.
It makes sense that the variable should be const, but on the other hand, gcc -std=c99 -Wall derivative.c -lm does not complain if it is not const.
This is ubuntu bug: https://bugs.launchpad.net/ubuntu/+source/llvm-3.2/+bug/1131614. Looks like they patched llvm+clang blindly, without understanding what they are doing.
The fatal error message is an indication you have discovered a bug in the compiler. Try reporting the bug at llvm.org/bugs.
While trying to compile an LLVM IR, like this
llc main.ll -o main.s && g++ main.s -O3 -o main -pthread
I get the following error. The same thing compiles on my Ubuntu 10 system, but in the CentOS I get the following error. Any idea what is going on here and why LLVM is going mad? And lastly, how to solve this?
llc: /home/schism/llvm/include/llvm/ADT/IntervalMap.h:606: unsigned int llvm::IntervalMapImpl::LeafNode< <template-parameter-1-1>, <template-parameter-1-2>, <anonymous>, <template-parameter-1-4> >::insertFrom(unsigned int&, unsigned int, KeyT, KeyT, ValT) [with KeyT = llvm::SlotIndex, ValT = unsigned int, unsigned int N = 9u, Traits = llvm::IntervalMapInfo<llvm::SlotIndex>]: Assertion `!Traits::stopLess(b, a) && "Invalid interval"' failed.
0 llc 0x0000000000d5009f
1 llc 0x0000000000d50db7
2 libpthread.so.0 0x0000003cfde0ebe0
3 libc.so.6 0x0000003cfce30285 gsignal + 53
4 libc.so.6 0x0000003cfce31d30 abort + 272
5 libc.so.6 0x0000003cfce29706 __assert_fail + 246
6 llc 0x000000000093624c llvm::IntervalMapImpl::LeafNode<llvm::SlotIndex, unsigned int, 9u, llvm::IntervalMapInfo<llvm::SlotIndex> >::insertFrom(unsigned int&, unsigned int, llvm::SlotIndex, llvm::SlotIndex, unsigned int) + 716
7 llc 0x0000000000936a00
8 llc 0x0000000000929898 llvm::SplitEditor::useIntv(llvm::SlotIndex, llvm::SlotIndex) + 88
9 llc 0x000000000092f369 llvm::SplitEditor::splitRegInBlock(llvm::SplitAnalysis::BlockInfo const&, unsigned int, llvm::SlotIndex) + 1513
10 llc 0x00000000008c20ea
11 llc 0x00000000008c3c78
12 llc 0x00000000008c90d1
13 llc 0x00000000008c95ab
14 llc 0x0000000000a06c84 llvm::RegAllocBase::allocatePhysRegs() + 324
15 llc 0x00000000008c4edc
16 llc 0x0000000000880005 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) + 53
17 llc 0x0000000000ce4c66 llvm::FPPassManager::runOnFunction(llvm::Function&) + 646
18 llc 0x0000000000ce4cfd llvm::FPPassManager::runOnModule(llvm::Module&) + 45
19 llc 0x0000000000ce641c llvm::MPPassManager::runOnModule(llvm::Module&) + 556
20 llc 0x0000000000ce657e llvm::PassManagerImpl::run(llvm::Module&) + 174
21 llc 0x0000000000ce66dd llvm::PassManager::run(llvm::Module&) + 13
22 llc 0x00000000004d0f1b main + 5451
23 libc.so.6 0x0000003cfce1d994 __libc_start_main + 244
24 llc 0x00000000004ce8e9
Stack dump:
0. Program arguments: llc main.ll -o main.s
1. Running pass 'Function Pass Manager' on module 'main.ll'.
2. Running pass 'Greedy Register Allocator' on function '#_Z7InitSimPKcj'
Aborted
Looks like LLVM is miscompiled by your system compiler. See http://llvm.org/docs/GettingStarted.html#brokengcc for a list of known broken compilers.
The solution is simple - use other version of the compiler (gcc in your case) to compile LLVM.
There's a similar problem to this floating around here somewhere. Answer was to check the versions of gcc and llvm. Turned out one was 32 bit the other 64 bit. ymmv.