[libcxx-commits] [PATCH] D146294: [libcxx] Fix crash in std::stringstream with payload >= INT_MAX
Azat Khuzhin via Phabricator via libcxx-commits
libcxx-commits at lists.llvm.org
Sun May 7 12:22:46 PDT 2023
azat marked 3 inline comments as done.
azat added inline comments.
================
Comment at: libcxx/test/std/input.output/string.streams/stringstream.members/gcount.pass.cpp:19
+int main(int, char**) {
+#if __SIZE_WIDTH__ == 64
+ std::stringstream ss;
----------------
Mordante wrote:
> azat wrote:
> > Mordante wrote:
> > > Why is this needed? Can't you just compare that an int is 32-bit?
> > >
> > > I ideally I would rather make the test unsupported on platform that are not used. Otherwise this test gives a false sense of doing something.
> > >
> > > Maybe we should add a feature in `libcxx/utils/libcxx/test/features.py` Something like `can-test-gcount` Then we only enable it on 64-bit platforms where int is a 32-bit value. WDYT?
> > Yeah, I did not like it either, but that was simpler.
> >
> > I don't think that introducing special flag only for one test will be a good choice however.
> > What do you think about something like this instead:
> >
> > ```
> > // UNSUPPORTED: target={{.*}}32{{.*}}
> > ```
> >
> > But this will not work for some arches (not sure that they are added to CI), i.e. `x86`.
> >
> > So instead I could add a separate parameter `libcxx/utils/libcxx/test/params.py` something like `size_t_bytes`, although I'm not sure is there an easy way to extract this in python, maybe you have an idea?
> The tests are also used outside libc++ so even when we don't test x86, other might test that platform.
>
> I don't mind adding a feature for a few test test. We already have precedence for them. For example
> 1 user host-has-gdb-with-python
> 2 users for glibc-old-ru_RU-decimal-point
> 2 users for win32-broken-printf-g-precision
>
> I'm not well enough versed in Python to know whether that's even possible. Even if it is I'm not sure whether Python uses the same widths as C++. I can imagine Python always using 64-bit integrals.
>
> I'm not against your suggestion as long as we can do it reliable.
I've found more or less simple, added two new parameters - `libcxx-32-bits` and `libcxx-64-bits`, and used `UNSUPPORTED: libcxx-32-bits` in the test, and `llvm-lit` successfully skips it if `libcxx-32-bits` is set. What do you think about this?
================
Comment at: libcxx/test/std/input.output/string.streams/stringstream.members/gcount.pass.cpp:23
+
+ for (size_t i = 0; i < (2ULL << 30) - payload.size(); i += payload.size()) {
+ assert(ss.tellp() != -1);
----------------
Mordante wrote:
> Why this loop? Wouldn't it be easier to:
> - create a string with `INT_MAX - 1` elements
> - write the string and validate (INT_MAX - 1)
> - write 1 character and validate (INT_MAX)
> - write 1 character and validate (INT_MAX + 1)
Nice catch, I've simplified it
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D146294/new/
https://reviews.llvm.org/D146294
More information about the libcxx-commits
mailing list