I just tried to compile a small piece of source code with
the new GNU C compiler version 4.2 snapshot 20060506. 

The compiler snapshot said

[EMAIL PROTECTED]:~/gnu/42-20060506/bugs> ~/gnu/42-20060506/results/bin/g++ -c 
-O3
bug16.cc
bug16.cc: In function 'bool cross(const LineSegment&, const LineSegment&)':
bug16.cc:49: internal compiler error: Segmentation fault
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.

Preprocessed source code attached.  Flag -O3 required.
This code compiled ok on the previous snapshot 20060429.

Valgrind says the following

==9134== Invalid read of size 2
==9134==    at 0x98D8F7: hash_descriptor_pre_extension (see.c:837)
==9134==    by 0x9C92E1: htab_find_slot (hashtab.c:657)
==9134==    by 0x98E5B7: see_seek_pre_extension_expr (see.c:1036)
==9134==    by 0x98E6E7: see_set_prop_unmerged_def (see.c:2280)
==9134==    by 0x9C89F7: htab_traverse_noresize (hashtab.c:729)
==9134==    by 0x98E497: see_handle_extensions_for_one_ref (see.c:2986)
==9134==    by 0x9C9B68: splay_tree_foreach_helper (splay-tree.c:218)
==9134==    by 0x990D10: see_main (see.c:3021)
==9134==    by 0x9913D5: rest_of_handle_see (see.c:3754)
==9134==    by 0x88E24A: execute_one_pass (passes.c:864)
==9134==    by 0x88E3BB: execute_pass_list (passes.c:911)
==9134==    by 0x88E3CD: execute_pass_list (passes.c:912)
==9134==  Address 0x0 is not stack'd, malloc'd or (recently) free'd

The source code is

struct Point
{
 float x;
 float y;
};

struct LineSegment
{
 Point start;
 Point end;
};

inline float min( float x, float y)
{
 return (x < y) ? x : y;
}

inline float max( float x, float y)
{
 return (x > y) ? x : y;
}

bool
cross( const LineSegment & ls1, const LineSegment & ls2)
{
 const float slope1 = (ls1.end.y - ls1.start.y) / (ls1.end.x - ls1.start.x);
 const float intercept1 = ls1.end.y - (slope1 * ls1.end.x);

 const float slope2 = (ls2.end.y - ls2.start.y) / (ls2.end.x - ls2.start.x);
 const float intercept2 = ls2.end.y - (slope2 * ls2.end.x);

 if (slope1 == slope2)
 {
  return (intercept1 == intercept2);
 }
 const float x = (intercept1 - intercept2) / (slope2 - slope1);

 const float ls1minx = min( ls1.start.x, ls1.end.x);
 const float ls1maxx = max( ls1.start.x, ls1.end.x);

 if ((ls1minx < x) && (x < ls1maxx))
 {
  const float ls2minx = min( ls2.start.x, ls2.end.x);
  const float ls2maxx = max( ls2.start.x, ls2.end.x);

  return (ls2minx < x) && (x < ls2maxx);
 }
}


-- 
           Summary: ice for legal code
           Product: gcc
           Version: 4.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: dcb314 at hotmail dot com
  GCC host triplet: i686-pc-linux-gnu


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

Reply via email to