Skip to content

Fix non-standard use of C99 flexible array in opal/mca/btl/base/btl_base_am_rdma.c #9828

Open
@jsquyres

Description

@jsquyres

As discussed in #9814 (comment) and #9814 (comment), the way struct mca_btl_base_rdma_hdr_t has a flexible array as its last member is valid C99. But when struct mca_btl_base_rdma_hdr_t is used as an element in struct mca_btl_base_rdma_operation_t, that's actually invalid C11 (and possibly invalid C99? I didn't check).

Per C11 standard (ISO/IEC 9899:2011) section 6.7.2.1:

A structure or union shall not contain a member with incomplete or function type [...], except that the last member of a structure with more than one named member may have incomplete array type; such a structure (and any union containing, possibly recursively, a member that is such a structure) shall not be a member of a structure or an element of an array.

Despite this, all C compilers somehow make OMPI's use of this construct work properly (and have done so for several years). Indeed, GCC only complains about this if you use -pedantic to compile:

$ cat ~/tmp/foo.c
struct inner {
    int i;
    char a[];
};

struct outer {
    int j;
    struct inner i;
};

$ gcc foo.c -c
$ gcc foo.c -c -Wall
$ gcc foo.c -c -pedantic
foo.c:8:18: warning: invalid use of structure with flexible array member [-Wpedantic]
    8 |     struct inner i;
      |                  ^

It's definitely not high priority, but someday we should probably fix this. It will likely be difficult to fix. ☹️

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions