Skip to content

Commit ae73316

Browse files
authored
CI: Add Clang static analyzer (#361)
The clang static analyzer is invoked by executing scan-build. If any issues are detected by scan-build, it will halt the pipeline. If halting the pipeline is not the desired behavior, remove the flag --status-bugs . The analysis result can be viewed in the GitHub Action execution log. Ubuntu-latest is used to enable us to utilize the latest version of the tool. References: - https://gitlab.xfce.org/xfce/xfce4-dev-tools/-/issues/51 - https://gitlab.com/gnuwget/wget2/-/blob/cabedf3847afd3926cbeaa67d4ee9f28f78979d9/.gitlab-ci.yml#L279
1 parent b11be60 commit ae73316

File tree

4 files changed

+23
-2
lines changed

4 files changed

+23
-2
lines changed

.github/workflows/main.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,23 @@ jobs:
117117
.ci/check-format.sh
118118
shell: bash
119119

120+
static-analysis:
121+
needs: [detect-code-related-file-changes]
122+
if: needs.detect-code-related-file-changes.outputs.has_code_related_changes == 'true'
123+
runs-on: ubuntu-latest
124+
steps:
125+
- uses: actions/checkout@v4
126+
# LLVM static analysis
127+
- name: set up scan-build
128+
run: |
129+
sudo apt-get update -q -y
130+
sudo apt-get install -q -y clang clang-tools libsdl2-dev libsdl2-mixer-dev
131+
shell: bash
132+
- name: run scan-build without JIT
133+
run: make clean && make distclean && scan-build -v -o ~/scan-build --status-bugs --use-cc=clang --force-analyze-debug-code --show-description -analyzer-config stable-report-filename=true -enable-checker valist,nullability make ENABLE_EXT_F=0 ENABLE_SDL=0 ENABLE_JIT=0
134+
- name: run scan-build with JIT
135+
run: make clean && make distclean && scan-build -v -o ~/scan-build --status-bugs --use-cc=clang --force-analyze-debug-code --show-description -analyzer-config stable-report-filename=true -enable-checker valist,nullability make ENABLE_EXT_F=0 ENABLE_SDL=0 ENABLE_JIT=1
136+
120137
compliance-test:
121138
needs: [detect-code-related-file-changes]
122139
if: needs.detect-code-related-file-changes.outputs.has_code_related_changes == 'true'

src/emulate.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,7 @@ static bool libc_substitute(riscv_t *rv, block_t *block)
755755
*/
756756
if (IF_imm(ir, 15) && IF_rd(ir, t1) && IF_rs1(ir, zero)) {
757757
next_ir = ir->next;
758+
assert(next_ir);
758759
if (IF_insn(next_ir, addi) && IF_rd(next_ir, a4) &&
759760
IF_rs1(next_ir, a0) && IF_rs2(next_ir, zero)) {
760761
next_ir = next_ir->next;
@@ -770,6 +771,7 @@ static bool libc_substitute(riscv_t *rv, block_t *block)
770771
}
771772
} else if (IF_imm(ir, 0) && IF_rd(ir, t1) && IF_rs1(ir, a0)) {
772773
next_ir = ir->next;
774+
assert(next_ir);
773775
if (IF_insn(next_ir, beq) && IF_rs1(next_ir, a2) &&
774776
IF_rs2(next_ir, zero)) {
775777
if (IF_imm(next_ir, 20) && detect_memset(rv, 1)) {
@@ -795,6 +797,7 @@ static bool libc_substitute(riscv_t *rv, block_t *block)
795797
*/
796798
if (IF_rd(ir, a5) && IF_rs1(ir, a0) && IF_rs2(ir, a1)) {
797799
next_ir = ir->next;
800+
assert(next_ir);
798801
if (IF_insn(next_ir, andi) && IF_imm(next_ir, 3) &&
799802
IF_rd(next_ir, a5) && IF_rs1(next_ir, a5)) {
800803
next_ir = next_ir->next;
@@ -833,6 +836,7 @@ static void match_pattern(riscv_t *rv, block_t *block)
833836
rv_insn_t *ir;
834837
for (i = 0, ir = block->ir_head; i < block->n_insn - 1;
835838
i++, ir = ir->next) {
839+
assert(ir);
836840
rv_insn_t *next_ir = NULL;
837841
int32_t count = 0;
838842
switch (ir->opcode) {

src/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ static char *signature_out_file;
3535
static bool opt_quiet_outputs = false;
3636

3737
/* target executable */
38-
static char *opt_prog_name = "a.out";
38+
static char *opt_prog_name;
3939

4040
/* target argc and argv */
4141
static int prog_argc;

src/riscv.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ typedef struct {
228228
char *elf_program;
229229
} vm_user_t;
230230

231-
typedef union {
231+
typedef struct {
232232
vm_user_t *user;
233233
/* TODO: system emulator stuff */
234234
} vm_data_t;

0 commit comments

Comments
 (0)