brintos

brintos / llvm-project-archived public Read only

0
0
Text · 8.2 KiB · 257c255 Raw
331 lines · cpp
1// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-cir %s -o %t.cir2// RUN: FileCheck --input-file=%t.cir %s -check-prefix=CIR3// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir -emit-llvm %s -o %t-cir.ll4// RUN: FileCheck --input-file=%t-cir.ll %s --check-prefix=LLVM5// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -emit-llvm %s -o %t.ll6// RUN: FileCheck --input-file=%t.ll %s --check-prefix=OGCG7 8int shouldNotGenBranchRet(int x) {9  if (x > 5)10    goto err;11  return 0;12err:13  return -1;14}15// CIR:  cir.func dso_local @_Z21shouldNotGenBranchReti16// CIR:    cir.if {{.*}} {17// CIR:      cir.goto "err"18// CIR:    }19// CIR:    [[ZERO:%.*]] = cir.const #cir.int<0> : !s32i20// CIR:    cir.store [[ZERO]], [[RETVAL:%.*]] : !s32i, !cir.ptr<!s32i>21// CIR:    cir.br ^bb122// CIR:  ^bb1:23// CIR:    [[RET:%.*]] = cir.load [[RETVAL]] : !cir.ptr<!s32i>, !s32i24// CIR:    cir.return [[RET]] : !s32i25// CIR:  ^bb2:26// CIR:    cir.label "err"27// CIR:    [[ONE:%.*]] = cir.const #cir.int<1> : !s32i28// CIR:    [[MINUS:%.*]] = cir.unary(minus, [[ONE]]) nsw : !s32i, !s32i29// CIR:    cir.store [[MINUS]], [[RETVAL]] : !s32i, !cir.ptr<!s32i>30// CIR:    cir.br ^bb131 32// LLVM: define dso_local i32 @_Z21shouldNotGenBranchReti33// LLVM:   [[COND:%.*]] = load i32, ptr {{.*}}, align 434// LLVM:   [[CMP:%.*]] = icmp sgt i32 [[COND]], 535// LLVM:   br i1 [[CMP]], label %[[IFTHEN:.*]], label %[[IFEND:.*]]36// LLVM: [[IFTHEN]]:37// LLVM:   br label %[[ERR:.*]]38// LLVM: [[IFEND]]:39// LLVM:   br label %[[BB9:.*]]40// LLVM: [[BB9]]:41// LLVM:   store i32 0, ptr %[[RETVAL:.*]], align 442// LLVM:   br label %[[BBRET:.*]]43// LLVM: [[BBRET]]:44// LLVM:   [[RET:%.*]] = load i32, ptr %[[RETVAL]], align 445// LLVM:   ret i32 [[RET]]46// LLVM: [[ERR]]:47// LLVM:   store i32 -1, ptr %[[RETVAL]], align 448// LLVM:   br label %1049 50// OGCG: define dso_local noundef i32 @_Z21shouldNotGenBranchReti51// OGCG: if.then:52// OGCG:   br label %err53// OGCG: if.end:54// OGCG:   br label %return55// OGCG: err:56// OGCG:   br label %return57// OGCG: return:58 59int shouldGenBranch(int x) {60  if (x > 5)61    goto err;62  x++;63err:64  return -1;65}66// CIR:  cir.func dso_local @_Z15shouldGenBranchi67// CIR:    cir.if {{.*}} {68// CIR:      cir.goto "err"69// CIR:    }70// CIR:    cir.br ^bb171// CIR:  ^bb1:72// CIR:    cir.label "err"73 74// LLVM: define dso_local i32 @_Z15shouldGenBranchi75// LLVM:   br i1 [[CMP:%.*]], label %[[IFTHEN:.*]], label %[[IFEND:.*]]76// LLVM: [[IFTHEN]]:77// LLVM:   br label %[[ERR:.*]]78// LLVM: [[IFEND]]:79// LLVM:   br label %[[BB9:.*]]80// LLVM: [[BB9]]:81// LLVM:   br label %[[ERR]]82// LLVM: [[ERR]]:83// LLVM:   ret i32 [[RET:%.*]]84 85// OGCG: define dso_local noundef i32 @_Z15shouldGenBranchi86// OGCG: if.then:87// OGCG:   br label %err88// OGCG: if.end:89// OGCG:   br label %err90// OGCG: err:91// OGCG:   ret92 93void severalLabelsInARow(int a) {94  int b = a;95  goto end1;96  b = b + 1;97  goto end2;98end1:99end2:100  b = b + 2;101}102// CIR:  cir.func dso_local @_Z19severalLabelsInARowi103// CIR:    cir.goto "end1"104// CIR:  ^bb[[#BLK1:]]105// CIR:    cir.goto "end2"106// CIR:  ^bb[[#BLK2:]]:107// CIR:    cir.label "end1"108// CIR:    cir.br ^bb[[#BLK3:]]109// CIR:  ^bb[[#BLK3]]:110// CIR:    cir.label "end2"111 112// LLVM: define dso_local void @_Z19severalLabelsInARowi113// LLVM:   br label %[[END1:.*]]114// LLVM: [[UNRE:.*]]:                                                ; No predecessors!115// LLVM:   br label %[[END2:.*]]116// LLVM: [[END1]]:117// LLVM:   br label %[[END2]]118// LLVM: [[END2]]:119// LLVM:   ret120 121// OGCG: define dso_local void @_Z19severalLabelsInARowi122// OGCG:   br label %end1123// OGCG: end1:124// OGCG:   br label %end2125// OGCG: end2:126// OGCG:   ret127 128void severalGotosInARow(int a) {129  int b = a;130  goto end;131  goto end;132end:133  b = b + 2;134}135// CIR:  cir.func dso_local @_Z18severalGotosInARowi136// CIR:    cir.goto "end"137// CIR:  ^bb[[#BLK1:]]:138// CIR:    cir.goto "end"139// CIR:  ^bb[[#BLK2:]]:140// CIR:    cir.label "end"141 142// LLVM: define dso_local void @_Z18severalGotosInARowi143// LLVM:   br label %[[END:.*]]144// LLVM: [[UNRE:.*]]:                                                ; No predecessors!145// LLVM:   br label %[[END]]146// LLVM: [[END]]:147// LLVM:   ret void148 149// OGCG: define dso_local void @_Z18severalGotosInARowi(i32 noundef %a) #0 {150// OGCG:   br label %end151// OGCG: end:152// OGCG:   ret void153 154extern "C" void action1();155extern "C" void action2();156extern "C" void multiple_non_case(int v) {157  switch (v) {158    default:159        action1();160      l2:161        action2();162        break;163  }164}165 166// CIR: cir.func dso_local @multiple_non_case167// CIR: cir.switch168// CIR: cir.case(default, []) {169// CIR: cir.call @action1()170// CIR: cir.br ^[[BB1:[a-zA-Z0-9]+]]171// CIR: ^[[BB1]]:172// CIR: cir.label173// CIR: cir.call @action2()174// CIR: cir.break175 176// LLVM: define dso_local void @multiple_non_case177// LLVM: [[SWDEFAULT:.*]]:178// LLVM:   call void @action1()179// LLVM:   br label %[[L2:.*]]180// LLVM: [[L2]]:181// LLVM:   call void @action2()182// LLVM:   br label %[[BREAK:.*]]183 184// OGCG: define dso_local void @multiple_non_case185// OGCG: sw.default:186// OGCG:   call void @action1()187// OGCG:   br label %l2188// OGCG: l2:189// OGCG:   call void @action2()190// OGCG:   br label [[BREAK:%.*]]191 192extern "C" void case_follow_label(int v) {193  switch (v) {194    case 1:195    label:196    case 2:197      action1();198      break;199    default:200      action2();201      goto label;202  }203}204 205// CIR: cir.func dso_local @case_follow_label206// CIR: cir.switch207// CIR: cir.case(equal, [#cir.int<1> : !s32i]) {208// CIR:   cir.br ^bb1209// CIR: ^bb1:210// CIR:   cir.label "label"211// CIR: cir.case(equal, [#cir.int<2> : !s32i]) {212// CIR:   cir.call @action1()213// CIR:   cir.break214// CIR: cir.case(default, []) {215// CIR:   cir.call @action2()216// CIR:   cir.goto "label"217 218// LLVM: define dso_local void @case_follow_label219// LLVM:  switch i32 {{.*}}, label %[[SWDEFAULT:.*]] [220// LLVM:    i32 1, label %[[CASE1:.*]]221// LLVM:    i32 2, label %[[CASE2:.*]]222// LLVM:  ]223// LLVM: [[CASE1]]:224// LLVM:   br label %[[LABEL:.*]]225// LLVM: [[LABEL]]:226// LLVM:   br label %[[CASE2]]227// LLVM: [[CASE2]]:228// LLVM:   call void @action1()229// LLVM:   br label %[[BREAK:.*]]230// LLVM: [[BREAK]]:231// LLVM:   br label %[[END:.*]]232// LLVM: [[SWDEFAULT]]:233// LLVM:   call void @action2()234// LLVM:   br label %[[LABEL]]235// LLVM: [[END]]:236// LLVM:   br label %[[RET:.*]]237// LLVM: [[RET]]:238// LLVM:   ret void239 240// OGCG: define dso_local void @case_follow_label241// OGCG: sw.bb:242// OGCG:   br label %label243// OGCG: label:244// OGCG:   br label %sw.bb1245// OGCG: sw.bb1:246// OGCG:   call void @action1()247// OGCG:   br label %sw.epilog248// OGCG: sw.default:249// OGCG:   call void @action2()250// OGCG:   br label %label251// OGCG: sw.epilog:252// OGCG:   ret void253 254extern "C" void default_follow_label(int v) {255  switch (v) {256    case 1:257    case 2:258      action1();259      break;260    label:261    default:262      action2();263      goto label;264  }265}266 267// CIR: cir.func dso_local @default_follow_label268// CIR: cir.switch269// CIR: cir.case(equal, [#cir.int<1> : !s32i]) {270// CIR:   cir.yield271// CIR: cir.case(equal, [#cir.int<2> : !s32i]) {272// CIR:   cir.call @action1()273// CIR:   cir.break274// CIR:   cir.label "label"275// CIR: cir.case(default, []) {276// CIR:   cir.call @action2()277// CIR:   cir.goto "label"278 279// LLVM: define dso_local void @default_follow_label280// LLVM: [[CASE1:.*]]:281// LLVM:   br label %[[BB8:.*]]282// LLVM: [[BB8]]:283// LLVM:   br label %[[CASE2:.*]]284// LLVM: [[CASE2]]:285// LLVM:   call void @action1()286// LLVM:   br label %[[BREAK:.*]]287// LLVM: [[LABEL:.*]]:288// LLVM:   br label %[[SWDEFAULT:.*]]289// LLVM: [[SWDEFAULT]]:290// LLVM:   call void @action2()291// LLVM:   br label %[[BB9:.*]]292// LLVM: [[BB9]]:293// LLVM:   br label %[[LABEL]]294// LLVM: [[BREAK]]:295// LLVM:   br label %[[RET:.*]]296// LLVM: [[RET]]:297// LLVM:   ret void298 299// OGCG: define dso_local void @default_follow_label300// OGCG: sw.bb:301// OGCG:   call void @action1()302// OGCG:   br label %sw.epilog303// OGCG: label:304// OGCG:   br label %sw.default305// OGCG: sw.default:306// OGCG:   call void @action2()307// OGCG:   br label %label308// OGCG: sw.epilog:309// OGCG:   ret void310 311void g3() {312label:313  goto label;314}315 316// CIR:  cir.func dso_local @_Z2g3v317// CIR:    cir.br ^bb1318// CIR:  ^bb1:319// CIR:    cir.label "label"320// CIR:    cir.goto "label"321 322// LLVM: define dso_local void @_Z2g3v()323// LLVM:   br label %1324// LLVM: 1:325// LLVM:   br label %1326 327// OGCG: define dso_local void @_Z2g3v()328// OGCG:   br label %label329// OGCG: label:330// OGCG:   br label %label331