Skip to content

Commit b8a6d77

Browse files
vtjnashtkelman
authored andcommitted
fix #922 (wrong line numbers in error expressions) and remove old hacks around this issue
(cherry picked from commit af81d6c)
1 parent 488fb5a commit b8a6d77

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
@@ -1059,11 +1059,9 @@ static void raise_exception_unless(Value *cond, Value *exc, jl_codectx_t *ctx)
10591059
builder.CreateCondBr(cond, passBB, failBB);
10601060
builder.SetInsertPoint(failBB);
10611061
#ifdef LLVM37
1062-
builder.CreateCall(prepare_call(jlthrow_line_func), { exc,
1063-
ConstantInt::get(T_int32, ctx->lineno) });
1062+
builder.CreateCall(prepare_call(jlthrow_func), { exc });
10641063
#else
1065-
builder.CreateCall2(prepare_call(jlthrow_line_func), exc,
1066-
ConstantInt::get(T_int32, ctx->lineno));
1064+
builder.CreateCall(prepare_call(jlthrow_func), exc);
10671065
#endif
10681066
builder.CreateUnreachable();
10691067
ctx->f->getBasicBlockList().push_back(passBB);
@@ -1107,13 +1105,11 @@ static void emit_type_error(Value *x, jl_value_t *type, const std::string &msg,
11071105
#ifdef LLVM37
11081106
builder.CreateCall(prepare_call(jltypeerror_func),
11091107
{ fname_val, msg_val,
1110-
literal_pointer_val(type), boxed(x,ctx),
1111-
ConstantInt::get(T_int32, ctx->lineno) });
1108+
literal_pointer_val(type), boxed(x,ctx)});
11121109
#else
1113-
builder.CreateCall5(prepare_call(jltypeerror_func),
1110+
builder.CreateCall4(prepare_call(jltypeerror_func),
11141111
fname_val, msg_val,
1115-
literal_pointer_val(type), boxed(x,ctx),
1116-
ConstantInt::get(T_int32, ctx->lineno));
1112+
literal_pointer_val(type), boxed(x,ctx));
11171113
#endif
11181114
}
11191115

src/codegen.cpp

Lines changed: 20 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,6 @@ extern RTDyldMemoryManager* createRTDyldMemoryManagerOSX();
298298
// important functions
299299
static Function *jlnew_func;
300300
static Function *jlthrow_func;
301-
static Function *jlthrow_line_func;
302301
static Function *jlerror_func;
303302
static Function *jltypeerror_func;
304303
static Function *jlundefvarerror_func;
@@ -468,7 +467,6 @@ typedef struct {
468467
bool vaStack; // varargs stack-allocated
469468
bool sret;
470469
int nReqArgs;
471-
int lineno;
472470
std::vector<bool> boundsCheck;
473471

474472
jl_gcinfo_t gc;
@@ -1272,7 +1270,7 @@ extern "C" void jl_write_malloc_log(void)
12721270
static void show_source_loc(JL_STREAM *out, jl_codectx_t *ctx)
12731271
{
12741272
if (ctx == NULL) return;
1275-
jl_printf(out, "in %s at %s:%d", ctx->linfo->name->name, ctx->linfo->file->name, ctx->lineno);
1273+
jl_printf(out, "in %s at %s", ctx->linfo->name->name, ctx->linfo->file->name);
12761274
}
12771275

12781276
extern "C" void jl_binding_deprecation_warning(jl_binding_t *b);
@@ -4185,7 +4183,6 @@ static Function *emit_function(jl_lambda_info_t *lam)
41854183
}
41864184
}
41874185
}
4188-
ctx.lineno = lno;
41894186
int toplineno = lno;
41904187

41914188
DIBuilder dbuilder(*m);
@@ -4197,6 +4194,7 @@ static Function *emit_function(jl_lambda_info_t *lam)
41974194
DIFile topfile;
41984195
DISubprogram SP;
41994196
#endif
4197+
DebugLoc inlineLoc;
42004198

