How to suppress a "warning: control reaches the end of a non-void function"

I have a PowerPC build code translated using gcc cross-compiler using this function:

uint32_t fill_cache(void)
{
    __asm__ ("addi 3, 0, 0\n");  /* R3 = 0 */
    /* More asm here modifying R3 and filling the cache lines. */
}

which under PowerPC EABI returns the value calculated in R3. When compiling, I get

foo.c:105: warning: control reaches end of non-void function

Is there a way to teach gcc that the value is really coming back? Or is there a way to suppress a warning (without removing -Wall or adding -Wno- *)? I would like to very selectively suppress this warning only for this function, in order to leave the overall warning level as high as possible.

It is not possible to force this function to return void since the computed value is required by the caller.

+5
source share
2 answers

1: . ( -Wall), -void-, - -Wreturn-type. , :

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wreturn-type"
/* Your code here */
#pragma GCC diagnostic pop

, , -fdiagnostics-show-option. .

2: . :

uint32_t fill_cache(void)
{
  register uint32_t cacheVal __asm__ ("r3");

  __asm__ __volatile__ ("addi %0, 0, 0" : "=r" (cacheVal));
  /* More code here */

  return cacheVal;
}

volatile , - .

2 :

  • -void undefined .
  • () , .
+12

​​ naked, , () .

uint32_t fill_cache(void) __attribute__((naked)); // Declaration
// attribute should be specified in declaration not in implementation

uint32_t fill_cache(void) 
{
    __asm__ ("addi 3, 0, 0\n");  /* R3 = 0 */
    /* More asm here modifying R3 and filling the cache lines. */
}

, , , - :)

PS: __asm__, __volatile__ std=c89. __asm__ asm GNU GCC. - : asm volatile.

asm_language

+1

All Articles