[llvm-bugs] [Bug 46259] New: Clang pointer to VLA conversions disallowed in C++ mode.
via llvm-bugs
llvm-bugs at lists.llvm.org
Tue Jun 9 13:54:38 PDT 2020
https://bugs.llvm.org/show_bug.cgi?id=46259
Bug ID: 46259
Summary: Clang pointer to VLA conversions disallowed in C++
mode.
Product: clang
Version: trunk
Hardware: PC
OS: Windows NT
Status: NEW
Severity: enhancement
Priority: P
Component: C++
Assignee: unassignedclangbugs at nondot.org
Reporter: erich.keane at intel.com
CC: blitzrakete at gmail.com, dgregor at apple.com,
erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
richard-llvm at metafoo.co.uk
See https://godbolt.org/z/dBvJLK
void foo(void *a, int x) {
int (*VLA) [x] = (int(*)[x]) a;
VLA = (int(*)[x]) a;
}
<source>:4:11: error: cannot initialize a variable of type 'int (*)[x]' with an
rvalue of type 'int (*)[x]'
int (*VLA) [x] = (int(*)[x]) a;
^ ~~~~~~~~~~~~~
<source>:5:11: error: incompatible pointer types assigning to 'int (*)[x]' from
'int (*)[x]'
VLA = (int(*)[x]) a;
^~~~~~~~~~~~~
2 errors generated.
Compiler returned: 1
The two types listed in both error message (despite syntactically and textually
identical) are actually pointers to different types, thus conversions aren't
allowed. In C mode the IsPointerConversion goes through typesAreConvertible
and mergeTypes and decides they are the compatible. However, the rules in C++
disallow these compatible conversions.
GCC allows these, and it seems to me that these two types should be allowed as
they are effectively the 'same' type despite being represented as different
types in our AST.
SO, to fix this I think we either need to
a: better canonicalize VLA types based on their represented types/bounds,
though this wouldn't fix the situation where the value of 'x' above could
change between them, so it would accept some incompatible types (where hte
value of "x" changed between the two), and disallow others.
b: Simply treat these as 'same-type' as a condition in isPointerConversion. I
think we can just do a minimal reproduction of mergeTypes to recursively check
ONLY VLA and element types. C mode ALSO allows fixed-size arrays on either
side of the conversion, so we may consider making this work for all array
types?
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20200609/b8f5fc5d/attachment-0001.html>
More information about the llvm-bugs
mailing list