Skip to content

[clang][bytecode] Reject assignments in C #136126

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
Apr 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion clang/lib/AST/ByteCode/Compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -863,8 +863,12 @@ bool Compiler<Emitter>::VisitBinaryOperator(const BinaryOperator *BO) {
return this->VisitPointerArithBinOp(BO);
}

// Assignmentes require us to evalute the RHS first.
// Assignments require us to evalute the RHS first.
if (BO->getOpcode() == BO_Assign) {
// We don't support assignments in C.
if (!Ctx.getLangOpts().CPlusPlus)
return this->emitInvalid(BO);

if (!visit(RHS) || !visit(LHS))
return false;
if (!this->emitFlip(*LT, *RT, BO))
Expand Down
23 changes: 23 additions & 0 deletions clang/test/AST/ByteCode/c2y.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// RUN: %clang_cc1 -triple x86_64-linux %s -std=c2y -verify=expected,both -fexperimental-new-constant-interpreter
// RUN: %clang_cc1 -triple x86_64-linux %s -std=c2y -verify=ref,both

// both-no-diagnostics

struct S {
int x;
char c;
float f;
};

#define DECL_BUFFER(Ty, Name) alignas(Ty) unsigned char Name[sizeof(Ty)]

struct T {
DECL_BUFFER(struct S, buffer);
};

int quorble() {
DECL_BUFFER(struct T, buffer);
((struct S *)((struct T *)buffer)->buffer)->x = 12;
const struct S *s_ptr = (struct S *)((struct T *)buffer)->buffer;
return s_ptr->x;
}
Loading