@@ -1007,6 +1007,7 @@ expand_volatile_load (tree callexp)
tree type = build_qualified_type (TREE_TYPE (ptrtype), TYPE_QUAL_VOLATILE);
tree result = indirect_ref (type, ptr);
TREE_THIS_VOLATILE (result) = 1;
+ TREE_SIDE_EFFECTS (result) = 1;
return result;
}
@@ -1034,6 +1035,7 @@ expand_volatile_store (tree callexp)
tree type = build_qualified_type (TREE_TYPE (ptrtype), TYPE_QUAL_VOLATILE);
tree result = indirect_ref (type, ptr);
TREE_THIS_VOLATILE (result) = 1;
+ TREE_SIDE_EFFECTS (result) = 1;
/* (*(volatile T *) ptr) = value; */
tree value = CALL_EXPR_ARG (callexp, 1);
new file mode 100644
@@ -0,0 +1,12 @@
+// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110516
+// { dg-do compile }
+// { dg-options "-fno-moduleinfo -fdump-tree-optimized" }
+void fn110516(ubyte* ptr)
+{
+ import core.volatile : volatileLoad;
+ volatileLoad(ptr);
+ volatileLoad(ptr);
+ volatileLoad(ptr);
+ volatileLoad(ptr);
+}
+// { dg-final { scan-tree-dump-times " ={v} " 4 "optimized" } }
new file mode 100644
@@ -0,0 +1,12 @@
+// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110516
+// { dg-do compile }
+// { dg-options "-fno-moduleinfo -fdump-tree-optimized" }
+void fn110516(ubyte* ptr)
+{
+ import core.volatile : volatileStore;
+ volatileStore(ptr, 0);
+ volatileStore(ptr, 0);
+ volatileStore(ptr, 0);
+ volatileStore(ptr, 0);
+}
+// { dg-final { scan-tree-dump-times " ={v} " 4 "optimized" } }