Skip to content

Commit

Permalink
CodeView debug information for Windows does not like "non-class" meth…
Browse files Browse the repository at this point in the history
…ods.

Following [Rust's solution](rust-lang/rust#35991 (comment)), we make a dummy scope for primitive methods.

This change also reorders some imports in codegen.h and gendebug.cc, as gendebug.h now depends on having PONY_LLVM defined.
  • Loading branch information
chalcolith committed Nov 19, 2017
1 parent f329da1 commit 842e09d
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 9 deletions.
16 changes: 8 additions & 8 deletions src/libponyc/codegen/codegen.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
#ifndef CODEGEN_H
#define CODEGEN_H

#include "gendebug.h"
#include "../reach/reach.h"
#include "../pass/pass.h"
#include "../ast/ast.h"
#include "../ast/printbuf.h"

#include <platform.h>
#include <llvm-c/Core.h>
#include <llvm-c/Target.h>
Expand All @@ -15,10 +9,16 @@
#include <llvm-c/Analysis.h>
#include <stdio.h>

PONY_EXTERN_C_BEGIN

#define PONY_LLVM ((LLVM_VERSION_MAJOR * 100) + LLVM_VERSION_MINOR)

#include "gendebug.h"
#include "../reach/reach.h"
#include "../pass/pass.h"
#include "../ast/ast.h"
#include "../ast/printbuf.h"

PONY_EXTERN_C_BEGIN

// Missing from C API.
char* LLVMGetHostCPUName();
char* LLVMGetHostCPUFeatures();
Expand Down
14 changes: 13 additions & 1 deletion src/libponyc/codegen/gendebug.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "gendebug.h"
#include "codegen.h"
#include "gendebug.h"

#ifdef _MSC_VER
# pragma warning(push)
Expand Down Expand Up @@ -97,6 +97,18 @@ LLVMMetadataRef LLVMDIBuilderCreateFile(LLVMDIBuilderRef d, const char* file)
return wrap(pd->createFile(filename, dir));
}

#if PONY_LLVM >= 309

LLVMMetadataRef LLVMDIBuilderCreateNamespace(LLVMDIBuilderRef d,
LLVMMetadataRef scope, const char* name, LLVMMetadataRef file, unsigned line)
{
DIBuilder* pd = unwrap(d);
return wrap(pd->createNameSpace(unwrap<DIScope>(scope), name,
unwrap<DIFile>(file), line));
}

#endif

LLVMMetadataRef LLVMDIBuilderCreateLexicalBlock(LLVMDIBuilderRef d,
LLVMMetadataRef scope, LLVMMetadataRef file, unsigned line, unsigned col)
{
Expand Down
6 changes: 6 additions & 0 deletions src/libponyc/codegen/gendebug.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ LLVMMetadataRef LLVMDIBuilderCreateCompileUnit(LLVMDIBuilderRef d,

LLVMMetadataRef LLVMDIBuilderCreateFile(LLVMDIBuilderRef d, const char* file);

#if PONY_LLVM >= 309
LLVMMetadataRef LLVMDIBuilderCreateNamespace(LLVMDIBuilderRef d,
LLVMMetadataRef scope, const char* name, LLVMMetadataRef file,
unsigned line);
#endif

LLVMMetadataRef LLVMDIBuilderCreateLexicalBlock(LLVMDIBuilderRef d,
LLVMMetadataRef scope, LLVMMetadataRef file, unsigned line, unsigned col);

Expand Down
9 changes: 9 additions & 0 deletions src/libponyc/codegen/genfun.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,15 @@ static void make_function_debug(compile_t* c, reach_type_t* t,
else
scope = c_t->di_type;

#if PONY_LLVM >= 309 && defined(_MSC_VER)
// CodeView on Windows doesn't like "non-class" methods
if (c_t->primitive != NULL)
{
scope = LLVMDIBuilderCreateNamespace(c->di, c->di_unit, t->name,
c_t->di_file, (unsigned)ast_line(t->ast));
}
#endif

c_m->di_method = LLVMDIBuilderCreateMethod(c->di, scope, ast_name(id),
m->full_name, c_m->di_file, (unsigned)ast_line(m->r_fun), subroutine, func,
c->opt->release);
Expand Down

0 comments on commit 842e09d

Please sign in to comment.