Skip to content

Commit 3202b54

Browse files
committed
Revert "fix #922 (wrong line numbers in error expressions) and remove old hacks around this issue"
This reverts commit b8a6d77.
1 parent fa54d22 commit 3202b54

File tree

6 files changed

+56
-27
lines changed

6 files changed

+56
-27
lines changed

src/builtins.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,12 @@ 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+
106112
void NORETURN jl_type_error(const char *fname, jl_value_t *expected, jl_value_t *got)
107113
{
108114
jl_type_error_rt(fname, "", expected, got);

src/cgutils.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,9 +1059,11 @@ 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_func), { exc });
1062+
builder.CreateCall(prepare_call(jlthrow_line_func), { exc,
1063+
ConstantInt::get(T_int32, ctx->lineno) });
10631064
#else
1064-
builder.CreateCall(prepare_call(jlthrow_func), exc);
1065+
builder.CreateCall2(prepare_call(jlthrow_line_func), exc,
1066+
ConstantInt::get(T_int32, ctx->lineno));
10651067
#endif
10661068
builder.CreateUnreachable();
10671069
ctx->f->getBasicBlockList().push_back(passBB);
@@ -1105,11 +1107,13 @@ static void emit_type_error(Value *x, jl_value_t *type, const std::string &msg,
11051107
#ifdef LLVM37
11061108
builder.CreateCall(prepare_call(jltypeerror_func),
11071109
{ fname_val, msg_val,
1108-
literal_pointer_val(type), boxed(x,ctx)});
1110+
literal_pointer_val(type), boxed(x,ctx),
1111+
ConstantInt::get(T_int32, ctx->lineno) });
11091112
#else
1110-
builder.CreateCall4(prepare_call(jltypeerror_func),
1113+
builder.CreateCall5(prepare_call(jltypeerror_func),
11111114
fname_val, msg_val,
1112-
literal_pointer_val(type), boxed(x,ctx));
1115+
literal_pointer_val(type), boxed(x,ctx),
1116+
ConstantInt::get(T_int32, ctx->lineno));
11131117
#endif
11141118
}
11151119

src/codegen.cpp

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,7 @@ extern RTDyldMemoryManager* createRTDyldMemoryManagerOSX();
298298
// important functions
299299
static Function *jlnew_func;
300300
static Function *jlthrow_func;
301+
static Function *jlthrow_line_func;
301302
static Function *jlerror_func;
302303
static Function *jltypeerror_func;
303304
static Function *jlundefvarerror_func;
@@ -467,6 +468,7 @@ typedef struct {
467468
bool vaStack; // varargs stack-allocated
468469
bool sret;
469470
int nReqArgs;
471+
int lineno;
470472
std::vector<bool> boundsCheck;
471473

472474
jl_gcinfo_t gc;
@@ -1270,7 +1272,7 @@ extern "C" void jl_write_malloc_log(void)
12701272
static void show_source_loc(JL_STREAM *out, jl_codectx_t *ctx)
12711273
{
12721274
if (ctx == NULL) return;
1273-
jl_printf(out, "in %s at %s", ctx->linfo->name->name, ctx->linfo->file->name);
1275+
jl_printf(out, "in %s at %s:%d", ctx->linfo->name->name, ctx->linfo->file->name, ctx->lineno);
12741276
}
12751277

12761278
extern "C" void jl_binding_deprecation_warning(jl_binding_t *b);
@@ -4183,6 +4185,7 @@ static Function *emit_function(jl_lambda_info_t *lam)
41834185
}
41844186
}
41854187
}
4188+
ctx.lineno = lno;
41864189
int toplineno = lno;
41874190

41884191
DIBuilder dbuilder(*m);
@@ -4194,7 +4197,6 @@ static Function *emit_function(jl_lambda_info_t *lam)
41944197
DIFile topfile;
41954198
DISubprogram SP;
41964199
#endif
4197-
DebugLoc inlineLoc;
41984200

