[Bug libstdc++/101203] Remove unnecessary empty check in std::function

2024-02-28 Thread lutztonineubert at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101203

Toni Neubert  changed:

   What|Removed |Added

 Status|UNCONFIRMED |RESOLVED
 Resolution|--- |WONTFIX

--- Comment #5 from Toni Neubert  ---
Improvement not possible for all environment.

[Bug ipa/106921] [11/12/13/14 Regression] -O1 and -fipa-icf -fpartial-inlining causes wrong code since r11-4987-g602c6cfc79ce4ae6

2023-11-21 Thread lutztonineubert at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106921

--- Comment #8 from Toni Neubert  ---
Hello,

I just wanted to ask what the state of this bug is? 

I think that incorrectly compiled code should be much more important than
anything else since any system can be affected without even knowing it.

I know that a lot of things happen here on a voluntary basis and I value that
very much.

What can we do to give such bugs a hire priority or help to solve such things?

[Bug c++/106921] [11/12/13 Regression] -O1 and -fipa-icf -fpartial-inlining causes wrong code since r11-4987-g602c6cfc79ce4ae6

2022-09-25 Thread lutztonineubert at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106921

--- Comment #3 from Toni Neubert  ---
Any update on this? Which compiler flag triggers this bug exactly? Or is it a
complex combination multiple?

[Bug c++/106921] New: [11/12.1] -O1 and -fipa-icf -fpartial-inlining causes wrong code

2022-09-13 Thread lutztonineubert at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106921

Bug ID: 106921
   Summary: [11/12.1] -O1 and -fipa-icf  -fpartial-inlining causes
wrong code
   Product: gcc
   Version: 11.3.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: lutztonineubert at gmail dot com
  Target Milestone: ---

Short summary:

The following code returns 1 if compiled with -O2 (which is wrong) and does
return 0 if compiled without optimization.

```
#include 
#include 
#include 

#define GCC_VERSION (__GNUC__ * 1 \
 + __GNUC_MINOR__ * 100 \
 + __GNUC_PATCHLEVEL__)
static_assert(GCC_VERSION == 110300);

template 
class bitset {
 private:
  using word_t = size_t;
  static constexpr size_t bits_per_word = sizeof(word_t) * 8;
  static constexpr size_t number_of_words = (Bits / bits_per_word) + (((Bits %
bits_per_word) == 0) ? 0 : 1);

 public:
  bool all_first(size_t n) const {
{
  if (n > Bits) {
#ifdef RETURN_INSTEAD_TERMINATE
return false;
#else
std::terminate();
#endif
  }
  size_t i = 0;
  for (; n > bits_per_word; n -= bits_per_word, i++) {
if (words_[i] != ~word_t{0}) {
  return false;
}
  }
  word_t last_word = words_[i];
  for (; n != 0; n--) {
if ((last_word & 1) != 1) {
  return false;
}
last_word >>= 1;
  }
  return true;
}
  }

  void fill() noexcept {
  for (auto& word : words_) {
  word = ~word_t{0};
  }
  }

 private:
  std::array words_{};
};

volatile int X = 0;

int main() {
  if (X == 1) {
bitset<123> bitset;
static_cast(bitset.all_first(123));
  } else {
bitset<256> bitset;
bitset.fill();
if (!bitset.all_first(255)) {
  return 1;
}
  }
  return 0;
}

```

See: https://gcc.godbolt.org/z/bEexjrKP4

This issue does not exist in GCC 10 or GCC > 12.1. I couldn't test if it does
work in GCC 11.3.1 (or the trunk of it).

Additional:
* I could also trigger the issue with -O1 -fipa-icf  -fpartial-inlining 
* If we do a return false instead of a std::terminate, no wrong code is
generated.

I am sorry, but I couldn't reduced the code any further - this already took so
much time to figure out it is a compiler bug.

[Bug c++/105060] New: [10/11] ICE with consteval function: internal compiler error: in cp_gimplify_expr, at cp/cp-gimplify.c:14879 with keep-inline-functions

2022-03-26 Thread lutztonineubert at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105060

Bug ID: 105060
   Summary: [10/11] ICE with consteval function: internal compiler
error: in cp_gimplify_expr, at cp/cp-gimplify.c:14879
with keep-inline-functions
   Product: gcc
   Version: 11.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: lutztonineubert at gmail dot com
  Target Milestone: ---

Compiled with g++ 10/11 and -fkeep-inline-functions -std=c++20. Doesn't seem to
happen with current trunk.

ERROR:

: In constructor 'consteval
basic_format_string::basic_format_string(const S&) [with S = char [1];
Args = {char, }]':
:19:5: internal compiler error: in gimplify_expr, at gimplify.c:14879
   19 | if (!check()) {
  | ^~
0x1786229 internal_error(char const*, ...)
???:0
0x678608 fancy_abort(char const*, int, char const*)
???:0
0xab0f92 gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*),
int)
???:0
0xab1068 gimplify_stmt(tree_node**, gimple**)
???:0
0xaaebb2 gimplify_expr(tree_node**, gimple**, gimple**, bool (*)(tree_node*),
int)
???:0
0xab1068 gimplify_stmt(tree_node**, gimple**)
???:0
0xab212b gimplify_body(tree_node*, bool)
???:0
0xab259f gimplify_function_tree(tree_node*)
???:0
0x943cf7 cgraph_node::analyze()
???:0
0x94707d symbol_table::finalize_compilation_unit()
???:0

