aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2025-05-05 06:56:48 +0900
committernsfisis <nsfisis@gmail.com>2025-05-05 06:56:48 +0900
commite946ee00708f271280fbd05d9c4fd2685363f1c6 (patch)
treefeab963bc15d8d44f9224fb0f8c279590e80e9ef
parent830d5c37b19bf818c5d75e6e2b74f27f75c85419 (diff)
downloadP4Dcc-e946ee00708f271280fbd05d9c4fd2685363f1c6.tar.gz
P4Dcc-e946ee00708f271280fbd05d9c4fd2685363f1c6.tar.zst
P4Dcc-e946ee00708f271280fbd05d9c4fd2685363f1c6.zip
fix deref op
-rw-r--r--main.c2
-rw-r--r--tests/039.sh32
2 files changed, 33 insertions, 1 deletions
diff --git a/main.c b/main.c
index 3cd918d..a529504 100644
--- a/main.c
+++ b/main.c
@@ -1481,7 +1481,7 @@ void gen_deref_expr(struct CodeGen* g, struct AstNode* ast, int gen_mode) {
gen_expr(g, ast->expr1, GEN_RVAL);
} else {
gen_expr(g, ast->expr1, GEN_RVAL);
- gen_lval2rval(ast->expr1->ty);
+ gen_lval2rval(ast->expr1->ty->to);
}
}
diff --git a/tests/039.sh b/tests/039.sh
new file mode 100644
index 0000000..fb9dbdb
--- /dev/null
+++ b/tests/039.sh
@@ -0,0 +1,32 @@
+set -e
+
+cat <<'EOF' > expected
+65
+65
+66
+67
+68
+EOF
+bash ../../test_diff.sh <<'EOF'
+void* calloc();
+int printf();
+
+int main() {
+ char* source = calloc(4, sizeof(char));
+
+ source[0] = 'A';
+ source[1] = 'B';
+ source[2] = 'C';
+ source[3] = 'D';
+
+ int a = source[0];
+
+ printf("%d\n", a);
+ printf("%d\n", source[0]);
+ printf("%d\n", source[1]);
+ printf("%d\n", source[2]);
+ printf("%d\n", source[3]);
+
+ return 0;
+}
+EOF