[Bug c++/11073] New: Optimizer -O3 with -Wcast-align generate "increases required alignment" warnings

deffeg@ecse.rpi.edu gcc-bugzilla@gcc.gnu.org
Tue Jun 3 07:31:00 GMT 2003


PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11073

           Summary: Optimizer -O3 with -Wcast-align generate "increases
                    required alignment" warnings
           Product: gcc
           Version: 3.3
            Status: UNCONFIRMED
          Severity: minor
          Priority: P4
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: deffeg@ecse.rpi.edu
                CC: gcc-bugs@gcc.gnu.org
 GCC build triplet: sun-sparc-solaris2.7
  GCC host triplet: sun-sparc-solaris2.7
GCC target triplet: sun-sparc-solaris2.7

The following code:

#include <iostream>

int main( )
{
  int error = -2;
  std::cerr << "ERROR? "<<error<<"\n";
}

compiled with:  g++ -Wcast-align -O3 -c demo.cc -o demo

Generates the following warning:

g++ -Wcast-align -O3 -c demo.cc -o demo.o
/usr/local/include/c++/3.3/bits/stl_alloc.h: In static member function `static 
   char* std::__default_alloc_template<__threads, 
   __inst>::_S_chunk_alloc(unsigned int, int&) [with bool __threads = true, int 
   __inst = 0]':
/usr/local/include/c++/3.3/bits/stl_alloc.h:550:   instantiated from `static 
void* std::__default_alloc_template<__threads, __inst>::_S_refill(unsigned int) 
[with bool __threads = true, int __inst = 0]'
/usr/local/include/c++/3.3/bits/stl_alloc.h:414:   instantiated from `static 
void* std::__default_alloc_template<__threads, __inst>::allocate(unsigned int) 
[with bool __threads = true, int __inst = 0]'
/usr/local/include/c++/3.3/bits/stl_alloc.h:673:   instantiated from `_Tp* 
std::allocator<_Alloc>::allocate(unsigned int, const void*) [with _Tp = char]'
/usr/local/include/c++/3.3/bits/basic_string.tcc:554:   instantiated from 
`static std::basic_string<_CharT, _Traits, _Alloc>::_Rep* 
std::basic_string<_CharT, _Traits, _Alloc>::_Rep::_S_create(unsigned int, const 
_Alloc&) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = 
std::allocator<char>]'
/usr/local/include/c++/3.3/bits/basic_string.tcc:579:   instantiated from 
`_CharT* std::basic_string<_CharT, _Traits, _Alloc>::_Rep::_M_clone(const 
_Alloc&, typename _Alloc::size_type) [with _CharT = char, _Traits = 
std::char_traits<char>, _Alloc = std::allocator<char>]'
/usr/local/include/c++/3.3/bits/basic_string.h:195:   instantiated from 
`_CharT* std::basic_string<_CharT, _Traits, _Alloc>::_Rep::_M_grab(const 
_Alloc&, const _Alloc&) [with _CharT = char, _Traits = std::char_traits<char>, 
_Alloc = std::allocator<char>]'
/usr/local/include/c++/3.3/bits/basic_string.tcc:194:   instantiated from 
`std::basic_string<_CharT, _Traits, _Alloc>::basic_string(const 
std::basic_string<_CharT, _Traits, _Alloc>&) [with _CharT = char, _Traits = 
std::char_traits<char>, _Alloc = std::allocator<char>]'
/usr/local/include/c++/3.3/bits/locale_facets.tcc:792:   instantiated from 
`_OutIter std::num_put<_CharT, _OutIter>::_M_convert_int(_OutIter, 
std::ios_base&, _CharT, _ValueT) const [with _ValueT = long unsigned int, 
_CharT = char, _OutIter = std::ostreambuf_iterator<char, std::char_traits<char> 
>]'
/usr/local/include/c++/3.3/bits/locale_facets.tcc:1020:   instantiated from 
`_OutIter std::num_put<_CharT, _OutIter>::do_put(_OutIter, std::ios_base&, 
_CharT, long unsigned int) const [with _CharT = char, _OutIter = 
std::ostreambuf_iterator<char, std::char_traits<char> >]'
/usr/local/include/c++/3.3/bits/locale_facets.h:871:   instantiated from 
`_OutIter std::num_put<_CharT, _OutIter>::put(_OutIter, std::ios_base&, _CharT, 
long unsigned int) const [with _CharT = char, _OutIter = 
std::ostreambuf_iterator<char, std::char_traits<char> >]'
/usr/local/include/c++/3.3/bits/ostream.tcc:223:   instantiated from 
`std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, 
_Traits>::operator<<(long unsigned int) [with _CharT = char, _Traits = 
std::char_traits<char>]'
/usr/local/include/c++/3.3/ostream:196:   instantiated from 
`std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, 
_Traits>::operator<<(int) [with _CharT = char, _Traits = 
std::char_traits<char>]'
demo.cc:7:   instantiated from here
/usr/local/include/c++/3.3/bits/stl_alloc.h:503: warning: cast from `char*' to `
   std::__default_alloc_template<true, 0>::_Obj*' increases required alignment 
   of target type
