|<< Back to previous view|
[PCC-316] ccom crashes due to SIGFPE Created: 13/Apr/11 Updated: 14/Aug/11
|Reporter:||Fred J. Tydeman||Assignee:||Anders Magnusson|
|Environment:||Intel Core i5 (64 bit); Linux Fedora Core 14 (64 bit); pcc of 2011/02/21|
Code similar to :
#define __STDC_WANT_DEC_FP__ /* Tell implementation that we want Decimal FP */
void * rc1,rc2;
void * ptrv2;
ptrv2 = ((void *)&ptrv2) ;
rc1 = (ptrv2 ++);
rc2 = (ptrv2 --);
return rc1 != rc2;
gets a core dump in the compiler. The automatic bug reporting tool on Linux says
process ccom was killed by signal 8 (SIGFPE). Since there is no floating-point in
my C program, that makes no sense to me.
|Comment by Iain Hibbert [ 23/Apr/11 12:47 PM ]|
First, the "void *rc1, rc2;" line might be missing a '*' before rc2?
This fails compilation (with errors) on my NetBSD/i386 system.. adding that
and the program compiles and runs with exit value 1
Then, I don't see the relevance of __STDC_WANT_DEC_FP__ since that string
does not appear anywhere in the pcc sources.. Is an include file from your
environment being brought in somehow?
|Comment by Fred J. Tydeman [ 23/Apr/11 05:04 PM ]|
You are correct that I need a '*' before rc2.
The program should not compile. Since ptrv2 is pointing to void, ptrv2++ makes so sense.
The compile does not know how much to alter ptrv2 by. That is the purpose of the little test program.
|Comment by Fred J. Tydeman [ 23/Apr/11 05:06 PM ]|
__STDC_WANT_DEC_FP__ should have no effect here (there is no Decimal floating-point).
But, just in case pcc supports it, and my test had it, I included it.
|Comment by Iain Hibbert [ 23/Apr/11 06:40 PM ]|
the C99 spec seems pretty quiet on this point, but gcc does also assign void and function
types a sizeof 1 for convenience with pointer calculations, and only generates a warning
if -Wpointer-arith is given (this is not included by -Wall)
pcc accepts -Wpointer-arith but doesn't generate any warnings at this time
perhaps the SIGFPE was caused by a divide by zero relating to this?
|Comment by Fred J. Tydeman [ 24/Apr/11 06:33 AM ]|
"ptrv2++" violates a constraint of 6.5.6 additive operators (it is
NOT a pointer to a complete object type).
19 The void type comprises an empty set of values; it is an incomplete
object type that cannot be completed.
22.214.171.124 Lvalues, arrays, and function designators
1 An lvalue is an expression (with an object type other than void) that
potentially designates an object;64) if an lvalue does not designate
an object when it is evaluated, the behavior is undefined. When an
object is said to have a particular type, the type is specified by the
lvalue used to designate the object. A modifiable lvalue is an lvalue
that does not have array type, does not have an incomplete type, does
not have a const-qualified type, and if it is a structure or union,
does not have any member (including, recursively, any member or
element of all contained aggregates or unions) with a const-qualified
64) The name "lvalue" comes originally from the assignment expression
E1 = E2, in which the left operand E1 is required to be a (modifiable)
lvalue. It is perhaps better considered as representing an object
"locator value". What is sometimes called "rvalue" is in this
International Standard described as the "value of an expression".
An obvious example of an lvalue is an identifier of an object. As a
further example, if E is a unary expression that is a pointer to an
object, *E is an lvalue that designates the object to which E points.
126.96.36.199 Postfix increment and decrement operators
2 ... See the discussions of additive operators and compound
assignment for information on constraints, types, and conversions and
the effects of operations on pointers. ...
6.5.6 Additive operators
2 For addition, either both operands shall have arithmetic type, or
one operand shall be a pointer to a complete object type and the other
shall have integer type. (Incrementing is equivalent to adding 1.)
|Comment by Anders Magnusson [ 14/Aug/11 09:54 AM ]|
It do not crash anymore AFAICT.
But pcc allows arithmetic on void pointers since a few years ago, I had to add it since there were too much problems by not allowing it since gcc do not complain about it. Sometime it may be reasonable to disallow it again, but not yet.