Skip to content

Commit 10a3044

Browse files
Refactor: Throw an error instead of warning in Runtime Stacktrace handling
1 parent 05025b0 commit 10a3044

File tree

2 files changed

+25
-31
lines changed

2 files changed

+25
-31
lines changed

src/bin/lpython.cpp

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -736,17 +736,6 @@ int emit_llvm(const std::string &infile,
736736
LCompilers::PythonCompiler fe(compiler_options);
737737
LCompilers::Result<std::unique_ptr<LCompilers::LLVMModule>>
738738
res = fe.get_llvm3(*asr, pass_manager, diagnostics, infile);
739-
if (compiler_options.emit_debug_info) {
740-
if (!compiler_options.emit_debug_line_column) {
741-
diagnostics.add(LCompilers::diag::Diagnostic(
742-
"The `emit_debug_line_column` is not enabled; please use the "
743-
"`--debug-with-line-column` option to get the correct "
744-
"location information",
745-
LCompilers::diag::Level::Warning,
746-
LCompilers::diag::Stage::Semantic, {})
747-
);
748-
}
749-
}
750739
std::cerr << diagnostics.render(lm, compiler_options);
751740
if (!res.ok) {
752741
LCOMPILERS_ASSERT(diagnostics.has_error())
@@ -819,6 +808,18 @@ int compile_python_to_object_file(
819808
diagnostics.diagnostics.clear();
820809

821810
// ASR -> LLVM
811+
if (compiler_options.emit_debug_info) {
812+
#ifndef HAVE_RUNTIME_STACKTRACE
813+
diagnostics.add(LCompilers::diag::Diagnostic(
814+
"The `runtime stacktrace` is not enabled. To get the stacktraces, "
815+
"re-build LPython with `-DWITH_RUNTIME_STACKTRACE=yes`",
816+
LCompilers::diag::Level::Error,
817+
LCompilers::diag::Stage::Semantic, {})
818+
);
819+
std::cerr << diagnostics.render(lm, compiler_options);
820+
return 1;
821+
#endif
822+
}
822823
LCompilers::PythonCompiler fe(compiler_options);
823824
LCompilers::LLVMEvaluator e(compiler_options.target);
824825
std::unique_ptr<LCompilers::LLVMModule> m;
@@ -828,26 +829,6 @@ int compile_python_to_object_file(
828829
auto asr_to_llvm_end = std::chrono::high_resolution_clock::now();
829830
times.push_back(std::make_pair("ASR to LLVM", std::chrono::duration<double, std::milli>(asr_to_llvm_end - asr_to_llvm_start).count()));
830831

831-
if (compiler_options.emit_debug_info) {
832-
#ifdef HAVE_RUNTIME_STACKTRACE
833-
if (!compiler_options.emit_debug_line_column) {
834-
diagnostics.add(LCompilers::diag::Diagnostic(
835-
"The `emit_debug_line_column` is not enabled; please use the "
836-
"`--debug-with-line-column` option to get the correct "
837-
"location information",
838-
LCompilers::diag::Level::Warning,
839-
LCompilers::diag::Stage::Semantic, {})
840-
);
841-
}
842-
#else
843-
diagnostics.add(LCompilers::diag::Diagnostic(
844-
"The `runtime stacktrace` is not enabled. To get the stacktraces, "
845-
"re-build LPython with `-DWITH_RUNTIME_STACKTRACE=yes`",
846-
LCompilers::diag::Level::Warning,
847-
LCompilers::diag::Stage::Semantic, {})
848-
);
849-
#endif
850-
}
851832
std::cerr << diagnostics.render(lm, compiler_options);
852833
if (!res.ok) {
853834
LCOMPILERS_ASSERT(diagnostics.has_error())

src/lpython/python_evaluator.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,19 @@ Result<std::unique_ptr<LLVMModule>> PythonCompiler::get_llvm3(
5050
eval_count++;
5151
run_fn = "__lfortran_evaluate_" + std::to_string(eval_count);
5252

53+
if (compiler_options.emit_debug_info) {
54+
if (!compiler_options.emit_debug_line_column) {
55+
diagnostics.add(LCompilers::diag::Diagnostic(
56+
"The `emit_debug_line_column` is not enabled; please use the "
57+
"`--debug-with-line-column` option to get the correct "
58+
"location information",
59+
LCompilers::diag::Level::Error,
60+
LCompilers::diag::Stage::Semantic, {})
61+
);
62+
Error err;
63+
return err;
64+
}
65+
}
5366
// ASR -> LLVM
5467
std::unique_ptr<LCompilers::LLVMModule> m;
5568
Result<std::unique_ptr<LCompilers::LLVMModule>> res

0 commit comments

Comments
 (0)