This is the mail archive of the mailing list for the GCC project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug middle-end/24932] New: GCC segfault's on strcmp in tree.c:annotate_with_file_line

I'm writing a tutorial on a HelloWorld compiler front-end for GCC
( and noticed
that a function with statements but no DECL_SOURCE_FILE set, seg-faults on 
cgraph_finalize_function(), because it calls
gimple-low.c:lower_function_body(), which in turn does:

SET_EXPR_LOCATION (x, cfun->function_end_locus);

however, if cfun->function_end_locus is empty ({NULL, 0}), it will call
tree.c:annotate_with_file_line() with file=NULL, and it will fail on this "if":

  if (last_annotated_node
      && last_annotated_node->line == line
      && (last_annotated_node->file == file
          || !strcmp (last_annotated_node->file, file)))

because strcmp (last_annotated_node->file, file), with file=NULL will

The attached patch checks if file is NULL before using strcmp.

The program that fails build is:

           Summary: GCC segfault's on strcmp in
           Product: gcc
           Version: 4.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: barbieri at gmail dot com

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]