-
Notifications
You must be signed in to change notification settings - Fork 397
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use custom function to format TRIL code #5587
base: master
Are you sure you want to change the base?
Conversation
@genie-omr build all |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for doing this @janvrany! This will simplify things for sure. A few general comments:
- Using fixed width integer types to overload functions (
literal()
in this case) can sometimes cause ambiguity problems because multiple primitive types can have the same size. For example, bothlong int
andlong long int
can be 64-bits wide, but are required to be distinct types.int64_t
can only be a typedef for one of the two. Becauselong int
(andunsigned long int
for that matter) can be implicitly converted to eitherlong long int
orunsigned long long int
, overloading withint64_t
anduint64_t
can cause an ambiguity if the latter are typedefs forlong long int
andunsigned long long int
, respectively. See the osx failure [1] and Compiler Explorer example [2]. - I think Tril already uses variadic templates for some things (see [3]) so I believe you should be able to use one for
Tril::format
. - Can you add some tests for this new tool? 🙂
[1] https://ci.eclipse.org/omr/job/PullRequest-osx_x86-64/2021/console
fvtest/tril/tril/format.hpp
Outdated
|
||
inline size_t literal(char* dst, const size_t size, const void* value) | ||
{ | ||
return std::snprintf(dst, size, "%" OMR_PRIXPTR, value); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe PRIXPTR
is technically for intptr_t
and clang is reporting a warning about this. Might need to add a reinterpret_cast.
return std::snprintf(dst, size, "%" OMR_PRIXPTR, value); | |
return std::snprintf(dst, size, "%" OMR_PRIXPTR, reinterpret_cast<intptr_t>(value)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I've seen that. Will fix as suggested.
fvtest/tril/tril/format.hpp
Outdated
{ | ||
if (*fmt == '%') | ||
{ | ||
throw std::runtime_error("found conversion specifier but no value given"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should there be a special case for %%?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed. Thanks!
fvtest/compilertriltest/CallTest.cpp
Outdated
const auto format_string = "(method return=Int32 args=[Int32] (block (ireturn (icall address=0x%jX args=[Int32] (iload parm=0)) ) ))"; | ||
std::snprintf(inputTrees, 200, format_string, reinterpret_cast<uintmax_t>(&oracleBoracle)); | ||
const auto format_string = "(method return=Int32 args=[Int32] (block (ireturn (icall address=0x%X args=[Int32] (iload parm=0)) ) ))"; | ||
Tril::format(inputTrees, 200, format_string, reinterpret_cast<void*>(&oracleBoracle)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this can become a static_cast now?
Tril::format(inputTrees, 200, format_string, reinterpret_cast<void*>(&oracleBoracle)); | |
Tril::format(inputTrees, 200, format_string, static_cast<void*>(&oracleBoracle)); |
Thanks for this review, @Leonardo2718 - and for all that will follow as this would - I'm afraid - take a couple of iterations!
Yeah, I guess so. I was afraid somebody would ask for them. :-)
Brilliant, I was put off by explicit mentioning in Unsupported C++11 Features
I'm actually thinking of using them. The idea is to have
This may provide more flexbility (removes "one formatting rules them all" for any given type), may provide more
I'll make a second pass next week. Thanks for having a look! |
Yeah..... sorry about that 😅
Hm, we've upgraded some of our compilers since the last time that document was revised. I've opened #5592 to revisit that list and bring it up to date.
Oh, interesting! 👍 |
21f8a89
to
5370ed3
Compare
@genie-omr build all |
@genie-omr build all Re-running CI to see if there are any failures. |
Just to let you know I still plan to finish this, but got distracted by all the J9, CI, linkage...will get back to it. |
Cool. Thanks @janvrany. |
5370ed3
to
00248d1
Compare
jenkins build all |
00248d1
to
d7e9c57
Compare
jenkins build all |
d7e9c57
to
27f372d
Compare
jenkins build zos aix |
1 similar comment
jenkins build zos aix |
jenkins build zos |
0e8a93b
to
7f9b99c
Compare
7b277b5
to
55b7637
Compare
jenkins build zos aix |
This commit introduces new template function `Tril::format()` that is to be used to format TRIL code in tests designed as drop-in replacement for `std::snprintf()` except that: 1. support only a (used) subset of *printf-like conversion specifiers, 2. "modifiers" like l, ll, h, hh, j, I, I32 and I64 are ignored and 3. used conversion specifier and a static type of actual parameter must match (it is not possible to format `double` using `%X` conversion) Use of a template function and static types rather than *printf-like conversion flags allows `Tril::format()` to be used in another templates and thus will allow to further simplify test creation. Moreover, this makes TRIL formatting independent on `std::snprintf()` which is known to behave differently on different systems. Therefore, this commit introduces indirection required to fix eclipse-omr#5183 and eclipse-omr#5324.
Since XLC compiler used at a time on AIX and ZOS does not support std::make_signed, this commit provides simplified drop-in replacement for use in reinterpret_as_signed(). Once XLC compiler on AIX and ZOS is upgraded to support std::make_signed, this simplified version can be removed in favour of standard version.
…f std::snprintf()
187c1bd
to
ad7275b
Compare
jenkins build all |
I finally got back to it hoping that over time compilers would be bumped to newer versions which would solve some mysterious template-related error messages I've got couple years ago. After a lot of trial and error on platforms I have no access to I thing I've got it working. The failure on macOS seems unrelated (jitbuilder API generator test), the failure on RISC-V seems to be #6905. On my RISC-V systems, FYI @0xdaryl as I'm not sure who maintains TRIL these days. |
This commit introduces new template function
Tril::format()
thatis to be used to format TRIL code in tests designed as drop-in
replacement for
std::snprintf()
except that:can/will be removed with allowed use of variadic templates),
on specified conversion (different conversion flags are supported
for
std::snprintf()
compatibility)Use of a template function and static types rather than *printf-like
conversion flags allows
Tril::format()
to be used in another templatesand thus will allow to further simplify test creation.
Moreover, this makes TRIL formatting independent on
std::snprintf()
which is known to behave differently on different systems. Therefore,
this commit introduces indirection required to fix #5183 and #5308 .