Author: Timm Baeder Date: 2025-04-17T13:39:27+02:00 New Revision: 51295d6d56f938b878ca0e2bb0a749eb801e8202
URL: https://github.com/llvm/llvm-project/commit/51295d6d56f938b878ca0e2bb0a749eb801e8202 DIFF: https://github.com/llvm/llvm-project/commit/51295d6d56f938b878ca0e2bb0a749eb801e8202.diff LOG: [clang][bytecode] Reject assignments in C (#136126) Similar to what the current interpreter does. Added: clang/test/AST/ByteCode/c2y.c Modified: clang/lib/AST/ByteCode/Compiler.cpp Removed: ################################################################################ diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp index d3eabc513a9ac..3e53f2a2c8557 100644 --- a/clang/lib/AST/ByteCode/Compiler.cpp +++ b/clang/lib/AST/ByteCode/Compiler.cpp @@ -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)) diff --git a/clang/test/AST/ByteCode/c2y.c b/clang/test/AST/ByteCode/c2y.c new file mode 100644 index 0000000000000..bbb163ab83833 --- /dev/null +++ b/clang/test/AST/ByteCode/c2y.c @@ -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; +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits