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

            Bug ID: 121922
           Summary: wrong code for "declare variant" replacement involving
                    user/condition selector
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Keywords: openmp
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: sandra at gcc dot gnu.org
  Target Milestone: ---

Created attachment 62371
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=62371&action=edit
test case borked-flag.c

The attached test case compiled with

x86_64-linux-gnu-gcc -S -fopenmp -fdump-tree-gimple borked-flag.c

produces this output from the gimplifier (where the declare variant replacement
happens):

void doit ()
{
  int iftmp.0;
  int iftmp.2;
  int iftmp.3;

  flag = 0;
  flag.1_1 = flag;
  if (flag.1_1 > 1) goto <D.3116>; else goto <D.3117>;
  <D.3116>:
  iftmp.0 = test_with_flag ();
  goto <D.3118>;
  <D.3117>:
  iftmp.0 = test ();
  <D.3118>:
  if (iftmp.0 != 0) goto <D.3119>; else goto <D.3120>;
  <D.3119>:
  __builtin_abort ();
  <D.3120>:
  flag = 1;
  if (flag.1_1 > 1) goto <D.3122>; else goto <D.3123>;
  <D.3122>:
  iftmp.2 = test_with_flag ();
  goto <D.3124>;
  <D.3123>:
  iftmp.2 = test ();
  <D.3124>:
  if (iftmp.2 != 0) goto <D.3125>; else goto <D.3126>;
  <D.3125>:
  __builtin_abort ();
  <D.3126>:
  flag = 42;
  if (flag.1_1 > 1) goto <D.3128>; else goto <D.3129>;
  <D.3128>:
  iftmp.3 = test_with_flag ();
  goto <D.3130>;
  <D.3129>:
  iftmp.3 = test ();
  <D.3130>:
  if (iftmp.3 != 42) goto <D.3131>; else goto <D.3132>;
  <D.3131>:
  __builtin_abort ();
  <D.3132>:
}

Note that it's properly setting "flag" before each call to the variant function
per the explicit assignments in the original code, but all the variant call
expansions for the dynamic selector are testing "flag.1_1" -- which only gets
set once at the beginning of the function.

Using g++ instead of gcc produces the same output.  This is surely happening in
the gimplifier or the support functions in omp-general.cc.

Reply via email to