home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / gnu / gcc / bug / 3083 < prev    next >
Encoding:
Text File  |  1992-12-30  |  12.0 KB  |  324 lines

  1. Newsgroups: gnu.gcc.bug
  2. Path: sparky!uunet!paladin.american.edu!darwin.sura.net!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!geom.umn.edu!nils
  3. From: nils@geom.umn.edu
  4. Subject: (none)
  5. Message-ID: <9212300518.AA05122@raisin-nut>
  6. Sender: gnulists@ai.mit.edu
  7. Organization: GNUs Not Usenet
  8. Distribution: gnu
  9. Date: Tue, 29 Dec 1992 15:02:24 GMT
  10. Approved: bug-gcc@prep.ai.mit.edu
  11. Lines: 311
  12.  
  13. Newsgroups: comp.std.c
  14. Path: news.cis.umn.edu!umn.edu!spool.mu.edu!wupost!csus.edu!netcom.com!rfg
  15. From: rfg@netcom.com (Ronald F. Guilmette)
  16. Subject: Standard conformance and GCC 2.3.3
  17. Message-ID: <1992Dec30.011211.11409@netcom.com>
  18. Organization: Netcom - Online Communication Services  (408 241-9760 guest) 
  19. Date: Wed, 30 Dec 1992 01:12:11 GMT
  20. Lines: 301
  21.  
  22.  
  23. The following testing report for GCC 2.3.3 may be of interest to readers of
  24. the comp.std.c newsgroup.
  25.  
  26. GCC is often held up as an example of a compiler which conforms well to the
  27. ANSI C standard.  In this report, I note a number of instances in which the
  28. most recent version of GCC fails to act in a fully conformant fashion.
  29. This report, and the examples given within it, may prove useful for some
  30. readers of comp.std.c who are attempting to assess the level of standard
  31. conformace provided by GCC and/or by other C compilers claiming to conform
  32. to the ANSI C standard.
  33.  
  34. // rfg
  35.  
  36.  
  37. =============================================================================
  38. I have just finished running my own tests on the recently released GCC 2.3.3.
  39. These tests reveal twenty bugs, all of which are described below.
  40.  
  41. The tests were run on a copy of GCC 2.3.3 which was the final product of a
  42. full three stage bootstrap for/on an i486 system running SVR4.  (The target
  43. configuration for the compiler was i486-svr4.)
  44.  
  45. All tests were run with the following GCC options in effect:
  46.  
  47.     -ansi -pedantic-errors -fno-common -w -O
  48.  
  49. Note that the -O (optimization) option seems to have no relevance to any of
  50. the bugs I have found.
  51.  
  52. Also note that most of the bugs described below are "platform independent"
  53. and I would expect them to afflict GCC when it is hosted and/or targeted
  54. to platforms other than i486/svr4 as well.
  55.  
  56. Most (but not all) of these twenty bugs are problems with standard conformance.
  57. GCC is either issuing errors for valid ANSI C code or else it is failing to
  58. issue errors for constructs which violate some constraint given in the ANSI
  59. C standard.
  60.  
  61. -----------------------------------------------------------------------------
  62. #1)  GCC fails to detect the error in the following code, even when the
  63.      -pedantic-errors option is used.
  64.  
  65. void foo ()
  66. {
  67.   extern void bar (int i, ...);
  68.  
  69.   bar (99, 88, 77);
  70. }
  71.  
  72. void bar (int i, int j, int k) { }      /* ERROR */
  73. -----------------------------------------------------------------------------
  74. #2)  GCC fails to detect the error in the following code, even when the
  75.      -pedantic-errors option is used.
  76.  
  77. unsigned long overflow = LONG_MAX + 3; /* ERROR */
  78. -----------------------------------------------------------------------------
  79. #3)  GCC incorrectly flags an error on the following standard-conformant code
  80.      when the -pedantic-errors option is in effect.
  81.  
  82. typedef int T;
  83. void test_1 (int T) { }
  84. -----------------------------------------------------------------------------
  85. #4)  On x86 machines, GCC fails to properly implement explicit floating-point
  86.      casts of those floating-point expressions which get evaluated using the
  87.      (internal) 80-bit floating-point format.  This causes the following
  88.      program to yield a non-zero exit status.
  89.  
  90. double point_four = 0.4;
  91. double point_one_six;
  92.  
  93. int
  94. main ()
  95. {
  96.   point_one_six = (point_four * point_four);
  97.   if ((double)(point_four * point_four) != point_one_six)
  98.     {
  99.       return 1;
  100.     }
  101.   return 0;
  102. }
  103. -----------------------------------------------------------------------------
  104. #5)  GCC incorrectly issues an error for the following standard-conformant
  105.      code.  (Note that `wchar_t' is the same as type `long int' on i486-svr4.)
  106.  
  107. typedef long int wchar_t;
  108. wchar_t array5[4] = L"abcd";
  109. -----------------------------------------------------------------------------
  110. #6)  The following erroneous code causes GCC to crash with a signal 6.
  111.  
  112. extern volatile struct s evs;
  113. void evs_test () { evs; }
  114. -----------------------------------------------------------------------------
  115. #7)  When compiling an empty source file while the -pedantic-errors option
  116.      is in effect, GCC will generate an error message for a line number which
  117.      does not actually exist in the source file.  (The line number indicated
  118.      in the error message is equal to the number of lines actually in the
  119.      file plus one.)  Issuing error messages which reference non-existant
  120.      source lines may cause some related tools (e.g. emacs) to go bonkers.
  121. -----------------------------------------------------------------------------
  122. #8)  GCC fails to issue errors for the following erroneous code, even when
  123.      the -pedantic-errors option is in effect.  (Note that the argument type
  124.      for the function is *not* a type which would result from integral
  125.      promotions.)
  126.  
  127. void test_0 (char);
  128. void test_0 (c) char c; { }
  129. -----------------------------------------------------------------------------
  130. #9)  GCC fails to issue errors in cases where a static function is referenced
  131.      but never defined, even when the -pedantic-errors option is used.
  132.  
  133.      Example:
  134.  
  135. static void s (); int main () { s (); return 1; }
  136. -----------------------------------------------------------------------------
  137. #10)  GCC fails to issue an error for the following invalid C code, even when
  138.       the -pedantic-errors option is used.
  139.  
  140. void (*func_ptr) ();
  141. int i;
  142. void test () { func_ptr = i ? 0 : 0; }         /* ERROR */
  143. -----------------------------------------------------------------------------
  144. #11)  GCC fails to issue errors for the following invalid C code involving
  145.       comparison operators, even when the -pedantic-errors option is used.
  146.  
  147. typedef int b_array[3];
  148. typedef int u_array[];
  149.  
  150. typedef b_array *b_array_ptr;
  151. typedef u_array *u_array_ptr;
  152.  
  153. b_array b_array_src;
  154. extern u_array u_array_src;
  155. int *ip;
  156. int i;
  157. b_array_ptr b_array_dest;
  158. u_array_ptr u_array_dest;
  159.  
  160. void test_relational_operators ()
  161. {
  162.   i = & u_array_src > & b_array_src;            /* ERROR */
  163.   i = & b_array_src > & u_array_src;            /* ERROR */
  164.  
  165.   i = & u_array_src <= & b_array_src;           /* ERROR */
  166.   i = & b_array_src <= & u_array_src;           /* ERROR */
  167.  
  168.   i = u_array_dest > b_array_dest;              /* ERROR */
  169.   i = b_array_dest > u_array_dest;              /* ERROR */
  170.  
  171.   i = u_array_dest <= b_array_dest;             /* ERROR */
  172.   i = b_array_dest <= u_array_dest;             /* ERROR */
  173. }
  174.  
  175. int u_array_src[20] = { 0 };    /* complete its type */
  176. -----------------------------------------------------------------------------
  177. #12)  GCC fails to issue errors for the following invalid C code involving
  178.       the binary `-' operator, even when the -pedantic-errors option is used.
  179.  
  180. typedef int b_array[3];
  181. typedef int u_array[];
  182.  
  183. typedef b_array *b_array_ptr;
  184. typedef u_array *u_array_ptr;
  185.  
  186. b_array b_array_src;
  187. extern u_array u_array_src;
  188. int *ip;
  189. int i;
  190. b_array_ptr b_array_dest;
  191. u_array_ptr u_array_dest;
  192.  
  193. void test_pointer_subtraction ()
  194. {
  195.   i = & u_array_src - & b_array_src;            /* ERROR */
  196.   i = & b_array_src - & u_array_src;            /* ERROR */
  197.  
  198.   i = u_array_dest - b_array_dest;              /* ERROR */
  199.   i = b_array_dest - u_array_dest;              /* ERROR */
  200. }
  201.  
  202. int u_array_src[20] = { 0 };    /* complete its type */
  203. -----------------------------------------------------------------------------
  204. #13)  GCC fails to issue errors for the following invalid C code involving
  205.       invalid null pointer constants, even when the -pedantic-errors option
  206.       is used.  (GCC also fails to properly flag these kinds of invalid
  207.       null pointer constants in other contexts as well.)
  208.  
  209. int (*fp) ();
  210. void test () { fp = (void *) (void *) 0; }    /* ERROR */
  211. -----------------------------------------------------------------------------
  212. #14)  GCC fails to issue errors for the following invalid C code involving
  213.       invalid pointer type conversions, even when the -pedantic-errors option
  214.       is used.
  215.  
  216. struct incomp1; /* never completed */
  217. struct incomp2; /* completed towards the end - may make a difference */
  218.  
  219. typedef int             *p_to_object_type;
  220. typedef struct incomp1  *p_to_incomp1_type;
  221. typedef struct incomp2  *p_to_incomp2_type;
  222. typedef int             (*p_to_func_type) ();
  223.  
  224. p_to_object_type        p_to_object_value;
  225. p_to_incomp1_type       p_to_incomp1_value;
  226. p_to_incomp2_type       p_to_incomp2_value;
  227. p_to_func_type          p_to_func_value;
  228.  
  229. void
  230. test ()
  231. {
  232.   p_to_func_value = (p_to_func_type) p_to_object_value;         /* ERROR */
  233.   p_to_func_value = (p_to_func_type) p_to_incomp1_value;        /* ERROR */
  234.   p_to_func_value = (p_to_func_type) p_to_incomp2_value;        /* ERROR */
  235. }
  236.  
  237. struct incomp2 { int i; };
  238. -----------------------------------------------------------------------------
  239. #15)  GCC fails to issue errors for the following invalid C code involving
  240.       invalid pointer type conversions, even when the -pedantic-errors option
  241.       is used.
  242.  
  243. struct incomp1; /* never completed */
  244. struct incomp2; /* completed towards the end - may make a difference */
  245.  
  246. typedef int             *p_to_object_type;
  247. typedef struct incomp1  *p_to_incomp1_type;
  248. typedef struct incomp2  *p_to_incomp2_type;
  249. typedef int             (*p_to_func_type) ();
  250.  
  251. p_to_object_type        p_to_object_value;
  252. p_to_incomp1_type       p_to_incomp1_value;
  253. p_to_incomp2_type       p_to_incomp2_value;
  254. p_to_func_type          p_to_func_value;
  255.  
  256. void
  257. test ()
  258. {
  259.   p_to_object_value = (p_to_object_type) p_to_func_value;       /* ERROR */
  260.   p_to_incomp1_value = (p_to_incomp1_type) p_to_func_value;     /* ERROR */
  261.   p_to_incomp2_value = (p_to_incomp2_type) p_to_func_value;     /* ERROR */
  262. }
  263.  
  264. struct incomp2 { int i; };
  265. -----------------------------------------------------------------------------
  266. #16)  GCC fails to issue errors for the following invalid C code involving
  267.       local redeclarations of objects, even when the -pedantic-errors option
  268.       is used.
  269.  
  270. static int object_decl_6;
  271. static int object_defn_6 = 0;
  272.  
  273. void
  274. test ()
  275. {
  276.     extern double object_decl_6;                /* ERROR */
  277.     extern double object_defn_6;                /* ERROR */
  278. }
  279. -----------------------------------------------------------------------------
  280. #17)  GCC fails to issue errors for the following invalid C code involving
  281.       incompatible redeclarations, even when the -pedantic-errors option
  282.       is used.
  283.  
  284. void callee (char c);
  285. void foobar () { void callee(); }     /* ERROR */
  286. void callee (char c) { }
  287. -----------------------------------------------------------------------------
  288. #18)  GCC incorrectly issues an error for the following standard-conformant
  289.       ANSI C code when the -pedantic-errors option is used.
  290.  
  291. extern const int func_1 ();
  292. -----------------------------------------------------------------------------
  293. #19)  GCC fails to issue an error for the following pair of incompatible
  294.       function declarations, even when the -pedantic-errors option is used.
  295.  
  296. extern const int func_4 ();
  297. extern int func_4 ();                   /* ERROR */
  298. -----------------------------------------------------------------------------
  299. #20)  GCC incorrectly issues errors for the following standard-conformant
  300.       ANSI C code when the -pedantic-errors option is used.
  301.  
  302. static enum E1 { red, green, blue};
  303. static struct S1 { int member; };
  304. static union U2 { int member; };
  305.  
  306. void foobar ()
  307. {
  308.     auto enum E2 { red, green, blue };
  309.     auto struct S2 { int member; };
  310.     auto union U2 { int member; };
  311. }
  312. -----------------------------------------------------------------------------
  313. -- 
  314.  
  315. // Ron ("Loose Cannon") Guilmette    uucp: ...uunet!lupine!segfault!rfg
  316. //
  317. //      "On the one hand I knew that programs could have a compelling
  318. //       and deep logical beauty, on the other hand I was forced to
  319. //       admit that most programs are presented in a way fit for
  320. //       mechanical execution, but even if of any beauty at all,
  321. //       totally unfit for human appreciation."
  322. //                                              -- Edsger W. Dijkstra
  323.  
  324.