llvm-project icon indicating copy to clipboard operation
llvm-project copied to clipboard

[clang] Add thousands-separator to "cannot allocate array; evaluated array bound [...] exceeds the limit" diagnostic

Open tbaederr opened this issue 4 months ago • 10 comments

E.g. for

constexpr int foo() {
  auto p = new int[1'048'577];
  delete[] p;
  return 0;
}
static_assert(foo() == 0);

we emit

a.cpp:10:15: error: static assertion expression is not an integral constant expression
   10 | static_assert(foo() == 0);
      |               ^~~~~~~~~~
a.cpp:5:20: note: cannot allocate array; evaluated array bound 1048577 exceeds the limit (1048576); use '-fconstexpr-steps' to
      increase this limit
    5 |   auto p = new int[1'048'577];
      |                    ^
a.cpp:10:15: note: in call to 'foo()'
   10 | static_assert(foo() == 0);

It would be nice to

  1. Add thousands-separators to both the given size and the limit
  2. Change the wording to "exceeds the limit of xyz" to avoid the parantheses.

tbaederr avatar Jul 24 '26 11:07 tbaederr

@llvm/issue-subscribers-clang-frontend

Author: Timm Baeder (tbaederr)

E.g. for
constexpr int foo() {
  auto p = new int[1'048'577];
  delete[] p;
  return 0;
}
static_assert(foo() == 0);

we emit

a.cpp:10:15: error: static assertion expression is not an integral constant expression
   10 | static_assert(foo() == 0);
      |               ^~~~~~~~~~
a.cpp:5:20: note: cannot allocate array; evaluated array bound 1048577 exceeds the limit (1048576); use '-fconstexpr-steps' to
      increase this limit
    5 |   auto p = new int[1'048'577];
      |                    ^
a.cpp:10:15: note: in call to 'foo()'
   10 | static_assert(foo() == 0);

It would be nice to

  1. Add thousands-separators to both the given size and the limit
  2. Change the wording to "exceeds the limit of xyz" to avoid the parantheses.

Hi!

This issue may be a good introductory issue for people new to working on LLVM. If you would like to work on this issue, your first steps are:

  1. Check that no other contributor is working on this issue. If someone is assigned to the issue or claimed to be working on it, ping the person. After one week without a response, the assignee may be changed.
  2. Leave a comment indicating that you are working on the issue, or just create a pull request after following the steps below. Mention this issue in the description of the pull request.
  3. Fix the issue locally. Be aware that LLVM's AI policy forbids the use of AI tools to fix good first issues since it squanders a learning opportunity. Using LLMs to search and learn is permitted, since the goal is learning.
  4. Run the test suite locally. Remember that the subdirectories under test/ create fine-grained testing targets, so you can e.g. use make check-clang-ast to only run Clang's AST tests.
  5. Create a Git commit.
  6. Run git clang-format HEAD~1 to format your changes.
  7. Open a pull request to the upstream repository on GitHub. Detailed instructions can be found in GitHub's documentation. Mention this issue in the description of the pull request.

If you have any further questions about this issue, don't hesitate to ask via a comment in the thread below.

@llvm/issue-subscribers-good-first-issue

Author: Timm Baeder (tbaederr)

E.g. for
constexpr int foo() {
  auto p = new int[1'048'577];
  delete[] p;
  return 0;
}
static_assert(foo() == 0);

we emit

a.cpp:10:15: error: static assertion expression is not an integral constant expression
   10 | static_assert(foo() == 0);
      |               ^~~~~~~~~~
a.cpp:5:20: note: cannot allocate array; evaluated array bound 1048577 exceeds the limit (1048576); use '-fconstexpr-steps' to
      increase this limit
    5 |   auto p = new int[1'048'577];
      |                    ^
a.cpp:10:15: note: in call to 'foo()'
   10 | static_assert(foo() == 0);

It would be nice to

  1. Add thousands-separators to both the given size and the limit
  2. Change the wording to "exceeds the limit of xyz" to avoid the parantheses.

@tbaederr ping for review

VachanVY avatar Jul 24 '26 13:07 VachanVY

Hey is anyone working on this if not could I take it up?

david04g avatar Jul 24 '26 19:07 david04g

Hi, if anyone is not working on this, I would like to take it up!

KaustAbhinand avatar Jul 26 '26 03:07 KaustAbhinand

there's already a PR open for this issue

VachanVY avatar Jul 26 '26 04:07 VachanVY

there's already a PR open for this issue

For future reference, if you are taking up a good first issue it is helpful to indicate you plan to work on it and also indicate when a PR is opened for it. Good first issuses get a lot of attention and it helps to avoid extra comments and wasted work.

shafik avatar Jul 26 '26 10:07 shafik

Hi! I'm planning to work on this issue as part of the CS3423 Compilers II hackathon at IIT Hyderabad. I'd like to take responsibility for implementing the diagnostic formatting change and adding the corresponding regression tests. Could a maintainer please assign this issue to me? Thank you!

PathriVidyaPraveen avatar Oct 18 '26 10:10 PathriVidyaPraveen

Hi! I'm planning to work on this issue as part of the CS3423 Compilers II hackathon at IIT Hyderabad. I'd like to take responsibility for implementing the diagnostic formatting change and adding the corresponding regression tests. Could a maintainer please assign this issue to me? Thank you!

There's already a pr open, just have to address the review comments to merge it

VachanVY avatar Oct 18 '26 11:10 VachanVY