CODE:

template 
struct type_identity {
  using type = T;
};

template 
using type_identity_t = typename type_identity::type;

constexpr int check() {
  return {};
}

template 
class basic_format_string {
 public:
  template 
  consteval basic_format_string(const S& s) {
if (!check()) {
}
  }
};

template 
using format_string = basic_format_string...>;

template 
void test(format_string format_str, const Args&... args) {}

enum { Blue };

void g() {
  test("", Blue);
}



See: https://gcc.godbolt.org/z/M7v96YPn1

[Bug libstdc++/101203] Remove unnecessary empty check in std::function

2021-06-27 Thread lutztonineubert at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101203

--- Comment #3 from Toni Neubert  ---
Thank you Jonathan for your fast answer.
To sad but the shared library issue seems valid.

Can shared libraries exist is a freestanding environment (like a bare-metal
microcontroller running without OS)? So there could maybe an optimization for
some targets?

[Bug libstdc++/101203] New: Remove unnecessary empty check in std::function

2021-06-24 Thread lutztonineubert at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101203

Bug ID: 101203
   Summary: Remove unnecessary empty check in std::function
   Product: gcc
   Version: unknown
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: libstdc++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: lutztonineubert at gmail dot com
  Target Milestone: ---

Hello,

this empty() check in std_function.h:

https://github.com/gcc-mirror/gcc/blob/master/libstdc++-v3/include/bits/std_function.h#L558

  _Res
  operator()(_ArgTypes... __args) const
  {
if (_M_empty())
  __throw_bad_function_call();
return _M_invoker(_M_functor, std::forward<_ArgTypes>(__args)...);
  }

can, as I assume, be removed to gain better performance.

An empty, default constructed std::function could be initialized with
__throw_bad_function_call() instead with nullptr/zeros.

If std::function::operator()(...) gets called, still
__throw_bad_function_call() would get called as before.

The implementation of `explicit operator bool()` or better `_M_empty()` would
then check if the function is initialized with the address of
__throw_bad_function_call.

This would be a similar technic as used in std::any:
https://github.com/gcc-mirror/gcc/blob/master/libstdc++-v3/include/experimental/any#L436

[Bug c++/97237] [10/11 Regression] static_assert does not accept fpermissive code

2020-11-04 Thread lutztonineubert at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97237

Toni Neubert  changed:

   What|Removed |Added

 Status|NEW |RESOLVED
 Resolution|--- |WONTFIX

--- Comment #5 from Toni Neubert  ---
Closed this in favor of other bugs.

This isn't necessary at all. Sorry for your time.

[Bug c++/97610] New: [10/11] template argument deduction fails for function with defaulted lambda as non-type-template parameter

2020-10-27 Thread lutztonineubert at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97610

Bug ID: 97610
   Summary: [10/11] template argument deduction fails for function
with defaulted lambda as non-type-template parameter
   Product: gcc
   Version: 11.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: lutztonineubert at gmail dot com
  Target Milestone: ---

The following code (with C++20 enabled):

template
constexpr auto nested() {
return 1;
}

template
constexpr void test() {
static_assert(nested());
}

--

Fails with:

: In function 'constexpr void test()':
:8:30: error: no matching function for call to 'nested()'
8 | static_assert(nested());
  |  ^
:2:16: note: candidate: 'template > constexpr auto
nested()'
2 | constexpr auto nested() {
  |^~
:2:16: note:   template argument deduction/substitution failed:

--

* same error happens if nested() has template as
this template parameters
* if the template non-type parameter of nested() is defaulted to 1, it compiles
* if test() is not a template function, it compiles
* if static_assert(nested<[]{}>()); is used, it compiles

[Bug c++/97237] [10/11 Regression] static_assert does not accept fpermissive code

2020-10-24 Thread lutztonineubert at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97237

--- Comment #4 from Toni Neubert  ---
This code seems to fail for the same reason:

constexpr int get() {
[[maybe_unused]] auto i = 1 << 32;
return 0;
}

template
constexpr int test() {
return a;
}

constexpr int t1 = get();
constexpr int t2 = test();

[Bug c++/97237] New: [10/11 Regression] static_assert does not accept fpermissive code

2020-09-29 Thread lutztonineubert at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97237

Bug ID: 97237
   Summary: [10/11 Regression] static_assert does not accept
fpermissive code
   Product: gcc
   Version: 11.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: lutztonineubert at gmail dot com
  Target Milestone: ---

The following valid code:

  constexpr bool test() {
  auto i = 1 << 132;
  return true;
  }

  static_assert(test());

Build with GCC -fpermissive does compile in GCC 9 but not in 10/11:

> non-constant condition for static assertion

See: https://gcc.godbolt.org/z/r85zvP

But this code is valid in all versions:

  constexpr bool test() {
  auto i = 1 << 132;
  return true;
  }

  constexpr auto t = test();

  static_assert(t);