41994201
BasicBlock *b0 = BasicBlock::Create(jl_LLVMContext, "top", f);
42004202
builder.SetInsertPoint(b0);
@@ -4275,8 +4277,7 @@ static Function *emit_function(jl_lambda_info_t *lam)
42754277
f); // Function
42764278
#endif
42774279
// set initial line number
4278-
inlineLoc = DebugLoc::get(lno, 0, (MDNode*)SP, NULL);
4279-
builder.SetCurrentDebugLocation(inlineLoc);
4280+
builder.SetCurrentDebugLocation(DebugLoc::get(lno, 0, (MDNode*)SP, NULL));
42804281
#ifdef LLVM38
42814282
f->setSubprogram(SP);
42824283
#endif
@@ -4296,7 +4297,7 @@ static Function *emit_function(jl_lambda_info_t *lam)
42964297
argname->name, // Variable name
42974298
ctx.sret + i + 1, // Argument number (1-based)
42984299
topfile, // File
4299-
toplineno == -1 ? 0 : toplineno, // Line
4300+
ctx.lineno == -1 ? 0 : ctx.lineno, // Line
43004301
// Variable type
43014302
julia_type_to_di(varinfo.declType,ctx.dbuilder,specsig));
43024303
#else
@@ -4305,7 +4306,7 @@ static Function *emit_function(jl_lambda_info_t *lam)
43054306
SP, // Scope (current function will be fill in later)
43064307
argname->name, // Variable name
43074308
topfile, // File
4308-
toplineno == -1 ? 0 : toplineno, // Line (for now, use lineno of the function)
4309+
ctx.lineno == -1 ? 0 : ctx.lineno, // Line (for now, use lineno of the function)
43094310
julia_type_to_di(varinfo.declType,ctx.dbuilder,specsig), // Variable type
43104311
false, // May be optimized out
43114312
0, // Flags (TODO: Do we need any)
@@ -4319,15 +4320,15 @@ static Function *emit_function(jl_lambda_info_t *lam)
43194320
ctx.vaName->name, // Variable name
43204321
ctx.sret + nreq + 1, // Argument number (1-based)
43214322
topfile, // File
4322-
toplineno == -1 ? 0 : toplineno, // Line (for now, use lineno of the function)
4323+
ctx.lineno == -1 ? 0 : ctx.lineno, // Line (for now, use lineno of the function)
43234324
julia_type_to_di(ctx.vars[ctx.vaName].declType,ctx.dbuilder,false));
43244325
#else
43254326
ctx.vars[ctx.vaName].dinfo = ctx.dbuilder->createLocalVariable(
43264327
llvm::dwarf::DW_TAG_arg_variable, // Tag
43274328
SP, // Scope (current function will be fill in later)
43284329
ctx.vaName->name, // Variable name
43294330
topfile, // File
4330-
toplineno == -1 ? 0 : toplineno, // Line (for now, use lineno of the function)
4331+
ctx.lineno == -1 ? 0 : ctx.lineno, // Line (for now, use lineno of the function)
43314332
julia_type_to_di(ctx.vars[ctx.vaName].declType,ctx.dbuilder,false), // Variable type
43324333
false, // May be optimized out
43334334
0, // Flags (TODO: Do we need any)
@@ -4348,7 +4349,7 @@ static Function *emit_function(jl_lambda_info_t *lam)
43484349
SP, // Scope (current function will be fill in later)
43494350
s->name, // Variable name
43504351
topfile, // File
4351-
toplineno == -1 ? 0 : toplineno, // Line (for now, use lineno of the function)
4352+
ctx.lineno == -1 ? 0 : ctx.lineno, // Line (for now, use lineno of the function)
43524353
julia_type_to_di(varinfo.declType,ctx.dbuilder,specsig), // Variable type
43534354
false, // May be optimized out
43544355
0 // Flags (TODO: Do we need any)
@@ -4372,7 +4373,7 @@ static Function *emit_function(jl_lambda_info_t *lam)
43724373
SP, // Scope (current function will be filled in later)
43734374
vname->name, // Variable name
43744375
topfile, // File
4375-
toplineno == -1 ? 0 : toplineno, // Line (for now, use lineno of the function)
4376+
ctx.lineno == -1 ? 0 : ctx.lineno, // Line (for now, use lineno of the function)
43764377
julia_type_to_di(varinfo.declType,ctx.dbuilder,specsig), // Variable type
43774378
false, // May be optimized out
43784379
0 // Flags (TODO: Do we need any)
@@ -4738,31 +4739,35 @@ static Function *emit_function(jl_lambda_info_t *lam)
47384739
}
47394740
DebugLoc loc;
47404741
if (ctx.debug_enabled) {
4742+
MDNode *funcscope = (MDNode*)dbuilder.createLexicalBlockFile(SP, topfile);
47414743
MDNode *scope;
47424744
if ((dfil == topfile || dfil == NULL) &&
47434745
lno >= toplineno)
47444746
{
47454747
// for sequentially-defined code,
47464748
// set location to line in top file.
47474749
// TODO: improve handling of nested inlines
4748-
loc = inlineLoc = DebugLoc::get(lno, 1, SP, NULL);
4750+
loc = DebugLoc::get(lno, 1, SP, NULL);
47494751
} else {
47504752
// otherwise, we are compiling inlined code,
47514753
// so set the DebugLoc "inlinedAt" parameter
47524754
// to the current line, then use source loc.
47534755
#ifdef LLVM37
47544756
scope = (MDNode*)dbuilder.createLexicalBlockFile(SP,dfil);
4755-
MDNode *inlineLocMd = inlineLoc.getAsMDNode();
4757+
MDNode *inlineLocMd = DebugLoc::get(toplineno, 1, funcscope, NULL).
4758+
getAsMDNode();
47564759
#else
47574760
scope = (MDNode*)dbuilder.createLexicalBlockFile(SP,DIFile(dfil));
4758-
MDNode *inlineLocMd = inlineLoc.getAsMDNode(jl_LLVMContext);
4761+
MDNode *inlineLocMd = DebugLoc::get(toplineno, 1, funcscope, NULL).
4762+
getAsMDNode(jl_LLVMContext);
47594763
#endif
47604764
loc = DebugLoc::get(lno, 1, scope, inlineLocMd);
47614765
}
47624766
builder.SetCurrentDebugLocation(loc);
47634767
}
47644768
if (do_coverage)
47654769
coverageVisitLine(filename, lno);
4770+
ctx.lineno = lno; // NOO TOUCHIE; NO TOUCH! See #922
47664771
}
47674772
if (jl_is_labelnode(stmt)) {
47684773
if (prevlabel) continue;
@@ -5201,6 +5206,15 @@ static void init_julia_llvm_env(Module *m)
52015206
jluboundserror_func->setDoesNotReturn();
52025207
add_named_global(jluboundserror_func, (void*)&jl_bounds_error_unboxed_int);
52035208

5209+
std::vector<Type*> args2_throw(0);
5210+
args2_throw.push_back(jl_pvalue_llvmt);
5211+
args2_throw.push_back(T_int32);
5212+
jlthrow_line_func =
5213+
(Function*)m->getOrInsertFunction("jl_throw_with_superfluous_argument",
5214+
FunctionType::get(T_void, args2_throw, false));
5215+
jlthrow_line_func->setDoesNotReturn();
5216+
add_named_global(jlthrow_line_func, (void*)&jl_throw_with_superfluous_argument);
5217+
52045218
jlnew_func =
52055219
Function::Create(jl_func_sig, Function::ExternalLinkage,
52065220
"jl_new_structv", m);
@@ -5231,12 +5245,13 @@ static void init_julia_llvm_env(Module *m)
52315245
te_args.push_back(T_pint8);
52325246
te_args.push_back(jl_pvalue_llvmt);
52335247
te_args.push_back(jl_pvalue_llvmt);
5248+
te_args.push_back(T_int32);
52345249
jltypeerror_func =
52355250
Function::Create(FunctionType::get(T_void, te_args, false),
52365251
Function::ExternalLinkage,
5237-
"jl_type_error_rt", m);
5252+
"jl_type_error_rt_line", m);
52385253
jltypeerror_func->setDoesNotReturn();
5239-
add_named_global(jltypeerror_func, (void*)&jl_type_error_rt);
5254+
add_named_global(jltypeerror_func, (void*)&jl_type_error_rt_line);
52405255

52415256
std::vector<Type *> args_2ptrs(0);
52425257
args_2ptrs.push_back(jl_pvalue_llvmt);
@@ -5678,16 +5693,13 @@ static inline SmallVector<std::string,10> getTargetFeatures() {
56785693

56795694
extern "C" void jl_init_codegen(void)
56805695
{
5681-
const char *const argv_tailmerge[] = {"", "-enable-tail-merge=0"}; // NOO TOUCHIE; NO TOUCH! See #922
5682-
cl::ParseCommandLineOptions(sizeof(argv_tailmerge)/sizeof(argv_tailmerge[0]), argv_tailmerge, "disable-tail-merge\n");
56835696
#if defined(_OS_WINDOWS_) && defined(_CPU_X86_64_)
5684-
const char *const argv_copyprop[] = {"", "-disable-copyprop"}; // llvm bug 21743
5685-
cl::ParseCommandLineOptions(sizeof(argv_copyprop)/sizeof(argv_copyprop[0]), argv_copyprop, "disable-copyprop\n");
5697+
const char *const argv[] = {"", "-disable-copyprop"}; // llvm bug 21743
5698+
cl::ParseCommandLineOptions(sizeof(argv)/sizeof(argv[0]), argv, "disable-copyprop\n");
56865699
#endif
56875700
#ifdef JL_DEBUG_BUILD
56885701
cl::ParseEnvironmentOptions("Julia", "JULIA_LLVM_ARGS");
56895702
#endif
5690-
56915703
#if defined(_CPU_PPC_) || defined(_CPU_PPC64_)
56925704
imaging_mode = true; // LLVM seems to JIT bad TOC tables for the optimizations we attempt in non-imaging_mode
56935705
#else

src/julia.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1146,6 +1146,8 @@ 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);
11491151
DLLEXPORT void NORETURN jl_undefined_var_error(jl_sym_t *var);
11501152
DLLEXPORT void NORETURN jl_bounds_error(jl_value_t *v, jl_value_t *t);
11511153
DLLEXPORT void NORETURN jl_bounds_error_v(jl_value_t *v, jl_value_t **idxs, size_t nidxs);
@@ -1399,6 +1401,7 @@ extern DLLEXPORT JL_THREAD jl_value_t *jl_exception_in_transit;
13991401
DLLEXPORT jl_task_t *jl_new_task(jl_function_t *start, size_t ssize);
14001402
DLLEXPORT jl_value_t *jl_switchto(jl_task_t *t, jl_value_t *arg);
14011403
DLLEXPORT void NORETURN jl_throw(jl_value_t *e);
1404+
DLLEXPORT void NORETURN jl_throw_with_superfluous_argument(jl_value_t *e, int);
14021405
DLLEXPORT void NORETURN jl_rethrow(void);
14031406
DLLEXPORT void NORETURN jl_rethrow_other(jl_value_t *e);
14041407

src/task.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -836,6 +836,11 @@ DLLEXPORT void jl_rethrow_other(jl_value_t *e)
836836
throw_internal(e);
837837
}
838838

839+
DLLEXPORT void jl_throw_with_superfluous_argument(jl_value_t *e, int line)
840+
{
841+
jl_throw(e);
842+
}
843+
839844
DLLEXPORT jl_task_t *jl_new_task(jl_function_t *start, size_t ssize)
840845
{
841846
size_t pagesz = jl_page_size;

test/backtrace.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,5 @@ 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]::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
102+
@test code_loc(b1[ind1[1]])[3] != code_loc(b2[ind2[1]])[3]
104103
end

0 commit comments

Comments
 (0)