badumbatish wrote:

> Can there be implicit return with value?
There can be some, an example is the following where we have `return %2` not 
present in the source code

```
Shell: /usr/bin/zsh
Git Branch: main
Git Commit: 90285d318fa4
Git Repo: [email protected]:badumbatish/llvm-project.git
Working Directory: /home/jjasmine/Developer/igalia/llvm-project
Command: ninja -C build && ./build/bin/clang -cc1 -fclangir -emit-cir 
scratch/switch_with_break.c -o -
Exit Code: 0
Duration: 622ms
Timestamp: 2026-01-08 13:16:17
--------------------------------------------------------------------------------------------------------------------------------------------
int switch_with_break(int x) {
  switch (x) {
  case 0:
    return 0;
  case 1:
    break;
  }
} // expected-warning {{non-void function does not return a value in all 
control paths}}
--------------------------------------------------------------------------------------------------------------------------------------------
ninja: Entering directory `build'
[88/88] Running utility command for liblldb-header-staging
scratch/switch_with_break.c:8:1: warning: non-void function does not return a 
value in all control paths [-Wreturn-type]
    8 | } // expected-warning {{non-void function does not return a value in 
all control paths}}
      | ^
!s32i = !cir.int<s, 32>
#loc3 = loc("scratch/switch_with_break.c":1:23)
#loc4 = loc("scratch/switch_with_break.c":1:27)
#loc15 = loc(fused[#loc3, #loc4])
module 
@"/home/jjasmine/Developer/igalia/llvm-project/scratch/switch_with_break.c" 
attributes {cir.lang = #cir.lang<c>, cir.module_asm = [], cir.triple = 
"x86_64-unknown-linux-gnu", dlti.dl_spec = #dl
ti.dl_spec<!llvm.ptr<270> = dense<32> : vector<4xi64>, !llvm.ptr<271> = 
dense<32> : vector<4xi64>, !llvm.ptr<272> = dense<64> : vector<4xi64>, i64 = 
dense<64> : vector<2xi64>, i128 = dense<128> : vect
or<2xi64>, f80 = dense<128> : vector<2xi64>, !llvm.ptr = dense<64> : 
vector<4xi64>, i1 = dense<8> : vector<2xi64>, i8 = dense<8> : vector<2xi64>, 
i16 = dense<16> : vector<2xi64>, i32 = dense<32> : vec
tor<2xi64>, f16 = dense<16> : vector<2xi64>, f64 = dense<64> : vector<2xi64>, 
f128 = dense<128> : vector<2xi64>, "dlti.endianness" = "little", 
"dlti.mangling_mode" = "e", "dlti.legal_int_widths" = arr
ay<i32: 8, 16, 32, 64>, "dlti.stack_alignment" = 128 : i64>} {
  cir.func no_inline dso_local @switch_with_break(%arg0: !s32i loc(fused[#loc3, 
#loc4])) -> !s32i {
    %0 = cir.alloca !s32i, !cir.ptr<!s32i>, ["x", init] {alignment = 4 : i64} 
loc(#loc15)
    %1 = cir.alloca !s32i, !cir.ptr<!s32i>, ["__retval"] {alignment = 4 : i64} 
loc(#loc2)
    cir.store %arg0, %0 : !s32i, !cir.ptr<!s32i> loc(#loc5)
    cir.scope {
      %3 = cir.load align(4) %0 : !cir.ptr<!s32i>, !s32i loc(#loc8)
      cir.switch(%3 : !s32i) {
        cir.case(equal, [#cir.int<0> : !s32i]) {
          %4 = cir.const #cir.int<0> : !s32i loc(#loc10)
          cir.store %4, %1 : !s32i, !cir.ptr<!s32i> loc(#loc17)
          %5 = cir.load %1 : !cir.ptr<!s32i>, !s32i loc(#loc17)
          cir.return %5 : !s32i loc(#loc17)
        } loc(#loc9)
        cir.case(equal, [#cir.int<1> : !s32i]) {
          cir.break loc(#loc13)
        } loc(#loc12)
        cir.yield loc(#loc6)
      } loc(#loc6)
    } loc(#loc16)
    %2 = cir.load %1 : !cir.ptr<!s32i>, !s32i loc(#loc2)
    cir.return %2 : !s32i loc(#loc2)
  } loc(#loc14)
} loc(#loc)
#loc = 
loc("/home/jjasmine/Developer/igalia/llvm-project/scratch/switch_with_break.c":0:0)
#loc1 = loc("scratch/switch_with_break.c":1:1)
#loc2 = loc("scratch/switch_with_break.c":8:1)
#loc5 = loc("scratch/switch_with_break.c":1:30)
#loc6 = loc("scratch/switch_with_break.c":2:3)
#loc7 = loc("scratch/switch_with_break.c":7:3)
#loc8 = loc("scratch/switch_with_break.c":2:11)
#loc9 = loc("scratch/switch_with_break.c":3:3)
#loc10 = loc("scratch/switch_with_break.c":4:12)
#loc11 = loc("scratch/switch_with_break.c":4:5)
#loc12 = loc("scratch/switch_with_break.c":5:3)
#loc13 = loc("scratch/switch_with_break.c":6:5)
#loc14 = loc(fused[#loc1, #loc2])
#loc16 = loc(fused[#loc6, #loc7])
#loc17 = loc(fused[#loc11, #loc10])
1 warning generated.
```

https://github.com/llvm/llvm-project/pull/174832
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to