[cfe-users] Why does clang not always produce constant value for same static constexpr

Christopher Williams via cfe-users cfe-users at lists.llvm.org
Wed Sep 25 12:37:39 PDT 2019

Given the code below, clang produces a constant value for test1, test2
and test4. Why doesn't it for test3?
This is more of a curious query, than a request for help, but if someone
does have the answer, I'd appreciate as much detail as possible.

    !=0;++str){count +=*str

    |test1():# @test1()mov eax,4ret test2():# @test2()mov eax,8ret
    test3():# @test3()xor eax,eax mov dl,49mov ecx,offset
    .L.str.2+1.LBB2_1:# =>This Inner Loop Header: Depth=1xor esi,esi cmp
    dl,120sete sil add eax,esi movzx edx,byte ptr [rcx]add rcx,1test
    dl,dl jne .LBB2_1 ret test4():# @test4()mov eax,16ret

gcc does:

    |test1():mov eax,4ret test2():mov eax,8ret test3():mov eax,16ret
    test4():mov eax,16ret|

Compilation command lines used:

|clang++-Ofast-std=c++2a-S -o --c src/test.cpp |grep -Ev$'^\t+\\.'gcc9
-Ofast-std=c++2a-S -o --c src/test.cpp |grep -Ev$'^\t+\\.'|

Compiler Explorer: https://godbolt.org/z/V-3MEp

More information about the cfe-users mailing list