-
Notifications
You must be signed in to change notification settings - Fork 13.4k
[clang][ExprConst] Check for array size of initlists #138673
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
base: main
Are you sure you want to change the base?
Conversation
@llvm/pr-subscribers-clang Author: Timm Baeder (tbaederr) ChangesFixes #138653 Full diff: https://github.com/llvm/llvm-project/pull/138673.diff 1 Files Affected:
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index e5950f461e4b2..46a87fd6c7e1c 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -11788,6 +11788,11 @@ bool ArrayExprEvaluator::VisitCXXParenListOrInitListExpr(
LLVM_DEBUG(llvm::dbgs() << "The number of elements to initialize: "
<< NumEltsToInit << ".\n");
+ if (!Info.CheckArraySize(ExprToVisit->getExprLoc(),
+ CAT->getNumAddressingBits(Info.Ctx), NumEltsToInit,
+ /*Diag=*/true))
+ return false;
+
Result = APValue(APValue::UninitArray(), NumEltsToInit, NumElts);
// If the array was previously zero-initialized, preserve the
|
That fixes compile-time computation, but this example still breaks in codegen: #include <array>
using namespace std;
constexpr size_t kMemoryChunk = 1024 * 8;
constexpr size_t kNumberOfIterations = 2000000;
constexpr size_t kThreadsNumber = 2 * kMemoryChunk;
struct S {};
int main() {
array<S, kThreadsNumber * kNumberOfIterations> futures{};
} here: llvm-project/clang/lib/CodeGen/CGExprConstant.cpp Lines 1408 to 1412 in dad3162
because Edit: Hmm, but that's only if |
I have not added the test since I thought it might take too long, but it's probably not a problem since we do the check before even touching the array... If I could come up with a reproducer that doesn't require |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be nice to also have tests to make sure we do emit the warning if the array is too large
Can’t you set the eval steps to like |
That comment is obsolete, I've added two test cases that work |
Fixes #138653