2.6.7 usb_lld_pump: no return statement

ChibiOS public support forum for topics related to the STMicroelectronics STM32 family of micro-controllers.

Moderator: RoccoMarco

Post Reply
User avatar
russian
Posts: 368
Joined: Mon Oct 29, 2012 3:17 am
Has thanked: 16 times
Been thanked: 14 times

2.6.7 usb_lld_pump: no return statement

Post by russian »

chibios/os/hal/platforms/STM32/OTGv1/usb_lld.c: In function 'usb_lld_pump':
chibios/os/hal/platforms/STM32/OTGv1/usb_lld.c:769:1: error: no return statement in function returning non-void [-Werror=return-type]
}
^
cc1.exe: all warnings being treated as errors
make: *** [build/obj/usb_lld.o] Error 1

that's because 'return 0;' was removed in 2.6.7 comparing with 2.6.6. That would be the only place where it complaints about no-return so I guess it should be?

Code: Select all

Index: hal/platforms/STM32/OTGv1/usb_lld.c
===================================================================
--- hal/platforms/STM32/OTGv1/usb_lld.c   (revision 6925)
+++ hal/platforms/STM32/OTGv1/usb_lld.c   (working copy)
@@ -766,6 +766,8 @@
     }
     chSysLock();
   }
+  // we are never here but GCC cannot figure this out
+  return 0;
 }
 
 #if STM32_USB_USE_OTG1 || defined(__DOXYGEN__)
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: 2.6.7 usb_lld_pump: no return statement

Post by Giovanni »

There are three compilers to consider:
GCC complains because there is no "return" statement even if it is obvious it cannot be reached.
IAR and Keil complain about an unreachable "return" statement.

2 vs 1

This is why you see that warning in all demos, in my opinion GCC is wrong in this case. The solution would be to make threads void-returning functions but I am not sure it would be a good idea.

Giovanni
User avatar
russian
Posts: 368
Joined: Mon Oct 29, 2012 3:17 am
Has thanked: 16 times
Been thanked: 14 times

Re: 2.6.7 usb_lld_pump: no return statement

Post by russian »

Oh, right - in fact I do have this issue with IAR with my own code. Because of that I do

#if defined __GNUC__
return 0;
#endif
dalbert
Posts: 16
Joined: Mon Mar 02, 2015 8:02 pm

Re: 2.6.7 usb_lld_pump: no return statement

Post by dalbert »

Another approach to disable the bogus warning for GCC is to disable the warning just for the problem function.

For example, my usb_lld.c is modified as follows:

#if defined __GNUC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wreturn-type"
#endif
static msg_t usb_lld_pump(void *p) {
...
}
#if defined __GNUC__
#pragma GCC diagnostic pop
#endif

It would be nice to remove the bogus compiler warnings; with too many bogus warnings, valid warnings get lost in the noise; builds should be clean without warnings.
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: 2.6.7 usb_lld_pump: no return statement

Post by Giovanni »

Hi,

I am thinking to make thread functions return "void", this would fix the issue but also delay the release slightly.

There could also be other advantages, I am evaluating tradeoffs. This would happen in 3.0 anyway.

Giovanni
User avatar
Giovanni
Site Admin
Posts: 14892
Joined: Wed May 27, 2009 8:48 am
Has thanked: 1202 times
Been thanked: 996 times

Re: 2.6.7 usb_lld_pump: no return statement

Post by Giovanni »

I implemented threads returning void, this eliminates also the problem with the warning.

Giovanni
Post Reply