aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
Diffstat (limited to 'gcc')
-rw-r--r--gcc/gimple-range-op.cc27
-rw-r--r--gcc/testsuite/gcc.dg/Wuse-after-free-pr109170.c15
-rw-r--r--gcc/testsuite/gcc.dg/predict-20.c3
-rw-r--r--gcc/testsuite/gcc.dg/tree-ssa/ssa-lim-21.c7
4 files changed, 48 insertions, 4 deletions
diff --git a/gcc/gimple-range-op.cc b/gcc/gimple-range-op.cc
index a5d6253..c7c546c 100644
--- a/gcc/gimple-range-op.cc
+++ b/gcc/gimple-range-op.cc
@@ -309,6 +309,26 @@ public:
}
} op_cfn_constant_p;
+// Implement range operator for integral/pointer functions returning
+// the first argument.
+class cfn_pass_through_arg1 : public range_operator
+{
+public:
+ using range_operator::fold_range;
+ virtual bool fold_range (irange &r, tree, const irange &lh,
+ const irange &, relation_trio) const
+ {
+ r = lh;
+ return true;
+ }
+ virtual bool op1_range (irange &r, tree, const irange &lhs,
+ const irange &, relation_trio) const
+ {
+ r = lhs;
+ return true;
+ }
+} op_cfn_pass_through_arg1;
+
// Implement range operator for CFN_BUILT_IN_SIGNBIT.
class cfn_signbit : public range_operator_float
{
@@ -966,6 +986,13 @@ gimple_range_op_handler::maybe_builtin_call ()
m_int = &op_cfn_parity;
break;
+ case CFN_BUILT_IN_EXPECT:
+ case CFN_BUILT_IN_EXPECT_WITH_PROBABILITY:
+ m_valid = true;
+ m_op1 = gimple_call_arg (call, 0);
+ m_int = &op_cfn_pass_through_arg1;
+ break;
+
default:
break;
}
diff --git a/gcc/testsuite/gcc.dg/Wuse-after-free-pr109170.c b/gcc/testsuite/gcc.dg/Wuse-after-free-pr109170.c
new file mode 100644
index 0000000..14f1350
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/Wuse-after-free-pr109170.c
@@ -0,0 +1,15 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -Wuse-after-free=2" } */
+
+unsigned long bufmax = 0;
+unsigned long __open_catalog_bufmax;
+void *realloc(void *, __SIZE_TYPE__);
+void free(void *);
+
+void __open_catalog(char *buf)
+{
+ char *old_buf = buf;
+ buf = realloc (buf, bufmax);
+ if (__builtin_expect ((buf == ((void *)0)), 0))
+ free (old_buf); /* { dg-bogus "used after" } */
+}
diff --git a/gcc/testsuite/gcc.dg/predict-20.c b/gcc/testsuite/gcc.dg/predict-20.c
index 31d0183..7bb0d41 100644
--- a/gcc/testsuite/gcc.dg/predict-20.c
+++ b/gcc/testsuite/gcc.dg/predict-20.c
@@ -16,8 +16,9 @@ c ()
break;
}
int d = b < 0;
+ /* We fail to apply __builtin_expect heuristics here. Se PR109210. */
if (__builtin_expect (d, 0))
asm("");
}
-/* { dg-final { scan-tree-dump-times "__builtin_expect heuristics of edge" 3 "profile_estimate"} } */
+/* { dg-final { scan-tree-dump-times "__builtin_expect heuristics of edge" 2 "profile_estimate" } } */
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/ssa-lim-21.c b/gcc/testsuite/gcc.dg/tree-ssa/ssa-lim-21.c
index ffe6f8f..fe29e84 100644
--- a/gcc/testsuite/gcc.dg/tree-ssa/ssa-lim-21.c
+++ b/gcc/testsuite/gcc.dg/tree-ssa/ssa-lim-21.c
@@ -17,7 +17,7 @@ void
func (int m, int n, int k, struct obj *a)
{
struct obj *q = a;
- for (int j = 0; j < m; j++)
+ for (int j = 0; j < n; j++)
if (__builtin_expect (m, 0))
for (int i = 0; i < m; i++)
{
@@ -31,5 +31,6 @@ func (int m, int n, int k, struct obj *a)
}
}
-/* { dg-final { scan-tree-dump-not "Executing store motion of" "lim2" } } */
-
+/* { dg-final { scan-tree-dump "Executing store motion of count from loop 2" "lim2" } } */
+/* { dg-final { scan-tree-dump "Executing store motion of \[^ \]*data1 from loop 2" "lim2" } } */
+/* { dg-final { scan-tree-dump-times "Executing store motion of" 2 "lim2" } } */