diff options
author | Andrew Pinski <quic_apinski@quicinc.com> | 2024-10-28 22:05:08 -0700 |
---|---|---|
committer | Andrew Pinski <quic_apinski@quicinc.com> | 2024-10-29 08:49:41 -0700 |
commit | 17f6add3aba96681673b78862116a85d619cd806 (patch) | |
tree | f2712575aaa06dbe60cee8499634aed5dea59fdc /gcc | |
parent | b22d9c8f8216d15773dee4f9677c6b26aff507fd (diff) | |
download | gcc-17f6add3aba96681673b78862116a85d619cd806.zip gcc-17f6add3aba96681673b78862116a85d619cd806.tar.gz gcc-17f6add3aba96681673b78862116a85d619cd806.tar.bz2 |
testcase: Add testcase for tree-optimization/117341
Even though PR 117341 was a duplicate of PR 116768, another
testcase this time C++ does not hurt to have.
The testcase is a self-contained and does not use directly libstdc++
except for operator new (it does not even call delete).
Tested on x86_64-linux-gnu with it working.
PR tree-optimization/117341
gcc/testsuite/ChangeLog:
* g++.dg/torture/pr117341-1.C: New test.
Signed-off-by: Andrew Pinski <quic_apinski@quicinc.com>
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/testsuite/g++.dg/torture/pr117341-1.C | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/gcc/testsuite/g++.dg/torture/pr117341-1.C b/gcc/testsuite/g++.dg/torture/pr117341-1.C new file mode 100644 index 0000000..b13d250 --- /dev/null +++ b/gcc/testsuite/g++.dg/torture/pr117341-1.C @@ -0,0 +1,54 @@ +void swap(long &a, long &b) +{ + long t = a; + a = b; + b = t; +} + +struct Array { + long arr[1]; + Array() : arr() {} + /* Operators */ + long& operator[](int index) { return arr[index]; } + const long& operator[](int index) const { return arr[index]; } + /* Operations */ + void swap(Array& array) { + for (int i = 0; i < 1; ++i) + ::swap(arr[i], array[i]); + } +}; + +class Vector : public Array {}; + +struct v +{ + Vector *e; + v() : e (new Vector[4]){} + Vector& operator[](int index) { return e[index]; } + const Vector& operator[](int index) const { return e[index]; } +}; +static inline Vector func(const Vector& y) +{ + return y; +} + +volatile int a; + +int main() { + v solution; + solution[0][0] = 1; + int t = a; + for (int i = 0; i < 3; ++i) { + const Vector& v = solution[i]; + Vector sum; + const long delta = func(v)[0] & t; + sum[0] = v[0] + delta; + solution[i + 1].swap(sum); + } + for(int i = 0; i < 4; i++) + { + if (solution[i][0] != 1) + __builtin_abort(); + } + return 0; +} |