[clang] [clang][bytecode] Load value of non-lvalue ArraySubscriptExpr (PR #160024)
via cfe-commits
cfe-commits at lists.llvm.org
Sun Sep 21 20:03:34 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Timm Baeder (tbaederr)
<details>
<summary>Changes</summary>
As happens in C.
Fixes #<!-- -->158482
---
Full diff: https://github.com/llvm/llvm-project/pull/160024.diff
2 Files Affected:
- (modified) clang/lib/AST/ByteCode/Compiler.cpp (+6-1)
- (modified) clang/test/AST/ByteCode/c.c (+4)
``````````diff
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]]; }
``````````
</details>
https://github.com/llvm/llvm-project/pull/160024
More information about the cfe-commits
mailing list