From a7c85ec3be036e87a6fd76e0d4cd0fba36dd1e07 Mon Sep 17 00:00:00 2001 From: "Richard (Rikki) Andrew Cattermole" Date: Thu, 7 Nov 2024 23:58:50 +1300 Subject: [PATCH] Fix bugzilla issue 24846 - atomicLoad does not work for class arguments with -preview=nosharedaccess --- compiler/src/dmd/expressionsem.d | 21 +++++++++++++++++++ compiler/src/dmd/frontend.h | 1 + compiler/src/dmd/id.d | 1 + ...es.d => atomic_loadstore_shared_classes.d} | 5 +++++ 4 files changed, 28 insertions(+) rename compiler/test/compilable/{atomic_store_2_shared_classes.d => atomic_loadstore_shared_classes.d} (60%) diff --git a/compiler/src/dmd/expressionsem.d b/compiler/src/dmd/expressionsem.d index 5cf0cbb4cb..07b1347938 100644 --- a/compiler/src/dmd/expressionsem.d +++ b/compiler/src/dmd/expressionsem.d @@ -15136,6 +15136,27 @@ bool checkSharedAccess(Expression e, Scope* sc, bool returnRef = false) { return false; } + else if (sc._module.ident == Id.atomic && sc._module.parent !is null) + { + // Allow core.internal.atomic, it is an compiler implementation for a given platform module. + // It is then exposed by other modules such as core.atomic and core.stdc.atomic. + // This is available as long as druntime is on the import path and the platform supports that operation. + + // https://issues.dlang.org/show_bug.cgi?id=24846 + + Package parent = sc._module.parent.isPackage(); + if (parent !is null) + { + // This can be easily converted over to apply to core.atomic and core.internal.atomic + if (parent.ident == Id.internal) + { + parent = parent.parent.isPackage(); + + if (parent !is null && parent.ident == Id.core && parent.parent is null) + return false; + } + } + } //printf("checkSharedAccess() `%s` returnRef: %d\n", e.toChars(), returnRef); diff --git a/compiler/src/dmd/frontend.h b/compiler/src/dmd/frontend.h index 845e4889e9..46b0efd8d1 100644 --- a/compiler/src/dmd/frontend.h +++ b/compiler/src/dmd/frontend.h @@ -8606,6 +8606,7 @@ struct Id final static Identifier* va_start; static Identifier* std; static Identifier* core; + static Identifier* internal; static Identifier* config; static Identifier* c_complex_float; static Identifier* c_complex_double; diff --git a/compiler/src/dmd/id.d b/compiler/src/dmd/id.d index f676361d95..f5d9340e86 100644 --- a/compiler/src/dmd/id.d +++ b/compiler/src/dmd/id.d @@ -389,6 +389,7 @@ immutable Msgtable[] msgtable = // Builtin functions { "std" }, { "core" }, + { "internal" }, { "config" }, { "c_complex_float" }, { "c_complex_double" }, diff --git a/compiler/test/compilable/atomic_store_2_shared_classes.d b/compiler/test/compilable/atomic_loadstore_shared_classes.d similarity index 60% rename from compiler/test/compilable/atomic_store_2_shared_classes.d rename to compiler/test/compilable/atomic_loadstore_shared_classes.d index 0d8cd74893..f719aa829f 100644 --- a/compiler/test/compilable/atomic_store_2_shared_classes.d +++ b/compiler/test/compilable/atomic_loadstore_shared_classes.d @@ -5,9 +5,14 @@ class Foo { } +shared Foo toLoad; + void oops() { auto f0 = new shared Foo; auto f1 = new shared Foo; atomicStore(f0, f1); + + // https://issues.dlang.org/show_bug.cgi?id=24846 + shared(Foo) f2 = atomicLoad(toLoad); }