public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r13-7518] d: Don't generate code that throws exceptions when compiling with `-fno-exceptions'
@ 2023-07-01 15:50 Iain Buclaw
  0 siblings, 0 replies; only message in thread
From: Iain Buclaw @ 2023-07-01 15:50 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:6e7909191ada316a426739eab88139d63194e05a

commit r13-7518-g6e7909191ada316a426739eab88139d63194e05a
Author: Iain Buclaw <ibuclaw@gdcproject.org>
Date:   Sat Jul 1 17:01:30 2023 +0200

    d: Don't generate code that throws exceptions when compiling with `-fno-exceptions'
    
    The version flags for RTMI, RTTI, and exceptions was unconditionally
    predefined.  These are now only predefined if the feature flag is
    enabled.  It was noticed that there was no `-fexceptions' definition
    inside d/lang.opt, so the detection of the exceptions option flag was
    only partially working.  Once that was fixed, a few places in the
    front-end implementation were found to fall fowl of `nothrow' rules,
    these have been fixed upstream and backported here as well.
    
    Reviewed-on: https://github.com/dlang/dmd/pull/15357
                 https://github.com/dlang/dmd/pull/15360
    
            PR d/110471
    
    gcc/d/ChangeLog:
    
            * d-builtins.cc (d_init_versions): Predefine D_ModuleInfo,
            D_Exceptions, and D_TypeInfo only if feature is enabled.
            * lang.opt: Add -fexceptions.
    
    gcc/testsuite/ChangeLog:
    
            * gdc.dg/pr110471a.d: New test.
            * gdc.dg/pr110471b.d: New test.
            * gdc.dg/pr110471c.d: New test.
    
    (cherry picked from commit da108c75ad386b3f1f47abb2265296e4b61d578a)

Diff:
---
 gcc/d/d-builtins.cc              | 9 ++++++---
 gcc/d/dmd/root/array.d           | 2 +-
 gcc/d/dmd/semantic2.d            | 3 +--
 gcc/d/dmd/semantic3.d            | 2 +-
 gcc/d/lang.opt                   | 4 ++++
 gcc/testsuite/gdc.dg/pr110471a.d | 5 +++++
 gcc/testsuite/gdc.dg/pr110471b.d | 5 +++++
 gcc/testsuite/gdc.dg/pr110471c.d | 5 +++++
 8 files changed, 28 insertions(+), 7 deletions(-)

diff --git a/gcc/d/d-builtins.cc b/gcc/d/d-builtins.cc
index f40888019ce..60f76fc694c 100644
--- a/gcc/d/d-builtins.cc
+++ b/gcc/d/d-builtins.cc
@@ -500,9 +500,12 @@ d_init_versions (void)
     VersionCondition::addPredefinedGlobalIdent ("D_BetterC");
   else
     {
-      VersionCondition::addPredefinedGlobalIdent ("D_ModuleInfo");
-      VersionCondition::addPredefinedGlobalIdent ("D_Exceptions");
-      VersionCondition::addPredefinedGlobalIdent ("D_TypeInfo");
+      if (global.params.useModuleInfo)
+       VersionCondition::addPredefinedGlobalIdent ("D_ModuleInfo");
+      if (global.params.useExceptions)
+       VersionCondition::addPredefinedGlobalIdent ("D_Exceptions");
+      if (global.params.useTypeInfo)
+       VersionCondition::addPredefinedGlobalIdent ("D_TypeInfo");
     }
 
   if (optimize)
