-
Notifications
You must be signed in to change notification settings - Fork 729
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
J9UTF8 FAM? #10244
Comments
Specifically, beyond being undefined behavior, this code fails to compile with gcc 10:
|
Given that we already have macros to access the size and data, the correct thing to do would be to declare J9UTF8 as an opaque structure and modify the macros to operate on the known offsets. We already have a setter for the size field. It's convenient to retain the structure name (as opposed to just making them all This is very similar to what I proposed in eclipse-omr/omr#5027 |
I agree the highlighted code is pretty obtuse. |
Oh, looking at that code I guess it should be read as |
Yeah, this code predates any modern C compiler. 2 was selected so that the total structure size was 4 (size of a pointer back then). 0 wasn't allowed in old compilers. Also, back in the day, sizeof was unreliable - some compilers padded structures, others did not. If you do as you propose, your code will not compile once the structure is opaque. |
Rather than making the structure opaque, I'm trying it with just the data field removed (to support older compilers). |
I was looking at a similar issue in OMR, where we do the same thing for UTTraceRecord. This then causes problems because we then
|
I'm also having trouble with the verifier, which has somehow embedded the knowledge that UTF8 is 4 bytes. None of the three solutions will work until that is addressed. |
According to https://stackoverflow.com/a/39152330, it is supported in at least MSVC 2015 with a warning in C++ mode. However, regarding OMR, my understanding is that such constructs are not supposed to be used in C++ anyways, and instead the struct should contain a pointer which is allocated internally; see std::string, std::vector.
I also had this problem.
|
Actually, there are more fake array members in OMR than that. Just searching for |
Also, I'd like to emphasize that the issue is not limited to compiler warnings. GCC has been documented to optimize aggressively based on invalid array sizes: https://lkml.org/lkml/2015/2/18/407. I don't know if this is still the case, but it's certainly a potential correctness issue, not just a warning issue. |
We still use VS2010 to compile Windows. We're planning to move to VS2013 #10129 since this is the highest level supported by OpenJDK atm. https://github.com/ibmruntimes/openj9-openjdk-jdk8/blob/openj9/common/autoconf/toolchain_windows.m4#L61 |
The errors mentioned by #10244 (comment) should be fixed by #10299. |
I've found the verifier issue - hopefully will have a fix out soon. |
@Hello71 Can you give my branch a try and see if it it fixes your issues? It's here: |
@gacholio seems to work on 15 (14 master doesn't compile atm?). for some reason without the patch I only get a warning, not an error. I'm not really convinced that removing the member is a better option than just making it a flexible array, but I guess it's fine. the commit messages are a little funny, but functionally it seems to work alright. thanks! |
I've tried the FAM, but it doesn't work on the outdated windows compilers that we use. |
That doesn't sound right, unless a different compiler is used for omr. As I point out in eclipse-omr/omr#5444, FAMs are already used in at least two places in omr. They're just hidden by |
Yep, adding the pragma fixes the problem. |
I didn't find any FAMs elsewhere in openj9, but if eclipse-omr/omr#5444 is accepted, I think it would make sense to use /wd4200 here too. |
I don't think we should use |
why is that? are there some contexts in which you want to keep pre-2015 MSVC compatibility? |
It isn't about compatibility, it's about ignoring warnings cautiously and selectively. |
While I agree completely with @keithc-ca in principle, I would be in favour of just disabling this warning. Windows is the only platform that doesn't support FAM by default, so there's no real value in causing a compile error on Windows when every other platform would succeed. |
I agree with @gacholio on this issue. I agree entirely that disabling warnings should be done cautiously, and have made a point to do so in exactly this case: I was and continue to be opposed to disabling the -Wstringop-overflow warning, since doing so potentially hides overly aggressive gcc optimization causing incorrect code generation. I am also opposed to globally disabling warnings that trigger on arguably-correct code, such as -Wimplicit-fallthrough, since those can potentially hide serious bugs. In this case, I think this warning is there mostly for historic reasons (Microsoft doesn't like C99), and partially for strict C++ compliance reasons (flexible array members are not technically allowed in C++), but in practice there are no useful implementations which forbid it, and no plausible future implementation would silently generate incorrect code for a FAM. Furthermore, I don't see any reason why FAMs would work in some contexts but not others in OpenJ9. Perhaps in some other projects, you might want to forbid them in header files (since other other projects may include them), but as far as I know, that's not the case here. |
Also fix all direct uses of J9UTF8 fields to use the access macros. Fixes: eclipse-openj9#10244 Signed-off-by: Graham Chapman <[email protected]>
I'm a little confused about the J9UTF8 struct. It seems that the data member is actually a flexible array member. In that case, this is both confusing because it is both undefined behavior and raises the question of why 2 was selected instead of 0 or 1.
Code like https://github.com/eclipse/openj9/blob/master/runtime/cfdumper/romdump.c#L157 is also confusing.
The text was updated successfully, but these errors were encountered: