Add codes in c-parser results in compilation error for gcc-4.7.2

k9119911 xxx-protoss@yahoo.com.tw
Fri Aug 7 23:23:00 GMT 2015


Hi

I have to modify the parser to have a shadow declaration for each pointer

field declared in a struct, so I add some codes in c-parser.c for gcc-4.7.2.

However, when I build the gcc-4.7.2, there are wired errors:

../../../gcc-4.7.2/libgcc/emutls.c:50:10: error: flexible array member not
at end of struct
In file included from ../../../gcc-4.7.2/libgcc/unwind-dw2.c:37:0:
../../../gcc-4.7.2/libgcc/unwind-dw2-fde.h:38:27: error: flexible array
member not at end of struct
../../../gcc-4.7.2/libgcc/unwind-dw2-fde.h:140:17: error: flexible array
member not at end of struct
../../../gcc-4.7.2/libgcc/unwind-dw2-fde.h:148:17: error: flexible array
member not at end of struct
In file included from ../../../gcc-4.7.2/libgcc/unwind-dw2-fde-dip.c:46:0:
../../../gcc-4.7.2/libgcc/unwind-dw2-fde.h:38:27: error: flexible array
member not at end of struct
../../../gcc-4.7.2/libgcc/unwind-dw2-fde.h:140:17: error: flexible array
member not at end of struct
../../../gcc-4.7.2/libgcc/unwind-dw2-fde.h:148:17: error: flexible array
member not at end of struct
make[2]: *** [emutls.o] Error 1
make[2]: *** Waiting for unfinished jobs....
../../../gcc-4.7.2/libgcc/unwind-dw2-fde-dip.c: In function
'_Unwind_IteratePhdrCallback':
../../../gcc-4.7.2/libgcc/unwind-dw2-fde-dip.c:374:24: warning: variable
'f_enc_size' set but not used [-Wunu   sed-but-set-variable]
make[2]: *** [unwind-dw2.o] Error 1
make[2]: *** [unwind-dw2-fde-dip.o] Error 1
In file included from
../../../../gcc-4.7.2/libgcc/unwind-dw2-fde-dip.c:46:0:
../../../../gcc-4.7.2/libgcc/unwind-dw2-fde.h:38:27: error: flexible array
member not at end of struct
../../../../gcc-4.7.2/libgcc/unwind-dw2-fde.h:140:17: error: flexible array
member not at end of struct
../../../../gcc-4.7.2/libgcc/unwind-dw2-fde.h:148:17: error: flexible array
member not at end of struct
../../../../gcc-4.7.2/libgcc/emutls.c:50:10: error: flexible array member
not at end of struct
In file included from ../../../../gcc-4.7.2/libgcc/unwind-dw2.c:37:0:
../../../../gcc-4.7.2/libgcc/unwind-dw2-fde.h:38:27: error: flexible array
member not at end of struct
../../../../gcc-4.7.2/libgcc/unwind-dw2-fde.h:140:17: error: flexible array
member not at end of struct
../../../../gcc-4.7.2/libgcc/unwind-dw2-fde.h:148:17: error: flexible array
member not at end of struct

Thus, I have to comment some of my codes out in c-parser.c and build it
without error at first.

Then I can un-comment those codes and build all of them successfully.

The following are my added codes in function
"static struct c_typespec c_parser_struct_or_union_specifier (c_parser
*parser)"

+2386   int is_user_def = 0;

+2435       /* For dual execution */
+2436       {
+2437         expanded_location el;
+2438
+2439         el = expand_location(struct_loc);
+2440         printf("c_parser_struct_or_union_specifier:%s:%d\n",
+2441             el.file, el.line);
+2442
+2443         /* We only declare shadow variable in user-defined structure
*/
+2444         if (strncmp(el.file, "/usr", 4) != 0)
+2445             is_user_def = 1;
+2446       }

+2506       if (is_user_def) {
+2507           if (TREE_CODE(TREE_TYPE(decls)) == POINTER_TYPE ||
+2508               TREE_CODE(TREE_TYPE(decls)) == ARRAY_TYPE)
+2509           {
+2510               tree shadow;
+2511               char buf[64];
+2512
+2513               sprintf(buf, "%s.shadow\0",
IDENTIFIER_POINTER(DECL_NAME(decls)));
+2514
+2515               shadow = build_decl(struct_loc, FIELD_DECL,
get_identifier(buf), TREE_TYPE(decls));
+2516
+2517               contents = chainon(shadow, contents);
+2518           }
+2519       }

If I comment out line 2513, 2515 or 2517, then everything goes fine without
error.

Is there any restriction for us to modify the c-parser.c?

Thanks




--
View this message in context: http://gcc.1065356.n5.nabble.com/Add-codes-in-c-parser-results-in-compilation-error-for-gcc-4-7-2-tp1175408.html
Sent from the gcc - Help mailing list archive at Nabble.com.



More information about the Gcc-help mailing list