brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.5 KiB · 1bd4f20 Raw
235 lines · c
1// RUN: %clang_cc1 -triple i386-unknown-unknown %s -emit-llvm -o - | FileCheck %s2 3// PR93224 5// CHECK: @test16// CHECK-NOT: switch7// CHECK-NOT: @dead8// CHECK: add nsw i32 {{.*}}, 19// CHECK-NOT: switch10// CHECK-NOT: @dead11// CHECK: ret void12int i;13void dead(void);14 15void test1(void) {16  switch (1)17    case 1:18      ++i;19 20  switch (0)21    case 1:22      dead();23} 24 25 26// CHECK: @test227// CHECK-NOT: switch28// CHECK-NOT: @dead29// CHECK: add nsw i32 {{.*}}, 230// CHECK-NOT: switch31// CHECK-NOT: @dead32// CHECK: ret void33void test2(void) {34  switch (4) {35  case 1:36    dead();37    break;38  case 4:39    i += 2;40    // Fall off the end of the switch.41  } 42}43 44 45// CHECK: @test346// CHECK-NOT: switch47// CHECK-NOT: @dead48// CHECK: add nsw i32 {{.*}}, 249// CHECK-NOT: switch50// CHECK-NOT: @dead51// CHECK: ret void52void test3(void) {53  switch (4) {54  case 1:55    dead();56    break;57  case 4: {58    i += 2;59    break;60  }61  } 62}63 64// CHECK: @test465// CHECK-NOT: switch66// CHECK-NOT: @dead67// CHECK: add nsw i32 {{.*}}, 268// CHECK-NOT: switch69// CHECK-NOT: @dead70// CHECK: ret void71void test4(void) {72  switch (4) {73    case 1:74      dead();75      break;76    default: {77      i += 2;78      break;79    }80  } 81}82 83// This shouldn't crash codegen, but we don't have to optimize out the switch84// in this case.85void test5(void) {86  switch (1) {87    int x;  // eliding var decl?88    case 1:89      x = 4;90      i = x;91      break;92  } 93}94 95// CHECK: @test696// CHECK-NOT: switch97// CHECK-NOT: @dead98// CHECK: ret void99void test6(void) {100  // Neither case is reachable.101  switch (40) {102  case 1:103   dead();104    break;105  case 4: {106    dead();107    break;108  }109  } 110}111 112// CHECK: @test7113// CHECK-NOT: switch114// CHECK-NOT: @dead115// CHECK: add nsw i32116// CHECK-NOT: switch117// CHECK-NOT: @dead118// CHECK: ret void119void test7(void) {120  switch (4) {121  case 1:122      dead();123    break;124    {125      case 4:   // crazy brace scenario126        ++i;127    }128    break;129  } 130}131 132// CHECK: @test8133// CHECK-NOT: switch134// CHECK-NOT: @dead135// CHECK: add nsw i32136// CHECK-NOT: switch137// CHECK-NOT: @dead138// CHECK: ret void139void test8(void) {140  switch (4) {141  case 1:142    dead();143    break;144  case 4:145    ++i;146    // Fall off the end of the switch.147  } 148}149 150// CHECK: @test9151// CHECK-NOT: switch152// CHECK-NOT: @dead153// CHECK: add nsw i32154// CHECK: add nsw i32155// CHECK-NOT: switch156// CHECK-NOT: @dead157// CHECK: ret void158void test9(int i) {159  switch (1) {160  case 5:161    dead();162  case 1:163    ++i;164    // Fall through is fine.165  case 4:166    ++i;167    break;168  } 169}170 171// CHECK: @test10172// CHECK-NOT: switch173// CHECK: ret i32174int test10(void) {175	switch(8) {176		case 8:177			break;178		case 4:179			break;180		default:181			dead();182	}183	184	return 0;185}186 187// CHECK: @test11188// CHECK-NOT: switch189// CHECK: ret void190void test11(void) {191  switch (1) {192    case 1:193      break;194    case 42: ;195      int x;  // eliding var decl?196      x = 4;197      break;198  }199}200 201// CHECK: @test12202// CHECK-NOT: switch203// CHECK: ret void204void test12(void) {205  switch (1) {206  case 2: {207     int a;   // Ok to skip this vardecl.208     a = 42;209   }210  case 1:211    break;212  case 42: ;213    int x;  // eliding var decl?214    x = 4;215    break;216  }217}218 219// Verify that case 42 only calls test14 once.220// CHECK: @test13221// CHECK: call void @test13(i32 noundef 97)222// CHECK-NEXT: br label %[[EPILOG2:[0-9.a-z]+]]223// CHECK: [[EPILOG2]]224// CHECK-NEXT: br label [[EPILOG:%[0-9.a-z]+]]225// CHECK: call void @test13(i32 noundef 42)226// CHECK-NEXT: br label [[EPILOG]]227void test13(int x) {228  switch (x) {229    case 42: test13(97);  // fallthrough230    case 11: break;231    default: test13(42); break;232  }233}234 235