42014199
BasicBlock *b0 = BasicBlock::Create(jl_LLVMContext, "top", f);
42024200
builder.SetInsertPoint(b0);
@@ -4273,7 +4271,8 @@ static Function *emit_function(jl_lambda_info_t *lam)
42734271
true, // isOptimized
42744272
f); // Fn
42754273
// set initial line number
4276-
builder.SetCurrentDebugLocation(DebugLoc::get(lno, 0, (MDNode*)SP, NULL));
4274+
inlineLoc = DebugLoc::get(lno, 0, (MDNode*)SP, NULL);
4275+
builder.SetCurrentDebugLocation(inlineLoc);
42774276
#ifndef LLVM37
42784277
assert(SP.Verify() && SP.describes(f) && SP.getFunction() == f);
42794278
#endif
@@ -4290,7 +4289,7 @@ static Function *emit_function(jl_lambda_info_t *lam)
42904289
argname->name, // Variable name
42914290
ctx.sret + i + 1, // Argument number (1-based)
42924291
topfile, // File
4293-
ctx.lineno == -1 ? 0 : ctx.lineno, // Line
4292+
toplineno == -1 ? 0 : toplineno, // Line
42944293
// Variable type
42954294
julia_type_to_di(varinfo.declType,ctx.dbuilder,specsig));
42964295
#else
@@ -4299,7 +4298,7 @@ static Function *emit_function(jl_lambda_info_t *lam)
42994298
SP, // Scope (current function will be fill in later)
43004299
argname->name, // Variable name
43014300
topfile, // File
4302-
ctx.lineno == -1 ? 0 : ctx.lineno, // Line (for now, use lineno of the function)
4301+
toplineno == -1 ? 0 : toplineno, // Line (for now, use lineno of the function)
43034302
julia_type_to_di(varinfo.declType,ctx.dbuilder,specsig), // Variable type
43044303
false, // May be optimized out
43054304
0, // Flags (TODO: Do we need any)
@@ -4313,15 +4312,15 @@ static Function *emit_function(jl_lambda_info_t *lam)
43134312
ctx.vaName->name, // Variable name
43144313
ctx.sret + nreq + 1, // Argument number (1-based)
43154314
topfile, // File
4316-
ctx.lineno == -1 ? 0 : ctx.lineno, // Line (for now, use lineno of the function)
4315+
toplineno == -1 ? 0 : toplineno, // Line (for now, use lineno of the function)
43174316
julia_type_to_di(ctx.vars[ctx.vaName].declType,ctx.dbuilder,false));
43184317
#else
43194318
ctx.vars[ctx.vaName].dinfo = ctx.dbuilder->createLocalVariable(
43204319
llvm::dwarf::DW_TAG_arg_variable, // Tag
43214320
SP, // Scope (current function will be fill in later)
43224321
ctx.vaName->name, // Variable name
43234322
topfile, // File
4324-
ctx.lineno == -1 ? 0 : ctx.lineno, // Line (for now, use lineno of the function)
4323+
toplineno == -1 ? 0 : toplineno, // Line (for now, use lineno of the function)
43254324
julia_type_to_di(ctx.vars[ctx.vaName].declType,ctx.dbuilder,false), // Variable type
43264325
false, // May be optimized out
43274326
0, // Flags (TODO: Do we need any)
@@ -4342,7 +4341,7 @@ static Function *emit_function(jl_lambda_info_t *lam)
43424341
SP, // Scope (current function will be fill in later)
43434342
s->name, // Variable name
43444343
topfile, // File
4345-
ctx.lineno == -1 ? 0 : ctx.lineno, // Line (for now, use lineno of the function)
4344+
toplineno == -1 ? 0 : toplineno, // Line (for now, use lineno of the function)
43464345
julia_type_to_di(varinfo.declType,ctx.dbuilder,specsig), // Variable type
43474346
false, // May be optimized out
43484347
0 // Flags (TODO: Do we need any)
@@ -4366,7 +4365,7 @@ static Function *emit_function(jl_lambda_info_t *lam)
43664365
SP, // Scope (current function will be filled in later)
43674366
vname->name, // Variable name
43684367
topfile, // File
4369-
ctx.lineno == -1 ? 0 : ctx.lineno, // Line (for now, use lineno of the function)
4368+
toplineno == -1 ? 0 : toplineno, // Line (for now, use lineno of the function)
43704369
julia_type_to_di(varinfo.declType,ctx.dbuilder,specsig), // Variable type
43714370
false, // May be optimized out
43724371
0 // Flags (TODO: Do we need any)
@@ -4732,35 +4731,31 @@ static Function *emit_function(jl_lambda_info_t *lam)
47324731
}
47334732
DebugLoc loc;
47344733
if (ctx.debug_enabled) {
4735-
MDNode *funcscope = (MDNode*)dbuilder.createLexicalBlockFile(SP, topfile);
47364734
MDNode *scope;
47374735
if ((dfil == topfile || dfil == NULL) &&
47384736
lno >= toplineno)
47394737
{
47404738
// for sequentially-defined code,
47414739
// set location to line in top file.
47424740
// TODO: improve handling of nested inlines
4743-
loc = DebugLoc::get(lno, 1, SP, NULL);
4741+
loc = inlineLoc = DebugLoc::get(lno, 1, SP, NULL);
47444742
} else {
47454743
// otherwise, we are compiling inlined code,
47464744
// so set the DebugLoc "inlinedAt" parameter
47474745
// to the current line, then use source loc.
47484746
#ifdef LLVM37
47494747
scope = (MDNode*)dbuilder.createLexicalBlockFile(SP,dfil);
4750-
MDNode *inlineLocMd = DebugLoc::get(toplineno, 1, funcscope, NULL).
4751-
getAsMDNode();
4748+
MDNode *inlineLocMd = inlineLoc.getAsMDNode();
47524749
#else
47534750
scope = (MDNode*)dbuilder.createLexicalBlockFile(SP,DIFile(dfil));
4754-
MDNode *inlineLocMd = DebugLoc::get(toplineno, 1, funcscope, NULL).
4755-
getAsMDNode(jl_LLVMContext);
4751+
MDNode *inlineLocMd = inlineLoc.getAsMDNode(jl_LLVMContext);
47564752
#endif
47574753
loc = DebugLoc::get(lno, 1, scope, inlineLocMd);
47584754
}
47594755
builder.SetCurrentDebugLocation(loc);
47604756
}
47614757
if (do_coverage)
47624758
coverageVisitLine(filename, lno);
4763-
ctx.lineno = lno; // NOO TOUCHIE; NO TOUCH! See #922
47644759
}
47654760
if (jl_is_labelnode(stmt)) {
47664761
if (prevlabel) continue;
@@ -5199,15 +5194,6 @@ static void init_julia_llvm_env(Module *m)
51995194
jluboundserror_func->setDoesNotReturn();
52005195
add_named_global(jluboundserror_func, (void*)&jl_bounds_error_unboxed_int);
52015196

5202-
std::vector<Type*> args2_throw(0);
5203-
args2_throw.push_back(jl_pvalue_llvmt);
5204-
args2_throw.push_back(T_int32);
5205-
jlthrow_line_func =
5206-
(Function*)m->getOrInsertFunction("jl_throw_with_superfluous_argument",
5207-
FunctionType::get(T_void, args2_throw, false));
5208-
jlthrow_line_func->setDoesNotReturn();
5209-
add_named_global(jlthrow_line_func, (void*)&jl_throw_with_superfluous_argument);
5210-
52115197
jlnew_func =
52125198
Function::Create(jl_func_sig, Function::ExternalLinkage,
52135199
"jl_new_structv", m);
@@ -5238,13 +5224,12 @@ static void init_julia_llvm_env(Module *m)
52385224
te_args.push_back(T_pint8);
52395225
te_args.push_back(jl_pvalue_llvmt);
52405226
te_args.push_back(jl_pvalue_llvmt);
5241-
te_args.push_back(T_int32);
52425227
jltypeerror_func =
52435228
Function::Create(FunctionType::get(T_void, te_args, false),
52445229
Function::ExternalLinkage,
5245-
"jl_type_error_rt_line", m);
5230+
"jl_type_error_rt", m);
52465231
jltypeerror_func->setDoesNotReturn();
5247-
add_named_global(jltypeerror_func, (void*)&jl_type_error_rt_line);
5232+
add_named_global(jltypeerror_func, (void*)&jl_type_error_rt);
52485233

52495234
std::vector<Type *> args_2ptrs(0);
52505235
args_2ptrs.push_back(jl_pvalue_llvmt);
@@ -5686,13 +5671,16 @@ static inline SmallVector<std::string,10> getTargetFeatures() {
56865671

56875672
extern "C" void jl_init_codegen(void)
56885673
{
5674+
const char *const argv_tailmerge[] = {"", "-enable-tail-merge=0"}; // NOO TOUCHIE; NO TOUCH! See #922
5675+
cl::ParseCommandLineOptions(sizeof(argv_tailmerge)/sizeof(argv_tailmerge[0]), argv_tailmerge, "disable-tail-merge\n");
56895676
#if defined(_OS_WINDOWS_) && defined(_CPU_X86_64_)
5690-
const char *const argv[] = {"", "-disable-copyprop"}; // llvm bug 21743
5691-
cl::ParseCommandLineOptions(sizeof(argv)/sizeof(argv[0]), argv, "disable-copyprop\n");
5677+
const char *const argv_copyprop[] = {"", "-disable-copyprop"}; // llvm bug 21743
5678+
cl::ParseCommandLineOptions(sizeof(argv_copyprop)/sizeof(argv_copyprop[0]), argv_copyprop, "disable-copyprop\n");
56925679
#endif
56935680
#ifdef JL_DEBUG_BUILD
56945681
cl::ParseEnvironmentOptions("Julia", "JULIA_LLVM_ARGS");
56955682
#endif
5683+
56965684
#if defined(_CPU_PPC_) || defined(_CPU_PPC64_)
56975685
imaging_mode = true; // LLVM seems to JIT bad TOC tables for the optimizations we attempt in non-imaging_mode
56985686
#else

src/julia.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,8 +1146,6 @@ DLLEXPORT void NORETURN jl_too_many_args(const char *fname, int max);
11461146
DLLEXPORT void NORETURN jl_type_error(const char *fname, jl_value_t *expected, jl_value_t *got);
11471147
DLLEXPORT void NORETURN jl_type_error_rt(const char *fname, const char *context,
11481148
jl_value_t *ty, jl_value_t *got);
1149-
DLLEXPORT void NORETURN jl_type_error_rt_line(const char *fname, const char *context,
1150-
jl_value_t *ty, jl_value_t *got, int line);
11511149
DLLEXPORT void NORETURN jl_undefined_var_error(jl_sym_t *var);
11521150
DLLEXPORT void NORETURN jl_bounds_error(jl_value_t *v, jl_value_t *t);
11531151
DLLEXPORT void NORETURN jl_bounds_error_v(jl_value_t *v, jl_value_t **idxs, size_t nidxs);
@@ -1401,7 +1399,6 @@ extern DLLEXPORT JL_THREAD jl_value_t *jl_exception_in_transit;
14011399
DLLEXPORT jl_task_t *jl_new_task(jl_function_t *start, size_t ssize);
14021400
DLLEXPORT jl_value_t *jl_switchto(jl_task_t *t, jl_value_t *arg);
14031401
DLLEXPORT void NORETURN jl_throw(jl_value_t *e);
1404-
DLLEXPORT void NORETURN jl_throw_with_superfluous_argument(jl_value_t *e, int);
14051402
DLLEXPORT void NORETURN jl_rethrow(void);
14061403
DLLEXPORT void NORETURN jl_rethrow_other(jl_value_t *e);
14071404

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]::Int == code_loc(b2[ind2[1]])[3]::Int && # source line, for example: essentials.jl:58
103+
code_loc(b1[ind1[1]])[5]::Int != code_loc(b2[ind2[1]])[5]::Int # inlined line, for example: backtrace.jl:82
103104
end

0 commit comments

Comments
 (0)