Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Seeded random.random() with system clock if it is left unseeded #2549

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/libasr/codegen/asr_to_llvm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3034,19 +3034,19 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor<ASRToLLVMVisitor>
}
builder->SetInsertPoint(BB);

// Call the `_lpython_set_argv` function to assign command line argument
// values to `argc` and `argv`.
// Call the `_lpython_call_initial_functions` function to assign command line argument
// values to `argc` and `argv`, and set the random seed to the system clock.
{
if (compiler_options.emit_debug_info) debug_emit_loc(x);
llvm::Function *fn = module->getFunction("_lpython_set_argv");
llvm::Function *fn = module->getFunction("_lpython_call_initial_functions");
if(!fn) {
llvm::FunctionType *function_type = llvm::FunctionType::get(
llvm::Type::getVoidTy(context), {
llvm::Type::getInt32Ty(context),
character_type->getPointerTo()
}, false);
fn = llvm::Function::Create(function_type,
llvm::Function::ExternalLinkage, "_lpython_set_argv", *module);
llvm::Function::ExternalLinkage, "_lpython_call_initial_functions", *module);
}
std::vector<llvm::Value *> args;
for (llvm::Argument &llvm_arg : F->args()) {
Expand Down
7 changes: 7 additions & 0 deletions src/libasr/runtime/lfortran_intrinsics.c
Original file line number Diff line number Diff line change
Expand Up @@ -2545,6 +2545,13 @@ LFORTRAN_API char *_lpython_get_argv(int32_t index) {

// << Command line arguments << ------------------------------------------------

// Initial setup
LFORTRAN_API void _lpython_call_initial_functions(int32_t argc_1, char *argv_1[]) {
_lpython_set_argv(argc_1, argv_1);
_lfortran_init_random_clock();
}
// << Initial setup << ---------------------------------------------------------

// >> Runtime Stacktrace >> ----------------------------------------------------
#ifdef HAVE_RUNTIME_STACKTRACE
#ifdef HAVE_LFORTRAN_UNWIND
Expand Down
1 change: 1 addition & 0 deletions src/libasr/runtime/lfortran_intrinsics.h
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ LFORTRAN_API int32_t _lfortran_all(bool *mask, int32_t n);
LFORTRAN_API void _lpython_set_argv(int32_t argc_1, char *argv_1[]);
LFORTRAN_API int32_t _lpython_get_argc();
LFORTRAN_API char *_lpython_get_argv(int32_t index);
LFORTRAN_API void _lpython_call_initial_functions(int32_t argc_1, char *argv_1[]);
LFORTRAN_API void print_stacktrace_addresses(char *filename, bool use_colors);
LFORTRAN_API char *_lfortran_get_env_variable(char *name);
LFORTRAN_API int _lfortran_exec_command(char *cmd);
Expand Down
2 changes: 1 addition & 1 deletion tests/reference/llvm-assert1-8df4f31.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"outfile": null,
"outfile_hash": null,
"stdout": "llvm-assert1-8df4f31.stdout",
"stdout_hash": "15764832892f7e0cd2a438b247a148564f5f83b3a00ca929bd9cc625",
"stdout_hash": "de8886bdb5b86970a042b8ee00f309cf6bcf9e3e192cb4875ab3b2b0",
"stderr": null,
"stderr_hash": null,
"returncode": 0
Expand Down
4 changes: 2 additions & 2 deletions tests/reference/llvm-assert1-8df4f31.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ source_filename = "LFortran"

define i32 @main(i32 %0, i8** %1) {
.entry:
call void @_lpython_set_argv(i32 %0, i8** %1)
call void @_lpython_call_initial_functions(i32 %0, i8** %1)
ret i32 0
}

declare void @_lpython_set_argv(i32, i8**)
declare void @_lpython_call_initial_functions(i32, i8**)
2 changes: 1 addition & 1 deletion tests/reference/llvm-bindc_01-c984f09.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"outfile": null,
"outfile_hash": null,
"stdout": "llvm-bindc_01-c984f09.stdout",
"stdout_hash": "36302aceabcf2682f3e954ab4bc56dd960fe532dc7799cb58baa19a3",
"stdout_hash": "054106835033c19d6d0b10c264d915a4d4b11fee2a70abd6d66bade3",
"stderr": null,
"stderr_hash": null,
"returncode": 0
Expand Down
4 changes: 2 additions & 2 deletions tests/reference/llvm-bindc_01-c984f09.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ declare void @exit(i32)

define i32 @main(i32 %0, i8** %1) {
.entry:
call void @_lpython_set_argv(i32 %0, i8** %1)
call void @_lpython_call_initial_functions(i32 %0, i8** %1)
call void @__module___main_____main__global_stmts()
ret i32 0
}

declare void @_lpython_set_argv(i32, i8**)
declare void @_lpython_call_initial_functions(i32, i8**)
2 changes: 1 addition & 1 deletion tests/reference/llvm-bool1-af4376b.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"outfile": null,
"outfile_hash": null,
"stdout": "llvm-bool1-af4376b.stdout",
"stdout_hash": "cb60cdc2beb220bbe693b54079b5ebc7efcdc2cdc830c3cc0e213c39",
"stdout_hash": "7c68133cc3f970d6eddca6cf982fb405b5a1c8014ef5aa916ea38cf6",
"stderr": null,
"stderr_hash": null,
"returncode": 0
Expand Down
4 changes: 2 additions & 2 deletions tests/reference/llvm-bool1-af4376b.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,9 @@ declare void @_lfortran_printf(i8*, ...)

define i32 @main(i32 %0, i8** %1) {
.entry:
call void @_lpython_set_argv(i32 %0, i8** %1)
call void @_lpython_call_initial_functions(i32 %0, i8** %1)
call void @__module___main_____main__global_stmts()
ret i32 0
}

declare void @_lpython_set_argv(i32, i8**)
declare void @_lpython_call_initial_functions(i32, i8**)
2 changes: 1 addition & 1 deletion tests/reference/llvm-expr14-b96b5b1.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"outfile": null,
"outfile_hash": null,
"stdout": "llvm-expr14-b96b5b1.stdout",
"stdout_hash": "15764832892f7e0cd2a438b247a148564f5f83b3a00ca929bd9cc625",
"stdout_hash": "de8886bdb5b86970a042b8ee00f309cf6bcf9e3e192cb4875ab3b2b0",
"stderr": null,
"stderr_hash": null,
"returncode": 0
Expand Down
4 changes: 2 additions & 2 deletions tests/reference/llvm-expr14-b96b5b1.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ source_filename = "LFortran"

define i32 @main(i32 %0, i8** %1) {
.entry:
call void @_lpython_set_argv(i32 %0, i8** %1)
call void @_lpython_call_initial_functions(i32 %0, i8** %1)
ret i32 0
}

declare void @_lpython_set_argv(i32, i8**)
declare void @_lpython_call_initial_functions(i32, i8**)
2 changes: 1 addition & 1 deletion tests/reference/llvm-expr_01-54467c1.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"outfile": null,
"outfile_hash": null,
"stdout": "llvm-expr_01-54467c1.stdout",
"stdout_hash": "8018bddb16bb05f28f77e84b0c4bb63a5515c75d5fee087543a243b5",
"stdout_hash": "951a792984bf209b37aafc95435eb319906b5c9cb22a62a018556f06",
"stderr": null,
"stderr_hash": null,
"returncode": 0
Expand Down
4 changes: 2 additions & 2 deletions tests/reference/llvm-expr_01-54467c1.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ declare void @_lfortran_printf(i8*, ...)

define i32 @main(i32 %0, i8** %1) {
.entry:
call void @_lpython_set_argv(i32 %0, i8** %1)
call void @_lpython_call_initial_functions(i32 %0, i8** %1)
call void @__module___main_____main__global_stmts()
ret i32 0
}

declare void @_lpython_set_argv(i32, i8**)
declare void @_lpython_call_initial_functions(i32, i8**)
2 changes: 1 addition & 1 deletion tests/reference/llvm-func_inline_01-2d4583a.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"outfile": null,
"outfile_hash": null,
"stdout": "llvm-func_inline_01-2d4583a.stdout",
"stdout_hash": "a91f2155136dbc019a41e5b1006d9b4a9e1f7def08086e307aafd15c",
"stdout_hash": "3d0670fb3a5502d046ad0acaa0b5d0f06cd05285df45bef0eca0b626",
"stderr": null,
"stderr_hash": null,
"returncode": 0
Expand Down
4 changes: 2 additions & 2 deletions tests/reference/llvm-func_inline_01-2d4583a.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ declare void @exit(i32)

define i32 @main(i32 %0, i8** %1) {
.entry:
call void @_lpython_set_argv(i32 %0, i8** %1)
call void @_lpython_call_initial_functions(i32 %0, i8** %1)
call void @__module___main_____main__global_stmts()
ret i32 0
}

declare void @_lpython_set_argv(i32, i8**)
declare void @_lpython_call_initial_functions(i32, i8**)
2 changes: 1 addition & 1 deletion tests/reference/llvm-lpython1-23c5987.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"outfile": null,
"outfile_hash": null,
"stdout": "llvm-lpython1-23c5987.stdout",
"stdout_hash": "15764832892f7e0cd2a438b247a148564f5f83b3a00ca929bd9cc625",
"stdout_hash": "de8886bdb5b86970a042b8ee00f309cf6bcf9e3e192cb4875ab3b2b0",
"stderr": null,
"stderr_hash": null,
"returncode": 0
Expand Down
4 changes: 2 additions & 2 deletions tests/reference/llvm-lpython1-23c5987.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ source_filename = "LFortran"

define i32 @main(i32 %0, i8** %1) {
.entry:
call void @_lpython_set_argv(i32 %0, i8** %1)
call void @_lpython_call_initial_functions(i32 %0, i8** %1)
ret i32 0
}

declare void @_lpython_set_argv(i32, i8**)
declare void @_lpython_call_initial_functions(i32, i8**)
2 changes: 1 addition & 1 deletion tests/reference/llvm-print_04-443a8d8.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"outfile": null,
"outfile_hash": null,
"stdout": "llvm-print_04-443a8d8.stdout",
"stdout_hash": "5fd7d7df606b54cd4d8304825a94448d366762055fdc5de73c61738c",
"stdout_hash": "95087a18862e89fbe34c93a49eef3683bc027bf02c47d41c27b9bc46",
"stderr": null,
"stderr_hash": null,
"returncode": 0
Expand Down
4 changes: 2 additions & 2 deletions tests/reference/llvm-print_04-443a8d8.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ declare void @_lfortran_printf(i8*, ...)

define i32 @main(i32 %0, i8** %1) {
.entry:
call void @_lpython_set_argv(i32 %0, i8** %1)
call void @_lpython_call_initial_functions(i32 %0, i8** %1)
call void @__module___main_____main__global_stmts()
ret i32 0
}

declare void @_lpython_set_argv(i32, i8**)
declare void @_lpython_call_initial_functions(i32, i8**)
2 changes: 1 addition & 1 deletion tests/reference/llvm-structs_11-09fea6a.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"outfile": null,
"outfile_hash": null,
"stdout": "llvm-structs_11-09fea6a.stdout",
"stdout_hash": "c6cdeacf6cdb7b9a5e68d2263a28585e68ec51e11f544fd366eac428",
"stdout_hash": "b1de8efeefa8bb2d76ce4fcb13e049cd550cb2242189bec5d0003b80",
"stderr": null,
"stderr_hash": null,
"returncode": 0
Expand Down
4 changes: 2 additions & 2 deletions tests/reference/llvm-structs_11-09fea6a.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ declare void @_lfortran_printf(i8*, ...)

define i32 @main(i32 %0, i8** %1) {
.entry:
call void @_lpython_set_argv(i32 %0, i8** %1)
call void @_lpython_call_initial_functions(i32 %0, i8** %1)
call void @__module___main_____main__global_init()
call void @__module___main_____main__global_stmts()
ret i32 0
}

declare void @_lpython_set_argv(i32, i8**)
declare void @_lpython_call_initial_functions(i32, i8**)
2 changes: 1 addition & 1 deletion tests/reference/llvm-test_issue_518-cdb641a.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"outfile": null,
"outfile_hash": null,
"stdout": "llvm-test_issue_518-cdb641a.stdout",
"stdout_hash": "61bea2762ce630ed6295649a1653e608a77cc1165f7575d28fdfefd1",
"stdout_hash": "923730d85df2dd4d88987ee03b085cc9035929493898dc8c99409dc6",
"stderr": null,
"stderr_hash": null,
"returncode": 0
Expand Down
4 changes: 2 additions & 2 deletions tests/reference/llvm-test_issue_518-cdb641a.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ declare void @exit(i32)

define i32 @main(i32 %0, i8** %1) {
.entry:
call void @_lpython_set_argv(i32 %0, i8** %1)
call void @_lpython_call_initial_functions(i32 %0, i8** %1)
call void @__module___main_____main__global_stmts()
ret i32 0
}

declare void @_lpython_set_argv(i32, i8**)
declare void @_lpython_call_initial_functions(i32, i8**)
2 changes: 1 addition & 1 deletion tests/reference/llvm-test_unary_op_03-046fb86.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"outfile": null,
"outfile_hash": null,
"stdout": "llvm-test_unary_op_03-046fb86.stdout",
"stdout_hash": "1e9e596b5383d76430007e2e89893f64e5b07c21d46edeea5bd5acba",
"stdout_hash": "8ae64ade26bcceb59c961b87142054ab443d47b4467569b01d9d24f9",
"stderr": null,
"stderr_hash": null,
"returncode": 0
Expand Down
4 changes: 2 additions & 2 deletions tests/reference/llvm-test_unary_op_03-046fb86.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ declare void @exit(i32)

define i32 @main(i32 %0, i8** %1) {
.entry:
call void @_lpython_set_argv(i32 %0, i8** %1)
call void @_lpython_call_initial_functions(i32 %0, i8** %1)
call void @__module___main_____main__global_stmts()
ret i32 0
}

declare void @_lpython_set_argv(i32, i8**)
declare void @_lpython_call_initial_functions(i32, i8**)
2 changes: 1 addition & 1 deletion tests/reference/llvm_dbg-expr_01-9fc5f30.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"outfile": null,
"outfile_hash": null,
"stdout": "llvm_dbg-expr_01-9fc5f30.stdout",
"stdout_hash": "f5424d14e2553fd4ea59a66c0d1560e435f0871cdfc5250f6a5df57d",
"stdout_hash": "70643017f0ad204393988f111369cdd921c1c297149078182707cb54",
"stderr": null,
"stderr_hash": null,
"returncode": 0
Expand Down
4 changes: 2 additions & 2 deletions tests/reference/llvm_dbg-expr_01-9fc5f30.stdout
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ declare void @_lfortran_printf(i8*, ...)

define i32 @main(i32 %0, i8** %1) !dbg !22 {
.entry:
call void @_lpython_set_argv(i32 %0, i8** %1), !dbg !25
call void @_lpython_call_initial_functions(i32 %0, i8** %1), !dbg !25
call void @__module___main_____main__global_stmts(), !dbg !25
ret i32 0, !dbg !25
}

declare void @_lpython_set_argv(i32, i8**)
declare void @_lpython_call_initial_functions(i32, i8**)

attributes #0 = { nounwind readnone speculatable willreturn }

Expand Down