Skip to content

Commit

Permalink
Require complete return and parameter types in MarkFunctionReferenced…
Browse files Browse the repository at this point in the history
…() to avoid codegen errors.
  • Loading branch information
Syniurge committed Nov 3, 2019
1 parent d33ea30 commit b2964d9
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion dmd/cpp/cppdeclaration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

#include "clang/AST/Decl.h"
#include "clang/Sema/Sema.h"
#include "clang/Sema/SemaDiagnostic.h"

int overloadApply(Dsymbol *fstart, void *param, int (*fp)(void *, Dsymbol *));

Expand Down Expand Up @@ -525,7 +526,7 @@ void MarkFunctionReferenced(::FuncDeclaration* fd)

if (isUsed)
return;
isUsed = true;
isUsed = true; // TODO: reduce the bloat even more, by splitting isUsed into isDeclared and isCalled?

auto CanonDecl = cast<clang::NamedDecl>(getCanonicalDecl(getFD(fd)));
if (auto instantiatedBy = CanonDecl->d->instantiatedBy)
Expand All @@ -541,6 +542,34 @@ void MarkFunctionReferenced(::FuncDeclaration* fd)

InstantiateAndTraverseFunctionBody(fd);

auto FD = getFD(fd);
if (!FD->hasBody())
{
auto& S = calypso.getSema();
bool hasIncompleteType = false;

auto requireCompleteType = [&] (clang::QualType T)
{
if (T->isVoidType())
return false;
return S.RequireCompleteType(FD->getLocation(), T,
clang::diag::err_incomplete_type);
};

if (requireCompleteType(FD->getReturnType()))
hasIncompleteType = true;

for (auto *Param : FD->parameters())
if (requireCompleteType(Param->getType()))
hasIncompleteType = true;

if (hasIncompleteType)
{
fd->error("return or parameter type is incomplete");
fd->errors = true;
}
}

markModuleForGenIfNeeded(fd);
}

Expand Down

0 comments on commit b2964d9

Please sign in to comment.