open-watcom / open-watcom-v2

Open Watcom V2.0 - Source code repository, Wiki, Latest Binary build, Archived builds including all installers for download.
Other
983 stars 160 forks source link

W115 warning not emitted for an array member of a struct #1158

Open sezero opened 11 months ago

sezero commented 11 months ago

As seen from the test case below, only the C++ compiler catches all 3, whereas the C compiler only catches the plain array variable.

OW toolchain is the CI build from commit af51255ab6905fa083c6f8955c4cd1b3a70b39f0

$ cat 1.c
#include <stdint.h>
#include <string.h>

#define MAX_TERM 8
struct decorr_pass {
    int32_t term, delta, weight_A, weight_B;
    int32_t samples_A [MAX_TERM], samples_B [MAX_TERM];
    int32_t aweight_A, aweight_B;
    int32_t sum_A, sum_B;
};

void foo (struct decorr_pass *dpp) {
    memset (&dpp->samples_A, 0, sizeof (dpp->samples_A));
    memset (&dpp->samples_B, 0, sizeof (dpp->samples_B));
}

struct decorr_pass dp;
void bar (void) {
    memset (&dp.samples_A, 0, sizeof (dp.samples_A));
}

int32_t samples_A [MAX_TERM];
void har (void) {
    memset (&samples_A, 0, sizeof (samples_A));
}

$ wcc386 -bt=os2 -d0 -zq -bm -5s -fp5 -fpi87 -sg -oeatxh -ei -w3 -bd 1.c
1.c(24): Warning! W115: &array may not produce intended result

$ wpp386 -bt=os2 -d0 -zq -bm -5s -fp5 -fpi87 -sg -oeatxh -ei -w3 -bd 1.c
1.c(13): Warning! W007: col(13) '&array' may not produce intended result
1.c(14): Warning! W007: col(13) '&array' may not produce intended result
1.c(19): Warning! W007: col(13) '&array' may not produce intended result
1.c(24): Warning! W007: col(13) '&array' may not produce intended result
jmalak commented 11 months ago

Thank you for your bug report. It looks like a problem with arrays in general. I've added a link to other issues that relate to array processing. There is also a problem with arrays in aggregate initialization that array processing will require complete rework. The problem is that the array type is transformed to a pointer too soon and the relevant information is lost.