Skip to content
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

Miscompile assigning to result of comma operator? #110617

Open
efriedma-quic opened this issue Oct 1, 2024 · 1 comment
Open

Miscompile assigning to result of comma operator? #110617

efriedma-quic opened this issue Oct 1, 2024 · 1 comment

Comments

@efriedma-quic
Copy link
Collaborator

Consider the following in C:

struct S;
struct C {
  int i;
  struct S *tab[1];
};
struct S { struct C c; };
void f(struct S *x) {
  ((void)1, x->c).tab[0] = 0;
}

Normally, the result of a comma operator isn't assignable, because it's an rvalue... but with array-to-pointer decay, you can assign to it. So the question is, does the assignment affect "x"? Or are we supposed to construct a temporary? Or is this just undefined behavior?

It looks like for the equivalent with an assignment operator, we do construct a temporary. Not sure if there's any other way to get a struct rvalue in C.

Ran into this trying to figure out why we allow EmitLValue on a CK_LValueToRValue in CodeGen.

@llvmbot
Copy link
Collaborator

llvmbot commented Oct 1, 2024

@llvm/issue-subscribers-clang-codegen

Author: Eli Friedman (efriedma-quic)

Consider the following in C:
struct S;
struct C {
  int i;
  struct S *tab[1];
};
struct S { struct C c; };
void f(struct S *x) {
  ((void)1, x->c).tab[0] = 0;
}

Normally, the result of a comma operator isn't assignable, because it's an rvalue... but with array-to-pointer decay, you can assign to it. So the question is, does the assignment affect "x"? Or are we supposed to construct a temporary? Or is this just undefined behavior?

It looks like for the equivalent with an assignment operator, we do construct a temporary. Not sure if there's any other way to get a struct rvalue in C.

Ran into this trying to figure out why we allow EmitLValue on a CK_LValueToRValue in CodeGen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants