[Bug c/57813] Change of global variable ignored

2013-07-03 Thread manu at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57813

--- Comment #9 from Manuel López-Ibáñez  ---
(In reply to Daniel Oertwig from comment #8)
> Ok, so: Is this behaviour "part" of the language or a bug in gcc?
> I could not find any documentation specifying that a sequence point should
> be inbetween the (side-effect) evaluation of the function call and the
> (value) evaluation of the assignment.

http://c-faq.com/expr/seqpoints.html
http://en.wikipedia.org/wiki/Sequence_point

[Bug c/57813] Change of global variable ignored

2013-07-03 Thread daniel.oertwig at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57813

--- Comment #8 from Daniel Oertwig  ---
Ok, so: Is this behaviour "part" of the language or a bug in gcc?
I could not find any documentation specifying that a sequence point should be
inbetween the (side-effect) evaluation of the function call and the (value)
evaluation of the assignment.


[Bug c/57813] Change of global variable ignored

2013-07-03 Thread manu at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57813

Manuel López-Ibáñez  changed:

   What|Removed |Added

 CC||manu at gcc dot gnu.org

--- Comment #7 from Manuel López-Ibáñez  ---
> (In reply to Daniel Oertwig from comment #5)
> > (In reply to Andrew Pinski from comment #3)
> > >   taskInfo.ready[priority]->wakeTime = Task_enforceTimeslice(priority);
> > > 
> > > This is the same as:
> > >   (*taskInfo.ready[priority]).wakeTime = Task_enforceTimeslice(priority);
> > > 
> > > Which means either the compiler can read the value of
> > > taskInfo.ready[priority] before or after the function call to
> > > Task_enforceTimeslice because there is no sequence point between them.
> > 
> > Shouldn't the compiler recognize that enforceTimeslice is altering the
> > global variable?

The GCC code that could warn about this does not look within functions being
called, so GCC does not know what enforeTimeslice is doing. Implementing this
would require a substantial amount of work, and the current devs have their
hands pretty full. Perhaps cppcheck or clang-analyzer can detect this case, but
I wouldn't be surprised if they can't.

[Bug c/57813] Change of global variable ignored

2013-07-03 Thread pinskia at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57813

Andrew Pinski  changed:

   What|Removed |Added

 Status|UNCONFIRMED |RESOLVED
 Resolution|--- |INVALID

--- Comment #6 from Andrew Pinski  ---
(In reply to Daniel Oertwig from comment #5)
> (In reply to Andrew Pinski from comment #3)
> > taskInfo.ready[priority]->wakeTime = Task_enforceTimeslice(priority);
> > 
> > This is the same as:
> > (*taskInfo.ready[priority]).wakeTime = Task_enforceTimeslice(priority);
> > 
> > Which means either the compiler can read the value of
> > taskInfo.ready[priority] before or after the function call to
> > Task_enforceTimeslice because there is no sequence point between them.
> 
> Shouldn't the compiler recognize that enforceTimeslice is altering the
> global variable?

No because without sequence point the left hand side or right hand side can be
done first.

[Bug c/57813] Change of global variable ignored

2013-07-03 Thread daniel.oertwig at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57813

--- Comment #5 from Daniel Oertwig  ---
(In reply to Andrew Pinski from comment #3)
>   taskInfo.ready[priority]->wakeTime = Task_enforceTimeslice(priority);
> 
> This is the same as:
>   (*taskInfo.ready[priority]).wakeTime = Task_enforceTimeslice(priority);
> 
> Which means either the compiler can read the value of
> taskInfo.ready[priority] before or after the function call to
> Task_enforceTimeslice because there is no sequence point between them.

Shouldn't the compiler recognize that enforceTimeslice is altering the global
variable?

[Bug c/57813] Change of global variable ignored

2013-07-03 Thread daniel.oertwig at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57813

Daniel Oertwig  changed:

   What|Removed |Added

 Status|RESOLVED|UNCONFIRMED
 Resolution|INVALID |---

--- Comment #4 from Daniel Oertwig  ---

Task * Task_getNextReady()
{
uint8_t priority;
if (taskInfo.ready[0]) priority = 0;
else if (taskInfo.ready[1]) priority = 1;
else if (taskInfo.ready[2]) priority = 2;
else if (taskInfo.ready[3]) priority = 3;
else if (taskInfo.ready[4]) priority = 4;
else if (taskInfo.ready[5]) priority = 5;
else if (taskInfo.ready[6]) priority = 6;
else priority = 7;
time_t delay = Task_enforceTimeslice(priority);
Task * next = taskInfo.ready[priority];
next->wakeTime = delay;
return next;
}

This code solves the issue, using the correct value of the global variable.
Please tell me if I am wrong, but I think this code should be equivalent to the
original code.

(Task_enforceTimeslice is not declared as pure, I checked just to be sure)


[Bug c/57813] Change of global variable ignored

2013-07-03 Thread pinskia at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57813

Andrew Pinski  changed:

   What|Removed |Added

 Status|UNCONFIRMED |RESOLVED
 Resolution|--- |INVALID

--- Comment #3 from Andrew Pinski  ---
taskInfo.ready[priority]->wakeTime = Task_enforceTimeslice(priority);

This is the same as:
(*taskInfo.ready[priority]).wakeTime = Task_enforceTimeslice(priority);

Which means either the compiler can read the value of taskInfo.ready[priority]
before or after the function call to Task_enforceTimeslice because there is no
sequence point between them.


[Bug c/57813] Change of global variable ignored

2013-07-03 Thread daniel.oertwig at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57813

--- Comment #2 from Daniel Oertwig  ---
Oh, I am compiling with:

CFLAGS := 
CFLAGS += -Os
CFLAGS += -funsigned-char
CFLAGS += -funsigned-bitfields
CFLAGS += -fpack-struct
CFLAGS += -fshort-enums
CFLAGS += -ffreestanding
CFLAGS += -Wall -Wextra
CFLAGS += -Wstrict-prototypes
CFLAGS += -Wundef
CFLAGS += -Wsign-compare
CFLAGS += -std=gnu99 #-std=c99
CFLAGS += -g3 -gdwarf-2 -pg
CFLAGS += -fstack-usage


LDFLAGS :=
LDFLAGS += -Wl,--relax

using avr-gcc. There are no warnings.


[Bug c/57813] Change of global variable ignored

2013-07-03 Thread daniel.oertwig at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57813

--- Comment #1 from Daniel Oertwig  ---
Created attachment 30451
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=30451&action=edit
Disassembly of the relating parts (from *.elf file, i.e. after linking)