https://gcc.gnu.org/bugzilla/show_bug.cgi?id=91916

            Bug ID: 91916
           Summary: Maybe a dead code in socket.d
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: d
          Assignee: ibuclaw at gdcproject dot org
          Reporter: marxin at gcc dot gnu.org
                CC: ibuclaw at gcc dot gnu.org
  Target Milestone: ---

Looking at the ./libphobos/src/std/socket.d file, when building:
/dev/shm/mliska/gcc_89622158a277a4f1200d2652d66f8c1b9c1e4012/objdir/./gcc/gdc
-B/dev/shm/mliska/gcc_89622158a277a4f1200d2652d66f8c1b9c1e4012/objdir/./gcc/
-B/usr/local/x86_64-pc-linux-gnu/bin/ -B/usr/local/x86_64-pc-linux-gnu/lib/
-isystem /usr/local/x86_64-pc-linux-gnu/include -isystem
/usr/local/x86_64-pc-linux-gnu/sys-include -fPIC -O2 -g -nostdinc -I
../../../../libphobos/src -I ../../../../libphobos/libdruntime -I
../libdruntime -I . -c ../../../../libphobos/src/std/socket.d -fversion=Shared
-o std/.libs/socket.o

I see there's a function formatValue which contains if-elseif chain that has a
dead code:

Statement can throw: formatValue (w_9(D), D.19387, f_5(D));
formatValue (struct Appender!(immutable(string)) & w, SocketOption val, const
struct FormatSpec!char & f)
{
...
  <bb 3> :
  if (val_6(D) == 1)
    goto <bb 4>; [INV]
  else
    goto <bb 5>; [INV]

  <bb 4> :
  D.19387.length = 5;
  D.19387.ptr = "DEBUG";
  formatValue (w_9(D), D.19387, f_5(D));
  // predicted unlikely by early return (on trees) predictor.
  goto <bb 53>; [INV]

  <bb 5> :
  if (val_6(D) == 6)
    goto <bb 6>; [INV]
  else
    goto <bb 7>; [INV]
...
  <bb 35> :
  if (val_6(D) == 1)
    goto <bb 36>; [INV]
  else
    goto <bb 37>; [INV]

  <bb 36> :
  D.19435.length = 11;
  D.19435.ptr = "TCP_NODELAY";
  formatValue (w_9(D), D.19435, f_5(D));
  // predicted unlikely by early return (on trees) predictor.
  goto <bb 53>; [INV]

So as seen:

/// Specifies a socket option:
enum SocketOption: int
{
    DEBUG =                SO_DEBUG,            /// Record debugging
information
...
    TCP_NODELAY =          .TCP_NODELAY,        /// Disable the Nagle algorithm
for send coalescing

these two have same integer representation == 1. Maybe it's a bug?

Reply via email to