Skip to content

[libc++][test] Bogus loops in time.cal.ymdlast.nonmembers/comparisons.pass.cpp #100502

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

Closed
StephanTLavavej opened this issue Jul 25, 2024 · 1 comment · Fixed by #101890
Closed
Assignees
Labels
libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. test-suite

Comments

@StephanTLavavej
Copy link
Member

Recently introduced by @mordante's #98169.

MSVC's /analyze complains:

D:\GitHub\STL\llvm-project\libcxx\test\std\time\time.cal\time.cal.ymdlast\time.cal.ymdlast.nonmembers\comparisons.pass.cpp(62) : warning C6294: Ill-defined for-loop.  Loop body not executed.
D:\GitHub\STL\llvm-project\libcxx\test\std\time\time.cal\time.cal.ymdlast\time.cal.ymdlast.nonmembers\comparisons.pass.cpp(63) : warning C6294: Ill-defined for-loop.  Loop body not executed.

This warning is usually a nuisance (complaining about loops that intentionally perform no iterations; calling them "ill-defined" isn't great either), but in this case it found actually-squirrely code 🐿️ :

// same month, different years
for (int i = 1000; i < 20; ++i)
for (int j = 1000; j < 20; ++j)
assert((testOrder(year_month_day_last{year{i}, month_day_last{January}},
year_month_day_last{year{j}, month_day_last{January}},
i == j ? std::strong_ordering::equal
: i < j ? std::strong_ordering::less
: std::strong_ordering::greater)));

I'm not sure what this code was intended to be doing. It appears that "same month, different years" previously looped from 1000 to 2000. Perhaps 1000 * 1000 = 1 million nested iterations was excessive, and the code should be looping from (say) 1000 to 1020?

@github-actions github-actions bot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Jul 25, 2024
@mordante mordante self-assigned this Jul 25, 2024
@mordante
Copy link
Member

mordante commented Aug 4, 2024

Thanks for reporting this!

I'm not sure what this code was intended to be doing. It appears that "same month, different years" previously looped from 1000 to 2000. Perhaps 1000 * 1000 = 1 million nested iterations was excessive, and the code should be looping from (say) 1000 to 1020?

Not just excessive, but it exceeds the number of constexpr steps allowed by the compiler. In differfent tests I changed the range to 1000 to 1010 so I'll do the same here.

mordante added a commit to mordante/llvm-project that referenced this issue Aug 4, 2024
Changes the loop range to match similar tests and avoids zero
iterations. The original motivation to reduce the number of iterations
was to allow the test to be executed during constant evaluation.

Fixes: llvm#100502
mordante added a commit that referenced this issue Aug 6, 2024
Changes the loop range to match similar tests and avoids zero
iterations. The original motivation to reduce the number of iterations
was to allow the test to be executed during constant evaluation.

Fixes: #100502
blueboxd pushed a commit to blueboxd/libcxx that referenced this issue Apr 19, 2025
Changes the loop range to match similar tests and avoids zero
iterations. The original motivation to reduce the number of iterations
was to allow the test to be executed during constant evaluation.

Fixes: llvm/llvm-project#100502
NOKEYCHECK=True
GitOrigin-RevId: 642259a2f21feffb0dc048162b4ce40b1e5a303d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. test-suite
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants