Compiler-explorer: Wrong gcc output when intrinsic is used.

Created on 12 May 2019  路  5Comments  路  Source: compiler-explorer/compiler-explorer

See https://godbolt.org/z/bWb_Av

Two functions f1 and f2 are implemented and we expected something similar to

f1():
    blah
f2():
    bleh

but, instead, we get

f1():
    blah
    bleh

That is, the line containing f2 is not shown and, consequently, the instructions of f2 are displayed after those of f1 giving the wrong impression they belong to f1.

It seems to be a "gcc issue" when code calls intrinsic function _addcarry_u32. Indeed, the output is correct when either of the below happens:

  1. clang or icc is selected;
  2. the call to _addcarry_u32 is replaced by expression b += a (which generates the same assembly instructions for -O1 level).

Another thing that plays a role is the optimization level: changing to from -O1 to -O0 (or leaving it blank) seems to "fix".

A better workaround is turning on the option "_Compile to binary and disassemble output_".

bug lang-c++

Most helpful comment

This was indeed fixed in master and is thus now fixed on the live website

All 5 comments

The output is also correct if "lib.f" is not selected.

Does look like a bug in CE's parser. The raw output is:

  .globl f1()
  .type f1(), @function
f1():
.LFB5530:
  .file 1 "/tmp/compiler-explorer-compiler119412-62-mk66va.fc11b/example.cpp"
  .loc 1 3 15
  .cfi_startproc
  .loc 1 4 5
  .loc 1 5 1 is_stmt 0
  movl $0, %eax
  ret
  .cfi_endproc
.LFE5530:
  .size f1(), .-f1()
  .globl f2(unsigned int, unsigned int)
  .type f2(unsigned int, unsigned int), @function
f2(unsigned int, unsigned int):
.LFB5531:
  .loc 1 7 37 is_stmt 1
  .cfi_startproc
.LVL0:
  .loc 1 9 5
.LBB4:
.LBB5:
  .file 2 "/opt/compiler-explorer/gcc-9.1.0/lib/gcc/x86_64-linux-gnu/9.1.0/include/adxintrin.h"
  .loc 2 44 3
.LBE5:
.LBE4:
  .loc 1 11 5
  .loc 1 11 12 is_stmt 0
  leal (%rdi,%rsi), %eax
  .loc 1 12 1
  ret
  .cfi_endproc

Without the intrinsic, the output of the f2 function is:

.LFE5530:
  .size f1(), .-f1()
  .globl f2(unsigned int, unsigned int)
  .type f2(unsigned int, unsigned int), @function
f2(unsigned int, unsigned int):
.LFB5531:
  .loc 1 7 37 is_stmt 1
  .cfi_startproc
.LVL0:
  .loc 1 10 5
  .loc 1 11 5
  .loc 1 10 7 is_stmt 0
  leal (%rsi,%rdi), %eax
.LVL1:
  .loc 1 12 1
  ret
  .cfi_endproc

I'm guessing this will be fixed once the lib.f fixes go live, but not totally sure looking at this code. Will test it out today/tomorrow.

This was indeed fixed in master and is thus now fixed on the live website

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mattgodbolt picture mattgodbolt  路  4Comments

mattgodbolt picture mattgodbolt  路  4Comments

daniel-j-h picture daniel-j-h  路  4Comments

phuclv90 picture phuclv90  路  4Comments

crea7or picture crea7or  路  4Comments