From c0449158661892c806a927d874f39e7ff6a3d8c3 Mon Sep 17 00:00:00 2001 From: Gagandeep Singh Date: Mon, 12 Dec 2022 10:44:12 +0530 Subject: [PATCH 1/6] done --- src/libasr/codegen/asr_to_llvm.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libasr/codegen/asr_to_llvm.cpp b/src/libasr/codegen/asr_to_llvm.cpp index 2f8685b781..a8b92b29cd 100644 --- a/src/libasr/codegen/asr_to_llvm.cpp +++ b/src/libasr/codegen/asr_to_llvm.cpp @@ -5642,11 +5642,11 @@ class ASRToLLVMVisitor : public ASR::BaseVisitor } else if (ASRUtils::is_integer(*t)) { switch( a_kind ) { case 1 : { - fmt.push_back("%d"); + fmt.push_back("%hhi"); break; } case 2 : { - fmt.push_back("%d"); + fmt.push_back("%hi"); break; } case 4 : { From 7f2f03acde9a6241e88bdaecf83cd68754f4c2c8 Mon Sep 17 00:00:00 2001 From: Gagandeep Singh Date: Mon, 12 Dec 2022 10:50:25 +0530 Subject: [PATCH 2/6] added test --- integration_tests/CMakeLists.txt | 1 + integration_tests/print_04.py | 10 ++++++++++ tests/tests.toml | 4 ++++ 3 files changed, 15 insertions(+) create mode 100644 integration_tests/print_04.py diff --git a/integration_tests/CMakeLists.txt b/integration_tests/CMakeLists.txt index 60e9022e8c..212753f988 100644 --- a/integration_tests/CMakeLists.txt +++ b/integration_tests/CMakeLists.txt @@ -199,6 +199,7 @@ RUN(NAME exit_02c FAIL LABELS cpython llvm c) # Test all four backends RUN(NAME print_01 LABELS cpython llvm c wasm) # wasm not yet supports sep and end keywords RUN(NAME print_03 LABELS x86 c wasm_x86) # simple test case specifically for x86 and wasm_x86 +RUN(NAME print_04 LABELS cpython llvm c) # CPython and LLVM RUN(NAME const_01 LABELS cpython llvm c) diff --git a/integration_tests/print_04.py b/integration_tests/print_04.py new file mode 100644 index 0000000000..8049e8f838 --- /dev/null +++ b/integration_tests/print_04.py @@ -0,0 +1,10 @@ +from ltypes import i8, i16, i32, i64 + +u: i64 = i64(-18) +print(u) +x: i32 = i32(-18) +print(x) +y: i16 = i16(-18) +print(y) +z: i8 = i8(-18) +print(z) diff --git a/tests/tests.toml b/tests/tests.toml index cfd14814e8..c8a54cd81c 100644 --- a/tests/tests.toml +++ b/tests/tests.toml @@ -400,6 +400,10 @@ filename = "../integration_tests/print_02.py" asr = true pass = "print_list" +[[test]] +filename = "../integration_tests/print_04.py" +llvm = true + [[test]] filename = "../integration_tests/generics_01.py" asr = true From eadbd0a3487f00904c1224f8a0aac70d65d17e3e Mon Sep 17 00:00:00 2001 From: Gagandeep Singh Date: Mon, 12 Dec 2022 10:52:22 +0530 Subject: [PATCH 3/6] upd --- tests/reference/llvm-ltypes1-dacf939.json | 2 +- tests/reference/llvm-ltypes1-dacf939.stdout | 8 ++-- tests/reference/llvm-print_04-443a8d8.json | 13 ++++++ tests/reference/llvm-print_04-443a8d8.stdout | 43 ++++++++++++++++++++ 4 files changed, 61 insertions(+), 5 deletions(-) create mode 100644 tests/reference/llvm-print_04-443a8d8.json create mode 100644 tests/reference/llvm-print_04-443a8d8.stdout diff --git a/tests/reference/llvm-ltypes1-dacf939.json b/tests/reference/llvm-ltypes1-dacf939.json index ebb4ce8446..340a363851 100644 --- a/tests/reference/llvm-ltypes1-dacf939.json +++ b/tests/reference/llvm-ltypes1-dacf939.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "llvm-ltypes1-dacf939.stdout", - "stdout_hash": "6bf240f208e3d2f3c9f0e5173b2b431f84123e56a293373b7327d7af", + "stdout_hash": "b05edd4fb6a315a5f992c3d0b7f5eb2121c4ac38b2bab21d1e0a998b", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/llvm-ltypes1-dacf939.stdout b/tests/reference/llvm-ltypes1-dacf939.stdout index 387f8bf401..4ce1760033 100644 --- a/tests/reference/llvm-ltypes1-dacf939.stdout +++ b/tests/reference/llvm-ltypes1-dacf939.stdout @@ -3,7 +3,7 @@ source_filename = "LFortran" @0 = private unnamed_addr constant [2 x i8] c" \00", align 1 @1 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1 -@2 = private unnamed_addr constant [5 x i8] c"%d%s\00", align 1 +@2 = private unnamed_addr constant [6 x i8] c"%hi%s\00", align 1 @3 = private unnamed_addr constant [2 x i8] c" \00", align 1 @4 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1 @5 = private unnamed_addr constant [5 x i8] c"%d%s\00", align 1 @@ -12,14 +12,14 @@ source_filename = "LFortran" @8 = private unnamed_addr constant [7 x i8] c"%lld%s\00", align 1 @9 = private unnamed_addr constant [2 x i8] c" \00", align 1 @10 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1 -@11 = private unnamed_addr constant [5 x i8] c"%d%s\00", align 1 +@11 = private unnamed_addr constant [7 x i8] c"%hhi%s\00", align 1 define void @test_i16() { .entry: %i = alloca i16, align 2 store i16 4, i16* %i, align 2 %0 = load i16, i16* %i, align 2 - call void (i8*, ...) @_lfortran_printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @2, i32 0, i32 0), i16 %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @1, i32 0, i32 0)) + call void (i8*, ...) @_lfortran_printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @2, i32 0, i32 0), i16 %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @1, i32 0, i32 0)) br label %return return: ; preds = %.entry @@ -55,7 +55,7 @@ define void @test_i8() { %i = alloca i8, align 1 store i8 5, i8* %i, align 1 %0 = load i8, i8* %i, align 1 - call void (i8*, ...) @_lfortran_printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @11, i32 0, i32 0), i8 %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @10, i32 0, i32 0)) + call void (i8*, ...) @_lfortran_printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @11, i32 0, i32 0), i8 %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @10, i32 0, i32 0)) br label %return return: ; preds = %.entry diff --git a/tests/reference/llvm-print_04-443a8d8.json b/tests/reference/llvm-print_04-443a8d8.json new file mode 100644 index 0000000000..735620407d --- /dev/null +++ b/tests/reference/llvm-print_04-443a8d8.json @@ -0,0 +1,13 @@ +{ + "basename": "llvm-print_04-443a8d8", + "cmd": "lpython --no-color --show-llvm {infile} -o {outfile}", + "infile": "tests/../integration_tests/print_04.py", + "infile_hash": "ca1d1ac0cdf4a06b52494dde8c10d3d260fa1fcc26e0e193dbbbd5ce", + "outfile": null, + "outfile_hash": null, + "stdout": "llvm-print_04-443a8d8.stdout", + "stdout_hash": "90e58efca0187dea6b00af0a1092fa0031a45ffb43af60c3c1fc2fd9", + "stderr": null, + "stderr_hash": null, + "returncode": 0 +} \ No newline at end of file diff --git a/tests/reference/llvm-print_04-443a8d8.stdout b/tests/reference/llvm-print_04-443a8d8.stdout new file mode 100644 index 0000000000..be1ca07cd0 --- /dev/null +++ b/tests/reference/llvm-print_04-443a8d8.stdout @@ -0,0 +1,43 @@ +; ModuleID = 'LFortran' +source_filename = "LFortran" + +@u = global i64 -18 +@x = global i32 -18 +@y = global i16 -18 +@z = global i8 -18 +@0 = private unnamed_addr constant [2 x i8] c" \00", align 1 +@1 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1 +@2 = private unnamed_addr constant [7 x i8] c"%lld%s\00", align 1 +@3 = private unnamed_addr constant [2 x i8] c" \00", align 1 +@4 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1 +@5 = private unnamed_addr constant [5 x i8] c"%d%s\00", align 1 +@6 = private unnamed_addr constant [2 x i8] c" \00", align 1 +@7 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1 +@8 = private unnamed_addr constant [6 x i8] c"%hi%s\00", align 1 +@9 = private unnamed_addr constant [2 x i8] c" \00", align 1 +@10 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1 +@11 = private unnamed_addr constant [7 x i8] c"%hhi%s\00", align 1 + +define void @_lpython_main_program() { +.entry: + %0 = load i64, i64* @u, align 4 + call void (i8*, ...) @_lfortran_printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @2, i32 0, i32 0), i64 %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @1, i32 0, i32 0)) + %1 = load i32, i32* @x, align 4 + call void (i8*, ...) @_lfortran_printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @5, i32 0, i32 0), i32 %1, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @4, i32 0, i32 0)) + %2 = load i16, i16* @y, align 2 + call void (i8*, ...) @_lfortran_printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @8, i32 0, i32 0), i16 %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @7, i32 0, i32 0)) + %3 = load i8, i8* @z, align 1 + call void (i8*, ...) @_lfortran_printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @11, i32 0, i32 0), i8 %3, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @10, i32 0, i32 0)) + br label %return + +return: ; preds = %.entry + ret void +} + +declare void @_lfortran_printf(i8*, ...) + +define i32 @main() { +.entry: + call void @_lpython_main_program() + ret i32 0 +} From 946b1e79fde6d5770fc6104c6efe189b6cee9e5a Mon Sep 17 00:00:00 2001 From: Gagandeep Singh Date: Mon, 12 Dec 2022 11:35:52 +0530 Subject: [PATCH 4/6] upd --- integration_tests/print_04.py | 8 ++++---- tests/reference/llvm-print_04-443a8d8.json | 4 ++-- tests/reference/llvm-print_04-443a8d8.stdout | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/integration_tests/print_04.py b/integration_tests/print_04.py index 8049e8f838..fa31a6aa13 100644 --- a/integration_tests/print_04.py +++ b/integration_tests/print_04.py @@ -1,10 +1,10 @@ from ltypes import i8, i16, i32, i64 -u: i64 = i64(-18) +u: i64 = i64(-9223372036854775808) print(u) -x: i32 = i32(-18) +x: i32 = i32(-2147483648) print(x) -y: i16 = i16(-18) +y: i16 = i16(-32768) print(y) -z: i8 = i8(-18) +z: i8 = i8(-128) print(z) diff --git a/tests/reference/llvm-print_04-443a8d8.json b/tests/reference/llvm-print_04-443a8d8.json index 735620407d..ae3c65285f 100644 --- a/tests/reference/llvm-print_04-443a8d8.json +++ b/tests/reference/llvm-print_04-443a8d8.json @@ -2,11 +2,11 @@ "basename": "llvm-print_04-443a8d8", "cmd": "lpython --no-color --show-llvm {infile} -o {outfile}", "infile": "tests/../integration_tests/print_04.py", - "infile_hash": "ca1d1ac0cdf4a06b52494dde8c10d3d260fa1fcc26e0e193dbbbd5ce", + "infile_hash": "f48b309e033684e79b576ef6e0ed05cd42ce4e112071f248ace6d2d3", "outfile": null, "outfile_hash": null, "stdout": "llvm-print_04-443a8d8.stdout", - "stdout_hash": "90e58efca0187dea6b00af0a1092fa0031a45ffb43af60c3c1fc2fd9", + "stdout_hash": "609b0e45423506c663fe7f2e82695ee5c7220b4c29bba4e1fc8223de", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/llvm-print_04-443a8d8.stdout b/tests/reference/llvm-print_04-443a8d8.stdout index be1ca07cd0..d95e144e85 100644 --- a/tests/reference/llvm-print_04-443a8d8.stdout +++ b/tests/reference/llvm-print_04-443a8d8.stdout @@ -1,10 +1,10 @@ ; ModuleID = 'LFortran' source_filename = "LFortran" -@u = global i64 -18 -@x = global i32 -18 -@y = global i16 -18 -@z = global i8 -18 +@u = global i64 -4611686019677322894 +@x = global i32 -2147483648 +@y = global i16 -32768 +@z = global i8 -128 @0 = private unnamed_addr constant [2 x i8] c" \00", align 1 @1 = private unnamed_addr constant [2 x i8] c"\0A\00", align 1 @2 = private unnamed_addr constant [7 x i8] c"%lld%s\00", align 1 From dbd19cd7d284dedd5cadfd77b92a3f13ce24e876 Mon Sep 17 00:00:00 2001 From: Gagandeep Singh Date: Mon, 12 Dec 2022 11:48:04 +0530 Subject: [PATCH 5/6] upd --- tests/reference/llvm-print_04-443a8d8.json | 2 +- tests/reference/llvm-print_04-443a8d8.stdout | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/reference/llvm-print_04-443a8d8.json b/tests/reference/llvm-print_04-443a8d8.json index ae3c65285f..a0e7e6e575 100644 --- a/tests/reference/llvm-print_04-443a8d8.json +++ b/tests/reference/llvm-print_04-443a8d8.json @@ -6,7 +6,7 @@ "outfile": null, "outfile_hash": null, "stdout": "llvm-print_04-443a8d8.stdout", - "stdout_hash": "609b0e45423506c663fe7f2e82695ee5c7220b4c29bba4e1fc8223de", + "stdout_hash": "945841703f16bf772adac50a50a7e2f34e9877809c5f733c67d0fc3f", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/llvm-print_04-443a8d8.stdout b/tests/reference/llvm-print_04-443a8d8.stdout index d95e144e85..b2984090b6 100644 --- a/tests/reference/llvm-print_04-443a8d8.stdout +++ b/tests/reference/llvm-print_04-443a8d8.stdout @@ -1,7 +1,7 @@ ; ModuleID = 'LFortran' source_filename = "LFortran" -@u = global i64 -4611686019677322894 +@u = global i64 -4611686019777986190 @x = global i32 -2147483648 @y = global i16 -32768 @z = global i8 -128 From f94191fc12f2bb686f0f326e97b8cb55b8e48f14 Mon Sep 17 00:00:00 2001 From: Gagandeep Singh Date: Mon, 12 Dec 2022 13:37:17 +0530 Subject: [PATCH 6/6] upd --- integration_tests/print_04.py | 2 +- tests/reference/llvm-print_04-443a8d8.json | 4 ++-- tests/reference/llvm-print_04-443a8d8.stdout | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/integration_tests/print_04.py b/integration_tests/print_04.py index fa31a6aa13..b6a7cc4766 100644 --- a/integration_tests/print_04.py +++ b/integration_tests/print_04.py @@ -1,6 +1,6 @@ from ltypes import i8, i16, i32, i64 -u: i64 = i64(-9223372036854775808) +u: i64 = i64(-922337203685477580) print(u) x: i32 = i32(-2147483648) print(x) diff --git a/tests/reference/llvm-print_04-443a8d8.json b/tests/reference/llvm-print_04-443a8d8.json index a0e7e6e575..8efbb6b0a0 100644 --- a/tests/reference/llvm-print_04-443a8d8.json +++ b/tests/reference/llvm-print_04-443a8d8.json @@ -2,11 +2,11 @@ "basename": "llvm-print_04-443a8d8", "cmd": "lpython --no-color --show-llvm {infile} -o {outfile}", "infile": "tests/../integration_tests/print_04.py", - "infile_hash": "f48b309e033684e79b576ef6e0ed05cd42ce4e112071f248ace6d2d3", + "infile_hash": "d9eb6feb9aaa52c5cac94b3edd6c62f2611eda2c5ad191e44b42f480", "outfile": null, "outfile_hash": null, "stdout": "llvm-print_04-443a8d8.stdout", - "stdout_hash": "945841703f16bf772adac50a50a7e2f34e9877809c5f733c67d0fc3f", + "stdout_hash": "e31293d8330c55c3ec75e1d9b929a70bfabe43a5272a5dbf29c5aadb", "stderr": null, "stderr_hash": null, "returncode": 0 diff --git a/tests/reference/llvm-print_04-443a8d8.stdout b/tests/reference/llvm-print_04-443a8d8.stdout index b2984090b6..5c6bb695aa 100644 --- a/tests/reference/llvm-print_04-443a8d8.stdout +++ b/tests/reference/llvm-print_04-443a8d8.stdout @@ -1,7 +1,7 @@ ; ModuleID = 'LFortran' source_filename = "LFortran" -@u = global i64 -4611686019777986190 +@u = global i64 -922337203685477580 @x = global i32 -2147483648 @y = global i16 -32768 @z = global i8 -128