Bug 61096 - error_init lacks a location
Summary: error_init lacks a location
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 5.0
: P3 normal
Target Milestone: 5.0
Assignee: Marek Polacek
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2014-05-07 14:36 UTC by Marek Polacek
Modified: 2014-05-09 17:52 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2014-05-07 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Marek Polacek 2014-05-07 14:36:19 UTC
Since error_init doesn't have a location parameter, all of these invalid initializers have wrong column info in diagnostics.

/* -std=gnu99 -fshort-enums -fshort-wchar -pedantic */

typedef enum { A } schar;
extern int e;
struct S
{
  int a[3];
};
struct f
{
  int w;
  int x[];
};
struct g
{
  struct f f;
};

char w1[] = L"foo";
__WCHAR_TYPE__ w2[] = "foo";
__WCHAR_TYPE__ w3[] = U "foo";
schar a1[] = "foo";
int a2[] = (int[]) { 1 };

int a3 = e;
int a4 = (e, 1);
int a5 = a1[0];
int a6 = &a3 - &a4;
int a7[] = a7;

struct S s = { {1}, {3} };
struct g g1 = { {0, {1}} };
struct g g2 = { .f[0] = 1 };

__extension__ int a8 = { };
int a9[10] = {[1.2] = 2 };
int a10[10] = {[e] = 2 };
__extension__ int a11[10] = {[1 ... e] = 1 };
int a12 = {[1] = 2 };
int a13[2] = {[-1] = 4 };
int a14[2] = {[64] = 4 };
__extension__ int a15[10] = {[2 ... 1] = 4 };
__extension__ int a16[10] = {[2 ... 100] = 4 };
int a17[] = { .B = 1 };
int a18[] = { e };
char a19[1] = { "x", "x" };

void
bar (void)
{
  struct f f = { 2, "c" };
}
Comment 1 Marek Polacek 2014-05-07 14:36:52 UTC
Another testcase:

struct s { char c[1]; };
extern struct s foo (void);

void
bar (void)
{
  char *t = (foo ()).c;
}
Comment 2 Marek Polacek 2014-05-07 14:52:01 UTC
Another testcase:

struct
{
  char *v;
} s[] = { .v = 0 };
Comment 3 Marek Polacek 2014-05-07 15:01:07 UTC
Note that there are 3 error_init calls that seem unreachable (?):

 6783 
 6784   if (COMPLETE_TYPE_P (type) && TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
 6785     {
 6786       error_init ("variable-sized object may not be initialized");
 6787       return error_mark_node;
 6788     }

 7491       else if (vec_safe_length (constructor_elements) != 1)
 7492         {
 7493           error_init ("extra elements in scalar initializer");
 7494           ret.value = (*constructor_elements)[0].value;
 7495         }

 8590   if (constructor_stack->replacement_value.value != 0)
 8591     {
 8592       error_init ("excess elements in struct initializer");
 8593       return;
 8594     }
Comment 4 Marek Polacek 2014-05-09 17:50:58 UTC
Author: mpolacek
Date: Fri May  9 17:50:25 2014
New Revision: 210280

URL: http://gcc.gnu.org/viewcvs?rev=210280&root=gcc&view=rev
Log:
	PR c/61096
	* c-parser.c (c_parser_braced_init): Pass brace_loc to push_init_level.
	(c_parser_initelt): Pass location to set_init_label.  Pass array index
	location to set_init_index.
	* c-tree.h (push_init_level): Update declaration.
	(pop_init_level): Likewise.
	(set_init_index): Likewise.
	(set_init_label): Likewise.
	* c-typeck.c (error_init): Add location parameter.  Call error_at
	instead of error.
	(digest_init): Pass init_loc to error_init.
	(really_start_incremental_init):
	(push_init_level): Add location parameter.  Pass loc to pop_init_level
	and error_init.
	(pop_init_level): Likewise.
	(set_designator): Add location parameter.  Pass loc to pop_init_level,
	push_init_level, and error_init.
	(set_init_index): Add location parameter.  Pass loc to error_init and
	set_designator.
	(set_init_label): Likewise.
	(output_init_element): Pass loc to error_init.
	(process_init_element): Pass loc to error_init, pop_init_level,
	pedwarn_init, and push_init_level.

	* gcc.dg/pr61096-1.c: New test.
	* gcc.dg/pr61096-2.c: New test.

Added:
    trunk/gcc/testsuite/gcc.dg/pr61096-1.c
    trunk/gcc/testsuite/gcc.dg/pr61096-2.c
Modified:
    trunk/gcc/c/ChangeLog
    trunk/gcc/c/c-parser.c
    trunk/gcc/c/c-tree.h
    trunk/gcc/c/c-typeck.c
    trunk/gcc/testsuite/ChangeLog
Comment 5 Marek Polacek 2014-05-09 17:52:08 UTC
Fixed.