-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Clang crashes and mis-handles aggregate initialization with base initializers in certain cases #80510
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@llvm/issue-subscribers-clang-codegen Author: Reid Kleckner (rnk)
I've identified a few loops over InitListExprs for records that don't account for the changes in C++17 which allowed base initializers to appear in an aggregate initialization expression, namely here and here:
https://github.com/llvm/llvm-project/blob/7a94acb2da5b20d12f13f3c5f4eb0f3f46e78e73/clang/lib/AST/Expr.cpp#L3345
https://github.com/llvm/llvm-project/blob/main/clang/lib/CodeGen/CGExprConstant.cpp#L696
The first case represents an actual bug, since it means we don't check the remaining initializer list expressions, as in this example:
Clang accepts this, but if you remove the Empty base and its initializer, it rejects it:
-->
Something is not right, and the dumped AST doesn't look right, it classifies
In this larger test case, this misclassification of this initializer as a constant ultimately results in a crash during codegen:
-->
I believe the solution is to update |
…#80519) This code was correct as written prior to C++17, which allowed bases to appear in the initializer list. This was observable by creating non-constant aggregate initialization at file scope in a compound literal, but since that behavior will change soon if we implement support for dynamic initialization, I also added a unit test for `isConstantInitializer`. This fixes at least one part of issue #80510 . --------- Co-authored-by: Aaron Ballman <[email protected]>
I've identified a few loops over InitListExprs for records that don't account for the changes in C++17 which allowed base initializers to appear in an aggregate initialization expression, namely here and here:
llvm-project/clang/lib/AST/Expr.cpp
Line 3345 in 7a94acb
https://github.com/llvm/llvm-project/blob/main/clang/lib/CodeGen/CGExprConstant.cpp#L696
The first case represents an actual bug, since it means we don't check the remaining initializer list expressions, as in this example:
Clang accepts this, but if you remove the Empty base and its initializer, it rejects it:
-->
Something is not right, and the dumped AST doesn't look right, it classifies
f()
as aConstantExpr
:In this larger test case, this misclassification of this initializer as a constant ultimately results in a crash during codegen:
-->
I believe the solution is to update
isConstantInitializer
to iterate over bases and not just fields, but that may uncover more issues.The text was updated successfully, but these errors were encountered: