Intel® C++ Compiler Classic Developer Guide and Reference

ID 767249
Date 12/16/2022
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Document Table of Contents

GAP Message (Diagnostic ID 30757)

Message

Remove unused field(s) '%s' from the struct '%s'.

This message is emitted only with whole-program recognition.

Advice

Some unused fields were seen in a class or structure type. If the unused fields can be removed from the structure definition, it will lead to reduced memory usage and better cache utilization since the cache will no longer be filled with unused data.

The advice is based on the analysis of the source code that is seen. You must verify that the fields that are reported as unused are not accessed elsewhere in the application. You also need to be careful when removing unused fields if the code relies on the structure fields to be laid out in a specific order. As an example, if the application code uses the address of a field to access other fields, it may stop working once unused fields are removed. Note that such code is not considered valid in the first place.

Example

Consider the following:

//unused_field_1.c
struct str {
    int a1, b1, c1, d1, e1;
};

struct str sp[1000000]; 
 int hot_func1() {
    int i, ret = 0; 
    for (i = 0; i < 1000000; i++) {
        ret += sp[i].a1;
        ret += sp[i].b1;
    }
    return ret; 
}
 
int hot_func2() {
    int ret = 0, i;
    for (i = 0; i < 1000000; i++) {
        ret += sp[i].a1;
        ret -= sp[i].c1;
    }
    return ret; 
}
 
int hot_func3() {
    int ret = 0, i;
    for (i = 0; i < 1000000; i++) {
        ret += sp[i].d1;
    }
    return ret; 
}
 
main() {
    hot_func1();
    hot_func2();
    hot_func3(); 
}

In this case, if the unused fields can be removed, the only source change needed would be the following:

//unused_field_1.c 
struct str {
    int a1, b1, c1, d1; 
}; 
...

Verify

Make sure that the restructured code satisfies the original program semantics.