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,
main_llvm2cpp.cc (1.64 KB)
+Bill who worked on the attribute change
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
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
cppgen.patch (816 Bytes)