[all-commits] [llvm/llvm-project] 48bb5f: [clang] Add early exit when checking for const ini...
Adam Czachorowski via All-commits
all-commits at lists.llvm.org
Wed Nov 10 09:18:16 PST 2021
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 48bb5f4cbe8d5951c1153e469dc6713a122b7fa3
https://github.com/llvm/llvm-project/commit/48bb5f4cbe8d5951c1153e469dc6713a122b7fa3
Author: Adam Czachorowski <adamcz at google.com>
Date: 2021-11-10 (Wed, 10 Nov 2021)
Changed paths:
M clang/lib/AST/ExprConstant.cpp
A clang/test/SemaCXX/PR51712-large-array-constexpr-check-oom.cpp
Log Message:
-----------
[clang] Add early exit when checking for const init of arrays.
Before this commit, on code like:
struct S { ... };
S arr[10000000];
while checking if arr is constexpr, clang would reserve memory for
arr before running constructor for S. If S turned out to not have a
valid constexpr c-tor, clang would still try to initialize each element
(and, in case the c-tor was trivial, even skipping the constexpr step
limit), only to discard that whole APValue later, since the first
element generated a diagnostic.
With this change, we start by allocating just 1 element in the array to
try out the c-tor and take an early exit if any diagnostics are
generated, avoiding possibly large memory allocation and a lot of work
initializing to-be-discarded APValues.
Fixes 51712 and 51843.
In the future we may want to be smarter about large possibly-constexrp
arrays and maybe make the allocation lazy.
Differential Revision: https://reviews.llvm.org/D113120
More information about the All-commits
mailing list