This is an archive of the discontinued LLVM Phabricator instance.

[libcxx][tests] Introduce 32-bit feature and use it for stringstream gcount test
ClosedPublic

Authored by azat on May 21 2023, 1:33 AM.

Details

Summary

This will avoid hardcoding all unsupported targets, since even after one
more follow up fix [1], there is one more failure.

[1]: https://reviews.llvm.org/D150886

Plus, if you want to run it locally on some target that CI does not
covers, it could also false-positively fail, which is not good.

Diff Detail

Event Timeline

azat created this revision.May 21 2023, 1:33 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 21 2023, 1:33 AM
Herald added a subscriber: arichardson. · View Herald Transcript
azat requested review of this revision.May 21 2023, 1:33 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 21 2023, 1:33 AM
Herald added a reviewer: Restricted Project. · View Herald Transcript
azat added a comment.May 22 2023, 8:00 AM

Looks like CI failures is unrelated?

Thanks. I can confirm that it works for me.

Thanks for the followup patch!

libcxx/utils/libcxx/test/features.py
387

I'm not convinced we should rely on __SIZEOF_SIZE_T__ being available at least we should test here it's defined. (Alternatively we do a runtime test, for an example see has-unix-headers.)

azat updated this revision to Diff 524378.May 22 2023, 10:21 AM

Fallback to 0 if SIZEOF_SIZE_T is not defined

azat updated this revision to Diff 524380.May 22 2023, 10:22 AM
azat marked an inline comment as done.

Rename feature to 32-bit-architecture

ldionne added inline comments.May 22 2023, 10:22 AM
libcxx/utils/libcxx/test/features.py
387

I would try using a runtime test that checks the result of sizeof(void*) == 4.

azat added inline comments.May 22 2023, 10:22 AM
libcxx/utils/libcxx/test/features.py
387

I'm not convinced we should rely on SIZEOF_SIZE_T being available at least we should test here it's defined. (Alternatively we do a runtime test, for an example see has-unix-headers.)

I guess a simple fallback to 0 will work, rebased.

azat added inline comments.May 22 2023, 10:25 AM
libcxx/utils/libcxx/test/features.py
387

@ldionne Ok, I could use this, but can you elaborate why int(compilerMacros(cfg).get('__SIZEOF_SIZE_T__', 0)) == 4 is not good, just to understand is there any difference? (since actually that test relies on the size_t size, but this feature flag is about 32-bit architecture so I'm fine both ways)

mgorny added inline comments.May 22 2023, 11:31 AM
libcxx/test/std/input.output/string.streams/stringstream.members/gcount.pass.cpp
9

Well, I don't want to be picky but if you want to use a long name anyway, than perhaps something like "32-bit-pointer" would be more precise. After all, I dare say n32 ABI is also using 32-bit pointers but it's works only on a 64-bit CPU architecture.

ldionne accepted this revision.May 22 2023, 6:29 PM
ldionne added inline comments.
libcxx/utils/libcxx/test/features.py
387

Using sizeof(void*) would work regardless of the compiler though.

This revision is now accepted and ready to land.May 22 2023, 6:29 PM

works for me, thanks.

azat updated this revision to Diff 524566.May 22 2023, 10:23 PM

Use sizeof(void*)

azat marked 2 inline comments as done.May 22 2023, 10:23 PM
azat added inline comments.
libcxx/utils/libcxx/test/features.py
387

I'm not convinced we should rely on SIZEOF_SIZE_T being available at least we should test here it's defined. (Alternatively we do a runtime test, for an example see has-unix-headers.)

@Mordante BTW it is defined in clang/lib/Frontend/InitPreprocessor.cpp, so it should always be defined.

philnik added inline comments.
libcxx/utils/libcxx/test/features.py
387

The tests aren't just for libc++. The test suite is designed to be as portable as possible, so __SIZEOF_SIZE_T__ might in fact not be defined. e.g. does MSVC define it? They actually use our test suite.

azat marked an inline comment as done.May 23 2023, 8:05 AM
azat added inline comments.
libcxx/utils/libcxx/test/features.py
387

The tests aren't just for libc++. The test suite is designed to be as portable as possible, so __SIZEOF_SIZE_T__ might in fact not be defined. e.g. does MSVC define it?

They don't - https://godbolt.org/z/d4d5xG1ET

They actually use our test suite.

Got it thanks!

Anyway, now sizeof(void*) is used.

azat marked an inline comment as done.May 23 2023, 8:05 AM

I'll land this on your behalf.

libcxx/utils/libcxx/test/features.py
387

That @philnik said was my reason too. Thanks for fixing it.