home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / std / c / 3280 < prev    next >
Encoding:
Text File  |  1992-12-29  |  11.6 KB  |  311 lines

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