Issue |
78841
|
Summary |
Clang crashes when generating a reference of auto type from a nullptr casted to a pointer to an integer array of unknown size
|
Labels |
clang
|
Assignees |
|
Reporter |
ChipsSpectre
|
Extension from https://github.com/llvm/llvm-project/issues/76634, since below the surface of that issue's crash problem there is another issue causing a crash of clang.
Consider this code, simplified from 76634:
```
int main() {
int m = 1;
auto& x = *(int(*)[m])(nullptr);
return x[0];
}
```
Compiling this with the latest version of clang will trigger the following assertion:
> clang-18: /home/drives/fastSSD/llvm-project/clang/include/clang/AST/Type.h:753: const clang::ExtQualsTypeCommonBase* clang::QualType::getCommonPtr() const: Assertion `!isNull() && "Cannot retrieve a NULL type pointer"' failed.
Because in ExprConstant.cpp.9275, the dynamic cast to a ConstantArrayType fails and clang tries to add an unsized array to the result.
If we add a check for a nullptr at this position (and return false in that case), several test cases in test/clang/AST/Interp/arrays.cpp (line 500) fail since the diagnostic errors for incomplete arrays are not emitted. For example, the _must be initialized by a constant expression_ diagnostic.
At which point in the clang AST parsing can we add the check for _must be initialized by a constant expression_, which should trigger when we try to perform the cast to a pointer to an integer array of unknown size?
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs