Skip to content

[clang][Interp] Zero-init remaining string literal elements #66862

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

Merged
merged 1 commit into from
Sep 30, 2023

Conversation

tbaederr
Copy link
Contributor

No description provided.

@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Sep 20, 2023
@tbaederr
Copy link
Contributor Author

Ping

Copy link
Collaborator

@shafik shafik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor comments on testing but I am curious about the size question.

static_assert(a.c[0] == 'a', "");
static_assert(a.c[1] == 'b', "");
static_assert(a.c[2] == 'c', "");
static_assert(a.c[3] == '\0', "");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't we just test all the bytes? It is small enough.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we also test wide string literals etc?

@@ -858,8 +858,8 @@ bool ByteCodeExprGen<Emitter>::VisitStringLiteral(const StringLiteral *E) {

// If the initializer string is too long, a diagnostic has already been
// emitted. Read only the array length from the string literal.
unsigned N =
std::min(unsigned(CAT->getSize().getZExtValue()), E->getLength());
unsigned ArraySize = CAT->getSize().getZExtValue();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So getZExtValue() returns uint64_t yet we are using unsigned. I know this is already an existing problem that we make varying assumptions in different places but I am wondering what the long-term plan is for this this. Forgive me if I have asked this question in another context and I just forgot.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a bit tricky since StringLiteral::getLength() returns unsigned again, so we can't use the extra bytes anyway and need to cast to unsigned for the std::min().

@tbaederr tbaederr merged commit 4909e7c into llvm:main Sep 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants