Skip to content

Commit

Permalink
Revert "fix #922 (wrong line numbers in error expressions) and remove…
Browse files Browse the repository at this point in the history
… old hacks around this issue"

This reverts commit b8a6d77.
  • Loading branch information
tkelman committed Dec 2, 2015
1 parent fa54d22 commit 3202b54
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 27 deletions.
6 changes: 6 additions & 0 deletions src/builtins.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,12 @@ void NORETURN jl_type_error_rt(const char *fname, const char *context,
jl_throw(ex);
}

void NORETURN jl_type_error_rt_line(const char *fname, const char *context,
jl_value_t *ty, jl_value_t *got, int line)
{
jl_type_error_rt(fname, context, ty, got);
}

void NORETURN jl_type_error(const char *fname, jl_value_t *expected, jl_value_t *got)
{
jl_type_error_rt(fname, "", expected, got);
Expand Down
14 changes: 9 additions & 5 deletions src/cgutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1059,9 +1059,11 @@ static void raise_exception_unless(Value *cond, Value *exc, jl_codectx_t *ctx)
builder.CreateCondBr(cond, passBB, failBB);
builder.SetInsertPoint(failBB);
#ifdef LLVM37
builder.CreateCall(prepare_call(jlthrow_func), { exc });
builder.CreateCall(prepare_call(jlthrow_line_func), { exc,
ConstantInt::get(T_int32, ctx->lineno) });
#else
builder.CreateCall(prepare_call(jlthrow_func), exc);
builder.CreateCall2(prepare_call(jlthrow_line_func), exc,
ConstantInt::get(T_int32, ctx->lineno));
#endif
builder.CreateUnreachable();
ctx->f->getBasicBlockList().push_back(passBB);
Expand Down Expand Up @@ -1105,11 +1107,13 @@ static void emit_type_error(Value *x, jl_value_t *type, const std::string &msg,
#ifdef LLVM37
builder.CreateCall(prepare_call(jltypeerror_func),
{ fname_val, msg_val,
literal_pointer_val(type), boxed(x,ctx)});
literal_pointer_val(type), boxed(x,ctx),
ConstantInt::get(T_int32, ctx->lineno) });
#else
builder.CreateCall4(prepare_call(jltypeerror_func),
builder.CreateCall5(prepare_call(jltypeerror_func),
fname_val, msg_val,
literal_pointer_val(type), boxed(x,ctx));
literal_pointer_val(type), boxed(x,ctx),
ConstantInt::get(T_int32, ctx->lineno));
#endif
}

Expand Down
52 changes: 32 additions & 20 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ extern RTDyldMemoryManager* createRTDyldMemoryManagerOSX();
// important functions
static Function *jlnew_func;
static Function *jlthrow_func;
static Function *jlthrow_line_func;
static Function *jlerror_func;
static Function *jltypeerror_func;
static Function *jlundefvarerror_func;
Expand Down Expand Up @@ -467,6 +468,7 @@ typedef struct {
bool vaStack; // varargs stack-allocated
bool sret;
int nReqArgs;
int lineno;
std::vector<bool> boundsCheck;

jl_gcinfo_t gc;
Expand Down Expand Up @@ -1270,7 +1272,7 @@ extern "C" void jl_write_malloc_log(void)
static void show_source_loc(JL_STREAM *out, jl_codectx_t *ctx)
{
if (ctx == NULL) return;
jl_printf(out, "in %s at %s", ctx->linfo->name->name, ctx->linfo->file->name);
jl_printf(out, "in %s at %s:%d", ctx->linfo->name->name, ctx->linfo->file->name, ctx->lineno);
}

extern "C" void jl_binding_deprecation_warning(jl_binding_t *b);
Expand Down Expand Up @@ -4183,6 +4185,7 @@ static Function *emit_function(jl_lambda_info_t *lam)
}
}
}
ctx.lineno = lno;
int toplineno = lno;

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

