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

            Bug ID: 106409
           Summary: GCC with LTO: Warning: argument 1 value ‘18...615’
                    (SIZE_MAX) exceeds maximum object size
           Product: gcc
           Version: 11.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: lluis.alemany.puig at gmail dot com
  Target Milestone: ---

I'm using g++ (Ubuntu 11.1.0-1ubuntu1~20.04) 11.1.0. I'm getting the following
warning when I compile my code using -flto and -fno-fat-lto-objects:

```
    In member function ‘alloc_data’,
        inlined from ‘__ct ’ at data_array.hpp:9:67,
        inlined from ‘__ct ’ at main.cpp:26:5,
        inlined from ‘main’ at main.cpp:61:16:
    data_array.hpp:29:50: warning: argument 1 value ‘18446744073709551615’
exceeds maximum object size 9223372036854775807 [-Walloc-size-larger-than=]
       29 |                 m_data = m_size == 0 ? nullptr : new T[m_size];
          |                                                  ^
    data_array.hpp: In function ‘main’:
    /usr/include/c++/11/new:128:26: note: in a call to allocation function
‘operator new []’ declared here
      128 | _GLIBCXX_NODISCARD void* operator new[](std::size_t) _GLIBCXX_THROW
(std::bad_alloc)
          |                          ^
```

The two sets of commands I use to compile my code are (-fsanitize=undefined):

```
    g++ -pipe -std=c++17 -fPIC -fopenmp -flto -fno-fat-lto-objects -O3 -Wall
-Wextra -Wshadow -Wnon-virtual-dtor -Wold-style-cast -Wcast-align -Wunused
-Woverloaded-virtual -Wpedantic -Wconversion -Wsign-conversion
-Wnull-dereference -Wdouble-promotion -Wformat=2 -Wduplicated-cond
-Wduplicated-branches -Wlogical-op -Wuseless-cast -Wrestrict -UDEBUG -DNDEBUG
-fstrict-aliasing -D_REENTRANT -fPIC -fsanitize=undefined -c main.cpp
    g++ -fPIC -O3 -flto -fno-fat-lto-objects -DNDEBUG -UDEBUG -Wl,-O3
-fsanitize=undefined -o main main.o
```

and (-fsanitize=address)

```
    g++ -pipe -std=c++17 -fPIC -fopenmp -flto -fno-fat-lto-objects -O3 -Wall
-Wextra -Wshadow -Wnon-virtual-dtor -Wold-style-cast -Wcast-align -Wunused
-Woverloaded-virtual -Wpedantic -Wconversion -Wsign-conversion
-Wnull-dereference -Wdouble-promotion -Wformat=2 -Wduplicated-cond
-Wduplicated-branches -Wlogical-op -Wuseless-cast -Wrestrict -UDEBUG -DNDEBUG
-fstrict-aliasing -D_REENTRANT -fPIC -fsanitize=address -c main.cpp
    g++ -fPIC -O3 -flto -fno-fat-lto-objects -DNDEBUG -UDEBUG -Wl,-O3 -o main
main.o -lasan
```

Both sets of commands produce the warning above. With both, the program
executes normally and finishes without issuing any error message.

I generated the *i file with the following command
```
    g++ -E -std=c++17 -fPIC -fopenmp -flto -fno-fat-lto-objects -O3 -Wall
-Wextra -Wshadow -Wnon-virtual-dtor -Wold-style-cast -Wcast-align -Wunused
-Woverloaded-virtual -Wpedantic -Wconversion -Wsign-conversion
-Wnull-dereference -Wdouble-promotion -Wformat=2 -Wduplicated-cond
-Wduplicated-branches -Wlogical-op -Wuseless-cast -Wrestrict -UDEBUG -DNDEBUG
-fstrict-aliasing -D_REENTRANT -fPIC -save-temps -c main.cpp
```

Reply via email to