[Bug c/78807] New: Loop optimization trigger bus error

2016-12-14 Thread m.gcc.gnu.org at alias dot viem.se
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78807

Bug ID: 78807
   Summary: Loop optimization trigger bus error
   Product: gcc
   Version: 5.3.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c
  Assignee: unassigned at gcc dot gnu.org
  Reporter: m.gcc.gnu.org at alias dot viem.se
  Target Milestone: ---

Created attachment 40331
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=40331&action=edit
Test program

With GCC 5.3.0 on Solaris 11 the below program ends due to bus error on sparc.
Turning of tree-loop optimizations with either of the below avoids bus error:
-fvect-cost-model=cheap
-fno-tree-loop-distribute-patterns
-fno-tree-loop-vectorize

=== bug.c ===
/*
$ gcc -m64 -O3 -fPIC -o bug bug.c

$ ./bug
Bus Error (core dumped)
*/

inline void g(unsigned size, unsigned x[], unsigned y[])
{
  unsigned i;
  for (i = 0; i < size; i++)
  {
x[i] |= y[i];
  }
  for (i = 0; i < size; i++)
  {
y[i] = 0;
  }
}

struct A
{
  long a; // Make struct A 8 byte aligned
  int b;  // Make x[] not 8 byte aligned
  unsigned x[6];
  unsigned y[6];
};

void f(struct A* a)
{
  g(6, a->x, a->y);
}

int
main()
{
  struct A a;
  f(&a);
  return 0;
}

=== END of bug.c ===

[Bug c/78807] Loop optimization trigger bus error

2016-12-14 Thread m.gcc.gnu.org at alias dot viem.se
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78807

--- Comment #1 from Mauritz Sundell  ---
Created attachment 40332
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=40332&action=edit
Stack trace and program disassembly

Crash is in clrx operation accessing long (8 byte) word on 4 byte address
alignment but not 8 byte aligned.

[Bug target/78807] Loop optimization trigger bus error

2016-12-21 Thread m.gcc.gnu.org at alias dot viem.se
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=78807

--- Comment #3 from Mauritz Sundell  ---
I did not have access to a Solaris/sparc machine with GCC 6.
But on Linux/sparc test program do not crash compiled with GCC 6.2.0.

$ uname -a
Linux xxx 4.1.12-80.el6uek.sparc64 #1 SMP Wed Nov 30 03:09:10 PST 2016 sparc64
sparc64 sparc64 GNU/Linux 

$ bin/gcc-6.2.0/bin/gcc -m64 -O3 -fPIC -o bug78807 bug78807.c
$ ./bug78807
$

[Bug c++/117259] warning: 'j.6' may be used uninitialized [-Wmaybe-unitialized] with -fsanitize=undefined

2024-10-22 Thread m.gcc.gnu.org at alias dot viem.se via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117259

--- Comment #1 from Mauritz Sundell  ---
(In reply to Mauritz Sundell from comment #0)

> Accessing dynamically initialized array of global member function pointer
should be:
Accessing dynamically initialized global array of member function pointers

[Bug c++/117259] New: warning: 'j.6' may be used uninitialized [-Wmaybe-unitialized] with -fsanitize=undefined

2024-10-22 Thread m.gcc.gnu.org at alias dot viem.se via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=117259

Bug ID: 117259
   Summary: warning: 'j.6' may be used uninitialized
[-Wmaybe-unitialized] with -fsanitize=undefined
   Product: gcc
   Version: 11.1.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: m.gcc.gnu.org at alias dot viem.se
  Target Milestone: ---

/*
Accessing dynamically initialized array of global member function pointer using
a non const index variable gives false and ill-formed warning if compiling with
-fsanitize=undefined (bounds) and -O1.

Warning disappears if either:
1. changing to static initialization by removing user defined B constructor
2. using const index variable (with same value)
3. using -O0
4. using no -fsanitize or something else than -fsanitize=undefined,
   -fsanitize=bounds, or, -fsanitize=bounds-strict
5. using gcc 10 or older

$ gcc -fsanitize=undefined -Wmaybe-uninitialized -O1 -c bug.cpp
bug.cpp: In member function 'void A::f()':
bug.cpp:48:15: warning: 'j.6' may be used uninitialized [-Wmaybe-uninitialized]
   48 |   (this->*bs[j].g)(); // warning: 'j.6' may be used uninitialized
  |   ^
bug.cpp:48:15: note: 'j.6' was declared here
   48 |   (this->*bs[j].g)(); // warning: 'j.6' may be used uninitialized
  |   ^

gcc 11.1 up to gcc 14.2 show warning.
gcc 12.1 up to gcc 14.2 also show note.

 */

struct A {
  struct B {
void (A::*g) ();

B(void (A::*func)()) : g(func) {};
  };

  static const B bs[1];

  void f();
  void h(){}
};

const A::B A::bs[1] = {{&A::h}};

void A::f() {
  (this->*bs[0].g)(); // no warning
  const unsigned i = 0;
  (this->*bs[i].g)(); // no warning
  unsigned j = 0;
  (this->*bs[j].g)(); // warning: 'j.6' may be used uninitialized
}

[Bug c++/116954] New: -Wsuggest-attribute=format false positive for function template

2024-10-03 Thread m.gcc.gnu.org at alias dot viem.se via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116954

Bug ID: 116954
   Summary: -Wsuggest-attribute=format false positive for function
template
   Product: gcc
   Version: 13.1.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: m.gcc.gnu.org at alias dot viem.se
  Target Milestone: ---

When defining a function template that calls a standard printf function there
will a -Wsuggest-attribute=format warning when instantiated.

One can not att attribute to function definition template.

And adding a function declaration template with attribute does not help.


/*
 Demonstrate -Wsuggest-attribute=format false positive for function template.

 Verified also for x86-64.gcc 13.1, 13.2, 13.3, 14.1, 14.2 on godbolt.org
(2024-10-03).

 > g++ --version
 g++ (Gentoo 13.3.1_p20240614 p17) 13.3.1 20240614
 ...
 > g++ -Wmissing-format-attribute temp-format.cpp
 : In instantiation of 'int fn(char (&)[N], const char*, ...) [with
long unsigned int N = 20]':
 :21:12:   required from here
 :13:27: warning: function 'int fn(char (&)[N], const char*, ...) [with
long unsigned int N = 20]' might be a candidate for 'gnu_printf' format
attribute [-Wsuggest-attribute=format]
13 |   int ret = std::vsnprintf(buf, N, fmt, ap);
  | ~~^

*/
#include
#include

template
int fn(char (&buf)[N], const char fmt[], ...)
  __attribute__ ((__format__ (__printf__, 2, 3)));

template int fn(char (&buf)[N], const char fmt[], ...)
  // __attribute__ ((__format__ (__printf__, 2, 3))) // error: attributes are
not allowed on a function-definition
{
  va_list ap;
  va_start(ap, fmt);
  int ret = std::vsnprintf(buf, N, fmt, ap); // warning: function âint fn(char
(&)[N], const char*, ...) [with long unsigned int N = 20]â might be a candidate
for âgnu_printfâ format attribute [-Wsuggest-attribute=format]
  va_end(ap);
  return ret;
}

int main()
{
  char buf[20];
  return fn(buf, "%d", 42);
}