| Issue |
159603
|
| Summary |
Multidimentional arrays generate an unexpected warning
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
earnol
|
Since The commit https://github.com/llvm/llvm-project/commit/b24769855d97697de08e2296a548c033f193caf4#diff-778d8768bc77e1375d9a34c93e3885c1a986c00baa2435489742f270aede51eb the following code:
```
#include <stdio.h>
int afunc(unsigned long * v)
{
return v != NULL;
}
unsigned long mdarr[5][6];
unsigned long sdarr[30];
int main()
{
afunc(sdarr);
afunc(mdarr);
printf("mdarr = %zu \n", sizeof(mdarr));
printf("sdarr = %zu \n", sizeof(sdarr));
return 0;
}
```
generate warning:
`error: incompatible pointer types passing 'unsigned long[5][6]' to parameter of type 'unsigned long *' [-Wincompatible-pointer-types]`.
Please see [godbolt example](https://godbolt.org/#g:!((g:!((g:!((h:codeEditor,i:(filename:'1',fontScale:14,fontUsePx:'0',j:1,lang:___c,selection:(endColumn:12,endLineNumber:17,positionColumn:12,positionLineNumber:17,selectionStartColumn:12,selectionStartLineNumber:17,startColumn:12,startLineNumber:17),source:'%23include+%3Cstdio.h%3E%0A%0Aint+afunc(unsigned+long+*+v)%0A%7B%0A++++return+v+!!%3D+NULL%3B%0A%7D%0A%0Aunsigned+long+mdarr%5B5%5D%5B6%5D%3B%0Aunsigned+long+sdarr%5B30%5D%3B%0A%0Aint+main()%0A%7B%0A++afunc(sdarr)%3B%0A++afunc(mdarr)%3B%0A++printf(%22mdarr+%3D+%25zu+%5Cn%22,+sizeof(mdarr))%3B%0A++printf(%22sdarr+%3D+%25zu+%5Cn%22,+sizeof(sdarr))%3B%0A++return+0%3B%0A%7D%0A%0A'),l:'5',n:'0',o:'C+source+%231',t:'0')),header:(),k:34.71001224185383,l:'4',n:'0',o:'',s:0,t:'0'),(g:!((h:compiler,i:(compiler:cclang_trunk,filters:(b:'0',binary:'1',binaryObject:'1',commentOnly:'0',debugCalls:'1',demangle:'0',directives:'0',execute:'0',intel:'0',libraryCode:'0',trim:'1',verboseDemangling:'0'),flagsViewOpen:'1',fontScale:14,fontUsePx:'0',j:1,lang:___c,libs:!(),options:'-O0+-Wincompatible-pointer-types',overrides:!(),selection:(endColumn:1,endLineNumber:1,positionColumn:1,positionLineNumber:1,selectionStartColumn:1,selectionStartLineNumber:1,startColumn:1,startLineNumber:1),source:1),l:'5',n:'0',o:'+x86-64+clang+(trunk)+(Editor+%231)',t:'0')),header:(),k:25.7599630930296,l:'4',n:'0',o:'',s:0,t:'0'),(g:!((h:output,i:(compilerName:'x86-64+clang+20.1.0',editorid:1,fontScale:14,fontUsePx:'0',j:1,wrap:'1'),l:'5',n:'0',o:'Output+of+x86-64+clang+(trunk)+(Compiler+%231)',t:'0')),k:39.530024665116564,l:'4',n:'0',o:'',s:0,t:'0')),l:'2',n:'0',o:'',t:'0')),version:4).
However the standard in 6.5.2.1 Array subscripting says:
```
If E is an n-dimensional array (n ≥ 2) with dimensions i × j × . . . × k, then E (used as other than an lvalue) is converted to a pointer to an (n − 1)-dimensional array with dimensions j × . . . × k. If the unary * operator is applied to this pointer explicitly, or implicitly as a result of subscripting, the result is the pointed-to (n − 1)-dimensional array, which itself is converted into a pointer if used as other than an lvalue.
```
effectively requiring compatibility between multidimensional array and pointer. Thus it looks like warning should not be generated in such case.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs