[LLVMdev] llvm2cpp attributes handling

Harris BAKIRAS h.bakiras at gmail.com
Mon Mar 25 09:15:26 PDT 2013


Hi everyone,

We are using the llvm2cpp feature of LLVM in the VMKit project and there 
are some issues that I would like to point out.

I made a tiny reproducible example here, to be clear:

echo "int main() { return 0; };" > test.c && clang test.c -emit-llvm -c 
-o - | llc -march=cpp -cppgen=function -cppfor=main -o -

This command is supposed to generate the C++ code to construct the main 
function in LLVM (see main_llvm2cpp.cc joined file).
But an error occurs while generating the code (see stack trace below).

It appears that an assertion is broken while treating attributes in the 
file CPPBackend.cpp.
So I dumped the main function's attributes before treating them, here is 
the result:

PAL[
   { ~0U => *nounwind uwtable* "less-precise-fpmad"="false" 
"no-frame-pointer-elim"="false" "no-frame-pointer-elim-non-leaf"="true" 
"no-infs-fp-math"="false" "no-nans-fp-math"="false" 
"unsafe-fp-math"="false" "use-soft-float"="false" }
]

The problem is that llvm2cpp code generation supports only the 
attributes present in the AttrKind enum of the Attribute class.
It means that the following attributes are not supported:
     - "less-precise-fpmad"
     - "no-frame-pointer-elim"
     - "no-frame-pointer-elim-non-leaf"
     - "no-infs-fp-math"
     - "no-nans-fp-math"
     - "unsafe-fp-math"
     - "use-soft-float"

What is extremely strange, is that those attributes are set by clang 
with no particular option.

So, is the assert in CPPBackend.cpp deprecated or should those 
attributes be handled somehow in C++ code generation (which means that 
the previous attribute list should be added to the AttrKind enum of the 
Attribute class)?

Cheers,

-- 

Harris Bakiras

    llc: CPPBackend.cpp:521: void 
{anonymous}::CppWriter::printAttributes(const llvm::AttributeSet&, const 
string&): Assertion `!attrs.hasAttributes() && "Unhandled attribute!"' 
failed.
0  llc             0x00000000010edc22 
llvm::sys::PrintStackTrace(_IO_FILE*) + 34
1  llc             0x00000000010ed049
2  libpthread.so.0 0x00007f9701addcb0
3  libc.so.6       0x00007f9700d2f425 gsignal + 53
4  libc.so.6       0x00007f9700d32b8b abort + 379
5  libc.so.6       0x00007f9700d280ee
6  libc.so.6       0x00007f9700d28192
7  llc             0x000000000064fed3
8  llc             0x000000000065335b
9  llc             0x0000000000659fed
10 llc             0x000000000065b0dc
11 llc             0x0000000001081230 
llvm::MPPassManager::runOnModule(llvm::Module&) + 688
12 llc             0x0000000001081405 
llvm::PassManagerImpl::run(llvm::Module&) + 245
13 llc             0x0000000000565d27
14 llc             0x0000000000551281 main + 353
15 libc.so.6       0x00007f9700d1a76d __libc_start_main + 237
16 llc             0x0000000000561fd5
Stack dump:
0.    Program arguments: llc -march=cpp -cppgen=function -cppfor=main -o -
1.    Running pass 'C++ backend' on module '<stdin>'.
Aborted (core dumped)

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130325/d6dca767/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: main_llvm2cpp.cc
Type: text/x-c++src
Size: 1683 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130325/d6dca767/attachment.cc>


More information about the llvm-dev mailing list