[pkg-d-commits] [ldc] 177/211: Infer return type of functions for vtbl initializer

Matthias Klumpp mak at moszumanska.debian.org
Sun Apr 23 22:36:21 UTC 2017


This is an automated email from the git hooks/post-receive script.

mak pushed a commit to annotated tag v1.1.0
in repository ldc.

commit 8a161260b3e3cbc79cc1bd2a312227137478a443
Author: Martin <noone at nowhere.com>
Date:   Wed Nov 30 00:02:04 2016 +0100

    Infer return type of functions for vtbl initializer
    
    Fixes issue #1906.
    
    Also get rid of another bug wrt. potentially failing `DtoFunctionType()`
    for abstract functions.
---
 ir/irclass.cpp                    | 31 +++++++++++++++++++++----------
 tests/compilable/gh1906.d         |  5 +++++
 tests/compilable/inputs/gh1906b.d |  5 +++++
 3 files changed, 31 insertions(+), 10 deletions(-)

diff --git a/ir/irclass.cpp b/ir/irclass.cpp
index 42fb198..0971e01 100644
--- a/ir/irclass.cpp
+++ b/ir/irclass.cpp
@@ -178,27 +178,38 @@ LLConstant *IrAggr::getVtblInit() {
   // add virtual function pointers
   size_t n = cd->vtbl.dim;
   for (size_t i = cd->vtblOffset(); i < n; i++) {
-    Dsymbol *dsym = static_cast<Dsymbol *>(cd->vtbl.data[i]);
+    Dsymbol *dsym = cd->vtbl[i];
     assert(dsym && "null vtbl member");
 
     FuncDeclaration *fd = dsym->isFuncDeclaration();
     assert(fd && "vtbl entry not a function");
 
     if (cd->isAbstract() || (fd->isAbstract() && !fd->fbody)) {
-      c = getNullValue(getPtrToType(DtoFunctionType(fd)));
+      c = getNullValue(voidPtrType);
     } else {
+      // If inferring return type and semantic3 has not been run, do it now.
+      // This pops up in some other places in the frontend as well, however
+      // it is probably a bug that it still occurs that late.
+      if (fd->inferRetType && !fd->type->nextOf()) {
+        Logger::println("Running late functionSemantic to infer return type.");
+        if (!fd->functionSemantic()) {
+          fd->error("failed to infer return type for vtbl initializer");
+          fatal();
+        }
+      }
+
       DtoResolveFunction(fd);
       assert(isIrFuncCreated(fd) && "invalid vtbl function");
-      c = getIrFunc(fd)->func;
+      c = DtoBitCast(getIrFunc(fd)->func, voidPtrType);
+
       if (cd->isFuncHidden(fd)) {
         // fd is hidden from the view of this class. If fd overlaps with any
         // function in the vtbl[], issue error.
-        for (size_t j = 1; j < n; j++) {
+        for (size_t j = cd->vtblOffset(); j < n; j++) {
           if (j == i) {
             continue;
           }
-          auto fd2 =
-              static_cast<Dsymbol *>(cd->vtbl.data[j])->isFuncDeclaration();
+          auto fd2 = cd->vtbl[j]->isFuncDeclaration();
           if (!fd2->ident->equals(fd->ident)) {
             continue;
           }
@@ -209,9 +220,8 @@ LLConstant *IrAggr::getVtblInit() {
                         "to introduce base class overload set",
                         fd->toPrettyChars(),
                         parametersTypeToChars(tf->parameters, tf->varargs),
-                        cd->toChars(),
-
-                        fd->toChars(), fd->parent->toChars(), fd->toChars());
+                        cd->toChars(), fd->toChars(), fd->parent->toChars(),
+                        fd->toChars());
             } else {
               cd->error("use of %s is hidden by %s", fd->toPrettyChars(),
                         cd->toChars());
@@ -222,7 +232,8 @@ LLConstant *IrAggr::getVtblInit() {
         }
       }
     }
-    constants.push_back(DtoBitCast(c, voidPtrType));
+
+    constants.push_back(c);
   }
 
   // build the constant array
diff --git a/tests/compilable/gh1906.d b/tests/compilable/gh1906.d
new file mode 100644
index 0000000..e8ee8d6
--- /dev/null
+++ b/tests/compilable/gh1906.d
@@ -0,0 +1,5 @@
+// RUN: %ldc -c -I%S/inputs %s
+
+import gh1906b;
+
+class C : Base {}
diff --git a/tests/compilable/inputs/gh1906b.d b/tests/compilable/inputs/gh1906b.d
new file mode 100644
index 0000000..ce50cbd
--- /dev/null
+++ b/tests/compilable/inputs/gh1906b.d
@@ -0,0 +1,5 @@
+class Base
+{
+    auto foo() { return this; }
+    abstract int bar();
+}

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-d/ldc.git



More information about the pkg-d-commits mailing list