diff --git a/gcc/d/dmd/root/array.d b/gcc/d/dmd/root/array.d
index 541a12d9e1d..d1c61be7344 100644
--- a/gcc/d/dmd/root/array.d
+++ b/gcc/d/dmd/root/array.d
@@ -574,7 +574,7 @@ unittest
 private template arraySortWrapper(T, alias fn)
 {
     pragma(mangle, "arraySortWrapper_" ~ T.mangleof ~ "_" ~ fn.mangleof)
-    extern(C) int arraySortWrapper(scope const void* e1, scope const void* e2) nothrow
+    extern(C) int arraySortWrapper(scope const void* e1, scope const void* e2)
     {
         return fn(cast(const(T*))e1, cast(const(T*))e2);
     }
diff --git a/gcc/d/dmd/semantic2.d b/gcc/d/dmd/semantic2.d
index 440e4cbc8e7..ee268d95251 100644
--- a/gcc/d/dmd/semantic2.d
+++ b/gcc/d/dmd/semantic2.d
@@ -807,9 +807,8 @@ private void doGNUABITagSemantic(ref Expression e, ref Expression* lastTag)
     // but it's a concession to practicality.
     // Casts are unfortunately necessary as `implicitConvTo` is not
     // `const` (and nor is `StringExp`, by extension).
-    static int predicate(const scope Expression* e1, const scope Expression* e2) nothrow
+    static int predicate(const scope Expression* e1, const scope Expression* e2)
     {
-        scope(failure) assert(0, "An exception was thrown");
         return (cast(Expression*)e1).toStringExp().compare((cast(Expression*)e2).toStringExp());
     }
     ale.elements.sort!predicate;
diff --git a/gcc/d/dmd/semantic3.d b/gcc/d/dmd/semantic3.d
index 33a43187fa8..a912e768f0c 100644
--- a/gcc/d/dmd/semantic3.d
+++ b/gcc/d/dmd/semantic3.d
@@ -1420,7 +1420,7 @@ private extern(C++) final class Semantic3Visitor : Visitor
          * https://issues.dlang.org/show_bug.cgi?id=14246
          */
         AggregateDeclaration ad = ctor.isMemberDecl();
-        if (!ctor.fbody || !ad || !ad.fieldDtor || !global.params.dtorFields || global.params.betterC || ctor.type.toTypeFunction.isnothrow)
+        if (!ctor.fbody || !ad || !ad.fieldDtor || !global.params.dtorFields || !global.params.useExceptions || ctor.type.toTypeFunction.isnothrow)
             return visit(cast(FuncDeclaration)ctor);
 
         /* Generate:
diff --git a/gcc/d/lang.opt b/gcc/d/lang.opt
index 26ca92c4c17..98a95c1dc38 100644
--- a/gcc/d/lang.opt
+++ b/gcc/d/lang.opt
@@ -291,6 +291,10 @@ fdump-d-original
 D
 Display the frontend AST after parsing and semantic passes.
 
+fexceptions
+D
+; Documented in common.opt
+
 fextern-std=
 D Joined RejectNegative Enum(extern_stdcpp) Var(flag_extern_stdcpp)
 -fextern-std=<standard>	Set C++ name mangling compatibility with <standard>.
diff --git a/gcc/testsuite/gdc.dg/pr110471a.d b/gcc/testsuite/gdc.dg/pr110471a.d
new file mode 100644
index 00000000000..2182f3d5ab2
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/pr110471a.d
@@ -0,0 +1,5 @@
+// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110471
+// { dg-do compile }
+// { dg-options "-fno-exceptions" }
+version (D_Exceptions)
+    static assert(0);
diff --git a/gcc/testsuite/gdc.dg/pr110471b.d b/gcc/testsuite/gdc.dg/pr110471b.d
new file mode 100644
index 00000000000..32562c14f56
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/pr110471b.d
@@ -0,0 +1,5 @@
+// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110471
+// { dg-do compile }
+// { dg-options "-fno-moduleinfo" }
+version (D_ModuleInfo)
+    static assert(0);
diff --git a/gcc/testsuite/gdc.dg/pr110471c.d b/gcc/testsuite/gdc.dg/pr110471c.d
new file mode 100644
index 00000000000..6d13dbaa3fb
--- /dev/null
+++ b/gcc/testsuite/gdc.dg/pr110471c.d
@@ -0,0 +1,5 @@
+// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110471
+// { dg-do compile }
+// { dg-options "-fno-rtti" }
+version (D_TypeInfo)
+    static assert(0);

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2023-07-01 15:50 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-01 15:50 [gcc r13-7518] d: Don't generate code that throws exceptions when compiling with `-fno-exceptions' Iain Buclaw

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).