[Bug c++/97151] New: GCC fails to optimize away uselessly allocated arrays (C++)

2020-09-21 Thread marat at slonopotamus dot org
Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: marat at slonopotamus dot org Target Milestone: --- A test program: int main() { int *a = new int[10](); delete[] a; return 0; } Tested against: gcc 10.2.0 and gcc trunk as

[Bug c++/97151] GCC fails to optimize away uselessly allocated arrays (C++)

2020-09-21 Thread marat at slonopotamus dot org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97151 --- Comment #1 from Marat Radchenko --- Another program that exhibits the same behavior: int main() { int *a = new int[10]; a[0] = 0; delete[] a; return 0; }

[Bug c++/97151] GCC fails to optimize away uselessly allocated arrays (C++)

2020-09-22 Thread marat at slonopotamus dot org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97151 --- Comment #4 from Marat Radchenko --- (In reply to Martin Liška from comment #3) > It's caused by what was mentioned as 2) which transforms to: > > _6 = operator new [] (40); > __builtin_memset (_6, 0, 40); > operator delete [] (_6); >

[Bug c++/108626] New: GCC doesn't combine string literals for const char*const and const char b[]

2023-02-01 Thread marat at slonopotamus dot org via Gcc-bugs
erity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: marat at slonopotamus dot org Target Milestone: --- Given the following code #include static const char* const a = "bla"; static const char b[] = &

[Bug c++/108626] GCC doesn't deduplicate string literals for const char*const and const char[]

2023-02-01 Thread marat at slonopotamus dot org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108626 --- Comment #2 from Marat Radchenko --- Thanks for the pointer to -fmerge-all-constants, that helped me to google out why such transformation is invalid: https://stackoverflow.com/a/70328102 Should I close this issue as INVALID (and probably op

[Bug c++/108626] GCC doesn't deduplicate string literals for const char*const and const char[]

2023-02-02 Thread marat at slonopotamus dot org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108626 --- Comment #5 from Marat Radchenko --- So, does "String literals, and compound literals with const-qualified types, need not designate distinct objects." apply here or not? If not, how does the case where it applies look like? https://en.cppre

[Bug c++/108626] GCC doesn't deduplicate string literals for const char*const and const char[]

2023-02-02 Thread marat at slonopotamus dot org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108626 --- Comment #7 from Marat Radchenko --- While playing with it more, I found that clang behaves in a very strange way. While they do combine `const char* const` + `const char[]`, the DO NOT combine two `const char[]` together. I don't have any ex

[Bug c++/108626] GCC doesn't deduplicate string literals for const char*const and const char[]

2023-02-02 Thread marat at slonopotamus dot org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108626 --- Comment #8 from Marat Radchenko --- Also, quote from C17 standard: Like string literals, const-qualified compound literals can be placed into read-only memory and *can even be shared*. (6.5.2.5 p 13).