BasicBlock *b0 = BasicBlock::Create(jl_LLVMContext, "top", f);
builder.SetInsertPoint(b0);
Expand Down Expand Up @@ -4275,8 +4277,7 @@ static Function *emit_function(jl_lambda_info_t *lam)
f); // Function
#endif
// set initial line number
inlineLoc = DebugLoc::get(lno, 0, (MDNode*)SP, NULL);
builder.SetCurrentDebugLocation(inlineLoc);
builder.SetCurrentDebugLocation(DebugLoc::get(lno, 0, (MDNode*)SP, NULL));
#ifdef LLVM38
f->setSubprogram(SP);
#endif
Expand All @@ -4296,7 +4297,7 @@ static Function *emit_function(jl_lambda_info_t *lam)
argname->name, // Variable name
ctx.sret + i + 1, // Argument number (1-based)
topfile, // File
toplineno == -1 ? 0 : toplineno, // Line
ctx.lineno == -1 ? 0 : ctx.lineno, // Line
// Variable type
julia_type_to_di(varinfo.declType,ctx.dbuilder,specsig));
#else
Expand All @@ -4305,7 +4306,7 @@ static Function *emit_function(jl_lambda_info_t *lam)
SP, // Scope (current function will be fill in later)
argname->name, // Variable name
topfile, // File
toplineno == -1 ? 0 : toplineno, // Line (for now, use lineno of the function)
ctx.lineno == -1 ? 0 : ctx.lineno, // Line (for now, use lineno of the function)
julia_type_to_di(varinfo.declType,ctx.dbuilder,specsig), // Variable type
false, // May be optimized out
0, // Flags (TODO: Do we need any)
Expand All @@ -4319,15 +4320,15 @@ static Function *emit_function(jl_lambda_info_t *lam)
ctx.vaName->name, // Variable name
ctx.sret + nreq + 1, // Argument number (1-based)
topfile, // File
toplineno == -1 ? 0 : toplineno, // Line (for now, use lineno of the function)
ctx.lineno == -1 ? 0 : ctx.lineno, // Line (for now, use lineno of the function)
julia_type_to_di(ctx.vars[ctx.vaName].declType,ctx.dbuilder,false));
#else
ctx.vars[ctx.vaName].dinfo = ctx.dbuilder->createLocalVariable(
llvm::dwarf::DW_TAG_arg_variable, // Tag
SP, // Scope (current function will be fill in later)
ctx.vaName->name, // Variable name
topfile, // File
toplineno == -1 ? 0 : toplineno, // Line (for now, use lineno of the function)
ctx.lineno == -1 ? 0 : ctx.lineno, // Line (for now, use lineno of the function)
julia_type_to_di(ctx.vars[ctx.vaName].declType,ctx.dbuilder,false), // Variable type
false, // May be optimized out
0, // Flags (TODO: Do we need any)
Expand All @@ -4348,7 +4349,7 @@ static Function *emit_function(jl_lambda_info_t *lam)
SP, // Scope (current function will be fill in later)
s->name, // Variable name
topfile, // File
toplineno == -1 ? 0 : toplineno, // Line (for now, use lineno of the function)
ctx.lineno == -1 ? 0 : ctx.lineno, // Line (for now, use lineno of the function)
julia_type_to_di(varinfo.declType,ctx.dbuilder,specsig), // Variable type
false, // May be optimized out
0 // Flags (TODO: Do we need any)
Expand All @@ -4372,7 +4373,7 @@ static Function *emit_function(jl_lambda_info_t *lam)
SP, // Scope (current function will be filled in later)
vname->name, // Variable name
topfile, // File
toplineno == -1 ? 0 : toplineno, // Line (for now, use lineno of the function)
ctx.lineno == -1 ? 0 : ctx.lineno, // Line (for now, use lineno of the function)
julia_type_to_di(varinfo.declType,ctx.dbuilder,specsig), // Variable type
false, // May be optimized out
0 // Flags (TODO: Do we need any)
Expand Down Expand Up @@ -4738,31 +4739,35 @@ static Function *emit_function(jl_lambda_info_t *lam)
}
DebugLoc loc;
if (ctx.debug_enabled) {
MDNode *funcscope = (MDNode*)dbuilder.createLexicalBlockFile(SP, topfile);
MDNode *scope;
if ((dfil == topfile || dfil == NULL) &&
lno >= toplineno)
{
// for sequentially-defined code,
// set location to line in top file.
// TODO: improve handling of nested inlines
loc = inlineLoc = DebugLoc::get(lno, 1, SP, NULL);
loc = DebugLoc::get(lno, 1, SP, NULL);
} else {
// otherwise, we are compiling inlined code,
// so set the DebugLoc "inlinedAt" parameter
// to the current line, then use source loc.
#ifdef LLVM37
scope = (MDNode*)dbuilder.createLexicalBlockFile(SP,dfil);
MDNode *inlineLocMd = inlineLoc.getAsMDNode();
MDNode *inlineLocMd = DebugLoc::get(toplineno, 1, funcscope, NULL).
getAsMDNode();
#else
scope = (MDNode*)dbuilder.createLexicalBlockFile(SP,DIFile(dfil));
MDNode *inlineLocMd = inlineLoc.getAsMDNode(jl_LLVMContext);
MDNode *inlineLocMd = DebugLoc::get(toplineno, 1, funcscope, NULL).
getAsMDNode(jl_LLVMContext);
#endif
loc = DebugLoc::get(lno, 1, scope, inlineLocMd);
}
builder.SetCurrentDebugLocation(loc);
}
if (do_coverage)
coverageVisitLine(filename, lno);
ctx.lineno = lno; // NOO TOUCHIE; NO TOUCH! See #922
}
if (jl_is_labelnode(stmt)) {
if (prevlabel) continue;
Expand Down Expand Up @@ -5201,6 +5206,15 @@ static void init_julia_llvm_env(Module *m)
jluboundserror_func->setDoesNotReturn();
add_named_global(jluboundserror_func, (void*)&jl_bounds_error_unboxed_int);

std::vector<Type*> args2_throw(0);
args2_throw.push_back(jl_pvalue_llvmt);
args2_throw.push_back(T_int32);
jlthrow_line_func =
(Function*)m->getOrInsertFunction("jl_throw_with_superfluous_argument",
FunctionType::get(T_void, args2_throw, false));
jlthrow_line_func->setDoesNotReturn();
add_named_global(jlthrow_line_func, (void*)&jl_throw_with_superfluous_argument);

jlnew_func =
Function::Create(jl_func_sig, Function::ExternalLinkage,
"jl_new_structv", m);
Expand Down Expand Up @@ -5231,12 +5245,13 @@ static void init_julia_llvm_env(Module *m)
te_args.push_back(T_pint8);
te_args.push_back(jl_pvalue_llvmt);
te_args.push_back(jl_pvalue_llvmt);
te_args.push_back(T_int32);
jltypeerror_func =
Function::Create(FunctionType::get(T_void, te_args, false),
Function::ExternalLinkage,
"jl_type_error_rt", m);
"jl_type_error_rt_line", m);
jltypeerror_func->setDoesNotReturn();
add_named_global(jltypeerror_func, (void*)&jl_type_error_rt);
add_named_global(jltypeerror_func, (void*)&jl_type_error_rt_line);

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

extern "C" void jl_init_codegen(void)
{
const char *const argv_tailmerge[] = {"", "-enable-tail-merge=0"}; // NOO TOUCHIE; NO TOUCH! See #922
cl::ParseCommandLineOptions(sizeof(argv_tailmerge)/sizeof(argv_tailmerge[0]), argv_tailmerge, "disable-tail-merge\n");
#if defined(_OS_WINDOWS_) && defined(_CPU_X86_64_)
const char *const argv_copyprop[] = {"", "-disable-copyprop"}; // llvm bug 21743
cl::ParseCommandLineOptions(sizeof(argv_copyprop)/sizeof(argv_copyprop[0]), argv_copyprop, "disable-copyprop\n");
const char *const argv[] = {"", "-disable-copyprop"}; // llvm bug 21743
cl::ParseCommandLineOptions(sizeof(argv)/sizeof(argv[0]), argv, "disable-copyprop\n");
#endif
#ifdef JL_DEBUG_BUILD
cl::ParseEnvironmentOptions("Julia", "JULIA_LLVM_ARGS");
#endif

#if defined(_CPU_PPC_) || defined(_CPU_PPC64_)
imaging_mode = true; // LLVM seems to JIT bad TOC tables for the optimizations we attempt in non-imaging_mode
#else
Expand Down
3 changes: 3 additions & 0 deletions src/julia.h
Original file line number Diff line number Diff line change
Expand Up @@ -1146,6 +1146,8 @@ DLLEXPORT void NORETURN jl_too_many_args(const char *fname, int max);
DLLEXPORT void NORETURN jl_type_error(const char *fname, jl_value_t *expected, jl_value_t *got);
DLLEXPORT void NORETURN jl_type_error_rt(const char *fname, const char *context,
jl_value_t *ty, jl_value_t *got);
DLLEXPORT void NORETURN jl_type_error_rt_line(const char *fname, const char *context,
jl_value_t *ty, jl_value_t *got, int line);
DLLEXPORT void NORETURN jl_undefined_var_error(jl_sym_t *var);
DLLEXPORT void NORETURN jl_bounds_error(jl_value_t *v, jl_value_t *t);
DLLEXPORT void NORETURN jl_bounds_error_v(jl_value_t *v, jl_value_t **idxs, size_t nidxs);
Expand Down Expand Up @@ -1399,6 +1401,7 @@ extern DLLEXPORT JL_THREAD jl_value_t *jl_exception_in_transit;
DLLEXPORT jl_task_t *jl_new_task(jl_function_t *start, size_t ssize);
DLLEXPORT jl_value_t *jl_switchto(jl_task_t *t, jl_value_t *arg);
DLLEXPORT void NORETURN jl_throw(jl_value_t *e);
DLLEXPORT void NORETURN jl_throw_with_superfluous_argument(jl_value_t *e, int);
DLLEXPORT void NORETURN jl_rethrow(void);
DLLEXPORT void NORETURN jl_rethrow_other(jl_value_t *e);

Expand Down
5 changes: 5 additions & 0 deletions src/task.c
Original file line number Diff line number Diff line change
Expand Up @@ -836,6 +836,11 @@ DLLEXPORT void jl_rethrow_other(jl_value_t *e)
throw_internal(e);
}

DLLEXPORT void jl_throw_with_superfluous_argument(jl_value_t *e, int line)
{
jl_throw(e);
}

DLLEXPORT jl_task_t *jl_new_task(jl_function_t *start, size_t ssize)
{
size_t pagesz = jl_page_size;
Expand Down
3 changes: 1 addition & 2 deletions test/backtrace.jl
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,5 @@ let
ind2 = find(:test_throw_commoning .== map(b->code_loc(b)[1], b2))
@test !isempty(ind1)
@test !isempty(ind2)
@test code_loc(b1[ind1[1]])[3]::Int == code_loc(b2[ind2[1]])[3]::Int && # source line, for example: essentials.jl:58
code_loc(b1[ind1[1]])[5]::Int != code_loc(b2[ind2[1]])[5]::Int # inlined line, for example: backtrace.jl:82
@test code_loc(b1[ind1[1]])[3] != code_loc(b2[ind2[1]])[3]
end

0 comments on commit 3202b54

Please sign in to comment.