aboutsummaryrefslogtreecommitdiff
path: root/libgomp
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2022-09-24 09:19:26 +0200
committerJakub Jelinek <jakub@redhat.com>2023-05-03 13:29:20 +0200
commit7cdefaee48af5d203560091bd37aad206df683b9 (patch)
tree47f7626bb20eb406f8c68d41ecbbb7055eebd387 /libgomp
parentf0ce91c8bb7311b5e98292ee3ae323a24bbe9c09 (diff)
downloadgcc-7cdefaee48af5d203560091bd37aad206df683b9.zip
gcc-7cdefaee48af5d203560091bd37aad206df683b9.tar.gz
gcc-7cdefaee48af5d203560091bd37aad206df683b9.tar.bz2
openmp, c: Tighten up c_tree_equal [PR106981]
This patch changes c_tree_equal to work more like cp_tree_equal, be more strict in what it accepts. The ICE on the first testcase was due to INTEGER_CST wi::wide (t1) == wi::wide (t2) comparison which ICEs if the two constants have different precision, but as the second testcase shows, being too lenient in it can also lead to miscompilation of valid OpenMP programs where we think certain expression is the same even when it isn't and can be guaranteed at runtime to represent different memory location. So, the patch looks through only NON_LVALUE_EXPRs and for constants as well as casts requires that the types match before actually comparing the constant values or recursing on the cast operands. 2022-09-24 Jakub Jelinek <jakub@redhat.com> PR c/106981 gcc/c/ * c-typeck.c (c_tree_equal): Only strip NON_LVALUE_EXPRs at the start. For CONSTANT_CLASS_P or CASE_CONVERT: return false if t1 and t2 have different types. gcc/testsuite/ * c-c++-common/gomp/pr106981.c: New test. libgomp/ * testsuite/libgomp.c-c++-common/pr106981.c: New test. (cherry picked from commit 3c5bccb608c665ac3f62adb1817c42c845812428)
Diffstat (limited to 'libgomp')
-rw-r--r--libgomp/testsuite/libgomp.c-c++-common/pr106981.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/libgomp/testsuite/libgomp.c-c++-common/pr106981.c b/libgomp/testsuite/libgomp.c-c++-common/pr106981.c
new file mode 100644
index 0000000..ed48d27
--- /dev/null
+++ b/libgomp/testsuite/libgomp.c-c++-common/pr106981.c
@@ -0,0 +1,19 @@
+/* PR c/106981 */
+
+int
+main ()
+{
+ int a[0x101];
+ unsigned int b = 0x100;
+ if ((unsigned char) b || (unsigned short) b != 0x100)
+ return 0;
+ a[0] = 0;
+ a[0x100] = 42;
+ #pragma omp atomic update
+ a[(unsigned char) b] = a[(unsigned short) b] + a[(unsigned char) b];
+ #pragma omp atomic update
+ a[(unsigned char) b] = a[(unsigned char) b] + a[(unsigned short) b];
+ if (a[0] != 84 || a[0x100] != 42)
+ __builtin_abort ();
+ return 0;
+}