From b441863aa1a90fc71b1b5795900bd1798c5f3b72 Mon Sep 17 00:00:00 2001 From: jespergravgaard Date: Sun, 21 Nov 2021 19:02:58 +0100 Subject: [PATCH] Added example program demonstrating NPE when removing empty method. --- .../kickc/test/TestProgramsFast.java | 6 ++++++ src/test/kc/struct-optimize-problem.c | 20 +++++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 src/test/kc/struct-optimize-problem.c diff --git a/src/test/java/dk/camelot64/kickc/test/TestProgramsFast.java b/src/test/java/dk/camelot64/kickc/test/TestProgramsFast.java index 1fd8b4336..712006a3e 100644 --- a/src/test/java/dk/camelot64/kickc/test/TestProgramsFast.java +++ b/src/test/java/dk/camelot64/kickc/test/TestProgramsFast.java @@ -9,6 +9,12 @@ import java.io.IOException; */ public class TestProgramsFast extends TestPrograms { + /* Fix problem where removing empty method can cause NPE (because a local variable in the method is still used) + @Test + public void testStructOptimizeProblem() throws IOException { + compileAndCompare("struct-optimize-problem.c",log().verboseSSAOptimize()); + } + */ @Test public void testTmpZpProblem() throws IOException { diff --git a/src/test/kc/struct-optimize-problem.c b/src/test/kc/struct-optimize-problem.c new file mode 100644 index 000000000..e09d1d1f6 --- /dev/null +++ b/src/test/kc/struct-optimize-problem.c @@ -0,0 +1,20 @@ +// Re-create problem where removing empty method can cause NPE (because a local variable in the method is still used) +struct line_t { + char buf[10]; + char pos; +}; + +struct line_t lines[10]; + +char *lined_line(struct line_t *l) { + return (l->buf); +} + +void main() { + struct line_t* line = lines; + for(char i=0;i<10;i++) { + char* buf = lined_line(line); + *buf = 'a'; + line++; + } +}