[clang] 242a1e2 - [clang][bytecode] Load value of non-lvalue ArraySubscriptExpr (#160024)
via cfe-commits
cfe-commits at lists.llvm.org
Tue Sep 23 00:47:27 PDT 2025
Author: Timm Baeder
Date: 2025-09-23T09:47:23+02:00
New Revision: 242a1e2fb1b2ddefc8dcde73e22ce3f06f6a8188
URL: https://github.com/llvm/llvm-project/commit/242a1e2fb1b2ddefc8dcde73e22ce3f06f6a8188
DIFF: https://github.com/llvm/llvm-project/commit/242a1e2fb1b2ddefc8dcde73e22ce3f06f6a8188.diff
LOG: [clang][bytecode] Load value of non-lvalue ArraySubscriptExpr (#160024)
As happens in C.
Fixes #158482
Added:
Modified:
clang/lib/AST/ByteCode/Compiler.cpp
clang/test/AST/ByteCode/c.c
Removed:
################################################################################
diff --git a/clang/lib/AST/ByteCode/Compiler.cpp b/clang/lib/AST/ByteCode/Compiler.cpp
index fafec47f7de3c..7518cfd2cf94d 100644
--- a/clang/lib/AST/ByteCode/Compiler.cpp
+++ b/clang/lib/AST/ByteCode/Compiler.cpp
@@ -1787,7 +1787,12 @@ bool Compiler<Emitter>::VisitArraySubscriptExpr(const ArraySubscriptExpr *E) {
return false;
if (DiscardResult)
return this->emitPopPtr(E);
- return true;
+
+ if (E->isGLValue())
+ return true;
+
+ OptPrimType T = classifyPrim(E);
+ return this->emitLoadPop(*T, E);
}
template <class Emitter>
diff --git a/clang/test/AST/ByteCode/c.c b/clang/test/AST/ByteCode/c.c
index 6681a4f427093..657a920e7d02c 100644
--- a/clang/test/AST/ByteCode/c.c
+++ b/clang/test/AST/ByteCode/c.c
@@ -368,3 +368,7 @@ void discardedCmp(void)
{
(*_b) = ((&a == &a) , a); // all-warning {{left operand of comma operator has no effect}}
}
+
+/// ArraySubscriptExpr that's not an lvalue
+typedef unsigned char U __attribute__((vector_size(1)));
+void nonLValueASE(U f) { f[0] = f[((U)(U){0})[0]]; }
More information about the cfe-commits
mailing list