/usr/local/include/c++/3.3/bits/stl_alloc.h:504: warning: cast from `char*' to `
   std::__default_alloc_template<true, 0>::_Obj*' increases required alignment 
   of target type
/usr/local/include/c++/3.3/bits/stl_alloc.h: In static member function `static 
   void* std::__default_alloc_template<__threads, __inst>::_S_refill(unsigned 
   int) [with bool __threads = true, int __inst = 0]':
/usr/local/include/c++/3.3/bits/stl_alloc.h:414:   instantiated from `static 
void* std::__default_alloc_template<__threads, __inst>::allocate(unsigned int) 
[with bool __threads = true, int __inst = 0]'
/usr/local/include/c++/3.3/bits/stl_alloc.h:673:   instantiated from `_Tp* 
std::allocator<_Alloc>::allocate(unsigned int, const void*) [with _Tp = char]'
/usr/local/include/c++/3.3/bits/basic_string.tcc:554:   instantiated from 
`static std::basic_string<_CharT, _Traits, _Alloc>::_Rep* 
std::basic_string<_CharT, _Traits, _Alloc>::_Rep::_S_create(unsigned int, const 
_Alloc&) [with _CharT = char, _Traits = std::char_traits<char>, _Alloc = 
std::allocator<char>]'
/usr/local/include/c++/3.3/bits/basic_string.tcc:579:   instantiated from 
`_CharT* std::basic_string<_CharT, _Traits, _Alloc>::_Rep::_M_clone(const 
_Alloc&, typename _Alloc::size_type) [with _CharT = char, _Traits = 
std::char_traits<char>, _Alloc = std::allocator<char>]'
/usr/local/include/c++/3.3/bits/basic_string.h:195:   instantiated from 
`_CharT* std::basic_string<_CharT, _Traits, _Alloc>::_Rep::_M_grab(const 
_Alloc&, const _Alloc&) [with _CharT = char, _Traits = std::char_traits<char>, 
_Alloc = std::allocator<char>]'
/usr/local/include/c++/3.3/bits/basic_string.tcc:194:   instantiated from 
`std::basic_string<_CharT, _Traits, _Alloc>::basic_string(const 
std::basic_string<_CharT, _Traits, _Alloc>&) [with _CharT = char, _Traits = 
std::char_traits<char>, _Alloc = std::allocator<char>]'
/usr/local/include/c++/3.3/bits/locale_facets.tcc:792:   instantiated from 
`_OutIter std::num_put<_CharT, _OutIter>::_M_convert_int(_OutIter, 
std::ios_base&, _CharT, _ValueT) const [with _ValueT = long unsigned int, 
_CharT = char, _OutIter = std::ostreambuf_iterator<char, std::char_traits<char> 
>]'
/usr/local/include/c++/3.3/bits/locale_facets.tcc:1020:   instantiated from 
`_OutIter std::num_put<_CharT, _OutIter>::do_put(_OutIter, std::ios_base&, 
_CharT, long unsigned int) const [with _CharT = char, _OutIter = 
std::ostreambuf_iterator<char, std::char_traits<char> >]'
/usr/local/include/c++/3.3/bits/locale_facets.h:871:   instantiated from 
`_OutIter std::num_put<_CharT, _OutIter>::put(_OutIter, std::ios_base&, _CharT, 
long unsigned int) const [with _CharT = char, _OutIter = 
std::ostreambuf_iterator<char, std::char_traits<char> >]'
/usr/local/include/c++/3.3/bits/ostream.tcc:223:   instantiated from 
`std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, 
_Traits>::operator<<(long unsigned int) [with _CharT = char, _Traits = 
std::char_traits<char>]'
/usr/local/include/c++/3.3/ostream:196:   instantiated from 
`std::basic_ostream<_CharT, _Traits>& std::basic_ostream<_CharT, 
_Traits>::operator<<(int) [with _CharT = char, _Traits = 
std::char_traits<char>]'
demo.cc:7:   instantiated from here
/usr/local/include/c++/3.3/bits/stl_alloc.h:562: warning: cast from `char*' to `
   std::__default_alloc_template<true, 0>::_Obj*' increases required alignment 
   of target type
/usr/local/include/c++/3.3/bits/stl_alloc.h:563: warning: cast from `char*' to `
   std::__default_alloc_template<true, 0>::_Obj*' increases required alignment 
   of target type
/usr/local/include/c++/3.3/bits/stl_alloc.h:567: warning: cast from `char*' to `
   std::__default_alloc_template<true, 0>::_Obj*' increases required alignment 
   of target type
g++ demo.o -o demo



The warning does not show up if optimize levels of -O -O0 -O2 are used.

I don't think it is supposed to do that.

-Grant



------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.



More information about the Gcc-bugs mailing list