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>
+Bill who worked on the attribute change On Mon, Mar 25, 2013 at 9:15 AM, Harris BAKIRAS <h.bakiras at gmail.com> wrote:> 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)?I believe that the C++ code generation should be updated (patches welcome - if you're relying on this functionality you may wish to contribute to it as I believe it's not much more than a learning tool for most other users/developers & is liable to rot fairly easily (if it's important to you, a bot/test cases to keep it working might be useful)) but probably not by "handling" the new attributes specifically. I think with the new attributes API there should be a general solution that doesn't require handling specific attributes explicitly, though I may be wrong. - David> > 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) > > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >
On Mar 25, 2013, at 9:15 AM, Harris BAKIRAS <h.bakiras at gmail.com> wrote:> Hi everyone, > > 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)? >Hi Harris, These shouldn't be added to the AttrKind list. I went ahead and removed the assert, because it's not really that useful anymore. -bw
Hello, I saw that the breaking assert was removed. Anyway, I made a patch to add the target dependent attributes when generating the code in CPPBackend.cpp. As you told me, the new API provides functions for general solution. Harris Bakiras On 03/25/2013 05:28 PM, David Blaikie wrote:> +Bill who worked on the attribute change > > On Mon, Mar 25, 2013 at 9:15 AM, Harris BAKIRAS <h.bakiras at gmail.com> wrote: >> 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)? > I believe that the C++ code generation should be updated (patches > welcome - if you're relying on this functionality you may wish to > contribute to it as I believe it's not much more than a learning tool > for most other users/developers & is liable to rot fairly easily (if > it's important to you, a bot/test cases to keep it working might be > useful)) but probably not by "handling" the new attributes > specifically. I think with the new attributes API there should be a > general solution that doesn't require handling specific attributes > explicitly, though I may be wrong. > > - David > >> 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) >> >> >> _______________________________________________ >> LLVM Developers mailing list >> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu >> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >>-------------- next part -------------- A non-text attachment was scrubbed... Name: cppgen.patch Type: text/x-patch Size: 816 bytes Desc: not available URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130327/8213531e/attachment.bin>