Skip to content

C++: Remove redundants casts from IR #20154

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

MathiasVP
Copy link
Contributor

Consider the following snippet:

struct S {
  void foo() const;
};

void test() {
  S s;
  s.foo();
}

Because foo is a const member function there will be a GlvalueConversion which converts the qualifier from a glval<S> to a glval<const S> before it's passed to foo. This conversion will generate a Convert instruction.

However, there is very little value in keeping those conversions. In fact, it sometimes makes analysis harder for us. For example, the value number of the qualifier to foo (i.e., s after the conversion) is different from any other uses of s since those uses likely have type glval<S>. This fact bit me today!

This PR removes these conversions which previously generated a Convert instruction, but only modified the specifiers (i.e., constness, volatileness, etc.)

@github-actions github-actions bot added the C++ label Aug 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant