Skip to content

Commit 81b2920

Browse files
committed
fix #922 (wrong line numbers in error expressions) and remove old hacks around this issue
1 parent a33cd07 commit 81b2920

File tree

6 files changed

+27
-56
lines changed

6 files changed

+27
-56
lines changed

src/builtins.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,6 @@ void NORETURN jl_type_error_rt(const char *fname, const char *context,
103103
jl_throw(ex);
104104
}
105105

106-
void NORETURN jl_type_error_rt_line(const char *fname, const char *context,
107-
jl_value_t *ty, jl_value_t *got, int line)
108-
{
109-
jl_type_error_rt(fname, context, ty, got);
110-
}
111-
112106
void NORETURN jl_type_error(const char *fname, jl_value_t *expected, jl_value_t *got)
113107
{
114108
jl_type_error_rt(fname, "", expected, got);

src/cgutils.cpp

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -935,11 +935,9 @@ static void raise_exception_unless(Value *cond, Value *exc, jl_codectx_t *ctx)
935935
builder.CreateCondBr(cond, passBB, failBB);
936936
builder.SetInsertPoint(failBB);
937937
#ifdef LLVM37
938-
builder.CreateCall(prepare_call(jlthrow_line_func), { exc,
939-
ConstantInt::get(T_int32, ctx->lineno) });
938+
builder.CreateCall(prepare_call(jlthrow_func), { exc });
940939
#else
941-
builder.CreateCall2(prepare_call(jlthrow_line_func), exc,
942-
ConstantInt::get(T_int32, ctx->lineno));
940+
builder.CreateCall(prepare_call(jlthrow_func), exc);
943941
#endif
944942
builder.CreateUnreachable();
945943
ctx->f->getBasicBlockList().push_back(passBB);
@@ -983,13 +981,11 @@ static void emit_type_error(const jl_cgval_t &x, jl_value_t *type, const std::st
983981
#ifdef LLVM37
984982
builder.CreateCall(prepare_call(jltypeerror_func),
985983
{ fname_val, msg_val,
986-
literal_pointer_val(type), boxed(x,ctx),
987-
ConstantInt::get(T_int32, ctx->lineno) });
984+
literal_pointer_val(type), boxed(x,ctx)});
988985
#else
989-
builder.CreateCall5(prepare_call(jltypeerror_func),
986+
builder.CreateCall4(prepare_call(jltypeerror_func),
990987
fname_val, msg_val,
991-
literal_pointer_val(type), boxed(x,ctx),
992-
ConstantInt::get(T_int32, ctx->lineno));
988+
literal_pointer_val(type), boxed(x,ctx));
993989
#endif
994990
}
995991

src/codegen.cpp

Lines changed: 20 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,6 @@ extern RTDyldMemoryManager* createRTDyldMemoryManagerOSX();
315315
// important functions
316316
static Function *jlnew_func;
317317
static Function *jlthrow_func;
318-
static Function *jlthrow_line_func;
319318
static Function *jlerror_func;
320319
static Function *jltypeerror_func;
321320
static Function *jlundefvarerror_func;
@@ -539,7 +538,6 @@ typedef struct {
539538
bool vaStack; // varargs stack-allocated
540539
bool sret;
541540
int nReqArgs;
542-
int lineno;
543541
std::vector<bool> boundsCheck;
544542

545543
jl_gcinfo_t gc;
@@ -1437,7 +1435,7 @@ extern "C" void jl_write_malloc_log(void)
14371435
static void show_source_loc(JL_STREAM *out, jl_codectx_t *ctx)
14381436
{
14391437
if (ctx == NULL) return;
1440-
jl_printf(out, "in %s at %s:%d", ctx->linfo->name->name, ctx->linfo->file->name, ctx->lineno);
1438+
jl_printf(out, "in %s at %s", ctx->linfo->name->name, ctx->linfo->file->name);
14411439
}
14421440

14431441
extern "C" void jl_binding_deprecation_warning(jl_binding_t *b);
@@ -4417,7 +4415,6 @@ static Function *emit_function(jl_lambda_info_t *lam)
44174415
}
44184416
}
44194417
}
4420-
ctx.lineno = lno;
44214418
int toplineno = lno;
44224419

44234420
DIBuilder dbuilder(*m);
@@ -4429,6 +4426,7 @@ static Function *emit_function(jl_lambda_info_t *lam)
44294426
DIFile topfile;
44304427
DISubprogram SP;
44314428
#endif
4429+
DebugLoc inlineLoc;
44324430

44334431
BasicBlock *b0 = BasicBlock::Create(jl_LLVMContext, "top", f);
44344432
builder.SetInsertPoint(b0);
@@ -4503,7 +4501,8 @@ static Function *emit_function(jl_lambda_info_t *lam)
45034501
true, // isOptimized
45044502
f); // Fn
45054503
// set initial line number
4506-
builder.SetCurrentDebugLocation(DebugLoc::get(lno, 0, (MDNode*)SP, NULL));
4504+
inlineLoc = DebugLoc::get(lno, 0, (MDNode*)SP, NULL);
4505+
builder.SetCurrentDebugLocation(inlineLoc);
45074506
#ifndef LLVM37
45084507
assert(SP.Verify() && SP.describes(f) && SP.getFunction() == f);
45094508
#endif
@@ -4520,7 +4519,7 @@ static Function *emit_function(jl_lambda_info_t *lam)
45204519
argname->name, // Variable name
45214520
ctx.sret + i + 1, // Argument number (1-based)
45224521
topfile, // File
4523-
ctx.lineno == -1 ? 0 : ctx.lineno, // Line
4522+
toplineno == -1 ? 0 : toplineno, // Line
45244523
// Variable type
45254524
julia_type_to_di(varinfo.value.typ,ctx.dbuilder,specsig));
45264525
#else
@@ -4529,7 +4528,7 @@ static Function *emit_function(jl_lambda_info_t *lam)
45294528
SP, // Scope (current function will be fill in later)
45304529
argname->name, // Variable name
45314530
topfile, // File
4532-
ctx.lineno == -1 ? 0 : ctx.lineno, // Line (for now, use lineno of the function)
4531+
toplineno == -1 ? 0 : toplineno, // Line (for now, use lineno of the function)
45334532
julia_type_to_di(varinfo.value.typ, ctx.dbuilder, specsig), // Variable type
45344533
false, // May be optimized out
45354534
0, // Flags (TODO: Do we need any)
@@ -4543,15 +4542,15 @@ static Function *emit_function(jl_lambda_info_t *lam)
45434542
ctx.vaName->name, // Variable name
45444543
ctx.sret + nreq + 1, // Argument number (1-based)
45454544
topfile, // File
4546-
ctx.lineno == -1 ? 0 : ctx.lineno, // Line (for now, use lineno of the function)
4545+
toplineno == -1 ? 0 : toplineno, // Line (for now, use lineno of the function)
45474546
julia_type_to_di(ctx.vars[ctx.vaName].value.typ, ctx.dbuilder, false));
45484547
#else
45494548
ctx.vars[ctx.vaName].dinfo = ctx.dbuilder->createLocalVariable(
45504549
llvm::dwarf::DW_TAG_arg_variable, // Tag
45514550
SP, // Scope (current function will be fill in later)
45524551
ctx.vaName->name, // Variable name
45534552
topfile, // File
4554-
ctx.lineno == -1 ? 0 : ctx.lineno, // Line (for now, use lineno of the function)
4553+
toplineno == -1 ? 0 : toplineno, // Line (for now, use lineno of the function)
45554554
julia_type_to_di(ctx.vars[ctx.vaName].value.typ, ctx.dbuilder, false), // Variable type
45564555
false, // May be optimized out
45574556
0, // Flags (TODO: Do we need any)
@@ -4572,7 +4571,7 @@ static Function *emit_function(jl_lambda_info_t *lam)
45724571
SP, // Scope (current function will be fill in later)
45734572
s->name, // Variable name
45744573
topfile, // File
4575-
ctx.lineno == -1 ? 0 : ctx.lineno, // Line (for now, use lineno of the function)
4574+
toplineno == -1 ? 0 : toplineno, // Line (for now, use lineno of the function)
45764575
julia_type_to_di(varinfo.value.typ, ctx.dbuilder, specsig), // Variable type
45774576
false, // May be optimized out
45784577
0 // Flags (TODO: Do we need any)
@@ -4596,7 +4595,7 @@ static Function *emit_function(jl_lambda_info_t *lam)
45964595
SP, // Scope (current function will be filled in later)
45974596
vname->name, // Variable name
45984597
topfile, // File
4599-
ctx.lineno == -1 ? 0 : ctx.lineno, // Line (for now, use lineno of the function)
4598+
toplineno == -1 ? 0 : toplineno, // Line (for now, use lineno of the function)
46004599
julia_type_to_di(varinfo.value.typ, ctx.dbuilder, specsig), // Variable type
46014600
false, // May be optimized out
46024601
0 // Flags (TODO: Do we need any)
@@ -4996,35 +4995,31 @@ static Function *emit_function(jl_lambda_info_t *lam)
49964995
}
49974996
DebugLoc loc;
49984997
if (ctx.debug_enabled) {
4999-
MDNode *funcscope = (MDNode*)dbuilder.createLexicalBlockFile(SP, topfile);
50004998
MDNode *scope;
50014999
if ((dfil == topfile || dfil == NULL) &&
50025000
lno >= toplineno)
50035001
{
50045002
// for sequentially-defined code,
50055003
// set location to line in top file.
50065004
// TODO: improve handling of nested inlines
5007-
loc = DebugLoc::get(lno, 1, SP, NULL);
5005+
loc = inlineLoc = DebugLoc::get(lno, 1, SP, NULL);
50085006
} else {
50095007
// otherwise, we are compiling inlined code,
50105008
// so set the DebugLoc "inlinedAt" parameter
50115009
// to the current line, then use source loc.
50125010
#ifdef LLVM37
50135011
scope = (MDNode*)dbuilder.createLexicalBlockFile(SP,dfil);
5014-
MDNode *inlineLocMd = DebugLoc::get(toplineno, 1, funcscope, NULL).
5015-
getAsMDNode();
5012+
MDNode *inlineLocMd = inlineLoc.getAsMDNode();
50165013
#else
50175014
scope = (MDNode*)dbuilder.createLexicalBlockFile(SP,DIFile(dfil));
5018-
MDNode *inlineLocMd = DebugLoc::get(toplineno, 1, funcscope, NULL).
5019-
getAsMDNode(jl_LLVMContext);
5015+
MDNode *inlineLocMd = inlineLoc.getAsMDNode(jl_LLVMContext);
50205016
#endif
50215017
loc = DebugLoc::get(lno, 1, scope, inlineLocMd);
50225018
}
50235019
builder.SetCurrentDebugLocation(loc);
50245020
}
50255021
if (do_coverage)
50265022
coverageVisitLine(filename, lno);
5027-
ctx.lineno = lno; // NOO TOUCHIE; NO TOUCH! See #922
50285023
}
50295024
if (jl_is_labelnode(stmt)) {
50305025
if (prevlabel) continue;
@@ -5478,15 +5473,6 @@ static void init_julia_llvm_env(Module *m)
54785473
jluboundserror_func->setDoesNotReturn();
54795474
add_named_global(jluboundserror_func, (void*)&jl_bounds_error_unboxed_int);
54805475

5481-
std::vector<Type*> args2_throw(0);
5482-
args2_throw.push_back(T_pjlvalue);
5483-
args2_throw.push_back(T_int32);
5484-
jlthrow_line_func =
5485-
(Function*)m->getOrInsertFunction("jl_throw_with_superfluous_argument",
5486-
FunctionType::get(T_void, args2_throw, false));
5487-
jlthrow_line_func->setDoesNotReturn();
5488-
add_named_global(jlthrow_line_func, (void*)&jl_throw_with_superfluous_argument);
5489-
54905476
jlnew_func =
54915477
Function::Create(jl_func_sig, Function::ExternalLinkage,
54925478
"jl_new_structv", m);
@@ -5517,13 +5503,12 @@ static void init_julia_llvm_env(Module *m)
55175503
te_args.push_back(T_pint8);
55185504
te_args.push_back(T_pjlvalue);
55195505
te_args.push_back(T_pjlvalue);
5520-
te_args.push_back(T_int32);
55215506
jltypeerror_func =
55225507
Function::Create(FunctionType::get(T_void, te_args, false),
55235508
Function::ExternalLinkage,
5524-
"jl_type_error_rt_line", m);
5509+
"jl_type_error_rt", m);
55255510
jltypeerror_func->setDoesNotReturn();
5526-
add_named_global(jltypeerror_func, (void*)&jl_type_error_rt_line);
5511+
add_named_global(jltypeerror_func, (void*)&jl_type_error_rt);
55275512

