Bug 71685 - [6 Regression] Segmentation fault in gcc when compiling the attached file.
Summary: [6 Regression] Segmentation fault in gcc when compiling the attached file.
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 6.1.1
: P3 normal
Target Milestone: 6.2
Assignee: Jakub Jelinek
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-06-28 15:04 UTC by vtselfa
Modified: 2016-07-04 09:36 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2016-06-28 00:00:00


Attachments
Reduced file that triggers the segfault (342 bytes, text/plain)
2016-06-28 15:04 UTC, vtselfa
Details
gcc7-pr71685.patch (547 bytes, patch)
2016-06-28 15:57 UTC, Jakub Jelinek
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description vtselfa 2016-06-28 15:04:58 UTC
Created attachment 38782 [details]
Reduced file that triggers the segfault
Comment 1 Jakub Jelinek 2016-06-28 15:19:10 UTC
Reduced testcase:
extern struct S v, s;
struct S { int t; int p[]; } v = { 4, 0 };
Comment 2 Jakub Jelinek 2016-06-28 15:26:06 UTC
Started with r229505.
Comment 3 Jakub Jelinek 2016-06-28 15:57:13 UTC
Created attachment 38783 [details]
gcc7-pr71685.patch

Untested fix.
Comment 4 Jim Wilson 2016-06-28 16:25:28 UTC
The problem here is that I assumed that c_build_qualified_type would only be called when we want to create a variant type.  However, there are a number of places that call it without checking to see if we have any type qualifiers first.  These places can call it with no qualifiers, in which case it returns the original type, which may be a main variant type.  So we need to avoid clearing C_TYPE_INCOMPLETE_TYPE in that case.  Perhaps with an early exit at the top if type_quals is 0.  Or alternatively, at the bottom, we can clear C_TYPE_INCOMPLETE_TYPE only if var_type != type.
Comment 5 Jakub Jelinek 2016-06-28 22:30:48 UTC
Author: jakub
Date: Tue Jun 28 22:30:04 2016
New Revision: 237830

URL: https://gcc.gnu.org/viewcvs?rev=237830&root=gcc&view=rev
Log:
	PR c/71685
	* c-typeck.c (c_build_qualified_type): Don't clear
	C_TYPE_INCOMPLETE_VARS for the main variant.

	* gcc.dg/pr71685.c: New test.

Added:
    trunk/gcc/testsuite/gcc.dg/pr71685.c
Modified:
    trunk/gcc/c/ChangeLog
    trunk/gcc/c/c-typeck.c
    trunk/gcc/testsuite/ChangeLog
Comment 6 Jakub Jelinek 2016-06-28 22:33:54 UTC
Fixed on the trunk so far.
Comment 7 Jim Wilson 2016-06-28 23:27:39 UTC
An early exit if type_quals is 0 does not work, as there is at least one place that deliberately calls c_build_qualified_type with no type qualifiers to create an unqualified type from a qualified type.  Likewise, my earlier suggestion of a check for var_type != type can't work as it fails in this case too.

I can see another possible fix, checking for type_quals non-zero before clearing the C_TYPE_INCOMPLETE_VARS, but given how complicated this code is turning out to be, the check for a type main variant is the safest fix.  And I see that Jakub has just checked in a patch for that solution, so I'm assuming I don't need to do anymore work on this.
Comment 8 Jakub Jelinek 2016-07-02 10:22:43 UTC
Author: jakub
Date: Sat Jul  2 10:22:11 2016
New Revision: 237940

URL: https://gcc.gnu.org/viewcvs?rev=237940&root=gcc&view=rev
Log:
	Backported from mainline
	2016-06-29  Jakub Jelinek  <jakub@redhat.com>

	PR c/71685
	* c-typeck.c (c_build_qualified_type): Don't clear
	C_TYPE_INCOMPLETE_VARS for the main variant.

	* gcc.dg/pr71685.c: New test.

Added:
    branches/gcc-6-branch/gcc/testsuite/gcc.dg/pr71685.c
Modified:
    branches/gcc-6-branch/gcc/c/ChangeLog
    branches/gcc-6-branch/gcc/c/c-typeck.c
    branches/gcc-6-branch/gcc/testsuite/ChangeLog
Comment 9 Jakub Jelinek 2016-07-04 09:36:03 UTC
Fixed.