Skip to content

Commit 842e09d

Browse files
committed
CodeView debug information for Windows does not like "non-class" methods.
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.
1 parent f329da1 commit 842e09d

File tree

4 files changed

+36
-9
lines changed

4 files changed

+36
-9
lines changed

src/libponyc/codegen/codegen.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
#ifndef CODEGEN_H
22
#define CODEGEN_H
33

4-
#include "gendebug.h"
5-
#include "../reach/reach.h"
6-
#include "../pass/pass.h"
7-
#include "../ast/ast.h"
8-
#include "../ast/printbuf.h"
9-
104
#include <platform.h>
115
#include <llvm-c/Core.h>
126
#include <llvm-c/Target.h>
@@ -15,10 +9,16 @@
159
#include <llvm-c/Analysis.h>
1610
#include <stdio.h>
1711

18-
PONY_EXTERN_C_BEGIN
19-
2012
#define PONY_LLVM ((LLVM_VERSION_MAJOR * 100) + LLVM_VERSION_MINOR)
2113

14+
#include "gendebug.h"
15+
#include "../reach/reach.h"
16+
#include "../pass/pass.h"
17+
#include "../ast/ast.h"
18+
#include "../ast/printbuf.h"
19+
20+
PONY_EXTERN_C_BEGIN
21+
2222
// Missing from C API.
2323
char* LLVMGetHostCPUName();
2424
char* LLVMGetHostCPUFeatures();

src/libponyc/codegen/gendebug.cc

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#include "gendebug.h"
21
#include "codegen.h"
2+
#include "gendebug.h"
33

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

100+
#if PONY_LLVM >= 309
101+
102+
LLVMMetadataRef LLVMDIBuilderCreateNamespace(LLVMDIBuilderRef d,
103+
LLVMMetadataRef scope, const char* name, LLVMMetadataRef file, unsigned line)
104+
{
105+
DIBuilder* pd = unwrap(d);
106+
return wrap(pd->createNameSpace(unwrap<DIScope>(scope), name,
107+
unwrap<DIFile>(file), line));
108+
}
109+
110+
#endif
111+
100112
LLVMMetadataRef LLVMDIBuilderCreateLexicalBlock(LLVMDIBuilderRef d,
101113
LLVMMetadataRef scope, LLVMMetadataRef file, unsigned line, unsigned col)
102114
{

src/libponyc/codegen/gendebug.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,12 @@ LLVMMetadataRef LLVMDIBuilderCreateCompileUnit(LLVMDIBuilderRef d,
5454

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

57+
#if PONY_LLVM >= 309
58+
LLVMMetadataRef LLVMDIBuilderCreateNamespace(LLVMDIBuilderRef d,
59+
LLVMMetadataRef scope, const char* name, LLVMMetadataRef file,
60+
unsigned line);
61+
#endif
62+
5763
LLVMMetadataRef LLVMDIBuilderCreateLexicalBlock(LLVMDIBuilderRef d,
5864
LLVMMetadataRef scope, LLVMMetadataRef file, unsigned line, unsigned col);
5965

src/libponyc/codegen/genfun.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,15 @@ static void make_function_debug(compile_t* c, reach_type_t* t,
189189
else
190190
scope = c_t->di_type;
191191

192+
#if PONY_LLVM >= 309 && defined(_MSC_VER)
193+
// CodeView on Windows doesn't like "non-class" methods
194+
if (c_t->primitive != NULL)
195+
{
196+
scope = LLVMDIBuilderCreateNamespace(c->di, c->di_unit, t->name,
197+
c_t->di_file, (unsigned)ast_line(t->ast));
198+
}
199+
#endif
200+
192201
c_m->di_method = LLVMDIBuilderCreateMethod(c->di, scope, ast_name(id),
193202
m->full_name, c_m->di_file, (unsigned)ast_line(m->r_fun), subroutine, func,
194203
c->opt->release);

0 commit comments

Comments
 (0)