Skip to content

[Clang] C2Y _Countof weird sub-array count with multidimensional VLA #141409

Closed
@fuhsnn

Description

@fuhsnn

This snippet:

#include <stdio.h>
int main(int i, char**) {
    int arr[11][++i][33][++i];

    printf("%lu\t", _Countof arr);
    printf("%lu\t", _Countof *arr);
    printf("%lu\t", _Countof **arr);
    printf("%lu\t", _Countof ***arr);
    printf("\n");
    printf("%lu\t",  sizeof arr / sizeof *arr);
    printf("%lu\t",  sizeof *arr / sizeof **arr);
    printf("%lu\t",  sizeof **arr / sizeof ***arr);
    printf("%lu\t",  sizeof ***arr / sizeof ****arr);
    printf("\n\t^ here\n");
}

prints the following with current Godbolt trunk and clang-21 in LLVM Debian nightly:

11	198	33	3	
11	2	33	3	
	^ here

The second output looks funny, if I understand _Countof correctly it should be 2 instead of 2*33*3.
Godbolt: https://godbolt.org/z/o1c6bWosM

Metadata

Metadata

Assignees

No one assigned

    Labels

    c2yclang:codegenIR generation bugs: mangling, exceptions, etc.confirmedVerified by a second party

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions