-
Notifications
You must be signed in to change notification settings - Fork 3k
Uninitialized variable warning in UARTSerial at -O3 #6611
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
690c8a4
to
a75201e
Compare
drivers/UARTSerial.cpp
Outdated
@@ -305,11 +305,11 @@ void UARTSerial::rx_irq(void) | |||
void UARTSerial::tx_irq(void) | |||
{ | |||
bool was_full = _txbuf.full(); | |||
char data = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't this now just masking the problem, which the compiler correctly warned for: if "CricularBuffer::pop()" returns false, the data -variable should not be forwarded to SerialBase::_base_putc()?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unless there's threading issues involved here, I don't think that pop()
will return false because of the check to empty()
The compiler is not able to make that rationalization, so I'm not sure if testing the return value of pop()
would help.
I suppose that it's writable as
char data;
/* Write to the peripheral if there is something to write
* and if the peripheral is available to write. */
while (SerialBase::writeable() && _txbuf.pop(data)) {
SerialBase::_base_putc(data);
}
Huh, it seems that the compiler was able to analyze the check to pop()
after all, with that change I don't get a warning.
I switched the conditional so that it short-circuits the call to pop()
if the object isn't writable.
I would go either way, within an IRQ I think that it's safe to call pop
after !empty
I chose the path of minimal change but could switch.
pop
calls empty
internally, so the end result is the same.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this version in the comment without the empty check is better. I think it's only the way it is because it's was imitating the read case.
Appears when complied with -O3 optimization level Compile: UARTSerial.cpp ../drivers/UARTSerial.cpp: In member function 'void mbed::UARTSerial::tx_irq()': ../drivers/UARTSerial.cpp:314:31: warning: 'data' may be used uninitialized in this function [-Wmaybe-uninitialized] SerialBase::_base_putc(data);
a75201e
to
d6c5f16
Compare
Starting CI since it looks like most recent commit addresses @kjbracey-arm' feedback. /morph build |
Build : SUCCESSBuild number : 1765 Triggering tests/morph test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. Pondered performance a bit - this does mean one more serial_writable
call per IRQ if we're not saturating the serial port, but does significantly decrease the number of circular buffer calls (which are a bit clunky with IRQ enable/disable). Should be a net performance win when highly loaded, I hope.
Exporter Build : FAILUREBuild number : 1402 |
/morph export-build |
Exporter Build : SUCCESSBuild number : 1409 |
/morph mbed2-build |
Attempting the close/reopen trick. |
Build : SUCCESSBuild number : 1779 Triggering tests/morph test |
Exporter Build : SUCCESSBuild number : 1420 |
1 similar comment
Exporter Build : SUCCESSBuild number : 1420 |
/morph test |
/morph export-build |
/morph mbed2-build |
Exporter Build : SUCCESSBuild number : 1451 |
Description
Appears when complied with -O3 optimization level
Pull request type
[X] Fix
[ ] Refactor
[ ] New target
[ ] Feature
[ ] Breaking change