55285513
std::vector<Type *> args_2ptrs(0);
55295514
args_2ptrs.push_back(T_pjlvalue);
@@ -5923,13 +5908,16 @@ static void init_julia_llvm_env(Module *m)
59235908

59245909
extern "C" void jl_init_codegen(void)
59255910
{
5911+
const char *const argv_tailmerge[] = {"", "-enable-tail-merge=0"}; // NOO TOUCHIE; NO TOUCH! See #922
5912+
cl::ParseCommandLineOptions(sizeof(argv_tailmerge)/sizeof(argv_tailmerge[0]), argv_tailmerge, "disable-tail-merge\n");
59265913
#if defined(_OS_WINDOWS_) && defined(_CPU_X86_64_)
5927-
const char *const argv[] = {"", "-disable-copyprop"}; // llvm bug 21743
5928-
cl::ParseCommandLineOptions(sizeof(argv)/sizeof(argv[0]), argv, "disable-copyprop\n");
5914+
const char *const argv_copyprop[] = {"", "-disable-copyprop"}; // llvm bug 21743
5915+
cl::ParseCommandLineOptions(sizeof(argv_copyprop)/sizeof(argv_copyprop[0]), argv_copyprop, "disable-copyprop\n");
59295916
#endif
59305917
#ifdef JL_DEBUG_BUILD
59315918
cl::ParseEnvironmentOptions("Julia", "JULIA_LLVM_ARGS");
59325919
#endif
5920+
59335921
#if defined(_CPU_PPC_) || defined(_CPU_PPC64_)
59345922
imaging_mode = true; // LLVM seems to JIT bad TOC tables for the optimizations we attempt in non-imaging_mode
59355923
#else

src/julia.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1150,8 +1150,6 @@ DLLEXPORT void NORETURN jl_too_many_args(const char *fname, int max);
11501150
DLLEXPORT void NORETURN jl_type_error(const char *fname, jl_value_t *expected, jl_value_t *got);
11511151
DLLEXPORT void NORETURN jl_type_error_rt(const char *fname, const char *context,
11521152
jl_value_t *ty, jl_value_t *got);
1153-
DLLEXPORT void NORETURN jl_type_error_rt_line(const char *fname, const char *context,
1154-
jl_value_t *ty, jl_value_t *got, int line);
11551153
DLLEXPORT void NORETURN jl_undefined_var_error(jl_sym_t *var);
11561154
DLLEXPORT void NORETURN jl_bounds_error(jl_value_t *v, jl_value_t *t);
11571155
DLLEXPORT void NORETURN jl_bounds_error_v(jl_value_t *v, jl_value_t **idxs, size_t nidxs);
@@ -1405,7 +1403,6 @@ extern DLLEXPORT JL_THREAD jl_value_t *jl_exception_in_transit;
14051403
DLLEXPORT jl_task_t *jl_new_task(jl_function_t *start, size_t ssize);
14061404
DLLEXPORT jl_value_t *jl_switchto(jl_task_t *t, jl_value_t *arg);
14071405
DLLEXPORT void NORETURN jl_throw(jl_value_t *e);
1408-
DLLEXPORT void NORETURN jl_throw_with_superfluous_argument(jl_value_t *e, int);
14091406
DLLEXPORT void NORETURN jl_rethrow(void);
14101407
DLLEXPORT void NORETURN jl_rethrow_other(jl_value_t *e);
14111408

src/task.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -828,11 +828,6 @@ DLLEXPORT void jl_rethrow_other(jl_value_t *e)
828828
throw_internal(e);
829829
}
830830

831-
DLLEXPORT void jl_throw_with_superfluous_argument(jl_value_t *e, int line)
832-
{
833-
jl_throw(e);
834-
}
835-
836831
DLLEXPORT jl_task_t *jl_new_task(jl_function_t *start, size_t ssize)
837832
{
838833
size_t pagesz = jl_page_size;

test/backtrace.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,5 +99,6 @@ let
9999
ind2 = find(:test_throw_commoning .== map(b->code_loc(b)[1], b2))
100100
@test !isempty(ind1)
101101
@test !isempty(ind2)
102-
@test code_loc(b1[ind1[1]])[3] != code_loc(b2[ind2[1]])[3]
102+
@test code_loc(b1[ind1[1]])[3] == code_loc(b2[ind2[1]])[3] && # source line, for example: essentials.jl:58
103+
code_loc(b1[ind1[1]])[5] != code_loc(b2[ind2[1]])[5] # inlined line, for example: backtrace.jl:82
103104
end

0 commit comments

Comments
 (0)