Skip to content

Conversation

@afshin-zafari
Copy link
Contributor

@afshin-zafari afshin-zafari commented Sep 26, 2023

  • The ATTRIBUTE_PRINTF usage in cpp files is useless. They are removed.
  • There are cases where jio_xxprintf functions use char * arguments for format string, rather than a literal like "%s...". These cases are not compiled when ATTRIBUTE_PRINTF is used for them. So, first I used the attribute and got the corresponding compile errors. Then I fixed the issues and removed the attribute when all issues were fixed.

Test

The changes are tested on all platforms tiers 1-4.


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8198918: jio_snprintf and friends are not checked by -Wformat (Enhancement - P4)

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/15918/head:pull/15918
$ git checkout pull/15918

Update a local copy of the PR:
$ git checkout pull/15918
$ git pull https://git.openjdk.org/jdk.git pull/15918/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 15918

View PR using the GUI difftool:
$ git pr show -t 15918

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/15918.diff

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Sep 26, 2023

👋 Welcome back azafari! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk openjdk bot added the rfr Pull request is ready for review label Sep 26, 2023
@openjdk
Copy link

openjdk bot commented Sep 26, 2023

@afshin-zafari The following labels will be automatically applied to this pull request:

  • graal
  • hotspot

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing lists. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added graal graal-dev@openjdk.org hotspot hotspot-dev@openjdk.org labels Sep 26, 2023
@mlbridge
Copy link

mlbridge bot commented Sep 26, 2023

Webrevs

@afshin-zafari afshin-zafari marked this pull request as draft September 26, 2023 11:55
@openjdk openjdk bot removed the rfr Pull request is ready for review label Sep 26, 2023
if (BootstrapJVMCI && (TieredStopAtLevel < CompLevel_full_optimization)) {
jio_fprintf(defaultStream::error_stream(),
"-XX:+BootstrapJVMCI is not compatible with -XX:TieredStopAtLevel=%d\n", TieredStopAtLevel);
"-XX:+BootstrapJVMCI is not compatible with -XX:TieredStopAtLevel=" INTX_FORMAT "\n", TieredStopAtLevel);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The real problem here is that TieredStopAtLevel is inappropriately declared to be an intx.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change required changes to 18 Java files and then many test failures in mach5 tiers tests. So, I removed the changes to avoid diverging from this PR.

const int printed = jio_snprintf(buffer, buffer_length,
"%04d-%02d-%02dT%02d:%02d:%02d.%03d%c%02d%02d",
const int printed = os::snprintf(buffer, buffer_length,
"%04d-%02d-%02dT%02d:%02d:%02d.%03d%c%02ld%02ld",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is making the unwarranted assumption that time_t == long. Also, the "l" length modifier should
probably never be used in shared code, just as the long type shouldn't be used, because of the LP vs LLP
issue. Better would be to declare zone_hours and zone_min to be int, and explicitly convert the initial
value expressions to int.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both are wrong. You can use %02d but must explicitly cast to int (or to long if you use %02ld but that makes no sense for a two-digit number) because time_t is often wider than long… which -Wformat would have shown.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, nevermind, I see now that the PR was changed to change the variable type instead… which is fair in this situation.

if (ReservedCodeCacheSize < InitialCodeCacheSize) {
jio_fprintf(defaultStream::error_stream(),
"Invalid ReservedCodeCacheSize: %dK. Must be at least InitialCodeCacheSize=%dK.\n",
"Invalid ReservedCodeCacheSize: " UINTX_FORMAT "K. Must be at least InitialCodeCacheSize=" UINTX_FORMAT "K.\n",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like all these size values ought to be size_t rather than uintx, in which case could use "%zu".
I don't know what the fannout for changing the types might be.

Copy link
Contributor Author

@afshin-zafari afshin-zafari Oct 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. There were also some related changes in JTREG Java files.

Copy link
Contributor Author

@afshin-zafari afshin-zafari left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Parts of the requested changes are done. Some others made many other unrelated changes. They may be handled in Wconversion change.

@afshin-zafari
Copy link
Contributor Author

@kimbarrett,
Any comments?

@afshin-zafari
Copy link
Contributor Author

I close this PR since the solution is not applicable to the jio_xxprintf invocations where a char * is used as the format string and not a string literal (e.g., "%s...%d"). In these cases we cannot get help from compiler to warn on mismatching formats, rather we get compile errors.

@mirabilos
Copy link

Why did this not add the ATTRIBUTE_PRINTF to prims/jvm.h where it belongs?

@afshin-zafari afshin-zafari deleted the _8198918 branch June 13, 2025 10:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

graal graal-dev@openjdk.org hotspot hotspot-dev@openjdk.org

Development

Successfully merging this pull request may close these issues.

3 participants