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

            Bug ID: 93837
           Summary: overly complicated code in
                    c_finish_omp_declare_variant
           Product: gcc
           Version: 10.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: roland.illig at gmx dot de
  Target Milestone: ---

> else if (fndecl_built_in_p (variant)
>          && (strncmp (IDENTIFIER_POINTER (DECL_NAME (variant)),
>                       "__builtin_", strlen ("__builtin_")) == 0
>                  || strncmp (IDENTIFIER_POINTER (DECL_NAME (variant)),
>                              "__sync_", strlen ("__sync_")) == 0
>                  || strncmp (IDENTIFIER_POINTER (DECL_NAME (variant)),
>                              "__atomic_", strlen ("__atomic_")) == 0))

Why not simply define a function str_startswith and rewrite the code to:

> str_startswith (IDENTIFIER_POINTER (DECL_NAME (variant)), "__builtin_")
> || str_startswith (IDENTIFIER_POINTER (DECL_NAME (variant)), "__sync_")
> || str_startswith (IDENTIFIER_POINTER (DECL_NAME (variant)), "__atomic_")

This would make it even more obvious that an additional CSE pass would make the
code even easier to read:

> const char *variant_name = IDENTIFIER_POINTER (DECL_NAME (variant));
> if (str_startswith(variant_name, "__builtin_")
>     || str_startswith(variant_name, "__sync_")
>     || str_startswith(variant_name, "__atomic_"))

Is there any reason why you chose to write the code in the complicated and hard
to read way?

Reply via email to