<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/119341>119341</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Clang: Both operands of conditional operator are evaluated
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          wzssyqa
      </td>
    </tr>
</table>

<pre>
    In some cases both the second and third operands are evaluated, which is not allowed by C standard.

I find this problem when I try to build glibc with clang.
    With the test of `powl` function, both `OVERFLOW` and `UNDERFLOW` exceptions are raised, while only one is expected.
I haven't figure out a short case.

How to reproduce
```
1. Download glibc 2.40 etc, and unpack it, and cd into the source tree
2. mkdir -p build-clang/math
3. put the attached abi-versions.h, config.h, first-versions.h, libc-modules.h to build-clang
4. <PATH_OF_LLVM>/bin/clang --target=riscv64-linux-gnu ../sysdeps/ieee754/ldbl-128/e_powl.c -S -std=gnu11 -fgnu89-inline  -g -O2 -Wall -Wwrite-strings -Wundef -Werror -fmerge-all-constants -frounding-math -ftrapping-math -fno-stack-protector -fno-common -Wp,-U_FORTIFY_SOURCE -Wstrict-prototypes -Wold-style-definition -fno-math-errno    -fPIE -fno-builtin-powf64x -fno-builtin-powf128       -I../include -Imath -I/Volumes/WD/develop/glibc/build-^Cang -I../sysdeps/unix/sysv/linux/riscv/rv64 -I../sysdeps/unix/sysv/linux/riscv/include -I../sysdeps/unix/sysv/linux/riscv -I../sysdeps/riscv/nptl  -I../sysdeps/unix/sysv/linux/wordsize-64 -I../sysdeps/unix/sysv/linux/riscv/multiarch -I../sysdeps/unix/sysv/linux/include -I../sysdeps/unix/sysv/linux -I../sysdeps/nptl  -I../sysdeps/pthread  -I../sysdeps/gnu -I../sysdeps/unix/inet  -I../sysdeps/unix/sysv  -I../sysdeps/unix -I../sysdeps/posix  -I../sysdeps/riscv/rv64/rvd  -I../sysdeps/riscv/rv64/rvf -I../sysdeps/riscv/rvf  -I../sysdeps/riscv/rvd  -I../sysdeps/riscv/rv64 -I../sysdeps/riscv/multiarch  -I../sysdeps/riscv -I../sysdeps/ieee754/ldbl-128  -I../sysdeps/ieee754/dbl-64 -I../sysdeps/ieee754/flt-32  -I../sysdeps/wordsize-64  -I../sysdeps/ieee754 -I../sysdeps/generic  -I.. -I../libio -I.  -D_LIBC_REENTRANT -include libc-modules.h -DMODULE_NAME=libm -include ../include/libc-symbols.h  -DPIC -DTOP_NAMESPACE=glibc -o math/e_powl.o -MD -MP -MF math/e_powl.o.dt -MT math/e_powl.o
```

So we get a file `math/e_powl.o`,  which is an `asm text` file.
In it we can find there are code like:

```
.Ltmp87:
# %bb.51:                               # %if.then222
        #DEBUG_VALUE: __ieee754_powl:x <- [DW_OP_LLVM_fragment 0 64] $x26
        #DEBUG_VALUE: __ieee754_powl:x <- [DW_OP_LLVM_fragment 64 64] $x9
        #DEBUG_VALUE: __ieee754_powl:y <- [DW_OP_LLVM_fragment 0 64] $x19
        #DEBUG_VALUE: __ieee754_powl:y <- [DW_OP_LLVM_fragment 64 64] $x24
        #DEBUG_VALUE: __ieee754_powl:iy <- $x18
        .loc    0 0 14 is_stmt 0                # ../sysdeps/ieee754/ldbl-128/e_powl.c:0:14
        mv      s0, a3 
.Lpcrel_hi1:
        auipc   a0, %pcrel_hi(.LCPI0_30)
 ld      a0, %pcrel_lo(.Lpcrel_hi1)(a0)
.Lpcrel_hi2:    
        auipc a1, %pcrel_hi(.LCPI0_31)
        ld      a1, %pcrel_lo(.Lpcrel_hi2)(a1)
.Ltmp88:
        mv      a2, a0
        mv a3, a1
        call    __multf3
.Ltmp89:
        mv      s10, a0
.Ltmp90:
        mv      s5, a1
.Lpcrel_hi3:
        auipc   a0, %pcrel_hi(.LCPI0_28)        
        ld      a0, %pcrel_lo(.Lpcrel_hi3)(a0)
.Lpcrel_hi4:
        auipc   a1, %pcrel_hi(.LCPI0_29)        
        ld      a1, %pcrel_lo(.Lpcrel_hi4)(a1)
        mv      a2, a0
        mv      a3, a1
 call    __multf3
.Ltmp91:
        lui     a2, 262128
        addiw a2, a2, -1
.Ltmp92:
        .loc    0 281 11 is_stmt 1              # ../sysdeps/ieee754/ldbl-128/e_powl.c:281:11
        bltu    a2, s6, .LBB0_72 
```

Note that `__multf3` are called twice one by one without condition test.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJysWElv6zrS_TX0pkBBojwuvHA8fM9AJuQm1_hWAkVRFvtSpJqkPLxf36DkKYmdThpPCKyYrDo8VaekIk2tFWvF-Rj17lBv1qG1K7QZb_-2dv9v2kl1th8vFVhdcmDUcgupdgW4goPlTKsMqMrAFcJkoCtuqMosUMOBb6isqeMZIlPYFoIVICwo7YBKqbc8g3QPU7COqoyaLEDhBIWTJeSixbNQGZ1KXsK24AqW4MwenIa0FjKDtRQpg61wBTBJ1dq7AwCsxIGc49aBzgH1w0pvJeqHkNeKOaGVJ9QEgfrh0-_5y-L-aeXnfSCoH749zs5jfMd45Z3aoAwV9hSR5KCV3INW3IfGdxVnjjeRLKGgG64QGTjIxbo2HHTtgIIttHFNIg8B_6W3PirDK6OzmnE_2g8Pf-EkCmCmt0pqeoyZBN0QuGOehGdcq4qyPyDccYBlIJTTrUS6NoyDM9wDkwDKP5kwgKs2jbjJHSKLkroChZM4gKp2jSd1jrKCZ0BTgTfcWJ-DoPCLMK1ysW7_z4Wx7sO8p4lLndWS26A4aXZYLJx0A0Dx9Hny-lfytEju738_oHiOyCIVCpFFYwUYO2rW3KF4ZoRlm34XS6HqHV6rGoIAkYXd24xXFpGF4JwPel1EFjJLJY7IEJEFT7zsAQP8C7B1GYpna1VHEeB8rerhCAslheIAeA34iQBeUSkBr7ZGOI6tM0KtLeBVrTKeA15xY7QBnJfcrDmmUmKmlS9eZwHnRtcqE2qNfSIB587Qqrr4rjS2jrI_uDLaceYaKKUx02WpFeBVhcgUvyWLp5fX5eL_k19Pby_TOeCVJ8Jc46b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