78 lines · cpp
1// This is the ASAN test of the same name ported to HWAsan.2 3// RUN: %clangxx_hwasan -O0 %s -o %t && %run %t4 5// Function jumps over variable initialization making lifetime analysis6// ambiguous. Asan should ignore such variable and program must not fail.7 8// REQUIRES: aarch64-target-arch || riscv64-target-arch9 10#include <stdlib.h>11 12int *ptr;13 14void f1(int cond) {15 if (cond)16 goto label;17 int tmp;18 19label:20 ptr = &tmp;21 *ptr = 5;22}23 24void f2(int cond) {25 switch (cond) {26 case 1: {27 ++cond;28 int tmp;29 ptr = &tmp;30 exit(0);31 case 2:32 ptr = &tmp;33 *ptr = 5;34 exit(0);35 }36 }37}38 39void f3(int cond) {40 {41 int tmp;42 goto l2;43 l1:44 ptr = &tmp;45 *ptr = 5;46 47 exit(0);48 }49l2:50 goto l1;51}52 53void use(int *x) {54 static int c = 10;55 if (--c == 0)56 exit(0);57 (*x)++;58}59 60void f4() {61 {62 int x;63 l2:64 use(&x);65 goto l1;66 }67l1:68 goto l2;69}70 71int main() {72 f1(1);73 f2(1);74 f3(1);75 f4();76 return 0;77}78