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

Bernd Buschinski <b.buschinski at googlemail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |b.buschinski at googlemail dot 
com

--- Comment #4 from Bernd Buschinski <b.buschinski at googlemail dot com> ---
I also hit this problem, but not 100% sure if this is a duplicate or not.
Because as far as I can remember it used to work with GCC-11 (can not test now
only have 12) and only started failing with GCC 12.

Can someone tell me if this should be a new bug or is just a duplicate?

Known to fail on:
- sys-devel/gcc-12.1.1_p20220625 (Gentoo)
- gcc-12.1.1-1.fc36.x86_64 12.1.1 20220507 (Red Hat 12.1.1-1) (Fedora)
- 12-20220319-1ubuntu1 (Ubuntu 22.04)

Compiler explorer: https://godbolt.org/z/rrWffMe9x


Code:


#include <stdlib.h>

extern void *my_memmem(const void *__haystack, size_t __haystacklen,
                       const void *__needle, size_t __needlelen)
     __THROW __attribute_pure__ __nonnull ((1, 3))
    __attribute__((access(__read_only__, 1, 2)))
    __attribute__((access(__read_only__, 3, 4)));

#define CONTAINSCONST(_cstring, string)                                        
  \
  ({                                                                           
  \
    size_t const tmp_CONST_LEN = sizeof(string) - 1;                           
  \
    ((_cstring).length >= tmp_CONST_LEN &&                                     
  \
     (my_memmem((_cstring).buffer, (_cstring).length, string, tmp_CONST_LEN) !=
  \
      NULL));                                                                  
  \
  })

struct my_string {
  unsigned char *buffer;
  unsigned long long length;
};

int foo(struct my_string const *const ss) {
  struct my_string const str_path = *ss;

  if (CONTAINSCONST(str_path, "/") ||
      CONTAINSCONST(str_path, ".abcd") ||
      CONTAINSCONST(str_path, "?")) {
    return 1;
  }
  return 0;
}

// $ gcc -std=gnu99 -Wall -Wextra -Walloc-zero -O2 -fsanitize=undefined -Werror
test2.c -S
// test2.c: In function 'foo':
// test2.c:13:7: error: argument 1 is null but the corresponding size argument
2 value is [5, 18446744073709551615] [-Werror=nonnull]
//    13 |      (my_memmem((_cstring).buffer, (_cstring).length, string,
tmp_CONST_LEN) !=   \
//       |      
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// test2.c:26:7: note: in expansion of macro 'CONTAINSCONST'
//    26 |       CONTAINSCONST(str_path, ".abcd") ||
//       |       ^~~~~~~~~~~~~
// test2.c:3:14: note: in a call to function 'my_memmem' declared with
attribute 'access (read_only, 3, 4)'
//     3 | extern void *my_memmem(const void *__haystack, size_t __haystacklen,
//       |              ^~~~~~~~~
// cc1: all warnings being treated as errors
  • [Bug middle-end/98109] See... b.buschinski at googlemail dot com via Gcc-bugs

Reply via email to