From: Jakub Jelinek Date: Wed, 27 Apr 2022 16:47:10 +0000 (+0200) Subject: testsuite: Add testcase for dangling pointer equality bogus warning [PR104492] X-Git-Tag: basepoints/gcc-13~24 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=948e8e401023f6c3153f6d0c449bc5c2899ee7b7;p=thirdparty%2Fgcc.git testsuite: Add testcase for dangling pointer equality bogus warning [PR104492] On Wed, Apr 27, 2022 at 12:02:33PM +0200, Richard Biener wrote: > I did that but the reduction result did not resemble the same failure > mode. I've failed to manually construct a testcase as well. Possibly > a testcase using libstdc++ but less Qt internals might be possible. Here is a testcase that I've managed to reduce, FAILs with: FAIL: g++.dg/warn/pr104492.C -std=gnu++14 (test for bogus messages, line 111) FAIL: g++.dg/warn/pr104492.C -std=gnu++17 (test for bogus messages, line 111) FAIL: g++.dg/warn/pr104492.C -std=gnu++20 (test for bogus messages, line 111) on both x86_64-linux and i686-linux without your commit and passes with it. 2022-04-27 Jakub Jelinek PR middle-end/104492 * g++.dg/warn/pr104492.C: New test. --- diff --git a/gcc/testsuite/g++.dg/warn/pr104492.C b/gcc/testsuite/g++.dg/warn/pr104492.C new file mode 100644 index 000000000000..229414d6dd39 --- /dev/null +++ b/gcc/testsuite/g++.dg/warn/pr104492.C @@ -0,0 +1,115 @@ +// PR middle-end/104492 +// { dg-do compile { target c++14 } } +// { dg-options "-O3 -Wall" } + +namespace std { +typedef decltype (sizeof 0) size_t; +template struct integral_constant { + static constexpr _Tp value = __v; +}; +template +struct is_same : integral_constant {}; +template struct enable_if; +template _Tp forward; +} +class QString; +struct random_access_iterator_tag {}; +template struct iterator_traits { + typedef random_access_iterator_tag iterator_category; +}; +template +typename iterator_traits<_Iter>::iterator_category __iterator_category(_Iter); +namespace __gnu_cxx { +namespace __ops { +template struct _Iter_equals_val { + template bool operator()(_Iterator); +}; +template _Iter_equals_val<_Value> __iter_equals_val(_Value); +} +} +namespace std { +template +_RandomAccessIterator __find_if(_RandomAccessIterator __first, + _RandomAccessIterator __last, _Predicate __pred, + random_access_iterator_tag) { + if (__pred(__first)) + return __first; + return __last; +} +template +_Iterator __find_if(_Iterator __first, _Iterator __last, _Predicate __pred) { + return __find_if(__first, __last, __pred, __iterator_category(__first)); +} +template _Tp *begin(_Tp (&__arr)[_Nm]) { + return __arr; +} +template _Tp *end(_Tp (&__arr)[_Nm]) { + return __arr + _Nm; +} +template +_InputIterator find(_InputIterator __first, _InputIterator __last, _Tp __val) { + return __find_if(__first, __last, __gnu_cxx::__ops::__iter_equals_val(__val)); +} +} +struct QStringView { + template + using if_compatible_qstring_like = std::enable_if::value, bool>; + template QStringView(String); +}; +template struct QStringTokenizerBase { + class sentinel {}; + struct iterator { + Haystack operator*(); + iterator operator++(int); + bool operator!=(sentinel); + }; + iterator begin(); + template ::value> sentinel end(); +}; +namespace QtPrivate { +namespace Tok { +template +using TokenizerBase = QStringTokenizerBase; +} +} +template +struct QStringTokenizer + : public QtPrivate::Tok::TokenizerBase { + QStringTokenizer(Haystack, Needle); +}; +namespace QtPrivate { +namespace Tok { +template +using TokenizerResult = QStringTokenizer; +} +} +template +auto qTokenize(Haystack, Needle) + -> decltype(QtPrivate::Tok::TokenizerResult{ + std::forward, std::forward}); +struct QLatin1String { + QLatin1String(const char *) {} +}; +class QString {}; +class QLibrary { + bool isLibrary(const QString &); +}; + +bool QLibrary::isLibrary(const QString &fileName) +{ + QString completeSuffix = fileName; + auto isValidSuffix = [](QStringView s) { + const QLatin1String candidates[] = { + QLatin1String("so"), + }; + return std::find(std::begin(candidates), std::end(candidates), s) != std::end(candidates); + }; + auto suffixes = qTokenize(completeSuffix, u'.'); + auto it = suffixes.begin(); + const auto end = suffixes.end(); + while (it != end) { + if (isValidSuffix(*it++)) // { dg-bogus "dangling pointer to .candidates. may be used" } + return true; + } + return false; +}