This is an archive of the discontinued LLVM Phabricator instance.

[libc] Fix matching on struct tm
Needs ReviewPublic

Authored by ddcc on Nov 3 2022, 3:40 PM.

Details

Summary

Ensure that struct tm pointer is not nullptr, and verify that all (not any) fields match

Diff Detail

Event Timeline

ddcc created this revision.Nov 3 2022, 3:40 PM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptNov 3 2022, 3:40 PM
ddcc requested review of this revision.Nov 3 2022, 3:40 PM
ddcc updated this revision to Diff 473065.Nov 3 2022, 3:50 PM

Fix incorrect testcase for gmtime

ddcc updated this revision to Diff 473069.Nov 3 2022, 4:00 PM

Fix incorrect testcase for gmtime_r

ddcc updated this revision to Diff 473095.Nov 3 2022, 6:23 PM

More gmtime test fixes

ddcc updated this revision to Diff 473096.Nov 3 2022, 6:36 PM

More gmtime_r test fixes

ddcc updated this revision to Diff 473098.Nov 3 2022, 6:39 PM

Last wrong testcase for gmtime

Ate these test changes enough to catch this? It seems a bit magical with the numbers. Should there be an explicit test that tests matching more than one field?

Thanks for the above fix (facepalm). In the following CL, jeff and I reworked the test code to make it more readable.

In https://reviews.llvm.org/D130405, https://reviews.llvm.org/differential/changeset/?ref=3574155

ddcc added a comment.EditedNov 7 2022, 10:50 AM

Ate these test changes enough to catch this? It seems a bit magical with the numbers. Should there be an explicit test that tests matching more than one field?

I'm not sure I understand the question. There were three issues with the tests that this commit fixes:

  1. The tests don't check that the pointer tm_data is not NULL before dereferencing it
  2. The test matcher only checked that at least one field of struct tm matches, and not that all fields match.
  3. Multiple testcases contained incorrect values for the tm_yday field.

I've been running the llvm-libc tests against a different libc, which is what led me to identify these testcase issues. After these above fixes, the tests against that libc no longer fail. I haven't manually tested these changes against the llvm-libc implementation itself, but from looking at the CI build output they seem fine.

As for the formatting changes, that looks good to me.